from loop_claude.project.records import HUMAN_RULES, RECORD_FILES # Where the judge may quote an answer from, named as the human and the worker see them; of README.md the judge sees only the premises. QUOTE_SOURCES = "README.md's Goals and Audience, " + ", ".join(RECORD_FILES) + " or " + HUMAN_RULES # Where the worker may write an answer the human typed, so it counts as recorded. ANSWER_DESTINATIONS = "README.md's Goals or Audience, " + ", ".join(RECORD_FILES) + ", todo.md or a comment" ANSWERS_RECORDED = f"every answer the human typed in it that a later chunk could need is recorded in {ANSWER_DESTINATIONS} at the one place it governs" JUDGE_RULES = ( "Decide whether the human must now be interrupted. interrupt=true when any of these appear:\n" "- the agent asks the human anything, seeks approval, or says a decision is the human's, and neither " "README.md nor the records settle the matter\n" "- it asks again a question a [loop] line already answered\n" "- it carried on under an assumption that decides the deliverable, that the human could " "reasonably reject and that neither README.md nor the records settle; a caveat about " "transient state it then handled is not one\n" "- it is blocked on something only the human can supply: a credential, a version bump, a choice " "outside the repo, or a release ready to cut, which only the human may publish\n" "- it flags that the goals, the plan in todo.md or the task itself is unclear, missing or in need of change\n" "- it chose between alternatives that neither README.md nor the records discriminate " "between - neither rules the rejected one out - and the choice materially changes the deliverable\n" "interrupt=false otherwise. Bookkeeping the agent settled silently - what to document, wording, " "where a note goes - is not on its own a reason to interrupt. The human may have replied inside the transcript, on a [human] line: judge only what " "is still open, never a question they already answered there. A [loop] line is what loop-claude told " "the agent, such as an answer quoted from README.md or the records.\n" "Where the agent asked or flagged something itself, the question is that one, in the agent's own " "wording; never construct another from facts it stated.\n" "Where README.md or the records answer the agent's own question and no [loop] line has " "quoted that answer yet, set interrupt=false and quote the passage that answers it; the agent is " "then given that passage in place of the human's reply. An interrupt outranks a quoted answer, and either " "outranks finished.\n" "The chunk is the piece of work the agent is on, shipped as one pull request. " "finished=true when the chunk is complete: merged, or nothing remains that the agent could do on " f"its own. Even then, it is finished only once {ANSWERS_RECORDED}. An answer counts as recorded " f"where README.md or the records above hold it, {HUMAN_RULES} included. It also counts where " f"the transcript shows the agent writing it into {ANSWER_DESTINATIONS}; writing it into " f"{HUMAN_RULES} does not count. finished=false when work remains that a further run can " "continue: an open PR, a review not yet run, CI not yet reported, an answer not yet recorded." ) def fresh(task: str) -> str: return f"{task}\n\nContinue any open draft PR or worktree for the chunk before creating a new one." def resumed(unfinished_evidence: str) -> str: ruled = f" A judge ruled the chunk unfinished, quoting this passage of your transcript as the work remaining:\n\n{quoted(unfinished_evidence)}\n\n" if unfinished_evidence else " " return f"Continue the task; the previous run ended before the chunk was finished.{ruled}The chunk is finished once it is merged, or nothing remains that you could do on your own. Even then, it is finished only once {ANSWERS_RECORDED}." def answered(question: str, answer: str) -> str: return f"Your question: {question}\n\n{QUOTE_SOURCES} answers it:\n\n{answer}\n\nContinue the task." def past_the_cap(question: str, answer: str, cap: int) -> str: """The question a quoted answer puts to the human once the cycle's quoted answers reach the cap.""" return f"{question}\n\n{QUOTE_SOURCES} says:\n{answer}\n\nThose files have answered {cap} questions this cycle, the most allowed, so this one comes to you." # Blockquoted, so a passage holding blank lines still ends visibly where the text after it starts. def quoted(passage: str) -> str: return "\n".join(f"> {line}" for line in passage.splitlines())