llm-wiki-compiler 0.1.1 → 0.3.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
@@ -17,12 +17,92 @@ Inspired by Karpathy's [LLM Wiki](https://gist.github.com/karpathy/442a6bf555914
17
17
  ```bash
18
18
  npm install -g llm-wiki-compiler
19
19
  export ANTHROPIC_API_KEY=sk-...
20
+ # Or use ANTHROPIC_AUTH_TOKEN if your Anthropic-compatible gateway expects it.
21
+ # Or use a different provider:
22
+ # export LLMWIKI_PROVIDER=openai
23
+ # export OPENAI_API_KEY=sk-...
20
24
 
21
25
  llmwiki ingest https://some-article.com
22
26
  llmwiki compile
23
27
  llmwiki query "what is X?"
24
28
  ```
25
29
 
30
+ ## Configuration
31
+
32
+ llmwiki configures providers via environment variables. The default provider is Anthropic.
33
+
34
+ Configuration precedence for Anthropic values:
35
+
36
+ 1. Shell env / local `.env`
37
+ 2. Claude Code settings fallback (`~/.claude/settings.json` → `env` block)
38
+ 3. Built-in provider defaults (where applicable)
39
+
40
+ - `LLMWIKI_PROVIDER`: The provider to use (e.g., anthropic, openai).
41
+ - `LLMWIKI_MODEL`: The model name to override the provider default.
42
+
43
+ ### Anthropic (Default)
44
+
45
+ - `ANTHROPIC_API_KEY` or `ANTHROPIC_AUTH_TOKEN`: Required. Either one can satisfy Anthropic authentication.
46
+ - `ANTHROPIC_BASE_URL`: Optional. Custom endpoint for proxies. Valid HTTP(S) URLs are accepted, including Claude-style path endpoints such as `https://api.kimi.com/coding/`.
47
+
48
+ Example using an Anthropic or cc-switch custom proxy:
49
+
50
+ ```bash
51
+ export LLMWIKI_PROVIDER=anthropic
52
+ export ANTHROPIC_API_KEY=sk-...
53
+ export ANTHROPIC_BASE_URL=https://proxy.example.com
54
+ ```
55
+
56
+ If those values are not set in shell env or `.env`, llmwiki will try Anthropic-compatible values from `~/.claude/settings.json` (`env` block) for:
57
+
58
+ - `ANTHROPIC_API_KEY`
59
+ - `ANTHROPIC_AUTH_TOKEN`
60
+ - `ANTHROPIC_BASE_URL`
61
+ - `ANTHROPIC_MODEL`
62
+
63
+ Example with zero exports (Claude Code already configured):
64
+
65
+ ```bash
66
+ llmwiki compile
67
+ ```
68
+
69
+ ### OpenAI-Compatible Local Servers
70
+
71
+ Use the OpenAI provider for local OpenAI-compatible servers such as
72
+ `llama-server`. `OPENAI_BASE_URL` is used for chat/tool calls, and
73
+ `OPENAI_EMBEDDINGS_BASE_URL` is optional. Set it only when embeddings are
74
+ served from a different endpoint; when unset, embeddings use the same client
75
+ and base URL as chat. Include `/v1` in custom URLs.
76
+
77
+ Split endpoint example:
78
+
79
+ ```bash
80
+ export LLMWIKI_PROVIDER=openai
81
+ export LLMWIKI_MODEL=qwen3.6-35b
82
+ export LLMWIKI_EMBEDDING_MODEL=text-embedding-model
83
+ export OPENAI_API_KEY=sk-local
84
+ export OPENAI_BASE_URL=http://host_url:port/v1
85
+ export OPENAI_EMBEDDINGS_BASE_URL=http://host_url:port/v1
86
+ ```
87
+
88
+ `OPENAI_API_KEY` is still required by the CLI and OpenAI SDK. For local
89
+ servers that do not check authentication, any dummy value is sufficient.
90
+
91
+ ### Ollama
92
+
93
+ Ollama uses its OpenAI-compatible endpoint. Set `OLLAMA_HOST` for chat and
94
+ optionally set `OLLAMA_EMBEDDINGS_HOST` only when embeddings are served from a
95
+ different endpoint. When unset, embeddings use `OLLAMA_HOST`. Include `/v1` in
96
+ custom URLs.
97
+
98
+ ```bash
99
+ export LLMWIKI_PROVIDER=ollama
100
+ export LLMWIKI_MODEL=llama3.1
101
+ export LLMWIKI_EMBEDDING_MODEL=nomic-embed-text
102
+ export OLLAMA_HOST=http://ollama_host:11434/v1
103
+ export OLLAMA_EMBEDDINGS_HOST=http://ollama_host:11435/v1
104
+ ```
105
+
26
106
  ## Why not just RAG?
