Answer architecture round 1: 0 🔴, 2 🟡; keep stepped_from through the typed answer, name the events HumanTyped and HumanTalked, parse the answer from the prompt's start, and say why the judge decides release_ready
This commit is contained in:
@@ -143,7 +143,7 @@ class Streamed:
|
||||
return self.code
|
||||
|
||||
|
||||
TYPED = states.TypedAnswer("Which one?", "Use B.", False)
|
||||
TYPED = states.TypedAnswer("Which one?", "Use B.")
|
||||
|
||||
|
||||
class Transitions(unittest.TestCase):
|
||||
@@ -161,10 +161,10 @@ class Transitions(unittest.TestCase):
|
||||
(states.Judging("/t", 3), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))),
|
||||
(states.Judging("/t"), states.Ruled(Unfinished("e")), states.Closing("/t", Unfinished("e"))),
|
||||
(states.Judging("/t", 3), states.Ruled(Unfinished("e")), states.Closing("/t", Unfinished("e"))),
|
||||
(states.Interrupting("/t", Interrupt("e", "q")), states.HumanAnswered(), states.Judging("/t")),
|
||||
(states.Interrupting("/t", Interrupt("e", "q"), 3), states.HumanAnswered(), states.Judging("/t", 3)),
|
||||
(states.Interrupting("/t", Interrupt("e", "q")), states.HumanAnswered(TYPED), states.Working(TYPED)),
|
||||
(states.Interrupting("/t", Interrupt("e", "q"), 3), states.HumanAnswered(TYPED), states.Working(TYPED, 3)),
|
||||
(states.Interrupting("/t", Interrupt("e", "q")), states.HumanTalked(), states.Judging("/t")),
|
||||
(states.Interrupting("/t", Interrupt("e", "q"), 3), states.HumanTalked(), states.Judging("/t", 3)),
|
||||
(states.Interrupting("/t", Interrupt("e", "q")), states.HumanTyped(TYPED), states.Working(TYPED)),
|
||||
(states.Interrupting("/t", Interrupt("e", "q"), 3), states.HumanTyped(TYPED), states.Working(TYPED, 3)),
|
||||
(states.Working(TYPED, 3), states.WorkerRan("/t"), states.Judging("/t", 3)),
|
||||
(states.Closing("/t", Finished("e")), states.Archived(), states.Ended(Finished("e"))),
|
||||
(states.Closing("/t", Unfinished("e")), states.Archived(), states.Ended(Unfinished("e"))),
|
||||
@@ -173,7 +173,7 @@ class Transitions(unittest.TestCase):
|
||||
with self.subTest(state=state, event=event):
|
||||
self.assertEqual(states.transition(state, event), after)
|
||||
every_state = (states.Working(), states.Working(QuotedAnswer("e", "Which one?", "A."), 3), states.Working(TYPED, 3), states.Judging("/t"), states.Judging("/t", 3), states.Interrupting("/t", Interrupt("e", "q")), states.Interrupting("/t", Interrupt("e", "q"), 3), states.Closing("/t", Finished("e")), states.Ended(Finished("e")))
|
||||
every_event = (states.WorkerRan("/t"), states.Ruled(Interrupt("e", "Which one?")), answered, states.Ruled(Finished("e")), states.Ruled(Unfinished("e")), states.HumanAnswered(), states.HumanAnswered(TYPED), states.Archived())
|
||||
every_event = (states.WorkerRan("/t"), states.Ruled(Interrupt("e", "Which one?")), answered, states.Ruled(Finished("e")), states.Ruled(Unfinished("e")), states.HumanTalked(), states.HumanTyped(TYPED), states.Archived())
|
||||
for state in every_state:
|
||||
for event in every_event:
|
||||
if (state, event) not in [(state, event) for state, event, _ in legal]:
|
||||
@@ -384,10 +384,10 @@ class Cycles(unittest.TestCase):
|
||||
self.assertEqual(fake.made("claude_on_terminal"), [])
|
||||
resumed = fake.made("stream_claude")[1]
|
||||
self.assertEqual(resumed[resumed.index("--resume") + 1], str(self.session.id))
|
||||
self.assertEqual(resumed[resumed.index("-p") + 1], "Your question: Which one?\n\nThe human answers it at loop-claude's terminal:\n\nUse B.\n\nContinue the task.")
|
||||
self.assertEqual(resumed[resumed.index("-p") + 1], "The human answered your question at loop-claude's terminal:\nUse B.\n\nYour question was: Which one?\n\nContinue the task.")
|
||||
judge_prompts = [stdin for args, stdin in fake.made("claude")]
|
||||
self.assertTrue(judge_prompts[1].split("\n\nDecide whether")[0].endswith("[human] Use B.\n\nworking"))
|
||||
self.assertNotIn("[loop] Your question", judge_prompts[1])
|
||||
self.assertNotIn("[loop] The human answered", judge_prompts[1])
|
||||
|
||||
def test_an_interrupt_that_steps_the_worker_up_names_its_new_rung_in_the_prompt_that_resumes_it_with_the_typed_answer(self):
|
||||
fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)] * 2, claude=[judged("interrupt", escalation="working"), judged("finished")], inputs=["Use B."])
|
||||
@@ -397,7 +397,7 @@ class Cycles(unittest.TestCase):
|
||||
self.assertEqual(concluded.route, Route(Routing.OPUS, 179, 2, 5))
|
||||
first, resumed = fake.made("stream_claude")
|
||||
self.assertEqual([args[args.index("--effort") + 1] for args in (first, resumed)], ["high", "medium"])
|
||||
self.assertTrue(resumed[resumed.index("-p") + 1].endswith(f"Use B.\n\nContinue the task. Your request for a higher rung went through: loop-claude runs you on {Routing.OPUS}.{prompts.rungs_held(concluded.route, Routing.OPUS)} A further request for a higher rung steps you up no more in this cycle."))
|
||||
self.assertEqual(resumed[resumed.index("-p") + 1], f"The human answered your question at loop-claude's terminal:\nUse B.\n\nYour question was: Which one?\n\nContinue the task. Your request for a higher rung went through: loop-claude runs you on {Routing.OPUS}.{prompts.rungs_held(concluded.route, Routing.OPUS)} A further request for a higher rung steps you up no more in this cycle.")
|
||||
|
||||
def test_a_release_ready_to_cut_opens_claudes_session_without_asking_for_an_answer(self):
|
||||
def answer(args):
|
||||
@@ -513,59 +513,44 @@ class Limits(unittest.TestCase):
|
||||
|
||||
|
||||
class Interrupts(unittest.TestCase):
|
||||
def ask(self, fake, home="/h", path="/t", rung=Rung("m"), env=None, release_ready=False):
|
||||
with contextlib.redirect_stderr(io.StringIO()) as said:
|
||||
asked = interrupt.interrupt(home, uuid7(), rung, path, "Which one?", release_ready, paths.paths_from(pathlib.Path(home)), env or {}, fake.effects())
|
||||
self.said = said.getvalue()
|
||||
return asked
|
||||
def test_puts_the_question_and_stops_off_a_terminal(self):
|
||||
for on_terminal, want in ((False, Stop(2, "the human is needed to answer the question above, but stdin or stdout is not a terminal; rerun loop-claude on a terminal")), (True, None)):
|
||||
with self.subTest(on_terminal=on_terminal):
|
||||
fake = FakeEffects(on_terminal=on_terminal)
|
||||
with contextlib.redirect_stderr(io.StringIO()) as said:
|
||||
self.assertEqual(interrupt.put_question("Which one?", fake.effects()), want)
|
||||
self.assertEqual(said.getvalue(), "\nWhich one?\n")
|
||||
self.assertEqual(fake.calls, [])
|
||||
|
||||
def test_stops_off_a_terminal_before_asking(self):
|
||||
fake = FakeEffects(on_terminal=False)
|
||||
self.assertEqual(self.ask(fake), Stop(2, "the human is needed to answer the question above, but stdin or stdout is not a terminal; rerun loop-claude on a terminal"))
|
||||
self.assertEqual(fake.calls, [])
|
||||
|
||||
def test_returns_the_answer_typed_at_the_terminal_without_starting_claude(self):
|
||||
fake = FakeEffects(inputs=[" Use B. "])
|
||||
self.assertEqual(self.ask(fake), "Use B.")
|
||||
self.assertEqual(self.said, "\nWhich one?\n")
|
||||
self.assertEqual(fake.made("input"), ["Answer (/talk opens claude, Enter stops the loop): "])
|
||||
self.assertEqual(fake.made("claude_on_terminal"), [])
|
||||
def test_reads_the_line_typed_at_the_terminal_stripped(self):
|
||||
for typed, want in ((" Use B. ", "Use B."), (" /talk ", "/talk")):
|
||||
with self.subTest(typed=typed):
|
||||
fake = FakeEffects(inputs=[typed])
|
||||
self.assertEqual(interrupt.read_answer(fake.effects()), want)
|
||||
self.assertEqual(fake.made("input"), ["Answer (/talk opens claude, Enter stops the loop): "])
|
||||
|
||||
def test_stops_on_an_empty_answer_or_the_inputs_end(self):
|
||||
for typed, why in ((" ", "nothing was typed"), (EOFError(), "the input ended")):
|
||||
with self.subTest(why=why):
|
||||
fake = FakeEffects(inputs=[typed])
|
||||
self.assertEqual(self.ask(fake), Stop(2, f"the human is needed to answer the question above, but {why}"))
|
||||
self.assertEqual(fake.made("claude_on_terminal"), [])
|
||||
|
||||
def test_opens_claudes_session_on_talk_and_at_once_for_a_release_ready_to_cut(self):
|
||||
for typed, release_ready in ((["/talk"], False), ([" /talk "], False), ([], True)):
|
||||
with self.subTest(typed=typed), tempfile.TemporaryDirectory() as home:
|
||||
path = pathlib.Path(home, "t.jsonl")
|
||||
path.write_text(json.dumps(human("a")) + "\n")
|
||||
def answer(args):
|
||||
with open(path, "a") as handle:
|
||||
handle.write(json.dumps(human("B")) + "\n")
|
||||
return 0
|
||||
fake = FakeEffects(inputs=typed, on_terminal_claude=[answer], git=[ran()])
|
||||
self.assertIsNone(self.ask(fake, home, str(path), Rung("m", "high"), release_ready=release_ready))
|
||||
self.assertEqual(fake.made("claude_on_terminal")[0][:4], ["--model", "m", "--effort", "high"])
|
||||
self.assertEqual(len(fake.made("input")), len(typed))
|
||||
for typed, why, said in ((" ", "nothing was typed", ""), (EOFError(), "the input ended", "\n")):
|
||||
with self.subTest(why=why), contextlib.redirect_stderr(io.StringIO()) as printed:
|
||||
self.assertEqual(interrupt.read_answer(FakeEffects(inputs=[typed]).effects()), Stop(2, f"the human is needed to answer the question above, but {why}"))
|
||||
self.assertEqual(printed.getvalue(), said)
|
||||
|
||||
def test_stops_when_nothing_was_typed_in_the_session(self):
|
||||
with tempfile.TemporaryDirectory() as home:
|
||||
path = pathlib.Path(home, "t.jsonl")
|
||||
path.write_text(json.dumps(human("a")) + "\n")
|
||||
fake = FakeEffects(inputs=["/talk"], on_terminal_claude=[0], git=[ran()])
|
||||
self.assertEqual(self.ask(fake, home, str(path)), Stop(2, "the human is needed to answer the question above, but the interrupt ended with nothing typed"))
|
||||
fake = FakeEffects(on_terminal_claude=[0], git=[ran()])
|
||||
stop = interrupt.talk(home, uuid7(), Rung("m", "high"), str(path), paths.paths_from(pathlib.Path(home)), {}, fake.effects())
|
||||
self.assertEqual(fake.made("claude_on_terminal")[0][:4], ["--model", "m", "--effort", "high"])
|
||||
self.assertEqual(stop, Stop(2, "the human is needed to answer the question above, but the interrupt ended with nothing typed"))
|
||||
|
||||
def test_hands_the_claude_that_takes_the_terminal_the_workers_environment(self):
|
||||
with tempfile.TemporaryDirectory() as home:
|
||||
path = pathlib.Path(home, "t.jsonl")
|
||||
path.write_text(json.dumps(human("a")) + "\n")
|
||||
fake = FakeEffects(inputs=["/talk"], on_terminal_claude=[0], git=[ran()])
|
||||
fake = FakeEffects(on_terminal_claude=[0], git=[ran()])
|
||||
handed = {"LOOP_CLAUDE_PROJECT_RUNG": "claude-opus-5-5 at medium effort", "LOOP_CLAUDE_WORKER_RUNG": "claude-haiku-5-5 at max effort"}
|
||||
self.ask(fake, home, str(path), Rung("claude-haiku-5-5", "max"), handed)
|
||||
interrupt.talk(home, uuid7(), Rung("claude-haiku-5-5", "max"), str(path), paths.paths_from(pathlib.Path(home)), handed, fake.effects())
|
||||
self.assertEqual(fake.terminal_environments, [handed])
|
||||
|
||||
|
||||
@@ -976,12 +961,14 @@ class PythonEffect(unittest.TestCase):
|
||||
|
||||
|
||||
class TypedAnswers(unittest.TestCase):
|
||||
def test_finds_the_answer_in_the_prompt_that_hands_it_over_and_in_no_other_prompt(self):
|
||||
def test_finds_the_answer_on_the_line_after_the_marker_that_opens_the_prompt_handing_it_over_and_in_no_other_prompt(self):
|
||||
route = Route(Rung("worker-model"))
|
||||
self.assertEqual(prompts.typed_answer(prompts.typed("Which one?\n\nThe human answers it at loop-claude's terminal:\n\nA?", "Use B.", route, None, False)), "Use B.")
|
||||
marked = "The human answered your question at loop-claude's terminal:\nB"
|
||||
self.assertEqual(prompts.typed_answer(prompts.typed("Which one?", "Use B.", route, None, False)), "Use B.")
|
||||
self.assertEqual(prompts.typed_answer(prompts.typed(f"Which one?\n{marked}", "Use B.", route, None, False)), "Use B.")
|
||||
self.assertEqual(prompts.typed_answer(prompts.typed("Which one?", "Use B.", Route(Routing.SONNET, 179, 2, 5), Routing.OPUS, True)), "Use B.")
|
||||
self.assertIsNone(prompts.typed_answer(prompts.answered("Which one?", "Use B.", route, None, False)))
|
||||
self.assertIsNone(prompts.typed_answer(prompts.resumed("Your question: A\n\nThe human answers it at loop-claude's terminal:\n\nB", route, None)))
|
||||
self.assertIsNone(prompts.typed_answer(prompts.answered("Which one?", marked, route, None, False)))
|
||||
self.assertIsNone(prompts.typed_answer(prompts.resumed(marked, route, None)))
|
||||
|
||||
|
||||
class WorkerArgs(unittest.TestCase):
|
||||
|
||||
Reference in New Issue
Block a user