Name the driver of a cycle in the text its worker, judge and human read
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
"""The escalation mark makes one escalation trigger step the worker up one rung, never two (docs/decisions.md → `routing: a worker whose run ends asking for a higher rung`).
|
||||
|
||||
A worker whose run ends asking loop-claude for a higher rung cites the trigger that fired, and the judge quotes the passage where it fired as the verdict's escalation. The mark, Route.escalated_at, is how many transcript entries the session held when an escalation last stepped the worker up, 0 before any. The session's transcript only grows, so the mark holds across cycles, and the archive's Worker: lines keep it for a rerun.
|
||||
A worker whose run ends asking its driver, such as loop-claude, for a higher rung cites the trigger that fired, and the judge quotes the passage where it fired as the verdict's escalation. The mark, Route.escalated_at, is how many transcript entries the session held when an escalation last stepped the worker up, 0 before any. The session's transcript only grows, so the mark holds across cycles, and the archive's Worker: lines keep it for a rerun.
|
||||
|
||||
- Stamp. stamped() writes on the judge's verdict how many entries the judge read.
|
||||
- Step. routing.next_route() steps the worker up on an escalation and moves the mark to moved_to(verdict).
|
||||
- Show. transcript() puts STEP_LINE after the mark, telling the judge that the triggers before that line are spent. QUOTE_AFTER_STEP, in the judge's schema, tells the judge to quote only the worker's words after that line.
|
||||
- Show. transcript() puts step_line after the mark, telling the judge that the triggers before that line are spent. quote_after_step, in the judge's schema, tells the judge to quote only the worker's words after that line.
|
||||
- Check. checked() keeps an escalation only where it quotes both the transcript the judge was shown and the worker's own lines after the mark, which after_mark() renders, so a passage that bought one step cannot buy another.
|
||||
"""
|
||||
import dataclasses
|
||||
@@ -17,9 +17,20 @@ from agent_cycle.quotes import verbatim
|
||||
|
||||
# Only the judge reads the step line, so it is not a [loop] line.
|
||||
STEP_TAG = "[step]"
|
||||
STEP_LINE = f"{STEP_TAG} loop-claude stepped the worker up a rung here, so the escalation triggers that fired before this line are spent."
|
||||
# Reply.escalation's description in agent_cycle/judge.py carries this sentence, so the judge reads STEP_LINE as the mark.
|
||||
QUOTE_AFTER_STEP = f"Where a {STEP_TAG} line says loop-claude stepped the worker up a rung, quote only the worker's own words after it, and leave this empty where the trigger fired only before it."
|
||||
|
||||
|
||||
def asks_higher_rung(driver: str) -> str:
|
||||
"""How a worker's run ends where it wants the rest of its chunk on a higher rung. The worker's prompt tells it to, and the judge's rules name the same words, so both take them from here. driver is the entry point that drives the cycle, such as `do-epic`."""
|
||||
return f"asking {driver} for a higher rung"
|
||||
|
||||
|
||||
def step_line(driver: str) -> str:
|
||||
return f"{STEP_TAG} {driver} stepped the worker up a rung here, so the escalation triggers that fired before this line are spent."
|
||||
|
||||
|
||||
def quote_after_step(driver: str) -> str:
|
||||
"""Reply.escalation's description in agent_cycle/judge.py carries this sentence, so the judge reads step_line as the mark."""
|
||||
return f"Where a {STEP_TAG} line says {driver} stepped the worker up a rung, quote only the worker's own words after it, and leave this empty where the trigger fired only before it."
|
||||
|
||||
|
||||
def stamped(verdict: Verdict, entries_read: int) -> Verdict:
|
||||
@@ -32,13 +43,13 @@ def moved_to(verdict: Escalating) -> int | None:
|
||||
return verdict.entries_read if verdict.escalation else None
|
||||
|
||||
|
||||
def transcript(entries: list[Entry], at: int, typed_answer: typing.Callable[[str], Typed | None]) -> str:
|
||||
"""The transcript as the judge sees it. Where the mark, at, is above 0, STEP_LINE comes after that many entries."""
|
||||
return "\n\n".join(part for part in (render(entries[:at], typed_answer), STEP_LINE if at else "", render(entries[at:], typed_answer)) if part)
|
||||
def transcript(entries: list[Entry], at: int, typed_answer: typing.Callable[[str], Typed | None], driver: str) -> str:
|
||||
"""The transcript as the judge sees it. Where the mark, at, is above 0, step_line comes after that many entries."""
|
||||
return "\n\n".join(part for part in (render(entries[:at], typed_answer), step_line(driver) if at else "", render(entries[at:], typed_answer)) if part)
|
||||
|
||||
|
||||
def after_mark(entries: list[Entry], at: int) -> str:
|
||||
"""All the text and tool calls of the worker's assistant turns after the mark, even where the judge is shown only the transcript's tail. loop-claude's prompts and the human's lines are left out, since they repeat earlier passages, such as the judge's evidence or the worker's question."""
|
||||
"""All the text and tool calls of the worker's assistant turns after the mark, even where the judge is shown only the transcript's tail. The driver's prompts and the human's lines are left out, since they repeat earlier passages, such as the judge's evidence or the worker's question."""
|
||||
return "\n\n".join(line for entry in entries[at:] if isinstance(entry, AssistantTurn) for line in assistant_lines(entry))
|
||||
|
||||
|
||||
|
||||
@@ -13,14 +13,14 @@ from agent_cycle.direct_message import tell
|
||||
from agent_cycle import tmux
|
||||
|
||||
ANSWER_QUESTION = "answer the question above"
|
||||
# TALK, what the human types at loop-claude's terminal to open claude for the question, and ASK_ANSWER were picked on 2026-10-17 by a bench of three readers seated as the README's audience, as ~/.claude/CLAUDE.md → "Working loop" → "Bench a syntax with the people who write it." has it.
|
||||
# TALK, what the human types at the entry point's terminal to open claude for the question, and ASK_ANSWER were picked on 2026-10-17 by a bench of three readers seated as the README's audience, as ~/.claude/CLAUDE.md → "Working loop" → "Bench a syntax with the people who write it." has it.
|
||||
TALK = "/talk"
|
||||
ASK_ANSWER = f"Answer ({TALK} opens claude, Enter stops the loop): "
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class WorkerSession:
|
||||
"""The worker's claude session, which /talk opens on loop-claude's terminal."""
|
||||
"""The worker's claude session, which /talk opens on the entry point's terminal."""
|
||||
root: str
|
||||
id: uuid.UUID
|
||||
rung: Rung
|
||||
@@ -37,8 +37,8 @@ class Talked:
|
||||
"""The human typed in the worker's claude session."""
|
||||
|
||||
|
||||
def interrupt(question: str, answer_here: bool, session: WorkerSession, window: tmux.Window, effects: Effects) -> str | Talked | Stop:
|
||||
"""Prints question for the human, in window, and returns their answer. While it waits, the window's name ends in tmux.WAITS, and the bell it rings shows in tmux's status bar. The answer: where answer_here, the first line typed at loop-claude's terminal, stripped, or Talked once they typed in the worker's claude session, which TALK opens; else Talked once they typed in that session, which opens at once on the terminal. A Stop where loop-claude is off a terminal, or they type no answer, or the input ends."""
|
||||
def interrupt(question: str, answer_here: bool, session: WorkerSession, window: tmux.Window, driver: str, effects: Effects) -> str | Talked | Stop:
|
||||
"""Prints question for the human, in window, and returns their answer. While it waits, the window's name ends in tmux.WAITS, and the bell it rings shows in tmux's status bar. The answer: where answer_here, the first line typed at the terminal of driver, the entry point, stripped, or Talked once they typed in the worker's claude session, which TALK opens; else Talked once they typed in that session, which opens at once on the terminal. A Stop where it is off a terminal, or they type no answer, or the input ends."""
|
||||
# The bell ends the question's line, so it rings once the question can be read.
|
||||
say(f"\n{question}{tmux.BELL}", effects)
|
||||
on_terminal = effects.on_terminal()
|
||||
@@ -47,8 +47,8 @@ def interrupt(question: str, answer_here: bool, session: WorkerSession, window:
|
||||
effects.discard_typed()
|
||||
tmux.mark(window, True, effects.tmux)
|
||||
# After the discard, so an answer typed while the DM sends counts; before the terminal check, so a loop that cannot ask still tells the human what it would have asked.
|
||||
tell(f"loop-claude in {session.root} asks, in the tmux window {window.target}:\n\n{question}", effects)
|
||||
answer = needs_terminal(ANSWER_QUESTION, on_terminal) or answered(answer_here, session, effects)
|
||||
tell(f"{driver} in {session.root} asks, in the tmux window {window.target}:\n\n{question}", effects)
|
||||
answer = needs_terminal(ANSWER_QUESTION, on_terminal, driver) or answered(answer_here, session, effects)
|
||||
# A loop that stops unanswered leaves the mark on its window.
|
||||
if not isinstance(answer, Stop):
|
||||
tmux.mark(window, False, effects.tmux)
|
||||
@@ -64,7 +64,7 @@ def answered(answer_here: bool, session: WorkerSession, effects: Effects) -> str
|
||||
|
||||
|
||||
def typed_answer(effects: Effects) -> str | Stop:
|
||||
"""The line typed at loop-claude's terminal, stripped. A Stop where they type no answer, or the input ends."""
|
||||
"""The line typed at the entry point's terminal, stripped. A Stop where they type no answer, or the input ends."""
|
||||
try:
|
||||
text = effects.input(ASK_ANSWER).strip()
|
||||
except EOFError:
|
||||
|
||||
+31
-20
@@ -36,8 +36,8 @@ INTERRUPT_RULES = (
|
||||
"interrupt=false otherwise. A choice in the repo that no rule reserves for the human is the worker's to make, "
|
||||
"so its taking its own recommendation on one is no reason to interrupt. Where it asks about such a choice and "
|
||||
"recommends an answer, quote the sentence of that rule telling it to take the option it would recommend, even "
|
||||
"where a [loop] line quoted that sentence for another question. A run that ends asking loop-claude for a higher "
|
||||
"rung is no reason to interrupt either; one that asks the human's yes to a higher rung is.\n\n"
|
||||
"where a [loop] line quoted that sentence for another question. A run that ends {asks_higher_rung} "
|
||||
"is no reason to interrupt either; one that asks the human's yes to a higher rung is.\n\n"
|
||||
"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. Where a [human] line from earlier in the "
|
||||
"chunk answered the question the worker asks now, interrupt only if that line's own words leave open what "
|
||||
@@ -66,22 +66,25 @@ FINISHED_RULES = (
|
||||
)
|
||||
|
||||
|
||||
def judge_rules(answer_destinations: str) -> str:
|
||||
"""The rules that end the judge's prompt. answer_destinations names where the entry point's worker may record an answer the human typed."""
|
||||
return "\n\n".join((INTERRUPT_RULES, QUOTE_RULES, FINISHED_RULES.format(answers_recorded=answers_recorded(answer_destinations), answer_destinations=answer_destinations)))
|
||||
def judge_rules(answer_destinations: str, driver: str) -> str:
|
||||
"""The rules that end the judge's prompt. answer_destinations names where the worker of driver, the entry point, may record an answer the human typed."""
|
||||
return "\n\n".join((INTERRUPT_RULES.format(asks_higher_rung=escalation_mark.asks_higher_rung(driver)), QUOTE_RULES, FINISHED_RULES.format(answers_recorded=answers_recorded(answer_destinations), answer_destinations=answer_destinations)))
|
||||
|
||||
|
||||
# Open the task and the transcript in the prompt; the premises and the records come before the task, the rules after the transcript.
|
||||
# judge_replay.archived_prompt splits each archived prompt on them, so rewording one makes every run archived before it replay as failed.
|
||||
TASK_HEADING = "The task the worker was given:\n"
|
||||
TRANSCRIPT_HEADING = "What the worker did and said, what the human typed on [human] lines and what loop-claude told it on [loop] lines, latest last:\n"
|
||||
|
||||
|
||||
def transcript_heading(driver: str) -> str:
|
||||
return f"What the worker did and said, what the human typed on [human] lines and what {driver} told it on [loop] lines, latest last:\n"
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Reply:
|
||||
answer: str = dataclasses.field(metadata={"description": "With interrupt false, the passage of the premises or the records that answers the worker's question, quoted verbatim, without elisions. Empty otherwise."})
|
||||
# Routes the worker one rung up, as the judge interrupts or quotes an answer, or on the next cycle: agent_cycle/escalation_mark.py.
|
||||
escalation: str = dataclasses.field(metadata={"description": "Empty unless the chunk is unfinished, interrupt is true or answer quotes a passage, and the worker's run ends asking loop-claude for a higher rung, citing an escalation trigger. Then: a verbatim quote, without elisions, of the transcript passage where the trigger fired, such as a review round's commit title or the worker's report of the finding or failing test. " + escalation_mark.QUOTE_AFTER_STEP + " Never a later mention of the trigger, and never the request itself."})
|
||||
escalation: str = dataclasses.field(metadata={"description": "Empty unless the chunk is unfinished, interrupt is true or answer quotes a passage, and the worker's run ends {asks_higher_rung}, citing an escalation trigger. Then: a verbatim quote, without elisions, of the transcript passage where the trigger fired, such as a review round's commit title or the worker's report of the finding or failing test. {quote_after_step} Never a later mention of the trigger, and never the request itself."})
|
||||
evidence: str = dataclasses.field(metadata={"description": "A verbatim quote of the one transcript passage the verdict rests on, without elisions: what triggers the interrupt; for a quoted answer, the worker's question; else what shows the chunk finished or the work remaining."})
|
||||
finished: bool = dataclasses.field(metadata={"description": "Whether the chunk is finished."})
|
||||
interrupt: bool = dataclasses.field(metadata={"description": "Whether the human must now be interrupted."})
|
||||
@@ -96,11 +99,17 @@ class Reply:
|
||||
|
||||
REPLY_TYPES = typing.get_type_hints(Reply)
|
||||
JSON_TYPES: dict[object, dict[str, typing.Any]] = {bool: {"type": "boolean"}, int: {"type": "integer"}, str: {"type": "string"}}
|
||||
JUDGE_SCHEMA = {
|
||||
"properties": {field.name: {**field.metadata, **JSON_TYPES[REPLY_TYPES[field.name]]} for field in dataclasses.fields(Reply)},
|
||||
"required": list(REPLY_TYPES),
|
||||
"type": "object",
|
||||
}
|
||||
|
||||
|
||||
def judge_schema(driver: str) -> dict[str, typing.Any]:
|
||||
"""The schema of the judge's reply, each field described from Reply's metadata, with the words that name driver, the entry point, filled in."""
|
||||
asks, quote = escalation_mark.asks_higher_rung(driver), escalation_mark.quote_after_step(driver)
|
||||
described = {field.name: field.metadata["description"].replace("{asks_higher_rung}", asks).replace("{quote_after_step}", quote) for field in dataclasses.fields(Reply)}
|
||||
return {
|
||||
"properties": {name: {"description": description, **JSON_TYPES[REPLY_TYPES[name]]} for name, description in described.items()},
|
||||
"required": list(REPLY_TYPES),
|
||||
"type": "object",
|
||||
}
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -137,6 +146,8 @@ class Brief(typing.NamedTuple):
|
||||
entries: list[Entry]
|
||||
# How many of the entries the session held when an escalation last stepped the worker up a rung, 0 before any.
|
||||
escalated_at: int
|
||||
# The entry point's name, such as `do-epic`, as WorkerPrompts.driver has it.
|
||||
driver: str
|
||||
|
||||
|
||||
def verdict_from(output: object) -> Verdict | Failure:
|
||||
@@ -170,21 +181,21 @@ def judge(root: str, brief: Brief, rung: Rung, effects: Effects, keep: typing.Ca
|
||||
def judge_once(root: str, brief: Brief, rung: Rung, effects: Effects) -> Verdict | Failure | Limited:
|
||||
"""One judge run on the brief, as judge retries it; judge-replay replays it."""
|
||||
prompt, grounds = judge_prompt(brief)
|
||||
verdict = run_judge(root, judge_args(rung), prompt, grounds, effects)
|
||||
verdict = run_judge(root, judge_args(rung, brief.driver), prompt, grounds, effects)
|
||||
return verdict if isinstance(verdict, Failure | Limited) else escalation_mark.stamped(verdict, len(brief.entries))
|
||||
|
||||
|
||||
def judge_archived(root: str, prompt: str, grounds: Grounds, entries_read: int, rung: Rung, effects: Effects) -> Verdict | Failure | Limited:
|
||||
def judge_archived(root: str, prompt: str, grounds: Grounds, entries_read: int, rung: Rung, driver: str, effects: Effects) -> Verdict | Failure | Limited:
|
||||
"""One judge run on a prompt the archive kept from an earlier run, as judge-replay replays it: the judge reads what it read then, and its quotes are checked against grounds, which judge_replay.archived_prompt makes from that prompt in place of the records of today."""
|
||||
verdict = run_judge(root, judge_args(rung), prompt, grounds, effects)
|
||||
verdict = run_judge(root, judge_args(rung, driver), prompt, grounds, effects)
|
||||
return verdict if isinstance(verdict, Failure | Limited) else escalation_mark.stamped(verdict, entries_read)
|
||||
|
||||
|
||||
def judge_args(rung: Rung) -> list[str]:
|
||||
def judge_args(rung: Rung, driver: str) -> list[str]:
|
||||
# --json-schema has claude check its reply against the schema and return it as the json result's structured_output.
|
||||
# No tools, so the verdict rests on the transcript grounded() checks it against.
|
||||
return [
|
||||
"--json-schema", json.dumps(JUDGE_SCHEMA),
|
||||
"--json-schema", json.dumps(judge_schema(driver)),
|
||||
*rung.flags(),
|
||||
"--tools", "",
|
||||
]
|
||||
@@ -281,11 +292,11 @@ def judge_prompt(brief: Brief) -> tuple[str, Grounds]:
|
||||
f"From the goals file, {brief.premises}\n\n"
|
||||
f"The records: the project's working rules and decisions, then the human's rules for every project:\n{brief.records or 'none'}\n\n"
|
||||
f"{TASK_HEADING}{brief.task}\n\n"
|
||||
f"{TRANSCRIPT_HEADING}"
|
||||
f"{transcript_heading(brief.driver)}"
|
||||
)
|
||||
rules = judge_rules(brief.answer_destinations)
|
||||
rules = judge_rules(brief.answer_destinations, brief.driver)
|
||||
room = max(0, JUDGE_PROMPT_CHARS - len(head) - len(rules) - 2)
|
||||
transcript = escalation_mark.transcript(brief.entries, brief.escalated_at, typed_answer)
|
||||
transcript = escalation_mark.transcript(brief.entries, brief.escalated_at, typed_answer, brief.driver)
|
||||
# The tail, where an interrupt or a finish lands; the session's transcript grows cycle over cycle.
|
||||
shown = transcript[max(0, len(transcript) - room):]
|
||||
grounds = Grounds(
|
||||
|
||||
@@ -159,6 +159,7 @@ def rule(cycle: Cycle, transcript_path: str, quoted_answers: int) -> Ruled | Sto
|
||||
answer_destinations=cycle.prompts.answer_destinations,
|
||||
entries=entries,
|
||||
escalated_at=cycle.route.escalated_at,
|
||||
driver=cycle.prompts.driver,
|
||||
)
|
||||
verdict = judge(cycle.root, brief, cycle.judge, cycle.effects, lambda rejected: keep_rejection(cycle, transcript_path, rejected))
|
||||
if isinstance(verdict, Stop):
|
||||
@@ -205,7 +206,7 @@ def keep_rejection(cycle: Cycle, transcript_path: str, rejected: Rejected) -> St
|
||||
def ask(cycle: Cycle, transcript_path: str, ruling: Interrupt | QuotedAnswer) -> HumanTyped | HumanTalked | Stop:
|
||||
"""The human's answer to a ruling that rule archived as it ruled; the human's answer then grows the transcript."""
|
||||
# Only the human may cut a release, so a release ready to cut opens claude's session at once.
|
||||
answer = interrupt(question_for(cycle, ruling), not (isinstance(ruling, Interrupt) and ruling.release_ready), worker_session(cycle, transcript_path), cycle.window, cycle.effects)
|
||||
answer = interrupt(question_for(cycle, ruling), not (isinstance(ruling, Interrupt) and ruling.release_ready), worker_session(cycle, transcript_path), cycle.window, cycle.prompts.driver, cycle.effects)
|
||||
match answer:
|
||||
case Stop():
|
||||
return answer
|
||||
|
||||
@@ -4,7 +4,7 @@ import typing
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Stop:
|
||||
"""loop-claude exits with code, printing reason."""
|
||||
"""The entry point exits with code, printing reason."""
|
||||
code: typing.Literal[0, 1, 2, 130]
|
||||
reason: str
|
||||
|
||||
@@ -13,7 +13,8 @@ def needs_human(need: str, blocker: str) -> Stop:
|
||||
return Stop(2, f"the human is needed to {need}, but {blocker}")
|
||||
|
||||
|
||||
def needs_terminal(need: str, on_terminal: bool) -> Stop | None:
|
||||
def needs_terminal(need: str, on_terminal: bool, driver: str) -> Stop | None:
|
||||
"""driver is the entry point the human reruns, such as `do-epic`."""
|
||||
if on_terminal:
|
||||
return None
|
||||
return needs_human(need, "stdin or stdout is not a terminal; rerun loop-claude on a terminal")
|
||||
return needs_human(need, f"stdin or stdout is not a terminal; rerun {driver} on a terminal")
|
||||
|
||||
+10
-7
@@ -1,4 +1,4 @@
|
||||
"""The tmux commands loop-claude runs: each chunk's loop runs in its own window of one tmux session named for the project (docs/decisions.md → `loop-claude: each chunk runs in its own tmux window`)."""
|
||||
"""The tmux commands an entry point runs: each chunk's loop runs in its own window of one tmux session, which loop-claude names for the project and do-epic for the epic (docs/decisions.md → `loop-claude: each chunk runs in its own tmux window`)."""
|
||||
import dataclasses
|
||||
import re
|
||||
import subprocess
|
||||
@@ -14,6 +14,9 @@ NEEDED = (3, 2)
|
||||
# What a window's name ends in while its chunk waits for the human. tmux's status bar shows the name, and `!` after it once the bell rang.
|
||||
WAITS = " ?"
|
||||
BELL = "\a"
|
||||
# What a session's name opens with: LOOP for a project's chunks under loop-claude, EPIC for an epic's chunks under do-epic.
|
||||
LOOP = "loop"
|
||||
EPIC = "epic"
|
||||
# The session option that names the checkout whose chunks the session runs, since two checkouts' keys may map to one session name.
|
||||
OWNER = "@loop-root"
|
||||
|
||||
@@ -44,18 +47,18 @@ class Listed:
|
||||
dead: bool
|
||||
|
||||
|
||||
def unusable(run: Tmux) -> str | None:
|
||||
"""Why loop-claude cannot use this machine's tmux, naming the version found and the one needed; None where it is NEEDED or later."""
|
||||
def unusable(run: Tmux, driver: str) -> str | None:
|
||||
"""Why driver, the entry point, cannot use this machine's tmux, naming the version found and the one needed; None where it is NEEDED or later."""
|
||||
found = run(["-V"]).stdout.strip()
|
||||
version = re.search(r"([0-9]+)\.([0-9]+)", found)
|
||||
if version and (int(version[1]), int(version[2])) >= NEEDED:
|
||||
return None
|
||||
return f"loop-claude runs each chunk in a tmux window, and needs tmux {NEEDED[0]}.{NEEDED[1]} or later; it found {found or 'no tmux'}"
|
||||
return f"{driver} runs each chunk in a tmux window, and needs tmux {NEEDED[0]}.{NEEDED[1]} or later; it found {found or 'no tmux'}"
|
||||
|
||||
|
||||
def session_name(key: str) -> str:
|
||||
"""The tmux session of the project with this key, such as `loop-claude-config`. tmux reads `.` and `:` in a target as separators, so every character but a letter, a digit, `_` and `-` becomes a dash."""
|
||||
return "loop-" + re.sub(r"[^A-Za-z0-9_-]", "-", key)
|
||||
def session_name(kind: str, key: str) -> str:
|
||||
"""The tmux session an entry point runs its chunks in: kind LOOP with a project's key, such as `loop-claude-config`, or kind EPIC with an epic's key, such as `epic-ABC-12`. tmux reads `.` and `:` in a target as separators, so every character of the key but a letter, a digit, `_` and `-` becomes a dash."""
|
||||
return f"{kind}-" + re.sub(r"[^A-Za-z0-9_-]", "-", key)
|
||||
|
||||
|
||||
def listed(session: str, run: Tmux) -> list[Listed]:
|
||||
|
||||
@@ -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."""
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
from loop_claude.cycle.prompts import ANSWER_DESTINATIONS
|
||||
from loop_claude.cycle.prompts import ANSWER_DESTINATIONS, DRIVER
|
||||
from claude_code.entries import Entry
|
||||
from agent_cycle import escalation_mark
|
||||
from failure import Failure
|
||||
from agent_cycle.judge import Grounds, judge_rules, TASK_HEADING, TRANSCRIPT_HEADING
|
||||
from agent_cycle.judge import Grounds, judge_rules, TASK_HEADING, transcript_heading
|
||||
from claude_code.transcript import human_answers
|
||||
from agent_cycle.worker_prompts import typed_answer
|
||||
|
||||
@@ -10,7 +10,8 @@ from agent_cycle.worker_prompts import typed_answer
|
||||
def grounds_of(prompt: str, entries: list[Entry]) -> Grounds | Failure:
|
||||
"""What the quotes of a judge run on prompt are checked against, as judge_prompt would have made it for the transcript's entries: the premises and the records before the task are quotable, the transcript the judge was shown comes before the rules. The prompt is split on the headings judge_prompt writes, at the first of each; a Failure where it lacks one. Rules of an earlier wording stay part of the transcript, a slack that lets an evidence quote them pass."""
|
||||
before_task, task_heading, after_task = prompt.partition(f"\n\n{TASK_HEADING}")
|
||||
_, transcript_heading, shown = after_task.partition(TRANSCRIPT_HEADING)
|
||||
if not (task_heading and transcript_heading):
|
||||
return Failure(f"the archived prompt lacks the heading {TASK_HEADING.strip()!r} or {TRANSCRIPT_HEADING.strip()!r}, which judge_prompt writes")
|
||||
return Grounds(shown.removesuffix(f"\n\n{judge_rules(ANSWER_DESTINATIONS)}"), escalation_mark.after_mark(entries, 0), before_task, tuple(human_answers(entries, typed_answer)))
|
||||
heading = transcript_heading(DRIVER)
|
||||
_, found_heading, shown = after_task.partition(heading)
|
||||
if not (task_heading and found_heading):
|
||||
return Failure(f"the archived prompt lacks the heading {TASK_HEADING.strip()!r} or {heading.strip()!r}, which judge_prompt writes")
|
||||
return Grounds(shown.removesuffix(f"\n\n{judge_rules(ANSWER_DESTINATIONS, DRIVER)}"), escalation_mark.after_mark(entries, 0), before_task, tuple(human_answers(entries, typed_answer)))
|
||||
|
||||
@@ -53,7 +53,7 @@ import pathlib
|
||||
import sys
|
||||
import typing
|
||||
|
||||
from loop_claude.cycle.prompts import ANSWER_DESTINATIONS
|
||||
from loop_claude.cycle.prompts import ANSWER_DESTINATIONS, DRIVER
|
||||
from transcript_archive.location import archive_root, transcript_of
|
||||
from transcript_archive.read import archived_outcomes
|
||||
from rung_replay.archive import archiving, print_report, replay_folder
|
||||
@@ -164,7 +164,7 @@ def rule(case: Case, rung: Rung, home: pathlib.Path, effects: Effects) -> Kind |
|
||||
grounds = grounds_of(kept.prompt, entries)
|
||||
if isinstance(grounds, Failure):
|
||||
return verdict_kind(grounds)
|
||||
verdict: Verdict | Failure | Limited = first_reply(lambda: judge_archived(case.root, kept.prompt, grounds, len(entries), rung, effects))
|
||||
verdict: Verdict | Failure | Limited = first_reply(lambda: judge_archived(case.root, kept.prompt, grounds, len(entries), rung, DRIVER, effects))
|
||||
return verdict if isinstance(verdict, Limited) else verdict_kind(verdict)
|
||||
premises, records = read_premises(case.root, home), read_records(case.root, home, home / ".claude")
|
||||
if isinstance(premises, Failure):
|
||||
@@ -172,5 +172,5 @@ def rule(case: Case, rung: Rung, home: pathlib.Path, effects: Effects) -> Kind |
|
||||
if isinstance(records, Failure):
|
||||
return verdict_kind(records)
|
||||
# 0 for the route's mark, as before any step-up: the replay compares verdict kinds, and a mark changes only which escalation quotes count.
|
||||
verdict = first_reply(lambda: judge_once(case.root, Brief(task=case.task, premises=premises, records=records, answer_destinations=ANSWER_DESTINATIONS, entries=entries, escalated_at=0), rung, effects))
|
||||
verdict = first_reply(lambda: judge_once(case.root, Brief(task=case.task, premises=premises, records=records, answer_destinations=ANSWER_DESTINATIONS, entries=entries, escalated_at=0, driver=DRIVER), rung, effects))
|
||||
return verdict if isinstance(verdict, Limited) else verdict_kind(verdict)
|
||||
|
||||
@@ -9,7 +9,7 @@ import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from loop_claude.cycle.prompts import ANSWER_DESTINATIONS
|
||||
from loop_claude.cycle.prompts import ANSWER_DESTINATIONS, DRIVER
|
||||
from transcript_archive.outcomes import ANSWERED, FINISHED, INTERRUPTED, UNFINISHED
|
||||
from claude_code.entries import AssistantTurn, HumanTurn, LoopPrompt, Text
|
||||
from judge_replay.replay import Case, case_from, report, reproduced, sample, verdict_kind
|
||||
@@ -19,7 +19,7 @@ from loop_effects.effects import Effects
|
||||
from failure import Failure
|
||||
from agent_cycle.verdicts import Finished, Interrupt, QuotedAnswer, Unfinished
|
||||
from judge_replay.archived_prompt import grounds_of
|
||||
from agent_cycle.judge import judge_archived, judge_rules, Rejected, TASK_HEADING, TRANSCRIPT_HEADING
|
||||
from agent_cycle.judge import judge_archived, judge_rules, Rejected, TASK_HEADING, transcript_heading
|
||||
from judge_replay import main
|
||||
from rung_replay.search import Miss, Replay, Tried
|
||||
from model_routing.ladder import Rung
|
||||
@@ -330,7 +330,7 @@ class Main(unittest.TestCase):
|
||||
|
||||
class JudgeArchivedRuns(unittest.TestCase):
|
||||
"""judge_archived on a prompt as judge_prompt writes it: the premises, the task, the transcript the judge was shown, and the rules."""
|
||||
PROMPT = f"HEAD: Ship fast.\n\n{TASK_HEADING}Do it.\n\n{TRANSCRIPT_HEADING}Worker chose option B.\n[human] Use Postgres.\n\n{judge_rules(ANSWER_DESTINATIONS)}"
|
||||
PROMPT = f"HEAD: Ship fast.\n\n{TASK_HEADING}Do it.\n\n{transcript_heading(DRIVER)}Worker chose option B.\n[human] Use Postgres.\n\n{judge_rules(ANSWER_DESTINATIONS, DRIVER)}"
|
||||
ENTRIES = [AssistantTurn(parts=(Text("Worker chose option B."),)), HumanTurn(text="Use Postgres."), LoopPrompt(text="Keep going.")]
|
||||
|
||||
def judged(self, prompt=PROMPT, **fields):
|
||||
@@ -344,7 +344,7 @@ class JudgeArchivedRuns(unittest.TestCase):
|
||||
|
||||
effects = Effects(claude=claude, claude_on_terminal=unused, discard_typed=unused, dm=unused, execv=unused, git=unused, input=unused, local_time=unused, memory=unused, now=lambda: 1790000000.0, on_terminal=unused, python=unused, sleep=unused, stream_claude=unused, tmux=unused, tmux_on_terminal=unused)
|
||||
grounds = grounds_of(prompt, self.ENTRIES)
|
||||
return (grounds if isinstance(grounds, Failure) else judge_archived("/code/p", prompt, grounds, len(self.ENTRIES), REFERENCE, effects)), cwds
|
||||
return (grounds if isinstance(grounds, Failure) else judge_archived("/code/p", prompt, grounds, len(self.ENTRIES), REFERENCE, DRIVER, effects)), cwds
|
||||
|
||||
def test_runs_in_the_projects_folder_and_stamps_the_verdict_with_the_entries_read(self):
|
||||
verdict, cwds = self.judged()
|
||||
@@ -363,11 +363,11 @@ class JudgeArchivedRuns(unittest.TestCase):
|
||||
self.assertEqual((type(rejected), rejected.cost), (Rejected, 0.25))
|
||||
|
||||
def test_checks_neither_the_task_nor_the_rules_as_the_transcript_or_the_premises(self):
|
||||
self.assertIsInstance(self.judged(evidence=judge_rules(ANSWER_DESTINATIONS))[0], Rejected)
|
||||
self.assertIsInstance(self.judged(evidence=judge_rules(ANSWER_DESTINATIONS, DRIVER))[0], Rejected)
|
||||
self.assertIsInstance(self.judged(answer="Do it.", question="Which?")[0], Interrupt)
|
||||
|
||||
def test_splits_the_prompt_at_the_first_transcript_heading(self):
|
||||
quoting = self.PROMPT.replace("Worker chose", f"Quoted: {TRANSCRIPT_HEADING}Worker chose", 1)
|
||||
quoting = self.PROMPT.replace("Worker chose", f"Quoted: {transcript_heading(DRIVER)}Worker chose", 1)
|
||||
self.assertIsInstance(self.judged(quoting, evidence="Quoted:")[0], Unfinished)
|
||||
|
||||
def test_splits_the_prompt_at_the_first_task_heading(self):
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
"""What loop-claude says to the worker each cycle. model_routing.review_choice chooses where the reviews run. review_launches and reruns put that choice into sentences, and escalation says where escalated subagents run; rung_sentences returns the sentences of all three. In a chunk's first prompt, routed_by places them after its routing sentences where an item routed the chunk, and fresh places them alone otherwise. rungs_held repeats them at the end of a prompt after a step-up or an unfinished verdict."""
|
||||
import functools
|
||||
import typing
|
||||
|
||||
from agent_cycle.escalation_mark import asks_higher_rung
|
||||
from agent_cycle.worker_prompts import answers_recorded, WorkerPrompts
|
||||
from model_routing.review_choice import chosen, ReviewChoice
|
||||
from loop_claude.cycle.chunk_items import CHUNK_ITEMS
|
||||
@@ -9,6 +13,8 @@ from review_rules.review_passes import INSTRUCTION_FILES, INSTRUCTION_FOLDERS
|
||||
from text_files.markdown_text import listed, quoted
|
||||
from model_routing.ladder import ProjectRung, Rung
|
||||
|
||||
# loop-claude's name as its workers, its judge and the human read it. A function below that takes a driver words a sentence for any entry point, such as do-epic.
|
||||
DRIVER = "loop-claude"
|
||||
# Where the judge may quote an answer from, named as the human and the worker see them; of the goals file the judge sees only the premises.
|
||||
QUOTE_SOURCES = listed(("the goals file's Goals and Audience", *RECORD_FILES, *HUMAN_RULE_NAMES), "or")
|
||||
# Where the worker may write an answer the human typed, so it counts as recorded.
|
||||
@@ -29,17 +35,17 @@ NAME_THE_ITEMS = f"Name every plan item this chunk takes on one line, as in `{CH
|
||||
AFTER_CODE_HEALTH = 'which rank after code health (~/.claude/CLAUDE.md → "Shared goal") unless the goals file voids it'
|
||||
|
||||
|
||||
def fresh(task: str, premises: str, route: Route, project: ProjectRung | None, facts: str) -> str:
|
||||
def fresh(driver: str, task: str, premises: str, route: Route, project: ProjectRung | None, facts: str) -> str:
|
||||
"""A chunk's first prompt; facts is preflight_facts' or preflight_failed's text."""
|
||||
routed = f"{routed_by(route, project)} {recount(route)}" if route.item else " ".join(rung_sentences(route, project))
|
||||
routed = f"{routed_by(driver, route, project)} {recount(route)}" if route.item else " ".join(rung_sentences(driver, route, project))
|
||||
opening = f"{routed}\n\n" if routed else ""
|
||||
return f"{task}\n\nContinue any open draft PR or worktree for the chunk before creating a new one. {READING_RULE} {NAME_THE_ITEMS}\n\n{opening}{facts}\n\nThe chunk's plan items, or else the task above, set its scope. The goals below, {AFTER_CODE_HEALTH}, choose between ways to deliver that scope, and never widen it.\n\nFrom the goals file, {premises}"
|
||||
|
||||
|
||||
def routed_by(route: Route, project: ProjectRung | None) -> str:
|
||||
def routed_by(driver: str, route: Route, project: ProjectRung | None) -> str:
|
||||
return " ".join((
|
||||
f"loop-claude runs you on {route.rung}, routed by item {route.item}'s L of {route.likelihood}.",
|
||||
*rung_sentences(route, project),
|
||||
f"{driver} runs you on {route.rung}, routed by item {route.item}'s L of {route.likelihood}.",
|
||||
*rung_sentences(driver, route, project),
|
||||
))
|
||||
|
||||
|
||||
@@ -123,7 +129,7 @@ def rung_named(rung: Rung, route: Route, project: ProjectRung) -> str:
|
||||
return f"the rung item {route.item}'s E + I of {route.escape_and_impact} picks"
|
||||
|
||||
|
||||
def escalation(route: Route, project: ProjectRung | None) -> list[str]:
|
||||
def escalation(driver: str, route: Route, project: ProjectRung | None) -> list[str]:
|
||||
"""The prompt's escalation sentences, the marker's among them. None off the ladder or on its top rung. Where escalation_rungs opens none, the worker escalates only with the human's yes.
|
||||
Else they name the rungs escalation_rungs opens to a subagent, and offer to resume the worker one rung up for the rest of the chunk, up to the highest of those rungs.
|
||||
|
||||
@@ -135,14 +141,14 @@ def escalation(route: Route, project: ProjectRung | None) -> list[str]:
|
||||
rungs = [f"`{rung.agent_args()}`" for rung in escalation_rungs(project, route)]
|
||||
if not rungs:
|
||||
return [
|
||||
f"An escalation trigger in `~/.claude/CLAUDE.md` lets you hand the hard part of a task to a subagent with the Agent tool set to `{project.ladder.climbed(route.rung, 1).agent_args()}`, one rung above yours, only once the human agrees; loop-claude will not resume you higher for a trigger either, so ask the human for that yes.",
|
||||
f"An escalation trigger in `~/.claude/CLAUDE.md` lets you hand the hard part of a task to a subagent with the Agent tool set to `{project.ladder.climbed(route.rung, 1).agent_args()}`, one rung above yours, only once the human agrees; {driver} will not resume you higher for a trigger either, so ask the human for that yes.",
|
||||
marked,
|
||||
]
|
||||
further = f", and on each further trigger one rung higher, up to {rungs[-1]}" if len(rungs) > 1 else ""
|
||||
return [
|
||||
f"When an escalation trigger in `~/.claude/CLAUDE.md` fires, hand the hard part of the task to a subagent with the Agent tool set to {rungs[0]}, one rung above yours{further}; above that, ask the human first.",
|
||||
marked,
|
||||
f"Where the hard part is the rest of the chunk, end your run instead, asking loop-claude for a higher rung and naming a trigger that fired since your last step-up, if any: once the judge finds it in your transcript, the next cycle resumes you one rung up, up to {rungs[-1]}.",
|
||||
f"Where the hard part is the rest of the chunk, end your run instead, {asks_higher_rung(driver)} and naming a trigger that fired since your last step-up, if any: once the judge finds it in your transcript, the next cycle resumes you one rung up, up to {rungs[-1]}.",
|
||||
]
|
||||
|
||||
|
||||
@@ -163,21 +169,26 @@ def reruns(route: Route, project: ProjectRung | None) -> list[str]:
|
||||
return [f"A reviewer that asks for a rerun one rung up reruns with the Agent tool set to `{rerun['reviewer'].agent_args()}`, and a comprehension seat with `{rerun['comprehension seat'].agent_args()}`."]
|
||||
|
||||
|
||||
def resumed(unfinished_evidence: str, route: Route, project: ProjectRung | None) -> str:
|
||||
def resumed(driver: str, unfinished_evidence: str, route: Route, project: ProjectRung | None) -> str:
|
||||
"""Names the worker's rung, so it learns whether its request for a higher rung went through, and the project's again, since a step-up between cycles may have taken the worker above it."""
|
||||
on = f" loop-claude runs you on {route.rung}." if project else ""
|
||||
on = f" {driver} runs you on {route.rung}." if project else ""
|
||||
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}. {NAME_THE_ITEMS}{on}{rungs_held(route, project)}"
|
||||
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}. {NAME_THE_ITEMS}{on}{rungs_held(driver, route, project)}"
|
||||
|
||||
|
||||
def rung_sentences(route: Route, project: ProjectRung | None) -> list[str]:
|
||||
def rung_sentences(driver: str, route: Route, project: ProjectRung | None) -> list[str]:
|
||||
"""The sentences that depend on the worker's rung: where its reviews run and rerun, and where its escalated subagents run."""
|
||||
return [*review_launches(route, project), *escalation(route, project), *reruns(route, project)]
|
||||
return [*review_launches(route, project), *escalation(driver, route, project), *reruns(route, project)]
|
||||
|
||||
|
||||
def rungs_held(route: Route, project: ProjectRung | None) -> str:
|
||||
def rungs_held(driver: str, route: Route, project: ProjectRung | None) -> str:
|
||||
"""rung_sentences, each after a space, to follow the sentence a prompt ends on."""
|
||||
return "".join(f" {sentence}" for sentence in rung_sentences(route, project))
|
||||
return "".join(f" {sentence}" for sentence in rung_sentences(driver, route, project))
|
||||
|
||||
|
||||
WORKER = WorkerPrompts(fresh, resumed, rungs_held, QUOTE_SOURCES, ANSWER_DESTINATIONS)
|
||||
def worker_prompts(driver: str, fresh: typing.Callable[[str, str, Route, ProjectRung | None, str], str]) -> WorkerPrompts:
|
||||
"""The prompts of an entry point's cycles: its own fresh prompt, and the resumed prompt and rung sentences every entry point shares, each naming driver."""
|
||||
return WorkerPrompts(driver, fresh, functools.partial(resumed, driver), functools.partial(rungs_held, driver), QUOTE_SOURCES, ANSWER_DESTINATIONS)
|
||||
|
||||
|
||||
WORKER = worker_prompts(DRIVER, functools.partial(fresh, DRIVER))
|
||||
|
||||
@@ -133,7 +133,7 @@ def start_chunks(loop_run: LoopRun, leaving: bool, paths: Paths, env: typing.Map
|
||||
if isinstance(config, Failure):
|
||||
return config
|
||||
key = project_key(loop_run.root, paths.home)
|
||||
session = tmux.session_name(key)
|
||||
session = tmux.session_name(tmux.LOOP, key)
|
||||
handed = {name: value for name, value in env.items() if name.startswith(HANDED)}
|
||||
try:
|
||||
with starting(paths.home, key):
|
||||
@@ -168,7 +168,7 @@ def held_beside(chunk: str, root: str, paths: Paths, effects: Effects) -> list[i
|
||||
"""The plan items that the project's other chunks hold now, running or stopped, which a chunk starting as `chunk` leaves to them. It waits for a loop that is starting windows, so chunks started together see each other. Where the lock cannot be taken, it reads the windows without it."""
|
||||
key = project_key(root, paths.home)
|
||||
wait_for_starts(paths.home, key)
|
||||
others = [window.name for window in tmux.listed(tmux.session_name(key), effects.tmux) if window.name != chunk]
|
||||
others = [window.name for window in tmux.listed(tmux.session_name(tmux.LOOP, key), effects.tmux) if window.name != chunk]
|
||||
return sorted(held_items(others, key, paths.claude_code_transcripts))
|
||||
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ def run_loop(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launc
|
||||
if isinstance(loop_run, Stop):
|
||||
return loop_run
|
||||
# Before anything starts: a worktree, a claude session or a tmux window.
|
||||
if reason := tmux.unusable(effects.tmux):
|
||||
if reason := tmux.unusable(effects.tmux, prompts.DRIVER):
|
||||
return Stop(1, reason)
|
||||
if loop_run.chunk is None:
|
||||
return windows_opened(loop_run, env, paths, launcher, effects)
|
||||
@@ -59,7 +59,7 @@ def run_loop(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launc
|
||||
return Stop(1, f"{CHUNK_FLAG} is how loop-claude starts itself in a tmux window; run loop-claude <task>")
|
||||
baseline = fingerprint(launcher)
|
||||
key = project_key(loop_run.root, paths.home)
|
||||
window = tmux.Window(tmux.session_name(key), loop_run.chunk, pane)
|
||||
window = tmux.Window(tmux.session_name(tmux.LOOP, key), loop_run.chunk, pane)
|
||||
loop = Loop(root=loop_run.root, session=chunk_session(key, loop_run.chunk, paths.claude_code_transcripts), window=window, paths=paths, env=env, launcher=launcher, effects=effects)
|
||||
while True:
|
||||
if stop := exec_if_edited(loop, baseline, loop_run):
|
||||
@@ -87,7 +87,7 @@ def windows_opened(loop_run: LoopRun, env: typing.Mapping[str, str], paths: Path
|
||||
started = start_chunks(loop_run, False, paths, env, launcher, effects)
|
||||
if isinstance(started, Failure):
|
||||
return Stop(1, started.reason)
|
||||
session = tmux.session_name(project_key(loop_run.root, paths.home))
|
||||
session = tmux.session_name(tmux.LOOP, project_key(loop_run.root, paths.home))
|
||||
say(f"started {', '.join(started)} in the tmux session {session}" if started else f"the tmux session {session} runs every chunk that may run now, so `{loop_run.task}` started in no new window", effects, stdout=True)
|
||||
if not effects.on_terminal():
|
||||
say(f"not on a terminal; see the chunks with `tmux attach -t ={session}`", effects, stdout=True)
|
||||
@@ -113,7 +113,7 @@ def next_cycle(loop_run: LoopRun, loop: Loop) -> Cycle | Stop:
|
||||
records = read_records(loop.root, loop.paths.home, loop.paths.claude_dir)
|
||||
if isinstance(records, Failure):
|
||||
return Stop(1, records.reason)
|
||||
models = get_or_ask_models(project_key(loop.root, loop.paths.home), loop.paths, loop.env, loop.effects)
|
||||
models = get_or_ask_models(project_key(loop.root, loop.paths.home), loop.paths, loop.env, prompts.DRIVER, loop.effects)
|
||||
if isinstance(models, Stop):
|
||||
return models
|
||||
ladder_file = project_ladder_file(loop.root, loop.paths.home)
|
||||
|
||||
@@ -18,24 +18,24 @@ class Models:
|
||||
worker: str
|
||||
|
||||
|
||||
def get_or_ask_models(project_key: str, paths: Paths, env: typing.Mapping[str, str], effects: Effects) -> Models | Stop:
|
||||
def get_or_ask_models(project_key: str, paths: Paths, env: typing.Mapping[str, str], driver: str, effects: Effects) -> Models | Stop:
|
||||
judge, worker = env.get("LOOP_CLAUDE_JUDGE_MODEL"), env.get("LOOP_CLAUDE_WORKER_MODEL")
|
||||
if judge and worker:
|
||||
return Models(judge, worker)
|
||||
chosen = get_or_ask_model(project_key, paths, effects)
|
||||
chosen = get_or_ask_model(project_key, paths, driver, effects)
|
||||
if isinstance(chosen, Stop):
|
||||
return chosen
|
||||
return Models(judge or chosen, worker or chosen)
|
||||
|
||||
|
||||
def get_or_ask_model(project_key: str, paths: Paths, effects: Effects) -> str | Stop:
|
||||
def get_or_ask_model(project_key: str, paths: Paths, driver: str, effects: Effects) -> str | Stop:
|
||||
saved = paths.models_file
|
||||
models = read_models_file(saved)
|
||||
if isinstance(models, Failure):
|
||||
return Stop(1, models.reason)
|
||||
if kept := models.get(project_key):
|
||||
return kept
|
||||
chosen = ask_for_model(project_key, saved, paths.model_catalog, effects)
|
||||
chosen = ask_for_model(project_key, saved, paths.model_catalog, driver, effects)
|
||||
if isinstance(chosen, Stop):
|
||||
return chosen
|
||||
# Reread: another loop may have saved its project while this one waited on the human.
|
||||
@@ -62,8 +62,8 @@ def read_models_file(saved: pathlib.Path) -> dict[str, str] | Failure:
|
||||
return models
|
||||
|
||||
|
||||
def ask_for_model(project_key: str, saved: pathlib.Path, folder: pathlib.Path, effects: Effects) -> str | Stop:
|
||||
if stop := needs_terminal(f"pick {project_key}'s model, or merge {{\"{project_key}\": \"<model>\"}} into {saved}", effects.on_terminal()):
|
||||
def ask_for_model(project_key: str, saved: pathlib.Path, folder: pathlib.Path, driver: str, effects: Effects) -> str | Stop:
|
||||
if stop := needs_terminal(f"pick {project_key}'s model, or merge {{\"{project_key}\": \"<model>\"}} into {saved}", effects.on_terminal(), driver):
|
||||
return stop
|
||||
offered = catalog_models(folder)
|
||||
choices = [f" {number}. {label} ({model_id})" for number, (model_id, label) in enumerate(offered, 1)] or [f" no model catalog cached in {folder}"]
|
||||
|
||||
@@ -568,7 +568,7 @@ Spent since 2026-09-21T14:13:20Z, in tokens of input, cache write 5m, cache writ
|
||||
self.assertEqual(concluded.route, Route(Routing.OPUS, 179, 2, 5, escalated_at=3))
|
||||
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"Continue the task. Your request for a higher rung went through: loop-claude runs you on {Routing.OPUS}. The escalation triggers that fired before this step are spent.{prompts.rungs_held(concluded.route, OPUS_PROJECT)}"))
|
||||
self.assertTrue(resumed[resumed.index("-p") + 1].endswith(f"Continue the task. Your request for a higher rung went through: loop-claude runs you on {Routing.OPUS}. The escalation triggers that fired before this step are spent.{prompts.WORKER.rungs_held(concluded.route, OPUS_PROJECT)}"))
|
||||
self.assertNotIn("went through", first[first.index("-p") + 1])
|
||||
answered = f"Verdict: quoted answer\n\nWhich one?\n\n{prompts.QUOTE_SOURCES} says:\n> Use A.\n\nEvidence:\n> working\n\nEscalation:\n> working\n\nConfig: {CONFIG}\nJudge: judge-model\nWorker: {SONNET_179}\n"
|
||||
stepped = f"Stepped up\n\nWorker: {OPUS_179_AT_3}\n"
|
||||
@@ -795,7 +795,7 @@ class Interrupts(unittest.TestCase):
|
||||
def put(self, fake, answer_here=True, effects=None, question="Which one?"):
|
||||
"""interrupt's answer and what it said, without the bell it rang, which self.bells counts."""
|
||||
with contextlib.redirect_stderr(io.StringIO()) as said:
|
||||
answer = interrupt.interrupt(question, answer_here, self.session, WINDOW, effects or fake.effects())
|
||||
answer = interrupt.interrupt(question, answer_here, self.session, WINDOW, prompts.DRIVER, effects or fake.effects())
|
||||
self.bells = said.getvalue().count(tmux.BELL)
|
||||
return answer, said.getvalue().replace(tmux.BELL, "")
|
||||
|
||||
@@ -1004,10 +1004,10 @@ class ModelPrompt(unittest.TestCase):
|
||||
def test_asks_again_until_an_answer_picks_a_model(self):
|
||||
with tempfile.TemporaryDirectory() as empty:
|
||||
fake = FakeEffects(inputs=["", "my-model"])
|
||||
self.assertEqual(model_choice.ask_for_model("proj", pathlib.Path("/m.json"), pathlib.Path(empty), fake.effects()), "my-model")
|
||||
self.assertEqual(model_choice.ask_for_model("proj", pathlib.Path("/m.json"), pathlib.Path(empty), prompts.DRIVER, fake.effects()), "my-model")
|
||||
self.assertEqual(len(fake.made("input")), 2)
|
||||
fake = FakeEffects(inputs=[EOFError()])
|
||||
self.assertEqual(model_choice.ask_for_model("proj", pathlib.Path("/m.json"), pathlib.Path(empty), fake.effects()), Stop(2, "the human is needed to pick proj's model, but the input ended"))
|
||||
self.assertEqual(model_choice.ask_for_model("proj", pathlib.Path("/m.json"), pathlib.Path(empty), prompts.DRIVER, fake.effects()), Stop(2, "the human is needed to pick proj's model, but the input ended"))
|
||||
|
||||
|
||||
# A plan read with no release cut yet.
|
||||
@@ -1308,14 +1308,14 @@ class TmuxCommands(unittest.TestCase):
|
||||
("", "loop-claude runs each chunk in a tmux window, and needs tmux 3.2 or later; it found no tmux")):
|
||||
with self.subTest(found=found):
|
||||
fake = FakeEffects(tmux_version=found)
|
||||
self.assertEqual(tmux.unusable(fake.tmux), reason)
|
||||
self.assertEqual(tmux.unusable(fake.tmux, prompts.DRIVER), reason)
|
||||
self.assertEqual(fake.tmux_calls, [["-V"]])
|
||||
|
||||
def test_names_the_session_for_the_project(self):
|
||||
self.assertEqual(tmux.session_name("claude-config"), "loop-claude-config")
|
||||
self.assertEqual(tmux.session_name(tmux.LOOP, "claude-config"), "loop-claude-config")
|
||||
# tmux reads `.` and `:` in a target as separators.
|
||||
self.assertEqual(tmux.session_name("my.site:2 x"), "loop-my-site-2-x")
|
||||
self.assertEqual(tmux.session_name("Acme/Billing"), "loop-Acme-Billing")
|
||||
self.assertEqual(tmux.session_name(tmux.LOOP, "my.site:2 x"), "loop-my-site-2-x")
|
||||
self.assertEqual(tmux.session_name(tmux.LOOP, "Acme/Billing"), "loop-Acme-Billing")
|
||||
|
||||
def test_lists_the_windows_without_the_waiting_mark(self):
|
||||
fake = FakeEffects(windows="item-372 ?\t0\t@1\nitem-380\t1\t@2\nno-item\t0\t@5\n")
|
||||
@@ -1722,7 +1722,7 @@ class TypedAnswers(unittest.TestCase):
|
||||
self.assertEqual(worker_prompts.typed_answer(prompts.WORKER.typed(f"Which one?\n{marked}", "Use B.", route, None, False)).answer, "Use B.")
|
||||
self.assertEqual(worker_prompts.typed_answer(prompts.WORKER.typed("Which one?", "Use B.", Route(Routing.SONNET, 179, 2, 5), OPUS_PROJECT, True)).answer, "Use B.")
|
||||
self.assertIsNone(worker_prompts.typed_answer(prompts.WORKER.answered("Which one?", marked, route, None, False)))
|
||||
self.assertIsNone(worker_prompts.typed_answer(prompts.resumed(marked, route, None)))
|
||||
self.assertIsNone(worker_prompts.typed_answer(prompts.WORKER.resumed(marked, route, None)))
|
||||
|
||||
|
||||
class WorkerArgs(unittest.TestCase):
|
||||
@@ -1733,24 +1733,24 @@ class WorkerArgs(unittest.TestCase):
|
||||
FACTS = "- A preflight fact."
|
||||
|
||||
def test_names_the_route_in_a_fresh_prompt_only_where_an_item_routed_it(self):
|
||||
routed = prompts.fresh("Do it.", "## Goals", Route(Rung("m", "high"), 3, 4, 5), None, self.FACTS)
|
||||
routed = prompts.WORKER.fresh("Do it.", "## Goals", Route(Rung("m", "high"), 3, 4, 5), None, self.FACTS)
|
||||
self.assertIn(f"Continue any open draft PR or worktree for the chunk before creating a new one. {prompts.READING_RULE} {prompts.NAME_THE_ITEMS}\n\nloop-claude runs you on m at high effort, routed by item 3's L of 4.", routed)
|
||||
unrouted = prompts.fresh("Do it.", "## Goals", Route(Rung("m")), None, self.FACTS)
|
||||
unrouted = prompts.WORKER.fresh("Do it.", "## Goals", Route(Rung("m")), None, self.FACTS)
|
||||
self.assertIn(f"before creating a new one. {prompts.READING_RULE} {prompts.NAME_THE_ITEMS}\n\n{self.FACTS}\n\nThe chunk's", unrouted)
|
||||
self.assertNotIn("loop-claude runs you on", unrouted)
|
||||
|
||||
def test_has_the_routed_worker_count_its_items_size_again_and_puts_the_facts_before_the_scope(self):
|
||||
routed = prompts.fresh("Do it.", "## Goals", Route(Rung("m", "high"), 3, 4, 5), None, self.FACTS)
|
||||
routed = prompts.WORKER.fresh("Do it.", "## Goals", Route(Rung("m", "high"), 3, 4, 5), None, self.FACTS)
|
||||
self.assertIn("item 3's size again", routed)
|
||||
self.assertIn("escalation trigger 1", routed)
|
||||
self.assertIn(f"\n\n{self.FACTS}\n\nThe chunk's", routed)
|
||||
self.assertNotIn("size again", prompts.fresh("Do it.", "## Goals", Route(Rung("m")), None, self.FACTS))
|
||||
self.assertNotIn("size again", prompts.WORKER.fresh("Do it.", "## Goals", Route(Rung("m")), None, self.FACTS))
|
||||
|
||||
def test_gives_each_fresh_worker_the_reading_rule_once(self):
|
||||
rule = "never read more than 80 lines of a file at once, nor take a tool output over 3,000 characters into your context"
|
||||
for route in (Route(Rung("m", "high"), 3, 4, 5), Route(Rung("m"))):
|
||||
with self.subTest(route=route):
|
||||
self.assertEqual(prompts.fresh("Do it.", "## Goals", route, None, self.FACTS).count(rule), 1)
|
||||
self.assertEqual(prompts.WORKER.fresh("Do it.", "## Goals", route, None, self.FACTS).count(rule), 1)
|
||||
|
||||
def test_quotes_what_the_preflight_printed_or_has_the_worker_find_the_facts_itself(self):
|
||||
self.assertIn("\n\n- A fact.", prompts.preflight_facts("- A fact."))
|
||||
@@ -1761,95 +1761,95 @@ class WorkerArgs(unittest.TestCase):
|
||||
def test_has_each_fresh_worker_continue_an_open_draft_pr_or_worktree_once_whatever_the_preflight_found(self):
|
||||
for facts in (prompts.preflight_facts("- A fact."), prompts.preflight_failed("git could not start")):
|
||||
with self.subTest(facts=facts):
|
||||
self.assertEqual(prompts.fresh("Do it.", "## Goals", Route(Rung("m")), None, facts).count("Continue any open draft PR or worktree"), 1)
|
||||
self.assertEqual(prompts.WORKER.fresh("Do it.", "## Goals", Route(Rung("m")), None, facts).count("Continue any open draft PR or worktree"), 1)
|
||||
|
||||
def test_keeps_every_review_on_the_projects_rung_while_the_worker_runs_below_it(self):
|
||||
opus = Rung("claude-opus-5-5", "medium")
|
||||
below = prompts.fresh("Do it.", "## Goals", Route(Rung("claude-sonnet-5-5", "high"), 3, 2, 4), OPUS_PROJECT, self.FACTS)
|
||||
below = prompts.WORKER.fresh("Do it.", "## Goals", Route(Rung("claude-sonnet-5-5", "high"), 3, 2, 4), OPUS_PROJECT, self.FACTS)
|
||||
self.assertIn(f"item 3's L of 2. Launch each reviewer, each comprehension seat and the security pass's subagent with the Agent tool set to model opus, effort medium, the project's rung.{self.SCAN} Your rung is below the project's: launch each subagent that files or scores plan items on the rung `~/.claude/bin/subagent-rung --plan claude-opus-5-5 <L>` prints. Where an item you take into the chunk has an E + I of 5 or more, launch each reviewer with the Agent tool set to `model fable, effort low` from 5, `model fable, effort medium` from 6, `model opus, effort xhigh` from 7 and `model fable, effort high` from 8. When an escalation trigger", below)
|
||||
self.assertNotIn("Launch each", prompts.fresh("Do it.", "## Goals", Route(opus, 3, 2, 4), OPUS_PROJECT, self.FACTS))
|
||||
self.assertNotIn("Launch each", prompts.WORKER.fresh("Do it.", "## Goals", Route(opus, 3, 2, 4), OPUS_PROJECT, self.FACTS))
|
||||
|
||||
def test_launches_reviewers_on_the_rung_the_items_e_plus_i_picks_above_the_workers(self):
|
||||
opus = Rung("claude-opus-5-5", "medium")
|
||||
level = prompts.fresh("Do it.", "## Goals", Route(opus, 3, 2, 6), OPUS_PROJECT, self.FACTS)
|
||||
level = prompts.WORKER.fresh("Do it.", "## Goals", Route(opus, 3, 2, 6), OPUS_PROJECT, self.FACTS)
|
||||
self.assertIn(f"item 3's L of 2. Launch each reviewer with the Agent tool set to model fable, effort medium, the rung item 3's E + I of 6 picks. Where an item you take into the chunk has an E + I of 7 or more, launch each reviewer with the Agent tool set to `model opus, effort xhigh` from 7 and `model fable, effort high` from 8.{self.MARKDOWN} When an escalation trigger", level)
|
||||
below = prompts.fresh("Do it.", "## Goals", Route(Rung("claude-sonnet-5-5", "high"), 3, 2, 5), OPUS_PROJECT, self.FACTS)
|
||||
below = prompts.WORKER.fresh("Do it.", "## Goals", Route(Rung("claude-sonnet-5-5", "high"), 3, 2, 5), OPUS_PROJECT, self.FACTS)
|
||||
self.assertIn(f"item 3's L of 2. Launch each reviewer with the Agent tool set to model fable, effort low, the rung item 3's E + I of 5 picks.{self.SEATS}{self.SCAN} Your rung is below the project's:", below)
|
||||
self.assertNotIn("Launch each reviewer", prompts.resumed("", Route(Rung("claude-fable-5-2", "medium"), 3, 4, 6), OPUS_PROJECT))
|
||||
self.assertNotIn("Launch each reviewer", prompts.WORKER.resumed("", Route(Rung("claude-fable-5-2", "medium"), 3, 4, 6), OPUS_PROJECT))
|
||||
|
||||
def test_names_the_reviewers_rung_each_higher_e_plus_i_an_item_taken_in_picks(self):
|
||||
opus = Rung("claude-opus-5-5", "medium")
|
||||
taking_in = " Where an item you take into the chunk has an E + I of 5 or more, launch each reviewer with the Agent tool set to `model fable, effort low` from 5, `model fable, effort medium` from 6, `model opus, effort xhigh` from 7 and `model fable, effort high` from 8."
|
||||
self.assertIn(f"item 3's L of 2.{taking_in} When an escalation trigger", prompts.fresh("Do it.", "## Goals", Route(opus, 3, 2, 4), OPUS_PROJECT, self.FACTS))
|
||||
self.assertIn(" Where an item you take into the chunk has an E + I of 7 or more, launch each reviewer with the Agent tool set to `model opus, effort xhigh` from 7 and `model fable, effort high` from 8.", prompts.resumed("", Route(opus, 3, 2, 6), OPUS_PROJECT))
|
||||
self.assertIn(" Where an item you take into the chunk has an E + I of 7 or more, launch each reviewer with the Agent tool set to `model opus, effort xhigh` from 7 and `model fable, effort high` from 8.", prompts.resumed("", Route(Rung("claude-fable-5-2", "medium"), 3, 4, 4), OPUS_PROJECT))
|
||||
self.assertNotIn("Where an item you take into", prompts.resumed("", Route(opus, 3, 2, 8), OPUS_PROJECT))
|
||||
self.assertNotIn("Where an item you take into", prompts.resumed("", Route(Rung("m")), None))
|
||||
self.assertIn(f"item 3's L of 2.{taking_in} When an escalation trigger", prompts.WORKER.fresh("Do it.", "## Goals", Route(opus, 3, 2, 4), OPUS_PROJECT, self.FACTS))
|
||||
self.assertIn(" Where an item you take into the chunk has an E + I of 7 or more, launch each reviewer with the Agent tool set to `model opus, effort xhigh` from 7 and `model fable, effort high` from 8.", prompts.WORKER.resumed("", Route(opus, 3, 2, 6), OPUS_PROJECT))
|
||||
self.assertIn(" Where an item you take into the chunk has an E + I of 7 or more, launch each reviewer with the Agent tool set to `model opus, effort xhigh` from 7 and `model fable, effort high` from 8.", prompts.WORKER.resumed("", Route(Rung("claude-fable-5-2", "medium"), 3, 4, 4), OPUS_PROJECT))
|
||||
self.assertNotIn("Where an item you take into", prompts.WORKER.resumed("", Route(opus, 3, 2, 8), OPUS_PROJECT))
|
||||
self.assertNotIn("Where an item you take into", prompts.WORKER.resumed("", Route(Rung("m")), None))
|
||||
|
||||
def test_launches_reviewers_on_the_rung_the_highest_e_plus_i_taken_in_picks(self):
|
||||
opus = Rung("claude-opus-5-5", "medium")
|
||||
self.assertIn(f"loop-claude runs you on claude-opus-5-5 at medium effort. Launch each reviewer with the Agent tool set to model opus, effort xhigh, the rung picked by an item of E + I 7 taken into the chunk. Where an item you take into the chunk has an E + I of 8 or more, launch each reviewer with the Agent tool set to `model fable, effort high` from 8.{self.MARKDOWN} When an escalation trigger", prompts.resumed("", Route(opus, 3, 2, 5, escape_and_impact_taken_in=7), OPUS_PROJECT))
|
||||
self.assertIn(" Launch each reviewer with the Agent tool set to model fable, effort low, the rung picked by an item of E + I 5 taken into the chunk.", prompts.resumed("", Route(opus, escape_and_impact_taken_in=5), OPUS_PROJECT))
|
||||
self.assertIn(f"loop-claude runs you on claude-opus-5-5 at medium effort. Launch each reviewer with the Agent tool set to model opus, effort xhigh, the rung picked by an item of E + I 7 taken into the chunk. Where an item you take into the chunk has an E + I of 8 or more, launch each reviewer with the Agent tool set to `model fable, effort high` from 8.{self.MARKDOWN} When an escalation trigger", prompts.WORKER.resumed("", Route(opus, 3, 2, 5, escape_and_impact_taken_in=7), OPUS_PROJECT))
|
||||
self.assertIn(" Launch each reviewer with the Agent tool set to model fable, effort low, the rung picked by an item of E + I 5 taken into the chunk.", prompts.WORKER.resumed("", Route(opus, escape_and_impact_taken_in=5), OPUS_PROJECT))
|
||||
|
||||
def test_keeps_seats_and_the_security_pass_on_the_projects_rung_while_the_worker_runs_above_it(self):
|
||||
opus = Rung("claude-opus-5-5", "medium")
|
||||
above = prompts.fresh("Do it.", "## Goals", Route(Rung("claude-fable-5-2", "low"), 3, 3, 4), OPUS_PROJECT, self.FACTS)
|
||||
stepped_up = prompts.resumed("", Route(Rung("claude-fable-5-2", "low"), 3, 3, 4), OPUS_PROJECT)
|
||||
above = prompts.WORKER.fresh("Do it.", "## Goals", Route(Rung("claude-fable-5-2", "low"), 3, 3, 4), OPUS_PROJECT, self.FACTS)
|
||||
stepped_up = prompts.WORKER.resumed("", Route(Rung("claude-fable-5-2", "low"), 3, 3, 4), OPUS_PROJECT)
|
||||
self.assertIn(f"{prompts.ANSWERS_RECORDED}. {prompts.NAME_THE_ITEMS} loop-claude runs you on claude-fable-5-2 at low effort.{self.SEATS}{self.SCAN} Where an item you take into the chunk has an E + I of 6 or more, launch each reviewer with the Agent tool set to `model fable, effort medium` from 6, `model opus, effort xhigh` from 7 and `model fable, effort high` from 8.{self.MARKDOWN} When an escalation trigger", stepped_up)
|
||||
self.assertNotIn("the project's", prompts.resumed("", Route(opus, 3, 2, 4), OPUS_PROJECT))
|
||||
self.assertNotIn("runs you on", prompts.resumed("", Route(Rung("m")), None))
|
||||
self.assertNotIn("the project's", prompts.WORKER.resumed("", Route(opus, 3, 2, 4), OPUS_PROJECT))
|
||||
self.assertNotIn("runs you on", prompts.WORKER.resumed("", Route(Rung("m")), None))
|
||||
self.assertIn(f"item 3's L of 3.{self.SEATS}{self.SCAN} Where an item you take into the chunk has an E + I of 6 or more, launch each reviewer with the Agent tool set to `model fable, effort medium` from 6, `model opus, effort xhigh` from 7 and `model fable, effort high` from 8.{self.MARKDOWN} When an escalation trigger", above)
|
||||
|
||||
def test_names_the_rungs_an_escalation_trigger_lets_the_worker_hand_a_task_to_at_most_two_above_its_items(self):
|
||||
opus = Rung("claude-opus-5-5", "medium")
|
||||
fresh = prompts.fresh("Do it.", "## Goals", Route(opus, 3, 2, 4), OPUS_PROJECT, self.FACTS)
|
||||
fresh = prompts.WORKER.fresh("Do it.", "## Goals", Route(opus, 3, 2, 4), OPUS_PROJECT, self.FACTS)
|
||||
self.assertIn("item 3's L of 2. Where an item you take into the chunk has an E + I of 5 or more, launch each reviewer with the Agent tool set to `model fable, effort low` from 5, `model fable, effort medium` from 6, `model opus, effort xhigh` from 7 and `model fable, effort high` from 8. When an escalation trigger in `~/.claude/CLAUDE.md` fires, hand the hard part of the task to a subagent with the Agent tool set to `model fable, effort low`, one rung above yours; above that, ask the human first. Open the subagent's prompt with `Escalation trigger <n>:`, n the trigger's number.", fresh)
|
||||
self.assertIn(" When an escalation trigger in `~/.claude/CLAUDE.md` fires, hand the hard part of the task to a subagent with the Agent tool set to `model fable, effort medium`, one rung above yours, and on each further trigger one rung higher, up to `model opus, effort xhigh`; above that, ask the human first. Open the subagent's prompt with `Escalation trigger <n>:`, n the trigger's number.", prompts.resumed("", Route(Rung("claude-fable-5-2", "low"), 3, 3, 4), OPUS_PROJECT))
|
||||
self.assertIn(" When an escalation trigger in `~/.claude/CLAUDE.md` fires, hand the hard part of the task to a subagent with the Agent tool set to `model opus, effort xhigh`, one rung above yours; above that, ask the human first. Open the subagent's prompt with `Escalation trigger <n>:`, n the trigger's number.", prompts.resumed("", Route(Rung("claude-fable-5-2", "medium"), 3, 3, 4), OPUS_PROJECT))
|
||||
self.assertNotIn("escalation", prompts.resumed("", Route(Rung("claude-fable-5-2", "max"), 3, 4, 8), OPUS_PROJECT))
|
||||
self.assertIn(" An escalation trigger in `~/.claude/CLAUDE.md` lets you hand the hard part of a task to a subagent with the Agent tool set to `model fable, effort high`, one rung above yours, only once the human agrees;", prompts.resumed("", Route(Rung("claude-opus-5-5", "xhigh"), 3, 3, 4), OPUS_PROJECT))
|
||||
self.assertIn("set to `model fable, effort max`, one rung above yours, only once the human agrees;", prompts.resumed("", Route(Rung("claude-fable-5-2", "high"), 3, 4, 5), OPUS_PROJECT), "one rung below the top still names the rung above")
|
||||
self.assertNotIn("rerun", prompts.resumed("", Route(Rung("claude-opus-5-5", "low"), 3, 3, 4), OPUS_PROJECT), "a worker off the ladder is told no rerun rung")
|
||||
self.assertIn("hand the hard part of the task to a subagent with the Agent tool set to `model fable, effort high`, one rung above yours;", prompts.resumed("", Route(Rung("claude-opus-5-5", "xhigh"), 3, 4, 5), OPUS_PROJECT))
|
||||
self.assertNotIn("escalation", prompts.resumed("", Route(Rung("m")), None))
|
||||
self.assertNotIn("escalation", prompts.resumed("", Route(Rung("claude-opus-5-5", "low"), 3, 3, 4), OPUS_PROJECT))
|
||||
self.assertIn(f"{prompts.READING_RULE} {prompts.NAME_THE_ITEMS}\n\nWhere an item you take into the chunk has an E + I of 5 or more, launch each reviewer with the Agent tool set to `model fable, effort low` from 5, `model fable, effort medium` from 6, `model opus, effort xhigh` from 7 and `model fable, effort high` from 8. When an escalation trigger in `~/.claude/CLAUDE.md` fires, hand the hard part of the task to a subagent with the Agent tool set to `model fable, effort low`, one rung above yours, and on each further trigger one rung higher, up to `model fable, effort medium`; above that, ask the human first. Open the subagent's prompt with `Escalation trigger <n>:`, n the trigger's number. Where the hard part is the rest of the chunk, end your run instead, asking loop-claude for a higher rung and naming a trigger that fired since your last step-up, if any: once the judge finds it in your transcript, the next cycle resumes you one rung up, up to `model fable, effort medium`. A reviewer", prompts.fresh("Do it.", "## Goals", Route(opus), OPUS_PROJECT, self.FACTS))
|
||||
self.assertIn(" When an escalation trigger in `~/.claude/CLAUDE.md` fires, hand the hard part of the task to a subagent with the Agent tool set to `model fable, effort medium`, one rung above yours, and on each further trigger one rung higher, up to `model opus, effort xhigh`; above that, ask the human first. Open the subagent's prompt with `Escalation trigger <n>:`, n the trigger's number.", prompts.WORKER.resumed("", Route(Rung("claude-fable-5-2", "low"), 3, 3, 4), OPUS_PROJECT))
|
||||
self.assertIn(" When an escalation trigger in `~/.claude/CLAUDE.md` fires, hand the hard part of the task to a subagent with the Agent tool set to `model opus, effort xhigh`, one rung above yours; above that, ask the human first. Open the subagent's prompt with `Escalation trigger <n>:`, n the trigger's number.", prompts.WORKER.resumed("", Route(Rung("claude-fable-5-2", "medium"), 3, 3, 4), OPUS_PROJECT))
|
||||
self.assertNotIn("escalation", prompts.WORKER.resumed("", Route(Rung("claude-fable-5-2", "max"), 3, 4, 8), OPUS_PROJECT))
|
||||
self.assertIn(" An escalation trigger in `~/.claude/CLAUDE.md` lets you hand the hard part of a task to a subagent with the Agent tool set to `model fable, effort high`, one rung above yours, only once the human agrees;", prompts.WORKER.resumed("", Route(Rung("claude-opus-5-5", "xhigh"), 3, 3, 4), OPUS_PROJECT))
|
||||
self.assertIn("set to `model fable, effort max`, one rung above yours, only once the human agrees;", prompts.WORKER.resumed("", Route(Rung("claude-fable-5-2", "high"), 3, 4, 5), OPUS_PROJECT), "one rung below the top still names the rung above")
|
||||
self.assertNotIn("rerun", prompts.WORKER.resumed("", Route(Rung("claude-opus-5-5", "low"), 3, 3, 4), OPUS_PROJECT), "a worker off the ladder is told no rerun rung")
|
||||
self.assertIn("hand the hard part of the task to a subagent with the Agent tool set to `model fable, effort high`, one rung above yours;", prompts.WORKER.resumed("", Route(Rung("claude-opus-5-5", "xhigh"), 3, 4, 5), OPUS_PROJECT))
|
||||
self.assertNotIn("escalation", prompts.WORKER.resumed("", Route(Rung("m")), None))
|
||||
self.assertNotIn("escalation", prompts.WORKER.resumed("", Route(Rung("claude-opus-5-5", "low"), 3, 3, 4), OPUS_PROJECT))
|
||||
self.assertIn(f"{prompts.READING_RULE} {prompts.NAME_THE_ITEMS}\n\nWhere an item you take into the chunk has an E + I of 5 or more, launch each reviewer with the Agent tool set to `model fable, effort low` from 5, `model fable, effort medium` from 6, `model opus, effort xhigh` from 7 and `model fable, effort high` from 8. When an escalation trigger in `~/.claude/CLAUDE.md` fires, hand the hard part of the task to a subagent with the Agent tool set to `model fable, effort low`, one rung above yours, and on each further trigger one rung higher, up to `model fable, effort medium`; above that, ask the human first. Open the subagent's prompt with `Escalation trigger <n>:`, n the trigger's number. Where the hard part is the rest of the chunk, end your run instead, asking loop-claude for a higher rung and naming a trigger that fired since your last step-up, if any: once the judge finds it in your transcript, the next cycle resumes you one rung up, up to `model fable, effort medium`. A reviewer", prompts.WORKER.fresh("Do it.", "## Goals", Route(opus), OPUS_PROJECT, self.FACTS))
|
||||
|
||||
def test_offers_the_worker_a_higher_rung_for_the_rest_of_the_chunk_up_to_the_escalation_cap(self):
|
||||
opus = Rung("claude-opus-5-5", "medium")
|
||||
offer = lambda cap: f" Where the hard part is the rest of the chunk, end your run instead, asking loop-claude for a higher rung and naming a trigger that fired since your last step-up, if any: once the judge finds it in your transcript, the next cycle resumes you one rung up, up to `{cap}`."
|
||||
self.assertIn(f"`Escalation trigger <n>:`, n the trigger's number.{offer('model fable, effort low')}", prompts.fresh("Do it.", "## Goals", Route(opus, 3, 2, 4), OPUS_PROJECT, self.FACTS))
|
||||
self.assertIn(f"`Escalation trigger <n>:`, n the trigger's number.{offer('model opus, effort xhigh')}", prompts.resumed("", Route(Rung("claude-fable-5-2", "low"), 3, 3, 4), OPUS_PROJECT))
|
||||
self.assertNotIn("Where the hard part", prompts.resumed("", Route(Rung("claude-opus-5-5", "xhigh"), 3, 3, 4), OPUS_PROJECT))
|
||||
self.assertIn(f"`Escalation trigger <n>:`, n the trigger's number.{offer('model fable, effort low')}", prompts.WORKER.fresh("Do it.", "## Goals", Route(opus, 3, 2, 4), OPUS_PROJECT, self.FACTS))
|
||||
self.assertIn(f"`Escalation trigger <n>:`, n the trigger's number.{offer('model opus, effort xhigh')}", prompts.WORKER.resumed("", Route(Rung("claude-fable-5-2", "low"), 3, 3, 4), OPUS_PROJECT))
|
||||
self.assertNotIn("Where the hard part", prompts.WORKER.resumed("", Route(Rung("claude-opus-5-5", "xhigh"), 3, 3, 4), OPUS_PROJECT))
|
||||
|
||||
def test_lets_a_markdown_only_branch_review_on_the_projects_rung_where_the_reviewers_run_above_it(self):
|
||||
opus = Rung("claude-opus-5-5", "medium")
|
||||
markdown = " Where your branch changes only Markdown, none of it `CLAUDE.md`, `AGENTS.md`, `workflow-bench/*-prompt.md` or under `agents/`, `principles/`, `rules/` or `skills/`, launch each reviewer on the project's rung instead, with the Agent tool set to model opus, effort medium."
|
||||
self.assertIn(markdown, prompts.fresh("Do it.", "## Goals", Route(opus, 3, 2, 7), OPUS_PROJECT, self.FACTS))
|
||||
self.assertIn(markdown, prompts.resumed("", Route(Rung("claude-fable-5-2", "low"), 3, 3, 4), OPUS_PROJECT))
|
||||
self.assertNotIn("only Markdown", prompts.fresh("Do it.", "## Goals", Route(opus, 3, 2, 4), OPUS_PROJECT, self.FACTS))
|
||||
self.assertIn(markdown, prompts.WORKER.fresh("Do it.", "## Goals", Route(opus, 3, 2, 7), OPUS_PROJECT, self.FACTS))
|
||||
self.assertIn(markdown, prompts.WORKER.resumed("", Route(Rung("claude-fable-5-2", "low"), 3, 3, 4), OPUS_PROJECT))
|
||||
self.assertNotIn("only Markdown", prompts.WORKER.fresh("Do it.", "## Goals", Route(opus, 3, 2, 4), OPUS_PROJECT, self.FACTS))
|
||||
|
||||
def test_names_the_rung_a_reviewer_or_seat_reruns_on_one_above_its_own(self):
|
||||
opus = Rung("claude-opus-5-5", "medium")
|
||||
both = " A reviewer or comprehension seat that asks for a rerun one rung up reruns with the Agent tool set to `model fable, effort low`."
|
||||
self.assertTrue(prompts.resumed("", Route(opus, 3, 2, 4), OPUS_PROJECT).endswith(both))
|
||||
self.assertTrue(prompts.resumed("", Route(Rung("claude-sonnet-5-5", "high"), 3, 2, 4), OPUS_PROJECT).endswith(both))
|
||||
self.assertTrue(prompts.fresh("Do it.", "## Goals", Route(opus), OPUS_PROJECT, self.FACTS).split(f"\n\n{self.FACTS}")[0].endswith(both))
|
||||
self.assertTrue(prompts.resumed("", Route(Rung("claude-fable-5-2", "low"), 3, 3, 4), OPUS_PROJECT).endswith(" A reviewer that asks for a rerun one rung up reruns with the Agent tool set to `model fable, effort medium`, and a comprehension seat with `model fable, effort low`."))
|
||||
self.assertTrue(prompts.resumed("", Route(opus, 3, 2, 7), OPUS_PROJECT).endswith(" A reviewer that asks for a rerun one rung up reruns with the Agent tool set to `model fable, effort high`, and a comprehension seat with `model fable, effort low`."))
|
||||
self.assertTrue(prompts.resumed("", Route(Rung("claude-fable-5-2", "max"), 3, 4, 8), OPUS_PROJECT).endswith(" A comprehension seat that asks for a rerun one rung up reruns with the Agent tool set to `model fable, effort low`."))
|
||||
self.assertNotIn("rerun", prompts.resumed("", Route(Rung("m")), None))
|
||||
self.assertNotIn("rerun", prompts.fresh("Do it.", "## Goals", Route(Rung("m", "high"), 3, 4, 5), None, self.FACTS))
|
||||
self.assertIn(f"{both} After your first read", prompts.fresh("Do it.", "## Goals", Route(opus, 3, 2, 4), OPUS_PROJECT, self.FACTS))
|
||||
self.assertTrue(prompts.WORKER.resumed("", Route(opus, 3, 2, 4), OPUS_PROJECT).endswith(both))
|
||||
self.assertTrue(prompts.WORKER.resumed("", Route(Rung("claude-sonnet-5-5", "high"), 3, 2, 4), OPUS_PROJECT).endswith(both))
|
||||
self.assertTrue(prompts.WORKER.fresh("Do it.", "## Goals", Route(opus), OPUS_PROJECT, self.FACTS).split(f"\n\n{self.FACTS}")[0].endswith(both))
|
||||
self.assertTrue(prompts.WORKER.resumed("", Route(Rung("claude-fable-5-2", "low"), 3, 3, 4), OPUS_PROJECT).endswith(" A reviewer that asks for a rerun one rung up reruns with the Agent tool set to `model fable, effort medium`, and a comprehension seat with `model fable, effort low`."))
|
||||
self.assertTrue(prompts.WORKER.resumed("", Route(opus, 3, 2, 7), OPUS_PROJECT).endswith(" A reviewer that asks for a rerun one rung up reruns with the Agent tool set to `model fable, effort high`, and a comprehension seat with `model fable, effort low`."))
|
||||
self.assertTrue(prompts.WORKER.resumed("", Route(Rung("claude-fable-5-2", "max"), 3, 4, 8), OPUS_PROJECT).endswith(" A comprehension seat that asks for a rerun one rung up reruns with the Agent tool set to `model fable, effort low`."))
|
||||
self.assertNotIn("rerun", prompts.WORKER.resumed("", Route(Rung("m")), None))
|
||||
self.assertNotIn("rerun", prompts.WORKER.fresh("Do it.", "## Goals", Route(Rung("m", "high"), 3, 4, 5), None, self.FACTS))
|
||||
self.assertIn(f"{both} After your first read", prompts.WORKER.fresh("Do it.", "## Goals", Route(opus, 3, 2, 4), OPUS_PROJECT, self.FACTS))
|
||||
fable = Rung("claude-fable-5-2", "max")
|
||||
self.assertNotIn("rerun", prompts.resumed("", Route(fable), ProjectRung(LADDER, fable)))
|
||||
self.assertNotIn("rerun", prompts.WORKER.resumed("", Route(fable), ProjectRung(LADDER, fable)))
|
||||
|
||||
def test_opens_a_fresh_session_by_name_and_resumes_an_open_one(self):
|
||||
opened = session.session_named("A proj loop-claude", pathlib.Path("/h/.claude/projects"))
|
||||
fresh = worker.worker_args(opened, Rung("m"), prompts.fresh("Do it.", "## Goals\n1. g\n\n## Audience\nme", Route(Rung("m")), None, self.FACTS), resume=False)
|
||||
fresh = worker.worker_args(opened, Rung("m"), prompts.WORKER.fresh("Do it.", "## Goals\n1. g\n\n## Audience\nme", Route(Rung("m")), None, self.FACTS), resume=False)
|
||||
self.assertEqual(fresh[fresh.index("--session-id") + 1], str(opened.id))
|
||||
self.assertEqual(fresh[fresh.index("--name") + 1], "A proj loop-claude")
|
||||
resumed = worker.worker_args(opened, Rung("m"), prompts.resumed("", Route(Rung("m")), None), resume=True)
|
||||
resumed = worker.worker_args(opened, Rung("m"), prompts.WORKER.resumed("", Route(Rung("m")), None), resume=True)
|
||||
self.assertEqual(resumed[resumed.index("--resume") + 1], str(opened.id))
|
||||
self.assertNotIn("--session-id", resumed)
|
||||
self.assertTrue(resumed[resumed.index("-p") + 1].startswith("Continue the task; the previous run ended before the chunk was finished. The chunk is finished once"))
|
||||
@@ -1924,7 +1924,7 @@ class Records(unittest.TestCase):
|
||||
class JudgePrompt(unittest.TestCase):
|
||||
def test_shows_the_transcripts_tail_and_returns_what_it_showed(self):
|
||||
entries = [assistant({"type": "text", "text": "old " + "x" * judge.JUDGE_PROMPT_CHARS}), assistant({"type": "text", "text": "new"})]
|
||||
prompt, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), 0))
|
||||
prompt, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), 0, prompts.DRIVER))
|
||||
self.assertTrue(grounds.shown.endswith("\n\nnew"))
|
||||
self.assertNotIn("old", grounds.shown)
|
||||
self.assertIn(grounds.shown, prompt)
|
||||
@@ -1933,11 +1933,11 @@ class JudgePrompt(unittest.TestCase):
|
||||
self.assertEqual(grounds.quotable, "## Goals\n\n")
|
||||
|
||||
def test_the_judge_prompt_and_schema_call_the_worker_the_worker(self):
|
||||
prompt, _ = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(assistant({"type": "text", "text": "done"})), 1))
|
||||
self.assertNotRegex(prompt + json.dumps(judge.JUDGE_SCHEMA), r"\b[Aa]gent")
|
||||
prompt, _ = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(assistant({"type": "text", "text": "done"})), 1, prompts.DRIVER))
|
||||
self.assertNotRegex(prompt + json.dumps(judge.judge_schema(prompts.DRIVER)), r"\b[Aa]gent")
|
||||
|
||||
def test_the_judge_prompt_names_the_entry_points_answer_destinations_in_both_rules_on_a_recorded_answer(self):
|
||||
prompt, _ = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", "the ledger", kinds(assistant({"type": "text", "text": "done"})), 0))
|
||||
prompt, _ = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", "the ledger", kinds(assistant({"type": "text", "text": "done"})), 0, prompts.DRIVER))
|
||||
self.assertIn("is recorded in the ledger at the one place it governs", prompt)
|
||||
self.assertIn("the worker writing it into the ledger, but not into one of the human's rules", prompt)
|
||||
|
||||
@@ -1946,28 +1946,28 @@ class JudgePrompt(unittest.TestCase):
|
||||
self.assertIn("is recorded in the ledger at the one place it governs.", ledger.typed("Which one?", "Use B.", Route(Rung("worker-model")), None, False))
|
||||
|
||||
def test_the_judge_prompt_names_every_rule_the_judge_reads_from_the_human(self):
|
||||
self.assertEqual([name for name in records.HUMAN_RULE_NAMES if name not in judge.judge_rules(prompts.ANSWER_DESTINATIONS)], [])
|
||||
self.assertEqual([name for name in records.HUMAN_RULE_NAMES if name not in judge.judge_rules(prompts.ANSWER_DESTINATIONS, prompts.DRIVER)], [])
|
||||
|
||||
def test_shows_the_judge_where_the_worker_last_stepped_up_and_checks_an_escalation_only_after_it(self):
|
||||
entries = [assistant({"type": "text", "text": "round 2: 🔴"}), assistant({"type": "text", "text": "round 3: 🔴"})]
|
||||
prompt, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), 1))
|
||||
prompt, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), 1, prompts.DRIVER))
|
||||
self.assertRegex(prompt, "round 2: 🔴\n\n\\[step\\] [^\n]+\n\nround 3: 🔴\n\n")
|
||||
self.assertEqual(grounds.after_mark, "round 3: 🔴")
|
||||
prompt, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), 0))
|
||||
prompt, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), 0, prompts.DRIVER))
|
||||
self.assertNotIn("stepped the worker up", prompt)
|
||||
self.assertEqual(grounds.shown, "round 2: 🔴\n\nround 3: 🔴")
|
||||
self.assertEqual(grounds.after_mark, "round 2: 🔴\n\nround 3: 🔴")
|
||||
|
||||
def test_drops_an_escalation_quote_from_after_the_step_up_that_the_tail_it_shows_cuts_off(self):
|
||||
entries = [assistant({"type": "text", "text": "round 2: 🔴"}), assistant({"type": "text", "text": "old " + "x" * judge.JUDGE_PROMPT_CHARS}), assistant({"type": "text", "text": "new"})]
|
||||
_, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), 1))
|
||||
_, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), 1, prompts.DRIVER))
|
||||
self.assertEqual(judge.quotes_checked(Unfinished("e", "old x", entries_read=3), grounds), Unfinished("e", entries_read=3))
|
||||
self.assertEqual(judge.quotes_checked(Unfinished("e", "new", entries_read=3), grounds), Unfinished("e", "new", entries_read=3))
|
||||
|
||||
def test_shows_a_typed_answer_before_the_step_up_as_the_humans(self):
|
||||
typed = prompts.WORKER.typed("Which one?", "Use B.", Route(Rung("worker-model")), None, False)
|
||||
entries = [{**human(typed), "promptSource": "sdk"}, assistant({"type": "text", "text": "round 3: 🔴"})]
|
||||
_, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), 1))
|
||||
_, grounds = judge.judge_prompt(judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), 1, prompts.DRIVER))
|
||||
self.assertIn("\n\n[human] Use B.\n\n[step] ", grounds.shown)
|
||||
|
||||
|
||||
@@ -2105,7 +2105,7 @@ class ChunkItems(unittest.TestCase):
|
||||
self.assertEqual(chunk_items.named([said(example)]), (297, 298))
|
||||
|
||||
def test_every_prompt_that_starts_or_resumes_a_chunk_asks_for_the_line(self):
|
||||
self.assertIn("on one line, as in `Chunk items: ", prompts.resumed("", Route(Rung("m")), None))
|
||||
self.assertIn("on one line, as in `Chunk items: ", prompts.WORKER.resumed("", Route(Rung("m")), None))
|
||||
|
||||
def test_reads_only_a_line_the_worker_opens_with_the_label_in_its_own_text(self):
|
||||
prompt = entries.LoopPrompt(text="Chunk items: 297 (L 3, E + I 5)")
|
||||
@@ -2194,7 +2194,7 @@ class Verdict(unittest.TestCase):
|
||||
def test_drops_an_escalation_quote_found_only_in_the_transcript_entries_before_the_workers_last_step_up(self):
|
||||
entries = [assistant({"type": "text", "text": "round 2: 🔴"}), assistant({"type": "text", "text": "round 3: 🔴"}), assistant({"type": "text", "text": "working"})]
|
||||
def judged_on(mark, escalation):
|
||||
return judge.judge_once("/r", judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), mark), Rung("judge-model"), FakeEffects(claude=[judged("unfinished", escalation=escalation)]).effects())
|
||||
return judge.judge_once("/r", judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), mark, prompts.DRIVER), Rung("judge-model"), FakeEffects(claude=[judged("unfinished", escalation=escalation)]).effects())
|
||||
self.assertEqual(judged_on(0, "round 2: 🔴"), Unfinished("working", "round 2: 🔴", entries_read=3))
|
||||
self.assertEqual(judged_on(1, "round 2: 🔴"), Unfinished("working", entries_read=3))
|
||||
self.assertEqual(judged_on(1, "round 3: 🔴"), Unfinished("working", "round 3: 🔴", entries_read=3))
|
||||
@@ -2203,12 +2203,12 @@ class Verdict(unittest.TestCase):
|
||||
|
||||
def test_drops_an_escalation_quote_that_only_loop_claudes_prompts_or_the_humans_lines_repeat_after_the_step_up(self):
|
||||
entries = [assistant({"type": "text", "text": "round 2: 🔴"}), {**human("as the work remaining: round 2: 🔴"), "promptSource": "sdk"}, human("round 2: 🔴 again"), assistant({"type": "text", "text": "working"})]
|
||||
verdict = judge.judge_once("/r", judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), 1), Rung("judge-model"), FakeEffects(claude=[judged("unfinished", escalation="round 2: 🔴")]).effects())
|
||||
verdict = judge.judge_once("/r", judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), 1, prompts.DRIVER), Rung("judge-model"), FakeEffects(claude=[judged("unfinished", escalation="round 2: 🔴")]).effects())
|
||||
self.assertEqual(verdict, Unfinished("working", entries_read=4))
|
||||
|
||||
def test_takes_evidence_from_before_the_workers_last_step_up(self):
|
||||
entries = [assistant({"type": "text", "text": "round 2: 🔴"}), assistant({"type": "text", "text": "working"})]
|
||||
verdict = judge.judge_once("/r", judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), 1), Rung("judge-model"), FakeEffects(claude=[judged("unfinished", evidence="round 2: 🔴")]).effects())
|
||||
verdict = judge.judge_once("/r", judge.Brief("Do it.", "## Goals", "", prompts.ANSWER_DESTINATIONS, kinds(*entries), 1, prompts.DRIVER), Rung("judge-model"), FakeEffects(claude=[judged("unfinished", evidence="round 2: 🔴")]).effects())
|
||||
self.assertEqual(verdict, Unfinished("round 2: 🔴", entries_read=2))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user