Several zelk processes in the user's browser
The user’s browser serves several zelk processes at once, such as two
TUIs in two repositories. Each process holds the browser for one root
session at a time (Linked, ErrInUse), and the extension dials a
small range of ports, one connection per process. A relay process
would also work, but it needs starting on demand, an idle exit, crash
takeover and version matching; a port range needs none of them.
Behaviour
Section titled “Behaviour”P1. Ports. A zelk process listens on the first free port of the
range: the pairing’s port and the seven after it (27823–27830 by
default), so at most eight processes at once. The default sits below
every range an operating system hands out for outgoing connections:
Linux’s (32768–60999), the dynamic range Windows and macOS use
(49152–65535), and the one WSL2’s mirrored networking reserves on
Windows for its distros’ ephemeral ports. A bind in such a range fails
with “address in use” though nothing listens, and nothing a user can
list says why. When no port of the range binds, the error says they are
in use or reserved by the system, keeps what each bind said, and tells
the user to pair again on another base with zelk browser pair -port
and set the same port in the extension’s panel; it doesn’t claim other
zelk processes hold them. The extension dials every port in the range when
its half-minute alarm fires and when the side panel opens. A port with
no listener refuses at once, so a dial costs nothing. Each port runs
the pairing’s handshake with the paired key. A connection that proves the key
is a link. A listener without the key fails the proof and is never
a link.
P2. A group per root session. After the handshake zelk calls
Zelk.hold with the root session it holds and a label for people to
read, such as zelk · shop-scraper (the workspace’s base name). The
extension keeps a tab group per root session (chrome.storage.local:
session → group) and gives the link that session’s group. A process that
resumes the session later, the same one after a restart or another,
gets the same group, so the tabs it trusted and its kept watches’
targets are still there. A lease holds a session in one process at a
time, so no two links hold one group. When a link ends, its group keeps
its tabs, named <label> (done). A session’s
group is forgotten once its last tab closes. While a process holds no
session (after CloseSession), it stays a link without a group: it
sees no tabs and has none opened.
P3. Routing. A tab belongs to at most one group, and a group to at
most one link. A link’s calls reach only its own group’s tabs:
Target.getTargets, createTarget (into its group), attachToTarget
and session calls are checked against that link’s group. A tab’s events go to the link holding its group.
A popup a tab opens joins the opener’s group.
P4. What stays one for the browser.
- The user’s stop stops every link, and Resume resumes every link:
the bar and the panel’s Stop are one switch for zelk in this browser.
Zelk.stoppedandZelk.resumedgo to every link. - One handoff and one export request at a time, across links, as across subagents: a second gets “zelk is already waiting on the user for another step”. The panel shows whose request it is.
- The badge: OFF while stopped, WAIT while a request waits, ON while any link acts.
P5. Per link. Trusted sites (Zelk.setTrusted), watches
(Zelk.setWatches) and activity are per link. The idle sweep
runs per link against that link’s watches. Downloads go to the link
whose group’s tab started them.
P6. The panel. One section per link, under its label: what it is doing, its watches, its trusted sites. Share this tab asks which session when more than one is connected, and goes straight to the only one otherwise.
P7. Pairing. zelk browser pair listens on the first free port of
the range. The panel’s Pair dials each port of the range with the code
until one accepts. A link’s port takes no pairing, so it refuses, as
any wrong listener does; the extension’s own dialling, in turn,
skips a port where a zelk is pairing, as no zelk to connect to, rather
than report it as an error while the user pairs. The Port setting stays the range’s
first port.
P8. Kept watches across processes. A single file written whole by
each process from its own list would let two processes undo each
other’s changes, so kept watches live in a file per root session
(watches/<session>.json). A process writes only the files of
sessions whose watches it changed, and reads them all to list
(Kept, Watching, and on connecting). It re-reads them
only when the directory’s time moved: every write lands by a rename, so
a host’s footer, which lists on each render, costs a stat. The session
a process holds is its own to change and stays as it has it. Watch IDs
are random (wk7q2xa), since two processes would each count from
w1.
P9. Versions. The link carries a protocol version (link.Version): an
extension without Zelk.hold and a zelk without the range refuse each
other with the message to reload the extension (zelk browser extension), as any version mismatch does.
P10. Out of scope. One process holds one root session at a
time (ErrInUse within a process). A process that serves several root
sessions at once (ACP) could open a link per session later, which P2
allows since a link’s identity is its session.