@vpxa/kb 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1140 -0
- package/bin/kb.mjs +10 -0
- package/package.json +67 -0
- package/packages/analyzers/dist/blast-radius-analyzer.d.ts +23 -0
- package/packages/analyzers/dist/blast-radius-analyzer.js +114 -0
- package/packages/analyzers/dist/dependency-analyzer.d.ts +29 -0
- package/packages/analyzers/dist/dependency-analyzer.js +425 -0
- package/packages/analyzers/dist/diagram-generator.d.ts +13 -0
- package/packages/analyzers/dist/diagram-generator.js +86 -0
- package/packages/analyzers/dist/entry-point-analyzer.d.ts +19 -0
- package/packages/analyzers/dist/entry-point-analyzer.js +239 -0
- package/packages/analyzers/dist/index.d.ts +14 -0
- package/packages/analyzers/dist/index.js +23 -0
- package/packages/analyzers/dist/knowledge-producer.d.ts +32 -0
- package/packages/analyzers/dist/knowledge-producer.js +113 -0
- package/packages/analyzers/dist/pattern-analyzer.d.ts +12 -0
- package/packages/analyzers/dist/pattern-analyzer.js +359 -0
- package/packages/analyzers/dist/regex-call-graph.d.ts +17 -0
- package/packages/analyzers/dist/regex-call-graph.js +428 -0
- package/packages/analyzers/dist/structure-analyzer.d.ts +11 -0
- package/packages/analyzers/dist/structure-analyzer.js +258 -0
- package/packages/analyzers/dist/symbol-analyzer.d.ts +10 -0
- package/packages/analyzers/dist/symbol-analyzer.js +442 -0
- package/packages/analyzers/dist/ts-call-graph.d.ts +27 -0
- package/packages/analyzers/dist/ts-call-graph.js +160 -0
- package/packages/analyzers/dist/types.d.ts +98 -0
- package/packages/analyzers/dist/types.js +1 -0
- package/packages/chunker/dist/call-graph-extractor.d.ts +22 -0
- package/packages/chunker/dist/call-graph-extractor.js +90 -0
- package/packages/chunker/dist/chunker-factory.d.ts +7 -0
- package/packages/chunker/dist/chunker-factory.js +36 -0
- package/packages/chunker/dist/chunker.interface.d.ts +10 -0
- package/packages/chunker/dist/chunker.interface.js +1 -0
- package/packages/chunker/dist/code-chunker.d.ts +14 -0
- package/packages/chunker/dist/code-chunker.js +134 -0
- package/packages/chunker/dist/generic-chunker.d.ts +12 -0
- package/packages/chunker/dist/generic-chunker.js +72 -0
- package/packages/chunker/dist/index.d.ts +8 -0
- package/packages/chunker/dist/index.js +21 -0
- package/packages/chunker/dist/markdown-chunker.d.ts +14 -0
- package/packages/chunker/dist/markdown-chunker.js +122 -0
- package/packages/chunker/dist/treesitter-chunker.d.ts +47 -0
- package/packages/chunker/dist/treesitter-chunker.js +234 -0
- package/packages/cli/dist/commands/analyze.d.ts +3 -0
- package/packages/cli/dist/commands/analyze.js +112 -0
- package/packages/cli/dist/commands/context-cmds.d.ts +3 -0
- package/packages/cli/dist/commands/context-cmds.js +155 -0
- package/packages/cli/dist/commands/environment.d.ts +3 -0
- package/packages/cli/dist/commands/environment.js +204 -0
- package/packages/cli/dist/commands/execution.d.ts +3 -0
- package/packages/cli/dist/commands/execution.js +137 -0
- package/packages/cli/dist/commands/graph.d.ts +3 -0
- package/packages/cli/dist/commands/graph.js +81 -0
- package/packages/cli/dist/commands/init.d.ts +8 -0
- package/packages/cli/dist/commands/init.js +87 -0
- package/packages/cli/dist/commands/knowledge.d.ts +3 -0
- package/packages/cli/dist/commands/knowledge.js +139 -0
- package/packages/cli/dist/commands/search.d.ts +3 -0
- package/packages/cli/dist/commands/search.js +267 -0
- package/packages/cli/dist/commands/system.d.ts +3 -0
- package/packages/cli/dist/commands/system.js +241 -0
- package/packages/cli/dist/commands/workspace.d.ts +3 -0
- package/packages/cli/dist/commands/workspace.js +388 -0
- package/packages/cli/dist/context.d.ts +5 -0
- package/packages/cli/dist/context.js +14 -0
- package/packages/cli/dist/helpers.d.ts +52 -0
- package/packages/cli/dist/helpers.js +458 -0
- package/packages/cli/dist/index.d.ts +8 -0
- package/packages/cli/dist/index.js +69 -0
- package/packages/cli/dist/kb-init.d.ts +57 -0
- package/packages/cli/dist/kb-init.js +82 -0
- package/packages/cli/dist/types.d.ts +7 -0
- package/packages/cli/dist/types.js +1 -0
- package/packages/core/dist/constants.d.ts +49 -0
- package/packages/core/dist/constants.js +43 -0
- package/packages/core/dist/content-detector.d.ts +9 -0
- package/packages/core/dist/content-detector.js +79 -0
- package/packages/core/dist/errors.d.ts +18 -0
- package/packages/core/dist/errors.js +40 -0
- package/packages/core/dist/index.d.ts +6 -0
- package/packages/core/dist/index.js +9 -0
- package/packages/core/dist/logger.d.ts +9 -0
- package/packages/core/dist/logger.js +34 -0
- package/packages/core/dist/types.d.ts +108 -0
- package/packages/core/dist/types.js +1 -0
- package/packages/embeddings/dist/embedder.interface.d.ts +24 -0
- package/packages/embeddings/dist/embedder.interface.js +1 -0
- package/packages/embeddings/dist/index.d.ts +3 -0
- package/packages/embeddings/dist/index.js +5 -0
- package/packages/embeddings/dist/onnx-embedder.d.ts +24 -0
- package/packages/embeddings/dist/onnx-embedder.js +82 -0
- package/packages/indexer/dist/file-hasher.d.ts +11 -0
- package/packages/indexer/dist/file-hasher.js +13 -0
- package/packages/indexer/dist/filesystem-crawler.d.ts +27 -0
- package/packages/indexer/dist/filesystem-crawler.js +125 -0
- package/packages/indexer/dist/graph-extractor.d.ts +22 -0
- package/packages/indexer/dist/graph-extractor.js +111 -0
- package/packages/indexer/dist/incremental-indexer.d.ts +47 -0
- package/packages/indexer/dist/incremental-indexer.js +278 -0
- package/packages/indexer/dist/index.d.ts +5 -0
- package/packages/indexer/dist/index.js +14 -0
- package/packages/server/dist/api.d.ts +8 -0
- package/packages/server/dist/api.js +9 -0
- package/packages/server/dist/config.d.ts +3 -0
- package/packages/server/dist/config.js +75 -0
- package/packages/server/dist/curated-manager.d.ts +86 -0
- package/packages/server/dist/curated-manager.js +357 -0
- package/packages/server/dist/index.d.ts +2 -0
- package/packages/server/dist/index.js +134 -0
- package/packages/server/dist/replay-interceptor.d.ts +11 -0
- package/packages/server/dist/replay-interceptor.js +38 -0
- package/packages/server/dist/resources/resources.d.ts +4 -0
- package/packages/server/dist/resources/resources.js +40 -0
- package/packages/server/dist/server.d.ts +21 -0
- package/packages/server/dist/server.js +247 -0
- package/packages/server/dist/tools/analyze.tools.d.ts +11 -0
- package/packages/server/dist/tools/analyze.tools.js +288 -0
- package/packages/server/dist/tools/forge.tools.d.ts +12 -0
- package/packages/server/dist/tools/forge.tools.js +501 -0
- package/packages/server/dist/tools/forget.tool.d.ts +4 -0
- package/packages/server/dist/tools/forget.tool.js +43 -0
- package/packages/server/dist/tools/graph.tool.d.ts +4 -0
- package/packages/server/dist/tools/graph.tool.js +110 -0
- package/packages/server/dist/tools/list.tool.d.ts +4 -0
- package/packages/server/dist/tools/list.tool.js +56 -0
- package/packages/server/dist/tools/lookup.tool.d.ts +4 -0
- package/packages/server/dist/tools/lookup.tool.js +53 -0
- package/packages/server/dist/tools/onboard.tool.d.ts +5 -0
- package/packages/server/dist/tools/onboard.tool.js +112 -0
- package/packages/server/dist/tools/produce.tool.d.ts +3 -0
- package/packages/server/dist/tools/produce.tool.js +74 -0
- package/packages/server/dist/tools/read.tool.d.ts +4 -0
- package/packages/server/dist/tools/read.tool.js +49 -0
- package/packages/server/dist/tools/reindex.tool.d.ts +7 -0
- package/packages/server/dist/tools/reindex.tool.js +70 -0
- package/packages/server/dist/tools/remember.tool.d.ts +4 -0
- package/packages/server/dist/tools/remember.tool.js +45 -0
- package/packages/server/dist/tools/replay.tool.d.ts +3 -0
- package/packages/server/dist/tools/replay.tool.js +89 -0
- package/packages/server/dist/tools/search.tool.d.ts +5 -0
- package/packages/server/dist/tools/search.tool.js +331 -0
- package/packages/server/dist/tools/status.tool.d.ts +4 -0
- package/packages/server/dist/tools/status.tool.js +68 -0
- package/packages/server/dist/tools/toolkit.tools.d.ts +35 -0
- package/packages/server/dist/tools/toolkit.tools.js +1674 -0
- package/packages/server/dist/tools/update.tool.d.ts +4 -0
- package/packages/server/dist/tools/update.tool.js +42 -0
- package/packages/server/dist/tools/utility.tools.d.ts +15 -0
- package/packages/server/dist/tools/utility.tools.js +461 -0
- package/packages/store/dist/graph-store.interface.d.ts +104 -0
- package/packages/store/dist/graph-store.interface.js +1 -0
- package/packages/store/dist/index.d.ts +6 -0
- package/packages/store/dist/index.js +9 -0
- package/packages/store/dist/lance-store.d.ts +32 -0
- package/packages/store/dist/lance-store.js +258 -0
- package/packages/store/dist/sqlite-graph-store.d.ts +43 -0
- package/packages/store/dist/sqlite-graph-store.js +374 -0
- package/packages/store/dist/store-factory.d.ts +9 -0
- package/packages/store/dist/store-factory.js +14 -0
- package/packages/store/dist/store.interface.d.ts +48 -0
- package/packages/store/dist/store.interface.js +1 -0
- package/packages/tools/dist/batch.d.ts +21 -0
- package/packages/tools/dist/batch.js +45 -0
- package/packages/tools/dist/changelog.d.ts +34 -0
- package/packages/tools/dist/changelog.js +112 -0
- package/packages/tools/dist/check.d.ts +26 -0
- package/packages/tools/dist/check.js +59 -0
- package/packages/tools/dist/checkpoint.d.ts +17 -0
- package/packages/tools/dist/checkpoint.js +43 -0
- package/packages/tools/dist/codemod.d.ts +37 -0
- package/packages/tools/dist/codemod.js +69 -0
- package/packages/tools/dist/compact.d.ts +41 -0
- package/packages/tools/dist/compact.js +60 -0
- package/packages/tools/dist/data-transform.d.ts +10 -0
- package/packages/tools/dist/data-transform.js +124 -0
- package/packages/tools/dist/dead-symbols.d.ts +21 -0
- package/packages/tools/dist/dead-symbols.js +71 -0
- package/packages/tools/dist/delegate.d.ts +34 -0
- package/packages/tools/dist/delegate.js +130 -0
- package/packages/tools/dist/diff-parse.d.ts +26 -0
- package/packages/tools/dist/diff-parse.js +153 -0
- package/packages/tools/dist/digest.d.ts +53 -0
- package/packages/tools/dist/digest.js +242 -0
- package/packages/tools/dist/encode.d.ts +14 -0
- package/packages/tools/dist/encode.js +46 -0
- package/packages/tools/dist/env-info.d.ts +28 -0
- package/packages/tools/dist/env-info.js +58 -0
- package/packages/tools/dist/eval.d.ts +13 -0
- package/packages/tools/dist/eval.js +79 -0
- package/packages/tools/dist/evidence-map.d.ts +79 -0
- package/packages/tools/dist/evidence-map.js +203 -0
- package/packages/tools/dist/file-summary.d.ts +32 -0
- package/packages/tools/dist/file-summary.js +106 -0
- package/packages/tools/dist/file-walk.d.ts +4 -0
- package/packages/tools/dist/file-walk.js +75 -0
- package/packages/tools/dist/find-examples.d.ts +25 -0
- package/packages/tools/dist/find-examples.js +48 -0
- package/packages/tools/dist/find.d.ts +47 -0
- package/packages/tools/dist/find.js +120 -0
- package/packages/tools/dist/forge-classify.d.ts +44 -0
- package/packages/tools/dist/forge-classify.js +319 -0
- package/packages/tools/dist/forge-ground.d.ts +64 -0
- package/packages/tools/dist/forge-ground.js +184 -0
- package/packages/tools/dist/git-context.d.ts +22 -0
- package/packages/tools/dist/git-context.js +46 -0
- package/packages/tools/dist/graph-query.d.ts +89 -0
- package/packages/tools/dist/graph-query.js +194 -0
- package/packages/tools/dist/health.d.ts +14 -0
- package/packages/tools/dist/health.js +118 -0
- package/packages/tools/dist/http-request.d.ts +23 -0
- package/packages/tools/dist/http-request.js +58 -0
- package/packages/tools/dist/index.d.ts +49 -0
- package/packages/tools/dist/index.js +273 -0
- package/packages/tools/dist/lane.d.ts +39 -0
- package/packages/tools/dist/lane.js +227 -0
- package/packages/tools/dist/measure.d.ts +38 -0
- package/packages/tools/dist/measure.js +119 -0
- package/packages/tools/dist/onboard.d.ts +41 -0
- package/packages/tools/dist/onboard.js +1139 -0
- package/packages/tools/dist/parse-output.d.ts +80 -0
- package/packages/tools/dist/parse-output.js +158 -0
- package/packages/tools/dist/process-manager.d.ts +18 -0
- package/packages/tools/dist/process-manager.js +69 -0
- package/packages/tools/dist/queue.d.ts +38 -0
- package/packages/tools/dist/queue.js +126 -0
- package/packages/tools/dist/regex-test.d.ts +31 -0
- package/packages/tools/dist/regex-test.js +39 -0
- package/packages/tools/dist/rename.d.ts +29 -0
- package/packages/tools/dist/rename.js +70 -0
- package/packages/tools/dist/replay.d.ts +56 -0
- package/packages/tools/dist/replay.js +108 -0
- package/packages/tools/dist/schema-validate.d.ts +23 -0
- package/packages/tools/dist/schema-validate.js +141 -0
- package/packages/tools/dist/scope-map.d.ts +52 -0
- package/packages/tools/dist/scope-map.js +72 -0
- package/packages/tools/dist/snippet.d.ts +34 -0
- package/packages/tools/dist/snippet.js +80 -0
- package/packages/tools/dist/stash.d.ts +12 -0
- package/packages/tools/dist/stash.js +60 -0
- package/packages/tools/dist/stratum-card.d.ts +31 -0
- package/packages/tools/dist/stratum-card.js +239 -0
- package/packages/tools/dist/symbol.d.ts +28 -0
- package/packages/tools/dist/symbol.js +87 -0
- package/packages/tools/dist/test-run.d.ts +23 -0
- package/packages/tools/dist/test-run.js +55 -0
- package/packages/tools/dist/text-utils.d.ts +16 -0
- package/packages/tools/dist/text-utils.js +31 -0
- package/packages/tools/dist/time-utils.d.ts +18 -0
- package/packages/tools/dist/time-utils.js +135 -0
- package/packages/tools/dist/trace.d.ts +24 -0
- package/packages/tools/dist/trace.js +114 -0
- package/packages/tools/dist/truncation.d.ts +22 -0
- package/packages/tools/dist/truncation.js +45 -0
- package/packages/tools/dist/watch.d.ts +30 -0
- package/packages/tools/dist/watch.js +61 -0
- package/packages/tools/dist/web-fetch.d.ts +45 -0
- package/packages/tools/dist/web-fetch.js +249 -0
- package/packages/tools/dist/web-search.d.ts +23 -0
- package/packages/tools/dist/web-search.js +46 -0
- package/packages/tools/dist/workset.d.ts +45 -0
- package/packages/tools/dist/workset.js +77 -0
- package/packages/tui/dist/App.d.ts +8 -0
- package/packages/tui/dist/App.js +52659 -0
- package/packages/tui/dist/index.d.ts +19 -0
- package/packages/tui/dist/index.js +54742 -0
- package/packages/tui/dist/panels/CuratedPanel.d.ts +8 -0
- package/packages/tui/dist/panels/CuratedPanel.js +34452 -0
- package/packages/tui/dist/panels/LogPanel.d.ts +3 -0
- package/packages/tui/dist/panels/LogPanel.js +51894 -0
- package/packages/tui/dist/panels/SearchPanel.d.ts +10 -0
- package/packages/tui/dist/panels/SearchPanel.js +34985 -0
- package/packages/tui/dist/panels/StatusPanel.d.ts +8 -0
- package/packages/tui/dist/panels/StatusPanel.js +34465 -0
- package/skills/knowledge-base/SKILL.md +316 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { resolve } from "node:path";
|
|
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
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
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
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { graphQuery } from "@kb/tools";
|
|
2
|
+
import { ctx } from "../context.js";
|
|
3
|
+
import { extractNumFlag, extractStrFlag } from "../helpers.js";
|
|
4
|
+
const graphCommands = [
|
|
5
|
+
{
|
|
6
|
+
name: "graph",
|
|
7
|
+
description: "Query the knowledge graph",
|
|
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
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `kb init` — scaffold a knowledge base in the current directory.
|
|
3
|
+
* Creates kb.config.json, .gitignore entry, and optional IDE config.
|
|
4
|
+
*/
|
|
5
|
+
export declare function initProject(options: {
|
|
6
|
+
force: boolean;
|
|
7
|
+
}): Promise<void>;
|
|
8
|
+
//# sourceMappingURL=init.d.ts.map
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
const DEFAULT_CONFIG = {
|
|
4
|
+
sources: [
|
|
5
|
+
{
|
|
6
|
+
path: ".",
|
|
7
|
+
excludePatterns: [
|
|
8
|
+
"**/node_modules/**",
|
|
9
|
+
"**/dist/**",
|
|
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
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { compact } from "@kb/tools";
|
|
2
|
+
import { ctx } from "../context.js";
|
|
3
|
+
import { extractNumFlag, extractStrFlag, readStdin, splitCsv } from "../helpers.js";
|
|
4
|
+
const knowledgeCommands = [
|
|
5
|
+
{
|
|
6
|
+
name: "remember",
|
|
7
|
+
description: "Store curated knowledge",
|
|
8
|
+
usage: "kb remember <title> --category <cat> [--tags tag1,tag2]",
|
|
9
|
+
run: async (args) => {
|
|
10
|
+
const category = extractStrFlag(args, "--category", "").trim();
|
|
11
|
+
const tags = splitCsv(extractStrFlag(args, "--tags", ""));
|
|
12
|
+
const title = args.shift()?.trim() ?? "";
|
|
13
|
+
const stdinContent = await readStdin();
|
|
14
|
+
const content = stdinContent.trim().length > 0 ? stdinContent : args.join(" ").trim();
|
|
15
|
+
if (!title || !category || !content.trim()) {
|
|
16
|
+
console.error("Usage: kb remember <title> --category <cat> [--tags tag1,tag2]");
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
const { curated } = await ctx();
|
|
20
|
+
const result = await curated.remember(title, content, category, tags);
|
|
21
|
+
console.log("Stored curated entry");
|
|
22
|
+
console.log(` Path: ${result.path}`);
|
|
23
|
+
console.log(` Category: ${category}`);
|
|
24
|
+
if (tags.length > 0) console.log(` Tags: ${tags.join(", ")}`);
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: "forget",
|
|
29
|
+
description: "Remove a curated entry",
|
|
30
|
+
usage: "kb forget <path> --reason <reason>",
|
|
31
|
+
run: async (args) => {
|
|
32
|
+
const reason = extractStrFlag(args, "--reason", "").trim();
|
|
33
|
+
const relativePath = args.shift()?.trim() ?? "";
|
|
34
|
+
if (!relativePath || !reason) {
|
|
35
|
+
console.error("Usage: kb forget <path> --reason <reason>");
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
const { curated } = await ctx();
|
|
39
|
+
const result = await curated.forget(relativePath, reason);
|
|
40
|
+
console.log(`Removed curated entry: ${result.path}`);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "read",
|
|
45
|
+
description: "Read a curated entry",
|
|
46
|
+
usage: "kb read <path>",
|
|
47
|
+
run: async (args) => {
|
|
48
|
+
const relativePath = args.shift()?.trim() ?? "";
|
|
49
|
+
if (!relativePath) {
|
|
50
|
+
console.error("Usage: kb read <path>");
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
const { curated } = await ctx();
|
|
54
|
+
const entry = await curated.read(relativePath);
|
|
55
|
+
console.log(entry.title);
|
|
56
|
+
console.log("\u2500".repeat(60));
|
|
57
|
+
console.log(`Path: ${entry.path}`);
|
|
58
|
+
console.log(`Category: ${entry.category}`);
|
|
59
|
+
console.log(`Version: ${entry.version}`);
|
|
60
|
+
console.log(`Tags: ${entry.tags.length > 0 ? entry.tags.join(", ") : "None"}`);
|
|
61
|
+
console.log("");
|
|
62
|
+
console.log(entry.content);
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: "list",
|
|
67
|
+
description: "List curated entries",
|
|
68
|
+
usage: "kb list [--category <cat>] [--tag <tag>]",
|
|
69
|
+
run: async (args) => {
|
|
70
|
+
const category = extractStrFlag(args, "--category", "").trim() || void 0;
|
|
71
|
+
const tag = extractStrFlag(args, "--tag", "").trim() || void 0;
|
|
72
|
+
const { curated } = await ctx();
|
|
73
|
+
const entries = await curated.list({ category, tag });
|
|
74
|
+
if (entries.length === 0) {
|
|
75
|
+
console.log("No curated entries found.");
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
console.log(`Curated entries (${entries.length})`);
|
|
79
|
+
console.log("\u2500".repeat(60));
|
|
80
|
+
for (const entry of entries) {
|
|
81
|
+
console.log(entry.path);
|
|
82
|
+
console.log(` ${entry.title}`);
|
|
83
|
+
console.log(` Category: ${entry.category} | Version: ${entry.version}`);
|
|
84
|
+
console.log(` Tags: ${entry.tags.length > 0 ? entry.tags.join(", ") : "None"}`);
|
|
85
|
+
const preview = entry.contentPreview.replace(/\s+/g, " ").trim();
|
|
86
|
+
if (preview) console.log(` Preview: ${preview}`);
|
|
87
|
+
console.log("");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: "update",
|
|
93
|
+
description: "Update a curated entry",
|
|
94
|
+
usage: "kb update <path> --reason <reason>",
|
|
95
|
+
run: async (args) => {
|
|
96
|
+
const reason = extractStrFlag(args, "--reason", "").trim();
|
|
97
|
+
const relativePath = args.shift()?.trim() ?? "";
|
|
98
|
+
const content = await readStdin();
|
|
99
|
+
if (!relativePath || !reason || !content.trim()) {
|
|
100
|
+
console.error("Usage: kb update <path> --reason <reason>");
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
const { curated } = await ctx();
|
|
104
|
+
const result = await curated.update(relativePath, content, reason);
|
|
105
|
+
console.log("Updated curated entry");
|
|
106
|
+
console.log(` Path: ${result.path}`);
|
|
107
|
+
console.log(` Version: ${result.version}`);
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
name: "compact",
|
|
112
|
+
description: "Compress text for context",
|
|
113
|
+
usage: "kb compact <query> [--max-chars N] [--segmentation paragraph|sentence|line]",
|
|
114
|
+
run: async (args) => {
|
|
115
|
+
const maxChars = extractNumFlag(args, "--max-chars", 3e3);
|
|
116
|
+
const segmentation = extractStrFlag(args, "--segmentation", "paragraph");
|
|
117
|
+
const query = args.join(" ").trim();
|
|
118
|
+
const text = await readStdin();
|
|
119
|
+
if (!query || !text.trim()) {
|
|
120
|
+
console.error(
|
|
121
|
+
"Usage: kb compact <query> [--max-chars N] [--segmentation paragraph|sentence|line]"
|
|
122
|
+
);
|
|
123
|
+
process.exit(1);
|
|
124
|
+
}
|
|
125
|
+
const { embedder } = await ctx();
|
|
126
|
+
const result = await compact(embedder, { text, query, maxChars, segmentation });
|
|
127
|
+
console.log(`Compressed ${result.originalChars} chars to ${result.compressedChars} chars`);
|
|
128
|
+
console.log(
|
|
129
|
+
`Ratio: ${(result.ratio * 100).toFixed(1)}% | Segments: ${result.segmentsKept}/${result.segmentsTotal}`
|
|
130
|
+
);
|
|
131
|
+
console.log("");
|
|
132
|
+
console.log(result.text);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
];
|
|
136
|
+
export {
|
|
137
|
+
knowledgeCommands
|
|
138
|
+
};
|
|
139
|
+
//# sourceMappingURL=knowledge.js.map
|