graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
fix(repl): quiet startup diagnostics
Rach Pradhan2e0a9b0463aa
diff --git a/scripts/test-pty-parallel-cancel.py b/scripts/test-pty-parallel-cancel.pyindex 0122bc48..7e5db6fc 100755--- a/scripts/test-pty-parallel-cancel.py+++ b/scripts/test-pty-parallel-cancel.py@@ -143,6 +143,7 @@ def main() -> None:# of ending at the prompt with nothing to go on. No marks at# all means the quit keystroke itself never landed."GRAFF_SHUTDOWN_DEBUG": "1",+ "GRAFF_REPL_DEBUG": "1", # this test asserts the debug-only parallel tool lifecycle rows}with PtySession(GRAFF, ["--model", "lmstudio", "--no-telemetry"], cwd=tmp, env=env, timeout=20) as session:session.wait_for_literal("] ›")diff --git a/src/engine_events.zig b/src/engine_events.zigindex 83a1c876..a8fcc28e 100644--- a/src/engine_events.zig+++ b/src/engine_events.zig@@ -129,6 +129,16 @@ pub const SessionBanner = struct { cwd: []const u8, trace_path: []const u8 };/// will checkpoint each turn onto that branch (main.g_worktree_autocommit).pub const WorktreeEntry = struct { path: []const u8, branch: []const u8, autocommit: bool };+/// A live Graff session already owns the checkout this session entered. Kept+/// structured so a frontend can foreground the owner and isolation action+/// instead of printing the collision warning as an undifferentiated string.+pub const SharedWorktreeOwner = struct {+ session_id: []const u8,+ pid: i32,+ active_minutes: i64,+ goal: []const u8,+};+/// Startup could not honor the saved model preference and picked another./// `blocked` means the substitute is cross-provider and not on the fallback/// allow-list, so it stays a one-session choice until the user widens it.@@ -323,6 +333,8 @@ pub const EngineEvent = union(enum) {session_banner: SessionBanner,/// `-w/--worktree` entered its scratch checkout.worktree_entered: WorktreeEntry,+ /// Another live session owns the checkout used by this session.+ shared_worktree_owner: SharedWorktreeOwner,/// The saved model preference could not be honored this session. The/// startup twin of provider_fallback, and deliberately not a Notice: a/// frontend that wants to offer "use it anyway" needs the fields.@@ -489,10 +501,11 @@ test "slice 1c: the tool-cluster notices are presentation pulses" {}test "slice 2: the lifecycle cluster is pulses, except the failover the wire carries" {- const pulses: [8]EngineEvent = .{+ const pulses: [9]EngineEvent = .{.{ .session_notice = .{ .text = "loaded 2 saved approval(s)", .tone = .dim } },.{ .session_banner = .{ .cwd = "/repo", .trace_path = ".graff/traces/a.jsonl" } },.{ .worktree_entered = .{ .path = ".graff/worktrees/w", .branch = "worktree-w", .autocommit = true } },+ .{ .shared_worktree_owner = .{ .session_id = "session-1", .pid = 42, .active_minutes = 5, .goal = "ship safely" } },.{ .saved_model_unavailable = .{ .saved = "old", .model = "new", .provider = "codex", .blocked = false } },.{ .mcp_consent_prompt = .{ .count = 3 } },.{ .session_saved = .{ .name = "session-1", .ext = ".session.json" } },diff --git a/src/engine_sink.zig b/src/engine_sink.zigindex 47118718..7e5e1a13 100644--- a/src/engine_sink.zig+++ b/src/engine_sink.zig@@ -45,6 +45,7 @@ const tool_render = @import("agent_tool_render.zig"); // slice 1c: the tool clusconst session_render = @import("session_render.zig"); // slice 2: the lifecycle cluster's terminal halfconst prompt_render = @import("agent_prompt_render.zig"); // batch 3: the status line's terminal halfconst tick_gate = @import("tick_gate.zig"); // #tui-tick: child ticks wait for a foreground line boundary+const repl = @import("repl.zig");/// An event plus its position, as delivered to a sink.pub const Stamped = struct {@@ -236,11 +237,11 @@ fn tuiEmit(ctx: *anyopaque, ev: Stamped) void {// the one file down here that still reaches the palette; the moments// the terminal never drew (the dispatch/close brackets, refusals) are// silent rather than absent from the vocabulary.- .tool_call_announced => |t| tool_render.toolUseLine(a, t),- .tool_result => |r| tool_render.toolResultLine(a, r),+ .tool_call_announced => |t| if (repl.g_debug) tool_render.toolUseLine(a, t),+ .tool_result => |r| if (repl.g_debug) tool_render.toolResultLine(a, r),.tool_call_started, .tool_call_finished, .tool_rejected => {},- .parallel_batch_started => |b| tool_render.parallelBatchStarted(a, b.count),- .parallel_batch_finished => |b| tool_render.parallelBatchFinished(a, b),+ .parallel_batch_started => |b| if (repl.g_debug) tool_render.parallelBatchStarted(a, b.count),+ .parallel_batch_finished => |b| if (repl.g_debug) tool_render.parallelBatchFinished(a, b),.completion_deferred => tool_render.completionDeferred(a),.goal_completed => tool_render.goalCompleted(a),.completion_text, .todo_list_updated => |t| tool_render.toolTextLine(a, t.text),@@ -251,6 +252,7 @@ fn tuiEmit(ctx: *anyopaque, ev: Stamped) void {.session_notice,.session_banner,.worktree_entered,+ .shared_worktree_owner,.saved_model_unavailable,.mcp_consent_prompt,.provider_fallback,diff --git a/src/engine_sink_tests.zig b/src/engine_sink_tests.zigindex f46304ba..0a429835 100644--- a/src/engine_sink_tests.zig+++ b/src/engine_sink_tests.zig@@ -13,6 +13,7 @@ const Agent = agent_mod.Agent;const engine_events = @import("engine_events.zig");const EngineEvent = engine_events.EngineEvent;const protocol_seq = @import("protocol_seq.zig");+const repl = @import("repl.zig");const engine_sink = @import("engine_sink.zig");const EngineSink = engine_sink.EngineSink;const VTable = engine_sink.VTable;@@ -255,13 +256,16 @@ test "a frontendless agent's wire sink burns no ids for the lines it cannot writtry std.testing.expectEqual(@as(u64, 0), protocol_seq.current());}-test "TuiSink draws the ⚙ and ✓ lines and nothing for the brackets (slice 1c)" {+test "TuiSink keeps tool diagnostics behind REPL debug mode (slice 1c)" {const saved_color = main_mod.use_color;main_mod.use_color = false;defer main_mod.use_color = saved_color;const saved_json = main_mod.json_mode; // sayText's root gate reads itmain_mod.json_mode = false;defer main_mod.json_mode = saved_json;+ const saved_debug = repl.g_debug;+ repl.g_debug = false;+ defer repl.g_debug = saved_debug;const ansi = @import("ansi.zig");const saved_style = ansi.style;ansi.style = .{}; // assert the text, not the palette@@ -277,11 +281,15 @@ test "TuiSink draws the ⚙ and ✓ lines and nothing for the brackets (slice 1cconst call: engine_events.ToolInvocation = .{ .name = "read_file", .input = input };const done: engine_events.ToolOutcome = .{ .name = "read_file", .text = "line one\nline two\n", .is_error = false };s.emit(undefined, .{ .tool_call_announced = call });+ s.emit(undefined, .{ .tool_result = done });+ try std.testing.expectEqualStrings("", aw.writer.buffered());++ repl.g_debug = true;+ s.emit(undefined, .{ .tool_call_announced = call });s.emit(undefined, .{ .tool_call_started = call }); // silent: the ⚙ line already said its.emit(undefined, .{ .tool_result = done });s.emit(undefined, .{ .tool_call_finished = done }); // silents.emit(undefined, .{ .tool_rejected = .{ .name = "bash", .input = input, .reason = "budget", .message = "no" } }); // silent- // Exactly the two lines the eval golden's tool turn shows.try std.testing.expectEqualStrings("⚙ read_file {\"path\":\"fixture.txt\"}\n ✓ line one…\n", aw.writer.buffered());}diff --git a/src/main.zig b/src/main.zigindex 180501ee..eb13e13b 100644--- a/src/main.zig+++ b/src/main.zig@@ -407,7 +407,7 @@ pub fn main(init: std.process.Init) !void {// Root system-prompt layering (base + AGENTS.md/HARNESS.md/CLAUDE.md + --append-system-prompt + active-skill lines + connected-MCP notes) lives// in startup.zig as buildSystemPrompt() — pure over io/arena, returns the composed base by value. buildRootAgent derives every prompt variant// from it via prompts.setSystemPrompts() (#326).- const sys_normal = try startup.buildSystemPrompt(io, arena, out, flags.system_prompt_flag, flags.append_system_flag, json_mode or flags.oneshot_prompt != null, (flags.oneshot_prompt != null or !(Io.File.stdin().isTty(io) catch true)) and !flags.effectiveYolo(), mcp_tools, g_codedbpro_licensed, init.environ_map.get("GRAFF_LEARNED_PROMPT"), init.environ_map);+ const sys_normal = try startup.buildSystemPrompt(io, arena, out, flags.system_prompt_flag, flags.append_system_flag, json_mode or flags.oneshot_prompt != null or init.environ_map.get("GRAFF_REPL_DEBUG") == null, (flags.oneshot_prompt != null or !(Io.File.stdin().isTty(io) catch true)) and !flags.effectiveYolo(), mcp_tools, g_codedbpro_licensed, init.environ_map.get("GRAFF_LEARNED_PROMPT"), init.environ_map);boot.mark(io, "system prompt");session_run.learningNotice(io, arena, init.environ_map, out, json_mode or flags.oneshot_prompt != null);diff --git a/src/mcp.zig b/src/mcp.zigindex c7a76b6f..9ea4630f 100644--- a/src/mcp.zig+++ b/src/mcp.zig@@ -54,6 +54,8 @@ pub const Registry = struct {mutex: Io.Mutex = .init,servers: []*Server = &.{},tools: []Tool = &.{},+ /// Startup connection/failure lines are developer diagnostics, not normal REPL output.+ show_diagnostics: bool = false,/// The stdio spec's backward-compatibility SHOULD: a dual-era client/// probes `server/discover` before assuming legacy. ON by default;/// `GRAFF_MCP_PROBE=0` opts out.@@ -233,7 +235,7 @@ pub const Registry = struct {};if (present) continue;reg.startServer(a, &servers, &tools, try a.dupe(u8, name), entry.value_ptr.*.object) catch |err| {- std.debug.print(" [mcp:{s}] failed to start: {t}\n", .{ name, err });+ if (reg.show_diagnostics) std.debug.print(" [mcp:{s}] failed to start: {t}\n", .{ name, err });};}reg.servers = try a.dupe(*Server, servers.items);@@ -438,7 +440,7 @@ pub const Registry = struct {try servers.append(a, server);registry_owns_server = true;const probe_note = if (server.probe_fallback) |reason| reason.note() else ""; // #327: a downgrade is never silent- std.debug.print(" [mcp:{s}] connected (mcp {s}) — {d} tool(s){s}\n", .{ name, server.protocol_version, tools_v.array.items.len, probe_note });+ if (reg.show_diagnostics) std.debug.print(" [mcp:{s}] connected (mcp {s}) — {d} tool(s){s}\n", .{ name, server.protocol_version, tools_v.array.items.len, probe_note });}/// One shared window bounds the whole teardown: the loop is sequential, sodiff --git a/src/mcp_boot.zig b/src/mcp_boot.zigindex 52029130..2c5ae953 100644--- a/src/mcp_boot.zig+++ b/src/mcp_boot.zig@@ -34,7 +34,7 @@ fn startServerTask(reg: *Registry, name: []const u8, cfg: std.json.ObjectMap) Stvar servers: std.ArrayList(*mcp_rpc.Server) = .empty;var tools: std.ArrayList(mcp.Tool) = .empty;reg.startServer(a, &servers, &tools, name, cfg) catch |err| {- std.debug.print(" [mcp:{s}] failed to start: {t}\n", .{ name, err });+ if (reg.show_diagnostics) std.debug.print(" [mcp:{s}] failed to start: {t}\n", .{ name, err });arena_state.deinit();return outcome;};@@ -48,13 +48,14 @@ fn startServerTask(reg: *Registry, name: []const u8, cfg: std.json.ObjectMap) St/// then handshake every server CONCURRENTLY. Returns null (no error) when/// neither file exists — MCP is optional. `global_path` is borrowed: it must/// outlive the registry, which re-reads it on `/mcp trust`.-pub fn init(gpa: Allocator, io: Io, config_path: []const u8, global_path: ?[]const u8, home: []const u8, environ_map: anytype) !?Registry {+pub fn init(gpa: Allocator, io: Io, config_path: []const u8, global_path: ?[]const u8, home: []const u8, show_diagnostics: bool, environ_map: anytype) !?Registry {var reg: Registry = .{.gpa = gpa,.io = io,.home = home,.arena_state = std.heap.ArenaAllocator.init(gpa),.stdio_probe = if (environ_map.get("GRAFF_MCP_PROBE")) |v| !std.mem.eql(u8, v, "0") else true,+ .show_diagnostics = show_diagnostics,.global_config_path = global_path,};mcp_rpc.applyHandshakeTimeoutEnv(environ_map); // #275 GRAFF_MCP_HANDSHAKE_SECS + #327 GRAFF_MCP_PROBE_MS, on the same pass as the probe flagdiff --git a/src/peer_channel.zig b/src/peer_channel.zigindex e2c1fdcd..a80c1f92 100644--- a/src/peer_channel.zig+++ b/src/peer_channel.zig@@ -24,6 +24,7 @@ const engine_sink = @import("engine_sink.zig");const presence = @import("presence.zig");const presence_chan = @import("presence_chan.zig");const worktree_lease = @import("worktree_lease.zig");+const repl = @import("repl.zig");const Agent = agent_mod.Agent;const ToolCall = tools_mod.ToolCall;@@ -222,14 +223,14 @@ pub fn deliverInbound(root: *Agent) void {if (note) |n| {buf.appendSlice(root.arena, n) catch {};buf.append(root.arena, '\n') catch {};- sink.emit(root.io, .{ .session_notice = .{ .text = n, .tone = .plain } });+ if (repl.g_debug) sink.emit(root.io, .{ .session_notice = .{ .text = n, .tone = .plain } });}if (omitted > 0) {const marker = std.fmt.allocPrint(root.arena, "[#469 channel: {d} older message(s) predating this session omitted]", .{omitted}) catch "";if (marker.len > 0) {buf.appendSlice(root.arena, marker) catch {};buf.append(root.arena, '\n') catch {};- sink.emit(root.io, .{ .session_notice = .{ .text = marker, .tone = .plain } });+ if (repl.g_debug) sink.emit(root.io, .{ .session_notice = .{ .text = marker, .tone = .plain } });}}if (skipped > 0) {@@ -237,7 +238,7 @@ pub fn deliverInbound(root: *Agent) void {if (marker.len > 0) {buf.appendSlice(root.arena, marker) catch {};buf.append(root.arena, '\n') catch {};- sink.emit(root.io, .{ .session_notice = .{ .text = marker, .tone = .plain } });+ if (repl.g_debug) sink.emit(root.io, .{ .session_notice = .{ .text = marker, .tone = .plain } });}}var lines: std.ArrayList([]const u8) = .empty;@@ -259,7 +260,7 @@ pub fn deliverInbound(root: *Agent) void {const window = displayWindow(is_backlog_drain, lines.items.len);if (window.hidden > 0) {const marker = std.fmt.allocPrint(root.arena, "[#469 channel: {d} backlog message(s) delivered to context — showing last {d}]", .{ window.hidden, backlog_repl_show }) catch "";- if (marker.len > 0) sink.emit(root.io, .{ .session_notice = .{ .text = marker, .tone = .plain } });+ if (marker.len > 0 and repl.g_debug) sink.emit(root.io, .{ .session_notice = .{ .text = marker, .tone = .plain } });}for (lines.items[window.start..]) |line|sink.emit(root.io, .{ .session_notice = .{ .text = line, .tone = .plain } });diff --git a/src/presence.zig b/src/presence.zigindex ef9da0c2..8ecdf396 100644--- a/src/presence.zig+++ b/src/presence.zig@@ -237,11 +237,11 @@ fn writeOwn(io: Io, arena: Allocator) void {}/// Register this root session and report any LIVE co-owner already present —-/// the #469 "see each other before, not mid-collision" moment. Returns an-/// arena-owned warning for the caller to surface (null = alone, or registry-/// unavailable). Never fails a session: every failure mode degrades to-/// silence, because presence must never be the reason graff did not start.-pub fn announce(io: Io, gpa: Allocator, arena: Allocator, home: []const u8, session_id: []const u8, goal: []const u8) ?[]const u8 {+/// the #469 "see each other before, not mid-collision" moment. Returns the+/// owner for the caller to surface (null = alone, or registry unavailable).+/// Never fails a session: every failure mode degrades to silence, because+/// presence must never be the reason graff did not start.+pub fn announce(io: Io, gpa: Allocator, arena: Allocator, home: []const u8, session_id: []const u8, goal: []const u8) ?Owner {if (builtin.is_test) return null; // tests get the parameterized store, never the real registryif (home.len == 0) return null;const dir_path = std.fmt.allocPrint(gpa, "{s}/{s}", .{ home, registry_subdir }) catch return null;@@ -259,16 +259,15 @@ pub fn announce(io: Io, gpa: Allocator, arena: Allocator, home: []const u8, sessvar chan_buf: [chan_name_max]u8 = undefined;g_chan = gpa.dupe(u8, chanName(&chan_buf, g_identity)) catch null;g_own_name = gpa.dupe(u8, name) catch return null;- // Peer check BEFORE writing our own record: the warning describes the tree as it was when we arrived.- const warning = blk: {+ // Peer check BEFORE writing our own record: the callout describes the tree as it was when we arrived.+ const duplicate = blk: {var dir = Io.Dir.cwd().openDir(io, dir_path, .{ .iterate = true }) catch break :blk null;defer dir.close(io);const peers = listPeers(io, arena, dir);- const dup = worktree_lease.duplicateOwner(peers.records, peers.probes, g_identity, self.pid) orelse break :blk null;- break :blk worktree_lease.duplicateOwnerWarning(arena, dup, unixMs(io) - dup.last_seen_ms);+ break :blk worktree_lease.duplicateOwner(peers.records, peers.probes, g_identity, self.pid);};writeOwn(io, arena);- return warning;+ return duplicate;}/// Remove our record. Best-effort: a crashed session leaves it behind and thediff --git a/src/repl_model_commands.zig b/src/repl_model_commands.zigindex 146d3441..ece320d4 100644--- a/src/repl_model_commands.zig+++ b/src/repl_model_commands.zig@@ -100,7 +100,7 @@ pub fn runCommand(self: *Model, line: []const u8) void {} else if (std.mem.eql(u8, cmd, "/debug")) {repl.g_debug = !repl.g_debug;self.dump_next = repl.g_debug;- self.pushFmt(.info, "debug: {s} — run `graff repl 2>/tmp/repl.log` to capture (raw agent stream per turn + frames → stderr)", .{onOff(repl.g_debug)}) catch {};+ self.pushFmt(.info, "debug: {s} — tool/presence diagnostics follow this toggle; set GRAFF_REPL_DEBUG=1 before launch for startup diagnostics + raw frames", .{onOff(repl.g_debug)}) catch {};} else if (std.mem.eql(u8, cmd, "/bash")) {self.push(.info, "running shell commands needs the agent loop — use the main `graff` session, or your shell") catch {};} else if (std.mem.eql(u8, cmd, "/mcp")) {diff --git a/src/session_render.zig b/src/session_render.zigindex fbb8d3db..08c1357f 100644--- a/src/session_render.zig+++ b/src/session_render.zig@@ -54,6 +54,7 @@ pub fn emit(w: ?*Io.Writer, ev: EngineEvent) void {style.dim, style.reset, style.accent, t.path, style.reset, t.branch,if (t.autocommit) autocommit_suffix else "",}),+ .shared_worktree_owner => |owner| sharedWorktreeOwner(w, owner),.saved_model_unavailable => |m| savedModelUnavailable(w, m),.mcp_consent_prompt => |p| line(w,@@ -92,6 +93,20 @@ fn toneColor(tone: engine_events.Notice.Tone) []const u8 {};}+fn sharedWorktreeOwner(w: ?*Io.Writer, owner: engine_events.SharedWorktreeOwner) void {+ const out = w orelse return;+ const session_id = if (owner.session_id.len > 0) owner.session_id else "unknown session";+ out.print("{s}╭─{s} {s}{s}◆ Shared worktree{s}\n", .{ style.dim, style.reset, style.accent, style.bold, style.reset }) catch return;+ out.print("{s}│{s} {s}Active session{s} {s}{s}{s} · pid {d} · active {d}m\n", .{+ style.dim, style.reset, style.dim, style.reset, style.accent, session_id, style.reset, owner.pid, owner.active_minutes,+ }) catch return;+ if (owner.goal.len > 0) out.print("{s}│{s} {s}Goal{s} {s}\n", .{ style.dim, style.reset, style.dim, style.reset, owner.goal }) catch return;+ out.print("{s}╰─{s} Edits share this checkout. Coordinate, or restart with {s}graff -w{s} to isolate.\n", .{+ style.dim, style.reset, style.bold, style.reset,+ }) catch return;+ out.flush() catch {};+}+/// The startup twin of providerFallback. The reset lands AFTER the newline/// here because the inline original wrote it with a separate `writeAll`, and/// this is a refactor: the bytes are the contract.@@ -162,6 +177,18 @@ test "slice 2: the startup lines render exactly as the inline prints did" {"worktree: .graff/worktrees/w (branch worktree-w) — edits isolated from the main checkout\n",renderTest(&aw, .{ .worktree_entered = .{ .path = ".graff/worktrees/w", .branch = "worktree-w", .autocommit = false } }),);+ try std.testing.expectEqualStrings(+ "╭─ ◆ Shared worktree\n" +++ "│ Active session session-42 · pid 4242 · active 5m\n" +++ "│ Goal polish startup output\n" +++ "╰─ Edits share this checkout. Coordinate, or restart with graff -w to isolate.\n",+ renderTest(&aw, .{ .shared_worktree_owner = .{+ .session_id = "session-42",+ .pid = 4242,+ .active_minutes = 5,+ .goal = "polish startup output",+ } }),+ );try std.testing.expectEqualStrings("note: saved model 'k2' is unavailable — selected sonnet via anthropic for this session; saved preference kept\n",renderTest(&aw, .{ .saved_model_unavailable = .{ .saved = "k2", .model = "sonnet", .provider = "anthropic", .blocked = false } }),@@ -243,6 +270,7 @@ test "slice 2: a frontendless lifecycle draws nothing" {emit(null, .{ .session_banner = .{ .cwd = "/repo", .trace_path = "t" } });emit(null, .{ .session_notice = .{ .text = "x", .tone = .dim } });emit(null, .{ .worktree_entered = .{ .path = "p", .branch = "b", .autocommit = true } });+ emit(null, .{ .shared_worktree_owner = .{ .session_id = "s", .pid = 1, .active_minutes = 0, .goal = "" } });emit(null, .{ .saved_model_unavailable = .{ .saved = "a", .model = "b", .provider = "c", .blocked = true } });emit(null, .{ .mcp_consent_prompt = .{ .count = 1 } });emit(null, .{ .session_saved = .{ .name = "s", .ext = ".session.json" } });diff --git a/src/session_run.zig b/src/session_run.zigindex 35a82b6f..175182fc 100644--- a/src/session_run.zig+++ b/src/session_run.zig@@ -205,7 +205,7 @@ pub fn initApprovalsHooksFleet(io: Io, gpa: Allocator, arena: Allocator, environfleet.g_home = keys_cli.homeEnv(environ_map); // for /agents promote's personal tierfleet.g_agent_types = fleet.loadAgentTypes(io, arena, fleet.g_home); // builtin < ~/.harness/agents (personal) < ./.harness/agents (private)const sink = engine_sink.writerSink(out);- const speak = !json_mode and flags.oneshot_prompt == null;+ const speak = !json_mode and flags.oneshot_prompt == null and environ_map.get("GRAFF_REPL_DEBUG") != null;if (persisted_approvals > 0 and speak)sink.emit(io, dimNotice(try std.fmt.allocPrint(arena, "loaded {d} saved approval(s) from {s}", .{ persisted_approvals, harness_policy.settings_path })));// Lifecycle hooks (pre_tool/post_tool/turn_end) from the same file.@@ -291,8 +291,16 @@ pub fn buildRootAgent(// #469: register this root session so co-resident graffs see it (and it// them) BEFORE anyone touches the shared tree — a live co-owner is named// at birth here, not discovered mid-collision.- if (presence.announce(io, gpa, arena, root.home, root.session_name, if (root.goal) |g| g.objective else "")) |warning| {- if (!main_mod.json_mode and flags.oneshot_prompt == null) try out.print("{s}", .{warning});+ if (presence.announce(io, gpa, arena, root.home, root.session_name, if (root.goal) |g| g.objective else "")) |owner| {+ if (!main_mod.json_mode and flags.oneshot_prompt == null) {+ const age_ms = util.unixMs(io) - owner.last_seen_ms;+ engine_sink.writerSink(out).emit(io, .{ .shared_worktree_owner = .{+ .session_id = owner.session_id,+ .pid = owner.pid,+ .active_minutes = @divTrunc(if (age_ms > 0) age_ms else 0, std.time.ms_per_min),+ .goal = owner.goal,+ } });+ }}if (flags.eval_cmd_flag) |c| root.eval_cmd = try arena.dupe(u8, c);if (flags.eval_target_flag) |t| root.eval_target = t;diff --git a/src/session_start.zig b/src/session_start.zigindex e5ebf454..3d855087 100644--- a/src/session_start.zig+++ b/src/session_start.zig@@ -144,7 +144,7 @@ pub fn setupWorktreeAndBanner(if (!main_mod.json_mode and flags.oneshot_prompt == null) {sink.emit(io, .{ .session_banner = .{ .cwd = main_mod.g_cwd_display, .trace_path = trace_path } });- if (codex_account) |acct| sink.emit(io, .{ .session_notice = .{+ if (environ_map.get("GRAFF_REPL_DEBUG") != null) if (codex_account) |acct| sink.emit(io, .{ .session_notice = .{.text = try std.fmt.allocPrint(arena, "logged into Codex (ChatGPT account {s}…) — /model codex", .{acct[0..@min(acct.len, 8)]}),} });if (flags.effectiveYolo()) sink.emit(io, .{ .session_notice = .{@@ -380,7 +380,7 @@ pub fn initRegistryConsent(io: Io, gpa: Allocator, arena: Allocator, out: *Io.Wr// --json's stdout is a JSONL stream and a one-shot's is the answer; neither// can carry chatter. With a global config `mcp_count > 0` in every project,// so an unguarded line here would corrupt the head of every --json run.- const quiet = json_mode or flags.oneshot_prompt != null;+ const quiet = json_mode or flags.oneshot_prompt != null or environ_map.get("GRAFF_REPL_DEBUG") == null;const merged = mcp_config.load(io, arena, Io.Dir.cwd(), mcp_config_path, global_path);// #416: resolve eager-vs-deferred BEFORE anything connects, so the first// catalog render already knows which servers pay their schemas up front.@@ -407,7 +407,7 @@ pub fn initRegistryConsent(io: Io, gpa: Allocator, arena: Allocator, out: *Io.Wrconst ans = in.takeDelimiter('\n') catch null;connect_mcp = ans != null and ans.?.len > 0 and (ans.?[0] == 'y' or ans.?[0] == 'Y');}- var registry: mcp.Registry = if (connect_mcp) ((mcp.Registry.init(gpa, io, mcp_config_path, global_path, home, environ_map) catch |err| inner: {+ var registry: mcp.Registry = if (connect_mcp) ((mcp.Registry.init(gpa, io, mcp_config_path, global_path, home, json_mode or flags.oneshot_prompt != null or environ_map.get("GRAFF_REPL_DEBUG") != null, environ_map) catch |err| inner: {sink.emit(io, .{ .session_notice = .{ .text = try std.fmt.allocPrint(arena, "[mcp] init failed: {t} — continuing without MCP", .{err}) } });if (telemetry.g_telem) |t| t.errorEvent("mcp", @errorName(err));break :inner null;@@ -420,6 +420,7 @@ pub fn initRegistryConsent(io: Io, gpa: Allocator, arena: Allocator, out: *Io.Wr// file precisely when consent was declined and no `init` ever ran. `arena`// is the session arena, so the path outlives the registry.registry.global_config_path = global_path;+ registry.show_diagnostics = json_mode or flags.oneshot_prompt != null or environ_map.get("GRAFF_REPL_DEBUG") != null;return registry;}@@ -445,7 +446,7 @@ pub fn probeLicensed(gpa: Allocator, io: Io) bool {/// is all that's needed — no return-by-value trickery here).pub fn connectCompanion(io: Io, arena: Allocator, registry: *mcp.Registry, flags: args.Flags, out: *Io.Writer, json_mode: bool, environ_map: anytype) !void {const sink = engine_sink.writerSink(out);- const speak = !json_mode and flags.oneshot_prompt == null;+ const speak = !json_mode and flags.oneshot_prompt == null and environ_map.get("GRAFF_REPL_DEBUG") != null;connect: {for (skills.companion_servers) |c| if (skills.mcpServerConnected(registry.tools, c.server)) break :connect;for (skills.companion_servers) |c| {diff --git a/src/startup.zig b/src/startup.zigindex e4512d85..a154cd8a 100644--- a/src/startup.zig+++ b/src/startup.zig@@ -299,9 +299,9 @@ pub fn resolveKeys(io: Io, gpa: Allocator, arena: Allocator, environ_map: anytyp/// then project instructions from the first of AGENTS.md/HARNESS.md//// CLAUDE.md found in the cwd, then --append-system-prompt text, then one/// capability line per active optional skill, then one usage note per-/// connected MCP server. `quiet` suppresses the "loaded project-/// instructions..." status line (set by callers the same way main() used-/// to gate it: json_mode or a one-shot prompt). Carved out of main()'s+/// connected MCP server. `quiet` suppresses startup diagnostics; interactive+/// callers clear it only for GRAFF_REPL_DEBUG, while JSON and one-shot modes+/// always keep stdout clean. Carved out of main()'s/// former inline block verbatim — pure over io/arena, returns everything by/// value, so it's safe to call from outside main()'s own stack frame./// The last edge of the learning loop: a genome this workspace actually