Name the driver of a cycle in the text its worker, judge and human read
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
An entry point is a tool that drives cycles, such as loop-claude. It words the prompts of its own workflow and names the files of its project. WorkerPrompts holds those, so the cycle doesn't import an entry point to word a prompt.
|
||||
"""
|
||||
import dataclasses
|
||||
import re
|
||||
import typing
|
||||
|
||||
from model_routing.ladder import ProjectRung
|
||||
@@ -10,7 +11,9 @@ from model_routing.route import Route
|
||||
from claude_code.transcript import Typed
|
||||
|
||||
# Opens typed's prompt, with the answer on the line after it, so typed_answer finds the answer at the prompt's start, whatever the question holds.
|
||||
TYPED_HERE = "The human answered your question at loop-claude's terminal:"
|
||||
TYPED_HERE = "The human answered your question at {driver}'s terminal:"
|
||||
# Finds TYPED_HERE whatever the driver, so a transcript reads the same to every tool that renders it.
|
||||
TYPED_OPENING = re.compile(re.escape(TYPED_HERE).replace(re.escape("{driver}"), r"[\w-]+") + "\n")
|
||||
|
||||
|
||||
def answers_recorded(destinations: str) -> str:
|
||||
@@ -20,16 +23,18 @@ def answers_recorded(destinations: str) -> str:
|
||||
|
||||
def typed_answer(prompt: str) -> Typed | None:
|
||||
"""Splits a prompt from WorkerPrompts.typed into its answer and the rest, so the judge reads the answer as the human's; None for any other prompt."""
|
||||
opening = f"{TYPED_HERE}\n"
|
||||
if not prompt.startswith(opening):
|
||||
opening = TYPED_OPENING.match(prompt)
|
||||
if not opening:
|
||||
return None
|
||||
answer, _, rest = prompt.removeprefix(opening).partition("\n\n")
|
||||
answer, _, rest = prompt[opening.end():].partition("\n\n")
|
||||
return Typed(rest, answer)
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class WorkerPrompts:
|
||||
"""What an entry point supplies to the prompts of its cycles."""
|
||||
# The entry point's name as the worker, the judge and the human read it, such as `do-epic`.
|
||||
driver: str
|
||||
# The prompt that starts a worker, from its task, the premises, its route, the project's rung and the facts found before the cycle.
|
||||
fresh: typing.Callable[[str, str, Route, ProjectRung | None, str], str]
|
||||
# The prompt that resumes a worker whose previous run ended before the chunk was finished, from the evidence of the unfinished verdict, if there was one.
|
||||
@@ -47,11 +52,11 @@ class WorkerPrompts:
|
||||
|
||||
def typed(self, question: str, answer: str, route: Route, project: ProjectRung | None, stepped: bool) -> str:
|
||||
"""The prompt that resumes the worker with the human's answer to an interrupt. answer is one line, as the terminal reads it."""
|
||||
return f"{TYPED_HERE}\n{answer}\n\nYour question was: {question}\n\nContinue the task. The chunk is finished only once {answers_recorded(self.answer_destinations)}.{self.stepped_to(route, project, stepped)}"
|
||||
return f"{TYPED_HERE.format(driver=self.driver)}\n{answer}\n\nYour question was: {question}\n\nContinue the task. The chunk is finished only once {answers_recorded(self.answer_destinations)}.{self.stepped_to(route, project, stepped)}"
|
||||
|
||||
def stepped_to(self, route: Route, project: ProjectRung | None, stepped: bool) -> str:
|
||||
"""The sentences naming the worker's new rung, as resumed has them, where the ruling that brought the answer stepped the worker up; empty otherwise."""
|
||||
return f" Your request for a higher rung went through: loop-claude runs you on {route.rung}. The escalation triggers that fired before this step are spent.{self.rungs_held(route, project)}" if stepped else ""
|
||||
return f" Your request for a higher rung went through: {self.driver} runs you on {route.rung}. The escalation triggers that fired before this step are spent.{self.rungs_held(route, project)}" if stepped else ""
|
||||
|
||||
def past_the_cap(self, 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."""
|
||||
|
||||
Reference in New Issue
Block a user