Skip to content

Commit f89fac8

Browse files
LLM-26758 fix Failed to initialize ACP process, add script for building binary
1 parent 1b58cc0 commit f89fac8

2 files changed

Lines changed: 109 additions & 2 deletions

File tree

scripts/build-macos-local.sh

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
VERSION_TAG="$VERSION_TAG"
5+
DIST_DIR="dist/bin"
6+
IDEA_CODEX_BIN_DIR="${IDEA_CODEX_BIN_DIR:-}"
7+
PACKAGE_JSON="package.json"
8+
PACKAGE_JSON_BAK="$(mktemp)"
9+
10+
cp "$PACKAGE_JSON" "$PACKAGE_JSON_BAK"
11+
12+
cleanup() {
13+
cp "$PACKAGE_JSON_BAK" "$PACKAGE_JSON"
14+
rm -f "$PACKAGE_JSON_BAK"
15+
}
16+
trap cleanup EXIT
17+
18+
mkdir -p "$DIST_DIR"
19+
20+
# Keep CI-compatible artifact names in dist/bin.
21+
rm -f \
22+
"$DIST_DIR/codex-acp-x64-darwin" \
23+
"$DIST_DIR/codex-acp-arm64-darwin" \
24+
"$DIST_DIR/codex-acp-x64-darwin.zip" \
25+
"$DIST_DIR/codex-acp-arm64-darwin.zip"
26+
27+
echo "Temporarily setting package version to: ${VERSION_TAG}"
28+
perl -i -pe 's/"version":\s*"[^"]+"/"version": "'"${VERSION_TAG}"'"/' "$PACKAGE_JSON"
29+
30+
echo "Building macOS binaries..."
31+
bun build src/index.ts --minify --sourcemap --compile --target=bun-darwin-x64-baseline --outfile dist/bin/codex-acp-x64-darwin
32+
bun build src/index.ts --minify --sourcemap --compile --target=bun-darwin-arm64 --outfile dist/bin/codex-acp-arm64-darwin
33+
34+
echo "Packaging artifacts in GitHub Actions format..."
35+
36+
(
37+
cd "$DIST_DIR"
38+
zip -q codex-acp-x64-darwin.zip codex-acp-x64-darwin
39+
zip -q codex-acp-arm64-darwin.zip codex-acp-arm64-darwin
40+
)
41+
42+
X64_VERSION="$("$DIST_DIR/codex-acp-x64-darwin" --version | tail -n 1)"
43+
ARM64_VERSION="$("$DIST_DIR/codex-acp-arm64-darwin" --version | tail -n 1)"
44+
45+
if [[ "$X64_VERSION" != *" ${VERSION_TAG}" ]]; then
46+
echo "Version check failed for x64: $X64_VERSION"
47+
exit 1
48+
fi
49+
50+
if [[ "$ARM64_VERSION" != *" ${VERSION_TAG}" ]]; then
51+
echo "Version check failed for arm64: $ARM64_VERSION"
52+
exit 1
53+
fi
54+
55+
echo "Done. Artifacts:"
56+
ls -lh \
57+
"$DIST_DIR/codex-acp-x64-darwin" \
58+
"$DIST_DIR/codex-acp-arm64-darwin" \
59+
"$DIST_DIR/codex-acp-x64-darwin.zip" \
60+
"$DIST_DIR/codex-acp-arm64-darwin.zip"
61+
62+
if [[ -n "$IDEA_CODEX_BIN_DIR" ]]; then
63+
echo "Copying local macOS binaries to IntelliJ dev Codex bin dir..."
64+
COPIED_ARTIFACTS=()
65+
66+
for artifact in \
67+
"codex-acp-x64-darwin" \
68+
"codex-acp-arm64-darwin" \
69+
"codex-acp-x64-darwin.zip" \
70+
"codex-acp-arm64-darwin.zip"; do
71+
source_path="$DIST_DIR/$artifact"
72+
target_path="$IDEA_CODEX_BIN_DIR/$artifact"
73+
74+
if [[ -e "$target_path" ]]; then
75+
cp -f "$source_path" "$target_path"
76+
COPIED_ARTIFACTS+=("$target_path")
77+
else
78+
echo "Skipping missing target: $target_path"
79+
fi
80+
done
81+
82+
echo "Copied artifacts:"
83+
if [[ ${#COPIED_ARTIFACTS[@]} -gt 0 ]]; then
84+
ls -lh "${COPIED_ARTIFACTS[@]}"
85+
else
86+
echo "No existing target artifacts were updated."
87+
fi
88+
else
89+
echo "IDEA_CODEX_BIN_DIR is not set; skipping IntelliJ artifact copy."
90+
fi
91+
92+
echo "Embedded version: ${VERSION_TAG}"

src/index.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ if (process.argv[2] === "login") {
3030
}
3131

3232
function startAcpServer() {
33-
const defaultCodexPath = createRequire(import.meta.url).resolve("@openai/codex/bin/codex.js");
34-
const codexPath = process.env["CODEX_PATH"] ?? defaultCodexPath;
33+
const codexPath = resolveCodexPath();
3534
const configString = process.env["CODEX_CONFIG"];
3635
const authRequestString = process.env["DEFAULT_AUTH_REQUEST"];
3736
const modelProvider = process.env["MODEL_PROVIDER"];
@@ -71,3 +70,19 @@ function startAcpServer() {
7170

7271
new acp.AgentSideConnection(createAgent, acpJsonStream);
7372
}
73+
74+
function resolveCodexPath(): string {
75+
const configuredCodexPath = process.env["CODEX_PATH"];
76+
if (configuredCodexPath) {
77+
return configuredCodexPath;
78+
}
79+
80+
try {
81+
return createRequire(import.meta.url).resolve("@openai/codex/bin/codex.js");
82+
} catch (error) {
83+
logger.log("Falling back to codex from PATH because @openai/codex/bin/codex.js could not be resolved", {
84+
error: error instanceof Error ? error.message : String(error),
85+
});
86+
return "codex";
87+
}
88+
}

0 commit comments

Comments
 (0)