Repository navigation
refactor(mobile): the terminal document is a function of its host (OTA phase C, C7.5b) - #21859
Conversation
The document is already pinned as a digest, which says whether the emitted bytes moved and nothing about where. C7.1 moves the hand-written script inside it into modules the web page can import and rebuilds the document from them, and the claim that has to hold through every one of those commits is that the native screen kept the document it had. A digest cannot be the instrument for that: it fails as two hexadecimal strings. So the document is also committed as itself. The fixture is generated by `scripts/build-terminal-document-fixture.mjs`, never pasted, and the test rebuilds the comparison through that script's own substitution rather than restating it, so a fixture written by one rule and read by another cannot agree with itself. The generated xterm engine is stored as two placeholders. It is already covered by the digest test, postinstall regenerates it from whatever xterm the lockfile holds, and inlining it would put 612 KiB of vendored bytes into the file whose job is to isolate hand-written changes. Two further cases keep that from becoming a hole: the placeholders must each appear exactly once and the engine must not appear at all, and the restored document must equal the real one. Regenerating the fixture is a review event. It is only correct when the emitted document was meant to change, and the diff in that commit is the evidence. Red-first: flipping one character inside a comment in `write-queue.ts` fails both identity cases with a one-line diff naming the comment, where the digest test reports a hash. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The C7.1 flip commit moves the document's 57 reassigned variables onto a scope object, because a variable assigned across ES modules is a syntax error, and every read and write of them gains a qualifier. The ruling asks that the review of that commit be a test rather than a 515-line read. This is that test's instrument. It cannot be a byte comparison. Once the script's source is modules, `oxfmt` owns its style, and the repository's style has no semicolons where the hand-written document has one on nearly every line. A byte diff would therefore be dominated by changes that are not the refactor, which is the opposite of what the reviewer needs. So the comparison is over tokens: semicolons are excluded for the same reason they moved, comments never reach the stream, and one difference is allowed — `name` becoming `<qualifier>.name`, three tokens for one — which it counts and reports. It is stricter than "it still runs": a reordered statement, a changed literal, a dropped operator, a renamed local and a qualifier under the wrong object name all diverge, each reported with the token index and both sides. Acorn carries `value` on its tokens but does not declare it, so the field is read through a narrowing check rather than asserted onto the declared type. Red-first, by mutation: dropping the qualifier-name check fails the case that names it; removing the leftover-token check fails the dropped- and added-statement cases; treating semicolons as significant fails the three cases that depend on ignoring them. The acceptance case runs on the real 2,758-line script rather than on a fixture, so the instrument is known to survive everything the document actually contains. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
Measured while extracting the first group: the document's ES5 style is not a
style this repository's own rules permit. `curly` braces 279 brace-less
if/else/for/while bodies, `no-unused-vars` unbinds 38 catch clauses, and 446
`var` declarators become `const`, `let` or a scope field. Those rewrites land
before the qualifier is considered at all, so "the qualifier and nothing else"
was never reachable once the source is a linted module.
The comparison now allows exactly four classes and counts each on its own: a
reference that gained the qualifier, a declaration that moved onto the scope
object, a `var` that only changed keyword, a body that gained braces, and a
catch clause that lost its binding. Separate counters rather than a total,
because the flip commit pins each number and a total would let one class absorb
another — which is the drift the pin exists to catch. The two `var` classes
partition the 446, and the qualifier's 641 sites partition into references that
kept their declaration and declarations that moved.
Two ordering facts the cases pin. The catch rule is tried before the brace rule,
or the inserted-brace rule eats the `{` that follows `catch` and the streams
never resynchronise. A body braced at the very end leaves its closing brace
after the baseline has run out, so trailing closes are absorbed after the walk
rather than reported as a length difference.
Everything outside the four classes still refuses with the token index and both
sides: a changed literal, a dropped operator, a reordered pair, a renamed local,
a qualifier under another object's name, a brace opened and never closed, and a
brace closed where none was opened.
Red-first, by mutation: disabling the catch rule, disabling the trailing-brace
absorption, folding scope-field declarations into plain references, and not
counting brace insertions each fail exactly the case that covers them.
Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…port The first of the twelve groups the document already names. `*-injected.ts` has been splicing JS strings into the document for a while, and tests evaluate those strings, so the one-source-two-consumers shape is already there; what is missing is that a string cannot be imported by the web page, typechecked, or linted. This turns one of them into a module and adds the generator that puts it back into the document. The generator is a transform, not a bundle: a bundler orders its output by the dependency graph, and the document's order is part of what the equivalence test holds fixed. Imports are dropped rather than resolved, because inside the document every name is already in scope — that is what the single IIFE means — and `document-externals.ts` declares the names whose groups have not moved yet and emits nothing at all. esbuild prints an ESM module's exports as a trailing block, so that block is dropped whole rather than by its keyword; leaving the keyword behind would put a bare block statement in the document. Both sides of the comparison now go through that same printer before being read. Otherwise every choice the printer makes — semicolons, property shorthand, quote style — reads as a difference in the program when it is a difference in who typed it, and each would need its own rule. A script that does not parse is reported as a refusal naming its side, not thrown. `let` is contextual outside strict mode, so acorn reports it as a name and not as a keyword; without that the var-to-let rewrite the linter performs would be refused on every reassigned local. The group's counts are pinned exactly: nine references gained the qualifier (`term` seven times, `panX` and `panY` once each), nine locals became `const` or `let`, thirteen one-statement `if` bodies gained braces, no declaration moved onto the scope object and no catch clause lost a binding. The document is untouched, so the byte pin from 3006d8d is still green. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The second of the twelve groups, and the one that corrects the scope table's
membership rule.
`terminalDataRepliesEnabled` is written from four places, so the whole-script
census counted it among the 57 variables that cannot stay free across modules.
All four writes are in this group. Once the script is modules, a variable
written only inside the module that declares it is that module's own state, not
the document's, and it stays a `let` there. So the scope object holds what
crosses a module boundary, and the 57 is an upper bound rather than the answer;
the qualifier count the flip commit pins will be lower than the 641 measured
over the single scope, and by how much is a function of where the boundaries
fall.
Two references do cross here and are qualified: the write-queue generation this
group compares against, and the observer-disposal list it pushes onto.
Counts pinned: two qualified references, one `var` to `let`, two one-statement
`if` bodies braced, both `catch (e) {}` clauses unbound, no declaration moved.
The document is untouched, so the byte pin is still green.
Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…n tests The third group, and the defect it found: esbuild wraps a long import list across lines, and the generator was skipping only the first of them, which left the remaining names loose in the emitted script. The document did not parse, and the equivalence check said so by name rather than throwing — which is what that refusal path was added for. Both lists, import and export, are now skipped to their closer instead of by their first line. The generator's own tests cover what the per-group comparisons cannot say on their own: an export is unmarked and indented into the document scope, a one-line import is dropped, a wrapped import is dropped whole, the trailing export block esbuild prints is dropped rather than left as a bare block statement, and types are erased without touching the program. Reflow's counts: eleven qualified references — the terminal ten times and the settled row count once — six locals that became `const`, and the two early returns braced. The row count is written from three groups, so unlike the query-reply flag it is the document's state rather than one module's. The document is untouched, so the byte pin is still green. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The fourth group, and the first that needed a non-null assertion.
`lineHasVisibleContent` reads the terminal's column count with no guard of its
own; the guard is in `computeContentBottomRow`, which is its only caller. Adding
a guard would change the program, and optional chaining would change what
happens when there is no terminal — the document throws there today. TypeScript
erases a non-null assertion, so the emitted script is unchanged and the
invariant is written down where the reader needs it.
Reflow now imports the metrics call from this module rather than declaring it an
external, which is the shape every group takes as its neighbours arrive.
Counts: fourteen qualified references, nine locals rebound, ten one-statement
bodies braced, and the two `catch (e) {}` clauses — the row scan and the
alternate-screen probe — unbound.
The scope table's rule is stated more precisely with it: a variable is this
module's own only when the group both declares and assigns it. While the rest of
the document is still strings, one the main slice declares stays shared even if
every use is in one group, because emitting a second declaration beside the one
the slice still carries would not be the same program.
The document is untouched, so the byte pin is still green.
Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The fifth group, and the first carrying a top-level statement rather than only declarations: the visibility listener it registers. In the document that runs when the IIFE reaches it; as a module it runs on import, which is the same single registration. The context-loss listener disposes the addon it is registered on, so it cannot run before that addon exists, but the assignment is to a `let` a closure captures and TypeScript will not carry the narrowing across it. A non-null assertion, erased by the compiler, keeps the emitted script identical and puts the invariant where the reader is. Counts: twenty-three qualified references across the terminal, the addon, its retry timer and the theme the host last sent; three locals rebound; twelve one-statement bodies braced; five of the six catch clauses unbound, the sixth keeping its binding because the attach failure reads the error into its diagnostic. The document is untouched, so the byte pin is still green. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…fifth class The sixth group found a rule the four classes do not cover, so I measured the whole script rather than meeting them one at a time: linting all 2,757 lines as a module trips `curly` 279 times and `no-unused-vars` 38, both already counted, and then five further rules at 23 sites — `prefer-number-properties` 17, `prefer-includes` 2, `no-useless-escape` 2, `prefer-exponentiation-operator` 1 and `no-unused-expressions` 1. Seventeen of those 23 are one rewrite: a global numeric function moved onto `Number`. It has the same token shape as the qualifier, so it is counted as its own class rather than folded into anything, and only the four numeric globals are admitted — anything else appearing under `Number` is refused, which a case pins. Every site is already behind a `typeof … === 'number'` check or is parsing a string, so the two forms are the same test. The remaining six sites are each a different shape and too few to be worth matching; they will surface as refusals in whichever group carries them, and I will report each rather than widen this. The scroll accumulator is the first declaration to move onto the scope: it is declared in this group but a touch scroll in another slice resets it, so the `var` becomes an assignment to the shared field and the class that exists for exactly that counts one. Counts: five qualified references, one declaration moved, four locals rebound, eight bodies braced, one `Number` rewrite. The document is untouched, so the byte pin is still green. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The seventh named group. `surface` and the uncommitted terminal are read by other slices, so both move onto the scope; the two committed handles and the pending surface are declared and assigned only here and stay module locals. Counts: qualified 7, scope declarations 1, rebindings 4, braced bodies 2, unbound catches 2, number properties 0. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The document's script text is not all hand-written: parts of it are template literals interpolating real values, starting with the theme background. A module cannot interpolate and still be the same program, so the generator now derives an esbuild `define` from `document-constants.ts` and substitutes after the import lines are dropped, when the names are free again. The page imports the very same bindings, so there is one source either way. The fixture script's TypeScript loader moves beside it rather than being written twice. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The eighth named group, and the first parameterised one: its background
fallback comes from the mobile theme through `document-constants.ts`.
Two sites carry a line-scoped lint disable rather than the rewrite the rule
asks for: `indexOf(',') >= 0` and `Math.pow`. Both rewrites are outside every
normalisation class the equivalence instrument counts, so taking them would
change the program the native document carries, which is the one thing this
branch holds fixed. The reason is on the disable line.
Counts: qualified 12, scope declarations 0, rebindings 28, braced bodies 13,
unbound catches 0, number properties 9.
Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The ninth named group, and a pure query: it reads no shared state, so it has no qualifier sites at all. Two things this group forced. The generator now drops lint directive lines before the transform, because a directive inside an expression makes esbuild parenthesise that expression to keep the comment where it was, and those parentheses are tokens the document does not have. And the two regexes keep their `no-useless-escape` escapes behind a line-scoped disable, for the same reason the theme group keeps `Math.pow`. One name the document declares twice in one function stays `var`. Two block-scoped declarations would be two bindings where the document has one, and esbuild renames the inner one to say so. Counts: qualified 0, scope declarations 0, rebindings 31, braced bodies 20, unbound catches 0, number properties 2. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The tenth named group, and the heaviest reader of shared state: the selection, its elements, its thresholds and both press origins are all declared by the overlay slice, which is still document text, so all of them move onto the scope with their declarations left where they are. Counts: qualified 49, scope declarations 0, rebindings 15, braced bodies 11, unbound catches 0, number properties 0. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…module The eleventh named group. The escape byte and both SGR mouse modes join the scope from the runtime slice; the gesture itself is declared here and never read outside, so it stays a module local. Counts: qualified 17, scope declarations 0, rebindings 22, braced bodies 27, unbound catches 1, number properties 0. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The twelfth and last named group, and the second parameterised one: both candidate patterns and the length bound come through `document-constants.ts`. Three modules rather than one. At 303 lines it was over the file cap, and the document's own order interleaves the OSC 8 lookup with the file-URL parsing, so the split follows that order and the group's text is the three emissions joined. The test does the joining. Note for a later lane: `terminal-webview-url-tap.ts` and `terminal-file-url-tap.ts` already hold TypeScript twins of some of this, written for the React Native side and not identical to what the document carries. Collapsing the two is a behaviour change and does not belong in a branch whose whole claim is that the document did not move. Counts: qualified 10, scope declarations 0, rebindings 41, braced bodies 25, unbound catches 6, number properties 4. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The first of the thirteen inline slices. Both control-sequence introducers, the straddling scan tail and all three mode fields are declared by the runtime-state slice, which is still document text, so they move onto the scope with their declarations left where they are. Counts: qualified 20, scope declarations 0, rebindings 10, braced bodies 9, unbound catches 0, number properties 0. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…dule The script and the document end in the same slice, so the slice splits in two at the point where the IIFE closes: the script half becomes a module, the document half stays text. The byte pin proves the join is unchanged. The second catch keeps its binding: it names the error and reports it. Counts: qualified 1, scope declarations 0, rebindings 1, braced bodies 0, unbound catches 1, number properties 0. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The previous commit put two exports in one slice file, which the slice-count guard reads as a mismatch: it derives the slice list from the composer's imports and cross-checks it against the composed entries, one per file. Five suites failed to load. Splitting the file rather than the constant is the better shape anyway. The file was called `message-bridge-and-document-close` because it carried two concerns; now each has its own. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
This slice interpolates the already-extracted keyboard-avoidance group between
its own two halves, so its text is three emissions joined in that order and
the test does the joining.
A sixth normalisation class, measured here rather than assumed: the printer
writes `{ name: name }` back as shorthand, and qualifying the value makes the
property name unavoidable again, so one baseline token faces four. It is
counted on its own like the others, with its own acceptance case in the
instrument's test, and every existing group's pin now carries a zero for it.
Counts: qualified 36, scope declarations 1, rebindings 12, braced bodies 12,
unbound catches 6, number properties 0, shorthand properties 4.
Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
… a module The slice that declares most of the shared selection state: every threshold, every overlay element and the selection itself, twenty-two scope declarations in one place. The eviction counter is declared and assigned only here, so it stays a module local. Counts: qualified 12, scope declarations 22, rebindings 2, braced bodies 3, unbound catches 0, number properties 0, shorthand properties 0. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
Two modules, not one: the slice carries the normal-buffer smooth scroll and then the cell-to-pixel geometry, and the split follows that order so the group's text is the two emissions joined. Four names stop being externals and become real imports. Counts: qualified 39, scope declarations 0, rebindings 15, braced bodies 16, unbound catches 0, number properties 0, shorthand properties 0. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The slice also carries `disposeTermObservers` and `extractMouseModeScanTail`, which belong to other concerns but sit here because emitted-document order pins them here; four names stop being externals as a result. The observer disposal keeps its guard-as-expression form behind a line-scoped disable: the rewrite the rule asks for is outside every counted class. Counts: qualified 50, scope declarations 0, rebindings 11, braced bodies 10, unbound catches 1, number properties 0, shorthand properties 0. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The slice opens with the already-extracted theme group, so its text is two emissions joined. Four more names stop being externals. Counts: qualified 47, scope declarations 0, rebindings 47, braced bodies 20, unbound catches 0, number properties 9, shorthand properties 0. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…dule The slice opens with the already-extracted webgl-recovery group, so its text is two emissions joined. init() resets almost every field the document shares, which makes this the densest qualifier site in the script. The caret options were interpolated from the theme module, so they join `document-constants.ts` as four exports: a substitution is keyed by name, not by property path. One local the document declares and never reads keeps a line-scoped `no-unused-vars` disable. Removing it would be a different program, which is the one thing this branch does not do. Counts: qualified 83, scope declarations 0, rebindings 11, braced bodies 18, unbound catches 7, number properties 0, shorthand properties 0. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The document's declaration block, where almost everything it shares is declared, with the query-reply and surface-swap groups interpolated inside it. Three modules: the two declarations that come before the groups, the text scaling, and the viewport transform with the scroll indicator. Seven more names stop being externals. Two things this slice forced. The scope-declaration rule now counts each declarator of one `var`, because `var panX = 0, panY = 0` becomes two assignments onto the scope. It has its own acceptance case in the instrument's test. The two halves are compared against their own text rather than as one joined program. The declaration the slice opens with is shadowed by a parameter inside one of the interpolated groups, and printing the baseline as one program renames that parameter; qualifying the outer name removes the shadow, so the rename has nothing to correspond to. Splitting the slice on the group constants compares like with like, and those groups have their own tests. Build-time constants are now substituted textually rather than through an esbuild `define`: a `define` whose value is an object or an array is injected as a helper binding instead of being inlined. Counts, head: scope declarations 2. Tail: qualified 31, scope declarations 38, rebindings 25, braced bodies 13, unbound catches 1. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
Two modules around the already-extracted mouse-report-cell group: the viewport cell lookup that precedes it, and the mouse input encoding and scroll routing that follow. Eight more names stop being externals, which leaves ten. Counts: qualified 49, scope declarations 0, rebindings 49, braced bodies 42, unbound catches 3, number properties 0, shorthand properties 0. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
Two modules after the already-extracted reflow group: the postMessage bridge with the engine error reporting that rides on it, and the router itself. `notify`, `handleMsg` and `reportEngineError` stop being externals, which leaves seven. The catch binding handed to the error reporter keeps a cast: a catch variable is `unknown` under strict mode, and the reporter reads only `message` before falling back to `String()`. The reason is on the line. Counts: qualified 48, scope declarations 0, rebindings 20, braced bodies 12, unbound catches 2, number properties 0, shorthand properties 0. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
Two modules after the already-extracted path-tap and url-tap groups: the selection range with the xterm mirror, and the overlay positioning with the edge scroll. Six more names stop being externals, which leaves one. Counts: qualified 77, scope declarations 0, rebindings 96, braced bodies 63, unbound catches 9, number properties 6, shorthand properties 0. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
Ruling 22, commit 1 of C7.5b. The generator's concatenation already gave the 38
modules one function scope with one local `scope`; naming that scope a function is
what makes it the shape both hosts run, and what will let the page have its own
state per mount instead of a module singleton with a reset between them.
`createTerminalDocument(host)` is emitted around the same module bodies, in the
same order, followed by the same start sequence. It then declares `stop`, which
calls every module's stop in reverse order and takes back the frames the document
is still owed, and returns `{ send: handleMsg, stop }`. The native document is
that function plus one call with no argument, which is what the WebView has always
run: no argument means every seam is the window read it already did.
`createTerminalDocumentScope` takes the host and spreads the hooks it names over
the window defaults, filtering undefined so absent and present-but-undefined mean
the same thing. The emitted scope declaration is the one line the host reaches, so
the generator rewrites it and refuses if the line it expects is not there — a
rename would otherwise leave every call on the defaults with nothing to say so.
The golden moves by the wrapper and that one line, and by nothing else. 108,329 to
108,831 bytes, the whole diff:
-(function() {
+function createTerminalDocument(host) {
- function createTerminalDocumentScope() {
- return { ...createTerminalDocumentState(), ...createTerminalDocumentHostSeams() };
+ function createTerminalDocumentScope(host = {}) {
+ const named = Object.fromEntries(Object.entries(host).filter(([, hook]) => hook !== void 0));
+ return { ...createTerminalDocumentState(), ...createTerminalDocumentHostSeams(), ...named };
- const scope = createTerminalDocumentScope();
+ const scope = createTerminalDocumentScope(host);
-})();
+ function stop() {
+ stopSurfaceTouchGestures();
+ stopTapDispatch();
+ stopSelectionOverlay();
+ stopNormalBufferSmoothScroll();
+ stopHostNotify();
+ stopTerminalInit();
+ stopWebglRecovery();
+ stopFitScale();
+ stopViewportTransform();
+ cancelDocumentFrames();
+ }
+ return { send: handleMsg, stop: stop };
+}
+createTerminalDocument();
The byte golden and the payload hash are re-pinned once: 726,363 to 726,865 bytes,
sha256 9950f177 to c7bbcb0b.
Four test files sliced the document with their own copy of the IIFE bounds, which
ruling 17 allows moving. They now share one reader in the test-support module
beside the one that locates a single module, and that reader names the factory and
its call. Every assertion is unchanged. The module-order guard and the region
reader compare against the text the document carries rather than a raw emit, since
the scope module is the one the generator rewrites; both go through one exported
function so neither can describe the rewrite differently from the generator.
`TerminalDocumentHostSeams` and the new `TerminalDocumentHost` moved to
`document-host-seams.ts`, which owns the six functions they type. Types emit
nothing, so the golden is unchanged by the move; it keeps `document-scope.ts`
inside its 300-line cap with no disable and no bump.
Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…ctory # Conflicts: # mobile/scripts/build-terminal-document-script.mjs # mobile/src/terminal/document/document-host-seams.ts # mobile/src/terminal/document/document-module-order.test.ts # mobile/src/terminal/document/document-scope.ts # mobile/src/terminal/document/generated-document-region.test-support.ts # mobile/src/terminal/terminal-document-golden.txt # mobile/src/terminal/terminal-webview-payload-hash.test.ts
…ebView's Ruling 23, and the first half of C7.5b commit 2: the artifact the page will import. The page cannot run the native script, because building a function from a string needs `eval` and the page's policy refuses it, and it cannot run the modules either, because they are one singleton while the whole point of the factory is a scope per call. So one emitted body gets two wrappers. `buildTerminalDocumentFactoryBody` is now the shared half: the modules in order, the start sequence, the stop handle and the return. The native script wraps it in the declaration and the trailing call, exactly as before. The new `terminal-webview-document-factory.generated.ts` wraps the same lines in a `@ts-nocheck` module whose only other content is the type import and the annotated signature. One generator run writes both, so the page's factory cannot be a build behind the WebView's. `@ts-nocheck` covers this one generated file. Every line of its body is esbuild output from a module that was type-checked at its source, with `declare global` blocks and type re-exports already erased and constants already substituted; the one line a caller reads is the signature, and the generator writes it with its types. `TerminalDocument` joins `TerminalDocumentHost` in `document-host-seams.ts` as the shape the factory returns. The pin is byte equality. `document-factory-artifacts.test.ts` strips each wrapper and holds the remaining text equal, so the byte golden pins the page's artifact by construction rather than by a second golden; it also reads the file on disk against what the generator would write now, since that file is gitignored and built by postinstall, and it refuses a trailing call in the page's copy, which would start a document as the module was imported. The path joins `.gitignore` and the oxlint ignore list beside the engine artifact. The consumer census gains the generated file by name: it is the document, and its one import is the host contract its signature is written against. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The page's half of ruling 23, and ruling 24. The mount plants the markup and calls the factory; the handle is `send` and a `dispose` that stops it. The document is a function, so the page holds an object per call and nothing else. Deleted with the singleton it was written for: `page-document-modules.ts`, the claim token and `liveDocument`, `release`, the owner-checked `dispose`, the second-mount refusal, `resetTerminalDocumentScope`, the `adopt` callback, `ready` and every pending-import path. All of it existed because two mounts shared one module-level scope and because the handle had to come back before its import did. A call is a document now, so a second mount cannot reach the first one's state and a caller's cleanup cannot arrive before there is something to clean up. The second-mount refusal is not replaced by a one-line guard: with a scope per call there is no shared state left to refuse for, and a host element with two documents planted in it is the caller's own doing, visible on the screen. Ruling 24 splits `message-bridge` by what it is, which is what made the page able to run this text at all. Two more seams, eight now: `installHostTransport`, whose window default installs the `message` listeners on window and document and hands back their removal, and `hasEngine`, whose default is the `window.Terminal` the engine bundle installs. The page answers a transport that installs nothing, because its transport is the handle, and an engine that is always there, because the engine is the import above. So the page no longer takes the shell's frames or reports a missing engine on every mount, and `stopMessageBridge` takes the listeners off — the WebView never removed them, which ruling 21 asks for. The refit the bridge happened to own moves to `fit-scale`, which is whose work it is; both hosts start it, and the mount's hand-copied five calls are gone. The engine's disposal moves into `stopTerminalInit` for the same reason: the mount cannot reach the scope any more, and a stopped document's terminal is a WebGL context nothing will read again. The start sequence the generator emits is now inside the document's own undo: a start that throws runs `stop` and rethrows, so neither host can be left holding a listener from a build that failed. That replaces the deleted entry module's unwind, and it covers every start rather than the four that had one. Readiness arrives the same way on both hosts. The document posts `web-ready` through `postToHost`, which the controller already handles, so the mount-side `confirmWebReady` is gone. That flush is also the one caller that reaches `post` before the effect has a handle, which is why the component's queue stays and now says so. The golden and the payload hash move, 102 diff lines: the two seam defaults and their state fields, the reset gone, `startFitScale`, the disposal, the bridge over its seams, and the start sequence inside its try. Tests: the seam tests and the unwind test move to the factory and the derived start sequence; the frame registry builds a fresh scope instead of resetting one; the two mount test files and the page entry's order test go with their subjects. The render check keeps every behavioural case and loses two whose subject the static import removed — a Reload while the chunk is in flight, and a chunk that will not load, which is now the route's chunk rather than the document's. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…lates Ruling 22 answers what ruling 21's state half was for. A module's top level is emitted inside the factory, so a `let` there is one binding per call — which is exactly what moving it onto the scope was achieving. The census that refused it, and the planted-module precondition beside it, go. The effect half stays, and the distinction is what a stop can reach. An effect in a module body runs at the position its module is emitted rather than in the start sequence, so no stop function undoes it and each call leaks another one. A binding leaks nothing. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The helper reaches its neighbours through a variable specifier, which the bundler answers by rewriting as a glob — and it refuses to glob the directory the import is written in, so every suite that loads this file printed the refusal twice. `@vite-ignore` leaves the specifier alone and the module runner resolves it, which is what was already happening. An extension does not help: with one the refusal becomes the own-directory rule, and the path alias is not resolved for a runtime specifier at all. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The factory arriving is not the whole -1,890. Making the document a factory put the `host` argument on `createTerminalDocumentScope`, which is this lane's only edit to a module the closure already carried, and that alone is +80. Both numbers are in the note now, so neither commit's cost is read as the other's. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The last thing two documents on one page shared. Ruling 22 gave each call its own scope, but the element reads were `document.getElementById` and the ids are in the markup every host plants, so the second document's start sequence took the first host's surface, overlay, handles and menu — two documents driving one terminal, with the second host left empty. Reachable, not theoretical: expo-router keeps the outgoing screen mounted for the length of a stack transition, so two routes that both hold a terminal have two live documents on the page while the animation runs. `root` joins the host argument and `elementInRoot` is the one reader; the ten reads in runtime-constants, surface-swap, selection-state-and-eviction and text-scaling go through it. No id is renamed and nothing is refused: two documents on one page are two terminals. Two deviations from the ruling, both about *when* the default is read. `root` is `ParentNode | null` with null meaning "the page I am in", rather than defaulting to `document`: a data default is evaluated whenever a scope is built, which put a DOM read into every slice evaluation and took eight keyboard-avoidance cases down with a `ReferenceError` in their `vm` context. Null defers it to the read, which is the rule the eight seams above it already follow. And the reader lives in `document-host-seams.ts`, which declares the type, taking the root as an argument: in `document-scope.ts` it was four lines over the file's 300 (no bump, no disable). Red first, and the red was the second document: with a page-wide read the second engine opens on an element outside its own host. `document-host-root.test.ts` plants two hosts, starts a document in each, and reads which surface each engine was opened on through the `createTerminal` seam, because the scope is not reachable from outside. Falsified again after the fix by pointing the emitted reader back at `document`: red, one case. Two neighbours checked while here. The document-level touch listeners are already host-scoped, because every handler tests its target against the scope's own surface, overlay and handles, which are now this document's. `window.__engineErrors` is the one page global left, and it is now kept rather than replaced per mount: a capped diagnostic buffer, where a second mount was costing the first its captured lines. Golden 27 diff lines, hash and length repinned: the reader, the `root: null` default, and the ten reads. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…ctory Main at 3b055c8. No conflicts and nothing under `mobile/`: the incoming work is relay wave tooling, release workflows and WSL plugin install. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…eturns The double was reaching `createTerminal`'s return type through `as unknown as Parameters<typeof queueMicrotask>[0] & never`, which the type-aware gate reads correctly as an intersection with `never` and which was a cast standing in for naming the type. `TerminalDocumentTerminal` names it. Every member the type declares is present — the ones `init` and the start sequence reach do something, the rest answer in the shape their caller reads — and the shape needed no narrowing to accept a double. Two things the type does not declare moved off it: where `open` was called is handed back beside the terminal rather than exposed as a second getter, so the literal carries nothing excess, and the buffer gained the `getLine` the type requires. No cast, so nothing to write a SAFETY line about. Still red without the fix, checked again after the retype by pointing the emitted reader back at `document`: one case. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
|
Understand this PR’s impact Explore downstream dependencies and potential security impact with Blast Radius. Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughThe terminal document changes from a generated IIFE to a reusable Priority: ➖ Normal 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description gives extensive technical context, rationale, linked PR information, and verification results. However, it does not follow the required template structure and omits required or incomplete sections, including Visual Proof, the explicit Linked Issue format, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist. Resolution Update the description to use the required section headings. Add visual proof or write exactly
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
… host (OTA phase C, C7.5b round 1) Round 1 H1. The dispatcher's four listeners are on `document`, so with two documents on one page (legitimate since `712daa80e6`) each is handed the other's touches, and the two-finger branch acts before any target filtering: a pinch in host B posted `mobile-clip-cancel-by-pinch` from document A and dropped A's selection. Fixed at the source, one predicate beside `elementInRoot`, asked once at the top of each handler rather than inside a branch. `root === null` is the WebView, where the document is the page, so it answers yes to everything and the native document is unchanged. `e.target` is the element the finger went down on for the life of the touch, so a select-drag travelling outside the host still answers yes on move, end and cancel. Census of every global listener install under `src/terminal/document/` (non-test): - `tap-dispatch.ts:241-244`, four capture-phase `document` touch listeners (touchstart, touchmove, touchend, touchcancel): MUST be root-filtered; this fix. - `document-host-seams.ts:165-166`, `window`+`document` `message` in `installWindowHostTransport`: WebView-only. It is that host's transport seam default and the page installs nothing (ruling 24), so no page carries two. - `fit-scale.ts:163`, `window` `resize`: page-wide by nature. A viewport change concerns every document on the page and the event has no target in either host; both must refit. - `webgl-recovery.ts:104`, `document` `visibilitychange`: page-wide by nature. Backgrounding concerns every document on the page; its target is the document. - No document-level mouse, wheel, keyboard or selection listener exists: those are all on `targetSurface` or the menu buttons, read through `elementInRoot`, so they are already inside their own host. Red-first, the reviewer's own repro in `document-host-root.test.ts`: A and B both in select mode, a two-finger touchstart in B's surface. Before: 2 failed (A posted the pinch cancel too, and the control in A's own host cancelled B). After: 3 passed. The control keeps the assertion honest — the same touch inside the document's own host still cancels its selection. Golden and payload hash move (regen is a review event): six hunks, +22/-1. `eventTargetInRoot` emitted after `elementInRoot`; `touchIsThisDocuments` after the CAPTURE constants; the three-line guard at the top of each of the four handlers; `onDocumentTouchCancel()` becomes `onDocumentTouchCancel(e)`. Document 728,119 -> 728,589 bytes, sha256 5b65315b... -> 1556f532... Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…aches (OTA phase C, C7.5b round 1) Round 1 M2. `terminal-web-document-mount.ts` had no unit test: the only reading of it was the render check, which drives the whole page bundle in a browser — right for behaviour, too coarse for three lines that only a failure reaches. The body's "five test files whose subjects no longer exist" is wrong for three of them. What ruling 22 deleted was the machinery (the claim token, `liveDocument`, the owner-checked dispose, the second-mount refusal); these three subjects survived it and lost their only cover: - both engines disposed when a swap never committed (`terminal-init.ts:203-213`); - the host given back when a start throws (`startDocumentOrGiveTheHostBack`); - the component naming that throw's cause (`TerminalWebView.web.tsx:83`). `terminal-web-document-mount.test.ts` (happy-dom) covers all three against the real generated factory. Only the factory's *arrival* is mocked, delegating to the real `createTerminalDocument` except for the one case that makes a start throw, so no stub stands in for the program under test. Six cases, each red against a deliberately broken line: - two distinct terminals both disposed. Broken `new Set([scope.term, scope.committedTerm])` -> `new Set([scope.term])`: expected [1,1], got [0,1]. - the same terminal disposed once. Broken the set -> a plain array: expected 1, got 2. The pair is the dedup's own oracle; either half alone passes for the wrong reason. - the host emptied and the class dropped on a throw. Broken by deleting the two lines in the mount's catch: host still carried `#terminal-container`. - control: a live document keeps the markup and the class, so the two assertions above cannot pass for a mount that planted nothing. - `onEngineError` gets `terminal document failed to start - engine missing`. Broken by deleting the component's `receive` in its catch: expected one message, got none. - control: nothing reported when the document starts. The engine double moves to `document-terminal-double.test-support.ts` and both readers of the seam share it; a second hand-written copy of thirty members would drift as the shape grows. It now counts disposals beside reporting `open`. Terminal suite 67 files / 625 tests -> 68 / 631. No product line changed, so the golden and the payload hash do not move. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
… would break now (OTA phase C, C7.5b round 1)
Round 1 M1 and L2.
M1, the mount's stylesheet comment was one version behind: it said the document
reads its elements with `document.getElementById`, which `712daa80e6` replaced
with `elementInRoot`, and drew its shadow-root conclusion from that read. Both
halves re-derived rather than reworded. A shadow root no longer breaks the reads
(`elementInRoot` is a `querySelector` under the host, which a shadow root
answers); it breaks this sheet, because a rule in the document's head does not
cross a shadow boundary, so it would have to move inside each root and be parsed
once per host instead of once per page.
L2, `document-factory-artifacts.test.ts` anchored the page body at `):
TerminalDocument {` and nothing else, so the header, the `@ts-nocheck` line, the
`import type` and the parameter's own line could all drift with the test green —
and that signature is the one line a caller of the page's artifact reads. Both
wrappers are now literal lines: nine for the page (header, directive, import,
blank, the three-line signature) and one plus two for the native script
(declaration, closing brace, trailing call). Literal rather than the generator's
own constants, which would only agree with whatever it emits.
Red controls, each with the generator changed and then restored:
- the page's `import type` reordered to `{ TerminalDocumentHost, TerminalDocument }`:
2 failed ("the page module opens with its wrapper", and the on-disk reading).
- the native trailing call changed to `createTerminalDocument({});`: 1 failed
("the native script closes with its wrapper"). The old anchor caught neither.
No emitted line moved: golden and payload hash unchanged, terminal suite 68 files
/ 631 tests.
Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Document is now a factory —
build-terminal-document-script.mjsemitscreateTerminalDocument(host)around the same module bodies/order, a reverse-orderstop(), and a start sequence wrapped intry/catchthat callsstop()and rethrows; it returns{ send, stop }. The native script is that factory plus one hostless call. - Second artifact for the page (ruling 23) — the page statically imports the gitignored generated module
terminal-webview-document-factory.generated.ts;document-factory-artifacts.test.tsstrips both wrappers and holds the bodies byte-equal, so the byte golden pins both. - Per-call scope —
page-document-modules.tsand the singleton machinery (claim token,liveDocument,release,adopt,ready, second-mount refusal,resetTerminalDocumentScope) are deleted; each mount is a function call with its own scope, so stale callbacks and stale handles can no longer reach a live document. - Two new host seams (ruling 24) —
installHostTransport(page installs nothing; its transport is the returnedsend),hasEngine(page: true), plusstopMessageBridge; the resize refit moved intostartFitScale/stopFitScaleso both hosts get it. - Element reads are host-scoped —
elementInRoot(scope.root, id)replaces all tendocument.getElementByIdreads;rootis the host element on the page (null = whole document in the WebView), making two simultaneous documents on one page independent. - Teardown —
stopTerminalInitnow disposes bothscope.termandscope.committedTerm(deduped) and nulls them, absorbing the mount's oldteardownStartedDocument.
Verified this run against 8b6d8c2718: mobile src/terminal 67 files / 623 tests pass, tsc --noEmit clean, and the host-root fix is genuinely red-first (reverting elementInRoot to read document fails document-host-root.test.ts). No stale references to the deleted symbols remain. Two non-blocking observations are noted in the snapshot: the plant in mountTerminalWebDocument is no longer inside the old release() unwind, and the deleted chunk-failure render cases have no replacement covering the new synchronous start-failure overlay path.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: fc6e7f57-6490-4170-8465-9b95f185ef73
📒 Files selected for processing (9)
mobile/src/terminal/document/document-factory-artifacts.test.tsmobile/src/terminal/document/document-host-root.test.tsmobile/src/terminal/document/document-host-seams.tsmobile/src/terminal/document/document-terminal-double.test-support.tsmobile/src/terminal/document/tap-dispatch.tsmobile/src/terminal/terminal-document-golden.txtmobile/src/terminal/terminal-web-document-mount.test.tsmobile/src/terminal/terminal-web-document-mount.tsmobile/src/terminal/terminal-webview-payload-hash.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- mobile/src/terminal/terminal-web-document-mount.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.
…OTA phase C, C7.5b round 2) Round 2's residual of `9824145e1f`'s class, one level in. `eventTargetInRoot` settles whose event it is; every branch then counts `e.touches`, which is every finger on the screen. A finger resting in host A is therefore B's second finger: a one-finger touch in B's own surface reads `length === 2`, latches a pinch and drops B's selection, and on touchend `length === 0` is never true so B's surface tap never fires. `touchesInRoot(root, touches)` beside `eventTargetInRoot` returns this document's own fingers, and every count and index reads through it. A list rather than a count, because `touches[0]` and `touches[1]` are page-wide in exactly the same way as `touches.length` — the first finger on the screen may be the other terminal's. `root === null` is the WebView, whose fingers are all its own: the list is returned untouched, so nothing is allocated on a path that runs at frame rate. Census of every `touches` / `changedTouches` / `targetTouches` read under `src/terminal/document/` (non-test). There are no `changedTouches` or `targetTouches` reads at all; every read is `e.touches`: - `tap-dispatch.ts`, 15 reads across the three handlers that take an event (`[0]`, `[1]`, `.length`, and the list handed to `touchById`): MUST be filtered. The document listens on `document`, so the event and its list are both page-wide. - `surface-touch-gestures.ts`, 18 reads across its touchstart, touchmove and touchend handlers: MUST be filtered. These listeners are on the document's own surface, so the event is always this document's — but the list inside it is still every finger on the screen, which is the whole defect. - `tap-dispatch.ts:21-24`, `touchById(touches, id)`: no filtering of its own. It reads whatever list it is given, and all three callers now hand it a filtered one; its parameter widens from `TouchList` to `ArrayLike<Touch>`. Red-first in `document-host-root.test.ts`, the reviewer's two repros, with the three product files at `aba99c3e4f` and the artifacts rebuilt: 2 failed / 3 passed (pinch cancel posted with one finger on B's overlay; `terminal-tap` never posted). With the fix: 5 passed. The pinch-inside-own-host control stays, and the first repro lands on B's menu pill rather than its surface, because a single finger on the surface dismisses a selection by design — on the pill, keeping the selection is the whole assertion. `document-host-seams.ts` also rewritten in the present tense where it read as history. Golden re-pinned: 19 hunks, +51/-33. `touchesInRoot` emitted after `eventTargetInRoot`; one `const touches = touchesInRoot(scope.root, e.touches)` at the top of each of the six touch handlers, and every `e.touches` read inside them now reads `touches`. Document 728,589 -> 729,152 bytes, sha256 1556f532... -> 02633389... Correction to `9824145e1f`'s message: it cites `tap-dispatch.ts:241-244` for the four installs, which at that commit are `261-264` (the line numbers are the pre-fold ones from the review). Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Filtered the document's page-level touch listeners to their own host —
eventTargetInRoot(root, target)joinselementInRoot, andtouchIsThisDocuments(e)is asked once at the top of all four capture-phase handlers intap-dispatch.ts, so a pinch in one host no longer cancels another document's selection.root === null(the WebView) admits every target, leaving the native dispatcher unchanged. Covered red-first indocument-host-root.test.tswith a same-host control. - Gave the page mount its own unit tests —
terminal-web-document-mount.test.tsexercises the real generated factory for three paths no happy path reaches: a start that throws empties the host and dropsHOST_CLASS,stop()disposes both a committed and an uncommitted engine (viaterminalDocumentDouble.disposals()), and the component reports the throw's cause toonEngineError. - Pinned both generated wrappers as literal lines —
document-factory-artifacts.test.tsnow holds the native and page wrapper heads/tails to exact strings before comparing bodies, so wrapper drift on either side reds instead of being stripped as absent. The shareddocument-terminal-double.test-support.tsreplaces the inline double (thedocument/order census already excludes*.test-support.ts), and the shadow-root docstring now points at the head<style>, which is genuinely what a shadow boundary would break.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
`bd860f34c1` (#21687, OMP terminal momentum normalised across refresh rates) landed on main and moved the same three files this branch does. Document modules #21687 changed: `surface-touch-gestures.ts` only, and only inside the momentum loop of its touchend handler — `momentumStep` takes the animation frame's timestamp, holds `lastMomentumTime`, decays by `FRICTION ** (elapsed / 16)` and scales the delta by `elapsed` instead of a fixed 16 ms. It auto-merged with this branch's change to the line above it (`touches.length === 0`, fold 5), so the module carries both: the loop is main's and the count is this branch's. No other document module was touched by either side in the same file, and there was no module-level conflict to resolve. `terminal-document-golden.txt` and `terminal-webview-payload-hash.test.ts` conflicted because both sides re-pinned them. Resolved by regenerating from the merged modules (`node scripts/build-terminal-document-script.mjs`, then `build-terminal-document-fixture.mjs`), never by taking a side: the golden now carries main's six momentum lines and this branch's seven `touchesInRoot` lines, which is the only reading of the merge that is true of the modules. Golden byte length: 729,152 on this branch and 726,574 on main, 729,363 merged. Fixture 111,329 bytes. sha256 0263338994... (ours) and 775a129414... (main's) -> 0be398e4d7... Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run reviewed the two commits since the prior Pullfrog review at aba99c3e4f: the round-2 fix and the merge of origin/main.
- Filtered each document's own fingers out of the page-wide touch list —
touchesInRoot(root, touches)indocument-host-seams.tskeeps only touches whose ownTouch.targetis inside the host, and all sixe.touchesreads intap-dispatch.ts(3) andsurface-touch-gestures.ts(3) now go through it.touchByIdbroadens toArrayLike<Touch>.root === null(the WebView) returns the inputTouchListuntouched, so the native document allocates nothing and its dispatcher is byte-unchanged. - Covered red-first in
document-host-root.test.ts— a finger resting in host A no longer reads as host B's second finger (B keeps its selection), and B's own surface tap fires while A still holds a finger down (B's filtered count reaches zero). The test helper was refactored into a generalfireTouch(type, fingers, target)with each finger carrying its own surface. - Merged
origin/main(#21687) and regenerated both pins — the momentum loop insurface-touch-gestures.tsauto-merged (main'sFRICTION ** (elapsed / 16)andelapsed-scaled delta now sit below this branch'stouches.length === 0), and the conflictedterminal-document-golden.txt/terminal-webview-payload-hash.test.tswere regenerated from the merged modules: golden 729,363 bytes, payload sha2560be398e4…. I confirmed the golden carries both the momentum change and thetouchesInRootreads.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
Main is at 35005fb, one commit past the sha in the brief (`35005fb65c`, a `src/main` pi change, unrelated to mobile). Two conflicts, both against PR B (C7.10 item B, mermaid on the page), plus two counts the merge falsified. `mobile/.oxlintrc.json`: both ignore entries kept, this branch's generated page factory and PR B's generated page engine. `mobile/.gitignore` auto-merged carrying both artifacts; all six `*.generated.ts` on disk after the four postinstall generators run are exactly its six entries, with no strays. `config/scripts/mobile-web-app-session-terminal-closure.test.mjs`: the conflict is the docstring's reading, and both sides' explanations are kept. The number is re-measured on the merged tree rather than summed, which is what the sum would have hidden: main 35005fb modules 4324 local 974 merged modules 4284 local 934 (-40, -40) Main's own recorded 4323 was against ec82173 and main has drifted a module since, so the merged total is one above this branch's -40 added to PR B's +3. Both sides read with `mobileWebAppRouteClosure(SESSION_ROUTE)` and the four generators run first, main's in a scratch worktree detached at the same sha and removed afterwards. `MODULES_WITH_MERMAID` is renamed `SESSION_ROUTE_MODULES`, because the number is now neither side's alone. The byte reading is not re-measured and stays anchored at ec82173, since that function returns no byte total and a figure produced here would be a different computation. `mobile/src/test-support/census-source-files.ts` (PR B's walker) still excludes this branch's page factory: the predicate is the `.generated.ts` suffix, which the artifact's name carries. Verified on the real tree, not only in scratch — the walk over `mobile/src` returns 2,189 files with no `.generated.ts` among them while the artifact is on disk, and the same artifact copied to `.bundled.ts` comes back in the walk at 2,190. Its docstring said five artifacts and its test said a sixth would be the failure; both are one higher now, so both are corrected. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…re reading (OTA phase C, C7.5b) The merge's re-measured 4284 sat one above this branch's -40 added to PR B's +3, and the comment could only say main had drifted "a module of its own". It is `src/mobile-web-shell/bridge/bridge-haptics-notify.ts`, which C7.10 item E put on the session route after PR B recorded 4323 — so pristine main reads 4324 against the 4323 it holds, which is what #21908 re-pins. Named here as #21908 names it on main. Nothing measured changes: 4284 is the same number, and the module is in it by main's route rather than by anything this branch did. `haptics.web.ts` was already in the closure; the bridge module joins it. Verified by reading the closure's own module list rather than inferred from the count: both haptics modules are in `local`, with the artifact-level totals unchanged at 4284 / 934. Which is why the reading is re-measured and not summed. A merged number arrived at as -40 plus +3 would have read 4283 and been wrong about a module neither side of the merge touched. After #21908 lands, a further merge of main reconciles the two comments. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
Main at 2d697a4, which carries #21908's re-pin of the session route's module count. One conflict, the pin itself, plus `27a0889dcf`'s relay test arriving unconflicted. Resolved by keeping this branch's `SESSION_ROUTE_MODULES = 4284` and folding #21908's account into the one explanation the docstring already holds. Re-measured on the merged tree with the four postinstall generators run first rather than carried over: 4284 modules, 934 local, with `src/mobile-web-shell/bridge/bridge-haptics-notify.ts` read out of the closure by name rather than inferred from the total. What #21908 adds to the account, and what this branch could not say on its own: C7.10 item E (#21864) and mermaid (#21871) were each green against a main that lacked the other, which is how main came to hold 4323 while measuring 4324. The module reaches this branch's 4284 by that same route and not by anything this branch did. The constant's own comment is now the short form and points at the docstring, so the two explanations read once rather than twice. Nothing under `mobile/` moves in this merge. It changes exactly two files here, the closure test and `src/relay/omp-fresh-launch-environment.test.ts`, so the mobile suite is not re-run; mobile tsc is, and is clean. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run re-reviewed the commits since the prior Pullfrog review at a82a8b1459: two merges of origin/main and one docs/config commit, whose conflict resolutions touched five PR-authored files (no production code).
- Merged main's mermaid page engine and the haptics notify module (
85d5ef0b8a, main35005fb65c9) —mermaid-page-engine.generated.tsjoins themobile/.gitignoreandmobile/.oxlintrc.jsonignore lists, and main's deferred-engine chunk test plus itsmobileWebAppRouteChunkClosure/artifactModules/packageModuleshelpers came in adapted alongside the factory change. - Re-anchored the session-route closure pin on the merged tree (
7ceb633df0, main2d697a4012) — main'sMODULES_WITH_MERMAID = 4324becameSESSION_ROUTE_MODULES = 4284, with the docstring recording why the merged number is one above the arithmetic sum of the two sides (−40 branch, +3 mermaid): the haptics module arrives by both sides' route. - Updated the generated-artifact census —
census-source-files.tsnow reads six*.generated.tsfiles from the four postinstall generators (verified againstmobile/package.jsonand.gitignore), and its test comment moves from "sixth" to "seventh". - Named the haptics bridge module (
f339500911) in the merged closure docstring.
No dangling references to the renamed MODULES_WITH_MERMAID, and no behavioral surface changed by the reconciliation itself; the closure pin is exercised green by the gate reported on this head. mobile/node_modules is absent in this environment, so the closure/generator suite could not be re-run here.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
Main at 5d13a70, which carries C2.9's re-pin of the session route's module count. One conflict, the pin again. Re-measured on the merged tree rather than adjusted, with the four postinstall generators run first: main 5d13a70 modules 4326 local 976 merged modules 4286 local 936 (-40, -40) The measured 4286 agrees with the expected 4284 + 2, and unlike the first merge the sum would have been right this time -- which is not a reason to have summed it. All four modules the count turns on are read out of the closure list by name: `bridge-haptics-notify.ts`, `bridge-page-route-grants.ts`, `manifest-contract.ts` and the `bridge-envelope.ts` that reaches the last two. Main's side is measured too, in a scratch worktree detached at the same sha and removed afterwards, rather than taken from its pin: the pin covers the module count alone, so the local count beside it would otherwise have been a number nobody had read. The measurement agrees with the pin at 4326. `SESSION_ROUTE_MODULES` keeps its name and takes 4286. C2.9's account is folded into the docstring beside #21908's, as one list of the three modules the base gained -- none of them this branch's, all of them in its 4286 by main's own route. The -40 is the only part of the reading that is the lane's, and it has not moved across main's three re-pins; what moved is the base. This merge brings C2.9's shell and bridge work under `mobile/`, so the mobile suite is re-run and not skipped. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb

Summary
Phase C, C7.5b: the terminal document becomes a function (
rulings-ota-c7.md22–24; 19–21 still in force). The generator emitscreateTerminalDocument(host)around the same module bodies in the same order, then the start sequence inside the document's own undo, and returns{ send, stop }; the native WebView document is that function plus one call with no host. The page imports the factory statically from a second generated file that carries the native factory's body verbatim (ruling 23), and calls it once per mount with its own hooks, so a mount owns its own scope and there is no shared state to claim, reset or refuse. Inert: no route serves the terminal until C7.7; the native screen keeps loading the generated document; released native RPCs unchanged.Deleted with that (mount 300 → 184 lines; lane vs main 44 files, +1,695 / −1,408): the page entry
page-document-modules.ts, the per-mount claim token andliveDocument,release, the owner-checked dispose, the second-mount refusal,resetTerminalDocumentScope, theadoptcallback, thereadypromise and every pending-import path, the mount's hand-copied resize refit, the mount-sideconfirmWebReady(true), the module-state census, and five test files: three whose subjects no longer exist (terminal-web-document-mount-rejection,page-document-module-order,page-document-start-unwind) and two whose machinery went but whose subjects did not (terminal-web-document-single-mount's both-terminals disposal and start-failure paths), which round 1 caught anda29d1cb107re-covers interminal-web-document-mount.test.ts(6 cases against the real generated factory).Ruling 24, two more host seams (eight in all). The page runs the native program whole, and that program's
message-bridgeinstalledwindow/documentmessagelisteners and probedwindow.Terminal; on the page the first double-delivers the shell's frames and the second reports a fatal "engine missing" on every mount. Both are now seams with window defaults:installHostTransport(page: installs nothing; its transport is the returnedsend) andhasEngine(page:true).stopMessageBridgeremoves the listeners the WebView never removed. The resize refit moved intostartFitScale/stopFitScale, run by both hosts.web-readytherefore reaches the controller throughpostToHoston both hosts.The document reads its host's elements (
712daa80e6):rootjoins the host argument (null= the page the document is in, read at the accessor rather than when a scope is built, since a data default put a DOM read into every slice evaluation) andelementInRootis the one reader for the ten reads that weredocument.getElementById. Two documents on one page, which a stack transition produces, are now two terminals; the red-first testdocument-host-root.test.tsplants two hosts and shows each engine opened on the surface inside its own host, red before the fix and red again with the reader pointed back atdocument.Round 1 (fresh) found one real defect, folded (
9824145e1f): the dispatcher's four capture-phase touch listeners sit on the globaldocumentand the two-finger branch ran before any target filtering, so with two documents on a page A cancelled its selection on a pinch inside B's host.eventTargetInRootbesideelementInRootis asked first in each of the four handlers (root === null, the WebView, admits everything, so the native document is unchanged); the census in the commit names every other page-level listener and why it stays (messageis WebView-only under ruling 24;resizeandvisibilitychangeare page-wide by nature). Red-first with the reviewer's repro indocument-host-root.test.ts(2 failed before, 3 passed after, with the same pinch inside A's own surface still cancelling as the control); lead control: the predicate made to admit every target → 2 failed again. Golden +22/−1, 728,119 → 728,589 bytes. Round 2 (delta) found the residual of the same class and it is folded (8dab23e4fe): the predicate filtered the event's target but every handler still reade.touches, which is page-wide, so a finger held in A made a one-finger touch in B read as a pinch (B postedmobile-clip-cancel-by-pinchand dropped its selection) and made B's surface tap never fire.touchesInRootbesideeventTargetInRootreturns this document's own fingers as a list (indices are page-wide exactly as the count is;root === nullreturns the list untouched, so the WebView allocates nothing at frame rate); everye.touchesread intap-dispatch.ts(15) andsurface-touch-gestures.ts(18) goes through it,touchByIdtakes the filtered list; nochangedTouchesortargetTouchesread exists. Red-first with the reviewer's two repros (2 failed / 3 passed before, 5 passed after; lead control: the filter made to return every finger → red again). Golden 19 hunks, +51/−33, 728,589 → 729,152 bytes. Both generated wrappers are now pinned as literal lines (aba99c3e4f; reordering the pageimport typeor changing the native trailing call reds, which the old single-line anchor did not catch).Beyond the rulings: the generator wraps the start sequence in
try { … } catch { stop(); throw }, so a start that throws leaves nothing installed on either host;document-factory-emit.test.tsfails exactly that case with the wrapper stripped (lead-reproduced).beforeMountRefin the page component stays, with its one caller named: the readiness flush that runs inside the factory call, before the effect has a handle to assign.Byte golden: 108,329 → 108,831 (commit 1, wrapper lines only), then 102 diff lines (ruling 24: two seam defaults, two state fields, the reset gone,
startFitScale, engine disposal instopTerminalInit, the bridge over its seams, the start sequence in its try), then 27 (commit 5:elementInRoot,root: null, the ten reads). Hash and length re-pinned at each; the page artifact's body is byte-equal to the native factory's bydocument-factory-artifacts.test.ts, so one golden pins both.ec82173130Commits (lane's own):
935fb0cd54587000852f89b6d5802d23b199b26868556796878a06a62369712daa80e68b6d8c27189824145e1fa29d1cb107aba99c3e4f8dab23e4fea82a8b1459origin/main(e476193bf5): #21687 changedsurface-touch-gestures.ts's momentum loop (the line below fold 5's finger count); both pins regenerated from the merged modules, golden 729,152 (branch) / 726,574 (main) → 729,363 bytes649e82856dorigin/main(8a3a119052)85d5ef0b8aorigin/main(35005fb65c, PR E haptics and PR B mermaid):mobile/.oxlintrc.jsonandmobile/.gitignorecarry both generated artifacts; the session closure test's docstring keeps both sides' readings, and its pin, renamedSESSION_ROUTE_MODULES, is re-measured on the merged tree at 4,284 modules / 934 local (main 4,324 / 974; a sum of the two deltas would have read 4,283)f339500911bridge-haptics-notify.tsas the module that joined the closure after PR B pinned it7ceb633df0origin/main(2d697a4012, #21908): the pin conflict resolved at 4,284 with #21908's account folded into the docstringef62eee7b4origin/main(5d13a70ea3, C2.9): the pin re-measured at 4,286 / 936 (main measured 4,326 / 976); the four modules the count turns on read out of the closure list by name; C2.9's account folded beside #21908'seb902c5b9f,f2d05ad9c8origin/main(the first without the footer, left as is)Verification
Lead gate on
ef62eee7b4(merges of main through5d13a70ea3) against5d13a70ea3(verify-gates.sh, four artifacts rebuilt): tsc 0, ratchet 0, oxlint 0, oxfmt 0, changed-code quality 0, react-doctor 0, oxlint-config 0, anti-slop 0, merge-max-lines 0, root oxlint over 41 changed files 0, machine paths 0; mobile 775 files / 8,674 passed, 0 failed; config/scripts 239 passed + the owner-loss timing flake in an untouched file (green alone, 21/21).Lead gate on
7ceb633df0(merges of main through2d697a4012) against2d697a4012(verify-gates.sh, four artifacts rebuilt): tsc 0, tests-typecheck ratchet 0, oxlint 0, oxfmt 0, changed-code quality 0, react-doctor 0, oxlint-config 0, anti-slop 0, merge-max-lines 0, root oxlint over 41 changed files 0, machine paths 0; config/scripts 238 files / 2,166 passed, 0 failed; mobile 775 files / 8,661 passed, 0 failed. The lane's re-measure of the session closure (4,284 / 934 on the merged tree,bridge-haptics-notify.tsread out of the module list by name) is what the pin carries.Lead gate on
aba99c3e4f(the round-1 fold head) against3b055c869f: tsc 0, ratchet 0, oxlint 0, oxfmt 0, changed-code quality 0, react-doctor 0, oxlint-config 0, anti-slop 0, merge-max-lines 0, root oxlint over 38 changed files 0, machine paths 0; config/scripts 235 passed + one load flake in an untouched file (build-native-for-platformdescendant reaping, green alone 21/21); mobile 771 files / 8,604 passed, 0 failed.Lead gate on
f2d05ad9c8against3b055c869f(verify-gates.sh, artifacts rebuilt first): tsc 0, tests-typecheck ratchet 0, oxlint 0, oxfmt 0, react-doctor 0, oxlint-config 0, anti-slop 0, merge-max-lines 0, root oxlint over 35 changed files 0, machine paths 0; config/scripts 235 passed + the known owner-loss timing flake (green alone, 21/21); mobile 770 files / 8,596 passed, 0 failed. The type-aware changed-code gate found one thing (document-host-root.test.ts:81, a double cast tonever), folded as8b6d8c2718(typed asTerminalDocumentTerminal, no cast); at that head: tsc 0, ratchet 0, oxlint 0, oxfmt 0, changed-code quality 0 on all five checks, anti-slop 0, terminal suite 67 files / 623 tests, machine paths 0.Lead reproductions (ota-verify-2 at the head, ota-c6-page for controls): mount 184 lines; delta 40 files +1,089/−1,333; the unwind control (generator without the try/catch →
document-factory-emit.test.ts1 failed / 5 passed); the host-root control (reader pointed atdocument→document-host-root.test.ts1 failed). The lane's report of nine full-suite failures "identical at main" was its own tree's environment (temp-root path prefixes and a key-pair race); the lead's pristine run of main and the gate above have none.Commit-message erratum:
9824145e1f's census citestap-dispatch.ts:241-244for the four installs; at that commit they are at261-264(241-244is insideonDocumentTouchCancel). Messages are not rewritten here.Not in this PR: the scope-threading rewrite that retires the generator, the order list and the byte golden (ruling 25, C7.5c, next); the seventeen never-written scope constants,
__engineErrorsas a scope field, and the three page casts all move there.