erosolar-cli 1.7.55 → 1.7.57

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/dist/shell/unifiedInputProcessor.d.ts +15 -12
  2. package/dist/shell/unifiedInputProcessor.d.ts.map +1 -1
  3. package/dist/shell/unifiedInputProcessor.js +45 -72
  4. package/dist/shell/unifiedInputProcessor.js.map +1 -1
  5. package/package.json +4 -4
  6. package/dist/active-stack-security.d.ts +0 -110
  7. package/dist/active-stack-security.js +0 -313
  8. package/dist/active-stack-security.js.map +0 -1
  9. package/dist/advanced-targeting.d.ts +0 -113
  10. package/dist/advanced-targeting.js +0 -252
  11. package/dist/advanced-targeting.js.map +0 -1
  12. package/dist/bin/adapters/node/index.js +0 -33
  13. package/dist/bin/adapters/types.js +0 -1
  14. package/dist/bin/alpha-zero/agentWrapper.js +0 -165
  15. package/dist/bin/alpha-zero/codeEvaluator.js +0 -272
  16. package/dist/bin/alpha-zero/competitiveRunner.js +0 -219
  17. package/dist/bin/alpha-zero/index.js +0 -98
  18. package/dist/bin/alpha-zero/introspection.js +0 -298
  19. package/dist/bin/alpha-zero/metricsTracker.js +0 -207
  20. package/dist/bin/alpha-zero/security/core.js +0 -269
  21. package/dist/bin/alpha-zero/security/google.js +0 -308
  22. package/dist/bin/alpha-zero/security/googleLoader.js +0 -40
  23. package/dist/bin/alpha-zero/security/index.js +0 -31
  24. package/dist/bin/alpha-zero/security/simulation.js +0 -274
  25. package/dist/bin/alpha-zero/selfModification.js +0 -231
  26. package/dist/bin/alpha-zero/types.js +0 -30
  27. package/dist/bin/bin/erosolar-optimized.js +0 -205
  28. package/dist/bin/capabilities/agentSpawningCapability.js +0 -116
  29. package/dist/bin/capabilities/bashCapability.js +0 -22
  30. package/dist/bin/capabilities/cloudCapability.js +0 -36
  31. package/dist/bin/capabilities/codeAnalysisCapability.js +0 -22
  32. package/dist/bin/capabilities/codeQualityCapability.js +0 -23
  33. package/dist/bin/capabilities/dependencySecurityCapability.js +0 -22
  34. package/dist/bin/capabilities/devCapability.js +0 -22
  35. package/dist/bin/capabilities/editCapability.js +0 -28
  36. package/dist/bin/capabilities/emailCapability.js +0 -20
  37. package/dist/bin/capabilities/enhancedGitCapability.js +0 -221
  38. package/dist/bin/capabilities/filesystemCapability.js +0 -22
  39. package/dist/bin/capabilities/globCapability.js +0 -28
  40. package/dist/bin/capabilities/interactionCapability.js +0 -20
  41. package/dist/bin/capabilities/learnCapability.js +0 -22
  42. package/dist/bin/capabilities/mcpCapability.js +0 -20
  43. package/dist/bin/capabilities/notebookCapability.js +0 -28
  44. package/dist/bin/capabilities/planningCapability.js +0 -27
  45. package/dist/bin/capabilities/refactoringCapability.js +0 -23
  46. package/dist/bin/capabilities/repoChecksCapability.js +0 -22
  47. package/dist/bin/capabilities/searchCapability.js +0 -22
  48. package/dist/bin/capabilities/skillCapability.js +0 -76
  49. package/dist/bin/capabilities/taskManagementCapability.js +0 -20
  50. package/dist/bin/capabilities/testingCapability.js +0 -23
  51. package/dist/bin/capabilities/toolManifest.js +0 -159
  52. package/dist/bin/capabilities/toolRegistry.js +0 -114
  53. package/dist/bin/capabilities/webCapability.js +0 -20
  54. package/dist/bin/config.js +0 -139
  55. package/dist/bin/contracts/v1/agent.js +0 -7
  56. package/dist/bin/contracts/v1/agentProfileManifest.js +0 -8
  57. package/dist/bin/contracts/v1/agentRules.js +0 -9
  58. package/dist/bin/contracts/v1/toolAccess.js +0 -8
  59. package/dist/bin/erosolar-optimized.d.ts +0 -12
  60. package/dist/bin/erosolar-optimized.d.ts.map +0 -1
  61. package/dist/bin/erosolar-optimized.js +0 -239
  62. package/dist/bin/erosolar-optimized.js.map +0 -1
  63. package/dist/bin/headless/headlessApp.js +0 -172
  64. package/dist/bin/mcp/config.js +0 -202
  65. package/dist/bin/mcp/stdioClient.js +0 -172
  66. package/dist/bin/mcp/toolBridge.js +0 -104
  67. package/dist/bin/mcp/types.js +0 -1
  68. package/dist/bin/plugins/index.js +0 -113
  69. package/dist/bin/plugins/providers/anthropic/index.js +0 -25
  70. package/dist/bin/plugins/providers/deepseek/index.js +0 -24
  71. package/dist/bin/plugins/providers/google/index.js +0 -26
  72. package/dist/bin/plugins/providers/index.js +0 -19
  73. package/dist/bin/plugins/providers/ollama/index.js +0 -59
  74. package/dist/bin/plugins/providers/openai/index.js +0 -26
  75. package/dist/bin/plugins/providers/xai/index.js +0 -24
  76. package/dist/bin/plugins/tools/agentSpawning/agentSpawningPlugin.js +0 -8
  77. package/dist/bin/plugins/tools/bash/localBashPlugin.js +0 -13
  78. package/dist/bin/plugins/tools/checks/localRepoChecksPlugin.js +0 -13
  79. package/dist/bin/plugins/tools/cloud/cloudPlugin.js +0 -13
  80. package/dist/bin/plugins/tools/codeAnalysis/codeAnalysisPlugin.js +0 -13
  81. package/dist/bin/plugins/tools/codeQuality/codeQualityPlugin.js +0 -13
  82. package/dist/bin/plugins/tools/dependency/dependencyPlugin.js +0 -11
  83. package/dist/bin/plugins/tools/development/devPlugin.js +0 -13
  84. package/dist/bin/plugins/tools/edit/editPlugin.js +0 -14
  85. package/dist/bin/plugins/tools/email/emailPlugin.js +0 -11
  86. package/dist/bin/plugins/tools/enhancedGit/enhancedGitPlugin.js +0 -8
  87. package/dist/bin/plugins/tools/filesystem/localFilesystemPlugin.js +0 -13
  88. package/dist/bin/plugins/tools/glob/globPlugin.js +0 -14
  89. package/dist/bin/plugins/tools/index.js +0 -2
  90. package/dist/bin/plugins/tools/interaction/interactionPlugin.js +0 -11
  91. package/dist/bin/plugins/tools/learn/learnPlugin.js +0 -13
  92. package/dist/bin/plugins/tools/mcp/mcpPlugin.js +0 -8
  93. package/dist/bin/plugins/tools/nodeDefaults.js +0 -56
  94. package/dist/bin/plugins/tools/notebook/notebookPlugin.js +0 -14
  95. package/dist/bin/plugins/tools/planning/planningPlugin.js +0 -14
  96. package/dist/bin/plugins/tools/refactoring/refactoringPlugin.js +0 -11
  97. package/dist/bin/plugins/tools/registry.js +0 -57
  98. package/dist/bin/plugins/tools/search/localSearchPlugin.js +0 -13
  99. package/dist/bin/plugins/tools/skills/skillPlugin.js +0 -8
  100. package/dist/bin/plugins/tools/taskManagement/taskManagementPlugin.js +0 -11
  101. package/dist/bin/plugins/tools/testing/testingPlugin.js +0 -11
  102. package/dist/bin/plugins/tools/web/webPlugin.js +0 -11
  103. package/dist/bin/providers/anthropicProvider.js +0 -329
  104. package/dist/bin/providers/googleProvider.js +0 -203
  105. package/dist/bin/providers/openaiChatCompletionsProvider.js +0 -208
  106. package/dist/bin/providers/openaiResponsesProvider.js +0 -249
  107. package/dist/bin/providers/providerFactory.js +0 -24
  108. package/dist/bin/runtime/agentController.js +0 -321
  109. package/dist/bin/runtime/agentHost.js +0 -153
  110. package/dist/bin/runtime/agentSession.js +0 -195
  111. package/dist/bin/runtime/node.js +0 -10
  112. package/dist/bin/runtime/universal.js +0 -28
  113. package/dist/bin/skills/skillRepository.js +0 -236
  114. package/dist/bin/skills/types.js +0 -1
  115. package/dist/bin/subagents/taskRunner.js +0 -269
  116. package/dist/bin/tools/backgroundBashTools.js +0 -211
  117. package/dist/bin/tools/bashTools.js +0 -159
  118. package/dist/bin/tools/cloudTools.js +0 -864
  119. package/dist/bin/tools/codeAnalysisTools.js +0 -641
  120. package/dist/bin/tools/codeQualityTools.js +0 -294
  121. package/dist/bin/tools/dependencyTools.js +0 -282
  122. package/dist/bin/tools/devTools.js +0 -238
  123. package/dist/bin/tools/diffUtils.js +0 -137
  124. package/dist/bin/tools/editTools.js +0 -134
  125. package/dist/bin/tools/emailTools.js +0 -448
  126. package/dist/bin/tools/fileTools.js +0 -282
  127. package/dist/bin/tools/globTools.js +0 -173
  128. package/dist/bin/tools/grepTools.js +0 -332
  129. package/dist/bin/tools/interactionTools.js +0 -170
  130. package/dist/bin/tools/learnTools.js +0 -1818
  131. package/dist/bin/tools/notebookEditTools.js +0 -196
  132. package/dist/bin/tools/planningTools.js +0 -46
  133. package/dist/bin/tools/refactoringTools.js +0 -293
  134. package/dist/bin/tools/repoChecksTools.js +0 -160
  135. package/dist/bin/tools/searchTools.js +0 -206
  136. package/dist/bin/tools/skillTools.js +0 -177
  137. package/dist/bin/tools/taskManagementTools.js +0 -156
  138. package/dist/bin/tools/testingTools.js +0 -232
  139. package/dist/bin/tools/webTools.js +0 -480
  140. package/dist/bin/workspace.js +0 -106
  141. package/dist/bin/workspace.validator.js +0 -213
  142. package/dist/capabilities/offensiveSecurityCapability.d.ts +0 -26
  143. package/dist/capabilities/offensiveSecurityCapability.d.ts.map +0 -1
  144. package/dist/capabilities/offensiveSecurityCapability.js +0 -58
  145. package/dist/capabilities/offensiveSecurityCapability.js.map +0 -1
  146. package/dist/capabilities/realSecurityCapability.d.ts +0 -26
  147. package/dist/capabilities/realSecurityCapability.d.ts.map +0 -1
  148. package/dist/capabilities/realSecurityCapability.js +0 -53
  149. package/dist/capabilities/realSecurityCapability.js.map +0 -1
  150. package/dist/capabilities/securityCapability.d.ts +0 -32
  151. package/dist/capabilities/securityCapability.d.ts.map +0 -1
  152. package/dist/capabilities/securityCapability.js +0 -57
  153. package/dist/capabilities/securityCapability.js.map +0 -1
  154. package/dist/capabilities/ultimateSecurityCapability.d.ts +0 -42
  155. package/dist/capabilities/ultimateSecurityCapability.d.ts.map +0 -1
  156. package/dist/capabilities/ultimateSecurityCapability.js +0 -96
  157. package/dist/capabilities/ultimateSecurityCapability.js.map +0 -1
  158. package/dist/core/designThoughtCheck.d.ts +0 -196
  159. package/dist/core/designThoughtCheck.d.ts.map +0 -1
  160. package/dist/core/designThoughtCheck.js +0 -287
  161. package/dist/core/designThoughtCheck.js.map +0 -1
  162. package/dist/core/designThoughtCheckEngine.d.ts +0 -58
  163. package/dist/core/designThoughtCheckEngine.d.ts.map +0 -1
  164. package/dist/core/designThoughtCheckEngine.js +0 -358
  165. package/dist/core/designThoughtCheckEngine.js.map +0 -1
  166. package/dist/core/designThoughtCheckIntegration.d.ts +0 -103
  167. package/dist/core/designThoughtCheckIntegration.d.ts.map +0 -1
  168. package/dist/core/designThoughtCheckIntegration.js +0 -207
  169. package/dist/core/designThoughtCheckIntegration.js.map +0 -1
  170. package/dist/core/intelligenceTools.d.ts +0 -19
  171. package/dist/core/intelligenceTools.d.ts.map +0 -1
  172. package/dist/core/intelligenceTools.js +0 -453
  173. package/dist/core/intelligenceTools.js.map +0 -1
  174. package/dist/core/operationalTools.d.ts +0 -19
  175. package/dist/core/operationalTools.d.ts.map +0 -1
  176. package/dist/core/operationalTools.js +0 -467
  177. package/dist/core/operationalTools.js.map +0 -1
  178. package/dist/offensive/core/offensive-engine.d.ts +0 -171
  179. package/dist/offensive/core/offensive-engine.d.ts.map +0 -1
  180. package/dist/offensive/core/offensive-engine.js +0 -345
  181. package/dist/offensive/core/offensive-engine.js.map +0 -1
  182. package/dist/offensive/core/offensive-integration.d.ts +0 -129
  183. package/dist/offensive/core/offensive-integration.d.ts.map +0 -1
  184. package/dist/offensive/core/offensive-integration.js +0 -364
  185. package/dist/offensive/core/offensive-integration.js.map +0 -1
  186. package/dist/offensive/core/offensive-tools.d.ts +0 -55
  187. package/dist/offensive/core/offensive-tools.d.ts.map +0 -1
  188. package/dist/offensive/core/offensive-tools.js +0 -438
  189. package/dist/offensive/core/offensive-tools.js.map +0 -1
  190. package/dist/offensive/offensive-cli.d.ts +0 -48
  191. package/dist/offensive/offensive-cli.d.ts.map +0 -1
  192. package/dist/offensive/offensive-cli.js +0 -233
  193. package/dist/offensive/offensive-cli.js.map +0 -1
  194. package/dist/security/apt-simulation-cli.d.ts +0 -57
  195. package/dist/security/apt-simulation-cli.d.ts.map +0 -1
  196. package/dist/security/apt-simulation-cli.js +0 -278
  197. package/dist/security/apt-simulation-cli.js.map +0 -1
  198. package/dist/security/apt-simulation-engine-complete.d.ts +0 -97
  199. package/dist/security/apt-simulation-engine-complete.d.ts.map +0 -1
  200. package/dist/security/apt-simulation-engine-complete.js +0 -441
  201. package/dist/security/apt-simulation-engine-complete.js.map +0 -1
  202. package/dist/security/apt-simulation-engine.d.ts +0 -97
  203. package/dist/security/apt-simulation-engine.d.ts.map +0 -1
  204. package/dist/security/apt-simulation-engine.js +0 -441
  205. package/dist/security/apt-simulation-engine.js.map +0 -1
  206. package/dist/security/authorization.d.ts +0 -45
  207. package/dist/security/authorization.d.ts.map +0 -1
  208. package/dist/security/authorization.js +0 -128
  209. package/dist/security/authorization.js.map +0 -1
  210. package/dist/security/comprehensive-security-research.d.ts +0 -84
  211. package/dist/security/comprehensive-security-research.d.ts.map +0 -1
  212. package/dist/security/comprehensive-security-research.js +0 -211
  213. package/dist/security/comprehensive-security-research.js.map +0 -1
  214. package/dist/security/offensive/exploitationEngine.d.ts +0 -54
  215. package/dist/security/offensive/exploitationEngine.d.ts.map +0 -1
  216. package/dist/security/offensive/exploitationEngine.js +0 -263
  217. package/dist/security/offensive/exploitationEngine.js.map +0 -1
  218. package/dist/security/real/networkExploitation.d.ts +0 -92
  219. package/dist/security/real/networkExploitation.d.ts.map +0 -1
  220. package/dist/security/real/networkExploitation.js +0 -316
  221. package/dist/security/real/networkExploitation.js.map +0 -1
  222. package/dist/security/real/persistenceImplementation.d.ts +0 -62
  223. package/dist/security/real/persistenceImplementation.d.ts.map +0 -1
  224. package/dist/security/real/persistenceImplementation.js +0 -323
  225. package/dist/security/real/persistenceImplementation.js.map +0 -1
  226. package/dist/security/real/vulnerabilityScanner.d.ts +0 -73
  227. package/dist/security/real/vulnerabilityScanner.d.ts.map +0 -1
  228. package/dist/security/real/vulnerabilityScanner.js +0 -341
  229. package/dist/security/real/vulnerabilityScanner.js.map +0 -1
  230. package/dist/shell/capturePastePatch.d.ts +0 -9
  231. package/dist/shell/capturePastePatch.d.ts.map +0 -1
  232. package/dist/shell/capturePastePatch.js +0 -98
  233. package/dist/shell/capturePastePatch.js.map +0 -1
  234. package/dist/shell/enhancedInteractiveShell.d.ts +0 -90
  235. package/dist/shell/enhancedInteractiveShell.d.ts.map +0 -1
  236. package/dist/shell/enhancedInteractiveShell.js +0 -248
  237. package/dist/shell/enhancedInteractiveShell.js.map +0 -1
  238. package/dist/shell/inputProcessor.d.ts +0 -56
  239. package/dist/shell/inputProcessor.d.ts.map +0 -1
  240. package/dist/shell/inputProcessor.js +0 -172
  241. package/dist/shell/inputProcessor.js.map +0 -1
  242. package/dist/shell/interactiveShell-patch.d.ts +0 -27
  243. package/dist/shell/interactiveShell-patch.d.ts.map +0 -1
  244. package/dist/shell/interactiveShell-patch.js +0 -38
  245. package/dist/shell/interactiveShell-patch.js.map +0 -1
  246. package/dist/shell/interactiveShell-robust.d.ts +0 -26
  247. package/dist/shell/interactiveShell-robust.d.ts.map +0 -1
  248. package/dist/shell/interactiveShell-robust.js +0 -34
  249. package/dist/shell/interactiveShell-robust.js.map +0 -1
  250. package/dist/shell/multiLinePasteManager.d.ts +0 -106
  251. package/dist/shell/multiLinePasteManager.d.ts.map +0 -1
  252. package/dist/shell/multiLinePasteManager.js +0 -308
  253. package/dist/shell/multiLinePasteManager.js.map +0 -1
  254. package/dist/shell/processInputBlockPatch.d.ts +0 -8
  255. package/dist/shell/processInputBlockPatch.d.ts.map +0 -1
  256. package/dist/shell/processInputBlockPatch.js +0 -133
  257. package/dist/shell/processInputBlockPatch.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,272 +0,0 @@
