@dikolab/kbdb 0.1.5 → 0.2.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 (193) hide show
  1. package/README.md +30 -9
  2. package/dist/cli.cjs +181 -50
  3. package/dist/cli.cjs.map +3 -3
  4. package/dist/cli.mjs +181 -50
  5. package/dist/cli.mjs.map +3 -3
  6. package/dist/kbdb-worker.cjs +283 -29
  7. package/dist/kbdb-worker.cjs.map +4 -4
  8. package/dist/mod.cjs +13 -2
  9. package/dist/mod.cjs.map +2 -2
  10. package/dist/mod.mjs +13 -2
  11. package/dist/mod.mjs.map +2 -2
  12. package/dist/src/shared/cli/functions/format-output.function.d.ts +7 -7
  13. package/dist/src/shared/cli/functions/run-search.function.d.ts +25 -16
  14. package/dist/src/shared/cli/index.d.ts +1 -1
  15. package/dist/src/shared/cli/typings/cli-options.interface.d.ts +2 -0
  16. package/dist/src/shared/cli/typings/search-display.model.d.ts +25 -7
  17. package/dist/src/shared/mcp/functions/handle-recall.function.d.ts +29 -0
  18. package/dist/src/shared/mcp/typings/mcp-client.interface.d.ts +30 -11
  19. package/dist/src/shared/version/constants/version.constant.d.ts +1 -1
  20. package/dist/src/shared/wasm-codec/functions/decode-recall-result.function.d.ts +28 -0
  21. package/dist/src/shared/wasm-codec/functions/decode-scored-results.function.d.ts +14 -7
  22. package/dist/src/shared/wasm-codec/functions/encode-recall-params.function.d.ts +21 -0
  23. package/dist/src/shared/wasm-codec/functions/encode-search-params.function.d.ts +1 -1
  24. package/dist/src/shared/wasm-codec/index.d.ts +5 -2
  25. package/dist/src/shared/worker-client/classes/worker-client.class.d.ts +13 -3
  26. package/dist/src/shared/worker-client/index.d.ts +2 -1
  27. package/dist/src/shared/worker-client/typings/recall-result.model.d.ts +94 -0
  28. package/dist/src/shared/worker-client/typings/search-params.model.d.ts +2 -0
  29. package/dist/src/shared/worker-client/typings/search-result.model.d.ts +23 -7
  30. package/dist/src/shared/worker-daemon/classes/worker-daemon.class.d.ts +1 -0
  31. package/dist/wasm/fs-database/kbdb_fs_database.d.ts +18 -0
  32. package/dist/wasm/fs-database/kbdb_fs_database.js +30 -0
  33. package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
  34. package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +2 -0
  35. package/dist/wasm/kb-worker/kbdb_worker.d.ts +38 -0
  36. package/dist/wasm/kb-worker/kbdb_worker.js +56 -0
  37. package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
  38. package/dist/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +3 -0
  39. package/dist/worker.mjs +283 -29
  40. package/dist/worker.mjs.map +4 -4
  41. package/docs/details/README.md +26 -0
  42. package/docs/details/cli.md +608 -0
  43. package/docs/details/library-api.md +406 -0
  44. package/docs/details/mcp-server.md +430 -0
  45. package/docs/details/search-and-ranking.md +457 -0
  46. package/docs/details/storage.md +529 -0
  47. package/docs/goals/agents.md +751 -0
  48. package/docs/goals/architecture.svg +198 -0
  49. package/docs/goals/cli.md +2308 -0
  50. package/docs/goals/content-composer.md +609 -0
  51. package/docs/goals/content-parser.md +279 -0
  52. package/docs/goals/database.md +1452 -0
  53. package/docs/goals/document.md +368 -0
  54. package/docs/goals/mcp.md +1467 -0
  55. package/docs/goals/overview.md +124 -0
  56. package/docs/goals/query-parser.md +271 -0
  57. package/docs/goals/query-result.md +693 -0
  58. package/docs/goals/skills.md +738 -0
  59. package/docs/goals/worker-client.md +944 -0
  60. package/docs/goals/worker-daemon.md +1447 -0
  61. package/docs/modules/overview.md +298 -0
  62. package/docs/modules/rust/fs-database/functions/document.md +48 -0
  63. package/docs/modules/rust/fs-database/functions/integrity.md +68 -0
  64. package/docs/modules/rust/fs-database/functions/io.md +87 -0
  65. package/docs/modules/rust/fs-database/functions/module.md +22 -0
  66. package/docs/modules/rust/fs-database/functions/query-exec.md +44 -0
  67. package/docs/modules/rust/fs-database/functions/section.md +59 -0
  68. package/docs/modules/rust/fs-database/indexes/btree.md +35 -0
  69. package/docs/modules/rust/fs-database/indexes/corpus.md +61 -0
  70. package/docs/modules/rust/fs-database/indexes/inverted.md +60 -0
  71. package/docs/modules/rust/fs-database/indexes/module.md +64 -0
  72. package/docs/modules/rust/fs-database/indexes/positional.md +39 -0
  73. package/docs/modules/rust/fs-database/module.md +149 -0
  74. package/docs/modules/rust/fs-database/types/catalog.md +53 -0
  75. package/docs/modules/rust/fs-database/types/module.md +12 -0
  76. package/docs/modules/rust/fs-database/types/section.md +101 -0
  77. package/docs/modules/rust/kb-worker/functions/compose.md +57 -0
  78. package/docs/modules/rust/kb-worker/functions/module.md +20 -0
  79. package/docs/modules/rust/kb-worker/functions/retrieve.md +194 -0
  80. package/docs/modules/rust/kb-worker/functions/search.md +173 -0
  81. package/docs/modules/rust/kb-worker/functions/write.md +172 -0
  82. package/docs/modules/rust/kb-worker/module.md +171 -0
  83. package/docs/modules/rust/kb-worker/types/cache.md +90 -0
  84. package/docs/modules/rust/kb-worker/types/context.md +26 -0
  85. package/docs/modules/rust/kb-worker/types/module.md +16 -0
  86. package/docs/modules/rust/kb-worker/types/status.md +29 -0
  87. package/docs/modules/rust/kb-worker/types/token.md +50 -0
  88. package/docs/modules/rust/overview.md +495 -0
  89. package/docs/modules/rust/query-parser/functions/extract.md +56 -0
  90. package/docs/modules/rust/query-parser/functions/module.md +16 -0
  91. package/docs/modules/rust/query-parser/functions/parse.md +33 -0
  92. package/docs/modules/rust/query-parser/functions/pipeline.md +103 -0
  93. package/docs/modules/rust/query-parser/functions/rank.md +85 -0
  94. package/docs/modules/rust/query-parser/module.md +136 -0
  95. package/docs/modules/rust/query-parser/types/cache.md +39 -0
  96. package/docs/modules/rust/query-parser/types/keyphrase.md +60 -0
  97. package/docs/modules/rust/query-parser/types/module.md +17 -0
  98. package/docs/modules/rust/query-parser/types/token.md +42 -0
  99. package/docs/modules/rust/shared/content-composer/functions.md +114 -0
  100. package/docs/modules/rust/shared/content-composer/module.md +147 -0
  101. package/docs/modules/rust/shared/content-composer/types.md +93 -0
  102. package/docs/modules/rust/shared/content-parser/functions.md +72 -0
  103. package/docs/modules/rust/shared/content-parser/module.md +99 -0
  104. package/docs/modules/rust/shared/content-parser/types.md +71 -0
  105. package/docs/modules/rust/shared/corpus/module.md +24 -0
  106. package/docs/modules/rust/shared/corpus/types.md +141 -0
  107. package/docs/modules/rust/shared/document/module.md +25 -0
  108. package/docs/modules/rust/shared/document/types.md +154 -0
  109. package/docs/modules/rust/shared/encode/module.md +22 -0
  110. package/docs/modules/rust/shared/encode/traits.md +304 -0
  111. package/docs/modules/rust/shared/error/module.md +28 -0
  112. package/docs/modules/rust/shared/error/types.md +302 -0
  113. package/docs/modules/rust/shared/kbid/module.md +24 -0
  114. package/docs/modules/rust/shared/kbid/types.md +147 -0
  115. package/docs/modules/rust/shared/memory/functions.md +209 -0
  116. package/docs/modules/rust/shared/memory/module.md +24 -0
  117. package/docs/modules/rust/shared/module.md +168 -0
  118. package/docs/modules/rust/shared/query/module.md +27 -0
  119. package/docs/modules/rust/shared/query/types.md +236 -0
  120. package/docs/modules/rust/shared/section/module.md +25 -0
  121. package/docs/modules/rust/shared/section/types.md +294 -0
  122. package/docs/modules/rust/shared/term/module.md +25 -0
  123. package/docs/modules/rust/shared/term/types.md +139 -0
  124. package/docs/modules/typescript/cli.md +129 -0
  125. package/docs/modules/typescript/kbdb-worker.md +135 -0
  126. package/docs/modules/typescript/overview.md +378 -0
  127. package/docs/modules/typescript/shared/cli/constants.md +23 -0
  128. package/docs/modules/typescript/shared/cli/functions.md +630 -0
  129. package/docs/modules/typescript/shared/cli/module.md +125 -0
  130. package/docs/modules/typescript/shared/cli/typings.md +172 -0
  131. package/docs/modules/typescript/shared/hash/functions.md +20 -0
  132. package/docs/modules/typescript/shared/hash/module.md +21 -0
  133. package/docs/modules/typescript/shared/mcp/classes.md +179 -0
  134. package/docs/modules/typescript/shared/mcp/functions.md +386 -0
  135. package/docs/modules/typescript/shared/mcp/module.md +160 -0
  136. package/docs/modules/typescript/shared/mcp/typings.md +522 -0
  137. package/docs/modules/typescript/shared/module.md +94 -0
  138. package/docs/modules/typescript/shared/platform/functions.md +42 -0
  139. package/docs/modules/typescript/shared/platform/module.md +25 -0
  140. package/docs/modules/typescript/shared/runtime/functions.md +26 -0
  141. package/docs/modules/typescript/shared/runtime/module.md +27 -0
  142. package/docs/modules/typescript/shared/runtime/typings.md +13 -0
  143. package/docs/modules/typescript/shared/version/module.md +27 -0
  144. package/docs/modules/typescript/shared/wasm-codec/functions.md +391 -0
  145. package/docs/modules/typescript/shared/wasm-codec/module.md +98 -0
  146. package/docs/modules/typescript/shared/worker-client/classes.md +264 -0
  147. package/docs/modules/typescript/shared/worker-client/functions.md +175 -0
  148. package/docs/modules/typescript/shared/worker-client/module.md +84 -0
  149. package/docs/modules/typescript/shared/worker-client/typings.md +508 -0
  150. package/docs/modules/typescript/shared/worker-daemon/classes.md +239 -0
  151. package/docs/modules/typescript/shared/worker-daemon/constants.md +37 -0
  152. package/docs/modules/typescript/shared/worker-daemon/functions.md +221 -0
  153. package/docs/modules/typescript/shared/worker-daemon/module.md +112 -0
  154. package/docs/modules/typescript/shared/worker-daemon/typings.md +126 -0
  155. package/docs/overview.md +188 -0
  156. package/docs/release-notes/0.1.0.md +189 -0
  157. package/docs/release-notes/0.1.1.md +46 -0
  158. package/docs/release-notes/0.1.2.md +38 -0
  159. package/docs/release-notes/0.1.3.md +42 -0
  160. package/docs/release-notes/0.2.0.md +147 -0
  161. package/docs/release-notes/README.md +9 -0
  162. package/package.json +8 -2
  163. package/src/shared/cli/functions/dispatch-command.function.ts +3 -3
  164. package/src/shared/cli/functions/format-output.function.ts +41 -34
  165. package/src/shared/cli/functions/parse-args.function.ts +7 -0
  166. package/src/shared/cli/functions/run-search.function.ts +53 -27
  167. package/src/shared/cli/index.ts +4 -1
  168. package/src/shared/cli/typings/cli-options.interface.ts +2 -0
  169. package/src/shared/cli/typings/search-display.model.ts +26 -7
  170. package/src/shared/mcp/functions/create-tool-definitions.function.ts +64 -4
  171. package/src/shared/mcp/functions/handle-recall.function.ts +66 -0
  172. package/src/shared/mcp/functions/handle-tool-call.function.ts +11 -1
  173. package/src/shared/mcp/typings/mcp-client.interface.ts +33 -15
  174. package/src/shared/version/constants/version.constant.ts +1 -1
  175. package/src/shared/wasm-codec/functions/decode-recall-result.function.ts +267 -0
  176. package/src/shared/wasm-codec/functions/decode-scored-results.function.ts +81 -27
  177. package/src/shared/wasm-codec/functions/encode-recall-params.function.ts +68 -0
  178. package/src/shared/wasm-codec/functions/encode-search-params.function.ts +4 -1
  179. package/src/shared/wasm-codec/index.ts +11 -3
  180. package/src/shared/worker-client/classes/worker-client.class.ts +24 -4
  181. package/src/shared/worker-client/index.ts +11 -1
  182. package/src/shared/worker-client/typings/recall-result.model.ts +98 -0
  183. package/src/shared/worker-client/typings/search-params.model.ts +2 -0
  184. package/src/shared/worker-client/typings/search-result.model.ts +24 -7
  185. package/src/shared/worker-daemon/classes/worker-daemon.class.ts +25 -4
  186. package/src/wasm/fs-database/kbdb_fs_database.d.ts +18 -0
  187. package/src/wasm/fs-database/kbdb_fs_database.js +30 -0
  188. package/src/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
  189. package/src/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +2 -0
  190. package/src/wasm/kb-worker/kbdb_worker.d.ts +38 -0
  191. package/src/wasm/kb-worker/kbdb_worker.js +56 -0
  192. package/src/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
  193. package/src/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +3 -0
