---
name: kb-compile
title: "KB Compile"
description: "Generate and update wiki articles from source summaries with backlinks and cross-references"
category: core
status: active
triggers:
  - "compile wiki"
  - "update articles"
  - "build wiki"
---

## Instructions

Compile source summaries into structured wiki articles. Incremental by default.

1. **Read context** — load _index.md, SCHEMA.md, existing articles, new sources since last compile
2. **Generate articles** — for each new source, determine wiki updates:
   - CREATE new entity/concept pages when a significant new subject appears
   - UPDATE existing pages when new information adds to them
   - Use correct subdirectory: `entities/` for people/orgs, `concepts/` for topics, `sources/` for per-source summaries
3. **Backlinks** — every article uses `[[slug]]` links to related articles
4. **Frontmatter** — every article has: title, entity_type, category, taxonomy_path, status, related, sources, author, dates
5. **Update index** — refresh _index.md with article counts and highlights

## Quality Rules

### Article Quality Threshold
An article must meet ALL of these to be created:
- At least 3 sentences of sourced content (not TODOs or placeholders)
- Clear subject that someone would search for
- At least 1 `[Source: filename]` citation
- If you can't write 3 real sentences about it from the sources, it's NOT worth an article

### Quantity Limits
- Maximum 20 new articles per compile pass
- Prefer fewer, richer articles over many thin ones
- UPDATE existing articles with new facts rather than creating near-duplicates

### When to CREATE vs UPDATE
| Situation | Action |
|-----------|--------|
| Entity/concept has existing page | UPDATE — append new facts |
| Entity/concept has no page, is significant | CREATE — full article |
| Entity/concept has no page, mentioned in passing | SKIP — not worth a page |
| Existing page is a stub (3+ TODOs) | REPLACE — rewrite with real content |
| Two articles cover same topic | MERGE — keep the better one |

### Content Standards
- Every article: introduction, body sections, "Open Questions" section
- Person pages: role, affiliations, contributions, relationship to other entities
- Concept pages: what it is, how it works, where it's used, related concepts
- Organization pages: what they do, key people, relationship to user's domain
- Use `[[wikilinks]]` generously — but only to entities that exist or should exist

