@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,522 @@
1
+ # mcp/typings -- MCP Type Definitions
2
+
3
+ *Interfaces and type aliases for the MCP server's
4
+ JSON-RPC protocol and worker client contract.*
5
+
6
+ ## Source
7
+
8
+ `src/shared/mcp/typings/`
9
+
10
+ ## Typings
11
+
12
+ ### `McpWorkerClient`
13
+
14
+ **File:** `mcp-client.interface.ts`
15
+
16
+ Interface for the worker client dependency consumed
17
+ by the MCP server. Defines the knowledge-base
18
+ operations the server exposes as MCP tools and
19
+ resources without coupling to the concrete
20
+ `WorkerClient` class.
21
+
22
+ ```ts
23
+ interface McpWorkerClient {
24
+ search(params: {
25
+ readonly query: string;
26
+ readonly mode?: string;
27
+ readonly limit?: number;
28
+ readonly content?: boolean;
29
+ readonly offset?: number;
30
+ }): Promise<PagedSearchResult>;
31
+
32
+ addSection(params: {
33
+ readonly type: string;
34
+ readonly content: string;
35
+ readonly title?: string;
36
+ readonly description?: string;
37
+ readonly docid?: string;
38
+ }): Promise<string>;
39
+
40
+ removeSection(kbid: string): Promise<RemoveSectionResult>;
41
+
42
+ readSections(
43
+ kbids: string[],
44
+ ): Promise<Section[]>;
45
+
46
+ retrieveDocument(
47
+ docid: string,
48
+ ): Promise<unknown>;
49
+
50
+ listByType(
51
+ sectionType: string,
52
+ ): Promise<Section[]>;
53
+
54
+ listDocumentsByType(
55
+ docType: string,
56
+ ): Promise<unknown[]>;
57
+
58
+ recall(params: {
59
+ readonly kbid?: string;
60
+ readonly kbids?: readonly string[];
61
+ readonly depth?: number;
62
+ }): Promise<RecallResult | RecallResult[]>;
63
+
64
+ dbStatus(): Promise<DbStatus>;
65
+
66
+ disconnect(): void;
67
+ }
68
+ ```
69
+
70
+ | Method | Description |
71
+ |-------------------------|-----------------------------------|
72
+ | `listByType` | Returns all sections whose |
73
+ | | `sectionType` matches the given |
74
+ | | value (e.g. `'skill'`) |
75
+ | `listDocumentsByType` | Returns all document manifests |
76
+ | | whose `type` field matches (e.g. |
77
+ | | `'agent'`) |
78
+
79
+ ### `RemoveSectionResult`
80
+
81
+ **File:** `remove-section-result.model.ts`
82
+
83
+ Result returned by `McpWorkerClient.removeSection`.
84
+ Reports whether the section was found and removed
85
+ and the elapsed operation time.
86
+
87
+ ```ts
88
+ interface RemoveSectionResult {
89
+ readonly removed: boolean;
90
+ readonly elapsed_ms: number;
91
+ }
92
+ ```
93
+
94
+ ### `McpRequest`
95
+
96
+ **File:** `mcp-types.interface.ts`
97
+
98
+ A JSON-RPC 2.0 request message sent to the MCP
99
+ server. The `id` field is absent for notifications.
100
+
101
+ ```ts
102
+ interface McpRequest {
103
+ readonly jsonrpc: '2.0';
104
+ readonly id?: number | string;
105
+ readonly method: string;
106
+ readonly params?: Record<string, unknown>;
107
+ }
108
+ ```
109
+
110
+ ### `McpResponse`
111
+
112
+ **File:** `mcp-types.interface.ts`
113
+
114
+ A JSON-RPC 2.0 response message. Contains either
115
+ `result` (success) or `error` (failure), never both.
116
+
117
+ ```ts
118
+ interface McpResponse {
119
+ readonly jsonrpc: '2.0';
120
+ readonly id: number | string;
121
+ readonly result?: unknown;
122
+ readonly error?: {
123
+ readonly code: number;
124
+ readonly message: string;
125
+ readonly data?: unknown;
126
+ };
127
+ }
128
+ ```
129
+
130
+ ### `McpNotification`
131
+
132
+ **File:** `mcp-types.interface.ts`
133
+
134
+ A JSON-RPC 2.0 notification with no `id` and no
135
+ expected response.
136
+
137
+ ```ts
138
+ interface McpNotification {
139
+ readonly jsonrpc: '2.0';
140
+ readonly method: string;
141
+ readonly params?: Record<string, unknown>;
142
+ }
143
+ ```
144
+
145
+ ### `McpToolDefinition`
146
+
147
+ **File:** `mcp-types.interface.ts`
148
+
149
+ Definition of a single MCP tool exposed by the
150
+ server via `tools/list`.
151
+
152
+ ```ts
153
+ interface McpToolDefinition {
154
+ readonly name: string;
155
+ readonly description: string;
156
+ readonly inputSchema: Record<string, unknown>;
157
+ readonly annotations?: McpToolAnnotations;
158
+ }
159
+ ```
160
+
161
+ The optional `annotations` field carries hints for
162
+ MCP clients about the tool's side effects and safety
163
+ characteristics.
164
+
165
+ ### `McpResourceTemplate`
166
+
167
+ **File:** `mcp-types.interface.ts`
168
+
169
+ A URI template describing an MCP resource served
170
+ via `resources/templates/list`.
171
+
172
+ ```ts
173
+ interface McpResourceTemplate {
174
+ readonly uriTemplate: string;
175
+ readonly name: string;
176
+ readonly description: string;
177
+ readonly mimeType?: string;
178
+ }
179
+ ```
180
+
181
+ ### `McpServerInfo`
182
+
183
+ **File:** `mcp-types.interface.ts`
184
+
185
+ Identity information for the MCP server, reported
186
+ in the `initialize` response.
187
+
188
+ ```ts
189
+ interface McpServerInfo {
190
+ readonly name: string;
191
+ readonly version: string;
192
+ }
193
+ ```
194
+
195
+ ### `McpCapabilities`
196
+
197
+ **File:** `mcp-types.interface.ts`
198
+
199
+ MCP capability flags advertised during
200
+ initialization. Each key enables a group of methods.
201
+
202
+ ```ts
203
+ interface McpCapabilities {
204
+ readonly tools?: Record<string, never>;
205
+ readonly resources?: Record<string, never>;
206
+ readonly prompts?: Record<string, never>;
207
+ readonly logging?: Record<string, never>;
208
+ readonly completions?: Record<string, never>;
209
+ }
210
+ ```
211
+
212
+ | Key | Methods enabled |
213
+ |---------------|------------------------------------------|
214
+ | `tools` | `tools/list`, `tools/call` |
215
+ | `resources` | `resources/list`, `resources/read`, etc. |
216
+ | `prompts` | `prompts/list`, `prompts/get` |
217
+ | `logging` | `logging/setLevel` |
218
+ | `completions` | `completion/complete` |
219
+
220
+ ### `McpToolResult`
221
+
222
+ **File:** `mcp-types.interface.ts`
223
+
224
+ Result returned by `handleToolCall`. Tool-level
225
+ errors use `isError: true` in the result rather than
226
+ JSON-RPC error responses.
227
+
228
+ ```ts
229
+ interface McpToolResult {
230
+ readonly content: readonly {
231
+ readonly type: string;
232
+ readonly text: string;
233
+ }[];
234
+ readonly isError?: boolean;
235
+ }
236
+ ```
237
+
238
+ ### `McpResourceResult`
239
+
240
+ **File:** `mcp-types.interface.ts`
241
+
242
+ Result returned by `handleResourceRead`.
243
+
244
+ ```ts
245
+ interface McpResourceResult {
246
+ readonly contents: readonly {
247
+ readonly uri: string;
248
+ readonly mimeType: string;
249
+ readonly text: string;
250
+ }[];
251
+ }
252
+ ```
253
+
254
+ ### `McpPrompt`
255
+
256
+ **File:** `mcp-types.interface.ts`
257
+
258
+ A single prompt entry returned by `prompts/list`.
259
+ Skills use `name` directly; agents use `agent:<name>`.
260
+
261
+ ```ts
262
+ interface McpPrompt {
263
+ readonly name: string;
264
+ readonly description?: string;
265
+ readonly arguments?: readonly McpPromptArgument[];
266
+ }
267
+ ```
268
+
269
+ | Property | Description |
270
+ |---------------|--------------------------------------|
271
+ | `name` | Prompt name (or `agent:<name>`) |
272
+ | `description` | Human-readable description |
273
+ | `arguments` | Accepted arguments for the prompt |
274
+
275
+ ### `McpPromptArgument`
276
+
277
+ **File:** `mcp-types.interface.ts`
278
+
279
+ A single argument accepted by an MCP prompt.
280
+
281
+ ```ts
282
+ interface McpPromptArgument {
283
+ readonly name: string;
284
+ readonly description?: string;
285
+ readonly required?: boolean;
286
+ }
287
+ ```
288
+
289
+ | Property | Description |
290
+ |---------------|-----------------------------------|
291
+ | `name` | Argument identifier |
292
+ | `description` | Human-readable hint |
293
+ | `required` | Whether the argument is required |
294
+
295
+ ### `McpPromptMessage`
296
+
297
+ **File:** `mcp-types.interface.ts`
298
+
299
+ A single message in the array returned by `prompts/get`.
300
+
301
+ ```ts
302
+ interface McpPromptMessage {
303
+ readonly role: 'user' | 'assistant';
304
+ readonly content: McpPromptMessageContent;
305
+ }
306
+ ```
307
+
308
+ ### `McpPromptMessageContent`
309
+
310
+ **File:** `mcp-types.interface.ts`
311
+
312
+ Content body of an `McpPromptMessage`.
313
+
314
+ ```ts
315
+ interface McpPromptMessageContent {
316
+ readonly type: 'text';
317
+ readonly text: string;
318
+ }
319
+ ```
320
+
321
+ ### `McpToolAnnotations`
322
+
323
+ **File:** `mcp-types.interface.ts`
324
+
325
+ Hints for MCP clients about a tool's side effects
326
+ and safety characteristics.
327
+
328
+ ```ts
329
+ interface McpToolAnnotations {
330
+ readonly title?: string;
331
+ readonly readOnlyHint?: boolean;
332
+ readonly destructiveHint?: boolean;
333
+ readonly idempotentHint?: boolean;
334
+ readonly openWorldHint?: boolean;
335
+ }
336
+ ```
337
+
338
+ | Property | Description |
339
+ |-------------------|------------------------------------|
340
+ | `title` | Human-readable tool title |
341
+ | `readOnlyHint` | `true` if the tool only reads data |
342
+ | `destructiveHint` | `true` if the tool deletes data |
343
+ | `idempotentHint` | `true` if repeated calls are safe |
344
+ | `openWorldHint` | `true` if side effects may extend |
345
+ | | outside the knowledge base |
346
+
347
+ ### `McpCompletionRef`
348
+
349
+ **File:** `mcp-types.interface.ts`
350
+
351
+ Reference descriptor sent with a `completion/complete`
352
+ request, identifying the kind of value to complete.
353
+
354
+ ```ts
355
+ interface McpCompletionRef {
356
+ readonly type: 'ref/prompt' | 'ref/resource';
357
+ readonly name?: string;
358
+ readonly uri?: string;
359
+ }
360
+ ```
361
+
362
+ | Property | Description |
363
+ |----------|----------------------------------------------|
364
+ | `type` | `'ref/prompt'` to complete prompt names; |
365
+ | | `'ref/resource'` to complete resource URIs |
366
+ | `name` | Prompt name prefix (for `ref/prompt`) |
367
+ | `uri` | Resource URI prefix (for `ref/resource`) |
368
+
369
+ ### `McpCompletionResult`
370
+
371
+ **File:** `mcp-types.interface.ts`
372
+
373
+ Result returned by `handleCompletion`.
374
+
375
+ ```ts
376
+ interface McpCompletionResult {
377
+ readonly completion: {
378
+ readonly values: readonly string[];
379
+ readonly hasMore?: boolean;
380
+ readonly total?: number;
381
+ };
382
+ }
383
+ ```
384
+
385
+ | Property | Description |
386
+ |--------------------|----------------------------------|
387
+ | `completion.values`| Matching completion strings |
388
+ | `completion.hasMore` | More results exist beyond this list |
389
+ | `completion.total` | Total number of matches |
390
+
391
+ ### `McpLogLevel`
392
+
393
+ **File:** `mcp-types.interface.ts`
394
+
395
+ MCP log severity levels as defined in the MCP spec.
396
+
397
+ ```ts
398
+ type McpLogLevel =
399
+ | 'debug'
400
+ | 'info'
401
+ | 'notice'
402
+ | 'warning'
403
+ | 'error'
404
+ | 'critical'
405
+ | 'alert'
406
+ | 'emergency';
407
+ ```
408
+
409
+ ### `McpLogMessage`
410
+
411
+ **File:** `mcp-types.interface.ts`
412
+
413
+ Parameters for a `notifications/message` server
414
+ notification.
415
+
416
+ ```ts
417
+ interface McpLogMessage {
418
+ readonly level: McpLogLevel;
419
+ readonly logger?: string;
420
+ readonly data?: unknown;
421
+ }
422
+ ```
423
+
424
+ | Property | Description |
425
+ |----------|----------------------------------------|
426
+ | `level` | Severity level of the log entry |
427
+ | `logger` | Optional logger name (e.g. `'kbdb'`) |
428
+ | `data` | Log message or structured data |
429
+
430
+ ### `SkillDefinition`
431
+
432
+ **File:** `mcp-types.interface.ts`
433
+
434
+ A complete skill definition as stored in the knowledge
435
+ base and returned by skill retrieval operations.
436
+
437
+ ```ts
438
+ interface SkillDefinition {
439
+ readonly name: string;
440
+ readonly description: string;
441
+ readonly arguments?: readonly SkillArgument[];
442
+ readonly body: string;
443
+ }
444
+ ```
445
+
446
+ | Property | Description |
447
+ |---------------|---------------------------------------|
448
+ | `name` | Skill name in kebab-case |
449
+ | `description` | What the skill does |
450
+ | `arguments` | Auto-detected template arguments |
451
+ | `body` | Template body with `{{arg}}` syntax |
452
+
453
+ ### `SkillArgument`
454
+
455
+ **File:** `mcp-types.interface.ts`
456
+
457
+ A single argument accepted by a skill template.
458
+
459
+ ```ts
460
+ interface SkillArgument {
461
+ readonly name: string;
462
+ readonly type?: 'string' | 'number' | 'boolean';
463
+ readonly description?: string;
464
+ readonly required?: boolean;
465
+ }
466
+ ```
467
+
468
+ | Property | Description |
469
+ |---------------|------------------------------------|
470
+ | `name` | Argument identifier |
471
+ | `type` | Value type (defaults to `string`) |
472
+ | `description` | Human-readable argument hint |
473
+ | `required` | Whether the argument is required |
474
+
475
+ ### `AgentDefinition`
476
+
477
+ **File:** `mcp-types.interface.ts`
478
+
479
+ A complete agent definition as returned by agent
480
+ retrieval operations. Skills are resolved from kbid
481
+ references; missing skills appear with `name: null`.
482
+
483
+ ```ts
484
+ interface AgentDefinition {
485
+ readonly docid: string;
486
+ readonly name: string;
487
+ readonly description: string;
488
+ readonly persona: string;
489
+ readonly skills: readonly {
490
+ readonly kbid: string;
491
+ readonly name: string | null;
492
+ readonly position: number;
493
+ }[];
494
+ }
495
+ ```
496
+
497
+ | Property | Description |
498
+ |---------------|--------------------------------------|
499
+ | `docid` | Agent document identifier |
500
+ | `name` | Agent name in kebab-case |
501
+ | `description` | What the agent does |
502
+ | `persona` | System prompt text for the agent |
503
+ | `skills` | Ordered skill references (resolved) |
504
+
505
+ ## Error Code Constants
506
+
507
+ **File:** `src/shared/mcp/constants/mcp-error-codes.constant.ts`
508
+
509
+ Named constants for JSON-RPC 2.0 and MCP-specific
510
+ error codes. Use these instead of inline numbers.
511
+
512
+ | Constant | Value | Meaning |
513
+ |---------------------|---------|--------------------------------|
514
+ | `PARSE_ERROR` | -32700 | Malformed JSON in request |
515
+ | `METHOD_NOT_FOUND` | -32601 | Method not implemented |
516
+ | `INVALID_PARAMS` | -32602 | Invalid or missing parameters |
517
+ | `INTERNAL_ERROR` | -32603 | Unexpected server error |
518
+ | `RESOURCE_NOT_FOUND`| -32002 | Resource not found (MCP-specific); also used for pre-initialization guard |
519
+
520
+ No spec -- typings are compile-time only. Constants
521
+ have a spec (`mcp-error-codes.spec.ts`) that verifies
522
+ the exported values.
@@ -0,0 +1,94 @@
1
+ # shared -- All TypeScript Modules
2
+
3
+ *Every TypeScript module lives under `src/shared/`.
4
+ The two entry points (`src/cli.ts`,
5
+ `src/worker.ts`) are thin executables that import
6
+ from these sub-modules.*
7
+
8
+ ## Source
9
+
10
+ `src/shared/`
11
+
12
+ ## Responsibility
13
+
14
+ Contains all TypeScript logic. There is **no**
15
+ top-level `shared/index.ts` barrel -- consumers import
16
+ directly from `shared/[module]/index.ts` or from
17
+ specific files.
18
+
19
+ ```ts
20
+ import {
21
+ createWorkerClient,
22
+ } from './shared/worker-client/functions/create-worker-client.function.ts';
23
+ ```
24
+
25
+ ## Directory Layout
26
+
27
+ ```
28
+ src/shared/
29
+ ├── cli/ ← CLI commands
30
+ ├── mcp/ ← MCP server
31
+ ├── worker-client/ ← IPC client to daemon
32
+ ├── worker-daemon/ ← Daemon process logic
33
+ ├── version/ ← Package version constant
34
+ ├── runtime/ ← Deno / Node.js detection
35
+ ├── platform/ ← OS abstractions
36
+ └── hash/ ← SHA-256 hashing
37
+ ```
38
+
39
+ ## Modules
40
+
41
+ ### Application Modules
42
+
43
+ - **[cli/](cli/module.md)** -- CLI argument parsing,
44
+ command handlers (`learn`, `unlearn`, `search`),
45
+ and output formatting.
46
+ - **[mcp/](mcp/module.md)** -- MCP server, tool
47
+ handlers (`search`, `learn`, `unlearn`, `retrieve`,
48
+ `status`), and resource handlers.
49
+ - **[worker-client/](worker-client/module.md)** --
50
+ IPC client. Discovers or spawns the daemon, provides
51
+ typed async API for all operations.
52
+ - **[worker-daemon/](worker-daemon/module.md)** --
53
+ Daemon process. Loads WASM modules, listens on IPC,
54
+ serves JSON-RPC 2.0 requests.
55
+
56
+ ### Utility Modules
57
+
58
+ - **[version/](version/module.md)** -- Package version
59
+ constant.
60
+ - **[runtime/](runtime/module.md)** -- Deno / Node.js
61
+ runtime detection and argument access.
62
+ - **[platform/](platform/module.md)** -- Cross-platform
63
+ helpers (tmpdir, PID checks, IPC socket paths).
64
+ - **[hash/](hash/module.md)** -- SHA-256 hashing via
65
+ Web Crypto API.
66
+
67
+ ## Dependency Direction
68
+
69
+ ```
70
+ src/cli.ts
71
+ ├── shared/cli/
72
+ │ └── shared/worker-client/
73
+ └── shared/mcp/
74
+ └── shared/worker-client/
75
+
76
+ src/worker.ts
77
+ └── shared/worker-daemon/
78
+
79
+ shared/worker-client/
80
+ ├── shared/platform/
81
+ └── shared/hash/
82
+
83
+ shared/worker-daemon/
84
+ └── shared/platform/
85
+
86
+ mod.ts
87
+ └── shared/version/
88
+ ```
89
+
90
+ Utility modules (`version`, `runtime`, `platform`,
91
+ `hash`) have no dependencies on application modules.
92
+ Application modules may depend on utility modules
93
+ but not on each other, except through the
94
+ worker-client which both `cli` and `mcp` share.
@@ -0,0 +1,42 @@
1
+ # platform/functions -- Platform Functions
2
+
3
+ **Source:** `src/shared/platform/functions/`
4
+
5
+ ## getTmpdir
6
+
7
+ ```ts
8
+ getTmpdir(): string
9
+ ```
10
+
11
+ Returns the OS temp directory path.
12
+
13
+ - **Node:** `os.tmpdir()`
14
+ - **Deno:** `Deno.env.get("TMPDIR")`, or
15
+ `Deno.env.get("TEMP")` on Windows.
16
+
17
+ ## isProcessAlive
18
+
19
+ ```ts
20
+ isProcessAlive(pid: number): boolean
21
+ ```
22
+
23
+ Checks whether a process with the given PID is still
24
+ running.
25
+
26
+ - **Node:** `process.kill(pid, 0)`
27
+ - **Deno (Linux/macOS):** `Deno.kill(pid, "SIGCONT")`
28
+ - **Deno (Windows):** Spawns a `tasklist` subprocess.
29
+
30
+ Returns `true` if alive, `false` if not.
31
+
32
+ ## getIpcPath
33
+
34
+ ```ts
35
+ getIpcPath(ctx: string): string
36
+ ```
37
+
38
+ Returns the IPC socket or named-pipe path for a given
39
+ context identifier.
40
+
41
+ - **Unix:** `${tmpdir}/kb-worker-${ctx}.sock`
42
+ - **Windows:** `\\.\pipe\kb-worker-${ctx}`
@@ -0,0 +1,25 @@
1
+ # platform -- Platform Abstractions
2
+
3
+ **Source:** `src/shared/platform/`
4
+
5
+ ## Responsibility
6
+
7
+ Cross-platform helpers for temp directories, process
8
+ checks, and IPC socket paths. Abstracts OS + runtime
9
+ differences.
10
+
11
+ ## Directory Layout
12
+
13
+ ```
14
+ src/shared/platform/
15
+ index.ts
16
+ functions/
17
+ get-tmpdir.function.ts
18
+ is-process-alive.function.ts
19
+ get-ipc-path.function.ts
20
+ ```
21
+
22
+ ## Exports
23
+
24
+ - [Functions](functions.md) -- `getTmpdir`,
25
+ `isProcessAlive`, `getIpcPath`
@@ -0,0 +1,26 @@
1
+ # runtime/functions -- Runtime Functions
2
+
3
+ **Source:** `src/shared/runtime/functions/`
4
+
5
+ ## detectRuntime
6
+
7
+ ```ts
8
+ detectRuntime(): Runtime
9
+ ```
10
+
11
+ Returns the current `Runtime` type
12
+ (`'deno'` | `'node'`).
13
+
14
+ Detection logic:
15
+ checks `typeof Deno !== 'undefined'`.
16
+
17
+ ## getArgs
18
+
19
+ ```ts
20
+ getArgs(): string[]
21
+ ```
22
+
23
+ Returns CLI arguments as a string array.
24
+
25
+ - **Deno:** `Deno.args`
26
+ - **Node:** `process.argv.slice(2)`