Skip to content

Commit 388da77

Browse files
max-sixtyclaude
andauthored
Rescore the dependency cutover list and reject what the measurements ruled out (#768)
The cutover list scored its candidates from a survey's estimates. Six of the rows ranked next were measured against the code, and every one was stale or overstated; an independent review then confirmed the six verdicts and corrected three of the reasons behind them. The rows now carry what was measured, and the ones the measurements ruled out have moved to the survey note, whose table is now named Rejected. What the measurements found: - **`html` as the page scroller** was already done: `26feec8b` made the switch on 2026-08-29, `theme.css` holds the rule, and the runtime reads `document.scrollingElement`. The row is gone. - **Same-document View Transitions** claimed ~150 lines against a `motion.js` of 87. The update applies after the old state is captured, later than the gesture's own turn; pointer input misses the page while it animates; a fold collapses height so later content slides, which a root cross-fade does not draw; and board cards move inside their own scroller, whose clip a snapshot escapes under the Chrome 125 floor. #666 removed the paint-boundary transition version travel used, which also leaves `theme.css`'s `lf-versioning` rule dead — deleted here. - **idiomorph for the version patch**: a live-tree diff keeps only the reader state an exclusion names, while `dom-children.js` compares authored source with authored source and keeps all of it. It has needed no fix since #514 split it out. - **`tsc --checkJs`** runs in under a second, but a bug-back over six runtime fixes (#404, #448, #625, #660, #676, #757) found no error that the fix removed from the files it touched, and the errors it does report are inference artifacts. - **Browser-owned anchoring** was spiked on `agent-a4111d25e33d466d2`. All three capture paths cut over and the anchors matched the Python capture exactly, but Python grew by 168 lines, a quoted `leaf comment` went from 0.2 s to 1.3 s and now needs Chrome, and the anchor tests went from 8 s to 37 s: the refusals and the diagnostics for a quote the page does not show read authored source the rendered page no longer holds. - **The user-level daemon** nets roughly zero lines. The browser already receives pushes over `EventSource`, the 70 µs stat loop serves CLI writers in other processes, pid probing and most locks stay, Windows is not a goal, and a user-level database stops the page directory being the deployment unit. Two rows are new. A size-first sweep of the largest hand-written mechanisms found one candidate the defect-led survey missed: serving each page through starlette and uvicorn, which `mcp` already installs, keeping one process per page. And the keyboard system becomes item #24 under architecture simplification: the reader keeps every key, sequence, hint, and the one-press-per-layer Escape, while the code that infers which surfaces are open — where ten of the last 24 keyboard fixes landed — gives way to a layer stack that openers push and closes pop. No library owns that; the ones that came closest are in Rejected. The preamble now says effort and confidence are estimates unless a row cites a measurement. Checks: the everyday suite (1,135) and `test_a_revision_navigates_without_the_view_transition_api`, which exercises activation with the View Transition API switched off, both pass; pre-commit is green on the changed files. 🤖 Generated with [Claude Code](https://claude.com/claude-code) > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
1 parent 8baf6c4 commit 388da77

3 files changed

Lines changed: 53 additions & 73 deletions

File tree

‎TODO.md‎

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ remain in git history.
3030

3131
## Architecture simplification
3232

33+
- **#24 — Give the keyboard an explicit layer stack.** Let whatever opens a surface push a
34+
layer carrying its close and its restore, let closing pop it, and have `stack()` read the
35+
bindings from the top layer instead of inferring which surfaces are open. The reader
36+
keeps every key, sequence, hint, and the one-press-per-layer Escape. Ten of the 24
37+
keyboard fixes since 2026-08-29 landed in the inference this removes (`stack()` in
38+
`keyboard/dispatch.js`, `keyboard/return-stack.js`, and `native-layers.js`), and about
39+
600 to 900 of the system's 6,085 lines go with it. A surface opened by pointer has to
40+
declare itself first, which is the invoker-commands row under the cutover. First step:
41+
fold `native-layers.js` into the return stack and drop `stack()`'s popover and modal
42+
branches. The fix rate here has fallen and nothing planned waits on it, so it sits
43+
behind the reading work above; the reason to do it is the implementation's own weight.
44+
The libraries that do not cover it, and the fix classification, are in
45+
[the survey note](notes/dependency-survey.md).
46+
3347
- **#1 — Keep the semantic application root thin.** Let the application publisher own
3448
ordering, adoption, and publication while pure Ask, conversation, projection, and widget
3549
models retain their own modules. Do not replace DOM authority with one module containing
@@ -72,8 +86,8 @@ The 2026-09-16 survey of what Leaf could hand to a dependency found the browser
7286
record concentrated in margin placement, geometry timing, and the keyboard register, which
7387
no library owns; a component library would have covered about 13 of the last 175 fixes. The
7488
direction chosen: keep Lit, and replace hand-built behavior with settled libraries and
75-
browser features one at a time as each proves out. The evidence, the candidates
76-
considered and not added, and the Leaf choices worth reconsidering are in
89+
browser features one at a time as each proves out. The evidence, the rejected
90+
candidates, and the Leaf choices worth reconsidering are in
7791
[the survey note](notes/dependency-survey.md).
7892

7993
Effort is S (under two days), M (two to ten), or L (weeks). Saving is lines deleted,
@@ -83,66 +97,27 @@ deleted 56 of a measured 130 for psutil, 6 of 262 for unidiff, 3 of ~100 for wat
8397
and 78 of ~180 for dependency-cruiser, because the refusals, contracts, and definitions
8498
around a mechanism stay. Confidence is how likely the
8599
swap works as described without a spike, weighing adopter evidence and Baseline status.
86-
Effort and confidence are estimates from the survey, not measurements. Each table is
100+
Effort and confidence are estimates unless the row cites a measurement. Each table is
87101
ordered by confidence, then effort.
88102

89103
### JavaScript
90104

91105
| Change | Effort | Saving | Confidence | Risk |
92106
|---|---|---|---|---|
93-
| Typecheck the runtime with `tsc --checkJs`. `scripts/browser/tsconfig.json` already sets `allowJs`, `strict`, and `noEmit` and includes only its own `*.ts`; adding `checkJs` and the runtime's `*.js` to `include` checks the 42,000 lines as they ship, with no emit and no build. JSDoc annotations raise the coverage over time. | M | none deleted; part of the state-sync and repaint class (17 fixes) | Med-High | The first run's error volume; annotations needed for full value |
94-
| Same-document View Transitions for version travel and margin motion. `theme.css:1997` already styles the root transition group and no runtime module calls `startViewTransition`; the FLIP helper and folds in `runtime/motion.js` are what a transition replaces. | M | ~150 est. | Med | Baseline since October 2025, but no UI library depends on it |
95-
| Make the page scroll normally: `html` as the scroller with fixed chrome, instead of `body` as the scroll container. Thirty fixes trace to scroll restoration, resize, and measuring before paint, and every library and browser feature assumes the normal setup. The reason for the current choice is not recorded; spike the switch and count which of those tests break. | M | part of the scroll and layout class (30 fixes) | Low-Med | Fixed chrome, print, and export may depend on the body scroller |
96-
| Spike a morph with exclusions for the version patch (detail below). | M | 325 pairing lines in `runtime/dom-children.js` plus the pairs map every patch maintains | Low-Med | Must prove retention of opened `<details>`, tokenizer spans, lent tab stops, and widget-built children |
97107
| Order the cascade with `@layer` (theme, package, page). Tried 2026-09-16 and backed out: the page's unlayered `<style>` then outranks the chrome, so a page `div { position: relative }` moved 53 chrome boxes including the aim (`test_render_aim`), and putting `chrome.css` on its own rung flipped the specificity contests it was written against `theme.css` with. Needs the chrome isolated from page CSS first: a shadow root, or Leaf wrapping page styles in `@scope … to (.lf-chrome)`. | M | ~50 `!important` and the specificity contests | Low-Med | Every rung assignment re-decides a tuned contest, and only the suite finds which |
98-
| Invoker commands (`command`, `commandfor`, Chrome 135) for the eight runtime modules that call `showModal` or the popover methods. | S-M | ~50 to 100 est. | Low | Chromium-only, no adopters |
99-
| `focusgroup` (Chrome 150) for the list and toolbar arrow-key walks the keyboard register drives. | M | ~100 to 200 est. | Low | Chromium-only, no adopters |
100-
| Navigation API for version travel history: three `history` and `popstate` sites, `runtime/navigation.js` at 197 lines. | M | small | Low | Gain only if intercept replaces the activation choreography |
101-
| TanStack Hotkeys for the parsing, sequence timing, and cheat-sheet formatting slice of the keyboard register (detail below). | M | ~200 to 400 est. of 6,100 | Low | Alpha, 715 stars, no scope stack; the register's core stays either way |
108+
| Invoker commands (`command`, `commandfor`, Chrome 135) for the eight runtime modules that call `showModal` or the popover methods, so a surface opened by pointer declares itself. The keyboard layer stack in [the survey note](notes/dependency-survey.md) needs that declaration. | S-M | ~50 to 100 est. | Low-Med | Chromium-only, so below Chrome 135 the button does nothing unless the module keeps its handler |
102109

103110
### Python
104111

105112
| Change | Effort | Saving | Confidence | Risk |
106113
|---|---|---|---|---|
107-
| Run one user-level daemon on SQLite, starlette, and asyncio (detail below). | L | ~3,100; Windows; push instead of 50 ms polling | Med | Loses per-page process isolation and the grep-able JSONL log per page; tests that reach into `http.server` internals rework |
114+
| Serve each page through starlette and uvicorn, already installed through `mcp`, keeping one process per page. `http.py`'s `Handler` hand-writes response, cookie, and query plumbing, the news stream's `select()` peer-gone loop, and the `http.server` lifecycle workarounds such as #630's preconnect drop. | M-L | ~150 to 200 est. of a ~480-line region; the connection-lifecycle fixes | Low-Med | Converts a threaded server to async: `TemporaryPageServer`, `cmd_serve`, the Worker's `WebsitePageHandler` subclass, and the tests that drive `Handler` |
108115

109116
### Both
110117

111118
| Change | Effort | Saving | Confidence | Risk |
112119
|---|---|---|---|---|
113-
| Let the browser own anchoring (detail below). | M | 824 Python lines plus consumers; the byte-exact parity class | Med-High | One headless page load per `leaf comment`, about a second, unless the daemon keeps a browser warm |
114120
| Bind one loopback port per MCP page with a wildcard-port `frame_domains`, removing MCP multiplexing under `/p/<capability>` as one of the two callers of the route-scoping regexes in `http.py`; the 69 rooted URL literals under `assets/` and `packages/` go relative. | M | ~75 of 155 | Low-Med | The wildcard needs an MCP-host check; leaf.page's example roots keep the mechanism |
115-
| Move the server to TypeScript (detail below). | L | 12,900 mirrored Python lines collapse; two native wheels | Low | Forfeits the pytest suite and render harness; node is not guaranteed on Codex hosts; not incremental |
116-
117-
### Detail
118-
119-
- **Morph spike.** `runtime/dom-children.js` diffs authored source against authored source
120-
and writes the live tree through a pair table, so a reader's open `<details>`, tokenizer
121-
spans, lent tab stops, and module-built children survive a revision. idiomorph diffs the
122-
live tree instead, and its `beforeNodeRemoved` and `beforeAttributeUpdated` callbacks can
123-
refuse those four classes. Measure whether a morph plus the existing jsdiff change marks
124-
reproduces the patch's retention across the corpus before replacing the pairing.
125-
126-
- **TanStack Hotkeys.** `@tanstack/lit-hotkeys` 0.11 (alpha, June 2026) parses
127-
template-string bindings with a platform `Mod`, runs vim-style sequences with a timeout,
128-
tracks held keys, formats bindings for a cheat sheet, scopes a binding to a `target`
129-
element, and detects conflicts at registration. It has no scope stack, priority, or
130-
Escape unwinding, which `runtime/keyboard/dispatch.js` owns. Keep focus-ancestry scopes
131-
and `aria-keyshortcuts` reflection in Leaf. Wait for a stable release.
132-
133-
- **Daemon.** starlette, sse-starlette, uvicorn, and pydantic are already installed through
134-
`mcp`. Deleted: the detached-server handshake, flock leases, pid probing, stat polling,
135-
torn-line repair, and most of `http.py`'s dispatch. Examples ship `.jsonl` companions,
136-
which would become an import format.
137-
138-
- **Browser-owned anchoring.** The browser already posts quote, prefix, suffix, and
139-
section; `leaf comment` and the MCP snapshot resolve through the runtime in a Playwright
140-
page instead of `passages.py` and `anchor_capture.py`. The server's independent check of
141-
browser-supplied anchors protects nothing on localhost.
142-
143-
- **TypeScript server.** Every Python dependency has a node equivalent, and the anchoring
144-
and projection code would exist once. Do the daemon, anchoring, and CSP items first; each
145-
shrinks what this would port.
146121

147122
## General reader continuity
148123

‎notes/dependency-survey.md‎

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
What Leaf could hand to a dependency or a browser feature, and why the rest stays. The
44
chosen candidates are scored in `TODO.md` under "Platform and dependency cutover"; this
5-
note keeps what that section leaves out: the evidence, the candidates considered and not
6-
added, and the Leaf choices worth reconsidering. Delete it once those are decided.
5+
note keeps what that section leaves out: the evidence, the rejected candidates, and the
6+
Leaf choices worth reconsidering. Delete it once those are decided.
77

88
## Method
99

@@ -40,11 +40,12 @@ same camp as Claude Code artifacts and Google's generative UI; no benchmark comp
4040
React and shadcn against HTML or a JSON page spec, so the authoring format is not a
4141
reason to change frameworks.
4242

43-
## Considered and not added
43+
## Rejected
4444

4545
| Area | Candidate | Why not |
4646
|---|---|---|
4747
| Anchoring | Hypothesis `dom-anchor-text-quote`, `approx-string-match` | Fuzzy; would replace ~150 lines of exact search |
48+
| Anchoring | Resolving a typed quote through the rendered page instead of `passages.py` | Spiked 2026-09-17 on `agent-a4111d25e33d466d2` (`3132c9af`): all three capture paths cut over with anchors identical to the Python capture and the suite green, but Python grew by 168 lines, because the section, part, retired, and gone refusals and the diagnostics for a quote the page does not show read authored source; a quoted `leaf comment` went from 0.2 s to 1.3 s and now needs Chrome, each MCP snapshot comment launches a browser, and the anchor tests went from 8 s to 37 s |
4849
| Keyboard parsing | tinykeys, hotkeys-js | The key normaliser is 15 lines; the rest is domain |
4950
| Command palette | cmdk | React only |
5051
| Composer | CodeMirror, ProseMirror, Lexical, Tiptap | The composer is a textarea |
@@ -59,16 +60,24 @@ reason to change frameworks.
5960
| Positioning | Floating UI for the CSS-anchored menus | Tried: +80 lines of JS and async placement for what 10 CSS lines do synchronously |
6061
| Focus | tabbable for the covering surface's Tab wrap | Tried: a vendored startup module in place of a 7-line local filter |
6162
| Motion | `@starting-style` for the thread card and agent-arrival listeners | It replays whenever an ancestor leaves `display: none`, so the reopened panel needs the end listener anyway; the pulse is not an entrance |
63+
| Motion | Same-document View Transitions for the folds, trays, board moves, and column carry in `runtime/motion.js` | The update runs after the old state is captured, later than the gesture's turn; pointer input misses the page while it animates; a fold collapses height so later content slides, which a root cross-fade does not draw; board cards move inside their own scroller, whose clip a snapshot escapes under the Chrome 125 floor. #666 removed the paint-boundary transition version travel used |
64+
| Version patch | idiomorph with exclusion callbacks in place of `runtime/dom-children.js` | A live-tree diff keeps only the reader state an exclusion names; the source-to-source patch keeps all of it and has needed no fix since #514 split it out |
65+
| Typecheck | `tsc --checkJs` over the runtime | It runs in under a second, but a bug-back over six runtime fixes (#404, #448, #625, #660, #676, #757) found no error the fix removed; the 272 errors outside vendored bundles are inference artifacts, and the typed `scripts/browser` core arrives through a bundle with no declarations |
66+
| Keyboard | TanStack Hotkeys (alpha), `@github/hotkey`, tinykeys | They own key parsing, which has had no fix since 2026-08-29; the scope stack, Escape order, and go-to grammar stay in Leaf either way |
67+
| Focus walks | `focusgroup`, Tabster | `focusgroup` is Chrome 150 with no WebKit, so the published site would carry the 19 KB polyfill; Tabster's Groupper returns focus to a group rather than closing a surface and restoring the reader's place |
68+
| History | Navigation API for version travel | Three `history` and `popstate` sites; the gain needs intercept to replace the activation choreography |
69+
| Server | One user-level daemon on SQLite, starlette, and asyncio | Measured about 750 gross and -300 to +500 net: the browser already receives pushes over `EventSource`, the 70 µs stat loop serves CLI writers in other processes, pid probing and the wait, adapter, and delivery locks stay, Windows is not a goal, and a user-level database stops the page directory being the deployment unit |
70+
| Server | The server rewritten in TypeScript | Not incremental; forfeits the pytest suite and render harness, and node is not guaranteed on Codex hosts |
6271
| Chrome library | Web Awesome, Spectrum, Lion, Zag | Not chosen over the platform-first direction; still open |
6372
| Chrome framework | React, Radix, Base UI, shadcn, Preact + htm | A framework migration for the smallest defect bucket |
6473
| Build | Vite, Rollup | One entry, no dev server; esbuild suffices |
6574
| HTML parsing | lxml, selectolax, BeautifulSoup, html5lib | Lose source offsets and browser-parity recovery |
6675
| Events | pydantic or msgspec for event shapes | Shapes are jsonschema; semantics are code |
6776
| Events | an event-sourcing library | None fits a CLI-appendable file |
68-
| Locks | filelock | Wrong lock semantics; the daemon item removes the locks |
77+
| Locks | filelock | Wrong lock semantics |
6978
| Supervision | supervisor-style libraries | The reaper is the session semantics |
70-
| File watching | watchfiles for the server | Presence is pids and locks, not files |
71-
| JS parsing | esprima, acorn | Pre-ES2020; needs node; per-revision copies are the reason it exists |
79+
| File watching | watchfiles for the server | Presence is pids and locks; the one file loop re-stats the log at 70 µs a look |
80+
| JS parsing | esprima, acorn | esprima is unmaintained and acorn needs node; tree-sitter parses authored `page/` modules in Python |
7281
| Codex | official `openai-codex` SDK | Spawns its own CLI; cannot join a running conversation |
7382
| Templating | jinja2 | No templating exists |
7483
| Export | premailer-class inliners | Different job |
@@ -86,26 +95,31 @@ reopened.
8695
- **Comments match text exactly or detach.** Excludes tolerant re-anchoring. Saves no
8796
complexity (the exact search is ~150 lines); a UX question about fewer detached
8897
comments. Proposal: leave it.
89-
- **The keyboard system is vim-like.** Letter chords, per-area scopes, an Escape that
90-
unwinds one level; 6,100 lines and the largest fix bucket. Proposal: prototype in a
91-
playground page a flatter model of global shortcuts from a settled library, a command
92-
palette listing every action, and native Tab and arrow movement; estimated 3 to 4k
93-
lines deleted if it wins.
98+
- **The keyboard system is vim-like.** Letter chords, per-area scopes, go-to hints, and
99+
an Escape that closes one layer; 6,085 lines and the largest fix bucket. The reader
100+
keeps this behaviour, and no library owns the scope stack, the Escape order, or the
101+
go-to grammar; the ones that came closest are in Rejected above. Ten of the 24 keyboard
102+
fixes since 2026-08-29 landed in the code that infers the open layers: `stack()` in
103+
`keyboard/dispatch.js`, `keyboard/return-stack.js`, and `native-layers.js`. Now item #24
104+
in `TODO.md`.
94105
- **Comments float in the margin in clusters, and the reply box sits inside the page.**
95106
6,600 lines and the second-largest bucket. Proposal: add a stacked side-column layout
96107
with the reply box in the panel as one arm of the "Now" item on annotation placement.
97-
- **The page body is the scroll container.** Behind 30 scroll and layout fixes, and every
98-
library assumes the normal setup. Now a row in the TODO tables (spike it).
99-
- **Every revision keeps its own copy of the runtime.** 3.2 MB per revision plus the
100-
import-path rewriting that tree-sitter exists for. The stated purpose is that an old
101-
revision renders after a plugin update replaces the install. Open question: do old
102-
revisions need their own runtime, or only their HTML rendered by the current one? If
103-
the latter, serve from the install and delete the copies and the parser; if the former,
104-
the "share by digest" item under Later keeps the guarantee.
108+
- **Every revision keeps its own copy of the layer.** Two versions of a new page measured
109+
about 3.27 MB in 189 files each, with all 187 resource digests identical, beside a
110+
3.24 MB page-level copy. The copy arrived with #666 so that activating a revision reads
111+
no mutable file, and it lets `page init` skip checking old revisions' HTML against a new
112+
layer. tree-sitter stays either way: it reads authored `page/` modules and builds
113+
interactive exports. Open question: must a stamped version keep the exact JS, CSS, and
114+
look it was approved with? If so, the "share by digest" item under Later keeps that at
115+
one stored copy per digest. If not, serve one page-level layer and have `page init`
116+
refuse a layer that an old revision's HTML cannot render under.
105117
- **Leaf joins the conversation the user has open in Codex.** Excludes the official SDK,
106118
which starts its own Codex (and bundles a 113 to 138 MB binary per platform). Open
107119
question: is the shared conversation a product requirement? If not, 758 lines of
108-
hand-written protocol code go.
120+
hand-written protocol code go. The website host in `worker/server.py` already spawns
121+
its own app-server, so the SDK's limit does not reach it; adopting the SDK there alone
122+
would run two clients for one protocol beside `codex.py`.
109123
- **Package authors describe widgets in JSON Schema.** 474 lines of meta-schema check
110124
those descriptions. Proposal: typed declarations (pydantic is installed through `mcp`)
111125
when packages are next revisited.

0 commit comments

Comments
 (0)