@zosmaai/pi-llm-wiki 0.10.7 → 0.11.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.
Files changed (73) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.de.md +35 -4
  3. package/README.es.md +260 -170
  4. package/README.fr.md +35 -4
  5. package/README.hi.md +35 -4
  6. package/README.ja.md +35 -4
  7. package/README.ko.md +35 -4
  8. package/README.md +38 -3
  9. package/README.pt.md +35 -4
  10. package/README.ru.md +35 -4
  11. package/README.zh.md +260 -170
  12. package/assets/demo.gif +0 -0
  13. package/dist/extensions/llm-wiki/lib/bootstrap.js +71 -0
  14. package/dist/extensions/llm-wiki/lib/embeddings.js +401 -0
  15. package/dist/extensions/llm-wiki/lib/guardrails.js +232 -0
  16. package/dist/extensions/llm-wiki/lib/indexing.js +78 -0
  17. package/dist/extensions/llm-wiki/lib/ingest-worker.js +310 -0
  18. package/dist/extensions/llm-wiki/lib/inject.js +65 -0
  19. package/dist/extensions/llm-wiki/lib/knowledge-document.js +442 -0
  20. package/dist/extensions/llm-wiki/lib/knowledge-links.js +206 -0
  21. package/dist/extensions/llm-wiki/lib/legacy-repair.js +443 -0
  22. package/dist/extensions/llm-wiki/lib/metadata.js +499 -0
  23. package/dist/extensions/llm-wiki/lib/model-command.js +86 -0
  24. package/dist/extensions/llm-wiki/lib/observation.js +283 -0
  25. package/dist/extensions/llm-wiki/lib/recall.js +875 -0
  26. package/dist/extensions/llm-wiki/lib/retro.js +158 -0
  27. package/dist/extensions/llm-wiki/lib/runtime.js +191 -0
  28. package/dist/extensions/llm-wiki/lib/source-extractors.js +426 -0
  29. package/dist/extensions/llm-wiki/lib/source-packet.js +229 -0
  30. package/dist/extensions/llm-wiki/lib/subagent.js +41 -0
  31. package/dist/extensions/llm-wiki/lib/task-config.js +172 -0
  32. package/dist/extensions/llm-wiki/lib/tools.js +1192 -0
  33. package/dist/extensions/llm-wiki/lib/trajectories-command.js +51 -0
  34. package/dist/extensions/llm-wiki/lib/trajectory.js +467 -0
  35. package/dist/extensions/llm-wiki/lib/utils.js +347 -0
  36. package/dist/extensions/llm-wiki/lib/vault-format.js +247 -0
  37. package/dist/extensions/llm-wiki/lib/visible-status.js +31 -0
  38. package/dist/extensions/llm-wiki/lib/wiki-service.js +128 -0
  39. package/dist/mcp/exec.js +121 -0
  40. package/dist/mcp/index.js +229 -0
  41. package/dist/mcp/operations.js +130 -0
  42. package/dist/package.json +1 -0
  43. package/docs/superpowers/plans/2026-08-02-okf-foundation.md +1579 -0
  44. package/docs/superpowers/plans/2026-08-03-okf-foundation-remediation.md +3005 -0
  45. package/docs/superpowers/plans/2026-08-06-okf-foundation-release-remediation.md +1174 -0
  46. package/docs/superpowers/specs/2026-08-02-okf-foundation-design.md +578 -0
  47. package/docs/superpowers/specs/2026-08-02-okf-v0.2-interoperability-design.md +538 -0
  48. package/extensions/llm-wiki/index.ts +22 -36
  49. package/extensions/llm-wiki/lib/bootstrap.ts +84 -0
  50. package/extensions/llm-wiki/lib/embeddings.ts +9 -3
  51. package/extensions/llm-wiki/lib/guardrails.ts +174 -29
  52. package/extensions/llm-wiki/lib/indexing.ts +2 -1
  53. package/extensions/llm-wiki/lib/ingest-worker.ts +170 -29
  54. package/extensions/llm-wiki/lib/knowledge-document.ts +661 -0
  55. package/extensions/llm-wiki/lib/knowledge-links.ts +282 -0
  56. package/extensions/llm-wiki/lib/legacy-repair.ts +572 -0
  57. package/extensions/llm-wiki/lib/metadata.ts +531 -116
  58. package/extensions/llm-wiki/lib/observation.ts +37 -43
  59. package/extensions/llm-wiki/lib/recall.ts +61 -33
  60. package/extensions/llm-wiki/lib/retro.ts +65 -41
  61. package/extensions/llm-wiki/lib/source-extractors.ts +12 -17
  62. package/extensions/llm-wiki/lib/source-packet.ts +44 -31
  63. package/extensions/llm-wiki/lib/tools.ts +406 -348
  64. package/extensions/llm-wiki/lib/trajectory.ts +15 -1
  65. package/extensions/llm-wiki/lib/utils.ts +121 -130
  66. package/extensions/llm-wiki/lib/vault-format.ts +363 -0
  67. package/extensions/llm-wiki/lib/wiki-service.ts +183 -0
  68. package/mcp/exec.ts +122 -0
  69. package/mcp/index.ts +60 -250
  70. package/mcp/operations.ts +176 -0
  71. package/package.json +8 -2
  72. package/scripts/migrate-llm-wiki.js +801 -0
  73. package/skills/llm-wiki/SKILL.md +8 -6
