Files
claude-config/bin/do_epic/human_tasks.py
T

42 lines
2.1 KiB
Python

"""A human's task that holds up other issues of an epic (docs/decisions.md → `do-epic: drives one Jira epic …`, "Human tasks").
do-epic leaves the issue as the team filed it. While it is open and blocks an open issue, its window DMs the human once, shows itself as parked so that it takes no running slot, and reads the epic every `poll` seconds. Once the issue is closed, or blocks nothing any more, the window ends, and the chunks it held up may start. A window that starts again, as after a reboot, DMs again."""
from loop_effects.effects import Effects, say
from do_epic.backend.protocol import EpicIssue, EpicStore
from failure import Failure
from do_epic import scheduler
from agent_cycle.direct_message import tell
from agent_cycle import tmux
# What the window of a human's task awaits, in its name.
AWAITS = "a human's task"
def holds_up(key: str, issues: list[EpicIssue]) -> list[str]:
"""The keys of the open issues that the human's task called key holds up; none where it is no such task, or is closed."""
if not any(chunk.human and chunk.issue == key for chunk in scheduler.chunks(issues)[0]):
return []
return scheduler.held_up(issues)[key]
def message(task: EpicIssue, epic: str, held: list[str]) -> str:
return f"do-epic {epic} awaits you: {task.key}, \"{task.summary}\", blocks {' and '.join(held)}. It goes on once you close {task.key} in Jira."
def awaited(task: EpicIssue, epic: str, store: EpicStore, window: tmux.Window, poll: int, effects: Effects) -> None:
"""Waits in window for the human to close the human's task `task` of the epic called epic, and returns once it holds up no issue. A read of the epic that fails is said once and tried again."""
told, said = False, None
while True:
issues = store.read()
if isinstance(issues, Failure):
if issues.reason != said:
say(f"cannot read the epic, so cannot tell whether {task.key} is closed; trying again every {poll} seconds: {issues.reason}", effects, stdout=True)
said = issues.reason
elif not (held := holds_up(task.key, issues)):
return
elif not told:
tell(message(task, epic, held), effects)
tmux.park(window, AWAITS, effects.tmux)
told = True
effects.sleep(poll)