graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Offer 0.0.x.y versions on the desktop updater
justrach128d4bae6770
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 2657fc5e..e60de370 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -12,6 +12,8 @@ current is part of cutting a release.## v0.0.302.3+- Ctrl-V screenshot paste is not killed by a leftover Esc (`clipboard helper unavailable`).+- Desktop auto-update accepts 4-part hotfix versions (`0.0.302.3`), not only `0.0.xxx`.- Task workspaces copy gitignored files (`.worktreeinclude` or Conductor `file_include_globs`) and run setup/run/archive scripts (ADR 0153). Desktop Tools: New task workspace, Run, Archive.## v0.0.302.2diff --git a/apps/native/desktop/update.zig b/apps/native/desktop/update.zigindex 8217fd05..01f839b2 100644--- a/apps/native/desktop/update.zig+++ b/apps/native/desktop/update.zig@@ -29,18 +29,18 @@ pub const Version = struct {major: u32 = 0,minor: u32 = 0,patch: u32 = 0,+ /// CLI/desktop hotfix segment (`0.0.302.3`); 0 when the tag has three parts.+ build: 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. 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.+ /// `v0.0.286`, `0.0.286`, `0.0.286-rc1` — anything after the last numeric+ /// segment is ignored, so a pre-release tag still compares on its numbers.+ /// A fourth hotfix segment (`0.0.302.3`) is part of the order: 0.0.302 <+ /// 0.0.302.3 < 0.0.303.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..];var out: Version = .{};- const fields = [_]*u32{ &out.major, &out.minor, &out.patch };+ const fields = [_]*u32{ &out.major, &out.minor, &out.patch, &out.build };var i: usize = 0;for (fields, 0..) |field, n| {if (i >= rest.len or !std.ascii.isDigit(rest[i])) return if (n == 0) null else out;@@ -61,7 +61,8 @@ pub const Version = struct {pub fn newerThan(self: Version, other: Version) bool {if (self.major != other.major) return self.major > other.major;if (self.minor != other.minor) return self.minor > other.minor;- return self.patch > other.patch;+ if (self.patch != other.patch) return self.patch > other.patch;+ return self.build > other.build;}};@@ -330,15 +331,13 @@ 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").?);+test "a four-segment hotfix is newer than its three-part base" {+ try std.testing.expectEqual(Version{ .major = 0, .minor = 0, .patch = 300, .build = 1 }, 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));+ try std.testing.expect(Version.parse("v0.0.300.1").?.newerThan(installed));+ try std.testing.expect(Version.parse("v0.0.300.3").?.newerThan(Version.parse("v0.0.300.2").?));+ try std.testing.expect(Version.parse("v0.0.301").?.newerThan(Version.parse("v0.0.300.9").?));+ try std.testing.expect(!Version.parse("v0.0.300.1").?.newerThan(Version.parse("v0.0.300.1").?));}test "the bundle version is read out of a plist" {diff --git a/apps/native/electron/distribute.sh b/apps/native/electron/distribute.shindex addec0ad..9da709e8 100755--- a/apps/native/electron/distribute.sh+++ b/apps/native/electron/distribute.sh@@ -18,11 +18,9 @@ trap cleanup EXITditto "$source_app" "$app"bun "$here/release-identity.cjs" "$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; }+# 3-part (0.0.302) or 4-part hotfix (0.0.302.3). The feed maps 4-part onto+# semver so electron-updater can compare; the zip name keeps the graff version.+[[ "$version" =~ ^[0-9]+\.[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"bun "$here/sign-bundle.mjs" "$app"diff --git a/apps/native/electron/publish-updates.sh b/apps/native/electron/publish-updates.shindex 79d57fc3..f070ace1 100644--- a/apps/native/electron/publish-updates.sh+++ b/apps/native/electron/publish-updates.sh@@ -18,8 +18,9 @@ spctl --assess --type open --context context:primary-signature "$out/Codegraff-mbun -e 'const fs=require("node:fs"),path=require("node:path"),crypto=require("node:crypto");const [tag,out]=process.argv.slice(1),m=JSON.parse(fs.readFileSync(path.join(out,"latest-mac.yml")));-if("v"+m.version!==tag||m.files.length!==1)throw Error("Release version mismatch");-const f=m.files[0];if(f.url!==`Codegraff-${m.version}-macos-arm64.zip`)throw Error("Invalid archive name");+const graff=m.graffVersion||m.version;+if("v"+graff!==tag||m.files.length!==1)throw Error("Release version mismatch");+const f=m.files[0];if(f.url!==`Codegraff-${graff}-macos-arm64.zip`)throw Error("Invalid archive name");const bytes=fs.readFileSync(path.join(out,f.url));if(bytes.length!==f.size||crypto.createHash("sha512").update(bytes).digest("base64")!==f.sha512)throw Error("Update checksum mismatch");' "$tag" "$out"diff --git a/apps/native/electron/update-artifacts.cjs b/apps/native/electron/update-artifacts.cjsindex 0dcd54f4..00ac7abc 100644--- a/apps/native/electron/update-artifacts.cjs+++ b/apps/native/electron/update-artifacts.cjs@@ -9,19 +9,18 @@ const feed = { provider: 'generic', url: 'https://github.com/justrach/codegraff/const bundleConfigRel = path.join('Contents', 'Resources', 'app-update.yml');// ditto --keepParent zips Codegraff.app itself, so this is the member path.const archiveMember = 'Codegraff.app/' + bundleConfigRel.split(path.sep).join('/');+const { isReleaseVersion, toSemver } = require('./update-version.cjs');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.');+ // electron-updater compares feed versions as semver (no fourth numeric+ // segment). 4-part hotfixes (0.0.302.3) still ship as desktop updates:+ // the zip keeps the graff version in its name, and `version` in the feed+ // is the mapped semver (0.302.3) so 0.0.302 apps see it as newer.+ if (!isReleaseVersion(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.');const bytes = fs.readFileSync(archive);const sha512 = crypto.createHash('sha512').update(bytes).digest('base64');- const manifest = { version, files: [{ url, sha512, size: bytes.length }], path: url, sha512, releaseDate: new Date().toISOString() };+ const manifest = { version: toSemver(version), graffVersion: version, files: [{ url, sha512, size: bytes.length }], path: url, sha512, releaseDate: new Date().toISOString() };// JSON is valid YAML, and avoids escaping release-controlled filenames by hand.fs.writeFileSync(output, JSON.stringify(manifest, null, 2) + '\n');return manifest;diff --git a/apps/native/electron/update-artifacts.test.cjs b/apps/native/electron/update-artifacts.test.cjsindex 1761ccb7..fcf63212 100644--- a/apps/native/electron/update-artifacts.test.cjs+++ b/apps/native/electron/update-artifacts.test.cjs@@ -10,14 +10,19 @@ test('release metadata can be read by the updater and identifies the exact archiwriteManifest('1.2.3', file, manifest);const data = load(fs.readFileSync(manifest, 'utf8'));expect(data.version).toBe('1.2.3');+ expect(data.graffVersion).toBe('1.2.3');expect(data.files[0].url).toBe(path.basename(file));expect(data.files[0].size).toBe(fs.statSync(file).size);expect(Buffer.from(data.files[0].sha512, 'base64').length).toBe(64);expect(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');+ const hotfixZip = path.join(dir, 'Codegraff-0.0.302.3-macos-arm64.zip'), hotfixManifest = path.join(dir, 'latest-mac-hotfix.yml');+ fs.writeFileSync(hotfixZip, 'archive fixture');+ const hotfix = writeManifest('0.0.302.3', hotfixZip, hotfixManifest);+ expect(hotfix.version).toBe('0.302.3');+ expect(hotfix.graffVersion).toBe('0.0.302.3');+ expect(hotfix.files[0].url).toBe('Codegraff-0.0.302.3-macos-arm64.zip');} finally { fs.rmSync(dir, { recursive: true, force: true }); }});// Minimal stored (uncompressed) zip writer: local headers, centraldiff --git a/apps/native/electron/update-version.cjs b/apps/native/electron/update-version.cjsnew file mode 100644index 00000000..9f07ad04--- /dev/null+++ b/apps/native/electron/update-version.cjs@@ -0,0 +1,36 @@+// Map graff 3/4-part versions onto semver so electron-updater can compare+// hotfix tags like 0.0.302.3. Semver has no fourth numeric segment; 0.0.X.Y+// becomes 0.X.Y (and 0.0.X becomes 0.X.0). Other 3-part versions stay as-is.+function isReleaseVersion(version) {+ return /^\d+\.\d+\.\d+(?:\.\d+)?$/.test(String(version));+}++function parts(version) {+ const m = String(version).trim().replace(/^[vV]/, '').match(/^(\d+)\.(\d+)\.(\d+)(?:\.(\d+))?$/);+ if (!m) return null;+ return { a: Number(m[1]), b: Number(m[2]), c: Number(m[3]), d: m[4] == null ? 0 : Number(m[4]), hotfix: m[4] != null };+}++function toSemver(version) {+ const p = parts(version);+ if (!p) throw Error(`Not a graff release version: ${version}`);+ if (p.a === 0 && p.b === 0) return `0.${p.c}.${p.d}`;+ if (!p.hotfix) return `${p.a}.${p.b}.${p.c}`;+ return `${p.a}.${p.b * 1_000_000 + p.c}.${p.d}`;+}++function fromSemver(mapped) {+ const m = String(mapped).trim().match(/^(\d+)\.(\d+)\.(\d+)$/);+ if (!m) return String(mapped);+ const a = Number(m[1]), x = Number(m[2]), d = Number(m[3]);+ if (a === 0) return d === 0 ? `0.0.${x}` : `0.0.${x}.${d}`;+ return String(mapped);+}++function displayVersion(info) {+ if (info && typeof info.graffVersion === 'string' && info.graffVersion) return info.graffVersion;+ if (info && typeof info.version === 'string') return fromSemver(info.version);+ return info?.version;+}++module.exports = { isReleaseVersion, toSemver, fromSemver, displayVersion };diff --git a/apps/native/electron/update-version.test.cjs b/apps/native/electron/update-version.test.cjsnew file mode 100644index 00000000..4c8de4ec--- /dev/null+++ b/apps/native/electron/update-version.test.cjs@@ -0,0 +1,59 @@+const { test, expect } = require('bun:test');+const { isReleaseVersion, toSemver, fromSemver, displayVersion } = require('./update-version.cjs');++function semverGt(a, b) {+ const pa = String(a).split('.').map(Number);+ const pb = String(b).split('.').map(Number);+ while (pa.length < 3) pa.push(0);+ while (pb.length < 3) pb.push(0);+ for (let i = 0; i < 3; i++) if (pa[i] !== pb[i]) return pa[i] > pb[i];+ return false;+}++test('3-part and 4-part hotfix versions are both release versions', () => {+ expect(isReleaseVersion('0.0.302')).toBe(true);+ expect(isReleaseVersion('0.0.302.3')).toBe(true);+ expect(isReleaseVersion('1.2.3')).toBe(true);+ expect(isReleaseVersion('1.2.3-beta.1')).toBe(false);+ expect(isReleaseVersion('0.0.302.3.1')).toBe(false);+});++test('0.0.x.y maps onto semver that orders like graff hotfixes', () => {+ expect(toSemver('0.0.302')).toBe('0.302.0');+ expect(toSemver('0.0.302.3')).toBe('0.302.3');+ expect(toSemver('v0.0.303')).toBe('0.303.0');+ expect(toSemver('1.2.3')).toBe('1.2.3');+ expect(semverGt(toSemver('0.0.302.1'), toSemver('0.0.302'))).toBe(true);+ expect(semverGt(toSemver('0.0.302.3'), toSemver('0.0.302.2'))).toBe(true);+ expect(semverGt(toSemver('0.0.303'), toSemver('0.0.302.9'))).toBe(true);+ expect(semverGt(toSemver('0.0.302.3'), toSemver('0.0.302'))).toBe(true);+ // Installed 3-part apps still see a 4-part feed as newer.+ expect(semverGt(toSemver('0.0.302.3'), '0.0.302')).toBe(true);+});++test('mapped 0.0.x.y versions round-trip for UI copy', () => {+ expect(fromSemver(toSemver('0.0.302'))).toBe('0.0.302');+ expect(fromSemver(toSemver('0.0.302.3'))).toBe('0.0.302.3');+ expect(fromSemver('1.2.3')).toBe('1.2.3');+ expect(displayVersion({ version: '0.302.3' })).toBe('0.0.302.3');+ expect(displayVersion({ version: '0.302.3', graffVersion: '0.0.302.3' })).toBe('0.0.302.3');+});++test('hotfix feed keeps the graff zip name and a comparable semver version', () => {+ const fs = require('node:fs'), os = require('node:os'), path = require('node:path');+ const { writeManifest } = require('./update-artifacts.cjs');+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'graff-hotfix-feed-'));+ try {+ const file = path.join(dir, 'Codegraff-0.0.302.3-macos-arm64.zip');+ fs.writeFileSync(file, 'archive fixture');+ const manifest = writeManifest('0.0.302.3', file, path.join(dir, 'latest-mac.yml'));+ expect(manifest.version).toBe('0.302.3');+ expect(manifest.graffVersion).toBe('0.0.302.3');+ expect(manifest.files[0].url).toBe('Codegraff-0.0.302.3-macos-arm64.zip');+ const onDisk = JSON.parse(fs.readFileSync(path.join(dir, 'latest-mac.yml'), 'utf8'));+ expect(onDisk.version).toBe('0.302.3');+ expect(onDisk.graffVersion).toBe('0.0.302.3');+ } finally {+ fs.rmSync(dir, { recursive: true, force: true });+ }+});diff --git a/apps/native/electron/updater-runtime.cjs b/apps/native/electron/updater-runtime.cjsindex bfae7b54..fdaaf5a2 100644--- a/apps/native/electron/updater-runtime.cjs+++ b/apps/native/electron/updater-runtime.cjs@@ -1,2 +1,17 @@// Bundled with Bun for the packaged main process; Electron remains external.+// electron-updater parses app.getVersion() as semver, which rejects 0.0.X.Y.+// Map only that read so the UI and Info.plist can keep the graff version.+const { toSemver } = require('./update-version.cjs');+try {+ const { app } = require('electron');+ if (typeof app.getVersion === 'function' && !app.__graffVersionMapped) {+ const real = app.getVersion.bind(app);+ app.getVersion = () => {+ try { return toSemver(real()); } catch { return real(); }+ };+ app.__graffVersionMapped = true;+ }+} catch {+ // Tests and non-Electron loads still export autoUpdater.+}module.exports = require('electron-updater').autoUpdater;diff --git a/apps/native/electron/updates.cjs b/apps/native/electron/updates.cjsindex 5dab3726..7b6e13df 100644--- a/apps/native/electron/updates.cjs+++ b/apps/native/electron/updates.cjs@@ -1,5 +1,6 @@const fs = require('node:fs');const path = require('node:path');+const { displayVersion } = require('./update-version.cjs');const FIRST_CHECK_MS = 30_000;const POLL_MS = 6 * 60 * 60 * 1000;@@ -51,17 +52,18 @@ function createUpdates({ updater, version, available = true, automatic = true, pupdater.disableDifferentialDownload = true;updater.logger = null;updater.on('checking-for-update', () => emit({ status: 'checking', message: undefined }));- updater.on('update-available', info => emit({ status: 'downloading', version: info.version, percent: 0 }));+ updater.on('update-available', info => emit({ status: 'downloading', version: displayVersion(info), percent: 0 }));updater.on('download-progress', progress => {const percent = Math.max(0, Math.min(100, Math.floor(progress.percent || 0)));if (percent !== state.percent) emit({ status: 'downloading', percent });});updater.on('update-not-available', () => emit({ status: 'current', version: undefined, percent: undefined }));updater.on('update-downloaded', info => {- emit({ status: 'ready', version: info.version, percent: 100 });- if (onReady && info.version && info.version !== state.prompted) {- state.prompted = info.version; // once per version: dismiss means Later, never a loop- onReady(info.version);+ const shown = displayVersion(info);+ emit({ status: 'ready', version: shown, percent: 100 });+ if (onReady && shown && shown !== state.prompted) {+ state.prompted = shown; // once per version: dismiss means Later, never a loop+ onReady(shown);}});updater.on('error', () => emit({ status: 'error', message: 'Could not update. Check your connection and try again.' }));