From 50e8056f4d1dfc2896d53d5612cb495fa639eba2 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 3 Oct 2026 14:13:30 +0200 Subject: [PATCH] Move the Markdown section parser out of premises into its own module; file the log loop's ellipsis crash as item 41 --- bin/loop_claude/markdown_sections.py | 27 ++++++++++++++++++++++++++ bin/loop_claude/project/premises.py | 29 +--------------------------- bin/rank_todo.py | 2 +- bin/test_loop_claude.py | 10 +++++----- todo.md | 7 ++++++- 5 files changed, 40 insertions(+), 35 deletions(-) create mode 100644 bin/loop_claude/markdown_sections.py diff --git a/bin/loop_claude/markdown_sections.py b/bin/loop_claude/markdown_sections.py new file mode 100644 index 00000000..593d6655 --- /dev/null +++ b/bin/loop_claude/markdown_sections.py @@ -0,0 +1,27 @@ +import re + +FENCE = re.compile(r"^ {0,3}(`{3,}|~{3,})", re.M) + + +def sections(text: str) -> dict[str, list[str]]: + blocks: list[tuple[str | None, list[str]]] = [] + opener = "" + for line in text.splitlines(): + if fence := FENCE.match(line): + marker = fence.group(1) + if not opener: + opener = marker + elif marker[0] == opener[0] and len(marker) >= len(opener) and not line[fence.end():].strip(): + opener = "" + fenced = bool(opener or fence) + if not fenced and line.startswith("## "): + blocks.append((line.strip()[3:], [])) + elif not fenced and line.startswith("# "): + blocks.append((None, [])) + elif blocks and line.strip(): + blocks[-1][1].append(line) + found: dict[str, list[str]] = {} + for name, body in blocks: + if name is not None: + found.setdefault(name, []).append("\n".join(body)) + return found diff --git a/bin/loop_claude/project/premises.py b/bin/loop_claude/project/premises.py index f30f0a28..45b080f4 100644 --- a/bin/loop_claude/project/premises.py +++ b/bin/loop_claude/project/premises.py @@ -1,10 +1,7 @@ -import re - +from loop_claude.markdown_sections import sections from loop_claude.project.checkout import read_checkout_file from loop_claude.stop import Stop -FENCE = re.compile(r"^ {0,3}(`{3,}|~{3,})", re.M) - def read_premises(root: str) -> str | Stop: text = read_checkout_file(root, "README.md", "no premises") @@ -20,27 +17,3 @@ def read_premises(root: str) -> str | Stop: if not bodies[0]: return Stop(1, f"README.md has nothing under ## {name} - no premises.") return f"## Goals\n{found['Goals'][0]}\n\n## Audience\n{found['Audience'][0]}" - - -def sections(text: str) -> dict[str, list[str]]: - blocks: list[tuple[str | None, list[str]]] = [] - opener = "" - for line in text.splitlines(): - if fence := FENCE.match(line): - marker = fence.group(1) - if not opener: - opener = marker - elif marker[0] == opener[0] and len(marker) >= len(opener) and not line[fence.end():].strip(): - opener = "" - fenced = bool(opener or fence) - if not fenced and line.startswith("## "): - blocks.append((line.strip()[3:], [])) - elif not fenced and line.startswith("# "): - blocks.append((None, [])) - elif blocks and line.strip(): - blocks[-1][1].append(line) - found: dict[str, list[str]] = {} - for name, body in blocks: - if name is not None: - found.setdefault(name, []).append("\n".join(body)) - return found diff --git a/bin/rank_todo.py b/bin/rank_todo.py index edff2d7e..f6dfdb92 100755 --- a/bin/rank_todo.py +++ b/bin/rank_todo.py @@ -60,7 +60,7 @@ import sys # Kept inside loop_claude/ so reload's fingerprint covers them. from loop_claude.failure import Failure from loop_claude.file_writes import replace_file -from loop_claude.project.premises import FENCE, sections +from loop_claude.markdown_sections import FENCE, sections EXEMPTIONS = ("", "decision", "defect", "principle", "question", "security") ITEMS_HEADER = "| ID | Release | Exempt | Item | R | S | A | G | Goals | Score |" diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index 5cb3afc5..cdf11d26 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -16,7 +16,7 @@ import uuid sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) -from loop_claude import file_writes, paths +from loop_claude import file_writes, markdown_sections, paths from loop_claude.claude_code import entries, session, transcript, trust from loop_claude.cycle import archive, interrupt, judge, retry, run, states, worker from loop_claude.cycle.limited import Limited @@ -24,7 +24,7 @@ from loop_claude.cycle.verdicts import Finished, Interrupt, QuotedAnswer, Unfini from loop_claude.effects import Effects from loop_claude.failure import Failure from loop_claude.loop import main, reload -from loop_claude.project import checkout, model_choice, premises, records +from loop_claude.project import checkout, model_choice, records from loop_claude.stop import Stop CWD = pathlib.Path("/c") @@ -397,12 +397,12 @@ class Records(unittest.TestCase): class Sections(unittest.TestCase): def test_keeps_every_headed_section_with_its_bodies(self): text = "# Title\n\nintro\n\n## Goals\n\n1. one\n```sh\n# not a heading\n```\n### Later\n2. two\n#1 priority\n\n## Empty\n\n## Audience\nme\n## Audience\nagain\n# Appendix\nnot audience\n" - self.assertEqual(premises.sections(text), {"Goals": ["1. one\n```sh\n# not a heading\n```\n### Later\n2. two\n#1 priority"], "Empty": [""], "Audience": ["me", "again"]}) + self.assertEqual(markdown_sections.sections(text), {"Goals": ["1. one\n```sh\n# not a heading\n```\n### Later\n2. two\n#1 priority"], "Empty": [""], "Audience": ["me", "again"]}) def test_closes_a_fence_only_on_its_own_marker(self): text = "## Goals\n````md\n~~~\n## Quoted\n```\n````\n ~~~\n## Also quoted\n ~~~\n1. one\n## Audience\nme\n" - self.assertEqual(list(premises.sections(text)), ["Goals", "Audience"]) - self.assertEqual(list(premises.sections("```\nquoted:\n```python\n## Inside\n```\n## Goals\n1. one\n")), ["Goals"]) + self.assertEqual(list(markdown_sections.sections(text)), ["Goals", "Audience"]) + self.assertEqual(list(markdown_sections.sections("```\nquoted:\n```python\n## Inside\n```\n## Goals\n1. one\n")), ["Goals"]) class Render(unittest.TestCase): diff --git a/todo.md b/todo.md index 6aa2a2d3..2330d235 100644 --- a/todo.md +++ b/todo.md @@ -6,7 +6,7 @@ `Bar = 9` -`Next ID = 41` +`Next ID = 42` | Goal | W | |---|---| @@ -24,6 +24,7 @@ | ID | Release | Exempt | Item | R | S | A | G | Goals | Score | |---|---|---|---|---|---|---|---|---|---| +| 41 | 0.1.0 | defect | **Ground a judge's quote that elides with an ellipsis, each fragment found in order, and tell the judge to quote one passage.** | 2 | 2 | 10 | 10 | 4, 4.2 | 30.9 | | 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 | | 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 | 6 | 7 | 4.1 | 15.6 | | 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,6 +41,10 @@ ## Details +### 41. Ground a judge's quote that elides with an ellipsis, each fragment found 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 `loop-claude-transcripts/log/dbac9d70…/5d8c9152….verdict.md`. Fix both ends: `grounded` splits on `...` and `…` and finds the fragments in order, and the `evidence` description asks for one contiguous passage. + ### 1. Say in README → Install how the transcript archive is backed up, once bender-infra backs up ai-sandbox's data volume. It lives under `~/.claude`, which `.gitignore` keeps from the remote, so a lost disk loses every unattended run's record. Back it up only to a destination private to me and encrypted at rest: the worker runs with permissions bypassed, so the archived tool results can hold credentials it read.