@dikolab/kbdb 0.4.3 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/CLA.md +68 -0
  2. package/LICENSE +676 -12
  3. package/LICENSING.md +58 -0
  4. package/README.md +50 -27
  5. package/README.md.bak +320 -0
  6. package/dist/README.md +320 -0
  7. package/dist/{chunk-BJXEVALU.mjs → chunk-QLJ33C74.mjs} +44 -44
  8. package/dist/chunk-QLJ33C74.mjs.map +7 -0
  9. package/dist/cli.cjs +550 -232
  10. package/dist/cli.cjs.map +4 -4
  11. package/dist/cli.d.ts +0 -8
  12. package/dist/cli.mjs +483 -154
  13. package/dist/cli.mjs.map +4 -4
  14. package/dist/kbdb-worker.cjs +36 -5
  15. package/dist/kbdb-worker.cjs.map +3 -3
  16. package/dist/mod.cjs +89 -30
  17. package/dist/mod.cjs.map +4 -4
  18. package/dist/mod.mjs +88 -30
  19. package/dist/mod.mjs.map +4 -4
  20. package/dist/src/cli.d.ts +0 -8
  21. package/dist/src/shared/cli/constants/defaults.constant.d.ts +1 -1
  22. package/dist/src/shared/cli/constants/recfile-command-field-map.constant.d.ts +8 -0
  23. package/dist/src/shared/cli/constants/recfile-field-maps.constant.d.ts +21 -0
  24. package/dist/src/shared/cli/functions/compute-directory-level.function.d.ts +14 -0
  25. package/dist/src/shared/cli/functions/dispatch-command.function.d.ts +2 -28
  26. package/dist/src/shared/cli/functions/format-command-output.function.d.ts +14 -0
  27. package/dist/src/shared/cli/functions/format-db-not-found.function.d.ts +20 -0
  28. package/dist/src/shared/cli/functions/format-output.function.d.ts +1 -0
  29. package/dist/src/shared/cli/functions/format-recfile-output.function.d.ts +11 -0
  30. package/dist/src/shared/cli/functions/render-recfile-value.function.d.ts +11 -0
  31. package/dist/src/shared/cli/functions/resolve-db-dir.function.d.ts +24 -0
  32. package/dist/src/shared/cli/functions/resolve-recfile-key.function.d.ts +9 -0
  33. package/dist/src/shared/cli/functions/run-db-path.function.d.ts +10 -0
  34. package/dist/src/shared/cli/functions/run-export.function.d.ts +8 -4
  35. package/dist/src/shared/cli/functions/run-import.function.d.ts +4 -0
  36. package/dist/src/shared/cli/functions/run-learn.function.d.ts +12 -0
  37. package/dist/src/shared/cli/index.d.ts +4 -1
  38. package/dist/src/shared/cli/typings/cli-options.interface.d.ts +9 -2
  39. package/dist/src/shared/cli/typings/db-resolution.interface.d.ts +9 -0
  40. package/dist/src/shared/cli/typings/recfile-field-map.type.d.ts +10 -0
  41. package/dist/src/shared/version/constants/version.constant.d.ts +1 -1
  42. package/dist/src/shared/wasm-codec/functions/decode-option-u8.function.d.ts +9 -0
  43. package/dist/src/shared/wasm-codec/functions/decode-section-records.function.d.ts +4 -0
  44. package/dist/src/shared/wasm-codec/functions/encode-add-section-params.function.d.ts +2 -45
  45. package/dist/src/shared/wasm-codec/functions/encode-update-section-params.function.d.ts +10 -1
  46. package/dist/src/shared/wasm-codec/index.d.ts +1 -1
  47. package/dist/src/shared/wasm-codec/typings/add-section-input.model.d.ts +6 -0
  48. package/dist/src/shared/wasm-codec/typings/section-record-trailing.model.d.ts +5 -0
  49. package/dist/src/shared/wasm-codec/typings/section-record.model.d.ts +5 -0
  50. package/dist/src/shared/worker-client/functions/build-deno-permissions.function.d.ts +11 -0
  51. package/dist/src/shared/worker-client/functions/read-crash-reason.function.d.ts +9 -0
  52. package/dist/src/shared/worker-client/functions/resolve-spawn-script.function.d.ts +6 -0
  53. package/dist/src/shared/worker-client/functions/spawn-daemon.function.d.ts +1 -1
  54. package/dist/src/shared/worker-client/typings/section.model.d.ts +5 -0
  55. package/dist/src/shared/worker-client/typings/worker-client-options.interface.d.ts +0 -6
  56. package/dist/src/shared/worker-daemon/functions/count-files.function.d.ts +12 -0
  57. package/dist/src/shared/worker-daemon/functions/handle-import.function.d.ts +2 -0
  58. package/dist/src/shared/worker-daemon/functions/handle-read-ops.function.d.ts +8 -0
  59. package/dist/src/shared/worker-daemon/functions/validate-daemon-path.function.d.ts +15 -0
  60. package/dist/src/worker.d.ts +0 -7
  61. package/dist/wasm/default-embedding/kbdb_default_embedding_bg.wasm +0 -0
  62. package/dist/wasm/default-embedding/package.json +1 -1
  63. package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
  64. package/dist/wasm/fs-database/package.json +1 -1
  65. package/dist/wasm/fs-migration/kbdb_fs_migration_bg.wasm +0 -0
  66. package/dist/wasm/fs-migration/package.json +1 -1
  67. package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
  68. package/dist/wasm/kb-worker/package.json +1 -1
  69. package/dist/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
  70. package/dist/wasm/query-parser/package.json +1 -1
  71. package/dist/worker.d.ts +0 -7
  72. package/dist/worker.mjs +37 -6
  73. package/dist/worker.mjs.map +3 -3
  74. package/package.json +13 -12
  75. package/dist/chunk-BJXEVALU.mjs.map +0 -7
  76. package/dist/src/shared/cli/functions/resolve-raw-db-path.function.d.ts +0 -10
  77. package/docs/details/README.md +0 -30
  78. package/docs/details/agent-tooling.md +0 -132
  79. package/docs/details/cli.md +0 -777
  80. package/docs/details/knowledge-base.md +0 -180
  81. package/docs/details/library-api.md +0 -495
  82. package/docs/details/mcp-server.md +0 -482
  83. package/docs/details/search-and-ranking.md +0 -575
  84. package/docs/details/storage.md +0 -531
  85. package/docs/goals/agents.md +0 -751
  86. package/docs/goals/architecture.svg +0 -198
  87. package/docs/goals/auto-capture.md +0 -378
  88. package/docs/goals/benchmarking.md +0 -296
  89. package/docs/goals/cli.md +0 -2654
  90. package/docs/goals/concurrency.md +0 -259
  91. package/docs/goals/content-composer.md +0 -609
  92. package/docs/goals/content-parser.md +0 -279
  93. package/docs/goals/database.md +0 -1679
  94. package/docs/goals/document.md +0 -368
  95. package/docs/goals/hybrid-search.md +0 -465
  96. package/docs/goals/mcp.md +0 -1541
  97. package/docs/goals/overview.md +0 -124
  98. package/docs/goals/query-parser.md +0 -373
  99. package/docs/goals/query-result.md +0 -860
  100. package/docs/goals/semantic-dedup.md +0 -233
  101. package/docs/goals/skills.md +0 -810
  102. package/docs/goals/sync.md +0 -217
  103. package/docs/goals/worker-client.md +0 -1005
  104. package/docs/goals/worker-daemon.md +0 -1547
  105. package/docs/modules/overview.md +0 -319
  106. package/docs/modules/rust/embedding/module.md +0 -91
  107. package/docs/modules/rust/fs-database/functions/document.md +0 -48
  108. package/docs/modules/rust/fs-database/functions/integrity.md +0 -79
  109. package/docs/modules/rust/fs-database/functions/io.md +0 -87
  110. package/docs/modules/rust/fs-database/functions/module.md +0 -22
  111. package/docs/modules/rust/fs-database/functions/query-exec.md +0 -44
  112. package/docs/modules/rust/fs-database/functions/section.md +0 -76
  113. package/docs/modules/rust/fs-database/indexes/btree.md +0 -35
  114. package/docs/modules/rust/fs-database/indexes/corpus.md +0 -61
  115. package/docs/modules/rust/fs-database/indexes/inverted.md +0 -60
  116. package/docs/modules/rust/fs-database/indexes/module.md +0 -64
  117. package/docs/modules/rust/fs-database/indexes/positional.md +0 -39
  118. package/docs/modules/rust/fs-database/indexes/vectors.md +0 -110
  119. package/docs/modules/rust/fs-database/module.md +0 -150
  120. package/docs/modules/rust/fs-database/types/catalog.md +0 -53
  121. package/docs/modules/rust/fs-database/types/module.md +0 -12
  122. package/docs/modules/rust/fs-database/types/section.md +0 -127
  123. package/docs/modules/rust/kb-worker/functions/compose.md +0 -57
  124. package/docs/modules/rust/kb-worker/functions/module.md +0 -20
  125. package/docs/modules/rust/kb-worker/functions/retrieve.md +0 -194
  126. package/docs/modules/rust/kb-worker/functions/search.md +0 -173
  127. package/docs/modules/rust/kb-worker/functions/write.md +0 -172
  128. package/docs/modules/rust/kb-worker/module.md +0 -171
  129. package/docs/modules/rust/kb-worker/types/cache.md +0 -90
  130. package/docs/modules/rust/kb-worker/types/context.md +0 -26
  131. package/docs/modules/rust/kb-worker/types/module.md +0 -16
  132. package/docs/modules/rust/kb-worker/types/status.md +0 -29
  133. package/docs/modules/rust/kb-worker/types/token.md +0 -50
  134. package/docs/modules/rust/overview.md +0 -531
  135. package/docs/modules/rust/query-parser/functions/extract.md +0 -56
  136. package/docs/modules/rust/query-parser/functions/module.md +0 -18
  137. package/docs/modules/rust/query-parser/functions/parse.md +0 -33
  138. package/docs/modules/rust/query-parser/functions/pipeline.md +0 -9
  139. package/docs/modules/rust/query-parser/functions/rank.md +0 -85
  140. package/docs/modules/rust/query-parser/module.md +0 -131
  141. package/docs/modules/rust/query-parser/types/cache.md +0 -39
  142. package/docs/modules/rust/query-parser/types/keyphrase.md +0 -71
  143. package/docs/modules/rust/query-parser/types/module.md +0 -18
  144. package/docs/modules/rust/query-parser/types/token.md +0 -46
  145. package/docs/modules/rust/shared/content-composer/functions.md +0 -114
  146. package/docs/modules/rust/shared/content-composer/module.md +0 -147
  147. package/docs/modules/rust/shared/content-composer/types.md +0 -93
  148. package/docs/modules/rust/shared/content-parser/functions.md +0 -72
  149. package/docs/modules/rust/shared/content-parser/module.md +0 -99
  150. package/docs/modules/rust/shared/content-parser/types.md +0 -71
  151. package/docs/modules/rust/shared/corpus/module.md +0 -24
  152. package/docs/modules/rust/shared/corpus/types.md +0 -141
  153. package/docs/modules/rust/shared/document/module.md +0 -25
  154. package/docs/modules/rust/shared/document/types.md +0 -154
  155. package/docs/modules/rust/shared/encode/module.md +0 -22
  156. package/docs/modules/rust/shared/encode/traits.md +0 -304
  157. package/docs/modules/rust/shared/error/module.md +0 -28
  158. package/docs/modules/rust/shared/error/types.md +0 -302
  159. package/docs/modules/rust/shared/kbid/module.md +0 -24
  160. package/docs/modules/rust/shared/kbid/types.md +0 -147
  161. package/docs/modules/rust/shared/memory/functions.md +0 -209
  162. package/docs/modules/rust/shared/memory/module.md +0 -24
  163. package/docs/modules/rust/shared/module.md +0 -196
  164. package/docs/modules/rust/shared/pipeline/functions.md +0 -141
  165. package/docs/modules/rust/shared/pipeline/module.md +0 -62
  166. package/docs/modules/rust/shared/pipeline/types.md +0 -43
  167. package/docs/modules/rust/shared/query/module.md +0 -27
  168. package/docs/modules/rust/shared/query/types.md +0 -236
  169. package/docs/modules/rust/shared/section/module.md +0 -25
  170. package/docs/modules/rust/shared/section/types.md +0 -294
  171. package/docs/modules/rust/shared/term/module.md +0 -25
  172. package/docs/modules/rust/shared/term/types.md +0 -139
  173. package/docs/modules/typescript/cli.md +0 -131
  174. package/docs/modules/typescript/kbdb-worker.md +0 -150
  175. package/docs/modules/typescript/overview.md +0 -400
  176. package/docs/modules/typescript/shared/auto-capture/module.md +0 -73
  177. package/docs/modules/typescript/shared/cli/constants.md +0 -23
  178. package/docs/modules/typescript/shared/cli/functions.md +0 -809
  179. package/docs/modules/typescript/shared/cli/module.md +0 -138
  180. package/docs/modules/typescript/shared/cli/typings.md +0 -197
  181. package/docs/modules/typescript/shared/embedding/functions.md +0 -200
  182. package/docs/modules/typescript/shared/embedding/module.md +0 -77
  183. package/docs/modules/typescript/shared/embedding/typings.md +0 -124
  184. package/docs/modules/typescript/shared/hash/functions.md +0 -20
  185. package/docs/modules/typescript/shared/hash/module.md +0 -21
  186. package/docs/modules/typescript/shared/log/constants.md +0 -82
  187. package/docs/modules/typescript/shared/log/functions.md +0 -131
  188. package/docs/modules/typescript/shared/log/module.md +0 -153
  189. package/docs/modules/typescript/shared/log/typings.md +0 -82
  190. package/docs/modules/typescript/shared/mcp/classes.md +0 -179
  191. package/docs/modules/typescript/shared/mcp/functions.md +0 -386
  192. package/docs/modules/typescript/shared/mcp/module.md +0 -160
  193. package/docs/modules/typescript/shared/mcp/typings.md +0 -529
  194. package/docs/modules/typescript/shared/module.md +0 -110
  195. package/docs/modules/typescript/shared/platform/functions.md +0 -42
  196. package/docs/modules/typescript/shared/platform/module.md +0 -25
  197. package/docs/modules/typescript/shared/runtime/functions.md +0 -26
  198. package/docs/modules/typescript/shared/runtime/module.md +0 -27
  199. package/docs/modules/typescript/shared/runtime/typings.md +0 -13
  200. package/docs/modules/typescript/shared/version/module.md +0 -27
  201. package/docs/modules/typescript/shared/wasm-codec/functions.md +0 -391
  202. package/docs/modules/typescript/shared/wasm-codec/module.md +0 -98
  203. package/docs/modules/typescript/shared/worker-client/classes.md +0 -264
  204. package/docs/modules/typescript/shared/worker-client/functions.md +0 -175
  205. package/docs/modules/typescript/shared/worker-client/module.md +0 -92
  206. package/docs/modules/typescript/shared/worker-client/typings.md +0 -511
  207. package/docs/modules/typescript/shared/worker-daemon/classes.md +0 -239
  208. package/docs/modules/typescript/shared/worker-daemon/constants.md +0 -37
  209. package/docs/modules/typescript/shared/worker-daemon/functions.md +0 -234
  210. package/docs/modules/typescript/shared/worker-daemon/module.md +0 -118
  211. package/docs/modules/typescript/shared/worker-daemon/typings.md +0 -132
  212. package/docs/overview.md +0 -191
  213. package/docs/release-notes/0.1.0.md +0 -189
  214. package/docs/release-notes/0.1.1.md +0 -46
  215. package/docs/release-notes/0.1.2.md +0 -38
  216. package/docs/release-notes/0.1.3.md +0 -42
  217. package/docs/release-notes/0.2.0.md +0 -147
  218. package/docs/release-notes/0.3.0.md +0 -89
  219. package/docs/release-notes/0.3.1.md +0 -121
  220. package/docs/release-notes/0.3.2.md +0 -64
  221. package/docs/release-notes/0.4.0.md +0 -80
  222. package/docs/release-notes/0.4.1.md +0 -149
  223. package/docs/release-notes/0.4.3.md +0 -60
  224. package/docs/release-notes/README.md +0 -13