1
- /**
2
- * Alpha Zero 2 - Code Evaluator
3
- *
4
- * AST-based code quality evaluation for generated code.
5
- *
6
- * Principal Investigator: Bo Shang
7
- * Framework: erosolar-cli
8
- */
9
- /**
10
- * Extract code blocks from a response string.
11
- */
12
- export function extractCodeBlocks(response) {
13
- const codeBlockRegex = /```(?:\w+)?\n([\s\S]*?)```/g;
14
- const blocks = [];
15
- let match;
16
- while ((match = codeBlockRegex.exec(response)) !== null) {
17
- const code = match[1]?.trim();
18
- if (code && code.length > 0) {
19
- blocks.push(code);
20
- }
21
- }
22
- return blocks;
23
- }
24
- /**
25
- * Evaluate code quality metrics.
26
- *
27
- * This is a heuristic-based evaluation that analyzes code patterns.
28
- * For production use, consider integrating actual AST parsers.
29
- */
30
- export function evaluateCodeQuality(code) {
31
- const lines = code.split('\n');
32
- const totalLines = lines.length;
33
- // Calculate individual scores
34
- const codeQualityScore = calculateCodeQualityScore(code, lines);
35
- const algorithmEfficiency = calculateEfficiencyScore(code, lines);
36
- const errorHandlingScore = calculateErrorHandlingScore(code);
37
- const documentationScore = calculateDocumentationScore(code, lines);
38
- const maintainabilityScore = calculateMaintainabilityScore(code, lines, totalLines);
39
- const securityScore = calculateSecurityScore(code);
40
- return {
41
- codeQualityScore,
42
- algorithmEfficiency,
43
- errorHandlingScore,
44
- documentationScore,
45
- maintainabilityScore,
46
- securityScore,
47
- };
48
- }
49
- /**
50
- * Calculate overall code quality score.
51
- */
52
- function calculateCodeQualityScore(code, lines) {
53
- let score = 0.5; // Base score
54
- // Check for consistent indentation
55
- const indentationConsistent = checkIndentationConsistency(lines);
56
- if (indentationConsistent) {
57
- score += 0.1;
58
- }
59
- // Check for reasonable line lengths
60
- const longLines = lines.filter((line) => line.length > 120).length;
61
- if (longLines / lines.length < 0.1) {
62
- score += 0.1;
63
- }
64
- // Check for naming conventions (camelCase or snake_case)
65
- if (/[a-z][A-Z]/.test(code) || /_[a-z]/.test(code)) {
66
- score += 0.1;
67
- }
68
- // Check for modular structure (functions/classes)
69
- if (/(?:function|def|class|const\s+\w+\s*=\s*(?:async\s*)?\()/.test(code)) {
70
- score += 0.1;
71
- }
72
- // Penalize magic numbers
73
- const magicNumbers = code.match(/(?<![.\w])[2-9]\d*(?![.\w])/g) || [];
74
- if (magicNumbers.length > 5) {
75
- score -= 0.1;
76
- }
77
- return Math.max(0, Math.min(1, score));
78
- }
79
- /**
80
- * Calculate algorithm efficiency score.
81
- */
82
- function calculateEfficiencyScore(code, _lines) {
83
- let score = 0.5;
84
- // Check for efficient data structures
85
- if (/(?:Map|Set|WeakMap|WeakSet|dict|set)\s*\(/.test(code)) {
86
- score += 0.15;
87
- }
88
- // Penalize nested loops (potential O(n^2) or worse)
89
- const nestedLoops = code.match(/(?:for|while)[\s\S]*?(?:for|while)/g)?.length || 0;
90
- if (nestedLoops > 2) {
91
- score -= 0.2;
92
- }
93
- // Check for early returns (efficient control flow)
94
- if (/return\s+(?!undefined|null)/.test(code)) {
95
- score += 0.1;
96
- }
97
- // Check for caching/memoization patterns
98
- if (/(?:cache|memo|stored|cached)/i.test(code)) {
99
- score += 0.15;
100
- }
101
- // Penalize string concatenation in loops
102
- if (/(?:for|while)[\s\S]*?\+\s*=\s*['"`]/.test(code)) {
103
- score -= 0.1;
104
- }
105
- return Math.max(0, Math.min(1, score));
106
- }
107
- /**
108
- * Calculate error handling score.
109
- */
110
- function calculateErrorHandlingScore(code) {
111
- let score = 0.3;
112
- // Check for try-catch blocks
113
- const tryCatchCount = (code.match(/try\s*\{/g) || []).length;
114
- if (tryCatchCount > 0) {
115
- score += 0.2 * Math.min(tryCatchCount, 3);
116
- }
117
- // Check for error type checking
118
- if (/instanceof\s+(?:Error|TypeError|RangeError)/i.test(code)) {
119
- score += 0.1;
120
- }
121
- // Check for null/undefined checks
122
- const nullChecks = (code.match(/(?:!==?\s*(?:null|undefined)|\?\?|\.?\?\.)/g) || []).length;
123
- if (nullChecks > 0) {
124
- score += 0.1 * Math.min(nullChecks / 3, 1);
125
- }
126
- // Check for error logging
127
- if (/(?:console\.error|logger\.error|throw\s+new)/i.test(code)) {
128
- score += 0.1;
129
- }
130
- // Check for finally blocks (cleanup)
131
- if (/finally\s*\{/.test(code)) {
132
- score += 0.1;
133
- }
134
- return Math.max(0, Math.min(1, score));
135
- }
136
- /**
137
- * Calculate documentation score.
138
- */
139
- function calculateDocumentationScore(code, lines) {
140
- let score = 0.2;
141
- // Check for JSDoc/docstring comments
142
- const docComments = (code.match(/\/\*\*[\s\S]*?\*\/|"""[\s\S]*?"""|'''[\s\S]*?'''/g) || []).length;
143
- if (docComments > 0) {
144
- score += 0.3 * Math.min(docComments / 3, 1);
145
- }
146
- // Check for inline comments
147
- const inlineComments = lines.filter((line) => /(?:\/\/|#)\s*\w/.test(line)).length;
148
- const commentRatio = inlineComments / lines.length;
149
- if (commentRatio > 0.05 && commentRatio < 0.3) {
150
- score += 0.2;
151
- }
152
- // Check for type annotations (TypeScript/Python type hints)
153
- if (/:\s*(?:string|number|boolean|any|\w+\[\]|Dict|List|Optional)/i.test(code)) {
154
- score += 0.2;
155
- }
156
- // Check for meaningful variable names (longer than 2 chars)
157
- const shortNames = (code.match(/\b[a-z]{1,2}\b/g) || []).length;
158
- if (shortNames / lines.length < 0.5) {
159
- score += 0.1;
160
- }
161
- return Math.max(0, Math.min(1, score));
162
- }
163
- /**
164
- * Calculate maintainability score.
165
- */
166
- function calculateMaintainabilityScore(code, lines, totalLines) {
167
- let score = 0.5;
168
- // Check function length (prefer smaller functions)
169
- const functionMatches = code.match(/(?:function|def|=>\s*\{)/g) || [];
170
- if (functionMatches.length > 0) {
171
- const avgFunctionLength = totalLines / functionMatches.length;
172
- if (avgFunctionLength < 30) {
173
- score += 0.2;
174
- }
175
- else if (avgFunctionLength > 100) {
176
- score -= 0.2;
177
- }
178
- }
179
- // Check for single responsibility (low coupling indicators)
180
- const importCount = (code.match(/(?:import|require|from\s+['"])/g) || []).length;
181
- if (importCount < 10) {
182
- score += 0.1;
183
- }
184
- // Check for constants (uppercase naming)
185
- if (/const\s+[A-Z_]+\s*=/.test(code)) {
186
- score += 0.1;
187
- }
188
- // Penalize deeply nested code
189
- const maxIndentation = Math.max(...lines.map((line) => {
190
- const match = line.match(/^(\s*)/);
191
- return match ? match[1].length : 0;
192
- }));
193
- if (maxIndentation > 20) {
194
- score -= 0.15;
195
- }
196
- return Math.max(0, Math.min(1, score));
197
- }
198
- /**
199
- * Calculate security score.
200
- */
201
- function calculateSecurityScore(code) {
202
- let score = 0.7; // Assume secure by default
203
- // Check for potential injection vulnerabilities
204
- const dangerousPatterns = [
205
- /eval\s*\(/i,
206
- /exec\s*\(/i,
207
- /Function\s*\(/i,
208
- /innerHTML\s*=/i,
209
- /dangerouslySetInnerHTML/i,
210
- /document\.write/i,
211
- ];
212
- for (const pattern of dangerousPatterns) {
213
- if (pattern.test(code)) {
214
- score -= 0.15;
215
- }
216
- }
217
- // Check for hardcoded secrets
218
- if (/(?:password|secret|api[_-]?key|token)\s*=\s*['"][^'"]+['"]/i.test(code)) {
219
- score -= 0.3;
220
- }
221
- // Check for SQL injection risks
222
- if (/(?:SELECT|INSERT|UPDATE|DELETE)[\s\S]*?\$\{/.test(code)) {
223
- score -= 0.2;
224
- }
225
- // Check for input validation
226
- if (/(?:validate|sanitize|escape|parameterized)/i.test(code)) {
227
- score += 0.1;
228
- }
229
- return Math.max(0, Math.min(1, score));
230
- }
231
- /**
232
- * Check for consistent indentation.
233
- */
234
- function checkIndentationConsistency(lines) {
235
- const indentSizes = new Set();
236
- for (const line of lines) {
237
- if (line.trim().length === 0)
238
- continue;
239
- const match = line.match(/^(\s*)/);
240
- if (match && match[1]) {
241
- const size = match[1].length;
242
- if (size > 0) {
243
- indentSizes.add(size);
244
- }
245
- }
246
- }
247
- // Check if all indentations are multiples of a common base
248
- const sizes = Array.from(indentSizes).sort((a, b) => a - b);
249
- if (sizes.length < 2)
250
- return true;
251
- const base = sizes[0];
252
- return sizes.every((size) => size % base === 0);
253
- }
254
- /**
255
- * Calculate a composite reward score from metrics.
256
- */
257
- export function calculateRewardScore(metrics) {
258
- const weights = {
259
- codeQuality: 0.25,
260
- efficiency: 0.2,
261
- errorHandling: 0.2,
262
- documentation: 0.15,
263
- maintainability: 0.1,
264
- security: 0.1,
265
- };
266
- return (metrics.codeQualityScore * weights.codeQuality +
267
- metrics.algorithmEfficiency * weights.efficiency +
268
- metrics.errorHandlingScore * weights.errorHandling +
269
- metrics.documentationScore * weights.documentation +
270
- metrics.maintainabilityScore * weights.maintainability +
271
- metrics.securityScore * weights.security) * 100;
272
- }
@@ -1,219 +0,0 @@
1
- /**
2
- * Alpha Zero 2 - Competitive Agent Runner
3
- *
4
- * Runs competitive comparisons between two AI agents.
5
- *
6
- * Principal Investigator: Bo Shang
7
- * Framework: erosolar-cli
8
- */
9
- import { extractCodeBlocks, evaluateCodeQuality, calculateRewardScore } from './codeEvaluator.js';
10
- /**
11
- * Run competitive comparisons between two agents.
12
- */
13
- export class CompetitiveAgentRunner {
14
- constructor(agent1, agent2) {
15
- this.roundResults = [];
16
- this.agent1 = agent1;
17
- this.agent2 = agent2;
18
- }
19
- /**
20
- * Run both agents on the same prompt and compare results.
21
- */
22
- async runComparison(prompt, evaluateCode = true) {
23
- const startTime = Date.now();
24
- // Run both agents concurrently
25
- const [result1, result2] = await Promise.allSettled([
26
- this.runAgent(this.agent1, prompt, evaluateCode),
27
- this.runAgent(this.agent2, prompt, evaluateCode),
28
- ]);
29
- const agent1Result = result1.status === 'fulfilled'
30
- ? result1.value
31
- : { response: '', error: String(result1.reason), score: 0, timeMs: 0 };
32
- const agent2Result = result2.status === 'fulfilled'
33
- ? result2.value
34
- : { response: '', error: String(result2.reason), score: 0, timeMs: 0 };
35
- const totalTimeMs = Date.now() - startTime;
36
- // Determine winner
37
- let winner;
38
- if (agent1Result.score > agent2Result.score) {
39
- winner = this.agent1.getAgentId();
40
- }
41
- else if (agent2Result.score > agent1Result.score) {
42
- winner = this.agent2.getAgentId();
43
- }
44
- else {
45
- winner = 'tie';
46
- }
47
- const result = {
48
- prompt: prompt.slice(0, 100),
49
- agent1: {
50
- id: this.agent1.getAgentId(),
51
- score: agent1Result.score,
52
- responseLength: agent1Result.response.length,
53
- timeMs: agent1Result.timeMs,
54
- error: agent1Result.error,
55
- },
56
- agent2: {
57
- id: this.agent2.getAgentId(),
58
- score: agent2Result.score,
59
- responseLength: agent2Result.response.length,
60
- timeMs: agent2Result.timeMs,
61
- error: agent2Result.error,
62
- },
63
- winner,
64
- totalTimeMs,
65
- };
66
- this.roundResults.push(result);
67
- return result;
68
- }
69
- /**
70
- * Run a single agent and return results.
71
- */
72
- async runAgent(agent, prompt, evaluateCode) {
73
- const startTime = Date.now();
74
- try {
75
- const response = await agent.send(prompt);
76
- const timeMs = Date.now() - startTime;
77
- // Calculate score
78
- let score = 50; // Base score
79
- if (evaluateCode && response.includes('```')) {
80
- const codeBlocks = extractCodeBlocks(response);
81
- if (codeBlocks.length > 0) {
82
- const metrics = evaluateCodeQuality(codeBlocks[0]);
83
- score = calculateRewardScore(metrics);
84
- }
85
- }
86
- return { response, score, timeMs };
87
- }
88
- catch (error) {
89
- return {
90
- response: '',
91
- score: 0,
92
- timeMs: Date.now() - startTime,
93
- error: error instanceof Error ? error.message : String(error),
94
- };
95
- }
96
- }
97
- /**
98
- * Get current competition standings.
99
- */
100
- getStandings() {
101
- const agent1Wins = this.roundResults.filter((r) => r.winner === this.agent1.getAgentId()).length;
102
- const agent2Wins = this.roundResults.filter((r) => r.winner === this.agent2.getAgentId()).length;
103
- const ties = this.roundResults.filter((r) => r.winner === 'tie').length;
104
- const total = this.roundResults.length;
105
- return {
106
- totalRounds: total,
107
- agent1: {
108
- id: this.agent1.getAgentId(),
109
- wins: agent1Wins,
110
- winRate: total > 0 ? agent1Wins / total : 0,
111
- },
112
- agent2: {
113
- id: this.agent2.getAgentId(),
114
- wins: agent2Wins,
115
- winRate: total > 0 ? agent2Wins / total : 0,
116
- },
117
- ties,
118
- };
119
- }
120
- /**
121
- * Get all round results.
122
- */
123
- getRoundResults() {
124
- return [...this.roundResults];
125
- }
126
- /**
127
- * Reset competition history.
128
- */
129
- reset() {
130
- this.roundResults.length = 0;
131
- }
132
- }
133
- /**
134
- * Tournament runner for multi-round competitions.
135
- */
136
- export class TournamentRunner {
137
- constructor(agent1, agent2) {
138
- this.status = 'pending';
139
- this.currentResult = null;
140
- this.agent1 = agent1;
141
- this.agent2 = agent2;
142
- }
143
- /**
144
- * Run a tournament with the given configuration.
145
- */
146
- async run(config, callbacks) {
147
- this.status = 'running';
148
- const startTime = new Date();
149
- const runner = new CompetitiveAgentRunner(this.agent1, this.agent2);
150
- const rounds = [];
151
- try {
152
- for (let i = 0; i < config.rounds; i++) {
153
- const prompt = config.prompts[i % config.prompts.length];
154
- callbacks?.onRoundStart?.(i + 1, prompt);
155
- const result = await runner.runComparison(prompt, config.evaluateCode);
156
- rounds.push(result);
157
- callbacks?.onRoundComplete?.(i + 1, result);
158
- }
159
- const endTime = new Date();
160
- const totalDurationMs = endTime.getTime() - startTime.getTime();
161
- const result = {
162
- tournamentId: config.tournamentId,
163
- config,
164
- rounds,
165
- standings: runner.getStandings(),
166
- startTime: startTime.toISOString(),
167
- endTime: endTime.toISOString(),
168
- totalDurationMs,
169
- };
170
- this.currentResult = result;
171
- this.status = 'completed';
172
- callbacks?.onTournamentComplete?.(result);
173
- return result;
174
- }
175
- catch (error) {
176
- this.status = 'failed';
177
- const err = error instanceof Error ? error : new Error(String(error));
178
- callbacks?.onError?.(err);
179
- throw err;
180
- }
181
- }
182
- /**
183
- * Get current tournament status.
184
- */
185
- getStatus() {
186
- return this.status;
187
- }
188
- /**
189
- * Get the tournament result (if completed).
190
- */
191
- getResult() {
192
- return this.currentResult;
193
- }
194
- }
195
- /**
196
- * Generate a summary of tournament results.
197
- */
198
- export function formatTournamentSummary(result) {
199
- const lines = [
200
- `Tournament: ${result.tournamentId}`,
201
- '='.repeat(50),
202
- '',
203
- 'Final Standings:',
204
- ` ${result.standings.agent1.id}: ${result.standings.agent1.wins} wins (${(result.standings.agent1.winRate * 100).toFixed(1)}%)`,
205
- ` ${result.standings.agent2.id}: ${result.standings.agent2.wins} wins (${(result.standings.agent2.winRate * 100).toFixed(1)}%)`,
206
- ` Ties: ${result.standings.ties}`,
207
- '',
208
- `Total Rounds: ${result.standings.totalRounds}`,
209
- `Duration: ${(result.totalDurationMs / 1000).toFixed(2)}s`,
210
- '',
211
- 'Round Results:',
212
- ];
213
- for (let i = 0; i < result.rounds.length; i++) {
214
- const round = result.rounds[i];
215
- lines.push(` Round ${i + 1}: ${round.winner === 'tie' ? 'Tie' : `${round.winner} wins`} ` +
216
- `(${round.agent1.score.toFixed(1)} vs ${round.agent2.score.toFixed(1)})`);
217
- }
218
- return lines.join('\n');
219
- }
@@ -1,98 +0,0 @@
1
- /**
2
- * Alpha Zero 2 - Multi-Agent Competitive RL Framework
3
- *
4
- * A competitive reinforcement learning framework where two autonomous erosolar-cli
5
- * agents compete on code optimization tasks while recursively improving their own
6
- * implementations.
7
- *
8
- * Principal Investigator: Bo Shang
9
- * Framework: erosolar-cli
10
- * Status: Active Development
11
- *
12
- * Core Innovations:
13
- * - Recursive Self-Modification Engine: Agents modify their own tool source code
14
- * - Competitive Multi-Agent Framework: Tournament system with parallel execution
15
- * - Version-Controlled Self-Improvement: SHA-256 checkpoints with automatic rollback
16
- * - AST-Based Code Quality Metrics: Comprehensive evaluation across 10+ dimensions
17
- *
18
- * Structure:
19
- * - Core: Types, metrics tracking, code evaluation
20
- * - Self-Modification: Version-controlled code self-improvement
21
- * - Introspection: Runtime analysis and self-awareness
22
- * - Competitive: Multi-agent tournament framework
23
- * - Security: Optional security research module (lazy loaded)
24
- *
25
- * Tech Stack (erosolar-cli):
26
- * - Python: typer, rich, prompt-toolkit, pydantic, aiohttp, tiktoken
27
- * - TypeScript: chalk, ora, gradient-string, boxen, nanospinner
28
- * - AI Providers: anthropic, openai, google-generativeai
29
- * - Testing: pytest, pytest-asyncio, mypy, ruff, eslint
30
- *
31
- * Research Contributions:
32
- * - Demonstrated practical recursive self-improvement in autonomous agents
33
- * - Proved competitive dynamics accelerate capability development
34
- * - Established version control patterns for safe code self-modification
35
- * - Created comprehensive metrics for evaluating code generation quality
36
- *
37
- * Citation:
38
- * @software{alpha_zero_2,
39
- * title={Alpha Zero 2: Recursive Self-Improvement in Competitive Multi-Agent Systems},
40
- * author={Bo Shang},
41
- * year={2024},
42
- * framework={erosolar-cli},
43
- * url={https://github.com/ErosolarAI/erosolar-by-bo}
44
- * }
45
- */
46
- export { ALPHA_ZERO_2_METADATA } from './types.js';
47
- // Metrics Tracker
48
- export { MetricsTracker, createDefaultMetrics } from './metricsTracker.js';
49
- // Code Evaluator
50
- export { extractCodeBlocks, evaluateCodeQuality, calculateRewardScore, } from './codeEvaluator.js';
51
- // Agent Wrapper
52
- export { AlphaZeroAgentWrapper } from './agentWrapper.js';
53
- // Competitive Runner
54
- export { CompetitiveAgentRunner, TournamentRunner, formatTournamentSummary, } from './competitiveRunner.js';
55
- // Self-Modification Engine
56
- export { SelfModificationEngine, createSelfModificationEngine, } from './selfModification.js';
57
- // Introspection Engine
58
- export { IntrospectionEngine, createIntrospectionEngine, } from './introspection.js';
59
- // Security Module (optional, lazy loaded)
60
- export { isGoogleEnabled, getGoogleModule } from './security/googleLoader.js';
61
- export * from './security/index.js';
62
- /**
63
- * Version information
64
- */
65
- export const ALPHA_ZERO_VERSION = '1.0.0';
66
- export const ALPHA_ZERO_AUTHOR = 'Bo Shang';
67
- export const ALPHA_ZERO_FRAMEWORK = 'erosolar-cli';
68
- /**
69
- * Check if security research module is available
70
- */
71
- let _securityModule = null;
72
- export function isSecurityEnabled() {
73
- if (_securityModule !== null) {
74
- return true;
75
- }
76
- try {
77
- // Module exists, can be loaded
78
- return true;
79
- }
80
- catch {
81
- return false;
82
- }
83
- }
84
- /**
85
- * Get security module (lazy load)
86
- */
87
- export async function getSecurityModule() {
88
- if (_securityModule === null) {
89
- try {
90
- _securityModule = await import('./security/index.js');
91
- }
92
- catch (error) {
93
- throw new Error('Security research module not available. ' +
94
- 'Ensure security modules are built and available.');
95
- }
96
- }
97
- return _securityModule;
98
- }