Merge remote-tracking branch 'origin/main' into item-411
CI / tests (pull_request) Has been cancelled
CI / tests (pull_request) Has been cancelled
# Conflicts: # README.md # bin/do_epic/chunk_prompt.py # bin/do_epic/main.py # bin/do_epic/test_main.py
This commit is contained in:
@@ -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 <EPIC-KEY> --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 <EPIC-KEY>`: it runs the chunks of one Jira epic, each in its own window of the tmux session `epic-<EPIC-KEY>`. 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.
|
||||
|
||||
@@ -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. `gates.py` reads once whether a chunk's pull request waits on its checks, an approval or a new review, and `parked.py` keeps each chunk that does in a state file, so it takes no running slot while it waits and goes on waiting after a reboot. `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. `gates.py` reads once whether a chunk's pull request waits on its checks, an approval or a new review, and `parked.py` keeps each chunk that does in a state file, so it takes no running slot while it waits and goes on waiting after a reboot. `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 reads its checks, once or until they settle (`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
|
||||
|
||||
@@ -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)}"
|
||||
)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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."""
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
import dataclasses
|
||||
|
||||
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 +15,10 @@ from agent_cycle.worker_prompts import WorkerPrompts
|
||||
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"'
|
||||
@@ -28,7 +32,13 @@ 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)
|
||||
|
||||
# What a worker does with a reviewer's feedback, as the decision asks (docs/decisions.md → `do-epic: drives one Jira epic …`, "Long gates").
|
||||
FEEDBACK = 'Where a reviewer left feedback, fix what is reasonable and push the fix, answer each other comment in its thread, and change the setup so our review would have caught the finding (~/.claude/CLAUDE.md → "Working loop", "Change the setup for each finding an outside reviewer raises on a PR, deterministic tools first"). Then merge the pull request as before.'
|
||||
|
||||
@@ -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())
|
||||
|
||||
|
||||
@@ -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: `<EPIC-KEY> --file` over `--file <EPIC-KEY>`, `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}<name>` 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 <EPIC-KEY> {FILE} <summary> [{LABEL} <label>] [<<'EOF' detail EOF]
|
||||
do-epic <EPIC-KEY> {RECORD_DECISION} <title> <<'EOF' entry EOF"""
|
||||
HELP = f"""{FILE} files a finding about one of the epic's goals as an open issue of the epic, with the markdown piped in as its description.
|
||||
{LABEL} is {LABELS}; without one the issue waits until someone labels it.
|
||||
A finding about a repo's own goals goes into that repo's plan instead.
|
||||
{RECORD_DECISION} appends a decision that governs the epic to its description's ## Decisions, under the title, with the markdown piped in as its text."""
|
||||
|
||||
|
||||
def instructions(epic: str, launcher: pathlib.Path, language: str) -> str:
|
||||
"""What a chunk's first prompt says about filing a finding and recording a decision in the epic with the key epic. launcher is the do-epic that runs the chunk, and language the one the epic's Jira text is in."""
|
||||
return (
|
||||
f"File a finding about one of the epic's goals in the epic, with `{launcher} {epic} {FILE} \"<summary>\" {LABEL} <label>` and its detail on stdin. "
|
||||
f"The label is {LABELS}; leave it out where you cannot tell, and the issue waits for the human. "
|
||||
"Where filing fails and says the issue may exist, ask the human to look before you file it again. "
|
||||
"File a finding about a repo's goals by that repo's rules. Where unsure which, ask the human. "
|
||||
f"Record a decision that governs the epic, such as an answer the human typed, with `{launcher} {epic} {RECORD_DECISION} \"<title>\"` and its text on stdin. "
|
||||
f"Write the issue and the decision in {language}, the epic's language."
|
||||
)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def decisions_locked(folder: pathlib.Path) -> typing.Iterator[None]:
|
||||
"""Holds the epic's DECISIONS_LOCK, in its folder, so two chunks that record a decision at once write one after the other. Raises OSError where the file cannot be made or locked."""
|
||||
folder.mkdir(parents=True, exist_ok=True)
|
||||
with open(folder / DECISIONS_LOCK, "w") as lock:
|
||||
fcntl.flock(lock, fcntl.LOCK_EX)
|
||||
yield
|
||||
|
||||
|
||||
def parsed(words: list[str]) -> tuple[str, str, str | None] | None:
|
||||
"""What the words after the epic's key ask for: the flag, the summary or title, and the label, None without one. None where they aren't spelt as USAGE has them. A word that opens with `--` is no summary, title or label."""
|
||||
if not words or words[0] not in (FILE, RECORD_DECISION):
|
||||
return None
|
||||
label: str | None = None
|
||||
rest = words[1:]
|
||||
if words[0] == FILE and LABEL in rest:
|
||||
at = rest.index(LABEL)
|
||||
if at + 1 >= len(rest):
|
||||
return None
|
||||
label, rest = rest[at + 1], rest[:at] + rest[at + 2:]
|
||||
if len(rest) != 1 or any(word.startswith("--") for word in (*rest, label or "")):
|
||||
return None
|
||||
return words[0], rest[0], label
|
||||
|
||||
|
||||
def written(epic: str, flag: str, value: str, label: str | None, store: EpicStore, record: EpicRecord, stdin: typing.TextIO, folder: pathlib.Path) -> str | Failure:
|
||||
"""Files the finding or records the decision, as flag says, and answers the line to print. folder is the epic's, where the lock for its decisions lies."""
|
||||
text = piped(stdin)
|
||||
if flag == FILE:
|
||||
if label and of_label(label) is None:
|
||||
return Failure(f"cannot file the finding in the epic {epic}: do-epic doesn't read the label {label!r}; write {LABELS}")
|
||||
key = store.file(epic, value, text, (label,) if label else ())
|
||||
if isinstance(key, Failure):
|
||||
return Failure(f"cannot file the finding in the epic {epic}: {key.reason}")
|
||||
return f"Filed {key} in the epic {epic}." + ("" if label else f" It waits until someone labels it: {LABELS}.")
|
||||
try:
|
||||
with decisions_locked(folder):
|
||||
added = record.append_decision(value, text)
|
||||
except OSError as failure:
|
||||
return Failure(f"cannot record the decision in the epic {epic}'s description: cannot lock {failure.filename or folder / DECISIONS_LOCK}: {failure.strerror}")
|
||||
if isinstance(added, Failure):
|
||||
return Failure(f"cannot record the decision in the epic {epic}'s description: {added.reason}")
|
||||
return f"Recorded the decision in the epic {epic}'s description." if added else f"The epic {epic}'s description already holds that decision."
|
||||
+38
-9
@@ -5,12 +5,14 @@
|
||||
After each cycle of a chunk in a repo, the window reads what the chunk's pull request waits on (`gates`). While that is a gate only time or a person passes, the chunk is parked (`parked`): the window frees its running slot and polls the forge, and the chunk's next cycle starts once the worker has something to do and a slot is free. `do-epic <EPIC-KEY> --status` prints what each open issue does."""
|
||||
import dataclasses
|
||||
import pathlib
|
||||
import sys
|
||||
import typing
|
||||
|
||||
from loop_claude.loop.chunk_start import archived_route, routed
|
||||
from do_epic import chunk_prompt, gates, parked, scheduler
|
||||
from do_epic import chunk_prompt, findings, gates, parked, scheduler
|
||||
from do_epic.repo_pick import ClaudeWork, HumanTask, recorded, Repo
|
||||
from loop_claude.loop.close import closed_cycle
|
||||
from loop_claude.project.records import CONSEQUENCE, read_records
|
||||
from agent_cycle.run import Cycle, run_cycle
|
||||
from do_epic.config import DoEpicConfig, load
|
||||
from loop_effects.effects import Effects, say
|
||||
@@ -31,7 +33,6 @@ from loop_state.paths import Paths
|
||||
from transcript_archive.project_key import project_key
|
||||
from model_routing.ladder_file import project_ladder_file, read_ladder, SHIPPED
|
||||
from loop_claude.project.premises import read_premises
|
||||
from loop_claude.project.records import read_records
|
||||
from forge.commands import Run, runner
|
||||
from claude_code.session import session_named
|
||||
from loop_claude.loop.main import setup_version
|
||||
@@ -40,6 +41,7 @@ from agent_cycle.direct_message import tell
|
||||
from agent_cycle import tmux
|
||||
|
||||
HELP = f"""usage: do-epic <EPIC-KEY> [--status]
|
||||
{findings.USAGE}
|
||||
|
||||
Runs the chunks of one Jira epic, such as ABC-12, each in its own window of the tmux session epic-<EPIC-KEY>.
|
||||
An open issue of the epic runs as a chunk once it has a label and no issue blocks it.
|
||||
@@ -51,6 +53,7 @@ is parked: it frees its place for the next chunk, and its window's name says wha
|
||||
on once the checks pass, the approval comes or a reviewer comments, and a place is free; until one is, the
|
||||
name says `awaits a slot`. A parked chunk survives a reboot: run do-epic <EPIC-KEY> again to go on polling.
|
||||
--status starts no chunk: it prints each open issue with whether its chunk runs, or why it waits.
|
||||
{findings.HELP}
|
||||
The Jira site and its credentials are set in ~/.claude-projects/do-epic/config.toml."""
|
||||
# Under the home folder, where a chunk's cycles are archived, a folder per epic. It is not loop-claude's archive, since that archive's readers, such as judge-replay and the routing figures, read loop-claude's prompts.
|
||||
ARCHIVE = ".claude/do-epic-transcripts"
|
||||
@@ -87,9 +90,9 @@ class EpicRun:
|
||||
return tmux.session_name(tmux.EPIC, self.key)
|
||||
|
||||
|
||||
def main(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launcher: pathlib.Path, effects: Effects, backend: Backend = jira_backend, forge_at: typing.Callable[[str], Run] = runner) -> int:
|
||||
def main(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launcher: pathlib.Path, effects: Effects, backend: Backend = jira_backend, stdin: typing.TextIO = sys.stdin, forge_at: typing.Callable[[str], Run] = runner) -> int:
|
||||
try:
|
||||
stop = run(argv, env, paths, launcher, effects, backend, forge_at)
|
||||
stop = run(argv, env, paths, launcher, effects, backend, stdin, forge_at)
|
||||
except KeyboardInterrupt:
|
||||
stop = Stop(130, "")
|
||||
except Exception as crash:
|
||||
@@ -103,12 +106,16 @@ def main(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launcher:
|
||||
return stop.code
|
||||
|
||||
|
||||
def run(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launcher: pathlib.Path, effects: Effects, backend: Backend, forge_at: typing.Callable[[str], Run]) -> Stop:
|
||||
def run(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launcher: pathlib.Path, effects: Effects, backend: Backend, stdin: typing.TextIO, forge_at: typing.Callable[[str], Run]) -> Stop:
|
||||
chunk, words = (argv[1], argv[2:]) if len(argv) >= 2 and argv[0] == scheduler.CHUNK_FLAG else (None, argv)
|
||||
status = chunk is None and words[1:] == [STATUS_FLAG]
|
||||
words = words[:1] if status else words
|
||||
if len(words) != 1 or not ISSUE_KEY.fullmatch(words[0]) or (chunk is not None and not ISSUE_KEY.fullmatch(chunk)):
|
||||
# What the words after the epic's key write into the epic, where they are a filing or a decision.
|
||||
writes = findings.parsed(words[1:]) if chunk is None else None
|
||||
if (len(words) != 1 and not writes) or not ISSUE_KEY.fullmatch(words[0]) or (chunk is not None and not ISSUE_KEY.fullmatch(chunk)):
|
||||
return Stop(0 if words in (["-h"], ["--help"]) else 1, HELP)
|
||||
if writes:
|
||||
return epic_written(words[0], writes, paths, backend, stdin)
|
||||
# Before anything starts: a clone, a claude session or a tmux window.
|
||||
if reason := tmux.unusable(effects.tmux, chunk_prompt.DRIVER):
|
||||
return Stop(1, reason)
|
||||
@@ -129,6 +136,15 @@ def status_printed(epic: EpicRun) -> Stop:
|
||||
return Stop(1, lines.reason) if isinstance(lines, Failure) else Stop(0, "\n".join(lines) or f"the epic {epic.key} has no open issue")
|
||||
|
||||
|
||||
def epic_written(key: str, writes: tuple[str, str, str | None], paths: Paths, backend: Backend, stdin: typing.TextIO) -> Stop:
|
||||
"""Files a finding in the epic, or records a decision in its description. It needs no tmux, so a chunk's worker may run it anywhere."""
|
||||
config = load(paths.home)
|
||||
if isinstance(config, Failure):
|
||||
return Stop(1, config.reason)
|
||||
done = findings.written(key, *writes, *backend(config, key), stdin, paths.home / scheduler.STATE / key)
|
||||
return Stop(1, done.reason) if isinstance(done, Failure) else Stop(0, done)
|
||||
|
||||
|
||||
def windows_opened(epic: EpicRun) -> Stop:
|
||||
"""What the do-epic the human runs does: starts each chunk that may start now, says why each other open issue waits, then puts the epic's session on the terminal until the human detaches."""
|
||||
started = chunks_started(epic, None)
|
||||
@@ -338,8 +354,10 @@ def next_cycle(loop_run: LoopRun, loop: Loop, in_repo: bool, epic: EpicRun, news
|
||||
premises = premises_read(loop.root if in_repo else None, epic)
|
||||
if isinstance(premises, Failure):
|
||||
return Stop(1, premises.reason)
|
||||
# The epic's records join the repo's with todo.md item 413; until then a chunk without a repo has none.
|
||||
records = read_records(loop.root, epic.paths.home, epic.paths.claude_dir) if in_repo else ""
|
||||
language = epic.record.language()
|
||||
if isinstance(language, Failure):
|
||||
return Stop(1, language.reason)
|
||||
records = records_read(loop.root if in_repo else None, epic)
|
||||
if isinstance(records, Failure):
|
||||
return Stop(1, records.reason)
|
||||
models = get_or_ask_models(project_key(loop.root, epic.paths.home), epic.paths, epic.env, chunk_prompt.DRIVER, epic.effects) if in_repo else repoless_models(epic)
|
||||
@@ -355,7 +373,7 @@ def next_cycle(loop_run: LoopRun, loop: Loop, in_repo: bool, epic: EpicRun, news
|
||||
project = ladder.project_rung(models.worker)
|
||||
route = routed(loop_run.route, project, models.worker, lambda: archived_route(archive_folder, loop), lambda: RoutingIssue(issue) if "L" in issue.scores else None)
|
||||
say(f"\n=== cycle {loop_run.cycle_number}, worker on {route.rung} ===", epic.effects, stdout=True)
|
||||
return Cycle(config=setup_version(epic.paths.claude_dir, epic.effects.git), effects=epic.effects, facts="", judge=judge_rung(ladder, models.judge), premises=premises, project=project, project_archive=archive_folder, records=records, root=loop.root, route=route, session=loop.session, task=chunk_prompt.task(issue, epic.key, loop.root if in_repo else None), prompts=chunk_prompt.unparked(news) if news else chunk_prompt.WORKER, taken_in=lambda entries: TakenIn(), unfinished_evidence=loop_run.unfinished_evidence, window=loop.window)
|
||||
return Cycle(config=setup_version(epic.paths.claude_dir, epic.effects.git), effects=epic.effects, facts="", judge=judge_rung(ladder, models.judge), premises=premises, project=project, project_archive=archive_folder, records=records, root=loop.root, route=route, session=loop.session, task=chunk_prompt.task(issue, epic.key, loop.root if in_repo else None, epic.launcher, language or epic.config.language), prompts=chunk_prompt.unparked(news) if news else chunk_prompt.WORKER, taken_in=lambda entries: TakenIn(), unfinished_evidence=loop_run.unfinished_evidence, window=loop.window)
|
||||
|
||||
|
||||
def repoless_models(epic: EpicRun) -> Models:
|
||||
@@ -363,6 +381,17 @@ def repoless_models(epic: EpicRun) -> Models:
|
||||
return Models(epic.env.get("LOOP_CLAUDE_JUDGE_MODEL") or epic.config.repoless_model, epic.env.get("LOOP_CLAUDE_WORKER_MODEL") or epic.config.repoless_model)
|
||||
|
||||
|
||||
def records_read(root: str | None, epic: EpicRun) -> str | Failure:
|
||||
"""The epic's Scoring and Decisions, from its description, then the records of the repo checked out at root, where the chunk has one, then the human's rules."""
|
||||
sections: list[tuple[str, str]] = []
|
||||
for name in ("Scoring", "Decisions"):
|
||||
body = epic.record.section(name)
|
||||
if isinstance(body, Failure):
|
||||
return Failure(f"the epic {epic.key}'s description: {body.reason} - {CONSEQUENCE}.")
|
||||
sections.append((f"the epic {epic.key}'s description, ## {name}", body))
|
||||
return read_records(root, epic.paths.home, epic.paths.claude_dir, tuple(sections))
|
||||
|
||||
|
||||
def premises_read(root: str | None, epic: EpicRun) -> str | Failure:
|
||||
"""The epic's Goals and Audience, from its description, then those of the repo checked out at root, where the chunk has one. A Failure where the epic lacks either: no chunk runs without premises."""
|
||||
bodies: list[str] = []
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
import contextlib
|
||||
import dataclasses
|
||||
import fcntl
|
||||
import io
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from do_epic.test_main import DESCRIPTION, DoEpicTest
|
||||
from do_epic.epic_record import EpicRecord
|
||||
from failure import Failure
|
||||
from loop_claude.test_loop_claude import FakeEffects
|
||||
from record_store.held import Held
|
||||
from do_epic import main
|
||||
from do_epic.backend.fake import MemoryEpic
|
||||
from loop_state.paths import paths_from
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class WrittenDescription:
|
||||
"""Stands in for an epic's description in Jira that takes writes: kept holds each text it held, the last one now. It refuses a write that claims the human's approval, and notes in locked whether lock was held during each write."""
|
||||
kept: list[str]
|
||||
lock: pathlib.Path
|
||||
locked: list[bool] = dataclasses.field(default_factory=list)
|
||||
approved: frozenset[str] | None = frozenset()
|
||||
|
||||
@property
|
||||
def text(self) -> str:
|
||||
return self.kept[-1]
|
||||
|
||||
def read(self) -> str | Failure:
|
||||
return self.text
|
||||
|
||||
def held(self) -> Held | Failure:
|
||||
return Held(self.text)
|
||||
|
||||
def write(self, text: str, version: str | None) -> Held | Failure:
|
||||
if self.approved != frozenset():
|
||||
return Failure(f"approved is {self.approved!r}")
|
||||
with open(self.lock, "a") as other:
|
||||
try:
|
||||
fcntl.flock(other, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
self.locked.append(False)
|
||||
except BlockingIOError:
|
||||
self.locked.append(True)
|
||||
self.kept.append(text)
|
||||
return Held(text)
|
||||
|
||||
|
||||
class FindingsTest(DoEpicTest):
|
||||
def setUp(self) -> None:
|
||||
super().setUp()
|
||||
self.store = MemoryEpic("ABC-12", list(self.issues))
|
||||
self.written = WrittenDescription([DESCRIPTION], self.home / ".local/state/do-epic/ABC-12/decisions.lock")
|
||||
self.keys: list[str] = []
|
||||
|
||||
def backend(self, config: object, key: str) -> tuple[MemoryEpic, EpicRecord]:
|
||||
self.keys.append(key)
|
||||
return self.store, EpicRecord(self.written) # type: ignore[arg-type]
|
||||
|
||||
def run_with(self, argv: list[str], stdin: str = "") -> tuple[int, str, str, FakeEffects]:
|
||||
out, err, fake = io.StringIO(), io.StringIO(), FakeEffects()
|
||||
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):
|
||||
code = main.main(argv, {}, paths_from(self.home), pathlib.Path("/b/do-epic"), fake.effects(), self.backend, io.StringIO(stdin))
|
||||
# Without the time each line of do-epic opens with.
|
||||
return code, out.getvalue().replace("<1790000000> ", ""), err.getvalue().replace("<1790000000> ", ""), fake
|
||||
|
||||
|
||||
class FilingAFinding(FindingsTest):
|
||||
def test_files_an_issue_under_the_epic_with_the_detail_piped_in_and_doesnt_start_anything(self) -> None:
|
||||
code, out, err, fake = self.run_with(["ABC-12", "--file", "Retry the import on a 503"], "The client times out.\n")
|
||||
self.assertEqual((code, out, err), (0, "Filed ABC-102 in the epic ABC-12. It waits until someone labels it: `repo:<name>` for the repo that works it, `do-epic-claude` for work of Claude's that changes no repo, or `do-epic-human` for a task of the human's.\n", ""))
|
||||
self.assertEqual(self.keys, ["ABC-12"])
|
||||
filed = self.store.issues[-1]
|
||||
self.assertEqual((filed.key, filed.summary, filed.detail, filed.labels, filed.parent, filed.by_loop), ("ABC-102", "Retry the import on a 503", "The client times out.", (), "ABC-12", True))
|
||||
self.assertEqual(fake.calls, [], "filing needs no tmux, clone or claude")
|
||||
|
||||
def test_a_label_says_where_the_issue_is_worked(self) -> None:
|
||||
for argv, label in ((["ABC-12", "--file", "Retry", "--label", "repo:api"], "repo:api"), (["ABC-12", "--file", "--label", "do-epic-claude", "Retry"], "do-epic-claude"), (["ABC-12", "--file", "Retry", "--label", "do-epic-human"], "do-epic-human")):
|
||||
with self.subTest(argv=argv):
|
||||
code, out, _, _ = self.run_with(argv)
|
||||
filed = self.store.issues[-1]
|
||||
self.assertEqual((code, out, filed.labels, filed.detail), (0, f"Filed {filed.key} in the epic ABC-12.\n", (label,), ""))
|
||||
|
||||
def test_refuses_a_label_the_scheduler_doesnt_read(self) -> None:
|
||||
for label in ("api", "repo:", "repo:a b"):
|
||||
with self.subTest(label=label):
|
||||
code, out, err, _ = self.run_with(["ABC-12", "--file", "Retry", "--label", label])
|
||||
self.assertEqual((code, out, len(self.store.issues)), (1, "", 2))
|
||||
self.assertEqual(err, f"cannot file the finding in the epic ABC-12: do-epic doesn't read the label {label!r}; write `repo:<name>` for the repo that works it, `do-epic-claude` for work of Claude's that changes no repo, or `do-epic-human` for a task of the human's\n")
|
||||
|
||||
def test_says_why_an_issue_was_not_filed(self) -> None:
|
||||
self.store.fails = "Jira answered 401"
|
||||
code, _, err, _ = self.run_with(["ABC-12", "--file", "Retry"])
|
||||
self.assertEqual((code, err), (1, "cannot file the finding in the epic ABC-12: Jira answered 401\n"))
|
||||
|
||||
def test_stops_where_the_machines_settings_cannot_be_read(self) -> None:
|
||||
(self.home / ".claude-projects/do-epic/config.toml").unlink()
|
||||
code, out, err, _ = self.run_with(["ABC-12", "--file", "Retry"])
|
||||
self.assertEqual((code, out, len(self.store.issues)), (1, "", 2))
|
||||
self.assertIn("config.toml", err)
|
||||
|
||||
def test_prints_the_help_for_a_filing_spelt_wrong(self) -> None:
|
||||
for argv in (["ABC-12", "--file"], ["ABC-12", "--file", "a", "b"], ["ABC-12", "--file", "a", "--label"], ["ABC-12", "--file", "a", "--labels", "x"], ["--file", "ABC-12", "a"], ["ABC-12", "--file", "--label", "x"], ["ABC-12", "--file", "--lable"], ["ABC-12", "--file", "a", "--label", "--x"], ["--chunk", "ABC-20", "ABC-12", "--file", "a"]):
|
||||
with self.subTest(argv=argv):
|
||||
code, out, err, _ = self.run_with(argv)
|
||||
self.assertEqual((code, out, err, len(self.store.issues)), (1, "", main.HELP + "\n", 2))
|
||||
|
||||
|
||||
class RecordingADecision(FindingsTest):
|
||||
def test_appends_the_entry_to_the_descriptions_decisions(self) -> None:
|
||||
code, out, err, fake = self.run_with(["ABC-12", "--record-decision", "Imports retry three times"], "2026-11-18, the human's answer. Valid while the client's API rate-limits.\n")
|
||||
self.assertEqual((code, out, err, fake.calls), (0, "Recorded the decision in the epic ABC-12's description.\n", "", []))
|
||||
self.assertEqual(self.written.text, DESCRIPTION + "\n## Decisions\n\n### Imports retry three times\n\n2026-11-18, the human's answer. Valid while the client's API rate-limits.\n")
|
||||
self.assertEqual(self.run_with(["ABC-12", "--record-decision", "Merges squash"], "Always.")[0], 0)
|
||||
self.assertTrue(self.written.text.endswith("rate-limits.\n\n### Merges squash\n\nAlways.\n"), self.written.text)
|
||||
self.assertIn("## Goals\nShip the import.\n\n## Audience\nThe client's team.\n", self.written.text)
|
||||
self.assertEqual((self.keys, self.written.locked), (["ABC-12", "ABC-12"], [True, True]))
|
||||
|
||||
def test_recording_a_decision_twice_keeps_one(self) -> None:
|
||||
self.run_with(["ABC-12", "--record-decision", "Merges squash"], "Always.\n\n```\n### not a title\n```\n")
|
||||
self.run_with(["ABC-12", "--record-decision", "Imports retry"], "Three times.")
|
||||
held = self.written.text
|
||||
code, out, err, _ = self.run_with(["ABC-12", "--record-decision", " Merges squash "], "Always.\n\n```\n### not a title\n```")
|
||||
self.assertEqual((code, out, err, self.written.text), (0, "The epic ABC-12's description already holds that decision.\n", "", held))
|
||||
self.assertEqual(len(self.written.kept), 3)
|
||||
|
||||
def test_refuses_another_decision_under_a_title_the_description_holds(self) -> None:
|
||||
self.run_with(["ABC-12", "--record-decision", "Merges squash"], "Always.")
|
||||
held = self.written.text
|
||||
code, out, err, _ = self.run_with(["ABC-12", "--record-decision", "Merges squash"], "Always")
|
||||
self.assertEqual((code, out, self.written.text), (1, "", held))
|
||||
self.assertEqual(err, "cannot record the decision in the epic ABC-12's description: ## Decisions already holds another decision titled 'Merges squash': give this one a title of its own\n")
|
||||
|
||||
def test_says_why_the_lock_was_not_taken(self) -> None:
|
||||
self.written.lock.parent.parent.mkdir(parents=True)
|
||||
self.written.lock.parent.write_text("")
|
||||
code, out, err, _ = self.run_with(["ABC-12", "--record-decision", "Merges squash"], "Always.")
|
||||
self.assertEqual((code, out, self.written.text), (1, "", DESCRIPTION))
|
||||
self.assertRegex(err, f"^cannot record the decision in the epic ABC-12's description: cannot lock {self.written.lock.parent}: \\w")
|
||||
|
||||
def test_refuses_a_decision_without_a_title_or_a_body(self) -> None:
|
||||
for argv, stdin, reason in ((["ABC-12", "--record-decision", "Merges squash"], " \n", "pipe the decision's text in"), (["ABC-12", "--record-decision", "two\nlines"], "Always.", "the title must be one line of text"), (["ABC-12", "--record-decision", " "], "Always.", "the title must be one line of text"), (["ABC-12", "--record-decision", "Merges squash"], "## Goals\nNone.", "the body of ## Decisions holds a level 1 or 2 heading, which would start another section")):
|
||||
with self.subTest(argv=argv, stdin=stdin):
|
||||
code, out, err, _ = self.run_with(argv, stdin)
|
||||
self.assertEqual((code, out, err, self.written.text), (1, "", f"cannot record the decision in the epic ABC-12's description: {reason}\n", DESCRIPTION))
|
||||
|
||||
def test_prints_the_help_for_a_decision_spelt_wrong(self) -> None:
|
||||
for argv in (["ABC-12", "--record-decision"], ["ABC-12", "--record-decision", "a", "b"], ["ABC-12", "--decide", "a"]):
|
||||
with self.subTest(argv=argv):
|
||||
code, out, err, _ = self.run_with(argv, "Always.")
|
||||
self.assertEqual((code, out, err, self.written.text), (1, "", main.HELP + "\n", DESCRIPTION))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import unittest
|
||||
unittest.main()
|
||||
@@ -80,7 +80,7 @@ class DoEpicTest(unittest.TestCase):
|
||||
def run_main(self, argv: list[str], fake: FakeEffects, env: dict[str, str] | None = None) -> tuple[int, str, str]:
|
||||
out, err = io.StringIO(), io.StringIO()
|
||||
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):
|
||||
code = main.main(argv, env or {}, paths_from(self.home), pathlib.Path("/b/do-epic"), fake.effects(), self.backend, self.forge_at)
|
||||
code = main.main(argv, env or {}, paths_from(self.home), pathlib.Path("/b/do-epic"), fake.effects(), self.backend, forge_at=self.forge_at)
|
||||
return code, out.getvalue(), err.getvalue()
|
||||
|
||||
|
||||
@@ -165,11 +165,27 @@ class ACycleOfAChunkWithoutARepo(DoEpicTest):
|
||||
cycle = self.cycle()
|
||||
self.assertEqual((cycle.root, cycle.project_archive, cycle.records), (str(self.home / ".local/state/do-epic/ABC-12"), self.home / ".claude/do-epic-transcripts/ABC-12", ""))
|
||||
|
||||
def test_the_records_are_the_epics_scoring_and_decisions_then_the_humans_rules(self) -> None:
|
||||
self.description = DESCRIPTION + "\n## Scoring\nE + I, bar 4.\n\n## Decisions\n### Merges squash\nAlways.\n"
|
||||
(self.home / ".claude").mkdir()
|
||||
(self.home / ".claude/CLAUDE.md").write_text("# Global\n", encoding="utf-8")
|
||||
self.assertEqual(self.cycle().records, "From the epic ABC-12's description, ## Scoring:\nE + I, bar 4.\n\nFrom the epic ABC-12's description, ## Decisions:\n### Merges squash\nAlways.\n\nFrom ~/.claude/CLAUDE.md:\n# Global")
|
||||
|
||||
def test_stops_where_a_section_of_the_epics_records_cannot_be_read(self) -> None:
|
||||
self.description = DESCRIPTION + "\n## Scoring\nA.\n\n## Scoring\nB.\n"
|
||||
with self.assertRaises(AssertionError) as raised:
|
||||
self.cycle()
|
||||
self.assertIn("the epic ABC-12's description: the epic's description has ## Scoring more than once - the judge cannot read the records.", str(raised.exception))
|
||||
|
||||
def test_the_premises_are_the_epics_goals_and_audience(self) -> None:
|
||||
self.assertEqual(self.cycle().premises, "the epic ABC-12's description:\n## Goals\nShip the import.\n\n## Audience\nThe client's team.")
|
||||
|
||||
def test_the_task_is_the_issue(self) -> None:
|
||||
self.assertEqual(self.cycle().task, "Work the Jira issue ABC-21 of the epic ABC-12 as one chunk, which changes no repo: work in the folder you start in. Its summary: Do ABC-21\n\nIts description:\n\nTidy the docs.")
|
||||
task = self.cycle().task
|
||||
self.assertTrue(task.startswith("Work the Jira issue ABC-21 of the epic ABC-12 as one chunk, which changes no repo: work in the folder you start in. File a finding"), task)
|
||||
self.assertIn('with `/b/do-epic ABC-12 --file "<summary>" --label <label>` and its detail on stdin', task)
|
||||
self.assertIn("Write the issue and the decision in English, the epic's language.", task)
|
||||
self.assertTrue(task.endswith(" Its summary: Do ABC-21\n\nIts description:\n\nTidy the docs."), task)
|
||||
|
||||
def test_an_issue_without_scores_runs_on_the_projects_rung(self) -> None:
|
||||
self.issues[1] = dataclasses.replace(self.issues[1], scores={})
|
||||
@@ -320,16 +336,19 @@ class AChunksRun(DoEpicTest):
|
||||
(checkout / "README.md").write_text("## Goals\nServe the API.\n\n## Audience\nIts callers.\n", encoding="utf-8")
|
||||
(checkout / "AGENTS.md").write_text("Squash every merge.\n", encoding="utf-8")
|
||||
self.issues = [dataclasses.replace(issue("ABC-20", "repo:api"), scores={"L": 2, "E": 1, "I": 1})]
|
||||
self.description = DESCRIPTION + "\n## Decisions\nKeep the v1 endpoints.\n"
|
||||
fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD)
|
||||
code, out, err = self.run_main(["--chunk", "ABC-20", "ABC-12"], fake, MODELS)
|
||||
self.assertEqual(code, 0, err)
|
||||
prompt = " ".join([what for seam, what in fake.calls if seam == "stream_claude"][0])
|
||||
self.assertIn(f"Work the Jira issue ABC-20 of the epic ABC-12 as one chunk, in the checkout {checkout}, on the branch ABC-20.", prompt)
|
||||
self.assertIn(f"Work the Jira issue ABC-20 of the epic ABC-12 as one chunk, in the checkout {checkout}, on the branch ABC-20. File a finding", prompt)
|
||||
self.assertIn("Ship the import.", prompt)
|
||||
self.assertIn("The repo's goals, which rank after the epic's and after code health, are from", prompt)
|
||||
self.assertIn("Serve the API.", prompt)
|
||||
self.assertIn("the chunk finished; ", out)
|
||||
self.assertIn("Squash every merge.", [what[1] for seam, what in fake.calls if seam == "claude"][0])
|
||||
self.assertIn("the chunk finished; started no other\n", out)
|
||||
judge_prompt = [what[1] for seam, what in fake.calls if seam == "claude"][0]
|
||||
self.assertIn("The records: the epic's scoring and decisions, then the repo's working rules and decisions, then the human's rules for every project:\nFrom the epic ABC-12's description, ## Decisions:\nKeep the v1 endpoints.\n\nFrom AGENTS.md:\nSquash every merge.", judge_prompt)
|
||||
self.assertIn("writing it into the epic's description under ## Decisions, the repo's goals file's Goals or Audience, AGENTS.md, docs/decisions.md, the repo's plan or a comment", judge_prompt)
|
||||
|
||||
def test_a_chunk_without_a_repo_reads_no_forge(self) -> None:
|
||||
fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD)
|
||||
|
||||
@@ -293,7 +293,16 @@ class StartingAnEpicsChunks(unittest.TestCase):
|
||||
|
||||
class TheFirstPrompt(unittest.TestCase):
|
||||
def test_the_task_names_the_checkout_and_branch_and_quotes_a_description_only_where_there_is_one(self) -> None:
|
||||
self.assertEqual(chunk_prompt.task(issue("ABC-20"), "ABC-12", "/code/api"), "Work the Jira issue ABC-20 of the epic ABC-12 as one chunk, in the checkout /code/api, on the branch ABC-20. Its summary: Do ABC-20")
|
||||
labels = "`repo:<name>` for the repo that works it, `do-epic-claude` for work of Claude's that changes no repo, or `do-epic-human` for a task of the human's"
|
||||
told = (
|
||||
f"File a finding about one of the epic's goals in the epic, with `/b/do-epic ABC-12 --file \"<summary>\" --label <label>` and its detail on stdin. The label is {labels}; leave it out where you cannot tell, and the issue waits for the human. "
|
||||
"Where filing fails and says the issue may exist, ask the human to look before you file it again. File a finding about a repo's goals by that repo's rules. Where unsure which, ask the human. "
|
||||
"Record a decision that governs the epic, such as an answer the human typed, with `/b/do-epic ABC-12 --record-decision \"<title>\"` and its text on stdin. Write the issue and the decision in Swedish, the epic's language."
|
||||
)
|
||||
self.assertEqual(chunk_prompt.task(issue("ABC-20"), "ABC-12", "/code/api", pathlib.Path("/b/do-epic"), "Swedish"), f"Work the Jira issue ABC-20 of the epic ABC-12 as one chunk, in the checkout /code/api, on the branch ABC-20. {told} Its summary: Do ABC-20")
|
||||
|
||||
def test_an_answer_the_judge_quoted_names_the_epics_description_first(self) -> None:
|
||||
self.assertTrue(chunk_prompt.WORKER.answered("Q", "A", Route(Rung("off-the-ladder")), None, False).startswith("Your question: Q\n\nthe epic's description, "))
|
||||
|
||||
def test_opens_with_the_task_then_the_rung_then_the_premises(self) -> None:
|
||||
rest = f"The issue sets the chunk's scope. The goals below choose between ways to deliver that scope, and never widen it. The epic's goals rank first, then code health ({chunk_prompt.CODE_HEALTH}), then the repo's.\n\nFrom P"
|
||||
|
||||
@@ -71,7 +71,7 @@ from model_routing.ladder import Ladder, ProjectRung, REVIEW_STEPS, Rung
|
||||
from claude_code.reply import Limited
|
||||
from model_routing.ladder_file import read_ladder, SHIPPED
|
||||
from loop_claude.project.premises import read_premises
|
||||
from loop_claude.project.records import read_records
|
||||
from loop_claude.project.records import read_records, RECORDS_NAMED
|
||||
from claude_code.transcript import read_transcript
|
||||
from agent_cycle.verdicts import Verdict
|
||||
|
||||
@@ -172,5 +172,5 @@ def rule(case: Case, rung: Rung, home: pathlib.Path, effects: Effects) -> Kind |
|
||||
if isinstance(records, Failure):
|
||||
return verdict_kind(records)
|
||||
# 0 for the route's mark, as before any step-up: the replay compares verdict kinds, and a mark changes only which escalation quotes count.
|
||||
verdict = first_reply(lambda: judge_once(case.root, Brief(task=case.task, premises=premises, records=records, answer_destinations=ANSWER_DESTINATIONS, entries=entries, escalated_at=0, driver=DRIVER), rung, effects))
|
||||
verdict = first_reply(lambda: judge_once(case.root, Brief(task=case.task, premises=premises, records=records, records_named=RECORDS_NAMED, answer_destinations=ANSWER_DESTINATIONS, entries=entries, escalated_at=0, driver=DRIVER), rung, effects))
|
||||
return verdict if isinstance(verdict, Limited) else verdict_kind(verdict)
|
||||
|
||||
@@ -8,7 +8,7 @@ from model_routing.review_choice import chosen, ReviewChoice
|
||||
from loop_claude.cycle.chunk_items import CHUNK_ITEMS
|
||||
from model_routing.route import ESCALATION_MARKER, Route
|
||||
from agent_cycle.routing import escalation_rungs
|
||||
from loop_claude.project.records import HUMAN_RULE_NAMES, RECORD_FILES
|
||||
from loop_claude.project.records import HUMAN_RULE_NAMES, RECORD_FILES, RECORDS_NAMED
|
||||
from review_rules.review_passes import INSTRUCTION_FILES, INSTRUCTION_FOLDERS
|
||||
from text_files.markdown_text import listed, quoted
|
||||
from model_routing.ladder import ProjectRung, Rung
|
||||
@@ -186,9 +186,16 @@ def rungs_held(driver: str, route: Route, project: ProjectRung | None) -> str:
|
||||
return "".join(f" {sentence}" for sentence in rung_sentences(driver, route, project))
|
||||
|
||||
|
||||
def worker_prompts(driver: str, fresh: typing.Callable[[str, str, Route, ProjectRung | None, str], str], naming: str) -> WorkerPrompts:
|
||||
"""The prompts of an entry point's cycles: its own fresh prompt, and the resumed prompt and rung sentences every entry point shares, each naming driver. resumed says what naming is."""
|
||||
return WorkerPrompts(driver, fresh, functools.partial(resumed, driver, naming), functools.partial(rungs_held, driver), QUOTE_SOURCES, ANSWER_DESTINATIONS)
|
||||
class RecordNames(typing.NamedTuple):
|
||||
"""The names an entry point's prompts give the places that answer a question, the places that take an answer, and the records the judge reads; WorkerPrompts says what each field is."""
|
||||
quote_sources: str = QUOTE_SOURCES
|
||||
answer_destinations: str = ANSWER_DESTINATIONS
|
||||
records_named: str = RECORDS_NAMED
|
||||
|
||||
|
||||
def worker_prompts(driver: str, fresh: typing.Callable[[str, str, Route, ProjectRung | None, str], str], naming: str, names: RecordNames = RecordNames()) -> WorkerPrompts:
|
||||
"""The prompts of an entry point's cycles: its own fresh prompt, and the resumed prompt and rung sentences every entry point shares, each naming driver. resumed says what naming is. names is loop-claude's unless the entry point keeps records elsewhere, as do-epic does."""
|
||||
return WorkerPrompts(driver, fresh, functools.partial(resumed, driver, naming), functools.partial(rungs_held, driver), *names)
|
||||
|
||||
|
||||
WORKER = worker_prompts(DRIVER, functools.partial(fresh, DRIVER), NAME_THE_ITEMS)
|
||||
|
||||
@@ -13,28 +13,35 @@ RECORD_FILES = (WORKING_RULES[0], DECISIONS[0])
|
||||
# then each .md file in the review standards folder the project's config sets.
|
||||
HUMAN_RULES_FILE = "CLAUDE.md"
|
||||
HUMAN_RULE_DIR = "rules"
|
||||
# How the judge's prompt names the records above, in the order it reads them.
|
||||
RECORDS_NAMED = "the project's working rules and decisions, then the human's rules for every project"
|
||||
HUMAN_RULE_NAMES = (f"~/.claude/{HUMAN_RULES_FILE}", f"~/.claude/{HUMAN_RULE_DIR}/", "the project's review standards")
|
||||
|
||||
|
||||
CONSEQUENCE = "the judge cannot read the records"
|
||||
|
||||
|
||||
def read_records(root: str, home: pathlib.Path, claude_dir: pathlib.Path) -> str | Failure:
|
||||
def read_records(root: str | None, home: pathlib.Path, claude_dir: pathlib.Path, first: tuple[tuple[str, str], ...] = ()) -> str | Failure:
|
||||
"""The project's `AGENTS.md` and decision log, then the human's rules, CLAUDE.md first, each headed by its name; one that does not exist, or is empty, is left out.
|
||||
|
||||
`AGENTS.md` is read where the config under home of root's project puts it, and the decision log from the store that config names. Each is headed by its name in RECORD_FILES wherever it is kept."""
|
||||
config = located(root, home)
|
||||
if isinstance(config, Failure):
|
||||
return Failure(f"{config.reason} - {CONSEQUENCE}.")
|
||||
rules = [claude_dir / HUMAN_RULES_FILE, *sorted((claude_dir / HUMAN_RULE_DIR).glob("*.md")), *sorted(config.paths["standards"].glob("*.md"))]
|
||||
decisions = store(config, DECISIONS[1]).read()
|
||||
texts = [(WORKING_RULES[0], file_text(config.paths[WORKING_RULES[1]])), (DECISIONS[0], Failure(f"{decisions.reason} - {CONSEQUENCE}.") if isinstance(decisions, Failure) else decisions)]
|
||||
`AGENTS.md` is read where the config under home of root's project puts it, and the decision log from the store that config names. Each is headed by its name in RECORD_FILES wherever it is kept.
|
||||
|
||||
first holds records kept outside the project, such as the sections of a Jira epic's description, each as its heading and text: they come before the project's. A root of None is work without a checkout, which has no project records and no review standards."""
|
||||
texts: list[tuple[str, str | Failure]] = list(first)
|
||||
rules = [claude_dir / HUMAN_RULES_FILE, *sorted((claude_dir / HUMAN_RULE_DIR).glob("*.md"))]
|
||||
if root is not None:
|
||||
config = located(root, home)
|
||||
if isinstance(config, Failure):
|
||||
return Failure(f"{config.reason} - {CONSEQUENCE}.")
|
||||
rules += sorted(config.paths["standards"].glob("*.md"))
|
||||
decisions = store(config, DECISIONS[1]).read()
|
||||
texts += [(WORKING_RULES[0], file_text(config.paths[WORKING_RULES[1]])), (DECISIONS[0], Failure(f"{decisions.reason} - {CONSEQUENCE}.") if isinstance(decisions, Failure) else decisions)]
|
||||
texts += [(named(rule, home, claude_dir), file_text(rule)) for rule in rules]
|
||||
records = []
|
||||
for heading, text in texts:
|
||||
if isinstance(text, Failure):
|
||||
return text
|
||||
if text:
|
||||
if text.strip():
|
||||
records.append(f"From {heading}:\n{text.strip()}")
|
||||
return "\n\n".join(records)
|
||||
|
||||
|
||||
@@ -1907,6 +1907,21 @@ class Records(unittest.TestCase):
|
||||
config.unlink()
|
||||
self.assertEqual(records.read_records(root, claude_md.parents[1], claude_md.parent), Failure(f"no config names the checkout {root}: write ~/.claude-projects/<key>/config.toml, as `project-config --help` shows - the judge cannot read the records."))
|
||||
|
||||
def test_puts_the_records_handed_in_first_and_reads_only_the_humans_rules_without_a_checkout(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
claude_md = pathlib.Path(root, "home", ".claude", "CLAUDE.md")
|
||||
configured(self, pathlib.Path(root), home=claude_md.parents[1])
|
||||
claude_md.parent.mkdir(parents=True)
|
||||
claude_md.write_text("# Global\n")
|
||||
pathlib.Path(claude_md.parent, "rules").mkdir()
|
||||
pathlib.Path(claude_md.parent, "rules", "todo-items.md").write_text("# Todo\n")
|
||||
pathlib.Path(claude_md.parent, "skills", "larv-review", "standards").mkdir(parents=True)
|
||||
pathlib.Path(claude_md.parent, "skills", "larv-review", "standards", "comments.md").write_text("# Comments\n")
|
||||
pathlib.Path(root, "AGENTS.md").write_text("# Rules\n")
|
||||
first = (("the epic ABC-1's description, ## Decisions", "Squash.\n"), ("the epic ABC-1's description, ## Scoring", " \n"))
|
||||
self.assertEqual(records.read_records(root, claude_md.parents[1], claude_md.parent, first), "From the epic ABC-1's description, ## Decisions:\nSquash.\n\nFrom AGENTS.md:\n# Rules\n\nFrom ~/.claude/CLAUDE.md:\n# Global\n\nFrom ~/.claude/rules/todo-items.md:\n# Todo\n\nFrom ~/.claude/skills/larv-review/standards/comments.md:\n# Comments")
|
||||
self.assertEqual(records.read_records(None, claude_md.parents[1], claude_md.parent, first), "From the epic ABC-1's description, ## Decisions:\nSquash.\n\nFrom ~/.claude/CLAUDE.md:\n# Global\n\nFrom ~/.claude/rules/todo-items.md:\n# Todo")
|
||||
|
||||
def test_stops_on_a_record_it_cannot_read(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
claude_md = pathlib.Path(root, "home", ".claude", "CLAUDE.md")
|
||||
@@ -1931,7 +1946,7 @@ class Records(unittest.TestCase):
|
||||
class JudgePrompt(unittest.TestCase):
|
||||
def test_shows_the_transcripts_tail_and_returns_what_it_showed(self):
|
||||
entries = [assistant({"type": "text", "text": "old " + "x" * judge.JUDGE_PROMPT_CHARS}), assistant({"type": "text", "text": "new"})]
|
||||
prompt, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), 0, prompts.DRIVER))
|
||||
prompt, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", records.RECORDS_NAMED, prompts.ANSWER_DESTINATIONS, kinds(*entries), 0, prompts.DRIVER))
|
||||
self.assertTrue(grounds.shown.endswith("\n\nnew"))
|
||||
self.assertNotIn("old", grounds.shown)
|
||||
self.assertIn(grounds.shown, prompt)
|
||||
@@ -1940,11 +1955,11 @@ class JudgePrompt(unittest.TestCase):
|
||||
self.assertEqual(grounds.quotable, "## Goals\n\n")
|
||||
|
||||
def test_the_judge_prompt_and_schema_call_the_worker_the_worker(self):
|
||||
prompt, _ = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(assistant({"type": "text", "text": "done"})), 1, prompts.DRIVER))
|
||||
prompt, _ = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", records.RECORDS_NAMED, prompts.ANSWER_DESTINATIONS, kinds(assistant({"type": "text", "text": "done"})), 1, prompts.DRIVER))
|
||||
self.assertNotRegex(prompt + json.dumps(judge.judge_schema(prompts.DRIVER)), r"\b[Aa]gent")
|
||||
|
||||
def test_the_judge_prompt_names_the_entry_points_answer_destinations_in_both_rules_on_a_recorded_answer(self):
|
||||
prompt, _ = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", "the ledger", kinds(assistant({"type": "text", "text": "done"})), 0, prompts.DRIVER))
|
||||
prompt, _ = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", records.RECORDS_NAMED, "the ledger", kinds(assistant({"type": "text", "text": "done"})), 0, prompts.DRIVER))
|
||||
self.assertIn("is recorded in the ledger at the one place it governs", prompt)
|
||||
self.assertIn("the worker writing it into the ledger, but not into one of the human's rules", prompt)
|
||||
|
||||
@@ -1957,24 +1972,24 @@ class JudgePrompt(unittest.TestCase):
|
||||
|
||||
def test_shows_the_judge_where_the_worker_last_stepped_up_and_checks_an_escalation_only_after_it(self):
|
||||
entries = [assistant({"type": "text", "text": "round 2: 🔴"}), assistant({"type": "text", "text": "round 3: 🔴"})]
|
||||
prompt, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), 1, prompts.DRIVER))
|
||||
prompt, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", records.RECORDS_NAMED, prompts.ANSWER_DESTINATIONS, kinds(*entries), 1, prompts.DRIVER))
|
||||
self.assertRegex(prompt, "round 2: 🔴\n\n\\[step\\] [^\n]+\n\nround 3: 🔴\n\n")
|
||||
self.assertEqual(grounds.after_mark, "round 3: 🔴")
|
||||
prompt, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), 0, prompts.DRIVER))
|
||||
prompt, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", records.RECORDS_NAMED, prompts.ANSWER_DESTINATIONS, kinds(*entries), 0, prompts.DRIVER))
|
||||
self.assertNotIn("stepped the worker up", prompt)
|
||||
self.assertEqual(grounds.shown, "round 2: 🔴\n\nround 3: 🔴")
|
||||
self.assertEqual(grounds.after_mark, "round 2: 🔴\n\nround 3: 🔴")
|
||||
|
||||
def test_drops_an_escalation_quote_from_after_the_step_up_that_the_tail_it_shows_cuts_off(self):
|
||||
entries = [assistant({"type": "text", "text": "round 2: 🔴"}), assistant({"type": "text", "text": "old " + "x" * judge.JUDGE_PROMPT_CHARS}), assistant({"type": "text", "text": "new"})]
|
||||
_, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), 1, prompts.DRIVER))
|
||||
_, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", records.RECORDS_NAMED, prompts.ANSWER_DESTINATIONS, kinds(*entries), 1, prompts.DRIVER))
|
||||
self.assertEqual(judge.quotes_checked(Unfinished("e", "old x", entries_read=3), grounds), Unfinished("e", entries_read=3))
|
||||
self.assertEqual(judge.quotes_checked(Unfinished("e", "new", entries_read=3), grounds), Unfinished("e", "new", entries_read=3))
|
||||
|
||||
def test_shows_a_typed_answer_before_the_step_up_as_the_humans(self):
|
||||
typed = prompts.WORKER.typed("Which one?", "Use B.", Route(Rung("worker-model")), None, False)
|
||||
entries = [{**human(typed), "promptSource": "sdk"}, assistant({"type": "text", "text": "round 3: 🔴"})]
|
||||
_, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), 1, prompts.DRIVER))
|
||||
_, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", records.RECORDS_NAMED, prompts.ANSWER_DESTINATIONS, kinds(*entries), 1, prompts.DRIVER))
|
||||
self.assertIn("\n\n[human] Use B.\n\n[step] ", grounds.shown)
|
||||
|
||||
|
||||
@@ -2201,7 +2216,7 @@ class Verdict(unittest.TestCase):
|
||||
def test_drops_an_escalation_quote_found_only_in_the_transcript_entries_before_the_workers_last_step_up(self):
|
||||
entries = [assistant({"type": "text", "text": "round 2: 🔴"}), assistant({"type": "text", "text": "round 3: 🔴"}), assistant({"type": "text", "text": "working"})]
|
||||
def judged_on(mark, escalation):
|
||||
return judge.judge_once("/r", judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), mark, prompts.DRIVER), Rung("judge-model"), FakeEffects(claude=[judged("unfinished", escalation=escalation)]).effects())
|
||||
return judge.judge_once("/r", judge.Brief("Do it.", "## Goals", "", records.RECORDS_NAMED, prompts.ANSWER_DESTINATIONS, kinds(*entries), mark, prompts.DRIVER), Rung("judge-model"), FakeEffects(claude=[judged("unfinished", escalation=escalation)]).effects())
|
||||
self.assertEqual(judged_on(0, "round 2: 🔴"), Unfinished("working", "round 2: 🔴", entries_read=3))
|
||||
self.assertEqual(judged_on(1, "round 2: 🔴"), Unfinished("working", entries_read=3))
|
||||
self.assertEqual(judged_on(1, "round 3: 🔴"), Unfinished("working", "round 3: 🔴", entries_read=3))
|
||||
@@ -2210,12 +2225,12 @@ class Verdict(unittest.TestCase):
|
||||
|
||||
def test_drops_an_escalation_quote_that_only_loop_claudes_prompts_or_the_humans_lines_repeat_after_the_step_up(self):
|
||||
entries = [assistant({"type": "text", "text": "round 2: 🔴"}), {**human("as the work remaining: round 2: 🔴"), "promptSource": "sdk"}, human("round 2: 🔴 again"), assistant({"type": "text", "text": "working"})]
|
||||
verdict = judge.judge_once("/r", judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), 1, prompts.DRIVER), Rung("judge-model"), FakeEffects(claude=[judged("unfinished", escalation="round 2: 🔴")]).effects())
|
||||
verdict = judge.judge_once("/r", judge.Brief("Do it.", "## Goals", "", records.RECORDS_NAMED, prompts.ANSWER_DESTINATIONS, kinds(*entries), 1, prompts.DRIVER), Rung("judge-model"), FakeEffects(claude=[judged("unfinished", escalation="round 2: 🔴")]).effects())
|
||||
self.assertEqual(verdict, Unfinished("working", entries_read=4))
|
||||
|
||||
def test_takes_evidence_from_before_the_workers_last_step_up(self):
|
||||
entries = [assistant({"type": "text", "text": "round 2: 🔴"}), assistant({"type": "text", "text": "working"})]
|
||||
verdict = judge.judge_once("/r", judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), 1, prompts.DRIVER), Rung("judge-model"), FakeEffects(claude=[judged("unfinished", evidence="round 2: 🔴")]).effects())
|
||||
verdict = judge.judge_once("/r", judge.Brief("Do it.", "## Goals", "", records.RECORDS_NAMED, prompts.ANSWER_DESTINATIONS, kinds(*entries), 1, prompts.DRIVER), Rung("judge-model"), FakeEffects(claude=[judged("unfinished", evidence="round 2: 🔴")]).effects())
|
||||
self.assertEqual(verdict, Unfinished("round 2: 🔴", entries_read=2))
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import typing
|
||||
|
||||
|
||||
def piped(stdin: typing.TextIO) -> str:
|
||||
"""The text piped in, empty from a terminal. Claude Code's Bash tool gives a command /dev/null as stdin (readlink /proc/self/fd/0 shows it), so without a heredoc read() returns "" at once."""
|
||||
return "" if stdin.isatty() else stdin.read()
|
||||
@@ -85,6 +85,8 @@ import pathlib
|
||||
import sys
|
||||
import typing
|
||||
|
||||
from text_files.piped_text import piped
|
||||
|
||||
from plan.todo_table import BLOCKED_BY, MOVES
|
||||
from failure import Failure
|
||||
from project_config.main import located
|
||||
@@ -184,11 +186,6 @@ def fields(args: argparse.Namespace) -> dict[str, str]:
|
||||
return {field: value for field, value in given.items() if value is not None}
|
||||
|
||||
|
||||
def piped(stdin: typing.TextIO) -> str:
|
||||
"""The text piped in, empty from a terminal. Claude Code's Bash tool gives a command /dev/null as stdin (readlink /proc/self/fd/0 shows it), so without a heredoc read() returns "" at once."""
|
||||
return "" if stdin.isatty() else stdin.read()
|
||||
|
||||
|
||||
def reported(written: Written | Failure, refusal: str, done: typing.Callable[[Written], str]) -> str | Failure:
|
||||
"""What a write prints: done's line, after the backend's notes on stderr; else the Failure, opened with refusal."""
|
||||
if isinstance(written, Failure):
|
||||
|
||||
@@ -121,6 +121,7 @@ A fix meets every row it fits, except that a fix for a 🟡 meets only the 🟡
|
||||
**Findings.** A reviewer rates each finding 🔴 must fix, 🟡 should fix, 🟢 nit, ❓ question, or 🔀 escalation naming the reviewer whose concern it is.
|
||||
|
||||
- **Outside the chunk.** A finding outside the chunk's change, whatever its pass or severity, is scored and filed in `todo.md` per `~/.claude/rules/todo-items.md`. A 🔴 is marked `defect`. A 🟡 against a file in the config's principles folder is marked `principle`, its detail naming the principle, where no other reason fits. One under the bar and not exempt is named in the summary with its score. A verified security HIGH is handled per "Security". In the release review the whole project is the chunk's change, so nothing lies outside it; "Release review" → "Findings" says which of its findings are filed.
|
||||
- **Under do-epic.** A chunk do-epic runs files a finding about one of the epic's goals in the epic, as its prompt says, in place of `todo.md`. Where unsure whether a finding is about the epic's goals or a repo's, ask the human.
|
||||
- **Goal or decision.** A fix that would change a goal, or a `docs/decisions.md` entry the repo held before the chunk began, is asked; no user reachable → filed, marked `question`, the goal or decision left as is.
|
||||
- **New decision.** Each decision a fix or an answer records in `docs/decisions.md` is checked against the project principles per `~/.claude/rules/decisions.md` → "Decisions: one home, each linked to a goal or a technical principle", "Check each new decision against the project's principles", before the commit that records it.
|
||||
- **🔴.** A 🔴 is fixed, or shown factually wrong, and what disproved it recorded per the review standards' `comments.md` → "Where a choice goes": in a comment at the code the finding concerns, or in `docs/decisions.md` when it concerns more than one place. Never declined.
|
||||
|
||||
@@ -14,8 +14,7 @@
|
||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||
| 441 | 0.12.0 | | | **Move an epic's issue to done in Jira when its chunk finishes, so no finished chunk starts again and what it blocks starts.** | 2 | 2 | 2 | 4 | 3 | 1 by 6 | 2.3 |
|
||||
| 416 | 0.12.0 | | | **Finish an epic's repo item with a bullet under its repo's `CHANGELOG.md` → `## Unreleased`, or with none where the repo's plan is in Jira.** | 1 | 1 | 1 | 1 | 2 | 1 by 5 | 2.1 |
|
||||
| 413 | 0.12.0 | | | **File a finding about an epic goal in the epic and one about a repo goal by that repo's rules, ask the human where unsure which, and give the judge the epic's records beside the repo's.** | 3 | 2 | 3 | 6 | 4 | 1 by 5 | 1.6 |
|
||||
| 415 | 0.12.0 | 413 | | **Finish an epic: run release-review passes on each repo it changed, work what they file, have the human confirm each goal, post a summary comment, and close the epic in Jira last.** | 3 | 2 | 3 | 6 | 5 | 1 by 5 | 1.2 |
|
||||
| 415 | 0.12.0 | | | **Finish an epic: run release-review passes on each repo it changed, work what they file, have the human confirm each goal, post a summary comment, and close the epic in Jira last.** | 3 | 2 | 3 | 6 | 5 | 1 by 5 | 1.2 |
|
||||
| 418 | 0.12.0 | 415 | | **Describe do-epic in `README.md`'s tools and setup, with its machine settings and `repo-rule.md`.** | 1 | 2 | 1 | 2 | 2 | 1 by 5 | 2.1 |
|
||||
| 420 | 0.12.0 | | | **End a worker that printed its final result and lingers, by killing the background shells it left, after a few minutes, and print each kill with its evidence on loop-claude's terminal.** | 2 | 2 | 2 | 4 | 3 | 1.5 by 6 | 2.0 |
|
||||
| 411 | 0.12.0 | | | **Park a chunk whose PR waits on a long gate, keeping its worktree, PR and session in a state file that survives a reboot, and resume its session when the gate passes or a reviewer comments.** | 4 | 2 | 3 | 7 | 6 | 1 by 5 | 0.8 |
|
||||
@@ -97,19 +96,6 @@ Touches:
|
||||
|
||||
- `bin/do_epic/main.py`
|
||||
|
||||
### 413. File a finding about an epic goal in the epic and one about a repo goal by that repo's rules, ask the human where unsure which, and give the judge the epic's records beside the repo's.
|
||||
|
||||
The epic's records are its description's sections (`docs/decisions.md` → `do-epic: drives one Jira epic …`). `read_records` and `read_premises` take the epic's record as a parameter, so loop-claude's judge is unchanged.
|
||||
|
||||
Touches:
|
||||
|
||||
- `bin/loop_claude/project/records.py`: `read_records` (small)
|
||||
- `bin/loop_claude/project/premises.py`: `read_premises` (small)
|
||||
- `bin/agent_cycle/judge.py`: `judge_prompt` (small)
|
||||
- `bin/loop_claude/cycle/prompts.py`: `ANSWER_DESTINATIONS` (small)
|
||||
- `skills/larv-review/SKILL.md`: `## 3. Passes` (small)
|
||||
- `bin/do_epic/findings.py`
|
||||
|
||||
### 415. Finish an epic: run release-review passes on each repo it changed, work what they file, have the human confirm each goal, post a summary comment, and close the epic in Jira last.
|
||||
|
||||
A goal is met only where the human confirms it: each achieve goal achieved, and no defect against a maintain goal. For a goal that isn't met, do-epic proposes a set of items, and the human approves the set before work starts (`docs/decisions.md` → `do-epic: drives one Jira epic …`). The summary names what shipped per repo and each goal's evidence, in the epic's language. The epic's transition is configured as `todo-item finish`'s is.
|
||||
|
||||
Reference in New Issue
Block a user