@dikolab/kbdb 0.5.0 → 0.6.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 (224) hide show
  1. package/CLA.md +68 -0
  2. package/LICENSE +676 -12
  3. package/LICENSING.md +58 -0
  4. package/README.md +50 -25
  5. package/README.md.bak +322 -0
  6. package/dist/README.md +322 -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 +11 -10
  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,110 +0,0 @@
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
- └── log/ ← Structured logging
38
- ```
39
-
40
- ## Modules
41
-
42
- ### Application Modules
43
-
44
- - **[cli/](cli/module.md)** -- CLI argument parsing,
45
- command handlers (`learn`, `unlearn`, `search`),
46
- and output formatting.
47
- - **[mcp/](mcp/module.md)** -- MCP server, tool
48
- handlers (`search`, `learn`, `unlearn`, `retrieve`,
49
- `status`), and resource handlers.
50
- - **[worker-client/](worker-client/module.md)** --
51
- IPC client. Discovers or spawns the daemon, provides
52
- typed async API for all operations.
53
- - **[worker-daemon/](worker-daemon/module.md)** --
54
- Daemon process. Loads WASM modules, listens on IPC,
55
- serves JSON-RPC 2.0 requests.
56
-
57
- ### Utility Modules
58
-
59
- - **[version/](version/module.md)** -- Package version
60
- constant.
61
- - **[runtime/](runtime/module.md)** -- Deno / Node.js
62
- runtime detection and argument access.
63
- - **[platform/](platform/module.md)** -- Cross-platform
64
- helpers (tmpdir, PID checks, IPC socket paths).
65
- - **[hash/](hash/module.md)** -- SHA-256 hashing via
66
- Web Crypto API.
67
- - **[log/](log/module.md)** -- Structured logging with
68
- configurable levels, ANSI colors, and per-level
69
- Unicode icons.
70
-
71
- ## Dependency Direction
72
-
73
- ```
74
- src/cli.ts
75
- ├── shared/cli/
76
- │ └── shared/worker-client/
77
- └── shared/mcp/
78
- └── shared/worker-client/
79
-
80
- src/worker.ts
81
- └── shared/worker-daemon/
82
-
83
- shared/worker-client/
84
- ├── shared/platform/
85
- ├── shared/hash/
86
- └── shared/log/
87
-
88
- shared/worker-daemon/
89
- ├── shared/platform/
90
- └── shared/log/
91
-
92
- shared/cli/
93
- └── shared/log/
94
-
95
- shared/mcp/
96
- └── shared/log/
97
-
98
- mod.ts
99
- └── shared/version/
100
- ```
101
-
102
- Utility modules (`version`, `runtime`, `platform`,
103
- `hash`, `log`) have no dependencies on application
104
- modules. Application modules may depend on utility
105
- modules but not on each other, except through the
106
- worker-client which both `cli` and `mcp` share.
107
- `shared/log/` is a standalone utility with no
108
- dependencies; `cli/`, `mcp/`, `worker-daemon/`, and
109
- `worker-client/` all depend on it for structured
110
- output.
@@ -1,42 +0,0 @@
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}`
@@ -1,25 +0,0 @@
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`
@@ -1,26 +0,0 @@
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)`
@@ -1,27 +0,0 @@
1
- # runtime -- Runtime Detection
2
-
3
- **Source:** `src/shared/runtime/`
4
-
5
- ## Responsibility
6
-
7
- Detect whether the process is running on Deno or
8
- Node.js, and provide cross-runtime access to CLI
9
- arguments.
10
-
11
- ## Directory Layout
12
-
13
- ```
14
- src/shared/runtime/
15
- index.ts
16
- functions/
17
- detect-runtime.function.ts
18
- get-args.function.ts
19
- typings/
20
- runtime.type.ts
21
- ```
22
-
23
- ## Exports
24
-
25
- - [Functions](functions.md) -- `detectRuntime`,
26
- `getArgs`
27
- - [Typings](typings.md) -- `Runtime`
@@ -1,13 +0,0 @@
1
- # runtime/typings -- Runtime Type Definitions
2
-
3
- **Source:** `src/shared/runtime/typings/`
4
-
5
- ## Runtime
6
-
7
- ```ts
8
- type Runtime = 'deno' | 'node';
9
- ```
10
-
11
- Discriminant for the two supported JavaScript runtimes.
12
-
13
- No spec -- typings are compile-time only.
@@ -1,27 +0,0 @@
1
- # version -- Package Version
2
-
3
- **Source:** `src/shared/version/`
4
-
5
- ## Responsibility
6
-
7
- Exposes the current package version as a constant.
8
- Exported from the library API (`mod.ts`). Currently the
9
- only public export.
10
-
11
- ## Exports
12
-
13
- - `version` -- `'0.0.1'`
14
-
15
- ## Directory Layout
16
-
17
- ```
18
- src/shared/version/
19
- index.ts
20
- constants/
21
- version.constant.ts
22
- ```
23
-
24
- ## Spec
25
-
26
- - `version.spec.ts` -- Validates the version string
27
- format.
@@ -1,391 +0,0 @@
1
- # wasm-codec/functions -- Codec Functions
2
-
3
- *One encode or decode function per file. Encoders
4
- build `Uint8Array` buffers; decoders parse them into
5
- typed TypeScript values.*
6
-
7
- ## Source
8
-
9
- `src/shared/wasm-codec/functions/`
10
-
11
- ---
12
-
13
- ## Encoder Functions
14
-
15
- ### `encodeString`
16
-
17
- **File:** `encode-string.function.ts`
18
-
19
- Encodes a UTF-8 string as a little-endian `u32`
20
- length prefix followed by the UTF-8 bytes.
21
-
22
- ```ts
23
- function encodeString(value: string): Uint8Array;
24
- ```
25
-
26
- ### `encodeU32`
27
-
28
- **File:** `encode-u32.function.ts`
29
-
30
- Encodes an unsigned 32-bit integer as 4 bytes,
31
- little-endian.
32
-
33
- ```ts
34
- function encodeU32(value: number): Uint8Array;
35
- ```
36
-
37
- ### `encodeOptionString`
38
-
39
- **File:** `encode-option-string.function.ts`
40
-
41
- Encodes an optional string. Writes `0x00` for `null`
42
- or `undefined`; writes `0x01` followed by the encoded
43
- string for a present value.
44
-
45
- ```ts
46
- function encodeOptionString(
47
- value: string | null | undefined,
48
- ): Uint8Array;
49
- ```
50
-
51
- ### `encodeSectionType`
52
-
53
- **File:** `encode-section-type.function.ts`
54
-
55
- Encodes a section type discriminant. Writes `0x00`
56
- for `text` (no MIME), `0x01` + MIME for `code`, or
57
- `0x02` + MIME for `image`.
58
-
59
- ```ts
60
- function encodeSectionType(
61
- kind: 'text' | 'code' | 'image',
62
- mimeType?: string,
63
- ): Uint8Array;
64
- ```
65
-
66
- ### `encodeAddSectionParams`
67
-
68
- **File:** `encode-add-section-params.function.ts`
69
-
70
- Encodes parameters for the `worker_add_section` WASM
71
- export: section type, content, optional title,
72
- optional description, and optional docid, in that
73
- order.
74
-
75
- ```ts
76
- function encodeAddSectionParams(
77
- params: AddSectionInput,
78
- ): Uint8Array;
79
- ```
80
-
81
- ```ts
82
- interface AddSectionInput {
83
- sectionType: 'text' | 'code' | 'image';
84
- mimeType?: string;
85
- content: string;
86
- title?: string | null;
87
- description?: string | null;
88
- docid?: string | null;
89
- }
90
- ```
91
-
92
- ### `encodeUpdateSectionParams`
93
-
94
- **File:** `encode-update-section-params.function.ts`
95
-
96
- Encodes parameters for the `worker_update_section`
97
- WASM export: the old KB ID as an encoded string
98
- followed by the full `AddSectionInput` encoding.
99
-
100
- ```ts
101
- function encodeUpdateSectionParams(
102
- oldKbid: string,
103
- params: AddSectionInput,
104
- ): Uint8Array;
105
- ```
106
-
107
- ### `encodeKbidList`
108
-
109
- **File:** `encode-kbid-list.function.ts`
110
-
111
- Encodes a list of KB IDs as a `u32` count followed
112
- by each ID encoded as a length-prefixed string.
113
- Returns an empty `Uint8Array` for an empty list.
114
-
115
- ```ts
116
- function encodeKbidList(kbids: string[]): Uint8Array;
117
- ```
118
-
119
- ### `encodeGroupParams`
120
-
121
- **File:** `encode-group-params.function.ts`
122
-
123
- Encodes parameters for the `worker_group_sections`
124
- WASM export: the document title followed by a
125
- `encodeKbidList` encoding of the section IDs.
126
-
127
- ```ts
128
- function encodeGroupParams(
129
- title: string,
130
- kbids: string[],
131
- ): Uint8Array;
132
- ```
133
-
134
- ### `encodeIdentifierList`
135
-
136
- **File:** `encode-identifier-list.function.ts`
137
-
138
- Encodes a list of arbitrary string identifiers (kbid
139
- or docid) as a `u32` count followed by each ID as a
140
- length-prefixed string. Returns an empty `Uint8Array`
141
- for an empty list.
142
-
143
- ```ts
144
- function encodeIdentifierList(
145
- ids: string[],
146
- ): Uint8Array;
147
- ```
148
-
149
- ### `encodeSearchParams`
150
-
151
- **File:** `encode-search-params.function.ts`
152
-
153
- Encodes search parameters as a newline-delimited
154
- UTF-8 string: `query\nmode\nlimit`.
155
-
156
- ```ts
157
- function encodeSearchParams(
158
- query: string,
159
- mode?: string,
160
- limit?: number,
161
- ): Uint8Array;
162
- ```
163
-
164
- `mode` defaults to `'and'`; `limit` defaults to `20`.
165
-
166
- ---
167
-
168
- ## Decoder Functions
169
-
170
- ### `decodeString`
171
-
172
- **File:** `decode-string.function.ts`
173
-
174
- Reads a length-prefixed UTF-8 string from a byte
175
- buffer at the given offset.
176
-
177
- ```ts
178
- function decodeString(
179
- bytes: Uint8Array,
180
- offset: number,
181
- ): DecodeResult<string>;
182
-
183
- interface DecodeResult<T> {
184
- value: T;
185
- bytesRead: number;
186
- }
187
- ```
188
-
189
- ### `decodeU32`
190
-
191
- **File:** `decode-u32.function.ts`
192
-
193
- Reads a little-endian `u32` from a byte buffer at the
194
- given offset.
195
-
196
- ```ts
197
- function decodeU32(
198
- bytes: Uint8Array,
199
- offset: number,
200
- ): DecodeResult<number>;
201
- ```
202
-
203
- ### `decodeF32`
204
-
205
- **File:** `decode-f32.function.ts`
206
-
207
- Reads a little-endian IEEE 754 `f32` from a byte
208
- buffer at the given offset.
209
-
210
- ```ts
211
- function decodeF32(
212
- bytes: Uint8Array,
213
- offset: number,
214
- ): DecodeResult<number>;
215
- ```
216
-
217
- ### `decodeU64`
218
-
219
- **File:** `decode-u64.function.ts`
220
-
221
- Reads a little-endian `u64` from a byte buffer at the
222
- given offset. Returns a `bigint`.
223
-
224
- ```ts
225
- function decodeU64(
226
- bytes: Uint8Array,
227
- offset: number,
228
- ): DecodeResult<bigint>;
229
- ```
230
-
231
- ### `decodeScoredResults`
232
-
233
- **File:** `decode-scored-results.function.ts`
234
-
235
- Decodes the binary response from `worker_search`
236
- into an array of scored results.
237
-
238
- ```ts
239
- function decodeScoredResults(
240
- bytes: Uint8Array,
241
- ): ScoredResult[];
242
-
243
- interface ScoredResult {
244
- kbid: string;
245
- score: number;
246
- matches: TermMatch[];
247
- }
248
-
249
- interface TermMatch {
250
- term: string;
251
- frequency: number;
252
- }
253
- ```
254
-
255
- Wire format: `u32` count, then for each result:
256
- kbid (length-prefixed string), score (`f32`), match
257
- count (`u32`), then for each match: term (string),
258
- frequency (`f32`).
259
-
260
- ### `decodeSectionRecords`
261
-
262
- **File:** `decode-section-records.function.ts`
263
-
264
- Decodes the binary response from `worker_read_sections`
265
- into an array of section records.
266
-
267
- ```ts
268
- function decodeSectionRecords(
269
- bytes: Uint8Array,
270
- ): SectionRecord[];
271
-
272
- interface SectionRecord {
273
- kbid: string;
274
- docid: string | null;
275
- sectionType: string;
276
- mimeType?: string;
277
- title: string | null;
278
- description: string | null;
279
- content: string;
280
- size: number;
281
- createdAt: bigint;
282
- checksum: string;
283
- tokenCount: number;
284
- headingTokenCount: number;
285
- bodyTokenCount: number;
286
- codeTokenCount: number;
287
- }
288
- ```
289
-
290
- ### `decodeDocumentManifest`
291
-
292
- **File:** `decode-document-manifest.function.ts`
293
-
294
- Decodes the binary response from `worker_retrieve_doc`
295
- into a document manifest.
296
-
297
- ```ts
298
- function decodeDocumentManifest(
299
- bytes: Uint8Array,
300
- ): DocumentManifest;
301
-
302
- interface DocumentManifest {
303
- docid: string;
304
- title: string;
305
- createdAt: bigint;
306
- sections: DocumentSection[];
307
- }
308
-
309
- interface DocumentSection {
310
- kbid: string;
311
- position: number;
312
- }
313
- ```
314
-
315
- ### `decodeComposeOutput`
316
-
317
- **File:** `decode-compose-output.function.ts`
318
-
319
- Decodes the binary response from `worker_compose`
320
- into a Markdown string and character count.
321
-
322
- ```ts
323
- function decodeComposeOutput(
324
- bytes: Uint8Array,
325
- ): ComposeOutput;
326
-
327
- interface ComposeOutput {
328
- markdown: string;
329
- totalChars: bigint;
330
- }
331
- ```
332
-
333
- Wire format: length-prefixed Markdown string followed
334
- by a `u64` character count.
335
-
336
- ### `decodeKeyValueText`
337
-
338
- **File:** `decode-key-value-text.function.ts`
339
-
340
- Parses a newline-delimited `key=value` text response
341
- into a `Record<string, string>`. Used to decode
342
- responses from `worker_status`, `worker_check_integrity`,
343
- and `worker_garbage_collect`.
344
-
345
- ```ts
346
- function decodeKeyValueText(
347
- text: string,
348
- ): Record<string, string>;
349
- ```
350
-
351
- Lines without a `=` separator are silently skipped.
352
-
353
- ### `decodeRemoveFlag`
354
-
355
- **File:** `decode-remove-flag.function.ts`
356
-
357
- Decodes a single-byte boolean response from
358
- `worker_remove_section`. Returns `true` when the
359
- first byte is `0x01`.
360
-
361
- ```ts
362
- function decodeRemoveFlag(bytes: Uint8Array): boolean;
363
- ```
364
-
365
- ## Testing
366
-
367
- Each function has a `.spec.ts` at the module root:
368
-
369
- ```
370
- src/shared/wasm-codec/
371
- ├── encode-string.spec.ts
372
- ├── encode-u32.spec.ts
373
- ├── encode-option-string.spec.ts
374
- ├── encode-section-type.spec.ts
375
- ├── encode-add-section-params.spec.ts
376
- ├── encode-update-section-params.spec.ts
377
- ├── encode-kbid-list.spec.ts
378
- ├── encode-group-params.spec.ts
379
- ├── encode-identifier-list.spec.ts
380
- ├── encode-search-params.spec.ts
381
- ├── decode-string.spec.ts
382
- ├── decode-u32.spec.ts
383
- ├── decode-f32.spec.ts
384
- ├── decode-u64.spec.ts
385
- ├── decode-scored-results.spec.ts
386
- ├── decode-section-records.spec.ts
387
- ├── decode-document-manifest.spec.ts
388
- ├── decode-compose-output.spec.ts
389
- ├── decode-key-value-text.spec.ts
390
- └── decode-remove-flag.spec.ts
391
- ```