@@ -0,0 +1,538 @@
1
+ # OKF v0.2 Interoperability Design
2
+
3
+ **Status:** Approved umbrella design; non-normative
4
+
5
+ **Date:** 2026-08-02
6
+
7
+ **Package:** `@zosmaai/pi-llm-wiki`
8
+
9
+ > This document records program-level goals and approved direction. Child specs own normative implementation requirements. If this document conflicts with a child spec, the child spec wins.
10
+
11
+ ## Specification Map
12
+
13
+ 1. [OKF Foundation](./2026-08-02-okf-foundation-design.md) — shared document model, dual-read behavior, OKF-canonical writes, vault mode, indexes, logs, and metadata integration. This is the only child currently ready for implementation planning.
14
+ 2. **OKF Interchange** — import, review, transactions, export, and explicit migration. Write and review this child spec after Foundation is planned.
15
+ 3. **OKF Intelligence** — trust-aware recall and expanded linting. Write and review this child spec after Interchange boundaries are stable.
16
+
17
+ MCP and Pi tools must call the same shared service operations defined by each child spec; no interface may implement separate business rules.
18
+
19
+ ## Summary
20
+
21
+ pi-llm-wiki will become an Open Knowledge Format (OKF) v0.2 producer and consumer without forcing existing users to migrate their vaults. The extension will read both legacy pi-llm-wiki pages and OKF pages, write new pages in an OKF-canonical form, import external bundles through a review gate, export portable bundles, and offer an explicit migration command.
22
+
23
+ The first release focuses on interoperability, provenance, trust, freshness, stronger linting, and trust-aware recall. Graph visualization, git-backed snapshots, frozen reads, advanced removal/versioning, broader document extraction, and execution of attested computations remain future work.
24
+
25
+ ## Goals
26
+
27
+ 1. Make `.llm-wiki/wiki/` a conformant OKF v0.2 knowledge bundle for new and migrated vaults.
28
+ 2. Preserve existing vault behavior without automatic migration.
29
+ 3. Safely import, review, approve, and export external OKF bundles.
30
+ 4. Preserve unknown types, producer fields, document bodies, and safe concept paths during round trips.
31
+ 5. Make provenance, verification, lifecycle, and freshness visible during recall.
32
+ 6. Extend `wiki_lint` into a deterministic OKF and wiki-health validator.
33
+ 7. Keep extension and MCP behavior equivalent.
34
+
35
+ ## Non-goals for the First Release
36
+
37
+ - Executing code referenced by an `Attested Computation` document.
38
+ - Defining a universal category taxonomy or registered type vocabulary.
39
+ - Automatically resolving semantic contradictions.
40
+ - Automatically committing wiki changes to git.
41
+ - Importing zip or tar archives. First-release imports accept directories; archive transport can be added later without changing the bundle model.
42
+ - Building a graph viewer or hosted service.
43
+ - Replacing the existing recall system with a new retrieval engine.
44
+
45
+ ## Research and Competitive Findings
46
+
47
+ ### OKF v0.2
48
+
49
+ OKF is a format, not a runtime or platform. A bundle is a directory tree of Markdown concept documents with YAML frontmatter. A document's path without `.md` is its concept ID. `index.md` and `log.md` are reserved. The only always-required concept field is `type`; consumers must tolerate unknown types and unknown producer fields.
50
+
51
+ Version 0.2 adds optional first-class metadata for:
52
+
53
+ - provenance through `sources`
54
+ - authorship through `generated`
55
+ - verification through `verified`
56
+ - lifecycle through `status`
57
+ - freshness through `stale_after`
58
+ - sanctioned, verifiable calculations through `Attested Computation`
59
+
60
+ OKF relationships use ordinary Markdown links. Directories provide hierarchy; links provide graph edges. Index files provide progressive disclosure.
61
+
62
+ ### Pi package competitors
63
+
64
+ | Package | Strong points | Main limitations relative to this design |
65
+ |---|---|---|
66
+ | `pi-okf-wiki` | Deterministic intake of conformant Markdown, broad extraction support, TF-IDF query injection, generated hierarchical indexes, collision-safe archive, deterministic removal | Targets OKF v0.1, has no layered personal/project recall, no MCP, limited YAML subset, no v0.2 trust model |
67
+ | `llm-wiki-okf` | Query-first discipline, immutable raw sources, git-native workflow, strict linting, global/project tiers, source tracing | Skill and Python-script workflow rather than a Pi-native extension; no semantic retrieval; strict custom schema exceeds base OKF requirements |
68
+ | `@d1g1tlprim8/pi-okf-wiki` | Atomic single-file writes, git commits, graph checks, tag harmonization | Small skill utility set, custom required schema, no advanced retrieval, no safe bundle exchange workflow |
69
+
70
+ ### Broader projects
71
+
72
+ - Google's reference implementation demonstrates two-pass enrichment, hierarchical indexes, sample bundles, and a self-contained graph viewer.
73
+ - `llm-wiki-compiler` demonstrates review-gated import, trusted import, preservation of foreign fields and paths, and OKF export.
74
+ - OKF Harness demonstrates bounded evidence retrieval, deterministic JSON tool output, workspace checks, and a local graph report.
75
+ - `wiki-as-an-mcp` demonstrates separate read/manage capabilities, frozen git-backed reads, snapshots, and multi-topic isolation.
76
+
77
+ The competitive advantage for pi-llm-wiki is combining OKF interoperability with its existing immutable source packets, layered personal/project recall, background ingestion, hybrid lexical/semantic retrieval, guardrails, observations, retrospectives, trajectories, and MCP access.
78
+
79
+ ## Design Decisions
80
+
81
+ - Deliver both OKF interoperability and Pi-native wiki advantages in phases.
82
+ - Use dual-read, OKF-canonical write behavior.
83
+ - Never force automatic migration.
84
+ - Stage untrusted imports by default; support dry-run and explicit trusted mode.
85
+ - Keep recall relevance-first. Trust and freshness may rerank relevant candidates and add warnings, but never silently hide knowledge.
86
+ - Keep `category`, `domain`, `aliases`, and `recall_triggers` as optional producer extensions.
87
+ - Preserve and validate Attested Computation metadata but do not execute it.
88
+ - Restrict automatic lint fixes to deterministic repairs; never fabricate knowledge pages.
89
+
90
+ ## Vault Architecture
91
+
92
+ ```text
93
+ .llm-wiki/
94
+ ├── config.json
95
+ ├── WIKI_SCHEMA.md
96
+ ├── wiki/ # canonical OKF bundle
97
+ │ ├── index.md # okf_version: "0.2"
98
+ │ ├── log.md
99
+ │ ├── sources/
100
+ │ ├── concepts/
101
+ │ ├── entities/
102
+ │ ├── syntheses/
103
+ │ ├── analyses/
104
+ │ └── ... # requirements, skills, cases, foreign paths
105
+ ├── raw/ # immutable pi-llm-wiki source packets
106
+ ├── imports/ # extension-owned import staging and audit records
107
+ │ ├── pending/<import-id>/
108
+ │ └── applied/<import-id>/manifest.json
109
+ ├── meta/ # generated registry, backlinks, embeddings
110
+ └── outputs/ # reports and explicit exports
111
+ ```
112
+
113
+ `.llm-wiki/wiki/` is the distributable OKF bundle. Product-specific raw packets, staging state, and generated search metadata remain outside it.
114
+
115
+ Source pages inside the bundle provide stable provenance targets for canonical pages. Raw packet paths may remain pi-llm-wiki extension metadata on source pages, but portable provenance references should resolve to source pages or external resources rather than escaping the bundle.
116
+
117
+ `imports/**` is extension-owned and protected by the same tool-call guardrail model as `raw/**` and `meta/**`. Pending imports never participate in recall or metadata indexing.
118
+
119
+ ## Knowledge Model
120
+
121
+ ### Terminology
122
+
123
+ In OKF, every non-reserved Markdown knowledge document is a concept. In the pi-llm-wiki profile, `type: concept` remains one specific page class beside `entity`, `source`, `analysis`, and other existing classes.
124
+
125
+ ### Standard and profile fields
126
+
127
+ | Field | Role |
128
+ |---|---|
129
+ | `type` | Primary semantic kind; only always-required OKF field |
130
+ | File path | Stable concept identity and broad hierarchy |
131
+ | `title` | Human-readable display name |
132
+ | `description` | One-sentence search and index summary |
133
+ | `resource` | Canonical URI for the described asset, when applicable |
134
+ | `tags` | Cross-cutting labels |
135
+ | `sources` | Structured provenance and source credibility signals |
136
+ | `generated` | Who or what produced the current content and when |
137
+ | `verified` | Independent verification events |
138
+ | `status` | `draft`, `stable`, or `deprecated`; absent means stable |
139
+ | `stale_after` | Absolute date after which content is stale |
140
+ | `category` | Optional pi-llm-wiki subtype such as `architecture`, `person`, or `library` |
141
+ | `domain` | Optional knowledge area such as `security` or `ai-engineering` |
142
+ | `aliases` | Optional alternate names |
143
+ | `recall_triggers` | Optional phrases likely to be used when retrieving the page |
144
+
145
+ `category`, `domain`, `aliases`, and `recall_triggers` remain top-level producer extensions. They are optional, have no central vocabulary, and must be preserved by round-tripping consumers. The profile does not add subjective credibility or confidence scores; trust is derived from objective OKF signals.
146
+
147
+ Existing type values remain valid:
148
+
149
+ - `source`
150
+ - `entity`
151
+ - `concept`
152
+ - `synthesis`
153
+ - `analysis`
154
+ - `requirement`
155
+ - `trajectory`
156
+ - `case`
157
+ - `skill`
158
+
159
+ Unknown imported types remain valid and are treated as generic concepts by code that lacks type-specific behavior.
160
+
161
+ ### Profile conventions
162
+
163
+ The root index declares only the base format:
164
+
165
+ ```yaml
166
+ ---
167
+ okf_version: "0.2"
168
+ ---
169
+ ```
170
+
171
+ OKF v0.2 is ambiguous about additional root-index frontmatter keys, so the bundle does not claim `profile: pi-llm-wiki/1` there. The package documentation still defines pi-llm-wiki extension fields and page-type conventions, but plain OKF bundles do not need them and imported documents never require them. A portable profile-discovery mechanism is deferred until OKF specifies one or a later child spec defines a conformant approach.
172
+
173
+ ### Example
174
+
175
+ ```markdown
176
+ ---
177
+ type: concept
178
+ title: Retrieval-Augmented Generation
179
+ description: Grounds generation using retrieved evidence.
180
+ category: architecture
181
+ domain: ai-engineering
182
+ tags: [rag, retrieval]
183
+ aliases: [RAG]
184
+ recall_triggers: [grounded generation, document retrieval]
185
+ status: stable
186
+ generated:
187
+ by: pi-llm-wiki/model
188
+ at: 2026-08-02T10:00:00Z
189
+ sources:
190
+ - id: SRC-2026-08-02-001
191
+ resource: /sources/SRC-2026-08-02-001.md
192
+ ---
193
+
194
+ # Retrieval-Augmented Generation
195
+
196
+ RAG retrieves evidence before generation.[^SRC-2026-08-02-001]
197
+
198
+ [^SRC-2026-08-02-001]: Source summary
199
+ ```
200
+
201
+ ## Shared Document Layer
202
+
203
+ A small shared format module becomes the only parser and serializer used by ingestion, metadata generation, recall, lint, migration, import, and export.
204
+
205
+ Conceptual API:
206
+
207
+ - `parseKnowledgeDocument(content, path)`
208
+ - `serializeKnowledgeDocument(document)`
209
+ - `parseBundleIndex(content)`
210
+ - `validateKnowledgeDocument(document)`
211
+ - `validateOkfBundle(bundle)`
212
+ - `resolveKnowledgeLinks(document, bundle)`
213
+ - `convertLegacyDocument(document)`
214
+
215
+ The internal model separates standard OKF fields, pi-llm-wiki extension fields, unknown producer fields, and the Markdown body. Unknown fields must survive semantic round trips. Exact YAML formatting, comments, quoting style, and key order are not guaranteed to survive migration or serialization.
216
+
217
+ ### YAML handling
218
+
219
+ The current dependency-free parser cannot represent OKF v0.2 nested mappings and lists. The implementation will use a maintained YAML parser rather than grow a bespoke general YAML implementation.
220
+
221
+ Security requirements:
222
+
223
+ - disable aliases and alias expansion
224
+ - disable custom executable tags
225
+ - reject multiple YAML documents
226
+ - cap frontmatter bytes and nesting depth
227
+ - return structured parse errors rather than throwing through tool boundaries
228
+ - preserve unknown ordinary mappings, lists, and scalar values
229
+
230
+ Parsing is permissive; conformance validation is separate. A parseable document with unknown fields or type is accepted. A malformed document produces a file- and field-specific validation result.
231
+
232
+ ## Link Model
233
+
234
+ New pages use ordinary Markdown links, preferably bundle-root-relative links such as `/concepts/retrieval.md`. Legacy `[[wikilinks]]` remain readable during the compatibility period.
235
+
236
+ Metadata and linting resolve both forms:
237
+
238
+ - standard Markdown links between concept documents
239
+ - bundle-root-relative and relative paths
240
+ - legacy folder-qualified wikilinks
241
+ - body footnotes whose labels join to `sources[].id`
242
+
243
+ Migration converts resolvable wikilinks into Markdown links while preserving display labels. Unresolvable links remain unchanged and are reported; migration must not guess a target.
244
+
245
+ ## Generated Indexes and Logs
246
+
247
+ The metadata rebuild writes:
248
+
249
+ - a root `wiki/index.md`
250
+ - one `index.md` in each directory containing concepts directly or transitively
251
+ - a root `wiki/log.md`
252
+ - existing machine-oriented files under `meta/`
253
+
254
+ Each directory index lists only direct concepts and immediate child directories. This preserves progressive disclosure and avoids loading a recursive catalog into context.
255
+
256
+ Reserved `index.md` and `log.md` files are not concept documents and are excluded from ordinary concept recall. Imported reserved files are validated and recorded in the import manifest, but the live bundle regenerates its own indexes and log. Foreign concept paths and document-level metadata are preserved; arbitrary foreign index prose is not merged into the live generated index.
257
+
258
+ ## Import Design
259
+
260
+ ### Tool
261
+
262
+ `wiki_okf_import` accepts:
263
+
264
+ - a local directory path
265
+ - `dry_run`, defaulting to `true`
266
+ - `trusted`, defaulting to `false`
267
+ - collision policy, defaulting to `error`
268
+
269
+ First-release directory imports avoid archive extraction and decompression risks. A future archive adapter can feed the same validated staging pipeline.
270
+
271
+ ### Flow
272
+
273
+ ```text
274
+ external directory
275
+ → bounded path and filesystem scan
276
+ → parse all concept and reserved documents
277
+ → validate OKF version and conformance
278
+ → calculate content hashes and collision report
279
+ → dry-run report OR immutable staged copy
280
+ → explicit review
281
+ → recoverable live-wiki transaction
282
+ → metadata rebuild
283
+ ```
284
+
285
+ ### Safety constraints
286
+
287
+ - Reject paths that escape the selected bundle root.
288
+ - Reject symlinks and non-regular files in the first release.
289
+ - Cap document count, individual file size, total bytes, frontmatter bytes, and nesting depth with conservative defaults.
290
+ - Ignore non-Markdown files unless a future adapter explicitly supports them.
291
+ - Never overwrite a live concept silently.
292
+ - Treat identical path and content hash as a no-op.
293
+ - Treat same path with different content as a conflict.
294
+ - Validate trusted imports and enforce collision rules; trusted means bypassing review, not bypassing safety.
295
+ - Copy staged bytes and hashes so approval applies to the reviewed content even if the source directory later changes.
296
+
297
+ ### Review
298
+
299
+ `wiki_okf_review` supports listing imports, showing a manifest and candidate diff, approving selected or all non-conflicting documents, rejecting an import, and explicitly resolving collisions as `skip` or `replace`.
300
+
301
+ `replace` requires an explicit choice and records the replaced content in the transaction backup. Rejected imports are removed only through this tool.
302
+
303
+ Applied import manifests retain source bundle metadata, file hashes, decisions, and timestamps under `imports/applied/`. They provide auditability but do not enter recall.
304
+
305
+ ### Transaction behavior
306
+
307
+ Cross-file filesystem writes cannot be truly atomic. The implementation therefore uses:
308
+
309
+ 1. validation before mutation
310
+ 2. temporary files for each changed document
311
+ 3. a transaction journal listing old and new hashes
312
+ 4. backups of replaced files
313
+ 5. atomic rename for each individual file
314
+ 6. startup/tool-entry recovery when an incomplete journal exists
315
+ 7. metadata rebuild only after the transaction commits
316
+
317
+ Any normal error rolls back changed files. An interrupted process leaves a journal that can deterministically finish or roll back on the next operation.
318
+
319
+ ## Export Design
320
+
321
+ `wiki_okf_export` writes to a new or empty output directory and refuses to overwrite an existing non-empty destination.
322
+
323
+ Flow:
324
+
325
+ ```text
326
+ live legacy + OKF pages
327
+ → shared parser
328
+ → in-memory legacy conversion
329
+ → full bundle validation
330
+ → deterministic hierarchical indexes and log
331
+ → portable OKF v0.2 output
332
+ → export report
333
+ ```
334
+
335
+ Export never mutates the live vault. It preserves safe concept paths, bodies, unknown document fields, standard metadata, and pi-llm-wiki extension fields. Legacy pages are converted in memory. Generated `meta/**`, pending imports, source packet internals, and embeddings are not exported.
336
+
337
+ Raw evidence remains represented through portable source concept pages and their provenance links. A later option may package selected original artifacts under an OKF `references/` convention.
338
+
339
+ ## Migration Design
340
+
341
+ `wiki_okf_migrate` defaults to dry-run. Applying migration requires an explicit `apply` flag.
342
+
343
+ Migration performs these deterministic conversions:
344
+
345
+ - add or update root OKF version metadata
346
+ - generate hierarchical indexes and root log
347
+ - convert resolvable wikilinks to Markdown links
348
+ - convert scalar legacy source references into structured `sources` entries
349
+ - preserve existing `type`, `category`, `domain`, aliases, recall triggers, timestamps, bodies, and unknown fields
350
+ - derive `description` from an existing concise summary only when no description exists; preserve the original summary field
351
+ - leave optional `generated` and `verified` absent when authorship or verification is unknown rather than inventing trust
352
+
353
+ Dry-run reports every changed file, unresolved link, invalid source reference, and conformance issue. Apply creates a dated backup of changed files, writes through the transaction journal, validates the result, and rebuilds metadata. Re-running migration after success is a no-op.
354
+
355
+ ## Recall and Trust
356
+
357
+ Existing lexical, chunk-level, pseudo-relevance-feedback, and optional semantic retrieval remain the candidate generators. Trust metadata does not create candidates.
358
+
359
+ For relevant candidates, recall computes and displays:
360
+
361
+ - human-reviewed
362
+ - machine-confirmed
363
+ - unverified
364
+ - verification-outdated when the latest verification predates the current generation timestamp
365
+ - stale when `today >= stale_after`
366
+ - deprecated when `status: deprecated`
367
+
368
+ A bounded trust factor may adjust a relevant candidate's base score within `0.90` to `1.10`:
369
+
370
+ - human-reviewed: positive adjustment
371
+ - machine-confirmed: smaller positive adjustment
372
+ - unverified: neutral
373
+ - stale: negative adjustment
374
+ - deprecated: larger negative adjustment
375
+ - verification-outdated: no verification boost and a warning
376
+
377
+ The final combined factor is clamped to the stated range. Tests must prove that trust cannot introduce a zero-relevance candidate or remove a relevant candidate from the result set solely because it is unverified, stale, or deprecated.
378
+
379
+ Recall output includes trust state, lifecycle warnings, and source links. Two-stage links-first behavior remains unchanged.
380
+
381
+ ## Lint Design
382
+
383
+ `wiki_lint` becomes the single health and conformance entry point. It reports machine-readable findings with severity, stable code, file path, field or line where available, and human guidance.
384
+
385
+ Checks include:
386
+
387
+ - OKF v0.2 document and bundle conformance
388
+ - missing or empty `type`
389
+ - invalid nested `sources`, `generated`, `verified`, lifecycle, or computation fields
390
+ - invalid actor and timestamp shapes
391
+ - stale content and outdated verification
392
+ - body footnote IDs missing from `sources[].id`
393
+ - duplicate source IDs within a document
394
+ - escaping or unsafe path-valued fields
395
+ - broken Markdown links and legacy wikilinks
396
+ - missing or stale directory indexes
397
+ - malformed logs
398
+ - duplicate concept paths and import collisions
399
+ - existing orphan, gap, and explicit contradiction-marker checks
400
+
401
+ Unknown types, absent optional trust metadata, and unknown extension fields are not errors.
402
+
403
+ Automatic fixes are limited to deterministic operations:
404
+
405
+ - regenerate indexes and log
406
+ - rebuild registry and backlinks
407
+ - normalize metadata shapes when conversion is unambiguous
408
+
409
+ Lint no longer auto-creates stub concept pages. Missing knowledge remains a reported gap until a human or ingestion flow supplies evidence.
410
+
411
+ ## Error Model
412
+
413
+ New OKF operations return stable result codes rather than relying on prose. Representative groups:
414
+
415
+ - `parse_invalid_frontmatter`
416
+ - `conformance_missing_type`
417
+ - `conformance_invalid_reserved_file`
418
+ - `path_escape`
419
+ - `path_symlink`
420
+ - `limit_file_count`
421
+ - `limit_file_size`
422
+ - `limit_total_bytes`
423
+ - `collision_changed`
424
+ - `transaction_incomplete`
425
+ - `transaction_rollback_failed`
426
+ - `migration_unresolved_link`
427
+
428
+ Tool responses provide a concise summary and store full reports under `outputs/` or import manifests. A failed validation, import, export, or migration does not leave partially indexed knowledge.
429
+
430
+ ## Tool and MCP Surface
431
+
432
+ New Pi tools:
433
+
434
+ - `wiki_okf_import`
435
+ - `wiki_okf_review`
436
+ - `wiki_okf_export`
437
+ - `wiki_okf_migrate`
438
+
439
+ Existing tools updated:
440
+
441
+ - `wiki_lint`
442
+ - `wiki_recall`
443
+ - `wiki_search`
444
+ - `wiki_status`
445
+ - `wiki_rebuild_meta`
446
+ - all page-producing ingestion, observation, retro, requirement, and trajectory flows
447
+
448
+ The MCP server exposes equivalent OKF operations and structured result codes. Slash commands may wrap tools for interactive use, but business logic remains in shared library functions rather than command handlers.
449
+
450
+ ## Testing Strategy
451
+
452
+ ### Unit tests
453
+
454
+ - nested OKF v0.2 frontmatter parsing and serialization
455
+ - alias/custom-tag/multiple-document rejection
456
+ - preservation of unknown mappings, lists, and scalar fields
457
+ - Markdown and legacy link extraction/resolution
458
+ - trust-tier and freshness derivation
459
+ - deterministic index and log generation
460
+ - legacy source and link conversion
461
+
462
+ ### Fixture tests
463
+
464
+ - conformant Google/reference-style v0.2 bundles
465
+ - current pi-llm-wiki legacy vaults
466
+ - unknown foreign types and producer extensions
467
+ - Attested Computation documents
468
+ - malformed frontmatter and reserved files
469
+ - path traversal, symlink, oversized file, excessive file count, deep nesting, and collision cases
470
+
471
+ ### Integration tests
472
+
473
+ - dry-run import makes no writes
474
+ - staged content is independent of later source-directory changes
475
+ - approval indexes content only after commit
476
+ - rejection removes staged content and never affects live recall
477
+ - trusted import still validates and detects collisions
478
+ - export converts legacy pages without modifying them
479
+ - migration apply is idempotent and recoverable
480
+ - simulated interruption recovers or rolls back through the journal
481
+ - extension and MCP produce equivalent structured outcomes
482
+
483
+ ### Recall tests
484
+
485
+ - existing lexical, chunk, and semantic tests remain green
486
+ - human-reviewed relevant pages receive only a bounded boost
487
+ - stale/deprecated relevant pages remain returned with warnings
488
+ - unverified pages are never silently hidden
489
+ - outdated verification is detected from timestamps
490
+ - pending imports never appear in recall
491
+
492
+ ### Release gates
493
+
494
+ - Reference/sample OKF v0.2 bundles validate.
495
+ - Parse/serialize preserves document bodies, paths, unknown field values, and nested metadata semantically.
496
+ - Existing vaults work without migration.
497
+ - Migration dry-run is deterministic and apply is idempotent.
498
+ - Invalid imports leave live concept files unchanged.
499
+ - Security fixtures fail with expected stable codes.
500
+ - Existing package tests, typecheck, lint, and coverage gates pass.
501
+ - Pi extension and MCP operations remain behaviorally aligned.
502
+
503
+ ## Rollout
504
+
505
+ 1. Introduce shared document model and hardened YAML parsing without changing writes.
506
+ 2. Switch all readers to dual legacy/OKF support.
507
+ 3. Switch new page producers to OKF-canonical output.
508
+ 4. Generate hierarchical bundle indexes and expand lint.
509
+ 5. Add safe import, review staging, and export.
510
+ 6. Add explicit migration.
511
+ 7. Add trust/freshness-aware recall.
512
+ 8. Publish profile documentation, migration guidance, and a competitor feature matrix.
513
+
514
+ Each stage is independently releasable. No stage forces migration.
515
+
516
+ ## Future Roadmap
517
+
518
+ 1. Self-contained graph viewer with backlinks and filters.
519
+ 2. Git snapshots, frozen read versions, rollback, and separate read/manage capabilities.
520
+ 3. Safe concept removal, deprecation workflows, and version history.
521
+ 4. DOCX, PPTX, XLSX, EPUB, image, and other broader extraction adapters.
522
+ 5. Archive import/export adapters with decompression-bomb protections.
523
+ 6. Bundle registry and multi-topic isolation.
524
+ 7. Optional Attested Computation executors and deterministic attesters behind explicit security boundaries.
525
+ 8. Retrieval benchmark suite, competitive evaluations, and larger-scale indexing.
526
+ 9. Versioned evolution of the `pi-llm-wiki/1` profile.
527
+
528
+ ## Sources
529
+
530
+ - [Google Cloud: How the Open Knowledge Format can improve data sharing](https://cloud.google.com/blog/products/data-analytics/how-the-open-knowledge-format-can-improve-data-sharing)
531
+ - [Open Knowledge Format v0.2 specification](https://github.com/GoogleCloudPlatform/knowledge-catalog/blob/main/okf/SPEC.md)
532
+ - [Google knowledge-catalog OKF reference implementation](https://github.com/GoogleCloudPlatform/knowledge-catalog/tree/main/okf)
533
+ - [Pi package: pi-okf-wiki](https://pi.dev/packages/pi-okf-wiki)
534
+ - [Pi package: llm-wiki-okf](https://pi.dev/packages/llm-wiki-okf)
535
+ - [Pi package: @d1g1tlprim8/pi-okf-wiki](https://pi.dev/packages/@d1g1tlprim8/pi-okf-wiki)
536
+ - [llm-wiki-compiler OKF round-trip guide](https://github.com/atomicstrata/llm-wiki-compiler/blob/main/docs/guides/open-knowledge-format.mdx)
537
+ - [OKF Harness](https://github.com/pumblus/okf-harness)
538
+ - [wiki-as-an-mcp](https://github.com/taikunudel/wiki-as-an-mcp)
@@ -1,6 +1,7 @@
1
- import { existsSync, readFileSync, writeFileSync } from "node:fs";
1
+ import { existsSync, readFileSync } from "node:fs";
2
2
  import { basename, join } from "node:path";
3
3
  import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
4
+ import { bootstrapVault } from "./lib/bootstrap.js";
4
5
  import { installGuardrails } from "./lib/guardrails.js";
5
6
  import { buildAgentStartInjection, normalizeSystemPrompt } from "./lib/inject.js";
6
7
  import { registerWikiModelCommand } from "./lib/model-command.js";
@@ -39,14 +40,8 @@ import {
39
40
  registerWikiDistillSkills,
40
41
  registerWikiRecallSkill,
41
42
  } from "./lib/trajectory.js";
42
- import {
43
- ensureVaultStructure,
44
- fmtDate,
45
- getVaultPaths,
46
- migrateDoubledPersonalVault,
47
- resolveVaultPaths,
48
- writeJson,
49
- } from "./lib/utils.js";
43
+ import { migrateDoubledPersonalVault, resolveVaultPaths } from "./lib/utils.js";
44
+ import { inspectWritableVault } from "./lib/vault-format.js";
50
45
  import { applySessionStartStatus } from "./lib/visible-status.js";
51
46
 
52
47
  /**
@@ -144,33 +139,18 @@ export default function (pi: ExtensionAPI) {
144
139
 
145
140
  const paths = resolveVaultPaths(process.cwd());
146
141
  if (!existsSync(join(paths.dotWiki, "config.json"))) {
147
- // Silently create the wiki vault — no UI prompts
148
- // Topic/mode will be inferred from user's first prompt via before_agent_start
149
- const root = paths.root;
150
- const vaultPaths = getVaultPaths(root);
151
- ensureVaultStructure(vaultPaths);
152
-
153
- writeJson(join(vaultPaths.dotWiki, "config.json"), {
154
- name: "pending",
155
- mode: "personal",
156
- topic: "pending",
157
- created: fmtDate(),
158
- version: "1.0",
159
- });
160
-
161
- const schema = [
162
- "# LLM Wiki Schema",
163
- "",
164
- "## Ownership Rules",
165
- "",
166
- "| Path | Owner | Rule |",
167
- "|------|-------|------|",
168
- "| raw/** | extension | immutable after capture |",
169
- "| wiki/** | model + user | editable knowledge pages |",
170
- "| meta/* | extension | auto-generated |",
171
- "| . | human + explicit request | operating rules |",
172
- ].join("\n");
173
- writeFileSync(join(vaultPaths.dotWiki, "WIKI_SCHEMA.md"), schema, "utf-8");
142
+ // Silently create the wiki vault — no UI prompts. Topic/mode will be
143
+ // inferred from the user's first prompt via before_agent_start.
144
+ const result = bootstrapVault(paths, { topic: "pending", mode: "personal" });
145
+ if (!result.ok || !result.projection.ok) {
146
+ ctx.ui.setStatus(
147
+ "llm-wiki",
148
+ `🧠 Wiki setup blocked: ${
149
+ result.ok ? result.projection.diagnostics[0].message : result.diagnostics[0].message
150
+ }`,
151
+ );
152
+ return;
153
+ }
174
154
 
175
155
  needsTopicInference = true;
176
156
  // INTENTIONALLY NOT gated by `noticesEnabled` (issues #77, #84): one-shot
@@ -180,6 +160,12 @@ export default function (pi: ExtensionAPI) {
180
160
  return;
181
161
  }
182
162
 
163
+ const writable = inspectWritableVault(paths);
164
+ if (!writable.ok) {
165
+ ctx.ui.setStatus("llm-wiki", `🧠 Wiki setup blocked: ${writable.diagnostics[0].message}`);
166
+ return;
167
+ }
168
+
183
169
  // Surface the "wiki active" badge and the active background task model
184
170
  // (issue #69), both gated by `llm-wiki.notices` (issue #77, regression
185
171
  // fixed in #83, helper extracted in #84). `ensureConfig` MUST run first so