erosolar-cli 1.7.54 → 1.7.56

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 (283) hide show
  1. package/dist/core/agent.d.ts.map +1 -1
  2. package/dist/core/agent.js +14 -4
  3. package/dist/core/agent.js.map +1 -1
  4. package/dist/providers/anthropicProvider.d.ts.map +1 -1
  5. package/dist/providers/anthropicProvider.js +2 -1
  6. package/dist/providers/anthropicProvider.js.map +1 -1
  7. package/dist/ui/persistentPrompt.d.ts +24 -0
  8. package/dist/ui/persistentPrompt.d.ts.map +1 -1
  9. package/dist/ui/persistentPrompt.js +86 -4
  10. package/dist/ui/persistentPrompt.js.map +1 -1
  11. package/package.json +1 -1
  12. package/dist/active-stack-security.d.ts +0 -110
  13. package/dist/active-stack-security.js +0 -313
  14. package/dist/active-stack-security.js.map +0 -1
  15. package/dist/advanced-targeting.d.ts +0 -113
  16. package/dist/advanced-targeting.js +0 -252
  17. package/dist/advanced-targeting.js.map +0 -1
  18. package/dist/bin/adapters/node/index.js +0 -33
  19. package/dist/bin/adapters/types.js +0 -1
  20. package/dist/bin/alpha-zero/agentWrapper.js +0 -165
  21. package/dist/bin/alpha-zero/codeEvaluator.js +0 -272
  22. package/dist/bin/alpha-zero/competitiveRunner.js +0 -219
  23. package/dist/bin/alpha-zero/index.js +0 -98
  24. package/dist/bin/alpha-zero/introspection.js +0 -298
  25. package/dist/bin/alpha-zero/metricsTracker.js +0 -207
  26. package/dist/bin/alpha-zero/security/core.js +0 -269
  27. package/dist/bin/alpha-zero/security/google.js +0 -308
  28. package/dist/bin/alpha-zero/security/googleLoader.js +0 -40
  29. package/dist/bin/alpha-zero/security/index.js +0 -31
  30. package/dist/bin/alpha-zero/security/simulation.js +0 -274
  31. package/dist/bin/alpha-zero/selfModification.js +0 -231
  32. package/dist/bin/alpha-zero/types.js +0 -30
  33. package/dist/bin/bin/erosolar-optimized.js +0 -205
  34. package/dist/bin/capabilities/agentSpawningCapability.js +0 -116
  35. package/dist/bin/capabilities/bashCapability.js +0 -22
  36. package/dist/bin/capabilities/cloudCapability.js +0 -36
  37. package/dist/bin/capabilities/codeAnalysisCapability.js +0 -22
  38. package/dist/bin/capabilities/codeQualityCapability.js +0 -23
  39. package/dist/bin/capabilities/dependencySecurityCapability.js +0 -22
  40. package/dist/bin/capabilities/devCapability.js +0 -22
  41. package/dist/bin/capabilities/editCapability.js +0 -28
  42. package/dist/bin/capabilities/emailCapability.js +0 -20
  43. package/dist/bin/capabilities/enhancedGitCapability.js +0 -221
  44. package/dist/bin/capabilities/filesystemCapability.js +0 -22
  45. package/dist/bin/capabilities/globCapability.js +0 -28
  46. package/dist/bin/capabilities/interactionCapability.js +0 -20
  47. package/dist/bin/capabilities/learnCapability.js +0 -22
  48. package/dist/bin/capabilities/mcpCapability.js +0 -20
  49. package/dist/bin/capabilities/notebookCapability.js +0 -28
  50. package/dist/bin/capabilities/planningCapability.js +0 -27
  51. package/dist/bin/capabilities/refactoringCapability.js +0 -23
  52. package/dist/bin/capabilities/repoChecksCapability.js +0 -22
  53. package/dist/bin/capabilities/searchCapability.js +0 -22
  54. package/dist/bin/capabilities/skillCapability.js +0 -76
  55. package/dist/bin/capabilities/taskManagementCapability.js +0 -20
  56. package/dist/bin/capabilities/testingCapability.js +0 -23
  57. package/dist/bin/capabilities/toolManifest.js +0 -159
  58. package/dist/bin/capabilities/toolRegistry.js +0 -114
  59. package/dist/bin/capabilities/webCapability.js +0 -20
  60. package/dist/bin/config.js +0 -139
  61. package/dist/bin/contracts/v1/agent.js +0 -7
  62. package/dist/bin/contracts/v1/agentProfileManifest.js +0 -8
  63. package/dist/bin/contracts/v1/agentRules.js +0 -9
  64. package/dist/bin/contracts/v1/toolAccess.js +0 -8
  65. package/dist/bin/erosolar-optimized.d.ts +0 -12
  66. package/dist/bin/erosolar-optimized.d.ts.map +0 -1
  67. package/dist/bin/erosolar-optimized.js +0 -239
  68. package/dist/bin/erosolar-optimized.js.map +0 -1
  69. package/dist/bin/headless/headlessApp.js +0 -172
  70. package/dist/bin/mcp/config.js +0 -202
  71. package/dist/bin/mcp/stdioClient.js +0 -172
  72. package/dist/bin/mcp/toolBridge.js +0 -104
  73. package/dist/bin/mcp/types.js +0 -1
  74. package/dist/bin/plugins/index.js +0 -113
  75. package/dist/bin/plugins/providers/anthropic/index.js +0 -25
  76. package/dist/bin/plugins/providers/deepseek/index.js +0 -24
  77. package/dist/bin/plugins/providers/google/index.js +0 -26
  78. package/dist/bin/plugins/providers/index.js +0 -19
  79. package/dist/bin/plugins/providers/ollama/index.js +0 -59
  80. package/dist/bin/plugins/providers/openai/index.js +0 -26
  81. package/dist/bin/plugins/providers/xai/index.js +0 -24
  82. package/dist/bin/plugins/tools/agentSpawning/agentSpawningPlugin.js +0 -8
  83. package/dist/bin/plugins/tools/bash/localBashPlugin.js +0 -13
  84. package/dist/bin/plugins/tools/checks/localRepoChecksPlugin.js +0 -13
  85. package/dist/bin/plugins/tools/cloud/cloudPlugin.js +0 -13
  86. package/dist/bin/plugins/tools/codeAnalysis/codeAnalysisPlugin.js +0 -13
  87. package/dist/bin/plugins/tools/codeQuality/codeQualityPlugin.js +0 -13
  88. package/dist/bin/plugins/tools/dependency/dependencyPlugin.js +0 -11
  89. package/dist/bin/plugins/tools/development/devPlugin.js +0 -13
  90. package/dist/bin/plugins/tools/edit/editPlugin.js +0 -14
  91. package/dist/bin/plugins/tools/email/emailPlugin.js +0 -11
  92. package/dist/bin/plugins/tools/enhancedGit/enhancedGitPlugin.js +0 -8
  93. package/dist/bin/plugins/tools/filesystem/localFilesystemPlugin.js +0 -13
  94. package/dist/bin/plugins/tools/glob/globPlugin.js +0 -14
  95. package/dist/bin/plugins/tools/index.js +0 -2
  96. package/dist/bin/plugins/tools/interaction/interactionPlugin.js +0 -11
  97. package/dist/bin/plugins/tools/learn/learnPlugin.js +0 -13
  98. package/dist/bin/plugins/tools/mcp/mcpPlugin.js +0 -8
  99. package/dist/bin/plugins/tools/nodeDefaults.js +0 -56
  100. package/dist/bin/plugins/tools/notebook/notebookPlugin.js +0 -14
  101. package/dist/bin/plugins/tools/planning/planningPlugin.js +0 -14
  102. package/dist/bin/plugins/tools/refactoring/refactoringPlugin.js +0 -11
  103. package/dist/bin/plugins/tools/registry.js +0 -57
  104. package/dist/bin/plugins/tools/search/localSearchPlugin.js +0 -13
  105. package/dist/bin/plugins/tools/skills/skillPlugin.js +0 -8
  106. package/dist/bin/plugins/tools/taskManagement/taskManagementPlugin.js +0 -11
  107. package/dist/bin/plugins/tools/testing/testingPlugin.js +0 -11
  108. package/dist/bin/plugins/tools/web/webPlugin.js +0 -11
  109. package/dist/bin/providers/anthropicProvider.js +0 -329
  110. package/dist/bin/providers/googleProvider.js +0 -203
  111. package/dist/bin/providers/openaiChatCompletionsProvider.js +0 -208
  112. package/dist/bin/providers/openaiResponsesProvider.js +0 -249
  113. package/dist/bin/providers/providerFactory.js +0 -24
  114. package/dist/bin/runtime/agentController.js +0 -321
  115. package/dist/bin/runtime/agentHost.js +0 -153
  116. package/dist/bin/runtime/agentSession.js +0 -195
  117. package/dist/bin/runtime/node.js +0 -10
  118. package/dist/bin/runtime/universal.js +0 -28
  119. package/dist/bin/skills/skillRepository.js +0 -236
  120. package/dist/bin/skills/types.js +0 -1
  121. package/dist/bin/subagents/taskRunner.js +0 -269
  122. package/dist/bin/tools/backgroundBashTools.js +0 -211
  123. package/dist/bin/tools/bashTools.js +0 -159
  124. package/dist/bin/tools/cloudTools.js +0 -864
  125. package/dist/bin/tools/codeAnalysisTools.js +0 -641
  126. package/dist/bin/tools/codeQualityTools.js +0 -294
  127. package/dist/bin/tools/dependencyTools.js +0 -282
  128. package/dist/bin/tools/devTools.js +0 -238
  129. package/dist/bin/tools/diffUtils.js +0 -137
  130. package/dist/bin/tools/editTools.js +0 -134
  131. package/dist/bin/tools/emailTools.js +0 -448
  132. package/dist/bin/tools/fileTools.js +0 -282
  133. package/dist/bin/tools/globTools.js +0 -173
  134. package/dist/bin/tools/grepTools.js +0 -332
  135. package/dist/bin/tools/interactionTools.js +0 -170
  136. package/dist/bin/tools/learnTools.js +0 -1818
  137. package/dist/bin/tools/notebookEditTools.js +0 -196
  138. package/dist/bin/tools/planningTools.js +0 -46
  139. package/dist/bin/tools/refactoringTools.js +0 -293
  140. package/dist/bin/tools/repoChecksTools.js +0 -160
  141. package/dist/bin/tools/searchTools.js +0 -206
  142. package/dist/bin/tools/skillTools.js +0 -177
  143. package/dist/bin/tools/taskManagementTools.js +0 -156
  144. package/dist/bin/tools/testingTools.js +0 -232
  145. package/dist/bin/tools/webTools.js +0 -480
  146. package/dist/bin/workspace.js +0 -106
  147. package/dist/bin/workspace.validator.js +0 -213
  148. package/dist/capabilities/offensiveSecurityCapability.d.ts +0 -26
  149. package/dist/capabilities/offensiveSecurityCapability.d.ts.map +0 -1
  150. package/dist/capabilities/offensiveSecurityCapability.js +0 -58
  151. package/dist/capabilities/offensiveSecurityCapability.js.map +0 -1
  152. package/dist/capabilities/realSecurityCapability.d.ts +0 -26
  153. package/dist/capabilities/realSecurityCapability.d.ts.map +0 -1
  154. package/dist/capabilities/realSecurityCapability.js +0 -53
  155. package/dist/capabilities/realSecurityCapability.js.map +0 -1
  156. package/dist/capabilities/securityCapability.d.ts +0 -32
  157. package/dist/capabilities/securityCapability.d.ts.map +0 -1
  158. package/dist/capabilities/securityCapability.js +0 -57
  159. package/dist/capabilities/securityCapability.js.map +0 -1
  160. package/dist/capabilities/ultimateSecurityCapability.d.ts +0 -42
  161. package/dist/capabilities/ultimateSecurityCapability.d.ts.map +0 -1
  162. package/dist/capabilities/ultimateSecurityCapability.js +0 -96
  163. package/dist/capabilities/ultimateSecurityCapability.js.map +0 -1
  164. package/dist/core/designThoughtCheck.d.ts +0 -196
  165. package/dist/core/designThoughtCheck.d.ts.map +0 -1
  166. package/dist/core/designThoughtCheck.js +0 -287
  167. package/dist/core/designThoughtCheck.js.map +0 -1
  168. package/dist/core/designThoughtCheckEngine.d.ts +0 -58
  169. package/dist/core/designThoughtCheckEngine.d.ts.map +0 -1
  170. package/dist/core/designThoughtCheckEngine.js +0 -358
  171. package/dist/core/designThoughtCheckEngine.js.map +0 -1
  172. package/dist/core/designThoughtCheckIntegration.d.ts +0 -103
  173. package/dist/core/designThoughtCheckIntegration.d.ts.map +0 -1
  174. package/dist/core/designThoughtCheckIntegration.js +0 -207
  175. package/dist/core/designThoughtCheckIntegration.js.map +0 -1
  176. package/dist/core/intelligenceTools.d.ts +0 -19
  177. package/dist/core/intelligenceTools.d.ts.map +0 -1
  178. package/dist/core/intelligenceTools.js +0 -453
  179. package/dist/core/intelligenceTools.js.map +0 -1
  180. package/dist/core/operationalTools.d.ts +0 -19
  181. package/dist/core/operationalTools.d.ts.map +0 -1
  182. package/dist/core/operationalTools.js +0 -467
  183. package/dist/core/operationalTools.js.map +0 -1
  184. package/dist/offensive/core/offensive-engine.d.ts +0 -171
  185. package/dist/offensive/core/offensive-engine.d.ts.map +0 -1
  186. package/dist/offensive/core/offensive-engine.js +0 -345
  187. package/dist/offensive/core/offensive-engine.js.map +0 -1
  188. package/dist/offensive/core/offensive-integration.d.ts +0 -129
  189. package/dist/offensive/core/offensive-integration.d.ts.map +0 -1
  190. package/dist/offensive/core/offensive-integration.js +0 -364
  191. package/dist/offensive/core/offensive-integration.js.map +0 -1
  192. package/dist/offensive/core/offensive-tools.d.ts +0 -55
  193. package/dist/offensive/core/offensive-tools.d.ts.map +0 -1
  194. package/dist/offensive/core/offensive-tools.js +0 -438
  195. package/dist/offensive/core/offensive-tools.js.map +0 -1
  196. package/dist/offensive/offensive-cli.d.ts +0 -48
  197. package/dist/offensive/offensive-cli.d.ts.map +0 -1
  198. package/dist/offensive/offensive-cli.js +0 -233
  199. package/dist/offensive/offensive-cli.js.map +0 -1
  200. package/dist/security/apt-simulation-cli.d.ts +0 -57
  201. package/dist/security/apt-simulation-cli.d.ts.map +0 -1
  202. package/dist/security/apt-simulation-cli.js +0 -278
  203. package/dist/security/apt-simulation-cli.js.map +0 -1
  204. package/dist/security/apt-simulation-engine-complete.d.ts +0 -97
  205. package/dist/security/apt-simulation-engine-complete.d.ts.map +0 -1
  206. package/dist/security/apt-simulation-engine-complete.js +0 -441
  207. package/dist/security/apt-simulation-engine-complete.js.map +0 -1
  208. package/dist/security/apt-simulation-engine.d.ts +0 -97
  209. package/dist/security/apt-simulation-engine.d.ts.map +0 -1
  210. package/dist/security/apt-simulation-engine.js +0 -441
  211. package/dist/security/apt-simulation-engine.js.map +0 -1
  212. package/dist/security/authorization.d.ts +0 -45
  213. package/dist/security/authorization.d.ts.map +0 -1
  214. package/dist/security/authorization.js +0 -128
  215. package/dist/security/authorization.js.map +0 -1
  216. package/dist/security/comprehensive-security-research.d.ts +0 -84
  217. package/dist/security/comprehensive-security-research.d.ts.map +0 -1
  218. package/dist/security/comprehensive-security-research.js +0 -211
  219. package/dist/security/comprehensive-security-research.js.map +0 -1
  220. package/dist/security/offensive/exploitationEngine.d.ts +0 -54
  221. package/dist/security/offensive/exploitationEngine.d.ts.map +0 -1
  222. package/dist/security/offensive/exploitationEngine.js +0 -263
  223. package/dist/security/offensive/exploitationEngine.js.map +0 -1
  224. package/dist/security/real/networkExploitation.d.ts +0 -92
  225. package/dist/security/real/networkExploitation.d.ts.map +0 -1
  226. package/dist/security/real/networkExploitation.js +0 -316
  227. package/dist/security/real/networkExploitation.js.map +0 -1
  228. package/dist/security/real/persistenceImplementation.d.ts +0 -62
  229. package/dist/security/real/persistenceImplementation.d.ts.map +0 -1
  230. package/dist/security/real/persistenceImplementation.js +0 -323
  231. package/dist/security/real/persistenceImplementation.js.map +0 -1
  232. package/dist/security/real/vulnerabilityScanner.d.ts +0 -73
  233. package/dist/security/real/vulnerabilityScanner.d.ts.map +0 -1
  234. package/dist/security/real/vulnerabilityScanner.js +0 -341
  235. package/dist/security/real/vulnerabilityScanner.js.map +0 -1
  236. package/dist/shell/capturePastePatch.d.ts +0 -9
  237. package/dist/shell/capturePastePatch.d.ts.map +0 -1
  238. package/dist/shell/capturePastePatch.js +0 -98
  239. package/dist/shell/capturePastePatch.js.map +0 -1
  240. package/dist/shell/enhancedInteractiveShell.d.ts +0 -90
  241. package/dist/shell/enhancedInteractiveShell.d.ts.map +0 -1
  242. package/dist/shell/enhancedInteractiveShell.js +0 -248
  243. package/dist/shell/enhancedInteractiveShell.js.map +0 -1
  244. package/dist/shell/inputProcessor.d.ts +0 -56
  245. package/dist/shell/inputProcessor.d.ts.map +0 -1
  246. package/dist/shell/inputProcessor.js +0 -172
  247. package/dist/shell/inputProcessor.js.map +0 -1
  248. package/dist/shell/interactiveShell-patch.d.ts +0 -27
  249. package/dist/shell/interactiveShell-patch.d.ts.map +0 -1
  250. package/dist/shell/interactiveShell-patch.js +0 -38
  251. package/dist/shell/interactiveShell-patch.js.map +0 -1
  252. package/dist/shell/interactiveShell-robust.d.ts +0 -26
  253. package/dist/shell/interactiveShell-robust.d.ts.map +0 -1
  254. package/dist/shell/interactiveShell-robust.js +0 -34
  255. package/dist/shell/interactiveShell-robust.js.map +0 -1
  256. package/dist/shell/multiLinePasteManager.d.ts +0 -106
  257. package/dist/shell/multiLinePasteManager.d.ts.map +0 -1
  258. package/dist/shell/multiLinePasteManager.js +0 -308
  259. package/dist/shell/multiLinePasteManager.js.map +0 -1
  260. package/dist/shell/processInputBlockPatch.d.ts +0 -8
  261. package/dist/shell/processInputBlockPatch.d.ts.map +0 -1
  262. package/dist/shell/processInputBlockPatch.js +0 -133
  263. package/dist/shell/processInputBlockPatch.js.map +0 -1
  264. package/dist/shell/unifiedInputProcessor.d.ts +0 -22
  265. package/dist/shell/unifiedInputProcessor.d.ts.map +0 -1
  266. package/dist/shell/unifiedInputProcessor.js +0 -78
  267. package/dist/shell/unifiedInputProcessor.js.map +0 -1
  268. package/dist/tools/enhancedSecurityTools.d.ts +0 -19
  269. package/dist/tools/enhancedSecurityTools.d.ts.map +0 -1
  270. package/dist/tools/enhancedSecurityTools.js +0 -215
  271. package/dist/tools/enhancedSecurityTools.js.map +0 -1
  272. package/dist/tools/offensiveSecurityTools.d.ts +0 -16
  273. package/dist/tools/offensiveSecurityTools.d.ts.map +0 -1
  274. package/dist/tools/offensiveSecurityTools.js +0 -285
  275. package/dist/tools/offensiveSecurityTools.js.map +0 -1
  276. package/dist/tools/realSecurityTools.d.ts +0 -18
  277. package/dist/tools/realSecurityTools.d.ts.map +0 -1
  278. package/dist/tools/realSecurityTools.js +0 -468
  279. package/dist/tools/realSecurityTools.js.map +0 -1
  280. package/dist/tools/securityTools.d.ts +0 -20
  281. package/dist/tools/securityTools.d.ts.map +0 -1
  282. package/dist/tools/securityTools.js +0 -449
  283. package/dist/tools/securityTools.js.map +0 -1
