Answer principles round 1: 0 🔴, 6 🟡; read the plan from the fetched default branch for routing and the preflight alike and drop the fast-forward, name no item where the release after the last tag has none, tell an empty items table from none, time out the fetch, return run_python's errors as exit codes, test the error paths and the gh rows, assert facts in place of sentences, keep the open-PR sentence in every fresh prompt, name the item branch in CLAUDE.md, and measure item 175 against five chunks with counter-signals

This commit is contained in:
2026-10-17 02:07:40 +02:00
parent 50541c32fd
commit 495184b9c6
21 changed files with 621 additions and 297 deletions
+24 -27
View File
@@ -6,11 +6,12 @@ Run it anywhere inside a project checkout whose README.md has ## Goals and ## Au
premises; the task runs at the checkout root. Each cycle a worker runs the task. A chunk's first
worker prompt also quotes the premises, which choose between ways to deliver the chunk's todo.md
items, or else the task, and never widen them. As a chunk starts, before it is routed, loop-claude
runs bin/chunk-preflight (bin/chunk_preflight/), which fast-forwards the checkout and finds the
chunk's facts; chunk-preflight --help lists them, and prompts.preflight_facts in
bin/loop_claude/cycle/prompts.py quotes them in the first prompt. A judge then reads the
transcript's end, the premises, and the records: the project's AGENTS.md and docs/decisions.md,
and the human's ~/.claude/CLAUDE.md, ~/.claude/rules/*.md and
runs bin/chunk-preflight (bin/chunk_preflight/), which finds the chunk's facts and makes its
worktree; chunk-preflight --help lists them, and prompts.preflight_facts in
bin/loop_claude/cycle/prompts.py quotes them in the first prompt. A preflight that fails, or is
still running after 600 s and is stopped, leaves the worker to find the facts itself. A judge then
reads the transcript's end, the premises, and the records: the project's AGENTS.md and
docs/decisions.md, and the human's ~/.claude/CLAUDE.md, ~/.claude/rules/*.md and
~/.claude/skills/larv-review/standards/*.md, where they exist. It rules whether the chunk, the work
of one PR, is finished. A chunk stays unfinished until each answer the human typed in it that a
later chunk could need is recorded: the premises or the records hold it, or the transcript shows the worker
@@ -48,13 +49,13 @@ run, is asked for one. LOOP_CLAUDE_JUDGE_MODEL overrides it for the judge, LOOP_
for the worker and the interrupt; with both set, nothing is asked.
Where that model is on the routing ladder (bin/model_routing/ladder.py), the worker and the
interrupt run on one of the ladder's rungs: a model at an effort. As a chunk starts, the checkout's
todo.md, read once chunk-preflight has run, routes it, so routing and the preflight's facts name one
item: the next release's top item that does not wait. An item waits while it is marked question,
or while an item that blocks it is still in the table. The item's L picks the worker's rung,
stepping from the model's cheapest rung by WORKER_STEPS in bin/model_routing/ladder.py, below it
for a low L; without such an item, or with its L, E or I unscored, the chunk runs on the model's
cheapest rung. The
interrupt run on one of the ladder's rungs: a model at an effort. As a chunk starts, todo.md on the
default branch, as chunk-preflight has just fetched it, routes it: its earliest release's top item
that does not wait, the item the preflight states where that release is the next. An item waits
while it is marked question, or while an item that blocks it is still in the table. The item's L
picks the worker's rung, stepping from the model's cheapest rung by WORKER_STEPS in
bin/model_routing/ladder.py, below it for a low L; without such an item, or with its L, E or I
unscored, the chunk runs on the model's cheapest rung. The
item's E + I picks the reviewers' rung, stepping up from the cheapest rung by REVIEW_STEPS there,
never below the worker's rung. The worker's first prompt names the rung and the item, and asks the
worker to name each item the chunk takes, with its L and E + I, and to count the item's size again
@@ -153,6 +154,7 @@ from loop_claude.loop.routing_check import check_routing
from loop_claude.project.checkout import checkout_root
from loop_claude.cycle.run import Cycle, run_cycle
from loop_claude.loop.reload import decode_handed, exec_if_edited, fingerprint, LoopRun, RELOAD_FLAG
from git_repo import default_branch_todo
from loop_claude.effects import Effects
from failure import Failure
from loop_claude.cycle.judge import Finished, Unfinished
@@ -171,6 +173,9 @@ from model_routing.route import Route, route_from
from claude_code.session import Session, session_named, session_open, transcript_file
from loop_claude.stop import Stop
# Seconds before routing gives up asking origin for its default branch, which it asks only where the checkout records none, and routes on the project's rung.
ORIGIN_TIMEOUT = 60
def main(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launcher: pathlib.Path, cwd: pathlib.Path, effects: Effects) -> int:
try:
@@ -195,8 +200,6 @@ def run_loop(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launc
if stop := exec_if_edited(launcher, baseline, loop_run, effects):
return stop
loop_run = dataclasses.replace(loop_run, cycle_number=loop_run.cycle_number + 1)
# First, so the premises, the records and the plan item routing reads are the checkout's as the preflight fast-forwarded it.
facts = "" if session_open(session) else chunk_facts(launcher.with_name("chunk-preflight"), loop_run.root, effects)
premises = read_premises(loop_run.root)
if isinstance(premises, Stop):
return premises
@@ -206,9 +209,11 @@ def run_loop(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launc
models = get_or_ask_models(key, paths, env, effects)
if isinstance(models, Stop):
return models
# Before routing, which reads the plan as the preflight's fetch left it; after the reads above, so a loop that stops on one makes no worktree.
facts = "" if session_open(session) else chunk_facts(launcher.with_name("chunk-preflight"), loop_run.root, effects)
anchor = project_rung(models.worker)
root = loop_run.root
loop_run = routed(loop_run, anchor, lambda: archived_route(archive_folder, session), lambda: plan_item(root))
loop_run = routed(loop_run, anchor, lambda: archived_route(archive_folder, session), lambda: plan_item(default_branch_todo(root, ORIGIN_TIMEOUT)))
route = loop_run.route or Route(Rung(models.worker))
print(f"\n=== cycle {loop_run.cycle_number}, worker on {route.rung} ===", flush=True)
verdict = run_cycle(Cycle(anchor=anchor, effects=effects, facts=facts, judge_model=models.judge, paths=paths, premises=premises, project_archive=archive_folder, records=records, root=loop_run.root, route=route, session=session, task=loop_run.task, unfinished_evidence=loop_run.unfinished_evidence))
@@ -258,23 +263,15 @@ def archived_route(archive_folder: pathlib.Path, session: Session) -> Route | No
def chunk_facts(preflight: pathlib.Path, root: str, effects: Effects) -> str:
"""What chunk-preflight printed at the checkout root, for a fresh worker's prompt, or why it could not run."""
try:
done = effects.python([str(preflight)], root)
except OSError as failure:
return prompts.preflight_failed(str(failure))
done = effects.python([str(preflight)], root)
if done.returncode:
return prompts.preflight_failed(done.stderr.strip() or f"it exited {done.returncode}")
return prompts.preflight_facts(done.stdout.strip())
def plan_item(root: str) -> Item | None:
"""The item that routes a chunk, from the checkout's todo.md: the file chunk-preflight reads, and the pick, todo_table.next_item, it makes. None without one, so the chunk runs on the project's rung."""
try:
item = routed_item(pathlib.Path(root, "todo.md").read_text(encoding="utf-8"))
except FileNotFoundError:
return None
except (OSError, ValueError) as failure:
item = Failure(f"could not read todo.md: {failure}")
def plan_item(todo: str | Failure) -> Item | None:
"""The item that routes a chunk, from todo.md as git_repo.default_branch_todo reads it, as chunk-preflight does, so both take todo_table.next_item's pick. None without one, so the chunk runs on the project's rung."""
item = todo if isinstance(todo, Failure) else routed_item(todo)
if isinstance(item, Failure):
print(f"routing on the project's rung: {item.reason}", file=sys.stderr)
return None
+4 -4
View File
@@ -80,11 +80,11 @@ def fingerprint(launcher: pathlib.Path) -> str:
def exec_if_edited(launcher: pathlib.Path, baseline: str, loop_run: LoopRun, effects: Effects) -> Stop | None:
if fingerprint(launcher) == baseline:
return None
trial = effects.python([str(launcher), "--help"], loop_run.root)
if trial.returncode != 0:
print(f"keeping the running script: {trial.stderr.strip() or f'exit {trial.returncode}'}", file=sys.stderr)
return None
try:
trial = effects.python([str(launcher), "--help"], loop_run.root)
if trial.returncode != 0:
print(f"keeping the running script: {trial.stderr.strip() or f'exit {trial.returncode}'}", file=sys.stderr)
return None
effects.execv(sys.executable, [sys.executable, str(launcher), RELOAD_FLAG, json.dumps(dataclasses.asdict(loop_run))])
except OSError as failure:
return Stop(1, f"could not reload loop-claude: {failure.strerror}; rerun loop-claude <task>")