Skip to content

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

Python

feat(repl): idle line REPL starts a turn on new peer mail (#1001)

Rach Pradhaneb6e82d2664e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 386c5810..94afb580 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,7 +13,7 @@ current is part of cutting a release.
## Unreleased
- Opt-in Accord Unix 0600 live path behind `presence_chan.postMessage` (`GRAFF_ACCORD=1`); JSONL stays the durable room (ADR 0134).
-- `#1001`: idle TUI starts a turn when the durable peer room has new unread mail (one auto-turn per batch; inbox consume resets).
+- `#1001`: idle TUI and line REPL start a turn when the durable peer room has new unread mail (one auto-turn per batch; inbox consume resets).
- Live 12-PR board on grok-4.6 SuperGrok (n=3, no SPEC.md): graff / Pi /
OpenCode 12/12, grok 11/12 (`#727`), exo 9/12 (gemini + two turbos —
diff --git a/docs/adr/0134-accord-live-jsonl-durable.md b/docs/adr/0134-accord-live-jsonl-durable.md
index ade417f0..154fe584 100644
--- a/docs/adr/0134-accord-live-jsonl-durable.md
+++ b/docs/adr/0134-accord-live-jsonl-durable.md
@@ -17,6 +17,6 @@ Do not replace the room with Mailbox.
## Consequences
-Idle TUI sessions auto-start a turn on new parked peer mail (#1001), one
+Idle TUI and line-REPL sessions auto-start a turn on new parked peer mail (#1001), one
batch at a time; `action=inbox` resets the latch. Flipping GRAFF_ACCORD
does not change history pull (ADR 0004).
diff --git a/src/peer_idle.zig b/src/peer_idle.zig
index 0d6f9ece..16562f35 100644
--- a/src/peer_idle.zig
+++ b/src/peer_idle.zig
@@ -32,9 +32,13 @@ fn ingest(io: Io, arena: Allocator) void {
_ = peer_inbox.parkHeard(tree.items, heard.items);
}
-/// Idle TUI auto-turn. Null when nothing new is parked. Does not inject
-/// history — `runTurn`'s deliverInbound handles that if JSONL still has bytes.
-pub fn takeIdleWake(io: Io, arena: Allocator, buf: []u8) ?[]const u8 {
+/// Idle TUI auto-turn. Null when nothing new is parked. Uses a scratch
+/// 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 {
+ var scratch: [64 * 1024]u8 = undefined;
+ var fba = std.heap.FixedBufferAllocator.init(&scratch);
+ const arena = fba.allocator();
ingest(io, arena);
const n = peer_inbox.unread();
if (n == 0 or n <= last_woken_unread) return null;
@@ -63,7 +67,7 @@ test "#1001 idle wake fires once per new unread batch" {
defer arena_state.deinit();
const arena = arena_state.allocator();
var buf: [256]u8 = undefined;
- try std.testing.expect(takeIdleWake(io, arena, &buf) == null);
+ try std.testing.expect(takeIdleWake(io, &buf) == null);
const msg: presence_chan.Message = .{
.from_pid = 2,
@@ -73,15 +77,15 @@ test "#1001 idle wake fires once per new unread batch" {
.to = "s-me",
};
try std.testing.expectEqual(@as(usize, 1), peer_inbox.parkHeard(&.{msg}, &.{}));
- const first = takeIdleWake(io, arena, &buf) orelse return error.ExpectedWake;
+ const first = takeIdleWake(io, &buf) orelse return error.ExpectedWake;
try std.testing.expect(std.mem.indexOf(u8, first, "[peer]") != null);
try std.testing.expect(std.mem.indexOf(u8, first, "inbox") != null);
try std.testing.expectEqual(@as(usize, 1), peer_inbox.unread());
- try std.testing.expect(takeIdleWake(io, arena, &buf) == null);
+ try std.testing.expect(takeIdleWake(io, &buf) == null);
_ = try peer_inbox.takeAll(arena);
noteInboxConsumed();
- try std.testing.expect(takeIdleWake(io, arena, &buf) == null);
+ try std.testing.expect(takeIdleWake(io, &buf) == null);
}
test "#1001 more mail after a wake can fire again" {
@@ -92,16 +96,13 @@ test "#1001 more mail after a wake can fire again" {
resetForTest();
}
const io = std.testing.io;
- var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
- defer arena_state.deinit();
- const arena = arena_state.allocator();
var buf: [256]u8 = undefined;
const a: presence_chan.Message = .{ .from_pid = 2, .from_start = 1, .from_session = "s-a", .text = "one" };
const b: presence_chan.Message = .{ .from_pid = 3, .from_start = 1, .from_session = "s-b", .text = "two" };
_ = peer_inbox.parkHeard(&.{a}, &.{});
- try std.testing.expect(takeIdleWake(io, arena, &buf) != null);
- try std.testing.expect(takeIdleWake(io, arena, &buf) == null);
+ try std.testing.expect(takeIdleWake(io, &buf) != null);
+ try std.testing.expect(takeIdleWake(io, &buf) == null);
_ = peer_inbox.parkHeard(&.{b}, &.{});
- const again = takeIdleWake(io, arena, &buf) orelse return error.ExpectedSecond;
+ const again = takeIdleWake(io, &buf) orelse return error.ExpectedSecond;
try std.testing.expect(std.mem.indexOf(u8, again, "[peer]") != null);
}
diff --git a/src/readline.zig b/src/readline.zig
index 731190de..a079d0f5 100644
--- a/src/readline.zig
+++ b/src/readline.zig
@@ -52,6 +52,7 @@ const session = @import("session.zig");
const Agent = agent_mod.Agent;
const saveSession = session.saveSession;
const shutdown_trace = @import("shutdown_trace.zig"); // #364: the quit path's first phase stamp
+const peer_idle = @import("peer_idle.zig");
const rl_history = @import("readline_history.zig");
const HistoryNav = rl_history.HistoryNav;
const PasteStore = @import("readline_paste.zig").Store;
@@ -185,6 +186,18 @@ pub fn readLine(
input_util.g_shine_phase +%= 1;
redraw(out, buf.items, cur, marks.items, &pastes, &rstate, prompt_col);
}
+ // #1001: empty composer polls so peer mail can start a turn without a key.
+ if (buf.items.len == 0) {
+ while (!inputPendingTimed(200)) {
+ var wake_buf: [512]u8 = undefined;
+ if (peer_idle.takeIdleWake(root.io, &wake_buf)) |wake| {
+ buf.appendSlice(gpa, wake) catch break;
+ try out.writeAll("\r\n");
+ try out.flush();
+ return buf.items;
+ }
+ }
+ }
break :blk switch (tty.promptByte(in)) {
.byte => |b| b,
.eof => return null,
diff --git a/src/tui_launch.zig b/src/tui_launch.zig
index a9f40244..a1a692d2 100644
--- a/src/tui_launch.zig
+++ b/src/tui_launch.zig
@@ -214,8 +214,7 @@ fn idleWakeCb(ctx: ?*anyopaque, buf: []u8) ?[]const u8 {
if (job_notify.takeIdleWake(c.io, buf)) |t| return t; // an idle stop waits for a real step boundary (#199)
if (schedule.takeWake(c.io, buf)) |t| return t;
if (channel_worker.takeWake(c.io, buf)) |t| return t;
- const root = c.root orelse return null;
- return peer_idle.takeIdleWake(c.io, root.arena, buf);
+ return peer_idle.takeIdleWake(c.io, buf);
}
fn versionCb(ctx: ?*anyopaque, gpa: Allocator) ?[]const u8 {