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(desktop): claude-code / codex 保留本地更新版本,不再被 manifest 降级 (#3803)

wpr317694-del7e8d99f4c36a
diff --git a/apps/desktop/src/main/agent-binaries/__tests__/binary-version-probe.test.ts b/apps/desktop/src/main/agent-binaries/__tests__/binary-version-probe.test.ts
index 39937e5cd2..af73cf078c 100644
--- a/apps/desktop/src/main/agent-binaries/__tests__/binary-version-probe.test.ts
+++ b/apps/desktop/src/main/agent-binaries/__tests__/binary-version-probe.test.ts
@@ -14,6 +14,12 @@ describe('binary version probe', () => {
expect(parseBinaryVersionOutput('pi v0.84.4-beta.1\n', '')).toBe('0.84.4-beta.1');
});
+ it('normalizes the Claude Code and codex --version shapes', () => {
+ expect(parseBinaryVersionOutput('2.1.258 (Claude Code)\n', '')).toBe('2.1.258');
+ expect(parseBinaryVersionOutput('codex-cli 0.145.0\n', '')).toBe('0.145.0');
+ expect(parseBinaryVersionOutput('codex-cli v0.145.0\n', '')).toBe('0.145.0');
+ });
+
it('uses SemVer precedence for prerelease arbitration', () => {
expect(isBinaryVersionNotOlder('0.84.5-beta.1', '0.84.4')).toBe(true);
expect(isBinaryVersionNotOlder('0.84.5-beta.1', '0.84.5')).toBe(false);
@@ -22,6 +28,8 @@ describe('binary version probe', () => {
it('rejects unrelated or multiline-leading output', () => {
expect(parseBinaryVersionOutput('other 0.84.4\n', '')).toBeNull();
expect(parseBinaryVersionOutput('warning\n0.84.4\n', '')).toBeNull();
+ expect(parseBinaryVersionOutput('codex-cli 0.145.0 (extra)\n', '')).toBeNull();
+ expect(parseBinaryVersionOutput('(Claude Code) 2.1.258\n', '')).toBeNull();
});
it('returns null instead of throwing when the executable cannot be spawned', async () => {
diff --git a/apps/desktop/src/main/agent-binaries/binary-version-probe.ts b/apps/desktop/src/main/agent-binaries/binary-version-probe.ts
index c3b8276c18..f2d029e212 100644
--- a/apps/desktop/src/main/agent-binaries/binary-version-probe.ts
+++ b/apps/desktop/src/main/agent-binaries/binary-version-probe.ts
@@ -19,19 +19,34 @@ export function isBinaryVersionNotOlder(candidate: string, required: string): bo
return semver.gte(candidate, required);
}
-/** Parse the supported Pi version forms from the first `--version` output line. */
+/** Managed CLIs that print `<name> <version>` instead of a leading bare version. */
+const NAMED_VERSION_PREFIXES = new Set(['pi', 'codex-cli']);
+
+function normalizeVersionToken(token: string | undefined): string | null {
+ return token ? normalizeBinaryVersion(token.replace(/^v(?=\d)/, '')) : null;
+}
+
+/**
+ * Parse the supported version forms from the first `--version` output line.
+ *
+ * Covers the three shapes the managed runtimes actually print:
+ * - `0.84.4` (pi)
+ * - `2.1.258 (Claude Code)` (claude-code — version leads, suffix is a product label)
+ * - `codex-cli 0.145.0` (codex)
+ *
+ * Stays deliberately strict: an unknown leading token that is not itself a valid
+ * version yields null rather than scanning the line for anything semver-shaped.
+ */
export function parseBinaryVersionOutput(stdout: string, stderr: string): string | null {
const output = (stdout || stderr).trim();
const firstLine = output.split(/\r?\n/, 1)[0]?.trim() ?? '';
const tokens = firstLine.split(/\s+/);
- const versionToken = tokens.length === 1
- ? tokens[0]
- : tokens.length === 2 && tokens[0]?.toLowerCase() === 'pi'
- ? tokens[1]
- : undefined;
- return versionToken
- ? normalizeBinaryVersion(versionToken.replace(/^v(?=\d)/, ''))
- : null;
+ const leadingVersion = normalizeVersionToken(tokens[0]);
+ if (leadingVersion) return leadingVersion;
+ if (tokens.length === 2 && NAMED_VERSION_PREFIXES.has(tokens[0]?.toLowerCase() ?? '')) {
+ return normalizeVersionToken(tokens[1]);
+ }
+ return null;
}
/**
diff --git a/apps/desktop/src/main/agent-binaries/index.ts b/apps/desktop/src/main/agent-binaries/index.ts
index f13d500da5..ddd198a360 100644
--- a/apps/desktop/src/main/agent-binaries/index.ts
+++ b/apps/desktop/src/main/agent-binaries/index.ts
@@ -187,6 +187,7 @@ const CONFIG: Record<AgentBinaryKind, AgentBinaryConfig> = {
devBinDir: 'claude-code-bin',
vendorTag: 'claude',
artifactKind: 'gz',
+ preserveLocalVersion: true,
},
codex: {
vendorKey: 'codex',
@@ -197,6 +198,7 @@ const CONFIG: Record<AgentBinaryKind, AgentBinaryConfig> = {
devBinaryName: path.join('bin', process.platform === 'win32' ? 'codex.exe' : 'codex'),
vendorTag: 'codex',
artifactKind: 'gz',
+ preserveLocalVersion: true,
},
pi: {
vendorKey: 'pi',