Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(remote-agent): preserve executable argv path
nothingyuancandob84e71e6e196
diff --git a/apps/desktop/src/main/remote-agent/__tests__/execServerProjection.e2e.test.ts b/apps/desktop/src/main/remote-agent/__tests__/execServerProjection.e2e.test.tsindex c0662cbc3f..132f5f0b53 100644--- a/apps/desktop/src/main/remote-agent/__tests__/execServerProjection.e2e.test.ts+++ b/apps/desktop/src/main/remote-agent/__tests__/execServerProjection.e2e.test.ts@@ -13,6 +13,68 @@ const REPO = path.resolve(__dirname, '../../../../../..');const CODEX = path.join(REPO, 'apps', 'codex-package-bin', process.platform + '-' + process.arch, 'bin', process.platform === 'win32' ? 'codex.exe' : 'codex');describe.skipIf(!fs.existsSync(CODEX))('native exec-server workspace projection', () => {+ // 测试价值:生产入口 ExecServerRelay → 原生 exec-server 必须能从含空格的别名目录+ // 启动程序。#6743 的旧实现把 argv[0] 当 Shell 文本引用,Windows 实际报 os error 123;+ // 现有 E2E 只使用未映射的 process.execPath。最小失败输入是一个程序目录别名,e2e tier。+ it('starts an executable through an alias without adding shell quoting', async () => {+ const root = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'cindy-exec-argv-')));+ const programs = path.join(root, 'Program Files');+ const executableName = process.platform === 'win32' ? 'node.exe' : 'node';+ const executable = path.join(programs, executableName);+ fs.mkdirSync(programs);+ if (process.platform === 'win32') {+ fs.copyFileSync(process.execPath, executable);+ } else {+ fs.symlinkSync(process.execPath, executable);+ }+ const virtual = '/agent/programs';+ const workspace = new ExecutorWorkspace({ workingDir: root, aliases: [{ from: virtual, to: programs }] });+ const messages: Array<Record<string, any>> = [];+ const actions: ExecutorAction[] = [];+ let parts = '';+ const relay = new ExecServerRelay({+ codexPath: CODEX,+ cwd: root,+ workspace,+ authorize: (action) => { actions.push(action); return { ok: true }; },+ push: async (frames) => {+ for (const frame of frames) {+ if (frame.kind !== 'message') continue;+ parts += frame.data;+ if (!frame.more) { messages.push(JSON.parse(parts)); parts = ''; }+ }+ },+ });+ const send = (message: unknown) => relay.handle({+ t: 'ws', connId: 'argv', kind: 'message', data: JSON.stringify(message),+ });+ try {+ relay.handle({ t: 'ws', connId: 'argv', kind: 'open', path: '/ws/exec-server' });+ send({ id: 1, method: 'initialize', params: { clientName: 'cindy-test', clientVersion: '1' } });+ await expect.poll(() => messages.find((item) => item.id === 1), { timeout: 5000 }).toBeDefined();+ expect(messages.find((item) => item.id === 1)?.error).toBeUndefined();+ send({ method: 'initialized', params: {} });+ send({ id: 2, method: 'process/start', params: {+ processId: 'argv',+ argv: [`${virtual}/${executableName}`, '-e', 'console.log(JSON.stringify(process.argv.slice(1)))', 'space in argument', 'literal "quotes"'],+ cwd: pathToFileURL(root).href,+ env: { PATH: programs, ...(process.platform === 'win32' ? { SystemRoot: process.env.SystemRoot, TEMP: os.tmpdir() } : {}) },+ tty: false,+ } });+ await expect.poll(() => messages.find((item) => item.id === 2), { timeout: 5000 }).toBeDefined();+ expect(messages.find((item) => item.id === 2)?.error).toBeUndefined();+ await expect.poll(() => messages.find((item) => item.method === 'process/exited'), { timeout: 5000 }).toBeDefined();+ expect(messages.find((item) => item.method === 'process/exited')?.params.exitCode).toBe(0);+ const output = messages.filter((item) => item.method === 'process/output')+ .map((item) => Buffer.from(item.params.chunk, 'base64').toString()).join('');+ expect(JSON.parse(output)).toEqual(['space in argument', 'literal "quotes"']);+ expect(actions).toEqual([expect.objectContaining({ kind: 'exec', cwd: root })]);+ } finally {+ relay.close();+ await fsp.rm(root, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 });+ }+ });+it('initializes and executes with virtual paths while the file and authorization stay on this computer', async () => {const root = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'cindy-exec-projection-')));const project = path.join(root, 'project');diff --git a/apps/desktop/src/main/remote-agent/controller/execServerRelay.ts b/apps/desktop/src/main/remote-agent/controller/execServerRelay.tsindex 3539c5fe9b..ac5b1435e6 100644--- a/apps/desktop/src/main/remote-agent/controller/execServerRelay.ts+++ b/apps/desktop/src/main/remote-agent/controller/execServerRelay.ts@@ -156,7 +156,12 @@ export function mapExecServerParams(value: unknown, workspace: ExecutorWorkspaceresult[key] = pathToFileURL(workspace.resolve(foreign)).href;} else result[key] = workspace.resolve(item);}- if (Array.isArray(result.argv)) result.argv = result.argv.map((part) => typeof part === 'string' ? workspace.mapCommand(part, resolveExecutorShell().dialect) : part);+ if (Array.isArray(result.argv)) result.argv = result.argv.map((part, index) => {+ if (typeof part !== 'string') return part;+ // argv[0] is passed directly to the OS as an executable name, so Shell quoting would+ // become part of the filename. Only expand a registered workspace alias here.+ return index === 0 ? workspace.mapAlias(part) : workspace.mapCommand(part, resolveExecutorShell().dialect);+ });if (typeof result.command === 'string') result.command = workspace.mapCommand(result.command, resolveExecutorShell().dialect);if (result.sandbox !== undefined) result.sandbox = mapExecServerSandbox(result.sandbox, workspace);return mapFileData ? mapExecServerFileData(result, workspace, method) : result;diff --git a/apps/desktop/src/main/remote-agent/executor/__tests__/virtualWorkspace.test.ts b/apps/desktop/src/main/remote-agent/executor/__tests__/virtualWorkspace.test.tsindex 44fdcfd0d8..3f66537887 100644--- a/apps/desktop/src/main/remote-agent/executor/__tests__/virtualWorkspace.test.ts+++ b/apps/desktop/src/main/remote-agent/executor/__tests__/virtualWorkspace.test.ts@@ -387,6 +387,33 @@ describe('virtual workspace', () => {expect(workspace.mapOutputForAgent(Buffer.from(pathExpected))).toEqual(Buffer.from(pathValue));});+ // 测试价值:生产入口 mapExecServerParams 必须给原生 exec-server 传递未经过 Shell+ // 引用的 argv[0]。#6743 在 Windows 上因含空格的程序别名被加引号而报 os error 123;+ // 现有覆盖只验证参数和命令文本映射。unit tier 的最小失败输入是一个含空格的程序目录别名。+ it.each(['/home/agent/bin', 'C:\\Agent\\bin'])('maps executable aliases without shell quoting from %s', (virtual) => {+ const programs = path.join(root, "Program Files 100% O'Brien");+ const workspace = new ExecutorWorkspace({ workingDir: root, aliases: [{ from: virtual, to: programs }] });+ const native = virtual.startsWith('C:') ? path.win32 : path.posix;+ const params = mapExecServerParams({+ argv: [native.join(virtual, 'tool.exe'), '--version'],+ cwd: pathToFileURL(root).href,+ }, workspace, 'process/start');+ expect(params).toEqual({+ argv: [path.join(programs, 'tool.exe'), '--version'],+ cwd: pathToFileURL(root).href,+ });+ });++ it('preserves native executable paths, PATH names, relative names and literal quote characters', () => {+ const workspace = new ExecutorWorkspace({+ workingDir: root,+ aliases: [{ from: '/agent/bin', to: path.join(root, 'Program Files') }],+ });+ for (const executable of ['pwsh', path.join(root, 'Program Files', 'pwsh.exe'), './tool', '"/agent/bin/pwsh.exe"']) {+ expect(mapExecServerParams({ argv: [executable] }, workspace, 'process/start')).toEqual({ argv: [executable] });+ }+ });+it('maps Codex request paths and commands before permission checks and projects text file bytes', async () => {const { workspace, project, executor } = setup('/Users/agent/workspace');const params = mapExecServerParams({ path: 'file:///Users/agent/workspace/a.txt', dataBase64: Buffer.from(project).toString('base64') }, workspace);