From 68ad38188ee8d4e79d88ded33258a7be73a5650c Mon Sep 17 00:00:00 2001 From: Lukasz Boryn Date: Fri, 31 Jul 2026 13:02:57 +0200 Subject: [PATCH] feat(link-check): lint relative markdown links across the repo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add skills/loop/write-OKF/scripts/link-check, a fourth lint mirroring okf-check / render-check / skill-check: same argv shape, ERROR prefix, closing tally and 0/1/2 exit codes. It walks every *.md from the repo root — dot-directories and OKF/blueprints/ out, render-check's walk exactly — skips fenced blocks, and errors on any inline link whose target does not resolve against its containing file's directory. Register it in write-OKF's run-and-paste line, and unmake the two ellipsis placeholders the lint catches: architect/SKILL.md's [NNN](…) and revise.md's [NNN](blueprints/…) become prose, without which the lint cannot reach green. Satisfies ROADMAP phase 12's precondition — that rename moves 26 of the 421 link targets, and a grep for the old names proves absence, not that the new paths resolve. blueprint 023 --- ...-add-a-link-lint-over-relative-md-links.md | 2 +- OKF/index.md | 2 +- skills/loop/architect/SKILL.md | 2 +- skills/loop/architect/revise.md | 3 +- skills/loop/write-OKF/SKILL.md | 6 +- skills/loop/write-OKF/scripts/link-check | 77 +++++++++++++++++++ 6 files changed, 85 insertions(+), 7 deletions(-) create mode 100755 skills/loop/write-OKF/scripts/link-check diff --git a/OKF/blueprints/023-add-a-link-lint-over-relative-md-links.md b/OKF/blueprints/023-add-a-link-lint-over-relative-md-links.md index 3f3fc5a..aa73729 100644 --- a/OKF/blueprints/023-add-a-link-lint-over-relative-md-links.md +++ b/OKF/blueprints/023-add-a-link-lint-over-relative-md-links.md @@ -1,6 +1,6 @@ --- type: Blueprint -status: locked +status: implemented traces-to: ROADMAP.md phase 12 sounded: 2026-07-31 cites: diff --git a/OKF/index.md b/OKF/index.md index 0e29c8e..f8c956c 100644 --- a/OKF/index.md +++ b/OKF/index.md @@ -45,7 +45,7 @@ your task needs. Humans welcome too. - [020](blueprints/020-enforce-the-prune-and-validate-every-cite.md) — enforce the roadmap prune and validate every page's cites — superseded-by-022 - [021](blueprints/021-align-validator-and-doctrine.md) — align the validator and the doctrine on splits, prefixes and cites — implemented - [022](blueprints/022-validate-every-cite-at-every-status.md) — enforce the roadmap prune and validate every cite at every status — implemented -- [023](blueprints/023-add-a-link-lint-over-relative-md-links.md) — add a link lint over relative markdown links — locked +- [023](blueprints/023-add-a-link-lint-over-relative-md-links.md) — add a link lint over relative markdown links — implemented ## Ferries diff --git a/skills/loop/architect/SKILL.md b/skills/loop/architect/SKILL.md index 433800d..2eabe4b 100644 --- a/skills/loop/architect/SKILL.md +++ b/skills/loop/architect/SKILL.md @@ -52,7 +52,7 @@ fill the missing sections as deltas, don't restart. ## Output / done criteria - `OKF/ROADMAP.md` matches the skeleton; every *open* phase has a verify - step and every discharged one is pruned to `✅ verified , [NNN](…)`; + step and every discharged one is pruned to `✅ verified , NNN`; every locked decision traces to a user answer or sourced finding. - Revision: superseded decisions remain visible; every edit traces to a named delta. diff --git a/skills/loop/architect/revise.md b/skills/loop/architect/revise.md index 6b32545..df04b83 100644 --- a/skills/loop/architect/revise.md +++ b/skills/loop/architect/revise.md @@ -13,7 +13,8 @@ For a roadmap that exists and reality that moved. Formerly time. 3. **Apply, smallest edit per delta:** - Phase done → *replace* its verify line with `✅ verified , - [NNN](blueprints/…)`, R-020's prune — never a tick beside a live step. + blueprints/NNN-.md`, R-020's prune — never a tick beside a + live step. - Verify failed → record what failed under the phase; do not delete the phase. Re-plan it only if the user agrees. - New gotcha/learning → append to *Risks & gotchas* (and mirror to diff --git a/skills/loop/write-OKF/SKILL.md b/skills/loop/write-OKF/SKILL.md index ee053c0..d04f937 100644 --- a/skills/loop/write-OKF/SKILL.md +++ b/skills/loop/write-OKF/SKILL.md @@ -80,9 +80,9 @@ contract: [okf-layout.md](okf-layout.md). judgement. ## Output / done criteria -- **`scripts/okf-check ` and `scripts/render-check ` - run and output pasted**, exiting 0 — invoke by this skill's own base - directory, `skills/loop/...` being octobot-only. Claims are not gates. +- **`scripts/okf-check `, `render-check ` and + `link-check ` run and output pasted**, exiting 0 — invoke + from this skill's own base dir, octobot-only. Claims are not gates. - `OKF/` matches [okf-layout.md](okf-layout.md) including its conformance block; `index.md` links every page that exists. - `AGENTS.md` carries the hook block. diff --git a/skills/loop/write-OKF/scripts/link-check b/skills/loop/write-OKF/scripts/link-check new file mode 100755 index 0000000..e297287 --- /dev/null +++ b/skills/loop/write-OKF/scripts/link-check @@ -0,0 +1,77 @@ +#!/usr/bin/env python3 +"""Validate relative markdown links. Usage: link-check + +Errors (exit 1): an inline link whose target does not resolve against the +containing file's directory. Nothing warns: an unresolvable link is always +a defect, never a judgement call. The tally keeps the siblings' shape. + +The links are load-bearing and silent when broken. A skill installs as a +symlink into `~/.claude/skills//` and `..` traverses it physically, +so a link written for the repo layout resolves from the installed base +directory too — but nothing follows a link automatically. A dangling one +surfaces as a failed read, not an error, so the signal has to be static. + +Fenced blocks are skipped: there a link is illustration, not navigation. +`OKF/blueprints/` is skipped for its siblings' reason — a locked +blueprint is append-only, so a rename cannot repair a link inside one. +""" +import re +import sys +from pathlib import Path + +LINK = re.compile(r"\]\(([^)]*)\)") +EXTERNAL = ("http://", "https://", "mailto:", "#") +SKIP = ("OKF/blueprints/",) + + +def targets(text): + """Link targets outside fenced blocks, as (line number, target). + + The line number is 1-based, so an error reads as a cite. A line + opening or closing a fence toggles the skip and is not itself read. + """ + fenced = False + for number, line in enumerate(text.splitlines(), 1): + if line.startswith("```"): + fenced = not fenced + elif not fenced: + for target in LINK.findall(line): + if not target.startswith(EXTERNAL): + yield number, target + + +def pages(root): + """Every `*.md` under the root, dot-directories and blueprints out.""" + for page in sorted(root.rglob("*.md")): + rel = page.relative_to(root) + if any(part.startswith(".") for part in rel.parts): + continue + if rel.as_posix().startswith(SKIP): + continue + yield page, rel + + +def main(argv): + if len(argv) != 2: + print("usage: link-check ", file=sys.stderr) + return 2 + root = Path(argv[1]).resolve() + if not root.is_dir(): + print(f"not a directory: {root}", file=sys.stderr) + return 2 + + errors = [] + for page, rel in pages(root): + for number, target in targets(page.read_text()): + path = target.split("#", 1)[0] # a fragment names no file + if not (page.parent / path).exists(): + errors.append(f"{rel}:{number}: unresolvable link: {target}") + + for line in errors: + print(f"ERROR {line}") + print(f"{len(errors)} error(s), 0 warning(s)") + return 1 if errors else 0 + + +if __name__ == "__main__": + sys.exit(main(sys.argv))