@vpxa/kb 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/package.json +1 -1
  2. package/packages/analyzers/dist/blast-radius-analyzer.js +13 -114
  3. package/packages/analyzers/dist/dependency-analyzer.js +11 -425
  4. package/packages/analyzers/dist/diagram-generator.js +4 -86
  5. package/packages/analyzers/dist/entry-point-analyzer.js +5 -239
  6. package/packages/analyzers/dist/index.js +1 -23
  7. package/packages/analyzers/dist/knowledge-producer.js +24 -113
  8. package/packages/analyzers/dist/pattern-analyzer.js +5 -359
  9. package/packages/analyzers/dist/regex-call-graph.js +1 -428
  10. package/packages/analyzers/dist/structure-analyzer.js +4 -258
  11. package/packages/analyzers/dist/symbol-analyzer.js +13 -442
  12. package/packages/analyzers/dist/ts-call-graph.js +1 -160
  13. package/packages/analyzers/dist/types.js +0 -1
  14. package/packages/chunker/dist/call-graph-extractor.js +1 -90
  15. package/packages/chunker/dist/chunker-factory.js +1 -36
  16. package/packages/chunker/dist/chunker.interface.js +0 -1
  17. package/packages/chunker/dist/code-chunker.js +14 -134
  18. package/packages/chunker/dist/generic-chunker.js +5 -72
  19. package/packages/chunker/dist/index.js +1 -21
  20. package/packages/chunker/dist/markdown-chunker.js +7 -119
  21. package/packages/chunker/dist/treesitter-chunker.js +8 -234
  22. package/packages/cli/dist/commands/analyze.js +3 -112
  23. package/packages/cli/dist/commands/context-cmds.js +1 -155
  24. package/packages/cli/dist/commands/environment.js +2 -204
  25. package/packages/cli/dist/commands/execution.js +1 -137
  26. package/packages/cli/dist/commands/graph.js +7 -81
  27. package/packages/cli/dist/commands/init.js +9 -87
  28. package/packages/cli/dist/commands/knowledge.js +1 -139
  29. package/packages/cli/dist/commands/search.js +8 -267
  30. package/packages/cli/dist/commands/system.js +4 -241
  31. package/packages/cli/dist/commands/workspace.js +2 -388
  32. package/packages/cli/dist/context.js +1 -14
  33. package/packages/cli/dist/helpers.js +3 -458
  34. package/packages/cli/dist/index.js +3 -69
  35. package/packages/cli/dist/kb-init.js +1 -82
  36. package/packages/cli/dist/types.js +0 -1
  37. package/packages/core/dist/constants.js +1 -43
  38. package/packages/core/dist/content-detector.js +1 -79
  39. package/packages/core/dist/errors.js +1 -40
  40. package/packages/core/dist/index.js +1 -9
  41. package/packages/core/dist/logger.js +1 -34
  42. package/packages/core/dist/types.js +0 -1
  43. package/packages/embeddings/dist/embedder.interface.js +0 -1
  44. package/packages/embeddings/dist/index.js +1 -5
  45. package/packages/embeddings/dist/onnx-embedder.js +1 -82
  46. package/packages/indexer/dist/file-hasher.js +1 -13
  47. package/packages/indexer/dist/filesystem-crawler.js +1 -125
  48. package/packages/indexer/dist/graph-extractor.js +1 -111
  49. package/packages/indexer/dist/incremental-indexer.js +1 -278
  50. package/packages/indexer/dist/index.js +1 -14
  51. package/packages/server/dist/api.js +1 -9
  52. package/packages/server/dist/config.js +1 -75
  53. package/packages/server/dist/curated-manager.js +9 -356
  54. package/packages/server/dist/index.js +1 -134
  55. package/packages/server/dist/replay-interceptor.js +1 -38
  56. package/packages/server/dist/resources/resources.js +2 -40
  57. package/packages/server/dist/server.js +1 -247
  58. package/packages/server/dist/tools/analyze.tools.js +1 -288
  59. package/packages/server/dist/tools/forge.tools.js +11 -499
  60. package/packages/server/dist/tools/forget.tool.js +3 -39
  61. package/packages/server/dist/tools/graph.tool.js +5 -110
  62. package/packages/server/dist/tools/list.tool.js +5 -53
  63. package/packages/server/dist/tools/lookup.tool.js +8 -51
  64. package/packages/server/dist/tools/onboard.tool.js +2 -112
  65. package/packages/server/dist/tools/produce.tool.js +4 -74
  66. package/packages/server/dist/tools/read.tool.js +4 -47
  67. package/packages/server/dist/tools/reindex.tool.js +2 -70
  68. package/packages/server/dist/tools/remember.tool.js +3 -42
  69. package/packages/server/dist/tools/replay.tool.js +6 -88
  70. package/packages/server/dist/tools/search.tool.js +17 -327
  71. package/packages/server/dist/tools/status.tool.js +3 -68
  72. package/packages/server/dist/tools/toolkit.tools.js +20 -1673
  73. package/packages/server/dist/tools/update.tool.js +3 -39
  74. package/packages/server/dist/tools/utility.tools.js +19 -456
  75. package/packages/store/dist/graph-store.interface.js +0 -1
  76. package/packages/store/dist/index.js +1 -9
  77. package/packages/store/dist/lance-store.js +1 -258
  78. package/packages/store/dist/sqlite-graph-store.js +8 -309
  79. package/packages/store/dist/store-factory.js +1 -14
  80. package/packages/store/dist/store.interface.js +0 -1
  81. package/packages/tools/dist/batch.js +1 -45
  82. package/packages/tools/dist/changelog.js +2 -112
  83. package/packages/tools/dist/check.js +2 -59
  84. package/packages/tools/dist/checkpoint.js +2 -43
  85. package/packages/tools/dist/codemod.js +2 -69
  86. package/packages/tools/dist/compact.js +3 -60
  87. package/packages/tools/dist/data-transform.js +1 -124
  88. package/packages/tools/dist/dead-symbols.js +2 -71
  89. package/packages/tools/dist/delegate.js +3 -128
  90. package/packages/tools/dist/diff-parse.js +3 -153
  91. package/packages/tools/dist/digest.js +7 -242
  92. package/packages/tools/dist/encode.js +1 -46
  93. package/packages/tools/dist/env-info.js +1 -58
  94. package/packages/tools/dist/eval.js +3 -79
  95. package/packages/tools/dist/evidence-map.js +3 -203
  96. package/packages/tools/dist/file-summary.js +2 -106
  97. package/packages/tools/dist/file-walk.js +1 -75
  98. package/packages/tools/dist/find-examples.js +3 -48
  99. package/packages/tools/dist/find.js +1 -120
  100. package/packages/tools/dist/forge-classify.js +2 -319
  101. package/packages/tools/dist/forge-ground.js +1 -184
  102. package/packages/tools/dist/git-context.js +3 -46
  103. package/packages/tools/dist/graph-query.js +1 -194
  104. package/packages/tools/dist/health.js +1 -118
  105. package/packages/tools/dist/http-request.js +1 -58
  106. package/packages/tools/dist/index.js +1 -273
  107. package/packages/tools/dist/lane.js +7 -227
  108. package/packages/tools/dist/measure.js +2 -119
  109. package/packages/tools/dist/onboard.js +42 -1136
  110. package/packages/tools/dist/parse-output.js +2 -158
  111. package/packages/tools/dist/process-manager.js +1 -69
  112. package/packages/tools/dist/queue.js +2 -126
  113. package/packages/tools/dist/regex-test.js +1 -39
  114. package/packages/tools/dist/rename.js +2 -70
  115. package/packages/tools/dist/replay.js +6 -108
  116. package/packages/tools/dist/schema-validate.js +1 -141
  117. package/packages/tools/dist/scope-map.js +1 -72
  118. package/packages/tools/dist/snippet.js +1 -80
  119. package/packages/tools/dist/stash.js +2 -60
  120. package/packages/tools/dist/stratum-card.js +5 -238
  121. package/packages/tools/dist/symbol.js +3 -87
  122. package/packages/tools/dist/test-run.js +2 -55
  123. package/packages/tools/dist/text-utils.js +2 -31
  124. package/packages/tools/dist/time-utils.js +1 -135
  125. package/packages/tools/dist/trace.js +2 -114
  126. package/packages/tools/dist/truncation.js +10 -41
  127. package/packages/tools/dist/watch.js +1 -61
  128. package/packages/tools/dist/web-fetch.js +9 -244
  129. package/packages/tools/dist/web-search.js +1 -46
  130. package/packages/tools/dist/workset.js +2 -77
  131. package/packages/tui/dist/App.js +260 -52468
  132. package/packages/tui/dist/index.js +286 -54551
  133. package/packages/tui/dist/panels/CuratedPanel.js +211 -34291
  134. package/packages/tui/dist/panels/LogPanel.js +259 -51703
  135. package/packages/tui/dist/panels/SearchPanel.js +212 -34824
  136. package/packages/tui/dist/panels/StatusPanel.js +211 -34304
