summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/next-plumber.md925
-rw-r--r--docs/next-terminal.md374
-rw-r--r--docs/render-pipeline.md2
-rw-r--r--docs/typ/building.typ16
-rw-r--r--docs/typ/builtins-gui.json4
-rw-r--r--docs/typ/builtins-tui.json4
-rw-r--r--docs/typ/cheatsheet.typ2
-rw-r--r--docs/typ/guide.typ2
-rw-r--r--docs/typ/reference.typ93
-rw-r--r--docs/typ/themes.typ2
10 files changed, 1413 insertions, 11 deletions
diff --git a/docs/next-plumber.md b/docs/next-plumber.md
new file mode 100644
index 00000000..178814b3
--- /dev/null
+++ b/docs/next-plumber.md
@@ -0,0 +1,925 @@
+# The plumber in pardes's core: the design record
+
+> it's really about time to write the acme plumber, it's a real part of the
+> core that we're missing. You may use its code at principia softwarica as a
+> reference.
+
+Said 2026-11-16, while ruling on the diff viewer ("Keep the diff compiled in
+and do the changes that it asks for pardes as a library"). The diff survey
+had found three diff decisions hard-coded in Look and the pager that are
+plumbing with no general form, because pardes's `Plumb` word has no
+`matches` test and cannot start anything (.scratch/sketch/reports/diff-module.md
+§3 row 12, §5 M3). The coordinator's ruling: the three hooks become default
+plumbing rules when the plumber lands (PLAN.md §7 Dv).
+
+This is round 1 of a design discussion. It is written to be committed as
+`docs/next-plumber.md`, and an implementation agent follows it. Nothing was
+built or run: every number below is a count from reading or an estimate. Plan
+9 paths are under `~/05-genizah/principia-softwarica` unless they say
+`plan9port/` (`~/05-genizah/plan9port`). pardes paths are the working copy,
+including the user's uncommitted edits.
+
+## 0. Summary
+
+- **What Plan 9's plumber is.** A small language-driven file server. A message
+ is six header lines (src, dst, wdir, type, attr, ndata) and then the data. The
+ rules are blank-line-separated rule sets of `object verb args` lines, and the
+ first rule set whose patterns all hold takes the message. Its actions are
+ `plumb to <port>`, `plumb start <cmd>` and `plumb client <cmd>`. The files are
+ `send`, `rules` and one file per port.
+- **What acme does with it.** acme asks the plumber first. A write that fails
+ means no rule matched, and acme then does its own look, which opens a file or
+ searches for the word (plan9port acme/look.c:147-223). acme reads the `edit`
+ port itself: it opens a file at an `addr`, or shows the data when
+ `action=showdata` (acme.c:556-564).
+- **What pardes has.** A one-line `Plumb` word with four tests and three ports
+ (look.zig:155-261). Its rules sit in the middle of `resolve`, which also
+ hard-codes four other decisions:
+ - http(s) URLs (look.zig:263-265, :1601);
+ - a bare `.diff`/`.patch` stacked in a +Diff (:1622-1633);
+ - a commit hash run through `git show` (:1092, :1118-1143);
+ - a diff paged into a +Pager restacked (ninep/ctl.zig:721-731).
+
+ No user rule exists today: the user's init has no `Plumb` line. Two tests pin
+ the word: look.zig:2688 and test/behaviour/addons.zig:188.
+- **The design.**
+ - `src/Plumb.zig` owns the rules as text, which is replicated and dumped core
+ state, plus the ports this session has named.
+ - Its matcher is a pure function of the rules and a message. The exceptions
+ are `isfile`/`isdir`, which resolve a name exactly as Look does, through
+ taped `.resolve` sites.
+ - `matches` uses mvzr through regexp.zig, with no engine work. The price is
+ `$0` but no `$1`–`$9`, because mvzr has no capture groups.
+ - pardes reads three kinds of port itself, as acme reads `edit`: `edit` (Look's
+ open), `web` (the host's link opener) and every loaded kind by its name.
+ Other ports are 9P files that external programs read, with the tree's held
+ reads.
+ - `plumb start` runs the expanded line as pardes's exec runs a line from the
+ message's pane, so a builtin such as `Diff $file` runs in place.
+ - The files are `plumb/send`, `plumb/rules` and `plumb/<port>`, in Plan 9's
+ text form and with Plan 9's error words.
+- **Look after it.** The pane-context readings stay first: History, Recent, a
+ diff line, a command word, `file:/re/`, and a name already open in a pane.
+ Then the plumber runs. If it takes nothing, pardes's own look runs on the
+ target it already resolved. The default rule file (§5.2) reproduces today's
+ behaviour, and the three diff hooks and the URL become rules. `Diff` gains an
+ argument (a file or a revision) and a way to decline silently, which is what
+ keeps the fallback byte-identical.
+- **Size.** About 600 lines of new code and 400 lines of tests. look.zig loses
+ about 150 lines.
+- **Phases.**
+ 1. The language and the files.
+ 2. Look sends to the plumber.
+ 3. External ports.
+ 4. The pager as a sender.
+
+ Deferred: the click attribute, the hover asking the matcher, and
+ `pardes plumb`.
+- **Four taste questions** (§8):
+ 1. submatches;
+ 2. whether an open pane comes before the rules;
+ 3. the `Plumb` word's form;
+ 4. whether `start` of a program is a command pane or detached.
+
+## 1. What Plan 9's plumber is
+
+### 1.1 The message
+
+- **Six lines of header, then the data.** The lines are src, dst, wdir, type,
+ attr and ndata, followed by ndata bytes of data with no terminating newline
+ (include/ipc/plumb.h:5-28; plumb.ms:223-263).
+ - Any header line may be empty except ndata.
+ - Only `type=text` is supported (plumb(6), ROOT/docs/man/6/plumb:49-59).
+- **attr** is `name=value` pairs separated by blanks.
+ - A value holding a blank, a quote, `=` or a tab is quoted rc-style: `'…'`,
+ with `''` for a quote (libplumb/mesg.c:76-103 quote, :260-338
+ plumbunpackattr).
+ - A value cannot hold a newline.
+- **Packing and unpacking** are plumbpack (mesg.c:157-193) and
+ plumbunpackpartial (:382-432).
+ - Unpacking tells "not yet complete" (`*morep` bytes still to come) apart from
+ "malformed".
+ - That is how the plumber assembles a message written in pieces
+ (fsys.c:858-887).
+
+### 1.2 The rules language
+
+Taken from rules.c and match.c, which are authoritative where the man page
+differs.
+
+- **Lines.**
+ - `#` starts a comment, which counts as a blank line.
+ - A blank line ends a rule set.
+ - `include file` substitutes a file: an absolute path, `./` or `../`, else the
+ plumber's directory, then `/lib/plumb` (principia patched this from
+ `/sys/lib/plumb`). It is limited to depth 10 (rules.c:89-112, :398-432).
+ - `name=value` defines a variable, one per line (:376-396).
+- **A rule line** is `object verb arg…`.
+ - The objects are `arg attr data dst plumb src type wdir`. `kind` is an old
+ spelling of `type` (rules.c:46-57, :474-480).
+ - The verbs are `add client delete is isdir isfile matches set start to`
+ (:59-72).
+- **Parse checks** (rules.c:348-374, :531-613):
+ - `plumb` takes only `to`, `start` and `client`, and only `plumb` takes them.
+ - `add` and `delete` take only `attr`.
+ - A rule set needs patterns and actions, with at most one `start` or `client`
+ and at most one `to`.
+ - A rule set of nothing but `plumb to X` lines declares ports.
+ - The port names `.`, `..` and `send` are illegal.
+- **Arguments are expanded twice.**
+ - At parse time, with the variables only (`qarg`). A `matches` regex is
+ compiled then, so `'$addr'` in a pattern is the macro (rules.c:351, :364-366).
+ - At match time, with the message's variables too.
+ - Expansion is rc quoting: `'…'` is literal, `''` is a quote, and `$` outside
+ quotes is a variable (rules.c:294-336).
+- **The variables** (rules.c:249-292):
+ - `$0`–`$9`: the last `data matches` and its parenthesised submatches;
+ - `$src`, `$dst`, `$type`, `$wdir`, `$data`;
+ - `$attr`: the packed attributes;
+ - `$file` and `$dir`: what `isfile`/`isdir` found. Without one they are data
+ joined to wdir (filename, :228-247).
+ - An unknown `$x` stays as written (:322-325).
+- **Patterns run in order, and a rewrite is permanent even if a later pattern
+ fails** (plumb(6) :140-145; match.c:366-386 mutates the message in place).
+- **Each verb:**
+ - `is`: string equality on data, dst, type, wdir or src (match.c:17-36).
+ - `isfile`/`isdir`: the expanded arg (or data, or wdir) is made absolute in
+ wdir and cleaned (not realpath'd), then stat'd. Success sets `$file`/`$dir`
+ (match.c:131-189, absolute :149-159).
+ - `set`: replaces data, dst, type, wdir or src. A `data set` clears the click
+ span (:191-231).
+ - `add`: appends attributes (:233-245).
+ - `delete`: removes an attribute. **The code fails the pattern when the
+ attribute is absent** (:247-264). The man page says it matches anyway
+ (plumb(6) :155-161). pardes follows the code.
+- **`matches`** (match.c:75-129):
+ - Without a `click` attribute, the regex must match the **whole** object
+ (:119-126).
+ - With `click=N` on data, the plumber tries the regex from each offset 0..N.
+ The first match that contains offset N wins, where N counts runes
+ (clickmatch, :55-73).
+ - Every `data matches` in the rule set must then match that same span
+ (:99-100). The data is cut to that span and the click attribute removed when
+ the set matches (rewrite, :318-344).
+ - This is Pike's two-patterns trick: one pattern finds the run of file
+ characters, the next checks its suffix, so `horse.gift` is no `.gif`
+ (plumb.ms:444-514).
+ - Plan 9's regexp is leftmost-longest (plumb.ms:481).
+- **First match wins**, then dispose (fsys.c:892-902):
+ - A message that names a dst only tries rule sets whose `to` names that port
+ (match.c:372-373). A set without `to` still tries.
+ - A matching set with `to` sets dst when dst was empty (:380-383).
+ - No set matches: a message that names a dst goes there unchanged. Anything
+ else is the write error `no matching plumb rule`.
+- **Dispose** (fsys.c:524-556, startup match.c:438-463):
+ - dst empty: run the `start`/`client` command, or fail `couldn't find
+ destination for message`.
+ - dst is a port with readers: queue the message to each of them (fan-out).
+ - dst is a port with no reader: run `start`, which discards the message, or
+ `client`, which holds it until the port is opened. Otherwise fail `no start
+ action for plumb message`.
+- **`start` and `client`** split the expanded arguments into argv and **exec
+ them directly, with no shell**, stdin `/dev/null`, falling back to `/bin/x`
+ (match.c:346-364, :419-436). Rules that need a pipe say `rc -c '…'`
+ (ROOT/lib/plumb/basic:13, :95). The man page's "a shell program" (plumb(6)
+ :254-260) is loose.
+
+### 1.3 The files
+
+- **The directory** is `rules` (0600), `send` (0200) and one file per port
+ (0400), each port created the first time a rule names it. Ports are never
+ deleted (fsys.c:94-99, :161-182; plumber(4) :85-101). At most 50 entries
+ (NDIR).
+- **`send`**: a write is a message, assembled across writes (fsys.c:858-887). It
+ is answered once the message is matched and queued, so the sender never
+ waits on the reader (plumb.ms:724-760). An error comes back as the write's
+ error string.
+- **A port**: opening it makes the opener a reader. A message goes to every fid
+ open when it was sent (queuesend, fsys.c:337-362).
+ - A read blocks until a message arrives, and a message may take several reads
+ (drainqueue, :377-436).
+ - A flush cancels a held read (:439-459).
+ - A clunk drops what that fid had not read (:462-491).
+ - Messages held for a `client` go to the first opener (queueheld on open,
+ :510-522, :754).
+- **`rules`**:
+ - A read gives the parsed rules printed back: variables, port declarations,
+ then each set as `obj\tverb\targ` (printrules, rules.c:695-710).
+ - A write appends. Complete rule sets, as judged by a blank line, are parsed
+ at each write and the rest at close, and a parse error is that write's
+ error (morerules :722-760, writerules :762-784, fsysclunk :943-952).
+ - An `OTRUNC` open clears the rules (fsys.c:707-711, :742-745). There is one
+ writer at a time (`file already open`, :732-741).
+- **Startup.** The plumber reads `$home/lib/plumbing` (plumber.c:60-72), which is
+ usually just `include basic` (ROOT/usr/pad/lib/plumbing; plan9port
+ plumb/initial.plumbing: `editor = acme`, `include basic`).
+
+### 1.4 What acme does around it
+
+Read in plan9port's acme (principia's acme predates the plumber's use).
+
+- **A pane with an event reader comes first.** The look goes to that reader as
+ an `l`/`L` event and is never plumbed (look.c:98-146).
+- **Otherwise acme sends a message** (look.c:147-195):
+ - src is `acme`;
+ - wdir is the window's directory, or acme's own (:152-162);
+ - type is `text`;
+ - the data is the selection when there is one. With no selection it is the
+ whitespace-delimited word around the click, plus `click=<offset>`
+ (:166-182).
+ - A write that succeeds ends the look. A failed write (no rule matched) falls
+ through (:189-194).
+- **acme's own look** opens a file or address (openfile, which also handles
+ directories and acme's `includename` search) or searches the window for the
+ word (:197-223).
+- **acme reads the `edit` port** (plumbthread, look.c:25-72, which reconnects to
+ a restarted plumber). It acts on a message by its `action` attribute
+ (acme.c:556-564):
+ - none or `showfile`: open the file at the message's `addr` attribute
+ (plumblook, look.c:241-271);
+ - `showdata`: a new window holding the data, named by the `filename`
+ attribute or `Untitled-N`, and clean (plumbshow, :273-311).
+
+ `plumb -i` adds `action=showdata` (plumb(1) :69-77). That is how the stock
+ rules show `man` output and `doc2txt` output in the editor (plumb.ms:993-1033;
+ plan9port plumb/basic:139-142).
+- **Plan 9's own limit**: the language cannot look inside files, only at names
+ (plumb.ms:1298-1314).
+
+## 2. What pardes has today, measured
+
+### 2.1 The `Plumb` word
+
+- **Builtin**: builtins.zig:941-978, with session scope. It takes one line,
+ `<test> [word…] to <port>`, checked by look.plumbRuleError (look.zig:160-186).
+- **Tests**: `prefix` (the text starts so), `suffix` (an existing file's
+ resolved path ends so, in any case), `isdir`, `isfile`.
+- **Ports**: `url`, `dir`, `file` or a loaded kind's name (look.zig:158). A port
+ naming a kind that is not loaded is refused.
+- **Forms**: bare lists the rules on the message row; `Plumb -` empties them.
+- **State**: the field `Core.plumb: ArrayList([]u8)` (Core.zig:211-213), which
+ is digested and dumped (it is not in `replica`'s lists, Core.zig:401-418).
+- **Matching**: inside `resolve` (look.zig:227-261). The user's rules come after
+ an `@p` pane address (:214-225) and after resolveLookTarget's open-pane check
+ (:881, :894-897), and before the URL test and the disk.
+- **Who uses it.**
+ - The user's init: none (grep of ~/.config/pardes/init).
+ - Tests: look.zig:2688-2735, and test/behaviour/addons.zig:188-209 (a rule to
+ the image kind).
+ - Docs: reference.typ:1355, guide.typ:177.
+
+### 2.2 Everything Look decides, and which of it is plumbing
+
+lookAt (look.zig:1493-1688) runs these steps in order. The last column says what
+each step is in acme's terms.
+
+| # | decision | code | in acme |
+|---|---|---|---|
+| 1 | a +History row restores a dump | look.zig:1507-1512 | the window's own (an event reader's): **not plumbing** |
+| 2 | a +Recent/+Jumplist row reopens, clamped | :1515-1520 | the window's own: not plumbing |
+| 3 | a whole diff line written over 9P is its address | :1524-1527 (diffLineAddress :1423) | the window's own rows (M4's row address): not plumbing |
+| 4 | a `` @`…` `` command word executes | :1528-1531 | exec: not plumbing |
+| 5 | `~`, `<x>` and a trailing `:` | :1500-1502, :1536-1540 | the sender's expansion (acme's `expand`) |
+| 6 | `file:3:0` refused | :1546 | address syntax: not plumbing |
+| 7 | `file:/re/`, `:addr` | :1547 (addressed :1028; lookAddress :1148) | plumbing in Plan 9 (fileaddr's `$addr`), but evaluated by the editor; stays here (see §5.1) |
+| 8 | `:N` in a kind's pane | :1550-1551 | the window's own |
+| 9 | an `@p<serial>` address | resolve :214-225 | pardes's names: not plumbing |
+| 10 | a name open in a pane, first by path, then joined to each candidate directory | resolveLookTarget :881, :894-897 | acme's `lookfile` inside openfile, after the plumber |
+| 11 | the user's Plumb rules | resolve :227-261 | **plumbing** |
+| 12 | http(s):// opens the browser | resolve :263-265; lookAt :1601 (emits `open_link`, Effect.zig:48, :131-134; the hosts' `look.openLink`, look.zig:39-54, double-fork xdg-open or `open`) | **plumbing** (`plumb to web`, plan9port plumb/basic:18-22) |
+| 13 | a name found in the pane's directory, then the jump list's directories, then Incl's | resolveLookTarget :877-911; fs.resolve fs.zig:341-381 (taped `.resolve`, fs.zig:436-446) | acme's openfile plus includename (its own look) |
+| 14 | a directory opens a listing pane | resolve :268; lookAt :1602-1611 | acme's openfile, not the plumber |
+| 15 | a kind's extension opens that kind | resolve :269; lookAt :1654-1686 | **plumbing** in Plan 9 (`plumb to image`); in pardes, the editor choosing the kind of pane |
+| 16 | a file opens at its line and column | lookAt :1612-1653 | the `edit` port (plumblook) |
+| 17 | **a bare `.diff`/`.patch` opens as a +Diff** | :1622-1633 | **plumbing** |
+| 18 | a `./` name that is not there is a miss | lookUnresolved :1078-1087 | acme's own |
+| 19 | no search in a raw terminal or a kind's pane | :1090 | the window's own |
+| 20 | **a commit hash in a git work tree runs `git show` paged** | :1092, lookCommit :1118-1131, isCommitHash :1133-1143; command_pages panes.zig:173-175, :704-707 | **plumbing** |
+| 21 | a word is searched in its pane, or in a +Search | lookWord :1011-1023; :1093-1110 | acme's search: **not plumbing** |
+| 22 | **a diff paged into a +Pager is restacked** | ninep/ctl.zig:721-731; the sniff File.zig:752 | `plumb -i … action=showdata` arriving at the editor: **plumbing** |
+
+The hover, the n/N walk and lineSpan ask `resolve` what is lookable (look.zig:133-153,
+:622-632). acme underlines nothing, so that is not plumbing. They keep asking
+`resolve` (§7, deferred).
+
+## 3. The plumber as part of the core
+
+### 3.1 Where the rules live
+
+`src/Plumb.zig` is one type file owning its fields, with its tests at its end.
+
+```zig
+//! The plumber (Plan 9's plumber(4), windows/plumb/): the rules, and a
+//! message matched against them and sent where they say.
+text: std.ArrayList(u8) = .empty, // the rules in force, as plumb/rules reads them
+ports: std.ArrayList([]u8) = .empty, // every port a rule named this session, never dropped
+```
+
+- **The rules are stored as their printed text.** The text is what Plan 9's
+ printrules prints, with includes already flattened. It is parsed on every
+ send. Parsing is a few kilobytes of lines and has not been measured.
+- **Why text and not a parsed table.**
+ - Digest, dump and replication are then one byte string; walk.zig needs
+ nothing new.
+ - `plumb/rules` returns the text as is.
+ - No compiled regex is kept: regexp.zig's `Regex` holds a 512-operation mvzr
+ program and 64 sets (regexp.zig:32-33).
+ - An `include` needs a disk read, and that read happens only when rules are
+ written, never when a message is sent.
+- **The field.** `Core.plumber: Plumb` replaces `Core.plumb`. The rename keeps an
+ old dump's `plumb` (a list of strings) from meeting a new type of the same
+ name. How walk.Load treats a field that has gone is not verified;
+ dump.zig:1145 shows a precedent for skipping removed fields.
+- **Bounds.** At most 64 KiB of rule text (Plan 9's whole basic is about 4 KiB),
+ 32 ports (Plan 9's 50, less the fixed files), 32 variables and include depth
+ 10. A write past a bound is refused in words.
+- **How rules change.** Each of these is an input, so a replica replays it or
+ receives it in a dump:
+ - at boot: the user's `plumbing` file if it exists, else `include basic` (§4.3);
+ - a write to `plumb/rules`: a 9P `serve_fs` input on the authority, taped,
+ tape.zig:39;
+ - saving the `plumbing` file in a pane: the same hook as the init file,
+ host_io.zig:3006 → exec.reapplyInitFile. Whether that call is itself taped
+ was not traced.
+
+### 3.2 The matcher, a pure function
+
+```zig
+pub const Msg = struct { src: []const u8, dst: []const u8, wdir: []const u8,
+ type: []const u8, attr: []const u8, data: []const u8 }; // attr in its packed text form
+pub const Verdict = struct { msg: Msg, set: u16, port: ?[]const u8,
+ start: ?[]const u8, client: bool }; // in the step's scratch
+pub fn match(p: *Pardes, id: usize, rules: []const u8, m: Msg) ?Verdict
+```
+
+It follows Plan 9's match.c line for line (§1.2), except:
+
+- **`isfile`/`isdir` resolve a name the way Look does.**
+ - A place written after the name (`:12`, `:12:5`, `:12-14`) is not part of the
+ name; parsePathLine reads it (look.zig:70).
+ - A relative name is tried in wdir, then in the jump list's pane directories,
+ then in Incl's, through the same function resolveLookTarget uses
+ (look.zig:886-909, fs.resolve).
+ - `$file`/`$dir` are the resolved real path, where Plan 9 gives the cleaned
+ join (match.c:149-159).
+ - Both differences keep today's behaviour byte-identical (§5). Each is acme's
+ own look's behaviour moved one step earlier: openfile and includename do
+ this search in acme.
+ - Each stat is a taped `.resolve` site (fs.zig:440). A per-send memo of name
+ to result keeps two rules asking about one name to one syscall.
+- **Determinism.** A replica replaying a unit gets the authority's recorded
+ answers to those sites. A speculating replica is poisoned at the first one and
+ waits a round trip (tape.zig:934-939), as every Look of a file does today. A
+ rule set with no `isfile`/`isdir` (the URL, the hash) never touches a site,
+ so its look speculates fully, as today's URL look does.
+- **Every other verb** is pure string work over the message.
+- **Expansion** has a fixed 4 KiB buffer, Plan 9's `ebuf` (rules.c:36). An
+ expansion past it gives Plan 9's `string-too-long`, and the rule fails. That
+ also keeps a megabyte of paged data out of `$data` (§5.4).
+
+### 3.3 `matches` on mvzr, through regexp.zig's convention
+
+- **No engine work.**
+ - A `matches` with no click compiles `^(` pattern `)$` with regexp.zig's
+ `Regex.compile` (regexp.zig:102) and asks `find` for a match over the
+ object (:371).
+ - Anchoring makes mvzr backtrack into a later alternative when a first one
+ would match short. So whole-match is exact even though mvzr takes the first
+ alternative and not the longest (regexp.zig:22-25).
+ - With `click=N`, the matcher tries `find` from each offset 0..N, as
+ clickmatch does, and N counts runes.
+ - regexp.zig's step budget bounds every call; `TooSlow` counts as no match.
+- **Plan 9 regexp features in the stock rule files, and what mvzr does with
+ them** (ROOT/lib/plumb/basic, plan9port plumb/basic; mvzr's list in
+ zig-pkg/mvzr-0.3.9…/README.md:36-77):
+
+| feature | used in | mvzr through regexp.zig |
+|---|---|---|
+| classes with ranges, `\-` `\.` `\^` escaped in them; `[.$]` | everywhere | yes |
+| `?` `*` `+`, groups, `\|` | everywhere | yes (greedy; first alternative, not longest: harmless under the `^(…)$` anchoring) |
+| `\.`, `\(`, `\)` outside classes | images, man | yes |
+| `.*` | `Local (.*)` (basic:116) | yes (`.` is a byte, or not a newline in a pattern naming `\n`: regexp.zig:9-13) |
+| the rune range `¡-￿` (U+00A1–U+FFFF) | file, image, man classes | **no**: regexp.zig spells non-ASCII ranges out rune by rune and refuses ones wider than 256 (`WideRange`, regexp.zig:78-79). Written instead as an alternation with a high-byte class, `([a-zA-Z0-9_\-./]\|[\x80-\xff])` (UTF-8 is self-synchronising, so a run of these is whole runes). regexp.zig's own rewrite emits high-byte `\x` classes (regexp.zig:300-330); this exact class is not verified |
+| leftmost-longest | clickmatch's choice of span | approximated: the first match from each offset, greedy. A click inside a run of file characters finds that run in every stock rule |
+| `$1`–`$9` submatches | `arg isfile $1`, `attr add addr=$3`, `man $2 $1` | **no**: mvzr has no capture groups (README.md:77). Phase 1 refuses a `$1`–`$9` outside quotes at parse, in words (Q1). The defaults need none (§5.2). |
+| `{m,n}` | nowhere in Plan 9 | mvzr has it (README.md:52): pardes's rules may use it, and the default hash rule does |
+
+### 3.4 Ports
+
+- **One comptime table in Plumb.zig names the ports pardes reads itself.**
+ pardes is always one of their readers, as acme always reads `edit`.
+ - `edit`: opens the data as Look opens a name. It takes a file, a directory or
+ a kind's file by extension, at the place written after it or given as
+ `addr=`. With `action=showdata` it shows the data. With `action=showdiff`
+ it shows the data stacked as a +Diff (§5.4).
+ - From the look that sent the message, in the same step, the handler runs
+ lookAt's final switch on the target Look already resolved. That is no
+ second resolution, and the same code as today.
+ - From anyone else (`plumb/send`), the handler resolves the data itself,
+ joined to the message's wdir when the data is relative.
+ - `web`: the host's link opener (`open_link`, at most 256 bytes as today,
+ look.zig:1601).
+ - every loaded kind by its name (`image`, `pdf`): the file opened in that
+ kind. While the kind is not loaded nobody reads its port, so Plan 9's rules
+ apply: `start`/`client` run, or the send fails and Look falls back to its
+ own look. That is today's "a kind gone since is passed over".
+- **Every other port is a file that external programs read** (§4.1). If a rule
+ names `edit` or `web`, an external reader of it gets a copy too (Plan 9's
+ fan-out). Diverting a message is done with a rule, not by holding the port.
+- **Whether a port has an external reader** is the authority's 9P state.
+ - The matcher asks it through `tape.authority` as a bool, the way mouse.zig
+ asks whether a pane's events are read (mouse.zig:1024-1044).
+ - A speculation guesses the last answer, and the unit confirms it or rolls it
+ back (tape.zig:884-901).
+ - Queues live in `p.fs`, which is authority-only (Core.zig:416). A push to a
+ port with no opens does nothing, as events.noteAction returns when nobody
+ reads (ninep/events.zig:602-611).
+
+### 3.5 `plumb start`, and a compiled-in word as what is started
+
+- **What it runs.** `plumb start <args>` expands its arguments (§1.2) and runs
+ them as pardes's exec runs a line from the message's pane, `exec.execute`
+ (exec.zig:651-722):
+ - A builtin or a kind's word runs in place, through executeBuiltinLine
+ (exec.zig:870-906). So `plumb start Diff $file` runs the compiled-in
+ stacker.
+ - Any other line is a command pane in the message's wdir. That is the pane's
+ directory for a look. For a `plumb/send` with another wdir, runCommand takes
+ an override field, as it takes `exec_column` (exec.zig:752).
+ - Each expanded word goes to `$SHELL -c` single-quoted, so a word stays one
+ argument whatever it holds. This is Plan 9's argv exec (match.c:346-364)
+ spoken to pardes's exec, which runs lines through a shell. A rule that wants
+ a pipe writes `plumb start sh -c '…'`, as Plan 9's write `rc -c '…'`.
+ - Plan 9's start is detached and windowless, and Q4 asks whether to keep that.
+ pardes's exec is already acme's, and nothing in the defaults starts a
+ program.
+- **A started word may decline.**
+ - `Ctx` gains `plumbed: bool`. A word started by the plumber that cannot do
+ what the message asks (Diff on a file with no hunk, Diff on a revision
+ outside a git work tree) sets `p.plumb_declined` and says nothing.
+ - The plumber then fails the send. Look falls back to its own look, as acme
+ does when the plumber's write fails (§1.4).
+ - Any other failure of a started word is the word's, said as usual. Plan 9's
+ sender never hears of a start that fails later.
+- **`Diff` gains an argument** (builtins.zig:1092-1103):
+ - `Diff <file>` stacks that file's hunks. It reads the file at a taped
+ `.read_file` site and calls Output.openDiff (Output.zig:491), which is
+ today's look.zig:1627-1631 moved.
+ - `Diff <rev>` (7 to 40 lowercase hex digits with a letter and a digit, the
+ old isCommitHash) finds `.git` above the pane's directory and runs
+ `git show <rev>` paged: lookCommit, look.zig:1118-1131, moved whole with its
+ `command_pages`.
+ - Bare `Diff` is as today.
+ - A diff pane is needed only when Diff is bare: the `needs` check at
+ exec.zig:985 applies to the bare form.
+- **`plumb client <cmd>`** is `start` plus a hold. The message waits, bounded,
+ in the port's hold list and goes to the port's first opener (Plan 9's
+ queueheld). Rules in the defaults never use it. Two uses it gives:
+ - a helper started on demand;
+ - `plumb client Addon load image`, holding the message until the kind
+ registers and pardes starts reading its port.
+
+## 4. The surface
+
+### 4.1 The 9P files
+
+`plumb/` is a new top directory. It needs `TopFile.plumb` (tree.zig:230-289; the
+u5 enum has 6 values free) and a third node family beside panes and columns for
+the ports, with a bit as `col_bit` has (tree.zig:367).
+
+| file | mode | read | write |
+|---|---|---|---|
+| `plumb/rules` | 0666 | the rules in force: variables, port declarations, rule sets, as printrules prints them | appends rule text. Complete sets (ended by a blank line) are parsed at each write, the rest at release. A parse error fails that write with the line number and Plan 9's words. An open with OTRUNC (`> plumb/rules`) clears the rules first. One writer at a time: `file in use` (tree.zig:62) |
+| `plumb/send` | 0222 | — | a message in the text form of §1.1, assembled across writes. Answered when it is matched and disposed. The error words are Plan 9's: `bad plumb message format`, `no matching plumb rule`, `couldn't find destination for message`, `no start action for plumb message`, `no port for "client" rule`, `empty argument list` (fsys.c:147-156, match.c:450-460) |
+| `plumb/<port>` | 0444 | one message a read, packed. A short read takes the front of a message and the next read the rest, as the event file does (events.zig:104-115). A read with nothing waiting is held (`.again`, Open.held, tree.zig:165-172). Messages sent before the open are not this open's; a release drops what the open did not read | — |
+
+- **Opens.** A port open is an `Open.what` of its own holding a bounded queue: an
+ `events.Queue`, 64 KiB, oldest dropped (events.zig:21-60). A message bigger
+ than the queue is not delivered to that reader, and the log gets an `err`
+ saying so.
+- **readdir order** is Plan 9's: `rules`, `send`, then the ports in the order
+ rules named them.
+- **Reserved port names**: `.`, `..` and `send` (Plan 9's badports,
+ rules.c:38-44), plus `rules`, which Plan 9 forgets.
+- **Wake-ups.** `plumb/send` and `plumb/rules` writes go through `needsQuiet`, as
+ every write does (tree.zig:82-90). A held port read is answered by the
+ listener when `p.fs.news` is set, as event reads are.
+
+### 4.2 The `Plumb` word
+
+The one-line form is replaced.
+
+- **Bare `Plumb`** opens the user's `plumbing` file in the configuration
+ directory, beside `init`, as `Config` opens init (builtins.zig:1338-1360).
+ - If the file is not there yet, the pane holds `include basic`, which Save
+ makes. That is plan9port's initial.plumbing, less the editor variable.
+ - Saving the file replaces the rules, through the same hook that applies a
+ saved init (host_io.zig:3006). It is `cp lib/plumbing /mnt/plumb/rules`
+ done for you (plumb.ms:784-787). A parse error is said with its line, and
+ the rules stay as they were.
+- **`Plumb <anything>`** is refused in words: "Plumb takes no rule now: rules are
+ plumb(6) rule sets, in <config>/plumbing (Plumb opens it) or written to
+ plumb/rules". An old init line `Plumb suffix .svg to image` is said the same
+ way, as an init line that fails is (exec.zig:941-954). The user's init has
+ none. Q3 asks whether a one-line form stays.
+- **Converting an old rule by hand.** `suffix .svg to image` becomes:
+
+```
+type is text
+data matches '.*\.([sS][vV][gG])'
+arg isfile $data
+plumb to image
+```
+
+### 4.3 Where the default rules live
+
+- **Location.** `src/plumbing`, the default rules file, compiled in with
+ `@embedFile`. `include basic` names it, as Plan 9's `include basic` names
+ `/lib/plumb/basic`.
+- **Other includes.** Any other relative include is read from the configuration
+ directory, and an absolute one from where it says. Both are taped `.read_file`
+ sites, read only when rules are written.
+- **Boot.** pardes reads `<config>/plumbing` the way it reads init: main.zig
+ puts it in Options beside `startup_config` (main.zig:725-728). Without the
+ file, the rules are `include basic`, so `Pardes.init` in every test has the
+ defaults.
+- **Where it is shown.**
+ - `plumb/rules`;
+ - the `Plumb` pane (after `include basic`, the flattened rules are in
+ `plumb/rules`);
+ - the reference, which quotes `src/plumbing` whole (§6).
+
+## 5. Look after the plumber
+
+### 5.1 The order
+
+1. **The pane's own readings**, unchanged:
+ - an event reader takes the look first (mouse.zig:1034, acme's look.c:98);
+ - History, Recent, a diff line, a command word (§2.2 rows 1-4);
+ - the sender's expansion (row 5);
+ - the zero column (row 6);
+ - `file:/re/` and `:addr` (rows 7-8). lookAddress calls lookAt on the path,
+ which plumbs it, so `x.diff:/re/` behaves as today.
+2. **resolveLookTarget** as today, minus the user's rules (row 11), which are
+ gone from `resolve`. A `.pane` result (a name open in a pane, or `@p`) is
+ focused as today and never plumbed. This is not acme's order (Q2).
+3. **The plumber**, with this message:
+ - `src`: `pardes`; `term` when the look came from a terminal in raw mode and
+ not over 9P (the condition at look.zig:1090); the kind's name in a kind's
+ pane;
+ - `dst`: empty;
+ - `wdir`: Pardes.paneDir;
+ - `type`: `text`;
+ - `attr`: empty, so no click in phase 2 (§7);
+ - `data`: the trimmed name reading (look.zig:1540).
+
+ Skipped when `p.look_text` is set. That flag now means "a look that opens as
+ text, unplumbed": showDiffText and Edit's `B` (Output.zig:532,
+ edit_cmd.zig:100).
+4. **If the send failed**, lookAt's switch runs on the target from step 2, as
+ today, minus the hooks that became rules:
+ - the `.url` arm becomes lookUnresolved, since acme's own look opens no URL;
+ - the `.diff` hook goes from the `.file` arm;
+ - lookCommit goes from lookUnresolved.
+
+### 5.2 The default rule file (`src/plumbing`), in full
+
+```
+# pardes's plumbing rules, in plumb(6)'s language. The first rule set
+# whose patterns all hold takes the message; one that none takes is
+# Look's own (a file or directory opened, else the word searched for).
+# A look sends what it looks at: type text, src pardes (term from a
+# terminal's raw mode, a kind's name from its pane), wdir its pane's
+# directory, data the name as Look reads it.
+
+# urls go to the web browser (the host's: xdg-open, open on macOS)
+type is text
+data matches 'https?://.*'
+plumb to web
+
+# a diff or patch looked at bare is stacked in a +Diff; one with no
+# hunk in it opens as text
+type is text
+data matches '.*\.(diff|patch)'
+arg isfile $data
+plumb start Diff $file
+
+# existing directories, and existing files at the place written after
+# them, go to the editor; a file a kind shows (a picture, a PDF) to
+# that kind
+type is text
+arg isdir $data
+plumb to edit
+
+type is text
+arg isfile $data
+plumb to edit
+
+# a commit hash looked at in the editor, in a git work tree: git show,
+# stacked in a +Diff (outside one, Diff declines and the word is
+# searched for)
+type is text
+src is pardes
+data matches '[0-9a-f]{7,40}'
+data matches '[0-9a-f]*[0-9][0-9a-f]*'
+data matches '[0-9a-f]*[a-f][0-9a-f]*'
+plumb start Diff $0
+
+# a diff paged (git show, git log -p) is shown stacked in a +Diff in
+# its +Pager's place
+type is text/x-diff
+attr delete action
+attr add action=showdiff
+plumb to edit
+```
+
+**Why each rule matches today's code byte for byte:**
+
+- **web.** Today it is `startsWith(trimmed, "http://" | "https://")`
+ (look.zig:263-265). The rule is a whole match of `https?://.*` over the same
+ `trimmed`. It runs after the open-pane check, as today's URL test does, and
+ needs no disk site, so a replica speculates it fully as today. The handler
+ keeps the 256-byte cap.
+- **diff/patch.** Today the hook is: target `.file`, no line given, not
+ `look_text`, and the path ends in `.diff` or `.patch` (look.zig:1625-1626).
+ - In the rule: a data that ends so and has no `:N` (the whole match fails on
+ `x.diff:12`); isfile, which is a file and not a directory, found where Look
+ finds it; `look_text` skips the plumber; and an open pane was focused
+ already in step 2.
+ - No hunk: Diff declines (§3.5), so Look opens the file as text, which is
+ today's fall-through (:1632).
+ - **One difference**: a symlink not named `.diff` that resolves to a `.diff`
+ file is stacked today (the test is on the resolved path) and opens as text
+ after. Plan 9 cannot test `$file` by pattern without a permanent
+ `data set`. Accepted.
+- **edit, two sets.** They make the hash rule come after file and directory
+ resolution, as lookCommit came after it (look.zig:1092 is inside
+ lookUnresolved). The handler is today's switch on today's target.
+- **hash.** Today: the whole `trimmed` is 7-40 lowercase hex with a digit and a
+ letter (isCommitHash), the pane is no kind's and not in raw mode
+ (look.zig:1090), `.git` is above the pane's directory, and git show runs from
+ that pane.
+ - The rule tests the same, with `src is pardes` covering the pane test.
+ - `Diff <rev>` does the `.git` walk, the exec and the paging exactly as
+ lookCommit did.
+ - Outside a work tree, Diff declines, so Look's search runs as today.
+- **paged diff.** The pager's send (§5.4) carries `type text/x-diff` exactly when
+ File.looksLikeDiff said so (File.zig:752: today's `pager_diff`). The edit
+ port's `showdiff` is today's restack code (ctl.zig:724-730) moved.
+ - The code's `attr delete` fails when the attribute is absent (match.c:258),
+ and the pager always sets `action`.
+ - Without this rule, the explicit dst `edit` delivers the message unchanged
+ and the +Pager stays as text.
+
+**What is deliberately not a rule:** directories in Plan 9's sense (acme's
+openfile handles them, and so does pardes's `edit`), kinds by extension (the
+`edit` port's choice of pane, so that today's `Addon load` of a new kind needs
+no rule), Incl, `@p`, addresses, and the search.
+
+### 5.3 What changes for a user
+
+- **Rules now see a look before any of pardes's own decisions** except steps 1
+ and 2. Today the user's rules came after the `@p` and open-pane checks too,
+ so that part is unchanged.
+- **A rule to a port no one reads is no longer refused at write.** Plan 9 never
+ refuses it (test/behaviour/addons.zig:199-200 changes).
+- **The hover, the n/N walk and the lookable span** no longer see the user's
+ rules. Today they did, through `resolve` (look.zig:133-153, :227). That is
+ deferred (§7). No user rule exists.
+
+### 5.4 The pager as a sender (acme's `plumb -i … action=showdata`)
+
+- **Today.** `pardes -` writes a directory to `/pager`, which makes the +Pager,
+ and then the text. fillPager fills the pane and, for a diff, stacks it and
+ closes the +Pager (ctl.zig:705-731).
+- **After.** fillPager fills the pane as today, then sends:
+ - `src pager`;
+ - `dst edit`;
+ - `wdir` the +Pager's directory;
+ - `type text/x-diff` when the text is a diff, else `text`;
+ - `attr action=showdata filename=<the +Pager's path>`;
+ - the text as data.
+- **The `edit` port's actions.**
+ - `showdata`: nothing more, since the +Pager is shown.
+ - `showdiff`: today's restack. It opens a +Diff from the pane `filename`
+ names, closes the +Pager and keeps the keyboard where it was.
+- **The look rules do not see this message.** They all say `type is text`, and
+ an expansion of `$data` past 4 KiB fails (§3.2).
+- **External readers of `plumb/edit`** get the paged text when it fits their
+ queue.
+
+## 6. One definition, several sinks
+
+| the one definition | its sinks |
+|---|---|
+| `src/plumbing` (embedded) | `include basic`; the boot rules; the reference's plumber section, which quotes the file. Typst reading `src/` from docs/typ is not verified; otherwise build.zig copies it next to the generated builtins JSON |
+| `Plumb.text` (the rules in force) | `plumb/rules`; the `Plumb` pane's file after a save; a dump |
+| Plumb.zig's table of pardes's own ports, each with a line saying what it does | `plumb/` readdir (with the ports rules named); the reference's port table; fs-help.txt's `plumb/` line (one line, as every directory has there, src/fs-help.txt:20-23) |
+| Plumb.zig's error words (Plan 9's) | `plumb/send` and `plumb/rules` write errors; the `Plumb` pane's save error; the reference |
+| the message's text form (one pack, one unpack in Plumb.zig) | `plumb/send`, the ports, a later `pardes plumb [-s src] [-d dst] [-w wdir] [-t type] [-a attr] -i \| data…` (plumb(1); PLAN.md §7 C+L's `fs write` over the tree) |
+
+## 7. Phases
+
+Each phase lands alone. Sizes are estimates from reading, as lines of code plus
+lines of tests.
+
+**Phase 1: the language and the files.** About 450 + 300.
+- What it builds:
+ - Plumb.zig: pack and unpack; parse, print, variables and include; expand;
+ match, including click; dispose to `start` and to pardes's own ports;
+ - `src/plumbing`;
+ - `plumb/rules` and `plumb/send` in the tree;
+ - the field `Core.plumber`.
+- Nothing calls the plumber from Look yet. External ports answer `no such plumb
+ port` on open.
+- **Gates.** Tests at the end of Plumb.zig:
+ - every parse error in Plan 9's words;
+ - a print/parse round trip;
+ - plan9port's basic, with its `¡-￿` classes rewritten and its `$1`/`$3` rule
+ sets dropped, parses;
+ - whole match and click match, each with Plan 9's `horse.gift` case;
+ - rc quoting;
+ - `attr delete` of an absent attribute fails;
+ - dst/port filtering;
+ - a dump keeps the rules.
+- One T1 behaviour test writes `plumb/rules` and reads it back, then sends a
+ message to `web` and sees `open_link` recorded (`p.fallback.setLink`,
+ host_io.zig:314).
+- Known base failures as RULES.md lists them.
+
+**Phase 2: Look sends.** About 120 + 100. look.zig loses about 150 lines:
+- Port, plumbRuleError, plumbTarget, the rules block, lookCommit,
+ isCommitHash and the `.diff` hook go;
+- the sender comes in.
+- What else changes:
+ - Diff takes an argument and declines;
+ - `Plumb` is rewritten as in §4.2;
+ - the hover keeps `resolve`.
+- **Gates**, all unchanged byte for byte:
+ - look.zig's 28 tests, with the Plumb test at :2688 rewritten onto
+ `plumb/rules`;
+ - hunks.zig:718 (`.patch` look, Diff to text and back) and :808 (pagers by
+ commit);
+ - test/behaviour/look_and_exec.zig (36 tests), addresses.zig (7), mouse.zig,
+ event.zig;
+ - addons.zig:188, rewritten to a rule in plumb/rules: same panes;
+ - process goldens look-center, look-file, look-file-1col, lookloaded,
+ lookpanes, lookrange, diffview, dirpane (test/process/tty_editing.zig),
+ ttylook and look-fd-deep (tty_terminals.zig), pagercolor (tty_themes.zig).
+- New tests:
+ - a hash looked at inside and outside a git work tree, so lookCommit's path
+ gets the end-to-end test it never had;
+ - a URL with the web rule removed is searched for.
+- **Replica gate** (this step changes which sites a look reads):
+ - test/replicas.zig gains a look at a `.patch`, at a URL and at a hash on the
+ authority, with digests equal. These are diff-module.md R2.1's missing
+ cases (a)-(c).
+ - A speculated URL look is confirmed with no rollback.
+ - The real-use soak, tty and window, local and on the box, as
+ replica-soak-gate asks.
+
+**Phase 3: external ports.** About 120 + 80.
+- What it builds:
+ - per-open queues, held reads, fan-out, `client` holds;
+ - the `tape.authority` question "is this port read".
+- **Gates:**
+ - a T1 test with two opens of `plumb/edit` sees one look's message each, an
+ open made after the send sees none, and a `client` message reaches the
+ first opener;
+ - monkey9p.zig gains the `plumb/` files;
+ - a replica speculating a look whose rule names an external port is
+ confirmed.
+
+**Phase 4: the pager sends.** About 40 + 30.
+- What it builds: fillPager's send, and the `edit` port's `showdata`/`showdiff`.
+- **Gates:**
+ - pagercolor;
+ - hunks.zig:808;
+ - a test that removes the paged-diff rule and keeps the +Pager;
+ - a soak task paging `git show`, which is diff-module.md R2.1 (c).
+
+**Deferred, and why:**
+- **The click attribute from Look** (acme's whitespace-delimited word plus
+ `click`). Look's own expansion (config.isFileChar, look.zig:318-325) would
+ give way to the rules' `matches`, and every click golden would move. Plan 9
+ fidelity says yes one day. Byte-identity says not with the plumber's first
+ landing. `plumb/send` honours `click` from phase 1, for external senders.
+- **The hover asking the matcher**, as a dry run without dispose. It would put a
+ rule set's regexes in the per-frame hover path; measure first.
+- **`$1`–`$9`**, unless Q1 decides otherwise.
+- **`pardes plumb`** and `pardes -` as `plumb -i -d edit`. These wait for the
+ CLI work (PLAN.md §7 C+L).
+- **Types other than text.** Plan 9 never did them (plumb(6) :49-51).
+
+## 8. Questions only the user can answer, and what was decided
+
+Decided 2026-11-17 by the coordinator, the user asked where marked:
+
+1. **Submatches: (a).** `$1`–`$9` are refused in words at parse: the regex
+ library has no capture groups, and the user's standing rule is never to
+ write or vendor a regex engine. Rules use `$0` and several `matches`. The
+ user has been asked whether they want more.
+2. **An open pane first: (a).** A name already open in a pane is focused
+ before the rules run, as today, so every existing look test and golden
+ stays byte-identical.
+3. **The `Plumb` word: (a).** Bare, it opens `<config>/plumbing` as `Config`
+ opens the init; Save applies it; an argument is refused in words. Without
+ that file the rules are `include basic`, the embedded `src/plumbing`.
+4. **`plumb start` of a program: (a).** It runs as pardes's exec does: a
+ builtin in place, a command as a command does today. The user has been
+ asked whether a started program should run detached with no pane, as Plan
+ 9's does; the place where that is decided is one spot (Plumb.zig's
+ `start`).
+
+The options as round 1 put them:
+
+
+1. **Submatches (`$1`–`$9`).** mvzr has no capture groups, and writing a regex
+ engine is ruled out.
+ - (a) **Refuse them in words, and write rules with `$0`, several `matches`
+ and isfile reading a name past its address.** Shell splitting is the
+ escape hatch: `plumb start sh -c '…' $0`. The defaults need nothing more.
+ *Leaning (a).*
+ - (b) Recover top-level groups by testing candidate splits with anchored
+ whole matches of each group's sub-pattern. That is about 100 lines and no
+ engine, but the spans are approximate where Plan 9's leftmost-longest
+ would choose otherwise. More of plan9port's basic would paste in as is.
+2. **Does a name open in a pane come before the rules?**
+ - (a) **Yes, as today and as today's `Plumb` rules see it.** A `.diff`
+ already open as text is focused, not restacked. *Leaning (a): byte-identity,
+ and acme has only one window per file to find anyway.*
+ - (b) acme's order: the rules first, and the `edit` port finds the open
+ pane. A user rule then wins over an open pane, and looking again at an open
+ `.diff` stacks it again.
+3. **The `Plumb` word.**
+ - (a) **Bare `Plumb` opens `<config>/plumbing`, Save applies it, and an
+ argument is refused.** *Leaning (a): Plan 9 keeps rules in a file, and a
+ rule set is several lines.*
+ - (b) Also keep a one-line `Plumb <rule set>` for tags and init, its lines
+ separated by `;`. But `;` is in Plan 9's `$addr` regexes, so this needs an
+ escape.
+ - (c) Remove the word, so rules live only in the file and in `plumb/rules`.
+4. **`plumb start` of a program.**
+ - (a) **A command pane in wdir, as pardes's exec.** Its output and exit
+ status show, and the defaults start only words. *Leaning (a).*
+ - (b) Plan 9's: a detached child, with no pane, stdin `/dev/null`, and output
+ discarded or logged as an `err`. That is closer to plan9port's rules (`web
+ $0`, `9 page $file`), at the cost of a host effect generalising
+ `open_link`.
+
+## What phases 2-4 did otherwise (2026-11-17)
+
+- **Q4 is (b) now**, the coordinator's lean while the user was away: a
+ program a rule starts runs detached, as Plan 9's plumber starts one
+ (Effect.start, every host's host_io.startDetached: setsid, stdin, stdout
+ and stderr `/dev/null`, every other fd closed, argv exec'd in wdir with no
+ shell). Its output is not the session's log, as the lean said: that needs
+ an inbox message and an Event through the tui, window, macOS and daemon
+ hosts, which other agents are changing. A failure to start (the program
+ not found, its directory gone) is said and logged, the child's errno
+ carried back by a close-on-exec pipe. Its directory and words fit 256
+ bytes, an effect's inline payload.
+- **Only a diff paged is sent** (§5.4 had every page sent). Text paged is
+ `type text`, which the look rules do see, contrary to §5.4: their
+ `matches` would run over the whole output (up to a MiB, and the regular
+ expressions' 300 ms budget) at each page. A diff is `text/x-diff`, which
+ every look rule refuses at its first pattern.
+- **A port pardes reads itself (edit, web, a kind) asks nobody** whether a
+ program reads it: its readers' copies are the authority's own to hand
+ out, and pardes reads it anyway, so a URL's look still speculates whole.
+ Only another port's dispose asks `tape.authority`.
+- **The rules in force are read once** and kept until their text changes
+ (by its hash, derived state): per send the parse was 29k instructions
+ in a fast build, about half of a URL's send and 40% of a word's look.
+- **`showdata` from another sender** makes a clean pane of its `filename`
+ (acme's plumbshow); the pager's own message is shown already.
+- **plumb/rules' rest read at the close**, refused there, is an `err` in
+ the log (Plan 9 loses it); the T1 monkey models it as a line file's.
+
+## Not verified
+
+- **Nothing was built or run.** All sizes are estimates, and the test counts are
+ greps.
+- **mvzr.**
+ - Whether one mvzr class may mix ASCII and high bytes, and that
+ `[\x80-\xff]` compiles. regexp.zig emits similar `\x` classes; this one was
+ not tried.
+ - The cost of compiling the rules' regexes on every send, and the size of a
+ compiled `Regex`.
+- **Dumps and boot.**
+ - How walk.Load treats the removed `plumb` field of an old dump.
+ - Whether the init-file reapply call at host_io.zig:3006 is a taped input.
+ - Whether Typst can read `src/plumbing` from docs/typ.
+- **Replicas.** That a replica's pushes to its own `p.fs` port queues are
+ harmless. That is assumed from events.noteAction's pattern; replica.zig was
+ not read for it.
+- **Behaviour** read in the code but never run:
+ - git paging into a +Pager under `command_pages` (host_io.zig:2103-2107);
+ - the exec `needs` check for Diff with an argument (exec.zig:985).
+- **Sources.**
+ - plan9port's acme was read for acme's side (look.c, acme.c). principia's
+ acme (editors/acme) was not, nor libplumb's event.c or plumb.c.
+ - The `¡-￿` range in the principia rule files was read through `cat`, as
+ UTF-8.
+- **The symlinked-`.diff` difference** (§5.2) is the only behaviour difference
+ found. Others may exist in paths no test covers.
diff --git a/docs/next-terminal.md b/docs/next-terminal.md
new file mode 100644
index 00000000..1229df6f
--- /dev/null
+++ b/docs/next-terminal.md
@@ -0,0 +1,374 @@
+# The terminal out of the core: one module, compiled in
+
+> investigate what it would take to remove the tty from the core and leave
+> it as an addon as the rest, I'm wondering if we would take most of the
+> dependencies (including transitive ones from libghostty) out of the core
+> and make it much leaner for iterating (compile times and all)
+
+> Yes the goal was to make the core leaner for its own sake too … that's why
+> I suggested adding it as an addon.
+
+> yes phase 1 is enough, you can document the phase 2 and the tradeoffs
+> discussions, but we won't do then now. leave the prompt editing to the
+> core (simple back and forth no? )
+
+Decided 2026-11-16. The destination is **Phase 1**:
+
+- The terminal's files become one module outside the core module.
+- That module is compiled into every pardes binary.
+- It is reached through a Zig interface that the core declares.
+
+Phase 2 (the terminal on the addon C ABI) and Phase 3 (shipping it as a `.so`) are written down below and not built. Prompt editing stays the core's.
+
+## What "leaner" means
+
+"The core" is the `core_module` in build.zig: `src/pardes.zig` and everything it reaches. It is what `core-test`, hxdiff, perf, the benches and the test runners are compiled from, about 15 artifacts, each its own compilation.
+
+**Today `wireCore` (build.zig:835) gives it:**
+- cloud9, uucode, mvzr, xitdb, zstd;
+- tree-sitter and its 30 grammars;
+- the generated themes, the translated `pardes_addon.h`;
+- vaxis (for `gwidth` alone: surface.zig:428, File.zig:189-208);
+- ghostty-vt, with what ghostty-vt brings:
+ - wuffs (PNG decode);
+ - simdutf and highway (C++);
+ - ghostty's four SIMD C++ files, and with them libc++ on the link;
+ - ghostty's `props-unigen`/`symbols-unigen` table generators and their own `uucode_generate`;
+ - zstbi (the terminal's PNG resize).
+- Building ghostty-vt also copies ghostty's whole `src/` (603 files) into the cache to patch one file (build.zig:1938).
+
+**After Phase 1 the core module has:**
+- cloud9, uucode, mvzr, xitdb, zstd;
+- tree-sitter and its grammars;
+- the themes and the addon header;
+- vaxis, for `gwidth` (the user's ruling: a dependency kept beats one reimplemented in the core).
+
+No ghostty-vt, wuffs, zstbi, simdutf, highway or libc++. The executables still link all of them through the terminal module, as they link MuPDF through the pdf addon.
+
+**Compile time, measured 2026-11-16** (Debug, `core-test` with one filter, Zig 0.17.1):
+- Any edit to a core file costs a full Zig recompile, 13.3 s, of which ghostty-vt is about 3 s.
+- With a live incremental compiler (`--watch -fincremental`) the same edit takes 0.06–0.36 s.
+- The comptime query filter in syntax.zig was a larger share (about 23%) than the terminal.
+- So compile time alone did not justify this; leanness did.
+- A cold build is 51 s wall, and ghostty's C++ and table generators are about 50 s of its (parallel) step time.
+
+## What the design stands on
+
+1. **The core already edits a copy of the terminal's text, never the emulator.**
+ - Editing shell rows with helix keys works on `EditBuffer`: "the owned text standing in for `rows` live terminal rows … the emulator grid remains untouched underneath" (terminal.zig:418-424).
+ - `editText` builds it from `shellRows` (terminal.zig:1695-1760). The pane says "a copy of the terminal's text: Tab or B2 runs it; what the program draws next replaces it".
+ - An exec types its line into an idle, empty prompt, or runs it in a new pane (exec.zig:663-674, 710-720).
+ - That is acme's `win` contract: text out of the terminal, edited by the editor, typed back.
+2. **Replicas run an emulator fed with state, not pty bytes.**
+ - The authority sends ghostty's own snapshot records: one terminal-wide record, and one record per row, content-addressed, 8 bytes per unchanged row (screen_state.zig:1-33).
+ - A replica's replayed steps read the rows its authority's step read (replica.zig:284-310). A speculation that reads rows is marked (`tape.touchTerminal`, tape.zig:1066).
+ - Predicted echo reads the replica's emulator (echo.zig:237-320).
+ - The kinds design's painted Shadow was generalised from this path and shares its messages (`kind_shadow`, replica.zig:289, 308; architecture §10.4).
+3. **Compiling an addon into the binary already exists.** The static build registers image and pdf from their modules with no `dlopen` (Addon.zig:180-188). This is the shape architecture §17.7 decided (`pub const pardes_addon = addon.ops(Kind)`, exported as a symbol only from a library).
+4. **The default boot is a shell, and so are most tests.**
+ - `Boot.of` chooses `.shell`, `.classic` or `.tty_shell` unless a file, a missing path or stdin is named (Core.zig:2135-2143).
+ - `tty_only` appears 353 times in src/. About 380 of 1,067 tests in src/ touch a terminal (a grep, not a count of those that need one).
+
+## The options
+
+| | (A) run-time `.so` over `pardes_addon.h` | (B) a compiled-in module behind a Zig interface | (C) an external program, a client of the tree (acme's `win`) | (D) A's C ABI, compiled in as `static` does, also built as a `.so` |
+|---|---|---|---|---|
+| the core module's deps | without the terminal's | without the terminal's | without the terminal's | without the terminal's |
+| the binary | the core; `terminal.so` beside it | everything | the core; `pardes-term` beside it | everything |
+| no terminal when | the `.so` is not found (a moved binary, a zig-out build, the ~/.local trap) | never | the helper is missing or dies | never |
+| interface | the versioned C ABI | a second, Zig-typed interface | 9P, plus a cells file | the versioned C ABI |
+| replicas | §11.3's tiers | as today | painted only | §11.3's tiers |
+
+- **A** is "an addon like the rest" taken literally. A pardes whose `.so` went missing boots without a shell, which is no product.
+- **B** costs a second interface beside pa_ops. It is the cheapest way to get the core module free of the terminal: the interface can be as Zig-typed as the code is today, and needs no versioning.
+- **C** keeps the right contract but puts the process boundary in the wrong place. A real VT needs cells, cursor addressing, the alternate screen, colours and images, which cost about 240 KB of cells a frame (≈14 MB/s at 60 fps) and two IPC hops per echo. Replicas would get painted cells only. (What of `win` survives is under Deferred.)
+- **D** is A done the way the static build already does image and pdf: one interface, no install trap.
+
+So the route is **B now, as Phase 1, with D as the way on (Phase 2) if it is ever wanted.** Phase 0 shapes B's interface like the future ABI entries (plain data in, plain data out), so that Phase 2 is a translation, not a redesign.
+
+## The cheap items (being done now, whatever follows)
+
+Items 1 and 3 were tried and reverted by the user's ruling (2026-11-16, "just keep the color palette then, the other choices were bad"): reimplementing a dependency in the core was judged worse than keeping it. Items 2 and 4 stand.
+
+1. **`gwidth` on uucode.** Tried and reverted: the core calls vaxis's `gwidth` again, and vaxis stays in the core module.
+ - vaxis's `gwidth` is about 100 lines over uucode (zig-pkg/vaxis-…/src/gwidth.zig:49-145). Its `.unicode` path, about 60 lines, moves beside `File.graphemeDisplayWidth`.
+ - The 5 call sites (surface.zig:428, File.zig:189-208, draw.zig:1333) use it, and vaxis leaves the core module (the tui, the gui and vaxis_input keep it).
+ - Gate: File.zig's "the ASCII arm of graphemeDisplayWidth matches the gwidth it skips" becomes an every-codepoint comparison against vaxis while both exist, plus the syntax and draw snapshots.
+2. **The palette table.**
+ - `ghostty_vt.color.default` (Art.zig:490, gui.zig:5143) is the xterm 256: sixteen base colours, a 6×6×6 cube, a 24-step grey ramp. That is about 15 lines of comptime in colors.zig.
+ - Art.zig and gui.zig stop importing ghostty.
+ - Gate: equality with ghostty's table in a test, and the gui and tui snapshots.
+3. **The pager's own SGR parser.** Tried and reverted: a +Pager's parse is an entry of the terminal interface instead (`Term.page`, bytes in, text and SGR spans out), ghostty's own stream behind it, so there is one parser.
+ - pager.zig keeps only printed text and SGR spans, but drives ghostty's `Stream` for it (pager.zig:1-10, 38, 64, 208).
+ - A CSI state machine that keeps `m` and drops every other sequence is about 150–200 lines. It stops pager.zig importing ghostty.
+ - Gate: today's `+Pager` outputs (spans and text) as goldens before the switch, and `pagercolor` byte-identical.
+4. **`terminal.Snapshot` into Text.zig.**
+ - `Text.ed_undo/ed_redo` are typed `terminal.Snapshot` (Text.zig:83-85).
+ - The undo of the edit copy is the core's, so its type moves to its user. This also clears the way for `pardes-editor` (the text library, reports/editor-lib.md:313).
+ - Gate: core-test and hxdiff.
+
+After 2 and the pager's move behind the interface, ghostty-vt is imported by the terminal's own files alone (terminal.zig, screen_state.zig, TerminalImages.zig, and the pager's parse in src/term/).
+
+## Phase 0: the narrow module (no behaviour change, no ABI)
+
+`src/term/` takes:
+- terminal.zig (3,422 lines);
+- screen_state.zig (1,664);
+- echo.zig (834);
+- TerminalImages.zig (380).
+
+That is about 6,300 lines moved, not rewritten.
+
+The rest of the core calls only the functions of one interface file. Its records are plain data: rows, numbers, bytes to write, cells. `src/Term.zig` is the suggested name: the core declares the interface and the module implements it.
+
+**Today the core calls 62 terminal functions** (outside tests, by grep). They shrink as follows:
+
+| group | today | becomes |
+|---|---|---|
+| lifecycle (10) | create, createDoc, deinitEmulator, armShellSpawn, shellSpawned, reviveShell, emulatorGpa, terminalIo, deinitPendingCommand, animationDueMs | `open`, `close`, `tick` (the next deadline), `dump`, `load`, `revive` |
+| output and view (13) | feedOutput, followOutput, atBottom, resizeGrid, resizeDeferred, scrollGrid, viewOf, viewTo, panFor, gridOffset, gridCursor, visibleCursor, scrollbar | `feed(bytes, track) → told`, `resize(cols, rows)`, `scroll(view, delta)` / `follow(view)`, and a `grid` record: offset, cursor, cursor visible, scrollbar, at bottom |
+| input (10) | forwardKey, mouseBytes, wheelBytes, encodePaste, bracketedPaste, reportsMouse, reportsFocus, ownsWheel, tracksAllMotion, enterTty | `key(key) → bytes`, `mouse(event) → bytes`, `paste(text) → bytes`, and a `modes` record: mouse, all motion, wheel, focus, bracketed paste, alternate screen. `enterTty` is the core's own mode switch and stays. |
+| prompt and commands (12) | promptInputEmpty, promptInputReady, onAlternateScreen, noteCommand, queuePendingCommand, releasePendingCommandIfReady, commandRunning, commandOutput, endOutputHere, padOutputBelowEdits, marksOf, takeMarks | a `prompt` record (phase, prompts, started, declined, last exit, input ready, input empty, cursor at prompt), `command_output(max_rows)`, `end_output_here`; the pending command queue becomes the core's, released by `prompt.ready`; the marks travel inside the term's replica state |
+| text (11) | screenTextAlloc, screenTextLen, bodyText, shellRows, cursorLines, promptPrefixBytes, editText, setEditText, flatSurface, pushUndo, undoStep | `body`/`body_len` (the plaintext scrollback), `rows(lo, hi)` with each row's prompt-prefix length. editText, setEditText, cursorLines, flatSurface, pushUndo, undoStep and `EditBuffer` return to the core (edit.zig, Text.zig): about 400 lines of the core's own editing, misfiled in terminal.zig. |
+| draw (6) | recolorAnsi, drawImages, hasImages, palColor, petscii, togglePetscii | `paint(window, palette)` writing cells with palette indices kept as indices, and `images(window) → placements`. The palette and the theme's contrast filter are the core's (colors.zig), and so are Petscii and glyph art (architecture §11.1). |
+
+So 62 functions become about 18 entries and three records (`grid`, `modes`, `prompt`).
+
+**The direct reaches into the emulator's state** (`.vt`, `.stream.handler`, `.terminal.?.` outside tests) number 33:
+- replica.zig 15, echo.zig 12, ninep/pty.zig 5, Core.zig 1.
+- echo.zig's go inside with it.
+- replica.zig's terminal half (replica.zig:284-450: `Screens`, `Track`, the peers' state) calls `term` for `encode(peer_base) → bytes`, `ack(seq)`, `apply(bytes)` and `rows_request(lo, hi)`.
+- ninep/pty.zig reads the `prompt` record. The pty files stay the core's: they are about processes, which the host owns.
+
+The ptys stay host resources:
+- host_io.zig forkpty (:2119, :2854), the readers (:591), signals (:2705);
+- upgrade.zig's records of their fds across the exec (:100-165);
+- the `Effect` variants (`write`, `resize_pty`, `signal_pty`, `close_pty`, Effect.zig:42-47).
+
+**Gates:**
+- core-test, pane-test, behaviour-test (with `--monkey` seeds);
+- kitty-test, the kitty and image harnesses;
+- every snapshot byte-identical;
+- `hxdiff --parity` (a pty pane against a file pane), `zig build replicas` (digests, rollback rate), the process suite;
+- `perf-gate` and `perf --terminal-mib` against the base on the same input;
+- the replica soak, local and box, because replica.zig and echo move.
+
+## Phase 1: the module leaves the core module
+
+- **The module.**
+ - `term` is a Zig module of its own, rooted in `src/term/`. Its imports are `std`, ghostty-vt, wuffs, zstbi, uucode and the interface module.
+ - It does not import `pardes`. Zig refuses a file outside a module's root, so the build graph enforces the seam in both directions: the core cannot name ghostty, and the terminal cannot name the core.
+ - The records the terminal writes (cells, placements) live in the interface module, or in a leaf module surface.zig's types are moved into. surface.zig today imports `pardes.zig` (surface.zig:3), so its cell types have to be lifted out.
+- **Registration.**
+ - main.zig hands the core `&term.ops` (`Pardes.Options.terminal`, or one global set at start beside `pardes.turn`).
+ - Every root that builds a product imports `term`: the exe, the static build, `run-isolated`, the gui.
+ - `core_module` does not. build.zig's `wireCore` stops giving it ghostty-vt, wuffs and zstbi, and core-test's link loses `-lc++`.
+- **The no-terminal core.** A core with no terminal ops (only a test can build one) boots to a scratch pane and says once "no terminal in this build". Words that make terminals (`Term`, `Repl`, an exec with no idle shell) refuse in words. `takesCommandLine` is false.
+- **The test fixtures.** This is decided at Phase 1 from the count of tests that need a real shell, as opposed to the ones that merely boot one:
+ - **A fake terminal for core-test** (`Kind.test_kind`'s pattern, Kind.zig:1153). A few hundred lines: `feed` appends text to rows, `prompt` says ready, `key` returns its UTF-8. The tests that boot `tty_only` for convenience boot a scratch pane or the fake. Terminal behaviour tests move to `term`'s own test step.
+ - **The shell tests leave core-test.** Every test that needs a shell moves to a suite that imports `term` (pane-test already imports the core and could import `term`). core-test keeps only what boots without one.
+ - Either way, about 350–700 lines of test boots change, most by one line.
+- **Replication, dumps and Upgrade are unchanged.**
+ - Both sides of a replica are the same binary, so the screen-state path works as now, only called through `term`.
+ - Echo keeps working.
+ - The dump record keeps its format (walk parts plus ghostty's snapshot, terminal.zig:280-330) with no size cap, since this is not the addon record.
+ - Upgrade passes the pty fds as now.
+- **Gates:** Phase 0's, plus:
+ - `zig build static` (musl), `-Dplatform=gui`, `macos-e2e` where a Mac is open;
+ - the replica soak at 30/80/207 ms, local and box;
+ - a check that core-test's compile command names no ghostty, wuffs, zstbi or `-lc++` (from `--verbose`).
+
+## Phase 1 as built (2026-11-17)
+
+What differs from the plan above, and why:
+
+- **The ops are a compile-time constant, not handed over at start.**
+ `Term.ops` (src/Term.zig:18) is `&@import("term").ops` when the build's
+ `term_options.terminal` says the core has a terminal, null otherwise.
+ Every core module but core-test's is given `term`; core-test's
+ (`core_lean` in build.zig) is not, and its `term_options` say so. A
+ run-time `Pardes.Options.terminal` would have put the table in every
+ test's options and every host's start for no gain: no build ever has two
+ terminals, and a null known at compile time drops the dead code.
+- **The table**, `plain.term.Ops` (src/plain/term.zig): about 60 entries
+ in the groups of Phase 0's table (lifecycle, output and view, input,
+ prompt, text, the pager, draw, replicas), each taking and giving plain
+ records or one of four opaque handles (`State`, `Encoder`, `Track`,
+ `Replica`). The module fills it through a cast refused at compile time
+ unless each entry's signature matches (src/term/term.zig).
+- **`Term.State` is a small struct around the handle** (src/Term.zig:55),
+ not the handle itself: walk.zig allocates a pane's terminal on load and
+ hooks its digest and dump, and needs a type of the core's to do it on.
+ The dump keeps a terminal as before (its `Parts` by name, then ghostty's
+ snapshot). The dump's type table names it `Term.State` where it said
+ `term.terminal.State` (and `main`, `terminal.State`); walk discards the
+ name on load, so dumps of either build load in the other (checked:
+ test/daemon.py --upgrade from a build of main, fc38c73c5, and from the
+ Phase 0 base into this one, and from this one back to main's).
+- **Predicted echo came back to the core** (src/echo.zig): it is the
+ replica's presentation, and reads the emulator through five entries
+ (`grid`, `modes`, `prompt`, `echoCell`, `markRead`).
+- **The draw group is plain data** (Phase 0 left it typed in the core's
+ types): `Term.paint` fills a cell buffer in the theme's colours, the
+ core lays it over the body (src/ansi.zig), and `Term.images` gives
+ placements. The colour filter stays the terminal's, as it wraps
+ ghostty's `generate256Color`. A finished command pane's diff colours
+ (`DiffOutput`, `recolorDiffOutput`) moved beside it in src/ansi.zig.
+- **The no-terminal core** boots a scratch pane where a shell would be
+ (Core.zig, `initSession`). `Term.open` refuses with `error.NoTerminal`,
+ which a word says as "no terminal in this build" (`Term: …`, `exec: …`
+ for a line no shell can take). `+Pager` pages the bytes as they are,
+ escapes and all: nothing in the core parses an escape. There is no
+ message at boot: only core-test builds this core, and a boot message
+ made seven of its tests about messages and notices fail.
+- **The test fixture: neither the fake terminal nor a separate suite.**
+ The count decided it. Of core-test's 946 tests, 535 booted a shell and
+ skipped while the scratch boot was a skip; run on the scratch boot, 128
+ of them fail for want of a terminal (they open a shell or a command
+ pane, read the emulator, or index the classic boot's three shells) and
+ say so on their first line (`if (pardes.Term.ops == null) return
+ error.SkipZigTest; // a shell`), and ninep/testing.zig's `withTerm`
+ once for its 29. The rest run. core-test: 810 of 949 run, 139 skip;
+ `shell-test` runs all of them with the terminal. The 28 tests that read
+ terminal.zig's own state through a core are in test/terminal.zig
+ (pane-test); the module's own tests are `term-test`.
+
+## Prompt editing: the back and forth
+
+The core owns the edit and the terminal owns the grid. Across the interface:
+
+**Terminal → core:**
+- `rows(lo, hi)`: the logical rows from absolute row `lo` to `hi` as text, and each row's prompt-prefix length in bytes (from its OSC 133 marks, today `promptPrefixBytes`, terminal.zig:1563).
+- The `grid` record: the absolute row the screen begins at, the cursor, the scrollbar.
+- The `prompt` record: phase, input ready, input empty, cursor at prompt.
+- From each `feed`, the `told` record (today `Told`, terminal.zig:1069):
+ - for every row the core asked to have tracked, its new absolute row;
+ - whether it was erased;
+ - whether the screen was cleared;
+ - whether the terminal is still alive.
+
+**Core → terminal:**
+- `feed`'s `track`: the absolute rows the core holds positions on (the copy's rows, the cursor, selections, their undo, pointer rows).
+- The line to run, as bytes to write to the pty: the line without its prompt prefix, then `\r`. Before it go as many `\r` as keep the program's output below the copy (today `padOutputBelowEdits`).
+
+**A worked example.**
+
+1. The shell is idle at absolute row 41, which shows `~/src $ ` (prefix 8 bytes, input empty). Row 12, in the scrollback, shows `~/src $ make test`.
+2. In normal mode the cursor goes to row 12 and `i` starts an edit. The core asks `rows(12, 12)`, gets `~/src $ make test` with prefix 8, and makes its copy over row 12. The pane says "a copy of the terminal's text…". The user makes the line `~/src $ make test -j8`, with helix's keys, undo and registers, all the core's.
+3. A background job prints three lines while the user types. The scrollback is at its limit, so the oldest three rows are dropped. The core calls `feed(bytes, track = [12, …])`, and `told` says row 12 is now row 9, not erased. The copy, the cursor and the undo snapshots move to row 9, and the program's output never touches the copy.
+ - Had the job run `clear` (ED 3), `told` would say row 12 erased and the screen cleared. The copy is dropped and the pane says so: "what the program draws next replaces it".
+4. B2 on the line, or Tab, runs it.
+ - The core takes the copy's line and cuts the 8-byte prefix the row had: `make test -j8`.
+ - The `prompt` record says the shell is ready with empty input, so the core may type there (otherwise the line goes to a command pane, as exec.zig:663-674 decides today).
+ - The core writes `\r` padding as needed, then `make test -j8\r`.
+ - The program's echo and output replace the copy when they draw over its rows.
+
+Nothing in this crosses per keystroke of the edit itself: the edit is the core's text. The terminal is asked for rows when an edit starts or widens, and tells where rows went on each feed.
+
+## Deferred: Phase 2, the terminal on the addon C ABI
+
+This is not built now. It is written down so the discussion is not lost.
+
+### What it would buy over Phase 1
+
+- **One interface.** The terminal would be a kind like image and pdf, on pa_ops.
+- **Live reload while developing it** (`Addon reload terminal` in a session with a live shell).
+- **A terminal someone else could replace.**
+
+The core module is already lean after Phase 1, so Phase 2 buys nothing more there.
+
+### What the C ABI would need (pardes_addon.h, today ABI 3.1, 19 function slots at :293-353)
+
+- **Bytes and the pty.**
+ - `feed(st, bytes, n, track, *told)`.
+ - `pa_api.spawn` (a child on a pty for this pane), `write`, `resize_pty`, `signal`.
+ - The ptys stay the host's, and Upgrade passes their fds as now: a kind never touches an fd, so the host-syscall yield rule (Turn.zig) is not involved.
+- **Text for editing.** `rows(st, lo, hi, out)` with prefix lengths, and `told`.
+- **Records.**
+ - `pa_grid`: cursor, shape, visibility, offset, scrollbar, dirty rows, coming out of `paint`.
+ - `pa_modes`: mouse, motion, wheel, focus, bracketed paste, alternate screen.
+ - `pa_prompt`: phase, counts, exit, ready, empty, at prompt.
+ - Plus `command_output` and `paste`.
+- **Keys.** `pa_key` is {cp, ctrl, alt, shift, view} (pardes_addon.h:151-154). The kitty keyboard protocol needs composed text, key release, super, the unshifted codepoint, F1–F25, insert and the rest (terminal.zig:1384-1440). That is a new `pa_key2`.
+- **Cells.** `pa_cell` (20 bytes, :63-69):
+ - strike, blink, invisible and the underline styles fit in `attrs`'s free bits;
+ - a wide/spacer flag fits in `flags`;
+ - underline colour and a hyperlink id do not fit. The record must grow, and records are passed as arrays with a fixed stride. That is a major bump.
+- **Images.** `z` on `pa_placement` (80 bytes, no spare field, :100-109). Kitty's `z=-1` draws under the text. architecture.md:721 left it out because "the terminal is not a kind".
+- **Replication, the fed tier.**
+ - `state_encode(st, peer_base, w)`, `state_ack(seq)`, `state_apply(st, bytes)`, `rows_request(lo, hi)`: screen_state.zig behind the ABI.
+ - The core carries opaque per-pane state messages beside today's `kind_shadow`/`kind_raster`.
+ - The hello pins the terminal's content hash (§11.3's `local` rule). A client whose terminal differs gets the painted Shadow (no echo, a round trip per key) and is told once, never refused.
+- **Echo.** `predict(st, key, seq)` and `confirmed(st, seq)`. echo.zig moves with the terminal, which paints the provisional cells itself.
+- **Dumps.**
+ - `PA_RECORD_MAX` is 1 MiB, and a scrollback is up to 16 MiB (terminal.zig:899).
+ - The record would hold the terminal-wide record plus each row's content hash, 8 bytes a row. The rows (screen_state's per-row records) go to the xitdb blob cache (architecture §14.4), written once across dumps and fetched by hash on a join.
+ - A version boundary at Upgrade or Restore: `load(rec, version)` refusing keeps the shell (its fd survived; `reviveShell`) and loses the history.
+- **Paint.** `paint` is called once a frame in each view (pardes_addon.h:111-116). A terminal must say which rows changed, or the core redraws 12k cells per pane per frame. `pa_grid` carries a dirty-row bitmap.
+
+All told: about 20 new functions and 5 new or grown records. pa_ops goes from 19 slots to about 35, and Kind.zig grows by about 500–800 lines. Because of `pa_key2` and `pa_cell`, this is **ABI 4**: every addon rebuilds (there are six, all in the tree).
+
+### What it would risk
+
+- **Remote feel.** The fed tier and echo must land together, or a replica stops feeling local. Gate: the replica soak at 30/80/207 ms with echo on (echo hits, visible rollbacks), box and local.
+- **The hot path.**
+ - Bytes in are one call per pty read (≤ 4 KiB, two in flight): nothing.
+ - Cells out add one pass of about 12k `pa_cell`s per pane per view per frame (architecture §10.2 estimates 10–20 µs), plus the dirty-row bookkeeping.
+ - Gates: `perf --terminal-mib`, `perf-gate`, and a new frame-time cell with four shell panes under `yes`. None of this is measured.
+- **History at version boundaries** (above).
+
+### Phase 3: shipping `terminal.so` instead of compiling it in
+
+This is option A. It brings back the install trap: a binary without its `.so` has no shell. It buys nothing that a dev `.so` loaded over the compiled-in terminal does not. Not planned.
+
+### Option C, and what of acme's `win` survives
+
+`win` (plan9port src/cmd/9term/win.c) works like this:
+- It opens a window's `ctl`, `event`, `addr` and `data` (:177-194).
+- It starts the shell on a pty as a dumb terminal (:205).
+- It strips CR, CRNL and NUL, and keeps a split rune for the next read.
+- It parses one escape, the label (:626-647).
+- It notices "password:" to stop echoing.
+- It appends output at its output point by writing `#q.p` to `addr` and the bytes to `data` (:523-620).
+- What is typed past the output point goes to the shell on newline.
+
+What survives:
+- **The contract**: output is text the editor can edit, and a line goes back as input. pardes's prompt editing is that contract.
+- **The process boundary, for one thing**: a helper would outlive an Upgrade of the editor by itself.
+
+What does not survive: everything a VT is for. Full-screen programs need cells, cursor addressing, the alternate screen, colours and images, and over a process boundary those cost a cells file per frame and two IPC hops per echo. A helper also sits outside the deterministic core, so replicas could only be painted.
+
+### The alternatives rejected for each hard part
+
+- **Prompt editing.**
+ - The terminal could embed `pardes-editor` and edit its own rows. Rejected: a second helix in the guest, possibly from another revision, with registers, macros, `.` and the selection's Look/exec/pipe needing round trips to the core.
+ - The core could edit the emulator's grid through pins. Rejected: it puts ghostty's pin model into the interface.
+- **Replication.**
+ - Replaying pty bytes on every client is rejected: a gigabyte `cat` costs every client a gigabyte.
+ - Painted cells only is rejected as the default: no echo, no local scrollback, a round trip per key into a terminal pane. It stays as the fallback for a client without the same terminal.
+- **Echo.**
+ - A per-cell read API back into the emulator is rejected: a reach the seam exists to remove.
+ - Dropping echo on replicas is rejected: it fails the soak.
+- **Dumps.**
+ - A chunked record (`dump(off, buf, n)` until done) is rejected: every dump carries the whole scrollback again.
+ - A per-kind larger cap is rejected: it breaks the wire bound (§17.3) and "a dump always loads".
+- **The 9P pty files.** Moving them into the addon, through kinds serving files of their own (§10.1 listed "the files it serves", which ABI 3 never got), is rejected for now: a 9P surface in C for one kind. The `prompt` record is enough.
+- **The pager.**
+ - Making `+Pager` a terminal pane is rejected: it loses the file-like pane.
+ - Vendoring ghostty's parse table is rejected: it keeps a piece of what is leaving.
+
+### Questions for the day Phase 2 is taken up
+
+1. Is live reload of the terminal worth an ABI 4 that every addon rebuilds for?
+2. A replica whose terminal build differs from the session's: painted with no echo, or refuse the build mismatch at the hello?
+3. Should kinds get served files (the pty tree would be the first), or does the `prompt` record stay the whole story?
+4. Dirty rows: a bitmap out of `paint`, or the terminal keeping cells across frames and the core asking only for changed rows?
+5. Does a third-party terminal (another emulator than ghostty) need to be possible, or is "one interface" the only reason?
+
+## Not verified
+
+- That `Kind.test_kind`'s pattern fits a terminal fake (none was built).
+- macOS: the Phase 1 tree was not built on a Mac.
+- Everything quantitative about Phase 2: the extra cell pass, the dirty-row bookkeeping, a scrollback's size as row hashes (8 bytes a row is an estimate).
+- The figure for option C (≈14 MB/s of cells) is arithmetic, not a measurement.
+- The compile-time numbers above are from one day on a loaded 16-core machine, about ±1 s.
diff --git a/docs/render-pipeline.md b/docs/render-pipeline.md
index 64fa4e65..05bc8cfa 100644
--- a/docs/render-pipeline.md
+++ b/docs/render-pipeline.md
@@ -62,7 +62,7 @@ core.
## The window's composition
Four fixed draw groups, bottom to top: the page and the panes, the
-notices, the guides and the debug box the core paints over them, and the
+notices, the debug box the core paints over them, and the
ink (bar cursors); then the overlay (the pet, a jump's trail, the caret's
quad). Decor is flat: rules, rails, grips, spines, notice rules and bar
cursors as hard-edged rectangles read from the regions.
diff --git a/docs/typ/building.typ b/docs/typ/building.typ
index cf80bd3a..f14c466b 100644
--- a/docs/typ/building.typ
+++ b/docs/typ/building.typ
@@ -121,8 +121,12 @@ package, and `zig build lib-test` builds and runs it.
```
zig build unit-test module and shell unit tests (the perf gate runs with it)
zig build test-build compile the unit-test programs without running them
-zig build core-test core tests without native shell tests
-zig build shell-test the native shell's own unit tests, without the perf gate
+zig build core-test core tests on the core without a terminal (no ghostty,
+ no C++): a shell boot is a scratch pane, and a test
+ that needs a terminal skips; the one to iterate on
+zig build shell-test the same tests and the native shell's, with the terminal,
+ without the perf gate
+zig build term-test the terminal module's own tests (src/term/)
zig build pane-test pane, output and namespace integration tests
zig build kitty-test kitty graphics conformance of terminal panes, at the core
zig build kitty-harness kitty graphics through a pane end to end (a fake kitty
@@ -238,6 +242,14 @@ effects such as spawning processes.
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()`.
+- The terminal is a module of its own, `term` (`src/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
+ reaches it through one table of plain-data entries (`src/plain/term.zig`,
+ through `src/Term.zig`), chosen at compile time. The records both name
+ (cells, colours, keys) are `plain` (`src/plain/plain.zig`, std only).
+ Every product is built with the terminal; core-test's core is built
+ without it, so its compile names no ghostty, wuffs, zstbi or C++.
- `memory.limits` is the one home for the core's capacities (selections,
the tag's bytes, undo, the arenas' regions). Each core
allocator is a DebugAllocator over its arena's reserved region, thread
diff --git a/docs/typ/builtins-gui.json b/docs/typ/builtins-gui.json
index c7ff594f..8ed70b10 100644
--- a/docs/typ/builtins-gui.json
+++ b/docs/typ/builtins-gui.json
@@ -26,7 +26,7 @@
{"name": "Delcol", "leader": "SPC c d", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Close this column and its panes, refusing once over unsaved text."},
{"name": "Detach", "leader": "SPC s D", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Detach this pardes from its terminal or window, leaving the session running: `pardes --attach` (or `pardes-gui --attach`) takes it back."},
{"name": "Diagnostics", "leader": "SPC l d", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "List the file's diagnostics from the language server."},
- {"name": "Diff", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Stack a diff's hunks as a diff viewer shows them, each under its place and the declarations around it, in a +Diff; on a +Diff, show the diff itself as text."},
+ {"name": "Diff", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Stack a diff's hunks as a diff viewer shows them, each under its place and the declarations around it, in a +Diff; on a +Diff, show the diff itself as text."},
{"name": "Down", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Move the keyboard to the pane below, off a tag onto the pane under it."},
{"name": "Dump", "leader": "SPC s d", "also": ["topbar"], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "Write the session's panes and layout to the state file, for Restore; `Dump export <path>` writes them to a file of their own instead."},
{"name": "DumpConfig", "leader": null, "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Open the settings in effect, each a word to click, and the startup file's path."},
@@ -76,7 +76,7 @@
{"name": "Panes", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Pick an open pane by its name in a query pane under this one (SPC b b)."},
{"name": "Pet", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "off, cat, frog", "doc": "The window's companion in the workspace tag's blank space: off, cat or frog."},
{"name": "Petscii", "leader": "SPC t p", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "glyph art over the host's pixels: an image pane's picture, or the kitty graphics a terminal's program placed (yazi's previews)"},
- {"name": "Plumb", "leader": null, "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "The plumber's rules, for the session, one a line as plumb(6) orders a rule: `Plumb suffix .svg to image` makes a look at an existing `.svg` file an image pane."},
+ {"name": "Plumb", "leader": null, "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "Open the plumbing file, the plumber's rules (plumb(6)'s rule sets) in the configuration directory beside `init`: saved, they are the rules in force."},
{"name": "Putall", "leader": null, "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "acme's Putall: every pane holding unsaved edits to a file is saved, each as its own Save; one that is refused (changed on disk since, a write that fails) says so and the rest are saved all the same."},
{"name": "Recent", "leader": "SPC f r", "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "List the files opened lately, closed ones too, each a place to open again."},
{"name": "Redo", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Redo the last undone edit."},
diff --git a/docs/typ/builtins-tui.json b/docs/typ/builtins-tui.json
index feb1140f..aa95d9a6 100644
--- a/docs/typ/builtins-tui.json
+++ b/docs/typ/builtins-tui.json
@@ -25,7 +25,7 @@
{"name": "Delcol", "leader": "SPC c d", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Close this column and its panes, refusing once over unsaved text."},
{"name": "Detach", "leader": "SPC s D", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Detach this pardes from its terminal or window, leaving the session running: `pardes --attach` (or `pardes-gui --attach`) takes it back."},
{"name": "Diagnostics", "leader": "SPC l d", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "List the file's diagnostics from the language server."},
- {"name": "Diff", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Stack a diff's hunks as a diff viewer shows them, each under its place and the declarations around it, in a +Diff; on a +Diff, show the diff itself as text."},
+ {"name": "Diff", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Stack a diff's hunks as a diff viewer shows them, each under its place and the declarations around it, in a +Diff; on a +Diff, show the diff itself as text."},
{"name": "Down", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Move the keyboard to the pane below, off a tag onto the pane under it."},
{"name": "Dump", "leader": "SPC s d", "also": ["topbar"], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "Write the session's panes and layout to the state file, for Restore; `Dump export <path>` writes them to a file of their own instead."},
{"name": "DumpConfig", "leader": null, "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Open the settings in effect, each a word to click, and the startup file's path."},
@@ -71,7 +71,7 @@
{"name": "Palette", "leader": "SPC t l", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "the C64 palette or the terminal's own 16"},
{"name": "Panes", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Pick an open pane by its name in a query pane under this one (SPC b b)."},
{"name": "Petscii", "leader": "SPC t p", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "glyph art over the host's pixels: an image pane's picture, or the kitty graphics a terminal's program placed (yazi's previews)"},
- {"name": "Plumb", "leader": null, "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "The plumber's rules, for the session, one a line as plumb(6) orders a rule: `Plumb suffix .svg to image` makes a look at an existing `.svg` file an image pane."},
+ {"name": "Plumb", "leader": null, "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "Open the plumbing file, the plumber's rules (plumb(6)'s rule sets) in the configuration directory beside `init`: saved, they are the rules in force."},
{"name": "Putall", "leader": null, "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "acme's Putall: every pane holding unsaved edits to a file is saved, each as its own Save; one that is refused (changed on disk since, a write that fails) says so and the rest are saved all the same."},
{"name": "Recent", "leader": "SPC f r", "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "List the files opened lately, closed ones too, each a place to open again."},
{"name": "Redo", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Redo the last undone edit."},
diff --git a/docs/typ/cheatsheet.typ b/docs/typ/cheatsheet.typ
index 5e373fac..e931effa 100644
--- a/docs/typ/cheatsheet.typ
+++ b/docs/typ/cheatsheet.typ
@@ -10,7 +10,7 @@
btn("B2"), [#word("Exec") the word or selection: a builtin, else a shell line.],
btn("B3"), [#word("Look"): open the file, address, directory or URL, else find the word's next place. Resting the pointer tints what #btn("B3") would take.],
[sweep], [drag #btn("B2") or #btn("B3") to #word("Exec") or #word("Look") exactly what you swept.],
- [grip], [drag the box left of a tag: up/down resizes, onto another column moves the pane. A column's right edge drags its width.],
+ [grip], [drag the box left of a tag: up/down resizes, onto another column moves the pane. A column's box: sideways resizes, past a neighbour's middle moves the column.],
)
=== Chords: hold the first, click the next
#pairs(
diff --git a/docs/typ/guide.typ b/docs/typ/guide.typ
index c602927d..6a50eef1 100644
--- a/docs/typ/guide.typ
+++ b/docs/typ/guide.typ
@@ -174,7 +174,7 @@ pardes.
addr("notes.txt:12"), [line 12],
addr("notes.txt:/TODO/"), [the next match of `TODO`],
addr("src/"), [a pane listing it, as acme's directory window: a #word("Look") at an entry opens it, `..` goes up, `Get` reads it again],
- addr("https://ziglang.org"), [the browser, through `xdg-open` (`open` on macOS); #word("Plumb") adds rules of your own],
+ addr("https://ziglang.org"), [the browser, through `xdg-open` (`open` on macOS): a plumbing rule's; #word("Plumb") opens your rules],
)
#key("Enter") does the same from the keyboard; the other address forms are
diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ
index 7360179f..987f9f9b 100644
--- a/docs/typ/reference.typ
+++ b/docs/typ/reference.typ
@@ -38,6 +38,10 @@ addons the kinds of pane here, compiled in or an addon's @add
layout a line per column, then active <serial> @columns-and-tags
tag the workspace tag @columns-and-tags
tagexec a word clicked in the workspace tag @columns-and-tags
+plumb/ the plumber's: plumb(6) rules, and messages sent by them @plumber
+ rules the rules in force; a write adds rule sets, > replaces them @plumber
+ send write a message: six header lines, then its data @plumber
+ <port> a port the rules name: read, the messages sent to it @plumber
col/ the columns @columns-and-tags
<n>/ column <n>; rmdir closes it when empty @columns-and-tags
tag its tag
@@ -64,6 +68,7 @@ pane/ the panes @pa
look a #word("Look") at this pane @look-and-exec
exec an #word("Exec") at this pane @look-and-exec
tagexec a word clicked in this pane's tag @look-and-exec
+ rows a line a row: where it points, how it is coloured (README) @panes
pty/ terminals only @pty
ctl winsize, sig, exec @pty
status cols rows busy @pty
@@ -1015,6 +1020,92 @@ at 200, ending in `…`. Control characters become spaces.
synthetic. Linux v9fs's truncation `mtime` hint is accepted and dropped.
- #file("/src/") with `-Dembed-sources=true`.
+= The plumber <plumber>
+
+Plan 9's plumber(4), its language plumb(6)'s, in the session: rules
+match a message and say where it goes. A #word("Look") asks it first, as
+acme's does: after the pane's own readings (a +History or +Recent row, a
+diff line, a command word, `file:/re/`) and once a name already open in a
+pane is focused (never sent), what is looked at is sent, `type` `text`,
+`src` `pardes` (`term` from a terminal's raw mode, a kind's name from its
+pane), `wdir` the pane's directory, the data the name as Look reads it.
+One that no rule set takes, or that a started word declines, is Look's
+own: a file or directory opened, else the word searched for.
+
+- #file("/plumb/rules") reads the rules in force: rule sets of
+ `object<tab>verb<tab>arg` lines, each set ended by a blank line, a
+ variable's `name=value` where it was set, an `include`'s rules in its
+ place. A session starts with the plumbing file's rules, #word("Plumb")
+ (`plumbing` in the configuration directory, beside `init`; saved, its
+ rules are in force), or without one `include basic`, pardes's own
+ (`src/plumbing`, below). A write adds rule sets, each
+ read as its blank line comes, the rest at the close (refused there, it
+ is an `err` in the log alone; Plan 9's loses it); `>` replaces them
+ all. One open writes at a time (`file in use`). Kept in a dump.
+- A rule set that does not read is refused at the write it is whole in,
+ `plumb/rules:<line>: <why>` in rules.c's words (`unknown verb isnt`,
+ `ruleset must have patterns and actions`), and the rules stay as they
+ were. `$1`-`$9` are refused: pardes's regular expressions
+ (#doc("reference", section: "regexp")) have no submatches; write `$0`
+ and several `matches`, as Pike's two patterns do. `include basic` is
+ `src/plumbing`; another name is the configuration directory's file, an
+ absolute one where it says.
+- #file("/plumb/send") takes a message, plumb(6)'s six lines (`src`,
+ `dst`, `wdir`, `type`, `attr`, the data's length) and then the data,
+ in one write or several. The write is answered once it has gone where
+ the first rule set whose patterns hold says, or refused in Plan 9's
+ words: `bad plumb message format`, `couldn't find destination for
+ message` (no rule set takes it and it names no port), `no start action
+ for plumb message`, `no port for "client" rule`.
+- The verbs are plumb(6)'s: `is`, `matches` (the whole text; with
+ `click=N` in `attr`, the run around rune N, and the data cut to it),
+ `isfile` and `isdir` (a name found as #word("Look") finds one: past the
+ place written after it, in `wdir`, then #word("Incl")'s directories;
+ `$file` and `$dir` are where), `set`, `add` and `delete` (`delete` of
+ an attribute not there fails, as plumber's code does), and the actions
+ `plumb to <port>`, `plumb start <words>` and `plumb client <words>`.
+- Each port a rule has named this session has a file,
+ #file("/plumb/<port>") (0444), listed after `rules` and `send` in the
+ order the rules named them, never dropped. An open of it reads the
+ messages sent to that port from then on, one a read in the six lines'
+ form, a read that finds none held until one comes; every open gets its
+ own copy (`cat /plumb/edit` beside the editor sees every look it opens),
+ a message over its 64 KiB queue is not sent to it (an `err` in the log
+ says so). Messages sent before the open are not its.
+- The ports pardes reads itself, whatever else reads them: `edit` (the
+ data opened as a #word("Look") opens it, at `addr=` when given; with
+ `action=showdata` the data itself shown, as acme's `plumb -i`, in the
+ pane `filename=` names, else a new clean one of that name, and with
+ `action=showdiff` then stacked in a +Diff in its place), `web`
+ (the host's browser, a URL of at most 256 bytes) and each loaded kind by
+ its name (`image`, `pdf`). A message to another port goes to its
+ readers; with none, its rule set's `start` runs (the message dropped),
+ or its `client`, the message held for the port's first reader (the
+ program it started, as a rule's `plumb client` means). To a port no
+ rule ever named it goes nowhere.
+- `plumb start` of a builtin or a kind's word runs it in place, at the
+ looking pane (the pane with the keyboard for a #file("/plumb/send")
+ message); one that cannot do what it is asked declines, saying
+ nothing, and the send is refused (`no matching plumb rule`), so a
+ #word("Look") looks itself. Any other word is a program, started as
+ Plan 9's plumber starts one: detached, no pane, stdin, stdout and
+ stderr `/dev/null`, its words exec'd in `wdir` with no shell (a rule
+ that wants one says `sh -c '...'`); a failure to start it is said, and
+ logged as an `err`. Its directory and words fit in 256 bytes.
+
+The default rules, `src/plumbing`, keep #word("Look")'s ways: a URL to
+the browser; a bare `.diff` or `.patch` stacked in a +Diff (#word("Diff")
+with the file, which declines one with no hunk, opened as text then); an
+existing directory or file to `edit`, Look's own open (a kind's file in
+its kind); a commit hash looked at in the editor, in a git work tree, to
+#word("Diff") with it, `git show` paged (outside one, Diff declines and
+the word is searched for); a diff paged into a +Pager, which the pager
+sends to `edit` (`src` `pager`, `type` `text/x-diff`, `action=showdata`
+and the +Pager's `filename`), made `showdiff`: stacked in a +Diff in the
++Pager's place. Text paged that is no diff is not sent:
+
+#raw(read("../../src/plumbing"), block: true)
+
= Addons <addons>
An addon is a shared library that brings one kind of pane: a picture, a
@@ -1352,7 +1443,7 @@ with Client(sys.argv[1]) as c: # a socket path, or (ip, port)
[Edit], [every acme command but `B <cmd`, `D <cmd` and the `'` address; no `\1`-`\9`, and an alternation takes the first branch that matches, not the longest; a failing `< | >` command changes nothing, where acme puts in what it wrote (#doc("fs", section: "edit"))],
[`win`], [#word("Term") is a VT terminal pane; #file("pty/run") runs a line at its prompt and answers `exit N` and the output; with #word("Repl") bound, #word("Exec") on a source pane types the text into it],
[a directory window], [as acme's: a text pane named `dir/` (#file("index") kind `text`, #file("ctl") isdir 1), its entries in columns sorted bytewise, dotfiles shown, a directory's marked `/`; blanks pad the columns where acme's tabs do; a #word("Look") at an entry is from that directory, `Get` or a look at it again reads it again, and an edit is kept until then rather than lost to a resize; never dirty, #word("Save") refuses it],
- [the plumber], [no process: #word("Plumb") rules, one a line in plumb(6)'s order (`Plumb suffix .svg to image`), for the session and kept in a dump, are tried before the built-in ones and the first that matches takes the #word("Look"); the tests are `prefix`, `suffix` (an existing file's name, any case), `isdir` and `isfile`, the ports `url` (`xdg-open`, `open` on macOS), `dir`, `file` and any loaded kind by its name (`image`, `pdf`): a rule naming a kind not loaded is refused, and one whose kind has gone since is passed over; no `matches`, attributes, variables or `include`; bare, #word("Plumb") lists the rules, `Plumb -` empties them; the user's own go in `init`, a `Plumb` line each; the built-in rules: an `http://` or `https://` URL to `url`, a directory, a kind's extensions, then any file],
+ [the plumber], [no process: the plumber is the editor's own (#doc("reference", section: "plumber")): plumb(6)'s rules in #file("/plumb/rules") and the plumbing file #word("Plumb") opens, messages to #file("/plumb/send"); no submatches (`$1`-`$9`), no `click` from a #word("Look") (its own expansion stands)],
[#key("Esc") selects what was typed], [#key("Esc") leaves insert mode, or goes back a pane (#doc("tags", section: "modes"))],
)
diff --git a/docs/typ/themes.typ b/docs/typ/themes.typ
index 97b42748..a78cf66c 100644
--- a/docs/typ/themes.typ
+++ b/docs/typ/themes.typ
@@ -109,7 +109,7 @@ take `null`, so older files stay valid:
[`tag_active_bg`, `tag_active_fg`], [the focused pane's tag; a ground closer than 1.25:1 to `tag_bg` is pushed further the way it leans, as far as its text keeps its contrast. Absent: `tag_bg`, `tag_fg`],
[`tagline_bg`, `tagline_fg`], [the tagline, the workspace row: an editor's status bar in its own colours (`dark_plus` has VS Code's blue). Absent: the tag's],
[`tag_name_fg`, `tag_active_name_fg`], [the file name's or a terminal's #word("Term") tint, in normal and focused tags. Absent: the tag's foreground],
- [`column_box`, `column_box_dim`], [a column's grip held (and its drag rail), and at rest. Absent: `num`; a mix of `column_box` and `tag_bg`],
+ [`column_box`, `column_box_dim`], [a column's grip held, and at rest. Absent: `num`; a mix of `column_box` and `tag_bg`],
[`border`], [quiet separators, lifted to 1.6:1 when under 1.5:1 off the page. Absent: `scroll_track`],
[`empty_col`], [a column with no pane, under its tag (acme: white). Absent: `border`],
[`lineno_active`], [the current line number. Absent: `lineno`],