| name | doc-index |
| description | Generate dense, token-efficient indexes of documents for fast contradiction detection. Use when indexing docs for canonicalize-architecture, compressing specs for analysis, or creating navigable summaries. Works on any markdown documents. |
| model | claude-haiku-4-5 |
| allowed-tools | Read, Write, Glob, Bash |
Document Indexing Skill
Create a compressed index of a markdown document that captures high-signal content for contradiction detection.
Your Task
Given a source file, create an index file alongside it (same name with .INDEX.md extension).
What to Extract
Scan the source document and extract:
-
Key Assertions - Normative statements with line references:
- MUST/MUST NOT/SHALL/SHALL NOT (RFC 2119 style)
- REQUIRED/FORBIDDEN/MANDATORY
- Imperative assertions ("all signals flow through...", "execution order is...")
- Bold requirements or numbered requirements
-
Definitions - Bold terms (just the term name and line number, no descriptions)
-
Invariants - Numbered rules like I1, I2, etc. (keep the full rule text INCLUDING critical examples)
- If examples define the rule's meaning, include them
- If rationale is one sentence, include it
- Keep consequences if they're critical to understanding
-
Data Structures - Interface/type names with field count and line reference
-
Dependencies - What this doc references and what references it
-
Decisions - Lines starting with "DECISION:" (just the decision title, no rationale)
-
Tier Suggestion - Is this T1 (foundational), T2 (structural), or T3 (optional)?
Line References
Use format: [L123] for single line, [L123-130] for ranges.
Output Format
---
indexed: true
source: {relative_path}
source_hash: {first 12 chars of sha256}
source_mtime: {ISO timestamp}
original_tokens: ~{word_count * 1.3}
index_tokens: ~{index_word_count * 1.3}
compression: {percentage}%
index_version: 1.0
---
- MUST: {assertion} [L{num}]
- **{Term}** [L{num}]
- **{ID}**: {full rule text} [L{num}]
- **{Name}** ({N} fields) [L{num}]
- **Depends on**: {list or "none"}
- **Referenced by**: {list}
- DECISION: {title only} [L{num}]
- **Suggested**: T{1|2|3}
- **Rationale**: {1-2 sentences}
Target
Compress to 20-25% of original size. Drop verbose descriptions - keep only names, IDs, and line references for targeted lookup.
Calculate Metadata
SOURCE_FILE="$1"
INDEX_FILE="${SOURCE_FILE}.INDEX.md"
source_hash=$(shasum -a 256 "$SOURCE_FILE" | cut -c1-12)
source_mtime=$(stat -f "%Sm" -t "%Y-%m-%dT%H:%M:%SZ" "$SOURCE_FILE" 2>/dev/null || date -Iseconds)
word_count=$(wc -w < "$SOURCE_FILE" | tr -d ' ')
original_tokens=$((word_count * 13 / 10))