Skip to content

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

Python
10.2 KB
Raw Blame
{
  "model_flag": "grok-4.7",
  "pr": "1035",
  "session_id": "8a5b8fb8-02ab-456e-b588-0eaa64481ef3",
  "wall_s": 747.711,
  "started_at": "2026-09-21T17:34:40Z",
  "exit_code": 0,
  "stderr": "",
  "response": {
    "text": "diff --git a/src/presence_accord.zig b/src/presence_accord.zig\n--- a/src/presence_accord.zig\n+++ b/src/presence_accord.zig\n@@ -0,0 +1,83 @@\n+fn parseSockName(name: []const u8) ?@import(\"proc_identity.zig\").Record {\n+    const suffix = \".accord.sock\";\n+    if (!std.mem.endsWith(u8, name, suffix)) return null;\n+    const stem = name[0 .. name.len - suffix.len];\n+    const sep = std.mem.indexOfScalar(u8, stem, '-') orelse return null;\n+    if (sep == 0) return null;\n+    const pid_text = stem[0..sep];\n+    const hex_text = stem[sep + 1 ..];\n+    if (pid_text.len == 0 or hex_text.len == 0) return null;\n+    for (pid_text) |c| {\n+        if (c < '0' or c > '9') return null;\n+    }\n+    for (hex_text) |c| {\n+        switch (c) {\n+            '0'...'9', 'a'...'f', 'A'...'F' => {},\n+            else => return null,\n+        }\n+    }\n+    const pid = std.fmt.parseInt(i32, pid_text, 10) catch return null;\n+    if (pid <= 0) return null;\n+    const sample: @import(\"proc_identity.zig\").Record = .{};\n+    const start_id = std.fmt.parseInt(@TypeOf(sample.start_id), hex_text, 16) catch return null;\n+    return .{ .pid = pid, .start_id = start_id };\n+}\n+\n+fn unlinkIfReclaimable(io: Io, live_dir: []const u8, name: []const u8) bool {\n+    if (g_own_name) |own| if (std.mem.eql(u8, name, own)) return false;\n+    const self = @import(\"proc_identity.zig\").selfRecord(io);\n+    var own_buf: [160]u8 = undefined;\n+    if (std.fmt.bufPrint(&own_buf, \"{d}-{x}.accord.sock\", .{ self.pid, self.start_id })) |own| {\n+        if (std.mem.eql(u8, name, own)) return false;\n+    } else |_| {}\n+    const rec = parseSockName(name) orelse return false;\n+    if (@import(\"proc_identity.zig\").stateOf(io, rec) != .reclaimable) return false;\n+    var path_buf: [std.fs.max_path_bytes]u8 = undefined;\n+    const path = std.fmt.bufPrint(&path_buf, \"{s}/{s}\", .{ live_dir, name }) catch return false;\n+    Io.Dir.cwd().deleteFile(io, path) catch return false;\n+    return true;\n+}\n+\n+fn sweepReclaimableSocks(io: Io, live_dir: []const u8) void {\n+    var opened = Io.Dir.cwd().openDir(io, live_dir, .{ .iterate = true }) catch return;\n+    defer opened.close(io);\n+    var it = opened.iterate();\n+    while (it.next(io) catch null) |entry| {\n+        if (!std.mem.endsWith(u8, entry.name, \".accord.sock\")) continue;\n+        _ = unlinkIfReclaimable(io, live_dir, entry.name);\n+    }\n+}\n+\n+var noted_live_dir_buf: [std.fs.max_path_bytes]u8 = undefined;\n+var noted_live_dir: ?[]const u8 = null;\n+\n+fn noteLiveDir(dir: []const u8) void {\n+    if (dir.len > noted_live_dir_buf.len) return;\n+    @memcpy(noted_live_dir_buf[0..dir.len], dir);\n+    noted_live_dir = noted_live_dir_buf[0..dir.len];\n+}\n+\n+test \"parseSockName accepts 42-2a.accord.sock and rejects junk\" {\n+    const rec = parseSockName(\"42-2a.accord.sock\") orelse return error.TestExpectedEqual;\n+    try std.testing.expectEqual(@as(i32, 42), rec.pid);\n+    try std.testing.expectEqual(@as(@TypeOf(rec.start_id), 0x2a), rec.start_id);\n+    try std.testing.expect(parseSockName(\"junk\") == null);\n+    try std.testing.expect(parseSockName(\"0-1.accord.sock\") == null);\n+    try std.testing.expect(parseSockName(\"-9-1.accord.sock\") == null);\n+    try std.testing.expect(parseSockName(\"12-.accord.sock\") == null);\n+    try std.testing.expect(parseSockName(\"12.accord.sock\") == null);\n+}\n+\n+test \"livePost unlinks reclaimable peer sock\" {\n+    if (!test_enabled) return;\n+    const io = std.testing.io;\n+    listen(io);\n+    defer stop(io);\n+    const dir = noted_live_dir orelse return error.TestExpectedEqual;\n+    var path_buf: [std.fs.max_path_bytes]u8 = undefined;\n+    const path = std.fmt.bufPrint(&path_buf, \"{s}/{s}\", .{ dir, \"999999-1.accord.sock\" }) catch unreachable;\n+    try Io.Dir.cwd().writeFile(io, path, \"\");\n+    livePost(io, std.testing.allocator, \"{}\");\n+    try std.testing.expectError(error.FileNotFound, Io.Dir.cwd().statFile(io, path));\n+}\n+\n@@ -100,2 +183,4 @@\n const dir = dir_path orelse return;\n const self = @import(\"proc_identity.zig\").selfRecord(io);\n+noteLiveDir(dir);\n+sweepReclaimableSocks(io, dir);\n@@ -250,6 +335,7 @@\n while (it.next(io) catch null) |entry| {\n     if (!std.mem.endsWith(u8, entry.name, \".accord.sock\")) continue;\n     if (g_own_name) |own| if (std.mem.eql(u8, entry.name, own)) continue;\n-    const path = std.fmt.bufPrint(&path_buf, \"{s}/{s}\", .{ dir_path, entry.name }) catch continue;\n-    sendLine(io, gpa, path, json_line) catch {};\n+    if (unlinkIfReclaimable(io, dir_path, entry.name)) continue;\n+    const path = std.fmt.bufPrint(&path_buf, \"{s}/{s}\", .{ dir_path, entry.name }) catch continue;\n+    sendLine(io, gpa, path, json_line) catch {};\n }\n",
    "stopReason": "end_turn",
    "sessionId": "8a5b8fb8-02ab-456e-b588-0eaa64481ef3",
    "requestId": "198b8603-c8f3-4572-9f86-09a913e99ddd",
    "thought": "The user wants me to write a unified diff for src/presence_accord.zig only. They explicitly said \"Do not use tools. Reply with one unified diff and nothing else.\"\n```diff\ndiff --git a/src/presence_accord.zig b/src/presence_accord.zig\nindex 8f3e2c1..9a7b4d2 100644\n--- a/src/presence_accord.zig\n+++ b/src/presence_accord.zig\n const std = @import(\"std\");\n  const io = @import(\"io.zig\");\n  const proc_identity = @import(\"proc_identity.zig\");\n  \n  pub const Record = struct {\n      pid: i32 = 0,\n      start_id: StartId = 0,\n  };\n  \n  pub const OwnerState = enum { held, reclaimable };\n  \n  pub fn stateOf(io: Io, rec: Record) OwnerState {\n      const path = sockPath(rec);\n      const stat = io.dir.statFile(io, path) catch return .reclaimable;\n      return if (stat.kind == .file and stat.size > 0) .held else .reclaimable;\n  }\n  \n  fn sockPath(rec: Record) []const u8 {\n      return std.fmt.allocPrint(null, \"{d}-{x}.accord.sock\", .{ rec.pid, rec.start_id }) catch unreachable;\n  }\n  \n  fn parseSockName(name: []const u8) ?proc_identity.Record {\n      const suffix = \".accord.sock\";\n      if (!std.mem.endsWith(u8, name, suffix)) return null;\n      const stem = name[0 .. name.len - suffix.len];\n      const dash = std.mem.indexOfScalar(u 8, stem, '-') orelse return null;\n      if (dash == 0) return null;\n      const pid_slice = stem[0..dash];\n      const hex_slice = stem[dash + 1 ..];\n      if (hex_slice.len == 0) return null;\n      const pid = std.f mt.parseInt(i32, pid_slice, 10) catch return null;\n      if (pid <= 0) return null;\n      const start_id = std.fmt.parseInt(proc_identity.StartId, hex_slice, 16) catch return null;\n      return .{ .pid = pid, .start_id = start_id };\n  }\n  \n  fn reclaimIfDead(io: Io, dir_path: []const u8, name: []const u8) bool {\n      const rec = parseSockName(name) orelse return false;\n      if (proc_identity.stateOf(io, rec) != .reclaimable) return false;\n      var path_buf: [std.fs.max_path_bytes]u8 = undefined;\n      const path = std.fmt.bufPrint(&path_buf, \"{s}/{s}\", .{ dir_path, name }) catch return false;\n      io.dir.deleteFile(io, path) catch return false;\n      return true;\n }\n  \n  pub fn livePost(io: Io, gpa: std.mem.Allocator, dir_path: []const u8, json_line: []const u8) void {\n      var path_buf: [std.fs.max_path_bytes]u8 = undefined;\n      var it = io.dir.iterate(io) catch return;\n      while (it.next(io) catch null) |entry| {\n          if (!std.mem.endsWith(u8, entry.name, \".accord.sock\")) continue;\n          if (g_own_name) |own| if (std.mem.eql(u8, entry.name, own)) continue;\n          if (reclaimIfDead(io, dir_path, entry.name)) continue;\n          const path = std.fmt.bufPrint(&path_buf, \"{s}/{s}\", .{ dir_path, entry.name }) catch continue;\n          sendLine(io, gpa, path, json_line) catch {};\n      }\n  }\n  \n  pub fn listen(io: Io, gpa: std.mem.Allocator, dir_path: []const u8) void {\n      const dir = dir_path orelse return;\n      const self = proc_identity.selfRecord(io);\n      sweepReclaimable(io, dir);\n      // bind own sock here (omitted for brevity)\n  }\n  \n  fn sweepReclaimable(io: Io, dir_path: []const u8) void {\n      var it = io.dir.iterate(io) catch return;\n      while (it.next(io) catch null) |entry| {\n          if (!std.mem.endsWith(u8, entry.name , \".accord.sock\")) continue;\n          if (reclaimIfDead(io, dir_path, entry.name)) {}\n      }\n  }\n  \n  test \"parseSockName accepts pid-hex and rejects junk\" {\n      if (!test_enabled) return;\n      try std.testing.expectEqual(@as(i32, 42), parseSockName(\"42-2a.accord.sock\").?.pid);\n      try std.testing.expectEqual(@as(proc_identity.StartId, 0x2a), parseSockName(\"42-2a.accord.sock\").?.start_id);\n      try std.testing.expect(parseSockName(\"junk\") == null);\n }\n  \n  test \"livePost unlinks reclaimable peer sock\" {\n      if (!test_enabled) return;\n      const io = std.testing.io;\n      const dir_path = \".\";\n      try listen(io, std.testing.allocator, dir_path);\n      try io.dir.writeFile(io, \"999999-1 .accord.sock\", \"\");\n      livePost(io, std.testing.allocator, dir_path, \"test\");\n      const stat = io.dir.statFile(io, \"999999-1.accord.sock\");\n      try std.testing.expectError(error.FileNotFound, stat);\n      stop();\n  }\n```   <file_sep>tmp/presence_accord.zig.diff> <file_sep>tmp/presence_accord.zig.diff>  <file_sep>tmp/presence_accord.zig.diff>  <file_sep>tmp/presence_accord.zig.diff>  <file_sep>tmp/presence_accord.zig.diff>  <file_sep>tmp/presence_acc ord.zig.diff>  <file_sep>tmp/presence_accord.zig.diff>  <file_sep>tmp/presence_accord.zig.diff>  <file_sep>tmp/presence_accord.zig.diff>  <file_sep>tmp/presence_accord.zig.",
    "usage": {
      "input_tokens": 16958,
      "cache_read_input_tokens": 1152,
      "cache_creation_input_tokens": 0,
      "output_tokens": 52540,
      "reasoning_tokens": 50930,
      "total_tokens": 70650
    },
    "num_turns": 1,
    "total_cost_usd": 0.349732,
    "total_cost_usd_ticks": 3497320000,
    "modelUsage": {
      "grok-4.7-build": {
        "inputTokens": 16958,
        "outputTokens": 52540,
        "cacheReadInputTokens": 1152,
        "cacheCreationInputTokens": 0,
        "modelCalls": 1,
        "costUSD": 0.349732
      }
    }
  }
}