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:
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
@@ -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"<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"])
|
||||
|
||||
@@ -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"))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user