summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-01 15:50:00 -0300
committerGabriel Schneider <[email protected]>2026-11-01 15:57:25 -0300
commitd79c5de9dbf77c06fb2174782093051786be2153 (patch)
tree8887d7e6dfea6023b9c7a05124eab56037198868 /src
parent15bd47670102ceae36565ee299fd8a40625c3b21 (diff)
downloadpardes-d79c5de9dbf77c06fb2174782093051786be2153.tar.gz
pardes-d79c5de9dbf77c06fb2174782093051786be2153.zip
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 <pid>; session <pid> tty|gui attached|detached <name>, a shell <pid> line for each shell it holds; orphan <pid>): 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 <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/fs-help.txt1
-rw-r--r--src/ninep/tree.zig43
-rw-r--r--src/tape.zig2
3 files changed, 36 insertions, 10 deletions
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 <pid>; session <pid> tty|gui attached|detached <name>; shell <pid>; orphan <pid>
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/<serial> rmdir closes that pane
//! /pane/<serial>/{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 <pid>`, `session <pid> tty|gui attached|detached
+ /// <name>`, `shell <pid>` (the session above's), `orphan <pid>`.
+ 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,