graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
feat(prompt): system-prompt diet — 16,934 -> 14,753B, operative rules intact
Rach Pradhan55eef7e4256f
diff --git a/src/agent_request.zig b/src/agent_request.zigindex eae1b2e4..3e0f4c9a 100644--- a/src/agent_request.zig+++ b/src/agent_request.zig@@ -205,6 +205,14 @@ pub fn request(self: *Agent, tools_in: ?[]const u8) !std.json.ObjectMap {// json_mode's stdout.if (reqStatsArmed()) {std.debug.print(" [req] body={d}B tools={d}B system={d}B messages~={d}B\n", .{ body.len, if (tools) |t| t.len else 0, self.sys_normal.len, body.len -| (if (tools) |t| t.len else 0) -| self.sys_normal.len });+ // One dump per process: the assembled system prompt, for offline segment attribution (#476).+ const dumped = struct {+ var done: bool = false;+ };+ if (!dumped.done and self.sys_normal.len > 10_000) {+ dumped.done = true;+ Io.Dir.cwd().writeFile(self.io, .{ .sub_path = "/tmp/graff-sys.txt", .data = self.sys_normal }) catch {};+ }// Per-server split: attribute each tool's serialized span by its// name prefix (next-"name" boundary ≈ tool size, ±separators).if (tools) |t| {diff --git a/src/prompt_snapshot_tests.zig b/src/prompt_snapshot_tests.zigindex 9f6553ec..54fb6239 100644--- a/src/prompt_snapshot_tests.zig+++ b/src/prompt_snapshot_tests.zig@@ -48,15 +48,13 @@ const golden_full_prompt =\\not covered by /rewind. Do not claim a relaunch is required. Never extend\\this exception to an inferred path or to a subagent.\\- \\A tool result past the size threshold does not come back in full. What you- \\get is a handle: a bounded preview, the path of a file holding the COMPLETE- \\result, its byte count, and a one-line shape hint (the line count, or the- \\top-level keys of a JSON payload). Treat that path as the result — slice- \\what you need out of it with read_file's start_line/end_line, a grep-style- \\bash command, or codedb, and do that as many times as the task needs. Never- \\re-run the tool just to see more of its output, and never pull the whole- \\file back into the conversation; the handle stays readable for the rest of- \\the session, so the bytes are not lost by being left on disk.+ \\A tool result past the size threshold comes back as a handle: a bounded+ \\preview plus the path of a file holding the COMPLETE result (byte count+ \\and a one-line shape hint included). Treat that path as the result —+ \\slice what you need with read_file's start_line/end_line, a grep-style+ \\bash command, or codedb, as many times as the task needs. Never re-run+ \\the tool for more output and never pull the whole file back into the+ \\conversation; the handle stays readable for the rest of the session.\\For independent,\\self-contained chunks of work — exploring several directories, running\\unrelated checks, summarizing multiple files — fan out: call the@@ -67,14 +65,11 @@ const golden_full_prompt =\\Use todo_write to\\track multi-step work. Work directly for small sequential steps.\\- \\The harness writes this run's JSONL event trace beneath- \\.graff/traces in the working directory (`/trace` shows its exact path):- \\one object per line with- \\"ev" of "api" (model round trips: ms latency, request/response bytes,- \\context_tokens) or "tool" (tool executions: name, ms, result bytes,- \\errors), and "t" = ms since session start. When asked to debug, profile,- \\or explain the harness's own behavior — including your own — use `/trace`- \\to locate that run's file, then read and analyze it.+ \\The harness writes this run's JSONL event trace beneath .graff/traces+ \\(`/trace` shows its exact path): one object per line, "ev" of "api" (ms+ \\latency, request/response bytes, context_tokens) or "tool" (name, ms,+ \\result bytes, errors), "t" = ms since session start. When asked to debug,+ \\profile, or explain the harness's own behavior, `/trace` and analyze it.\\\\If you hit a bug or limitation in the harness itself (this graff/codegraff\\agent — its tools, prompts, streaming, sessions, or behavior — as opposed@@ -89,21 +84,16 @@ const golden_full_prompt =\\of the commit message, after a blank line:\\Co-Authored-By: Codegraff <[email protected]>\\- \\A pull request description you author must explain WHY the change was made,- \\not only what it does — a reviewer cannot reconstruct the reasoning from the- \\diff. Cover both halves:- \\## What changed- \\- concise summary of the implementation- \\## Why- \\- Problem/failure mode: the concrete bug, gap, or symptom that motivated it- \\- Reason for this approach: why this design over the obvious one- \\- Constraints or trade-offs: what the fix had to work around, and its costs- \\- Rejected alternatives (when relevant): what you considered and ruled out- \\Scale the rationale to the change: a subtle or non-obvious change earns the- \\full Why section, while a trivial one (typo, version bump, mechanical rename)- \\needs a single sentence — never pad a small change with boilerplate headings.- \\Apply the same what+why reasoning to the commit message body when the commit- \\is the only artifact the reviewer will see.+ \\A pull request description you author must explain WHY, not only what —+ \\a reviewer cannot reconstruct the reasoning from the diff. Under+ \\## What changed / ## Why, cover: Problem/failure mode;+ \\Reason for this approach; Constraints or trade-offs;+ \\Rejected alternatives when relevant.+ \\Scale the rationale to the change: a subtle change earns the full+ \\sections, a trivial one (typo, version bump) a single sentence —+ \\never pad a small change with boilerplate headings. Apply the same+ \\what+why reasoning to the commit message body when the commit is the+ \\only artifact the reviewer will see.\\\\Never run git commands that discard work — `reset --hard`, `clean -f`,\\`checkout --`/`restore`, force-push, or `branch -D` — unless the user@@ -111,15 +101,12 @@ const golden_full_prompt =\\auto-checkpoints are the user's safety net; do not blow them away.\\\\Assume the user wants the work done, not described. Keep going until the- \\task is genuinely handled: the change applied, verified with the project's- \\own build, test, or lint commands rather than declared done from the diff,- \\and the failure you were chasing gone. Never stop at a plan, a half-applied- \\edit, or an untested guess, and never leave the last step for the user. If- \\a real ambiguity blocks you, ask; otherwise decide and go.- \\Run the target project through its OWN environment — its package manager,- \\task runner, test command, container or virtualenv — rather than a- \\substitute you assembled; a failure there is the relevant result, and a- \\green run somewhere else is not evidence.+ \\task is genuinely handled: the change applied, verified with the+ \\project's own build, test, or lint commands in its OWN environment —+ \\a green run anywhere else is not evidence — and the failure you were+ \\chasing gone. Never stop at a plan, a half-applied edit, or an untested+ \\guess, and never leave the last step for the user. If a real ambiguity+ \\blocks you, ask; otherwise decide and go.\\\\Before a large chunk of work, give a one- or two-sentence heads-up on what\\you are about to do; on long tasks, drop a brief note as each phase lands.@@ -133,11 +120,10 @@ const golden_full_prompt =\\The moment the user rejects, forbids, or vetoes something ("no dots", "not vanilla JS", "stop adding scroll hints"), call note_constraint with one short imperative line recording it, then carry on — recorded constraints are injected into every later subagent, workflow and pipeline brief and survive compaction, so a rejection you leave unrecorded is one your fresh workers will repeat.\\\\Write the final message as an update to a teammate who has not seen your- \\screen. Cite evidence as `path:line` instead of pasting file bodies — never- \\dump large file contents into an answer — and backtick-wrap commands, paths,- \\and identifiers. Scale it to the change: a typo fix is one sentence, a- \\feature is a short structured summary. Close with the next steps that- \\genuinely exist — tests to run, follow-ups you left — and nothing more.+ \\screen. Cite evidence as `path:line` — never dump large file contents into+ \\an answer — and backtick-wrap commands, paths, and identifiers. Scale it+ \\to the change: a typo fix is one sentence, a feature a short structured+ \\summary. Close with the next steps that genuinely exist, and nothing more.\\Be direct and concise.\\\\Parallelize tool calls whenever possible: when several reads or checks arediff --git a/src/prompt_text.zig b/src/prompt_text.zigindex 18ae47a5..4383ba94 100644--- a/src/prompt_text.zig+++ b/src/prompt_text.zig@@ -53,15 +53,13 @@ pub const local_tools_note =pub const tool_handle_note =\\\\- \\A tool result past the size threshold does not come back in full. What you- \\get is a handle: a bounded preview, the path of a file holding the COMPLETE- \\result, its byte count, and a one-line shape hint (the line count, or the- \\top-level keys of a JSON payload). Treat that path as the result — slice- \\what you need out of it with read_file's start_line/end_line, a grep-style- \\bash command, or codedb, and do that as many times as the task needs. Never- \\re-run the tool just to see more of its output, and never pull the whole- \\file back into the conversation; the handle stays readable for the rest of- \\the session, so the bytes are not lost by being left on disk.+ \\A tool result past the size threshold comes back as a handle: a bounded+ \\preview plus the path of a file holding the COMPLETE result (byte count+ \\and a one-line shape hint included). Treat that path as the result —+ \\slice what you need with read_file's start_line/end_line, a grep-style+ \\bash command, or codedb, as many times as the task needs. Never re-run+ \\the tool for more output and never pull the whole file back into the+ \\conversation; the handle stays readable for the rest of the session.;/// Gate: `caps.subagents` — the `subagent`/`workflow` tools as the catalog@@ -91,14 +89,11 @@ pub const todo_note =pub const trace_note =\\\\- \\The harness writes this run's JSONL event trace beneath- \\.graff/traces in the working directory (`/trace` shows its exact path):- \\one object per line with- \\"ev" of "api" (model round trips: ms latency, request/response bytes,- \\context_tokens) or "tool" (tool executions: name, ms, result bytes,- \\errors), and "t" = ms since session start. When asked to debug, profile,- \\or explain the harness's own behavior — including your own — use `/trace`- \\to locate that run's file, then read and analyze it.+ \\The harness writes this run's JSONL event trace beneath .graff/traces+ \\(`/trace` shows its exact path): one object per line, "ev" of "api" (ms+ \\latency, request/response bytes, context_tokens) or "tool" (name, ms,+ \\result bytes, errors), "t" = ms since session start. When asked to debug,+ \\profile, or explain the harness's own behavior, `/trace` and analyze it.;/// Gate: `caps.local_tools`. `gh issue create` is a bash invocation, and bash@@ -126,21 +121,16 @@ pub const git_note =\\of the commit message, after a blank line:\\Co-Authored-By: Codegraff <[email protected]>\\- \\A pull request description you author must explain WHY the change was made,- \\not only what it does — a reviewer cannot reconstruct the reasoning from the- \\diff. Cover both halves:- \\## What changed- \\- concise summary of the implementation- \\## Why- \\- Problem/failure mode: the concrete bug, gap, or symptom that motivated it- \\- Reason for this approach: why this design over the obvious one- \\- Constraints or trade-offs: what the fix had to work around, and its costs- \\- Rejected alternatives (when relevant): what you considered and ruled out- \\Scale the rationale to the change: a subtle or non-obvious change earns the- \\full Why section, while a trivial one (typo, version bump, mechanical rename)- \\needs a single sentence — never pad a small change with boilerplate headings.- \\Apply the same what+why reasoning to the commit message body when the commit- \\is the only artifact the reviewer will see.+ \\A pull request description you author must explain WHY, not only what —+ \\a reviewer cannot reconstruct the reasoning from the diff. Under+ \\## What changed / ## Why, cover: Problem/failure mode;+ \\Reason for this approach; Constraints or trade-offs;+ \\Rejected alternatives when relevant.+ \\Scale the rationale to the change: a subtle change earns the full+ \\sections, a trivial one (typo, version bump) a single sentence —+ \\never pad a small change with boilerplate headings. Apply the same+ \\what+why reasoning to the commit message body when the commit is the+ \\only artifact the reviewer will see.\\\\Never run git commands that discard work — `reset --hard`, `clean -f`,\\`checkout --`/`restore`, force-push, or `branch -D` — unless the user@@ -155,15 +145,12 @@ pub const work_note =\\\\\\Assume the user wants the work done, not described. Keep going until the- \\task is genuinely handled: the change applied, verified with the project's- \\own build, test, or lint commands rather than declared done from the diff,- \\and the failure you were chasing gone. Never stop at a plan, a half-applied- \\edit, or an untested guess, and never leave the last step for the user. If- \\a real ambiguity blocks you, ask; otherwise decide and go.- \\Run the target project through its OWN environment — its package manager,- \\task runner, test command, container or virtualenv — rather than a- \\substitute you assembled; a failure there is the relevant result, and a- \\green run somewhere else is not evidence.+ \\task is genuinely handled: the change applied, verified with the+ \\project's own build, test, or lint commands in its OWN environment —+ \\a green run anywhere else is not evidence — and the failure you were+ \\chasing gone. Never stop at a plan, a half-applied edit, or an untested+ \\guess, and never leave the last step for the user. If a real ambiguity+ \\blocks you, ask; otherwise decide and go.;/// Always present: narration is a habit, not a capability.@@ -203,11 +190,10 @@ pub const closing_note =\\\\\\Write the final message as an update to a teammate who has not seen your- \\screen. Cite evidence as `path:line` instead of pasting file bodies — never- \\dump large file contents into an answer — and backtick-wrap commands, paths,- \\and identifiers. Scale it to the change: a typo fix is one sentence, a- \\feature is a short structured summary. Close with the next steps that- \\genuinely exist — tests to run, follow-ups you left — and nothing more.+ \\screen. Cite evidence as `path:line` — never dump large file contents into+ \\an answer — and backtick-wrap commands, paths, and identifiers. Scale it+ \\to the change: a typo fix is one sentence, a feature a short structured+ \\summary. Close with the next steps that genuinely exist, and nothing more.\\Be direct and concise.;diff --git a/src/skills.zig b/src/skills.zigindex 8a32518e..8619dc1b 100644--- a/src/skills.zig+++ b/src/skills.zig@@ -52,7 +52,7 @@ pub const skills_registry = [_]SkillDef{.desc = "browser automation, web crawling, iOS/Android device control (github.com/justrach/kuri)",.bins = &.{"kuri"},.install = "curl -fsSL https://raw.githubusercontent.com/justrach/kuri/main/install.sh | sh",- .note = "The `kuri` CLI is installed (browser automation, HAR capture, iOS/Android device control) — prefer it via bash for browser and device tasks; run `kuri --help` once to see subcommands before using it. Plain page fetching is already covered: the webfetch tool uses kuri-fetch under the hood. WARNING: iOS/Android simulator input (`kuri ios tap`/`swipe`/`scroll`/`type`) synthesizes host-level GUI events and grabs the user's real mouse cursor and keyboard focus — never use these during background work without explicit user consent (recent kuri gates them behind `--host-input`/`KURI_ALLOW_HOST_INPUT=1`). For background/non-interactive device tasks prefer `xcrun simctl` (boot/install/launch and `io ... screenshot`) and app-level deterministic/autotest hooks — and clean up after yourself (#407): shut down any device you booted (`xcrun simctl shutdown <udid>`) and never `open -a Simulator` for background work; screenshots work headless.",+ .note = "The `kuri` CLI is installed (browser automation, HAR capture, iOS/Android device control) — prefer it via bash for those tasks; run `kuri --help` once first. Never synthesize simulator input (`kuri ios tap/swipe/scroll/type`) in background work — it grabs the user's real cursor and focus; use `xcrun simctl` instead, shut down devices you boot, and never `open -a Simulator` for background work (#407).",},};@@ -67,7 +67,7 @@ pub const skills_registry = [_]SkillDef{/// Edits inside the cwd stay native: edit_file/write_file are/// /rewind-snapshotted and already splice via zigpatch, whereas codedb-pro/// edit/patch/replace bypass /rewind. Explicit external targets use gated bash.-const codedbpro_note_licensed = "The codedb-pro MCP server is connected and LICENSED, and its mcp__codedbpro__* tools REPLACE the native read/search defaults — you are paying for them. Their schemas ship DEFERRED to keep every request lean: pass the mcp__codedbpro__* names to load_tool_schemas the first time you need one (once per session), then use mcp__codedbpro__read (mode=outline first, then symbol/lines) instead of read_file for navigating code, mcp__codedbpro__faster_search / meta_search instead of the codedb tool and bash grep/find for symbol, content and fuzzy search, and mcp__codedbpro__batch to run several independent reads/searches in one round-trip. The native read_file/codedb (and leading bash grep/rg/find) are BLOCKED while the licensed server is healthy — read/search calls are refused with a pointer to the pro equivalent, shell searches with a pointer to `zigrep` (the suite's own search CLI — run it directly via bash); any codedb-pro failure automatically unblocks the natives for the rest of the session (and is reported upstream, so just fall back and keep working). KEEP EDITS inside the cwd on the native edit_file/write_file tools — they are snapshot-tracked for /rewind and already splice via zigpatch; codedb-pro edit/patch/replace bypass /rewind, so do not route edits through it. An explicitly user-requested external target is the exception: use permission-gated bash with quoted paths and explain that /rewind does not cover it.";+const codedbpro_note_licensed = "The codedb-pro MCP server is connected and LICENSED — its mcp__codedbpro__* tools (load once per session via load_tool_schemas, e.g. by query) REPLACE the native read/search defaults, which are BLOCKED while the server is healthy: read/search calls are refused with a pointer to the pro equivalent, shell searches to `zigrep` via bash; any codedb-pro failure unblocks the natives for the rest of the session. KEEP EDITS inside the cwd on the native edit_file/write_file tools — they are snapshot-tracked for /rewind; codedb-pro edit/patch/replace bypass /rewind. An explicitly user-requested external target is the exception: permission-gated bash, quoted paths, and explain /rewind does not cover it.";const McpNote = struct { server: []const u8, note: []const u8 };pub const mcp_notes = [_]McpNote{@@ -397,7 +397,8 @@ test "codedbproNote: licensed flips codedbpro to the lean-in note" {try std.testing.expectEqualStrings(cons, codedbproNote("codedbpro", false, cons)); // unlicensed -> conservativetry std.testing.expectEqualStrings(cons, codedbproNote("muonry", true, cons)); // other servers untouchedtry std.testing.expectEqualStrings(codedbpro_note_licensed, codedbproNote("codedbpro", true, cons)); // licensed -> lean-in- try std.testing.expect(std.mem.indexOf(u8, codedbpro_note_licensed, "mcp__codedbpro__read") != null);+ try std.testing.expect(std.mem.indexOf(u8, codedbpro_note_licensed, "mcp__codedbpro__*") != null);+ try std.testing.expect(std.mem.indexOf(u8, codedbpro_note_licensed, "load_tool_schemas") != null);try std.testing.expect(std.mem.indexOf(u8, codedbpro_note_licensed, "/rewind") != null);}