Repository navigation
Move three folds to the modules that own their facts, ending three backward imports - #7118
Merged
Merged
Conversation
`unlined`, the user's turns in a thread that no word of the agent's has reached since the oldest of them, is a pure fold over a built thread: it reads only `events.unanswered_turns` and `events.spoken_turns`, which it imported inside its body. Two modules read it, the line fork's follower (`forks.look`, `forks._awaits_line`) and the delivery envelope (`thread_context.batch_threads`). Defined in `forks`, it made `thread_context` reach up past `forks`' imports of the service, leases and state through a deferred import. In `events` it sits beside `unanswered_turns` and `owed_turns`, and both readers import it downward. Behavior is unchanged. The import-linter allowance `leaf.thread_context -> leaf.forks` goes with the import.
`activity` decides where the agent's work stands from the obligation records `obligations` produces, so it belongs above that module. The order had it below, because `obligations` reached `activity` back through `thread_context`'s deferred import of `forks`; with `unlined` moved into `events`, no path from `obligations` leads back to `activity`, and the allowance `leaf.activity -> leaf.obligations` goes. Only `.config/importlinter.ini` changes; no code or behavior does.
…ve its checks `package_layer_inputs` gives the layer inputs a page selecting one package composes: `layer_inputs()` with the package appended once. That is layer input resolution, the subject of `layer`, beside `layer_inputs` and `checked_layer_inputs`. Kept in `packages`, the module of the `package` commands, it made `render_gate.widget_quality` import the command module, so `packages` stood below `render_gate` and `cmd_package_check` reached up to `render_gate.command` against the order. With the function in `layer`, `render_gate` no longer imports `packages`, and `packages` stands above `render_gate`, as `validation` (the `page check` command) stands above the checks it runs. The allowance `leaf.packages -> leaf.render_gate.command` goes. Behavior is unchanged.
leaf-agent
approved these changes
Nov 25, 2026
max-sixty
added a commit
that referenced
this pull request
Nov 25, 2026
…es, so todos, plans and forks import only downward (#7121) `todos.py` and `plans.py` each held two levels: readings that admission, `activity` and the served state build on, and the `leaf task` commands, which write through admission. Each command imported `event_contracts`, `thread`, `service`, `revisioning` and `leases` inside its body, and wrapped its work in a nested `def write` only because `contract_writer` couldn't be imported at load. The commands now live in a new `tasks.py`, which mirrors the `leaf task` CLI group and sits beside `thread`, the other write-command module. Its imports are module-level, and each command carries `@contract_writer` as `thread`'s commands do. `todos` and `plans` become readings, so `activity` imports `todos` once at load instead of in three functions. `lane_path`, `take_lane` and `lane_up` are a session lease, so they move from `forks` into `leases`, beside the adapter and watch leases of the same shape. `delivery` had imported the whole line-fork module for that one question, which held `forks` and `summary_fork` below `thread`, although both post through `thread`'s writes. Now `clerk`, `forks`, `summary_fork` and `thread_titles` stand above `thread` in `.config/importlinter.ini`. No module imports `forks` at load any more, so `summary_fork`'s page readings import at module level, and only its imports from `forks`, which imports it, wait until called. This branch merges #7118, still in CI. On top of it, `src/leaf`'s allowed backward imports go from 74 to 64. Behavior is unchanged: the moved bodies differ from the originals only in imports, decorators and docstring pointers. Two further cuts in this group wait on open PRs. Once #7061 lands, the reply reservations can move from `thread` into `delivery`, whose header already describes them. Once #7114 lands, the fork helpers split between `clerk` and `forks` can move into one module below both. max-sixty asked for refactoring to continue while each change improves the code. The branch merges cleanly with #7061; its only conflicts with #7114 are ones #7114 already has with `main`. Tests: `lint-imports` and pre-commit pass. The model tests for forks, hook registration, responses, clerk, activity, to-dos, thread readings and the suite's source checks pass (1847), as do the fork, pages and follower tests in `test_hooks`, `dev/tests/test_evals.py` and the browser test that ends a to-do. > _This was written by Claude Code on behalf of max-sixty_
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This moves two functions into the modules that own their facts and reorders one module. That ends three of the backward imports
.config/importlinter.iniallows insrc/leaf, taking them from 77 to 74. Behavior is unchanged.unlinedmoves fromforkstoevents. It is a pure fold over a built thread that reads onlyevents.unanswered_turnsandevents.spoken_turns, which it used to import inside its body. It now sits besideowed_turns.thread_context.batch_threadsthen imports it downward, instead of reaching pastforks's imports of service, leases and state.activitymoves aboveobligationsin the order.activitydecides where the agent's work stands from the recordsobligationsproduces. Its only path back ran through the import above, so only the ini changes.package_layer_inputsmoves frompackagestolayer. It resolves the layer a one-package selection composes, besidelayer_inputsandchecked_layer_inputs.render_gate.widget_qualitywas the only part ofrender_gatethat importedpackages. With the function moved,packages, which holds thepackagecommands, stands aboverender_gate, asvalidationdoes.These are the cuts that read better from one group of the 77, the page readings and checks. The rest of that group stays as it is:
authored_checks.source → sample_contentis a real recursion thatadmission.pycomments.passages → obligationsandpassages → data_contractscome fromSourceReadingcaching readings that higher modules own. Ending them would mean redesigning those caches, not moving code.render_gate.handover_pass → validation.commandwaits on Give every record kind a verified window of shapes it reads through its kept keys, and keep drafts, grants, the page key and a page's address across a shape change #7114, which editshandover_pass.py.max-sixty asked for refactoring to continue while each change improves the code. No file that #7061 or #7114 changes is touched, and the branch merges cleanly with both.
Tests:
lint-importsand pre-commit pass.tests/model/test_forks.py,test_thread_reading.pyandtest_render_gate.pypass.package, summary and batch interaction tests, pass.