diff --git a/CHANGELOG.md b/CHANGELOG.md index 6575311f..c6cff680 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- A chunk that `do-epic` runs files a finding about an epic goal as an issue of the epic, with `do-epic --file`, and records a decision in the epic's description, with `--record-decision`; its judge reads the epic's Scoring and Decisions before the repo's records. - Added `do-epic `: it runs the chunks of one Jira epic, each in its own window of the tmux session `epic-`. As many run at once as the line `**Max parallel chunks:** 2` in the epic's description allows, one without it; a repo takes as many as its `parallel-chunks`, and none while loop-claude runs chunks in it. loop-claude in turn starts no chunk in a checkout where do-epic runs one. - Refuse in rule-hook a Bash or Monitor command that waits forever: a sleeping loop with no time or count cap, and a `pgrep -f` or `pkill -f` whose pattern its own command line matches. - A project's config may list its team's convention files in `coding-conventions`, which larv-review's reviewer agents read beside the principles and the standards, the team's rule winning where they conflict. larv-review opens the pull request after its own review where a push to the branch starts CI, and files an item to add a mutation tool where `mutate-changes` covers none of a language. The technical principles gain rules for tests on a shared environment, "Never mock a service your own team runs" and "Don't loosen a type when refactoring"; stability-reviewer checks a change that stores a value differently; and every finding of an outside reviewer now changes the setup, a deterministic tool first. diff --git a/README.md b/README.md index 1da63f00..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. `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`. @@ -237,7 +237,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a - `routing_figures/` measures loop-claude's archive, and each of its projects' default branches, for loop-claude's routing calls. - `rung_replay/` holds what `judge_replay` and `review_replay` share: the parallel replay runner, the argument reader, the candidate rungs and the exits, and `judge_replay`'s rung search. It reads `agent_cycle`'s retry count and `loop_claude`'s models file, and finds that file through `loop_state`'s paths. Its `archive.py` keeps each replay's runs and its report in a `replays/` folder of loop-claude's archive. - `test_env.py` serves the tests. -- `text_files/` reads a Markdown file's `##` sections, quotes a passage and joins names into a list, stamps times in UTC, replaces a file in one step, private where it is new, and gzips a file beside its plain name, by which it reads it afterwards. +- `text_files/` reads a Markdown file's `##` sections, quotes a passage and joins names into a list, reads the text piped into a command, stamps times in UTC, replaces a file in one step, private where it is new, and gzips a file beside its plain name, by which it reads it afterwards. - `transcript_archive/` stores loop-claude's transcripts. Its `project_key.py` names each project's archive folder, loop-claude session and models-file entry. ## Test diff --git a/bin/agent_cycle/judge.py b/bin/agent_cycle/judge.py index 993ebf85..3591a649 100644 --- a/bin/agent_cycle/judge.py +++ b/bin/agent_cycle/judge.py @@ -141,6 +141,8 @@ class Brief(typing.NamedTuple): task: str premises: str records: str + # What the records are, in their order, as WorkerPrompts.records_named has it. + records_named: str # Where the worker may record an answer the human typed, as the entry point names it. answer_destinations: str entries: list[Entry] @@ -290,7 +292,7 @@ def judge_prompt(brief: Brief) -> tuple[str, Grounds]: """The prompt, and what the judge's quotes are checked against.""" head = ( f"From the goals file, {brief.premises}\n\n" - f"The records: the project's working rules and decisions, then the human's rules for every project:\n{brief.records or 'none'}\n\n" + f"The records: {brief.records_named}:\n{brief.records or 'none'}\n\n" f"{TASK_HEADING}{brief.task}\n\n" f"{transcript_heading(brief.driver)}" ) diff --git a/bin/agent_cycle/run.py b/bin/agent_cycle/run.py index 98bf2bf8..a836cb47 100644 --- a/bin/agent_cycle/run.py +++ b/bin/agent_cycle/run.py @@ -156,6 +156,7 @@ def rule(cycle: Cycle, transcript_path: str, quoted_answers: int) -> Ruled | Sto task=cycle.task, premises=cycle.premises, records=cycle.records, + records_named=cycle.prompts.records_named, answer_destinations=cycle.prompts.answer_destinations, entries=entries, escalated_at=cycle.route.escalated_at, diff --git a/bin/agent_cycle/worker_prompts.py b/bin/agent_cycle/worker_prompts.py index 25f9c931..9c070afb 100644 --- a/bin/agent_cycle/worker_prompts.py +++ b/bin/agent_cycle/worker_prompts.py @@ -45,6 +45,8 @@ class WorkerPrompts: quote_sources: str # Where the worker may record an answer the human typed. answer_destinations: str + # What the records the judge reads are, in the order it reads them. + records_named: str def answered(self, question: str, answer: str, route: Route, project: ProjectRung | None, stepped: bool) -> str: """stepped is whether the answer's ruling stepped the worker up.""" diff --git a/bin/do_epic/chunk_prompt.py b/bin/do_epic/chunk_prompt.py index 3de4876d..c5aa911b 100644 --- a/bin/do_epic/chunk_prompt.py +++ b/bin/do_epic/chunk_prompt.py @@ -1,5 +1,9 @@ """What a do-epic cycle's worker is told: its task, from the issue, and its first prompt. The resumed prompt and the rung sentences are the ones loop-claude's cycles use, naming do-epic.""" 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 @@ -8,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}. 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"' @@ -25,4 +29,10 @@ 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. -WORKER = prompts.worker_prompts(DRIVER, fresh, "") +# 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", + records_named="the epic's scoring and decisions, then the repo's working rules and decisions, then the human's rules for every project", +) +WORKER = prompts.worker_prompts(DRIVER, fresh, "", NAMES) diff --git a/bin/do_epic/epic_record.py b/bin/do_epic/epic_record.py index fb302034..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,6 +123,28 @@ 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) -> 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: + return Failure("pipe the decision's text in") + 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 new file mode 100644 index 00000000..9985adc9 --- /dev/null +++ b/bin/do_epic/findings.py @@ -0,0 +1,85 @@ +"""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.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, 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}