How atomicmemory/llm-wiki-compiler works
1. What this repo is
- llmwiki is a Node.js/TypeScript CLI that turns raw inputs in sources/ into a persistent markdown wiki in wiki/.
- The architectural center is a compile pipeline, not a live retrieval service: sources are ingested, compiled, queried, and optionally fed back into the wiki.
2. Top-level execution model
- src/cli.ts is the entrypoint, and src/commands/* contains the user-facing verbs: ingest, compile, query, lint, and watch.
- Each command is a thin orchestration layer over shared compiler, provider, and utility modules.
3. Input boundary: source ingestion
- src/ingest/file.ts and src/ingest/web.ts form the boundary where external content enters the system.
- Ingested artifacts are normalized into local source files, with the README noting truncation metadata for oversized inputs so downstream compilation knows content may be partial.
4. Core pipeline: two-phase compilation
- The compiler lives under src/compiler/* and follows a two-phase flow described in the README:
- Phase 1: extract concepts from all changed sources.
- Phase 2: generate wiki pages from the merged concept set.
- This design removes order dependence and allows shared concepts from multiple sources to converge into one page.
5. Change detection and incremental rebuilds
- src/compiler/hasher.ts and src/compiler/deps.ts support incremental compilation by detecting which sources changed and what downstream pages depend on them.
- src/utils/state.ts likely stores compile state between runs, while src/utils/lock.ts suggests the repo prevents concurrent compiles or writes.
- The result is that only changed sources re-enter the LLM-backed part of the pipeline.
6. Concept extraction, resolution, and page generation
- src/compiler/prompts.ts holds the LLM prompts used for extraction and page synthesis.
- src/compiler/resolver.ts and src/compiler/obsidian.ts handle wiki-style linking and Obsidian-compatible page structure.
- src/compiler/orphan.ts indicates the system also tracks unlinked or unused pages, which feeds the lint/health model.
7. Indexing and navigation output
- src/compiler/indexgen.ts generates the wiki index page.
- Output is organized as wiki/concepts/, wiki/queries/, and wiki/index.md, making the compiled artifact browsable as static markdown.
- The README’s [[wikilink]] behavior is part of this output boundary: generated pages are meant to be traversed as an interlinked knowledge base.
8. Query subsystem and compounding knowledge
- src/commands/query.ts routes questions against the compiled wiki, rather than querying raw sources directly.
- --save turns an answer into a new markdown page, which immediately becomes part of the next compile/index pass.
- This creates a feedback loop: query answers are not ephemeral; they become new durable knowledge in wiki/queries/.
9. Linting and quality checks
- src/linter/* implements repository-specific health checks such as broken links, empty pages, and orphans.
- This is a separate validation pass over the compiled wiki, not part of ingestion or query execution.
10. LLM provider boundary
- src/utils/provider.ts plus src/providers/anthropic.ts, openai.ts, and ollama.ts abstract model backends.
- The README says Anthropic is the primary supported path today, but the codebase is already shaped around a provider interface, which keeps the compiler decoupled from any single vendor.
11. Shared utilities and I/O concerns
- src/utils/markdown.ts, output.ts, constants.ts, and types.ts hold common formatting, terminal output, and shared domain types.
- src/utils/llm.ts is the likely shared call layer for prompt execution and response handling.
12. Watch mode and automation
- src/commands/watch.ts wraps the same compile pipeline in filesystem-triggered automation, rebuilding when sources/ changes.
- This is not a separate build system; it is a convenience loop around the same incremental compiler.
13. Repository shape and verification
- examples/basic/ contains a pre-generated wiki that demonstrates the artifact structure without requiring API access.
- test/* is broad and architecture-revealing: there are tests for hashing, resolver behavior, index generation, provider compatibility, ingest truncation, linting, and query save flows.
- That test spread mirrors the main boundaries of the system: ingestion, compilation, linking, query/save, and validation.
Main entry points: index.ts Compiler core · provider.ts Provider API · cli.ts CLI entry · ingest.ts Ingest
Components 29
CLI
User-facing command entrypoints and orchestration.
- CLI entry · Main executable that dispatches subcommands.
src/cli.ts - Ingest · Imports external content into local source files.
src/commands/ingest.ts - Compile · Runs the two-phase wiki compilation pipeline.
src/commands/compile.ts - Query · Answers questions from the compiled wiki and can save results.
src/commands/query.ts - Lint · Checks compiled wiki health and consistency.
src/commands/lint.ts - Watch · Rebuilds automatically when sources change.
src/commands/watch.ts
Pipeline
Core ingest and compile flow that turns sources into wiki pages.
- File ingest · Normalizes local file inputs into repository sources.
src/ingest/file.ts - Web ingest · Fetches and normalizes web content into local sources.
src/ingest/web.ts - Compiler core · Coordinates incremental compilation across the repository.
src/compiler/index.ts - Hasher · Detects changed sources for selective recompilation.
src/compiler/hasher.ts - Deps · Tracks downstream page dependencies for rebuilds.
src/compiler/deps.ts - Prompts · Defines extraction and page-generation prompts.
src/compiler/prompts.ts - Resolver · Resolves concepts and wiki links across pages.
src/compiler/resolver.ts - Obsidian · Builds Obsidian-compatible page structure and links.
src/compiler/obsidian.ts - Index generator · Creates the wiki index page for browseable output.
src/compiler/indexgen.ts - Orphans · Identifies unlinked or unused wiki pages.
src/compiler/orphan.ts
Model I/O
LLM provider abstraction and shared request handling.
- Provider API · Abstracts model backends behind a common interface.
src/utils/provider.ts - Anthropic · Primary model backend implementation.
src/providers/anthropic.ts - OpenAI · OpenAI backend implementation.
src/providers/openai.ts - Ollama · Local model backend implementation.
src/providers/ollama.ts - LLM client · Shared request and response handling for model calls.
src/utils/llm.ts
Validation
Wiki health checks and repository-specific linting.
- Linter core · Runs repository-specific wiki checks.
src/linter/index.ts - Lint rules · Implements checks for links, empty pages, and orphans.
src/linter/rules.ts
Shared
Cross-cutting utilities used by the commands and compiler.
- Markdown · Shared markdown formatting and page helpers.
src/utils/markdown.ts - State · Stores incremental compile state between runs.
src/utils/state.ts - Lock · Prevents overlapping compiles or writes.
src/utils/lock.ts - Output · Centralized user-facing output and status messages.
src/utils/output.ts - Types · Common domain types across the toolchain.
src/utils/types.ts - Constants · Shared constants used throughout the repository.
src/utils/constants.ts
Connections 35
- CLI entry → Ingest: dispatches · CLI routes to ingest commands.
- CLI entry → Compile: dispatches · CLI routes to compile commands.
- CLI entry → Query: dispatches · CLI routes to query commands.
- CLI entry → Lint: dispatches · CLI routes to lint commands.
- CLI entry → Watch: dispatches · CLI routes to watch commands.
- Ingest → File ingest: uses · File ingestion handles local inputs.
- Ingest → Web ingest: uses · Web ingestion handles remote inputs.
- Compile → Compiler core: runs · Compile command invokes the compiler pipeline.
- Query → Compiler core: queries · Query reads from compiled wiki outputs.
- Lint → Linter core: runs · Lint command invokes validation checks.
- Watch → Compiler core: loops · Watch mode repeatedly triggers compilation.
- Compiler core → Hasher: detects changes · Compiler uses hashing to find changed sources.
- Compiler core → Deps: tracks deps · Compiler uses dependency information for rebuilds.
- Compiler core → Prompts: prompts · Compiler uses prompt templates for extraction and synthesis.
- Compiler core → Resolver: resolves links · Compiler normalizes concepts and links.
- Compiler core → Obsidian: writes pages · Compiler emits wiki-compatible markdown pages.
- Compiler core → Index generator: builds index · Compiler generates the wiki index page.
- Compiler core → Orphans: reports orphans · Compiler tracks unused or unlinked pages.
- Compiler core → Provider API: calls model API · Compiler delegates model access through the provider abstraction.
- Provider API → Anthropic: implements · Anthropic is a provider backend.
- Provider API → OpenAI: implements · OpenAI is a provider backend.
- Provider API → Ollama: implements · Ollama is a provider backend.
- Provider API → LLM client: delegates · Provider calls are executed through the shared LLM client.
- Linter core → Lint rules: applies · Linter core runs the rule set.
- Query → Index generator: reads index · Query can use the browsable wiki index as part of the compiled corpus.
- Compile → State: persists state · Compilation writes and reads incremental state.
- Compiler core → Lock: serializes · Compiler uses a lock to prevent concurrent runs.
- Obsidian → Markdown: formats · Wiki page generation relies on markdown helpers.
- Index generator → Markdown: formats · Index generation relies on markdown helpers.
- Ingest → Output: reports · Ingest commands surface status through shared output.
- Compile → Output: reports · Compile commands surface status through shared output.
- Query → Output: reports · Query commands surface status through shared output.
- Linter core → Output: reports · Lint commands surface status through shared output.
- Compiler core → Types: shares types · Compiler components use shared domain types.
- Provider API → Constants: uses · Provider and pipeline code share constants.