9a9ccf56
docs: add CLAUDE.md, a context budget for this repo
a73x 2026-08-18 12:38
Commit message
CLAUDE.md
| Old | New | ||
|---|---|---|---|
| @@ -0,0 +1,84 @@ | |||
| 1 | # mux | ||
| 2 | |||
| 3 | Terminal multiplexer: ghostty-vt engine runs authoritatively in `muxd`, replicated | ||
| 4 | in the client. Attach = one snapshot, then row deltas. Zig, Linux only, prototype. | ||
| 5 | |||
| 6 | ## Toolchain (pinned — system zig will NOT build this) | ||
| 7 | |||
| 8 | ```sh | ||
| 9 | ZIG=$HOME/Downloads/zig-x86_64-linux-0.15.2/zig # ghostty pin, 0.15.x only | ||
| 10 | make build test e2e # Makefile already points at it | ||
| 11 | $ZIG build check # fmt + unit tests + shell syntax — pre-commit gate (no make target) | ||
| 12 | make agent soak bench xversion | ||
| 13 | ``` | ||
| 14 | |||
| 15 | First build after a clean checkout fetches ~30MB of QUIC deps (minutes, once). | ||
| 16 | `make clean` deliberately spares `deps/quic`. | ||
| 17 | |||
| 18 | ## Reading this repo without burning context | ||
| 19 | |||
| 20 | Files are large and comment-dense (~44% of Zig bytes are `//`). Reading the repo | ||
| 21 | costs ~800k tokens; every token stays in context and is re-billed each turn. | ||
| 22 | |||
| 23 | - **Never `cat` these:** `src/server.zig` (9.1k lines, ~110k tok), | ||
| 24 | `test/e2e.sh` (4.2k), `docs/decisions.md` (3.7k), `src/client.zig` (3.1k). | ||
| 25 | Use `grep -n` for the symbol, then `sed -n 'A,Bp'` for a window. | ||
| 26 | - Every module has a `//!` header stating its contract. `head -12 src/X.zig` | ||
| 27 | answers most "what is this" questions for ~200 tokens. | ||
| 28 | - Pipe Bash output: `| tail -30`, `2>/dev/null`, `grep -c`. `make test` full | ||
| 29 | output is thousands of tokens of re-billed noise. | ||
| 30 | - `docs/superpowers/plans/*` are historical (16 files, ~15k lines). Grep, don't read. | ||
| 31 | |||
| 32 | ## Layout | ||
| 33 | |||
| 34 | Layers are enforced in `build.zig`'s module table (grep `.layer =` for the graph). | ||
| 35 | |||
| 36 | | Layer | Modules | | ||
| 37 | |---|---| | ||
| 38 | | 0 | `protocol` `engine` `pty` `quic` `keymap` `xdg` `sockpath` `proxy` `testtmp` | | ||
| 39 | | 1 | `quic_server` `quic_client` `predict` `spawn` `handoff` `delta` `cmd` `shellint` `replica` `paint` | | ||
| 40 | | 2 | `server` `client` `muxa` | | ||
| 41 | | 3/4 | `mux_main` `main`(muxd) `webhub` `webhub_main`(muxweb) | | ||
| 42 | |||
| 43 | Binaries: `muxd` (daemon), `mux` (client), `muxa` (agent client, JSON verbs), | ||
| 44 | `muxweb` (browser hub). Test fixtures in `test/`: `ptyclient` (real client on a | ||
| 45 | real pty), `wsclient` (browser stand-in), `rawmode`, `delaypipe`, `render`. | ||
| 46 | |||
| 47 | ## Invariants — do not break, they are load-bearing | ||
| 48 | |||
| 49 | - **Transport is dumb.** `proxy.zig` and the QUIC modules carry opaque bytes and | ||
| 50 | know nothing of frames. Keep `protocol` out of `proxy.zig`'s imports. | ||
| 51 | - **Prediction is an overlay.** `predict.zig` output never enters the replica. | ||
| 52 | - **One replay core.** CLI, wasm, and test fixtures all go through `replica.zig`. | ||
| 53 | Do not hand-roll a second applier. | ||
| 54 | - **Latest wins.** The grid follows the most recently active client. | ||
| 55 | - **`muxa` attaches at 0×0** so an agent never resizes a human's session. | ||
| 56 | - **OSC 133 marks are opt-in** (`MUX_SHELL_INTEGRATION=1`); without them `muxa` | ||
| 57 | falls back to `pgid`/`settle` and there is no real exit code. Every `muxa` | ||
| 58 | reply names the `mechanism` that answered it. | ||
| 59 | - **OSC 52 clipboard READ is refused deliberately.** Not a gap. | ||
| 60 | - No socket stealing: `muxd run` refuses a path another daemon owns. | ||
| 61 | |||
| 62 | ## Working rules | ||
| 63 | |||
| 64 | - Assert behavior, don't assume it. Mocks are assumptions. | ||
| 65 | - Comments say *why*, not *how*. Existing ones are load-bearing — trim noise, | ||
| 66 | keep rationale. | ||
| 67 | - Commit often with `--fixup`/`--squash`, autosquash before delivery. The final | ||
| 68 | history should tell the feature's story, not the development's. | ||
| 69 | - `git-collab` tracks issues (`git-collab issue list`); the commit-msg hook | ||
| 70 | stamps `Patch:` trailers. Each collab write costs a ~15s origin sync — batch. | ||
| 71 | - `zig build check` before commit; capture `$?` before piping (`make test | tail` | ||
| 72 | reports tail's exit code, not the build's). | ||
| 73 | |||
| 74 | ## Where the answers live | ||
| 75 | |||
| 76 | `docs/roadmap.md` (579 ln) what's next · `docs/decisions.md` (3.7k ln, grep only) | ||
| 77 | every decision + measurement · `docs/handoff.md` (199 ln) original design · | ||
| 78 | `README.md` user-facing usage. | ||
| 79 | |||
| 80 | ## Session hygiene | ||
| 81 | |||
| 82 | Context is billed per turn. Compact or start fresh around ~150k rather than | ||
| 83 | riding to the 900k ceiling — a long session pays for its whole history on every | ||
| 84 | turn, including the trivial ones. | ||