@dikolab/kbdb 0.2.1 → 0.3.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 (120) hide show
  1. package/README.md +59 -24
  2. package/dist/cli.cjs +462 -73
  3. package/dist/cli.cjs.map +4 -4
  4. package/dist/cli.mjs +454 -65
  5. package/dist/cli.mjs.map +4 -4
  6. package/dist/kbdb-worker.cjs +395 -60
  7. package/dist/kbdb-worker.cjs.map +4 -4
  8. package/dist/mod.cjs +18 -1
  9. package/dist/mod.cjs.map +2 -2
  10. package/dist/mod.mjs +18 -1
  11. package/dist/mod.mjs.map +2 -2
  12. package/dist/src/shared/cli/functions/dispatch-command.function.d.ts +3 -1
  13. package/dist/src/shared/cli/functions/install-default-skills.function.d.ts +12 -0
  14. package/dist/src/shared/cli/functions/run-check.function.d.ts +47 -5
  15. package/dist/src/shared/cli/functions/run-export.function.d.ts +34 -0
  16. package/dist/src/shared/cli/functions/run-gc.function.d.ts +6 -0
  17. package/dist/src/shared/cli/functions/run-learn.function.d.ts +35 -6
  18. package/dist/src/shared/cli/functions/run-recall.function.d.ts +45 -0
  19. package/dist/src/shared/cli/functions/run-search.function.d.ts +52 -15
  20. package/dist/src/shared/cli/index.d.ts +4 -0
  21. package/dist/src/shared/cli/typings/cli-options.interface.d.ts +13 -0
  22. package/dist/src/shared/cli/typings/learn-result.model.d.ts +19 -0
  23. package/dist/src/shared/cli/typings/search-display.model.d.ts +18 -0
  24. package/dist/src/shared/mcp/classes/mcp-server.class.d.ts +8 -0
  25. package/dist/src/shared/mcp/typings/mcp-client.interface.d.ts +43 -0
  26. package/dist/src/shared/version/constants/version.constant.d.ts +1 -1
  27. package/dist/src/shared/wasm-codec/functions/decode-add-section-result.function.d.ts +48 -0
  28. package/dist/src/shared/wasm-codec/functions/decode-scored-results.function.d.ts +58 -0
  29. package/dist/src/shared/wasm-codec/functions/decode-section-records.function.d.ts +33 -0
  30. package/dist/src/shared/wasm-codec/functions/encode-add-section-params.function.d.ts +52 -0
  31. package/dist/src/shared/wasm-codec/index.d.ts +2 -0
  32. package/dist/src/shared/worker-client/classes/worker-client.class.d.ts +16 -0
  33. package/dist/src/shared/worker-client/index.d.ts +1 -1
  34. package/dist/src/shared/worker-client/typings/add-section-result.model.d.ts +29 -15
  35. package/dist/src/shared/worker-client/typings/export-result.model.d.ts +14 -0
  36. package/dist/src/shared/worker-client/typings/gc-result.model.d.ts +6 -0
  37. package/dist/src/shared/worker-client/typings/search-result.model.d.ts +12 -0
  38. package/dist/src/shared/worker-client/typings/section.model.d.ts +16 -0
  39. package/dist/src/shared/worker-daemon/classes/worker-daemon.class.d.ts +35 -0
  40. package/dist/wasm/fs-database/kbdb_fs_database.d.ts +22 -1
  41. package/dist/wasm/fs-database/kbdb_fs_database.js +28 -1
  42. package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
  43. package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +1 -0
  44. package/dist/wasm/kb-worker/kbdb_worker.d.ts +48 -1
  45. package/dist/wasm/kb-worker/kbdb_worker.js +60 -1
  46. package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
  47. package/dist/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +2 -0
  48. package/dist/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
  49. package/dist/worker.mjs +396 -60
  50. package/dist/worker.mjs.map +4 -4
  51. package/docs/details/cli.md +102 -15
  52. package/docs/details/library-api.md +55 -6
  53. package/docs/details/mcp-server.md +8 -4
  54. package/docs/details/search-and-ranking.md +63 -5
  55. package/docs/details/storage.md +2 -0
  56. package/docs/goals/cli.md +255 -14
  57. package/docs/goals/database.md +244 -17
  58. package/docs/goals/document.md +1 -1
  59. package/docs/goals/mcp.md +83 -14
  60. package/docs/goals/query-parser.md +98 -4
  61. package/docs/goals/query-result.md +177 -10
  62. package/docs/goals/skills.md +72 -0
  63. package/docs/goals/worker-daemon.md +54 -7
  64. package/docs/modules/rust/fs-database/functions/integrity.md +11 -0
  65. package/docs/modules/rust/fs-database/functions/section.md +23 -6
  66. package/docs/modules/rust/fs-database/module.md +1 -0
  67. package/docs/modules/rust/fs-database/types/section.md +27 -1
  68. package/docs/modules/rust/overview.md +2 -1
  69. package/docs/modules/rust/query-parser/functions/module.md +2 -2
  70. package/docs/modules/rust/query-parser/functions/pipeline.md +44 -6
  71. package/docs/modules/rust/query-parser/module.md +5 -4
  72. package/docs/modules/rust/query-parser/types/keyphrase.md +11 -0
  73. package/docs/modules/rust/query-parser/types/module.md +3 -3
  74. package/docs/modules/typescript/shared/cli/functions.md +68 -3
  75. package/package.json +1 -1
  76. package/src/shared/cli/functions/dispatch-command.function.ts +53 -1
  77. package/src/shared/cli/functions/format-output.function.ts +36 -12
  78. package/src/shared/cli/functions/generate-help.function.ts +56 -1
  79. package/src/shared/cli/functions/install-default-skills.function.ts +296 -0
  80. package/src/shared/cli/functions/parse-args.function.ts +13 -0
  81. package/src/shared/cli/functions/run-check.function.ts +87 -6
  82. package/src/shared/cli/functions/run-export.function.ts +40 -0
  83. package/src/shared/cli/functions/run-gc.function.ts +6 -0
  84. package/src/shared/cli/functions/run-init.function.ts +2 -0
  85. package/src/shared/cli/functions/run-learn.function.ts +68 -16
  86. package/src/shared/cli/functions/run-recall.function.ts +66 -0
  87. package/src/shared/cli/functions/run-search.function.ts +58 -15
  88. package/src/shared/cli/index.ts +4 -0
  89. package/src/shared/cli/typings/cli-options.interface.ts +13 -0
  90. package/src/shared/cli/typings/learn-result.model.ts +16 -0
  91. package/src/shared/cli/typings/search-display.model.ts +18 -0
  92. package/src/shared/mcp/classes/mcp-server.class.ts +30 -1
  93. package/src/shared/mcp/functions/create-tool-definitions.function.ts +46 -5
  94. package/src/shared/mcp/functions/handle-tool-call.function.ts +70 -2
  95. package/src/shared/mcp/typings/mcp-client.interface.ts +45 -0
  96. package/src/shared/version/constants/version.constant.ts +1 -1
  97. package/src/shared/wasm-codec/functions/decode-add-section-result.function.ts +112 -0
  98. package/src/shared/wasm-codec/functions/decode-scored-results.function.ts +86 -0
  99. package/src/shared/wasm-codec/functions/decode-section-records.function.ts +87 -0
  100. package/src/shared/wasm-codec/functions/encode-add-section-params.function.ts +68 -0
  101. package/src/shared/wasm-codec/index.ts +5 -0
  102. package/src/shared/worker-client/classes/worker-client.class.ts +19 -0
  103. package/src/shared/worker-client/index.ts +4 -1
  104. package/src/shared/worker-client/typings/add-section-result.model.ts +30 -15
  105. package/src/shared/worker-client/typings/export-result.model.ts +14 -0
  106. package/src/shared/worker-client/typings/gc-result.model.ts +6 -0
  107. package/src/shared/worker-client/typings/search-result.model.ts +12 -0
  108. package/src/shared/worker-client/typings/section.model.ts +16 -0
  109. package/src/shared/worker-daemon/classes/worker-daemon.class.ts +315 -46
  110. package/src/shared/worker-daemon/functions/create-host-imports.function.ts +19 -4
  111. package/src/shared/worker-daemon/functions/create-ipc-server.function.ts +5 -1
  112. package/src/wasm/fs-database/kbdb_fs_database.d.ts +22 -1
  113. package/src/wasm/fs-database/kbdb_fs_database.js +28 -1
  114. package/src/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
  115. package/src/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +1 -0
  116. package/src/wasm/kb-worker/kbdb_worker.d.ts +48 -1
  117. package/src/wasm/kb-worker/kbdb_worker.js +60 -1
  118. package/src/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
  119. package/src/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +2 -0
  120. package/src/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
