Answer the architect: fail a judge that answers without interrupting, read every checkout file through one function
This commit is contained in:
@@ -14,7 +14,8 @@ from loop_claude.stop import Stop
|
|||||||
JUDGED_TRANSCRIPT_TAIL = 400000
|
JUDGED_TRANSCRIPT_TAIL = 400000
|
||||||
|
|
||||||
JUDGE_RULES = (
|
JUDGE_RULES = (
|
||||||
"Decide whether the human must now be interrupted. interrupt=true when any of these appear:\n"
|
"Decide whether the agent has something open that the human, or README.md and the project's records, "
|
||||||
|
"must answer. 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"
|
"- the agent asks the human anything, seeks approval, or says a decision is the human's\n"
|
||||||
"- it carried on under an assumption that decides the deliverable, that the human could "
|
"- it carried on under an assumption that decides the deliverable, that the human could "
|
||||||
"reasonably reject and that neither README.md nor the project's records settle; a caveat about "
|
"reasonably reject and that neither README.md nor the project's records settle; a caveat about "
|
||||||
@@ -108,6 +109,8 @@ def verdict_from(output: object) -> Verdict | Failure:
|
|||||||
if not isinstance(output.get(name), kind):
|
if not isinstance(output.get(name), kind):
|
||||||
return Failure(f"the judge's reply has no {name} of type {JSON_TYPES[kind]}")
|
return Failure(f"the judge's reply has no {name} of type {JSON_TYPES[kind]}")
|
||||||
# An interrupt outranks finished: the human answers before the chunk can close.
|
# An interrupt outranks finished: the human answers before the chunk can close.
|
||||||
|
if output["answer"].strip() and not output["interrupt"]:
|
||||||
|
return Failure("the judge answered without interrupting")
|
||||||
if output["interrupt"]:
|
if output["interrupt"]:
|
||||||
if not output["question"].strip():
|
if not output["question"].strip():
|
||||||
return Failure("the judge interrupted without a question")
|
return Failure("the judge interrupted without a question")
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ loop-claude --help succeeds: the loop reloads into the edited script.
|
|||||||
Exit 1, saying why, when:
|
Exit 1, saying why, when:
|
||||||
- no task is given
|
- no task is given
|
||||||
- git cannot start or finds no checkout
|
- git cannot start or finds no checkout
|
||||||
|
- README.md, or AGENTS.md or docs/decisions.md where they exist, cannot be read or is not UTF-8
|
||||||
- README.md holds no premises
|
- README.md holds no premises
|
||||||
- AGENTS.md or docs/decisions.md cannot be read, or is not UTF-8
|
|
||||||
- the models file cannot be read or written
|
- the models file cannot be read or written
|
||||||
- claude leaves no transcript
|
- claude leaves no transcript
|
||||||
- a transcript cannot be read or archived
|
- a transcript cannot be read or archived
|
||||||
@@ -50,9 +50,9 @@ Exit 1, saying why, when:
|
|||||||
- the worker or the judge fails three times running, retried a minute apart within the cycle. A
|
- the worker or the judge fails three times running, retried a minute apart within the cycle. A
|
||||||
worker fails when claude cannot start, exits non-zero, is killed, or ends without a result event;
|
worker fails when claude cannot start, exits non-zero, is killed, or ends without a result event;
|
||||||
a judge when claude cannot start or exits non-zero, or its reply misses or mistypes a field,
|
a judge when claude cannot start or exits non-zero, or its reply misses or mistypes a field,
|
||||||
interrupts without a question, quotes a line the transcript does not hold, or quotes an answer
|
interrupts without a question, answers without interrupting, quotes a line the transcript does
|
||||||
the premises and the records do not hold. A usage limit is
|
not hold, or quotes an answer the premises and the records do not hold. A usage limit is not a
|
||||||
not a failure, and restarts the count of three: the worker or the judge is retried 2 minutes
|
failure, and restarts the count of three: the worker or the judge is retried 2 minutes
|
||||||
after the limit resets, or every 10 minutes when the reset time is unknown or more than 2
|
after the limit resets, or every 10 minutes when the reset time is unknown or more than 2
|
||||||
minutes past. The judge's reply gives its reset time only as text, so the judge is always
|
minutes past. The judge's reply gives its reset time only as text, so the judge is always
|
||||||
retried every 10 minutes. stderr says when the next try is due.
|
retried every 10 minutes. stderr says when the next try is due.
|
||||||
|
|||||||
@@ -27,3 +27,13 @@ def worktrees(root: str, effects: Effects) -> list[str]:
|
|||||||
|
|
||||||
def project_key(root: str, code: pathlib.Path) -> str:
|
def project_key(root: str, code: pathlib.Path) -> str:
|
||||||
return root.removeprefix(f"{code}/").lstrip("/")
|
return root.removeprefix(f"{code}/").lstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def read_checkout_file(root: str, name: str, consequence: str) -> str | Stop:
|
||||||
|
try:
|
||||||
|
return pathlib.Path(root, name).read_text(encoding="utf-8")
|
||||||
|
except OSError as failure:
|
||||||
|
return Stop(1, f"{name} in {root}: {failure.strerror} - {consequence}.")
|
||||||
|
except UnicodeDecodeError as failure:
|
||||||
|
line = failure.object.count(b"\n", 0, failure.start) + 1
|
||||||
|
return Stop(1, f"{name} is not UTF-8 on line {line} - {consequence}.")
|
||||||
|
|||||||
@@ -1,19 +1,16 @@
|
|||||||
import pathlib
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from loop_claude.project.checkout import read_checkout_file
|
||||||
from loop_claude.stop import Stop
|
from loop_claude.stop import Stop
|
||||||
|
|
||||||
FENCE = re.compile(r"^ {0,3}(`{3,}|~{3,})", re.M)
|
FENCE = re.compile(r"^ {0,3}(`{3,}|~{3,})", re.M)
|
||||||
|
|
||||||
|
|
||||||
def read_premises(root: str) -> str | Stop:
|
def read_premises(root: str) -> str | Stop:
|
||||||
try:
|
text = read_checkout_file(root, "README.md", "no premises")
|
||||||
found = sections(pathlib.Path(root, "README.md").read_text(encoding="utf-8"))
|
if isinstance(text, Stop):
|
||||||
except OSError as failure:
|
return text
|
||||||
return Stop(1, f"README.md in {root}: {failure.strerror} - no premises.")
|
found = sections(text)
|
||||||
except UnicodeDecodeError as failure:
|
|
||||||
line = failure.object.count(b"\n", 0, failure.start) + 1
|
|
||||||
return Stop(1, f"README.md is not UTF-8 on line {line} - no premises.")
|
|
||||||
for name in ("Goals", "Audience"):
|
for name in ("Goals", "Audience"):
|
||||||
bodies = found.get(name, [])
|
bodies = found.get(name, [])
|
||||||
if not bodies:
|
if not bodies:
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import pathlib
|
import pathlib
|
||||||
|
|
||||||
|
from loop_claude.project.checkout import read_checkout_file
|
||||||
from loop_claude.stop import Stop
|
from loop_claude.stop import Stop
|
||||||
|
|
||||||
|
|
||||||
@@ -7,14 +8,10 @@ def read_records(root: str) -> str | Stop:
|
|||||||
"""AGENTS.md and docs/decisions.md, each headed by its path; a file the project lacks is left out."""
|
"""AGENTS.md and docs/decisions.md, each headed by its path; a file the project lacks is left out."""
|
||||||
records = []
|
records = []
|
||||||
for name in ("AGENTS.md", "docs/decisions.md"):
|
for name in ("AGENTS.md", "docs/decisions.md"):
|
||||||
try:
|
if not pathlib.Path(root, name).exists():
|
||||||
text = pathlib.Path(root, name).read_text(encoding="utf-8")
|
|
||||||
except FileNotFoundError:
|
|
||||||
continue
|
continue
|
||||||
except OSError as failure:
|
text = read_checkout_file(root, name, "the judge cannot read the project's records")
|
||||||
return Stop(1, f"{name} in {root}: {failure.strerror} - the judge cannot read the project's records.")
|
if isinstance(text, Stop):
|
||||||
except UnicodeDecodeError as failure:
|
return text
|
||||||
line = failure.object.count(b"\n", 0, failure.start) + 1
|
|
||||||
return Stop(1, f"{name} is not UTF-8 on line {line} - the judge cannot read the project's records.")
|
|
||||||
records.append(f"From {name}:\n{text.strip()}")
|
records.append(f"From {name}:\n{text.strip()}")
|
||||||
return "\n\n".join(records)
|
return "\n\n".join(records)
|
||||||
|
|||||||
@@ -496,7 +496,7 @@ class Verdict(unittest.TestCase):
|
|||||||
self.assertEqual(judge.verdict_from({"answer": "", "interrupt": False, "evidence": "e", "finished": False, "question": "ignored"}), Unfinished("e"))
|
self.assertEqual(judge.verdict_from({"answer": "", "interrupt": False, "evidence": "e", "finished": False, "question": "ignored"}), Unfinished("e"))
|
||||||
self.assertEqual(judge.verdict_from({"answer": "", "interrupt": True, "evidence": "e", "finished": True, "question": "Which one?"}), Interrupt("e", "Which one?"))
|
self.assertEqual(judge.verdict_from({"answer": "", "interrupt": True, "evidence": "e", "finished": True, "question": "Which one?"}), Interrupt("e", "Which one?"))
|
||||||
self.assertEqual(judge.verdict_from({"answer": "A.", "interrupt": True, "evidence": "e", "finished": False, "question": "Which one?"}), Recorded("e", "Which one?", "A."))
|
self.assertEqual(judge.verdict_from({"answer": "A.", "interrupt": True, "evidence": "e", "finished": False, "question": "Which one?"}), Recorded("e", "Which one?", "A."))
|
||||||
self.assertEqual(judge.verdict_from({"answer": "ignored", "interrupt": False, "evidence": "e", "finished": False, "question": ""}), Unfinished("e"))
|
self.assertEqual(judge.verdict_from({"answer": "A.", "interrupt": False, "evidence": "e", "finished": False, "question": ""}), Failure("the judge answered without interrupting"))
|
||||||
self.assertEqual(judge.verdict_from({"answer": "", "interrupt": "no", "evidence": "", "finished": True, "question": ""}), Failure("the judge's reply has no interrupt of type boolean"))
|
self.assertEqual(judge.verdict_from({"answer": "", "interrupt": "no", "evidence": "", "finished": True, "question": ""}), Failure("the judge's reply has no interrupt of type boolean"))
|
||||||
self.assertEqual(judge.verdict_from({"answer": "", "interrupt": False, "evidence": None, "finished": True, "question": ""}), Failure("the judge's reply has no evidence of type string"))
|
self.assertEqual(judge.verdict_from({"answer": "", "interrupt": False, "evidence": None, "finished": True, "question": ""}), Failure("the judge's reply has no evidence of type string"))
|
||||||
self.assertEqual(judge.verdict_from({"answer": "", "interrupt": True, "evidence": "x", "finished": False, "question": " "}), Failure("the judge interrupted without a question"))
|
self.assertEqual(judge.verdict_from({"answer": "", "interrupt": True, "evidence": "x", "finished": False, "question": " "}), Failure("the judge interrupted without a question"))
|
||||||
@@ -529,6 +529,7 @@ class ExitContract(unittest.TestCase):
|
|||||||
def test_every_exit_1_stop_has_its_clause_in_help(self):
|
def test_every_exit_1_stop_has_its_clause_in_help(self):
|
||||||
read, git, premises_ = "a transcript cannot be read or archived", "git cannot start or finds no checkout", "README.md holds no premises"
|
read, git, premises_ = "a transcript cannot be read or archived", "git cannot start or finds no checkout", "README.md holds no premises"
|
||||||
models_ = "the models file cannot be read or written"
|
models_ = "the models file cannot be read or written"
|
||||||
|
unreadable = "README.md, or AGENTS.md or docs/decisions.md where they exist, cannot be read or is not UTF-8"
|
||||||
# Every Stop whose code is not a literal 0, 2 or 130, in source order: path, function, code, start of reason, its --help clause.
|
# Every Stop whose code is not a literal 0, 2 or 130, in source order: path, function, code, start of reason, its --help clause.
|
||||||
clauses = [
|
clauses = [
|
||||||
("cycle/interrupt.py", "interrupt", "1", "entries.reason", read),
|
("cycle/interrupt.py", "interrupt", "1", "entries.reason", read),
|
||||||
@@ -546,16 +547,14 @@ class ExitContract(unittest.TestCase):
|
|||||||
("loop/reload.py", "exec_if_edited", "1", "f'could not reload loop-claude:", "python cannot start for a reload"),
|
("loop/reload.py", "exec_if_edited", "1", "f'could not reload loop-claude:", "python cannot start for a reload"),
|
||||||
("project/checkout.py", "checkout_root", "1", "f'could not start git:", git),
|
("project/checkout.py", "checkout_root", "1", "f'could not start git:", git),
|
||||||
("project/checkout.py", "checkout_root", "1", "found.stderr.strip()", git),
|
("project/checkout.py", "checkout_root", "1", "found.stderr.strip()", git),
|
||||||
|
("project/checkout.py", "read_checkout_file", "1", "f'{name} in {root}:", unreadable),
|
||||||
|
("project/checkout.py", "read_checkout_file", "1", "f'{name} is not UTF-8", unreadable),
|
||||||
("project/model_choice.py", "get_or_ask_model", "1", "f'could not save the model in", models_),
|
("project/model_choice.py", "get_or_ask_model", "1", "f'could not save the model in", models_),
|
||||||
("project/model_choice.py", "read_models_file", "1", 'f"could not read {saved}: {getattr(', models_),
|
("project/model_choice.py", "read_models_file", "1", 'f"could not read {saved}: {getattr(', models_),
|
||||||
("project/model_choice.py", "read_models_file", "1", "f'could not read {saved}: not an object", models_),
|
("project/model_choice.py", "read_models_file", "1", "f'could not read {saved}: not an object", models_),
|
||||||
("project/premises.py", "read_premises", "1", "f'README.md in {root}:", premises_),
|
|
||||||
("project/premises.py", "read_premises", "1", "f'README.md is not UTF-8", premises_),
|
|
||||||
("project/premises.py", "read_premises", "1", "f'README.md has no ##", premises_),
|
("project/premises.py", "read_premises", "1", "f'README.md has no ##", premises_),
|
||||||
("project/premises.py", "read_premises", "1", "f'README.md has ## {name} more than once", premises_),
|
("project/premises.py", "read_premises", "1", "f'README.md has ## {name} more than once", premises_),
|
||||||
("project/premises.py", "read_premises", "1", "f'README.md has nothing under", premises_),
|
("project/premises.py", "read_premises", "1", "f'README.md has nothing under", premises_),
|
||||||
("project/records.py", "read_records", "1", 'f"{name} in {root}:', "AGENTS.md or docs/decisions.md cannot be read, or is not UTF-8"),
|
|
||||||
("project/records.py", "read_records", "1", 'f"{name} is not UTF-8', "AGENTS.md or docs/decisions.md cannot be read, or is not UTF-8"),
|
|
||||||
]
|
]
|
||||||
root = pathlib.Path(main.__file__).parents[1]
|
root = pathlib.Path(main.__file__).parents[1]
|
||||||
found = []
|
found = []
|
||||||
|
|||||||
Reference in New Issue
Block a user