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,304 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safety Validator - Enhanced validation with auto-fixing
|
|
3
|
+
*
|
|
4
|
+
* Validates operations for safety, provides suggestions, and attempts auto-fixing
|
|
5
|
+
*/
|
|
6
|
+
import { DangerousOperationError, BlockedOperationError, ResourceLimitError, ValidationError, } from './errorTypes.js';
|
|
7
|
+
const DANGEROUS_PATTERNS = [
|
|
8
|
+
// Critical - system destruction
|
|
9
|
+
{
|
|
10
|
+
pattern: /rm\s+-rf\s+\/($|\s)/,
|
|
11
|
+
reason: 'Attempts to delete entire root filesystem',
|
|
12
|
+
severity: 'critical',
|
|
13
|
+
safeAlternative: 'rm -rf ./specific-directory',
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
pattern: /:\(\)\s*\{[^}]*\}\s*;\s*:/,
|
|
17
|
+
reason: 'Fork bomb that crashes system',
|
|
18
|
+
severity: 'critical',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
pattern: /mkfs\./,
|
|
22
|
+
reason: 'Formats filesystem, destroying all data',
|
|
23
|
+
severity: 'critical',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
pattern: /dd\s+.*of=\/dev\/(sd|hd|nvme)/,
|
|
27
|
+
reason: 'Writes directly to disk, can destroy data',
|
|
28
|
+
severity: 'critical',
|
|
29
|
+
},
|
|
30
|
+
// High - data loss
|
|
31
|
+
{
|
|
32
|
+
pattern: /rm\s+-rf\s+(\/(?!\s)|~\/)/,
|
|
33
|
+
reason: 'Removes files recursively without confirmation',
|
|
34
|
+
severity: 'high',
|
|
35
|
+
safeAlternative: 'rm -ri ./directory (interactive)',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
pattern: />\s*\/dev\/(sd|hd|nvme)/,
|
|
39
|
+
reason: 'Redirects output to disk device',
|
|
40
|
+
severity: 'high',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
pattern: /shred\s+-[a-z]*n/,
|
|
44
|
+
reason: 'Securely deletes files, unrecoverable',
|
|
45
|
+
severity: 'high',
|
|
46
|
+
},
|
|
47
|
+
// Medium - risky operations
|
|
48
|
+
{
|
|
49
|
+
pattern: /chmod\s+-R\s+777/,
|
|
50
|
+
reason: 'Makes all files world-writable (security risk)',
|
|
51
|
+
severity: 'medium',
|
|
52
|
+
safeAlternative: 'chmod -R 755 ./directory',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
pattern: /curl.*\|\s*sh/,
|
|
56
|
+
reason: 'Pipes remote script to shell (security risk)',
|
|
57
|
+
severity: 'medium',
|
|
58
|
+
safeAlternative: 'Download and inspect script first',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
pattern: /wget.*\|\s*sh/,
|
|
62
|
+
reason: 'Pipes remote script to shell (security risk)',
|
|
63
|
+
severity: 'medium',
|
|
64
|
+
safeAlternative: 'Download and inspect script first',
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
pattern: /eval\s+\$\(/,
|
|
68
|
+
reason: 'Executes arbitrary code (injection risk)',
|
|
69
|
+
severity: 'medium',
|
|
70
|
+
},
|
|
71
|
+
];
|
|
72
|
+
const BLOCKED_OPERATIONS = [
|
|
73
|
+
{
|
|
74
|
+
pattern: /npm\s+publish/,
|
|
75
|
+
policy: 'Publishing requires explicit user approval',
|
|
76
|
+
allowedAlternatives: ['npm publish --dry-run'],
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
pattern: /git\s+push\s+--force/,
|
|
80
|
+
policy: 'Force push can overwrite remote history',
|
|
81
|
+
allowedAlternatives: ['git push --force-with-lease'],
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
pattern: /docker\s+system\s+prune\s+-a/,
|
|
85
|
+
policy: 'Removes all unused Docker resources',
|
|
86
|
+
allowedAlternatives: ['docker system prune'],
|
|
87
|
+
},
|
|
88
|
+
];
|
|
89
|
+
/**
|
|
90
|
+
* Validate bash command for safety
|
|
91
|
+
*/
|
|
92
|
+
export function validateBashCommand(command) {
|
|
93
|
+
const warnings = [];
|
|
94
|
+
// Check for dangerous patterns (CRITICAL - must block)
|
|
95
|
+
for (const { pattern, reason, severity, safeAlternative } of DANGEROUS_PATTERNS) {
|
|
96
|
+
if (pattern.test(command)) {
|
|
97
|
+
if (severity === 'critical' || severity === 'high') {
|
|
98
|
+
const error = new DangerousOperationError(command, reason, safeAlternative);
|
|
99
|
+
return {
|
|
100
|
+
valid: false,
|
|
101
|
+
error,
|
|
102
|
+
warnings,
|
|
103
|
+
autoFix: safeAlternative ? {
|
|
104
|
+
available: true,
|
|
105
|
+
apply: () => safeAlternative,
|
|
106
|
+
description: `Replace with: ${safeAlternative}`,
|
|
107
|
+
} : undefined,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
// Medium severity - warn but allow
|
|
112
|
+
warnings.push(`Warning: ${reason}. Consider: ${safeAlternative || 'reviewing command'}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// Check for blocked operations (ERROR - policy violation)
|
|
117
|
+
for (const { pattern, policy, allowedAlternatives } of BLOCKED_OPERATIONS) {
|
|
118
|
+
if (pattern.test(command)) {
|
|
119
|
+
const error = new BlockedOperationError(command, policy, allowedAlternatives);
|
|
120
|
+
return {
|
|
121
|
+
valid: false,
|
|
122
|
+
error,
|
|
123
|
+
warnings,
|
|
124
|
+
autoFix: allowedAlternatives && allowedAlternatives.length > 0 ? {
|
|
125
|
+
available: true,
|
|
126
|
+
apply: () => allowedAlternatives[0],
|
|
127
|
+
description: `Replace with: ${allowedAlternatives[0]}`,
|
|
128
|
+
} : undefined,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return { valid: true, warnings };
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Validate tool arguments with auto-fixing
|
|
136
|
+
*/
|
|
137
|
+
export function validateToolArgs(_toolName, args, constraints) {
|
|
138
|
+
const warnings = [];
|
|
139
|
+
for (const [field, value] of Object.entries(args)) {
|
|
140
|
+
const constraint = constraints[field];
|
|
141
|
+
if (!constraint)
|
|
142
|
+
continue;
|
|
143
|
+
// Type validation
|
|
144
|
+
if (typeof value !== constraint.type) {
|
|
145
|
+
const error = new ValidationError(field, value, `Must be ${constraint.type}`, `${field}: <${constraint.type} value>`);
|
|
146
|
+
return {
|
|
147
|
+
valid: false,
|
|
148
|
+
error,
|
|
149
|
+
warnings,
|
|
150
|
+
autoFix: {
|
|
151
|
+
available: true,
|
|
152
|
+
apply: () => convertType(value, constraint.type),
|
|
153
|
+
description: `Convert ${field} to ${constraint.type}`,
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
// Range validation (for numbers)
|
|
158
|
+
if (constraint.type === 'number' && typeof value === 'number') {
|
|
159
|
+
if (constraint.max !== undefined && value > constraint.max) {
|
|
160
|
+
const error = new ResourceLimitError(field, value, constraint.max);
|
|
161
|
+
const safeValue = Math.floor(constraint.max * 0.8);
|
|
162
|
+
return {
|
|
163
|
+
valid: false,
|
|
164
|
+
error,
|
|
165
|
+
warnings,
|
|
166
|
+
autoFix: {
|
|
167
|
+
available: true,
|
|
168
|
+
apply: () => safeValue,
|
|
169
|
+
description: `Reduce ${field} to ${safeValue}`,
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
if (constraint.min !== undefined && value < constraint.min) {
|
|
174
|
+
const error = new ValidationError(field, value, `Must be at least ${constraint.min}`, `${constraint.min}`);
|
|
175
|
+
return {
|
|
176
|
+
valid: false,
|
|
177
|
+
error,
|
|
178
|
+
warnings,
|
|
179
|
+
autoFix: {
|
|
180
|
+
available: true,
|
|
181
|
+
apply: () => constraint.min,
|
|
182
|
+
description: `Set ${field} to minimum value ${constraint.min}`,
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
// Warning thresholds (80% of max)
|
|
187
|
+
if (constraint.max !== undefined && value > constraint.max * 0.8) {
|
|
188
|
+
warnings.push(`${field} is ${value}, approaching maximum of ${constraint.max}`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return { valid: true, warnings };
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Helper: Convert value to target type
|
|
196
|
+
*/
|
|
197
|
+
function convertType(value, targetType) {
|
|
198
|
+
switch (targetType) {
|
|
199
|
+
case 'number':
|
|
200
|
+
return Number(value);
|
|
201
|
+
case 'string':
|
|
202
|
+
return String(value);
|
|
203
|
+
case 'boolean':
|
|
204
|
+
return Boolean(value);
|
|
205
|
+
default:
|
|
206
|
+
return value;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Smart fixer - attempts to automatically fix common issues
|
|
211
|
+
*/
|
|
212
|
+
export class SmartFixer {
|
|
213
|
+
/**
|
|
214
|
+
* Fix dangerous bash commands by replacing with safe alternatives
|
|
215
|
+
*/
|
|
216
|
+
static fixDangerousCommand(command) {
|
|
217
|
+
let fixed = command;
|
|
218
|
+
const changes = [];
|
|
219
|
+
// Fix rm -rf / → rm -rf ./
|
|
220
|
+
if (/rm\s+-rf\s+\/($|\s)/.test(fixed)) {
|
|
221
|
+
fixed = fixed.replace(/rm\s+-rf\s+\/($|\s)/, 'rm -rf ./');
|
|
222
|
+
changes.push('Changed "rm -rf /" to "rm -rf ./"');
|
|
223
|
+
}
|
|
224
|
+
// Fix chmod 777 → chmod 755
|
|
225
|
+
if (/chmod\s+-R\s+777/.test(fixed)) {
|
|
226
|
+
fixed = fixed.replace(/chmod\s+-R\s+777/g, 'chmod -R 755');
|
|
227
|
+
changes.push('Changed "chmod -R 777" to "chmod -R 755"');
|
|
228
|
+
}
|
|
229
|
+
// Fix git push --force → git push --force-with-lease
|
|
230
|
+
if (/git\s+push\s+--force($|\s)/.test(fixed)) {
|
|
231
|
+
fixed = fixed.replace(/git\s+push\s+--force($|\s)/g, 'git push --force-with-lease ');
|
|
232
|
+
changes.push('Changed "git push --force" to "git push --force-with-lease"');
|
|
233
|
+
}
|
|
234
|
+
return { fixed, changes };
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Fix resource limits by reducing to safe values
|
|
238
|
+
*/
|
|
239
|
+
static fixResourceLimits(args, limits) {
|
|
240
|
+
const fixed = { ...args };
|
|
241
|
+
const changes = [];
|
|
242
|
+
for (const [field, limit] of Object.entries(limits)) {
|
|
243
|
+
if (field in fixed && typeof fixed[field] === 'number') {
|
|
244
|
+
const value = fixed[field];
|
|
245
|
+
if (value > limit) {
|
|
246
|
+
const safeValue = Math.floor(limit * 0.8); // 80% of limit
|
|
247
|
+
fixed[field] = safeValue;
|
|
248
|
+
changes.push(`Reduced ${field} from ${value} to ${safeValue}`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return { fixed, changes };
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Fix validation errors by coercing types
|
|
256
|
+
*/
|
|
257
|
+
static fixValidationErrors(args, schema) {
|
|
258
|
+
const fixed = { ...args };
|
|
259
|
+
const changes = [];
|
|
260
|
+
for (const [field, constraint] of Object.entries(schema)) {
|
|
261
|
+
if (field in fixed && typeof fixed[field] !== constraint.type) {
|
|
262
|
+
const original = fixed[field];
|
|
263
|
+
fixed[field] = convertType(original, constraint.type);
|
|
264
|
+
changes.push(`Converted ${field} from ${typeof original} to ${constraint.type}`);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return { fixed, changes };
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Validator with auto-fix integration
|
|
272
|
+
*/
|
|
273
|
+
export class AutoFixValidator {
|
|
274
|
+
constructor(autoFixEnabled = false) {
|
|
275
|
+
this.autoFixEnabled = autoFixEnabled;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Validate with optional auto-fixing
|
|
279
|
+
*/
|
|
280
|
+
async validate(value, validator) {
|
|
281
|
+
let result = validator(value);
|
|
282
|
+
// If invalid and auto-fix is available, try to fix
|
|
283
|
+
if (!result.valid && this.autoFixEnabled && result.autoFix?.available) {
|
|
284
|
+
console.warn(`[AutoFix] Attempting to fix: ${result.error?.message}`);
|
|
285
|
+
try {
|
|
286
|
+
const fixedValue = result.autoFix.apply();
|
|
287
|
+
console.warn(`[AutoFix] Applied: ${result.autoFix.description}`);
|
|
288
|
+
// Re-validate fixed value
|
|
289
|
+
result = validator(fixedValue);
|
|
290
|
+
if (result.valid) {
|
|
291
|
+
console.log('[AutoFix] Validation passed after fix');
|
|
292
|
+
return { value: fixedValue, result };
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
catch (error) {
|
|
296
|
+
console.error('[AutoFix] Failed to apply fix:', error);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return { value, result };
|
|
300
|
+
}
|
|
301
|
+
setAutoFix(enabled) {
|
|
302
|
+
this.autoFixEnabled = enabled;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export function buildError(action, error, context) {
|
|
2
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
3
|
+
const contextDetails = formatContext(context);
|
|
4
|
+
return contextDetails ? `Error ${action}: ${message} (${contextDetails})` : `Error ${action}: ${message}`;
|
|
5
|
+
}
|
|
6
|
+
function formatContext(context) {
|
|
7
|
+
if (!context) {
|
|
8
|
+
return '';
|
|
9
|
+
}
|
|
10
|
+
const entries = Object.entries(context).filter(([, value]) => value !== undefined && value !== null);
|
|
11
|
+
if (entries.length === 0) {
|
|
12
|
+
return '';
|
|
13
|
+
}
|
|
14
|
+
return entries
|
|
15
|
+
.map(([key, value]) => `${formatContextKey(key)} ${formatContextValue(value)}`)
|
|
16
|
+
.join(', ');
|
|
17
|
+
}
|
|
18
|
+
function formatContextKey(key) {
|
|
19
|
+
if (!key) {
|
|
20
|
+
return key;
|
|
21
|
+
}
|
|
22
|
+
return key.slice(0, 1).toUpperCase() + key.slice(1);
|
|
23
|
+
}
|
|
24
|
+
function formatContextValue(value) {
|
|
25
|
+
if (typeof value === 'string') {
|
|
26
|
+
return value || '(empty)';
|
|
27
|
+
}
|
|
28
|
+
if (typeof value === 'number' || typeof value === 'boolean') {
|
|
29
|
+
return String(value);
|
|
30
|
+
}
|
|
31
|
+
return '(unknown)';
|
|
32
|
+
}
|