@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,204 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
delegate,
|
|
5
|
-
delegateListModels,
|
|
6
|
-
processList,
|
|
7
|
-
processLogs,
|
|
8
|
-
processStart,
|
|
9
|
-
processStatus,
|
|
10
|
-
processStop,
|
|
11
|
-
watchList,
|
|
12
|
-
watchStart,
|
|
13
|
-
watchStop
|
|
14
|
-
} from "@kb/tools";
|
|
15
|
-
import { extractNumFlag, extractStrFlag, printManagedProcess, readStdin } from "../helpers.js";
|
|
16
|
-
const environmentCommands = [
|
|
17
|
-
{
|
|
18
|
-
name: "proc",
|
|
19
|
-
description: "Manage in-memory child processes",
|
|
20
|
-
usage: "kb proc <start|stop|status|list|logs> ...",
|
|
21
|
-
run: async (args) => {
|
|
22
|
-
const action = args.shift()?.trim() ?? "";
|
|
23
|
-
switch (action) {
|
|
24
|
-
case "start": {
|
|
25
|
-
const id = args.shift()?.trim();
|
|
26
|
-
const command = args.shift()?.trim();
|
|
27
|
-
if (!id || !command) {
|
|
28
|
-
console.error("Usage: kb proc start <id> <command> [args...]");
|
|
29
|
-
process.exit(1);
|
|
30
|
-
}
|
|
31
|
-
printManagedProcess(processStart(id, command, args));
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
case "stop": {
|
|
35
|
-
const id = args.shift()?.trim();
|
|
36
|
-
if (!id) {
|
|
37
|
-
console.error("Usage: kb proc stop <id>");
|
|
38
|
-
process.exit(1);
|
|
39
|
-
}
|
|
40
|
-
const result = processStop(id);
|
|
41
|
-
if (!result) {
|
|
42
|
-
console.log(`No managed process found: ${id}`);
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
printManagedProcess(result);
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
case "status": {
|
|
49
|
-
const id = args.shift()?.trim();
|
|
50
|
-
if (!id) {
|
|
51
|
-
console.error("Usage: kb proc status <id>");
|
|
52
|
-
process.exit(1);
|
|
53
|
-
}
|
|
54
|
-
const result = processStatus(id);
|
|
55
|
-
if (!result) {
|
|
56
|
-
console.log(`No managed process found: ${id}`);
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
printManagedProcess(result);
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
case "list": {
|
|
63
|
-
const processes = processList();
|
|
64
|
-
if (processes.length === 0) {
|
|
65
|
-
console.log("No managed processes.");
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
for (const info of processes) {
|
|
69
|
-
printManagedProcess(info);
|
|
70
|
-
console.log("");
|
|
71
|
-
}
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
case "logs": {
|
|
75
|
-
const tail = extractNumFlag(args, "--tail", 50);
|
|
76
|
-
const id = args.shift()?.trim();
|
|
77
|
-
if (!id) {
|
|
78
|
-
console.error("Usage: kb proc logs <id> [--tail N]");
|
|
79
|
-
process.exit(1);
|
|
80
|
-
}
|
|
81
|
-
const logs = processLogs(id, tail);
|
|
82
|
-
if (logs.length === 0) {
|
|
83
|
-
console.log(`No logs found for process: ${id}`);
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
for (const line of logs) console.log(line);
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
default:
|
|
90
|
-
console.error(`Unknown proc action: ${action}`);
|
|
91
|
-
console.error("Actions: start, stop, status, list, logs");
|
|
92
|
-
process.exit(1);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
name: "watch",
|
|
98
|
-
description: "Manage in-memory filesystem watchers",
|
|
99
|
-
usage: "kb watch <start|stop|list> ...",
|
|
100
|
-
run: async (args) => {
|
|
101
|
-
const action = args.shift()?.trim() ?? "";
|
|
102
|
-
switch (action) {
|
|
103
|
-
case "start": {
|
|
104
|
-
const targetPath = args.shift()?.trim();
|
|
105
|
-
if (!targetPath) {
|
|
106
|
-
console.error("Usage: kb watch start <path>");
|
|
107
|
-
process.exit(1);
|
|
108
|
-
}
|
|
109
|
-
const handle = watchStart({ path: resolve(targetPath) });
|
|
110
|
-
console.log(`Started watcher: ${handle.id}`);
|
|
111
|
-
console.log(` Path: ${handle.path}`);
|
|
112
|
-
console.log(` Status: ${handle.status}`);
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
case "stop": {
|
|
116
|
-
const id = args.shift()?.trim();
|
|
117
|
-
if (!id) {
|
|
118
|
-
console.error("Usage: kb watch stop <id>");
|
|
119
|
-
process.exit(1);
|
|
120
|
-
}
|
|
121
|
-
const stopped = watchStop(id);
|
|
122
|
-
console.log(stopped ? `Stopped watcher: ${id}` : `Watcher not found: ${id}`);
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
case "list": {
|
|
126
|
-
const watches = watchList();
|
|
127
|
-
if (watches.length === 0) {
|
|
128
|
-
console.log("No active watchers.");
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
for (const watcher of watches) {
|
|
132
|
-
console.log(`${watcher.id}`);
|
|
133
|
-
console.log(` Path: ${watcher.path}`);
|
|
134
|
-
console.log(` Status: ${watcher.status}`);
|
|
135
|
-
console.log(` Events: ${watcher.eventCount}`);
|
|
136
|
-
}
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
default:
|
|
140
|
-
console.error(`Unknown watch action: ${action}`);
|
|
141
|
-
console.error("Actions: start, stop, list");
|
|
142
|
-
process.exit(1);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
name: "delegate",
|
|
148
|
-
description: "Delegate a task to a local Ollama model",
|
|
149
|
-
usage: "kb delegate [--model name] [--system prompt] [--temp 0.3] <prompt | --stdin>",
|
|
150
|
-
run: async (args) => {
|
|
151
|
-
const action = args[0] === "models" ? args.shift() : void 0;
|
|
152
|
-
if (action === "models") {
|
|
153
|
-
try {
|
|
154
|
-
const models = await delegateListModels();
|
|
155
|
-
if (models.length === 0) {
|
|
156
|
-
console.log("No Ollama models available. Pull one with: ollama pull qwen2.5-coder:7b");
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
for (const m of models) console.log(m);
|
|
160
|
-
} catch {
|
|
161
|
-
console.error("Ollama is not running. Start it with: ollama serve");
|
|
162
|
-
process.exit(1);
|
|
163
|
-
}
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
const model = extractStrFlag(args, "--model", "");
|
|
167
|
-
const system = extractStrFlag(args, "--system", "");
|
|
168
|
-
const temp = extractNumFlag(args, "--temp", 0.3);
|
|
169
|
-
const contextFile = extractStrFlag(args, "--context", "");
|
|
170
|
-
let prompt = args.join(" ");
|
|
171
|
-
if (!prompt) {
|
|
172
|
-
prompt = await readStdin();
|
|
173
|
-
}
|
|
174
|
-
if (!prompt) {
|
|
175
|
-
console.error("Usage: kb delegate [--model name] <prompt>");
|
|
176
|
-
process.exit(1);
|
|
177
|
-
}
|
|
178
|
-
let context;
|
|
179
|
-
if (contextFile) {
|
|
180
|
-
context = await readFile(resolve(contextFile), "utf-8");
|
|
181
|
-
}
|
|
182
|
-
const result = await delegate({
|
|
183
|
-
prompt,
|
|
184
|
-
model: model || void 0,
|
|
185
|
-
system: system || void 0,
|
|
186
|
-
context,
|
|
187
|
-
temperature: temp
|
|
188
|
-
});
|
|
189
|
-
if (result.error) {
|
|
190
|
-
console.error(`Error: ${result.error}`);
|
|
191
|
-
process.exit(1);
|
|
192
|
-
}
|
|
193
|
-
console.log(result.response);
|
|
194
|
-
console.error(
|
|
195
|
-
`
|
|
196
|
-
(${result.model}, ${result.durationMs}ms, ${result.tokenCount ?? "?"} tokens)`
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
];
|
|
201
|
-
export {
|
|
202
|
-
environmentCommands
|
|
203
|
-
};
|
|
204
|
-
//# sourceMappingURL=environment.js.map
|
|
1
|
+
import{readFile as h}from"node:fs/promises";import{resolve as d}from"node:path";import{delegate as g,delegateListModels as w,processList as $,processLogs as x,processStart as k,processStatus as y,processStop as b,watchList as S,watchStart as U,watchStop as N}from"../../../tools/dist/index.js";import{extractNumFlag as f,extractStrFlag as l,printManagedProcess as i,readStdin as v}from"../helpers.js";const L=[{name:"proc",description:"Manage in-memory child processes",usage:"kb proc <start|stop|status|list|logs> ...",run:async e=>{const s=e.shift()?.trim()??"";switch(s){case"start":{const o=e.shift()?.trim(),t=e.shift()?.trim();(!o||!t)&&(console.error("Usage: kb proc start <id> <command> [args...]"),process.exit(1)),i(k(o,t,e));return}case"stop":{const o=e.shift()?.trim();o||(console.error("Usage: kb proc stop <id>"),process.exit(1));const t=b(o);if(!t){console.log(`No managed process found: ${o}`);return}i(t);return}case"status":{const o=e.shift()?.trim();o||(console.error("Usage: kb proc status <id>"),process.exit(1));const t=y(o);if(!t){console.log(`No managed process found: ${o}`);return}i(t);return}case"list":{const o=$();if(o.length===0){console.log("No managed processes.");return}for(const t of o)i(t),console.log("");return}case"logs":{const o=f(e,"--tail",50),t=e.shift()?.trim();t||(console.error("Usage: kb proc logs <id> [--tail N]"),process.exit(1));const n=x(t,o);if(n.length===0){console.log(`No logs found for process: ${t}`);return}for(const c of n)console.log(c);return}default:console.error(`Unknown proc action: ${s}`),console.error("Actions: start, stop, status, list, logs"),process.exit(1)}}},{name:"watch",description:"Manage in-memory filesystem watchers",usage:"kb watch <start|stop|list> ...",run:async e=>{const s=e.shift()?.trim()??"";switch(s){case"start":{const o=e.shift()?.trim();o||(console.error("Usage: kb watch start <path>"),process.exit(1));const t=U({path:d(o)});console.log(`Started watcher: ${t.id}`),console.log(` Path: ${t.path}`),console.log(` Status: ${t.status}`);return}case"stop":{const o=e.shift()?.trim();o||(console.error("Usage: kb watch stop <id>"),process.exit(1));const t=N(o);console.log(t?`Stopped watcher: ${o}`:`Watcher not found: ${o}`);return}case"list":{const o=S();if(o.length===0){console.log("No active watchers.");return}for(const t of o)console.log(`${t.id}`),console.log(` Path: ${t.path}`),console.log(` Status: ${t.status}`),console.log(` Events: ${t.eventCount}`);return}default:console.error(`Unknown watch action: ${s}`),console.error("Actions: start, stop, list"),process.exit(1)}}},{name:"delegate",description:"Delegate a task to a local Ollama model",usage:"kb delegate [--model name] [--system prompt] [--temp 0.3] <prompt | --stdin>",run:async e=>{if((e[0]==="models"?e.shift():void 0)==="models"){try{const p=await w();if(p.length===0){console.log("No Ollama models available. Pull one with: ollama pull qwen2.5-coder:7b");return}for(const u of p)console.log(u)}catch{console.error("Ollama is not running. Start it with: ollama serve"),process.exit(1)}return}const o=l(e,"--model",""),t=l(e,"--system",""),n=f(e,"--temp",.3),c=l(e,"--context","");let a=e.join(" ");a||(a=await v()),a||(console.error("Usage: kb delegate [--model name] <prompt>"),process.exit(1));let m;c&&(m=await h(d(c),"utf-8"));const r=await g({prompt:a,model:o||void 0,system:t||void 0,context:m,temperature:n});r.error&&(console.error(`Error: ${r.error}`),process.exit(1)),console.log(r.response),console.error(`
|
|
2
|
+
(${r.model}, ${r.durationMs}ms, ${r.tokenCount??"?"} tokens)`)}}];export{L as environmentCommands};
|
|
@@ -1,137 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { resolve } from "node:path";
|
|
3
|
-
import { codemod, dataTransform, evaluate, rename, testRun } from "@kb/tools";
|
|
4
|
-
import {
|
|
5
|
-
extractBoolFlag,
|
|
6
|
-
extractNumFlag,
|
|
7
|
-
extractStrFlag,
|
|
8
|
-
printTestRunResult,
|
|
9
|
-
readStdin,
|
|
10
|
-
splitCsv
|
|
11
|
-
} from "../helpers.js";
|
|
12
|
-
const executionCommands = [
|
|
13
|
-
{
|
|
14
|
-
name: "eval",
|
|
15
|
-
description: "Evaluate JavaScript or TypeScript in a constrained VM sandbox",
|
|
16
|
-
usage: "kb eval [code] [--lang js|ts] [--timeout ms]",
|
|
17
|
-
run: async (args) => {
|
|
18
|
-
const lang = extractStrFlag(args, "--lang", "js");
|
|
19
|
-
const timeout = extractNumFlag(args, "--timeout", 5e3);
|
|
20
|
-
const inlineCode = args.join(" ");
|
|
21
|
-
const stdinCode = inlineCode.trim() ? "" : await readStdin();
|
|
22
|
-
const code = inlineCode || stdinCode;
|
|
23
|
-
if (!code.trim()) {
|
|
24
|
-
console.error("Usage: kb eval [code] [--lang js|ts] [--timeout ms]");
|
|
25
|
-
process.exit(1);
|
|
26
|
-
}
|
|
27
|
-
const result = evaluate({
|
|
28
|
-
code,
|
|
29
|
-
lang: lang === "ts" ? "ts" : "js",
|
|
30
|
-
timeout
|
|
31
|
-
});
|
|
32
|
-
if (!result.success) {
|
|
33
|
-
console.error(`Eval failed in ${result.durationMs}ms: ${result.error}`);
|
|
34
|
-
process.exitCode = 1;
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
console.log(`Eval succeeded in ${result.durationMs}ms`);
|
|
38
|
-
console.log("\u2500".repeat(60));
|
|
39
|
-
console.log(result.output);
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
name: "test",
|
|
44
|
-
description: "Run Vitest for all tests or a specific subset",
|
|
45
|
-
usage: "kb test [files...] [--grep pattern] [--cwd path] [--timeout ms]",
|
|
46
|
-
run: async (args) => {
|
|
47
|
-
const grep = extractStrFlag(args, "--grep", "").trim() || void 0;
|
|
48
|
-
const cwd = extractStrFlag(args, "--cwd", "").trim() || void 0;
|
|
49
|
-
const timeout = extractNumFlag(args, "--timeout", 6e4);
|
|
50
|
-
const files = args.filter(Boolean);
|
|
51
|
-
const result = await testRun({
|
|
52
|
-
files: files.length > 0 ? files : void 0,
|
|
53
|
-
grep,
|
|
54
|
-
cwd,
|
|
55
|
-
timeout
|
|
56
|
-
});
|
|
57
|
-
printTestRunResult(result);
|
|
58
|
-
if (!result.passed) process.exitCode = 1;
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
name: "rename",
|
|
63
|
-
description: "Rename a symbol across files using whole-word regex matching",
|
|
64
|
-
usage: "kb rename <old> <new> <path> [--dry-run] [--extensions .ts,.tsx] [--exclude dist/**]",
|
|
65
|
-
run: async (args) => {
|
|
66
|
-
const oldName = args.shift()?.trim() ?? "";
|
|
67
|
-
const newName = args.shift()?.trim() ?? "";
|
|
68
|
-
const targetPath = args.shift()?.trim() ?? "";
|
|
69
|
-
if (!oldName || !newName || !targetPath) {
|
|
70
|
-
console.error(
|
|
71
|
-
"Usage: kb rename <old> <new> <path> [--dry-run] [--extensions .ts,.tsx] [--exclude dist/**]"
|
|
72
|
-
);
|
|
73
|
-
process.exit(1);
|
|
74
|
-
}
|
|
75
|
-
const extensions = splitCsv(extractStrFlag(args, "--extensions", ""));
|
|
76
|
-
const exclude = splitCsv(extractStrFlag(args, "--exclude", ""));
|
|
77
|
-
const result = await rename({
|
|
78
|
-
oldName,
|
|
79
|
-
newName,
|
|
80
|
-
rootPath: resolve(targetPath),
|
|
81
|
-
extensions: extensions.length > 0 ? extensions : void 0,
|
|
82
|
-
exclude: exclude.length > 0 ? exclude : void 0,
|
|
83
|
-
dryRun: extractBoolFlag(args, "--dry-run")
|
|
84
|
-
});
|
|
85
|
-
console.log(JSON.stringify(result, null, 2));
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
name: "codemod",
|
|
90
|
-
description: "Apply regex-based codemod rules from a JSON file across a path",
|
|
91
|
-
usage: "kb codemod <path> --rules <file.json> [--dry-run] [--extensions .ts,.tsx] [--exclude dist/**]",
|
|
92
|
-
run: async (args) => {
|
|
93
|
-
const targetPath = args.shift()?.trim() ?? "";
|
|
94
|
-
const rulesPath = extractStrFlag(args, "--rules", "").trim();
|
|
95
|
-
if (!targetPath || !rulesPath) {
|
|
96
|
-
console.error(
|
|
97
|
-
"Usage: kb codemod <path> --rules <file.json> [--dry-run] [--extensions .ts,.tsx] [--exclude dist/**]"
|
|
98
|
-
);
|
|
99
|
-
process.exit(1);
|
|
100
|
-
}
|
|
101
|
-
const rulesInput = await readFile(resolve(rulesPath), "utf-8");
|
|
102
|
-
const parsedRules = JSON.parse(rulesInput);
|
|
103
|
-
if (!Array.isArray(parsedRules)) {
|
|
104
|
-
throw new Error("Codemod rules file must contain a JSON array.");
|
|
105
|
-
}
|
|
106
|
-
const extensions = splitCsv(extractStrFlag(args, "--extensions", ""));
|
|
107
|
-
const exclude = splitCsv(extractStrFlag(args, "--exclude", ""));
|
|
108
|
-
const result = await codemod({
|
|
109
|
-
rootPath: resolve(targetPath),
|
|
110
|
-
rules: parsedRules,
|
|
111
|
-
extensions: extensions.length > 0 ? extensions : void 0,
|
|
112
|
-
exclude: exclude.length > 0 ? exclude : void 0,
|
|
113
|
-
dryRun: extractBoolFlag(args, "--dry-run")
|
|
114
|
-
});
|
|
115
|
-
console.log(JSON.stringify(result, null, 2));
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
name: "transform",
|
|
120
|
-
description: "Apply jq-like transforms to JSON from stdin",
|
|
121
|
-
usage: "cat data.json | kb transform <expression>",
|
|
122
|
-
run: async (args) => {
|
|
123
|
-
const expression = args.join(" ").trim();
|
|
124
|
-
const input = await readStdin();
|
|
125
|
-
if (!expression || !input.trim()) {
|
|
126
|
-
console.error("Usage: cat data.json | kb transform <expression>");
|
|
127
|
-
process.exit(1);
|
|
128
|
-
}
|
|
129
|
-
const result = dataTransform({ input, expression });
|
|
130
|
-
console.log(result.outputString);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
];
|
|
134
|
-
export {
|
|
135
|
-
executionCommands
|
|
136
|
-
};
|
|
137
|
-
//# sourceMappingURL=execution.js.map
|
|
1
|
+
import{readFile as f}from"node:fs/promises";import{resolve as l}from"node:path";import{codemod as x,dataTransform as g,evaluate as y,rename as h,testRun as w}from"../../../tools/dist/index.js";import{extractBoolFlag as d,extractNumFlag as u,extractStrFlag as a,printTestRunResult as b,readStdin as m,splitCsv as c}from"../helpers.js";const v=[{name:"eval",description:"Evaluate JavaScript or TypeScript in a constrained VM sandbox",usage:"kb eval [code] [--lang js|ts] [--timeout ms]",run:async e=>{const t=a(e,"--lang","js"),s=u(e,"--timeout",5e3),o=e.join(" "),r=o.trim()?"":await m(),n=o||r;n.trim()||(console.error("Usage: kb eval [code] [--lang js|ts] [--timeout ms]"),process.exit(1));const i=y({code:n,lang:t==="ts"?"ts":"js",timeout:s});if(!i.success){console.error(`Eval failed in ${i.durationMs}ms: ${i.error}`),process.exitCode=1;return}console.log(`Eval succeeded in ${i.durationMs}ms`),console.log("\u2500".repeat(60)),console.log(i.output)}},{name:"test",description:"Run Vitest for all tests or a specific subset",usage:"kb test [files...] [--grep pattern] [--cwd path] [--timeout ms]",run:async e=>{const t=a(e,"--grep","").trim()||void 0,s=a(e,"--cwd","").trim()||void 0,o=u(e,"--timeout",6e4),r=e.filter(Boolean),n=await w({files:r.length>0?r:void 0,grep:t,cwd:s,timeout:o});b(n),n.passed||(process.exitCode=1)}},{name:"rename",description:"Rename a symbol across files using whole-word regex matching",usage:"kb rename <old> <new> <path> [--dry-run] [--extensions .ts,.tsx] [--exclude dist/**]",run:async e=>{const t=e.shift()?.trim()??"",s=e.shift()?.trim()??"",o=e.shift()?.trim()??"";(!t||!s||!o)&&(console.error("Usage: kb rename <old> <new> <path> [--dry-run] [--extensions .ts,.tsx] [--exclude dist/**]"),process.exit(1));const r=c(a(e,"--extensions","")),n=c(a(e,"--exclude","")),i=await h({oldName:t,newName:s,rootPath:l(o),extensions:r.length>0?r:void 0,exclude:n.length>0?n:void 0,dryRun:d(e,"--dry-run")});console.log(JSON.stringify(i,null,2))}},{name:"codemod",description:"Apply regex-based codemod rules from a JSON file across a path",usage:"kb codemod <path> --rules <file.json> [--dry-run] [--extensions .ts,.tsx] [--exclude dist/**]",run:async e=>{const t=e.shift()?.trim()??"",s=a(e,"--rules","").trim();(!t||!s)&&(console.error("Usage: kb codemod <path> --rules <file.json> [--dry-run] [--extensions .ts,.tsx] [--exclude dist/**]"),process.exit(1));const o=await f(l(s),"utf-8"),r=JSON.parse(o);if(!Array.isArray(r))throw new Error("Codemod rules file must contain a JSON array.");const n=c(a(e,"--extensions","")),i=c(a(e,"--exclude","")),p=await x({rootPath:l(t),rules:r,extensions:n.length>0?n:void 0,exclude:i.length>0?i:void 0,dryRun:d(e,"--dry-run")});console.log(JSON.stringify(p,null,2))}},{name:"transform",description:"Apply jq-like transforms to JSON from stdin",usage:"cat data.json | kb transform <expression>",run:async e=>{const t=e.join(" ").trim(),s=await m();(!t||!s.trim())&&(console.error("Usage: cat data.json | kb transform <expression>"),process.exit(1));const o=g({input:s,expression:t});console.log(o.outputString)}}];export{v as executionCommands};
|
|
@@ -1,81 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
{
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
usage: "kb graph <action> [options]\n Actions: stats, find-nodes, find-edges, neighbors, traverse, delete, clear\n Options: --type, --name, --node-id, --edge-type, --direction, --depth, --limit, --source-path",
|
|
9
|
-
run: async (args) => {
|
|
10
|
-
const action = args.shift()?.trim() ?? "";
|
|
11
|
-
if (!action) {
|
|
12
|
-
console.error(
|
|
13
|
-
"Usage: kb graph <action>\nActions: stats, find-nodes, find-edges, neighbors, traverse, delete, clear"
|
|
14
|
-
);
|
|
15
|
-
process.exit(1);
|
|
16
|
-
}
|
|
17
|
-
const { graphStore } = await ctx();
|
|
18
|
-
const nodeType = extractStrFlag(args, "--type", "");
|
|
19
|
-
const namePattern = extractStrFlag(args, "--name", "");
|
|
20
|
-
const nodeId = extractStrFlag(args, "--node-id", "");
|
|
21
|
-
const edgeType = extractStrFlag(args, "--edge-type", "");
|
|
22
|
-
const direction = extractStrFlag(args, "--direction", "both");
|
|
23
|
-
const maxDepth = extractNumFlag(args, "--depth", 2);
|
|
24
|
-
const limit = extractNumFlag(args, "--limit", 50);
|
|
25
|
-
const sourcePath = extractStrFlag(args, "--source-path", "");
|
|
26
|
-
const actionMap = {
|
|
27
|
-
stats: "stats",
|
|
28
|
-
"find-nodes": "find_nodes",
|
|
29
|
-
"find-edges": "find_edges",
|
|
30
|
-
neighbors: "neighbors",
|
|
31
|
-
traverse: "traverse",
|
|
32
|
-
delete: "delete",
|
|
33
|
-
clear: "clear"
|
|
34
|
-
};
|
|
35
|
-
const mapped = actionMap[action];
|
|
36
|
-
if (!mapped) {
|
|
37
|
-
console.error(`Unknown graph action: ${action}`);
|
|
38
|
-
console.error("Actions: stats, find-nodes, find-edges, neighbors, traverse, delete, clear");
|
|
39
|
-
process.exit(1);
|
|
40
|
-
}
|
|
41
|
-
const result = await graphQuery(graphStore, {
|
|
42
|
-
action: mapped,
|
|
43
|
-
nodeType: nodeType || void 0,
|
|
44
|
-
namePattern: namePattern || void 0,
|
|
45
|
-
sourcePath: sourcePath || void 0,
|
|
46
|
-
nodeId: nodeId || void 0,
|
|
47
|
-
edgeType: edgeType || void 0,
|
|
48
|
-
direction,
|
|
49
|
-
maxDepth,
|
|
50
|
-
limit
|
|
51
|
-
});
|
|
52
|
-
console.log(result.summary);
|
|
53
|
-
if (result.nodes && result.nodes.length > 0) {
|
|
54
|
-
console.log("\nNodes:");
|
|
55
|
-
for (const n of result.nodes) {
|
|
56
|
-
const props = Object.keys(n.properties).length > 0 ? ` ${JSON.stringify(n.properties)}` : "";
|
|
57
|
-
console.log(` ${n.name} (${n.type}, id: ${n.id})${props}`);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (result.edges && result.edges.length > 0) {
|
|
61
|
-
console.log("\nEdges:");
|
|
62
|
-
for (const e of result.edges) {
|
|
63
|
-
const w = e.weight !== 1 ? ` (weight: ${e.weight})` : "";
|
|
64
|
-
console.log(` ${e.fromId} --[${e.type}]--> ${e.toId}${w}`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
if (result.stats) {
|
|
68
|
-
console.log(`
|
|
69
|
-
Node types: ${JSON.stringify(result.stats.nodeTypes)}`);
|
|
70
|
-
console.log(`Edge types: ${JSON.stringify(result.stats.edgeTypes)}`);
|
|
71
|
-
}
|
|
72
|
-
if (result.deleted !== void 0) {
|
|
73
|
-
console.log(`Deleted: ${result.deleted}`);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
];
|
|
78
|
-
export {
|
|
79
|
-
graphCommands
|
|
80
|
-
};
|
|
81
|
-
//# sourceMappingURL=graph.js.map
|
|
1
|
+
import{graphQuery as u}from"../../../tools/dist/index.js";import{ctx as $}from"../context.js";import{extractNumFlag as r,extractStrFlag as n}from"../helpers.js";const T=[{name:"graph",description:"Query the knowledge graph",usage:`kb graph <action> [options]
|
|
2
|
+
Actions: stats, find-nodes, find-edges, neighbors, traverse, delete, clear
|
|
3
|
+
Options: --type, --name, --node-id, --edge-type, --direction, --depth, --limit, --source-path`,run:async t=>{const s=t.shift()?.trim()??"";s||(console.error(`Usage: kb graph <action>
|
|
4
|
+
Actions: stats, find-nodes, find-edges, neighbors, traverse, delete, clear`),process.exit(1));const{graphStore:a}=await $(),c=n(t,"--type",""),p=n(t,"--name",""),g=n(t,"--node-id",""),l=n(t,"--edge-type",""),f=n(t,"--direction","both"),m=r(t,"--depth",2),h=r(t,"--limit",50),y=n(t,"--source-path",""),i={stats:"stats","find-nodes":"find_nodes","find-edges":"find_edges",neighbors:"neighbors",traverse:"traverse",delete:"delete",clear:"clear"}[s];i||(console.error(`Unknown graph action: ${s}`),console.error("Actions: stats, find-nodes, find-edges, neighbors, traverse, delete, clear"),process.exit(1));const e=await u(a,{action:i,nodeType:c||void 0,namePattern:p||void 0,sourcePath:y||void 0,nodeId:g||void 0,edgeType:l||void 0,direction:f,maxDepth:m,limit:h});if(console.log(e.summary),e.nodes&&e.nodes.length>0){console.log(`
|
|
5
|
+
Nodes:`);for(const o of e.nodes){const d=Object.keys(o.properties).length>0?` ${JSON.stringify(o.properties)}`:"";console.log(` ${o.name} (${o.type}, id: ${o.id})${d}`)}}if(e.edges&&e.edges.length>0){console.log(`
|
|
6
|
+
Edges:`);for(const o of e.edges){const d=o.weight!==1?` (weight: ${o.weight})`:"";console.log(` ${o.fromId} --[${o.type}]--> ${o.toId}${d}`)}}e.stats&&(console.log(`
|
|
7
|
+
Node types: ${JSON.stringify(e.stats.nodeTypes)}`),console.log(`Edge types: ${JSON.stringify(e.stats.edgeTypes)}`)),e.deleted!==void 0&&console.log(`Deleted: ${e.deleted}`)}}];export{T as graphCommands};
|
|
@@ -1,87 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"**/build/**",
|
|
11
|
-
"**/.git/**",
|
|
12
|
-
"**/.kb-data/**",
|
|
13
|
-
"**/coverage/**",
|
|
14
|
-
"**/*.min.js",
|
|
15
|
-
"**/package-lock.json",
|
|
16
|
-
"**/pnpm-lock.yaml"
|
|
17
|
-
]
|
|
18
|
-
}
|
|
19
|
-
],
|
|
20
|
-
indexing: {
|
|
21
|
-
chunkSize: 1500,
|
|
22
|
-
chunkOverlap: 200,
|
|
23
|
-
minChunkSize: 100
|
|
24
|
-
},
|
|
25
|
-
embedding: {
|
|
26
|
-
model: "Xenova/mxbai-embed-large-v1",
|
|
27
|
-
dimensions: 1024
|
|
28
|
-
},
|
|
29
|
-
store: {
|
|
30
|
-
backend: "lancedb",
|
|
31
|
-
path: ".kb-data/lance"
|
|
32
|
-
},
|
|
33
|
-
curated: {
|
|
34
|
-
path: "curated"
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
const VSCODE_MCP_CONFIG = {
|
|
38
|
-
servers: {
|
|
39
|
-
"knowledge-base": {
|
|
40
|
-
type: "stdio",
|
|
41
|
-
command: "npx",
|
|
42
|
-
args: ["kb", "serve"]
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
async function initProject(options) {
|
|
47
|
-
const cwd = process.cwd();
|
|
48
|
-
const configPath = resolve(cwd, "kb.config.json");
|
|
49
|
-
if (existsSync(configPath) && !options.force) {
|
|
50
|
-
console.log("kb.config.json already exists. Use --force to overwrite.");
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
writeFileSync(configPath, `${JSON.stringify(DEFAULT_CONFIG, null, 2)}
|
|
54
|
-
`, "utf-8");
|
|
55
|
-
console.log(" Created kb.config.json");
|
|
56
|
-
const curatedDir = resolve(cwd, "curated");
|
|
57
|
-
if (!existsSync(curatedDir)) {
|
|
58
|
-
mkdirSync(curatedDir, { recursive: true });
|
|
59
|
-
console.log(" Created curated/");
|
|
60
|
-
}
|
|
61
|
-
const gitignorePath = resolve(cwd, ".gitignore");
|
|
62
|
-
if (existsSync(gitignorePath)) {
|
|
63
|
-
const content = readFileSync(gitignorePath, "utf-8");
|
|
64
|
-
if (!content.includes(".kb-data")) {
|
|
65
|
-
appendFileSync(gitignorePath, "\n# Knowledge base vector store\n.kb-data/\n", "utf-8");
|
|
66
|
-
console.log(" Added .kb-data/ to .gitignore");
|
|
67
|
-
}
|
|
68
|
-
} else {
|
|
69
|
-
writeFileSync(gitignorePath, "# Knowledge base vector store\n.kb-data/\n", "utf-8");
|
|
70
|
-
console.log(" Created .gitignore with .kb-data/");
|
|
71
|
-
}
|
|
72
|
-
const vscodePath = resolve(cwd, ".vscode");
|
|
73
|
-
const mcpJsonPath = resolve(vscodePath, "mcp.json");
|
|
74
|
-
if (existsSync(vscodePath) && !existsSync(mcpJsonPath)) {
|
|
75
|
-
writeFileSync(mcpJsonPath, `${JSON.stringify(VSCODE_MCP_CONFIG, null, 2)}
|
|
76
|
-
`, "utf-8");
|
|
77
|
-
console.log(" Created .vscode/mcp.json");
|
|
78
|
-
}
|
|
79
|
-
console.log("\nKnowledge base initialized! Next steps:");
|
|
80
|
-
console.log(" kb reindex Index your codebase");
|
|
81
|
-
console.log(" kb search Search indexed content");
|
|
82
|
-
console.log(" kb serve Start MCP server for IDE integration");
|
|
83
|
-
}
|
|
84
|
-
export {
|
|
85
|
-
initProject
|
|
86
|
-
};
|
|
87
|
-
//# sourceMappingURL=init.js.map
|
|
1
|
+
import{appendFileSync as l,existsSync as e,mkdirSync as g,readFileSync as b,writeFileSync as c}from"node:fs";import{resolve as o}from"node:path";const u={sources:[{path:".",excludePatterns:["**/node_modules/**","**/dist/**","**/build/**","**/.git/**","**/.kb-data/**","**/coverage/**","**/*.min.js","**/package-lock.json","**/pnpm-lock.yaml"]}],indexing:{chunkSize:1500,chunkOverlap:200,minChunkSize:100},embedding:{model:"Xenova/mxbai-embed-large-v1",dimensions:1024},store:{backend:"lancedb",path:".kb-data/lance"},curated:{path:"curated"}},f={servers:{"knowledge-base":{type:"stdio",command:"npx",args:["kb","serve"]}}};async function v(d){const n=process.cwd(),s=o(n,"kb.config.json");if(e(s)&&!d.force){console.log("kb.config.json already exists. Use --force to overwrite.");return}c(s,`${JSON.stringify(u,null,2)}
|
|
2
|
+
`,"utf-8"),console.log(" Created kb.config.json");const r=o(n,"curated");e(r)||(g(r,{recursive:!0}),console.log(" Created curated/"));const t=o(n,".gitignore");e(t)?b(t,"utf-8").includes(".kb-data")||(l(t,`
|
|
3
|
+
# Knowledge base vector store
|
|
4
|
+
.kb-data/
|
|
5
|
+
`,"utf-8"),console.log(" Added .kb-data/ to .gitignore")):(c(t,`# Knowledge base vector store
|
|
6
|
+
.kb-data/
|
|
7
|
+
`,"utf-8"),console.log(" Created .gitignore with .kb-data/"));const i=o(n,".vscode"),a=o(i,"mcp.json");e(i)&&!e(a)&&(c(a,`${JSON.stringify(f,null,2)}
|
|
8
|
+
`,"utf-8"),console.log(" Created .vscode/mcp.json")),console.log(`
|
|
9
|
+
Knowledge base initialized! Next steps:`),console.log(" kb reindex Index your codebase"),console.log(" kb search Search indexed content"),console.log(" kb serve Start MCP server for IDE integration")}export{v as initProject};
|