"""What loop-claude alone says to its worker: the first prompt of a chunk, with what chunk-preflight found. The resumed prompt and the rung sentences are chunk_driver.prompts', which do-epic's cycles use too.""" import functools from loop_claude.chunk.chunk_items import CHUNK_ITEMS from chunk_driver.drivers import LOOP_CLAUDE from model_routing.ladder import ProjectRung from chunk_driver.prompts import READING_RULE, rung_sentences, worker_prompts from model_routing.route import Route # loop-claude's name as its workers, its judge and the human read it. A function below that takes a driver words a sentence for any entry point, such as do-epic. DRIVER = LOOP_CLAUDE # chunk_items reads the latest such line; three fresh readers picked the label (docs/decisions.md → `routing: loop-claude reads the items a chunk takes`). NAME_THE_ITEMS = f"Name every plan item this chunk takes on one line, as in `{CHUNK_ITEMS} 297 (L 3, E + I 5), 298 (L 3, E + I 7)`, and write the whole line again whenever the set changes." AFTER_CODE_HEALTH = 'which rank after code health (~/.claude/CLAUDE.md → "Shared goal") unless the goals file voids it' def fresh(driver: str, task: str, premises: str, route: Route, project: ProjectRung | None, facts: str) -> str: """A chunk's first prompt; facts is preflight_facts' or preflight_failed's text.""" routed = f"{routed_by(driver, route, project)} {recount(route)}" if route.item else " ".join(rung_sentences(driver, route, project)) opening = f"{routed}\n\n" if routed else "" return f"{task}\n\nContinue any open draft PR or worktree for the chunk before creating a new one. {READING_RULE} {NAME_THE_ITEMS}\n\n{opening}{facts}\n\nThe chunk's plan items, or else the task above, set its scope. The goals below, {AFTER_CODE_HEALTH}, choose between ways to deliver that scope, and never widen it.\n\nFrom the goals file, {premises}" def routed_by(driver: str, route: Route, project: ProjectRung | None) -> str: return " ".join(( f"{driver} runs you on {route.rung}, routed by item {route.item}'s L of {route.likelihood}.", *rung_sentences(driver, route, project), )) def recount(route: Route) -> str: """Has the worker count the routing item's size again once it knows the code, since the L that routed it was scored before anyone read that code.""" return f"After your first read of the code, count item {route.item}'s size again: the lines, files and components you will change. Where that count would change its L, have a subagent that scores plan items re-score it; a re-score whose L picks a rung above yours is escalation trigger 1." def preflight_facts(printed: str) -> str: """What chunk-preflight printed, for the worker to take as found.""" return f"loop-claude ran `~/.claude/bin/chunk-preflight` at the checkout root just before this run. Take what it printed as found rather than finding it again:\n\n{printed}" def held_by_others(items: list[int]) -> str: """Keeps a fresh worker off the plan items the project's other chunks hold, running or stopped.""" return f"\n\nOther chunks of this project, running or stopped, hold {'items ' if len(items) > 1 else 'item '}{', '.join(map(str, items))}. Leave those items out of this chunk, even where the facts above list them as items that may join it." def preflight_failed(reason: str) -> str: """Has the worker find the facts chunk-preflight would have, its worktree among them.""" return f"loop-claude could not run `~/.claude/bin/chunk-preflight`, so find the chunk's facts yourself. Why it could not run: {reason}" WORKER = worker_prompts(DRIVER, functools.partial(fresh, DRIVER), NAME_THE_ITEMS)