@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.
- package/README.md +59 -24
- package/dist/cli.cjs +462 -73
- package/dist/cli.cjs.map +4 -4
- package/dist/cli.mjs +454 -65
- package/dist/cli.mjs.map +4 -4
- package/dist/kbdb-worker.cjs +395 -60
- package/dist/kbdb-worker.cjs.map +4 -4
- package/dist/mod.cjs +18 -1
- package/dist/mod.cjs.map +2 -2
- package/dist/mod.mjs +18 -1
- package/dist/mod.mjs.map +2 -2
- package/dist/src/shared/cli/functions/dispatch-command.function.d.ts +3 -1
- package/dist/src/shared/cli/functions/install-default-skills.function.d.ts +12 -0
- package/dist/src/shared/cli/functions/run-check.function.d.ts +47 -5
- package/dist/src/shared/cli/functions/run-export.function.d.ts +34 -0
- package/dist/src/shared/cli/functions/run-gc.function.d.ts +6 -0
- package/dist/src/shared/cli/functions/run-learn.function.d.ts +35 -6
- package/dist/src/shared/cli/functions/run-recall.function.d.ts +45 -0
- package/dist/src/shared/cli/functions/run-search.function.d.ts +52 -15
- package/dist/src/shared/cli/index.d.ts +4 -0
- package/dist/src/shared/cli/typings/cli-options.interface.d.ts +13 -0
- package/dist/src/shared/cli/typings/learn-result.model.d.ts +19 -0
- package/dist/src/shared/cli/typings/search-display.model.d.ts +18 -0
- package/dist/src/shared/mcp/classes/mcp-server.class.d.ts +8 -0
- package/dist/src/shared/mcp/typings/mcp-client.interface.d.ts +43 -0
- package/dist/src/shared/version/constants/version.constant.d.ts +1 -1
- package/dist/src/shared/wasm-codec/functions/decode-add-section-result.function.d.ts +48 -0
- package/dist/src/shared/wasm-codec/functions/decode-scored-results.function.d.ts +58 -0
- package/dist/src/shared/wasm-codec/functions/decode-section-records.function.d.ts +33 -0
- package/dist/src/shared/wasm-codec/functions/encode-add-section-params.function.d.ts +52 -0
- package/dist/src/shared/wasm-codec/index.d.ts +2 -0
- package/dist/src/shared/worker-client/classes/worker-client.class.d.ts +16 -0
- package/dist/src/shared/worker-client/index.d.ts +1 -1
- package/dist/src/shared/worker-client/typings/add-section-result.model.d.ts +29 -15
- package/dist/src/shared/worker-client/typings/export-result.model.d.ts +14 -0
- package/dist/src/shared/worker-client/typings/gc-result.model.d.ts +6 -0
- package/dist/src/shared/worker-client/typings/search-result.model.d.ts +12 -0
- package/dist/src/shared/worker-client/typings/section.model.d.ts +16 -0
- package/dist/src/shared/worker-daemon/classes/worker-daemon.class.d.ts +35 -0
- package/dist/wasm/fs-database/kbdb_fs_database.d.ts +22 -1
- package/dist/wasm/fs-database/kbdb_fs_database.js +28 -1
- package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
- package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +1 -0
- package/dist/wasm/kb-worker/kbdb_worker.d.ts +48 -1
- package/dist/wasm/kb-worker/kbdb_worker.js +60 -1
- package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
- package/dist/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +2 -0
- package/dist/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
- package/dist/worker.mjs +396 -60
- package/dist/worker.mjs.map +4 -4
- package/docs/details/cli.md +102 -15
- package/docs/details/library-api.md +55 -6
- package/docs/details/mcp-server.md +8 -4
- package/docs/details/search-and-ranking.md +63 -5
- package/docs/details/storage.md +2 -0
- package/docs/goals/cli.md +255 -14
- package/docs/goals/database.md +244 -17
- package/docs/goals/document.md +1 -1
- package/docs/goals/mcp.md +83 -14
- package/docs/goals/query-parser.md +98 -4
- package/docs/goals/query-result.md +177 -10
- package/docs/goals/skills.md +72 -0
- package/docs/goals/worker-daemon.md +54 -7
- package/docs/modules/rust/fs-database/functions/integrity.md +11 -0
- package/docs/modules/rust/fs-database/functions/section.md +23 -6
- package/docs/modules/rust/fs-database/module.md +1 -0
- package/docs/modules/rust/fs-database/types/section.md +27 -1
- package/docs/modules/rust/overview.md +2 -1
- package/docs/modules/rust/query-parser/functions/module.md +2 -2
- package/docs/modules/rust/query-parser/functions/pipeline.md +44 -6
- package/docs/modules/rust/query-parser/module.md +5 -4
- package/docs/modules/rust/query-parser/types/keyphrase.md +11 -0
- package/docs/modules/rust/query-parser/types/module.md +3 -3
- package/docs/modules/typescript/shared/cli/functions.md +68 -3
- package/package.json +1 -1
- package/src/shared/cli/functions/dispatch-command.function.ts +53 -1
- package/src/shared/cli/functions/format-output.function.ts +36 -12
- package/src/shared/cli/functions/generate-help.function.ts +56 -1
- package/src/shared/cli/functions/install-default-skills.function.ts +296 -0
- package/src/shared/cli/functions/parse-args.function.ts +13 -0
- package/src/shared/cli/functions/run-check.function.ts +87 -6
- package/src/shared/cli/functions/run-export.function.ts +40 -0
- package/src/shared/cli/functions/run-gc.function.ts +6 -0
- package/src/shared/cli/functions/run-init.function.ts +2 -0
- package/src/shared/cli/functions/run-learn.function.ts +68 -16
- package/src/shared/cli/functions/run-recall.function.ts +66 -0
- package/src/shared/cli/functions/run-search.function.ts +58 -15
- package/src/shared/cli/index.ts +4 -0
- package/src/shared/cli/typings/cli-options.interface.ts +13 -0
- package/src/shared/cli/typings/learn-result.model.ts +16 -0
- package/src/shared/cli/typings/search-display.model.ts +18 -0
- package/src/shared/mcp/classes/mcp-server.class.ts +30 -1
- package/src/shared/mcp/functions/create-tool-definitions.function.ts +46 -5
- package/src/shared/mcp/functions/handle-tool-call.function.ts +70 -2
- package/src/shared/mcp/typings/mcp-client.interface.ts +45 -0
- package/src/shared/version/constants/version.constant.ts +1 -1
- package/src/shared/wasm-codec/functions/decode-add-section-result.function.ts +112 -0
- package/src/shared/wasm-codec/functions/decode-scored-results.function.ts +86 -0
- package/src/shared/wasm-codec/functions/decode-section-records.function.ts +87 -0
- package/src/shared/wasm-codec/functions/encode-add-section-params.function.ts +68 -0
- package/src/shared/wasm-codec/index.ts +5 -0
- package/src/shared/worker-client/classes/worker-client.class.ts +19 -0
- package/src/shared/worker-client/index.ts +4 -1
- package/src/shared/worker-client/typings/add-section-result.model.ts +30 -15
- package/src/shared/worker-client/typings/export-result.model.ts +14 -0
- package/src/shared/worker-client/typings/gc-result.model.ts +6 -0
- package/src/shared/worker-client/typings/search-result.model.ts +12 -0
- package/src/shared/worker-client/typings/section.model.ts +16 -0
- package/src/shared/worker-daemon/classes/worker-daemon.class.ts +315 -46
- package/src/shared/worker-daemon/functions/create-host-imports.function.ts +19 -4
- package/src/shared/worker-daemon/functions/create-ipc-server.function.ts +5 -1
- package/src/wasm/fs-database/kbdb_fs_database.d.ts +22 -1
- package/src/wasm/fs-database/kbdb_fs_database.js +28 -1
- package/src/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
- package/src/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +1 -0
- package/src/wasm/kb-worker/kbdb_worker.d.ts +48 -1
- package/src/wasm/kb-worker/kbdb_worker.js +60 -1
- package/src/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
- package/src/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +2 -0
- package/src/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
|
@@ -49,8 +49,9 @@ engine/crates/query-parser/
|
|
|
49
49
|
│ ├── identifiers.rs # stage 4: camelCase split
|
|
50
50
|
│ ├── case.rs # stage 5: case folding
|
|
51
51
|
│ ├── stopwords.rs # stage 6: stop words
|
|
52
|
-
│ ├──
|
|
53
|
-
│
|
|
52
|
+
│ ├── synonyms.rs # stage 7: synonym expansion
|
|
53
|
+
│ ├── stem.rs # stage 8: Snowball stemmer
|
|
54
|
+
│ └── ngram.rs # stage 9: n-gram extract
|
|
54
55
|
├── parse.rs # query string → QueryPlan
|
|
55
56
|
├── extract/
|
|
56
57
|
│ ├── mod.rs # extraction facade
|
|
@@ -78,10 +79,10 @@ engine/crates/query-parser/
|
|
|
78
79
|
|
|
79
80
|
### [functions/](functions/module.md) -- Operations
|
|
80
81
|
|
|
81
|
-
- **[pipeline](functions/pipeline.md)** --
|
|
82
|
+
- **[pipeline](functions/pipeline.md)** -- 9-stage
|
|
82
83
|
tokenization pipeline. Marker stripping, NFC,
|
|
83
84
|
segmentation, identifier splitting, case folding,
|
|
84
|
-
stop words, stemming, n-grams.
|
|
85
|
+
stop words, synonym expansion, stemming, n-grams.
|
|
85
86
|
- **[parse](functions/parse.md)** -- Query string
|
|
86
87
|
parsing into `QueryPlan`.
|
|
87
88
|
- **[extract](functions/extract.md)** -- RAKE
|
|
@@ -58,3 +58,14 @@ component and per-field corpus average from
|
|
|
58
58
|
[FieldTokenCounts](../../shared/query/types.md)
|
|
59
59
|
for the per-field token counts used in length
|
|
60
60
|
normalization.
|
|
61
|
+
|
|
62
|
+
```rust
|
|
63
|
+
pub type SynonymMap = HashMap<String, Vec<String>>;
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`SynonymMap` is a type alias for the bidirectional
|
|
67
|
+
synonym lookup used in tokenization pipeline stage 7.
|
|
68
|
+
It is constructed once via `build_synonym_map()` from
|
|
69
|
+
a curated list of synonym pairs and reused across all
|
|
70
|
+
tokenization calls. The map is immutable after
|
|
71
|
+
construction.
|
|
@@ -9,9 +9,9 @@ tokenization, keyword extraction, and ranking.*
|
|
|
9
9
|
`Ngram`, `NgramType`, `StemResult`. Output types
|
|
10
10
|
from the tokenization pipeline.
|
|
11
11
|
- **[keyphrase](keyphrase.md)** -- `Keyphrase`,
|
|
12
|
-
`WeightedTerm`, `BM25FParams`, `FieldWeights
|
|
13
|
-
Types for keyword extraction
|
|
14
|
-
configuration.
|
|
12
|
+
`WeightedTerm`, `BM25FParams`, `FieldWeights`,
|
|
13
|
+
`SynonymMap`. Types for keyword extraction, ranking
|
|
14
|
+
configuration, and synonym expansion.
|
|
15
15
|
- **[cache](cache.md)** -- `QueryCache`. Short-lived
|
|
16
16
|
cache scoped to a single query or indexing
|
|
17
17
|
operation.
|
|
@@ -68,14 +68,17 @@ async function dispatchCommand(
|
|
|
68
68
|
|
|
69
69
|
`DispatchClient` is the intersection of all per-command
|
|
70
70
|
client interfaces (`SearchClient & LearnClient &
|
|
71
|
-
UnlearnClient &
|
|
72
|
-
GcClient & RebuildClient &
|
|
71
|
+
UnlearnClient & RecallClient & ContentClient &
|
|
72
|
+
CheckClient & GcClient & RebuildClient & ExportClient &
|
|
73
|
+
SkillClient & AgentClient`).
|
|
73
74
|
|
|
74
75
|
| Command | Handler |
|
|
75
76
|
|----------------|----------------------------------|
|
|
76
77
|
| `learn` | `runLearn(client, options, io)` |
|
|
78
|
+
| `export` | `runExport(client, options)` |
|
|
77
79
|
| `unlearn` | `runUnlearn(client, options)` |
|
|
78
80
|
| `search` | `runSearch(client, options)` |
|
|
81
|
+
| `recall` | `runRecall(client, options)` |
|
|
79
82
|
| `content` | `runContent(client, options)` |
|
|
80
83
|
| `check` | `runCheck(client, options)` |
|
|
81
84
|
| `gc` | `runGc(client, options)` |
|
|
@@ -222,8 +225,15 @@ async function runLearn(
|
|
|
222
225
|
- If input is a **text file**: adds that single file.
|
|
223
226
|
`--title` and `--description` are optional.
|
|
224
227
|
- If input is **stdin** (`-`): reads `text/markdown`.
|
|
228
|
+
- `--tags <t,...>` attaches comma-separated tags for
|
|
229
|
+
scoping and filtering.
|
|
230
|
+
- `--replace` enables supersession by source key:
|
|
231
|
+
if a section with the same source key exists, the
|
|
232
|
+
old section is replaced.
|
|
225
233
|
- Returns a `LearnResult[]` with one record per file
|
|
226
|
-
processed.
|
|
234
|
+
processed. Each result includes `superseded` (kbid
|
|
235
|
+
of replaced section or `null`), `warnings` (e.g.
|
|
236
|
+
`"heading_missing"`), and `near_duplicates`.
|
|
227
237
|
|
|
228
238
|
### `runUnlearn`
|
|
229
239
|
|
|
@@ -275,6 +285,36 @@ async function runContent(
|
|
|
275
285
|
Takes identifiers from `options.args`. Calls
|
|
276
286
|
`client.content(ids)`.
|
|
277
287
|
|
|
288
|
+
### `runRecall`
|
|
289
|
+
|
|
290
|
+
**File:** `run-recall.function.ts`
|
|
291
|
+
|
|
292
|
+
Retrieves full content and progressive context for one
|
|
293
|
+
or more sections by kbid.
|
|
294
|
+
|
|
295
|
+
```ts
|
|
296
|
+
async function runRecall(
|
|
297
|
+
client: RecallClient,
|
|
298
|
+
options: CliOptions,
|
|
299
|
+
): Promise<CommandResult>;
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
`RecallClient` interface:
|
|
303
|
+
|
|
304
|
+
```ts
|
|
305
|
+
interface RecallClient {
|
|
306
|
+
recall(
|
|
307
|
+
params: RecallParams,
|
|
308
|
+
): Promise<RecallResult | RecallResult[]>;
|
|
309
|
+
}
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
Takes kbid(s) from `options.args` and depth from
|
|
313
|
+
`options.depth` (default 0, clamped 0-3). When a
|
|
314
|
+
single kbid is provided, returns a `RecallResult`
|
|
315
|
+
JSON object. When multiple kbids are provided, returns
|
|
316
|
+
a `RecallResult[]` JSON array.
|
|
317
|
+
|
|
278
318
|
### `runCheck`
|
|
279
319
|
|
|
280
320
|
**File:** `run-check.function.ts`
|
|
@@ -320,6 +360,30 @@ async function runRebuild(
|
|
|
320
360
|
|
|
321
361
|
Calls `client.rebuildIndexes()`.
|
|
322
362
|
|
|
363
|
+
### `runExport`
|
|
364
|
+
|
|
365
|
+
**File:** `run-export.function.ts`
|
|
366
|
+
|
|
367
|
+
Exports the knowledge base as a self-contained
|
|
368
|
+
directory snapshot for backup or versioning.
|
|
369
|
+
|
|
370
|
+
```ts
|
|
371
|
+
async function runExport(
|
|
372
|
+
client: ExportClient,
|
|
373
|
+
options: CliOptions,
|
|
374
|
+
): Promise<CommandResult>;
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
Copies sections, documents, and catalog (no indexes
|
|
378
|
+
-- they are rebuildable via `rebuild`). The export
|
|
379
|
+
destination defaults to `./kbdb-export/` and can be
|
|
380
|
+
overridden via `options.args[0]`.
|
|
381
|
+
|
|
382
|
+
Output: JSON `{ "path": "...",
|
|
383
|
+
"sections_exported": number,
|
|
384
|
+
"documents_exported": number,
|
|
385
|
+
"elapsed_ms": number }`.
|
|
386
|
+
|
|
323
387
|
### `ensureDb`
|
|
324
388
|
|
|
325
389
|
**File:** `ensure-db.function.ts`
|
|
@@ -608,6 +672,7 @@ src/shared/cli/
|
|
|
608
672
|
├── run-db-init.spec.ts
|
|
609
673
|
├── run-db-migrate.spec.ts
|
|
610
674
|
├── run-learn.spec.ts
|
|
675
|
+
├── run-export.spec.ts
|
|
611
676
|
├── run-unlearn.spec.ts
|
|
612
677
|
├── run-search.spec.ts
|
|
613
678
|
├── run-content.spec.ts
|
package/package.json
CHANGED
|
@@ -19,6 +19,8 @@ import type { AgentCreateClient } from './run-agent-create.function.ts';
|
|
|
19
19
|
import type { AgentListClient } from './run-agent-list.function.ts';
|
|
20
20
|
import type { AgentGetClient } from './run-agent-get.function.ts';
|
|
21
21
|
import type { AgentDeleteClient } from './run-agent-delete.function.ts';
|
|
22
|
+
import type { RecallClient } from './run-recall.function.ts';
|
|
23
|
+
import type { ExportClient } from './run-export.function.ts';
|
|
22
24
|
import { runSearch } from './run-search.function.ts';
|
|
23
25
|
import { runLearn } from './run-learn.function.ts';
|
|
24
26
|
import { runUnlearn } from './run-unlearn.function.ts';
|
|
@@ -38,6 +40,8 @@ import { runAgentCreate } from './run-agent-create.function.ts';
|
|
|
38
40
|
import { runAgentList } from './run-agent-list.function.ts';
|
|
39
41
|
import { runAgentGet } from './run-agent-get.function.ts';
|
|
40
42
|
import { runAgentDelete } from './run-agent-delete.function.ts';
|
|
43
|
+
import { runRecall } from './run-recall.function.ts';
|
|
44
|
+
import { runExport } from './run-export.function.ts';
|
|
41
45
|
import { formatOutput } from './format-output.function.ts';
|
|
42
46
|
import { errorToMessage } from './error-to-message.function.ts';
|
|
43
47
|
|
|
@@ -64,7 +68,9 @@ export type DispatchClient = SearchClient &
|
|
|
64
68
|
AgentCreateClient &
|
|
65
69
|
AgentListClient &
|
|
66
70
|
AgentGetClient &
|
|
67
|
-
AgentDeleteClient
|
|
71
|
+
AgentDeleteClient &
|
|
72
|
+
RecallClient &
|
|
73
|
+
ExportClient;
|
|
68
74
|
|
|
69
75
|
/**
|
|
70
76
|
* Routes a parsed CLI command to the appropriate handler and
|
|
@@ -86,6 +92,8 @@ export async function dispatchCommand(
|
|
|
86
92
|
return handleUnlearn(client, options);
|
|
87
93
|
case 'search':
|
|
88
94
|
return handleSearch(client, options);
|
|
95
|
+
case 'recall':
|
|
96
|
+
return handleRecall(client, options);
|
|
89
97
|
case 'content':
|
|
90
98
|
return handleContent(client, options);
|
|
91
99
|
case 'check':
|
|
@@ -96,6 +104,8 @@ export async function dispatchCommand(
|
|
|
96
104
|
return handleRebuild(client, options);
|
|
97
105
|
case 'status':
|
|
98
106
|
return handleStatus(client, options);
|
|
107
|
+
case 'export':
|
|
108
|
+
return handleExport(client, options);
|
|
99
109
|
case 'db-init':
|
|
100
110
|
return handleDbInit(options);
|
|
101
111
|
case 'db-migrate':
|
|
@@ -198,6 +208,48 @@ async function handleSearch(
|
|
|
198
208
|
}
|
|
199
209
|
}
|
|
200
210
|
|
|
211
|
+
async function handleRecall(
|
|
212
|
+
client: DispatchClient,
|
|
213
|
+
options: CliOptions,
|
|
214
|
+
): Promise<CommandResult> {
|
|
215
|
+
try {
|
|
216
|
+
const result = await runRecall(client, options);
|
|
217
|
+
if ('error' in result) {
|
|
218
|
+
return {
|
|
219
|
+
error: `error: ${result.error}`,
|
|
220
|
+
exitCode: 1,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
return {
|
|
224
|
+
output: JSON.stringify(result, null, 2),
|
|
225
|
+
exitCode: 0,
|
|
226
|
+
};
|
|
227
|
+
} catch (err) {
|
|
228
|
+
return {
|
|
229
|
+
error: `recall failed: ${errorToMessage(err)}`,
|
|
230
|
+
exitCode: 1,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
async function handleExport(
|
|
236
|
+
client: DispatchClient,
|
|
237
|
+
options: CliOptions,
|
|
238
|
+
): Promise<CommandResult> {
|
|
239
|
+
try {
|
|
240
|
+
const result = await runExport(client, options);
|
|
241
|
+
return {
|
|
242
|
+
output: JSON.stringify(result, null, 2),
|
|
243
|
+
exitCode: 0,
|
|
244
|
+
};
|
|
245
|
+
} catch (err) {
|
|
246
|
+
return {
|
|
247
|
+
error: `export failed: ${errorToMessage(err)}`,
|
|
248
|
+
exitCode: 1,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
201
253
|
async function handleContent(
|
|
202
254
|
client: DispatchClient,
|
|
203
255
|
options: CliOptions,
|
|
@@ -37,12 +37,16 @@ function formatText(paged: PagedSearchDisplay): string {
|
|
|
37
37
|
const num = paged.offset + i + 1;
|
|
38
38
|
const heading = r.heading ?? '(untitled)';
|
|
39
39
|
const terms = r.matched_terms.join(', ');
|
|
40
|
+
const fields = r.matched_fields.join(', ');
|
|
41
|
+
const confidencePct = (r.confidence * 100).toFixed(0);
|
|
40
42
|
return (
|
|
41
43
|
`${String(num)}. [${r.kbid}] ${heading}` +
|
|
42
|
-
` (score: ${r.score.toFixed(4)}
|
|
44
|
+
` (score: ${r.score.toFixed(4)},` +
|
|
45
|
+
` confidence: ${confidencePct}%)\n` +
|
|
43
46
|
` ${r.snippet || r.preview || '(no snippet)'}\n` +
|
|
44
47
|
` type: ${r.type}` +
|
|
45
|
-
` terms: ${terms}`
|
|
48
|
+
` terms: ${terms}` +
|
|
49
|
+
(fields ? ` fields: ${fields}` : '')
|
|
46
50
|
);
|
|
47
51
|
})
|
|
48
52
|
.join('\n\n');
|
|
@@ -58,14 +62,34 @@ function formatText(paged: PagedSearchDisplay): string {
|
|
|
58
62
|
}
|
|
59
63
|
|
|
60
64
|
function formatMcp(paged: PagedSearchDisplay): string {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
});
|
|
65
|
+
const mcpItems = paged.items.map((r) => ({
|
|
66
|
+
kbid: r.kbid,
|
|
67
|
+
heading: r.heading,
|
|
68
|
+
type: r.type,
|
|
69
|
+
docids: r.docids,
|
|
70
|
+
snippet: r.snippet,
|
|
71
|
+
matched_terms: r.matched_terms,
|
|
72
|
+
matched_fields: r.matched_fields,
|
|
73
|
+
created_at: r.created_at,
|
|
74
|
+
}));
|
|
75
|
+
return JSON.stringify(
|
|
76
|
+
{
|
|
77
|
+
type: 'text',
|
|
78
|
+
text: paged.items
|
|
79
|
+
.map(
|
|
80
|
+
(r) =>
|
|
81
|
+
`[${r.kbid}] ${r.heading ?? '(untitled)'}` +
|
|
82
|
+
` — ${r.snippet || r.preview}`,
|
|
83
|
+
)
|
|
84
|
+
.join('\n'),
|
|
85
|
+
items: mcpItems,
|
|
86
|
+
total: paged.total,
|
|
87
|
+
offset: paged.offset,
|
|
88
|
+
limit: paged.limit,
|
|
89
|
+
has_more: paged.has_more,
|
|
90
|
+
relaxed: paged.relaxed,
|
|
91
|
+
},
|
|
92
|
+
null,
|
|
93
|
+
2,
|
|
94
|
+
);
|
|
71
95
|
}
|
|
@@ -8,11 +8,13 @@ const KNOWN_COMMANDS = new Set([
|
|
|
8
8
|
'learn',
|
|
9
9
|
'unlearn',
|
|
10
10
|
'search',
|
|
11
|
+
'recall',
|
|
11
12
|
'content',
|
|
12
13
|
'check',
|
|
13
14
|
'gc',
|
|
14
15
|
'rebuild',
|
|
15
16
|
'status',
|
|
17
|
+
'export',
|
|
16
18
|
'mcp',
|
|
17
19
|
'db',
|
|
18
20
|
'skill',
|
|
@@ -125,6 +127,8 @@ function generateGlobalHelp(): string {
|
|
|
125
127
|
` files/stdin\n` +
|
|
126
128
|
` unlearn Remove sections by kbid\n` +
|
|
127
129
|
` search Query the knowledge base\n` +
|
|
130
|
+
` recall Retrieve section context` +
|
|
131
|
+
` by kbid\n` +
|
|
128
132
|
` content Compose rendered content` +
|
|
129
133
|
` from ids\n` +
|
|
130
134
|
`\n` +
|
|
@@ -142,6 +146,8 @@ function generateGlobalHelp(): string {
|
|
|
142
146
|
` rebuild Reconstruct all index` +
|
|
143
147
|
` files\n` +
|
|
144
148
|
` status Show database status\n` +
|
|
149
|
+
` export Snapshot database for` +
|
|
150
|
+
` backup\n` +
|
|
145
151
|
`\n` +
|
|
146
152
|
`Skills:\n` +
|
|
147
153
|
` skill learn Create a new skill` +
|
|
@@ -238,14 +244,20 @@ const LEAF_HELP: Readonly<Record<string, string>> = {
|
|
|
238
244
|
` --description <d> Section description\n` +
|
|
239
245
|
` --docid <docid> Document ID to group` +
|
|
240
246
|
` under\n` +
|
|
247
|
+
` --tags <t,...> Comma-separated tags\n` +
|
|
248
|
+
` --replace Supersede existing section` +
|
|
249
|
+
` by source key\n` +
|
|
241
250
|
` --db <path> Path to .kbdb directory\n` +
|
|
242
251
|
`\n` +
|
|
243
252
|
`Output:\n` +
|
|
244
|
-
` JSON array of { kbid, path, size, skipped
|
|
253
|
+
` JSON array of { kbid, path, size, skipped,\n` +
|
|
254
|
+
` superseded, warnings,` +
|
|
255
|
+
` near_duplicates }\n` +
|
|
245
256
|
`\n` +
|
|
246
257
|
`Examples:\n` +
|
|
247
258
|
` kbdb learn README.md\n` +
|
|
248
259
|
` kbdb learn ./docs/\n` +
|
|
260
|
+
` kbdb learn --tags auth,api --replace doc.md\n` +
|
|
249
261
|
` cat notes.txt | kbdb learn -\n`,
|
|
250
262
|
|
|
251
263
|
unlearn:
|
|
@@ -294,6 +306,28 @@ const LEAF_HELP: Readonly<Record<string, string>> = {
|
|
|
294
306
|
` kbdb search --limit 5 --format text query\n` +
|
|
295
307
|
` kbdb search --mode documents --content term\n`,
|
|
296
308
|
|
|
309
|
+
recall:
|
|
310
|
+
`kbdb recall - Retrieve section context by kbid\n` +
|
|
311
|
+
`\n` +
|
|
312
|
+
`Usage: kbdb recall [options] <kbid>...\n` +
|
|
313
|
+
`\n` +
|
|
314
|
+
`Arguments:\n` +
|
|
315
|
+
` <kbid> 26-character knowledge` +
|
|
316
|
+
` base identifier\n` +
|
|
317
|
+
`\n` +
|
|
318
|
+
`Options:\n` +
|
|
319
|
+
` --depth <n>, -d Expansion depth (0-3,` +
|
|
320
|
+
` default: 0)\n` +
|
|
321
|
+
` --tags <t,...> Filter by tags\n` +
|
|
322
|
+
` --db <path> Path to .kbdb directory\n` +
|
|
323
|
+
`\n` +
|
|
324
|
+
`Output:\n` +
|
|
325
|
+
` JSON RecallResult or RecallResult[]\n` +
|
|
326
|
+
`\n` +
|
|
327
|
+
`Examples:\n` +
|
|
328
|
+
` kbdb recall abcdef1234567890abcdef1234\n` +
|
|
329
|
+
` kbdb recall kbid1 --depth 2\n`,
|
|
330
|
+
|
|
297
331
|
content:
|
|
298
332
|
`kbdb content - Compose rendered content from ids\n` +
|
|
299
333
|
`\n` +
|
|
@@ -372,6 +406,27 @@ const LEAF_HELP: Readonly<Record<string, string>> = {
|
|
|
372
406
|
` kbdb status\n` +
|
|
373
407
|
` kbdb status --db /path/to/project\n`,
|
|
374
408
|
|
|
409
|
+
export:
|
|
410
|
+
`kbdb export - Snapshot database for backup\n` +
|
|
411
|
+
`\n` +
|
|
412
|
+
`Usage: kbdb export [options] [<path>]\n` +
|
|
413
|
+
`\n` +
|
|
414
|
+
`Arguments:\n` +
|
|
415
|
+
` <path> Output directory path\n` +
|
|
416
|
+
` (default: ./kbdb-export/)\n` +
|
|
417
|
+
`\n` +
|
|
418
|
+
`Options:\n` +
|
|
419
|
+
` --db <path> Path to .kbdb directory\n` +
|
|
420
|
+
`\n` +
|
|
421
|
+
`Output:\n` +
|
|
422
|
+
` JSON { path, sections_exported,` +
|
|
423
|
+
` documents_exported }\n` +
|
|
424
|
+
`\n` +
|
|
425
|
+
`Examples:\n` +
|
|
426
|
+
` kbdb export\n` +
|
|
427
|
+
` kbdb export ./my-backup\n` +
|
|
428
|
+
` kbdb export --db /path/to/project\n`,
|
|
429
|
+
|
|
375
430
|
mcp:
|
|
376
431
|
`kbdb mcp - Start MCP server mode (stdio)\n` +
|
|
377
432
|
`\n` +
|