@agent-wiki/mcp 0.22.4 → 0.22.6

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 (94) hide show
  1. package/README.md +31 -0
  2. package/dist/cli.js +177 -0
  3. package/dist/cli.js.map +1 -1
  4. package/dist/evidence-migration.js +1 -1
  5. package/dist/evidence-migration.js.map +1 -1
  6. package/dist/evidence-report.d.ts +17 -0
  7. package/dist/evidence-report.d.ts.map +1 -1
  8. package/dist/evidence-report.js +46 -2
  9. package/dist/evidence-report.js.map +1 -1
  10. package/dist/evidence-search.d.ts +71 -0
  11. package/dist/evidence-search.d.ts.map +1 -1
  12. package/dist/evidence-search.js +104 -1
  13. package/dist/evidence-search.js.map +1 -1
  14. package/dist/evidence-search.test.js +58 -1
  15. package/dist/evidence-search.test.js.map +1 -1
  16. package/dist/index.d.ts +10 -0
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +5 -0
  19. package/dist/index.js.map +1 -1
  20. package/dist/okf-compat.d.ts +152 -0
  21. package/dist/okf-compat.d.ts.map +1 -0
  22. package/dist/okf-compat.js +604 -0
  23. package/dist/okf-compat.js.map +1 -0
  24. package/dist/okf-compat.test.d.ts +2 -0
  25. package/dist/okf-compat.test.d.ts.map +1 -0
  26. package/dist/okf-compat.test.js +234 -0
  27. package/dist/okf-compat.test.js.map +1 -0
  28. package/dist/okf-export.d.ts +63 -0
  29. package/dist/okf-export.d.ts.map +1 -0
  30. package/dist/okf-export.js +655 -0
  31. package/dist/okf-export.js.map +1 -0
  32. package/dist/okf-export.test.d.ts +2 -0
  33. package/dist/okf-export.test.d.ts.map +1 -0
  34. package/dist/okf-export.test.js +469 -0
  35. package/dist/okf-export.test.js.map +1 -0
  36. package/dist/okf-import.d.ts +136 -0
  37. package/dist/okf-import.d.ts.map +1 -0
  38. package/dist/okf-import.js +471 -0
  39. package/dist/okf-import.js.map +1 -0
  40. package/dist/okf-import.test.d.ts +2 -0
  41. package/dist/okf-import.test.d.ts.map +1 -0
  42. package/dist/okf-import.test.js +339 -0
  43. package/dist/okf-import.test.js.map +1 -0
  44. package/dist/okf-trust.test.d.ts +2 -0
  45. package/dist/okf-trust.test.d.ts.map +1 -0
  46. package/dist/okf-trust.test.js +223 -0
  47. package/dist/okf-trust.test.js.map +1 -0
  48. package/dist/okf.d.ts +128 -0
  49. package/dist/okf.d.ts.map +1 -0
  50. package/dist/okf.js +659 -0
  51. package/dist/okf.js.map +1 -0
  52. package/dist/search-currency.d.ts +44 -0
  53. package/dist/search-currency.d.ts.map +1 -0
  54. package/dist/search-currency.js +111 -0
  55. package/dist/search-currency.js.map +1 -0
  56. package/dist/search.d.ts +19 -0
  57. package/dist/search.d.ts.map +1 -1
  58. package/dist/search.js.map +1 -1
  59. package/dist/server.d.ts +0 -1
  60. package/dist/server.d.ts.map +1 -1
  61. package/dist/server.js +617 -21
  62. package/dist/server.js.map +1 -1
  63. package/dist/server.test.js +772 -0
  64. package/dist/server.test.js.map +1 -1
  65. package/dist/wiki-graph.d.ts +126 -0
  66. package/dist/wiki-graph.d.ts.map +1 -0
  67. package/dist/wiki-graph.js +479 -0
  68. package/dist/wiki-graph.js.map +1 -0
  69. package/dist/wiki-graph.test.d.ts +2 -0
  70. package/dist/wiki-graph.test.d.ts.map +1 -0
  71. package/dist/wiki-graph.test.js +216 -0
  72. package/dist/wiki-graph.test.js.map +1 -0
  73. package/dist/wiki.d.ts +140 -1
  74. package/dist/wiki.d.ts.map +1 -1
  75. package/dist/wiki.js +509 -23
  76. package/dist/wiki.js.map +1 -1
  77. package/dist/worklist.d.ts +43 -0
  78. package/dist/worklist.d.ts.map +1 -0
  79. package/dist/worklist.js +147 -0
  80. package/dist/worklist.js.map +1 -0
  81. package/dist/worklist.test.d.ts +2 -0
  82. package/dist/worklist.test.d.ts.map +1 -0
  83. package/dist/worklist.test.js +233 -0
  84. package/dist/worklist.test.js.map +1 -0
  85. package/docs/evidence-envelope.md +5 -0
  86. package/docs/okf-adoption-plan.md +566 -0
  87. package/docs/okf-compat-plan.md +418 -0
  88. package/docs/okf-extensions.md +245 -0
  89. package/docs/open-knowledge-format.md +280 -0
  90. package/docs/tools.md +264 -2
  91. package/package.json +1 -1
  92. package/schemas/agent-wiki-okf.schema.json +130 -0
  93. package/skills/agent-wiki/SKILL.md +7 -0
  94. package/skills/agent-wiki/references/tools-reference.md +80 -3
