Answer the architecture pass's first round
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import sys
|
||||
import uuid
|
||||
|
||||
from loop_claude.claude_code.transcript import human_turns, read
|
||||
from loop_claude.claude_code.transcript import human_turns, read_transcript
|
||||
from loop_claude.claude_code.trust import trust
|
||||
from loop_claude.effects import Effects
|
||||
from loop_claude.failure import Failure
|
||||
from loop_claude.paths import Paths
|
||||
from loop_claude.project.checkout import checkouts
|
||||
from loop_claude.project.checkout import worktrees
|
||||
from loop_claude.stop import Stop, needs_human, needs_terminal
|
||||
|
||||
ANSWER_QUESTION = "answer the question above"
|
||||
@@ -16,8 +16,8 @@ def interrupt(root: str, session_id: uuid.UUID, model: str, path: str, question:
|
||||
print(f"\n{question}", file=sys.stderr)
|
||||
if stop := needs_terminal(ANSWER_QUESTION, effects.on_terminal()):
|
||||
return stop
|
||||
trust(paths.claude_json, checkouts(root, effects))
|
||||
entries = read(path)
|
||||
trust(paths.claude_json, worktrees(root, effects))
|
||||
entries = read_transcript(path)
|
||||
if isinstance(entries, Failure):
|
||||
return Stop(1, entries.reason)
|
||||
before = human_turns(entries)
|
||||
@@ -25,7 +25,7 @@ def interrupt(root: str, session_id: uuid.UUID, model: str, path: str, question:
|
||||
effects.claude_on_terminal(["--model", model, "--permission-mode", "bypassPermissions", "--resume", str(session_id)], root)
|
||||
except OSError as failure:
|
||||
return Stop(1, f"could not start claude for the interrupt: {failure.strerror}")
|
||||
entries = read(path)
|
||||
entries = read_transcript(path)
|
||||
if isinstance(entries, Failure):
|
||||
return Stop(1, f"could not tell whether you typed anything: {entries.reason}")
|
||||
return None if human_turns(entries) > before else needs_human(ANSWER_QUESTION, "the interrupt ended with nothing typed")
|
||||
|
||||
@@ -9,6 +9,8 @@ from loop_claude.effects import Effects
|
||||
from loop_claude.failure import Failure
|
||||
from loop_claude.stop import Stop
|
||||
|
||||
JUDGED_TRANSCRIPT_TAIL = 40000
|
||||
|
||||
JUDGE_RULES = (
|
||||
"Decide whether the human must now be interrupted. interrupt=true when any of these appear:\n"
|
||||
"- the agent asks the human anything, seeks approval, or says a decision is the human's\n"
|
||||
@@ -81,7 +83,7 @@ def judge_prompt(task: str, premises: str, rendered_transcript: str) -> str:
|
||||
f"From README.md:\n{premises}\n\n"
|
||||
f"The task an agent was given:\n{task}\n\n"
|
||||
# The tail, where an interrupt or a finish lands; the session's transcript grows cycle over cycle.
|
||||
f"What the agent did and said, and what the human typed on [human] lines, latest last:\n{rendered_transcript[-40000:]}\n\n"
|
||||
f"What the agent did and said, and what the human typed on [human] lines, latest last:\n{rendered_transcript[-JUDGED_TRANSCRIPT_TAIL:]}\n\n"
|
||||
f"{JUDGE_RULES}"
|
||||
)
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ from loop_claude.effects import Effects
|
||||
from loop_claude.failure import Failure
|
||||
from loop_claude.stop import Stop
|
||||
|
||||
ATTEMPTS = 3
|
||||
RETRY_DELAY_SECONDS = 60
|
||||
T = typing.TypeVar("T")
|
||||
|
||||
|
||||
@@ -15,7 +17,7 @@ def retried(who: str, attempt: typing.Callable[[], T | Failure], effects: Effect
|
||||
result = attempt()
|
||||
if not isinstance(result, Failure):
|
||||
return result
|
||||
if failures == 3:
|
||||
if failures == ATTEMPTS:
|
||||
return Stop(1, f"the {who} failed three times running: {result.reason}")
|
||||
print(f"retrying the {who} in a minute: {result.reason}", file=sys.stderr)
|
||||
effects.sleep(60)
|
||||
effects.sleep(RETRY_DELAY_SECONDS)
|
||||
|
||||
@@ -2,7 +2,7 @@ import dataclasses
|
||||
import typing
|
||||
|
||||
from loop_claude.claude_code.session import Session, delete_session, session_open, transcript_file
|
||||
from loop_claude.claude_code.transcript import read, render
|
||||
from loop_claude.claude_code.transcript import read_transcript, render
|
||||
from loop_claude.cycle.archive import archive
|
||||
from loop_claude.cycle.interrupt import interrupt
|
||||
from loop_claude.cycle.judge import judge
|
||||
@@ -12,7 +12,7 @@ from loop_claude.cycle.worker import run_worker, worker_args
|
||||
from loop_claude.effects import Effects
|
||||
from loop_claude.failure import Failure
|
||||
from loop_claude.paths import Paths
|
||||
from loop_claude.project.models import Models
|
||||
from loop_claude.project.model_choice import Models
|
||||
from loop_claude.stop import Stop
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ def work(cycle: Cycle) -> WorkerRan | Stop:
|
||||
|
||||
|
||||
def rule(cycle: Cycle, transcript_path: str) -> Ruled | Stop:
|
||||
entries = read(transcript_path)
|
||||
entries = read_transcript(transcript_path)
|
||||
if isinstance(entries, Failure):
|
||||
return Stop(1, entries.reason)
|
||||
verdict = judge(cycle.root, cycle.task, cycle.premises, render(entries), cycle.models.judge, cycle.effects)
|
||||
|
||||
@@ -66,6 +66,7 @@ def transition(state: State, event: Event) -> State:
|
||||
return Finishing(transcript_path)
|
||||
case Judging(), Ruled(Unfinished()):
|
||||
return Ended()
|
||||
# The interrupt is a whole claude session on the terminal, so the judge rules again on what it left.
|
||||
case Interrupting(transcript_path), Answered():
|
||||
return Judging(transcript_path)
|
||||
case Finishing(), Archived():
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from loop_claude.claude_code.entries import assistant_parts, ends_stream, parse
|
||||
from loop_claude.claude_code.entries import assistant_parts, ends_stream, parse_entry
|
||||
from loop_claude.claude_code.session import Session
|
||||
from loop_claude.claude_code.transcript import part_line
|
||||
from loop_claude.effects import Effects
|
||||
@@ -14,7 +14,7 @@ def run_worker(root: str, args: list[str], effects: Effects) -> Failure | None:
|
||||
return Failure(f"could not start claude: {failure.strerror}")
|
||||
done = False
|
||||
for raw in proc.lines():
|
||||
event = parse(raw) or {}
|
||||
event = parse_entry(raw) or {}
|
||||
done = done or ends_stream(event)
|
||||
for part in assistant_parts(event):
|
||||
if line := part_line(part, PRINTED_TOOL_INPUT):
|
||||
|
||||
Reference in New Issue
Block a user