erosolar-cli 1.7.303 → 1.7.305
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 +3 -1
- 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 +16 -7
- package/dist/shell/interactiveShell.d.ts.map +1 -1
- package/dist/shell/interactiveShell.js +225 -163
- 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 +40 -9
- 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 +124 -126
- package/dist/shell/terminalInput.d.ts.map +1 -1
- package/dist/shell/terminalInput.js +548 -638
- package/dist/shell/terminalInput.js.map +1 -1
- package/dist/shell/terminalInputAdapter.d.ts +56 -20
- package/dist/shell/terminalInputAdapter.d.ts.map +1 -1
- package/dist/shell/terminalInputAdapter.js +66 -30
- 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 +24 -45
- package/dist/ui/display.d.ts.map +1 -1
- package/dist/ui/display.js +140 -259
- 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 +4 -4
- 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,15 +3,20 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Design principles:
|
|
5
5
|
* - Single source of truth for input state
|
|
6
|
+
* - Hybrid floating/scroll approach:
|
|
7
|
+
* - Initially: chat box floats below content
|
|
8
|
+
* - When terminal fills: scroll region activates, chat box pins to bottom
|
|
6
9
|
* - Native bracketed paste support (no heuristics)
|
|
7
10
|
* - Clean cursor model with render-time wrapping
|
|
8
11
|
* - State machine for different input modes
|
|
9
12
|
* - No readline dependency for display
|
|
10
13
|
*/
|
|
11
14
|
import { EventEmitter } from 'node:events';
|
|
12
|
-
import { isMultilinePaste
|
|
15
|
+
import { isMultilinePaste } from '../core/multilinePasteHandler.js';
|
|
13
16
|
import { writeLock } from '../ui/writeLock.js';
|
|
14
|
-
import {
|
|
17
|
+
import { renderDivider, renderStatusLine } from '../ui/unified/layout.js';
|
|
18
|
+
import { isStreamingMode } from '../ui/globalWriteLock.js';
|
|
19
|
+
import { formatThinking } from '../ui/toolDisplay.js';
|
|
15
20
|
// ANSI escape codes
|
|
16
21
|
const ESC = {
|
|
17
22
|
// Cursor control
|
|
@@ -21,9 +26,6 @@ const ESC = {
|
|
|
21
26
|
SHOW: '\x1b[?25h',
|
|
22
27
|
TO: (row, col) => `\x1b[${row};${col}H`,
|
|
23
28
|
TO_COL: (col) => `\x1b[${col}G`,
|
|
24
|
-
// Screen control
|
|
25
|
-
CLEAR_SCREEN: '\x1b[2J',
|
|
26
|
-
HOME: '\x1b[H',
|
|
27
29
|
// Line control
|
|
28
30
|
CLEAR_LINE: '\x1b[2K',
|
|
29
31
|
CLEAR_TO_END: '\x1b[0J',
|
|
@@ -69,48 +71,46 @@ export class TerminalInput extends EventEmitter {
|
|
|
69
71
|
statusMessage = null;
|
|
70
72
|
overrideStatusMessage = null; // Secondary status (warnings, etc.)
|
|
71
73
|
streamingLabel = null; // Streaming progress indicator
|
|
74
|
+
metaElapsedSeconds = null; // Optional elapsed time for header line
|
|
75
|
+
metaTokensUsed = null; // Optional token usage
|
|
76
|
+
metaTokenLimit = null; // Optional token window
|
|
77
|
+
metaThinkingMs = null; // Optional thinking duration
|
|
78
|
+
metaThinkingHasContent = false; // Whether collapsed thinking content exists
|
|
72
79
|
lastRenderContent = '';
|
|
73
80
|
lastRenderCursor = -1;
|
|
74
81
|
renderDirty = false;
|
|
75
82
|
isRendering = false;
|
|
76
|
-
flowModeRenderedLines = 0; // Track lines rendered for clearing
|
|
77
|
-
inputAreaStartRow = 0; // Track absolute row position of input area
|
|
78
|
-
contentEndRow = 0; // Row where content ends (for idle mode positioning)
|
|
79
|
-
scrollRegionActive = false; // Track if scroll region is enabled for streaming
|
|
80
|
-
// Command suggestions (Claude Code style auto-complete)
|
|
81
|
-
commandSuggestions = [];
|
|
82
|
-
filteredSuggestions = [];
|
|
83
|
-
selectedSuggestionIndex = 0;
|
|
84
|
-
showSuggestions = false;
|
|
85
83
|
// Lifecycle
|
|
86
84
|
disposed = false;
|
|
87
85
|
enabled = true;
|
|
88
86
|
contextUsage = null;
|
|
87
|
+
contextAutoCompactThreshold = 90;
|
|
88
|
+
// Track current content row (starts at top, moves down)
|
|
89
|
+
contentRow = 1;
|
|
90
|
+
// Track if scroll region is currently active
|
|
91
|
+
scrollRegionActive = false;
|
|
92
|
+
thinkingModeLabel = null;
|
|
89
93
|
editMode = 'display-edits';
|
|
90
94
|
verificationEnabled = true;
|
|
91
95
|
autoContinueEnabled = false;
|
|
92
96
|
verificationHotkey = 'alt+v';
|
|
93
97
|
autoContinueHotkey = 'alt+c';
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
// Streaming input area render timer (updates elapsed time display)
|
|
98
|
+
thinkingHotkey = '/thinking';
|
|
99
|
+
modelLabel = null;
|
|
100
|
+
providerLabel = null;
|
|
101
|
+
// Streaming render throttle
|
|
102
|
+
lastStreamingRender = 0;
|
|
103
|
+
streamingRenderInterval = 250; // ms between renders during streaming
|
|
101
104
|
streamingRenderTimer = null;
|
|
102
|
-
// Unified UI initialization flag
|
|
103
|
-
unifiedUIInitialized = false;
|
|
104
105
|
constructor(writeStream = process.stdout, config = {}) {
|
|
105
106
|
super();
|
|
106
107
|
this.out = writeStream;
|
|
107
|
-
// Use schema defaults for configuration consistency
|
|
108
108
|
this.config = {
|
|
109
|
-
maxLines: config.maxLines ??
|
|
110
|
-
maxLength: config.maxLength ??
|
|
109
|
+
maxLines: config.maxLines ?? 1000,
|
|
110
|
+
maxLength: config.maxLength ?? 10000,
|
|
111
111
|
maxQueueSize: config.maxQueueSize ?? 100,
|
|
112
|
-
promptChar: config.promptChar ??
|
|
113
|
-
continuationChar: config.continuationChar ??
|
|
112
|
+
promptChar: config.promptChar ?? '> ',
|
|
113
|
+
continuationChar: config.continuationChar ?? '│ ',
|
|
114
114
|
};
|
|
115
115
|
}
|
|
116
116
|
// ===========================================================================
|
|
@@ -189,429 +189,36 @@ export class TerminalInput extends EventEmitter {
|
|
|
189
189
|
if (handled)
|
|
190
190
|
return;
|
|
191
191
|
}
|
|
192
|
-
// Handle '?' for help hint (if buffer is empty)
|
|
193
|
-
if (str === '?' && this.buffer.length === 0) {
|
|
194
|
-
this.emit('showHelp');
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
192
|
// Insert printable characters
|
|
198
193
|
if (str && !key?.ctrl && !key?.meta) {
|
|
199
194
|
this.insertText(str);
|
|
200
195
|
}
|
|
201
196
|
}
|
|
202
|
-
// Banner content to write on init (set via setBannerContent before initializeUnifiedUI)
|
|
203
|
-
bannerContent = null;
|
|
204
|
-
/**
|
|
205
|
-
* Set banner content to be written when unified UI initializes.
|
|
206
|
-
*/
|
|
207
|
-
setBannerContent(content) {
|
|
208
|
-
this.bannerContent = content;
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Initialize the unified UI system.
|
|
212
|
-
*
|
|
213
|
-
* Layout:
|
|
214
|
-
* 1. Clear screen
|
|
215
|
-
* 2. Write banner at top
|
|
216
|
-
* 3. Track content end position
|
|
217
|
-
* 4. Render floating input area below banner
|
|
218
|
-
*/
|
|
219
|
-
initializeUnifiedUI() {
|
|
220
|
-
if (this.unifiedUIInitialized) {
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
// Hide cursor during setup
|
|
224
|
-
this.write(ESC.HIDE);
|
|
225
|
-
// Clear screen and go home
|
|
226
|
-
this.write(ESC.HOME);
|
|
227
|
-
this.write(ESC.CLEAR_SCREEN);
|
|
228
|
-
// Write banner at top and track where it ends
|
|
229
|
-
let bannerLines = 0;
|
|
230
|
-
if (this.bannerContent) {
|
|
231
|
-
const lines = this.bannerContent.split('\n');
|
|
232
|
-
bannerLines = lines.length + 2; // +2 for the trailing \n\n
|
|
233
|
-
process.stdout.write(this.bannerContent + '\n\n');
|
|
234
|
-
}
|
|
235
|
-
// Set content end row so input renders right after banner
|
|
236
|
-
this.contentEndRow = bannerLines > 0 ? bannerLines : 1;
|
|
237
|
-
// Mark initialized
|
|
238
|
-
this.unifiedUIInitialized = true;
|
|
239
|
-
// Render floating input area below the banner
|
|
240
|
-
this.renderFloatingInputArea();
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Clear the input area at its tracked position.
|
|
244
|
-
* Returns true if something was cleared.
|
|
245
|
-
*/
|
|
246
|
-
clearInputArea() {
|
|
247
|
-
if (this.inputAreaStartRow > 0 && this.flowModeRenderedLines > 0) {
|
|
248
|
-
for (let i = 0; i < this.flowModeRenderedLines; i++) {
|
|
249
|
-
this.write(ESC.TO(this.inputAreaStartRow + i, 1));
|
|
250
|
-
this.write(ESC.CLEAR_LINE);
|
|
251
|
-
}
|
|
252
|
-
return true;
|
|
253
|
-
}
|
|
254
|
-
return false;
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* Reset input area tracking state.
|
|
258
|
-
*/
|
|
259
|
-
resetInputAreaTracking() {
|
|
260
|
-
this.inputAreaStartRow = 0;
|
|
261
|
-
this.flowModeRenderedLines = 0;
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Enable scroll region - content scrolls above, input area protected below.
|
|
265
|
-
* The scroll region ends just above where the chat box will be rendered.
|
|
266
|
-
*/
|
|
267
|
-
enableScrollRegion() {
|
|
268
|
-
const { rows } = this.getSize();
|
|
269
|
-
const linesNeeded = 5 + (this.modelInfo ? 1 : 0);
|
|
270
|
-
// Calculate where chat box will be (floating below content)
|
|
271
|
-
let chatBoxStartRow;
|
|
272
|
-
if (this.contentEndRow > 0) {
|
|
273
|
-
chatBoxStartRow = Math.min(this.contentEndRow + 1, rows - linesNeeded + 1);
|
|
274
|
-
}
|
|
275
|
-
else {
|
|
276
|
-
// Default to terminal bottom if no content yet
|
|
277
|
-
chatBoxStartRow = rows - linesNeeded + 1;
|
|
278
|
-
}
|
|
279
|
-
chatBoxStartRow = Math.max(1, chatBoxStartRow);
|
|
280
|
-
// Scroll region ends just before the chat box
|
|
281
|
-
const scrollBottom = Math.max(1, chatBoxStartRow - 1);
|
|
282
|
-
this.write(ESC.SET_SCROLL(1, scrollBottom));
|
|
283
|
-
this.scrollRegionActive = true;
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* Disable scroll region - return to normal terminal mode.
|
|
287
|
-
*/
|
|
288
|
-
disableScrollRegion() {
|
|
289
|
-
if (!this.scrollRegionActive)
|
|
290
|
-
return;
|
|
291
|
-
this.write(ESC.RESET_SCROLL);
|
|
292
|
-
this.scrollRegionActive = false;
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* Render input area floating below content.
|
|
296
|
-
* During streaming, positions based on contentEndRow (persistent bottom floating).
|
|
297
|
-
*/
|
|
298
|
-
renderInputAreaAtBottom() {
|
|
299
|
-
const { rows, cols } = this.getSize();
|
|
300
|
-
const divider = '─'.repeat(cols - 1);
|
|
301
|
-
const { dim: DIM, reset: R } = UI_COLORS;
|
|
302
|
-
// Calculate lines needed
|
|
303
|
-
const linesNeeded = 5 + (this.modelInfo ? 1 : 0);
|
|
304
|
-
// Calculate starting row: float below content, but don't go past terminal bounds
|
|
305
|
-
let startRow;
|
|
306
|
-
if (this.contentEndRow > 0) {
|
|
307
|
-
// Float below content
|
|
308
|
-
startRow = this.contentEndRow + 1;
|
|
309
|
-
}
|
|
310
|
-
else {
|
|
311
|
-
// Default to terminal bottom if no content tracked yet
|
|
312
|
-
startRow = rows - linesNeeded + 1;
|
|
313
|
-
}
|
|
314
|
-
// Ensure we don't exceed terminal bounds
|
|
315
|
-
startRow = Math.min(startRow, rows - linesNeeded + 1);
|
|
316
|
-
startRow = Math.max(1, startRow);
|
|
317
|
-
// Save cursor and hide during render
|
|
318
|
-
this.write(ESC.SAVE);
|
|
319
|
-
this.write(ESC.HIDE);
|
|
320
|
-
let currentRow = startRow;
|
|
321
|
-
// Clear input area lines
|
|
322
|
-
for (let r = startRow; r <= rows; r++) {
|
|
323
|
-
this.write(ESC.TO(r, 1));
|
|
324
|
-
this.write(ESC.CLEAR_LINE);
|
|
325
|
-
}
|
|
326
|
-
// Status bar (shows streaming status)
|
|
327
|
-
this.write(ESC.TO(currentRow, 1));
|
|
328
|
-
this.write(this.buildStatusBar(cols));
|
|
329
|
-
currentRow++;
|
|
330
|
-
// Model info line (if set)
|
|
331
|
-
if (this.modelInfo) {
|
|
332
|
-
this.write(ESC.TO(currentRow, 1));
|
|
333
|
-
let modelLine = `${DIM}${this.modelInfo}${R}`;
|
|
334
|
-
if (this.contextUsage !== null) {
|
|
335
|
-
const rem = Math.max(0, 100 - this.contextUsage);
|
|
336
|
-
if (rem < 10)
|
|
337
|
-
modelLine += ` ${UI_COLORS.red}⚠ ctx: ${rem}%${R}`;
|
|
338
|
-
else if (rem < 25)
|
|
339
|
-
modelLine += ` ${UI_COLORS.yellow}! ctx: ${rem}%${R}`;
|
|
340
|
-
else
|
|
341
|
-
modelLine += ` ${DIM}· ctx: ${rem}%${R}`;
|
|
342
|
-
}
|
|
343
|
-
this.write(modelLine);
|
|
344
|
-
currentRow++;
|
|
345
|
-
}
|
|
346
|
-
// Top divider
|
|
347
|
-
this.write(ESC.TO(currentRow, 1));
|
|
348
|
-
this.write(divider);
|
|
349
|
-
currentRow++;
|
|
350
|
-
// Input line with prompt and buffer content
|
|
351
|
-
const { lines } = this.wrapBuffer(cols - 4);
|
|
352
|
-
const displayLine = lines[0] ?? '';
|
|
353
|
-
this.write(ESC.TO(currentRow, 1));
|
|
354
|
-
this.write(ESC.BG_DARK + ESC.DIM + this.config.promptChar + ESC.RESET);
|
|
355
|
-
this.write(ESC.BG_DARK + displayLine);
|
|
356
|
-
const padding = Math.max(0, cols - this.config.promptChar.length - displayLine.length - 1);
|
|
357
|
-
if (padding > 0)
|
|
358
|
-
this.write(' '.repeat(padding));
|
|
359
|
-
this.write(ESC.RESET);
|
|
360
|
-
currentRow++;
|
|
361
|
-
// Bottom divider
|
|
362
|
-
this.write(ESC.TO(currentRow, 1));
|
|
363
|
-
this.write(divider);
|
|
364
|
-
currentRow++;
|
|
365
|
-
// Mode controls
|
|
366
|
-
this.write(ESC.TO(currentRow, 1));
|
|
367
|
-
this.write(this.buildModeControls(cols));
|
|
368
|
-
// Track position
|
|
369
|
-
this.inputAreaStartRow = startRow;
|
|
370
|
-
this.flowModeRenderedLines = currentRow - startRow + 1;
|
|
371
|
-
// Restore cursor position (back to scroll region if streaming)
|
|
372
|
-
this.write(ESC.RESTORE);
|
|
373
|
-
this.write(ESC.SHOW);
|
|
374
|
-
// Update tracking
|
|
375
|
-
this.lastRenderContent = this.buffer;
|
|
376
|
-
this.lastRenderCursor = this.cursor;
|
|
377
|
-
}
|
|
378
|
-
/**
|
|
379
|
-
* Render floating input area below current content.
|
|
380
|
-
* This is "bottom floating" - follows content, not pinned to terminal bottom.
|
|
381
|
-
* Uses absolute positioning to prevent duplicates.
|
|
382
|
-
*/
|
|
383
|
-
renderFloatingInputArea() {
|
|
384
|
-
const { rows, cols } = this.getSize();
|
|
385
|
-
const divider = '─'.repeat(cols - 1);
|
|
386
|
-
const { dim: DIM, reset: R } = UI_COLORS;
|
|
387
|
-
// Calculate lines needed for input area
|
|
388
|
-
const linesNeeded = 5 + (this.modelInfo ? 1 : 0);
|
|
389
|
-
// FIRST: Clear any previously rendered input area
|
|
390
|
-
this.clearInputArea();
|
|
391
|
-
// Hide cursor during render
|
|
392
|
-
this.write(ESC.HIDE);
|
|
393
|
-
// Calculate where to render: after current content
|
|
394
|
-
// Use contentEndRow if set, otherwise estimate from terminal bottom
|
|
395
|
-
let startRow;
|
|
396
|
-
if (this.contentEndRow > 0) {
|
|
397
|
-
startRow = this.contentEndRow + 1;
|
|
398
|
-
}
|
|
399
|
-
else {
|
|
400
|
-
// Render near bottom, leaving space for input area
|
|
401
|
-
startRow = Math.max(1, rows - linesNeeded);
|
|
402
|
-
}
|
|
403
|
-
// Ensure we don't go past terminal bounds
|
|
404
|
-
startRow = Math.min(startRow, rows - linesNeeded + 1);
|
|
405
|
-
startRow = Math.max(1, startRow);
|
|
406
|
-
// Track this position
|
|
407
|
-
this.inputAreaStartRow = startRow;
|
|
408
|
-
let currentRow = startRow;
|
|
409
|
-
// Status bar
|
|
410
|
-
this.write(ESC.TO(currentRow, 1));
|
|
411
|
-
this.write(this.buildStatusBar(cols));
|
|
412
|
-
currentRow++;
|
|
413
|
-
// Model info line (if set)
|
|
414
|
-
if (this.modelInfo) {
|
|
415
|
-
this.write(ESC.TO(currentRow, 1));
|
|
416
|
-
let modelLine = `${DIM}${this.modelInfo}${R}`;
|
|
417
|
-
if (this.contextUsage !== null) {
|
|
418
|
-
const rem = Math.max(0, 100 - this.contextUsage);
|
|
419
|
-
if (rem < 10)
|
|
420
|
-
modelLine += ` ${UI_COLORS.red}⚠ ctx: ${rem}%${R}`;
|
|
421
|
-
else if (rem < 25)
|
|
422
|
-
modelLine += ` ${UI_COLORS.yellow}! ctx: ${rem}%${R}`;
|
|
423
|
-
else
|
|
424
|
-
modelLine += ` ${DIM}· ctx: ${rem}%${R}`;
|
|
425
|
-
}
|
|
426
|
-
this.write(modelLine);
|
|
427
|
-
currentRow++;
|
|
428
|
-
}
|
|
429
|
-
// Top divider
|
|
430
|
-
this.write(ESC.TO(currentRow, 1));
|
|
431
|
-
this.write(divider);
|
|
432
|
-
currentRow++;
|
|
433
|
-
// Input line with prompt and buffer content
|
|
434
|
-
const { lines, cursorCol } = this.wrapBuffer(cols - 4);
|
|
435
|
-
const displayLine = lines[0] ?? '';
|
|
436
|
-
const inputRow = currentRow;
|
|
437
|
-
this.write(ESC.TO(currentRow, 1));
|
|
438
|
-
this.write(ESC.BG_DARK + ESC.DIM + this.config.promptChar + ESC.RESET);
|
|
439
|
-
this.write(ESC.BG_DARK + displayLine);
|
|
440
|
-
const padding = Math.max(0, cols - this.config.promptChar.length - displayLine.length - 1);
|
|
441
|
-
if (padding > 0)
|
|
442
|
-
this.write(' '.repeat(padding));
|
|
443
|
-
this.write(ESC.RESET);
|
|
444
|
-
currentRow++;
|
|
445
|
-
// Bottom divider
|
|
446
|
-
this.write(ESC.TO(currentRow, 1));
|
|
447
|
-
this.write(divider);
|
|
448
|
-
currentRow++;
|
|
449
|
-
// Mode controls
|
|
450
|
-
this.write(ESC.TO(currentRow, 1));
|
|
451
|
-
this.write(this.buildModeControls(cols));
|
|
452
|
-
// Track lines rendered
|
|
453
|
-
this.flowModeRenderedLines = currentRow - startRow + 1;
|
|
454
|
-
// Position cursor in input line for typing
|
|
455
|
-
this.write(ESC.TO(inputRow, this.config.promptChar.length + 1 + cursorCol));
|
|
456
|
-
// Show cursor
|
|
457
|
-
this.write(ESC.SHOW);
|
|
458
|
-
// Update tracking
|
|
459
|
-
this.lastRenderContent = this.buffer;
|
|
460
|
-
this.lastRenderCursor = this.cursor;
|
|
461
|
-
}
|
|
462
197
|
/**
|
|
463
198
|
* Set the input mode
|
|
464
199
|
*
|
|
465
|
-
*
|
|
466
|
-
* After streaming: chat box floats below content (no scroll region)
|
|
200
|
+
* Content flows naturally - no scroll region pinning.
|
|
467
201
|
*/
|
|
468
202
|
setMode(mode) {
|
|
469
203
|
const prevMode = this.mode;
|
|
470
204
|
this.mode = mode;
|
|
471
205
|
if (mode === 'streaming' && prevMode !== 'streaming') {
|
|
472
|
-
|
|
473
|
-
this.streamingStartTime = Date.now();
|
|
474
|
-
// Ensure unified UI is initialized
|
|
475
|
-
if (!this.unifiedUIInitialized) {
|
|
476
|
-
this.initializeUnifiedUI();
|
|
477
|
-
}
|
|
478
|
-
// Clear any floating input area first
|
|
479
|
-
this.clearInputArea();
|
|
480
|
-
this.resetInputAreaTracking();
|
|
481
|
-
// Enable scroll region - ends just before where chat box will be
|
|
482
|
-
this.enableScrollRegion();
|
|
483
|
-
// Render chat box floating below content
|
|
484
|
-
this.renderInputAreaAtBottom();
|
|
485
|
-
// Position cursor at content end (or start of scroll region) for streaming
|
|
486
|
-
const cursorRow = this.contentEndRow > 0 ? this.contentEndRow : 1;
|
|
487
|
-
this.write(ESC.TO(cursorRow, 1));
|
|
206
|
+
this.resetStreamingRenderThrottle();
|
|
488
207
|
this.renderDirty = true;
|
|
208
|
+
this.render();
|
|
489
209
|
}
|
|
490
210
|
else if (mode !== 'streaming' && prevMode === 'streaming') {
|
|
491
|
-
//
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
this.streamingRenderTimer = null;
|
|
495
|
-
}
|
|
496
|
-
// Reset streaming time
|
|
497
|
-
this.streamingStartTime = null;
|
|
498
|
-
// Disable scroll region
|
|
499
|
-
this.disableScrollRegion();
|
|
500
|
-
// Clear bottom input area
|
|
501
|
-
this.clearInputArea();
|
|
502
|
-
this.resetInputAreaTracking();
|
|
503
|
-
// Render floating input area below content
|
|
504
|
-
writeLock.withLock(() => {
|
|
505
|
-
this.renderFloatingInputArea();
|
|
506
|
-
}, 'terminalInput.streamingEnd');
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
/**
|
|
510
|
-
* Set the row where content ends (for idle mode positioning).
|
|
511
|
-
* Input area will render starting from this row + 1.
|
|
512
|
-
*/
|
|
513
|
-
setContentEndRow(row) {
|
|
514
|
-
const prevRow = this.contentEndRow;
|
|
515
|
-
this.contentEndRow = Math.max(0, row);
|
|
516
|
-
// During streaming, dynamically adjust scroll region and chat box position
|
|
517
|
-
if (this.mode === 'streaming' && this.scrollRegionActive && this.contentEndRow !== prevRow) {
|
|
518
|
-
// Re-enable scroll region with new boundaries
|
|
519
|
-
this.enableScrollRegion();
|
|
520
|
-
// Re-render chat box at new position (floating below content)
|
|
521
|
-
this.renderInputAreaAtBottom();
|
|
522
|
-
}
|
|
523
|
-
else {
|
|
524
|
-
this.renderDirty = true;
|
|
525
|
-
this.scheduleRender();
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
/**
|
|
529
|
-
* Set available slash commands for auto-complete suggestions.
|
|
530
|
-
*/
|
|
531
|
-
setCommands(commands) {
|
|
532
|
-
this.commandSuggestions = commands;
|
|
533
|
-
this.updateSuggestions();
|
|
534
|
-
}
|
|
535
|
-
/**
|
|
536
|
-
* Update filtered suggestions based on current input.
|
|
537
|
-
*/
|
|
538
|
-
updateSuggestions() {
|
|
539
|
-
const input = this.buffer.trim();
|
|
540
|
-
// Only show suggestions when input starts with "/"
|
|
541
|
-
if (!input.startsWith('/')) {
|
|
542
|
-
this.showSuggestions = false;
|
|
543
|
-
this.filteredSuggestions = [];
|
|
544
|
-
this.selectedSuggestionIndex = 0;
|
|
545
|
-
return;
|
|
546
|
-
}
|
|
547
|
-
const query = input.toLowerCase();
|
|
548
|
-
this.filteredSuggestions = this.commandSuggestions.filter(cmd => cmd.command.toLowerCase().startsWith(query) ||
|
|
549
|
-
cmd.command.toLowerCase().includes(query.slice(1)));
|
|
550
|
-
// Show suggestions if we have matches
|
|
551
|
-
this.showSuggestions = this.filteredSuggestions.length > 0;
|
|
552
|
-
// Keep selection in bounds
|
|
553
|
-
if (this.selectedSuggestionIndex >= this.filteredSuggestions.length) {
|
|
554
|
-
this.selectedSuggestionIndex = Math.max(0, this.filteredSuggestions.length - 1);
|
|
211
|
+
// Streaming ended - render the input area
|
|
212
|
+
this.resetStreamingRenderThrottle();
|
|
213
|
+
this.forceRender();
|
|
555
214
|
}
|
|
556
215
|
}
|
|
557
216
|
/**
|
|
558
|
-
*
|
|
559
|
-
|
|
560
|
-
selectNextSuggestion() {
|
|
561
|
-
if (!this.showSuggestions || this.filteredSuggestions.length === 0)
|
|
562
|
-
return;
|
|
563
|
-
this.selectedSuggestionIndex = (this.selectedSuggestionIndex + 1) % this.filteredSuggestions.length;
|
|
564
|
-
this.renderDirty = true;
|
|
565
|
-
this.scheduleRender();
|
|
566
|
-
}
|
|
567
|
-
/**
|
|
568
|
-
* Select previous suggestion (arrow up / shift+tab).
|
|
569
|
-
*/
|
|
570
|
-
selectPrevSuggestion() {
|
|
571
|
-
if (!this.showSuggestions || this.filteredSuggestions.length === 0)
|
|
572
|
-
return;
|
|
573
|
-
this.selectedSuggestionIndex = this.selectedSuggestionIndex === 0
|
|
574
|
-
? this.filteredSuggestions.length - 1
|
|
575
|
-
: this.selectedSuggestionIndex - 1;
|
|
576
|
-
this.renderDirty = true;
|
|
577
|
-
this.scheduleRender();
|
|
578
|
-
}
|
|
579
|
-
/**
|
|
580
|
-
* Accept current suggestion and insert into buffer.
|
|
581
|
-
*/
|
|
582
|
-
acceptSuggestion() {
|
|
583
|
-
if (!this.showSuggestions || this.filteredSuggestions.length === 0)
|
|
584
|
-
return false;
|
|
585
|
-
const selected = this.filteredSuggestions[this.selectedSuggestionIndex];
|
|
586
|
-
if (!selected)
|
|
587
|
-
return false;
|
|
588
|
-
// Replace buffer with selected command
|
|
589
|
-
this.buffer = selected.command + ' ';
|
|
590
|
-
this.cursor = this.buffer.length;
|
|
591
|
-
this.showSuggestions = false;
|
|
592
|
-
this.renderDirty = true;
|
|
593
|
-
this.scheduleRender();
|
|
594
|
-
return true;
|
|
595
|
-
}
|
|
596
|
-
/**
|
|
597
|
-
* Check if suggestions are visible.
|
|
217
|
+
* Legacy method - no longer used (content flows naturally).
|
|
218
|
+
* @deprecated Use setContentRow instead
|
|
598
219
|
*/
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
}
|
|
602
|
-
/**
|
|
603
|
-
* Toggle thinking/reasoning mode
|
|
604
|
-
*/
|
|
605
|
-
toggleThinking() {
|
|
606
|
-
this.thinkingEnabled = !this.thinkingEnabled;
|
|
607
|
-
this.emit('thinkingToggle', this.thinkingEnabled);
|
|
608
|
-
this.scheduleRender();
|
|
609
|
-
}
|
|
610
|
-
/**
|
|
611
|
-
* Get thinking enabled state
|
|
612
|
-
*/
|
|
613
|
-
isThinkingEnabled() {
|
|
614
|
-
return this.thinkingEnabled;
|
|
220
|
+
setPinnedHeaderLines(_count) {
|
|
221
|
+
// No-op: scroll region pinning removed
|
|
615
222
|
}
|
|
616
223
|
/**
|
|
617
224
|
* Get current mode
|
|
@@ -644,17 +251,14 @@ export class TerminalInput extends EventEmitter {
|
|
|
644
251
|
}
|
|
645
252
|
/**
|
|
646
253
|
* Clear the buffer
|
|
647
|
-
* @param skipRender - If true, don't trigger a re-render (used during submit flow)
|
|
648
254
|
*/
|
|
649
|
-
clear(
|
|
255
|
+
clear() {
|
|
650
256
|
this.buffer = '';
|
|
651
257
|
this.cursor = 0;
|
|
652
258
|
this.historyIndex = -1;
|
|
653
259
|
this.tempInput = '';
|
|
654
260
|
this.pastePlaceholders = [];
|
|
655
|
-
|
|
656
|
-
this.scheduleRender();
|
|
657
|
-
}
|
|
261
|
+
this.scheduleRender();
|
|
658
262
|
}
|
|
659
263
|
/**
|
|
660
264
|
* Get queued inputs
|
|
@@ -725,6 +329,37 @@ export class TerminalInput extends EventEmitter {
|
|
|
725
329
|
this.streamingLabel = next;
|
|
726
330
|
this.scheduleRender();
|
|
727
331
|
}
|
|
332
|
+
/**
|
|
333
|
+
* Surface meta status just above the divider (e.g., elapsed time or token usage).
|
|
334
|
+
*/
|
|
335
|
+
setMetaStatus(meta) {
|
|
336
|
+
const nextElapsed = typeof meta.elapsedSeconds === 'number' && Number.isFinite(meta.elapsedSeconds) && meta.elapsedSeconds >= 0
|
|
337
|
+
? Math.floor(meta.elapsedSeconds)
|
|
338
|
+
: null;
|
|
339
|
+
const nextTokens = typeof meta.tokensUsed === 'number' && Number.isFinite(meta.tokensUsed) && meta.tokensUsed >= 0
|
|
340
|
+
? Math.floor(meta.tokensUsed)
|
|
341
|
+
: null;
|
|
342
|
+
const nextLimit = typeof meta.tokenLimit === 'number' && Number.isFinite(meta.tokenLimit) && meta.tokenLimit > 0
|
|
343
|
+
? Math.floor(meta.tokenLimit)
|
|
344
|
+
: null;
|
|
345
|
+
const nextThinking = typeof meta.thinkingMs === 'number' && Number.isFinite(meta.thinkingMs) && meta.thinkingMs >= 0
|
|
346
|
+
? Math.floor(meta.thinkingMs)
|
|
347
|
+
: null;
|
|
348
|
+
const nextThinkingHasContent = !!meta.thinkingHasContent;
|
|
349
|
+
if (this.metaElapsedSeconds === nextElapsed &&
|
|
350
|
+
this.metaTokensUsed === nextTokens &&
|
|
351
|
+
this.metaTokenLimit === nextLimit &&
|
|
352
|
+
this.metaThinkingMs === nextThinking &&
|
|
353
|
+
this.metaThinkingHasContent === nextThinkingHasContent) {
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
this.metaElapsedSeconds = nextElapsed;
|
|
357
|
+
this.metaTokensUsed = nextTokens;
|
|
358
|
+
this.metaTokenLimit = nextLimit;
|
|
359
|
+
this.metaThinkingMs = nextThinking;
|
|
360
|
+
this.metaThinkingHasContent = nextThinkingHasContent;
|
|
361
|
+
this.scheduleRender();
|
|
362
|
+
}
|
|
728
363
|
/**
|
|
729
364
|
* Keep mode toggles (verification/auto-continue) visible in the control bar.
|
|
730
365
|
* Hotkey labels remain stable so the bar looks the same before/during streaming.
|
|
@@ -734,26 +369,22 @@ export class TerminalInput extends EventEmitter {
|
|
|
734
369
|
const nextAutoContinue = !!options.autoContinueEnabled;
|
|
735
370
|
const nextVerifyHotkey = options.verificationHotkey ?? this.verificationHotkey;
|
|
736
371
|
const nextAutoHotkey = options.autoContinueHotkey ?? this.autoContinueHotkey;
|
|
372
|
+
const nextThinkingHotkey = options.thinkingHotkey ?? this.thinkingHotkey;
|
|
373
|
+
const nextThinkingLabel = options.thinkingModeLabel === undefined ? this.thinkingModeLabel : (options.thinkingModeLabel || null);
|
|
737
374
|
if (this.verificationEnabled === nextVerification &&
|
|
738
375
|
this.autoContinueEnabled === nextAutoContinue &&
|
|
739
376
|
this.verificationHotkey === nextVerifyHotkey &&
|
|
740
|
-
this.autoContinueHotkey === nextAutoHotkey
|
|
377
|
+
this.autoContinueHotkey === nextAutoHotkey &&
|
|
378
|
+
this.thinkingHotkey === nextThinkingHotkey &&
|
|
379
|
+
this.thinkingModeLabel === nextThinkingLabel) {
|
|
741
380
|
return;
|
|
742
381
|
}
|
|
743
382
|
this.verificationEnabled = nextVerification;
|
|
744
383
|
this.autoContinueEnabled = nextAutoContinue;
|
|
745
384
|
this.verificationHotkey = nextVerifyHotkey;
|
|
746
385
|
this.autoContinueHotkey = nextAutoHotkey;
|
|
747
|
-
this.
|
|
748
|
-
|
|
749
|
-
/**
|
|
750
|
-
* Set the model info string (e.g., "OpenAI · gpt-4")
|
|
751
|
-
* This is displayed persistently above the input area.
|
|
752
|
-
*/
|
|
753
|
-
setModelInfo(info) {
|
|
754
|
-
if (this.modelInfo === info)
|
|
755
|
-
return;
|
|
756
|
-
this.modelInfo = info;
|
|
386
|
+
this.thinkingHotkey = nextThinkingHotkey;
|
|
387
|
+
this.thinkingModeLabel = nextThinkingLabel;
|
|
757
388
|
this.scheduleRender();
|
|
758
389
|
}
|
|
759
390
|
/**
|
|
@@ -766,38 +397,154 @@ export class TerminalInput extends EventEmitter {
|
|
|
766
397
|
this.scheduleRender();
|
|
767
398
|
}
|
|
768
399
|
/**
|
|
769
|
-
*
|
|
770
|
-
|
|
771
|
-
|
|
400
|
+
* Surface model/provider context in the controls bar.
|
|
401
|
+
*/
|
|
402
|
+
setModelContext(options) {
|
|
403
|
+
const nextModel = options.model?.trim() || null;
|
|
404
|
+
const nextProvider = options.provider?.trim() || null;
|
|
405
|
+
if (this.modelLabel === nextModel && this.providerLabel === nextProvider) {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
this.modelLabel = nextModel;
|
|
409
|
+
this.providerLabel = nextProvider;
|
|
410
|
+
this.scheduleRender();
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Render the floating input area at contentRow.
|
|
414
|
+
*
|
|
415
|
+
* The chat box "floats" - it renders right below the last streamed content.
|
|
416
|
+
* As content is added, contentRow advances, and the chat box moves down.
|
|
417
|
+
* No scroll regions - pure floating behavior.
|
|
772
418
|
*/
|
|
773
419
|
render() {
|
|
774
420
|
if (!this.canRender())
|
|
775
421
|
return;
|
|
776
422
|
if (this.isRendering)
|
|
777
423
|
return;
|
|
424
|
+
const streamingActive = this.mode === 'streaming' || isStreamingMode();
|
|
425
|
+
// During streaming, throttle re-renders
|
|
426
|
+
if (streamingActive && this.lastStreamingRender > 0) {
|
|
427
|
+
const elapsed = Date.now() - this.lastStreamingRender;
|
|
428
|
+
const waitMs = Math.max(0, this.streamingRenderInterval - elapsed);
|
|
429
|
+
if (waitMs > 0) {
|
|
430
|
+
this.renderDirty = true;
|
|
431
|
+
this.scheduleStreamingRender(waitMs);
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
778
435
|
const shouldSkip = !this.renderDirty &&
|
|
779
436
|
this.buffer === this.lastRenderContent &&
|
|
780
437
|
this.cursor === this.lastRenderCursor;
|
|
781
438
|
this.renderDirty = false;
|
|
782
|
-
// Skip if nothing changed (unless explicitly forced)
|
|
783
439
|
if (shouldSkip) {
|
|
784
440
|
return;
|
|
785
441
|
}
|
|
786
|
-
// If write lock is held, defer render
|
|
787
442
|
if (writeLock.isLocked()) {
|
|
788
443
|
writeLock.safeWrite(() => this.render());
|
|
789
444
|
return;
|
|
790
445
|
}
|
|
446
|
+
this.renderFloatingInputArea();
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Core floating input area renderer.
|
|
450
|
+
* Chat box always floats at contentRow (below streamed content).
|
|
451
|
+
* This creates "persistent bottom floating" behavior.
|
|
452
|
+
*/
|
|
453
|
+
renderFloatingInputArea() {
|
|
454
|
+
const { rows, cols } = this.getSize();
|
|
455
|
+
const maxWidth = Math.max(8, cols - 4);
|
|
456
|
+
const streamingActive = this.mode === 'streaming' || isStreamingMode();
|
|
457
|
+
// Wrap buffer into display lines
|
|
458
|
+
const { lines, cursorLine, cursorCol } = this.wrapBuffer(maxWidth);
|
|
459
|
+
const maxVisible = Math.max(1, Math.min(this.config.maxLines, rows - 3));
|
|
460
|
+
const displayLines = Math.min(lines.length, maxVisible);
|
|
461
|
+
const metaLines = this.buildMetaLines(cols - 2);
|
|
462
|
+
// Calculate display window (keep cursor visible)
|
|
463
|
+
let startLine = 0;
|
|
464
|
+
if (lines.length > displayLines) {
|
|
465
|
+
startLine = Math.max(0, cursorLine - displayLines + 1);
|
|
466
|
+
startLine = Math.min(startLine, lines.length - displayLines);
|
|
467
|
+
}
|
|
468
|
+
const visibleLines = lines.slice(startLine, startLine + displayLines);
|
|
469
|
+
const adjustedCursorLine = cursorLine - startLine;
|
|
470
|
+
// Chat box height
|
|
471
|
+
const chatBoxHeight = metaLines.length + 1 + displayLines + 1;
|
|
472
|
+
// Dynamic floating: chat box is always at contentRow + 1 (below scroll region)
|
|
473
|
+
// When terminal fills, contentRow is capped, so chat box pins at bottom
|
|
474
|
+
const chatBoxStartRow = Math.min(this.contentRow + 1, rows - chatBoxHeight + 1);
|
|
475
|
+
writeLock.lock('terminalInput.renderFloating');
|
|
791
476
|
this.isRendering = true;
|
|
792
|
-
writeLock.lock('terminalInput.render');
|
|
793
477
|
try {
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
478
|
+
// Hide cursor during render
|
|
479
|
+
this.write(ESC.HIDE);
|
|
480
|
+
this.write(ESC.RESET);
|
|
481
|
+
// Clear the chat box area
|
|
482
|
+
for (let i = 0; i < chatBoxHeight; i++) {
|
|
483
|
+
this.write(ESC.TO(chatBoxStartRow + i, 1));
|
|
484
|
+
this.write(ESC.CLEAR_LINE);
|
|
797
485
|
}
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
486
|
+
let currentRow = chatBoxStartRow;
|
|
487
|
+
// Meta/status header
|
|
488
|
+
for (const metaLine of metaLines) {
|
|
489
|
+
this.write(ESC.TO(currentRow, 1));
|
|
490
|
+
this.write(metaLine);
|
|
491
|
+
currentRow += 1;
|
|
492
|
+
}
|
|
493
|
+
// Separator line
|
|
494
|
+
this.write(ESC.TO(currentRow, 1));
|
|
495
|
+
this.write(renderDivider(cols - 2));
|
|
496
|
+
currentRow += 1;
|
|
497
|
+
// Render input lines
|
|
498
|
+
let finalRow = currentRow;
|
|
499
|
+
let finalCol = 3;
|
|
500
|
+
for (let i = 0; i < visibleLines.length; i++) {
|
|
501
|
+
const rowNum = currentRow + i;
|
|
502
|
+
this.write(ESC.TO(rowNum, 1));
|
|
503
|
+
const line = visibleLines[i] ?? '';
|
|
504
|
+
const isFirstLine = (startLine + i) === 0;
|
|
505
|
+
const isCursorLine = i === adjustedCursorLine;
|
|
506
|
+
this.write(ESC.BG_DARK);
|
|
507
|
+
this.write(ESC.DIM);
|
|
508
|
+
this.write(isFirstLine ? this.config.promptChar : this.config.continuationChar);
|
|
509
|
+
this.write(ESC.RESET);
|
|
510
|
+
this.write(ESC.BG_DARK);
|
|
511
|
+
if (isCursorLine) {
|
|
512
|
+
const col = Math.min(cursorCol, line.length);
|
|
513
|
+
const before = line.slice(0, col);
|
|
514
|
+
const at = col < line.length ? line[col] : ' ';
|
|
515
|
+
const after = col < line.length ? line.slice(col + 1) : '';
|
|
516
|
+
this.write(before);
|
|
517
|
+
this.write(ESC.REVERSE + ESC.BOLD);
|
|
518
|
+
this.write(at);
|
|
519
|
+
this.write(ESC.RESET + ESC.BG_DARK);
|
|
520
|
+
this.write(after);
|
|
521
|
+
finalRow = rowNum;
|
|
522
|
+
finalCol = this.config.promptChar.length + col + 1;
|
|
523
|
+
}
|
|
524
|
+
else {
|
|
525
|
+
this.write(line);
|
|
526
|
+
}
|
|
527
|
+
// Pad to edge
|
|
528
|
+
const lineLen = this.config.promptChar.length + line.length + (isCursorLine && cursorCol >= line.length ? 1 : 0);
|
|
529
|
+
const padding = Math.max(0, cols - lineLen - 1);
|
|
530
|
+
if (padding > 0)
|
|
531
|
+
this.write(' '.repeat(padding));
|
|
532
|
+
this.write(ESC.RESET);
|
|
533
|
+
}
|
|
534
|
+
// Mode controls line
|
|
535
|
+
const controlRow = currentRow + visibleLines.length;
|
|
536
|
+
this.write(ESC.TO(controlRow, 1));
|
|
537
|
+
this.write(this.buildModeControls(cols));
|
|
538
|
+
// Position cursor in input box
|
|
539
|
+
this.write(ESC.TO(finalRow, Math.min(finalCol, cols)));
|
|
540
|
+
this.write(ESC.SHOW);
|
|
541
|
+
// Update state
|
|
542
|
+
this.lastRenderContent = this.buffer;
|
|
543
|
+
this.lastRenderCursor = this.cursor;
|
|
544
|
+
this.lastStreamingRender = streamingActive ? Date.now() : 0;
|
|
545
|
+
if (this.streamingRenderTimer) {
|
|
546
|
+
clearTimeout(this.streamingRenderTimer);
|
|
547
|
+
this.streamingRenderTimer = null;
|
|
801
548
|
}
|
|
802
549
|
}
|
|
803
550
|
finally {
|
|
@@ -806,99 +553,217 @@ export class TerminalInput extends EventEmitter {
|
|
|
806
553
|
}
|
|
807
554
|
}
|
|
808
555
|
/**
|
|
809
|
-
* Build
|
|
810
|
-
*
|
|
556
|
+
* Build one or more compact meta lines above the divider (thinking, status, usage).
|
|
557
|
+
* During streaming, shows model line pinned above streaming info.
|
|
811
558
|
*/
|
|
812
|
-
|
|
813
|
-
const
|
|
814
|
-
const
|
|
815
|
-
//
|
|
816
|
-
if (this.
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
559
|
+
buildMetaLines(width) {
|
|
560
|
+
const streamingActive = this.mode === 'streaming' || isStreamingMode();
|
|
561
|
+
const lines = [];
|
|
562
|
+
// Model line should ALWAYS be shown (pinned above streaming content)
|
|
563
|
+
if (this.modelLabel) {
|
|
564
|
+
const modelText = this.providerLabel
|
|
565
|
+
? `model ${this.modelLabel} @ ${this.providerLabel}`
|
|
566
|
+
: `model ${this.modelLabel}`;
|
|
567
|
+
lines.push(renderStatusLine([{ text: modelText, tone: 'info' }], width));
|
|
568
|
+
}
|
|
569
|
+
// During streaming, add a compact status line with essential info
|
|
570
|
+
if (streamingActive) {
|
|
571
|
+
const parts = [];
|
|
572
|
+
// Essential streaming info
|
|
573
|
+
if (this.metaThinkingMs !== null) {
|
|
574
|
+
parts.push({ text: formatThinking(this.metaThinkingMs, this.metaThinkingHasContent), tone: 'info' });
|
|
575
|
+
}
|
|
576
|
+
if (this.metaElapsedSeconds !== null) {
|
|
577
|
+
parts.push({ text: this.formatElapsedLabel(this.metaElapsedSeconds), tone: 'muted' });
|
|
823
578
|
}
|
|
824
|
-
parts.push(
|
|
579
|
+
parts.push({ text: 'esc to stop', tone: 'warn' });
|
|
580
|
+
if (parts.length) {
|
|
581
|
+
lines.push(renderStatusLine(parts, width));
|
|
582
|
+
}
|
|
583
|
+
return lines;
|
|
825
584
|
}
|
|
826
|
-
//
|
|
827
|
-
if (this.
|
|
828
|
-
|
|
585
|
+
// Non-streaming: show full status info (model line already added above)
|
|
586
|
+
if (this.metaThinkingMs !== null) {
|
|
587
|
+
const thinkingText = formatThinking(this.metaThinkingMs, this.metaThinkingHasContent);
|
|
588
|
+
lines.push(renderStatusLine([{ text: thinkingText, tone: 'info' }], width));
|
|
829
589
|
}
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
590
|
+
const statusParts = [];
|
|
591
|
+
const statusLabel = this.statusMessage ?? this.streamingLabel;
|
|
592
|
+
if (statusLabel) {
|
|
593
|
+
statusParts.push({ text: statusLabel, tone: 'info' });
|
|
834
594
|
}
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
parts.push(`\x1b[33m⚠ ${this.overrideStatusMessage}\x1b[0m`); // Yellow
|
|
595
|
+
if (this.metaElapsedSeconds !== null) {
|
|
596
|
+
statusParts.push({ text: this.formatElapsedLabel(this.metaElapsedSeconds), tone: 'muted' });
|
|
838
597
|
}
|
|
839
|
-
|
|
840
|
-
if (
|
|
841
|
-
|
|
598
|
+
const tokensRemaining = this.computeTokensRemaining();
|
|
599
|
+
if (tokensRemaining !== null) {
|
|
600
|
+
statusParts.push({ text: `↓ ${tokensRemaining}`, tone: 'muted' });
|
|
842
601
|
}
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
parts.push(`${ESC.DIM}${this.buffer.split('\n').length}L${ESC.RESET}`);
|
|
602
|
+
if (statusParts.length) {
|
|
603
|
+
lines.push(renderStatusLine(statusParts, width));
|
|
846
604
|
}
|
|
847
|
-
|
|
848
|
-
|
|
605
|
+
const usageParts = [];
|
|
606
|
+
if (this.metaTokensUsed !== null) {
|
|
607
|
+
const formattedUsed = this.formatTokenCount(this.metaTokensUsed);
|
|
608
|
+
const formattedLimit = this.metaTokenLimit ? `/${this.formatTokenCount(this.metaTokenLimit)}` : '';
|
|
609
|
+
usageParts.push({ text: `tokens ${formattedUsed}${formattedLimit}`, tone: 'muted' });
|
|
849
610
|
}
|
|
850
|
-
|
|
851
|
-
|
|
611
|
+
if (this.contextUsage !== null) {
|
|
612
|
+
const tone = this.contextUsage >= 75 ? 'warn' : 'muted';
|
|
613
|
+
const left = Math.max(0, 100 - this.contextUsage);
|
|
614
|
+
usageParts.push({ text: `context used ${this.contextUsage}% (${left}% left)`, tone });
|
|
615
|
+
}
|
|
616
|
+
if (this.queue.length > 0) {
|
|
617
|
+
usageParts.push({ text: `queued ${this.queue.length}`, tone: 'info' });
|
|
618
|
+
}
|
|
619
|
+
if (usageParts.length) {
|
|
620
|
+
lines.push(renderStatusLine(usageParts, width));
|
|
621
|
+
}
|
|
622
|
+
return lines;
|
|
852
623
|
}
|
|
853
624
|
/**
|
|
854
|
-
* Build mode controls line
|
|
855
|
-
*
|
|
856
|
-
*
|
|
857
|
-
* Layout: [toggles on left] ... [context info on right]
|
|
625
|
+
* Build Claude Code style mode controls line.
|
|
626
|
+
* Combines streaming label + override status + main status for simultaneous display.
|
|
858
627
|
*/
|
|
859
628
|
buildModeControls(cols) {
|
|
860
|
-
const
|
|
861
|
-
|
|
862
|
-
const
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
// Edit mode (green=auto, yellow=ask) - per schema.editMode
|
|
866
|
-
if (this.editMode === 'display-edits') {
|
|
867
|
-
toggles.push(`${GREEN}⏵⏵ auto-edit${R}`);
|
|
629
|
+
const width = Math.max(8, cols - 2);
|
|
630
|
+
const leftParts = [];
|
|
631
|
+
const rightParts = [];
|
|
632
|
+
if (this.streamingLabel) {
|
|
633
|
+
leftParts.push({ text: `◐ ${this.streamingLabel}`, tone: 'info' });
|
|
868
634
|
}
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
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
|
-
|
|
635
|
+
if (this.overrideStatusMessage) {
|
|
636
|
+
leftParts.push({ text: `⚠ ${this.overrideStatusMessage}`, tone: 'warn' });
|
|
637
|
+
}
|
|
638
|
+
if (this.statusMessage) {
|
|
639
|
+
leftParts.push({ text: this.statusMessage, tone: this.streamingLabel ? 'muted' : 'info' });
|
|
640
|
+
}
|
|
641
|
+
const editHotkey = this.formatHotkey('shift+tab');
|
|
642
|
+
const editLabel = this.editMode === 'display-edits' ? 'edits: accept' : 'edits: ask';
|
|
643
|
+
const editTone = this.editMode === 'display-edits' ? 'success' : 'muted';
|
|
644
|
+
leftParts.push({ text: `${editHotkey} ${editLabel}`, tone: editTone });
|
|
645
|
+
const verifyHotkey = this.formatHotkey(this.verificationHotkey);
|
|
646
|
+
const verifyLabel = this.verificationEnabled ? 'verify:on' : 'verify:off';
|
|
647
|
+
leftParts.push({ text: `${verifyHotkey} ${verifyLabel}`, tone: this.verificationEnabled ? 'success' : 'muted' });
|
|
648
|
+
const continueHotkey = this.formatHotkey(this.autoContinueHotkey);
|
|
649
|
+
const continueLabel = this.autoContinueEnabled ? 'auto:on' : 'auto:off';
|
|
650
|
+
leftParts.push({ text: `${continueHotkey} ${continueLabel}`, tone: this.autoContinueEnabled ? 'info' : 'muted' });
|
|
651
|
+
if (this.queue.length > 0 && this.mode !== 'streaming') {
|
|
652
|
+
leftParts.push({ text: `queued ${this.queue.length}`, tone: 'info' });
|
|
653
|
+
}
|
|
654
|
+
if (this.buffer.includes('\n')) {
|
|
655
|
+
const lineCount = this.buffer.split('\n').length;
|
|
656
|
+
leftParts.push({ text: `${lineCount} lines`, tone: 'muted' });
|
|
657
|
+
}
|
|
658
|
+
if (this.pastePlaceholders.length > 0) {
|
|
659
|
+
const latest = this.pastePlaceholders[this.pastePlaceholders.length - 1];
|
|
660
|
+
leftParts.push({
|
|
661
|
+
text: `paste #${latest.id} +${latest.lineCount} lines (⌫ to drop)`,
|
|
662
|
+
tone: 'info',
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
const contextRemaining = this.computeContextRemaining();
|
|
666
|
+
if (this.thinkingModeLabel) {
|
|
667
|
+
const thinkingHotkey = this.formatHotkey(this.thinkingHotkey);
|
|
668
|
+
rightParts.push({ text: `${thinkingHotkey} thinking:${this.thinkingModeLabel}`, tone: 'info' });
|
|
669
|
+
}
|
|
670
|
+
// Show model in controls only when NOT streaming (during streaming it's in meta lines)
|
|
671
|
+
const streamingActive = this.mode === 'streaming' || isStreamingMode();
|
|
672
|
+
if (this.modelLabel && !streamingActive) {
|
|
673
|
+
const modelText = this.providerLabel ? `${this.modelLabel} @ ${this.providerLabel}` : this.modelLabel;
|
|
674
|
+
rightParts.push({ text: modelText, tone: 'muted' });
|
|
675
|
+
}
|
|
676
|
+
if (contextRemaining !== null) {
|
|
677
|
+
const tone = contextRemaining <= 10 ? 'warn' : 'muted';
|
|
678
|
+
const label = contextRemaining === 0 && this.contextUsage !== null
|
|
679
|
+
? 'Context auto-compact imminent'
|
|
680
|
+
: `Context left until auto-compact: ${contextRemaining}%`;
|
|
681
|
+
rightParts.push({ text: label, tone });
|
|
682
|
+
}
|
|
683
|
+
if (!rightParts.length || width < 60) {
|
|
684
|
+
const merged = rightParts.length ? [...leftParts, ...rightParts] : leftParts;
|
|
685
|
+
return renderStatusLine(merged, width);
|
|
686
|
+
}
|
|
687
|
+
const leftWidth = Math.max(12, Math.floor(width * 0.6));
|
|
688
|
+
const rightWidth = Math.max(14, width - leftWidth - 1);
|
|
689
|
+
const leftText = renderStatusLine(leftParts, leftWidth);
|
|
690
|
+
const rightText = renderStatusLine(rightParts, rightWidth);
|
|
691
|
+
const spacing = Math.max(1, width - this.visibleLength(leftText) - this.visibleLength(rightText));
|
|
692
|
+
return `${leftText}${' '.repeat(spacing)}${rightText}`;
|
|
693
|
+
}
|
|
694
|
+
formatHotkey(hotkey) {
|
|
695
|
+
const normalized = hotkey.trim().toLowerCase();
|
|
696
|
+
if (!normalized)
|
|
697
|
+
return hotkey;
|
|
698
|
+
const parts = normalized.split('+').filter(Boolean);
|
|
699
|
+
const map = {
|
|
700
|
+
shift: '⇧',
|
|
701
|
+
sh: '⇧',
|
|
702
|
+
alt: '⌥',
|
|
703
|
+
option: '⌥',
|
|
704
|
+
opt: '⌥',
|
|
705
|
+
ctrl: '⌃',
|
|
706
|
+
control: '⌃',
|
|
707
|
+
cmd: '⌘',
|
|
708
|
+
meta: '⌘',
|
|
709
|
+
};
|
|
710
|
+
const formatted = parts
|
|
711
|
+
.map((part) => {
|
|
712
|
+
const symbol = map[part];
|
|
713
|
+
if (symbol)
|
|
714
|
+
return symbol;
|
|
715
|
+
return part.length === 1 ? part.toUpperCase() : part.toUpperCase();
|
|
716
|
+
})
|
|
717
|
+
.join('');
|
|
718
|
+
return formatted || hotkey;
|
|
719
|
+
}
|
|
720
|
+
computeContextRemaining() {
|
|
721
|
+
if (this.contextUsage === null) {
|
|
722
|
+
return null;
|
|
723
|
+
}
|
|
724
|
+
return Math.max(0, this.contextAutoCompactThreshold - this.contextUsage);
|
|
725
|
+
}
|
|
726
|
+
computeTokensRemaining() {
|
|
727
|
+
if (this.metaTokensUsed === null || this.metaTokenLimit === null) {
|
|
728
|
+
return null;
|
|
729
|
+
}
|
|
730
|
+
const remaining = Math.max(0, this.metaTokenLimit - this.metaTokensUsed);
|
|
731
|
+
return this.formatTokenCount(remaining);
|
|
732
|
+
}
|
|
733
|
+
formatElapsedLabel(seconds) {
|
|
734
|
+
if (seconds < 60) {
|
|
735
|
+
return `${seconds}s`;
|
|
736
|
+
}
|
|
737
|
+
const mins = Math.floor(seconds / 60);
|
|
738
|
+
const secs = seconds % 60;
|
|
739
|
+
return secs > 0 ? `${mins}m ${secs}s` : `${mins}m`;
|
|
740
|
+
}
|
|
741
|
+
formatTokenCount(value) {
|
|
742
|
+
if (!Number.isFinite(value)) {
|
|
743
|
+
return `${value}`;
|
|
744
|
+
}
|
|
745
|
+
if (value >= 1_000_000) {
|
|
746
|
+
return `${(value / 1_000_000).toFixed(1)}M`;
|
|
747
|
+
}
|
|
748
|
+
if (value >= 1_000) {
|
|
749
|
+
return `${(value / 1_000).toFixed(1)}k`;
|
|
750
|
+
}
|
|
751
|
+
return `${Math.round(value)}`;
|
|
752
|
+
}
|
|
753
|
+
visibleLength(value) {
|
|
754
|
+
const ansiPattern = /\u001B\[[0-?]*[ -/]*[@-~]/g;
|
|
755
|
+
return value.replace(ansiPattern, '').length;
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* Debug-only snapshot used by tests to assert rendered strings without
|
|
759
|
+
* needing a TTY. Not used by production code.
|
|
760
|
+
*/
|
|
761
|
+
getDebugUiSnapshot(width) {
|
|
762
|
+
const cols = Math.max(8, width ?? this.getSize().cols);
|
|
763
|
+
return {
|
|
764
|
+
meta: this.buildMetaLines(cols - 2),
|
|
765
|
+
controls: this.buildModeControls(cols),
|
|
766
|
+
};
|
|
902
767
|
}
|
|
903
768
|
/**
|
|
904
769
|
* Force a re-render
|
|
@@ -921,20 +786,113 @@ export class TerminalInput extends EventEmitter {
|
|
|
921
786
|
handleResize() {
|
|
922
787
|
this.lastRenderContent = '';
|
|
923
788
|
this.lastRenderCursor = -1;
|
|
789
|
+
this.resetStreamingRenderThrottle();
|
|
924
790
|
this.scheduleRender();
|
|
925
791
|
}
|
|
926
792
|
/**
|
|
927
|
-
*
|
|
928
|
-
*
|
|
793
|
+
* Stream content with dynamic floating scroll region.
|
|
794
|
+
*
|
|
795
|
+
* - Chat box floats below content (not pinned to terminal bottom)
|
|
796
|
+
* - Scroll region dynamically adjusts based on where content ends
|
|
797
|
+
* - As content grows, scroll region expands, chat box moves down
|
|
798
|
+
* - When terminal fills, content scrolls within scroll region
|
|
929
799
|
*/
|
|
930
|
-
|
|
931
|
-
if (
|
|
932
|
-
|
|
800
|
+
streamContent(content) {
|
|
801
|
+
if (!content)
|
|
802
|
+
return;
|
|
803
|
+
const { rows } = this.getSize();
|
|
804
|
+
const chatBoxHeight = this.getChatBoxHeight();
|
|
805
|
+
const newlines = (content.match(/\n/g) || []).length;
|
|
806
|
+
// Calculate where content will end
|
|
807
|
+
const projectedContentRow = this.contentRow + newlines;
|
|
808
|
+
// Max scroll region bottom (leaves room for chat box)
|
|
809
|
+
const maxScrollBottom = Math.max(1, rows - chatBoxHeight);
|
|
810
|
+
// Will content overflow the terminal?
|
|
811
|
+
const willOverflow = projectedContentRow > maxScrollBottom;
|
|
812
|
+
if (willOverflow) {
|
|
813
|
+
// Set scroll region to max (pinned mode)
|
|
814
|
+
this.write(ESC.SET_SCROLL(1, maxScrollBottom));
|
|
815
|
+
this.scrollRegionActive = true;
|
|
816
|
+
// Write at bottom of scroll region - content will scroll up
|
|
817
|
+
this.write(ESC.TO(maxScrollBottom, 1));
|
|
818
|
+
this.write(content);
|
|
819
|
+
// contentRow stays at max
|
|
820
|
+
this.contentRow = maxScrollBottom;
|
|
933
821
|
}
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
822
|
+
else {
|
|
823
|
+
// Dynamic floating mode - scroll region expands with content
|
|
824
|
+
const newScrollBottom = Math.max(1, projectedContentRow);
|
|
825
|
+
this.write(ESC.SET_SCROLL(1, newScrollBottom));
|
|
826
|
+
this.scrollRegionActive = true;
|
|
827
|
+
// Write at current contentRow
|
|
828
|
+
this.write(ESC.TO(this.contentRow, 1));
|
|
829
|
+
this.write(content);
|
|
830
|
+
// Advance contentRow
|
|
831
|
+
this.contentRow = projectedContentRow;
|
|
832
|
+
}
|
|
833
|
+
// Re-render chat box at new position (floats below scroll region)
|
|
834
|
+
this.forceRender();
|
|
835
|
+
}
|
|
836
|
+
/**
|
|
837
|
+
* Enable scroll region with dynamic sizing.
|
|
838
|
+
* Scroll region is rows 1 to contentRow (expands as content grows).
|
|
839
|
+
*/
|
|
840
|
+
enableScrollRegion() {
|
|
841
|
+
const scrollBottom = Math.max(1, this.contentRow);
|
|
842
|
+
this.write(ESC.SET_SCROLL(1, scrollBottom));
|
|
843
|
+
this.scrollRegionActive = true;
|
|
844
|
+
}
|
|
845
|
+
/**
|
|
846
|
+
* Disable scroll region and reset to full terminal.
|
|
847
|
+
*/
|
|
848
|
+
disableScrollRegion() {
|
|
849
|
+
if (this.scrollRegionActive) {
|
|
850
|
+
this.write(ESC.RESET_SCROLL);
|
|
851
|
+
this.scrollRegionActive = false;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
/**
|
|
855
|
+
* Calculate the chat box height based on current state.
|
|
856
|
+
*/
|
|
857
|
+
getChatBoxHeight() {
|
|
858
|
+
const { cols } = this.getSize();
|
|
859
|
+
const metaLines = this.buildMetaLines(cols - 2);
|
|
860
|
+
// meta lines + divider + at least 1 input line + controls
|
|
861
|
+
return metaLines.length + 1 + 1 + 1;
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* @deprecated Use streamContent() instead
|
|
865
|
+
* Register with display's output interceptor - kept for backwards compatibility
|
|
866
|
+
*/
|
|
867
|
+
registerOutputInterceptor(_display) {
|
|
868
|
+
// No-op: Use streamContent() for cleaner floating chat box behavior
|
|
869
|
+
}
|
|
870
|
+
/**
|
|
871
|
+
* @deprecated Use streamContent() instead
|
|
872
|
+
* Write content above the floating chat box.
|
|
873
|
+
*/
|
|
874
|
+
writeToScrollRegion(content) {
|
|
875
|
+
this.streamContent(content);
|
|
876
|
+
}
|
|
877
|
+
/**
|
|
878
|
+
* Reset content position to row 1.
|
|
879
|
+
* Does NOT clear the terminal - content starts from current position.
|
|
880
|
+
*/
|
|
881
|
+
resetContentPosition() {
|
|
882
|
+
this.contentRow = 1;
|
|
883
|
+
}
|
|
884
|
+
/**
|
|
885
|
+
* Set the content row explicitly (used after banner is written).
|
|
886
|
+
* This tells the input where content should start flowing from.
|
|
887
|
+
*/
|
|
888
|
+
setContentRow(row) {
|
|
889
|
+
this.contentRow = Math.max(1, row);
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* Get the current content row position.
|
|
893
|
+
*/
|
|
894
|
+
getContentRow() {
|
|
895
|
+
return this.contentRow;
|
|
938
896
|
}
|
|
939
897
|
/**
|
|
940
898
|
* Dispose and clean up
|
|
@@ -942,18 +900,10 @@ export class TerminalInput extends EventEmitter {
|
|
|
942
900
|
dispose() {
|
|
943
901
|
if (this.disposed)
|
|
944
902
|
return;
|
|
945
|
-
// Clean up streaming render timer
|
|
946
|
-
if (this.streamingRenderTimer) {
|
|
947
|
-
clearInterval(this.streamingRenderTimer);
|
|
948
|
-
this.streamingRenderTimer = null;
|
|
949
|
-
}
|
|
950
|
-
// Clean up output interceptor
|
|
951
|
-
if (this.outputInterceptorCleanup) {
|
|
952
|
-
this.outputInterceptorCleanup();
|
|
953
|
-
this.outputInterceptorCleanup = undefined;
|
|
954
|
-
}
|
|
955
903
|
this.disposed = true;
|
|
956
904
|
this.enabled = false;
|
|
905
|
+
this.disableScrollRegion();
|
|
906
|
+
this.resetStreamingRenderThrottle();
|
|
957
907
|
this.disableBracketedPaste();
|
|
958
908
|
this.buffer = '';
|
|
959
909
|
this.queue = [];
|
|
@@ -1058,22 +1008,7 @@ export class TerminalInput extends EventEmitter {
|
|
|
1058
1008
|
this.toggleEditMode();
|
|
1059
1009
|
return true;
|
|
1060
1010
|
}
|
|
1061
|
-
|
|
1062
|
-
if (this.findPlaceholderAt(this.cursor)) {
|
|
1063
|
-
this.togglePasteExpansion();
|
|
1064
|
-
}
|
|
1065
|
-
else {
|
|
1066
|
-
this.toggleThinking();
|
|
1067
|
-
}
|
|
1068
|
-
return true;
|
|
1069
|
-
case 'escape':
|
|
1070
|
-
// Esc: interrupt if streaming, otherwise clear buffer
|
|
1071
|
-
if (this.mode === 'streaming') {
|
|
1072
|
-
this.emit('interrupt');
|
|
1073
|
-
}
|
|
1074
|
-
else if (this.buffer.length > 0) {
|
|
1075
|
-
this.clear();
|
|
1076
|
-
}
|
|
1011
|
+
this.insertText(' ');
|
|
1077
1012
|
return true;
|
|
1078
1013
|
}
|
|
1079
1014
|
return false;
|
|
@@ -1091,7 +1026,6 @@ export class TerminalInput extends EventEmitter {
|
|
|
1091
1026
|
this.insertPlainText(chunk, insertPos);
|
|
1092
1027
|
this.cursor = insertPos + chunk.length;
|
|
1093
1028
|
this.emit('change', this.buffer);
|
|
1094
|
-
this.updateSuggestions();
|
|
1095
1029
|
this.scheduleRender();
|
|
1096
1030
|
}
|
|
1097
1031
|
insertNewline() {
|
|
@@ -1116,7 +1050,6 @@ export class TerminalInput extends EventEmitter {
|
|
|
1116
1050
|
this.cursor = Math.max(0, this.cursor - 1);
|
|
1117
1051
|
}
|
|
1118
1052
|
this.emit('change', this.buffer);
|
|
1119
|
-
this.updateSuggestions();
|
|
1120
1053
|
this.scheduleRender();
|
|
1121
1054
|
}
|
|
1122
1055
|
deleteForward() {
|
|
@@ -1344,13 +1277,12 @@ export class TerminalInput extends EventEmitter {
|
|
|
1344
1277
|
timestamp: Date.now(),
|
|
1345
1278
|
});
|
|
1346
1279
|
this.emit('queue', text);
|
|
1347
|
-
this.clear(); // Clear immediately for queued input
|
|
1280
|
+
this.clear(); // Clear immediately for queued input
|
|
1348
1281
|
}
|
|
1349
1282
|
else {
|
|
1350
|
-
// In idle mode, clear the input
|
|
1351
|
-
// The
|
|
1352
|
-
|
|
1353
|
-
this.clear(true); // Skip render - streaming will handle display
|
|
1283
|
+
// In idle mode, clear the input first, then emit submit.
|
|
1284
|
+
// The prompt will be logged as a visible message by the caller.
|
|
1285
|
+
this.clear();
|
|
1354
1286
|
this.emit('submit', text);
|
|
1355
1287
|
}
|
|
1356
1288
|
}
|
|
@@ -1367,7 +1299,9 @@ export class TerminalInput extends EventEmitter {
|
|
|
1367
1299
|
if (available <= 0)
|
|
1368
1300
|
return;
|
|
1369
1301
|
const chunk = clean.slice(0, available);
|
|
1370
|
-
|
|
1302
|
+
const isMultiline = isMultilinePaste(chunk);
|
|
1303
|
+
const isShortMultiline = isMultiline && this.shouldInlineMultiline(chunk);
|
|
1304
|
+
if (isMultiline && !isShortMultiline) {
|
|
1371
1305
|
this.insertPastePlaceholder(chunk);
|
|
1372
1306
|
}
|
|
1373
1307
|
else {
|
|
@@ -1503,17 +1437,19 @@ export class TerminalInput extends EventEmitter {
|
|
|
1503
1437
|
this.shiftPlaceholders(position, text.length);
|
|
1504
1438
|
this.buffer = this.buffer.slice(0, position) + text + this.buffer.slice(position);
|
|
1505
1439
|
}
|
|
1440
|
+
shouldInlineMultiline(content) {
|
|
1441
|
+
const lines = content.split('\n').length;
|
|
1442
|
+
const maxInlineLines = 4;
|
|
1443
|
+
const maxInlineChars = 240;
|
|
1444
|
+
return lines <= maxInlineLines && content.length <= maxInlineChars;
|
|
1445
|
+
}
|
|
1506
1446
|
findPlaceholderAt(position) {
|
|
1507
1447
|
return this.pastePlaceholders.find((ph) => position >= ph.start && position < ph.end) ?? null;
|
|
1508
1448
|
}
|
|
1509
|
-
buildPlaceholder(
|
|
1449
|
+
buildPlaceholder(lineCount) {
|
|
1510
1450
|
const id = ++this.pasteCounter;
|
|
1511
|
-
const
|
|
1512
|
-
|
|
1513
|
-
const preview = summary.preview.length > 30
|
|
1514
|
-
? `${summary.preview.slice(0, 30)}...`
|
|
1515
|
-
: summary.preview;
|
|
1516
|
-
const placeholder = `[📋 #${id}${lang} ${summary.lineCount}L] "${preview}"`;
|
|
1451
|
+
const plural = lineCount === 1 ? '' : 's';
|
|
1452
|
+
const placeholder = `[Pasted text #${id} +${lineCount} line${plural}]`;
|
|
1517
1453
|
return { id, placeholder };
|
|
1518
1454
|
}
|
|
1519
1455
|
insertPastePlaceholder(content) {
|
|
@@ -1521,67 +1457,21 @@ export class TerminalInput extends EventEmitter {
|
|
|
1521
1457
|
if (available <= 0)
|
|
1522
1458
|
return;
|
|
1523
1459
|
const cleanContent = content.slice(0, available);
|
|
1524
|
-
const
|
|
1525
|
-
|
|
1526
|
-
if (summary.lineCount < 5) {
|
|
1527
|
-
const placeholder = this.findPlaceholderAt(this.cursor);
|
|
1528
|
-
const insertPos = placeholder && this.cursor > placeholder.start ? placeholder.end : this.cursor;
|
|
1529
|
-
this.insertPlainText(cleanContent, insertPos);
|
|
1530
|
-
this.cursor = insertPos + cleanContent.length;
|
|
1531
|
-
return;
|
|
1532
|
-
}
|
|
1533
|
-
const { id, placeholder } = this.buildPlaceholder(summary);
|
|
1460
|
+
const lineCount = cleanContent.split('\n').length;
|
|
1461
|
+
const { id, placeholder } = this.buildPlaceholder(lineCount);
|
|
1534
1462
|
const insertPos = this.cursor;
|
|
1535
1463
|
this.shiftPlaceholders(insertPos, placeholder.length);
|
|
1536
1464
|
this.pastePlaceholders.push({
|
|
1537
1465
|
id,
|
|
1538
1466
|
content: cleanContent,
|
|
1539
|
-
lineCount
|
|
1467
|
+
lineCount,
|
|
1540
1468
|
placeholder,
|
|
1541
1469
|
start: insertPos,
|
|
1542
1470
|
end: insertPos + placeholder.length,
|
|
1543
|
-
summary,
|
|
1544
|
-
expanded: false,
|
|
1545
1471
|
});
|
|
1546
1472
|
this.buffer = this.buffer.slice(0, insertPos) + placeholder + this.buffer.slice(insertPos);
|
|
1547
1473
|
this.cursor = insertPos + placeholder.length;
|
|
1548
1474
|
}
|
|
1549
|
-
/**
|
|
1550
|
-
* Toggle expansion of a paste placeholder at the current cursor position.
|
|
1551
|
-
* When expanded, shows first 3 and last 2 lines of the content.
|
|
1552
|
-
*/
|
|
1553
|
-
togglePasteExpansion() {
|
|
1554
|
-
const placeholder = this.findPlaceholderAt(this.cursor);
|
|
1555
|
-
if (!placeholder)
|
|
1556
|
-
return false;
|
|
1557
|
-
placeholder.expanded = !placeholder.expanded;
|
|
1558
|
-
// Update the placeholder text in buffer
|
|
1559
|
-
const newPlaceholder = placeholder.expanded
|
|
1560
|
-
? this.buildExpandedPlaceholder(placeholder)
|
|
1561
|
-
: this.buildPlaceholder(placeholder.summary).placeholder;
|
|
1562
|
-
const lengthDiff = newPlaceholder.length - placeholder.placeholder.length;
|
|
1563
|
-
// Update buffer
|
|
1564
|
-
this.buffer =
|
|
1565
|
-
this.buffer.slice(0, placeholder.start) +
|
|
1566
|
-
newPlaceholder +
|
|
1567
|
-
this.buffer.slice(placeholder.end);
|
|
1568
|
-
// Update placeholder tracking
|
|
1569
|
-
placeholder.placeholder = newPlaceholder;
|
|
1570
|
-
placeholder.end = placeholder.start + newPlaceholder.length;
|
|
1571
|
-
// Shift other placeholders
|
|
1572
|
-
this.shiftPlaceholders(placeholder.end, lengthDiff, placeholder.id);
|
|
1573
|
-
this.scheduleRender();
|
|
1574
|
-
return true;
|
|
1575
|
-
}
|
|
1576
|
-
buildExpandedPlaceholder(ph) {
|
|
1577
|
-
const lines = ph.content.split('\n');
|
|
1578
|
-
const firstLines = lines.slice(0, 3).map(l => l.slice(0, 60)).join('\n');
|
|
1579
|
-
const lastLines = lines.length > 5
|
|
1580
|
-
? '\n...\n' + lines.slice(-2).map(l => l.slice(0, 60)).join('\n')
|
|
1581
|
-
: '';
|
|
1582
|
-
const lang = ph.summary.language ? ` ${ph.summary.language.toUpperCase()}` : '';
|
|
1583
|
-
return `[📋 #${ph.id}${lang} ${ph.lineCount}L ▼]\n${firstLines}${lastLines}\n[/📋 #${ph.id}]`;
|
|
1584
|
-
}
|
|
1585
1475
|
deletePlaceholder(placeholder) {
|
|
1586
1476
|
const length = placeholder.end - placeholder.start;
|
|
1587
1477
|
this.buffer = this.buffer.slice(0, placeholder.start) + this.buffer.slice(placeholder.end);
|
|
@@ -1589,7 +1479,11 @@ export class TerminalInput extends EventEmitter {
|
|
|
1589
1479
|
this.shiftPlaceholders(placeholder.end, -length, placeholder.id);
|
|
1590
1480
|
this.cursor = placeholder.start;
|
|
1591
1481
|
}
|
|
1592
|
-
updateContextUsage(value) {
|
|
1482
|
+
updateContextUsage(value, autoCompactThreshold) {
|
|
1483
|
+
if (typeof autoCompactThreshold === 'number' && Number.isFinite(autoCompactThreshold)) {
|
|
1484
|
+
const boundedThreshold = Math.max(1, Math.min(100, Math.round(autoCompactThreshold)));
|
|
1485
|
+
this.contextAutoCompactThreshold = boundedThreshold;
|
|
1486
|
+
}
|
|
1593
1487
|
if (value === null || !Number.isFinite(value)) {
|
|
1594
1488
|
this.contextUsage = null;
|
|
1595
1489
|
}
|
|
@@ -1616,6 +1510,22 @@ export class TerminalInput extends EventEmitter {
|
|
|
1616
1510
|
const next = this.editMode === 'display-edits' ? 'ask-permission' : 'display-edits';
|
|
1617
1511
|
this.setEditMode(next);
|
|
1618
1512
|
}
|
|
1513
|
+
scheduleStreamingRender(delayMs) {
|
|
1514
|
+
if (this.streamingRenderTimer)
|
|
1515
|
+
return;
|
|
1516
|
+
const wait = Math.max(16, delayMs);
|
|
1517
|
+
this.streamingRenderTimer = setTimeout(() => {
|
|
1518
|
+
this.streamingRenderTimer = null;
|
|
1519
|
+
this.render();
|
|
1520
|
+
}, wait);
|
|
1521
|
+
}
|
|
1522
|
+
resetStreamingRenderThrottle() {
|
|
1523
|
+
if (this.streamingRenderTimer) {
|
|
1524
|
+
clearTimeout(this.streamingRenderTimer);
|
|
1525
|
+
this.streamingRenderTimer = null;
|
|
1526
|
+
}
|
|
1527
|
+
this.lastStreamingRender = 0;
|
|
1528
|
+
}
|
|
1619
1529
|
scheduleRender() {
|
|
1620
1530
|
if (!this.canRender())
|
|
1621
1531
|
return;
|