@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.
Files changed (275) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1140 -0
  3. package/bin/kb.mjs +10 -0
  4. package/package.json +67 -0
  5. package/packages/analyzers/dist/blast-radius-analyzer.d.ts +23 -0
  6. package/packages/analyzers/dist/blast-radius-analyzer.js +114 -0
  7. package/packages/analyzers/dist/dependency-analyzer.d.ts +29 -0
  8. package/packages/analyzers/dist/dependency-analyzer.js +425 -0
  9. package/packages/analyzers/dist/diagram-generator.d.ts +13 -0
  10. package/packages/analyzers/dist/diagram-generator.js +86 -0
  11. package/packages/analyzers/dist/entry-point-analyzer.d.ts +19 -0
  12. package/packages/analyzers/dist/entry-point-analyzer.js +239 -0
  13. package/packages/analyzers/dist/index.d.ts +14 -0
  14. package/packages/analyzers/dist/index.js +23 -0
  15. package/packages/analyzers/dist/knowledge-producer.d.ts +32 -0
  16. package/packages/analyzers/dist/knowledge-producer.js +113 -0
  17. package/packages/analyzers/dist/pattern-analyzer.d.ts +12 -0
  18. package/packages/analyzers/dist/pattern-analyzer.js +359 -0
  19. package/packages/analyzers/dist/regex-call-graph.d.ts +17 -0
  20. package/packages/analyzers/dist/regex-call-graph.js +428 -0
  21. package/packages/analyzers/dist/structure-analyzer.d.ts +11 -0
  22. package/packages/analyzers/dist/structure-analyzer.js +258 -0
  23. package/packages/analyzers/dist/symbol-analyzer.d.ts +10 -0
  24. package/packages/analyzers/dist/symbol-analyzer.js +442 -0
  25. package/packages/analyzers/dist/ts-call-graph.d.ts +27 -0
  26. package/packages/analyzers/dist/ts-call-graph.js +160 -0
  27. package/packages/analyzers/dist/types.d.ts +98 -0
  28. package/packages/analyzers/dist/types.js +1 -0
  29. package/packages/chunker/dist/call-graph-extractor.d.ts +22 -0
  30. package/packages/chunker/dist/call-graph-extractor.js +90 -0
  31. package/packages/chunker/dist/chunker-factory.d.ts +7 -0
  32. package/packages/chunker/dist/chunker-factory.js +36 -0
  33. package/packages/chunker/dist/chunker.interface.d.ts +10 -0
  34. package/packages/chunker/dist/chunker.interface.js +1 -0
  35. package/packages/chunker/dist/code-chunker.d.ts +14 -0
  36. package/packages/chunker/dist/code-chunker.js +134 -0
  37. package/packages/chunker/dist/generic-chunker.d.ts +12 -0
  38. package/packages/chunker/dist/generic-chunker.js +72 -0
  39. package/packages/chunker/dist/index.d.ts +8 -0
  40. package/packages/chunker/dist/index.js +21 -0
  41. package/packages/chunker/dist/markdown-chunker.d.ts +14 -0
  42. package/packages/chunker/dist/markdown-chunker.js +122 -0
  43. package/packages/chunker/dist/treesitter-chunker.d.ts +47 -0
  44. package/packages/chunker/dist/treesitter-chunker.js +234 -0
  45. package/packages/cli/dist/commands/analyze.d.ts +3 -0
  46. package/packages/cli/dist/commands/analyze.js +112 -0
  47. package/packages/cli/dist/commands/context-cmds.d.ts +3 -0
  48. package/packages/cli/dist/commands/context-cmds.js +155 -0
  49. package/packages/cli/dist/commands/environment.d.ts +3 -0
  50. package/packages/cli/dist/commands/environment.js +204 -0
  51. package/packages/cli/dist/commands/execution.d.ts +3 -0
  52. package/packages/cli/dist/commands/execution.js +137 -0
  53. package/packages/cli/dist/commands/graph.d.ts +3 -0
  54. package/packages/cli/dist/commands/graph.js +81 -0
  55. package/packages/cli/dist/commands/init.d.ts +8 -0
  56. package/packages/cli/dist/commands/init.js +87 -0
  57. package/packages/cli/dist/commands/knowledge.d.ts +3 -0
  58. package/packages/cli/dist/commands/knowledge.js +139 -0
  59. package/packages/cli/dist/commands/search.d.ts +3 -0
  60. package/packages/cli/dist/commands/search.js +267 -0
  61. package/packages/cli/dist/commands/system.d.ts +3 -0
  62. package/packages/cli/dist/commands/system.js +241 -0
  63. package/packages/cli/dist/commands/workspace.d.ts +3 -0
  64. package/packages/cli/dist/commands/workspace.js +388 -0
  65. package/packages/cli/dist/context.d.ts +5 -0
  66. package/packages/cli/dist/context.js +14 -0
  67. package/packages/cli/dist/helpers.d.ts +52 -0
  68. package/packages/cli/dist/helpers.js +458 -0
  69. package/packages/cli/dist/index.d.ts +8 -0
  70. package/packages/cli/dist/index.js +69 -0
  71. package/packages/cli/dist/kb-init.d.ts +57 -0
  72. package/packages/cli/dist/kb-init.js +82 -0
  73. package/packages/cli/dist/types.d.ts +7 -0
  74. package/packages/cli/dist/types.js +1 -0
  75. package/packages/core/dist/constants.d.ts +49 -0
  76. package/packages/core/dist/constants.js +43 -0
  77. package/packages/core/dist/content-detector.d.ts +9 -0
  78. package/packages/core/dist/content-detector.js +79 -0
  79. package/packages/core/dist/errors.d.ts +18 -0
  80. package/packages/core/dist/errors.js +40 -0
  81. package/packages/core/dist/index.d.ts +6 -0
  82. package/packages/core/dist/index.js +9 -0
  83. package/packages/core/dist/logger.d.ts +9 -0
  84. package/packages/core/dist/logger.js +34 -0
  85. package/packages/core/dist/types.d.ts +108 -0
  86. package/packages/core/dist/types.js +1 -0
  87. package/packages/embeddings/dist/embedder.interface.d.ts +24 -0
  88. package/packages/embeddings/dist/embedder.interface.js +1 -0
  89. package/packages/embeddings/dist/index.d.ts +3 -0
  90. package/packages/embeddings/dist/index.js +5 -0
  91. package/packages/embeddings/dist/onnx-embedder.d.ts +24 -0
  92. package/packages/embeddings/dist/onnx-embedder.js +82 -0
  93. package/packages/indexer/dist/file-hasher.d.ts +11 -0
  94. package/packages/indexer/dist/file-hasher.js +13 -0
  95. package/packages/indexer/dist/filesystem-crawler.d.ts +27 -0
  96. package/packages/indexer/dist/filesystem-crawler.js +125 -0
  97. package/packages/indexer/dist/graph-extractor.d.ts +22 -0
  98. package/packages/indexer/dist/graph-extractor.js +111 -0
  99. package/packages/indexer/dist/incremental-indexer.d.ts +47 -0
  100. package/packages/indexer/dist/incremental-indexer.js +278 -0
  101. package/packages/indexer/dist/index.d.ts +5 -0
  102. package/packages/indexer/dist/index.js +14 -0
  103. package/packages/server/dist/api.d.ts +8 -0
  104. package/packages/server/dist/api.js +9 -0
  105. package/packages/server/dist/config.d.ts +3 -0
  106. package/packages/server/dist/config.js +75 -0
  107. package/packages/server/dist/curated-manager.d.ts +86 -0
  108. package/packages/server/dist/curated-manager.js +357 -0
  109. package/packages/server/dist/index.d.ts +2 -0
  110. package/packages/server/dist/index.js +134 -0
  111. package/packages/server/dist/replay-interceptor.d.ts +11 -0
  112. package/packages/server/dist/replay-interceptor.js +38 -0
  113. package/packages/server/dist/resources/resources.d.ts +4 -0
  114. package/packages/server/dist/resources/resources.js +40 -0
  115. package/packages/server/dist/server.d.ts +21 -0
  116. package/packages/server/dist/server.js +247 -0
  117. package/packages/server/dist/tools/analyze.tools.d.ts +11 -0
  118. package/packages/server/dist/tools/analyze.tools.js +288 -0
  119. package/packages/server/dist/tools/forge.tools.d.ts +12 -0
  120. package/packages/server/dist/tools/forge.tools.js +501 -0
  121. package/packages/server/dist/tools/forget.tool.d.ts +4 -0
  122. package/packages/server/dist/tools/forget.tool.js +43 -0
  123. package/packages/server/dist/tools/graph.tool.d.ts +4 -0
  124. package/packages/server/dist/tools/graph.tool.js +110 -0
  125. package/packages/server/dist/tools/list.tool.d.ts +4 -0
  126. package/packages/server/dist/tools/list.tool.js +56 -0
  127. package/packages/server/dist/tools/lookup.tool.d.ts +4 -0
  128. package/packages/server/dist/tools/lookup.tool.js +53 -0
  129. package/packages/server/dist/tools/onboard.tool.d.ts +5 -0
  130. package/packages/server/dist/tools/onboard.tool.js +112 -0
  131. package/packages/server/dist/tools/produce.tool.d.ts +3 -0
  132. package/packages/server/dist/tools/produce.tool.js +74 -0
  133. package/packages/server/dist/tools/read.tool.d.ts +4 -0
  134. package/packages/server/dist/tools/read.tool.js +49 -0
  135. package/packages/server/dist/tools/reindex.tool.d.ts +7 -0
  136. package/packages/server/dist/tools/reindex.tool.js +70 -0
  137. package/packages/server/dist/tools/remember.tool.d.ts +4 -0
  138. package/packages/server/dist/tools/remember.tool.js +45 -0
  139. package/packages/server/dist/tools/replay.tool.d.ts +3 -0
  140. package/packages/server/dist/tools/replay.tool.js +89 -0
  141. package/packages/server/dist/tools/search.tool.d.ts +5 -0
  142. package/packages/server/dist/tools/search.tool.js +331 -0
  143. package/packages/server/dist/tools/status.tool.d.ts +4 -0
  144. package/packages/server/dist/tools/status.tool.js +68 -0
  145. package/packages/server/dist/tools/toolkit.tools.d.ts +35 -0
  146. package/packages/server/dist/tools/toolkit.tools.js +1674 -0
  147. package/packages/server/dist/tools/update.tool.d.ts +4 -0
  148. package/packages/server/dist/tools/update.tool.js +42 -0
  149. package/packages/server/dist/tools/utility.tools.d.ts +15 -0
  150. package/packages/server/dist/tools/utility.tools.js +461 -0
  151. package/packages/store/dist/graph-store.interface.d.ts +104 -0
  152. package/packages/store/dist/graph-store.interface.js +1 -0
  153. package/packages/store/dist/index.d.ts +6 -0
  154. package/packages/store/dist/index.js +9 -0
  155. package/packages/store/dist/lance-store.d.ts +32 -0
  156. package/packages/store/dist/lance-store.js +258 -0
  157. package/packages/store/dist/sqlite-graph-store.d.ts +43 -0
  158. package/packages/store/dist/sqlite-graph-store.js +374 -0
  159. package/packages/store/dist/store-factory.d.ts +9 -0
  160. package/packages/store/dist/store-factory.js +14 -0
  161. package/packages/store/dist/store.interface.d.ts +48 -0
  162. package/packages/store/dist/store.interface.js +1 -0
  163. package/packages/tools/dist/batch.d.ts +21 -0
  164. package/packages/tools/dist/batch.js +45 -0
  165. package/packages/tools/dist/changelog.d.ts +34 -0
  166. package/packages/tools/dist/changelog.js +112 -0
  167. package/packages/tools/dist/check.d.ts +26 -0
  168. package/packages/tools/dist/check.js +59 -0
  169. package/packages/tools/dist/checkpoint.d.ts +17 -0
  170. package/packages/tools/dist/checkpoint.js +43 -0
  171. package/packages/tools/dist/codemod.d.ts +37 -0
  172. package/packages/tools/dist/codemod.js +69 -0
  173. package/packages/tools/dist/compact.d.ts +41 -0
  174. package/packages/tools/dist/compact.js +60 -0
  175. package/packages/tools/dist/data-transform.d.ts +10 -0
  176. package/packages/tools/dist/data-transform.js +124 -0
  177. package/packages/tools/dist/dead-symbols.d.ts +21 -0
  178. package/packages/tools/dist/dead-symbols.js +71 -0
  179. package/packages/tools/dist/delegate.d.ts +34 -0
  180. package/packages/tools/dist/delegate.js +130 -0
  181. package/packages/tools/dist/diff-parse.d.ts +26 -0
  182. package/packages/tools/dist/diff-parse.js +153 -0
  183. package/packages/tools/dist/digest.d.ts +53 -0
  184. package/packages/tools/dist/digest.js +242 -0
  185. package/packages/tools/dist/encode.d.ts +14 -0
  186. package/packages/tools/dist/encode.js +46 -0
  187. package/packages/tools/dist/env-info.d.ts +28 -0
  188. package/packages/tools/dist/env-info.js +58 -0
  189. package/packages/tools/dist/eval.d.ts +13 -0
  190. package/packages/tools/dist/eval.js +79 -0
  191. package/packages/tools/dist/evidence-map.d.ts +79 -0
  192. package/packages/tools/dist/evidence-map.js +203 -0
  193. package/packages/tools/dist/file-summary.d.ts +32 -0
  194. package/packages/tools/dist/file-summary.js +106 -0
  195. package/packages/tools/dist/file-walk.d.ts +4 -0
  196. package/packages/tools/dist/file-walk.js +75 -0
  197. package/packages/tools/dist/find-examples.d.ts +25 -0
  198. package/packages/tools/dist/find-examples.js +48 -0
  199. package/packages/tools/dist/find.d.ts +47 -0
  200. package/packages/tools/dist/find.js +120 -0
  201. package/packages/tools/dist/forge-classify.d.ts +44 -0
  202. package/packages/tools/dist/forge-classify.js +319 -0
  203. package/packages/tools/dist/forge-ground.d.ts +64 -0
  204. package/packages/tools/dist/forge-ground.js +184 -0
  205. package/packages/tools/dist/git-context.d.ts +22 -0
  206. package/packages/tools/dist/git-context.js +46 -0
  207. package/packages/tools/dist/graph-query.d.ts +89 -0
  208. package/packages/tools/dist/graph-query.js +194 -0
  209. package/packages/tools/dist/health.d.ts +14 -0
  210. package/packages/tools/dist/health.js +118 -0
  211. package/packages/tools/dist/http-request.d.ts +23 -0
  212. package/packages/tools/dist/http-request.js +58 -0
  213. package/packages/tools/dist/index.d.ts +49 -0
  214. package/packages/tools/dist/index.js +273 -0
  215. package/packages/tools/dist/lane.d.ts +39 -0
  216. package/packages/tools/dist/lane.js +227 -0
  217. package/packages/tools/dist/measure.d.ts +38 -0
  218. package/packages/tools/dist/measure.js +119 -0
  219. package/packages/tools/dist/onboard.d.ts +41 -0
  220. package/packages/tools/dist/onboard.js +1139 -0
  221. package/packages/tools/dist/parse-output.d.ts +80 -0
  222. package/packages/tools/dist/parse-output.js +158 -0
  223. package/packages/tools/dist/process-manager.d.ts +18 -0
  224. package/packages/tools/dist/process-manager.js +69 -0
  225. package/packages/tools/dist/queue.d.ts +38 -0
  226. package/packages/tools/dist/queue.js +126 -0
  227. package/packages/tools/dist/regex-test.d.ts +31 -0
  228. package/packages/tools/dist/regex-test.js +39 -0
  229. package/packages/tools/dist/rename.d.ts +29 -0
  230. package/packages/tools/dist/rename.js +70 -0
  231. package/packages/tools/dist/replay.d.ts +56 -0
  232. package/packages/tools/dist/replay.js +108 -0
  233. package/packages/tools/dist/schema-validate.d.ts +23 -0
  234. package/packages/tools/dist/schema-validate.js +141 -0
  235. package/packages/tools/dist/scope-map.d.ts +52 -0
  236. package/packages/tools/dist/scope-map.js +72 -0
  237. package/packages/tools/dist/snippet.d.ts +34 -0
  238. package/packages/tools/dist/snippet.js +80 -0
  239. package/packages/tools/dist/stash.d.ts +12 -0
  240. package/packages/tools/dist/stash.js +60 -0
  241. package/packages/tools/dist/stratum-card.d.ts +31 -0
  242. package/packages/tools/dist/stratum-card.js +239 -0
  243. package/packages/tools/dist/symbol.d.ts +28 -0
  244. package/packages/tools/dist/symbol.js +87 -0
  245. package/packages/tools/dist/test-run.d.ts +23 -0
  246. package/packages/tools/dist/test-run.js +55 -0
  247. package/packages/tools/dist/text-utils.d.ts +16 -0
  248. package/packages/tools/dist/text-utils.js +31 -0
  249. package/packages/tools/dist/time-utils.d.ts +18 -0
  250. package/packages/tools/dist/time-utils.js +135 -0
  251. package/packages/tools/dist/trace.d.ts +24 -0
  252. package/packages/tools/dist/trace.js +114 -0
  253. package/packages/tools/dist/truncation.d.ts +22 -0
  254. package/packages/tools/dist/truncation.js +45 -0
  255. package/packages/tools/dist/watch.d.ts +30 -0
  256. package/packages/tools/dist/watch.js +61 -0
  257. package/packages/tools/dist/web-fetch.d.ts +45 -0
  258. package/packages/tools/dist/web-fetch.js +249 -0
  259. package/packages/tools/dist/web-search.d.ts +23 -0
  260. package/packages/tools/dist/web-search.js +46 -0
  261. package/packages/tools/dist/workset.d.ts +45 -0
  262. package/packages/tools/dist/workset.js +77 -0
  263. package/packages/tui/dist/App.d.ts +8 -0
  264. package/packages/tui/dist/App.js +52659 -0
  265. package/packages/tui/dist/index.d.ts +19 -0
  266. package/packages/tui/dist/index.js +54742 -0
  267. package/packages/tui/dist/panels/CuratedPanel.d.ts +8 -0
  268. package/packages/tui/dist/panels/CuratedPanel.js +34452 -0
  269. package/packages/tui/dist/panels/LogPanel.d.ts +3 -0
  270. package/packages/tui/dist/panels/LogPanel.js +51894 -0
  271. package/packages/tui/dist/panels/SearchPanel.d.ts +10 -0
  272. package/packages/tui/dist/panels/SearchPanel.js +34985 -0
  273. package/packages/tui/dist/panels/StatusPanel.d.ts +8 -0
  274. package/packages/tui/dist/panels/StatusPanel.js +34465 -0
  275. package/skills/knowledge-base/SKILL.md +316 -0
