From d79c5de9dbf77c06fb2174782093051786be2153 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sun, 1 Nov 2026 15:50:00 -0300 Subject: fs: /sessions, the pardes daemon's registry in every session's tree, as pardes --ps lists it and a record a line, as the daemon says it (daemon ; session tty|gui attached|detached , a shell line for each shell it holds; orphan ): a snapshot frozen at the open as /listeners is, its read the daemon's `list` asked out of the turn as a tape site (`sessions`), so a replica reads the authority's answer; none in a build with no daemon (web, esp32), and `no pardes daemon answers` with none running or one too old to list; README, the reference and Scripting's ls say it; test/daemon.py --manage reads it beside --ps Co-Authored-By: Claude Opus 5.5 --- docs/typ/reference.typ | 11 +++++++++-- docs/typ/scripting.typ | 2 +- src/fs-help.txt | 1 + src/ninep/tree.zig | 43 +++++++++++++++++++++++++++++++++---------- src/tape.zig | 2 ++ test/daemon.py | 8 ++++++++ 6 files changed, 54 insertions(+), 13 deletions(-) diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ index 4de57d64..e60964cc 100644 --- a/docs/typ/reference.typ +++ b/docs/typ/reference.typ @@ -26,6 +26,7 @@ pager write a directory: a new +Pager there; read: its serial @pardes log the event log; write follow to wait for more @log screen the rendered screen as JSON @on-screen listeners dial addresses @other-files +sessions the pardes daemon's sessions and shells (pardes --ps) @other-files focus the serial of the pane with the keyboard; write one to move it @columns-and-tags ctl settings and session builtins @root-ctl commands every builtin, one a line @other-files @@ -157,7 +158,7 @@ other clients about, write and read on one open: #cmd("exec 3<>$m/pane/$n/look; echo x >&3; cat <&3; exec 3<&-") *Snapshots.* #file("/index"), #file("/layout"), #file("/recent"), -#file("/commands"), #file("/status"), #file("/listeners"), a read-only +#file("/commands"), #file("/status"), #file("/listeners"), #file("/sessions"), a read-only #file("ctl"), #file("/log"), #file("/screen") and a terminal's #file("body") freeze at the open, so one read in several chunks never splices two moments; open again for now. @@ -188,7 +189,7 @@ the range and flag files, the workspace's #file("tag"), the root #file("look")/#file("exec") answers, #file("focus"); #file("event") and #file("pty/data") the next record's, zero when none waits. A stream and a view generated by each read stat 0, as acme's do: #file("log"), #file("screen"), #file("data"), #file("xdata"), #file("index"), -#file("layout"), #file("recent"), #file("listeners"), #file("pane/new"). +#file("layout"), #file("recent"), #file("listeners"), #file("sessions"), #file("pane/new"). Read those to the end rather than trust a length (`cat` does). The qid version of #file("body"), #file("data") and #file("xdata") is the pane's revision, so a stat sees an edit land. Modes are 0644/0666, 0444 @@ -930,6 +931,12 @@ at 200, ending in `…`. Control characters become spaces. `+Pager` of the session's. - #file("/listeners"): the session's dial addresses, a line each (#doc("building", section: "listeners")). +- #file("/sessions"): what the pardes daemon keeps, as `pardes --ps` + shows it, a record a line: `daemon `, then `session tty|gui + attached|detached ` with a `shell ` line for each shell it + holds, then `orphan ` for each shell no session holds. Any of the + names attaches (`pardes --attach=`, either kind). Read fails `no + pardes daemon answers` with none, or one too old to list (Upgrade it). - #file("/os/"): existing regular files take read, write and truncation to zero; create, remove, rename and mode changes are refused as not permitted (`permission denied`, EACCES through a mount); ownership is diff --git a/docs/typ/scripting.typ b/docs/typ/scripting.typ index 590d71ac..d90f68ac 100644 --- a/docs/typ/scripting.typ +++ b/docs/typ/scripting.typ @@ -10,7 +10,7 @@ files is an extension: ``` $ ls $m README col commands ctl exec focus index layout listeners log -look os pager pane recent screen status tag tagexec +look os pager pane recent screen sessions status tag tagexec $ cat $m/index 1 term 0 /home/me/src 1 2 text 0 /home/me/src/+New 1 diff --git a/src/fs-help.txt b/src/fs-help.txt index 40dd05c5..ee63dd0e 100644 --- a/src/fs-help.txt +++ b/src/fs-help.txt @@ -9,6 +9,7 @@ pager write a directory: its one +Pager, made or emptied; read the same op log events: new del rename save newcol delcol run exit send ask answer changed dump restore restored restoredcol msg err screen the rendered screen as JSON, frozen from open to close listeners the session's dial addresses +sessions the pardes daemon's, as pardes --ps: daemon ; session tty|gui attached|detached ; shell ; orphan focus the serial of the pane with the keyboard (empty on a column tag); write one to give it the keyboard ctl settings a line; or Newcol, Dump, Restore [f], Exit (refuses once over unsaved panes), Kill [w], size C R commands every builtin: word, arg, root|pane|both (the ctl that takes it), -- what it does diff --git a/src/ninep/tree.zig b/src/ninep/tree.zig index bd87f5bc..c3eb3636 100644 --- a/src/ninep/tree.zig +++ b/src/ninep/tree.zig @@ -4,7 +4,7 @@ //! extended here with the editor's reply payload; fs.zig keeps host access //! and mounts. //! -//! /README /index /status /look /exec /log /screen /listeners +//! /README /index /status /look /exec /log /screen /listeners /sessions //! /pane/new an open makes a pane, a read names it //! /pane/ rmdir closes that pane //! /pane//{name,body,tag,ctl,addr,dot,limit,data,xdata,sel, @@ -23,6 +23,7 @@ const layout = pardes.layout; pub const pty = @import("pty.zig"); pub const sources = @import("sources.zig"); pub const screen = @import("screen.zig"); +const daemon = @import("../daemon.zig"); const Pardes = pardes.Pardes; const Pane = pardes.Pane; @@ -261,6 +262,10 @@ pub const TopFile = enum(u5) { /// `pardes -`'s: a directory written, a new +Pager made there; a /// read of the same open answers its serial. pager, + /// The pardes daemon's sessions and shells, as `pardes --ps` lists + /// them: `daemon `, `session tty|gui attached|detached + /// `, `shell ` (the session above's), `orphan `. + sessions, pub fn fileName(f: TopFile) []const u8 { return if (f == .root) "/" else @tagName(f); @@ -270,7 +275,7 @@ pub const TopFile = enum(u5) { return switch (f) { .root, .pane, .col => 0o755, .look, .exec, .log, .focus, .ctl, .tag, .tagexec, .pager => 0o666, - .README, .index, .status, .screen, .listeners, .new, .commands, .layout, .recent => 0o444, + .README, .index, .status, .screen, .listeners, .new, .commands, .layout, .recent, .sessions => 0o444, }; } @@ -463,6 +468,13 @@ pub fn stageDirent(out: *std.ArrayList(u8), gpa: std.mem.Allocator, node: u64, d } /// Answers a read from whatever the handler staged, windowed by offset and size. +/// The daemon's registry (/sessions), its `list` answer as it gave it. +fn daemonList(gpa: std.mem.Allocator) anyerror![]u8 { + var buf: [4096]u8 = undefined; + const said = daemon.ask("list", &buf) orelse return error.NoDaemon; + return gpa.dupe(u8, said); +} + pub fn stagedReply(p: *Pardes, req: Req) Reply { const out = &p.fs.out; const off = @min(req.off, out.items.len); @@ -669,7 +681,7 @@ fn topSize(p: *Pardes, f: TopFile) u64 { // frame, /pane/new until an open has a pane to name, and the index, // layout, recent list and listeners, which a stat would otherwise // have to build to count. - .root, .pane, .col, .screen, .new, .layout, .index, .recent, .listeners => 0, + .root, .pane, .col, .screen, .new, .layout, .index, .recent, .listeners, .sessions => 0, .tag => cols.headerText(p, null).?.len, .README => fs.help.len, .status => ctl.statusLen(p), @@ -777,7 +789,7 @@ fn readdir(p: *Pardes, req: Req, target: Target) Reply { .root => { // The guide, then what describes the session, then the // files that act, then the directories. - inline for (.{ TopFile.README, TopFile.index, TopFile.status, TopFile.focus, TopFile.ctl, TopFile.commands, TopFile.recent, TopFile.look, TopFile.exec, TopFile.pager, TopFile.log, TopFile.screen, TopFile.listeners, TopFile.layout, TopFile.tag, TopFile.tagexec, TopFile.pane, TopFile.col }) |t| { + inline for (.{ TopFile.README, TopFile.index, TopFile.status, TopFile.focus, TopFile.ctl, TopFile.commands, TopFile.recent, TopFile.look, TopFile.exec, TopFile.pager, TopFile.log, TopFile.screen, TopFile.listeners, TopFile.sessions, TopFile.layout, TopFile.tag, TopFile.tagexec, TopFile.pane, TopFile.col }) |t| { if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, @backingInt(t), t.dir(), t.fileName()); } if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, fs.os_root, true, "os"); @@ -856,7 +868,7 @@ fn open(p: *Pardes, req: Req, target: Target) Reply { }, .screen => .{ .snapshot = null }, .log => .{ .log = .{} }, - .index, .layout, .recent, .commands, .status, .listeners => .{ .frozen = &.{} }, + .index, .layout, .recent, .commands, .status, .listeners, .sessions => .{ .frozen = &.{} }, // The root's ctl opened only to read: its settings, frozen. .ctl => if (linesOpen(target, req)) .lines else .{ .frozen = &.{} }, else => if (linesOpen(target, req)) .lines else return .{ .tag = req.tag }, @@ -1106,6 +1118,17 @@ fn readFile(p: *Pardes, req: Req, target: Target) Reply { .log => events.readLog(p, req), .screen => screen.readSnapshot(p, req, null), .listeners => screen.readListeners(p, req), + .sessions => sessions: { + if (comptime !(pardes.hosted and daemon.supported)) break :sessions stagedReply(p, req); + // Out of the turn: the daemon answers within 2 s, or not at all. + const said = pardes.tape.site(.sessions, p.gpa, daemonList, .{p.gpa}) catch |err| break :sessions switch (err) { + error.OutOfMemory => Reply.fail(req.tag, E.NOMEM), + else => failText(req.tag, E.NOENT, "no pardes daemon answers"), + }; + defer p.gpa.free(said); + p.fs.stage(p.gpa).appendSlice(p.gpa, said) catch break :sessions Reply.fail(req.tag, E.NOMEM); + break :sessions stagedReply(p, req); + }, .focus => ctl.readFocus(p, req), .ctl => ctl.readRoot(p, req), .commands => ctl.readCommands(p, req), @@ -1534,13 +1557,13 @@ test "readdir lists the root and a pane directory without creating anything" { @memcpy(top_bytes[0..top_reply.bytes.len], top_reply.bytes); const top = th.dirents(top_bytes[0..top_reply.bytes.len], &buf); try testing.expect(top.len >= 10); - for ([_][]const u8{ "README", "index", "status", "focus", "ctl", "commands", "recent", "look", "exec", "pager", "log", "screen", "listeners", "layout", "tag", "tagexec", "pane", "col", "os" }, 0..) |name, i| { + for ([_][]const u8{ "README", "index", "status", "focus", "ctl", "commands", "recent", "look", "exec", "pager", "log", "screen", "listeners", "sessions", "layout", "tag", "tagexec", "pane", "col", "os" }, 0..) |name, i| { try testing.expectEqualStrings(name, top[i].name); - try testing.expectEqual(i >= 16, top[i].dir); + try testing.expectEqual(i >= 17, top[i].dir); } - try testing.expectEqual(@backingInt(TopFile.pane), top[16].node); - try testing.expectEqual(@backingInt(TopFile.col), top[17].node); - try testing.expectEqual(fs.os_root, top[18].node); + try testing.expectEqual(@backingInt(TopFile.pane), top[17].node); + try testing.expectEqual(@backingInt(TopFile.col), top[18].node); + try testing.expectEqual(fs.os_root, top[19].node); var idbuf: [16]u8 = undefined; try testing.expect(th.nameAt(top, try std.fmt.bufPrint(&idbuf, "{d}", .{serial})) == null); try testing.expect(th.nameAt(top, "self") == null); diff --git a/src/tape.zig b/src/tape.zig index 74576eed..c0f33f21 100644 --- a/src/tape.zig +++ b/src/tape.zig @@ -98,6 +98,8 @@ pub const Site = enum(u16) { preview, /// A search run on the loop (Stream.runHere: a 9P write's Grep or Find). search, + /// The daemon's registry, as /sessions reads it (daemon.ask "list"). + sessions, // Read in place (`value`). clock, budget, diff --git a/test/daemon.py b/test/daemon.py index 2c2ee318..954433a9 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -537,6 +537,14 @@ def manage(binary): for name in ('one', 'two'): assert f'session {name} {sessions[name]} (tty, detached)' in listed, listed assert f'shell {shells[name]}' in listed, listed + # The same, a record a line, in each session's /sessions. + with Client(root / 'pardes-9p-one.sock') as c: + records = c.read('/sessions').decode().splitlines() + assert records[0] == f'daemon {daemon}', records + for name in ('one', 'two'): + at = records.index(f'session {sessions[name]} tty detached {name}') + assert records[at + 1] == f'shell {shells[name]}', records + print('manage: /sessions read over 9P listed the daemon, both sessions and their shells') os.kill(sessions['two'], signal.SIGKILL) wait_for('session two gone', lambda: not alive(sessions['two'])) wait_for('its shell no session\'s', lambda: 'no session holds' in cli('--ps').stdout.decode()) -- cgit v1.3