Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 远端 codex config 写入改经 stdin 传输不进 argv
yan7746ffed71c8
diff --git a/apps/desktop/src/main/remote-ssh/__tests__/codex-remote-mcp.test.ts b/apps/desktop/src/main/remote-ssh/__tests__/codex-remote-mcp.test.tsindex e1c5b568e7..406d7932ee 100644--- a/apps/desktop/src/main/remote-ssh/__tests__/codex-remote-mcp.test.ts+++ b/apps/desktop/src/main/remote-ssh/__tests__/codex-remote-mcp.test.ts@@ -25,10 +25,12 @@ const SERVERS = ['cindy_orca', 'orca_worker_bridge'];/** 走完整 ensure 流程的 fake host:读 config 返回给定内容, 其余命令一律成功。 */function fakeHost(hostId: string, configContent: string) {const execCmds: string[] = [];+ const inputs: string[] = [];const host = {id: hostId,- exec: async (cmd: string) => {+ exec: async (cmd: string, opts?: { input?: string }) => {execCmds.push(cmd);+ if (opts?.input) inputs.push(opts.input);if (cmd.includes('cat "$CODEX_HOME/config.toml"')) {return { exitCode: 0, stdout: configContent, stderr: '' };}@@ -40,21 +42,20 @@ function fakeHost(hostId: string, configContent: string) {close: async () => {},}),} as unknown as RemoteHost;- return { host, execCmds };+ return { host, execCmds, inputs };}/**- * 从 write 命令里解出写入的 config 内容。依赖 writeConfigCmd 的- * `printf '%s' '<base64>'` 形态 (base64 无单引号):取命令里最长的类- * base64 token 解码。下限 16:清理后的小 config (如只剩一行 model) base64- * 也只有二十余字符;命令里其余 token 均被符号断开, 不会更长的误匹配。+ * 从 write 命令的 stdin input 解出写入的 config 内容。config base64 经+ * stdin 传入 (不进 argv, 见 codex-remote-mcp.ts writeConfigCmd 注释):纯+ * base64 形态的那条 input 即写入内容;bootstrap 的 KEY=value 块含下划线/+ * 换行, 形态不符自然跳过。下限 16 与旧版 (argv 提取) 同理由。*/-function decodeWrittenConfig(execCmds: string[]): string | null {- for (const cmd of execCmds) {- if (!cmd.includes('base64 -d')) continue;- const tokens = cmd.match(/[A-Za-z0-9+/=]{16,}/g) ?? [];- const b64 = tokens.sort((a, b) => b.length - a.length)[0];- if (b64) return Buffer.from(b64, 'base64').toString('utf-8');+function decodeWrittenConfig(inputs: string[]): string | null {+ for (const input of inputs) {+ const t = input.trim();+ if (t.length < 16 || !/^[A-Za-z0-9+/=]+$/.test(t)) continue;+ return Buffer.from(t, 'base64').toString('utf-8');}return null;}@@ -415,6 +416,27 @@ describe('ensureRemoteCodexMcpBridge live-turn defer', () => {// bootstrap 的 stdin 是 KEY=value + 空行终止。expect(inputs).toContain('LIZI_MCP_TOKEN=test-persistent-token\n\n');});++ it('streams the config payload via stdin, never argv (secrets in user config stay out of ps)', async () => {+ // sec 回归 (codex-connector R17 P1):用户 config.toml 可能已含 secret+ // (其他 MCP server 的 bearer / provider token);合并后的整份 config 嵌进+ // bash -c argv 时远端 `ps` / audit log 可回收 — 必须经 stdin 通道写入,+ // 与 bootstrap token 同约束。+ const { host, execCmds, inputs } = fakeHost('host-write-stdin', 'model = "gpt-5.5"\n');+ const result = await ensureRemoteCodexMcpBridge(host, {+ ...bridgeDeps,+ hasLiveTurnOnHost: () => false,+ });+ expect(result.ok).toBe(true);+ const writeCmd = execCmds.find((c) => c.includes('base64 -d'));+ expect(writeCmd).toBeTruthy();+ // argv 里不得出现 config 内容或其 base64 payload。+ expect(writeCmd).not.toContain('cindy-remote-mcp');+ expect(writeCmd!.match(/[A-Za-z0-9+/=]{40,}/g)).toBeNull();+ // payload 确实经 stdin 送达且内容正确。+ const written = decodeWrittenConfig(inputs);+ expect(written).toContain('[mcp_servers.cindy_orca]');+ });});describe('ensureRemoteCodexMcpBridge bootstrap retry', () => {@@ -426,7 +448,7 @@ describe('ensureRemoteCodexMcpBridge bootstrap retry', () => {let configContent = '';const host = {id: 'host-bootstrap-retry',- exec: async (cmd: string) => {+ exec: async (cmd: string, opts?: { input?: string }) => {if (cmd.includes('cat "$CODEX_HOME/config.toml"')) {return { exitCode: 0, stdout: configContent, stderr: '' };}@@ -441,8 +463,8 @@ describe('ensureRemoteCodexMcpBridge bootstrap retry', () => {return { exitCode: 0, stdout: 'ok', stderr: '' };}if (cmd.includes('base64 -d')) {- // 模拟真实远端:写入内容反映到后续读取。- const written = decodeWrittenConfig([cmd]);+ // 模拟真实远端:stdin 写入的内容反映到后续读取。+ const written = decodeWrittenConfig(opts?.input ? [opts.input] : []);if (written !== null) configContent = written;return { exitCode: 0, stdout: 'ok', stderr: '' };}@@ -479,7 +501,7 @@ describe('ensureRemoteCodexMcpBridge server whitelist', () => {// review P1 回归:bridge 上还挂着 cindy_memory / cindy_ssh 等 in-process// provider — 全量写进远端 daemon config 会让远端 session 获得本机 MCP// 能力, 越出协同边界。远端只注入 cindy_orca / orca_worker_bridge。- const { host, execCmds } = fakeHost('host-whitelist', '');+ const { host, execCmds, inputs } = fakeHost('host-whitelist', '');const result = await ensureRemoteCodexMcpBridge(host, {ensureBridgeStarted: async () => ({port: 38080,@@ -489,7 +511,7 @@ describe('ensureRemoteCodexMcpBridge server whitelist', () => {hasLiveTurnOnHost: () => false,});expect(result.ok).toBe(true);- const written = decodeWrittenConfig(execCmds);+ const written = decodeWrittenConfig(inputs);expect(written).not.toBeNull();expect(written).toContain('[mcp_servers.cindy_orca]');expect(written).toContain('[mcp_servers.orca_worker_bridge]');@@ -517,7 +539,7 @@ describe('ensureRemoteCodexMcpBridge server whitelist', () => {// 否则远端 session 继续调用已失效的 MCP endpoint。const stale = renderManagedMcpBlock({ remotePort: 47921, serverNames: SERVERS, tokenFingerprint: 'fp-old' });const existing = `model = "gpt-5.5"\n\n${stale}\n`;- const { host, execCmds } = fakeHost('host-cleanup', existing);+ const { host, execCmds, inputs } = fakeHost('host-cleanup', existing);const result = await ensureRemoteCodexMcpBridge(host, {ensureBridgeStarted: async () => ({ port: 38080, serverNames: ['cindy_memory'], bridgeInstanceId: 'bridge-1' }),hasLiveTurnOnHost: () => false,@@ -526,7 +548,7 @@ describe('ensureRemoteCodexMcpBridge server whitelist', () => {const joined = execCmds.join('\n');expect(joined).toContain('base64 -d'); // 写了清理后的 configexpect(joined).toContain('bootstrap'); // 重启 daemon 清 env- const written = decodeWrittenConfig(execCmds);+ const written = decodeWrittenConfig(inputs);expect(written).not.toBeNull();expect(written).not.toContain('cindy-remote-mcp'); // 受管段已剥除expect(written).toContain('model = "gpt-5.5"'); // 用户配置保留@@ -536,26 +558,26 @@ describe('ensureRemoteCodexMcpBridge server whitelist', () => {// review P2 回归:bridge 重建后旧 mcp-session-id 全失效, 但 token// (persistent) 与端口 (per-host 固定) 不变 — 代际 id 必须进漂移指纹,// 否则常驻 daemon 持旧 id 打新 bridge 全部 404。- const { host: host1, execCmds: execCmds1 } = fakeHost('host-regen', '');+ const { host: host1, inputs: inputs1 } = fakeHost('host-regen', '');const deps = (instanceId: string) => ({ensureBridgeStarted: async () => ({ port: 38080, serverNames: SERVERS, bridgeInstanceId: instanceId }),hasLiveTurnOnHost: () => false,});const first = await ensureRemoteCodexMcpBridge(host1, deps('bridge-1'));expect(first.ok).toBe(true);- const writtenFirst = decodeWrittenConfig(execCmds1);+ const writtenFirst = decodeWrittenConfig(inputs1);expect(writtenFirst).toContain('# cindy-token-fingerprint:');// 远端 config 已是 bridge-1 指纹;bridge 重建 (bridge-2) → 指纹漂移 →// 重写 config 并再 bootstrap (daemon 仍存活, changed 是唯一触发)。- const { host: host2, execCmds: execCmds2 } = fakeHost('host-regen', writtenFirst ?? '');+ const { host: host2, execCmds: execCmds2, inputs: inputs2 } = fakeHost('host-regen', writtenFirst ?? '');const second = await ensureRemoteCodexMcpBridge(host2, deps('bridge-2'));expect(second.ok).toBe(true);const joined2 = execCmds2.join('\n');expect(joined2).toContain('base64 -d');expect(joined2).toContain('bootstrap');// 幂等对照:同代际重复 ensure 不触发重写/重启。- const { host: host3, execCmds: execCmds3 } = fakeHost('host-regen', decodeWrittenConfig(execCmds2) ?? '');+ const { host: host3, execCmds: execCmds3 } = fakeHost('host-regen', decodeWrittenConfig(inputs2) ?? '');const third = await ensureRemoteCodexMcpBridge(host3, deps('bridge-2'));expect(third.ok).toBe(true);const joined3 = execCmds3.join('\n');diff --git a/apps/desktop/src/main/remote-ssh/codex-remote-mcp.ts b/apps/desktop/src/main/remote-ssh/codex-remote-mcp.tsindex cac8e5d867..b8cf60577f 100644--- a/apps/desktop/src/main/remote-ssh/codex-remote-mcp.ts+++ b/apps/desktop/src/main/remote-ssh/codex-remote-mcp.ts@@ -309,13 +309,17 @@ function readConfigCmd(): string {)}`;}-function writeConfigCmd(contentBase64: string): string {+function writeConfigCmd(): string {// 原子写:先 decode 到 tmp 再 mv 就位。直接 `> config.toml` 时, decode// 失败或 SSH 中断会把用户配置截断成空/半截 — 这里编辑的是真实远端// config.toml, 错误路径不得破坏现有内容 (tmp 残留无害, 下次覆盖)。+ // base64 内容经 stdin 传入, 不进 argv:用户 config.toml 可能已含 secret+ // (其他 MCP server 的 bearer / provider token), argv 在远端 `ps` / audit+ // log 可见 — 与 bootstrap token 的 "secrets only live in stdin" 同约束+ // (review: PR #778 codex-connector R17 P1)。return `bash -c ${shellQuoteSh(`${codexHomePrefix(DEFAULT_INSTALL_ROOT)}; mkdir -p "$CODEX_HOME" && ` +- `printf '%s' ${shellQuoteSh(contentBase64)} | base64 -d > "$CODEX_HOME/config.toml.tmp" && ` ++ `base64 -d > "$CODEX_HOME/config.toml.tmp" && ` +`mv "$CODEX_HOME/config.toml.tmp" "$CODEX_HOME/config.toml"`,)}`;}@@ -330,7 +334,13 @@ async function readRemoteConfig(host: RemoteHost): Promise<string> {async function writeRemoteConfig(host: RemoteHost, content: string): Promise<void> {const b64 = Buffer.from(content, 'utf-8').toString('base64');- const result = await host.exec(writeConfigCmd(b64), { timeoutMs: 15_000, label: 'write codex config.toml' });+ const result = await host.exec(writeConfigCmd(), {+ timeoutMs: 15_000,+ label: 'write codex config.toml',+ // base64 单行无空白, stdin 写完即 EOF, base64 -d 读到 EOF 解码 (与+ // bootstrapDaemon 的 stdin 协议同通道, cmd 不进日志见 exec label 约定)。+ input: `${b64}\n`,+ });if (result.exitCode !== 0) {throw new Error(`write remote config.toml failed: ${result.stderr.trim().slice(0, 200)}`);}