@@ -0,0 +1,418 @@
1
+ # OKF v0.3 Compatibility Plan
2
+
3
+ Status: phases 0 to 4 are done. Of phase 5, the public description of the
4
+ extension keys is written; raising it upstream is open.
5
+
6
+ This plan makes `agent-wiki` able to read and write bundles of the
7
+ **Open Knowledge Format (OKF) v0.3**, the specification published by Google
8
+ Cloud in June 2026 and maintained since November 2026 at
9
+ [open-knowledge-format/open-knowledge-format](https://github.com/open-knowledge-format/open-knowledge-format).
10
+
11
+ It replaces phases 3 to 5 of [`okf-adoption-plan.md`](okf-adoption-plan.md).
12
+
13
+ ## Why
14
+
15
+ There are two things called OKF.
16
+
17
+ - **Upstream OKF** is a bundle format: a directory of Markdown files with YAML
18
+ frontmatter, where `type` is the only required key. v0.2 added provenance and
19
+ trust fields, v0.3 added conformance rules and an extension model.
20
+ - **agent-wiki's own "OKF v0.1"** (`agent-wiki.yaml`, `format-check`,
21
+ `evidence/okf-report.json`) was written a week after the upstream release and
22
+ shares the name, but not the format. It describes a whole workspace: immutable
23
+ `raw/`, mutable `wiki/`, policies, a conformance report.
24
+
25
+ Someone who reads "OKF reference implementation" in the README today expects the
26
+ upstream format and will not find it. The decision taken here:
27
+
28
+ > agent-wiki becomes an OKF v0.3 consumer and producer. What it has beyond the
29
+ > spec (sealed source hashes, source drift, contradictions, evidence envelopes)
30
+ > is expressed as OKF extension keys, not as a second format with the same name.
31
+
32
+ The upstream spec leaves room for exactly this. §12.2 lists "validity windows,
33
+ source drift signals, and a `refuted` verification event" as deferred and says to
34
+ use extension keys until the community agrees on a form. agent-wiki already
35
+ ships two of those three.
36
+
37
+ ## What upstream OKF v0.3 requires
38
+
39
+ Section numbers refer to the upstream `SPEC.md`.
40
+
41
+ - **Conformance (§11.1)** is deliberately weak: every frontmatter block parses as
42
+ a YAML mapping, and `index.md` / `log.md` follow §8 and §9 when present.
43
+ - **Concepts (§3.2)**: a `.md` file with a non-empty `type` that is not
44
+ `index.md` or `log.md`. Other `.md` files are skipped. Dot-files are not part
45
+ of the bundle.
46
+ - **Links (§6.1)**: only standard Markdown links count. `[[wikilinks]]` are
47
+ explicitly not links.
48
+ - **Paths (§6)**: a leading `/` resolves from the bundle root, anything else from
49
+ the directory of the file. Nothing outside the bundle root may be read.
50
+ - **Provenance (§5.1)**: `sources` is a list of mappings, each with a required
51
+ `resource`. An entry without it is ignored.
52
+ - **Trust (§5.2, §5.3)**: `generated: { by, at }` and `verified: [{ by, at }]`.
53
+ The trust tier counts only verifications at or after `generated.at`.
54
+ - **Lifecycle (§5.4, §5.5)**: `status` (`draft` | `stable` | `deprecated`),
55
+ `superseded_by`, and `stale_after` as an absolute instant.
56
+ - **Extensions (§4.1)**: unknown keys are allowed at every level, consumers must
57
+ not reject them, and a producer that rewrites a file must keep them. Keys that
58
+ start with `x-` are reserved for producers.
59
+ - **Bundle metadata (§8.1)**: `okf_version`, `title`, `description`, `license` in
60
+ the frontmatter of the bundle-root `index.md`.
61
+
62
+ ## Where agent-wiki stands
63
+
64
+ Checked by reading the spec against a freshly generated workspace. The upstream
65
+ validator (`skills/okf-generate/scripts/validate.py`) has not been run against
66
+ agent-wiki output yet; that is part of phase 3.
67
+
68
+ | Area | agent-wiki today | OKF v0.3 | Gap |
69
+ |------|------------------|----------|-----|
70
+ | Page frontmatter | YAML mapping with `type`, `title`, `tags` | `type` required, rest optional | None |
71
+ | Concept ID | page path without `.md` | same | None |
72
+ | Links | `[[slug]]`, `[[slug\|alias]]` | Markdown links only | Wikilinks are invisible to an OKF consumer: no graph |
73
+ | `sources` | list of strings (`raw/report.md`, URLs) | list of mappings with `resource` | String entries are ignored by an OKF consumer: no provenance |
74
+ | Sealed hashes | `sources_sha` map (since #57) | not defined | Needs an extension key |
75
+ | `index.md` | frontmatter with `type: index`, wikilink entries | root may carry bundle metadata; entries are Markdown links | Different entry syntax, no `okf_version` |
76
+ | `log.md` | frontmatter, one Markdown table | no frontmatter, `## YYYY-MM-DD` groups | Not conformant with §9 |
77
+ | `timeline.md` | has `type: timeline` | not a reserved name | Would be read as a concept |
78
+ | Authorship and review | `created`, `updated` | `generated`, `verified`, trust tiers | No `generated`, no way to record a review |
79
+ | Staleness | relative, from lint config | absolute `stale_after` | Different model |
80
+ | Lifecycle | none per page | `status`, `superseded_by` | Not present |
81
+ | Contradictions, drift | workspace dot-files (`.contradiction-index.json`, `.source-drift-index.json`) | deferred (§12.2) | Dot-files are outside the bundle, so this state is not portable |
82
+ | Bundle metadata | `agent-wiki.yaml` manifest | root `index.md` frontmatter | Different place |
83
+ | Attested computations (§10) | none | optional | Out of scope; keys must survive a round trip |
84
+
85
+ The native `wiki/` directory already passes rule 1 of §11.1. It fails rule 2
86
+ because of `log.md`. Passing conformance is the small part. Being *useful* to an
87
+ OKF consumer needs the links and the `sources` shape.
88
+
89
+ ## Design
90
+
91
+ ### Native storage does not change
92
+
93
+ agent-wiki keeps `wiki/` + `raw/`, wikilinks, and string `sources`. Compatibility
94
+ is reached in two ways:
95
+
96
+ 1. the reader accepts OKF shapes as well as its own (phase 1), and
97
+ 2. an exporter writes a conformant bundle (phase 3).
98
+
99
+ Rewriting every existing wiki to Markdown links would break every user for a
100
+ format that is at v0.3 and still allows breaking changes before 1.0 (§12).
101
+
102
+ ### Exported bundle layout
103
+
104
+ ```
105
+ <bundle>/
106
+ index.md # bundle metadata + listing, generated in §8 form
107
+ log.md # converted to §9 form
108
+ <page>.md ... # wiki pages, same relative paths
109
+ <dir>/index.md # per directory, no frontmatter
110
+ references/raw/... # cited raw files with their .meta.yaml sidecars;
111
+ # raw Markdown as <name>.md.txt (see phase 3)
112
+ ```
113
+
114
+ `timeline.md` and `evidence-report.md` are not exported: both are derived and
115
+ would otherwise be read as concepts.
116
+
117
+ ### Frontmatter mapping
118
+
119
+ | agent-wiki | OKF v0.3 on export | Notes |
120
+ |------------|--------------------|-------|
121
+ | `type`, `title`, `tags` | same | |
122
+ | `sources: [raw/x.md]` | `sources: [{ resource: /references/raw/x.md }]` | In-bundle path |
123
+ | `sources: [https://…]` | `sources: [{ resource: https://… }]` | |
124
+ | `sources_sha[entry]` | `x-agent-wiki-sha256` inside that `sources` entry | Extensions are allowed inside entries (§4.1) |
125
+ | `derived_from: [a.md]` | extra `sources` entries with `resource: /a.md` | Becomes a graph edge (§6.4) |
126
+ | `updated` | `generated.at` | Approximation: `updated` also moves on trivial edits |
127
+ | (producer) | `generated.by: agent-wiki/<version>` | See open decision 5 |
128
+ | `created` | `x-agent-wiki-created` | |
129
+ | `synthesis`, `unsupported`, `legacyUnsupported` | `x-agent-wiki-synthesis`, `x-agent-wiki-unsupported`, … | Not mapped to `status`; see open decision 4 |
130
+ | `reconciles`, `reconciled_claims`, `decisions` | `x-agent-wiki-reconciles`, … | Per-claim decisions do not deprecate a page, so no `superseded_by` |
131
+ | manifest `name`, `description`, `license` | root `index.md`: `title`, `description`, `license`, `okf_version: "0.3"` | |
132
+ | manifest `wiki_policy.stale_after_days` | `stale_after` = `updated` + days | Only when the policy is set. The spec says not to invent a review date |
133
+
134
+ State that lives in workspace dot-files is computed at export time and written
135
+ onto the concept, so it travels with the bundle:
136
+
137
+ | agent-wiki state | Extension key on the concept |
138
+ |------------------|------------------------------|
139
+ | open contradictions | `x-agent-wiki-disputed-by: [/other.md]` |
140
+ | source drift | `x-agent-wiki-source-drift: [{ resource, reason, newer }]` |
141
+
142
+ ### Links
143
+
144
+ - Export: `[[slug]]` becomes `[Title](relative/path.md)`, `[[slug|alias]]` becomes
145
+ `[alias](relative/path.md)`. An unresolved wikilink becomes plain text and is
146
+ listed in the export report (changed in phase 3, see there).
147
+ - Read: the link extractor recognises Markdown links to in-bundle `.md` files in
148
+ addition to wikilinks. `wiki_graph`, lint (orphans, broken links) and
149
+ auto-linking then see one graph whichever syntax a page uses. An imported
150
+ bundle is not rewritten.
151
+
152
+ ### Reading OKF shapes (consumer rules, §11.2)
153
+
154
+ - `sources` entries may be strings or mappings; a mapping contributes its
155
+ `resource`. One mapping without the list dash is a list of one.
156
+ - A scalar `tags` is one tag. Null, empty string and empty list mean absent.
157
+ - `index.md` and `log.md` are never concepts, whatever their frontmatter.
158
+ - Unknown keys are kept on every write. `wiki_write` already keeps unknown
159
+ top-level keys; nested ones need a test.
160
+ - A path that resolves outside the bundle root is external and is not read.
161
+ - `status: deprecated` and a past `stale_after` lower the search envelope the way
162
+ contradictions and source drift do. An unparseable `stale_after` is never
163
+ treated as fresh.
164
+ - The trust tier (unverified, machine-confirmed, human-reviewed) is computed
165
+ from current `verified` events and shown in read results. It does not raise
166
+ envelope confidence in the first version.
167
+
168
+ ### Per-claim provenance
169
+
170
+ The old plan had `evidence/claim-provenance.json`. OKF already has a mechanism:
171
+ a footnote whose label is the `id` of a `sources` entry (§5.1). agent-wiki adopts
172
+ that and drops the separate file.
173
+
174
+ ### The name
175
+
176
+ agent-wiki's own format stops being called "OKF". Proposed: the
177
+ **agent-wiki package profile**, defined as "an OKF v0.3 bundle plus the
178
+ `x-agent-wiki-*` extension keys and a `raw/` evidence layer". The manifest keeps
179
+ working: `format: agent-wiki-okf` stays accepted for existing workspaces.
180
+
181
+ ## Phases
182
+
183
+ ### Phase 0: naming and documentation
184
+
185
+ - README and both OKF documents say what upstream OKF is and how agent-wiki
186
+ relates to it.
187
+ - The existing manifest, `format-check` and report are renamed in prose.
188
+
189
+ Done when a reader of the README can tell in one screen that agent-wiki reads and
190
+ writes upstream OKF, and what it adds.
191
+
192
+ ### Phase 1: tolerant reader
193
+
194
+ - `sources` as strings or mappings; single-item coercions.
195
+ - Markdown links counted as links.
196
+ - `status`, `superseded_by`, `stale_after` read and reflected in the envelope.
197
+ - Trust tier computed and shown.
198
+ - Round-trip preservation of unknown and nested keys.
199
+
200
+ Done when the four upstream sample bundles (`acme_retail`, `crypto_bitcoin`,
201
+ `ga4`, `stackoverflow`) can be placed in `wiki/` and searched, read, linted and
202
+ graphed without errors, and a `wiki_write` to one of their concepts loses no key.
203
+
204
+ Result: done. The four bundles load with every file parsed, no broken links and
205
+ no orphans; lint reports only missing sources on concepts that have none. The
206
+ regression test uses a small hand-written v0.3 bundle rather than a vendored
207
+ copy of the upstream ones (open decision 7). Not covered here: rebuilding the
208
+ index rewrites every `index.md` in agent-wiki's own form (root bundle metadata is
209
+ kept); making that output follow §8 belongs to open decision 6.
210
+
211
+ ### Phase 2: import
212
+
213
+ - `agent-wiki import --format okf <dir|archive>`.
214
+ - Checks §11.1 before copying; refuses paths that leave the bundle root.
215
+ - Reports what was imported: concepts, skipped files, warnings.
216
+
217
+ Done when importing a sample bundle into an empty workspace gives the same search
218
+ and graph results as phase 1, and a malformed bundle is refused with the rule it
219
+ breaks.
220
+
221
+ Result: done. The four upstream sample bundles import with every copied file
222
+ byte-identical, no findings, no broken links and no orphans. Also exposed as
223
+ `wiki_admin` `action: "import"`. Decisions taken on the way:
224
+
225
+ - The bundle root becomes the wiki root. Importing below a subdirectory would
226
+ change what a leading `/` means, so it is not offered.
227
+ - The bundle's root `log.md` is not imported: agent-wiki appends its own
228
+ operation log to that file in a different form. The bundle's history is
229
+ therefore lost on import. Carrying it over belongs to open decision 6.
230
+ - Archives: `.zip` only. A tarball has to be unpacked first.
231
+ - A wiki holds one bundle root.
232
+
233
+ ### Phase 3: export
234
+
235
+ - `agent-wiki export --format okf --out <dir>`, with the mapping above.
236
+ - CI runs the upstream validator on the exported fixture with `--strict`.
237
+ - Round-trip test: export, import into an empty workspace, export again; the two
238
+ bundles are equal.
239
+
240
+ Done when the upstream validator reports no errors and no warnings on an exported
241
+ workspace that includes grounded, synthesis, reconciliation and drifted pages.
242
+
243
+ Result: done. Also exposed as `wiki_admin` `action: "export"`. CI exports the test
244
+ fixture and runs the upstream validator on it with `--strict`, at a pinned commit
245
+ of the spec repository. What turned out differently from the design above, each
246
+ because the validator (or the round trip) required it:
247
+
248
+ - **Unresolved wikilinks become plain text, not links.** The validator warns
249
+ about a link whose target is not in the bundle (W115), so a bundle with
250
+ dangling links does not pass `--strict`. The export report lists them.
251
+ - **Raw Markdown is copied as `<name>.md.txt`.** Every `.md` file in a bundle is
252
+ either a concept or a warning (W120), and a raw file with a `type` in its
253
+ frontmatter would become a concept. The bytes are unchanged, so the sealed
254
+ hash still matches. Other raw files keep their names. If raw/ already has a
255
+ file called `<name>.md.txt`, the Markdown file goes to `<name>.md.raw.txt`.
256
+ - **`derived_from` entries are marked.** They become `sources` entries with
257
+ `x-agent-wiki-relation: derived_from`, so they can be told apart from cited
258
+ evidence when the bundle is read back.
259
+ - **Extension keys are read back.** When agent-wiki writes such a page it moves
260
+ the keys to their native names, so the file is native again. A page that carries `x-agent-wiki-synthesis`,
261
+ `x-agent-wiki-reconciles` and so on is read as if it had the native key. Without
262
+ this an exported reconciliation page stopped settling its contradiction after
263
+ the import.
264
+ - **Pages already in OKF form are copied byte for byte.** Only a page with
265
+ something to translate is re-serialised. Exporting an imported bundle
266
+ therefore gives the bundle back.
267
+ - **The round trip is equal except for `log.md`.** The log is the history of the
268
+ workspace that was exported, and an import does not carry it over (see phase
269
+ 2), so the second bundle has the second workspace's log.
270
+ - **`stale_after` and `generated.at`** come from `updated`. A page without
271
+ `updated` gets neither.
272
+
273
+ Carried state on import: `x-agent-wiki-source-drift` is read back. The importing
274
+ workspace has no seal to check the page against, so the finding of the exporting
275
+ workspace stays in force (lint reports it, search lowers the envelope) until the
276
+ page is written again. `x-agent-wiki-disputed-by` is not read back, because the
277
+ importing workspace detects contradictions itself from the same pages.
278
+
279
+ Not done here: the native `log.md` and `index.md` keep their forms (open decision
280
+ 6).
281
+
282
+ ### Phase 4: trust
283
+
284
+ - `wiki_write` records `generated`.
285
+ - A way to record a review, which appends a `verified` event.
286
+ - The trust tier takes part in the evidence envelope.
287
+
288
+ Done when a page reviewed by a human and then rewritten by an agent drops from
289
+ human-reviewed to unverified, as §5.3 requires.
290
+
291
+ Result: done.
292
+
293
+ - `wiki_write` writes `generated: { by, at }`. `by` is the new `actor` argument
294
+ or `agent-wiki/<version>` (open decision 5: both, the tool by default). `at`
295
+ moves only when the body changes beyond whitespace and `[[wikilink]]` markup
296
+ (code and Markdown links are compared exactly), so
297
+ auto-linking and frontmatter edits do not invalidate a review (§5.2).
298
+ - `agent-wiki verify <page> --by <actor>` and `wiki_admin` `action: "verify"`
299
+ append a `verified` event and change nothing else.
300
+ - Both fields belong to the server. `wiki_write` ignores what the submitted
301
+ frontmatter says about them, so a write cannot add or drop a review.
302
+ - Envelope: trust never raises confidence. `wiki_search` takes `min_trust`;
303
+ when the top cited page is below it, `strong` becomes `weak`. A review that
304
+ predates the last change is named in the rationale and marked
305
+ `review_lapsed` on the result, without lowering confidence: such a page is
306
+ not worse than one nobody ever reviewed.
307
+ - A page without `generated` whose text does not change on a write stays
308
+ without it: how that text was made is not known.
309
+
310
+ Not done: there is no check that the caller of `verify` is who the actor says.
311
+ OKF calls the tiers advisory (§5.3); every review is written to the operation
312
+ log.
313
+
314
+ ### Phase 5: upstream
315
+
316
+ - Describe the `x-agent-wiki-*` keys for source drift and contradictions in a
317
+ short public document.
318
+ - Raise them upstream as input to the items §12.2 defers.
319
+
320
+ This is the phase where agent-wiki can contribute something the spec does not
321
+ have yet.
322
+
323
+ Result: the document is written, [`okf-extensions.md`](okf-extensions.md). It
324
+ defines every `x-agent-wiki-*` key and says, for source drift and contradictions,
325
+ what a field in the specification would have to cover. Raising it upstream is
326
+ the owner's decision and has not been done.
327
+
328
+ ## Open decisions
329
+
330
+ These need the owner's call before the phase that depends on them.
331
+
332
+ 1. **Name of the agent-wiki profile** (phase 0). Proposed: "agent-wiki package
333
+ profile". The point is only that it is not called OKF.
334
+ 2. **Native link syntax** (phase 1). Proposed: keep wikilinks, read both, convert
335
+ on export. The alternative, switching native storage to Markdown links,
336
+ removes the conversion but breaks existing wikis.
337
+ 3. **Raw files in an export** (phase 3). Proposed: copy cited raw files to
338
+ `references/raw/`. A raw Markdown file that itself has frontmatter with `type`
339
+ would then be read as a concept; the exporter lists such files in its report.
340
+ The alternative is to export only URLs and hashes, which keeps the bundle
341
+ small and loses portability of the evidence.
342
+ 4. **`unsupported` pages and `status`** (phase 3). Proposed: do not map to
343
+ `status: draft`. "No sources" and "not yet reviewed" are different statements.
344
+ 5. **`generated.by`** (phase 3 and 4). Proposed: `agent-wiki/<version>`, the tool
345
+ that wrote the file. The alternative is an actor passed by the caller, which
346
+ says more and can be wrong.
347
+ 6. **Native `log.md` and `index.md`** (after phase 3). Changing them to the §8 and
348
+ §9 forms would make an unexported `wiki/` directory conformant by itself. It
349
+ changes generated files that users may have tooling around.
350
+ 7. **Upstream fixtures** (phase 1). The sample bundles are Apache 2.0. Either
351
+ vendor a copy under `test/fixtures/` or fetch them in CI.
352
+
353
+ 8. **A Markdown parser instead of the hand-written link scanner** (any time).
354
+ Phase 1 reads Markdown links with a scanner in `src/okf-compat.ts`, because
355
+ the project has no Markdown parser dependency. It covers inline, reference
356
+ and shortcut links, destinations in angle brackets or with balanced
357
+ parentheses, backslash escapes, and code that must be skipped: fenced (by
358
+ length and character, also inside blockquotes and list items), indented, and
359
+ code spans, including across a line break. It is not a CommonMark
360
+ implementation, and review of #62 kept finding further edge cases, two per
361
+ round. The decision taken for now: stop there and merge.
362
+
363
+ The alternative is to parse the page body with a real parser and walk the
364
+ link nodes.
365
+
366
+ - Candidates: `micromark` with `mdast-util-from-markdown` (CommonMark and,
367
+ with its extension, the GFM tables and footnotes OKF §4.2 names), or
368
+ `markdown-it`.
369
+ - Gain: links, reference definitions and every kind of code are found by
370
+ construction, so this class of bug ends. The parser also gives exact
371
+ positions, which the graph's snippets and the exporter (phase 3: rewriting
372
+ `[[wikilinks]]` as Markdown links) both need. The same pass could read
373
+ OKF footnotes for per-claim provenance.
374
+ - Cost: one more runtime dependency in a package that so far parses pages
375
+ with regular expressions; a parse of every page on every index build, so
376
+ it needs measuring on a large wiki; `[[wikilinks]]` are not Markdown and
377
+ still need their own handling.
378
+ - What stays the same: `extractLinks` and `scanLinks` keep their signatures,
379
+ so only the inside of `okf-compat.ts` changes, and the existing tests are
380
+ the acceptance suite.
381
+
382
+ Reasons to pick it up: phase 3 turns out to need positions the scanner
383
+ cannot give reliably, or a real bundle hits one of the gaps below.
384
+
385
+ Known gaps of the scanner at the time of merging:
386
+ - A fence opened inside a blockquote and never closed should end where the
387
+ blockquote ends. The scanner keeps it open to the end of the page, so
388
+ links after such a quote are missed. (Reported in the last review round of
389
+ #62, not fixed.)
390
+ - Link text with brackets nested more than one level deep.
391
+ - HTML blocks and inline HTML are read as text.
392
+ - Setext headings, tables and other block structure are not interpreted;
393
+ only code is told apart from prose.
394
+
395
+ ## Not in scope
396
+
397
+ - Attested computations (§10): keys are preserved, nothing is executed.
398
+ - Serving bundles to Google Knowledge Catalog or any other catalog.
399
+ - Changing the evidence envelope contract.
400
+ - Chasing each pre-1.0 spec revision as it lands. Each new upstream version gets
401
+ its own small issue.
402
+
403
+ ## Relation to the earlier adoption plan
404
+
405
+ | Earlier plan | Now |
406
+ |--------------|-----|
407
+ | Phase 0 to 2: docs, manifest, `format-check`, package report | Stay, renamed (phase 0 here) |
408
+ | Phase 3: evidence export files | Replaced by extension keys on concepts and OKF footnotes |
409
+ | Phase 4: export and import | Phases 2 and 3 here, targeting upstream OKF |
410
+ | Phase 5: compatibility and governance | Follows upstream versioning (§12) |
411
+
412
+ ## References
413
+
414
+ - OKF v0.3 specification: https://github.com/open-knowledge-format/open-knowledge-format/blob/main/SPEC.md
415
+ - OKF v0.3 announcement: https://cloud.google.com/blog/products/data-analytics/introducing-okf-v0-3
416
+ - Upstream validator: `skills/okf-generate/scripts/validate.py` in the spec repository
417
+ - Earlier plan: [`okf-adoption-plan.md`](okf-adoption-plan.md)
418
+ - Format thesis: [`open-knowledge-format.md`](open-knowledge-format.md)
@@ -0,0 +1,245 @@
1
+ # agent-wiki extension keys for OKF v0.3
2
+
3
+ agent-wiki exports a workspace as an [Open Knowledge Format](https://github.com/open-knowledge-format/open-knowledge-format)
4
+ v0.3 bundle. Whatever OKF has a field for is written with that field. The rest is
5
+ written under extension keys with the prefix `x-agent-wiki-`, as §4.1 of the
6
+ specification asks producers to do.
7
+
8
+ This document defines those keys. It is written for two readers: someone who
9
+ receives a bundle that agent-wiki exported and wants to know what the keys mean,
10
+ and someone who is working out how OKF itself could express the same things.
11
+ §12.2 of the specification defers two of them, source drift signals and typed
12
+ relationships between concepts, and says to use extension keys until there is
13
+ agreement on one form. The keys below are one form that is implemented and in use.
14
+
15
+ A consumer that does not know these keys loses nothing it had before. They are
16
+ ordinary extension keys, and the bundle that agent-wiki's own build exports is
17
+ checked on every change with the specification's validator in strict mode.
18
+
19
+ ## Summary
20
+
21
+ | Key | Where | Meaning |
22
+ |-----|-------|---------|
23
+ | [`x-agent-wiki-source-drift`](#source-drift) | concept | Cited evidence has changed since the concept was written |
24
+ | [`x-agent-wiki-sha256`](#sealed-sources) | `sources` entry | Hash of the cited file when the concept was written |
25
+ | [`x-agent-wiki-disputed-by`](#contradictions) | concept | Other concepts that state something else |
26
+ | [`x-agent-wiki-reconciles`, `-reconciled-claims`, `-decisions`](#reconciliation) | concept | A recorded decision between two disputing concepts |
27
+ | [`x-agent-wiki-relation`](#derivation) | `sources` entry | The entry is a concept this one was derived from |
28
+ | [`x-agent-wiki-synthesis`, `-unsupported`, `-legacy-unsupported`](#grounding) | concept | How the concept is grounded |
29
+ | `x-agent-wiki-created` | concept | When the page was first written (`generated.at` is the last change) |
30
+
31
+ Paths in these keys follow §6.2: a leading `/` means the bundle root, and each
32
+ segment is percent-encoded.
33
+
34
+ ## Source drift
35
+
36
+ **The problem.** A concept is written from a source. Later the source changes.
37
+ The concept still reads well, still has its `sources`, and may still carry a
38
+ human review, but it now describes a document that no longer says that.
39
+ `stale_after` does not cover this: it is a date somebody chose in advance, not
40
+ an observation that the ground has moved.
41
+
42
+ **Sealing.** To notice drift, the producer has to know what the source looked
43
+ like. When agent-wiki writes a concept, it records the SHA-256 of every cited
44
+ file it can read, inside the `sources` entry:
45
+
46
+ <a id="sealed-sources"></a>
47
+
48
+ ```yaml
49
+ sources:
50
+ - resource: /references/raw/q3-report.pdf
51
+ x-agent-wiki-sha256: 883a4cbc4435cdb0709436968a643027bbf229fee1ffee4ae1173cb8bd3fd05c
52
+ - resource: https://example.com/q3 # not sealed: nothing local to hash
53
+ ```
54
+
55
+ - The hash is of the file's bytes when the concept was last written. It is
56
+ renewed on every write of the concept.
57
+ - An entry without the key is not sealed. Nothing can be said about drift for it.
58
+ - The copy under `references/raw/` in an exported bundle is the file as it is at
59
+ export time. It matches the hash exactly when there is no drift.
60
+
61
+ **The signal.** When a sealed source no longer matches, the concept carries:
62
+
63
+ ```yaml
64
+ x-agent-wiki-source-drift:
65
+ - resource: /references/raw/q3-report.pdf
66
+ reason: changed
67
+ ```
68
+
69
+ Each item has:
70
+
71
+ | Field | Required | Meaning |
72
+ |-------|----------|---------|
73
+ | `resource` | yes | The `sources` entry concerned, by its `resource` |
74
+ | `reason` | yes | `changed`, `missing` or `superseded` |
75
+ | `newer` | no | With `superseded`: the path of the newer version |
76
+
77
+ | `reason` | Meaning |
78
+ |----------|---------|
79
+ | `changed` | The file exists and its content differs from the sealed hash |
80
+ | `missing` | The file is gone |
81
+ | `superseded` | The file is unchanged, but a newer version of the same document was added after the concept was written (`report_v2.xlsx` next to `report.xlsx`) |
82
+
83
+ **Rules for producers.**
84
+
85
+ - Write the key only from an observation: a hash that was compared, a file that
86
+ was looked for. Do not write it from age or from a guess.
87
+ - Remove the key when the concept is written again. Writing is the author's
88
+ re-check against the current source, and it re-seals.
89
+ - The key is absent when there is no drift. An empty list means the same.
90
+
91
+ **Rules for consumers.**
92
+
93
+ - Treat a concept with the key as *not confirmed against its current sources*.
94
+ It is not wrong, and it is not deprecated. agent-wiki lowers the confidence of
95
+ an answer that rests on such a concept from strong to weak and names the
96
+ source.
97
+ - A consumer that has the source files and the hashes can check for itself and
98
+ need not rely on the key. A consumer that has only the bundle cannot, and for
99
+ it the key is the only way the finding travels. For that reason agent-wiki
100
+ keeps a received finding in force until the concept is rewritten.
101
+ - Drift is independent of the trust tier (§5.3). A concept can be
102
+ human-reviewed and drifted at once: the review was of the text against the
103
+ source as it was.
104
+
105
+ **Relation to the specification.** §12.2 names "source drift signals" as
106
+ deferred. Two smaller pieces would cover what the keys above do:
107
+
108
+ 1. an optional content hash on a `sources` entry, and
109
+ 2. a concept-level list of sources that have moved on, with a reason.
110
+
111
+ A `refuted` verification event, deferred in the same sentence, is a different
112
+ thing: it records that somebody checked and found the concept wrong. Drift
113
+ records that nobody has checked since the source changed.
114
+
115
+ ## Contradictions
116
+
117
+ **The problem.** Two concepts in one bundle say different things about the same
118
+ fact: one gives a release year of 2015, the other 2018. Each is well-formed and
119
+ sourced. A consumer that retrieves only one of them answers with confidence and
120
+ has no way to know there is a second opinion in the same bundle.
121
+
122
+ **The signal.** Each concept in an open contradiction names the others:
123
+
124
+ ```yaml
125
+ x-agent-wiki-disputed-by:
126
+ - /yolo-history.md
127
+ ```
128
+
129
+ - The value is a list of paths to concepts in the bundle.
130
+ - The relation is symmetric: if A lists B, B lists A.
131
+ - The key says *that* the concepts disagree, not about what. The claim itself is
132
+ in the text of the two concepts.
133
+ - A contradiction that has been decided (see below) is not listed.
134
+
135
+ **Rules for consumers.**
136
+
137
+ - When an answer rests on a concept with the key, read the listed concepts too,
138
+ or say that the bundle disagrees with itself on this point. agent-wiki lowers
139
+ the confidence of such an answer from strong to weak and names the other
140
+ concept.
141
+ - A consumer with its own way of detecting contradictions should prefer its own
142
+ result, since it reflects the concepts as they are now. agent-wiki does this:
143
+ it does not read the key back, it detects again.
144
+
145
+ **How agent-wiki detects.** By comparing statements of the same shape (a date, a
146
+ number with a unit) between concepts that share a tag or link to each other. The
147
+ method is not part of this definition. The key only carries the result.
148
+
149
+ <a id="reconciliation"></a>
150
+
151
+ **Recording a decision.** When someone decides which of two concepts is right,
152
+ agent-wiki writes a third concept that records the decision. Neither of the two
153
+ is edited. The deciding concept carries:
154
+
155
+ ```yaml
156
+ x-agent-wiki-reconciles:
157
+ - yolo-history.md
158
+ - yolo-origin.md
159
+ x-agent-wiki-reconciled-claims:
160
+ - released in year
161
+ x-agent-wiki-decisions:
162
+ - claim: released in year
163
+ winner: yolo-origin.md
164
+ superseded: yolo-history.md
165
+ kept_excerpt: released in 2015
166
+ superseded_excerpt: released in 2018
167
+ note: The original paper is dated 2015.
168
+ decided_at: "2026-12-06T03:06:12.852Z"
169
+ ```
170
+
171
+ - `x-agent-wiki-reconciles`: the two concepts the decision is about.
172
+ - `x-agent-wiki-reconciled-claims`: the claims it covers. A new disagreement
173
+ between the same two concepts is not covered and is reported again.
174
+ - `x-agent-wiki-decisions`: one item per claim, with what was kept, what was set
175
+ aside, and why.
176
+
177
+ The losing concept is not given `status: deprecated` or `superseded_by`. A
178
+ decision is about one claim. The rest of that concept may be right, and
179
+ deprecating it would withdraw all of it.
180
+
181
+ **Relation to the specification.** OKF has no statement that two concepts
182
+ conflict. `superseded_by` is the nearest field, and it means something else:
183
+ this concept is replaced as a whole. Typed relationships between concepts are
184
+ deferred in §12.2; "disputes" and "decides between" are two relationship types
185
+ that an agent-maintained corpus needs early, because agents add concepts faster
186
+ than anyone reads them side by side.
187
+
188
+ ## Derivation
189
+
190
+ A synthesis concept is written from other concepts, not from outside sources.
191
+ Those concepts are listed in `sources`, where §6.4 makes them graph edges, and
192
+ marked so that they can be told apart from cited evidence:
193
+
194
+ <a id="derivation"></a>
195
+
196
+ ```yaml
197
+ sources:
198
+ - resource: /yolo-origin.md
199
+ x-agent-wiki-relation: derived_from
200
+ - resource: /yolo-history.md
201
+ x-agent-wiki-relation: derived_from
202
+ ```
203
+
204
+ `derived_from` is the only value in use. An entry without the key is evidence.
205
+
206
+ ## Grounding
207
+
208
+ <a id="grounding"></a>
209
+
210
+ | Key | Meaning |
211
+ |-----|---------|
212
+ | `x-agent-wiki-synthesis: true` | The concept combines other concepts and is not expected to cite outside sources |
213
+ | `x-agent-wiki-unsupported: true` | The concept has no sources and is not a synthesis |
214
+ | `x-agent-wiki-legacy-unsupported: true` | The same, for a concept written before sources were required |
215
+
216
+ These are not mapped to `status`. "Has no sources" and "is a draft" are
217
+ different statements: a draft may be fully sourced, and an unsourced page may be
218
+ what the author considers finished.
219
+
220
+ ## What agent-wiki does with the keys on import
221
+
222
+ | Key | On import |
223
+ |-----|-----------|
224
+ | `-source-drift` | In force until the concept is rewritten: reported by lint, lowers answer confidence |
225
+ | `-sha256` | Kept in the file; not checked, because the importing workspace has no original to compare with |
226
+ | `-disputed-by` | Not read; contradictions are detected again |
227
+ | `-reconciles`, `-reconciled-claims`, `-decisions` | Read: the decision still settles its contradiction |
228
+ | `-relation` | Read: the concept is derived from the marked entries |
229
+ | `-synthesis`, `-unsupported`, `-legacy-unsupported`, `-created` | Read as the native fields |
230
+
231
+ When agent-wiki itself rewrites an imported concept, it moves these keys back to
232
+ its native field names. The next export writes them as extension keys again.
233
+
234
+ ## Stability
235
+
236
+ The keys are defined by the agent-wiki version that wrote the bundle, which is
237
+ recorded in `generated.by` (`agent-wiki/<version>`). They may change while OKF
238
+ is below 1.0. If OKF adopts a field for any of them, agent-wiki will write that
239
+ field and keep reading the extension key.
240
+
241
+ ## See also
242
+
243
+ - [`okf-compat-plan.md`](okf-compat-plan.md): how agent-wiki reads and writes OKF v0.3
244
+ - [`tools.md`](tools.md): the export and import commands, source drift, contradictions
245
+ - [OKF v0.3 specification](https://github.com/open-knowledge-format/open-knowledge-format), §4.1 (extension keys), §5 (provenance and trust), §12.2 (deferred items)