@dikolab/kbdb 0.1.6 → 0.2.1

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 (199) 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.d.ts +25 -0
  11. package/dist/mod.mjs +13 -2
  12. package/dist/mod.mjs.map +2 -2
  13. package/dist/src/cli.d.ts +8 -0
  14. package/dist/src/shared/cli/functions/format-output.function.d.ts +7 -7
  15. package/dist/src/shared/cli/functions/run-search.function.d.ts +25 -16
  16. package/dist/src/shared/cli/index.d.ts +1 -1
  17. package/dist/src/shared/cli/typings/cli-options.interface.d.ts +2 -0
  18. package/dist/src/shared/cli/typings/search-display.model.d.ts +25 -7
  19. package/dist/src/shared/mcp/functions/handle-recall.function.d.ts +29 -0
  20. package/dist/src/shared/mcp/typings/mcp-client.interface.d.ts +30 -11
  21. package/dist/src/shared/version/constants/version.constant.d.ts +1 -1
  22. package/dist/src/shared/wasm-codec/functions/decode-recall-result.function.d.ts +28 -0
  23. package/dist/src/shared/wasm-codec/functions/decode-scored-results.function.d.ts +14 -7
  24. package/dist/src/shared/wasm-codec/functions/encode-recall-params.function.d.ts +21 -0
  25. package/dist/src/shared/wasm-codec/functions/encode-search-params.function.d.ts +1 -1
  26. package/dist/src/shared/wasm-codec/index.d.ts +5 -2
  27. package/dist/src/shared/worker-client/classes/worker-client.class.d.ts +13 -3
  28. package/dist/src/shared/worker-client/index.d.ts +2 -1
  29. package/dist/src/shared/worker-client/typings/recall-result.model.d.ts +94 -0
  30. package/dist/src/shared/worker-client/typings/search-params.model.d.ts +2 -0
  31. package/dist/src/shared/worker-client/typings/search-result.model.d.ts +23 -7
  32. package/dist/src/shared/worker-daemon/classes/worker-daemon.class.d.ts +1 -0
  33. package/dist/src/worker.d.ts +7 -0
  34. package/dist/wasm/fs-database/kbdb_fs_database.d.ts +18 -0
  35. package/dist/wasm/fs-database/kbdb_fs_database.js +30 -0
  36. package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
  37. package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +2 -0
  38. package/dist/wasm/kb-worker/kbdb_worker.d.ts +38 -0
  39. package/dist/wasm/kb-worker/kbdb_worker.js +56 -0
  40. package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
  41. package/dist/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +3 -0
  42. package/dist/worker.mjs +283 -29
  43. package/dist/worker.mjs.map +4 -4
  44. package/docs/details/README.md +26 -0
  45. package/docs/details/cli.md +608 -0
  46. package/docs/details/library-api.md +406 -0
  47. package/docs/details/mcp-server.md +430 -0
  48. package/docs/details/search-and-ranking.md +457 -0
  49. package/docs/details/storage.md +529 -0
  50. package/docs/goals/agents.md +751 -0
  51. package/docs/goals/architecture.svg +198 -0
  52. package/docs/goals/cli.md +2308 -0
  53. package/docs/goals/content-composer.md +609 -0
  54. package/docs/goals/content-parser.md +279 -0
  55. package/docs/goals/database.md +1452 -0
  56. package/docs/goals/document.md +368 -0
  57. package/docs/goals/mcp.md +1467 -0
  58. package/docs/goals/overview.md +124 -0
  59. package/docs/goals/query-parser.md +271 -0
  60. package/docs/goals/query-result.md +693 -0
  61. package/docs/goals/skills.md +738 -0
  62. package/docs/goals/worker-client.md +944 -0
  63. package/docs/goals/worker-daemon.md +1447 -0
  64. package/docs/modules/overview.md +298 -0
  65. package/docs/modules/rust/fs-database/functions/document.md +48 -0
  66. package/docs/modules/rust/fs-database/functions/integrity.md +68 -0
  67. package/docs/modules/rust/fs-database/functions/io.md +87 -0
  68. package/docs/modules/rust/fs-database/functions/module.md +22 -0
  69. package/docs/modules/rust/fs-database/functions/query-exec.md +44 -0
  70. package/docs/modules/rust/fs-database/functions/section.md +59 -0
  71. package/docs/modules/rust/fs-database/indexes/btree.md +35 -0
  72. package/docs/modules/rust/fs-database/indexes/corpus.md +61 -0
  73. package/docs/modules/rust/fs-database/indexes/inverted.md +60 -0
  74. package/docs/modules/rust/fs-database/indexes/module.md +64 -0
  75. package/docs/modules/rust/fs-database/indexes/positional.md +39 -0
  76. package/docs/modules/rust/fs-database/module.md +149 -0
  77. package/docs/modules/rust/fs-database/types/catalog.md +53 -0
  78. package/docs/modules/rust/fs-database/types/module.md +12 -0
  79. package/docs/modules/rust/fs-database/types/section.md +101 -0
  80. package/docs/modules/rust/kb-worker/functions/compose.md +57 -0
  81. package/docs/modules/rust/kb-worker/functions/module.md +20 -0
  82. package/docs/modules/rust/kb-worker/functions/retrieve.md +194 -0
  83. package/docs/modules/rust/kb-worker/functions/search.md +173 -0
  84. package/docs/modules/rust/kb-worker/functions/write.md +172 -0
  85. package/docs/modules/rust/kb-worker/module.md +171 -0
  86. package/docs/modules/rust/kb-worker/types/cache.md +90 -0
  87. package/docs/modules/rust/kb-worker/types/context.md +26 -0
  88. package/docs/modules/rust/kb-worker/types/module.md +16 -0
  89. package/docs/modules/rust/kb-worker/types/status.md +29 -0
  90. package/docs/modules/rust/kb-worker/types/token.md +50 -0
  91. package/docs/modules/rust/overview.md +495 -0
  92. package/docs/modules/rust/query-parser/functions/extract.md +56 -0
  93. package/docs/modules/rust/query-parser/functions/module.md +16 -0
  94. package/docs/modules/rust/query-parser/functions/parse.md +33 -0
  95. package/docs/modules/rust/query-parser/functions/pipeline.md +103 -0
  96. package/docs/modules/rust/query-parser/functions/rank.md +85 -0
  97. package/docs/modules/rust/query-parser/module.md +136 -0
  98. package/docs/modules/rust/query-parser/types/cache.md +39 -0
  99. package/docs/modules/rust/query-parser/types/keyphrase.md +60 -0
  100. package/docs/modules/rust/query-parser/types/module.md +17 -0
  101. package/docs/modules/rust/query-parser/types/token.md +42 -0
  102. package/docs/modules/rust/shared/content-composer/functions.md +114 -0
  103. package/docs/modules/rust/shared/content-composer/module.md +147 -0
  104. package/docs/modules/rust/shared/content-composer/types.md +93 -0
  105. package/docs/modules/rust/shared/content-parser/functions.md +72 -0
  106. package/docs/modules/rust/shared/content-parser/module.md +99 -0
  107. package/docs/modules/rust/shared/content-parser/types.md +71 -0
  108. package/docs/modules/rust/shared/corpus/module.md +24 -0
  109. package/docs/modules/rust/shared/corpus/types.md +141 -0
  110. package/docs/modules/rust/shared/document/module.md +25 -0
  111. package/docs/modules/rust/shared/document/types.md +154 -0
  112. package/docs/modules/rust/shared/encode/module.md +22 -0
  113. package/docs/modules/rust/shared/encode/traits.md +304 -0
  114. package/docs/modules/rust/shared/error/module.md +28 -0
  115. package/docs/modules/rust/shared/error/types.md +302 -0
  116. package/docs/modules/rust/shared/kbid/module.md +24 -0
  117. package/docs/modules/rust/shared/kbid/types.md +147 -0
  118. package/docs/modules/rust/shared/memory/functions.md +209 -0
  119. package/docs/modules/rust/shared/memory/module.md +24 -0
  120. package/docs/modules/rust/shared/module.md +168 -0
  121. package/docs/modules/rust/shared/query/module.md +27 -0
  122. package/docs/modules/rust/shared/query/types.md +236 -0
  123. package/docs/modules/rust/shared/section/module.md +25 -0
  124. package/docs/modules/rust/shared/section/types.md +294 -0
  125. package/docs/modules/rust/shared/term/module.md +25 -0
  126. package/docs/modules/rust/shared/term/types.md +139 -0
  127. package/docs/modules/typescript/cli.md +129 -0
  128. package/docs/modules/typescript/kbdb-worker.md +135 -0
  129. package/docs/modules/typescript/overview.md +378 -0
  130. package/docs/modules/typescript/shared/cli/constants.md +23 -0
  131. package/docs/modules/typescript/shared/cli/functions.md +630 -0
  132. package/docs/modules/typescript/shared/cli/module.md +125 -0
  133. package/docs/modules/typescript/shared/cli/typings.md +172 -0
  134. package/docs/modules/typescript/shared/hash/functions.md +20 -0
  135. package/docs/modules/typescript/shared/hash/module.md +21 -0
  136. package/docs/modules/typescript/shared/mcp/classes.md +179 -0
  137. package/docs/modules/typescript/shared/mcp/functions.md +386 -0
  138. package/docs/modules/typescript/shared/mcp/module.md +160 -0
  139. package/docs/modules/typescript/shared/mcp/typings.md +522 -0
  140. package/docs/modules/typescript/shared/module.md +94 -0
  141. package/docs/modules/typescript/shared/platform/functions.md +42 -0
  142. package/docs/modules/typescript/shared/platform/module.md +25 -0
  143. package/docs/modules/typescript/shared/runtime/functions.md +26 -0
  144. package/docs/modules/typescript/shared/runtime/module.md +27 -0
  145. package/docs/modules/typescript/shared/runtime/typings.md +13 -0
  146. package/docs/modules/typescript/shared/version/module.md +27 -0
  147. package/docs/modules/typescript/shared/wasm-codec/functions.md +391 -0
  148. package/docs/modules/typescript/shared/wasm-codec/module.md +98 -0
  149. package/docs/modules/typescript/shared/worker-client/classes.md +264 -0
  150. package/docs/modules/typescript/shared/worker-client/functions.md +175 -0
  151. package/docs/modules/typescript/shared/worker-client/module.md +84 -0
  152. package/docs/modules/typescript/shared/worker-client/typings.md +508 -0
  153. package/docs/modules/typescript/shared/worker-daemon/classes.md +239 -0
  154. package/docs/modules/typescript/shared/worker-daemon/constants.md +37 -0
  155. package/docs/modules/typescript/shared/worker-daemon/functions.md +221 -0
  156. package/docs/modules/typescript/shared/worker-daemon/module.md +112 -0
  157. package/docs/modules/typescript/shared/worker-daemon/typings.md +126 -0
  158. package/docs/overview.md +188 -0
  159. package/docs/release-notes/0.1.0.md +189 -0
  160. package/docs/release-notes/0.1.1.md +46 -0
  161. package/docs/release-notes/0.1.2.md +38 -0
  162. package/docs/release-notes/0.1.3.md +42 -0
  163. package/docs/release-notes/0.2.0.md +147 -0
  164. package/docs/release-notes/README.md +9 -0
  165. package/mod.ts +26 -0
  166. package/package.json +8 -2
  167. package/src/cli.ts +9 -0
  168. package/src/shared/cli/functions/dispatch-command.function.ts +3 -3
  169. package/src/shared/cli/functions/format-output.function.ts +41 -34
  170. package/src/shared/cli/functions/parse-args.function.ts +7 -0
  171. package/src/shared/cli/functions/run-search.function.ts +53 -27
  172. package/src/shared/cli/index.ts +4 -1
  173. package/src/shared/cli/typings/cli-options.interface.ts +2 -0
  174. package/src/shared/cli/typings/search-display.model.ts +26 -7
  175. package/src/shared/mcp/functions/create-tool-definitions.function.ts +64 -4
  176. package/src/shared/mcp/functions/handle-recall.function.ts +66 -0
  177. package/src/shared/mcp/functions/handle-tool-call.function.ts +11 -1
  178. package/src/shared/mcp/typings/mcp-client.interface.ts +33 -15
  179. package/src/shared/version/constants/version.constant.ts +1 -1
  180. package/src/shared/wasm-codec/functions/decode-recall-result.function.ts +267 -0
  181. package/src/shared/wasm-codec/functions/decode-scored-results.function.ts +81 -27
  182. package/src/shared/wasm-codec/functions/encode-recall-params.function.ts +68 -0
  183. package/src/shared/wasm-codec/functions/encode-search-params.function.ts +4 -1
  184. package/src/shared/wasm-codec/index.ts +11 -3
  185. package/src/shared/worker-client/classes/worker-client.class.ts +24 -4
  186. package/src/shared/worker-client/index.ts +11 -1
  187. package/src/shared/worker-client/typings/recall-result.model.ts +98 -0
  188. package/src/shared/worker-client/typings/search-params.model.ts +2 -0
  189. package/src/shared/worker-client/typings/search-result.model.ts +24 -7
  190. package/src/shared/worker-daemon/classes/worker-daemon.class.ts +25 -4
  191. package/src/wasm/fs-database/kbdb_fs_database.d.ts +18 -0
  192. package/src/wasm/fs-database/kbdb_fs_database.js +30 -0
  193. package/src/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
  194. package/src/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +2 -0
  195. package/src/wasm/kb-worker/kbdb_worker.d.ts +38 -0
  196. package/src/wasm/kb-worker/kbdb_worker.js +56 -0
  197. package/src/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
  198. package/src/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +3 -0
  199. package/src/worker.ts +8 -0