@@ -1,359 +1,5 @@
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 DIRECTORY_PATTERNS = [
22
- {
23
- dirs: ["adapters", "ports"],
24
- pattern: "Hexagonal Architecture",
25
- description: "Ports & adapters (hexagonal) separation"
26
- },
27
- {
28
- dirs: ["domain", "infrastructure", "application"],
29
- pattern: "Clean Architecture",
30
- description: "Layered with domain/infrastructure separation"
31
- },
32
- {
33
- dirs: ["controllers", "models"],
34
- pattern: "MVC Pattern",
35
- description: "Model-View-Controller structure"
36
- },
37
- {
38
- dirs: ["repositories"],
39
- pattern: "Repository Pattern",
40
- description: "Data access abstraction via repositories"
41
- },
42
- { dirs: ["factories"], pattern: "Factory Pattern", description: "Object creation via factories" },
43
- {
44
- dirs: ["handlers"],
45
- pattern: "Handler Pattern",
46
- description: "Event/request handler separation"
47
- },
48
- {
49
- dirs: ["middleware"],
50
- pattern: "Middleware Pattern",
51
- description: "Request pipeline middleware"
52
- },
53
- { dirs: ["hooks"], pattern: "React Hooks", description: "Custom React hooks for logic reuse" },
54
- {
55
- dirs: ["components"],
56
- pattern: "Component Architecture",
57
- description: "UI component-based structure"
58
- },
59
- {
60
- dirs: ["stacks", "constructs"],
61
- pattern: "CDK IaC",
62
- description: "AWS CDK infrastructure as code"
63
- },
64
- {
65
- dirs: ["lambdas", "functions"],
66
- pattern: "Serverless",
67
- description: "Serverless function architecture"
68
- }
69
- ];
70
- function collapseLocations(locations) {
71
- if (locations.length <= 3) return locations;
72
- const byDir = /* @__PURE__ */ new Map();
73
- for (const loc of locations) {
74
- const parts = loc.split("/");
75
- const dir = parts.length > 1 ? parts.slice(0, -1).join("/") : ".";
76
- const arr = byDir.get(dir);
77
- if (arr) arr.push(loc);
78
- else byDir.set(dir, [loc]);
79
- }
80
- const result = [];
81
- for (const [dir, files] of byDir) {
82
- if (files.length >= 3) {
83
- result.push(`${dir}/ (${files.length} files)`);
84
- } else {
85
- result.push(...files);
86
- }
87
- }
88
- return result.slice(0, 5);
89
- }
90
- const CODE_PATTERNS = [
91
- {
92
- regex: /container\.register|@injectable|@inject/i,
93
- pattern: "Dependency Injection",
94
- description: "IoC container or DI decorators"
95
- },
96
- {
97
- regex: /\.pipe\(|Observable|BehaviorSubject/i,
98
- pattern: "Reactive (RxJS)",
99
- description: "Reactive programming with observables",
100
- lang: "js"
101
- },
102
- {
103
- regex: /createContext|useContext/i,
104
- pattern: "React Context",
105
- description: "React Context API for state sharing",
106
- lang: "js"
107
- },
108
- {
109
- regex: /createSlice|configureStore/i,
110
- pattern: "Redux Toolkit",
111
- description: "Redux state management",
112
- lang: "js"
113
- },
114
- {
115
- regex: /defineStore|usePinia/i,
116
- pattern: "Pinia Store",
117
- description: "Vue Pinia state management",
118
- lang: "js"
119
- },
120
- {
121
- regex: /\.(test|spec)\.[jt]sx?|describe\s*\(|\bit\s*\([\s'"]/i,
122
- pattern: "Test Suite",
123
- description: "Unit/integration test files"
124
- },
125
- {
126
- regex: /@SpringBootApplication|@EnableAutoConfiguration/,
127
- pattern: "Spring Boot",
128
- description: "Spring Boot application framework",
129
- lang: "java",
130
- definitive: true
131
- },
132
- {
133
- regex: /@Autowired|@Component|@Service|@Repository|@Controller/,
134
- pattern: "Spring DI",
135
- description: "Spring dependency injection",
136
- lang: "java"
137
- },
138
- {
139
- regex: /@RestController|@RequestMapping|@GetMapping|@PostMapping/,
140
- pattern: "Spring REST",
141
- description: "Spring REST API controllers",
142
- lang: "java"
143
- },
144
- {
145
- regex: /app\s*=\s*Flask\s*\(|@app\.route/,
146
- pattern: "Flask",
147
- description: "Flask web framework",
148
- lang: "python"
149
- },
150
- {
151
- regex: /app\s*=\s*FastAPI\s*\(|@app\.get|@app\.post/,
152
- pattern: "FastAPI",
153
- description: "FastAPI web framework",
154
- lang: "python"
155
- },
156
- {
157
- regex: /func\s+main\s*\(\s*\)|http\.ListenAndServe/,
158
- pattern: "Go Application",
159
- description: "Go main application",
160
- lang: "go"
161
- }
162
- ];
163
- class PatternAnalyzer {
164
- name = "patterns";
165
- async analyze(rootPath, _options = {}) {
166
- const startTime = Date.now();
167
- const dirs = await this.collectDirectories(rootPath);
168
- const dirPatterns = this.detectDirectoryPatterns(dirs, rootPath);
169
- const files = await this.collectCodeFiles(rootPath);
170
- const codePatterns = await this.detectCodePatterns(files, rootPath);
171
- const allPatterns = [...dirPatterns, ...codePatterns];
172
- const configPatterns = await this.detectConfigPatterns(rootPath);
173
- const primaryBuild = configPatterns.find(
174
- (p) => p.pattern === "Maven" || p.pattern === "Gradle" || p.pattern === "Gradle (Kotlin DSL)" || p.pattern === "Node.js Project" || p.pattern === "Go Module" || p.pattern === "Rust (Cargo)"
175
- );
176
- const secondaryLangPatterns = /* @__PURE__ */ new Set([
177
- "Ruby (Bundler)",
178
- "PHP (Composer)",
179
- "Swift Package",
180
- "SBT"
181
- ]);
182
- for (const cp of configPatterns) {
183
- if (primaryBuild && secondaryLangPatterns.has(cp.pattern)) continue;
184
- allPatterns.push(cp);
185
- }
186
- const output = this.formatMarkdown(allPatterns, rootPath);
187
- return {
188
- output,
189
- data: { patterns: allPatterns, total: allPatterns.length },
190
- meta: {
191
- analyzedAt: (/* @__PURE__ */ new Date()).toISOString(),
192
- scope: rootPath,
193
- fileCount: files.length,
194
- durationMs: Date.now() - startTime
195
- }
196
- };
197
- }
198
- async collectDirectories(rootPath) {
199
- const dirs = [];
200
- const walk = async (dir, depth) => {
201
- if (depth > 5) return;
202
- const entries = await readdir(dir, { withFileTypes: true });
203
- for (const entry of entries) {
204
- if (!entry.isDirectory()) continue;
205
- if (DEFAULT_EXCLUDES.has(entry.name)) continue;
206
- if (entry.name.startsWith(".")) continue;
207
- const fullPath = join(dir, entry.name);
208
- dirs.push(entry.name);
209
- await walk(fullPath, depth + 1);
210
- }
211
- };
212
- await walk(rootPath, 0);
213
- return dirs;
214
- }
215
- async collectCodeFiles(rootPath) {
216
- const files = [];
217
- const codeExts = /* @__PURE__ */ new Set([
218
- ".ts",
219
- ".tsx",
220
- ".js",
221
- ".jsx",
222
- ".java",
223
- ".py",
224
- ".go",
225
- ".cs",
226
- ".kt",
227
- ".scala",
228
- ".rb",
229
- ".rs",
230
- ".php",
231
- ".swift"
232
- ]);
233
- const walk = async (dir) => {
234
- const entries = await readdir(dir, { withFileTypes: true });
235
- for (const entry of entries) {
236
- if (DEFAULT_EXCLUDES.has(entry.name)) continue;
237
- if (entry.name.startsWith(".")) continue;
238
- const fullPath = join(dir, entry.name);
239
- if (entry.isDirectory()) {
240
- await walk(fullPath);
241
- } else if (codeExts.has(extname(entry.name))) {
242
- files.push(fullPath);
243
- }
244
- }
245
- };
246
- await walk(rootPath);
247
- return files;
248
- }
249
- detectDirectoryPatterns(dirs, _rootPath) {
250
- const dirSet = new Set(dirs.map((d) => d.toLowerCase()));
251
- const matches = [];
252
- for (const dp of DIRECTORY_PATTERNS) {
253
- const found = dp.dirs.filter((d) => dirSet.has(d));
254
- if (found.length === 0) continue;
255
- if (dp.dirs.length > 1 && found.length < 2) continue;
256
- matches.push({
257
- pattern: dp.pattern,
258
- description: dp.description,
259
- locations: found.map((d) => `${d}/`),
260
- confidence: found.length === dp.dirs.length ? "high" : "medium"
261
- });
262
- }
263
- return matches;
264
- }
265
- async detectCodePatterns(files, rootPath) {
266
- const matches = [];
267
- const patternFiles = {};
268
- const priorityFiles = files.filter(
269
- (f) => /Application\.\w+$|Main\.\w+$|app\.\w+$|main\.\w+$/i.test(f) || /Controller|Service|Handler|Router/i.test(f)
270
- );
271
- const rest = files.filter((f) => !priorityFiles.includes(f));
272
- const sampled = [...priorityFiles.slice(0, 50), ...rest.slice(0, 150)];
273
- for (const filePath of sampled) {
274
- try {
275
- const content = await readFile(filePath, "utf-8");
276
- const ext = extname(filePath).toLowerCase();
277
- const fileLang = ext === ".java" || ext === ".kt" || ext === ".scala" ? "java" : ext === ".py" ? "python" : ext === ".go" ? "go" : "js";
278
- for (const cp of CODE_PATTERNS) {
279
- if (cp.lang && cp.lang !== fileLang) continue;
280
- if (cp.regex.test(content)) {
281
- if (!patternFiles[cp.pattern]) patternFiles[cp.pattern] = /* @__PURE__ */ new Set();
282
- patternFiles[cp.pattern].add(relative(rootPath, filePath).replace(/\\/g, "/"));
283
- }
284
- }
285
- } catch {
286
- }
287
- }
288
- for (const cp of CODE_PATTERNS) {
289
- const locations = patternFiles[cp.pattern];
290
- if (locations && locations.size > 0) {
291
- const collapsed = collapseLocations([...locations]);
292
- matches.push({
293
- pattern: cp.pattern,
294
- description: cp.description,
295
- locations: collapsed,
296
- confidence: cp.definitive || locations.size >= 3 ? "high" : locations.size >= 2 ? "medium" : "low"
297
- });
298
- }
299
- }
300
- return matches;
301
- }
302
- async detectConfigPatterns(rootPath) {
303
- const matches = [];
304
- const checks = [
305
- { file: "Dockerfile", pattern: "Docker", description: "Containerized application" },
306
- {
307
- file: "docker-compose.yml",
308
- pattern: "Docker Compose",
309
- description: "Container orchestration"
310
- },
311
- { file: "cdk.json", pattern: "AWS CDK", description: "AWS CDK infrastructure as code" },
312
- { file: "terraform.tf", pattern: "Terraform", description: "Terraform IaC" },
313
- { file: "main.tf", pattern: "Terraform", description: "Terraform IaC" }
314
- ];
315
- for (const check of checks) {
316
- try {
317
- await access(join(rootPath, check.file));
318
- matches.push({
319
- pattern: check.pattern,
320
- description: check.description,
321
- locations: [check.file],
322
- confidence: "high"
323
- });
324
- } catch {
325
- }
326
- }
327
- return matches;
328
- }
329
- formatMarkdown(patterns, rootPath) {
330
- const lines = [];
331
- lines.push(`## Patterns Detected: ${rootPath}
332
- `);
333
- lines.push(`**${patterns.length} patterns** found
334
- `);
335
- const byConfidence = {
336
- high: [],
337
- medium: [],
338
- low: []
339
- };
340
- for (const p of patterns) {
341
- byConfidence[p.confidence].push(p);
342
- }
343
- for (const [level, group] of Object.entries(byConfidence)) {
344
- if (group.length === 0) continue;
345
- lines.push(`### ${level.charAt(0).toUpperCase() + level.slice(1)} Confidence
346
- `);
347
- for (const p of group) {
348
- lines.push(`- **${p.pattern}**: ${p.description}`);
349
- lines.push(` Locations: ${p.locations.slice(0, 5).join(", ")}`);
350
- }
351
- lines.push("");
352
- }
353
- return lines.join("\n");
354
- }
355
- }
356
- export {
357
- PatternAnalyzer
358
- };
359
- //# sourceMappingURL=pattern-analyzer.js.map
1
+ import{access as P,readdir as h,readFile as C}from"node:fs/promises";import{extname as m,join as u,relative as S}from"node:path";const y=new Set(["node_modules",".git","dist","build","coverage",".turbo",".cache","cdk.out","__pycache__",".venv","target","bin","obj",".gradle","venv","env"]),v=[{dirs:["adapters","ports"],pattern:"Hexagonal Architecture",description:"Ports & adapters (hexagonal) separation"},{dirs:["domain","infrastructure","application"],pattern:"Clean Architecture",description:"Layered with domain/infrastructure separation"},{dirs:["controllers","models"],pattern:"MVC Pattern",description:"Model-View-Controller structure"},{dirs:["repositories"],pattern:"Repository Pattern",description:"Data access abstraction via repositories"},{dirs:["factories"],pattern:"Factory Pattern",description:"Object creation via factories"},{dirs:["handlers"],pattern:"Handler Pattern",description:"Event/request handler separation"},{dirs:["middleware"],pattern:"Middleware Pattern",description:"Request pipeline middleware"},{dirs:["hooks"],pattern:"React Hooks",description:"Custom React hooks for logic reuse"},{dirs:["components"],pattern:"Component Architecture",description:"UI component-based structure"},{dirs:["stacks","constructs"],pattern:"CDK IaC",description:"AWS CDK infrastructure as code"},{dirs:["lambdas","functions"],pattern:"Serverless",description:"Serverless function architecture"}];function A(g){if(g.length<=3)return g;const r=new Map;for(const e of g){const t=e.split("/"),n=t.length>1?t.slice(0,-1).join("/"):".",a=r.get(n);a?a.push(e):r.set(n,[e])}const o=[];for(const[e,t]of r)t.length>=3?o.push(`${e}/ (${t.length} files)`):o.push(...t);return o.slice(0,5)}const w=[{regex:/container\.register|@injectable|@inject/i,pattern:"Dependency Injection",description:"IoC container or DI decorators"},{regex:/\.pipe\(|Observable|BehaviorSubject/i,pattern:"Reactive (RxJS)",description:"Reactive programming with observables",lang:"js"},{regex:/createContext|useContext/i,pattern:"React Context",description:"React Context API for state sharing",lang:"js"},{regex:/createSlice|configureStore/i,pattern:"Redux Toolkit",description:"Redux state management",lang:"js"},{regex:/defineStore|usePinia/i,pattern:"Pinia Store",description:"Vue Pinia state management",lang:"js"},{regex:/\.(test|spec)\.[jt]sx?|describe\s*\(|\bit\s*\([\s'"]/i,pattern:"Test Suite",description:"Unit/integration test files"},{regex:/@SpringBootApplication|@EnableAutoConfiguration/,pattern:"Spring Boot",description:"Spring Boot application framework",lang:"java",definitive:!0},{regex:/@Autowired|@Component|@Service|@Repository|@Controller/,pattern:"Spring DI",description:"Spring dependency injection",lang:"java"},{regex:/@RestController|@RequestMapping|@GetMapping|@PostMapping/,pattern:"Spring REST",description:"Spring REST API controllers",lang:"java"},{regex:/app\s*=\s*Flask\s*\(|@app\.route/,pattern:"Flask",description:"Flask web framework",lang:"python"},{regex:/app\s*=\s*FastAPI\s*\(|@app\.get|@app\.post/,pattern:"FastAPI",description:"FastAPI web framework",lang:"python"},{regex:/func\s+main\s*\(\s*\)|http\.ListenAndServe/,pattern:"Go Application",description:"Go main application",lang:"go"}];class D{name="patterns";async analyze(r,o={}){const e=Date.now(),t=await this.collectDirectories(r),n=this.detectDirectoryPatterns(t,r),a=await this.collectCodeFiles(r),i=await this.detectCodePatterns(a,r),s=[...n,...i],c=await this.detectConfigPatterns(r),p=c.find(l=>l.pattern==="Maven"||l.pattern==="Gradle"||l.pattern==="Gradle (Kotlin DSL)"||l.pattern==="Node.js Project"||l.pattern==="Go Module"||l.pattern==="Rust (Cargo)"),f=new Set(["Ruby (Bundler)","PHP (Composer)","Swift Package","SBT"]);for(const l of c)p&&f.has(l.pattern)||s.push(l);return{output:this.formatMarkdown(s,r),data:{patterns:s,total:s.length},meta:{analyzedAt:new Date().toISOString(),scope:r,fileCount:a.length,durationMs:Date.now()-e}}}async collectDirectories(r){const o=[],e=async(t,n)=>{if(n>5)return;const a=await h(t,{withFileTypes:!0});for(const i of a){if(!i.isDirectory()||y.has(i.name)||i.name.startsWith("."))continue;const s=u(t,i.name);o.push(i.name),await e(s,n+1)}};return await e(r,0),o}async collectCodeFiles(r){const o=[],e=new Set([".ts",".tsx",".js",".jsx",".java",".py",".go",".cs",".kt",".scala",".rb",".rs",".php",".swift"]),t=async n=>{const a=await h(n,{withFileTypes:!0});for(const i of a){if(y.has(i.name)||i.name.startsWith("."))continue;const s=u(n,i.name);i.isDirectory()?await t(s):e.has(m(i.name))&&o.push(s)}};return await t(r),o}detectDirectoryPatterns(r,o){const e=new Set(r.map(n=>n.toLowerCase())),t=[];for(const n of v){const a=n.dirs.filter(i=>e.has(i));a.length!==0&&(n.dirs.length>1&&a.length<2||t.push({pattern:n.pattern,description:n.description,locations:a.map(i=>`${i}/`),confidence:a.length===n.dirs.length?"high":"medium"}))}return t}async detectCodePatterns(r,o){const e=[],t={},n=r.filter(s=>/Application\.\w+$|Main\.\w+$|app\.\w+$|main\.\w+$/i.test(s)||/Controller|Service|Handler|Router/i.test(s)),a=r.filter(s=>!n.includes(s)),i=[...n.slice(0,50),...a.slice(0,150)];for(const s of i)try{const c=await C(s,"utf-8"),p=m(s).toLowerCase(),f=p===".java"||p===".kt"||p===".scala"?"java":p===".py"?"python":p===".go"?"go":"js";for(const d of w)d.lang&&d.lang!==f||d.regex.test(c)&&(t[d.pattern]||(t[d.pattern]=new Set),t[d.pattern].add(S(o,s).replace(/\\/g,"/")))}catch{}for(const s of w){const c=t[s.pattern];if(c&&c.size>0){const p=A([...c]);e.push({pattern:s.pattern,description:s.description,locations:p,confidence:s.definitive||c.size>=3?"high":c.size>=2?"medium":"low"})}}return e}async detectConfigPatterns(r){const o=[],e=[{file:"Dockerfile",pattern:"Docker",description:"Containerized application"},{file:"docker-compose.yml",pattern:"Docker Compose",description:"Container orchestration"},{file:"cdk.json",pattern:"AWS CDK",description:"AWS CDK infrastructure as code"},{file:"terraform.tf",pattern:"Terraform",description:"Terraform IaC"},{file:"main.tf",pattern:"Terraform",description:"Terraform IaC"}];for(const t of e)try{await P(u(r,t.file)),o.push({pattern:t.pattern,description:t.description,locations:[t.file],confidence:"high"})}catch{}return o}formatMarkdown(r,o){const e=[];e.push(`## Patterns Detected: ${o}
2
+ `),e.push(`**${r.length} patterns** found
3
+ `);const t={high:[],medium:[],low:[]};for(const n of r)t[n.confidence].push(n);for(const[n,a]of Object.entries(t))if(a.length!==0){e.push(`### ${n.charAt(0).toUpperCase()+n.slice(1)} Confidence
4
+ `);for(const i of a)e.push(`- **${i.pattern}**: ${i.description}`),e.push(` Locations: ${i.locations.slice(0,5).join(", ")}`);e.push("")}return e.join(`
5
+ `)}}export{D as PatternAnalyzer};