diff --git a/OKF/decisions/022-prose-cites-carry-a-register-prefix.md b/OKF/decisions/022-prose-cites-carry-a-register-prefix.md index 47c4e20..e914576 100644 --- a/OKF/decisions/022-prose-cites-carry-a-register-prefix.md +++ b/OKF/decisions/022-prose-cites-carry-a-register-prefix.md @@ -15,8 +15,8 @@ reversible: yes — drop the prefixes; numbers, filenames and links never moved # 022 — a prose cite carries its register's prefix Blueprints and the why-register number independently, so the same three -digits already name two unrelated pages three times over: 013, 017 and -019 each exist in both. A markdown link is safe — its path says which — +digits already name two unrelated pages three times over: `013`, `017` +and `019` each exist in both. A markdown link is safe — its path says which — but a bare number in prose is not, and `B-019` (the render lint) against `R-019` (recon may self-fire) is the kind of collision a reader resolves wrongly without noticing. **In prose: `B-NNN` for a blueprint, `R-NNN` diff --git a/skills/loop/write-OKF/scripts/okf-check b/skills/loop/write-OKF/scripts/okf-check index 8676254..8f42b0a 100755 --- a/skills/loop/write-OKF/scripts/okf-check +++ b/skills/loop/write-OKF/scripts/okf-check @@ -2,11 +2,11 @@ """Validate an OKF bundle. Usage: okf-check Errors (exit 1): missing type, missing warrant, duplicate answer, -unresolvable cite, malformed `okf:derived` fence, page unreachable from -index.md, page over its line cap, register index line disagreeing with -its decision file, moored ferry with a malformed `sealed:` pin or a -surviving directory. Warnings (exit 0): page with no cites, blueprint -locked without a `sounded:` stamp. +unresolvable cite, unprefixed register cite in prose, malformed +`okf:derived` fence, page unreachable from index.md, page over its line +cap, register index line disagreeing with its decision file, moored ferry +with a malformed `sealed:` pin or a surviving directory. Warnings +(exit 0): page with no cites, blueprint locked without a `sounded:` stamp. Pin *shape* only — whether the change id still resolves needs the repo in hand, which is write-OKF refresh's job, not a validator that must exit 0 @@ -116,6 +116,32 @@ def cite_resolves(cite, page, okf): return False +def register_numbers(okf): + """Three-digit numbers naming a live file in either register.""" + return {p.name[:3] for register in ("blueprints", "decisions") + for p in (okf / register).glob("[0-9][0-9][0-9]-*.md")} + + +def prose_cites(text, numbers): + """Bare register numbers standing in a page's prose. + + Blueprints and the why-register number independently, so a bare `019` + names two unrelated pages and a reader resolves it by guessing. The + exclusions are the rule's hard half and all mechanical: frontmatter, + fenced blocks, code spans, whole markdown links (text and target + both — the path already says which register), and the page's own H1. + A number touching `/`, `-`, `.` or a word character is part of a path, + a date or a `superseded-by-NNN`, never a cite. + """ + body = text.partition("\n---")[2] if text.startswith("---\n") else text + body = re.sub(r"^```.*?^```", " ", body, flags=re.M | re.S) + body = re.sub(r"`[^`]*`", " ", body) + body = re.sub(r"\[[^\]]*\]\([^)]*\)", " ", body) + body = re.sub(r"^#.*$", " ", body, flags=re.M) + found = re.findall(r"(?.md split. + if fields.get("type") != "Learnings": + for number in prose_cites(text, numbers): + errors.append(f"{rel}: unprefixed register cite: {number}") + check_ferries(okf, errors) check_register(okf, warrants, errors)