@@ -0,0 +1,125 @@
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
+ │ ├── run-agent-create.function.ts
44
+ │ ├── run-agent-delete.function.ts
45
+ │ ├── run-agent-get.function.ts
46
+ │ ├── run-agent-list.function.ts
47
+ │ ├── run-check.function.ts
48
+ │ ├── run-cli.function.ts
49
+ │ ├── run-content.function.ts
50
+ │ ├── run-db-init.function.ts
51
+ │ ├── run-db-migrate.function.ts
52
+ │ ├── run-gc.function.ts
53
+ │ ├── run-init.function.ts
54
+ │ ├── run-learn.function.ts
55
+ │ ├── run-migrate.function.ts
56
+ │ ├── run-rebuild.function.ts
57
+ │ ├── run-search.function.ts
58
+ │ ├── run-skill-delete.function.ts
59
+ │ ├── run-skill-get.function.ts
60
+ │ ├── run-skill-learn.function.ts
61
+ │ ├── run-skill-list.function.ts
62
+ │ └── run-unlearn.function.ts
63
+ ├── typings/
64
+ │ ├── cli-options.interface.ts
65
+ │ ├── command-result.model.ts
66
+ │ ├── learn-result.model.ts
67
+ │ └── search-display.model.ts
68
+ └── *.spec.ts
69
+ ```
70
+
71
+ ## Exports
72
+
73
+ - **[functions.md](functions.md)** -- `runCli`,
74
+ `dispatchCommand`, `parseArgs`, `findDb`,
75
+ `runInit`, `runMigrate`, `runLearn`, `runUnlearn`,
76
+ `runSearch`, `runContent`, `runCheck`, `runGc`,
77
+ `runRebuild`, `ensureDb`, `formatOutput`,
78
+ `errorToMessage`, `isStdinTty`, `promptUser`,
79
+ `runDbInit`, `runDbMigrate`, `runSkillLearn`,
80
+ `runSkillList`, `runSkillGet`, `runSkillDelete`,
81
+ `runAgentCreate`, `runAgentList`, `runAgentGet`,
82
+ `runAgentDelete`.
83
+ - **[typings.md](typings.md)** -- `CliOptions`,
84
+ `CommandResult`, `LearnResult`, `SearchDisplay`,
85
+ `SearchMode`, `OutputFormat`.
86
+ - **[constants.md](constants.md)** -- `DEFAULT_LIMIT`,
87
+ `DEFAULT_FORMAT`.
88
+
89
+ ## Execution Flow
90
+
91
+ ```
92
+ cli.ts (entry point)
93
+
94
+ ├─ runCli(argv, deps)
95
+ │ ├─ parseArgs(argv) → CliOptions
96
+ │ ├─ command === 'help' → print HELP_TEXT
97
+ │ ├─ command === 'version' → print VERSION
98
+ │ ├─ command === 'init' → runInit(options)
99
+ │ ├─ command === 'mcp' → startMcpServer
100
+ │ ├─ command === 'migrate' → runMigrate(client, options)
101
+ │ ├─ command === 'db-init' → runDbInit(options)
102
+ │ ├─ command === 'db-migrate' → runDbMigrate(client, options)
103
+ │ └─ data command:
104
+ │ ├─ findDb(options.dbPath) → dbDir
105
+ │ ├─ if not found: isStdinTty() / promptUser()
106
+ │ ├─ createWorkerClient({ contextPath: dbDir })
107
+ │ ├─ version gate (checkVersion)
108
+ │ └─ dispatchCommand(client, options)
109
+ │ ├─ learn → runLearn(client, options)
110
+ │ ├─ unlearn → runUnlearn(client, options)
111
+ │ ├─ search → runSearch(client, options)
112
+ │ ├─ content → runContent(client, options)
113
+ │ ├─ check → runCheck(client, options)
114
+ │ ├─ gc → runGc(client, options)
115
+ │ ├─ rebuild → runRebuild(client, options)
116
+ │ ├─ skill-learn → runSkillLearn(client, options)
117
+ │ ├─ skill-list → runSkillList(client, options)
118
+ │ ├─ skill-get → runSkillGet(client, options)
119
+ │ ├─ skill-delete → runSkillDelete(client, options)
120
+ │ ├─ agent-create → runAgentCreate(client, options)
121
+ │ ├─ agent-list → runAgentList(client, options)
122
+ │ ├─ agent-get → runAgentGet(client, options)
123
+ │ └─ agent-delete → runAgentDelete(client, options)
124
+ └─ returns CommandResult { output?, error?, exitCode }
125
+ ```
@@ -0,0 +1,172 @@
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
+ }
36
+ ```
37
+
38
+ | Property | Description |
39
+ |---------------|---------------------------------------|
40
+ | `command` | CLI sub-command. Simple commands: |
41
+ | | `'search'`, `'learn'`, `'unlearn'`, |
42
+ | | `'content'`, `'check'`, `'gc'`, |
43
+ | | `'rebuild'`, `'mcp'`, `'status'`. |
44
+ | | Compound commands: `'db-init'`, |
45
+ | | `'db-migrate'`, `'skill-learn'`, |
46
+ | | `'skill-list'`, `'skill-get'`, |
47
+ | | `'skill-delete'`, `'agent-create'`, |
48
+ | | `'agent-list'`, `'agent-get'`, |
49
+ | | `'agent-delete'`. |
50
+ | `args` | Positional arguments |
51
+ | `dbPath` | Database directory (`--db`) |
52
+ | `format` | Output format flag |
53
+ | `mode` | Search result mode (`--mode`) |
54
+ | `limit` | Max results (`--limit`) |
55
+ | `title` | Section title (`--title`) |
56
+ | `description` | Section description |
57
+ | `docid` | Document ID for learn command |
58
+ | `content` | Hydrate search results with |
59
+ | | section content when `true` |
60
+ | `name` | Skill or agent name (`--name`) |
61
+ | `persona` | Agent persona file path (`--persona`) |
62
+ | `body` | Skill body file path (`--body`) |
63
+ | `skills` | Ordered skill kbid list (`--skills`) |
64
+
65
+ ### `OutputFormat`
66
+
67
+ **File:** `cli-options.interface.ts`
68
+
69
+ Type alias for supported output formats.
70
+
71
+ ```ts
72
+ type OutputFormat = 'json' | 'text' | 'mcp';
73
+ ```
74
+
75
+ | Value | Description |
76
+ |--------|---------------------------------|
77
+ | `json` | Machine-readable JSON array |
78
+ | `text` | Human-readable numbered list |
79
+ | `mcp` | JSON envelope for MCP consumers |
80
+
81
+ ### `SearchMode`
82
+
83
+ **File:** `cli-options.interface.ts`
84
+
85
+ Controls which entity type is returned by a search
86
+ query.
87
+
88
+ ```ts
89
+ type SearchMode = 'sections' | 'documents' | 'stats';
90
+ ```
91
+
92
+ ### `CommandResult`
93
+
94
+ **File:** `command-result.model.ts`
95
+
96
+ Result of dispatching a CLI command. Encapsulates
97
+ output, error text, and exit code so the caller can
98
+ decide how to present them without touching process
99
+ globals.
100
+
101
+ ```ts
102
+ interface CommandResult {
103
+ output?: string;
104
+ error?: string;
105
+ exitCode: number;
106
+ }
107
+ ```
108
+
109
+ | Property | Description |
110
+ |------------|--------------------------------------|
111
+ | `output` | Text to write to stdout (if any) |
112
+ | `error` | Error message for stderr (if any) |
113
+ | `exitCode` | Process exit code (`0` = success) |
114
+
115
+ ### `LearnResult`
116
+
117
+ **File:** `learn-result.model.ts`
118
+
119
+ Result record produced for each file processed by the
120
+ learn command.
121
+
122
+ ```ts
123
+ interface LearnResult {
124
+ kbid: string;
125
+ path: string;
126
+ size: number;
127
+ skipped: boolean;
128
+ }
129
+ ```
130
+
131
+ | Property | Description |
132
+ |-----------|---------------------------------------|
133
+ | `kbid` | Knowledge-base identifier assigned |
134
+ | `path` | Absolute path to the source file |
135
+ | `size` | Size of file content in bytes |
136
+ | `skipped` | `true` when file was skipped |
137
+
138
+ ### `SearchDisplay`
139
+
140
+ **File:** `search-display.model.ts`
141
+
142
+ A single search result formatted for display to the
143
+ user.
144
+
145
+ ```ts
146
+ interface SearchDisplay {
147
+ kbid: string;
148
+ heading: string | null;
149
+ type: string;
150
+ docids: readonly string[];
151
+ score: number;
152
+ snippet: string;
153
+ matched_terms: readonly string[];
154
+ preview: string;
155
+ }
156
+ ```
157
+
158
+ | Property | Description |
159
+ |-----------------|--------------------------------------|
160
+ | `kbid` | Knowledge-base identifier |
161
+ | `heading` | Section heading, or `null` |
162
+ | `type` | Semantic section type label |
163
+ | `docids` | Parent document IDs for the section |
164
+ | `score` | Relevance score from ranking engine |
165
+ | `snippet` | Short excerpt highlighting matched |
166
+ | | terms |
167
+ | `matched_terms` | Terms from the query that matched |
168
+ | | this section |
169
+ | `preview` | Formatted preview string for |
170
+ | | terminal output |
171
+
172
+ No spec -- typings are compile-time only.
@@ -0,0 +1,20 @@
1
+ # hash/functions -- Hash Functions
2
+
3
+ **Source:** `src/shared/hash/functions/`
4
+
5
+ ## computeSha256
6
+
7
+ ```ts
8
+ computeSha256(input: string): Promise<string>
9
+ ```
10
+
11
+ Returns a hex-encoded SHA-256 hash of the input string.
12
+
13
+ Uses the Web Crypto API
14
+ (`globalThis.crypto.subtle.digest`), which is available
15
+ in both Deno and Node.js >= 20.
16
+
17
+ ### Usage
18
+
19
+ Used by `compute-context-id.function.ts` (truncated to
20
+ 16 hex chars) and content hashing.
@@ -0,0 +1,21 @@
1
+ # hash -- Hashing Utilities
2
+
3
+ **Source:** `src/shared/hash/`
4
+
5
+ ## Responsibility
6
+
7
+ SHA-256 hashing for context ID computation and
8
+ content-addressable storage.
9
+
10
+ ## Directory Layout
11
+
12
+ ```
13
+ src/shared/hash/
14
+ index.ts
15
+ functions/
16
+ compute-sha256.function.ts
17
+ ```
18
+
19
+ ## Exports
20
+
21
+ - [Functions](functions.md) -- `computeSha256`
@@ -0,0 +1,179 @@
1
+ # mcp/classes -- MCP Server Class
2
+
3
+ *Wraps the MCP protocol layer and routes incoming
4
+ tool calls and resource reads to handler functions.*
5
+
6
+ ## Source
7
+
8
+ `src/shared/mcp/classes/`
9
+
10
+ ## Classes
11
+
12
+ ### `McpServer`
13
+
14
+ **File:** `mcp-server.class.ts`
15
+
16
+ Long-lived MCP server that communicates over stdio.
17
+ Hand-rolled JSON-RPC 2.0 protocol handling over
18
+ stdio using `node:readline`. Implements protocol
19
+ version **2025-11-25**.
20
+
21
+ ```ts
22
+ class McpServer {
23
+ constructor(client: McpWorkerClient);
24
+ listen(): Promise<void>;
25
+ handleLineForTest(line: string): Promise<McpResponse | null>;
26
+ }
27
+ ```
28
+
29
+ #### Constructor
30
+
31
+ Takes a `McpWorkerClient` instance. Routing happens
32
+ at request dispatch time -- each incoming method
33
+ name is matched to the appropriate handler.
34
+
35
+ **Properties:**
36
+
37
+ | Property | Type | Description |
38
+ |--------------------|-----------------------|------------------------------|
39
+ | `logLevel` | `McpLogLevel \| null` | Current log level; `null` |
40
+ | | | until `logging/setLevel` is |
41
+ | | | received |
42
+ | `subscriptions` | `Set<string>` | Set of URIs the client has |
43
+ | | | subscribed to via |
44
+ | | | `resources/subscribe` |
45
+ | `hostCapabilities` | `object \| null` | Host capabilities received |
46
+ | | | in the `initialize` params; |
47
+ | | | `null` until initialized |
48
+
49
+ **Protocol methods handled:**
50
+
51
+ | Method | Behavior |
52
+ |-------------------------------|----------------------------------|
53
+ | `initialize` | Returns protocol version and capabilities |
54
+ | `ping` | Returns `{}` (liveness check) |
55
+ | `notifications/initialized` | Sets initialized flag |
56
+ | `notifications/cancelled` | Silently ignored |
57
+ | `tools/list` | Returns tool definitions |
58
+ | `tools/call` | Dispatches to `handleToolCall` |
59
+ | `prompts/list` | Returns prompt definitions |
60
+ | `prompts/get` | Renders and returns prompt |
61
+ | `completion/complete` | Returns completion suggestions |
62
+ | `logging/setLevel` | Stores requested log level |
63
+ | `roots/list` | Returns `.kbdb` directory root |
64
+ | `resources/list` | Returns `{ resources: [] }` |
65
+ | `resources/templates/list` | Returns URI templates |
66
+ | `resources/read` | Dispatches to `handleResourceRead` |
67
+ | `resources/subscribe` | Adds URI to subscriptions set |
68
+ | `resources/unsubscribe` | Removes URI from subscriptions |
69
+
70
+ **Pre-initialization guard**: all methods except
71
+ `initialize` and `ping` return error `-32002`
72
+ ("Server not initialized") until
73
+ `notifications/initialized` is received.
74
+
75
+ **Tools (via `handleToolCall`):**
76
+
77
+ | Tool | Client Method / Handler |
78
+ |----------------|-------------------------------------|
79
+ | `search` | `client.search()` |
80
+ | `learn` | `client.addSection()` |
81
+ | `unlearn` | `client.removeSection()` |
82
+ | `retrieve` | `client.readSections()` or |
83
+ | | `client.retrieveDocument()` |
84
+ | `recall` | `handleRecall(params, client)` |
85
+ | `status` | `client.dbStatus()` |
86
+ | `skill-learn` | `handleSkillLearn(params, client)` |
87
+ | `skill-list` | `handleSkillList(client)` |
88
+ | `skill-get` | `handleSkillGet(params, client)` |
89
+ | `skill-delete` | `handleSkillDelete(params, client)` |
90
+ | `agent-create` | `handleAgentCreate(params, client)` |
91
+ | `agent-list` | `handleAgentList(client)` |
92
+ | `agent-get` | `handleAgentGet(params, client)` |
93
+ | `agent-delete` | `handleAgentDelete(params, client)` |
94
+
95
+ **Resource URI templates:**
96
+
97
+ | URI Template | MIME Type |
98
+ |-------------------------------|------------------|
99
+ | `kbdb://section/{kbid}` | `text/plain` |
100
+ | `kbdb://document/{docid}` | `application/json` |
101
+
102
+ #### `listen()`
103
+
104
+ Returns a `Promise<void>` that resolves when stdin
105
+ closes. Reads JSON-RPC 2.0 requests from stdin,
106
+ dispatches to the appropriate handler, and writes
107
+ JSON-RPC responses to stdout. Disconnects the
108
+ `McpWorkerClient` when the promise resolves.
109
+
110
+ #### `handleLineForTest(line)`
111
+
112
+ Processes a single raw input line and returns the
113
+ JSON-RPC response, or `null` for notifications
114
+ (which have no id and expect no response). Used
115
+ for unit testing protocol handling without stdio.
116
+
117
+ #### `prompts/list` handler
118
+
119
+ Calls `client.listByType('skill')` and
120
+ `client.listDocumentsByType('agent')`, then maps
121
+ results to `McpPrompt[]` via
122
+ `createPromptDefinitions(sections)`. Agent prompts
123
+ use the `agent:` name prefix.
124
+
125
+ #### `prompts/get` handler
126
+
127
+ Parses the prompt name to determine whether it is
128
+ a skill (no prefix) or agent (`agent:` prefix),
129
+ then calls `handlePromptGet(name, args, client)` to
130
+ render the template and return `McpPromptMessage[]`.
131
+
132
+ #### `completion/complete` handler
133
+
134
+ Dispatches to `handleCompletion(ref, argument, client)`
135
+ based on the ref type (`ref/prompt` or `ref/resource`)
136
+ and returns a `McpCompletionResult` with matching
137
+ name or URI suggestions.
138
+
139
+ #### `logging/setLevel` handler
140
+
141
+ Stores the requested `McpLogLevel` in `this.logLevel`.
142
+ Subsequent log events emitted at or above this level
143
+ are sent to the client as `notifications/message`
144
+ using the `notify` method.
145
+
146
+ #### `roots/list` handler
147
+
148
+ Returns the `.kbdb` directory as a single root entry:
149
+ `{ uri: "file:///path/to/.kbdb", name: "kbdb database" }`.
150
+
151
+ #### `resources/subscribe` handler
152
+
153
+ Adds the requested URI to `this.subscriptions`. When
154
+ a subscribed resource is updated (section added,
155
+ modified, or deleted), the server calls `notify` with
156
+ method `notifications/resources/updated`.
157
+
158
+ #### `resources/unsubscribe` handler
159
+
160
+ Removes the requested URI from `this.subscriptions`.
161
+
162
+ #### `notify(method, params)`
163
+
164
+ Sends a server-initiated JSON-RPC 2.0 notification
165
+ to the client over stdout. Used for log messages
166
+ (`notifications/message`) and resource update events
167
+ (`notifications/resources/updated`).
168
+
169
+ ```ts
170
+ notify(method: string, params: unknown): void;
171
+ ```
172
+
173
+ ## Testing
174
+
175
+ ```
176
+ src/shared/mcp/
177
+ ├── classes/
178
+ │ └── mcp-server.spec.ts
179
+ ```