feat(link-check): lint relative markdown links across the repo
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
This commit is contained in:
parent
83f78aa618
commit
68ad38188e
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
type: Blueprint
|
type: Blueprint
|
||||||
status: locked
|
status: implemented
|
||||||
traces-to: ROADMAP.md phase 12
|
traces-to: ROADMAP.md phase 12
|
||||||
sounded: 2026-07-31
|
sounded: 2026-07-31
|
||||||
cites:
|
cites:
|
||||||
|
|||||||
@ -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
|
- [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
|
- [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
|
- [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
|
## Ferries
|
||||||
|
|
||||||
|
|||||||
@ -52,7 +52,7 @@ fill the missing sections as deltas, don't restart.
|
|||||||
|
|
||||||
## Output / done criteria
|
## Output / done criteria
|
||||||
- `OKF/ROADMAP.md` matches the skeleton; every *open* phase has a verify
|
- `OKF/ROADMAP.md` matches the skeleton; every *open* phase has a verify
|
||||||
step and every discharged one is pruned to `✅ verified <date>, [NNN](…)`;
|
step and every discharged one is pruned to `✅ verified <date>, NNN`;
|
||||||
every locked decision traces to a user answer or sourced finding.
|
every locked decision traces to a user answer or sourced finding.
|
||||||
- Revision: superseded decisions remain visible; every edit traces to a
|
- Revision: superseded decisions remain visible; every edit traces to a
|
||||||
named delta.
|
named delta.
|
||||||
|
|||||||
@ -13,7 +13,8 @@ For a roadmap that exists and reality that moved. Formerly
|
|||||||
time.
|
time.
|
||||||
3. **Apply, smallest edit per delta:**
|
3. **Apply, smallest edit per delta:**
|
||||||
- Phase done → *replace* its verify line with `✅ verified <date>,
|
- Phase done → *replace* its verify line with `✅ verified <date>,
|
||||||
[NNN](blueprints/…)`, R-020's prune — never a tick beside a live step.
|
blueprints/NNN-<slug>.md`, R-020's prune — never a tick beside a
|
||||||
|
live step.
|
||||||
- Verify failed → record what failed under the phase; do not delete
|
- Verify failed → record what failed under the phase; do not delete
|
||||||
the phase. Re-plan it only if the user agrees.
|
the phase. Re-plan it only if the user agrees.
|
||||||
- New gotcha/learning → append to *Risks & gotchas* (and mirror to
|
- New gotcha/learning → append to *Risks & gotchas* (and mirror to
|
||||||
|
|||||||
@ -80,9 +80,9 @@ contract: [okf-layout.md](okf-layout.md).
|
|||||||
judgement.
|
judgement.
|
||||||
|
|
||||||
## Output / done criteria
|
## Output / done criteria
|
||||||
- **`scripts/okf-check <okf-dir>` and `scripts/render-check <repo-root>`
|
- **`scripts/okf-check <okf-dir>`, `render-check <repo-root>` and
|
||||||
run and output pasted**, exiting 0 — invoke by this skill's own base
|
`link-check <repo-root>` run and output pasted**, exiting 0 — invoke
|
||||||
directory, `skills/loop/...` being octobot-only. Claims are not gates.
|
from this skill's own base dir, octobot-only. Claims are not gates.
|
||||||
- `OKF/` matches [okf-layout.md](okf-layout.md) including its
|
- `OKF/` matches [okf-layout.md](okf-layout.md) including its
|
||||||
conformance block; `index.md` links every page that exists.
|
conformance block; `index.md` links every page that exists.
|
||||||
- `AGENTS.md` carries the hook block.
|
- `AGENTS.md` carries the hook block.
|
||||||
|
|||||||
77
skills/loop/write-OKF/scripts/link-check
Executable file
77
skills/loop/write-OKF/scripts/link-check
Executable file
@ -0,0 +1,77 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Validate relative markdown links. Usage: link-check <repo-root>
|
||||||
|
|
||||||
|
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/<name>/` 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 <repo-root>", 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))
|
||||||
Loading…
x
Reference in New Issue
Block a user