27
107
 
28
108
  RAG retrieves chunks at query time. Every question re-discovers the same relationships from scratch. Nothing accumulates.
@@ -70,7 +150,7 @@ a knowledge base into a target language that supports efficient queries.
70
150
  Related concepts: [[Propositional Logic]], [[Model Counting]]
71
151
  ```
72
152
 
73
- Pages include source attribution in frontmatter. Provenance is page-level today, not claim-level.
153
+ Pages include source attribution in frontmatter. Paragraphs are annotated with `^[filename.md]` markers pointing back to the source file that contributed the content.
74
154
 
75
155
  ## Commands
76
156
 
@@ -78,21 +158,76 @@ Pages include source attribution in frontmatter. Provenance is page-level today,
78
158
  |---------|-------------|
79
159
  | `llmwiki ingest <url\|file>` | Fetch a URL or copy a local file into `sources/` |
80
160
  | `llmwiki compile` | Incremental compile: extract concepts, generate wiki pages |
161
+ | `llmwiki compile --review` | Write candidate pages to `.llmwiki/candidates/` instead of `wiki/` so you can review before they land |
162
+ | `llmwiki review list` | List pending candidate pages |
163
+ | `llmwiki review show <id>` | Print a candidate's title, summary, and body |
164
+ | `llmwiki review approve <id>` | Promote a candidate into `wiki/` and refresh index/MOC/embeddings |
165
+ | `llmwiki review reject <id>` | Archive a candidate without touching `wiki/` |
81
166
  | `llmwiki query "question"` | Ask questions against your compiled wiki |
82
167
  | `llmwiki query "question" --save` | Answer and save the result as a wiki page |
168
+ | `llmwiki lint` | Check wiki quality (broken links, orphans, empty pages, low confidence, contradictions, etc.) |
83
169
  | `llmwiki watch` | Auto-recompile when `sources/` changes |
170
+ | `llmwiki serve [--root <dir>]` | Start an MCP server exposing wiki tools to AI agents |
84
171
 
85
172
  ## Output
86
173
 
87
174
  ```
88
175
  wiki/
