Answer the architect's first round
This commit is contained in:
@@ -4,37 +4,38 @@ from loop_claude.cycle.verdicts import Finished, Interrupt, Unfinished, Verdict
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Fresh:
|
||||
"""No transcript: the worker opens the session."""
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Resuming:
|
||||
"""The session's transcript exists: the worker continues it."""
|
||||
class Working:
|
||||
"""The worker runs: opening the session, or resuming it while its transcript exists."""
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Judging:
|
||||
transcript: str
|
||||
transcript_path: str
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Interrupting:
|
||||
transcript: str
|
||||
transcript_path: str
|
||||
question: str
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Finishing:
|
||||
transcript: str
|
||||
transcript_path: str
|
||||
|
||||
|
||||
State = Fresh | Resuming | Judging | Interrupting | Finishing
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Ended:
|
||||
"""The cycle is over; the next one starts Working."""
|
||||
|
||||
|
||||
Active = Working | Judging | Interrupting | Finishing
|
||||
State = Active | Ended
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class WorkerRan:
|
||||
transcript: str
|
||||
transcript_path: str
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -55,23 +56,18 @@ class Archived:
|
||||
Event = WorkerRan | Ruled | Answered | Archived
|
||||
|
||||
|
||||
def opening(transcript: str) -> Fresh | Resuming:
|
||||
return Resuming() if transcript else Fresh()
|
||||
|
||||
|
||||
def transition(state: State, event: Event) -> State:
|
||||
"""The state after event; a cycle ends when it reaches Fresh or Resuming again."""
|
||||
match state, event:
|
||||
case Fresh() | Resuming(), WorkerRan(transcript):
|
||||
return Judging(transcript)
|
||||
case Judging(transcript), Ruled(Interrupt(question=question)):
|
||||
return Interrupting(transcript, question)
|
||||
case Judging(transcript), Ruled(Finished()):
|
||||
return Finishing(transcript)
|
||||
case Working(), WorkerRan(transcript_path):
|
||||
return Judging(transcript_path)
|
||||
case Judging(transcript_path), Ruled(Interrupt(question=question)):
|
||||
return Interrupting(transcript_path, question)
|
||||
case Judging(transcript_path), Ruled(Finished()):
|
||||
return Finishing(transcript_path)
|
||||
case Judging(), Ruled(Unfinished()):
|
||||
return Resuming()
|
||||
case Interrupting(transcript), Answered():
|
||||
return Judging(transcript)
|
||||
return Ended()
|
||||
case Interrupting(transcript_path), Answered():
|
||||
return Judging(transcript_path)
|
||||
case Finishing(), Archived():
|
||||
return Fresh()
|
||||
return Ended()
|
||||
raise ValueError(f"no transition from {state} on {event}")
|
||||
|
||||
Reference in New Issue
Block a user