llm-wiki-compiler 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,10 +6,24 @@ Inspired by Karpathy's [LLM Wiki](https://gist.github.com/karpathy/442a6bf555914
6
6
 
7
7
  ![llmwiki demo](docs/images/demo.gif)
8
8
 
9
+ ## What you get
10
+
11
+ - **Compiled wiki, not chunks.** A two-phase LLM pipeline turns raw sources into typed pages (`concept`, `entity`, `comparison`, `overview`) with paragraph- and claim-level citations back to source line ranges.
12
+ - **Hybrid retrieval.** Semantic chunk embeddings (incremental, content-hash-aware) narrow hundreds of pages to a small top-K; BM25 reranking and wikilink-graph expansion build the final evidence pack.
13
+ - **Local web viewer.** `llmwiki view` opens a read-only browser UI with sidebar navigation, search, a force-directed graph, and provenance/citation chips per page.
14
+ - **Eval harness.** `llmwiki eval` measures health score (0–100), citation coverage and precision, optional LLM-as-judge support scoring, regression deltas, and CI-gateable thresholds.
15
+ - **Source freshness.** `llmwiki lint` flags pages whose sources changed (`stale`) or were deleted (`orphaned`) since the last compile — surfaced across the viewer, MCP, context packs, the JSON export, and `llmwiki next` — and `llmwiki refresh --stale` repairs them with a targeted recompile.
16
+ - **MCP server.** `llmwiki serve` exposes the full pipeline to Claude Desktop, Cursor, Claude Code, and any MCP-compatible agent — including `get_context_pack` for budgeted, citation-aware evidence packs.
17
+ - **In-process SDK.** `createWiki({ root })` drives the whole pipeline programmatically — ingest, compile, query, status/freshness, context packs, export, eval — for embedding llmwiki in your own tooling without shelling out.
18
+ - **Activity journal.** Every ingest, compile, and query appends a timestamped, machine-parseable entry to `log.md` — a human- and agent-readable audit trail of how the wiki was built, carrying page wikilinks and counts.
19
+ - **Bridge to runtime memory.** `llmwiki export --target json --project-id <id>` produces a typed envelope that [`@atomicmemory/llmwiki`](https://github.com/atomicstrata/atomicmemory/tree/main/packages/llmwiki) imports as one verbatim Atomic Memory record per page, preserving all advisory metadata.
20
+ - **Provider-portable.** Anthropic, Claude Agent SDK (local Claude Code login, no API key), OpenAI-compatible (incl. local llama.cpp / vLLM), Ollama, GitHub Copilot.
21
+
9
22
  ## Who this is for
10
23
 
11
- - **AI researchers and engineers** building persistent knowledge from papers, docs, and notes
24
+ - **AI researchers and engineers** building durable knowledge from papers, docs, and notes
12
25
  - **Technical writers** compiling scattered sources into a structured, interlinked reference
26
+ - **Open-source maintainers** turning READMEs, ADRs, and design docs into a navigable knowledge base
13
27
  - **Anyone with too many bookmarks** who wants a wiki instead of a graveyard of tabs
14
28
 
15
29
  ## Quick start
@@ -22,12 +36,13 @@ export ANTHROPIC_API_KEY=sk-...
22
36
  # export LLMWIKI_PROVIDER=openai
23
37
  # export OPENAI_API_KEY=sk-...
24
38
 
25
- llmwiki ingest https://some-article.com
26
- llmwiki compile
39
+ llmwiki quickstart ./notes.md
27
40
  llmwiki query "what is X?"
28
41
  llmwiki view --open
29
42
  ```
30
43
 
44
+ `llmwiki quickstart ./notes.md` ingests one supported source, compiles the wiki, and opens the local viewer when pages are ready. Use `--no-open` to stop after compile, `--review` to queue candidates instead of writing pages, or `--json` for an agent-friendly envelope. If you're inside an existing project and unsure what to do next, run `llmwiki next`.
45
+
31
46
 
32
47
  <br>
33
48
 
@@ -77,6 +92,43 @@ Example with zero exports (Claude Code already configured):
77
92
  llmwiki compile
78
93
  ```
79
94
 
95
+ ### Claude Agent SDK (local Claude Code login)
96
+
97
+ The `claude-agent` provider routes calls through the
98
+ [Claude Agent SDK](https://github.com/anthropics/claude-agent-sdk-typescript)
99
+ instead of the raw Messages API. It authenticates with your **local Claude Code
100
+ login** (OAuth/subscription), so **no `ANTHROPIC_API_KEY` is required** — if you
101
+ can run `claude` in your terminal, this provider works.
102
+
103
+ > **Terms of use.** This provider drives your Claude Code / Agent SDK session
104
+ > programmatically to compile wikis. That is not automatically appropriate for
105
+ > every account type, plan, or environment. Before using it, review Anthropic's
106
+ > current [Claude Code](https://www.anthropic.com/legal/consumer-terms) and
107
+ > [Agent SDK](https://docs.anthropic.com/en/api/agent-sdk/overview) terms and
108
+ > usage policies, and make sure your intended use complies with them.
109
+
110
+ ```bash
111
+ export LLMWIKI_PROVIDER=claude-agent
112
+ export LLMWIKI_MODEL=claude-sonnet-4-6 # optional; this is the default
113
+ llmwiki compile
114
+ ```
115
+
116
+ Notes:
117
+
118
+ - Generation (`compile`) and structured extraction work off the local login with
119
+ no extra credentials.
120
+ - Semantic search (`llmwiki query`) still needs embeddings, which Claude does not
121
+ provide. Set `VOYAGE_API_KEY` to enable them (same as the `anthropic`
122
+ provider); otherwise `query` falls back to lexical ranking.
123
+ - To see what the SDK is doing, set `LLMWIKI_DEBUG=1` for a concise one-line trace
124
+ per SDK message (`[claude-agent] system:init`, `… assistant`, `… result:success`)
125
+ plus any `claude` subprocess errors. Use `LLMWIKI_DEBUG=verbose` to additionally
126
+ enable the SDK's full verbose logging.
127
+
128
+ ```bash
129
+ LLMWIKI_DEBUG=1 LLMWIKI_PROVIDER=claude-agent llmwiki compile
130
+ ```
131
+
80
132
  ### OpenAI-Compatible Local Servers
81
133
 
82
134
  Use the OpenAI provider for local OpenAI-compatible servers such as
@@ -179,28 +231,46 @@ A truncation warning prints to stderr when the cap fires so you know which conce
179
231
  <br>
180
232
 
181
233
 
182
- ## Why not just RAG?
234
+ ## Why compile, not just retrieve?
183
235
 
184
- RAG retrieves chunks at query time. Every question re-discovers the same relationships from scratch. Nothing accumulates.
236
+ llmwiki uses embeddings chunk-level, incremental, with BM25 reranking. But the embedding layer sits **below** the compiled wiki, not in front of it.
185
237
 
186
- llmwiki **compiles** your sources into a wiki. Concepts get their own pages. Pages link to each other. When you ask a question with `--save`, the answer becomes a new page, and future queries use it as context. Your explorations compound.
238
+ **RAG retrieves chunks at query time.** Every question re-discovers the same relationships from scratch. The wiki structure, citation graph, and merged-concept disambiguation never accumulate; they get re-invented per query.
187
239
 
188
- This is complementary to RAG, not a replacement. RAG is great for ad-hoc retrieval over large corpora. llmwiki gives you a persistent, structured artifact to retrieve from.
240
+ **llmwiki compiles your sources into a wiki first.** Concepts get their own typed pages. Concepts shared across multiple sources are merged into one page instead of competing as duplicate chunks. Pages link to each other via `[[wikilinks]]`. When you ask a question with `--save`, the answer becomes a new page, and future queries use it as context.
241
+
242
+ Then semantic retrieval, BM25 reranking, and graph expansion run over the compiled artifact — narrowing hundreds of pages to a tight, citation-traceable evidence pack.
189
243
 
190
244
  ```
191
245
  RAG: query → search chunks → answer → forget
192
- llmwiki: sources → compile → wiki → query → save → richer wiki → better answers
246
+ llmwiki: sources → compile → wiki → embed → query → save → richer wiki → better answers
193
247
  ```
194
248
 
249
+ llmwiki is complementary to traditional RAG: use RAG for ad-hoc retrieval over noisy or fast-changing corpora; use llmwiki when you want a persistent, structured, citation-traceable artifact that compounds.
250
+
195
251
  ## How it works
196
252
 
197
253
  ```
198
- sources/ → SHA-256 hash check → LLM concept extraction → wiki page generation → [[wikilink]] resolution → index.md
254
+ sources/ → hash check → LLM concept extraction → page generation → [[wikilink]] resolve
255
+ │ ↓
256
+ │ chunk embeddings ← wiki/ → index.md
257
+ │ ↓
258
+ │ semantic search + BM25 rerank + graph expansion
259
+ │ ↓
260
+ │ llmwiki query / context / MCP
261
+
262
+ stale / orphaned pages → llmwiki refresh --stale → recompile changed owners, clean up orphans
199
263
  ```
200
264
 
201
- **Two-phase pipeline.** Phase 1 extracts all concepts from all sources. Phase 2 generates pages. This eliminates order-dependence, catches failures before writing anything, and merges concepts shared across multiple sources into single pages.
265
+ **Two-phase compile.** Phase 1 extracts all concepts from every source; Phase 2 generates pages. Splitting the phases eliminates order-dependence, catches extraction failures before anything is written, merges concepts shared across multiple sources into a single page, and marks pages whose sources were all deleted as `orphaned` rather than silently dropping them.
202
266
 
203
- **Incremental.** Only changed sources go through the LLM. Everything else is skipped via hash-based change detection.
267
+ **Incremental everywhere.** Hash-based change detection on sources, content-hash-aware embedding updates, and cached citation judgements mean only changed work runs through the LLM. Recompiling after editing one source touches just the pages that source contributed to.
268
+
269
+ **Source freshness and repair.** Every page records the sources — and their content hashes — that produced it. On any later command, llmwiki compares those recorded hashes against `sources/` on disk: a page whose sources changed since the last compile is `stale`, and a page whose sources were all deleted is `orphaned`. `llmwiki lint`, `llmwiki status`, the viewer, the JSON export, and the MCP tools surface this without recompiling anything. `llmwiki refresh --stale` then repairs it — recompiling only the changed sources that own stale pages and cleaning up orphaned ones, while deliberately leaving unrelated new sources for a full `llmwiki compile`. `--dry-run` previews the plan with no LLM calls.
270
+
271
+ **Hybrid retrieval.** `.llmwiki/embeddings.json` v2 carries page- and chunk-level vectors. `llmwiki query` and `llmwiki context` narrow hundreds of pages down to a chunk-level top-K via cosine similarity, then rerank with BM25 and expand along the wikilink graph for the final evidence pack.
272
+
273
+ **Citation-traceable.** Paragraphs carry `^[source.md]` markers; specific claims pin to `^[source.md:42-58]` line ranges. `llmwiki lint` validates that every citation resolves to a real file and line range; `llmwiki eval` measures citation precision and (optionally) LLM-judged claim support.
204
274
 
205
275
  **Compounding queries.** `llmwiki query --save` writes the answer as a wiki page and immediately rebuilds the index. Saved answers show up in future queries as context.
206
276
 
@@ -247,26 +317,43 @@ Pages include source attribution in frontmatter. Paragraphs are annotated with `
247
317
  |---------|-------------|
248
318
  | `llmwiki ingest <url\|file>` | Fetch a URL or copy a local file into `sources/` |
249
319
  | `llmwiki ingest-session <path>` | Import a Claude/Codex/Cursor session export (single file or whole directory) into `sources/` |
320
+ | `llmwiki quickstart <source>` | Ingest a source and compile a wiki in one step; supports `--review`, `--no-open`, `--provider`, `--lang`, and `--json` |
250
321
  | `llmwiki compile` | Incremental compile: extract concepts, generate wiki pages |
251
322
  | `llmwiki compile --review` | Write candidate pages to `.llmwiki/candidates/` instead of `wiki/` so you can review before they land |
252
323
  | `llmwiki compile --lang <code>` | Generate wiki content in the given language (e.g. `Chinese`, `ja`, `zh-CN`); also works on `query` |
324
+ | `llmwiki refresh --stale [--dry-run]` | Repair stale/orphaned pages: recompile the sources that own stale pages and clean up deleted owners, skipping unrelated new sources. `--dry-run` previews the plan with no LLM calls or writes |
253
325
  | `llmwiki review list` | List pending candidate pages |
254
326
  | `llmwiki review show <id>` | Print a candidate's title, summary, and body |
255
327
  | `llmwiki review approve <id>` | Promote a candidate into `wiki/` and refresh index/MOC/embeddings |
256
328
  | `llmwiki review reject <id>` | Archive a candidate without touching `wiki/` |
329
+ | `llmwiki rules extract` | Extract machine-actionable rule candidates from changed sources into `.llmwiki/rule-candidates/` |
330
+ | `llmwiki rules list` | List pending rule candidates |
331
+ | `llmwiki rules approve <id>` / `reject <id>` | Approve or reject a rule candidate |
332
+ | `llmwiki rules export` | Emit approved rule candidates as a JSON array for a downstream rule importer |
257
333
  | `llmwiki schema init` | Write a starter `.llmwiki/schema.json` file |
258
334
  | `llmwiki schema show` | Print the resolved schema for the current project |
259
335
  | `llmwiki query "question"` | Ask questions against your compiled wiki |
260
336
  | `llmwiki query "question" --save` | Answer and save the result as a wiki page |
261
- | `llmwiki export [--target <name>]` | Export the wiki to portable formats — `llms.txt`, `llms-full.txt`, JSON, JSON-LD, GraphML, Marp slides |
337
+ | `llmwiki export [--target <name>] [--project-id <id>]` | Export the wiki to portable formats — `llms.txt`, `llms-full.txt`, JSON, JSON-LD, GraphML, Marp slides. `--project-id` pins a stable identifier inside the JSON envelope so downstream importers (e.g. [`@atomicmemory/llmwiki`](https://github.com/atomicstrata/atomicmemory/tree/main/packages/llmwiki)) can derive deterministic external IDs |
262
338
  | `llmwiki view [--open]` | Start a read-only local web viewer for browsing, searching, and inspecting the compiled wiki |
263
- | `llmwiki lint` | Check wiki quality (broken links, orphans, empty pages, low confidence, contradictions, etc.) |
339
+ | `llmwiki next [--json]` | Show the recommended next action for this project (read-only); `--json` emits a stable envelope for agents |
340
+ | `llmwiki context "<prompt>" [--json]` | Build an agent-ready evidence pack (primary pages, citations, neighbors, suggested actions) — same v1 envelope as MCP `get_context_pack` |
341
+ | `llmwiki lint` | Check wiki quality (broken links, orphans, empty pages, low confidence, contradictions, stale pages whose sources changed, etc.) |
342
+ | `llmwiki eval [--suite fast\|full]` | Measure wiki quality: health score (0–100), citation coverage, corpus stats. `--suite full` adds LLM-as-judge citation support scoring |
343
+ | `llmwiki eval cache show` | Print score distribution and top-cited pages from the citation judgement cache |
344
+ | `llmwiki eval cache clear` | Remove the citation judgement cache |
345
+ | `llmwiki eval report` | Print the most recent eval report |
346
+ | `llmwiki eval history [--n N]` | Show a trend table of past eval runs from `history.jsonl` |
347
+ | `llmwiki eval judgements [--score 0\|1\|2] [--page slug]` | Inspect individual citation judgements with optional score or page filters |
264
348
  | `llmwiki watch` | Auto-recompile when `sources/` changes |
265
349
  | `llmwiki serve [--root <dir>]` | Start an MCP server exposing wiki tools to AI agents |
266
350
 
351
+ `llmwiki context --include-sources` and MCP `get_context_pack` with `includeSources: true` are opt-in because they can return raw snippets from files under `sources/`. Path confinement prevents reads outside `sources/`, but only enable source windows for agents you trust with the ingested source text.
352
+
267
353
  ## Output
268
354
 
269
355
  ```
356
+ log.md append-only activity journal (ingests, compiles, queries)
270
357
  wiki/
271
358
  concepts/ one .md file per concept, with YAML frontmatter
272
359
  queries/ saved query answers, included in index and retrieval
@@ -277,7 +364,31 @@ wiki/
277
364
  candidates/archive/ rejected candidates kept for audit
278
365
  ```
279
366
 
280
- Obsidian-compatible. `[[wikilinks]]` resolve to concept titles.
367
+ Obsidian-compatible. `[[wikilinks]]` resolve to concept titles — or to any page that declares the term in its `aliases` frontmatter, so links survive renames and synonyms.
368
+
369
+ `log.md` records what happened and when. Each entry is a heading with a fixed
370
+ prefix — `## [YYYY-MM-DDThh:mm:ssZ] operation | description` (an ISO 8601 UTC
371
+ timestamp) — followed by a short bullet body carrying page wikilinks and counts:
372
+
373
+ ```markdown
374
+ ## [2026-06-05T09:14:02Z] ingest | Attention Is All You Need
375
+ - Source: https://arxiv.org/abs/1706.03762
376
+ - Saved: sources/attention-is-all-you-need.md
377
+ - Chars: 38,214
378
+
379
+ ## [2026-06-05T09:15:30Z] compile | 1 source(s) → 6 page(s)
380
+ - Sources: attention-is-all-you-need.md
381
+ - Created: [[self-attention]], [[multi-head-attention]], [[transformer]]
382
+ - Updated: [[positional-encoding]]
383
+
384
+ ## [2026-06-05T09:16:11Z] query | What is multi-head attention?
385
+ - Pages: [[multi-head-attention]], [[self-attention]]
386
+ ```
387
+
388
+ Only headings start with `## [`, so the gist's recipe still works even with the
389
+ bodies: `grep "^## \[" log.md | tail -5` shows the five most recent operations.
390
+ Where `index.md` organizes content for discovery, `log.md` tracks temporal
391
+ progression.
281
392
 
282
393
  ## Local web viewer
283
394
 
@@ -369,6 +480,55 @@ The schema supports four page kinds:
369
480
 
370
481
  Schema rules can set per-kind `minWikilinks` and optional `seedPages`. Compile can materialize seed pages such as overviews, lint enforces page-kind-specific cross-link minimums, and review candidates surface schema violations before approval.
371
482
 
483
+ ## Eval / quality measurement
484
+
485
+ `llmwiki eval` gives the wiki a quantitative health score and tracks citation quality over time, making it possible to detect regressions after a recompile.
486
+
487
+ ```bash
488
+ llmwiki eval # fast suite: health score, citation coverage, corpus stats
489
+ llmwiki eval --suite full # + LLM-as-judge citation support scoring (requires API)
490
+ llmwiki eval report # re-print the most recent report
491
+ llmwiki eval history # trend table across past runs
492
+ llmwiki eval history --n 10 # limit to last 10 entries
493
+ llmwiki eval judgements # all cached citation judgements
494
+ llmwiki eval judgements --score 0 # only unsupported citations
495
+ llmwiki eval judgements --page some-slug # filter to one page
496
+ llmwiki eval cache show # score distribution + top-cited pages
497
+ llmwiki eval cache clear # wipe the citation judgement cache
498
+ ```
499
+
500
+ **What it measures:**
501
+
502
+ - **Health score (0–100)** aggregates all lint rules. Errors (broken citations, broken wikilinks, duplicate concepts) cost more than warnings.
503
+ - **Citation coverage** — fraction of prose paragraphs that carry a `^[...]` marker, plus citation precision (fraction of citations pointing to existing source files).
504
+ - **Citation support (full suite)** — samples up to N `(claim, source span)` pairs, asks a judge model to score each 0–2 (unsupported → fully supported), and caches results so subsequent runs only re-judge new pairs.
505
+ - **Source utilization & citation depth** — the fraction of a page's valid sources that are actually cited (`source_utilization_rate`), and the share of citations pinned to specific line ranges rather than whole files (`claim_level_citation_rate`). Source warnings flag sources excluded from compilation (e.g. out-of-tree symlinks), gateable via `source_warnings_max`.
506
+ - **Corpus stats** — page count, source count, total wiki characters, embedding counts, appended to `history.jsonl` for trend tracking.
507
+ - **Regression deltas** — current report is diffed against the previous entry in history.
508
+
509
+ **CI thresholds:** add `.llmwiki/eval/thresholds.yaml` to configure minimum acceptable scores:
510
+
511
+ ```yaml
512
+ health_score: 85
513
+ citation_coverage_percent: 70
514
+ citation_precision_percent: 90
515
+ citation_support_mean: 1.4 # only checked when --suite full
516
+ source_utilization_rate: 0.9 # min fraction of valid sources cited by a page
517
+ source_warnings_max: 0 # max excluded sources (out-of-tree symlinks, etc.)
518
+ claim_level_citation_rate: 0.5 # min fraction of citations with line ranges
519
+ ```
520
+
521
+ Threshold violations are listed in the report. Exit code is non-zero when any threshold is breached, suitable for CI gating.
522
+
523
+ **Artifacts** written under `.llmwiki/eval/`:
524
+
525
+ ```
526
+ .llmwiki/eval/
527
+ history.jsonl one JSON line per eval run
528
+ citation-cache.jsonl one JSON line per citation judgement
529
+ thresholds.yaml optional CI threshold config
530
+ ```
531
+
372
532
  </details>
373
533
 
374
534
 
@@ -385,10 +545,8 @@ Try it on any article or document:
385
545
 
386
546
  ```bash
387
547
  mkdir my-wiki && cd my-wiki
388
- llmwiki ingest https://en.wikipedia.org/wiki/Andrej_Karpathy
389
- llmwiki compile
548
+ llmwiki quickstart https://en.wikipedia.org/wiki/Andrej_Karpathy
390
549
  llmwiki query "What terms did Andrej coin?"
391
- llmwiki view --open
392
550
  ```
393
551
 
394
552
  See `examples/basic/` in the repo for pre-generated output you can browse without an API key.
@@ -437,7 +595,7 @@ Add to your client's MCP config (e.g. `claude_desktop_config.json`):
437
595
  }
438
596
  ```
439
597
 
440
- Tools that need an LLM (`compile_wiki`, `query_wiki`, `search_pages`) check for a configured provider on each call. Read-only tools (`read_page`, `lint_wiki`, `wiki_status`) and `ingest_source` work without any credentials.
598
+ Tools that need an LLM (`compile_wiki`, `query_wiki`, `search_pages`) check for a configured provider on each call. Read-only tools (`read_page`, `lint_wiki`, `wiki_status`) and `ingest_source` work without any credentials. `get_context_pack` is read-only and provider credentials are optional — when present, semantic retrieval is used; otherwise the tool falls back to lexical ranking and surfaces an `embedding-store-missing` or `query-embedding-unavailable` warning.
441
599
 
442
600
  ### Tools
443
601
 
@@ -449,7 +607,9 @@ Tools that need an LLM (`compile_wiki`, `query_wiki`, `search_pages`) check for
449
607
  | `search_pages` | Return full content of pages relevant to a question. |
450
608
  | `read_page` | Read a single page by slug (concepts/ then queries/). |
451
609
  | `lint_wiki` | Run quality checks; returns structured diagnostics. |
452
- | `wiki_status` | Page count, source count, orphans, pending changes (read-only). |
610
+ | `wiki_status` | Page/source counts, stale and orphaned pages, a `stateStatus` field, and pending changes (read-only). |
611
+ | `get_context_pack` | Build an agent-ready evidence pack (primary pages, semantic chunks, graph neighbors, citations, per-page freshness, warnings, suggested actions) — same v1 JSON envelope as `llmwiki context --json`. `get_context_pack` **packages evidence**; `query_wiki` **generates answers**. |
612
+ | `run_eval` | Score wiki quality (the fast suite needs no API key; the full suite LLM-judges a sample of citations); read-only. |
453
613
 
454
614
  ### Resources
455
615
 
@@ -460,6 +620,8 @@ Tools that need an LLM (`compile_wiki`, `query_wiki`, `search_pages`) check for
460
620
  | `llmwiki://query/{slug}` | A single saved query page. |
461
621
  | `llmwiki://sources` | List of ingested source files with metadata. |
462
622
  | `llmwiki://state` | Compilation state (per-source hashes, last compile times). |
623
+ | `llmwiki://eval/report` | The most recent eval report. |
624
+ | `llmwiki://eval/history` | Trend of past eval runs. |
463
625
 
464
626
  </details>
465
627
 
@@ -471,31 +633,115 @@ Tools that need an LLM (`compile_wiki`, `query_wiki`, `search_pages`) check for
471
633
  <br>
472
634
 
473
635
 
474
- ## Limitations
636
+ <details>
637
+ <summary><span style="font-size: 1.4em;"><strong>SDK — programmatic API — click to expand</strong></span></summary>
638
+
639
+
640
+ ## SDK — `createWiki()`
641
+
642
+ Drive llmwiki in-process instead of shelling out to the CLI. `createWiki({ root })` returns a `Wiki` facade bound to a project directory. Every method runs silently (no console output) and is concurrency-safe — quiet mode is scoped per async call, not via a global flag. `createWiki` is exported from the package entry, so `import { createWiki } from "llm-wiki-compiler"` works for any installed version.
475
643
 
476
- Early software. Best for small, high-signal corpora (a few dozen sources). Query routing is index-based.
644
+ ```ts
645
+ import { createWiki } from "llm-wiki-compiler";
477
646
 
478
- **Honest about truncation.** Sources that exceed the character limit are truncated on ingest with `truncated: true` and the original character count recorded in frontmatter, so downstream consumers know they're working with partial content.
647
+ const wiki = createWiki({ root: "./my-wiki" });
648
+
649
+ await wiki.ingestText({ title: "Notes", text: "Raw text to compile…" });
650
+ await wiki.compile(); // needs LLM credentials
651
+ const { answer } = await wiki.query("What did I note about X?");
652
+ const status = await wiki.status(); // no credentials needed
653
+ ```
654
+
655
+ ### Methods
656
+
657
+ | Method | What it does | LLM creds |
658
+ |--------|--------------|:---------:|
659
+ | `ingest({ source })` | Fetch a URL or read a local file into `sources/`. **Trusted input only** — a server-side fetch + local-file-read primitive (SSRF risk); use `ingestText` for untrusted content. | No |
660
+ | `ingestText({ title, text })` | Ingest raw text — the safe path for untrusted content (no fetch, no file read). | No |
661
+ | `compile(options?)` | Compile pending sources into wiki pages. `options.review` queues candidates instead of writing. **Sends source content to the provider.** | Yes |
662
+ | `search(question)` | Retrieve and hydrate the most relevant page records. | Yes |
663
+ | `query(question, options?)` | Grounded answer; `options.save` persists it as a page, `options.debug` returns retrieval detail. | Yes |
664
+ | `getPage(ref)` / `listPages(options?)` | Read one page / list pages with filters and cursor pagination. | No |
665
+ | `listSources(options?)` / `getSource(id)` / `deleteSource(id)` | List, read, or delete ingested sources. `id` is the `IngestResult.filename` (e.g. `"note.md"`); `deleteSource` reconciles the compiled page on the next `compile()`. | No |
666
+ | `status()` | Read-only status snapshot — counts, freshness, pending changes. | No |
667
+ | `lint()` | Run all lint rules; severity-counted summary. | No |
668
+ | `getContextPack({ prompt, budget?, depth?, topPages?, topChunks? })` | Build a v1 context pack — same envelope as MCP `get_context_pack`. Semantic retrieval when embeddings exist, lexical fallback otherwise. | No |
669
+ | `exportJson(options?)` | Structured JSON export document (same shape as `llmwiki export --target json`). | No |
670
+ | `runEval({ mode, record? })` | Eval harness. `mode: "fast"` is credential-free; `"full"` LLM-judges a sample of citations. | full only |
671
+
672
+ **Notes.** Methods that need a provider throw `ProviderUnavailableError` when no credentials are configured; the rest run credential-free. Output is suppressed and there is no progress callback in v1 (`compile`/`runEval` on a large corpus can run for minutes with no feedback). `status()`, `lint()`, and `exportJson()` each hash the full source corpus per call (no cross-call cache) — avoid calling them in a hot loop. All result types (`CompileResult`, `QueryResult`, `WikiStatus`, `ContextPack`, …) are exported from the package for typed consumption.
673
+
674
+ </details>
675
+
676
+
677
+ <br>
678
+
679
+ ---
680
+
681
+ <br>
682
+
683
+
684
+ ## Companion: Atomic Memory
685
+
686
+ llmwiki and [Atomic Memory](https://github.com/atomicstrata/atomicmemory) are complementary layers of open context infrastructure, both maintained by [Atomic Strata](https://github.com/atomicstrata):
687
+
688
+ - **llmwiki** gives you a persistent **knowledge base** — durable markdown compiled from your sources, inspectable on disk.
689
+ - **Atomic Memory** gives your agents persistent **working memory** — runtime context that's searchable, correctable, scoped, and inspectable over time.
690
+
691
+ Use them independently or together. Each remains valuable on its own — llmwiki as a notebook, RAG index, CI-checked knowledge base, or domain pack source; Atomic Memory as a runtime memory layer for any agent or app.
692
+
693
+ The [`@atomicmemory/llmwiki`](https://github.com/atomicstrata/atomicmemory/tree/main/packages/llmwiki) bridge ingests `llmwiki export --target json --project-id <id>` envelopes as one verbatim Atomic Memory record per wiki page, preserving all advisory metadata (kind, citations, confidence, provenance state, contradictions, aliases, freshness) under `memory.metadata.llmwiki.*`. See the [bridge cookbook](https://github.com/atomicstrata/atomicmemory/blob/main/packages/llmwiki/docs/cookbook.md) for the full compile → export → import → package workflow.
694
+
695
+ ## Scale and what works
696
+
697
+ Still early software, but the scale story has matured well past the "few dozen sources" era.
698
+
699
+ - **Semantic chunk retrieval** (`.llmwiki/embeddings.json` v2) narrows hundreds of pages down to a small top-K before LLM selection, with BM25 reranking and graph-neighborhood expansion layered on top.
700
+ - **Incremental everything.** Hash-based source-change detection, content-hash-aware embedding updates, cached citation judgements. Re-running on an unchanged corpus is a few seconds.
701
+ - **Lexical fallback.** Index-based routing kicks in automatically when no embedding store is present or the active provider has no embedding credentials, surfacing a stable warning code rather than hard-failing.
702
+
703
+ **Honest about truncation.** Sources that exceed the character limit are truncated on ingest with `truncated: true` and the original character count recorded in frontmatter, so downstream consumers know they're working with partial content. A per-concept prompt budget prevents popular shared concepts from crashing compile.
704
+
705
+ **Where it's still early.** No source-freshness watchdog yet (re-ingest detects content changes, but doesn't proactively re-check URLs). No team / multi-writer conflict resolution. The viewer is read-only by design — write operations go through the CLI or MCP.
479
706
 
480
707
  ## Karpathy's LLM Wiki pattern vs this compiler
481
708
 
482
- Karpathy describes an abstract pattern for turning raw data into compiled knowledge. Here's how llmwiki maps to it:
709
+ Karpathy described an abstract pattern for turning raw data into compiled knowledge. Here's how llmwiki maps to it today:
483
710
 
484
711
  | Karpathy's concept | llmwiki | Status |
485
712
  |---|---|---|
486
- | Data ingest | `llmwiki ingest` | Implemented |
487
- | Compile wiki | `llmwiki compile` | Implemented |
488
- | Q&A | `llmwiki query` | Implemented |
713
+ | Data ingest | `llmwiki ingest`, `ingest-session` (Claude/Codex/Cursor) | Implemented |
714
+ | Compile wiki | `llmwiki compile` (two-phase, incremental) | Implemented |
715
+ | Q&A | `llmwiki query` (semantic + BM25 + graph expansion) | Implemented |
489
716
  | Output filing (save answers back) | `llmwiki query --save` | Implemented |
490
717
  | Auto-recompile | `llmwiki watch` | Implemented |
491
- | Linting / health-check pass | `llmwiki lint` | Implemented |
492
- | Agent integration | `llmwiki serve` (MCP server) | Implemented |
493
- | Image support | `llmwiki ingest <image>` | Implemented |
718
+ | Linting / health-check pass | `llmwiki lint` + `llmwiki eval` (CI-gateable) | Implemented |
719
+ | Agent integration | `llmwiki serve` MCP server with `get_context_pack` | Implemented |
720
+ | Multimodal ingest | Images, PDFs, transcripts via `llmwiki ingest` | Implemented |
494
721
  | Marp slides | `llmwiki export --target marp` | Implemented |
722
+ | Bridge to runtime memory | `llmwiki export --target json --project-id` → [`@atomicmemory/llmwiki`](https://github.com/atomicstrata/atomicmemory/tree/main/packages/llmwiki) | Implemented |
495
723
  | Fine-tuning | — | Not yet implemented |
496
724
 
497
725
  ## Roadmap
498
726
 
727
+ Shipped in 0.9.0:
728
+
729
+ - ✅ Source freshness — `llmwiki lint` flags pages whose sources changed (`stale`) or were all deleted (`orphaned`) since compile, surfaced across MCP (`wiki_status`, `get_context_pack`), context packs, the viewer (badges, a per-axis filter, health counts, a corrupt-state banner), the JSON export, and `llmwiki next`
730
+ - ✅ `llmwiki refresh --stale` — repairs stale/orphaned pages with a targeted recompile of their changed owning sources (and deleted-owner cleanup), skipping unrelated new sources; `--dry-run` previews with no LLM calls or writes
731
+ - ✅ JSON export bridge contract — `llmwiki export --target json --project-id <id>` adds per-page `path`, `kind`, advisory confidence/provenance, flattened citations, aliases, and freshness so downstream importers (e.g. [`@atomicmemory/llmwiki`](https://github.com/atomicstrata/atomicmemory/tree/main/packages/llmwiki)) can ingest pages as durable memory records
732
+ - ✅ In-process SDK — `createWiki()` exposes the compiler in-process, with source-backed write APIs for programmatic callers
733
+ - ✅ Eval over MCP + richer metrics — `run_eval` tool and read-only `llmwiki://eval/report`/`llmwiki://eval/history` resources, plus source-utilization and citation-depth metrics with a `source_warnings_max` CI gate
734
+ - ✅ Rule-candidate extraction — extract reusable rule candidates from sources with review/approve and a JSON export pipeline
735
+ - ✅ Claude Agent provider — authenticates through a local Claude Code login (bundled plan tokens, no separate API key)
736
+ - ✅ Alias-aware wikilinks — the viewer resolves a `[[term]]` link to any page that declares `term` in its `aliases` frontmatter, not just an exact slug match
737
+
738
+ Shipped in 0.8.0:
739
+
740
+ - ✅ Guided project flow — `llmwiki next` recommends the next useful command, and `llmwiki quickstart <source>` ingests, compiles, and opens the viewer in one step
741
+ - ✅ Graph/context layer — `llmwiki context` and MCP `get_context_pack` produce token-budgeted evidence packs with primary pages, graph neighbors, citations, optional source windows, warnings, and suggested actions
742
+ - ✅ Viewer graph route — `llmwiki view` includes a force-directed `#/graph` route for exploring page relationships
743
+ - ✅ Evaluation harness — `llmwiki eval` measures health score, citation coverage/precision, corpus stats, regression deltas, optional LLM-as-judge citation support, and CI thresholds
744
+
499
745
  Shipped in 0.7.0:
500
746
 
501
747
  - ✅ Read-only local web viewer — `llmwiki view` with sidebar navigation, markdown rendering, search, metadata, health counts, and provenance/citation chips
@@ -536,11 +782,10 @@ Shipped in 0.2.0:
536
782
 
537
783
  Next up:
538
784
 
539
- - **Graph/context layer** — page-neighborhood tools, graph paths, gap detection, and token-budgeted context packs for agents.
540
- - **Evaluation harness** — benchmark answer quality, citation accuracy, update drift, retrieval recall, and scale curves against serious retrieval baselines.
541
785
  - **Task and decision ledger** — turn session ingest into durable agent memory: goals, decisions, open questions, outcomes, and next-agent handoffs.
542
786
  - **Rollback, audit, and source lifecycle** — undo/reverse ingest, compile diff reports, stale-claim checks, freshness reports, and a durable operation log.
543
787
  - **Domain templates** — schema/prompt packs for research, codebase docs, team handbooks, decision logs, and standards/regulations.
788
+ - **Eval extensions** — retrieval recall suites, update-drift benchmarks, and comparisons against serious retrieval baselines.
544
789
 
545
790
  Later / open to discussion:
546
791
 
@@ -549,7 +794,7 @@ Later / open to discussion:
549
794
  - Codex OAuth provider — ChatGPT subscription auth as a dedicated provider, with clear token refresh and embedding-limit behavior
550
795
  - Team-chat connectors for Slack/Discord/Teams-style institutional memory
551
796
 
552
- If you like ambitious problems: **local web UI**, **graph/context packs**, and **eval harness** are the meatiest next contributions. Open an issue to claim one or kick off a design discussion.
797
+ If you like ambitious problems: **task/decision ledger**, **rollback/audit tooling**, and **eval extensions** are the meatiest next contributions. Open an issue to claim one or kick off a design discussion.
553
798
 
554
799
  Explicitly not planned (good ideas, just not for this repo): full static-site generator, desktop or mobile apps, fine-tuning, a formal ontology engine, heavy graph database infrastructure.
555
800
 
@@ -557,6 +802,10 @@ Explicitly not planned (good ideas, just not for this repo): full static-site ge
557
802
 
558
803
  Node.js >= 24, plus provider credentials (for Anthropic: `ANTHROPIC_API_KEY` or `ANTHROPIC_AUTH_TOKEN`).
559
804
 
805
+ ## About
806
+
807
+ llmwiki is maintained by [Atomic Strata](https://github.com/atomicstrata), the team behind [Atomic Memory](https://github.com/atomicstrata/atomicmemory). Atomic Strata builds open context infrastructure: durable compiled knowledge with llmwiki, runtime memory with Atomic Memory.
808
+
560
809
  ## License
561
810
 
562
811
  MIT