Repository navigation
Delete surplus exports and dead helpers, and gate dead code in JavaScript and Python - #2326
Conversation
…anguages Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts: # skills/leaf/assets/runtime/thread/landing.js
…lication's members Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts: # skills/leaf/assets/vendor/browser-runtime.js
# Conflicts: # skills/leaf/assets/runtime/standing-target.js # skills/leaf/scripts/leaf/tasks.py
…er merging main Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
The new gate misses default exports. exported_names() returns an empty set for export default function lfUnusedDefaultExportReviewProbe() {}, so deleting that export's last reader leaves a green gate. This is a live export form in the tree (hooks/pi.ts), and the PR describes the gate as covering any JavaScript or TypeScript export. Please cover default exports or state why they are outside the gate and how their orphans are caught.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
The new gate fails on the current merged tree: uv run pytest tests/test_unused_exports.py -q -n0 reports GRADE_SCHEMA in evals/ui-review-detection/grade.mjs and BROWSER_SCHEMA in provider.mjs as unread. The lint job also fails vulture on list_directory in dev/leaf_dev/review_detection_eval.py and codex_cli in tests/test_eval.py. These files arrived on main after this branch diverged; the branch needs to account for them before the new gates can pass.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts: # skills/leaf/assets/runtime/application.js # skills/leaf/assets/runtime/widget-api.js # skills/leaf/scripts/leaf/service.py
# Conflicts: # skills/leaf/assets/leaf.js # skills/leaf/assets/runtime/application.js # skills/leaf/assets/runtime/queues.js # skills/leaf/assets/runtime/widget-api.js
# Conflicts: # skills/leaf/assets/runtime/application.js # skills/leaf/assets/runtime/keeps.js # skills/leaf/assets/runtime/pointed-place.js
The JavaScript export check (`tests/journeys/test_unused_exports.py`) ran only in the daily `journeys` tier. That run has failed every day this week, with over a hundred failures each time, so an orphaned export reached main and stayed until Tend triaged the daily report: #4724 and #4873 left seven on 30 and 31 October, and #5014 removed them on 1 November. Vulture, its Python counterpart, runs as a pre-commit hook, which both landing paths (a pull request's lint step and `wt merge`'s pre-merge) run over the whole tree, so the change that orphans a Python definition is the one told. This moves the export check beside vulture: - `leaf-dev unused-exports` holds the check, unchanged, with the test's docstring as its module header. It takes about two seconds. - `.pre-commit-config.yaml` runs it as `unused-exports`, woken locally by the file kinds that export or read (`.js`, `.mjs`, `.ts`, `.py`, `.html`, `.md`, `worker/wrangler.toml`). CI runs every hook on every file. It also removes what #5014's deletion of `since-seen.js` left behind: - the `keepalive` option of `deliverBookkeeping` and `postEvent`, which only the departing `seen` send set, and `runtime.seen`, which only `since-seen.js` read; - the six arrival tests skipped while `since-seen.js` was unmounted. The module, renamed `test_changes_in_place.py`, keeps the comparison and at-work tests; - the prose in `change-walk.js`, `events.md`, `read_state.py`, `agent_state.py` and `browser/AGENTS.md` that described the turned-off marking. The server's reading of `seen` events is unchanged, and no tab posts one. And it drops the `uuid` devDependency, which no module imports. A one-off knip scan of dependencies flagged 33; the other 32 are bundled from `build/entries`, loaded by evals or `tests/*.mjs`, or resolved as types and peers. As #2326 and #3423 found for exports, knip would need more configuration than it saves, so it is not added as a gate. Validation: `leaf-dev unused-exports` and every pre-commit hook pass on the changed files; `pnpm run check:browser`, the 737 runtime tests, and the browser test for comparison bars and the `h` walk pass. > _This was written by Claude Code on behalf of max-sixty_
Removing a caller never flagged its callees, so exports, application trampolines and Python helpers kept outliving their last use (#2020 and #1808 left several). This deletes them and adds two gates, so the next orphan fails in the change that creates it.
Gates
tests/test_unused_exports.pyfails on any JavaScript or TypeScript export that no other tracked file names as a word. A default export counts as read where another file names its module's file name, since tools such as eslint and Pi load those modules by path. A JavaScript comment or a stylesheet counts as no reader, apart from a JSDocimport("…").Name; code, Python strings, pages and contract prose do. It runs over the whole tree rather than through knip because the browser tests import runtime modules inside Python strings and the render gate calls probes by name. Committed bundles are skipped, and thebuild/inputs of third-party bundles are skipped as exporters, since the bundled dependency reads their exports. A name that collides with another word can hide an unused export.build,dev,hooks,skills,tests,worker), configured in[tool.vulture]. A function a framework calls is excluded by the decorator that registers it (click commands, pytest fixtures,atexit.register, jsonschema format checks) or by the name the framework's protocol fixes (do_*,pytest_*, uvicorn'smain_loop, and so on), never one dead name at a time.Deleted or narrowed
application.jsloses the trampolines nothing imports (approvalBlockingQuestions,beginRead,midComposition,receiveState,startFeed,unaccountedGesture,undoable,undoLast). Pure helpers stop routing through the mounted application:widget-api.jsre-exportswatchReportsfromreports.js, andleaf.jsimportsbeginReadandapprovalBlockingQuestionsfrom theirs. The mount drops the unreadupdateFaband thefeeddependency bag, which repeatedstate, and the sixopenPageThreadforward references share one forwarder. The mounted object lists the members boot reads instead of spreading the projection commands and engagement into it, soundoable,undoLast,retainReversal,unaccountedGesture,dispatchWidget,refreshAnnotationInventoryandreceiveStateleave it.exportcomes off every symbol only its own module uses, across the runtime, the default package, the browser framework's types,eslint.config.mjs, the Worker and the rust-sort example.widget-api.jsstops re-exportingsubmitBindingsandsubmitLabel, which no package uses.history.jsandbanner-toolbar.jsusefocus.js'sdrawninstead of their own copies,context.jsloses the unreadeventsandactivitygetters and shares one live-revision test,pointed-place.jsnames its functionpointIntoinstead of aliasingrowIn,geometry.jsloses the uncalleddocumentPoint, andcomposing/input.jsgets its contract comment as a header.events.current_anchors,anchored_idsandanchored_parts,tasks.canonical_tasks,log_tasks_open,OUTCOMESand theENDS_BY_*constants,PageTransaction.voice, and the test-only wrappersunattended_pagesandlayer_generation, whose tests now call what production calls.task_errorreads the task'sownerdirectly, which is what theendscomparison meant; theendsfield itself stays. Test helpersxfail_browser_problemanddraft_ownerhad no callers; a fixture requested only for its effect moves tousefixtures, and protocol overrides collect arguments they ignore in underscore-named*or**parameters.test_interact_anchors.pyasserted that a version may drop a part a detached, moved, resolved, reopened or bare-reaction thread had pointed at. Since Clarify navigation and keep decided pages editable #2020 no thread blocks that removal, so each passed without its premise;test_a_removed_visual_part_moves_its_thread_to_the_surviving_sectionkeeps the live-thread case.Rule
skills/leaf/assets/AGENTS.mdgains "Facts both runtimes know": a fact Python and the browser both use is owned by one language and consumed as data, or generated from the registry, and a new parity fixture or source-scanning test is a review flag asking why it is not generated./developing-leafpoints reviewers at it.