Repository navigation
docs(adr): anchor all cross-ADR links + enforce reference hygiene - #600
Conversation
Every anchorless cross-ADR *.md link now carries its target file's H1 heading anchor (e.g. 016-contract-interactions.md -> 016-contract-interactions.md#smart-contract-interaction-model). 808 links across 37 files; slugs computed with the GitHub algorithm and verified 38/38 against pandoc gfm_auto_identifiers (the PDF renderer). A retitled/renamed ADR now breaks the link, so drift is caught instead of silently pointing at the wrong file. Adds adr/Makefile guards (awk/sed/grep only, no perl/python): - check-bare-refs: every ADR mention (with OR without § Section) must be a markdown link, not bare prose/table text (was § only). - check-md-anchors: every cross-ADR *.md link must carry a #anchor. - check-section-spacing: §3 for numbers, § Word for names (locks in the #599 § normalization). - check-refs: runs all three. A new adr-ref-hygiene pre-commit hook mirrors them (same files: scope as the existing adr-book-list hook). Fenced code, ATX headings, inline code, and existing links are excluded; ugly but correct slugs (em-dash -> --) are kept as-is. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Adds check-bare-refs, check-md-anchors, check-section-spacing as separate steps in the adr-book-list job (renamed display "ADR book check"; job id unchanged so ci-success needs/allowed-skips stay valid). Separate steps so a failure points at the specific guard in the UI. Still pure shell (awk/sed/grep), sub-second, gated on adr/** changes. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…f787 # Conflicts: # adr/001-network.md # adr/003-payments.md # adr/005-protocol.md # adr/008-reputation.md # adr/009-governance.md # adr/011-content-takedown.md # adr/014-on-chain-verification.md # adr/016-contract-interactions.md # adr/018-liquidity-strategy.md # adr/019-node-onboarding.md # adr/026-tokenomics.md # adr/028-slashing-appeals.md # adr/030-node-region-self-attestation.md # adr/032-safety-reserve-appeals-contract.md # adr/033-safety-insurance-reserve.md # adr/appendix-fraud-detection.md # adr/appendix-l2-deployment.md # adr/appendix-observability.md # adr/appendix-operator-key-rotation.md # adr/appendix-operator-upgrade-path.md # adr/architecture.md # adr/glossary.md
There was a problem hiding this comment.
Code Review
This pull request introduces new reference-hygiene checks in the Makefile and updates numerous cross-references across the ADR documentation to include specific section anchors. The reviewer provided actionable feedback to improve the regex for bare reference detection by including headings and offered guidance on maintaining stable Markdown anchor links in accordance with GitHub Flavored Markdown conventions.
| @bad=""; for f in $(SRCS_REF); do \ | ||
| hits=$$(awk -v F="$$f" '/^```/{c=!c;next} c{next} /^#{1,6} /{next} {print F":"FNR": "$$0}' "$$f" \ | ||
| | sed -e 's/`[^`]*`//g' -e 's/\[[^]]*\]([^)]*)//g' \ | ||
| | grep -E '(^|[^[*])ADR ?[0-9]{1,3}' || true); \ |
There was a problem hiding this comment.
The regex (^|[^[*])ADR used in check-bare-refs has gaps that prevent it from catching certain bare references. Specifically, it excludes matches where the preceding character is [ or *. This means bare references in brackets (e.g., [ADR 001]) or emphasized text (e.g., *ADR 001*) will be missed. Since the preceding sed command already removes valid inline links, using a word-boundary check is more robust and correctly identifies these cases as bare references.
| grep -E '\\bADR ?[0-9]{1,3}\\b' || true); \
|
|
||
| check-bare-refs: | ||
| @bad=""; for f in $(SRCS_REF); do \ | ||
| hits=$$(awk -v F="$$f" '/^```/{c=!c;next} c{next} /^#{1,6} /{next} {print F":"FNR": "$$0}' "$$f" \ |
There was a problem hiding this comment.
The check-bare-refs target currently skips ATX headings (/^#{1,6} /{next}). This allows bare ADR references to persist in section titles (e.g., ## Relationship to ADR 001). To maintain high reference hygiene throughout the documentation, headings should also be checked to ensure all ADR mentions are properly linked.
| 2. **DHT FIND_VALUE.** Issue an iterative O(log N) `FindValueRequest` for H via `cdn/dht/v1` (see [ADR 022 §1.6](022-content-discovery.md#adr-022--content-discovery-at-scale)). Returns a `Vec<NodeId>` of known holders. The DHT bootstraps from `StakingRegistry.getActiveNodes()` — a node's first peers come from the on-chain registry and immediately participate in DHT lookups, so there is no separate bootstrap window. | ||
| 3. **Probe the DHT candidate set.** Send `ProbeRequest {hash, timestamp_us}` in parallel to the NodeIds returned by the DHT. ALPN: `cdn/probe/v1` — `ProbeResponse {has_blob, rate_per_mb, timestamp_us, total_bytes?, slash_sig}`. If DHT returned no providers, fall back to the on-chain origin directory ([ADR 022 § Origin discovery](022-content-discovery.md#adr-022--content-discovery-at-scale)): resolve namespaces via `PublisherRegistry.namespaceOf(hash)` and union the operator-address sets via `OriginAssignment.getOrigins(namespaceId)` for each, then probe those NodeIds. |
There was a problem hiding this comment.
Several links that refer to specific sections (e.g., §1.6 or § Origin discovery) have been updated to point to the target file's H1 anchor. While this satisfies the requirement for links to have anchors, it reduces the utility of the documentation by losing deep link specificity. Where the link text refers to a specific section, the link should use that section's anchor. Ensure these anchors follow GitHub Flavored Markdown (GFM) conventions: convert headers to lowercase, replace spaces with hyphens, and include numbers for numbered headings (e.g., #16-section-name for '1.6 Section Name'). Additionally, simplify target headings by removing backticks or mathematical symbols, and be aware that special characters like '+' or em-dashes are removed, which may result in double hyphens for sequences like ' + '.
References
- When creating Markdown anchor links for headings that include numbering, the slug must include the number and follow GitHub Flavored Markdown (GFM) conventions (e.g., use 'Add devcontainer for secure Claude Code sessions #1-section-name' for a heading titled '### 1. Section Name') to ensure link stability.
- When referencing ADR sections via Markdown links, use stable GitHub Flavored Markdown (GFM) anchor slugs and simplify the target headings (e.g., by removing backticks or mathematical symbols) to ensure link stability across different renderers.
- Verify that internal Markdown links use correct GitHub Flavored Markdown (GFM) anchor slugs, which are typically generated by converting headers to lowercase and replacing spaces with hyphens (e.g., '### HeaderName' becomes '#headername').
- When extracting historical content from documents, verify that section headings and their corresponding anchors are up-to-date, as they may have been renamed since the original draft.
- When referencing ADRs, ensure that anchor links are correctly formatted, especially when special characters like '+' or em-dashes ('—') are present. GFM slug generation replaces whitespace with hyphens and removes special characters, potentially leading to double hyphens.
Coverage reportTotal: 89.68% (was 89.68%, ● 0.00%) — 16110/17964 lines No Rust files changed in this PR. History
|
check-bare-refs skipped ALL ATX headings, letting bare ADR refs persist in section titles (e.g. "## Relationship to ADR 001"). Now only the H1 title line is exempt (can't link a doc to its own title); H2-H6 are checked. Linked the 5 sub-heading refs this surfaced (026/005/012/002/013 + one self-ref) — adding the link keeps the visible heading text, so section slugs are unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Follow-up to #599. Closes the gap where cross-ADR links could rot silently.
[…](NNN-foo.md)links across 37 files now carry the file's H1 anchor(
…NNN-foo.md#adr-nnn-title). A retitled/renamed ADR now breaks thelink, so drift is caught instead of silently pointing at the wrong file.
Slugs computed with the GitHub algorithm, verified 38/38 against
pandoc gfm_auto_identifiers(the PDF renderer). Ugly-but-correctslugs (em-dash →
--) kept as-is — nobody reads raw markdown.adr/Makefile, awk/sed/grep only — no perl/python):check-bare-refs— everyADR NNNmention (with or without§ Section) must be a markdown link, not bare prose/table text.check-md-anchors— every cross-ADR*.mdlink must carry a#anchor.check-section-spacing—§3for numbers,§ Wordfor names(locks in docs(adr): link bare ADR cross-references; normalize § spacing #599's
§normalization).check-refs— runs all three.ADR book-check job (job id unchanged) and via a new
adr-ref-hygienepre-commit hook mirroring the existing
adr-book-listone.Fenced code, ATX headings, inline code, and existing links are excluded
(references there either can't be links or already are).
Test plan
make -C adr check-refs→ all three greenmake -C adr check-book-list→ still green (unaffected)pandoc gfm_auto_identifiers; 0 unresolved anchorsmarkdownlint-cli2onadr/*.md→ 0 errors (MD013/MD051off)git diff --checkclean; pre-commit hooks pass on both commitsADR book checkjob green on this PR