Make the judge's prompt readable on its own, ask once before the full scan, and sort imports by their first binding

This commit is contained in:
2026-10-03 16:02:02 +02:00
parent e9365c26fc
commit ce1ee9b6d2
19 changed files with 81 additions and 62 deletions
+2 -2
View File
@@ -3,11 +3,11 @@ import os
import pathlib
import sys
from loop_claude.claude_code.session import session_files
from loop_claude.claude_code.transcript import first_timestamped_line
from loop_claude.failure import Failure
from loop_claude.claude_code.transcript import first_timestamped_line
from loop_claude.file_writes import make_private, replace_file
from loop_claude.paths import Paths
from loop_claude.claude_code.session import session_files
def archive(project_key: str, path: str, task: str, outcome: str, paths: Paths) -> Failure | None:
+3 -3
View File
@@ -1,13 +1,13 @@
import sys
import uuid
from loop_claude.claude_code.transcript import human_turns, read_transcript
from loop_claude.claude_code.trust import trust
from loop_claude.effects import Effects
from loop_claude.failure import Failure
from loop_claude.claude_code.transcript import human_turns, read_transcript
from loop_claude.stop import needs_human, needs_terminal, Stop
from loop_claude.paths import Paths
from loop_claude.claude_code.trust import trust
from loop_claude.project.checkout import worktrees
from loop_claude.stop import Stop, needs_human, needs_terminal
ANSWER_QUESTION = "answer the question above"
+8 -6
View File
@@ -3,12 +3,12 @@ import json
import re
import typing
from loop_claude.effects import Effects
from loop_claude.failure import Failure
from loop_claude.cycle.verdicts import Finished, Interrupt, QuotedAnswer, Unfinished, Verdict
from loop_claude.claude_code.entries import hit_limit, limit_said, parse_entry, structured_output
from loop_claude.cycle.limited import Limited
from loop_claude.cycle.retry import retried
from loop_claude.cycle.verdicts import Finished, Interrupt, QuotedAnswer, Unfinished, Verdict
from loop_claude.effects import Effects
from loop_claude.failure import Failure
from loop_claude.stop import Stop
# At 3 to 4 characters a token, 100,000 to 133,000 tokens, which leaves a 200,000-token context room for the reply; the largest session rendered here was 364,000 characters on 2026-10-03.
@@ -21,9 +21,9 @@ JUDGE_RULES = (
"- it carried on under an assumption that decides the deliverable, that the human could "
"reasonably reject and that neither README.md nor the project's records settle; a caveat about "
"transient state it then handled is not one\n"
"- it is blocked on something only the human can supply: a credential, a version bump, a release "
"ready to cut, a choice outside the repo\n"
"- it flags that the goals, the plan or the task itself is unclear, missing or in need of change\n"
"- it is blocked on something only the human can supply: a credential, a version bump, the go-ahead "
"to publish a release, a choice outside the repo\n"
"- it flags that the goals, the plan in todo.md or the task itself is unclear, missing or in need of change\n"
"- it chose between alternatives that neither README.md nor the project's records discriminate "
"between - neither rules the rejected one out - and the choice materially changes the deliverable\n"
"interrupt=false otherwise. Bookkeeping the agent settled silently - what to document, wording, "
@@ -36,6 +36,7 @@ JUDGE_RULES = (
"Where README.md or the project's records answer the agent's own question and no [loop] line has "
"quoted that answer yet, set interrupt=false, put that question in question and quote the passage that answers it in answer, verbatim; the agent is "
"then given that passage in place of the human's reply.\n"
"The chunk is the one piece of work the task asks for, shipped as one pull request. "
"finished=true when the chunk is complete: merged, or nothing remains that the agent could do on "
"its own. finished=false when work remains that a further run can continue: an open PR, a review "
"not yet run, CI not yet reported."
@@ -60,6 +61,7 @@ JUDGE_SCHEMA = {
def judge(root: str, task: str, premises: str, records: str, rendered_transcript: str, model: str, effects: Effects) -> Verdict | Stop:
# --json-schema has claude check its reply against the schema and return it as the json result's structured_output.
# No tools, so the verdict rests on the transcript grounded() checks it against; no persistence, so its runs stay out of the session picker.
args = [
"-p",
+1 -1
View File
@@ -1,9 +1,9 @@
import sys
import typing
from loop_claude.cycle.limited import Limited
from loop_claude.effects import Effects
from loop_claude.failure import Failure
from loop_claude.cycle.limited import Limited
from loop_claude.stop import Stop
T = typing.TypeVar("T")
+9 -9
View File
@@ -1,20 +1,20 @@
import dataclasses
import typing
from loop_claude.claude_code.session import Session, delete_session, session_open, transcript_file
from loop_claude.claude_code.transcript import read_transcript, render
from loop_claude.cycle.states import Active, Archived, Closing, Ended, Event, HumanAnswered, Interrupting, Judging, Ruled, State, transition, WorkerRan, Working
from loop_claude.cycle.archive import archive
from loop_claude.cycle.interrupt import interrupt
from loop_claude.cycle.judge import judge
from loop_claude.cycle.retry import retried
from loop_claude.cycle.states import Active, Archived, Closing, Ended, Event, HumanAnswered, Interrupting, Judging, Ruled, State, WorkerRan, Working, transition
from loop_claude.cycle.verdicts import Finished, QuotedAnswer, Unfinished
from loop_claude.cycle.worker import run_worker, worker_args
from loop_claude.claude_code.session import delete_session, Session, session_open, transcript_file
from loop_claude.effects import Effects
from loop_claude.failure import Failure
from loop_claude.paths import Paths
from loop_claude.cycle.verdicts import Finished, QuotedAnswer, Unfinished
from loop_claude.cycle.interrupt import interrupt
from loop_claude.cycle.judge import judge
from loop_claude.project.model_choice import Models
from loop_claude.paths import Paths
from loop_claude.project.records import QUOTE_SOURCES
from loop_claude.claude_code.transcript import read_transcript, render
from loop_claude.cycle.retry import retried
from loop_claude.cycle.worker import run_worker, worker_args
from loop_claude.stop import Stop
+5 -4
View File
@@ -1,11 +1,11 @@
from loop_claude.claude_code.entries import assistant_parts, ends_stream, hit_limit, limit_said, parse_entry, rejected_until
from loop_claude.claude_code.session import Session
from loop_claude.claude_code.transcript import part_line
from loop_claude.cycle.limited import Limited
from loop_claude.cycle.verdicts import QuotedAnswer
from loop_claude.effects import Effects
from loop_claude.failure import Failure
from loop_claude.cycle.limited import Limited
from loop_claude.claude_code.transcript import part_line
from loop_claude.project.records import QUOTE_SOURCES
from loop_claude.cycle.verdicts import QuotedAnswer
from loop_claude.claude_code.session import Session
PRINTED_TOOL_INPUT = 160
@@ -46,6 +46,7 @@ def worker_args(task: str, session: Session, model: str, resuming: bool, answere
start = ["-p", "Continue the task; the previous run stopped before it was finished.", "--resume", str(session.id)]
else:
start = ["-p", f"{task}\n\nContinue any open draft PR or worktree for the chunk before creating a new one.", "--name", session.name, "--session-id", str(session.id)]
# --session-id starts a session under the id loop-claude keeps, which --resume continues; -p needs --verbose for stream-json, one JSON event a line, the last a result event.
return [
*start,
"--output-format", "stream-json",
+5 -5
View File
@@ -71,15 +71,15 @@ import pathlib
import sys
import typing
from loop_claude.claude_code.session import session_for
from loop_claude.cycle.run import Cycle, run_cycle
from loop_claude.effects import Effects
from loop_claude.loop.reload import RELOAD_FLAG, LoopRun, decode_handed, exec_if_edited, fingerprint
from loop_claude.paths import Paths
from loop_claude.project.checkout import checkout_root, project_key
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 loop_claude.effects import Effects
from loop_claude.project.model_choice import get_or_ask_models
from loop_claude.paths import Paths
from loop_claude.project.premises import read_premises
from loop_claude.project.records import read_records
from loop_claude.claude_code.session import session_for
from loop_claude.stop import Stop
+2 -2
View File
@@ -7,9 +7,9 @@ import typing
from loop_claude.claude_code.model_catalog import catalog_models
from loop_claude.effects import Effects
from loop_claude.failure import Failure
from loop_claude.file_writes import replace_json
from loop_claude.stop import needs_human, needs_terminal, Stop
from loop_claude.paths import Paths
from loop_claude.stop import Stop, needs_human, needs_terminal
from loop_claude.file_writes import replace_json
@dataclasses.dataclass(frozen=True)
+1 -1
View File
@@ -1,5 +1,5 @@
from loop_claude.markdown_sections import sections
from loop_claude.project.checkout import read_checkout_file
from loop_claude.markdown_sections import sections
from loop_claude.stop import Stop
+1 -1
View File
@@ -59,8 +59,8 @@ import sys
# Kept inside loop_claude/ so reload's fingerprint covers them.
from loop_claude.failure import Failure
from loop_claude.file_writes import replace_file
from loop_claude.markdown_sections import FENCE, sections
from loop_claude.file_writes import replace_file
EXEMPTIONS = ("", "decision", "defect", "principle", "question", "security")
ITEMS_HEADER = "| ID | Release | Exempt | Item | R | S | A | G | Goals | Score |"
+29
View File
@@ -0,0 +1,29 @@
import ast
import subprocess
import unittest
from test_python_floor import ROOT
def bound(node: ast.Import | ast.ImportFrom) -> list[str]:
return [alias.asname or alias.name for alias in node.names]
def unsorted_imports(source: str) -> list[int]:
"""The lines of the imports that list their names out of order, or sort before the import on the line above."""
imports = [node for node in ast.parse(source).body if isinstance(node, ast.Import | ast.ImportFrom)]
names_out = [node.lineno for node in imports if bound(node) != sorted(bound(node), key=str.casefold)]
lines_out = [node.lineno for above, node in zip(imports, imports[1:]) if node.lineno == above.end_lineno + 1 and bound(node)[0].casefold() < bound(above)[0].casefold()]
return sorted(set(names_out + lines_out))
class ImportOrder(unittest.TestCase):
def test_each_python_file_sorts_its_imports_by_their_first_binding(self):
listed = subprocess.run(["git", "ls-files", "*.py", "bin/loop-claude"], capture_output=True, check=True, cwd=ROOT, text=True).stdout.split()
self.assertIn("bin/loop-claude", listed)
for name in listed:
with self.subTest(name):
self.assertEqual(unsorted_imports((ROOT / name).read_text(encoding="utf-8")), [])
def test_a_case_insensitive_name_out_of_order_is_found(self):
self.assertEqual(unsorted_imports("import B\nimport a\n\nfrom x import C, b\n"), [2, 4])
+7 -7
View File
@@ -16,15 +16,15 @@ import uuid
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
from loop_claude import file_writes, markdown_sections, paths
from loop_claude.claude_code import entries, session, transcript, trust
from loop_claude.cycle import archive, interrupt, judge, retry, run, states, worker
from loop_claude.cycle.limited import Limited
from loop_claude.cycle.verdicts import Finished, Interrupt, QuotedAnswer, Unfinished
from loop_claude.effects import Effects
from loop_claude.failure import Failure
from loop_claude.loop import main, reload
from loop_claude.project import checkout, model_choice, records
from loop_claude.effects import Effects
from loop_claude.claude_code import entries, session, transcript, trust
from loop_claude.failure import Failure
from loop_claude import file_writes, markdown_sections, paths
from loop_claude.cycle.verdicts import Finished, Interrupt, QuotedAnswer, Unfinished
from loop_claude.cycle.limited import Limited
from loop_claude.loop import main, reload
from loop_claude.stop import Stop
CWD = pathlib.Path("/c")
+1 -1
View File
@@ -7,8 +7,8 @@ import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
import rank_todo
from loop_claude.failure import Failure
import rank_todo
from test_python_floor import ROOT
README = "# P\n\n## Goals\n\n1. Fast.\n2. Correct.\n 1. Tested.\n\n## Audience\n\nMe.\n"
+1 -1
View File
@@ -9,8 +9,8 @@ import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
import statusline
from statusline import CYAN, DIM, GREEN, RED, RESET, YELLOW
import statusline
NOW = datetime.datetime(2026, 10, 2, 12, 0, tzinfo=datetime.timezone.utc)
EPOCH = int(NOW.timestamp())
+1 -1
View File
@@ -2,7 +2,7 @@ import shutil
import subprocess
import unittest
from test_python_floor import ROOT, readme_floor
from test_python_floor import readme_floor, ROOT
class Types(unittest.TestCase):