@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,777 +0,0 @@
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 -Agf jsr:@dikolab/kbdb/cli
16
- ```
17
-
18
- ## Synopsis
19
-
20
- ```
21
- kbdb [options]
22
- kbdb <command> [options] ...[parameters]
23
- kbdb <command> <subcommand> [options] ...[parameters]
24
- kbdb --version
25
- kbdb -v <command> (verbose: warnings)
26
- kbdb -vv <command> (verbose: info)
27
- kbdb -vvv <command> (verbose: debug)
28
- ```
29
-
30
- ## Command Groups
31
-
32
- | Group | Command | Description |
33
- |-------|---------|-------------|
34
- | Knowledge Base | `learn` | Import content from files or stdin |
35
- | Knowledge Base | `unlearn` | Remove sections by kbid |
36
- | Knowledge Base | `search` | Query the knowledge base |
37
- | Knowledge Base | `recall` | Recall full context for sections |
38
- | Knowledge Base | `content` | Compose rendered content from ids |
39
- | Database | `db init` | Initialise a new `.kbdb` directory |
40
- | Database | `db migrate` | Migrate database to current format |
41
- | Maintenance | `status` | Show database status |
42
- | Maintenance | `check` | Verify knowledge base integrity |
43
- | Maintenance | `gc` | Garbage collect unreferenced sections |
44
- | Maintenance | `export` | Export database snapshot |
45
- | Maintenance | `rebuild` | Reconstruct all index files |
46
- | Skills | `skill learn` | Create a new skill definition |
47
- | Skills | `skill list` | List all skills |
48
- | Skills | `skill get` | Retrieve a skill by name or kbid |
49
- | Skills | `skill delete` | Remove a skill |
50
- | Agents | `agent create` | Create an agent with skill refs |
51
- | Agents | `agent list` | List all agents |
52
- | Agents | `agent get` | Retrieve an agent by docid |
53
- | Agents | `agent delete` | Remove an agent |
54
- | Server | `mcp` | Start MCP server mode (stdio) |
55
- | Worker | `worker stop` | Stop the background worker daemon |
56
- | Worker | `worker restart` | Restart the background worker daemon |
57
-
58
- ### Reading Data
59
-
60
- Three commands retrieve stored content at different
61
- granularities:
62
-
63
- | Command | Purpose |
64
- |---------|---------|
65
- | `search` | Find sections by query; returns ranked snippets |
66
- | `recall` | Expand full context around known kbids (post-search deep-dive) |
67
- | `content` | Compose rendered Markdown from kbid or docid identifiers |
68
-
69
- **When to use which:** Start with `search` to find
70
- relevant sections by keyword. Use `recall` to expand
71
- a search result into its full context -- parent
72
- documents, sibling sections, and references. Use
73
- `content` when you already know the exact kbid or
74
- docid and want rendered Markdown output.
75
-
76
- ## Global Options
77
-
78
- | Option | Short | Default | Description |
79
- |--------|-------|---------|-------------|
80
- | `--help` | `-h` | | Print help text and exit |
81
- | `--version` | | | Print version and exit |
82
- | `--verbose` | `-v` | | Set log level to WARNING (errors + warnings) |
83
- | `--verbose-info` | `-vv` | | Set log level to INFO |
84
- | `--verbose-debug` | `-vvv` | | Set log level to DEBUG (all messages) |
85
- | `--db <path>` | | cwd | Database directory path (optional) |
86
- | `--format <fmt>` | `-f` | `json` (text when interactive) | Output format (`json`, `text`, `mcp`) |
87
- | `--timeout-ms <ms>` | | `30000` | Per-request daemon timeout in milliseconds |
88
- | `--retry <n>` | | `1` | Max retries with daemon respawn on timeout |
89
- | `--non-interactive` | | | Suppress prompts; use defaults |
90
-
91
- ### `--db <path>`
92
-
93
- Set the path to the directory containing the
94
- `.kbdb` database folder. The actual database is
95
- always at `${path}/.kbdb`. This flag is optional.
96
-
97
- Resolution order:
98
-
99
- 1. `--db` flag (highest priority)
100
- 2. `KBDB_DB_DIR` environment variable
101
- 3. Current working directory (CLI mode only)
102
-
103
- - **CLI mode**: resolves using the order above.
104
- - **MCP mode**: falls back to the `KBDB_DB_DIR`
105
- environment variable. If neither `--db` nor
106
- `KBDB_DB_DIR` is set, the server exits with an
107
- error.
108
-
109
- ## Search Options
110
-
111
- These options apply to the `search` command.
112
-
113
- | Option | Short | Default | Values | Description |
114
- |--------|-------|---------|--------|-------------|
115
- | `--mode <mode>` | `-m` | `sections` | `sections`, `documents`, `stats` | Result granularity |
116
- | `--limit <n>` | `-l` | `20` | positive integer | Maximum results returned |
117
- | `--offset <n>` | | `0` | non-negative integer | Zero-based result offset for pagination |
118
- | `--format <fmt>` | `-f` | `json` | `json`, `text`, `mcp` | Output format |
119
- | `--algo <algo>` | | `lexical` | `lexical`, `vector`, `hybrid` | Search algorithm |
120
- | `--content` | `-c` | off | boolean flag | Hydrate results with section content |
121
-
122
- ### Search Algorithms
123
-
124
- | Algorithm | Description |
125
- |-----------|-------------|
126
- | `lexical` | Keyword matching with stemming and synonyms |
127
- | `vector` | Similarity search using embeddings |
128
- | `hybrid` | Combines keyword and similarity results for best coverage |
129
-
130
- ### Configuring Hybrid Search
131
-
132
- Hybrid and vector search use a built-in TF-IDF
133
- embedding provider by default -- no configuration
134
- needed. For higher quality embeddings, configure a
135
- provider via `worker.toml`:
136
-
137
- | Provider | Description |
138
- |----------|-------------|
139
- | *(none)* | Built-in TF-IDF (256 dimensions, works offline) |
140
- | `none` | Explicitly disabled; hybrid and vector return an error |
141
- | `onnx` | Local ONNX model (no network required) |
142
- | `api` | Remote embedding API (OpenAI-compatible endpoint) |
143
-
144
- ### Search Modes
145
-
146
- | Mode | Description |
147
- |------|-------------|
148
- | `sections` | Individual matching sections (default) |
149
- | `documents` | Complete documents containing matches |
150
- | `stats` | Index statistics and result counts |
151
-
152
- ### Output Formats
153
-
154
- | Format | Description |
155
- |--------|-------------|
156
- | `json` | Pretty-printed JSON array |
157
- | `text` | Numbered human-readable list with scores |
158
- | `mcp` | JSON envelope for MCP protocol consumers |
159
-
160
- ## Commands
161
-
162
- ### `learn` -- Import Documents
163
-
164
- ```
165
- kbdb learn [options] <path | ->...
166
- ```
167
-
168
- Import and index documents into the knowledge base.
169
- Accepts file paths, directory paths (scanned
170
- recursively for `.md`, `.txt`, `.rst`, `.adoc`),
171
- or `-` for stdin.
172
-
173
- **Options:**
174
-
175
- | Option | Description |
176
- |--------|-------------|
177
- | `--title <title>` | Section title (applies to all sections) |
178
- | `--description <d>` | Section description |
179
- | `--docid <docid>` | Attach sections to this document ID |
180
- | `--tags <t,...>` | Comma-separated tags for scoping and filtering |
181
- | `--replace` | Enable supersession by source key |
182
-
183
- **Output:** JSON array of `LearnResult` objects:
184
-
185
- ```json
186
- [
187
- {
188
- "kbid": "abcdef1234567890abcdef1234",
189
- "path": "/absolute/path/to/file.md",
190
- "size": 1234,
191
- "skipped": false,
192
- "superseded": null,
193
- "warnings": [],
194
- "near_duplicates": []
195
- }
196
- ]
197
- ```
198
-
199
- ### `unlearn` -- Remove Sections
200
-
201
- ```
202
- kbdb unlearn [options] <kbid>...
203
- ```
204
-
205
- Remove sections by their 26-character kb-id.
206
- Cascades deletion to associated index entries
207
- and ranking data.
208
-
209
- **Output:** JSON array of `UnlearnResult` objects:
210
-
211
- ```json
212
- [
213
- {
214
- "kbid": "abcdef1234567890abcdef1234",
215
- "removed": true
216
- }
217
- ]
218
- ```
219
-
220
- > kbid arguments accept unique prefixes -- kbdb
221
- > resolves them to full 26-character identifiers.
222
-
223
- ### `search` -- Query the Knowledge Base
224
-
225
- ```
226
- kbdb search [options] <query>...
227
- ```
228
-
229
- Search by keywords or phrases. All query terms
230
- are joined into a single query string.
231
-
232
- **Output (json):**
233
-
234
- ```json
235
- {
236
- "items": [
237
- {
238
- "kbid": "abcdef1234567890abcdef1234",
239
- "heading": "Machine Learning Overview",
240
- "type": "text/markdown",
241
- "docids": ["doc-5678"],
242
- "snippet": "...applies machine learning...",
243
- "matched_terms": ["machine", "learning"],
244
- "matched_fields": ["heading", "body"],
245
- "confidence": 1.0,
246
- "created_at": "2026-06-15T10:00:00Z"
247
- }
248
- ],
249
- "total": 42,
250
- "offset": 0,
251
- "limit": 20,
252
- "has_more": true,
253
- "relaxed": false
254
- }
255
- ```
256
-
257
- **Output (text):**
258
-
259
- ```
260
- 1. [abcdef1234567890abcdef1234] (confidence: 1.00)
261
- Machine Learning Overview
262
- ...applies machine learning...
263
- matches: machine, learning (heading, body)
264
- ```
265
-
266
- ### `recall` -- Recall Context
267
-
268
- ```
269
- kbdb recall [options] <kbid>...
270
- ```
271
-
272
- Retrieve full content and progressive context for
273
- one or more sections. Use after `search` to read
274
- relevant results.
275
-
276
- > Identifiers can be shortened to a unique prefix
277
- > (like git short hashes). kbdb resolves the prefix
278
- > to the full 26-character kbid.
279
-
280
- **Options:**
281
-
282
- | Option | Default | Description |
283
- |--------|---------|-------------|
284
- | `--depth <n>` | `0` | Context expansion level (0--3) |
285
-
286
- **Expansion levels:**
287
-
288
- | Depth | Returns |
289
- |-------|---------|
290
- | 0 | Full section content with heading, type, docids |
291
- | 1 | Depth 0 + parent documents + back-references |
292
- | 2 | Depth 1 + sibling sections + forward references |
293
- | 3 | Depth 2 + full text of referenced sections |
294
-
295
- **Output:**
296
-
297
- ```json
298
- {
299
- "kbid": "abcdef1234567890abcdef1234",
300
- "heading": "Architecture Overview",
301
- "type": "text/markdown",
302
- "content": "Full section text...",
303
- "docids": ["doc-5678"]
304
- }
305
- ```
306
-
307
- When multiple kbids are provided, output is a JSON
308
- array. The `--depth` parameter applies to all
309
- sections.
310
-
311
- ### `content` -- Compose Rendered Content
312
-
313
- ```
314
- kbdb content [options] <id>...
315
- ```
316
-
317
- Compose a rendered Markdown document from one or
318
- more kbid or docid identifiers.
319
-
320
- > Identifiers can be shortened to a unique prefix
321
- > (like git short hashes). kbdb resolves the prefix
322
- > to the full 26-character kbid.
323
-
324
- **Output:**
325
-
326
- ```json
327
- {
328
- "type": "text/markdown",
329
- "data": "# Rendered Markdown\n\nContent here...",
330
- "total": 42
331
- }
332
- ```
333
-
334
- ### `status` -- Database Status
335
-
336
- ```
337
- kbdb status [options]
338
- ```
339
-
340
- Show database status and cache statistics.
341
-
342
- ### `check` -- Integrity Check
343
-
344
- ```
345
- kbdb check [options]
346
- ```
347
-
348
- Verify database integrity. Checks checksums,
349
- document references, and type consistency.
350
-
351
- **Output:**
352
-
353
- ```json
354
- {
355
- "ok": false,
356
- "errors": [
357
- {
358
- "type": "orphan_section",
359
- "entity": "x9y8z7w6v5u4t3s2r1q0p9o8n7",
360
- "detail": "Section not referenced by any document"
361
- },
362
- {
363
- "type": "divergent_content",
364
- "entity": "a1b2c3d4e5f67890",
365
- "detail": "Sections sharing source key have different content"
366
- }
367
- ]
368
- }
369
- ```
370
-
371
- Exit code is `0` when `ok` is `true`, `1`
372
- when errors are found.
373
-
374
- ### `gc` -- Garbage Collection
375
-
376
- ```
377
- kbdb gc [options]
378
- ```
379
-
380
- Remove unreferenced sections (sections with no
381
- document manifest references).
382
-
383
- **Output:**
384
-
385
- ```json
386
- {
387
- "removed_sections": 3,
388
- "removed_bytes": 15360,
389
- "stale_sources": 1
390
- }
391
- ```
392
-
393
- ### `rebuild` -- Rebuild Indexes
394
-
395
- ```
396
- kbdb rebuild [options]
397
- ```
398
-
399
- Reconstruct all index files from section files
400
- and document manifests on disk.
401
-
402
- **Output:**
403
-
404
- ```json
405
- {
406
- "sections_reindexed": 39,
407
- "terms_indexed": 1500
408
- }
409
- ```
410
-
411
- ### `export` -- Export Database
412
-
413
- ```
414
- kbdb export [options] [<path>]
415
- ```
416
-
417
- Export the knowledge base as a self-contained
418
- directory snapshot for backup or versioning. Copies
419
- sections, documents, and catalog (no indexes -- they
420
- are rebuildable via `rebuild`). Defaults to
421
- `./kbdb-export/`.
422
-
423
- **Output:**
424
-
425
- ```json
426
- {
427
- "path": "/absolute/path/to/export",
428
- "sections_exported": 39,
429
- "documents_exported": 5
430
- }
431
- ```
432
-
433
- ### `db init` -- Initialise Database
434
-
435
- ```
436
- kbdb db init [options]
437
- ```
438
-
439
- Create a blank `.kbdb` database directory at the
440
- target path. No daemon required.
441
-
442
- **Output:**
443
-
444
- ```json
445
- { "path": "/absolute/path/.kbdb", "created": true }
446
- ```
447
-
448
- ### `db migrate` -- Migrate Database
449
-
450
- ```
451
- kbdb db migrate [options]
452
- ```
453
-
454
- Upgrade a `.kbdb` database from an older format
455
- version to the current version. Prints "already
456
- up to date" when no migration is needed.
457
-
458
- ### `skill learn` -- Create a Skill
459
-
460
- ```
461
- kbdb skill learn [options] --name <n> --body <file|->
462
- ```
463
-
464
- Read a skill body from a file or stdin, extract
465
- `{{argName}}` placeholders, and store the skill
466
- as an indexed section.
467
-
468
- **Options:**
469
-
470
- | Option | Required | Description |
471
- |--------|----------|-------------|
472
- | `--name <n>` | yes | Skill name (kebab-case) |
473
- | `--description <d>` | no | Human-readable description |
474
- | `--body <file\|->` | yes | Template body file or stdin |
475
-
476
- **Output:**
477
-
478
- ```json
479
- {
480
- "kbid": "abcdef1234567890abcdef1234",
481
- "name": "summarize-document",
482
- "arguments": ["docid", "max_points"]
483
- }
484
- ```
485
-
486
- ### `skill list` -- List Skills
487
-
488
- ```
489
- kbdb skill list [options]
490
- ```
491
-
492
- **Output:** JSON array of skill summaries:
493
-
494
- ```json
495
- [
496
- {
497
- "kbid": "abcdef1234567890abcdef1234",
498
- "name": "summarize-document",
499
- "description": "Summarize a document...",
500
- "argumentCount": 2
501
- }
502
- ]
503
- ```
504
-
505
- ### `skill get` -- Retrieve a Skill
506
-
507
- ```
508
- kbdb skill get [options] <name-or-kbid>
509
- ```
510
-
511
- Retrieve a skill by name or 26-character kbid.
512
-
513
- **Output:** Full `SkillDefinition` JSON including
514
- `kbid`, `name`, `description`, `arguments`, and
515
- `body`.
516
-
517
- ### `skill delete` -- Remove a Skill
518
-
519
- ```
520
- kbdb skill delete [options] <kbid>
521
- ```
522
-
523
- Remove a skill section by kbid. The skill body
524
- and index entries are permanently deleted.
525
-
526
- **Output:**
527
-
528
- ```json
529
- {
530
- "kbid": "abcdef1234567890abcdef1234",
531
- "removed": true
532
- }
533
- ```
534
-
535
- ### `agent create` -- Create an Agent
536
-
537
- ```
538
- kbdb agent create [options] --name <n>
539
- --persona <file|-> --skills <kbid,...>
540
- ```
541
-
542
- Create an agent document with a persona and an
543
- ordered list of skill references.
544
-
545
- **Options:**
546
-
547
- | Option | Required | Description |
548
- |--------|----------|-------------|
549
- | `--name <n>` | yes | Agent name (kebab-case) |
550
- | `--description <d>` | no | Human-readable description |
551
- | `--persona <file\|->` | yes | Persona file or stdin |
552
- | `--skills <kbid,...>` | yes | Comma-separated skill kbids |
553
-
554
- **Output:**
555
-
556
- ```json
557
- {
558
- "docid": "agent-code-reviewer",
559
- "name": "code-reviewer",
560
- "skills": [
561
- "abcdef1234567890abcdef1234",
562
- "fedcba9876543210fedcba9876"
563
- ]
564
- }
565
- ```
566
-
567
- ### `agent list` -- List Agents
568
-
569
- ```
570
- kbdb agent list [options]
571
- ```
572
-
573
- **Output:** JSON array of agent summaries:
574
-
575
- ```json
576
- [
577
- {
578
- "docid": "agent-code-reviewer",
579
- "name": "code-reviewer",
580
- "description": "Reviews code for best practices",
581
- "skillCount": 2
582
- }
583
- ]
584
- ```
585
-
586
- ### `agent get` -- Retrieve an Agent
587
-
588
- ```
589
- kbdb agent get [options] <docid>
590
- ```
591
-
592
- Retrieve an agent with resolved skill definitions.
593
- Dangling skill references (deleted skills) appear
594
- with `name: null`.
595
-
596
- **Output:** Full `AgentDefinition` JSON including
597
- `docid`, `name`, `description`, `persona`, and
598
- `skills` array.
599
-
600
- ### `agent delete` -- Remove an Agent
601
-
602
- ```
603
- kbdb agent delete [options] <docid>
604
- ```
605
-
606
- Remove an agent document manifest. Referenced
607
- skill sections are not deleted.
608
-
609
- **Output:**
610
-
611
- ```json
612
- {
613
- "docid": "agent-code-reviewer",
614
- "removed": true
615
- }
616
- ```
617
-
618
- ### `mcp` -- Start MCP Server
619
-
620
- ```
621
- kbdb mcp [options]
622
- ```
623
-
624
- Start a long-lived MCP server on stdio. Requires
625
- `--db <path>` or the `KBDB_DB_DIR` environment
626
- variable. See the
627
- [MCP Server Guide](mcp-server.md) for setup and
628
- tool reference.
629
-
630
- ## Example Workflows
631
-
632
- ### Import Documents and Search
633
-
634
- ```sh
635
- # Initialise a new database
636
- kbdb db init --db ~/my-project
637
-
638
- # Import a single file
639
- kbdb learn README.md --db ~/my-project
640
-
641
- # Import an entire directory of docs
642
- kbdb learn ./docs/ --db ~/my-project
643
-
644
- # Import from stdin
645
- cat notes.txt | kbdb learn - --db ~/my-project
646
-
647
- # Search for content
648
- kbdb search "API endpoint" --db ~/my-project
649
-
650
- # Search with content preview and text output
651
- kbdb search "authentication" --content \
652
- --format text --limit 5
653
-
654
- # Search in document mode
655
- kbdb search "deployment" --mode documents
656
-
657
- # Remove a section by kbid
658
- kbdb unlearn abcdef1234567890abcdef1234
659
-
660
- # Compose rendered content from multiple ids
661
- kbdb content id1 id2 id3
662
- ```
663
-
664
- ### Create and Use Skills
665
-
666
- ```sh
667
- # Write a skill template with placeholders
668
- cat > summarize.txt << 'EOF'
669
- Summarize the document {{docid}}.
670
- Extract at most {{max_points}} key points.
671
- Return as a bulleted markdown list.
672
- EOF
673
-
674
- # Create the skill
675
- kbdb skill learn --name summarize-document \
676
- --description "Summarize a document" \
677
- --body summarize.txt
678
-
679
- # List all skills
680
- kbdb skill list
681
-
682
- # Retrieve a skill by name
683
- kbdb skill get summarize-document
684
-
685
- # Retrieve a skill by kbid
686
- kbdb skill get abcdef1234567890abcdef1234
687
-
688
- # Delete a skill
689
- kbdb skill delete abcdef1234567890abcdef1234
690
- ```
691
-
692
- ### Create and Manage Agents
693
-
694
- ```sh
695
- # Write a persona file
696
- cat > reviewer-persona.txt << 'EOF'
697
- You are an expert code reviewer. You focus on
698
- correctness, readability, and maintainability.
699
- EOF
700
-
701
- # Create an agent referencing existing skills
702
- kbdb agent create --name code-reviewer \
703
- --description "Reviews code for best practices" \
704
- --persona reviewer-persona.txt \
705
- --skills abc123,def456
706
-
707
- # Create an agent with persona from stdin
708
- cat persona.txt | kbdb agent create \
709
- --name my-agent --persona - \
710
- --skills abc123
711
-
712
- # List all agents
713
- kbdb agent list
714
-
715
- # Retrieve an agent with resolved skills
716
- kbdb agent get agent-code-reviewer
717
-
718
- # Delete an agent (skills are preserved)
719
- kbdb agent delete agent-code-reviewer
720
- ```
721
-
722
- ## Environment Variables
723
-
724
- | Variable | Used By | Default | Description |
725
- |----------|---------|---------|-------------|
726
- | `KBDB_DB_DIR` | CLI + MCP | cwd (CLI) / none (MCP) | Fallback database directory path when `--db` is not specified. |
727
- | `KBDB_DAEMON_TIMEOUT` | CLI + MCP | `30000` | Per-request daemon timeout in milliseconds. Overridden by `--timeout-ms`. |
728
- | `KBDB_RETRY` | CLI + MCP | `1` | Max retries with daemon respawn on timeout. Overridden by `--retry`. |
729
- | `KBDB_LOG_LEVEL` | CLI + MCP + Daemon | `error` | Log verbosity: `debug`, `info`, `warning`, `error`. Overridden by `-v`/`-vv`/`-vvv`. |
730
- | `KBDB_NON_INTERACTIVE` | CLI + MCP + Daemon | off | Suppress interactive prompts. Accepts `1` or `true`. Overridden by `--non-interactive`. |
731
-
732
- ## Exit Codes
733
-
734
- | Code | Meaning |
735
- |------|---------|
736
- | `0` | Success |
737
- | `1` | Error (invalid arguments, missing database, WASM error, version mismatch, unknown command, integrity check failure) |
738
-
739
- ## Database Initialisation
740
-
741
- Before any data command (`learn`, `unlearn`,
742
- `search`, etc.), the CLI checks for an existing
743
- `.kbdb` directory:
744
-
745
- 1. **No `.kbdb` found + interactive terminal** --
746
- prompts to create one.
747
- 2. **No `.kbdb` found + non-interactive** -- prints
748
- error and exits.
749
-
750
- The `--non-interactive` flag (or
751
- `KBDB_NON_INTERACTIVE=1`) forces the non-interactive
752
- path regardless of terminal type. This is useful in
753
- scripts, CI pipelines, and automated testing.
754
-
755
- 3. **`.kbdb` found** -- runs a version gate before
756
- proceeding. If migration is needed, prints an
757
- error directing the user to run `kbdb db migrate`.
758
-
759
- Use `kbdb db init` for explicit, non-interactive
760
- database creation.
761
-
762
- ## Design Notes
763
-
764
- - The CLI is a thin pass-through. All keyword
765
- extraction, indexing, ranking, and database I/O
766
- is handled by the worker daemon and its WASM
767
- modules.
768
- - **stdout** contains only command output. No
769
- banners, progress bars, or decorative text.
770
- - **stderr** contains log messages. Default level is
771
- ERROR (errors only). Use `-v`/`-vv`/`-vvv` or
772
- `KBDB_LOG_LEVEL` to increase verbosity. Log lines
773
- are prefixed with per-level icons (✖⚠ℹ▸) and ANSI
774
- colors.
775
- - Works on both Deno and Node.js (>= 20).
776
- - The `--init` and `--migrate` flags are deprecated.
777
- Use `kbdb db init` and `kbdb db migrate` instead.