@@ -5,7 +5,10 @@ declare namespace wasm_bindgen {
5
5
  /**
6
6
  * Adds a section. `ptr`/`len` point to an encoded `AddSectionParams`.
7
7
  *
8
- * On success: writes encoded kbid string to return slot, returns 0.
8
+ * On success: writes an encoded `AddSectionResult` to the return slot and
9
+ * returns 0. When `params.replace` is true and a section with the same
10
+ * `source_key` exists, the superseded section's index entries are removed
11
+ * and the returned `AddSectionResult.superseded` is set to its kbid.
9
12
  * On error: writes error message to return slot, returns -1.
10
13
  */
11
14
  export function db_add_section(ptr: number, len: number): number;
@@ -42,6 +45,23 @@ declare namespace wasm_bindgen {
42
45
  */
43
46
  export function db_check_version(ptr: number, len: number): number;
44
47
 
48
+ /**
49
+ * Exports the database to a target directory.
50
+ *
51
+ * `ptr`/`len` point to a UTF-8 string containing the target path.
52
+ *
53
+ * Copies `sections/`, `documents/`, and `catalog.toml` to the target.
54
+ * Indexes are not copied because they can be rebuilt from the data.
55
+ *
56
+ * The target path may be absolute or relative. It is an external output
57
+ * destination, not a database-internal path, so no path validation is
58
+ * applied to it.
59
+ *
60
+ * On success a summary string is placed in the return slot:
61
+ * `path={target}\nsections_exported={N}\ndocuments_exported={M}`
62
+ */
63
+ export function db_export(ptr: number, len: number): number;
64
+
45
65
  /**
46
66
  * Runs garbage collection. Returns 0 on success.
47
67
  * On success a summary string is placed in the return slot.
@@ -344,6 +364,10 @@ declare namespace wasm_bindgen {
344
364
 
345
365
  /**
346
366
  * Adds a section. Returns 0 on success, -1 on error.
367
+ *
368
+ * On success the return slot holds the binary-encoded `AddSectionResult`
369
+ * (kbid + indexed_terms_count + elapsed_ms + superseded + warnings +
370
+ * near_duplicates) using the `Encode` trait wire format.
347
371
  */
348
372
  export function worker_add_section(ptr: number, len: number): number;
349
373
 
@@ -365,6 +389,19 @@ declare namespace wasm_bindgen {
365
389
  */
366
390
  export function worker_compose(ptr: number, len: number): number;
367
391
 
392
+ /**
393
+ * Exports the database to a target directory.
394
+ *
395
+ * `ptr`/`len` point to a UTF-8 string containing the target path.
396
+ *
397
+ * Delegates directly to `db_export` in `kbdb-fs-database`. Does not require
398
+ * the worker to have been initialised because the target path is given
399
+ * explicitly by the caller.
400
+ *
401
+ * Returns 0 on success, -1 on error (message in return slot).
402
+ */
403
+ export function worker_export(ptr: number, len: number): number;
404
+
368
405
  /**
369
406
  * Runs garbage collection and invalidates all cache entries.
370
407
  *
@@ -444,6 +481,14 @@ declare namespace wasm_bindgen {
444
481
 
445
482
  /**
446
483
  * Rebuilds all database indexes.
484
+ *
485
+ * First clears the existing inverted, positional, and reference indexes via
486
+ * `db_rebuild_index`. Then re-tokenizes every stored section and re-populates
487
+ * the indexes via `rebuild_all_section_indexes`.
488
+ *
489
+ * On success the return slot holds the number of reindexed sections as a
490
+ * little-endian `u32`, and 0 is returned. On error -1 is returned and an
491
+ * error message is in the return slot.
447
492
  */
448
493
  export function worker_rebuild_indexes(): number;
449
494
 
@@ -525,6 +570,7 @@ declare interface InitOutput {
525
570
  readonly worker_add_section: (a: number, b: number) => number;
526
571
  readonly worker_check_integrity: () => number;
527
572
  readonly worker_compose: (a: number, b: number) => number;
573
+ readonly worker_export: (a: number, b: number) => number;
528
574
  readonly worker_garbage_collect: () => number;
529
575
  readonly worker_get_result: (a: number) => number;
530
576
  readonly worker_group_sections: (a: number, b: number) => number;
@@ -565,6 +611,7 @@ declare interface InitOutput {
565
611
  readonly db_add_to_index: (a: number, b: number) => number;
566
612
  readonly db_check_integrity: (a: number, b: number) => number;
567
613
  readonly db_check_version: (a: number, b: number) => number;
614
+ readonly db_export: (a: number, b: number) => number;
568
615
  readonly db_gc: (a: number, b: number) => number;
569
616
  readonly db_get_back_refs: (a: number, b: number) => number;
570
617
  readonly db_get_forward_refs: (a: number, b: number) => number;
@@ -7,7 +7,10 @@ let wasm_bindgen = (function(exports) {
7
7
  /**
8
8
  * Adds a section. `ptr`/`len` point to an encoded `AddSectionParams`.
9
9
  *
10
- * On success: writes encoded kbid string to return slot, returns 0.
10
+ * On success: writes an encoded `AddSectionResult` to the return slot and
11
+ * returns 0. When `params.replace` is true and a section with the same
12
+ * `source_key` exists, the superseded section's index entries are removed
13
+ * and the returned `AddSectionResult.superseded` is set to its kbid.
11
14
  * On error: writes error message to return slot, returns -1.
12
15
  * @param {number} ptr
13
16
  * @param {number} len
@@ -72,6 +75,30 @@ let wasm_bindgen = (function(exports) {
72
75
  }
73
76
  exports.db_check_version = db_check_version;
74
77
 
78
+ /**
79
+ * Exports the database to a target directory.
80
+ *
81
+ * `ptr`/`len` point to a UTF-8 string containing the target path.
82
+ *
83
+ * Copies `sections/`, `documents/`, and `catalog.toml` to the target.
84
+ * Indexes are not copied because they can be rebuilt from the data.
85
+ *
86
+ * The target path may be absolute or relative. It is an external output
87
+ * destination, not a database-internal path, so no path validation is
88
+ * applied to it.
89
+ *
90
+ * On success a summary string is placed in the return slot:
91
+ * `path={target}\nsections_exported={N}\ndocuments_exported={M}`
92
+ * @param {number} ptr
93
+ * @param {number} len
94
+ * @returns {number}
95
+ */
96
+ function db_export(ptr, len) {
97
+ const ret = wasm.db_export(ptr, len);
98
+ return ret;
99
+ }
100
+ exports.db_export = db_export;
101
+
75
102
  /**
76
103
  * Runs garbage collection. Returns 0 on success.
77
104
  * On success a summary string is placed in the return slot.
@@ -644,6 +671,10 @@ let wasm_bindgen = (function(exports) {
644
671
 
645
672
  /**
646
673
  * Adds a section. Returns 0 on success, -1 on error.
674
+ *
675
+ * On success the return slot holds the binary-encoded `AddSectionResult`
676
+ * (kbid + indexed_terms_count + elapsed_ms + superseded + warnings +
677
+ * near_duplicates) using the `Encode` trait wire format.
647
678
  * @param {number} ptr
648
679
  * @param {number} len
649
680
  * @returns {number}
@@ -684,6 +715,26 @@ let wasm_bindgen = (function(exports) {
684
715
  }
685
716
  exports.worker_compose = worker_compose;
686
717
 
718
+ /**
719
+ * Exports the database to a target directory.
720
+ *
721
+ * `ptr`/`len` point to a UTF-8 string containing the target path.
722
+ *
723
+ * Delegates directly to `db_export` in `kbdb-fs-database`. Does not require
724
+ * the worker to have been initialised because the target path is given
725
+ * explicitly by the caller.
726
+ *
727
+ * Returns 0 on success, -1 on error (message in return slot).
728
+ * @param {number} ptr
729
+ * @param {number} len
730
+ * @returns {number}
731
+ */
732
+ function worker_export(ptr, len) {
733
+ const ret = wasm.worker_export(ptr, len);
734
+ return ret;
735
+ }
736
+ exports.worker_export = worker_export;
737
+
687
738
  /**
688
739
  * Runs garbage collection and invalidates all cache entries.
689
740
  *
@@ -835,6 +886,14 @@ let wasm_bindgen = (function(exports) {
835
886
 
836
887
  /**
837
888
  * Rebuilds all database indexes.
889
+ *
890
+ * First clears the existing inverted, positional, and reference indexes via
891
+ * `db_rebuild_index`. Then re-tokenizes every stored section and re-populates
892
+ * the indexes via `rebuild_all_section_indexes`.
893
+ *
894
+ * On success the return slot holds the number of reindexed sections as a
895
+ * little-endian `u32`, and 0 is returned. On error -1 is returned and an
896
+ * error message is in the return slot.
838
897
  * @returns {number}
839
898
  */
840
899
  function worker_rebuild_indexes() {
@@ -8,6 +8,7 @@ export const set_return: (a: number, b: number) => void;
8
8
  export const worker_add_section: (a: number, b: number) => number;
9
9
  export const worker_check_integrity: () => number;
10
10
  export const worker_compose: (a: number, b: number) => number;
11
+ export const worker_export: (a: number, b: number) => number;
11
12
  export const worker_garbage_collect: () => number;
12
13
  export const worker_get_result: (a: number) => number;
13
14
  export const worker_group_sections: (a: number, b: number) => number;
@@ -48,6 +49,7 @@ export const db_add_section: (a: number, b: number) => number;
48
49
  export const db_add_to_index: (a: number, b: number) => number;
49
50
  export const db_check_integrity: (a: number, b: number) => number;
50
51
  export const db_check_version: (a: number, b: number) => number;
52
+ export const db_export: (a: number, b: number) => number;
51
53
  export const db_gc: (a: number, b: number) => number;
52
54
  export const db_get_back_refs: (a: number, b: number) => number;
53
55
  export const db_get_forward_refs: (a: number, b: number) => number;