Answer stability round 1: count an answer the transcript shows written, give worker and judge one finish rule, cite CLAUDE.md by its heading, test a quoted answer that cannot be archived
This commit is contained in:
@@ -29,9 +29,10 @@ JUDGE_RULES = (
|
||||
"outranks finished.\n"
|
||||
"The chunk is the piece of work the agent is on, shipped as one pull request. "
|
||||
"finished=true when the chunk is complete: merged, or nothing remains that the agent could do on "
|
||||
f"its own, and {ANSWERS_RECORDED}. Judge that from the files above; a comment counts only where the "
|
||||
"transcript shows the agent writing it. finished=false when work remains that a further run can "
|
||||
"continue: an open PR, a review not yet run, CI not yet reported, an answer not yet recorded."
|
||||
f"its own. Even then, it is finished only once {ANSWERS_RECORDED}. An answer counts as recorded "
|
||||
"where the files above hold it, or where the transcript shows the agent writing it in one of those "
|
||||
"places. finished=false when work remains that a further run can continue: an open PR, a review "
|
||||
"not yet run, CI not yet reported, an answer not yet recorded."
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ def worker_args(task: str, session: Session, model: str, resuming: bool, answere
|
||||
if answered is not None:
|
||||
start = ["-p", f"Your question: {answered.question}\n\n{QUOTE_SOURCES} answers it:\n\n{answered.answer}\n\nContinue the task.", "--resume", str(session.id)]
|
||||
elif resuming:
|
||||
start = ["-p", f"Continue the task; the previous run stopped before it was finished. The chunk is finished once it is merged and {ANSWERS_RECORDED}.", "--resume", str(session.id)]
|
||||
start = ["-p", f"Continue the task; the previous run stopped before it was finished. The chunk is finished once it is complete and {ANSWERS_RECORDED}.", "--resume", str(session.id)]
|
||||
else:
|
||||
# --session-id creates the session under the id loop-claude keeps; --resume continues that session.
|
||||
start = ["-p", f"{task}\n\nContinue any open draft PR or worktree for the chunk before creating a new one.", "--name", session.name, "--session-id", str(session.id)]
|
||||
|
||||
@@ -7,9 +7,9 @@ premises; the task runs at the checkout root. Each cycle a worker runs the task.
|
||||
the transcript's end, the premises, and the records: the project's AGENTS.md and docs/decisions.md
|
||||
and the human's ~/.claude/CLAUDE.md, where they exist. It rules whether the chunk, the work of one
|
||||
PR, is finished. It is not while an answer the human typed in it, that a later chunk could need, is
|
||||
recorded nowhere: not in the premises, AGENTS.md or docs/decisions.md, nor in a code comment the
|
||||
transcript shows the worker writing. A choice the worker made that the premises or the records
|
||||
settle is not asked about. When the worker asks a question they answer, the judge quotes the
|
||||
recorded nowhere: neither the premises, AGENTS.md or docs/decisions.md hold it, nor does the
|
||||
transcript show the worker writing it there or in a code comment. A choice the worker made that the
|
||||
premises or the records settle is not asked about. When the worker asks a question they answer, the judge quotes the
|
||||
answer, loop-claude prints it, and the worker resumes with it. A quote they do not hold word for
|
||||
word is dropped, and the question goes to the human. So does a question asked again after its
|
||||
answer. The fourth question they answer in one cycle goes to the human too, with the quote.
|
||||
|
||||
@@ -29,11 +29,11 @@ def project_key(root: str, code: pathlib.Path) -> str:
|
||||
return root.removeprefix(f"{code}/").lstrip("/")
|
||||
|
||||
|
||||
def read_checkout_file(root: str, name: str, consequence: str) -> str | Stop:
|
||||
def read_utf8(folder: str, name: str, consequence: str) -> str | Stop:
|
||||
try:
|
||||
return pathlib.Path(root, name).read_text(encoding="utf-8")
|
||||
return pathlib.Path(folder, name).read_text(encoding="utf-8")
|
||||
except OSError as failure:
|
||||
return Stop(1, f"{name} in {root}: {failure.strerror} - {consequence}.")
|
||||
return Stop(1, f"{name} in {folder}: {failure.strerror} - {consequence}.")
|
||||
except UnicodeDecodeError as failure:
|
||||
line = failure.object.count(b"\n", 0, failure.start) + 1
|
||||
return Stop(1, f"{name} in {root} is not UTF-8 on line {line} - {consequence}.")
|
||||
return Stop(1, f"{name} in {folder} is not UTF-8 on line {line} - {consequence}.")
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
from loop_claude.project.checkout import read_checkout_file
|
||||
from loop_claude.project.checkout import read_utf8
|
||||
from markdown_sections import sections
|
||||
from loop_claude.stop import Stop
|
||||
|
||||
|
||||
def read_premises(root: str) -> str | Stop:
|
||||
text = read_checkout_file(root, "README.md", "no premises")
|
||||
text = read_utf8(root, "README.md", "no premises")
|
||||
if isinstance(text, Stop):
|
||||
return text
|
||||
found = sections(text)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import pathlib
|
||||
|
||||
from loop_claude.project.checkout import read_checkout_file
|
||||
from loop_claude.project.checkout import read_utf8
|
||||
from loop_claude.stop import Stop
|
||||
|
||||
RECORD_FILES = ("AGENTS.md", "docs/decisions.md")
|
||||
@@ -11,11 +11,12 @@ QUOTE_SOURCES = "README.md's Goals and Audience, " + ", ".join(RECORD_FILES) + "
|
||||
|
||||
def read_records(root: str, claude_md: pathlib.Path) -> str | Stop:
|
||||
"""The project's record files, then the human's rules for every project, each headed by its name; a file that does not exist is left out."""
|
||||
sources = [(root, name, name) for name in RECORD_FILES] + [(str(claude_md.parent), claude_md.name, HUMAN_RULES)]
|
||||
records = []
|
||||
for folder, name, heading in (*((root, name, name) for name in RECORD_FILES), (str(claude_md.parent), claude_md.name, HUMAN_RULES)):
|
||||
for folder, name, heading in sources:
|
||||
if not pathlib.Path(folder, name).exists():
|
||||
continue
|
||||
text = read_checkout_file(folder, name, "the judge cannot read the records")
|
||||
text = read_utf8(folder, name, "the judge cannot read the records")
|
||||
if isinstance(text, Stop):
|
||||
return text
|
||||
records.append(f"From {heading}:\n{text.strip()}")
|
||||
|
||||
+10
-2
@@ -268,6 +268,14 @@ class Cycles(unittest.TestCase):
|
||||
quoted = "2026-09-21T14:13:20Z Verdict: quoted answer\n\nWhich one?\n\nREADME.md's Goals and Audience, AGENTS.md, docs/decisions.md or ~/.claude/CLAUDE.md says:\n> Use *A*.\n\nEvidence:\n> working\n"
|
||||
self.assertEqual(self.archived_outcomes(), [f"Task: Do it.\n\n2026-09-21T14:13:20Z Verdict: interrupt\n\nWhich one?\n\nREADME.md's Goals and Audience, AGENTS.md, docs/decisions.md or ~/.claude/CLAUDE.md says:\nUse *A*.\n\nThose files have answered 3 questions this cycle, the most allowed, so this one comes to you.\n\nEvidence:\n> working\n\n2026-09-21T14:13:20Z Stopped: the human is needed to answer the question above, but the interrupt ended with nothing typed\n", *[f"Task: Do it.\n\n{quoted}"] * 3])
|
||||
|
||||
def test_stops_when_a_quoted_answer_cannot_be_archived(self):
|
||||
self.paths.transcript_archive.parent.mkdir(parents=True)
|
||||
self.paths.transcript_archive.write_text("")
|
||||
fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[judged("quoted", answer="Use A.")])
|
||||
with contextlib.redirect_stdout(io.StringIO()):
|
||||
self.assertEqual(run.run_cycle(self.cycle(fake, records="From AGENTS.md:\nUse A.")), Stop(1, f"could not archive the transcript: {self.paths.transcript_archive / 'proj'}: Not a directory"))
|
||||
self.assertEqual(len(fake.made("stream_claude")), 1)
|
||||
|
||||
def test_an_answer_the_records_do_not_hold_is_dropped_and_the_question_goes_to_the_human(self):
|
||||
fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[judged("quoted", answer="Use ... A.")], on_terminal_claude=[0], git=[ran()])
|
||||
with contextlib.redirect_stderr(io.StringIO()) as said:
|
||||
@@ -610,8 +618,8 @@ class ExitContract(unittest.TestCase):
|
||||
("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", "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} in {root} is not UTF-8", unreadable),
|
||||
("project/checkout.py", "read_utf8", "1", "f'{name} in {folder}:", unreadable),
|
||||
("project/checkout.py", "read_utf8", "1", "f'{name} in {folder} 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", "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_),
|
||||
|
||||
@@ -344,7 +344,7 @@ class Cycles(unittest.TestCase):
|
||||
self.assertEqual(argument(workers[2], "--session-id"), session)
|
||||
self.assertTrue(argument(workers[0], "-p").startswith(f"{TASK}\n\nContinue any open draft PR"))
|
||||
self.assertNotIn(TASK, argument(workers[1], "-p"))
|
||||
self.assertIn("The chunk is finished once it is merged and every answer the human typed in it", argument(workers[1], "-p"))
|
||||
self.assertIn("The chunk is finished once it is complete and every answer the human typed in it", argument(workers[1], "-p"))
|
||||
self.assertEqual({call["cwd"] for call in run.calls}, {str(checkout.root)})
|
||||
self.assertIn("1. Work.", run.calls[1]["stdin"])
|
||||
self.assertIn("From docs/decisions.md:\n# Decisions\n\nFrom ~/.claude/CLAUDE.md:\n# Global instructions", run.calls[1]["stdin"])
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
|
||||
2026-10-03, lilleman: the judge is to read `~/.claude/CLAUDE.md` whole too. The worker follows that file, so a question it answers should not reach the human (goal 4.2). Reading the whole file is safe, because the judge may quote only words that appear in it. A list of sections would need keeping current. Implemented the same day.
|
||||
|
||||
2026-10-03, lilleman: the judge rules a chunk finished only once every answer the human typed in it is recorded. A finished chunk's session is deleted, and its answers with it, so an answer recorded nowhere would be asked again in a later chunk (goal 4.2). Implemented the same day by claude, which settled two choices the ruling left open. First, an answer counts as recorded in a code comment the transcript shows the worker writing, beside `README.md`'s premises, `AGENTS.md` and `docs/decisions.md`: `CLAUDE.md` → "Ask, don't guess" puts a standing choice made in one place in a comment there, and a judge refusing it would hold the chunk open every cycle. Second, only an answer a later chunk could need must be recorded, so an approval such as "merge it" holds nothing open. The worker's resume prompt states the rule, so a chunk held open says why.
|
||||
2026-10-03, lilleman: the judge rules a chunk finished only once every answer the human typed in it is recorded. A finished chunk's session is deleted, and its answers with it, so an answer recorded nowhere would be asked again in a later chunk (goal 4.2). Implemented the same day by claude, which settled two choices the ruling left open. First, an answer counts as recorded where the files the judge reads hold it, or where the transcript shows the worker writing it into `README.md`'s premises, `AGENTS.md`, `docs/decisions.md` or a code comment. The judge cannot read a code comment, yet `CLAUDE.md` → "Working loop", "Ask, don't guess" puts a standing choice made in one place there. And the judge reads the records from the main checkout once a cycle, which may not yet hold an answer the worker merged. A judge refusing either would hold the chunk open every cycle. Second, only an answer a later chunk could need must be recorded, so an approval such as "merge it" holds nothing open. The worker's resume prompt states the rule, so a chunk held open says why.
|
||||
|
||||
## loop-claude: one session per project, its id derived from the checkout's path relative to `~/code`, or to `/` outside it
|
||||
|
||||
|
||||
Reference in New Issue
Block a user