@dikolab/kbdb 0.5.0 → 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 +47 -24
  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/package.json +1 -1
  66. package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
  67. package/dist/wasm/kb-worker/package.json +1 -1
  68. package/dist/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
  69. package/dist/wasm/query-parser/package.json +1 -1
  70. package/dist/worker.d.ts +0 -7
  71. package/dist/worker.mjs +37 -6
  72. package/dist/worker.mjs.map +3 -3
  73. package/package.json +10 -9
  74. package/dist/chunk-BJXEVALU.mjs.map +0 -7
  75. package/dist/src/shared/cli/functions/resolve-raw-db-path.function.d.ts +0 -10
  76. package/docs/details/README.md +0 -30
  77. package/docs/details/agent-tooling.md +0 -132
  78. package/docs/details/cli.md +0 -777
  79. package/docs/details/knowledge-base.md +0 -180
  80. package/docs/details/library-api.md +0 -495
  81. package/docs/details/mcp-server.md +0 -482
  82. package/docs/details/search-and-ranking.md +0 -575
  83. package/docs/details/storage.md +0 -531
  84. package/docs/goals/agents.md +0 -751
  85. package/docs/goals/architecture.svg +0 -198
  86. package/docs/goals/auto-capture.md +0 -378
  87. package/docs/goals/benchmarking.md +0 -296
  88. package/docs/goals/cli.md +0 -2654
  89. package/docs/goals/concurrency.md +0 -259
  90. package/docs/goals/content-composer.md +0 -609
  91. package/docs/goals/content-parser.md +0 -279
  92. package/docs/goals/database.md +0 -1679
  93. package/docs/goals/document.md +0 -368
  94. package/docs/goals/hybrid-search.md +0 -465
  95. package/docs/goals/mcp.md +0 -1541
  96. package/docs/goals/overview.md +0 -124
  97. package/docs/goals/query-parser.md +0 -373
  98. package/docs/goals/query-result.md +0 -860
  99. package/docs/goals/semantic-dedup.md +0 -233
  100. package/docs/goals/skills.md +0 -810
  101. package/docs/goals/sync.md +0 -217
  102. package/docs/goals/worker-client.md +0 -1005
  103. package/docs/goals/worker-daemon.md +0 -1547
  104. package/docs/modules/overview.md +0 -319
  105. package/docs/modules/rust/embedding/module.md +0 -91
  106. package/docs/modules/rust/fs-database/functions/document.md +0 -48
  107. package/docs/modules/rust/fs-database/functions/integrity.md +0 -79
  108. package/docs/modules/rust/fs-database/functions/io.md +0 -87
  109. package/docs/modules/rust/fs-database/functions/module.md +0 -22
  110. package/docs/modules/rust/fs-database/functions/query-exec.md +0 -44
  111. package/docs/modules/rust/fs-database/functions/section.md +0 -76
  112. package/docs/modules/rust/fs-database/indexes/btree.md +0 -35
  113. package/docs/modules/rust/fs-database/indexes/corpus.md +0 -61
  114. package/docs/modules/rust/fs-database/indexes/inverted.md +0 -60
  115. package/docs/modules/rust/fs-database/indexes/module.md +0 -64
  116. package/docs/modules/rust/fs-database/indexes/positional.md +0 -39
  117. package/docs/modules/rust/fs-database/indexes/vectors.md +0 -110
  118. package/docs/modules/rust/fs-database/module.md +0 -150
  119. package/docs/modules/rust/fs-database/types/catalog.md +0 -53
  120. package/docs/modules/rust/fs-database/types/module.md +0 -12
  121. package/docs/modules/rust/fs-database/types/section.md +0 -127
  122. package/docs/modules/rust/kb-worker/functions/compose.md +0 -57
  123. package/docs/modules/rust/kb-worker/functions/module.md +0 -20
  124. package/docs/modules/rust/kb-worker/functions/retrieve.md +0 -194
  125. package/docs/modules/rust/kb-worker/functions/search.md +0 -173
  126. package/docs/modules/rust/kb-worker/functions/write.md +0 -172
  127. package/docs/modules/rust/kb-worker/module.md +0 -171
  128. package/docs/modules/rust/kb-worker/types/cache.md +0 -90
  129. package/docs/modules/rust/kb-worker/types/context.md +0 -26
  130. package/docs/modules/rust/kb-worker/types/module.md +0 -16
  131. package/docs/modules/rust/kb-worker/types/status.md +0 -29
  132. package/docs/modules/rust/kb-worker/types/token.md +0 -50
  133. package/docs/modules/rust/overview.md +0 -531
  134. package/docs/modules/rust/query-parser/functions/extract.md +0 -56
  135. package/docs/modules/rust/query-parser/functions/module.md +0 -18
  136. package/docs/modules/rust/query-parser/functions/parse.md +0 -33
  137. package/docs/modules/rust/query-parser/functions/pipeline.md +0 -9
  138. package/docs/modules/rust/query-parser/functions/rank.md +0 -85
  139. package/docs/modules/rust/query-parser/module.md +0 -131
  140. package/docs/modules/rust/query-parser/types/cache.md +0 -39
  141. package/docs/modules/rust/query-parser/types/keyphrase.md +0 -71
  142. package/docs/modules/rust/query-parser/types/module.md +0 -18
  143. package/docs/modules/rust/query-parser/types/token.md +0 -46
  144. package/docs/modules/rust/shared/content-composer/functions.md +0 -114
  145. package/docs/modules/rust/shared/content-composer/module.md +0 -147
  146. package/docs/modules/rust/shared/content-composer/types.md +0 -93
  147. package/docs/modules/rust/shared/content-parser/functions.md +0 -72
  148. package/docs/modules/rust/shared/content-parser/module.md +0 -99
  149. package/docs/modules/rust/shared/content-parser/types.md +0 -71
  150. package/docs/modules/rust/shared/corpus/module.md +0 -24
  151. package/docs/modules/rust/shared/corpus/types.md +0 -141
  152. package/docs/modules/rust/shared/document/module.md +0 -25
  153. package/docs/modules/rust/shared/document/types.md +0 -154
  154. package/docs/modules/rust/shared/encode/module.md +0 -22
  155. package/docs/modules/rust/shared/encode/traits.md +0 -304
  156. package/docs/modules/rust/shared/error/module.md +0 -28
  157. package/docs/modules/rust/shared/error/types.md +0 -302
  158. package/docs/modules/rust/shared/kbid/module.md +0 -24
  159. package/docs/modules/rust/shared/kbid/types.md +0 -147
  160. package/docs/modules/rust/shared/memory/functions.md +0 -209
  161. package/docs/modules/rust/shared/memory/module.md +0 -24
  162. package/docs/modules/rust/shared/module.md +0 -196
  163. package/docs/modules/rust/shared/pipeline/functions.md +0 -141
  164. package/docs/modules/rust/shared/pipeline/module.md +0 -62
  165. package/docs/modules/rust/shared/pipeline/types.md +0 -43
  166. package/docs/modules/rust/shared/query/module.md +0 -27
  167. package/docs/modules/rust/shared/query/types.md +0 -236
  168. package/docs/modules/rust/shared/section/module.md +0 -25
  169. package/docs/modules/rust/shared/section/types.md +0 -294
  170. package/docs/modules/rust/shared/term/module.md +0 -25
  171. package/docs/modules/rust/shared/term/types.md +0 -139
  172. package/docs/modules/typescript/cli.md +0 -131
  173. package/docs/modules/typescript/kbdb-worker.md +0 -150
  174. package/docs/modules/typescript/overview.md +0 -400
  175. package/docs/modules/typescript/shared/auto-capture/module.md +0 -73
  176. package/docs/modules/typescript/shared/cli/constants.md +0 -23
  177. package/docs/modules/typescript/shared/cli/functions.md +0 -809
  178. package/docs/modules/typescript/shared/cli/module.md +0 -138
  179. package/docs/modules/typescript/shared/cli/typings.md +0 -197
  180. package/docs/modules/typescript/shared/embedding/functions.md +0 -200
  181. package/docs/modules/typescript/shared/embedding/module.md +0 -77
  182. package/docs/modules/typescript/shared/embedding/typings.md +0 -124
  183. package/docs/modules/typescript/shared/hash/functions.md +0 -20
  184. package/docs/modules/typescript/shared/hash/module.md +0 -21
  185. package/docs/modules/typescript/shared/log/constants.md +0 -82
  186. package/docs/modules/typescript/shared/log/functions.md +0 -131
  187. package/docs/modules/typescript/shared/log/module.md +0 -153
  188. package/docs/modules/typescript/shared/log/typings.md +0 -82
  189. package/docs/modules/typescript/shared/mcp/classes.md +0 -179
  190. package/docs/modules/typescript/shared/mcp/functions.md +0 -386
  191. package/docs/modules/typescript/shared/mcp/module.md +0 -160
  192. package/docs/modules/typescript/shared/mcp/typings.md +0 -529
  193. package/docs/modules/typescript/shared/module.md +0 -110
  194. package/docs/modules/typescript/shared/platform/functions.md +0 -42
  195. package/docs/modules/typescript/shared/platform/module.md +0 -25
  196. package/docs/modules/typescript/shared/runtime/functions.md +0 -26
  197. package/docs/modules/typescript/shared/runtime/module.md +0 -27
  198. package/docs/modules/typescript/shared/runtime/typings.md +0 -13
  199. package/docs/modules/typescript/shared/version/module.md +0 -27
  200. package/docs/modules/typescript/shared/wasm-codec/functions.md +0 -391
  201. package/docs/modules/typescript/shared/wasm-codec/module.md +0 -98
  202. package/docs/modules/typescript/shared/worker-client/classes.md +0 -264
  203. package/docs/modules/typescript/shared/worker-client/functions.md +0 -175
  204. package/docs/modules/typescript/shared/worker-client/module.md +0 -92
  205. package/docs/modules/typescript/shared/worker-client/typings.md +0 -511
  206. package/docs/modules/typescript/shared/worker-daemon/classes.md +0 -239
  207. package/docs/modules/typescript/shared/worker-daemon/constants.md +0 -37
  208. package/docs/modules/typescript/shared/worker-daemon/functions.md +0 -234
  209. package/docs/modules/typescript/shared/worker-daemon/module.md +0 -118
  210. package/docs/modules/typescript/shared/worker-daemon/typings.md +0 -132
  211. package/docs/overview.md +0 -191
  212. package/docs/release-notes/0.1.0.md +0 -189
  213. package/docs/release-notes/0.1.1.md +0 -46
  214. package/docs/release-notes/0.1.2.md +0 -38
  215. package/docs/release-notes/0.1.3.md +0 -42
  216. package/docs/release-notes/0.2.0.md +0 -147
  217. package/docs/release-notes/0.3.0.md +0 -89
  218. package/docs/release-notes/0.3.1.md +0 -121
  219. package/docs/release-notes/0.3.2.md +0 -64
  220. package/docs/release-notes/0.4.0.md +0 -80
  221. package/docs/release-notes/0.4.1.md +0 -149
  222. package/docs/release-notes/0.4.3.md +0 -60
  223. package/docs/release-notes/0.5.0.md +0 -41
  224. package/docs/release-notes/README.md +0 -16
