@vpxa/kb 0.1.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/LICENSE +21 -0
- package/README.md +1140 -0
- package/bin/kb.mjs +10 -0
- package/package.json +67 -0
- package/packages/analyzers/dist/blast-radius-analyzer.d.ts +23 -0
- package/packages/analyzers/dist/blast-radius-analyzer.js +114 -0
- package/packages/analyzers/dist/dependency-analyzer.d.ts +29 -0
- package/packages/analyzers/dist/dependency-analyzer.js +425 -0
- package/packages/analyzers/dist/diagram-generator.d.ts +13 -0
- package/packages/analyzers/dist/diagram-generator.js +86 -0
- package/packages/analyzers/dist/entry-point-analyzer.d.ts +19 -0
- package/packages/analyzers/dist/entry-point-analyzer.js +239 -0
- package/packages/analyzers/dist/index.d.ts +14 -0
- package/packages/analyzers/dist/index.js +23 -0
- package/packages/analyzers/dist/knowledge-producer.d.ts +32 -0
- package/packages/analyzers/dist/knowledge-producer.js +113 -0
- package/packages/analyzers/dist/pattern-analyzer.d.ts +12 -0
- package/packages/analyzers/dist/pattern-analyzer.js +359 -0
- package/packages/analyzers/dist/regex-call-graph.d.ts +17 -0
- package/packages/analyzers/dist/regex-call-graph.js +428 -0
- package/packages/analyzers/dist/structure-analyzer.d.ts +11 -0
- package/packages/analyzers/dist/structure-analyzer.js +258 -0
- package/packages/analyzers/dist/symbol-analyzer.d.ts +10 -0
- package/packages/analyzers/dist/symbol-analyzer.js +442 -0
- package/packages/analyzers/dist/ts-call-graph.d.ts +27 -0
- package/packages/analyzers/dist/ts-call-graph.js +160 -0
- package/packages/analyzers/dist/types.d.ts +98 -0
- package/packages/analyzers/dist/types.js +1 -0
- package/packages/chunker/dist/call-graph-extractor.d.ts +22 -0
- package/packages/chunker/dist/call-graph-extractor.js +90 -0
- package/packages/chunker/dist/chunker-factory.d.ts +7 -0
- package/packages/chunker/dist/chunker-factory.js +36 -0
- package/packages/chunker/dist/chunker.interface.d.ts +10 -0
- package/packages/chunker/dist/chunker.interface.js +1 -0
- package/packages/chunker/dist/code-chunker.d.ts +14 -0
- package/packages/chunker/dist/code-chunker.js +134 -0
- package/packages/chunker/dist/generic-chunker.d.ts +12 -0
- package/packages/chunker/dist/generic-chunker.js +72 -0
- package/packages/chunker/dist/index.d.ts +8 -0
- package/packages/chunker/dist/index.js +21 -0
- package/packages/chunker/dist/markdown-chunker.d.ts +14 -0
- package/packages/chunker/dist/markdown-chunker.js +122 -0
- package/packages/chunker/dist/treesitter-chunker.d.ts +47 -0
- package/packages/chunker/dist/treesitter-chunker.js +234 -0
- package/packages/cli/dist/commands/analyze.d.ts +3 -0
- package/packages/cli/dist/commands/analyze.js +112 -0
- package/packages/cli/dist/commands/context-cmds.d.ts +3 -0
- package/packages/cli/dist/commands/context-cmds.js +155 -0
- package/packages/cli/dist/commands/environment.d.ts +3 -0
- package/packages/cli/dist/commands/environment.js +204 -0
- package/packages/cli/dist/commands/execution.d.ts +3 -0
- package/packages/cli/dist/commands/execution.js +137 -0
- package/packages/cli/dist/commands/graph.d.ts +3 -0
- package/packages/cli/dist/commands/graph.js +81 -0
- package/packages/cli/dist/commands/init.d.ts +8 -0
- package/packages/cli/dist/commands/init.js +87 -0
- package/packages/cli/dist/commands/knowledge.d.ts +3 -0
- package/packages/cli/dist/commands/knowledge.js +139 -0
- package/packages/cli/dist/commands/search.d.ts +3 -0
- package/packages/cli/dist/commands/search.js +267 -0
- package/packages/cli/dist/commands/system.d.ts +3 -0
- package/packages/cli/dist/commands/system.js +241 -0
- package/packages/cli/dist/commands/workspace.d.ts +3 -0
- package/packages/cli/dist/commands/workspace.js +388 -0
- package/packages/cli/dist/context.d.ts +5 -0
- package/packages/cli/dist/context.js +14 -0
- package/packages/cli/dist/helpers.d.ts +52 -0
- package/packages/cli/dist/helpers.js +458 -0
- package/packages/cli/dist/index.d.ts +8 -0
- package/packages/cli/dist/index.js +69 -0
- package/packages/cli/dist/kb-init.d.ts +57 -0
- package/packages/cli/dist/kb-init.js +82 -0
- package/packages/cli/dist/types.d.ts +7 -0
- package/packages/cli/dist/types.js +1 -0
- package/packages/core/dist/constants.d.ts +49 -0
- package/packages/core/dist/constants.js +43 -0
- package/packages/core/dist/content-detector.d.ts +9 -0
- package/packages/core/dist/content-detector.js +79 -0
- package/packages/core/dist/errors.d.ts +18 -0
- package/packages/core/dist/errors.js +40 -0
- package/packages/core/dist/index.d.ts +6 -0
- package/packages/core/dist/index.js +9 -0
- package/packages/core/dist/logger.d.ts +9 -0
- package/packages/core/dist/logger.js +34 -0
- package/packages/core/dist/types.d.ts +108 -0
- package/packages/core/dist/types.js +1 -0
- package/packages/embeddings/dist/embedder.interface.d.ts +24 -0
- package/packages/embeddings/dist/embedder.interface.js +1 -0
- package/packages/embeddings/dist/index.d.ts +3 -0
- package/packages/embeddings/dist/index.js +5 -0
- package/packages/embeddings/dist/onnx-embedder.d.ts +24 -0
- package/packages/embeddings/dist/onnx-embedder.js +82 -0
- package/packages/indexer/dist/file-hasher.d.ts +11 -0
- package/packages/indexer/dist/file-hasher.js +13 -0
- package/packages/indexer/dist/filesystem-crawler.d.ts +27 -0
- package/packages/indexer/dist/filesystem-crawler.js +125 -0
- package/packages/indexer/dist/graph-extractor.d.ts +22 -0
- package/packages/indexer/dist/graph-extractor.js +111 -0
- package/packages/indexer/dist/incremental-indexer.d.ts +47 -0
- package/packages/indexer/dist/incremental-indexer.js +278 -0
- package/packages/indexer/dist/index.d.ts +5 -0
- package/packages/indexer/dist/index.js +14 -0
- package/packages/server/dist/api.d.ts +8 -0
- package/packages/server/dist/api.js +9 -0
- package/packages/server/dist/config.d.ts +3 -0
- package/packages/server/dist/config.js +75 -0
- package/packages/server/dist/curated-manager.d.ts +86 -0
- package/packages/server/dist/curated-manager.js +357 -0
- package/packages/server/dist/index.d.ts +2 -0
- package/packages/server/dist/index.js +134 -0
- package/packages/server/dist/replay-interceptor.d.ts +11 -0
- package/packages/server/dist/replay-interceptor.js +38 -0
- package/packages/server/dist/resources/resources.d.ts +4 -0
- package/packages/server/dist/resources/resources.js +40 -0
- package/packages/server/dist/server.d.ts +21 -0
- package/packages/server/dist/server.js +247 -0
- package/packages/server/dist/tools/analyze.tools.d.ts +11 -0
- package/packages/server/dist/tools/analyze.tools.js +288 -0
- package/packages/server/dist/tools/forge.tools.d.ts +12 -0
- package/packages/server/dist/tools/forge.tools.js +501 -0
- package/packages/server/dist/tools/forget.tool.d.ts +4 -0
- package/packages/server/dist/tools/forget.tool.js +43 -0
- package/packages/server/dist/tools/graph.tool.d.ts +4 -0
- package/packages/server/dist/tools/graph.tool.js +110 -0
- package/packages/server/dist/tools/list.tool.d.ts +4 -0
- package/packages/server/dist/tools/list.tool.js +56 -0
- package/packages/server/dist/tools/lookup.tool.d.ts +4 -0
- package/packages/server/dist/tools/lookup.tool.js +53 -0
- package/packages/server/dist/tools/onboard.tool.d.ts +5 -0
- package/packages/server/dist/tools/onboard.tool.js +112 -0
- package/packages/server/dist/tools/produce.tool.d.ts +3 -0
- package/packages/server/dist/tools/produce.tool.js +74 -0
- package/packages/server/dist/tools/read.tool.d.ts +4 -0
- package/packages/server/dist/tools/read.tool.js +49 -0
- package/packages/server/dist/tools/reindex.tool.d.ts +7 -0
- package/packages/server/dist/tools/reindex.tool.js +70 -0
- package/packages/server/dist/tools/remember.tool.d.ts +4 -0
- package/packages/server/dist/tools/remember.tool.js +45 -0
- package/packages/server/dist/tools/replay.tool.d.ts +3 -0
- package/packages/server/dist/tools/replay.tool.js +89 -0
- package/packages/server/dist/tools/search.tool.d.ts +5 -0
- package/packages/server/dist/tools/search.tool.js +331 -0
- package/packages/server/dist/tools/status.tool.d.ts +4 -0
- package/packages/server/dist/tools/status.tool.js +68 -0
- package/packages/server/dist/tools/toolkit.tools.d.ts +35 -0
- package/packages/server/dist/tools/toolkit.tools.js +1674 -0
- package/packages/server/dist/tools/update.tool.d.ts +4 -0
- package/packages/server/dist/tools/update.tool.js +42 -0
- package/packages/server/dist/tools/utility.tools.d.ts +15 -0
- package/packages/server/dist/tools/utility.tools.js +461 -0
- package/packages/store/dist/graph-store.interface.d.ts +104 -0
- package/packages/store/dist/graph-store.interface.js +1 -0
- package/packages/store/dist/index.d.ts +6 -0
- package/packages/store/dist/index.js +9 -0
- package/packages/store/dist/lance-store.d.ts +32 -0
- package/packages/store/dist/lance-store.js +258 -0
- package/packages/store/dist/sqlite-graph-store.d.ts +43 -0
- package/packages/store/dist/sqlite-graph-store.js +374 -0
- package/packages/store/dist/store-factory.d.ts +9 -0
- package/packages/store/dist/store-factory.js +14 -0
- package/packages/store/dist/store.interface.d.ts +48 -0
- package/packages/store/dist/store.interface.js +1 -0
- package/packages/tools/dist/batch.d.ts +21 -0
- package/packages/tools/dist/batch.js +45 -0
- package/packages/tools/dist/changelog.d.ts +34 -0
- package/packages/tools/dist/changelog.js +112 -0
- package/packages/tools/dist/check.d.ts +26 -0
- package/packages/tools/dist/check.js +59 -0
- package/packages/tools/dist/checkpoint.d.ts +17 -0
- package/packages/tools/dist/checkpoint.js +43 -0
- package/packages/tools/dist/codemod.d.ts +37 -0
- package/packages/tools/dist/codemod.js +69 -0
- package/packages/tools/dist/compact.d.ts +41 -0
- package/packages/tools/dist/compact.js +60 -0
- package/packages/tools/dist/data-transform.d.ts +10 -0
- package/packages/tools/dist/data-transform.js +124 -0
- package/packages/tools/dist/dead-symbols.d.ts +21 -0
- package/packages/tools/dist/dead-symbols.js +71 -0
- package/packages/tools/dist/delegate.d.ts +34 -0
- package/packages/tools/dist/delegate.js +130 -0
- package/packages/tools/dist/diff-parse.d.ts +26 -0
- package/packages/tools/dist/diff-parse.js +153 -0
- package/packages/tools/dist/digest.d.ts +53 -0
- package/packages/tools/dist/digest.js +242 -0
- package/packages/tools/dist/encode.d.ts +14 -0
- package/packages/tools/dist/encode.js +46 -0
- package/packages/tools/dist/env-info.d.ts +28 -0
- package/packages/tools/dist/env-info.js +58 -0
- package/packages/tools/dist/eval.d.ts +13 -0
- package/packages/tools/dist/eval.js +79 -0
- package/packages/tools/dist/evidence-map.d.ts +79 -0
- package/packages/tools/dist/evidence-map.js +203 -0
- package/packages/tools/dist/file-summary.d.ts +32 -0
- package/packages/tools/dist/file-summary.js +106 -0
- package/packages/tools/dist/file-walk.d.ts +4 -0
- package/packages/tools/dist/file-walk.js +75 -0
- package/packages/tools/dist/find-examples.d.ts +25 -0
- package/packages/tools/dist/find-examples.js +48 -0
- package/packages/tools/dist/find.d.ts +47 -0
- package/packages/tools/dist/find.js +120 -0
- package/packages/tools/dist/forge-classify.d.ts +44 -0
- package/packages/tools/dist/forge-classify.js +319 -0
- package/packages/tools/dist/forge-ground.d.ts +64 -0
- package/packages/tools/dist/forge-ground.js +184 -0
- package/packages/tools/dist/git-context.d.ts +22 -0
- package/packages/tools/dist/git-context.js +46 -0
- package/packages/tools/dist/graph-query.d.ts +89 -0
- package/packages/tools/dist/graph-query.js +194 -0
- package/packages/tools/dist/health.d.ts +14 -0
- package/packages/tools/dist/health.js +118 -0
- package/packages/tools/dist/http-request.d.ts +23 -0
- package/packages/tools/dist/http-request.js +58 -0
- package/packages/tools/dist/index.d.ts +49 -0
- package/packages/tools/dist/index.js +273 -0
- package/packages/tools/dist/lane.d.ts +39 -0
- package/packages/tools/dist/lane.js +227 -0
- package/packages/tools/dist/measure.d.ts +38 -0
- package/packages/tools/dist/measure.js +119 -0
- package/packages/tools/dist/onboard.d.ts +41 -0
- package/packages/tools/dist/onboard.js +1139 -0
- package/packages/tools/dist/parse-output.d.ts +80 -0
- package/packages/tools/dist/parse-output.js +158 -0
- package/packages/tools/dist/process-manager.d.ts +18 -0
- package/packages/tools/dist/process-manager.js +69 -0
- package/packages/tools/dist/queue.d.ts +38 -0
- package/packages/tools/dist/queue.js +126 -0
- package/packages/tools/dist/regex-test.d.ts +31 -0
- package/packages/tools/dist/regex-test.js +39 -0
- package/packages/tools/dist/rename.d.ts +29 -0
- package/packages/tools/dist/rename.js +70 -0
- package/packages/tools/dist/replay.d.ts +56 -0
- package/packages/tools/dist/replay.js +108 -0
- package/packages/tools/dist/schema-validate.d.ts +23 -0
- package/packages/tools/dist/schema-validate.js +141 -0
- package/packages/tools/dist/scope-map.d.ts +52 -0
- package/packages/tools/dist/scope-map.js +72 -0
- package/packages/tools/dist/snippet.d.ts +34 -0
- package/packages/tools/dist/snippet.js +80 -0
- package/packages/tools/dist/stash.d.ts +12 -0
- package/packages/tools/dist/stash.js +60 -0
- package/packages/tools/dist/stratum-card.d.ts +31 -0
- package/packages/tools/dist/stratum-card.js +239 -0
- package/packages/tools/dist/symbol.d.ts +28 -0
- package/packages/tools/dist/symbol.js +87 -0
- package/packages/tools/dist/test-run.d.ts +23 -0
- package/packages/tools/dist/test-run.js +55 -0
- package/packages/tools/dist/text-utils.d.ts +16 -0
- package/packages/tools/dist/text-utils.js +31 -0
- package/packages/tools/dist/time-utils.d.ts +18 -0
- package/packages/tools/dist/time-utils.js +135 -0
- package/packages/tools/dist/trace.d.ts +24 -0
- package/packages/tools/dist/trace.js +114 -0
- package/packages/tools/dist/truncation.d.ts +22 -0
- package/packages/tools/dist/truncation.js +45 -0
- package/packages/tools/dist/watch.d.ts +30 -0
- package/packages/tools/dist/watch.js +61 -0
- package/packages/tools/dist/web-fetch.d.ts +45 -0
- package/packages/tools/dist/web-fetch.js +249 -0
- package/packages/tools/dist/web-search.d.ts +23 -0
- package/packages/tools/dist/web-search.js +46 -0
- package/packages/tools/dist/workset.d.ts +45 -0
- package/packages/tools/dist/workset.js +77 -0
- package/packages/tui/dist/App.d.ts +8 -0
- package/packages/tui/dist/App.js +52659 -0
- package/packages/tui/dist/index.d.ts +19 -0
- package/packages/tui/dist/index.js +54742 -0
- package/packages/tui/dist/panels/CuratedPanel.d.ts +8 -0
- package/packages/tui/dist/panels/CuratedPanel.js +34452 -0
- package/packages/tui/dist/panels/LogPanel.d.ts +3 -0
- package/packages/tui/dist/panels/LogPanel.js +51894 -0
- package/packages/tui/dist/panels/SearchPanel.d.ts +10 -0
- package/packages/tui/dist/panels/SearchPanel.js +34985 -0
- package/packages/tui/dist/panels/StatusPanel.d.ts +8 -0
- package/packages/tui/dist/panels/StatusPanel.js +34465 -0
- package/skills/knowledge-base/SKILL.md +316 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
function registerListTool(server, curated) {
|
|
3
|
+
server.registerTool(
|
|
4
|
+
"list",
|
|
5
|
+
{
|
|
6
|
+
description: "List curated knowledge entries. Optionally filter by category or tag.",
|
|
7
|
+
inputSchema: {
|
|
8
|
+
category: z.string().optional().describe('Filter by category (e.g., "decisions", "patterns")'),
|
|
9
|
+
tag: z.string().optional().describe("Filter by tag")
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
async ({ category, tag }) => {
|
|
13
|
+
try {
|
|
14
|
+
const entries = await curated.list({ category, tag });
|
|
15
|
+
if (entries.length === 0) {
|
|
16
|
+
return {
|
|
17
|
+
content: [
|
|
18
|
+
{
|
|
19
|
+
type: "text",
|
|
20
|
+
text: "No curated knowledge entries found." + (category ? ` (category: ${category})` : "") + (tag ? ` (tag: ${tag})` : "")
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const formatted = entries.map((e) => {
|
|
26
|
+
const tags = e.tags.length > 0 ? ` [${e.tags.join(", ")}]` : "";
|
|
27
|
+
return `- **${e.title}** (v${e.version})${tags}
|
|
28
|
+
\`${e.path}\` \u2014 ${e.contentPreview.slice(0, 80)}\u2026`;
|
|
29
|
+
}).join("\n");
|
|
30
|
+
return {
|
|
31
|
+
content: [
|
|
32
|
+
{
|
|
33
|
+
type: "text",
|
|
34
|
+
text: `## Curated Knowledge (${entries.length} entries)
|
|
35
|
+
|
|
36
|
+
${formatted}
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
_Next: Use \`read\` to view full content of any entry, or \`remember\` to store new knowledge._`
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
};
|
|
43
|
+
} catch (err) {
|
|
44
|
+
console.error("[KB] List failed:", err);
|
|
45
|
+
return {
|
|
46
|
+
content: [{ type: "text", text: `List failed: ${err.message}` }],
|
|
47
|
+
isError: true
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
registerListTool
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=list.tool.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
function registerLookupTool(server, store) {
|
|
3
|
+
server.registerTool(
|
|
4
|
+
"lookup",
|
|
5
|
+
{
|
|
6
|
+
description: "Look up all indexed chunks for a specific file path. Returns all chunks sorted by position.",
|
|
7
|
+
inputSchema: {
|
|
8
|
+
path: z.string().describe('Relative file path to look up (e.g., "src/index.ts")')
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
async ({ path }) => {
|
|
12
|
+
try {
|
|
13
|
+
const records = await store.getBySourcePath(path);
|
|
14
|
+
if (records.length === 0) {
|
|
15
|
+
return {
|
|
16
|
+
content: [{ type: "text", text: `No indexed content found for: ${path}` }]
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
records.sort((a, b) => a.chunkIndex - b.chunkIndex);
|
|
20
|
+
const header = `## ${path}
|
|
21
|
+
**Chunks**: ${records.length} | **Type**: ${records[0].contentType}
|
|
22
|
+
`;
|
|
23
|
+
const chunks = records.map((r) => {
|
|
24
|
+
const lineInfo = r.startLine ? ` (lines ${r.startLine}-${r.endLine})` : "";
|
|
25
|
+
return `### Chunk ${r.chunkIndex + 1}/${r.totalChunks}${lineInfo}
|
|
26
|
+
${r.content}`;
|
|
27
|
+
}).join("\n\n");
|
|
28
|
+
return {
|
|
29
|
+
content: [
|
|
30
|
+
{
|
|
31
|
+
type: "text",
|
|
32
|
+
text: `${header}
|
|
33
|
+
${chunks}
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
_Next: Use \`search\` to find related content, or \`analyze_dependencies\` to see what this file imports._`
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
};
|
|
40
|
+
} catch (err) {
|
|
41
|
+
console.error("[KB] Lookup failed:", err);
|
|
42
|
+
return {
|
|
43
|
+
content: [{ type: "text", text: `Lookup failed: ${err.message}` }],
|
|
44
|
+
isError: true
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
registerLookupTool
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=lookup.tool.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { IEmbedder } from '@kb/embeddings';
|
|
2
|
+
import type { IKnowledgeStore } from '@kb/store';
|
|
3
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
4
|
+
export declare function registerOnboardTool(server: McpServer, store: IKnowledgeStore, embedder: IEmbedder): void;
|
|
5
|
+
//# sourceMappingURL=onboard.tool.d.ts.map
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { onboard } from "@kb/tools";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
async function persistOnboardResults(store, embedder, result) {
|
|
5
|
+
for (const step of result.steps) {
|
|
6
|
+
if (step.status !== "success" || !step.output) continue;
|
|
7
|
+
try {
|
|
8
|
+
const pathHash = createHash("sha256").update(result.path).digest("hex").slice(0, 12);
|
|
9
|
+
const sourcePath = `produced/onboard/${step.name}/${pathHash}.md`;
|
|
10
|
+
const contentHash = createHash("sha256").update(step.output).digest("hex").slice(0, 16);
|
|
11
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
12
|
+
const sections = step.output.length > 2e3 ? step.output.split(/(?=^## )/m).filter((s) => s.trim().length > 0) : [step.output];
|
|
13
|
+
const records = sections.map((text, i) => ({
|
|
14
|
+
id: createHash("sha256").update(`${sourcePath}::${i}`).digest("hex").slice(0, 16),
|
|
15
|
+
content: text.trim(),
|
|
16
|
+
sourcePath,
|
|
17
|
+
contentType: "produced-knowledge",
|
|
18
|
+
chunkIndex: i,
|
|
19
|
+
totalChunks: sections.length,
|
|
20
|
+
startLine: 0,
|
|
21
|
+
endLine: 0,
|
|
22
|
+
fileHash: contentHash,
|
|
23
|
+
indexedAt: now,
|
|
24
|
+
origin: "produced",
|
|
25
|
+
tags: ["onboard", step.name],
|
|
26
|
+
category: "analysis",
|
|
27
|
+
version: 1
|
|
28
|
+
}));
|
|
29
|
+
const vectors = await embedder.embedBatch(records.map((r) => r.content));
|
|
30
|
+
await store.upsert(records, vectors);
|
|
31
|
+
} catch (err) {
|
|
32
|
+
console.error(`[KB] Auto-persist onboard/${step.name} failed:`, err);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function registerOnboardTool(server, store, embedder) {
|
|
37
|
+
server.registerTool(
|
|
38
|
+
"onboard",
|
|
39
|
+
{
|
|
40
|
+
description: "First-time codebase onboarding: runs all analysis tools (structure, dependencies, entry-points, symbols, patterns, diagram) in one command. Results are auto-persisted to KB. Use mode=generate to also write structured output to .ai/kb/ directory.",
|
|
41
|
+
inputSchema: {
|
|
42
|
+
path: z.string().describe("Root path of the codebase to onboard"),
|
|
43
|
+
mode: z.enum(["memory", "generate"]).default("memory").describe(
|
|
44
|
+
"Output mode: memory = KB vector store only; generate = also write to .ai/kb/ directory"
|
|
45
|
+
),
|
|
46
|
+
out_dir: z.string().optional().describe("Custom output directory for generate mode (default: <path>/.ai/kb)")
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
async ({ path, mode, out_dir }) => {
|
|
50
|
+
try {
|
|
51
|
+
console.error(`[KB] Starting onboard for: ${path} (mode: ${mode})`);
|
|
52
|
+
const result = await onboard({
|
|
53
|
+
path,
|
|
54
|
+
mode,
|
|
55
|
+
outDir: out_dir
|
|
56
|
+
});
|
|
57
|
+
persistOnboardResults(store, embedder, result);
|
|
58
|
+
const lines = [
|
|
59
|
+
"## Onboard Complete",
|
|
60
|
+
"",
|
|
61
|
+
`**Path:** \`${result.path}\``,
|
|
62
|
+
`**Mode:** ${result.mode}`,
|
|
63
|
+
`**Duration:** ${result.totalDurationMs}ms`,
|
|
64
|
+
""
|
|
65
|
+
];
|
|
66
|
+
if (result.outDir) {
|
|
67
|
+
lines.push(`**Output directory:** \`${result.outDir}\``);
|
|
68
|
+
lines.push("");
|
|
69
|
+
}
|
|
70
|
+
lines.push("### Analysis Results", "");
|
|
71
|
+
const successSteps = [];
|
|
72
|
+
const failedSteps = [];
|
|
73
|
+
for (const step of result.steps) {
|
|
74
|
+
if (step.status === "success") {
|
|
75
|
+
successSteps.push(
|
|
76
|
+
`- \u2713 **${step.name}** (${step.durationMs}ms) \u2014 ${step.output.length} chars`
|
|
77
|
+
);
|
|
78
|
+
} else {
|
|
79
|
+
failedSteps.push(`- \u2717 **${step.name}** \u2014 ${step.error}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
lines.push(...successSteps);
|
|
83
|
+
if (failedSteps.length > 0) {
|
|
84
|
+
lines.push("", "### Failed", "", ...failedSteps);
|
|
85
|
+
}
|
|
86
|
+
lines.push("", "---", "");
|
|
87
|
+
for (const step of result.steps) {
|
|
88
|
+
if (step.status !== "success") continue;
|
|
89
|
+
lines.push(`### ${step.name}`, "", step.output, "", "---", "");
|
|
90
|
+
}
|
|
91
|
+
lines.push(
|
|
92
|
+
"_All results auto-saved to KB.",
|
|
93
|
+
result.mode === "generate" ? ` Files written to \`${result.outDir}\`.` : "",
|
|
94
|
+
" Next: Use `search` to query the knowledge, or `remember` to add custom insights._"
|
|
95
|
+
);
|
|
96
|
+
return {
|
|
97
|
+
content: [{ type: "text", text: lines.join("\n") }]
|
|
98
|
+
};
|
|
99
|
+
} catch (err) {
|
|
100
|
+
console.error("[KB] Onboard failed:", err);
|
|
101
|
+
return {
|
|
102
|
+
content: [{ type: "text", text: `Onboard failed: ${err.message}` }],
|
|
103
|
+
isError: true
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
export {
|
|
110
|
+
registerOnboardTool
|
|
111
|
+
};
|
|
112
|
+
//# sourceMappingURL=onboard.tool.js.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DependencyAnalyzer,
|
|
3
|
+
DiagramGenerator,
|
|
4
|
+
EntryPointAnalyzer,
|
|
5
|
+
KnowledgeProducer,
|
|
6
|
+
PatternAnalyzer,
|
|
7
|
+
StructureAnalyzer,
|
|
8
|
+
SymbolAnalyzer
|
|
9
|
+
} from "@kb/analyzers";
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
function registerProduceKnowledgeTool(server) {
|
|
12
|
+
const analyzers = {
|
|
13
|
+
structure: new StructureAnalyzer(),
|
|
14
|
+
dependencies: new DependencyAnalyzer(),
|
|
15
|
+
symbols: new SymbolAnalyzer(),
|
|
16
|
+
patterns: new PatternAnalyzer(),
|
|
17
|
+
entryPoints: new EntryPointAnalyzer(),
|
|
18
|
+
diagrams: new DiagramGenerator()
|
|
19
|
+
};
|
|
20
|
+
const producer = new KnowledgeProducer(analyzers);
|
|
21
|
+
server.registerTool(
|
|
22
|
+
"produce_knowledge",
|
|
23
|
+
{
|
|
24
|
+
description: "Run automated codebase analysis and produce synthesis instructions. Executes Tier 1 deterministic analyzers, then returns structured baselines and instructions for you to synthesize knowledge using remember.",
|
|
25
|
+
inputSchema: {
|
|
26
|
+
scope: z.string().optional().describe("Root path to analyze (defaults to workspace root)"),
|
|
27
|
+
aspects: z.array(
|
|
28
|
+
z.enum([
|
|
29
|
+
"all",
|
|
30
|
+
"structure",
|
|
31
|
+
"dependencies",
|
|
32
|
+
"symbols",
|
|
33
|
+
"patterns",
|
|
34
|
+
"entry-points",
|
|
35
|
+
"diagrams"
|
|
36
|
+
])
|
|
37
|
+
).default(["all"]).describe("Which analysis aspects to run")
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
async ({ scope, aspects }) => {
|
|
41
|
+
try {
|
|
42
|
+
const rootPath = scope ?? ".";
|
|
43
|
+
console.error(
|
|
44
|
+
`[KB] Running knowledge production for: ${rootPath}, aspects: ${aspects.join(", ")}`
|
|
45
|
+
);
|
|
46
|
+
const baselines = await producer.runExtraction(rootPath, aspects);
|
|
47
|
+
const instructions = producer.buildSynthesisInstructions(baselines, aspects);
|
|
48
|
+
return {
|
|
49
|
+
content: [
|
|
50
|
+
{
|
|
51
|
+
type: "text",
|
|
52
|
+
text: instructions + "\n\n---\n_Next: Review the baselines above and use `remember` to store synthesized knowledge entries._"
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
};
|
|
56
|
+
} catch (err) {
|
|
57
|
+
console.error("[KB] Knowledge production failed:", err);
|
|
58
|
+
return {
|
|
59
|
+
content: [
|
|
60
|
+
{
|
|
61
|
+
type: "text",
|
|
62
|
+
text: `Knowledge production failed: ${err.message}`
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
isError: true
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
export {
|
|
72
|
+
registerProduceKnowledgeTool
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=produce.tool.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import type { CuratedKnowledgeManager } from '../curated-manager.js';
|
|
3
|
+
export declare function registerReadTool(server: McpServer, curated: CuratedKnowledgeManager): void;
|
|
4
|
+
//# sourceMappingURL=read.tool.d.ts.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
function registerReadTool(server, curated) {
|
|
3
|
+
server.registerTool(
|
|
4
|
+
"read",
|
|
5
|
+
{
|
|
6
|
+
description: "Read the full content of a specific curated knowledge entry by its path. Use list first to discover available entries.",
|
|
7
|
+
inputSchema: {
|
|
8
|
+
path: z.string().describe('Relative path within curated/ (e.g., "decisions/use-lancedb.md")')
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
async ({ path }) => {
|
|
12
|
+
try {
|
|
13
|
+
const entry = await curated.read(path);
|
|
14
|
+
const meta = [
|
|
15
|
+
`## ${entry.title}`,
|
|
16
|
+
`- **Path**: curated/${path}`,
|
|
17
|
+
`- **Category**: ${entry.category}`,
|
|
18
|
+
entry.tags.length ? `- **Tags**: ${entry.tags.join(", ")}` : null,
|
|
19
|
+
`- **Version**: ${entry.version}`,
|
|
20
|
+
`- **Created**: ${entry.created}`,
|
|
21
|
+
entry.updated !== entry.created ? `- **Updated**: ${entry.updated}` : null,
|
|
22
|
+
""
|
|
23
|
+
].filter((l) => l !== null).join("\n");
|
|
24
|
+
return {
|
|
25
|
+
content: [
|
|
26
|
+
{
|
|
27
|
+
type: "text",
|
|
28
|
+
text: `${meta}
|
|
29
|
+
${entry.content}
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
_Next: Use \`update\` to modify this entry, or \`search\` to find related entries._`
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
};
|
|
36
|
+
} catch (err) {
|
|
37
|
+
console.error("[KB] Read failed:", err);
|
|
38
|
+
return {
|
|
39
|
+
content: [{ type: "text", text: `Read failed: ${err.message}` }],
|
|
40
|
+
isError: true
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
export {
|
|
47
|
+
registerReadTool
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=read.tool.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { KBConfig } from '@kb/core';
|
|
2
|
+
import type { IncrementalIndexer } from '@kb/indexer';
|
|
3
|
+
import type { IKnowledgeStore } from '@kb/store';
|
|
4
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
5
|
+
import type { CuratedKnowledgeManager } from '../curated-manager.js';
|
|
6
|
+
export declare function registerReindexTool(server: McpServer, indexer: IncrementalIndexer, config: KBConfig, curated: CuratedKnowledgeManager, store?: IKnowledgeStore): void;
|
|
7
|
+
//# sourceMappingURL=reindex.tool.d.ts.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
function registerReindexTool(server, indexer, config, curated, store) {
|
|
3
|
+
server.registerTool(
|
|
4
|
+
"reindex",
|
|
5
|
+
{
|
|
6
|
+
description: "Trigger re-indexing of the knowledge base. Can do incremental (only changed files) or full re-index.",
|
|
7
|
+
inputSchema: {
|
|
8
|
+
full: z.boolean().default(false).describe("If true, force full re-index ignoring file hashes")
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
async ({ full }) => {
|
|
12
|
+
try {
|
|
13
|
+
console.error(`[KB] Starting ${full ? "full" : "incremental"} re-index...`);
|
|
14
|
+
const logProgress = (prefix) => (p) => {
|
|
15
|
+
if (p.phase === "chunking" && p.currentFile) {
|
|
16
|
+
console.error(
|
|
17
|
+
`[KB] ${prefix} [${p.filesProcessed + 1}/${p.filesTotal}] ${p.currentFile}`
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const result = full ? await indexer.reindexAll(config, logProgress("Reindex")) : await indexer.index(config, logProgress("Index"));
|
|
22
|
+
const text = [
|
|
23
|
+
"## Re-index Complete",
|
|
24
|
+
"",
|
|
25
|
+
`- **Files Processed**: ${result.filesProcessed}`,
|
|
26
|
+
`- **Files Skipped** (unchanged): ${result.filesSkipped}`,
|
|
27
|
+
`- **Chunks Created**: ${result.chunksCreated}`,
|
|
28
|
+
`- **Files Removed**: ${result.filesRemoved}`,
|
|
29
|
+
`- **Duration**: ${(result.durationMs / 1e3).toFixed(1)}s`
|
|
30
|
+
];
|
|
31
|
+
if (store) {
|
|
32
|
+
try {
|
|
33
|
+
await store.createFtsIndex();
|
|
34
|
+
} catch (ftsErr) {
|
|
35
|
+
text.push("", `- **FTS Index Failed**: ${ftsErr.message}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const curatedResult = await curated.reindexAll();
|
|
40
|
+
text.push("", `- **Curated Entries Re-indexed**: ${curatedResult.indexed}`);
|
|
41
|
+
if (curatedResult.errors.length > 0) {
|
|
42
|
+
text.push(`- **Curated Errors**: ${curatedResult.errors.length}`);
|
|
43
|
+
}
|
|
44
|
+
console.error(`[KB] Curated re-index: ${curatedResult.indexed} entries`);
|
|
45
|
+
} catch (curatedErr) {
|
|
46
|
+
text.push("", `- **Curated Re-index Failed**: ${curatedErr.message}`);
|
|
47
|
+
console.error("[KB] Curated re-index failed:", curatedErr);
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
content: [
|
|
51
|
+
{
|
|
52
|
+
type: "text",
|
|
53
|
+
text: text.join("\n") + "\n\n---\n_Next: Use `search` to query the refreshed index, or `status` to verify index stats._"
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
};
|
|
57
|
+
} catch (err) {
|
|
58
|
+
console.error("[KB] Reindex failed:", err);
|
|
59
|
+
return {
|
|
60
|
+
content: [{ type: "text", text: `Reindex failed: ${err.message}` }],
|
|
61
|
+
isError: true
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
export {
|
|
68
|
+
registerReindexTool
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=reindex.tool.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import type { CuratedKnowledgeManager } from '../curated-manager.js';
|
|
3
|
+
export declare function registerRememberTool(server: McpServer, curated: CuratedKnowledgeManager): void;
|
|
4
|
+
//# sourceMappingURL=remember.tool.d.ts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
function registerRememberTool(server, curated) {
|
|
3
|
+
server.registerTool(
|
|
4
|
+
"remember",
|
|
5
|
+
{
|
|
6
|
+
description: "Store a new piece of curated knowledge. Use this to persist decisions, patterns, conventions, or any insight worth remembering across sessions.",
|
|
7
|
+
inputSchema: {
|
|
8
|
+
title: z.string().min(3).max(120).describe("Short descriptive title for the knowledge entry"),
|
|
9
|
+
content: z.string().min(10).describe("The markdown content to store"),
|
|
10
|
+
category: z.string().regex(/^[a-z][a-z0-9-]*$/).describe(
|
|
11
|
+
'Category slug (e.g., "decisions", "patterns", "conventions", "api-contracts")'
|
|
12
|
+
),
|
|
13
|
+
tags: z.array(z.string()).default([]).describe("Optional tags for filtering")
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
async ({ title, content, category, tags }) => {
|
|
17
|
+
try {
|
|
18
|
+
const result = await curated.remember(title, content, category, tags);
|
|
19
|
+
return {
|
|
20
|
+
content: [
|
|
21
|
+
{
|
|
22
|
+
type: "text",
|
|
23
|
+
text: `Remembered: **${title}**
|
|
24
|
+
|
|
25
|
+
Stored at \`curated/${result.path}\` and indexed for semantic search.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
_Next: Use \`search\` to verify the entry is findable, or \`list\` to see all curated entries._`
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
};
|
|
32
|
+
} catch (err) {
|
|
33
|
+
console.error("[KB] Remember failed:", err);
|
|
34
|
+
return {
|
|
35
|
+
content: [{ type: "text", text: `Remember failed: ${err.message}` }],
|
|
36
|
+
isError: true
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
registerRememberTool
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=remember.tool.js.map
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { replayClear, replayList, replayTrim } from "@kb/tools";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
function registerReplayTool(server) {
|
|
4
|
+
server.registerTool(
|
|
5
|
+
"replay_list",
|
|
6
|
+
{
|
|
7
|
+
description: "View the audit trail of recent MCP tool and CLI invocations. Shows tool name, duration, status, and input/output summaries. Useful for debugging agent behavior and understanding what happened.",
|
|
8
|
+
inputSchema: {
|
|
9
|
+
last: z.number().optional().describe("Number of entries to return (default: 20)"),
|
|
10
|
+
tool: z.string().optional().describe('Filter by tool name (e.g., "search")'),
|
|
11
|
+
source: z.enum(["mcp", "cli"]).optional().describe('Filter by source: "mcp" or "cli"'),
|
|
12
|
+
since: z.string().optional().describe("ISO timestamp \u2014 only show entries after this time")
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
async ({ last, tool, source, since }) => {
|
|
16
|
+
try {
|
|
17
|
+
const entries = replayList({ last, tool, source, since });
|
|
18
|
+
if (entries.length === 0) {
|
|
19
|
+
return {
|
|
20
|
+
content: [
|
|
21
|
+
{
|
|
22
|
+
type: "text",
|
|
23
|
+
text: "No replay entries found. Activity is logged when tools are invoked via MCP or CLI."
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const lines = entries.map((e) => {
|
|
29
|
+
const time = e.ts.split("T")[1]?.split(".")[0] ?? e.ts;
|
|
30
|
+
const status = e.status === "ok" ? "\u2713" : "\u2717";
|
|
31
|
+
return `${time} ${status} ${e.tool} (${e.durationMs}ms) [${e.source}]
|
|
32
|
+
in: ${e.input}
|
|
33
|
+
out: ${e.output}`;
|
|
34
|
+
});
|
|
35
|
+
replayTrim();
|
|
36
|
+
return {
|
|
37
|
+
content: [
|
|
38
|
+
{
|
|
39
|
+
type: "text",
|
|
40
|
+
text: `**Replay Log** (${entries.length} entries)
|
|
41
|
+
|
|
42
|
+
${lines.join("\n\n")}`
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
};
|
|
46
|
+
} catch (err) {
|
|
47
|
+
console.error("[KB] Replay list failed:", err);
|
|
48
|
+
return {
|
|
49
|
+
content: [
|
|
50
|
+
{ type: "text", text: `Replay list failed: ${err.message}` }
|
|
51
|
+
],
|
|
52
|
+
isError: true
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
server.registerTool(
|
|
58
|
+
"replay_clear",
|
|
59
|
+
{
|
|
60
|
+
description: "Clear the entire replay audit trail.",
|
|
61
|
+
inputSchema: {}
|
|
62
|
+
},
|
|
63
|
+
async () => {
|
|
64
|
+
try {
|
|
65
|
+
replayClear();
|
|
66
|
+
return {
|
|
67
|
+
content: [
|
|
68
|
+
{
|
|
69
|
+
type: "text",
|
|
70
|
+
text: "Replay log cleared."
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
};
|
|
74
|
+
} catch (err) {
|
|
75
|
+
console.error("[KB] Replay clear failed:", err);
|
|
76
|
+
return {
|
|
77
|
+
content: [
|
|
78
|
+
{ type: "text", text: `Replay clear failed: ${err.message}` }
|
|
79
|
+
],
|
|
80
|
+
isError: true
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
export {
|
|
87
|
+
registerReplayTool
|
|
88
|
+
};
|
|
89
|
+
//# sourceMappingURL=replay.tool.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { IEmbedder } from '@kb/embeddings';
|
|
2
|
+
import type { IGraphStore, IKnowledgeStore } from '@kb/store';
|
|
3
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
4
|
+
export declare function registerSearchTool(server: McpServer, embedder: IEmbedder, store: IKnowledgeStore, graphStore?: IGraphStore): void;
|
|
5
|
+
//# sourceMappingURL=search.tool.d.ts.map
|