DM the human when a human-task issue blocks the epic's next item, and poll until it closes
This commit is contained in:
@@ -19,6 +19,8 @@ from agent_cycle import tmux
|
||||
|
||||
# Under the home folder, a folder per epic key holds the epic's LOCK. A chunk without a repo works there.
|
||||
STATE = ".local/state/do-epic"
|
||||
# Why a human's task with a live window waits, as the epic's status says.
|
||||
HUMAN_WAIT = "it is a human's task; do-epic polls until its issue closes"
|
||||
# The flag that tells the do-epic in a window its chunk, as `--chunk ABC-34 ABC-12`. Nobody types it, so no panel picked it.
|
||||
CHUNK_FLAG = "--chunk"
|
||||
|
||||
@@ -29,6 +31,8 @@ class Chunk:
|
||||
issue: str
|
||||
# The name of the repo it changes; None for work without a repo.
|
||||
repo: str | None
|
||||
# Whether it is a human's task that holds up another open issue: its window only waits for the human to close the issue (`human_tasks`), and takes no running slot.
|
||||
human: bool = False
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -76,22 +80,41 @@ class Epic:
|
||||
return self.home / STATE / self.key
|
||||
|
||||
|
||||
def chunks(issues: list[EpicIssue]) -> tuple[list[Chunk], list[Waits]]:
|
||||
"""The open issues to work as chunks, in the tracker's rank order, and those that wait. An item split by repo is worked through its sub-tasks, and what blocks it blocks them. A blocker outside the epic blocks until the human removes the link, since its state is unknown."""
|
||||
def open_blockers(issue: EpicIssue, by_key: dict[str, EpicIssue]) -> list[str]:
|
||||
"""The keys of the issues that block issue, or its parent, that are not done. A blocker outside the epic counts, since its state is unknown."""
|
||||
parent = by_key.get(issue.parent)
|
||||
return [key for key in (*issue.blockers, *(parent.blockers if parent else ())) if key not in by_key or not by_key[key].done]
|
||||
|
||||
|
||||
def held_up(issues: list[EpicIssue]) -> dict[str, list[str]]:
|
||||
"""For each issue that blocks an open issue to work as a chunk, the keys of the open issues it blocks, in the tracker's rank order."""
|
||||
by_key = {issue.key: issue for issue in issues}
|
||||
held: dict[str, list[str]] = {}
|
||||
for issue in issues:
|
||||
if not issue.done and SPLIT_LABEL not in issue.labels:
|
||||
for key in open_blockers(issue, by_key):
|
||||
held.setdefault(key, []).append(issue.key)
|
||||
return held
|
||||
|
||||
|
||||
def chunks(issues: list[EpicIssue]) -> tuple[list[Chunk], list[Waits]]:
|
||||
"""The open issues to work as chunks, in the tracker's rank order, and those that wait. An item split by repo is worked through its sub-tasks, and what blocks it blocks them. A blocker outside the epic blocks until the human removes the link, since its state is unknown. A human's task is a chunk only while it holds up another issue and nothing holds it up: its window waits for the human."""
|
||||
by_key = {issue.key: issue for issue in issues}
|
||||
holding = held_up(issues)
|
||||
found: list[Chunk] = []
|
||||
waits: list[Waits] = []
|
||||
for issue in issues:
|
||||
if issue.done or SPLIT_LABEL in issue.labels:
|
||||
continue
|
||||
pick = recorded(issue)
|
||||
parent = by_key.get(issue.parent)
|
||||
blocking = [key for key in (*issue.blockers, *(parent.blockers if parent else ())) if key not in by_key or not by_key[key].done]
|
||||
blocking = open_blockers(issue, by_key)
|
||||
outside = [key for key in blocking if key not in by_key]
|
||||
if isinstance(pick, Failure):
|
||||
waits.append(Waits(issue.key, pick.reason))
|
||||
elif pick is None:
|
||||
waits.append(Waits(issue.key, "no label names its repo"))
|
||||
elif isinstance(pick, HumanTask) and not blocking and issue.key in holding:
|
||||
found.append(Chunk(issue.key, None, human=True))
|
||||
elif isinstance(pick, HumanTask):
|
||||
waits.append(Waits(issue.key, "it is a human's task"))
|
||||
elif blocking:
|
||||
@@ -131,11 +154,14 @@ def start_chunks(epic: Epic, issues: list[EpicIssue], finishing: bool, own: str
|
||||
for chunk in found:
|
||||
if chunk.issue in running or chunk.issue == own:
|
||||
continue
|
||||
if chunk.issue in parked and chunk.issue in live:
|
||||
slot = chunk.issue not in parked and not chunk.human
|
||||
if chunk.human and chunk.issue in live:
|
||||
waits.append(Waits(chunk.issue, HUMAN_WAIT))
|
||||
elif chunk.issue in parked and chunk.issue in live:
|
||||
waits.append(Waits(chunk.issue, parked[chunk.issue].waits(live[chunk.issue].awaits)))
|
||||
elif own and (chunk.issue in stopped or chunk.issue in parked):
|
||||
waits.append(Waits(chunk.issue, f"its window stopped; run `do-epic {epic.key}` to start it again"))
|
||||
elif chunk.issue not in parked and len(running) + taken >= epic.cap:
|
||||
elif slot and len(running) + taken >= epic.cap:
|
||||
waits.append(Waits(chunk.issue, f"the epic runs as many chunks as its `{CAP}` line allows: {epic.cap}"))
|
||||
else:
|
||||
now = start_chunk(epic, chunk if chunk.issue not in parked else Chunk(chunk.issue, None), own, windows, run)
|
||||
@@ -146,7 +172,7 @@ def start_chunks(epic: Epic, issues: list[EpicIssue], finishing: bool, own: str
|
||||
else:
|
||||
windows = now
|
||||
started.append(chunk.issue)
|
||||
taken += chunk.issue not in parked
|
||||
taken += slot
|
||||
except OSError as failure:
|
||||
return Failure(f"cannot lock {failure.filename or epic.folder / LOCK}: {failure.strerror}")
|
||||
# The epic's finishing is no issue: its wait is listed after every issue's.
|
||||
@@ -212,6 +238,8 @@ def status(key: str, home: pathlib.Path, issues: list[EpicIssue], run: tmux.Tmux
|
||||
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.human and chunk.issue in live:
|
||||
reasons[chunk.issue] = HUMAN_WAIT
|
||||
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]
|
||||
|
||||
Reference in New Issue
Block a user