graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
feat(peer): Accord Unix live path on by default
justrach2f49d79b9957
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 810a4244..14580c1e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -12,12 +12,10 @@ 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).+- Accord Unix 0600 live path is on by default (`GRAFF_ACCORD=0` opts out); JSONL stays the durable room (ADR 0134).- `#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).- `#1007`: idle `graff acp` sessions start that same turn; `peer_message` no longer claims delivery waits for a step boundary.- `#1006`: rendered views sit in the transcript without product chrome; desktop appearance tokens ride the turn (ADR 0135).-- `#1007`: idle `graff acp` sessions start that same turn; `peer_message` no longer claims delivery waits for a step boundary.-- `#1006`: rendered views sit in the transcript without product chrome; desktop appearance tokens ride the turn (ADR 0135).- 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.mdindex 866c1d67..3e17cf7e 100644--- a/docs/adr/0134-accord-live-jsonl-durable.md+++ b/docs/adr/0134-accord-live-jsonl-durable.md@@ -1,4 +1,4 @@-# 0134. JSONL is the durable peer room; Accord Unix is opt-in live+# 0134. JSONL is the durable peer room; Accord Unix is live by defaultStatus: accepted 2026-09-17@@ -11,13 +11,14 @@ Mailbox is a shape demo and cannot be the room.## DecisionJSONL stays the durable log. `postMessage` / `readNewMessages` remain the seam.-`GRAFF_ACCORD=1` may also send the same JSONL line over Unix 0600 (`GRAFF_ACCORD_SOCK`-or `{chan}.sock`). Default off. A live miss never fails the durable write.+On Unix, the same JSONL line is also sent live over Accord 0600 sockets in the+presence dir (`{pid}-{start}.accord.sock`). `GRAFF_ACCORD=0` opts out. Windows+stays JSONL-only. A live miss never fails the durable write.Do not replace the room with Mailbox.## ConsequencesIdle TUI, line-REPL, and `graff acp` sessions auto-start a turn on new parkedpeer mail (#1001, #1007), one batch at a time; `action=inbox` resets the latch.-An in-flight prompt is not preempted (#430). Flipping GRAFF_ACCORD-does not change history pull (ADR 0004).+An in-flight prompt is not preempted (#430). `GRAFF_ACCORD=0` does not+change history pull (ADR 0004).diff --git a/docs/adr/README.md b/docs/adr/README.mdindex 4e50b74b..f1c1e7a6 100644--- a/docs/adr/README.md+++ b/docs/adr/README.md@@ -153,7 +153,7 @@ record only when you need the evidence or the edge cases.| [0133](0133-clipboard-files-follow-consumer-ownership.md) | Clipboard cleanup requires file ownership and released consumers; age alone never deletes active or saved attachments. || [0133](0133-publication-review-binds-committed-inputs.md) | Proposed: non-draft publication reviews immutable source and observed checks; changed inputs invalidate earlier assessments. |-| [0134](0134-accord-live-jsonl-durable.md) | JSONL is the durable peer room; Accord Unix 0600 is opt-in live behind postMessage. |+| [0134](0134-accord-live-jsonl-durable.md) | JSONL is the durable peer room; Accord Unix 0600 is live by default (`GRAFF_ACCORD=0` opts out). || [0135](0135-desktop-appearance-is-a-turn-note.md) | Desktop appearance tokens for `render_html` ride the turn, never the prefix or tool catalog. |## When to write onediff --git a/src/acp_inbox.zig b/src/acp_inbox.zigindex 3a63fbc1..152f9ed1 100644--- a/src/acp_inbox.zig+++ b/src/acp_inbox.zig@@ -130,8 +130,14 @@ pub const Inbox = struct {}fn tickPump(self: *Inbox) void {+ const accord = @import("presence_accord.zig");while (true) {- self.io.sleep(.fromMilliseconds(200), .awake) catch break;+ var n: u32 = 0;+ while (n < 4) : (n += 1) {+ if (accord.takePing()) break;+ self.io.sleep(.fromMilliseconds(50), .awake) catch return;+ if (self.eof) return;+ }self.mutex.lockUncancelable(self.io);defer self.mutex.unlock(self.io);if (self.eof) break;diff --git a/src/presence_accord.zig b/src/presence_accord.zigindex 66c690ba..482c21aa 100644--- a/src/presence_accord.zig+++ b/src/presence_accord.zig@@ -1,6 +1,6 @@-//! Opt-in Accord Unix 0600 live path behind presence_chan.postMessage.-//! JSONL stays the durable room (ADR 0134). Off unless GRAFF_ACCORD=1-//! (or test_enabled). Lost live frames are never errors — the log remains.+//! Accord Unix 0600 live path behind presence_chan.postMessage.+//! JSONL stays the durable room (ADR 0134). On by default except Windows;+//! GRAFF_ACCORD=0 opts out. Lost live frames are never errors — the log remains.const std = @import("std");const builtin = @import("builtin");@@ -16,35 +16,142 @@ pub var test_enabled: bool = false;pub var test_sock: ?[]const u8 = null;pub fn enabled() bool {+ if (builtin.os.tag == .windows) return false;if (builtin.is_test) return test_enabled;- const v = std.c.getenv(env_var) orelse return false;+ const v = std.c.getenv(env_var) orelse return true;const s = std.mem.span(v);- if (s.len == 0) return false;+ if (s.len == 0) return true;return !std.mem.eql(u8, s, "0") and !std.mem.eql(u8, s, "off") and !std.mem.eql(u8, s, "false");}+var g_ping = std.atomic.Value(bool).init(false);+var g_io: ?Io = null;+var g_gpa: ?std.mem.Allocator = null;+var g_dir_path: ?[]u8 = null;+var g_own_name: ?[]u8 = null;+var g_listener: ?net.Server = null;+var g_future: ?Io.Future(void) = null;++pub fn takePing() bool {+ return g_ping.swap(false, .acq_rel);+}+fn sockPath(buf: []u8, chan_name: []const u8) ?[]const u8 {- if (builtin.is_test) {- if (test_sock) |p| return p;- } else if (std.c.getenv(sock_env)) |p| {+ _ = chan_name;+ if (builtin.is_test) return test_sock;+ if (std.c.getenv(sock_env)) |p| {const s = std.mem.span(p);- if (s.len > 0) return s;+ if (s.len > 0) {+ const n = @min(s.len, buf.len);+ @memcpy(buf[0..n], s[0..n]);+ return buf[0..n];+ }}- const stem = if (std.mem.endsWith(u8, chan_name, ".jsonl"))- chan_name[0 .. chan_name.len - ".jsonl".len]- else- chan_name;- return std.fmt.bufPrint(buf, "{s}.sock", .{stem}) catch null;+ return null;}/// Best-effort live send of the same JSONL line already appended to the room.-/// Never fails the durable write.+/// Never fails the durable write. Fans out to every peer sock in the live dir.pub fn livePost(io: Io, gpa: std.mem.Allocator, chan_name: []const u8, json_line: []const u8) void {if (!enabled()) return;if (builtin.os.tag == .windows) return;var path_buf: [std.fs.max_path_bytes]u8 = undefined;- const path = sockPath(&path_buf, chan_name) orelse return;- sendLine(io, gpa, path, json_line) catch {};+ if (sockPath(&path_buf, chan_name)) |path| {+ sendLine(io, gpa, path, json_line) catch {};+ return;+ }+ const dir_path = g_dir_path orelse return;+ var dir = Io.Dir.cwd().openDir(io, dir_path, .{ .iterate = true }) catch return;+ defer dir.close(io);+ var it = dir.iterate();+ while (it.next(io) catch null) |entry| {+ if (!std.mem.endsWith(u8, entry.name, ".accord.sock")) continue;+ if (g_own_name) |own| if (std.mem.eql(u8, entry.name, own)) continue;+ const path = std.fmt.bufPrint(&path_buf, "{s}/{s}", .{ dir_path, entry.name }) catch continue;+ sendLine(io, gpa, path, json_line) catch {};+ }+}++/// Bind `{live_dir}/{pid}-{start}.accord.sock` and accept live posts.+pub fn listen(io: Io, gpa: std.mem.Allocator, dir_path: ?[]const u8) void {+ if (!enabled()) return;+ if (builtin.os.tag == .windows) return;+ if (g_listener != null) return;+ const dir = dir_path orelse return;+ const self = @import("proc_identity.zig").selfRecord(io);+ var name_buf: [64]u8 = undefined;+ const name = std.fmt.bufPrint(&name_buf, "{d}-{x}.accord.sock", .{ self.pid, self.start_id }) catch return;+ var path_buf: [std.fs.max_path_bytes]u8 = undefined;+ const path = std.fmt.bufPrint(&path_buf, "{s}/{s}", .{ dir, name }) catch return;+ const owned_dir = gpa.dupe(u8, dir) catch return;+ const owned_name = gpa.dupe(u8, name) catch {+ gpa.free(owned_dir);+ return;+ };+ const listener = accord.listenUnix(io, path) catch {+ gpa.free(owned_dir);+ gpa.free(owned_name);+ return;+ };+ g_dir_path = owned_dir;+ g_own_name = owned_name;+ g_listener = listener;+ g_io = io;+ g_gpa = gpa;+ g_future = io.concurrent(acceptLoop, .{}) catch {+ stop(io);+ return;+ };+}++pub fn stop(io: Io) void {+ if (g_future) |*f| {+ f.cancel(io);+ g_future = null;+ }+ if (g_listener) |*l| {+ l.deinit(io);+ g_listener = null;+ }+ if (g_dir_path) |dir| if (g_own_name) |name| {+ var path_buf: [std.fs.max_path_bytes]u8 = undefined;+ if (std.fmt.bufPrint(&path_buf, "{s}/{s}", .{ dir, name })) |path| {+ Io.Dir.cwd().deleteFile(io, path) catch {};+ } else |_| {}+ if (g_gpa) |gpa| gpa.free(name);+ g_own_name = null;+ };+ if (g_dir_path) |dir| if (g_gpa) |gpa| gpa.free(dir);+ g_dir_path = null;+ g_gpa = null;+ g_io = null;+ g_ping.store(false, .release);+}++fn acceptLoop() void {+ const io = g_io orelse return;+ const gpa = g_gpa orelse return;+ const listener = &(g_listener orelse return);+ while (true) {+ const stream = listener.accept(io) catch break;+ serveOne(io, gpa, stream);+ }+}++fn serveOne(io: Io, gpa: std.mem.Allocator, stream: net.Stream) void {+ const sess = gpa.create(accord.Session) catch {+ stream.close(io);+ return;+ };+ sess.* = .{ .io = io, .gpa = gpa, .role = .server, .stream = stream };+ defer {+ sess.shutdown();+ gpa.destroy(sess);+ }+ sess.start() catch return;+ const got = sess.recv(1) catch return;+ defer got.deinit(gpa);+ g_ping.store(true, .release);}fn sendLine(io: Io, gpa: std.mem.Allocator, path: []const u8, json_line: []const u8) !void {@@ -116,11 +223,41 @@ const Pair = struct {}};-test "Accord live path is off by default" {+test "Accord live path is off in tests unless enabled" {try std.testing.expect(!test_enabled);try std.testing.expect(!enabled());}+test "listen binds a 0600 sock and stop unlinks it" {+ if (builtin.os.tag == .windows) return;+ const io = std.testing.io;+ const gpa = std.testing.allocator;+ test_enabled = true;+ defer {+ stop(io);+ test_enabled = false;+ }+ const dir = "graff-accord-listen";+ Io.Dir.cwd().makeDir(io, dir) catch |err| switch (err) {+ error.PathAlreadyExists => {},+ else => return err,+ };+ defer Io.Dir.cwd().deleteDir(io, dir) catch {};+ listen(io, gpa, dir);+ const name = g_own_name orelse return error.NoSock;+ var path_buf: [std.fs.max_path_bytes]u8 = undefined;+ const path = try std.fmt.bufPrint(&path_buf, "{s}/{s}", .{ dir, name });+ var tmp: [107:0]u8 = undefined;+ try std.testing.expect(path.len <= tmp.len);+ @memcpy(tmp[0..path.len], path);+ tmp[path.len] = 0;+ var st: std.c.Stat = undefined;+ try std.testing.expect(std.c.stat(tmp[0..path.len :0], &st) == 0);+ try std.testing.expectEqual(@as(std.c.mode_t, 0o600), st.mode & 0o777);+ stop(io);+ try std.testing.expect(std.c.stat(tmp[0..path.len :0], &st) != 0);+}+test "listenUnix socket is 0600" {if (builtin.os.tag == .windows) return;const io = std.testing.io;diff --git a/src/session_run.zig b/src/session_run.zigindex 66031cb7..a5070d83 100644--- a/src/session_run.zig+++ b/src/session_run.zig@@ -246,6 +246,7 @@ pub fn runOneshotPrompt(gpa: Allocator, io: Io, arena: Allocator, root: *agent_m// they reach the exit-time leak check — and our record would linger in// the registry until a peer's liveness probe reaps it.presence.retire(io);+ @import("presence_accord.zig").stop(io);presence.deinit(gpa);@import("router_catalog.zig").shutdown(io);// #396: the run is over. The frontend hands the terminal back and latches@@ -370,6 +371,7 @@ pub fn buildRootAgent(}}presence.noteLabelsFrom(io, gpa, arena, root.session_title, root.session_name);+ @import("presence_accord.zig").listen(io, gpa, presence.registryPath());if (flags.eval_cmd_flag) |c| root.eval_cmd = try arena.dupe(u8, c);// #502: --output-schema (inline JSON or @file) → structured outputs.if (flags.output_schema_flag) |schema_arg| {@@ -469,6 +471,7 @@ pub fn finalizeSession(gpa: Allocator, io: Io, arena: Allocator, out: *Io.Writer// #469: our presence record leaves the registry with us; a crashed session// skips this and gets reaped by the next reader's liveness probe instead.presence.retire(io);+ @import("presence_accord.zig").stop(io);presence.deinit(gpa); // its gpa-owned globals must not reach the exit-time leak check@import("router_catalog.zig").shutdown(io);@import("workspace_switch.zig").deinitDisplay(gpa);