89
- concepts/ one .md file per concept, with YAML frontmatter
90
- queries/ saved query answers, included in index and retrieval
91
- index.md auto-generated table of contents
176
+ concepts/ one .md file per concept, with YAML frontmatter
177
+ queries/ saved query answers, included in index and retrieval
178
+ index.md auto-generated table of contents
179
+ .llmwiki/
180
+ candidates/ pending review candidates from `compile --review`
181
+ candidates/archive/ rejected candidates kept for audit
92
182
  ```
93
183
 
94
184
  Obsidian-compatible. `[[wikilinks]]` resolve to concept titles.
95
185
 
186
+ ## Review queue
187
+
188
+ By default, `compile` writes pages directly to `wiki/`. Add `--review` to write candidate JSON records to `.llmwiki/candidates/` instead, so you can inspect each generated page before it lands.
189
+
190
+ ```bash
191
+ llmwiki compile --review # produces candidates, leaves wiki/ untouched
192
+ llmwiki review list # see what's pending
193
+ llmwiki review show <id> # inspect a single candidate
194
+ llmwiki review approve <id> # write into wiki/ + refresh index/MOC/embeddings
195
+ llmwiki review reject <id> # archive to .llmwiki/candidates/archive/
196
+ ```
197
+
198
+ A few things to know:
199
+
200
+ - **Approve and reject acquire `.llmwiki/lock`** so they serialize cleanly against each other and against any concurrent `compile`.
201
+ - **Source state is deferred per-source.** When one source produces multiple candidates, the source isn't marked compiled until the last candidate is approved — so unresolved siblings stay re-detectable on the next `compile --review`.
202
+ - **Deletion bookkeeping is deferred.** `compile --review` does not orphan-mark deleted sources; the next non-review `compile` does that. The `--review` help text advertises this.
203
+ - MCP `wiki_status` exposes `pendingCandidates` so agents can see the queue depth.
204
+
205
+ ## Page metadata
206
+
207
+ Compiled pages can carry epistemic metadata in frontmatter so consumers know how trustworthy each page is. All fields are optional and existing pages without them continue to work.
208
+
209
+ ```yaml
210
+ ---
211
+ title: Knowledge Compilation
212
+ summary: Techniques for converting knowledge representations...
213
+ sources:
214
+ - knowledge-compilation.md
215
+ confidence: 0.82 # 0–1, LLM-reported confidence in the synthesized page
216
+ provenanceState: merged # extracted | merged | inferred | ambiguous
217
+ contradictedBy:
218
+ - slug: probabilistic-reasoning
219
+ inferredParagraphs: 1 # paragraphs the LLM marked as inferred (vs cited)
220
+ ---
221
+ ```
222
+
223
+ When multiple sources merge into one slug, metadata is reconciled: `min` confidence, `provenanceState = 'merged'`, union of `contradictedBy` (deduped by slug), `max` `inferredParagraphs`.
224
+
225
+ `llmwiki lint` adds three rules that surface this metadata:
226
+
227
+ - `low-confidence` — flags pages with `confidence` below a threshold
228
+ - `contradicted-page` — flags pages with non-empty `contradictedBy`
229
+ - `excess-inferred-paragraphs` — flags pages with too many inferred paragraphs without citations
230
+
96
231
  ## Demo
97
232
 
98
233
  Try it on any article or document:
@@ -106,9 +241,65 @@ llmwiki query "What terms did Andrej coin?"
106
241
 
107
242
  See `examples/basic/` in the repo for pre-generated output you can browse without an API key.
108
243
 
244
+ ## MCP Server
245
+
246
+ llmwiki ships an MCP (Model Context Protocol) server so AI agents (Claude Desktop, Cursor, Claude Code, etc.) can drive the full pipeline directly: ingest sources, compile, query, search, lint, and read pages — without scraping CLI output.
247
+
248
+ Where [llm-wiki-kit](https://github.com/iamsashank09/llm-wiki-kit) gives agents raw CRUD against wiki pages, llmwiki exposes the **automated pipelines**: agents get intelligent compilation, incremental change detection, and semantic query routing built in.
249
+
250
+ ### Setup
251
+
252
+ Start the server (stdio transport, no API key required at startup):
253
+
254
+ ```bash
255
+ llmwiki serve --root /path/to/your/wiki-project
256
+ ```
257
+
258
+ ### Claude Desktop / Cursor configuration
259
+
260
+ Add to your client's MCP config (e.g. `claude_desktop_config.json`):
261
+
262
+ ```json
263
+ {
264
+ "mcpServers": {
265
+ "llmwiki": {
266
+ "command": "npx",
267
+ "args": ["llm-wiki-compiler", "serve", "--root", "/path/to/wiki-project"],
268
+ "env": {
269
+ "ANTHROPIC_API_KEY": "sk-ant-..."
270
+ }
271
+ }
272
+ }
273
+ }
274
+ ```
275
+
276
+ 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.
277
+
278
+ ### Tools
279
+
280
+ | Tool | What it does |
281
+ |------|--------------|
282
+ | `ingest_source` | Fetch a URL or local file into `sources/`. |
283
+ | `compile_wiki` | Run the incremental compile pipeline; returns counts, slugs, errors. |
284
+ | `query_wiki` | Two-step grounded answer with optional `--save`. |
285
+ | `search_pages` | Return full content of pages relevant to a question. |
286
+ | `read_page` | Read a single page by slug (concepts/ then queries/). |
287
+ | `lint_wiki` | Run quality checks; returns structured diagnostics. |
288
+ | `wiki_status` | Page count, source count, orphans, pending changes (read-only). |
289
+
290
+ ### Resources
291
+
292
+ | URI | Returns |
293
+ |-----|---------|
294
+ | `llmwiki://index` | Full `wiki/index.md` content. |
295
+ | `llmwiki://concept/{slug}` | A single concept page (frontmatter + body). |
296
+ | `llmwiki://query/{slug}` | A single saved query page. |
297
+ | `llmwiki://sources` | List of ingested source files with metadata. |
298
+ | `llmwiki://state` | Compilation state (per-source hashes, last compile times). |
299
+
109
300
  ## Limitations
