idle-draft: strip :line-range suffixes before citation existence check

First pilot rejected valid citations like SPEC.md:1-80 — the form the
research template itself mandates. 5 new test cases (83 total).

Claude-Session: https://claude.ai/code/session_01YQDoWNM7XPPii28khFWoMc
This commit is contained in:
Paul O'Reilly
2026-08-02 21:27:53 +12:00
parent 6c4bf449aa
commit cd5be1cf92
3 changed files with 37 additions and 2 deletions

View File

@@ -92,6 +92,7 @@ RETRYABLE_STDERR_MARKERS = (
ITEM_FILENAME_RE = re.compile(r"^(\d+)-(.+)\.overview\.md$")
ABS_PATH_RE = re.compile(r"/home/[^\s`)\]\"'>,;]+")
LINE_RANGE_SUFFIX_RE = re.compile(r"^(.*/[^/:]+):\d+(?:-\d+)?$")
SCRIPT_PATH = Path(__file__).resolve()
REPO_SELF = SCRIPT_PATH.parent.parent # small-scripts repo (holds data/idle-draft)
@@ -721,6 +722,16 @@ def extract_absolute_paths(text: str) -> list[str]:
return ABS_PATH_RE.findall(text)
def strip_line_range(p: str) -> str:
"""Strip a trailing ':<digits>' or ':<digits>-<digits>' citation line-range suffix.
Only strips when the remainder still looks like a path (has a filename
segment before the colon); a plain path with no suffix is unchanged.
"""
m = LINE_RANGE_SUFFIX_RE.match(p)
return m.group(1) if m else p
def validate_output(work_type: str, text: str) -> tuple[bool, str]:
if not text or not text.strip():
return False, "output is empty"
@@ -729,7 +740,7 @@ def validate_output(work_type: str, text: str) -> tuple[bool, str]:
if not first_line.startswith(prefix):
return False, f"first non-blank line does not start with '{prefix}': {first_line!r}"
if work_type == "research":
dead = [p for p in extract_absolute_paths(text) if not Path(p.rstrip(".,;:")).exists()]
dead = [p for p in extract_absolute_paths(text) if not Path(strip_line_range(p.rstrip(".,;:"))).exists()]
if dead:
return False, f"dead cited path(s): {dead}"
return True, "ok"