@@ -1,138 +0,0 @@
1
- # cli -- CLI Command Module
2
-
3
- *Parses command-line arguments, delegates operations
4
- to the worker daemon via worker-client, and prints
5
- results to stdout.*
6
-
7
- ## Source
8
-
9
- `src/shared/cli/`
10
-
11
- ## Responsibility
12
-
13
- Thin pass-through between the user's shell and the
14
- worker daemon. Parses arguments, validates input,
15
- creates a `WorkerClient`, calls the appropriate client
16
- method, formats the result, and prints to stdout.
17
- Errors go to stderr.
18
-
19
- The CLI does **not** perform keyword extraction,
20
- indexing, ranking, or database I/O. All processing is
21
- delegated to the worker daemon.
22
-
23
- See [CLI](../../../../goals/cli.md) for the full
24
- behavioral specification.
25
-
26
- ## Directory Layout
27
-
28
- ```
29
- src/shared/cli/
30
- ├── index.ts
31
- ├── constants/
32
- │ ├── defaults.constant.ts
33
- │ └── help-text.constant.ts
34
- ├── functions/
35
- │ ├── dispatch-command.function.ts
36
- │ ├── ensure-db.function.ts
37
- │ ├── error-to-message.function.ts
38
- │ ├── find-db.function.ts
39
- │ ├── format-output.function.ts
40
- │ ├── is-stdin-tty.function.ts
41
- │ ├── parse-args.function.ts
42
- │ ├── prompt-user.function.ts
43
- │ ├── resolve-kbid-prefix.function.ts
44
- │ ├── run-agent-create.function.ts
45
- │ ├── run-agent-delete.function.ts
46
- │ ├── run-agent-get.function.ts
47
- │ ├── run-agent-list.function.ts
48
- │ ├── run-check.function.ts
49
- │ ├── run-cli.function.ts
50
- │ ├── run-content.function.ts
51
- │ ├── run-db-init.function.ts
52
- │ ├── run-db-migrate.function.ts
53
- │ ├── run-export.function.ts
54
- │ ├── run-gc.function.ts
55
- │ ├── run-init.function.ts
56
- │ ├── run-learn.function.ts
57
- │ ├── run-migrate.function.ts
58
- │ ├── run-recall.function.ts
59
- │ ├── run-rebuild.function.ts
60
- │ ├── run-search.function.ts
61
- │ ├── run-skill-delete.function.ts
62
- │ ├── run-skill-get.function.ts
63
- │ ├── run-skill-learn.function.ts
64
- │ ├── run-skill-list.function.ts
65
- │ ├── run-status.function.ts
66
- │ ├── run-unlearn.function.ts
67
- │ ├── run-worker-restart.function.ts
68
- │ └── run-worker-stop.function.ts
69
- ├── typings/
70
- │ ├── cli-options.interface.ts
71
- │ ├── command-result.model.ts
72
- │ ├── learn-result.model.ts
73
- │ └── search-display.model.ts
74
- └── *.spec.ts
75
- ```
76
-
77
- ## Exports
78
-
79
- - **[functions.md](functions.md)** -- `runCli`,
80
- `dispatchCommand`, `parseArgs`, `findDb`,
81
- `resolveKbidPrefix`, `runInit`, `runMigrate`,
82
- `runLearn`, `runUnlearn`, `runSearch`, `runRecall`,
83
- `runContent`, `runExport`, `runStatus`, `runCheck`,
84
- `runGc`, `runRebuild`, `ensureDb`, `formatOutput`,
85
- `errorToMessage`, `isStdinTty`, `promptUser`,
86
- `runDbInit`, `runDbMigrate`, `runSkillLearn`,
87
- `runSkillList`, `runSkillGet`, `runSkillDelete`,
88
- `runAgentCreate`, `runAgentList`, `runAgentGet`,
89
- `runAgentDelete`, `runWorkerStop`,
90
- `runWorkerRestart`.
91
- - **[typings.md](typings.md)** -- `CliOptions`,
92
- `CommandResult`, `LearnResult`, `SearchDisplay`,
93
- `SearchMode`, `OutputFormat`.
94
- - **[constants.md](constants.md)** -- `DEFAULT_LIMIT`,
95
- `DEFAULT_FORMAT`.
96
-
97
- ## Execution Flow
98
-
99
- ```
100
- cli.ts (entry point)
101
-
102
- ├─ runCli(argv, deps)
103
- │ ├─ parseArgs(argv) → CliOptions
104
- │ ├─ command === 'help' → print HELP_TEXT
105
- │ ├─ command === 'version' → print VERSION
106
- │ ├─ command === 'init' → runInit(options)
107
- │ ├─ command === 'mcp' → startMcpServer
108
- │ ├─ command === 'migrate' → runMigrate(client, options)
109
- │ ├─ command === 'db-init' → runDbInit(options)
110
- │ ├─ command === 'db-migrate' → runDbMigrate(client, options)
111
- │ ├─ command === 'worker-stop' → runWorkerStop(dbDir)
112
- │ ├─ command === 'worker-restart' → runWorkerRestart(dbDir)
113
- │ └─ data command:
114
- │ ├─ findDb(options.dbPath) → dbDir
115
- │ ├─ if not found: isStdinTty() / promptUser()
116
- │ ├─ createWorkerClient({ contextPath: dbDir })
117
- │ ├─ version gate (checkVersion)
118
- │ └─ dispatchCommand(client, options)
119
- │ ├─ learn → runLearn(client, options)
120
- │ ├─ unlearn → runUnlearn(client, options)
121
- │ ├─ search → runSearch(client, options)
122
- │ ├─ recall → runRecall(client, options)
123
- │ ├─ content → runContent(client, options)
124
- │ ├─ export → runExport(client, options)
125
- │ ├─ status → runStatus(client, options)
126
- │ ├─ check → runCheck(client, options)
127
- │ ├─ gc → runGc(client, options)
128
- │ ├─ rebuild → runRebuild(client, options)
129
- │ ├─ skill-learn → runSkillLearn(client, options)
130
- │ ├─ skill-list → runSkillList(client, options)
131
- │ ├─ skill-get → runSkillGet(client, options)
132
- │ ├─ skill-delete → runSkillDelete(client, options)
133
- │ ├─ agent-create → runAgentCreate(client, options)
134
- │ ├─ agent-list → runAgentList(client, options)
135
- │ ├─ agent-get → runAgentGet(client, options)
136
- │ └─ agent-delete → runAgentDelete(client, options)
137
- └─ returns CommandResult { output?, error?, exitCode }
138
- ```
@@ -1,197 +0,0 @@
1
- # cli/typings -- CLI Type Definitions
2
-
3
- *Interfaces, type aliases, and data models for CLI
4
- argument parsing, command results, and display output.*
5
-
6
- ## Source
7
-
8
- `src/shared/cli/typings/`
9
-
10
- ## Typings
11
-
12
- ### `CliOptions`
13
-
14
- **File:** `cli-options.interface.ts`
15
-
16
- Parsed representation of all CLI arguments for a
17
- single invocation.
18
-
19
- ```ts
20
- interface CliOptions {
21
- command: string;
22
- args: string[];
23
- dbPath?: string;
24
- format: OutputFormat;
25
- mode: SearchMode;
26
- limit: number;
27
- title?: string;
28
- description?: string;
29
- docid?: string;
30
- content?: boolean;
31
- name?: string;
32
- persona?: string;
33
- body?: string;
34
- skills?: string[];
35
- timeoutMs?: number;
36
- retry?: number;
37
- logLevel?: LogLevel;
38
- }
39
- ```
40
-
41
- | Property | Description |
42
- |---------------|---------------------------------------|
43
- | `command` | CLI sub-command. Simple commands: |
44
- | | `'search'`, `'learn'`, `'unlearn'`, |
45
- | | `'content'`, `'check'`, `'gc'`, |
46
- | | `'rebuild'`, `'mcp'`, `'status'`. |
47
- | | Compound commands: `'db-init'`, |
48
- | | `'db-migrate'`, `'skill-learn'`, |
49
- | | `'skill-list'`, `'skill-get'`, |
50
- | | `'skill-delete'`, `'agent-create'`, |
51
- | | `'agent-list'`, `'agent-get'`, |
52
- | | `'agent-delete'`. |
53
- | `args` | Positional arguments |
54
- | `dbPath` | Database directory (`--db`) |
55
- | `format` | Output format flag |
56
- | `mode` | Search result mode (`--mode`) |
57
- | `limit` | Max results (`--limit`) |
58
- | `title` | Section title (`--title`) |
59
- | `description` | Section description |
60
- | `docid` | Document ID for learn command |
61
- | `content` | Hydrate search results with |
62
- | | section content when `true` |
63
- | `name` | Skill or agent name (`--name`) |
64
- | `persona` | Agent persona file path (`--persona`) |
65
- | `body` | Skill body file path (`--body`) |
66
- | `skills` | Ordered skill kbid list (`--skills`) |
67
- | `timeoutMs` | Request timeout in ms |
68
- | `retry` | Max retry count on timeout |
69
- | `logLevel` | Log verbosity level from `-v`/`-vv`/`-vvv` |
70
- | `nonInteractive` | Suppress prompts (`--non-interactive`) |
71
-
72
- ### `OutputFormat`
73
-
74
- **File:** `cli-options.interface.ts`
75
-
76
- Type alias for supported output formats.
77
-
78
- ```ts
79
- type OutputFormat = 'json' | 'text' | 'mcp';
80
- ```
81
-
82
- | Value | Description |
83
- |--------|---------------------------------|
84
- | `json` | Machine-readable JSON array |
85
- | `text` | Human-readable numbered list |
86
- | `mcp` | JSON envelope for MCP consumers |
87
-
88
- ### `SearchMode`
89
-
90
- **File:** `cli-options.interface.ts`
91
-
92
- Controls which entity type is returned by a search
93
- query.
94
-
95
- ```ts
96
- type SearchMode = 'sections' | 'documents' | 'stats';
97
- ```
98
-
99
- ### `LogLevel`
100
-
101
- **File:** `cli-options.interface.ts`
102
-
103
- Log verbosity level. Set via `-v`/`-vv`/`-vvv` flags
104
- or the `KBDB_LOG_LEVEL` environment variable.
105
-
106
- ```ts
107
- type LogLevel = 'debug' | 'info' | 'warning' | 'error';
108
- ```
109
-
110
- | Value | Description |
111
- |-----------|--------------------------------------|
112
- | `error` | Errors only (default) |
113
- | `warning` | Errors and warnings (`-v`) |
114
- | `info` | Errors, warnings, and info (`-vv`) |
115
- | `debug` | All messages including debug (`-vvv`)|
116
-
117
- ### `CommandResult`
118
-
119
- **File:** `command-result.model.ts`
120
-
121
- Result of dispatching a CLI command. Encapsulates
122
- output, error text, and exit code so the caller can
123
- decide how to present them without touching process
124
- globals.
125
-
126
- ```ts
127
- interface CommandResult {
128
- output?: string;
129
- error?: string;
130
- exitCode: number;
131
- }
132
- ```
133
-
134
- | Property | Description |
135
- |------------|--------------------------------------|
136
- | `output` | Text to write to stdout (if any) |
137
- | `error` | Error message for stderr (if any) |
138
- | `exitCode` | Process exit code (`0` = success) |
139
-
140
- ### `LearnResult`
141
-
142
- **File:** `learn-result.model.ts`
143
-
144
- Result record produced for each file processed by the
145
- learn command.
146
-
147
- ```ts
148
- interface LearnResult {
149
- kbid: string;
150
- path: string;
151
- size: number;
152
- skipped: boolean;
153
- }
154
- ```
155
-
156
- | Property | Description |
157
- |-----------|---------------------------------------|
158
- | `kbid` | Knowledge-base identifier assigned |
159
- | `path` | Absolute path to the source file |
160
- | `size` | Size of file content in bytes |
161
- | `skipped` | `true` when file was skipped |
162
-
163
- ### `SearchDisplay`
164
-
165
- **File:** `search-display.model.ts`
166
-
167
- A single search result formatted for display to the
168
- user.
169
-
170
- ```ts
171
- interface SearchDisplay {
172
- kbid: string;
173
- heading: string | null;
174
- type: string;
175
- docids: readonly string[];
176
- score: number;
177
- snippet: string;
178
- matched_terms: readonly string[];
179
- preview: string;
180
- }
181
- ```
182
-
183
- | Property | Description |
184
- |-----------------|--------------------------------------|
185
- | `kbid` | Knowledge-base identifier |
186
- | `heading` | Section heading, or `null` |
187
- | `type` | Semantic section type label |
188
- | `docids` | Parent document IDs for the section |
189
- | `score` | Relevance score from ranking engine |
190
- | `snippet` | Short excerpt highlighting matched |
191
- | | terms |
192
- | `matched_terms` | Terms from the query that matched |
193
- | | this section |
194
- | `preview` | Formatted preview string for |
195
- | | terminal output |
196
-
197
- No spec -- typings are compile-time only.
@@ -1,200 +0,0 @@
1
- # embedding/functions -- Embedding Functions
2
-
3
- **Source:** `src/shared/embedding/functions/`
4
-
5
- ## createEmbeddingProvider
6
-
7
- ```ts
8
- createEmbeddingProvider(
9
- config: EmbeddingConfig,
10
- ): EmbeddingProvider
11
- ```
12
-
13
- Factory that returns the appropriate `EmbeddingProvider`
14
- implementation based on the given config. Returns an
15
- `OnnxEmbeddingProvider` for `provider: 'onnx'`, an
16
- `ApiEmbeddingProvider` for `provider: 'api'`, or a
17
- `TfidfEmbeddingProvider` when config is undefined, or a
18
- `NullEmbeddingProvider` when `provider: 'none'`. The
19
- TF-IDF provider is the default when no embedding config
20
- is present, enabling hybrid search without external
21
- configuration.
22
-
23
- ## hashToken
24
-
25
- ```ts
26
- hashToken(token: string): number
27
- ```
28
-
29
- Computes an FNV-1a hash of a string token, returning
30
- a non-negative 32-bit unsigned integer. Used by
31
- `TfidfEmbeddingProvider` to map tokens to fixed-size
32
- vector buckets (feature hashing).
33
-
34
- ## tokenizeText
35
-
36
- ```ts
37
- tokenizeText(text: string): string[]
38
- ```
39
-
40
- Splits text into lowercase tokens by non-word
41
- characters, filtering out tokens shorter than 3
42
- characters. A simple JS tokenizer used by
43
- `TfidfEmbeddingProvider` for both document and query
44
- embedding.
45
-
46
- ## cosineSimilarity
47
-
48
- ```ts
49
- cosineSimilarity(
50
- a: Float32Array,
51
- b: Float32Array,
52
- ): number
53
- ```
54
-
55
- Computes the cosine similarity between two vectors. Returns a
56
- value in [-1, 1], where 1 means identical direction. Used by
57
- semantic near-duplicate detection (threshold >= 0.92) and by
58
- vector search ranking.
59
-
60
- Both vectors must have the same length (same embedding
61
- dimensions). Throws if lengths differ.
62
-
63
- ## buildVectorIndex
64
-
65
- ```ts
66
- buildVectorIndex(
67
- provider: EmbeddingProvider,
68
- sections: SectionRecord[],
69
- outPath: string,
70
- ): Promise<VectorIndexMeta>
71
- ```
72
-
73
- Builds the vector index file (`vectors.idx`) from all
74
- sections. Embeds each section's content via `batchEmbed`,
75
- writes fixed-width records (kbid + vector) to `outPath`, and
76
- writes `vectors-meta.toml` alongside it with model name,
77
- dimensions, and record count.
78
-
79
- Called by `rebuild` when an embedding provider is configured.
80
- Returns metadata about the built index.
81
-
82
- ## searchVectors
83
-
84
- ```ts
85
- searchVectors(
86
- provider: EmbeddingProvider,
87
- query: string,
88
- indexPath: string,
89
- limit: number,
90
- ): Promise<VectorSearchResult[]>
91
- ```
92
-
93
- Performs vector similarity search. Embeds the query, reads
94
- `vectors.idx`, computes cosine similarity against all stored
95
- vectors, and returns the top `limit` results sorted by
96
- similarity descending.
97
-
98
- Each result includes the kbid and similarity score. The
99
- results are passed to the RRF fusion step alongside lexical
100
- search results.
101
-
102
- Note: This is a brute-force linear scan. For corpus sizes
103
- under 100k sections, this is fast enough (< 50ms). A future
104
- version may add approximate nearest neighbor (ANN) indexing
105
- if scale demands it.
106
-
107
- ## appendVectorEntry
108
-
109
- ```ts
110
- appendVectorEntry(
111
- provider: EmbeddingProvider,
112
- kbid: string,
113
- content: string,
114
- indexPath: string,
115
- ): Promise<void>
116
- ```
117
-
118
- Appends a single vector entry to an existing vector index.
119
- Used during incremental `learn` to add new sections without
120
- a full rebuild.
121
-
122
- ## readVectorIndexMeta
123
-
124
- ```ts
125
- readVectorIndexMeta(
126
- indexPath: string,
127
- ): Promise<VectorIndexMeta | null>
128
- ```
129
-
130
- Reads the `vectors-meta.toml` file for an existing vector
131
- index. Returns `null` if the index does not exist.
132
-
133
- ## rrfFuse
134
-
135
- ```ts
136
- rrfFuse(
137
- lexical: { kbid: string; rank: number }[],
138
- vector: { kbid: string; score: number }[],
139
- k?: number,
140
- ): { kbid: string; score: number }[]
141
- ```
142
-
143
- Merges lexical and vector result lists using Reciprocal
144
- Rank Fusion. The `k` parameter controls rank smoothing
145
- (default: 60).
146
-
147
- ## jaccardCoefficient
148
-
149
- ```ts
150
- jaccardCoefficient(
151
- a: Set<string>,
152
- b: Set<string>,
153
- ): number
154
- ```
155
-
156
- Computes the Jaccard similarity coefficient between two
157
- term sets. Returns a value in [0, 1]. Used as the first
158
- pass in near-duplicate detection.
159
-
160
- ## detectNearDuplicates
161
-
162
- ```ts
163
- detectNearDuplicates(
164
- sections: SectionRecord[],
165
- provider?: EmbeddingProvider,
166
- ): Promise<NearDuplicateResult[]>
167
- ```
168
-
169
- Two-pass near-duplicate detection: Jaccard coefficient on
170
- term sets (always), then cosine similarity on embeddings
171
- (when a provider is available). Returns pairs of sections
172
- that exceed the similarity thresholds.
173
-
174
- ## detectStaleVectors
175
-
176
- ```ts
177
- detectStaleVectors(
178
- indexPath: string,
179
- currentKbids: Set<string>,
180
- ): Promise<StaleVectorsReport>
181
- ```
182
-
183
- Compares the vector index against the current section set
184
- and reports entries whose kbid no longer exists. Used by
185
- `check` to flag stale vector data.
186
-
187
- ## rebuildVectors
188
-
189
- ```ts
190
- rebuildVectors(
191
- provider: EmbeddingProvider,
192
- sections: SectionRecord[],
193
- outPath: string,
194
- ): Promise<VectorIndexMeta>
195
- ```
196
-
197
- Rebuilds the entire vector index from scratch. Embeds all
198
- sections and writes a fresh `vectors.idx` and
199
- `vectors-meta.toml`. Called by `rebuild` when an embedding
200
- provider is configured.
@@ -1,77 +0,0 @@
1
- # embedding -- Pluggable Embedding Computation
2
-
3
- **Source:** `src/shared/embedding/`
4
-
5
- ## Responsibility
6
-
7
- Pluggable embedding computation for hybrid lexical+vector search.
8
- Provides the `EmbeddingProvider` interface and implementations for
9
- different backends. Used by the worker daemon to embed sections at
10
- learn time and to compute query embeddings at search time.
11
-
12
- ## Directory Layout
13
-
14
- ```
15
- src/shared/embedding/
16
- index.ts
17
- functions/
18
- embed.function.ts
19
- batch-embed.function.ts
20
- cosine-similarity.function.ts
21
- build-vector-index.function.ts
22
- search-vectors.function.ts
23
- providers/
24
- null-embedding.provider.ts
25
- onnx-embedding.provider.ts
26
- api-embedding.provider.ts
27
- typings/
28
- embedding-provider.typing.ts
29
- embedding-config.typing.ts
30
- vector-search-result.typing.ts
31
- vector-index-meta.typing.ts
32
- ```
33
-
34
- ## Exports
35
-
36
- - [Functions](functions.md) -- `embed`, `batchEmbed`,
37
- `cosineSimilarity`, `buildVectorIndex`, `searchVectors`
38
- - [Typings](typings.md) -- `EmbeddingProvider`, `EmbeddingConfig`,
39
- `VectorSearchResult`, `VectorIndexMeta`
40
-
41
- ## Providers
42
-
43
- Four implementations of the `EmbeddingProvider` interface:
44
-
45
- - **TfidfEmbeddingProvider** -- Built-in default provider backed by
46
- the `kbdb-default-embedding` WASM crate. Delegates `embed()`
47
- calls to WASM exports that compute feature-hashed sublinear TF
48
- vectors (256 dimensions, L2-normalized) using kbdb-shared's
49
- tokenization pipeline. Zero external dependencies, zero
50
- configuration. Enables hybrid search out of the box.
51
- - **NullEmbeddingProvider** -- No-op provider (dimensions = 0).
52
- Available for explicit use when embeddings should be fully
53
- disabled.
54
- - **OnnxEmbeddingProvider** -- Local inference using ONNX Runtime.
55
- Loads a model from disk (e.g., `all-MiniLM-L6-v2`). Zero network
56
- calls, fully offline.
57
- - **ApiEmbeddingProvider** -- Remote inference via HTTP API (OpenAI,
58
- Anthropic, or compatible endpoints). Configured via `worker.toml`
59
- with endpoint URL and API key.
60
-
61
- ## Dependency Direction
62
-
63
- ```
64
- shared/embedding/
65
- ├── shared/hash/ (content hashing for cache keys)
66
- └── shared/platform/ (file paths for local models)
67
-
68
- shared/worker-daemon/
69
- └── shared/embedding/ (init provider at startup)
70
-
71
- shared/mcp/
72
- └── (indirect via worker-client)
73
- ```
74
-
75
- The embedding module is a utility module -- it depends only on other
76
- utility modules. The worker daemon initializes the provider at startup
77
- based on `worker.toml` config.