graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
update: graff update works on Windows
justrach7927240b32e5
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 16bc711c..a5e51e14 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -259,3 +259,30 @@ jobs:- name: smoke --helpshell: cmdrun: zig-out\bin\graff.exe --help++ # graff update on Windows runs the release's install.ps1 (there is no+ # /bin/sh). It must replace the RUNNING graff.exe: install.ps1 renames it+ # aside. This branch's install.ps1 is served locally; the release asset it+ # installs is the latest published one.+ - name: graff update replaces a running graff.exe (Windows)+ shell: pwsh+ env:+ GH_TOKEN: ${{ github.token }}+ run: |+ $dir = Join-Path $env:RUNNER_TEMP 'graff-update'+ New-Item -ItemType Directory -Force -Path $dir | Out-Null+ Copy-Item zig-out\bin\graff.exe (Join-Path $dir 'graff.exe')+ $server = Start-Process python -ArgumentList '-m', 'http.server', '8765', '--bind', '127.0.0.1' -WorkingDirectory $PWD -PassThru+ Start-Sleep -Seconds 2+ try {+ $env:GRAFF_INSTALL_PS1_URL = 'http://127.0.0.1:8765/install.ps1'+ & (Join-Path $dir 'graff.exe') update --force+ if ($LASTEXITCODE -ne 0) { throw "graff update exited $LASTEXITCODE" }+ } finally {+ Stop-Process -Id $server.Id -Force -ErrorAction SilentlyContinue+ }+ $after = & (Join-Path $dir 'graff.exe') --version | Select-Object -First 1+ $latest = (Invoke-RestMethod https://api.github.com/repos/justrach/codegraff/releases/latest -Headers @{ Authorization = "Bearer $env:GH_TOKEN" }).tag_name.TrimStart('v')+ if ($after -ne "graff $latest") { throw "expected 'graff $latest' after the update, got '$after'" }+ if (-not (Test-Path (Join-Path $dir 'graff.exe.old'))) { throw 'the running graff.exe was not renamed aside' }+ Write-Host "graff update on Windows: $after installed over the running build"diff --git a/src/cli.zig b/src/cli.zigindex 582f29f6..b09d4250 100644--- a/src/cli.zig+++ b/src/cli.zig@@ -9,6 +9,7 @@//! since they're only ever printed from within main().const std = @import("std");+const builtin = @import("builtin");const Io = std.Io;const Allocator = std.mem.Allocator;@@ -170,6 +171,7 @@ pub const usage_text =\\ graff [-p] "prompt" one-shot: run the prompt, print the answer, exit\\ graff login get a codegraff key (device-code OAuth)\\ graff login chatgpt ChatGPT sign-in (also: codex, openai)+ \\ graff login anthropic Anthropic Console sign-in (runs `ant auth login`)\\ graff login kimi Kimi Code OAuth login (device-code)\\ graff login xai Grok/SuperGrok OAuth login (device-code)\\ graff login zai Z.AI Coding Plan OAuth login@@ -364,6 +366,8 @@ pub fn updateCommand(}try out.flush();+ if (builtin.os.tag == .windows) return @import("update_windows.zig").run(io, gpa, environ, out);+// Delegate download/codesign/atomic swap to install.sh. Inherit our stdio// so its progress (and any sudo prompt) reaches the terminal directly.// Download to a temp file, then run it: piping curl into sh would mask adiff --git a/src/test_hooks.zig b/src/test_hooks.zigindex 23447698..9b742058 100644--- a/src/test_hooks.zig+++ b/src/test_hooks.zig@@ -393,6 +393,7 @@ test {_ = @import("update_service.zig");_ = @import("update_cmd.zig");_ = @import("update_tests.zig");+ _ = @import("update_windows.zig");_ = @import("mcp_elicitation.zig"); // #768: Computer Use form elicitation_ = @import("skill_runtime_adapter.zig"); // #768: read-only get_app_state adapter_ = @import("edit_worktree_tests.zig"); // #747: edit lands on the selected worktreediff --git a/src/update_windows.zig b/src/update_windows.zignew file mode 100644index 00000000..4c1f0da7--- /dev/null+++ b/src/update_windows.zig@@ -0,0 +1,76 @@+//! `graff update` on Windows. The macOS/Linux path pipes install.sh through+//! /bin/sh, which Windows does not have, so updating died with "could not+//! launch installer". Here the release's install.ps1 runs under PowerShell.+//! It verifies SHA256SUMS and, because a running graff.exe cannot be+//! overwritten, renames it aside before copying the new one in. Both URL and+//! directory travel as environment variables, never interpolated into the+//! command string.++const std = @import("std");+const Io = std.Io;+const Allocator = std.mem.Allocator;++pub const default_url = "https://github.com/justrach/codegraff/releases/latest/download/install.ps1";++/// The PowerShell program: download the installer to a temp file, run it,+/// clean up, and exit non-zero on any failure.+pub const script =+ "$f = Join-Path ([IO.Path]::GetTempPath()) ('graff-update-' + [guid]::NewGuid().ToString('N') + '.ps1'); " +++ "try { Invoke-WebRequest -UseBasicParsing -Uri $env:GRAFF_INSTALL_PS1_URL -OutFile $f; & $f; exit 0 } " +++ "catch { Write-Host (' error: ' + $_); exit 1 } " +++ "finally { Remove-Item -Force -ErrorAction SilentlyContinue $f }";++/// The installer URL: `GRAFF_INSTALL_PS1_URL`, else a `GRAFF_INSTALL_URL`+/// that names a .ps1, else the latest release's install.ps1.+pub fn installerUrl(environ: *const std.process.Environ.Map) []const u8 {+ if (environ.get("GRAFF_INSTALL_PS1_URL")) |url| return url;+ if (environ.get("GRAFF_INSTALL_URL")) |url| {+ if (std.ascii.endsWithIgnoreCase(url, ".ps1")) return url;+ }+ return default_url;+}++/// Run install.ps1 into the running graff.exe's own directory. Returns+/// normally on success; exits the process with a message on failure.+pub fn run(io: Io, gpa: Allocator, environ: *const std.process.Environ.Map, out: *Io.Writer) !void {+ const exe = std.process.executablePathAlloc(io, gpa) catch std.process.fatal("update: cannot locate the running graff.exe", .{});+ defer gpa.free(exe);+ const dir = std.fs.path.dirname(exe) orelse std.process.fatal("update: cannot locate the running graff.exe", .{});++ var env = try environ.clone(gpa);+ defer env.deinit();+ try env.put("GRAFF_INSTALL_PS1_URL", installerUrl(environ));+ try env.put("GRAFF_INSTALL_DIR", dir);+ // Updating keeps the install where it is; PATH already finds it.+ try env.put("GRAFF_NO_PATH", "1");++ var child = std.process.spawn(io, .{+ .argv = &.{ "powershell.exe", "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Command", script },+ .environ_map = &env,+ }) catch |err|+ std.process.fatal("update: could not launch PowerShell: {t}", .{err});+ const term = child.wait(io) catch std.process.fatal("update: installer did not exit cleanly", .{});+ if (term != .exited or term.exited != 0)+ std.process.fatal("update: installer failed — try again or run: irm {s} | iex", .{default_url});+ try out.writeAll("✓ update installed — restart every running graff session to load the new binary\n");+ try out.flush();+}++test "installerUrl prefers an explicit ps1 and ignores install.sh overrides" {+ const gpa = std.testing.allocator;+ var env: std.process.Environ.Map = .init(gpa);+ defer env.deinit();+ try std.testing.expectEqualStrings(default_url, installerUrl(&env));+ try env.put("GRAFF_INSTALL_URL", "https://example.test/install.sh");+ try std.testing.expectEqualStrings(default_url, installerUrl(&env));+ try env.put("GRAFF_INSTALL_URL", "https://example.test/install.PS1");+ try std.testing.expectEqualStrings("https://example.test/install.PS1", installerUrl(&env));+ try env.put("GRAFF_INSTALL_PS1_URL", "https://example.test/pinned.ps1");+ try std.testing.expectEqualStrings("https://example.test/pinned.ps1", installerUrl(&env));+}++test "the PowerShell program reads its inputs from the environment only" {+ try std.testing.expect(std.mem.indexOf(u8, script, "$env:GRAFF_INSTALL_PS1_URL") != null);+ try std.testing.expect(std.mem.indexOf(u8, script, "exit 1") != null);+ try std.testing.expect(std.mem.indexOf(u8, script, "http") == null);+}