From 6e171fe2c0135d7c55644851d56209554bd1c199 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 28 Oct 2026 18:40:24 +0100 Subject: [PATCH] =?UTF-8?q?Answer=20principles=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=202=20=F0=9F=9F=A1=20(0=20misread);=20move=20say?= =?UTF-8?q?=20beside=20Effects=20and=20drop=20a=20clock=20comparison=20fro?= =?UTF-8?q?m=20the=20black-box=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/loop_claude/cycle/interrupt.py | 5 ++--- bin/loop_claude/cycle/retry.py | 3 +-- bin/loop_claude/cycle/run.py | 3 +-- bin/loop_claude/cycle/worker.py | 3 +-- bin/loop_claude/effects.py | 9 ++++++++- bin/loop_claude/loop/main.py | 3 +-- bin/loop_claude/loop/reload.py | 3 +-- bin/loop_claude/loop/routing_check.py | 3 +-- bin/loop_claude/project/model_choice.py | 5 ++--- bin/loop_claude/terminal.py | 11 ----------- bin/loop_claude/test_black_box.py | 3 +-- bin/loop_claude/test_loop_claude.py | 10 +++++----- 12 files changed, 24 insertions(+), 37 deletions(-) delete mode 100644 bin/loop_claude/terminal.py diff --git a/bin/loop_claude/cycle/interrupt.py b/bin/loop_claude/cycle/interrupt.py index 04458689..45156c62 100644 --- a/bin/loop_claude/cycle/interrupt.py +++ b/bin/loop_claude/cycle/interrupt.py @@ -2,13 +2,12 @@ import dataclasses import sys import uuid -from loop_claude.effects import Effects +from loop_claude.effects import Effects, say from failure import Failure from 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 model_routing.ladder import Rung -from loop_claude.terminal import say from claude_code.trust import trust from loop_claude.project.checkout import worktrees @@ -35,7 +34,7 @@ def put_question(question: str, answer_here: bool, effects: Effects) -> str | Ta try: answer = effects.input(ASK_ANSWER).strip() 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") if not answer: return needs_human(ANSWER_QUESTION, "nothing was typed") diff --git a/bin/loop_claude/cycle/retry.py b/bin/loop_claude/cycle/retry.py index 3fe6ec5d..7860b4a0 100644 --- a/bin/loop_claude/cycle/retry.py +++ b/bin/loop_claude/cycle/retry.py @@ -1,9 +1,8 @@ import typing -from loop_claude.effects import Effects +from loop_claude.effects import Effects, say from failure import Failure from claude_code.reply import Limited -from loop_claude.terminal import say from loop_claude.stop import Stop T = typing.TypeVar("T") diff --git a/bin/loop_claude/cycle/run.py b/bin/loop_claude/cycle/run.py index 4c33f546..5ee3507f 100644 --- a/bin/loop_claude/cycle/run.py +++ b/bin/loop_claude/cycle/run.py @@ -7,7 +7,7 @@ from loop_claude.routing import after_ruling, judge_rung from transcript_archive.write import archive 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 loop_claude.effects import Effects +from loop_claude.effects import Effects, say from failure import Failure from loop_claude.verdicts import Finished, Interrupt, QuotedAnswer, Unfinished, Verdict 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 model_routing.route import Route from model_routing.ladder import Rung -from loop_claude.terminal import say from loop_claude.escalation_mark import StepUp from loop_claude.stop import Stop from model_routing import worker_rungs diff --git a/bin/loop_claude/cycle/worker.py b/bin/loop_claude/cycle/worker.py index 2cad28bf..9f61a158 100644 --- a/bin/loop_claude/cycle/worker.py +++ b/bin/loop_claude/cycle/worker.py @@ -1,11 +1,10 @@ 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 claude_code.reply import Limited from claude_code.transcript import part_line from machine_load.memory import ROOM_SHARE from model_routing.ladder import Rung -from loop_claude.terminal import say from claude_code.session import Session PRINTED_TOOL_INPUT = 160 diff --git a/bin/loop_claude/effects.py b/bin/loop_claude/effects.py index 27d37637..b4a2d3e0 100644 --- a/bin/loop_claude/effects.py +++ b/bin/loop_claude/effects.py @@ -37,7 +37,7 @@ class Effects: execv: typing.Callable[[str, list[str]], None] git: Git 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] # The machine's memory; None where it cannot be read. 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}") except subprocess.TimeoutExpired: 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) diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index 33ca0d7f..f4e92809 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -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 chunk_pick import default_plan, DefaultPlan from git_repo import default_ref -from loop_claude.effects import Effects +from loop_claude.effects import Effects, say from failure import Failure from loop_claude.verdicts import Finished, Unfinished 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.records import read_records 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 # 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. diff --git a/bin/loop_claude/loop/reload.py b/bin/loop_claude/loop/reload.py index 5a3d024b..783a1581 100644 --- a/bin/loop_claude/loop/reload.py +++ b/bin/loop_claude/loop/reload.py @@ -6,9 +6,8 @@ import sys import types import typing -from loop_claude.effects import Effects +from loop_claude.effects import Effects, say from model_routing.route import Route -from loop_claude.terminal import say from loop_claude.stop import Stop RELOAD_FLAG = "--reloaded" diff --git a/bin/loop_claude/loop/routing_check.py b/bin/loop_claude/loop/routing_check.py index 8d0cd9a8..72955096 100644 --- a/bin/loop_claude/loop/routing_check.py +++ b/bin/loop_claude/loop/routing_check.py @@ -3,12 +3,11 @@ import pathlib from routing_figures import archive 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 loop_claude.cycle.interrupt import hand_over from loop_claude.paths import Paths from model_routing.ladder import Rung -from loop_claude.terminal import say from loop_claude.stop import Stop from utc_stamp import utc diff --git a/bin/loop_claude/project/model_choice.py b/bin/loop_claude/project/model_choice.py index f4f38244..79980c8e 100644 --- a/bin/loop_claude/project/model_choice.py +++ b/bin/loop_claude/project/model_choice.py @@ -5,12 +5,11 @@ import sys import typing 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 loop_claude.stop import needs_human, needs_terminal, Stop from loop_claude.paths import Paths from file_writes import replace_json -from loop_claude.terminal import say @dataclasses.dataclass(frozen=True) @@ -72,7 +71,7 @@ def ask_for_model(project_key: str, saved: pathlib.Path, folder: pathlib.Path, e try: answer = effects.input(f"{'A number, or any' if offered else 'A'} name claude --model takes: ") 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") picked = model_picked(answer, offered) if isinstance(picked, Failure): diff --git a/bin/loop_claude/terminal.py b/bin/loop_claude/terminal.py deleted file mode 100644 index 9ebaa0b2..00000000 --- a/bin/loop_claude/terminal.py +++ /dev/null @@ -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) diff --git a/bin/loop_claude/test_black_box.py b/bin/loop_claude/test_black_box.py index fe2263eb..de16ade3 100644 --- a/bin/loop_claude/test_black_box.py +++ b/bin/loop_claude/test_black_box.py @@ -408,8 +408,7 @@ class Cycles(unittest.TestCase): 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.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.assertLess(abs(time.time() - time.mktime(time.strptime(header, "%Y-%m-%d %H:%M:%S"))), 120) + self.assertEqual(len(re.findall(rf"(?m)^{STAMP} === cycle 3, worker on worker-model ===$", run.raw_stdout)), 1) copies = {verdict.removeprefix(f"Task: {TASK}\n\n"): copy for copy, verdict in checkout.archived().items()} self.assertEqual(sorted(copies), [f" Stopped: Ctrl-C\n\nWorker: {OFF_LADDER}\n", f" Verdict: finished\n\nEvidence:\n> landed-it\n\nJudge: judge-model\nWorker: {OFF_LADDER}\n", f" Verdict: unfinished\n\nEvidence:\n> started\n\nJudge: judge-model\nWorker: {OFF_LADDER}\n"]) self.assertIn('"text": "landed-it"', copies[f" Verdict: finished\n\nEvidence:\n> landed-it\n\nJudge: judge-model\nWorker: {OFF_LADDER}\n"]) diff --git a/bin/loop_claude/test_loop_claude.py b/bin/loop_claude/test_loop_claude.py index 76fa9808..5564eec6 100644 --- a/bin/loop_claude/test_loop_claude.py +++ b/bin/loop_claude/test_loop_claude.py @@ -20,9 +20,9 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) from routing_figures import archive, measure from loop_claude.project import checkout, model_choice, records 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 loop_claude import escalation_mark, paths, routing, terminal +from loop_claude import escalation_mark, paths, routing from failure import Failure from loop_claude.verdicts import Finished, Interrupt, QuotedAnswer, Unfinished from loop_claude.cycle import interrupt, judge, prompts, retry, run, states, worker @@ -563,17 +563,17 @@ class Retried(unittest.TestCase): class Said(unittest.TestCase): 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: - terminal.say("hello", FakeEffects().effects()) + say("hello", FakeEffects().effects()) 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): 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") def test_says_on_stdout_where_asked(self): 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"))