@@ -0,0 +1,20 @@
1
+ /** Options controlling the "database not found" diagnostic. */
2
+ interface FormatDbNotFoundOptions {
3
+ /** Explicit `--db` flag value, if provided. */
4
+ dbPath?: string;
5
+ /** When true, omits the cwd traversal line and init hint. */
6
+ skipTraversal?: boolean;
7
+ }
8
+ /**
9
+ * Formats the error message shown when no `.kbdb` database
10
+ * directory can be resolved.
11
+ *
12
+ * When `options.dbPath` is set, an explicit `--db` flag failed
13
+ * to resolve and a single-line message is returned. Otherwise a
14
+ * multi-line diagnostic lists each fallback that was checked so
15
+ * the user can see why resolution failed.
16
+ *
17
+ * @param options - resolution context that produced the failure
18
+ */
19
+ export declare function formatDbNotFound(options: FormatDbNotFoundOptions): string;
20
+ export type { FormatDbNotFoundOptions };
@@ -6,6 +6,7 @@ import type { PagedSearchDisplay } from '../typings/search-display.model.ts';
6
6
  *
7
7
  * - `'json'` -- pretty-printed JSON envelope
8
8
  * - `'text'` -- numbered human-readable list with paging footer
9
+ * - `'rec'` -- recfile field records, one per result
9
10
  * - `'mcp'` -- JSON envelope compatible with MCP protocol
