erosolar-cli 1.7.299 → 1.7.300
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 +1 -3
- 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 +159 -221
- 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 +105 -98
- package/dist/shell/terminalInput.d.ts.map +1 -1
- package/dist/shell/terminalInput.js +471 -514
- package/dist/shell/terminalInput.js.map +1 -1
- package/dist/shell/terminalInputAdapter.d.ts +20 -41
- package/dist/shell/terminalInputAdapter.d.ts.map +1 -1
- package/dist/shell/terminalInputAdapter.js +30 -45
- 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
|
@@ -3,18 +3,15 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Design principles:
|
|
5
5
|
* - Single source of truth for input state
|
|
6
|
-
* - Content flows naturally from top to bottom (no scroll region pinning)
|
|
7
6
|
* - Native bracketed paste support (no heuristics)
|
|
8
7
|
* - Clean cursor model with render-time wrapping
|
|
9
8
|
* - State machine for different input modes
|
|
10
9
|
* - No readline dependency for display
|
|
11
10
|
*/
|
|
12
11
|
import { EventEmitter } from 'node:events';
|
|
13
|
-
import { isMultilinePaste } from '../core/multilinePasteHandler.js';
|
|
12
|
+
import { isMultilinePaste, generatePasteSummary } from '../core/multilinePasteHandler.js';
|
|
14
13
|
import { writeLock } from '../ui/writeLock.js';
|
|
15
|
-
import {
|
|
16
|
-
import { isStreamingMode } from '../ui/globalWriteLock.js';
|
|
17
|
-
import { formatThinking } from '../ui/toolDisplay.js';
|
|
14
|
+
import { UI_COLORS, DEFAULT_UI_CONFIG, } from '../ui/terminalUISchema.js';
|
|
18
15
|
// ANSI escape codes
|
|
19
16
|
const ESC = {
|
|
20
17
|
// Cursor control
|
|
@@ -24,12 +21,12 @@ const ESC = {
|
|
|
24
21
|
SHOW: '\x1b[?25h',
|
|
25
22
|
TO: (row, col) => `\x1b[${row};${col}H`,
|
|
26
23
|
TO_COL: (col) => `\x1b[${col}G`,
|
|
24
|
+
// Screen control
|
|
25
|
+
CLEAR_SCREEN: '\x1b[2J',
|
|
26
|
+
HOME: '\x1b[H',
|
|
27
27
|
// Line control
|
|
28
28
|
CLEAR_LINE: '\x1b[2K',
|
|
29
29
|
CLEAR_TO_END: '\x1b[0J',
|
|
30
|
-
// Scroll region
|
|
31
|
-
SET_SCROLL: (top, bottom) => `\x1b[${top};${bottom}r`,
|
|
32
|
-
RESET_SCROLL: '\x1b[r',
|
|
33
30
|
// Style
|
|
34
31
|
RESET: '\x1b[0m',
|
|
35
32
|
DIM: '\x1b[2m',
|
|
@@ -69,46 +66,47 @@ export class TerminalInput extends EventEmitter {
|
|
|
69
66
|
statusMessage = null;
|
|
70
67
|
overrideStatusMessage = null; // Secondary status (warnings, etc.)
|
|
71
68
|
streamingLabel = null; // Streaming progress indicator
|
|
72
|
-
metaElapsedSeconds = null; // Optional elapsed time for header line
|
|
73
|
-
metaTokensUsed = null; // Optional token usage
|
|
74
|
-
metaTokenLimit = null; // Optional token window
|
|
75
|
-
metaThinkingMs = null; // Optional thinking duration
|
|
76
|
-
metaThinkingHasContent = false; // Whether collapsed thinking content exists
|
|
77
69
|
lastRenderContent = '';
|
|
78
70
|
lastRenderCursor = -1;
|
|
79
71
|
renderDirty = false;
|
|
80
72
|
isRendering = false;
|
|
73
|
+
flowModeRenderedLines = 0; // Track lines rendered for clearing
|
|
74
|
+
inputAreaStartRow = 0; // Track absolute row position of input area
|
|
75
|
+
contentEndRow = 0; // Row where content ends (for idle mode positioning)
|
|
76
|
+
// Command suggestions (Claude Code style auto-complete)
|
|
77
|
+
commandSuggestions = [];
|
|
78
|
+
filteredSuggestions = [];
|
|
79
|
+
selectedSuggestionIndex = 0;
|
|
80
|
+
showSuggestions = false;
|
|
81
81
|
// Lifecycle
|
|
82
82
|
disposed = false;
|
|
83
83
|
enabled = true;
|
|
84
84
|
contextUsage = null;
|
|
85
|
-
contextAutoCompactThreshold = 90;
|
|
86
|
-
// Track current content row in scroll region (starts at top, moves down)
|
|
87
|
-
contentRow = 1;
|
|
88
|
-
thinkingModeLabel = null;
|
|
89
85
|
editMode = 'display-edits';
|
|
90
86
|
verificationEnabled = true;
|
|
91
87
|
autoContinueEnabled = false;
|
|
92
88
|
verificationHotkey = 'alt+v';
|
|
93
89
|
autoContinueHotkey = 'alt+c';
|
|
94
|
-
thinkingHotkey = '/thinking';
|
|
95
|
-
modelLabel = null;
|
|
96
|
-
providerLabel = null;
|
|
97
90
|
// Output interceptor cleanup
|
|
98
91
|
outputInterceptorCleanup;
|
|
99
|
-
//
|
|
100
|
-
|
|
101
|
-
|
|
92
|
+
// Metrics tracking for status bar
|
|
93
|
+
streamingStartTime = null;
|
|
94
|
+
thinkingEnabled = true;
|
|
95
|
+
modelInfo = null; // Provider · Model info
|
|
96
|
+
// Streaming input area render timer (updates elapsed time display)
|
|
102
97
|
streamingRenderTimer = null;
|
|
98
|
+
// Unified UI initialization flag
|
|
99
|
+
unifiedUIInitialized = false;
|
|
103
100
|
constructor(writeStream = process.stdout, config = {}) {
|
|
104
101
|
super();
|
|
105
102
|
this.out = writeStream;
|
|
103
|
+
// Use schema defaults for configuration consistency
|
|
106
104
|
this.config = {
|
|
107
|
-
maxLines: config.maxLines ??
|
|
108
|
-
maxLength: config.maxLength ??
|
|
105
|
+
maxLines: config.maxLines ?? DEFAULT_UI_CONFIG.inputArea.maxLines,
|
|
106
|
+
maxLength: config.maxLength ?? DEFAULT_UI_CONFIG.inputArea.maxLength,
|
|
109
107
|
maxQueueSize: config.maxQueueSize ?? 100,
|
|
110
|
-
promptChar: config.promptChar ??
|
|
111
|
-
continuationChar: config.continuationChar ??
|
|
108
|
+
promptChar: config.promptChar ?? DEFAULT_UI_CONFIG.inputArea.promptChar,
|
|
109
|
+
continuationChar: config.continuationChar ?? DEFAULT_UI_CONFIG.inputArea.continuationChar,
|
|
112
110
|
};
|
|
113
111
|
}
|
|
114
112
|
// ===========================================================================
|
|
@@ -187,36 +185,282 @@ export class TerminalInput extends EventEmitter {
|
|
|
187
185
|
if (handled)
|
|
188
186
|
return;
|
|
189
187
|
}
|
|
188
|
+
// Handle '?' for help hint (if buffer is empty)
|
|
189
|
+
if (str === '?' && this.buffer.length === 0) {
|
|
190
|
+
this.emit('showHelp');
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
190
193
|
// Insert printable characters
|
|
191
194
|
if (str && !key?.ctrl && !key?.meta) {
|
|
192
195
|
this.insertText(str);
|
|
193
196
|
}
|
|
194
197
|
}
|
|
198
|
+
// Banner content to write on init (set via setBannerContent before initializeUnifiedUI)
|
|
199
|
+
bannerContent = null;
|
|
200
|
+
/**
|
|
201
|
+
* Set banner content to be written when unified UI initializes.
|
|
202
|
+
*/
|
|
203
|
+
setBannerContent(content) {
|
|
204
|
+
this.bannerContent = content;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Initialize the unified UI system.
|
|
208
|
+
*
|
|
209
|
+
* Layout:
|
|
210
|
+
* 1. Clear screen
|
|
211
|
+
* 2. Write banner at top
|
|
212
|
+
* 3. Render floating input area below banner
|
|
213
|
+
*/
|
|
214
|
+
initializeUnifiedUI() {
|
|
215
|
+
if (this.unifiedUIInitialized) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
// Hide cursor during setup
|
|
219
|
+
this.write(ESC.HIDE);
|
|
220
|
+
// Clear screen and go home
|
|
221
|
+
this.write(ESC.HOME);
|
|
222
|
+
this.write(ESC.CLEAR_SCREEN);
|
|
223
|
+
// Write banner at top
|
|
224
|
+
if (this.bannerContent) {
|
|
225
|
+
process.stdout.write(this.bannerContent + '\n\n');
|
|
226
|
+
}
|
|
227
|
+
// Mark initialized
|
|
228
|
+
this.unifiedUIInitialized = true;
|
|
229
|
+
// Render floating input area
|
|
230
|
+
this.renderFloatingInputArea();
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Clear the input area at its tracked position.
|
|
234
|
+
* Returns true if something was cleared.
|
|
235
|
+
*/
|
|
236
|
+
clearInputArea() {
|
|
237
|
+
if (this.inputAreaStartRow > 0 && this.flowModeRenderedLines > 0) {
|
|
238
|
+
for (let i = 0; i < this.flowModeRenderedLines; i++) {
|
|
239
|
+
this.write(ESC.TO(this.inputAreaStartRow + i, 1));
|
|
240
|
+
this.write(ESC.CLEAR_LINE);
|
|
241
|
+
}
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Reset input area tracking state.
|
|
248
|
+
*/
|
|
249
|
+
resetInputAreaTracking() {
|
|
250
|
+
this.inputAreaStartRow = 0;
|
|
251
|
+
this.flowModeRenderedLines = 0;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Render floating input area below current content.
|
|
255
|
+
* This is "bottom floating" - follows content, not pinned to terminal bottom.
|
|
256
|
+
* Uses absolute positioning to prevent duplicates.
|
|
257
|
+
*/
|
|
258
|
+
renderFloatingInputArea() {
|
|
259
|
+
const { rows, cols } = this.getSize();
|
|
260
|
+
const divider = '─'.repeat(cols - 1);
|
|
261
|
+
const { dim: DIM, reset: R } = UI_COLORS;
|
|
262
|
+
// Calculate lines needed for input area
|
|
263
|
+
const linesNeeded = 5 + (this.modelInfo ? 1 : 0);
|
|
264
|
+
// FIRST: Clear any previously rendered input area
|
|
265
|
+
this.clearInputArea();
|
|
266
|
+
// Hide cursor during render
|
|
267
|
+
this.write(ESC.HIDE);
|
|
268
|
+
// Calculate where to render: after current content
|
|
269
|
+
// Use contentEndRow if set, otherwise estimate from terminal bottom
|
|
270
|
+
let startRow;
|
|
271
|
+
if (this.contentEndRow > 0) {
|
|
272
|
+
startRow = this.contentEndRow + 1;
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
// Render near bottom, leaving space for input area
|
|
276
|
+
startRow = Math.max(1, rows - linesNeeded);
|
|
277
|
+
}
|
|
278
|
+
// Ensure we don't go past terminal bounds
|
|
279
|
+
startRow = Math.min(startRow, rows - linesNeeded + 1);
|
|
280
|
+
startRow = Math.max(1, startRow);
|
|
281
|
+
// Track this position
|
|
282
|
+
this.inputAreaStartRow = startRow;
|
|
283
|
+
let currentRow = startRow;
|
|
284
|
+
// Status bar
|
|
285
|
+
this.write(ESC.TO(currentRow, 1));
|
|
286
|
+
this.write(this.buildStatusBar(cols));
|
|
287
|
+
currentRow++;
|
|
288
|
+
// Model info line (if set)
|
|
289
|
+
if (this.modelInfo) {
|
|
290
|
+
this.write(ESC.TO(currentRow, 1));
|
|
291
|
+
let modelLine = `${DIM}${this.modelInfo}${R}`;
|
|
292
|
+
if (this.contextUsage !== null) {
|
|
293
|
+
const rem = Math.max(0, 100 - this.contextUsage);
|
|
294
|
+
if (rem < 10)
|
|
295
|
+
modelLine += ` ${UI_COLORS.red}⚠ ctx: ${rem}%${R}`;
|
|
296
|
+
else if (rem < 25)
|
|
297
|
+
modelLine += ` ${UI_COLORS.yellow}! ctx: ${rem}%${R}`;
|
|
298
|
+
else
|
|
299
|
+
modelLine += ` ${DIM}· ctx: ${rem}%${R}`;
|
|
300
|
+
}
|
|
301
|
+
this.write(modelLine);
|
|
302
|
+
currentRow++;
|
|
303
|
+
}
|
|
304
|
+
// Top divider
|
|
305
|
+
this.write(ESC.TO(currentRow, 1));
|
|
306
|
+
this.write(divider);
|
|
307
|
+
currentRow++;
|
|
308
|
+
// Input line with prompt and buffer content
|
|
309
|
+
const { lines, cursorCol } = this.wrapBuffer(cols - 4);
|
|
310
|
+
const displayLine = lines[0] ?? '';
|
|
311
|
+
const inputRow = currentRow;
|
|
312
|
+
this.write(ESC.TO(currentRow, 1));
|
|
313
|
+
this.write(ESC.BG_DARK + ESC.DIM + this.config.promptChar + ESC.RESET);
|
|
314
|
+
this.write(ESC.BG_DARK + displayLine);
|
|
315
|
+
const padding = Math.max(0, cols - this.config.promptChar.length - displayLine.length - 1);
|
|
316
|
+
if (padding > 0)
|
|
317
|
+
this.write(' '.repeat(padding));
|
|
318
|
+
this.write(ESC.RESET);
|
|
319
|
+
currentRow++;
|
|
320
|
+
// Bottom divider
|
|
321
|
+
this.write(ESC.TO(currentRow, 1));
|
|
322
|
+
this.write(divider);
|
|
323
|
+
currentRow++;
|
|
324
|
+
// Mode controls
|
|
325
|
+
this.write(ESC.TO(currentRow, 1));
|
|
326
|
+
this.write(this.buildModeControls(cols));
|
|
327
|
+
// Track lines rendered
|
|
328
|
+
this.flowModeRenderedLines = currentRow - startRow + 1;
|
|
329
|
+
// Position cursor in input line for typing
|
|
330
|
+
this.write(ESC.TO(inputRow, this.config.promptChar.length + 1 + cursorCol));
|
|
331
|
+
// Show cursor
|
|
332
|
+
this.write(ESC.SHOW);
|
|
333
|
+
// Update tracking
|
|
334
|
+
this.lastRenderContent = this.buffer;
|
|
335
|
+
this.lastRenderCursor = this.cursor;
|
|
336
|
+
}
|
|
195
337
|
/**
|
|
196
338
|
* Set the input mode
|
|
197
339
|
*
|
|
198
|
-
*
|
|
340
|
+
* Unified floating input - input area always floats below content.
|
|
199
341
|
*/
|
|
200
342
|
setMode(mode) {
|
|
201
343
|
const prevMode = this.mode;
|
|
202
344
|
this.mode = mode;
|
|
203
345
|
if (mode === 'streaming' && prevMode !== 'streaming') {
|
|
204
|
-
|
|
346
|
+
// Track streaming start time for elapsed display
|
|
347
|
+
this.streamingStartTime = Date.now();
|
|
348
|
+
// Ensure unified UI is initialized
|
|
349
|
+
if (!this.unifiedUIInitialized) {
|
|
350
|
+
this.initializeUnifiedUI();
|
|
351
|
+
}
|
|
205
352
|
this.renderDirty = true;
|
|
206
|
-
this.
|
|
353
|
+
this.scheduleRender();
|
|
207
354
|
}
|
|
208
355
|
else if (mode !== 'streaming' && prevMode === 'streaming') {
|
|
209
|
-
//
|
|
210
|
-
this.
|
|
211
|
-
|
|
356
|
+
// Stop streaming render timer (if any)
|
|
357
|
+
if (this.streamingRenderTimer) {
|
|
358
|
+
clearInterval(this.streamingRenderTimer);
|
|
359
|
+
this.streamingRenderTimer = null;
|
|
360
|
+
}
|
|
361
|
+
// Reset streaming time
|
|
362
|
+
this.streamingStartTime = null;
|
|
363
|
+
// Re-render floating input area
|
|
364
|
+
this.renderDirty = true;
|
|
365
|
+
this.scheduleRender();
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Set the row where content ends (for idle mode positioning).
|
|
370
|
+
* Input area will render starting from this row + 1.
|
|
371
|
+
*/
|
|
372
|
+
setContentEndRow(row) {
|
|
373
|
+
this.contentEndRow = Math.max(0, row);
|
|
374
|
+
this.renderDirty = true;
|
|
375
|
+
this.scheduleRender();
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Set available slash commands for auto-complete suggestions.
|
|
379
|
+
*/
|
|
380
|
+
setCommands(commands) {
|
|
381
|
+
this.commandSuggestions = commands;
|
|
382
|
+
this.updateSuggestions();
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Update filtered suggestions based on current input.
|
|
386
|
+
*/
|
|
387
|
+
updateSuggestions() {
|
|
388
|
+
const input = this.buffer.trim();
|
|
389
|
+
// Only show suggestions when input starts with "/"
|
|
390
|
+
if (!input.startsWith('/')) {
|
|
391
|
+
this.showSuggestions = false;
|
|
392
|
+
this.filteredSuggestions = [];
|
|
393
|
+
this.selectedSuggestionIndex = 0;
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
const query = input.toLowerCase();
|
|
397
|
+
this.filteredSuggestions = this.commandSuggestions.filter(cmd => cmd.command.toLowerCase().startsWith(query) ||
|
|
398
|
+
cmd.command.toLowerCase().includes(query.slice(1)));
|
|
399
|
+
// Show suggestions if we have matches
|
|
400
|
+
this.showSuggestions = this.filteredSuggestions.length > 0;
|
|
401
|
+
// Keep selection in bounds
|
|
402
|
+
if (this.selectedSuggestionIndex >= this.filteredSuggestions.length) {
|
|
403
|
+
this.selectedSuggestionIndex = Math.max(0, this.filteredSuggestions.length - 1);
|
|
212
404
|
}
|
|
213
405
|
}
|
|
214
406
|
/**
|
|
215
|
-
*
|
|
216
|
-
|
|
407
|
+
* Select next suggestion (arrow down / tab).
|
|
408
|
+
*/
|
|
409
|
+
selectNextSuggestion() {
|
|
410
|
+
if (!this.showSuggestions || this.filteredSuggestions.length === 0)
|
|
411
|
+
return;
|
|
412
|
+
this.selectedSuggestionIndex = (this.selectedSuggestionIndex + 1) % this.filteredSuggestions.length;
|
|
413
|
+
this.renderDirty = true;
|
|
414
|
+
this.scheduleRender();
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Select previous suggestion (arrow up / shift+tab).
|
|
418
|
+
*/
|
|
419
|
+
selectPrevSuggestion() {
|
|
420
|
+
if (!this.showSuggestions || this.filteredSuggestions.length === 0)
|
|
421
|
+
return;
|
|
422
|
+
this.selectedSuggestionIndex = this.selectedSuggestionIndex === 0
|
|
423
|
+
? this.filteredSuggestions.length - 1
|
|
424
|
+
: this.selectedSuggestionIndex - 1;
|
|
425
|
+
this.renderDirty = true;
|
|
426
|
+
this.scheduleRender();
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Accept current suggestion and insert into buffer.
|
|
430
|
+
*/
|
|
431
|
+
acceptSuggestion() {
|
|
432
|
+
if (!this.showSuggestions || this.filteredSuggestions.length === 0)
|
|
433
|
+
return false;
|
|
434
|
+
const selected = this.filteredSuggestions[this.selectedSuggestionIndex];
|
|
435
|
+
if (!selected)
|
|
436
|
+
return false;
|
|
437
|
+
// Replace buffer with selected command
|
|
438
|
+
this.buffer = selected.command + ' ';
|
|
439
|
+
this.cursor = this.buffer.length;
|
|
440
|
+
this.showSuggestions = false;
|
|
441
|
+
this.renderDirty = true;
|
|
442
|
+
this.scheduleRender();
|
|
443
|
+
return true;
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Check if suggestions are visible.
|
|
447
|
+
*/
|
|
448
|
+
areSuggestionsVisible() {
|
|
449
|
+
return this.showSuggestions && this.filteredSuggestions.length > 0;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Toggle thinking/reasoning mode
|
|
453
|
+
*/
|
|
454
|
+
toggleThinking() {
|
|
455
|
+
this.thinkingEnabled = !this.thinkingEnabled;
|
|
456
|
+
this.emit('thinkingToggle', this.thinkingEnabled);
|
|
457
|
+
this.scheduleRender();
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Get thinking enabled state
|
|
217
461
|
*/
|
|
218
|
-
|
|
219
|
-
|
|
462
|
+
isThinkingEnabled() {
|
|
463
|
+
return this.thinkingEnabled;
|
|
220
464
|
}
|
|
221
465
|
/**
|
|
222
466
|
* Get current mode
|
|
@@ -249,14 +493,17 @@ export class TerminalInput extends EventEmitter {
|
|
|
249
493
|
}
|
|
250
494
|
/**
|
|
251
495
|
* Clear the buffer
|
|
496
|
+
* @param skipRender - If true, don't trigger a re-render (used during submit flow)
|
|
252
497
|
*/
|
|
253
|
-
clear() {
|
|
498
|
+
clear(skipRender = false) {
|
|
254
499
|
this.buffer = '';
|
|
255
500
|
this.cursor = 0;
|
|
256
501
|
this.historyIndex = -1;
|
|
257
502
|
this.tempInput = '';
|
|
258
503
|
this.pastePlaceholders = [];
|
|
259
|
-
|
|
504
|
+
if (!skipRender) {
|
|
505
|
+
this.scheduleRender();
|
|
506
|
+
}
|
|
260
507
|
}
|
|
261
508
|
/**
|
|
262
509
|
* Get queued inputs
|
|
@@ -327,37 +574,6 @@ export class TerminalInput extends EventEmitter {
|
|
|
327
574
|
this.streamingLabel = next;
|
|
328
575
|
this.scheduleRender();
|
|
329
576
|
}
|
|
330
|
-
/**
|
|
331
|
-
* Surface meta status just above the divider (e.g., elapsed time or token usage).
|
|
332
|
-
*/
|
|
333
|
-
setMetaStatus(meta) {
|
|
334
|
-
const nextElapsed = typeof meta.elapsedSeconds === 'number' && Number.isFinite(meta.elapsedSeconds) && meta.elapsedSeconds >= 0
|
|
335
|
-
? Math.floor(meta.elapsedSeconds)
|
|
336
|
-
: null;
|
|
337
|
-
const nextTokens = typeof meta.tokensUsed === 'number' && Number.isFinite(meta.tokensUsed) && meta.tokensUsed >= 0
|
|
338
|
-
? Math.floor(meta.tokensUsed)
|
|
339
|
-
: null;
|
|
340
|
-
const nextLimit = typeof meta.tokenLimit === 'number' && Number.isFinite(meta.tokenLimit) && meta.tokenLimit > 0
|
|
341
|
-
? Math.floor(meta.tokenLimit)
|
|
342
|
-
: null;
|
|
343
|
-
const nextThinking = typeof meta.thinkingMs === 'number' && Number.isFinite(meta.thinkingMs) && meta.thinkingMs >= 0
|
|
344
|
-
? Math.floor(meta.thinkingMs)
|
|
345
|
-
: null;
|
|
346
|
-
const nextThinkingHasContent = !!meta.thinkingHasContent;
|
|
347
|
-
if (this.metaElapsedSeconds === nextElapsed &&
|
|
348
|
-
this.metaTokensUsed === nextTokens &&
|
|
349
|
-
this.metaTokenLimit === nextLimit &&
|
|
350
|
-
this.metaThinkingMs === nextThinking &&
|
|
351
|
-
this.metaThinkingHasContent === nextThinkingHasContent) {
|
|
352
|
-
return;
|
|
353
|
-
}
|
|
354
|
-
this.metaElapsedSeconds = nextElapsed;
|
|
355
|
-
this.metaTokensUsed = nextTokens;
|
|
356
|
-
this.metaTokenLimit = nextLimit;
|
|
357
|
-
this.metaThinkingMs = nextThinking;
|
|
358
|
-
this.metaThinkingHasContent = nextThinkingHasContent;
|
|
359
|
-
this.scheduleRender();
|
|
360
|
-
}
|
|
361
577
|
/**
|
|
362
578
|
* Keep mode toggles (verification/auto-continue) visible in the control bar.
|
|
363
579
|
* Hotkey labels remain stable so the bar looks the same before/during streaming.
|
|
@@ -367,22 +583,26 @@ export class TerminalInput extends EventEmitter {
|
|
|
367
583
|
const nextAutoContinue = !!options.autoContinueEnabled;
|
|
368
584
|
const nextVerifyHotkey = options.verificationHotkey ?? this.verificationHotkey;
|
|
369
585
|
const nextAutoHotkey = options.autoContinueHotkey ?? this.autoContinueHotkey;
|
|
370
|
-
const nextThinkingHotkey = options.thinkingHotkey ?? this.thinkingHotkey;
|
|
371
|
-
const nextThinkingLabel = options.thinkingModeLabel === undefined ? this.thinkingModeLabel : (options.thinkingModeLabel || null);
|
|
372
586
|
if (this.verificationEnabled === nextVerification &&
|
|
373
587
|
this.autoContinueEnabled === nextAutoContinue &&
|
|
374
588
|
this.verificationHotkey === nextVerifyHotkey &&
|
|
375
|
-
this.autoContinueHotkey === nextAutoHotkey
|
|
376
|
-
this.thinkingHotkey === nextThinkingHotkey &&
|
|
377
|
-
this.thinkingModeLabel === nextThinkingLabel) {
|
|
589
|
+
this.autoContinueHotkey === nextAutoHotkey) {
|
|
378
590
|
return;
|
|
379
591
|
}
|
|
380
592
|
this.verificationEnabled = nextVerification;
|
|
381
593
|
this.autoContinueEnabled = nextAutoContinue;
|
|
382
594
|
this.verificationHotkey = nextVerifyHotkey;
|
|
383
595
|
this.autoContinueHotkey = nextAutoHotkey;
|
|
384
|
-
this.
|
|
385
|
-
|
|
596
|
+
this.scheduleRender();
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* Set the model info string (e.g., "OpenAI · gpt-4")
|
|
600
|
+
* This is displayed persistently above the input area.
|
|
601
|
+
*/
|
|
602
|
+
setModelInfo(info) {
|
|
603
|
+
if (this.modelInfo === info)
|
|
604
|
+
return;
|
|
605
|
+
this.modelInfo = info;
|
|
386
606
|
this.scheduleRender();
|
|
387
607
|
}
|
|
388
608
|
/**
|
|
@@ -395,155 +615,30 @@ export class TerminalInput extends EventEmitter {
|
|
|
395
615
|
this.scheduleRender();
|
|
396
616
|
}
|
|
397
617
|
/**
|
|
398
|
-
*
|
|
399
|
-
*/
|
|
400
|
-
setModelContext(options) {
|
|
401
|
-
const nextModel = options.model?.trim() || null;
|
|
402
|
-
const nextProvider = options.provider?.trim() || null;
|
|
403
|
-
if (this.modelLabel === nextModel && this.providerLabel === nextProvider) {
|
|
404
|
-
return;
|
|
405
|
-
}
|
|
406
|
-
this.modelLabel = nextModel;
|
|
407
|
-
this.providerLabel = nextProvider;
|
|
408
|
-
this.scheduleRender();
|
|
409
|
-
}
|
|
410
|
-
/**
|
|
411
|
-
* Render the floating input area at contentRow.
|
|
412
|
-
*
|
|
413
|
-
* The chat box "floats" - it renders right below the last streamed content.
|
|
414
|
-
* As content is added, contentRow advances, and the chat box moves down.
|
|
415
|
-
* No scroll regions - pure floating behavior.
|
|
618
|
+
* Render the input area - always floating below content.
|
|
416
619
|
*/
|
|
417
620
|
render() {
|
|
418
621
|
if (!this.canRender())
|
|
419
622
|
return;
|
|
420
623
|
if (this.isRendering)
|
|
421
624
|
return;
|
|
422
|
-
const streamingActive = this.mode === 'streaming' || isStreamingMode();
|
|
423
|
-
// During streaming, throttle re-renders
|
|
424
|
-
if (streamingActive && this.lastStreamingRender > 0) {
|
|
425
|
-
const elapsed = Date.now() - this.lastStreamingRender;
|
|
426
|
-
const waitMs = Math.max(0, this.streamingRenderInterval - elapsed);
|
|
427
|
-
if (waitMs > 0) {
|
|
428
|
-
this.renderDirty = true;
|
|
429
|
-
this.scheduleStreamingRender(waitMs);
|
|
430
|
-
return;
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
625
|
const shouldSkip = !this.renderDirty &&
|
|
434
626
|
this.buffer === this.lastRenderContent &&
|
|
435
627
|
this.cursor === this.lastRenderCursor;
|
|
436
628
|
this.renderDirty = false;
|
|
629
|
+
// Skip if nothing changed (unless explicitly forced)
|
|
437
630
|
if (shouldSkip) {
|
|
438
631
|
return;
|
|
439
632
|
}
|
|
633
|
+
// If write lock is held, defer render
|
|
440
634
|
if (writeLock.isLocked()) {
|
|
441
635
|
writeLock.safeWrite(() => this.render());
|
|
442
636
|
return;
|
|
443
637
|
}
|
|
444
|
-
this.renderFloatingInputArea();
|
|
445
|
-
}
|
|
446
|
-
/**
|
|
447
|
-
* Core floating input area renderer.
|
|
448
|
-
* Chat box always floats at contentRow (below streamed content).
|
|
449
|
-
* This creates "persistent bottom floating" behavior.
|
|
450
|
-
*/
|
|
451
|
-
renderFloatingInputArea() {
|
|
452
|
-
const { rows, cols } = this.getSize();
|
|
453
|
-
const maxWidth = Math.max(8, cols - 4);
|
|
454
|
-
const streamingActive = this.mode === 'streaming' || isStreamingMode();
|
|
455
|
-
// Wrap buffer into display lines
|
|
456
|
-
const { lines, cursorLine, cursorCol } = this.wrapBuffer(maxWidth);
|
|
457
|
-
const maxVisible = Math.max(1, Math.min(this.config.maxLines, rows - 3));
|
|
458
|
-
const displayLines = Math.min(lines.length, maxVisible);
|
|
459
|
-
const metaLines = this.buildMetaLines(cols - 2);
|
|
460
|
-
// Calculate display window (keep cursor visible)
|
|
461
|
-
let startLine = 0;
|
|
462
|
-
if (lines.length > displayLines) {
|
|
463
|
-
startLine = Math.max(0, cursorLine - displayLines + 1);
|
|
464
|
-
startLine = Math.min(startLine, lines.length - displayLines);
|
|
465
|
-
}
|
|
466
|
-
const visibleLines = lines.slice(startLine, startLine + displayLines);
|
|
467
|
-
const adjustedCursorLine = cursorLine - startLine;
|
|
468
|
-
// Chat box height
|
|
469
|
-
const chatBoxHeight = metaLines.length + 1 + displayLines + 1;
|
|
470
|
-
// Chat box floats at contentRow - right below the last content
|
|
471
|
-
// This is "persistent bottom floating" - always at bottom of content
|
|
472
|
-
const chatBoxStartRow = this.contentRow;
|
|
473
|
-
writeLock.lock('terminalInput.renderFloating');
|
|
474
638
|
this.isRendering = true;
|
|
639
|
+
writeLock.lock('terminalInput.render');
|
|
475
640
|
try {
|
|
476
|
-
|
|
477
|
-
this.write(ESC.HIDE);
|
|
478
|
-
this.write(ESC.RESET);
|
|
479
|
-
// Clear the chat box area
|
|
480
|
-
for (let i = 0; i < chatBoxHeight; i++) {
|
|
481
|
-
this.write(ESC.TO(chatBoxStartRow + i, 1));
|
|
482
|
-
this.write(ESC.CLEAR_LINE);
|
|
483
|
-
}
|
|
484
|
-
let currentRow = chatBoxStartRow;
|
|
485
|
-
// Meta/status header
|
|
486
|
-
for (const metaLine of metaLines) {
|
|
487
|
-
this.write(ESC.TO(currentRow, 1));
|
|
488
|
-
this.write(metaLine);
|
|
489
|
-
currentRow += 1;
|
|
490
|
-
}
|
|
491
|
-
// Separator line
|
|
492
|
-
this.write(ESC.TO(currentRow, 1));
|
|
493
|
-
this.write(renderDivider(cols - 2));
|
|
494
|
-
currentRow += 1;
|
|
495
|
-
// Render input lines
|
|
496
|
-
let finalRow = currentRow;
|
|
497
|
-
let finalCol = 3;
|
|
498
|
-
for (let i = 0; i < visibleLines.length; i++) {
|
|
499
|
-
const rowNum = currentRow + i;
|
|
500
|
-
this.write(ESC.TO(rowNum, 1));
|
|
501
|
-
const line = visibleLines[i] ?? '';
|
|
502
|
-
const isFirstLine = (startLine + i) === 0;
|
|
503
|
-
const isCursorLine = i === adjustedCursorLine;
|
|
504
|
-
this.write(ESC.BG_DARK);
|
|
505
|
-
this.write(ESC.DIM);
|
|
506
|
-
this.write(isFirstLine ? this.config.promptChar : this.config.continuationChar);
|
|
507
|
-
this.write(ESC.RESET);
|
|
508
|
-
this.write(ESC.BG_DARK);
|
|
509
|
-
if (isCursorLine) {
|
|
510
|
-
const col = Math.min(cursorCol, line.length);
|
|
511
|
-
const before = line.slice(0, col);
|
|
512
|
-
const at = col < line.length ? line[col] : ' ';
|
|
513
|
-
const after = col < line.length ? line.slice(col + 1) : '';
|
|
514
|
-
this.write(before);
|
|
515
|
-
this.write(ESC.REVERSE + ESC.BOLD);
|
|
516
|
-
this.write(at);
|
|
517
|
-
this.write(ESC.RESET + ESC.BG_DARK);
|
|
518
|
-
this.write(after);
|
|
519
|
-
finalRow = rowNum;
|
|
520
|
-
finalCol = this.config.promptChar.length + col + 1;
|
|
521
|
-
}
|
|
522
|
-
else {
|
|
523
|
-
this.write(line);
|
|
524
|
-
}
|
|
525
|
-
// Pad to edge
|
|
526
|
-
const lineLen = this.config.promptChar.length + line.length + (isCursorLine && cursorCol >= line.length ? 1 : 0);
|
|
527
|
-
const padding = Math.max(0, cols - lineLen - 1);
|
|
528
|
-
if (padding > 0)
|
|
529
|
-
this.write(' '.repeat(padding));
|
|
530
|
-
this.write(ESC.RESET);
|
|
531
|
-
}
|
|
532
|
-
// Mode controls line
|
|
533
|
-
const controlRow = currentRow + visibleLines.length;
|
|
534
|
-
this.write(ESC.TO(controlRow, 1));
|
|
535
|
-
this.write(this.buildModeControls(cols));
|
|
536
|
-
// Position cursor in input box
|
|
537
|
-
this.write(ESC.TO(finalRow, Math.min(finalCol, cols)));
|
|
538
|
-
this.write(ESC.SHOW);
|
|
539
|
-
// Update state
|
|
540
|
-
this.lastRenderContent = this.buffer;
|
|
541
|
-
this.lastRenderCursor = this.cursor;
|
|
542
|
-
this.lastStreamingRender = streamingActive ? Date.now() : 0;
|
|
543
|
-
if (this.streamingRenderTimer) {
|
|
544
|
-
clearTimeout(this.streamingRenderTimer);
|
|
545
|
-
this.streamingRenderTimer = null;
|
|
546
|
-
}
|
|
641
|
+
this.renderFloatingInputArea();
|
|
547
642
|
}
|
|
548
643
|
finally {
|
|
549
644
|
writeLock.unlock();
|
|
@@ -551,217 +646,99 @@ export class TerminalInput extends EventEmitter {
|
|
|
551
646
|
}
|
|
552
647
|
}
|
|
553
648
|
/**
|
|
554
|
-
* Build
|
|
555
|
-
*
|
|
649
|
+
* Build status bar showing streaming/ready status and key info.
|
|
650
|
+
* This is the TOP line above the input area - minimal Claude Code style.
|
|
556
651
|
*/
|
|
557
|
-
|
|
558
|
-
const
|
|
559
|
-
const
|
|
560
|
-
//
|
|
561
|
-
if (this.
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
if (streamingActive) {
|
|
569
|
-
const parts = [];
|
|
570
|
-
// Essential streaming info
|
|
571
|
-
if (this.metaThinkingMs !== null) {
|
|
572
|
-
parts.push({ text: formatThinking(this.metaThinkingMs, this.metaThinkingHasContent), tone: 'info' });
|
|
573
|
-
}
|
|
574
|
-
if (this.metaElapsedSeconds !== null) {
|
|
575
|
-
parts.push({ text: this.formatElapsedLabel(this.metaElapsedSeconds), tone: 'muted' });
|
|
576
|
-
}
|
|
577
|
-
parts.push({ text: 'esc to stop', tone: 'warn' });
|
|
578
|
-
if (parts.length) {
|
|
579
|
-
lines.push(renderStatusLine(parts, width));
|
|
652
|
+
buildStatusBar(cols) {
|
|
653
|
+
const maxWidth = cols - 2;
|
|
654
|
+
const parts = [];
|
|
655
|
+
// Streaming status with elapsed time (left side)
|
|
656
|
+
if (this.mode === 'streaming') {
|
|
657
|
+
let statusText = '● Streaming';
|
|
658
|
+
if (this.streamingStartTime) {
|
|
659
|
+
const elapsed = Math.floor((Date.now() - this.streamingStartTime) / 1000);
|
|
660
|
+
const mins = Math.floor(elapsed / 60);
|
|
661
|
+
const secs = elapsed % 60;
|
|
662
|
+
statusText += mins > 0 ? ` ${mins}m ${secs}s` : ` ${secs}s`;
|
|
580
663
|
}
|
|
581
|
-
|
|
582
|
-
}
|
|
583
|
-
// Non-streaming: show full status info (model line already added above)
|
|
584
|
-
if (this.metaThinkingMs !== null) {
|
|
585
|
-
const thinkingText = formatThinking(this.metaThinkingMs, this.metaThinkingHasContent);
|
|
586
|
-
lines.push(renderStatusLine([{ text: thinkingText, tone: 'info' }], width));
|
|
664
|
+
parts.push(`\x1b[32m${statusText}\x1b[0m`); // Green
|
|
587
665
|
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
statusParts.push({ text: statusLabel, tone: 'info' });
|
|
666
|
+
// Queue indicator during streaming
|
|
667
|
+
if (this.mode === 'streaming' && this.queue.length > 0) {
|
|
668
|
+
parts.push(`\x1b[36mqueued: ${this.queue.length}\x1b[0m`); // Cyan
|
|
592
669
|
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
if (tokensRemaining !== null) {
|
|
598
|
-
statusParts.push({ text: `↓ ${tokensRemaining}`, tone: 'muted' });
|
|
599
|
-
}
|
|
600
|
-
if (statusParts.length) {
|
|
601
|
-
lines.push(renderStatusLine(statusParts, width));
|
|
670
|
+
// Paste indicator
|
|
671
|
+
if (this.pastePlaceholders.length > 0) {
|
|
672
|
+
const totalLines = this.pastePlaceholders.reduce((sum, p) => sum + p.lineCount, 0);
|
|
673
|
+
parts.push(`\x1b[36m📋 ${totalLines}L\x1b[0m`);
|
|
602
674
|
}
|
|
603
|
-
|
|
604
|
-
if (this.
|
|
605
|
-
|
|
606
|
-
const formattedLimit = this.metaTokenLimit ? `/${this.formatTokenCount(this.metaTokenLimit)}` : '';
|
|
607
|
-
usageParts.push({ text: `tokens ${formattedUsed}${formattedLimit}`, tone: 'muted' });
|
|
675
|
+
// Override/warning status
|
|
676
|
+
if (this.overrideStatusMessage) {
|
|
677
|
+
parts.push(`\x1b[33m⚠ ${this.overrideStatusMessage}\x1b[0m`); // Yellow
|
|
608
678
|
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
usageParts.push({ text: `context used ${this.contextUsage}% (${left}% left)`, tone });
|
|
679
|
+
// If idle with empty buffer, show quick shortcuts
|
|
680
|
+
if (this.mode !== 'streaming' && this.buffer.length === 0 && parts.length === 0) {
|
|
681
|
+
return `${ESC.DIM}Type a message or / for commands${ESC.RESET}`;
|
|
613
682
|
}
|
|
614
|
-
|
|
615
|
-
|
|
683
|
+
// Multi-line indicator
|
|
684
|
+
if (this.buffer.includes('\n')) {
|
|
685
|
+
parts.push(`${ESC.DIM}${this.buffer.split('\n').length}L${ESC.RESET}`);
|
|
616
686
|
}
|
|
617
|
-
if (
|
|
618
|
-
|
|
687
|
+
if (parts.length === 0) {
|
|
688
|
+
return ''; // Empty status bar when idle
|
|
619
689
|
}
|
|
620
|
-
|
|
690
|
+
const joined = parts.join(`${ESC.DIM} · ${ESC.RESET}`);
|
|
691
|
+
return joined.slice(0, maxWidth);
|
|
621
692
|
}
|
|
622
693
|
/**
|
|
623
|
-
* Build
|
|
624
|
-
*
|
|
694
|
+
* Build mode controls line showing toggles and context info.
|
|
695
|
+
* This is the BOTTOM line below the input area - Claude Code style layout with erosolar features.
|
|
696
|
+
*
|
|
697
|
+
* Layout: [toggles on left] ... [context info on right]
|
|
625
698
|
*/
|
|
626
699
|
buildModeControls(cols) {
|
|
627
|
-
const
|
|
628
|
-
|
|
629
|
-
const
|
|
630
|
-
|
|
631
|
-
|
|
700
|
+
const maxWidth = cols - 2;
|
|
701
|
+
// Use schema-defined colors for consistency
|
|
702
|
+
const { green: GREEN, yellow: YELLOW, cyan: CYAN, magenta: MAGENTA, red: RED, dim: DIM, reset: R } = UI_COLORS;
|
|
703
|
+
// Mode toggles with colors (following ModeControlsSchema)
|
|
704
|
+
const toggles = [];
|
|
705
|
+
// Edit mode (green=auto, yellow=ask) - per schema.editMode
|
|
706
|
+
if (this.editMode === 'display-edits') {
|
|
707
|
+
toggles.push(`${GREEN}⏵⏵ auto-edit${R}`);
|
|
632
708
|
}
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
rightParts.push({ text: `${thinkingHotkey} thinking:${this.thinkingModeLabel}`, tone: 'info' });
|
|
667
|
-
}
|
|
668
|
-
// Show model in controls only when NOT streaming (during streaming it's in meta lines)
|
|
669
|
-
const streamingActive = this.mode === 'streaming' || isStreamingMode();
|
|
670
|
-
if (this.modelLabel && !streamingActive) {
|
|
671
|
-
const modelText = this.providerLabel ? `${this.modelLabel} @ ${this.providerLabel}` : this.modelLabel;
|
|
672
|
-
rightParts.push({ text: modelText, tone: 'muted' });
|
|
673
|
-
}
|
|
674
|
-
if (contextRemaining !== null) {
|
|
675
|
-
const tone = contextRemaining <= 10 ? 'warn' : 'muted';
|
|
676
|
-
const label = contextRemaining === 0 && this.contextUsage !== null
|
|
677
|
-
? 'Context auto-compact imminent'
|
|
678
|
-
: `Context left until auto-compact: ${contextRemaining}%`;
|
|
679
|
-
rightParts.push({ text: label, tone });
|
|
680
|
-
}
|
|
681
|
-
if (!rightParts.length || width < 60) {
|
|
682
|
-
const merged = rightParts.length ? [...leftParts, ...rightParts] : leftParts;
|
|
683
|
-
return renderStatusLine(merged, width);
|
|
684
|
-
}
|
|
685
|
-
const leftWidth = Math.max(12, Math.floor(width * 0.6));
|
|
686
|
-
const rightWidth = Math.max(14, width - leftWidth - 1);
|
|
687
|
-
const leftText = renderStatusLine(leftParts, leftWidth);
|
|
688
|
-
const rightText = renderStatusLine(rightParts, rightWidth);
|
|
689
|
-
const spacing = Math.max(1, width - this.visibleLength(leftText) - this.visibleLength(rightText));
|
|
690
|
-
return `${leftText}${' '.repeat(spacing)}${rightText}`;
|
|
691
|
-
}
|
|
692
|
-
formatHotkey(hotkey) {
|
|
693
|
-
const normalized = hotkey.trim().toLowerCase();
|
|
694
|
-
if (!normalized)
|
|
695
|
-
return hotkey;
|
|
696
|
-
const parts = normalized.split('+').filter(Boolean);
|
|
697
|
-
const map = {
|
|
698
|
-
shift: '⇧',
|
|
699
|
-
sh: '⇧',
|
|
700
|
-
alt: '⌥',
|
|
701
|
-
option: '⌥',
|
|
702
|
-
opt: '⌥',
|
|
703
|
-
ctrl: '⌃',
|
|
704
|
-
control: '⌃',
|
|
705
|
-
cmd: '⌘',
|
|
706
|
-
meta: '⌘',
|
|
707
|
-
};
|
|
708
|
-
const formatted = parts
|
|
709
|
-
.map((part) => {
|
|
710
|
-
const symbol = map[part];
|
|
711
|
-
if (symbol)
|
|
712
|
-
return symbol;
|
|
713
|
-
return part.length === 1 ? part.toUpperCase() : part.toUpperCase();
|
|
714
|
-
})
|
|
715
|
-
.join('');
|
|
716
|
-
return formatted || hotkey;
|
|
717
|
-
}
|
|
718
|
-
computeContextRemaining() {
|
|
719
|
-
if (this.contextUsage === null) {
|
|
720
|
-
return null;
|
|
721
|
-
}
|
|
722
|
-
return Math.max(0, this.contextAutoCompactThreshold - this.contextUsage);
|
|
723
|
-
}
|
|
724
|
-
computeTokensRemaining() {
|
|
725
|
-
if (this.metaTokensUsed === null || this.metaTokenLimit === null) {
|
|
726
|
-
return null;
|
|
727
|
-
}
|
|
728
|
-
const remaining = Math.max(0, this.metaTokenLimit - this.metaTokensUsed);
|
|
729
|
-
return this.formatTokenCount(remaining);
|
|
730
|
-
}
|
|
731
|
-
formatElapsedLabel(seconds) {
|
|
732
|
-
if (seconds < 60) {
|
|
733
|
-
return `${seconds}s`;
|
|
734
|
-
}
|
|
735
|
-
const mins = Math.floor(seconds / 60);
|
|
736
|
-
const secs = seconds % 60;
|
|
737
|
-
return secs > 0 ? `${mins}m ${secs}s` : `${mins}m`;
|
|
738
|
-
}
|
|
739
|
-
formatTokenCount(value) {
|
|
740
|
-
if (!Number.isFinite(value)) {
|
|
741
|
-
return `${value}`;
|
|
742
|
-
}
|
|
743
|
-
if (value >= 1_000_000) {
|
|
744
|
-
return `${(value / 1_000_000).toFixed(1)}M`;
|
|
745
|
-
}
|
|
746
|
-
if (value >= 1_000) {
|
|
747
|
-
return `${(value / 1_000).toFixed(1)}k`;
|
|
748
|
-
}
|
|
749
|
-
return `${Math.round(value)}`;
|
|
750
|
-
}
|
|
751
|
-
visibleLength(value) {
|
|
752
|
-
const ansiPattern = /\u001B\[[0-?]*[ -/]*[@-~]/g;
|
|
753
|
-
return value.replace(ansiPattern, '').length;
|
|
754
|
-
}
|
|
755
|
-
/**
|
|
756
|
-
* Debug-only snapshot used by tests to assert rendered strings without
|
|
757
|
-
* needing a TTY. Not used by production code.
|
|
758
|
-
*/
|
|
759
|
-
getDebugUiSnapshot(width) {
|
|
760
|
-
const cols = Math.max(8, width ?? this.getSize().cols);
|
|
761
|
-
return {
|
|
762
|
-
meta: this.buildMetaLines(cols - 2),
|
|
763
|
-
controls: this.buildModeControls(cols),
|
|
764
|
-
};
|
|
709
|
+
else {
|
|
710
|
+
toggles.push(`${YELLOW}⏸⏸ ask-first${R}`);
|
|
711
|
+
}
|
|
712
|
+
// Thinking mode (cyan when on) - per schema.thinkingMode
|
|
713
|
+
toggles.push(this.thinkingEnabled ? `${CYAN}💭 think${R}` : `${DIM}○ think${R}`);
|
|
714
|
+
// Verification (green when on) - per schema.verificationMode
|
|
715
|
+
toggles.push(this.verificationEnabled ? `${GREEN}✓ verify${R}` : `${DIM}○ verify${R}`);
|
|
716
|
+
// Auto-continue (magenta when on) - per schema.autoContinueMode
|
|
717
|
+
toggles.push(this.autoContinueEnabled ? `${MAGENTA}↻ auto${R}` : `${DIM}○ auto${R}`);
|
|
718
|
+
const leftPart = toggles.join(`${DIM} · ${R}`) + `${DIM} (⇧⇥)${R}`;
|
|
719
|
+
// Context usage with color - per schema.contextUsage thresholds
|
|
720
|
+
let rightPart = '';
|
|
721
|
+
if (this.contextUsage !== null) {
|
|
722
|
+
const rem = Math.max(0, 100 - this.contextUsage);
|
|
723
|
+
// Thresholds: critical < 10%, warning < 25%
|
|
724
|
+
if (rem < 10)
|
|
725
|
+
rightPart = `${RED}⚠ ctx: ${rem}%${R}`;
|
|
726
|
+
else if (rem < 25)
|
|
727
|
+
rightPart = `${YELLOW}! ctx: ${rem}%${R}`;
|
|
728
|
+
else
|
|
729
|
+
rightPart = `${DIM}ctx: ${rem}%${R}`;
|
|
730
|
+
}
|
|
731
|
+
// Calculate visible lengths (strip ANSI)
|
|
732
|
+
const strip = (s) => s.replace(/\x1b\[[0-9;]*m/g, '');
|
|
733
|
+
const leftLen = strip(leftPart).length;
|
|
734
|
+
const rightLen = strip(rightPart).length;
|
|
735
|
+
if (leftLen + rightLen < maxWidth - 4) {
|
|
736
|
+
return `${leftPart}${' '.repeat(maxWidth - leftLen - rightLen)}${rightPart}`;
|
|
737
|
+
}
|
|
738
|
+
if (rightLen > 0 && leftLen + 8 < maxWidth) {
|
|
739
|
+
return `${leftPart} ${rightPart}`;
|
|
740
|
+
}
|
|
741
|
+
return leftPart;
|
|
765
742
|
}
|
|
766
743
|
/**
|
|
767
744
|
* Force a re-render
|
|
@@ -784,91 +761,32 @@ export class TerminalInput extends EventEmitter {
|
|
|
784
761
|
handleResize() {
|
|
785
762
|
this.lastRenderContent = '';
|
|
786
763
|
this.lastRenderCursor = -1;
|
|
787
|
-
this.resetStreamingRenderThrottle();
|
|
788
764
|
this.scheduleRender();
|
|
789
765
|
}
|
|
790
766
|
/**
|
|
791
|
-
* Register with display's output interceptor
|
|
792
|
-
*
|
|
767
|
+
* Register with display's output interceptor (kept for API compatibility).
|
|
768
|
+
* With unified floating input, no special cursor manipulation is needed.
|
|
793
769
|
*/
|
|
794
770
|
registerOutputInterceptor(display) {
|
|
795
771
|
if (this.outputInterceptorCleanup) {
|
|
796
772
|
this.outputInterceptorCleanup();
|
|
797
773
|
}
|
|
798
774
|
this.outputInterceptorCleanup = display.registerOutputInterceptor({
|
|
799
|
-
beforeWrite: () => {
|
|
800
|
-
|
|
801
|
-
// This allows content to be written where the chat box was
|
|
802
|
-
const metaLines = this.buildMetaLines(this.getSize().cols - 2);
|
|
803
|
-
const chatBoxHeight = metaLines.length + 1 + 2 + 1; // meta + divider + 1 line input + controls
|
|
804
|
-
// Clear the chat box area so content can be written there
|
|
805
|
-
for (let i = 0; i < chatBoxHeight; i++) {
|
|
806
|
-
this.write(ESC.TO(this.contentRow + i, 1));
|
|
807
|
-
this.write(ESC.CLEAR_LINE);
|
|
808
|
-
}
|
|
809
|
-
// Position cursor at contentRow for writing new content
|
|
810
|
-
this.write(ESC.TO(this.contentRow, 1));
|
|
811
|
-
},
|
|
812
|
-
afterWrite: (content) => {
|
|
813
|
-
// Advance contentRow by number of newlines in the content
|
|
814
|
-
const newlines = content ? (content.match(/\n/g) || []).length : 0;
|
|
815
|
-
this.contentRow += newlines;
|
|
816
|
-
// Schedule re-render to show chat box at new position (below new content)
|
|
817
|
-
this.scheduleRender();
|
|
818
|
-
},
|
|
775
|
+
beforeWrite: () => { },
|
|
776
|
+
afterWrite: () => { },
|
|
819
777
|
});
|
|
820
778
|
}
|
|
821
|
-
/**
|
|
822
|
-
* Write content above the floating chat box.
|
|
823
|
-
* Clears the chat box, writes content at contentRow, advances contentRow, re-renders chat box.
|
|
824
|
-
*/
|
|
825
|
-
writeToScrollRegion(content) {
|
|
826
|
-
if (!content)
|
|
827
|
-
return;
|
|
828
|
-
// Get chat box dimensions for clearing
|
|
829
|
-
const { cols } = this.getSize();
|
|
830
|
-
const metaLines = this.buildMetaLines(cols - 2);
|
|
831
|
-
const chatBoxHeight = metaLines.length + 1 + 1 + 1 + 2; // meta + divider + input + controls + buffer
|
|
832
|
-
// Clear the current chat box area (it will re-render at new position)
|
|
833
|
-
for (let i = 0; i < chatBoxHeight; i++) {
|
|
834
|
-
this.write(ESC.TO(this.contentRow + i, 1));
|
|
835
|
-
this.write(ESC.CLEAR_LINE);
|
|
836
|
-
}
|
|
837
|
-
// Write content at contentRow
|
|
838
|
-
this.write(ESC.TO(this.contentRow, 1));
|
|
839
|
-
this.write(content);
|
|
840
|
-
// Advance contentRow by number of newlines
|
|
841
|
-
const newlines = (content.match(/\n/g) || []).length;
|
|
842
|
-
this.contentRow += newlines;
|
|
843
|
-
// Re-render chat box at new position (below the content just written)
|
|
844
|
-
this.forceRender();
|
|
845
|
-
}
|
|
846
|
-
/**
|
|
847
|
-
* Reset content position to row 1.
|
|
848
|
-
* Does NOT clear the terminal - content starts from current position.
|
|
849
|
-
*/
|
|
850
|
-
resetContentPosition() {
|
|
851
|
-
this.contentRow = 1;
|
|
852
|
-
}
|
|
853
|
-
/**
|
|
854
|
-
* Set the content row explicitly (used after banner is written).
|
|
855
|
-
* This tells the input where content should start flowing from.
|
|
856
|
-
*/
|
|
857
|
-
setContentRow(row) {
|
|
858
|
-
this.contentRow = Math.max(1, row);
|
|
859
|
-
}
|
|
860
|
-
/**
|
|
861
|
-
* Get the current content row position.
|
|
862
|
-
*/
|
|
863
|
-
getContentRow() {
|
|
864
|
-
return this.contentRow;
|
|
865
|
-
}
|
|
866
779
|
/**
|
|
867
780
|
* Dispose and clean up
|
|
868
781
|
*/
|
|
869
782
|
dispose() {
|
|
870
783
|
if (this.disposed)
|
|
871
784
|
return;
|
|
785
|
+
// Clean up streaming render timer
|
|
786
|
+
if (this.streamingRenderTimer) {
|
|
787
|
+
clearInterval(this.streamingRenderTimer);
|
|
788
|
+
this.streamingRenderTimer = null;
|
|
789
|
+
}
|
|
872
790
|
// Clean up output interceptor
|
|
873
791
|
if (this.outputInterceptorCleanup) {
|
|
874
792
|
this.outputInterceptorCleanup();
|
|
@@ -876,7 +794,6 @@ export class TerminalInput extends EventEmitter {
|
|
|
876
794
|
}
|
|
877
795
|
this.disposed = true;
|
|
878
796
|
this.enabled = false;
|
|
879
|
-
this.resetStreamingRenderThrottle();
|
|
880
797
|
this.disableBracketedPaste();
|
|
881
798
|
this.buffer = '';
|
|
882
799
|
this.queue = [];
|
|
@@ -981,7 +898,22 @@ export class TerminalInput extends EventEmitter {
|
|
|
981
898
|
this.toggleEditMode();
|
|
982
899
|
return true;
|
|
983
900
|
}
|
|
984
|
-
|
|
901
|
+
// Tab: toggle paste expansion if in placeholder, otherwise toggle thinking
|
|
902
|
+
if (this.findPlaceholderAt(this.cursor)) {
|
|
903
|
+
this.togglePasteExpansion();
|
|
904
|
+
}
|
|
905
|
+
else {
|
|
906
|
+
this.toggleThinking();
|
|
907
|
+
}
|
|
908
|
+
return true;
|
|
909
|
+
case 'escape':
|
|
910
|
+
// Esc: interrupt if streaming, otherwise clear buffer
|
|
911
|
+
if (this.mode === 'streaming') {
|
|
912
|
+
this.emit('interrupt');
|
|
913
|
+
}
|
|
914
|
+
else if (this.buffer.length > 0) {
|
|
915
|
+
this.clear();
|
|
916
|
+
}
|
|
985
917
|
return true;
|
|
986
918
|
}
|
|
987
919
|
return false;
|
|
@@ -999,6 +931,7 @@ export class TerminalInput extends EventEmitter {
|
|
|
999
931
|
this.insertPlainText(chunk, insertPos);
|
|
1000
932
|
this.cursor = insertPos + chunk.length;
|
|
1001
933
|
this.emit('change', this.buffer);
|
|
934
|
+
this.updateSuggestions();
|
|
1002
935
|
this.scheduleRender();
|
|
1003
936
|
}
|
|
1004
937
|
insertNewline() {
|
|
@@ -1023,6 +956,7 @@ export class TerminalInput extends EventEmitter {
|
|
|
1023
956
|
this.cursor = Math.max(0, this.cursor - 1);
|
|
1024
957
|
}
|
|
1025
958
|
this.emit('change', this.buffer);
|
|
959
|
+
this.updateSuggestions();
|
|
1026
960
|
this.scheduleRender();
|
|
1027
961
|
}
|
|
1028
962
|
deleteForward() {
|
|
@@ -1250,12 +1184,13 @@ export class TerminalInput extends EventEmitter {
|
|
|
1250
1184
|
timestamp: Date.now(),
|
|
1251
1185
|
});
|
|
1252
1186
|
this.emit('queue', text);
|
|
1253
|
-
this.clear(); // Clear immediately for queued input
|
|
1187
|
+
this.clear(); // Clear immediately for queued input, re-render to update queue display
|
|
1254
1188
|
}
|
|
1255
1189
|
else {
|
|
1256
|
-
// In idle mode, clear the input
|
|
1257
|
-
// The
|
|
1258
|
-
|
|
1190
|
+
// In idle mode, clear the input WITHOUT rendering.
|
|
1191
|
+
// The caller will display the user message and start streaming.
|
|
1192
|
+
// We'll render the input area again after streaming ends.
|
|
1193
|
+
this.clear(true); // Skip render - streaming will handle display
|
|
1259
1194
|
this.emit('submit', text);
|
|
1260
1195
|
}
|
|
1261
1196
|
}
|
|
@@ -1272,9 +1207,7 @@ export class TerminalInput extends EventEmitter {
|
|
|
1272
1207
|
if (available <= 0)
|
|
1273
1208
|
return;
|
|
1274
1209
|
const chunk = clean.slice(0, available);
|
|
1275
|
-
|
|
1276
|
-
const isShortMultiline = isMultiline && this.shouldInlineMultiline(chunk);
|
|
1277
|
-
if (isMultiline && !isShortMultiline) {
|
|
1210
|
+
if (isMultilinePaste(chunk)) {
|
|
1278
1211
|
this.insertPastePlaceholder(chunk);
|
|
1279
1212
|
}
|
|
1280
1213
|
else {
|
|
@@ -1410,19 +1343,17 @@ export class TerminalInput extends EventEmitter {
|
|
|
1410
1343
|
this.shiftPlaceholders(position, text.length);
|
|
1411
1344
|
this.buffer = this.buffer.slice(0, position) + text + this.buffer.slice(position);
|
|
1412
1345
|
}
|
|
1413
|
-
shouldInlineMultiline(content) {
|
|
1414
|
-
const lines = content.split('\n').length;
|
|
1415
|
-
const maxInlineLines = 4;
|
|
1416
|
-
const maxInlineChars = 240;
|
|
1417
|
-
return lines <= maxInlineLines && content.length <= maxInlineChars;
|
|
1418
|
-
}
|
|
1419
1346
|
findPlaceholderAt(position) {
|
|
1420
1347
|
return this.pastePlaceholders.find((ph) => position >= ph.start && position < ph.end) ?? null;
|
|
1421
1348
|
}
|
|
1422
|
-
buildPlaceholder(
|
|
1349
|
+
buildPlaceholder(summary) {
|
|
1423
1350
|
const id = ++this.pasteCounter;
|
|
1424
|
-
const
|
|
1425
|
-
|
|
1351
|
+
const lang = summary.language ? ` ${summary.language.toUpperCase()}` : '';
|
|
1352
|
+
// Show first line preview (truncated)
|
|
1353
|
+
const preview = summary.preview.length > 30
|
|
1354
|
+
? `${summary.preview.slice(0, 30)}...`
|
|
1355
|
+
: summary.preview;
|
|
1356
|
+
const placeholder = `[📋 #${id}${lang} ${summary.lineCount}L] "${preview}"`;
|
|
1426
1357
|
return { id, placeholder };
|
|
1427
1358
|
}
|
|
1428
1359
|
insertPastePlaceholder(content) {
|
|
@@ -1430,21 +1361,67 @@ export class TerminalInput extends EventEmitter {
|
|
|
1430
1361
|
if (available <= 0)
|
|
1431
1362
|
return;
|
|
1432
1363
|
const cleanContent = content.slice(0, available);
|
|
1433
|
-
const
|
|
1434
|
-
|
|
1364
|
+
const summary = generatePasteSummary(cleanContent);
|
|
1365
|
+
// For short pastes (< 5 lines), show full content instead of placeholder
|
|
1366
|
+
if (summary.lineCount < 5) {
|
|
1367
|
+
const placeholder = this.findPlaceholderAt(this.cursor);
|
|
1368
|
+
const insertPos = placeholder && this.cursor > placeholder.start ? placeholder.end : this.cursor;
|
|
1369
|
+
this.insertPlainText(cleanContent, insertPos);
|
|
1370
|
+
this.cursor = insertPos + cleanContent.length;
|
|
1371
|
+
return;
|
|
1372
|
+
}
|
|
1373
|
+
const { id, placeholder } = this.buildPlaceholder(summary);
|
|
1435
1374
|
const insertPos = this.cursor;
|
|
1436
1375
|
this.shiftPlaceholders(insertPos, placeholder.length);
|
|
1437
1376
|
this.pastePlaceholders.push({
|
|
1438
1377
|
id,
|
|
1439
1378
|
content: cleanContent,
|
|
1440
|
-
lineCount,
|
|
1379
|
+
lineCount: summary.lineCount,
|
|
1441
1380
|
placeholder,
|
|
1442
1381
|
start: insertPos,
|
|
1443
1382
|
end: insertPos + placeholder.length,
|
|
1383
|
+
summary,
|
|
1384
|
+
expanded: false,
|
|
1444
1385
|
});
|
|
1445
1386
|
this.buffer = this.buffer.slice(0, insertPos) + placeholder + this.buffer.slice(insertPos);
|
|
1446
1387
|
this.cursor = insertPos + placeholder.length;
|
|
1447
1388
|
}
|
|
1389
|
+
/**
|
|
1390
|
+
* Toggle expansion of a paste placeholder at the current cursor position.
|
|
1391
|
+
* When expanded, shows first 3 and last 2 lines of the content.
|
|
1392
|
+
*/
|
|
1393
|
+
togglePasteExpansion() {
|
|
1394
|
+
const placeholder = this.findPlaceholderAt(this.cursor);
|
|
1395
|
+
if (!placeholder)
|
|
1396
|
+
return false;
|
|
1397
|
+
placeholder.expanded = !placeholder.expanded;
|
|
1398
|
+
// Update the placeholder text in buffer
|
|
1399
|
+
const newPlaceholder = placeholder.expanded
|
|
1400
|
+
? this.buildExpandedPlaceholder(placeholder)
|
|
1401
|
+
: this.buildPlaceholder(placeholder.summary).placeholder;
|
|
1402
|
+
const lengthDiff = newPlaceholder.length - placeholder.placeholder.length;
|
|
1403
|
+
// Update buffer
|
|
1404
|
+
this.buffer =
|
|
1405
|
+
this.buffer.slice(0, placeholder.start) +
|
|
1406
|
+
newPlaceholder +
|
|
1407
|
+
this.buffer.slice(placeholder.end);
|
|
1408
|
+
// Update placeholder tracking
|
|
1409
|
+
placeholder.placeholder = newPlaceholder;
|
|
1410
|
+
placeholder.end = placeholder.start + newPlaceholder.length;
|
|
1411
|
+
// Shift other placeholders
|
|
1412
|
+
this.shiftPlaceholders(placeholder.end, lengthDiff, placeholder.id);
|
|
1413
|
+
this.scheduleRender();
|
|
1414
|
+
return true;
|
|
1415
|
+
}
|
|
1416
|
+
buildExpandedPlaceholder(ph) {
|
|
1417
|
+
const lines = ph.content.split('\n');
|
|
1418
|
+
const firstLines = lines.slice(0, 3).map(l => l.slice(0, 60)).join('\n');
|
|
1419
|
+
const lastLines = lines.length > 5
|
|
1420
|
+
? '\n...\n' + lines.slice(-2).map(l => l.slice(0, 60)).join('\n')
|
|
1421
|
+
: '';
|
|
1422
|
+
const lang = ph.summary.language ? ` ${ph.summary.language.toUpperCase()}` : '';
|
|
1423
|
+
return `[📋 #${ph.id}${lang} ${ph.lineCount}L ▼]\n${firstLines}${lastLines}\n[/📋 #${ph.id}]`;
|
|
1424
|
+
}
|
|
1448
1425
|
deletePlaceholder(placeholder) {
|
|
1449
1426
|
const length = placeholder.end - placeholder.start;
|
|
1450
1427
|
this.buffer = this.buffer.slice(0, placeholder.start) + this.buffer.slice(placeholder.end);
|
|
@@ -1452,11 +1429,7 @@ export class TerminalInput extends EventEmitter {
|
|
|
1452
1429
|
this.shiftPlaceholders(placeholder.end, -length, placeholder.id);
|
|
1453
1430
|
this.cursor = placeholder.start;
|
|
1454
1431
|
}
|
|
1455
|
-
updateContextUsage(value
|
|
1456
|
-
if (typeof autoCompactThreshold === 'number' && Number.isFinite(autoCompactThreshold)) {
|
|
1457
|
-
const boundedThreshold = Math.max(1, Math.min(100, Math.round(autoCompactThreshold)));
|
|
1458
|
-
this.contextAutoCompactThreshold = boundedThreshold;
|
|
1459
|
-
}
|
|
1432
|
+
updateContextUsage(value) {
|
|
1460
1433
|
if (value === null || !Number.isFinite(value)) {
|
|
1461
1434
|
this.contextUsage = null;
|
|
1462
1435
|
}
|
|
@@ -1483,22 +1456,6 @@ export class TerminalInput extends EventEmitter {
|
|
|
1483
1456
|
const next = this.editMode === 'display-edits' ? 'ask-permission' : 'display-edits';
|
|
1484
1457
|
this.setEditMode(next);
|
|
1485
1458
|
}
|
|
1486
|
-
scheduleStreamingRender(delayMs) {
|
|
1487
|
-
if (this.streamingRenderTimer)
|
|
1488
|
-
return;
|
|
1489
|
-
const wait = Math.max(16, delayMs);
|
|
1490
|
-
this.streamingRenderTimer = setTimeout(() => {
|
|
1491
|
-
this.streamingRenderTimer = null;
|
|
1492
|
-
this.render();
|
|
1493
|
-
}, wait);
|
|
1494
|
-
}
|
|
1495
|
-
resetStreamingRenderThrottle() {
|
|
1496
|
-
if (this.streamingRenderTimer) {
|
|
1497
|
-
clearTimeout(this.streamingRenderTimer);
|
|
1498
|
-
this.streamingRenderTimer = null;
|
|
1499
|
-
}
|
|
1500
|
-
this.lastStreamingRender = 0;
|
|
1501
|
-
}
|
|
1502
1459
|
scheduleRender() {
|
|
1503
1460
|
if (!this.canRender())
|
|
1504
1461
|
return;
|