graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
fix: sanitize what goes out to the internet, and stop compaction inventing constraints
justrachfaa75cd44a18
diff --git a/TUI/key.zig b/TUI/key.zigindex 4f07f1d7..5d17e026 100644--- a/TUI/key.zig+++ b/TUI/key.zig@@ -18,15 +18,6 @@ pub fn inPaste() bool {return in_paste;}-/// Set by the read loop for reads that belong to a paste spanning several-/// tty reads. `looksLikeBurst` only sees the read in front of it, so without-/// this a chunk ending at a line boundary submits mid-paste (#737).-var burst_read: bool = false;--pub fn setBurstRead(on: bool) void {- burst_read = on;-}-/// Close a bracketed paste and clear modifiers whose events were ignored/// inside it. The read loop also calls this when `CSI 201~` never arrived —/// without it the latch is permanent and every Enter, Escape and slash command@@ -66,7 +57,6 @@ pub fn abandonSequence(bytes: []const u8, recovery: SequenceRecovery) void {pub fn resetInputState() void {abandonSequence("", .none);in_paste = false;- burst_read = false;paste.resetBurst();orphan.reset();}@@ -156,9 +146,9 @@ pub fn next(bytes: []const u8, i: *usize) ?Key {i.* += 1;if (b == 0x1b) return escapeSeq(bytes, i);if (b == 0x0d or b == 0x0a) {- // Embedded newlines from a bracketed paste — or a wrap-less multiline- // dump in this same read — must not become the Enter/send key (#643).- if (in_paste or burst_read or paste.looksLikeBurst(bytes)) {+ // Newlines inside a paste are text, not the Enter/send key: bracketed,+ // a multiline dump in this read, or a run spanning reads (#643/#737).+ if (in_paste or paste.burstActive() or paste.looksLikeBurst(bytes)) {if (paste.pasteNewline(bytes, i, b)) |nl| return .{ .char = nl };}return .enter;diff --git a/TUI/key_paste.zig b/TUI/key_paste.zigindex 7e37cb06..c93a3975 100644--- a/TUI/key_paste.zig+++ b/TUI/key_paste.zig@@ -52,6 +52,19 @@ pub fn inBurst(now_ms: u64) bool {pub fn resetBurst() void {burst_until_ms = 0;+ active = false;+}++/// Whether the read the parser is walking belongs to a paste. The read loop+/// decides (it holds the clock); the parser only asks.+var active: bool = false;++pub fn setBurstRead(on: bool) void {+ active = on;+}++pub fn burstActive() bool {+ return active;}/// True when this read is part of a paste: it looks like one on its own, ordiff --git a/TUI/run.zig b/TUI/run.zigindex 9d36897e..6fcc0c85 100644--- a/TUI/run.zig+++ b/TUI/run.zig@@ -376,7 +376,7 @@ pub fn run(// A paste bigger than one read arrives as several back to back. Judge// the whole run, not each chunk: otherwise a chunk that ends at a line// boundary reads as Enter and sends half the paste (#737).- key_mod.setBurstRead(paste_mod.burstRead(inbuf[0..n], m.now_ms));+ paste_mod.setBurstRead(paste_mod.burstRead(inbuf[0..n], m.now_ms));// Everything this tick drained is applied as ONE batch, with runs of// consecutive wheel reports folded into a single accumulated delta// (pacing.zig). Order is preserved and a keystroke BREAKS the run atdiff --git a/src/playbook_glue.zig b/src/playbook_glue.zigindex bce866f1..131514e9 100644--- a/src/playbook_glue.zig+++ b/src/playbook_glue.zig@@ -70,7 +70,13 @@ pub fn noteConstraint(agent: *Agent, input: std.json.Value) ExecResult {refreshRoot(agent, agent.arena);// ADR 0021: the user just said this. Echoing "constraint recorded" is// machine state, not progress. The tool result still tells the model.- return .{ .text = std.fmt.allocPrint(agent.arena, "constraint recorded as {s}. It is now in {s} and rides every subagent, workflow and pipeline brief from here on, in this session and in later ones — you do not need to restate it.", .{ r.id, playbook.path }) catch "constraint recorded", .is_error = false };+ // The recorded constraint is in force NOW, not from the next user turn:+ // the ledger was rewritten before this result was written and the root+ // prompt refreshed above, so the very next request carries it. Saying so+ // matters — the model was still treating built-in guidance as controlling+ // for the rest of the turn and refusing the correction the user had just+ // asked for (#738).+ return .{ .text = std.fmt.allocPrint(agent.arena, "constraint recorded as {s}. It is now in {s} and rides every subagent, workflow and pipeline brief from here on, in this session and in later ones — you do not need to restate it. It takes effect immediately, in this turn: where it contradicts a built-in instruction the user has overruled that instruction, so act on the constraint now rather than waiting for the next turn.", .{ r.id, playbook.path }) catch "constraint recorded", .is_error = false };}/// Privacy-safe operational trace: id + success, never constraint text (#644).diff --git a/src/prompt_snapshot_tests.zig b/src/prompt_snapshot_tests.zigindex e48fc1ac..0e0f3010 100644--- a/src/prompt_snapshot_tests.zig+++ b/src/prompt_snapshot_tests.zig@@ -74,6 +74,22 @@ const golden_full_prompt =\\issue at justrach/codegraff (`gh issue create --repo justrach/codegraff\\...`), never in the current working repository's issue tracker.\\+ \\Anything you publish outside this machine — a GitHub issue, PR, comment or+ \\gist, a hosted page, a paste, a request to someone else's API — carries only+ \\what the task needs. Debugging gives you far more than that: prompts and+ \\conversation text, absolute paths, usernames and host details, model and+ \\provider names, session, run and trace ids, logs and test data. None of it+ \\belongs in a public artifact unless the user asked for that detail to be+ \\public. Being told to file the issue authorizes filing it, not copying your+ \\local context into it.+ \\Keep the evidence, drop the identifiers: an error message the tool printed,+ \\the failing behavior, event counts and relative timings, the cause in terms+ \\of the code. If a detail really is necessary and it identifies the user,+ \\their machine or their work, ask before publishing it and show what you+ \\would disclose. Editing afterwards does not undo it — edit history,+ \\notifications and mirrors keep the first version — so sanitize before the+ \\write, not after. Secrets are never publishable, with or without approval.+ \\\\When making git commits on behalf of the user, commit as the USER's own git\\identity — do NOT override GIT_AUTHOR_*/GIT_COMMITTER_*; their configured\\name + email (matching their GitHub account) must be the commit Author, justdiff --git a/src/prompt_text.zig b/src/prompt_text.zigindex 1605c737..e891e6fc 100644--- a/src/prompt_text.zig+++ b/src/prompt_text.zig@@ -99,6 +99,28 @@ pub const harness_issue_note =\\...`), never in the current working repository's issue tracker.;+/// Gate: `caps.local_tools`. Every outbound write goes through bash (gh, curl),+/// so the rule earns its tokens only where bash exists (#739).+pub const public_write_note =+ \\+ \\+ \\Anything you publish outside this machine — a GitHub issue, PR, comment or+ \\gist, a hosted page, a paste, a request to someone else's API — carries only+ \\what the task needs. Debugging gives you far more than that: prompts and+ \\conversation text, absolute paths, usernames and host details, model and+ \\provider names, session, run and trace ids, logs and test data. None of it+ \\belongs in a public artifact unless the user asked for that detail to be+ \\public. Being told to file the issue authorizes filing it, not copying your+ \\local context into it.+ \\Keep the evidence, drop the identifiers: an error message the tool printed,+ \\the failing behavior, event counts and relative timings, the cause in terms+ \\of the code. If a detail really is necessary and it identifies the user,+ \\their machine or their work, ask before publishing it and show what you+ \\would disclose. Editing afterwards does not undo it — edit history,+ \\notifications and mirrors keep the first version — so sanitize before the+ \\write, not after. Secrets are never publishable, with or without approval.+;+/// Gate: `caps.git_repo`. Commit-identity and PR-description discipline only/// earn their tokens where a repository exists to commit to — a scratch-dir/// one-shot or an eval run pays ~250 tokens/call for guidance it can neverdiff --git a/src/prompts.zig b/src/prompts.zigindex 4142795a..3d326ae0 100644--- a/src/prompts.zig+++ b/src/prompts.zig@@ -62,6 +62,7 @@ pub const segments = [_]Segment{.{ .name = "todo", .text = text.todo_note, .gate = .todos },.{ .name = "trace", .text = text.trace_note, .gate = .local_tools },.{ .name = "harness_issue", .text = text.harness_issue_note, .gate = .local_tools },+ .{ .name = "public_write", .text = text.public_write_note, .gate = .local_tools },.{ .name = "git_authoring", .text = text.git_authoring_note, .gate = .git_repo },.{ .name = "git_safety", .text = text.git_safety_note, .gate = .always },.{ .name = "work", .text = text.work_note, .gate = .always },@@ -473,6 +474,12 @@ pub const compact_instruction =\\that was created or modified, command results that matter, the current\\task checklist and each item's status, and any pending or unfinished\\work. Be thorough but compact. Reply with only the summary.+ \\Report only what this conversation actually contains. Do not write that a+ \\rule, constraint or preference was recorded — recorded constraints live in+ \\a durable ledger that is injected separately and in full, so a summary+ \\that asserts one invents it, and the agent reading you cannot tell the+ \\difference (#738). A standing instruction the user gave in words belongs+ \\here as what they said, attributed to them, not as machine state.;test { // #421/#410: prompt snapshots and goal-prefix behavior must stay reachable.