Print each chunk that asks a question and since when each parked chunk awaits its gate in do-epic --status
CI / tests (pull_request) Failing after 3m23s
CI / tests (pull_request) Failing after 3m23s
This commit is contained in:
@@ -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]:
|
||||
|
||||
+6
-6
@@ -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 <EPIC-KEY> 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 <EPIC-KEY> --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")
|
||||
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
"""What `do-epic <EPIC-KEY> --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"
|
||||
@@ -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"})
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user