erosolar-cli 1.7.271 → 1.7.272
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 +24 -148
- package/dist/bin/erosolar.js +1 -0
- package/dist/bin/erosolar.js.map +1 -1
- package/dist/capabilities/agentSpawningCapability.d.ts.map +1 -1
- package/dist/capabilities/agentSpawningCapability.js +56 -31
- package/dist/capabilities/agentSpawningCapability.js.map +1 -1
- package/dist/contracts/agent-schemas.json +0 -15
- package/dist/contracts/tools.schema.json +0 -9
- 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/customCommands.d.ts +1 -0
- package/dist/core/customCommands.d.ts.map +1 -1
- package/dist/core/customCommands.js +3 -0
- package/dist/core/customCommands.js.map +1 -1
- package/dist/core/hooks.d.ts +113 -0
- package/dist/core/hooks.d.ts.map +1 -0
- package/dist/core/hooks.js +267 -0
- package/dist/core/hooks.js.map +1 -0
- package/dist/core/metricsTracker.d.ts +122 -0
- package/dist/core/metricsTracker.d.ts.map +1 -0
- package/dist/{alpha-zero → core}/metricsTracker.js +2 -5
- package/dist/core/metricsTracker.js.map +1 -0
- package/dist/core/securityAssessment.d.ts +91 -0
- package/dist/core/securityAssessment.d.ts.map +1 -0
- package/dist/core/securityAssessment.js +580 -0
- package/dist/core/securityAssessment.js.map +1 -0
- package/dist/core/toolPreconditions.d.ts.map +1 -1
- package/dist/core/toolPreconditions.js +0 -14
- package/dist/core/toolPreconditions.js.map +1 -1
- package/dist/core/toolRuntime.d.ts +22 -1
- package/dist/core/toolRuntime.d.ts.map +1 -1
- package/dist/core/toolRuntime.js +0 -5
- package/dist/core/toolRuntime.js.map +1 -1
- package/dist/core/toolValidation.d.ts.map +1 -1
- package/dist/core/toolValidation.js +14 -3
- package/dist/core/toolValidation.js.map +1 -1
- package/dist/core/validationRunner.d.ts +1 -3
- package/dist/core/validationRunner.d.ts.map +1 -1
- package/dist/core/validationRunner.js.map +1 -1
- package/dist/core/verification.d.ts +137 -0
- package/dist/core/verification.d.ts.map +1 -0
- package/dist/core/verification.js +323 -0
- package/dist/core/verification.js.map +1 -0
- package/dist/headless/headlessApp.d.ts.map +1 -1
- package/dist/headless/headlessApp.js +21 -0
- package/dist/headless/headlessApp.js.map +1 -1
- package/dist/mcp/sseClient.d.ts.map +1 -1
- package/dist/mcp/sseClient.js +9 -18
- package/dist/mcp/sseClient.js.map +1 -1
- package/dist/plugins/tools/build/buildPlugin.d.ts +0 -6
- package/dist/plugins/tools/build/buildPlugin.d.ts.map +1 -1
- package/dist/plugins/tools/build/buildPlugin.js +4 -10
- 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 +0 -2
- package/dist/plugins/tools/nodeDefaults.js.map +1 -1
- 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/shell/interactiveShell.d.ts +11 -7
- package/dist/shell/interactiveShell.d.ts.map +1 -1
- package/dist/shell/interactiveShell.js +190 -157
- package/dist/shell/interactiveShell.js.map +1 -1
- package/dist/shell/shellApp.d.ts +2 -0
- package/dist/shell/shellApp.d.ts.map +1 -1
- package/dist/shell/shellApp.js +36 -1
- package/dist/shell/shellApp.js.map +1 -1
- package/dist/shell/systemPrompt.d.ts.map +1 -1
- package/dist/shell/systemPrompt.js +1 -4
- package/dist/shell/systemPrompt.js.map +1 -1
- package/dist/shell/terminalInput.d.ts +67 -168
- package/dist/shell/terminalInput.d.ts.map +1 -1
- package/dist/shell/terminalInput.js +455 -831
- package/dist/shell/terminalInput.js.map +1 -1
- package/dist/shell/terminalInputAdapter.d.ts +20 -25
- package/dist/shell/terminalInputAdapter.d.ts.map +1 -1
- package/dist/shell/terminalInputAdapter.js +14 -36
- package/dist/shell/terminalInputAdapter.js.map +1 -1
- package/dist/subagents/agentConfig.d.ts +27 -0
- package/dist/subagents/agentConfig.d.ts.map +1 -0
- package/dist/subagents/agentConfig.js +89 -0
- package/dist/subagents/agentConfig.js.map +1 -0
- package/dist/subagents/agentRegistry.d.ts +33 -0
- package/dist/subagents/agentRegistry.d.ts.map +1 -0
- package/dist/subagents/agentRegistry.js +162 -0
- package/dist/subagents/agentRegistry.js.map +1 -0
- package/dist/subagents/taskRunner.d.ts +7 -1
- package/dist/subagents/taskRunner.d.ts.map +1 -1
- package/dist/subagents/taskRunner.js +180 -47
- package/dist/subagents/taskRunner.js.map +1 -1
- package/dist/ui/ShellUIAdapter.d.ts.map +1 -1
- package/dist/ui/ShellUIAdapter.js +13 -12
- package/dist/ui/ShellUIAdapter.js.map +1 -1
- package/dist/ui/display.d.ts +23 -0
- package/dist/ui/display.d.ts.map +1 -1
- package/dist/ui/display.js +137 -33
- package/dist/ui/display.js.map +1 -1
- package/dist/ui/theme.d.ts.map +1 -1
- package/dist/ui/theme.js +6 -8
- package/dist/ui/theme.js.map +1 -1
- package/dist/ui/toolDisplay.d.ts +0 -158
- package/dist/ui/toolDisplay.d.ts.map +1 -1
- package/dist/ui/toolDisplay.js +0 -348
- package/dist/ui/toolDisplay.js.map +1 -1
- package/dist/ui/unified/layout.d.ts +1 -0
- package/dist/ui/unified/layout.d.ts.map +1 -1
- package/dist/ui/unified/layout.js +15 -25
- package/dist/ui/unified/layout.js.map +1 -1
- package/dist/utils/frontmatter.d.ts +10 -0
- package/dist/utils/frontmatter.d.ts.map +1 -0
- package/dist/utils/frontmatter.js +78 -0
- package/dist/utils/frontmatter.js.map +1 -0
- package/package.json +1 -1
- package/dist/alpha-zero/agentWrapper.d.ts +0 -84
- package/dist/alpha-zero/agentWrapper.d.ts.map +0 -1
- package/dist/alpha-zero/agentWrapper.js +0 -171
- package/dist/alpha-zero/agentWrapper.js.map +0 -1
- package/dist/alpha-zero/codeEvaluator.d.ts +0 -25
- package/dist/alpha-zero/codeEvaluator.d.ts.map +0 -1
- package/dist/alpha-zero/codeEvaluator.js +0 -273
- package/dist/alpha-zero/codeEvaluator.js.map +0 -1
- package/dist/alpha-zero/competitiveRunner.d.ts +0 -66
- package/dist/alpha-zero/competitiveRunner.d.ts.map +0 -1
- package/dist/alpha-zero/competitiveRunner.js +0 -224
- package/dist/alpha-zero/competitiveRunner.js.map +0 -1
- package/dist/alpha-zero/index.d.ts +0 -67
- package/dist/alpha-zero/index.d.ts.map +0 -1
- package/dist/alpha-zero/index.js +0 -99
- package/dist/alpha-zero/index.js.map +0 -1
- package/dist/alpha-zero/introspection.d.ts +0 -128
- package/dist/alpha-zero/introspection.d.ts.map +0 -1
- package/dist/alpha-zero/introspection.js +0 -300
- package/dist/alpha-zero/introspection.js.map +0 -1
- package/dist/alpha-zero/metricsTracker.d.ts +0 -71
- package/dist/alpha-zero/metricsTracker.d.ts.map +0 -1
- package/dist/alpha-zero/metricsTracker.js.map +0 -1
- package/dist/alpha-zero/security/core.d.ts +0 -125
- package/dist/alpha-zero/security/core.d.ts.map +0 -1
- package/dist/alpha-zero/security/core.js +0 -271
- package/dist/alpha-zero/security/core.js.map +0 -1
- package/dist/alpha-zero/security/google.d.ts +0 -125
- package/dist/alpha-zero/security/google.d.ts.map +0 -1
- package/dist/alpha-zero/security/google.js +0 -311
- package/dist/alpha-zero/security/google.js.map +0 -1
- package/dist/alpha-zero/security/googleLoader.d.ts +0 -17
- package/dist/alpha-zero/security/googleLoader.d.ts.map +0 -1
- package/dist/alpha-zero/security/googleLoader.js +0 -41
- package/dist/alpha-zero/security/googleLoader.js.map +0 -1
- package/dist/alpha-zero/security/index.d.ts +0 -29
- package/dist/alpha-zero/security/index.d.ts.map +0 -1
- package/dist/alpha-zero/security/index.js +0 -32
- package/dist/alpha-zero/security/index.js.map +0 -1
- package/dist/alpha-zero/security/simulation.d.ts +0 -124
- package/dist/alpha-zero/security/simulation.d.ts.map +0 -1
- package/dist/alpha-zero/security/simulation.js +0 -277
- package/dist/alpha-zero/security/simulation.js.map +0 -1
- package/dist/alpha-zero/selfModification.d.ts +0 -109
- package/dist/alpha-zero/selfModification.d.ts.map +0 -1
- package/dist/alpha-zero/selfModification.js +0 -233
- package/dist/alpha-zero/selfModification.js.map +0 -1
- package/dist/alpha-zero/types.d.ts +0 -170
- package/dist/alpha-zero/types.d.ts.map +0 -1
- package/dist/alpha-zero/types.js +0 -31
- package/dist/alpha-zero/types.js.map +0 -1
- package/dist/capabilities/securityTestingCapability.d.ts +0 -13
- package/dist/capabilities/securityTestingCapability.d.ts.map +0 -1
- package/dist/capabilities/securityTestingCapability.js +0 -25
- package/dist/capabilities/securityTestingCapability.js.map +0 -1
- package/dist/core/aiFlowOptimizer.d.ts +0 -26
- package/dist/core/aiFlowOptimizer.d.ts.map +0 -1
- package/dist/core/aiFlowOptimizer.js +0 -31
- package/dist/core/aiFlowOptimizer.js.map +0 -1
- package/dist/core/aiOptimizationEngine.d.ts +0 -158
- package/dist/core/aiOptimizationEngine.d.ts.map +0 -1
- package/dist/core/aiOptimizationEngine.js +0 -428
- package/dist/core/aiOptimizationEngine.js.map +0 -1
- package/dist/core/aiOptimizationIntegration.d.ts +0 -93
- package/dist/core/aiOptimizationIntegration.d.ts.map +0 -1
- package/dist/core/aiOptimizationIntegration.js +0 -250
- package/dist/core/aiOptimizationIntegration.js.map +0 -1
- package/dist/core/enhancedErrorRecovery.d.ts +0 -100
- package/dist/core/enhancedErrorRecovery.d.ts.map +0 -1
- package/dist/core/enhancedErrorRecovery.js +0 -345
- package/dist/core/enhancedErrorRecovery.js.map +0 -1
- package/dist/core/hooksSystem.d.ts +0 -65
- package/dist/core/hooksSystem.d.ts.map +0 -1
- package/dist/core/hooksSystem.js +0 -273
- package/dist/core/hooksSystem.js.map +0 -1
- package/dist/core/memorySystem.d.ts +0 -48
- package/dist/core/memorySystem.d.ts.map +0 -1
- package/dist/core/memorySystem.js +0 -271
- package/dist/core/memorySystem.js.map +0 -1
- package/dist/core/unified/errors.d.ts +0 -189
- package/dist/core/unified/errors.d.ts.map +0 -1
- package/dist/core/unified/errors.js +0 -497
- package/dist/core/unified/errors.js.map +0 -1
- package/dist/core/unified/index.d.ts +0 -19
- package/dist/core/unified/index.d.ts.map +0 -1
- package/dist/core/unified/index.js +0 -68
- package/dist/core/unified/index.js.map +0 -1
- package/dist/core/unified/schema.d.ts +0 -101
- package/dist/core/unified/schema.d.ts.map +0 -1
- package/dist/core/unified/schema.js +0 -350
- package/dist/core/unified/schema.js.map +0 -1
- package/dist/core/unified/toolRuntime.d.ts +0 -179
- package/dist/core/unified/toolRuntime.d.ts.map +0 -1
- package/dist/core/unified/toolRuntime.js +0 -517
- package/dist/core/unified/toolRuntime.js.map +0 -1
- package/dist/core/unified/tools.d.ts +0 -127
- package/dist/core/unified/tools.d.ts.map +0 -1
- package/dist/core/unified/tools.js +0 -1333
- package/dist/core/unified/tools.js.map +0 -1
- package/dist/core/unified/types.d.ts +0 -352
- package/dist/core/unified/types.d.ts.map +0 -1
- package/dist/core/unified/types.js +0 -12
- package/dist/core/unified/types.js.map +0 -1
- package/dist/core/unified/version.d.ts +0 -209
- package/dist/core/unified/version.d.ts.map +0 -1
- package/dist/core/unified/version.js +0 -454
- package/dist/core/unified/version.js.map +0 -1
- package/dist/plugins/tools/security/securityPlugin.d.ts +0 -3
- package/dist/plugins/tools/security/securityPlugin.d.ts.map +0 -1
- package/dist/plugins/tools/security/securityPlugin.js +0 -12
- package/dist/plugins/tools/security/securityPlugin.js.map +0 -1
- package/dist/security/active-stack-security.d.ts +0 -112
- package/dist/security/active-stack-security.d.ts.map +0 -1
- package/dist/security/active-stack-security.js +0 -296
- package/dist/security/active-stack-security.js.map +0 -1
- package/dist/security/advanced-persistence-research.d.ts +0 -92
- package/dist/security/advanced-persistence-research.d.ts.map +0 -1
- package/dist/security/advanced-persistence-research.js +0 -195
- package/dist/security/advanced-persistence-research.js.map +0 -1
- package/dist/security/advanced-targeting.d.ts +0 -119
- package/dist/security/advanced-targeting.d.ts.map +0 -1
- package/dist/security/advanced-targeting.js +0 -233
- package/dist/security/advanced-targeting.js.map +0 -1
- package/dist/security/assessment/vulnerabilityAssessment.d.ts +0 -104
- package/dist/security/assessment/vulnerabilityAssessment.d.ts.map +0 -1
- package/dist/security/assessment/vulnerabilityAssessment.js +0 -315
- package/dist/security/assessment/vulnerabilityAssessment.js.map +0 -1
- package/dist/security/authorization/securityAuthorization.d.ts +0 -88
- package/dist/security/authorization/securityAuthorization.d.ts.map +0 -1
- package/dist/security/authorization/securityAuthorization.js +0 -172
- package/dist/security/authorization/securityAuthorization.js.map +0 -1
- package/dist/security/comprehensive-targeting.d.ts +0 -85
- package/dist/security/comprehensive-targeting.d.ts.map +0 -1
- package/dist/security/comprehensive-targeting.js +0 -438
- package/dist/security/comprehensive-targeting.js.map +0 -1
- package/dist/security/global-security-integration.d.ts +0 -91
- package/dist/security/global-security-integration.d.ts.map +0 -1
- package/dist/security/global-security-integration.js +0 -218
- package/dist/security/global-security-integration.js.map +0 -1
- package/dist/security/index.d.ts +0 -38
- package/dist/security/index.d.ts.map +0 -1
- package/dist/security/index.js +0 -47
- package/dist/security/index.js.map +0 -1
- package/dist/security/persistence-analyzer.d.ts +0 -56
- package/dist/security/persistence-analyzer.d.ts.map +0 -1
- package/dist/security/persistence-analyzer.js +0 -187
- package/dist/security/persistence-analyzer.js.map +0 -1
- package/dist/security/persistence-cli.d.ts +0 -36
- package/dist/security/persistence-cli.d.ts.map +0 -1
- package/dist/security/persistence-cli.js +0 -160
- package/dist/security/persistence-cli.js.map +0 -1
- package/dist/security/persistence-research.d.ts +0 -92
- package/dist/security/persistence-research.d.ts.map +0 -1
- package/dist/security/persistence-research.js +0 -364
- package/dist/security/persistence-research.js.map +0 -1
- package/dist/security/research/persistenceResearch.d.ts +0 -97
- package/dist/security/research/persistenceResearch.d.ts.map +0 -1
- package/dist/security/research/persistenceResearch.js +0 -282
- package/dist/security/research/persistenceResearch.js.map +0 -1
- package/dist/security/security-integration.d.ts +0 -74
- package/dist/security/security-integration.d.ts.map +0 -1
- package/dist/security/security-integration.js +0 -137
- package/dist/security/security-integration.js.map +0 -1
- package/dist/security/security-testing-framework.d.ts +0 -112
- package/dist/security/security-testing-framework.d.ts.map +0 -1
- package/dist/security/security-testing-framework.js +0 -364
- package/dist/security/security-testing-framework.js.map +0 -1
- package/dist/security/simulation/attackSimulation.d.ts +0 -93
- package/dist/security/simulation/attackSimulation.d.ts.map +0 -1
- package/dist/security/simulation/attackSimulation.js +0 -341
- package/dist/security/simulation/attackSimulation.js.map +0 -1
- package/dist/security/strategic-operations.d.ts +0 -100
- package/dist/security/strategic-operations.d.ts.map +0 -1
- package/dist/security/strategic-operations.js +0 -276
- package/dist/security/strategic-operations.js.map +0 -1
- package/dist/security/tool-security-wrapper.d.ts +0 -58
- package/dist/security/tool-security-wrapper.d.ts.map +0 -1
- package/dist/security/tool-security-wrapper.js +0 -156
- package/dist/security/tool-security-wrapper.js.map +0 -1
- package/dist/shell/claudeCodeStreamHandler.d.ts +0 -145
- package/dist/shell/claudeCodeStreamHandler.d.ts.map +0 -1
- package/dist/shell/claudeCodeStreamHandler.js +0 -322
- package/dist/shell/claudeCodeStreamHandler.js.map +0 -1
- package/dist/shell/inputQueueManager.d.ts +0 -144
- package/dist/shell/inputQueueManager.d.ts.map +0 -1
- package/dist/shell/inputQueueManager.js +0 -290
- package/dist/shell/inputQueueManager.js.map +0 -1
- package/dist/shell/metricsTracker.d.ts +0 -60
- package/dist/shell/metricsTracker.d.ts.map +0 -1
- package/dist/shell/metricsTracker.js +0 -119
- package/dist/shell/metricsTracker.js.map +0 -1
- package/dist/shell/streamingOutputManager.d.ts +0 -115
- package/dist/shell/streamingOutputManager.d.ts.map +0 -1
- package/dist/shell/streamingOutputManager.js +0 -225
- package/dist/shell/streamingOutputManager.js.map +0 -1
- package/dist/tools/securityTools.d.ts +0 -22
- package/dist/tools/securityTools.d.ts.map +0 -1
- package/dist/tools/securityTools.js +0 -448
- package/dist/tools/securityTools.js.map +0 -1
- package/dist/ui/persistentPrompt.d.ts +0 -50
- package/dist/ui/persistentPrompt.d.ts.map +0 -1
- package/dist/ui/persistentPrompt.js +0 -92
- package/dist/ui/persistentPrompt.js.map +0 -1
- package/dist/ui/terminalUISchema.d.ts +0 -195
- package/dist/ui/terminalUISchema.d.ts.map +0 -1
- package/dist/ui/terminalUISchema.js +0 -113
- package/dist/ui/terminalUISchema.js.map +0 -1
- package/scripts/deploy-security-capabilities.js +0 -178
|
@@ -3,16 +3,18 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Design principles:
|
|
5
5
|
* - Single source of truth for input state
|
|
6
|
+
* - One bottom-pinned chat box for the entire session (no inline anchors)
|
|
6
7
|
* - Native bracketed paste support (no heuristics)
|
|
7
8
|
* - Clean cursor model with render-time wrapping
|
|
8
9
|
* - State machine for different input modes
|
|
9
10
|
* - No readline dependency for display
|
|
10
11
|
*/
|
|
11
12
|
import { EventEmitter } from 'node:events';
|
|
12
|
-
import { isMultilinePaste
|
|
13
|
+
import { isMultilinePaste } from '../core/multilinePasteHandler.js';
|
|
13
14
|
import { writeLock } from '../ui/writeLock.js';
|
|
14
|
-
import { renderDivider } from '../ui/unified/layout.js';
|
|
15
|
-
import {
|
|
15
|
+
import { renderDivider, renderStatusLine } from '../ui/unified/layout.js';
|
|
16
|
+
import { isStreamingMode } from '../ui/globalWriteLock.js';
|
|
17
|
+
import { formatThinking } from '../ui/toolDisplay.js';
|
|
16
18
|
// ANSI escape codes
|
|
17
19
|
const ESC = {
|
|
18
20
|
// Cursor control
|
|
@@ -67,6 +69,11 @@ export class TerminalInput extends EventEmitter {
|
|
|
67
69
|
statusMessage = null;
|
|
68
70
|
overrideStatusMessage = null; // Secondary status (warnings, etc.)
|
|
69
71
|
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
|
|
70
77
|
reservedLines = 2;
|
|
71
78
|
scrollRegionActive = false;
|
|
72
79
|
lastRenderContent = '';
|
|
@@ -74,47 +81,35 @@ export class TerminalInput extends EventEmitter {
|
|
|
74
81
|
renderDirty = false;
|
|
75
82
|
isRendering = false;
|
|
76
83
|
pinnedTopRows = 0;
|
|
77
|
-
inlineAnchorRow = null;
|
|
78
|
-
inlineLayout = false;
|
|
79
|
-
anchorProvider = null;
|
|
80
|
-
// Flow mode: when true, renders inline after content (no absolute positioning)
|
|
81
|
-
flowMode = true;
|
|
82
|
-
flowModeRenderedLines = 0; // Track lines rendered for clearing
|
|
83
|
-
contentEndRow = 0; // Row where content ends (for idle mode positioning)
|
|
84
|
-
// Command suggestions (Claude Code style auto-complete)
|
|
85
|
-
commandSuggestions = [];
|
|
86
|
-
filteredSuggestions = [];
|
|
87
|
-
selectedSuggestionIndex = 0;
|
|
88
|
-
showSuggestions = false;
|
|
89
|
-
maxVisibleSuggestions = 10;
|
|
90
84
|
// Lifecycle
|
|
91
85
|
disposed = false;
|
|
92
86
|
enabled = true;
|
|
93
87
|
contextUsage = null;
|
|
88
|
+
contextAutoCompactThreshold = 90;
|
|
89
|
+
thinkingModeLabel = null;
|
|
94
90
|
editMode = 'display-edits';
|
|
95
91
|
verificationEnabled = true;
|
|
96
92
|
autoContinueEnabled = false;
|
|
97
93
|
verificationHotkey = 'alt+v';
|
|
98
94
|
autoContinueHotkey = 'alt+c';
|
|
95
|
+
thinkingHotkey = '/thinking';
|
|
96
|
+
modelLabel = null;
|
|
97
|
+
providerLabel = null;
|
|
99
98
|
// Output interceptor cleanup
|
|
100
99
|
outputInterceptorCleanup;
|
|
101
|
-
//
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
thinkingEnabled = true;
|
|
105
|
-
modelInfo = null; // Provider · Model info
|
|
106
|
-
// Streaming input area render timer (updates elapsed time display)
|
|
100
|
+
// Streaming render throttle
|
|
101
|
+
lastStreamingRender = 0;
|
|
102
|
+
streamingRenderInterval = 250; // ms between renders during streaming
|
|
107
103
|
streamingRenderTimer = null;
|
|
108
104
|
constructor(writeStream = process.stdout, config = {}) {
|
|
109
105
|
super();
|
|
110
106
|
this.out = writeStream;
|
|
111
|
-
// Use schema defaults for configuration consistency
|
|
112
107
|
this.config = {
|
|
113
|
-
maxLines: config.maxLines ??
|
|
114
|
-
maxLength: config.maxLength ??
|
|
108
|
+
maxLines: config.maxLines ?? 1000,
|
|
109
|
+
maxLength: config.maxLength ?? 10000,
|
|
115
110
|
maxQueueSize: config.maxQueueSize ?? 100,
|
|
116
|
-
promptChar: config.promptChar ??
|
|
117
|
-
continuationChar: config.continuationChar ??
|
|
111
|
+
promptChar: config.promptChar ?? '> ',
|
|
112
|
+
continuationChar: config.continuationChar ?? '│ ',
|
|
118
113
|
};
|
|
119
114
|
}
|
|
120
115
|
// ===========================================================================
|
|
@@ -193,11 +188,6 @@ export class TerminalInput extends EventEmitter {
|
|
|
193
188
|
if (handled)
|
|
194
189
|
return;
|
|
195
190
|
}
|
|
196
|
-
// Handle '?' for help hint (if buffer is empty)
|
|
197
|
-
if (str === '?' && this.buffer.length === 0) {
|
|
198
|
-
this.emit('showHelp');
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
191
|
// Insert printable characters
|
|
202
192
|
if (str && !key?.ctrl && !key?.meta) {
|
|
203
193
|
this.insertText(str);
|
|
@@ -206,492 +196,38 @@ export class TerminalInput extends EventEmitter {
|
|
|
206
196
|
/**
|
|
207
197
|
* Set the input mode
|
|
208
198
|
*
|
|
209
|
-
* Streaming
|
|
210
|
-
*
|
|
211
|
-
* the cursor is (below the streamed content).
|
|
199
|
+
* Streaming keeps the scroll region active so the prompt/status stay pinned
|
|
200
|
+
* below the streaming output. When streaming ends, we refresh the input area.
|
|
212
201
|
*/
|
|
213
202
|
setMode(mode) {
|
|
214
203
|
const prevMode = this.mode;
|
|
215
204
|
this.mode = mode;
|
|
216
205
|
if (mode === 'streaming' && prevMode !== 'streaming') {
|
|
217
|
-
//
|
|
218
|
-
this.
|
|
219
|
-
// Set up scroll region to reserve bottom for persistent input area
|
|
220
|
-
this.pinnedTopRows = 0;
|
|
221
|
-
this.reservedLines = 6; // status + model + divider + input + divider + controls
|
|
222
|
-
// Enable scroll region: content scrolls above, bottom is reserved
|
|
206
|
+
// Keep scroll region active so status/prompt stay pinned while streaming
|
|
207
|
+
this.resetStreamingRenderThrottle();
|
|
223
208
|
this.enableScrollRegion();
|
|
224
|
-
// Initial render of bottom input area
|
|
225
|
-
this.renderBottomInputArea();
|
|
226
|
-
// Start timer to update bottom input area (updates elapsed time)
|
|
227
|
-
this.streamingRenderTimer = setInterval(() => {
|
|
228
|
-
if (this.mode === 'streaming') {
|
|
229
|
-
this.updateStreamingStatus();
|
|
230
|
-
this.renderBottomInputArea();
|
|
231
|
-
}
|
|
232
|
-
}, 1000);
|
|
233
209
|
this.renderDirty = true;
|
|
210
|
+
this.render();
|
|
234
211
|
}
|
|
235
212
|
else if (mode !== 'streaming' && prevMode === 'streaming') {
|
|
236
|
-
//
|
|
237
|
-
|
|
238
|
-
clearInterval(this.streamingRenderTimer);
|
|
239
|
-
this.streamingRenderTimer = null;
|
|
240
|
-
}
|
|
241
|
-
// Reset streaming time
|
|
242
|
-
this.streamingStartTime = null;
|
|
243
|
-
// Keep scroll region active for consistent bottom-pinned UI
|
|
244
|
-
// (scroll region reserves bottom for input area in all modes)
|
|
245
|
-
// Reset flow mode tracking
|
|
246
|
-
this.flowModeRenderedLines = 0;
|
|
247
|
-
// Render using unified bottom input area (same layout as streaming)
|
|
248
|
-
writeLock.withLock(() => {
|
|
249
|
-
this.renderBottomInputArea();
|
|
250
|
-
}, 'terminalInput.streamingEnd');
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Update streaming status label (called by timer)
|
|
255
|
-
*/
|
|
256
|
-
updateStreamingStatus() {
|
|
257
|
-
if (this.mode !== 'streaming' || !this.streamingStartTime)
|
|
258
|
-
return;
|
|
259
|
-
// Calculate elapsed time
|
|
260
|
-
const elapsed = Date.now() - this.streamingStartTime;
|
|
261
|
-
const seconds = Math.floor(elapsed / 1000);
|
|
262
|
-
const minutes = Math.floor(seconds / 60);
|
|
263
|
-
const secs = seconds % 60;
|
|
264
|
-
// Format elapsed time
|
|
265
|
-
let elapsedStr;
|
|
266
|
-
if (minutes > 0) {
|
|
267
|
-
elapsedStr = `${minutes}m ${secs}s`;
|
|
268
|
-
}
|
|
269
|
-
else {
|
|
270
|
-
elapsedStr = `${secs}s`;
|
|
271
|
-
}
|
|
272
|
-
// Update streaming label
|
|
273
|
-
this.streamingLabel = `Streaming ${elapsedStr}`;
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* Render input area - unified for streaming and normal modes.
|
|
277
|
-
*
|
|
278
|
-
* In streaming mode: renders at absolute bottom, uses cursor save/restore
|
|
279
|
-
* In normal mode: renders right after the banner (pinnedTopRows + 1)
|
|
280
|
-
*/
|
|
281
|
-
renderPinnedInputArea() {
|
|
282
|
-
const { rows, cols } = this.getSize();
|
|
283
|
-
const maxWidth = Math.max(8, cols - 4);
|
|
284
|
-
const divider = renderDivider(cols - 2);
|
|
285
|
-
const isStreaming = this.mode === 'streaming';
|
|
286
|
-
// Wrap buffer into display lines (multi-line support)
|
|
287
|
-
const { lines, cursorLine, cursorCol } = this.wrapBuffer(maxWidth);
|
|
288
|
-
const availableForContent = Math.max(1, rows - 5); // Reserve 5 lines for UI
|
|
289
|
-
const maxVisible = Math.max(1, Math.min(this.config.maxLines, availableForContent));
|
|
290
|
-
const displayLines = Math.min(lines.length, maxVisible);
|
|
291
|
-
// Calculate display window (keep cursor visible)
|
|
292
|
-
let startLine = 0;
|
|
293
|
-
if (lines.length > displayLines) {
|
|
294
|
-
startLine = Math.max(0, cursorLine - displayLines + 1);
|
|
295
|
-
startLine = Math.min(startLine, lines.length - displayLines);
|
|
296
|
-
}
|
|
297
|
-
const visibleLines = lines.slice(startLine, startLine + displayLines);
|
|
298
|
-
const adjustedCursorLine = cursorLine - startLine;
|
|
299
|
-
// Calculate total height: status + (model info if set) + topDiv + input lines + bottomDiv + controls
|
|
300
|
-
const hasModelInfo = !!this.modelInfo;
|
|
301
|
-
const totalHeight = 4 + visibleLines.length + (hasModelInfo ? 1 : 0);
|
|
302
|
-
// Save cursor position during streaming (so content flow resumes correctly)
|
|
303
|
-
if (isStreaming) {
|
|
304
|
-
this.write(ESC.SAVE);
|
|
305
|
-
}
|
|
306
|
-
this.write(ESC.HIDE);
|
|
307
|
-
this.write(ESC.RESET);
|
|
308
|
-
// Calculate start row based on mode:
|
|
309
|
-
// - Streaming: absolute bottom (rows - totalHeight + 1)
|
|
310
|
-
// - Normal: right after content (contentEndRow + 1)
|
|
311
|
-
let currentRow;
|
|
312
|
-
if (isStreaming) {
|
|
313
|
-
currentRow = Math.max(1, rows - totalHeight + 1);
|
|
314
|
-
}
|
|
315
|
-
else {
|
|
316
|
-
// In normal mode, render right after content
|
|
317
|
-
// Use contentEndRow if set, otherwise use pinnedTopRows
|
|
318
|
-
const contentRow = this.contentEndRow > 0 ? this.contentEndRow : this.pinnedTopRows;
|
|
319
|
-
currentRow = Math.max(1, contentRow + 1);
|
|
320
|
-
}
|
|
321
|
-
let finalRow = currentRow;
|
|
322
|
-
let finalCol = 3;
|
|
323
|
-
// Clear from current position to end of screen to remove any "ghost" content
|
|
324
|
-
this.write(ESC.TO(currentRow, 1));
|
|
325
|
-
this.write(ESC.CLEAR_TO_END);
|
|
326
|
-
// Status bar
|
|
327
|
-
this.write(ESC.TO(currentRow, 1));
|
|
328
|
-
this.write(isStreaming ? this.buildStreamingStatusBar(cols) : this.buildStatusBar(cols));
|
|
329
|
-
currentRow++;
|
|
330
|
-
// Model info line (if set) - displayed below status, above input
|
|
331
|
-
if (hasModelInfo) {
|
|
332
|
-
const { dim: DIM, reset: R } = UI_COLORS;
|
|
333
|
-
this.write(ESC.TO(currentRow, 1));
|
|
334
|
-
// Build model info with context usage
|
|
335
|
-
let modelLine = `${DIM}${this.modelInfo}${R}`;
|
|
336
|
-
if (this.contextUsage !== null) {
|
|
337
|
-
const rem = Math.max(0, 100 - this.contextUsage);
|
|
338
|
-
if (rem < 10)
|
|
339
|
-
modelLine += ` ${UI_COLORS.red}⚠ ctx: ${rem}%${R}`;
|
|
340
|
-
else if (rem < 25)
|
|
341
|
-
modelLine += ` ${UI_COLORS.yellow}! ctx: ${rem}%${R}`;
|
|
342
|
-
else
|
|
343
|
-
modelLine += ` ${DIM}· ctx: ${rem}%${R}`;
|
|
344
|
-
}
|
|
345
|
-
this.write(modelLine);
|
|
346
|
-
currentRow++;
|
|
347
|
-
}
|
|
348
|
-
// Top divider
|
|
349
|
-
this.write(ESC.TO(currentRow, 1));
|
|
350
|
-
this.write(divider);
|
|
351
|
-
currentRow++;
|
|
352
|
-
// Input lines with background styling
|
|
353
|
-
for (let i = 0; i < visibleLines.length; i++) {
|
|
354
|
-
this.write(ESC.TO(currentRow, 1));
|
|
355
|
-
const line = visibleLines[i] ?? '';
|
|
356
|
-
const absoluteLineIdx = startLine + i;
|
|
357
|
-
const isFirstLine = absoluteLineIdx === 0;
|
|
358
|
-
const isCursorLine = i === adjustedCursorLine;
|
|
359
|
-
// Background
|
|
360
|
-
this.write(ESC.BG_DARK);
|
|
361
|
-
// Prompt prefix
|
|
362
|
-
this.write(ESC.DIM);
|
|
363
|
-
this.write(isFirstLine ? this.config.promptChar : this.config.continuationChar);
|
|
364
|
-
this.write(ESC.RESET);
|
|
365
|
-
this.write(ESC.BG_DARK);
|
|
366
|
-
if (isCursorLine) {
|
|
367
|
-
const col = Math.min(cursorCol, line.length);
|
|
368
|
-
const before = line.slice(0, col);
|
|
369
|
-
const at = col < line.length ? line[col] : ' ';
|
|
370
|
-
const after = col < line.length ? line.slice(col + 1) : '';
|
|
371
|
-
this.write(before);
|
|
372
|
-
this.write(ESC.REVERSE + ESC.BOLD);
|
|
373
|
-
this.write(at);
|
|
374
|
-
this.write(ESC.RESET + ESC.BG_DARK);
|
|
375
|
-
this.write(after);
|
|
376
|
-
finalRow = currentRow;
|
|
377
|
-
finalCol = this.config.promptChar.length + col + 1;
|
|
378
|
-
}
|
|
379
|
-
else {
|
|
380
|
-
this.write(line);
|
|
381
|
-
}
|
|
382
|
-
// Pad to edge
|
|
383
|
-
const lineLen = this.config.promptChar.length + line.length + (isCursorLine && cursorCol >= line.length ? 1 : 0);
|
|
384
|
-
const padding = Math.max(0, cols - lineLen - 1);
|
|
385
|
-
if (padding > 0)
|
|
386
|
-
this.write(' '.repeat(padding));
|
|
387
|
-
this.write(ESC.RESET);
|
|
388
|
-
currentRow++;
|
|
389
|
-
}
|
|
390
|
-
// Bottom divider
|
|
391
|
-
this.write(ESC.TO(currentRow, 1));
|
|
392
|
-
this.write(divider);
|
|
393
|
-
currentRow++;
|
|
394
|
-
// Mode controls line
|
|
395
|
-
this.write(ESC.TO(currentRow, 1));
|
|
396
|
-
this.write(this.buildModeControls(cols));
|
|
397
|
-
// Restore cursor position during streaming, or show cursor in normal mode
|
|
398
|
-
if (isStreaming) {
|
|
399
|
-
this.write(ESC.RESTORE);
|
|
400
|
-
}
|
|
401
|
-
else {
|
|
402
|
-
// Position cursor in input area
|
|
403
|
-
this.write(ESC.TO(finalRow, Math.min(finalCol, cols)));
|
|
404
|
-
this.write(ESC.SHOW);
|
|
405
|
-
}
|
|
406
|
-
// Update reserved lines for scroll region calculations
|
|
407
|
-
this.updateReservedLines(totalHeight);
|
|
408
|
-
}
|
|
409
|
-
/**
|
|
410
|
-
* Render input area during streaming (alias for unified method)
|
|
411
|
-
*/
|
|
412
|
-
renderStreamingInputArea() {
|
|
413
|
-
this.renderPinnedInputArea();
|
|
414
|
-
}
|
|
415
|
-
/**
|
|
416
|
-
* Render bottom input area - UNIFIED for all modes.
|
|
417
|
-
* Uses cursor save/restore to update bottom without affecting content flow.
|
|
418
|
-
*
|
|
419
|
-
* Layout (same for idle/streaming/ready):
|
|
420
|
-
* - Status bar (streaming timer or "Type a message")
|
|
421
|
-
* - Model info line (provider · model · ctx)
|
|
422
|
-
* - Divider
|
|
423
|
-
* - Input area
|
|
424
|
-
* - Divider
|
|
425
|
-
* - Mode controls
|
|
426
|
-
*/
|
|
427
|
-
renderBottomInputArea() {
|
|
428
|
-
const { rows, cols } = this.getSize();
|
|
429
|
-
const maxWidth = Math.max(8, cols - 4);
|
|
430
|
-
const divider = renderDivider(cols - 2);
|
|
431
|
-
const { dim: DIM, reset: R } = UI_COLORS;
|
|
432
|
-
const isStreaming = this.mode === 'streaming';
|
|
433
|
-
// Wrap buffer into display lines
|
|
434
|
-
const { lines, cursorLine, cursorCol } = this.wrapBuffer(maxWidth);
|
|
435
|
-
// Allow multi-line in non-streaming, single line during streaming
|
|
436
|
-
const maxDisplayLines = isStreaming ? 1 : 3;
|
|
437
|
-
const displayLines = Math.min(lines.length, maxDisplayLines);
|
|
438
|
-
const visibleLines = lines.slice(0, displayLines);
|
|
439
|
-
// Calculate total height for bottom area
|
|
440
|
-
const hasModelInfo = !!this.modelInfo;
|
|
441
|
-
const totalHeight = 4 + displayLines + (hasModelInfo ? 1 : 0);
|
|
442
|
-
// Ensure scroll region is always enabled (unified behavior)
|
|
443
|
-
if (!this.scrollRegionActive || this.reservedLines !== totalHeight) {
|
|
444
|
-
this.reservedLines = totalHeight;
|
|
213
|
+
// Streaming ended - render the input area
|
|
214
|
+
this.resetStreamingRenderThrottle();
|
|
445
215
|
this.enableScrollRegion();
|
|
216
|
+
this.forceRender();
|
|
446
217
|
}
|
|
447
|
-
const startRow = Math.max(1, rows - totalHeight + 1);
|
|
448
|
-
// Save cursor, hide it
|
|
449
|
-
this.write(ESC.SAVE);
|
|
450
|
-
this.write(ESC.HIDE);
|
|
451
|
-
let currentRow = startRow;
|
|
452
|
-
// Clear the bottom reserved area
|
|
453
|
-
for (let r = startRow; r <= rows; r++) {
|
|
454
|
-
this.write(ESC.TO(r, 1));
|
|
455
|
-
this.write(ESC.CLEAR_LINE);
|
|
456
|
-
}
|
|
457
|
-
// Status bar - UNIFIED: same format for all modes
|
|
458
|
-
this.write(ESC.TO(currentRow, 1));
|
|
459
|
-
this.write(isStreaming ? this.buildStreamingStatusBar(cols) : this.buildStatusBar(cols));
|
|
460
|
-
currentRow++;
|
|
461
|
-
// Model info line (if set)
|
|
462
|
-
if (hasModelInfo) {
|
|
463
|
-
this.write(ESC.TO(currentRow, 1));
|
|
464
|
-
let modelLine = `${DIM}${this.modelInfo}${R}`;
|
|
465
|
-
if (this.contextUsage !== null) {
|
|
466
|
-
const rem = Math.max(0, 100 - this.contextUsage);
|
|
467
|
-
if (rem < 10)
|
|
468
|
-
modelLine += ` ${UI_COLORS.red}⚠ ctx: ${rem}%${R}`;
|
|
469
|
-
else if (rem < 25)
|
|
470
|
-
modelLine += ` ${UI_COLORS.yellow}! ctx: ${rem}%${R}`;
|
|
471
|
-
else
|
|
472
|
-
modelLine += ` ${DIM}· ctx: ${rem}%${R}`;
|
|
473
|
-
}
|
|
474
|
-
this.write(modelLine);
|
|
475
|
-
currentRow++;
|
|
476
|
-
}
|
|
477
|
-
// Top divider
|
|
478
|
-
this.write(ESC.TO(currentRow, 1));
|
|
479
|
-
this.write(divider);
|
|
480
|
-
currentRow++;
|
|
481
|
-
// Input lines with background styling
|
|
482
|
-
for (let i = 0; i < visibleLines.length; i++) {
|
|
483
|
-
this.write(ESC.TO(currentRow, 1));
|
|
484
|
-
const line = visibleLines[i] ?? '';
|
|
485
|
-
const isFirstLine = i === 0;
|
|
486
|
-
this.write(ESC.BG_DARK);
|
|
487
|
-
this.write(ESC.DIM);
|
|
488
|
-
this.write(isFirstLine ? this.config.promptChar : this.config.continuationChar);
|
|
489
|
-
this.write(ESC.RESET);
|
|
490
|
-
this.write(ESC.BG_DARK);
|
|
491
|
-
this.write(line);
|
|
492
|
-
// Pad to edge
|
|
493
|
-
const lineLen = this.config.promptChar.length + line.length;
|
|
494
|
-
const padding = Math.max(0, cols - lineLen - 1);
|
|
495
|
-
if (padding > 0)
|
|
496
|
-
this.write(' '.repeat(padding));
|
|
497
|
-
this.write(ESC.RESET);
|
|
498
|
-
currentRow++;
|
|
499
|
-
}
|
|
500
|
-
// Bottom divider
|
|
501
|
-
this.write(ESC.TO(currentRow, 1));
|
|
502
|
-
this.write(divider);
|
|
503
|
-
currentRow++;
|
|
504
|
-
// Mode controls
|
|
505
|
-
this.write(ESC.TO(currentRow, 1));
|
|
506
|
-
this.write(this.buildModeControls(cols));
|
|
507
|
-
// Cursor positioning depends on mode:
|
|
508
|
-
// - Streaming: restore to content area (where streaming output continues)
|
|
509
|
-
// - Normal: position in input area for typing
|
|
510
|
-
if (isStreaming) {
|
|
511
|
-
this.write(ESC.RESTORE);
|
|
512
|
-
}
|
|
513
|
-
else {
|
|
514
|
-
// Position cursor in input area
|
|
515
|
-
// Input line is at: startRow + (hasModelInfo ? 2 : 1) + cursorLine
|
|
516
|
-
const inputStartRow = startRow + (hasModelInfo ? 2 : 1) + 1; // +1 for status bar, +1 for divider
|
|
517
|
-
const targetRow = inputStartRow + Math.min(cursorLine, displayLines - 1);
|
|
518
|
-
const targetCol = this.config.promptChar.length + cursorCol + 1;
|
|
519
|
-
this.write(ESC.TO(targetRow, Math.min(targetCol, cols)));
|
|
520
|
-
}
|
|
521
|
-
this.write(ESC.SHOW);
|
|
522
|
-
// Track last render state
|
|
523
|
-
this.lastRenderContent = this.buffer;
|
|
524
|
-
this.lastRenderCursor = this.cursor;
|
|
525
|
-
}
|
|
526
|
-
/**
|
|
527
|
-
* Enable or disable flow mode.
|
|
528
|
-
* In flow mode, the input renders immediately after content (wherever cursor is).
|
|
529
|
-
* When disabled, input renders at the absolute bottom of terminal.
|
|
530
|
-
*/
|
|
531
|
-
setFlowMode(enabled) {
|
|
532
|
-
if (this.flowMode === enabled)
|
|
533
|
-
return;
|
|
534
|
-
this.flowMode = enabled;
|
|
535
|
-
this.renderDirty = true;
|
|
536
|
-
this.scheduleRender();
|
|
537
|
-
}
|
|
538
|
-
/**
|
|
539
|
-
* Check if flow mode is enabled.
|
|
540
|
-
*/
|
|
541
|
-
isFlowMode() {
|
|
542
|
-
return this.flowMode;
|
|
543
|
-
}
|
|
544
|
-
/**
|
|
545
|
-
* Set the row where content ends (for idle mode positioning).
|
|
546
|
-
* Input area will render starting from this row + 1.
|
|
547
|
-
*/
|
|
548
|
-
setContentEndRow(row) {
|
|
549
|
-
this.contentEndRow = Math.max(0, row);
|
|
550
|
-
this.renderDirty = true;
|
|
551
|
-
this.scheduleRender();
|
|
552
|
-
}
|
|
553
|
-
/**
|
|
554
|
-
* Set available slash commands for auto-complete suggestions.
|
|
555
|
-
*/
|
|
556
|
-
setCommands(commands) {
|
|
557
|
-
this.commandSuggestions = commands;
|
|
558
|
-
this.updateSuggestions();
|
|
559
|
-
}
|
|
560
|
-
/**
|
|
561
|
-
* Update filtered suggestions based on current input.
|
|
562
|
-
*/
|
|
563
|
-
updateSuggestions() {
|
|
564
|
-
const input = this.buffer.trim();
|
|
565
|
-
// Only show suggestions when input starts with "/"
|
|
566
|
-
if (!input.startsWith('/')) {
|
|
567
|
-
this.showSuggestions = false;
|
|
568
|
-
this.filteredSuggestions = [];
|
|
569
|
-
this.selectedSuggestionIndex = 0;
|
|
570
|
-
return;
|
|
571
|
-
}
|
|
572
|
-
const query = input.toLowerCase();
|
|
573
|
-
this.filteredSuggestions = this.commandSuggestions.filter(cmd => cmd.command.toLowerCase().startsWith(query) ||
|
|
574
|
-
cmd.command.toLowerCase().includes(query.slice(1)));
|
|
575
|
-
// Show suggestions if we have matches
|
|
576
|
-
this.showSuggestions = this.filteredSuggestions.length > 0;
|
|
577
|
-
// Keep selection in bounds
|
|
578
|
-
if (this.selectedSuggestionIndex >= this.filteredSuggestions.length) {
|
|
579
|
-
this.selectedSuggestionIndex = Math.max(0, this.filteredSuggestions.length - 1);
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
/**
|
|
583
|
-
* Select next suggestion (arrow down / tab).
|
|
584
|
-
*/
|
|
585
|
-
selectNextSuggestion() {
|
|
586
|
-
if (!this.showSuggestions || this.filteredSuggestions.length === 0)
|
|
587
|
-
return;
|
|
588
|
-
this.selectedSuggestionIndex = (this.selectedSuggestionIndex + 1) % this.filteredSuggestions.length;
|
|
589
|
-
this.renderDirty = true;
|
|
590
|
-
this.scheduleRender();
|
|
591
|
-
}
|
|
592
|
-
/**
|
|
593
|
-
* Select previous suggestion (arrow up / shift+tab).
|
|
594
|
-
*/
|
|
595
|
-
selectPrevSuggestion() {
|
|
596
|
-
if (!this.showSuggestions || this.filteredSuggestions.length === 0)
|
|
597
|
-
return;
|
|
598
|
-
this.selectedSuggestionIndex = this.selectedSuggestionIndex === 0
|
|
599
|
-
? this.filteredSuggestions.length - 1
|
|
600
|
-
: this.selectedSuggestionIndex - 1;
|
|
601
|
-
this.renderDirty = true;
|
|
602
|
-
this.scheduleRender();
|
|
603
|
-
}
|
|
604
|
-
/**
|
|
605
|
-
* Accept current suggestion and insert into buffer.
|
|
606
|
-
*/
|
|
607
|
-
acceptSuggestion() {
|
|
608
|
-
if (!this.showSuggestions || this.filteredSuggestions.length === 0)
|
|
609
|
-
return false;
|
|
610
|
-
const selected = this.filteredSuggestions[this.selectedSuggestionIndex];
|
|
611
|
-
if (!selected)
|
|
612
|
-
return false;
|
|
613
|
-
// Replace buffer with selected command
|
|
614
|
-
this.buffer = selected.command + ' ';
|
|
615
|
-
this.cursor = this.buffer.length;
|
|
616
|
-
this.showSuggestions = false;
|
|
617
|
-
this.renderDirty = true;
|
|
618
|
-
this.scheduleRender();
|
|
619
|
-
return true;
|
|
620
|
-
}
|
|
621
|
-
/**
|
|
622
|
-
* Check if suggestions are visible.
|
|
623
|
-
*/
|
|
624
|
-
areSuggestionsVisible() {
|
|
625
|
-
return this.showSuggestions && this.filteredSuggestions.length > 0;
|
|
626
|
-
}
|
|
627
|
-
/**
|
|
628
|
-
* Update token count for metrics display
|
|
629
|
-
*/
|
|
630
|
-
setTokensUsed(tokens) {
|
|
631
|
-
this.tokensUsed = tokens;
|
|
632
|
-
}
|
|
633
|
-
/**
|
|
634
|
-
* Toggle thinking/reasoning mode
|
|
635
|
-
*/
|
|
636
|
-
toggleThinking() {
|
|
637
|
-
this.thinkingEnabled = !this.thinkingEnabled;
|
|
638
|
-
this.emit('thinkingToggle', this.thinkingEnabled);
|
|
639
|
-
this.scheduleRender();
|
|
640
|
-
}
|
|
641
|
-
/**
|
|
642
|
-
* Get thinking enabled state
|
|
643
|
-
*/
|
|
644
|
-
isThinkingEnabled() {
|
|
645
|
-
return this.thinkingEnabled;
|
|
646
218
|
}
|
|
647
219
|
/**
|
|
648
220
|
* Keep the top N rows pinned outside the scroll region (used for the launch banner).
|
|
649
221
|
*/
|
|
650
222
|
setPinnedHeaderLines(count) {
|
|
651
|
-
//
|
|
652
|
-
if (this.pinnedTopRows !==
|
|
653
|
-
this.pinnedTopRows =
|
|
223
|
+
// No pinned header rows anymore; keep everything in the scroll region.
|
|
224
|
+
if (this.pinnedTopRows !== 0) {
|
|
225
|
+
this.pinnedTopRows = 0;
|
|
654
226
|
if (this.scrollRegionActive) {
|
|
655
227
|
this.applyScrollRegion();
|
|
656
228
|
}
|
|
657
229
|
}
|
|
658
230
|
}
|
|
659
|
-
/**
|
|
660
|
-
* Anchor prompt rendering near a specific row (inline layout). Pass null to
|
|
661
|
-
* restore the default bottom-aligned layout.
|
|
662
|
-
*/
|
|
663
|
-
setInlineAnchor(row) {
|
|
664
|
-
if (row === null || row === undefined) {
|
|
665
|
-
this.inlineAnchorRow = null;
|
|
666
|
-
this.inlineLayout = false;
|
|
667
|
-
this.renderDirty = true;
|
|
668
|
-
this.render();
|
|
669
|
-
return;
|
|
670
|
-
}
|
|
671
|
-
const { rows } = this.getSize();
|
|
672
|
-
const clamped = Math.max(1, Math.min(Math.floor(row), rows));
|
|
673
|
-
this.inlineAnchorRow = clamped;
|
|
674
|
-
this.inlineLayout = true;
|
|
675
|
-
this.renderDirty = true;
|
|
676
|
-
this.render();
|
|
677
|
-
}
|
|
678
|
-
/**
|
|
679
|
-
* Provide a dynamic anchor callback. When set, the prompt will follow the
|
|
680
|
-
* output by re-evaluating the anchor before each render.
|
|
681
|
-
*/
|
|
682
|
-
setInlineAnchorProvider(provider) {
|
|
683
|
-
this.anchorProvider = provider;
|
|
684
|
-
if (!provider) {
|
|
685
|
-
this.inlineLayout = false;
|
|
686
|
-
this.inlineAnchorRow = null;
|
|
687
|
-
this.renderDirty = true;
|
|
688
|
-
this.render();
|
|
689
|
-
return;
|
|
690
|
-
}
|
|
691
|
-
this.inlineLayout = true;
|
|
692
|
-
this.renderDirty = true;
|
|
693
|
-
this.render();
|
|
694
|
-
}
|
|
695
231
|
/**
|
|
696
232
|
* Get current mode
|
|
697
233
|
*/
|
|
@@ -801,6 +337,37 @@ export class TerminalInput extends EventEmitter {
|
|
|
801
337
|
this.streamingLabel = next;
|
|
802
338
|
this.scheduleRender();
|
|
803
339
|
}
|
|
340
|
+
/**
|
|
341
|
+
* Surface meta status just above the divider (e.g., elapsed time or token usage).
|
|
342
|
+
*/
|
|
343
|
+
setMetaStatus(meta) {
|
|
344
|
+
const nextElapsed = typeof meta.elapsedSeconds === 'number' && Number.isFinite(meta.elapsedSeconds) && meta.elapsedSeconds >= 0
|
|
345
|
+
? Math.floor(meta.elapsedSeconds)
|
|
346
|
+
: null;
|
|
347
|
+
const nextTokens = typeof meta.tokensUsed === 'number' && Number.isFinite(meta.tokensUsed) && meta.tokensUsed >= 0
|
|
348
|
+
? Math.floor(meta.tokensUsed)
|
|
349
|
+
: null;
|
|
350
|
+
const nextLimit = typeof meta.tokenLimit === 'number' && Number.isFinite(meta.tokenLimit) && meta.tokenLimit > 0
|
|
351
|
+
? Math.floor(meta.tokenLimit)
|
|
352
|
+
: null;
|
|
353
|
+
const nextThinking = typeof meta.thinkingMs === 'number' && Number.isFinite(meta.thinkingMs) && meta.thinkingMs >= 0
|
|
354
|
+
? Math.floor(meta.thinkingMs)
|
|
355
|
+
: null;
|
|
356
|
+
const nextThinkingHasContent = !!meta.thinkingHasContent;
|
|
357
|
+
if (this.metaElapsedSeconds === nextElapsed &&
|
|
358
|
+
this.metaTokensUsed === nextTokens &&
|
|
359
|
+
this.metaTokenLimit === nextLimit &&
|
|
360
|
+
this.metaThinkingMs === nextThinking &&
|
|
361
|
+
this.metaThinkingHasContent === nextThinkingHasContent) {
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
this.metaElapsedSeconds = nextElapsed;
|
|
365
|
+
this.metaTokensUsed = nextTokens;
|
|
366
|
+
this.metaTokenLimit = nextLimit;
|
|
367
|
+
this.metaThinkingMs = nextThinking;
|
|
368
|
+
this.metaThinkingHasContent = nextThinkingHasContent;
|
|
369
|
+
this.scheduleRender();
|
|
370
|
+
}
|
|
804
371
|
/**
|
|
805
372
|
* Keep mode toggles (verification/auto-continue) visible in the control bar.
|
|
806
373
|
* Hotkey labels remain stable so the bar looks the same before/during streaming.
|
|
@@ -810,26 +377,22 @@ export class TerminalInput extends EventEmitter {
|
|
|
810
377
|
const nextAutoContinue = !!options.autoContinueEnabled;
|
|
811
378
|
const nextVerifyHotkey = options.verificationHotkey ?? this.verificationHotkey;
|
|
812
379
|
const nextAutoHotkey = options.autoContinueHotkey ?? this.autoContinueHotkey;
|
|
380
|
+
const nextThinkingHotkey = options.thinkingHotkey ?? this.thinkingHotkey;
|
|
381
|
+
const nextThinkingLabel = options.thinkingModeLabel === undefined ? this.thinkingModeLabel : (options.thinkingModeLabel || null);
|
|
813
382
|
if (this.verificationEnabled === nextVerification &&
|
|
814
383
|
this.autoContinueEnabled === nextAutoContinue &&
|
|
815
384
|
this.verificationHotkey === nextVerifyHotkey &&
|
|
816
|
-
this.autoContinueHotkey === nextAutoHotkey
|
|
385
|
+
this.autoContinueHotkey === nextAutoHotkey &&
|
|
386
|
+
this.thinkingHotkey === nextThinkingHotkey &&
|
|
387
|
+
this.thinkingModeLabel === nextThinkingLabel) {
|
|
817
388
|
return;
|
|
818
389
|
}
|
|
819
390
|
this.verificationEnabled = nextVerification;
|
|
820
391
|
this.autoContinueEnabled = nextAutoContinue;
|
|
821
392
|
this.verificationHotkey = nextVerifyHotkey;
|
|
822
393
|
this.autoContinueHotkey = nextAutoHotkey;
|
|
823
|
-
this.
|
|
824
|
-
|
|
825
|
-
/**
|
|
826
|
-
* Set the model info string (e.g., "OpenAI · gpt-4")
|
|
827
|
-
* This is displayed persistently above the input area.
|
|
828
|
-
*/
|
|
829
|
-
setModelInfo(info) {
|
|
830
|
-
if (this.modelInfo === info)
|
|
831
|
-
return;
|
|
832
|
-
this.modelInfo = info;
|
|
394
|
+
this.thinkingHotkey = nextThinkingHotkey;
|
|
395
|
+
this.thinkingModeLabel = nextThinkingLabel;
|
|
833
396
|
this.scheduleRender();
|
|
834
397
|
}
|
|
835
398
|
/**
|
|
@@ -842,298 +405,390 @@ export class TerminalInput extends EventEmitter {
|
|
|
842
405
|
this.scheduleRender();
|
|
843
406
|
}
|
|
844
407
|
/**
|
|
845
|
-
*
|
|
408
|
+
* Surface model/provider context in the controls bar.
|
|
409
|
+
*/
|
|
410
|
+
setModelContext(options) {
|
|
411
|
+
const nextModel = options.model?.trim() || null;
|
|
412
|
+
const nextProvider = options.provider?.trim() || null;
|
|
413
|
+
if (this.modelLabel === nextModel && this.providerLabel === nextProvider) {
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
this.modelLabel = nextModel;
|
|
417
|
+
this.providerLabel = nextProvider;
|
|
418
|
+
this.scheduleRender();
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Render the input area - Claude Code style with mode controls
|
|
846
422
|
*
|
|
847
|
-
*
|
|
848
|
-
*
|
|
849
|
-
*
|
|
850
|
-
* - Ready mode: Shows status info
|
|
423
|
+
* During streaming we keep the scroll region active and repaint only the
|
|
424
|
+
* pinned status/input block (throttled) so streamed content can scroll
|
|
425
|
+
* naturally above while elapsed time and status stay fresh.
|
|
851
426
|
*/
|
|
852
427
|
render() {
|
|
853
428
|
if (!this.canRender())
|
|
854
429
|
return;
|
|
855
430
|
if (this.isRendering)
|
|
856
431
|
return;
|
|
432
|
+
const streamingActive = this.mode === 'streaming' || isStreamingMode();
|
|
433
|
+
// During streaming we still render the pinned input/status region, but throttle
|
|
434
|
+
// to avoid fighting with the streamed content flow.
|
|
435
|
+
if (streamingActive && this.lastStreamingRender > 0) {
|
|
436
|
+
const elapsed = Date.now() - this.lastStreamingRender;
|
|
437
|
+
const waitMs = Math.max(0, this.streamingRenderInterval - elapsed);
|
|
438
|
+
if (waitMs > 0) {
|
|
439
|
+
this.renderDirty = true;
|
|
440
|
+
this.scheduleStreamingRender(waitMs);
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
857
444
|
const shouldSkip = !this.renderDirty &&
|
|
858
445
|
this.buffer === this.lastRenderContent &&
|
|
859
446
|
this.cursor === this.lastRenderCursor;
|
|
860
447
|
this.renderDirty = false;
|
|
861
|
-
// Skip if nothing changed
|
|
448
|
+
// Skip if nothing changed and no explicit refresh requested
|
|
862
449
|
if (shouldSkip) {
|
|
863
450
|
return;
|
|
864
451
|
}
|
|
865
|
-
// If write lock is held, defer render
|
|
452
|
+
// If write lock is held, defer render to avoid race conditions
|
|
866
453
|
if (writeLock.isLocked()) {
|
|
867
454
|
writeLock.safeWrite(() => this.render());
|
|
868
455
|
return;
|
|
869
456
|
}
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
this.
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
* - Input line(s)
|
|
908
|
-
* - Bottom divider
|
|
909
|
-
* - Mode controls
|
|
910
|
-
*/
|
|
911
|
-
renderBottomPinned() {
|
|
912
|
-
const { rows, cols } = this.getSize();
|
|
913
|
-
const maxWidth = Math.max(8, cols - 4);
|
|
914
|
-
const isStreaming = this.mode === 'streaming';
|
|
915
|
-
// Use unified pinned input area (works for both streaming and normal)
|
|
916
|
-
// Only use complex rendering when suggestions are visible
|
|
917
|
-
const hasSuggestions = !isStreaming && this.showSuggestions && this.filteredSuggestions.length > 0;
|
|
918
|
-
if (!hasSuggestions) {
|
|
919
|
-
this.renderPinnedInputArea();
|
|
920
|
-
return;
|
|
921
|
-
}
|
|
922
|
-
// Wrap buffer into display lines
|
|
923
|
-
const { lines, cursorLine, cursorCol } = this.wrapBuffer(maxWidth);
|
|
924
|
-
const availableForContent = Math.max(1, rows - 3);
|
|
925
|
-
const maxVisible = Math.max(1, Math.min(this.config.maxLines, availableForContent));
|
|
926
|
-
const displayLines = Math.min(lines.length, maxVisible);
|
|
927
|
-
// Calculate display window (keep cursor visible)
|
|
928
|
-
let startLine = 0;
|
|
929
|
-
if (lines.length > displayLines) {
|
|
930
|
-
startLine = Math.max(0, cursorLine - displayLines + 1);
|
|
931
|
-
startLine = Math.min(startLine, lines.length - displayLines);
|
|
932
|
-
}
|
|
933
|
-
const visibleLines = lines.slice(startLine, startLine + displayLines);
|
|
934
|
-
const adjustedCursorLine = cursorLine - startLine;
|
|
935
|
-
// Calculate suggestion display (not during streaming)
|
|
936
|
-
const suggestionsToShow = (!isStreaming && this.showSuggestions)
|
|
937
|
-
? this.filteredSuggestions.slice(0, this.maxVisibleSuggestions)
|
|
938
|
-
: [];
|
|
939
|
-
const suggestionLines = suggestionsToShow.length;
|
|
940
|
-
this.write(ESC.HIDE);
|
|
941
|
-
this.write(ESC.RESET);
|
|
942
|
-
const divider = renderDivider(cols - 2);
|
|
943
|
-
// Calculate positions from absolute bottom
|
|
944
|
-
let currentRow;
|
|
945
|
-
if (suggestionLines > 0) {
|
|
946
|
-
// With suggestions: input area + dividers + suggestions
|
|
947
|
-
// Layout: [topDiv] [input] [bottomDiv] [suggestions...]
|
|
948
|
-
const totalHeight = 2 + visibleLines.length + suggestionLines; // 2 dividers
|
|
949
|
-
currentRow = Math.max(1, rows - totalHeight + 1);
|
|
950
|
-
this.updateReservedLines(totalHeight);
|
|
951
|
-
// Clear from current position to end of screen to remove any "ghost" content
|
|
952
|
-
this.write(ESC.TO(currentRow, 1));
|
|
953
|
-
this.write(ESC.CLEAR_TO_END);
|
|
954
|
-
// Top divider
|
|
457
|
+
const performRender = () => {
|
|
458
|
+
if (!this.scrollRegionActive) {
|
|
459
|
+
this.enableScrollRegion();
|
|
460
|
+
}
|
|
461
|
+
const { rows, cols } = this.getSize();
|
|
462
|
+
const maxWidth = Math.max(8, cols - 4);
|
|
463
|
+
// Wrap buffer into display lines
|
|
464
|
+
const { lines, cursorLine, cursorCol } = this.wrapBuffer(maxWidth);
|
|
465
|
+
const availableForContent = Math.max(1, rows - 3); // room for separator + input + controls
|
|
466
|
+
const maxVisible = Math.max(1, Math.min(this.config.maxLines, availableForContent));
|
|
467
|
+
const displayLines = Math.min(lines.length, maxVisible);
|
|
468
|
+
const metaLines = this.buildMetaLines(cols - 2);
|
|
469
|
+
// Reserved lines: optional meta lines + separator(1) + input lines + controls(1)
|
|
470
|
+
this.updateReservedLines(displayLines + 2 + metaLines.length);
|
|
471
|
+
// Calculate display window (keep cursor visible)
|
|
472
|
+
let startLine = 0;
|
|
473
|
+
if (lines.length > displayLines) {
|
|
474
|
+
startLine = Math.max(0, cursorLine - displayLines + 1);
|
|
475
|
+
startLine = Math.min(startLine, lines.length - displayLines);
|
|
476
|
+
}
|
|
477
|
+
const visibleLines = lines.slice(startLine, startLine + displayLines);
|
|
478
|
+
const adjustedCursorLine = cursorLine - startLine;
|
|
479
|
+
// Hide cursor during render to prevent flicker
|
|
480
|
+
this.write(ESC.HIDE);
|
|
481
|
+
this.write(ESC.RESET);
|
|
482
|
+
const startRow = Math.max(1, rows - this.reservedLines + 1);
|
|
483
|
+
let currentRow = startRow;
|
|
484
|
+
// Clear the reserved block to avoid stale meta/status lines
|
|
485
|
+
this.clearReservedArea(startRow, this.reservedLines, cols);
|
|
486
|
+
// Meta/status header (elapsed, tokens/context)
|
|
487
|
+
for (const metaLine of metaLines) {
|
|
488
|
+
this.write(ESC.TO(currentRow, 1));
|
|
489
|
+
this.write(ESC.CLEAR_LINE);
|
|
490
|
+
this.write(metaLine);
|
|
491
|
+
currentRow += 1;
|
|
492
|
+
}
|
|
493
|
+
// Separator line
|
|
955
494
|
this.write(ESC.TO(currentRow, 1));
|
|
495
|
+
this.write(ESC.CLEAR_LINE);
|
|
496
|
+
const divider = renderDivider(cols - 2);
|
|
956
497
|
this.write(divider);
|
|
957
|
-
currentRow
|
|
958
|
-
//
|
|
498
|
+
currentRow += 1;
|
|
499
|
+
// Render input lines
|
|
959
500
|
let finalRow = currentRow;
|
|
960
501
|
let finalCol = 3;
|
|
961
502
|
for (let i = 0; i < visibleLines.length; i++) {
|
|
962
|
-
|
|
503
|
+
const rowNum = currentRow + i;
|
|
504
|
+
this.write(ESC.TO(rowNum, 1));
|
|
505
|
+
this.write(ESC.CLEAR_LINE);
|
|
963
506
|
const line = visibleLines[i] ?? '';
|
|
964
507
|
const absoluteLineIdx = startLine + i;
|
|
965
508
|
const isFirstLine = absoluteLineIdx === 0;
|
|
966
509
|
const isCursorLine = i === adjustedCursorLine;
|
|
510
|
+
// Background
|
|
511
|
+
this.write(ESC.BG_DARK);
|
|
512
|
+
// Prompt prefix
|
|
513
|
+
this.write(ESC.DIM);
|
|
967
514
|
this.write(isFirstLine ? this.config.promptChar : this.config.continuationChar);
|
|
515
|
+
this.write(ESC.RESET);
|
|
516
|
+
this.write(ESC.BG_DARK);
|
|
968
517
|
if (isCursorLine) {
|
|
518
|
+
// Render with block cursor
|
|
969
519
|
const col = Math.min(cursorCol, line.length);
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
this.write(
|
|
974
|
-
this.write(
|
|
975
|
-
|
|
520
|
+
const before = line.slice(0, col);
|
|
521
|
+
const at = col < line.length ? line[col] : ' ';
|
|
522
|
+
const after = col < line.length ? line.slice(col + 1) : '';
|
|
523
|
+
this.write(before);
|
|
524
|
+
this.write(ESC.REVERSE + ESC.BOLD);
|
|
525
|
+
this.write(at);
|
|
526
|
+
this.write(ESC.RESET + ESC.BG_DARK);
|
|
527
|
+
this.write(after);
|
|
528
|
+
finalRow = rowNum;
|
|
976
529
|
finalCol = this.config.promptChar.length + col + 1;
|
|
977
530
|
}
|
|
978
531
|
else {
|
|
979
532
|
this.write(line);
|
|
980
533
|
}
|
|
981
|
-
|
|
534
|
+
// Pad to edge for clean look
|
|
535
|
+
const lineLen = this.config.promptChar.length + line.length + (isCursorLine && cursorCol >= line.length ? 1 : 0);
|
|
536
|
+
const padding = Math.max(0, cols - lineLen - 1);
|
|
537
|
+
if (padding > 0)
|
|
538
|
+
this.write(' '.repeat(padding));
|
|
539
|
+
this.write(ESC.RESET);
|
|
982
540
|
}
|
|
983
|
-
//
|
|
984
|
-
|
|
985
|
-
this.write(
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
this.write(ESC.TO(currentRow, 1));
|
|
990
|
-
const suggestion = suggestionsToShow[i];
|
|
991
|
-
const isSelected = i === this.selectedSuggestionIndex;
|
|
992
|
-
// Indent and highlight selected
|
|
993
|
-
this.write(' ');
|
|
994
|
-
if (isSelected) {
|
|
995
|
-
this.write(ESC.REVERSE);
|
|
996
|
-
this.write(ESC.BOLD);
|
|
997
|
-
}
|
|
998
|
-
this.write(suggestion.command);
|
|
999
|
-
if (isSelected) {
|
|
1000
|
-
this.write(ESC.RESET);
|
|
1001
|
-
}
|
|
1002
|
-
// Description (dimmed)
|
|
1003
|
-
const descSpace = cols - suggestion.command.length - 8;
|
|
1004
|
-
if (descSpace > 10 && suggestion.description) {
|
|
1005
|
-
const desc = suggestion.description.slice(0, descSpace);
|
|
1006
|
-
this.write(ESC.RESET);
|
|
1007
|
-
this.write(ESC.DIM);
|
|
1008
|
-
this.write(' ');
|
|
1009
|
-
this.write(desc);
|
|
1010
|
-
this.write(ESC.RESET);
|
|
1011
|
-
}
|
|
1012
|
-
currentRow++;
|
|
1013
|
-
}
|
|
1014
|
-
// Position cursor in input area
|
|
541
|
+
// Mode controls line (Claude Code style)
|
|
542
|
+
const controlRow = currentRow + visibleLines.length;
|
|
543
|
+
this.write(ESC.TO(controlRow, 1));
|
|
544
|
+
this.write(ESC.CLEAR_LINE);
|
|
545
|
+
this.write(this.buildModeControls(cols));
|
|
546
|
+
// Position cursor in the input box for user editing
|
|
1015
547
|
this.write(ESC.TO(finalRow, Math.min(finalCol, cols)));
|
|
548
|
+
this.write(ESC.SHOW);
|
|
549
|
+
// Update state
|
|
550
|
+
this.lastRenderContent = this.buffer;
|
|
551
|
+
this.lastRenderCursor = this.cursor;
|
|
552
|
+
this.lastStreamingRender = streamingActive ? Date.now() : 0;
|
|
553
|
+
if (this.streamingRenderTimer) {
|
|
554
|
+
clearTimeout(this.streamingRenderTimer);
|
|
555
|
+
this.streamingRenderTimer = null;
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
// Use write lock during render to prevent interleaved output
|
|
559
|
+
writeLock.lock('terminalInput.render');
|
|
560
|
+
this.isRendering = true;
|
|
561
|
+
try {
|
|
562
|
+
performRender();
|
|
563
|
+
}
|
|
564
|
+
finally {
|
|
565
|
+
writeLock.unlock();
|
|
566
|
+
this.isRendering = false;
|
|
1016
567
|
}
|
|
1017
|
-
this.write(ESC.SHOW);
|
|
1018
|
-
// Update state
|
|
1019
|
-
this.lastRenderContent = this.buffer;
|
|
1020
|
-
this.lastRenderCursor = this.cursor;
|
|
1021
568
|
}
|
|
1022
569
|
/**
|
|
1023
|
-
* Build
|
|
570
|
+
* Build one or more compact meta lines above the divider (thinking, status, usage).
|
|
571
|
+
* During streaming, shows model line pinned above streaming info.
|
|
1024
572
|
*/
|
|
1025
|
-
|
|
1026
|
-
const
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
if (this.
|
|
1030
|
-
const
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
//
|
|
573
|
+
buildMetaLines(width) {
|
|
574
|
+
const streamingActive = this.mode === 'streaming' || isStreamingMode();
|
|
575
|
+
const lines = [];
|
|
576
|
+
// Model line should ALWAYS be shown (pinned above streaming content)
|
|
577
|
+
if (this.modelLabel) {
|
|
578
|
+
const modelText = this.providerLabel
|
|
579
|
+
? `model ${this.modelLabel} @ ${this.providerLabel}`
|
|
580
|
+
: `model ${this.modelLabel}`;
|
|
581
|
+
lines.push(renderStatusLine([{ text: modelText, tone: 'info' }], width));
|
|
582
|
+
}
|
|
583
|
+
// During streaming, add a compact status line with essential info
|
|
584
|
+
if (streamingActive) {
|
|
585
|
+
const parts = [];
|
|
586
|
+
// Essential streaming info
|
|
587
|
+
if (this.metaThinkingMs !== null) {
|
|
588
|
+
parts.push({ text: formatThinking(this.metaThinkingMs, this.metaThinkingHasContent), tone: 'info' });
|
|
589
|
+
}
|
|
590
|
+
if (this.metaElapsedSeconds !== null) {
|
|
591
|
+
parts.push({ text: this.formatElapsedLabel(this.metaElapsedSeconds), tone: 'muted' });
|
|
592
|
+
}
|
|
593
|
+
parts.push({ text: 'esc to stop', tone: 'warn' });
|
|
594
|
+
if (parts.length) {
|
|
595
|
+
lines.push(renderStatusLine(parts, width));
|
|
596
|
+
}
|
|
597
|
+
return lines;
|
|
598
|
+
}
|
|
599
|
+
// Non-streaming: show full status info (model line already added above)
|
|
600
|
+
if (this.metaThinkingMs !== null) {
|
|
601
|
+
const thinkingText = formatThinking(this.metaThinkingMs, this.metaThinkingHasContent);
|
|
602
|
+
lines.push(renderStatusLine([{ text: thinkingText, tone: 'info' }], width));
|
|
603
|
+
}
|
|
604
|
+
const statusParts = [];
|
|
605
|
+
const statusLabel = this.statusMessage ?? this.streamingLabel;
|
|
606
|
+
if (statusLabel) {
|
|
607
|
+
statusParts.push({ text: statusLabel, tone: 'info' });
|
|
608
|
+
}
|
|
609
|
+
if (this.metaElapsedSeconds !== null) {
|
|
610
|
+
statusParts.push({ text: this.formatElapsedLabel(this.metaElapsedSeconds), tone: 'muted' });
|
|
611
|
+
}
|
|
612
|
+
const tokensRemaining = this.computeTokensRemaining();
|
|
613
|
+
if (tokensRemaining !== null) {
|
|
614
|
+
statusParts.push({ text: `↓ ${tokensRemaining}`, tone: 'muted' });
|
|
615
|
+
}
|
|
616
|
+
if (statusParts.length) {
|
|
617
|
+
lines.push(renderStatusLine(statusParts, width));
|
|
618
|
+
}
|
|
619
|
+
const usageParts = [];
|
|
620
|
+
if (this.metaTokensUsed !== null) {
|
|
621
|
+
const formattedUsed = this.formatTokenCount(this.metaTokensUsed);
|
|
622
|
+
const formattedLimit = this.metaTokenLimit ? `/${this.formatTokenCount(this.metaTokenLimit)}` : '';
|
|
623
|
+
usageParts.push({ text: `tokens ${formattedUsed}${formattedLimit}`, tone: 'muted' });
|
|
624
|
+
}
|
|
625
|
+
if (this.contextUsage !== null) {
|
|
626
|
+
const tone = this.contextUsage >= 75 ? 'warn' : 'muted';
|
|
627
|
+
const left = Math.max(0, 100 - this.contextUsage);
|
|
628
|
+
usageParts.push({ text: `context used ${this.contextUsage}% (${left}% left)`, tone });
|
|
629
|
+
}
|
|
1036
630
|
if (this.queue.length > 0) {
|
|
1037
|
-
|
|
631
|
+
usageParts.push({ text: `queued ${this.queue.length}`, tone: 'info' });
|
|
1038
632
|
}
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
633
|
+
if (usageParts.length) {
|
|
634
|
+
lines.push(renderStatusLine(usageParts, width));
|
|
635
|
+
}
|
|
636
|
+
return lines;
|
|
1042
637
|
}
|
|
1043
638
|
/**
|
|
1044
|
-
*
|
|
1045
|
-
* This is the TOP line above the input area - minimal Claude Code style.
|
|
639
|
+
* Clear the reserved bottom block (meta + divider + input + controls) before repainting.
|
|
1046
640
|
*/
|
|
1047
|
-
|
|
1048
|
-
const
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
if (this.streamingStartTime) {
|
|
1054
|
-
const elapsed = Math.floor((Date.now() - this.streamingStartTime) / 1000);
|
|
1055
|
-
const mins = Math.floor(elapsed / 60);
|
|
1056
|
-
const secs = elapsed % 60;
|
|
1057
|
-
statusText += mins > 0 ? ` ${mins}m ${secs}s` : ` ${secs}s`;
|
|
1058
|
-
}
|
|
1059
|
-
parts.push(`\x1b[32m${statusText}\x1b[0m`); // Green
|
|
1060
|
-
}
|
|
1061
|
-
// Queue indicator during streaming
|
|
1062
|
-
if (this.mode === 'streaming' && this.queue.length > 0) {
|
|
1063
|
-
parts.push(`\x1b[36mqueued: ${this.queue.length}\x1b[0m`); // Cyan
|
|
641
|
+
clearReservedArea(startRow, reservedLines, cols) {
|
|
642
|
+
const width = Math.max(1, cols);
|
|
643
|
+
for (let i = 0; i < reservedLines; i++) {
|
|
644
|
+
const row = startRow + i;
|
|
645
|
+
this.write(ESC.TO(row, 1));
|
|
646
|
+
this.write(' '.repeat(width));
|
|
1064
647
|
}
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Build Claude Code style mode controls line.
|
|
651
|
+
* Combines streaming label + override status + main status for simultaneous display.
|
|
652
|
+
*/
|
|
653
|
+
buildModeControls(cols) {
|
|
654
|
+
const width = Math.max(8, cols - 2);
|
|
655
|
+
const leftParts = [];
|
|
656
|
+
const rightParts = [];
|
|
657
|
+
if (this.streamingLabel) {
|
|
658
|
+
leftParts.push({ text: `◐ ${this.streamingLabel}`, tone: 'info' });
|
|
1069
659
|
}
|
|
1070
|
-
// Override/warning status
|
|
1071
660
|
if (this.overrideStatusMessage) {
|
|
1072
|
-
|
|
1073
|
-
}
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
661
|
+
leftParts.push({ text: `⚠ ${this.overrideStatusMessage}`, tone: 'warn' });
|
|
662
|
+
}
|
|
663
|
+
if (this.statusMessage) {
|
|
664
|
+
leftParts.push({ text: this.statusMessage, tone: this.streamingLabel ? 'muted' : 'info' });
|
|
665
|
+
}
|
|
666
|
+
const editHotkey = this.formatHotkey('shift+tab');
|
|
667
|
+
const editLabel = this.editMode === 'display-edits' ? 'edits: accept' : 'edits: ask';
|
|
668
|
+
const editTone = this.editMode === 'display-edits' ? 'success' : 'muted';
|
|
669
|
+
leftParts.push({ text: `${editHotkey} ${editLabel}`, tone: editTone });
|
|
670
|
+
const verifyHotkey = this.formatHotkey(this.verificationHotkey);
|
|
671
|
+
const verifyLabel = this.verificationEnabled ? 'verify:on' : 'verify:off';
|
|
672
|
+
leftParts.push({ text: `${verifyHotkey} ${verifyLabel}`, tone: this.verificationEnabled ? 'success' : 'muted' });
|
|
673
|
+
const continueHotkey = this.formatHotkey(this.autoContinueHotkey);
|
|
674
|
+
const continueLabel = this.autoContinueEnabled ? 'auto:on' : 'auto:off';
|
|
675
|
+
leftParts.push({ text: `${continueHotkey} ${continueLabel}`, tone: this.autoContinueEnabled ? 'info' : 'muted' });
|
|
676
|
+
if (this.queue.length > 0 && this.mode !== 'streaming') {
|
|
677
|
+
leftParts.push({ text: `queued ${this.queue.length}`, tone: 'info' });
|
|
1077
678
|
}
|
|
1078
|
-
// Multi-line indicator
|
|
1079
679
|
if (this.buffer.includes('\n')) {
|
|
1080
|
-
|
|
680
|
+
const lineCount = this.buffer.split('\n').length;
|
|
681
|
+
leftParts.push({ text: `${lineCount} lines`, tone: 'muted' });
|
|
682
|
+
}
|
|
683
|
+
if (this.pastePlaceholders.length > 0) {
|
|
684
|
+
const latest = this.pastePlaceholders[this.pastePlaceholders.length - 1];
|
|
685
|
+
leftParts.push({
|
|
686
|
+
text: `paste #${latest.id} +${latest.lineCount} lines (⌫ to drop)`,
|
|
687
|
+
tone: 'info',
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
const contextRemaining = this.computeContextRemaining();
|
|
691
|
+
if (this.thinkingModeLabel) {
|
|
692
|
+
const thinkingHotkey = this.formatHotkey(this.thinkingHotkey);
|
|
693
|
+
rightParts.push({ text: `${thinkingHotkey} thinking:${this.thinkingModeLabel}`, tone: 'info' });
|
|
694
|
+
}
|
|
695
|
+
// Show model in controls only when NOT streaming (during streaming it's in meta lines)
|
|
696
|
+
const streamingActive = this.mode === 'streaming' || isStreamingMode();
|
|
697
|
+
if (this.modelLabel && !streamingActive) {
|
|
698
|
+
const modelText = this.providerLabel ? `${this.modelLabel} @ ${this.providerLabel}` : this.modelLabel;
|
|
699
|
+
rightParts.push({ text: modelText, tone: 'muted' });
|
|
700
|
+
}
|
|
701
|
+
if (contextRemaining !== null) {
|
|
702
|
+
const tone = contextRemaining <= 10 ? 'warn' : 'muted';
|
|
703
|
+
const label = contextRemaining === 0 && this.contextUsage !== null
|
|
704
|
+
? 'Context auto-compact imminent'
|
|
705
|
+
: `Context left until auto-compact: ${contextRemaining}%`;
|
|
706
|
+
rightParts.push({ text: label, tone });
|
|
707
|
+
}
|
|
708
|
+
if (!rightParts.length || width < 60) {
|
|
709
|
+
const merged = rightParts.length ? [...leftParts, ...rightParts] : leftParts;
|
|
710
|
+
return renderStatusLine(merged, width);
|
|
711
|
+
}
|
|
712
|
+
const leftWidth = Math.max(12, Math.floor(width * 0.6));
|
|
713
|
+
const rightWidth = Math.max(14, width - leftWidth - 1);
|
|
714
|
+
const leftText = renderStatusLine(leftParts, leftWidth);
|
|
715
|
+
const rightText = renderStatusLine(rightParts, rightWidth);
|
|
716
|
+
const spacing = Math.max(1, width - this.visibleLength(leftText) - this.visibleLength(rightText));
|
|
717
|
+
return `${leftText}${' '.repeat(spacing)}${rightText}`;
|
|
718
|
+
}
|
|
719
|
+
formatHotkey(hotkey) {
|
|
720
|
+
const normalized = hotkey.trim().toLowerCase();
|
|
721
|
+
if (!normalized)
|
|
722
|
+
return hotkey;
|
|
723
|
+
const parts = normalized.split('+').filter(Boolean);
|
|
724
|
+
const map = {
|
|
725
|
+
shift: '⇧',
|
|
726
|
+
sh: '⇧',
|
|
727
|
+
alt: '⌥',
|
|
728
|
+
option: '⌥',
|
|
729
|
+
opt: '⌥',
|
|
730
|
+
ctrl: '⌃',
|
|
731
|
+
control: '⌃',
|
|
732
|
+
cmd: '⌘',
|
|
733
|
+
meta: '⌘',
|
|
734
|
+
};
|
|
735
|
+
const formatted = parts
|
|
736
|
+
.map((part) => {
|
|
737
|
+
const symbol = map[part];
|
|
738
|
+
if (symbol)
|
|
739
|
+
return symbol;
|
|
740
|
+
return part.length === 1 ? part.toUpperCase() : part.toUpperCase();
|
|
741
|
+
})
|
|
742
|
+
.join('');
|
|
743
|
+
return formatted || hotkey;
|
|
744
|
+
}
|
|
745
|
+
computeContextRemaining() {
|
|
746
|
+
if (this.contextUsage === null) {
|
|
747
|
+
return null;
|
|
748
|
+
}
|
|
749
|
+
return Math.max(0, this.contextAutoCompactThreshold - this.contextUsage);
|
|
750
|
+
}
|
|
751
|
+
computeTokensRemaining() {
|
|
752
|
+
if (this.metaTokensUsed === null || this.metaTokenLimit === null) {
|
|
753
|
+
return null;
|
|
754
|
+
}
|
|
755
|
+
const remaining = Math.max(0, this.metaTokenLimit - this.metaTokensUsed);
|
|
756
|
+
return this.formatTokenCount(remaining);
|
|
757
|
+
}
|
|
758
|
+
formatElapsedLabel(seconds) {
|
|
759
|
+
if (seconds < 60) {
|
|
760
|
+
return `${seconds}s`;
|
|
761
|
+
}
|
|
762
|
+
const mins = Math.floor(seconds / 60);
|
|
763
|
+
const secs = seconds % 60;
|
|
764
|
+
return secs > 0 ? `${mins}m ${secs}s` : `${mins}m`;
|
|
765
|
+
}
|
|
766
|
+
formatTokenCount(value) {
|
|
767
|
+
if (!Number.isFinite(value)) {
|
|
768
|
+
return `${value}`;
|
|
1081
769
|
}
|
|
1082
|
-
if (
|
|
1083
|
-
return
|
|
770
|
+
if (value >= 1_000_000) {
|
|
771
|
+
return `${(value / 1_000_000).toFixed(1)}M`;
|
|
1084
772
|
}
|
|
1085
|
-
|
|
1086
|
-
|
|
773
|
+
if (value >= 1_000) {
|
|
774
|
+
return `${(value / 1_000).toFixed(1)}k`;
|
|
775
|
+
}
|
|
776
|
+
return `${Math.round(value)}`;
|
|
777
|
+
}
|
|
778
|
+
visibleLength(value) {
|
|
779
|
+
const ansiPattern = /\u001B\[[0-?]*[ -/]*[@-~]/g;
|
|
780
|
+
return value.replace(ansiPattern, '').length;
|
|
1087
781
|
}
|
|
1088
782
|
/**
|
|
1089
|
-
*
|
|
1090
|
-
*
|
|
1091
|
-
*
|
|
1092
|
-
* Layout: [toggles on left] ... [context info on right]
|
|
783
|
+
* Debug-only snapshot used by tests to assert rendered strings without
|
|
784
|
+
* needing a TTY. Not used by production code.
|
|
1093
785
|
*/
|
|
1094
|
-
|
|
1095
|
-
const
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
// Edit mode (green=auto, yellow=ask) - per schema.editMode
|
|
1101
|
-
if (this.editMode === 'display-edits') {
|
|
1102
|
-
toggles.push(`${GREEN}⏵⏵ auto-edit${R}`);
|
|
1103
|
-
}
|
|
1104
|
-
else {
|
|
1105
|
-
toggles.push(`${YELLOW}⏸⏸ ask-first${R}`);
|
|
1106
|
-
}
|
|
1107
|
-
// Thinking mode (cyan when on) - per schema.thinkingMode
|
|
1108
|
-
toggles.push(this.thinkingEnabled ? `${CYAN}💭 think${R}` : `${DIM}○ think${R}`);
|
|
1109
|
-
// Verification (green when on) - per schema.verificationMode
|
|
1110
|
-
toggles.push(this.verificationEnabled ? `${GREEN}✓ verify${R}` : `${DIM}○ verify${R}`);
|
|
1111
|
-
// Auto-continue (magenta when on) - per schema.autoContinueMode
|
|
1112
|
-
toggles.push(this.autoContinueEnabled ? `${MAGENTA}↻ auto${R}` : `${DIM}○ auto${R}`);
|
|
1113
|
-
const leftPart = toggles.join(`${DIM} · ${R}`) + `${DIM} (⇧⇥)${R}`;
|
|
1114
|
-
// Context usage with color - per schema.contextUsage thresholds
|
|
1115
|
-
let rightPart = '';
|
|
1116
|
-
if (this.contextUsage !== null) {
|
|
1117
|
-
const rem = Math.max(0, 100 - this.contextUsage);
|
|
1118
|
-
// Thresholds: critical < 10%, warning < 25%
|
|
1119
|
-
if (rem < 10)
|
|
1120
|
-
rightPart = `${RED}⚠ ctx: ${rem}%${R}`;
|
|
1121
|
-
else if (rem < 25)
|
|
1122
|
-
rightPart = `${YELLOW}! ctx: ${rem}%${R}`;
|
|
1123
|
-
else
|
|
1124
|
-
rightPart = `${DIM}ctx: ${rem}%${R}`;
|
|
1125
|
-
}
|
|
1126
|
-
// Calculate visible lengths (strip ANSI)
|
|
1127
|
-
const strip = (s) => s.replace(/\x1b\[[0-9;]*m/g, '');
|
|
1128
|
-
const leftLen = strip(leftPart).length;
|
|
1129
|
-
const rightLen = strip(rightPart).length;
|
|
1130
|
-
if (leftLen + rightLen < maxWidth - 4) {
|
|
1131
|
-
return `${leftPart}${' '.repeat(maxWidth - leftLen - rightLen)}${rightPart}`;
|
|
1132
|
-
}
|
|
1133
|
-
if (rightLen > 0 && leftLen + 8 < maxWidth) {
|
|
1134
|
-
return `${leftPart} ${rightPart}`;
|
|
1135
|
-
}
|
|
1136
|
-
return leftPart;
|
|
786
|
+
getDebugUiSnapshot(width) {
|
|
787
|
+
const cols = Math.max(8, width ?? this.getSize().cols);
|
|
788
|
+
return {
|
|
789
|
+
meta: this.buildMetaLines(cols - 2),
|
|
790
|
+
controls: this.buildModeControls(cols),
|
|
791
|
+
};
|
|
1137
792
|
}
|
|
1138
793
|
/**
|
|
1139
794
|
* Force a re-render
|
|
@@ -1156,17 +811,19 @@ export class TerminalInput extends EventEmitter {
|
|
|
1156
811
|
handleResize() {
|
|
1157
812
|
this.lastRenderContent = '';
|
|
1158
813
|
this.lastRenderCursor = -1;
|
|
814
|
+
this.resetStreamingRenderThrottle();
|
|
1159
815
|
// Re-clamp pinned header rows to the new terminal height
|
|
1160
816
|
this.setPinnedHeaderLines(this.pinnedTopRows);
|
|
817
|
+
if (this.scrollRegionActive) {
|
|
818
|
+
this.disableScrollRegion();
|
|
819
|
+
this.enableScrollRegion();
|
|
820
|
+
}
|
|
1161
821
|
this.scheduleRender();
|
|
1162
822
|
}
|
|
1163
823
|
/**
|
|
1164
824
|
* Register with display's output interceptor to position cursor correctly.
|
|
1165
825
|
* When scroll region is active, output needs to go to the scroll region,
|
|
1166
826
|
* not the protected bottom area where the input is rendered.
|
|
1167
|
-
*
|
|
1168
|
-
* NOTE: With scroll region properly set, content naturally stays within
|
|
1169
|
-
* the region boundaries - no cursor manipulation needed per-write.
|
|
1170
827
|
*/
|
|
1171
828
|
registerOutputInterceptor(display) {
|
|
1172
829
|
if (this.outputInterceptorCleanup) {
|
|
@@ -1174,11 +831,20 @@ export class TerminalInput extends EventEmitter {
|
|
|
1174
831
|
}
|
|
1175
832
|
this.outputInterceptorCleanup = display.registerOutputInterceptor({
|
|
1176
833
|
beforeWrite: () => {
|
|
1177
|
-
//
|
|
1178
|
-
//
|
|
834
|
+
// Position cursor at scroll region bottom for content.
|
|
835
|
+
// Terminal handles scrolling automatically when bottom is reached.
|
|
836
|
+
if (this.scrollRegionActive) {
|
|
837
|
+
const { rows } = this.getSize();
|
|
838
|
+
const scrollBottom = Math.max(this.pinnedTopRows + 1, rows - this.reservedLines);
|
|
839
|
+
this.write(ESC.SAVE);
|
|
840
|
+
this.write(ESC.TO(scrollBottom, 1));
|
|
841
|
+
}
|
|
1179
842
|
},
|
|
1180
843
|
afterWrite: () => {
|
|
1181
|
-
//
|
|
844
|
+
// Restore cursor position after content output.
|
|
845
|
+
if (this.scrollRegionActive) {
|
|
846
|
+
this.write(ESC.RESTORE);
|
|
847
|
+
}
|
|
1182
848
|
},
|
|
1183
849
|
});
|
|
1184
850
|
}
|
|
@@ -1188,11 +854,6 @@ export class TerminalInput extends EventEmitter {
|
|
|
1188
854
|
dispose() {
|
|
1189
855
|
if (this.disposed)
|
|
1190
856
|
return;
|
|
1191
|
-
// Clean up streaming render timer
|
|
1192
|
-
if (this.streamingRenderTimer) {
|
|
1193
|
-
clearInterval(this.streamingRenderTimer);
|
|
1194
|
-
this.streamingRenderTimer = null;
|
|
1195
|
-
}
|
|
1196
857
|
// Clean up output interceptor
|
|
1197
858
|
if (this.outputInterceptorCleanup) {
|
|
1198
859
|
this.outputInterceptorCleanup();
|
|
@@ -1200,6 +861,7 @@ export class TerminalInput extends EventEmitter {
|
|
|
1200
861
|
}
|
|
1201
862
|
this.disposed = true;
|
|
1202
863
|
this.enabled = false;
|
|
864
|
+
this.resetStreamingRenderThrottle();
|
|
1203
865
|
this.disableScrollRegion();
|
|
1204
866
|
this.disableBracketedPaste();
|
|
1205
867
|
this.buffer = '';
|
|
@@ -1305,22 +967,7 @@ export class TerminalInput extends EventEmitter {
|
|
|
1305
967
|
this.toggleEditMode();
|
|
1306
968
|
return true;
|
|
1307
969
|
}
|
|
1308
|
-
|
|
1309
|
-
if (this.findPlaceholderAt(this.cursor)) {
|
|
1310
|
-
this.togglePasteExpansion();
|
|
1311
|
-
}
|
|
1312
|
-
else {
|
|
1313
|
-
this.toggleThinking();
|
|
1314
|
-
}
|
|
1315
|
-
return true;
|
|
1316
|
-
case 'escape':
|
|
1317
|
-
// Esc: interrupt if streaming, otherwise clear buffer
|
|
1318
|
-
if (this.mode === 'streaming') {
|
|
1319
|
-
this.emit('interrupt');
|
|
1320
|
-
}
|
|
1321
|
-
else if (this.buffer.length > 0) {
|
|
1322
|
-
this.clear();
|
|
1323
|
-
}
|
|
970
|
+
this.insertText(' ');
|
|
1324
971
|
return true;
|
|
1325
972
|
}
|
|
1326
973
|
return false;
|
|
@@ -1338,7 +985,6 @@ export class TerminalInput extends EventEmitter {
|
|
|
1338
985
|
this.insertPlainText(chunk, insertPos);
|
|
1339
986
|
this.cursor = insertPos + chunk.length;
|
|
1340
987
|
this.emit('change', this.buffer);
|
|
1341
|
-
this.updateSuggestions();
|
|
1342
988
|
this.scheduleRender();
|
|
1343
989
|
}
|
|
1344
990
|
insertNewline() {
|
|
@@ -1363,7 +1009,6 @@ export class TerminalInput extends EventEmitter {
|
|
|
1363
1009
|
this.cursor = Math.max(0, this.cursor - 1);
|
|
1364
1010
|
}
|
|
1365
1011
|
this.emit('change', this.buffer);
|
|
1366
|
-
this.updateSuggestions();
|
|
1367
1012
|
this.scheduleRender();
|
|
1368
1013
|
}
|
|
1369
1014
|
deleteForward() {
|
|
@@ -1613,7 +1258,9 @@ export class TerminalInput extends EventEmitter {
|
|
|
1613
1258
|
if (available <= 0)
|
|
1614
1259
|
return;
|
|
1615
1260
|
const chunk = clean.slice(0, available);
|
|
1616
|
-
|
|
1261
|
+
const isMultiline = isMultilinePaste(chunk);
|
|
1262
|
+
const isShortMultiline = isMultiline && this.shouldInlineMultiline(chunk);
|
|
1263
|
+
if (isMultiline && !isShortMultiline) {
|
|
1617
1264
|
this.insertPastePlaceholder(chunk);
|
|
1618
1265
|
}
|
|
1619
1266
|
else {
|
|
@@ -1633,6 +1280,7 @@ export class TerminalInput extends EventEmitter {
|
|
|
1633
1280
|
return;
|
|
1634
1281
|
this.applyScrollRegion();
|
|
1635
1282
|
this.scrollRegionActive = true;
|
|
1283
|
+
this.forceRender();
|
|
1636
1284
|
}
|
|
1637
1285
|
disableScrollRegion() {
|
|
1638
1286
|
if (!this.scrollRegionActive)
|
|
@@ -1783,17 +1431,19 @@ export class TerminalInput extends EventEmitter {
|
|
|
1783
1431
|
this.shiftPlaceholders(position, text.length);
|
|
1784
1432
|
this.buffer = this.buffer.slice(0, position) + text + this.buffer.slice(position);
|
|
1785
1433
|
}
|
|
1434
|
+
shouldInlineMultiline(content) {
|
|
1435
|
+
const lines = content.split('\n').length;
|
|
1436
|
+
const maxInlineLines = 4;
|
|
1437
|
+
const maxInlineChars = 240;
|
|
1438
|
+
return lines <= maxInlineLines && content.length <= maxInlineChars;
|
|
1439
|
+
}
|
|
1786
1440
|
findPlaceholderAt(position) {
|
|
1787
1441
|
return this.pastePlaceholders.find((ph) => position >= ph.start && position < ph.end) ?? null;
|
|
1788
1442
|
}
|
|
1789
|
-
buildPlaceholder(
|
|
1443
|
+
buildPlaceholder(lineCount) {
|
|
1790
1444
|
const id = ++this.pasteCounter;
|
|
1791
|
-
const
|
|
1792
|
-
|
|
1793
|
-
const preview = summary.preview.length > 30
|
|
1794
|
-
? `${summary.preview.slice(0, 30)}...`
|
|
1795
|
-
: summary.preview;
|
|
1796
|
-
const placeholder = `[📋 #${id}${lang} ${summary.lineCount}L] "${preview}"`;
|
|
1445
|
+
const plural = lineCount === 1 ? '' : 's';
|
|
1446
|
+
const placeholder = `[Pasted text #${id} +${lineCount} line${plural}]`;
|
|
1797
1447
|
return { id, placeholder };
|
|
1798
1448
|
}
|
|
1799
1449
|
insertPastePlaceholder(content) {
|
|
@@ -1801,67 +1451,21 @@ export class TerminalInput extends EventEmitter {
|
|
|
1801
1451
|
if (available <= 0)
|
|
1802
1452
|
return;
|
|
1803
1453
|
const cleanContent = content.slice(0, available);
|
|
1804
|
-
const
|
|
1805
|
-
|
|
1806
|
-
if (summary.lineCount < 5) {
|
|
1807
|
-
const placeholder = this.findPlaceholderAt(this.cursor);
|
|
1808
|
-
const insertPos = placeholder && this.cursor > placeholder.start ? placeholder.end : this.cursor;
|
|
1809
|
-
this.insertPlainText(cleanContent, insertPos);
|
|
1810
|
-
this.cursor = insertPos + cleanContent.length;
|
|
1811
|
-
return;
|
|
1812
|
-
}
|
|
1813
|
-
const { id, placeholder } = this.buildPlaceholder(summary);
|
|
1454
|
+
const lineCount = cleanContent.split('\n').length;
|
|
1455
|
+
const { id, placeholder } = this.buildPlaceholder(lineCount);
|
|
1814
1456
|
const insertPos = this.cursor;
|
|
1815
1457
|
this.shiftPlaceholders(insertPos, placeholder.length);
|
|
1816
1458
|
this.pastePlaceholders.push({
|
|
1817
1459
|
id,
|
|
1818
1460
|
content: cleanContent,
|
|
1819
|
-
lineCount
|
|
1461
|
+
lineCount,
|
|
1820
1462
|
placeholder,
|
|
1821
1463
|
start: insertPos,
|
|
1822
1464
|
end: insertPos + placeholder.length,
|
|
1823
|
-
summary,
|
|
1824
|
-
expanded: false,
|
|
1825
1465
|
});
|
|
1826
1466
|
this.buffer = this.buffer.slice(0, insertPos) + placeholder + this.buffer.slice(insertPos);
|
|
1827
1467
|
this.cursor = insertPos + placeholder.length;
|
|
1828
1468
|
}
|
|
1829
|
-
/**
|
|
1830
|
-
* Toggle expansion of a paste placeholder at the current cursor position.
|
|
1831
|
-
* When expanded, shows first 3 and last 2 lines of the content.
|
|
1832
|
-
*/
|
|
1833
|
-
togglePasteExpansion() {
|
|
1834
|
-
const placeholder = this.findPlaceholderAt(this.cursor);
|
|
1835
|
-
if (!placeholder)
|
|
1836
|
-
return false;
|
|
1837
|
-
placeholder.expanded = !placeholder.expanded;
|
|
1838
|
-
// Update the placeholder text in buffer
|
|
1839
|
-
const newPlaceholder = placeholder.expanded
|
|
1840
|
-
? this.buildExpandedPlaceholder(placeholder)
|
|
1841
|
-
: this.buildPlaceholder(placeholder.summary).placeholder;
|
|
1842
|
-
const lengthDiff = newPlaceholder.length - placeholder.placeholder.length;
|
|
1843
|
-
// Update buffer
|
|
1844
|
-
this.buffer =
|
|
1845
|
-
this.buffer.slice(0, placeholder.start) +
|
|
1846
|
-
newPlaceholder +
|
|
1847
|
-
this.buffer.slice(placeholder.end);
|
|
1848
|
-
// Update placeholder tracking
|
|
1849
|
-
placeholder.placeholder = newPlaceholder;
|
|
1850
|
-
placeholder.end = placeholder.start + newPlaceholder.length;
|
|
1851
|
-
// Shift other placeholders
|
|
1852
|
-
this.shiftPlaceholders(placeholder.end, lengthDiff, placeholder.id);
|
|
1853
|
-
this.scheduleRender();
|
|
1854
|
-
return true;
|
|
1855
|
-
}
|
|
1856
|
-
buildExpandedPlaceholder(ph) {
|
|
1857
|
-
const lines = ph.content.split('\n');
|
|
1858
|
-
const firstLines = lines.slice(0, 3).map(l => l.slice(0, 60)).join('\n');
|
|
1859
|
-
const lastLines = lines.length > 5
|
|
1860
|
-
? '\n...\n' + lines.slice(-2).map(l => l.slice(0, 60)).join('\n')
|
|
1861
|
-
: '';
|
|
1862
|
-
const lang = ph.summary.language ? ` ${ph.summary.language.toUpperCase()}` : '';
|
|
1863
|
-
return `[📋 #${ph.id}${lang} ${ph.lineCount}L ▼]\n${firstLines}${lastLines}\n[/📋 #${ph.id}]`;
|
|
1864
|
-
}
|
|
1865
1469
|
deletePlaceholder(placeholder) {
|
|
1866
1470
|
const length = placeholder.end - placeholder.start;
|
|
1867
1471
|
this.buffer = this.buffer.slice(0, placeholder.start) + this.buffer.slice(placeholder.end);
|
|
@@ -1869,7 +1473,11 @@ export class TerminalInput extends EventEmitter {
|
|
|
1869
1473
|
this.shiftPlaceholders(placeholder.end, -length, placeholder.id);
|
|
1870
1474
|
this.cursor = placeholder.start;
|
|
1871
1475
|
}
|
|
1872
|
-
updateContextUsage(value) {
|
|
1476
|
+
updateContextUsage(value, autoCompactThreshold) {
|
|
1477
|
+
if (typeof autoCompactThreshold === 'number' && Number.isFinite(autoCompactThreshold)) {
|
|
1478
|
+
const boundedThreshold = Math.max(1, Math.min(100, Math.round(autoCompactThreshold)));
|
|
1479
|
+
this.contextAutoCompactThreshold = boundedThreshold;
|
|
1480
|
+
}
|
|
1873
1481
|
if (value === null || !Number.isFinite(value)) {
|
|
1874
1482
|
this.contextUsage = null;
|
|
1875
1483
|
}
|
|
@@ -1896,6 +1504,22 @@ export class TerminalInput extends EventEmitter {
|
|
|
1896
1504
|
const next = this.editMode === 'display-edits' ? 'ask-permission' : 'display-edits';
|
|
1897
1505
|
this.setEditMode(next);
|
|
1898
1506
|
}
|
|
1507
|
+
scheduleStreamingRender(delayMs) {
|
|
1508
|
+
if (this.streamingRenderTimer)
|
|
1509
|
+
return;
|
|
1510
|
+
const wait = Math.max(16, delayMs);
|
|
1511
|
+
this.streamingRenderTimer = setTimeout(() => {
|
|
1512
|
+
this.streamingRenderTimer = null;
|
|
1513
|
+
this.render();
|
|
1514
|
+
}, wait);
|
|
1515
|
+
}
|
|
1516
|
+
resetStreamingRenderThrottle() {
|
|
1517
|
+
if (this.streamingRenderTimer) {
|
|
1518
|
+
clearTimeout(this.streamingRenderTimer);
|
|
1519
|
+
this.streamingRenderTimer = null;
|
|
1520
|
+
}
|
|
1521
|
+
this.lastStreamingRender = 0;
|
|
1522
|
+
}
|
|
1899
1523
|
scheduleRender() {
|
|
1900
1524
|
if (!this.canRender())
|
|
1901
1525
|
return;
|