diff --git a/README.md b/README.md index 7515b10d..d0205e4c 100644 --- a/README.md +++ b/README.md @@ -216,7 +216,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a - `branch_chunks/` cuts a default branch into chunks and finds, for each, the items it shipped and the later chunks that fixed its code, for `score_outcomes` and `routing_figures`. It imports `reading_cost`'s record path. - `command_lines/` reads a shell command: its simple commands, and a docker call's subcommand and memory limits, for `command_patterns`, `reading_cost`, `routing_figures`, `rule_hook` and `run_heavy`. - `deploy_release` imports `release_plan`'s `release_standing`. -- `do_epic/` holds `do-epic`, the tool that drives one Jira epic. `main.py` starts the epic's chunks and runs one chunk's cycles in its window, through `agent_cycle`. `scheduler.py` says which issues run now: as many as the epic's cap and each repo's `parallel-chunks` allow, and none in a repo where loop-claude runs chunks. Beside it, `chunk_prompt.py` words what a chunk's worker reads. `findings.py` is what that worker writes into the epic: `do-epic --file` files a finding as an issue of the epic, and `--record-decision` appends a decision to its description. `config.py` reads its machine-wide settings, importing `project_config`'s settings and `model_routing`'s ladder file, and `epic_record.py` reads and writes an epic's description by section, language line and cap line, through `record_store`'s `EpicDescription`. `repos.py` finds a repo's checkout and project config by its name, and clones a missing checkout from the host and owner of the epic's other repos, through `forge`'s `url_beside`. `repo_pick.py` asks claude, by `repo-rule.md`, where an epic item is worked, and records the answer as a label on the issue. `split.py` has claude predict from the code which repos an item changes, and files a sub-task per repo under it where there are several. `ranking.py` orders an epic's items by score over one chain of goals, the epic's, then code health, then the item's repo's, through `plan`'s ranking, and re-ranks the tracker's backlog to that order through `backend/`. `backend/` reads, files and ranks the epic's issues, adds the labels `repo_pick.py` and `split.py` record, and posts comments. +- `do_epic/` holds `do-epic`, the tool that drives one Jira epic. `main.py` starts the epic's chunks and runs one chunk's cycles in its window, through `agent_cycle`. `scheduler.py` says which issues run now: as many as the epic's cap and each repo's `parallel-chunks` allow, and none in a repo where loop-claude runs chunks. Beside it, `chunk_prompt.py` words what a chunk's worker reads. Through `findings.py` that worker files a finding as an issue of the epic, with `--file`, and appends a decision to its description, with `--record-decision`. `config.py` reads its machine-wide settings, importing `project_config`'s settings and `model_routing`'s ladder file, and `epic_record.py` reads and writes an epic's description by section, language line and cap line, through `record_store`'s `EpicDescription`. `repos.py` finds a repo's checkout and project config by its name, and clones a missing checkout from the host and owner of the epic's other repos, through `forge`'s `url_beside`. `repo_pick.py` asks claude, by `repo-rule.md`, where an epic item is worked, and records the answer as a label on the issue. `split.py` has claude predict from the code which repos an item changes, and files a sub-task per repo under it where there are several. `ranking.py` orders an epic's items by score over one chain of goals, the epic's, then code health, then the item's repo's, through `plan`'s ranking, and re-ranks the tracker's backlog to that order through `backend/`. `backend/` reads, files and ranks the epic's issues, adds the labels `repo_pick.py` and `split.py` record, and posts comments. - `forge/` tells a GitHub origin from a Gitea one, names a repo beside an origin's and runs that forge's CLI (`commands.py`), and finds a pull request and waits for its checks (`pulls.py`), for `chunk_preflight`, `chunk_pr`, `deploy_release`, `do_epic` and `larv_review`. - `git_cli/` runs git for every tool (`git_repo.py`), and reads the git calls in a shell command (`git_command.py`). - `judge_replay` imports `agent_cycle`'s judge and verdicts, and `loop_claude`'s premises, records and `ANSWER_DESTINATIONS`. diff --git a/bin/do_epic/chunk_prompt.py b/bin/do_epic/chunk_prompt.py index f2128c06..c5aa911b 100644 --- a/bin/do_epic/chunk_prompt.py +++ b/bin/do_epic/chunk_prompt.py @@ -3,6 +3,7 @@ from do_epic.backend.protocol import EpicIssue from do_epic import findings from loop_claude.project.records import HUMAN_RULE_NAMES, RECORD_FILES from text_files.markdown_text import listed +import pathlib from model_routing.ladder import ProjectRung from loop_claude.cycle import prompts from model_routing.route import Route @@ -11,10 +12,10 @@ from model_routing.route import Route DRIVER = "do-epic" -def task(issue: EpicIssue, epic: str, checkout: str | None) -> str: - """The task of the chunk that works issue, of the epic with the key epic: in checkout, or without a repo where it is None.""" +def task(issue: EpicIssue, epic: str, checkout: str | None, launcher: pathlib.Path, language: str) -> str: + """The task of the chunk that works issue, of the epic with the key epic: in checkout, or without a repo where it is None. launcher is the do-epic that runs the chunk, and language the one the epic's Jira text is in.""" where = f"in the checkout {checkout}, on the branch {issue.key}" if checkout else "which changes no repo: work in the folder you start in" - return f"Work the Jira issue {issue.key} of the epic {epic} as one chunk, {where}. {findings.instructions(epic)} Its summary: {issue.summary}" + (f"\n\nIts description:\n\n{issue.detail}" if issue.detail else "") + return f"Work the Jira issue {issue.key} of the epic {epic} as one chunk, {where}. {findings.instructions(epic, launcher, language)} Its summary: {issue.summary}" + (f"\n\nIts description:\n\n{issue.detail}" if issue.detail else "") CODE_HEALTH = '~/.claude/CLAUDE.md → "Shared goal"' @@ -28,7 +29,7 @@ def fresh(task: str, premises: str, route: Route, project: ProjectRung | None, f # The worker names no plan items: the chunk's one item is its issue. -# The epic's records come first, as its goals do; a chunk without a repo has only those and the human's rules. +# The epic's records come first, as its goals do; a chunk without a repo is handed only those and the human's rules, so the names that mention a repo's then name nothing it reads. NAMES = prompts.RecordNames( quote_sources=listed(("the epic's description", "the repo's goals file's Goals and Audience", *RECORD_FILES, *HUMAN_RULE_NAMES), "or"), answer_destinations="the epic's description under ## Decisions, the repo's goals file's Goals or Audience, " + ", ".join(RECORD_FILES) + ", the repo's plan or a comment", diff --git a/bin/do_epic/epic_record.py b/bin/do_epic/epic_record.py index 2e8b5490..736e1bc8 100644 --- a/bin/do_epic/epic_record.py +++ b/bin/do_epic/epic_record.py @@ -89,6 +89,19 @@ def with_language(text: str, language: str) -> str | Failure: return line + "\n" + "\n" * bool(text.strip()) + text +def decision_titled(decisions: str, title: str) -> str | None: + """The entry under the ### title heading of decisions, a ## Decisions section's body; None where it has no such heading.""" + found: list[str] | None = None + for line, fenced in fenced_lines(decisions): + if not fenced and line.startswith("### "): + if found is not None: + break + found = [] if line[4:].strip() == title else None + elif found is not None: + found.append(line) + return None if found is None else "\n".join(found).strip() + + @dataclasses.dataclass(frozen=True) class EpicRecord: """One epic's record, kept in its description.""" @@ -110,18 +123,27 @@ class EpicRecord: """Writes body as the ## name section. approved says the human approved the change in an interrupt, which Goals and Audience need.""" return self.written(lambda text: with_section(text, name, body), frozenset({name}) if approved else frozenset()) - def append_decision(self, title: str, entry: str) -> Held | Failure: - """Adds entry under a ### title heading at the end of ## Decisions, leaving the decisions before it as they are.""" - if not title.strip() or "\n" in title: + def append_decision(self, title: str, entry: str) -> bool | Failure: + """Adds entry under a ### title heading at the end of ## Decisions, leaving the decisions before it as they are. False where the section already holds that entry under that title, so recording a decision twice keeps one; a Failure where it holds another entry under it, so one title names one decision.""" + title, entry = title.strip(), entry.strip() + if not title or "\n" in title: return Failure("the title must be one line of text") - if not entry.strip(): + if not entry: return Failure("pipe the decision's text in") - - def appended(text: str) -> str | Failure: - before = read_section(text, "Decisions") - return before if isinstance(before, Failure) else with_section(text, "Decisions", f"{before}\n\n### {title.strip()}\n\n{entry.strip()}".strip()) - - return self.written(appended, frozenset()) + held = self.description.held() + if isinstance(held, Failure): + return held + before = read_section(held.text, "Decisions") + if isinstance(before, Failure): + return before + same = decision_titled(before, title) + if same is not None: + return False if same == entry else Failure(f"## Decisions already holds another decision titled {title!r}: give this one a title of its own") + text = with_section(held.text, "Decisions", f"{before}\n\n### {title}\n\n{entry}".strip()) + if isinstance(text, Failure): + return text + wrote = dataclasses.replace(self.description, approved=frozenset()).write(text, held.version) + return wrote if isinstance(wrote, Failure) else True def write_language(self, language: str) -> Held | Failure: return self.written(lambda text: with_language(text, language), frozenset()) diff --git a/bin/do_epic/findings.py b/bin/do_epic/findings.py index d15cc7db..9985adc9 100644 --- a/bin/do_epic/findings.py +++ b/bin/do_epic/findings.py @@ -1,36 +1,56 @@ """What a chunk's worker writes into its epic: a finding, filed as an issue, and a decision, appended to the description. A finding about one of the epic's goals is filed in the epic, and one about a repo's goals by that repo's rules (docs/decisions.md → `do-epic: drives one Jira epic …` → "Findings"). A decision that governs the epic goes under the description's ## Decisions, where the judge of each later chunk reads it.""" +import contextlib +import fcntl +import pathlib import typing -from do_epic.backend.protocol import EpicStore +from do_epic.repo_pick import CLAUDE_LABEL, HUMAN_LABEL, of_label, REPO_PREFIX from do_epic.epic_record import EpicRecord +from do_epic.backend.protocol import EpicStore from failure import Failure from text_files.piped_text import piped -# Three readers, seated as the human and as a chunk's worker, ranked four spellings of each flag: ` --file` came first, second and second, ahead of `--file `, `add` and `--finding`; `--record-decision` won 2-1 over `--decision`, since `--decide` reads as do-epic deciding. +# Three readers, seated as the human and as a chunk's worker, picked each spelling from four: ` --file` over `--file `, `add` and `--finding`, and `--record-decision` over `--decision` and `--decide`. FILE = "--file" LABEL = "--label" RECORD_DECISION = "--record-decision" +# The labels that say where an issue is worked, as do-epic's scheduler reads them. +LABELS = f"`{REPO_PREFIX}` for the repo that works it, `{CLAUDE_LABEL}` for work of Claude's that changes no repo, or `{HUMAN_LABEL}` for a task of the human's" +# Under the epic's folder, the file a do-epic holds locked while it appends a decision. +DECISIONS_LOCK = "decisions.lock" USAGE = f"""do-epic {FILE} [{LABEL}