fix(macos): strip "OpenClaw " prefix before parsing gateway version

`openclaw --version` outputs "OpenClaw 2026.x.y-z" but
readGatewayVersion() passed the full string to Semver.parse(),
which failed on the "OpenClaw " prefix. This caused the app to
fall back to reading package.json from a local source checkout
(~/Projects/openclaw), reporting a false version mismatch.

Strip the product name prefix before parsing so the installed
CLI version is correctly recognized.
This commit is contained in:
huohua-dev
2026-03-24 10:40:12 +08:00
committed by ImLukeF
parent 2de896524f
commit 8545cbd358
2 changed files with 9 additions and 1 deletions

View File

@@ -317,8 +317,13 @@ enum GatewayEnvironment {
bin=\(binary, privacy: .public)
""")
}
let raw = String(data: data, encoding: .utf8)?
var raw = String(data: data, encoding: .utf8)?
.trimmingCharacters(in: .whitespacesAndNewlines)
// `openclaw --version` outputs "OpenClaw 2026.x.y"; strip the product prefix
// so Semver.parse receives only the version token.
if let r = raw, r.lowercased().hasPrefix("openclaw ") {
raw = String(r.dropFirst("openclaw ".count))
}
return Semver.parse(raw)
} catch {
let elapsedMs = Int(Date().timeIntervalSince(start) * 1000)

View File

@@ -19,6 +19,9 @@ struct GatewayEnvironmentTests {
#expect(Semver.parse("invalid") == nil)
#expect(Semver.parse("1.2") == nil)
#expect(Semver.parse("1.2.x") == nil)
// Product-prefixed output from `openclaw --version` should NOT parse as semver
// (the prefix must be stripped by the caller, not the parser).
#expect(Semver.parse("OpenClaw 2026.3.23-1") == nil)
}
@Test func `semver compatibility requires same major and not older`() {