1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
|
// How pardes runs: which processes each way of starting pardes makes, who
// holds what, what draws, and what survives what. What is BUILT, in the
// words ruled on 2026-11-17 (session, client, far, frontend, detached,
// 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-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-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 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, 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 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. 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
marked the same way each time. A line is a connection, labelled with what
travels on it.
#run-legend()
= `pardes` in a terminal <run-terminal>
#run-terminal()
// 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
passes signals on (a resize, a hangup, a TERM: `kill` on the stub ends the
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 it ends the session and its shells.
= `pardes-gui` <run-window>
#run-window()
// runtime/main.zig:1568-1569 (registered, no fork);
// dev/gui/gui.zig:1830-1843 (the window's close); next-daemon.md "Phase 3
// notes", known gaps (a terminal's job).
The process you started is the session; there is no stub. Closing the
window ends the session and its shells, unless the session has clients and
a daemon: then only the window closes, and the session runs on, detached.
Started from a terminal, it stays that terminal's job, and ends when that
terminal hangs up.
= `pardes --detach` <run-detach>
#run-detach()
// runtime/main.zig:1517-1552 (no fork; 160x50); runtime/main.zig:1567-1569
// (registered detached, or with no daemon not at all);
// dev/tui/tui.zig:598-605 and :1688 (a hangup taken, nothing to leave);
// runtime/9p_io.zig:704-729 (the hangup's default handler in a window's
// 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 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:
a detached session draws nothing, and a window's binary would start a GPU
device and its fonts for it. So every detached session is a terminal's
(`ps` says tty), and a window shows it as a client; only where no `pardes`
is beside it is the session the window's binary, with no window.
A terminal's detached session runs on through its terminal's hangup while
a daemon keeps it; a window's binary's ends on it, as any job does. With no daemon,
`--detach` still starts a session, which nothing can attach to: only 9P
reaches it.
= Attach <run-attach-client>
#run-attach-client()
// 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 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.
`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
// (readSessionFacts: the session's home, shell, directory);
// runtime/client.zig:245-261 (asks: a client's yank, paste and link, here).
What a client applies at once is what changes the editor alone: typing,
motions, edits, the layout (a pane dragged, collapsed or closed, a column
made), a yank. What touches the session's machine waits a round trip for
the session's step: a save, a shell's keys or its closing, a file read
from its disk, a program run, a kind whose state is the session's
(#doc("building", section: "may-wait") lists each, with why). The
session's machine is the one a client's words read: `~`, the default
shell and the directory a word runs in are the session's. The client's
machine is the one its view acts on: a yank to the system clipboard fills
the clipboard here, #word("ClipPaste") pastes it, and a link looked at
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 (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
shows a line saying so, and any other addon's panes show a line saying
it runs in the session alone. A
window client's wheel glides as the session's own window does: whole rows
go to the session, and the picture moves between them on the client's own
clock. It takes the session's font only when the same face is installed on
its machine. A client costs what a frontend of its kind costs: 10-16 MB
for a terminal's, about 110 MB for a window's, the same as any window
(mostly the GPU and display libraries); its copy of the core is the small
part.
= A far session <run-far>
#run-far()
// runtime/main.zig:1513-1515, :1719-1804 (HOST:NAME, ssh -L, PARDES_SSH,
// PARDES_REMOTE_RUNTIME, a path with '/'); runtime/client.zig:74-87 (far:
// blobs by hash, zstd); core/replica.zig:2709-2845 (Have: the disk cache);
// runtime/client.zig:168-177, core/replica.zig:3262-3274 (no reconnect; a
// rejoin only after a divergence or an Upgrade).
`pardes attach box:work` runs `ssh -L` from a socket here to box's replica
socket and is a client through it. `PARDES_SSH` replaces `ssh`;
`PARDES_REMOTE_RUNTIME` names box's runtime directory when it is not the
same path as here. A far client is sent the session's tape in zstd and only
the texts it lacks, by hash, and keeps what it was sent on disk for its
next start. Both ends must be the same build.
When the link ends (ssh, the network, the session) the client exits. It
does not reconnect: it joins again by itself only after an #word("Upgrade")
of the session or a divergence of its own. `pardes attach /run/x.sock:work`
(a path, with a `/`) is a client through a socket forwarded already.
= No daemon <run-no-daemon>
#run-no-daemon()
// 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 not: it starts the next one itself (#link(<run-survives>)[below]).
`pardes-gui` built for a Mac has no daemon either, but can still be a far
client.
= An experiment: `PARDES_PAIR` <run-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 <run-glance>
// The rows' sources are the sections above; `ps`:
// runtime/daemon.zig:241-245 (the daemon is whichever binary started it),
// runtime/main.zig:1759 (ssh's arguments), runtime/upgrade.zig:5-8 (an
// upgraded session's command line).
#{
set text(size: 0.85em)
set par(justify: false)
table(
columns: (1.2fr, 1fr, 1.45fr, 0.85fr, 1fr, 1.45fr),
stroke: (x, y) => if y == 0 { (bottom: 0.8pt) } else { (bottom: 0.3pt) },
inset: (x: 4pt, y: 4pt),
table.header([*you type*], [*processes*], [*`ps` shows*], [*the truth*], [*what draws*], [*its terminal or window closes*]),
[`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`], [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],
)
}
The daemon is `pardes --daemon` or `pardes-gui --daemon`, whichever binary
started it. After an #word("Upgrade"), a session's command line starts with
`--upgraded=` and its record, and the daemon's ends with its list.
= What survives what <run-survives>
// 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 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 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)
set par(justify: false)
table(
columns: (1fr, 1.5fr, 1.2fr, 1fr),
stroke: (x, y) => if y == 0 { (bottom: 0.8pt) } else { (bottom: 0.3pt) },
inset: (x: 4pt, y: 4pt),
table.header([], [*the session*], [*its shells*], [*its clients*]),
[its own frontend closes], [as the table above says], [stay while the session does], [stay while the session does],
[a client leaves (its #word("Detach"), its terminal or window, its process)], [runs on; that client's view closes], [stay], [the others stay],
[#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, 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],
)
}
= The words <run-words>
// PARDES.md ruling 1 (2026-11-17).
#pairs(
[*session*], [the process with the truth],
[*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, 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],
)
The code says these words too, each for one thing of its own (the older
notes, `docs/next-daemon.md` among them, still say `remote` for a client
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 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).
#pairs(
[`authority`], [the session's core, inside the replica engine; `replica`, a client's core],
[`Peers`, `Peer`; `Link`, `Joining`, `Joined`], [a session's clients, seen from the session; a client's connection, seen from the client],
[`Shell`], [a frontend's host object (`dev/tui/tui.zig`, `dev/gui/gui.zig`); elsewhere the user's shell],
[`session.Loop`, `client.Loop`], [the one loop a terminal's or a window's session runs and the one a client runs (`runtime/session.zig`, `runtime/client.zig`), each over the frontend that draws it: `Own` for a session's own terminal or window, `Tty` and `Client` for a client's; the Mac's own build keeps its own],
[`unattended`], [a detached session with no client either: nobody looks, so a message goes on the clock],
[`attached` in #file("/sessions")], [the daemon's word for a session with a frontend of its own; `pardes ps` says "has a frontend"],
)
|