@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,86 @@
1
+ import { DependencyAnalyzer } from "./dependency-analyzer.js";
2
+ import { StructureAnalyzer } from "./structure-analyzer.js";
3
+ class DiagramGenerator {
4
+ name = "diagrams";
5
+ structureAnalyzer = new StructureAnalyzer();
6
+ dependencyAnalyzer = new DependencyAnalyzer();
7
+ async analyze(rootPath, options = {}) {
8
+ const { diagramType = "architecture" } = options;
9
+ const startTime = Date.now();
10
+ let output;
11
+ switch (diagramType) {
12
+ case "dependencies":
13
+ output = await this.generateDependencyDiagram(rootPath);
14
+ break;
15
+ default:
16
+ output = await this.generateArchitectureDiagram(rootPath);
17
+ break;
18
+ }
19
+ return {
20
+ output,
21
+ data: { diagramType },
22
+ meta: {
23
+ analyzedAt: (/* @__PURE__ */ new Date()).toISOString(),
24
+ scope: rootPath,
25
+ fileCount: 0,
26
+ durationMs: Date.now() - startTime
27
+ }
28
+ };
29
+ }
30
+ async generateArchitectureDiagram(rootPath) {
31
+ const structResult = await this.structureAnalyzer.analyze(rootPath, {
32
+ format: "json",
33
+ maxDepth: 4
34
+ });
35
+ const tree = structResult.data.tree;
36
+ const depResult = await this.dependencyAnalyzer.analyze(rootPath, { format: "json" });
37
+ const depData = depResult.data;
38
+ const lines = ["```mermaid", "graph TB"];
39
+ const topDirs = (tree.children ?? []).filter((c) => c.type === "directory").slice(0, 15);
40
+ for (const dir of topDirs) {
41
+ const id = dir.name.replace(/[^a-zA-Z0-9]/g, "_");
42
+ const subDirs = (dir.children ?? []).filter((c) => c.type === "directory");
43
+ if (subDirs.length > 0) {
44
+ lines.push(` subgraph ${id}["${dir.name}/"]`);
45
+ for (const sub of subDirs.slice(0, 12)) {
46
+ const subId = `${id}_${sub.name.replace(/[^a-zA-Z0-9]/g, "_")}`;
47
+ const fileCount = Array.isArray(sub.children) ? sub.children.length : 0;
48
+ lines.push(` ${subId}["${sub.name}/ (${fileCount})"]`);
49
+ }
50
+ lines.push(" end");
51
+ } else {
52
+ const childCount = Array.isArray(dir.children) ? dir.children.length : 0;
53
+ lines.push(` ${id}["${dir.name}/ (${childCount} files)"]`);
54
+ }
55
+ }
56
+ const addedEdges = /* @__PURE__ */ new Set();
57
+ if (depData.internal) {
58
+ for (const [file, imports] of Object.entries(depData.internal)) {
59
+ const fromDir = file.split("/")[0]?.replace(/[^a-zA-Z0-9]/g, "_");
60
+ for (const imp of imports) {
61
+ if (imp.startsWith(".")) continue;
62
+ const toDir = imp.split("/")[0]?.replace(/[^a-zA-Z0-9]/g, "_");
63
+ if (fromDir && toDir && fromDir !== toDir) {
64
+ const edgeKey = `${fromDir}->${toDir}`;
65
+ if (!addedEdges.has(edgeKey)) {
66
+ addedEdges.add(edgeKey);
67
+ lines.push(` ${fromDir} --> ${toDir}`);
68
+ }
69
+ }
70
+ }
71
+ }
72
+ }
73
+ lines.push("```");
74
+ return lines.join("\n");
75
+ }
76
+ async generateDependencyDiagram(rootPath) {
77
+ const depResult = await this.dependencyAnalyzer.analyze(rootPath, { format: "mermaid" });
78
+ return `\`\`\`mermaid
79
+ ${depResult.output}
80
+ \`\`\``;
81
+ }
82
+ }
83
+ export {
84
+ DiagramGenerator
85
+ };
86
+ //# sourceMappingURL=diagram-generator.js.map
@@ -0,0 +1,19 @@
1
+ import type { AnalysisResult, AnalyzerOptions, IAnalyzer } from './types.js';
2
+ export declare class EntryPointAnalyzer implements IAnalyzer<AnalyzerOptions> {
3
+ readonly name = "entry-points";
4
+ analyze(rootPath: string, _options?: AnalyzerOptions): Promise<AnalysisResult>;
5
+ private fromPackageJson;
6
+ private fromHandlerExports;
7
+ /** Extract a meaningful name from the file path for non-JS entry points */
8
+ private inferNameFromFile;
9
+ /**
10
+ * Derive a contextual name from the directory path for generic handler/main files.
11
+ * E.g., "services/channels/email/delivery/src/handler.ts" → "email-delivery"
12
+ */
13
+ private deriveContextualName;
14
+ private inferEntryType;
15
+ private detectTrigger;
16
+ private collectFiles;
17
+ private formatMarkdown;
18
+ }
19
+ //# sourceMappingURL=entry-point-analyzer.d.ts.map
@@ -0,0 +1,239 @@
1
+ import { access, readdir, readFile } from "node:fs/promises";
2
+ import { extname, join, relative } from "node:path";
3
+ const DEFAULT_EXCLUDES = /* @__PURE__ */ new Set([
4
+ "node_modules",
5
+ ".git",
6
+ "dist",
7
+ "build",
8
+ "coverage",
9
+ ".turbo",
10
+ ".cache",
11
+ "cdk.out",
12
+ "__pycache__",
13
+ ".venv",
14
+ "target",
15
+ "bin",
16
+ "obj",
17
+ ".gradle",
18
+ "venv",
19
+ "env"
20
+ ]);
21
+ const TEST_DIR_SEGMENTS = /* @__PURE__ */ new Set(["test", "tests", "__tests__", "spec", "specs", "test-utils"]);
22
+ const HANDLER_PATTERNS = [
23
+ // ── JS/TS ──
24
+ // Lambda: export const handler = ... (with optional type annotation)
25
+ /export\s+const\s+(handler|main)\s*(?::[^=]*)?\s*=/,
26
+ // Lambda: export async function handler
27
+ /export\s+(?:async\s+)?function\s+(handler|main)\s*\(/,
28
+ // Named handler exports: export const emailHandler = ... (with optional type annotation)
29
+ /export\s+const\s+(\w+Handler)\s*(?::[^=]*)?\s*=/,
30
+ // Express/Hono app: export default app
31
+ /export\s+default\s+app/,
32
+ // ── Python ──
33
+ // Flask/FastAPI app
34
+ /^app\s*=\s*(?:Flask|FastAPI)\s*\(/m,
35
+ // Django: urlpatterns
36
+ /^urlpatterns\s*=\s*\[/m,
37
+ // Python main guard
38
+ /^if\s+__name__\s*==\s*['"]__main__['"]:/m,
39
+ // ── Java ──
40
+ // Spring Boot main class
41
+ /public\s+static\s+void\s+main\s*\(\s*String/,
42
+ // Spring Boot Application annotation
43
+ /@SpringBootApplication/,
44
+ // ── Go ──
45
+ /^func\s+main\s*\(\s*\)/m
46
+ ];
47
+ const TRIGGER_PATTERNS = [
48
+ { regex: /SqsEventSource|SQSEvent|sqs/i, trigger: "SQS" },
49
+ { regex: /SnsEventSource|SNSEvent|sns/i, trigger: "SNS" },
50
+ { regex: /ApiGateway|APIGatewayEvent|httpApi|restApi/i, trigger: "API Gateway" },
51
+ { regex: /ScheduleExpression|EventBridgeRule|schedule/i, trigger: "EventBridge Schedule" },
52
+ { regex: /S3EventSource|S3Event|s3/i, trigger: "S3" },
53
+ { regex: /DynamoEventSource|DynamoDBStream/i, trigger: "DynamoDB Stream" },
54
+ // Multi-language triggers
55
+ { regex: /@RequestMapping|@GetMapping|@PostMapping/i, trigger: "HTTP Endpoint" },
56
+ { regex: /http\.ListenAndServe|gin\.Default|echo\.New/i, trigger: "HTTP Server" },
57
+ { regex: /app\.route\(|@app\.get|@app\.post|@router\./i, trigger: "HTTP Route" }
58
+ ];
59
+ class EntryPointAnalyzer {
60
+ name = "entry-points";
61
+ async analyze(rootPath, _options = {}) {
62
+ const startTime = Date.now();
63
+ const entryPoints = [];
64
+ const pkgEntries = await this.fromPackageJson(rootPath);
65
+ entryPoints.push(...pkgEntries);
66
+ const handlerEntries = await this.fromHandlerExports(rootPath);
67
+ entryPoints.push(...handlerEntries);
68
+ const output = this.formatMarkdown(entryPoints, rootPath);
69
+ return {
70
+ output,
71
+ data: { entryPoints, total: entryPoints.length },
72
+ meta: {
73
+ analyzedAt: (/* @__PURE__ */ new Date()).toISOString(),
74
+ scope: rootPath,
75
+ fileCount: entryPoints.length,
76
+ durationMs: Date.now() - startTime
77
+ }
78
+ };
79
+ }
80
+ async fromPackageJson(rootPath) {
81
+ const entries = [];
82
+ try {
83
+ const pkgPath = join(rootPath, "package.json");
84
+ await access(pkgPath);
85
+ const pkg = JSON.parse(await readFile(pkgPath, "utf-8"));
86
+ if (pkg.main) {
87
+ entries.push({
88
+ name: "main",
89
+ type: "main",
90
+ filePath: pkg.main
91
+ });
92
+ }
93
+ if (pkg.bin) {
94
+ const bins = typeof pkg.bin === "string" ? { [pkg.name ?? "cli"]: pkg.bin } : pkg.bin;
95
+ for (const [name, path] of Object.entries(bins)) {
96
+ entries.push({ name, type: "cli", filePath: path });
97
+ }
98
+ }
99
+ if (pkg.scripts?.start) {
100
+ entries.push({
101
+ name: "start",
102
+ type: "server",
103
+ filePath: pkg.scripts.start,
104
+ trigger: "npm start"
105
+ });
106
+ }
107
+ } catch {
108
+ }
109
+ return entries;
110
+ }
111
+ async fromHandlerExports(rootPath) {
112
+ const entries = [];
113
+ const files = await this.collectFiles(rootPath);
114
+ for (const filePath of files) {
115
+ try {
116
+ const content = await readFile(filePath, "utf-8");
117
+ const relPath = relative(rootPath, filePath).replace(/\\/g, "/");
118
+ const pathSegments = relPath.split("/");
119
+ if (pathSegments.some((seg) => TEST_DIR_SEGMENTS.has(seg))) continue;
120
+ for (const pattern of HANDLER_PATTERNS) {
121
+ const match = content.match(pattern);
122
+ if (match) {
123
+ let name = match[1] ?? this.inferNameFromFile(relPath);
124
+ if (name === "handler" || name === "main") {
125
+ name = this.deriveContextualName(relPath) ?? name;
126
+ }
127
+ const isSpringBoot = /@SpringBootApplication/.test(content);
128
+ const trigger = isSpringBoot ? "HTTP Server" : this.detectTrigger(content);
129
+ entries.push({
130
+ name,
131
+ type: this.inferEntryType(match[1] ?? name, relPath),
132
+ filePath: relPath,
133
+ trigger
134
+ });
135
+ break;
136
+ }
137
+ }
138
+ } catch {
139
+ }
140
+ }
141
+ return entries;
142
+ }
143
+ /** Extract a meaningful name from the file path for non-JS entry points */
144
+ inferNameFromFile(relPath) {
145
+ const base = relPath.split(/[/\\]/).pop() ?? "default";
146
+ return base.replace(/\.\w+$/, "");
147
+ }
148
+ /**
149
+ * Derive a contextual name from the directory path for generic handler/main files.
150
+ * E.g., "services/channels/email/delivery/src/handler.ts" → "email-delivery"
151
+ */
152
+ deriveContextualName(relPath) {
153
+ const parts = relPath.split("/").filter((p) => p !== "src" && p !== "lib");
154
+ parts.pop();
155
+ if (parts.length === 0) return void 0;
156
+ const meaningful = parts.filter(
157
+ (p) => !["services", "functions", "lambdas", "handlers", "packages", "apps"].includes(p)
158
+ );
159
+ if (meaningful.length === 0) return void 0;
160
+ const last = meaningful.slice(-2);
161
+ if (last.length === 2 && last[1].startsWith(last[0])) {
162
+ return last[1];
163
+ }
164
+ return last.join("-");
165
+ }
166
+ inferEntryType(name, relPath) {
167
+ if (name === "handler" || name === "main") return "lambda-handler";
168
+ if (relPath.includes("handler")) return "lambda-handler";
169
+ if (/functions[/]/.test(relPath)) return "lambda-handler";
170
+ if (name.endsWith("Handler")) return "lambda-handler";
171
+ if (relPath.endsWith(".py") || relPath.endsWith(".go") || relPath.endsWith(".java")) {
172
+ return "main";
173
+ }
174
+ return "main";
175
+ }
176
+ detectTrigger(content) {
177
+ for (const tp of TRIGGER_PATTERNS) {
178
+ if (tp.regex.test(content)) return tp.trigger;
179
+ }
180
+ return void 0;
181
+ }
182
+ async collectFiles(rootPath) {
183
+ const files = [];
184
+ const codeExts = /* @__PURE__ */ new Set([
185
+ ".ts",
186
+ ".tsx",
187
+ ".js",
188
+ ".jsx",
189
+ ".java",
190
+ ".py",
191
+ ".go",
192
+ ".cs",
193
+ ".kt",
194
+ ".rb",
195
+ ".rs",
196
+ ".php",
197
+ ".swift"
198
+ ]);
199
+ const walk = async (dir, depth) => {
200
+ if (depth > 10) return;
201
+ const entries = await readdir(dir, { withFileTypes: true });
202
+ for (const entry of entries) {
203
+ if (DEFAULT_EXCLUDES.has(entry.name)) continue;
204
+ if (entry.name.startsWith(".")) continue;
205
+ const fullPath = join(dir, entry.name);
206
+ if (entry.isDirectory()) {
207
+ await walk(fullPath, depth + 1);
208
+ } else if (codeExts.has(extname(entry.name))) {
209
+ files.push(fullPath);
210
+ }
211
+ }
212
+ };
213
+ await walk(rootPath, 0);
214
+ return files;
215
+ }
216
+ formatMarkdown(entryPoints, rootPath) {
217
+ const lines = [];
218
+ lines.push(`## Entry Points: ${rootPath}
219
+ `);
220
+ lines.push(
221
+ `**${entryPoints.length} entry ${entryPoints.length === 1 ? "point" : "points"}** found
222
+ `
223
+ );
224
+ if (entryPoints.length === 0) {
225
+ lines.push("No entry points detected.");
226
+ return lines.join("\n");
227
+ }
228
+ lines.push("| Name | Type | File | Trigger |");
229
+ lines.push("|------|------|------|---------|");
230
+ for (const ep of entryPoints) {
231
+ lines.push(`| ${ep.name} | ${ep.type} | ${ep.filePath} | ${ep.trigger ?? "\u2014"} |`);
232
+ }
233
+ return lines.join("\n");
234
+ }
235
+ }
236
+ export {
237
+ EntryPointAnalyzer
238
+ };
239
+ //# sourceMappingURL=entry-point-analyzer.js.map
@@ -0,0 +1,14 @@
1
+ export type { BlastRadiusOptions } from './blast-radius-analyzer.js';
2
+ export { BlastRadiusAnalyzer } from './blast-radius-analyzer.js';
3
+ export { DependencyAnalyzer } from './dependency-analyzer.js';
4
+ export { DiagramGenerator } from './diagram-generator.js';
5
+ export { EntryPointAnalyzer } from './entry-point-analyzer.js';
6
+ export type { Analyzers } from './knowledge-producer.js';
7
+ export { KnowledgeProducer } from './knowledge-producer.js';
8
+ export { PatternAnalyzer } from './pattern-analyzer.js';
9
+ export { extractRegexCallGraph } from './regex-call-graph.js';
10
+ export { StructureAnalyzer } from './structure-analyzer.js';
11
+ export { SymbolAnalyzer } from './symbol-analyzer.js';
12
+ export { extractTsCallGraph } from './ts-call-graph.js';
13
+ export type { AnalysisResult, AnalyzerOptions, DependencyAnalyzerOptions, DiagramOptions, EntryPoint, ExistingKnowledge, ExtractionBaselines, IAnalyzer, ImportInfo, PatternMatch, ProjectStats, StructureAnalyzerOptions, SymbolAnalyzerOptions, SymbolInfo, TreeNode, } from './types.js';
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,23 @@
1
+ import { BlastRadiusAnalyzer } from "./blast-radius-analyzer.js";
2
+ import { DependencyAnalyzer } from "./dependency-analyzer.js";
3
+ import { DiagramGenerator } from "./diagram-generator.js";
4
+ import { EntryPointAnalyzer } from "./entry-point-analyzer.js";
5
+ import { KnowledgeProducer } from "./knowledge-producer.js";
6
+ import { PatternAnalyzer } from "./pattern-analyzer.js";
7
+ import { extractRegexCallGraph } from "./regex-call-graph.js";
8
+ import { StructureAnalyzer } from "./structure-analyzer.js";
9
+ import { SymbolAnalyzer } from "./symbol-analyzer.js";
10
+ import { extractTsCallGraph } from "./ts-call-graph.js";
11
+ export {
12
+ BlastRadiusAnalyzer,
13
+ DependencyAnalyzer,
14
+ DiagramGenerator,
15
+ EntryPointAnalyzer,
16
+ KnowledgeProducer,
17
+ PatternAnalyzer,
18
+ StructureAnalyzer,
19
+ SymbolAnalyzer,
20
+ extractRegexCallGraph,
21
+ extractTsCallGraph
22
+ };
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,32 @@
1
+ import type { DependencyAnalyzer } from './dependency-analyzer.js';
2
+ import type { DiagramGenerator } from './diagram-generator.js';
3
+ import type { EntryPointAnalyzer } from './entry-point-analyzer.js';
4
+ import type { PatternAnalyzer } from './pattern-analyzer.js';
5
+ import type { StructureAnalyzer } from './structure-analyzer.js';
6
+ import type { SymbolAnalyzer } from './symbol-analyzer.js';
7
+ import type { ExtractionBaselines } from './types.js';
8
+ export interface Analyzers {
9
+ structure: StructureAnalyzer;
10
+ dependencies: DependencyAnalyzer;
11
+ symbols: SymbolAnalyzer;
12
+ patterns: PatternAnalyzer;
13
+ entryPoints: EntryPointAnalyzer;
14
+ diagrams: DiagramGenerator;
15
+ }
16
+ /**
17
+ * Orchestrates Tier 1 deterministic extraction and prepares
18
+ * synthesis instructions for the LLM to produce knowledge.
19
+ */
20
+ export declare class KnowledgeProducer {
21
+ private readonly analyzers;
22
+ constructor(analyzers: Analyzers);
23
+ /**
24
+ * Run Tier 1 deterministic extraction for specified aspects.
25
+ */
26
+ runExtraction(scope: string, aspects: string[]): Promise<ExtractionBaselines>;
27
+ /**
28
+ * Build synthesis instructions from baselines for the LLM.
29
+ */
30
+ buildSynthesisInstructions(baselines: ExtractionBaselines, _aspects: string[]): string;
31
+ }
32
+ //# sourceMappingURL=knowledge-producer.d.ts.map
@@ -0,0 +1,113 @@
1
+ const ASPECT_MAP = {
2
+ structure: "structure",
3
+ dependencies: "dependencies",
4
+ symbols: "symbols",
5
+ patterns: "patterns",
6
+ "entry-points": "entryPoints",
7
+ diagrams: "diagrams"
8
+ };
9
+ const ALL_ASPECTS = Object.keys(ASPECT_MAP);
10
+ class KnowledgeProducer {
11
+ constructor(analyzers) {
12
+ this.analyzers = analyzers;
13
+ }
14
+ /**
15
+ * Run Tier 1 deterministic extraction for specified aspects.
16
+ */
17
+ async runExtraction(scope, aspects) {
18
+ const resolvedAspects = aspects.includes("all") ? ALL_ASPECTS : aspects;
19
+ const baselines = {};
20
+ const promises = [];
21
+ for (const aspect of resolvedAspects) {
22
+ const analyzerKey = ASPECT_MAP[aspect];
23
+ if (!analyzerKey) continue;
24
+ const analyzer = this.analyzers[analyzerKey];
25
+ if (!analyzer) continue;
26
+ if (aspect === "diagrams") {
27
+ promises.push({
28
+ key: "diagrams",
29
+ promise: analyzer.analyze(scope, { diagramType: "architecture" })
30
+ });
31
+ } else {
32
+ promises.push({
33
+ key: aspect,
34
+ promise: analyzer.analyze(scope)
35
+ });
36
+ }
37
+ }
38
+ const results = await Promise.allSettled(
39
+ promises.map(async (p) => ({ key: p.key, result: await p.promise }))
40
+ );
41
+ for (const settled of results) {
42
+ if (settled.status !== "fulfilled") continue;
43
+ const { key, result } = settled.value;
44
+ if (key === "diagrams") {
45
+ baselines.diagrams = [result];
46
+ } else {
47
+ baselines[key] = result;
48
+ }
49
+ }
50
+ return baselines;
51
+ }
52
+ /**
53
+ * Build synthesis instructions from baselines for the LLM.
54
+ */
55
+ buildSynthesisInstructions(baselines, _aspects) {
56
+ const sections = [];
57
+ sections.push("## Knowledge Production Results\n");
58
+ sections.push("### Extraction Baselines (auto-generated)\n");
59
+ if (baselines.structure) {
60
+ sections.push("#### File Structure\n");
61
+ sections.push(baselines.structure.output);
62
+ sections.push("");
63
+ }
64
+ if (baselines.dependencies) {
65
+ sections.push("#### Dependencies\n");
66
+ sections.push(baselines.dependencies.output);
67
+ sections.push("");
68
+ }
69
+ if (baselines.symbols) {
70
+ sections.push("#### Symbols\n");
71
+ sections.push(baselines.symbols.output);
72
+ sections.push("");
73
+ }
74
+ if (baselines.patterns) {
75
+ sections.push("#### Detected Patterns\n");
76
+ sections.push(baselines.patterns.output);
77
+ sections.push("");
78
+ }
79
+ if (baselines.entryPoints) {
80
+ sections.push("#### Entry Points\n");
81
+ sections.push(baselines.entryPoints.output);
82
+ sections.push("");
83
+ }
84
+ if (baselines.diagrams && baselines.diagrams.length > 0) {
85
+ sections.push("#### Architecture Diagram\n");
86
+ for (const d of baselines.diagrams) {
87
+ sections.push(d.output);
88
+ }
89
+ sections.push("");
90
+ }
91
+ sections.push("### Your Task: Synthesize Knowledge\n");
92
+ sections.push("Based on the baselines above and your reading of the source files, produce");
93
+ sections.push("the following knowledge documents using `kb_remember`:\n");
94
+ sections.push(
95
+ "1. **Domain Overview** (category: `architecture`)\n - What this service does, boundary with other services\n - Key entities and their lifecycle\n"
96
+ );
97
+ sections.push(
98
+ "2. **Architecture Summary** (category: `architecture`)\n - Layer structure, dependency flow\n - Key design decisions\n"
99
+ );
100
+ sections.push(
101
+ "3. **Pattern Usage** (category: `patterns`)\n - Which patterns are used and why\n - Where to find examples\n"
102
+ );
103
+ sections.push(
104
+ "4. **Conventions** (category: `conventions`)\n - Naming conventions observed\n - File organization rules\n - Testing patterns\n"
105
+ );
106
+ sections.push("Store each as a separate `kb_remember` call with descriptive titles.\n");
107
+ return sections.join("\n");
108
+ }
109
+ }
110
+ export {
111
+ KnowledgeProducer
112
+ };
113
+ //# sourceMappingURL=knowledge-producer.js.map
@@ -0,0 +1,12 @@
1
+ import type { AnalysisResult, AnalyzerOptions, IAnalyzer } from './types.js';
2
+ export declare class PatternAnalyzer implements IAnalyzer<AnalyzerOptions> {
3
+ readonly name = "patterns";
4
+ analyze(rootPath: string, _options?: AnalyzerOptions): Promise<AnalysisResult>;
5
+ private collectDirectories;
6
+ private collectCodeFiles;
7
+ private detectDirectoryPatterns;
8
+ private detectCodePatterns;
9
+ private detectConfigPatterns;
10
+ private formatMarkdown;
11
+ }
12
+ //# sourceMappingURL=pattern-analyzer.d.ts.map