erosolar-cli 1.7.330 → 1.7.331
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/README.md +148 -24
- package/dist/alpha-zero/agentWrapper.d.ts +84 -0
- package/dist/alpha-zero/agentWrapper.d.ts.map +1 -0
- package/dist/alpha-zero/agentWrapper.js +171 -0
- package/dist/alpha-zero/agentWrapper.js.map +1 -0
- package/dist/alpha-zero/codeEvaluator.d.ts +25 -0
- package/dist/alpha-zero/codeEvaluator.d.ts.map +1 -0
- package/dist/alpha-zero/codeEvaluator.js +273 -0
- package/dist/alpha-zero/codeEvaluator.js.map +1 -0
- package/dist/alpha-zero/competitiveRunner.d.ts +66 -0
- package/dist/alpha-zero/competitiveRunner.d.ts.map +1 -0
- package/dist/alpha-zero/competitiveRunner.js +224 -0
- package/dist/alpha-zero/competitiveRunner.js.map +1 -0
- package/dist/alpha-zero/index.d.ts +67 -0
- package/dist/alpha-zero/index.d.ts.map +1 -0
- package/dist/alpha-zero/index.js +99 -0
- package/dist/alpha-zero/index.js.map +1 -0
- package/dist/alpha-zero/introspection.d.ts +128 -0
- package/dist/alpha-zero/introspection.d.ts.map +1 -0
- package/dist/alpha-zero/introspection.js +300 -0
- package/dist/alpha-zero/introspection.js.map +1 -0
- package/dist/alpha-zero/metricsTracker.d.ts +71 -0
- package/dist/alpha-zero/metricsTracker.d.ts.map +1 -0
- package/dist/{core → alpha-zero}/metricsTracker.js +5 -2
- package/dist/alpha-zero/metricsTracker.js.map +1 -0
- package/dist/alpha-zero/security/core.d.ts +125 -0
- package/dist/alpha-zero/security/core.d.ts.map +1 -0
- package/dist/alpha-zero/security/core.js +271 -0
- package/dist/alpha-zero/security/core.js.map +1 -0
- package/dist/alpha-zero/security/google.d.ts +125 -0
- package/dist/alpha-zero/security/google.d.ts.map +1 -0
- package/dist/alpha-zero/security/google.js +311 -0
- package/dist/alpha-zero/security/google.js.map +1 -0
- package/dist/alpha-zero/security/googleLoader.d.ts +17 -0
- package/dist/alpha-zero/security/googleLoader.d.ts.map +1 -0
- package/dist/alpha-zero/security/googleLoader.js +41 -0
- package/dist/alpha-zero/security/googleLoader.js.map +1 -0
- package/dist/alpha-zero/security/index.d.ts +29 -0
- package/dist/alpha-zero/security/index.d.ts.map +1 -0
- package/dist/alpha-zero/security/index.js +32 -0
- package/dist/alpha-zero/security/index.js.map +1 -0
- package/dist/alpha-zero/security/simulation.d.ts +124 -0
- package/dist/alpha-zero/security/simulation.d.ts.map +1 -0
- package/dist/alpha-zero/security/simulation.js +277 -0
- package/dist/alpha-zero/security/simulation.js.map +1 -0
- package/dist/alpha-zero/selfModification.d.ts +109 -0
- package/dist/alpha-zero/selfModification.d.ts.map +1 -0
- package/dist/alpha-zero/selfModification.js +233 -0
- package/dist/alpha-zero/selfModification.js.map +1 -0
- package/dist/alpha-zero/types.d.ts +170 -0
- package/dist/alpha-zero/types.d.ts.map +1 -0
- package/dist/alpha-zero/types.js +31 -0
- package/dist/alpha-zero/types.js.map +1 -0
- package/dist/bin/erosolar.js +21 -5
- package/dist/bin/erosolar.js.map +1 -1
- package/dist/capabilities/agentSpawningCapability.d.ts.map +1 -1
- package/dist/capabilities/agentSpawningCapability.js +31 -56
- package/dist/capabilities/agentSpawningCapability.js.map +1 -1
- package/dist/capabilities/securityTestingCapability.d.ts +13 -0
- package/dist/capabilities/securityTestingCapability.d.ts.map +1 -0
- package/dist/capabilities/securityTestingCapability.js +25 -0
- package/dist/capabilities/securityTestingCapability.js.map +1 -0
- package/dist/contracts/agent-schemas.json +15 -0
- package/dist/contracts/tools.schema.json +9 -0
- package/dist/core/agent.d.ts +2 -2
- package/dist/core/agent.d.ts.map +1 -1
- package/dist/core/agent.js.map +1 -1
- package/dist/core/aiFlowOptimizer.d.ts +26 -0
- package/dist/core/aiFlowOptimizer.d.ts.map +1 -0
- package/dist/core/aiFlowOptimizer.js +31 -0
- package/dist/core/aiFlowOptimizer.js.map +1 -0
- package/dist/core/aiOptimizationEngine.d.ts +158 -0
- package/dist/core/aiOptimizationEngine.d.ts.map +1 -0
- package/dist/core/aiOptimizationEngine.js +428 -0
- package/dist/core/aiOptimizationEngine.js.map +1 -0
- package/dist/core/aiOptimizationIntegration.d.ts +93 -0
- package/dist/core/aiOptimizationIntegration.d.ts.map +1 -0
- package/dist/core/aiOptimizationIntegration.js +250 -0
- package/dist/core/aiOptimizationIntegration.js.map +1 -0
- package/dist/core/customCommands.d.ts +0 -1
- package/dist/core/customCommands.d.ts.map +1 -1
- package/dist/core/customCommands.js +0 -3
- package/dist/core/customCommands.js.map +1 -1
- package/dist/core/enhancedErrorRecovery.d.ts +100 -0
- package/dist/core/enhancedErrorRecovery.d.ts.map +1 -0
- package/dist/core/enhancedErrorRecovery.js +345 -0
- package/dist/core/enhancedErrorRecovery.js.map +1 -0
- package/dist/core/hooksSystem.d.ts +65 -0
- package/dist/core/hooksSystem.d.ts.map +1 -0
- package/dist/core/hooksSystem.js +273 -0
- package/dist/core/hooksSystem.js.map +1 -0
- package/dist/core/memorySystem.d.ts +48 -0
- package/dist/core/memorySystem.d.ts.map +1 -0
- package/dist/core/memorySystem.js +271 -0
- package/dist/core/memorySystem.js.map +1 -0
- package/dist/core/toolPreconditions.d.ts.map +1 -1
- package/dist/core/toolPreconditions.js +14 -0
- package/dist/core/toolPreconditions.js.map +1 -1
- package/dist/core/toolRuntime.d.ts +1 -22
- package/dist/core/toolRuntime.d.ts.map +1 -1
- package/dist/core/toolRuntime.js +5 -0
- package/dist/core/toolRuntime.js.map +1 -1
- package/dist/core/toolValidation.d.ts.map +1 -1
- package/dist/core/toolValidation.js +3 -14
- package/dist/core/toolValidation.js.map +1 -1
- package/dist/core/unified/errors.d.ts +189 -0
- package/dist/core/unified/errors.d.ts.map +1 -0
- package/dist/core/unified/errors.js +497 -0
- package/dist/core/unified/errors.js.map +1 -0
- package/dist/core/unified/index.d.ts +19 -0
- package/dist/core/unified/index.d.ts.map +1 -0
- package/dist/core/unified/index.js +68 -0
- package/dist/core/unified/index.js.map +1 -0
- package/dist/core/unified/schema.d.ts +101 -0
- package/dist/core/unified/schema.d.ts.map +1 -0
- package/dist/core/unified/schema.js +350 -0
- package/dist/core/unified/schema.js.map +1 -0
- package/dist/core/unified/toolRuntime.d.ts +179 -0
- package/dist/core/unified/toolRuntime.d.ts.map +1 -0
- package/dist/core/unified/toolRuntime.js +517 -0
- package/dist/core/unified/toolRuntime.js.map +1 -0
- package/dist/core/unified/tools.d.ts +127 -0
- package/dist/core/unified/tools.d.ts.map +1 -0
- package/dist/core/unified/tools.js +1333 -0
- package/dist/core/unified/tools.js.map +1 -0
- package/dist/core/unified/types.d.ts +352 -0
- package/dist/core/unified/types.d.ts.map +1 -0
- package/dist/core/unified/types.js +12 -0
- package/dist/core/unified/types.js.map +1 -0
- package/dist/core/unified/version.d.ts +209 -0
- package/dist/core/unified/version.d.ts.map +1 -0
- package/dist/core/unified/version.js +454 -0
- package/dist/core/unified/version.js.map +1 -0
- package/dist/core/validationRunner.d.ts +3 -1
- package/dist/core/validationRunner.d.ts.map +1 -1
- package/dist/core/validationRunner.js.map +1 -1
- package/dist/headless/headlessApp.d.ts.map +1 -1
- package/dist/headless/headlessApp.js +0 -21
- package/dist/headless/headlessApp.js.map +1 -1
- package/dist/mcp/sseClient.d.ts.map +1 -1
- package/dist/mcp/sseClient.js +18 -9
- package/dist/mcp/sseClient.js.map +1 -1
- package/dist/plugins/tools/build/buildPlugin.d.ts +6 -0
- package/dist/plugins/tools/build/buildPlugin.d.ts.map +1 -1
- package/dist/plugins/tools/build/buildPlugin.js +10 -4
- package/dist/plugins/tools/build/buildPlugin.js.map +1 -1
- 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/plugins/tools/security/securityPlugin.d.ts +3 -0
- package/dist/plugins/tools/security/securityPlugin.d.ts.map +1 -0
- package/dist/plugins/tools/security/securityPlugin.js +12 -0
- package/dist/plugins/tools/security/securityPlugin.js.map +1 -0
- package/dist/runtime/agentSession.d.ts +2 -2
- package/dist/runtime/agentSession.d.ts.map +1 -1
- package/dist/runtime/agentSession.js +2 -2
- package/dist/runtime/agentSession.js.map +1 -1
- package/dist/security/active-stack-security.d.ts +112 -0
- package/dist/security/active-stack-security.d.ts.map +1 -0
- package/dist/security/active-stack-security.js +296 -0
- package/dist/security/active-stack-security.js.map +1 -0
- 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/advanced-targeting.d.ts +119 -0
- package/dist/security/advanced-targeting.d.ts.map +1 -0
- package/dist/security/advanced-targeting.js +233 -0
- package/dist/security/advanced-targeting.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/comprehensive-targeting.d.ts +85 -0
- package/dist/security/comprehensive-targeting.d.ts.map +1 -0
- package/dist/security/comprehensive-targeting.js +438 -0
- package/dist/security/comprehensive-targeting.js.map +1 -0
- package/dist/security/global-security-integration.d.ts +91 -0
- package/dist/security/global-security-integration.d.ts.map +1 -0
- package/dist/security/global-security-integration.js +218 -0
- package/dist/security/global-security-integration.js.map +1 -0
- package/dist/security/index.d.ts +38 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +47 -0
- package/dist/security/index.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 +92 -0
- package/dist/security/persistence-research.d.ts.map +1 -0
- package/dist/security/persistence-research.js +364 -0
- package/dist/security/persistence-research.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-integration.d.ts +74 -0
- package/dist/security/security-integration.d.ts.map +1 -0
- package/dist/security/security-integration.js +137 -0
- package/dist/security/security-integration.js.map +1 -0
- package/dist/security/security-testing-framework.d.ts +112 -0
- package/dist/security/security-testing-framework.d.ts.map +1 -0
- package/dist/security/security-testing-framework.js +364 -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/security/strategic-operations.d.ts +100 -0
- package/dist/security/strategic-operations.d.ts.map +1 -0
- package/dist/security/strategic-operations.js +276 -0
- package/dist/security/strategic-operations.js.map +1 -0
- package/dist/security/tool-security-wrapper.d.ts +58 -0
- package/dist/security/tool-security-wrapper.d.ts.map +1 -0
- package/dist/security/tool-security-wrapper.js +156 -0
- package/dist/security/tool-security-wrapper.js.map +1 -0
- package/dist/shell/claudeCodeStreamHandler.d.ts +145 -0
- package/dist/shell/claudeCodeStreamHandler.d.ts.map +1 -0
- package/dist/shell/claudeCodeStreamHandler.js +322 -0
- package/dist/shell/claudeCodeStreamHandler.js.map +1 -0
- package/dist/shell/inputQueueManager.d.ts +144 -0
- package/dist/shell/inputQueueManager.d.ts.map +1 -0
- package/dist/shell/inputQueueManager.js +290 -0
- package/dist/shell/inputQueueManager.js.map +1 -0
- package/dist/shell/interactiveShell.d.ts +7 -16
- package/dist/shell/interactiveShell.d.ts.map +1 -1
- package/dist/shell/interactiveShell.js +166 -235
- package/dist/shell/interactiveShell.js.map +1 -1
- package/dist/shell/metricsTracker.d.ts +60 -0
- package/dist/shell/metricsTracker.d.ts.map +1 -0
- package/dist/shell/metricsTracker.js +119 -0
- package/dist/shell/metricsTracker.js.map +1 -0
- package/dist/shell/shellApp.d.ts +0 -2
- package/dist/shell/shellApp.d.ts.map +1 -1
- package/dist/shell/shellApp.js +9 -40
- package/dist/shell/shellApp.js.map +1 -1
- package/dist/shell/streamingOutputManager.d.ts +115 -0
- package/dist/shell/streamingOutputManager.d.ts.map +1 -0
- package/dist/shell/streamingOutputManager.js +225 -0
- package/dist/shell/streamingOutputManager.js.map +1 -0
- package/dist/shell/systemPrompt.d.ts.map +1 -1
- package/dist/shell/systemPrompt.js +4 -1
- package/dist/shell/systemPrompt.js.map +1 -1
- package/dist/shell/terminalInput.d.ts +117 -149
- package/dist/shell/terminalInput.d.ts.map +1 -1
- package/dist/shell/terminalInput.js +517 -659
- package/dist/shell/terminalInput.js.map +1 -1
- package/dist/shell/terminalInputAdapter.d.ts +20 -79
- package/dist/shell/terminalInputAdapter.d.ts.map +1 -1
- package/dist/shell/terminalInputAdapter.js +30 -99
- package/dist/shell/terminalInputAdapter.js.map +1 -1
- package/dist/subagents/taskRunner.d.ts +1 -7
- package/dist/subagents/taskRunner.d.ts.map +1 -1
- package/dist/subagents/taskRunner.js +47 -180
- package/dist/subagents/taskRunner.js.map +1 -1
- package/dist/tools/securityTools.d.ts +22 -0
- package/dist/tools/securityTools.d.ts.map +1 -0
- package/dist/tools/securityTools.js +448 -0
- package/dist/tools/securityTools.js.map +1 -0
- package/dist/ui/ShellUIAdapter.d.ts.map +1 -1
- package/dist/ui/ShellUIAdapter.js +12 -13
- package/dist/ui/ShellUIAdapter.js.map +1 -1
- package/dist/ui/display.d.ts +45 -24
- package/dist/ui/display.d.ts.map +1 -1
- package/dist/ui/display.js +259 -140
- package/dist/ui/display.js.map +1 -1
- package/dist/ui/persistentPrompt.d.ts +50 -0
- package/dist/ui/persistentPrompt.d.ts.map +1 -0
- package/dist/ui/persistentPrompt.js +92 -0
- package/dist/ui/persistentPrompt.js.map +1 -0
- package/dist/ui/terminalUISchema.d.ts +195 -0
- package/dist/ui/terminalUISchema.d.ts.map +1 -0
- package/dist/ui/terminalUISchema.js +113 -0
- package/dist/ui/terminalUISchema.js.map +1 -0
- package/dist/ui/theme.d.ts.map +1 -1
- package/dist/ui/theme.js +8 -6
- package/dist/ui/theme.js.map +1 -1
- package/dist/ui/toolDisplay.d.ts +158 -0
- package/dist/ui/toolDisplay.d.ts.map +1 -1
- package/dist/ui/toolDisplay.js +348 -0
- package/dist/ui/toolDisplay.js.map +1 -1
- package/dist/ui/unified/layout.d.ts +0 -1
- package/dist/ui/unified/layout.d.ts.map +1 -1
- package/dist/ui/unified/layout.js +25 -15
- package/dist/ui/unified/layout.js.map +1 -1
- package/package.json +4 -4
- package/scripts/deploy-security-capabilities.js +178 -0
- package/dist/core/hooks.d.ts +0 -113
- package/dist/core/hooks.d.ts.map +0 -1
- package/dist/core/hooks.js +0 -267
- package/dist/core/hooks.js.map +0 -1
- package/dist/core/metricsTracker.d.ts +0 -122
- package/dist/core/metricsTracker.d.ts.map +0 -1
- package/dist/core/metricsTracker.js.map +0 -1
- package/dist/core/securityAssessment.d.ts +0 -91
- package/dist/core/securityAssessment.d.ts.map +0 -1
- package/dist/core/securityAssessment.js +0 -580
- package/dist/core/securityAssessment.js.map +0 -1
- package/dist/core/verification.d.ts +0 -137
- package/dist/core/verification.d.ts.map +0 -1
- package/dist/core/verification.js +0 -323
- package/dist/core/verification.js.map +0 -1
- package/dist/subagents/agentConfig.d.ts +0 -27
- package/dist/subagents/agentConfig.d.ts.map +0 -1
- package/dist/subagents/agentConfig.js +0 -89
- package/dist/subagents/agentConfig.js.map +0 -1
- package/dist/subagents/agentRegistry.d.ts +0 -33
- package/dist/subagents/agentRegistry.d.ts.map +0 -1
- package/dist/subagents/agentRegistry.js +0 -162
- package/dist/subagents/agentRegistry.js.map +0 -1
- package/dist/utils/frontmatter.d.ts +0 -10
- package/dist/utils/frontmatter.d.ts.map +0 -1
- package/dist/utils/frontmatter.js +0 -78
- package/dist/utils/frontmatter.js.map +0 -1
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ClaudeCodeStreamHandler - Complete streaming I/O handler following Claude Code's approach
|
|
3
|
+
*
|
|
4
|
+
* This module combines StreamingOutputManager and InputQueueManager to provide
|
|
5
|
+
* the complete Claude Code streaming experience:
|
|
6
|
+
*
|
|
7
|
+
* 1. Natural Output Flow
|
|
8
|
+
* - Streaming output just writes to stdout normally
|
|
9
|
+
* - Cursor stays where it is after each write
|
|
10
|
+
* - Lines scroll up naturally as new content appears
|
|
11
|
+
* - NO scroll regions, NO save/restore cursor during streaming
|
|
12
|
+
*
|
|
13
|
+
* 2. Readline Handles Input
|
|
14
|
+
* - Uses Node.js readline module
|
|
15
|
+
* - Input prompt naturally moves up as output streams above it
|
|
16
|
+
* - User can type while streaming - input is queued in memory, not rendered
|
|
17
|
+
*
|
|
18
|
+
* 3. Queue-Based Approach
|
|
19
|
+
* User types during streaming → Input stored in queue → Processed after streaming ends
|
|
20
|
+
*
|
|
21
|
+
* 4. The Key Insight
|
|
22
|
+
* The cursor is NEVER moved during streaming. Output just appends at current position.
|
|
23
|
+
* The "input at bottom" effect comes from:
|
|
24
|
+
* - New output pushes older content (including the prompt) upward
|
|
25
|
+
* - After streaming ends, a new prompt is shown at the bottom
|
|
26
|
+
*/
|
|
27
|
+
import * as readline from 'node:readline';
|
|
28
|
+
import { EventEmitter } from 'node:events';
|
|
29
|
+
import { getStreamingOutputManager } from './streamingOutputManager.js';
|
|
30
|
+
import { getInputQueueManager } from './inputQueueManager.js';
|
|
31
|
+
import { writeLock } from '../ui/writeLock.js';
|
|
32
|
+
/**
|
|
33
|
+
* Coordinates streaming output and queued input for Claude Code style UX.
|
|
34
|
+
*/
|
|
35
|
+
export class ClaudeCodeStreamHandler extends EventEmitter {
|
|
36
|
+
outputManager;
|
|
37
|
+
inputManager;
|
|
38
|
+
writeStream;
|
|
39
|
+
readStream;
|
|
40
|
+
rl = null;
|
|
41
|
+
keypressHandler = null;
|
|
42
|
+
originalStdoutWrite = null;
|
|
43
|
+
isOutputSuppressed = false;
|
|
44
|
+
constructor(writeStream = process.stdout, readStream = process.stdin) {
|
|
45
|
+
super();
|
|
46
|
+
this.writeStream = writeStream;
|
|
47
|
+
this.readStream = readStream;
|
|
48
|
+
this.outputManager = getStreamingOutputManager();
|
|
49
|
+
this.inputManager = getInputQueueManager();
|
|
50
|
+
// Forward events
|
|
51
|
+
this.inputManager.on('input-queued', (input) => {
|
|
52
|
+
this.emit('input-queued', input);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Attach to an existing readline interface
|
|
57
|
+
* Call this after creating your readline.Interface
|
|
58
|
+
*/
|
|
59
|
+
attachToReadline(rl) {
|
|
60
|
+
this.rl = rl;
|
|
61
|
+
this.setupKeypressCapture();
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Set up keypress capturing for queued input during streaming
|
|
65
|
+
*/
|
|
66
|
+
setupKeypressCapture() {
|
|
67
|
+
if (!this.readStream || !this.readStream.isTTY) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
// Enable keypress events if not already enabled
|
|
71
|
+
if (this.readStream.listenerCount('keypress') === 0 && this.rl) {
|
|
72
|
+
readline.emitKeypressEvents(this.readStream, this.rl);
|
|
73
|
+
}
|
|
74
|
+
// Ensure raw mode for keypress events
|
|
75
|
+
if (this.readStream.setRawMode && !this.readStream.isRaw) {
|
|
76
|
+
this.readStream.setRawMode(true);
|
|
77
|
+
}
|
|
78
|
+
this.keypressHandler = (_str, key) => {
|
|
79
|
+
// Only capture when streaming
|
|
80
|
+
if (!this.outputManager.isStreaming() || !this.inputManager.isCapturing()) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
// Handle special keys
|
|
84
|
+
if (key) {
|
|
85
|
+
// Ctrl+C - interrupt
|
|
86
|
+
if (key.ctrl && key.name === 'c') {
|
|
87
|
+
this.inputManager.handleInterrupt();
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
// Enter - submit queued input
|
|
91
|
+
if (key.name === 'return' || key.name === 'enter') {
|
|
92
|
+
this.inputManager.handleSubmit();
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
// Backspace
|
|
96
|
+
if (key.name === 'backspace') {
|
|
97
|
+
this.inputManager.handleBackspace();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
// Delete
|
|
101
|
+
if (key.name === 'delete') {
|
|
102
|
+
this.inputManager.handleDelete();
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
// Arrow keys
|
|
106
|
+
if (key.name === 'left') {
|
|
107
|
+
this.inputManager.handleCursorLeft();
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (key.name === 'right') {
|
|
111
|
+
this.inputManager.handleCursorRight();
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
// Ignore other control sequences during capture
|
|
115
|
+
if (key.ctrl || key.meta) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// Regular character input
|
|
120
|
+
if (_str && _str.length > 0 && !key?.ctrl && !key?.meta) {
|
|
121
|
+
this.inputManager.handleChar(_str);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
this.readStream.prependListener('keypress', this.keypressHandler);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Begin streaming mode
|
|
128
|
+
*
|
|
129
|
+
* Claude Code approach:
|
|
130
|
+
* - Start capturing input to queue
|
|
131
|
+
* - Suppress readline echo (characters typed go to queue, not screen)
|
|
132
|
+
* - Output flows naturally to stdout
|
|
133
|
+
*/
|
|
134
|
+
startStreaming() {
|
|
135
|
+
if (this.outputManager.isStreaming()) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
// Start both managers
|
|
139
|
+
this.outputManager.startStream();
|
|
140
|
+
this.inputManager.startCapturing();
|
|
141
|
+
// Suppress readline's output so typed characters don't appear
|
|
142
|
+
this.suppressReadlineOutput();
|
|
143
|
+
this.emit('streaming-start');
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* End streaming mode
|
|
147
|
+
*
|
|
148
|
+
* Claude Code approach:
|
|
149
|
+
* - Stop capturing (any remaining buffer is preserved)
|
|
150
|
+
* - Restore readline echo
|
|
151
|
+
* - Return streaming statistics
|
|
152
|
+
*/
|
|
153
|
+
endStreaming() {
|
|
154
|
+
// Get remaining buffer before stopping capture
|
|
155
|
+
const remainingBuffer = this.inputManager.stopCapturing();
|
|
156
|
+
// If there's unsubmitted content in buffer, preserve it for next prompt
|
|
157
|
+
if (remainingBuffer && remainingBuffer.trim()) {
|
|
158
|
+
// The remaining buffer will be shown when readline prompts again
|
|
159
|
+
// We could queue it, but leaving it as-is is more intuitive
|
|
160
|
+
}
|
|
161
|
+
// Restore readline output
|
|
162
|
+
this.restoreReadlineOutput();
|
|
163
|
+
// End output streaming
|
|
164
|
+
const stats = this.outputManager.endStream();
|
|
165
|
+
const result = {
|
|
166
|
+
...stats,
|
|
167
|
+
queuedInputs: this.inputManager.getQueueLength(),
|
|
168
|
+
};
|
|
169
|
+
this.emit('streaming-end', stats);
|
|
170
|
+
return result;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Write content during streaming
|
|
174
|
+
* Just writes naturally to stdout - no cursor manipulation
|
|
175
|
+
*/
|
|
176
|
+
write(content) {
|
|
177
|
+
this.outputManager.writeChunk(content);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Write a complete line during streaming
|
|
181
|
+
*/
|
|
182
|
+
writeLine(line = '') {
|
|
183
|
+
this.outputManager.writeLine(line);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Check if currently streaming
|
|
187
|
+
*/
|
|
188
|
+
isStreaming() {
|
|
189
|
+
return this.outputManager.isStreaming();
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Get current state
|
|
193
|
+
*/
|
|
194
|
+
getState() {
|
|
195
|
+
const outputStats = this.outputManager.getStats();
|
|
196
|
+
return {
|
|
197
|
+
isStreaming: this.outputManager.isStreaming(),
|
|
198
|
+
queuedCount: this.inputManager.getQueueLength(),
|
|
199
|
+
charsWritten: outputStats.chars,
|
|
200
|
+
linesWritten: outputStats.lines,
|
|
201
|
+
elapsedMs: outputStats.elapsed,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Check if there are queued inputs to process
|
|
206
|
+
*/
|
|
207
|
+
hasQueuedInput() {
|
|
208
|
+
return this.inputManager.hasQueuedInput();
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Get the next queued input
|
|
212
|
+
*/
|
|
213
|
+
getNextQueuedInput() {
|
|
214
|
+
return this.inputManager.dequeue();
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Get all queued inputs
|
|
218
|
+
*/
|
|
219
|
+
getAllQueuedInputs() {
|
|
220
|
+
return this.inputManager.getQueue();
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Clear all queued inputs
|
|
224
|
+
*/
|
|
225
|
+
clearQueue() {
|
|
226
|
+
this.inputManager.clearQueue();
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Get queue summary for display
|
|
230
|
+
*/
|
|
231
|
+
getQueueSummary() {
|
|
232
|
+
return this.inputManager.getQueueSummary();
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Suppress readline's output during streaming
|
|
236
|
+
* Characters typed will be captured but not displayed
|
|
237
|
+
*/
|
|
238
|
+
suppressReadlineOutput() {
|
|
239
|
+
if (this.isOutputSuppressed) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
// Save original write function
|
|
243
|
+
this.originalStdoutWrite = this.writeStream.write.bind(this.writeStream);
|
|
244
|
+
// Replace with filtered version that suppresses readline echo
|
|
245
|
+
const outputManager = this.outputManager;
|
|
246
|
+
const originalWrite = this.originalStdoutWrite;
|
|
247
|
+
this.writeStream.write = function (chunk, encodingOrCallback, callback) {
|
|
248
|
+
const text = typeof chunk === 'string' ? chunk : chunk.toString();
|
|
249
|
+
// During streaming, only allow output from the streaming manager
|
|
250
|
+
// Suppress readline's echo of typed characters (single character writes)
|
|
251
|
+
if (outputManager.isStreaming()) {
|
|
252
|
+
// Allow newlines and multi-character writes (likely streaming content)
|
|
253
|
+
if (text.length === 1 && !text.includes('\n') && !text.includes('\r')) {
|
|
254
|
+
// Single character during streaming - likely user typing, suppress it
|
|
255
|
+
if (typeof encodingOrCallback === 'function') {
|
|
256
|
+
encodingOrCallback(null);
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
if (callback) {
|
|
260
|
+
callback(null);
|
|
261
|
+
}
|
|
262
|
+
return true;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
// Pass through everything else
|
|
266
|
+
// If lock is already held, write directly - we're in a protected context
|
|
267
|
+
// This prevents queuing issues where content gets delayed during streaming
|
|
268
|
+
if (writeLock.isLocked()) {
|
|
269
|
+
return originalWrite(chunk, encodingOrCallback, callback);
|
|
270
|
+
}
|
|
271
|
+
let result = true;
|
|
272
|
+
writeLock.withLock(() => {
|
|
273
|
+
result = originalWrite(chunk, encodingOrCallback, callback);
|
|
274
|
+
}, 'claudeCodeStreamHandler.stdout');
|
|
275
|
+
return result;
|
|
276
|
+
};
|
|
277
|
+
this.isOutputSuppressed = true;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Restore readline's normal output
|
|
281
|
+
*/
|
|
282
|
+
restoreReadlineOutput() {
|
|
283
|
+
if (!this.isOutputSuppressed || !this.originalStdoutWrite) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
this.writeStream.write = this.originalStdoutWrite;
|
|
287
|
+
this.originalStdoutWrite = null;
|
|
288
|
+
this.isOutputSuppressed = false;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Cleanup when done
|
|
292
|
+
*/
|
|
293
|
+
dispose() {
|
|
294
|
+
// Restore output if suppressed
|
|
295
|
+
this.restoreReadlineOutput();
|
|
296
|
+
// Remove keypress handler
|
|
297
|
+
if (this.keypressHandler && this.readStream) {
|
|
298
|
+
this.readStream.off('keypress', this.keypressHandler);
|
|
299
|
+
this.keypressHandler = null;
|
|
300
|
+
}
|
|
301
|
+
// Clear queue
|
|
302
|
+
this.inputManager.clearQueue();
|
|
303
|
+
this.rl = null;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Singleton instance for global use
|
|
308
|
+
*/
|
|
309
|
+
let globalInstance = null;
|
|
310
|
+
export function getClaudeCodeStreamHandler() {
|
|
311
|
+
if (!globalInstance) {
|
|
312
|
+
globalInstance = new ClaudeCodeStreamHandler();
|
|
313
|
+
}
|
|
314
|
+
return globalInstance;
|
|
315
|
+
}
|
|
316
|
+
export function resetClaudeCodeStreamHandler() {
|
|
317
|
+
if (globalInstance) {
|
|
318
|
+
globalInstance.dispose();
|
|
319
|
+
}
|
|
320
|
+
globalInstance = null;
|
|
321
|
+
}
|
|
322
|
+
//# sourceMappingURL=claudeCodeStreamHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claudeCodeStreamHandler.js","sourceRoot":"","sources":["../../src/shell/claudeCodeStreamHandler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,QAA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G,IAAI,CAAC;QAC9B,CAAC;QAED,cAAc;QACd,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,CAAC;QAE/B,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC;IACjB,CAAC;CACF;AAED;;GAEG;AACH,IAAI,cAAc,GAAmC,IAAI,CAAC;AAE1D,MAAM,UAAU,0BAA0B;IACxC,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,cAAc,GAAG,IAAI,uBAAuB,EAAE,CAAC;IACjD,CAAC;IACD,OAAO,cAAc,CAAC;AACxB,CAAC;AAED,MAAM,UAAU,4BAA4B;IAC1C,IAAI,cAAc,EAAE,CAAC;QACnB,cAAc,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IACD,cAAc,GAAG,IAAI,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* InputQueueManager - Queue-based input handling for Claude Code style streaming
|
|
3
|
+
*
|
|
4
|
+
* Key principles from Claude Code:
|
|
5
|
+
* 1. Readline handles input - Uses Node.js readline module
|
|
6
|
+
* 2. User can type while streaming - Input is queued in memory, not rendered
|
|
7
|
+
* 3. Queue-based approach: User types → stored in queue → processed after streaming ends
|
|
8
|
+
*
|
|
9
|
+
* The key insight is that the cursor is never moved during streaming.
|
|
10
|
+
* Input is captured "invisibly" while streaming, then processed when streaming ends.
|
|
11
|
+
*/
|
|
12
|
+
import { EventEmitter } from 'node:events';
|
|
13
|
+
export interface QueuedInput {
|
|
14
|
+
id: string;
|
|
15
|
+
text: string;
|
|
16
|
+
timestamp: number;
|
|
17
|
+
type: 'message' | 'command' | 'interrupt';
|
|
18
|
+
}
|
|
19
|
+
export interface InputQueueState {
|
|
20
|
+
isCapturing: boolean;
|
|
21
|
+
buffer: string;
|
|
22
|
+
cursorPosition: number;
|
|
23
|
+
queue: QueuedInput[];
|
|
24
|
+
}
|
|
25
|
+
export interface InputQueueEvents {
|
|
26
|
+
'input-queued': (input: QueuedInput) => void;
|
|
27
|
+
'input-processed': (input: QueuedInput) => void;
|
|
28
|
+
'queue-cleared': () => void;
|
|
29
|
+
'capture-start': () => void;
|
|
30
|
+
'capture-end': () => void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Manages input queuing during streaming output.
|
|
34
|
+
*
|
|
35
|
+
* When streaming is active:
|
|
36
|
+
* - Captures keystrokes into a buffer
|
|
37
|
+
* - On Enter, queues the input for later processing
|
|
38
|
+
* - Provides methods to process queue after streaming ends
|
|
39
|
+
*/
|
|
40
|
+
export declare class InputQueueManager extends EventEmitter {
|
|
41
|
+
private state;
|
|
42
|
+
private inputIdCounter;
|
|
43
|
+
private readonly maxQueueSize;
|
|
44
|
+
private readonly maxBufferLength;
|
|
45
|
+
constructor(options?: {
|
|
46
|
+
maxQueueSize?: number;
|
|
47
|
+
maxBufferLength?: number;
|
|
48
|
+
});
|
|
49
|
+
/**
|
|
50
|
+
* Start capturing input (during streaming)
|
|
51
|
+
* Input will be buffered and queued, not immediately processed
|
|
52
|
+
*/
|
|
53
|
+
startCapturing(): void;
|
|
54
|
+
/**
|
|
55
|
+
* Stop capturing input (after streaming ends)
|
|
56
|
+
* Returns any remaining buffer content
|
|
57
|
+
*/
|
|
58
|
+
stopCapturing(): string;
|
|
59
|
+
/**
|
|
60
|
+
* Check if currently capturing input
|
|
61
|
+
*/
|
|
62
|
+
isCapturing(): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Handle a character input
|
|
65
|
+
* During capturing, adds to buffer; otherwise ignored
|
|
66
|
+
*/
|
|
67
|
+
handleChar(char: string): void;
|
|
68
|
+
/**
|
|
69
|
+
* Handle backspace
|
|
70
|
+
*/
|
|
71
|
+
handleBackspace(): void;
|
|
72
|
+
/**
|
|
73
|
+
* Handle delete key
|
|
74
|
+
*/
|
|
75
|
+
handleDelete(): void;
|
|
76
|
+
/**
|
|
77
|
+
* Handle cursor left
|
|
78
|
+
*/
|
|
79
|
+
handleCursorLeft(): void;
|
|
80
|
+
/**
|
|
81
|
+
* Handle cursor right
|
|
82
|
+
*/
|
|
83
|
+
handleCursorRight(): void;
|
|
84
|
+
/**
|
|
85
|
+
* Handle Enter - queue the current buffer
|
|
86
|
+
* Returns the queued input or null if buffer was empty
|
|
87
|
+
*/
|
|
88
|
+
handleSubmit(): QueuedInput | null;
|
|
89
|
+
/**
|
|
90
|
+
* Handle Ctrl+C during capture - queue an interrupt
|
|
91
|
+
*/
|
|
92
|
+
handleInterrupt(): QueuedInput;
|
|
93
|
+
/**
|
|
94
|
+
* Get current buffer contents (for display purposes)
|
|
95
|
+
*/
|
|
96
|
+
getBuffer(): string;
|
|
97
|
+
/**
|
|
98
|
+
* Get current cursor position
|
|
99
|
+
*/
|
|
100
|
+
getCursorPosition(): number;
|
|
101
|
+
/**
|
|
102
|
+
* Get the number of queued inputs
|
|
103
|
+
*/
|
|
104
|
+
getQueueLength(): number;
|
|
105
|
+
/**
|
|
106
|
+
* Check if there are queued inputs
|
|
107
|
+
*/
|
|
108
|
+
hasQueuedInput(): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Get the next queued input without removing it
|
|
111
|
+
*/
|
|
112
|
+
peekQueue(): QueuedInput | undefined;
|
|
113
|
+
/**
|
|
114
|
+
* Get and remove the next queued input
|
|
115
|
+
*/
|
|
116
|
+
dequeue(): QueuedInput | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* Get all queued inputs (copy)
|
|
119
|
+
*/
|
|
120
|
+
getQueue(): QueuedInput[];
|
|
121
|
+
/**
|
|
122
|
+
* Clear all queued inputs
|
|
123
|
+
*/
|
|
124
|
+
clearQueue(): void;
|
|
125
|
+
/**
|
|
126
|
+
* Clear the current buffer
|
|
127
|
+
*/
|
|
128
|
+
clearBuffer(): void;
|
|
129
|
+
/**
|
|
130
|
+
* Set the buffer content directly (for paste handling)
|
|
131
|
+
*/
|
|
132
|
+
setBuffer(content: string, cursorPos?: number): void;
|
|
133
|
+
/**
|
|
134
|
+
* Get queue summary for display
|
|
135
|
+
*/
|
|
136
|
+
getQueueSummary(): string;
|
|
137
|
+
/**
|
|
138
|
+
* Get full state (for debugging)
|
|
139
|
+
*/
|
|
140
|
+
getState(): InputQueueState;
|
|
141
|
+
}
|
|
142
|
+
export declare function getInputQueueManager(): InputQueueManager;
|
|
143
|
+
export declare function resetInputQueueManager(): void;
|
|
144
|
+
//# sourceMappingURL=inputQueueManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inputQueueManager.d.ts","sourceRoot":"","sources":["../../src/shell/inputQueueManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,SAAS,GAAG,SAAS,GAAG,WAAW,CAAC;CAC3C;AAED,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,OAAO,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,WAAW,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAC/B,cAAc,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IAC7C,iBAAiB,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IAChD,eAAe,EAAE,MAAM,IAAI,CAAC;IAC5B,eAAe,EAAE,MAAM,IAAI,CAAC;IAC5B,aAAa,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED;;;;;;;GAOG;AACH,qBAAa,iBAAkB,SAAQ,YAAY;IACjD,OAAO,CAAC,KAAK,CAKX;IAEF,OAAO,CAAC,cAAc,CAAK;IAC3B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,eAAe,C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