Knowledge Compiler is a local-first tool for turning source material into structured, durable Markdown knowledge artifacts.
It keeps raw inputs and compiled topics in a local vault, uses OpenAI structured generation to classify and synthesize material, and exposes Bun-powered CLI commands for seeding, compiling, and asking questions over the compiled knowledge base.
The project has an end-to-end local wiki workflow:
- Seed a raw note from a question.
- Compile raw Markdown sources into topic pages.
- Repair and validate generated topic links and frontmatter.
- Regenerate the wiki index and append compile/ask/memory events to the log.
- Ask questions using selected compiled topic pages as context.
- Optionally save durable answers back into raw sources and recompile the topic.
This is still early software. The workflow is intentionally small, local, and file-based while the project boundaries settle.
- Bun
- An OpenAI API key
Install dependencies:
bun installCreate a .env file:
OPENAI_API_KEY=your_api_key
KNOWLEDGE_VAULT_PATH=/absolute/path/to/your/knowledge-vaultKNOWLEDGE_VAULT_PATH is optional. If it is not set, the app uses ~/knowledge-vault.
Optional:
OPENAI_BASE_URL=https://your-compatible-openai-endpoint.exampleSeed a raw source note from a question:
bun run seed "How does consistent hashing work?"Compile all raw sources into topic pages:
bun run compileCompile a specific domain/topic:
bun run compile --domain "System Design" --topic "Consistent Hashing"Ask a question over compiled topics:
bun run ask "When should I use consistent hashing?"Check vault quality:
bun run checkRepair legacy vault issues without writing changes:
bun run doctor --dry-runApply safe deterministic vault repairs:
bun run doctor --applyRun the yargs-based command shell:
bun run cli replRun the test suite:
bun testKnowledge Compiler reads and writes Markdown files inside the configured vault.
knowledge-vault/
00-raw/
consistent-hashing.md
answers/
when-to-use-consistent-hashing.md
04-topics/
index.md
log.md
System Design/
consistent-hashing.md
Raw source files must include frontmatter that matches the ingest schema:
---
title: Consistent Hashing
domain: System Design
topic: Consistent Hashing
tags:
- distributed-systems
source_type: note
source_url: https://example.com/optional-source
---
Your raw source material goes here.Compiled topic pages include structured sections such as summary, key concepts, deep dives, related topics, open questions, and sources.
Generated topics are repaired and validated before they are written. Validation errors block new compiled output when required sections, frontmatter, source counts, or Obsidian links are structurally wrong.
bun run check scans existing compiled topics and reports:
- ERROR: structural problems that can break traceability or retrieval, such as bad source links, bad related links, missing source links, and source count mismatches.
- WARNING: quality signals that are useful but not blocking, such as orphan topics, weak summaries, broken legacy source paths, or duplicate raw source titles.
bun run doctor --apply fixes safe legacy issues deterministically, without asking the LLM to rewrite note content.
The main flow is intentionally layered:
- CLI entry points in
src/cli/and local scripts inscripts/receive user commands. - Core use cases in
src/core/coordinate classification, compiling, repair, validation, answering, retrieval, and answer memory. - Ingest code in
src/ingest/reads raw Markdown sources from the vault. - LLM code in
src/llm/owns OpenAI client access, structured output, metadata-rich topic selection, contextual answering, and answer-memory decisions. - Render code in
src/render/converts structured knowledge into Markdown plus frontmatter and Obsidian links. - Storage code in
src/storage/reads compiled topics, validates topic quality, and writes topic pages, answer memories, the wiki index, and the wiki log. - Schema code in
src/schema/defines the structured knowledge shape expected from the LLM.
CLI/scripts
-> core
-> ingest
-> llm
-> render
-> storage
-> local knowledge vault
knowledge-compiler/
src/
cli/ command-line entry points and argument handling
config/ environment and runtime configuration
core/ compiler use cases and domain orchestration
ingest/ source adapters and input normalization
llm/ AI provider boundary and structured generation
pipeline/ placeholder for composable workflow stages
render/ Markdown and metadata rendering
schema/ structured knowledge schemas
storage/ filesystem and vault persistence
tests/
unit/ isolated module tests
scripts/ local development and maintenance scripts
docs/ decisions, plans, and reference notes
Each implementation folder has its own README with function-level details:
src/core/README.mddocuments orchestration functions such ascompileTopic,askQuestion, andaskQuestionWithAutoCompile.src/llm/README.mddocuments LLM boundaries such ascallStructured,answerWithContext,selectTopicsFromIndex, anddecideAnswerMemory.src/storage/README.mddocuments filesystem and quality functions such asresolveTopicDomainPath,readCompiledTopics,writeAnswerMemory,regenerateWikiIndex,appendWikiLogEntry, and topic validation helpers.src/ingest/README.md,src/render/README.md,src/config/README.md, andsrc/schema/README.mddocument schemas, helpers, and rendering/config behavior.scripts/README.mddocuments raw seed creation helpers and vault maintenance scripts.tests/README.mddocuments test helpers and module coverage.
Implementation happens incrementally:
- Keep the core workflow small and testable.
- Add tests around behavior before expanding capabilities.
- Preserve clear module boundaries between CLI, core orchestration, storage, rendering, ingest, and LLM access.
- Document design decisions as the structure evolves.
- LLM calls currently use
gpt-5-mini. - Raw sources are scanned from
00-raw. - Compiled topics are written under
04-topics. - Answer memories are written under
00-raw/answers. - Compile automatically repairs rendered links and validates the topic before writing.
- Retrieval selection uses the wiki index plus compiled topic metadata such as summary, tags, related topics, and source paths.
- The project uses path aliases from
tsconfig.json, with@/*mapped tosrc/*.