From 4bcf2055cb97d0c69fc94643b3e43b579d6fa30c Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 20 Nov 2026 00:51:28 -0300 Subject: term: a kitty image's medium (a file, a temporary file, shared memory) is the session's read and a recorded answer on the tape, so every replica's emulator is handed the bytes the session read, or its failure, and never reads its own machine: ghostty's loader gets the bytes through `LoadingImage.read_medium` (an Edit in build/patches.zig, ghostty's own read handed to it, the report in docs/ghostty-kitty-medium.md), which the terminal module sets to the core's `Term.media`, a `tape.valueIn(.medium, ...)` site (a new Site; `valueIn` is `value` with the answer's slices in the loader's allocator, no yield inside a feed), so a read crosses to a client as a file read does (inline under 1 MiB, by hash at or over it), a temporary file is deleted and shared memory unlinked once, on the session, and the program is answered by the session alone; a replica no longer loads by direct data only: `Term.direct`, `State.direct` and the `direct` entry go (`media` in their place); under screen state the read stays the authority's (a screen-state replica feeds no emulator); FIRST the test through the replica's surface (a session and a bytes replica, four images shown, by a file, a temporary file, shared memory and a missing file): on the base the digests parted (expected 8810391091473565423, found 2236913079067993401: the replica's loader said "unsupported medium" and did not move its cursor), now they agree, the terminals dump the same bytes, the temporary file and the object are gone and the replica read nothing (ghostty's FileNotFound warned once); tui term-test 17/17, kitty-test 45/45, core-test 856/1007 (151 skipped), shell-test 1043/1046, unit-test -Dtest-filter=bytes: 23/23 (the perf check's BaselineHarnessMismatch, as on the base) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- docs/ghostty-kitty-medium.md | 57 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 docs/ghostty-kitty-medium.md (limited to 'docs') diff --git a/docs/ghostty-kitty-medium.md b/docs/ghostty-kitty-medium.md new file mode 100644 index 00000000..c990ea6d --- /dev/null +++ b/docs/ghostty-kitty-medium.md @@ -0,0 +1,57 @@ +# ghostty: a host cannot be the one that reads a kitty image's medium + +A note for upstream (https://github.com/ghostty-org/ghostty), against the +commit pardes pins (83fb95624b04, 1.4.0, `build.zig.zon`). pardes patches +its fetched copy at build time (build/patches.zig, `ghostty_kitty`, and +build/patches/ghostty_kitty.zig) until upstream has a way, if it wants one. + +## What a host cannot do + +A kitty graphics transmission by file (`t=f`), temporary file (`t=t`) or +shared memory (`t=s`) is read inside `LoadingImage.init` +(`src/terminal/kitty/graphics_image.zig`): `readFile` opens, checks and +reads the path, and deletes a temporary file; `readSharedMemory` opens, +maps, copies and unlinks the object. A host of libghostty-vt can allow or +refuse each medium (`LoadingImage.Limits`), and nothing else: it cannot +be the one that has the bytes. + +pardes needs to. A session's terminal is parsed by its own emulator and, +the same bytes in the same order, by the emulator of every client of the +session, each on its own machine. A file or a shared memory object names +something on the session's machine, and a temporary file or an object is +gone once its first reader has read it. So a client must not read the +medium: it must be handed the bytes the session read, or the failure the +session met, and the program must be answered once, by the session. If a +client refuses the medium instead, a shown image (`a=T`) moves the +session's cursor past it and not the client's, and the two terminals part. + +## The patch + +`LoadingImage.read_medium`, a hook a host may set (null: ghostty's read +as it is). When set, `init` hands it ghostty's own read as a function and +a context, and the allocator the bytes are to be in; what it returns +becomes the image's data: + +```zig +pub var read_medium: ?*const fn (ctx: *const anyopaque, read: *const fn (ctx: *const anyopaque) MediumError![]u8, alloc: Allocator) MediumError![]u8 = null; +``` + +The read itself is ghostty's, unchanged (`readFile`, `readSharedMemory`, +their checks, the deletion and the unlink), behind a small struct appended +to the file (`PardesMedium.read`). pardes's hook calls it on the session +and records what it returned; a client's hook returns the recorded bytes +(or error) without calling it. Everything before the read (the limits, +the PNG check, the path's NUL check) and after it (decompression, +decoding, the size checks of `complete`, the answer) runs on every side +alike. + +## Why not rewrite the transmission instead + +The other way is to turn `t=f`, `t=t` and `t=s` into direct data before +the emulator sees it. That parses the APC outside ghostty, repeats its +rules (the temporary directory and the name a temporary file must have, +the `/proc`, `/sys` and device refusals, the shared memory range by +format, offset and size, `S` meaning an exact length), and re-encodes the +bytes as base64 a third larger, chunked to the protocol's limits. It also +changes what the emulator sees, so its answer to the program has to be +checked to match. The hook keeps all of that in ghostty. -- cgit v1.3 From a6c258bec5808ac2b6ef9d3362134e34e759c1c9 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 20 Nov 2026 03:20:39 -0300 Subject: docs: an attach is always a client, and a session registers again with a restarted daemon, in the documents: the manual's "How pardes runs" (docs/typ/running.typ: one Attach section, its figure of the in-place attach deleted from figures.typ, the glance and survival tables, the words), the guide's Sessions, the reference's /sessions and command line, the building chapter's daemon, the cheatsheet's line, `pardes help attach` (runtime/main.zig, docs/typ/command-line.txt from builtins-json), the Detach word's doc (core/builtins.zig, both builtins JSONs), docs/next-run.md as built (what went, counted on the change: 305 lines deleted, 94 added; the re-registration as built; --detach forking still not) with its figure (Before / Now), and the changelog's Unreleased; the book and the cheatsheet render (typst), tui shell-test 1046/1049 (3 skipped), core-test 855/1005 (150 skipped: the base's 856/1006 less the deleted `find` test) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/CHANGELOG.md | 20 ++++++ core/builtins.zig | 2 +- docs/next-run.md | 157 +++++++++++++++++++++++++-------------------- docs/next-run.svg | 2 +- docs/next-run.typ | 4 +- docs/typ/building.typ | 17 +++-- docs/typ/builtins-gui.json | 2 +- docs/typ/builtins-tui.json | 2 +- docs/typ/cheatsheet.typ | 2 +- docs/typ/command-line.txt | 21 +++--- docs/typ/figures.typ | 46 +++---------- docs/typ/guide.typ | 27 ++++---- docs/typ/reference.typ | 18 +++--- docs/typ/running.typ | 148 ++++++++++++++++++++---------------------- runtime/main.zig | 21 +++--- 15 files changed, 247 insertions(+), 242 deletions(-) (limited to 'docs') diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 9b551e9b..fe9adec8 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -2,6 +2,26 @@ ## Unreleased +- `pardes attach NAME` (and `pardes-gui attach NAME`) is always a client: + a process of its own with its own view, whatever the session was + started in. A session's own terminal or window is only the one it was + born with: once a Detach or its terminal let it go, it never takes one + back. Before, an attach to a detached terminal's session handed it this + terminal (the attach waiting as its stub), and `pardes-gui attach` asked + a detached window's session to open its own window again and exited 0. + A client's Detach ends it with "'NAME' let this client go" and exit 1, + where the stub said "detached from 'NAME'" and exited 0. Bare, `pardes + attach` takes the one detached session, else the one session, of either + kind; with several it names them all. + +- A session whose daemon was killed starts the next one itself and + registers with it again, its shells' terminals and its clients with it: + `pardes ps` lists it, an attach and Adopt find it, and Detach works. It + ran on unlisted for good before, and its terminal closing ended it. + +- The words `pardes` says at a Detach name `pardes attach NAME`, the + command's spelling now, not `--attach=NAME`. + - On a client, and so on a far one, what changes only the editor is applied at once and only what touches the session's machine waits for it (a save, a shell's keys, a file read from disk, a program run, a diff --git a/core/builtins.zig b/core/builtins.zig index 1a0b4ce7..2740e05a 100644 --- a/core/builtins.zig +++ b/core/builtins.zig @@ -532,7 +532,7 @@ pub const Restore = struct { }; /// Detach this pardes from its terminal or window, leaving the session -/// running: `pardes --attach` (or `pardes-gui --attach`) takes it back. +/// running: `pardes attach` (or `pardes-gui attach`) shows it as a client. pub const Detach = struct { pub const scope: Scope = .session; pub const enabled = pardes.can_attach; diff --git a/docs/next-run.md b/docs/next-run.md index 06941026..74eab197 100644 --- a/docs/next-run.md +++ b/docs/next-run.md @@ -1,4 +1,4 @@ -# Running pardes: an attach is always a client (ruled, not built) +# Running pardes: an attach is always a client (ruled; built 2026-11-20, all but `--detach` forking) > the way it's distributed with client/server and detached and stuff, it's > confusing to me now and I think it must be confusing in the code too, @@ -7,69 +7,84 @@ Ruled by the user on 2026-11-17, answering the reorganisation plan's questions: the words of distribution (*session*, *client*, *far*, *frontend*, *detached*, *attach*); "attach is always a client"; the daemon -stays as built; the vocabulary and the manual's page first, no code moved -yet. Nothing in this note is built. What runs today, with a figure for each -way of starting pardes, is the manual's "How pardes runs" +stays as built; the vocabulary and the manual's page first, the code +after. Built on 2026-11-20 (agent pardes-attach, report +`.scratch/sketch/reports/pardes-attach.md`): an attach is always a client, +the in-place attach deleted, and a session registering again with a +restarted daemon. Not built: `--detach` forking (below). What runs, with a +figure for each way of starting pardes, is the manual's "How pardes runs" (`docs/typ/running.typ`); the daemon's history is `docs/next-daemon.md`. -Line numbers are this tree's, 2026-11-19. ## The ruling A session's own frontend is only the one it was born with. Once it has let that go (a Detach, its terminal or window closing), it stays detached, and every attach after that is a client: a process of its own with a -replica core, as the second attach to a session is today. +replica core, as the second attach to a session already was. Two more things go with it (the coordinator's, put to the user with the question): - a session registers again with a daemon that was restarted, so a daemon's - death no longer leaves its sessions unlisted for good; + death no longer leaves its sessions unlisted for good (built); - `--detach` forks as a terminal's session does, so the process you typed - returns at once and `ps` always shows a session the same way. + returns at once and `ps` always shows a session the same way (not + built). -## Today, and after +## Before, and now -![What `pardes attach` does today, and after](next-run.svg) +![What `pardes attach` did before, and does now](next-run.svg) The figure is `docs/next-run.typ`, drawn by `docs/typ/figures.typ` (`typst compile --root . --ignore-system-fonts -f svg docs/next-run.typ docs/next-run.svg`). -Today `pardes attach` is four mechanisms, picked by the daemon's `find` -(`runtime/daemon.zig:901-972`) and by `main.zig`'s `attachTo` -(`runtime/main.zig:1806-1842`): a terminal handed to a detached terminal's -session, which draws on it in its own process while the attach process -waits as its stub; a window's detached session asked to open its own -window again, while the attach process exits; a client here, when the -session has a frontend or is of the other kind; a far client through -`ssh -L`. After, it is the last two only: a client, here or far. - -## What it removes - -The reorganisation plan's option b, checked against this tree: - -| What goes | Where today | Lines, about | +Before, `pardes attach` was four mechanisms, picked by the daemon's `find` +and by `main.zig`'s `attachTo`: a terminal handed to a detached terminal's +session, which drew on it in its own process while the attach process +waited as its stub; a window's detached session asked to open its own +window again, while the attach process exited; a client here, when the +session had a frontend or was of the other kind; a far client through +`ssh -L`. Now it is the last two only: a client, here or far. +`runtime/main.zig`'s `attachTo` goes to this machine's replica socket with +the name (the daemon refuses one no session has); bare, `bareAttach` takes +the one detached session from the daemon's `list`, else the one session, +else names them and asks which. + +What a user who relied on the in-place attach does now: `pardes attach +work` (or `pardes-gui attach work`) is a client of the detached session, +its own process in this terminal or window. What differs from having the +session's own frontend back: the client is a second process (a terminal's +10-16 MB, a window's about 110 MB); an addon that is not plain runs in the +session alone (its panes show a line saying so); its Detach, or its +terminal closing, ends the client with "'work' let this client go" and exit +1, where the stub said "detached from 'work'" and exit 0 (the last word a +session sends its client, and exit codes, are the next steps: "B" in +`.scratch/sketch/reports/pardes-last-step-design.md`). + +## What it removed + +Counted on the change itself (deleted lines, comments with them; a +function's added replacement in brackets): + +| What went | Where | Lines | |---|---|---| -| A terminal handed to a session: the daemon's `attach` request and answer, the session's `attachTerminal`, the `attach` note and message | `runtime/daemon.zig:400-403`, `:431-437`, `:504-533`, `:883-897`; `dev/tui/tui.zig:107-109`, `:1037-1040`, `:1135-1140`, `:1354-1387`, `:1711`; `runtime/main.zig:1821-1842` | 110 | -| A window opened again in place | `dev/gui/gui.zig:550-557` (what it reopens with), `:1004-1022` (`reopenWindow`), `:2588-2601` (`openTheWindow`), `:2823`, `:3388-3394` | 50 | -| The daemon choosing which session takes a frontend: `find`, its `other` answer, the use of `daemon.Kind` to match | `runtime/daemon.zig:901-972`, `:506-509` | 75 | -| The stub's second use: an attach process waiting on a session that is not its child (`stubWait`'s `child = false`, its `r` refusals) | `runtime/daemon.zig:561-616` in part (`:593-597`, `:613-615`) | 10 | - -What does not go, against the plan's list: the upgrade record's terminal -and window fields. A session born with a terminal still takes it across an -Upgrade (`dev/tui/tui.zig:1438-1446`, `runtime/upgrade.zig:101-117`), and a window's still -says whether it had its window (`dev/gui/gui.zig:2656`). Only the record's other -terminals (`dev/tui/tui.zig:1487-1506`, a build's from before 2026-11-06, when a -second local terminal stopped being the session's) are already dead weight. -Detach of the session's own frontend stays too (`dev/tui/tui.zig:1327-1352`, -`dev/gui/gui.zig:2530-2539`, `:2575-2586`): it is how a session becomes detached. -`daemon.Kind` stays in the hello and in `pardes ps` (`tty` or `gui`). - -The plan counted 87 + about 60 + 67 lines for the first three rows; the -counts above include each piece's comments and its callers' lines. - -## What a client lacks today, which the change makes work +| The daemon choosing which session takes a frontend: `find`, its `other` answer, the `attach` verb and its test | `runtime/daemon.zig` `Daemon.find`, `Daemon.take` | 99 | +| The attach request: `daemon.attach`, `Answer`, `Note.attach` and the reader's arm | `runtime/daemon.zig` | 36 | +| The stub's second use: `stubWait`'s `child` and its `r` and `x` words, `tellStubExit` | `runtime/daemon.zig`, `runtime/main.zig` | 37 | +| `attachTo`'s two hand-offs and `crossAttach` | `runtime/main.zig` | 41 (+16: `attachTo`; +33: `bareAttach` and its test, what `find` chose, done here) | +| A terminal handed to a session: `attachTerminal`, `refuse`, the `.attach` message and its three arms | `dev/tui/tui.zig` | 52 | +| A window opened again in place: `openTheWindow`, `Shell.detached`, the queue's `.window` and its arms | `dev/gui/gui.zig`, `dev/Inbox.zig`, `runtime/macos.zig` | 34 | +| `setState(false)`, which nothing says now | `runtime/daemon.zig` (`setDetached`) | 2 | +| **in all** | | **305 deleted, 94 added** | + +What did not go: the upgrade record's terminal and window fields (a +session born with a terminal still takes it across an Upgrade); Detach of +the session's own frontend (it is how a session becomes detached); +`reopenWindow`, which a WindowOpacity under 100 makes a window again with; +`daemon.Kind` in the hello and in `pardes ps` (`tty` or `gui`). + +## What a client lacked, which the change made work The ruling turns these from objections into work. Each is checked here: what is true, and whether it was measured. @@ -86,7 +101,7 @@ what is true, and whether it was measured. terminal's client and is four or five times too small for a window's; what would shed it is a lighter way to draw, not a lighter core. A client adds about 1.3 MB to its session (a terminal's), 13 MB (a - window's with addon panes). Today only a second attach pays it; after, every attach to a detached + window's with addon panes). Before, only a second attach paid it; now every attach to a detached session does, which is the tmux habit (`pardes --detach=work`, then `pardes attach work`). - **An addon's code does not run in a replica.** No longer so for an @@ -121,23 +136,31 @@ what is true, and whether it was measured. Not measured here: a keystroke to its frame, local client against own frontend, on the soak gate. -## A session registering again - -Today a session says hello once, at its start (`runtime/main.zig:1567-1595`), or -on its link after an Upgrade (`runtime/daemon.zig:392-398`). When the daemon dies -the session's reader sees the link end (`runtime/daemon.zig:419-425`) and nothing -dials again, so the session runs on unlisted: `pardes ps` and attach do not -find it, Detach and Adopt refuse, and its frontend closing ends it -(`dev/tui/tui.zig:1699-1709`, `dev/gui/gui.zig:1839`). The next daemon knows only the -sessions that start after it. - -The work: when `gone` is set, the session's loop (which calls -`daemon.watch` each iteration already, `runtime/session.zig:115`, `:133-135`) -dials again, starting a daemon if none answers (`daemon.connect(true)`), -says its hello with its state, sends a dup of every pty master it holds -(at most 64 fds a message, `runtime/daemon.zig:37`), and its clients' pids. What -cannot come back: the shells of sessions killed earlier, which only the -dead daemon held. +## A session registering again (built) + +Before, a session said hello once, at its start, or on its link after an +Upgrade; when the daemon died the session's reader saw the link end and +nothing dialled again, so the session ran on unlisted: `pardes ps` and +attach did not find it, Detach and Adopt refused, and its frontend closing +ended it. With "an attach is always a client" that would have meant no +attach to any session after a daemon's death. + +Now (`runtime/daemon.zig` `readNotes`, `redial`, `relinked`; +`runtime/session.zig` `watch`; `dev/Ptys.zig` `tellDaemon`): the reader +thread, blocked in its read, is woken by the link's end alone. If the +daemon had taken the hello (an `ok` came) and the session is not ending, +it dials the next daemon, starting one if none answers +(`daemon.connect(true)`: the lock decides which of several sessions starts +it), puts the new connection on the link's own fd (`dup3`, so the session +loop's own sends never race a new fd) and says the hello with its kind, +name and whether it is detached. It then posts a note that wakes the +session loop once, which tells the new daemon a dup of every pty master it +holds and its clients' pids. Nothing polls and nothing waits on a timer: an +idle session is at 0 wakeups before and after (`test/daemon.py --relink`, +2 s each). A link the daemon never took (another build's daemon refuses +the hello) is not dialled again, so two builds cannot loop. What cannot +come back: the shells of sessions killed earlier, which only the dead +daemon held. ## `--detach` forking @@ -166,10 +189,10 @@ binary's strings (`/usr/sbin/rex` links libghostty); Rex was not run. | Who holds the programs | one server an account holds every session and runs every program (`skill-show.txt`) | each session is its own process, with the truth; the daemon holds a dup of each pty master and a list | | What starts it | any command starts a missing server (`--autostart`) | the first session starts the daemon; what you start is the session | | A client | "one program connected to the server" (`help-client.txt`); not a thin view: it replays the server's stream into its own libghostty and draws locally (the binary links libghostty; the help text does not say so, and this row first called it a view of the server's state: the user's correction, 2026-11-17) | the same principle, the stream shipped and the state derived where it is shown, into a whole replica core with its own view; what pardes adds is a client applying its own input before the session confirms it (speculation, rolled back when the session ordered things otherwise) and a predicted echo | -| Attach | no user's verb; in the API "start receiving its events and get its current view" | today four mechanisms; after this note, one: a client | +| Attach | no user's verb; in the API "start receiving its events and get its current view" | one: a client (four mechanisms until 2026-11-20) | | The last client leaves | "the session keeps running" (`api-session.detach.txt`) | the same for a client; today a session's own frontend closing depends on its kind and the daemon | | Another machine | the same commands with `-S HOST` | `attach HOST:NAME`; a far session's 9P is not reached that way | -| The server or daemon dies | "Stopping the server ends every program" (`help-server-stop.txt`) | a killed daemon ends nothing; today its sessions run on unlisted | +| The server or daemon dies | "Stopping the server ends every program" (`help-server-stop.txt`) | a killed daemon ends nothing; its sessions start the next and register with it again | What pardes bought that Rex does not have: a deterministic core replicated in each client, so a far session feels local (a key is applied @@ -182,8 +205,6 @@ session takes back. ## Open questions -- Re-registration: dial again at once and back off, or only when - something needs the daemon (a Detach, an Adopt, the frontend closing)? - `--detach` with no daemon starts a session nothing can attach to (`runtime/main.zig:1567-1569` ignores the failed registration). Refuse, or keep it as a 9P-only session? @@ -191,6 +212,6 @@ session takes back. own (the daemon's list, and so /sessions, still says `attached`, a wire word). After the change that frontend can only be the first one: is "has a frontend" the word, or "with its first frontend"? -- When: the order the user ruled is this vocabulary and the page first, - and the code after sketchbook's steps land (`.scratch/sketch/PARDES.md`, - ruling 4). +- A client's Detach exits 1 with "let this client go", where the stub's + said "detached from" and exited 0: the session's last word to a client + (step B of the last-step design) would let it say which. diff --git a/docs/next-run.svg b/docs/next-run.svg index fdfc705a..b46d94fa 100644 --- a/docs/next-run.svg +++ b/docs/next-run.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/docs/next-run.typ b/docs/next-run.typ index 91461b25..5d972f0e 100644 --- a/docs/next-run.typ +++ b/docs/next-run.typ @@ -1,5 +1,5 @@ -// The figure of docs/next-run.md: what `pardes attach` does today beside -// what it does once "an attach is always a client" is built. Drawn by +// The figure of docs/next-run.md: what `pardes attach` did before beside +// what it does since "an attach is always a client" was built. Drawn by // docs/typ/figures.typ, the one file of the docs that imports cetz. // typst compile --root . --ignore-system-fonts -f svg docs/next-run.typ docs/next-run.svg #import "typ/style.typ": palette diff --git a/docs/typ/building.typ b/docs/typ/building.typ index 9350b484..8bfcb85b 100644 --- a/docs/typ/building.typ +++ b/docs/typ/building.typ @@ -501,10 +501,13 @@ life; the first session that finds none starts it (a double fork and an exec) and it exits a second after it holds nothing. It is nobody's parent: a session registers on one connection, sends it a dup of every pty master it forks (so a session killed outright never hangs its shells up, and -#word("Adopt") takes them into another), says whether a terminal or a -window shows it, and is handed a terminal (`pardes --attach`) or a window -request (`pardes-gui --attach`) through it. Messages are `SOCK_SEQPACKET` -datagrams: a line of words and the fds it carries. +#word("Adopt") takes them into another), says whether it has let its own +terminal or window go, and is handed each client's connection through it +(`pardes attach`, below). A daemon that dies is started again by the +sessions: each one's link's reader, woken by the link's end, dials the +next, says the hello again and tells it its masters and its clients. +Messages are `SOCK_SEQPACKET` datagrams: a line of words and the fds it +carries. `pardes` in a terminal forks its session off before anything starts: the session, in a session of its own (`setsid`), draws on the terminal it @@ -512,9 +515,9 @@ opened, and the process the shell waits on stays as its stub, passing it `SIGWINCH`, `SIGTERM`, `SIGINT` and `SIGQUIT` and ending with its status. #word("Detach"), or the terminal's end (EIO, a hangup), puts the terminal back and lets it go; the stub ends (exit 0) and the session -runs on with nothing drawn, until `pardes --attach` hands it another -terminal. A window's #word("Detach") closes the window and keeps the -process; `pardes-gui --attach` opens one again. `PARDES_DAEMON=off` (the +runs on with nothing drawn, detached for good: `pardes attach` is a client +of it. A window's #word("Detach") closes the window and keeps the +process, the same. `PARDES_DAEMON=off` (the process tests) runs a session as before the daemon: in the terminal's own process, ended by its hangup. diff --git a/docs/typ/builtins-gui.json b/docs/typ/builtins-gui.json index 732e66a7..34a46fa6 100644 --- a/docs/typ/builtins-gui.json +++ b/docs/typ/builtins-gui.json @@ -24,7 +24,7 @@ {"name": "DelAbove", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Close the pane, giving its rows to the pane above it."}, {"name": "DelBelow", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Close the pane, giving its rows to the pane below it."}, {"name": "Delcol", "leader": "SPC c d", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Close this column and its panes, refusing once over unsaved text."}, - {"name": "Detach", "leader": "SPC s D", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Detach this pardes from its terminal or window, leaving the session running: `pardes --attach` (or `pardes-gui --attach`) takes it back."}, + {"name": "Detach", "leader": "SPC s D", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Detach this pardes from its terminal or window, leaving the session running: `pardes attach` (or `pardes-gui attach`) shows it as a client."}, {"name": "Diagnostics", "leader": "SPC l d", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "List the file's diagnostics from the language server."}, {"name": "Diff", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Stack a diff's hunks as a diff viewer shows them, each under its place and the declarations around it, in a +Diff; on a +Diff, show the diff itself as text."}, {"name": "Down", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Move the keyboard to the pane below, off a tag onto the pane under it."}, diff --git a/docs/typ/builtins-tui.json b/docs/typ/builtins-tui.json index 0a074c44..5919a77a 100644 --- a/docs/typ/builtins-tui.json +++ b/docs/typ/builtins-tui.json @@ -23,7 +23,7 @@ {"name": "DelAbove", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Close the pane, giving its rows to the pane above it."}, {"name": "DelBelow", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Close the pane, giving its rows to the pane below it."}, {"name": "Delcol", "leader": "SPC c d", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Close this column and its panes, refusing once over unsaved text."}, - {"name": "Detach", "leader": "SPC s D", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Detach this pardes from its terminal or window, leaving the session running: `pardes --attach` (or `pardes-gui --attach`) takes it back."}, + {"name": "Detach", "leader": "SPC s D", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Detach this pardes from its terminal or window, leaving the session running: `pardes attach` (or `pardes-gui attach`) shows it as a client."}, {"name": "Diagnostics", "leader": "SPC l d", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "List the file's diagnostics from the language server."}, {"name": "Diff", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Stack a diff's hunks as a diff viewer shows them, each under its place and the declarations around it, in a +Diff; on a +Diff, show the diff itself as text."}, {"name": "Down", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Move the keyboard to the pane below, off a tag onto the pane under it."}, diff --git a/docs/typ/cheatsheet.typ b/docs/typ/cheatsheet.typ index e931effa..2df92b00 100644 --- a/docs/typ/cheatsheet.typ +++ b/docs/typ/cheatsheet.typ @@ -122,7 +122,7 @@ Helix-style: motions *select*, then an edit acts on the selection. Mode box: bla - A query pane under the pane: line 1 the query, its first word the source: `/pat`, `Find name` (fuzzy), `Grep text` (literal), `Recent`, `Panes`, `Symbols`, `All`. #keys("Ctrl-n", "Ctrl-p") step, #key("Enter") lands and keeps the rows, #key("Esc") puts things back. #word("Help"), #word("Tutor"). == Sessions -`pardes --detach=work`; `--attach=work` (`pardes-gui --attach=work`) takes it back; #word("Detach") leaves it running; #word("Adopt") takes in a killed session's shells. #doc("detached") +`pardes --detach=work`; `pardes attach work` shows it here, as a client (`pardes-gui attach work`: in a window); #word("Detach") leaves it running; #word("Adopt") takes in a killed session's shells. #doc("detached") == Config #word("Config") (#key("SPC f c")): `~/.config/pardes/init`, a builtin a line (#word("Theme") `atelier`). #word("DumpConfig"): every setting. #word("Dump") / #word("Restore"): the workspace. #doc("config") diff --git a/docs/typ/command-line.txt b/docs/typ/command-line.txt index 0b06275e..3c73fed4 100644 --- a/docs/typ/command-line.txt +++ b/docs/typ/command-line.txt @@ -12,7 +12,7 @@ Open: Sessions: ps the daemon's sessions, their clients and shells - attach [NAME] show a detached session here (HOST:NAME: over ssh) + attach [NAME] show a session here, as a client (HOST:NAME: over ssh) kill NAME end a session and its shells (--all: every one) new [flags] [FILE] start one: --detach=NAME --9p=NAME -n 3 (help new) @@ -54,15 +54,16 @@ See also: attach, kill, /sessions == pardes help attach -Show a detached session here: in this terminal for pardes, a window -for pardes-gui. Bare, the one detached session (with none, the one -session). One with a frontend already, or of the other kind, is joined -as a client. HOST:NAME is a client of session NAME on another machine, -over `ssh -L` to its pardes-replica.sock ($PARDES_SSH: the ssh -command, default ssh; $PARDES_REMOTE_RUNTIME: its runtime directory, -if not this one's path); SOCK:NAME goes through a socket forwarded -already (a path, with a '/'). Returns when the session detaches or -ends. +Show a session here as a client: a process of its own, with a copy of +the session's core and a view of its own, in this terminal for pardes, +a window for pardes-gui, whatever the session was started in. Bare, +the one detached session (with none, the one session). HOST:NAME is a +client of session NAME on another machine, over `ssh -L` to its +pardes-replica.sock ($PARDES_SSH: the ssh command, default ssh; +$PARDES_REMOTE_RUNTIME: its runtime directory, if not this one's +path); SOCK:NAME goes through a socket forwarded already (a path, with +a '/'). Returns when it is let go: its Detach or its terminal or window +closing (the session runs on), or the session's end. Usage: pardes attach [NAME] diff --git a/docs/typ/figures.typ b/docs/typ/figures.typ index 4ca51c1a..15364e47 100644 --- a/docs/typ/figures.typ +++ b/docs/typ/figures.typ @@ -201,37 +201,9 @@ wire((14.1, 3.0), (14.1, 1.67), ends: none, dash: "dotted", label: [keeps each \ one open], at: (15.15, 2.33), width: 1.6) }) -/// `pardes attach work` to a session with no frontend: a terminal's and a -/// window's. -#let run-attach-detached() = drawn(alt: "pardes attach to a detached session: the terminal handed to the session through the daemon; for a window, the session opens its own again", { - import cetz.draw: * - // A terminal's session. - content((0, 8.75), anchor: "west", text(size: 8pt, weight: "bold")[a terminal's session: `pardes attach work`]) - screen(0, 6.4, 3.4, 1.7, [this terminal]) - proc(0, 3.9, 3.4, 2.0, "stub", "pardes attach work", - ("plain", [now the job your shell waits on]), ("plain", [holds nothing])) - daemon-box(5.5, 3.9) - proc(11.0, 3.9, 5.0, 4.2, "session", "pardes --detach=work", - core-truth, ptys, ninep("work"), - ("plain", [draws on this terminal now]), - ("plain", [the same process as before])) - wire((3.4, 4.8), (5.5, 4.8), label: [① this terminal \ and a pipe], at: (4.45, 5.32), width: 1.8) - wire((8.9, 4.8), (11.0, 4.8), dash: "dashed", label: [② handed on], at: (9.95, 5.15)) - wire((3.4, 7.25), (11.0, 7.25), ends: "both", label: [③ keys in, frames out], at: (7.2, 7.6)) - line((-0.1, 3.3), (16.1, 3.3), stroke: (paint: palette.rule, thickness: 0.6pt)) - // A window's session. - content((0, 2.85), anchor: "west", text(size: 8pt, weight: "bold")[a window's session: `pardes-gui attach work`]) - proc(0, 0, 3.4, 2.0, "other", "pardes-gui attach work", ("plain", [asks, then exits: no stub]), dash: "dashed") - daemon-box(5.5, 0) - proc(11.0, 0, 5.0, 2.3, "session", "pardes-gui --detach=work", - core-truth, ("plain", [opens its own window again])) - wire((3.4, 0.9), (5.5, 0.9), label: [① asks], at: (4.45, 1.25)) - wire((8.9, 0.9), (11.0, 0.9), dash: "dashed", label: [② "attach"], at: (9.95, 1.25)) -}) - -/// `pardes attach work` to a session that has a frontend (or is of the -/// other kind): a client. -#let run-attach-client() = drawn(alt: "pardes attach to a session with a frontend: a client process with its own replica core, joined through the daemon", { +/// `pardes attach work`: a client, whether or not the session still has +/// the frontend it was born with (here it has). +#let run-attach-client() = drawn(alt: "pardes attach: a client process with its own replica core, joined through the daemon", { import cetz.draw: * screen(0, 3.4, 3.0, 1.7, [its own terminal]) proc(0, 0, 4.8, 2.9, "session", "pardes", @@ -283,12 +255,12 @@ wire((10.6, 0.7), (12.2, 0.7), ends: "both", label: [a pty's bytes], at: (11.4, 1.05)) }) -// ---- docs/next-run.md: the ruled direction, not built ---- +// ---- docs/next-run.md: the ruling, built ---- -/// What `pardes attach` does today (four things) beside what it does once -/// "an attach is always a client" is built (one). Drawn by +/// What `pardes attach` did before 2026-11-20 (four things) beside what it +/// does since "an attach is always a client" was built (one). Drawn by /// docs/next-run.typ for the design note; no chapter shows it. -#let run-attach-before-after() = drawn(alt: "pardes attach today: four mechanisms; after: always a client", { +#let run-attach-before-after() = drawn(alt: "pardes attach before: four mechanisms; now: always a client", { import cetz.draw: * let row(x, y, when, typed, kind, said) = { content((x, y + 1.2), anchor: "west", text(size: small, style: "italic", fill: palette.tag-fg, when)) @@ -299,13 +271,13 @@ rect((x + 3.9, y), (x + 7.5, y + 0.95), fill: tint(c), stroke: 1.3pt + c, radius: 3pt) content((x + 5.7, y + 0.475), box(width: 3.4cm, align(center, text(size: small, said)))) } - content((0, 8.15), anchor: "west", text(size: 9pt, weight: "bold")[Today: four mechanisms]) + content((0, 8.15), anchor: "west", text(size: 9pt, weight: "bold")[Before: four mechanisms]) row(0, 6.0, [a terminal's session, detached], [pardes attach work], "session", [the session draws here; this process becomes its stub]) row(0, 4.3, [a window's session, detached], [pardes-gui attach work], "session", [the session opens its own window; this process exits]) row(0, 2.6, [it has a frontend, or is the other kind], [pardes attach work], "client", [a client: this process, with a replica]) row(0, 0.9, [on another machine], [pardes attach box:work], "client", [a client, through `ssh -L`]) line((7.95, -0.1), (7.95, 8.4), stroke: (paint: palette.rule, thickness: 0.8pt)) - content((8.45, 8.15), anchor: "west", text(size: 9pt, weight: "bold")[After: always a client]) + content((8.45, 8.15), anchor: "west", text(size: 9pt, weight: "bold")[Now: always a client]) row(8.45, 6.0, [any session on this machine], [pardes attach work], "client", [a client: this process, with a replica]) row(8.45, 4.3, [on another machine], [pardes attach box:work], "client", [a client, through `ssh -L`]) content((8.45, 2.85), anchor: "west", box(width: 7.5cm, text(size: small)[A session's own frontend is only the one it was born with: a Detach, or its terminal or window closing, leaves it detached for good, and each attach after is a client.])) diff --git a/docs/typ/guide.typ b/docs/typ/guide.typ index e69c756a..3dd8107c 100644 --- a/docs/typ/guide.typ +++ b/docs/typ/guide.typ @@ -352,28 +352,29 @@ cheatsheet (#doc("cheatsheet")) say so. ``` pardes --detach=work & a session with no screen of its own -pardes --attach=work show it here -pardes-gui --attach=work a window session's window again -pardes --ps every session the daemon lists, and its shells -pardes --kill=work end it and its shells (--kill-all: every one) +pardes attach work show it here, as a client +pardes-gui attach work show it in a window, as a client +pardes ps every session the daemon lists, and its shells +pardes kill work end it and its shells (kill --all: every one) ``` #word("Detach") (#key("SPC s D")) lets the terminal or the window go and leaves the session running, its panes, shells and files kept; so does a terminal that closes, while the daemon (below) is there. A window that -closes ends its session, unless the session has clients. -`pardes --attach` takes it back in any terminal, -`pardes-gui --attach` a window session's window: a terminal session takes -a terminal, a window session a window. Attached already, it takes another -view: each terminal or window has its own columns, focus, cursors and -scroll over the same panes, texts and registers, and a terminal shown in -two takes the size of the one that last typed into it. #word("Detach") in -one lets only that one go. A session is named by `--9p=` or +closes ends its session, unless the session has clients. Once let go, a +session's own terminal or window never comes back: `pardes attach` shows +it in any terminal, `pardes-gui attach` in a window, either kind of +session, each as a client, a process of its own. Each terminal or window +has its own view (columns, focus, cursors, scroll) over the same panes, +texts and registers, and a terminal shown in two takes the size of the +one that last typed into it. #word("Detach") in one lets only that one +go. A session is named by `--9p=` or `--detach=`, else its pid. A session killed outright leaves its shells running; #word("Adopt") in another takes them in as terminal panes, what they showed gone. One `pardes --daemon` per user lists the sessions and holds their shells' terminals open; the first session starts it, it is -nobody's parent, and it leaves once it holds nothing. Which processes +nobody's parent, and it leaves once it holds nothing; killed, the +sessions start it again. Which processes run, and what survives what, is in #doc("running"). After a rebuild, #word("Upgrade") (#key("SPC s U")) moves a running session onto the pardes now installed diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ index 4c193e0f..425209a0 100644 --- a/docs/typ/reference.typ +++ b/docs/typ/reference.typ @@ -1014,7 +1014,7 @@ at 200, ending in `…`. Control characters become spaces. of its own, a terminal or window; `pardes ps` says "has a frontend") with a `client ` line for each of its clients and 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 + names attaches (`pardes attach `, either kind, as a client). 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 @@ -1350,15 +1350,13 @@ to its end before the write is answered, and one that finds nothing fails, which #word("Adopt") takes. `--kill=NAME` ends that session and its shells (a TERM, then a KILL 2 s later; unsaved changes are lost), `--kill-all` every session and every kept shell; with no daemon running - each says so and exits 1. Bare `--detach` names the session after its pid; bare - `--attach` needs exactly one detached session of its kind (a terminal's - for `pardes`, a window's for `pardes-gui`), or with none detached the - only session of that kind, joined as a client (with none of that kind, - the only session there is); a second `--detach=NAME` - while NAME runs (a plain session is named by its pid) says so in words - and exits 1. A session with a frontend already is joined as a client, as one of - the other kind is, and one on another machine (`--attach=HOST:NAME`, over - `ssh -L`; `--attach=SOCKET:NAME` through a socket forwarded already): its + each says so and exits 1. Bare `--detach` names the session after its pid; a + second `--detach=NAME` while NAME runs (a plain session is named by its + pid) says so in words and exits 1. `attach NAME` (`--attach=NAME`) is + always a client of session NAME, either kind, here or on another machine + (`attach HOST:NAME`, over `ssh -L`; `attach SOCKET:NAME` through a socket + forwarded already); bare, of the one detached session, else the only + session (with several, it names them and exits 1): its own process, listed under the session by `--ps`, up to three clients (four views at once, the session's own among them): each terminal or window its own layout, focus, cursors, selections, modes, diff --git a/docs/typ/running.typ b/docs/typ/running.typ index 1500845e..74eb8cbd 100644 --- a/docs/typ/running.typ +++ b/docs/typ/running.typ @@ -4,31 +4,32 @@ // attach); the direction not built yet is docs/next-run.md. The file:line // that says each fact is in a comment beside it. #import "style.typ": word, doc, pairs, file -#import "figures.typ": run-legend, run-terminal, run-window, run-detach, run-attach-detached, run-attach-client, run-far, run-no-daemon +#import "figures.typ": run-legend, run-terminal, run-window, run-detach, run-attach-client, run-far, run-no-daemon A running pardes is up to four kinds of process. Which of them there are, and what each holds, depends only on how it was started. -// runtime/daemon.zig:8-16 (nobody's parent; dups; hands terminals, -// windows, replicas); core/replica.zig:1-19, :747-794 (a client's core +// runtime/daemon.zig:8-17 (nobody's parent; dups; lists the sessions, +// hands a client's connection on); core/replica.zig:1-19, :747-794 (a client's core // from the dump); dev/host_io.zig:548-551 (the shells are the session's -// children); runtime/9p_io.zig:57 (the socket); runtime/daemon.zig:546-698 -// (the stub). +// children); runtime/9p_io.zig:57 (the socket); runtime/daemon.zig forkSession, +// stubWait (the stub). #pairs( [*session*], [the process with the truth: the one core every other copy follows, the shells' pty masters (the shells are its children) and the 9P socket. There is one a session, always.], [*client*], [any further terminal or window on a session: a process of its own, with a copy of the session's core (a replica) loaded from the session's dump and kept in step with the session's tape. It has its own view (columns, focus, cursors, scroll) and draws it. It holds no shells and no 9P socket. A client on another machine is *far*.], - [*daemon*], [`pardes --daemon`, one per user per machine: a switchboard. It spawns nothing and is nobody's parent. It keeps the list of sessions and a dup of every pty master, so that a session killed outright never hangs its shells up; clients dial its replica socket; it hands a terminal, a window's request or a client's connection to the session that takes it. The first session that finds none starts it, and it exits a second after it holds nothing.], + [*daemon*], [`pardes --daemon`, one per user per machine: a switchboard. It spawns nothing and is nobody's parent. It keeps the list of sessions and a dup of every pty master, so that a session killed outright never hangs its shells up; clients dial its replica socket, and it hands each client's connection to the session it names. The first session that finds none starts it, and it exits a second after it holds nothing. Killed, it is started again by its sessions, which register with the next one.], [*stub*], [the process your shell waits on when the session is not it. It holds nothing: it passes signals on, and ends when the session leaves its terminal.], ) -// dev/tui/tui.zig:590 (a session's terminal: one or none); -// dev/gui/gui.zig:2433-2436 (the window, or none while detached); -// runtime/daemon.zig:901-905 ("a session shows one frontend of its own"). +// dev/tui/tui.zig Screen (a session's terminal: the one it was born +// with, or none); dev/gui/gui.zig Shell.gui (the window, or none once +// detached); runtime/main.zig attachTo (an attach is a client). A *frontend* is what draws: the terminal (`pardes`), the window (`pardes-gui`), or the Mac's own build. A session draws at most one -frontend of its own: the one it was started with, or one attached to it -later. A session with none is *detached*; it may still have clients. -To *attach* is to show a session here. +frontend of its own: the one it was started with. Once it lets that one go +(a #word("Detach"), its terminal closing) it is *detached*, for good; it +may still have clients. To *attach* is to show a session here, and an +attach is always a client. In the figures a box with a heavy edge is a process: its kind, then the command `ps` shows for it, then what it holds. The core with the truth is @@ -41,11 +42,11 @@ travels on it. #run-terminal() -// runtime/main.zig:1570-1595, runtime/daemon.zig:663-698 (the fork, -// setsid, the stub); runtime/daemon.zig:550-559, :567-616 (what the stub -// forwards and how it ends); dev/tui/tui.zig:1685-1709 (the terminal's -// end: detached while kept, else the end); runtime/daemon.zig:305-314 -// (kept: the daemon answered and is still there). +// runtime/main.zig, the fork (daemon.forkSession: setsid, the stub); +// runtime/daemon.zig forward, stubWait (what the stub forwards and how it +// ends); dev/tui/tui.zig, the `.quit` arm (the terminal's end: detached +// while kept, else the end); runtime/daemon.zig kept (the daemon +// answered and is still there). `pardes` forks the session off and stays as its stub. The session runs in a POSIX session of its own, so it can outlive the job your shell waits on. It reads the keys from the terminal and draws on it itself; the stub only @@ -54,7 +55,7 @@ session too) and exits when the session leaves the terminal, with the session's status, or 0 after a #word("Detach"). Closing the terminal detaches the session while a daemon keeps it. With no -daemon, or after the daemon has died, it ends the session and its shells. +daemon it ends the session and its shells. = `pardes-gui` @@ -80,9 +81,9 @@ terminal hangs up. // process). The process you started is the session: nothing is forked, so the `&` that puts it in the background is yours to type (`pardes new --detach=work` is -the same). It draws nothing and is 160×50 until an attach or the root -#file("ctl")'s `size` sizes it. Until something attaches, 9P is the only -way in (#doc("scripting")). +the same). It draws nothing and is 160×50 until the root #file("ctl")'s +`size` sizes it; a client shows its own view, at its own size. Until a +client attaches, 9P is the only way in (#doc("scripting")). // runtime/main.zig, the --detach branch (the exec of the pardes beside it). `pardes-gui --detach` runs the `pardes` installed beside it in its place: @@ -95,55 +96,42 @@ a daemon keeps it; a window's binary's ends on it, as any job does. With no daem `--detach` still starts a session, which nothing can attach to: only 9P reaches it. -= Attach, to a detached session - -#run-attach-detached() - -// runtime/main.zig:1812-1842 (attachTo); runtime/daemon.zig:883-897 -// (handed on); dev/tui/tui.zig:1354-1382 (the terminal entered as the -// first was); dev/gui/gui.zig:3384-3402, :2588-2601 (the window opened -// again). -For a terminal's session, `pardes attach work` hands its terminal and a -pipe to the session through the daemon, and stays as the stub. For a -window's, `pardes-gui attach work` asks, then exits, and the session opens -its own window again. Either way the frontend is the session's own again, -in the process that has been the session all along: what happens when -it closes is what the first two sections say. - -// runtime/daemon.zig:901-972 (find: the bare attach, and `other`). -The kind has to match. A terminal's session attached from `pardes-gui`, -or a window's from `pardes`, is joined as a client (the next section). -Bare, `pardes attach` takes the one detached session of its kind; with -none, the one session of its kind, as a client; with no session of its -kind, the only session there is, as a client. `--attach=work` is the older -spelling of `attach work`. - -= Attach, to a session that has a frontend += Attach #run-attach-client() -// runtime/main.zig:1844-1850 (crossAttach); runtime/daemon.zig:974-1008 -// (the hello, the same build, handed on); core/replica.zig:1-19 -// (speculation and rollback); core/replica.zig:2204-2214, core/views.zig:31, +// runtime/main.zig attachTo, bareAttach (a client, through the replica +// socket; bare: the one detached session, else the one session); +// runtime/daemon.zig hear (the hello, the same build, handed on); +// core/replica.zig:1-19 (speculation and rollback); core/views.zig:31, // core/Core.zig:1163-1203 (four views, the session's own among them); -// core/replica.zig:2303-2325 (a client leaving); core/replica.zig initDump, -// core/Addon.zig plainOps (a plain kind's code runs in the client that has -// it; another's in the session alone); dev/gui/gui.zig:2200-2214 (a -// client's notch: whole rows sent), :3673 (glideFrame: the picture on the -// client's clock); dev/gui/gui.zig:595-623 (a client's font: the session's -// request, by the face's name on this machine). Measured 2026-11-17 +// core/replica.zig closeViewOf (a client leaving); core/replica.zig +// initDump, core/Addon.zig plainOps (a plain kind's code runs in the +// client that has it; another's in the session alone); +// dev/gui/gui.zig:2200-2214 (a client's notch: whole rows sent), +// glideFrame (the picture on the client's clock); dev/gui/gui.zig +// syncReplicaFont (a client's font: the session's request, by the face's +// name on this machine). Measured 2026-11-17 // (.scratch/sketch/reports/pardes-measure.md sections A, C and E): a // client's notch glides as the session's window does (5 frames, 0 to // -22 px); a terminal's client 10-16 MB PSS idle, a window's about 110 MB // (187 MB RSS), as a window session's, three quarters of it the GPU and // display libraries. -A session draws one frontend of its own, so the second attach is a client. -The daemon checks the client's hello (the session's name, and the client's -build: a client must be the build its session is) and hands its -connection to the session; from then on the two talk directly. The client -loads the session's dump into its own core, applies its own keys at once, -and takes the session's tape (each step as the session took it) as the -truth, rolling back when the session ordered things differently. +`pardes attach work` is a client of session work, whatever the session was +started in and whether or not it still has its own frontend: in a terminal +for `pardes`, a window for `pardes-gui`. A session never takes a frontend +of its own back: the one it was born with is the only one it ever has. +Bare, `pardes attach` takes the one detached session; with none detached, +the only session there is; with several, it names them and asks which. +`--attach=work` is the older spelling of `attach work`. + +The client says its hello on the daemon's replica socket: the session's +name, and the client's build (a client must be the build its session is). +The daemon refuses a name no session has, and hands the connection to the +session; from then on the two talk directly. The client loads the +session's dump into its own core, applies its own keys at once, and takes +the session's tape (each step as the session took it) as the truth, +rolling back when the session ordered things differently. // core/replica.zig:5316-5395 (may_wait: what a client waits for, each // row's why); core/tape.zig:1163-1193 (keeps_stopping); core/Core.zig:1763-1778 @@ -163,7 +151,7 @@ opens here. A session takes three clients: four views at once, its own among them. A client's #word("Detach"), or its terminal or window closing, ends that -client only; the last client of a detached session leaves its layout as +client only (it says the session let it go, and exits 1); the last client of a detached session leaves its layout as the session's, for the next one to find. In a client, an addon whose state is plain (`PA_PLAIN`: the games, the picture, the PDF) runs in the client that shows it, from that client's own addons; one the client lacks @@ -202,18 +190,18 @@ of the session or a divergence of its own. `pardes attach /run/x.sock:work` #run-no-daemon() -// runtime/daemon.zig:52-61 (PARDES_DAEMON, PARDES_TEST), :34 (Linux and -// FreeBSD only); runtime/main.zig:1576-1592 (no daemon reached: no fork); -// dev/tui/tui.zig:1333-1334, dev/gui/gui.zig:2537, dev/host_io.zig:85 -// (Detach and Adopt refused); core/replica.zig:2087-2092 (a client only -// through the daemon); core/root.zig:118 (can_attach); -// runtime/main.zig:1513-1515 (a far attach needs no daemon here). +// runtime/daemon.zig wanted (PARDES_DAEMON, PARDES_TEST), supported +// (Linux and FreeBSD only); runtime/main.zig, the fork (no daemon reached: +// no fork); dev/tui/tui.zig detach, dev/gui/gui.zig detachWindow, +// dev/host_io.zig (Detach and Adopt refused); runtime/main.zig attachTo (a +// client only through the daemon); core/root.zig can_attach; +// runtime/main.zig, `attach HOST:NAME` (a far attach needs no daemon here). With `PARDES_DAEMON=off`, in a window under test (`PARDES_TEST`), where none could start, and in the Mac's own build, the session is the process you started, with no stub. #word("Detach") and #word("Adopt") refuse, no client can join (a client comes only through the daemon), and closing the terminal or the window ends the session and its shells. A session whose -daemon died is in the same place (#link()[below]). +daemon died is not: it starts the next one itself (#link()[below]). `pardes-gui` built for a Mac has no daemon either, but can still be a far client. @@ -234,8 +222,7 @@ client. [`pardes`], [stub, session, daemon], [`pardes` twice (the stub, and its child the session), `pardes --daemon`], [the session], [the session, on your terminal], [the session detaches while a daemon keeps it; else it ends], [`pardes-gui`], [session, daemon], [`pardes-gui`, the daemon], [the session], [the session, its window], [the session ends, unless it has clients and a daemon: then it runs on, detached], [`pardes --detach=work &`], [session, daemon], [`pardes --detach=work`, the daemon], [the session], [nothing], [it has none; its terminal's hangup ends a window's, not a terminal's while a daemon keeps it], - [`pardes attach work`, detached], [stub, session, daemon (a window's attach exits)], [`pardes attach work` (the stub), the session as it was], [the session], [the session, on this terminal (or its window)], [as for `pardes` (or `pardes-gui`)], - [`pardes attach work`, it has a frontend], [client, session, daemon], [`pardes attach work` (the client), the session], [the session; the client has a replica], [each its own: the session its frontend, the client this terminal], [the client ends; the session runs on], + [`pardes attach work`], [client, session, daemon], [`pardes attach work` (the client), the session as it was], [the session; the client has a replica], [the client, this terminal (`pardes-gui`: a window); the session its own frontend, if it still has it], [the client ends; the session runs on], [`pardes attach box:work`], [here: client, ssh; on box: daemon, session], [`pardes attach box:work`, `ssh -tt -q -o ExitOnForwardFailure=yes -L … box exec sleep 2147483647`], [the far session], [the client, here], [the client ends, and its ssh], [no daemon], [session], [`pardes` (or `pardes-gui`)], [the session], [the session], [the session ends, with its shells], ) @@ -247,13 +234,14 @@ started it. After an #word("Upgrade"), a session's command line starts with = What survives what -// core/replica.zig:2303-2325 (a client leaving); runtime/daemon.zig:485-502, +// core/replica.zig closeViewOf (a client leaving); runtime/daemon.zig hangUp, quit, // runtime/9p_io.zig:704-729, dev/tui/tui.zig:928-940 (TERM, HUP, INT: the -// shells go); runtime/daemon.zig:755-765, :770-789 (killed outright: kept +// shells go); runtime/daemon.zig Daemon.hangUp, Daemon.kill (killed outright: kept // for Adopt; `kill`: not); dev/tui/tui.zig:598-600 (a HUP kept by a daemon -// is a terminal's end, not the session's); runtime/daemon.zig:397, -// runtime/main.zig:1566-1593 (registered at the start and at an Upgrade -// only); runtime/upgrade.zig:1-15, core/replica.zig:2370-2393, :2988-3008 +// is a terminal's end, not the session's); runtime/daemon.zig readNotes, +// redial, relinked, dev/Ptys.zig tellDaemon (the next daemon dialled by +// the link's end alone, the hello and the shells' masters told it +// again); runtime/upgrade.zig:1-15, core/replica.zig:2370-2393, :2988-3008 // (Upgrade); core/Db.zig:1-17, :385-410 (the state file: Recent, the dumps). #{ set text(size: 0.85em) @@ -268,7 +256,7 @@ started it. After an #word("Upgrade"), a session's command line starts with [#word("Detach") in its own frontend], [runs on, detached (refused with no daemon)], [stay], [stay], [it ends (#word("Exit"), `pardes kill`, a TERM or an INT)], [gone; a terminal's stub exits with its status], [hang up with it], [each told, and exits], [it is killed outright (KILL) or crashes], [gone, its text with it unless dumped (#word("Dump"))], [run on while a daemon holds their terminals, and #word("Adopt") in another session takes them (what they showed is lost)], [each exits], - [the daemon is killed], [runs on, but no daemon lists it again, this one or the next: `pardes ps` and attach do not find it, #word("Detach") and #word("Adopt") refuse, and its frontend closing ends it], [stay; the shells of sessions killed earlier, held only by the daemon, hang up], [the ones joined stay; no new one can join], + [the daemon is killed], [runs on, and dials the next daemon at once, starting it if none answers: `pardes ps` lists it again, clients attach, #word("Detach") and #word("Adopt") work], [stay, their terminals held by the next daemon too; the shells of sessions killed earlier, held only by the dead daemon, hang up], [the ones joined stay; new ones join through the next daemon], [#word("Upgrade")], [the same pid on the new build, its dump loaded again; every view, terminal and stub kept; the daemon moves too. A build that cannot load the dump hands it back to the one before], [stay, the session's children still], [let go, and each joins again by itself (it tries for 20 s)], [a reboot], [gone; what is on disk stays: saved files and the state file (`pardes.xitdb`: Recent and the dumps, which #word("Restore") brings back)], [gone], [gone], ) @@ -282,8 +270,8 @@ started it. After an #word("Upgrade"), a session's command line starts with [*client*], [any further terminal or window on a session: its own process, a replica core], [*far*], [a client on another machine], [*frontend*], [what draws: the terminal, the window, the Mac's own], - [*detached*], [a session with no frontend of its own (it may have clients)], - [*attach*], [show a session here], + [*detached*], [a session with no frontend of its own, for good once it has let go the one it was born with (it may have clients)], + [*attach*], [show a session here: always a client], [*daemon*], [the per-user switchboard, `pardes --daemon`], [*stub*], [the process your shell waits on when the session is not it], ) @@ -295,7 +283,7 @@ and `headless` for detached): // core/replica.zig:1-19 (authority); core/replica.zig:2006-2062, :3013 // (Peers, Link, Joining); dev/tui/tui.zig:1162, dev/gui/gui.zig:2431 // (Shell); core/Core.zig:313-315, core/replica.zig:2028-2030 (unattended -// against detached); runtime/daemon.zig:283, :363, :799 (the daemon's +// against detached); runtime/daemon.zig hello, setDetached, Daemon.list (the daemon's // attached and detached), runtime/main.zig:1647 (`ps` says "has a // frontend"); runtime/session.zig:1-30, runtime/client.zig:1-35 (the // loops and what a frontend gives each). diff --git a/runtime/main.zig b/runtime/main.zig index 563461ed..a791ffec 100644 --- a/runtime/main.zig +++ b/runtime/main.zig @@ -280,17 +280,18 @@ const cmds = std.EnumArray(Cmd, Doc).init(.{ .attach = .{ .group = .Sessions, .args = "[NAME]", - .line = "show a detached session here (HOST:NAME: over ssh)", + .line = "show a session here, as a client (HOST:NAME: over ssh)", .doc = - \\Show a detached session here: in this terminal for pardes, a window - \\for pardes-gui. Bare, the one detached session (with none, the one - \\session). One with a frontend already, or of the other kind, is joined - \\as a client. HOST:NAME is a client of session NAME on another machine, - \\over `ssh -L` to its pardes-replica.sock ($PARDES_SSH: the ssh - \\command, default ssh; $PARDES_REMOTE_RUNTIME: its runtime directory, - \\if not this one's path); SOCK:NAME goes through a socket forwarded - \\already (a path, with a '/'). Returns when the session detaches or - \\ends. + \\Show a session here as a client: a process of its own, with a copy of + \\the session's core and a view of its own, in this terminal for pardes, + \\a window for pardes-gui, whatever the session was started in. Bare, + \\the one detached session (with none, the one session). HOST:NAME is a + \\client of session NAME on another machine, over `ssh -L` to its + \\pardes-replica.sock ($PARDES_SSH: the ssh command, default ssh; + \\$PARDES_REMOTE_RUNTIME: its runtime directory, if not this one's + \\path); SOCK:NAME goes through a socket forwarded already (a path, with + \\a '/'). Returns when it is let go: its Detach or its terminal or window + \\closing (the session runs on), or the session's end. , .examples = &.{ .{ "pardes attach", "the one detached session" }, -- cgit v1.3