Skip to content

Move three folds to the modules that own their facts, ending three backward imports - #7118

Merged
max-sixty merged 3 commits into
mainfrom
agent-ab7d2cc6bcc8f1c52
Nov 25, 2026
Merged

max-sixty merged 3 commits into
mainfrom
agent-ab7d2cc6bcc8f1c52

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

This moves two functions into the modules that own their facts and reorders one module. That ends three of the backward imports .config/importlinter.ini allows in src/leaf, taking them from 77 to 74. Behavior is unchanged.

  • unlined moves from forks to events. It is a pure fold over a built thread that reads only events.unanswered_turns and events.spoken_turns, which it used to import inside its body. It now sits beside owed_turns. thread_context.batch_threads then imports it downward, instead of reaching past forks's imports of service, leases and state.
  • activity moves above obligations in the order. activity decides where the agent's work stands from the records obligations produces. Its only path back ran through the import above, so only the ini changes.
  • package_layer_inputs moves from packages to layer. It resolves the layer a one-package selection composes, beside layer_inputs and checked_layer_inputs. render_gate.widget_quality was the only part of render_gate that imported packages. With the function moved, packages, which holds the package commands, stands above render_gate, as validation does.

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:

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-imports and pre-commit pass.
  • tests/model/test_forks.py, test_thread_reading.py and test_render_gate.py pass.
  • The line-fork and summary-fork process tests, and the package, summary and batch interaction tests, pass.

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

`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.
@max-sixty
max-sixty merged commit 109461e into main Nov 25, 2026
6 checks passed
@max-sixty
max-sixty deleted the agent-ab7d2cc6bcc8f1c52 branch November 25, 2026 05:54
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_
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