Answer architecture round 1: 1 🔴, 2 🟡 (0 misread); render the stamp through Effects.local_time

This commit is contained in:
2026-10-28 18:33:31 +01:00
parent 43e7e96b41
commit 08855e8055
5 changed files with 21 additions and 19 deletions
+2 -1
View File
@@ -37,6 +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`.
local_time: typing.Callable[[float], str]
# The machine's memory; None where it cannot be read.
memory: typing.Callable[[], Memory | None]
@@ -68,7 +69,7 @@ def system_effects() -> Effects:
execv=os.execv,
git=git_repo.git,
input=input,
local_time=lambda seconds: time.strftime("%Y-%m-%d %H:%M %Z", time.localtime(seconds)),
local_time=lambda seconds: time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(seconds)),
memory=read_memory,
now=time.time,
on_terminal=lambda: sys.stdin.isatty() and sys.stdout.isatty(),
+1
View File
@@ -287,6 +287,7 @@ def fetched_plan(root: str) -> DefaultPlan | Failure:
def plan_item(plan: DefaultPlan | Failure, effects: Effects) -> Item | None:
"""The item that routes a chunk, chunk_pick.chunk_item's pick from the default branch; None without one, so the chunk runs on the project's rung."""
# It says why through effects, as every loop-claude function that prints does; todo.md item 51 moves all of them to one injected effect, and splitting this one off first would only be undone.
if isinstance(plan, Failure):
item: Item | Failure | None = plan
elif isinstance(plan.todo, Failure):
+3 -5
View File
@@ -1,13 +1,11 @@
import sys
import time
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.
# 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 as `2026-10-28 11:46:01`, so the human sees when it happened. Blank lines before the text stay blank, and only its first line gets the time."""
"""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)]
stamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(effects.now()))
print(f"{blanks}{stamp} {body}", file=sys.stdout if stdout else sys.stderr, flush=True)
print(f"{blanks}{effects.local_time(effects.now())} {body}", file=sys.stdout if stdout else sys.stderr, flush=True)
+14 -12
View File
@@ -20,7 +20,7 @@ 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
from loop_claude.effects import Effects, PYTHON_TIMEOUT, run_python, system_effects
from claude_code import entries, reply, session
from loop_claude import escalation_mark, paths, routing, terminal
from failure import Failure
@@ -47,17 +47,8 @@ OPUS_179_AT_6 = '{"model": "claude-opus-5-5", "effort": "medium", "item": 179, "
CWD = pathlib.Path("/c")
NOW = 1790000000
# How a line said at NOW opens in a zone two hours ahead of UTC, which setUpModule sets: a stamp in UTC would read 14:13:20.
STAMP = "2026-09-21 16:13:20"
def setUpModule():
zone = unittest.mock.patch.dict(os.environ, {"TZ": "XXX-2"})
zone.start()
# Cleanups run last in, first out: the zone is restored before the clock rereads it.
unittest.addModuleCleanup(time.tzset)
unittest.addModuleCleanup(zone.stop)
time.tzset()
# How a line said at NOW opens, with FakeEffects' local_time.
STAMP = f"<{NOW}>"
def assistant(*parts):
@@ -1118,6 +1109,17 @@ class ChunkFacts(unittest.TestCase):
self.assertEqual((resumed.made("python"), facts), ([], ""))
class LocalTime(unittest.TestCase):
def test_renders_seconds_in_the_machines_zone(self):
# A POSIX zone two hours ahead of UTC, so a time in UTC would read 14:13:20. Cleanups run last in, first out: the zone is restored before the clock rereads it.
self.addCleanup(time.tzset)
zone = unittest.mock.patch.dict(os.environ, {"TZ": "XXX-2"})
zone.start()
self.addCleanup(zone.stop)
time.tzset()
self.assertEqual(system_effects().local_time(NOW), "2026-09-21 16:13:20")
class PythonEffect(unittest.TestCase):
def test_runs_a_script_in_the_given_directory(self):
with tempfile.TemporaryDirectory() as cwd: