@dikolab/kbdb 0.5.0 → 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 +47 -24
  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/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 +10 -9
  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,93 +0,0 @@
1
- # content-composer -- Types
2
-
3
- ## `ComposeRequest`
4
-
5
- Input to the composition engine. Contains all
6
- pre-fetched data needed to produce the composed
7
- Markdown -- no I/O occurs during composition.
8
-
9
- ```rust
10
- pub struct ComposeRequest {
11
- pub main_ids: Vec<ResolvedId>,
12
- pub sections: HashMap<String, SectionData>,
13
- pub documents: HashMap<String, DocumentData>,
14
- }
15
- ```
16
-
17
- | Field | Description |
18
- |-------------|------------------------------------------|
19
- | `main_ids` | Ordered list of resolved identifiers forming the primary content |
20
- | `sections` | All pre-fetched sections, keyed by kbid |
21
- | `documents` | All pre-fetched documents, keyed by docid|
22
-
23
- ## `ResolvedId`
24
-
25
- Discriminated identifier from the resolution phase.
26
-
27
- ```rust
28
- pub enum ResolvedId {
29
- Section(String),
30
- Document(String),
31
- }
32
- ```
33
-
34
- ## `SectionData`
35
-
36
- Pre-fetched section content with extracted content
37
- markers.
38
-
39
- ```rust
40
- pub struct SectionData {
41
- pub kbid: String,
42
- pub section_type: SectionType,
43
- pub content: String,
44
- pub markers: Vec<ExtractedContentMarker>,
45
- }
46
- ```
47
-
48
- | Field | Description |
49
- |----------------|---------------------------------------|
50
- | `kbid` | Content-addressed section identifier |
51
- | `section_type` | MIME-based type (`SectionType` from `section` module) |
52
- | `content` | Raw section body text |
53
- | `markers` | Pre-extracted content markers from `extract_content_markers()` |
54
-
55
- ## `DocumentData`
56
-
57
- Pre-fetched document manifest.
58
-
59
- ```rust
60
- pub struct DocumentData {
61
- pub docid: String,
62
- pub title: String,
63
- pub section_kbids: Vec<String>,
64
- }
65
- ```
66
-
67
- | Field | Description |
68
- |----------------|---------------------------------------|
69
- | `docid` | Document identifier |
70
- | `title` | Document title for heading rendering |
71
- | `section_kbids`| Ordered section kbids in this document|
72
-
73
- ## `ComposeResult`
74
-
75
- Output of the composition engine.
76
-
77
- ```rust
78
- pub struct ComposeResult {
79
- pub markdown: String,
80
- pub total_chars: usize,
81
- }
82
- ```
83
-
84
- | Field | Description |
85
- |--------------|-----------------------------------------|
86
- | `markdown` | Composed Markdown string |
87
- | `total_chars` | Character count of `markdown` (not byte count) |
88
-
89
- ## `RenderedSection`
90
-
91
- Internal rendering type used by `render.rs` during
92
- Phase 2 composition. Tracks per-section rendering
93
- state.
@@ -1,72 +0,0 @@
1
- # content-parser -- Functions
2
-
3
- ## `extract_content_markers`
4
-
5
- ```rust
6
- pub fn extract_content_markers(text: &str)
7
- -> Vec<ExtractedContentMarker>
8
- ```
9
-
10
- Scans the input text and returns all recognized
11
- content markers in document order (lowest to highest
12
- byte offset). Does not modify the input. Returns an
13
- empty `Vec` if no markers are found.
14
-
15
- The function performs a single left-to-right scan.
16
- It is non-recursive -- it does not follow references
17
- or read other sections.
18
-
19
- ### Tests
20
-
21
- Unit tests in
22
- `engine/crates/shared/src/content-parser/extract.rs`:
23
-
24
- - Empty input returns empty vec.
25
- - Single `$(image: {kbid})` returns one marker with
26
- correct type, value, offset, and length.
27
- - All six content marker types recognized
28
- individually.
29
- - Multiple markers in sequence, returned in document
30
- order.
31
- - Adjacent markers with no space between them.
32
- - Unrecognized `$(formula: ...)` produces no marker.
33
- - Unclosed marker (no `)`) produces no marker.
34
- - Unicode text surrounding markers -- offsets are
35
- byte-accurate.
36
- - Marker-only input (no surrounding text).
37
- - Whitespace variations inside markers (e.g. extra
38
- spaces after colon).
39
-
40
- ## `strip_content_markers`
41
-
42
- ```rust
43
- pub fn strip_content_markers(text: &str) -> String
44
- ```
45
-
46
- Returns a new string with all recognized content
47
- markers removed. Whitespace left by marker removal
48
- is preserved; the caller should normalise whitespace
49
- if needed.
50
-
51
- This function replaces the earlier implementation in
52
- `shared/src/pipeline/markers.rs`, which only
53
- recognized `$(image:)` and `$(code:)`. The shared
54
- version recognizes all six content marker types.
55
-
56
- Both functions share the same scanning logic
57
- internally. `strip_content_markers` is equivalent to
58
- removing every character range identified by
59
- `extract_content_markers`.
60
-
61
- ### Tests
62
-
63
- Unit tests in
64
- `engine/crates/shared/src/content-parser/strip.rs`:
65
-
66
- - Empty input returns empty string.
67
- - Plain text with no markers returns unchanged.
68
- - All six content marker types stripped.
69
- - Multiple markers stripped in one pass.
70
- - Unrecognized markers left untouched.
71
- - Unclosed markers left untouched.
72
- - Unicode text preserved around stripped markers.
@@ -1,99 +0,0 @@
1
- # content-parser -- Content Marker Extraction
2
-
3
- *Format-agnostic parser that extracts `$(type: value)`
4
- embedding and link markers from section content,
5
- producing structured reference lists for result set
6
- resolution.*
7
-
8
- ## Module
9
-
10
- | Field | Value |
11
- |-------------|-------------------------------------------|
12
- | Rust module | `content_parser` |
13
- | Source path | `engine/crates/shared/src/content-parser/`|
14
- | Crate | `kbdb-shared` (rlib) |
15
-
16
- The module is declared in `lib.rs` with a path
17
- attribute because the source directory uses a
18
- hyphenated name:
19
-
20
- ```rust
21
- #[path = "content-parser/mod.rs"]
22
- pub mod content_parser;
23
- ```
24
-
25
- ## Directory Layout
26
-
27
- ```
28
- engine/crates/shared/src/content-parser/
29
- mod.rs -- re-exports
30
- types.rs -- ContentMarkerType,
31
- ExtractedContentMarker
32
- extract.rs -- extract_content_markers()
33
- strip.rs -- strip_content_markers()
34
- ```
35
-
36
- ## Purpose
37
-
38
- The content parser scans any UTF-8 text for
39
- `$(type: value)` markers and returns a structured
40
- list of extracted references. It is format-agnostic
41
- -- the marker syntax is independent of the
42
- surrounding text format (markdown, source code,
43
- plain text).
44
-
45
- The parser performs a **single left-to-right scan**
46
- of the input. It is **non-recursive** -- it does not
47
- follow references or read other sections. Recursive
48
- reference resolution is the caller's responsibility
49
- (typically `kb-worker`).
50
-
51
- ## Integration Points
52
-
53
- ### Query Parser
54
-
55
- The `query-parser` crate imports
56
- `strip_content_markers()` from
57
- `kbdb_shared::content_parser` for tokenization
58
- Pipeline Stage 1. This replaces the crate's earlier
59
- local regex that only recognized `$(image:)` and
60
- `$(code:)`. The shared version recognizes all six
61
- content marker types.
62
-
63
- ### Filesystem Database
64
-
65
- The `fs-database` crate imports
66
- `extract_content_markers()` from
67
- `kbdb_shared::content_parser` for integrity
68
- checking. The integrity checker extracts all markers
69
- and verifies that each referenced kb-id or doc-id
70
- exists and has the expected type.
71
-
72
- ### Worker Orchestration
73
-
74
- The `kb-worker` crate imports
75
- `extract_content_markers()` from
76
- `kbdb_shared::content_parser` to build the
77
- `references` array in result sets. When a search
78
- or retrieval request returns sections, `kb-worker`
79
- scans each section's content, follows `$(text:)` and
80
- `$(document:)` references recursively using a visited
81
- set, and returns a flat deduplicated `references`
82
- array alongside the primary result data.
83
-
84
- ## Sub-documents
85
-
86
- - [types.md](types.md) -- `ContentMarkerType`,
87
- `ExtractedContentMarker`
88
- - [functions.md](functions.md) --
89
- `extract_content_markers()`,
90
- `strip_content_markers()`
91
-
92
- ## Testing
93
-
94
- Tests live inline in
95
- `engine/crates/shared/src/content-parser/extract.rs`
96
- and
97
- `engine/crates/shared/src/content-parser/strip.rs`
98
- (`#[cfg(test)]` modules). See
99
- [functions.md](functions.md) for test descriptions.
@@ -1,71 +0,0 @@
1
- # content-parser -- Types
2
-
3
- ## `ContentMarkerType`
4
-
5
- Enum identifying the six recognized content marker
6
- types.
7
-
8
- ```rust
9
- pub enum ContentMarkerType {
10
- /// `$(image: {kbid})` -- image section embedding.
11
- Image,
12
- /// `$(code: {kbid})` -- code section embedding.
13
- Code,
14
- /// `$(text: {kbid})` -- text section embedding.
15
- Text,
16
- /// `$(document: {docid})` -- document embedding.
17
- Document,
18
- /// `$(link: {kbid})` -- section cross-reference.
19
- Link,
20
- /// `$(doc-link: {docid})` -- document
21
- /// cross-reference.
22
- DocLink,
23
- }
24
- ```
25
-
26
- Each variant maps to a `$(type:` prefix:
27
-
28
- | Variant | Prefix | Value type |
29
- |------------|----------------|------------|
30
- | `Image` | `$(image:` | kbid |
31
- | `Code` | `$(code:` | kbid |
32
- | `Text` | `$(text:` | kbid |
33
- | `Document` | `$(document:` | docid |
34
- | `Link` | `$(link:` | kbid |
35
- | `DocLink` | `$(doc-link:` | docid |
36
-
37
- ## `ExtractedContentMarker`
38
-
39
- A single marker extracted from text content.
40
-
41
- ```rust
42
- pub struct ExtractedContentMarker {
43
- /// The marker category.
44
- pub marker_type: ContentMarkerType,
45
- /// The value inside the marker (kb-id or doc-id).
46
- pub value: String,
47
- /// Byte offset of the marker start (`$`) in the
48
- /// original text.
49
- pub offset: usize,
50
- /// Byte length of the entire marker, including
51
- /// the `$(` and `)` delimiters.
52
- pub length: usize,
53
- }
54
- ```
55
-
56
- ## Syntax Rules
57
-
58
- Content markers follow these parsing rules:
59
-
60
- 1. A marker starts with `$(` and ends with the next
61
- `)`.
62
- 2. The type identifier is matched against the six
63
- recognized prefixes listed above.
64
- 3. Unrecognized prefixes (e.g. `$(formula:`) are
65
- **skipped** -- no `ExtractedContentMarker` is
66
- produced.
67
- 4. Unclosed markers (no closing `)` before end of
68
- input) are **skipped**.
69
- 5. The value is the text between the colon-space and
70
- the closing `)`, trimmed of leading and trailing
71
- whitespace.
@@ -1,24 +0,0 @@
1
- # corpus -- Corpus Statistics
2
-
3
- *Lightweight corpus statistics passed between modules
4
- for IDF computation and BM25F length normalization.*
5
-
6
- ## Source
7
-
8
- `engine/crates/shared/src/corpus/`
9
-
10
- ## Responsibility
11
-
12
- Defines the lightweight `CorpusStats` view passed
13
- from `fs-database` to `query-parser` via `kb-worker`
14
- for ranking computations. Contains only the scalar
15
- values needed for BM25F -- the full document
16
- frequency map stays private to `fs-database`.
17
-
18
- See [Query Parser -- Ranking](
19
- ../../../../goals/query-parser.md) for how these
20
- values are used in BM25F scoring.
21
-
22
- ## Exports
23
-
24
- - **[types.md](types.md)** -- `CorpusStats`.
@@ -1,141 +0,0 @@
1
- # types::corpus -- Corpus Statistics
2
-
3
- *Lightweight corpus statistics struct passed between
4
- modules for IDF computation and BM25F length
5
- normalization.*
6
-
7
- ## File
8
-
9
- `engine/crates/shared/src/corpus/corpus.rs`
10
-
11
- ## Overview
12
-
13
- Ranking functions need corpus-wide statistics to
14
- compute inverse document frequency (IDF) and
15
- normalize for section length. The full corpus data
16
- (including the per-term document frequency map) lives
17
- in `fs-database`'s `CorpusStats` struct in the
18
- `index::corpus` module. This shared type is a
19
- **lightweight view** -- just the scalar values needed
20
- by `query-parser`'s ranking exports.
21
-
22
- `kb-worker` reads the full stats from `fs-database`,
23
- extracts the fields needed for ranking, and passes
24
- this struct to `query-parser`.
25
-
26
- See [Query Parser -- Ranking](
27
- ../../../../../goals/query-parser.md) for how these
28
- values are used in BM25F scoring.
29
-
30
- ## Type Definition
31
-
32
- ```rust
33
- pub struct CorpusStats {
34
- pub total_sections: u32,
35
- pub total_terms: u32,
36
- pub avg_section_length: f32,
37
- pub avg_heading_length: f32,
38
- pub avg_body_length: f32,
39
- pub avg_code_length: f32,
40
- }
41
- ```
42
-
43
- | Field | Description |
44
- |----------------------|--------------------------------|
45
- | `total_sections` | Number of sections with at least one indexed term |
46
- | `total_terms` | Total number of distinct terms in the inverted index |
47
- | `avg_section_length` | Average total token count per indexed section |
48
- | `avg_heading_length` | Average heading-field token count per indexed section |
49
- | `avg_body_length` | Average body-field token count per indexed section |
50
- | `avg_code_length` | Average code-field token count per indexed section |
51
-
52
- ### `total_sections`
53
-
54
- Count of sections that have at least one indexed
55
- term. Image sections are included when their
56
- `title` or `description` produces indexed terms.
57
- Used as the `N` value in IDF:
58
- `idf(t) = ln((N - df(t) + 0.5) / (df(t) + 0.5) + 1)`.
59
-
60
- ### `total_terms`
61
-
62
- Number of unique terms across the entire index.
63
- Informational -- not directly used in ranking, but
64
- useful for status reporting and diagnostics.
65
-
66
- ### `avg_section_length`
67
-
68
- Average number of tokens per indexed section. Used
69
- by BM25F for overall length normalization.
70
-
71
- Computed as:
72
- `sum(token_count for each indexed section) / total_sections`
73
-
74
- ### `avg_heading_length`
75
-
76
- Average heading-field token count per indexed
77
- section. Used by BM25F for per-field length
78
- normalization of the heading component (title
79
- content).
80
-
81
- Computed as:
82
- `sum(heading_token_count for each indexed section) / total_sections`
83
-
84
- ### `avg_body_length`
85
-
86
- Average body-field token count per indexed section.
87
- Used by BM25F for per-field length normalization
88
- of the body component (body text + description).
89
-
90
- Computed as:
91
- `sum(body_token_count for each indexed section) / total_sections`
92
-
93
- ### `avg_code_length`
94
-
95
- Average code-field token count per indexed section.
96
- Used by BM25F for per-field length normalization
97
- of the code component (source code content).
98
-
99
- Computed as:
100
- `sum(code_token_count for each indexed section) / total_sections`
101
-
102
- ## Why a Separate Shared Type
103
-
104
- `fs-database`'s internal `CorpusStats` struct (in
105
- `index::corpus`) contains additional fields -- the
106
- full `HashMap<Term, u32>` of per-term document
107
- frequencies, incremental update methods, and
108
- serialization logic for the `corpus.dat` binary file.
109
- That struct is private to `fs-database`.
110
-
111
- The shared `CorpusStats` here contains only the
112
- scalar fields that cross module boundaries. This
113
- keeps the shared type small and avoids exposing
114
- `fs-database` internals to `query-parser`.
115
-
116
- When `kb-worker` needs per-term IDF values, it calls
117
- `db_corpus_stats` (which returns this shared struct)
118
- and separately calls `db_execute_plan` (which returns
119
- per-term frequencies in `RawMatch`). The full
120
- document frequency map never leaves `fs-database`.
121
-
122
- ## Trait Implementations
123
-
124
- | Trait | Purpose |
125
- |----------|----------------------------------|
126
- | `Clone` | Cached alongside index segments |
127
- | `Debug` | Diagnostic output |
128
- | `Copy` | Small struct, stack-friendly |
129
- | `Encode` | Binary serialization for shared memory (see [encode](../encode/traits.md)) |
130
-
131
- ## Testing
132
-
133
- Unit tests:
134
-
135
- - Construction with valid values.
136
- - `Copy` semantics: assignment creates independent
137
- value.
138
- - `Encode` round-trip preserves all six fields
139
- including `f32` precision.
140
- - Edge cases: `total_sections = 0` (empty database),
141
- all average lengths `0.0`.
@@ -1,25 +0,0 @@
1
- # document -- Document Records
2
-
3
- *Data structures for document manifests and document-
4
- level retrieval results.*
5
-
6
- ## Source
7
-
8
- `engine/crates/shared/src/document/`
9
-
10
- ## Responsibility
11
-
12
- Defines the document manifest and record types that
13
- group sections under a title with a defined order.
14
- Shared across `fs-database` (manifest storage),
15
- `kb-worker` (cache entries and retrieval), and the
16
- IPC boundary.
17
-
18
- See [Database -- Documents](
19
- ../../../../goals/database.md) for the behavioral
20
- specification of document manifests.
21
-
22
- ## Exports
23
-
24
- - **[types.md](types.md)** -- `DocumentManifest`,
25
- `DocumentSection`, `DocumentRecord`.
@@ -1,154 +0,0 @@
1
- # types::document -- Document Records
2
-
3
- *Data structures for document manifests and document-
4
- level retrieval results shared across WASM modules.*
5
-
6
- ## File
7
-
8
- `engine/crates/shared/src/document/document.rs`
9
-
10
- ## Overview
11
-
12
- A **document** groups sections under a title with a
13
- defined order. The document itself contains no content
14
- -- it references sections by kb-id. These types are
15
- shared across `fs-database` (manifest storage),
16
- `kb-worker` (cache entries and retrieval), and
17
- the IPC boundary (JSON-RPC responses).
18
-
19
- See [Database -- Documents](
20
- ../../../../../goals/database.md) for the behavioral
21
- specification of document manifests.
22
-
23
- ## Type Definitions
24
-
25
- ### `DocumentManifest`
26
-
27
- ```rust
28
- pub struct DocumentManifest {
29
- pub docid: String,
30
- pub title: String,
31
- pub created_at: String,
32
- pub sections: Vec<DocumentSection>,
33
- }
34
- ```
35
-
36
- Represents the TOML manifest file at
37
- `documents/{docid}.toml`. Contains metadata and an
38
- ordered list of section references.
39
-
40
- `sections` is ordered by `position` -- the manifest
41
- preserves the original section order within the
42
- document.
43
-
44
- ### `DocumentSection`
45
-
46
- ```rust
47
- pub struct DocumentSection {
48
- pub kbid: KbId,
49
- pub position: u32,
50
- }
51
- ```
52
-
53
- A reference from a document to a section. `position`
54
- is a zero-based ordinal that determines the section's
55
- display order when the document is retrieved.
56
-
57
- ### `DocumentRecord`
58
-
59
- ```rust
60
- pub struct DocumentRecord {
61
- pub docid: String,
62
- pub title: String,
63
- pub created_at: String,
64
- pub sections: Vec<SectionRecord>,
65
- }
66
- ```
67
-
68
- A fully resolved document -- the manifest plus the
69
- actual content of each referenced section. Produced
70
- by `kb-worker` when a caller requests a document
71
- via `worker_retrieve_doc`. The `sections` vector
72
- contains full `SectionRecord` entries (with content
73
- bodies) in position order.
74
-
75
- This type is used at the IPC boundary for the
76
- `retrieve document` endpoint and in the `get_result`
77
- response with `type: "content"`.
78
-
79
- ## Methods
80
-
81
- ### `DocumentManifest`
82
-
83
- ```rust
84
- impl DocumentManifest {
85
- pub fn section_count(&self) -> u32;
86
-
87
- pub fn contains(&self, kbid: &KbId) -> bool;
88
-
89
- pub fn replace_section(
90
- &mut self,
91
- old_kbid: &KbId,
92
- new_kbid: &KbId,
93
- ) -> bool;
94
-
95
- pub fn remove_section(
96
- &mut self,
97
- kbid: &KbId,
98
- ) -> bool;
99
-
100
- pub fn reposition(&mut self);
101
- }
102
- ```
103
-
104
- #### `section_count`
105
-
106
- Returns the number of section references.
107
-
108
- #### `contains`
109
-
110
- Checks whether a kb-id is in the section list.
111
-
112
- #### `replace_section`
113
-
114
- Replaces `old_kbid` with `new_kbid` in the section
115
- list, preserving position. Returns `true` if the
116
- replacement was made, `false` if `old_kbid` was not
117
- found. Used by `fs-database` during section updates
118
- (content-addressable storage means a content change
119
- produces a new kb-id).
120
-
121
- #### `remove_section`
122
-
123
- Removes a section reference by kb-id. Returns `true`
124
- if removed. Does **not** reposition remaining
125
- sections -- call `reposition()` afterward if
126
- contiguous positions are required.
127
-
128
- #### `reposition`
129
-
130
- Reassigns `position` values to `0, 1, 2, ...` based
131
- on current vector order. Called after
132
- `remove_section` to close gaps.
133
-
134
- ## Trait Implementations
135
-
136
- | Trait | Types |
137
- |----------|-----------------------------------------|
138
- | `Clone` | All three types |
139
- | `Debug` | All three types |
140
- | `Encode` | All three types (see [encode](../encode/traits.md)) |
141
-
142
- ## Testing
143
-
144
- Unit tests:
145
-
146
- - `replace_section` swaps kb-ids correctly and
147
- preserves position.
148
- - `replace_section` returns `false` for missing
149
- kb-ids.
150
- - `remove_section` + `reposition` closes position
151
- gaps.
152
- - `contains` matches on kb-id.
153
- - `Encode` round-trip for `DocumentManifest` and
154
- `DocumentRecord` with multiple sections.
@@ -1,22 +0,0 @@
1
- # encode -- Binary Encoding
2
-
3
- *Compact binary serialization for structured data
4
- passed through shared `WebAssembly.Memory` between
5
- WASM modules.*
6
-
7
- ## Source
8
-
9
- `engine/crates/shared/src/encode/`
10
-
11
- ## Responsibility
12
-
13
- Defines the `Encode` trait and its implementations
14
- for all shared types. Provides the wire format used
15
- whenever structured data crosses a WASM module
16
- boundary through shared memory.
17
-
18
- ## Exports
19
-
20
- - **[traits.md](traits.md)** -- `Encode` trait
21
- definition, wire format specification, per-type
22
- implementations, `DecodeError`.