erosolar-cli 1.7.55 → 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 (273) hide show
  1. package/package.json +1 -1
  2. package/dist/active-stack-security.d.ts +0 -110
  3. package/dist/active-stack-security.js +0 -313
  4. package/dist/active-stack-security.js.map +0 -1
  5. package/dist/advanced-targeting.d.ts +0 -113
  6. package/dist/advanced-targeting.js +0 -252
  7. package/dist/advanced-targeting.js.map +0 -1
  8. package/dist/bin/adapters/node/index.js +0 -33
  9. package/dist/bin/adapters/types.js +0 -1
  10. package/dist/bin/alpha-zero/agentWrapper.js +0 -165
  11. package/dist/bin/alpha-zero/codeEvaluator.js +0 -272
  12. package/dist/bin/alpha-zero/competitiveRunner.js +0 -219
  13. package/dist/bin/alpha-zero/index.js +0 -98
  14. package/dist/bin/alpha-zero/introspection.js +0 -298
  15. package/dist/bin/alpha-zero/metricsTracker.js +0 -207
  16. package/dist/bin/alpha-zero/security/core.js +0 -269
  17. package/dist/bin/alpha-zero/security/google.js +0 -308
  18. package/dist/bin/alpha-zero/security/googleLoader.js +0 -40
  19. package/dist/bin/alpha-zero/security/index.js +0 -31
  20. package/dist/bin/alpha-zero/security/simulation.js +0 -274
  21. package/dist/bin/alpha-zero/selfModification.js +0 -231
  22. package/dist/bin/alpha-zero/types.js +0 -30
  23. package/dist/bin/bin/erosolar-optimized.js +0 -205
  24. package/dist/bin/capabilities/agentSpawningCapability.js +0 -116
  25. package/dist/bin/capabilities/bashCapability.js +0 -22
  26. package/dist/bin/capabilities/cloudCapability.js +0 -36
  27. package/dist/bin/capabilities/codeAnalysisCapability.js +0 -22
  28. package/dist/bin/capabilities/codeQualityCapability.js +0 -23
  29. package/dist/bin/capabilities/dependencySecurityCapability.js +0 -22
  30. package/dist/bin/capabilities/devCapability.js +0 -22
  31. package/dist/bin/capabilities/editCapability.js +0 -28
  32. package/dist/bin/capabilities/emailCapability.js +0 -20
  33. package/dist/bin/capabilities/enhancedGitCapability.js +0 -221
  34. package/dist/bin/capabilities/filesystemCapability.js +0 -22
  35. package/dist/bin/capabilities/globCapability.js +0 -28
  36. package/dist/bin/capabilities/interactionCapability.js +0 -20
  37. package/dist/bin/capabilities/learnCapability.js +0 -22
  38. package/dist/bin/capabilities/mcpCapability.js +0 -20
  39. package/dist/bin/capabilities/notebookCapability.js +0 -28
  40. package/dist/bin/capabilities/planningCapability.js +0 -27
  41. package/dist/bin/capabilities/refactoringCapability.js +0 -23
  42. package/dist/bin/capabilities/repoChecksCapability.js +0 -22
  43. package/dist/bin/capabilities/searchCapability.js +0 -22
  44. package/dist/bin/capabilities/skillCapability.js +0 -76
  45. package/dist/bin/capabilities/taskManagementCapability.js +0 -20
  46. package/dist/bin/capabilities/testingCapability.js +0 -23
  47. package/dist/bin/capabilities/toolManifest.js +0 -159
  48. package/dist/bin/capabilities/toolRegistry.js +0 -114
  49. package/dist/bin/capabilities/webCapability.js +0 -20
  50. package/dist/bin/config.js +0 -139
  51. package/dist/bin/contracts/v1/agent.js +0 -7
  52. package/dist/bin/contracts/v1/agentProfileManifest.js +0 -8
  53. package/dist/bin/contracts/v1/agentRules.js +0 -9
  54. package/dist/bin/contracts/v1/toolAccess.js +0 -8
  55. package/dist/bin/erosolar-optimized.d.ts +0 -12
  56. package/dist/bin/erosolar-optimized.d.ts.map +0 -1
  57. package/dist/bin/erosolar-optimized.js +0 -239
  58. package/dist/bin/erosolar-optimized.js.map +0 -1
  59. package/dist/bin/headless/headlessApp.js +0 -172
  60. package/dist/bin/mcp/config.js +0 -202
  61. package/dist/bin/mcp/stdioClient.js +0 -172
  62. package/dist/bin/mcp/toolBridge.js +0 -104
  63. package/dist/bin/mcp/types.js +0 -1
  64. package/dist/bin/plugins/index.js +0 -113
  65. package/dist/bin/plugins/providers/anthropic/index.js +0 -25
  66. package/dist/bin/plugins/providers/deepseek/index.js +0 -24
  67. package/dist/bin/plugins/providers/google/index.js +0 -26
  68. package/dist/bin/plugins/providers/index.js +0 -19
  69. package/dist/bin/plugins/providers/ollama/index.js +0 -59
  70. package/dist/bin/plugins/providers/openai/index.js +0 -26
  71. package/dist/bin/plugins/providers/xai/index.js +0 -24
  72. package/dist/bin/plugins/tools/agentSpawning/agentSpawningPlugin.js +0 -8
  73. package/dist/bin/plugins/tools/bash/localBashPlugin.js +0 -13
  74. package/dist/bin/plugins/tools/checks/localRepoChecksPlugin.js +0 -13
  75. package/dist/bin/plugins/tools/cloud/cloudPlugin.js +0 -13
  76. package/dist/bin/plugins/tools/codeAnalysis/codeAnalysisPlugin.js +0 -13
  77. package/dist/bin/plugins/tools/codeQuality/codeQualityPlugin.js +0 -13
  78. package/dist/bin/plugins/tools/dependency/dependencyPlugin.js +0 -11
  79. package/dist/bin/plugins/tools/development/devPlugin.js +0 -13
  80. package/dist/bin/plugins/tools/edit/editPlugin.js +0 -14
  81. package/dist/bin/plugins/tools/email/emailPlugin.js +0 -11
  82. package/dist/bin/plugins/tools/enhancedGit/enhancedGitPlugin.js +0 -8
  83. package/dist/bin/plugins/tools/filesystem/localFilesystemPlugin.js +0 -13
  84. package/dist/bin/plugins/tools/glob/globPlugin.js +0 -14
  85. package/dist/bin/plugins/tools/index.js +0 -2
  86. package/dist/bin/plugins/tools/interaction/interactionPlugin.js +0 -11
  87. package/dist/bin/plugins/tools/learn/learnPlugin.js +0 -13
  88. package/dist/bin/plugins/tools/mcp/mcpPlugin.js +0 -8
  89. package/dist/bin/plugins/tools/nodeDefaults.js +0 -56
  90. package/dist/bin/plugins/tools/notebook/notebookPlugin.js +0 -14
  91. package/dist/bin/plugins/tools/planning/planningPlugin.js +0 -14
  92. package/dist/bin/plugins/tools/refactoring/refactoringPlugin.js +0 -11
  93. package/dist/bin/plugins/tools/registry.js +0 -57
  94. package/dist/bin/plugins/tools/search/localSearchPlugin.js +0 -13
  95. package/dist/bin/plugins/tools/skills/skillPlugin.js +0 -8
  96. package/dist/bin/plugins/tools/taskManagement/taskManagementPlugin.js +0 -11
  97. package/dist/bin/plugins/tools/testing/testingPlugin.js +0 -11
  98. package/dist/bin/plugins/tools/web/webPlugin.js +0 -11
  99. package/dist/bin/providers/anthropicProvider.js +0 -329
  100. package/dist/bin/providers/googleProvider.js +0 -203
  101. package/dist/bin/providers/openaiChatCompletionsProvider.js +0 -208
  102. package/dist/bin/providers/openaiResponsesProvider.js +0 -249
  103. package/dist/bin/providers/providerFactory.js +0 -24
  104. package/dist/bin/runtime/agentController.js +0 -321
  105. package/dist/bin/runtime/agentHost.js +0 -153
  106. package/dist/bin/runtime/agentSession.js +0 -195
  107. package/dist/bin/runtime/node.js +0 -10
  108. package/dist/bin/runtime/universal.js +0 -28
  109. package/dist/bin/skills/skillRepository.js +0 -236
  110. package/dist/bin/skills/types.js +0 -1
  111. package/dist/bin/subagents/taskRunner.js +0 -269
  112. package/dist/bin/tools/backgroundBashTools.js +0 -211
  113. package/dist/bin/tools/bashTools.js +0 -159
  114. package/dist/bin/tools/cloudTools.js +0 -864
  115. package/dist/bin/tools/codeAnalysisTools.js +0 -641
  116. package/dist/bin/tools/codeQualityTools.js +0 -294
  117. package/dist/bin/tools/dependencyTools.js +0 -282
  118. package/dist/bin/tools/devTools.js +0 -238
  119. package/dist/bin/tools/diffUtils.js +0 -137
  120. package/dist/bin/tools/editTools.js +0 -134
  121. package/dist/bin/tools/emailTools.js +0 -448
  122. package/dist/bin/tools/fileTools.js +0 -282
  123. package/dist/bin/tools/globTools.js +0 -173
  124. package/dist/bin/tools/grepTools.js +0 -332
  125. package/dist/bin/tools/interactionTools.js +0 -170
  126. package/dist/bin/tools/learnTools.js +0 -1818
  127. package/dist/bin/tools/notebookEditTools.js +0 -196
  128. package/dist/bin/tools/planningTools.js +0 -46
  129. package/dist/bin/tools/refactoringTools.js +0 -293
  130. package/dist/bin/tools/repoChecksTools.js +0 -160
  131. package/dist/bin/tools/searchTools.js +0 -206
  132. package/dist/bin/tools/skillTools.js +0 -177
  133. package/dist/bin/tools/taskManagementTools.js +0 -156
  134. package/dist/bin/tools/testingTools.js +0 -232
  135. package/dist/bin/tools/webTools.js +0 -480
  136. package/dist/bin/workspace.js +0 -106
  137. package/dist/bin/workspace.validator.js +0 -213
  138. package/dist/capabilities/offensiveSecurityCapability.d.ts +0 -26
  139. package/dist/capabilities/offensiveSecurityCapability.d.ts.map +0 -1
  140. package/dist/capabilities/offensiveSecurityCapability.js +0 -58
  141. package/dist/capabilities/offensiveSecurityCapability.js.map +0 -1
  142. package/dist/capabilities/realSecurityCapability.d.ts +0 -26
  143. package/dist/capabilities/realSecurityCapability.d.ts.map +0 -1
  144. package/dist/capabilities/realSecurityCapability.js +0 -53
  145. package/dist/capabilities/realSecurityCapability.js.map +0 -1
  146. package/dist/capabilities/securityCapability.d.ts +0 -32
  147. package/dist/capabilities/securityCapability.d.ts.map +0 -1
  148. package/dist/capabilities/securityCapability.js +0 -57
  149. package/dist/capabilities/securityCapability.js.map +0 -1
  150. package/dist/capabilities/ultimateSecurityCapability.d.ts +0 -42
  151. package/dist/capabilities/ultimateSecurityCapability.d.ts.map +0 -1
  152. package/dist/capabilities/ultimateSecurityCapability.js +0 -96
  153. package/dist/capabilities/ultimateSecurityCapability.js.map +0 -1
  154. package/dist/core/designThoughtCheck.d.ts +0 -196
  155. package/dist/core/designThoughtCheck.d.ts.map +0 -1
  156. package/dist/core/designThoughtCheck.js +0 -287
  157. package/dist/core/designThoughtCheck.js.map +0 -1
  158. package/dist/core/designThoughtCheckEngine.d.ts +0 -58
  159. package/dist/core/designThoughtCheckEngine.d.ts.map +0 -1
  160. package/dist/core/designThoughtCheckEngine.js +0 -358
  161. package/dist/core/designThoughtCheckEngine.js.map +0 -1
  162. package/dist/core/designThoughtCheckIntegration.d.ts +0 -103
  163. package/dist/core/designThoughtCheckIntegration.d.ts.map +0 -1
  164. package/dist/core/designThoughtCheckIntegration.js +0 -207
  165. package/dist/core/designThoughtCheckIntegration.js.map +0 -1
  166. package/dist/core/intelligenceTools.d.ts +0 -19
  167. package/dist/core/intelligenceTools.d.ts.map +0 -1
  168. package/dist/core/intelligenceTools.js +0 -453
  169. package/dist/core/intelligenceTools.js.map +0 -1
  170. package/dist/core/operationalTools.d.ts +0 -19
  171. package/dist/core/operationalTools.d.ts.map +0 -1
  172. package/dist/core/operationalTools.js +0 -467
  173. package/dist/core/operationalTools.js.map +0 -1
  174. package/dist/offensive/core/offensive-engine.d.ts +0 -171
  175. package/dist/offensive/core/offensive-engine.d.ts.map +0 -1
  176. package/dist/offensive/core/offensive-engine.js +0 -345
  177. package/dist/offensive/core/offensive-engine.js.map +0 -1
  178. package/dist/offensive/core/offensive-integration.d.ts +0 -129
  179. package/dist/offensive/core/offensive-integration.d.ts.map +0 -1
  180. package/dist/offensive/core/offensive-integration.js +0 -364
  181. package/dist/offensive/core/offensive-integration.js.map +0 -1
  182. package/dist/offensive/core/offensive-tools.d.ts +0 -55
  183. package/dist/offensive/core/offensive-tools.d.ts.map +0 -1
  184. package/dist/offensive/core/offensive-tools.js +0 -438
  185. package/dist/offensive/core/offensive-tools.js.map +0 -1
  186. package/dist/offensive/offensive-cli.d.ts +0 -48
  187. package/dist/offensive/offensive-cli.d.ts.map +0 -1
  188. package/dist/offensive/offensive-cli.js +0 -233
  189. package/dist/offensive/offensive-cli.js.map +0 -1
  190. package/dist/security/apt-simulation-cli.d.ts +0 -57
  191. package/dist/security/apt-simulation-cli.d.ts.map +0 -1
  192. package/dist/security/apt-simulation-cli.js +0 -278
  193. package/dist/security/apt-simulation-cli.js.map +0 -1
  194. package/dist/security/apt-simulation-engine-complete.d.ts +0 -97
  195. package/dist/security/apt-simulation-engine-complete.d.ts.map +0 -1
  196. package/dist/security/apt-simulation-engine-complete.js +0 -441
  197. package/dist/security/apt-simulation-engine-complete.js.map +0 -1
  198. package/dist/security/apt-simulation-engine.d.ts +0 -97
  199. package/dist/security/apt-simulation-engine.d.ts.map +0 -1
  200. package/dist/security/apt-simulation-engine.js +0 -441
  201. package/dist/security/apt-simulation-engine.js.map +0 -1
  202. package/dist/security/authorization.d.ts +0 -45
  203. package/dist/security/authorization.d.ts.map +0 -1
  204. package/dist/security/authorization.js +0 -128
  205. package/dist/security/authorization.js.map +0 -1
  206. package/dist/security/comprehensive-security-research.d.ts +0 -84
  207. package/dist/security/comprehensive-security-research.d.ts.map +0 -1
  208. package/dist/security/comprehensive-security-research.js +0 -211
  209. package/dist/security/comprehensive-security-research.js.map +0 -1
  210. package/dist/security/offensive/exploitationEngine.d.ts +0 -54
  211. package/dist/security/offensive/exploitationEngine.d.ts.map +0 -1
  212. package/dist/security/offensive/exploitationEngine.js +0 -263
  213. package/dist/security/offensive/exploitationEngine.js.map +0 -1
  214. package/dist/security/real/networkExploitation.d.ts +0 -92
  215. package/dist/security/real/networkExploitation.d.ts.map +0 -1
  216. package/dist/security/real/networkExploitation.js +0 -316
  217. package/dist/security/real/networkExploitation.js.map +0 -1
  218. package/dist/security/real/persistenceImplementation.d.ts +0 -62
  219. package/dist/security/real/persistenceImplementation.d.ts.map +0 -1
  220. package/dist/security/real/persistenceImplementation.js +0 -323
  221. package/dist/security/real/persistenceImplementation.js.map +0 -1
  222. package/dist/security/real/vulnerabilityScanner.d.ts +0 -73
  223. package/dist/security/real/vulnerabilityScanner.d.ts.map +0 -1
  224. package/dist/security/real/vulnerabilityScanner.js +0 -341
  225. package/dist/security/real/vulnerabilityScanner.js.map +0 -1
  226. package/dist/shell/capturePastePatch.d.ts +0 -9
  227. package/dist/shell/capturePastePatch.d.ts.map +0 -1
  228. package/dist/shell/capturePastePatch.js +0 -98
  229. package/dist/shell/capturePastePatch.js.map +0 -1
  230. package/dist/shell/enhancedInteractiveShell.d.ts +0 -90
  231. package/dist/shell/enhancedInteractiveShell.d.ts.map +0 -1
  232. package/dist/shell/enhancedInteractiveShell.js +0 -248
  233. package/dist/shell/enhancedInteractiveShell.js.map +0 -1
  234. package/dist/shell/inputProcessor.d.ts +0 -56
  235. package/dist/shell/inputProcessor.d.ts.map +0 -1
  236. package/dist/shell/inputProcessor.js +0 -172
  237. package/dist/shell/inputProcessor.js.map +0 -1
  238. package/dist/shell/interactiveShell-patch.d.ts +0 -27
  239. package/dist/shell/interactiveShell-patch.d.ts.map +0 -1
  240. package/dist/shell/interactiveShell-patch.js +0 -38
  241. package/dist/shell/interactiveShell-patch.js.map +0 -1
  242. package/dist/shell/interactiveShell-robust.d.ts +0 -26
  243. package/dist/shell/interactiveShell-robust.d.ts.map +0 -1
  244. package/dist/shell/interactiveShell-robust.js +0 -34
  245. package/dist/shell/interactiveShell-robust.js.map +0 -1
  246. package/dist/shell/multiLinePasteManager.d.ts +0 -106
  247. package/dist/shell/multiLinePasteManager.d.ts.map +0 -1
  248. package/dist/shell/multiLinePasteManager.js +0 -308
  249. package/dist/shell/multiLinePasteManager.js.map +0 -1
  250. package/dist/shell/processInputBlockPatch.d.ts +0 -8
  251. package/dist/shell/processInputBlockPatch.d.ts.map +0 -1
  252. package/dist/shell/processInputBlockPatch.js +0 -133
  253. package/dist/shell/processInputBlockPatch.js.map +0 -1
  254. package/dist/shell/unifiedInputProcessor.d.ts +0 -23
  255. package/dist/shell/unifiedInputProcessor.d.ts.map +0 -1
  256. package/dist/shell/unifiedInputProcessor.js +0 -92
  257. package/dist/shell/unifiedInputProcessor.js.map +0 -1
  258. package/dist/tools/enhancedSecurityTools.d.ts +0 -19
  259. package/dist/tools/enhancedSecurityTools.d.ts.map +0 -1
  260. package/dist/tools/enhancedSecurityTools.js +0 -215
  261. package/dist/tools/enhancedSecurityTools.js.map +0 -1
  262. package/dist/tools/offensiveSecurityTools.d.ts +0 -16
  263. package/dist/tools/offensiveSecurityTools.d.ts.map +0 -1
  264. package/dist/tools/offensiveSecurityTools.js +0 -285
  265. package/dist/tools/offensiveSecurityTools.js.map +0 -1
  266. package/dist/tools/realSecurityTools.d.ts +0 -18
  267. package/dist/tools/realSecurityTools.d.ts.map +0 -1
  268. package/dist/tools/realSecurityTools.js +0 -468
  269. package/dist/tools/realSecurityTools.js.map +0 -1
  270. package/dist/tools/securityTools.d.ts +0 -20
  271. package/dist/tools/securityTools.d.ts.map +0 -1
  272. package/dist/tools/securityTools.js +0 -449
  273. package/dist/tools/securityTools.js.map +0 -1
