summaryrefslogtreecommitdiff
path: root/docs/typ
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-19 20:40:15 -0300
committerGabriel Schneider <[email protected]>2026-11-19 20:54:39 -0300
commitb24f6a3ba68442259d28eb7de6e9debbc4607d58 (patch)
treeb3110ee5e65cc81ee14a711e968fb70ecffd1f0a /docs/typ
parent0db34fbf28e70c8c6a3c6025c0888fc5ec75201c (diff)
downloadpardes-b24f6a3ba68442259d28eb7de6e9debbc4607d58.tar.gz
pardes-b24f6a3ba68442259d28eb7de6e9debbc4607d58.zip
docs: the building chapter says the tree as it is (the reorganisation, 2026-11-17 to 19): the principle in the owner's words ("keep the wire protocol simple and raw, and the local state process it") and what follows from it in the tree today, its exceptions named (a joiner's dump, the digests, a terminal's screen state); the four directories and their modules; a frontend drawing from the Surface and Facts; the one session loop and the one client loop and what a frontend gives each, and the soak running both (zig build replicas, now in the test list); the tape: an entry written once (tape.taped), the tape as the handle a step is given as far as it has gone (p.tape; tape.on still beside it), Pane.Id and View.Id, the session's facts; what may wait (keeps_stopping, may_wait and the walk that pins them); the three checks at the end of core/root.zig and draw.zig's frame test; the patches to dependencies (build/patches.zig, docs/mvzr-*.md); and what was false: Zig 0.17.0 (0.17.1), host_io.Host, the root module by platform, src/Terminal.zig, abi/wire.zig as a wire to come, host_io.Lsp.Job, "shells" for frontends; the cheatsheet, the book and the site build (zig build cheatsheet, book, site, -Dplatform=tui, to a scratch prefix), core-test's drift test (docs/typ names only words, keys and default tags that exist) passes, and every path, identifier and line cited in the added lines exists on pardes-merge22 (the checker in .scratch/sketch/reorg/pardes-docs-arch/check.py: 454 ok, 0 bad); no code changed, so the suites and the corpus were not run
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'docs/typ')
-rw-r--r--docs/typ/building.typ229
1 files changed, 203 insertions, 26 deletions
diff --git a/docs/typ/building.typ b/docs/typ/building.typ
index 5273298e..9350b484 100644
--- a/docs/typ/building.typ
+++ b/docs/typ/building.typ
@@ -1,7 +1,8 @@
-// Building pardes, for contributors: platforms, options, the library, tests,
-// the release gates and sending patches, then how the pieces fit: the core
-// and its shells, the threads, the daemon and its sessions, the 9P engine, the
-// listeners and mounts.
+// Building pardes, for contributors: platforms, options, the patches to
+// dependencies, the library, tests, the release gates and sending patches,
+// then how the pieces fit: the principle, the tree, the core and its
+// frontends, the loops, the tape, the checks, the threads, the daemon and its
+// sessions, the 9P engine, the listeners and mounts.
#import "style.typ": key, keys, btn, chord, word, tag, addr, file, cmd, doc, pairs
For contributors: how pardes is built, tested and released, and how its
@@ -9,7 +10,7 @@ pieces fit. To install it, see #doc("setup", section: "install").
= Platforms
-Zig *0.17.0* (`build.zig.zon` pins `minimum_zig_version`). Dependencies are
+Zig *0.17.1* (`build.zig.zon` pins `minimum_zig_version`). Dependencies are
fetched and pinned by the manifest; the terminal build needs no system
package. The SDL shell builds SDL3 and FreeType from source. Pictures and
PDFs are addons, each its own step: `zig build image`, `zig build pdf`
@@ -73,6 +74,22 @@ must share with its session; `pardes --help` lists every flag.
[`-Dhelix-harness`], [reference executable for live differential tests; `HX_HARNESS`, else `hx-harness` on `PATH`],
)
+== Patches to dependencies <dep-patches>
+
+A fault in a dependency is fixed in the dependency, never guarded in the
+core. pardes builds a few with edits of its own, made as each is fetched:
+`build/patches.zig` holds, for each patched file, a table of exact edits
+(and a file to append, in `build/patches/`), which `tools/patch.zig`
+applies at make time, so a fresh fetch is patched the same and a bump that
+moves an anchor fails that file's step. Each table says why, edit by edit.
+
+#pairs(
+ [vaxis], [its input parser (no reply, split read or malformed sequence reaches the editor as typed text), its event queue (every blocked writer woken) and its render (a blank whose ink alone changed is not sent)],
+ [zstbi], [stb_image and its writer cut out: its resize alone is left, for a terminal PNG's downscale],
+ [ghostty], [kitty graphics: a path opened only once it is a regular file, shared memory non-blocking, an image no larger than a screen's storage],
+ [mvzr], [a step budget, a group's backtracking, `$` before `|`, the `**` Zig 0.17 removed, a class's range to `\xff`, and its reads past a pattern cut short; `docs/mvzr-group-backtrack.md` and `docs/mvzr-bounds.md` are the reports for upstream],
+)
+
== As a library <library>
A Zig package that depends on pardes is given one module and nothing of
@@ -174,6 +191,9 @@ zig build lib-test the library, from a package that depends on pardes (t
zig build hxlib helix's cases on the library's editor (-- --parity: against the file pane)
zig build behaviour-test behaviour through the 9P tree, in process (test/behaviour/),
and the T1 runner's short run of random 9P requests
+zig build replicas the soak: a session and clients in process, on the real
+ session and client loops, each client typing over a
+ delayed link (-- [--seeds N] [--clients C] [--rtt 30,80,207])
zig build process-test real sessions over their sockets: mounts, flags, shells (test/process/),
and the tty's own cases, each a pardes in a pty against its golden
(test/process/tty_*.zig, test/snapshots/); -Dplatform=gui runs the
@@ -251,12 +271,60 @@ Mail patches to the list `~gbrls/[email protected]`; it is the preferred way to
#link("https://git-send-email.io")[git-send-email.io] sets `git send-email` up. The mirrors (#doc("setup", section: "install")) are for cloning, as a GitHub one will be; pull requests are not the preferred route.
-= The core and its shells
+= The principle <principle>
+
+The owner's rule, in their words: "keep the wire protocol simple and raw,
+and the local state process it" (2026-11-19). Every design choice is
+measured against it.
+
+What crosses between processes is raw and ordered: a client's keys and
+gestures, and the session's steps, each with what the session's machine
+answered inside it (a file's bytes, the clock, a directory's listing) as
+the machine said it. Each process's own core turns them into state. Nothing
+computed is shipped where the input that computes it can be, and bandwidth
+is spent before correctness is. What follows from it in the tree today:
+
+- A client is a whole core, loaded once from the session's dump. It applies
+ its own input at once and replays the session's units over it, rolling
+ back where the session ordered otherwise; nothing it draws is sent to it.
+ A picture or a game is drawn by the process that shows it, from its own
+ addon's code.
+- A step that asks the machine asks through the tape (#link(<tape>)[below]):
+ the session records the answer, a client's replay reads that answer and
+ not its own machine's. The session's home, shell and directory are state
+ of the core for the same reason.
+- What may wait is what touches the session's machine; the lists that say
+ so are checked by a test (#link(<may-wait>)[below]).
+- Nothing a frame writes is read by a step, and nothing of a core is a
+ process global, so a core that drew and one that did not, in this process
+ or another, step alike (#link(<core-checks>)[the checks]).
+- The exceptions, each small and named: the dump a client joins from (it
+ cannot replay from the start); the digests and quiet checks (a check, not
+ state); and a terminal, which crosses as the session's screen state
+ (rows and their changes), not as the pty's bytes.
+
+= The tree <tree>
+
+#pairs(
+ [`core/`], [the editor as a state machine: panes, layout, the frame, the 9P tree, the tape and the replica engine. Module `core`, rooted at `core/root.zig`; the core's struct is `core/Core.zig`, `pardes.Pardes`],
+ [`dev/`], [the devices: the frontends (`dev/tui`, `dev/gui`, the Mac app's Swift in `dev/macos`), the host's services (`dev/host_io.zig` and the files beside it: `Host`, `Shell`, `Inbox`, `KindJob`, `Lsp`), the file watcher, the fonts, the language servers' client. Module `dev`],
+ [`runtime/`], [what runs a session: a session's loop (`session.zig`) and a client's (`client.zig`), the daemon and the stub, the upgrade, the crash file, the 9P listener and client (`9p_io.zig`). Module `runtime`; beside it each product's root, a module of its own: `runtime/main.zig` (`pardes`, `pardes-gui`) and `runtime/macos.zig` (the Mac's library)],
+ [`abi/`], [what crosses a process or a language: the replica stream (`abi/wire.zig`, module `wire`), the records the core and the terminal share (`plain.zig`), the terminal's table (`term.zig`), the addon's header and module, `pardes.h`],
+)
+
+The modules name each other. A Zig test program runs the tests of the
+module it is rooted at, so `core-test` and `shell-test` run one program a
+module (core, dev, runtime, wire, and for `shell-test` `runtime/main.zig`'s);
+each module's `root.zig` lists the files whose tests it runs. Beside the
+four: `addons/`, `build/` (the build script's parts, the patches), `test/`,
+`tools/`, `shaders/`, `vendor/`, `assets/` and `docs/`.
+
+= The core and its frontends
-One core, three shells (tui, gui, macos). The core owns
-editing, layout, rendering and the virtual filesystem it serves over 9P; a shell turns native
-input into `pardes.Event`, presents `pardes.Surface`, and performs host
-effects such as spawning processes.
+One core, three frontends (tui, gui, macos). The core owns
+editing, layout, rendering and the virtual filesystem it serves over 9P; a
+frontend turns native input into `pardes.Event`, presents `pardes.Surface`,
+and its host performs effects such as spawning processes.
- The core is a state machine: input arrives as an `Event` through
`update`; output leaves as a `Surface` from `render(arena)` and as a ring
@@ -271,13 +339,21 @@ effects such as spawning processes.
- `pump` runs: wait for input (the host owns the sleep), flush paused 9P
write batches, drain queued events, drain effects, settle the turn, then
render and present only when a frame is needed and someone is looking.
-- `host_io.Host` is a context pointer and a vtable of optional callbacks; a
- null method is not an error, and `Host{}` is a complete in-process pardes
- that the tests use. Comptime decides what a build has (`pardes.platform`,
- `can_attach`); the vtable
- decides who serves it.
-- The root module is chosen by platform: `main.zig` (tui, gui),
- `macos.zig`. The macOS shell is a library whose host owns `main()`.
+- `Host` (`dev/Host.zig`) is a context pointer and a table of optional
+ callbacks; a null method is not an error, and `Host{}` is a complete
+ in-process pardes that the tests use. Comptime decides what a build has
+ (`pardes.platform`, `can_attach`); the table decides who serves it.
+- The terminal and the window draw from the frame alone: the `Surface`
+ (cells, regions, layers, placements, cursor, `Chrome`) and one record
+ beside it, `Facts` (`core/surface.zig`: the view's size, each open
+ pane's rectangle, tag rows and kind, the settings a frontend draws by),
+ which `draw.place` fills with the frame. Each reads these, not the core,
+ to draw and to turn its input into events, so a client draws its own
+ view with no view of the core made live. A few reads of the core remain, in the window: its
+ hit test, its close and a session window's font.
+- The macOS build is a library whose Swift app owns `main()` and the run
+ loop (`runtime/macos.zig`); it reads the core beyond the frame (its
+ theme, a pane's document state) and runs neither loop below.
- The terminal is a module of its own, `term` (`core/term/`): the
emulator (ghostty-vt), kitty images (wuffs, zstbi), the pager's parse
and the replicas' screen state. It never imports the core; the core
@@ -292,14 +368,115 @@ effects such as spawning processes.
safe, its checks in Debug builds only.
Code map: `core/panes.zig` and the pane kinds it names (`core/File.zig`,
-`src/Terminal.zig`, ...), `core/layout.zig`, `core/fs.zig` (host access,
-mounts and resolution) and `core/root.zig` (input), with one file per
-thing beside them (`edit.zig`, `normal.zig`, `look.zig`, `exec.zig`,
-`mouse.zig`, ...). `core/ninep/` is the control tree, `runtime/daemon.zig` the
-per-user daemon and a terminal's stub, `abi/wire.zig` the input
-wire a remote client will speak, `core/lsp/` the
-language-server client; `test/` holds harnesses, goldens and helix cases,
-`build/` the process tests' build steps.
+`core/Term.zig`, `core/Kind.zig`, ...), `core/layout.zig`, `core/fs.zig`
+(host access, mounts and resolution), `core/Core.zig` (the core's state
+and its entries) and `core/draw.zig` (the frame), with one file per thing
+beside them (`edit.zig`, `normal.zig`, `look.zig`, `exec.zig`,
+`mouse.zig`, ...). `core/ninep/` is the control tree, `core/tape.zig` the
+tape, `core/replica.zig` the replica engine (a client's `Replica` and
+`Link`, a session's `Peers`), `runtime/daemon.zig` the per-user daemon and
+a terminal's stub, `abi/wire.zig` the replica stream's frames, `core/lsp/`
+the language-server client; `test/` holds harnesses, goldens and helix
+cases, `build/` the build script's parts.
+
+== The loops <loops>
+
+A session runs `runtime/session.zig`'s `Loop`, a client
+`runtime/client.zig`'s, each over the frontend it is given (comptime: no
+vtable). The terminal's and the window's own frontend (`Own` in each) and
+their client frontends (`Tty`, the window's `Client`) give the calls;
+what a loop holds and its order are written once.
+
+- The session's loop holds its allocators and workers, its core (new,
+ from a dump, or an Upgrade's), the prompt files its shells start with,
+ the 9P listener and its clients (`Peers`). A turn is a `pump`, the step's
+ unit to the clients (`Peers.boundary`), the frontend's `sent`, an
+ Upgrade or a Restore between steps, and the daemon's notes. Its parts end
+ in one order: the listener, the clients, the frontend's devices, the
+ prompt files, the core, the workers, the allocators. The devices (ptys,
+ their readers, watched files, the jobs, the queue they post to) are
+ still each frontend's (`open`, `start`, `close`).
+- A client's loop holds what it keeps across joins (`client.Start`: its
+ allocators, the addons it distrusts, its frame timings, the blobs it
+ keeps when far) and runs its joins: the reader thread, a pass at a time,
+ and a join again after a divergence or an Upgrade. A pass: the
+ frontend's own work (`own`), the predicted echo's frame, a draw or the
+ frontend's own motion (`again`), the wait (`deadline`, `wait`), then the
+ session's units settled, and a yank, paste or link its view asked for
+ done on this machine (`copy`, `paste`, `open`). An input is sent to the
+ session before it is applied here.
+- The soak, `zig build replicas` (`test/replicas.zig`), runs both: its
+ session is `session.Loop` over a frontend whose host is the soak's
+ delayed network, every client a `client.Loop`, so what it tests is what
+ a session and a client run. The core's own unit tests stand a session in
+ with `replica.Authority`.
+
+== The tape <tape>
+
+The tape (`core/tape.zig`) records what a step takes in: the entry a host
+called and its arguments, and every answer of the machine inside the step.
+A session records its steps; a client replays the session's and records
+its own speculations, to compare.
+
+- An entry is written once: a private body and, directly under it, its
+ public name made by `tape.taped`
+ (`pub const update = pardes.tape.taped(updateInner);`); the tape's
+ `Input` variant and the replay come from the body's parameters. The few
+ written by hand (`init`, `deinit`, `pump`, `render`, ...) each say why.
+- The tape is the handle a step is given, as an allocator is: a core
+ holds it (`p.tape`, never null), and a function handed no core takes
+ `tape: *Tape`. A step's question of the machine goes through it
+ (`p.tape.value`, `p.tape.site`, `p.tape.authorityOnly`): the session
+ records the answer, a replay reads it. So far the kinds and addons, a
+ directory's listing, the file system, the core's own files and the
+ smaller ones ask it so; beside the field, the process's `tape.on` still
+ says which core is being stepped.
+- A pane's and a view's slot are types where they cross the core's edge
+ (an entry's argument or answer, an event, an effect, a host call, the
+ wire's welcome): `Pane.Id` and `View.Id`, each an `enum(u8)` of its own.
+ The core's own loops keep their integers.
+- The session's facts, its home, default shell and directory, are the
+ core's state (`session_home`, `session_shell`, `session_dir`), read once
+ at its start through the tape and carried in its dump: a far client's
+ `~`, #word("Shell") and a word run in the session's directory are the
+ session's.
+
+== What may wait <may-wait>
+
+A client applies its own input at once; a step that needs the session's
+machine stops its speculation, and the input waits a round trip for the
+session's unit (`tape.hostCall`). The user's line: motions, edits and
+layout are instant; what has a side effect on the system may wait. Two
+lists say which, each row with why:
+
+- `keeps_stopping` (`core/tape.zig`): the Host entries that return nothing
+ and still stop a speculation (`pty_write`, `spawn`, `write_file`, ...).
+ A client records any other such call as made and goes on; an entry that
+ answers stops by nature, the answer being the session's.
+- `may_wait` (`core/replica.zig`): each word, key or gesture that may wait,
+ on a kind of pane, and where it stops. A test walks every word of the
+ registry, every key (and every key after each prefix) and the gestures
+ between panes, on a file's, a kind's and a shell's pane: a stop not
+ listed fails it, and a row nothing stopped at is stale. The soak judges
+ its stops by name against the same list.
+
+== The checks <core-checks>
+
+At the end of `core/root.zig`, run by `core-test`, `shell-test` and
+`unit-test`:
+
+- *No process globals:* every container-level `var` in `core/` is on
+ `allowed_vars`, with why it is not a core's.
+- *What the core asks of the machine:* every line of `core/` naming libc,
+ `std.posix`, `getenv`, a `std.Io` file, directory or socket, `dev` or
+ `runtime` is counted, a file at a time, against `machine_lines`, with why.
+- *What is kept out of the digest:* every field kept out of the digest and
+ the dump (`.local`, `.derived`) is on `kept_out`, with who writes it and
+ why a step's read of it is the step's.
+
+Beside them, `core/draw.zig`'s test "a frame changes nothing a step reads"
+steps a core that draws after every input and one that never draws, and
+their digests agree after every step.
== Threads
@@ -311,7 +488,7 @@ would change a pane parks (`Status.again`) and is retried when the editor
rests. 9P requests are not events: they enter through `Pardes.serveFs`, and
only one that changes a pane costs a frame. Language-server and
selection-pipe workers post completions through a bounded mailbox; a
-`host_io.Lsp.Job` owns copies of the source, path and arguments, never
+`Lsp.Job` (`dev/Lsp.zig`) owns copies of the source, path and arguments, never
reading the live core, and a request id, the pane's serial and (for an
edit) the file's revision reject a stale reply. A process that never calls
`turn.start` (the tests) has no second thread.