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
|
// 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-detached, 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.
// daemon.zig:8-16 (nobody's parent; dups; hands terminals, windows,
// replicas); replica.zig:1-19, :730-769 (a client's core from the dump);
// host_io.zig:2176-2179 (the shells are the session's children);
// 9p_io.zig:57 (the socket); daemon.zig:546-698 (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.],
[*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.],
)
// tui.zig:588 (a session's terminal: one or none); gui.zig:2381-2384 (the
// window, or none while detached); daemon.zig:901-905 ("a session shows one
// frontend of its own").
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.
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()
// main.zig:1538-1563, daemon.zig:663-698 (the fork, setsid, the stub);
// daemon.zig:550-559, :567-616 (what the stub forwards and how it ends);
// tui.zig:1697-1721 (the terminal's end: detached while kept, else the
// end); daemon.zig:305-314 (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, or after the daemon has died, it ends the session and its shells.
= `pardes-gui` <run-window>
#run-window()
// main.zig:1536-1537 (registered, no fork); gui.zig:1775-1788 (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()
// main.zig:1502-1520 (no fork; 160x50); main.zig:1535-1537 (registered
// detached, or with no daemon not at all); tui.zig:596-603 and :1700
// (a hangup taken, nothing to leave); 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 an attach or the root
#file("ctl")'s `size` sizes it. Until something attaches, 9P is the only
way in (#doc("scripting")).
A terminal's detached session (`pardes --detach`) runs on through its
terminal's hangup while a daemon keeps it. A window's
(`pardes-gui --detach`) 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, to a detached session <run-attach-detached>
#run-attach-detached()
// main.zig:1780-1810 (attachTo); daemon.zig:883-897 (handed on);
// tui.zig:1373-1401 (the terminal entered as the first was);
// gui.zig:3271-3289, :2534-2547 (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.
// 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 <run-attach-client>
#run-attach-client()
// main.zig:1812-1818 (crossAttach); daemon.zig:974-1008 (the hello, the
// same build, handed on); replica.zig:1-19 (speculation and rollback);
// replica.zig:2013-2023, views.zig:31, Core.zig:1110-1153 (four views, the
// session's own among them); replica.zig:2111-2133 (a client leaving);
// replica.zig initDump, Addon.zig plainOps (a plain kind's code runs in
// the client that has it; another's in the session alone); gui.zig:2147-2161
// (a client's notch: whole rows sent), :3544 (glideFrame: the picture on
// the client's clock); gui.zig:580-608 (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.
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
the session's, for the next one to find. In a client, an addon whose state
is plain (`PA_PLAIN`: the games) runs in the client that shows it, from
that client's own addons, its keys applied at once; one the client lacks
shows a line saying so; any other addon's panes show what the session's
code drew. 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()
// main.zig:1498-1500, :1687-1772 (HOST:NAME, ssh -L, PARDES_SSH,
// PARDES_REMOTE_RUNTIME, a path with '/'); tui.zig:678-685 (far: blobs by
// hash, zstd); replica.zig:2516-2640 (Have: the disk cache);
// tui.zig:819-828, replica.zig:3012-3024 (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()
// daemon.zig:52-61 (PARDES_DAEMON, PARDES_TEST), :34 (Linux and FreeBSD
// only); main.zig:1544-1560 (no daemon reached: no fork); tui.zig:1352-1353,
// gui.zig:2483, host_io.zig:227 (Detach and Adopt refused);
// replica.zig:1900-1905 (a client only through the daemon);
// pardes.zig:113 (can_attach); main.zig:1498-1500 (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(<run-survives>)[below]).
`pardes-gui` built for a Mac has no daemon either, but can still be a far
client.
= At a glance <run-glance>
// The rows' sources are the sections above; `ps`: daemon.zig:241-245
// (the daemon is whichever binary started it), main.zig:1727 (ssh's
// arguments), 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`, 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 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>
// replica.zig:2111-2133 (a client leaving); daemon.zig:485-502,
// 9p_io.zig:704-729, tui.zig:949-961 (TERM, HUP, INT: the shells go);
// daemon.zig:755-765, :770-789 (killed outright: kept for Adopt; `kill`:
// not); tui.zig:596-598 (a HUP kept by a daemon is a terminal's end, not
// the session's); daemon.zig:397, main.zig:1534-1561 (registered at the start and at
// an Upgrade only); upgrade.zig:1-15, replica.zig:2178-2201, :2787-2807
// (Upgrade); 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, 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],
[#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 (it may have clients)],
[*attach*], [show a session here],
[*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):
// replica.zig:1-19 (authority); replica.zig:1832-1876, :2812 (Peers, Link,
// Joining); tui.zig:1189, gui.zig:2379 (Shell); Core.zig:269-271,
// replica.zig:1850-1852 (unattended against detached); daemon.zig:283,
// :363, :799 (the daemon's attached and detached), main.zig:1616 (`ps`
// says "has a frontend").
#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 (`tui.zig`, `gui.zig`); elsewhere the user's shell],
[`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"],
)
|