@@ -1,641 +0,0 @@
1
- import { readFileSync, existsSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import ts from 'typescript';
4
- export function createCodeAnalysisTools(workingDir) {
5
- return [
6
- {
7
- name: 'analyze_code_structure',
8
- description: 'Analyze TypeScript/JavaScript file structure and extract functions, classes, interfaces, imports, and exports',
9
- parameters: {
10
- type: 'object',
11
- properties: {
12
- path: {
13
- type: 'string',
14
- description: 'Path to the TypeScript/JavaScript file to analyze',
15
- },
16
- },
17
- required: ['path'],
18
- additionalProperties: false,
19
- },
20
- handler: async (args) => {
21
- try {
22
- const filePath = resolveFilePath(workingDir, args['path']);
23
- if (!existsSync(filePath)) {
24
- return `Error: File not found: ${filePath}`;
25
- }
26
- const content = readFileSync(filePath, 'utf-8');
27
- const analysis = analyzeTypeScriptFile(content, filePath);
28
- return formatAnalysisResults(analysis);
29
- }
30
- catch (error) {
31
- return formatHandlerError('analyzing file', error);
32
- }
33
- },
34
- },
35
- {
36
- name: 'find_dependencies',
37
- description: 'Find all dependencies and imports in a TypeScript/JavaScript file',
38
- parameters: {
39
- type: 'object',
40
- properties: {
41
- path: {
42
- type: 'string',
43
- description: 'Path to the TypeScript/JavaScript file',
44
- },
45
- },
46
- required: ['path'],
47
- additionalProperties: false,
48
- },
49
- handler: async (args) => {
50
- try {
51
- const filePath = resolveFilePath(workingDir, args['path']);
52
- if (!existsSync(filePath)) {
53
- return `Error: File not found: ${filePath}`;
54
- }
55
- const content = readFileSync(filePath, 'utf-8');
56
- const analysis = analyzeTypeScriptFile(content, filePath);
57
- return formatDependencies(analysis);
58
- }
59
- catch (error) {
60
- return formatHandlerError('analyzing dependencies', error);
61
- }
62
- },
63
- },
64
- {
65
- name: 'check_code_complexity',
66
- description: 'Analyze code complexity metrics (function length, parameter count, etc.)',
67
- parameters: {
68
- type: 'object',
69
- properties: {
70
- path: {
71
- type: 'string',
72
- description: 'Path to the TypeScript/JavaScript file',
73
- },
74
- },
75
- required: ['path'],
76
- additionalProperties: false,
77
- },
78
- handler: async (args) => {
79
- try {
80
- const filePath = resolveFilePath(workingDir, args['path']);
81
- if (!existsSync(filePath)) {
82
- return `Error: File not found: ${filePath}`;
83
- }
84
- const content = readFileSync(filePath, 'utf-8');
85
- const analysis = analyzeTypeScriptFile(content, filePath);
86
- return formatComplexityMetrics(analysis);
87
- }
88
- catch (error) {
89
- return formatHandlerError('analyzing complexity', error);
90
- }
91
- },
92
- },
93
- {
94
- name: 'advanced_ast_analysis',
95
- description: 'Perform AST-based analysis with cyclomatic complexity scoring, call graph construction, and potential hotspot detection.',
96
- parameters: {
97
- type: 'object',
98
- properties: {
99
- path: {
100
- type: 'string',
101
- description: 'Path to the TypeScript/JavaScript file to inspect',
102
- },
103
- },
104
- required: ['path'],
105
- additionalProperties: false,
106
- },
107
- handler: async (args) => {
108
- try {
109
- const filePath = resolveFilePath(workingDir, args['path']);
110
- if (!existsSync(filePath)) {
111
- return `Error: File not found: ${filePath}`;
112
- }
113
- const content = readFileSync(filePath, 'utf-8');
114
- const analysis = performAdvancedAstAnalysis(content, filePath);
115
- return formatAstAnalysis(analysis);
116
- }
117
- catch (error) {
118
- return formatHandlerError('performing AST analysis', error);
119
- }
120
- },
121
- },
122
- ];
123
- }
124
- function resolveFilePath(workingDir, path) {
125
- const normalized = validatePathArg(path);
126
- return normalized.startsWith('/') ? normalized : join(workingDir, normalized);
127
- }
128
- function validatePathArg(path) {
129
- if (typeof path !== 'string' || !path.trim()) {
130
- throw new Error('Path must be a non-empty string.');
131
- }
132
- return path.trim();
133
- }
134
- export function analyzeTypeScriptFile(content, filePath) {
135
- const lines = content.split('\n');
136
- const result = {
137
- file: filePath,
138
- functions: [],
139
- classes: [],
140
- interfaces: [],
141
- imports: [],
142
- exports: [],
143
- };
144
- lines.forEach((line, index) => {
145
- const lineNumber = index + 1;
146
- const trimmed = line.trim();
147
- // Parse imports
148
- if (trimmed.startsWith('import')) {
149
- const importInfo = parseImportStatement(trimmed, lineNumber);
150
- if (importInfo) {
151
- result.imports.push(importInfo);
152
- }
153
- }
154
- // Parse exports
155
- if (trimmed.startsWith('export')) {
156
- const exportInfo = parseExportStatement(trimmed, lineNumber);
157
- if (exportInfo) {
158
- result.exports.push(exportInfo);
159
- }
160
- }
161
- // Parse functions
162
- const functionMatch = trimmed.match(/^(?:export\s+)?(?:async\s+)?function\s+(\w+)\s*\(([^)]*)\)/);
163
- if (functionMatch) {
164
- const fnName = functionMatch[1] ?? '';
165
- const fnParams = functionMatch[2] ?? '';
166
- result.functions.push({
167
- name: fnName,
168
- line: lineNumber,
169
- parameters: parseParameters(fnParams),
170
- });
171
- }
172
- // Parse arrow functions
173
- const arrowFunctionMatch = trimmed.match(/^(?:export\s+)?(?:const|let|var)\s+(\w+)\s*=\s*(?:\(([^)]*)\)|(\w+))\s*=>/);
174
- if (arrowFunctionMatch) {
175
- const name = arrowFunctionMatch[1] ?? '';
176
- const params = arrowFunctionMatch[2] || arrowFunctionMatch[3] || '';
177
- result.functions.push({
178
- name,
179
- line: lineNumber,
180
- parameters: parseParameters(params),
181
- });
182
- }
183
- // Parse classes
184
- const classMatch = trimmed.match(/^(?:export\s+)?class\s+(\w+)/);
185
- if (classMatch) {
186
- const className = classMatch[1] ?? '';
187
- result.classes.push({
188
- name: className,
189
- line: lineNumber,
190
- methods: [],
191
- properties: [],
192
- });
193
- }
194
- // Parse interfaces
195
- const interfaceMatch = trimmed.match(/^(?:export\s+)?interface\s+(\w+)/);
196
- if (interfaceMatch) {
197
- const interfaceName = interfaceMatch[1] ?? '';
198
- result.interfaces.push({
199
- name: interfaceName,
200
- line: lineNumber,
201
- properties: [],
202
- methods: [],
203
- });
204
- }
205
- // Parse class methods and properties (simplified)
206
- if (trimmed.match(/^(?:public|private|protected|readonly)?\s*\w+\s*\([^)]*\)/)) {
207
- const methodMatch = trimmed.match(/^(?:public|private|protected)?\s*(\w+)\s*\(([^)]*)\)/);
208
- if (methodMatch && result.classes.length > 0) {
209
- const currentClass = result.classes[result.classes.length - 1];
210
- if (currentClass) {
211
- currentClass.methods.push({
212
- name: methodMatch[1] ?? '',
213
- line: lineNumber,
214
- parameters: parseParameters(methodMatch[2] ?? ''),
215
- });
216
- }
217
- }
218
- }
219
- // Parse interface properties
220
- if (trimmed.match(/^\w+\s*:/) && result.interfaces.length > 0) {
221
- const propMatch = trimmed.match(/^(\w+)\s*:/);
222
- if (propMatch) {
223
- const currentInterface = result.interfaces[result.interfaces.length - 1];
224
- if (currentInterface) {
225
- currentInterface.properties.push({
226
- name: propMatch[1] ?? '',
227
- line: lineNumber,
228
- });
229
- }
230
- }
231
- }
232
- });
233
- return result;
234
- }
235
- export function performAdvancedAstAnalysis(content, filePath) {
236
- const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true);
237
- const symbols = [];
238
- const callGraph = new Map();
239
- const issues = [];
240
- const symbolStack = [];
241
- const recordCall = (callee) => {
242
- if (!callee) {
243
- return;
244
- }
245
- const caller = symbolStack[symbolStack.length - 1];
246
- if (!caller) {
247
- return;
248
- }
249
- if (!callGraph.has(caller)) {
250
- callGraph.set(caller, new Map());
251
- }
252
- const targets = callGraph.get(caller);
253
- targets.set(callee, (targets.get(callee) ?? 0) + 1);
254
- };
255
- const registerSymbol = (info) => {
256
- symbols.push(info);
257
- if (info.statementCount > 50) {
258
- issues.push(`Large function detected: ${info.name} spans ${info.statementCount} statements.`);
259
- }
260
- if (info.cyclomaticComplexity > 10) {
261
- issues.push(`High complexity function: ${info.name} cyclomatic complexity is ${info.cyclomaticComplexity}.`);
262
- }
263
- };
264
- const visit = (node) => {
265
- if (ts.isFunctionDeclaration(node) && node.name) {
266
- const info = buildFunctionSymbol(node, node.name.text, 'function', sourceFile);
267
- registerSymbol(info);
268
- symbolStack.push(info.name);
269
- ts.forEachChild(node, visit);
270
- symbolStack.pop();
271
- return;
272
- }
273
- if (ts.isClassDeclaration(node) && node.name) {
274
- const info = buildClassSymbol(node, sourceFile);
275
- registerSymbol(info);
276
- ts.forEachChild(node, visit);
277
- return;
278
- }
279
- if ((ts.isMethodDeclaration(node) || ts.isGetAccessorDeclaration(node) || ts.isSetAccessorDeclaration(node)) &&
280
- ts.isClassLike(node.parent)) {
281
- const className = (node.parent.name && node.parent.name.getText(sourceFile)) || 'anonymous-class';
282
- const methodName = ts.isIdentifier(node.name) ? node.name.getText(sourceFile) : 'anonymous-method';
283
- const info = buildFunctionSymbol(node, `${className}.${methodName}`, 'method', sourceFile);
284
- registerSymbol(info);
285
- symbolStack.push(info.name);
286
- ts.forEachChild(node, visit);
287
- symbolStack.pop();
288
- return;
289
- }
290
- if (ts.isConstructorDeclaration(node) && ts.isClassLike(node.parent)) {
291
- const className = (node.parent.name && node.parent.name.getText(sourceFile)) || 'anonymous-class';
292
- const info = buildFunctionSymbol(node, `${className}.constructor`, 'method', sourceFile);
293
- registerSymbol(info);
294
- symbolStack.push(info.name);
295
- ts.forEachChild(node, visit);
296
- symbolStack.pop();
297
- return;
298
- }
299
- if (ts.isVariableDeclaration(node) &&
300
- node.initializer &&
301
- (ts.isArrowFunction(node.initializer) || ts.isFunctionExpression(node.initializer)) &&
302
- ts.isIdentifier(node.name)) {
303
- const kind = ts.isArrowFunction(node.initializer) ? 'arrow-function' : 'function';
304
- const info = buildFunctionSymbol(node.initializer, node.name.text, kind, sourceFile);
305
- registerSymbol(info);
306
- symbolStack.push(info.name);
307
- ts.forEachChild(node.initializer, visit);
308
- symbolStack.pop();
309
- return;
310
- }
311
- if (ts.isCallExpression(node) || ts.isNewExpression(node)) {
312
- const callee = extractCalleeName(node.expression);
313
- recordCall(callee);
314
- }
315
- ts.forEachChild(node, visit);
316
- };
317
- visit(sourceFile);
318
- const callGraphList = [];
319
- for (const [from, targets] of callGraph.entries()) {
320
- for (const [to, count] of targets.entries()) {
321
- callGraphList.push({ from, to, count });
322
- }
323
- }
324
- const totalCyclomaticComplexity = symbols.reduce((sum, symbol) => sum + symbol.cyclomaticComplexity, 0);
325
- return {
326
- file: filePath,
327
- symbols,
328
- callGraph: callGraphList,
329
- totalCyclomaticComplexity,
330
- issues,
331
- };
332
- }
333
- function buildFunctionSymbol(node, name, kind, sourceFile) {
334
- const startLine = sourceFile.getLineAndCharacterOfPosition(node.getStart()).line + 1;
335
- const endLine = sourceFile.getLineAndCharacterOfPosition(node.end).line + 1;
336
- const statementCount = countStatements(node);
337
- const cyclomaticComplexity = estimateCyclomaticComplexity(node);
338
- const parameters = node.parameters?.map((param) => param.name.getText(sourceFile)) ?? [];
339
- return {
340
- name,
341
- kind,
342
- startLine,
343
- endLine,
344
- parameters,
345
- statementCount,
346
- cyclomaticComplexity,
347
- };
348
- }
349
- function buildClassSymbol(node, sourceFile) {
350
- const name = (node.name && node.name.getText(sourceFile)) || 'AnonymousClass';
351
- const startLine = sourceFile.getLineAndCharacterOfPosition(node.getStart()).line + 1;
352
- const endLine = sourceFile.getLineAndCharacterOfPosition(node.end).line + 1;
353
- const statementCount = node.members.length;
354
- const cyclomaticComplexity = node.members.reduce((sum, member) => {
355
- if (ts.isMethodDeclaration(member) ||
356
- ts.isConstructorDeclaration(member) ||
357
- ts.isGetAccessorDeclaration(member) ||
358
- ts.isSetAccessorDeclaration(member)) {
359
- return sum + estimateCyclomaticComplexity(member);
360
- }
361
- return sum;
362
- }, 1);
363
- return {
364
- name,
365
- kind: 'class',
366
- startLine,
367
- endLine,
368
- parameters: [],
369
- statementCount,
370
- cyclomaticComplexity,
371
- };
372
- }
373
- function countStatements(node) {
374
- const body = node.body;
375
- if (!body) {
376
- return 0;
377
- }
378
- if (ts.isBlock(body)) {
379
- return body.statements.length;
380
- }
381
- return 1;
382
- }
383
- function estimateCyclomaticComplexity(node) {
384
- let complexity = 1;
385
- const visit = (child) => {
386
- if (ts.isIfStatement(child) ||
387
- ts.isForStatement(child) ||
388
- ts.isWhileStatement(child) ||
389
- ts.isForOfStatement(child) ||
390
- ts.isForInStatement(child) ||
391
- ts.isCaseClause(child) ||
392
- ts.isCatchClause(child)) {
393
- complexity += 1;
394
- }
395
- else if (ts.isConditionalExpression(child)) {
396
- complexity += 1;
397
- }
398
- else if (ts.isBinaryExpression(child) &&
399
- (child.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken ||
400
- child.operatorToken.kind === ts.SyntaxKind.BarBarToken)) {
401
- complexity += 1;
402
- }
403
- ts.forEachChild(child, visit);
404
- };
405
- ts.forEachChild(node, visit);
406
- return complexity;
407
- }
408
- function extractCalleeName(expression) {
409
- if (!expression) {
410
- return null;
411
- }
412
- if (ts.isIdentifier(expression)) {
413
- return expression.text;
414
- }
415
- if (ts.isPropertyAccessExpression(expression)) {
416
- return expression.name.text;
417
- }
418
- return null;
419
- }
420
- function formatAstAnalysis(result) {
421
- const output = [];
422
- output.push(`# Advanced AST Analysis: ${result.file}`);
423
- output.push('');
424
- output.push('## Symbol Metrics');
425
- if (result.symbols.length === 0) {
426
- output.push('No functions or classes detected.');
427
- }
428
- else {
429
- const sorted = [...result.symbols].sort((a, b) => b.cyclomaticComplexity - a.cyclomaticComplexity);
430
- for (const symbol of sorted) {
431
- output.push(`- ${symbol.name} (${symbol.kind}) lines ${symbol.startLine}-${symbol.endLine} | statements: ${symbol.statementCount} | CC: ${symbol.cyclomaticComplexity} | params: ${symbol.parameters.join(', ') || 'none'}`);
432
- }
433
- }
434
- output.push('');
435
- output.push('## Call Graph');
436
- if (result.callGraph.length === 0) {
437
- output.push('No function-to-function calls detected.');
438
- }
439
- else {
440
- for (const edge of result.callGraph) {
441
- output.push(`- ${edge.from} → ${edge.to} (x${edge.count})`);
442
- }
443
- }
444
- output.push('');
445
- output.push('## Hotspot Alerts');
446
- if (result.issues.length === 0) {
447
- output.push('No hotspots detected.');
448
- }
449
- else {
450
- for (const issue of result.issues) {
451
- output.push(`- ${issue}`);
452
- }
453
- }
454
- output.push('');
455
- const averageComplexity = result.symbols.length === 0 ? 0 : result.totalCyclomaticComplexity / result.symbols.length;
456
- output.push('## Aggregate Metrics');
457
- output.push(`- Total symbols analyzed: ${result.symbols.length}`);
458
- output.push(`- Total cyclomatic complexity: ${result.totalCyclomaticComplexity}`);
459
- output.push(`- Average cyclomatic complexity: ${averageComplexity.toFixed(2)}`);
460
- return output.join('\n');
461
- }
462
- function formatHandlerError(task, error) {
463
- const message = error instanceof Error ? error.message : String(error);
464
- return `Error ${task}: ${message}`;
465
- }
466
- function parseImportStatement(line, lineNumber) {
467
- // Simple import parsing - can be enhanced with proper AST parsing
468
- const importMatch = line.match(/import\s+(?:\*\s+as\s+(\w+)|\{([^}]+)\}|(\w+))\s+from\s+['"]([^'"]+)['"]/);
469
- if (importMatch) {
470
- let specifiers = [];
471
- if (importMatch[1]) {
472
- // namespace import
473
- specifiers = [`* as ${importMatch[1]}`];
474
- }
475
- else if (importMatch[2]) {
476
- // named imports
477
- specifiers = importMatch[2].split(',').map(s => s.trim()).filter(Boolean);
478
- }
479
- else if (importMatch[3]) {
480
- // default import
481
- specifiers = [importMatch[3]];
482
- }
483
- return {
484
- source: importMatch[4] ?? '',
485
- specifiers,
486
- line: lineNumber,
487
- };
488
- }
489
- return null;
490
- }
491
- function parseExportStatement(line, lineNumber) {
492
- if (line.includes('export default')) {
493
- const defaultMatch = line.match(/export\s+default\s+(\w+)/);
494
- if (defaultMatch) {
495
- return {
496
- name: defaultMatch[1] ?? '',
497
- type: 'default',
498
- line: lineNumber,
499
- };
500
- }
501
- }
502
- else if (line.includes('export {')) {
503
- const namedMatch = line.match(/export\s+\{\s*([^}]+)\s*\}/);
504
- if (namedMatch) {
505
- return {
506
- name: namedMatch[1] ?? '',
507
- type: 'named',
508
- line: lineNumber,
509
- };
510
- }
511
- }
512
- else {
513
- const exportMatch = line.match(/export\s+(?:class|function|interface|const|let|var)\s+(\w+)/);
514
- if (exportMatch) {
515
- return {
516
- name: exportMatch[1] ?? '',
517
- type: 'named',
518
- line: lineNumber,
519
- };
520
- }
521
- }
522
- return null;
523
- }
524
- function parseParameters(paramString) {
525
- return paramString
526
- .split(',')
527
- .map((p) => p.trim())
528
- .filter((p) => p.length > 0)
529
- .map((p) => {
530
- // Extract parameter name (ignore types for now)
531
- const nameMatch = p.match(/^(\w+)(?:\s*:\s*[^,]+)?$/);
532
- return nameMatch?.[1] ?? p;
533
- });
534
- }
535
- function formatAnalysisResults(analysis) {
536
- const output = [];
537
- output.push(`# Code Analysis: ${analysis.file}`);
538
- output.push('');
539
- if (analysis.imports.length > 0) {
540
- output.push('## Imports');
541
- analysis.imports.forEach(imp => {
542
- output.push(`- Line ${imp.line}: from "${imp.source}"`);
543
- if (imp.specifiers.length > 0) {
544
- output.push(` ${imp.specifiers.join(', ')}`);
545
- }
546
- });
547
- output.push('');
548
- }
549
- if (analysis.exports.length > 0) {
550
- output.push('## Exports');
551
- analysis.exports.forEach(exp => {
552
- output.push(`- Line ${exp.line}: ${exp.type} ${exp.name}`);
553
- });
554
- output.push('');
555
- }
556
- if (analysis.functions.length > 0) {
557
- output.push('## Functions');
558
- analysis.functions.forEach(func => {
559
- output.push(`- Line ${func.line}: ${func.name}(${func.parameters.join(', ')})`);
560
- });
561
- output.push('');
562
- }
563
- if (analysis.classes.length > 0) {
564
- output.push('## Classes');
565
- analysis.classes.forEach(cls => {
566
- output.push(`- Line ${cls.line}: ${cls.name}`);
567
- if (cls.methods.length > 0) {
568
- output.push(` Methods: ${cls.methods.map(m => m.name).join(', ')}`);
569
- }
570
- if (cls.properties.length > 0) {
571
- output.push(` Properties: ${cls.properties.map(p => p.name).join(', ')}`);
572
- }
573
- });
574
- output.push('');
575
- }
576
- if (analysis.interfaces.length > 0) {
577
- output.push('## Interfaces');
578
- analysis.interfaces.forEach(intf => {
579
- output.push(`- Line ${intf.line}: ${intf.name}`);
580
- if (intf.properties.length > 0) {
581
- output.push(` Properties: ${intf.properties.map(p => p.name).join(', ')}`);
582
- }
583
- if (intf.methods.length > 0) {
584
- output.push(` Methods: ${intf.methods.map(m => m.name).join(', ')}`);
585
- }
586
- });
587
- output.push('');
588
- }
589
- return output.join('\n');
590
- }
591
- function formatDependencies(analysis) {
592
- const output = [];
593
- output.push(`# Dependencies: ${analysis.file}`);
594
- output.push('');
595
- if (analysis.imports.length > 0) {
596
- output.push('## Imported Modules');
597
- analysis.imports.forEach(imp => {
598
- output.push(`- ${imp.source}`);
599
- if (imp.specifiers.length > 0) {
600
- output.push(` Used: ${imp.specifiers.join(', ')}`);
601
- }
602
- });
603
- }
604
- else {
605
- output.push('No imports found.');
606
- }
607
- return output.join('\n');
608
- }
609
- function formatComplexityMetrics(analysis) {
610
- const output = [];
611
- output.push(`# Code Complexity: ${analysis.file}`);
612
- output.push('');
613
- // Function complexity
614
- if (analysis.functions.length > 0) {
615
- output.push('## Function Complexity');
616
- analysis.functions.forEach(func => {
617
- const paramCount = func.parameters.length;
618
- const complexity = paramCount > 3 ? 'High' : paramCount > 1 ? 'Medium' : 'Low';
619
- output.push(`- ${func.name}: ${paramCount} parameters (${complexity})`);
620
- });
621
- }
622
- // Class complexity
623
- if (analysis.classes.length > 0) {
624
- output.push('## Class Complexity');
625
- analysis.classes.forEach(cls => {
626
- const methodCount = cls.methods.length;
627
- const propCount = cls.properties.length;
628
- const complexity = methodCount + propCount > 5 ? 'High' : methodCount + propCount > 2 ? 'Medium' : 'Low';
629
- output.push(`- ${cls.name}: ${methodCount} methods, ${propCount} properties (${complexity})`);
630
- });
631
- }
632
- // Overall metrics
633
- output.push('');
634
- output.push('## Overall Metrics');
635
- output.push(`- Total functions: ${analysis.functions.length}`);
636
- output.push(`- Total classes: ${analysis.classes.length}`);
637
- output.push(`- Total interfaces: ${analysis.interfaces.length}`);
638
- output.push(`- Total imports: ${analysis.imports.length}`);
639
- output.push(`- Total exports: ${analysis.exports.length}`);
640
- return output.join('\n');
641
- }