From 1f731da28bd9983cc414839bd32372d183438164 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 20 Nov 2026 14:33:20 -0300 Subject: pair: `kept`, whole (P36): a session's state the daemon hears is one of attached, detached, pair, kept (daemon.State, its hello's and `state` word, numbered as the daemon's record said its bool), a `new --detach` (and the bare `--detach`) under PARDES_PAIR kept from birth, a pair's session `pair` until a Detach typed in any client makes it kept (daemon.keepSession, never cleared), an Upgrade carrying it (the record's `state` word), and Peers.kept deleted: a client's close ends the session only while it is `pair` (Peers.leave), the end condition no longer asks Options.pair but for the daemonless pair; `pardes ps` says `(tty)` of a pair's session not kept and `(tty, kept)` of a kept one, an own-path session's line unchanged (`(tty, has a frontend)`, `(tty, detached)`), and a bare attach takes any session without a frontend; test/daemon.py `pair_rows` rewritten (a `new --detach` kept, its clients ended by HUP and TERM: runs on; a pair `(tty)` across an Upgrade, its Detach `(tty, kept)` across another, its clients ended by TERM, KILL, HUP: runs on), `pair` and `gui_pair` read the new line, and gui_pair closes a window client of a `new --detach` session: it runs on; on the base `--pair` fails at "the client listed" (ps said `(tty, detached)`), here it passes (load 5-8), shell-test's record and bare-attach tests 32/32 and 9/9 Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- docs/typ/command-line.txt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'docs/typ') diff --git a/docs/typ/command-line.txt b/docs/typ/command-line.txt index 0ced145f..2f7753e4 100644 --- a/docs/typ/command-line.txt +++ b/docs/typ/command-line.txt @@ -39,10 +39,12 @@ The old spellings --ps, --attach[=NAME], --kill=NAME, --kill-all, -h and == pardes help ps What the per-user daemon lists: each session with its name, pid, kind -(tty or gui) and whether it has a frontend of its own or is detached; -under it its clients and its shells; then the shells no session holds, -which Adopt takes. /sessions is the same list, read from inside a -session (where a session with a frontend says attached). +(tty or gui) and whether it has a frontend of its own or is detached +(under PARDES_PAIR: kept, or nothing when its last client's close +ends it); under it its clients and its shells; then the shells no +session holds, which Adopt takes. /sessions is the same list, read +from inside a session (where a session with a frontend says +attached, and a pair's not kept says pair). Usage: pardes ps -- cgit v1.3 From 6683e03a40c0bbd88dadf6bb30121d41e944207c Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 20 Nov 2026 16:18:25 -0300 Subject: docs: PARDES_PAIR, what it is (pardes-pair-3's item 3e): docs/next-run.md a section (the experiment behind its variable, how to turn it on, kept and what `ps` says, the lifetime table as built: Detach, a close, a loss, no daemon, in the columns not kept and kept), docs/typ/running.typ the same as a section "An experiment: PARDES_PAIR" with the table (the book compiles with typst), core/CHANGELOG.md one entry (and the one change without the variable: a TERMed terminal client's goodbye and exit 0); `pardes help` says nothing of it yet Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/CHANGELOG.md | 11 +++++++++++ docs/next-run.md | 27 +++++++++++++++++++++++++++ docs/typ/running.typ | 31 +++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) (limited to 'docs/typ') diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index faa02ade..e5d592bb 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -2,6 +2,17 @@ ## Unreleased +- An experiment, behind `PARDES_PAIR=1` until it is the default: `pardes + FILE` in a terminal and `pardes-gui FILE` fork a session with no + frontend of its own and are its first client. Such a session is kept + (started with `new --detach`, or a Detach typed in any client since) or + not: closing a client's window or terminal, or a TERM to it, ends a + session not kept when that was its last client; a client killed outright + leaves it running. `pardes ps` says `(tty, kept)` or `(tty)` of it. + Without the variable nothing changes, but a terminal client (`pardes + attach`) ended by a TERM now says goodbye and exits 0, its terminal put + back, where it died of the signal. + - `pardes new --detach[=NAME]` returns once the session runs (registered and listening), printing its name, exit 0; the session runs on in a session of its own. `pardes --detach=NAME` without `new` is still the diff --git a/docs/next-run.md b/docs/next-run.md index c2d3488b..00890ef1 100644 --- a/docs/next-run.md +++ b/docs/next-run.md @@ -178,6 +178,33 @@ it). For the window's build the fork comes before SDL starts. Then `pardes --detach=work` returns at once, `&` is not needed, and every session in `ps` is either its stub's child or a process of its own. +## `PARDES_PAIR`: every frontend a client (an experiment, built) + +With `PARDES_PAIR=1` in its environment (`export PARDES_PAIR=1` in a +shell's rc; unset, nothing below happens), `pardes FILE` in a terminal and +`pardes-gui FILE` start the way the last step's design has every frontend +start: the process you started forks a session with no terminal or window +of its own (`setsid`, `/dev/null`; a window's child execs the `pardes` +beside it) and is its first client over a socket pair, the job your shell +waits on (`runtime/main.zig` `pair`). A session is `kept` or not: kept from +birth when started with `new --detach[=NAME]` or `--detach`, kept once a +Detach is typed in any of its clients, never unkept, and an Upgrade +carries it (`runtime/daemon.zig` `State`, the upgrade record's `state`). +`pardes ps` says `(tty, kept)` of a kept session and `(tty)` of one that +is not; a session with a frontend of its own still says `(tty, has a +frontend)` and a detached one `(tty, detached)`. Its lifetime +(`core/replica.zig` `Peers.leave`, `runtime/session.zig`): + +| What happens | Not kept | Kept | +|---|---|---| +| Detach typed in a client | it becomes kept; the client says "detached from 'NAME', which is still running" and exits 0 | the same | +| a window closed, a terminal closed (its hangup), a TERM to a client | the client says goodbye with a close and exits 0, its terminal put back; the session ends if that was its last client | it runs on | +| a client killed outright (KILL) or crashed | the link ends with no goodbye: it runs on, listed by `pardes ps`, attachable | it runs on | +| no daemon | it ends when its last client's link ends, goodbye or not | cannot be: Detach refuses | + +Tested by `test/daemon.py --pair` (`pair`, `pair_rows`) and `--gui` +(`gui_pair`). + ## Rex beside pardes From Rex's own help (captured under diff --git a/docs/typ/running.typ b/docs/typ/running.typ index 74eb8cbd..320b3130 100644 --- a/docs/typ/running.typ +++ b/docs/typ/running.typ @@ -205,6 +205,37 @@ 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. += An experiment: `PARDES_PAIR` + +// runtime/main.zig pair (the fork); runtime/daemon.zig State, keepSession; +// core/replica.zig Peers.leave, Peers.detach; runtime/session.zig (the +// end); dev/tui/tui.zig runClient and winchWatch (HUP and TERM a close); +// dev/gui/gui.zig Input.close; runtime/upgrade.zig Record.state. +With `PARDES_PAIR=1` in its environment (`export PARDES_PAIR=1`; unset, +none of this happens), `pardes FILE` in a terminal and `pardes-gui FILE` +start the way every frontend will: the process you started forks a +session with no terminal or window of its own and is its first client, +the job your shell waits on. A session is _kept_ or not: kept from birth +when started with `pardes new --detach` (or `--detach`), and once a +#word("Detach") is typed in any of its clients; an #word("Upgrade") keeps +which. `pardes ps` says `(tty, kept)` of a kept session and `(tty)` of +one that is not. + +#{ + set text(size: 0.85em) + set par(justify: false) + table( + columns: (1.2fr, 1.6fr, 0.9fr), + stroke: (x, y) => if y == 0 { (bottom: 0.8pt) } else { (bottom: 0.3pt) }, + inset: (x: 4pt, y: 4pt), + table.header([*what happens*], [*not kept*], [*kept*]), + [#word("Detach") typed in a client], [it becomes kept; the client says so and exits 0], [the same], + [a window closed, a terminal closed, a TERM to a client], [the client says goodbye and exits 0, its terminal put back; the session ends if that was its last client], [it runs on], + [a client killed outright (KILL) or crashed], [it runs on, listed by `pardes ps`], [it runs on], + [no daemon], [it ends with its last client, whatever ended it], [cannot be: #word("Detach") refuses], + ) +} + = At a glance // The rows' sources are the sections above; `ps`: -- cgit v1.3