Skip to content

Commit d354617

Browse files
committed
fix(server): parse CLI versions with a "v" prefix
`\b` does not match between the "v" and the major version, so output like "opencode v2.0.3" parsed as null and the OpenCode health check reported a misleading "Unable to determine OpenCode version" error. Accept an optional "v" prefix, matching parseSemver, which already strips a leading "v".
1 parent 9375c77 commit d354617

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎apps/server/src/provider/providerSnapshot.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
1111

1212
import {
1313
isCommandMissingCause,
14+
parseGenericCliVersion,
1415
providerModelsFromSettings,
1516
spawnAndCollect,
1617
} from "./providerSnapshot.ts";
@@ -93,6 +94,29 @@ describe("providerModelsFromSettings", () => {
9394
});
9495
});
9596

97+
describe("parseGenericCliVersion", () => {
98+
it("parses a bare version", () => {
99+
expect(parseGenericCliVersion("1.14.19")).toBe("1.14.19");
100+
});
101+
102+
it("parses a v-prefixed version", () => {
103+
expect(parseGenericCliVersion("opencode v2.0.3")).toBe("2.0.3");
104+
expect(parseGenericCliVersion("v22.19.0")).toBe("22.19.0");
105+
});
106+
107+
it("parses a version embedded in other output", () => {
108+
expect(parseGenericCliVersion("codex-cli 0.53.0 (build abc)")).toBe("0.53.0");
109+
});
110+
111+
it("returns null when no version is present", () => {
112+
expect(parseGenericCliVersion("no version here")).toBeNull();
113+
});
114+
115+
it("ignores versions glued to other word characters", () => {
116+
expect(parseGenericCliVersion("build2.0.3artifact")).toBeNull();
117+
});
118+
});
119+
96120
describe("ProviderCommandNotFoundError", () => {
97121
it("classifies normalized platform failures without parsing messages", () => {
98122
expect(

‎apps/server/src/provider/providerSnapshot.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,14 @@ export const spawnAndCollect = (binaryPath: string, command: ChildProcess.Comman
107107
return result;
108108
}).pipe(Effect.scoped);
109109

110+
/**
111+
* Return the first semantic version found in CLI output, or null. Accepts a
112+
* leading "v" (for example `opencode v2.0.3`).
113+
*/
110114
export function parseGenericCliVersion(output: string): string | null {
111-
const match = output.match(/\b(\d+\.\d+\.\d+)\b/);
115+
// "opencode v2.0.3"-style output: the optional "v" has to be consumed first,
116+
// since "v2" itself contains no word boundary.
117+
const match = output.match(/\bv?(\d+\.\d+\.\d+)\b/);
112118
return match?.[1] ?? null;
113119
}
114120

0 commit comments

Comments
 (0)