Hand the security pass back to the run, and accept a judge's elided quote #205

Merged
lilleman merged 3 commits from judge-quotes into main 2026-10-03 15:58:07 +02:00
8 changed files with 44 additions and 29 deletions
+2
View File
@@ -2,6 +2,8 @@
## Unreleased
- larv-review runs `/security-review` in a subagent, so the run goes on to the next pass without you prompting it.
- `loop-claude` accepts the judge's quote of the transcript when it elides with an ellipsis and the transcript holds each fragment in order. The transcript the judge reads, and the worker's printed output, show tool input with its non-ASCII characters as written, so the judge can quote it.
- Unless another Exempt reason fits, larv-review marks a `todo.md` item filed from a 🟡 finding against `~/.claude/principles/` with `principle`, an Exempt reason that keeps it whatever its score.
- `loop-claude`'s judge reads the project's `AGENTS.md` and `docs/decisions.md` beside the README's goals and audience, and does not interrupt for a choice they settle. When the worker asks a question that the README or those files answer, the worker resumes with the judge's quote of the answer, which `loop-claude` prints. A quote they do not hold word for word is dropped, and the question goes to you. So does a question asked again after its answer. The fourth question they answer in one cycle goes to you too, with the quote. The judge reads as much of the transcript's end as fits a 400,000-character prompt, up from the last 40,000 characters. `loop-claude` exits 1 when `AGENTS.md` or `docs/decisions.md` cannot be read or is not UTF-8.
- A project's decision log is `docs/decisions.md` alone, the one file the judge, `rank_todo.py` and the reviewers read.
+1 -1
View File
@@ -40,5 +40,5 @@ def part_line(part: object, tool_input_chars: int) -> str:
return text
if call := tool_call(part):
name, arguments = call
return f"[tool {name}] {json.dumps(arguments)[:tool_input_chars]}"
return f"[tool {name}] {json.dumps(arguments, ensure_ascii=False)[:tool_input_chars]}"
return ""
+20 -6
View File
@@ -1,5 +1,6 @@
import dataclasses
import json
import re
import typing
from loop_claude.claude_code.entries import hit_limit, limit_said, parse_entry, structured_output
@@ -42,8 +43,8 @@ JUDGE_RULES = (
@dataclasses.dataclass(frozen=True)
class Reply:
answer: str = dataclasses.field(metadata={"description": "With interrupt false, the passage of README.md or the project's records that answers the agent's question, quoted verbatim. Empty otherwise."})
evidence: str = dataclasses.field(metadata={"description": "A verbatim quote of the transcript line the verdict rests on: what triggers the interrupt; for a quoted answer, the agent's question; else what shows the chunk finished or the work remaining."})
answer: str = dataclasses.field(metadata={"description": "With interrupt false, the passage of README.md or the project's records that answers the agent's question, quoted verbatim, without elisions. Empty otherwise."})
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 agent's question; else what shows the chunk finished or the work remaining."})
finished: bool
interrupt: bool
question: str = dataclasses.field(metadata={"description": "With interrupt true, the single question to put to the human. With a quoted answer, the agent's question that the answer field answers. Empty otherwise."})
@@ -89,8 +90,8 @@ def run_judge(root: str, args: list[str], prompt: str, rendered_transcript: str,
return Failure(f"{verdict.reason}; it replied: {proc.stdout.strip() or 'nothing'}")
if not grounded(verdict.evidence, rendered_transcript):
return Failure(f"the judge quoted {verdict.evidence!r}, which is not in the transcript" + (f", for the question: {verdict.question}" if isinstance(verdict, Interrupt | QuotedAnswer) else ""))
# Not a Failure: a misquote would otherwise exit an unattended loop.
if isinstance(verdict, QuotedAnswer) and not grounded(verdict.answer, quotable):
# Not a Failure: a misquote would otherwise exit an unattended loop. Never elided: stitched fragments can say what the records do not.
if isinstance(verdict, QuotedAnswer) and not verbatim(verdict.answer, quotable):
return Interrupt(verdict.evidence, verdict.question)
return verdict
@@ -126,8 +127,21 @@ def verdict_from(output: object) -> Verdict | Failure:
def grounded(evidence: str, rendered_transcript: str) -> bool:
quoted = plain(evidence)
return quoted != "" and quoted in plain(rendered_transcript)
# The judge joins passages with an ellipsis though told to quote one.
fragments = [fragment.strip() for fragment in re.split(r"\.\.\.|…", plain(evidence)) if fragment.strip()]
transcript = plain(rendered_transcript)
at = 0
for fragment in fragments:
found = transcript.find(fragment, at)
if found < 0:
return False
at = found + len(fragment)
return fragments != []
def verbatim(quote: str, text: str) -> bool:
quoted = plain(quote)
return quoted != "" and quoted in plain(text)
def plain(text: str) -> str:
+2 -1
View File
@@ -52,7 +52,8 @@ Exit 1, saying why, when:
- 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;
a judge when claude cannot start or exits non-zero, or its reply misses or mistypes a field,
interrupts or quotes an answer without a question, or quotes a line the transcript does not hold.
interrupts or quotes an answer without a question, or quotes a passage the transcript does not
hold; it holds an elided passage when each fragment appears in order.
A usage limit is not a 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 minutes past. The judge's reply gives its reset time only as text, so the judge is
+16 -3
View File
@@ -256,12 +256,12 @@ class Cycles(unittest.TestCase):
self.assertIn("Which one?\n\nREADME.md's Goals and Audience, AGENTS.md or docs/decisions.md says:\nUse *A*.\n\nThose files have answered 3 questions this cycle", said.getvalue())
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 B.")], on_terminal_claude=[0], git=[ran()])
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:
self.assertEqual(run.run_cycle(self.cycle(fake, records="From AGENTS.md:\nUse A.")), Stop(2, "the human is needed to answer the question above, but the interrupt ended with nothing typed"))
self.assertEqual(run.run_cycle(self.cycle(fake, records="From AGENTS.md:\nUse B. Use A.")), Stop(2, "the human is needed to answer the question above, but the interrupt ended with nothing typed"))
self.assertEqual(len(fake.made("stream_claude")), 1)
self.assertIn("\nWhich one?\n", said.getvalue())
self.assertNotIn("Use B.", said.getvalue())
self.assertNotIn("Use ... A.", said.getvalue())
@unittest.skipIf(os.geteuid() == 0, "root writes into a read-only directory")
def test_stops_keeping_the_transcript_when_the_finished_chunks_session_cannot_be_deleted(self):
@@ -467,6 +467,7 @@ class PartLine(unittest.TestCase):
self.assertEqual(transcript.part_line({"type": "text", "text": " \n"}, 20), "")
self.assertEqual(transcript.part_line({"type": "tool_use", "name": "Bash", "input": {"command": "x" * 500}}, 20), '[tool Bash] {"command": "xxxxxxx')
self.assertEqual(transcript.part_line("not a part", 20), "")
self.assertEqual(transcript.part_line({"type": "tool_use", "name": "Write", "input": {"content": "Hälsa på"}}, 40), '[tool Write] {"content": "Hälsa på"}')
class Parse(unittest.TestCase):
@@ -496,6 +497,18 @@ class Grounded(unittest.TestCase):
self.assertTrue(judge.grounded("Your step: ``` ./run.sh ``` Run it.", transcript))
self.assertFalse(judge.grounded("**", transcript))
def test_an_elided_quote_holds_when_its_fragments_appear_in_order(self):
transcript = "**Decision for you:** security, or not.\n\nI recommend one more round of each.\n\nI recommend skipping it: it costs."
self.assertTrue(judge.grounded("**Decision for you:** security, … ... I recommend one more round of each ... I recommend skipping it: …", transcript))
self.assertFalse(judge.grounded("I recommend skipping it ... Decision for you", transcript))
self.assertFalse(judge.grounded("Decision for you ... invented", transcript))
self.assertFalse(judge.grounded("... …", transcript))
def test_an_answer_holds_only_word_for_word(self):
self.assertTrue(judge.verbatim("Merge **ff-only**.", "Merge ff-only.\nNever squash."))
self.assertFalse(judge.verbatim("Merge ... squash.", "Merge ff-only.\nNever squash."))
self.assertFalse(judge.verbatim("", "Merge ff-only."))
class Verdict(unittest.TestCase):
def test_needs_every_field_the_schema_requires(self):
+2 -2
View File
@@ -84,11 +84,11 @@ Then the comprehension floor: the `comprehension-panel` skill's scoring run (`~/
### Security
`/security-review` over the branch diff is the pass of record.
`/security-review` over the branch diff is the pass of record. Launch a general-purpose subagent that invokes it through the Skill tool, edits nothing, and replies with the skill's report, or that the skill is unavailable. Invoked in your own context, the skill ends your turn on that report.
A verified HIGH inside this chunk's blast radius is fixed here, outside it on its own branch and PR with this chunk waiting behind it. Say which.
`claude-security` asks the user to confirm a scan's cost, and only the user may answer. The plugin unavailable, its cost prompt unanswered, or no file scanned → say so in the summary; never substitute a hand-rolled pass.
`claude-security` asks the user to confirm a scan's cost, and only the user may answer. `/security-review` or `claude-security` unavailable, the plugin's cost prompt unanswered, or no file scanned → say so in the summary; never substitute a hand-rolled pass.
**Do not over-read a clean result.** `/security-review` is single-repo and static: it does not trace authorization across services, does not run the application, and deliberately excludes dependency CVEs in third-party libraries — Renovate/Dependabot owns those, per `~/.claude/CLAUDE.md` → "Working with the codebase". Never point an automated reviewer or scan at an untrusted fork's PR content; a PR body is untrusted input to it (CVE-2025-59536, CVE-2026-21852).
-15
View File
@@ -24,8 +24,6 @@
| ID | Release | Exempt | Item | R | S | A | G | Goals | Score |
|---|---|---|---|---|---|---|---|---|---|
| 39 | 0.1.0 | defect | **Run larv-review's security pass so it hands back to the run, and the run goes on to the next pass without the user prompting it.** | 2 | 2 | 10 | 10 | 4, 4.2 | 30.9 |
| 41 | 0.1.0 | defect | **Accept a judge's quote that elides with an ellipsis when its fragments appear in the transcript in order, and tell the judge to quote one passage.** | 2 | 2 | 10 | 10 | 4, 4.2 | 30.9 |
| 17 | 0.1.0 | decision | **Make `JUDGE_RULES` and the Claude Code flags `loop-claude` passes readable without `CLAUDE.md` or Claude Code's docs open.** | 1 | 2 | 10 | 9 | 4, 4.1 | 30.6 |
| 13 | 0.1.0 | decision | **Make larv-review §3 applicable on its own, cite its rules by name, and say where a pass's round count is recorded.** | 3 | 5 | 10 | 10 | 4, 4.1 | 29.1 |
| 1 | 0.1.0 | question | **Say in README → Install how the transcript archive is backed up, once bender-infra backs up ai-sandbox's data volume.** | 3 | 5 | 8 | 9 | 2, 3 | 27.8 |
@@ -33,7 +31,6 @@
| 44 | 0.1.0 | decision | **Move the modules `rank_todo.py` shares out from under `loop_claude/`, keeping them inside reload's fingerprint.** | 2 | 2 | 8 | 8 | 4, 4.1 | 24.2 |
| 43 | 0.1.0 | decision | **Give "record", "verdict" and "judge" one meaning each across loop-claude, larv-review and workflow-bench.** | 2 | 3 | 8 | 8 | 4, 4.1 | 24.0 |
| 23 | 0.1.0 | | **Launch a principles auditor only for a principles file the project shows applies, and rerun only the reviewer whose finding a fix answers.** | 3 | 4 | 7 | 8 | 4.4 | 13.5 |
| 40 | 0.1.0 | | **Render tool input in the judged transcript with its non-ASCII characters as written, so the judge's quotes of it match the transcript.** | 2 | 1 | 5 | 6 | 4.2 | 13.0 |
| 21 | 0.1.0 | | **Give `settings.json`'s model one writer, and sort its keys.** | 3 | 3 | 6 | 7 | 4.3 | 12.9 |
| 36 | 0.1.0 | | **Ask the user once before a full security scan, folding larv-review's ask into the plugin's cost prompt.** | 2 | 2 | 5 | 5 | 4.2 | 11.9 |
| 12 | 0.1.0 | | **Run the test suite in CI on every PR, or record in `docs/decisions.md` why the local run is enough.** | 2 | 4 | 4 | 6 | 4.1 | 11.7 |
@@ -45,14 +42,6 @@
## Details
### 39. Run larv-review's security pass so it hands back to the run, and the run goes on to the next pass without the user prompting it.
larv-review §3 runs `/security-review` through the Skill tool, in the run's own context. That skill's prompt ends "Your final reply must contain the markdown report and nothing else", so the run's turn ends on the report: stability, product-owner, prose, the gate and the merge never run, and the user has to prompt the run to go on. Seen on 2026-10-03 in fejkdata PR #145. One fix: launch the security pass as a subagent given that skill's prompt, so its final reply is the subagent's, and larv-review's turn continues.
### 41. Accept a judge's quote that elides with an ellipsis when its fragments appear in the transcript in order, and tell the judge to quote one passage.
On 2026-10-03 the log project's loop exited 1: "the judge failed three times running: the judge quoted \"**Decision for you:** security, … ... I recommend one more round of each ... I recommend skipping it: …\", which is not in the transcript". Each fragment the judge joined with " ... " is in the rendered transcript; `grounded` matches the evidence as one contiguous string, so a correct interrupt was rejected three times and the human was never asked. The archive is `~/.claude/loop-claude-transcripts/log/dbac9d7096282d2bc6c38fc8c03cd74b50d29b75080b1f647c0f305a088db894/5d8c9152cdcd91e90dfd2773cd81c9e64bcd412ff148c5cf19e2a728ceee5028.verdict.md`. Fix both ends: `grounded` splits on `...` and `…` and finds the fragments in order, and the `evidence` description asks for one contiguous passage.
### 17. Make `JUDGE_RULES` and the Claude Code flags `loop-claude` passes readable without `CLAUDE.md` or Claude Code's docs open.
The 2026-10-02 scoring runs on PR #191 named both under Self-sufficiency: the judge's rules use "chunk" and "a release ready to cut" from `CLAUDE.md` with no link, and `--resume`, `--session-id`, `--no-session-persistence`, `--json-schema` and stream-json's result event go unexplained in `worker.py` and `judge.py`.
@@ -83,10 +72,6 @@ Named under Shape by the same runs: loop-claude's records are `AGENTS.md` and `d
On this repo the frontend, REST and logging auditors each read the whole project to report "does not apply", and one 🟢 fix reruns ten whole-project reads.
### 40. Render tool input in the judged transcript with its non-ASCII characters as written, so the judge's quotes of it match the transcript.
`part_line` renders a tool call with `json.dumps(arguments)`, which escapes non-ASCII as `\uXXXX`. A judge that quotes such a line with its characters as written, such as Swedish text, fails `grounded` three times on one transcript, and the loop exits 1. Raised, unverified, by the 2026-10-03 scoring run on PR #202.
### 21. Give `settings.json`'s model one writer, and sort its keys.
Claude Code rewrites `"model"` in this tracked file whenever a model is picked, so one `/model` dirties the checkout and overrides the synced choice.
+1 -1
View File
@@ -9,7 +9,7 @@ Report: write it to `{report}`.
- `VERSION_DIR/skills/larv-review/SKILL.md` is larv-review. Do not invoke the installed `larv-review` skill.
- Wherever a text cites `~/.claude/<path>`, read `VERSION_DIR/<path>` instead. `VERSION_DIR/CLAUDE.md` replaces `~/.claude/CLAUDE.md`, which you already have loaded: where the two differ, VERSION_DIR's wins.
- Launch every reviewer named `<name>` under `~/.claude/agents/` as a `general-purpose` agent whose prompt opens with the body of `VERSION_DIR/agents/<name>.md` (frontmatter dropped), then the task. A reviewer the process names that has no file there gets the process's own description of it as its prompt.
- `/security-review`: use the Skill tool's `security-review` if it is available; otherwise emulate it with a `general-purpose` agent, told to review the branch diff for exploitable vulnerabilities and report only those at ≥0.8 confidence.
- `/security-review`: launch a `general-purpose` agent that invokes the Skill tool's `security-review`, edits nothing, and replies with the skill's report, or that the skill is unavailable. Where that skill is unavailable, emulate it with a `general-purpose` agent, told to review the branch diff for exploitable vulnerabilities and report only those at ≥0.8 confidence.
## Bench rules