@dikolab/kbdb 0.4.3 → 0.6.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 (224) hide show
  1. package/CLA.md +68 -0
  2. package/LICENSE +676 -12
  3. package/LICENSING.md +58 -0
  4. package/README.md +50 -27
  5. package/README.md.bak +320 -0
  6. package/dist/README.md +320 -0
  7. package/dist/{chunk-BJXEVALU.mjs → chunk-QLJ33C74.mjs} +44 -44
  8. package/dist/chunk-QLJ33C74.mjs.map +7 -0
  9. package/dist/cli.cjs +550 -232
  10. package/dist/cli.cjs.map +4 -4
  11. package/dist/cli.d.ts +0 -8
  12. package/dist/cli.mjs +483 -154
  13. package/dist/cli.mjs.map +4 -4
  14. package/dist/kbdb-worker.cjs +36 -5
  15. package/dist/kbdb-worker.cjs.map +3 -3
  16. package/dist/mod.cjs +89 -30
  17. package/dist/mod.cjs.map +4 -4
  18. package/dist/mod.mjs +88 -30
  19. package/dist/mod.mjs.map +4 -4
  20. package/dist/src/cli.d.ts +0 -8
  21. package/dist/src/shared/cli/constants/defaults.constant.d.ts +1 -1
  22. package/dist/src/shared/cli/constants/recfile-command-field-map.constant.d.ts +8 -0
  23. package/dist/src/shared/cli/constants/recfile-field-maps.constant.d.ts +21 -0
  24. package/dist/src/shared/cli/functions/compute-directory-level.function.d.ts +14 -0
  25. package/dist/src/shared/cli/functions/dispatch-command.function.d.ts +2 -28
  26. package/dist/src/shared/cli/functions/format-command-output.function.d.ts +14 -0
  27. package/dist/src/shared/cli/functions/format-db-not-found.function.d.ts +20 -0
  28. package/dist/src/shared/cli/functions/format-output.function.d.ts +1 -0
  29. package/dist/src/shared/cli/functions/format-recfile-output.function.d.ts +11 -0
  30. package/dist/src/shared/cli/functions/render-recfile-value.function.d.ts +11 -0
  31. package/dist/src/shared/cli/functions/resolve-db-dir.function.d.ts +24 -0
  32. package/dist/src/shared/cli/functions/resolve-recfile-key.function.d.ts +9 -0
  33. package/dist/src/shared/cli/functions/run-db-path.function.d.ts +10 -0
  34. package/dist/src/shared/cli/functions/run-export.function.d.ts +8 -4
  35. package/dist/src/shared/cli/functions/run-import.function.d.ts +4 -0
  36. package/dist/src/shared/cli/functions/run-learn.function.d.ts +12 -0
  37. package/dist/src/shared/cli/index.d.ts +4 -1
  38. package/dist/src/shared/cli/typings/cli-options.interface.d.ts +9 -2
  39. package/dist/src/shared/cli/typings/db-resolution.interface.d.ts +9 -0
  40. package/dist/src/shared/cli/typings/recfile-field-map.type.d.ts +10 -0
  41. package/dist/src/shared/version/constants/version.constant.d.ts +1 -1
  42. package/dist/src/shared/wasm-codec/functions/decode-option-u8.function.d.ts +9 -0
  43. package/dist/src/shared/wasm-codec/functions/decode-section-records.function.d.ts +4 -0
  44. package/dist/src/shared/wasm-codec/functions/encode-add-section-params.function.d.ts +2 -45
  45. package/dist/src/shared/wasm-codec/functions/encode-update-section-params.function.d.ts +10 -1
  46. package/dist/src/shared/wasm-codec/index.d.ts +1 -1
  47. package/dist/src/shared/wasm-codec/typings/add-section-input.model.d.ts +6 -0
  48. package/dist/src/shared/wasm-codec/typings/section-record-trailing.model.d.ts +5 -0
  49. package/dist/src/shared/wasm-codec/typings/section-record.model.d.ts +5 -0
  50. package/dist/src/shared/worker-client/functions/build-deno-permissions.function.d.ts +11 -0
  51. package/dist/src/shared/worker-client/functions/read-crash-reason.function.d.ts +9 -0
  52. package/dist/src/shared/worker-client/functions/resolve-spawn-script.function.d.ts +6 -0
  53. package/dist/src/shared/worker-client/functions/spawn-daemon.function.d.ts +1 -1
  54. package/dist/src/shared/worker-client/typings/section.model.d.ts +5 -0
  55. package/dist/src/shared/worker-client/typings/worker-client-options.interface.d.ts +0 -6
  56. package/dist/src/shared/worker-daemon/functions/count-files.function.d.ts +12 -0
  57. package/dist/src/shared/worker-daemon/functions/handle-import.function.d.ts +2 -0
  58. package/dist/src/shared/worker-daemon/functions/handle-read-ops.function.d.ts +8 -0
  59. package/dist/src/shared/worker-daemon/functions/validate-daemon-path.function.d.ts +15 -0
  60. package/dist/src/worker.d.ts +0 -7
  61. package/dist/wasm/default-embedding/kbdb_default_embedding_bg.wasm +0 -0
  62. package/dist/wasm/default-embedding/package.json +1 -1
  63. package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
  64. package/dist/wasm/fs-database/package.json +1 -1
  65. package/dist/wasm/fs-migration/kbdb_fs_migration_bg.wasm +0 -0
  66. package/dist/wasm/fs-migration/package.json +1 -1
  67. package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
  68. package/dist/wasm/kb-worker/package.json +1 -1
  69. package/dist/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
  70. package/dist/wasm/query-parser/package.json +1 -1
  71. package/dist/worker.d.ts +0 -7
  72. package/dist/worker.mjs +37 -6
  73. package/dist/worker.mjs.map +3 -3
  74. package/package.json +13 -12
  75. package/dist/chunk-BJXEVALU.mjs.map +0 -7
  76. package/dist/src/shared/cli/functions/resolve-raw-db-path.function.d.ts +0 -10
  77. package/docs/details/README.md +0 -30
  78. package/docs/details/agent-tooling.md +0 -132
  79. package/docs/details/cli.md +0 -777
  80. package/docs/details/knowledge-base.md +0 -180
  81. package/docs/details/library-api.md +0 -495
  82. package/docs/details/mcp-server.md +0 -482
  83. package/docs/details/search-and-ranking.md +0 -575
  84. package/docs/details/storage.md +0 -531
  85. package/docs/goals/agents.md +0 -751
  86. package/docs/goals/architecture.svg +0 -198
  87. package/docs/goals/auto-capture.md +0 -378
  88. package/docs/goals/benchmarking.md +0 -296
  89. package/docs/goals/cli.md +0 -2654
  90. package/docs/goals/concurrency.md +0 -259
  91. package/docs/goals/content-composer.md +0 -609
  92. package/docs/goals/content-parser.md +0 -279
  93. package/docs/goals/database.md +0 -1679
  94. package/docs/goals/document.md +0 -368
  95. package/docs/goals/hybrid-search.md +0 -465
  96. package/docs/goals/mcp.md +0 -1541
  97. package/docs/goals/overview.md +0 -124
  98. package/docs/goals/query-parser.md +0 -373
  99. package/docs/goals/query-result.md +0 -860
  100. package/docs/goals/semantic-dedup.md +0 -233
  101. package/docs/goals/skills.md +0 -810
  102. package/docs/goals/sync.md +0 -217
  103. package/docs/goals/worker-client.md +0 -1005
  104. package/docs/goals/worker-daemon.md +0 -1547
  105. package/docs/modules/overview.md +0 -319
  106. package/docs/modules/rust/embedding/module.md +0 -91
  107. package/docs/modules/rust/fs-database/functions/document.md +0 -48
  108. package/docs/modules/rust/fs-database/functions/integrity.md +0 -79
  109. package/docs/modules/rust/fs-database/functions/io.md +0 -87
  110. package/docs/modules/rust/fs-database/functions/module.md +0 -22
  111. package/docs/modules/rust/fs-database/functions/query-exec.md +0 -44
  112. package/docs/modules/rust/fs-database/functions/section.md +0 -76
  113. package/docs/modules/rust/fs-database/indexes/btree.md +0 -35
  114. package/docs/modules/rust/fs-database/indexes/corpus.md +0 -61
  115. package/docs/modules/rust/fs-database/indexes/inverted.md +0 -60
  116. package/docs/modules/rust/fs-database/indexes/module.md +0 -64
  117. package/docs/modules/rust/fs-database/indexes/positional.md +0 -39
  118. package/docs/modules/rust/fs-database/indexes/vectors.md +0 -110
  119. package/docs/modules/rust/fs-database/module.md +0 -150
  120. package/docs/modules/rust/fs-database/types/catalog.md +0 -53
  121. package/docs/modules/rust/fs-database/types/module.md +0 -12
  122. package/docs/modules/rust/fs-database/types/section.md +0 -127
  123. package/docs/modules/rust/kb-worker/functions/compose.md +0 -57
  124. package/docs/modules/rust/kb-worker/functions/module.md +0 -20
  125. package/docs/modules/rust/kb-worker/functions/retrieve.md +0 -194
  126. package/docs/modules/rust/kb-worker/functions/search.md +0 -173
  127. package/docs/modules/rust/kb-worker/functions/write.md +0 -172
  128. package/docs/modules/rust/kb-worker/module.md +0 -171
  129. package/docs/modules/rust/kb-worker/types/cache.md +0 -90
  130. package/docs/modules/rust/kb-worker/types/context.md +0 -26
  131. package/docs/modules/rust/kb-worker/types/module.md +0 -16
  132. package/docs/modules/rust/kb-worker/types/status.md +0 -29
  133. package/docs/modules/rust/kb-worker/types/token.md +0 -50
  134. package/docs/modules/rust/overview.md +0 -531
  135. package/docs/modules/rust/query-parser/functions/extract.md +0 -56
  136. package/docs/modules/rust/query-parser/functions/module.md +0 -18
  137. package/docs/modules/rust/query-parser/functions/parse.md +0 -33
  138. package/docs/modules/rust/query-parser/functions/pipeline.md +0 -9
  139. package/docs/modules/rust/query-parser/functions/rank.md +0 -85
  140. package/docs/modules/rust/query-parser/module.md +0 -131
  141. package/docs/modules/rust/query-parser/types/cache.md +0 -39
  142. package/docs/modules/rust/query-parser/types/keyphrase.md +0 -71
  143. package/docs/modules/rust/query-parser/types/module.md +0 -18
  144. package/docs/modules/rust/query-parser/types/token.md +0 -46
  145. package/docs/modules/rust/shared/content-composer/functions.md +0 -114
  146. package/docs/modules/rust/shared/content-composer/module.md +0 -147
  147. package/docs/modules/rust/shared/content-composer/types.md +0 -93
  148. package/docs/modules/rust/shared/content-parser/functions.md +0 -72
  149. package/docs/modules/rust/shared/content-parser/module.md +0 -99
  150. package/docs/modules/rust/shared/content-parser/types.md +0 -71
  151. package/docs/modules/rust/shared/corpus/module.md +0 -24
  152. package/docs/modules/rust/shared/corpus/types.md +0 -141
  153. package/docs/modules/rust/shared/document/module.md +0 -25
  154. package/docs/modules/rust/shared/document/types.md +0 -154
  155. package/docs/modules/rust/shared/encode/module.md +0 -22
  156. package/docs/modules/rust/shared/encode/traits.md +0 -304
  157. package/docs/modules/rust/shared/error/module.md +0 -28
  158. package/docs/modules/rust/shared/error/types.md +0 -302
  159. package/docs/modules/rust/shared/kbid/module.md +0 -24
  160. package/docs/modules/rust/shared/kbid/types.md +0 -147
  161. package/docs/modules/rust/shared/memory/functions.md +0 -209
  162. package/docs/modules/rust/shared/memory/module.md +0 -24
  163. package/docs/modules/rust/shared/module.md +0 -196
  164. package/docs/modules/rust/shared/pipeline/functions.md +0 -141
  165. package/docs/modules/rust/shared/pipeline/module.md +0 -62
  166. package/docs/modules/rust/shared/pipeline/types.md +0 -43
  167. package/docs/modules/rust/shared/query/module.md +0 -27
  168. package/docs/modules/rust/shared/query/types.md +0 -236
  169. package/docs/modules/rust/shared/section/module.md +0 -25
  170. package/docs/modules/rust/shared/section/types.md +0 -294
  171. package/docs/modules/rust/shared/term/module.md +0 -25
  172. package/docs/modules/rust/shared/term/types.md +0 -139
  173. package/docs/modules/typescript/cli.md +0 -131
  174. package/docs/modules/typescript/kbdb-worker.md +0 -150
  175. package/docs/modules/typescript/overview.md +0 -400
  176. package/docs/modules/typescript/shared/auto-capture/module.md +0 -73
  177. package/docs/modules/typescript/shared/cli/constants.md +0 -23
  178. package/docs/modules/typescript/shared/cli/functions.md +0 -809
  179. package/docs/modules/typescript/shared/cli/module.md +0 -138
  180. package/docs/modules/typescript/shared/cli/typings.md +0 -197
  181. package/docs/modules/typescript/shared/embedding/functions.md +0 -200
  182. package/docs/modules/typescript/shared/embedding/module.md +0 -77
  183. package/docs/modules/typescript/shared/embedding/typings.md +0 -124
  184. package/docs/modules/typescript/shared/hash/functions.md +0 -20
  185. package/docs/modules/typescript/shared/hash/module.md +0 -21
  186. package/docs/modules/typescript/shared/log/constants.md +0 -82
  187. package/docs/modules/typescript/shared/log/functions.md +0 -131
  188. package/docs/modules/typescript/shared/log/module.md +0 -153
  189. package/docs/modules/typescript/shared/log/typings.md +0 -82
  190. package/docs/modules/typescript/shared/mcp/classes.md +0 -179
  191. package/docs/modules/typescript/shared/mcp/functions.md +0 -386
  192. package/docs/modules/typescript/shared/mcp/module.md +0 -160
  193. package/docs/modules/typescript/shared/mcp/typings.md +0 -529
  194. package/docs/modules/typescript/shared/module.md +0 -110
  195. package/docs/modules/typescript/shared/platform/functions.md +0 -42
  196. package/docs/modules/typescript/shared/platform/module.md +0 -25
  197. package/docs/modules/typescript/shared/runtime/functions.md +0 -26
  198. package/docs/modules/typescript/shared/runtime/module.md +0 -27
  199. package/docs/modules/typescript/shared/runtime/typings.md +0 -13
  200. package/docs/modules/typescript/shared/version/module.md +0 -27
  201. package/docs/modules/typescript/shared/wasm-codec/functions.md +0 -391
  202. package/docs/modules/typescript/shared/wasm-codec/module.md +0 -98
  203. package/docs/modules/typescript/shared/worker-client/classes.md +0 -264
  204. package/docs/modules/typescript/shared/worker-client/functions.md +0 -175
  205. package/docs/modules/typescript/shared/worker-client/module.md +0 -92
  206. package/docs/modules/typescript/shared/worker-client/typings.md +0 -511
  207. package/docs/modules/typescript/shared/worker-daemon/classes.md +0 -239
  208. package/docs/modules/typescript/shared/worker-daemon/constants.md +0 -37
  209. package/docs/modules/typescript/shared/worker-daemon/functions.md +0 -234
  210. package/docs/modules/typescript/shared/worker-daemon/module.md +0 -118
  211. package/docs/modules/typescript/shared/worker-daemon/typings.md +0 -132
  212. package/docs/overview.md +0 -191
  213. package/docs/release-notes/0.1.0.md +0 -189
  214. package/docs/release-notes/0.1.1.md +0 -46
  215. package/docs/release-notes/0.1.2.md +0 -38
  216. package/docs/release-notes/0.1.3.md +0 -42
  217. package/docs/release-notes/0.2.0.md +0 -147
  218. package/docs/release-notes/0.3.0.md +0 -89
  219. package/docs/release-notes/0.3.1.md +0 -121
  220. package/docs/release-notes/0.3.2.md +0 -64
  221. package/docs/release-notes/0.4.0.md +0 -80
  222. package/docs/release-notes/0.4.1.md +0 -149
  223. package/docs/release-notes/0.4.3.md +0 -60
  224. package/docs/release-notes/README.md +0 -13
