Skip to content

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

Python

claude-agent: a prompt followed by notices stays the prompt

justrach82b4ae5b7148
diff --git a/err.txt b/err.txt
new file mode 100644
index 00000000..62677876
--- /dev/null
+++ b/err.txt
@@ -0,0 +1,12 @@
+{"type":"run_started","run_id":"0923cccfa4a5ab6f","session_id":"session-1793428962555-2630","parent_session_id":null}
+calling claude-agent-sonnet
+›
+›
+›
+›
+ [main] I couldn't find a `logs/` directory, so I haven't counted anything or written `summary.json`.
+
+The working directory is `/Users/rachpradhan/.harness/worktrees/codegraff/swift-falcon`. There's no `logs/` in it, and a search up to three levels deep turned up no directory with that name. I didn't search outside the worktree.
+
+Where are the logs? If you give me the path, I'll start one sub-agent per service (auth, billing, search, mailer) in parallel, then combine their counts into `summary.json`.
+[usage] 4 api call(s) · 44589 in (37470 cached, 7111 cache writes) + 522 out tokens · $0.00000000 · 4 subscription call(s), flat-rate (not in $)
diff --git a/graff-evals/harnesses.json b/graff-evals/harnesses.json
index fdffa27f..9d2844d9 100644
--- a/graff-evals/harnesses.json
+++ b/graff-evals/harnesses.json
@@ -440,16 +440,16 @@
"answer": "stdout",
"usage": "graff-stderr",
"capabilities": [],
- "env": {"GRAFF_CLAUDE_AGENT": "1", "GRAFF_MCP_CONFIG": "{repo}/graff-evals/empty-mcp.json", "GRAFF_POST_DEADLINE_SECS": "90"},
+ "env": {"GRAFF_CLAUDE_AGENT": "1", "GRAFF_MCP_CONFIG": "{repo}/graff-evals/no-global-mcp.json", "GRAFF_POST_DEADLINE_SECS": "90"},
"default_model": "sonnet",
- "note": "graff on the Claude Agent provider (ADR 0309): the user's own `claude` login runs the model; graff's prompt, tools and loop. Global MCP off; a task's .mcp.json still loads. Pass a Claude Code model alias (sonnet, opus, haiku)."
+ "note": "graff on the Claude Agent provider (ADR 0309): the user's own `claude` login runs the model; graff's prompt, tools and loop. GRAFF_MCP_CONFIG names a file that does not exist: no global MCP servers, while a task's .mcp.json still loads (an existing empty file would switch MCP off entirely). Pass a Claude Code model alias (sonnet, opus, haiku)."
},
"graff-dev-claude-agent-ccprompt": {
"cmd": ["{repo}/zig-out/bin/graff", "-p", "{prompt}", "--model", "claude-agent/{model}", "--yolo"],
"answer": "stdout",
"usage": "graff-stderr",
"capabilities": [],
- "env": {"GRAFF_CLAUDE_AGENT": "1", "GRAFF_CLAUDE_AGENT_PROMPT": "claude", "GRAFF_MCP_CONFIG": "{repo}/graff-evals/empty-mcp.json", "GRAFF_POST_DEADLINE_SECS": "90"},
+ "env": {"GRAFF_CLAUDE_AGENT": "1", "GRAFF_CLAUDE_AGENT_PROMPT": "claude", "GRAFF_MCP_CONFIG": "{repo}/graff-evals/no-global-mcp.json", "GRAFF_POST_DEADLINE_SECS": "90"},
"default_model": "sonnet",
"note": "graff-dev-claude-agent keeping Claude Code's system prompt with graff's appended."
},
diff --git a/out.txt b/out.txt
new file mode 100644
index 00000000..c1aaa25a
--- /dev/null
+++ b/out.txt
@@ -0,0 +1,5 @@
+I couldn't find a `logs/` directory, so I haven't counted anything or written `summary.json`.
+
+The working directory is `/Users/rachpradhan/.harness/worktrees/codegraff/swift-falcon`. There's no `logs/` in it, and a search up to three levels deep turned up no directory with that name. I didn't search outside the worktree.
+
+Where are the logs? If you give me the path, I'll start one sub-agent per service (auth, billing, search, mailer) in parallel, then combine their counts into `summary.json`.
diff --git a/src/claude_agent_history.zig b/src/claude_agent_history.zig
index 71a76123..a5bccc15 100644
--- a/src/claude_agent_history.zig
+++ b/src/claude_agent_history.zig
@@ -53,15 +53,20 @@ fn hasToolResult(m: Value) bool {
}
/// Content for the first message of a fresh session: the checkpoint of
-/// everything before the latest user prompt, then that prompt's own blocks.
+/// everything up to the last assistant reply, then the user messages after
+/// it as the prompt (graff may follow a prompt with notices of its own).
pub fn freshContent(a: Allocator, items: []const Value) !Value {
var blocks: std.json.Array = .init(a);
- const last_is_prompt = items.len > 0 and std.mem.eql(u8, role(items[items.len - 1]), "user") and !hasToolResult(items[items.len - 1]);
- const head = if (last_is_prompt) items[0 .. items.len - 1] else items;
+ var start = items.len;
+ while (start > 0 and std.mem.eql(u8, role(items[start - 1]), "user")) start -= 1;
+ var prompt_run = start < items.len;
+ for (items[start..]) |m| if (hasToolResult(m)) {
+ prompt_run = false; // results of a call in the checkpoint: no new prompt
+ };
+ const head = if (prompt_run) items[0..start] else items;
if (head.len > 0) try blocks.append(try textBlock(a, try checkpoint(a, head)));
- if (last_is_prompt) {
- const c = items[items.len - 1].object.get("content") orelse Value{ .string = "" };
- try appendPromptBlocks(a, &blocks, c);
+ if (prompt_run) {
+ for (items[start..]) |m| try appendPromptBlocks(a, &blocks, m.object.get("content") orelse Value{ .string = "" });
} else if (head.len > 0) {
try blocks.append(try textBlock(a, "Continue from where the checkpoint ends."));
}
diff --git a/src/claude_agent_tests.zig b/src/claude_agent_tests.zig
index dbed7566..14a3753e 100644
--- a/src/claude_agent_tests.zig
+++ b/src/claude_agent_tests.zig
@@ -151,6 +151,13 @@ test "claude-agent fresh session: earlier history is a checkpoint, the prompt ke
try std.testing.expect(std.mem.indexOf(u8, cp, "secret") == null); // no thinking text
try std.testing.expectEqualStrings("now add a test", blocks[1].object.get("text").?.string);
try std.testing.expect(blocks[1].object.get("cache_control") == null);
+ // A prompt followed by graff's own notice is still the prompt, not history.
+ const noticed = try parse(a,
+ \\[{"role":"user","content":"spawn two workers"},{"role":"user","content":"Already loaded for this turn: subagent."}]
+ );
+ const fresh = try history.freshContent(a, noticed.array.items);
+ try std.testing.expectEqual(@as(usize, 2), fresh.array.items.len);
+ try std.testing.expectEqualStrings("spawn two workers", fresh.array.items[0].object.get("text").?.string);
// Ending on tool results (a restart mid-loop): everything is checkpoint.
const mid = try history.freshContent(a, msgs.array.items[0..3]);
try std.testing.expectEqual(@as(usize, 2), mid.array.items.len);