graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Accept 4-segment CLI versions in update checks; desktop stays 3-part
Cursor Agentf28716cadab0
diff --git a/apps/native/desktop/update.zig b/apps/native/desktop/update.zigindex 411ef853..8217fd05 100644--- a/apps/native/desktop/update.zig+++ b/apps/native/desktop/update.zig@@ -31,7 +31,11 @@ pub const Version = struct {patch: u32 = 0,/// `v0.0.286`, `0.0.286`, `0.0.286-rc1` — anything after the patch digits- /// is ignored, so a pre-release tag still compares on its numbers.+ /// is ignored, so a pre-release tag still compares on its numbers. A+ /// fourth CLI hotfix segment (`0.0.300.1`) is likewise ignored: desktop+ /// bundles stay 3-part (see electron/update-artifacts.cjs), so comparing+ /// a segment the bundle can never carry would offer an update that never+ /// converges. 4-part tags are CLI-only and carry no desktop asset.pub fn parse(text: []const u8) ?Version {var rest = std.mem.trim(u8, text, " \t\r\n\"");if (rest.len > 0 and (rest[0] == 'v' or rest[0] == 'V')) rest = rest[1..];@@ -326,6 +330,17 @@ test "a tag parses with or without its v, and a partial one still reads" {try std.testing.expect(Version.parse("main") == null);}+test "a four-segment CLI tag compares on its three-part base" {+ // Desktop bundles stay 3-part while the CLI accepts 4-part hotfixes+ // (see electron/update-artifacts.cjs). The trailing segment is ignored+ // so a CLI-only 0.0.300.1 tag never offers a desktop "update" to an+ // installed 0.0.300 build — there is no 4-part bundle to converge on.+ try std.testing.expectEqual(Version{ .major = 0, .minor = 0, .patch = 300 }, Version.parse("v0.0.300.1").?);+ const installed = Version.parse("0.0.300").?;+ try std.testing.expect(!Version.parse("v0.0.300.1").?.newerThan(installed));+ try std.testing.expect(Version.parse("v0.0.301").?.newerThan(installed));+}+test "the bundle version is read out of a plist" {const plist =\\<plist version="1.0">diff --git a/apps/native/electron/distribute.sh b/apps/native/electron/distribute.shindex 3e31b928..1b64c5d7 100755--- a/apps/native/electron/distribute.sh+++ b/apps/native/electron/distribute.sh@@ -17,6 +17,10 @@ cleanup() { rm -rf "$work"; }trap cleanup EXITditto "$source_app" "$app"version="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$app/Contents/Info.plist")"+# Desktop stays 3-part while the CLI accepts 4-part hotfixes (0.0.300.1):+# electron-updater compares the feed as semver and the notarization chain is+# only verified for 3-part (see update-artifacts.cjs). 4-part tags are+# CLI-only and must never reach distribution.[[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo 'Distribution requires a stable version.' >&2; exit 1; }# Only distribution builds opt into online updates; include the feed in the signature.bun "$here/update-artifacts.cjs" config "$app/Contents/Resources/app-update.yml"diff --git a/apps/native/electron/update-artifacts.cjs b/apps/native/electron/update-artifacts.cjsindex 6489c7b4..21524bda 100644--- a/apps/native/electron/update-artifacts.cjs+++ b/apps/native/electron/update-artifacts.cjs@@ -3,6 +3,12 @@ const path = require('node:path');const crypto = require('node:crypto');const feed = { provider: 'generic', url: 'https://github.com/justrach/codegraff/releases/latest/download/', updaterCacheDirName: 'codegraff-updater' };function writeManifest(version, archive, output) {+ // Desktop bundles stay 3-part even though the CLI accepts 4-part hotfix+ // versions (0.0.300.1): electron-updater compares feed versions as semver,+ // which has no fourth segment, and the Apple chain (Info.plist marketing+ // version, notarization, spctl) is only verified for 3-part. Ship desktop+ // fixes as 3-part releases; 4-part tags are CLI-only and carry no desktop+ // asset, so the desktop updaters below never see one.if (!/^\d+\.\d+\.\d+$/.test(version)) throw Error('Only stable versions can enter the desktop update feed.');const url = path.basename(archive);if (url !== `Codegraff-${version}-macos-arm64.zip`) throw Error('Update archive name must match its version and architecture.');diff --git a/apps/native/electron/update-artifacts.test.cjs b/apps/native/electron/update-artifacts.test.cjsindex 32e648af..54f8f3c5 100644--- a/apps/native/electron/update-artifacts.test.cjs+++ b/apps/native/electron/update-artifacts.test.cjs@@ -16,5 +16,7 @@ test('release metadata can be read by the updater and identifies the exact archiexpect(load(JSON.stringify(feed)).url).toBe('https://github.com/justrach/codegraff/releases/latest/download/');expect(() => writeManifest('1.2.4', file, manifest)).toThrow('archive name');expect(() => writeManifest('1.2.3-beta.1', file, manifest)).toThrow('stable');+ // Four-segment CLI hotfixes (0.0.300.1) never enter the desktop feed.+ expect(() => writeManifest('1.2.3.4', file, manifest)).toThrow('stable');} finally { fs.rmSync(dir, { recursive: true, force: true }); }});diff --git a/src/version_status.zig b/src/version_status.zigindex 860f2001..10cc8dd2 100644--- a/src/version_status.zig+++ b/src/version_status.zig@@ -24,15 +24,19 @@ const Version = struct {major: u32,minor: u32,patch: u32,+ // CLI hotfix segment (0.0.300.1); 0 when the tag has three parts.+ // Desktop bundles stay 3-part (see electron/update-artifacts.cjs).+ build: u32 = 0,fn eql(self: Version, other: Version) bool {- return self.major == other.major and self.minor == other.minor and self.patch == other.patch;+ return self.major == other.major and self.minor == other.minor and self.patch == other.patch and self.build == other.build;}fn order(self: Version, other: Version) std.math.Order {if (self.major != other.major) return std.math.order(self.major, other.major);if (self.minor != other.minor) return std.math.order(self.minor, other.minor);- return std.math.order(self.patch, other.patch);+ if (self.patch != other.patch) return std.math.order(self.patch, other.patch);+ return std.math.order(self.build, other.build);}};@@ -48,8 +52,18 @@ fn parseVersion(s: []const u8) ?Version {const major_s = it.next() orelse return null;const minor_s = it.next() orelse return null;const patch_s = it.next() orelse return null;+ const build_s = it.next();+ if (it.next() != null) return null;const major = std.fmt.parseInt(u32, major_s, 10) catch return null;const minor = std.fmt.parseInt(u32, minor_s, 10) catch return null;+ if (build_s) |b| {+ // A pre-release suffix belongs to the last segment only; anything+ // after the patch digits when a fourth segment follows is malformed.+ const patch = std.fmt.parseInt(u32, patch_s, 10) catch return null;+ const build_digits = std.mem.indexOfAny(u8, b, "-+") orelse b.len;+ const build = std.fmt.parseInt(u32, b[0..build_digits], 10) catch return null;+ return .{ .major = major, .minor = minor, .patch = patch, .build = build };+ }const patch_digits = std.mem.indexOfAny(u8, patch_s, "-+") orelse patch_s.len;const patch = std.fmt.parseInt(u32, patch_s[0..patch_digits], 10) catch return null;return .{ .major = major, .minor = minor, .patch = patch };@@ -63,7 +77,10 @@ fn isCleanReleaseVersion(s: []const u8) bool {'.' => dots += 1,else => return false,};- return dots == 2;+ // Releases are 3-part (0.0.301); CLI hotfixes add a fourth segment+ // (0.0.300.1). Desktop bundles stay 3-part (see+ // apps/native/electron/update-artifacts.cjs).+ return dots == 2 or dots == 3;}/// Pure comparison. `latest_tag` is the GitHub tag (with or without `v`);@@ -192,6 +209,30 @@ test "unavailable and unparseable latest checks do not guess" {try std.testing.expectEqual(Failure.latest_tag, compare("0.0.292", "latest").failure);}+test "four-segment hotfix versions order between their neighbors" {+ // 0.0.300 < 0.0.300.1 < 0.0.301, and a missing fourth segment reads as 0.+ try std.testing.expectEqual(State.older, compare("0.0.300", "v0.0.300.1").state);+ try std.testing.expectEqual(State.newer, compare("0.0.300.1", "v0.0.300").state);+ try std.testing.expectEqual(State.older, compare("0.0.300.1", "v0.0.301").state);+ try std.testing.expectEqual(State.current, compare("0.0.300.1", "v0.0.300.1").state);+ try std.testing.expectEqual(State.current, compare("0.0.300", "v0.0.300.0").state);+ try std.testing.expectEqual(State.current, compare("0.0.300.0", "v0.0.300").state);+ try std.testing.expectEqual(std.math.Order.lt, compare("0.0.300", "v0.0.300.1").order.?);+ try std.testing.expectEqual(std.math.Order.gt, compare("0.0.300.2", "v0.0.300.1").order.?);+}++test "four-segment dev builds and the reinstall guard follow the same policy" {+ const dev = compare("0.0.300.1-2-gabc", "v0.0.300.1");+ try std.testing.expectEqual(State.dev, dev.state);+ try std.testing.expectEqual(std.math.Order.eq, dev.order.?);+ try std.testing.expect(alreadyHasRelease("0.0.300.1", "v0.0.300.1"));+ try std.testing.expect(alreadyHasRelease("0.0.300.1", "v0.0.300"));+ try std.testing.expect(!alreadyHasRelease("0.0.300", "v0.0.300.1"));+ // Five segments are not a release on either side.+ try std.testing.expectEqual(Failure.latest_tag, compare("0.0.300.1", "v0.0.300.1.2").failure);+ try std.testing.expectEqual(State.dev, compare("0.0.300.1.2", "v0.0.300.1").state);+}+test "alreadyHasRelease refuses a reinstall when disk is current or newer" {try std.testing.expect(alreadyHasRelease("0.0.292", "v0.0.292"));try std.testing.expect(alreadyHasRelease("0.0.293", "v0.0.292"));