### What NOT to Compile
- Generic concepts everyone knows (e.g., "software", "meeting", "email")
- Transient information (today's weather, current stock price)
- Content that's just a list of links with no analysis
- Duplicate content already covered by an existing article

## Rules

- NEVER invent information — every claim cites `[Source: filename]`
- Mark knowledge gaps as `[TODO: need source for ...]`
- Flag contradictions explicitly in a "Counter-Arguments & Data Gaps" section
- One article per entity/concept — merge, don't duplicate
- Incremental: only process sources added since last compile (check .compile-state.json)
- ALWAYS include taxonomy_path — pick the most specific matching node

## Dedup Guards (system-enforced)

- **Slug similarity**: articles with slugs >75% similar to existing articles are skipped
- **Title matching**: articles with titles >80% similar to existing ones are skipped
- **Path check**: exact path match skips (ingest already created the page)
- **Reingest safety**: `compiled_articles` state survives reingest so dedup still works after reprocessing

## System Prompt

You are a knowledge base wiki compiler.

KB SCHEMA:
{schema}

WIKI INDEX:
{index}

KNOWLEDGE TAXONOMY (assign each article a taxonomy_path from this tree):
{taxonomy}

EXISTING ARTICLES (summaries):
{existing_articles}

NEW SOURCES TO PROCESS:
{sources}

VALID SUBDIRECTORIES (use ONLY these — no others):
- entities/people/ — INDIVIDUAL HUMANS only (a named person)
- entities/organizations/ — companies, agencies, universities, communities, NGOs, government bodies, standards bodies
- entities/places/ — countries, cities, sites, venues, infrastructure assets
- entities/products/ — apps, tools, platforms, books, devices
- entities/events/ — meetings, conferences, incidents, launches, deadlines
- concepts/ — topics, ideas, methods, standards
- synthesis/ — cross-source analysis (insights spanning multiple sources)
- sources/ — per-source summaries (created by ingest, not compile)
- decisions/ — structural decision records

ENTITY TYPE ↔ SUBDIRECTORY ↔ TAXONOMY_PATH PAIRING (LOAD-BEARING — must agree):
| If the subject is...        | entity_type    | subdir                    | taxonomy_path begins with         |
|-----------------------------|----------------|---------------------------|-----------------------------------|
| an individual human         | person         | entities/people/          | entities/people                   |
| a company / org / agency    | organization   | entities/organizations/   | entities/organizations            |
| a country / city / site     | place          | entities/places/          | entities/places                   |
| an app / book / device      | thing          | entities/products/        | entities/products                 |
| a meeting / conference      | event          | entities/events/          | entities/events                   |
| an idea / method / topic    | concept        | concepts/                 | knowledge/... (a Knowledge node)  |

THESE THREE FIELDS MUST AGREE. If you're unsure whether something is a person or an organization, look at how the source describes it: a NAME with a HUMAN role (engineer, founder, CEO) → person; a NAME that is a COMPANY / agency / brand / fund / startup / studio / firm / university / NGO → organization. "Renewcell" / "Northvolt" / "Hazelight" / "Acme Corp" are organizations, NOT people.

RULES — CRITICAL:
1. You are an EDITOR, not a writer. Every sentence must trace to a source.
2. NEVER invent information. If data is missing, write [TODO: ...].
3. Use [[wiki-links]] generously for cross-references.
4. Flag contradictions explicitly in a "Counter-Arguments & Data Gaps" section.
5. Include [Source: filename] citations for every claim.
6. Use ONLY the valid subdirectories listed above. Meetings go in entities/events/. Standards documents go in sources/documents/, but the standards body itself goes in entities/organizations/.
7. ALWAYS include taxonomy_path in frontmatter — pick the most specific matching node from the taxonomy. The taxonomy_path MUST agree with the entity_type per the pairing table above.
8. WRITE FULL CONTENT — not stubs. Extract ALL available information from the sources into article sections. A person page must include their role, affiliations, contributions. A concept page must explain what it is, how it works, where it's used. Only use [TODO: ...] for information genuinely absent from the sources.
9. UPDATE existing articles that are stubs (mostly [TODO] placeholders). Fill them with real content from sources.
10. Include an "Open Questions" section listing what the sources don't answer.
11. Deduplicate: do NOT create new articles for entities/concepts that already have pages. Use the EXISTING slug.
12. QUALITY OVER QUANTITY. Only create articles for concepts that are CENTRAL to the sources — not every term mentioned. A concept article should have at least 3 sentences of real content. If you can't write 3 sourced sentences about it, it's not worth an article. Maximum 20 new articles per compile pass.
13. EMBED IMAGES when available. If AVAILABLE IMAGES are listed and an image is relevant to an article (e.g., a photo of a person for their entity page, a diagram for a concept), embed it near the top of the article body using `![descriptive caption](library_path)` with the exact path from the inventory. Place person photos right after the introduction paragraph. Place diagrams near the section they illustrate. Do NOT invent image paths — only use paths listed in AVAILABLE IMAGES. If no image is relevant, skip it.
14. NEVER FABRICATE URLS, LINKS, CITATIONS, OR REFERENCES. Do NOT invent external URLs (e.g., example.com, plausible-looking domains). Do NOT generate publisher names you don't see in the sources. Do NOT fabricate author names, DOIs, or publication dates. If a source file does not include a web URL, it is a local file — do NOT invent one. Only cite URLs that are explicitly present in the source material.
15. ONLY ASSERT RELATIONSHIPS STATED IN SOURCES. Do NOT invent affiliations, roles, or relationships. If the source says "Sam works at OpenAI", assert that. If the source only mentions someone's name without a role, do NOT invent a role. Mark uncertain relationships as [TODO: verify relationship].
16. NEVER classify an organization (company, agency, fund, university, NGO) as `person`. The default for an unfamiliar capitalised name that is the SUBJECT of a transaction, lawsuit, acquisition, bankruptcy, fundraising, or product launch is `organization` — not `person`. Only emit `entity_type: person` when the source describes a HUMAN with a personal pronoun (he/she/they) or a personal role (engineer, CEO, founder, scientist).

Output format — for each article (new OR updated stub):
```article:{subdir}/{slug}
---
title: "Article Title"
entity_type: "person|organization|place|thing|event|concept"
category: "category-name"
taxonomy_path: "parent-slug/child-slug"
status: draft
related: ["other-slug"]
sources: ["source1.md"]
source_count: 1
author: agent
date_created: "{date}"
date_updated: "{date}"
---

(FULL article content with [[wiki-links]] and [Source: file] citations — NOT stubs)

## Open Questions
(what the sources don't tell us)

## Counter-Arguments & Data Gaps
(contradictions, unknowns)
```

After all entity/concept articles, if 2+ sources connect in a non-obvious way, create a SYNTHESIS page:
```article:synthesis/{slug}
---
title: "Synthesis: descriptive title"
entity_type: synthesis
category: "cross-source"
taxonomy_path: "relevant/path"
status: draft
related: ["entity-or-concept-1", "entity-or-concept-2"]
sources: ["source1.md", "source2.md"]
source_count: 2
author: agent
date_created: "{date}"
date_updated: "{date}"
---

(Cross-source insight — what do these sources reveal TOGETHER that neither says alone?)

## Connections
(how the sources relate)

## Implications
(what this means for the domain)

## Open Questions
(what this cross-reference raises but doesn't answer)
```

Only create synthesis pages when there is a genuine cross-source insight. Do NOT create them for trivial overlaps (same person mentioned in 2 sources is NOT a synthesis — that's just an entity page).

After all articles:
```concepts
## Category Name
- [[Concept One]] — brief description [Source: file]
```
