Fix under the floor's Shape: interrupt means only the human, QuotedAnswer names the verdict, one owner for the record files, Limited beside its cycle

This commit is contained in:
2026-10-03 11:33:34 +02:00
parent fdc3bc38d4
commit 2d46aa3b8f
10 changed files with 68 additions and 59 deletions
+18 -17
View File
@@ -1,30 +1,31 @@
import dataclasses
from loop_claude.cycle.verdicts import AnsweredFromRecords, Finished, Interrupt, Unfinished, Verdict
from loop_claude.cycle.verdicts import Finished, Interrupt, QuotedAnswer, Unfinished, Verdict
from loop_claude.project.records import QUOTE_SOURCES
# A backstop for what the judge misses, such as a reworded repeat, so the worker cannot loop unattended on answers quoted from README.md or the records.
RECORDS_ANSWERS_PER_CYCLE = 3
QUOTED_ANSWERS_PER_CYCLE = 3
@dataclasses.dataclass(frozen=True)
class Working:
"""The worker runs, resumed with an answer quoted from README.md or the records when there is one."""
answered: AnsweredFromRecords | None = None
records_answers: int = 0
answered: QuotedAnswer | None = None
quoted_answers: int = 0
@dataclasses.dataclass(frozen=True)
class Judging:
"""The judge rules; records_answers counts the questions README.md or the records answered this cycle."""
"""The judge rules; quoted_answers counts the questions README.md or the records answered this cycle."""
transcript_path: str
records_answers: int = 0
quoted_answers: int = 0
@dataclasses.dataclass(frozen=True)
class Interrupting:
transcript_path: str
question: str
records_answers: int = 0
quoted_answers: int = 0
@dataclasses.dataclass(frozen=True)
@@ -67,19 +68,19 @@ Event = WorkerRan | Ruled | HumanAnswered | Archived
def transition(state: State, event: Event) -> State:
match state, event:
case Working(_, records_answers), WorkerRan(transcript_path):
return Judging(transcript_path, records_answers)
case Judging(_, records_answers), Ruled(AnsweredFromRecords() as answered) if records_answers < RECORDS_ANSWERS_PER_CYCLE:
return Working(answered, records_answers + 1)
case Judging(transcript_path, records_answers), Ruled(AnsweredFromRecords(question=question, answer=answer)):
return Interrupting(transcript_path, f"{question}\n\nREADME.md, AGENTS.md or docs/decisions.md say:\n{answer}\n\nThey answered {records_answers} questions this cycle, so this one comes to you.", records_answers)
case Judging(transcript_path, records_answers), Ruled(Interrupt(question=question)):
return Interrupting(transcript_path, question, records_answers)
case Working(_, quoted_answers), WorkerRan(transcript_path):
return Judging(transcript_path, quoted_answers)
case Judging(_, quoted_answers), Ruled(QuotedAnswer() as answered) if quoted_answers < QUOTED_ANSWERS_PER_CYCLE:
return Working(answered, quoted_answers + 1)
case Judging(transcript_path, quoted_answers), Ruled(QuotedAnswer(question=question, answer=answer)):
return Interrupting(transcript_path, f"{question}\n\n{QUOTE_SOURCES} says:\n{answer}\n\nThey answered {quoted_answers} questions this cycle, so this one comes to you.", quoted_answers)
case Judging(transcript_path, quoted_answers), Ruled(Interrupt(question=question)):
return Interrupting(transcript_path, question, quoted_answers)
case Judging(transcript_path, _), Ruled(Finished() | Unfinished() as verdict):
return Closing(transcript_path, verdict)
# The human works in the interrupt's claude session, so the judge rules again on the transcript it leaves.
case Interrupting(transcript_path, _, records_answers), HumanAnswered():
return Judging(transcript_path, records_answers)
case Interrupting(transcript_path, _, quoted_answers), HumanAnswered():
return Judging(transcript_path, quoted_answers)
case Closing(), Archived():
return Ended()
raise ValueError(f"no transition from {state} on {event}")