Answer stability round 1: 0 🔴, 5 🟡 (1 misread); start chunks after a partial planning and keep what planning wrote
This commit is contained in:
+52
-28
@@ -1,8 +1,10 @@
|
||||
"""What `do-epic <EPIC-KEY>` settles before it starts chunks: where each open issue is worked, and the order the loop's issues come in (docs/decisions.md → `do-epic: drives one Jira epic …`).
|
||||
|
||||
An open child issue that no label places is first split by repo (`split`), and where it changes one repo or none, its repo is picked (`repo_pick`). Each is a headless claude call on `repoless-model`'s rung of the shipped ladder. Where the repo rule leaves a pick unclear, the human answers on the terminal. Then the loop's issues are scored and Jira's backlog re-ranked to match (`ranking`).
|
||||
An open child issue that no label places is first split by repo (`split`), and where it changes one repo or none, its repo is picked (`repo_pick`). Each is a headless claude call on `repoless-model`'s rung of the shipped ladder. Where the repo rule leaves a pick unclear, the human answers on the terminal. Then the issues do-epic filed are scored and Jira's backlog re-ranked to match (`ranking`).
|
||||
|
||||
Only the do-epic the human runs plans. A chunk that finishes starts the next chunks from the labels and the order it finds, so no window waits on a question."""
|
||||
Planning runs only in the `do-epic <EPIC-KEY>` the human starts. A chunk that finishes starts the next chunks from the labels and the order it finds, so no window waits on a question.
|
||||
|
||||
Planning holds no lock: one `do-epic <EPIC-KEY>` at a time is assumed. A second one started meanwhile finds the sub-tasks the first filed, since `split` reads them before it files, unless Jira's search lags."""
|
||||
import dataclasses
|
||||
import pathlib
|
||||
import re
|
||||
@@ -39,29 +41,41 @@ class Planned:
|
||||
effects: Effects
|
||||
|
||||
|
||||
def planned(epic: Planned, issues: list[EpicIssue]) -> list[EpicIssue] | Failure | Limited:
|
||||
"""The epic's issues, read again after each open child issue that no label placed was split or got its pick, and the loop's issues were re-ranked. issues are the epic's, as just read. A Failure or a Limited says why the epic isn't planned; what was labelled, filed or ranked before it stays."""
|
||||
def planned(epic: Planned, issues: list[EpicIssue]) -> tuple[list[EpicIssue], Failure | Limited | None]:
|
||||
"""The epic's issues as far as they are planned, and why the planning stopped early, None where it didn't. issues are the epic's, as just read.
|
||||
|
||||
Each open child issue that no label places is split or gets its pick. Then the issues do-epic filed are re-ranked. What was labelled, filed or ranked before a Failure or a Limited stays, and the issues returned show it."""
|
||||
unplaced = [issue for issue in issues if issue.parent == epic.key and not issue.done and split.SPLIT_LABEL not in issue.labels and repo_pick.recorded(issue) is None]
|
||||
if unplaced:
|
||||
stopped = placed(epic, issues, unplaced)
|
||||
if stopped is not None:
|
||||
return stopped
|
||||
added: dict[str, str] = {}
|
||||
stopped = placed(epic, issues, unplaced, added) if unplaced else None
|
||||
if added:
|
||||
read = epic.store.read()
|
||||
if isinstance(read, Failure):
|
||||
return read
|
||||
issues = read
|
||||
# A search may not show a label added a moment ago, so each label added here counts whatever the read says. A sub-task the search doesn't show yet starts on the next run.
|
||||
issues = [labelled(each, added.get(each.key)) for each in (issues if isinstance(read, Failure) else read)]
|
||||
stopped = stopped or (read if isinstance(read, Failure) else None)
|
||||
if stopped is not None:
|
||||
return issues, stopped
|
||||
order = ranked_keys(epic, issues)
|
||||
if isinstance(order, Failure):
|
||||
return order
|
||||
return issues, order
|
||||
if [issue.key for issue in issues if issue.key in order] == order:
|
||||
return issues
|
||||
say(f"re-ranking the loop's issues in {epic.key}'s backlog", epic.effects, stdout=True)
|
||||
return issues, None
|
||||
say(f"re-ranking the issues do-epic filed in {epic.key}'s backlog", epic.effects, stdout=True)
|
||||
refused = ranking.reranked(epic.store, order)
|
||||
return refused or epic.store.read()
|
||||
if refused:
|
||||
return issues, refused
|
||||
# A search may not show the new order yet, so the issues are put in it here, as `reranked` put them in Jira: each ranked issue in a position a ranked issue held.
|
||||
by_key, ranked = {issue.key: issue for issue in issues}, iter(order)
|
||||
return [by_key[next(ranked)] if issue.key in order else issue for issue in issues], None
|
||||
|
||||
|
||||
def placed(epic: Planned, issues: list[EpicIssue], unplaced: list[EpicIssue]) -> None | Failure | Limited:
|
||||
"""Splits each of unplaced by repo, or labels it with its pick. An issue that claude or the tracker fails on is named and left for the next run, as is one whose question the human doesn't answer; a usage limit ends the planning."""
|
||||
def labelled(issue: EpicIssue, label: str | None) -> EpicIssue:
|
||||
"""issue with label among its labels; issue itself where label is None."""
|
||||
return issue if label is None or label in issue.labels else dataclasses.replace(issue, labels=tuple(sorted((*issue.labels, label))))
|
||||
|
||||
|
||||
def placed(epic: Planned, issues: list[EpicIssue], unplaced: list[EpicIssue], added: dict[str, str]) -> None | Failure | Limited:
|
||||
"""Splits each of unplaced by repo, or labels it with its pick, and notes in added the label each got, by its key. An issue that claude or the tracker fails on is named and left for the next run, as is one whose question the human doesn't answer; a usage limit ends the planning."""
|
||||
rung = planning_rung(epic.config.repoless_model)
|
||||
language = epic.record.language()
|
||||
# Claude reads every repo a label of the epic names, a finished issue's too, to predict which of them an issue changes.
|
||||
@@ -76,6 +90,7 @@ def placed(epic: Planned, issues: list[EpicIssue], unplaced: list[EpicIssue]) ->
|
||||
say(f"planning {issue.key}", epic.effects, stdout=True)
|
||||
parts = split.split(epic.store, issue, not issue.by_loop, epic.config.repo_rule, language or epic.config.language, checkouts, rung, epic.effects.claude, str(folder))
|
||||
if isinstance(parts, split.Split) and parts.repos:
|
||||
added[issue.key] = split.SPLIT_LABEL
|
||||
say(f"{issue.key} is split into a sub-task for each of {', '.join(parts.repos)}", epic.effects, stdout=True)
|
||||
continue
|
||||
pick: repo_pick.Pick | repo_pick.Unclear | Failure | Limited | None = parts if not isinstance(parts, split.Split) else repo_pick.picked(epic.store, issue, epic.config.repo_rule, rung, epic.effects.claude, str(folder))
|
||||
@@ -86,7 +101,8 @@ def placed(epic: Planned, issues: list[EpicIssue], unplaced: list[EpicIssue]) ->
|
||||
if isinstance(pick, Failure):
|
||||
say(f"{issue.key} is not planned: {pick.reason}", epic.effects, stdout=True)
|
||||
elif pick is not None and not isinstance(pick, repo_pick.Unclear):
|
||||
say(f"{issue.key} is labelled {repo_pick.label_of(pick)}", epic.effects, stdout=True)
|
||||
added[issue.key] = repo_pick.label_of(pick)
|
||||
say(f"{issue.key} is labelled {added[issue.key]}", epic.effects, stdout=True)
|
||||
return None
|
||||
|
||||
|
||||
@@ -100,20 +116,26 @@ def planning_rung(model: str) -> Rung | Failure:
|
||||
|
||||
|
||||
def answered(epic: Planned, issue: EpicIssue, question: str) -> repo_pick.Pick | None | Failure:
|
||||
"""The pick the human types for an issue the repo rule leaves unclear, once it is recorded; None where nobody is at a terminal to answer, so the issue waits for the next run. The answer is the label to give the issue, so that it is spelt as a person would spell it in Jira."""
|
||||
"""The pick the human types for an issue the repo rule leaves unclear, once it is recorded; None where nobody is at a terminal to answer, or the human answers with Enter alone, so the issue waits for the next run. The answer is the label to give the issue, so that it is spelt as a person would spell it in Jira.
|
||||
|
||||
A repo's name is not checked against the repos do-epic knows: an epic's first issue in a repo names one it has not seen."""
|
||||
if not epic.effects.on_terminal():
|
||||
say(f"{issue.key} waits for your answer: {question} Run `do-epic {epic.key}` on a terminal to answer, or label the issue in Jira.", epic.effects, stdout=True)
|
||||
return None
|
||||
say(f"\n{issue.key}, {issue.summary}: {question}", epic.effects)
|
||||
while True:
|
||||
try:
|
||||
typed = epic.effects.input(f"The label that says where {issue.key} is worked, `{repo_pick.REPO_PREFIX}<name>`, `{repo_pick.CLAUDE_LABEL}` or `{repo_pick.HUMAN_LABEL}`: ")
|
||||
typed = epic.effects.input(f"The label that says where {issue.key} is worked, `{repo_pick.REPO_PREFIX}<name>`, `{repo_pick.CLAUDE_LABEL}` or `{repo_pick.HUMAN_LABEL}`, or Enter alone to leave it waiting: ")
|
||||
except EOFError:
|
||||
return None
|
||||
pick = repo_pick.of_label(typed.strip())
|
||||
label = typed.strip()
|
||||
if not label:
|
||||
return None
|
||||
pick = repo_pick.of_label(label)
|
||||
if pick is not None:
|
||||
return repo_pick.record(epic.store, issue, pick)
|
||||
say(f"`{typed.strip()}` is none of those labels", epic.effects)
|
||||
named = f"; the repo {label}'s label is `{repo_pick.REPO_PREFIX}{label}`" if repo_pick.of_label(repo_pick.REPO_PREFIX + label) else ""
|
||||
say(f"`{label}` is none of those labels{named}", epic.effects)
|
||||
|
||||
|
||||
def located(epic: Planned, picks: list[repo_pick.Repo]) -> dict[str, repos.Located] | Failure:
|
||||
@@ -128,21 +150,23 @@ def located(epic: Planned, picks: list[repo_pick.Repo]) -> dict[str, repos.Locat
|
||||
|
||||
|
||||
def ranked_keys(epic: Planned, issues: list[EpicIssue]) -> list[str] | Failure:
|
||||
"""The keys of the loop's open child issues that hold scores, in the order ranking gives them; empty where fewer than two do, since one issue has no order. Every other issue keeps its position, as a person's does: an issue nobody scored, one labelled with two picks, and an item split by repo, which has no one repo whose goals to score it by."""
|
||||
ours = [issue for issue in issues if issue.parent == epic.key and issue.by_loop and not issue.done and split.SPLIT_LABEL not in issue.labels and not isinstance(repo_pick.recorded(issue), Failure) and not ranking.unscored(item_of(issue, {}), issue.key)]
|
||||
"""The keys of the open child issues do-epic filed that hold scores and one pick, in the order ranking gives them; empty where fewer than two do, since one issue has no order.
|
||||
|
||||
Every other issue keeps its position: a person's issue, one nobody scored, one with no pick yet or with two, and an item split by repo, since several repos' goals would score it."""
|
||||
ours = [issue for issue in issues if issue.parent == epic.key and issue.by_loop and not issue.done and split.SPLIT_LABEL not in issue.labels and (pick := repo_pick.recorded(issue)) is not None and not isinstance(pick, Failure) and not ranking.unscored(item_of(issue, {}), issue.key)]
|
||||
if len(ours) < 2:
|
||||
return []
|
||||
numbers = {issue.key: number(issue.key) for issue in ours}
|
||||
keys = {id_: key for key, id_ in numbers.items()}
|
||||
if len(keys) < len(numbers):
|
||||
return Failure(f"two of the loop's issues in the epic {epic.key} share a number in different Jira projects, so they cannot be ranked; move one of them")
|
||||
if clash := next(((key, keys[id_]) for key, id_ in numbers.items() if keys[id_] != key), None):
|
||||
return Failure(f"{clash[0]} and {clash[1]} share a number in different Jira projects, so the issues do-epic filed in the epic {epic.key} cannot be ranked; move one of the two to the other's Jira project")
|
||||
scoring, goals = epic.record.section("Scoring"), epic.record.section("Goals")
|
||||
if failed := next((each for each in (scoring, goals) if isinstance(each, Failure)), None):
|
||||
return Failure(f"the epic {epic.key}'s description: {failed.reason}")
|
||||
assert isinstance(scoring, str) and isinstance(goals, str)
|
||||
formulas = FORMULA.findall(scoring)
|
||||
if len(formulas) != 1:
|
||||
return Failure(f"the epic {epic.key}'s description states `Score = ...` {len(formulas)} times under ## Scoring; state the formula that ranks its issues once, on a line of its own, such as `Score = 100 * V / (2**S + 32)`")
|
||||
return Failure(f"the epic {epic.key}'s description states `Score = ...` {len(formulas)} times under ## Scoring; state the formula that ranks its issues once, on a line of its own and inside backticks, such as `Score = 100 * V / (2**S + 32)`")
|
||||
picks = {issue.key: repo_pick.recorded(issue) for issue in ours}
|
||||
places = located(epic, [pick for pick in picks.values() if isinstance(pick, repo_pick.Repo)])
|
||||
if isinstance(places, Failure):
|
||||
@@ -159,5 +183,5 @@ def ranked_keys(epic: Planned, issues: list[EpicIssue]) -> list[str] | Failure:
|
||||
|
||||
|
||||
def item_of(issue: EpicIssue, numbers: dict[str, int]) -> Item:
|
||||
"""The issue as ranking scores it, blocked by each of its blockers among numbers, the issues ranked with it by key."""
|
||||
"""The issue as ranking scores it. numbers holds the number of each issue ranked with it, by key; the item is blocked by those of them that block the issue."""
|
||||
return Item(numbers.get(issue.key, 0), NO_RELEASE, issue.exempt, issue.summary, issue.scores, issue.moves, tuple(sorted(numbers[key] for key in issue.blockers if key in numbers)))
|
||||
|
||||
Reference in New Issue
Block a user