@vpxa/kb 0.1.1 → 0.1.2
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/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.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,234 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
".js": { package: "tree-sitter-javascript" },
|
|
10
|
-
".jsx": { package: "tree-sitter-javascript" },
|
|
11
|
-
".mjs": { package: "tree-sitter-javascript" },
|
|
12
|
-
".cjs": { package: "tree-sitter-javascript" },
|
|
13
|
-
".py": { package: "tree-sitter-python" },
|
|
14
|
-
".go": { package: "tree-sitter-go" },
|
|
15
|
-
".rs": { package: "tree-sitter-rust" },
|
|
16
|
-
".java": { package: "tree-sitter-java" }
|
|
17
|
-
};
|
|
18
|
-
const DECLARATION_TYPES = /* @__PURE__ */ new Set([
|
|
19
|
-
// TypeScript / JavaScript
|
|
20
|
-
"function_declaration",
|
|
21
|
-
"class_declaration",
|
|
22
|
-
"interface_declaration",
|
|
23
|
-
"type_alias_declaration",
|
|
24
|
-
"enum_declaration",
|
|
25
|
-
"lexical_declaration",
|
|
26
|
-
"export_statement",
|
|
27
|
-
"variable_declaration",
|
|
28
|
-
"abstract_class_declaration",
|
|
29
|
-
// Python
|
|
30
|
-
"function_definition",
|
|
31
|
-
"class_definition",
|
|
32
|
-
"decorated_definition",
|
|
33
|
-
// Go
|
|
34
|
-
"function_declaration",
|
|
35
|
-
"method_declaration",
|
|
36
|
-
"type_declaration",
|
|
37
|
-
// Rust
|
|
38
|
-
"function_item",
|
|
39
|
-
"impl_item",
|
|
40
|
-
"struct_item",
|
|
41
|
-
"enum_item",
|
|
42
|
-
"trait_item",
|
|
43
|
-
"mod_item",
|
|
44
|
-
"type_item",
|
|
45
|
-
// Java
|
|
46
|
-
"class_declaration",
|
|
47
|
-
"interface_declaration",
|
|
48
|
-
"method_declaration",
|
|
49
|
-
"enum_declaration"
|
|
50
|
-
]);
|
|
51
|
-
class TreeSitterRuntime {
|
|
52
|
-
static instance = null;
|
|
53
|
-
// biome-ignore lint/suspicious/noExplicitAny: tree-sitter parser has no published types
|
|
54
|
-
parser = null;
|
|
55
|
-
// biome-ignore lint/suspicious/noExplicitAny: tree-sitter language has no published types
|
|
56
|
-
languages = /* @__PURE__ */ new Map();
|
|
57
|
-
static async initialize() {
|
|
58
|
-
if (TreeSitterRuntime.instance) return TreeSitterRuntime.instance;
|
|
59
|
-
const runtime = new TreeSitterRuntime();
|
|
60
|
-
if (await runtime.init()) {
|
|
61
|
-
TreeSitterRuntime.instance = runtime;
|
|
62
|
-
return runtime;
|
|
63
|
-
}
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
static get() {
|
|
67
|
-
return TreeSitterRuntime.instance;
|
|
68
|
-
}
|
|
69
|
-
async init() {
|
|
70
|
-
try {
|
|
71
|
-
const parserMod = await import("tree-sitter");
|
|
72
|
-
const ParserClass = parserMod.default ?? parserMod;
|
|
73
|
-
this.parser = new ParserClass();
|
|
74
|
-
for (const [ext, config] of Object.entries(LANGUAGE_MODULES)) {
|
|
75
|
-
try {
|
|
76
|
-
const mod = await import(config.package);
|
|
77
|
-
const resolved = mod.default ?? mod;
|
|
78
|
-
const lang = config.subLanguage ? resolved[config.subLanguage] : resolved;
|
|
79
|
-
if (lang) this.languages.set(ext, lang);
|
|
80
|
-
} catch {
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
const loaded = this.languages.size > 0;
|
|
84
|
-
if (loaded) {
|
|
85
|
-
console.error(
|
|
86
|
-
`[KB] Tree-sitter initialized with ${this.languages.size} languages: ${[...this.languages.keys()].join(", ")}`
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
return loaded;
|
|
90
|
-
} catch {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
/** Parse source code with the grammar for the given file extension. */
|
|
95
|
-
// biome-ignore lint/suspicious/noExplicitAny: tree-sitter tree has no published types
|
|
96
|
-
parse(content, ext) {
|
|
97
|
-
const lang = this.languages.get(ext);
|
|
98
|
-
if (!lang) return null;
|
|
99
|
-
this.parser.setLanguage(lang);
|
|
100
|
-
return this.parser.parse(content);
|
|
101
|
-
}
|
|
102
|
-
/** Check if a grammar is loaded for the given file extension. */
|
|
103
|
-
hasLanguage(ext) {
|
|
104
|
-
return this.languages.has(ext);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
async function initializeTreeSitter() {
|
|
108
|
-
const runtime = await TreeSitterRuntime.initialize();
|
|
109
|
-
return runtime !== null;
|
|
110
|
-
}
|
|
111
|
-
class TreeSitterChunker {
|
|
112
|
-
maxChunkSize;
|
|
113
|
-
runtime;
|
|
114
|
-
regexFallback;
|
|
115
|
-
constructor(runtime, options) {
|
|
116
|
-
this.runtime = runtime;
|
|
117
|
-
this.maxChunkSize = options?.maxChunkSize ?? CHUNK_SIZES.code.max;
|
|
118
|
-
this.regexFallback = new CodeChunker(options);
|
|
119
|
-
}
|
|
120
|
-
chunk(content, metadata) {
|
|
121
|
-
const ext = extname(metadata.sourcePath).toLowerCase();
|
|
122
|
-
const tree = this.runtime.parse(content, ext);
|
|
123
|
-
if (!tree) {
|
|
124
|
-
return this.regexFallback.chunk(content, metadata);
|
|
125
|
-
}
|
|
126
|
-
try {
|
|
127
|
-
return this.chunkFromAst(tree, content, metadata);
|
|
128
|
-
} catch {
|
|
129
|
-
return this.regexFallback.chunk(content, metadata);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
// biome-ignore lint/suspicious/noExplicitAny: tree-sitter tree has no published types
|
|
133
|
-
chunkFromAst(tree, content, metadata) {
|
|
134
|
-
const rootNode = tree.rootNode;
|
|
135
|
-
const chunks = [];
|
|
136
|
-
const declarations = [];
|
|
137
|
-
for (let i = 0; i < rootNode.childCount; i++) {
|
|
138
|
-
const child = rootNode.child(i);
|
|
139
|
-
if (!child) continue;
|
|
140
|
-
if (DECLARATION_TYPES.has(child.type)) {
|
|
141
|
-
let startByte = child.startPosition ? child.startIndex : child.startByte ?? 0;
|
|
142
|
-
let startRow = child.startPosition?.row ?? 0;
|
|
143
|
-
let prev = child.previousSibling;
|
|
144
|
-
while (prev && (prev.type === "comment" || prev.type === "line_comment" || prev.type === "block_comment" || prev.type === "decorator")) {
|
|
145
|
-
startByte = prev.startIndex ?? prev.startByte ?? startByte;
|
|
146
|
-
startRow = prev.startPosition?.row ?? startRow;
|
|
147
|
-
prev = prev.previousSibling;
|
|
148
|
-
}
|
|
149
|
-
declarations.push({
|
|
150
|
-
startByte,
|
|
151
|
-
endByte: child.endIndex ?? child.endByte ?? content.length,
|
|
152
|
-
startRow,
|
|
153
|
-
endRow: child.endPosition?.row ?? content.split("\n").length - 1
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
if (declarations.length === 0) {
|
|
158
|
-
return this.regexFallback.chunk(content, metadata);
|
|
159
|
-
}
|
|
160
|
-
if (declarations[0].startByte > 0) {
|
|
161
|
-
const preamble = content.slice(0, declarations[0].startByte).trim();
|
|
162
|
-
if (preamble.length > 0) {
|
|
163
|
-
chunks.push({
|
|
164
|
-
text: `// File: ${metadata.sourcePath}
|
|
165
|
-
${preamble}`,
|
|
166
|
-
sourcePath: metadata.sourcePath,
|
|
167
|
-
contentType: metadata.contentType,
|
|
168
|
-
chunkIndex: 0,
|
|
169
|
-
totalChunks: 0,
|
|
170
|
-
startLine: 1,
|
|
171
|
-
endLine: declarations[0].startRow + 1
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
for (const decl of declarations) {
|
|
176
|
-
let text = content.slice(decl.startByte, decl.endByte).trim();
|
|
177
|
-
const header = `// File: ${metadata.sourcePath}
|
|
178
|
-
`;
|
|
179
|
-
text = header + text;
|
|
180
|
-
if (text.length > this.maxChunkSize) {
|
|
181
|
-
const subChunks = this.splitByLines(text, this.maxChunkSize);
|
|
182
|
-
let currentLine = decl.startRow + 1;
|
|
183
|
-
for (const sub of subChunks) {
|
|
184
|
-
const subLines = sub.split("\n").length;
|
|
185
|
-
chunks.push({
|
|
186
|
-
text: sub,
|
|
187
|
-
sourcePath: metadata.sourcePath,
|
|
188
|
-
contentType: metadata.contentType,
|
|
189
|
-
chunkIndex: chunks.length,
|
|
190
|
-
totalChunks: 0,
|
|
191
|
-
startLine: currentLine,
|
|
192
|
-
endLine: currentLine + subLines - 1
|
|
193
|
-
});
|
|
194
|
-
currentLine += subLines;
|
|
195
|
-
}
|
|
196
|
-
} else {
|
|
197
|
-
chunks.push({
|
|
198
|
-
text,
|
|
199
|
-
sourcePath: metadata.sourcePath,
|
|
200
|
-
contentType: metadata.contentType,
|
|
201
|
-
chunkIndex: chunks.length,
|
|
202
|
-
totalChunks: 0,
|
|
203
|
-
startLine: decl.startRow + 1,
|
|
204
|
-
endLine: decl.endRow + 1
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
return chunks.map((c, i) => ({ ...c, chunkIndex: i, totalChunks: chunks.length }));
|
|
209
|
-
}
|
|
210
|
-
splitByLines(text, maxSize) {
|
|
211
|
-
const lines = text.split("\n");
|
|
212
|
-
const result = [];
|
|
213
|
-
let current = [];
|
|
214
|
-
let currentSize = 0;
|
|
215
|
-
for (const line of lines) {
|
|
216
|
-
if (currentSize + line.length + 1 > maxSize && current.length > 0) {
|
|
217
|
-
result.push(current.join("\n"));
|
|
218
|
-
current = [line];
|
|
219
|
-
currentSize = line.length;
|
|
220
|
-
} else {
|
|
221
|
-
current.push(line);
|
|
222
|
-
currentSize += line.length + 1;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
if (current.length > 0) result.push(current.join("\n"));
|
|
226
|
-
return result;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
export {
|
|
230
|
-
TreeSitterChunker,
|
|
231
|
-
TreeSitterRuntime,
|
|
232
|
-
initializeTreeSitter
|
|
233
|
-
};
|
|
234
|
-
//# sourceMappingURL=treesitter-chunker.js.map
|
|
1
|
+
import{extname as m}from"node:path";import{CHUNK_SIZES as k}from"@kb/core";import{CodeChunker as y}from"./code-chunker.js";const f={".ts":{package:"tree-sitter-typescript",subLanguage:"typescript"},".tsx":{package:"tree-sitter-typescript",subLanguage:"tsx"},".mts":{package:"tree-sitter-typescript",subLanguage:"typescript"},".cts":{package:"tree-sitter-typescript",subLanguage:"typescript"},".js":{package:"tree-sitter-javascript"},".jsx":{package:"tree-sitter-javascript"},".mjs":{package:"tree-sitter-javascript"},".cjs":{package:"tree-sitter-javascript"},".py":{package:"tree-sitter-python"},".go":{package:"tree-sitter-go"},".rs":{package:"tree-sitter-rust"},".java":{package:"tree-sitter-java"}},b=new Set(["function_declaration","class_declaration","interface_declaration","type_alias_declaration","enum_declaration","lexical_declaration","export_statement","variable_declaration","abstract_class_declaration","function_definition","class_definition","decorated_definition","function_declaration","method_declaration","type_declaration","function_item","impl_item","struct_item","enum_item","trait_item","mod_item","type_item","class_declaration","interface_declaration","method_declaration","enum_declaration"]);class u{static instance=null;parser=null;languages=new Map;static async initialize(){if(u.instance)return u.instance;const t=new u;return await t.init()?(u.instance=t,t):null}static get(){return u.instance}async init(){try{const t=await import("tree-sitter"),r=t.default??t;this.parser=new r;for(const[c,s]of Object.entries(f))try{const o=await import(s.package),e=o.default??o,n=s.subLanguage?e[s.subLanguage]:e;n&&this.languages.set(c,n)}catch{}const i=this.languages.size>0;return i&&console.error(`[KB] Tree-sitter initialized with ${this.languages.size} languages: ${[...this.languages.keys()].join(", ")}`),i}catch{return!1}}parse(t,r){const i=this.languages.get(r);return i?(this.parser.setLanguage(i),this.parser.parse(t)):null}hasLanguage(t){return this.languages.has(t)}}async function w(){return await u.initialize()!==null}class L{maxChunkSize;runtime;regexFallback;constructor(t,r){this.runtime=t,this.maxChunkSize=r?.maxChunkSize??k.code.max,this.regexFallback=new y(r)}chunk(t,r){const i=m(r.sourcePath).toLowerCase(),c=this.runtime.parse(t,i);if(!c)return this.regexFallback.chunk(t,r);try{return this.chunkFromAst(c,t,r)}catch{return this.regexFallback.chunk(t,r)}}chunkFromAst(t,r,i){const c=t.rootNode,s=[],o=[];for(let e=0;e<c.childCount;e++){const n=c.child(e);if(n&&b.has(n.type)){let h=n.startPosition?n.startIndex:n.startByte??0,l=n.startPosition?.row??0,a=n.previousSibling;for(;a&&(a.type==="comment"||a.type==="line_comment"||a.type==="block_comment"||a.type==="decorator");)h=a.startIndex??a.startByte??h,l=a.startPosition?.row??l,a=a.previousSibling;o.push({startByte:h,endByte:n.endIndex??n.endByte??r.length,startRow:l,endRow:n.endPosition?.row??r.split(`
|
|
2
|
+
`).length-1})}}if(o.length===0)return this.regexFallback.chunk(r,i);if(o[0].startByte>0){const e=r.slice(0,o[0].startByte).trim();e.length>0&&s.push({text:`// File: ${i.sourcePath}
|
|
3
|
+
${e}`,sourcePath:i.sourcePath,contentType:i.contentType,chunkIndex:0,totalChunks:0,startLine:1,endLine:o[0].startRow+1})}for(const e of o){let n=r.slice(e.startByte,e.endByte).trim();if(n=`// File: ${i.sourcePath}
|
|
4
|
+
`+n,n.length>this.maxChunkSize){const l=this.splitByLines(n,this.maxChunkSize);let a=e.startRow+1;for(const p of l){const g=p.split(`
|
|
5
|
+
`).length;s.push({text:p,sourcePath:i.sourcePath,contentType:i.contentType,chunkIndex:s.length,totalChunks:0,startLine:a,endLine:a+g-1}),a+=g}}else s.push({text:n,sourcePath:i.sourcePath,contentType:i.contentType,chunkIndex:s.length,totalChunks:0,startLine:e.startRow+1,endLine:e.endRow+1})}return s.map((e,n)=>({...e,chunkIndex:n,totalChunks:s.length}))}splitByLines(t,r){const i=t.split(`
|
|
6
|
+
`),c=[];let s=[],o=0;for(const e of i)o+e.length+1>r&&s.length>0?(c.push(s.join(`
|
|
7
|
+
`)),s=[e],o=e.length):(s.push(e),o+=e.length+1);return s.length>0&&c.push(s.join(`
|
|
8
|
+
`)),c}}export{L as TreeSitterChunker,u as TreeSitterRuntime,w as initializeTreeSitter};
|
|
@@ -1,112 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
name: "analyze",
|
|
5
|
-
description: "Run analyzer output for a path",
|
|
6
|
-
usage: "kb analyze <type> <path>",
|
|
7
|
-
run: async (args) => {
|
|
8
|
-
const type = args.shift()?.trim() ?? "";
|
|
9
|
-
const targetPath = args.shift()?.trim() ?? "";
|
|
10
|
-
if (!type || !targetPath) {
|
|
11
|
-
console.error("Usage: kb analyze <type> <path>");
|
|
12
|
-
console.error(
|
|
13
|
-
"Types: structure, deps, symbols, patterns, entry-points, blast-radius, diagram"
|
|
14
|
-
);
|
|
15
|
-
process.exit(1);
|
|
16
|
-
}
|
|
17
|
-
const {
|
|
18
|
-
BlastRadiusAnalyzer,
|
|
19
|
-
DependencyAnalyzer,
|
|
20
|
-
DiagramGenerator,
|
|
21
|
-
EntryPointAnalyzer,
|
|
22
|
-
PatternAnalyzer,
|
|
23
|
-
StructureAnalyzer,
|
|
24
|
-
SymbolAnalyzer
|
|
25
|
-
} = await import("@kb/analyzers");
|
|
26
|
-
const absolutePath = resolve(targetPath);
|
|
27
|
-
let result;
|
|
28
|
-
switch (type) {
|
|
29
|
-
case "structure":
|
|
30
|
-
result = await new StructureAnalyzer().analyze(absolutePath, { format: "markdown" });
|
|
31
|
-
break;
|
|
32
|
-
case "deps":
|
|
33
|
-
case "dependencies":
|
|
34
|
-
result = await new DependencyAnalyzer().analyze(absolutePath, { format: "markdown" });
|
|
35
|
-
break;
|
|
36
|
-
case "symbols":
|
|
37
|
-
result = await new SymbolAnalyzer().analyze(absolutePath, { format: "markdown" });
|
|
38
|
-
break;
|
|
39
|
-
case "patterns":
|
|
40
|
-
result = await new PatternAnalyzer().analyze(absolutePath, { format: "markdown" });
|
|
41
|
-
break;
|
|
42
|
-
case "entry-points":
|
|
43
|
-
result = await new EntryPointAnalyzer().analyze(absolutePath, { format: "markdown" });
|
|
44
|
-
break;
|
|
45
|
-
case "blast-radius":
|
|
46
|
-
result = await new BlastRadiusAnalyzer().analyze(process.cwd(), {
|
|
47
|
-
files: [targetPath],
|
|
48
|
-
format: "markdown"
|
|
49
|
-
});
|
|
50
|
-
break;
|
|
51
|
-
case "diagram":
|
|
52
|
-
result = await new DiagramGenerator().analyze(absolutePath, {
|
|
53
|
-
diagramType: "architecture"
|
|
54
|
-
});
|
|
55
|
-
break;
|
|
56
|
-
default:
|
|
57
|
-
console.error(`Unknown analyze type: ${type}`);
|
|
58
|
-
console.error(
|
|
59
|
-
"Types: structure, deps, symbols, patterns, entry-points, blast-radius, diagram"
|
|
60
|
-
);
|
|
61
|
-
process.exit(1);
|
|
62
|
-
}
|
|
63
|
-
console.log(result.output);
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
name: "onboard",
|
|
68
|
-
description: "Run all analyses for first-time codebase onboarding",
|
|
69
|
-
usage: "kb onboard <path> [--generate] [--out-dir <dir>]",
|
|
70
|
-
run: async (args) => {
|
|
71
|
-
const { onboard } = await import("@kb/tools");
|
|
72
|
-
let targetPath = "";
|
|
73
|
-
let mode = "memory";
|
|
74
|
-
let outDir;
|
|
75
|
-
for (let i = 0; i < args.length; i++) {
|
|
76
|
-
const arg = args[i].trim();
|
|
77
|
-
if (arg === "--generate") {
|
|
78
|
-
mode = "generate";
|
|
79
|
-
} else if (arg === "--out-dir" && i + 1 < args.length) {
|
|
80
|
-
outDir = args[++i].trim();
|
|
81
|
-
} else if (!arg.startsWith("--")) {
|
|
82
|
-
targetPath = arg;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (!targetPath) {
|
|
86
|
-
targetPath = process.cwd();
|
|
87
|
-
}
|
|
88
|
-
const absolutePath = resolve(targetPath);
|
|
89
|
-
console.log(`Onboarding: ${absolutePath} (mode: ${mode})`);
|
|
90
|
-
console.log("Running analyses...\n");
|
|
91
|
-
const result = await onboard({
|
|
92
|
-
path: absolutePath,
|
|
93
|
-
mode,
|
|
94
|
-
outDir
|
|
95
|
-
});
|
|
96
|
-
for (const step of result.steps) {
|
|
97
|
-
const icon = step.status === "success" ? "\u2713" : "\u2717";
|
|
98
|
-
const info = step.status === "success" ? `${step.durationMs}ms, ${step.output.length} chars` : step.error;
|
|
99
|
-
console.log(` ${icon} ${step.name} \u2014 ${info}`);
|
|
100
|
-
}
|
|
101
|
-
console.log(`
|
|
102
|
-
Total: ${result.totalDurationMs}ms`);
|
|
103
|
-
if (result.outDir) {
|
|
104
|
-
console.log(`Output written to: ${result.outDir}`);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
];
|
|
109
|
-
export {
|
|
110
|
-
analyzeCommands
|
|
111
|
-
};
|
|
112
|
-
//# sourceMappingURL=analyze.js.map
|
|
1
|
+
import{resolve as p}from"node:path";const d=[{name:"analyze",description:"Run analyzer output for a path",usage:"kb analyze <type> <path>",run:async r=>{const i=r.shift()?.trim()??"",a=r.shift()?.trim()??"";(!i||!a)&&(console.error("Usage: kb analyze <type> <path>"),console.error("Types: structure, deps, symbols, patterns, entry-points, blast-radius, diagram"),process.exit(1));const{BlastRadiusAnalyzer:l,DependencyAnalyzer:c,DiagramGenerator:m,EntryPointAnalyzer:n,PatternAnalyzer:e,StructureAnalyzer:t,SymbolAnalyzer:u}=await import("@kb/analyzers"),s=p(a);let o;switch(i){case"structure":o=await new t().analyze(s,{format:"markdown"});break;case"deps":case"dependencies":o=await new c().analyze(s,{format:"markdown"});break;case"symbols":o=await new u().analyze(s,{format:"markdown"});break;case"patterns":o=await new e().analyze(s,{format:"markdown"});break;case"entry-points":o=await new n().analyze(s,{format:"markdown"});break;case"blast-radius":o=await new l().analyze(process.cwd(),{files:[a],format:"markdown"});break;case"diagram":o=await new m().analyze(s,{diagramType:"architecture"});break;default:console.error(`Unknown analyze type: ${i}`),console.error("Types: structure, deps, symbols, patterns, entry-points, blast-radius, diagram"),process.exit(1)}console.log(o.output)}},{name:"onboard",description:"Run all analyses for first-time codebase onboarding",usage:"kb onboard <path> [--generate] [--out-dir <dir>]",run:async r=>{const{onboard:i}=await import("@kb/tools");let a="",l="memory",c;for(let e=0;e<r.length;e++){const t=r[e].trim();t==="--generate"?l="generate":t==="--out-dir"&&e+1<r.length?c=r[++e].trim():t.startsWith("--")||(a=t)}a||(a=process.cwd());const m=p(a);console.log(`Onboarding: ${m} (mode: ${l})`),console.log(`Running analyses...
|
|
2
|
+
`);const n=await i({path:m,mode:l,outDir:c});for(const e of n.steps){const t=e.status==="success"?"\u2713":"\u2717",u=e.status==="success"?`${e.durationMs}ms, ${e.output.length} chars`:e.error;console.log(` ${t} ${e.name} \u2014 ${u}`)}console.log(`
|
|
3
|
+
Total: ${n.totalDurationMs}ms`),n.outDir&&console.log(`Output written to: ${n.outDir}`)}}];export{d as analyzeCommands};
|
|
@@ -1,155 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
checkpointLatest,
|
|
4
|
-
checkpointList,
|
|
5
|
-
checkpointLoad,
|
|
6
|
-
checkpointSave,
|
|
7
|
-
diffParse,
|
|
8
|
-
fileSummary,
|
|
9
|
-
gitContext,
|
|
10
|
-
parseOutput
|
|
11
|
-
} from "@kb/tools";
|
|
12
|
-
import {
|
|
13
|
-
extractBoolFlag,
|
|
14
|
-
extractNumFlag,
|
|
15
|
-
extractStrFlag,
|
|
16
|
-
parseRecordString,
|
|
17
|
-
printCheckpoint,
|
|
18
|
-
printDiffFiles,
|
|
19
|
-
printFileSummary,
|
|
20
|
-
printGitContext,
|
|
21
|
-
printParsedOutput,
|
|
22
|
-
readStdin
|
|
23
|
-
} from "../helpers.js";
|
|
24
|
-
const contextCommands = [
|
|
25
|
-
{
|
|
26
|
-
name: "parse-output",
|
|
27
|
-
description: "Parse build or tool output from stdin",
|
|
28
|
-
usage: "kb parse-output [--tool tsc|vitest|biome|git-status]",
|
|
29
|
-
run: async (args) => {
|
|
30
|
-
const tool = extractStrFlag(args, "--tool", "").trim() || void 0;
|
|
31
|
-
const input = await readStdin();
|
|
32
|
-
if (!input.trim()) {
|
|
33
|
-
console.error("Usage: kb parse-output [--tool tsc|vitest|biome|git-status]");
|
|
34
|
-
process.exit(1);
|
|
35
|
-
}
|
|
36
|
-
printParsedOutput(parseOutput(input, tool));
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
name: "git",
|
|
41
|
-
description: "Show git branch, status, recent commits, and optional diff stats",
|
|
42
|
-
usage: "kb git [--cwd path] [--commit-count N] [--diff]",
|
|
43
|
-
run: async (args) => {
|
|
44
|
-
const cwd = extractStrFlag(args, "--cwd", "").trim() || void 0;
|
|
45
|
-
const commitCount = extractNumFlag(args, "--commit-count", 5);
|
|
46
|
-
const includeDiff = extractBoolFlag(args, "--diff");
|
|
47
|
-
const result = await gitContext({ cwd, commitCount, includeDiff });
|
|
48
|
-
printGitContext(result);
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
name: "diff",
|
|
53
|
-
description: "Parse unified diff text from stdin into structured file changes",
|
|
54
|
-
usage: "git diff | kb diff",
|
|
55
|
-
run: async () => {
|
|
56
|
-
const input = await readStdin();
|
|
57
|
-
if (!input.trim()) {
|
|
58
|
-
console.error("Usage: git diff | kb diff");
|
|
59
|
-
process.exit(1);
|
|
60
|
-
}
|
|
61
|
-
printDiffFiles(diffParse({ diff: input }));
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
name: "summarize",
|
|
66
|
-
description: "Show a structural summary of a file",
|
|
67
|
-
usage: "kb summarize <path>",
|
|
68
|
-
run: async (args) => {
|
|
69
|
-
const targetPath = args.shift()?.trim();
|
|
70
|
-
if (!targetPath) {
|
|
71
|
-
console.error("Usage: kb summarize <path>");
|
|
72
|
-
process.exit(1);
|
|
73
|
-
}
|
|
74
|
-
const summary = await fileSummary({ path: resolve(targetPath) });
|
|
75
|
-
printFileSummary(summary);
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
name: "checkpoint",
|
|
80
|
-
description: "Save and restore lightweight session checkpoints",
|
|
81
|
-
usage: "kb checkpoint <save|load|list|latest> [label-or-id] [--data json] [--notes text]",
|
|
82
|
-
run: async (args) => {
|
|
83
|
-
const action = args.shift()?.trim();
|
|
84
|
-
if (!action) {
|
|
85
|
-
console.error(
|
|
86
|
-
"Usage: kb checkpoint <save|load|list|latest> [label-or-id] [--data json] [--notes text]"
|
|
87
|
-
);
|
|
88
|
-
process.exit(1);
|
|
89
|
-
}
|
|
90
|
-
switch (action) {
|
|
91
|
-
case "save": {
|
|
92
|
-
const label = args.shift()?.trim();
|
|
93
|
-
const dataFlag = extractStrFlag(args, "--data", "");
|
|
94
|
-
const notes = extractStrFlag(args, "--notes", "").trim() || void 0;
|
|
95
|
-
const stdinData = dataFlag.trim() ? "" : await readStdin();
|
|
96
|
-
if (!label) {
|
|
97
|
-
console.error("Usage: kb checkpoint save <label> [--data json] [--notes text]");
|
|
98
|
-
process.exit(1);
|
|
99
|
-
}
|
|
100
|
-
const checkpoint = checkpointSave(label, parseRecordString(dataFlag || stdinData), {
|
|
101
|
-
notes
|
|
102
|
-
});
|
|
103
|
-
printCheckpoint(checkpoint);
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
case "load": {
|
|
107
|
-
const id = args.shift()?.trim();
|
|
108
|
-
if (!id) {
|
|
109
|
-
console.error("Usage: kb checkpoint load <id>");
|
|
110
|
-
process.exit(1);
|
|
111
|
-
}
|
|
112
|
-
const checkpoint = checkpointLoad(id);
|
|
113
|
-
if (!checkpoint) {
|
|
114
|
-
console.log(`No checkpoint found: ${id}`);
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
printCheckpoint(checkpoint);
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
case "list": {
|
|
121
|
-
const checkpoints = checkpointList();
|
|
122
|
-
if (checkpoints.length === 0) {
|
|
123
|
-
console.log("No checkpoints saved.");
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
console.log(`Checkpoints (${checkpoints.length})`);
|
|
127
|
-
console.log("\u2500".repeat(60));
|
|
128
|
-
for (const checkpoint of checkpoints) {
|
|
129
|
-
console.log(`${checkpoint.id}`);
|
|
130
|
-
console.log(` Label: ${checkpoint.label}`);
|
|
131
|
-
console.log(` Created: ${checkpoint.createdAt}`);
|
|
132
|
-
}
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
case "latest": {
|
|
136
|
-
const checkpoint = checkpointLatest();
|
|
137
|
-
if (!checkpoint) {
|
|
138
|
-
console.log("No checkpoints saved.");
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
printCheckpoint(checkpoint);
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
default:
|
|
145
|
-
console.error(`Unknown checkpoint action: ${action}`);
|
|
146
|
-
console.error("Actions: save, load, list, latest");
|
|
147
|
-
process.exit(1);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
];
|
|
152
|
-
export {
|
|
153
|
-
contextCommands
|
|
154
|
-
};
|
|
155
|
-
//# sourceMappingURL=context-cmds.js.map
|
|
1
|
+
import{resolve as p}from"node:path";import{checkpointLatest as d,checkpointList as u,checkpointLoad as f,checkpointSave as m,diffParse as h,fileSummary as k,gitContext as g,parseOutput as b}from"@kb/tools";import{extractBoolFlag as x,extractNumFlag as w,extractStrFlag as i,parseRecordString as v,printCheckpoint as c,printDiffFiles as y,printFileSummary as C,printGitContext as S,printParsedOutput as U,readStdin as a}from"../helpers.js";const P=[{name:"parse-output",description:"Parse build or tool output from stdin",usage:"kb parse-output [--tool tsc|vitest|biome|git-status]",run:async e=>{const s=i(e,"--tool","").trim()||void 0,t=await a();t.trim()||(console.error("Usage: kb parse-output [--tool tsc|vitest|biome|git-status]"),process.exit(1)),U(b(t,s))}},{name:"git",description:"Show git branch, status, recent commits, and optional diff stats",usage:"kb git [--cwd path] [--commit-count N] [--diff]",run:async e=>{const s=i(e,"--cwd","").trim()||void 0,t=w(e,"--commit-count",5),o=x(e,"--diff"),n=await g({cwd:s,commitCount:t,includeDiff:o});S(n)}},{name:"diff",description:"Parse unified diff text from stdin into structured file changes",usage:"git diff | kb diff",run:async()=>{const e=await a();e.trim()||(console.error("Usage: git diff | kb diff"),process.exit(1)),y(h({diff:e}))}},{name:"summarize",description:"Show a structural summary of a file",usage:"kb summarize <path>",run:async e=>{const s=e.shift()?.trim();s||(console.error("Usage: kb summarize <path>"),process.exit(1));const t=await k({path:p(s)});C(t)}},{name:"checkpoint",description:"Save and restore lightweight session checkpoints",usage:"kb checkpoint <save|load|list|latest> [label-or-id] [--data json] [--notes text]",run:async e=>{const s=e.shift()?.trim();switch(s||(console.error("Usage: kb checkpoint <save|load|list|latest> [label-or-id] [--data json] [--notes text]"),process.exit(1)),s){case"save":{const t=e.shift()?.trim(),o=i(e,"--data",""),n=i(e,"--notes","").trim()||void 0,r=o.trim()?"":await a();t||(console.error("Usage: kb checkpoint save <label> [--data json] [--notes text]"),process.exit(1));const l=m(t,v(o||r),{notes:n});c(l);return}case"load":{const t=e.shift()?.trim();t||(console.error("Usage: kb checkpoint load <id>"),process.exit(1));const o=f(t);if(!o){console.log(`No checkpoint found: ${t}`);return}c(o);return}case"list":{const t=u();if(t.length===0){console.log("No checkpoints saved.");return}console.log(`Checkpoints (${t.length})`),console.log("\u2500".repeat(60));for(const o of t)console.log(`${o.id}`),console.log(` Label: ${o.label}`),console.log(` Created: ${o.createdAt}`);return}case"latest":{const t=d();if(!t){console.log("No checkpoints saved.");return}c(t);return}default:console.error(`Unknown checkpoint action: ${s}`),console.error("Actions: save, load, list, latest"),process.exit(1)}}}];export{P as contextCommands};
|