graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Ship run-time text gzipped and the sign-in images as WebP
Rach Pradhan75e45436d7ac
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d2da8284..3020680b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -20,6 +20,7 @@ current is part of cutting a release.- Includes independent conversation forks for subagents and workflow fan-out, optional retained workers, and bounded workflow synthesis that preserves earlier findings.- Release binaries are built ReleaseSafe: an out-of-range index or overflow stops graff with a clear panic instead of silently corrupting state, and the stripped binaries are about 17-20% smaller.- `graff learn` is no longer part of the release binary, which is about 300 KB smaller for it; sessions no longer start background learning trials.+- Release binaries are another 50-120 KB smaller: the MCP installer and two HTML pages ship gzipped, the sign-in page's images are WebP, and graff's own code on Windows drops its unwind tables like the other platforms.- Retains all changes from v0.302.51.## v0.302.51diff --git a/build.zig b/build.zigindex 38b3ddd7..19aefdc1 100644--- a/build.zig+++ b/build.zig@@ -46,8 +46,9 @@ pub fn build(b: *std.Build) void {opts.addOption(bool, "learn", learn);// Release binaries ship without unwind tables or frame pointers: they are- // stripped, so a panic can't print a useful trace anyway. Windows keeps its- // tables because the MinGW startup code registers SEH handlers with them.+ // stripped, so a panic can't print a useful trace anyway. On Windows only+ // graff's module drops them: the root's setting also builds the MinGW+ // startup code, which registers SEH handlers and needs its tables.const no_unwind = lean_release and target.result.os.tag != .windows;// graff's own code is its own module so it keeps the requested build mode// (ReleaseSafe checks overflow, bounds and union tags). The root module@@ -61,7 +62,7 @@ pub fn build(b: *std.Build) void {// Linux cross-builds (x86_64-linux for in-container evals) must say// libc explicitly; macOS resolves it implicitly and never notices..link_libc = true,- .unwind_tables = if (no_unwind) .none else null,+ .unwind_tables = if (lean_release) .none else null,.omit_frame_pointer = if (lean_release) true else null,.error_tracing = if (lean_release) false else null,});@@ -281,7 +282,6 @@ pub fn build(b: *std.Build) void {// into a workspace so zero-configuration learning needs no repo checkout.// Embedded by name (src/learn_assets.zig `@embedFile`s these imports).for ([_]struct { import: []const u8, path: []const u8 }{- .{ .import = "mcp_installer", .path = "scripts/install-mcp.py" },.{ .import = "learn_kit_mutator", .path = "examples/learn_graff_mutator.py" },.{ .import = "learn_kit_evaluator", .path = "examples/learn_graff_evaluator.py" },.{ .import = "learn_kit_case", .path = "examples/learn_graff_case.py" },@@ -294,6 +294,27 @@ pub fn build(b: *std.Build) void {unit_tests.root_module.addAnonymousImport(asset.import, .{ .root_source_file = b.path(asset.path) });}+ // Text only needed at run time ships gzipped; callers inflate it with+ // update_archive.gunzip. Imported as "<name>.gz".+ const gzip_asset = b.addExecutable(.{+ .name = "gzip_asset",+ .root_module = b.createModule(.{+ .root_source_file = b.path("scripts/gzip_asset.zig"),+ .target = b.graph.host,+ }),+ });+ for ([_]struct { import: []const u8, path: []const u8 }{+ .{ .import = "mcp_installer.gz", .path = "scripts/install-mcp.py" },+ .{ .import = "chatgpt_callback.gz", .path = "src/oauth_page/chatgpt_callback.html" },+ .{ .import = "mcp_app_host.gz", .path = "src/mcp_app_host.html" },+ }) |asset| {+ const gzip_run = b.addRunArtifact(gzip_asset);+ gzip_run.addFileArg(b.path(asset.path));+ const gz = gzip_run.addOutputFileArg(asset.import);+ app_mod.addAnonymousImport(asset.import, .{ .root_source_file = gz });+ unit_tests.root_module.addAnonymousImport(asset.import, .{ .root_source_file = gz });+ }+// Bundled skills: SKILL.md playbooks compiled into every binary (embedded// by name in src/skill_docs.zig), so a fresh install already knows how to// author more skills and how to change this workspace's MCP servers.diff --git a/scripts/gzip_asset.zig b/scripts/gzip_asset.zignew file mode 100644index 00000000..768b7bd1--- /dev/null+++ b/scripts/gzip_asset.zig@@ -0,0 +1,26 @@+//! Build-time helper: `gzip_asset <in> <out>` gzips one file. build.zig runs it+//! over text the CLI only needs at run time (an installer script, HTML pages),+//! so the release binary carries those compressed; callers read them back with+//! update_archive.gunzip, which `graff update` already links in.++const std = @import("std");++pub fn main(init: std.process.Init) !void {+ const args = try init.minimal.args.toSlice(init.arena.allocator());+ if (args.len != 3) std.process.fatal("usage: gzip_asset <in> <out>", .{});+ const cwd = std.Io.Dir.cwd();+ const plain = try cwd.readFileAlloc(init.io, args[1], init.gpa, .limited(1 << 24));+ defer init.gpa.free(plain);++ // Compress needs a writer that already has room to emit into.+ var out: std.Io.Writer.Allocating = try .initCapacity(init.gpa, plain.len + 1024);+ defer out.deinit();+ const window = try init.gpa.alloc(u8, std.compress.flate.max_window_len);+ defer init.gpa.free(window);+ const c = try init.gpa.create(std.compress.flate.Compress);+ defer init.gpa.destroy(c);+ c.* = try std.compress.flate.Compress.init(&out.writer, window, .gzip, .best);+ try c.writer.writeAll(plain);+ try c.finish();+ try cwd.writeFile(init.io, .{ .sub_path = args[2], .data = out.written() });+}diff --git a/src/mcp_apps.zig b/src/mcp_apps.zigindex 2e4407f0..5b0b2f3b 100644--- a/src/mcp_apps.zig+++ b/src/mcp_apps.zig@@ -68,7 +68,7 @@ pub fn snapshot(io: Io, a: Allocator, home: []const u8, server: *rpc.Server, uriconst encoder = std.base64.standard.Encoder;const encoded = try a.alloc(u8, encoder.calcSize(payload.len));_ = encoder.encode(encoded, payload);- const template = @embedFile("mcp_app_host.html");+ const template = try @import("update_archive.zig").gunzip(a, @embedFile("mcp_app_host.gz"));const marker = "GRAFF_APP_PAYLOAD";const split = std.mem.indexOf(u8, template, marker).?;const html = try std.mem.concat(a, u8, &.{ template[0..split], encoded, template[split + marker.len ..] });@@ -103,6 +103,12 @@ test "MCP app resources require matching URI and app MIME type" {try std.testing.expect(readResource(parsed.value, "ui://b") == null);}+test "MCP app host page ships gzipped and keeps its payload slot" {+ const page = try @import("update_archive.zig").gunzip(std.testing.allocator, @embedFile("mcp_app_host.gz"));+ defer std.testing.allocator.free(page);+ try std.testing.expect(std.mem.indexOf(u8, page, "GRAFF_APP_PAYLOAD") != null);+}+test "app-only MCP tools stay out of the model catalog" {const p = try std.json.parseFromSlice(Value, std.testing.allocator, "{\"_meta\":{\"ui\":{\"visibility\":[\"app\"]}}}", .{});defer p.deinit();diff --git a/src/mcp_cli.zig b/src/mcp_cli.zigindex 7caea06e..bf68a46c 100644--- a/src/mcp_cli.zig+++ b/src/mcp_cli.zig@@ -294,7 +294,8 @@ pub fn mcpCommand(io: Io, gpa: Allocator, arena: Allocator, home: []const u8, en}const exe = try std.process.executablePathAlloc(io, arena);var argv: std.ArrayList([]const u8) = .empty;- try argv.appendSlice(arena, &.{ "python3", "-c", @embedFile("mcp_installer"), "--binary", exe });+ const installer = try @import("update_archive.zig").gunzip(arena, @embedFile("mcp_installer.gz"));+ try argv.appendSlice(arena, &.{ "python3", "-c", installer, "--binary", exe });try argv.appendSlice(arena, args[1..]);const result = try @import("process_runner.zig").runCappedWithOptions(arena, io, argv.items, 16384, 4096, 30000, .{ .environ_map = environ_map });var buffer: [4096]u8 = undefined;@@ -518,6 +519,12 @@ pub fn mcpCommand(io: Io, gpa: Allocator, arena: Allocator, home: []const u8, entry out.interface.writeAll(" a running session connects it before its next request; otherwise `/mcp trust` if startup is waiting for consent.\n");try out.interface.flush();}+test "graff mcp install: the bundled installer inflates to the whole script" {+ const script = try @import("update_archive.zig").gunzip(std.testing.allocator, @embedFile("mcp_installer.gz"));+ defer std.testing.allocator.free(script);+ try std.testing.expect(std.mem.startsWith(u8, script, "#!/usr/bin/env python3\n"));+ try std.testing.expect(std.mem.indexOf(u8, script, "'--binary', required=True") != null);+}test "trustedMcpEntry: only the exact companion shape skips the consent gate" {var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);defer arena_state.deinit();diff --git a/src/oauth_chatgpt_page.zig b/src/oauth_chatgpt_page.zigindex 68e5df5a..ce1fa47d 100644--- a/src/oauth_chatgpt_page.zig+++ b/src/oauth_chatgpt_page.zig@@ -9,9 +9,9 @@ const Allocator = std.mem.Allocator;pub const State = enum { first, ok, noplan, denied, @"error" };-const template = @embedFile("oauth_page/chatgpt_callback.html");-const emblem = @embedFile("oauth_page/codegraff-emblem-96.png");-const art = @embedFile("oauth_page/auth-handoff-760.jpg");+const template_gz = @embedFile("chatgpt_callback.gz");+const emblem = @embedFile("oauth_page/codegraff-emblem-96.webp");+const art = @embedFile("oauth_page/auth-handoff-760.webp");fn dataUri(arena: Allocator, mime: []const u8, bytes: []const u8) ![]const u8 {const enc = std.base64.standard.Encoder;@@ -35,11 +35,11 @@ fn escapeHtml(arena: Allocator, text: []const u8) ![]const u8 {/// The page body for one outcome. `account` is the signed-in email, shown in/// the states that have one.pub fn render(arena: Allocator, state: State, account: []const u8) ![]const u8 {- var page: []const u8 = template;+ var page: []const u8 = try @import("update_archive.zig").gunzip(arena, template_gz);page = try std.mem.replaceOwned(u8, arena, page, "{{state}}", @tagName(state));page = try std.mem.replaceOwned(u8, arena, page, "{{account}}", try escapeHtml(arena, account));- page = try std.mem.replaceOwned(u8, arena, page, "{{emblem}}", try dataUri(arena, "image/png", emblem));- return std.mem.replaceOwned(u8, arena, page, "{{art}}", try dataUri(arena, "image/jpeg", art));+ page = try std.mem.replaceOwned(u8, arena, page, "{{emblem}}", try dataUri(arena, "image/webp", emblem));+ return std.mem.replaceOwned(u8, arena, page, "{{art}}", try dataUri(arena, "image/webp", art));}/// The whole HTTP response: not cached, no referrer, connection closed.@@ -61,7 +61,7 @@ test "ChatGPT callback page: every state renders complete, escaped and self-conttry std.testing.expect(std.mem.indexOf(u8, page, "{{") == null);// No network fetch while the code is in the address bar.try std.testing.expect(std.mem.indexOf(u8, page, "src=\"http") == null);- try std.testing.expect(std.mem.indexOf(u8, page, "data:image/jpeg;base64,") != null);+ try std.testing.expect(std.mem.indexOf(u8, page, "data:image/webp;base64,") != null);}const hostile = try render(a, .ok, "<script>x</script>@example.com");try std.testing.expect(std.mem.indexOf(u8, hostile, "<script>x") == null);diff --git a/src/oauth_page/auth-handoff-760.jpg b/src/oauth_page/auth-handoff-760.jpgdeleted file mode 100644index f8dc7fe4..00000000Binary files a/src/oauth_page/auth-handoff-760.jpg and /dev/null differdiff --git a/src/oauth_page/auth-handoff-760.webp b/src/oauth_page/auth-handoff-760.webpnew file mode 100644index 00000000..4e0d970fBinary files /dev/null and b/src/oauth_page/auth-handoff-760.webp differdiff --git a/src/oauth_page/codegraff-emblem-96.png b/src/oauth_page/codegraff-emblem-96.pngdeleted file mode 100644index 0ece595f..00000000Binary files a/src/oauth_page/codegraff-emblem-96.png and /dev/null differdiff --git a/src/oauth_page/codegraff-emblem-96.webp b/src/oauth_page/codegraff-emblem-96.webpnew file mode 100644index 00000000..497995fbBinary files /dev/null and b/src/oauth_page/codegraff-emblem-96.webp differ