110
301
 
111
- Early software. Best for small, high-signal corpora (a few dozen sources). Query routing is index-based. Provenance is page-level, not claim-level. Anthropic-only for now.
302
+ Early software. Best for small, high-signal corpora (a few dozen sources). Query routing is index-based.
112
303
 
113
304
  **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.
114
305
 
@@ -123,24 +314,42 @@ Karpathy describes an abstract pattern for turning raw data into compiled knowle
123
314
  | Q&A | `llmwiki query` | Implemented |
124
315
  | Output filing (save answers back) | `llmwiki query --save` | Implemented |
125
316
  | Auto-recompile | `llmwiki watch` | Implemented |
126
- | Linting / health-check pass | | Not yet implemented (`watch` is auto-recompile, not lint) |
317
+ | Linting / health-check pass | `llmwiki lint` | Implemented |
318
+ | Agent integration | `llmwiki serve` (MCP server) | Implemented |
127
319
  | Image support | — | Not yet implemented |
128
320
  | Marp slides | — | Not yet implemented |
129
321
  | Fine-tuning | — | Not yet implemented |
130
322
 
131
323
  ## Roadmap
132
324
 
133
- - Multi-provider support (OpenAI, local models)
134
- - Better provenance (claim-level source attribution)
135
- - Larger-corpus query strategy (semantic search, embeddings)
136
- - Deeper Obsidian integration
137
- - Linting pass for wiki quality checks
325
+ Shipped in 0.3.0:
326
+
327
+ - Candidate review queue (approve compile output before pages are written)
328
+ - Confidence and contradiction metadata on compiled pages
329
+
330
+ Shipped in 0.2.0:
331
+
332
+ - ✅ Better provenance (paragraph-level source attribution)
333
+ - ✅ Linting pass for wiki quality checks
334
+ - ✅ Multi-provider support (OpenAI, Ollama, MiniMax)
335
+ - ✅ Larger-corpus query strategy (semantic search, embeddings)
336
+ - ✅ Deeper Obsidian integration (tags, aliases, Map of Content)
337
+ - ✅ MCP server for agent integration
338
+
339
+ Next up:
340
+
341
+ - Claim-level provenance with source ranges
342
+ - First-class schema layer with typed page kinds (`concept`, `entity`, `comparison`, `overview`)
343
+ - Multimodal ingest (images, PDFs, transcripts)
344
+ - Chunked retrieval with reranking
345
+ - Export bundle (`llms.txt`, JSON, JSON-LD, GraphML, Marp)
346
+ - Session-history adapters (Claude, Codex, Cursor exports)
138
347
 
139
- If you want to contribute, these are the highest-leverage areas right now. Issues and PRs are welcome.
348
+ If you like ambitious problems: **schema layer + typed page kinds**, **claim-level provenance**, and **chunked retrieval with reranking** are the meatiest. Open an issue to claim one or kick off a design discussion.
140
349
 
141
350
  ## Requirements
142
351
 
143
- Node.js >= 18, an Anthropic API key.
352
+ Node.js >= 18, plus provider credentials (for Anthropic: `ANTHROPIC_API_KEY` or `ANTHROPIC_AUTH_TOKEN`).
144
353
 
145
354
  ## License
146
355