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,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self-Modification Engine for Alpha Zero 2
|
|
3
|
+
*
|
|
4
|
+
* Enables autonomous code self-modification with version control.
|
|
5
|
+
* Agents can modify their own tool source code based on performance feedback.
|
|
6
|
+
*
|
|
7
|
+
* Principal Investigator: Bo Shang
|
|
8
|
+
* Framework: erosolar-cli
|
|
9
|
+
*/
|
|
10
|
+
import * as crypto from 'crypto';
|
|
11
|
+
import * as fs from 'fs/promises';
|
|
12
|
+
import * as path from 'path';
|
|
13
|
+
const DEFAULT_CONFIG = {
|
|
14
|
+
dataDir: '.alpha_zero_versions',
|
|
15
|
+
maxVersions: 100,
|
|
16
|
+
enableAutoRollback: true,
|
|
17
|
+
minQualityThreshold: 0.7,
|
|
18
|
+
verbose: false,
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Self-Modification Engine
|
|
22
|
+
*
|
|
23
|
+
* Manages version-controlled code modifications with automatic rollback.
|
|
24
|
+
*/
|
|
25
|
+
export class SelfModificationEngine {
|
|
26
|
+
constructor(config = {}) {
|
|
27
|
+
this.versions = new Map();
|
|
28
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Create a checkpoint of current tool code
|
|
32
|
+
*/
|
|
33
|
+
async createCheckpoint(toolId, sourceCode, metrics) {
|
|
34
|
+
const hash = this.computeHash(sourceCode);
|
|
35
|
+
const versionId = `${toolId}-${Date.now()}-${hash.slice(0, 8)}`;
|
|
36
|
+
const toolVersions = this.versions.get(toolId) || [];
|
|
37
|
+
const lastVersion = toolVersions.length > 0 ? toolVersions[toolVersions.length - 1] : undefined;
|
|
38
|
+
const parentVersion = lastVersion?.versionId;
|
|
39
|
+
const version = {
|
|
40
|
+
versionId,
|
|
41
|
+
hash,
|
|
42
|
+
timestamp: Date.now(),
|
|
43
|
+
sourceCode,
|
|
44
|
+
performanceMetrics: metrics,
|
|
45
|
+
parentVersion,
|
|
46
|
+
};
|
|
47
|
+
toolVersions.push(version);
|
|
48
|
+
this.versions.set(toolId, toolVersions);
|
|
49
|
+
// Persist to disk
|
|
50
|
+
await this.saveVersion(toolId, version);
|
|
51
|
+
if (this.config.verbose) {
|
|
52
|
+
console.log(`[SelfMod] Created checkpoint ${versionId}`);
|
|
53
|
+
}
|
|
54
|
+
return version;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Attempt to modify tool code
|
|
58
|
+
*/
|
|
59
|
+
async modifyTool(toolId, currentCode, modifiedCode, testFn) {
|
|
60
|
+
// Create checkpoint of current code
|
|
61
|
+
const currentVersion = await this.createCheckpoint(toolId, currentCode);
|
|
62
|
+
// Test modified code if test function provided
|
|
63
|
+
let testResult;
|
|
64
|
+
if (testFn) {
|
|
65
|
+
try {
|
|
66
|
+
testResult = await testFn(modifiedCode);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
return {
|
|
70
|
+
success: false,
|
|
71
|
+
previousVersion: currentVersion,
|
|
72
|
+
error: `Test execution failed: ${error}`,
|
|
73
|
+
rolledBack: false,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
// Check if tests pass
|
|
77
|
+
if (!testResult.passed && this.config.enableAutoRollback) {
|
|
78
|
+
if (this.config.verbose) {
|
|
79
|
+
console.log(`[SelfMod] Tests failed, rolling back`);
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
success: false,
|
|
83
|
+
previousVersion: currentVersion,
|
|
84
|
+
error: `Tests failed: ${testResult.failedTests}/${testResult.totalTests}`,
|
|
85
|
+
rolledBack: true,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// Create new version
|
|
90
|
+
const newVersion = await this.createCheckpoint(toolId, modifiedCode, {
|
|
91
|
+
executionTimeMs: 0,
|
|
92
|
+
memoryUsageMb: 0,
|
|
93
|
+
errorCount: testResult?.failedTests || 0,
|
|
94
|
+
successRate: testResult ? testResult.passedTests / testResult.totalTests : 1,
|
|
95
|
+
qualityScore: this.evaluateCodeQuality(modifiedCode),
|
|
96
|
+
});
|
|
97
|
+
newVersion.testResults = testResult;
|
|
98
|
+
// Calculate performance delta
|
|
99
|
+
const performanceDelta = newVersion.performanceMetrics && currentVersion.performanceMetrics
|
|
100
|
+
? newVersion.performanceMetrics.qualityScore - currentVersion.performanceMetrics.qualityScore
|
|
101
|
+
: 0;
|
|
102
|
+
return {
|
|
103
|
+
success: true,
|
|
104
|
+
newVersion,
|
|
105
|
+
previousVersion: currentVersion,
|
|
106
|
+
performanceDelta,
|
|
107
|
+
rolledBack: false,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Rollback to a previous version
|
|
112
|
+
*/
|
|
113
|
+
async rollback(toolId, targetVersionId) {
|
|
114
|
+
const toolVersions = this.versions.get(toolId);
|
|
115
|
+
if (!toolVersions || toolVersions.length < 2) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
if (targetVersionId) {
|
|
119
|
+
const targetIndex = toolVersions.findIndex(v => v.versionId === targetVersionId);
|
|
120
|
+
if (targetIndex === -1)
|
|
121
|
+
return null;
|
|
122
|
+
// Remove versions after target
|
|
123
|
+
const removedVersions = toolVersions.splice(targetIndex + 1);
|
|
124
|
+
if (this.config.verbose) {
|
|
125
|
+
console.log(`[SelfMod] Rolled back ${removedVersions.length} versions`);
|
|
126
|
+
}
|
|
127
|
+
return toolVersions[targetIndex] ?? null;
|
|
128
|
+
}
|
|
129
|
+
// Rollback to previous version
|
|
130
|
+
toolVersions.pop();
|
|
131
|
+
return toolVersions[toolVersions.length - 1] ?? null;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Get version history for a tool
|
|
135
|
+
*/
|
|
136
|
+
getVersionHistory(toolId) {
|
|
137
|
+
return this.versions.get(toolId) || [];
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Get current version of a tool
|
|
141
|
+
*/
|
|
142
|
+
getCurrentVersion(toolId) {
|
|
143
|
+
const versions = this.versions.get(toolId);
|
|
144
|
+
return versions && versions.length > 0 ? (versions[versions.length - 1] ?? null) : null;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Compare two versions
|
|
148
|
+
*/
|
|
149
|
+
compareVersions(version1, version2) {
|
|
150
|
+
const codeChanged = version1.hash !== version2.hash;
|
|
151
|
+
const q1 = version1.performanceMetrics?.qualityScore || 0;
|
|
152
|
+
const q2 = version2.performanceMetrics?.qualityScore || 0;
|
|
153
|
+
return {
|
|
154
|
+
codeChanged,
|
|
155
|
+
performanceImproved: q2 > q1,
|
|
156
|
+
qualityDelta: q2 - q1,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Evaluate code quality (simplified AST-based analysis)
|
|
161
|
+
*/
|
|
162
|
+
evaluateCodeQuality(code) {
|
|
163
|
+
let score = 0.5; // Base score
|
|
164
|
+
// Check for documentation
|
|
165
|
+
if (code.includes('/**') || code.includes('///')) {
|
|
166
|
+
score += 0.1;
|
|
167
|
+
}
|
|
168
|
+
// Check for error handling
|
|
169
|
+
if (code.includes('try') && code.includes('catch')) {
|
|
170
|
+
score += 0.1;
|
|
171
|
+
}
|
|
172
|
+
// Check for type annotations (TypeScript)
|
|
173
|
+
if (code.includes(': string') || code.includes(': number') || code.includes(': boolean')) {
|
|
174
|
+
score += 0.1;
|
|
175
|
+
}
|
|
176
|
+
// Check for async/await patterns
|
|
177
|
+
if (code.includes('async') && code.includes('await')) {
|
|
178
|
+
score += 0.05;
|
|
179
|
+
}
|
|
180
|
+
// Penalize very long functions
|
|
181
|
+
const lines = code.split('\n').length;
|
|
182
|
+
if (lines > 200) {
|
|
183
|
+
score -= 0.1;
|
|
184
|
+
}
|
|
185
|
+
return Math.max(0, Math.min(1, score));
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Compute SHA-256 hash of code
|
|
189
|
+
*/
|
|
190
|
+
computeHash(code) {
|
|
191
|
+
return crypto.createHash('sha256').update(code).digest('hex');
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Save version to disk
|
|
195
|
+
*/
|
|
196
|
+
async saveVersion(toolId, version) {
|
|
197
|
+
const dir = path.join(this.config.dataDir, toolId);
|
|
198
|
+
await fs.mkdir(dir, { recursive: true });
|
|
199
|
+
const filePath = path.join(dir, `${version.versionId}.json`);
|
|
200
|
+
await fs.writeFile(filePath, JSON.stringify(version, null, 2));
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Load versions from disk
|
|
204
|
+
*/
|
|
205
|
+
async loadVersions(toolId) {
|
|
206
|
+
const dir = path.join(this.config.dataDir, toolId);
|
|
207
|
+
try {
|
|
208
|
+
const files = await fs.readdir(dir);
|
|
209
|
+
const versions = [];
|
|
210
|
+
for (const file of files) {
|
|
211
|
+
if (file.endsWith('.json')) {
|
|
212
|
+
const content = await fs.readFile(path.join(dir, file), 'utf-8');
|
|
213
|
+
versions.push(JSON.parse(content));
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
// Sort by timestamp
|
|
217
|
+
versions.sort((a, b) => a.timestamp - b.timestamp);
|
|
218
|
+
this.versions.set(toolId, versions);
|
|
219
|
+
return versions;
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
return [];
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Create a default self-modification engine
|
|
228
|
+
*/
|
|
229
|
+
export function createSelfModificationEngine(config) {
|
|
230
|
+
return new SelfModificationEngine(config);
|
|
231
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Alpha Zero 2 - Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* Core type definitions for the competitive multi-agent RL framework.
|
|
5
|
+
*
|
|
6
|
+
* Principal Investigator: Bo Shang
|
|
7
|
+
* Framework: erosolar-cli
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Default research metadata.
|
|
11
|
+
*/
|
|
12
|
+
export const ALPHA_ZERO_2_METADATA = {
|
|
13
|
+
projectName: 'Alpha Zero 2',
|
|
14
|
+
version: '1.0.0',
|
|
15
|
+
author: 'Bo Shang',
|
|
16
|
+
framework: 'erosolar-cli',
|
|
17
|
+
description: 'Recursive Self-Improvement in Competitive Multi-Agent Systems',
|
|
18
|
+
innovations: [
|
|
19
|
+
'Recursive Self-Modification Engine: Agents modify their own tool source code',
|
|
20
|
+
'Competitive Multi-Agent Framework: Tournament system with parallel execution',
|
|
21
|
+
'Version-Controlled Self-Improvement: SHA-256 checkpoints with automatic rollback',
|
|
22
|
+
'AST-Based Code Quality Metrics: Comprehensive evaluation across 10+ dimensions',
|
|
23
|
+
],
|
|
24
|
+
techStack: {
|
|
25
|
+
python: ['typer', 'rich', 'prompt-toolkit', 'pydantic', 'aiohttp', 'tiktoken'],
|
|
26
|
+
typescript: ['chalk', 'ora', 'gradient-string', 'boxen', 'nanospinner'],
|
|
27
|
+
aiProviders: ['anthropic', 'openai', 'google-generativeai'],
|
|
28
|
+
testing: ['pytest', 'pytest-asyncio', 'mypy', 'ruff', 'eslint'],
|
|
29
|
+
},
|
|
30
|
+
};
|
|
@@ -0,0 +1,205 @@
|
|
|
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
|
+
// Fast-path command handling
|
|
15
|
+
function handleFastPathCommand(argv) {
|
|
16
|
+
const command = argv[0];
|
|
17
|
+
switch (command) {
|
|
18
|
+
case '--version':
|
|
19
|
+
case 'version':
|
|
20
|
+
case '-v':
|
|
21
|
+
console.log(`Erosolar CLI v${getPackageVersion()}`);
|
|
22
|
+
return true;
|
|
23
|
+
case '--help':
|
|
24
|
+
case 'help':
|
|
25
|
+
case '-h':
|
|
26
|
+
showFastHelp();
|
|
27
|
+
return true;
|
|
28
|
+
case '--json':
|
|
29
|
+
// Defer to full implementation for JSON mode
|
|
30
|
+
return false;
|
|
31
|
+
case 'health-check':
|
|
32
|
+
// This will be handled in main async function
|
|
33
|
+
return false;
|
|
34
|
+
case 'status':
|
|
35
|
+
showStatus();
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
// Get package version without full initialization
|
|
41
|
+
function getPackageVersion() {
|
|
42
|
+
try {
|
|
43
|
+
const filePath = fileURLToPath(import.meta.url);
|
|
44
|
+
const packagePath = resolve(dirname(filePath), '../../package.json');
|
|
45
|
+
const payload = JSON.parse(readFileSync(packagePath, 'utf8'));
|
|
46
|
+
return typeof payload.version === 'string' ? payload.version : '0.0.0';
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return '0.0.0';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// Fast help without full initialization
|
|
53
|
+
function showFastHelp() {
|
|
54
|
+
console.log(`
|
|
55
|
+
Erosolar CLI v${getPackageVersion()} - Fast Help
|
|
56
|
+
|
|
57
|
+
Usage:
|
|
58
|
+
erosolar [command] [options]
|
|
59
|
+
|
|
60
|
+
Fast Commands:
|
|
61
|
+
version, -v Show version
|
|
62
|
+
help, -h Show this help
|
|
63
|
+
status Show system status
|
|
64
|
+
|
|
65
|
+
Full Commands:
|
|
66
|
+
[interactive] Start interactive shell
|
|
67
|
+
--json <command> Run command in JSON mode
|
|
68
|
+
health-check Run health check
|
|
69
|
+
|
|
70
|
+
Options:
|
|
71
|
+
--provider <name> Specify AI provider
|
|
72
|
+
--model <name> Specify AI model
|
|
73
|
+
--profile <name> Use specific agent profile
|
|
74
|
+
|
|
75
|
+
Examples:
|
|
76
|
+
erosolar version
|
|
77
|
+
erosolar --json "list files"
|
|
78
|
+
erosolar --provider openai --model gpt-4
|
|
79
|
+
`);
|
|
80
|
+
}
|
|
81
|
+
// Run health check without full initialization
|
|
82
|
+
async function runHealthCheck() {
|
|
83
|
+
console.log('🧪 Running fast health check...\n');
|
|
84
|
+
const checks = [
|
|
85
|
+
{ name: 'Node.js version', check: checkNodeVersion },
|
|
86
|
+
{ name: 'Package configuration', check: checkPackageConfig },
|
|
87
|
+
{ name: 'Build directory', check: checkBuildDir },
|
|
88
|
+
{ name: 'Main binary', check: checkMainBinary },
|
|
89
|
+
];
|
|
90
|
+
let passed = 0;
|
|
91
|
+
let failed = 0;
|
|
92
|
+
for (const { name, check } of checks) {
|
|
93
|
+
try {
|
|
94
|
+
await check();
|
|
95
|
+
console.log(`✅ ${name}`);
|
|
96
|
+
passed++;
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
console.log(`❌ ${name}: ${error instanceof Error ? error.message : error}`);
|
|
100
|
+
failed++;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
console.log(`\n📊 Results: ${passed} passed, ${failed} failed`);
|
|
104
|
+
if (failed > 0) {
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// Check Node.js version
|
|
109
|
+
function checkNodeVersion() {
|
|
110
|
+
const version = process.version;
|
|
111
|
+
const major = parseInt(version.slice(1).split('.')[0], 10);
|
|
112
|
+
if (major < 20) {
|
|
113
|
+
throw new Error(`Node.js ${version} is too old, requires >=20.0.0`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// Check package configuration
|
|
117
|
+
function checkPackageConfig() {
|
|
118
|
+
const filePath = fileURLToPath(import.meta.url);
|
|
119
|
+
const packagePath = resolve(dirname(filePath), '../../package.json');
|
|
120
|
+
if (!readFileSync(packagePath, 'utf8')) {
|
|
121
|
+
throw new Error('Package.json not found or empty');
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Check build directory
|
|
125
|
+
function checkBuildDir() {
|
|
126
|
+
const filePath = fileURLToPath(import.meta.url);
|
|
127
|
+
const buildPath = resolve(dirname(filePath), '../../dist');
|
|
128
|
+
try {
|
|
129
|
+
const stats = readFileSync(buildPath);
|
|
130
|
+
if (!stats) {
|
|
131
|
+
throw new Error('Build directory does not exist');
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
throw new Error('Build directory does not exist');
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// Check main binary
|
|
139
|
+
function checkMainBinary() {
|
|
140
|
+
const filePath = fileURLToPath(import.meta.url);
|
|
141
|
+
const binaryPath = resolve(dirname(filePath), '../../dist/bin/erosolar.js');
|
|
142
|
+
try {
|
|
143
|
+
const stats = readFileSync(binaryPath);
|
|
144
|
+
if (!stats) {
|
|
145
|
+
throw new Error('Main binary does not exist');
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
throw new Error('Main binary does not exist');
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
// Show system status
|
|
153
|
+
function showStatus() {
|
|
154
|
+
console.log(`
|
|
155
|
+
Erosolar CLI Status
|
|
156
|
+
───────────────────
|
|
157
|
+
Version: ${getPackageVersion()}
|
|
158
|
+
Node.js: ${process.version}
|
|
159
|
+
Platform: ${process.platform} ${process.arch}
|
|
160
|
+
Working Directory: ${process.cwd()}
|
|
161
|
+
|
|
162
|
+
Fast Commands: ✅ Available
|
|
163
|
+
Full Shell: ⚠️ May be slow to initialize
|
|
164
|
+
Health Check: ✅ Available
|
|
165
|
+
`);
|
|
166
|
+
}
|
|
167
|
+
// Main execution
|
|
168
|
+
async function main() {
|
|
169
|
+
const argv = process.argv.slice(2);
|
|
170
|
+
// Handle fast-path commands
|
|
171
|
+
if (handleFastPathCommand(argv)) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
// Handle health check (needs to be async)
|
|
175
|
+
if (argv[0] === 'health-check') {
|
|
176
|
+
await runHealthCheck();
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
// Defer to full implementation for complex commands
|
|
180
|
+
console.log('🚀 Starting full Erosolar CLI...');
|
|
181
|
+
console.log('⏳ This may take a moment for complex initialization...\n');
|
|
182
|
+
try {
|
|
183
|
+
if (argv.includes('--json')) {
|
|
184
|
+
const { runHeadlessApp } = await import('../headless/headlessApp.js');
|
|
185
|
+
await runHeadlessApp({ argv });
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
const { launchShell } = await import('../shell/shellApp.js');
|
|
189
|
+
await launchShell('erosolar-code', { enableProfileSelection: true });
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
console.error('\n❌ CLI Error:', error instanceof Error ? error.message : error);
|
|
194
|
+
// Provide helpful suggestions
|
|
195
|
+
if (error instanceof Error && error.message.includes('Cannot find module')) {
|
|
196
|
+
console.log('\n💡 Try running: npm run build');
|
|
197
|
+
}
|
|
198
|
+
process.exit(1);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
// Start the application
|
|
202
|
+
main().catch((error) => {
|
|
203
|
+
console.error('Fatal error:', error instanceof Error ? error.message : error);
|
|
204
|
+
process.exit(1);
|
|
205
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { TaskRunner } from '../subagents/taskRunner.js';
|
|
2
|
+
export class AgentSpawningCapabilityModule {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.id = 'capability.agent-spawning';
|
|
5
|
+
}
|
|
6
|
+
async create(context) {
|
|
7
|
+
const runner = new TaskRunner(context);
|
|
8
|
+
return {
|
|
9
|
+
id: 'agent-spawning.tools',
|
|
10
|
+
description: 'Launch specialized agents to handle complex, multi-step tasks autonomously',
|
|
11
|
+
toolSuite: {
|
|
12
|
+
id: 'agent-spawning',
|
|
13
|
+
description: 'Task agent spawning and management',
|
|
14
|
+
tools: [
|
|
15
|
+
{
|
|
16
|
+
name: 'Task',
|
|
17
|
+
description: `Launch a new agent to handle complex, multi-step tasks autonomously.
|
|
18
|
+
|
|
19
|
+
The Task tool launches specialized agents (subprocesses) that autonomously handle complex tasks. Each agent type has specific capabilities and tools available to it.
|
|
20
|
+
|
|
21
|
+
Available agent types and the tools they have access to:
|
|
22
|
+
- general-purpose: General-purpose agent for researching complex questions, searching for code, and executing multi-step tasks. When you are searching for a keyword or file and are not confident that you will find the right match in the first few tries use this agent to perform the search for you. (Tools: *)
|
|
23
|
+
- Explore: Fast agent specialized for exploring codebases. Use this when you need to quickly find files by patterns (eg. "src/components/**/*.tsx"), search code for keywords (eg. "API endpoints"), or answer questions about the codebase (eg. "how do API endpoints work?"). When calling this agent, specify the desired thoroughness level: "quick" for basic searches, "medium" for moderate exploration, or "very thorough" for comprehensive analysis across multiple locations and naming conventions. (Tools: All tools)
|
|
24
|
+
- Plan: Fast agent specialized for planning tasks. Use this when you need to break down complex tasks into steps, analyze requirements, or create implementation strategies. (Tools: All tools)
|
|
25
|
+
|
|
26
|
+
When using the Task tool, you must specify a subagent_type parameter to select which agent type to use.
|
|
27
|
+
|
|
28
|
+
When NOT to use the Task tool:
|
|
29
|
+
- If you want to read a specific file path, use the Read or Glob tool instead of the Task tool, to find the match more quickly
|
|
30
|
+
- If you are searching for a specific class definition like "class Foo", use the Glob tool instead, to find the match more quickly
|
|
31
|
+
- If you are searching for code within a specific file or set of 2-3 files, use the Read tool instead of the Task tool, to find the match more quickly
|
|
32
|
+
- Other tasks that are not related to the agent descriptions above
|
|
33
|
+
|
|
34
|
+
Usage notes:
|
|
35
|
+
- Launch multiple agents concurrently whenever possible, to maximize performance; to do that, use a single message with multiple tool uses
|
|
36
|
+
- When the agent is done, it will return a single message back to you. The result returned by the agent is not visible to the user. To show the user the result, you should send a text message back to the user with a concise summary of the result.
|
|
37
|
+
- Each agent invocation is stateless. You will not be able to send additional messages to the agent, nor will the agent be able to communicate with you outside of its final report. Therefore, your prompt should contain a highly detailed task description for the agent to perform autonomously and you should specify exactly what information the agent should return back to you in its final and only message to you.
|
|
38
|
+
- The agent's outputs should generally be trusted
|
|
39
|
+
- Clearly tell the agent whether you expect it to write code or just to do research (search, file reads, web fetches, etc.), since it is not aware of the user's intent
|
|
40
|
+
- If the agent description mentions that it should be used proactively, then you should try your best to use it without the user having to ask for it first. Use your judgement.
|
|
41
|
+
|
|
42
|
+
Example usage:
|
|
43
|
+
- "Find all TypeScript files in the project and identify which ones use async/await"
|
|
44
|
+
- "Explore the authentication system and explain how JWT tokens are validated"
|
|
45
|
+
- "Plan the implementation of a new user dashboard feature"`,
|
|
46
|
+
parameters: {
|
|
47
|
+
type: 'object',
|
|
48
|
+
properties: {
|
|
49
|
+
description: {
|
|
50
|
+
type: 'string',
|
|
51
|
+
description: 'A short (3-5 word) description of the task',
|
|
52
|
+
},
|
|
53
|
+
prompt: {
|
|
54
|
+
type: 'string',
|
|
55
|
+
description: 'The task for the agent to perform',
|
|
56
|
+
},
|
|
57
|
+
subagent_type: {
|
|
58
|
+
type: 'string',
|
|
59
|
+
description: 'The type of specialized agent to use for this task',
|
|
60
|
+
},
|
|
61
|
+
model: {
|
|
62
|
+
type: 'string',
|
|
63
|
+
enum: ['sonnet', 'opus', 'haiku'],
|
|
64
|
+
description: 'Optional model to use for this agent. If not specified, inherits from parent. Prefer haiku for quick, straightforward tasks to minimize cost and latency.',
|
|
65
|
+
},
|
|
66
|
+
resume: {
|
|
67
|
+
type: 'string',
|
|
68
|
+
description: 'Optional agent ID to resume from. If provided, the agent will continue from the previous execution transcript.',
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
required: ['description', 'prompt', 'subagent_type'],
|
|
72
|
+
},
|
|
73
|
+
handler: async (args) => {
|
|
74
|
+
try {
|
|
75
|
+
const input = parseTaskArguments(args);
|
|
76
|
+
const result = await runner.runTask(input);
|
|
77
|
+
return result.output;
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
81
|
+
return `Task tool failed: ${message}`;
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function parseTaskArguments(args) {
|
|
91
|
+
const description = expectString(args['description'], 'description');
|
|
92
|
+
const prompt = expectString(args['prompt'], 'prompt');
|
|
93
|
+
const subagentType = expectString(args['subagent_type'], 'subagent_type');
|
|
94
|
+
const modelValue = typeof args['model'] === 'string' ? args['model'].trim().toLowerCase() : undefined;
|
|
95
|
+
let model;
|
|
96
|
+
if (modelValue) {
|
|
97
|
+
if (modelValue !== 'sonnet' && modelValue !== 'opus' && modelValue !== 'haiku') {
|
|
98
|
+
throw new Error(`Invalid model "${args['model']}". Allowed values are sonnet, opus, or haiku.`);
|
|
99
|
+
}
|
|
100
|
+
model = modelValue;
|
|
101
|
+
}
|
|
102
|
+
const resumeId = typeof args['resume'] === 'string' ? args['resume'].trim() : undefined;
|
|
103
|
+
return {
|
|
104
|
+
description,
|
|
105
|
+
prompt,
|
|
106
|
+
subagentType,
|
|
107
|
+
model,
|
|
108
|
+
resumeId: resumeId && resumeId.length ? resumeId : undefined,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function expectString(value, field) {
|
|
112
|
+
if (typeof value !== 'string' || !value.trim()) {
|
|
113
|
+
throw new Error(`Task tool is missing a valid "${field}" parameter.`);
|
|
114
|
+
}
|
|
115
|
+
return value.trim();
|
|
116
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createBashTools } from '../tools/bashTools.js';
|
|
2
|
+
export class BashCapabilityModule {
|
|
3
|
+
constructor(options = {}) {
|
|
4
|
+
this.id = 'capability.bash';
|
|
5
|
+
this.options = options;
|
|
6
|
+
}
|
|
7
|
+
async create(context) {
|
|
8
|
+
const workingDir = this.options.workingDir ?? context.workingDir;
|
|
9
|
+
return {
|
|
10
|
+
id: this.options.id ?? 'bash.tools.shell',
|
|
11
|
+
description: this.options.description ?? 'Shell execution with stdout/stderr summaries for reproducibility.',
|
|
12
|
+
toolSuite: {
|
|
13
|
+
id: 'bash',
|
|
14
|
+
description: 'Shell access',
|
|
15
|
+
tools: createBashTools(workingDir),
|
|
16
|
+
},
|
|
17
|
+
metadata: {
|
|
18
|
+
workingDir,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createCloudTools } from '../tools/cloudTools.js';
|
|
2
|
+
export class CloudCapabilityModule {
|
|
3
|
+
constructor(options = {}) {
|
|
4
|
+
this.id = 'capability.cloud';
|
|
5
|
+
this.options = options;
|
|
6
|
+
}
|
|
7
|
+
async create(context) {
|
|
8
|
+
const workingDir = this.options.workingDir ?? context.workingDir;
|
|
9
|
+
return {
|
|
10
|
+
id: this.options.id ?? 'cloud.tools.deployment',
|
|
11
|
+
description: this.options.description ??
|
|
12
|
+
'Cloud deployment tools with automatic CLI detection, configuration checking, and auto-fixing for Firebase, Aliyun, AWS, GCP, Azure, Vercel, Netlify, and more.',
|
|
13
|
+
toolSuite: {
|
|
14
|
+
id: 'cloud',
|
|
15
|
+
description: 'Multi-cloud deployment and management tools',
|
|
16
|
+
tools: createCloudTools(workingDir),
|
|
17
|
+
},
|
|
18
|
+
metadata: {
|
|
19
|
+
workingDir,
|
|
20
|
+
supportedProviders: [
|
|
21
|
+
'firebase',
|
|
22
|
+
'aliyun',
|
|
23
|
+
'aws',
|
|
24
|
+
'gcloud',
|
|
25
|
+
'azure',
|
|
26
|
+
'vercel',
|
|
27
|
+
'netlify',
|
|
28
|
+
'cloudflare',
|
|
29
|
+
'fly',
|
|
30
|
+
'railway',
|
|
31
|
+
'supabase',
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createCodeAnalysisTools } from '../tools/codeAnalysisTools.js';
|
|
2
|
+
export class CodeAnalysisCapabilityModule {
|
|
3
|
+
constructor(options = {}) {
|
|
4
|
+
this.id = 'capability.code-analysis';
|
|
5
|
+
this.options = options;
|
|
6
|
+
}
|
|
7
|
+
async create(context) {
|
|
8
|
+
const workingDir = this.options.workingDir ?? context.workingDir;
|
|
9
|
+
return {
|
|
10
|
+
id: this.options.id ?? 'code-analysis.tools.structural',
|
|
11
|
+
description: this.options.description ?? 'Advanced code structure analysis, dependency tracking, and complexity metrics.',
|
|
12
|
+
toolSuite: {
|
|
13
|
+
id: 'code-analysis',
|
|
14
|
+
description: 'Code analysis and metrics',
|
|
15
|
+
tools: createCodeAnalysisTools(workingDir),
|
|
16
|
+
},
|
|
17
|
+
metadata: {
|
|
18
|
+
workingDir,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createCodeQualityTools } from '../tools/codeQualityTools.js';
|
|
2
|
+
export class CodeQualityCapabilityModule {
|
|
3
|
+
constructor(options = {}) {
|
|
4
|
+
this.id = 'capability.code-quality';
|
|
5
|
+
this.options = options;
|
|
6
|
+
}
|
|
7
|
+
async create(context) {
|
|
8
|
+
const workingDir = this.options.workingDir ?? context.workingDir;
|
|
9
|
+
return {
|
|
10
|
+
id: this.options.id ?? 'code-quality.tools.linting',
|
|
11
|
+
description: this.options.description ??
|
|
12
|
+
'Code quality helpers for linting, maintainability analysis, and ESLint rule discovery.',
|
|
13
|
+
toolSuite: {
|
|
14
|
+
id: 'code-quality',
|
|
15
|
+
description: 'Code quality and linting',
|
|
16
|
+
tools: createCodeQualityTools(workingDir),
|
|
17
|
+
},
|
|
18
|
+
metadata: {
|
|
19
|
+
workingDir,
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|