@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,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default constants for the Knowledge Base system.
|
|
3
|
+
*/
|
|
4
|
+
/** Default chunk sizes by content type */
|
|
5
|
+
export declare const CHUNK_SIZES: {
|
|
6
|
+
readonly markdown: {
|
|
7
|
+
readonly max: 1500;
|
|
8
|
+
readonly min: 100;
|
|
9
|
+
};
|
|
10
|
+
readonly code: {
|
|
11
|
+
readonly max: 2000;
|
|
12
|
+
readonly min: 50;
|
|
13
|
+
};
|
|
14
|
+
readonly config: {
|
|
15
|
+
readonly max: 3000;
|
|
16
|
+
readonly min: 50;
|
|
17
|
+
};
|
|
18
|
+
readonly default: {
|
|
19
|
+
readonly max: 1500;
|
|
20
|
+
readonly min: 100;
|
|
21
|
+
readonly overlap: 200;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
/** Default embedding config */
|
|
25
|
+
export declare const EMBEDDING_DEFAULTS: {
|
|
26
|
+
readonly model: "mixedbread-ai/mxbai-embed-large-v1";
|
|
27
|
+
readonly dimensions: 1024;
|
|
28
|
+
};
|
|
29
|
+
/** Default store config */
|
|
30
|
+
export declare const STORE_DEFAULTS: {
|
|
31
|
+
readonly backend: "lancedb";
|
|
32
|
+
readonly path: ".kb-data";
|
|
33
|
+
readonly tableName: "knowledge";
|
|
34
|
+
};
|
|
35
|
+
/** File size limits */
|
|
36
|
+
export declare const FILE_LIMITS: {
|
|
37
|
+
readonly maxFileSizeBytes: 1000000;
|
|
38
|
+
readonly maxCuratedFileSizeBytes: 50000;
|
|
39
|
+
};
|
|
40
|
+
/** Search defaults */
|
|
41
|
+
export declare const SEARCH_DEFAULTS: {
|
|
42
|
+
readonly maxResults: 10;
|
|
43
|
+
readonly minScore: 0.25;
|
|
44
|
+
};
|
|
45
|
+
/** Category validation regex */
|
|
46
|
+
export declare const CATEGORY_PATTERN: RegExp;
|
|
47
|
+
/** Default knowledge categories */
|
|
48
|
+
export declare const DEFAULT_CATEGORIES: readonly ["decisions", "patterns", "troubleshooting", "conventions", "architecture"];
|
|
49
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const CHUNK_SIZES = {
|
|
2
|
+
markdown: { max: 1500, min: 100 },
|
|
3
|
+
code: { max: 2e3, min: 50 },
|
|
4
|
+
config: { max: 3e3, min: 50 },
|
|
5
|
+
default: { max: 1500, min: 100, overlap: 200 }
|
|
6
|
+
};
|
|
7
|
+
const EMBEDDING_DEFAULTS = {
|
|
8
|
+
model: "mixedbread-ai/mxbai-embed-large-v1",
|
|
9
|
+
dimensions: 1024
|
|
10
|
+
};
|
|
11
|
+
const STORE_DEFAULTS = {
|
|
12
|
+
backend: "lancedb",
|
|
13
|
+
path: ".kb-data",
|
|
14
|
+
tableName: "knowledge"
|
|
15
|
+
};
|
|
16
|
+
const FILE_LIMITS = {
|
|
17
|
+
maxFileSizeBytes: 1e6,
|
|
18
|
+
// 1MB — skip larger files
|
|
19
|
+
maxCuratedFileSizeBytes: 5e4
|
|
20
|
+
// 50KB for curated knowledge
|
|
21
|
+
};
|
|
22
|
+
const SEARCH_DEFAULTS = {
|
|
23
|
+
maxResults: 10,
|
|
24
|
+
minScore: 0.25
|
|
25
|
+
};
|
|
26
|
+
const CATEGORY_PATTERN = /^[a-z][a-z0-9-]*$/;
|
|
27
|
+
const DEFAULT_CATEGORIES = [
|
|
28
|
+
"decisions",
|
|
29
|
+
"patterns",
|
|
30
|
+
"troubleshooting",
|
|
31
|
+
"conventions",
|
|
32
|
+
"architecture"
|
|
33
|
+
];
|
|
34
|
+
export {
|
|
35
|
+
CATEGORY_PATTERN,
|
|
36
|
+
CHUNK_SIZES,
|
|
37
|
+
DEFAULT_CATEGORIES,
|
|
38
|
+
EMBEDDING_DEFAULTS,
|
|
39
|
+
FILE_LIMITS,
|
|
40
|
+
SEARCH_DEFAULTS,
|
|
41
|
+
STORE_DEFAULTS
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detects content type from file path and extension.
|
|
3
|
+
*/
|
|
4
|
+
import type { ContentType } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Detect the content type of a file based on its path.
|
|
7
|
+
*/
|
|
8
|
+
export declare function detectContentType(filePath: string): ContentType;
|
|
9
|
+
//# sourceMappingURL=content-detector.d.ts.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { basename, extname } from "node:path";
|
|
2
|
+
const EXTENSION_MAP = {
|
|
3
|
+
".ts": "code-typescript",
|
|
4
|
+
".tsx": "code-typescript",
|
|
5
|
+
".mts": "code-typescript",
|
|
6
|
+
".cts": "code-typescript",
|
|
7
|
+
".js": "code-javascript",
|
|
8
|
+
".jsx": "code-javascript",
|
|
9
|
+
".mjs": "code-javascript",
|
|
10
|
+
".cjs": "code-javascript",
|
|
11
|
+
".py": "code-python",
|
|
12
|
+
".json": "config-json",
|
|
13
|
+
".yaml": "config-yaml",
|
|
14
|
+
".yml": "config-yaml",
|
|
15
|
+
".toml": "config-toml",
|
|
16
|
+
".env": "config-env",
|
|
17
|
+
".md": "markdown",
|
|
18
|
+
".mdx": "markdown"
|
|
19
|
+
};
|
|
20
|
+
const TEST_PATTERNS = [
|
|
21
|
+
/\.test\.[jt]sx?$/,
|
|
22
|
+
/\.spec\.[jt]sx?$/,
|
|
23
|
+
/(^|\/)__tests__\//,
|
|
24
|
+
/(^|\/)test\//,
|
|
25
|
+
/(^|\/)tests\//,
|
|
26
|
+
/(^|\/)spec\//,
|
|
27
|
+
/(^|\/)fixtures\//
|
|
28
|
+
];
|
|
29
|
+
const CDK_PATTERNS = [/\.stack\.[jt]s$/, /(^|\/)stacks\//, /(^|\/)constructs\//, /cdk\.json$/];
|
|
30
|
+
function detectContentType(filePath) {
|
|
31
|
+
const ext = extname(filePath).toLowerCase();
|
|
32
|
+
const name = basename(filePath).toLowerCase();
|
|
33
|
+
if (filePath.includes("curated/")) {
|
|
34
|
+
return "curated-knowledge";
|
|
35
|
+
}
|
|
36
|
+
if (TEST_PATTERNS.some((p) => p.test(filePath))) {
|
|
37
|
+
return "test-code";
|
|
38
|
+
}
|
|
39
|
+
if (CDK_PATTERNS.some((p) => p.test(filePath))) {
|
|
40
|
+
return "cdk-stack";
|
|
41
|
+
}
|
|
42
|
+
if (ext in EXTENSION_MAP) {
|
|
43
|
+
return EXTENSION_MAP[ext];
|
|
44
|
+
}
|
|
45
|
+
if (name.startsWith(".env")) {
|
|
46
|
+
return "config-env";
|
|
47
|
+
}
|
|
48
|
+
const codeExtensions = [
|
|
49
|
+
".go",
|
|
50
|
+
".rs",
|
|
51
|
+
".java",
|
|
52
|
+
".rb",
|
|
53
|
+
".php",
|
|
54
|
+
".sh",
|
|
55
|
+
".ps1",
|
|
56
|
+
".sql",
|
|
57
|
+
".graphql",
|
|
58
|
+
".proto",
|
|
59
|
+
".css",
|
|
60
|
+
".scss",
|
|
61
|
+
".less",
|
|
62
|
+
".html",
|
|
63
|
+
".htm",
|
|
64
|
+
".vue",
|
|
65
|
+
".svelte",
|
|
66
|
+
".astro",
|
|
67
|
+
".hbs",
|
|
68
|
+
".ejs",
|
|
69
|
+
".svg"
|
|
70
|
+
];
|
|
71
|
+
if (codeExtensions.includes(ext)) {
|
|
72
|
+
return "code-other";
|
|
73
|
+
}
|
|
74
|
+
return "unknown";
|
|
75
|
+
}
|
|
76
|
+
export {
|
|
77
|
+
detectContentType
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=content-detector.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare class KBError extends Error {
|
|
2
|
+
readonly code: string;
|
|
3
|
+
readonly cause?: unknown | undefined;
|
|
4
|
+
constructor(message: string, code: string, cause?: unknown | undefined);
|
|
5
|
+
}
|
|
6
|
+
export declare class EmbeddingError extends KBError {
|
|
7
|
+
constructor(message: string, cause?: unknown);
|
|
8
|
+
}
|
|
9
|
+
export declare class StoreError extends KBError {
|
|
10
|
+
constructor(message: string, cause?: unknown);
|
|
11
|
+
}
|
|
12
|
+
export declare class IndexError extends KBError {
|
|
13
|
+
constructor(message: string, cause?: unknown);
|
|
14
|
+
}
|
|
15
|
+
export declare class ConfigError extends KBError {
|
|
16
|
+
constructor(message: string, cause?: unknown);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
class KBError extends Error {
|
|
2
|
+
constructor(message, code, cause) {
|
|
3
|
+
super(message);
|
|
4
|
+
this.code = code;
|
|
5
|
+
this.cause = cause;
|
|
6
|
+
this.name = "KBError";
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
class EmbeddingError extends KBError {
|
|
10
|
+
constructor(message, cause) {
|
|
11
|
+
super(message, "EMBEDDING_ERROR", cause);
|
|
12
|
+
this.name = "EmbeddingError";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
class StoreError extends KBError {
|
|
16
|
+
constructor(message, cause) {
|
|
17
|
+
super(message, "STORE_ERROR", cause);
|
|
18
|
+
this.name = "StoreError";
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
class IndexError extends KBError {
|
|
22
|
+
constructor(message, cause) {
|
|
23
|
+
super(message, "INDEX_ERROR", cause);
|
|
24
|
+
this.name = "IndexError";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
class ConfigError extends KBError {
|
|
28
|
+
constructor(message, cause) {
|
|
29
|
+
super(message, "CONFIG_ERROR", cause);
|
|
30
|
+
this.name = "ConfigError";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
ConfigError,
|
|
35
|
+
EmbeddingError,
|
|
36
|
+
IndexError,
|
|
37
|
+
KBError,
|
|
38
|
+
StoreError
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
2
|
+
export declare function setLogLevel(level: LogLevel): void;
|
|
3
|
+
export declare function createLogger(component: string): {
|
|
4
|
+
debug: (msg: string, data?: Record<string, unknown>) => void;
|
|
5
|
+
info: (msg: string, data?: Record<string, unknown>) => void;
|
|
6
|
+
warn: (msg: string, data?: Record<string, unknown>) => void;
|
|
7
|
+
error: (msg: string, data?: Record<string, unknown>) => void;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const LOG_LEVELS = {
|
|
2
|
+
debug: 0,
|
|
3
|
+
info: 1,
|
|
4
|
+
warn: 2,
|
|
5
|
+
error: 3
|
|
6
|
+
};
|
|
7
|
+
let currentLevel = process.env.KB_LOG_LEVEL ?? "info";
|
|
8
|
+
function setLogLevel(level) {
|
|
9
|
+
currentLevel = level;
|
|
10
|
+
}
|
|
11
|
+
function createLogger(component) {
|
|
12
|
+
function log(level, message, data) {
|
|
13
|
+
if (LOG_LEVELS[level] < LOG_LEVELS[currentLevel]) return;
|
|
14
|
+
const entry = {
|
|
15
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
16
|
+
level,
|
|
17
|
+
component,
|
|
18
|
+
msg: message,
|
|
19
|
+
...data
|
|
20
|
+
};
|
|
21
|
+
console.error(JSON.stringify(entry));
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
debug: (msg, data) => log("debug", msg, data),
|
|
25
|
+
info: (msg, data) => log("info", msg, data),
|
|
26
|
+
warn: (msg, data) => log("warn", msg, data),
|
|
27
|
+
error: (msg, data) => log("error", msg, data)
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
createLogger,
|
|
32
|
+
setLogLevel
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types for the MCP Knowledge Base system.
|
|
3
|
+
*/
|
|
4
|
+
/** The origin of a knowledge record — how it was created */
|
|
5
|
+
export type KnowledgeOrigin = 'indexed' | 'curated' | 'produced';
|
|
6
|
+
/** Content type classification */
|
|
7
|
+
export type ContentType = 'documentation' | 'code-typescript' | 'code-javascript' | 'code-python' | 'code-other' | 'config-json' | 'config-yaml' | 'config-toml' | 'config-env' | 'test-code' | 'cdk-stack' | 'markdown' | 'curated-knowledge' | 'produced-knowledge' | 'unknown';
|
|
8
|
+
/** A single knowledge record stored in the vector DB */
|
|
9
|
+
export interface KnowledgeRecord {
|
|
10
|
+
/** Unique identifier (deterministic hash of source + chunk index) */
|
|
11
|
+
id: string;
|
|
12
|
+
/** The text content of this chunk */
|
|
13
|
+
content: string;
|
|
14
|
+
/** Source file path relative to workspace root */
|
|
15
|
+
sourcePath: string;
|
|
16
|
+
/** Content type classification */
|
|
17
|
+
contentType: ContentType;
|
|
18
|
+
/** Heading path for markdown (e.g., "## Setup > ### Prerequisites") */
|
|
19
|
+
headingPath?: string;
|
|
20
|
+
/** Zero-based chunk index within the source file */
|
|
21
|
+
chunkIndex: number;
|
|
22
|
+
/** Total number of chunks from this source file */
|
|
23
|
+
totalChunks: number;
|
|
24
|
+
/** Start line in source file (1-based) */
|
|
25
|
+
startLine: number;
|
|
26
|
+
/** End line in source file (1-based) */
|
|
27
|
+
endLine: number;
|
|
28
|
+
/** File hash for incremental indexing */
|
|
29
|
+
fileHash: string;
|
|
30
|
+
/** ISO timestamp when this record was created/updated */
|
|
31
|
+
indexedAt: string;
|
|
32
|
+
/** How this record was created */
|
|
33
|
+
origin: KnowledgeOrigin;
|
|
34
|
+
/** User-defined tags for categorization */
|
|
35
|
+
tags: string[];
|
|
36
|
+
/** Category for curated/produced knowledge */
|
|
37
|
+
category?: string;
|
|
38
|
+
/** Version number for curated knowledge updates */
|
|
39
|
+
version: number;
|
|
40
|
+
}
|
|
41
|
+
/** A raw chunk produced by a chunker before embedding */
|
|
42
|
+
export interface RawChunk {
|
|
43
|
+
/** The text content */
|
|
44
|
+
text: string;
|
|
45
|
+
/** Source file path */
|
|
46
|
+
sourcePath: string;
|
|
47
|
+
/** Content type */
|
|
48
|
+
contentType: ContentType;
|
|
49
|
+
/** Heading path (markdown only) */
|
|
50
|
+
headingPath?: string;
|
|
51
|
+
/** Chunk index */
|
|
52
|
+
chunkIndex: number;
|
|
53
|
+
/** Total chunks from this file */
|
|
54
|
+
totalChunks: number;
|
|
55
|
+
/** Start line (1-based) */
|
|
56
|
+
startLine: number;
|
|
57
|
+
/** End line (1-based) */
|
|
58
|
+
endLine: number;
|
|
59
|
+
}
|
|
60
|
+
/** Metadata passed to a chunker */
|
|
61
|
+
export interface ChunkMetadata {
|
|
62
|
+
/** File path relative to workspace root */
|
|
63
|
+
sourcePath: string;
|
|
64
|
+
/** Detected content type */
|
|
65
|
+
contentType: ContentType;
|
|
66
|
+
}
|
|
67
|
+
/** Search result returned by the store */
|
|
68
|
+
export interface SearchResult {
|
|
69
|
+
/** The matching knowledge record */
|
|
70
|
+
record: KnowledgeRecord;
|
|
71
|
+
/** Similarity score (0-1, higher = more similar) */
|
|
72
|
+
score: number;
|
|
73
|
+
}
|
|
74
|
+
/** Configuration loaded from kb.config.json */
|
|
75
|
+
export interface KBConfig {
|
|
76
|
+
sources: Array<{
|
|
77
|
+
path: string;
|
|
78
|
+
excludePatterns: string[];
|
|
79
|
+
}>;
|
|
80
|
+
indexing: {
|
|
81
|
+
chunkSize: number;
|
|
82
|
+
chunkOverlap: number;
|
|
83
|
+
minChunkSize: number;
|
|
84
|
+
/** Max files processed concurrently. Defaults to half of available CPU cores. */
|
|
85
|
+
concurrency?: number;
|
|
86
|
+
};
|
|
87
|
+
embedding: {
|
|
88
|
+
model: string;
|
|
89
|
+
dimensions: number;
|
|
90
|
+
};
|
|
91
|
+
store: {
|
|
92
|
+
backend: string;
|
|
93
|
+
path: string;
|
|
94
|
+
};
|
|
95
|
+
curated: {
|
|
96
|
+
path: string;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/** Index statistics */
|
|
100
|
+
export interface IndexStats {
|
|
101
|
+
totalRecords: number;
|
|
102
|
+
totalFiles: number;
|
|
103
|
+
contentTypeBreakdown: Record<string, number>;
|
|
104
|
+
lastIndexedAt: string | null;
|
|
105
|
+
storeBackend: string;
|
|
106
|
+
embeddingModel: string;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Embedding abstraction — allows swapping embedding models.
|
|
3
|
+
*/
|
|
4
|
+
export interface IEmbedder {
|
|
5
|
+
/** Generate an embedding vector for a single text string (used for documents/passages) */
|
|
6
|
+
embed(text: string): Promise<Float32Array>;
|
|
7
|
+
/**
|
|
8
|
+
* Generate an embedding vector for a search query.
|
|
9
|
+
* Some models (e.g., BGE) use a query prefix for asymmetric retrieval.
|
|
10
|
+
* Falls back to embed() if the model doesn't need query prefixing.
|
|
11
|
+
*/
|
|
12
|
+
embedQuery(query: string): Promise<Float32Array>;
|
|
13
|
+
/** Generate embeddings for multiple text strings (batched, for documents/passages) */
|
|
14
|
+
embedBatch(texts: string[]): Promise<Float32Array[]>;
|
|
15
|
+
/** The dimensionality of the embedding vectors */
|
|
16
|
+
readonly dimensions: number;
|
|
17
|
+
/** The model identifier */
|
|
18
|
+
readonly modelId: string;
|
|
19
|
+
/** Initialize the model (download if needed, load into memory) */
|
|
20
|
+
initialize(): Promise<void>;
|
|
21
|
+
/** Release model resources */
|
|
22
|
+
shutdown?(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=embedder.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=embedder.interface.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ONNX-based embedder using @huggingface/transformers.
|
|
3
|
+
* Uses mixedbread-ai/mxbai-embed-large-v1 (1024 dimensions, ~1.3GB ONNX model).
|
|
4
|
+
* BGE-derived models use query prefixing for asymmetric retrieval (short query → long document).
|
|
5
|
+
*/
|
|
6
|
+
import type { IEmbedder } from './embedder.interface.js';
|
|
7
|
+
export declare class OnnxEmbedder implements IEmbedder {
|
|
8
|
+
private pipe;
|
|
9
|
+
readonly dimensions: number;
|
|
10
|
+
readonly modelId: string;
|
|
11
|
+
private readonly queryPrefix;
|
|
12
|
+
constructor(options?: {
|
|
13
|
+
model?: string;
|
|
14
|
+
dimensions?: number;
|
|
15
|
+
queryPrefix?: string;
|
|
16
|
+
});
|
|
17
|
+
private detectQueryPrefix;
|
|
18
|
+
initialize(): Promise<void>;
|
|
19
|
+
shutdown(): Promise<void>;
|
|
20
|
+
embed(text: string): Promise<Float32Array>;
|
|
21
|
+
embedQuery(query: string): Promise<Float32Array>;
|
|
22
|
+
embedBatch(texts: string[]): Promise<Float32Array[]>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=onnx-embedder.d.ts.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { pipeline } from "@huggingface/transformers";
|
|
2
|
+
import { EMBEDDING_DEFAULTS } from "@kb/core";
|
|
3
|
+
class OnnxEmbedder {
|
|
4
|
+
pipe = null;
|
|
5
|
+
dimensions;
|
|
6
|
+
modelId;
|
|
7
|
+
queryPrefix;
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.modelId = options?.model ?? EMBEDDING_DEFAULTS.model;
|
|
10
|
+
this.dimensions = options?.dimensions ?? EMBEDDING_DEFAULTS.dimensions;
|
|
11
|
+
this.queryPrefix = options?.queryPrefix ?? this.detectQueryPrefix(this.modelId);
|
|
12
|
+
}
|
|
13
|
+
detectQueryPrefix(modelId) {
|
|
14
|
+
const id = modelId.toLowerCase();
|
|
15
|
+
if (id.includes("bge") || id.includes("mxbai-embed")) {
|
|
16
|
+
return "Represent this sentence for searching relevant passages: ";
|
|
17
|
+
}
|
|
18
|
+
if (id.includes("/e5-") || id.includes("multilingual-e5")) {
|
|
19
|
+
return "query: ";
|
|
20
|
+
}
|
|
21
|
+
return "";
|
|
22
|
+
}
|
|
23
|
+
async initialize() {
|
|
24
|
+
if (this.pipe) return;
|
|
25
|
+
try {
|
|
26
|
+
this.pipe = await pipeline("feature-extraction", this.modelId, {
|
|
27
|
+
dtype: "fp32"
|
|
28
|
+
});
|
|
29
|
+
} catch (err) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`Failed to initialize embedding model "${this.modelId}": ${err.message}`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async shutdown() {
|
|
36
|
+
this.pipe = null;
|
|
37
|
+
}
|
|
38
|
+
async embed(text) {
|
|
39
|
+
if (!this.pipe) {
|
|
40
|
+
await this.initialize();
|
|
41
|
+
}
|
|
42
|
+
const output = await this.pipe?.(text, {
|
|
43
|
+
pooling: "mean",
|
|
44
|
+
normalize: true
|
|
45
|
+
});
|
|
46
|
+
if (!output) throw new Error("Embedding pipeline returned no output");
|
|
47
|
+
return new Float32Array(output.data);
|
|
48
|
+
}
|
|
49
|
+
async embedQuery(query) {
|
|
50
|
+
return this.embed(this.queryPrefix + query);
|
|
51
|
+
}
|
|
52
|
+
async embedBatch(texts) {
|
|
53
|
+
if (texts.length === 0) return [];
|
|
54
|
+
if (!this.pipe) {
|
|
55
|
+
await this.initialize();
|
|
56
|
+
}
|
|
57
|
+
const results = [];
|
|
58
|
+
const BATCH_SIZE = 32;
|
|
59
|
+
for (let i = 0; i < texts.length; i += BATCH_SIZE) {
|
|
60
|
+
const batch = texts.slice(i, i + BATCH_SIZE);
|
|
61
|
+
const output = await this.pipe?.(batch, {
|
|
62
|
+
pooling: "mean",
|
|
63
|
+
normalize: true
|
|
64
|
+
});
|
|
65
|
+
if (!output) throw new Error("Embedding pipeline returned no output");
|
|
66
|
+
if (batch.length === 1) {
|
|
67
|
+
results.push(new Float32Array(output.data));
|
|
68
|
+
} else {
|
|
69
|
+
for (let j = 0; j < batch.length; j++) {
|
|
70
|
+
const start = j * this.dimensions;
|
|
71
|
+
const slice = output.data.slice(start, start + this.dimensions);
|
|
72
|
+
results.push(new Float32Array(slice));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return results;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export {
|
|
80
|
+
OnnxEmbedder
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=onnx-embedder.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate a deterministic hash for a file's content.
|
|
3
|
+
* Used for incremental indexing -- skip files that haven't changed.
|
|
4
|
+
*/
|
|
5
|
+
export declare function hashContent(content: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* Generate a deterministic ID for a knowledge record.
|
|
8
|
+
* Based on source path + chunk index to ensure idempotent upserts.
|
|
9
|
+
*/
|
|
10
|
+
export declare function generateRecordId(sourcePath: string, chunkIndex: number): string;
|
|
11
|
+
//# sourceMappingURL=file-hasher.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
function hashContent(content) {
|
|
3
|
+
return createHash("sha256").update(content).digest("hex").slice(0, 16);
|
|
4
|
+
}
|
|
5
|
+
function generateRecordId(sourcePath, chunkIndex) {
|
|
6
|
+
const input = `${sourcePath}:${chunkIndex}`;
|
|
7
|
+
return createHash("sha256").update(input).digest("hex").slice(0, 16);
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
generateRecordId,
|
|
11
|
+
hashContent
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=file-hasher.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface CrawlResult {
|
|
2
|
+
/** File path relative to workspace root */
|
|
3
|
+
relativePath: string;
|
|
4
|
+
/** Absolute file path */
|
|
5
|
+
absolutePath: string;
|
|
6
|
+
/** File content */
|
|
7
|
+
content: string;
|
|
8
|
+
/** File extension (lowercase, with dot) */
|
|
9
|
+
extension: string;
|
|
10
|
+
}
|
|
11
|
+
export interface CrawlOptions {
|
|
12
|
+
/** Glob patterns to exclude */
|
|
13
|
+
excludePatterns: string[];
|
|
14
|
+
/** Root directory to crawl */
|
|
15
|
+
rootDir: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Crawl a directory tree and yield files that should be indexed.
|
|
19
|
+
*/
|
|
20
|
+
export declare class FilesystemCrawler {
|
|
21
|
+
/** Binary file extensions that should always be skipped */
|
|
22
|
+
private static readonly BINARY_EXTENSIONS;
|
|
23
|
+
crawl(options: CrawlOptions): Promise<CrawlResult[]>;
|
|
24
|
+
private walkDir;
|
|
25
|
+
private isExcluded;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=filesystem-crawler.d.ts.map
|