Skip to content

Route the hooks module's reports in hooks.cmd_fork, ending the forks import cycle in agents - #7216

Merged
max-sixty merged 3 commits into
mainfrom
agent-a3d69c645157554fd
Nov 26, 2026
Merged

max-sixty merged 3 commits into
mainfrom
agent-a3d69c645157554fd

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

carrier, clerk, forks and summary_fork in src/leaf/agents imported 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 order forks > summary_fork > clerk > carrier:

  • The router that hands each of the hooks module's reports to its step moves from carrier.step to commands/hooks.py as cmd_fork, beside cmd_pages, which lists the same instructions. carrier.py keeps 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 to carrier, whose header defines that report.
  • forks.note was a second copy of interaction_log._record_in. Both become interaction_log.note, which record_command, record_watch, record_follower, the forks and the clerk now write through.
  • forks.ask decides 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's acyclic_siblings check 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_log and the hooks module (245 passed).

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

…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_
@max-sixty
max-sixty merged commit 3719710 into main Nov 26, 2026
6 checks passed
@max-sixty
max-sixty deleted the agent-a3d69c645157554fd branch November 26, 2026 04:28
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_
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