graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
fix(todo,loop): a write with no items changes nothing; clamp and rank the clock
Rach Pradhan63005144ab1c
diff --git a/src/agent_tools.zig b/src/agent_tools.zigindex 77a9cea0..2fcf6f10 100644--- a/src/agent_tools.zig+++ b/src/agent_tools.zig@@ -316,11 +316,11 @@ pub fn handleMeta(self: *Agent, call: ToolCall) !ExecResult {return self.runEval(note);}if (std.mem.eql(u8, call.name, "todo_write")) {- // Epoch-scoped replace, keeping omitted completed items: goal_todo owns- // the rule and its tests (this file is at the 600-line cap).- const rendered = try goal_todo.applyTodoWrite(self, call.input.object.get("todos"));- if (!self.sub) try self.say("{s}\n", .{rendered});- return .{ .text = rendered, .is_error = false };+ // Epoch-scoped replace, keeping omitted completed items; a write with+ // no usable items is rejected untouched (#318). goal_todo owns the rule.+ const r = try goal_todo.applyTodoWrite(self, call.input.object.get("todos"));+ if (!self.sub and !r.rejected) try self.say("{s}\n", .{r.text});+ return .{ .text = r.text, .is_error = r.rejected };}if (std.mem.eql(u8, call.name, "clock_sleep")) {const parsed = parseClockSleepMs(call.input) catch return .{diff --git a/src/command_catalog.zig b/src/command_catalog.zigindex 19cdcf20..2d7fc6df 100644--- a/src/command_catalog.zig+++ b/src/command_catalog.zig@@ -27,7 +27,7 @@ pub const commands = [_]Item{.{ .name = "/new", .desc = "start a fresh autosaved session" },.{ .name = "/rename", .usage = "/rename <title>", .desc = "set the current session title" },.{ .name = "/goal", .usage = "/goal [text|pause|resume|status|clear]", .desc = "set/show a standing objective (tracked as a checklist); pause/resume steering, status shows state, clear removes it" },- .{ .name = "/loop", .usage = "/loop <prompt>", .desc = "run an autonomous plan->act->verify pass" },+ .{ .name = "/loop", .usage = "/loop [30m] <prompt>", .desc = "run an autonomous plan->act->verify pass; an optional 30s/30m/2h budget paces it and stops it" },.{ .name = "/review", .usage = "/review <target or instructions>", .desc = "run one isolated read-only review pass; no edits, delegation, or workflows" },.{ .name = "/plan", .desc = "toggle plan mode: read-only explore + propose; writes/edits denied" },.{ .name = "/ultracode", .desc = "toggle persistent workflow mode; bare opens an on/off picker, or /ultracode on|off" },diff --git a/src/commands_session.zig b/src/commands_session.zigindex 79caeaef..e8a4714a 100644--- a/src/commands_session.zig+++ b/src/commands_session.zig@@ -199,7 +199,7 @@ pub fn tryHandle(root: *Agent, keys: *Keys, arena: Allocator, line: []const u8,return true;}if (std.mem.eql(u8, line, "/loop")) {- try out.writeAll("usage: /loop <prompt> — run an autonomous plan→act→verify pass.\n");+ try out.writeAll("usage: /loop [30m] <prompt> — run an autonomous plan→act→verify pass. A leading 30s/30m/2h paces the run and stops it when the time is up.\n");try out.flush();return true;}diff --git a/src/goal_flow.zig b/src/goal_flow.zigindex 83b16fff..acf4a645 100644--- a/src/goal_flow.zig+++ b/src/goal_flow.zig@@ -91,7 +91,7 @@ pub fn compactionSnapshot(arena: Allocator, root: *Agent) !?[]const u8 {if (rendered.len == 0)return try std.fmt.allocPrint(arena, "[standing state (harness-kept, survives context rewrites): goal: {s}. No checklist has been written for it yet - plan the work with todo_write, and read the list back with todo_read at any time.]", .{objective});const open = goal_state.openCount(root.todos.items, goal_state.currentEpoch(root.goal));- return try std.fmt.allocPrint(arena, "[standing state (harness-kept, survives context rewrites): goal: {s}. Checklist ({d} open):\n{s}\nThis list is live harness state, read it back with todo_read at any time. todo_write REPLACES the current goal's whole list, so include already-completed items when rewriting.]", .{ objective, open, try capRender(arena, rendered) });+ return try std.fmt.allocPrint(arena, "[standing state (harness-kept, survives context rewrites): goal: {s}. Checklist ({d} open):\n{s}\nThis list is live harness state, read it back with todo_read at any time. todo_write REPLACES the current goal's whole list; completed items you omit are kept automatically, open items you omit are dropped.]", .{ objective, open, try capRender(arena, rendered) });}/// Cut an oversized checklist render at a line boundary (never mid-item, never@@ -151,15 +151,20 @@ pub fn applyGoalSet(root: *Agent, objective: []const u8, now_ms: i64) GoalSetRes/// is governed by its work and its iteration bound alone.pub fn loopTurnDecision(root: *Agent, iters_left: u32, now_ms: i64) repl_glue.ContinuationDecision {const work_done = root.completed != null or goal_state.checklistFinished(root);- // A `/loop 30m ...` deadline is the run's ONLY hard effect (#224 dropped- // goal budget enforcement, and that stands): it stops the run and names the- // outcome. It flips no goal status and is never `accepted` - the work is- // unfinished, that is the whole point. Real completion evidence still wins,- // so a run that finished on its last second reports accepted, not expired.- if (!work_done) if (root.loop_deadline_ms) |d| if (now_ms >= d) return .{ .stop = .expired };const model_stopped = repl_glue.turnStopped(root.tool_calls_this_turn, root.completion_refused);const gstatus: agent_mod.GoalStatus = if (root.goal) |g| g.status else .active;- return repl_glue.continuationDecision(gstatus, work_done, model_stopped, iters_left);+ const d = repl_glue.continuationDecision(gstatus, work_done, model_stopped, iters_left);+ // A deadline is the run's ONLY hard effect (#224 dropped goal budget+ // enforcement): it stops the run and names the outcome, flipping no goal+ // status. accepted (real evidence) and cancelled/blocked (the USER is+ // needed) outrank the clock; expired renames only uninformative stops.+ if (root.loop_deadline_ms) |dl| if (now_ms >= dl) {+ return switch (d) {+ .continue_turn => .{ .stop = .expired },+ .stop => |o| if (o == .idle or o == .exhausted) .{ .stop = .expired } else d,+ };+ };+ return d;}/// The steering appended to each autonomous /loop continuation turn (the@@ -457,7 +462,7 @@ test "compactionSnapshot: no live goal, no checklist, and a capped render (#318)try std.testing.expect(capped.len < snapshot_render_cap + 600);try std.testing.expect(std.mem.indexOf(u8, capped, "checklist truncated") != null);try std.testing.expect(std.mem.indexOf(u8, capped, "Checklist (401 open)") != null);- try std.testing.expect(std.mem.endsWith(u8, capped, "when rewriting.]")); // the REPLACES warning survives the cut+ try std.testing.expect(std.mem.endsWith(u8, capped, "are dropped.]")); // the REPLACES warning survives the cut}test "a compaction does not move the goal note's diff-gate fingerprint (#318)" {diff --git a/src/goal_pacing.zig b/src/goal_pacing.zigindex f85f280c..f9be77e2 100644--- a/src/goal_pacing.zig+++ b/src/goal_pacing.zig@@ -17,6 +17,7 @@const std = @import("std");const Allocator = std.mem.Allocator;+const Io = std.Io;const Agent = @import("agent.zig").Agent;/// A parsed `/loop` argument: an optional wall-clock budget and the prompt.@@ -54,9 +55,15 @@ pub fn parseLoopBudget(text: []const u8) LoopBudget {const n = std.fmt.parseInt(i64, trimmed[0..digits], 10) catch return none;if (n <= 0) return none; // "0m" is not a deadline that already passed, it is a typoconst delta = std.math.mul(i64, n, unit) catch return none;- return .{ .deadline_ms_delta = delta, .prompt = prompt };+ // Clamped, not rejected: "/loop 9999h soak" is a real (if odd) instruction,+ // and an unclamped delta overflowed pacingNote's percent math (round-4+ // verifier: a typed line panicked Debug builds and mis-phased ReleaseFast).+ return .{ .deadline_ms_delta = @min(delta, max_budget_ms), .prompt = prompt };}+/// A week: past it nothing about a run is meaningful, and the percent math stays in i64.+pub const max_budget_ms: i64 = 7 * 24 * std.time.ms_per_hour;+/// The same parse straight off an input line, so the caller stays one line./// Returns null when the line is not a `/loop` invocation at all.pub fn loopBudgetFromLine(line: []const u8) ?LoopBudget {@@ -104,6 +111,16 @@ pub fn armFreshRun(clock: *LoopClock, root: *Agent, now_ms: i64, budget: ?LoopBuclock.arm(root, now_ms, b.deadline_ms_delta);}+/// armFreshRun plus one line of feedback the instant a wall clock arms. Silent+/// arming hid misparses: `/loop 5m ...` quietly took the "5m" out of the prompt+/// AND started a deadline whose only trace was an `expired` stop minutes later.+pub fn armAndAnnounce(clock: *LoopClock, root: *Agent, out: *Io.Writer, arena: Allocator, now_ms: i64, budget: ?LoopBudget) !void {+ armFreshRun(clock, root, now_ms, budget);+ const d = (budget orelse return).deadline_ms_delta orelse return;+ try out.print("\xe2\x8f\xb1 /loop budget: {s}\n", .{try fmtDur(arena, d)});+ try out.flush();+}+/// "45s" / "12m" / "1h5m" - short enough to sit inside a bracketed note.pub fn fmtDur(arena: Allocator, ms: i64) ![]const u8 {const secs = @divTrunc(@max(0, ms), std.time.ms_per_s);@@ -130,10 +147,12 @@ fn phaseHint(pct_left: i64) []const u8 {pub fn pacingNote(arena: Allocator, now_ms: i64, clock: LoopClock, iters_used: u32, iters_cap: u32) ![]const u8 {const elapsed = try fmtDur(arena, now_ms - clock.started_ms);const deadline = clock.deadline_ms orelse- return std.fmt.allocPrint(arena, "[pace: continuation {d} of {d}, {s} elapsed. No wall-clock budget was set for this run.]", .{ iters_used, iters_cap, elapsed });+ return std.fmt.allocPrint(arena, "[pace: continuation {d} of {d}, {s} elapsed.]", .{ iters_used, iters_cap, elapsed });const total = @max(1, deadline - clock.started_ms);const left = @max(0, deadline - now_ms);- const pct = @divTrunc(left * 100, total);+ // Divide before multiplying: parseLoopBudget clamps, but this math must not+ // depend on every caller remembering that (left * 100 overflowed i64).+ const pct = @divTrunc(left, @max(1, @divTrunc(total, 100)));return std.fmt.allocPrint(arena, "[pace: continuation {d} of {d}, {s} elapsed, ~{s} of the time budget left ({d}%). {s}]", .{ iters_used, iters_cap, elapsed, try fmtDur(arena, left), pct, phaseHint(pct) });}@@ -195,14 +214,26 @@ test "parseLoopBudget: every ambiguous shape stays a prompt, verbatim" {try std.testing.expect(b.deadline_ms_delta == null);try std.testing.expectEqualStrings(std.mem.trim(u8, text, " \t"), b.prompt);}+ // An absurd-but-parseable duration clamps to the week cap instead of+ // feeding pacingNote a deadline whose percent math overflows i64.+ try std.testing.expectEqual(@as(?i64, max_budget_ms), parseLoopBudget("30000000000h go").deadline_ms_delta);// And the whole thing only fires on a real /loop line.try std.testing.expect(loopBudgetFromLine("/goal 30m ship") == null);try std.testing.expectEqual(@as(?i64, 5 * std.time.ms_per_min), loopBudgetFromLine("/loop 5m ship").?.deadline_ms_delta);}-test "LoopClock: arms and clears the Agent-visible deadline together" {+/// The two Agent fields this file's helpers touch, initialized; everything+/// else stays undefined ON PURPOSE, so a future read of another field in this+/// path fails loudly under the testing allocator instead of passing by luck.+fn pacingRoot() Agent {var root: Agent = undefined;root.loop_deadline_ms = null;+ root.todos_dirty = false;+ return root;+}++test "LoopClock: arms and clears the Agent-visible deadline together" {+ var root = pacingRoot();var clock: LoopClock = .{};clock.arm(&root, 1_000, null);try std.testing.expect(clock.deadline_ms == null and root.loop_deadline_ms == null);@@ -251,8 +282,7 @@ test "childTaskPrompt: the same absolute deadline reaches every child, minus a m}test "armFreshRun: a /loop line starts the clock, any other line ends it" {- var root: Agent = undefined;- root.loop_deadline_ms = null;+ var root = pacingRoot();root.todos_dirty = true; // left over from the previous runvar clock: LoopClock = .{};@@ -280,9 +310,11 @@ test "pacingNote: iterations always, then remaining time and one phase hint" {defer arena_state.deinit();const ar = arena_state.allocator();- // No budget: the model still learns how many continuations it has left.+ // No budget: the model still learns how many continuations it has left,+ // and nothing more - a sentence restating the absence of a budget was pure+ // compaction fodder (25 unique copies per run, round-4 verifier).const plain = try pacingNote(ar, 90_000, .{ .started_ms = 0 }, 3, 25);- try std.testing.expectEqualStrings("[pace: continuation 3 of 25, 1m elapsed. No wall-clock budget was set for this run.]", plain);+ try std.testing.expectEqualStrings("[pace: continuation 3 of 25, 1m elapsed.]", plain);const clock: LoopClock = .{ .started_ms = 0, .deadline_ms = 60 * std.time.ms_per_min };const hints = [_]struct { now: i64, frag: []const u8 }{diff --git a/src/goal_state.zig b/src/goal_state.zigindex f202ae6e..66ffcfd2 100644--- a/src/goal_state.zig+++ b/src/goal_state.zig@@ -78,21 +78,6 @@ pub fn parkedOpenCount(todos: []const TodoItem, keep_epoch: u64) usize {return parked;}-/// Drop `epoch`'s items so todo_write can write that epoch's checklist afresh.-/// The only removal in this file, and the safe one: it is the authoring goal-/// rewriting its own list. Items from other (parked) epochs are untouched.-pub fn clearEpoch(todos: *std.ArrayList(TodoItem), epoch: u64) usize {- var removed: usize = 0;- var i: usize = 0;- while (i < todos.items.len) {- if (todos.items[i].epoch == epoch) {- _ = todos.orderedRemove(i);- removed += 1;- } else i += 1;- }- return removed;-}-/// A fresh goal set while a current (unscoped, or post-completion) checklist/// exists adopts it: the user just formalized the objective the plan was already/// serving. Only `from_epoch` items move - work parked by a finished or@@ -363,13 +348,10 @@ test "parking retains: superseded items are counted and kept, never deleted (#31try std.testing.expectEqual(@as(usize, 3), todos.items.len); // a mistyped /goal deletes nothingtry std.testing.expectEqual(@as(u64, 1), todos.items[0].epoch); // parked work keeps its own epoch// Retention is safe because every query is epoch-scoped: parked items are- // invisible to the new goal's open/allDone accounting.+ // invisible to the new goal's open/allDone accounting. (todo_write's+ // epoch-scoped replace lives in goal_todo.zig with its own tests.)try std.testing.expectEqual(@as(usize, 1), openCount(todos.items, 2));try std.testing.expect(!allDone(todos.items, 2));- // todo_write rewrites the CURRENT epoch only - parked items survive it.- try std.testing.expectEqual(@as(usize, 1), clearEpoch(&todos, 2));- try std.testing.expectEqual(@as(usize, 2), todos.items.len);- try std.testing.expectEqualStrings("phase3 audit", todos.items[0].content);}test "adoptTodos takes OPEN current-epoch items only; finished and parked work stays put" {diff --git a/src/goal_todo.zig b/src/goal_todo.zigindex bee4c2e2..e1adb736 100644--- a/src/goal_todo.zig+++ b/src/goal_todo.zig@@ -30,8 +30,9 @@ const goal_state = @import("goal_state.zig");/// EXCEPT completed ones whose content the incoming list does not mention./// Items from other (parked) epochs are never touched - the authoring goal is/// rewriting its own list, nobody else's. Returns the number removed.-/// This is goal_state.clearEpoch plus the preserve rule; clearEpoch itself-/// stays for the callers that really do mean "drop the whole epoch".+/// Callers must guarantee `incoming` is nonempty (applyTodoWrite rejects the+/// empty case): an empty replace here would leave only completed survivors,+/// an epoch that reads allDone off a write that did nothing (#318).pub fn clearEpochForReplace(todos: *std.ArrayList(TodoItem), epoch: u64, incoming: []const []const u8) usize {var removed: usize = 0;var i: usize = 0;@@ -53,18 +54,27 @@ fn mentions(contents: []const []const u8, content: []const u8) bool {return false;}+pub const WriteResult = struct { text: []const u8, rejected: bool = false };+/// The whole todo_write handler: replace the current epoch's checklist with/// `list` (the tool call's "todos" argument, already parsed), preserving/// omitted completed items, and return the rendered result the model sees.-/// `list` is null or a non-array when the model sent nothing usable, which is a-/// legitimate way to clear the open items of a checklist.-pub fn applyTodoWrite(root: *Agent, list: ?Value) ![]const u8 {+/// A write with ZERO usable items (missing/typo'd "todos" key, empty array,+/// items without a content string) is REJECTED without touching anything:+/// under the preserve rule it would have left the epoch holding only+/// completed survivors - allDone true, todos_dirty true - so one malformed+/// call ended a /loop as accepted and retired the goal (#318, proven by the+/// round-4 verifier). It must also never count as completion evidence, so+/// noteTodoWrite runs only on the accepted path.+pub fn applyTodoWrite(root: *Agent, list: ?Value) !WriteResult {const epoch = goal_state.currentEpoch(root.goal); // items belong to the goal that authored them (#318)var incoming: std.ArrayList([]const u8) = .empty;defer incoming.deinit(root.gpa);if (asArray(list)) |items| {for (items) |item| if (contentOf(item)) |c| try incoming.append(root.gpa, c);}+ if (incoming.items.len == 0)+ return .{ .text = "todo_write had no usable items; the list is unchanged. Each item needs a content string and a status. Send your full remaining plan - completed items you omit are kept automatically.", .rejected = true };_ = clearEpochForReplace(&root.todos, epoch, incoming.items);goal_state.noteTodoWrite(root); // fresh evidence for the completion double-check, and this-process evidence for /loop (#318)if (asArray(list)) |items| {@@ -78,7 +88,7 @@ pub fn applyTodoWrite(root: *Agent, list: ?Value) ![]const u8 {});}}- return goal_state.renderTodos(root, epoch);+ return .{ .text = goal_state.renderTodos(root, epoch) };}fn asArray(list: ?Value) ?[]const Value {@@ -133,9 +143,9 @@ test "a replace keeps omitted completed items and still drops omitted open ones"// the two finished items were deleted outright - most often after a// compaction, where the list is rewritten from a summary (#318) - and the// goal's record of what it had already done was gone for good.- const rendered = try applyTodoWrite(&root, try todosArg(ar,+ const rendered = (try applyTodoWrite(&root, try todosArg(ar,\\{"todos":[{"content":"wire it up","status":"in_progress"}]}- ));+ ))).text;try std.testing.expectEqualStrings("[x] write the helper\n[x] test it\n[~] wire it up", rendered);// The omitted OPEN item really is gone: a re-plan must be able to abandon work.try std.testing.expect(std.mem.indexOf(u8, rendered, "abandoned idea") == null);@@ -161,10 +171,10 @@ test "an incoming item with the same content replaces the preserved one, never d));// "that one was not actually done, redo it" has to keep working: the// incoming item wins outright, so the list holds one entry, not two.- const rendered = try applyTodoWrite(&root, try todosArg(ar,+ const rendered = (try applyTodoWrite(&root, try todosArg(ar,\\{"todos":[{"content":"land the fix","status":"pending"},\\ {"content":"and verify","status":"pending"}]}- ));+ ))).text;try std.testing.expectEqualStrings("[ ] land the fix\n[ ] and verify", rendered);try std.testing.expectEqual(@as(usize, 2), root.todos.items.len);try std.testing.expectEqual(@as(usize, 2), goal_state.openCount(root.todos.items, 1));@@ -181,16 +191,16 @@ test "the replace stays epoch-scoped: parked work of any status is untouched" {_ = try applyTodoWrite(&root, try todosArg(ar,\\{"todos":[{"content":"B1","status":"pending"}]}));- const rendered = try applyTodoWrite(&root, try todosArg(ar,+ const rendered = (try applyTodoWrite(&root, try todosArg(ar,\\{"todos":[{"content":"B2","status":"pending"}]}- ));+ ))).text;try std.testing.expectEqualStrings("[ ] B2", rendered); // B1 was open, so it droppedtry std.testing.expectEqual(@as(usize, 3), root.todos.items.len);try std.testing.expectEqual(@as(u64, 3), root.todos.items[0].epoch);try std.testing.expectEqual(@as(usize, 1), goal_state.parkedOpenCount(root.todos.items, 4));}-test "an empty or missing todos argument clears the open items but not the record" {+test "a write with zero usable items is rejected untouched, never completion evidence (#318)" {var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);defer arena_state.deinit();const ar = arena_state.allocator();@@ -199,9 +209,20 @@ test "an empty or missing todos argument clears the open items but not the recor_ = try applyTodoWrite(&root, try todosArg(ar,\\{"todos":[{"content":"done","status":"completed"},{"content":"open","status":"pending"}]}));- try std.testing.expectEqualStrings("[x] done", try applyTodoWrite(&root, try todosArg(ar, "{\"todos\":[]}")));- // A malformed call (no "todos" at all) takes the same path rather than crashing.- try std.testing.expectEqualStrings("[x] done", try applyTodoWrite(&root, null));+ root.todos_dirty = false; // as after a resume: the list is persisted state, not evidence+ // The round-4 verifier's exact trace: under the preserve rule, an empty or+ // malformed write used to strip the open items and leave only completed+ // survivors - allDone true, todos_dirty true - so one typo'd call ended a+ // /loop as accepted and retired the goal. It is rejected outright instead.+ for ([_]?Value{ try todosArg(ar, "{\"todos\":[]}"), null, try todosArg(ar, "{\"todos\":[{\"status\":\"pending\"}]}") }) |bad| {+ const r = try applyTodoWrite(&root, bad);+ try std.testing.expect(r.rejected);+ try std.testing.expect(std.mem.indexOf(u8, r.text, "unchanged") != null);+ }+ try std.testing.expectEqual(@as(usize, 2), root.todos.items.len); // nothing removed+ try std.testing.expectEqual(@as(usize, 1), goal_state.openCount(root.todos.items, 1));+ try std.testing.expect(!root.todos_dirty); // and no fake this-process evidence+ try std.testing.expect(!goal_state.checklistFinished(&root));}test "preserved [x] items never make the NEXT goal born done (#318 guard holds)" {@@ -213,10 +234,12 @@ test "preserved [x] items never make the NEXT goal born done (#318 guard holds)"_ = try applyTodoWrite(&root, try todosArg(ar,\\{"todos":[{"content":"A1","status":"completed"}]}));- // A replace that mentions nothing leaves A's finished item standing - which- // is precisely the state that used to make the next goal inherit a "done"- // checklist. adoptTodos takes OPEN items only, so it adopts nothing.- _ = try applyTodoWrite(&root, try todosArg(ar, "{\"todos\":[]}"));+ // A later replace omits A1 but it survives as history: the epoch reads all+ // done - precisely the state that used to make the next goal inherit a+ // "done" checklist. adoptTodos takes OPEN items only, so it adopts nothing.+ _ = try applyTodoWrite(&root, try todosArg(ar,+ \\{"todos":[{"content":"A2","status":"completed"}]}+ ));try std.testing.expect(goal_state.allDone(root.todos.items, 1));const epoch_b = goal_state.nextEpoch(root.goal, root.todos.items);@@ -228,5 +251,5 @@ test "preserved [x] items never make the NEXT goal born done (#318 guard holds)"const refusal = try goal_state.completionGate(ar, &root);try std.testing.expect(refusal != null and std.mem.indexOf(u8, refusal.?, "no checklist") != null);// A's record is still there, parked under its own epoch.- try std.testing.expectEqualStrings("[x] A1", goal_state.renderTodos(&root, 1));+ try std.testing.expectEqualStrings("[x] A1\n[x] A2", goal_state.renderTodos(&root, 1));}diff --git a/src/mainloop.zig b/src/mainloop.zigindex 6545a924..d63d0e46 100644--- a/src/mainloop.zig+++ b/src/mainloop.zig@@ -117,9 +117,10 @@ pub fn run(ctx: *Ctx) !void {// `/loop [<n>s|m|h] <prompt>`: an unambiguous duration arms this run's wall clock; anything else is prompt.const loop_budget: ?goal_pacing.LoopBudget = if (main_mod.json_mode) null else goal_pacing.loopBudgetFromLine(line);const loop_prompt: ?[]const u8 = if (loop_budget) |b| b.prompt else null;- // A fresh line starts (or ends) a /loop run: its wall clock begins here, and stale todos_dirty- // is dropped - a checklist finished BEFORE this prompt ended the next run at iteration 1 (#318).- if (!is_loop_continuation) goal_pacing.armFreshRun(&loop_clock, ctx.root, util.unixMs(ctx.io), loop_budget);+ // A fresh line starts (or ends) a /loop run: the wall clock begins here, stale todos_dirty is+ // dropped (a checklist finished BEFORE this prompt ended the next run at iteration 1, #318),+ // and an armed budget is echoed - a silently-eaten "5m" reads exactly like a truncated prompt.+ if (!is_loop_continuation) try goal_pacing.armAndAnnounce(&loop_clock, ctx.root, ctx.out, ctx.arena, util.unixMs(ctx.io), loop_budget);var review_prompt: ?[]const u8 = if (!main_mod.json_mode) review.promptFromLine(line) else null;// /goal <objective>: set the standing goal AND run it as the first turn right away — codex/opencode// both start the loop on a goal instead of just recording it (the parse itself is in repl_glue).diff --git a/src/repl_glue.zig b/src/repl_glue.zigindex 05c179bc..53eac064 100644--- a/src/repl_glue.zig+++ b/src/repl_glue.zig@@ -107,8 +107,8 @@ pub fn goalSteeringNote(arena: Allocator, goal: ?agent_mod.Goal) ![]const u8 {// attempt_completion "to end this steering", and one such call left the rest// of a headless/SDK session running unsteered (#318).if (g.standing)- return std.fmt.allocPrint(arena, "[standing goal: {s} - keep this objective in view on every task; track multi-step work as a live todo_write checklist (todo_read shows the current one; todo_write REPLACES it, so include already-completed items when rewriting), marking each item in_progress when you start and completed when done. This steering persists for the whole session.]", .{g.objective});- return std.fmt.allocPrint(arena, "[standing goal: {s} - track this as a live todo_write checklist and work through it (todo_read shows the current one; todo_write REPLACES it, so include already-completed items when rewriting), marking each item in_progress when you start and completed when done. When the objective is verifiably done, call attempt_completion - that completes the goal and ends this steering.]", .{g.objective});+ return std.fmt.allocPrint(arena, "[standing goal: {s} - keep this objective in view on every task; track multi-step work as a live todo_write checklist (todo_read shows the current one; todo_write REPLACES it - completed items you omit are kept, open items you omit are dropped), marking each item in_progress when you start and completed when done. This steering persists for the whole session.]", .{g.objective});+ return std.fmt.allocPrint(arena, "[standing goal: {s} - track this as a live todo_write checklist and work through it (todo_read shows the current one; todo_write REPLACES it - completed items you omit are kept, open items you omit are dropped), marking each item in_progress when you start and completed when done. When the objective is verifiably done, call attempt_completion - that completes the goal and ends this steering.]", .{g.objective});}/// Extract a 0-100 score from an eval command's output: a `score` key (JSON ordiff --git a/src/schema.zig b/src/schema.zigindex 8219736f..e5cec034 100644--- a/src/schema.zig+++ b/src/schema.zig@@ -130,7 +130,7 @@ const base_specs = [_]ToolSpec{const meta_specs = [_]ToolSpec{.{.name = "todo_write",- .desc = "Replace the task list for the current standing goal (items from a replaced, cleared or completed goal are parked - kept in the session, but not part of this list and not replaced by this call). An item you already marked completed is kept as history when you leave it out; list it again to change its status. Omitted pending/in_progress items are dropped. Use to plan and track multi-step work. Each item has content and status (pending|in_progress|completed).",+ .desc = "Replace the task list for the current standing goal (items from a replaced, cleared or completed goal are parked - kept in the session, but not part of this list and not replaced by this call). An item you already marked completed is kept as history when you leave it out; list it again (with any status) to change or remove it that way. Omitted pending/in_progress items are dropped. Every call needs at least one item: a call with none leaves the list untouched. Use to plan and track multi-step work. Each item has content and status (pending|in_progress|completed).",.schema =\\{"type": "object", "properties": {"todos": {"type": "array", "items": {"type": "object", "properties": {"content": {"type": "string"}, "status": {"type": "string", "enum": ["pending", "in_progress", "completed"]}}, "required": ["content", "status"]}}}, "required": ["todos"]},diff --git a/src/subagent_run.zig b/src/subagent_run.zigindex 597b61a9..baa50b77 100644--- a/src/subagent_run.zig+++ b/src/subagent_run.zig@@ -180,6 +180,7 @@ pub fn runSub(ctx: ToolCtx, kind: []const u8, label: []const u8, prompt: []const.approvals = ctx.approvals,.tracer = ctx.tracer,.run_budget = ctx.run_budget,+ .loop_deadline_ms = ctx.loop_deadline_ms, // a timed run's deadline reaches grandchildren too, not just depth 1.depth = ctx.depth + 1,.call_kind = if (std.mem.eql(u8, kind, "judge_task")).judge