Annotate the return type of every function in loop_claude

This commit is contained in:
2026-09-29 12:23:37 +02:00
parent 0842135b87
commit d13658967a
20 changed files with 62 additions and 58 deletions
+6 -6
View File
@@ -5,7 +5,7 @@ import typing
from loop_claude.claude_code.formats import structured_output
from loop_claude.cycle.retry import retried
from loop_claude.outcome import Failure
from loop_claude.outcome import Failure, Stop
JUDGE_RULES = (
"Decide whether the human must now be interrupted. interrupt=true when any of these appear:\n"
@@ -44,7 +44,7 @@ JUDGE_SCHEMA = {
}
def judge(root, task, premises, transcript, model):
def judge(root, task, premises, transcript, model) -> Verdict | Stop:
# No tools, so the verdict rests on the transcript grounded() checks it against; no persistence, so its runs stay out of the session picker.
args = [
"-p",
@@ -59,7 +59,7 @@ def judge(root, task, premises, transcript, model):
return retried("judge", lambda: run_judge(root, args, prompt, transcript))
def run_judge(root, args, prompt, transcript):
def run_judge(root, args, prompt, transcript) -> Verdict | Failure:
try:
proc = subprocess.run(["claude", *args], capture_output=True, cwd=root, input=prompt, text=True)
except OSError as failure:
@@ -72,7 +72,7 @@ def run_judge(root, args, prompt, transcript):
return verdict
def judge_prompt(task, premises, transcript):
def judge_prompt(task, premises, transcript) -> str:
return (
f"From README.md:\n{premises}\n\n"
f"The task an agent was given:\n{task}\n\n"
@@ -82,7 +82,7 @@ def judge_prompt(task, premises, transcript):
)
def verdict_from(output):
def verdict_from(output) -> Verdict | Failure:
if not isinstance(output, dict):
return Failure("the judge returned no verdict")
for name, kind in VERDICT_TYPES.items():
@@ -93,5 +93,5 @@ def verdict_from(output):
return Verdict(**{name: output[name] for name in VERDICT_TYPES})
def grounded(verdict, transcript):
def grounded(verdict, transcript) -> bool:
return verdict.evidence.strip() != "" and verdict.evidence in transcript