Repository navigation
Route the hooks module's reports in hooks.cmd_fork, ending the forks import cycle in agents - #7216
Merged
Merged
Conversation
…k helper its owner's home `carrier`, `clerk`, `forks` and `summary_fork` imported each other in a cycle, nearly every edge a deferred import, because three shared pieces sat in the wrong module: - `carrier.py` held both the contract every fork kind speaks (the `fork` instruction) and the router that names every kind (`step`). The router moves up to `commands/hooks.py` as `cmd_fork`, the `--fork` branch it served, beside `cmd_pages`, which already lists each kind's instructions. `carrier.py` keeps the contract and the instruction. - `forks.run_facts` reads the module's report of a fork, which `carrier.py`'s header defines, so it moves to `carrier.run_facts`. - `forks.note` was a second copy of `interaction_log._record_in`. Both become `interaction_log.note`, which every fork kind and the follower and watch records call. - `summary_fork.ask` rendered the thread with `forks.thread_json`. It now takes the rendered thread, as `summary_fork.prompt` already did, so the fork beside the line fork no longer reaches back into it. The order is now forks > summary_fork > clerk > carrier, with no cycle among them, and summary_fork's comment about dodging one goes. A refactor: no behaviour changes. Every caller moves, the dev stand-in for the hooks module included, and the prose naming `carrier.step` points at `hooks.cmd_fork`. > _This was written by Claude Code on behalf of max-sixty_
… to note `forks.ask` now decides under the page's lock which prompts are due, the line fork's and the summary fork's (`summary_fork.due`, which returns the beside fork's basis), and renders the captured thread once (`thread_json`) for whichever are. `line_prompt` and `summary_fork.prompt` both take the rendered thread. A line-only report renders the thread once, and a repeated report that asks no fork renders nothing. `forks`' header now names every place a new beside-duty is wired in: its module, its calls in `ask`, and its `BESIDE` entry. `interaction_log.record_command` keeps its check that the page is initialized and writes through `note`. The interaction_log header separates the line fork's `fork_asked` record from the outcomes the three forks note, and How it works' entry for `carrier.py` points to `hooks.cmd_fork`, which routes the reports. A refactor: what Leaf asks, writes and records is unchanged. > _This was written by Claude Code on behalf of max-sixty_
leaf-agent
approved these changes
Nov 26, 2026
max-sixty
added a commit
that referenced
this pull request
Nov 26, 2026
…a cycle (#7230) import-linter's layers contract checks only the imports between `src/leaf`'s eight packages, so the modules inside a package could import each other in a cycle, and six groups did. The cuts that ended them have landed (#7216, #7217, #7218, #7222, #7224). This adds import-linter's own `acyclic_siblings` contract over every package (`ancestors = leaf.*`). It recurses into subpackages such as `served_state` and `render_gate`, so a new cycle fails pre-commit as an upward import does, naming the import that closes it. A planted deferred import from `presence` into `delivery`, and one from `served_state.context` into `served_state.page`, each fail the contract; the tree as it stands passes. The config's header now says how to fix a cycle, and that a deferred import counts like any other, so deferring one ends no cycle; `src/AGENTS.md` states the rule beside the layering one. The maintainer asked for the cycles inside `agents` to be broken; this widens that to every package and keeps them broken. The two allowances the layers contract still lists are cut by #7223 and the PR after it. Tests: `lint-imports` (both contracts), pre-commit, and the two planted cycles above. > _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.
carrier,clerk,forksandsummary_forkinsrc/leaf/agentsimported each other in a cycle, nearly all through imports deferred into functions. This puts each shared piece with the module that owns it, leaving the orderforks>summary_fork>clerk>carrier:carrier.steptocommands/hooks.pyascmd_fork, besidecmd_pages, which lists the same instructions.carrier.pykeeps the contract its header states: the instructions Leaf gives the module and what the module reports back.run_facts, which reads the module's report of a fork, moves tocarrier, whose header defines that report.forks.notewas a second copy ofinteraction_log._record_in. Both becomeinteraction_log.note, whichrecord_command,record_watch,record_follower, the forks and the clerk now write through.forks.askdecides under the page lock which prompts are due (summary_fork.due), then renders the thread once for them, where before the summary fork rendered it a second time.Behaviour is unchanged: the prompts' JSON, the diagnostics records and the hooks module's protocol are as before.
This is one of the cuts the maintainer asked for to break the import cycles inside
src/leaf's packages. A later PR adds import-linter'sacyclic_siblingscheck once the others land. Codex reviewed the change, and its five findings are folded in.Tests:
lint-imports, pre-commit, and the model tests covering forks, the clerk, hooks,interaction_logand the hooks module (245 passed).