@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,241 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { ctx } from "../context.js";
|
|
6
|
-
import {
|
|
7
|
-
executeCliBatchOperation,
|
|
8
|
-
extractStrFlag,
|
|
9
|
-
parseBatchPayload,
|
|
10
|
-
printCheckResult,
|
|
11
|
-
readInput
|
|
12
|
-
} from "../helpers.js";
|
|
13
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
14
|
-
const systemCommands = [
|
|
15
|
-
{
|
|
16
|
-
name: "status",
|
|
17
|
-
description: "Show knowledge base index status and statistics",
|
|
18
|
-
run: async () => {
|
|
19
|
-
const { store } = await ctx();
|
|
20
|
-
const stats = await store.getStats();
|
|
21
|
-
const paths = await store.listSourcePaths();
|
|
22
|
-
console.log("Knowledge Base Status");
|
|
23
|
-
console.log("\u2500".repeat(40));
|
|
24
|
-
console.log(` Records: ${stats.totalRecords}`);
|
|
25
|
-
console.log(` Files: ${stats.totalFiles}`);
|
|
26
|
-
console.log(` Indexed: ${stats.lastIndexedAt ?? "Never"}`);
|
|
27
|
-
console.log(` Backend: ${stats.storeBackend}`);
|
|
28
|
-
console.log(` Model: ${stats.embeddingModel}`);
|
|
29
|
-
console.log("");
|
|
30
|
-
console.log("Content Types:");
|
|
31
|
-
for (const [type, count] of Object.entries(stats.contentTypeBreakdown)) {
|
|
32
|
-
console.log(` ${type}: ${count}`);
|
|
33
|
-
}
|
|
34
|
-
if (paths.length > 0) {
|
|
35
|
-
console.log("");
|
|
36
|
-
console.log(`Files (${paths.length} total):`);
|
|
37
|
-
for (const p of paths.slice(0, 20)) console.log(` ${p}`);
|
|
38
|
-
if (paths.length > 20) console.log(` ... and ${paths.length - 20} more`);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
name: "reindex",
|
|
44
|
-
description: "Re-index the knowledge base from configured sources",
|
|
45
|
-
usage: "kb reindex [--full]",
|
|
46
|
-
run: async (args) => {
|
|
47
|
-
const full = args.includes("--full");
|
|
48
|
-
const { store, indexer, curated, config } = await ctx();
|
|
49
|
-
console.log("Indexing sources...");
|
|
50
|
-
const progressCb = (p) => {
|
|
51
|
-
if (p.phase === "chunking" && p.currentFile) {
|
|
52
|
-
process.stdout.write(`\r [${p.filesProcessed + 1}/${p.filesTotal}] ${p.currentFile}`);
|
|
53
|
-
}
|
|
54
|
-
if (p.phase === "done") process.stdout.write("\n");
|
|
55
|
-
};
|
|
56
|
-
let result;
|
|
57
|
-
if (full) {
|
|
58
|
-
console.log("Dropping existing index for full reindex...");
|
|
59
|
-
result = await indexer.reindexAll(config, progressCb);
|
|
60
|
-
} else {
|
|
61
|
-
result = await indexer.index(config, progressCb);
|
|
62
|
-
}
|
|
63
|
-
console.log(
|
|
64
|
-
`Done: ${result.filesProcessed} files, ${result.chunksCreated} chunks in ${(result.durationMs / 1e3).toFixed(1)}s`
|
|
65
|
-
);
|
|
66
|
-
console.log("Building FTS index...");
|
|
67
|
-
await store.createFtsIndex();
|
|
68
|
-
console.log("Re-indexing curated entries...");
|
|
69
|
-
const curatedResult = await curated.reindexAll();
|
|
70
|
-
console.log(`Curated: ${curatedResult.indexed} entries restored`);
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
name: "serve",
|
|
75
|
-
description: "Start the MCP server (stdio or HTTP)",
|
|
76
|
-
usage: "kb serve [--transport stdio|http] [--port N]",
|
|
77
|
-
run: async (args) => {
|
|
78
|
-
const serverEntry = resolve(__dirname, "..", "..", "..", "server", "dist", "index.js");
|
|
79
|
-
const transport = extractStrFlag(args, "--transport", "stdio");
|
|
80
|
-
const port = extractStrFlag(args, "--port", "3210");
|
|
81
|
-
const child = fork(serverEntry, [], {
|
|
82
|
-
stdio: transport === "stdio" ? ["pipe", "pipe", "inherit", "ipc"] : "inherit",
|
|
83
|
-
env: {
|
|
84
|
-
...process.env,
|
|
85
|
-
KB_TRANSPORT: transport,
|
|
86
|
-
KB_PORT: port
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
if (transport === "stdio" && child.stdin && child.stdout) {
|
|
90
|
-
process.stdin.pipe(child.stdin);
|
|
91
|
-
child.stdout.pipe(process.stdout);
|
|
92
|
-
}
|
|
93
|
-
child.on("exit", (code) => process.exit(code ?? 0));
|
|
94
|
-
process.on("SIGINT", () => child.kill("SIGINT"));
|
|
95
|
-
process.on("SIGTERM", () => child.kill("SIGTERM"));
|
|
96
|
-
await new Promise(() => {
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
name: "init",
|
|
102
|
-
description: "Initialize a knowledge base in the current directory",
|
|
103
|
-
usage: "kb init [--force]",
|
|
104
|
-
run: async (args) => {
|
|
105
|
-
const force = args.includes("--force");
|
|
106
|
-
const { initProject } = await import("./init.js");
|
|
107
|
-
await initProject({ force });
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
name: "check",
|
|
112
|
-
description: "Run incremental typecheck and lint",
|
|
113
|
-
usage: "kb check [--cwd <dir>] [--files f1,f2] [--skip-types] [--skip-lint]",
|
|
114
|
-
run: async (args) => {
|
|
115
|
-
const cwd = extractStrFlag(args, "--cwd", "").trim() || void 0;
|
|
116
|
-
const filesValue = extractStrFlag(args, "--files", "");
|
|
117
|
-
const files = filesValue.split(",").map((item) => item.trim()).filter(Boolean);
|
|
118
|
-
let skipTypes = false;
|
|
119
|
-
if (args.includes("--skip-types")) {
|
|
120
|
-
args.splice(args.indexOf("--skip-types"), 1);
|
|
121
|
-
skipTypes = true;
|
|
122
|
-
}
|
|
123
|
-
let skipLint = false;
|
|
124
|
-
if (args.includes("--skip-lint")) {
|
|
125
|
-
args.splice(args.indexOf("--skip-lint"), 1);
|
|
126
|
-
skipLint = true;
|
|
127
|
-
}
|
|
128
|
-
const result = await check({
|
|
129
|
-
cwd,
|
|
130
|
-
files: files.length > 0 ? files : void 0,
|
|
131
|
-
skipTypes,
|
|
132
|
-
skipLint
|
|
133
|
-
});
|
|
134
|
-
printCheckResult(result);
|
|
135
|
-
if (!result.passed) process.exitCode = 1;
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
name: "batch",
|
|
140
|
-
description: "Execute built-in operations from JSON input",
|
|
141
|
-
usage: "kb batch [--file path] [--concurrency N]",
|
|
142
|
-
run: async (args) => {
|
|
143
|
-
const filePath = extractStrFlag(args, "--file", "").trim() || void 0;
|
|
144
|
-
const overrideConcurrency = (() => {
|
|
145
|
-
const idx = args.indexOf("--concurrency");
|
|
146
|
-
if (idx === -1 || idx + 1 >= args.length) return 0;
|
|
147
|
-
const val = Number.parseInt(args.splice(idx, 2)[1], 10);
|
|
148
|
-
return Number.isNaN(val) ? 0 : val;
|
|
149
|
-
})();
|
|
150
|
-
const input = await readInput(filePath);
|
|
151
|
-
if (!input.trim()) {
|
|
152
|
-
console.error("Usage: kb batch [--file path] [--concurrency N]");
|
|
153
|
-
process.exit(1);
|
|
154
|
-
}
|
|
155
|
-
const payload = parseBatchPayload(input);
|
|
156
|
-
const concurrency = overrideConcurrency > 0 ? overrideConcurrency : payload.concurrency;
|
|
157
|
-
const needsContext = payload.operations.some((operation) => operation.type !== "check");
|
|
158
|
-
const context = needsContext ? await ctx() : null;
|
|
159
|
-
const result = await batch(
|
|
160
|
-
payload.operations,
|
|
161
|
-
async (operation) => executeCliBatchOperation(operation, context),
|
|
162
|
-
{ concurrency }
|
|
163
|
-
);
|
|
164
|
-
console.log(JSON.stringify(result, null, 2));
|
|
165
|
-
if (result.some((item) => item.status === "error")) process.exitCode = 1;
|
|
166
|
-
}
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
name: "health",
|
|
170
|
-
description: "Run project health checks on the current directory",
|
|
171
|
-
usage: "kb health [path]",
|
|
172
|
-
run: async (args) => {
|
|
173
|
-
const targetPath = args.shift();
|
|
174
|
-
const result = health(targetPath);
|
|
175
|
-
console.log(`Project Health: ${result.path}`);
|
|
176
|
-
console.log("\u2500".repeat(50));
|
|
177
|
-
for (const check2 of result.checks) {
|
|
178
|
-
const icon = check2.status === "pass" ? "+" : check2.status === "warn" ? "~" : "X";
|
|
179
|
-
console.log(` [${icon}] ${check2.name}: ${check2.message}`);
|
|
180
|
-
}
|
|
181
|
-
console.log("\u2500".repeat(50));
|
|
182
|
-
console.log(`Score: ${result.score}% \u2014 ${result.summary}`);
|
|
183
|
-
}
|
|
184
|
-
},
|
|
185
|
-
{
|
|
186
|
-
name: "replay",
|
|
187
|
-
description: "Show recent tool invocation audit trail",
|
|
188
|
-
usage: "kb replay [--last N] [--tool <name>] [--source mcp|cli]",
|
|
189
|
-
run: async (args) => {
|
|
190
|
-
const last = Number.parseInt(args[args.indexOf("--last") + 1], 10) || 20;
|
|
191
|
-
const toolFilter = args.includes("--tool") ? args[args.indexOf("--tool") + 1] : void 0;
|
|
192
|
-
const sourceFilter = args.includes("--source") ? args[args.indexOf("--source") + 1] : void 0;
|
|
193
|
-
const entries = replayList({ last, tool: toolFilter, source: sourceFilter });
|
|
194
|
-
if (entries.length === 0) {
|
|
195
|
-
console.log("No replay entries. Activity is logged when tools are invoked.");
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
console.log(`Replay Log (${entries.length} entries)
|
|
199
|
-
`);
|
|
200
|
-
for (const e of entries) {
|
|
201
|
-
const time = e.ts.split("T")[1]?.split(".")[0] ?? e.ts;
|
|
202
|
-
const status = e.status === "ok" ? "\u2713" : "\u2717";
|
|
203
|
-
console.log(`${time} ${status} ${e.tool} (${e.durationMs}ms) [${e.source}]`);
|
|
204
|
-
console.log(` in: ${e.input}`);
|
|
205
|
-
console.log(` out: ${e.output}`);
|
|
206
|
-
}
|
|
207
|
-
replayTrim();
|
|
208
|
-
}
|
|
209
|
-
},
|
|
210
|
-
{
|
|
211
|
-
name: "replay-clear",
|
|
212
|
-
description: "Clear the replay audit trail",
|
|
213
|
-
run: async () => {
|
|
214
|
-
replayClear();
|
|
215
|
-
console.log("Replay log cleared.");
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
|
-
{
|
|
219
|
-
name: "tui",
|
|
220
|
-
description: "Launch interactive terminal dashboard (human monitoring)",
|
|
221
|
-
run: async () => {
|
|
222
|
-
try {
|
|
223
|
-
const { launch } = await import("@kb/tui");
|
|
224
|
-
const { store, embedder, config } = await ctx();
|
|
225
|
-
launch({ store, embedder, config });
|
|
226
|
-
} catch (err) {
|
|
227
|
-
if (err.code === "ERR_MODULE_NOT_FOUND") {
|
|
228
|
-
console.error(
|
|
229
|
-
"TUI requires ink and react. Install them with:\n pnpm add -D ink react @types/react"
|
|
230
|
-
);
|
|
231
|
-
process.exit(1);
|
|
232
|
-
}
|
|
233
|
-
throw err;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
];
|
|
238
|
-
export {
|
|
239
|
-
systemCommands
|
|
240
|
-
};
|
|
241
|
-
//# sourceMappingURL=system.js.map
|
|
1
|
+
import{fork as f}from"node:child_process";import{dirname as m,resolve as h}from"node:path";import{fileURLToPath as g}from"node:url";import{batch as y,check as x,health as k,replayClear as w,replayList as $,replayTrim as b}from"@kb/tools";import{ctx as p}from"../context.js";import{executeCliBatchOperation as I,extractStrFlag as a,parseBatchPayload as R,printCheckResult as N,readInput as T}from"../helpers.js";const C=m(g(import.meta.url)),E=[{name:"status",description:"Show knowledge base index status and statistics",run:async()=>{const{store:e}=await p(),s=await e.getStats(),t=await e.listSourcePaths();console.log("Knowledge Base Status"),console.log("\u2500".repeat(40)),console.log(` Records: ${s.totalRecords}`),console.log(` Files: ${s.totalFiles}`),console.log(` Indexed: ${s.lastIndexedAt??"Never"}`),console.log(` Backend: ${s.storeBackend}`),console.log(` Model: ${s.embeddingModel}`),console.log(""),console.log("Content Types:");for(const[n,o]of Object.entries(s.contentTypeBreakdown))console.log(` ${n}: ${o}`);if(t.length>0){console.log(""),console.log(`Files (${t.length} total):`);for(const n of t.slice(0,20))console.log(` ${n}`);t.length>20&&console.log(` ... and ${t.length-20} more`)}}},{name:"reindex",description:"Re-index the knowledge base from configured sources",usage:"kb reindex [--full]",run:async e=>{const s=e.includes("--full"),{store:t,indexer:n,curated:o,config:i}=await p();console.log("Indexing sources...");const l=r=>{r.phase==="chunking"&&r.currentFile&&process.stdout.write(`\r [${r.filesProcessed+1}/${r.filesTotal}] ${r.currentFile}`),r.phase==="done"&&process.stdout.write(`
|
|
2
|
+
`)};let c;s?(console.log("Dropping existing index for full reindex..."),c=await n.reindexAll(i,l)):c=await n.index(i,l),console.log(`Done: ${c.filesProcessed} files, ${c.chunksCreated} chunks in ${(c.durationMs/1e3).toFixed(1)}s`),console.log("Building FTS index..."),await t.createFtsIndex(),console.log("Re-indexing curated entries...");const d=await o.reindexAll();console.log(`Curated: ${d.indexed} entries restored`)}},{name:"serve",description:"Start the MCP server (stdio or HTTP)",usage:"kb serve [--transport stdio|http] [--port N]",run:async e=>{const s=h(C,"..","..","..","server","dist","index.js"),t=a(e,"--transport","stdio"),n=a(e,"--port","3210"),o=f(s,[],{stdio:t==="stdio"?["pipe","pipe","inherit","ipc"]:"inherit",env:{...process.env,KB_TRANSPORT:t,KB_PORT:n}});t==="stdio"&&o.stdin&&o.stdout&&(process.stdin.pipe(o.stdin),o.stdout.pipe(process.stdout)),o.on("exit",i=>process.exit(i??0)),process.on("SIGINT",()=>o.kill("SIGINT")),process.on("SIGTERM",()=>o.kill("SIGTERM")),await new Promise(()=>{})}},{name:"init",description:"Initialize a knowledge base in the current directory",usage:"kb init [--force]",run:async e=>{const s=e.includes("--force"),{initProject:t}=await import("./init.js");await t({force:s})}},{name:"check",description:"Run incremental typecheck and lint",usage:"kb check [--cwd <dir>] [--files f1,f2] [--skip-types] [--skip-lint]",run:async e=>{const s=a(e,"--cwd","").trim()||void 0,n=a(e,"--files","").split(",").map(c=>c.trim()).filter(Boolean);let o=!1;e.includes("--skip-types")&&(e.splice(e.indexOf("--skip-types"),1),o=!0);let i=!1;e.includes("--skip-lint")&&(e.splice(e.indexOf("--skip-lint"),1),i=!0);const l=await x({cwd:s,files:n.length>0?n:void 0,skipTypes:o,skipLint:i});N(l),l.passed||(process.exitCode=1)}},{name:"batch",description:"Execute built-in operations from JSON input",usage:"kb batch [--file path] [--concurrency N]",run:async e=>{const s=a(e,"--file","").trim()||void 0,t=(()=>{const r=e.indexOf("--concurrency");if(r===-1||r+1>=e.length)return 0;const u=Number.parseInt(e.splice(r,2)[1],10);return Number.isNaN(u)?0:u})(),n=await T(s);n.trim()||(console.error("Usage: kb batch [--file path] [--concurrency N]"),process.exit(1));const o=R(n),i=t>0?t:o.concurrency,c=o.operations.some(r=>r.type!=="check")?await p():null,d=await y(o.operations,async r=>I(r,c),{concurrency:i});console.log(JSON.stringify(d,null,2)),d.some(r=>r.status==="error")&&(process.exitCode=1)}},{name:"health",description:"Run project health checks on the current directory",usage:"kb health [path]",run:async e=>{const s=e.shift(),t=k(s);console.log(`Project Health: ${t.path}`),console.log("\u2500".repeat(50));for(const n of t.checks){const o=n.status==="pass"?"+":n.status==="warn"?"~":"X";console.log(` [${o}] ${n.name}: ${n.message}`)}console.log("\u2500".repeat(50)),console.log(`Score: ${t.score}% \u2014 ${t.summary}`)}},{name:"replay",description:"Show recent tool invocation audit trail",usage:"kb replay [--last N] [--tool <name>] [--source mcp|cli]",run:async e=>{const s=Number.parseInt(e[e.indexOf("--last")+1],10)||20,t=e.includes("--tool")?e[e.indexOf("--tool")+1]:void 0,n=e.includes("--source")?e[e.indexOf("--source")+1]:void 0,o=$({last:s,tool:t,source:n});if(o.length===0){console.log("No replay entries. Activity is logged when tools are invoked.");return}console.log(`Replay Log (${o.length} entries)
|
|
3
|
+
`);for(const i of o){const l=i.ts.split("T")[1]?.split(".")[0]??i.ts,c=i.status==="ok"?"\u2713":"\u2717";console.log(`${l} ${c} ${i.tool} (${i.durationMs}ms) [${i.source}]`),console.log(` in: ${i.input}`),console.log(` out: ${i.output}`)}b()}},{name:"replay-clear",description:"Clear the replay audit trail",run:async()=>{w(),console.log("Replay log cleared.")}},{name:"tui",description:"Launch interactive terminal dashboard (human monitoring)",run:async()=>{try{const{launch:e}=await import("@kb/tui"),{store:s,embedder:t,config:n}=await p();e({store:s,embedder:t,config:n})}catch(e){throw e.code==="ERR_MODULE_NOT_FOUND"&&(console.error(`TUI requires ink and react. Install them with:
|
|
4
|
+
pnpm add -D ink react @types/react`),process.exit(1)),e}}}];export{E as systemCommands};
|
|
@@ -1,388 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
deleteWorkset,
|
|
4
|
-
getWorkset,
|
|
5
|
-
laneCreate,
|
|
6
|
-
laneDiff,
|
|
7
|
-
laneDiscard,
|
|
8
|
-
laneList,
|
|
9
|
-
laneMerge,
|
|
10
|
-
laneStatus,
|
|
11
|
-
listWorksets,
|
|
12
|
-
queueClear,
|
|
13
|
-
queueCreate,
|
|
14
|
-
queueDelete,
|
|
15
|
-
queueDone,
|
|
16
|
-
queueFail,
|
|
17
|
-
queueGet,
|
|
18
|
-
queueList,
|
|
19
|
-
queueNext,
|
|
20
|
-
queuePush,
|
|
21
|
-
removeFromWorkset,
|
|
22
|
-
saveWorkset,
|
|
23
|
-
stashClear,
|
|
24
|
-
stashDelete,
|
|
25
|
-
stashGet,
|
|
26
|
-
stashList,
|
|
27
|
-
stashSet
|
|
28
|
-
} from "@kb/tools";
|
|
29
|
-
import {
|
|
30
|
-
extractStrFlag,
|
|
31
|
-
parseMaybeJsonString,
|
|
32
|
-
printWorkset,
|
|
33
|
-
readStdin,
|
|
34
|
-
splitCsv
|
|
35
|
-
} from "../helpers.js";
|
|
36
|
-
const workspaceCommands = [
|
|
37
|
-
{
|
|
38
|
-
name: "workset",
|
|
39
|
-
description: "Manage saved file sets",
|
|
40
|
-
usage: "kb workset <action> [name] [--files f1,f2] [--description desc]",
|
|
41
|
-
run: async (args) => {
|
|
42
|
-
const action = args.shift()?.trim();
|
|
43
|
-
const files = splitCsv(extractStrFlag(args, "--files", ""));
|
|
44
|
-
const description = extractStrFlag(args, "--description", "").trim() || void 0;
|
|
45
|
-
const name = args.shift()?.trim();
|
|
46
|
-
if (!action) {
|
|
47
|
-
console.error("Usage: kb workset <action> [name] [--files f1,f2] [--description desc]");
|
|
48
|
-
console.error("Actions: save, get, list, delete, add, remove");
|
|
49
|
-
process.exit(1);
|
|
50
|
-
}
|
|
51
|
-
switch (action) {
|
|
52
|
-
case "save": {
|
|
53
|
-
if (!name || files.length === 0) {
|
|
54
|
-
console.error("Usage: kb workset save <name> --files f1,f2 [--description desc]");
|
|
55
|
-
process.exit(1);
|
|
56
|
-
}
|
|
57
|
-
const workset = saveWorkset(name, files, { description });
|
|
58
|
-
console.log(`Saved workset: ${workset.name}`);
|
|
59
|
-
printWorkset(workset);
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
case "get": {
|
|
63
|
-
if (!name) {
|
|
64
|
-
console.error("Usage: kb workset get <name>");
|
|
65
|
-
process.exit(1);
|
|
66
|
-
}
|
|
67
|
-
const workset = getWorkset(name);
|
|
68
|
-
if (!workset) {
|
|
69
|
-
console.log(`No workset found: ${name}`);
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
printWorkset(workset);
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
case "list": {
|
|
76
|
-
const worksets = listWorksets();
|
|
77
|
-
if (worksets.length === 0) {
|
|
78
|
-
console.log("No worksets saved.");
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
console.log(`Worksets (${worksets.length})`);
|
|
82
|
-
console.log("\u2500".repeat(60));
|
|
83
|
-
for (const workset of worksets) {
|
|
84
|
-
printWorkset(workset);
|
|
85
|
-
console.log("");
|
|
86
|
-
}
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
case "delete": {
|
|
90
|
-
if (!name) {
|
|
91
|
-
console.error("Usage: kb workset delete <name>");
|
|
92
|
-
process.exit(1);
|
|
93
|
-
}
|
|
94
|
-
const deleted = deleteWorkset(name);
|
|
95
|
-
console.log(deleted ? `Deleted workset: ${name}` : `No workset found: ${name}`);
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
case "add": {
|
|
99
|
-
if (!name || files.length === 0) {
|
|
100
|
-
console.error("Usage: kb workset add <name> --files f1,f2");
|
|
101
|
-
process.exit(1);
|
|
102
|
-
}
|
|
103
|
-
const workset = addToWorkset(name, files);
|
|
104
|
-
console.log(`Updated workset: ${workset.name}`);
|
|
105
|
-
printWorkset(workset);
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
case "remove": {
|
|
109
|
-
if (!name || files.length === 0) {
|
|
110
|
-
console.error("Usage: kb workset remove <name> --files f1,f2");
|
|
111
|
-
process.exit(1);
|
|
112
|
-
}
|
|
113
|
-
const workset = removeFromWorkset(name, files);
|
|
114
|
-
if (!workset) {
|
|
115
|
-
console.log(`No workset found: ${name}`);
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
console.log(`Updated workset: ${workset.name}`);
|
|
119
|
-
printWorkset(workset);
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
default:
|
|
123
|
-
console.error(`Unknown workset action: ${action}`);
|
|
124
|
-
console.error("Actions: save, get, list, delete, add, remove");
|
|
125
|
-
process.exit(1);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
name: "stash",
|
|
131
|
-
description: "Persist and retrieve named intermediate values",
|
|
132
|
-
usage: "kb stash <set|get|list|delete|clear> [key] [value]",
|
|
133
|
-
run: async (args) => {
|
|
134
|
-
const action = args.shift()?.trim();
|
|
135
|
-
const key = args.shift()?.trim();
|
|
136
|
-
if (!action) {
|
|
137
|
-
console.error("Usage: kb stash <set|get|list|delete|clear> [key] [value]");
|
|
138
|
-
process.exit(1);
|
|
139
|
-
}
|
|
140
|
-
switch (action) {
|
|
141
|
-
case "set": {
|
|
142
|
-
if (!key) {
|
|
143
|
-
console.error("Usage: kb stash set <key> <value>");
|
|
144
|
-
process.exit(1);
|
|
145
|
-
}
|
|
146
|
-
const inlineValue = args.join(" ");
|
|
147
|
-
const stdinValue = inlineValue.trim() ? "" : await readStdin();
|
|
148
|
-
const rawValue = inlineValue || stdinValue;
|
|
149
|
-
const entry = stashSet(key, parseMaybeJsonString(rawValue));
|
|
150
|
-
console.log(`Stored stash entry: ${entry.key}`);
|
|
151
|
-
console.log(` Type: ${entry.type}`);
|
|
152
|
-
console.log(` Stored: ${entry.storedAt}`);
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
case "get": {
|
|
156
|
-
if (!key) {
|
|
157
|
-
console.error("Usage: kb stash get <key>");
|
|
158
|
-
process.exit(1);
|
|
159
|
-
}
|
|
160
|
-
const entry = stashGet(key);
|
|
161
|
-
if (!entry) {
|
|
162
|
-
console.log(`No stash entry found: ${key}`);
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
console.log(JSON.stringify(entry, null, 2));
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
case "list": {
|
|
169
|
-
const entries = stashList();
|
|
170
|
-
if (entries.length === 0) {
|
|
171
|
-
console.log("No stash entries saved.");
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
console.log(`Stash entries (${entries.length})`);
|
|
175
|
-
console.log("\u2500".repeat(60));
|
|
176
|
-
for (const entry of entries) {
|
|
177
|
-
console.log(`${entry.key} (${entry.type})`);
|
|
178
|
-
console.log(` Stored: ${entry.storedAt}`);
|
|
179
|
-
}
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
case "delete": {
|
|
183
|
-
if (!key) {
|
|
184
|
-
console.error("Usage: kb stash delete <key>");
|
|
185
|
-
process.exit(1);
|
|
186
|
-
}
|
|
187
|
-
const deleted = stashDelete(key);
|
|
188
|
-
console.log(deleted ? `Deleted stash entry: ${key}` : `No stash entry found: ${key}`);
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
case "clear": {
|
|
192
|
-
const count = stashClear();
|
|
193
|
-
console.log(`Cleared ${count} stash entr${count === 1 ? "y" : "ies"}.`);
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
default:
|
|
197
|
-
console.error(`Unknown stash action: ${action}`);
|
|
198
|
-
console.error("Actions: set, get, list, delete, clear");
|
|
199
|
-
process.exit(1);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
},
|
|
203
|
-
{
|
|
204
|
-
name: "lane",
|
|
205
|
-
description: "Manage verified lanes \u2014 isolated file copies for parallel exploration",
|
|
206
|
-
usage: "kb lane <create|list|status|diff|merge|discard> [name] [--files f1,f2]",
|
|
207
|
-
run: async (args) => {
|
|
208
|
-
const action = args.shift();
|
|
209
|
-
if (!action || !["create", "list", "status", "diff", "merge", "discard"].includes(action)) {
|
|
210
|
-
console.error(
|
|
211
|
-
"Usage: kb lane <create|list|status|diff|merge|discard> [name] [--files f1,f2]"
|
|
212
|
-
);
|
|
213
|
-
process.exit(1);
|
|
214
|
-
}
|
|
215
|
-
if (action === "list") {
|
|
216
|
-
const lanes = laneList();
|
|
217
|
-
if (lanes.length === 0) {
|
|
218
|
-
console.log("No active lanes.");
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
for (const lane of lanes) {
|
|
222
|
-
console.log(
|
|
223
|
-
`${lane.name} (${lane.sourceFiles.length} files, created ${lane.createdAt})`
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
const name = args.shift();
|
|
229
|
-
if (!name) {
|
|
230
|
-
console.error(`Lane name is required for "${action}".`);
|
|
231
|
-
process.exit(1);
|
|
232
|
-
}
|
|
233
|
-
switch (action) {
|
|
234
|
-
case "create": {
|
|
235
|
-
const filesStr = extractStrFlag(args, "--files", "");
|
|
236
|
-
if (!filesStr) {
|
|
237
|
-
console.error("Usage: kb lane create <name> --files file1.ts,file2.ts");
|
|
238
|
-
process.exit(1);
|
|
239
|
-
}
|
|
240
|
-
const files = filesStr.split(",").map((f) => f.trim());
|
|
241
|
-
const meta = laneCreate(name, files);
|
|
242
|
-
console.log(`Lane "${meta.name}" created with ${meta.sourceFiles.length} files.`);
|
|
243
|
-
break;
|
|
244
|
-
}
|
|
245
|
-
case "status": {
|
|
246
|
-
const result = laneStatus(name);
|
|
247
|
-
console.log(`Lane: ${result.name}`);
|
|
248
|
-
console.log(
|
|
249
|
-
`Modified: ${result.modified} | Added: ${result.added} | Deleted: ${result.deleted}`
|
|
250
|
-
);
|
|
251
|
-
for (const entry of result.entries) {
|
|
252
|
-
console.log(` ${entry.status.padEnd(10)} ${entry.file}`);
|
|
253
|
-
}
|
|
254
|
-
break;
|
|
255
|
-
}
|
|
256
|
-
case "diff": {
|
|
257
|
-
const result = laneDiff(name);
|
|
258
|
-
console.log(
|
|
259
|
-
`Lane: ${result.name} \u2014 ${result.modified} modified, ${result.added} added, ${result.deleted} deleted`
|
|
260
|
-
);
|
|
261
|
-
for (const entry of result.entries) {
|
|
262
|
-
if (entry.diff) {
|
|
263
|
-
console.log(`
|
|
264
|
-
--- ${entry.file} (${entry.status})`);
|
|
265
|
-
console.log(entry.diff);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
break;
|
|
269
|
-
}
|
|
270
|
-
case "merge": {
|
|
271
|
-
const result = laneMerge(name);
|
|
272
|
-
console.log(`Merged ${result.filesMerged} files from lane "${result.name}".`);
|
|
273
|
-
for (const f of result.files) console.log(` ${f}`);
|
|
274
|
-
break;
|
|
275
|
-
}
|
|
276
|
-
case "discard": {
|
|
277
|
-
const ok = laneDiscard(name);
|
|
278
|
-
console.log(ok ? `Lane "${name}" discarded.` : `Lane "${name}" not found.`);
|
|
279
|
-
break;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
},
|
|
284
|
-
{
|
|
285
|
-
name: "queue",
|
|
286
|
-
description: "Manage task queues for sequential agent operations",
|
|
287
|
-
usage: "kb queue <create|push|next|done|fail|get|list|clear|delete> [name] [args]",
|
|
288
|
-
run: async (args) => {
|
|
289
|
-
const action = args.shift();
|
|
290
|
-
if (!action || !["create", "push", "next", "done", "fail", "get", "list", "clear", "delete"].includes(
|
|
291
|
-
action
|
|
292
|
-
)) {
|
|
293
|
-
console.error(
|
|
294
|
-
"Usage: kb queue <create|push|next|done|fail|get|list|clear|delete> [name] [args]"
|
|
295
|
-
);
|
|
296
|
-
process.exit(1);
|
|
297
|
-
}
|
|
298
|
-
if (action === "list") {
|
|
299
|
-
const queues = queueList();
|
|
300
|
-
if (queues.length === 0) {
|
|
301
|
-
console.log("No queues.");
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
for (const q of queues) {
|
|
305
|
-
console.log(
|
|
306
|
-
`${q.name} pending:${q.pending} done:${q.done} failed:${q.failed} total:${q.total}`
|
|
307
|
-
);
|
|
308
|
-
}
|
|
309
|
-
return;
|
|
310
|
-
}
|
|
311
|
-
const name = args.shift();
|
|
312
|
-
if (!name) {
|
|
313
|
-
console.error(`Queue name is required for "${action}".`);
|
|
314
|
-
process.exit(1);
|
|
315
|
-
}
|
|
316
|
-
switch (action) {
|
|
317
|
-
case "create": {
|
|
318
|
-
const q = queueCreate(name);
|
|
319
|
-
console.log(`Queue "${q.name}" created.`);
|
|
320
|
-
break;
|
|
321
|
-
}
|
|
322
|
-
case "push": {
|
|
323
|
-
const title = args.join(" ") || "Untitled task";
|
|
324
|
-
const item = queuePush(name, title);
|
|
325
|
-
console.log(`Pushed "${item.title}" (${item.id}) to queue "${name}".`);
|
|
326
|
-
break;
|
|
327
|
-
}
|
|
328
|
-
case "next": {
|
|
329
|
-
const item = queueNext(name);
|
|
330
|
-
if (!item) {
|
|
331
|
-
console.log(`No pending items in queue "${name}".`);
|
|
332
|
-
} else {
|
|
333
|
-
console.log(`Next: ${item.title} (${item.id})`);
|
|
334
|
-
}
|
|
335
|
-
break;
|
|
336
|
-
}
|
|
337
|
-
case "done": {
|
|
338
|
-
const id = args.shift();
|
|
339
|
-
if (!id) {
|
|
340
|
-
console.error("Usage: kb queue done <name> <id>");
|
|
341
|
-
process.exit(1);
|
|
342
|
-
}
|
|
343
|
-
const item = queueDone(name, id);
|
|
344
|
-
console.log(`Marked "${item.title}" as done.`);
|
|
345
|
-
break;
|
|
346
|
-
}
|
|
347
|
-
case "fail": {
|
|
348
|
-
const id = args.shift();
|
|
349
|
-
const error = args.join(" ") || "Unknown error";
|
|
350
|
-
if (!id) {
|
|
351
|
-
console.error("Usage: kb queue fail <name> <id> [error message]");
|
|
352
|
-
process.exit(1);
|
|
353
|
-
}
|
|
354
|
-
const item = queueFail(name, id, error);
|
|
355
|
-
console.log(`Marked "${item.title}" as failed: ${error}`);
|
|
356
|
-
break;
|
|
357
|
-
}
|
|
358
|
-
case "get": {
|
|
359
|
-
const q = queueGet(name);
|
|
360
|
-
if (!q) {
|
|
361
|
-
console.log(`Queue "${name}" not found.`);
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
console.log(`Queue: ${q.name} (${q.items.length} items)`);
|
|
365
|
-
for (const item of q.items) {
|
|
366
|
-
const extra = item.error ? ` \u2014 ${item.error}` : "";
|
|
367
|
-
console.log(` ${item.status.padEnd(12)} ${item.id} ${item.title}${extra}`);
|
|
368
|
-
}
|
|
369
|
-
break;
|
|
370
|
-
}
|
|
371
|
-
case "clear": {
|
|
372
|
-
const removed = queueClear(name);
|
|
373
|
-
console.log(`Cleared ${removed} completed/failed items from queue "${name}".`);
|
|
374
|
-
break;
|
|
375
|
-
}
|
|
376
|
-
case "delete": {
|
|
377
|
-
const ok = queueDelete(name);
|
|
378
|
-
console.log(ok ? `Queue "${name}" deleted.` : `Queue "${name}" not found.`);
|
|
379
|
-
break;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
];
|
|
385
|
-
export {
|
|
386
|
-
workspaceCommands
|
|
387
|
-
};
|
|
388
|
-
//# sourceMappingURL=workspace.js.map
|
|
1
|
+
import{addToWorkset as c,deleteWorkset as d,getWorkset as f,laneCreate as u,laneDiff as g,laneDiscard as m,laneList as k,laneMerge as $,laneStatus as p,listWorksets as h,queueClear as w,queueCreate as b,queueDelete as x,queueDone as y,queueFail as q,queueGet as v,queueList as U,queueNext as N,queuePush as S,removeFromWorkset as C,saveWorkset as M,stashClear as L,stashDelete as D,stashGet as W,stashList as A,stashSet as Q}from"@kb/tools";import{extractStrFlag as i,parseMaybeJsonString as F,printWorkset as a,readStdin as j,splitCsv as V}from"../helpers.js";const G=[{name:"workset",description:"Manage saved file sets",usage:"kb workset <action> [name] [--files f1,f2] [--description desc]",run:async n=>{const r=n.shift()?.trim(),s=V(i(n,"--files","")),e=i(n,"--description","").trim()||void 0,o=n.shift()?.trim();switch(r||(console.error("Usage: kb workset <action> [name] [--files f1,f2] [--description desc]"),console.error("Actions: save, get, list, delete, add, remove"),process.exit(1)),r){case"save":{(!o||s.length===0)&&(console.error("Usage: kb workset save <name> --files f1,f2 [--description desc]"),process.exit(1));const t=M(o,s,{description:e});console.log(`Saved workset: ${t.name}`),a(t);return}case"get":{o||(console.error("Usage: kb workset get <name>"),process.exit(1));const t=f(o);if(!t){console.log(`No workset found: ${o}`);return}a(t);return}case"list":{const t=h();if(t.length===0){console.log("No worksets saved.");return}console.log(`Worksets (${t.length})`),console.log("\u2500".repeat(60));for(const l of t)a(l),console.log("");return}case"delete":{o||(console.error("Usage: kb workset delete <name>"),process.exit(1));const t=d(o);console.log(t?`Deleted workset: ${o}`:`No workset found: ${o}`);return}case"add":{(!o||s.length===0)&&(console.error("Usage: kb workset add <name> --files f1,f2"),process.exit(1));const t=c(o,s);console.log(`Updated workset: ${t.name}`),a(t);return}case"remove":{(!o||s.length===0)&&(console.error("Usage: kb workset remove <name> --files f1,f2"),process.exit(1));const t=C(o,s);if(!t){console.log(`No workset found: ${o}`);return}console.log(`Updated workset: ${t.name}`),a(t);return}default:console.error(`Unknown workset action: ${r}`),console.error("Actions: save, get, list, delete, add, remove"),process.exit(1)}}},{name:"stash",description:"Persist and retrieve named intermediate values",usage:"kb stash <set|get|list|delete|clear> [key] [value]",run:async n=>{const r=n.shift()?.trim(),s=n.shift()?.trim();switch(r||(console.error("Usage: kb stash <set|get|list|delete|clear> [key] [value]"),process.exit(1)),r){case"set":{s||(console.error("Usage: kb stash set <key> <value>"),process.exit(1));const e=n.join(" "),o=e.trim()?"":await j(),l=Q(s,F(e||o));console.log(`Stored stash entry: ${l.key}`),console.log(` Type: ${l.type}`),console.log(` Stored: ${l.storedAt}`);return}case"get":{s||(console.error("Usage: kb stash get <key>"),process.exit(1));const e=W(s);if(!e){console.log(`No stash entry found: ${s}`);return}console.log(JSON.stringify(e,null,2));return}case"list":{const e=A();if(e.length===0){console.log("No stash entries saved.");return}console.log(`Stash entries (${e.length})`),console.log("\u2500".repeat(60));for(const o of e)console.log(`${o.key} (${o.type})`),console.log(` Stored: ${o.storedAt}`);return}case"delete":{s||(console.error("Usage: kb stash delete <key>"),process.exit(1));const e=D(s);console.log(e?`Deleted stash entry: ${s}`:`No stash entry found: ${s}`);return}case"clear":{const e=L();console.log(`Cleared ${e} stash entr${e===1?"y":"ies"}.`);return}default:console.error(`Unknown stash action: ${r}`),console.error("Actions: set, get, list, delete, clear"),process.exit(1)}}},{name:"lane",description:"Manage verified lanes \u2014 isolated file copies for parallel exploration",usage:"kb lane <create|list|status|diff|merge|discard> [name] [--files f1,f2]",run:async n=>{const r=n.shift();if((!r||!["create","list","status","diff","merge","discard"].includes(r))&&(console.error("Usage: kb lane <create|list|status|diff|merge|discard> [name] [--files f1,f2]"),process.exit(1)),r==="list"){const e=k();if(e.length===0){console.log("No active lanes.");return}for(const o of e)console.log(`${o.name} (${o.sourceFiles.length} files, created ${o.createdAt})`);return}const s=n.shift();switch(s||(console.error(`Lane name is required for "${r}".`),process.exit(1)),r){case"create":{const e=i(n,"--files","");e||(console.error("Usage: kb lane create <name> --files file1.ts,file2.ts"),process.exit(1));const o=e.split(",").map(l=>l.trim()),t=u(s,o);console.log(`Lane "${t.name}" created with ${t.sourceFiles.length} files.`);break}case"status":{const e=p(s);console.log(`Lane: ${e.name}`),console.log(`Modified: ${e.modified} | Added: ${e.added} | Deleted: ${e.deleted}`);for(const o of e.entries)console.log(` ${o.status.padEnd(10)} ${o.file}`);break}case"diff":{const e=g(s);console.log(`Lane: ${e.name} \u2014 ${e.modified} modified, ${e.added} added, ${e.deleted} deleted`);for(const o of e.entries)o.diff&&(console.log(`
|
|
2
|
+
--- ${o.file} (${o.status})`),console.log(o.diff));break}case"merge":{const e=$(s);console.log(`Merged ${e.filesMerged} files from lane "${e.name}".`);for(const o of e.files)console.log(` ${o}`);break}case"discard":{const e=m(s);console.log(e?`Lane "${s}" discarded.`:`Lane "${s}" not found.`);break}}}},{name:"queue",description:"Manage task queues for sequential agent operations",usage:"kb queue <create|push|next|done|fail|get|list|clear|delete> [name] [args]",run:async n=>{const r=n.shift();if((!r||!["create","push","next","done","fail","get","list","clear","delete"].includes(r))&&(console.error("Usage: kb queue <create|push|next|done|fail|get|list|clear|delete> [name] [args]"),process.exit(1)),r==="list"){const e=U();if(e.length===0){console.log("No queues.");return}for(const o of e)console.log(`${o.name} pending:${o.pending} done:${o.done} failed:${o.failed} total:${o.total}`);return}const s=n.shift();switch(s||(console.error(`Queue name is required for "${r}".`),process.exit(1)),r){case"create":{const e=b(s);console.log(`Queue "${e.name}" created.`);break}case"push":{const e=n.join(" ")||"Untitled task",o=S(s,e);console.log(`Pushed "${o.title}" (${o.id}) to queue "${s}".`);break}case"next":{const e=N(s);console.log(e?`Next: ${e.title} (${e.id})`:`No pending items in queue "${s}".`);break}case"done":{const e=n.shift();e||(console.error("Usage: kb queue done <name> <id>"),process.exit(1));const o=y(s,e);console.log(`Marked "${o.title}" as done.`);break}case"fail":{const e=n.shift(),o=n.join(" ")||"Unknown error";e||(console.error("Usage: kb queue fail <name> <id> [error message]"),process.exit(1));const t=q(s,e,o);console.log(`Marked "${t.title}" as failed: ${o}`);break}case"get":{const e=v(s);if(!e){console.log(`Queue "${s}" not found.`);return}console.log(`Queue: ${e.name} (${e.items.length} items)`);for(const o of e.items){const t=o.error?` \u2014 ${o.error}`:"";console.log(` ${o.status.padEnd(12)} ${o.id} ${o.title}${t}`)}break}case"clear":{const e=w(s);console.log(`Cleared ${e} completed/failed items from queue "${s}".`);break}case"delete":{const e=x(s);console.log(e?`Queue "${s}" deleted.`:`Queue "${s}" not found.`);break}}}}];export{G as workspaceCommands};
|
|
@@ -1,14 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
let _ctx = null;
|
|
3
|
-
async function ctx() {
|
|
4
|
-
if (!_ctx) _ctx = await initKB();
|
|
5
|
-
return _ctx;
|
|
6
|
-
}
|
|
7
|
-
function getCtx() {
|
|
8
|
-
return _ctx;
|
|
9
|
-
}
|
|
10
|
-
export {
|
|
11
|
-
ctx,
|
|
12
|
-
getCtx
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=context.js.map
|
|
1
|
+
import{initKB as n}from"./kb-init.js";let t=null;async function o(){return t||(t=await n()),t}function r(){return t}export{o as ctx,r as getCtx};
|