Read a team's own repo labels as do-epic's picks, and treat an item a person filed sub-tasks under as split
CI / tests (pull_request) Has been cancelled

This commit is contained in:
Lilleman
2026-11-19 15:33:51 +01:00
parent 017cf33611
commit 95535b4fb3
20 changed files with 278 additions and 119 deletions
+16 -9
View File
@@ -4,6 +4,7 @@ An item is worked in a repo, or has no repo and is either Claude's work, done wi
import dataclasses
import json
import re
import typing
from claude_code.reply import Claude, claude_reply, Limited
from do_epic.backend.protocol import EpicIssue, EpicStore
@@ -20,6 +21,9 @@ REVIEW_LABEL = "do-epic-release-review"
# A repo's name is a folder name and part of a clone address, so claude's answer or a label a person typed must not hold a slash, a colon or a leading dot.
REPO_NAME = re.compile(r"\w[\w.-]*")
# A team's own label for a repo, mapped to the repo's name: the `[label-repos]` table of do-epic's config (config.py). Three readers, seated as those who write and read that config, picked `label-repos` from four candidates, over `repo-aliases`, `repo-labels` and `team-labels`, 2-1; each would misread `repo-labels` as mapping a repo to its label.
LabelRepos = typing.Mapping[str, str]
PICK_SCHEMA = {
"type": "object",
"properties": {
@@ -61,15 +65,18 @@ def label_of(pick: Pick) -> str:
return f"{REPO_PREFIX}{pick.name}" if isinstance(pick, Repo) else CLAUDE_LABEL if isinstance(pick, ClaudeWork) else HUMAN_LABEL
def recorded(issue: EpicIssue) -> Pick | None | Failure:
"""The pick the issue's labels record; None where they record no pick, a Failure where they record more than one."""
picks = [pick for label in issue.labels if (pick := of_label(label)) is not None]
if len(picks) > 1:
return Failure(f"{issue.key} is labelled with {len(picks)} picks: {', '.join(label_of(pick) for pick in picks)}; remove all but the right one")
return picks[0] if picks else None
def recorded(issue: EpicIssue, team: LabelRepos) -> Pick | None | Failure:
"""The pick the issue's labels record; None where they record no pick, a Failure where they record more than one. Two labels that name one repo, such as the team's and `repo:<name>`, record one pick."""
picks = {label: pick for label in issue.labels if (pick := of_label(label, team)) is not None}
if len(set(picks.values())) > 1:
return Failure(f"{issue.key} is labelled with {len(picks)} picks: {', '.join(picks)}; remove all but the right one")
return next(iter(picks.values()), None)
def of_label(label: str) -> Pick | None:
def of_label(label: str, team: LabelRepos) -> Pick | None:
"""The pick the label records: one of do-epic's own, or one the team's table maps to a repo."""
if label in team:
return Repo(team[label])
if label == CLAUDE_LABEL:
return ClaudeWork()
if label == HUMAN_LABEL:
@@ -77,9 +84,9 @@ def of_label(label: str) -> Pick | None:
return Repo(label[len(REPO_PREFIX):]) if label.startswith(REPO_PREFIX) and REPO_NAME.fullmatch(label[len(REPO_PREFIX):]) else None
def picked(store: EpicStore, issue: EpicIssue, rule: str, rung: Rung, claude: Claude, cwd: str) -> Pick | Unclear | Failure | Limited:
def picked(store: EpicStore, issue: EpicIssue, team: LabelRepos, rule: str, rung: Rung, claude: Claude, cwd: str) -> Pick | Unclear | Failure | Limited:
"""The pick for a child issue of the epic: the one its labels record, else claude's by rule, recorded on the issue. An unclear pick is not recorded; the human's answer is, with record."""
known = recorded(issue)
known = recorded(issue, team)
if known is not None:
return known
reply = claude_reply(claude, ["--json-schema", json.dumps(PICK_SCHEMA), *rung.flags(), "--tools", ""], cwd, prompt(rule, issue), "the repo pick")