Skip to content

Fail a change that adds a backward import in browser/runtime - #7113

Merged
max-sixty merged 3 commits into
mainfrom
deslop-please
Nov 25, 2026
Merged

max-sixty merged 3 commits into
mainfrom
deslop-please

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

A commit that adds an import against browser/runtime's order now fails pre-commit and names the import, as src/leaf has since #6923. This is the runtime half #6923 left out until the package-interface refactor stopped moving runtime files.

.config/dependency-cruiser.mjs lists the runtime's 187 children in one order, a layering rule per child forbids importing a child before it, and layering-unplaced fails a child the order doesn't name. The order is Eades, Lin and Smyth's greedy feedback-arc-set heuristic over the children's imports, run on current main after the keyboard split (#7115). The 15 backward imports it leaves (10 child pairs) are in .config/dependency-cruiser-known.json, which the hook passes over and which only shrinks. Unlike import-linter, dependency-cruiser passes a stale entry silently, so the config's header asks for each entry to go with its import.

To weigh: the order is the one the code already mostly takes, not a design. max-sixty chose to move the runtime's children into named layer directories once the modules that cross layers are split; that move rewrites this list to name layers.

Probed: passes as committed (1.8 s); fails naming carry.js → thread/selectors.js when that known entry is dropped; fails layering-unplaced when age is left out of the order. Pre-commit passes on the changed files.

This was written by Claude Code on behalf of max-sixty

browser/runtime's 185 children now stand in one import order, and each may import
only the children after it, as src/leaf's modules have since #6923. A new import
against the order fails pre-commit, naming the import; a child the order doesn't name
fails `layering-unplaced`.

The order comes from Eades, Lin and Smyth's greedy heuristic for a minimum feedback
arc set over the children's imports, run on this tree after the package-interface
refactor landed. The 34 backward imports it leaves (21 child pairs) are listed in
.config/dependency-cruiser-known.json, which the hook passes over. That list only
shrinks; a stale entry passes silently, unlike import-linter's allowances, so the
config's header asks for an entry to go with its import.

Probed on this tree: the check passes as committed (1.8 s), fails with the import
named when one known entry is dropped (carry.js -> thread/selectors.js), and fails
when a child is left out of the order (age).

max-sixty chose this on the deslop-please page ("Fail changes that add a backward
import"), with the runtime half to follow the package-interface refactor.
leaf-agent
leaf-agent previously approved these changes Nov 25, 2026
#7115 split keyboard/ into keyboard/, key-badges/ and page-keys/, none of which
is in an import cycle. Rerunning the same heuristic over the runtime's imports on
current main places all 187 children, and the order now leaves 15 backward imports
(10 child pairs) where it left 34 (21), so the known list shrinks to match.
@max-sixty
max-sixty merged commit 9482a7f into main Nov 25, 2026
6 checks passed
@max-sixty
max-sixty deleted the deslop-please branch November 25, 2026 05:27
leaf-agent added a commit that referenced this pull request Nov 25, 2026
…ontrols with the library's offered (#7130)

Two cleanups from the nightly survey. Neither changes what a page draws.

- **`repaint.js`'s `paintVersionShortcuts` slot was dead.** The
`Painters` typedef declared it and each frame called
`p.paintVersionShortcuts?.()`, but neither `mountRepaint` call in
`browser/leaf.js` (live page or export) passes such a painter, and
nothing else in `browser/` names it. The slot and the call are removed.
- **`shot-view.js` had its own copy of `offered`.** Its `render()`
defined `offered(cls, pressable)` as a `ref` around `offerElement`,
which is what `offered` in `runtime/lib/controls.js` already is
(`elementDirective("offered", offerElement)`). The screenshot now
imports the library's directive, and its caption uses it too. Lit's
`ref` re-runs a callback that changed, and an inline arrow is new each
render, so the copy already wrote on every render, as the directive
does; both write through `keeps`. With the screenshot gone as its only
outside importer, `offerElement` is no longer exported (knip flags it
otherwise), and the library header names `offer` and `offered` as the
forms that mark a field or a box.

The survey also flagged `drafts.js` importing the framework as
`./framework.js`, the one backward import #7113 recorded for it; #7119
moves `framework.js` beside `drafts.js` and drops that entry, so this PR
leaves it alone.

**Verified:** pre-commit on the changed files (eslint, oxfmt, knip,
dependency-cruiser) passes; `pnpm run check:browser` passes; `pnpm run
test:runtime` passes 1130 of 1130; the screenshot tests
`test_shot_controls_have_disjoint_targets_and_labels_stay_passive`,
`test_shot_inspects_either_original_without_flipping_or_moving`,
`test_a_shot_takes_a_view_pressed_as_the_page_shows_and_keeps_its_divider`
and `test_a_shot_opens_in_the_view_its_author_names` pass. No regression
test is added, since no behavior changes.

Co-authored-by: leaf-agent <[email protected]>
max-sixty added a commit that referenced this pull request Nov 25, 2026
…eck the layers (#7119)

Moves each top-level child of `browser/runtime/` into a directory for
its import layer, and rewrites the dependency-cruiser layering check
(#7113) to name 11 layers in place of an order of 187 children. A module
imports only its own layer and the layers below it. The layering, drawn
from today's imports, leaves 2 imports pointing up, against 15 for the
best flat order, so the known list drops from 15 entries to 2. No
behaviour changes.

| # | Layer | Directory |
|---|---|---|
| 0 | Entry points and diagnostics | top level of `runtime/` |
| 1 | Floating panel, page dialogs and page keys | `panel/` |
| 2 | Annotation presentation, composing and undo | `annotations/` |
| 3 | Application and widget host | `host/` |
| 4 | Page features: annotation inventory, contributions, version travel
| `features/` |
| 5 | Records and history | `records/` |
| 6 | Page readings, places and paint | `readings/` |
| 7 | Transport, errors and notices | `transport/` |
| 8 | DOM, geometry, focus and the key register | `dom/` |
| 9 | State and registry | `state/` |
| 10 | Primitives and the library | `base/`, and `lib/` where it was |

**What stays put.** The entry points (`bootstrap`, `prepaint`,
`check-api`, `validation`, `widget-api`, `portable-api`,
`stage-integration`, `age`) and `lib/` keep their paths, since pages,
packages, the server and the render checks load them by served path. So
do the files that aren't modules: `chrome.css`, `marks.css`,
`panel-row.html` and `kernel-registry.json`, which the server and Python
read at their served paths. A child directory keeps its name inside its
layer, as in `dom/keyboard/`.

**How the paths moved.** The first commit is the move with `git mv` (all
271 renames detected) and the path rewrites. A script resolved every
relative and served-path specifier in the old tree and wrote the
target's new path; other references in Python, configs, the build, tests
and guidance followed. The primitives' eslint rule now names each
primitive's neighbours by the relative path from its own place. Eval
fixtures, pinned GitHub permalinks and the example diff in
`worktree-diffs.html` keep the paths they recorded. The second commit
rewrites the check and adds "Import layers" to `browser/AGENTS.md`. A
later commit gives the new path wherever guidance, comments or tests
named a moved top-level module by its bare filename (`focus.js` →
`dom/focus.js`), which had also been its path under `runtime/`; a
sibling in the same directory keeps its bare name, and a basename code
compares keeps it too.

**The two upward imports** in `.config/dependency-cruiser-known.json`:
`host/application.js` → `annotations/undo.js`, and
`host/sample-child.js` → `annotations/composing/page-image.js` (a lazy
import).

**What to check.**
- The framework's facade stays excluded from the graph by its served
path, now `/runtime/records/framework.js`, as #7113's config already
did. Twelve modules below `records/` import it that way, and
`state/semantic-state.js` reaches the record folds through its
`createSemanticApplication`, so the check doesn't see that route from
`state/` up to `records/`.
- Open PRs that touch runtime files, #7082 and #7132, need `main` merged
in; git's rename detection carries most of their edits to the new paths.
- `test_each_sampled_focus_ring_is_shown_whole_in_its_surface`
(journeys) runs here because the PR touches its file, and fails as it
does on `main`. One of its six faults is real: since #7091, an opened
settled decision's mark stands as tall as its row, so its ring runs
under the next row. The other five are the check reading a transparent
click target as paint over the ring. #7129 fixes both. The move doesn't
cause it.

Tests: `pnpm run check` (type checks, `test:runtime` 1130 pass, build
and worker tests), `pnpm run build:browser` (no generated file changed),
the prepared kernel build (same 68 outputs as base), pre-commit on every
changed file, `tests/smoke`, the model tests for served runtime modules
and public modules (`test_module_url_delivery`,
`test_revision_delivery`, `test_distribution`, `test_interact_layer`:
318 pass), `test_owner_index`, the prepared-install journey in
`tests/journeys/test_distribution.py`, and `leaf-dev probe alert-review
--base`: the page boots, the panel draws the same label, with the same
317 requests and no console output on either arm.

> _This was written by Claude Code on behalf of max-sixty_
max-sixty added a commit that referenced this pull request Nov 25, 2026
…port (#7137)

Removes `browser/runtime/records/framework.js`, the facade that every
layer imported. The layer check (#7113, #7119) had to exclude it, so it
couldn't see routes through it, such as `state/semantic-state.js`
reaching the record folds in `records/` through
`createSemanticApplication`. With the facade gone, dependency-cruiser
checks every runtime import and still finds only the 2 known crossings.
A Leaf page behaves as before. #7119's reviewer proposed this split.

Each piece now stands in the lowest layer its own imports allow:

- **Lit and signals.** Importers use `/vendor/lit.js` and
`/vendor/signals-core.js` directly, as `lib/` and several runtime
modules already did.
- **`base/snapshot.js` and `base/presentation.js`.** Both import only
signals.
- **`state/semantic-application.js`** (was
`records/framework/application.js`). The five folds it reads move from
`records/` to the same paths under `state/`: `thread/model`,
`thread/identity`, `pending/model`, `projection/model` and
`obligations/source`. `semantic-state.js` stays in `state/`, since
modules in `state/` and `readings/` import it.
- **A new dependency-cruiser rule.** `one-application-publisher` lets
only `state/semantic-state.js` import `semantic-application.js`. It
replaces the eslint rule `semantic-store-ownership` and its test, which
policed imports through the facade.

**What to check**

- `dom/move-focus.js` installs Leaf's focus accounting around DOM moves.
Any entry point that imported the facade used to install it,
`portable-api.js` on a plain HTML page included. Now `leaf.js` imports
it first, so only a Leaf page installs it, as the module's header says
("off Leaf the browser owns focus"). On a Leaf page it installs earlier
than before.
- `createApplicationPublisher` now sits in `base/snapshot.js` beside
`share` and `defineOwn`, so any module can import it, where before only
the framework's own modules could. The new rule fences
`createSemanticApplication`, which builds the page's one application
state.

Tests: pre-commit over the change (dependency-cruiser, knip, eslint),
`pnpm run test:runtime` (1126 pass), `pnpm run check`, `pnpm run
build:browser` (no generated file changed), the kernel bundle build,
`tests/smoke/test_plain_page.py`, and `leaf-dev probe alert-review
--base` (both arms boot with no console output).

> _This was written by Claude Code on behalf of max-sixty_
max-sixty added a commit that referenced this pull request Nov 25, 2026
… fails every upward import (#7145)

Ends the 2 imports in `browser/runtime` that pointed up a layer, so
dependency-cruiser's layer check (#7113, #7119, #7137) needs no list of
known crossings. `.config/dependency-cruiser-known.json` and the hook's
`--ignore-known` go, and any upward import now fails pre-commit.

- **Undo** moves from `annotations/` to `records/`, the lowest layer its
imports allow, so `host/application.js`, which creates it, imports
downward. It borrowed two things from `annotations/`. `commentDraft`,
the draft a comment was written in, moves to `records/drafts.js` beside
every other draft's key, with the composer's draft record
(`composerCtx`, `composerPayload`, `ComposerDraft`, `isComposerDraft`).
`reactionPlace`, whose only caller was undo, becomes private to it.
- **The page image** moves from `annotations/composing/` to `host/`,
beside `host/sample-child.js`, which loads it, and `host/sample.js`,
which it loads. `dom/` would put its import of `sample.js` upward.

No module re-exports an old path, and a page behaves as before.

**What to check:** `ComposerDraft` in `records/drafts.js` names
`DraftDrawing` from `annotations/composing/drawing-record.js` in a JSDoc
type, as drafts.js's other type references already point upward.
dependency-cruiser doesn't read JSDoc.

Tests: pre-commit over the change (dependency-cruiser finds 0
violations), `pnpm run check` (1127 runtime tests pass), `pnpm run
build:browser` (no generated file changed), and `leaf-dev probe
alert-review --base` with a ⌘Z press (no console output on either arm).

> _This was written by Claude Code on behalf of max-sixty_

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants