erosolar-cli 1.5.2 → 1.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config/security-deployment.json +54 -0
- package/dist/bin/adapters/node/index.js +33 -0
- package/dist/bin/adapters/types.js +1 -0
- package/dist/bin/alpha-zero/agentWrapper.js +165 -0
- package/dist/bin/alpha-zero/codeEvaluator.js +272 -0
- package/dist/bin/alpha-zero/competitiveRunner.js +219 -0
- package/dist/bin/alpha-zero/index.js +98 -0
- package/dist/bin/alpha-zero/introspection.js +298 -0
- package/dist/bin/alpha-zero/metricsTracker.js +207 -0
- package/dist/bin/alpha-zero/security/core.js +269 -0
- package/dist/bin/alpha-zero/security/google.js +308 -0
- package/dist/bin/alpha-zero/security/googleLoader.js +40 -0
- package/dist/bin/alpha-zero/security/index.js +31 -0
- package/dist/bin/alpha-zero/security/simulation.js +274 -0
- package/dist/bin/alpha-zero/selfModification.js +231 -0
- package/dist/bin/alpha-zero/types.js +30 -0
- package/dist/bin/bin/erosolar-optimized.js +205 -0
- package/dist/bin/capabilities/agentSpawningCapability.js +116 -0
- package/dist/bin/capabilities/bashCapability.js +22 -0
- package/dist/bin/capabilities/cloudCapability.js +36 -0
- package/dist/bin/capabilities/codeAnalysisCapability.js +22 -0
- package/dist/bin/capabilities/codeQualityCapability.js +23 -0
- package/dist/bin/capabilities/dependencySecurityCapability.js +22 -0
- package/dist/bin/capabilities/devCapability.js +22 -0
- package/dist/bin/capabilities/editCapability.js +28 -0
- package/dist/bin/capabilities/emailCapability.js +20 -0
- package/dist/bin/capabilities/enhancedGitCapability.js +221 -0
- package/dist/bin/capabilities/filesystemCapability.js +22 -0
- package/dist/bin/capabilities/globCapability.js +28 -0
- package/dist/bin/capabilities/interactionCapability.js +20 -0
- package/dist/bin/capabilities/learnCapability.js +22 -0
- package/dist/bin/capabilities/mcpCapability.js +20 -0
- package/dist/bin/capabilities/notebookCapability.js +28 -0
- package/dist/bin/capabilities/planningCapability.js +27 -0
- package/dist/bin/capabilities/refactoringCapability.js +23 -0
- package/dist/bin/capabilities/repoChecksCapability.js +22 -0
- package/dist/bin/capabilities/searchCapability.js +22 -0
- package/dist/bin/capabilities/skillCapability.js +76 -0
- package/dist/bin/capabilities/taskManagementCapability.js +20 -0
- package/dist/bin/capabilities/testingCapability.js +23 -0
- package/dist/bin/capabilities/toolManifest.js +159 -0
- package/dist/bin/capabilities/toolRegistry.js +114 -0
- package/dist/bin/capabilities/webCapability.js +20 -0
- package/dist/bin/config.js +139 -0
- package/dist/bin/contracts/v1/agent.js +7 -0
- package/dist/bin/contracts/v1/agentProfileManifest.js +8 -0
- package/dist/bin/contracts/v1/agentRules.js +9 -0
- package/dist/bin/contracts/v1/toolAccess.js +8 -0
- package/dist/bin/core/agent.js +362 -0
- package/dist/bin/core/agentProfileManifest.js +187 -0
- package/dist/bin/core/agentProfiles.js +34 -0
- package/dist/bin/core/agentRulebook.js +135 -0
- package/dist/bin/core/agentSchemaLoader.js +233 -0
- package/dist/bin/core/contextManager.js +412 -0
- package/dist/bin/core/contextWindow.js +122 -0
- package/dist/bin/core/customCommands.js +80 -0
- package/dist/bin/core/errors/apiKeyErrors.js +114 -0
- package/dist/bin/core/errors/errorTypes.js +340 -0
- package/dist/bin/core/errors/safetyValidator.js +304 -0
- package/dist/bin/core/errors.js +32 -0
- package/dist/bin/core/modelDiscovery.js +755 -0
- package/dist/bin/core/preferences.js +224 -0
- package/dist/bin/core/schemaValidator.js +92 -0
- package/dist/bin/core/secretStore.js +199 -0
- package/dist/bin/core/sessionStore.js +187 -0
- package/dist/bin/core/toolRuntime.js +290 -0
- package/dist/bin/core/types.js +1 -0
- package/dist/bin/erosolar-optimized.d.ts +12 -0
- package/dist/bin/erosolar-optimized.d.ts.map +1 -0
- package/dist/bin/erosolar-optimized.js +239 -0
- package/dist/bin/erosolar-optimized.js.map +1 -0
- package/dist/bin/erosolar.js +14 -0
- package/dist/bin/erosolar.js.map +1 -1
- package/dist/bin/headless/headlessApp.js +172 -0
- package/dist/bin/mcp/config.js +202 -0
- package/dist/bin/mcp/stdioClient.js +172 -0
- package/dist/bin/mcp/toolBridge.js +104 -0
- package/dist/bin/mcp/types.js +1 -0
- package/dist/bin/plugins/index.js +113 -0
- package/dist/bin/plugins/providers/anthropic/index.js +25 -0
- package/dist/bin/plugins/providers/deepseek/index.js +24 -0
- package/dist/bin/plugins/providers/google/index.js +26 -0
- package/dist/bin/plugins/providers/index.js +19 -0
- package/dist/bin/plugins/providers/ollama/index.js +59 -0
- package/dist/bin/plugins/providers/openai/index.js +26 -0
- package/dist/bin/plugins/providers/xai/index.js +24 -0
- package/dist/bin/plugins/tools/agentSpawning/agentSpawningPlugin.js +8 -0
- package/dist/bin/plugins/tools/bash/localBashPlugin.js +13 -0
- package/dist/bin/plugins/tools/checks/localRepoChecksPlugin.js +13 -0
- package/dist/bin/plugins/tools/cloud/cloudPlugin.js +13 -0
- package/dist/bin/plugins/tools/codeAnalysis/codeAnalysisPlugin.js +13 -0
- package/dist/bin/plugins/tools/codeQuality/codeQualityPlugin.js +13 -0
- package/dist/bin/plugins/tools/dependency/dependencyPlugin.js +11 -0
- package/dist/bin/plugins/tools/development/devPlugin.js +13 -0
- package/dist/bin/plugins/tools/edit/editPlugin.js +14 -0
- package/dist/bin/plugins/tools/email/emailPlugin.js +11 -0
- package/dist/bin/plugins/tools/enhancedGit/enhancedGitPlugin.js +8 -0
- package/dist/bin/plugins/tools/filesystem/localFilesystemPlugin.js +13 -0
- package/dist/bin/plugins/tools/glob/globPlugin.js +14 -0
- package/dist/bin/plugins/tools/index.js +2 -0
- package/dist/bin/plugins/tools/interaction/interactionPlugin.js +11 -0
- package/dist/bin/plugins/tools/learn/learnPlugin.js +13 -0
- package/dist/bin/plugins/tools/mcp/mcpPlugin.js +8 -0
- package/dist/bin/plugins/tools/nodeDefaults.js +56 -0
- package/dist/bin/plugins/tools/notebook/notebookPlugin.js +14 -0
- package/dist/bin/plugins/tools/planning/planningPlugin.js +14 -0
- package/dist/bin/plugins/tools/refactoring/refactoringPlugin.js +11 -0
- package/dist/bin/plugins/tools/registry.js +57 -0
- package/dist/bin/plugins/tools/search/localSearchPlugin.js +13 -0
- package/dist/bin/plugins/tools/skills/skillPlugin.js +8 -0
- package/dist/bin/plugins/tools/taskManagement/taskManagementPlugin.js +11 -0
- package/dist/bin/plugins/tools/testing/testingPlugin.js +11 -0
- package/dist/bin/plugins/tools/web/webPlugin.js +11 -0
- package/dist/bin/providers/anthropicProvider.js +329 -0
- package/dist/bin/providers/googleProvider.js +203 -0
- package/dist/bin/providers/openaiChatCompletionsProvider.js +208 -0
- package/dist/bin/providers/openaiResponsesProvider.js +249 -0
- package/dist/bin/providers/providerFactory.js +24 -0
- package/dist/bin/runtime/agentController.js +321 -0
- package/dist/bin/runtime/agentHost.js +153 -0
- package/dist/bin/runtime/agentSession.js +195 -0
- package/dist/bin/runtime/node.js +10 -0
- package/dist/bin/runtime/universal.js +28 -0
- package/dist/bin/shell/bracketedPasteManager.js +350 -0
- package/dist/bin/shell/fileChangeTracker.js +65 -0
- package/dist/bin/shell/interactiveShell.js +2908 -0
- package/dist/bin/shell/liveStatus.js +78 -0
- package/dist/bin/shell/shellApp.js +290 -0
- package/dist/bin/shell/systemPrompt.js +60 -0
- package/dist/bin/shell/updateManager.js +108 -0
- package/dist/bin/skills/skillRepository.js +236 -0
- package/dist/bin/skills/types.js +1 -0
- package/dist/bin/subagents/taskRunner.js +269 -0
- package/dist/bin/tools/backgroundBashTools.js +211 -0
- package/dist/bin/tools/bashTools.js +159 -0
- package/dist/bin/tools/cloudTools.js +864 -0
- package/dist/bin/tools/codeAnalysisTools.js +641 -0
- package/dist/bin/tools/codeQualityTools.js +294 -0
- package/dist/bin/tools/dependencyTools.js +282 -0
- package/dist/bin/tools/devTools.js +238 -0
- package/dist/bin/tools/diffUtils.js +137 -0
- package/dist/bin/tools/editTools.js +134 -0
- package/dist/bin/tools/emailTools.js +448 -0
- package/dist/bin/tools/fileTools.js +282 -0
- package/dist/bin/tools/globTools.js +173 -0
- package/dist/bin/tools/grepTools.js +332 -0
- package/dist/bin/tools/interactionTools.js +170 -0
- package/dist/bin/tools/learnTools.js +1818 -0
- package/dist/bin/tools/notebookEditTools.js +196 -0
- package/dist/bin/tools/planningTools.js +46 -0
- package/dist/bin/tools/refactoringTools.js +293 -0
- package/dist/bin/tools/repoChecksTools.js +160 -0
- package/dist/bin/tools/searchTools.js +206 -0
- package/dist/bin/tools/skillTools.js +177 -0
- package/dist/bin/tools/taskManagementTools.js +156 -0
- package/dist/bin/tools/testingTools.js +232 -0
- package/dist/bin/tools/webTools.js +480 -0
- package/dist/bin/ui/ShellUIAdapter.js +459 -0
- package/dist/bin/ui/UnifiedUIController.js +183 -0
- package/dist/bin/ui/animation/AnimationScheduler.js +430 -0
- package/dist/bin/ui/codeHighlighter.js +854 -0
- package/dist/bin/ui/designSystem.js +121 -0
- package/dist/bin/ui/display.js +1222 -0
- package/dist/bin/ui/interrupts/InterruptManager.js +437 -0
- package/dist/bin/ui/layout.js +139 -0
- package/dist/bin/ui/orchestration/StatusOrchestrator.js +403 -0
- package/dist/bin/ui/outputMode.js +38 -0
- package/dist/bin/ui/persistentPrompt.js +183 -0
- package/dist/bin/ui/richText.js +338 -0
- package/dist/bin/ui/shortcutsHelp.js +87 -0
- package/dist/bin/ui/telemetry/UITelemetry.js +443 -0
- package/dist/bin/ui/textHighlighter.js +210 -0
- package/dist/bin/ui/theme.js +116 -0
- package/dist/bin/ui/toolDisplay.js +423 -0
- package/dist/bin/ui/toolDisplayAdapter.js +357 -0
- package/dist/bin/workspace.js +106 -0
- package/dist/bin/workspace.validator.js +213 -0
- package/dist/capabilities/cloudCapability.d.ts +13 -0
- package/dist/capabilities/cloudCapability.d.ts.map +1 -0
- package/dist/capabilities/cloudCapability.js +38 -0
- package/dist/capabilities/cloudCapability.js.map +1 -0
- package/dist/capabilities/index.d.ts +1 -0
- package/dist/capabilities/index.d.ts.map +1 -1
- package/dist/capabilities/index.js +1 -0
- package/dist/capabilities/index.js.map +1 -1
- package/dist/capabilities/offensiveSecurityCapability.d.ts +26 -0
- package/dist/capabilities/offensiveSecurityCapability.d.ts.map +1 -0
- package/dist/capabilities/offensiveSecurityCapability.js +58 -0
- package/dist/capabilities/offensiveSecurityCapability.js.map +1 -0
- package/dist/capabilities/realSecurityCapability.d.ts +26 -0
- package/dist/capabilities/realSecurityCapability.d.ts.map +1 -0
- package/dist/capabilities/realSecurityCapability.js +53 -0
- package/dist/capabilities/realSecurityCapability.js.map +1 -0
- package/dist/capabilities/securityCapability.d.ts +32 -0
- package/dist/capabilities/securityCapability.d.ts.map +1 -0
- package/dist/capabilities/securityCapability.js +57 -0
- package/dist/capabilities/securityCapability.js.map +1 -0
- package/dist/capabilities/ultimateSecurityCapability.d.ts +42 -0
- package/dist/capabilities/ultimateSecurityCapability.d.ts.map +1 -0
- package/dist/capabilities/ultimateSecurityCapability.js +96 -0
- package/dist/capabilities/ultimateSecurityCapability.js.map +1 -0
- package/dist/core/LazyLoader.d.ts +129 -0
- package/dist/core/LazyLoader.d.ts.map +1 -0
- package/dist/core/LazyLoader.js +240 -0
- package/dist/core/LazyLoader.js.map +1 -0
- package/dist/core/intelligenceTools.d.ts +19 -0
- package/dist/core/intelligenceTools.d.ts.map +1 -0
- package/dist/core/intelligenceTools.js +453 -0
- package/dist/core/intelligenceTools.js.map +1 -0
- package/dist/core/operationalTools.d.ts +19 -0
- package/dist/core/operationalTools.d.ts.map +1 -0
- package/dist/core/operationalTools.js +467 -0
- package/dist/core/operationalTools.js.map +1 -0
- package/dist/offensive/core/offensive-engine.d.ts +171 -0
- package/dist/offensive/core/offensive-engine.d.ts.map +1 -0
- package/dist/offensive/core/offensive-engine.js +345 -0
- package/dist/offensive/core/offensive-engine.js.map +1 -0
- package/dist/offensive/core/offensive-integration.d.ts +129 -0
- package/dist/offensive/core/offensive-integration.d.ts.map +1 -0
- package/dist/offensive/core/offensive-integration.js +364 -0
- package/dist/offensive/core/offensive-integration.js.map +1 -0
- package/dist/offensive/core/offensive-tools.d.ts +55 -0
- package/dist/offensive/core/offensive-tools.d.ts.map +1 -0
- package/dist/offensive/core/offensive-tools.js +438 -0
- package/dist/offensive/core/offensive-tools.js.map +1 -0
- package/dist/offensive/offensive-cli.d.ts +48 -0
- package/dist/offensive/offensive-cli.d.ts.map +1 -0
- package/dist/offensive/offensive-cli.js +233 -0
- package/dist/offensive/offensive-cli.js.map +1 -0
- package/dist/plugins/index.d.ts +1 -1
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +2 -0
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/tools/cloud/cloudPlugin.d.ts +3 -0
- package/dist/plugins/tools/cloud/cloudPlugin.d.ts.map +1 -0
- package/dist/plugins/tools/cloud/cloudPlugin.js +14 -0
- package/dist/plugins/tools/cloud/cloudPlugin.js.map +1 -0
- package/dist/plugins/tools/nodeDefaults.d.ts.map +1 -1
- package/dist/plugins/tools/nodeDefaults.js +2 -0
- package/dist/plugins/tools/nodeDefaults.js.map +1 -1
- package/dist/security/advanced-persistence-research.d.ts +92 -0
- package/dist/security/advanced-persistence-research.d.ts.map +1 -0
- package/dist/security/advanced-persistence-research.js +195 -0
- package/dist/security/advanced-persistence-research.js.map +1 -0
- package/dist/security/apt-simulation-cli.d.ts +57 -0
- package/dist/security/apt-simulation-cli.d.ts.map +1 -0
- package/dist/security/apt-simulation-cli.js +278 -0
- package/dist/security/apt-simulation-cli.js.map +1 -0
- package/dist/security/apt-simulation-engine-complete.d.ts +97 -0
- package/dist/security/apt-simulation-engine-complete.d.ts.map +1 -0
- package/dist/security/apt-simulation-engine-complete.js +441 -0
- package/dist/security/apt-simulation-engine-complete.js.map +1 -0
- package/dist/security/apt-simulation-engine.d.ts +97 -0
- package/dist/security/apt-simulation-engine.d.ts.map +1 -0
- package/dist/security/apt-simulation-engine.js +441 -0
- package/dist/security/apt-simulation-engine.js.map +1 -0
- package/dist/security/assessment/vulnerabilityAssessment.d.ts +104 -0
- package/dist/security/assessment/vulnerabilityAssessment.d.ts.map +1 -0
- package/dist/security/assessment/vulnerabilityAssessment.js +315 -0
- package/dist/security/assessment/vulnerabilityAssessment.js.map +1 -0
- package/dist/security/authorization/securityAuthorization.d.ts +88 -0
- package/dist/security/authorization/securityAuthorization.d.ts.map +1 -0
- package/dist/security/authorization/securityAuthorization.js +172 -0
- package/dist/security/authorization/securityAuthorization.js.map +1 -0
- package/dist/security/authorization.d.ts +45 -0
- package/dist/security/authorization.d.ts.map +1 -0
- package/dist/security/authorization.js +128 -0
- package/dist/security/authorization.js.map +1 -0
- package/dist/security/comprehensive-security-research.d.ts +84 -0
- package/dist/security/comprehensive-security-research.d.ts.map +1 -0
- package/dist/security/comprehensive-security-research.js +211 -0
- package/dist/security/comprehensive-security-research.js.map +1 -0
- package/dist/security/offensive/exploitationEngine.d.ts +54 -0
- package/dist/security/offensive/exploitationEngine.d.ts.map +1 -0
- package/dist/security/offensive/exploitationEngine.js +263 -0
- package/dist/security/offensive/exploitationEngine.js.map +1 -0
- package/dist/security/persistence-analyzer.d.ts +56 -0
- package/dist/security/persistence-analyzer.d.ts.map +1 -0
- package/dist/security/persistence-analyzer.js +187 -0
- package/dist/security/persistence-analyzer.js.map +1 -0
- package/dist/security/persistence-cli.d.ts +36 -0
- package/dist/security/persistence-cli.d.ts.map +1 -0
- package/dist/security/persistence-cli.js +160 -0
- package/dist/security/persistence-cli.js.map +1 -0
- package/dist/security/persistence-research.d.ts +100 -0
- package/dist/security/persistence-research.d.ts.map +1 -0
- package/dist/security/persistence-research.js +372 -0
- package/dist/security/persistence-research.js.map +1 -0
- package/dist/security/real/networkExploitation.d.ts +92 -0
- package/dist/security/real/networkExploitation.d.ts.map +1 -0
- package/dist/security/real/networkExploitation.js +316 -0
- package/dist/security/real/networkExploitation.js.map +1 -0
- package/dist/security/real/persistenceImplementation.d.ts +62 -0
- package/dist/security/real/persistenceImplementation.d.ts.map +1 -0
- package/dist/security/real/persistenceImplementation.js +323 -0
- package/dist/security/real/persistenceImplementation.js.map +1 -0
- package/dist/security/real/vulnerabilityScanner.d.ts +73 -0
- package/dist/security/real/vulnerabilityScanner.d.ts.map +1 -0
- package/dist/security/real/vulnerabilityScanner.js +341 -0
- package/dist/security/real/vulnerabilityScanner.js.map +1 -0
- package/dist/security/research/persistenceResearch.d.ts +97 -0
- package/dist/security/research/persistenceResearch.d.ts.map +1 -0
- package/dist/security/research/persistenceResearch.js +282 -0
- package/dist/security/research/persistenceResearch.js.map +1 -0
- package/dist/security/security-testing-framework.d.ts +120 -0
- package/dist/security/security-testing-framework.d.ts.map +1 -0
- package/dist/security/security-testing-framework.js +372 -0
- package/dist/security/security-testing-framework.js.map +1 -0
- package/dist/security/simulation/attackSimulation.d.ts +93 -0
- package/dist/security/simulation/attackSimulation.d.ts.map +1 -0
- package/dist/security/simulation/attackSimulation.js +341 -0
- package/dist/security/simulation/attackSimulation.js.map +1 -0
- package/dist/shell/bracketedPasteManager.d.ts +76 -0
- package/dist/shell/bracketedPasteManager.d.ts.map +1 -1
- package/dist/shell/bracketedPasteManager.js +267 -9
- package/dist/shell/bracketedPasteManager.js.map +1 -1
- package/dist/shell/interactiveShell.d.ts +34 -1
- package/dist/shell/interactiveShell.d.ts.map +1 -1
- package/dist/shell/interactiveShell.js +304 -24
- package/dist/shell/interactiveShell.js.map +1 -1
- package/dist/shell/taskCompletionDetector.d.ts +101 -0
- package/dist/shell/taskCompletionDetector.d.ts.map +1 -0
- package/dist/shell/taskCompletionDetector.js +343 -0
- package/dist/shell/taskCompletionDetector.js.map +1 -0
- package/dist/tools/cloudTools.d.ts +57 -0
- package/dist/tools/cloudTools.d.ts.map +1 -0
- package/dist/tools/cloudTools.js +865 -0
- package/dist/tools/cloudTools.js.map +1 -0
- package/dist/tools/enhancedSecurityTools.d.ts +19 -0
- package/dist/tools/enhancedSecurityTools.d.ts.map +1 -0
- package/dist/tools/enhancedSecurityTools.js +215 -0
- package/dist/tools/enhancedSecurityTools.js.map +1 -0
- package/dist/tools/offensiveSecurityTools.d.ts +16 -0
- package/dist/tools/offensiveSecurityTools.d.ts.map +1 -0
- package/dist/tools/offensiveSecurityTools.js +285 -0
- package/dist/tools/offensiveSecurityTools.js.map +1 -0
- package/dist/tools/realSecurityTools.d.ts +18 -0
- package/dist/tools/realSecurityTools.d.ts.map +1 -0
- package/dist/tools/realSecurityTools.js +468 -0
- package/dist/tools/realSecurityTools.js.map +1 -0
- package/dist/tools/securityTools.d.ts +20 -0
- package/dist/tools/securityTools.d.ts.map +1 -0
- package/dist/tools/securityTools.js +449 -0
- package/dist/tools/securityTools.js.map +1 -0
- package/package.json +27 -12
- package/scripts/deploy-security-capabilities.js +178 -0
|
@@ -0,0 +1,641 @@
|
|
|
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
|
+
}
|