graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Merge release/v0.0.302.2 into the supervisor-direct branch
Cursor Agent196d4268b6b0
diff --cc docs/adr/0149-daddy-directives-are-explicit-control.mdindex 00000000,00000000..bff3717bnew file mode 100644--- /dev/null+++ b/docs/adr/0149-daddy-directives-are-explicit-control.md@@@ -1,0 -1,0 +1,26 @@@++# 0149. Daddy directives are explicit supervisor control++++Status: accepted 2026-09-21++++## Context++++ADR 0147 already parks ambient `[peer]` wakes: they are not a new task, do++not inject during tool continuation, and do not idle-wake after++`attempt_completion`. A supervisor ("daddy") agent on the GUI Agent tab++needs the opposite: an explicit directive that *may* steer or wake a named++sibling.++++## Decision++++- A `[daddy]` directive (`peer_message action=direct` / `/daddy`) is named++ control. An idle root may start a turn on it even after completion. The GUI++ Agent tab sends the same prefix into the target conversation.++- Children in one process stay on `agent_message`. Daddy is the++ cross-session path. Surface chrome differs; the engine path is shared by++ REPL, TUI, and `graff acp`.++++## Consequences++++Ambient mail stays on ADR 0147. Completing a task no longer reopens on a++greeting, but a named `[daddy]` line can. Revisit if a structured control++channel replaces the prefixed DM.diff --cc docs/adr/README.mdindex a3c2b57b,6df2bdcf..0358778b--- a/docs/adr/README.md+++ b/docs/adr/README.md@@@ -165,7 -165,9 +165,10 @@@ record only when you need the evidence| [0143](0143-release-desktop-is-com-codegraff-app.md) | Packaged Codegraff.app is `com.codegraff.app`. `dev.*` identities are local rebuilds only. || [0144](0144-claim-asks-on-accord.md) | Claim conflicts ping the owner on Accord/JSONL; the model does not broker handoff in chat. || [0145](0145-live-claims-are-accord-progress.md) | Claim acquire/release/handoff replicate as replaceable Accord progress; the JSON ledger stays canonical. |- | [0146](0146-ambient-peer-wakes-are-not-authoritative.md) | Ambient `[peer]` wakes are not a new task; `[daddy]` directives are explicit supervisor control. |+ | [0146](0146-concurrent-sessions-auto-isolate.md) | A second live session in the same Git checkout gets its own worktree; concurrent agents never share `index.lock`. |+ | [0147](0147-finish-is-not-cleanup-fanout.md) | Finish is not archive: park peer wakes until idle, paint the tally at the step boundary, refuse cleanup/fix-it children, cap live fan-out. |+ | [0148](0148-read-file-miss-storm-stops.md) | After N same-prefix or incrementing `read_file` misses, refuse further guesses this turn and point at `codedb list_dir`. |++| [0149](0149-daddy-directives-are-explicit-control.md) | Ambient `[peer]` wakes are not a new task; `[daddy]` directives are explicit supervisor control. |## When to write onediff --cc src/daddy.zigindex 01847a6a,00000000..eb7befe6mode 100644,000000..100644--- a/src/daddy.zig+++ b/src/daddy.zig@@@ -1,224 -1,0 +1,224 @@@+//! Supervisor ("daddy") directives: explicit control of sibling sessions+//! and a slash/tool surface shared by REPL, TUI, and GUI (`graff acp`).+//!+//! Ambient peer mail stays a parked mailbox (ADR 0004 / #1137). A daddy+//! directive is a named DM whose body is prefixed `[daddy]`. Idle roots+//! may start a turn on that prefix even after `attempt_completion`; busy+//! roots still only see it at the next step (same as `/tell`).+//!+//! Children inside one process stay on `agent_message`. This module is+//! the cross-session supervisor path.++const std = @import("std");+const Io = std.Io;+const Allocator = std.mem.Allocator;++const agent_mod = @import("agent.zig");+const peer_inbox = @import("peer_inbox.zig");+const peer_target = @import("peer_target.zig");+const presence = @import("presence.zig");+const tools_mod = @import("tools.zig");+const Owner = @import("worktree_lease.zig").Owner;++const Agent = agent_mod.Agent;+const ExecResult = tools_mod.ExecResult;++pub const prefix = "[daddy] ";++pub fn isDirective(s: []const u8) bool {+ const t = std.mem.trimStart(u8, s, " \t\r\n");+ return std.mem.startsWith(u8, t, "[daddy]");+}++pub fn formatBody(arena: Allocator, text: []const u8) ![]const u8 {+ const t = std.mem.trim(u8, text, " \t\r\n");+ if (t.len == 0) return error.EmptyDirective;+ if (isDirective(t)) return t;+ return std.fmt.allocPrint(arena, "{s}{s}", .{ prefix, t });+}++pub fn stripPrefix(s: []const u8) []const u8 {+ const t = std.mem.trimStart(u8, s, " \t\r\n");+ if (std.mem.startsWith(u8, t, prefix)) return std.mem.trim(u8, t[prefix.len..], " \t\r\n");+ if (std.mem.startsWith(u8, t, "[daddy]")) return std.mem.trim(u8, t["[daddy]".len..], " \t\r\n");+ return t;+}++pub fn parkedDirectives() bool {+ return peer_inbox.anyTextPrefixed("[daddy]");+}++pub fn formatSteer(arena: Allocator, text: []const u8) []const u8 {+ const body = stripPrefix(text);+ return std.fmt.allocPrint(arena, "[daddy] directive — {s}", .{body}) catch "[daddy] directive waiting — peer_message action=inbox";+}++pub const Slash = struct { target: []const u8, text: []const u8 };++pub fn parseSlash(line: []const u8) ?Slash {+ if (!std.mem.startsWith(u8, line, "/daddy")) return null;+ if (line.len > 6 and line[6] != ' ' and line[6] != '\t') return null;+ const rest = std.mem.trim(u8, line["/daddy".len..], " \t");+ const split = std.mem.indexOfAny(u8, rest, " \t") orelse return null;+ const target = rest[0..split];+ const text = std.mem.trim(u8, rest[split + 1 ..], " \t");+ if (target.len == 0 or text.len == 0) return null;+ return .{ .target = target, .text = text };+}++fn peerListText(arena: Allocator, peers: []const Owner) []const u8 {+ var buf: std.ArrayList(u8) = .empty;+ for (peers) |p| {+ const line = std.fmt.allocPrint(arena, "\"{s}\" (pid {d})", .{ p.session_id, p.pid }) catch continue;+ buf.appendSlice(arena, line) catch {};+ buf.appendSlice(arena, ", ") catch {};+ }+ const items = buf.items;+ return if (items.len >= 2) items[0 .. items.len - 2] else items;+}++fn isLocal(peers: []const Owner, session_id: []const u8, my_identity: []const u8) bool {+ for (peers) |p| {+ if (std.mem.eql(u8, p.session_id, session_id)) return std.mem.eql(u8, p.identity, my_identity);+ }+ return true;+}++fn postDirect(io: Io, arena: Allocator, text: []const u8, to: []const u8, everyone: []const Owner) bool {+ const cross_folder = to.len > 0 and !isLocal(everyone, to, presence.ownIdentity());+ if (cross_folder) return presence.postToDevice(io, arena, text, to, false);+ return presence.postTo(io, arena, text, to);+}++pub fn send(self: *Agent, session: []const u8, text: []const u8) !ExecResult {+ const body = formatBody(self.arena, text) catch return .{+ .text = "daddy: empty text — say what the other agent should do",+ .is_error = true,+ };+ const everyone = presence.liveAllPeers(self.io, self.arena);+ if (session.len == 0) return .{+ .text = "daddy: name the session to direct (title, saved-session base, id, or pid). Not a room broadcast.",+ .is_error = true,+ };+ if (std.mem.eql(u8, session, "all")) return .{+ .text = "daddy: \"all\" is not a control target — name one session. Ambient room posts stay on peer_message action=send.",+ .is_error = true,+ };+ const to: []const u8 = switch (peer_target.resolvePeer(everyone, session)) {+ .one => |p| p.session_id,+ .none => return .{+ .text = try std.fmt.allocPrint(self.arena, "daddy: no live peer matches \"{s}\" — live now: {s}", .{ session, peerListText(self.arena, everyone) }),+ .is_error = true,+ },+ .ambiguous => return .{+ .text = try std.fmt.allocPrint(self.arena, "daddy: more than one live peer matches — name one: {s}", .{peerListText(self.arena, everyone)}),+ .is_error = true,+ },+ };+ if (!postDirect(self.io, self.arena, body, to, everyone)) return .{+ .text = "daddy: delivery failed — the presence registry is unavailable",+ .is_error = true,+ };+ return .{+ .text = try std.fmt.allocPrint(self.arena, "directed \"{s}\" — they read this as supervisor control at their next step (or an idle root starts a turn). Re-direct with session=\"{s}\".", .{ to, to }),+ .is_error = false,+ };+}++/// /daddy <session> <text>: user-facing supervisor control, same post as+/// `peer_message action=direct`.+pub fn slashCommand(root: *Agent, arena: Allocator, line: []const u8, out: *Io.Writer) !bool {+ if (!std.mem.startsWith(u8, line, "/daddy")) return false;+ if (line.len > 6 and line[6] != ' ' and line[6] != '\t') return false;+ const parsed = parseSlash(line);+ if (parsed == null) {+ try out.writeAll("usage: /daddy <session> <text> — direct one live graff (title, base, id, or pid). Not a room broadcast.\n");+ const everyone = presence.liveAllPeers(root.io, arena);+ if (everyone.len == 0) try out.writeAll(" (no live peers right now)\n") else try out.print(" live now: {s}\n", .{peerListText(arena, everyone)});+ try out.flush();+ return true;+ }+ const result = try send(root, parsed.?.target, parsed.?.text);+ try out.print("{s}\n", .{result.text});+ try out.flush();+ return true;+}++/// Idle wake text when a directive is parked — allowed after completion.+pub fn takeIdleText(arena: Allocator, buf: []u8) ?[]const u8 {+ if (!parkedDirectives()) return null;+ const wake = formatSteer(arena, "waiting");+ const copy = @min(wake.len, buf.len);+ @memcpy(buf[0..copy], wake[0..copy]);+ return buf[0..copy];+}++test "isDirective: prefix only" {+ try std.testing.expect(isDirective("[daddy] stop the publish"));+ try std.testing.expect(isDirective(" [daddy] hold"));+ try std.testing.expect(!isDirective("[peer] 1 unread"));+ try std.testing.expect(!isDirective("please finish"));+}++test "formatBody: prefixes once and rejects empty" {+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);+ defer arena_state.deinit();+ const a = arena_state.allocator();+ try std.testing.expectEqualStrings("[daddy] hold gui/src", try formatBody(a, "hold gui/src"));+ try std.testing.expectEqualStrings("[daddy] already", try formatBody(a, "[daddy] already"));+ try std.testing.expectError(error.EmptyDirective, formatBody(a, " "));+}++test "parseSlash: target and text; usage is null" {+ const ok = parseSlash("/daddy reviewer pause the PR") orelse return error.ExpectedSlash;+ try std.testing.expectEqualStrings("reviewer", ok.target);+ try std.testing.expectEqualStrings("pause the PR", ok.text);+ try std.testing.expect(parseSlash("/daddy") == null);+ try std.testing.expect(parseSlash("/daddyonly x") == null);+ try std.testing.expect(parseSlash("/tell reviewer hi") == null);+}++test "stripPrefix and formatSteer stay one line" {+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);+ defer arena_state.deinit();+ const a = arena_state.allocator();+ try std.testing.expectEqualStrings("pause the PR", stripPrefix("[daddy] pause the PR"));+ const steer = formatSteer(a, "[daddy] pause the PR");+ try std.testing.expect(std.mem.startsWith(u8, steer, "[daddy]"));+ try std.testing.expect(std.mem.indexOf(u8, steer, "pause the PR") != null);+ try std.testing.expect(std.mem.indexOfScalar(u8, steer, '\n') == null);+}++test "send refuses empty, all, and a missing session" {+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);+ defer arena_state.deinit();+ var root: Agent = undefined;+ root.arena = arena_state.allocator();+ root.io = std.testing.io;+ const empty = try send(&root, "reviewer", " ");+ try std.testing.expect(empty.is_error);+ const all = try send(&root, "all", "stop");+ try std.testing.expect(all.is_error);+ try std.testing.expect(std.mem.indexOf(u8, all.text, "all") != null);+ const missing = try send(&root, "no-such-peer", "stop");+ try std.testing.expect(missing.is_error);+}++test "parkedDirectives sees a [daddy] body and takeIdleText fires after completion" {+ peer_inbox.resetForTest();- @import("peer_wake.zig").resetForTest();++ @import("peer_idle.zig").resetForTest();+ defer {+ peer_inbox.resetForTest();- @import("peer_wake.zig").resetForTest();++ @import("peer_idle.zig").resetForTest();+ }- @import("peer_wake.zig").noteCompleted();- try std.testing.expect(!@import("peer_wake.zig").idlePeerAllowed());++ @import("peer_idle.zig").noteCompletion();++ try std.testing.expect(@import("peer_idle.zig").idleWakeSuppressed());+ try std.testing.expect(!parkedDirectives());+ _ = peer_inbox.parkHeard(&.{.{ .from_session = "s-dad", .text = "[daddy] switch to the tests" }}, &.{});+ try std.testing.expect(parkedDirectives());+ var buf: [128]u8 = undefined;+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);+ defer arena_state.deinit();+ const idle = takeIdleText(arena_state.allocator(), &buf) orelse return error.ExpectedDaddyIdle;+ try std.testing.expect(std.mem.indexOf(u8, idle, "[daddy]") != null);+}diff --cc src/main.zigindex 97f038a3,3df29599..c935d8c3--- a/src/main.zig+++ b/src/main.zig@@@ -590,7 -590,7 +590,7 @@@ test { // ── Unit tests (`zig buil_ = @import("goal_flow.zig");_ = @import("goal_todo.zig");_ = @import("goal_pacing.zig");- _ = .{ @import("presence_accord.zig"), @import("peer_idle.zig"), @import("acp_idle.zig"), @import("presence_chan.zig"), @import("presence_record.zig"), @import("peer_wake.zig"), @import("daddy.zig"), @import("peer_inbox_content_test.zig"), @import("peer_inbox_failure_test.zig"), @import("peer_inbox_storage_test.zig"), @import("peer_inbox_sequence_test.zig"), @import("peer_inbox_snapshot_test.zig") };- _ = .{ @import("presence_accord.zig"), @import("peer_idle.zig"), @import("acp_idle.zig"), @import("presence_chan.zig"), @import("presence_record.zig"), @import("peer_inbox_content_test.zig"), @import("peer_inbox_failure_test.zig"), @import("peer_inbox_storage_test.zig"), @import("peer_inbox_sequence_test.zig"), @import("peer_inbox_snapshot_test.zig") };++ _ = .{ @import("presence_accord.zig"), @import("peer_idle.zig"), @import("acp_idle.zig"), @import("presence_chan.zig"), @import("presence_record.zig"), @import("daddy.zig"), @import("peer_inbox_content_test.zig"), @import("peer_inbox_failure_test.zig"), @import("peer_inbox_storage_test.zig"), @import("peer_inbox_sequence_test.zig"), @import("peer_inbox_snapshot_test.zig") };_ = @import("acp_agents.zig");_ = @import("subagent_activity.zig");_ = @import("subagent_recovery.zig");diff --cc src/peer_channel.zigindex 62d732a6,42ca4de6..bd2239ba--- a/src/peer_channel.zig+++ b/src/peer_channel.zig@@@ -89,14 -90,10 +90,13 @@@ pub fn handleMessage(self: *Agent, call.is_error = true,};peer_idle.noteInboxConsumed();- @import("peer_wake.zig").markInboxCleared();return .{ .text = text, .is_error = false };}+ if (std.mem.eql(u8, action, "direct")) {+ return @import("daddy.zig").send(self, tools_mod.json_args.str(obj, "session") orelse "", tools_mod.json_args.str(obj, "text") orelse "");+ }if (!std.mem.eql(u8, action, "send")) return .{- .text = "peer_message action must be send, list, inbox, claim, release, handoff, or status",+ .text = "peer_message action must be send, list, inbox, direct, claim, release, handoff, or status",.is_error = true,};const text = tools_mod.json_args.str(obj, "text") orelse "";diff --cc src/peer_idle.zigindex 00bcd432,e4968caa..321e4f00--- a/src/peer_idle.zig+++ b/src/peer_idle.zig@@@ -38,15 -81,11 +81,16 @@@ fn ingest(io: Io, arena: Allocator) voi/// buffer so a spent Agent arena cannot hide new JSONL. Does not inject/// history — `runTurn`'s deliverInbound handles leftover room bytes.pub fn takeIdleWake(io: Io, buf: []u8) ?[]const u8 {- if (isBusy() or suppress_idle_wake) return null;++ if (isBusy()) return null;var scratch: [64 * 1024]u8 = undefined;var fba = std.heap.FixedBufferAllocator.init(&scratch);const arena = fba.allocator();ingest(io, arena);+ if (@import("daddy.zig").takeIdleText(arena, buf)) |t| {+ last_woken_unread = peer_inbox.unread();+ return t;+ }- if (!@import("peer_wake.zig").idlePeerAllowed()) return null;++ if (suppress_idle_wake) return null;const n = peer_inbox.unread();if (n == 0 or n <= last_woken_unread) return null;last_woken_unread = n;@@@ -113,3 -220,3 +225,17 @@@ test "#1001 more mail after a wake canconst again = takeIdleWake(io, &buf) orelse return error.ExpectedSecond;try std.testing.expect(std.mem.indexOf(u8, again, "[peer]") != null);}++++test "daddy idle wake fires after attempt_completion" {++ peer_inbox.resetForTest();++ resetForTest();++ defer {++ peer_inbox.resetForTest();++ resetForTest();++ }++ var buf: [256]u8 = undefined;++ noteCompletion();++ _ = peer_inbox.parkHeard(&.{.{ .from_session = "s-dad", .text = "[daddy] switch to the tests" }}, &.{});++ const wake = takeIdleWake(std.testing.io, &buf) orelse return error.ExpectedDaddyAfterCompletion;++ try std.testing.expect(std.mem.indexOf(u8, wake, "[daddy]") != null);++}