summaryrefslogtreecommitdiff
path: root/9agents/src/tree.zig
diff options
context:
space:
mode:
Diffstat (limited to '9agents/src/tree.zig')
-rw-r--r--9agents/src/tree.zig50
1 files changed, 24 insertions, 26 deletions
diff --git a/9agents/src/tree.zig b/9agents/src/tree.zig
index 5e513f1..3c293ba 100644
--- a/9agents/src/tree.zig
+++ b/9agents/src/tree.zig
@@ -186,7 +186,7 @@ pub const Kind = enum(u8) { top = 0, path = 1, active = 2 };
comptime {
// The derived view indexes the same pinned roots the mirror does.
for (std.enums.values(Root)) |r| {
- if (!std.mem.eql(u8, @tagName(r), @tagName(@as(active.Kind, @enumFromInt(@intFromEnum(r))))))
+ if (!std.mem.eql(u8, @tagName(r), @tagName(@as(active.Kind, @fromBackingInt(@intCast(@backingInt(r)))))))
@compileError("tree.Root and active.Kind must agree, index by index");
}
}
@@ -226,8 +226,8 @@ pub const AFile = enum(u8) {
/// The fields of one entry, in listing order. A field with no value
/// is not listed and does not resolve.
pub const entry_files = [_]AFile{
- .pid, .ppid, .started, .cwd, .name, .title,
- .session, .model, .via, .zmx, .status, .transcript,
+ .pid, .ppid, .started, .cwd, .name, .title,
+ .session, .model, .via, .zmx, .status, .transcript,
};
pub const agent_files = [_]AFile{ .agent_model, .agent_transcript };
@@ -269,12 +269,12 @@ comptime {
pub fn activeNode(a: Act) u64 {
const arg: u48 = if (a.file == .message) a.msg else a.agent;
const serial: u48 = switch (a.file) {
- .harness_dir => @intFromEnum(a.kind),
+ .harness_dir => @backingInt(a.kind),
else => @as(u48, a.slot) | (@as(u48, a.gen) << act_slot_bits) | (arg << (act_slot_bits + act_gen_bits)),
};
return @bitCast(Node{
- .idx = @intFromEnum(a.file),
- .kind = @intFromEnum(Kind.active),
+ .idx = @backingInt(a.file),
+ .kind = @backingInt(Kind.active),
.serial = serial,
});
}
@@ -287,7 +287,7 @@ pub const Node = packed struct(u64) {
};
pub fn topNode(t: Top) u64 {
- return @bitCast(Node{ .idx = @intFromEnum(t), .kind = @intFromEnum(Kind.top) });
+ return @bitCast(Node{ .idx = @backingInt(t), .kind = @backingInt(Kind.top) });
}
pub const root: u64 = topNode(Top.root);
@@ -315,8 +315,8 @@ fn serialOf(slot: u12, gen: u32) u48 {
fn nodeOf(e: *const Entry, slot: u12) u64 {
return @bitCast(Node{
- .idx = @intFromEnum(e.root),
- .kind = @intFromEnum(Kind.path),
+ .idx = @backingInt(e.root),
+ .kind = @backingInt(Kind.path),
.serial = serialOf(slot, e.gen),
});
}
@@ -516,15 +516,15 @@ pub const Harness = struct {
}
pub fn base(h: *const Harness, r: Root) ?[]const u8 {
- if (!h.base_set[@intFromEnum(r)]) return null;
- return h.base_buf[@intFromEnum(r)][0..h.base_len[@intFromEnum(r)]];
+ if (!h.base_set[@backingInt(r)]) return null;
+ return h.base_buf[@backingInt(r)][0..h.base_len[@backingInt(r)]];
}
// -- path table --
fn hashOf(r: Root, rel_path: []const u8) u64 {
var hh = std.hash.Wyhash.init(0x6861_726e_6573_7300); // "harness"
- hh.update(&.{@intFromEnum(r)});
+ hh.update(&.{@backingInt(r)});
hh.update(rel_path);
return hh.final();
}
@@ -969,7 +969,7 @@ fn activePath(h: *Harness, a: Act) ?[]const u8 {
/// that is not below the root is not opened at all. Non-blocking, so a
/// fifo cannot park the daemon; the caller checks what it got.
fn openAgentFile(h: *Harness, k: active.Kind, path: []const u8) ?Io.File {
- const r: Root = @enumFromInt(@intFromEnum(k));
+ const r: Root = @fromBackingInt(@intCast(@backingInt(k)));
const b = h.base(r) orelse return null;
if (path.len <= b.len + 1 or !std.mem.startsWith(u8, path, b) or path[b.len] != '/') return null;
const fd = openIn(h, r, path[b.len + 1 ..], .{ .ACCMODE = .RDONLY, .NONBLOCK = true, .CLOEXEC = true }) orelse return null;
@@ -1357,7 +1357,7 @@ fn spawnZmx(h: *Harness, l: *const active.Live, name: []const u8, resume_value:
var argv: [9]?[*:0]const u8 = @splat(null);
var n: usize = 0;
const parts = [_][]const u8{
- h.zmx_buf[0..h.zmx_len], "run", name, "-d",
+ h.zmx_buf[0..h.zmx_len], "run", name, "-d",
harness_argv0, resume_flag, resume_value,
};
for (parts) |w| {
@@ -1387,7 +1387,7 @@ fn spawnZmx(h: *Harness, l: *const active.Live, name: []const u8, resume_value:
const child: i32 = @intCast(rc);
var status: u32 = 0;
for (0..post_ticks) |_| {
- const w = linux.waitpid(child, &status, 1); // WNOHANG
+ const w = linux.waitpid(child, @ptrCast(&status), 1); // WNOHANG
if (w == @as(usize, @intCast(child))) break;
napOneTick(h);
}
@@ -1893,10 +1893,9 @@ const Rig = struct {
var mk: [std.fs.max_path_bytes]u8 = undefined;
// The five roots, pinned to the fake home.
inline for ([_][]const u8{
- ".claude/projects/p1", ".claude/skills/revu",
- ".codex/sessions/2026/09/21",
- ".omp/agent", ".hermes/logs",
- ".dsh/profiles",
+ ".claude/projects/p1", ".claude/skills/revu",
+ ".codex/sessions/2026/09/21", ".omp/agent",
+ ".hermes/logs", ".dsh/profiles",
}) |sub| {
try Io.Dir.cwd().createDirPath(io, try std.fmt.bufPrint(&mk, "{s}/{s}", .{ rig.home, sub }));
}
@@ -1948,7 +1947,6 @@ const Rig = struct {
try file.writeStreamingAll(testing.io, bytes);
}
-
fn del(rig: *Rig, rel_path: []const u8) !void {
var buf: [std.fs.max_path_bytes]u8 = undefined;
const path = try std.fmt.bufPrint(&buf, "{s}/{s}", .{ rig.home, rel_path });
@@ -1983,7 +1981,7 @@ const Rig = struct {
const target = if (o.cwd.len > 0) o.cwd else rig.home;
var link_buf: [std.fs.max_path_bytes]u8 = undefined;
- const link = try std.fmt.bufPrintZ(&link_buf, "{s}/proc/{d}/cwd", .{ rig.home, o.pid });
+ const link = try std.fmt.bufPrintSentinel(&link_buf, "{s}/proc/{d}/cwd", .{ rig.home, o.pid }, 0);
Io.Dir.cwd().symLink(testing.io, target, link, .{}) catch {};
}
@@ -2171,7 +2169,7 @@ test "tree: paths compose only from the pinned roots" {
try expectNoent(rig.lookupName(2, topNode(.claude), "projects/\x00"));
// A symlink inside a mirror is not served, whatever it points at.
var buf: [std.fs.max_path_bytes]u8 = undefined;
- const link = try std.fmt.bufPrintZ(&buf, "{s}/.claude/projects/p1/escape", .{rig.home});
+ const link = try std.fmt.bufPrintSentinel(&buf, "{s}/.claude/projects/p1/escape", .{rig.home}, 0);
try Io.Dir.cwd().symLink(testing.io, rig.home, link, .{});
const projects = rig.lookupName(3, topNode(.claude), "projects");
const p1 = rig.lookupName(4, projects.reply.attr.node, "p1");
@@ -2379,7 +2377,7 @@ test "tree: a name swapped for a symlink under an open handle serves nothing" {
// The file becomes a symlink out of the tree while the handle is open.
var link_buf: [std.fs.max_path_bytes]u8 = undefined;
var target_buf: [std.fs.max_path_bytes]u8 = undefined;
- const link = try std.fmt.bufPrintZ(&link_buf, "{s}/.claude/projects/p1/swap.txt", .{rig.home});
+ const link = try std.fmt.bufPrintSentinel(&link_buf, "{s}/.claude/projects/p1/swap.txt", .{rig.home}, 0);
const target = try std.fmt.bufPrint(&target_buf, "{s}/outside.txt", .{rig.home});
try rig.del(".claude/projects/p1/swap.txt");
try Io.Dir.cwd().symLink(testing.io, target, link, .{});
@@ -2415,7 +2413,7 @@ test "tree: a listing spanning several reads loses no entry" {
const count = 200;
var name_buf: [320]u8 = undefined;
for (0..count) |i| {
- const name = try std.fmt.bufPrint(&name_buf, ".dsh/{d:0>3}{s}", .{ i, "n" ** 200 });
+ const name = try std.fmt.bufPrint(&name_buf, ".dsh/{d:0>3}{s}", .{ i, &@as([200]u8, @splat('n')) });
try rig.put(name, "");
}
var seen: [count]bool = @splat(false);
@@ -2686,7 +2684,7 @@ test "chat: a codex agent's rollout, found through the fd it holds" {
var link_buf: [std.fs.max_path_bytes]u8 = undefined;
var target_buf: [std.fs.max_path_bytes]u8 = undefined;
try Io.Dir.cwd().createDirPath(testing.io, try std.fmt.bufPrint(&link_buf, "{s}/proc/1102/fd", .{rig.home}));
- const link = try std.fmt.bufPrintZ(&link_buf, "{s}/proc/1102/fd/3", .{rig.home});
+ const link = try std.fmt.bufPrintSentinel(&link_buf, "{s}/proc/1102/fd/3", .{rig.home}, 0);
const target = try std.fmt.bufPrint(&target_buf, "{s}/{s}", .{ rig.home, rollout });
try Io.Dir.cwd().symLink(testing.io, target, link, .{});
@@ -2759,7 +2757,7 @@ test "chat: a fifo where the transcript should be never blocks the daemon" {
const tr = try claudeTranscript(&rig, &rel);
try rig.del(tr);
var abs: [std.fs.max_path_bytes]u8 = undefined;
- const path = try std.fmt.bufPrintZ(&abs, "{s}/{s}", .{ rig.home, tr });
+ const path = try std.fmt.bufPrintSentinel(&abs, "{s}/{s}", .{ rig.home, tr }, 0);
try testing.expectEqual(linux.E.SUCCESS, linux.errno(linux.mknodat(linux.AT.FDCWD, path, linux.S.IFIFO | 0o600, 0)));
for ([_][]const u8{ "title", "model", "transcript", "chat" }) |name| {
const f = rig.lookupName(1, entry, name);