Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

fix(imagegen): copy credentials when symlinking fails, regenerate SDKs, gate the mtime tests on Windows

justrach106f15a6c30d
diff --git a/sdk/py/harness_sdk.py b/sdk/py/harness_sdk.py
index 30bbc7ed..47d09715 100644
--- a/sdk/py/harness_sdk.py
+++ b/sdk/py/harness_sdk.py
@@ -14,7 +14,7 @@ import urllib.request
from typing import Iterator, Optional
MODELS = ["MiniMax-M2.5", "MiniMax-M2.7", "MiniMax-M3", "accounts/fireworks/models/deepseek-v4-flash", "accounts/fireworks/models/deepseek-v4-pro", "accounts/fireworks/models/glm-5p2", "accounts/fireworks/models/gpt-oss-120b", "accounts/fireworks/models/kimi-k2p6", "accounts/fireworks/models/kimi-k2p7-code", "accounts/fireworks/models/minimax-m3", "accounts/fireworks/models/qwen3p7-plus", "claude-fable-5", "claude-haiku-4-5", "claude-opus-4-5", "claude-opus-4-6", "claude-opus-4-7", "claude-opus-4-8", "claude-opus-4.8", "claude-sonnet-4-5", "claude-sonnet-4-6", "claude-sonnet-4.6", "deepseek-chat", "deepseek-reasoner", "deepseek-v4-flash", "deepseek-v4-pro", "fugu", "fugu-ultra", "fugu-ultra-20260615", "glm-4.5", "glm-4.7", "glm-5", "glm-5.2", "gpt-5-codex", "gpt-5.2", "gpt-5.3-codex-spark", "gpt-5.4", "gpt-5.4-mini", "gpt-5.4-pro", "gpt-5.5", "gpt-5.6", "gpt-5.6-luna", "gpt-5.6-sol", "gpt-5.6-terra", "grok-4.3", "grok-build", "k3", "kimi-for-coding", "kimi-for-coding-highspeed", "kimi-k2.6", "kimi-latest", "lmstudio", "mimo-v2-flash", "mimo-v2.5", "mimo-v2.5-pro", "mimo-v2.5-pro-ultraspeed", "minimax-m3", "mlx-community/Qwen3.6-27B-OptiQ-4bit"]
-TOOLS = ["bash", "bash_output", "bash_kill", "read_file", "edit_file", "write_file", "webfetch", "skill", "codedb", "todo_write", "todo_read", "eval", "ask_user", "attempt_completion", "clock_sleep", "subagent", "workflow", "agent_output", "learn_candidate"]
+TOOLS = ["bash", "bash_output", "bash_kill", "read_file", "edit_file", "write_file", "webfetch", "skill", "codedb", "todo_write", "todo_read", "eval", "ask_user", "attempt_completion", "clock_sleep", "subagent", "workflow", "agent_output", "learn_candidate", "imagegen"]
PROVIDERS = ["anthropic", "codegraff", "deepseek", "openai", "minimax", "xiaomi", "kimi", "moonshot", "xai", "zai", "fugu", "fireworks", "mlx", "lmstudio", "codex"]
diff --git a/sdk/ts/harness.ts b/sdk/ts/harness.ts
index 9d700048..23d327ec 100644
--- a/sdk/ts/harness.ts
+++ b/sdk/ts/harness.ts
@@ -11,7 +11,7 @@ import { createInterface } from "node:readline";
export const HARNESS_VERSION = "0.10";
export type ModelName = "MiniMax-M2.5" | "MiniMax-M2.7" | "MiniMax-M3" | "accounts/fireworks/models/deepseek-v4-flash" | "accounts/fireworks/models/deepseek-v4-pro" | "accounts/fireworks/models/glm-5p2" | "accounts/fireworks/models/gpt-oss-120b" | "accounts/fireworks/models/kimi-k2p6" | "accounts/fireworks/models/kimi-k2p7-code" | "accounts/fireworks/models/minimax-m3" | "accounts/fireworks/models/qwen3p7-plus" | "claude-fable-5" | "claude-haiku-4-5" | "claude-opus-4-5" | "claude-opus-4-6" | "claude-opus-4-7" | "claude-opus-4-8" | "claude-opus-4.8" | "claude-sonnet-4-5" | "claude-sonnet-4-6" | "claude-sonnet-4.6" | "deepseek-chat" | "deepseek-reasoner" | "deepseek-v4-flash" | "deepseek-v4-pro" | "fugu" | "fugu-ultra" | "fugu-ultra-20260615" | "glm-4.5" | "glm-4.7" | "glm-5" | "glm-5.2" | "gpt-5-codex" | "gpt-5.2" | "gpt-5.3-codex-spark" | "gpt-5.4" | "gpt-5.4-mini" | "gpt-5.4-pro" | "gpt-5.5" | "gpt-5.6" | "gpt-5.6-luna" | "gpt-5.6-sol" | "gpt-5.6-terra" | "grok-4.3" | "grok-build" | "k3" | "kimi-for-coding" | "kimi-for-coding-highspeed" | "kimi-k2.6" | "kimi-latest" | "lmstudio" | "mimo-v2-flash" | "mimo-v2.5" | "mimo-v2.5-pro" | "mimo-v2.5-pro-ultraspeed" | "minimax-m3" | "mlx-community/Qwen3.6-27B-OptiQ-4bit" | (string & {});
-export type ToolName = "bash" | "bash_output" | "bash_kill" | "read_file" | "edit_file" | "write_file" | "webfetch" | "skill" | "codedb" | "todo_write" | "todo_read" | "eval" | "ask_user" | "attempt_completion" | "clock_sleep" | "subagent" | "workflow" | "agent_output" | "learn_candidate";
+export type ToolName = "bash" | "bash_output" | "bash_kill" | "read_file" | "edit_file" | "write_file" | "webfetch" | "skill" | "codedb" | "todo_write" | "todo_read" | "eval" | "ask_user" | "attempt_completion" | "clock_sleep" | "subagent" | "workflow" | "agent_output" | "learn_candidate" | "imagegen";
export type ProviderId = "anthropic" | "codegraff" | "deepseek" | "openai" | "minimax" | "xiaomi" | "kimi" | "moonshot" | "xai" | "zai" | "fugu" | "fireworks" | "mlx" | "lmstudio" | "codex";
/** Events streamed by `harness --json` (one JSON object per stdout line), each
@@ -432,4 +432,4 @@ export async function* runAgent(opts: RunAgentOptions): AsyncGenerator<Event> {
}
export const MODELS: ModelName[] = ["MiniMax-M2.5", "MiniMax-M2.7", "MiniMax-M3", "accounts/fireworks/models/deepseek-v4-flash", "accounts/fireworks/models/deepseek-v4-pro", "accounts/fireworks/models/glm-5p2", "accounts/fireworks/models/gpt-oss-120b", "accounts/fireworks/models/kimi-k2p6", "accounts/fireworks/models/kimi-k2p7-code", "accounts/fireworks/models/minimax-m3", "accounts/fireworks/models/qwen3p7-plus", "claude-fable-5", "claude-haiku-4-5", "claude-opus-4-5", "claude-opus-4-6", "claude-opus-4-7", "claude-opus-4-8", "claude-opus-4.8", "claude-sonnet-4-5", "claude-sonnet-4-6", "claude-sonnet-4.6", "deepseek-chat", "deepseek-reasoner", "deepseek-v4-flash", "deepseek-v4-pro", "fugu", "fugu-ultra", "fugu-ultra-20260615", "glm-4.5", "glm-4.7", "glm-5", "glm-5.2", "gpt-5-codex", "gpt-5.2", "gpt-5.3-codex-spark", "gpt-5.4", "gpt-5.4-mini", "gpt-5.4-pro", "gpt-5.5", "gpt-5.6", "gpt-5.6-luna", "gpt-5.6-sol", "gpt-5.6-terra", "grok-4.3", "grok-build", "k3", "kimi-for-coding", "kimi-for-coding-highspeed", "kimi-k2.6", "kimi-latest", "lmstudio", "mimo-v2-flash", "mimo-v2.5", "mimo-v2.5-pro", "mimo-v2.5-pro-ultraspeed", "minimax-m3", "mlx-community/Qwen3.6-27B-OptiQ-4bit"];
-export const TOOLS: ToolName[] = ["bash", "bash_output", "bash_kill", "read_file", "edit_file", "write_file", "webfetch", "skill", "codedb", "todo_write", "todo_read", "eval", "ask_user", "attempt_completion", "clock_sleep", "subagent", "workflow", "agent_output", "learn_candidate"];
+export const TOOLS: ToolName[] = ["bash", "bash_output", "bash_kill", "read_file", "edit_file", "write_file", "webfetch", "skill", "codedb", "todo_write", "todo_read", "eval", "ask_user", "attempt_completion", "clock_sleep", "subagent", "workflow", "agent_output", "learn_candidate", "imagegen"];
diff --git a/sdk/ts/remote.ts b/sdk/ts/remote.ts
index 86bce1b9..030fa2ef 100644
--- a/sdk/ts/remote.ts
+++ b/sdk/ts/remote.ts
@@ -10,7 +10,7 @@
export const HARNESS_VERSION = "0.10";
export type ModelName = "MiniMax-M2.5" | "MiniMax-M2.7" | "MiniMax-M3" | "accounts/fireworks/models/deepseek-v4-flash" | "accounts/fireworks/models/deepseek-v4-pro" | "accounts/fireworks/models/glm-5p2" | "accounts/fireworks/models/gpt-oss-120b" | "accounts/fireworks/models/kimi-k2p6" | "accounts/fireworks/models/kimi-k2p7-code" | "accounts/fireworks/models/minimax-m3" | "accounts/fireworks/models/qwen3p7-plus" | "claude-fable-5" | "claude-haiku-4-5" | "claude-opus-4-5" | "claude-opus-4-6" | "claude-opus-4-7" | "claude-opus-4-8" | "claude-opus-4.8" | "claude-sonnet-4-5" | "claude-sonnet-4-6" | "claude-sonnet-4.6" | "deepseek-chat" | "deepseek-reasoner" | "deepseek-v4-flash" | "deepseek-v4-pro" | "fugu" | "fugu-ultra" | "fugu-ultra-20260615" | "glm-4.5" | "glm-4.7" | "glm-5" | "glm-5.2" | "gpt-5-codex" | "gpt-5.2" | "gpt-5.3-codex-spark" | "gpt-5.4" | "gpt-5.4-mini" | "gpt-5.4-pro" | "gpt-5.5" | "gpt-5.6" | "gpt-5.6-luna" | "gpt-5.6-sol" | "gpt-5.6-terra" | "grok-4.3" | "grok-build" | "k3" | "kimi-for-coding" | "kimi-for-coding-highspeed" | "kimi-k2.6" | "kimi-latest" | "lmstudio" | "mimo-v2-flash" | "mimo-v2.5" | "mimo-v2.5-pro" | "mimo-v2.5-pro-ultraspeed" | "minimax-m3" | "mlx-community/Qwen3.6-27B-OptiQ-4bit" | (string & {});
-export type ToolName = "bash" | "bash_output" | "bash_kill" | "read_file" | "edit_file" | "write_file" | "webfetch" | "skill" | "codedb" | "todo_write" | "todo_read" | "eval" | "ask_user" | "attempt_completion" | "clock_sleep" | "subagent" | "workflow" | "agent_output" | "learn_candidate";
+export type ToolName = "bash" | "bash_output" | "bash_kill" | "read_file" | "edit_file" | "write_file" | "webfetch" | "skill" | "codedb" | "todo_write" | "todo_read" | "eval" | "ask_user" | "attempt_completion" | "clock_sleep" | "subagent" | "workflow" | "agent_output" | "learn_candidate" | "imagegen";
export type ProviderId = "anthropic" | "codegraff" | "deepseek" | "openai" | "minimax" | "xiaomi" | "kimi" | "moonshot" | "xai" | "zai" | "fugu" | "fireworks" | "mlx" | "lmstudio" | "codex";
/** Events streamed by the bridge (same `--json` contract as the stdio SDK).
@@ -323,4 +323,4 @@ export async function* runAgentRemote(opts: RunAgentRemoteOptions): AsyncGenerat
}
export const MODELS: ModelName[] = ["MiniMax-M2.5", "MiniMax-M2.7", "MiniMax-M3", "accounts/fireworks/models/deepseek-v4-flash", "accounts/fireworks/models/deepseek-v4-pro", "accounts/fireworks/models/glm-5p2", "accounts/fireworks/models/gpt-oss-120b", "accounts/fireworks/models/kimi-k2p6", "accounts/fireworks/models/kimi-k2p7-code", "accounts/fireworks/models/minimax-m3", "accounts/fireworks/models/qwen3p7-plus", "claude-fable-5", "claude-haiku-4-5", "claude-opus-4-5", "claude-opus-4-6", "claude-opus-4-7", "claude-opus-4-8", "claude-opus-4.8", "claude-sonnet-4-5", "claude-sonnet-4-6", "claude-sonnet-4.6", "deepseek-chat", "deepseek-reasoner", "deepseek-v4-flash", "deepseek-v4-pro", "fugu", "fugu-ultra", "fugu-ultra-20260615", "glm-4.5", "glm-4.7", "glm-5", "glm-5.2", "gpt-5-codex", "gpt-5.2", "gpt-5.3-codex-spark", "gpt-5.4", "gpt-5.4-mini", "gpt-5.4-pro", "gpt-5.5", "gpt-5.6", "gpt-5.6-luna", "gpt-5.6-sol", "gpt-5.6-terra", "grok-4.3", "grok-build", "k3", "kimi-for-coding", "kimi-for-coding-highspeed", "kimi-k2.6", "kimi-latest", "lmstudio", "mimo-v2-flash", "mimo-v2.5", "mimo-v2.5-pro", "mimo-v2.5-pro-ultraspeed", "minimax-m3", "mlx-community/Qwen3.6-27B-OptiQ-4bit"];
-export const TOOLS: ToolName[] = ["bash", "bash_output", "bash_kill", "read_file", "edit_file", "write_file", "webfetch", "skill", "codedb", "todo_write", "todo_read", "eval", "ask_user", "attempt_completion", "clock_sleep", "subagent", "workflow", "agent_output", "learn_candidate"];
+export const TOOLS: ToolName[] = ["bash", "bash_output", "bash_kill", "read_file", "edit_file", "write_file", "webfetch", "skill", "codedb", "todo_write", "todo_read", "eval", "ask_user", "attempt_completion", "clock_sleep", "subagent", "workflow", "agent_output", "learn_candidate", "imagegen"];
diff --git a/src/imagegen_codex.zig b/src/imagegen_codex.zig
index 8532064b..4333fd9b 100644
--- a/src/imagegen_codex.zig
+++ b/src/imagegen_codex.zig
@@ -27,6 +27,7 @@
//! repo it was called from.
const std = @import("std");
+const builtin = @import("builtin");
const Io = std.Io;
const Allocator = std.mem.Allocator;
@@ -76,7 +77,8 @@ pub fn buildArgv(arena: Allocator, private_home: []const u8, prompt: []const u8)
}
/// Credentials that make a private CODEX_HOME usable. Symlinked rather than
-/// copied so a token never lands as a second plaintext file in a temp dir.
+/// copied where the OS allows it, so a token never lands as a second plaintext
+/// file in a temp dir; see `prepareHome` for the copy fallback.
pub const linked_files = [_][]const u8{ "auth.json", "config.toml" };
/// Build a private CODEX_HOME for ONE run.
@@ -106,12 +108,24 @@ pub fn prepareHome(io: Io, arena: Allocator, private_home: []const u8, real_home
const target = try std.fmt.allocPrint(arena, "{s}/{s}", .{ real_home, name });
_ = Io.Dir.cwd().statFile(io, target, .{}) catch continue; // config.toml is optional
const link = try std.fmt.allocPrint(arena, "{s}/{s}", .{ private_home, name });
- Io.Dir.cwd().symLink(io, target, link, .{}) catch {};
+ // A symlink is preferred (no second copy of a token on disk), but it is
+ // not always available: Windows only creates one for a process holding
+ // SeCreateSymbolicLinkPrivilege or running in developer mode, and a
+ // FAT/exFAT TMPDIR cannot hold one on any OS. Silently skipping, as
+ // this used to, leaves the private CODEX_HOME with no credentials at
+ // all — codex then runs logged out and the engine looks broken for a
+ // reason nothing reports. Copying is the lesser evil, and it is no more
+ // exposed than the link was: `unlinkHome` removes it and the whole
+ // scratch tree is deleted when the run ends either way.
+ Io.Dir.cwd().symLink(io, target, link, .{}) catch {
+ Io.Dir.cwd().copyFile(target, Io.Dir.cwd(), link, io, .{}) catch {};
+ };
}
}
-/// Remove the credential symlinks BEFORE the tree is deleted, so a delete can
-/// never walk into the user's real CODEX_HOME through one of them.
+/// Remove the credential links BEFORE the tree is deleted, so a delete can
+/// never walk into the user's real CODEX_HOME through one of them. `deleteFile`
+/// covers the copy fallback too — the copy is a plain file at the same path.
pub fn unlinkHome(io: Io, arena: Allocator, private_home: []const u8) void {
for (linked_files) |name| {
const link = std.fmt.allocPrint(arena, "{s}/{s}", .{ private_home, name }) catch continue;
@@ -363,13 +377,20 @@ test "#352: discovery picks the newest FRESH file, ignores stale ones and dotfil
for ([_][]const u8{ stale, fresh, fresher, junk }) |p|
try Io.Dir.cwd().writeFile(io, .{ .sub_path = p, .data = "\x89PNG\r\n\x1a\n" ++ "payload" });
- // Stale = written two weeks ago; the .DS_Store is fresh but must be skipped.
- try Io.Dir.cwd().setTimestamps(io, stale, .{ .modify_timestamp = .{ .new = .{ .nanoseconds = @intCast(now - 14 * day_ns) } } });
- try Io.Dir.cwd().setTimestamps(io, fresh, .{ .modify_timestamp = .{ .new = .{ .nanoseconds = @intCast(now - 30 * std.time.ns_per_s) } } });
- try Io.Dir.cwd().setTimestamps(io, fresher, .{ .modify_timestamp = .{ .new = .{ .nanoseconds = @intCast(now - 5 * std.time.ns_per_s) } } });
-
- const picked = newestFresh(io, arena, root, marker).?;
- try testing.expect(std.mem.endsWith(u8, picked.path, "exec-newest.png"));
+ // Backdating is the only deterministic way to give three files distinct,
+ // known mtimes, and `Io.Dir.setTimestamps` is literally
+ // `@panic("TODO implement dirSetTimestamps windows")` in Zig 0.17's
+ // Threaded io — so this half of the test aborts the runner on Windows
+ // rather than failing. Everything below it is portable and still runs.
+ if (builtin.os.tag != .windows) {
+ // Stale = written two weeks ago; the .DS_Store is fresh but must be skipped.
+ try Io.Dir.cwd().setTimestamps(io, stale, .{ .modify_timestamp = .{ .new = .{ .nanoseconds = @intCast(now - 14 * day_ns) } } });
+ try Io.Dir.cwd().setTimestamps(io, fresh, .{ .modify_timestamp = .{ .new = .{ .nanoseconds = @intCast(now - 30 * std.time.ns_per_s) } } });
+ try Io.Dir.cwd().setTimestamps(io, fresher, .{ .modify_timestamp = .{ .new = .{ .nanoseconds = @intCast(now - 5 * std.time.ns_per_s) } } });
+
+ const picked = newestFresh(io, arena, root, marker).?;
+ try testing.expect(std.mem.endsWith(u8, picked.path, "exec-newest.png"));
+ }
// A marker AFTER everything on disk finds nothing — the fabrication case,
// and the state a run that generated nothing leaves behind.
diff --git a/src/imagegen_skill.zig b/src/imagegen_skill.zig
index 2c1014c9..efa2a63a 100644
--- a/src/imagegen_skill.zig
+++ b/src/imagegen_skill.zig
@@ -26,6 +26,7 @@
//! edited their copy keeps their edits until Codex itself ships a new version.
const std = @import("std");
+const builtin = @import("builtin");
const Io = std.Io;
const Allocator = std.mem.Allocator;
@@ -285,11 +286,18 @@ test "#352: sync mirrors the tree with LICENSE + scripts, and only re-copies whe
try Io.Dir.cwd().writeFile(io, .{ .sub_path = edited, .data = "---\nname: imagegen\ndescription: d\n---\nmine\n" });
try testing.expect(!needsSync(io, arena, src, dest)); // the copy is now NEWER than the source
- // A newer upstream SKILL.md is the one thing that re-copies.
- const src_md = try std.fmt.allocPrint(arena, "{s}/SKILL.md", .{src});
- const dest_mtime = skillMtime(io, arena, dest).?;
- try Io.Dir.cwd().setTimestamps(io, src_md, .{
- .modify_timestamp = .{ .new = .{ .nanoseconds = @intCast(dest_mtime + std.time.ns_per_s) } },
- });
- try testing.expect(needsSync(io, arena, src, dest));
+ // A newer upstream SKILL.md is the one thing that re-copies. Forcing that
+ // ordering needs an explicit mtime, and `Io.Dir.setTimestamps` is
+ // `@panic("TODO implement dirSetTimestamps windows")` in Zig 0.17's
+ // Threaded io — it aborts the test runner rather than returning an error,
+ // so only this last assertion is POSIX-only. The mirror/addendum/no-recopy
+ // checks above all still run on Windows.
+ if (builtin.os.tag != .windows) {
+ const src_md = try std.fmt.allocPrint(arena, "{s}/SKILL.md", .{src});
+ const dest_mtime = skillMtime(io, arena, dest).?;
+ try Io.Dir.cwd().setTimestamps(io, src_md, .{
+ .modify_timestamp = .{ .new = .{ .nanoseconds = @intCast(dest_mtime + std.time.ns_per_s) } },
+ });
+ try testing.expect(needsSync(io, arena, src, dest));
+ }
}
diff --git a/src/imagegen_tests.zig b/src/imagegen_tests.zig
index 9f49003a..3ede39c4 100644
--- a/src/imagegen_tests.zig
+++ b/src/imagegen_tests.zig
@@ -2,6 +2,7 @@
//! ceiling); referenced from its test block so they actually run.
const std = @import("std");
+const builtin = @import("builtin");
const Io = std.Io;
const Value = std.json.Value;
const Allocator = std.mem.Allocator;
@@ -271,8 +272,12 @@ test "#352 replay: codex exits 0 with a confident success transcript and NO fres
}
// 2. A STALE artifact in our own save_root is still not this run's work.
- FakeCodex.plant = .stale_png;
- {
+ // Planting one means backdating its mtime, and `Io.Dir.setTimestamps` is
+ // `@panic("TODO implement dirSetTimestamps windows")` in Zig 0.17's
+ // Threaded io — it aborts the runner instead of returning an error, so this
+ // one scenario is POSIX-only. Scenarios 1, 3 and 4 still run on Windows.
+ if (builtin.os.tag != .windows) {
+ FakeCodex.plant = .stale_png;
const r = try execImagegen(ctx, input.value);
defer gpa.free(r.text);
try std.testing.expect(r.is_error);