Answer principles round 1: 0 🔴, 2 🟡 (0 misread); move say beside Effects and drop a clock comparison from the black-box test

This commit is contained in:
2026-10-28 18:40:24 +01:00
parent 4d40cc81bc
commit 6e171fe2c0
12 changed files with 24 additions and 37 deletions
+2 -3
View File
@@ -2,13 +2,12 @@ import dataclasses
import sys import sys
import uuid import uuid
from loop_claude.effects import Effects from loop_claude.effects import Effects, say
from failure import Failure from failure import Failure
from claude_code.transcript import human_turns, read_transcript from claude_code.transcript import human_turns, read_transcript
from loop_claude.stop import needs_human, needs_terminal, Stop from loop_claude.stop import needs_human, needs_terminal, Stop
from loop_claude.paths import Paths from loop_claude.paths import Paths
from model_routing.ladder import Rung from model_routing.ladder import Rung
from loop_claude.terminal import say
from claude_code.trust import trust from claude_code.trust import trust
from loop_claude.project.checkout import worktrees from loop_claude.project.checkout import worktrees
@@ -35,7 +34,7 @@ def put_question(question: str, answer_here: bool, effects: Effects) -> str | Ta
try: try:
answer = effects.input(ASK_ANSWER).strip() answer = effects.input(ASK_ANSWER).strip()
except EOFError: except EOFError:
print(file=sys.stderr) print(file=sys.stderr) # Ends the prompt's line; it says nothing, so it gets no time.
return needs_human(ANSWER_QUESTION, "the input ended") return needs_human(ANSWER_QUESTION, "the input ended")
if not answer: if not answer:
return needs_human(ANSWER_QUESTION, "nothing was typed") return needs_human(ANSWER_QUESTION, "nothing was typed")
+1 -2
View File
@@ -1,9 +1,8 @@
import typing import typing
from loop_claude.effects import Effects from loop_claude.effects import Effects, say
from failure import Failure from failure import Failure
from claude_code.reply import Limited from claude_code.reply import Limited
from loop_claude.terminal import say
from loop_claude.stop import Stop from loop_claude.stop import Stop
T = typing.TypeVar("T") T = typing.TypeVar("T")
+1 -2
View File
@@ -7,7 +7,7 @@ from loop_claude.routing import after_ruling, judge_rung
from transcript_archive.write import archive from transcript_archive.write import archive
from loop_claude.cycle.worker import AUTO_COMPACT_WINDOW, COMPACT_WINDOW, run_worker, worker_args from loop_claude.cycle.worker import AUTO_COMPACT_WINDOW, COMPACT_WINDOW, run_worker, worker_args
from claude_code.session import delete_session, Session, session_open, transcript_file from claude_code.session import delete_session, Session, session_open, transcript_file
from loop_claude.effects import Effects from loop_claude.effects import Effects, say
from failure import Failure from failure import Failure
from loop_claude.verdicts import Finished, Interrupt, QuotedAnswer, Unfinished, Verdict from loop_claude.verdicts import Finished, Interrupt, QuotedAnswer, Unfinished, Verdict
from loop_claude.cycle.judge import judge, Rejected from loop_claude.cycle.judge import judge, Rejected
@@ -19,7 +19,6 @@ from claude_code.transcript import read_transcript
from loop_claude.cycle.retry import retried from loop_claude.cycle.retry import retried
from model_routing.route import Route from model_routing.route import Route
from model_routing.ladder import Rung from model_routing.ladder import Rung
from loop_claude.terminal import say
from loop_claude.escalation_mark import StepUp from loop_claude.escalation_mark import StepUp
from loop_claude.stop import Stop from loop_claude.stop import Stop
from model_routing import worker_rungs from model_routing import worker_rungs
+1 -2
View File
@@ -1,11 +1,10 @@
from claude_code.entries import assistant_parts, ends_stream, hit_limit, limit_said, parse_entry, rejected_until from claude_code.entries import assistant_parts, ends_stream, hit_limit, limit_said, parse_entry, rejected_until
from loop_claude.effects import Effects from loop_claude.effects import Effects, say
from failure import Failure from failure import Failure
from claude_code.reply import Limited from claude_code.reply import Limited
from claude_code.transcript import part_line from claude_code.transcript import part_line
from machine_load.memory import ROOM_SHARE from machine_load.memory import ROOM_SHARE
from model_routing.ladder import Rung from model_routing.ladder import Rung
from loop_claude.terminal import say
from claude_code.session import Session from claude_code.session import Session
PRINTED_TOOL_INPUT = 160 PRINTED_TOOL_INPUT = 160
+8 -1
View File
@@ -37,7 +37,7 @@ class Effects:
execv: typing.Callable[[str, list[str]], None] execv: typing.Callable[[str, list[str]], None]
git: Git git: Git
input: typing.Callable[[str], str] input: typing.Callable[[str], str]
# A time of day in the machine's zone, as `2026-10-28 11:46:01`. # A time of day in the machine's zone, as `2026-10-28 11:46:01`. The spelling, and local time over UTC, is lilleman's call of 2026-10-28.
local_time: typing.Callable[[float], str] local_time: typing.Callable[[float], str]
# The machine's memory; None where it cannot be read. # The machine's memory; None where it cannot be read.
memory: typing.Callable[[], Memory | None] memory: typing.Callable[[], Memory | None]
@@ -88,3 +88,10 @@ def run_python(args: list[str], cwd: str, timeout: float) -> subprocess.Complete
return subprocess.CompletedProcess(command, 1, "", f"could not start: {failure}") return subprocess.CompletedProcess(command, 1, "", f"could not start: {failure}")
except subprocess.TimeoutExpired: except subprocess.TimeoutExpired:
return subprocess.CompletedProcess(command, 1, "", f"stopped after {timeout} s") return subprocess.CompletedProcess(command, 1, "", f"stopped after {timeout} s")
def say(text: str, effects: Effects, *, stdout: bool = False) -> None:
"""Prints text on stderr, or on stdout where stdout, opening its first line with the machine's local time, so the human sees when it happened. Blank lines before the text stay blank, and only its first line gets the time."""
body = text.lstrip("\n")
blanks = text[: len(text) - len(body)]
print(f"{blanks}{effects.local_time(effects.now())} {body}", file=sys.stdout if stdout else sys.stderr, flush=True)
+1 -2
View File
@@ -128,7 +128,7 @@ from loop_claude.project.checkout import checkout_root
from loop_claude.loop.reload import decode_handed, exec_if_edited, fingerprint, LoopRun, RELOAD_FLAG from loop_claude.loop.reload import decode_handed, exec_if_edited, fingerprint, LoopRun, RELOAD_FLAG
from chunk_pick import default_plan, DefaultPlan from chunk_pick import default_plan, DefaultPlan
from git_repo import default_ref from git_repo import default_ref
from loop_claude.effects import Effects from loop_claude.effects import Effects, say
from failure import Failure from failure import Failure
from loop_claude.verdicts import Finished, Unfinished from loop_claude.verdicts import Finished, Unfinished
from loop_claude.project.model_choice import get_or_ask_models from loop_claude.project.model_choice import get_or_ask_models
@@ -143,7 +143,6 @@ from loop_claude.cycle import prompts
from loop_claude.project.premises import read_premises from loop_claude.project.premises import read_premises
from loop_claude.project.records import read_records from loop_claude.project.records import read_records
from model_routing.route import Route, route_from from model_routing.route import Route, route_from
from loop_claude.terminal import say
from claude_code.session import Session, session_named, session_open, transcript_file from claude_code.session import Session, session_named, session_open, transcript_file
# 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. # 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.
+1 -2
View File
@@ -6,9 +6,8 @@ import sys
import types import types
import typing import typing
from loop_claude.effects import Effects from loop_claude.effects import Effects, say
from model_routing.route import Route from model_routing.route import Route
from loop_claude.terminal import say
from loop_claude.stop import Stop from loop_claude.stop import Stop
RELOAD_FLAG = "--reloaded" RELOAD_FLAG = "--reloaded"
+1 -2
View File
@@ -3,12 +3,11 @@ import pathlib
from routing_figures import archive from routing_figures import archive
from routing_figures.measure import calls, due, render, totals from routing_figures.measure import calls, due, render, totals
from loop_claude.effects import Effects from loop_claude.effects import Effects, say
from failure import Failure from failure import Failure
from loop_claude.cycle.interrupt import hand_over from loop_claude.cycle.interrupt import hand_over
from loop_claude.paths import Paths from loop_claude.paths import Paths
from model_routing.ladder import Rung from model_routing.ladder import Rung
from loop_claude.terminal import say
from loop_claude.stop import Stop from loop_claude.stop import Stop
from utc_stamp import utc from utc_stamp import utc
+2 -3
View File
@@ -5,12 +5,11 @@ import sys
import typing import typing
from claude_code.model_catalog import catalog_models from claude_code.model_catalog import catalog_models
from loop_claude.effects import Effects from loop_claude.effects import Effects, say
from failure import Failure from failure import Failure
from loop_claude.stop import needs_human, needs_terminal, Stop from loop_claude.stop import needs_human, needs_terminal, Stop
from loop_claude.paths import Paths from loop_claude.paths import Paths
from file_writes import replace_json from file_writes import replace_json
from loop_claude.terminal import say
@dataclasses.dataclass(frozen=True) @dataclasses.dataclass(frozen=True)
@@ -72,7 +71,7 @@ def ask_for_model(project_key: str, saved: pathlib.Path, folder: pathlib.Path, e
try: try:
answer = effects.input(f"{'A number, or any' if offered else 'A'} name claude --model takes: ") answer = effects.input(f"{'A number, or any' if offered else 'A'} name claude --model takes: ")
except EOFError: except EOFError:
print(file=sys.stderr) print(file=sys.stderr) # Ends the prompt's line; it says nothing, so it gets no time.
return needs_human(f"pick {project_key}'s model", "the input ended") return needs_human(f"pick {project_key}'s model", "the input ended")
picked = model_picked(answer, offered) picked = model_picked(answer, offered)
if isinstance(picked, Failure): if isinstance(picked, Failure):
-11
View File
@@ -1,11 +0,0 @@
import sys
from loop_claude.effects import Effects
# The spelling `YYYY-MM-DD HH:MM:SS` in local time, never UTC, is lilleman's call of 2026-10-28; Effects.local_time renders it.
def say(text: str, effects: Effects, *, stdout: bool = False) -> None:
"""Prints text on stderr, or on stdout where stdout, opening its first line with the machine's local time, so the human sees when it happened. Blank lines before the text stay blank, and only its first line gets the time."""
body = text.lstrip("\n")
blanks = text[: len(text) - len(body)]
print(f"{blanks}{effects.local_time(effects.now())} {body}", file=sys.stdout if stdout else sys.stderr, flush=True)
+1 -2
View File
@@ -408,8 +408,7 @@ class Cycles(unittest.TestCase):
self.assertNotIn("landed-it", run.calls[5]["stdin"]) self.assertNotIn("landed-it", run.calls[5]["stdin"])
self.assertEqual([path.name for path in checkout.transcripts()[0].parent.iterdir()], [checkout.transcripts()[0].name]) self.assertEqual([path.name for path in checkout.transcripts()[0].parent.iterdir()], [checkout.transcripts()[0].name])
self.assertIn("=== cycle 3, worker on worker-model ===", run.stdout) self.assertIn("=== cycle 3, worker on worker-model ===", run.stdout)
(header,) = re.findall(rf"(?m)^({STAMP}) === cycle 3, worker on worker-model ===$", run.raw_stdout) self.assertEqual(len(re.findall(rf"(?m)^{STAMP} === cycle 3, worker on worker-model ===$", run.raw_stdout)), 1)
self.assertLess(abs(time.time() - time.mktime(time.strptime(header, "%Y-%m-%d %H:%M:%S"))), 120)
copies = {verdict.removeprefix(f"Task: {TASK}\n\n"): copy for copy, verdict in checkout.archived().items()} copies = {verdict.removeprefix(f"Task: {TASK}\n\n"): copy for copy, verdict in checkout.archived().items()}
self.assertEqual(sorted(copies), [f"<UTC> Stopped: Ctrl-C\n\nWorker: {OFF_LADDER}\n", f"<UTC> Verdict: finished\n\nEvidence:\n> landed-it\n\nJudge: judge-model\nWorker: {OFF_LADDER}\n", f"<UTC> Verdict: unfinished\n\nEvidence:\n> started\n\nJudge: judge-model\nWorker: {OFF_LADDER}\n"]) self.assertEqual(sorted(copies), [f"<UTC> Stopped: Ctrl-C\n\nWorker: {OFF_LADDER}\n", f"<UTC> Verdict: finished\n\nEvidence:\n> landed-it\n\nJudge: judge-model\nWorker: {OFF_LADDER}\n", f"<UTC> Verdict: unfinished\n\nEvidence:\n> started\n\nJudge: judge-model\nWorker: {OFF_LADDER}\n"])
self.assertIn('"text": "landed-it"', copies[f"<UTC> Verdict: finished\n\nEvidence:\n> landed-it\n\nJudge: judge-model\nWorker: {OFF_LADDER}\n"]) self.assertIn('"text": "landed-it"', copies[f"<UTC> Verdict: finished\n\nEvidence:\n> landed-it\n\nJudge: judge-model\nWorker: {OFF_LADDER}\n"])
+5 -5
View File
@@ -20,9 +20,9 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from routing_figures import archive, measure from routing_figures import archive, measure
from loop_claude.project import checkout, model_choice, records from loop_claude.project import checkout, model_choice, records
from chunk_pick import DefaultPlan, LastCut from chunk_pick import DefaultPlan, LastCut
from loop_claude.effects import Effects, PYTHON_TIMEOUT, run_python, system_effects from loop_claude.effects import Effects, PYTHON_TIMEOUT, run_python, say, system_effects
from claude_code import entries, reply, session from claude_code import entries, reply, session
from loop_claude import escalation_mark, paths, routing, terminal from loop_claude import escalation_mark, paths, routing
from failure import Failure from failure import Failure
from loop_claude.verdicts import Finished, Interrupt, QuotedAnswer, Unfinished from loop_claude.verdicts import Finished, Interrupt, QuotedAnswer, Unfinished
from loop_claude.cycle import interrupt, judge, prompts, retry, run, states, worker from loop_claude.cycle import interrupt, judge, prompts, retry, run, states, worker
@@ -563,17 +563,17 @@ class Retried(unittest.TestCase):
class Said(unittest.TestCase): class Said(unittest.TestCase):
def test_opens_a_line_with_the_local_time_of_the_effects_clock(self): def test_opens_a_line_with_the_local_time_of_the_effects_clock(self):
with contextlib.redirect_stderr(io.StringIO()) as stderr, contextlib.redirect_stdout(io.StringIO()) as stdout: with contextlib.redirect_stderr(io.StringIO()) as stderr, contextlib.redirect_stdout(io.StringIO()) as stdout:
terminal.say("hello", FakeEffects().effects()) say("hello", FakeEffects().effects())
self.assertEqual((stderr.getvalue(), stdout.getvalue()), (f"{STAMP} hello\n", "")) self.assertEqual((stderr.getvalue(), stdout.getvalue()), (f"{STAMP} hello\n", ""))
def test_stamps_only_the_first_line_of_a_question_after_its_blank_line(self): def test_stamps_only_the_first_line_of_a_question_after_its_blank_line(self):
with contextlib.redirect_stderr(io.StringIO()) as stderr: with contextlib.redirect_stderr(io.StringIO()) as stderr:
terminal.say("\nWhich one?\n\nA or B?", FakeEffects().effects()) say("\nWhich one?\n\nA or B?", FakeEffects().effects())
self.assertEqual(stderr.getvalue(), f"\n{STAMP} Which one?\n\nA or B?\n") self.assertEqual(stderr.getvalue(), f"\n{STAMP} Which one?\n\nA or B?\n")
def test_says_on_stdout_where_asked(self): def test_says_on_stdout_where_asked(self):
with contextlib.redirect_stderr(io.StringIO()) as stderr, contextlib.redirect_stdout(io.StringIO()) as stdout: with contextlib.redirect_stderr(io.StringIO()) as stderr, contextlib.redirect_stdout(io.StringIO()) as stdout:
terminal.say("\n=== cycle 2 ===", FakeEffects().effects(), stdout=True) say("\n=== cycle 2 ===", FakeEffects().effects(), stdout=True)
self.assertEqual((stderr.getvalue(), stdout.getvalue()), ("", f"\n{STAMP} === cycle 2 ===\n")) self.assertEqual((stderr.getvalue(), stdout.getvalue()), ("", f"\n{STAMP} === cycle 2 ===\n"))