@@ -1,239 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Optimized Erosolar CLI Entry Point
4
- *
5
- * Features:
6
- * - Fast-path commands for simple operations
7
- * - Lazy loading for complex functionality
8
- * - Performance monitoring
9
- * - Graceful error handling
10
- */
11
- import { readFileSync } from 'node:fs';
12
- import { dirname, resolve } from 'node:path';
13
- import { fileURLToPath } from 'node:url';
14
- import { initializeLazyLoaders, LazyLoaderRegistry } from '../core/LazyLoader.js';
15
- // Initialize lazy loading system
16
- initializeLazyLoaders();
17
- // Fast-path command handling
18
- function handleFastPathCommand(argv) {
19
- const command = argv[0];
20
- switch (command) {
21
- case '--version':
22
- case 'version':
23
- case '-v':
24
- console.log(`Erosolar CLI v${getPackageVersion()}`);
25
- return true;
26
- case '--help':
27
- case 'help':
28
- case '-h':
29
- showFastHelp();
30
- return true;
31
- case '--json':
32
- // Defer to full implementation for JSON mode
33
- return false;
34
- case 'health-check':
35
- // This will be handled in main async function
36
- return false;
37
- case 'status':
38
- showStatus();
39
- return true;
40
- case 'performance':
41
- showPerformanceStats();
42
- return true;
43
- }
44
- return false;
45
- }
46
- // Get package version without full initialization
47
- function getPackageVersion() {
48
- try {
49
- const filePath = fileURLToPath(import.meta.url);
50
- const packagePath = resolve(dirname(filePath), '../../package.json');
51
- const payload = JSON.parse(readFileSync(packagePath, 'utf8'));
52
- return typeof payload.version === 'string' ? payload.version : '0.0.0';
53
- }
54
- catch {
55
- return '0.0.0';
56
- }
57
- }
58
- // Fast help without full initialization
59
- function showFastHelp() {
60
- console.log(`
61
- Erosolar CLI v${getPackageVersion()} - Fast Help
62
-
63
- Usage:
64
- erosolar [command] [options]
65
-
66
- Fast Commands:
67
- version, -v Show version
68
- help, -h Show this help
69
- status Show system status
70
- performance Show performance statistics
71
-
72
- Full Commands:
73
- [interactive] Start interactive shell
74
- --json <command> Run command in JSON mode
75
- health-check Run health check
76
-
77
- Options:
78
- --provider <name> Specify AI provider
79
- --model <name> Specify AI model
80
- --profile <name> Use specific agent profile
81
-
82
- Examples:
83
- erosolar version
84
- erosolar --json "list files"
85
- erosolar --provider openai --model gpt-4
86
- `);
87
- }
88
- // Run health check without full initialization
89
- async function runHealthCheck() {
90
- console.log('🧪 Running fast health check...\n');
91
- const checks = [
92
- { name: 'Node.js version', check: checkNodeVersion },
93
- { name: 'Package configuration', check: checkPackageConfig },
94
- { name: 'Build directory', check: checkBuildDir },
95
- { name: 'Main binary', check: checkMainBinary },
96
- ];
97
- let passed = 0;
98
- let failed = 0;
99
- for (const { name, check } of checks) {
100
- try {
101
- await check();
102
- console.log(`✅ ${name}`);
103
- passed++;
104
- }
105
- catch (error) {
106
- console.log(`❌ ${name}: ${error instanceof Error ? error.message : error}`);
107
- failed++;
108
- }
109
- }
110
- console.log(`\n📊 Results: ${passed} passed, ${failed} failed`);
111
- if (failed > 0) {
112
- process.exit(1);
113
- }
114
- }
115
- // Check Node.js version
116
- function checkNodeVersion() {
117
- const version = process.version;
118
- const major = parseInt(version.slice(1).split('.')[0], 10);
119
- if (major < 20) {
120
- throw new Error(`Node.js ${version} is too old, requires >=20.0.0`);
121
- }
122
- }
123
- // Check package configuration
124
- function checkPackageConfig() {
125
- const filePath = fileURLToPath(import.meta.url);
126
- const packagePath = resolve(dirname(filePath), '../../package.json');
127
- if (!readFileSync(packagePath, 'utf8')) {
128
- throw new Error('Package.json not found or empty');
129
- }
130
- }
131
- // Check build directory
132
- function checkBuildDir() {
133
- const filePath = fileURLToPath(import.meta.url);
134
- const buildPath = resolve(dirname(filePath), '../../dist');
135
- try {
136
- const stats = readFileSync(buildPath);
137
- if (!stats) {
138
- throw new Error('Build directory does not exist');
139
- }
140
- }
141
- catch {
142
- throw new Error('Build directory does not exist');
143
- }
144
- }
145
- // Check main binary
146
- function checkMainBinary() {
147
- const filePath = fileURLToPath(import.meta.url);
148
- const binaryPath = resolve(dirname(filePath), '../../dist/bin/erosolar.js');
149
- try {
150
- const stats = readFileSync(binaryPath);
151
- if (!stats) {
152
- throw new Error('Main binary does not exist');
153
- }
154
- }
155
- catch {
156
- throw new Error('Main binary does not exist');
157
- }
158
- }
159
- // Show system status
160
- function showStatus() {
161
- const registry = LazyLoaderRegistry.getInstance();
162
- const stats = registry.getStats();
163
- console.log(`
164
- Erosolar CLI Status
165
- ───────────────────
166
- Version: ${getPackageVersion()}
167
- Node.js: ${process.version}
168
- Platform: ${process.platform} ${process.arch}
169
- Working Directory: ${process.cwd()}
170
-
171
- Lazy Loading Status:
172
- ${Object.entries(stats).map(([name, loaderStats]) => ` ${name}: ${loaderStats.isLoaded ? '✅ Loaded' : loaderStats.isLoading ? '🔄 Loading' : '⏳ Not Loaded'} (${loaderStats.loadCount} loads)`).join('\n')}
173
-
174
- Fast Commands: ✅ Available
175
- Full Shell: ⚠️ May be slow to initialize
176
- Health Check: ✅ Available
177
- `);
178
- }
179
- // Show performance statistics
180
- function showPerformanceStats() {
181
- const registry = LazyLoaderRegistry.getInstance();
182
- const stats = registry.getStats();
183
- console.log(`
184
- Erosolar CLI Performance Statistics
185
- ──────────────────────────────────
186
-
187
- Lazy Loader Status:
188
- ${Object.entries(stats).map(([name, loaderStats]) => ` ${name}:
189
- Status: ${loaderStats.isLoaded ? '✅ Loaded' : loaderStats.isLoading ? '🔄 Loading' : '⏳ Not Loaded'}
190
- Load Count: ${loaderStats.loadCount}
191
- Last Load: ${loaderStats.lastLoadTime ? new Date(loaderStats.lastLoadTime).toISOString() : 'Never'}`).join('\n\n')}
192
-
193
- Performance Tips:
194
- • Use fast commands (version, help, status) for instant response
195
- • Complex commands load components on-demand
196
- • Lazy loading prevents slow startup for simple operations
197
- • Cached components improve subsequent command performance
198
- `);
199
- }
200
- // Main execution
201
- async function main() {
202
- const argv = process.argv.slice(2);
203
- // Handle fast-path commands
204
- if (handleFastPathCommand(argv)) {
205
- return;
206
- }
207
- // Handle health check (needs to be async)
208
- if (argv[0] === 'health-check') {
209
- await runHealthCheck();
210
- return;
211
- }
212
- // Defer to full implementation for complex commands
213
- console.log('🚀 Starting full Erosolar CLI...');
214
- console.log('⏳ This may take a moment for complex initialization...\n');
215
- try {
216
- if (argv.includes('--json')) {
217
- const { runHeadlessApp } = await import('../headless/headlessApp.js');
218
- await runHeadlessApp({ argv });
219
- }
220
- else {
221
- const { launchShell } = await import('../shell/shellApp.js');
222
- await launchShell('erosolar-code', { enableProfileSelection: true });
223
- }
224
- }
225
- catch (error) {
226
- console.error('\n❌ CLI Error:', error instanceof Error ? error.message : error);
227
- // Provide helpful suggestions
228
- if (error instanceof Error && error.message.includes('Cannot find module')) {
229
- console.log('\n💡 Try running: npm run build');
230
- }
231
- process.exit(1);
232
- }
233
- }
234
- // Start the application
235
- main().catch((error) => {
236
- console.error('Fatal error:', error instanceof Error ? error.message : error);
237
- process.exit(1);
238
- });
239
- //# sourceMappingURL=erosolar-optimized.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"erosolar-optimized.js","sourceRoot":"","sources":["../../src/bin/erosolar-optimized.ts"],"names":[],"mappings":";AAEA;;;;;;;;GAQG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAElF,iCAAiC;AACjC,qBAAqB,EAAE,CAAC;AAExB,6BAA6B;AAC7B,SAAS,qBAAqB,CAAC,IAAc;IAC3C,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IAExB,QAAQ,OAAO,EAAE,CAAC;QAChB,KAAK,WAAW,CAAC;QACjB,KAAK,SAAS,CAAC;QACf,KAAK,IAAI;YACP,OAAO,CAAC,GAAG,CAAC,iBAAiB,iBAA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AAK,CAAC,CAAC;QAEhF,8BAA8B;QAC9B,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAC,EAAE,CAAC;YAC3E,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;QACjD,CAAC;QAED,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,wBAAwB;AACxB,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAC9E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -1,172 +0,0 @@
1
- import { randomUUID } from 'node:crypto';
2
- import { readFileSync } from 'node:fs';
3
- import { dirname, resolve } from 'node:path';
4
- import { fileURLToPath } from 'node:url';
5
- import readline from 'node:readline';
6
- import { exit, stdin, stdout } from 'node:process';
7
- import { hasAgentProfile, listAgentProfiles } from '../core/agentProfiles.js';
8
- import { createAgentController } from '../runtime/agentController.js';
9
- import { resolveWorkspaceCaptureOptions, buildWorkspaceContext } from '../workspace.js';
10
- export async function runHeadlessApp(options) {
11
- const parsed = parseHeadlessArgs(options.argv);
12
- const profile = resolveProfile(parsed.profile);
13
- const sessionId = parsed.sessionId ?? randomUUID();
14
- const workingDir = process.cwd();
15
- const workspaceOptions = resolveWorkspaceCaptureOptions(process.env);
16
- const workspaceContext = buildWorkspaceContext(workingDir, workspaceOptions);
17
- const controller = await createAgentController({
18
- profile,
19
- workingDir,
20
- workspaceContext,
21
- env: process.env,
22
- });
23
- const manifest = controller.getCapabilities();
24
- emitEvent({
25
- type: 'session',
26
- sessionId,
27
- profile,
28
- manifest,
29
- workingDir,
30
- workspaceContext,
31
- version: readPackageVersion(),
32
- });
33
- const queue = [];
34
- let processing = false;
35
- let stdinClosed = !parsed.watchStdIn;
36
- const enqueuePrompt = (prompt) => {
37
- const content = prompt.trim();
38
- if (!content) {
39
- return;
40
- }
41
- queue.push({ id: randomUUID(), prompt: content });
42
- void processQueue();
43
- };
44
- const processQueue = async () => {
45
- if (processing) {
46
- return;
47
- }
48
- processing = true;
49
- while (queue.length) {
50
- const next = queue.shift();
51
- await handlePrompt(next).catch((error) => {
52
- emitEvent({
53
- type: 'error',
54
- sessionId,
55
- profile,
56
- runId: next.id,
57
- message: error instanceof Error ? error.message : String(error),
58
- });
59
- });
60
- }
61
- processing = false;
62
- if (stdinClosed) {
63
- exit(0);
64
- }
65
- };
66
- const handlePrompt = async (work) => {
67
- emitEvent({ type: 'user-input', sessionId, profile, runId: work.id, content: work.prompt });
68
- for await (const event of controller.send(work.prompt)) {
69
- emitEvent({ type: 'agent-event', sessionId, profile, runId: work.id, event });
70
- }
71
- emitEvent({ type: 'run-complete', sessionId, profile, runId: work.id });
72
- };
73
- if (parsed.initialPrompt) {
74
- enqueuePrompt(parsed.initialPrompt);
75
- }
76
- if (parsed.watchStdIn) {
77
- const rl = readline.createInterface({ input: stdin, terminal: false });
78
- rl.on('line', (line) => {
79
- enqueuePrompt(line);
80
- });
81
- rl.on('close', () => {
82
- stdinClosed = true;
83
- if (!processing) {
84
- exit(0);
85
- }
86
- });
87
- // Keep stdin open to receive input
88
- stdin.resume();
89
- }
90
- else if (!parsed.initialPrompt) {
91
- // Nothing to do in headless mode without stdin or an initial prompt
92
- emitEvent({
93
- type: 'error',
94
- sessionId,
95
- profile,
96
- message: 'Headless mode requires stdin or a prompt argument.',
97
- });
98
- exit(1);
99
- }
100
- // Note: stdin.resume() is now only called when watchStdIn is true
101
- }
102
- function parseHeadlessArgs(argv) {
103
- let profile;
104
- let sessionId;
105
- let watchStdIn = true;
106
- const promptTokens = [];
107
- for (let index = 0; index < argv.length; index += 1) {
108
- const token = argv[index];
109
- if (!token) {
110
- continue;
111
- }
112
- if (token === '--json') {
113
- continue;
114
- }
115
- if (token === '--profile' || token === '-p') {
116
- profile = argv[index + 1];
117
- index += 1;
118
- continue;
119
- }
120
- if (token.startsWith('--profile=')) {
121
- profile = token.slice('--profile='.length);
122
- continue;
123
- }
124
- if (token === '--session-id') {
125
- sessionId = argv[index + 1];
126
- index += 1;
127
- continue;
128
- }
129
- if (token.startsWith('--session-id=')) {
130
- sessionId = token.slice('--session-id='.length);
131
- continue;
132
- }
133
- if (token === '--no-stdin') {
134
- watchStdIn = false;
135
- continue;
136
- }
137
- promptTokens.push(token);
138
- }
139
- return {
140
- profile,
141
- sessionId,
142
- watchStdIn,
143
- initialPrompt: promptTokens.length ? promptTokens.join(' ').trim() : null,
144
- };
145
- }
146
- function resolveProfile(candidate) {
147
- const envOverride = process.env['EROSOLAR_PROFILE']?.trim();
148
- const desired = candidate?.trim() || envOverride || 'erosolar-code';
149
- if (hasAgentProfile(desired)) {
150
- return desired;
151
- }
152
- const lower = desired.toLowerCase();
153
- const match = listAgentProfiles().find((entry) => entry.name.toLowerCase() === lower);
154
- if (match) {
155
- return match.name;
156
- }
157
- throw new Error(`Unknown profile "${candidate ?? desired}".`);
158
- }
159
- function emitEvent(event) {
160
- stdout.write(`${JSON.stringify(event)}\n`);
161
- }
162
- function readPackageVersion() {
163
- try {
164
- const filePath = fileURLToPath(import.meta.url);
165
- const packagePath = resolve(dirname(filePath), '../../package.json');
166
- const payload = JSON.parse(readFileSync(packagePath, 'utf8'));
167
- return typeof payload.version === 'string' ? payload.version : '0.0.0';
168
- }
169
- catch {
170
- return '0.0.0';
171
- }
172
- }
@@ -1,202 +0,0 @@
1
- import { readFile, readdir, stat } from 'node:fs/promises';
2
- import { homedir } from 'node:os';
3
- import { join, resolve } from 'node:path';
4
- const DEFAULT_FILES = ['.mcp.json', join('.erosolar', 'mcp.json')];
5
- const DEFAULT_DIRECTORIES = [join('.erosolar', 'mcp.d')];
6
- export async function loadMcpServers(options) {
7
- const candidates = await discoverConfigFiles(options);
8
- if (!candidates.length) {
9
- return [];
10
- }
11
- const normalized = new Map();
12
- for (const file of candidates) {
13
- try {
14
- const definitions = await parseConfigFile(file);
15
- for (const definition of definitions) {
16
- if (definition.disabled) {
17
- normalized.delete(definition.id ?? '');
18
- continue;
19
- }
20
- const entry = normalizeServerDefinition(definition, file, options);
21
- if (entry) {
22
- normalized.set(entry.id, entry);
23
- }
24
- }
25
- }
26
- catch {
27
- // Ignore malformed files but continue loading others.
28
- }
29
- }
30
- return Array.from(normalized.values());
31
- }
32
- async function discoverConfigFiles(options) {
33
- const files = new Set();
34
- const home = homedir();
35
- const envOverride = options.env['EROSOLAR_MCP_CONFIG'];
36
- if (envOverride) {
37
- for (const path of envOverride.split(/[:,;]/)) {
38
- const trimmed = path.trim();
39
- if (trimmed) {
40
- files.add(resolve(trimmed));
41
- }
42
- }
43
- }
44
- const searchRoots = [options.workingDir, home];
45
- for (const root of searchRoots) {
46
- for (const name of DEFAULT_FILES) {
47
- const candidate = resolve(root, name);
48
- if (await fileExists(candidate)) {
49
- files.add(candidate);
50
- }
51
- }
52
- for (const dirName of DEFAULT_DIRECTORIES) {
53
- const directory = resolve(root, dirName);
54
- const entries = await readDirectoryJsonFiles(directory);
55
- for (const entry of entries) {
56
- files.add(entry);
57
- }
58
- }
59
- }
60
- return Array.from(files);
61
- }
62
- async function readDirectoryJsonFiles(directory) {
63
- try {
64
- const stats = await stat(directory);
65
- if (!stats.isDirectory()) {
66
- return [];
67
- }
68
- const entries = await readdir(directory);
69
- return entries
70
- .filter((name) => name.endsWith('.json'))
71
- .map((name) => resolve(directory, name));
72
- }
73
- catch {
74
- return [];
75
- }
76
- }
77
- async function parseConfigFile(path) {
78
- const content = await readFile(path, 'utf8');
79
- const trimmed = content.trim();
80
- if (!trimmed) {
81
- return [];
82
- }
83
- const parsed = JSON.parse(trimmed);
84
- if (Array.isArray(parsed)) {
85
- return parsed.filter((entry) => Boolean(entry && typeof entry === 'object'));
86
- }
87
- if (parsed && typeof parsed === 'object') {
88
- const result = [];
89
- for (const [id, value] of Object.entries(parsed)) {
90
- if (value && typeof value === 'object') {
91
- result.push({ ...value, id });
92
- }
93
- }
94
- return result;
95
- }
96
- return [];
97
- }
98
- function normalizeServerDefinition(raw, source, options) {
99
- const type = normalizeTransport(raw.type);
100
- if (!type) {
101
- return null;
102
- }
103
- const id = sanitizeId(raw.id ?? '');
104
- if (!id) {
105
- return null;
106
- }
107
- if (type === 'stdio') {
108
- const command = expandTemplate(raw.command ?? '', options, source);
109
- if (!command) {
110
- return null;
111
- }
112
- const args = Array.isArray(raw.args)
113
- ? raw.args.map((value) => expandTemplate(String(value ?? ''), options, source)).filter(Boolean)
114
- : [];
115
- const env = normalizeEnv(raw.env, options, source);
116
- const cwd = raw.cwd ? expandTemplate(raw.cwd, options, source) : undefined;
117
- return {
118
- id,
119
- type,
120
- command,
121
- args,
122
- cwd,
123
- env,
124
- description: raw.description,
125
- source,
126
- };
127
- }
128
- return null;
129
- }
130
- function normalizeTransport(value) {
131
- if (!value) {
132
- return 'stdio';
133
- }
134
- const normalized = value.trim().toLowerCase();
135
- if (normalized === 'stdio') {
136
- return 'stdio';
137
- }
138
- return null;
139
- }
140
- function normalizeEnv(env, options, source) {
141
- if (!env) {
142
- return {};
143
- }
144
- const record = {};
145
- for (const [key, value] of Object.entries(env)) {
146
- if (typeof value !== 'string') {
147
- continue;
148
- }
149
- const expanded = expandTemplate(value, options, source);
150
- if (expanded) {
151
- record[key] = expanded;
152
- }
153
- }
154
- return record;
155
- }
156
- function expandTemplate(value, options, file) {
157
- if (!value) {
158
- return '';
159
- }
160
- const workspace = resolve(options.workingDir);
161
- const erosolarHome = join(homedir(), '.erosolar');
162
- const replacements = {
163
- WORKSPACE_ROOT: workspace,
164
- PROJECT_DIR: workspace,
165
- CLAUDE_PROJECT_DIR: workspace,
166
- EROSOLAR_HOME: erosolarHome,
167
- HOME: homedir(),
168
- MCP_CONFIG_DIR: resolve(file, '..'),
169
- };
170
- return value.replace(/\$\{([^}]+)\}/g, (_match, token) => {
171
- const key = token.trim();
172
- if (Object.prototype.hasOwnProperty.call(replacements, key)) {
173
- const replacementKey = key;
174
- return replacements[replacementKey];
175
- }
176
- const envValue = options.env[key];
177
- if (typeof envValue === 'string' && envValue.trim()) {
178
- return envValue.trim();
179
- }
180
- if (typeof process.env[key] === 'string' && process.env[key].trim()) {
181
- return process.env[key].trim();
182
- }
183
- return '';
184
- });
185
- }
186
- async function fileExists(path) {
187
- try {
188
- const stats = await stat(path);
189
- return stats.isFile();
190
- }
191
- catch {
192
- return false;
193
- }
194
- }
195
- function sanitizeId(value) {
196
- return value
197
- .trim()
198
- .replace(/[^a-zA-Z0-9_-]/g, '-')
199
- .replace(/-+/g, '-')
200
- .replace(/^-+|-+$/g, '')
201
- .toLowerCase();
202
- }