@dikolab/kbdb 0.1.6 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -9
- package/dist/cli.cjs +181 -50
- package/dist/cli.cjs.map +3 -3
- package/dist/cli.mjs +181 -50
- package/dist/cli.mjs.map +3 -3
- package/dist/kbdb-worker.cjs +283 -29
- package/dist/kbdb-worker.cjs.map +4 -4
- package/dist/mod.cjs +13 -2
- package/dist/mod.cjs.map +2 -2
- package/dist/mod.d.ts +25 -0
- package/dist/mod.mjs +13 -2
- package/dist/mod.mjs.map +2 -2
- package/dist/src/cli.d.ts +8 -0
- package/dist/src/shared/cli/functions/format-output.function.d.ts +7 -7
- package/dist/src/shared/cli/functions/run-search.function.d.ts +25 -16
- package/dist/src/shared/cli/index.d.ts +1 -1
- package/dist/src/shared/cli/typings/cli-options.interface.d.ts +2 -0
- package/dist/src/shared/cli/typings/search-display.model.d.ts +25 -7
- package/dist/src/shared/mcp/functions/handle-recall.function.d.ts +29 -0
- package/dist/src/shared/mcp/typings/mcp-client.interface.d.ts +30 -11
- package/dist/src/shared/version/constants/version.constant.d.ts +1 -1
- package/dist/src/shared/wasm-codec/functions/decode-recall-result.function.d.ts +28 -0
- package/dist/src/shared/wasm-codec/functions/decode-scored-results.function.d.ts +14 -7
- package/dist/src/shared/wasm-codec/functions/encode-recall-params.function.d.ts +21 -0
- package/dist/src/shared/wasm-codec/functions/encode-search-params.function.d.ts +1 -1
- package/dist/src/shared/wasm-codec/index.d.ts +5 -2
- package/dist/src/shared/worker-client/classes/worker-client.class.d.ts +13 -3
- package/dist/src/shared/worker-client/index.d.ts +2 -1
- package/dist/src/shared/worker-client/typings/recall-result.model.d.ts +94 -0
- package/dist/src/shared/worker-client/typings/search-params.model.d.ts +2 -0
- package/dist/src/shared/worker-client/typings/search-result.model.d.ts +23 -7
- package/dist/src/shared/worker-daemon/classes/worker-daemon.class.d.ts +1 -0
- package/dist/src/worker.d.ts +7 -0
- package/dist/wasm/fs-database/kbdb_fs_database.d.ts +18 -0
- package/dist/wasm/fs-database/kbdb_fs_database.js +30 -0
- package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
- package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +2 -0
- package/dist/wasm/kb-worker/kbdb_worker.d.ts +38 -0
- package/dist/wasm/kb-worker/kbdb_worker.js +56 -0
- package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
- package/dist/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +3 -0
- package/dist/worker.mjs +283 -29
- package/dist/worker.mjs.map +4 -4
- package/docs/details/README.md +26 -0
- package/docs/details/cli.md +608 -0
- package/docs/details/library-api.md +406 -0
- package/docs/details/mcp-server.md +430 -0
- package/docs/details/search-and-ranking.md +457 -0
- package/docs/details/storage.md +529 -0
- package/docs/goals/agents.md +751 -0
- package/docs/goals/architecture.svg +198 -0
- package/docs/goals/cli.md +2308 -0
- package/docs/goals/content-composer.md +609 -0
- package/docs/goals/content-parser.md +279 -0
- package/docs/goals/database.md +1452 -0
- package/docs/goals/document.md +368 -0
- package/docs/goals/mcp.md +1467 -0
- package/docs/goals/overview.md +124 -0
- package/docs/goals/query-parser.md +271 -0
- package/docs/goals/query-result.md +693 -0
- package/docs/goals/skills.md +738 -0
- package/docs/goals/worker-client.md +944 -0
- package/docs/goals/worker-daemon.md +1447 -0
- package/docs/modules/overview.md +298 -0
- package/docs/modules/rust/fs-database/functions/document.md +48 -0
- package/docs/modules/rust/fs-database/functions/integrity.md +68 -0
- package/docs/modules/rust/fs-database/functions/io.md +87 -0
- package/docs/modules/rust/fs-database/functions/module.md +22 -0
- package/docs/modules/rust/fs-database/functions/query-exec.md +44 -0
- package/docs/modules/rust/fs-database/functions/section.md +59 -0
- package/docs/modules/rust/fs-database/indexes/btree.md +35 -0
- package/docs/modules/rust/fs-database/indexes/corpus.md +61 -0
- package/docs/modules/rust/fs-database/indexes/inverted.md +60 -0
- package/docs/modules/rust/fs-database/indexes/module.md +64 -0
- package/docs/modules/rust/fs-database/indexes/positional.md +39 -0
- package/docs/modules/rust/fs-database/module.md +149 -0
- package/docs/modules/rust/fs-database/types/catalog.md +53 -0
- package/docs/modules/rust/fs-database/types/module.md +12 -0
- package/docs/modules/rust/fs-database/types/section.md +101 -0
- package/docs/modules/rust/kb-worker/functions/compose.md +57 -0
- package/docs/modules/rust/kb-worker/functions/module.md +20 -0
- package/docs/modules/rust/kb-worker/functions/retrieve.md +194 -0
- package/docs/modules/rust/kb-worker/functions/search.md +173 -0
- package/docs/modules/rust/kb-worker/functions/write.md +172 -0
- package/docs/modules/rust/kb-worker/module.md +171 -0
- package/docs/modules/rust/kb-worker/types/cache.md +90 -0
- package/docs/modules/rust/kb-worker/types/context.md +26 -0
- package/docs/modules/rust/kb-worker/types/module.md +16 -0
- package/docs/modules/rust/kb-worker/types/status.md +29 -0
- package/docs/modules/rust/kb-worker/types/token.md +50 -0
- package/docs/modules/rust/overview.md +495 -0
- package/docs/modules/rust/query-parser/functions/extract.md +56 -0
- package/docs/modules/rust/query-parser/functions/module.md +16 -0
- package/docs/modules/rust/query-parser/functions/parse.md +33 -0
- package/docs/modules/rust/query-parser/functions/pipeline.md +103 -0
- package/docs/modules/rust/query-parser/functions/rank.md +85 -0
- package/docs/modules/rust/query-parser/module.md +136 -0
- package/docs/modules/rust/query-parser/types/cache.md +39 -0
- package/docs/modules/rust/query-parser/types/keyphrase.md +60 -0
- package/docs/modules/rust/query-parser/types/module.md +17 -0
- package/docs/modules/rust/query-parser/types/token.md +42 -0
- package/docs/modules/rust/shared/content-composer/functions.md +114 -0
- package/docs/modules/rust/shared/content-composer/module.md +147 -0
- package/docs/modules/rust/shared/content-composer/types.md +93 -0
- package/docs/modules/rust/shared/content-parser/functions.md +72 -0
- package/docs/modules/rust/shared/content-parser/module.md +99 -0
- package/docs/modules/rust/shared/content-parser/types.md +71 -0
- package/docs/modules/rust/shared/corpus/module.md +24 -0
- package/docs/modules/rust/shared/corpus/types.md +141 -0
- package/docs/modules/rust/shared/document/module.md +25 -0
- package/docs/modules/rust/shared/document/types.md +154 -0
- package/docs/modules/rust/shared/encode/module.md +22 -0
- package/docs/modules/rust/shared/encode/traits.md +304 -0
- package/docs/modules/rust/shared/error/module.md +28 -0
- package/docs/modules/rust/shared/error/types.md +302 -0
- package/docs/modules/rust/shared/kbid/module.md +24 -0
- package/docs/modules/rust/shared/kbid/types.md +147 -0
- package/docs/modules/rust/shared/memory/functions.md +209 -0
- package/docs/modules/rust/shared/memory/module.md +24 -0
- package/docs/modules/rust/shared/module.md +168 -0
- package/docs/modules/rust/shared/query/module.md +27 -0
- package/docs/modules/rust/shared/query/types.md +236 -0
- package/docs/modules/rust/shared/section/module.md +25 -0
- package/docs/modules/rust/shared/section/types.md +294 -0
- package/docs/modules/rust/shared/term/module.md +25 -0
- package/docs/modules/rust/shared/term/types.md +139 -0
- package/docs/modules/typescript/cli.md +129 -0
- package/docs/modules/typescript/kbdb-worker.md +135 -0
- package/docs/modules/typescript/overview.md +378 -0
- package/docs/modules/typescript/shared/cli/constants.md +23 -0
- package/docs/modules/typescript/shared/cli/functions.md +630 -0
- package/docs/modules/typescript/shared/cli/module.md +125 -0
- package/docs/modules/typescript/shared/cli/typings.md +172 -0
- package/docs/modules/typescript/shared/hash/functions.md +20 -0
- package/docs/modules/typescript/shared/hash/module.md +21 -0
- package/docs/modules/typescript/shared/mcp/classes.md +179 -0
- package/docs/modules/typescript/shared/mcp/functions.md +386 -0
- package/docs/modules/typescript/shared/mcp/module.md +160 -0
- package/docs/modules/typescript/shared/mcp/typings.md +522 -0
- package/docs/modules/typescript/shared/module.md +94 -0
- package/docs/modules/typescript/shared/platform/functions.md +42 -0
- package/docs/modules/typescript/shared/platform/module.md +25 -0
- package/docs/modules/typescript/shared/runtime/functions.md +26 -0
- package/docs/modules/typescript/shared/runtime/module.md +27 -0
- package/docs/modules/typescript/shared/runtime/typings.md +13 -0
- package/docs/modules/typescript/shared/version/module.md +27 -0
- package/docs/modules/typescript/shared/wasm-codec/functions.md +391 -0
- package/docs/modules/typescript/shared/wasm-codec/module.md +98 -0
- package/docs/modules/typescript/shared/worker-client/classes.md +264 -0
- package/docs/modules/typescript/shared/worker-client/functions.md +175 -0
- package/docs/modules/typescript/shared/worker-client/module.md +84 -0
- package/docs/modules/typescript/shared/worker-client/typings.md +508 -0
- package/docs/modules/typescript/shared/worker-daemon/classes.md +239 -0
- package/docs/modules/typescript/shared/worker-daemon/constants.md +37 -0
- package/docs/modules/typescript/shared/worker-daemon/functions.md +221 -0
- package/docs/modules/typescript/shared/worker-daemon/module.md +112 -0
- package/docs/modules/typescript/shared/worker-daemon/typings.md +126 -0
- package/docs/overview.md +188 -0
- package/docs/release-notes/0.1.0.md +189 -0
- package/docs/release-notes/0.1.1.md +46 -0
- package/docs/release-notes/0.1.2.md +38 -0
- package/docs/release-notes/0.1.3.md +42 -0
- package/docs/release-notes/0.2.0.md +147 -0
- package/docs/release-notes/README.md +9 -0
- package/mod.ts +26 -0
- package/package.json +8 -2
- package/src/cli.ts +9 -0
- package/src/shared/cli/functions/dispatch-command.function.ts +3 -3
- package/src/shared/cli/functions/format-output.function.ts +41 -34
- package/src/shared/cli/functions/parse-args.function.ts +7 -0
- package/src/shared/cli/functions/run-search.function.ts +53 -27
- package/src/shared/cli/index.ts +4 -1
- package/src/shared/cli/typings/cli-options.interface.ts +2 -0
- package/src/shared/cli/typings/search-display.model.ts +26 -7
- package/src/shared/mcp/functions/create-tool-definitions.function.ts +64 -4
- package/src/shared/mcp/functions/handle-recall.function.ts +66 -0
- package/src/shared/mcp/functions/handle-tool-call.function.ts +11 -1
- package/src/shared/mcp/typings/mcp-client.interface.ts +33 -15
- package/src/shared/version/constants/version.constant.ts +1 -1
- package/src/shared/wasm-codec/functions/decode-recall-result.function.ts +267 -0
- package/src/shared/wasm-codec/functions/decode-scored-results.function.ts +81 -27
- package/src/shared/wasm-codec/functions/encode-recall-params.function.ts +68 -0
- package/src/shared/wasm-codec/functions/encode-search-params.function.ts +4 -1
- package/src/shared/wasm-codec/index.ts +11 -3
- package/src/shared/worker-client/classes/worker-client.class.ts +24 -4
- package/src/shared/worker-client/index.ts +11 -1
- package/src/shared/worker-client/typings/recall-result.model.ts +98 -0
- package/src/shared/worker-client/typings/search-params.model.ts +2 -0
- package/src/shared/worker-client/typings/search-result.model.ts +24 -7
- package/src/shared/worker-daemon/classes/worker-daemon.class.ts +25 -4
- package/src/wasm/fs-database/kbdb_fs_database.d.ts +18 -0
- package/src/wasm/fs-database/kbdb_fs_database.js +30 -0
- package/src/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
- package/src/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +2 -0
- package/src/wasm/kb-worker/kbdb_worker.d.ts +38 -0
- package/src/wasm/kb-worker/kbdb_worker.js +56 -0
- package/src/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
- package/src/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +3 -0
- package/src/worker.ts +8 -0
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
# cli/functions -- Command Functions
|
|
2
|
+
|
|
3
|
+
*CLI orchestrator, command dispatcher, argument parser,
|
|
4
|
+
utility helpers, and one function per CLI sub-command.*
|
|
5
|
+
|
|
6
|
+
## Source
|
|
7
|
+
|
|
8
|
+
`src/shared/cli/functions/`
|
|
9
|
+
|
|
10
|
+
## Functions
|
|
11
|
+
|
|
12
|
+
### `runCli`
|
|
13
|
+
|
|
14
|
+
**File:** `run-cli.function.ts`
|
|
15
|
+
|
|
16
|
+
Full CLI orchestrator. Parses arguments, routes to the
|
|
17
|
+
appropriate sub-flow, and returns a `CommandResult`
|
|
18
|
+
without touching process globals.
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
async function runCli(
|
|
22
|
+
argv: string[],
|
|
23
|
+
deps: CliDeps,
|
|
24
|
+
): Promise<CommandResult>;
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`CliDeps` is an injectable dependency record:
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
interface CliDeps {
|
|
31
|
+
isStdinTty: () => boolean;
|
|
32
|
+
promptUser: (question: string) => Promise<string>;
|
|
33
|
+
createWorkerClient: (opts: {
|
|
34
|
+
contextPath: string;
|
|
35
|
+
}) => Promise<DisconnectableClient>;
|
|
36
|
+
findDb: (basePath?: string) => string | null;
|
|
37
|
+
runInit: (options: CliOptions) => InitResult;
|
|
38
|
+
startMcpServer?: (contextPath: string) => Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Routes:
|
|
43
|
+
|
|
44
|
+
| Command | Handler |
|
|
45
|
+
|-------------|----------------------------------|
|
|
46
|
+
| `help` | returns `HELP_TEXT` |
|
|
47
|
+
| `version` | returns `VERSION` |
|
|
48
|
+
| `init` | calls `deps.runInit` |
|
|
49
|
+
| `mcp` | calls `deps.startMcpServer` |
|
|
50
|
+
| `migrate` | version check + migrate daemon |
|
|
51
|
+
| *(other)* | `dispatchCommand(client, opts)` |
|
|
52
|
+
|
|
53
|
+
### `dispatchCommand`
|
|
54
|
+
|
|
55
|
+
**File:** `dispatch-command.function.ts`
|
|
56
|
+
|
|
57
|
+
Routes a parsed CLI command to the appropriate handler
|
|
58
|
+
and returns a `CommandResult` without touching process
|
|
59
|
+
globals.
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
async function dispatchCommand(
|
|
63
|
+
client: DispatchClient,
|
|
64
|
+
options: CliOptions,
|
|
65
|
+
io?: LearnIO,
|
|
66
|
+
): Promise<CommandResult>;
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`DispatchClient` is the intersection of all per-command
|
|
70
|
+
client interfaces (`SearchClient & LearnClient &
|
|
71
|
+
UnlearnClient & ContentClient & CheckClient &
|
|
72
|
+
GcClient & RebuildClient & SkillClient & AgentClient`).
|
|
73
|
+
|
|
74
|
+
| Command | Handler |
|
|
75
|
+
|----------------|----------------------------------|
|
|
76
|
+
| `learn` | `runLearn(client, options, io)` |
|
|
77
|
+
| `unlearn` | `runUnlearn(client, options)` |
|
|
78
|
+
| `search` | `runSearch(client, options)` |
|
|
79
|
+
| `content` | `runContent(client, options)` |
|
|
80
|
+
| `check` | `runCheck(client, options)` |
|
|
81
|
+
| `gc` | `runGc(client, options)` |
|
|
82
|
+
| `rebuild` | `runRebuild(client, options)` |
|
|
83
|
+
| `skill-learn` | `runSkillLearn(client, options)` |
|
|
84
|
+
| `skill-list` | `runSkillList(client, options)` |
|
|
85
|
+
| `skill-get` | `runSkillGet(client, options)` |
|
|
86
|
+
| `skill-delete` | `runSkillDelete(client, options)`|
|
|
87
|
+
| `agent-create` | `runAgentCreate(client, options)`|
|
|
88
|
+
| `agent-list` | `runAgentList(client, options)` |
|
|
89
|
+
| `agent-get` | `runAgentGet(client, options)` |
|
|
90
|
+
| `agent-delete` | `runAgentDelete(client, options)`|
|
|
91
|
+
|
|
92
|
+
### `parseArgs`
|
|
93
|
+
|
|
94
|
+
**File:** `parse-args.function.ts`
|
|
95
|
+
|
|
96
|
+
Parses command-line arguments into a typed `CliOptions`
|
|
97
|
+
object. Supports both Deno (`Deno.args`) and Node.js
|
|
98
|
+
(`process.argv.slice(2)`) argument sources.
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
function parseArgs(
|
|
102
|
+
argv: string[],
|
|
103
|
+
): CliOptions;
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Throws on invalid or missing required arguments.
|
|
107
|
+
Prints help text and exits for `--help` / `--version`.
|
|
108
|
+
|
|
109
|
+
**Compound command handling**: when the first positional
|
|
110
|
+
argument is `db`, `skill`, or `agent`, the parser
|
|
111
|
+
consumes the next positional as the subcommand and sets
|
|
112
|
+
`command` to the hyphenated form:
|
|
113
|
+
|
|
114
|
+
| First positional | Second positional | `command` value |
|
|
115
|
+
|------------------|-------------------|------------------|
|
|
116
|
+
| `db` | `init` | `db-init` |
|
|
117
|
+
| `db` | `migrate` | `db-migrate` |
|
|
118
|
+
| `skill` | `learn` | `skill-learn` |
|
|
119
|
+
| `skill` | `list` | `skill-list` |
|
|
120
|
+
| `skill` | `get` | `skill-get` |
|
|
121
|
+
| `skill` | `delete` | `skill-delete` |
|
|
122
|
+
| `agent` | `create` | `agent-create` |
|
|
123
|
+
| `agent` | `list` | `agent-list` |
|
|
124
|
+
| `agent` | `get` | `agent-get` |
|
|
125
|
+
| `agent` | `delete` | `agent-delete` |
|
|
126
|
+
|
|
127
|
+
**New options parsed:**
|
|
128
|
+
|
|
129
|
+
| Flag | `CliOptions` field | Description |
|
|
130
|
+
|-----------------|--------------------|-----------------------|
|
|
131
|
+
| `--name <n>` | `name` | Skill or agent name |
|
|
132
|
+
| `--persona <p>` | `persona` | Agent persona file |
|
|
133
|
+
| `--body <b>` | `body` | Skill body file |
|
|
134
|
+
| `--skills <s>` | `skills` | Comma-separated kbids |
|
|
135
|
+
|
|
136
|
+
### `findDb`
|
|
137
|
+
|
|
138
|
+
**File:** `find-db.function.ts`
|
|
139
|
+
|
|
140
|
+
Resolves the absolute path to the `.kbdb` directory
|
|
141
|
+
under the given base path. Returns `null` when the
|
|
142
|
+
directory does not exist. Pure read-only -- never
|
|
143
|
+
creates the directory.
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
function findDb(
|
|
147
|
+
dbPath?: string,
|
|
148
|
+
): string | null;
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### `runInit`
|
|
152
|
+
|
|
153
|
+
**File:** `run-init.function.ts`
|
|
154
|
+
|
|
155
|
+
Creates the `.kbdb` directory scaffold directly on disk
|
|
156
|
+
without requiring a running worker daemon.
|
|
157
|
+
|
|
158
|
+
```ts
|
|
159
|
+
function runInit(
|
|
160
|
+
options: CliOptions,
|
|
161
|
+
): InitResult;
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
interface InitResult {
|
|
166
|
+
readonly ok: boolean;
|
|
167
|
+
readonly targetPath: string;
|
|
168
|
+
readonly errorMessage?: string;
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### `runMigrate`
|
|
173
|
+
|
|
174
|
+
**File:** `run-migrate.function.ts`
|
|
175
|
+
|
|
176
|
+
Checks the database version and runs pending migrations
|
|
177
|
+
when needed.
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
async function runMigrate(
|
|
181
|
+
client: MigrateClient,
|
|
182
|
+
options: CliOptions,
|
|
183
|
+
): Promise<MigrateCommandResult>;
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
```ts
|
|
187
|
+
interface MigrateCommandResult {
|
|
188
|
+
readonly status: VersionCompatibility;
|
|
189
|
+
readonly versionStatus: VersionStatus;
|
|
190
|
+
readonly migrateResult?: MigrateResult;
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Resolution order:
|
|
195
|
+
|
|
196
|
+
| Version status | Action |
|
|
197
|
+
|-------------------|-------------------------------------|
|
|
198
|
+
| `compatible` | returns without running migrations |
|
|
199
|
+
| `needs_migration` | calls `client.migrateDatabase` |
|
|
200
|
+
| `too_new` | returns without running migrations |
|
|
201
|
+
|
|
202
|
+
### `runLearn`
|
|
203
|
+
|
|
204
|
+
**File:** `run-learn.function.ts`
|
|
205
|
+
|
|
206
|
+
Imports and indexes documents into the knowledge base.
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
async function runLearn(
|
|
210
|
+
client: LearnClient,
|
|
211
|
+
options: CliOptions,
|
|
212
|
+
io?: LearnIO,
|
|
213
|
+
): Promise<LearnResult[]>;
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
- If input is a **directory**: recursively scans for
|
|
217
|
+
supported text files (`.md`, `.txt`, `.rst`,
|
|
218
|
+
`.adoc`). Image files are silently skipped during
|
|
219
|
+
directory scans. Computes content hash for each,
|
|
220
|
+
skips duplicates, calls `client.addSection()` per
|
|
221
|
+
file.
|
|
222
|
+
- If input is a **text file**: adds that single file.
|
|
223
|
+
`--title` and `--description` are optional.
|
|
224
|
+
- If input is **stdin** (`-`): reads `text/markdown`.
|
|
225
|
+
- Returns a `LearnResult[]` with one record per file
|
|
226
|
+
processed.
|
|
227
|
+
|
|
228
|
+
### `runUnlearn`
|
|
229
|
+
|
|
230
|
+
**File:** `run-unlearn.function.ts`
|
|
231
|
+
|
|
232
|
+
Removes knowledge base contents by KB ID.
|
|
233
|
+
|
|
234
|
+
```ts
|
|
235
|
+
async function runUnlearn(
|
|
236
|
+
client: UnlearnClient,
|
|
237
|
+
options: CliOptions,
|
|
238
|
+
): Promise<unknown>;
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Accepts a list of KB IDs from `options.args`. Calls
|
|
242
|
+
`client.removeSection()` for each.
|
|
243
|
+
|
|
244
|
+
### `runSearch`
|
|
245
|
+
|
|
246
|
+
**File:** `run-search.function.ts`
|
|
247
|
+
|
|
248
|
+
Searches the knowledge base by query string.
|
|
249
|
+
|
|
250
|
+
```ts
|
|
251
|
+
async function runSearch(
|
|
252
|
+
client: SearchClient,
|
|
253
|
+
options: CliOptions,
|
|
254
|
+
): Promise<SearchDisplay[]>;
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Calls `client.search()` with the query, mode, and
|
|
258
|
+
limit from options. Returns `SearchDisplay[]` for
|
|
259
|
+
use by `dispatchCommand`.
|
|
260
|
+
|
|
261
|
+
### `runContent`
|
|
262
|
+
|
|
263
|
+
**File:** `run-content.function.ts`
|
|
264
|
+
|
|
265
|
+
Composes and outputs a rendered Markdown document from
|
|
266
|
+
one or more kbid or docid identifiers.
|
|
267
|
+
|
|
268
|
+
```ts
|
|
269
|
+
async function runContent(
|
|
270
|
+
client: ContentClient,
|
|
271
|
+
options: CliOptions,
|
|
272
|
+
): Promise<unknown>;
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
Takes identifiers from `options.args`. Calls
|
|
276
|
+
`client.content(ids)`.
|
|
277
|
+
|
|
278
|
+
### `runCheck`
|
|
279
|
+
|
|
280
|
+
**File:** `run-check.function.ts`
|
|
281
|
+
|
|
282
|
+
Runs an integrity check on the database.
|
|
283
|
+
|
|
284
|
+
```ts
|
|
285
|
+
async function runCheck(
|
|
286
|
+
client: CheckClient,
|
|
287
|
+
options: CliOptions,
|
|
288
|
+
): Promise<{ ok: boolean }>;
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
Calls `client.integrityCheck()`.
|
|
292
|
+
|
|
293
|
+
### `runGc`
|
|
294
|
+
|
|
295
|
+
**File:** `run-gc.function.ts`
|
|
296
|
+
|
|
297
|
+
Runs garbage collection on the database.
|
|
298
|
+
|
|
299
|
+
```ts
|
|
300
|
+
async function runGc(
|
|
301
|
+
client: GcClient,
|
|
302
|
+
options: CliOptions,
|
|
303
|
+
): Promise<unknown>;
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
Calls `client.gc()`.
|
|
307
|
+
|
|
308
|
+
### `runRebuild`
|
|
309
|
+
|
|
310
|
+
**File:** `run-rebuild.function.ts`
|
|
311
|
+
|
|
312
|
+
Rebuilds all indexes from sections and documents.
|
|
313
|
+
|
|
314
|
+
```ts
|
|
315
|
+
async function runRebuild(
|
|
316
|
+
client: RebuildClient,
|
|
317
|
+
options: CliOptions,
|
|
318
|
+
): Promise<unknown>;
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
Calls `client.rebuildIndexes()`.
|
|
322
|
+
|
|
323
|
+
### `ensureDb`
|
|
324
|
+
|
|
325
|
+
**File:** `ensure-db.function.ts`
|
|
326
|
+
|
|
327
|
+
Ensures the database directory exists, prompting the
|
|
328
|
+
user if stdin is a TTY or failing if stdin is piped.
|
|
329
|
+
|
|
330
|
+
```ts
|
|
331
|
+
async function ensureDb(
|
|
332
|
+
dbPath: string,
|
|
333
|
+
): Promise<void>;
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
### `formatOutput`
|
|
337
|
+
|
|
338
|
+
**File:** `format-output.function.ts`
|
|
339
|
+
|
|
340
|
+
Formats a result object for the selected output format.
|
|
341
|
+
|
|
342
|
+
```ts
|
|
343
|
+
function formatOutput(
|
|
344
|
+
result: unknown,
|
|
345
|
+
format: OutputFormat,
|
|
346
|
+
): string;
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
| Format | Output |
|
|
350
|
+
|--------|-----------------------------|
|
|
351
|
+
| `json` | JSON string (default) |
|
|
352
|
+
| `text` | Human-readable list |
|
|
353
|
+
| `mcp` | MCP tool result format |
|
|
354
|
+
|
|
355
|
+
### `errorToMessage`
|
|
356
|
+
|
|
357
|
+
**File:** `error-to-message.function.ts`
|
|
358
|
+
|
|
359
|
+
Converts an unknown thrown value to a human-readable
|
|
360
|
+
message.
|
|
361
|
+
|
|
362
|
+
```ts
|
|
363
|
+
function errorToMessage(
|
|
364
|
+
err: unknown,
|
|
365
|
+
): string;
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
Returns `err.message` for `Error` instances, or
|
|
369
|
+
`String(err)` for all other values.
|
|
370
|
+
|
|
371
|
+
### `isStdinTty`
|
|
372
|
+
|
|
373
|
+
**File:** `is-stdin-tty.function.ts`
|
|
374
|
+
|
|
375
|
+
Returns `true` when stdin is an interactive terminal.
|
|
376
|
+
|
|
377
|
+
```ts
|
|
378
|
+
function isStdinTty(
|
|
379
|
+
stdin?: NodeJS.ReadStream,
|
|
380
|
+
): boolean;
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
`stdin` defaults to `process.stdin`.
|
|
384
|
+
|
|
385
|
+
### `promptUser`
|
|
386
|
+
|
|
387
|
+
**File:** `prompt-user.function.ts`
|
|
388
|
+
|
|
389
|
+
Prompts the user on stdin (TTY only) and returns the
|
|
390
|
+
trimmed reply.
|
|
391
|
+
|
|
392
|
+
```ts
|
|
393
|
+
async function promptUser(
|
|
394
|
+
question: string,
|
|
395
|
+
io?: PromptIO,
|
|
396
|
+
): Promise<string>;
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
`io` is an injectable interface for testing:
|
|
400
|
+
|
|
401
|
+
```ts
|
|
402
|
+
interface PromptIO {
|
|
403
|
+
ask: (question: string) => Promise<string>;
|
|
404
|
+
}
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
Defaults to readline on `process.stdin`/`process.stdout`.
|
|
408
|
+
|
|
409
|
+
### `runDbInit`
|
|
410
|
+
|
|
411
|
+
**File:** `run-db-init.function.ts`
|
|
412
|
+
|
|
413
|
+
Creates the `.kbdb` directory scaffold directly on disk
|
|
414
|
+
without requiring a running worker daemon. Replaces
|
|
415
|
+
the deprecated `runInit` for the `kbdb db init`
|
|
416
|
+
subcommand.
|
|
417
|
+
|
|
418
|
+
```ts
|
|
419
|
+
async function runDbInit(
|
|
420
|
+
options: CliOptions,
|
|
421
|
+
): Promise<CommandResult>;
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
Output on success: JSON `{ "path": "...", "created": true }`.
|
|
425
|
+
|
|
426
|
+
### `runDbMigrate`
|
|
427
|
+
|
|
428
|
+
**File:** `run-db-migrate.function.ts`
|
|
429
|
+
|
|
430
|
+
Checks the database version and runs pending migrations
|
|
431
|
+
when needed. Successor to the deprecated `runMigrate`
|
|
432
|
+
for the `kbdb db migrate` subcommand.
|
|
433
|
+
|
|
434
|
+
```ts
|
|
435
|
+
async function runDbMigrate(
|
|
436
|
+
client: MigrateClient,
|
|
437
|
+
options: CliOptions,
|
|
438
|
+
): Promise<CommandResult>;
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
Calls `client.migrateDatabase(dbDir)` after resolving
|
|
442
|
+
the database directory from options.
|
|
443
|
+
|
|
444
|
+
### `runSkillLearn`
|
|
445
|
+
|
|
446
|
+
**File:** `run-skill-learn.function.ts`
|
|
447
|
+
|
|
448
|
+
Creates a new skill definition in the knowledge base.
|
|
449
|
+
Reads the skill body from the file path in
|
|
450
|
+
`options.body` (or stdin when `options.body` is `-`),
|
|
451
|
+
constructs the skill JSON, and adds it as a section
|
|
452
|
+
with `sectionType: 'skill'`.
|
|
453
|
+
|
|
454
|
+
```ts
|
|
455
|
+
async function runSkillLearn(
|
|
456
|
+
client: SkillLearnClient,
|
|
457
|
+
options: CliOptions,
|
|
458
|
+
): Promise<CommandResult>;
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
| Parameter | Source | Required |
|
|
462
|
+
|-------------------|-----------------|----------|
|
|
463
|
+
| `options.name` | `--name` | yes |
|
|
464
|
+
| `options.body` | `--body` | yes |
|
|
465
|
+
| `options.description` | `--description` | no |
|
|
466
|
+
|
|
467
|
+
Output: JSON `{ "kbid": "...", "name": "...",
|
|
468
|
+
"arguments": ["argName", ...] }`.
|
|
469
|
+
|
|
470
|
+
### `runSkillList`
|
|
471
|
+
|
|
472
|
+
**File:** `run-skill-list.function.ts`
|
|
473
|
+
|
|
474
|
+
Lists all skill sections stored in the knowledge base.
|
|
475
|
+
|
|
476
|
+
```ts
|
|
477
|
+
async function runSkillList(
|
|
478
|
+
client: SkillListClient,
|
|
479
|
+
options: CliOptions,
|
|
480
|
+
): Promise<CommandResult>;
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
Calls `client.listByType('skill')`. Output: JSON array
|
|
484
|
+
of `{ kbid, name, description, argumentCount }`.
|
|
485
|
+
|
|
486
|
+
### `runSkillGet`
|
|
487
|
+
|
|
488
|
+
**File:** `run-skill-get.function.ts`
|
|
489
|
+
|
|
490
|
+
Retrieves a single skill by name or kbid.
|
|
491
|
+
|
|
492
|
+
```ts
|
|
493
|
+
async function runSkillGet(
|
|
494
|
+
client: SkillGetClient,
|
|
495
|
+
options: CliOptions,
|
|
496
|
+
): Promise<CommandResult>;
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
The name-or-kbid argument is taken from `options.args[0]`.
|
|
500
|
+
Output: JSON `SkillDefinition` with `kbid` field.
|
|
501
|
+
|
|
502
|
+
### `runSkillDelete`
|
|
503
|
+
|
|
504
|
+
**File:** `run-skill-delete.function.ts`
|
|
505
|
+
|
|
506
|
+
Removes a skill section from the knowledge base.
|
|
507
|
+
|
|
508
|
+
```ts
|
|
509
|
+
async function runSkillDelete(
|
|
510
|
+
client: SkillDeleteClient,
|
|
511
|
+
options: CliOptions,
|
|
512
|
+
): Promise<CommandResult>;
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
The kbid argument is taken from `options.args[0]`.
|
|
516
|
+
Calls `client.removeSection(kbid)`. Output: JSON
|
|
517
|
+
`{ "kbid": "...", "removed": true }`.
|
|
518
|
+
|
|
519
|
+
### `runAgentCreate`
|
|
520
|
+
|
|
521
|
+
**File:** `run-agent-create.function.ts`
|
|
522
|
+
|
|
523
|
+
Creates a new agent document with a persona and
|
|
524
|
+
ordered skill references. Reads the persona from the
|
|
525
|
+
file path in `options.persona` (or stdin when `-`),
|
|
526
|
+
validates the skill kbids from `options.skills`, and
|
|
527
|
+
creates the agent document manifest.
|
|
528
|
+
|
|
529
|
+
```ts
|
|
530
|
+
async function runAgentCreate(
|
|
531
|
+
client: AgentCreateClient,
|
|
532
|
+
options: CliOptions,
|
|
533
|
+
): Promise<CommandResult>;
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
| Parameter | Source | Required |
|
|
537
|
+
|---------------------|-------------|----------|
|
|
538
|
+
| `options.name` | `--name` | yes |
|
|
539
|
+
| `options.persona` | `--persona` | yes |
|
|
540
|
+
| `options.skills` | `--skills` | yes |
|
|
541
|
+
| `options.description` | `--description` | no |
|
|
542
|
+
|
|
543
|
+
Output: JSON `{ "docid": "agent-...", "name": "...",
|
|
544
|
+
"skills": [...] }`.
|
|
545
|
+
|
|
546
|
+
### `runAgentList`
|
|
547
|
+
|
|
548
|
+
**File:** `run-agent-list.function.ts`
|
|
549
|
+
|
|
550
|
+
Lists all agent documents stored in the knowledge base.
|
|
551
|
+
|
|
552
|
+
```ts
|
|
553
|
+
async function runAgentList(
|
|
554
|
+
client: AgentListClient,
|
|
555
|
+
options: CliOptions,
|
|
556
|
+
): Promise<CommandResult>;
|
|
557
|
+
```
|
|
558
|
+
|
|
559
|
+
Calls `client.listDocumentsByType('agent')`. Output:
|
|
560
|
+
JSON array of `{ docid, name, description, skillCount }`.
|
|
561
|
+
|
|
562
|
+
### `runAgentGet`
|
|
563
|
+
|
|
564
|
+
**File:** `run-agent-get.function.ts`
|
|
565
|
+
|
|
566
|
+
Retrieves a single agent by document ID, with resolved
|
|
567
|
+
skill definitions.
|
|
568
|
+
|
|
569
|
+
```ts
|
|
570
|
+
async function runAgentGet(
|
|
571
|
+
client: AgentGetClient,
|
|
572
|
+
options: CliOptions,
|
|
573
|
+
): Promise<CommandResult>;
|
|
574
|
+
```
|
|
575
|
+
|
|
576
|
+
The docid argument is taken from `options.args[0]`.
|
|
577
|
+
Output: JSON `AgentDefinition` with resolved skills.
|
|
578
|
+
|
|
579
|
+
### `runAgentDelete`
|
|
580
|
+
|
|
581
|
+
**File:** `run-agent-delete.function.ts`
|
|
582
|
+
|
|
583
|
+
Removes an agent document manifest. The skill sections
|
|
584
|
+
referenced by the agent are not deleted.
|
|
585
|
+
|
|
586
|
+
```ts
|
|
587
|
+
async function runAgentDelete(
|
|
588
|
+
client: AgentDeleteClient,
|
|
589
|
+
options: CliOptions,
|
|
590
|
+
): Promise<CommandResult>;
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
The docid argument is taken from `options.args[0]`.
|
|
594
|
+
Output: JSON `{ "docid": "...", "removed": true }`.
|
|
595
|
+
|
|
596
|
+
## Testing
|
|
597
|
+
|
|
598
|
+
Each function has a `.spec.ts` at the module root:
|
|
599
|
+
|
|
600
|
+
```
|
|
601
|
+
src/shared/cli/
|
|
602
|
+
├── run-cli.spec.ts
|
|
603
|
+
├── dispatch-command.spec.ts
|
|
604
|
+
├── parse-args.spec.ts
|
|
605
|
+
├── find-db.spec.ts
|
|
606
|
+
├── run-init.spec.ts
|
|
607
|
+
├── run-migrate.spec.ts
|
|
608
|
+
├── run-db-init.spec.ts
|
|
609
|
+
├── run-db-migrate.spec.ts
|
|
610
|
+
├── run-learn.spec.ts
|
|
611
|
+
├── run-unlearn.spec.ts
|
|
612
|
+
├── run-search.spec.ts
|
|
613
|
+
├── run-content.spec.ts
|
|
614
|
+
├── run-check.spec.ts
|
|
615
|
+
├── run-gc.spec.ts
|
|
616
|
+
├── run-rebuild.spec.ts
|
|
617
|
+
├── run-skill-learn.spec.ts
|
|
618
|
+
├── run-skill-list.spec.ts
|
|
619
|
+
├── run-skill-get.spec.ts
|
|
620
|
+
├── run-skill-delete.spec.ts
|
|
621
|
+
├── run-agent-create.spec.ts
|
|
622
|
+
├── run-agent-list.spec.ts
|
|
623
|
+
├── run-agent-get.spec.ts
|
|
624
|
+
├── run-agent-delete.spec.ts
|
|
625
|
+
├── ensure-db.spec.ts
|
|
626
|
+
├── format-output.spec.ts
|
|
627
|
+
├── error-to-message.spec.ts
|
|
628
|
+
├── is-stdin-tty.spec.ts
|
|
629
|
+
└── prompt-user.spec.ts
|
|
630
|
+
```
|