erosolar-cli 1.7.296 → 1.7.298
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 +218 -159
- 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 +96 -161
- package/dist/shell/terminalInput.d.ts.map +1 -1
- package/dist/shell/terminalInput.js +504 -672
- package/dist/shell/terminalInput.js.map +1 -1
- package/dist/shell/terminalInputAdapter.d.ts +37 -36
- package/dist/shell/terminalInputAdapter.d.ts.map +1 -1
- package/dist/shell/terminalInputAdapter.js +40 -53
- 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,18 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Design principles:
|
|
5
5
|
* - Single source of truth for input state
|
|
6
|
+
* - Content flows naturally from top to bottom (no scroll region pinning)
|
|
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 {
|
|
15
|
+
import { renderDivider, renderStatusLine } from '../ui/unified/layout.js';
|
|
16
|
+
import { isStreamingMode } from '../ui/globalWriteLock.js';
|
|
17
|
+
import { formatThinking } from '../ui/toolDisplay.js';
|
|
15
18
|
// ANSI escape codes
|
|
16
19
|
const ESC = {
|
|
17
20
|
// Cursor control
|
|
@@ -21,9 +24,6 @@ const ESC = {
|
|
|
21
24
|
SHOW: '\x1b[?25h',
|
|
22
25
|
TO: (row, col) => `\x1b[${row};${col}H`,
|
|
23
26
|
TO_COL: (col) => `\x1b[${col}G`,
|
|
24
|
-
// Screen control
|
|
25
|
-
CLEAR_SCREEN: '\x1b[2J',
|
|
26
|
-
HOME: '\x1b[H',
|
|
27
27
|
// Line control
|
|
28
28
|
CLEAR_LINE: '\x1b[2K',
|
|
29
29
|
CLEAR_TO_END: '\x1b[0J',
|
|
@@ -69,56 +69,46 @@ export class TerminalInput extends EventEmitter {
|
|
|
69
69
|
statusMessage = null;
|
|
70
70
|
overrideStatusMessage = null; // Secondary status (warnings, etc.)
|
|
71
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
|
|
72
77
|
lastRenderContent = '';
|
|
73
78
|
lastRenderCursor = -1;
|
|
74
79
|
renderDirty = false;
|
|
75
80
|
isRendering = false;
|
|
76
|
-
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
|
-
inputAreaStartRow = 0; // Track absolute row position of input area
|
|
84
|
-
scrollRegionActive = false; // Track if scroll region is enabled
|
|
85
|
-
contentEndRow = 0; // Row where content ends (for idle mode positioning)
|
|
86
|
-
// Command suggestions (Claude Code style auto-complete)
|
|
87
|
-
commandSuggestions = [];
|
|
88
|
-
filteredSuggestions = [];
|
|
89
|
-
selectedSuggestionIndex = 0;
|
|
90
|
-
showSuggestions = false;
|
|
91
|
-
maxVisibleSuggestions = 10;
|
|
92
81
|
// Lifecycle
|
|
93
82
|
disposed = false;
|
|
94
83
|
enabled = true;
|
|
95
84
|
contextUsage = null;
|
|
85
|
+
contextAutoCompactThreshold = 90;
|
|
86
|
+
// Track current content row in scroll region (starts at top, moves down)
|
|
87
|
+
contentRow = 1;
|
|
88
|
+
thinkingModeLabel = null;
|
|
96
89
|
editMode = 'display-edits';
|
|
97
90
|
verificationEnabled = true;
|
|
98
91
|
autoContinueEnabled = false;
|
|
99
92
|
verificationHotkey = 'alt+v';
|
|
100
93
|
autoContinueHotkey = 'alt+c';
|
|
94
|
+
thinkingHotkey = '/thinking';
|
|
95
|
+
modelLabel = null;
|
|
96
|
+
providerLabel = null;
|
|
101
97
|
// Output interceptor cleanup
|
|
102
98
|
outputInterceptorCleanup;
|
|
103
|
-
//
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
thinkingEnabled = true;
|
|
107
|
-
modelInfo = null; // Provider · Model info
|
|
108
|
-
// Streaming input area render timer (updates elapsed time display)
|
|
99
|
+
// Streaming render throttle
|
|
100
|
+
lastStreamingRender = 0;
|
|
101
|
+
streamingRenderInterval = 250; // ms between renders during streaming
|
|
109
102
|
streamingRenderTimer = null;
|
|
110
|
-
// Unified UI initialization flag
|
|
111
|
-
unifiedUIInitialized = false;
|
|
112
103
|
constructor(writeStream = process.stdout, config = {}) {
|
|
113
104
|
super();
|
|
114
105
|
this.out = writeStream;
|
|
115
|
-
// Use schema defaults for configuration consistency
|
|
116
106
|
this.config = {
|
|
117
|
-
maxLines: config.maxLines ??
|
|
118
|
-
maxLength: config.maxLength ??
|
|
107
|
+
maxLines: config.maxLines ?? 1000,
|
|
108
|
+
maxLength: config.maxLength ?? 10000,
|
|
119
109
|
maxQueueSize: config.maxQueueSize ?? 100,
|
|
120
|
-
promptChar: config.promptChar ??
|
|
121
|
-
continuationChar: config.continuationChar ??
|
|
110
|
+
promptChar: config.promptChar ?? '> ',
|
|
111
|
+
continuationChar: config.continuationChar ?? '│ ',
|
|
122
112
|
};
|
|
123
113
|
}
|
|
124
114
|
// ===========================================================================
|
|
@@ -197,460 +187,36 @@ export class TerminalInput extends EventEmitter {
|
|
|
197
187
|
if (handled)
|
|
198
188
|
return;
|
|
199
189
|
}
|
|
200
|
-
// Handle '?' for help hint (if buffer is empty)
|
|
201
|
-
if (str === '?' && this.buffer.length === 0) {
|
|
202
|
-
this.emit('showHelp');
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
190
|
// Insert printable characters
|
|
206
191
|
if (str && !key?.ctrl && !key?.meta) {
|
|
207
192
|
this.insertText(str);
|
|
208
193
|
}
|
|
209
194
|
}
|
|
210
|
-
// Banner content to write on init (set via setBannerContent before initializeUnifiedUI)
|
|
211
|
-
bannerContent = null;
|
|
212
|
-
/**
|
|
213
|
-
* Set banner content to be written when unified UI initializes.
|
|
214
|
-
*/
|
|
215
|
-
setBannerContent(content) {
|
|
216
|
-
this.bannerContent = content;
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Initialize the unified UI system.
|
|
220
|
-
*
|
|
221
|
-
* Layout:
|
|
222
|
-
* 1. Clear screen
|
|
223
|
-
* 2. Write banner at top
|
|
224
|
-
* 3. Render input area at bottom
|
|
225
|
-
*/
|
|
226
|
-
initializeUnifiedUI() {
|
|
227
|
-
if (this.unifiedUIInitialized) {
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
// Hide cursor during setup
|
|
231
|
-
this.write(ESC.HIDE);
|
|
232
|
-
// Clear screen and go home
|
|
233
|
-
this.write(ESC.HOME);
|
|
234
|
-
this.write(ESC.CLEAR_SCREEN);
|
|
235
|
-
// Write banner at top
|
|
236
|
-
if (this.bannerContent) {
|
|
237
|
-
process.stdout.write(this.bannerContent + '\n\n');
|
|
238
|
-
}
|
|
239
|
-
// Mark initialized
|
|
240
|
-
this.unifiedUIInitialized = true;
|
|
241
|
-
// Render input area at bottom (unified for all modes)
|
|
242
|
-
this.renderInputAreaAtBottom();
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Clear the input area at its tracked position.
|
|
246
|
-
* Returns true if something was cleared.
|
|
247
|
-
*/
|
|
248
|
-
clearInputArea() {
|
|
249
|
-
if (this.inputAreaStartRow > 0 && this.flowModeRenderedLines > 0) {
|
|
250
|
-
for (let i = 0; i < this.flowModeRenderedLines; i++) {
|
|
251
|
-
this.write(ESC.TO(this.inputAreaStartRow + i, 1));
|
|
252
|
-
this.write(ESC.CLEAR_LINE);
|
|
253
|
-
}
|
|
254
|
-
return true;
|
|
255
|
-
}
|
|
256
|
-
return false;
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* Reset input area tracking state.
|
|
260
|
-
*/
|
|
261
|
-
resetInputAreaTracking() {
|
|
262
|
-
this.inputAreaStartRow = 0;
|
|
263
|
-
this.flowModeRenderedLines = 0;
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* Enable scroll region - content scrolls above, input area protected at bottom.
|
|
267
|
-
*/
|
|
268
|
-
enableScrollRegion() {
|
|
269
|
-
if (this.scrollRegionActive)
|
|
270
|
-
return;
|
|
271
|
-
const { rows } = this.getSize();
|
|
272
|
-
const linesNeeded = 6 + (this.modelInfo ? 1 : 0);
|
|
273
|
-
const scrollBottom = Math.max(1, rows - linesNeeded);
|
|
274
|
-
this.write(ESC.SET_SCROLL(1, scrollBottom));
|
|
275
|
-
this.scrollRegionActive = true;
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Disable scroll region.
|
|
279
|
-
*/
|
|
280
|
-
disableScrollRegion() {
|
|
281
|
-
if (!this.scrollRegionActive)
|
|
282
|
-
return;
|
|
283
|
-
this.write(ESC.RESET_SCROLL);
|
|
284
|
-
this.scrollRegionActive = false;
|
|
285
|
-
}
|
|
286
|
-
/**
|
|
287
|
-
* Render input area at absolute bottom of terminal.
|
|
288
|
-
* Used during streaming (with scroll region) and after streaming.
|
|
289
|
-
* This is the UNIFIED render method for all modes.
|
|
290
|
-
*/
|
|
291
|
-
renderInputAreaAtBottom() {
|
|
292
|
-
const { rows, cols } = this.getSize();
|
|
293
|
-
const divider = '─'.repeat(cols - 1);
|
|
294
|
-
const { dim: DIM, reset: R } = UI_COLORS;
|
|
295
|
-
// Calculate lines needed and starting row
|
|
296
|
-
const linesNeeded = 5 + (this.modelInfo ? 1 : 0);
|
|
297
|
-
const startRow = Math.max(1, rows - linesNeeded + 1);
|
|
298
|
-
// Save cursor and hide during render
|
|
299
|
-
this.write(ESC.SAVE);
|
|
300
|
-
this.write(ESC.HIDE);
|
|
301
|
-
let currentRow = startRow;
|
|
302
|
-
// Clear input area lines
|
|
303
|
-
for (let r = startRow; r <= rows; r++) {
|
|
304
|
-
this.write(ESC.TO(r, 1));
|
|
305
|
-
this.write(ESC.CLEAR_LINE);
|
|
306
|
-
}
|
|
307
|
-
// Status bar (shows streaming status or idle hint)
|
|
308
|
-
this.write(ESC.TO(currentRow, 1));
|
|
309
|
-
this.write(this.buildStatusBar(cols));
|
|
310
|
-
currentRow++;
|
|
311
|
-
// Model info line (if set)
|
|
312
|
-
if (this.modelInfo) {
|
|
313
|
-
this.write(ESC.TO(currentRow, 1));
|
|
314
|
-
let modelLine = `${DIM}${this.modelInfo}${R}`;
|
|
315
|
-
if (this.contextUsage !== null) {
|
|
316
|
-
const rem = Math.max(0, 100 - this.contextUsage);
|
|
317
|
-
if (rem < 10)
|
|
318
|
-
modelLine += ` ${UI_COLORS.red}⚠ ctx: ${rem}%${R}`;
|
|
319
|
-
else if (rem < 25)
|
|
320
|
-
modelLine += ` ${UI_COLORS.yellow}! ctx: ${rem}%${R}`;
|
|
321
|
-
else
|
|
322
|
-
modelLine += ` ${DIM}· ctx: ${rem}%${R}`;
|
|
323
|
-
}
|
|
324
|
-
this.write(modelLine);
|
|
325
|
-
currentRow++;
|
|
326
|
-
}
|
|
327
|
-
// Top divider
|
|
328
|
-
this.write(ESC.TO(currentRow, 1));
|
|
329
|
-
this.write(divider);
|
|
330
|
-
currentRow++;
|
|
331
|
-
// Input line with prompt and buffer content
|
|
332
|
-
const { lines, cursorCol } = this.wrapBuffer(cols - 4);
|
|
333
|
-
const displayLine = lines[0] ?? '';
|
|
334
|
-
const inputRow = currentRow;
|
|
335
|
-
this.write(ESC.TO(currentRow, 1));
|
|
336
|
-
this.write(ESC.BG_DARK + ESC.DIM + this.config.promptChar + ESC.RESET);
|
|
337
|
-
this.write(ESC.BG_DARK + displayLine);
|
|
338
|
-
const padding = Math.max(0, cols - this.config.promptChar.length - displayLine.length - 1);
|
|
339
|
-
if (padding > 0)
|
|
340
|
-
this.write(' '.repeat(padding));
|
|
341
|
-
this.write(ESC.RESET);
|
|
342
|
-
currentRow++;
|
|
343
|
-
// Bottom divider
|
|
344
|
-
this.write(ESC.TO(currentRow, 1));
|
|
345
|
-
this.write(divider);
|
|
346
|
-
currentRow++;
|
|
347
|
-
// Mode controls
|
|
348
|
-
this.write(ESC.TO(currentRow, 1));
|
|
349
|
-
this.write(this.buildModeControls(cols));
|
|
350
|
-
// Track position
|
|
351
|
-
this.inputAreaStartRow = startRow;
|
|
352
|
-
this.flowModeRenderedLines = currentRow - startRow + 1;
|
|
353
|
-
// Restore cursor position (back to scroll region if streaming)
|
|
354
|
-
this.write(ESC.RESTORE);
|
|
355
|
-
this.write(ESC.SHOW);
|
|
356
|
-
// Update tracking
|
|
357
|
-
this.lastRenderContent = this.buffer;
|
|
358
|
-
this.lastRenderCursor = this.cursor;
|
|
359
|
-
}
|
|
360
|
-
/**
|
|
361
|
-
* Render floating input area below current content.
|
|
362
|
-
* This is "bottom floating" - follows content, not pinned to terminal bottom.
|
|
363
|
-
* Uses absolute positioning to prevent duplicates.
|
|
364
|
-
*/
|
|
365
|
-
renderFloatingInputArea() {
|
|
366
|
-
const { rows, cols } = this.getSize();
|
|
367
|
-
const divider = '─'.repeat(cols - 1);
|
|
368
|
-
const { dim: DIM, reset: R } = UI_COLORS;
|
|
369
|
-
// Calculate lines needed for input area
|
|
370
|
-
const linesNeeded = 5 + (this.modelInfo ? 1 : 0);
|
|
371
|
-
// FIRST: Clear any previously rendered input area
|
|
372
|
-
this.clearInputArea();
|
|
373
|
-
// Hide cursor during render
|
|
374
|
-
this.write(ESC.HIDE);
|
|
375
|
-
// Calculate where to render: after current content
|
|
376
|
-
// Use contentEndRow if set, otherwise estimate from terminal bottom
|
|
377
|
-
let startRow;
|
|
378
|
-
if (this.contentEndRow > 0) {
|
|
379
|
-
startRow = this.contentEndRow + 1;
|
|
380
|
-
}
|
|
381
|
-
else {
|
|
382
|
-
// Render near bottom, leaving space for input area
|
|
383
|
-
startRow = Math.max(1, rows - linesNeeded);
|
|
384
|
-
}
|
|
385
|
-
// Ensure we don't go past terminal bounds
|
|
386
|
-
startRow = Math.min(startRow, rows - linesNeeded + 1);
|
|
387
|
-
startRow = Math.max(1, startRow);
|
|
388
|
-
// Track this position
|
|
389
|
-
this.inputAreaStartRow = startRow;
|
|
390
|
-
let currentRow = startRow;
|
|
391
|
-
// Status bar
|
|
392
|
-
this.write(ESC.TO(currentRow, 1));
|
|
393
|
-
this.write(this.buildStatusBar(cols));
|
|
394
|
-
currentRow++;
|
|
395
|
-
// Model info line (if set)
|
|
396
|
-
if (this.modelInfo) {
|
|
397
|
-
this.write(ESC.TO(currentRow, 1));
|
|
398
|
-
let modelLine = `${DIM}${this.modelInfo}${R}`;
|
|
399
|
-
if (this.contextUsage !== null) {
|
|
400
|
-
const rem = Math.max(0, 100 - this.contextUsage);
|
|
401
|
-
if (rem < 10)
|
|
402
|
-
modelLine += ` ${UI_COLORS.red}⚠ ctx: ${rem}%${R}`;
|
|
403
|
-
else if (rem < 25)
|
|
404
|
-
modelLine += ` ${UI_COLORS.yellow}! ctx: ${rem}%${R}`;
|
|
405
|
-
else
|
|
406
|
-
modelLine += ` ${DIM}· ctx: ${rem}%${R}`;
|
|
407
|
-
}
|
|
408
|
-
this.write(modelLine);
|
|
409
|
-
currentRow++;
|
|
410
|
-
}
|
|
411
|
-
// Top divider
|
|
412
|
-
this.write(ESC.TO(currentRow, 1));
|
|
413
|
-
this.write(divider);
|
|
414
|
-
currentRow++;
|
|
415
|
-
// Input line with prompt and buffer content
|
|
416
|
-
const { lines, cursorCol } = this.wrapBuffer(cols - 4);
|
|
417
|
-
const displayLine = lines[0] ?? '';
|
|
418
|
-
const inputRow = currentRow;
|
|
419
|
-
this.write(ESC.TO(currentRow, 1));
|
|
420
|
-
this.write(ESC.BG_DARK + ESC.DIM + this.config.promptChar + ESC.RESET);
|
|
421
|
-
this.write(ESC.BG_DARK + displayLine);
|
|
422
|
-
const padding = Math.max(0, cols - this.config.promptChar.length - displayLine.length - 1);
|
|
423
|
-
if (padding > 0)
|
|
424
|
-
this.write(' '.repeat(padding));
|
|
425
|
-
this.write(ESC.RESET);
|
|
426
|
-
currentRow++;
|
|
427
|
-
// Bottom divider
|
|
428
|
-
this.write(ESC.TO(currentRow, 1));
|
|
429
|
-
this.write(divider);
|
|
430
|
-
currentRow++;
|
|
431
|
-
// Mode controls
|
|
432
|
-
this.write(ESC.TO(currentRow, 1));
|
|
433
|
-
this.write(this.buildModeControls(cols));
|
|
434
|
-
// Track lines rendered
|
|
435
|
-
this.flowModeRenderedLines = currentRow - startRow + 1;
|
|
436
|
-
// Position cursor in input line for typing
|
|
437
|
-
this.write(ESC.TO(inputRow, this.config.promptChar.length + 1 + cursorCol));
|
|
438
|
-
// Show cursor
|
|
439
|
-
this.write(ESC.SHOW);
|
|
440
|
-
// Update tracking
|
|
441
|
-
this.lastRenderContent = this.buffer;
|
|
442
|
-
this.lastRenderCursor = this.cursor;
|
|
443
|
-
}
|
|
444
195
|
/**
|
|
445
196
|
* Set the input mode
|
|
446
197
|
*
|
|
447
|
-
*
|
|
198
|
+
* Content flows naturally - no scroll region pinning.
|
|
448
199
|
*/
|
|
449
200
|
setMode(mode) {
|
|
450
201
|
const prevMode = this.mode;
|
|
451
202
|
this.mode = mode;
|
|
452
203
|
if (mode === 'streaming' && prevMode !== 'streaming') {
|
|
453
|
-
|
|
454
|
-
this.streamingStartTime = Date.now();
|
|
455
|
-
// Ensure unified UI is initialized
|
|
456
|
-
if (!this.unifiedUIInitialized) {
|
|
457
|
-
this.initializeUnifiedUI();
|
|
458
|
-
}
|
|
459
|
-
// Clear any floating input area first
|
|
460
|
-
this.clearInputArea();
|
|
461
|
-
this.resetInputAreaTracking();
|
|
462
|
-
// Enable scroll region - content scrolls above, input protected at bottom
|
|
463
|
-
this.enableScrollRegion();
|
|
464
|
-
// Render input at bottom (protected by scroll region)
|
|
465
|
-
this.renderInputAreaAtBottom();
|
|
466
|
-
// Position cursor in scroll region for content
|
|
467
|
-
const { rows } = this.getSize();
|
|
468
|
-
const linesNeeded = 6 + (this.modelInfo ? 1 : 0);
|
|
469
|
-
this.write(ESC.TO(Math.max(1, rows - linesNeeded), 1));
|
|
204
|
+
this.resetStreamingRenderThrottle();
|
|
470
205
|
this.renderDirty = true;
|
|
206
|
+
this.render();
|
|
471
207
|
}
|
|
472
208
|
else if (mode !== 'streaming' && prevMode === 'streaming') {
|
|
473
|
-
//
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
this.streamingRenderTimer = null;
|
|
477
|
-
}
|
|
478
|
-
// Reset streaming time
|
|
479
|
-
this.streamingStartTime = null;
|
|
480
|
-
// Disable scroll region
|
|
481
|
-
this.disableScrollRegion();
|
|
482
|
-
// Clear bottom input area
|
|
483
|
-
this.clearInputArea();
|
|
484
|
-
this.resetInputAreaTracking();
|
|
485
|
-
// Render input area floating below content
|
|
486
|
-
writeLock.withLock(() => {
|
|
487
|
-
this.renderFloatingInputArea();
|
|
488
|
-
}, 'terminalInput.streamingEnd');
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
/**
|
|
492
|
-
* Enable or disable flow mode.
|
|
493
|
-
* In flow mode, the input renders immediately after content (wherever cursor is).
|
|
494
|
-
* When disabled, input renders at the absolute bottom of terminal.
|
|
495
|
-
*/
|
|
496
|
-
setFlowMode(enabled) {
|
|
497
|
-
if (this.flowMode === enabled)
|
|
498
|
-
return;
|
|
499
|
-
this.flowMode = enabled;
|
|
500
|
-
this.renderDirty = true;
|
|
501
|
-
this.scheduleRender();
|
|
502
|
-
}
|
|
503
|
-
/**
|
|
504
|
-
* Check if flow mode is enabled.
|
|
505
|
-
*/
|
|
506
|
-
isFlowMode() {
|
|
507
|
-
return this.flowMode;
|
|
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
|
-
this.contentEndRow = Math.max(0, row);
|
|
515
|
-
this.renderDirty = true;
|
|
516
|
-
this.scheduleRender();
|
|
517
|
-
}
|
|
518
|
-
/**
|
|
519
|
-
* Set available slash commands for auto-complete suggestions.
|
|
520
|
-
*/
|
|
521
|
-
setCommands(commands) {
|
|
522
|
-
this.commandSuggestions = commands;
|
|
523
|
-
this.updateSuggestions();
|
|
524
|
-
}
|
|
525
|
-
/**
|
|
526
|
-
* Update filtered suggestions based on current input.
|
|
527
|
-
*/
|
|
528
|
-
updateSuggestions() {
|
|
529
|
-
const input = this.buffer.trim();
|
|
530
|
-
// Only show suggestions when input starts with "/"
|
|
531
|
-
if (!input.startsWith('/')) {
|
|
532
|
-
this.showSuggestions = false;
|
|
533
|
-
this.filteredSuggestions = [];
|
|
534
|
-
this.selectedSuggestionIndex = 0;
|
|
535
|
-
return;
|
|
536
|
-
}
|
|
537
|
-
const query = input.toLowerCase();
|
|
538
|
-
this.filteredSuggestions = this.commandSuggestions.filter(cmd => cmd.command.toLowerCase().startsWith(query) ||
|
|
539
|
-
cmd.command.toLowerCase().includes(query.slice(1)));
|
|
540
|
-
// Show suggestions if we have matches
|
|
541
|
-
this.showSuggestions = this.filteredSuggestions.length > 0;
|
|
542
|
-
// Keep selection in bounds
|
|
543
|
-
if (this.selectedSuggestionIndex >= this.filteredSuggestions.length) {
|
|
544
|
-
this.selectedSuggestionIndex = Math.max(0, this.filteredSuggestions.length - 1);
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
/**
|
|
548
|
-
* Select next suggestion (arrow down / tab).
|
|
549
|
-
*/
|
|
550
|
-
selectNextSuggestion() {
|
|
551
|
-
if (!this.showSuggestions || this.filteredSuggestions.length === 0)
|
|
552
|
-
return;
|
|
553
|
-
this.selectedSuggestionIndex = (this.selectedSuggestionIndex + 1) % this.filteredSuggestions.length;
|
|
554
|
-
this.renderDirty = true;
|
|
555
|
-
this.scheduleRender();
|
|
556
|
-
}
|
|
557
|
-
/**
|
|
558
|
-
* Select previous suggestion (arrow up / shift+tab).
|
|
559
|
-
*/
|
|
560
|
-
selectPrevSuggestion() {
|
|
561
|
-
if (!this.showSuggestions || this.filteredSuggestions.length === 0)
|
|
562
|
-
return;
|
|
563
|
-
this.selectedSuggestionIndex = this.selectedSuggestionIndex === 0
|
|
564
|
-
? this.filteredSuggestions.length - 1
|
|
565
|
-
: this.selectedSuggestionIndex - 1;
|
|
566
|
-
this.renderDirty = true;
|
|
567
|
-
this.scheduleRender();
|
|
568
|
-
}
|
|
569
|
-
/**
|
|
570
|
-
* Accept current suggestion and insert into buffer.
|
|
571
|
-
*/
|
|
572
|
-
acceptSuggestion() {
|
|
573
|
-
if (!this.showSuggestions || this.filteredSuggestions.length === 0)
|
|
574
|
-
return false;
|
|
575
|
-
const selected = this.filteredSuggestions[this.selectedSuggestionIndex];
|
|
576
|
-
if (!selected)
|
|
577
|
-
return false;
|
|
578
|
-
// Replace buffer with selected command
|
|
579
|
-
this.buffer = selected.command + ' ';
|
|
580
|
-
this.cursor = this.buffer.length;
|
|
581
|
-
this.showSuggestions = false;
|
|
582
|
-
this.renderDirty = true;
|
|
583
|
-
this.scheduleRender();
|
|
584
|
-
return true;
|
|
585
|
-
}
|
|
586
|
-
/**
|
|
587
|
-
* Check if suggestions are visible.
|
|
588
|
-
*/
|
|
589
|
-
areSuggestionsVisible() {
|
|
590
|
-
return this.showSuggestions && this.filteredSuggestions.length > 0;
|
|
591
|
-
}
|
|
592
|
-
/**
|
|
593
|
-
* Update token count for metrics display
|
|
594
|
-
*/
|
|
595
|
-
setTokensUsed(tokens) {
|
|
596
|
-
this.tokensUsed = tokens;
|
|
597
|
-
}
|
|
598
|
-
/**
|
|
599
|
-
* Toggle thinking/reasoning mode
|
|
600
|
-
*/
|
|
601
|
-
toggleThinking() {
|
|
602
|
-
this.thinkingEnabled = !this.thinkingEnabled;
|
|
603
|
-
this.emit('thinkingToggle', this.thinkingEnabled);
|
|
604
|
-
this.scheduleRender();
|
|
605
|
-
}
|
|
606
|
-
/**
|
|
607
|
-
* Get thinking enabled state
|
|
608
|
-
*/
|
|
609
|
-
isThinkingEnabled() {
|
|
610
|
-
return this.thinkingEnabled;
|
|
611
|
-
}
|
|
612
|
-
/**
|
|
613
|
-
* Keep the top N rows pinned (used for the launch banner tracking).
|
|
614
|
-
* Note: No longer uses scroll regions - inline rendering only.
|
|
615
|
-
*/
|
|
616
|
-
setPinnedHeaderLines(count) {
|
|
617
|
-
this.pinnedTopRows = count;
|
|
618
|
-
}
|
|
619
|
-
/**
|
|
620
|
-
* Anchor prompt rendering near a specific row (inline layout). Pass null to
|
|
621
|
-
* restore the default bottom-aligned layout.
|
|
622
|
-
*/
|
|
623
|
-
setInlineAnchor(row) {
|
|
624
|
-
if (row === null || row === undefined) {
|
|
625
|
-
this.inlineAnchorRow = null;
|
|
626
|
-
this.inlineLayout = false;
|
|
627
|
-
this.renderDirty = true;
|
|
628
|
-
this.render();
|
|
629
|
-
return;
|
|
209
|
+
// Streaming ended - render the input area
|
|
210
|
+
this.resetStreamingRenderThrottle();
|
|
211
|
+
this.forceRender();
|
|
630
212
|
}
|
|
631
|
-
const { rows } = this.getSize();
|
|
632
|
-
const clamped = Math.max(1, Math.min(Math.floor(row), rows));
|
|
633
|
-
this.inlineAnchorRow = clamped;
|
|
634
|
-
this.inlineLayout = true;
|
|
635
|
-
this.renderDirty = true;
|
|
636
|
-
this.render();
|
|
637
213
|
}
|
|
638
214
|
/**
|
|
639
|
-
*
|
|
640
|
-
*
|
|
215
|
+
* Legacy method - no longer used (content flows naturally).
|
|
216
|
+
* @deprecated Use setContentRow instead
|
|
641
217
|
*/
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
if (!provider) {
|
|
645
|
-
this.inlineLayout = false;
|
|
646
|
-
this.inlineAnchorRow = null;
|
|
647
|
-
this.renderDirty = true;
|
|
648
|
-
this.render();
|
|
649
|
-
return;
|
|
650
|
-
}
|
|
651
|
-
this.inlineLayout = true;
|
|
652
|
-
this.renderDirty = true;
|
|
653
|
-
this.render();
|
|
218
|
+
setPinnedHeaderLines(_count) {
|
|
219
|
+
// No-op: scroll region pinning removed
|
|
654
220
|
}
|
|
655
221
|
/**
|
|
656
222
|
* Get current mode
|
|
@@ -683,17 +249,14 @@ export class TerminalInput extends EventEmitter {
|
|
|
683
249
|
}
|
|
684
250
|
/**
|
|
685
251
|
* Clear the buffer
|
|
686
|
-
* @param skipRender - If true, don't trigger a re-render (used during submit flow)
|
|
687
252
|
*/
|
|
688
|
-
clear(
|
|
253
|
+
clear() {
|
|
689
254
|
this.buffer = '';
|
|
690
255
|
this.cursor = 0;
|
|
691
256
|
this.historyIndex = -1;
|
|
692
257
|
this.tempInput = '';
|
|
693
258
|
this.pastePlaceholders = [];
|
|
694
|
-
|
|
695
|
-
this.scheduleRender();
|
|
696
|
-
}
|
|
259
|
+
this.scheduleRender();
|
|
697
260
|
}
|
|
698
261
|
/**
|
|
699
262
|
* Get queued inputs
|
|
@@ -764,6 +327,37 @@ export class TerminalInput extends EventEmitter {
|
|
|
764
327
|
this.streamingLabel = next;
|
|
765
328
|
this.scheduleRender();
|
|
766
329
|
}
|
|
330
|
+
/**
|
|
331
|
+
* Surface meta status just above the divider (e.g., elapsed time or token usage).
|
|
332
|
+
*/
|
|
333
|
+
setMetaStatus(meta) {
|
|
334
|
+
const nextElapsed = typeof meta.elapsedSeconds === 'number' && Number.isFinite(meta.elapsedSeconds) && meta.elapsedSeconds >= 0
|
|
335
|
+
? Math.floor(meta.elapsedSeconds)
|
|
336
|
+
: null;
|
|
337
|
+
const nextTokens = typeof meta.tokensUsed === 'number' && Number.isFinite(meta.tokensUsed) && meta.tokensUsed >= 0
|
|
338
|
+
? Math.floor(meta.tokensUsed)
|
|
339
|
+
: null;
|
|
340
|
+
const nextLimit = typeof meta.tokenLimit === 'number' && Number.isFinite(meta.tokenLimit) && meta.tokenLimit > 0
|
|
341
|
+
? Math.floor(meta.tokenLimit)
|
|
342
|
+
: null;
|
|
343
|
+
const nextThinking = typeof meta.thinkingMs === 'number' && Number.isFinite(meta.thinkingMs) && meta.thinkingMs >= 0
|
|
344
|
+
? Math.floor(meta.thinkingMs)
|
|
345
|
+
: null;
|
|
346
|
+
const nextThinkingHasContent = !!meta.thinkingHasContent;
|
|
347
|
+
if (this.metaElapsedSeconds === nextElapsed &&
|
|
348
|
+
this.metaTokensUsed === nextTokens &&
|
|
349
|
+
this.metaTokenLimit === nextLimit &&
|
|
350
|
+
this.metaThinkingMs === nextThinking &&
|
|
351
|
+
this.metaThinkingHasContent === nextThinkingHasContent) {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
this.metaElapsedSeconds = nextElapsed;
|
|
355
|
+
this.metaTokensUsed = nextTokens;
|
|
356
|
+
this.metaTokenLimit = nextLimit;
|
|
357
|
+
this.metaThinkingMs = nextThinking;
|
|
358
|
+
this.metaThinkingHasContent = nextThinkingHasContent;
|
|
359
|
+
this.scheduleRender();
|
|
360
|
+
}
|
|
767
361
|
/**
|
|
768
362
|
* Keep mode toggles (verification/auto-continue) visible in the control bar.
|
|
769
363
|
* Hotkey labels remain stable so the bar looks the same before/during streaming.
|
|
@@ -773,26 +367,22 @@ export class TerminalInput extends EventEmitter {
|
|
|
773
367
|
const nextAutoContinue = !!options.autoContinueEnabled;
|
|
774
368
|
const nextVerifyHotkey = options.verificationHotkey ?? this.verificationHotkey;
|
|
775
369
|
const nextAutoHotkey = options.autoContinueHotkey ?? this.autoContinueHotkey;
|
|
370
|
+
const nextThinkingHotkey = options.thinkingHotkey ?? this.thinkingHotkey;
|
|
371
|
+
const nextThinkingLabel = options.thinkingModeLabel === undefined ? this.thinkingModeLabel : (options.thinkingModeLabel || null);
|
|
776
372
|
if (this.verificationEnabled === nextVerification &&
|
|
777
373
|
this.autoContinueEnabled === nextAutoContinue &&
|
|
778
374
|
this.verificationHotkey === nextVerifyHotkey &&
|
|
779
|
-
this.autoContinueHotkey === nextAutoHotkey
|
|
375
|
+
this.autoContinueHotkey === nextAutoHotkey &&
|
|
376
|
+
this.thinkingHotkey === nextThinkingHotkey &&
|
|
377
|
+
this.thinkingModeLabel === nextThinkingLabel) {
|
|
780
378
|
return;
|
|
781
379
|
}
|
|
782
380
|
this.verificationEnabled = nextVerification;
|
|
783
381
|
this.autoContinueEnabled = nextAutoContinue;
|
|
784
382
|
this.verificationHotkey = nextVerifyHotkey;
|
|
785
383
|
this.autoContinueHotkey = nextAutoHotkey;
|
|
786
|
-
this.
|
|
787
|
-
|
|
788
|
-
/**
|
|
789
|
-
* Set the model info string (e.g., "OpenAI · gpt-4")
|
|
790
|
-
* This is displayed persistently above the input area.
|
|
791
|
-
*/
|
|
792
|
-
setModelInfo(info) {
|
|
793
|
-
if (this.modelInfo === info)
|
|
794
|
-
return;
|
|
795
|
-
this.modelInfo = info;
|
|
384
|
+
this.thinkingHotkey = nextThinkingHotkey;
|
|
385
|
+
this.thinkingModeLabel = nextThinkingLabel;
|
|
796
386
|
this.scheduleRender();
|
|
797
387
|
}
|
|
798
388
|
/**
|
|
@@ -805,39 +395,154 @@ export class TerminalInput extends EventEmitter {
|
|
|
805
395
|
this.scheduleRender();
|
|
806
396
|
}
|
|
807
397
|
/**
|
|
808
|
-
*
|
|
398
|
+
* Surface model/provider context in the controls bar.
|
|
399
|
+
*/
|
|
400
|
+
setModelContext(options) {
|
|
401
|
+
const nextModel = options.model?.trim() || null;
|
|
402
|
+
const nextProvider = options.provider?.trim() || null;
|
|
403
|
+
if (this.modelLabel === nextModel && this.providerLabel === nextProvider) {
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
this.modelLabel = nextModel;
|
|
407
|
+
this.providerLabel = nextProvider;
|
|
408
|
+
this.scheduleRender();
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Render the floating input area at contentRow.
|
|
809
412
|
*
|
|
810
|
-
*
|
|
811
|
-
*
|
|
413
|
+
* The chat box "floats" - it renders right below the last streamed content.
|
|
414
|
+
* As content is added, contentRow advances, and the chat box moves down.
|
|
415
|
+
* No scroll regions - pure floating behavior.
|
|
812
416
|
*/
|
|
813
417
|
render() {
|
|
814
418
|
if (!this.canRender())
|
|
815
419
|
return;
|
|
816
420
|
if (this.isRendering)
|
|
817
421
|
return;
|
|
422
|
+
const streamingActive = this.mode === 'streaming' || isStreamingMode();
|
|
423
|
+
// During streaming, throttle re-renders
|
|
424
|
+
if (streamingActive && this.lastStreamingRender > 0) {
|
|
425
|
+
const elapsed = Date.now() - this.lastStreamingRender;
|
|
426
|
+
const waitMs = Math.max(0, this.streamingRenderInterval - elapsed);
|
|
427
|
+
if (waitMs > 0) {
|
|
428
|
+
this.renderDirty = true;
|
|
429
|
+
this.scheduleStreamingRender(waitMs);
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
818
433
|
const shouldSkip = !this.renderDirty &&
|
|
819
434
|
this.buffer === this.lastRenderContent &&
|
|
820
435
|
this.cursor === this.lastRenderCursor;
|
|
821
436
|
this.renderDirty = false;
|
|
822
|
-
// Skip if nothing changed (unless explicitly forced)
|
|
823
437
|
if (shouldSkip) {
|
|
824
438
|
return;
|
|
825
439
|
}
|
|
826
|
-
// If write lock is held, defer render
|
|
827
440
|
if (writeLock.isLocked()) {
|
|
828
441
|
writeLock.safeWrite(() => this.render());
|
|
829
442
|
return;
|
|
830
443
|
}
|
|
444
|
+
this.renderFloatingInputArea();
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Core floating input area renderer.
|
|
448
|
+
* Chat box always floats at contentRow (below streamed content).
|
|
449
|
+
* This creates "persistent bottom floating" behavior.
|
|
450
|
+
*/
|
|
451
|
+
renderFloatingInputArea() {
|
|
452
|
+
const { rows, cols } = this.getSize();
|
|
453
|
+
const maxWidth = Math.max(8, cols - 4);
|
|
454
|
+
const streamingActive = this.mode === 'streaming' || isStreamingMode();
|
|
455
|
+
// Wrap buffer into display lines
|
|
456
|
+
const { lines, cursorLine, cursorCol } = this.wrapBuffer(maxWidth);
|
|
457
|
+
const maxVisible = Math.max(1, Math.min(this.config.maxLines, rows - 3));
|
|
458
|
+
const displayLines = Math.min(lines.length, maxVisible);
|
|
459
|
+
const metaLines = this.buildMetaLines(cols - 2);
|
|
460
|
+
// Calculate display window (keep cursor visible)
|
|
461
|
+
let startLine = 0;
|
|
462
|
+
if (lines.length > displayLines) {
|
|
463
|
+
startLine = Math.max(0, cursorLine - displayLines + 1);
|
|
464
|
+
startLine = Math.min(startLine, lines.length - displayLines);
|
|
465
|
+
}
|
|
466
|
+
const visibleLines = lines.slice(startLine, startLine + displayLines);
|
|
467
|
+
const adjustedCursorLine = cursorLine - startLine;
|
|
468
|
+
// Chat box height
|
|
469
|
+
const chatBoxHeight = metaLines.length + 1 + displayLines + 1;
|
|
470
|
+
// Chat box floats at contentRow - right below the last content
|
|
471
|
+
// This is "persistent bottom floating" - always at bottom of content
|
|
472
|
+
const chatBoxStartRow = this.contentRow;
|
|
473
|
+
writeLock.lock('terminalInput.renderFloating');
|
|
831
474
|
this.isRendering = true;
|
|
832
|
-
writeLock.lock('terminalInput.render');
|
|
833
475
|
try {
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
476
|
+
// Hide cursor during render
|
|
477
|
+
this.write(ESC.HIDE);
|
|
478
|
+
this.write(ESC.RESET);
|
|
479
|
+
// Clear the chat box area
|
|
480
|
+
for (let i = 0; i < chatBoxHeight; i++) {
|
|
481
|
+
this.write(ESC.TO(chatBoxStartRow + i, 1));
|
|
482
|
+
this.write(ESC.CLEAR_LINE);
|
|
837
483
|
}
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
484
|
+
let currentRow = chatBoxStartRow;
|
|
485
|
+
// Meta/status header
|
|
486
|
+
for (const metaLine of metaLines) {
|
|
487
|
+
this.write(ESC.TO(currentRow, 1));
|
|
488
|
+
this.write(metaLine);
|
|
489
|
+
currentRow += 1;
|
|
490
|
+
}
|
|
491
|
+
// Separator line
|
|
492
|
+
this.write(ESC.TO(currentRow, 1));
|
|
493
|
+
this.write(renderDivider(cols - 2));
|
|
494
|
+
currentRow += 1;
|
|
495
|
+
// Render input lines
|
|
496
|
+
let finalRow = currentRow;
|
|
497
|
+
let finalCol = 3;
|
|
498
|
+
for (let i = 0; i < visibleLines.length; i++) {
|
|
499
|
+
const rowNum = currentRow + i;
|
|
500
|
+
this.write(ESC.TO(rowNum, 1));
|
|
501
|
+
const line = visibleLines[i] ?? '';
|
|
502
|
+
const isFirstLine = (startLine + i) === 0;
|
|
503
|
+
const isCursorLine = i === adjustedCursorLine;
|
|
504
|
+
this.write(ESC.BG_DARK);
|
|
505
|
+
this.write(ESC.DIM);
|
|
506
|
+
this.write(isFirstLine ? this.config.promptChar : this.config.continuationChar);
|
|
507
|
+
this.write(ESC.RESET);
|
|
508
|
+
this.write(ESC.BG_DARK);
|
|
509
|
+
if (isCursorLine) {
|
|
510
|
+
const col = Math.min(cursorCol, line.length);
|
|
511
|
+
const before = line.slice(0, col);
|
|
512
|
+
const at = col < line.length ? line[col] : ' ';
|
|
513
|
+
const after = col < line.length ? line.slice(col + 1) : '';
|
|
514
|
+
this.write(before);
|
|
515
|
+
this.write(ESC.REVERSE + ESC.BOLD);
|
|
516
|
+
this.write(at);
|
|
517
|
+
this.write(ESC.RESET + ESC.BG_DARK);
|
|
518
|
+
this.write(after);
|
|
519
|
+
finalRow = rowNum;
|
|
520
|
+
finalCol = this.config.promptChar.length + col + 1;
|
|
521
|
+
}
|
|
522
|
+
else {
|
|
523
|
+
this.write(line);
|
|
524
|
+
}
|
|
525
|
+
// Pad to edge
|
|
526
|
+
const lineLen = this.config.promptChar.length + line.length + (isCursorLine && cursorCol >= line.length ? 1 : 0);
|
|
527
|
+
const padding = Math.max(0, cols - lineLen - 1);
|
|
528
|
+
if (padding > 0)
|
|
529
|
+
this.write(' '.repeat(padding));
|
|
530
|
+
this.write(ESC.RESET);
|
|
531
|
+
}
|
|
532
|
+
// Mode controls line
|
|
533
|
+
const controlRow = currentRow + visibleLines.length;
|
|
534
|
+
this.write(ESC.TO(controlRow, 1));
|
|
535
|
+
this.write(this.buildModeControls(cols));
|
|
536
|
+
// Position cursor in input box
|
|
537
|
+
this.write(ESC.TO(finalRow, Math.min(finalCol, cols)));
|
|
538
|
+
this.write(ESC.SHOW);
|
|
539
|
+
// Update state
|
|
540
|
+
this.lastRenderContent = this.buffer;
|
|
541
|
+
this.lastRenderCursor = this.cursor;
|
|
542
|
+
this.lastStreamingRender = streamingActive ? Date.now() : 0;
|
|
543
|
+
if (this.streamingRenderTimer) {
|
|
544
|
+
clearTimeout(this.streamingRenderTimer);
|
|
545
|
+
this.streamingRenderTimer = null;
|
|
841
546
|
}
|
|
842
547
|
}
|
|
843
548
|
finally {
|
|
@@ -846,99 +551,217 @@ export class TerminalInput extends EventEmitter {
|
|
|
846
551
|
}
|
|
847
552
|
}
|
|
848
553
|
/**
|
|
849
|
-
* Build
|
|
850
|
-
*
|
|
554
|
+
* Build one or more compact meta lines above the divider (thinking, status, usage).
|
|
555
|
+
* During streaming, shows model line pinned above streaming info.
|
|
851
556
|
*/
|
|
852
|
-
|
|
853
|
-
const
|
|
854
|
-
const
|
|
855
|
-
//
|
|
856
|
-
if (this.
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
557
|
+
buildMetaLines(width) {
|
|
558
|
+
const streamingActive = this.mode === 'streaming' || isStreamingMode();
|
|
559
|
+
const lines = [];
|
|
560
|
+
// Model line should ALWAYS be shown (pinned above streaming content)
|
|
561
|
+
if (this.modelLabel) {
|
|
562
|
+
const modelText = this.providerLabel
|
|
563
|
+
? `model ${this.modelLabel} @ ${this.providerLabel}`
|
|
564
|
+
: `model ${this.modelLabel}`;
|
|
565
|
+
lines.push(renderStatusLine([{ text: modelText, tone: 'info' }], width));
|
|
566
|
+
}
|
|
567
|
+
// During streaming, add a compact status line with essential info
|
|
568
|
+
if (streamingActive) {
|
|
569
|
+
const parts = [];
|
|
570
|
+
// Essential streaming info
|
|
571
|
+
if (this.metaThinkingMs !== null) {
|
|
572
|
+
parts.push({ text: formatThinking(this.metaThinkingMs, this.metaThinkingHasContent), tone: 'info' });
|
|
863
573
|
}
|
|
864
|
-
|
|
574
|
+
if (this.metaElapsedSeconds !== null) {
|
|
575
|
+
parts.push({ text: this.formatElapsedLabel(this.metaElapsedSeconds), tone: 'muted' });
|
|
576
|
+
}
|
|
577
|
+
parts.push({ text: 'esc to stop', tone: 'warn' });
|
|
578
|
+
if (parts.length) {
|
|
579
|
+
lines.push(renderStatusLine(parts, width));
|
|
580
|
+
}
|
|
581
|
+
return lines;
|
|
865
582
|
}
|
|
866
|
-
//
|
|
867
|
-
if (this.
|
|
868
|
-
|
|
583
|
+
// Non-streaming: show full status info (model line already added above)
|
|
584
|
+
if (this.metaThinkingMs !== null) {
|
|
585
|
+
const thinkingText = formatThinking(this.metaThinkingMs, this.metaThinkingHasContent);
|
|
586
|
+
lines.push(renderStatusLine([{ text: thinkingText, tone: 'info' }], width));
|
|
869
587
|
}
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
588
|
+
const statusParts = [];
|
|
589
|
+
const statusLabel = this.statusMessage ?? this.streamingLabel;
|
|
590
|
+
if (statusLabel) {
|
|
591
|
+
statusParts.push({ text: statusLabel, tone: 'info' });
|
|
874
592
|
}
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
parts.push(`\x1b[33m⚠ ${this.overrideStatusMessage}\x1b[0m`); // Yellow
|
|
593
|
+
if (this.metaElapsedSeconds !== null) {
|
|
594
|
+
statusParts.push({ text: this.formatElapsedLabel(this.metaElapsedSeconds), tone: 'muted' });
|
|
878
595
|
}
|
|
879
|
-
|
|
880
|
-
if (
|
|
881
|
-
|
|
596
|
+
const tokensRemaining = this.computeTokensRemaining();
|
|
597
|
+
if (tokensRemaining !== null) {
|
|
598
|
+
statusParts.push({ text: `↓ ${tokensRemaining}`, tone: 'muted' });
|
|
882
599
|
}
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
600
|
+
if (statusParts.length) {
|
|
601
|
+
lines.push(renderStatusLine(statusParts, width));
|
|
602
|
+
}
|
|
603
|
+
const usageParts = [];
|
|
604
|
+
if (this.metaTokensUsed !== null) {
|
|
605
|
+
const formattedUsed = this.formatTokenCount(this.metaTokensUsed);
|
|
606
|
+
const formattedLimit = this.metaTokenLimit ? `/${this.formatTokenCount(this.metaTokenLimit)}` : '';
|
|
607
|
+
usageParts.push({ text: `tokens ${formattedUsed}${formattedLimit}`, tone: 'muted' });
|
|
608
|
+
}
|
|
609
|
+
if (this.contextUsage !== null) {
|
|
610
|
+
const tone = this.contextUsage >= 75 ? 'warn' : 'muted';
|
|
611
|
+
const left = Math.max(0, 100 - this.contextUsage);
|
|
612
|
+
usageParts.push({ text: `context used ${this.contextUsage}% (${left}% left)`, tone });
|
|
886
613
|
}
|
|
887
|
-
if (
|
|
888
|
-
|
|
614
|
+
if (this.queue.length > 0) {
|
|
615
|
+
usageParts.push({ text: `queued ${this.queue.length}`, tone: 'info' });
|
|
889
616
|
}
|
|
890
|
-
|
|
891
|
-
|
|
617
|
+
if (usageParts.length) {
|
|
618
|
+
lines.push(renderStatusLine(usageParts, width));
|
|
619
|
+
}
|
|
620
|
+
return lines;
|
|
892
621
|
}
|
|
893
622
|
/**
|
|
894
|
-
* Build mode controls line
|
|
895
|
-
*
|
|
896
|
-
*
|
|
897
|
-
* Layout: [toggles on left] ... [context info on right]
|
|
623
|
+
* Build Claude Code style mode controls line.
|
|
624
|
+
* Combines streaming label + override status + main status for simultaneous display.
|
|
898
625
|
*/
|
|
899
626
|
buildModeControls(cols) {
|
|
900
|
-
const
|
|
901
|
-
|
|
902
|
-
const
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
// Edit mode (green=auto, yellow=ask) - per schema.editMode
|
|
906
|
-
if (this.editMode === 'display-edits') {
|
|
907
|
-
toggles.push(`${GREEN}⏵⏵ auto-edit${R}`);
|
|
627
|
+
const width = Math.max(8, cols - 2);
|
|
628
|
+
const leftParts = [];
|
|
629
|
+
const rightParts = [];
|
|
630
|
+
if (this.streamingLabel) {
|
|
631
|
+
leftParts.push({ text: `◐ ${this.streamingLabel}`, tone: 'info' });
|
|
908
632
|
}
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
}
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
633
|
+
if (this.overrideStatusMessage) {
|
|
634
|
+
leftParts.push({ text: `⚠ ${this.overrideStatusMessage}`, tone: 'warn' });
|
|
635
|
+
}
|
|
636
|
+
if (this.statusMessage) {
|
|
637
|
+
leftParts.push({ text: this.statusMessage, tone: this.streamingLabel ? 'muted' : 'info' });
|
|
638
|
+
}
|
|
639
|
+
const editHotkey = this.formatHotkey('shift+tab');
|
|
640
|
+
const editLabel = this.editMode === 'display-edits' ? 'edits: accept' : 'edits: ask';
|
|
641
|
+
const editTone = this.editMode === 'display-edits' ? 'success' : 'muted';
|
|
642
|
+
leftParts.push({ text: `${editHotkey} ${editLabel}`, tone: editTone });
|
|
643
|
+
const verifyHotkey = this.formatHotkey(this.verificationHotkey);
|
|
644
|
+
const verifyLabel = this.verificationEnabled ? 'verify:on' : 'verify:off';
|
|
645
|
+
leftParts.push({ text: `${verifyHotkey} ${verifyLabel}`, tone: this.verificationEnabled ? 'success' : 'muted' });
|
|
646
|
+
const continueHotkey = this.formatHotkey(this.autoContinueHotkey);
|
|
647
|
+
const continueLabel = this.autoContinueEnabled ? 'auto:on' : 'auto:off';
|
|
648
|
+
leftParts.push({ text: `${continueHotkey} ${continueLabel}`, tone: this.autoContinueEnabled ? 'info' : 'muted' });
|
|
649
|
+
if (this.queue.length > 0 && this.mode !== 'streaming') {
|
|
650
|
+
leftParts.push({ text: `queued ${this.queue.length}`, tone: 'info' });
|
|
651
|
+
}
|
|
652
|
+
if (this.buffer.includes('\n')) {
|
|
653
|
+
const lineCount = this.buffer.split('\n').length;
|
|
654
|
+
leftParts.push({ text: `${lineCount} lines`, tone: 'muted' });
|
|
655
|
+
}
|
|
656
|
+
if (this.pastePlaceholders.length > 0) {
|
|
657
|
+
const latest = this.pastePlaceholders[this.pastePlaceholders.length - 1];
|
|
658
|
+
leftParts.push({
|
|
659
|
+
text: `paste #${latest.id} +${latest.lineCount} lines (⌫ to drop)`,
|
|
660
|
+
tone: 'info',
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
const contextRemaining = this.computeContextRemaining();
|
|
664
|
+
if (this.thinkingModeLabel) {
|
|
665
|
+
const thinkingHotkey = this.formatHotkey(this.thinkingHotkey);
|
|
666
|
+
rightParts.push({ text: `${thinkingHotkey} thinking:${this.thinkingModeLabel}`, tone: 'info' });
|
|
667
|
+
}
|
|
668
|
+
// Show model in controls only when NOT streaming (during streaming it's in meta lines)
|
|
669
|
+
const streamingActive = this.mode === 'streaming' || isStreamingMode();
|
|
670
|
+
if (this.modelLabel && !streamingActive) {
|
|
671
|
+
const modelText = this.providerLabel ? `${this.modelLabel} @ ${this.providerLabel}` : this.modelLabel;
|
|
672
|
+
rightParts.push({ text: modelText, tone: 'muted' });
|
|
673
|
+
}
|
|
674
|
+
if (contextRemaining !== null) {
|
|
675
|
+
const tone = contextRemaining <= 10 ? 'warn' : 'muted';
|
|
676
|
+
const label = contextRemaining === 0 && this.contextUsage !== null
|
|
677
|
+
? 'Context auto-compact imminent'
|
|
678
|
+
: `Context left until auto-compact: ${contextRemaining}%`;
|
|
679
|
+
rightParts.push({ text: label, tone });
|
|
680
|
+
}
|
|
681
|
+
if (!rightParts.length || width < 60) {
|
|
682
|
+
const merged = rightParts.length ? [...leftParts, ...rightParts] : leftParts;
|
|
683
|
+
return renderStatusLine(merged, width);
|
|
684
|
+
}
|
|
685
|
+
const leftWidth = Math.max(12, Math.floor(width * 0.6));
|
|
686
|
+
const rightWidth = Math.max(14, width - leftWidth - 1);
|
|
687
|
+
const leftText = renderStatusLine(leftParts, leftWidth);
|
|
688
|
+
const rightText = renderStatusLine(rightParts, rightWidth);
|
|
689
|
+
const spacing = Math.max(1, width - this.visibleLength(leftText) - this.visibleLength(rightText));
|
|
690
|
+
return `${leftText}${' '.repeat(spacing)}${rightText}`;
|
|
691
|
+
}
|
|
692
|
+
formatHotkey(hotkey) {
|
|
693
|
+
const normalized = hotkey.trim().toLowerCase();
|
|
694
|
+
if (!normalized)
|
|
695
|
+
return hotkey;
|
|
696
|
+
const parts = normalized.split('+').filter(Boolean);
|
|
697
|
+
const map = {
|
|
698
|
+
shift: '⇧',
|
|
699
|
+
sh: '⇧',
|
|
700
|
+
alt: '⌥',
|
|
701
|
+
option: '⌥',
|
|
702
|
+
opt: '⌥',
|
|
703
|
+
ctrl: '⌃',
|
|
704
|
+
control: '⌃',
|
|
705
|
+
cmd: '⌘',
|
|
706
|
+
meta: '⌘',
|
|
707
|
+
};
|
|
708
|
+
const formatted = parts
|
|
709
|
+
.map((part) => {
|
|
710
|
+
const symbol = map[part];
|
|
711
|
+
if (symbol)
|
|
712
|
+
return symbol;
|
|
713
|
+
return part.length === 1 ? part.toUpperCase() : part.toUpperCase();
|
|
714
|
+
})
|
|
715
|
+
.join('');
|
|
716
|
+
return formatted || hotkey;
|
|
717
|
+
}
|
|
718
|
+
computeContextRemaining() {
|
|
719
|
+
if (this.contextUsage === null) {
|
|
720
|
+
return null;
|
|
721
|
+
}
|
|
722
|
+
return Math.max(0, this.contextAutoCompactThreshold - this.contextUsage);
|
|
723
|
+
}
|
|
724
|
+
computeTokensRemaining() {
|
|
725
|
+
if (this.metaTokensUsed === null || this.metaTokenLimit === null) {
|
|
726
|
+
return null;
|
|
727
|
+
}
|
|
728
|
+
const remaining = Math.max(0, this.metaTokenLimit - this.metaTokensUsed);
|
|
729
|
+
return this.formatTokenCount(remaining);
|
|
730
|
+
}
|
|
731
|
+
formatElapsedLabel(seconds) {
|
|
732
|
+
if (seconds < 60) {
|
|
733
|
+
return `${seconds}s`;
|
|
734
|
+
}
|
|
735
|
+
const mins = Math.floor(seconds / 60);
|
|
736
|
+
const secs = seconds % 60;
|
|
737
|
+
return secs > 0 ? `${mins}m ${secs}s` : `${mins}m`;
|
|
738
|
+
}
|
|
739
|
+
formatTokenCount(value) {
|
|
740
|
+
if (!Number.isFinite(value)) {
|
|
741
|
+
return `${value}`;
|
|
742
|
+
}
|
|
743
|
+
if (value >= 1_000_000) {
|
|
744
|
+
return `${(value / 1_000_000).toFixed(1)}M`;
|
|
745
|
+
}
|
|
746
|
+
if (value >= 1_000) {
|
|
747
|
+
return `${(value / 1_000).toFixed(1)}k`;
|
|
748
|
+
}
|
|
749
|
+
return `${Math.round(value)}`;
|
|
750
|
+
}
|
|
751
|
+
visibleLength(value) {
|
|
752
|
+
const ansiPattern = /\u001B\[[0-?]*[ -/]*[@-~]/g;
|
|
753
|
+
return value.replace(ansiPattern, '').length;
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* Debug-only snapshot used by tests to assert rendered strings without
|
|
757
|
+
* needing a TTY. Not used by production code.
|
|
758
|
+
*/
|
|
759
|
+
getDebugUiSnapshot(width) {
|
|
760
|
+
const cols = Math.max(8, width ?? this.getSize().cols);
|
|
761
|
+
return {
|
|
762
|
+
meta: this.buildMetaLines(cols - 2),
|
|
763
|
+
controls: this.buildModeControls(cols),
|
|
764
|
+
};
|
|
942
765
|
}
|
|
943
766
|
/**
|
|
944
767
|
* Force a re-render
|
|
@@ -961,17 +784,12 @@ export class TerminalInput extends EventEmitter {
|
|
|
961
784
|
handleResize() {
|
|
962
785
|
this.lastRenderContent = '';
|
|
963
786
|
this.lastRenderCursor = -1;
|
|
964
|
-
|
|
965
|
-
this.setPinnedHeaderLines(this.pinnedTopRows);
|
|
787
|
+
this.resetStreamingRenderThrottle();
|
|
966
788
|
this.scheduleRender();
|
|
967
789
|
}
|
|
968
790
|
/**
|
|
969
791
|
* Register with display's output interceptor to position cursor correctly.
|
|
970
|
-
*
|
|
971
|
-
* not the protected bottom area where the input is rendered.
|
|
972
|
-
*
|
|
973
|
-
* NOTE: With scroll region properly set, content naturally stays within
|
|
974
|
-
* the region boundaries - no cursor manipulation needed per-write.
|
|
792
|
+
* Output is written at contentRow, which advances as content is written.
|
|
975
793
|
*/
|
|
976
794
|
registerOutputInterceptor(display) {
|
|
977
795
|
if (this.outputInterceptorCleanup) {
|
|
@@ -979,25 +797,78 @@ export class TerminalInput extends EventEmitter {
|
|
|
979
797
|
}
|
|
980
798
|
this.outputInterceptorCleanup = display.registerOutputInterceptor({
|
|
981
799
|
beforeWrite: () => {
|
|
982
|
-
//
|
|
983
|
-
//
|
|
800
|
+
// During streaming: clear chat box and position cursor at contentRow
|
|
801
|
+
// This allows content to be written where the chat box was
|
|
802
|
+
const metaLines = this.buildMetaLines(this.getSize().cols - 2);
|
|
803
|
+
const chatBoxHeight = metaLines.length + 1 + 2 + 1; // meta + divider + 1 line input + controls
|
|
804
|
+
// Clear the chat box area so content can be written there
|
|
805
|
+
for (let i = 0; i < chatBoxHeight; i++) {
|
|
806
|
+
this.write(ESC.TO(this.contentRow + i, 1));
|
|
807
|
+
this.write(ESC.CLEAR_LINE);
|
|
808
|
+
}
|
|
809
|
+
// Position cursor at contentRow for writing new content
|
|
810
|
+
this.write(ESC.TO(this.contentRow, 1));
|
|
984
811
|
},
|
|
985
|
-
afterWrite: () => {
|
|
986
|
-
//
|
|
812
|
+
afterWrite: (content) => {
|
|
813
|
+
// Advance contentRow by number of newlines in the content
|
|
814
|
+
const newlines = content ? (content.match(/\n/g) || []).length : 0;
|
|
815
|
+
this.contentRow += newlines;
|
|
816
|
+
// Schedule re-render to show chat box at new position (below new content)
|
|
817
|
+
this.scheduleRender();
|
|
987
818
|
},
|
|
988
819
|
});
|
|
989
820
|
}
|
|
821
|
+
/**
|
|
822
|
+
* Write content above the floating chat box.
|
|
823
|
+
* Clears the chat box, writes content at contentRow, advances contentRow, re-renders chat box.
|
|
824
|
+
*/
|
|
825
|
+
writeToScrollRegion(content) {
|
|
826
|
+
if (!content)
|
|
827
|
+
return;
|
|
828
|
+
// Get chat box dimensions for clearing
|
|
829
|
+
const { cols } = this.getSize();
|
|
830
|
+
const metaLines = this.buildMetaLines(cols - 2);
|
|
831
|
+
const chatBoxHeight = metaLines.length + 1 + 1 + 1 + 2; // meta + divider + input + controls + buffer
|
|
832
|
+
// Clear the current chat box area (it will re-render at new position)
|
|
833
|
+
for (let i = 0; i < chatBoxHeight; i++) {
|
|
834
|
+
this.write(ESC.TO(this.contentRow + i, 1));
|
|
835
|
+
this.write(ESC.CLEAR_LINE);
|
|
836
|
+
}
|
|
837
|
+
// Write content at contentRow
|
|
838
|
+
this.write(ESC.TO(this.contentRow, 1));
|
|
839
|
+
this.write(content);
|
|
840
|
+
// Advance contentRow by number of newlines
|
|
841
|
+
const newlines = (content.match(/\n/g) || []).length;
|
|
842
|
+
this.contentRow += newlines;
|
|
843
|
+
// Re-render chat box at new position (below the content just written)
|
|
844
|
+
this.forceRender();
|
|
845
|
+
}
|
|
846
|
+
/**
|
|
847
|
+
* Reset content position to row 1.
|
|
848
|
+
* Does NOT clear the terminal - content starts from current position.
|
|
849
|
+
*/
|
|
850
|
+
resetContentPosition() {
|
|
851
|
+
this.contentRow = 1;
|
|
852
|
+
}
|
|
853
|
+
/**
|
|
854
|
+
* Set the content row explicitly (used after banner is written).
|
|
855
|
+
* This tells the input where content should start flowing from.
|
|
856
|
+
*/
|
|
857
|
+
setContentRow(row) {
|
|
858
|
+
this.contentRow = Math.max(1, row);
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* Get the current content row position.
|
|
862
|
+
*/
|
|
863
|
+
getContentRow() {
|
|
864
|
+
return this.contentRow;
|
|
865
|
+
}
|
|
990
866
|
/**
|
|
991
867
|
* Dispose and clean up
|
|
992
868
|
*/
|
|
993
869
|
dispose() {
|
|
994
870
|
if (this.disposed)
|
|
995
871
|
return;
|
|
996
|
-
// Clean up streaming render timer
|
|
997
|
-
if (this.streamingRenderTimer) {
|
|
998
|
-
clearInterval(this.streamingRenderTimer);
|
|
999
|
-
this.streamingRenderTimer = null;
|
|
1000
|
-
}
|
|
1001
872
|
// Clean up output interceptor
|
|
1002
873
|
if (this.outputInterceptorCleanup) {
|
|
1003
874
|
this.outputInterceptorCleanup();
|
|
@@ -1005,6 +876,7 @@ export class TerminalInput extends EventEmitter {
|
|
|
1005
876
|
}
|
|
1006
877
|
this.disposed = true;
|
|
1007
878
|
this.enabled = false;
|
|
879
|
+
this.resetStreamingRenderThrottle();
|
|
1008
880
|
this.disableBracketedPaste();
|
|
1009
881
|
this.buffer = '';
|
|
1010
882
|
this.queue = [];
|
|
@@ -1109,22 +981,7 @@ export class TerminalInput extends EventEmitter {
|
|
|
1109
981
|
this.toggleEditMode();
|
|
1110
982
|
return true;
|
|
1111
983
|
}
|
|
1112
|
-
|
|
1113
|
-
if (this.findPlaceholderAt(this.cursor)) {
|
|
1114
|
-
this.togglePasteExpansion();
|
|
1115
|
-
}
|
|
1116
|
-
else {
|
|
1117
|
-
this.toggleThinking();
|
|
1118
|
-
}
|
|
1119
|
-
return true;
|
|
1120
|
-
case 'escape':
|
|
1121
|
-
// Esc: interrupt if streaming, otherwise clear buffer
|
|
1122
|
-
if (this.mode === 'streaming') {
|
|
1123
|
-
this.emit('interrupt');
|
|
1124
|
-
}
|
|
1125
|
-
else if (this.buffer.length > 0) {
|
|
1126
|
-
this.clear();
|
|
1127
|
-
}
|
|
984
|
+
this.insertText(' ');
|
|
1128
985
|
return true;
|
|
1129
986
|
}
|
|
1130
987
|
return false;
|
|
@@ -1142,7 +999,6 @@ export class TerminalInput extends EventEmitter {
|
|
|
1142
999
|
this.insertPlainText(chunk, insertPos);
|
|
1143
1000
|
this.cursor = insertPos + chunk.length;
|
|
1144
1001
|
this.emit('change', this.buffer);
|
|
1145
|
-
this.updateSuggestions();
|
|
1146
1002
|
this.scheduleRender();
|
|
1147
1003
|
}
|
|
1148
1004
|
insertNewline() {
|
|
@@ -1167,7 +1023,6 @@ export class TerminalInput extends EventEmitter {
|
|
|
1167
1023
|
this.cursor = Math.max(0, this.cursor - 1);
|
|
1168
1024
|
}
|
|
1169
1025
|
this.emit('change', this.buffer);
|
|
1170
|
-
this.updateSuggestions();
|
|
1171
1026
|
this.scheduleRender();
|
|
1172
1027
|
}
|
|
1173
1028
|
deleteForward() {
|
|
@@ -1395,13 +1250,12 @@ export class TerminalInput extends EventEmitter {
|
|
|
1395
1250
|
timestamp: Date.now(),
|
|
1396
1251
|
});
|
|
1397
1252
|
this.emit('queue', text);
|
|
1398
|
-
this.clear(); // Clear immediately for queued input
|
|
1253
|
+
this.clear(); // Clear immediately for queued input
|
|
1399
1254
|
}
|
|
1400
1255
|
else {
|
|
1401
|
-
// In idle mode, clear the input
|
|
1402
|
-
// The
|
|
1403
|
-
|
|
1404
|
-
this.clear(true); // Skip render - streaming will handle display
|
|
1256
|
+
// In idle mode, clear the input first, then emit submit.
|
|
1257
|
+
// The prompt will be logged as a visible message by the caller.
|
|
1258
|
+
this.clear();
|
|
1405
1259
|
this.emit('submit', text);
|
|
1406
1260
|
}
|
|
1407
1261
|
}
|
|
@@ -1418,7 +1272,9 @@ export class TerminalInput extends EventEmitter {
|
|
|
1418
1272
|
if (available <= 0)
|
|
1419
1273
|
return;
|
|
1420
1274
|
const chunk = clean.slice(0, available);
|
|
1421
|
-
|
|
1275
|
+
const isMultiline = isMultilinePaste(chunk);
|
|
1276
|
+
const isShortMultiline = isMultiline && this.shouldInlineMultiline(chunk);
|
|
1277
|
+
if (isMultiline && !isShortMultiline) {
|
|
1422
1278
|
this.insertPastePlaceholder(chunk);
|
|
1423
1279
|
}
|
|
1424
1280
|
else {
|
|
@@ -1554,17 +1410,19 @@ export class TerminalInput extends EventEmitter {
|
|
|
1554
1410
|
this.shiftPlaceholders(position, text.length);
|
|
1555
1411
|
this.buffer = this.buffer.slice(0, position) + text + this.buffer.slice(position);
|
|
1556
1412
|
}
|
|
1413
|
+
shouldInlineMultiline(content) {
|
|
1414
|
+
const lines = content.split('\n').length;
|
|
1415
|
+
const maxInlineLines = 4;
|
|
1416
|
+
const maxInlineChars = 240;
|
|
1417
|
+
return lines <= maxInlineLines && content.length <= maxInlineChars;
|
|
1418
|
+
}
|
|
1557
1419
|
findPlaceholderAt(position) {
|
|
1558
1420
|
return this.pastePlaceholders.find((ph) => position >= ph.start && position < ph.end) ?? null;
|
|
1559
1421
|
}
|
|
1560
|
-
buildPlaceholder(
|
|
1422
|
+
buildPlaceholder(lineCount) {
|
|
1561
1423
|
const id = ++this.pasteCounter;
|
|
1562
|
-
const
|
|
1563
|
-
|
|
1564
|
-
const preview = summary.preview.length > 30
|
|
1565
|
-
? `${summary.preview.slice(0, 30)}...`
|
|
1566
|
-
: summary.preview;
|
|
1567
|
-
const placeholder = `[📋 #${id}${lang} ${summary.lineCount}L] "${preview}"`;
|
|
1424
|
+
const plural = lineCount === 1 ? '' : 's';
|
|
1425
|
+
const placeholder = `[Pasted text #${id} +${lineCount} line${plural}]`;
|
|
1568
1426
|
return { id, placeholder };
|
|
1569
1427
|
}
|
|
1570
1428
|
insertPastePlaceholder(content) {
|
|
@@ -1572,67 +1430,21 @@ export class TerminalInput extends EventEmitter {
|
|
|
1572
1430
|
if (available <= 0)
|
|
1573
1431
|
return;
|
|
1574
1432
|
const cleanContent = content.slice(0, available);
|
|
1575
|
-
const
|
|
1576
|
-
|
|
1577
|
-
if (summary.lineCount < 5) {
|
|
1578
|
-
const placeholder = this.findPlaceholderAt(this.cursor);
|
|
1579
|
-
const insertPos = placeholder && this.cursor > placeholder.start ? placeholder.end : this.cursor;
|
|
1580
|
-
this.insertPlainText(cleanContent, insertPos);
|
|
1581
|
-
this.cursor = insertPos + cleanContent.length;
|
|
1582
|
-
return;
|
|
1583
|
-
}
|
|
1584
|
-
const { id, placeholder } = this.buildPlaceholder(summary);
|
|
1433
|
+
const lineCount = cleanContent.split('\n').length;
|
|
1434
|
+
const { id, placeholder } = this.buildPlaceholder(lineCount);
|
|
1585
1435
|
const insertPos = this.cursor;
|
|
1586
1436
|
this.shiftPlaceholders(insertPos, placeholder.length);
|
|
1587
1437
|
this.pastePlaceholders.push({
|
|
1588
1438
|
id,
|
|
1589
1439
|
content: cleanContent,
|
|
1590
|
-
lineCount
|
|
1440
|
+
lineCount,
|
|
1591
1441
|
placeholder,
|
|
1592
1442
|
start: insertPos,
|
|
1593
1443
|
end: insertPos + placeholder.length,
|
|
1594
|
-
summary,
|
|
1595
|
-
expanded: false,
|
|
1596
1444
|
});
|
|
1597
1445
|
this.buffer = this.buffer.slice(0, insertPos) + placeholder + this.buffer.slice(insertPos);
|
|
1598
1446
|
this.cursor = insertPos + placeholder.length;
|
|
1599
1447
|
}
|
|
1600
|
-
/**
|
|
1601
|
-
* Toggle expansion of a paste placeholder at the current cursor position.
|
|
1602
|
-
* When expanded, shows first 3 and last 2 lines of the content.
|
|
1603
|
-
*/
|
|
1604
|
-
togglePasteExpansion() {
|
|
1605
|
-
const placeholder = this.findPlaceholderAt(this.cursor);
|
|
1606
|
-
if (!placeholder)
|
|
1607
|
-
return false;
|
|
1608
|
-
placeholder.expanded = !placeholder.expanded;
|
|
1609
|
-
// Update the placeholder text in buffer
|
|
1610
|
-
const newPlaceholder = placeholder.expanded
|
|
1611
|
-
? this.buildExpandedPlaceholder(placeholder)
|
|
1612
|
-
: this.buildPlaceholder(placeholder.summary).placeholder;
|
|
1613
|
-
const lengthDiff = newPlaceholder.length - placeholder.placeholder.length;
|
|
1614
|
-
// Update buffer
|
|
1615
|
-
this.buffer =
|
|
1616
|
-
this.buffer.slice(0, placeholder.start) +
|
|
1617
|
-
newPlaceholder +
|
|
1618
|
-
this.buffer.slice(placeholder.end);
|
|
1619
|
-
// Update placeholder tracking
|
|
1620
|
-
placeholder.placeholder = newPlaceholder;
|
|
1621
|
-
placeholder.end = placeholder.start + newPlaceholder.length;
|
|
1622
|
-
// Shift other placeholders
|
|
1623
|
-
this.shiftPlaceholders(placeholder.end, lengthDiff, placeholder.id);
|
|
1624
|
-
this.scheduleRender();
|
|
1625
|
-
return true;
|
|
1626
|
-
}
|
|
1627
|
-
buildExpandedPlaceholder(ph) {
|
|
1628
|
-
const lines = ph.content.split('\n');
|
|
1629
|
-
const firstLines = lines.slice(0, 3).map(l => l.slice(0, 60)).join('\n');
|
|
1630
|
-
const lastLines = lines.length > 5
|
|
1631
|
-
? '\n...\n' + lines.slice(-2).map(l => l.slice(0, 60)).join('\n')
|
|
1632
|
-
: '';
|
|
1633
|
-
const lang = ph.summary.language ? ` ${ph.summary.language.toUpperCase()}` : '';
|
|
1634
|
-
return `[📋 #${ph.id}${lang} ${ph.lineCount}L ▼]\n${firstLines}${lastLines}\n[/📋 #${ph.id}]`;
|
|
1635
|
-
}
|
|
1636
1448
|
deletePlaceholder(placeholder) {
|
|
1637
1449
|
const length = placeholder.end - placeholder.start;
|
|
1638
1450
|
this.buffer = this.buffer.slice(0, placeholder.start) + this.buffer.slice(placeholder.end);
|
|
@@ -1640,7 +1452,11 @@ export class TerminalInput extends EventEmitter {
|
|
|
1640
1452
|
this.shiftPlaceholders(placeholder.end, -length, placeholder.id);
|
|
1641
1453
|
this.cursor = placeholder.start;
|
|
1642
1454
|
}
|
|
1643
|
-
updateContextUsage(value) {
|
|
1455
|
+
updateContextUsage(value, autoCompactThreshold) {
|
|
1456
|
+
if (typeof autoCompactThreshold === 'number' && Number.isFinite(autoCompactThreshold)) {
|
|
1457
|
+
const boundedThreshold = Math.max(1, Math.min(100, Math.round(autoCompactThreshold)));
|
|
1458
|
+
this.contextAutoCompactThreshold = boundedThreshold;
|
|
1459
|
+
}
|
|
1644
1460
|
if (value === null || !Number.isFinite(value)) {
|
|
1645
1461
|
this.contextUsage = null;
|
|
1646
1462
|
}
|
|
@@ -1667,6 +1483,22 @@ export class TerminalInput extends EventEmitter {
|
|
|
1667
1483
|
const next = this.editMode === 'display-edits' ? 'ask-permission' : 'display-edits';
|
|
1668
1484
|
this.setEditMode(next);
|
|
1669
1485
|
}
|
|
1486
|
+
scheduleStreamingRender(delayMs) {
|
|
1487
|
+
if (this.streamingRenderTimer)
|
|
1488
|
+
return;
|
|
1489
|
+
const wait = Math.max(16, delayMs);
|
|
1490
|
+
this.streamingRenderTimer = setTimeout(() => {
|
|
1491
|
+
this.streamingRenderTimer = null;
|
|
1492
|
+
this.render();
|
|
1493
|
+
}, wait);
|
|
1494
|
+
}
|
|
1495
|
+
resetStreamingRenderThrottle() {
|
|
1496
|
+
if (this.streamingRenderTimer) {
|
|
1497
|
+
clearTimeout(this.streamingRenderTimer);
|
|
1498
|
+
this.streamingRenderTimer = null;
|
|
1499
|
+
}
|
|
1500
|
+
this.lastStreamingRender = 0;
|
|
1501
|
+
}
|
|
1670
1502
|
scheduleRender() {
|
|
1671
1503
|
if (!this.canRender())
|
|
1672
1504
|
return;
|