@@ -0,0 +1,26 @@
1
+ # Detailed Documentation
2
+
3
+ In-depth guides and reference for @dikolab/kbdb.
4
+
5
+ ## Guides
6
+
7
+ - [CLI Reference](cli.md) -- Full command reference
8
+ with examples
9
+ - [MCP Server Setup](mcp-server.md) -- Configure
10
+ kbdb as an AI agent plugin
11
+ - [Library API](library-api.md) -- Use kbdb from
12
+ Node.js or Deno code
13
+
14
+ ## Technical Reference
15
+
16
+ - [Search and Ranking](search-and-ranking.md) --
17
+ How search works under the hood
18
+ - [Storage Architecture](storage.md) -- File formats,
19
+ directory layout, and design principles
20
+
21
+ ## See Also
22
+
23
+ - [Architecture Overview](../overview.md)
24
+ - [Design Goals](../goals/)
25
+ - [Module Reference](../modules/)
26
+ - [Release Notes](../release-notes/)
@@ -0,0 +1,608 @@
1
+ # CLI Reference
2
+
3
+ The `kbdb` command manages a file-based knowledge
4
+ base database. It imports documents, searches by
5
+ keyword, and manages skills and agents -- all from
6
+ the command line.
7
+
8
+ ## Installation
9
+
10
+ ```sh
11
+ # Node.js
12
+ npm install -g @dikolab/kbdb
13
+
14
+ # Deno
15
+ deno install
16
+ ```
17
+
18
+ ## Synopsis
19
+
20
+ ```
21
+ kbdb [options]
22
+ kbdb <command> [options] ...[parameters]
23
+ kbdb <command> <subcommand> [options] ...[parameters]
24
+ ```
25
+
26
+ ## Command Groups
27
+
28
+ | Group | Command | Description |
29
+ |-------|---------|-------------|
30
+ | Knowledge Base | `learn` | Import content from files or stdin |
31
+ | Knowledge Base | `unlearn` | Remove sections by kbid |
32
+ | Knowledge Base | `search` | Query the knowledge base |
33
+ | Knowledge Base | `content` | Compose rendered content from ids |
34
+ | Database | `db init` | Initialise a new `.kbdb` directory |
35
+ | Database | `db migrate` | Migrate database to current format |
36
+ | Maintenance | `status` | Show database status |
37
+ | Maintenance | `check` | Verify knowledge base integrity |
38
+ | Maintenance | `gc` | Garbage collect unreferenced sections |
39
+ | Maintenance | `rebuild` | Reconstruct all index files |
40
+ | Skills | `skill learn` | Create a new skill definition |
41
+ | Skills | `skill list` | List all skills |
42
+ | Skills | `skill get` | Retrieve a skill by name or kbid |
43
+ | Skills | `skill delete` | Remove a skill |
44
+ | Agents | `agent create` | Create an agent with skill refs |
45
+ | Agents | `agent list` | List all agents |
46
+ | Agents | `agent get` | Retrieve an agent by docid |
47
+ | Agents | `agent delete` | Remove an agent |
48
+ | Server | `mcp` | Start MCP server mode (stdio) |
49
+
50
+ ## Global Options
51
+
52
+ | Option | Short | Default | Description |
53
+ |--------|-------|---------|-------------|
54
+ | `--help` | `-h` | | Print help text and exit |
55
+ | `--version` | `-v` | | Print version and exit |
56
+ | `--db <path>` | | cwd | Database directory path |
57
+ | `--format <fmt>` | `-f` | `json` | Output format (`json`, `text`, `mcp`) |
58
+
59
+ ### `--db <path>`
60
+
61
+ Set the path to the directory containing the
62
+ `.kbdb` database folder. The actual database is
63
+ always at `${path}/.kbdb`.
64
+
65
+ - **CLI mode**: defaults to the current working
66
+ directory.
67
+ - **MCP mode**: falls back to the `KBDB_DIR`
68
+ environment variable. If neither `--db` nor
69
+ `KBDB_DIR` is set, the server exits with an error.
70
+
71
+ ## Search Options
72
+
73
+ These options apply to the `search` command.
74
+
75
+ | Option | Short | Default | Values | Description |
76
+ |--------|-------|---------|--------|-------------|
77
+ | `--mode <mode>` | `-m` | `sections` | `sections`, `documents`, `stats` | Result granularity |
78
+ | `--limit <n>` | `-l` | `20` | positive integer | Maximum results returned |
79
+ | `--format <fmt>` | `-f` | `json` | `json`, `text`, `mcp` | Output format |
80
+ | `--content` | `-c` | off | boolean flag | Hydrate results with section content |
81
+
82
+ ### Search Modes
83
+
84
+ | Mode | Description |
85
+ |------|-------------|
86
+ | `sections` | Individual matching sections (default) |
87
+ | `documents` | Complete documents containing matches |
88
+ | `stats` | Index statistics and result counts |
89
+
90
+ ### Output Formats
91
+
92
+ | Format | Description |
93
+ |--------|-------------|
94
+ | `json` | Pretty-printed JSON array |
95
+ | `text` | Numbered human-readable list with scores |
96
+ | `mcp` | JSON envelope for MCP protocol consumers |
97
+
98
+ ## Commands
99
+
100
+ ### `learn` -- Import Documents
101
+
102
+ ```
103
+ kbdb learn [options] <path | ->...
104
+ ```
105
+
106
+ Import and index documents into the knowledge base.
107
+ Accepts file paths, directory paths (scanned
108
+ recursively for `.md`, `.txt`, `.rst`, `.adoc`),
109
+ or `-` for stdin.
110
+
111
+ **Options:**
112
+
113
+ | Option | Description |
114
+ |--------|-------------|
115
+ | `--title <title>` | Section title (applies to all sections) |
116
+ | `--description <d>` | Section description |
117
+ | `--docid <docid>` | Attach sections to this document ID |
118
+
119
+ **Output:** JSON array of `LearnResult` objects:
120
+
121
+ ```json
122
+ [
123
+ {
124
+ "kbid": "abcdef1234567890abcdef1234",
125
+ "path": "/absolute/path/to/file.md",
126
+ "size": 1234,
127
+ "skipped": false
128
+ }
129
+ ]
130
+ ```
131
+
132
+ ### `unlearn` -- Remove Sections
133
+
134
+ ```
135
+ kbdb unlearn [options] <kbid>...
136
+ ```
137
+
138
+ Remove sections by their 26-character kb-id.
139
+ Cascades deletion to associated index entries
140
+ and ranking data.
141
+
142
+ **Output:** JSON array of `UnlearnResult` objects:
143
+
144
+ ```json
145
+ [
146
+ {
147
+ "kbid": "abcdef1234567890abcdef1234",
148
+ "removed": true
149
+ }
150
+ ]
151
+ ```
152
+
153
+ ### `search` -- Query the Knowledge Base
154
+
155
+ ```
156
+ kbdb search [options] <query>...
157
+ ```
158
+
159
+ Search by keywords or phrases. All query terms
160
+ are joined into a single query string.
161
+
162
+ **Output (json):**
163
+
164
+ ```json
165
+ [
166
+ {
167
+ "kbid": "abcdef1234567890abcdef1234",
168
+ "score": 8.7432,
169
+ "preview": "",
170
+ "matches": [
171
+ { "term": "machine", "frequency": 3 },
172
+ { "term": "learning", "frequency": 1 }
173
+ ]
174
+ }
175
+ ]
176
+ ```
177
+
178
+ **Output (text):**
179
+
180
+ ```
181
+ 1. [abcdef1234567890abcdef1234] (score: 8.7432)
182
+
183
+ matches: machine, learning
184
+ ```
185
+
186
+ ### `content` -- Compose Rendered Content
187
+
188
+ ```
189
+ kbdb content [options] <id>...
190
+ ```
191
+
192
+ Compose a rendered Markdown document from one or
193
+ more kbid or docid identifiers.
194
+
195
+ **Output:**
196
+
197
+ ```json
198
+ {
199
+ "type": "text/markdown",
200
+ "data": "# Rendered Markdown\n\nContent here...",
201
+ "total": 42
202
+ }
203
+ ```
204
+
205
+ ### `status` -- Database Status
206
+
207
+ ```
208
+ kbdb status [options]
209
+ ```
210
+
211
+ Show database status and cache statistics.
212
+
213
+ ### `check` -- Integrity Check
214
+
215
+ ```
216
+ kbdb check [options]
217
+ ```
218
+
219
+ Verify database integrity. Checks checksums,
220
+ document references, and type consistency.
221
+
222
+ **Output:**
223
+
224
+ ```json
225
+ {
226
+ "ok": false,
227
+ "errors": [
228
+ {
229
+ "type": "orphan_section",
230
+ "entity": "x9y8z7w6v5u4t3s2r1q0p9o8n7",
231
+ "detail": "Section not referenced by any document"
232
+ }
233
+ ]
234
+ }
235
+ ```
236
+
237
+ Exit code is `0` when `ok` is `true`, `1`
238
+ when errors are found.
239
+
240
+ ### `gc` -- Garbage Collection
241
+
242
+ ```
243
+ kbdb gc [options]
244
+ ```
245
+
246
+ Remove unreferenced sections (sections with no
247
+ document manifest references).
248
+
249
+ **Output:**
250
+
251
+ ```json
252
+ {
253
+ "removed_sections": 3,
254
+ "removed_bytes": 15360
255
+ }
256
+ ```
257
+
258
+ ### `rebuild` -- Rebuild Indexes
259
+
260
+ ```
261
+ kbdb rebuild [options]
262
+ ```
263
+
264
+ Reconstruct all index files from section files
265
+ and document manifests on disk.
266
+
267
+ **Output:**
268
+
269
+ ```json
270
+ {
271
+ "sections_reindexed": 39,
272
+ "terms_indexed": 1500
273
+ }
274
+ ```
275
+
276
+ ### `db init` -- Initialise Database
277
+
278
+ ```
279
+ kbdb db init [options]
280
+ ```
281
+
282
+ Create a blank `.kbdb` database directory at the
283
+ target path. No daemon required.
284
+
285
+ **Output:**
286
+
287
+ ```json
288
+ { "path": "/absolute/path/.kbdb", "created": true }
289
+ ```
290
+
291
+ ### `db migrate` -- Migrate Database
292
+
293
+ ```
294
+ kbdb db migrate [options]
295
+ ```
296
+
297
+ Upgrade a `.kbdb` database from an older format
298
+ version to the current version. Prints "already
299
+ up to date" when no migration is needed.
300
+
301
+ ### `skill learn` -- Create a Skill
302
+
303
+ ```
304
+ kbdb skill learn [options] --name <n> --body <file|->
305
+ ```
306
+
307
+ Read a skill body from a file or stdin, extract
308
+ `{{argName}}` placeholders, and store the skill
309
+ as an indexed section.
310
+
311
+ **Options:**
312
+
313
+ | Option | Required | Description |
314
+ |--------|----------|-------------|
315
+ | `--name <n>` | yes | Skill name (kebab-case) |
316
+ | `--description <d>` | no | Human-readable description |
317
+ | `--body <file\|->` | yes | Template body file or stdin |
318
+
319
+ **Output:**
320
+
321
+ ```json
322
+ {
323
+ "kbid": "abcdef1234567890abcdef1234",
324
+ "name": "summarize-document",
325
+ "arguments": ["docid", "max_points"]
326
+ }
327
+ ```
328
+
329
+ ### `skill list` -- List Skills
330
+
331
+ ```
332
+ kbdb skill list [options]
333
+ ```
334
+
335
+ **Output:** JSON array of skill summaries:
336
+
337
+ ```json
338
+ [
339
+ {
340
+ "kbid": "abcdef1234567890abcdef1234",
341
+ "name": "summarize-document",
342
+ "description": "Summarize a document...",
343
+ "argumentCount": 2
344
+ }
345
+ ]
346
+ ```
347
+
348
+ ### `skill get` -- Retrieve a Skill
349
+
350
+ ```
351
+ kbdb skill get [options] <name-or-kbid>
352
+ ```
353
+
354
+ Retrieve a skill by name or 26-character kbid.
355
+
356
+ **Output:** Full `SkillDefinition` JSON including
357
+ `kbid`, `name`, `description`, `arguments`, and
358
+ `body`.
359
+
360
+ ### `skill delete` -- Remove a Skill
361
+
362
+ ```
363
+ kbdb skill delete [options] <kbid>
364
+ ```
365
+
366
+ Remove a skill section by kbid. The skill body
367
+ and index entries are permanently deleted.
368
+
369
+ **Output:**
370
+
371
+ ```json
372
+ {
373
+ "kbid": "abcdef1234567890abcdef1234",
374
+ "removed": true
375
+ }
376
+ ```
377
+
378
+ ### `agent create` -- Create an Agent
379
+
380
+ ```
381
+ kbdb agent create [options] --name <n>
382
+ --persona <file|-> --skills <kbid,...>
383
+ ```
384
+
385
+ Create an agent document with a persona and an
386
+ ordered list of skill references.
387
+
388
+ **Options:**
389
+
390
+ | Option | Required | Description |
391
+ |--------|----------|-------------|
392
+ | `--name <n>` | yes | Agent name (kebab-case) |
393
+ | `--description <d>` | no | Human-readable description |
394
+ | `--persona <file\|->` | yes | Persona file or stdin |
395
+ | `--skills <kbid,...>` | yes | Comma-separated skill kbids |
396
+
397
+ **Output:**
398
+
399
+ ```json
400
+ {
401
+ "docid": "agent-code-reviewer",
402
+ "name": "code-reviewer",
403
+ "skills": [
404
+ "abcdef1234567890abcdef1234",
405
+ "fedcba9876543210fedcba9876"
406
+ ]
407
+ }
408
+ ```
409
+
410
+ ### `agent list` -- List Agents
411
+
412
+ ```
413
+ kbdb agent list [options]
414
+ ```
415
+
416
+ **Output:** JSON array of agent summaries:
417
+
418
+ ```json
419
+ [
420
+ {
421
+ "docid": "agent-code-reviewer",
422
+ "name": "code-reviewer",
423
+ "description": "Reviews code for best practices",
424
+ "skillCount": 2
425
+ }
426
+ ]
427
+ ```
428
+
429
+ ### `agent get` -- Retrieve an Agent
430
+
431
+ ```
432
+ kbdb agent get [options] <docid>
433
+ ```
434
+
435
+ Retrieve an agent with resolved skill definitions.
436
+ Dangling skill references (deleted skills) appear
437
+ with `name: null`.
438
+
439
+ **Output:** Full `AgentDefinition` JSON including
440
+ `docid`, `name`, `description`, `persona`, and
441
+ `skills` array.
442
+
443
+ ### `agent delete` -- Remove an Agent
444
+
445
+ ```
446
+ kbdb agent delete [options] <docid>
447
+ ```
448
+
449
+ Remove an agent document manifest. Referenced
450
+ skill sections are not deleted.
451
+
452
+ **Output:**
453
+
454
+ ```json
455
+ {
456
+ "docid": "agent-code-reviewer",
457
+ "removed": true
458
+ }
459
+ ```
460
+
461
+ ### `mcp` -- Start MCP Server
462
+
463
+ ```
464
+ kbdb mcp [options]
465
+ ```
466
+
467
+ Start a long-lived MCP server on stdio. Requires
468
+ `--db <path>` or the `KBDB_DIR` environment
469
+ variable. See the
470
+ [MCP Server Guide](mcp-server.md) for setup and
471
+ tool reference.
472
+
473
+ ## Example Workflows
474
+
475
+ ### Import Documents and Search
476
+
477
+ ```sh
478
+ # Initialise a new database
479
+ kbdb db init --db ~/my-project
480
+
481
+ # Import a single file
482
+ kbdb learn README.md --db ~/my-project
483
+
484
+ # Import an entire directory of docs
485
+ kbdb learn ./docs/ --db ~/my-project
486
+
487
+ # Import from stdin
488
+ cat notes.txt | kbdb learn - --db ~/my-project
489
+
490
+ # Search for content
491
+ kbdb search "API endpoint" --db ~/my-project
492
+
493
+ # Search with content preview and text output
494
+ kbdb search "authentication" --content \
495
+ --format text --limit 5
496
+
497
+ # Search in document mode
498
+ kbdb search "deployment" --mode documents
499
+
500
+ # Remove a section by kbid
501
+ kbdb unlearn abcdef1234567890abcdef1234
502
+
503
+ # Compose rendered content from multiple ids
504
+ kbdb content id1 id2 id3
505
+ ```
506
+
507
+ ### Create and Use Skills
508
+
509
+ ```sh
510
+ # Write a skill template with placeholders
511
+ cat > summarize.txt << 'EOF'
512
+ Summarize the document {{docid}}.
513
+ Extract at most {{max_points}} key points.
514
+ Return as a bulleted markdown list.
515
+ EOF
516
+
517
+ # Create the skill
518
+ kbdb skill learn --name summarize-document \
519
+ --description "Summarize a document" \
520
+ --body summarize.txt
521
+
522
+ # List all skills
523
+ kbdb skill list
524
+
525
+ # Retrieve a skill by name
526
+ kbdb skill get summarize-document
527
+
528
+ # Retrieve a skill by kbid
529
+ kbdb skill get abcdef1234567890abcdef1234
530
+
531
+ # Delete a skill
532
+ kbdb skill delete abcdef1234567890abcdef1234
533
+ ```
534
+
535
+ ### Create and Manage Agents
536
+
537
+ ```sh
538
+ # Write a persona file
539
+ cat > reviewer-persona.txt << 'EOF'
540
+ You are an expert code reviewer. You focus on
541
+ correctness, readability, and maintainability.
542
+ EOF
543
+
544
+ # Create an agent referencing existing skills
545
+ kbdb agent create --name code-reviewer \
546
+ --description "Reviews code for best practices" \
547
+ --persona reviewer-persona.txt \
548
+ --skills abc123,def456
549
+
550
+ # Create an agent with persona from stdin
551
+ cat persona.txt | kbdb agent create \
552
+ --name my-agent --persona - \
553
+ --skills abc123
554
+
555
+ # List all agents
556
+ kbdb agent list
557
+
558
+ # Retrieve an agent with resolved skills
559
+ kbdb agent get agent-code-reviewer
560
+
561
+ # Delete an agent (skills are preserved)
562
+ kbdb agent delete agent-code-reviewer
563
+ ```
564
+
565
+ ## Environment Variables
566
+
567
+ | Variable | Used By | Description |
568
+ |----------|---------|-------------|
569
+ | `KBDB_DIR` | MCP mode | Fallback database directory path when `--db` is not specified. Not used in CLI mode (CLI defaults to cwd). |
570
+
571
+ ## Exit Codes
572
+
573
+ | Code | Meaning |
574
+ |------|---------|
575
+ | `0` | Success |
576
+ | `1` | Error (invalid arguments, missing database, WASM error, version mismatch, unknown command, integrity check failure) |
577
+
578
+ ## Database Initialisation
579
+
580
+ Before any data command (`learn`, `unlearn`,
581
+ `search`, etc.), the CLI checks for an existing
582
+ `.kbdb` directory:
583
+
584
+ 1. **No `.kbdb` found + interactive terminal** --
585
+ prompts to create one.
586
+ 2. **No `.kbdb` found + non-interactive** -- prints
587
+ error and exits.
588
+ 3. **`.kbdb` found** -- runs a version gate before
589
+ proceeding. If migration is needed, prints an
590
+ error directing the user to run `kbdb db migrate`.
591
+
592
+ Use `kbdb db init` for explicit, non-interactive
593
+ database creation.
594
+
595
+ ## Design Notes
596
+
597
+ - The CLI is a thin pass-through. All keyword
598
+ extraction, indexing, ranking, and database I/O
599
+ is handled by the worker daemon and its WASM
600
+ modules.
601
+ - **stdout** contains only command output. No
602
+ banners, progress bars, or decorative text.
603
+ - **stderr** contains only errors (and deprecation
604
+ warnings for the legacy `--init`/`--migrate`
605
+ flags).
606
+ - Works on both Deno and Node.js (>= 20).
607
+ - The `--init` and `--migrate` flags are deprecated.
608
+ Use `kbdb db init` and `kbdb db migrate` instead.