"""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; a chunk that was parked is first told why it resumes.""" import dataclasses from do_epic.backend.protocol import EpicIssue from model_routing.ladder import ProjectRung from loop_claude.cycle import prompts from model_routing.route import Route from agent_cycle.worker_prompts import WorkerPrompts # The entry point's name as the worker, the judge and the human read it. 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.""" 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 "") CODE_HEALTH = '~/.claude/CLAUDE.md → "Shared goal"' def fresh(task: str, premises: str, route: Route, project: ProjectRung | None, facts: str) -> str: """A chunk's first prompt. facts is empty: do-epic runs no preflight.""" routed = f"{DRIVER} runs you on {route.rung}, routed by the issue's L of {route.likelihood}. Where a sentence below names item {route.item}, it means the issue." if route.item else "" opening = " ".join(filter(None, [routed, *prompts.rung_sentences(DRIVER, route, project)])) return f"{task}\n\nContinue any open draft PR or worktree for the chunk before creating a new one. {prompts.READING_RULE}\n\n{opening and f'{opening}{chr(10)}{chr(10)}'}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 ({CODE_HEALTH}), then the repo's.\n\nFrom {premises}" # The worker names no plan items: the chunk's one item is its issue. WORKER = prompts.worker_prompts(DRIVER, fresh, "") # 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 it, answer the rest in its thread, and change the setup so review would have caught it (~/.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.' def unparked(news: str) -> WorkerPrompts: """The prompts of the first cycle after a parked chunk resumes: WORKER's, with each prompt that starts a worker opening with news, which says what the chunk waited on and what changed. The fresh prompt opens with it too, since a chunk the judge ruled finished before it parked has no session left to resume.""" opening = f"{news} {FEEDBACK}\n\n" return dataclasses.replace(WORKER, fresh=lambda *task: opening + WORKER.fresh(*task), resumed=lambda *evidence: opening + WORKER.resumed(*evidence))