Answer architecture round 1: 0 🔴, 12 🟡; break the import loop, share the interrupt hand-over and formats, measure under a lock 20 cycles past the last measurement, go on off a terminal, and add a reset
This commit is contained in:
@@ -60,17 +60,21 @@ and counts its unfinished verdicts afresh. A rung no longer on the ladder, or be
|
||||
item's R + C picks, is dropped, and the chunk is routed afresh from todo.md. A todo.md or an
|
||||
archive that cannot be read or parsed is said on stderr, and the chunk is routed without it.
|
||||
|
||||
Every 20th cycle across all projects in the archive, counting the cycles a verdict closed, it
|
||||
measures every finished chunk there, with no model run: tokens by project, subagent type, rung and
|
||||
the tool whose results they took in, and for each chunk an item routed, by the rung it started on,
|
||||
its review rounds past each pass's first, its unfinished verdicts and its subagents' rungs. It
|
||||
writes them to routing-figures.md at the archive's root. They call for a routing change when chunks
|
||||
routed onto a rung took more review rounds or unfinished verdicts than chunks routed onto the next
|
||||
rung up, each rung with 5 chunks or more, or when the reports of 5 or more subagents of one type
|
||||
were longer than the tool results they read. Each call not raised before is an interrupt: claude
|
||||
on the terminal in ~/.claude, asked the calls. Once that claude ends, the calls are listed in
|
||||
routing-calls-raised.md beside the figures, and never raised again. A figure that cannot be
|
||||
measured or written is said on stderr, and the loop goes on.
|
||||
Every 20 cycles across all projects in the archive, counting the cycles a verdict closed, the loop
|
||||
that closes the 20th measures every finished chunk there, with no model run: tokens by project,
|
||||
subagent type, rung and the tool whose results they took in, and for each chunk an item routed, by
|
||||
the rung it started on, its review rounds past each pass's first, its unfinished verdicts and its
|
||||
subagents' rungs. It writes them to routing-figures.md at the archive's root. They call for a
|
||||
routing change when chunks routed onto a rung took more review rounds or unfinished verdicts than
|
||||
chunks routed onto the next rung up, each rung with 5 chunks or more, or when the reports of 5 or
|
||||
more subagents of one type were longer than the tool results they read. Each call not raised before
|
||||
is an interrupt: claude, on the project's model, on the terminal in ~/.claude, asked to put the
|
||||
calls to the human. Once that claude ends, the calls are listed in routing-calls-raised.md beside the
|
||||
figures, and not raised again. Off a terminal, the calls are said on stderr, the loop goes on, and
|
||||
they are raised again at the next measurement. A line `- <UTC time> Reset` in
|
||||
routing-calls-raised.md restarts both: the figures count only chunks that finished after it, and a
|
||||
call raised before it may be raised again. A figure that cannot be measured or written is said on
|
||||
stderr, and the loop goes on.
|
||||
|
||||
A change to bin/loop-claude or any bin/**/*.py takes effect at the next cycle boundary, once
|
||||
loop-claude --help succeeds: the loop reloads into the edited script.
|
||||
@@ -121,7 +125,7 @@ from loop_claude.loop.reload import decode_handed, exec_if_edited, fingerprint,
|
||||
from loop_claude.effects import Effects
|
||||
from failure import Failure
|
||||
from loop_claude.cycle.judge import Finished, Unfinished
|
||||
from loop_claude.routing import first_route, kept, Route, route_from, routed_item, stepped
|
||||
from loop_claude.routing import first_route, kept, routed_item, stepped
|
||||
from loop_claude.project.model_choice import get_or_ask_models
|
||||
from todo_table import Item
|
||||
from transcript_archive.read import latest_worker
|
||||
@@ -131,6 +135,7 @@ from project_key import project_key
|
||||
from model_routing.ladder import project_rung, Rung
|
||||
from loop_claude.project.premises import read_premises
|
||||
from loop_claude.project.records import read_records
|
||||
from model_routing.route import Route, route_from
|
||||
from claude_code.session import Session, session_named, transcript_file
|
||||
from loop_claude.stop import Stop
|
||||
|
||||
@@ -178,7 +183,7 @@ def run_loop(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launc
|
||||
before, loop_run = loop_run.route, after_verdict(loop_run, anchor, verdict)
|
||||
if stop := archive_step(archive_folder, session, loop_run, before, effects):
|
||||
return stop
|
||||
if stop := check_routing(archive_root(paths.home, env), paths, effects):
|
||||
if stop := check_routing(archive_root(paths.home, env), anchor or Rung(models.worker), paths, effects):
|
||||
return stop
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import types
|
||||
import typing
|
||||
|
||||
from loop_claude.effects import Effects
|
||||
from loop_claude.routing import Route
|
||||
from model_routing.route import Route
|
||||
from loop_claude.stop import Stop
|
||||
|
||||
RELOAD_FLAG = "--reloaded"
|
||||
|
||||
@@ -1,55 +1,59 @@
|
||||
"""Every CYCLES_PER_CHECK-th cycle across all projects, measure the archive's routing figures, keep them at its root, and interrupt the human with each call for a routing change not raised before: docs/decisions.md → `routing:`."""
|
||||
"""Every CYCLES_PER_CHECK cycles across all projects, measure the archive's routing figures, keep them at its root, and interrupt the human with each call for a routing change not raised before: docs/decisions.md → `routing:`."""
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
from routing_figures import archive
|
||||
from routing_figures.measure import calls, render, totals
|
||||
from routing_figures.measure import calls, due, render, totals
|
||||
from loop_claude.effects import Effects
|
||||
from failure import Failure
|
||||
from loop_claude.stop import needs_terminal, Stop
|
||||
from loop_claude.cycle.interrupt import hand_over
|
||||
from loop_claude.paths import Paths
|
||||
from claude_code.trust import trust
|
||||
from model_routing.ladder import Rung
|
||||
from loop_claude.stop import Stop
|
||||
from utc_stamp import utc
|
||||
from loop_claude.project.checkout import worktrees
|
||||
|
||||
CYCLES_PER_CHECK = 20
|
||||
ANSWER_CALLS = "answer the routing calls above"
|
||||
|
||||
|
||||
def check_routing(root: pathlib.Path, paths: Paths, effects: Effects) -> Stop | None:
|
||||
"""Stops only for an interrupt it cannot hold; a figure it cannot measure or keep is said on stderr, and the loop goes on."""
|
||||
new = new_calls(root, paths, effects)
|
||||
if isinstance(new, Failure):
|
||||
print(f"routing figures: {new.reason}", file=sys.stderr)
|
||||
return None
|
||||
return raise_calls(root, new, paths, effects) if new else None
|
||||
def check_routing(root: pathlib.Path, rung: Rung, paths: Paths, effects: Effects) -> Stop | None:
|
||||
"""Stops only when claude cannot start for the calls; a figure it cannot measure or keep is said on stderr, and the loop goes on. rung runs the claude the calls are put to."""
|
||||
with archive.locked(root) as held:
|
||||
new = new_calls(root, paths, effects) if held else []
|
||||
if isinstance(new, Failure):
|
||||
print(f"routing figures: {new.reason}", file=sys.stderr)
|
||||
return None
|
||||
return raise_calls(root, new, rung, paths, effects) if new else None
|
||||
|
||||
|
||||
def new_calls(root: pathlib.Path, paths: Paths, effects: Effects) -> list[str] | Failure:
|
||||
"""The calls not raised before, measured and kept at every CYCLES_PER_CHECK-th cycle; none at any other."""
|
||||
"""Once due, measures and keeps the figures, and returns their calls not raised since the latest reset; none while not due."""
|
||||
cycle = archive.cycles(root)
|
||||
if isinstance(cycle, Failure) or not cycle or cycle % CYCLES_PER_CHECK:
|
||||
return cycle if isinstance(cycle, Failure) else []
|
||||
last = archive.last_measured(root)
|
||||
if isinstance(cycle, Failure) or isinstance(last, Failure) or not due(cycle, last):
|
||||
return cycle if isinstance(cycle, Failure) else last if isinstance(last, Failure) else []
|
||||
kept = archive.raised(root)
|
||||
if isinstance(kept, Failure):
|
||||
return kept
|
||||
print(f"\n=== cycle {cycle} across loop-claude's archive: measuring the routing figures ===", flush=True)
|
||||
measured = archive.measure_archive(root, str(paths.home))
|
||||
measured = archive.measure_archive(root, str(paths.home), kept.since)
|
||||
if isinstance(measured, Failure):
|
||||
return measured
|
||||
figures = totals(measured)
|
||||
found = calls(figures)
|
||||
return archive.write_figures(root, render(figures, found, utc(effects.now()), cycle)) or archive.unraised(root, found)
|
||||
if unwritten := archive.write_figures(root, render(figures, found, utc(effects.now()), cycle, kept.since)):
|
||||
return unwritten
|
||||
return [call for call in found if call not in kept.calls]
|
||||
|
||||
|
||||
def raise_calls(root: pathlib.Path, new: list[str], paths: Paths, effects: Effects) -> Stop | None:
|
||||
"""Hands the terminal to a claude in this setup's checkout, where the routing decision lives; a call counts as raised once that claude ends."""
|
||||
question = "loop-claude's routing figures call for a routing change, which is yours to decide:\n" + "".join(f"- {call}\n" for call in new) + f"The figures are in {root / archive.FIGURES}. The ladder's bands and the delegation rule are docs/decisions.md → `routing:`."
|
||||
print(f"\n{question}", file=sys.stderr)
|
||||
if stop := needs_terminal(ANSWER_CALLS, effects.on_terminal()):
|
||||
return stop
|
||||
trust(paths.claude_json, worktrees(str(paths.claude_dir), effects))
|
||||
try:
|
||||
effects.claude_on_terminal(["--permission-mode", "bypassPermissions", question], str(paths.claude_dir))
|
||||
except OSError as failure:
|
||||
return Stop(1, f"could not start claude for the routing calls: {failure.strerror}")
|
||||
def raise_calls(root: pathlib.Path, new: list[str], rung: Rung, paths: Paths, effects: Effects) -> Stop | None:
|
||||
"""Puts the calls to the human through a claude in this setup's checkout, where the routing decision lives. Off a terminal they are only said, and raised again at the next measurement; this repo's AGENTS.md files them meanwhile."""
|
||||
listed = "".join(f"- {call}\n" for call in new)
|
||||
print(f"\nloop-claude's routing figures call for a routing change:\n{listed}The figures: {root / archive.FIGURES}", file=sys.stderr)
|
||||
if not effects.on_terminal():
|
||||
print("Not on a terminal: the calls are raised again at the next measurement.", file=sys.stderr)
|
||||
return None
|
||||
prompt = f"Put these calls for a routing change from loop-claude's figures to the human, and change nothing until they answer:\n{listed}The figures are in {root / archive.FIGURES}. The ladder, its bands and the delegation rule are docs/decisions.md → `routing:`, and a change to them is the human's."
|
||||
if unstarted := hand_over(rung, [prompt], str(paths.claude_dir), paths, effects):
|
||||
return Stop(1, f"could not start claude for the routing calls: {unstarted.reason}")
|
||||
# Raised once the human has seen them, answered or not: an unanswered call reaches the plan through AGENTS.md, so it is not asked twice.
|
||||
if unmarked := archive.mark_raised(root, new, utc(effects.now())):
|
||||
print(f"routing figures: {unmarked.reason}", file=sys.stderr)
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user