Merge remote-tracking branch 'origin/main' into item-416
CI / tests (pull_request) Has been cancelled
CI / tests (pull_request) Has been cancelled
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
- `do-epic <EPIC-KEY> --status` says which chunk asks you a question, and since when each parked chunk has awaited its gate.
|
||||
- do-epic moves a chunk's issue to done in Jira when the chunk finishes, and the split item it belongs to once its last sub-task is done, so no finished chunk starts again and the chunks it blocks start. It moves them by the transition `jira-finish-transition` and `jira-finish-status` name, so set both; without them a finishing chunk stops with that reason.
|
||||
- Describe do-epic in the README: its entry under Tools, and its machine settings and `repo-rule.md` under Set up a project.
|
||||
- do-epic finishes an epic: once none of its issues is open, a finishing chunk files a release review of each repo the epic changed, as an issue labelled `do-epic-release-review`, and asks you to confirm each goal. `do-epic <EPIC-KEY> --close-epic` then posts the summary piped in as a comment on the epic and closes it in Jira, by the transition `jira-finish-transition` names, to the status `jira-finish-status` names.
|
||||
|
||||
@@ -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 loop asks the human something.
|
||||
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, finish, gates, parked, scheduler, split
|
||||
from do_epic import chunk_prompt, findings, finish, gates, parked, scheduler, split, 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
|
||||
@@ -54,7 +54,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 doesn't start any chunk. It prints a line per open issue: that its chunk runs or asks you a question, or why it waits, such as the gate a parked chunk awaits and since when.
|
||||
{findings.HELP}
|
||||
{finish.HELP}
|
||||
The Jira site and its credentials are set in ~/.claude-projects/do-epic/config.toml."""
|
||||
@@ -111,8 +111,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
|
||||
closes = chunk is None and words[1:] == [finish.CLOSE]
|
||||
@@ -128,7 +128,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)
|
||||
|
||||
@@ -136,7 +136,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")
|
||||
|
||||
|
||||
|
||||
@@ -197,21 +197,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,48 @@
|
||||
"""What `do-epic <EPIC-KEY> --status` prints: a line per open issue of the epic (docs/decisions.md → `do-epic: drives one Jira epic …`)."""
|
||||
import datetime
|
||||
import pathlib
|
||||
|
||||
from do_epic.scheduler import chunks, STATE
|
||||
from do_epic.backend.protocol import EpicIssue
|
||||
from failure import Failure
|
||||
from do_epic.parked import file_of, Parked, parked_chunks, SLOT
|
||||
from agent_cycle import tmux
|
||||
|
||||
|
||||
def since(folder: pathlib.Path, chunk: Parked) -> str:
|
||||
"""`, since <time>`: when the chunk's pull request began to await the gate its file records, to the minute in UTC, since the machine may be one the human reaches over ssh. The file is written once per gate. Empty where the file cannot be read."""
|
||||
try:
|
||||
return f", since {datetime.datetime.fromtimestamp(file_of(folder, chunk.issue).stat().st_mtime, datetime.timezone.utc).strftime('%Y-%m-%d %H:%M')} UTC"
|
||||
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 or check any 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:
|
||||
shown = live[chunk.issue].awaits if chunk.issue in live else ""
|
||||
# Past its gate, a chunk that awaits a slot has no time the file knows: the file's is when its gate began.
|
||||
when = "" if shown == SLOT else since(folder, parked[chunk.issue])
|
||||
stopped = "" if chunk.issue in live else f", and its window stopped; {again}"
|
||||
reasons[chunk.issue] = parked[chunk.issue].waits(shown) + when + stopped
|
||||
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"
|
||||
@@ -718,23 +718,13 @@ class AChunkWhosePullRequestWaitsOnAGate(DoEpicTest):
|
||||
|
||||
class TheStatus(DoEpicTest):
|
||||
def test_prints_what_each_open_issue_does_and_starts_nothing(self) -> None:
|
||||
self.issues = [issue("ABC-20", "repo:api"), issue("ABC-21", "repo:api"), issue("ABC-22", "repo:api"), issue("ABC-23", "repo:api", blockers=("ABC-20",)), issue("ABC-24", "repo:api"), issue("ABC-25", "repo:api", done=True), issue("ABC-26", "repo:api"), issue("ABC-27")]
|
||||
folder = self.home / ".local/state/do-epic/ABC-12"
|
||||
parked.park(folder, parked.Parked("ABC-20", "/code/api-ABC-20", "7", "s", "an approval"))
|
||||
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"))
|
||||
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")
|
||||
self.issues = [issue("ABC-21", "repo:api"), issue("ABC-24", "repo:api"), issue("ABC-27")]
|
||||
fake = FakeEffects(windows="ABC-21 ?\t0\t@2\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",
|
||||
"ABC-22 waits: its window stopped; run `do-epic ABC-12` to start it again",
|
||||
"ABC-23 waits: ABC-20 blocks it",
|
||||
"ABC-21 asks you: answer its question in the tmux window epic-ABC-12:ABC-21",
|
||||
"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",
|
||||
"ABC-27 waits: no label names its repo",
|
||||
])
|
||||
self.assertEqual({args[0] for args in fake.tmux_calls}, {"-V", "list-windows"})
|
||||
|
||||
@@ -345,7 +345,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:
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
import os
|
||||
import pathlib
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from failure import Failure
|
||||
from do_epic.test_scheduler import issue, Tmux
|
||||
from do_epic import parked, status
|
||||
from do_epic.scheduler import STATE
|
||||
|
||||
SINCE = 1_700_000_000
|
||||
# SINCE as the status prints it.
|
||||
SINCE_ON = "2023-11-14 22:13 UTC"
|
||||
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) -> None:
|
||||
parked.park(self.folder, parked.Parked(key, f"/code/api-{key}", "7", "s", on))
|
||||
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_that_awaits_a_slot_gives_no_time_since_its_gate_began(self) -> None:
|
||||
self.park("ABC-20", "an approval")
|
||||
self.assertEqual(self.lines([issue("ABC-20", "repo:api")], (EPIC, "ABC-20 awaits a slot", False, "")), ["ABC-20 waits: it is parked: its worker has work again on pull request #7 and awaits a slot"])
|
||||
|
||||
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_the_time_of_the_chunks_file_to_the_minute(self) -> None:
|
||||
folder = pathlib.Path(tempfile.mkdtemp())
|
||||
chunk = parked.Parked("ABC-20", "/code/api", "7", "s", "an approval")
|
||||
parked.park(folder, chunk)
|
||||
os.utime(parked.file_of(folder, "ABC-20"), (SINCE, SINCE))
|
||||
self.assertEqual(status.since(folder, chunk), f", since {SINCE_ON}")
|
||||
|
||||
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()
|
||||
@@ -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")
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||
| 416 | 0.12.0 | | | **Finish an epic's repo item with a bullet under its repo's `CHANGELOG.md` → `## Unreleased`, or with none where the repo's plan is in Jira.** | 1 | 1 | 1 | 1 | 2 | 1 by 5 | 2.1 |
|
||||
| 420 | 0.12.0 | | | **End a worker that printed its final result and lingers, by killing the background shells it left, after a few minutes, and print each kill with its evidence on loop-claude's terminal.** | 2 | 2 | 2 | 4 | 3 | 1.5 by 6 | 2.0 |
|
||||
| 412 | 0.12.0 | | | **Print each chunk of an epic, running, parked with its gate and since when, or stopped, each human task and each open interrupt with `do-epic <key> --status`, and name a parked chunk's gate in its tmux window's name.** | 2 | 1 | 1 | 2 | 3 | 1 by 5 | 1.9 |
|
||||
| 414 | 0.12.0 | | | **DM the human through the notifier when a human-task issue blocks the epic's next item, and poll until it closes.** | 2 | 2 | 2 | 4 | 3 | 1 by 5 | 1.9 |
|
||||
| 417 | 0.12.0 | | | **Run do-epic end to end against a sandbox epic on a real Jira site with a command of its own, outside `run-tests`.** | 2 | 1 | 1 | 2 | 3 | 1 by 5 | 1.9 |
|
||||
| 440 | 0.12.0 | | | **End the shell that the interrupt test of `mutate-changes` starts within a minute, so a mutation run of this repo never waits on it for ever.** | 1 | 1 | 2 | 2 | 2 | 1 by 4 | 1.7 |
|
||||
@@ -97,15 +96,6 @@ Touches:
|
||||
- `bin/loop_claude/loop/lingering_workers.py`
|
||||
- `README.md`: `## Tools` (small)
|
||||
|
||||
### 412. Print each chunk of an epic, running, parked with its gate and since when, or stopped, each human task and each open interrupt with `do-epic <key> --status`, and name a parked chunk's gate in its tmux window's name.
|
||||
|
||||
A plain `do-epic <key>` resumes all of them, as after a reboot (`docs/decisions.md` → `do-epic: drives one Jira epic …`). The window suffix generalises the interrupt's " ?".
|
||||
|
||||
Touches:
|
||||
|
||||
- `bin/agent_cycle/tmux.py`: `WAITS`, `mark` (small)
|
||||
- `bin/do_epic/status.py`
|
||||
|
||||
### 414. DM the human through the notifier when a human-task issue blocks the epic's next item, and poll until it closes.
|
||||
|
||||
do-epic leaves the issue as the team filed it (`docs/decisions.md` → `do-epic: drives one Jira epic …`).
|
||||
|
||||
Reference in New Issue
Block a user