@dikolab/kbdb 0.1.5 → 0.2.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 +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.mjs +13 -2
- package/dist/mod.mjs.map +2 -2
- 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/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/package.json +8 -2
- 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/README.md
CHANGED
|
@@ -88,22 +88,40 @@ search index.
|
|
|
88
88
|
kbdb search "how does auth work" --db ./my-kb
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
Results are ranked by relevance
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
Results are ranked by relevance with snippets
|
|
92
|
+
showing matched terms in context. Use `--offset`
|
|
93
|
+
to page through large result sets.
|
|
94
|
+
|
|
95
|
+
**4. Recall context**
|
|
96
|
+
|
|
97
|
+
```sh
|
|
98
|
+
kbdb recall <kbid> --depth 1 --db ./my-kb
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Start with a search result's kbid and expand
|
|
102
|
+
context progressively: depth 0 gives the section
|
|
103
|
+
content, depth 1 adds parent documents and
|
|
104
|
+
back-references, depth 2 adds siblings and forward
|
|
105
|
+
references, depth 3 includes full text of
|
|
106
|
+
referenced sections.
|
|
94
107
|
|
|
95
108
|
---
|
|
96
109
|
|
|
97
110
|
## What Can It Do?
|
|
98
111
|
|
|
99
112
|
- **Import** Markdown files and other documents
|
|
100
|
-
- **Search** with ranked results and
|
|
101
|
-
|
|
113
|
+
- **Search** with ranked results, snippets, and
|
|
114
|
+
paginated output
|
|
115
|
+
- **Recall** sections with progressive context --
|
|
116
|
+
from a quick summary to full related content
|
|
117
|
+
- **Skills** -- store reusable prompt templates
|
|
118
|
+
with placeholder arguments
|
|
119
|
+
- **Agents** -- create AI agent profiles that
|
|
120
|
+
combine a persona with skills
|
|
102
121
|
- **Manage** documents, sections, and metadata
|
|
103
122
|
- **Verify** database integrity and clean up
|
|
104
123
|
unused data
|
|
105
124
|
- **Rebuild** indexes if anything goes wrong
|
|
106
|
-
- **Check status** of your knowledge base
|
|
107
125
|
|
|
108
126
|
See the [CLI Reference](docs/details/cli.md)
|
|
109
127
|
for the full command list and examples.
|
|
@@ -113,8 +131,9 @@ for the full command list and examples.
|
|
|
113
131
|
## Use It With AI Agents
|
|
114
132
|
|
|
115
133
|
kbdb runs as an
|
|
116
|
-
[MCP](https://modelcontextprotocol.io/) server
|
|
117
|
-
so AI agents can search your docs,
|
|
134
|
+
[MCP](https://modelcontextprotocol.io/) server
|
|
135
|
+
with 18 tools, so AI agents can search your docs,
|
|
136
|
+
recall context progressively, store reusable
|
|
118
137
|
skills, and build agent profiles -- a second brain
|
|
119
138
|
that persists between sessions.
|
|
120
139
|
|
|
@@ -208,9 +227,11 @@ const client = await createWorkerClient({
|
|
|
208
227
|
const results = await client.search({
|
|
209
228
|
query: 'authentication',
|
|
210
229
|
limit: 10,
|
|
230
|
+
offset: 0,
|
|
211
231
|
});
|
|
212
232
|
|
|
213
|
-
|
|
233
|
+
// results = { items, total, offset, limit, has_more }
|
|
234
|
+
console.log(results.items);
|
|
214
235
|
client.disconnect();
|
|
215
236
|
```
|
|
216
237
|
|
package/dist/cli.cjs
CHANGED
|
@@ -118,6 +118,13 @@ function parseArgs(argv) {
|
|
|
118
118
|
case "-l":
|
|
119
119
|
options.limit = parseInt(argv[++i] ?? "", 10) || DEFAULT_LIMIT;
|
|
120
120
|
break;
|
|
121
|
+
case "--offset":
|
|
122
|
+
case "-o":
|
|
123
|
+
options.offset = Math.max(
|
|
124
|
+
0,
|
|
125
|
+
parseInt(argv[++i] ?? "", 10) || 0
|
|
126
|
+
);
|
|
127
|
+
break;
|
|
121
128
|
case "--title":
|
|
122
129
|
options.title = argv[++i];
|
|
123
130
|
break;
|
|
@@ -158,29 +165,39 @@ function parseArgs(argv) {
|
|
|
158
165
|
}
|
|
159
166
|
|
|
160
167
|
// src/shared/cli/functions/format-output.function.ts
|
|
161
|
-
function formatOutput(
|
|
168
|
+
function formatOutput(paged, format) {
|
|
162
169
|
switch (format) {
|
|
163
170
|
case "json":
|
|
164
|
-
return JSON.stringify(
|
|
171
|
+
return JSON.stringify(paged, null, 2);
|
|
165
172
|
case "text":
|
|
166
|
-
return formatText(
|
|
173
|
+
return formatText(paged);
|
|
167
174
|
case "mcp":
|
|
168
|
-
return formatMcp(
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
function formatText(
|
|
172
|
-
if (
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
175
|
+
return formatMcp(paged);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function formatText(paged) {
|
|
179
|
+
if (paged.items.length === 0) return "No results found.";
|
|
180
|
+
const start = paged.offset + 1;
|
|
181
|
+
const end = paged.offset + paged.items.length;
|
|
182
|
+
const lines = paged.items.map((r, i) => {
|
|
183
|
+
const num = paged.offset + i + 1;
|
|
184
|
+
const heading = r.heading ?? "(untitled)";
|
|
185
|
+
const terms = r.matched_terms.join(", ");
|
|
186
|
+
return `${String(num)}. [${r.kbid}] ${heading} (score: ${r.score.toFixed(4)})
|
|
187
|
+
${r.snippet || r.preview || "(no snippet)"}
|
|
188
|
+
type: ${r.type} terms: ${terms}`;
|
|
189
|
+
}).join("\n\n");
|
|
190
|
+
const footer = `
|
|
191
|
+
Showing ${String(start)}-${String(end)} of ${String(paged.total)} results`;
|
|
192
|
+
const hint = paged.has_more ? `
|
|
193
|
+
Use --offset ${String(end)} to see more` : "";
|
|
194
|
+
return lines + footer + hint;
|
|
195
|
+
}
|
|
196
|
+
function formatMcp(paged) {
|
|
180
197
|
return JSON.stringify({
|
|
181
198
|
type: "text",
|
|
182
|
-
text:
|
|
183
|
-
(r) => `[${r.kbid}]
|
|
199
|
+
text: paged.items.map(
|
|
200
|
+
(r) => `[${r.kbid}] ${r.heading ?? "(untitled)"} \u2014 ${r.snippet || r.preview}`
|
|
184
201
|
).join("\n")
|
|
185
202
|
});
|
|
186
203
|
}
|
|
@@ -188,18 +205,37 @@ function formatMcp(results) {
|
|
|
188
205
|
// src/shared/cli/functions/run-search.function.ts
|
|
189
206
|
async function runSearch(client, options) {
|
|
190
207
|
const query = options.args.join(" ").trim();
|
|
191
|
-
if (!query)
|
|
208
|
+
if (!query) {
|
|
209
|
+
return {
|
|
210
|
+
items: [],
|
|
211
|
+
total: 0,
|
|
212
|
+
offset: 0,
|
|
213
|
+
limit: options.limit,
|
|
214
|
+
has_more: false
|
|
215
|
+
};
|
|
216
|
+
}
|
|
192
217
|
const results = await client.search({
|
|
193
218
|
query,
|
|
194
219
|
mode: options.mode,
|
|
195
|
-
limit: options.limit
|
|
220
|
+
limit: options.limit,
|
|
221
|
+
offset: options.offset
|
|
196
222
|
});
|
|
197
|
-
return
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
223
|
+
return {
|
|
224
|
+
items: results.items.map((r) => ({
|
|
225
|
+
kbid: r.kbid,
|
|
226
|
+
heading: r.heading,
|
|
227
|
+
type: r.type,
|
|
228
|
+
docids: r.docids,
|
|
229
|
+
score: r.score,
|
|
230
|
+
snippet: r.snippet,
|
|
231
|
+
matched_terms: r.matched_terms,
|
|
232
|
+
preview: ""
|
|
233
|
+
})),
|
|
234
|
+
total: results.total,
|
|
235
|
+
offset: results.offset,
|
|
236
|
+
limit: results.limit,
|
|
237
|
+
has_more: results.has_more
|
|
238
|
+
};
|
|
203
239
|
}
|
|
204
240
|
|
|
205
241
|
// src/shared/cli/functions/run-learn.function.ts
|
|
@@ -919,9 +955,9 @@ async function handleDbMigrate(client, options) {
|
|
|
919
955
|
};
|
|
920
956
|
}
|
|
921
957
|
}
|
|
922
|
-
async function hydrateSearchPreviews(client,
|
|
958
|
+
async function hydrateSearchPreviews(client, paged) {
|
|
923
959
|
await Promise.all(
|
|
924
|
-
|
|
960
|
+
paged.items.map(async (result) => {
|
|
925
961
|
try {
|
|
926
962
|
const contentResult = await client.content([result.kbid]);
|
|
927
963
|
result.preview = contentResult.data;
|
|
@@ -932,7 +968,7 @@ async function hydrateSearchPreviews(client, results) {
|
|
|
932
968
|
}
|
|
933
969
|
|
|
934
970
|
// src/shared/version/constants/version.constant.ts
|
|
935
|
-
var VERSION = "0.
|
|
971
|
+
var VERSION = "0.2.0";
|
|
936
972
|
|
|
937
973
|
// src/shared/cli/functions/generate-help.function.ts
|
|
938
974
|
var KNOWN_COMMANDS = /* @__PURE__ */ new Set([
|
|
@@ -1641,11 +1677,22 @@ var WorkerClient = class {
|
|
|
1641
1677
|
* Searches the knowledge base.
|
|
1642
1678
|
*
|
|
1643
1679
|
* @param params - query parameters including the search string
|
|
1644
|
-
* @returns
|
|
1680
|
+
* @returns paginated search results with metadata
|
|
1645
1681
|
*/
|
|
1646
1682
|
async search(params) {
|
|
1647
1683
|
return this.call("search", params);
|
|
1648
1684
|
}
|
|
1685
|
+
/**
|
|
1686
|
+
* Retrieves full content and context for one or more sections by
|
|
1687
|
+
* their knowledge-base identifiers.
|
|
1688
|
+
*
|
|
1689
|
+
* @param params - section identifier(s) and optional expansion depth
|
|
1690
|
+
* @returns a single `RecallResult` when `kbid` is provided without
|
|
1691
|
+
* `kbids`, or a `RecallResult[]` when `kbids` is provided
|
|
1692
|
+
*/
|
|
1693
|
+
async recall(params) {
|
|
1694
|
+
return this.call("recall", params);
|
|
1695
|
+
}
|
|
1649
1696
|
/**
|
|
1650
1697
|
* Adds a new section to the knowledge base.
|
|
1651
1698
|
*
|
|
@@ -2088,7 +2135,7 @@ function createToolDefinitions() {
|
|
|
2088
2135
|
return [
|
|
2089
2136
|
{
|
|
2090
2137
|
name: "search",
|
|
2091
|
-
description: "Search the knowledge base for
|
|
2138
|
+
description: "Search the knowledge base. Returns ranked results with headings and snippets for relevance evaluation. Use `recall` to get full content of specific results.",
|
|
2092
2139
|
inputSchema: {
|
|
2093
2140
|
type: "object",
|
|
2094
2141
|
properties: {
|
|
@@ -2104,6 +2151,10 @@ function createToolDefinitions() {
|
|
|
2104
2151
|
limit: {
|
|
2105
2152
|
type: "number",
|
|
2106
2153
|
description: "Maximum results (default: 20)"
|
|
2154
|
+
},
|
|
2155
|
+
offset: {
|
|
2156
|
+
type: "number",
|
|
2157
|
+
description: "Number of results to skip for pagination (default: 0)"
|
|
2107
2158
|
}
|
|
2108
2159
|
},
|
|
2109
2160
|
required: ["query"]
|
|
@@ -2112,7 +2163,8 @@ function createToolDefinitions() {
|
|
|
2112
2163
|
title: "Search KB",
|
|
2113
2164
|
readOnlyHint: true,
|
|
2114
2165
|
destructiveHint: false,
|
|
2115
|
-
idempotentHint: true
|
|
2166
|
+
idempotentHint: true,
|
|
2167
|
+
openWorldHint: false
|
|
2116
2168
|
}
|
|
2117
2169
|
},
|
|
2118
2170
|
{
|
|
@@ -2148,7 +2200,8 @@ function createToolDefinitions() {
|
|
|
2148
2200
|
title: "Import Content",
|
|
2149
2201
|
readOnlyHint: false,
|
|
2150
2202
|
destructiveHint: false,
|
|
2151
|
-
idempotentHint: true
|
|
2203
|
+
idempotentHint: true,
|
|
2204
|
+
openWorldHint: false
|
|
2152
2205
|
}
|
|
2153
2206
|
},
|
|
2154
2207
|
{
|
|
@@ -2168,12 +2221,13 @@ function createToolDefinitions() {
|
|
|
2168
2221
|
title: "Remove Section",
|
|
2169
2222
|
readOnlyHint: false,
|
|
2170
2223
|
destructiveHint: true,
|
|
2171
|
-
idempotentHint: true
|
|
2224
|
+
idempotentHint: true,
|
|
2225
|
+
openWorldHint: false
|
|
2172
2226
|
}
|
|
2173
2227
|
},
|
|
2174
2228
|
{
|
|
2175
2229
|
name: "retrieve",
|
|
2176
|
-
description: "
|
|
2230
|
+
description: "Low-level fetch of a section or document by identifier. For AI agent workflows, prefer `recall` which includes metadata, context, and back-references.",
|
|
2177
2231
|
inputSchema: {
|
|
2178
2232
|
type: "object",
|
|
2179
2233
|
properties: {
|
|
@@ -2191,7 +2245,37 @@ function createToolDefinitions() {
|
|
|
2191
2245
|
title: "Fetch Content",
|
|
2192
2246
|
readOnlyHint: true,
|
|
2193
2247
|
destructiveHint: false,
|
|
2194
|
-
idempotentHint: true
|
|
2248
|
+
idempotentHint: true,
|
|
2249
|
+
openWorldHint: false
|
|
2250
|
+
}
|
|
2251
|
+
},
|
|
2252
|
+
{
|
|
2253
|
+
name: "recall",
|
|
2254
|
+
description: "Retrieve full content and context for sections by identifier. Use after search to read relevant results. Returns section text, metadata, references, and back-references.",
|
|
2255
|
+
inputSchema: {
|
|
2256
|
+
type: "object",
|
|
2257
|
+
properties: {
|
|
2258
|
+
kbid: {
|
|
2259
|
+
type: "string",
|
|
2260
|
+
description: "Single section identifier"
|
|
2261
|
+
},
|
|
2262
|
+
kbids: {
|
|
2263
|
+
type: "array",
|
|
2264
|
+
items: { type: "string" },
|
|
2265
|
+
description: "Batch section identifiers"
|
|
2266
|
+
},
|
|
2267
|
+
depth: {
|
|
2268
|
+
type: "number",
|
|
2269
|
+
description: "Expansion depth (0-3, default: 0)"
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
},
|
|
2273
|
+
annotations: {
|
|
2274
|
+
title: "Recall Context",
|
|
2275
|
+
readOnlyHint: true,
|
|
2276
|
+
destructiveHint: false,
|
|
2277
|
+
idempotentHint: true,
|
|
2278
|
+
openWorldHint: false
|
|
2195
2279
|
}
|
|
2196
2280
|
},
|
|
2197
2281
|
{
|
|
@@ -2205,7 +2289,8 @@ function createToolDefinitions() {
|
|
|
2205
2289
|
title: "DB Status",
|
|
2206
2290
|
readOnlyHint: true,
|
|
2207
2291
|
destructiveHint: false,
|
|
2208
|
-
idempotentHint: true
|
|
2292
|
+
idempotentHint: true,
|
|
2293
|
+
openWorldHint: false
|
|
2209
2294
|
}
|
|
2210
2295
|
},
|
|
2211
2296
|
{
|
|
@@ -2226,7 +2311,8 @@ function createToolDefinitions() {
|
|
|
2226
2311
|
title: "Compose Content",
|
|
2227
2312
|
readOnlyHint: true,
|
|
2228
2313
|
destructiveHint: false,
|
|
2229
|
-
idempotentHint: true
|
|
2314
|
+
idempotentHint: true,
|
|
2315
|
+
openWorldHint: false
|
|
2230
2316
|
}
|
|
2231
2317
|
},
|
|
2232
2318
|
{
|
|
@@ -2240,7 +2326,8 @@ function createToolDefinitions() {
|
|
|
2240
2326
|
title: "Integrity Check",
|
|
2241
2327
|
readOnlyHint: true,
|
|
2242
2328
|
destructiveHint: false,
|
|
2243
|
-
idempotentHint: true
|
|
2329
|
+
idempotentHint: true,
|
|
2330
|
+
openWorldHint: false
|
|
2244
2331
|
}
|
|
2245
2332
|
},
|
|
2246
2333
|
{
|
|
@@ -2254,7 +2341,8 @@ function createToolDefinitions() {
|
|
|
2254
2341
|
title: "Garbage Collect",
|
|
2255
2342
|
readOnlyHint: false,
|
|
2256
2343
|
destructiveHint: true,
|
|
2257
|
-
idempotentHint: false
|
|
2344
|
+
idempotentHint: false,
|
|
2345
|
+
openWorldHint: false
|
|
2258
2346
|
}
|
|
2259
2347
|
},
|
|
2260
2348
|
{
|
|
@@ -2268,7 +2356,8 @@ function createToolDefinitions() {
|
|
|
2268
2356
|
title: "Rebuild Indexes",
|
|
2269
2357
|
readOnlyHint: false,
|
|
2270
2358
|
destructiveHint: false,
|
|
2271
|
-
idempotentHint: false
|
|
2359
|
+
idempotentHint: false,
|
|
2360
|
+
openWorldHint: false
|
|
2272
2361
|
}
|
|
2273
2362
|
},
|
|
2274
2363
|
{
|
|
@@ -2296,7 +2385,8 @@ function createToolDefinitions() {
|
|
|
2296
2385
|
title: "Create Skill",
|
|
2297
2386
|
readOnlyHint: false,
|
|
2298
2387
|
destructiveHint: false,
|
|
2299
|
-
idempotentHint: true
|
|
2388
|
+
idempotentHint: true,
|
|
2389
|
+
openWorldHint: false
|
|
2300
2390
|
}
|
|
2301
2391
|
},
|
|
2302
2392
|
{
|
|
@@ -2310,7 +2400,8 @@ function createToolDefinitions() {
|
|
|
2310
2400
|
title: "List Skills",
|
|
2311
2401
|
readOnlyHint: true,
|
|
2312
2402
|
destructiveHint: false,
|
|
2313
|
-
idempotentHint: true
|
|
2403
|
+
idempotentHint: true,
|
|
2404
|
+
openWorldHint: false
|
|
2314
2405
|
}
|
|
2315
2406
|
},
|
|
2316
2407
|
{
|
|
@@ -2333,7 +2424,8 @@ function createToolDefinitions() {
|
|
|
2333
2424
|
title: "Get Skill",
|
|
2334
2425
|
readOnlyHint: true,
|
|
2335
2426
|
destructiveHint: false,
|
|
2336
|
-
idempotentHint: true
|
|
2427
|
+
idempotentHint: true,
|
|
2428
|
+
openWorldHint: false
|
|
2337
2429
|
}
|
|
2338
2430
|
},
|
|
2339
2431
|
{
|
|
@@ -2353,7 +2445,8 @@ function createToolDefinitions() {
|
|
|
2353
2445
|
title: "Delete Skill",
|
|
2354
2446
|
readOnlyHint: false,
|
|
2355
2447
|
destructiveHint: true,
|
|
2356
|
-
idempotentHint: true
|
|
2448
|
+
idempotentHint: true,
|
|
2449
|
+
openWorldHint: false
|
|
2357
2450
|
}
|
|
2358
2451
|
},
|
|
2359
2452
|
{
|
|
@@ -2386,7 +2479,8 @@ function createToolDefinitions() {
|
|
|
2386
2479
|
title: "Create Agent",
|
|
2387
2480
|
readOnlyHint: false,
|
|
2388
2481
|
destructiveHint: false,
|
|
2389
|
-
idempotentHint: true
|
|
2482
|
+
idempotentHint: true,
|
|
2483
|
+
openWorldHint: false
|
|
2390
2484
|
}
|
|
2391
2485
|
},
|
|
2392
2486
|
{
|
|
@@ -2400,7 +2494,8 @@ function createToolDefinitions() {
|
|
|
2400
2494
|
title: "List Agents",
|
|
2401
2495
|
readOnlyHint: true,
|
|
2402
2496
|
destructiveHint: false,
|
|
2403
|
-
idempotentHint: true
|
|
2497
|
+
idempotentHint: true,
|
|
2498
|
+
openWorldHint: false
|
|
2404
2499
|
}
|
|
2405
2500
|
},
|
|
2406
2501
|
{
|
|
@@ -2420,7 +2515,8 @@ function createToolDefinitions() {
|
|
|
2420
2515
|
title: "Get Agent",
|
|
2421
2516
|
readOnlyHint: true,
|
|
2422
2517
|
destructiveHint: false,
|
|
2423
|
-
idempotentHint: true
|
|
2518
|
+
idempotentHint: true,
|
|
2519
|
+
openWorldHint: false
|
|
2424
2520
|
}
|
|
2425
2521
|
},
|
|
2426
2522
|
{
|
|
@@ -2440,7 +2536,8 @@ function createToolDefinitions() {
|
|
|
2440
2536
|
title: "Delete Agent",
|
|
2441
2537
|
readOnlyHint: false,
|
|
2442
2538
|
destructiveHint: true,
|
|
2443
|
-
idempotentHint: true
|
|
2539
|
+
idempotentHint: true,
|
|
2540
|
+
openWorldHint: false
|
|
2444
2541
|
}
|
|
2445
2542
|
}
|
|
2446
2543
|
];
|
|
@@ -2641,6 +2738,33 @@ async function handleAgentDelete(client, args) {
|
|
|
2641
2738
|
};
|
|
2642
2739
|
}
|
|
2643
2740
|
|
|
2741
|
+
// src/shared/mcp/functions/handle-recall.function.ts
|
|
2742
|
+
async function handleRecall(client, args) {
|
|
2743
|
+
const kbid = typeof args["kbid"] === "string" ? args["kbid"] : void 0;
|
|
2744
|
+
const kbids = Array.isArray(args["kbids"]) && args["kbids"].every((item) => typeof item === "string") ? args["kbids"] : void 0;
|
|
2745
|
+
if (!kbid && !kbids) {
|
|
2746
|
+
return {
|
|
2747
|
+
content: [
|
|
2748
|
+
{
|
|
2749
|
+
type: "text",
|
|
2750
|
+
text: "Provide kbid or kbids"
|
|
2751
|
+
}
|
|
2752
|
+
],
|
|
2753
|
+
isError: true
|
|
2754
|
+
};
|
|
2755
|
+
}
|
|
2756
|
+
const depth = typeof args["depth"] === "number" ? args["depth"] : 0;
|
|
2757
|
+
const result = await client.recall({ kbid, kbids, depth });
|
|
2758
|
+
return {
|
|
2759
|
+
content: [
|
|
2760
|
+
{
|
|
2761
|
+
type: "text",
|
|
2762
|
+
text: JSON.stringify(result, null, 2)
|
|
2763
|
+
}
|
|
2764
|
+
]
|
|
2765
|
+
};
|
|
2766
|
+
}
|
|
2767
|
+
|
|
2644
2768
|
// src/shared/mcp/functions/handle-tool-call.function.ts
|
|
2645
2769
|
function asString2(value, fallback) {
|
|
2646
2770
|
return typeof value === "string" ? value : fallback;
|
|
@@ -2662,6 +2786,8 @@ async function handleToolCall(client, name, args) {
|
|
|
2662
2786
|
return await handleUnlearn2(client, args);
|
|
2663
2787
|
case "retrieve":
|
|
2664
2788
|
return await handleRetrieve(client, args);
|
|
2789
|
+
case "recall":
|
|
2790
|
+
return await handleRecall(client, args);
|
|
2665
2791
|
case "status":
|
|
2666
2792
|
return await handleStatus2(client);
|
|
2667
2793
|
case "content":
|
|
@@ -2715,13 +2841,18 @@ async function handleSearch2(client, args) {
|
|
|
2715
2841
|
const results = await client.search({
|
|
2716
2842
|
query: asString2(args["query"], ""),
|
|
2717
2843
|
mode: args["mode"],
|
|
2718
|
-
limit: args["limit"]
|
|
2844
|
+
limit: args["limit"],
|
|
2845
|
+
offset: args["offset"]
|
|
2719
2846
|
});
|
|
2847
|
+
const stripped = {
|
|
2848
|
+
...results,
|
|
2849
|
+
items: results.items.map(({ score: _score, ...rest }) => rest)
|
|
2850
|
+
};
|
|
2720
2851
|
return {
|
|
2721
2852
|
content: [
|
|
2722
2853
|
{
|
|
2723
2854
|
type: "text",
|
|
2724
|
-
text: JSON.stringify(
|
|
2855
|
+
text: JSON.stringify(stripped, null, 2)
|
|
2725
2856
|
}
|
|
2726
2857
|
]
|
|
2727
2858
|
};
|