@vpxa/kb 0.1.1 → 0.1.3
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 +3 -3
- package/package.json +1 -1
- package/packages/analyzers/dist/blast-radius-analyzer.js +13 -114
- package/packages/analyzers/dist/dependency-analyzer.js +11 -425
- package/packages/analyzers/dist/diagram-generator.js +4 -86
- package/packages/analyzers/dist/entry-point-analyzer.js +5 -239
- package/packages/analyzers/dist/index.js +1 -23
- package/packages/analyzers/dist/knowledge-producer.js +24 -113
- package/packages/analyzers/dist/pattern-analyzer.js +5 -359
- package/packages/analyzers/dist/regex-call-graph.js +1 -428
- package/packages/analyzers/dist/structure-analyzer.js +4 -258
- package/packages/analyzers/dist/symbol-analyzer.js +13 -442
- package/packages/analyzers/dist/ts-call-graph.js +1 -160
- package/packages/analyzers/dist/types.js +0 -1
- package/packages/chunker/dist/call-graph-extractor.js +1 -90
- package/packages/chunker/dist/chunker-factory.js +1 -36
- package/packages/chunker/dist/chunker.interface.js +0 -1
- package/packages/chunker/dist/code-chunker.js +14 -134
- package/packages/chunker/dist/generic-chunker.js +5 -72
- package/packages/chunker/dist/index.js +1 -21
- package/packages/chunker/dist/markdown-chunker.js +7 -119
- package/packages/chunker/dist/treesitter-chunker.js +8 -234
- package/packages/cli/dist/commands/analyze.js +3 -112
- package/packages/cli/dist/commands/context-cmds.js +1 -155
- package/packages/cli/dist/commands/environment.js +2 -204
- package/packages/cli/dist/commands/execution.js +1 -137
- package/packages/cli/dist/commands/graph.js +7 -81
- package/packages/cli/dist/commands/init.js +9 -87
- package/packages/cli/dist/commands/knowledge.js +1 -139
- package/packages/cli/dist/commands/search.js +8 -267
- package/packages/cli/dist/commands/system.js +4 -241
- package/packages/cli/dist/commands/workspace.js +2 -388
- package/packages/cli/dist/context.js +1 -14
- package/packages/cli/dist/helpers.js +3 -458
- package/packages/cli/dist/index.d.ts +1 -1
- package/packages/cli/dist/index.js +3 -69
- package/packages/cli/dist/kb-init.js +1 -82
- package/packages/cli/dist/types.js +0 -1
- package/packages/core/dist/constants.js +1 -43
- package/packages/core/dist/content-detector.js +1 -79
- package/packages/core/dist/errors.js +1 -40
- package/packages/core/dist/index.js +1 -9
- package/packages/core/dist/logger.js +1 -34
- package/packages/core/dist/types.js +0 -1
- package/packages/embeddings/dist/embedder.interface.js +0 -1
- package/packages/embeddings/dist/index.js +1 -5
- package/packages/embeddings/dist/onnx-embedder.js +1 -82
- package/packages/indexer/dist/file-hasher.js +1 -13
- package/packages/indexer/dist/filesystem-crawler.js +1 -125
- package/packages/indexer/dist/graph-extractor.js +1 -111
- package/packages/indexer/dist/incremental-indexer.js +1 -278
- package/packages/indexer/dist/index.js +1 -14
- package/packages/server/dist/api.js +1 -9
- package/packages/server/dist/config.js +1 -75
- package/packages/server/dist/curated-manager.js +9 -356
- package/packages/server/dist/index.js +1 -134
- package/packages/server/dist/replay-interceptor.js +1 -38
- package/packages/server/dist/resources/resources.js +2 -40
- package/packages/server/dist/server.js +1 -247
- package/packages/server/dist/tools/analyze.tools.js +1 -288
- package/packages/server/dist/tools/forge.tools.js +11 -499
- package/packages/server/dist/tools/forget.tool.js +3 -39
- package/packages/server/dist/tools/graph.tool.js +5 -110
- package/packages/server/dist/tools/list.tool.js +5 -53
- package/packages/server/dist/tools/lookup.tool.js +8 -51
- package/packages/server/dist/tools/onboard.tool.js +2 -112
- package/packages/server/dist/tools/produce.tool.js +4 -74
- package/packages/server/dist/tools/read.tool.js +4 -47
- package/packages/server/dist/tools/reindex.tool.js +2 -70
- package/packages/server/dist/tools/remember.tool.js +3 -42
- package/packages/server/dist/tools/replay.tool.js +6 -88
- package/packages/server/dist/tools/search.tool.js +17 -327
- package/packages/server/dist/tools/status.tool.js +3 -68
- package/packages/server/dist/tools/toolkit.tools.js +20 -1673
- package/packages/server/dist/tools/update.tool.js +3 -39
- package/packages/server/dist/tools/utility.tools.js +19 -456
- package/packages/store/dist/graph-store.interface.js +0 -1
- package/packages/store/dist/index.js +1 -9
- package/packages/store/dist/lance-store.js +1 -258
- package/packages/store/dist/sqlite-graph-store.js +8 -309
- package/packages/store/dist/store-factory.js +1 -14
- package/packages/store/dist/store.interface.js +0 -1
- package/packages/tools/dist/batch.js +1 -45
- package/packages/tools/dist/changelog.js +2 -112
- package/packages/tools/dist/check.js +2 -59
- package/packages/tools/dist/checkpoint.js +2 -43
- package/packages/tools/dist/codemod.js +2 -69
- package/packages/tools/dist/compact.js +3 -60
- package/packages/tools/dist/data-transform.js +1 -124
- package/packages/tools/dist/dead-symbols.js +2 -71
- package/packages/tools/dist/delegate.js +3 -128
- package/packages/tools/dist/diff-parse.js +3 -153
- package/packages/tools/dist/digest.js +7 -242
- package/packages/tools/dist/encode.js +1 -46
- package/packages/tools/dist/env-info.js +1 -58
- package/packages/tools/dist/eval.js +3 -79
- package/packages/tools/dist/evidence-map.js +3 -203
- package/packages/tools/dist/file-summary.js +2 -106
- package/packages/tools/dist/file-walk.js +1 -75
- package/packages/tools/dist/find-examples.js +3 -48
- package/packages/tools/dist/find.js +1 -120
- package/packages/tools/dist/forge-classify.js +2 -319
- package/packages/tools/dist/forge-ground.js +1 -184
- package/packages/tools/dist/git-context.js +3 -46
- package/packages/tools/dist/graph-query.js +1 -194
- package/packages/tools/dist/health.js +1 -118
- package/packages/tools/dist/http-request.js +1 -58
- package/packages/tools/dist/index.js +1 -273
- package/packages/tools/dist/lane.js +7 -227
- package/packages/tools/dist/measure.js +2 -119
- package/packages/tools/dist/onboard.js +42 -1136
- package/packages/tools/dist/parse-output.js +2 -158
- package/packages/tools/dist/process-manager.js +1 -69
- package/packages/tools/dist/queue.js +2 -126
- package/packages/tools/dist/regex-test.js +1 -39
- package/packages/tools/dist/rename.js +2 -70
- package/packages/tools/dist/replay.js +6 -108
- package/packages/tools/dist/schema-validate.js +1 -141
- package/packages/tools/dist/scope-map.js +1 -72
- package/packages/tools/dist/snippet.js +1 -80
- package/packages/tools/dist/stash.js +2 -60
- package/packages/tools/dist/stratum-card.js +5 -238
- package/packages/tools/dist/symbol.js +3 -87
- package/packages/tools/dist/test-run.js +2 -55
- package/packages/tools/dist/text-utils.js +2 -31
- package/packages/tools/dist/time-utils.js +1 -135
- package/packages/tools/dist/trace.js +2 -114
- package/packages/tools/dist/truncation.js +10 -41
- package/packages/tools/dist/watch.js +1 -61
- package/packages/tools/dist/web-fetch.js +9 -244
- package/packages/tools/dist/web-search.js +1 -46
- package/packages/tools/dist/workset.js +2 -77
- package/packages/tui/dist/App.js +260 -52468
- package/packages/tui/dist/index.js +286 -54551
- package/packages/tui/dist/panels/CuratedPanel.js +211 -34291
- package/packages/tui/dist/panels/LogPanel.js +259 -51703
- package/packages/tui/dist/panels/SearchPanel.js +212 -34824
- package/packages/tui/dist/panels/StatusPanel.js +211 -34304
|
@@ -1,43 +1 @@
|
|
|
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
|
|
1
|
+
const e={markdown:{max:1500,min:100},code:{max:2e3,min:50},config:{max:3e3,min:50},default:{max:1500,min:100,overlap:200}},t={model:"mixedbread-ai/mxbai-embed-large-v1",dimensions:1024},o={backend:"lancedb",path:".kb-data",tableName:"knowledge"},a={maxFileSizeBytes:1e6,maxCuratedFileSizeBytes:5e4},n={maxResults:10,minScore:.25},s=/^[a-z][a-z0-9-]*$/,c=["decisions","patterns","troubleshooting","conventions","architecture"];export{s as CATEGORY_PATTERN,e as CHUNK_SIZES,c as DEFAULT_CATEGORIES,t as EMBEDDING_DEFAULTS,a as FILE_LIMITS,n as SEARCH_DEFAULTS,o as STORE_DEFAULTS};
|
|
@@ -1,79 +1 @@
|
|
|
1
|
-
import
|
|
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
|
|
1
|
+
import{basename as c,extname as r}from"node:path";const o={".ts":"code-typescript",".tsx":"code-typescript",".mts":"code-typescript",".cts":"code-typescript",".js":"code-javascript",".jsx":"code-javascript",".mjs":"code-javascript",".cjs":"code-javascript",".py":"code-python",".json":"config-json",".yaml":"config-yaml",".yml":"config-yaml",".toml":"config-toml",".env":"config-env",".md":"markdown",".mdx":"markdown"},p=[/\.test\.[jt]sx?$/,/\.spec\.[jt]sx?$/,/(^|\/)__tests__\//,/(^|\/)test\//,/(^|\/)tests\//,/(^|\/)spec\//,/(^|\/)fixtures\//],i=[/\.stack\.[jt]s$/,/(^|\/)stacks\//,/(^|\/)constructs\//,/cdk\.json$/];function m(t){const s=r(t).toLowerCase(),n=c(t).toLowerCase();return t.includes("curated/")?"curated-knowledge":p.some(e=>e.test(t))?"test-code":i.some(e=>e.test(t))?"cdk-stack":s in o?o[s]:n.startsWith(".env")?"config-env":[".go",".rs",".java",".rb",".php",".sh",".ps1",".sql",".graphql",".proto",".css",".scss",".less",".html",".htm",".vue",".svelte",".astro",".hbs",".ejs",".svg"].includes(s)?"code-other":"unknown"}export{m as detectContentType};
|
|
@@ -1,40 +1 @@
|
|
|
1
|
-
class
|
|
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
|
|
1
|
+
class s extends Error{constructor(r,e,t){super(r);this.code=e;this.cause=t;this.name="KBError"}}class E extends s{constructor(n,r){super(n,"EMBEDDING_ERROR",r),this.name="EmbeddingError"}}class c extends s{constructor(n,r){super(n,"STORE_ERROR",r),this.name="StoreError"}}class u extends s{constructor(n,r){super(n,"INDEX_ERROR",r),this.name="IndexError"}}class i extends s{constructor(n,r){super(n,"CONFIG_ERROR",r),this.name="ConfigError"}}export{i as ConfigError,E as EmbeddingError,u as IndexError,s as KBError,c as StoreError};
|
|
@@ -1,9 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
import { detectContentType } from "./content-detector.js";
|
|
3
|
-
export * from "./errors.js";
|
|
4
|
-
export * from "./logger.js";
|
|
5
|
-
export * from "./types.js";
|
|
6
|
-
export {
|
|
7
|
-
detectContentType
|
|
8
|
-
};
|
|
9
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export*from"./constants.js";import{detectContentType as t}from"./content-detector.js";export*from"./errors.js";export*from"./logger.js";export*from"./types.js";export{t as detectContentType};
|
|
@@ -1,34 +1 @@
|
|
|
1
|
-
const
|
|
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
|
|
1
|
+
const t={debug:0,info:1,warn:2,error:3};let g=process.env.KB_LOG_LEVEL??"info";function s(o){g=o}function u(o){function e(n,r,i){if(t[n]<t[g])return;const L={ts:new Date().toISOString(),level:n,component:o,msg:r,...i};console.error(JSON.stringify(L))}return{debug:(n,r)=>e("debug",n,r),info:(n,r)=>e("info",n,r),warn:(n,r)=>e("warn",n,r),error:(n,r)=>e("error",n,r)}}export{u as createLogger,s as setLogLevel};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=types.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=embedder.interface.js.map
|
|
@@ -1,82 +1 @@
|
|
|
1
|
-
import
|
|
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
|
|
1
|
+
import{pipeline as m}from"@huggingface/transformers";import{EMBEDDING_DEFAULTS as l}from"../../core/dist/index.js";class h{pipe=null;dimensions;modelId;queryPrefix;constructor(e){this.modelId=e?.model??l.model,this.dimensions=e?.dimensions??l.dimensions,this.queryPrefix=e?.queryPrefix??this.detectQueryPrefix(this.modelId)}detectQueryPrefix(e){const i=e.toLowerCase();return i.includes("bge")||i.includes("mxbai-embed")?"Represent this sentence for searching relevant passages: ":i.includes("/e5-")||i.includes("multilingual-e5")?"query: ":""}async initialize(){if(!this.pipe)try{this.pipe=await m("feature-extraction",this.modelId,{dtype:"fp32"})}catch(e){throw new Error(`Failed to initialize embedding model "${this.modelId}": ${e.message}`)}}async shutdown(){this.pipe=null}async embed(e){this.pipe||await this.initialize();const i=await this.pipe?.(e,{pooling:"mean",normalize:!0});if(!i)throw new Error("Embedding pipeline returned no output");return new Float32Array(i.data)}async embedQuery(e){return this.embed(this.queryPrefix+e)}async embedBatch(e){if(e.length===0)return[];this.pipe||await this.initialize();const i=[],a=32;for(let r=0;r<e.length;r+=a){const t=e.slice(r,r+a),n=await this.pipe?.(t,{pooling:"mean",normalize:!0});if(!n)throw new Error("Embedding pipeline returned no output");if(t.length===1)i.push(new Float32Array(n.data));else for(let s=0;s<t.length;s++){const o=s*this.dimensions,d=n.data.slice(o,o+this.dimensions);i.push(new Float32Array(d))}}return i}}export{h as OnnxEmbedder};
|
|
@@ -1,13 +1 @@
|
|
|
1
|
-
import
|
|
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
|
|
1
|
+
import{createHash as e}from"node:crypto";function i(t){return e("sha256").update(t).digest("hex").slice(0,16)}function o(t,n){const r=`${t}:${n}`;return e("sha256").update(r).digest("hex").slice(0,16)}export{o as generateRecordId,i as hashContent};
|
|
@@ -1,125 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { extname, join, relative } from "node:path";
|
|
3
|
-
import { FILE_LIMITS } from "@kb/core";
|
|
4
|
-
import { minimatch } from "minimatch";
|
|
5
|
-
class FilesystemCrawler {
|
|
6
|
-
/** Binary file extensions that should always be skipped */
|
|
7
|
-
static BINARY_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
8
|
-
".node",
|
|
9
|
-
".so",
|
|
10
|
-
".dylib",
|
|
11
|
-
".dll",
|
|
12
|
-
".wasm",
|
|
13
|
-
".bin",
|
|
14
|
-
".exe",
|
|
15
|
-
".png",
|
|
16
|
-
".jpg",
|
|
17
|
-
".jpeg",
|
|
18
|
-
".gif",
|
|
19
|
-
".bmp",
|
|
20
|
-
".ico",
|
|
21
|
-
".webp",
|
|
22
|
-
".svg",
|
|
23
|
-
".mp3",
|
|
24
|
-
".mp4",
|
|
25
|
-
".wav",
|
|
26
|
-
".avi",
|
|
27
|
-
".mov",
|
|
28
|
-
".flac",
|
|
29
|
-
".zip",
|
|
30
|
-
".gz",
|
|
31
|
-
".tar",
|
|
32
|
-
".bz2",
|
|
33
|
-
".7z",
|
|
34
|
-
".rar",
|
|
35
|
-
".pdf",
|
|
36
|
-
".doc",
|
|
37
|
-
".docx",
|
|
38
|
-
".xls",
|
|
39
|
-
".xlsx",
|
|
40
|
-
".ppt",
|
|
41
|
-
".pptx",
|
|
42
|
-
".ttf",
|
|
43
|
-
".otf",
|
|
44
|
-
".woff",
|
|
45
|
-
".woff2",
|
|
46
|
-
".eot",
|
|
47
|
-
".pyc",
|
|
48
|
-
".class",
|
|
49
|
-
".o",
|
|
50
|
-
".obj",
|
|
51
|
-
".a",
|
|
52
|
-
".lib"
|
|
53
|
-
]);
|
|
54
|
-
async crawl(options) {
|
|
55
|
-
const results = [];
|
|
56
|
-
const visited = /* @__PURE__ */ new Set();
|
|
57
|
-
await this.walkDir(options.rootDir, options.rootDir, options.excludePatterns, results, visited);
|
|
58
|
-
return results;
|
|
59
|
-
}
|
|
60
|
-
async walkDir(dir, rootDir, excludePatterns, results, visited) {
|
|
61
|
-
let entries;
|
|
62
|
-
try {
|
|
63
|
-
entries = await readdir(dir, { withFileTypes: true });
|
|
64
|
-
} catch (err) {
|
|
65
|
-
const code = err.code;
|
|
66
|
-
if (code === "EACCES" || code === "EPERM") {
|
|
67
|
-
console.error(`[KB] Permission denied, skipping directory: ${dir}`);
|
|
68
|
-
}
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
for (const entry of entries) {
|
|
72
|
-
const fullPath = join(dir, entry.name);
|
|
73
|
-
const relPath = relative(rootDir, fullPath).replace(/\\/g, "/");
|
|
74
|
-
if (this.isExcluded(relPath, excludePatterns)) {
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
if (entry.isDirectory()) {
|
|
78
|
-
if (entry.name.startsWith(".")) {
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
try {
|
|
82
|
-
const linkStat = await lstat(fullPath);
|
|
83
|
-
if (linkStat.isSymbolicLink()) {
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
} catch {
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
const realPath = fullPath;
|
|
90
|
-
if (visited.has(realPath)) continue;
|
|
91
|
-
visited.add(realPath);
|
|
92
|
-
await this.walkDir(fullPath, rootDir, excludePatterns, results, visited);
|
|
93
|
-
} else if (entry.isFile()) {
|
|
94
|
-
const ext = extname(entry.name).toLowerCase();
|
|
95
|
-
if (FilesystemCrawler.BINARY_EXTENSIONS.has(ext)) {
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
try {
|
|
99
|
-
const fileStat = await stat(fullPath);
|
|
100
|
-
if (fileStat.size > FILE_LIMITS.maxFileSizeBytes) {
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
const content = await readFile(fullPath, "utf-8");
|
|
104
|
-
if (content.includes("\0")) {
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
results.push({
|
|
108
|
-
relativePath: relPath,
|
|
109
|
-
absolutePath: fullPath,
|
|
110
|
-
content,
|
|
111
|
-
extension: ext
|
|
112
|
-
});
|
|
113
|
-
} catch {
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
isExcluded(relativePath, patterns) {
|
|
119
|
-
return patterns.some((pattern) => minimatch(relativePath, pattern, { dot: true }));
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
export {
|
|
123
|
-
FilesystemCrawler
|
|
124
|
-
};
|
|
125
|
-
//# sourceMappingURL=filesystem-crawler.js.map
|
|
1
|
+
import{lstat as u,readdir as w,readFile as d,stat as g}from"node:fs/promises";import{extname as h,join as x,relative as S}from"node:path";import{FILE_LIMITS as y}from"../../core/dist/index.js";import{minimatch as E}from"minimatch";class p{static BINARY_EXTENSIONS=new Set([".node",".so",".dylib",".dll",".wasm",".bin",".exe",".png",".jpg",".jpeg",".gif",".bmp",".ico",".webp",".svg",".mp3",".mp4",".wav",".avi",".mov",".flac",".zip",".gz",".tar",".bz2",".7z",".rar",".pdf",".doc",".docx",".xls",".xlsx",".ppt",".pptx",".ttf",".otf",".woff",".woff2",".eot",".pyc",".class",".o",".obj",".a",".lib"]);async crawl(e){const i=[],n=new Set;return await this.walkDir(e.rootDir,e.rootDir,e.excludePatterns,i,n),i}async walkDir(e,i,n,s,o){let c;try{c=await w(e,{withFileTypes:!0})}catch(r){const t=r.code;(t==="EACCES"||t==="EPERM")&&console.error(`[KB] Permission denied, skipping directory: ${e}`);return}for(const r of c){const t=x(e,r.name),l=S(i,t).replace(/\\/g,"/");if(!this.isExcluded(l,n)){if(r.isDirectory()){if(r.name.startsWith("."))continue;try{if((await u(t)).isSymbolicLink())continue}catch{continue}const a=t;if(o.has(a))continue;o.add(a),await this.walkDir(t,i,n,s,o)}else if(r.isFile()){const a=h(r.name).toLowerCase();if(p.BINARY_EXTENSIONS.has(a))continue;try{if((await g(t)).size>y.maxFileSizeBytes)continue;const f=await d(t,"utf-8");if(f.includes("\0"))continue;s.push({relativePath:l,absolutePath:t,content:f,extension:a})}catch{}}}}}isExcluded(e,i){return i.some(n=>E(e,n,{dot:!0}))}}export{p as FilesystemCrawler};
|
|
@@ -1,111 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { dirname, extname, join } from "node:path";
|
|
3
|
-
const CODE_EXTENSIONS = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"]);
|
|
4
|
-
const SYMBOL_PATTERNS = [
|
|
5
|
-
// Exported
|
|
6
|
-
{ pattern: /^export\s+(?:async\s+)?function\s+(\w+)/gm, kind: "function", exported: true },
|
|
7
|
-
{ pattern: /^export\s+(?:default\s+)?class\s+(\w+)/gm, kind: "class", exported: true },
|
|
8
|
-
{ pattern: /^export\s+interface\s+(\w+)/gm, kind: "interface", exported: true },
|
|
9
|
-
{ pattern: /^export\s+type\s+(\w+)/gm, kind: "type", exported: true },
|
|
10
|
-
{ pattern: /^export\s+(?:const|let)\s+(\w+)/gm, kind: "const", exported: true },
|
|
11
|
-
{ pattern: /^export\s+enum\s+(\w+)/gm, kind: "enum", exported: true },
|
|
12
|
-
// Non-exported (top-level only)
|
|
13
|
-
{ pattern: /^(?:async\s+)?function\s+(\w+)/gm, kind: "function", exported: false },
|
|
14
|
-
{ pattern: /^class\s+(\w+)/gm, kind: "class", exported: false },
|
|
15
|
-
{ pattern: /^interface\s+(\w+)/gm, kind: "interface", exported: false },
|
|
16
|
-
{ pattern: /^type\s+(\w+)/gm, kind: "type", exported: false },
|
|
17
|
-
{ pattern: /^enum\s+(\w+)/gm, kind: "enum", exported: false }
|
|
18
|
-
];
|
|
19
|
-
const IMPORT_PATTERNS = [
|
|
20
|
-
// ES import: import { x } from 'module' / import x from 'module' / import type { x } from '...'
|
|
21
|
-
/import\s+(?:(?:type\s+)?(?:(?:\{[^}]*\}|[\w*]+)\s+from\s+)?)['"]([^'"]+)['"]/g,
|
|
22
|
-
// Dynamic import: import('module')
|
|
23
|
-
/import\(\s*['"]([^'"]+)['"]\s*\)/g,
|
|
24
|
-
// CommonJS require: require('module')
|
|
25
|
-
/require\(\s*['"]([^'"]+)['"]\s*\)/g
|
|
26
|
-
];
|
|
27
|
-
function nodeId(type, name, sourcePath) {
|
|
28
|
-
return createHash("sha256").update(`${type}:${name}:${sourcePath}`).digest("hex").slice(0, 16);
|
|
29
|
-
}
|
|
30
|
-
function edgeId(fromId, toId, type) {
|
|
31
|
-
return createHash("sha256").update(`${fromId}-${type}-${toId}`).digest("hex").slice(0, 16);
|
|
32
|
-
}
|
|
33
|
-
function resolveImportPath(importSource, fromPath) {
|
|
34
|
-
const dir = dirname(fromPath);
|
|
35
|
-
const resolved = join(dir, importSource).replace(/\\/g, "/");
|
|
36
|
-
return resolved.replace(/\.(js|jsx|ts|tsx|mjs|cjs)$/, "");
|
|
37
|
-
}
|
|
38
|
-
function moduleKey(sourcePath) {
|
|
39
|
-
return sourcePath.replace(/\.(js|jsx|ts|tsx|mjs|cjs)$/, "");
|
|
40
|
-
}
|
|
41
|
-
function extractGraph(content, sourcePath) {
|
|
42
|
-
const ext = extname(sourcePath).toLowerCase();
|
|
43
|
-
if (!CODE_EXTENSIONS.has(ext)) {
|
|
44
|
-
return { nodes: [], edges: [] };
|
|
45
|
-
}
|
|
46
|
-
const nodes = [];
|
|
47
|
-
const edges = [];
|
|
48
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
49
|
-
const seenSymbols = /* @__PURE__ */ new Set();
|
|
50
|
-
const mk = moduleKey(sourcePath);
|
|
51
|
-
const modId = nodeId("module", mk, mk);
|
|
52
|
-
nodes.push({
|
|
53
|
-
id: modId,
|
|
54
|
-
type: "module",
|
|
55
|
-
name: sourcePath,
|
|
56
|
-
properties: { ext },
|
|
57
|
-
sourcePath,
|
|
58
|
-
createdAt: now
|
|
59
|
-
});
|
|
60
|
-
for (const { pattern, kind, exported } of SYMBOL_PATTERNS) {
|
|
61
|
-
const regex = new RegExp(pattern.source, pattern.flags);
|
|
62
|
-
let match;
|
|
63
|
-
while ((match = regex.exec(content)) !== null) {
|
|
64
|
-
const name = match[1];
|
|
65
|
-
const key = `${kind}:${name}`;
|
|
66
|
-
if (seenSymbols.has(key)) continue;
|
|
67
|
-
seenSymbols.add(key);
|
|
68
|
-
const symId = nodeId(kind, name, sourcePath);
|
|
69
|
-
nodes.push({
|
|
70
|
-
id: symId,
|
|
71
|
-
type: kind,
|
|
72
|
-
name,
|
|
73
|
-
properties: { exported },
|
|
74
|
-
sourcePath,
|
|
75
|
-
createdAt: now
|
|
76
|
-
});
|
|
77
|
-
edges.push({
|
|
78
|
-
id: edgeId(modId, symId, "defines"),
|
|
79
|
-
fromId: modId,
|
|
80
|
-
toId: symId,
|
|
81
|
-
type: "defines",
|
|
82
|
-
weight: exported ? 1 : 0.5
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
const seenImports = /* @__PURE__ */ new Set();
|
|
87
|
-
for (const pattern of IMPORT_PATTERNS) {
|
|
88
|
-
const regex = new RegExp(pattern.source, pattern.flags);
|
|
89
|
-
let match;
|
|
90
|
-
while ((match = regex.exec(content)) !== null) {
|
|
91
|
-
const source = match[1];
|
|
92
|
-
if (!source.startsWith(".")) continue;
|
|
93
|
-
if (seenImports.has(source)) continue;
|
|
94
|
-
seenImports.add(source);
|
|
95
|
-
const targetKey = resolveImportPath(source, sourcePath);
|
|
96
|
-
const targetModId = nodeId("module", targetKey, targetKey);
|
|
97
|
-
edges.push({
|
|
98
|
-
id: edgeId(modId, targetModId, "imports"),
|
|
99
|
-
fromId: modId,
|
|
100
|
-
toId: targetModId,
|
|
101
|
-
type: "imports",
|
|
102
|
-
properties: { source }
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return { nodes, edges };
|
|
107
|
-
}
|
|
108
|
-
export {
|
|
109
|
-
extractGraph
|
|
110
|
-
};
|
|
111
|
-
//# sourceMappingURL=graph-extractor.js.map
|
|
1
|
+
import{createHash as y}from"node:crypto";import{dirname as k,extname as j,join as I}from"node:path";const S=new Set([".ts",".tsx",".js",".jsx",".mjs",".cjs"]),$=[{pattern:/^export\s+(?:async\s+)?function\s+(\w+)/gm,kind:"function",exported:!0},{pattern:/^export\s+(?:default\s+)?class\s+(\w+)/gm,kind:"class",exported:!0},{pattern:/^export\s+interface\s+(\w+)/gm,kind:"interface",exported:!0},{pattern:/^export\s+type\s+(\w+)/gm,kind:"type",exported:!0},{pattern:/^export\s+(?:const|let)\s+(\w+)/gm,kind:"const",exported:!0},{pattern:/^export\s+enum\s+(\w+)/gm,kind:"enum",exported:!0},{pattern:/^(?:async\s+)?function\s+(\w+)/gm,kind:"function",exported:!1},{pattern:/^class\s+(\w+)/gm,kind:"class",exported:!1},{pattern:/^interface\s+(\w+)/gm,kind:"interface",exported:!1},{pattern:/^type\s+(\w+)/gm,kind:"type",exported:!1},{pattern:/^enum\s+(\w+)/gm,kind:"enum",exported:!1}],G=[/import\s+(?:(?:type\s+)?(?:(?:\{[^}]*\}|[\w*]+)\s+from\s+)?)['"]([^'"]+)['"]/g,/import\(\s*['"]([^'"]+)['"]\s*\)/g,/require\(\s*['"]([^'"]+)['"]\s*\)/g];function x(t,e,s){return y("sha256").update(`${t}:${e}:${s}`).digest("hex").slice(0,16)}function E(t,e,s){return y("sha256").update(`${t}-${s}-${e}`).digest("hex").slice(0,16)}function R(t,e){const s=k(e);return I(s,t).replace(/\\/g,"/").replace(/\.(js|jsx|ts|tsx|mjs|cjs)$/,"")}function N(t){return t.replace(/\.(js|jsx|ts|tsx|mjs|cjs)$/,"")}function O(t,e){const s=j(e).toLowerCase();if(!S.has(s))return{nodes:[],edges:[]};const c=[],g=[],l=new Date().toISOString(),u=new Set,f=N(e),o=x("module",f,f);c.push({id:o,type:"module",name:e,properties:{ext:s},sourcePath:e,createdAt:l});for(const{pattern:i,kind:p,exported:d}of $){const n=new RegExp(i.source,i.flags);let a;for(;(a=n.exec(t))!==null;){const r=a[1],h=`${p}:${r}`;if(u.has(h))continue;u.add(h);const m=x(p,r,e);c.push({id:m,type:p,name:r,properties:{exported:d},sourcePath:e,createdAt:l}),g.push({id:E(o,m,"defines"),fromId:o,toId:m,type:"defines",weight:d?1:.5})}}const w=new Set;for(const i of G){const p=new RegExp(i.source,i.flags);let d;for(;(d=p.exec(t))!==null;){const n=d[1];if(!n.startsWith(".")||w.has(n))continue;w.add(n);const a=R(n,e),r=x("module",a,a);g.push({id:E(o,r,"imports"),fromId:o,toId:r,type:"imports",properties:{source:n}})}}return{nodes:c,edges:g}}export{O as extractGraph};
|