Document semantic coherence

From CarlosCaPe/octorato · View interactive version

Document semantic coherence is an AI agent skill from the GitHub repository CarlosCaPe/octorato. Document Semantic Coherence

How to use this skill

Skill file

Document Semantic Coherence

What

A discipline for ensuring technical documents maintain internal logical consistency, structural integrity, and semantic alignment throughout their lifecycle. This skill addresses the hidden complexity of long documents where contradictions, orphaned references, and structural decay accumulate invisibly.

Why

Long technical documents (1,000+ lines) are prone to semantic drift — incremental edits that introduce contradictions, orphan references, duplicate content, or broken narrative flow. These defects erode reader trust and can lead to incorrect decisions based on conflicting information within the same document.

Common failure modes:

The Seven Coherence Dimensions

| # | Dimension | Definition | Detection Method |

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

| 1 | Logical Consistency | No statement contradicts another statement | Search for antonym pairs near same topic keywords |

| 2 | Reference Integrity | All cross-references resolve to valid targets | Grep all §, #, line, Finding, Evidence patterns |

| 3 | Status Alignment | Status markers (✅⚠️🔴⏳) match the content they describe | Audit each marker against its surrounding context |

| 4 | Structural Completeness | Every promised section exists; no orphan headers | Walk heading hierarchy, verify all TOC entries |

| 5 | Temporal Consistency | Dates, timelines, and sequences don't contradict | Extract all dates, verify chronological plausibility |

| 6 | Voice Uniformity | Consistent tense, person, and formality level | Spot-check random paragraphs for stylistic drift |

| 7 | Deduplication | No content repeated verbatim in multiple locations | Hash paragraph fingerprints, flag duplicates |

How

Pre-Edit Coherence Check

Before making significant edits to a long document:

1. Identify all sections that reference the content you're changing
2. Note the current status markers (✅⚠️🔴⏳) in affected areas
3. List all cross-references (§, Finding #, Evidence #) pointing to/from the area
4. Check if the content appears elsewhere (search key phrases)

Post-Edit Coherence Verification

After completing edits, run a systematic sweep:

## Coherence Checklist

### 1. Contradiction Scan
- [ ] Search for "NOT" / "ZERO" / "confirmed" near edited topics
- [ ] Verify no section now contradicts the changes made
- [ ] Check that summary/conclusion sections align with detail sections

### 2. Reference Integrity
- [ ] All §X.Y references point to existing sections
- [ ] All "Finding #N" references exist in the findings register
- [ ] All "Evidence #N" references exist in the evidence register
- [ ] All line number references (if any) are still valid

### 3. Status Marker Audit
- [ ] No ⏳ TBD where content is now complete
- [ ] No ✅ where content is actually pending
- [ ] No ⚠️ where issue is fully resolved
- [ ] No 🔴 where blocker is removed

### 4. Stale Content Removal
- [ ] No strikethrough (~~) text left in final document
- [ ] No "PENDING DISCOVERY" or similar placeholder text
- [ ] No "deferred to Phase X" where Phase X is now complete
- [ ] No duplicate paragraphs from copy-paste errors

### 5. Structural Integrity
- [ ] All sections in TOC exist in document
- [ ] All major sections have content (no empty headers)
- [ ] Heading hierarchy is consistent (no orphan ### under #)
- [ ] Section numbering is sequential (no gaps)

Automated Detection Patterns

# Find potential contradictions (antonym patterns)
grep -n "NOT\|ZERO\|confirmed\|complete\|pending\|TBD" doc.md | sort

# Find orphan cross-references
grep -oE '§[0-9]+\.[0-9]+' doc.md | sort | uniq -c | sort -rn

# Find status markers
grep -n "✅\|⚠️\|🔴\|⏳" doc.md

# Find stale markers
grep -n "~~\|PENDING\|TBD\|deferred" doc.md

# Find duplicate content (paragraph hash)
awk 'NF>5 {print NR": "$0}' doc.md | sort -t: -k2 | uniq -d -f1

When to Use

Anti-Patterns

| Anti-Pattern | Problem | Solution |

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

| Edit-and-forget | Change one section, forget to update referencing sections | Use checklist systematically |

| Copy-paste accumulation | Same paragraph appears in 3 places with slight variations | Single source of truth + references |

| Status marker decay | ✅ added when started, never updated when blocked | Audit markers on every edit |

| Reference rot | §4.3 becomes §4.4 after insertion, old refs broken | Search-and-replace all refs after structural changes |

| Revision cruft | ~~old text~~ and "UPDATED:" annotations pile up | Clean document after each revision cycle |

Real-World Example

From the Acme Corp Migration Evaluation TDD session:

Problem Found: §2.4.2 said "🔴 Critical Extrapolation — NOW REPLACED BY ACTUAL DATA" but still contained the old extrapolated content below the label.

Detection Method: Contradiction scan — "REPLACED" claims removal, but content still present.

Resolution: Removed the entire outdated extrapolation block, kept only the factual content.

Lesson: Labels claiming removal don't remove content — verify the actual document state.

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.