erosolar-cli 1.7.334 → 1.7.336
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 +5 -21
- 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 +235 -166
- 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 +149 -118
- package/dist/shell/terminalInput.d.ts.map +1 -1
- package/dist/shell/terminalInput.js +638 -532
- package/dist/shell/terminalInput.js.map +1 -1
- package/dist/shell/terminalInputAdapter.d.ts +79 -21
- package/dist/shell/terminalInputAdapter.d.ts.map +1 -1
- package/dist/shell/terminalInputAdapter.js +99 -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,14 +26,18 @@ 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
|
-
ALT_SCREEN_ENTER: '\x1b[?1049h', // Enter alternate screen buffer
|
|
28
|
-
ALT_SCREEN_EXIT: '\x1b[?1049l', // Exit alternate screen buffer
|
|
29
29
|
// Line control
|
|
30
30
|
CLEAR_LINE: '\x1b[2K',
|
|
31
31
|
CLEAR_TO_END: '\x1b[0J',
|
|
32
|
+
// Screen control
|
|
33
|
+
HOME: '\x1b[H',
|
|
34
|
+
CLEAR_SCREEN: '\x1b[2J',
|
|
35
|
+
// Alternate screen buffer (like vim/tmux)
|
|
36
|
+
ENTER_ALT_SCREEN: '\x1b[?1049h',
|
|
37
|
+
EXIT_ALT_SCREEN: '\x1b[?1049l',
|
|
38
|
+
// Scroll region
|
|
39
|
+
SET_SCROLL: (top, bottom) => `\x1b[${top};${bottom}r`,
|
|
40
|
+
RESET_SCROLL: '\x1b[r',
|
|
32
41
|
// Style
|
|
33
42
|
RESET: '\x1b[0m',
|
|
34
43
|
DIM: '\x1b[2m',
|
|
@@ -68,47 +77,46 @@ export class TerminalInput extends EventEmitter {
|
|
|
68
77
|
statusMessage = null;
|
|
69
78
|
overrideStatusMessage = null; // Secondary status (warnings, etc.)
|
|
70
79
|
streamingLabel = null; // Streaming progress indicator
|
|
80
|
+
metaElapsedSeconds = null; // Optional elapsed time for header line
|
|
81
|
+
metaTokensUsed = null; // Optional token usage
|
|
82
|
+
metaTokenLimit = null; // Optional token window
|
|
83
|
+
metaThinkingMs = null; // Optional thinking duration
|
|
84
|
+
metaThinkingHasContent = false; // Whether collapsed thinking content exists
|
|
71
85
|
lastRenderContent = '';
|
|
72
86
|
lastRenderCursor = -1;
|
|
73
87
|
renderDirty = false;
|
|
74
88
|
isRendering = false;
|
|
75
|
-
flowModeRenderedLines = 0; // Track lines rendered for clearing
|
|
76
|
-
inputAreaStartRow = 0; // Track absolute row position of input area
|
|
77
|
-
contentEndRow = 0; // Row where content ends (chat box renders below this)
|
|
78
|
-
// Command suggestions (Claude Code style auto-complete)
|
|
79
|
-
commandSuggestions = [];
|
|
80
|
-
filteredSuggestions = [];
|
|
81
|
-
selectedSuggestionIndex = 0;
|
|
82
|
-
showSuggestions = false;
|
|
83
89
|
// Lifecycle
|
|
84
90
|
disposed = false;
|
|
85
91
|
enabled = true;
|
|
86
92
|
contextUsage = null;
|
|
93
|
+
contextAutoCompactThreshold = 90;
|
|
94
|
+
// Track current content row (starts at top, moves down)
|
|
95
|
+
contentRow = 1;
|
|
96
|
+
// Track if scroll region is currently active
|
|
97
|
+
scrollRegionActive = false;
|
|
98
|
+
thinkingModeLabel = null;
|
|
87
99
|
editMode = 'display-edits';
|
|
88
100
|
verificationEnabled = true;
|
|
89
101
|
autoContinueEnabled = false;
|
|
90
102
|
verificationHotkey = 'alt+v';
|
|
91
103
|
autoContinueHotkey = 'alt+c';
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
// Streaming input area render timer (updates elapsed time display)
|
|
104
|
+
thinkingHotkey = '/thinking';
|
|
105
|
+
modelLabel = null;
|
|
106
|
+
providerLabel = null;
|
|
107
|
+
// Streaming render throttle
|
|
108
|
+
lastStreamingRender = 0;
|
|
109
|
+
streamingRenderInterval = 250; // ms between renders during streaming
|
|
99
110
|
streamingRenderTimer = null;
|
|
100
|
-
// Unified UI initialization flag
|
|
101
|
-
unifiedUIInitialized = false;
|
|
102
111
|
constructor(writeStream = process.stdout, config = {}) {
|
|
103
112
|
super();
|
|
104
113
|
this.out = writeStream;
|
|
105
|
-
// Use schema defaults for configuration consistency
|
|
106
114
|
this.config = {
|
|
107
|
-
maxLines: config.maxLines ??
|
|
108
|
-
maxLength: config.maxLength ??
|
|
115
|
+
maxLines: config.maxLines ?? 1000,
|
|
116
|
+
maxLength: config.maxLength ?? 10000,
|
|
109
117
|
maxQueueSize: config.maxQueueSize ?? 100,
|
|
110
|
-
promptChar: config.promptChar ??
|
|
111
|
-
continuationChar: config.continuationChar ??
|
|
118
|
+
promptChar: config.promptChar ?? '> ',
|
|
119
|
+
continuationChar: config.continuationChar ?? '│ ',
|
|
112
120
|
};
|
|
113
121
|
}
|
|
114
122
|
// ===========================================================================
|
|
@@ -187,290 +195,36 @@ export class TerminalInput extends EventEmitter {
|
|
|
187
195
|
if (handled)
|
|
188
196
|
return;
|
|
189
197
|
}
|
|
190
|
-
// Handle '?' for help hint (if buffer is empty)
|
|
191
|
-
if (str === '?' && this.buffer.length === 0) {
|
|
192
|
-
this.emit('showHelp');
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
198
|
// Insert printable characters
|
|
196
199
|
if (str && !key?.ctrl && !key?.meta) {
|
|
197
200
|
this.insertText(str);
|
|
198
201
|
}
|
|
199
202
|
}
|
|
200
|
-
// Banner content to write on init (set via setBannerContent before initializeUnifiedUI)
|
|
201
|
-
bannerContent = null;
|
|
202
|
-
/**
|
|
203
|
-
* Set banner content to be written when unified UI initializes.
|
|
204
|
-
*/
|
|
205
|
-
setBannerContent(content) {
|
|
206
|
-
this.bannerContent = content;
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Initialize the unified UI system with BOTTOM PINNED chat box.
|
|
210
|
-
*
|
|
211
|
-
* Layout:
|
|
212
|
-
* 1. Clear screen
|
|
213
|
-
* 2. Write banner at top
|
|
214
|
-
* 3. Set content cursor row after banner
|
|
215
|
-
* 4. Render chat box at bottom (sets up scroll region)
|
|
216
|
-
*/
|
|
217
|
-
initializeUnifiedUI() {
|
|
218
|
-
if (this.unifiedUIInitialized) {
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
// Enter alternate screen buffer for complete terminal control
|
|
222
|
-
this.write(ESC.ALT_SCREEN_ENTER);
|
|
223
|
-
// Hide cursor during setup
|
|
224
|
-
this.write(ESC.HIDE);
|
|
225
|
-
// Clear screen and go home (in alternate buffer)
|
|
226
|
-
this.write(ESC.HOME);
|
|
227
|
-
this.write(ESC.CLEAR_SCREEN);
|
|
228
|
-
// Write banner at top
|
|
229
|
-
let bannerLines = 0;
|
|
230
|
-
if (this.bannerContent) {
|
|
231
|
-
const lines = this.bannerContent.split('\n');
|
|
232
|
-
bannerLines = lines.length + 2; // +2 for trailing \n\n
|
|
233
|
-
process.stdout.write(this.bannerContent + '\n\n');
|
|
234
|
-
}
|
|
235
|
-
// Set content cursor row after banner
|
|
236
|
-
this.contentCursorRow = bannerLines > 0 ? bannerLines + 1 : 1;
|
|
237
|
-
// Content ends at same row initially (no content yet)
|
|
238
|
-
this.contentEndRow = this.contentCursorRow - 1;
|
|
239
|
-
// Mark initialized
|
|
240
|
-
this.unifiedUIInitialized = true;
|
|
241
|
-
// Render floating chat box below content
|
|
242
|
-
this.renderFloatingInputArea();
|
|
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
|
-
* Render chat box - FLOATING below content (no scroll regions).
|
|
267
|
-
* Chat box appears right after content and moves down as content grows.
|
|
268
|
-
* Content and banner scroll naturally off the top of the screen.
|
|
269
|
-
*/
|
|
270
|
-
renderFloatingInputArea() {
|
|
271
|
-
const { cols } = this.getSize();
|
|
272
|
-
const divider = '─'.repeat(cols);
|
|
273
|
-
const { dim: DIM, reset: R } = UI_COLORS;
|
|
274
|
-
// Chat box is 4 lines: divider + input + divider + controls
|
|
275
|
-
const chatBoxHeight = 4;
|
|
276
|
-
// Chat box starts right after content
|
|
277
|
-
const chatBoxStartRow = this.contentEndRow + 1;
|
|
278
|
-
// Hide cursor during render
|
|
279
|
-
this.write(ESC.HIDE);
|
|
280
|
-
// Track position
|
|
281
|
-
this.inputAreaStartRow = chatBoxStartRow;
|
|
282
|
-
let currentRow = chatBoxStartRow;
|
|
283
|
-
// Helper to write a line at absolute position (clears then writes)
|
|
284
|
-
const writeLine = (content) => {
|
|
285
|
-
this.write(ESC.TO(currentRow, 1));
|
|
286
|
-
this.write(ESC.CLEAR_LINE);
|
|
287
|
-
this.write(content);
|
|
288
|
-
currentRow++;
|
|
289
|
-
};
|
|
290
|
-
// Top divider
|
|
291
|
-
writeLine(`${DIM}${divider}${R}`);
|
|
292
|
-
// Input line with > prompt
|
|
293
|
-
const { lines, cursorCol } = this.wrapBuffer(cols - 3);
|
|
294
|
-
const displayLine = lines[0] ?? '';
|
|
295
|
-
const inputRow = currentRow;
|
|
296
|
-
writeLine(`${DIM}>${R} ${displayLine}`);
|
|
297
|
-
// Bottom divider
|
|
298
|
-
writeLine(`${DIM}${divider}${R}`);
|
|
299
|
-
// Mode controls line - Claude Code style
|
|
300
|
-
this.write(ESC.TO(currentRow, 1));
|
|
301
|
-
this.write(ESC.CLEAR_LINE);
|
|
302
|
-
this.write(this.buildClaudeStyleControls(cols));
|
|
303
|
-
// Track lines rendered
|
|
304
|
-
this.flowModeRenderedLines = chatBoxHeight;
|
|
305
|
-
// Position cursor at input line for typing
|
|
306
|
-
this.write(ESC.TO(inputRow, 3 + cursorCol));
|
|
307
|
-
// Show cursor
|
|
308
|
-
this.write(ESC.SHOW);
|
|
309
|
-
// Update tracking
|
|
310
|
-
this.lastRenderContent = this.buffer;
|
|
311
|
-
this.lastRenderCursor = this.cursor;
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* Build Claude Code style controls line.
|
|
315
|
-
* Shows: edit mode indicator (shift+tab to cycle)
|
|
316
|
-
*/
|
|
317
|
-
buildClaudeStyleControls(cols) {
|
|
318
|
-
const { dim: DIM, green: GREEN, yellow: YELLOW, cyan: CYAN, reset: R } = UI_COLORS;
|
|
319
|
-
// Edit mode indicator
|
|
320
|
-
let editModeText;
|
|
321
|
-
if (this.editMode === 'display-edits') {
|
|
322
|
-
editModeText = `${GREEN}⏵⏵${R} accept edits on`;
|
|
323
|
-
}
|
|
324
|
-
else {
|
|
325
|
-
editModeText = `${YELLOW}⏸⏸${R} ask before edit`;
|
|
326
|
-
}
|
|
327
|
-
// Build controls line
|
|
328
|
-
const parts = [` ${editModeText} ${DIM}(shift+tab to cycle)${R}`];
|
|
329
|
-
// Add thinking mode if enabled
|
|
330
|
-
if (this.thinkingEnabled) {
|
|
331
|
-
parts.push(`${CYAN}💭${R}`);
|
|
332
|
-
}
|
|
333
|
-
// Add context usage if available
|
|
334
|
-
if (this.contextUsage !== null) {
|
|
335
|
-
const rem = Math.max(0, 100 - this.contextUsage);
|
|
336
|
-
if (rem < 10) {
|
|
337
|
-
parts.push(`${UI_COLORS.red}ctx ${rem}%${R}`);
|
|
338
|
-
}
|
|
339
|
-
else if (rem < 25) {
|
|
340
|
-
parts.push(`${YELLOW}ctx ${rem}%${R}`);
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
return parts.join(` ${DIM}·${R} `);
|
|
344
|
-
}
|
|
345
203
|
/**
|
|
346
204
|
* Set the input mode
|
|
347
205
|
*
|
|
348
|
-
*
|
|
349
|
-
* Scroll region protects chat box, content scrolls above it.
|
|
206
|
+
* Content flows naturally - no scroll region pinning.
|
|
350
207
|
*/
|
|
351
208
|
setMode(mode) {
|
|
352
209
|
const prevMode = this.mode;
|
|
353
210
|
this.mode = mode;
|
|
354
211
|
if (mode === 'streaming' && prevMode !== 'streaming') {
|
|
355
|
-
|
|
356
|
-
this.streamingStartTime = Date.now();
|
|
357
|
-
// Ensure unified UI is initialized
|
|
358
|
-
if (!this.unifiedUIInitialized) {
|
|
359
|
-
this.initializeUnifiedUI();
|
|
360
|
-
}
|
|
361
|
-
// Re-render to ensure scroll region is set correctly
|
|
212
|
+
this.resetStreamingRenderThrottle();
|
|
362
213
|
this.renderDirty = true;
|
|
363
|
-
this.
|
|
214
|
+
this.render();
|
|
364
215
|
}
|
|
365
216
|
else if (mode !== 'streaming' && prevMode === 'streaming') {
|
|
366
|
-
//
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
this.streamingRenderTimer = null;
|
|
370
|
-
}
|
|
371
|
-
// Reset streaming time
|
|
372
|
-
this.streamingStartTime = null;
|
|
373
|
-
// Re-render chat box
|
|
374
|
-
this.renderDirty = true;
|
|
375
|
-
this.scheduleRender();
|
|
217
|
+
// Streaming ended - render the input area
|
|
218
|
+
this.resetStreamingRenderThrottle();
|
|
219
|
+
this.forceRender();
|
|
376
220
|
}
|
|
377
221
|
}
|
|
378
222
|
/**
|
|
379
|
-
*
|
|
380
|
-
*
|
|
223
|
+
* Legacy method - no longer used (content flows naturally).
|
|
224
|
+
* @deprecated Use setContentRow instead
|
|
381
225
|
*/
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
this.renderDirty = true;
|
|
385
|
-
this.scheduleRender();
|
|
386
|
-
}
|
|
387
|
-
/**
|
|
388
|
-
* Set available slash commands for auto-complete suggestions.
|
|
389
|
-
*/
|
|
390
|
-
setCommands(commands) {
|
|
391
|
-
this.commandSuggestions = commands;
|
|
392
|
-
this.updateSuggestions();
|
|
393
|
-
}
|
|
394
|
-
/**
|
|
395
|
-
* Update filtered suggestions based on current input.
|
|
396
|
-
*/
|
|
397
|
-
updateSuggestions() {
|
|
398
|
-
const input = this.buffer.trim();
|
|
399
|
-
// Only show suggestions when input starts with "/"
|
|
400
|
-
if (!input.startsWith('/')) {
|
|
401
|
-
this.showSuggestions = false;
|
|
402
|
-
this.filteredSuggestions = [];
|
|
403
|
-
this.selectedSuggestionIndex = 0;
|
|
404
|
-
return;
|
|
405
|
-
}
|
|
406
|
-
const query = input.toLowerCase();
|
|
407
|
-
this.filteredSuggestions = this.commandSuggestions.filter(cmd => cmd.command.toLowerCase().startsWith(query) ||
|
|
408
|
-
cmd.command.toLowerCase().includes(query.slice(1)));
|
|
409
|
-
// Show suggestions if we have matches
|
|
410
|
-
this.showSuggestions = this.filteredSuggestions.length > 0;
|
|
411
|
-
// Keep selection in bounds
|
|
412
|
-
if (this.selectedSuggestionIndex >= this.filteredSuggestions.length) {
|
|
413
|
-
this.selectedSuggestionIndex = Math.max(0, this.filteredSuggestions.length - 1);
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
/**
|
|
417
|
-
* Select next suggestion (arrow down / tab).
|
|
418
|
-
*/
|
|
419
|
-
selectNextSuggestion() {
|
|
420
|
-
if (!this.showSuggestions || this.filteredSuggestions.length === 0)
|
|
421
|
-
return;
|
|
422
|
-
this.selectedSuggestionIndex = (this.selectedSuggestionIndex + 1) % this.filteredSuggestions.length;
|
|
423
|
-
this.renderDirty = true;
|
|
424
|
-
this.scheduleRender();
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* Select previous suggestion (arrow up / shift+tab).
|
|
428
|
-
*/
|
|
429
|
-
selectPrevSuggestion() {
|
|
430
|
-
if (!this.showSuggestions || this.filteredSuggestions.length === 0)
|
|
431
|
-
return;
|
|
432
|
-
this.selectedSuggestionIndex = this.selectedSuggestionIndex === 0
|
|
433
|
-
? this.filteredSuggestions.length - 1
|
|
434
|
-
: this.selectedSuggestionIndex - 1;
|
|
435
|
-
this.renderDirty = true;
|
|
436
|
-
this.scheduleRender();
|
|
437
|
-
}
|
|
438
|
-
/**
|
|
439
|
-
* Accept current suggestion and insert into buffer.
|
|
440
|
-
*/
|
|
441
|
-
acceptSuggestion() {
|
|
442
|
-
if (!this.showSuggestions || this.filteredSuggestions.length === 0)
|
|
443
|
-
return false;
|
|
444
|
-
const selected = this.filteredSuggestions[this.selectedSuggestionIndex];
|
|
445
|
-
if (!selected)
|
|
446
|
-
return false;
|
|
447
|
-
// Replace buffer with selected command
|
|
448
|
-
this.buffer = selected.command + ' ';
|
|
449
|
-
this.cursor = this.buffer.length;
|
|
450
|
-
this.showSuggestions = false;
|
|
451
|
-
this.renderDirty = true;
|
|
452
|
-
this.scheduleRender();
|
|
453
|
-
return true;
|
|
454
|
-
}
|
|
455
|
-
/**
|
|
456
|
-
* Check if suggestions are visible.
|
|
457
|
-
*/
|
|
458
|
-
areSuggestionsVisible() {
|
|
459
|
-
return this.showSuggestions && this.filteredSuggestions.length > 0;
|
|
460
|
-
}
|
|
461
|
-
/**
|
|
462
|
-
* Toggle thinking/reasoning mode
|
|
463
|
-
*/
|
|
464
|
-
toggleThinking() {
|
|
465
|
-
this.thinkingEnabled = !this.thinkingEnabled;
|
|
466
|
-
this.emit('thinkingToggle', this.thinkingEnabled);
|
|
467
|
-
this.scheduleRender();
|
|
468
|
-
}
|
|
469
|
-
/**
|
|
470
|
-
* Get thinking enabled state
|
|
471
|
-
*/
|
|
472
|
-
isThinkingEnabled() {
|
|
473
|
-
return this.thinkingEnabled;
|
|
226
|
+
setPinnedHeaderLines(_count) {
|
|
227
|
+
// No-op: scroll region pinning removed
|
|
474
228
|
}
|
|
475
229
|
/**
|
|
476
230
|
* Get current mode
|
|
@@ -503,17 +257,14 @@ export class TerminalInput extends EventEmitter {
|
|
|
503
257
|
}
|
|
504
258
|
/**
|
|
505
259
|
* Clear the buffer
|
|
506
|
-
* @param skipRender - If true, don't trigger a re-render (used during submit flow)
|
|
507
260
|
*/
|
|
508
|
-
clear(
|
|
261
|
+
clear() {
|
|
509
262
|
this.buffer = '';
|
|
510
263
|
this.cursor = 0;
|
|
511
264
|
this.historyIndex = -1;
|
|
512
265
|
this.tempInput = '';
|
|
513
266
|
this.pastePlaceholders = [];
|
|
514
|
-
|
|
515
|
-
this.scheduleRender();
|
|
516
|
-
}
|
|
267
|
+
this.scheduleRender();
|
|
517
268
|
}
|
|
518
269
|
/**
|
|
519
270
|
* Get queued inputs
|
|
@@ -584,6 +335,37 @@ export class TerminalInput extends EventEmitter {
|
|
|
584
335
|
this.streamingLabel = next;
|
|
585
336
|
this.scheduleRender();
|
|
586
337
|
}
|
|
338
|
+
/**
|
|
339
|
+
* Surface meta status just above the divider (e.g., elapsed time or token usage).
|
|
340
|
+
*/
|
|
341
|
+
setMetaStatus(meta) {
|
|
342
|
+
const nextElapsed = typeof meta.elapsedSeconds === 'number' && Number.isFinite(meta.elapsedSeconds) && meta.elapsedSeconds >= 0
|
|
343
|
+
? Math.floor(meta.elapsedSeconds)
|
|
344
|
+
: null;
|
|
345
|
+
const nextTokens = typeof meta.tokensUsed === 'number' && Number.isFinite(meta.tokensUsed) && meta.tokensUsed >= 0
|
|
346
|
+
? Math.floor(meta.tokensUsed)
|
|
347
|
+
: null;
|
|
348
|
+
const nextLimit = typeof meta.tokenLimit === 'number' && Number.isFinite(meta.tokenLimit) && meta.tokenLimit > 0
|
|
349
|
+
? Math.floor(meta.tokenLimit)
|
|
350
|
+
: null;
|
|
351
|
+
const nextThinking = typeof meta.thinkingMs === 'number' && Number.isFinite(meta.thinkingMs) && meta.thinkingMs >= 0
|
|
352
|
+
? Math.floor(meta.thinkingMs)
|
|
353
|
+
: null;
|
|
354
|
+
const nextThinkingHasContent = !!meta.thinkingHasContent;
|
|
355
|
+
if (this.metaElapsedSeconds === nextElapsed &&
|
|
356
|
+
this.metaTokensUsed === nextTokens &&
|
|
357
|
+
this.metaTokenLimit === nextLimit &&
|
|
358
|
+
this.metaThinkingMs === nextThinking &&
|
|
359
|
+
this.metaThinkingHasContent === nextThinkingHasContent) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
this.metaElapsedSeconds = nextElapsed;
|
|
363
|
+
this.metaTokensUsed = nextTokens;
|
|
364
|
+
this.metaTokenLimit = nextLimit;
|
|
365
|
+
this.metaThinkingMs = nextThinking;
|
|
366
|
+
this.metaThinkingHasContent = nextThinkingHasContent;
|
|
367
|
+
this.scheduleRender();
|
|
368
|
+
}
|
|
587
369
|
/**
|
|
588
370
|
* Keep mode toggles (verification/auto-continue) visible in the control bar.
|
|
589
371
|
* Hotkey labels remain stable so the bar looks the same before/during streaming.
|
|
@@ -593,26 +375,22 @@ export class TerminalInput extends EventEmitter {
|
|
|
593
375
|
const nextAutoContinue = !!options.autoContinueEnabled;
|
|
594
376
|
const nextVerifyHotkey = options.verificationHotkey ?? this.verificationHotkey;
|
|
595
377
|
const nextAutoHotkey = options.autoContinueHotkey ?? this.autoContinueHotkey;
|
|
378
|
+
const nextThinkingHotkey = options.thinkingHotkey ?? this.thinkingHotkey;
|
|
379
|
+
const nextThinkingLabel = options.thinkingModeLabel === undefined ? this.thinkingModeLabel : (options.thinkingModeLabel || null);
|
|
596
380
|
if (this.verificationEnabled === nextVerification &&
|
|
597
381
|
this.autoContinueEnabled === nextAutoContinue &&
|
|
598
382
|
this.verificationHotkey === nextVerifyHotkey &&
|
|
599
|
-
this.autoContinueHotkey === nextAutoHotkey
|
|
383
|
+
this.autoContinueHotkey === nextAutoHotkey &&
|
|
384
|
+
this.thinkingHotkey === nextThinkingHotkey &&
|
|
385
|
+
this.thinkingModeLabel === nextThinkingLabel) {
|
|
600
386
|
return;
|
|
601
387
|
}
|
|
602
388
|
this.verificationEnabled = nextVerification;
|
|
603
389
|
this.autoContinueEnabled = nextAutoContinue;
|
|
604
390
|
this.verificationHotkey = nextVerifyHotkey;
|
|
605
391
|
this.autoContinueHotkey = nextAutoHotkey;
|
|
606
|
-
this.
|
|
607
|
-
|
|
608
|
-
/**
|
|
609
|
-
* Set the model info string (e.g., "OpenAI · gpt-4")
|
|
610
|
-
* This is displayed persistently above the input area.
|
|
611
|
-
*/
|
|
612
|
-
setModelInfo(info) {
|
|
613
|
-
if (this.modelInfo === info)
|
|
614
|
-
return;
|
|
615
|
-
this.modelInfo = info;
|
|
392
|
+
this.thinkingHotkey = nextThinkingHotkey;
|
|
393
|
+
this.thinkingModeLabel = nextThinkingLabel;
|
|
616
394
|
this.scheduleRender();
|
|
617
395
|
}
|
|
618
396
|
/**
|
|
@@ -625,33 +403,170 @@ export class TerminalInput extends EventEmitter {
|
|
|
625
403
|
this.scheduleRender();
|
|
626
404
|
}
|
|
627
405
|
/**
|
|
628
|
-
*
|
|
629
|
-
|
|
630
|
-
|
|
406
|
+
* Surface model/provider context in the controls bar.
|
|
407
|
+
*/
|
|
408
|
+
setModelContext(options) {
|
|
409
|
+
const nextModel = options.model?.trim() || null;
|
|
410
|
+
const nextProvider = options.provider?.trim() || null;
|
|
411
|
+
if (this.modelLabel === nextModel && this.providerLabel === nextProvider) {
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
this.modelLabel = nextModel;
|
|
415
|
+
this.providerLabel = nextProvider;
|
|
416
|
+
this.scheduleRender();
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Render the floating input area at contentRow.
|
|
420
|
+
*
|
|
421
|
+
* The chat box "floats" - it renders right below the last streamed content.
|
|
422
|
+
* As content is added, contentRow advances, and the chat box moves down.
|
|
423
|
+
* No scroll regions - pure floating behavior.
|
|
631
424
|
*/
|
|
632
425
|
render() {
|
|
633
426
|
if (!this.canRender())
|
|
634
427
|
return;
|
|
635
428
|
if (this.isRendering)
|
|
636
429
|
return;
|
|
430
|
+
const streamingActive = this.mode === 'streaming' || isStreamingMode();
|
|
431
|
+
// During streaming, throttle re-renders
|
|
432
|
+
if (streamingActive && this.lastStreamingRender > 0) {
|
|
433
|
+
const elapsed = Date.now() - this.lastStreamingRender;
|
|
434
|
+
const waitMs = Math.max(0, this.streamingRenderInterval - elapsed);
|
|
435
|
+
if (waitMs > 0) {
|
|
436
|
+
this.renderDirty = true;
|
|
437
|
+
this.scheduleStreamingRender(waitMs);
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
637
441
|
const shouldSkip = !this.renderDirty &&
|
|
638
442
|
this.buffer === this.lastRenderContent &&
|
|
639
443
|
this.cursor === this.lastRenderCursor;
|
|
640
444
|
this.renderDirty = false;
|
|
641
|
-
// Skip if nothing changed (unless explicitly forced)
|
|
642
445
|
if (shouldSkip) {
|
|
643
446
|
return;
|
|
644
447
|
}
|
|
645
|
-
// If write lock is held, defer render
|
|
646
448
|
if (writeLock.isLocked()) {
|
|
647
449
|
writeLock.safeWrite(() => this.render());
|
|
648
450
|
return;
|
|
649
451
|
}
|
|
452
|
+
this.renderPinnedChatBox();
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Unified scroll region renderer.
|
|
456
|
+
* Chat box is ALWAYS pinned at the bottom of the terminal.
|
|
457
|
+
* Content scrolls in the region above the chat box.
|
|
458
|
+
*/
|
|
459
|
+
renderPinnedChatBox() {
|
|
460
|
+
const { rows, cols } = this.getSize();
|
|
461
|
+
const maxWidth = Math.max(8, cols - 4);
|
|
462
|
+
const streamingActive = this.mode === 'streaming' || isStreamingMode();
|
|
463
|
+
// Wrap buffer into display lines
|
|
464
|
+
const { lines, cursorLine, cursorCol } = this.wrapBuffer(maxWidth);
|
|
465
|
+
const maxVisible = Math.max(1, Math.min(this.config.maxLines, rows - 3));
|
|
466
|
+
const displayLines = Math.min(lines.length, maxVisible);
|
|
467
|
+
const metaLines = this.buildMetaLines(cols - 2);
|
|
468
|
+
// Calculate display window (keep cursor visible)
|
|
469
|
+
let startLine = 0;
|
|
470
|
+
if (lines.length > displayLines) {
|
|
471
|
+
startLine = Math.max(0, cursorLine - displayLines + 1);
|
|
472
|
+
startLine = Math.min(startLine, lines.length - displayLines);
|
|
473
|
+
}
|
|
474
|
+
const visibleLines = lines.slice(startLine, startLine + displayLines);
|
|
475
|
+
const adjustedCursorLine = cursorLine - startLine;
|
|
476
|
+
// Chat box height
|
|
477
|
+
const chatBoxHeight = this.getChatBoxHeight();
|
|
478
|
+
// ALWAYS pin chat box at absolute bottom
|
|
479
|
+
const chatBoxStartRow = Math.max(1, rows - chatBoxHeight + 1);
|
|
480
|
+
const scrollEnd = chatBoxStartRow - 1;
|
|
481
|
+
writeLock.lock('terminalInput.renderPinned');
|
|
650
482
|
this.isRendering = true;
|
|
651
|
-
writeLock.lock('terminalInput.render');
|
|
652
483
|
try {
|
|
653
|
-
|
|
654
|
-
this.
|
|
484
|
+
this.write(ESC.SAVE);
|
|
485
|
+
this.write(ESC.HIDE);
|
|
486
|
+
// Temporarily reset scroll region to write chat box cleanly
|
|
487
|
+
if (this.scrollRegionActive) {
|
|
488
|
+
this.write(ESC.RESET_SCROLL);
|
|
489
|
+
}
|
|
490
|
+
// Clear the chat box area
|
|
491
|
+
for (let i = 0; i < chatBoxHeight; i++) {
|
|
492
|
+
const row = chatBoxStartRow + i;
|
|
493
|
+
if (row <= rows) {
|
|
494
|
+
this.write(ESC.TO(row, 1));
|
|
495
|
+
this.write(ESC.CLEAR_LINE);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
let currentRow = chatBoxStartRow;
|
|
499
|
+
// Meta/status header
|
|
500
|
+
for (const metaLine of metaLines) {
|
|
501
|
+
this.write(ESC.TO(currentRow, 1));
|
|
502
|
+
this.write(metaLine);
|
|
503
|
+
currentRow += 1;
|
|
504
|
+
}
|
|
505
|
+
// Separator line
|
|
506
|
+
this.write(ESC.TO(currentRow, 1));
|
|
507
|
+
this.write(renderDivider(cols - 2));
|
|
508
|
+
currentRow += 1;
|
|
509
|
+
// Render input lines
|
|
510
|
+
let finalRow = currentRow;
|
|
511
|
+
let finalCol = 3;
|
|
512
|
+
for (let i = 0; i < visibleLines.length; i++) {
|
|
513
|
+
const rowNum = currentRow + i;
|
|
514
|
+
this.write(ESC.TO(rowNum, 1));
|
|
515
|
+
const line = visibleLines[i] ?? '';
|
|
516
|
+
const isFirstLine = (startLine + i) === 0;
|
|
517
|
+
const isCursorLine = i === adjustedCursorLine;
|
|
518
|
+
this.write(ESC.BG_DARK);
|
|
519
|
+
this.write(ESC.DIM);
|
|
520
|
+
this.write(isFirstLine ? this.config.promptChar : this.config.continuationChar);
|
|
521
|
+
this.write(ESC.RESET);
|
|
522
|
+
this.write(ESC.BG_DARK);
|
|
523
|
+
if (isCursorLine) {
|
|
524
|
+
const col = Math.min(cursorCol, line.length);
|
|
525
|
+
const before = line.slice(0, col);
|
|
526
|
+
const at = col < line.length ? line[col] : ' ';
|
|
527
|
+
const after = col < line.length ? line.slice(col + 1) : '';
|
|
528
|
+
this.write(before);
|
|
529
|
+
this.write(ESC.REVERSE + ESC.BOLD);
|
|
530
|
+
this.write(at);
|
|
531
|
+
this.write(ESC.RESET + ESC.BG_DARK);
|
|
532
|
+
this.write(after);
|
|
533
|
+
finalRow = rowNum;
|
|
534
|
+
finalCol = this.config.promptChar.length + col + 1;
|
|
535
|
+
}
|
|
536
|
+
else {
|
|
537
|
+
this.write(line);
|
|
538
|
+
}
|
|
539
|
+
// Pad to edge
|
|
540
|
+
const lineLen = this.config.promptChar.length + line.length + (isCursorLine && cursorCol >= line.length ? 1 : 0);
|
|
541
|
+
const padding = Math.max(0, cols - lineLen - 1);
|
|
542
|
+
if (padding > 0)
|
|
543
|
+
this.write(' '.repeat(padding));
|
|
544
|
+
this.write(ESC.RESET);
|
|
545
|
+
}
|
|
546
|
+
// Mode controls line with all keyboard shortcuts
|
|
547
|
+
const controlRow = currentRow + visibleLines.length;
|
|
548
|
+
this.write(ESC.TO(controlRow, 1));
|
|
549
|
+
this.write(this.buildModeControls(cols));
|
|
550
|
+
// Restore scroll region if active
|
|
551
|
+
if (this.scrollRegionActive) {
|
|
552
|
+
this.write(ESC.SET_SCROLL(1, scrollEnd));
|
|
553
|
+
// Position cursor in scroll region for content
|
|
554
|
+
this.write(ESC.TO(Math.min(this.contentRow, scrollEnd), 1));
|
|
555
|
+
}
|
|
556
|
+
this.write(ESC.RESTORE);
|
|
557
|
+
// Position cursor in input box (unless streaming)
|
|
558
|
+
if (!streamingActive) {
|
|
559
|
+
this.write(ESC.TO(finalRow, Math.min(finalCol, cols)));
|
|
560
|
+
}
|
|
561
|
+
this.write(ESC.SHOW);
|
|
562
|
+
// Update state
|
|
563
|
+
this.lastRenderContent = this.buffer;
|
|
564
|
+
this.lastRenderCursor = this.cursor;
|
|
565
|
+
this.lastStreamingRender = streamingActive ? Date.now() : 0;
|
|
566
|
+
if (this.streamingRenderTimer) {
|
|
567
|
+
clearTimeout(this.streamingRenderTimer);
|
|
568
|
+
this.streamingRenderTimer = null;
|
|
569
|
+
}
|
|
655
570
|
}
|
|
656
571
|
finally {
|
|
657
572
|
writeLock.unlock();
|
|
@@ -659,99 +574,198 @@ export class TerminalInput extends EventEmitter {
|
|
|
659
574
|
}
|
|
660
575
|
}
|
|
661
576
|
/**
|
|
662
|
-
* Build
|
|
663
|
-
*
|
|
577
|
+
* Build compact meta line above the divider.
|
|
578
|
+
* Shows model/provider and key metrics in a single line.
|
|
579
|
+
* Status message is shown in mode controls to avoid duplication.
|
|
664
580
|
*/
|
|
665
|
-
|
|
666
|
-
const maxWidth = cols - 2;
|
|
581
|
+
buildMetaLines(width) {
|
|
667
582
|
const parts = [];
|
|
668
|
-
//
|
|
669
|
-
if (this.
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
const secs = elapsed % 60;
|
|
675
|
-
statusText += mins > 0 ? ` ${mins}m ${secs}s` : ` ${secs}s`;
|
|
676
|
-
}
|
|
677
|
-
parts.push(`\x1b[32m${statusText}\x1b[0m`); // Green
|
|
583
|
+
// Model/provider info
|
|
584
|
+
if (this.modelLabel) {
|
|
585
|
+
const modelText = this.providerLabel
|
|
586
|
+
? `${this.modelLabel} @ ${this.providerLabel}`
|
|
587
|
+
: this.modelLabel;
|
|
588
|
+
parts.push({ text: modelText, tone: 'info' });
|
|
678
589
|
}
|
|
679
|
-
//
|
|
680
|
-
if (this.
|
|
681
|
-
parts.push(
|
|
590
|
+
// Elapsed time
|
|
591
|
+
if (this.metaElapsedSeconds !== null) {
|
|
592
|
+
parts.push({ text: this.formatElapsedLabel(this.metaElapsedSeconds), tone: 'muted' });
|
|
682
593
|
}
|
|
683
|
-
//
|
|
684
|
-
if (this.
|
|
685
|
-
const
|
|
686
|
-
|
|
594
|
+
// Token usage (compact)
|
|
595
|
+
if (this.metaTokensUsed !== null) {
|
|
596
|
+
const formattedUsed = this.formatTokenCount(this.metaTokensUsed);
|
|
597
|
+
const formattedLimit = this.metaTokenLimit ? `/${this.formatTokenCount(this.metaTokenLimit)}` : '';
|
|
598
|
+
parts.push({ text: `${formattedUsed}${formattedLimit}`, tone: 'muted' });
|
|
687
599
|
}
|
|
688
|
-
//
|
|
689
|
-
|
|
690
|
-
|
|
600
|
+
// Context remaining (only show if concerning)
|
|
601
|
+
const tokensRemaining = this.computeTokensRemaining();
|
|
602
|
+
if (tokensRemaining !== null) {
|
|
603
|
+
parts.push({ text: `↓${tokensRemaining}`, tone: 'muted' });
|
|
691
604
|
}
|
|
692
|
-
//
|
|
693
|
-
if (this.
|
|
694
|
-
|
|
605
|
+
// Thinking indicator
|
|
606
|
+
if (this.metaThinkingMs !== null) {
|
|
607
|
+
parts.push({ text: formatThinking(this.metaThinkingMs, this.metaThinkingHasContent), tone: 'info' });
|
|
608
|
+
}
|
|
609
|
+
if (!parts.length) {
|
|
610
|
+
return [];
|
|
611
|
+
}
|
|
612
|
+
return [renderStatusLine(parts, width)];
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* Build mode controls line with all keyboard shortcuts.
|
|
616
|
+
* Shows status, all toggles, and contextual information.
|
|
617
|
+
*/
|
|
618
|
+
buildModeControls(cols) {
|
|
619
|
+
const width = Math.max(8, cols - 2);
|
|
620
|
+
const leftParts = [];
|
|
621
|
+
const rightParts = [];
|
|
622
|
+
// Streaming indicator
|
|
623
|
+
if (this.streamingLabel) {
|
|
624
|
+
leftParts.push({ text: `◐ ${this.streamingLabel}`, tone: 'info' });
|
|
625
|
+
}
|
|
626
|
+
// Override status (warnings, errors)
|
|
627
|
+
if (this.overrideStatusMessage) {
|
|
628
|
+
leftParts.push({ text: `⚠ ${this.overrideStatusMessage}`, tone: 'warn' });
|
|
629
|
+
}
|
|
630
|
+
// Main status message
|
|
631
|
+
if (this.statusMessage) {
|
|
632
|
+
leftParts.push({ text: this.statusMessage, tone: this.streamingLabel ? 'muted' : 'info' });
|
|
633
|
+
}
|
|
634
|
+
// === KEYBOARD SHORTCUTS ===
|
|
635
|
+
// Interrupt shortcut (during streaming)
|
|
636
|
+
if (this.mode === 'streaming' || this.scrollRegionActive) {
|
|
637
|
+
leftParts.push({ text: `${this.formatHotkey('esc')} stop`, tone: 'warn' });
|
|
638
|
+
}
|
|
639
|
+
// Edit mode toggle (Shift+Tab)
|
|
640
|
+
const editHotkey = this.formatHotkey('shift+tab');
|
|
641
|
+
const editLabel = this.editMode === 'display-edits' ? 'edits:accept' : 'edits:ask';
|
|
642
|
+
const editTone = this.editMode === 'display-edits' ? 'success' : 'muted';
|
|
643
|
+
leftParts.push({ text: `${editHotkey} ${editLabel}`, tone: editTone });
|
|
644
|
+
// Verification toggle (Alt+V)
|
|
645
|
+
const verifyHotkey = this.formatHotkey(this.verificationHotkey || 'alt+v');
|
|
646
|
+
const verifyLabel = this.verificationEnabled ? 'verify:on' : 'verify:off';
|
|
647
|
+
leftParts.push({ text: `${verifyHotkey} ${verifyLabel}`, tone: this.verificationEnabled ? 'success' : 'muted' });
|
|
648
|
+
// Auto-continue toggle (Alt+C)
|
|
649
|
+
const continueHotkey = this.formatHotkey(this.autoContinueHotkey || 'alt+c');
|
|
650
|
+
const continueLabel = this.autoContinueEnabled ? 'auto:on' : 'auto:off';
|
|
651
|
+
leftParts.push({ text: `${continueHotkey} ${continueLabel}`, tone: this.autoContinueEnabled ? 'info' : 'muted' });
|
|
652
|
+
// Thinking mode toggle (if available)
|
|
653
|
+
if (this.thinkingModeLabel) {
|
|
654
|
+
const thinkingHotkey = this.formatHotkey(this.thinkingHotkey || 'alt+t');
|
|
655
|
+
rightParts.push({ text: `${thinkingHotkey} think:${this.thinkingModeLabel}`, tone: 'info' });
|
|
656
|
+
}
|
|
657
|
+
// === CONTEXTUAL INFO ===
|
|
658
|
+
// Queued commands
|
|
659
|
+
if (this.queue.length > 0 && this.mode !== 'streaming') {
|
|
660
|
+
leftParts.push({ text: `queued:${this.queue.length}`, tone: 'info' });
|
|
695
661
|
}
|
|
696
662
|
// Multi-line indicator
|
|
697
663
|
if (this.buffer.includes('\n')) {
|
|
698
|
-
|
|
664
|
+
const lineCount = this.buffer.split('\n').length;
|
|
665
|
+
rightParts.push({ text: `${lineCount}L`, tone: 'muted' });
|
|
666
|
+
}
|
|
667
|
+
// Paste indicator
|
|
668
|
+
if (this.pastePlaceholders.length > 0) {
|
|
669
|
+
const latest = this.pastePlaceholders[this.pastePlaceholders.length - 1];
|
|
670
|
+
rightParts.push({
|
|
671
|
+
text: `paste#${latest.id} +${latest.lineCount}L ${this.formatHotkey('backspace')}drop`,
|
|
672
|
+
tone: 'info',
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
// Context remaining warning
|
|
676
|
+
const contextRemaining = this.computeContextRemaining();
|
|
677
|
+
if (contextRemaining !== null) {
|
|
678
|
+
const tone = contextRemaining <= 10 ? 'warn' : 'muted';
|
|
679
|
+
const label = contextRemaining === 0 && this.contextUsage !== null
|
|
680
|
+
? 'compact imminent'
|
|
681
|
+
: `ctx:${contextRemaining}%`;
|
|
682
|
+
rightParts.push({ text: label, tone });
|
|
683
|
+
}
|
|
684
|
+
// Render: left-aligned shortcuts, right-aligned context info
|
|
685
|
+
if (!rightParts.length || width < 60) {
|
|
686
|
+
const merged = rightParts.length ? [...leftParts, ...rightParts] : leftParts;
|
|
687
|
+
return renderStatusLine(merged, width);
|
|
688
|
+
}
|
|
689
|
+
const leftWidth = Math.max(12, Math.floor(width * 0.65));
|
|
690
|
+
const rightWidth = Math.max(14, width - leftWidth - 1);
|
|
691
|
+
const leftText = renderStatusLine(leftParts, leftWidth);
|
|
692
|
+
const rightText = renderStatusLine(rightParts, rightWidth);
|
|
693
|
+
const spacing = Math.max(1, width - this.visibleLength(leftText) - this.visibleLength(rightText));
|
|
694
|
+
return `${leftText}${' '.repeat(spacing)}${rightText}`;
|
|
695
|
+
}
|
|
696
|
+
formatHotkey(hotkey) {
|
|
697
|
+
const normalized = hotkey.trim().toLowerCase();
|
|
698
|
+
if (!normalized)
|
|
699
|
+
return hotkey;
|
|
700
|
+
const parts = normalized.split('+').filter(Boolean);
|
|
701
|
+
const map = {
|
|
702
|
+
shift: '⇧',
|
|
703
|
+
sh: '⇧',
|
|
704
|
+
alt: '⌥',
|
|
705
|
+
option: '⌥',
|
|
706
|
+
opt: '⌥',
|
|
707
|
+
ctrl: '⌃',
|
|
708
|
+
control: '⌃',
|
|
709
|
+
cmd: '⌘',
|
|
710
|
+
meta: '⌘',
|
|
711
|
+
};
|
|
712
|
+
const formatted = parts
|
|
713
|
+
.map((part) => {
|
|
714
|
+
const symbol = map[part];
|
|
715
|
+
if (symbol)
|
|
716
|
+
return symbol;
|
|
717
|
+
return part.length === 1 ? part.toUpperCase() : part.toUpperCase();
|
|
718
|
+
})
|
|
719
|
+
.join('');
|
|
720
|
+
return formatted || hotkey;
|
|
721
|
+
}
|
|
722
|
+
computeContextRemaining() {
|
|
723
|
+
if (this.contextUsage === null) {
|
|
724
|
+
return null;
|
|
725
|
+
}
|
|
726
|
+
return Math.max(0, this.contextAutoCompactThreshold - this.contextUsage);
|
|
727
|
+
}
|
|
728
|
+
computeTokensRemaining() {
|
|
729
|
+
if (this.metaTokensUsed === null || this.metaTokenLimit === null) {
|
|
730
|
+
return null;
|
|
731
|
+
}
|
|
732
|
+
const remaining = Math.max(0, this.metaTokenLimit - this.metaTokensUsed);
|
|
733
|
+
return this.formatTokenCount(remaining);
|
|
734
|
+
}
|
|
735
|
+
formatElapsedLabel(seconds) {
|
|
736
|
+
if (seconds < 60) {
|
|
737
|
+
return `${seconds}s`;
|
|
738
|
+
}
|
|
739
|
+
const mins = Math.floor(seconds / 60);
|
|
740
|
+
const secs = seconds % 60;
|
|
741
|
+
return secs > 0 ? `${mins}m ${secs}s` : `${mins}m`;
|
|
742
|
+
}
|
|
743
|
+
formatTokenCount(value) {
|
|
744
|
+
if (!Number.isFinite(value)) {
|
|
745
|
+
return `${value}`;
|
|
746
|
+
}
|
|
747
|
+
if (value >= 1_000_000) {
|
|
748
|
+
return `${(value / 1_000_000).toFixed(1)}M`;
|
|
699
749
|
}
|
|
700
|
-
if (
|
|
701
|
-
return
|
|
750
|
+
if (value >= 1_000) {
|
|
751
|
+
return `${(value / 1_000).toFixed(1)}k`;
|
|
702
752
|
}
|
|
703
|
-
|
|
704
|
-
|
|
753
|
+
return `${Math.round(value)}`;
|
|
754
|
+
}
|
|
755
|
+
visibleLength(value) {
|
|
756
|
+
const ansiPattern = /\u001B\[[0-?]*[ -/]*[@-~]/g;
|
|
757
|
+
return value.replace(ansiPattern, '').length;
|
|
705
758
|
}
|
|
706
759
|
/**
|
|
707
|
-
*
|
|
708
|
-
*
|
|
709
|
-
*
|
|
710
|
-
* Layout: [toggles on left] ... [context info on right]
|
|
760
|
+
* Debug-only snapshot used by tests to assert rendered strings without
|
|
761
|
+
* needing a TTY. Not used by production code.
|
|
711
762
|
*/
|
|
712
|
-
|
|
713
|
-
const
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
// Edit mode (green=auto, yellow=ask) - per schema.editMode
|
|
719
|
-
if (this.editMode === 'display-edits') {
|
|
720
|
-
toggles.push(`${GREEN}⏵⏵ auto-edit${R}`);
|
|
721
|
-
}
|
|
722
|
-
else {
|
|
723
|
-
toggles.push(`${YELLOW}⏸⏸ ask-first${R}`);
|
|
724
|
-
}
|
|
725
|
-
// Thinking mode (cyan when on) - per schema.thinkingMode
|
|
726
|
-
toggles.push(this.thinkingEnabled ? `${CYAN}💭 think${R}` : `${DIM}○ think${R}`);
|
|
727
|
-
// Verification (green when on) - per schema.verificationMode
|
|
728
|
-
toggles.push(this.verificationEnabled ? `${GREEN}✓ verify${R}` : `${DIM}○ verify${R}`);
|
|
729
|
-
// Auto-continue (magenta when on) - per schema.autoContinueMode
|
|
730
|
-
toggles.push(this.autoContinueEnabled ? `${MAGENTA}↻ auto${R}` : `${DIM}○ auto${R}`);
|
|
731
|
-
const leftPart = toggles.join(`${DIM} · ${R}`) + `${DIM} (⇧⇥)${R}`;
|
|
732
|
-
// Context usage with color - per schema.contextUsage thresholds
|
|
733
|
-
let rightPart = '';
|
|
734
|
-
if (this.contextUsage !== null) {
|
|
735
|
-
const rem = Math.max(0, 100 - this.contextUsage);
|
|
736
|
-
// Thresholds: critical < 10%, warning < 25%
|
|
737
|
-
if (rem < 10)
|
|
738
|
-
rightPart = `${RED}⚠ ctx: ${rem}%${R}`;
|
|
739
|
-
else if (rem < 25)
|
|
740
|
-
rightPart = `${YELLOW}! ctx: ${rem}%${R}`;
|
|
741
|
-
else
|
|
742
|
-
rightPart = `${DIM}ctx: ${rem}%${R}`;
|
|
743
|
-
}
|
|
744
|
-
// Calculate visible lengths (strip ANSI)
|
|
745
|
-
const strip = (s) => s.replace(/\x1b\[[0-9;]*m/g, '');
|
|
746
|
-
const leftLen = strip(leftPart).length;
|
|
747
|
-
const rightLen = strip(rightPart).length;
|
|
748
|
-
if (leftLen + rightLen < maxWidth - 4) {
|
|
749
|
-
return `${leftPart}${' '.repeat(maxWidth - leftLen - rightLen)}${rightPart}`;
|
|
750
|
-
}
|
|
751
|
-
if (rightLen > 0 && leftLen + 8 < maxWidth) {
|
|
752
|
-
return `${leftPart} ${rightPart}`;
|
|
753
|
-
}
|
|
754
|
-
return leftPart;
|
|
763
|
+
getDebugUiSnapshot(width) {
|
|
764
|
+
const cols = Math.max(8, width ?? this.getSize().cols);
|
|
765
|
+
return {
|
|
766
|
+
meta: this.buildMetaLines(cols - 2),
|
|
767
|
+
controls: this.buildModeControls(cols),
|
|
768
|
+
};
|
|
755
769
|
}
|
|
756
770
|
/**
|
|
757
771
|
* Force a re-render
|
|
@@ -774,74 +788,200 @@ export class TerminalInput extends EventEmitter {
|
|
|
774
788
|
handleResize() {
|
|
775
789
|
this.lastRenderContent = '';
|
|
776
790
|
this.lastRenderCursor = -1;
|
|
791
|
+
this.resetStreamingRenderThrottle();
|
|
777
792
|
this.scheduleRender();
|
|
778
793
|
}
|
|
779
|
-
// Track current content row for writing
|
|
780
|
-
contentCursorRow = 1;
|
|
781
794
|
/**
|
|
782
|
-
*
|
|
783
|
-
*
|
|
795
|
+
* Enter streaming mode with scroll region.
|
|
796
|
+
* Sets up terminal scroll region to exclude chat box.
|
|
784
797
|
*/
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
afterWrite: () => {
|
|
804
|
-
// Debounce render: wait 50ms for more writes before rendering chat box
|
|
805
|
-
// This prevents rapid re-renders during streaming
|
|
806
|
-
if (pendingRender) {
|
|
807
|
-
clearTimeout(pendingRender);
|
|
808
|
-
}
|
|
809
|
-
pendingRender = setTimeout(() => {
|
|
810
|
-
pendingRender = null;
|
|
811
|
-
// Update contentEndRow from display's line count if available
|
|
812
|
-
if (display.getTotalWrittenLines) {
|
|
813
|
-
this.contentEndRow = display.getTotalWrittenLines();
|
|
814
|
-
}
|
|
815
|
-
// Re-render chat box below content
|
|
816
|
-
this.renderFloatingInputArea();
|
|
817
|
-
}, 50);
|
|
818
|
-
},
|
|
819
|
-
});
|
|
798
|
+
enterStreamingScrollRegion() {
|
|
799
|
+
const { rows } = this.getSize();
|
|
800
|
+
const chatBoxHeight = this.getChatBoxHeight();
|
|
801
|
+
const scrollEnd = Math.max(1, rows - chatBoxHeight);
|
|
802
|
+
writeLock.lock('enterStreamingScrollRegion');
|
|
803
|
+
try {
|
|
804
|
+
// Set scroll region for content area (above chat box)
|
|
805
|
+
this.write(ESC.SET_SCROLL(1, scrollEnd));
|
|
806
|
+
// Position cursor at current content row
|
|
807
|
+
this.write(ESC.TO(Math.min(this.contentRow, scrollEnd), 1));
|
|
808
|
+
this.scrollRegionActive = true;
|
|
809
|
+
this.setStatusMessage('esc to interrupt');
|
|
810
|
+
}
|
|
811
|
+
finally {
|
|
812
|
+
writeLock.unlock();
|
|
813
|
+
}
|
|
814
|
+
// Render pinned chat box at bottom
|
|
815
|
+
this.forceRender();
|
|
820
816
|
}
|
|
821
817
|
/**
|
|
822
|
-
*
|
|
818
|
+
* Exit streaming mode and restore normal operation.
|
|
823
819
|
*/
|
|
824
|
-
|
|
825
|
-
|
|
820
|
+
exitStreamingScrollRegion() {
|
|
821
|
+
writeLock.lock('exitStreamingScrollRegion');
|
|
822
|
+
try {
|
|
823
|
+
// Reset scroll region to full terminal
|
|
824
|
+
this.write(ESC.RESET_SCROLL);
|
|
825
|
+
this.scrollRegionActive = false;
|
|
826
|
+
this.setStatusMessage('Ready for prompts');
|
|
827
|
+
}
|
|
828
|
+
finally {
|
|
829
|
+
writeLock.unlock();
|
|
830
|
+
}
|
|
831
|
+
// Final render
|
|
832
|
+
this.forceRender();
|
|
833
|
+
}
|
|
834
|
+
/**
|
|
835
|
+
* Render chat box at bottom - now uses unified renderer.
|
|
836
|
+
* @deprecated Use renderPinnedChatBox() directly via render()/forceRender()
|
|
837
|
+
*/
|
|
838
|
+
renderChatBoxAtBottom() {
|
|
839
|
+
this.renderPinnedChatBox();
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* Stream content within the scroll region.
|
|
843
|
+
* Content is written directly and scrolls naturally.
|
|
844
|
+
*/
|
|
845
|
+
streamContent(content) {
|
|
846
|
+
if (!content)
|
|
826
847
|
return;
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
this.
|
|
848
|
+
writeLock.lock('streamContent');
|
|
849
|
+
try {
|
|
850
|
+
// Write content - scroll region handles scrolling
|
|
851
|
+
this.write(content);
|
|
852
|
+
// Track newlines
|
|
853
|
+
const newlines = (content.match(/\n/g) || []).length;
|
|
854
|
+
this.contentRow += newlines;
|
|
831
855
|
}
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
856
|
+
finally {
|
|
857
|
+
writeLock.unlock();
|
|
858
|
+
}
|
|
859
|
+
// Throttle chat box updates during streaming
|
|
860
|
+
this.scheduleStreamingRender(200);
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* Enable scroll region (no-op in floating mode).
|
|
864
|
+
*/
|
|
865
|
+
enableScrollRegion() {
|
|
866
|
+
// No-op: using pure floating approach
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* Disable scroll region (no-op in floating mode).
|
|
870
|
+
*/
|
|
871
|
+
disableScrollRegion() {
|
|
872
|
+
// No-op: using pure floating approach
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* Calculate chat box height.
|
|
876
|
+
*/
|
|
877
|
+
getChatBoxHeight() {
|
|
878
|
+
return 6; // Fixed: meta + divider + input + controls + buffer
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* @deprecated Use streamContent() instead
|
|
882
|
+
* Register with display's output interceptor - kept for backwards compatibility
|
|
883
|
+
*/
|
|
884
|
+
registerOutputInterceptor(_display) {
|
|
885
|
+
// No-op: Use streamContent() for cleaner floating chat box behavior
|
|
886
|
+
}
|
|
887
|
+
/**
|
|
888
|
+
* Write content above the floating chat box.
|
|
889
|
+
* Works both during streaming and when idle.
|
|
890
|
+
*/
|
|
891
|
+
writeToScrollRegion(content) {
|
|
892
|
+
if (!content)
|
|
893
|
+
return;
|
|
894
|
+
writeLock.lock('writeToScrollRegion');
|
|
895
|
+
try {
|
|
896
|
+
// Position cursor at content row and write
|
|
897
|
+
this.write(ESC.TO(this.contentRow, 1));
|
|
898
|
+
this.write(content);
|
|
899
|
+
// Track newlines
|
|
900
|
+
const newlines = (content.match(/\n/g) || []).length;
|
|
901
|
+
this.contentRow += newlines;
|
|
902
|
+
}
|
|
903
|
+
finally {
|
|
904
|
+
writeLock.unlock();
|
|
836
905
|
}
|
|
837
|
-
//
|
|
838
|
-
this.
|
|
839
|
-
|
|
840
|
-
if (this.unifiedUIInitialized) {
|
|
841
|
-
this.write(ESC.ALT_SCREEN_EXIT);
|
|
906
|
+
// Re-render chat box below new content (only when not streaming)
|
|
907
|
+
if (!this.scrollRegionActive) {
|
|
908
|
+
this.forceRender();
|
|
842
909
|
}
|
|
910
|
+
}
|
|
911
|
+
/**
|
|
912
|
+
* Enter alternate screen buffer and clear it.
|
|
913
|
+
* This gives us full control over the terminal without affecting user's history.
|
|
914
|
+
*/
|
|
915
|
+
enterAlternateScreen() {
|
|
916
|
+
writeLock.lock('enterAltScreen');
|
|
917
|
+
try {
|
|
918
|
+
this.write(ESC.ENTER_ALT_SCREEN);
|
|
919
|
+
this.write(ESC.HOME);
|
|
920
|
+
this.write(ESC.CLEAR_SCREEN);
|
|
921
|
+
this.contentRow = 1;
|
|
922
|
+
}
|
|
923
|
+
finally {
|
|
924
|
+
writeLock.unlock();
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
/**
|
|
928
|
+
* Exit alternate screen buffer.
|
|
929
|
+
* Restores the user's previous terminal content.
|
|
930
|
+
*/
|
|
931
|
+
exitAlternateScreen() {
|
|
932
|
+
writeLock.lock('exitAltScreen');
|
|
933
|
+
try {
|
|
934
|
+
this.write(ESC.EXIT_ALT_SCREEN);
|
|
935
|
+
}
|
|
936
|
+
finally {
|
|
937
|
+
writeLock.unlock();
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
/**
|
|
941
|
+
* Clear the entire terminal screen and reset content position.
|
|
942
|
+
* This removes all content including the launching command.
|
|
943
|
+
*/
|
|
944
|
+
clearScreen() {
|
|
945
|
+
writeLock.lock('clearScreen');
|
|
946
|
+
try {
|
|
947
|
+
this.write(ESC.HOME);
|
|
948
|
+
this.write(ESC.CLEAR_SCREEN);
|
|
949
|
+
this.contentRow = 1;
|
|
950
|
+
}
|
|
951
|
+
finally {
|
|
952
|
+
writeLock.unlock();
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
/**
|
|
956
|
+
* Reset content position to row 1.
|
|
957
|
+
* Does NOT clear the terminal - content starts from current position.
|
|
958
|
+
*/
|
|
959
|
+
resetContentPosition() {
|
|
960
|
+
this.contentRow = 1;
|
|
961
|
+
}
|
|
962
|
+
/**
|
|
963
|
+
* Set the content row explicitly (used after banner is written).
|
|
964
|
+
* This tells the input where content should start flowing from.
|
|
965
|
+
*/
|
|
966
|
+
setContentRow(row) {
|
|
967
|
+
this.contentRow = Math.max(1, row);
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* Get the current content row position.
|
|
971
|
+
*/
|
|
972
|
+
getContentRow() {
|
|
973
|
+
return this.contentRow;
|
|
974
|
+
}
|
|
975
|
+
/**
|
|
976
|
+
* Dispose and clean up
|
|
977
|
+
*/
|
|
978
|
+
dispose() {
|
|
979
|
+
if (this.disposed)
|
|
980
|
+
return;
|
|
843
981
|
this.disposed = true;
|
|
844
982
|
this.enabled = false;
|
|
983
|
+
this.disableScrollRegion();
|
|
984
|
+
this.resetStreamingRenderThrottle();
|
|
845
985
|
this.disableBracketedPaste();
|
|
846
986
|
this.buffer = '';
|
|
847
987
|
this.queue = [];
|
|
@@ -946,22 +1086,7 @@ export class TerminalInput extends EventEmitter {
|
|
|
946
1086
|
this.toggleEditMode();
|
|
947
1087
|
return true;
|
|
948
1088
|
}
|
|
949
|
-
|
|
950
|
-
if (this.findPlaceholderAt(this.cursor)) {
|
|
951
|
-
this.togglePasteExpansion();
|
|
952
|
-
}
|
|
953
|
-
else {
|
|
954
|
-
this.toggleThinking();
|
|
955
|
-
}
|
|
956
|
-
return true;
|
|
957
|
-
case 'escape':
|
|
958
|
-
// Esc: interrupt if streaming, otherwise clear buffer
|
|
959
|
-
if (this.mode === 'streaming') {
|
|
960
|
-
this.emit('interrupt');
|
|
961
|
-
}
|
|
962
|
-
else if (this.buffer.length > 0) {
|
|
963
|
-
this.clear();
|
|
964
|
-
}
|
|
1089
|
+
this.insertText(' ');
|
|
965
1090
|
return true;
|
|
966
1091
|
}
|
|
967
1092
|
return false;
|
|
@@ -979,7 +1104,6 @@ export class TerminalInput extends EventEmitter {
|
|
|
979
1104
|
this.insertPlainText(chunk, insertPos);
|
|
980
1105
|
this.cursor = insertPos + chunk.length;
|
|
981
1106
|
this.emit('change', this.buffer);
|
|
982
|
-
this.updateSuggestions();
|
|
983
1107
|
this.scheduleRender();
|
|
984
1108
|
}
|
|
985
1109
|
insertNewline() {
|
|
@@ -1004,7 +1128,6 @@ export class TerminalInput extends EventEmitter {
|
|
|
1004
1128
|
this.cursor = Math.max(0, this.cursor - 1);
|
|
1005
1129
|
}
|
|
1006
1130
|
this.emit('change', this.buffer);
|
|
1007
|
-
this.updateSuggestions();
|
|
1008
1131
|
this.scheduleRender();
|
|
1009
1132
|
}
|
|
1010
1133
|
deleteForward() {
|
|
@@ -1232,13 +1355,12 @@ export class TerminalInput extends EventEmitter {
|
|
|
1232
1355
|
timestamp: Date.now(),
|
|
1233
1356
|
});
|
|
1234
1357
|
this.emit('queue', text);
|
|
1235
|
-
this.clear(); // Clear immediately for queued input
|
|
1358
|
+
this.clear(); // Clear immediately for queued input
|
|
1236
1359
|
}
|
|
1237
1360
|
else {
|
|
1238
|
-
// In idle mode, clear the input
|
|
1239
|
-
// The
|
|
1240
|
-
|
|
1241
|
-
this.clear(true); // Skip render - streaming will handle display
|
|
1361
|
+
// In idle mode, clear the input first, then emit submit.
|
|
1362
|
+
// The prompt will be logged as a visible message by the caller.
|
|
1363
|
+
this.clear();
|
|
1242
1364
|
this.emit('submit', text);
|
|
1243
1365
|
}
|
|
1244
1366
|
}
|
|
@@ -1255,7 +1377,9 @@ export class TerminalInput extends EventEmitter {
|
|
|
1255
1377
|
if (available <= 0)
|
|
1256
1378
|
return;
|
|
1257
1379
|
const chunk = clean.slice(0, available);
|
|
1258
|
-
|
|
1380
|
+
const isMultiline = isMultilinePaste(chunk);
|
|
1381
|
+
const isShortMultiline = isMultiline && this.shouldInlineMultiline(chunk);
|
|
1382
|
+
if (isMultiline && !isShortMultiline) {
|
|
1259
1383
|
this.insertPastePlaceholder(chunk);
|
|
1260
1384
|
}
|
|
1261
1385
|
else {
|
|
@@ -1391,17 +1515,19 @@ export class TerminalInput extends EventEmitter {
|
|
|
1391
1515
|
this.shiftPlaceholders(position, text.length);
|
|
1392
1516
|
this.buffer = this.buffer.slice(0, position) + text + this.buffer.slice(position);
|
|
1393
1517
|
}
|
|
1518
|
+
shouldInlineMultiline(content) {
|
|
1519
|
+
const lines = content.split('\n').length;
|
|
1520
|
+
const maxInlineLines = 4;
|
|
1521
|
+
const maxInlineChars = 240;
|
|
1522
|
+
return lines <= maxInlineLines && content.length <= maxInlineChars;
|
|
1523
|
+
}
|
|
1394
1524
|
findPlaceholderAt(position) {
|
|
1395
1525
|
return this.pastePlaceholders.find((ph) => position >= ph.start && position < ph.end) ?? null;
|
|
1396
1526
|
}
|
|
1397
|
-
buildPlaceholder(
|
|
1527
|
+
buildPlaceholder(lineCount) {
|
|
1398
1528
|
const id = ++this.pasteCounter;
|
|
1399
|
-
const
|
|
1400
|
-
|
|
1401
|
-
const preview = summary.preview.length > 30
|
|
1402
|
-
? `${summary.preview.slice(0, 30)}...`
|
|
1403
|
-
: summary.preview;
|
|
1404
|
-
const placeholder = `[📋 #${id}${lang} ${summary.lineCount}L] "${preview}"`;
|
|
1529
|
+
const plural = lineCount === 1 ? '' : 's';
|
|
1530
|
+
const placeholder = `[Pasted text #${id} +${lineCount} line${plural}]`;
|
|
1405
1531
|
return { id, placeholder };
|
|
1406
1532
|
}
|
|
1407
1533
|
insertPastePlaceholder(content) {
|
|
@@ -1409,67 +1535,21 @@ export class TerminalInput extends EventEmitter {
|
|
|
1409
1535
|
if (available <= 0)
|
|
1410
1536
|
return;
|
|
1411
1537
|
const cleanContent = content.slice(0, available);
|
|
1412
|
-
const
|
|
1413
|
-
|
|
1414
|
-
if (summary.lineCount < 5) {
|
|
1415
|
-
const placeholder = this.findPlaceholderAt(this.cursor);
|
|
1416
|
-
const insertPos = placeholder && this.cursor > placeholder.start ? placeholder.end : this.cursor;
|
|
1417
|
-
this.insertPlainText(cleanContent, insertPos);
|
|
1418
|
-
this.cursor = insertPos + cleanContent.length;
|
|
1419
|
-
return;
|
|
1420
|
-
}
|
|
1421
|
-
const { id, placeholder } = this.buildPlaceholder(summary);
|
|
1538
|
+
const lineCount = cleanContent.split('\n').length;
|
|
1539
|
+
const { id, placeholder } = this.buildPlaceholder(lineCount);
|
|
1422
1540
|
const insertPos = this.cursor;
|
|
1423
1541
|
this.shiftPlaceholders(insertPos, placeholder.length);
|
|
1424
1542
|
this.pastePlaceholders.push({
|
|
1425
1543
|
id,
|
|
1426
1544
|
content: cleanContent,
|
|
1427
|
-
lineCount
|
|
1545
|
+
lineCount,
|
|
1428
1546
|
placeholder,
|
|
1429
1547
|
start: insertPos,
|
|
1430
1548
|
end: insertPos + placeholder.length,
|
|
1431
|
-
summary,
|
|
1432
|
-
expanded: false,
|
|
1433
1549
|
});
|
|
1434
1550
|
this.buffer = this.buffer.slice(0, insertPos) + placeholder + this.buffer.slice(insertPos);
|
|
1435
1551
|
this.cursor = insertPos + placeholder.length;
|
|
1436
1552
|
}
|
|
1437
|
-
/**
|
|
1438
|
-
* Toggle expansion of a paste placeholder at the current cursor position.
|
|
1439
|
-
* When expanded, shows first 3 and last 2 lines of the content.
|
|
1440
|
-
*/
|
|
1441
|
-
togglePasteExpansion() {
|
|
1442
|
-
const placeholder = this.findPlaceholderAt(this.cursor);
|
|
1443
|
-
if (!placeholder)
|
|
1444
|
-
return false;
|
|
1445
|
-
placeholder.expanded = !placeholder.expanded;
|
|
1446
|
-
// Update the placeholder text in buffer
|
|
1447
|
-
const newPlaceholder = placeholder.expanded
|
|
1448
|
-
? this.buildExpandedPlaceholder(placeholder)
|
|
1449
|
-
: this.buildPlaceholder(placeholder.summary).placeholder;
|
|
1450
|
-
const lengthDiff = newPlaceholder.length - placeholder.placeholder.length;
|
|
1451
|
-
// Update buffer
|
|
1452
|
-
this.buffer =
|
|
1453
|
-
this.buffer.slice(0, placeholder.start) +
|
|
1454
|
-
newPlaceholder +
|
|
1455
|
-
this.buffer.slice(placeholder.end);
|
|
1456
|
-
// Update placeholder tracking
|
|
1457
|
-
placeholder.placeholder = newPlaceholder;
|
|
1458
|
-
placeholder.end = placeholder.start + newPlaceholder.length;
|
|
1459
|
-
// Shift other placeholders
|
|
1460
|
-
this.shiftPlaceholders(placeholder.end, lengthDiff, placeholder.id);
|
|
1461
|
-
this.scheduleRender();
|
|
1462
|
-
return true;
|
|
1463
|
-
}
|
|
1464
|
-
buildExpandedPlaceholder(ph) {
|
|
1465
|
-
const lines = ph.content.split('\n');
|
|
1466
|
-
const firstLines = lines.slice(0, 3).map(l => l.slice(0, 60)).join('\n');
|
|
1467
|
-
const lastLines = lines.length > 5
|
|
1468
|
-
? '\n...\n' + lines.slice(-2).map(l => l.slice(0, 60)).join('\n')
|
|
1469
|
-
: '';
|
|
1470
|
-
const lang = ph.summary.language ? ` ${ph.summary.language.toUpperCase()}` : '';
|
|
1471
|
-
return `[📋 #${ph.id}${lang} ${ph.lineCount}L ▼]\n${firstLines}${lastLines}\n[/📋 #${ph.id}]`;
|
|
1472
|
-
}
|
|
1473
1553
|
deletePlaceholder(placeholder) {
|
|
1474
1554
|
const length = placeholder.end - placeholder.start;
|
|
1475
1555
|
this.buffer = this.buffer.slice(0, placeholder.start) + this.buffer.slice(placeholder.end);
|
|
@@ -1477,7 +1557,11 @@ export class TerminalInput extends EventEmitter {
|
|
|
1477
1557
|
this.shiftPlaceholders(placeholder.end, -length, placeholder.id);
|
|
1478
1558
|
this.cursor = placeholder.start;
|
|
1479
1559
|
}
|
|
1480
|
-
updateContextUsage(value) {
|
|
1560
|
+
updateContextUsage(value, autoCompactThreshold) {
|
|
1561
|
+
if (typeof autoCompactThreshold === 'number' && Number.isFinite(autoCompactThreshold)) {
|
|
1562
|
+
const boundedThreshold = Math.max(1, Math.min(100, Math.round(autoCompactThreshold)));
|
|
1563
|
+
this.contextAutoCompactThreshold = boundedThreshold;
|
|
1564
|
+
}
|
|
1481
1565
|
if (value === null || !Number.isFinite(value)) {
|
|
1482
1566
|
this.contextUsage = null;
|
|
1483
1567
|
}
|
|
@@ -1504,6 +1588,28 @@ export class TerminalInput extends EventEmitter {
|
|
|
1504
1588
|
const next = this.editMode === 'display-edits' ? 'ask-permission' : 'display-edits';
|
|
1505
1589
|
this.setEditMode(next);
|
|
1506
1590
|
}
|
|
1591
|
+
scheduleStreamingRender(delayMs) {
|
|
1592
|
+
if (this.streamingRenderTimer)
|
|
1593
|
+
return;
|
|
1594
|
+
const wait = Math.max(16, delayMs);
|
|
1595
|
+
this.streamingRenderTimer = setTimeout(() => {
|
|
1596
|
+
this.streamingRenderTimer = null;
|
|
1597
|
+
// During streaming, only update chat box (not full render)
|
|
1598
|
+
if (this.scrollRegionActive) {
|
|
1599
|
+
this.renderChatBoxAtBottom();
|
|
1600
|
+
}
|
|
1601
|
+
else {
|
|
1602
|
+
this.render();
|
|
1603
|
+
}
|
|
1604
|
+
}, wait);
|
|
1605
|
+
}
|
|
1606
|
+
resetStreamingRenderThrottle() {
|
|
1607
|
+
if (this.streamingRenderTimer) {
|
|
1608
|
+
clearTimeout(this.streamingRenderTimer);
|
|
1609
|
+
this.streamingRenderTimer = null;
|
|
1610
|
+
}
|
|
1611
|
+
this.lastStreamingRender = 0;
|
|
1612
|
+
}
|
|
1507
1613
|
scheduleRender() {
|
|
1508
1614
|
if (!this.canRender())
|
|
1509
1615
|
return;
|