From 885bf37891c4f944a1aa6450655452e8290b03d4 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 18 Nov 2026 17:07:03 +0100 Subject: [PATCH] =?UTF-8?q?Answer=20stability=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=206=20=F0=9F=9F=A1=20(0=20misread);=20pin=20the?= =?UTF-8?q?=20answer=20destinations=20in=20the=20prompts,=20name=20Brief's?= =?UTF-8?q?=20fields,=20drop=20the=20duplicate=20import=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/agent_cycle/__init__.py | 2 +- bin/agent_cycle/run.py | 10 +++++++++- bin/agent_cycle/test_agent_cycle.py | 21 --------------------- bin/judge_replay/main.py | 2 +- bin/judge_replay/test_judge_replay.py | 1 + bin/loop_claude/__init__.py | 2 +- bin/loop_claude/loop/usage.py | 10 +++++----- bin/loop_claude/test_loop_claude.py | 10 ++++++++++ 8 files changed, 28 insertions(+), 30 deletions(-) delete mode 100644 bin/agent_cycle/test_agent_cycle.py diff --git a/bin/agent_cycle/__init__.py b/bin/agent_cycle/__init__.py index 8aa43b57..87650737 100644 --- a/bin/agent_cycle/__init__.py +++ b/bin/agent_cycle/__init__.py @@ -1,4 +1,4 @@ """One cycle of a headless claude worker and the judge of its transcript, for every entry point that drives such cycles: loop-claude today, do-epic next (docs/decisions.md → `do-epic: drives one Jira epic …`). -run.py runs a cycle through the states in states.py: worker.py runs the worker, judge.py rules on its transcript, interrupt.py puts a question to the human in the tmux window tmux.py names, and routing.py picks the rung the worker runs on next. An entry point hands the cycle what is its own: its prompts and file names (worker_prompts.py) and how it reads the plan items a worker took in (run.py's Cycle.taken_in). No module here imports an entry point's package, which test_agent_cycle.py checks. A reader finds a module by its name, so the modules stay at one level. docs/decisions.md → `principles: about seven things per level, …` allows that. +run.py runs a cycle through the states in states.py: worker.py runs the worker, judge.py rules on its transcript, interrupt.py puts a question to the human in the tmux window tmux.py names, and routing.py picks the rung the worker runs on next. An entry point hands the cycle what is its own: its prompts and file names (worker_prompts.py) and how it reads the plan items a worker took in (run.py's Cycle.taken_in). No module here imports an entry point's package: loop_claude imports this one, so bin/repo_checks/test_package_cycles.py fails on such an import. A reader finds a module by its name, so the modules stay at one level. docs/decisions.md → `principles: about seven things per level, …` allows that. """ diff --git a/bin/agent_cycle/run.py b/bin/agent_cycle/run.py index b934c85f..6e09465f 100644 --- a/bin/agent_cycle/run.py +++ b/bin/agent_cycle/run.py @@ -152,7 +152,15 @@ def rule(cycle: Cycle, transcript_path: str, quoted_answers: int) -> Ruled | Sto entries = read_transcript(transcript_path) if isinstance(entries, Failure): return Stop(1, entries.reason) - verdict = judge(cycle.root, Brief(cycle.task, cycle.premises, cycle.records, cycle.prompts.answer_destinations, entries, cycle.route.escalated_at), cycle.judge, cycle.effects, lambda rejected: keep_rejection(cycle, transcript_path, rejected)) + brief = Brief( + task=cycle.task, + premises=cycle.premises, + records=cycle.records, + answer_destinations=cycle.prompts.answer_destinations, + entries=entries, + escalated_at=cycle.route.escalated_at, + ) + verdict = judge(cycle.root, brief, cycle.judge, cycle.effects, lambda rejected: keep_rejection(cycle, transcript_path, rejected)) if isinstance(verdict, Stop): return verdict if not isinstance(verdict, Finished): diff --git a/bin/agent_cycle/test_agent_cycle.py b/bin/agent_cycle/test_agent_cycle.py deleted file mode 100644 index 72d9a9ef..00000000 --- a/bin/agent_cycle/test_agent_cycle.py +++ /dev/null @@ -1,21 +0,0 @@ -import ast -import pathlib -import unittest - -PACKAGE = pathlib.Path(__file__).resolve().parent -# The packages of the entry points that drive a cycle. -ENTRY_POINTS = ("loop_claude", "do_epic") - - -class Imports(unittest.TestCase): - def test_no_module_imports_an_entry_points_package_so_a_second_entry_point_drives_the_cycle_alone(self): - imported = [] - for path in sorted(PACKAGE.glob("*.py")): - for node in ast.walk(ast.parse(path.read_text())): - names = [node.module or ""] if isinstance(node, ast.ImportFrom) else [alias.name for alias in node.names] if isinstance(node, ast.Import) else [] - imported += [(path.name, name) for name in names if name.split(".")[0] in ENTRY_POINTS] - self.assertEqual(imported, []) - - -if __name__ == "__main__": - unittest.main() diff --git a/bin/judge_replay/main.py b/bin/judge_replay/main.py index 0ab247d0..d6cfdefa 100644 --- a/bin/judge_replay/main.py +++ b/bin/judge_replay/main.py @@ -172,5 +172,5 @@ def rule(case: Case, rung: Rung, home: pathlib.Path, effects: Effects) -> Kind | if isinstance(records, Failure): return verdict_kind(records) # 0 for the route's mark, as before any step-up: the replay compares verdict kinds, and a mark changes only which escalation quotes count. - verdict = first_reply(lambda: judge_once(case.root, Brief(case.task, premises, records, ANSWER_DESTINATIONS, entries, 0), rung, effects)) + verdict = first_reply(lambda: judge_once(case.root, Brief(task=case.task, premises=premises, records=records, answer_destinations=ANSWER_DESTINATIONS, entries=entries, escalated_at=0), rung, effects)) return verdict if isinstance(verdict, Limited) else verdict_kind(verdict) diff --git a/bin/judge_replay/test_judge_replay.py b/bin/judge_replay/test_judge_replay.py index 39942f5f..acc9619f 100644 --- a/bin/judge_replay/test_judge_replay.py +++ b/bin/judge_replay/test_judge_replay.py @@ -159,6 +159,7 @@ class Main(unittest.TestCase): code, out, err = self.run_main(["claude-opus-5-5"], reply) self.assertEqual(code, 0, err) + self.assertEqual([prompt for prompt in self.prompts if f"writing it into {ANSWER_DESTINATIONS}," not in prompt], []) self.assertEqual({cwd for _, _, cwd in self.calls}, {str(self.home / "code" / "proj")}) self.assertEqual([(model, effort) for model, effort, _ in self.calls[::2]], [ ("claude-opus-5-5", "xhigh"), diff --git a/bin/loop_claude/__init__.py b/bin/loop_claude/__init__.py index cb30fdb3..64f69ecb 100644 --- a/bin/loop_claude/__init__.py +++ b/bin/loop_claude/__init__.py @@ -1,4 +1,4 @@ """loop-claude: headless claude cycles, judged, that interrupt the human only for a decision that is theirs (loop/usage.py's help). -Its packages hold one concern each: cycle/ words the worker's prompts and reads the items it names, loop/ runs the cycles, and project/ reads a checkout's files. The cycle itself, its judge, interrupts and routing live in bin/agent_cycle/, which other entry points drive too. Its paths live in bin/loop_state/, and its effects in bin/loop_effects/. Each module at this level is imported by more than one package, or by a module at this level that is. A reader finds a module by its name, so the modules stay at one level. docs/decisions.md → `principles: about seven things per level, …` allows that. +Its packages hold one concern each: cycle/ words the worker's prompts and reads the items it names, loop/ runs the cycles, and project/ reads a checkout's files. loop-claude's paths live in bin/loop_state/, and its effects in bin/loop_effects/. The cycle itself, its judge, interrupts and routing live in bin/agent_cycle/, which doesn't import this package, so that a second entry point can drive it. routed_item.py, at this level, reads the plan for the item a chunk starts on. """ diff --git a/bin/loop_claude/loop/usage.py b/bin/loop_claude/loop/usage.py index 42f04298..bac28074 100644 --- a/bin/loop_claude/loop/usage.py +++ b/bin/loop_claude/loop/usage.py @@ -103,11 +103,11 @@ worker names on its `Chunk items:` line an item that picks a higher rung, or whe in the transcript an escalation trigger that fired and the worker asked for a higher rung. The rules are in bin/agent_cycle/routing.py and bin/model_routing/ladder.py, the choice of each review's rung in bin/model_routing/review_choice.py, and the prompts' wording in -bin/loop_claude/cycle/prompts.py. Each verdict, interrupt, quoted answer, stop and -step-up in the archive ends with a Worker: line, the route as JSON (Route.worker_line in -bin/model_routing/route.py); a rerun resumes an open chunk on the latest route named there. A -plan or an archive that cannot be read or parsed is said on stderr, and the chunk is routed -without it. +bin/loop_claude/cycle/prompts.py and bin/agent_cycle/worker_prompts.py. Each verdict, interrupt, +quoted answer, stop and step-up in the archive ends with a Worker: line, the route as JSON +(Route.worker_line in bin/model_routing/route.py); a rerun resumes an open chunk on the latest +route named there. A plan or an archive that cannot be read or parsed is said on stderr, and the +chunk is routed without it. The ladder is a JSON file, each rung a model's full name and an effort of low, medium, high, xhigh or max: diff --git a/bin/loop_claude/test_loop_claude.py b/bin/loop_claude/test_loop_claude.py index aaad11b6..873ae18d 100644 --- a/bin/loop_claude/test_loop_claude.py +++ b/bin/loop_claude/test_loop_claude.py @@ -543,6 +543,7 @@ Spent since 2026-09-21T14:13:20Z, in tokens of input, cache write 5m, cache writ self.assertNotIn("the second", judge_prompts[0]) self.assertIn("[human] the second", judge_prompts[1]) self.assertIn("From the goals file, ## Goals", judge_prompts[0]) + self.assertIn(f"writing it into {prompts.ANSWER_DESTINATIONS},", judge_prompts[0]) self.assertIn("The task the worker was given:\nDo it.", judge_prompts[0]) def test_a_question_the_records_answer_resumes_the_worker_with_the_answer_three_times_a_cycle(self): @@ -1934,6 +1935,15 @@ class JudgePrompt(unittest.TestCase): prompt, _ = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(assistant({"type": "text", "text": "done"})), 1)) self.assertNotRegex(prompt + json.dumps(judge.JUDGE_SCHEMA), r"\b[Aa]gent") + def test_the_judge_prompt_names_the_entry_points_answer_destinations_in_both_rules_on_a_recorded_answer(self): + prompt, _ = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", "the ledger", kinds(assistant({"type": "text", "text": "done"})), 0)) + self.assertIn("is recorded in the ledger at the one place it governs", prompt) + self.assertIn("the worker writing it into the ledger, but not into one of the human's rules", prompt) + + def test_the_typed_answers_prompt_names_the_entry_points_answer_destinations(self): + ledger = dataclasses.replace(prompts.WORKER, answer_destinations="the ledger") + self.assertIn("is recorded in the ledger at the one place it governs.", ledger.typed("Which one?", "Use B.", Route(Rung("worker-model")), None, False)) + def test_the_judge_prompt_names_every_rule_the_judge_reads_from_the_human(self): self.assertEqual([name for name in records.HUMAN_RULE_NAMES if name not in judge.judge_rules(prompts.ANSWER_DESTINATIONS)], [])