Step 1: Parse Arguments
Required:
Optional Flags:
| Flag | Purpose | Default |
|------|---------|---------|
| --dry-run | Show what would be linked without making changes | false |
| --all-worlds | Search all worlds for entities, not just the source entity's world | false |
| --case-sensitive | Require exact case matching | false |
| --world [name] | BULK MODE: Process all entities in the specified world | - |
| --category [type] | With --world: only process entities in this category (Characters, Settlements, etc.) | all |
Step 2: Locate Entity & Determine World
- If path provided (contains
/ or .md):
- Read the file directly
- Extract world name from path: Worlds/[World Name]/...
- If name provided:
- Search Worlds/ directories for matching entity
- Try exact filename match first
- Then fuzzy match on filename and YAML name: field
- If multiple matches, list them and ask user to clarify
- If not found:
- List similar entities and ask for clarification
Step 3: Build Entity Index
Create a complete index of existing entities:
- Scan all files in
Worlds/[World Name]/ recursively (or all worlds if --all-worlds) - For each entity file, extract:
- Filename (without .md extension) β primary name
- YAML name: field β canonical name
- YAML aliases: array β alternative names
- Build lookup dictionary (case-insensitive by default):
```
{
"Lord Varic Valdren": { path: "Characters/Lord Varic Valdren.md", canonical: "Lord Varic Valdren" },
"Varic": { path: "Characters/Lord Varic Valdren.md", canonical: "Lord Varic Valdren" },
"The Merchant Lord": { path: "Characters/Lord Varic Valdren.md", canonical: "Lord Varic Valdren" },
...
}
```
Important: Sort the lookup dictionary by name length (longest first) to ensure longer matches are found before shorter partial matches.
Step 4: Identify Content to Scan
Read the source entity file and identify sections to scan:
INCLUDE these sections:
- Overview
- Geography
- History
- Demographics
- Government & Politics
- Economy
- Defense & Military
- Notable Locations
- Key Figures
- Secrets
- Plot Hooks
- Description
- Any custom content sections
EXCLUDE these sections:
- YAML frontmatter (between
--- markers) - Image Prompts section and everything after it
- Connections section (already has wikilinks)
- Code blocks (between ``` markers)
- Existing wikilinks
[[...]] - Block quotes used for image prompts (lines starting with
> after Prompt:)
Step 5: Find Matches
For each entity name/alias in the index (longest first):
- Skip if entity is the source file itself (don't self-link)
- Search for the name in content:
- Use word-boundary matching to avoid partial matches within words
- Match: "Lord Varic Valdren" in "talked to Lord Varic Valdren about"
- Skip: "Lord Varic Valdren" in "[[Lord Varic Valdren]]" (already linked)
- Skip: "Stone" in "Aldric Stone" if "Aldric Stone" is a separate entity
- Record each match:
- Line number
- Exact text matched
- Canonical entity name (for the wikilink)
- Surrounding context (5 words before/after)
- Handle partial name matches:
- If "Lord Varic Valdren" exists but text says "Lord Varic", offer to link as [[Lord Varic Valdren|Lord Varic]]
- If "House Valdren" exists but text says "the Valdren house", consider display text
Step 6: Present Findings
```
=== LINKIFY ANALYSIS: [Entity Name] ===
World: [World Name]
Source: [path/to/entity.md]
Entities Indexed: X
---
MATCHES FOUND: Y
| # | Text Found | Line | Links To | Context |
|---|------------|------|----------|---------|
| 1 | Lady Serana Valdren | 121 | [[Lady Serana Valdren]] | "...wife, manages court..." |
| 2 | High Confessor Maren | 136 | [[High Confessor Maren]] | "...supporters, seeking..." |
| 3 | Sister Elspeth | 204 | [[Sister Elspeth]] | "...Abbess of the..." |
| 4 | Lord Varic | 117 | [[Lord Varic Valdren|Lord Varic]] | "...ensuring Varic holds..." |
---
PARTIAL MATCHES (display text needed):
| # | Text Found | Line | Suggested Link |
|---|------------|------|----------------|
| 1 | "the Owl" | 123 | [[The Owl|the Owl]] |
| 2 | "young Edric" | 117, 177 | [[Edric Valdren|young Edric]] |
---
AMBIGUOUS (multiple possible matches):
| # | Text Found | Line | Could Match |
|---|------------|------|-------------|
| 1 | "Edric" | 177 | [[Edric Valdren]] or [[Prince Edric the Liberator]] |
---
SUMMARY:
- Exact matches: X
- Partial matches: X
- Ambiguous: X
- Total changes: X
Options:
- Apply all exact matches
- Apply exact + partial matches
- Review each individually
- Dry run complete (--dry-run flag)
```
If --dry-run flag is set, show report and stop.
Step 7: Apply Changes
For each approved match:
- Build replacement text:
- Exact match: EntityName β [[EntityName]]
- Partial match: PartialName β [[FullEntityName|PartialName]]
- Apply using Edit tool:
- Process from bottom of file to top (so line numbers don't shift)
- Use precise string replacement with surrounding context for uniqueness
- Verify each replacement succeeded
- Handle duplicates:
- If the same entity is mentioned multiple times, link ALL occurrences
- Exception: Don't link the same name twice in the same sentence
Step 8: Validation
After applying changes:
- Re-read the file
- Verify all intended wikilinks are present
- Check no content was accidentally corrupted
- Verify wikilinks point to existing files
Step 9: Summary Report
```
=== LINKIFY COMPLETE: [Entity Name] ===
Changes Applied: X
Links Added:
- [[Lady Serana Valdren]] (line 121)
- [[High Confessor Maren]] (line 136)
- [[Sister Elspeth]] (lines 204, 252)
- [[Lord Varic Valdren|Lord Varic]] (line 117)
Skipped (ambiguous):
- "Edric" (line 177) - multiple matches possible
---
File Updated: [path/to/entity.md]
Suggested Next Steps:
- Review ambiguous matches manually
- Run /audit-world to check bidirectional links
- Use /link-entities to add reciprocal connections
```