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。

feat(desktop): use Codex package in production

MagicLizib43ee771add0
diff --git a/apps/desktop/src/main/__tests__/agentBinaryLinuxPrepare.test.ts b/apps/desktop/src/main/__tests__/agentBinaryLinuxPrepare.test.ts
index 38b8b1b58e..292fe0502a 100644
--- a/apps/desktop/src/main/__tests__/agentBinaryLinuxPrepare.test.ts
+++ b/apps/desktop/src/main/__tests__/agentBinaryLinuxPrepare.test.ts
@@ -107,17 +107,27 @@ describe('dev Codex package selection', () => {
expect(createBinaryProvisioner).not.toHaveBeenCalled();
});
- it('keeps the packaged release on the existing Codex manifest and single binary', async () => {
+ it('starts the packaged release from the complete Codex package entrypoint', async () => {
+ const expectedPath = path.join(
+ '/tmp/xdt-userdata',
+ 'codex-package',
+ '0.153.0',
+ 'bin',
+ 'codex',
+ );
cdndProvisioner.prepare.mockResolvedValueOnce({
ready: true,
- binaryPath: '/tmp/xdt-userdata/codex/0.152.0/codex',
+ binaryPath: expectedPath,
});
- await expect(binaries.prepare('codex')).resolves.toMatchObject({ ready: true });
+ await expect(binaries.prepare('codex')).resolves.toMatchObject({
+ ready: true,
+ path: expectedPath,
+ });
expect(createBinaryProvisioner).toHaveBeenCalledWith(expect.objectContaining({
- manifestField: 'codex',
- installSubdir: 'codex',
- artifact: { kind: 'gz', binaryName: 'codex' },
+ manifestField: 'codexPackage',
+ installSubdir: 'codex-package',
+ artifact: { kind: 'tar-gz-dir', binaryName: path.join('bin', 'codex') },
}));
});
});
@@ -255,9 +265,9 @@ describe('packaged Linux agent binary prepare', () => {
it('peek delegates to the CDN check when the manifest publishes a linux asset', async () => {
manifestService.getCachedManifest.mockReturnValue({
app: { version: '0.1.59' },
- codex: {
- version: '0.144.6',
- file: 'codex/0.144.6/linux-x64/codex.gz',
+ codexPackage: {
+ version: '0.153.0',
+ file: 'codex-package/0.153.0/linux-x64/codex-package.dist.tar.gz',
sha256: 'b'.repeat(64),
size: 5678,
},
diff --git a/apps/desktop/src/main/__tests__/agentProcessPriority.test.ts b/apps/desktop/src/main/__tests__/agentProcessPriority.test.ts
index 7188a78451..b45ae3e87c 100644
--- a/apps/desktop/src/main/__tests__/agentProcessPriority.test.ts
+++ b/apps/desktop/src/main/__tests__/agentProcessPriority.test.ts
@@ -223,6 +223,7 @@ describe('agent process discovery', () => {
const userDataDir = allUserDataDirNames(CURRENT_CINDY_REGION)[0].toLowerCase();
const claudeCmd = `/users/me/library/application support/${userDataDir}/claude-code/2.1.219/claude --setting-sources user`;
const codexCmd = `/users/me/library/application support/${userDataDir}/codex/0.145.0/codex app-server`;
+ const codexPackageCmd = `/users/me/library/application support/${userDataDir}/codex-package/0.153.0/bin/codex app-server`;
const devClaudeCmd = '/repo/apps/claude-code-bin/darwin-arm64/claude';
const devCodexPackageCmd = '/repo/apps/codex-package-bin/darwin-arm64/bin/codex app-server';
const externalClaudeCmd = '/usr/local/bin/claude';
@@ -230,6 +231,7 @@ describe('agent process discovery', () => {
it('classifies bundled claude/codex command lines and rejects external installs', () => {
expect(classifyAgentCommandLine(claudeCmd)).toBe('claude');
expect(classifyAgentCommandLine(codexCmd)).toBe('codex');
+ expect(classifyAgentCommandLine(codexPackageCmd)).toBe('codex');
expect(classifyAgentCommandLine(devClaudeCmd)).toBe('claude');
expect(classifyAgentCommandLine(devCodexPackageCmd)).toBe('codex');
expect(classifyAgentCommandLine(externalClaudeCmd)).toBeNull();
@@ -251,6 +253,9 @@ describe('agent process discovery', () => {
expect(
classifyAgentCommandLine(`/home/u/.config/${userDataDir}/codex/0.145.0/codex app-server`),
).toBe('codex');
+ expect(
+ classifyAgentCommandLine(`/home/u/.config/${userDataDir}/codex-package/0.153.0/bin/codex app-server`),
+ ).toBe('codex');
// 外部安装(不带 userData 目录)仍不认领
expect(classifyAgentCommandLine('/home/u/.local/bin/claude')).toBeNull();
});
@@ -268,6 +273,9 @@ describe('agent process discovery', () => {
expect(
classifyAgentCommandLine(`${redirected.toLowerCase()}/agent-runtime/codex/bin/codex`),
).toBe('codex');
+ expect(
+ classifyAgentCommandLine(`${redirected.toLowerCase()}/codex-package/0.153.0/bin/codex`),
+ ).toBe('codex');
expect(
classifyAgentCommandLine(`${redirected.toLowerCase()}/claude-code/2.1.219/claude`),
).toBe('claude');
diff --git a/apps/desktop/src/main/agent-binaries/__tests__/factory-dir-dist.test.ts b/apps/desktop/src/main/agent-binaries/__tests__/factory-dir-dist.test.ts
index 5e8e235c48..fee5821c99 100644
--- a/apps/desktop/src/main/agent-binaries/__tests__/factory-dir-dist.test.ts
+++ b/apps/desktop/src/main/agent-binaries/__tests__/factory-dir-dist.test.ts
@@ -81,13 +81,14 @@ async function fulfillDownloadWithTarGz(opts: DownloadOpts) {
};
}
-function makeProvisioner(overrides?: { optionalAsset?: boolean }) {
+function makeProvisioner(overrides?: { optionalAsset?: boolean; binaryName?: string }) {
+ const { binaryName = BIN_NAME, ...configOverrides } = overrides ?? {};
return createBinaryProvisioner({
vendorKey: 'pi',
manifestField: 'pi',
installSubdir: `dir-dist-test-${Date.now()}-${Math.random().toString(36).slice(2)}`,
- artifact: { kind: 'tar-gz-dir', binaryName: BIN_NAME },
- ...overrides,
+ artifact: { kind: 'tar-gz-dir', binaryName },
+ ...configOverrides,
});
}
@@ -136,6 +137,33 @@ describe('createBinaryProvisioner tar-gz-dir', () => {
}
});
+ it('supports a nested package entrypoint such as bin/codex', async () => {
+ const binaryName = path.join('bin', process.platform === 'win32' ? 'codex.exe' : 'codex');
+ const sourceRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'codex-package-src-'));
+ const sourceBinary = path.join(sourceRoot, binaryName);
+ fs.mkdirSync(path.dirname(sourceBinary), { recursive: true });
+ fs.writeFileSync(sourceBinary, '#!/bin/sh\necho codex\n', { mode: 0o755 });
+ fs.writeFileSync(path.join(sourceRoot, 'codex-package.json'), '{}');
+ mocks.archiveState.srcDir = sourceRoot;
+ mocks.download.mockImplementation(fulfillDownloadWithTarGz);
+
+ let installRoot: string | undefined;
+ try {
+ const result = await makeProvisioner({ binaryName }).prepare();
+
+ expect(result.ready).toBe(true);
+ const versionDir = path.dirname(path.dirname(result.binaryPath));
+ installRoot = path.dirname(versionDir);
+ expect(result.binaryPath).toBe(path.join(versionDir, binaryName));
+ expect(fs.existsSync(path.join(versionDir, 'codex-package.json'))).toBe(true);
+ expect(fs.existsSync(path.join(versionDir, '.verified'))).toBe(true);
+ expect(fs.existsSync(path.join(versionDir, `${binaryName}.dist.tar.gz`))).toBe(false);
+ } finally {
+ fs.rmSync(sourceRoot, { recursive: true, force: true });
+ if (installRoot) fs.rmSync(installRoot, { recursive: true, force: true });
+ }
+ });
+
it('嵌套归档(上游 Unix 布局):内容上移到版本目录根', async () => {
mocks.archiveState.srcDir = stageDist('nested');
mocks.download.mockImplementation(fulfillDownloadWithTarGz);
diff --git a/apps/desktop/src/main/agent-binaries/index.ts b/apps/desktop/src/main/agent-binaries/index.ts
index ddd198a360..e2ddff02c5 100644
--- a/apps/desktop/src/main/agent-binaries/index.ts
+++ b/apps/desktop/src/main/agent-binaries/index.ts
@@ -156,12 +156,11 @@ import type {
// createBinaryProvisioner 用的内部 enum, 历史叫 'claude' / 'codex' (factory 内部
// 硬约定, 不改)。
//
-// pi 与 cc/codex 的差异:
-// - artifactKind 'tar-gz-dir': pi 是整目录分发(主二进制 + theme/ 等运行时资产,
-// 只装主二进制会在 RPC 启动期崩溃), CDN 资产是整包 tar.gz, 归档根即完整目录
-// (与 apps/pi-bin/<platform>/ 同布局)。
-// - optionalAsset: pi 是可选实验 agent。manifest 缺 pi 字段 / 下载失败都不阻塞
-// 启动 —— check-environment 的 pi 段静默降级,本次不注册 pi。
+// 目录分发运行时:
+// - codex-package:完整目录包含 bin/codex、code-mode host、rg 与 resources;生产入口
+// 与 dev 一致指向 bin/codex,CDN 资产读取 manifest.codexPackage。
+// - pi:完整目录包含主二进制与 theme/ 等运行时资产;同时它是可选实验 agent,
+// manifest 缺 pi 字段 / 下载失败都不阻塞启动。
export type AgentBinaryKind = 'claude-code' | 'codex' | 'pi';
@@ -191,13 +190,13 @@ const CONFIG: Record<AgentBinaryKind, AgentBinaryConfig> = {
},
codex: {
vendorKey: 'codex',
- manifestField: 'codex',
- installSubdir: 'codex',
- binaryName: process.platform === 'win32' ? 'codex.exe' : 'codex',
+ manifestField: 'codexPackage',
+ installSubdir: 'codex-package',
+ binaryName: path.join('bin', process.platform === 'win32' ? 'codex.exe' : 'codex'),
devBinDir: 'codex-package-bin',
devBinaryName: path.join('bin', process.platform === 'win32' ? 'codex.exe' : 'codex'),
vendorTag: 'codex',
- artifactKind: 'gz',
+ artifactKind: 'tar-gz-dir',
preserveLocalVersion: true,
},
pi: {
diff --git a/apps/desktop/src/main/agent-process-priority.ts b/apps/desktop/src/main/agent-process-priority.ts
index f654105e8b..4094faf955 100644
--- a/apps/desktop/src/main/agent-process-priority.ts
+++ b/apps/desktop/src/main/agent-process-priority.ts
@@ -86,15 +86,18 @@ export interface AgentProcessPriorityWatcher {
/**
* codex 二进制路径 marker(与 buildClaudePathMarkers 同构):
- * <userData>/codex/<ver>/ 及 dev checkout 的 apps/codex-package-bin/。
+ * <userData>/codex[-package]/<ver>/ 及 dev checkout 的 apps/codex-package-bin/。
*/
export function buildCodexPathMarkers(dirNames: readonly string[]): string[] {
return dirNames.flatMap((dirName) => {
const dir = dirName.toLowerCase();
return [
`appdata\\roaming\\${dir}\\codex\\`,
+ `appdata\\roaming\\${dir}\\codex-package\\`,
`appdata/roaming/${dir}/codex/`,
+ `appdata/roaming/${dir}/codex-package/`,
`/library/application support/${dir}/codex/`,
+ `/library/application support/${dir}/codex-package/`,
];
});
}
@@ -112,8 +115,9 @@ export function buildLinuxPathMarkers(
): string[] {
return dirNames.flatMap((dirName) => {
const dir = dirName.toLowerCase();
+ const installSubdirs = kind === 'codex' ? ['codex', 'codex-package'] : [kind];
return [
- `/.config/${dir}/${kind}/`,
+ ...installSubdirs.map((installSubdir) => `/.config/${dir}/${installSubdir}/`),
`/.config/${dir}/agent-runtime/${kind}/`,
];
});
@@ -151,9 +155,12 @@ export function registerUserDataMarkers(userDataPath: string): void {
// 两种形态都登记;非本平台形态的变体永不命中,无害。
const variants = new Set([lower.replace(/\\/g, '/'), lower.replace(/\//g, '\\')]);
const out: string[] = [];
+ const installSubdirs = kind === 'codex' ? ['codex', 'codex-package'] : [kind];
for (const v of variants) {
const sep = v.includes('\\') ? '\\' : '/';
- out.push(`${v}${sep}${kind}${sep}`);
+ for (const installSubdir of installSubdirs) {
+ out.push(`${v}${sep}${installSubdir}${sep}`);
+ }
out.push(`${v}${sep}agent-runtime${sep}${kind}${sep}`);
}
return out;
diff --git a/apps/desktop/src/main/maker-host/__tests__/codexAuthIsolatedSandbox.test.ts b/apps/desktop/src/main/maker-host/__tests__/codexAuthIsolatedSandbox.test.ts
index 9145b8dec7..2de59c5137 100644
--- a/apps/desktop/src/main/maker-host/__tests__/codexAuthIsolatedSandbox.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/codexAuthIsolatedSandbox.test.ts
@@ -69,6 +69,7 @@ function fixture(): { codexHome: string; systemAuth: string; localAuth: string }
function trustIsolatedAuthSandbox(): void {
const nonce = 'a'.repeat(64);
+ const isolationName = 'test-isolated-auth';
const now = Date.now();
fs.writeFileSync(
path.join(h.userDataDir, '.isolated-auth-launch-proof.json'),
@@ -78,13 +79,14 @@ function trustIsolatedAuthSandbox(): void {
userDataDir: fs.realpathSync.native(h.userDataDir),
profileKind: 'isolated-sandbox',
epoch: 1,
- isolationName: '',
+ isolationName,
issuedAtMs: now,
expiresAtMs: now + 60_000,
})}\n`,
{ mode: 0o600 },
);
vi.stubEnv('XDT_ISOLATED', '1');
+ vi.stubEnv('XDT_ISOLATED_NAME', isolationName);
vi.stubEnv('XDT_ISOLATED_AUTH', '1');
vi.stubEnv('XDT_USER_DATA_DIR_EPOCH', '1');
vi.stubEnv('XDT_ALLOW_DEV_OAUTH_WRITE', '1');
diff --git a/apps/desktop/src/main/manifestService.ts b/apps/desktop/src/main/manifestService.ts
index ab4c63d584..5777b020b3 100644
--- a/apps/desktop/src/main/manifestService.ts
+++ b/apps/desktop/src/main/manifestService.ts
@@ -90,6 +90,7 @@ export interface Manifest {
/** Linux manifests omit agent assets; packaged Linux uses its official runtime fallback. */
claudeCode?: ClaudeCodeManifest;
codex?: CodexManifest;
+ codexPackage?: CodexManifest;
ripgrep?: RipgrepManifest;
pi?: PiManifest;
}