{"success":true,"name":"llm-wiki","description":"Karpathy's LLM Wiki: build/query interlinked markdown KB.","category":"research","path":"research/llm-wiki/SKILL.md","file":"SKILL.md","content":"---\nname: llm-wiki\ndescription: \"Karpathy's LLM Wiki: build/query interlinked markdown KB.\"\nversion: 2.1.0\nauthor: Hermes Agent\nlicense: MIT\nplatforms: [linux, macos, windows]\nmetadata:\n  hermes:\n    tags: [wiki, knowledge-base, research, notes, markdown, rag-alternative]\n    category: research\n    related_skills: [obsidian, arxiv]\n---\n\n# Karpathy's LLM Wiki\n\nBuild and maintain a persistent, compounding knowledge base as interlinked markdown files.\nBased on [Andrej Karpathy's LLM Wiki pattern](https://gist.github.com/karpathy/442a6bf555914893e9891c11519de94f).\n\nUnlike traditional RAG (which rediscovers knowledge from scratch per query), the wiki\ncompiles knowledge once and keeps it current. Cross-references are already there.\nContradictions have already been flagged. Synthesis reflects everything ingested.\n\n**Division of labor:** The human curates sources and directs analysis. The agent\nsummarizes, cross-references, files, and maintains consistency.\n\n## When This Skill Activates\n\nUse this skill when the user:\n- Asks to create, build, or start a wiki or knowledge base\n- Asks to ingest, add, or process a source into their wiki\n- Asks a question and an existing wiki is present at the configured path\n- Asks to lint, audit, or health-check their wiki\n- References their wiki, knowledge base, or \"notes\" in a research context\n\n## Wiki Location\n\n**Location:** Set via `WIKI_PATH` environment variable (e.g. in `${HERMES_HOME:-~/.hermes}/.env`).\n\nIf unset, defaults to `~/wiki`.\n\n```bash\nWIKI=\"${WIKI_PATH:-$HOME/wiki}\"\n```\n\nThe wiki is just a directory of markdown files — open it in Obsidian, VS Code, or\nany editor. No database, no special tooling required.\n\n## Architecture: Three Layers\n\n```\nwiki/\n├── SCHEMA.md           # Conventions, structure rules, domain config\n├── index.md            # Sectioned content catalog with one-line summaries\n├── log.md              # Chronological action log (append-only, rotated yearly)\n├── raw/                # Layer 1: Immutable source material\n│   ├── articles/       # Web articles, clippings\n│   ├── papers/         # PDFs, arxiv papers\n│   ├── transcripts/    # Meeting notes, interviews\n│   └── assets/         # Images, diagrams referenced by sources\n├── entities/           # Layer 2: Entity pages (people, orgs, products, models)\n├── concepts/           # Layer 2: Concept/topic pages\n├── comparisons/        # Layer 2: Side-by-side analyses\n└── queries/            # Layer 2: Filed query results worth keeping\n```\n\n**Layer 1 — Raw Sources:** Immutable. The agent reads but never modifies these.\n**Layer 2 — The Wiki:** Agent-owned markdown files. Created, updated, and\ncross-referenced by the agent.\n**Layer 3 — The Schema:** `SCHEMA.md` defines structure, conventions, and tag taxonomy.\n\n## Resuming an Existing Wiki (CRITICAL — do this every session)\n\nWhen the user has an existing wiki, **always orient yourself before doing anything**:\n\n① **Read `SCHEMA.md`** — understand the domain, conventions, and tag taxonomy.\n② **Read `index.md`** — learn what pages exist and their summaries.\n③ **Scan recent `log.md`** — read the last 20-30 entries to understand recent activity.\n\n```bash\nWIKI=\"${WIKI_PATH:-$HOME/wiki}\"\n# Orientation reads at session start\nread_file \"$WIKI/SCHEMA.md\"\nread_file \"$WIKI/index.md\"\nread_file \"$WIKI/log.md\" offset=<last 30 lines>\n```\n\nOnly after orientation should you ingest, query, or lint. This prevents:\n- Creating duplicate pages for entities that already exist\n- Missing cross-references to existing content\n- Contradicting the schema's conventions\n- Repeating work already logged\n\nFor large wikis (100+ pages), also run a quick `search_files` for the topic\nat hand before creating anything new.\n\n## Initializing a New Wiki\n\nWhen the user asks to create or start a wiki:\n\n1. Determine the wiki path (from `$WIKI_PATH` env var, or ask the user; default `~/wiki`)\n2. Create the directory structure above\n3. Ask the user what domain the wiki covers — be specific\n4. Write `SCHEMA.md` customized to the domain (see template below)\n5. Write initial `index.md` with sectioned header\n6. Write initial `log.md` with creation entry\n7. Confirm the wiki is ready and suggest first sources to ingest\n\n### SCHEMA.md Template\n\nAdapt to the user's domain. The schema constrains agent behavior and ensures consistency:\n\n```markdown\n# Wiki Schema\n\n## Domain\n[What this wiki covers — e.g., \"AI/ML research\", \"personal health\", \"startup intelligence\"]\n\n## Conventions\n- File names: lowercase, hyphens, no spaces (e.g., `transformer-architecture.md`)\n- Every wiki page starts with YAML frontmatter (see below)\n- Use `[[wikilinks]]` to link between pages (minimum 2 outbound links per page)\n- When updating a page, always bump the `updated` date\n- Every new page must be added to `index.md` under the correct section\n- Every action must be appended to `log.md`\n- **Provenance markers:** On pages that synthesize 3+ sources, append `^[raw/articles/source-file.md]`\n  at the end of paragraphs whose claims come from a specific source. This lets a reader trace each\n  claim back without re-reading the whole raw file. Optional on single-source pages where the\n  `sources:` frontmatter is enough.\n\n## Frontmatter\n  ```yaml\n  ---\n  title: Page Title\n  created: YYYY-MM-DD\n  updated: YYYY-MM-DD\n  type: entity | concept | comparison | query | summary\n  tags: [from taxonomy below]\n  sources: [raw/articles/source-name.md]\n  # Optional quality signals:\n  confidence: high | medium | low        # how well-supported the claims are\n  contested: true                        # set when the page has unresolved contradictions\n  contradictions: [other-page-slug]      # pages this one conflicts with\n  ---\n  ```\n\n`confidence` and `contested` are optional but recommended for opinion-heavy or fast-moving\ntopics. Lint surfaces `contested: true` and `confidence: low` pages for review so weak claims\ndon't silently harden into accepted wiki fact.\n\n### raw/ Frontmatter\n\nRaw sources ALSO get a small frontmatter block so re-ingests can detect drift:\n\n```yaml\n---\nsource_url: https://example.com/article   # original URL, if applicable\ningested: YYYY-MM-DD\nsha256: <hex digest of the raw content below the frontmatter>\n---\n```\n\nThe `sha256:` lets a future re-ingest of the same URL skip processing when content is unchanged,\nand flag drift when it has changed. Compute over the body only (everything after the closing\n`---`), not the frontmatter itself.\n\n## Tag Taxonomy\n[Define 10-20 top-level tags for the domain. Add new tags here BEFORE using them.]\n\nExample for AI/ML:\n- Models: model, architecture, benchmark, training\n- People/Orgs: person, company, lab, open-source\n- Techniques: optimization, fine-tuning, inference, alignment, data\n- Meta: comparison, timeline, controversy, prediction\n\nRule: every tag on a page must appear in this taxonomy. If a new tag is needed,\nadd it here first, then use it. This prevents tag sprawl.\n\n## Page Thresholds\n- **Create a page** when an entity/concept appears in 2+ sources OR is central to one source\n- **Add to existing page** when a source mentions something already covered\n- **DON'T create a page** for passing mentions, minor details, or things outside the domain\n- **Split a page** when it exceeds ~200 lines — break into sub-topics with cross-links\n- **Archive a page** when its content is fully superseded — move to `_archive/`, remove from index\n\n## Entity Pages\nOne page per notable entity. Include:\n- Overview / what it is\n- Key facts and dates\n- Relationships to other entities ([[wikilinks]])\n- Source references\n\n## Concept Pages\nOne page per concept or topic. Include:\n- Definition / explanation\n- Current state of knowledge\n- Open questions or debates\n- Related concepts ([[wikilinks]])\n\n## Comparison Pages\nSide-by-side analyses. Include:\n- What is being compared and why\n- Dimensions of comparison (table format preferred)\n- Verdict or synthesis\n- Sources\n\n## Update Policy\nWhen new information conflicts with existing content:\n1. Check the dates — newer sources generally supersede older ones\n2. If genuinely contradictory, note both positions with dates and sources\n3. Mark the contradiction in frontmatter: `contradictions: [page-name]`\n4. Flag for user review in the lint report\n```\n\n### index.md Template\n\nThe index is sectioned by type. Each entry is one line: wikilink + summary.\n\n```markdown\n# Wiki Index\n\n> Content catalog. Every wiki page listed under its type with a one-line summary.\n> Read this first to find relevant pages for any query.\n> Last updated: YYYY-MM-DD | Total pages: N\n\n## Entities\n<!-- Alphabetical within section -->\n\n## Concepts\n\n## Comparisons\n\n## Queries\n```\n\n**Scaling rule:** When any section exceeds 50 entries, split it into sub-sections\nby first letter or sub-domain. When the index exceeds 200 entries total, create\na `_meta/topic-map.md` that groups pages by theme for faster navigation.\n\n### log.md Template\n\n```markdown\n# Wiki Log\n\n> Chronological record of all wiki actions. Append-only.\n> Format: `## [YYYY-MM-DD] action | subject`\n> Actions: ingest, update, query, lint, create, archive, delete\n> When this file exceeds 500 entries, rotate: rename to log-YYYY.md, start fresh.\n\n## [YYYY-MM-DD] create | Wiki initialized\n- Domain: [domain]\n- Structure created with SCHEMA.md, index.md, log.md\n```\n\n## Core Operations\n\n### 1. Ingest\n\nWhen the user provides a source (URL, file, paste), integrate it into the wiki:\n\n① **Capture the raw source:**\n   - URL → use `web_extract` to get markdown, save to `raw/articles/`\n   - PDF → use `web_extract` (handles PDFs), save to `raw/papers/`\n   - Pasted text → save to appropriate `raw/` subdirectory\n   - Name the file descriptively: `raw/articles/karpathy-llm-wiki-2026.md`\n   - **Add raw frontmatter** (`source_url`, `ingested`, `sha256` of the body).\n     On re-ingest of the same URL: recompute the sha256, compare to the stored value —\n     skip if identical, flag drift and update if different. This is cheap enough to\n     do on every re-ingest and catches silent source changes.\n\n② **Discuss takeaways** with the user — what's interesting, what matters for\n   the domain. (Skip this in automated/cron contexts — proceed directly.)\n\n③ **Check what already exists** — search index.md and use `search_files` to find\n   existing pages for mentioned entities/concepts. This is the difference between\n   a growing wiki and a pile of duplicates.\n\n④ **Write or update wiki pages:**\n   - **New entities/concepts:** Create pages only if they meet the Page Thresholds\n     in SCHEMA.md (2+ source mentions, or central to one source)\n   - **Existing pages:** Add new information, update facts, bump `updated` date.\n     When new info contradicts existing content, follow the Update Policy.\n   - **Cross-reference:** Every new or updated page must link to at least 2 other\n     pages via `[[wikilinks]]`. Check that existing pages link back.\n   - **Tags:** Only use tags from the taxonomy in SCHEMA.md\n   - **Provenance:** On pages synthesizing 3+ sources, append `^[raw/articles/source.md]`\n     markers to paragraphs whose claims trace to a specific source.\n   - **Confidence:** For opinion-heavy, fast-moving, or single-source claims, set\n     `confidence: medium` or `low` in frontmatter. Don't mark `high` unless the\n     claim is well-supported across multiple sources.\n\n⑤ **Update navigation:**\n   - Add new pages to `index.md` under the correct section, alphabetically\n   - Update the \"Total pages\" count and \"Last updated\" date in index header\n   - Append to `log.md`: `## [YYYY-MM-DD] ingest | Source Title`\n   - List every file created or updated in the log entry\n\n⑥ **Report what changed** — list every file created or updated to the user.\n\nA single source can trigger updates across 5-15 wiki pages. This is normal\nand desired — it's the compounding effect.\n\n### 2. Query\n\nWhen the user asks a question about the wiki's domain:\n\n① **Read `index.md`** to identify relevant pages.\n② **For wikis with 100+ pages**, also `search_files` across all `.md` files\n   for key terms — the index alone may miss relevant content.\n③ **Read the relevant pages** using `read_file`.\n④ **Synthesize an answer** from the compiled knowledge. Cite the wiki pages\n   you drew from: \"Based on [[page-a]] and [[page-b]]...\"\n⑤ **File valuable answers back** — if the answer is a substantial comparison,\n   deep dive, or novel synthesis, create a page in `queries/` or `comparisons/`.\n   Don't file trivial lookups — only answers that would be painful to re-derive.\n⑥ **Update log.md** with the query and whether it was filed.\n\n### 3. Lint\n\nWhen the user asks to lint, health-check, or audit the wiki:\n\n① **Orphan pages:** Find pages with no inbound `[[wikilinks]]` from other pages.\n```python\n# Use execute_code for this — programmatic scan across all wiki pages\nimport os, re\nfrom collections import defaultdict\nwiki = \"<WIKI_PATH>\"\n# Scan all .md files in entities/, concepts/, comparisons/, queries/\n# Extract all [[wikilinks]] — build inbound link map\n# Pages with zero inbound links are orphans\n```\n\n② **Broken wikilinks:** Find `[[links]]` that point to pages that don't exist.\n\n③ **Index completeness:** Every wiki page should appear in `index.md`. Compare\n   the filesystem against index entries.\n\n④ **Frontmatter validation:** Every wiki page must have all required fields\n   (title, created, updated, type, tags, sources). Tags must be in the taxonomy.\n\n⑤ **Stale content:** Pages whose `updated` date is >90 days older than the most\n   recent source that mentions the same entities.\n\n⑥ **Contradictions:** Pages on the same topic with conflicting claims. Look for\n   pages that share tags/entities but state different facts. Surface all pages\n   with `contested: true` or `contradictions:` frontmatter for user review.\n\n⑦ **Quality signals:** List pages with `confidence: low` and any page that cites\n   only a single source but has no confidence field set — these are candidates\n   for either finding corroboration or demoting to `confidence: medium`.\n\n⑧ **Source drift:** For each file in `raw/` with a `sha256:` frontmatter, recompute\n   the hash and flag mismatches. Mismatches indicate the raw file was edited\n   (shouldn't happen — raw/ is immutable) or ingested from a URL that has since\n   changed. Not a hard error, but worth reporting.\n\n⑨ **Page size:** Flag pages over 200 lines — candidates for splitting.\n\n⑩ **Tag audit:** List all tags in use, flag any not in the SCHEMA.md taxonomy.\n\n⑪ **Log rotation:** If log.md exceeds 500 entries, rotate it.\n\n⑫ **Report findings** with specific file paths and suggested actions, grouped by\n   severity (broken links > orphans > source drift > contested pages > stale content > style issues).\n\n⑬ **Append to log.md:** `## [YYYY-MM-DD] lint | N issues found`\n\n## Working with the Wiki\n\n### Searching\n\n```bash\n# Find pages by content\nsearch_files \"transformer\" path=\"$WIKI\" file_glob=\"*.md\"\n\n# Find pages by filename\nsearch_files \"*.md\" target=\"files\" path=\"$WIKI\"\n\n# Find pages by tag\nsearch_files \"tags:.*alignment\" path=\"$WIKI\" file_glob=\"*.md\"\n\n# Recent activity\nread_file \"$WIKI/log.md\" offset=<last 20 lines>\n```\n\n### Bulk Ingest\n\nWhen ingesting multiple sources at once, batch the updates:\n1. Read all sources first\n2. Identify all entities and concepts across all sources\n3. Check existing pages for all of them (one search pass, not N)\n4. Create/update pages in one pass (avoids redundant updates)\n5. Update index.md once at the end\n6. Write a single log entry covering the batch\n\n### Archiving\n\nWhen content is fully superseded or the domain scope changes:\n1. Create `_archive/` directory if it doesn't exist\n2. Move the page to `_archive/` with its original path (e.g., `_archive/entities/old-page.md`)\n3. Remove from `index.md`\n4. Update any pages that linked to it — replace wikilink with plain text + \"(archived)\"\n5. Log the archive action\n\n### Obsidian Integration\n\nThe wiki directory works as an Obsidian vault out of the box:\n- `[[wikilinks]]` render as clickable links\n- Graph View visualizes the knowledge network\n- YAML frontmatter powers Dataview queries\n- The `raw/assets/` folder holds images referenced via `![[image.png]]`\n\nFor best results:\n- Set Obsidian's attachment folder to `raw/assets/`\n- Enable \"Wikilinks\" in Obsidian settings (usually on by default)\n- Install Dataview plugin for queries like `TABLE tags FROM \"entities\" WHERE contains(tags, \"company\")`\n\nIf using the Obsidian skill alongside this one, set `OBSIDIAN_VAULT_PATH` to the\nsame directory as the wiki path.\n\n### Obsidian Headless (servers and headless machines)\n\nOn machines without a display, use `obsidian-headless` instead of the desktop app.\nIt syncs vaults via Obsidian Sync without a GUI — perfect for agents running on\nservers that write to the wiki while Obsidian desktop reads it on another device.\n\n**Setup:**\n```bash\n# Requires Node.js 22+\nnpm install -g obsidian-headless\n\n# Login (requires Obsidian account with Sync subscription)\nob login --email <email> --password '<password>'\n\n# Create a remote vault for the wiki\nob sync-create-remote --name \"LLM Wiki\"\n\n# Connect the wiki directory to the vault\ncd ~/wiki\nob sync-setup --vault \"<vault-id>\"\n\n# Initial sync\nob sync\n\n# Continuous sync (foreground — use systemd for background)\nob sync --continuous\n```\n\n**Continuous background sync via systemd:**\n```ini\n# ~/.config/systemd/user/obsidian-wiki-sync.service\n[Unit]\nDescription=Obsidian LLM Wiki Sync\nAfter=network-online.target\nWants=network-online.target\n\n[Service]\nExecStart=/path/to/ob sync --continuous\nWorkingDirectory=%h/wiki\nRestart=on-failure\nRestartSec=10\n\n[Install]\nWantedBy=default.target\n```\n\n```bash\nsystemctl --user daemon-reload\nsystemctl --user enable --now obsidian-wiki-sync\n# Enable linger so sync survives logout:\nsudo loginctl enable-linger $USER\n```\n\nThis lets the agent write to `~/wiki` on a server while you browse the same\nvault in Obsidian on your laptop/phone — changes appear within seconds.\n\n## Pitfalls\n\n- **Never modify files in `raw/`** — sources are immutable. Corrections go in wiki pages.\n- **Always orient first** — read SCHEMA + index + recent log before any operation in a new session.\n  Skipping this causes duplicates and missed cross-references.\n- **Always update index.md and log.md** — skipping this makes the wiki degrade. These are the\n  navigational backbone.\n- **Don't create pages for passing mentions** — follow the Page Thresholds in SCHEMA.md. A name\n  appearing once in a footnote doesn't warrant an entity page.\n- **Don't create pages without cross-references** — isolated pages are invisible. Every page must\n  link to at least 2 other pages.\n- **Frontmatter is required** — it enables search, filtering, and staleness detection.\n- **Tags must come from the taxonomy** — freeform tags decay into noise. Add new tags to SCHEMA.md\n  first, then use them.\n- **Keep pages scannable** — a wiki page should be readable in 30 seconds. Split pages over\n  200 lines. Move detailed analysis to dedicated deep-dive pages.\n- **Ask before mass-updating** — if an ingest would touch 10+ existing pages, confirm\n  the scope with the user first.\n- **Rotate the log** — when log.md exceeds 500 entries, rename it `log-YYYY.md` and start fresh.\n  The agent should check log size during lint.\n- **Handle contradictions explicitly** — don't silently overwrite. Note both claims with dates,\n  mark in frontmatter, flag for user review.\n\n## Related Tools\n\n[llm-wiki-compiler](https://github.com/atomicmemory/llm-wiki-compiler) is a Node.js CLI that\ncompiles sources into a concept wiki with the same Karpathy inspiration. It's Obsidian-compatible,\nso users who want a scheduled/CLI-driven compile pipeline can point it at the same vault this\nskill maintains. Trade-offs: it owns page generation (replaces the agent's judgment on page\ncreation) and is tuned for small corpora. Use this skill when you want agent-in-the-loop curation;\nuse llmwiki when you want batch compile of a source directory.\n","linked_files":[],"origin":"brimind","owner_id":null,"source":"router"}