Cross reference integrity

From CarlosCaPe/octorato · View interactive version

Cross reference integrity is an AI agent skill from the GitHub repository CarlosCaPe/octorato. Cross-Reference Integrity

How to use this skill

Skill file

Cross-Reference Integrity

What

A systematic approach to managing internal document references (section numbers, finding numbers, evidence numbers, line numbers) that prevents reference rot and orphan links as documents evolve.

Why

Cross-references are the hyperlinks of technical documents. When they break:

Reference rot accelerates as documents grow. A 500-line document might have 20 cross-references. A 3,000-line document might have 200+. Manual tracking becomes impossible.

Reference Types and Vulnerabilities

| Reference Type | Pattern | Vulnerability | Example |

|----------------|---------|---------------|---------|

| Section reference | §X.Y, Section X.Y | Breaks when sections renumbered | "See §2.4.2 for details" |

| Finding reference | Finding #N, #N | Breaks when findings reordered | "Confirmed by Finding #35" |

| Evidence reference | Evidence #N | Breaks when evidence list changes | "Source: Evidence #12" |

| Line reference | line N, lines N-M | Breaks on any edit above that line | "See line 450" |

| Named anchor | Appendix A Q7 | Stable if naming consistent | "Answered in Appendix A Q7" |

Stability ranking (most to least stable):

  1. Named anchors (survive most edits)
  2. Finding/Evidence numbers (survive structural changes)
  3. Section numbers (break on outline changes)
  4. Line numbers (break on any edit)

How

Reference Inventory

Before major edits, inventory all references:

# Extract all section references
grep -oE '§[0-9]+(\.[0-9]+)*' document.md | sort | uniq -c

# Extract all finding references  
grep -oE 'Finding #[0-9]+|#[0-9]+' document.md | sort | uniq -c

# Extract all evidence references
grep -oE 'Evidence #[0-9]+' document.md | sort | uniq -c

# Extract potential line references
grep -oE 'line[s]? [0-9]+' document.md

Validation Matrix

Create a validation matrix for critical documents:

| Reference | Target Exists? | Target Content Matches? | Used In |
|-----------|----------------|------------------------|---------|
| §2.5.2 | ✅ | ✅ SP inventory table | §6.4, Exec Summary |
| Finding #35 | ✅ | ✅ Hospital pipeline failures | §6.3, Charter row 5 |
| Evidence #12 | ✅ | ✅ Lincoln's charter PDF | Charter Traceability |

Structural Change Protocol

When renumbering sections or reordering content:

  1. Before change: Export all references to a temp file
  2. Make change: Perform the structural modification
  3. After change: Search-and-replace all affected references
  4. Verify: Re-run reference inventory, compare to original
# Example: Section 2.4 becomes 2.5
sed -i 's/§2\.4/§2.5/g; s/§2\.5/§2.6/g; s/§2\.6/§2.7/g' document.md
# WARNING: Order matters! Work backwards to avoid collisions

Bidirectional Reference Tracking

For critical references, track both directions:

## §6.4 Domain Migration Roadmap

**Referenced by:** Charter Traceability row 6, Executive Summary, §3.6.3
**References:** §2.5.2 (SP counts), §3.1 (criteria matrix), §3.4 (risk), Finding #28 (cross-DB)

This makes it visible which sections need updating when either end changes.

Reference Patterns by Document Type

| Document Type | Primary Reference Style | Rationale |

|---------------|------------------------|-----------|

| TDD / RFC | Section numbers + Finding numbers | Formal structure, evidence-backed |

| Runbook | Named anchors + step numbers | Execution sequence matters |

| API Docs | Named anchors + code refs | Stability across versions |

| Audit Report | Finding numbers + Evidence numbers | Traceability chain critical |

When to Use

Anti-Patterns

| Anti-Pattern | Problem | Solution |

|--------------|---------|----------|

| Line number references | Break on any edit | Use section/finding numbers instead |

| Implicit references | "See above" — where exactly? | Use explicit section numbers |

| Stale reference comments | // See §4.2 (MOVED TO §5.1) | Update the reference, remove comment |

| Reference-free claims | "As confirmed earlier..." — where? | Add explicit Finding # or § reference |

| Copy-paste references | Same §2.4.2 appears 15 times, section renamed | Search-replace systematically |

Automation Helpers

Node.js Reference Validator

const fs = require('fs');
const doc = fs.readFileSync('document.md', 'utf8');

// Extract all section references
const sectionRefs = doc.match(/§\d+(\.\d+)*/g) || [];

// Extract all section headers
const sectionHeaders = doc.match(/^#{1,6}\s+\d+(\.\d+)*\s/gm) || [];
const definedSections = sectionHeaders.map(h => h.match(/\d+(\.\d+)*/)[0]);

// Find orphan references
const orphans = sectionRefs.filter(ref => {
  const num = ref.replace('§', '');
  return !definedSections.some(s => s.startsWith(num));
});

console.log('Potentially orphaned references:', [...new Set(orphans)]);

Grep-Based Quick Check

# Find all unique section references
grep -oE '§[0-9.]+' doc.md | sort -u > refs.txt

# Find all section headers
grep -oE '^#{1,4} [0-9.]+' doc.md | sed 's/^#* /§/' | sort -u > headers.txt

# Show references without matching headers
comm -23 refs.txt headers.txt

Real-World Example

From the Acme Corp TDD session:

Scenario: Added new §6 Charter Deliverables section (366 lines) between existing content.

Reference Impact:

Verification: Node.js script checked all 8 traceability rows showed ✅ with valid §6.x references.

Related Skills

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.