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
|
// The figures of the corpus, drawn with cetz: the one file that imports it
// (a content file imports what it draws from here, never cetz itself).
// Colours are style.typ's palette. Each figure is a cetz canvas: on paper
// the canvas itself, in HTML the same canvas laid out as an inline SVG
// (html.frame), on the paper colour so it reads the same on a dark page.
#import "@preview/cetz:0.4.2"
#import "style.typ": palette, mono, html-out
// ---- the grammar of "how pardes runs" (running.typ) ----
//
// A box with a heavy edge is a process: its kind (session, client, daemon,
// stub) in the kind's colour, the command `ps` shows, then what it holds.
// The core with the truth is a filled chip with a star, a replica's core an
// outlined one; a terminal or a window is a screen (a bar along its top);
// a line is a connection, labelled with what travels on it, solid for
// what a person types and sees, dashed for the processes' own errands.
#let kinds = (
session: palette.grip,
client: palette.tag-name,
daemon: palette.col-grip,
stub: palette.rule.darken(25%),
other: palette.ink.lighten(45%),
)
#let truth = palette.mouse
#let small = 7.4pt
#let tint(c) = c.lighten(87%)
/// What a process holds, one line each: `("truth", body)` the core with the
/// truth, `("replica", body)` a replica's core, `("plain", body)` anything
/// else.
#let held(kind, body) = {
let (fill, stroke, mark) = if kind == "truth" {
(truth.lighten(80%), 1pt + truth, text(fill: truth)[★ ])
} else if kind == "replica" {
(palette.paper, (paint: truth, thickness: 0.9pt, dash: "dashed"), text(fill: truth)[☆ ])
} else {
(palette.paper, 0.5pt + palette.rule, [])
}
box(width: 100%, fill: fill, stroke: stroke, radius: 1.5pt, inset: (x: 3pt, y: 2.2pt),
text(size: small, fill: palette.ink, [#mark#body]))
}
/// A process at (x, y), w by h (cm): its kind, its command, what it holds.
/// `dash` for a process that does not stay (an attach that asks and exits).
#let proc(x, y, w, ht, kind, cmd, ..holds, name: none, dash: none) = {
import cetz.draw: *
let c = kinds.at(kind)
rect((x, y), (x + w, y + ht), fill: tint(c), stroke: (paint: c, thickness: 1.3pt, dash: dash), radius: 3pt, name: name)
content((x + 0.14, y + ht - 0.1), anchor: "north-west", box(width: (w - 0.28) * 1cm, stack(spacing: 2.4pt,
if kind != "other" { text(size: small, weight: "bold", fill: c, upper(kind)) },
text(font: mono, size: 0.95 * small, fill: palette.ink, cmd),
v(1pt),
..holds.pos().map(((k, b)) => held(k, b)),
)))
}
/// A terminal or a window at (x, y), w by h: a screen with a bar along its
/// top. `none-there: true` for the screen a session does not have.
#let screen(x, y, w, ht, label, none-there: false) = {
import cetz.draw: *
let ink = if none-there { palette.rule } else { palette.ink }
let dash = if none-there { "dashed" } else { none }
rect((x, y), (x + w, y + ht), fill: palette.paper, stroke: (paint: ink, thickness: 0.9pt, dash: dash), radius: 2pt)
if not none-there {
rect((x, y + ht - 0.22), (x + w, y + ht), fill: ink.lighten(70%), stroke: (paint: ink, thickness: 0.9pt), radius: (north: 2pt))
}
content((x + w / 2, y + (ht - if none-there { 0 } else { 0.22 }) / 2), box(width: (w - 0.3) * 1cm,
align(center, text(size: small, fill: if none-there { palette.tag-fg } else { palette.ink }, label))))
}
/// A shell, a child of its session: a small plain box.
#let shellbox(x, y, label) = {
import cetz.draw: *
rect((x, y), (x + 1.3, y + 0.62), fill: palette.paper, stroke: 0.7pt + palette.rule, radius: 2pt)
content((x + 0.65, y + 0.31), text(font: mono, size: small, fill: palette.tag-fg, label))
}
/// A connection through `pts`, labelled where `at` says (on the paper, so
/// no text sits on a line). `ends`: "end", "both" or none.
#let wire(..pts, label: none, at: none, ends: "end", dash: none, side: "center", width: none) = {
import cetz.draw: *
let p = pts.pos()
let m = (fill: palette.ink, scale: 0.6)
let mark = if ends == "both" { (start: "stealth", end: "stealth", ..m) } else if ends == "end" { (end: "stealth", ..m) } else { none }
line(..p, stroke: (paint: palette.ink, thickness: 0.8pt, dash: dash), mark: mark)
if label != none and at != none {
let body = text(size: small, fill: palette.ink, label)
content(at, anchor: side, box(fill: palette.paper, inset: (x: 2pt, y: 1.2pt),
if width != none { box(width: width * 1cm, align(center, body)) } else { body }))
}
}
/// A machine's edge, dashed, its name at its top left.
#let machine(x, y, w, ht, label) = {
import cetz.draw: *
rect((x, y), (x + w, y + ht), stroke: (paint: palette.rule, thickness: 0.9pt, dash: "dashed"), radius: 5pt)
content((x + 0.2, y + ht - 0.12), anchor: "north-west", text(size: small, style: "italic", fill: palette.tag-fg, label))
}
/// A canvas as a figure of either output: on paper unbreakable, in HTML an
/// inline SVG on the paper colour (class `diagram`, for site.css).
#let drawn(body, alt: "") = {
let canvas = {
// A figure's words are short labels: never justified, never hyphenated.
set par(justify: false)
set text(hyphenate: false)
cetz.canvas(length: 1cm, body)
}
context if html-out() {
html.elem("figure", attrs: (class: "diagram", role: "img", "aria-label": alt),
html.frame(block(fill: palette.paper, inset: 8pt, canvas)))
} else {
block(breakable: false, above: 1em, below: 1.2em, width: 100%, align(center, canvas))
}
}
// The truth and the screens, the same in every figure below.
#let core-truth = ("truth", [the core: *the truth*])
#let ptys = ("plain", [the shells' pty masters])
#let ninep(n) = ("plain", [the 9P socket #raw("pardes-9p-" + n + ".sock")])
#let daemon-box(x, y, ..extra) = proc(x, y, 3.4, 2.0, "daemon", "pardes --daemon",
("plain", [a dup of each pty master]), ("plain", [the list of sessions]), ..extra)
/// The legend: one of each mark the figures use.
#let run-legend() = drawn(alt: "legend: the four kinds of process, the core with the truth, a replica's core, a screen, a connection", {
import cetz.draw: *
let chip(x, kind, label) = {
let c = kinds.at(kind)
rect((x, 0.75), (x + 0.42, 1.17), fill: tint(c), stroke: 1.3pt + c, radius: 2pt)
content((x + 0.55, 0.96), anchor: "west", text(size: small, fill: c, weight: "bold", upper(label)))
}
chip(0, "session", "session")
chip(2.45, "client", "client")
chip(4.65, "daemon", "daemon")
chip(6.95, "stub", "stub")
content((9.0, 0.96), anchor: "west", box(width: 3.2cm, held("truth", [the truth])))
content((12.5, 0.96), anchor: "west", box(width: 3.3cm, held("replica", [a replica's core])))
screen(0, -0.55, 3.0, 0.85, [a terminal, a window])
wire((3.4, -0.12), (5.0, -0.12), ends: "both")
content((5.2, -0.12), anchor: "west", text(size: small)[what you type and see])
wire((8.1, -0.12), (9.9, -0.12), dash: "dashed")
content((10.1, -0.12), anchor: "west", text(size: small)[the processes' own errands])
})
/// `pardes` in a terminal.
#let run-terminal() = drawn(alt: "pardes in a terminal: a stub, the session it forked, the daemon, the shells", {
import cetz.draw: *
screen(0, 3.1, 3.2, 1.9, [your terminal])
proc(0, 0, 3.2, 2.0, "stub", "pardes",
("plain", [the job your shell waits on]), ("plain", [holds nothing else]))
proc(5.4, 1.0, 5.0, 4.0, "session", "pardes",
core-truth, ptys, ninep("<pid>"),
("plain", [draws on your terminal]),
("plain", [the stub's child, in a POSIX session of its own]))
daemon-box(12.6, 3.0)
shellbox(12.6, 1.05, "bash")
shellbox(14.3, 1.05, "make")
wire((3.2, 4.25), (5.4, 4.25), ends: "both", label: [keys in, \ frames out], at: (4.3, 4.72), width: 1.9)
wire((3.2, 1.4), (5.4, 1.4), ends: "both", dash: "dashed", label: [signals →\ ← it left, or ended], at: (4.3, 0.82), width: 2.0)
wire((1.6, 3.1), (1.6, 2.0), ends: none, dash: "dotted", label: [opened it], at: (2.4, 2.55))
wire((10.4, 4.25), (12.6, 4.25), ends: "both", dash: "dashed", label: [registered; \ a dup of each pty], at: (11.5, 4.82), width: 2.0)
wire((10.4, 1.36), (12.6, 1.36), ends: "both", label: [a pty's bytes], at: (11.5, 1.72))
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-gui`.
#let run-window() = drawn(alt: "pardes-gui: one session process that draws the window, the daemon, the shells", {
import cetz.draw: *
screen(0, 2.6, 3.2, 2.4, [a window])
content((1.6, 1.7), box(width: 3.1cm, align(center, text(size: small, fill: palette.tag-fg)[started from a terminal, it is that terminal's job])))
proc(5.4, 1.0, 5.0, 4.0, "session", "pardes-gui",
core-truth, ptys, ninep("<pid>"),
("plain", [draws the window (SDL, the GPU)]),
("plain", [no stub: it is the process you started]))
daemon-box(12.6, 3.0)
shellbox(12.6, 1.05, "bash")
shellbox(14.3, 1.05, "make")
wire((3.2, 4.0), (5.4, 4.0), ends: "both", label: [keys in, \ frames out], at: (4.3, 4.47), width: 1.9)
wire((10.4, 4.25), (12.6, 4.25), ends: "both", dash: "dashed", label: [registered; \ a dup of each pty], at: (11.5, 4.82), width: 2.0)
wire((10.4, 1.36), (12.6, 1.36), ends: "both", label: [a pty's bytes], at: (11.5, 1.72))
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 --detach=work &`.
#let run-detach() = drawn(alt: "pardes --detach: the session with nothing drawn, reached by 9P, registered with the daemon", {
import cetz.draw: *
screen(0, 3.1, 3.2, 1.9, [no terminal, no window: nothing drawn, 160×50 until something sizes it], none-there: true)
proc(0, 0, 3.2, 2.0, "other", "pardes fs read index -s work",
("plain", [a script, or a pane's `pardes FILE`: a 9P client]))
proc(5.4, 1.0, 5.0, 4.0, "session", "pardes --detach=work",
core-truth, ptys, ninep("work"),
("plain", [draws nothing]),
("plain", [the process you started: your shell's background job]))
daemon-box(12.6, 3.0)
shellbox(12.6, 1.05, "bash")
shellbox(14.3, 1.05, "make")
wire((3.2, 1.4), (5.4, 1.4), ends: "both", label: [9P], at: (4.3, 1.75))
wire((10.4, 4.25), (12.6, 4.25), ends: "both", dash: "dashed", label: [registered, \ detached], at: (11.5, 4.82), width: 2.0)
wire((10.4, 1.36), (12.6, 1.36), ends: "both", label: [a pty's bytes], at: (11.5, 1.72))
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`: 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",
core-truth, ptys, ninep("<pid>"), ("plain", [draws its own terminal]))
daemon-box(6.3, 3.4)
proc(11.2, 0, 4.8, 2.9, "client", "pardes attach work",
("replica", [the core: a replica]), ("plain", [its own view: columns, focus, cursors]),
("plain", [no shells, no 9P socket]), ("plain", [draws this terminal]))
screen(13.0, 3.4, 3.0, 1.7, [another terminal])
wire((1.5, 3.4), (1.5, 2.9), ends: "both", label: [keys in, frames out], at: (1.7, 3.15), side: "west")
wire((14.5, 3.4), (14.5, 2.9), ends: "both", label: [keys in, frames out], at: (14.3, 3.15), side: "east")
wire((12.0, 2.9), (12.0, 4.4), (9.7, 4.4), label: [① hello: the session's \ name, this build], at: (10.85, 4.88), width: 2.2)
wire((6.3, 4.4), (3.9, 4.4), (3.9, 2.9), dash: "dashed", label: [② its socket, \ handed on], at: (5.05, 4.9), width: 1.8)
wire((11.2, 1.75), (4.8, 1.75), label: [③ its keys and clicks], at: (8.0, 2.1))
wire((4.8, 0.85), (11.2, 0.85), label: [③ the tape: each step the session took; the terminals' screens], at: (8.0, 0.45), width: 6.2)
})
/// A far session: `pardes attach box:work`.
#let run-far() = drawn(alt: "a far session: a client here, ssh -L, and on the far machine the daemon and the session", {
import cetz.draw: *
machine(0, 0, 7.7, 5.6, [this machine])
machine(8.3, 0, 7.7, 5.6, [box, the far machine])
screen(0.3, 3.4, 2.8, 1.6, [your terminal])
proc(0.3, 0.3, 4.2, 2.7, "client", "pardes attach box:work",
("replica", [the core: a replica]), ("plain", [its own view]),
("plain", [the texts it was sent, kept on disk]))
proc(5.0, 0.7, 2.4, 1.6, "other", "ssh -L", ("plain", [a socket here, \ the far one there]))
daemon-box(8.6, 2.9)
proc(12.4, 0.3, 3.3, 2.7, "session", "pardes",
core-truth, ptys, ("plain", [its own frontend there, or none]))
wire((1.7, 3.4), (1.7, 3.0), ends: "both")
wire((4.5, 1.55), (5.0, 1.55), ends: "both")
wire((7.4, 2.0), (10.3, 2.0), (10.3, 2.9), label: [① hello], at: (9.0, 2.35))
wire((12.0, 4.1), (14.05, 4.1), (14.05, 3.0), dash: "dashed", label: [② handed on], at: (13.3, 4.45))
wire((7.4, 1.1), (12.4, 1.1), ends: "both", label: [③ the tape in zstd, \ texts by hash], at: (9.9, 0.6), width: 2.6)
})
/// No daemon: `PARDES_DAEMON=off`, or none could start.
#let run-no-daemon() = drawn(alt: "no daemon: one process, the session, with nothing to detach to", {
import cetz.draw: *
screen(0, 1.5, 3.0, 1.9, [your terminal, \ or its window])
proc(5.4, 0.3, 5.2, 3.1, "session", "pardes",
core-truth, ptys, ninep("<pid>"), ("plain", [draws on the terminal: the process you started]))
shellbox(12.2, 0.4, "bash")
shellbox(13.9, 0.4, "make")
rect((12.2, 1.7), (15.6, 3.4), stroke: (paint: truth, thickness: 0.9pt, dash: "dashed"), radius: 3pt)
content((13.9, 2.55), box(width: 3.2cm, align(center, text(size: small, fill: truth)[no daemon: Detach, Adopt and clients are refused])))
wire((3.0, 2.45), (5.4, 2.45), ends: "both", label: [keys in, \ frames out], at: (4.2, 2.95), width: 1.6)
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 ruling, built ----
/// 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 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))
rect((x, y), (x + 3.4, y + 0.95), fill: palette.paper, stroke: 0.8pt + palette.ink, radius: 2pt)
content((x + 1.7, y + 0.475), text(font: mono, size: 0.95 * small, typed))
line((x + 3.4, y + 0.475), (x + 3.9, y + 0.475), stroke: 0.8pt + palette.ink, mark: (end: "stealth", fill: palette.ink, scale: 0.6))
let c = kinds.at(kind)
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")[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")[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.]))
content((8.45, 1.1), anchor: "west", box(width: 7.5cm, text(size: small, fill: truth)[Gone: a terminal handed to a session, a window opened again in place, the daemon choosing which session takes a frontend, the stub of an attach.]))
})
|