---
name: kb-crosslink
description: Scan wiki articles for unlinked entity mentions and insert [[wikilinks]] to eliminate orphans
title: KB Cross-Link — Wiki Link Insertion
category: core
status: active
metadata:
  triggers:
  - cross-link wiki
  - add wikilinks
  - link articles
  - fix orphans
---
## Instructions

Scan all wiki articles and insert [[wikilinks]] wherever an entity or concept is mentioned by name but not yet linked. This is the primary mechanism for eliminating orphan pages and building the wiki's link graph.

### Process

1. **Build title index** — collect all article titles and slugs from the wiki
2. **Scan each article** — for every article, check if any other article's title appears in the text without being wrapped in `[[...]]`
3. **Insert links** — wrap the first unlinked mention of each entity in `[[slug]]` notation
4. **Skip self-links** — never link an article to itself
5. **Skip already-linked** — if the mention is already inside `[[...]]`, leave it alone
6. **Skip frontmatter** — never modify YAML frontmatter blocks
7. **Skip code blocks** — never modify content inside ``` fences

### Matching Strategy

- **Case-insensitive** title matching against article text
- **First mention only** — link the first occurrence in the body, not every instance
- **Whole word matching** — "AI" should not match "FAIR" or "SAID"
- **Title variations** — match both the full title and the slug form (e.g., "Sarah Chen" and "sarah-chen")

## Rules

- Never modify the semantic content of an article — only add link markup
- Never create links to articles that don't exist
- Never link inside frontmatter, code blocks, or existing wikilinks
- This operation is idempotent — running it twice produces the same result
- Cross-linking runs as part of the compile pipeline (after article generation)
- Article versioning is suppressed during cross-link passes (pipeline context) to avoid history noise