@@ -1,198 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg"
2
- width="780" height="770" viewBox="0 0 780 770"
3
- font-family="system-ui, -apple-system, sans-serif">
4
-
5
- <defs>
6
- <marker id="arrowhead" viewBox="0 0 10 7"
7
- refX="10" refY="3.5"
8
- markerWidth="8" markerHeight="6" orient="auto">
9
- <path d="M0,0 L10,3.5 L0,7 z" fill="#6b7280"/>
10
- </marker>
11
- <marker id="arrowhead-red" viewBox="0 0 10 7"
12
- refX="10" refY="3.5"
13
- markerWidth="8" markerHeight="6" orient="auto">
14
- <path d="M0,0 L10,3.5 L0,7 z" fill="#dc2626"/>
15
- </marker>
16
- </defs>
17
-
18
- <!-- Background -->
19
- <rect width="780" height="770" fill="#ffffff"/>
20
-
21
- <!-- =========================================== -->
22
- <!-- Process boundary: kbdb executable -->
23
- <!-- =========================================== -->
24
- <rect x="35" y="90" width="710" height="200" rx="12"
25
- fill="none" stroke="#d1d5db" stroke-width="1.5"
26
- stroke-dasharray="8,4"/>
27
- <text x="50" y="105" font-size="11" fill="#9ca3af"
28
- font-weight="500">kbdb executable</text>
29
-
30
- <!-- =========================================== -->
31
- <!-- Process boundary: worker daemon -->
32
- <!-- =========================================== -->
33
- <rect x="35" y="355" width="710" height="285" rx="12"
34
- fill="none" stroke="#d1d5db" stroke-width="1.5"
35
- stroke-dasharray="8,4"/>
36
- <text x="50" y="370" font-size="11" fill="#9ca3af"
37
- font-weight="500">worker daemon (detached process)</text>
38
-
39
- <!-- =========================================== -->
40
- <!-- External: User / Script -->
41
- <!-- =========================================== -->
42
- <rect x="85" y="20" width="200" height="44" rx="8"
43
- fill="#f8f9fa" stroke="#9ca3af" stroke-width="1.5"
44
- stroke-dasharray="6,3"/>
45
- <text x="185" y="47" text-anchor="middle"
46
- font-size="13" font-weight="600" fill="#495057">User / Script</text>
47
-
48
- <!-- =========================================== -->
49
- <!-- External: AI Agent Host -->
50
- <!-- =========================================== -->
51
- <rect x="495" y="20" width="200" height="44" rx="8"
52
- fill="#f8f9fa" stroke="#9ca3af" stroke-width="1.5"
53
- stroke-dasharray="6,3"/>
54
- <text x="595" y="47" text-anchor="middle"
55
- font-size="13" font-weight="600" fill="#495057">AI Agent Host</text>
56
-
57
- <!-- =========================================== -->
58
- <!-- CLI Mode -->
59
- <!-- =========================================== -->
60
- <rect x="85" y="110" width="200" height="52" rx="8"
61
- fill="#dbeafe" stroke="#3b82f6" stroke-width="1.5"/>
62
- <text x="185" y="134" text-anchor="middle"
63
- font-size="13" font-weight="600" fill="#1e40af">CLI Mode</text>
64
- <text x="185" y="150" text-anchor="middle"
65
- font-size="11" fill="#6b7280">cli.ts</text>
66
-
67
- <!-- =========================================== -->
68
- <!-- MCP Mode -->
69
- <!-- =========================================== -->
70
- <rect x="495" y="110" width="200" height="52" rx="8"
71
- fill="#dbeafe" stroke="#3b82f6" stroke-width="1.5"/>
72
- <text x="595" y="134" text-anchor="middle"
73
- font-size="13" font-weight="600" fill="#1e40af">MCP Mode</text>
74
- <text x="595" y="150" text-anchor="middle"
75
- font-size="11" fill="#6b7280">mcp.ts (stdio)</text>
76
-
77
- <!-- =========================================== -->
78
- <!-- Worker Client -->
79
- <!-- =========================================== -->
80
- <rect x="240" y="220" width="300" height="52" rx="8"
81
- fill="#d1fae5" stroke="#10b981" stroke-width="1.5"/>
82
- <text x="390" y="244" text-anchor="middle"
83
- font-size="13" font-weight="600" fill="#065f46">Worker Client</text>
84
- <text x="390" y="260" text-anchor="middle"
85
- font-size="11" fill="#6b7280">src/shared/worker-client/</text>
86
-
87
- <!-- =========================================== -->
88
- <!-- Worker Daemon -->
89
- <!-- =========================================== -->
90
- <rect x="240" y="375" width="300" height="52" rx="8"
91
- fill="#fed7aa" stroke="#f97316" stroke-width="1.5"/>
92
- <text x="390" y="399" text-anchor="middle"
93
- font-size="13" font-weight="600" fill="#9a3412">Worker Daemon</text>
94
- <text x="390" y="415" text-anchor="middle"
95
- font-size="11" fill="#6b7280">kbdb-worker.ts</text>
96
-
97
- <!-- =========================================== -->
98
- <!-- kb-worker.wasm -->
99
- <!-- =========================================== -->
100
- <rect x="265" y="475" width="250" height="46" rx="8"
101
- fill="#ede9fe" stroke="#8b5cf6" stroke-width="1.5"/>
102
- <text x="390" y="503" text-anchor="middle"
103
- font-size="13" font-weight="600" fill="#5b21b6">kb-worker.wasm</text>
104
-
105
- <!-- =========================================== -->
106
- <!-- query-parser.wasm -->
107
- <!-- =========================================== -->
108
- <rect x="55" y="575" width="220" height="46" rx="8"
109
- fill="#ede9fe" stroke="#8b5cf6" stroke-width="1.5"/>
110
- <text x="165" y="603" text-anchor="middle"
111
- font-size="13" font-weight="600" fill="#5b21b6">query-parser.wasm</text>
112
-
113
- <!-- =========================================== -->
114
- <!-- fs-database.wasm -->
115
- <!-- =========================================== -->
116
- <rect x="505" y="575" width="220" height="46" rx="8"
117
- fill="#ede9fe" stroke="#8b5cf6" stroke-width="1.5"/>
118
- <text x="615" y="603" text-anchor="middle"
119
- font-size="13" font-weight="600" fill="#5b21b6">fs-database.wasm</text>
120
-
121
- <!-- =========================================== -->
122
- <!-- .kbdb/ directory -->
123
- <!-- =========================================== -->
124
- <rect x="505" y="700" width="220" height="50" rx="8"
125
- fill="#f3f4f6" stroke="#6b7280" stroke-width="1.5"/>
126
- <text x="615" y="722" text-anchor="middle"
127
- font-size="13" font-weight="600" fill="#374151">.kbdb/</text>
128
- <text x="615" y="738" text-anchor="middle"
129
- font-size="11" fill="#6b7280">directory on disk</text>
130
-
131
- <!-- =========================================== -->
132
- <!-- Arrows -->
133
- <!-- =========================================== -->
134
-
135
- <!-- User → CLI -->
136
- <line x1="185" y1="64" x2="185" y2="108"
137
- stroke="#6b7280" stroke-width="1.5"
138
- marker-end="url(#arrowhead)"/>
139
- <text x="195" y="91" font-size="10" fill="#6b7280"
140
- font-style="italic">args / stdout</text>
141
-
142
- <!-- AI Agent → MCP -->
143
- <line x1="595" y1="64" x2="595" y2="108"
144
- stroke="#6b7280" stroke-width="1.5"
145
- marker-end="url(#arrowhead)"/>
146
- <text x="605" y="84" font-size="10" fill="#6b7280"
147
- font-style="italic">stdio</text>
148
- <text x="605" y="96" font-size="10" fill="#6b7280"
149
- font-style="italic">(JSON-RPC 2.0)</text>
150
-
151
- <!-- CLI → Worker Client -->
152
- <line x1="215" y1="162" x2="320" y2="218"
153
- stroke="#6b7280" stroke-width="1.5"
154
- marker-end="url(#arrowhead)"/>
155
-
156
- <!-- MCP → Worker Client -->
157
- <line x1="565" y1="162" x2="460" y2="218"
158
- stroke="#6b7280" stroke-width="1.5"
159
- marker-end="url(#arrowhead)"/>
160
-
161
- <!-- Worker Client → Worker Daemon (IPC boundary) -->
162
- <line x1="390" y1="272" x2="390" y2="373"
163
- stroke="#dc2626" stroke-width="2"
164
- marker-end="url(#arrowhead-red)"/>
165
- <text x="400" y="318" font-size="11" fill="#dc2626"
166
- font-weight="600">IPC (JSON-RPC 2.0)</text>
167
- <text x="400" y="333" font-size="10" fill="#dc2626"
168
- font-style="italic">Unix socket / named pipe</text>
169
-
170
- <!-- Worker Daemon → kb-worker.wasm -->
171
- <line x1="390" y1="427" x2="390" y2="473"
172
- stroke="#6b7280" stroke-width="1.5"
173
- marker-end="url(#arrowhead)"/>
174
- <text x="400" y="455" font-size="10" fill="#6b7280"
175
- font-style="italic">loads</text>
176
-
177
- <!-- kb-worker.wasm → query-parser.wasm -->
178
- <line x1="315" y1="521" x2="210" y2="573"
179
- stroke="#6b7280" stroke-width="1.5"
180
- marker-end="url(#arrowhead)"/>
181
- <text x="232" y="543" font-size="10" fill="#6b7280"
182
- font-style="italic">imports</text>
183
-
184
- <!-- kb-worker.wasm → fs-database.wasm -->
185
- <line x1="465" y1="521" x2="570" y2="573"
186
- stroke="#6b7280" stroke-width="1.5"
187
- marker-end="url(#arrowhead)"/>
188
- <text x="508" y="543" font-size="10" fill="#6b7280"
189
- font-style="italic">imports</text>
190
-
191
- <!-- fs-database.wasm → .kbdb/ -->
192
- <line x1="615" y1="621" x2="615" y2="698"
193
- stroke="#6b7280" stroke-width="1.5"
194
- marker-end="url(#arrowhead)"/>
195
- <text x="625" y="665" font-size="10" fill="#6b7280"
196
- font-style="italic">host file I/O</text>
197
-
198
- </svg>
@@ -1,378 +0,0 @@
1
- # Auto-Capture -- Proactive Knowledge Capture Hooks
2
-
3
- *Server-side enforcement of knowledge capture that
4
- closes the gap between agent intent and reliable
5
- storage -- without requiring the agent to remember
6
- to act.*
7
-
8
- ## Goal
9
-
10
- The `memory-protocol` skill (see [Skills](skills.md))
11
- teaches an agent what to store, but enforcement
12
- depends entirely on the agent choosing to act.
13
- Agents are unreliable at remembering to call `learn`
14
- after every significant exchange. Auto-capture closes
15
- this gap by having the MCP server proactively issue
16
- a sampling request to the host LLM, asking it to
17
- review recent context and identify storable knowledge.
18
-
19
- This is gap #2 from the
20
- [Opus 4.8 second brain review](../issues/2026-06-23-opus-48-second-brain-review.md):
21
-
22
- > A memory-protocol *skill* is intent, not
23
- > enforcement -- agents are unreliable at remembering
24
- > to write. Real second brains lean on auto-capture
25
- > hooks.
26
-
27
- Auto-capture is opt-in and default-disabled. It never
28
- writes to the database without the host LLM's
29
- explicit response identifying items to store.
30
-
31
- ## MCP Sampling Approach
32
-
33
- Auto-capture uses the MCP `sampling/createMessage`
34
- capability. When a trigger fires, the kbdb MCP server
35
- sends a `sampling/createMessage` request to the host
36
- asking it to identify storable knowledge from the
37
- current conversation context.
38
-
39
- If the host's `initialize` response does not include
40
- a `sampling` capability entry, auto-capture is
41
- silently disabled for that session regardless of
42
- configuration.
43
-
44
- ### Sampling Prompt Template
45
-
46
- ```
47
- Review the recent conversation context. Identify any
48
- durable facts, decisions, corrections, architecture
49
- choices, or configuration details that should be
50
- stored in the knowledge base for future sessions.
51
-
52
- For each item, provide:
53
- - title: short heading
54
- - content: the fact or decision
55
- - tags: relevant topic tags
56
-
57
- Respond with JSON: {"items": [...]} or {"items": []}
58
- if nothing is worth storing. Apply the same criteria
59
- as the memory-protocol skill: store durable facts,
60
- not transient context.
61
- ```
62
-
63
- The server sets `maxTokens` to a fixed ceiling (e.g.
64
- 2048) to bound cost. The sampling request carries no
65
- `systemPrompt` -- context comes from the host's own
66
- conversation window.
67
-
68
- ### Sampling Response Schema
69
-
70
- The host LLM must respond with a JSON object at the
71
- top level. The server parses the text content of the
72
- sampling response and extracts:
73
-
74
- ```json
75
- {
76
- "items": [
77
- {
78
- "title": "Postgres chosen for JSONB support",
79
- "content": "We chose Postgres because JSONB
80
- support simplifies document storage.",
81
- "tags": ["architecture", "database"]
82
- }
83
- ]
84
- }
85
- ```
86
-
87
- When `items` is empty or the response cannot be parsed
88
- as valid JSON, the server takes no action and logs a
89
- `debug`-level notification.
90
-
91
- Each item in `items` is stored via `addSection` with
92
- `sectionType: 'text/markdown'` and the
93
- `auto-capture` tag appended to `tags`.
94
-
95
- ## Trigger Points
96
-
97
- Three independent trigger mechanisms fire a capture
98
- review. All three can be active simultaneously.
99
-
100
- ### 1. Tool-Call Count Trigger
101
-
102
- The MCP server maintains a per-session counter of
103
- tool invocations. When the count reaches a multiple
104
- of `trigger_interval`, a capture review fires.
105
-
106
- - The counter increments on every `tools/call`
107
- dispatch, including read-only tools.
108
- - The counter does not increment during the capture
109
- review itself (no recursion).
110
- - The review fires after the triggering tool call
111
- returns its result to the agent, not before.
112
-
113
- Default: every 10 tool calls.
114
-
115
- ### 2. Explicit Tool Trigger
116
-
117
- The `auto-capture-review` tool is always registered,
118
- regardless of whether auto-capture is enabled in
119
- `worker.toml`. Agents or users can call it at any
120
- time to request an immediate capture review.
121
-
122
- When `dry_run: true` is passed, the review runs but
123
- no sections are written. See [MCP Surface](#mcp-surface).
124
-
125
- ### 3. Session-End Trigger
126
-
127
- When the MCP connection closes gracefully (stdin EOF
128
- or explicit disconnect), one final capture review
129
- runs before the server exits.
130
-
131
- The session-end trigger fires only when
132
- `auto_capture.enabled` is `true`. It does not fire
133
- when the connection is lost abruptly (SIGKILL, socket
134
- drop).
135
-
136
- ## Configuration
137
-
138
- Auto-capture is configured in `worker.toml` under the
139
- `[auto_capture]` table:
140
-
141
- ```toml
142
- [auto_capture]
143
- enabled = false # opt-in, default off
144
- trigger_interval = 10 # tool calls between reviews
145
- max_captures_per_session = 20 # rate limit
146
- dry_run = false # log without writing
147
- ```
148
-
149
- | Field | Type | Default | Description |
150
- |-------|------|---------|-------------|
151
- | `enabled` | bool | `false` | Enable auto-capture for all MCP sessions |
152
- | `trigger_interval` | integer | `10` | Tool calls between automatic reviews |
153
- | `max_captures_per_session` | integer | `20` | Maximum sections stored per session |
154
- | `dry_run` | bool | `false` | Log what would be stored; write nothing |
155
-
156
- When `enabled` is `false`, only the `auto-capture-review`
157
- tool remains active. The tool-call count and
158
- session-end triggers are suppressed.
159
-
160
- ## Guard Rails
161
-
162
- ### Rate Limiting
163
-
164
- The server tracks the number of sections stored
165
- during the current MCP session. When
166
- `max_captures_per_session` is reached, further
167
- automatic reviews are skipped. The
168
- `auto-capture-review` tool still runs but returns a
169
- rate-limit message instead of executing the review.
170
-
171
- The counter resets when the MCP session ends. It is
172
- not persisted across sessions.
173
-
174
- ### Dry-Run Mode
175
-
176
- When `dry_run` is `true` (either from `worker.toml`
177
- or the `auto-capture-review` tool parameter), the
178
- server executes the full review -- sends the sampling
179
- request, parses the response, and evaluates items --
180
- but does not call `addSection`. Instead, it emits a
181
- `notifications/message` at `info` level describing
182
- what would have been stored.
183
-
184
- Dry-run mode is useful for tuning `trigger_interval`
185
- and verifying that the sampling prompt produces
186
- reasonable output before enabling writes.
187
-
188
- ### Deduplication
189
-
190
- Before storing each item from the sampling response,
191
- the server searches the database for existing sections
192
- with similar content. If any existing section has a
193
- Jaccard similarity >= 0.85 to the candidate item, the
194
- item is skipped and logged at `debug` level.
195
-
196
- This uses the same near-duplicate detection that the
197
- `learn` tool uses, reflected in the `near_duplicates`
198
- field of `AddSectionResult`.
199
-
200
- ### No Recursion
201
-
202
- The tool-call counter does not increment during an
203
- active capture review. The `addSection` calls made
204
- by auto-capture do not trigger a nested review.
205
-
206
- ### Agent Override
207
-
208
- Auto-capture never overrides an agent's explicit
209
- decision not to store something. If an agent
210
- calls `unlearn` to remove a section, auto-capture
211
- will not re-add it in the same session (the content's
212
- kbid is added to a per-session exclusion set after
213
- removal).
214
-
215
- ## Interaction with the memory-protocol Skill
216
-
217
- | Aspect | memory-protocol | Auto-capture |
218
- |--------|-----------------|--------------|
219
- | Audience | Agent (reads skill text) | MCP server (server-side) |
220
- | Mechanism | Teaches filtering criteria | Sends sampling request |
221
- | Enforcement | Agent must choose to act | Server acts automatically |
222
- | Criteria | Defined in skill body | Sampling prompt mirrors skill |
223
- | Override | Agent decides | Agent's `unlearn` is respected |
224
-
225
- Both mechanisms apply the same filtering criteria --
226
- store durable facts, skip transient context. They are
227
- complementary: `memory-protocol` is agent-facing
228
- intent; auto-capture is server-side enforcement.
229
-
230
- ## CLI Surface
231
-
232
- The `--auto-capture` flag on `kbdb mcp` enables
233
- auto-capture for the current session, overriding the
234
- `enabled` value in `worker.toml`:
235
-
236
- ```
237
- kbdb mcp --db <path> [--auto-capture]
238
- ```
239
-
240
- The flag does not accept a value -- its presence sets
241
- `enabled: true`. It does not override other fields
242
- (`trigger_interval`, `max_captures_per_session`,
243
- `dry_run`), which continue to come from `worker.toml`
244
- or their defaults.
245
-
246
- ## MCP Surface
247
-
248
- ### auto-capture-review Tool
249
-
250
- Triggers an immediate capture review regardless of
251
- whether auto-capture is enabled in configuration.
252
-
253
- **Parameters:**
254
-
255
- | Name | Type | Required | Description |
256
- |------|------|----------|-------------|
257
- | `dry_run` | boolean | no | When `true`, evaluate but do not write (default: `false`) |
258
-
259
- **Returns:**
260
-
261
- ```json
262
- {
263
- "captured": 2,
264
- "items": [
265
- {
266
- "title": "Postgres chosen for JSONB support",
267
- "kbid": "a1b2c3d4e5f6g7h8j9k0l1m2n3"
268
- }
269
- ],
270
- "skipped": 1,
271
- "dry_run": false
272
- }
273
- ```
274
-
275
- | Field | Description |
276
- |-------|-------------|
277
- | `captured` | Number of sections written (0 when `dry_run: true`) |
278
- | `items` | Array of `{ title, kbid }` for each section stored |
279
- | `skipped` | Items returned by LLM but not stored (duplicates, parse errors, rate limit) |
280
- | `dry_run` | Reflects the effective dry-run mode used |
281
-
282
- When sampling is not supported by the host, the tool
283
- returns `isError: true` with message:
284
- `"Host does not support sampling; auto-capture-review
285
- unavailable"`.
286
-
287
- **Tool annotation:**
288
-
289
- | Attribute | Value |
290
- |-----------|-------|
291
- | `readOnlyHint` | `false` |
292
- | `destructiveHint` | `false` |
293
- | `idempotentHint` | `false` |
294
- | `openWorldHint` | `false` |
295
-
296
- ### Capability Advertisement
297
-
298
- When `sampling` is present in the host's `initialize`
299
- capabilities, the server advertises the `sampling`
300
- capability in its own `initialize` response. When
301
- `sampling` is absent, the capability is omitted from
302
- the response and auto-capture is silently disabled.
303
-
304
- ## Response Flow
305
-
306
- ```
307
- Agent uses kbdb tools
308
- |
309
- v
310
- Tool call count reaches N
311
- |
312
- v
313
- Server sends sampling/createMessage
314
- |
315
- v
316
- Host LLM reviews conversation context
317
- |
318
- v
319
- Returns {"items": [...]} or {"items": []}
320
- |
321
- v
322
- Server deduplicates against existing sections
323
- |
324
- v
325
- Server stores each new item via addSection
326
- (with "auto-capture" tag appended)
327
- |
328
- v
329
- notifications/message logged (info level)
330
- ```
331
-
332
- When the host does not support sampling, or when
333
- `enabled` is `false` and the trigger is automatic
334
- (not the explicit tool), the flow terminates after
335
- the trigger fires with a `debug`-level log and no
336
- sampling request is sent.
337
-
338
- ## Tagging
339
-
340
- Every section stored by auto-capture receives the
341
- `auto-capture` tag appended to any tags the sampling
342
- response supplied. This makes auto-captured sections
343
- filterable and identifiable in search results and
344
- integrity checks.
345
-
346
- Example stored section tags when the sampling
347
- response supplies `["architecture", "database"]`:
348
-
349
- ```
350
- ["architecture", "database", "auto-capture"]
351
- ```
352
-
353
- ## Design Constraints
354
-
355
- - **Opt-in by default.** `enabled` is `false` in
356
- `worker.toml` until explicitly set. No sections are
357
- written without explicit configuration or the
358
- `--auto-capture` flag.
359
- - **Sampling required.** Auto-capture cannot function
360
- without MCP sampling support. It is silently
361
- disabled when the host omits the `sampling`
362
- capability, with no error and no user-visible
363
- change to other tools.
364
- - **No recursion.** Auto-capture calls do not
365
- increment the tool-call counter and do not trigger
366
- nested reviews.
367
- - **Agent override respected.** Sections removed by
368
- an explicit `unlearn` call are not re-added by
369
- auto-capture within the same session.
370
- - **Rate-limited.** `max_captures_per_session`
371
- prevents runaway storage from a misconfigured
372
- trigger interval or a verbose LLM response.
373
- - **Traceability.** Auto-captured sections always
374
- carry the `auto-capture` tag so they can be
375
- distinguished from manually learned content.
376
- - **Dry-run available.** `dry_run` mode allows
377
- operators to verify sampling output and tune
378
- configuration before enabling writes.