From 8e210eaa099719839b386bc97ffb8ea946a58d6a Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 19 Nov 2026 00:40:16 +0100 Subject: [PATCH 1/8] Print each chunk that asks a question and since when each parked chunk awaits its gate in do-epic --status --- bin/agent_cycle/tmux.py | 4 ++- bin/do_epic/main.py | 12 ++++---- bin/do_epic/scheduler.py | 18 ----------- bin/do_epic/status.py | 46 +++++++++++++++++++++++++++++ bin/do_epic/test_main.py | 17 ++++++++--- bin/do_epic/test_scheduler.py | 2 +- bin/loop_claude/test_loop_claude.py | 2 +- docs/reading-cost.md | 34 +++++++++++++++++++++ 8 files changed, 104 insertions(+), 31 deletions(-) create mode 100644 bin/do_epic/status.py diff --git a/bin/agent_cycle/tmux.py b/bin/agent_cycle/tmux.py index 704caaec..c23f6dc4 100644 --- a/bin/agent_cycle/tmux.py +++ b/bin/agent_cycle/tmux.py @@ -51,6 +51,8 @@ class Listed: dead: bool # What its name says its parked chunk awaits, as the words after PARKED; empty for a chunk that isn't parked. awaits: str = "" + # Whether its name ended in WAITS: its chunk's worker asks the human a question. + asks: bool = False @property def parked(self) -> bool: @@ -90,7 +92,7 @@ def listed(session: str, run: Tmux) -> list[Listed]: def as_listed(shown: str, id: str, pane_dead: str) -> Listed: """The window tmux shows under the name shown, with the ID id and `#{pane_dead}` as pane_dead.""" name, _, awaits = shown.removesuffix(WAITS).partition(PARKED) - return Listed(name, id, pane_dead == "1", awaits) + return Listed(name, id, pane_dead == "1", awaits, shown.endswith(WAITS)) def everywhere(run: Tmux) -> list[Placed]: diff --git a/bin/do_epic/main.py b/bin/do_epic/main.py index 1ab8c919..aa2e16be 100644 --- a/bin/do_epic/main.py +++ b/bin/do_epic/main.py @@ -9,7 +9,7 @@ import sys import typing from loop_claude.loop.chunk_start import archived_route, routed -from do_epic import chunk_prompt, findings, gates, parked, scheduler +from do_epic import chunk_prompt, findings, gates, parked, scheduler, status from do_epic.repo_pick import ClaudeWork, HumanTask, recorded, Repo from loop_claude.loop.close import closed_cycle from loop_claude.project.records import CONSEQUENCE, read_records @@ -52,7 +52,7 @@ A chunk whose worker ends its run while its pull request waits on its checks, an is parked: it frees its place for the next chunk, and its window's name says what it awaits. Its worker goes on once the checks pass, the approval comes or a reviewer comments, and a place is free; until one is, the name says `awaits a slot`. A parked chunk survives a reboot: run do-epic again to go on polling. ---status starts no chunk: it prints each open issue with whether its chunk runs, or why it waits. +--status starts no chunk: it prints each open issue with whether its chunk runs, asks you a question, or why it waits: a parked chunk's gate and since when, a stopped window, a blocker or a human's task. {findings.HELP} The Jira site and its credentials are set in ~/.claude-projects/do-epic/config.toml.""" # Under the home folder, where a chunk's cycles are archived, a folder per epic. It is not loop-claude's archive, since that archive's readers, such as judge-replay and the routing figures, read loop-claude's prompts. @@ -108,8 +108,8 @@ def main(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launcher: def run(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launcher: pathlib.Path, effects: Effects, backend: Backend, stdin: typing.TextIO, forge_at: typing.Callable[[str], Run]) -> Stop: chunk, words = (argv[1], argv[2:]) if len(argv) >= 2 and argv[0] == scheduler.CHUNK_FLAG else (None, argv) - status = chunk is None and words[1:] == [STATUS_FLAG] - words = words[:1] if status else words + status_asked = chunk is None and words[1:] == [STATUS_FLAG] + words = words[:1] if status_asked else words # What the words after the epic's key write into the epic, where they are a filing or a decision. writes = findings.parsed(words[1:]) if chunk is None else None if (len(words) != 1 and not writes) or not ISSUE_KEY.fullmatch(words[0]) or (chunk is not None and not ISSUE_KEY.fullmatch(chunk)): @@ -124,7 +124,7 @@ def run(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launcher: return Stop(1, config.reason) store, record = backend(config, words[0]) epic = EpicRun(words[0], config, store, record, paths, env, launcher, effects, forge_at) - if status: + if status_asked: return status_printed(epic) return windows_opened(epic) if chunk is None else chunk_run(chunk, epic) @@ -132,7 +132,7 @@ def run(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launcher: def status_printed(epic: EpicRun) -> Stop: """What `do-epic --status` does: prints a line per open issue, and doesn't start anything.""" issues = epic.store.read() - lines = issues if isinstance(issues, Failure) else scheduler.status(epic.key, epic.paths.home, issues, epic.effects.tmux) + lines = issues if isinstance(issues, Failure) else status.lines(epic.key, epic.paths.home, issues, epic.effects.tmux) return Stop(1, lines.reason) if isinstance(lines, Failure) else Stop(0, "\n".join(lines) or f"the epic {epic.key} has no open issue") diff --git a/bin/do_epic/scheduler.py b/bin/do_epic/scheduler.py index 7c3dc066..38557080 100644 --- a/bin/do_epic/scheduler.py +++ b/bin/do_epic/scheduler.py @@ -191,21 +191,3 @@ def resume(epic: Epic, repo: str, window: tmux.Window, run: tmux.Tmux) -> str | return None except OSError as failure: return f"cannot lock {failure.filename or epic.folder / LOCK}: {failure.strerror}" - - -def status(key: str, home: pathlib.Path, issues: list[EpicIssue], run: tmux.Tmux) -> list[str] | Failure: - """A line per open issue of the epic called key, in the tracker's rank order: that its chunk runs, or why it waits. It doesn't start anything and checks no limit, so the line of a chunk that has yet to start doesn't say which limit holds it back.""" - found, waits = chunks(issues) - parked = parked_chunks(home / STATE / key) - if isinstance(parked, Failure): - return parked - windows = tmux.listed(tmux.session_name(tmux.EPIC, key), run) - live = {window.name: window for window in windows if not window.dead} - again = f"run `do-epic {key}` to start it again" - reasons = {wait.issue: wait.reason for wait in waits} - for chunk in found: - if chunk.issue in parked: - reasons[chunk.issue] = parked[chunk.issue].waits(live[chunk.issue].awaits) if chunk.issue in live else f"{parked[chunk.issue].waits('')}, and its window stopped; {again}" - elif chunk.issue not in live: - reasons[chunk.issue] = f"its window stopped; {again}" if chunk.issue in {window.name for window in windows} else f"it has not started; `do-epic {key}` starts it once the epic and its repo have room" - return [f"{issue.key} waits: {reasons[issue.key]}" if issue.key in reasons else f"{issue.key} runs" for issue in issues if issue.key in reasons or issue.key in live] diff --git a/bin/do_epic/status.py b/bin/do_epic/status.py new file mode 100644 index 00000000..90c0edb9 --- /dev/null +++ b/bin/do_epic/status.py @@ -0,0 +1,46 @@ +"""What `do-epic --status` prints: each open issue of the epic, with whether its chunk runs, asks the human, is parked on a gate, has stopped or has yet to start (docs/decisions.md → `do-epic: drives one Jira epic …`).""" +import datetime +import pathlib + +from agent_cycle import tmux +from do_epic.backend.protocol import EpicIssue +from do_epic.parked import file_of, Parked, parked_chunks +from do_epic.scheduler import chunks, STATE +from failure import Failure + + +def since(folder: pathlib.Path, chunk: Parked) -> str: + """When the chunk parked on what its file says it awaits, to the minute in the machine's time zone: the file is written once per gate, so its time is when the gate began. Empty where the file cannot be read.""" + try: + return datetime.datetime.fromtimestamp(file_of(folder, chunk.issue).stat().st_mtime).strftime("%Y-%m-%d %H:%M") + except OSError: + return "" + + +def lines(key: str, home: pathlib.Path, issues: list[EpicIssue], run: tmux.Tmux) -> list[str] | Failure: + """A line per open issue of the epic called key, in the tracker's rank order: that its chunk runs or asks the human, or why it waits. It doesn't start anything and checks no limit, so the line of a chunk that has yet to start doesn't say which limit holds it back.""" + found, waits = chunks(issues) + folder = home / STATE / key + parked = parked_chunks(folder) + if isinstance(parked, Failure): + return parked + session = tmux.session_name(tmux.EPIC, key) + windows = tmux.listed(session, run) + live = {window.name: window for window in windows if not window.dead} + again = f"run `do-epic {key}` to start it again" + reasons = {wait.issue: wait.reason for wait in waits} + for chunk in found: + if chunk.issue in parked: + gate = since(folder, parked[chunk.issue]) + when = f", since {gate}" if gate else "" + reasons[chunk.issue] = parked[chunk.issue].waits(live[chunk.issue].awaits) + when if chunk.issue in live else f"{parked[chunk.issue].waits('')}{when}, and its window stopped; {again}" + elif chunk.issue not in live: + reasons[chunk.issue] = f"its window stopped; {again}" if chunk.issue in {window.name for window in windows} else f"it has not started; `do-epic {key}` starts it once the epic and its repo have room" + return [line(issue.key, reasons, live, session) for issue in issues if issue.key in reasons or issue.key in live] + + +def line(issue: str, reasons: dict[str, str], live: dict[str, tmux.Listed], session: str) -> str: + """The status line of issue, whose chunk has a live window or a reason not to run.""" + if issue in reasons: + return f"{issue} waits: {reasons[issue]}" + return f"{issue} asks you: answer its question in the tmux window {session}:{issue}" if live[issue].asks else f"{issue} runs" diff --git a/bin/do_epic/test_main.py b/bin/do_epic/test_main.py index fd02277e..5d027f07 100644 --- a/bin/do_epic/test_main.py +++ b/bin/do_epic/test_main.py @@ -1,7 +1,9 @@ import contextlib import dataclasses +import datetime import io import json +import os import pathlib import shutil import subprocess @@ -41,6 +43,11 @@ class Description: return self.text +# When the parked chunks of the status test were parked, and how the status prints it, in the machine's time zone. +PARKED_SINCE = 1_700_000_000 +PARKED_ON = datetime.datetime.fromtimestamp(PARKED_SINCE).strftime("%Y-%m-%d %H:%M") + + class DoEpicTest(unittest.TestCase): def setUp(self) -> None: made = tempfile.TemporaryDirectory() @@ -614,17 +621,19 @@ class TheStatus(DoEpicTest): parked.park(folder, parked.Parked("ABC-26", "/code/api-ABC-26", "9", "s", "its checks")) parked.park(folder, parked.Parked("ABC-28", "/code/api-ABC-28", "11", "s", "an approval")) self.issues.insert(7, issue("ABC-28", "repo:api")) + for issue_key, when in (("ABC-20", PARKED_SINCE), ("ABC-26", PARKED_SINCE), ("ABC-28", PARKED_SINCE)): + os.utime(parked.file_of(folder, issue_key), (when, when)) fake = FakeEffects(windows="ABC-20 awaits an approval\t0\t@1\nABC-21 ?\t0\t@2\nABC-22\t1\t@3\nABC-28 awaits a slot\t0\t@4\n") code, out, err = self.run_main(["ABC-12", "--status"], fake) self.assertEqual((code, err), (0, "")) self.assertEqual(out.replace("<1790000000> ", "").splitlines(), [ - "ABC-20 waits: it is parked: its pull request #7 awaits an approval", - "ABC-21 runs", + f"ABC-20 waits: it is parked: its pull request #7 awaits an approval, since {PARKED_ON}", + "ABC-21 asks you: answer its question in the tmux window epic-ABC-12:ABC-21", "ABC-22 waits: its window stopped; run `do-epic ABC-12` to start it again", "ABC-23 waits: ABC-20 blocks it", "ABC-24 waits: it has not started; `do-epic ABC-12` starts it once the epic and its repo have room", - "ABC-26 waits: it is parked: its pull request #9 awaits its checks, and its window stopped; run `do-epic ABC-12` to start it again", - "ABC-28 waits: it is parked: its worker has work again on pull request #11 and awaits a slot", + f"ABC-26 waits: it is parked: its pull request #9 awaits its checks, since {PARKED_ON}, and its window stopped; run `do-epic ABC-12` to start it again", + f"ABC-28 waits: it is parked: its worker has work again on pull request #11 and awaits a slot, since {PARKED_ON}", "ABC-27 waits: no label names its repo", ]) self.assertEqual({args[0] for args in fake.tmux_calls}, {"-V", "list-windows"}) diff --git a/bin/do_epic/test_scheduler.py b/bin/do_epic/test_scheduler.py index 97fd1573..70ba18ae 100644 --- a/bin/do_epic/test_scheduler.py +++ b/bin/do_epic/test_scheduler.py @@ -316,7 +316,7 @@ class TheFirstPrompt(unittest.TestCase): class WindowsAcrossSessions(unittest.TestCase): def test_lists_each_window_with_its_session_and_root(self) -> None: run = Tmux(("epic-ABC-12", "ABC-20 ?", False, "/code/api"), ("loop-api", "item-3", True, "")) - self.assertEqual(tmux.everywhere(run), [tmux.Placed("epic-ABC-12", tmux.Listed("ABC-20", "@0", False), "/code/api"), tmux.Placed("loop-api", tmux.Listed("item-3", "@1", True), "")]) + self.assertEqual(tmux.everywhere(run), [tmux.Placed("epic-ABC-12", tmux.Listed("ABC-20", "@0", False, asks=True), "/code/api"), tmux.Placed("loop-api", tmux.Listed("item-3", "@1", True), "")]) self.assertEqual(run.calls, [["list-windows", "-a", "-F", f"#{{session_name}}\t#{{window_name}}\t#{{pane_dead}}\t#{{window_id}}\t#{{{tmux.ROOT}}}"]]) def test_without_a_tmux_server_there_are_none(self) -> None: diff --git a/bin/loop_claude/test_loop_claude.py b/bin/loop_claude/test_loop_claude.py index a3268f58..79c04daf 100644 --- a/bin/loop_claude/test_loop_claude.py +++ b/bin/loop_claude/test_loop_claude.py @@ -1319,7 +1319,7 @@ class TmuxCommands(unittest.TestCase): def test_lists_the_windows_without_the_waiting_mark(self): fake = FakeEffects(windows="item-372 ?\t0\t@1\nitem-380\t1\t@2\nno-item\t0\t@5\n") - self.assertEqual(tmux.listed("loop-proj", fake.tmux), [tmux.Listed("item-372", "@1", False), tmux.Listed("item-380", "@2", True), tmux.Listed("no-item", "@5", False)]) + self.assertEqual(tmux.listed("loop-proj", fake.tmux), [tmux.Listed("item-372", "@1", False, asks=True), tmux.Listed("item-380", "@2", True), tmux.Listed("no-item", "@5", False)]) self.assertEqual(fake.tmux_calls, [["list-windows", "-t", "=loop-proj", "-F", "#{window_name}\t#{pane_dead}\t#{window_id}"]]) self.assertEqual(tmux.listed("loop-proj", FakeEffects().tmux), []) failed = lambda args: subprocess.CompletedProcess(args, 1, "item-1\t0\t@1\n", "no server") diff --git a/docs/reading-cost.md b/docs/reading-cost.md index 2438e973..27a660b4 100644 --- a/docs/reading-cost.md +++ b/docs/reading-cost.md @@ -2910,3 +2910,37 @@ Read most (opens and searches): - `docs/decisions.md` 2 - `bin/agent_cycle/tmux.py` 1 - `bin/loop-claude` 1 + +## Reading cost, chunk 43ac6d329242, finished 2026-11-18T22:50:16Z + +104341 new input tokens before the first commit. + +Read most (opens and searches): + +- `bin/agent_cycle/judge.py` 3 +- `rules/todo-items.md` 3 +- `bin/do_epic/main.py` 2 +- `bin/loop_claude/cycle/prompts.py` 2 +- `bin/agent_cycle/run.py` 1 +- `bin/agent_cycle/worker_prompts.py` 1 +- `bin/do_epic/chunk_prompt.py` 1 +- `bin/do_epic/epic_record.py` 1 +- `bin/loop_claude/project/premises.py` 1 +- `bin/loop_claude/project/records.py` 1 + +## Reading cost, chunk d77b99fcaa22, finished 2026-11-18T23:16:50Z + +112582 new input tokens before the first commit. + +Read most (opens and searches): + +- `bin/do_epic/main.py` 7 +- `bin/forge/pulls.py` 4 +- `bin/chunk_pr/approval.py` 3 +- `bin/chunk_pr/main.py` 3 +- `bin/do_epic/scheduler.py` 3 +- `rules/todo-items.md` 3 +- `README.md` 2 +- `bin/agent_cycle/tmux.py` 1 +- `bin/do_epic/chunk_prompt.py` 1 +- `docs/decisions.md` 1 -- 2.52.0 From 07ef481c51840761775e5d718b2bd76953142a2c Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 19 Nov 2026 01:35:37 +0100 Subject: [PATCH 2/8] Test do-epic's status lines on their own --- bin/do_epic/test_status.py | 63 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 bin/do_epic/test_status.py diff --git a/bin/do_epic/test_status.py b/bin/do_epic/test_status.py new file mode 100644 index 00000000..3f6faac1 --- /dev/null +++ b/bin/do_epic/test_status.py @@ -0,0 +1,63 @@ +import datetime +import os +import pathlib +import tempfile +import unittest + +from do_epic import parked, status +from do_epic.scheduler import STATE +from do_epic.test_scheduler import issue, Tmux +from failure import Failure + +SINCE = 1_700_000_000 +# How the status prints SINCE, in the machine's time zone. +SINCE_ON = datetime.datetime.fromtimestamp(SINCE).strftime("%Y-%m-%d %H:%M") +EPIC = "epic-ABC-12" + + +class TheStatusLines(unittest.TestCase): + def setUp(self) -> None: + self.home = pathlib.Path(tempfile.mkdtemp()) + self.folder = self.home / STATE / "ABC-12" + + def park(self, key: str, on: str, since: int | None = SINCE) -> None: + parked.park(self.folder, parked.Parked(key, f"/code/api-{key}", "7", "s", on)) + if since is not None: + os.utime(parked.file_of(self.folder, key), (since, since)) + + def lines(self, issues: list, *windows: tuple[str, str, bool, str]) -> list[str] | Failure: + return status.lines("ABC-12", self.home, issues, Tmux(*windows)) + + def test_a_chunk_that_asks_says_where_to_answer_and_one_that_works_runs(self) -> None: + found = self.lines([issue("ABC-20", "repo:api"), issue("ABC-21", "repo:api")], (EPIC, "ABC-20 ?", False, ""), (EPIC, "ABC-21", False, "")) + self.assertEqual(found, ["ABC-20 asks you: answer its question in the tmux window epic-ABC-12:ABC-20", "ABC-21 runs"]) + + def test_a_parked_chunk_says_what_it_awaits_and_since_when(self) -> None: + self.park("ABC-20", "an approval") + self.assertEqual(self.lines([issue("ABC-20", "repo:api")], (EPIC, "ABC-20 awaits its checks", False, "")), [f"ABC-20 waits: it is parked: its pull request #7 awaits its checks, since {SINCE_ON}"]) + + def test_a_parked_chunk_without_a_window_says_since_when_and_how_to_start_it_again(self) -> None: + self.park("ABC-20", "an approval") + self.assertEqual(self.lines([issue("ABC-20", "repo:api")]), [f"ABC-20 waits: it is parked: its pull request #7 awaits an approval, since {SINCE_ON}, and its window stopped; run `do-epic ABC-12` to start it again"]) + + def test_a_stopped_chunk_and_one_not_started_say_so(self) -> None: + found = self.lines([issue("ABC-20", "repo:api"), issue("ABC-21", "repo:api")], (EPIC, "ABC-20", True, "")) + self.assertEqual(found, ["ABC-20 waits: its window stopped; run `do-epic ABC-12` to start it again", "ABC-21 waits: it has not started; `do-epic ABC-12` starts it once the epic and its repo have room"]) + + def test_a_human_task_and_a_blocked_issue_say_why_they_wait(self) -> None: + found = self.lines([issue("ABC-20", "repo:api"), issue("ABC-21", "repo:api", blockers=("ABC-20",)), issue("ABC-22", "do-epic-human")], (EPIC, "ABC-20", False, "")) + self.assertEqual(found, ["ABC-20 runs", "ABC-21 waits: ABC-20 blocks it", "ABC-22 waits: it is a human's task"]) + + def test_a_parked_chunk_that_cannot_be_read_is_a_failure(self) -> None: + (self.folder / parked.FOLDER).mkdir(parents=True) + (self.folder / parked.FOLDER / "ABC-20.json").write_text("{", encoding="utf-8") + self.assertIsInstance(self.lines([issue("ABC-20", "repo:api")]), Failure) + + +class TheTimeSinceParking(unittest.TestCase): + def test_is_empty_where_the_chunks_file_is_gone(self) -> None: + self.assertEqual(status.since(pathlib.Path(tempfile.mkdtemp()), parked.Parked("ABC-20", "/code/api", "7", "s", "an approval")), "") + + +if __name__ == "__main__": + unittest.main() -- 2.52.0 From 3e2e0ae5bf13d598dcb0a6bc2781c0e80538282a Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 19 Nov 2026 01:59:18 +0100 Subject: [PATCH 3/8] Put the since-when suffix in since, so its own test covers it --- bin/do_epic/status.py | 7 +++---- bin/do_epic/test_status.py | 7 +++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/bin/do_epic/status.py b/bin/do_epic/status.py index 90c0edb9..157636d8 100644 --- a/bin/do_epic/status.py +++ b/bin/do_epic/status.py @@ -10,9 +10,9 @@ from failure import Failure def since(folder: pathlib.Path, chunk: Parked) -> str: - """When the chunk parked on what its file says it awaits, to the minute in the machine's time zone: the file is written once per gate, so its time is when the gate began. Empty where the file cannot be read.""" + """`, since