Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(remote): install the pinned full Codex package over SSH

DavidShen6af38c0265af
diff --git a/packages/maker-remote-ssh/src/__tests__/remote-agent-installer.test.ts b/packages/maker-remote-ssh/src/__tests__/remote-agent-installer.test.ts
index 416948f448..9a41dd8615 100644
--- a/packages/maker-remote-ssh/src/__tests__/remote-agent-installer.test.ts
+++ b/packages/maker-remote-ssh/src/__tests__/remote-agent-installer.test.ts
@@ -1,6 +1,11 @@
import { describe, expect, it } from 'vitest';
+import { spawnSync } from 'node:child_process';
+import { chmodSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
+import os from 'node:os';
+import path from 'node:path';
+import codexPackage from '../../../../tools/codex-package/latest.json';
-import { BOOTSTRAP_SH } from '../bootstrap/bootstrap-script.js';
+import { BOOTSTRAP_SH, VERIFY_CODEX_LAYOUT_SH } from '../bootstrap/bootstrap-script.js';
import {
installRemoteAgent,
PINNED_CLAUDE_CODE_VERSION,
@@ -33,6 +38,9 @@ describe('remote agent installer', () => {
expect(result.ready).toBe(true);
expect(result.installedVersion).toBe(PINNED_CODEX_RELEASE_VERSION);
+ expect(PINNED_CODEX_RELEASE_VERSION).toBe(codexPackage.version);
+ // Full-package install.sh preserves this alias for legacy daemon callers.
+ expect(result.binaryPath).toBe('/home/u/.xdt-server/v1/codex-home/packages/standalone/current/codex');
expect(calls).toHaveLength(1);
expect(calls[0].command).toContain(`'${PINNED_CODEX_RELEASE_VERSION}'`);
expect(calls[0].input).toBe(BOOTSTRAP_SH);
@@ -43,6 +51,47 @@ describe('remote agent installer', () => {
expect(BOOTSTRAP_SH).toContain('sh "$INSTALLER_TMP" --release "$CODEX_RELEASE"');
});
+ it('keeps the generated bootstrap valid bash', () => {
+ const result = spawnSync('bash', ['-n'], { input: BOOTSTRAP_SH, encoding: 'utf8' });
+ expect(result.error).toBeUndefined();
+ expect(result.status, result.stderr).toBe(0);
+ });
+
+ it.each([
+ { name: 'legacy standalone', os: 'Darwin', legacy: true, missing: '', ok: true },
+ { name: 'complete macOS package', os: 'Darwin', legacy: false, missing: 'codex-resources/bwrap', ok: true },
+ { name: 'complete Linux package', os: 'Linux', legacy: false, missing: '', ok: true },
+ { name: 'missing code-mode host', os: 'Darwin', legacy: false, missing: 'bin/codex-code-mode-host', ok: false },
+ { name: 'missing ripgrep', os: 'Darwin', legacy: false, missing: 'codex-path/rg', ok: false },
+ { name: 'missing package manifest', os: 'Darwin', legacy: false, missing: 'codex-package.json', ok: false },
+ { name: 'missing Linux sandbox', os: 'Linux', legacy: false, missing: 'codex-resources/bwrap', ok: false },
+ ])('checks $name using the remote layout guard', ({ os: remoteOs, legacy, missing, ok }) => {
+ const root = mkdtempSync(path.join(os.tmpdir(), 'cindy-ssh-codex-layout-'));
+ try {
+ const files = legacy ? ['codex'] : [
+ 'codex', 'codex-package.json', 'bin/codex', 'bin/codex-code-mode-host',
+ 'codex-path/rg', 'codex-resources/bwrap',
+ ];
+ if (!legacy) mkdirSync(path.join(root, 'codex-resources'), { recursive: true });
+ for (const file of files.filter((file) => file !== missing)) {
+ const destination = path.join(root, file);
+ mkdirSync(path.dirname(destination), { recursive: true });
+ writeFileSync(destination, '#!/bin/sh\nexit 0\n');
+ chmodSync(destination, 0o755);
+ }
+ const result = spawnSync('bash', ['-c', `
+ BIN_PATH="$PWD/codex"
+ uname() { printf '%s\n' '${remoteOs}'; }
+ ${VERIFY_CODEX_LAYOUT_SH}
+ verify_codex_layout
+ `], { cwd: root, encoding: 'utf8' });
+ expect(result.error).toBeUndefined();
+ expect(result.status, result.stderr).toBe(ok ? 0 : 1);
+ } finally {
+ rmSync(root, { recursive: true, force: true });
+ }
+ });
+
it('pins Claude Code for probe and install, and rejects a stale sentinel version', async () => {
const calls: Array<{ command: string; input: string }> = [];
const host = {
diff --git a/packages/maker-remote-ssh/src/bootstrap/bootstrap-script.ts b/packages/maker-remote-ssh/src/bootstrap/bootstrap-script.ts
index fec3ce5546..5b6d5d1f4a 100644
--- a/packages/maker-remote-ssh/src/bootstrap/bootstrap-script.ts
+++ b/packages/maker-remote-ssh/src/bootstrap/bootstrap-script.ts
@@ -25,7 +25,7 @@
* ALREADY_INSTALLED <version> (agent sentinel valid; skip install)
* INSTALL_START <package-or-installer>
* (claude-code: npm package name;
- * codex: 'codex-standalone' — official curl install.sh)
+ * codex: 'codex-package' — official curl install.sh)
* INSTALL_LOG <line> (relayed npm / curl / install.sh line, may repeat)
* INSTALL_DONE
* READY <version> (final terminal-success; binary verified)
@@ -131,13 +131,32 @@ export const NODE_DIST_BASE_URL_DEFAULT = 'https://nodejs.org/dist';
export const CODEX_RELEASE_INSTALLER_URL_BASE = 'https://github.com/openai/codex/releases/download';
export const CODEX_LATEST_INSTALLER_URL = 'https://chatgpt.com/codex/install.sh';
+/** Shared by probe and bootstrap. Keep legacy standalone installs usable, but
+ * never accept a partially installed full package just because --version runs.
+ * The official installer preserves current/codex -> bin/codex for old callers. */
+export const VERIFY_CODEX_LAYOUT_SH = String.raw`verify_codex_layout() {
+ local root
+ root="$(dirname "$BIN_PATH")"
+ if [ -e "$root/codex-package.json" ] || [ -d "$root/bin" ]; then
+ [ -f "$root/codex-package.json" ] &&
+ [ -x "$root/bin/codex" ] &&
+ [ -x "$root/bin/codex-code-mode-host" ] &&
+ [ -x "$root/codex-path/rg" ] &&
+ [ -d "$root/codex-resources" ] || return 1
+ if [ "$(uname -s)" = "Linux" ]; then
+ [ -x "$root/codex-resources/bwrap" ] || return 1
+ fi
+ fi
+}
+`;
+
/**
* Bash script. Args:
* $1 = agentKind (claude-code | codex)
* $2 = serverVersion (matches REMOTE_SERVER_SCHEMA_VERSION; reserved for future bumps)
* $3 = bundled node version (BUNDLED_NODE_VERSION)
* $4 = node dist base URL (NODE_DIST_BASE_URL_DEFAULT)
- * $5 = codex release version (tools/codex/latest.json pin; codex only)
+ * $5 = codex release version (tools/codex-package/latest.json pin; codex only)
* $6 = Claude Code version (tools/claude/latest.json pin; claude-code only)
*
* The version + URL are passed as args (not hardcoded) so a host-side
@@ -158,8 +177,8 @@ emit() { printf '%s\n' "$*"; }
# Per-agent install method:
# - claude-code: npm install into our isolated $INSTALL_DIR/node_modules/
-# - codex: official install.sh standalone, redirected via CODEX_HOME
-# to our isolated $INSTALL_DIR/codex-home/. Why standalone:
+# - codex: official install.sh full package, redirected via CODEX_HOME
+# to our isolated $INSTALL_DIR/codex-home/. Why managed install:
# codex daemon mode (app-server daemon bootstrap --remote-control)
# requires a "managed install" at $CODEX_HOME/packages/standalone/current/codex.
# The npm @openai/codex package does NOT create that layout
@@ -184,7 +203,7 @@ NODE_DIR="$INSTALL_DIR/node"
NODE_BIN="$NODE_DIR/bin/node"
NPM_BIN="$NODE_DIR/bin/npm"
SENTINEL="$INSTALL_DIR/.installed-$AGENT_KIND"
-# codex 走 standalone (install.sh), binary 在 isolated CODEX_HOME 下;
+# codex 走完整 codex-package (install.sh), 保留 current/codex 兼容入口;
# claude-code 走 npm,binary 在 isolated node_modules/.bin 下。
# 所有路径都在 ~/.xdt-server/$SERVER_VER/ 下,卸载只需 rm -rf 这一棵树。
if [ "$AGENT_KIND" = "codex" ]; then
@@ -300,8 +319,13 @@ ensure_node() {
# chmod +x real target 兜底 — npm 装 native binary 偶尔丢 +x mode。
# 失败时把 stderr + ls / file / head 几行 emit 到 INSTALL_LOG (silent install
# pipeline 透传到 desktop main log), 不用 ssh 进远端调试。
+${VERIFY_CODEX_LAYOUT_SH}
verify_binary() {
if [ ! -L "$BIN_PATH" ] && [ ! -x "$BIN_PATH" ] && [ ! -f "$BIN_PATH" ]; then return 1; fi
+ if [ "$AGENT_KIND" = "codex" ] && ! verify_codex_layout; then
+ emit "INSTALL_LOG incomplete Codex package layout"
+ return 1
+ fi
_STDERR_LOG="$INSTALL_DIR/.verify-stderr-$$"
# Make sure the real binary (follow symlink) is executable — npm shim 创建
@@ -458,7 +482,7 @@ elif [ "$AGENT_KIND" = "codex" ]; then
&& emit "INSTALL_LOG mirrored existing $HOME/.codex/auth.json -> $CODEX_HOME_DIR/auth.json"
fi
- emit "INSTALL_START codex-standalone"
+ emit "INSTALL_START codex-package"
# install.sh respects three env vars to keep everything in our tree:
# CODEX_HOME → tarball extract target + daemon state + auth
# CODEX_INSTALL_DIR → "visible command" symlink dir (we don't add to PATH; daemon uses absolute path)
@@ -512,6 +536,12 @@ elif [ "$AGENT_KIND" = "codex" ]; then
emit "ERROR install.sh exit=$SH_EXIT"
exit 4
fi
+ # New installs must be the full package. The official installer supplies
+ # the compatibility symlink used by existing daemon / one-shot callers.
+ if [ ! -f "$CODEX_HOME_DIR/packages/standalone/current/codex-package.json" ] || ! verify_codex_layout; then
+ emit "ERROR install.sh did not produce a complete Codex package"
+ exit 5
+ fi
# install.sh's add_to_path() unconditionally writes a "# >>> Codex installer >>>"
# block to user's ~/.bashrc / ~/.zshrc / etc. We don't want to touch user
diff --git a/packages/maker-remote-ssh/src/bootstrap/installer.ts b/packages/maker-remote-ssh/src/bootstrap/installer.ts
index f849c8b0ea..5e08ed296c 100644
--- a/packages/maker-remote-ssh/src/bootstrap/installer.ts
+++ b/packages/maker-remote-ssh/src/bootstrap/installer.ts
@@ -17,13 +17,14 @@
import type { RemoteHost } from '../RemoteHost.js';
import claudeLatest from '../../../../tools/claude/latest.json';
-import codexLatest from '../../../../tools/codex/latest.json';
+import codexLatest from '../../../../tools/codex-package/latest.json';
import piLatest from '../../../../tools/pi/latest.json';
import {
BOOTSTRAP_SH,
BUNDLED_NODE_VERSION,
NODE_DIST_BASE_URL_DEFAULT,
PROBE_BUNDLED_NODE_SH,
+ VERIFY_CODEX_LAYOUT_SH,
REMOTE_SERVER_SCHEMA_VERSION,
} from './bootstrap-script.js';
@@ -201,8 +202,9 @@ INSTALL_DIR="$HOME/.xdt-server/$SERVER_VER"
NODE_DIR="$INSTALL_DIR/node"
NODE_BIN="$NODE_DIR/bin/node"
SENTINEL="$INSTALL_DIR/.installed-$AGENT_KIND"
-# codex: standalone install via install.sh -> isolated CODEX_HOME (binary at
-# $CODEX_HOME/packages/standalone/current/codex). claude-code: npm install
+# codex: official full package via install.sh -> isolated CODEX_HOME.
+# current/codex is the installer's compatibility symlink to bin/codex;
+# legacy standalone installs use the same entrypoint. claude-code: npm install
# -> node_modules/.bin/claude. Stay in sync with bootstrap-script.ts.
if [ "$AGENT_KIND" = "codex" ]; then
BIN_PATH="$INSTALL_DIR/codex-home/packages/standalone/current/codex"
@@ -215,7 +217,11 @@ ${PROBE_BUNDLED_NODE_SH}
# when we run --version. If bundled node is missing, the version check will
# silently fail and we'll report NOT_INSTALLED, which is the right outcome.
export PATH="$NODE_DIR/bin:$PATH"
+${VERIFY_CODEX_LAYOUT_SH}
if [ -f "$SENTINEL" ] && { [ -x "$BIN_PATH" ] || [ -f "$BIN_PATH" ]; }; then
+ if [ "$AGENT_KIND" = "codex" ] && ! verify_codex_layout; then
+ printf 'NOT_INSTALLED\n'; exit 0
+ fi
V="$("$BIN_PATH" --version 2>/dev/null | head -1 || true)"
if [ -n "$V" ]; then
if [ "$AGENT_KIND" != "claude-code" ] || [ "${'$'}{V%% *}" = "$CLAUDE_RELEASE" ]; then
@@ -605,8 +611,8 @@ function binaryName(kind: RemoteAgentKind): string {
/**
* 跟 bootstrap-script.ts / installer.ts probe shell (line 97-101) 的 BIN_PATH
* 分支保持一致:
- * - codex 用 install.sh 装成 standalone, 二进制落在 CODEX_HOME 下
- * ($INSTALL_DIR/codex-home/packages/standalone/current/codex)
+ * - codex 用 install.sh 安装完整 codex-package,保留官方 current/codex
+ * 兼容入口(新布局指向 bin/codex,旧 standalone 是实际二进制)
* - claude-code 走 npm install, 在 $INSTALL_DIR/node_modules/.bin/claude
* 任一端改路径都要同步 — 否则 RUN_AGENT_ONE_SHOT 等消费 binaryPath 的链路会
* 执行不存在的路径, 已安装的 agent 也会跑不起来。