10
11
  *
11
12
  * @param paged - paginated search results to format
@@ -0,0 +1,11 @@
1
+ import type { RecfileFieldMap } from '../typings/recfile-field-map.type.ts';
2
+ /**
3
+ * Formats one or more records as recfile (GNU recutils style)
4
+ * output: `Field: Value` pairs, blank-line separated records,
5
+ * and `+ ` continuation lines for multi-line values.
6
+ *
7
+ * @param data - a single record or an array of records
8
+ * @param fields - ordered field map controlling which
9
+ * properties are rendered and in what order
10
+ */
11
+ export declare function formatRecfileOutput(data: unknown, fields: RecfileFieldMap): string;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Renders a value for recfile output, or returns `null` when the
3
+ * value is absent and the field should be omitted.
4
+ *
5
+ * Arrays render comma-separated; booleans render as `'true'` or
6
+ * `'false'`; `null`, `undefined`, empty strings, and empty
7
+ * arrays are treated as absent.
8
+ *
9
+ * @param value - the value to render
10
+ */
11
+ export declare function renderRecfileValue(value: unknown): string | null;
@@ -0,0 +1,24 @@
1
+ import type { DbResolution } from '../typings/db-resolution.interface.ts';
2
+ /** Options controlling database directory resolution. */
3
+ interface ResolveDbDirOptions {
4
+ /** Explicit `--db` flag value, if provided. */
5
+ dbPath?: string;
6
+ /** When true, skips cwd upward traversal. */
7
+ skipTraversal?: boolean;
8
+ }
9
+ /**
10
+ * Resolves the `.kbdb` database directory using a strict
11
+ * priority chain: explicit `--db` flag, then upward cwd
12
+ * traversal, then the `KBDB_DB_DIR` environment variable.
13
+ *
14
+ * An explicit `--db` flag that fails to resolve returns
15
+ * `null` immediately -- it never falls through to
16
+ * traversal or the environment variable.
17
+ *
18
+ * @param findDb - locates a `.kbdb` directory. Called with
19
+ * a base path to resolve from, or with no argument to
20
+ * trigger upward traversal from the current working
21
+ * directory.
22
+ */
23
+ export declare function resolveDbDir(options: ResolveDbDirOptions, findDb: (basePath?: string) => string | null): DbResolution | null;
24
+ export type { ResolveDbDirOptions };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Resolves a dot-notation property path (e.g.
3
+ * `'cacheStats.contentCount'`) against an object, returning
4
+ * `undefined` if any segment along the path is missing.
5
+ *
6
+ * @param obj - the object to traverse
7
+ * @param key - dot-separated property path
8
+ */
9
+ export declare function resolveRecfileKey(obj: unknown, key: string): unknown;
@@ -0,0 +1,10 @@
1
+ import type { CommandResult } from '../typings/command-result.model.ts';
2
+ import type { CliOptions } from '../typings/cli-options.interface.ts';
3
+ /**
4
+ * Handles the `kbdb db path` subcommand.
5
+ *
6
+ * Prints the resolved `.kbdb` directory path. With
7
+ * `--format json`, outputs a full diagnostic object
8
+ * showing which source provided the resolution.
9
+ */
10
+ export declare function runDbPath(options: Pick<CliOptions, 'dbPath' | 'format'>, findDb: (basePath?: string) => string | null): CommandResult;
@@ -10,8 +10,9 @@ export interface ExportClient {
10
10
  /**
11
11
  * Exports the database to the given directory path.
12
12
  *
13
- * @param params - optional target path; the daemon defaults to
14
- * `./kbdb-export/` when `path` is `undefined`
13
+ * @param params - optional absolute target path; the daemon
14
+ * picks its own default, relative to the database directory,
15
+ * when `path` is `undefined`
15
16
  * @returns export report with the resolved path and file counts
16
17
  */
17
18
  export(params: {
@@ -22,8 +23,11 @@ export interface ExportClient {
22
23
  * Exports the knowledge-base database to a target directory via the
23
24
  * provided client.
24
25
  *
25
- * The target path is taken from `options.args[0]`. When no argument
26
- * is given the daemon resolves its own default (`./kbdb-export/`).
26
+ * The target path is taken from `options.args[0]` and resolved
27
+ * against the current working directory so that the daemon --
28
+ * which may run with a different working directory -- always
29
+ * receives an absolute path. When no argument is given, the daemon
30
+ * picks its own default.
27
31
  *
28
32
  * @param client - export client to delegate to
29
33
  * @param options - parsed CLI options whose first positional
@@ -19,6 +19,10 @@ export interface ImportClient {
19
19
  * Imports an exported knowledge-base from the path specified by
20
20
  * `--from`, delegating to the worker client.
21
21
  *
22
+ * The path is resolved against the current working directory so
23
+ * that the daemon -- which may run with a different working
24
+ * directory -- always receives an absolute path.
25
+ *
22
26
  * @param client - import client to delegate to
23
27
  * @param options - parsed CLI options with `from` path
24
28
  * @returns the import result with section/document counts
@@ -50,6 +50,12 @@ export interface LearnClient {
50
50
  * via source key when `replace` is `true`.
51
51
  */
52
52
  sourcePath?: string;
53
+ /**
54
+ * Hierarchical level (1-6). Explicitly set via `--level`, or
55
+ * auto-detected from directory depth. `undefined` means no
56
+ * level (the engine defaults to 1).
57
+ */
58
+ level?: number;
53
59
  }): Promise<AddSectionResult>;
54
60
  }
55
61
  /** Injectable I/O for testing without real stdin. */
@@ -65,6 +71,12 @@ export interface LearnIO {
65
71
  * silently skipped. The `-` argument reads content from stdin
66
72
  * (consumed only once).
67
73
  *
74
+ * When `options.level` is unset, the level sent for each file is
75
+ * auto-detected from its depth relative to the target argument
76
+ * (root = 1, each subdirectory +1, capped at 6). Stdin input has no
77
+ * directory to derive a level from, so it is sent unset unless
78
+ * `options.level` is explicit.
79
+ *
68
80
  * @param client - learn client to delegate ingestion to
69
81
  * @param options - parsed CLI options whose `args` list targets to
70
82
  * ingest
@@ -1,5 +1,7 @@
1
1
  export { parseArgs } from './functions/parse-args.function.ts';
2
2
  export { formatOutput } from './functions/format-output.function.ts';
3
+ export { formatCommandOutput } from './functions/format-command-output.function.ts';
4
+ export { formatRecfileOutput } from './functions/format-recfile-output.function.ts';
3
5
  export { runSearch } from './functions/run-search.function.ts';
4
6
  export { runRecall } from './functions/run-recall.function.ts';
5
7
  export { runExport } from './functions/run-export.function.ts';
@@ -23,7 +25,8 @@ export { runWorkerRestart } from './functions/run-worker-restart.function.ts';
23
25
  export { HELP_TEXT } from './constants/help-text.constant.ts';
24
26
  export type { CliOptions, OutputFormat, SearchMode, } from './typings/cli-options.interface.ts';
25
27
  export type { LearnResult } from './typings/learn-result.model.ts';
26
- export type { SearchDisplay, PagedSearchDisplay, } from './typings/search-display.model.ts';
28
+ export type { RecfileFieldEntry, RecfileFieldMap, } from './typings/recfile-field-map.type.ts';
29
+ export type { PagedSearchDisplay, SearchDisplay, } from './typings/search-display.model.ts';
27
30
  export type { SearchClient } from './functions/run-search.function.ts';
28
31
  export type { RecallClient } from './functions/run-recall.function.ts';
29
32
  export type { ExportClient } from './functions/run-export.function.ts';
@@ -3,9 +3,11 @@
3
3
  *
4
4
  * - `'json'` -- machine-readable JSON array
5
5
  * - `'text'` -- human-readable numbered list
6
+ * - `'rec'` -- recfile (GNU recutils style) field records;
7
+ * the default format
6
8
  * - `'mcp'` -- JSON envelope for MCP protocol consumers
7
9
  */
8
- export type OutputFormat = 'json' | 'text' | 'mcp';
10
+ export type OutputFormat = 'json' | 'text' | 'rec' | 'mcp';
9
11
  /**
10
12
  * Controls which entity type is returned by a search query.
11
13
  *
@@ -24,12 +26,17 @@ export interface CliOptions {
24
26
  * Defaults to the current working directory when omitted.
25
27
  */
26
28
  dbPath?: string;
27
- /** Output format for results. Defaults to `'json'`. */
29
+ /** Output format for results. Defaults to `'rec'`. */
28
30
  format: OutputFormat;
29
31
  /** When `true`, the user explicitly passed `--format`. */
30
32
  formatExplicit?: boolean;
31
33
  /** Search mode passed to the worker daemon. Defaults to `'sections'`. */
32
34
  mode: SearchMode;
35
+ /**
36
+ * Hierarchical level (1-6). Level 1 is broadest scope,
37
+ * level 6 is narrowest.
38
+ */
39
+ level?: number;
33
40
  /** Search algorithm: `'lexical'`, `'vector'`, or `'hybrid'`. */
34
41
  algo?: string;
35
42
  /** Maximum number of results to return. Defaults to 20. */
@@ -0,0 +1,9 @@
1
+ /** Identifies which source resolved the database directory. */
2
+ export type DbSource = 'flag' | 'traversal' | 'env';
3
+ /** Successful database directory resolution result. */
4
+ export interface DbResolution {
5
+ /** Absolute path to the resolved `.kbdb` directory. */
6
+ path: string;
7
+ /** Which source provided the resolution. */
8
+ source: DbSource;
9
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Mapping entry from an object property path to a recfile
3
+ * field name.
4
+ */
5
+ export type RecfileFieldEntry = readonly [field: string, key: string];
6
+ /**
7
+ * Ordered list of field mappings for a command's recfile
8
+ * output. Fields are rendered in array order.
9
+ */
10
+ export type RecfileFieldMap = readonly RecfileFieldEntry[];
@@ -1,2 +1,2 @@
1
1
  /** Current package version, kept in sync with package.json. */
2
- export declare const VERSION = "0.4.3";
2
+ export declare const VERSION = "0.6.0";
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Decodes an `Option<u8>` from WASM binary output.
3
+ *
4
+ * Wire format: `0x00` = None, `0x01 <byte>` = Some.
5
+ */
6
+ export declare function decodeOptionU8(bytes: Uint8Array, offset: number): {
7
+ value: number | null;
8
+ bytesRead: number;
9
+ };
@@ -63,6 +63,10 @@ export interface SectionRecord {
63
63
  * `null` on first creation or non-superseding additions.
64
64
  */
65
65
  supersedes: string | null;
66
+ /**
67
+ * Hierarchical level (1-6). `null` when not set.
68
+ */
69
+ level?: number | null;
66
70
  }
67
71
  /**
68
72
  * Decodes a list of `SectionRecord` values from WASM binary output.
@@ -1,48 +1,4 @@
1
- /**
2
- * Parameters for adding a new section to the knowledge base.
3
- *
4
- * Maps to the Rust `AddSectionParams` struct encoded for the
5
- * `worker_add_section` WASM export.
6
- */
7
- export interface AddSectionInput {
8
- /** Semantic content category. */
9
- sectionType: 'text' | 'code' | 'image';
10
- /** MIME type; required for `code` and `image` section types. */
11
- mimeType?: string;
12
- /** Raw section content. */
13
- content: string;
14
- /** Optional section heading. */
15
- title?: string | null;
16
- /** Optional description summary. */
17
- description?: string | null;
18
- /** Optional document identifier to attach the section to. */
19
- docid?: string | null;
20
- /**
21
- * Application-level type name for the section (e.g. `'skill'`,
22
- * `'fact'`). `null` means no custom type.
23
- */
24
- typeName?: string | null;
25
- /**
26
- * Absolute path of the source file being learned. `undefined`
27
- * means stdin input or programmatic API call.
28
- */
29
- sourcePath?: string;
30
- /**
31
- * ISO 8601 modified time of the source file. `undefined` means
32
- * no source file exists.
33
- */
34
- sourceMtime?: string;
35
- /**
36
- * User-supplied tags for scoping and filtering. Defaults to
37
- * an empty list when not provided.
38
- */
39
- tags?: string[];
40
- /**
41
- * When `true`, supersede any existing section with the same
42
- * source key. Defaults to `false`.
43
- */
44
- replace?: boolean;
45
- }
1
+ import type { AddSectionInput } from '../typings/add-section-input.model.ts';
46
2
  /**
47
3
  * Encodes `AddSectionInput` as the binary format expected by the
48
4
  * `worker_add_section` WASM export.
@@ -58,5 +14,6 @@ export interface AddSectionInput {
58
14
  * - `sourceMtime`: `u8` flag + optional `String`
59
15
  * - `tags`: `u32` count + each `String`
60
16
  * - `replace`: `u8` (0 or 1)
17
+ * - `level`: `u8` flag + optional `u8` (`Option<u8>`)
61
18
  */
62
19
  export declare function encodeAddSectionParams(params: AddSectionInput): Uint8Array;
@@ -1,2 +1,11 @@
1
- import type { AddSectionInput } from './encode-add-section-params.function.ts';
1
+ import type { AddSectionInput } from '../typings/add-section-input.model.ts';
2
+ /**
3
+ * Encodes parameters for updating an existing section as the
4
+ * binary format expected by the `worker_update_section` WASM
5
+ * export.
6
+ *
7
+ * Wire format: the target section's `kbid` `String`, followed
8
+ * by the same `AddSectionInput` encoding used by
9
+ * {@link encodeAddSectionParams}.
10
+ */
2
11
  export declare function encodeUpdateSectionParams(oldKbid: string, params: AddSectionInput): Uint8Array;
@@ -25,7 +25,7 @@ export { encodeRecallParams } from './functions/encode-recall-params.function.ts
25
25
  export { decodeRecallResult } from './functions/decode-recall-result.function.ts';
26
26
  export { decodeAddSectionResult } from './functions/decode-add-section-result.function.ts';
27
27
  export type { DecodeResult } from './functions/decode-string.function.ts';
28
- export type { AddSectionInput } from './functions/encode-add-section-params.function.ts';
28
+ export type { AddSectionInput } from './typings/add-section-input.model.ts';
29
29
  export type { AddSectionResult, NearDuplicate, } from './functions/decode-add-section-result.function.ts';
30
30
  export type { SectionMatch, PagedSearchResult, } from './functions/decode-scored-results.function.ts';
31
31
  export type { SectionRecord } from './functions/decode-section-records.function.ts';
@@ -42,4 +42,10 @@ export interface AddSectionInput {
42
42
  * source key. Defaults to `false`.
43
43
  */
44
44
  replace?: boolean;
45
+ /**
46
+ * Hierarchical level (1-6). Level 1 is the broadest
47
+ * scope, level 6 the narrowest. `undefined` means
48
+ * no explicit level (defaults to 1 in the engine).
49
+ */
50
+ level?: number;
45
51
  }
@@ -33,6 +33,11 @@ export interface SectionRecordTrailing {
33
33
  * `null` on first creation or non-superseding additions.
34
34
  */
35
35
  supersedes: string | null;
36
+ /**
37
+ * Hierarchical level (1-6). `null` when not set (defaults
38
+ * to 1 in the engine).
39
+ */
40
+ level: number | null;
36
41
  /** Number of bytes consumed from the buffer. */
37
42
  bytesRead: number;
38
43
  }
@@ -63,4 +63,9 @@ export interface SectionRecord {
63
63
  * `null` on first creation or non-superseding additions.
64
64
  */
65
65
  supersedes: string | null;
66
+ /**
67
+ * Hierarchical level (1-6). `null` when not set (defaults
68
+ * to 1 in the engine).
69
+ */
70
+ level?: number | null;
66
71
  }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Deno permission flags for the worker daemon.
3
+ *
4
+ * - read: WASM modules, DB files, config
5
+ * - write: DB files, IPC socket, crash logs, exports
6
+ * - env: KBDB_LOG_LEVEL, HOME, TMPDIR, XDG_RUNTIME_DIR
7
+ * - run: not used by daemon itself (CLI needs it to
8
+ * spawn the daemon, included for symmetry)
9
+ * - sys: os.tmpdir(), os.hostname() via node:os compat
10
+ */
11
+ export declare function buildDenoPermissions(): string[];
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Reads and clears the crash log written by a worker daemon that
3
+ * failed to start, returning a human-readable reason.
4
+ *
5
+ * @param contextId - the 16-char hex context ID for the daemon
6
+ * @returns the recorded crash error, or a fallback message when no
7
+ * usable crash log is found
8
+ */
9
+ export declare function readCrashReason(contextId: string): string;
@@ -0,0 +1,6 @@
1
+ import type { Runtime } from '../../runtime/typings/runtime.ts';
2
+ /**
3
+ * Resolves the worker daemon script path from within
4
+ * the worker-client module.
5
+ */
6
+ export declare function resolveSpawnScript(runtime: Runtime): string;
@@ -6,6 +6,6 @@ import type { Runtime } from '../../runtime/typings/runtime.ts';
6
6
  * daemon should serve
7
7
  * @param runtime - the current JavaScript runtime environment
8
8
  * @param workerScript - absolute path to the worker daemon script,
9
- * resolved at the entry point by `resolveWorkerScript`
9
+ * resolved by `resolveSpawnScript`
10
10
  */
11
11
  export declare function spawnDaemon(contextPath: string, runtime: Runtime, workerScript?: string): void;
@@ -39,4 +39,9 @@ export interface AddSectionParams {
39
39
  * via source key when `replace` is `true`.
40
40
  */
41
41
  readonly sourcePath?: string;
42
+ /**
43
+ * Hierarchical level (1-6). Higher-level sections
44
+ * (lower number) represent broader scope.
45
+ */
46
+ readonly level?: number;
42
47
  }
@@ -21,12 +21,6 @@ export interface WorkerClientOptions {
21
21
  * appear after spawning. Defaults to 10 000 ms.
22
22
  */
23
23
  readonly connectTimeoutMs?: number;
24
- /**
25
- * Absolute path to the worker daemon script. Resolved
26
- * once at the entry point and injected here so that
27
- * `spawnDaemon` needs no runtime-specific path logic.
28
- */
29
- readonly workerScript?: string;
30
24
  /**
31
25
  * Per-request timeout in milliseconds for daemon IPC
32
26
  * calls. When a request exceeds this duration, the
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Counts files with a given extension inside a directory tree,
3
+ * including nested subdirectories.
4
+ *
5
+ * Returns `0` when `dir` does not exist rather than throwing, so
6
+ * callers can size dry-run import reports without first checking
7
+ * directory existence themselves.
8
+ *
9
+ * @param dir - directory to search
10
+ * @param ext - file extension to match, including the leading dot
11
+ */
12
+ export declare function countFiles(dir: string, ext: string): number;
@@ -10,5 +10,7 @@ import type { ImportResult } from '../../worker-client/typings/import-result.mod
10
10
  * @param ctx - handler context with WASM modules
11
11
  * @param params - `sourcePath` and `dryRun` flag
12
12
  * @returns import report with counts and timing
13
+ * @throws {IpcError} when `sourcePath` is missing, relative, or
14
+ * contains a `..` traversal segment
13
15
  */
14
16
  export declare function handleImport(ctx: HandlerContext, params: Record<string, unknown>): Promise<ImportResult>;
@@ -54,5 +54,13 @@ export declare function handleListDocsByType(ctx: HandlerContext, params: Record
54
54
  export declare function handleRecall(ctx: HandlerContext, params: Record<string, unknown>): unknown;
55
55
  /**
56
56
  * Handles the `export` and `exportDb` IPC methods.
57
+ *
58
+ * When `targetPath`/`path` is not supplied, defaults to a
59
+ * `kbdb-export` directory next to the database directory, since
60
+ * the daemon's own working directory is not meaningful to the
61
+ * client that issued the request.
62
+ *
63
+ * @throws {IpcError} when the resolved target path is relative, or
64
+ * contains a `..` traversal segment
57
65
  */
58
66
  export declare function handleExport(ctx: HandlerContext, params: Record<string, unknown>): unknown;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Validates that a daemon-received path is absolute and free of
3
+ * `..` traversal segments.
4
+ *
5
+ * The daemon trusts paths sent by IPC clients to read from and
6
+ * write to the filesystem. Rejecting relative and traversal paths
7
+ * here, at the boundary, prevents a malformed or malicious client
8
+ * from escaping the intended target directory.
9
+ *
10
+ * @param path - path received from an IPC request
11
+ * @returns the same path, unchanged, when valid
12
+ * @throws {IpcError} with code `-32602` when `path` is not
13
+ * absolute, or contains a `..` segment
14
+ */
15
+ export declare function validateDaemonPath(path: string): string;
@@ -1,8 +1 @@
1
- /**
2
- * @module
3
- *
4
- * Worker daemon executable for kbdb. Runs as a detached
5
- * background process that loads WASM modules and serves
6
- * JSON-RPC 2.0 requests over local IPC.
7
- */
8
1
  export {};
@@ -2,7 +2,7 @@
2
2
  "name": "kbdb-default-embedding",
3
3
  "description": "Built-in TF-IDF embedding for kbdb -- compiles to default-embedding.wasm",
4
4
  "version": "0.0.1",
5
- "license": "ISC",
5
+ "license": "AGPL-3.0-only",
6
6
  "files": [
7
7
  "kbdb_default_embedding_bg.wasm",
8
8
  "kbdb_default_embedding.js",
@@ -2,7 +2,7 @@
2
2
  "name": "kbdb-fs-database",
3
3
  "description": "Filesystem storage engine for kbdb -- compiles to fs-database.wasm",
4
4
  "version": "0.0.1",
5
- "license": "ISC",
5
+ "license": "AGPL-3.0-only",
6
6
  "files": [
7
7
  "kbdb_fs_database_bg.wasm",
8
8
  "kbdb_fs_database.js",
@@ -2,7 +2,7 @@
2
2
  "name": "kbdb-fs-migration",
3
3
  "description": "Database migration engine for kbdb -- compiles to fs-migration.wasm",
4
4
  "version": "0.0.1",
5
- "license": "ISC",
5
+ "license": "AGPL-3.0-only",
6
6
  "files": [
7
7
  "kbdb_fs_migration_bg.wasm",
8
8
  "kbdb_fs_migration.js",
@@ -2,7 +2,7 @@
2
2
  "name": "kbdb-worker",
3
3
  "description": "Worker orchestration and cache for kbdb -- compiles to kb-worker.wasm",
4
4
  "version": "0.0.1",
5
- "license": "ISC",
5
+ "license": "AGPL-3.0-only",
6
6
  "files": [
7
7
  "kbdb_worker_bg.wasm",
8
8
  "kbdb_worker.js",
@@ -2,7 +2,7 @@
2
2
  "name": "kbdb-query-parser",
3
3
  "description": "Query processing and tokenization for kbdb -- compiles to query-parser.wasm",
4
4
  "version": "0.0.1",
5
- "license": "ISC",
5
+ "license": "AGPL-3.0-only",
6
6
  "files": [
7
7
  "kbdb_query_parser_bg.wasm",
8
8
  "kbdb_query_parser.js",
package/dist/worker.d.ts CHANGED
@@ -1,8 +1 @@
1
- /**
2
- * @module
3
- *
4
- * Worker daemon executable for kbdb. Runs as a detached
5
- * background process that loads WASM modules and serves
6
- * JSON-RPC 2.0 requests over local IPC.
7
- */
8
1
  export {};