Skip to content

Move the leaf task commands into tasks and the forks lane into leases, so todos, plans and forks import only downward - #7121

Merged
max-sixty merged 9 commits into
mainfrom
agent-af7333253fb62974b
Nov 25, 2026
Merged

max-sixty merged 9 commits into
mainfrom
agent-af7333253fb62974b

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

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

`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.
`todos` and `plans` each held two levels of code: the readings of the log that
admission (`event_contracts`), `activity` and the served state build on, and the
`leaf task` commands, which write through admission. So each command imported
`event_contracts`, `thread`, `service`, `revisioning` and `leases` inside its body,
and wrapped its work in a nested `write` function only because `contract_writer`
couldn't be imported where the module could apply it.

The new `tasks` module holds `cmd_create`, `take_in_hand`, `cmd_start`, `cmd_end` and
`cmd_plan`, with plain module-level imports and `@contract_writer` on each command,
as `thread`'s commands have it. `todos` and `plans` now import only readings below
them, so `activity` imports `todos` once at module level instead of in three
functions, and the import order places `activity` and `todos` above `obligations`.

Allowances removed (77 -> 71): todos -> event_contracts, todos -> thread,
plans -> event_contracts, plans -> thread, activity -> todos, and
activity -> obligations, which the same reordering turns forward.

Behavior is unchanged. `cli` and the tests that called the commands import them
from `tasks`.
…rites

The forks lane is a lease: its file, the follower's taking of it and whether a
follower holds it (`lane_path`, `take_lane`, `lane_up`). It lived in `forks`, the
line fork's module, so `delivery` imported the line fork to ask one lease question.
That import held `forks`, and `summary_fork` with it, below `delivery` and so below
`thread`, though both post through `thread`'s writes (`post_reply`,
`cmd_summarize`). `clerk`, which posts through `open_thread` and `ask_again`, sat
just below `thread` by the order alone.

The lane now sits in `leases` beside the session leases of the same shape, the
adapter's and the watch's (`adapter_is_live`, `wait_is_live`), whose
`take_wait_lease` already named it. `delivery` and `hooks` import it from there, and
the import order places `clerk`, `forks` and `summary_fork` above `thread`, so the
modules that write through a thread now import it forward.

Allowances removed (71 -> 67): clerk -> thread, forks -> thread,
forks -> delivery, summary_fork -> thread.

Behavior is unchanged. The lane's prose references in `hooks`, `thread_context`,
`events.md`, `summary_fork` and `fork_eval` name `leases`.
`thread_titles` names a thread by asking the harness's model and writing the answer
through `thread`'s writes (`fit_title`, `name_untitled`), so it belongs above
`thread`. It sat below because `harness` imports its prompt (`title_generator`),
which left two backward edges in one cycle, `thread -> harness -> thread_titles ->
thread`: `harness -> thread_titles` and `thread_titles -> thread`. Above `thread`,
only the first stays backward. That is the edge where the harness reaches up for the
title prompt.

Allowance removed (67 -> 66): thread_titles -> thread. Only the import order changes.
unlined now lives in events and the lane in leases, so forks holds neither, and no
module imports forks at load. summary_fork's page readings therefore import at module
level; only its imports from forks, which imports it, wait until called.
leaf-agent
leaf-agent previously approved these changes Nov 25, 2026
# Conflicts:
#	.config/importlinter.ini
#	src/leaf/events.md
#	src/leaf/forks.py
#	src/leaf/summary_fork.py
@max-sixty
max-sixty dismissed leaf-agent’s stale review November 25, 2026 05:57

The merge-base changed after approval.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description becomes main's commit message on merge, and two of its claims are now out of date: #7118 has landed (it is no longer "still in CI"), and so this PR's own diff against main is what takes src/leaf's allowed backward imports to 64. Worth dropping the "This branch merges #7118" sentence before landing.

@max-sixty
max-sixty merged commit 5ccbb40 into main Nov 25, 2026
6 checks passed
@max-sixty
max-sixty deleted the agent-af7333253fb62974b branch November 25, 2026 06:11
leaf-agent added a commit that referenced this pull request Nov 25, 2026
…tion or a false reason, or tell history (#7131)

Four comments the nightly survey found wrong or out of place. Comments
only; no behavior changes.

- **`lf-activity.js` header** said a row names the user "You". `actorOf`
writes "Me", the glossary's author word.
- **`findings.py`** pointed the `not-a-widget` and `not-an-element`
refusals at `tasks.task_error`, which doesn't exist; #7121's new
`tasks.py` made that pointer actively misleading. The to-do check is
`todos.todo_error`.
- **`http.py` `body_unread`** said an undrained body "would be read as
the next request line on a reused connection". uvicorn's h11 protocol
discards a request's body data once the response is done (`h11_impl.py`,
the `h11.Data` branch checks `our_state is h11.DONE`), as
`PageEndpoint`'s docstring already says. What the flag does is close the
connection so the transport doesn't drain a body the peer may never
finish sending, which
`test_a_user_without_the_key_reads_and_writes_nothing` exercises with a
keyless POST declaring 1 GiB. Both comments now give that reason, so a
later reader neither removes the flag as redundant nor copies it for the
wrong reason.
- **`packages/diagram/defaults.css`** told how its rules left the
default theme and the incident behind the fade's 30% stop. Root
`AGENTS.md`, "Where instructions live", puts that in commit history; the
comments keep the rule and its reason.

Verified with pre-commit on the four files (ruff, oxfmt, eslint, typos).

Co-authored-by: leaf-agent <[email protected]>
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