Answer principles round 1: 0 🔴, 1 🟡 (0 misread); test the trials' imports from bin, pass one loop value through loop/, type the Exempt reasons
CI / tests (pull_request) Successful in 2m20s
CI / tests (pull_request) Successful in 2m20s
This commit is contained in:
@@ -5,11 +5,11 @@ import re
|
||||
import typing
|
||||
|
||||
from branch_chunks.cut import Branch, BranchChunk, NOT_WORK
|
||||
from release_plan.todo_table import Item
|
||||
from release_plan.todo_table import Exempt, Item
|
||||
from review_rules.round_titles import title_counts
|
||||
|
||||
# The Exempt cells, per ~/.claude/rules/todo-items.md, that mark an item fixing a defect.
|
||||
FIXES = ("defect", "security")
|
||||
FIXES: tuple[Exempt, ...] = ("defect", "security")
|
||||
HUNK = re.compile(r"@@ -([0-9]+)(?:,([0-9]+))? \+[0-9]+(?:,([0-9]+))? @@")
|
||||
BLAME_HEADER = re.compile(r"([0-9a-f]{40}|[0-9a-f]{64}) [0-9]+ [0-9]+")
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ def rule(cycle: Cycle, transcript_path: str, quoted_answers: int) -> Ruled | Sto
|
||||
def ruling_outcome(cycle: Cycle, ruling: Interrupt | QuotedAnswer, quoted_answers: int) -> str:
|
||||
"""The archive's outcome for a ruling: interrupted where it goes to the human, with the question put to them, and else answered from README.md or the records."""
|
||||
if isinstance(ruling, QuotedAnswer) and not to_the_human(ruling, quoted_answers):
|
||||
return outcomes.answered(ruling.question, prompts.QUOTE_SOURCES, ruling.answer, ruling.evidence, ruling.escalation, str(judge_of(cycle)), cycle.route.worker_line(), ruling.judge_cost)
|
||||
return outcomes.answered(question=ruling.question, sources=prompts.QUOTE_SOURCES, answer=ruling.answer, evidence=ruling.evidence, escalation=ruling.escalation, judge=str(judge_of(cycle)), worker=cycle.route.worker_line(), judge_cost=ruling.judge_cost)
|
||||
return outcomes.interrupted(question_for(ruling), ruling.evidence, str(judge_of(cycle)), ruling.escalation, cycle.route.worker_line(), ruling.judge_cost)
|
||||
|
||||
|
||||
|
||||
@@ -9,26 +9,27 @@ from failure import Failure
|
||||
from loop_claude.routing import first_route, kept, routed_item
|
||||
from release_plan.todo_table import Item
|
||||
from transcript_archive.read import latest_worker
|
||||
from loop_claude.loop.this_loop import Loop
|
||||
from loop_claude.cycle import prompts
|
||||
from model_routing.route import Route, route_from
|
||||
from model_routing.ladder import Rung
|
||||
from claude_code.session import Session, session_open, transcript_file
|
||||
from loop_state.running_loops import Show, taken_items
|
||||
from claude_code.session import session_open, transcript_file
|
||||
from loop_state.running_loops import taken_items
|
||||
|
||||
# Seconds routing waits for origin to name its default branch, asked only where the checkout records none; past them, the chunk runs on the project's rung.
|
||||
ORIGIN_TIMEOUT = 60
|
||||
|
||||
|
||||
def shown_items(show: Show, root: str, routed: int, effects: Effects) -> typing.Callable[[tuple[int, ...]], None]:
|
||||
def shown_items(loop: Loop, routed: int) -> typing.Callable[[tuple[int, ...]], None]:
|
||||
"""A function that lists in loop-inbox the items a chunk takes, given the IDs the judge found taken in. routed is the item the chunk was routed on, 0 for none. shown_items reads todo.md once, as the cycle starts, and the function shows those taglines."""
|
||||
todo = fetched_todo(root, effects)
|
||||
return lambda taken_in: show(taken_items(todo, routed, taken_in))
|
||||
todo = fetched_todo(loop)
|
||||
return lambda taken_in: loop.listed.show(taken_items(todo, routed, taken_in))
|
||||
|
||||
|
||||
def fetched_todo(root: str, effects: Effects) -> str | Failure:
|
||||
def fetched_todo(loop: Loop) -> str | Failure:
|
||||
"""todo.md on the default branch, as last fetched. fetched_plan reads it too, but also the release tag, CHANGELOG.md and each todo.md since the tag, which the listing doesn't need."""
|
||||
ref = default_ref(root, ORIGIN_TIMEOUT, run=effects.git)
|
||||
return ref if isinstance(ref, Failure) else file_at(ref, "todo.md", root, effects.git)
|
||||
ref = default_ref(loop.root, ORIGIN_TIMEOUT, run=loop.effects.git)
|
||||
return ref if isinstance(ref, Failure) else file_at(ref, "todo.md", loop.root, loop.effects.git)
|
||||
|
||||
|
||||
def routed(route: Route | None, project: Rung | None, model: str, archived: typing.Callable[[], Route | None], item: typing.Callable[[], Item | None]) -> Route:
|
||||
@@ -42,37 +43,37 @@ def routed(route: Route | None, project: Rung | None, model: str, archived: typi
|
||||
return route if route and kept(route, project) else first_route(project, item())
|
||||
|
||||
|
||||
def archived_route(archive_folder: pathlib.Path, session: Session, effects: Effects) -> Route | None:
|
||||
"""The route the latest verdict archived for the session's open chunk names; None for a chunk not yet judged."""
|
||||
transcript = transcript_file(session)
|
||||
def archived_route(archive_folder: pathlib.Path, loop: Loop) -> Route | None:
|
||||
"""The route the latest verdict archived for the loop's open chunk names; None for a chunk not yet judged."""
|
||||
transcript = transcript_file(loop.session)
|
||||
worker = latest_worker(archive_folder, transcript) if transcript else None
|
||||
if isinstance(worker, Failure):
|
||||
say(f"routing the chunk afresh: {worker.reason}", effects)
|
||||
say(f"routing the chunk afresh: {worker.reason}", loop.effects)
|
||||
return None
|
||||
route = route_from(worker) if worker else None
|
||||
if worker and route is None:
|
||||
say(f"routing the chunk afresh: the archive's latest Worker: line names no route loop-claude can read: {worker}", effects)
|
||||
say(f"routing the chunk afresh: the archive's latest Worker: line names no route loop-claude can read: {worker}", loop.effects)
|
||||
return route
|
||||
|
||||
|
||||
def chunk_start(session: Session, preflight: pathlib.Path, root: str, effects: Effects) -> tuple[str, typing.Callable[[], Item | None]]:
|
||||
def chunk_start(loop: Loop) -> tuple[str, typing.Callable[[], Item | None]]:
|
||||
"""The facts for a fresh worker's prompt, empty where the session is open, and the reader of the item that routes the chunk. The reader reads the default branch as last fetched: for a fresh chunk, by the preflight that runs first; for an open session, which runs none, by whatever fetched last."""
|
||||
facts = "" if session_open(session) else chunk_facts(preflight, root, effects)
|
||||
return facts, lambda: plan_item(fetched_plan(root, effects), effects)
|
||||
facts = "" if session_open(loop.session) else chunk_facts(loop)
|
||||
return facts, lambda: plan_item(fetched_plan(loop), loop.effects)
|
||||
|
||||
|
||||
def chunk_facts(preflight: pathlib.Path, root: str, effects: Effects) -> str:
|
||||
def chunk_facts(loop: Loop) -> str:
|
||||
"""What `chunk-preflight --worktree` printed at the checkout root, for a fresh worker's prompt, or why it could not run."""
|
||||
done = effects.python([str(preflight), "--worktree"], root)
|
||||
done = loop.effects.python([str(loop.launcher.with_name("chunk-preflight")), "--worktree"], loop.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 fetched_plan(root: str, effects: Effects) -> DefaultPlan | Failure:
|
||||
def fetched_plan(loop: Loop) -> DefaultPlan | Failure:
|
||||
"""What the default branch, as last fetched, holds for routing."""
|
||||
ref = default_ref(root, ORIGIN_TIMEOUT, run=effects.git)
|
||||
return ref if isinstance(ref, Failure) else default_plan(root, ref, effects.git)
|
||||
ref = default_ref(loop.root, ORIGIN_TIMEOUT, run=loop.effects.git)
|
||||
return ref if isinstance(ref, Failure) else default_plan(loop.root, ref, loop.effects.git)
|
||||
|
||||
|
||||
def plan_item(plan: DefaultPlan | Failure, effects: Effects) -> Item | None:
|
||||
|
||||
@@ -3,31 +3,31 @@ import dataclasses
|
||||
import pathlib
|
||||
|
||||
from loop_claude.cycle.run import archived_step, archived_stop, Concluded
|
||||
from loop_effects.effects import Effects
|
||||
from loop_claude.verdicts import Finished
|
||||
from loop_claude.loop.this_loop import Loop
|
||||
from loop_claude.loop.reload import LoopRun
|
||||
from loop_claude.stop import needs_human, Stop
|
||||
from loop_claude.routing import next_route, step_up
|
||||
from model_routing.ladder import Rung
|
||||
from claude_code.session import Session, transcript_file
|
||||
from claude_code.session import transcript_file
|
||||
|
||||
# How many unfinished verdicts running end the loop, so a worker and a judge that disagree about a chunk cannot cycle unattended without end. A policy number, not derived from the routing steps: well above the two unfinished verdicts running that archived chunks have reached at most, and low enough that a stuck pair is stopped after six cycles. It counts every unfinished verdict, including those of cycles where the human answered an interrupt: a rerun is cheap, and a chunk that needs that many answers is worth a look. The human confirmed both the number and what it counts.
|
||||
UNFINISHED_LIMIT = 6
|
||||
|
||||
|
||||
def closed_cycle(loop_run: LoopRun, project: Rung | None, concluded: Concluded, archive_folder: pathlib.Path, session: Session, effects: Effects) -> LoopRun | Stop:
|
||||
def closed_cycle(loop_run: LoopRun, project: Rung | None, concluded: Concluded, archive_folder: pathlib.Path, loop: Loop) -> LoopRun | Stop:
|
||||
"""The loop run after a cycle concluded, with the step-up archived; the stop that needs the human, archived, once the chunk has had UNFINISHED_LIMIT unfinished verdicts running."""
|
||||
after = after_verdict(loop_run, project, concluded)
|
||||
# A finished chunk drops its route, so it has no step-up, and its run of unfinished verdicts restarts.
|
||||
if after.route is None:
|
||||
return after
|
||||
# The unfinished verdict, archived as the cycle closed, names the route its cycle ended on; the step-up names the one the next cycle runs on.
|
||||
path = transcript_file(session)
|
||||
if path and (failure := archived_step(archive_folder, path, after.task, step_up(concluded.route, after.route), effects)):
|
||||
path = transcript_file(loop.session)
|
||||
if path and (failure := archived_step(archive_folder, path, after.task, step_up(concluded.route, after.route), loop.effects)):
|
||||
return Stop(1, failure.reason)
|
||||
if limit := reached_limit(after):
|
||||
# Archived with the route the next cycle would run on, so a rerun resumes there.
|
||||
return archived_stop(archive_folder, session, after.task, after.route, limit, limit.reason, effects)
|
||||
return archived_stop(archive_folder, loop.session, after.task, after.route, limit, limit.reason, loop.effects)
|
||||
return after
|
||||
|
||||
|
||||
|
||||
@@ -13,13 +13,14 @@ from loop_effects.effects import Effects, say
|
||||
from failure import Failure
|
||||
from loop_claude.project.model_choice import get_or_ask_models
|
||||
from loop_claude.loop.usage import HELP
|
||||
from loop_state.running_loops import Listed, shown_running
|
||||
from loop_claude.loop.this_loop import Loop
|
||||
from loop_state.paths import Paths
|
||||
from transcript_archive.project_key import project_key
|
||||
from model_routing.ladder import project_rung
|
||||
from loop_claude.project.premises import read_premises
|
||||
from loop_claude.project.records import read_records
|
||||
from claude_code.session import Session, session_named
|
||||
from claude_code.session import session_named
|
||||
from loop_state.running_loops import shown_running
|
||||
from loop_claude.stop import Stop
|
||||
|
||||
|
||||
@@ -42,45 +43,46 @@ def run_loop(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launc
|
||||
# "A " is the human's cue in the session picker that the session is the loop's.
|
||||
session = session_named(f"A {project_key(loop_run.root, paths.home)} loop-claude", paths.claude_code_transcripts)
|
||||
with shown_running(paths.waiting, str(session.id), loop_run.root, effects) as listed:
|
||||
loop = Loop(root=loop_run.root, session=session, listed=listed, paths=paths, env=env, launcher=launcher, effects=effects)
|
||||
while True:
|
||||
if stop := exec_if_edited(launcher, baseline, loop_run, effects):
|
||||
if stop := exec_if_edited(loop, baseline, loop_run):
|
||||
return stop
|
||||
loop_run = dataclasses.replace(loop_run, cycle_number=loop_run.cycle_number + 1)
|
||||
cycle = next_cycle(loop_run, session, listed, paths, env, launcher, effects)
|
||||
cycle = next_cycle(loop_run, loop)
|
||||
if isinstance(cycle, Stop):
|
||||
return cycle
|
||||
concluded = run_cycle(cycle)
|
||||
if isinstance(concluded, Stop):
|
||||
return concluded
|
||||
closed = closed_cycle(loop_run, cycle.project, concluded, cycle.project_archive, session, effects)
|
||||
closed = closed_cycle(loop_run, cycle.project, concluded, cycle.project_archive, loop)
|
||||
if isinstance(closed, Stop):
|
||||
return closed
|
||||
loop_run = closed
|
||||
# Off the ladder the worker runs on the project's model itself, which its route names.
|
||||
if stop := check_routing(archive_root(paths.home, env), loop_run.root, str(session.id), cycle.project or cycle.route.rung, paths, listed.folder, effects):
|
||||
if stop := check_routing(archive_root(paths.home, env), cycle.project or cycle.route.rung, loop):
|
||||
return stop
|
||||
|
||||
|
||||
def next_cycle(loop_run: LoopRun, session: Session, listed: Listed, paths: Paths, env: typing.Mapping[str, str], launcher: pathlib.Path, effects: Effects) -> Cycle | Stop:
|
||||
def next_cycle(loop_run: LoopRun, loop: Loop) -> Cycle | Stop:
|
||||
"""The cycle loop_run runs next, from the premises, the records and the project's models read afresh, and the route the chunk runs on; the stop where one of them cannot be read."""
|
||||
premises = read_premises(loop_run.root)
|
||||
premises = read_premises(loop.root)
|
||||
if isinstance(premises, Failure):
|
||||
return Stop(1, premises.reason)
|
||||
records = read_records(loop_run.root, paths.claude_dir)
|
||||
records = read_records(loop.root, loop.paths.claude_dir)
|
||||
if isinstance(records, Failure):
|
||||
return Stop(1, records.reason)
|
||||
models = get_or_ask_models(project_key(loop_run.root, paths.home), paths, env, effects)
|
||||
models = get_or_ask_models(project_key(loop.root, loop.paths.home), loop.paths, loop.env, loop.effects)
|
||||
if isinstance(models, Stop):
|
||||
return models
|
||||
archive_folder = project_archive(loop_run.root, paths.home, env)
|
||||
archive_folder = project_archive(loop.root, loop.paths.home, loop.env)
|
||||
# After the reads above, so a loop that stops on one makes no worktree.
|
||||
facts, item = chunk_start(session, launcher.with_name("chunk-preflight"), loop_run.root, effects)
|
||||
facts, item = chunk_start(loop)
|
||||
project = project_rung(models.worker)
|
||||
route = routed(loop_run.route, project, models.worker, lambda: archived_route(archive_folder, session, effects), item)
|
||||
say(f"\n=== cycle {loop_run.cycle_number}, worker on {route.rung} ===", effects, stdout=True)
|
||||
show_taken_in = shown_items(listed.show, loop_run.root, route.item, effects)
|
||||
route = routed(loop_run.route, project, models.worker, lambda: archived_route(archive_folder, loop), item)
|
||||
say(f"\n=== cycle {loop_run.cycle_number}, worker on {route.rung} ===", loop.effects, stdout=True)
|
||||
show_taken_in = shown_items(loop, route.item)
|
||||
show_taken_in(loop_run.items_taken_in)
|
||||
return Cycle(effects=effects, facts=facts, judge_model=models.judge, premises=premises, project=project, project_archive=archive_folder, questions=listed.folder, records=records, root=loop_run.root, route=route, session=session, show_taken_in=show_taken_in, task=loop_run.task, unfinished_evidence=loop_run.unfinished_evidence)
|
||||
return Cycle(effects=loop.effects, facts=facts, judge_model=models.judge, premises=premises, project=project, project_archive=archive_folder, questions=loop.listed.folder, records=records, root=loop.root, route=route, session=loop.session, show_taken_in=show_taken_in, task=loop_run.task, unfinished_evidence=loop_run.unfinished_evidence)
|
||||
|
||||
|
||||
def loop_run_from(argv: list[str], cwd: pathlib.Path, effects: Effects) -> LoopRun | Stop:
|
||||
|
||||
@@ -5,8 +5,9 @@ import pathlib
|
||||
import sys
|
||||
import typing
|
||||
|
||||
from loop_effects.effects import Effects, say
|
||||
from loop_claude.loop.this_loop import Loop
|
||||
from model_routing.route import Route, route_of
|
||||
from loop_effects.effects import say
|
||||
from loop_claude.stop import Stop
|
||||
|
||||
RELOAD_FLAG = "--reloaded"
|
||||
@@ -94,15 +95,15 @@ def fingerprint(launcher: pathlib.Path) -> str:
|
||||
|
||||
|
||||
# A loop runs unattended for hours, often on its own checkout: reloading puts each edit to loop-claude to use without the human rerunning it.
|
||||
def exec_if_edited(launcher: pathlib.Path, baseline: str, loop_run: LoopRun, effects: Effects) -> Stop | None:
|
||||
if fingerprint(launcher) == baseline:
|
||||
def exec_if_edited(loop: Loop, baseline: str, loop_run: LoopRun) -> Stop | None:
|
||||
if fingerprint(loop.launcher) == baseline:
|
||||
return None
|
||||
trial = effects.python([str(launcher), "--help"], loop_run.root)
|
||||
trial = loop.effects.python([str(loop.launcher), "--help"], loop.root)
|
||||
if trial.returncode != 0:
|
||||
say(f"keeping the running script: {trial.stderr.strip() or f'exit {trial.returncode}'}", effects)
|
||||
say(f"keeping the running script: {trial.stderr.strip() or f'exit {trial.returncode}'}", loop.effects)
|
||||
return None
|
||||
try:
|
||||
effects.execv(sys.executable, [sys.executable, str(launcher), RELOAD_FLAG, json.dumps(dataclasses.asdict(loop_run))])
|
||||
loop.effects.execv(sys.executable, [sys.executable, str(loop.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>")
|
||||
return None
|
||||
|
||||
@@ -8,6 +8,7 @@ from loop_state.hand_over import claude_args, ClaudeCommand, hand_over
|
||||
from loop_effects.effects import Effects, say
|
||||
from failure import Failure
|
||||
from loop_state.waiting.listing import listed
|
||||
from loop_claude.loop.this_loop import Loop
|
||||
from loop_state.paths import Paths
|
||||
from routing_figures.render import render
|
||||
from model_routing.ladder import Rung
|
||||
@@ -16,14 +17,14 @@ from loop_claude.stop import Stop
|
||||
from records.utc_stamp import utc
|
||||
|
||||
|
||||
def check_routing(root: pathlib.Path, checkout: str, session: str, rung: Rung, paths: Paths, questions: pathlib.Path, 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. checkout is the loop's, session is its worker's session id, which loop-inbox lists the calls under, and rung is the rung of the claude that puts the calls to the human."""
|
||||
def check_routing(root: pathlib.Path, rung: Rung, loop: Loop) -> 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. root is the archive's, and rung is the rung of the claude that puts the calls to the human."""
|
||||
with archive.locked(root) as held:
|
||||
new = new_calls(root, paths, effects) if held else []
|
||||
new = new_calls(root, loop.paths, loop.effects) if held else []
|
||||
if isinstance(new, Failure):
|
||||
say(f"routing figures: {new.reason}", effects)
|
||||
say(f"routing figures: {new.reason}", loop.effects)
|
||||
return None
|
||||
return raise_calls(root, checkout, session, new, rung, paths, questions, effects) if new else None
|
||||
return raise_calls(root, new, rung, loop) if new else None
|
||||
|
||||
|
||||
def new_calls(root: pathlib.Path, paths: Paths, effects: Effects) -> list[Call] | Failure:
|
||||
@@ -48,21 +49,21 @@ def new_calls(root: pathlib.Path, paths: Paths, effects: Effects) -> list[Call]
|
||||
return [call for call in found if call not in raised.calls]
|
||||
|
||||
|
||||
def raise_calls(root: pathlib.Path, checkout: str, session: str, new: list[Call], rung: Rung, paths: Paths, questions: pathlib.Path, effects: Effects) -> Stop | None:
|
||||
def raise_calls(root: pathlib.Path, new: list[Call], rung: Rung, loop: Loop) -> Stop | None:
|
||||
"""Puts the calls to the human through a claude in this setup's development clone, where the routing decision is changed; loop-inbox lists them under the loop's checkout while that claude is open. Off a terminal they are only said, and stay in the figures, raised at the next measurement on a terminal."""
|
||||
bullets = "".join(f"- {call.sentence()}\n" for call in new)
|
||||
question = f"loop-claude's routing figures call for a routing change:\n{bullets}The figures: {root / archive.FIGURES}"
|
||||
say(f"\n{question}", effects)
|
||||
if not effects.on_terminal():
|
||||
say("Not on a terminal: the calls are raised again at the next measurement.", effects)
|
||||
say(f"\n{question}", loop.effects)
|
||||
if not loop.effects.on_terminal():
|
||||
say("Not on a terminal: the calls are raised again at the next measurement.", loop.effects)
|
||||
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{bullets}The figures are in {root / archive.FIGURES}. The ladder, its steps and the delegation rule are docs/decisions.md → `routing:`, and a change to them is the human's. Record what they decide in this checkout, the development clone, as ~/.claude/CLAUDE.md says; the next chunk of this repo files the plan item for these calls."
|
||||
ask = Ask(effects.new_id(), session, checkout, question, effects.now(), OpenOnTerminal())
|
||||
with listed(questions, ask, effects):
|
||||
unstarted = hand_over(ClaudeCommand(claude_args(rung, [prompt]), str(paths.config_clone), {}), effects)
|
||||
ask = Ask(loop.effects.new_id(), str(loop.session.id), loop.root, question, loop.effects.now(), OpenOnTerminal())
|
||||
with listed(loop.listed.folder, ask, loop.effects):
|
||||
unstarted = hand_over(ClaudeCommand(claude_args(rung, [prompt]), str(loop.paths.config_clone), {}), loop.effects)
|
||||
if unstarted:
|
||||
return Stop(1, f"could not start claude for the routing calls in {paths.config_clone}, the setup's development clone: {unstarted.reason}")
|
||||
return Stop(1, f"could not start claude for the routing calls in {loop.paths.config_clone}, the setup's development clone: {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 := state.mark_raised(root, new, utc(effects.now())):
|
||||
say(f"routing figures: {unmarked.reason}", effects)
|
||||
if unmarked := state.mark_raised(root, new, utc(loop.effects.now())):
|
||||
say(f"routing figures: {unmarked.reason}", loop.effects)
|
||||
return None
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import dataclasses
|
||||
import pathlib
|
||||
import typing
|
||||
|
||||
from loop_effects.effects import Effects
|
||||
from loop_state.running_loops import Listed
|
||||
from loop_state.paths import Paths
|
||||
from claude_code.session import Session
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Loop:
|
||||
"""One run of loop-claude, as it stays from its first cycle to its last; run_loop builds it once."""
|
||||
# The checkout the loop runs in. LoopRun.root names it too, since a reload hands it on there.
|
||||
root: str
|
||||
# The worker's session, under whose id loop-inbox lists the loop and its questions.
|
||||
session: Session
|
||||
listed: Listed
|
||||
paths: Paths
|
||||
env: typing.Mapping[str, str]
|
||||
# The loop-claude script, whose edits reload the loop and beside which chunk-preflight lies.
|
||||
launcher: pathlib.Path
|
||||
effects: Effects
|
||||
@@ -31,7 +31,7 @@ from loop_state import hand_over, paths, running_loops, session_lock
|
||||
from loop_claude.cycle import interrupt, judge, prompts, retry, run, states, worker
|
||||
from model_routing.ladder import LADDER, Rung
|
||||
from claude_code.reply import Limited
|
||||
from loop_claude.loop import main, reload, routing_check, usage
|
||||
from loop_claude.loop import main, reload, routing_check, this_loop, usage
|
||||
from loop_state.waiting.talk import make_way
|
||||
from machine_load import memory
|
||||
from transcript_archive import outcomes, write
|
||||
@@ -80,6 +80,13 @@ def asks_and_answers(folder):
|
||||
return [path for path in sorted(folder.iterdir()) if path.suffix != ".lock"]
|
||||
|
||||
|
||||
def a_loop(effects, **fields):
|
||||
"""A loop in /r on effects, with fields in place of its defaults."""
|
||||
home = pathlib.Path("/h")
|
||||
defaults = {"root": "/r", "session": session.session_named("A proj loop-claude", home / ".claude" / "projects"), "listed": running_loops.Listed(home / "waiting", lambda items: None), "paths": paths.paths_from(home), "env": {}, "launcher": pathlib.Path("/b/loop-claude")}
|
||||
return this_loop.Loop(**{**defaults, **fields}, effects=effects)
|
||||
|
||||
|
||||
class FakeEffects:
|
||||
"""Effects that record each call and answer from a script, one answer per call."""
|
||||
|
||||
@@ -834,6 +841,11 @@ class RoutingCheck(unittest.TestCase):
|
||||
self.addCleanup(shutil.rmtree, self.home)
|
||||
self.root = self.home / "archive"
|
||||
self.paths = paths.paths_from(self.home)
|
||||
self.session = session.session_named("A log loop-claude", self.paths.claude_code_transcripts)
|
||||
|
||||
def loop(self, fake):
|
||||
"""The loop in /code/log, whose questions loop-inbox lists."""
|
||||
return a_loop(fake.effects(), root="/code/log", session=self.session, listed=running_loops.Listed(self.paths.waiting, lambda items: None), paths=self.paths)
|
||||
|
||||
def chunks(self, count, verdicts, project="log"):
|
||||
"""count finished chunks, each closed by verdicts verdicts, each with one Explore subagent whose report outgrew its searches."""
|
||||
@@ -852,15 +864,15 @@ class RoutingCheck(unittest.TestCase):
|
||||
def check(self, fake):
|
||||
"""What check_routing returns and says for a loop in /code/log."""
|
||||
with contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()) as said:
|
||||
self.enterContext(session_lock.held(self.paths.waiting, "s1"))
|
||||
stop = routing_check.check_routing(self.root, "/code/log", "s1", Rung("m", "high"), self.paths, self.paths.waiting, fake.effects())
|
||||
self.enterContext(session_lock.held(self.paths.waiting, str(self.session.id)))
|
||||
stop = routing_check.check_routing(self.root, Rung("m", "high"), self.loop(fake))
|
||||
return stop, said.getvalue()
|
||||
|
||||
def test_lists_the_calls_in_loop_inbox_while_their_claude_is_open(self):
|
||||
self.chunks(5, 4)
|
||||
question = f"loop-claude's routing figures call for a routing change:\n- Explore subagents' reports took more of the worker's context than their searches would have.\nThe figures: {self.root / 'routing-figures.md'}"
|
||||
def ran(args):
|
||||
self.assertEqual(waiting(self.paths.waiting), [Ask(ASK_ID, "s1", "/code/log", question, NOW, OpenOnTerminal())])
|
||||
self.assertEqual(waiting(self.paths.waiting), [Ask(ASK_ID, str(self.session.id), "/code/log", question, NOW, OpenOnTerminal())])
|
||||
return 0
|
||||
self.check(FakeEffects(on_terminal_claude=[ran], git=[UNREAD]))
|
||||
self.assertEqual(asks_and_answers(self.paths.waiting), [])
|
||||
@@ -945,7 +957,7 @@ class RoutingCheck(unittest.TestCase):
|
||||
new = [Call("reports", ("Explore",)), Call("rounds", ("x", "y"))]
|
||||
fake = FakeEffects(on_terminal_claude=[0])
|
||||
with contextlib.redirect_stderr(io.StringIO()) as said, unittest.mock.patch.object(state, "mark_raised", return_value=Failure("full")):
|
||||
self.assertIsNone(routing_check.raise_calls(self.root, "/code/log", "s1", new, Rung("m", "high"), self.paths, self.paths.waiting, fake.effects()))
|
||||
self.assertIsNone(routing_check.raise_calls(self.root, new, Rung("m", "high"), self.loop(fake)))
|
||||
((args),) = fake.made("claude_on_terminal")
|
||||
self.assertIn(f"change nothing until they answer:\n- {new[0].sentence()}\n- {new[1].sentence()}\nThe figures", args[6])
|
||||
self.assertIn(f"call for a routing change:\n- {new[0].sentence()}\n- {new[1].sentence()}\n", said.getvalue())
|
||||
@@ -1176,25 +1188,25 @@ class RouteSources(unittest.TestCase):
|
||||
transcript = pathlib.Path(home, "projects", "-fake", f"{opened.id}.jsonl")
|
||||
route = Route(Rung("claude-opus-5-5", "high"), 3, 4, 5)
|
||||
with contextlib.redirect_stderr(io.StringIO()) as stderr:
|
||||
self.assertIsNone(chunk_start.archived_route(archive, opened, FakeEffects().effects()))
|
||||
self.assertIsNone(chunk_start.archived_route(archive, a_loop(FakeEffects().effects(), session=opened)))
|
||||
transcript.parent.mkdir(parents=True)
|
||||
transcript.write_text(json.dumps({"type": "queue-operation", "timestamp": "1"}) + "\n")
|
||||
self.assertIsNone(chunk_start.archived_route(archive, opened, FakeEffects().effects()))
|
||||
self.assertIsNone(chunk_start.archived_route(archive, a_loop(FakeEffects().effects(), session=opened)))
|
||||
with contextlib.redirect_stderr(io.StringIO()):
|
||||
self.assertIsNone(write.archive(archive, str(transcript), "Do it.", outcomes.unfinished(route.worker_line(), "working", "j", ""), NOW))
|
||||
with contextlib.redirect_stderr(stderr):
|
||||
self.assertEqual(chunk_start.archived_route(archive, opened, FakeEffects().effects()), route)
|
||||
self.assertEqual(chunk_start.archived_route(archive, a_loop(FakeEffects().effects(), session=opened)), route)
|
||||
self.assertEqual(stderr.getvalue(), "")
|
||||
with contextlib.redirect_stderr(io.StringIO()):
|
||||
self.assertIsNone(write.archive(archive, str(transcript), "Do it.", outcomes.stepped_up(WorkerLine('{"model": "claude-opus-5-5", "rung": 3}')), NOW + 1))
|
||||
with contextlib.redirect_stderr(io.StringIO()) as stderr:
|
||||
self.assertIsNone(chunk_start.archived_route(archive, opened, FakeEffects().effects()))
|
||||
self.assertIsNone(chunk_start.archived_route(archive, a_loop(FakeEffects().effects(), session=opened)))
|
||||
self.assertEqual(stderr.getvalue(), f'{STAMP} routing the chunk afresh: the archive\'s latest Worker: line names no route loop-claude can read: {{"model": "claude-opus-5-5", "rung": 3}}\n')
|
||||
(chunk,) = archive.iterdir()
|
||||
chunk.chmod(0)
|
||||
try:
|
||||
with contextlib.redirect_stderr(io.StringIO()) as stderr:
|
||||
self.assertIsNone(chunk_start.archived_route(archive, opened, FakeEffects().effects()))
|
||||
self.assertIsNone(chunk_start.archived_route(archive, a_loop(FakeEffects().effects(), session=opened)))
|
||||
finally:
|
||||
chunk.chmod(0o700)
|
||||
self.assertTrue(stderr.getvalue().startswith(f"{STAMP} routing the chunk afresh: could not read the archive"), stderr.getvalue())
|
||||
@@ -1239,14 +1251,14 @@ class Steps(unittest.TestCase):
|
||||
before = Route(self.OPUS, 3, 3, 4)
|
||||
with contextlib.redirect_stderr(io.StringIO()):
|
||||
self.assertIsNone(write.archive(archive, str(transcript), "Do it.", outcomes.unfinished(before.worker_line(), "working", "j", ""), NOW))
|
||||
after = close.closed_cycle(main.LoopRun(cycle_number=1, root="/r", task="Do it.", unfinished_evidence=""), self.OPUS, run.Concluded(Unfinished("working", taken_in=TakenIn(highest_likelihood=4)), before), archive, opened, FakeEffects().effects())
|
||||
self.assertEqual(chunk_start.archived_route(archive, opened, FakeEffects().effects()), Route(Rung("claude-opus-5-5", "high"), 3, 3, 4))
|
||||
after = close.closed_cycle(main.LoopRun(cycle_number=1, root="/r", task="Do it.", unfinished_evidence=""), self.OPUS, run.Concluded(Unfinished("working", taken_in=TakenIn(highest_likelihood=4)), before), archive, a_loop(FakeEffects().effects(), session=opened))
|
||||
self.assertEqual(chunk_start.archived_route(archive, a_loop(FakeEffects().effects(), session=opened)), Route(Rung("claude-opus-5-5", "high"), 3, 3, 4))
|
||||
with contextlib.redirect_stderr(io.StringIO()):
|
||||
close.closed_cycle(after, self.OPUS, run.Concluded(Finished("done"), after.route), archive, opened, FakeEffects().effects())
|
||||
self.assertEqual(chunk_start.archived_route(archive, opened, FakeEffects().effects()), Route(Rung("claude-opus-5-5", "high"), 3, 3, 4))
|
||||
close.closed_cycle(after, self.OPUS, run.Concluded(Finished("done"), after.route), archive, a_loop(FakeEffects().effects(), session=opened))
|
||||
self.assertEqual(chunk_start.archived_route(archive, a_loop(FakeEffects().effects(), session=opened)), Route(Rung("claude-opus-5-5", "high"), 3, 3, 4))
|
||||
blocked = pathlib.Path(home, "blocked")
|
||||
blocked.write_text("")
|
||||
stop = close.closed_cycle(main.LoopRun(cycle_number=1, root="/r", task="Do it.", unfinished_evidence=""), self.OPUS, run.Concluded(Unfinished("working", taken_in=TakenIn(highest_likelihood=4)), before), blocked, opened, FakeEffects().effects())
|
||||
stop = close.closed_cycle(main.LoopRun(cycle_number=1, root="/r", task="Do it.", unfinished_evidence=""), self.OPUS, run.Concluded(Unfinished("working", taken_in=TakenIn(highest_likelihood=4)), before), blocked, a_loop(FakeEffects().effects(), session=opened))
|
||||
self.assertEqual((stop.code, stop.reason.split(":")[0]), (1, "could not archive the transcript"))
|
||||
|
||||
def test_names_no_step_up_where_only_the_count_of_unfinished_verdicts_changed(self):
|
||||
@@ -1264,8 +1276,8 @@ class Steps(unittest.TestCase):
|
||||
before = Route(self.OPUS, 3, 3, 4)
|
||||
with contextlib.redirect_stderr(io.StringIO()):
|
||||
self.assertIsNone(write.archive(archive, str(transcript), "Do it.", outcomes.unfinished(before.worker_line(), "working", "j", ""), NOW))
|
||||
close.closed_cycle(main.LoopRun(cycle_number=1, root="/r", task="Do it.", unfinished_evidence=""), self.OPUS, run.Concluded(Unfinished("working", taken_in=TakenIn(highest_escape_and_impact=6)), before), archive, opened, FakeEffects().effects())
|
||||
self.assertEqual(chunk_start.archived_route(archive, opened, FakeEffects().effects()), Route(self.OPUS, 3, 3, 4, escape_and_impact_taken_in=6))
|
||||
close.closed_cycle(main.LoopRun(cycle_number=1, root="/r", task="Do it.", unfinished_evidence=""), self.OPUS, run.Concluded(Unfinished("working", taken_in=TakenIn(highest_escape_and_impact=6)), before), archive, a_loop(FakeEffects().effects(), session=opened))
|
||||
self.assertEqual(chunk_start.archived_route(archive, a_loop(FakeEffects().effects(), session=opened)), Route(self.OPUS, 3, 3, 4, escape_and_impact_taken_in=6))
|
||||
|
||||
|
||||
class ChunkFacts(unittest.TestCase):
|
||||
@@ -1275,11 +1287,12 @@ class ChunkFacts(unittest.TestCase):
|
||||
self.assertEqual(running_loops.taken_items(Failure("no todo.md"), 3, ()), (Taken(3, ""),))
|
||||
self.assertEqual(running_loops.taken_items(TODO, 0, ()), ())
|
||||
|
||||
PREFLIGHT = pathlib.Path("/b/chunk-preflight")
|
||||
# The launcher beside which chunk_start finds /b/chunk-preflight.
|
||||
LAUNCHER = pathlib.Path("/b/loop-claude")
|
||||
|
||||
def test_runs_the_preflight_at_the_checkout_root_and_quotes_what_it_printed(self):
|
||||
fake = FakeEffects(python=[ran("- A fact.\n")])
|
||||
said = chunk_start.chunk_facts(self.PREFLIGHT, "/r", fake.effects())
|
||||
said = chunk_start.chunk_facts(a_loop(fake.effects(), launcher=self.LAUNCHER))
|
||||
self.assertEqual(fake.made("python"), [(["/b/chunk-preflight", "--worktree"], "/r")])
|
||||
self.assertIn("\n\n- A fact.", said)
|
||||
self.assertNotIn("yourself", said)
|
||||
@@ -1287,7 +1300,7 @@ class ChunkFacts(unittest.TestCase):
|
||||
def test_has_the_worker_find_the_facts_itself_where_the_preflight_failed(self):
|
||||
for failed, why in ((ran(code=1, stderr="git could not start\n"), "git could not start"), (ran(code=1), "exited 1")):
|
||||
with self.subTest(why=why):
|
||||
said = chunk_start.chunk_facts(self.PREFLIGHT, "/r", FakeEffects(python=[failed]).effects())
|
||||
said = chunk_start.chunk_facts(a_loop(FakeEffects(python=[failed]).effects(), launcher=self.LAUNCHER))
|
||||
self.assertIn("yourself", said)
|
||||
self.assertIn(why, said)
|
||||
|
||||
@@ -1295,13 +1308,13 @@ class ChunkFacts(unittest.TestCase):
|
||||
with tempfile.TemporaryDirectory() as home:
|
||||
opened = session.session_named("A proj loop-claude", pathlib.Path(home, "projects"))
|
||||
fresh = FakeEffects(python=[ran("- A fact.\n")])
|
||||
facts, _ = chunk_start.chunk_start(opened, self.PREFLIGHT, "/r", fresh.effects())
|
||||
facts, _ = chunk_start.chunk_start(a_loop(fresh.effects(), session=opened, launcher=self.LAUNCHER))
|
||||
self.assertEqual((fresh.made("python"), "- A fact." in facts), ([(["/b/chunk-preflight", "--worktree"], "/r")], True))
|
||||
transcript = pathlib.Path(home, "projects", "-fake", f"{opened.id}.jsonl")
|
||||
transcript.parent.mkdir(parents=True)
|
||||
transcript.write_text("")
|
||||
resumed = FakeEffects()
|
||||
facts, _ = chunk_start.chunk_start(opened, self.PREFLIGHT, "/r", resumed.effects())
|
||||
facts, _ = chunk_start.chunk_start(a_loop(resumed.effects(), session=opened, launcher=self.LAUNCHER))
|
||||
self.assertEqual((resumed.made("python"), facts), ([], ""))
|
||||
|
||||
|
||||
@@ -1753,7 +1766,7 @@ class LoopRuns(unittest.TestCase):
|
||||
launcher = pathlib.Path(root, "loop-claude")
|
||||
launcher.write_text("")
|
||||
fake = FakeEffects(python=[ran()])
|
||||
self.assertEqual(reload.exec_if_edited(launcher, "stale", main.LoopRun(cycle_number=1, root="/r", task="do it", unfinished_evidence=""), fake.effects()), Stop(1, "could not reload loop-claude: No such file or directory; rerun loop-claude <task>"))
|
||||
self.assertEqual(reload.exec_if_edited(a_loop(fake.effects(), launcher=launcher), "stale", main.LoopRun(cycle_number=1, root="/r", task="do it", unfinished_evidence="")), Stop(1, "could not reload loop-claude: No such file or directory; rerun loop-claude <task>"))
|
||||
|
||||
|
||||
class HelpLimits(unittest.TestCase):
|
||||
@@ -1799,7 +1812,7 @@ class ExitContract(unittest.TestCase):
|
||||
("loop/main.py", "loop_run_from", "0 if task else 1", "HELP", "no task is given"),
|
||||
("loop/main.py", "loop_run_from", "1", 'f"the edited loop-claude cannot read the state', "a reload cannot read the state the running script handed it"),
|
||||
("loop/reload.py", "exec_if_edited", "1", "f'could not reload loop-claude:", "python cannot start for a reload"),
|
||||
("loop/routing_check.py", "raise_calls", "1", "f\"could not start claude for the routing calls in {paths.config_clone}", "claude cannot start for an interrupt"),
|
||||
("loop/routing_check.py", "raise_calls", "1", "f\"could not start claude for the routing calls in {loop.paths.config_clone}", "claude cannot start for an interrupt"),
|
||||
("project/checkout.py", "checkout_root", "1", "found.reason", git),
|
||||
("project/model_choice.py", "get_or_ask_model", "1", "models.reason", models_),
|
||||
("project/model_choice.py", "get_or_ask_model", "1", "models.reason", models_),
|
||||
|
||||
@@ -9,7 +9,7 @@ import math
|
||||
import re
|
||||
import typing
|
||||
|
||||
from release_plan.todo_table import BLOCKED_BY, cells, CODE_HEALTH, DETAILS, HEADER_START, Item, item_details, items_table, MOVES, OLD_SHAPE, parse_row, renames, risk, Shape, SHAPE, shape_of, Table, table_rows
|
||||
from release_plan.todo_table import BLOCKED_BY, cells, CODE_HEALTH, DETAILS, Exempt, HEADER_START, Item, item_details, items_table, MOVES, OLD_SHAPE, parse_row, renames, risk, Shape, SHAPE, shape_of, Table, table_rows
|
||||
from release_plan.blockers import blocked_through, blockers_first
|
||||
from release_plan.formula import evaluate, parse_formula
|
||||
from failure import Failure
|
||||
@@ -29,7 +29,7 @@ VOID = re.compile(r"^\*\*Void:\*\* (.*)$", re.M)
|
||||
OPTED_OUT = re.compile(r"^## review opt-out:.*\bcomprehension check\b", re.M)
|
||||
WEIGHTS_HEADER = "| Goal | W |"
|
||||
# The Exempt reasons that rank ahead of the rest of their release, in this order: a question first, since its answer may change other items, then a security finding.
|
||||
FIRST = {"question": 0, "security": 1}
|
||||
FIRST: dict[Exempt, int] = {"question": 0, "security": 1}
|
||||
# How README.md marks a goal; None where it marks it neither way.
|
||||
Mark = typing.Literal["Maintain", "Achieve"] | None
|
||||
RESHAPE = f"todo.md's items table is in the old shape, scoring A and G against goal weights todo.md states. Until todo.md has the shape rank_todo.py --help shows, reshaping it is the project's only work, as ~/.claude/CLAUDE.md → 'Working loop' says: mark README.md's goals **Maintain:** or **Achieve:**, name each item's {MOVES}, score its L, E and I in place of C, and set the bar below the score of every item to keep"
|
||||
|
||||
@@ -13,7 +13,9 @@ LEVELS = {"L": 4, "E": 3, "I": 5}
|
||||
RISK_FLOOR = {4: 5, 5: 7}
|
||||
# The highest R an item may have and still share a chunk; `docs/decisions.md` → `chunks:` says why 5.
|
||||
BUNDLE_MAX_R = 5
|
||||
EXEMPTIONS = ("", "decision", "defect", "owner", "principle", "question", "security")
|
||||
# What an Exempt cell may hold: empty, or a reason ~/.claude/rules/todo-items.md defines.
|
||||
Exempt = typing.Literal["", "decision", "defect", "owner", "principle", "question", "security"]
|
||||
EXEMPTIONS: tuple[Exempt, ...] = typing.get_args(Exempt)
|
||||
# The column naming the items that block an item: each must be done before the item starts.
|
||||
BLOCKED_BY = "Blocked by"
|
||||
# The column naming each achieve goal an item moves and how far, such as `1.1 by 8, 1.2 by 5`.
|
||||
@@ -94,7 +96,7 @@ OLD_SHAPE = Shape(("R", "S", "C", "A", "G"), (BLOCKED_BY, "C", "Score"), (), (),
|
||||
class Item:
|
||||
id: int
|
||||
release: Release
|
||||
exempt: str
|
||||
exempt: Exempt
|
||||
tagline: str
|
||||
scores: dict[str, int]
|
||||
moves: Moves
|
||||
@@ -263,8 +265,9 @@ def parse_row(row: str, table: Table) -> Item | Failure:
|
||||
if isinstance(found, Failure):
|
||||
return found
|
||||
named = dict(zip(table.columns, found))
|
||||
if misformed := check_cells(row, named):
|
||||
return misformed
|
||||
exempt = check_cells(row, named)
|
||||
if isinstance(exempt, Failure):
|
||||
return exempt
|
||||
shape = shape_of(table.columns)
|
||||
scores = parse_scores(named["ID"], {name: cell for name, cell in named.items() if cell or name not in shape.derived}, shape.score_columns)
|
||||
if isinstance(scores, Failure):
|
||||
@@ -275,21 +278,25 @@ def parse_row(row: str, table: Table) -> Item | Failure:
|
||||
moves = shape.read_goals(named["ID"], named[shape.goals_column])
|
||||
if isinstance(moves, Failure):
|
||||
return moves
|
||||
return Item(int(named["ID"]), release_of(named["Release"]), named["Exempt"], named["Item"], scores, moves, blocked_by)
|
||||
return Item(int(named["ID"]), release_of(named["Release"]), exempt, named["Item"], scores, moves, blocked_by)
|
||||
|
||||
|
||||
def check_cells(row: str, named: dict[str, str]) -> Failure | None:
|
||||
"""Holds the row's ID, Release, Exempt and Item cells to the format: why one breaks it, None when none does."""
|
||||
def is_exempt(cell: str) -> typing.TypeGuard[Exempt]:
|
||||
return cell in EXEMPTIONS
|
||||
|
||||
|
||||
def check_cells(row: str, named: dict[str, str]) -> Exempt | Failure:
|
||||
"""Holds the row's ID, Release, Exempt and Item cells to the format: the row's Exempt cell, or why a cell breaks it."""
|
||||
id_, release, exempt, tagline = named["ID"], named["Release"], named["Exempt"], named["Item"]
|
||||
if not re.fullmatch(r"[0-9]+", id_) or int(id_) < 1:
|
||||
return Failure(f"the ID {id_!r} is not a positive whole number: {row}")
|
||||
if parsed(release) is None:
|
||||
return Failure(f"item {id_}'s release {release!r} is not a semver version")
|
||||
if exempt not in EXEMPTIONS:
|
||||
if not is_exempt(exempt):
|
||||
return Failure(f"item {id_}'s Exempt {exempt!r} is not empty or one of {', '.join(EXEMPTIONS[1:])}")
|
||||
if not re.fullmatch(r"\*\*[^*].*[^*]\*\*", tagline):
|
||||
return Failure(f"item {id_}'s Item cell is not one bold tagline: {tagline}")
|
||||
return None
|
||||
return exempt
|
||||
|
||||
|
||||
def parse_scores(id_: str, named: dict[str, str], names: tuple[str, ...]) -> dict[str, int] | Failure:
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import ast
|
||||
import importlib
|
||||
import importlib.util
|
||||
import pathlib
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from repo_checks import ROOT
|
||||
|
||||
TRIALS = ROOT / "reviewer-merge-trials"
|
||||
|
||||
|
||||
def bin_imports(source: str) -> list[tuple[str, str | None]]:
|
||||
"""Each module the source imports from bin/, with each name it takes from that module, or None for the module itself."""
|
||||
found: list[tuple[str, str | None]] = []
|
||||
for node in ast.walk(ast.parse(source)):
|
||||
if isinstance(node, ast.ImportFrom) and node.module and node.level == 0:
|
||||
found += [(node.module, alias.name) for alias in node.names]
|
||||
elif isinstance(node, ast.Import):
|
||||
found += [(alias.name, None) for alias in node.names]
|
||||
return [(module, name) for module, name in found if in_bin(module)]
|
||||
|
||||
|
||||
def in_bin(module: str) -> bool:
|
||||
top = ROOT / "bin" / module.split(".")[0]
|
||||
return top.is_dir() or top.with_suffix(".py").is_file()
|
||||
|
||||
|
||||
class TrialsImports(unittest.TestCase):
|
||||
"""docs/decisions.md says to rerun the trials' scripts when a new model joins the ladder or a reviewer changes, so a refactor of bin/ must not break what they import."""
|
||||
|
||||
def test_each_name_a_trials_script_imports_from_bin_exists(self):
|
||||
scripts = sorted(TRIALS.glob("*.py"))
|
||||
self.assertTrue(scripts)
|
||||
for script in scripts:
|
||||
for module, name in bin_imports(script.read_text(encoding="utf-8")):
|
||||
with self.subTest(script=script.name, module=module, name=name):
|
||||
imported = importlib.import_module(module)
|
||||
if name is not None:
|
||||
self.assertTrue(hasattr(imported, name) or importlib.util.find_spec(f"{module}.{name}"))
|
||||
|
||||
def test_an_import_of_a_bin_module_is_found_and_a_stdlib_one_is_not(self):
|
||||
self.assertEqual(bin_imports("import json\nfrom failure import Failure\nimport review_replay.main as rm\n"), [("failure", "Failure"), ("review_replay.main", None)])
|
||||
@@ -7,13 +7,14 @@ import resource
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import typing
|
||||
import unittest
|
||||
import unittest.mock
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from rule_hook.repeat_read import Asked, modified, read_breaches, result_lines
|
||||
from rule_hook.rules import blocks, Breach, check, command_breaches, file_breaches, overrides
|
||||
from rule_hook.rules import blocks, Breach, check, command_breaches, file_breaches, overrides, RuleName, RULES
|
||||
from rule_hook.main import breaches_of
|
||||
from rule_hook.call import Call, parsed_call
|
||||
from git_cli.git_command import commit_message, CommitCall, commits
|
||||
@@ -910,3 +911,8 @@ class TodoRankCheck(unittest.TestCase):
|
||||
reasons = self.details(self.changed_plan(self.other, self.STUB))
|
||||
self.assertTrue(reasons)
|
||||
self.assertNotIn("own script", " ".join(reasons))
|
||||
|
||||
|
||||
class RuleNames(unittest.TestCase):
|
||||
def test_every_rule_name_has_a_rule_and_every_rule_a_name(self):
|
||||
self.assertEqual(set(RULES), set(typing.get_args(RuleName)))
|
||||
|
||||
@@ -58,8 +58,8 @@ def interrupted(question: str, evidence: str, judge: str, escalation: str, worke
|
||||
return f"{INTERRUPTED}\n\n{question}\n\nEvidence:\n{quoted(evidence)}\n\n{escalated}{judge_lines(judge, judge_cost)}\n{WORKER}{worker}"
|
||||
|
||||
|
||||
def answered(question: str, sources: str, answer: str, evidence: str, escalation: str, judge: str, worker: WorkerLine, judge_cost: float = 0.0) -> str:
|
||||
"""escalation and worker are as on interrupted."""
|
||||
def answered(*, question: str, sources: str, answer: str, evidence: str, escalation: str, judge: str, worker: WorkerLine, judge_cost: float = 0.0) -> str:
|
||||
"""escalation and worker are as on interrupted. Every parameter is keyword-only, since a swap of two str ones would still type-check."""
|
||||
escalated = escalation_block(escalation)
|
||||
return f"{ANSWERED}\n\n{question}\n\n{sources} says:\n{quoted(answer)}\n\nEvidence:\n{quoted(evidence)}\n\n{escalated}{judge_lines(judge, judge_cost)}\n{WORKER}{worker}"
|
||||
|
||||
|
||||
@@ -72,9 +72,9 @@ class Outcomes(unittest.TestCase):
|
||||
self.assertEqual(outcomes.interrupted("q?", "e", "j", "", "w"), "Verdict: interrupt\n\nq?\n\nEvidence:\n> e\n\nJudge: j\nWorker: w")
|
||||
|
||||
def test_archives_the_escalation_and_the_worker_a_quoted_answer_names(self):
|
||||
self.assertEqual(outcomes.answered("q?", "AGENTS.md", "A.", "e", "round 2: 🔴", "j", "w"), "Verdict: quoted answer\n\nq?\n\nAGENTS.md says:\n> A.\n\nEvidence:\n> e\n\nEscalation:\n> round 2: 🔴\n\nJudge: j\nWorker: w")
|
||||
self.assertEqual(outcomes.answered("q?", "AGENTS.md", "A.", "e", "", "j", "w"), "Verdict: quoted answer\n\nq?\n\nAGENTS.md says:\n> A.\n\nEvidence:\n> e\n\nJudge: j\nWorker: w")
|
||||
self.assertEqual(outcomes.workers(f"{utc(NOW)} {outcomes.answered('q?', 'AGENTS.md', 'A.', 'e', '', 'j', 'w')}\n"), [(utc(NOW), "w")])
|
||||
self.assertEqual(outcomes.answered(question="q?", sources="AGENTS.md", answer="A.", evidence="e", escalation="round 2: 🔴", judge="j", worker="w"), "Verdict: quoted answer\n\nq?\n\nAGENTS.md says:\n> A.\n\nEvidence:\n> e\n\nEscalation:\n> round 2: 🔴\n\nJudge: j\nWorker: w")
|
||||
self.assertEqual(outcomes.answered(question="q?", sources="AGENTS.md", answer="A.", evidence="e", escalation="", judge="j", worker="w"), "Verdict: quoted answer\n\nq?\n\nAGENTS.md says:\n> A.\n\nEvidence:\n> e\n\nJudge: j\nWorker: w")
|
||||
self.assertEqual(outcomes.workers(f"{utc(NOW)} {outcomes.answered(question='q?', sources='AGENTS.md', answer='A.', evidence='e', escalation='', judge='j', worker='w')}\n"), [(utc(NOW), "w")])
|
||||
|
||||
def test_reads_no_worker_from_an_outcome_written_before_the_worker_line(self):
|
||||
kept = f"Task: Do it.\n\n{utc(NOW)} Stopped: Ctrl-C\n\n{utc(NOW)} Verdict: unfinished\n\nEvidence:\n> Worker: no\n"
|
||||
|
||||
@@ -47,6 +47,7 @@ h1, h2, h3 { font-family: var(--display); text-wrap: balance; margin: 0; line-he
|
||||
h1 { font-size: 3.4rem; font-weight: 800; letter-spacing: -0.02em; }
|
||||
h2 { font-size: 2rem; font-weight: 800; letter-spacing: -0.01em; }
|
||||
h3 { font-size: 1.15rem; font-weight: 600; }
|
||||
.intro3 h2 { font-size: 1.15rem; font-weight: 600; letter-spacing: normal; }
|
||||
p { margin: 0; max-width: 65ch; }
|
||||
.lead { font-size: 1.25rem; color: var(--muted); max-width: 52ch; }
|
||||
.eyebrow { font: 700 0.75rem/1 var(--body); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
|
||||
@@ -199,7 +200,7 @@ dl.gloss dt { font-weight: 700; } dl.gloss dd { margin: 0; color: var(--muted);
|
||||
<p class="lead">You write down what you want and who it is for. An AI plans the work, writes the code, gets it reviewed and merges it, one pull request at a time, for as long as the plan holds work.</p>
|
||||
<div class="intro3">
|
||||
<div class="col">
|
||||
<h3>The problem</h3>
|
||||
<h2>The problem</h2>
|
||||
<ul>
|
||||
<li><b>You babysit the agent.</b> Every few minutes it asks something, or waits for a yes.</li>
|
||||
<li><b>It forgets.</b> Long sessions drift, and you explain the same context again.</li>
|
||||
@@ -208,7 +209,7 @@ dl.gloss dt { font-weight: 700; } dl.gloss dd { margin: 0; color: var(--muted);
|
||||
</ul>
|
||||
</div>
|
||||
<div class="col">
|
||||
<h3>What loop-claude does</h3>
|
||||
<h2>What loop-claude does</h2>
|
||||
<ul>
|
||||
<li><b>It runs unattended.</b> A judge reads every run, and interrupts you only for a choice that is yours.</li>
|
||||
<li><b>It starts fresh every chunk.</b> The repo is the memory: goals, plan and decisions are written down.</li>
|
||||
@@ -217,7 +218,7 @@ dl.gloss dt { font-weight: 700; } dl.gloss dd { margin: 0; color: var(--muted);
|
||||
</ul>
|
||||
</div>
|
||||
<div class="col">
|
||||
<h3>What it aims for</h3>
|
||||
<h2>What it aims for</h2>
|
||||
<ul>
|
||||
<li><b>Maintainable for years.</b> Code that stays easy to read, change and debug, tomorrow and after seven years.</li>
|
||||
<li>The highest quality, with the fewest interruptions.</li>
|
||||
|
||||
@@ -172,7 +172,7 @@ Each match and new-finding count costs about $0.30 on Opus 5.5 at medium.
|
||||
|
||||
## How to rerun
|
||||
|
||||
Run every script from this folder, on the host's Python. They import review-replay from `~/code/claude-config/bin`; the trials ran against commit 82eb8ff, and candidate 4 against 0442074, where review-replay was unchanged.
|
||||
Run every script from this folder, on the host's Python. They import review-replay from this checkout's `bin/`, and `bin/repo_checks/test_trials_imports.py` checks that every name they import from it still exists; the trials ran against commit 82eb8ff, and candidate 4 against 0442074, where review-replay was unchanged.
|
||||
The scripts name the candidates `wave3` (candidate 1), `release` (candidate 2) and `pair` (candidate 4).
|
||||
|
||||
To replay on another model, change two places: `collect.py` keeps only projects on `claude-opus-5-5`, and `driver.py`'s `RUNG` is Opus 5.5 at medium.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Match each variant's replay reports to the archived findings, and list new findings. Usage: analyze.py <candidate> <variant>-<run>..."""
|
||||
import concurrent.futures, json, pathlib, pickle, re, sys
|
||||
sys.path.insert(0, str(pathlib.Path.home() / "code/claude-config/bin"))
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1] / "bin"))
|
||||
from claude_code.reply import claude_reply
|
||||
import driver as d
|
||||
from failure import Failure
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Pickle to runs.pkl one flat list of the archived reviewer runs of the projects on claude-opus-5-5, with or without findings, each with its round number from the prompt."""
|
||||
import json, pathlib, pickle, re, sys
|
||||
sys.path.insert(0, str(pathlib.Path.home() / "code/claude-config/bin"))
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1] / "bin"))
|
||||
from claude_code.entries import AssistantTurn, parse_entry, Text, UserText
|
||||
from transcript_archive.project_key import checkout_of
|
||||
from failure import Failure
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import collections, glob, json, pathlib, re, sys
|
||||
sys.path.insert(0, str(pathlib.Path.home() / "code/claude-config/bin"))
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1] / "bin"))
|
||||
from review_replay.rounds import recorded_findings
|
||||
cand=sys.argv[1]
|
||||
for vr in sys.argv[2:]:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Replay archived review rounds separately or merged, and save each replay's reply, reports and cost; analyze.py matches them. Usage: driver.py <candidate> <sep|merged> <run> [case ids...]"""
|
||||
import concurrent.futures, json, os, pathlib, pickle, re, shutil, sys, tempfile
|
||||
sys.path.insert(0, str(pathlib.Path.home() / "code/claude-config/bin"))
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1] / "bin"))
|
||||
from claude_code.reply import claude_reply, Limited
|
||||
from review_replay.main import clone_reviewed, Copies, copy_reports, match, redirected
|
||||
from failure import Failure
|
||||
|
||||
Reference in New Issue
Block a user