@@ -0,0 +1,124 @@
1
+ function dataTransform(options) {
2
+ const { input, expression } = options;
3
+ const data = typeof input === "string" ? JSON.parse(input) : input;
4
+ let output;
5
+ if (expression === ".") {
6
+ output = data;
7
+ } else if (expression === "keys") {
8
+ output = Object.keys(asRecord(data));
9
+ } else if (expression === "values") {
10
+ output = Object.values(asRecord(data));
11
+ } else if (expression === "length") {
12
+ output = Array.isArray(data) ? data.length : Object.keys(asRecord(data)).length;
13
+ } else if (expression === "flatten") {
14
+ output = asArray(data).flat();
15
+ } else if (expression === "unique") {
16
+ output = [...new Set(asArray(data))];
17
+ } else if (expression === "sort") {
18
+ output = [...asArray(data)].sort();
19
+ } else if (expression === "reverse") {
20
+ output = [...asArray(data)].reverse();
21
+ } else if (expression.startsWith(".")) {
22
+ output = resolvePath(data, expression.slice(1));
23
+ } else if (expression.startsWith("map(") && expression.endsWith(")")) {
24
+ const field = expression.slice(4, -1).trim();
25
+ const path = field.startsWith(".") ? field.slice(1) : field;
26
+ output = asArray(data).map((item) => resolvePath(item, path));
27
+ } else if (expression.startsWith("select(") && expression.endsWith(")")) {
28
+ output = filterByCondition(asArray(data), expression.slice(7, -1).trim());
29
+ } else if (expression.startsWith("group_by(") && expression.endsWith(")")) {
30
+ const field = expression.slice(9, -1).trim().replace(/^\./, "");
31
+ const groups = {};
32
+ for (const item of asArray(data)) {
33
+ const key = String(resolvePath(item, field) ?? "null");
34
+ if (!groups[key]) {
35
+ groups[key] = [];
36
+ }
37
+ groups[key].push(item);
38
+ }
39
+ output = groups;
40
+ } else if (expression.startsWith("pick(") && expression.endsWith(")")) {
41
+ const fields = expression.slice(5, -1).split(",").map((field) => field.trim().replace(/^\./, "")).filter(Boolean);
42
+ output = Array.isArray(data) ? asArray(data).map((item) => pickFields(item, fields)) : pickFields(data, fields);
43
+ } else {
44
+ throw new Error(
45
+ `Unsupported expression: ${expression}. Supported: ., .path.to.field, keys, values, length, flatten, unique, sort, reverse, map(.field), select(.field == | != | > | < | >= | <= "value"), group_by(.field), pick(.a, .b)`
46
+ );
47
+ }
48
+ return {
49
+ output,
50
+ outputString: typeof output === "string" ? output : JSON.stringify(output, null, 2) ?? "null"
51
+ };
52
+ }
53
+ function filterByCondition(items, condition) {
54
+ const match = condition.match(/^\.?([\w.[\]]+)\s*(==|!=|>=|<=|>|<)\s*"?([^"]*)"?$/);
55
+ if (!match) {
56
+ throw new Error(`Unsupported select expression: ${condition}`);
57
+ }
58
+ const [, field, operator, value] = match;
59
+ return items.filter((item) => {
60
+ const resolved = resolvePath(item, field);
61
+ const resolvedStr = String(resolved);
62
+ switch (operator) {
63
+ case "==":
64
+ return resolvedStr === value;
65
+ case "!=":
66
+ return resolvedStr !== value;
67
+ case ">":
68
+ case "<":
69
+ case ">=":
70
+ case "<=": {
71
+ const numResolved = Number(resolved);
72
+ const numValue = Number(value);
73
+ if (Number.isNaN(numResolved) || Number.isNaN(numValue)) return false;
74
+ if (operator === ">") return numResolved > numValue;
75
+ if (operator === "<") return numResolved < numValue;
76
+ if (operator === ">=") return numResolved >= numValue;
77
+ return numResolved <= numValue;
78
+ }
79
+ default:
80
+ return false;
81
+ }
82
+ });
83
+ }
84
+ function pickFields(input, fields) {
85
+ const picked = {};
86
+ for (const field of fields) {
87
+ picked[field] = resolvePath(input, field);
88
+ }
89
+ return picked;
90
+ }
91
+ function resolvePath(input, path) {
92
+ if (!path) return input;
93
+ const tokens = [...path.matchAll(/([^.[\]]+)|\[(\d+)\]/g)].map(
94
+ (match) => match[1] ?? Number.parseInt(match[2], 10)
95
+ );
96
+ let current = input;
97
+ for (const token of tokens) {
98
+ if (current == null) return void 0;
99
+ if (typeof token === "number") {
100
+ if (!Array.isArray(current)) return void 0;
101
+ current = current[token];
102
+ continue;
103
+ }
104
+ if (typeof current !== "object") return void 0;
105
+ current = current[token];
106
+ }
107
+ return current;
108
+ }
109
+ function asArray(value) {
110
+ if (!Array.isArray(value)) {
111
+ throw new Error("Operation requires an array input.");
112
+ }
113
+ return value;
114
+ }
115
+ function asRecord(value) {
116
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
117
+ throw new Error("Operation requires an object input.");
118
+ }
119
+ return value;
120
+ }
121
+ export {
122
+ dataTransform
123
+ };
124
+ //# sourceMappingURL=data-transform.js.map
@@ -0,0 +1,21 @@
1
+ import type { IEmbedder } from '@kb/embeddings';
2
+ import type { IKnowledgeStore } from '@kb/store';
3
+ export interface DeadSymbolOptions {
4
+ /** Root path to scope the search */
5
+ rootPath?: string;
6
+ /** Max symbols to scan (default: 100) */
7
+ limit?: number;
8
+ }
9
+ export interface DeadSymbol {
10
+ name: string;
11
+ path: string;
12
+ line: number;
13
+ kind: string;
14
+ }
15
+ export interface DeadSymbolResult {
16
+ deadSymbols: DeadSymbol[];
17
+ totalExports: number;
18
+ totalDead: number;
19
+ }
20
+ export declare function findDeadSymbols(embedder: IEmbedder, store: IKnowledgeStore, options?: DeadSymbolOptions): Promise<DeadSymbolResult>;
21
+ //# sourceMappingURL=dead-symbols.d.ts.map
@@ -0,0 +1,71 @@
1
+ async function findDeadSymbols(embedder, store, options = {}) {
2
+ const { rootPath, limit = 100 } = options;
3
+ const exportVector = await embedder.embed("export function class const type interface enum");
4
+ const exportChunks = await store.search(exportVector, { limit: limit * 3 });
5
+ const exportPattern = /^export\s+(?:async\s+)?(?:function|class|const|let|interface|type|enum)\s+(\w+)/gm;
6
+ const exports = [];
7
+ for (const chunk of exportChunks) {
8
+ if (!matchesRootPath(chunk.record.sourcePath, rootPath)) continue;
9
+ const content = chunk.record.content;
10
+ exportPattern.lastIndex = 0;
11
+ for (const match of content.matchAll(exportPattern)) {
12
+ const matchIndex = match.index ?? 0;
13
+ const linesBefore = content.slice(0, matchIndex).split("\n").length - 1;
14
+ const kindMatch = content.slice(matchIndex).match(/export\s+(?:async\s+)?(\w+)/);
15
+ exports.push({
16
+ name: match[1],
17
+ path: chunk.record.sourcePath,
18
+ line: chunk.record.startLine + linesBefore,
19
+ kind: kindMatch?.[1] ?? "unknown"
20
+ });
21
+ }
22
+ }
23
+ const uniqueExports = /* @__PURE__ */ new Map();
24
+ for (const exportedSymbol of exports) {
25
+ const key = `${exportedSymbol.path}:${exportedSymbol.name}`;
26
+ if (!uniqueExports.has(key)) uniqueExports.set(key, exportedSymbol);
27
+ }
28
+ const deadSymbols = [];
29
+ for (const exportedSymbol of uniqueExports.values()) {
30
+ const escapedName = escapeRegExp(exportedSymbol.name);
31
+ const importPattern = new RegExp(`import\\s+.*\\b${escapedName}\\b.*from`, "m");
32
+ const reexportPattern = new RegExp(`export\\s+\\{[^}]*\\b${escapedName}\\b`, "m");
33
+ const importResults = await store.ftsSearch(`import ${exportedSymbol.name}`, { limit: 10 });
34
+ const isImported = importResults.some(
35
+ (result) => result.record.sourcePath !== exportedSymbol.path && importPattern.test(result.record.content)
36
+ );
37
+ const isReexported = importResults.some(
38
+ (result) => result.record.sourcePath !== exportedSymbol.path && reexportPattern.test(result.record.content)
39
+ );
40
+ if (!isImported && !isReexported) {
41
+ deadSymbols.push(exportedSymbol);
42
+ }
43
+ }
44
+ deadSymbols.sort(
45
+ (left, right) => left.path === right.path ? left.line - right.line : left.path.localeCompare(right.path)
46
+ );
47
+ return {
48
+ deadSymbols,
49
+ totalExports: uniqueExports.size,
50
+ totalDead: deadSymbols.length
51
+ };
52
+ }
53
+ function escapeRegExp(value) {
54
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
55
+ }
56
+ function matchesRootPath(sourcePath, rootPath) {
57
+ if (!rootPath) return true;
58
+ const normalizedRoot = normalizePath(rootPath).replace(/\/+$/, "");
59
+ if (/^[A-Za-z]:\//.test(normalizedRoot) || normalizedRoot.startsWith("/")) {
60
+ return true;
61
+ }
62
+ const normalizedSource = normalizePath(sourcePath);
63
+ return normalizedSource === normalizedRoot || normalizedSource.startsWith(`${normalizedRoot}/`);
64
+ }
65
+ function normalizePath(value) {
66
+ return value.replace(/\\/g, "/").replace(/^\.\//, "");
67
+ }
68
+ export {
69
+ findDeadSymbols
70
+ };
71
+ //# sourceMappingURL=dead-symbols.js.map
@@ -0,0 +1,34 @@
1
+ export interface DelegateOptions {
2
+ /** The prompt / task to send to the local model. */
3
+ prompt: string;
4
+ /** Model to use (default: the first available model). */
5
+ model?: string;
6
+ /** Optional system prompt. */
7
+ system?: string;
8
+ /** Optional context to include before the prompt. */
9
+ context?: string;
10
+ /** Temperature (0-2, default: 0.3 for deterministic-ish output). */
11
+ temperature?: number;
12
+ /** Timeout in milliseconds (default: 120_000). */
13
+ timeout?: number;
14
+ /** Ollama base URL (default: http://localhost:11434). */
15
+ baseUrl?: string;
16
+ }
17
+ export interface DelegateResult {
18
+ model: string;
19
+ response: string;
20
+ durationMs: number;
21
+ tokenCount?: number;
22
+ error?: string;
23
+ }
24
+ /**
25
+ * Check if Ollama is running and return available models.
26
+ */
27
+ export declare function delegateListModels(baseUrl?: string): Promise<string[]>;
28
+ /**
29
+ * Delegate a task to a local Ollama model.
30
+ *
31
+ * Fails fast if Ollama is not running or no models are available.
32
+ */
33
+ export declare function delegate(options: DelegateOptions): Promise<DelegateResult>;
34
+ //# sourceMappingURL=delegate.d.ts.map
@@ -0,0 +1,130 @@
1
+ import { request } from "node:http";
2
+ const DEFAULT_BASE_URL = "http://localhost:11434";
3
+ const DEFAULT_TIMEOUT = 12e4;
4
+ async function delegateListModels(baseUrl = DEFAULT_BASE_URL) {
5
+ const body = await ollamaGet(`${baseUrl}/api/tags`);
6
+ const parsed = JSON.parse(body);
7
+ return (parsed.models ?? []).map((m) => m.name);
8
+ }
9
+ async function delegate(options) {
10
+ const baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;
11
+ const timeout = options.timeout ?? DEFAULT_TIMEOUT;
12
+ let models;
13
+ try {
14
+ models = await delegateListModels(baseUrl);
15
+ } catch {
16
+ return {
17
+ model: options.model ?? "unknown",
18
+ response: "",
19
+ durationMs: 0,
20
+ error: `Ollama is not running at ${baseUrl}. Start it with: ollama serve`
21
+ };
22
+ }
23
+ if (models.length === 0) {
24
+ return {
25
+ model: "none",
26
+ response: "",
27
+ durationMs: 0,
28
+ error: "No Ollama models available. Pull one with: ollama pull qwen2.5-coder:7b"
29
+ };
30
+ }
31
+ const model = options.model ?? models[0];
32
+ if (!models.includes(model)) {
33
+ return {
34
+ model,
35
+ response: "",
36
+ durationMs: 0,
37
+ error: `Model "${model}" not found. Available: ${models.join(", ")}`
38
+ };
39
+ }
40
+ let fullPrompt = "";
41
+ if (options.context) {
42
+ fullPrompt += `<context>
43
+ ${options.context}
44
+ </context>
45
+
46
+ `;
47
+ }
48
+ fullPrompt += options.prompt;
49
+ const start = Date.now();
50
+ const payload = JSON.stringify({
51
+ model,
52
+ prompt: fullPrompt,
53
+ system: options.system,
54
+ stream: false,
55
+ options: {
56
+ temperature: options.temperature ?? 0.3
57
+ }
58
+ });
59
+ try {
60
+ const body = await ollamaPost(`${baseUrl}/api/generate`, payload, timeout);
61
+ const parsed = JSON.parse(body);
62
+ if (parsed.error) {
63
+ return { model, response: "", durationMs: Date.now() - start, error: parsed.error };
64
+ }
65
+ return {
66
+ model,
67
+ response: (parsed.response ?? "").trim(),
68
+ durationMs: Date.now() - start,
69
+ tokenCount: parsed.eval_count
70
+ };
71
+ } catch (err) {
72
+ return {
73
+ model,
74
+ response: "",
75
+ durationMs: Date.now() - start,
76
+ error: err instanceof Error ? err.message : String(err)
77
+ };
78
+ }
79
+ }
80
+ function ollamaGet(url) {
81
+ return new Promise((resolve, reject) => {
82
+ const u = new URL(url);
83
+ const req = request(
84
+ { hostname: u.hostname, port: u.port, path: u.pathname, method: "GET", timeout: 5e3 },
85
+ (res) => {
86
+ const chunks = [];
87
+ res.on("data", (c) => chunks.push(c));
88
+ res.on("end", () => resolve(Buffer.concat(chunks).toString("utf-8")));
89
+ }
90
+ );
91
+ req.on("error", reject);
92
+ req.on("timeout", () => {
93
+ req.destroy();
94
+ reject(new Error("Connection timeout"));
95
+ });
96
+ req.end();
97
+ });
98
+ }
99
+ function ollamaPost(url, body, timeout) {
100
+ return new Promise((resolve, reject) => {
101
+ const u = new URL(url);
102
+ const req = request(
103
+ {
104
+ hostname: u.hostname,
105
+ port: u.port,
106
+ path: u.pathname,
107
+ method: "POST",
108
+ headers: { "Content-Type": "application/json", "Content-Length": Buffer.byteLength(body) },
109
+ timeout
110
+ },
111
+ (res) => {
112
+ const chunks = [];
113
+ res.on("data", (c) => chunks.push(c));
114
+ res.on("end", () => resolve(Buffer.concat(chunks).toString("utf-8")));
115
+ }
116
+ );
117
+ req.on("error", reject);
118
+ req.on("timeout", () => {
119
+ req.destroy();
120
+ reject(new Error(`Ollama request timed out after ${timeout}ms`));
121
+ });
122
+ req.write(body);
123
+ req.end();
124
+ });
125
+ }
126
+ export {
127
+ delegate,
128
+ delegateListModels
129
+ };
130
+ //# sourceMappingURL=delegate.js.map
@@ -0,0 +1,26 @@
1
+ export interface DiffFile {
2
+ path: string;
3
+ oldPath?: string;
4
+ status: 'added' | 'modified' | 'deleted' | 'renamed';
5
+ hunks: DiffHunk[];
6
+ additions: number;
7
+ deletions: number;
8
+ }
9
+ export interface DiffHunk {
10
+ oldStart: number;
11
+ oldLines: number;
12
+ newStart: number;
13
+ newLines: number;
14
+ header: string;
15
+ changes: DiffChange[];
16
+ }
17
+ export interface DiffChange {
18
+ type: 'add' | 'delete' | 'context';
19
+ line: number;
20
+ content: string;
21
+ }
22
+ export interface DiffParseOptions {
23
+ diff: string;
24
+ }
25
+ export declare function diffParse(options: DiffParseOptions): DiffFile[];
26
+ //# sourceMappingURL=diff-parse.d.ts.map
@@ -0,0 +1,153 @@
1
+ function diffParse(options) {
2
+ const { diff } = options;
3
+ const fileBlocks = diff.split(/^diff --git /m).filter(Boolean);
4
+ if (fileBlocks.length > 0 && /^a\//.test(fileBlocks[0])) {
5
+ return parseGitDiff(fileBlocks);
6
+ }
7
+ return parseUnifiedDiff(diff);
8
+ }
9
+ function parseGitDiff(fileBlocks) {
10
+ const files = [];
11
+ for (const block of fileBlocks) {
12
+ const lines = block.split("\n");
13
+ const headerMatch = lines[0]?.match(/a\/(.+?)\s+b\/(.+)/);
14
+ if (!headerMatch) continue;
15
+ const oldPath = headerMatch[1];
16
+ const newPath = headerMatch[2];
17
+ let status = "modified";
18
+ if (block.includes("new file mode")) status = "added";
19
+ else if (block.includes("deleted file mode")) status = "deleted";
20
+ else if (oldPath !== newPath) status = "renamed";
21
+ const hunks = [];
22
+ let additions = 0;
23
+ let deletions = 0;
24
+ let currentHunk = null;
25
+ let oldLine = 0;
26
+ let newLine = 0;
27
+ for (const line of lines) {
28
+ const hunkMatch = line.match(/^@@\s+-(\d+)(?:,(\d+))?\s+\+(\d+)(?:,(\d+))?\s+@@(.*)$/);
29
+ if (hunkMatch) {
30
+ currentHunk = {
31
+ oldStart: Number(hunkMatch[1]),
32
+ oldLines: Number(hunkMatch[2] ?? 1),
33
+ newStart: Number(hunkMatch[3]),
34
+ newLines: Number(hunkMatch[4] ?? 1),
35
+ header: hunkMatch[5]?.trim() ?? "",
36
+ changes: []
37
+ };
38
+ hunks.push(currentHunk);
39
+ oldLine = currentHunk.oldStart;
40
+ newLine = currentHunk.newStart;
41
+ continue;
42
+ }
43
+ if (!currentHunk || line.startsWith("\\")) continue;
44
+ if (line.startsWith("+") && !line.startsWith("+++")) {
45
+ currentHunk.changes.push({ type: "add", line: newLine, content: line.slice(1) });
46
+ additions += 1;
47
+ newLine += 1;
48
+ continue;
49
+ }
50
+ if (line.startsWith("-") && !line.startsWith("---")) {
51
+ currentHunk.changes.push({ type: "delete", line: oldLine, content: line.slice(1) });
52
+ deletions += 1;
53
+ oldLine += 1;
54
+ continue;
55
+ }
56
+ if (line.startsWith(" ")) {
57
+ currentHunk.changes.push({ type: "context", line: newLine, content: line.slice(1) });
58
+ oldLine += 1;
59
+ newLine += 1;
60
+ }
61
+ }
62
+ files.push({
63
+ path: newPath,
64
+ oldPath: status === "renamed" ? oldPath : void 0,
65
+ status,
66
+ hunks,
67
+ additions,
68
+ deletions
69
+ });
70
+ }
71
+ return files;
72
+ }
73
+ function parseUnifiedDiff(diff) {
74
+ const files = [];
75
+ const lines = diff.split("\n");
76
+ let i = 0;
77
+ while (i < lines.length) {
78
+ const oldMatch = lines[i]?.match(/^---\s+(?:a\/)?(.+)/);
79
+ const newMatch = lines[i + 1]?.match(/^\+\+\+\s+(?:b\/)?(.+)/);
80
+ if (!oldMatch || !newMatch) {
81
+ i++;
82
+ continue;
83
+ }
84
+ const oldPath = oldMatch[1].trim();
85
+ const newPath = newMatch[1].trim();
86
+ let status = "modified";
87
+ if (oldPath === "/dev/null") status = "added";
88
+ else if (newPath === "/dev/null") status = "deleted";
89
+ else if (oldPath !== newPath) status = "renamed";
90
+ i += 2;
91
+ const hunks = [];
92
+ let additions = 0;
93
+ let deletions = 0;
94
+ while (i < lines.length && !lines[i]?.startsWith("--- ")) {
95
+ const hunkMatch = lines[i]?.match(/^@@\s+-(\d+)(?:,(\d+))?\s+\+(\d+)(?:,(\d+))?\s+@@(.*)$/);
96
+ if (hunkMatch) {
97
+ const currentHunk = {
98
+ oldStart: Number(hunkMatch[1]),
99
+ oldLines: Number(hunkMatch[2] ?? 1),
100
+ newStart: Number(hunkMatch[3]),
101
+ newLines: Number(hunkMatch[4] ?? 1),
102
+ header: hunkMatch[5]?.trim() ?? "",
103
+ changes: []
104
+ };
105
+ hunks.push(currentHunk);
106
+ let oldLine = currentHunk.oldStart;
107
+ let newLine = currentHunk.newStart;
108
+ i++;
109
+ while (i < lines.length) {
110
+ const line = lines[i];
111
+ if (line?.startsWith("@@") || line?.startsWith("--- ") || line?.startsWith("diff "))
112
+ break;
113
+ if (line?.startsWith("\\")) {
114
+ i++;
115
+ continue;
116
+ }
117
+ if (line?.startsWith("+")) {
118
+ currentHunk.changes.push({ type: "add", line: newLine, content: line.slice(1) });
119
+ additions++;
120
+ newLine++;
121
+ } else if (line?.startsWith("-")) {
122
+ currentHunk.changes.push({ type: "delete", line: oldLine, content: line.slice(1) });
123
+ deletions++;
124
+ oldLine++;
125
+ } else if (line?.startsWith(" ")) {
126
+ currentHunk.changes.push({ type: "context", line: newLine, content: line.slice(1) });
127
+ oldLine++;
128
+ newLine++;
129
+ } else {
130
+ break;
131
+ }
132
+ i++;
133
+ }
134
+ } else {
135
+ i++;
136
+ }
137
+ }
138
+ const effectivePath = status === "deleted" ? oldPath : newPath;
139
+ files.push({
140
+ path: effectivePath,
141
+ oldPath: status === "renamed" ? oldPath : void 0,
142
+ status,
143
+ hunks,
144
+ additions,
145
+ deletions
146
+ });
147
+ }
148
+ return files;
149
+ }
150
+ export {
151
+ diffParse
152
+ };
153
+ //# sourceMappingURL=diff-parse.js.map
@@ -0,0 +1,53 @@
1
+ /**
2
+ * kb_digest — Multi-source context compressor.
3
+ *
4
+ * Compress N text blocks into a token-budgeted digest with source attribution
5
+ * and pinned structured fields. Uses embedding similarity — no LLM needed.
6
+ */
7
+ import type { IEmbedder } from '@kb/embeddings';
8
+ export interface DigestSource {
9
+ /** Unique identifier for this source */
10
+ id: string;
11
+ /** The text to compress */
12
+ text: string;
13
+ /** Priority weight (default: 1). Higher = more budget share */
14
+ weight?: number;
15
+ }
16
+ export interface DigestOptions {
17
+ /** Source texts to compress */
18
+ sources: DigestSource[];
19
+ /** Focus query — what matters for the next step? */
20
+ query: string;
21
+ /** Target budget in characters (default: 4000) */
22
+ maxChars?: number;
23
+ /** Key fields to always extract via keyword matching */
24
+ pinFields?: string[];
25
+ /** Segmentation strategy (default: 'paragraph') */
26
+ segmentation?: 'paragraph' | 'sentence' | 'line';
27
+ }
28
+ export interface DigestFieldEntry {
29
+ sourceId: string;
30
+ value: string;
31
+ }
32
+ export interface DigestResult {
33
+ /** Compressed narrative (all sources merged, reading order maintained) */
34
+ text: string;
35
+ /** Extracted structured fields */
36
+ fields: Record<string, DigestFieldEntry[]>;
37
+ /** Per-source compression stats */
38
+ sourceStats: Array<{
39
+ id: string;
40
+ originalChars: number;
41
+ keptChars: number;
42
+ segmentsKept: number;
43
+ segmentsTotal: number;
44
+ }>;
45
+ totalOriginalChars: number;
46
+ totalCompressedChars: number;
47
+ ratio: number;
48
+ }
49
+ /**
50
+ * Compress multiple text sources into a single digest.
51
+ */
52
+ export declare function digest(embedder: IEmbedder, options: DigestOptions): Promise<DigestResult>;
53
+ //# sourceMappingURL=digest.d.ts.map