erosolar-cli 1.7.340 → 1.7.342
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/sessionStore.d.ts +2 -0
- package/dist/core/sessionStore.d.ts.map +1 -1
- package/dist/core/sessionStore.js +1 -0
- package/dist/core/sessionStore.js.map +1 -1
- 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 +19 -7
- package/dist/shell/interactiveShell.d.ts.map +1 -1
- package/dist/shell/interactiveShell.js +271 -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 +82 -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 +215 -120
- package/dist/shell/terminalInput.d.ts.map +1 -1
- package/dist/shell/terminalInput.js +926 -537
- package/dist/shell/terminalInput.js.map +1 -1
- package/dist/shell/terminalInputAdapter.d.ts +99 -21
- package/dist/shell/terminalInputAdapter.d.ts.map +1 -1
- package/dist/shell/terminalInputAdapter.js +131 -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,21 @@
|
|
|
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';
|
|
20
|
+
import { theme } from '../ui/theme.js';
|
|
15
21
|
// ANSI escape codes
|
|
16
22
|
const ESC = {
|
|
17
23
|
// Cursor control
|
|
@@ -21,14 +27,18 @@ const ESC = {
|
|
|
21
27
|
SHOW: '\x1b[?25h',
|
|
22
28
|
TO: (row, col) => `\x1b[${row};${col}H`,
|
|
23
29
|
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
30
|
// Line control
|
|
30
31
|
CLEAR_LINE: '\x1b[2K',
|
|
31
32
|
CLEAR_TO_END: '\x1b[0J',
|
|
33
|
+
// Screen control
|
|
34
|
+
HOME: '\x1b[H',
|
|
35
|
+
CLEAR_SCREEN: '\x1b[2J',
|
|
36
|
+
// Alternate screen buffer (like vim/tmux)
|
|
37
|
+
ENTER_ALT_SCREEN: '\x1b[?1049h',
|
|
38
|
+
EXIT_ALT_SCREEN: '\x1b[?1049l',
|
|
39
|
+
// Scroll region
|
|
40
|
+
SET_SCROLL: (top, bottom) => `\x1b[${top};${bottom}r`,
|
|
41
|
+
RESET_SCROLL: '\x1b[r',
|
|
32
42
|
// Style
|
|
33
43
|
RESET: '\x1b[0m',
|
|
34
44
|
DIM: '\x1b[2m',
|
|
@@ -40,6 +50,9 @@ const ESC = {
|
|
|
40
50
|
PASTE_DISABLE: '\x1b[?2004l',
|
|
41
51
|
PASTE_START: '\x1b[200~',
|
|
42
52
|
PASTE_END: '\x1b[201~',
|
|
53
|
+
// Mouse tracking
|
|
54
|
+
MOUSE_ENABLE: '\x1b[?1000h\x1b[?1003h\x1b[?1006h', // Enable mouse tracking + SGR mode
|
|
55
|
+
MOUSE_DISABLE: '\x1b[?1006l\x1b[?1003l\x1b[?1000l', // Disable mouse tracking
|
|
43
56
|
};
|
|
44
57
|
/**
|
|
45
58
|
* Unified terminal input handler
|
|
@@ -68,49 +81,54 @@ export class TerminalInput extends EventEmitter {
|
|
|
68
81
|
statusMessage = null;
|
|
69
82
|
overrideStatusMessage = null; // Secondary status (warnings, etc.)
|
|
70
83
|
streamingLabel = null; // Streaming progress indicator
|
|
84
|
+
metaElapsedSeconds = null; // Optional elapsed time for header line
|
|
85
|
+
metaTokensUsed = null; // Optional token usage
|
|
86
|
+
metaTokenLimit = null; // Optional token window
|
|
87
|
+
metaThinkingMs = null; // Optional thinking duration
|
|
88
|
+
metaThinkingHasContent = false; // Whether collapsed thinking content exists
|
|
71
89
|
lastRenderContent = '';
|
|
72
90
|
lastRenderCursor = -1;
|
|
73
91
|
renderDirty = false;
|
|
74
92
|
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
93
|
// Lifecycle
|
|
84
94
|
disposed = false;
|
|
85
95
|
enabled = true;
|
|
86
96
|
contextUsage = null;
|
|
97
|
+
contextAutoCompactThreshold = 90;
|
|
98
|
+
// Track current content row (starts at top, moves down)
|
|
99
|
+
contentRow = 1;
|
|
100
|
+
// Track if scroll region is currently active
|
|
101
|
+
scrollRegionActive = false;
|
|
102
|
+
thinkingModeLabel = null;
|
|
103
|
+
// Scrollback buffer
|
|
104
|
+
scrollbackBuffer = [];
|
|
105
|
+
maxScrollbackLines = 10000;
|
|
106
|
+
scrollbackOffset = 0; // 0 = at bottom (live), > 0 = scrolled up
|
|
107
|
+
isInScrollbackMode = false;
|
|
108
|
+
scrollIndicatorFrame = 0; // For animated scroll indicator
|
|
109
|
+
// Alternate screen state
|
|
110
|
+
alternateScreenActive = false;
|
|
87
111
|
editMode = 'display-edits';
|
|
88
112
|
verificationEnabled = true;
|
|
89
113
|
autoContinueEnabled = false;
|
|
90
114
|
verificationHotkey = 'alt+v';
|
|
91
115
|
autoContinueHotkey = 'alt+c';
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
// Streaming input area render timer (updates elapsed time display)
|
|
116
|
+
thinkingHotkey = '/thinking';
|
|
117
|
+
modelLabel = null;
|
|
118
|
+
providerLabel = null;
|
|
119
|
+
// Streaming render throttle
|
|
120
|
+
lastStreamingRender = 0;
|
|
121
|
+
streamingRenderInterval = 250; // ms between renders during streaming
|
|
99
122
|
streamingRenderTimer = null;
|
|
100
|
-
// Reference to display module for getting line counts during streaming
|
|
101
|
-
displayRef = null;
|
|
102
|
-
// Unified UI initialization flag
|
|
103
|
-
unifiedUIInitialized = false;
|
|
104
123
|
constructor(writeStream = process.stdout, config = {}) {
|
|
105
124
|
super();
|
|
106
125
|
this.out = writeStream;
|
|
107
|
-
// Use schema defaults for configuration consistency
|
|
108
126
|
this.config = {
|
|
109
|
-
maxLines: config.maxLines ??
|
|
110
|
-
maxLength: config.maxLength ??
|
|
127
|
+
maxLines: config.maxLines ?? 1000,
|
|
128
|
+
maxLength: config.maxLength ?? 10000,
|
|
111
129
|
maxQueueSize: config.maxQueueSize ?? 100,
|
|
112
|
-
promptChar: config.promptChar ??
|
|
113
|
-
continuationChar: config.continuationChar ??
|
|
130
|
+
promptChar: config.promptChar ?? '> ',
|
|
131
|
+
continuationChar: config.continuationChar ?? '│ ',
|
|
114
132
|
};
|
|
115
133
|
}
|
|
116
134
|
// ===========================================================================
|
|
@@ -133,10 +151,39 @@ export class TerminalInput extends EventEmitter {
|
|
|
133
151
|
}
|
|
134
152
|
}
|
|
135
153
|
/**
|
|
136
|
-
*
|
|
154
|
+
* Enable mouse tracking in terminal
|
|
155
|
+
*/
|
|
156
|
+
enableMouseTracking() {
|
|
157
|
+
if (this.isTTY()) {
|
|
158
|
+
this.write(ESC.MOUSE_ENABLE);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Disable mouse tracking
|
|
163
|
+
*/
|
|
164
|
+
disableMouseTracking() {
|
|
165
|
+
if (this.isTTY()) {
|
|
166
|
+
this.write(ESC.MOUSE_DISABLE);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Process raw terminal data (handles bracketed paste sequences and mouse events)
|
|
137
171
|
* Returns true if the data was consumed (paste sequence)
|
|
138
172
|
*/
|
|
139
173
|
processRawData(data) {
|
|
174
|
+
// Check for mouse events (SGR mode: \x1b[<button;x;yM or m)
|
|
175
|
+
const mouseMatch = data.match(/\x1b\[<(\d+);(\d+);(\d+)([Mm])/);
|
|
176
|
+
if (mouseMatch) {
|
|
177
|
+
const button = parseInt(mouseMatch[1], 10);
|
|
178
|
+
const x = parseInt(mouseMatch[2], 10);
|
|
179
|
+
const y = parseInt(mouseMatch[3], 10);
|
|
180
|
+
const action = mouseMatch[4]; // 'M' = press, 'm' = release
|
|
181
|
+
this.handleMouseEvent(button, x, y, action);
|
|
182
|
+
// Remove mouse event from data and return remaining
|
|
183
|
+
const mouseEventEnd = data.indexOf(action) + 1;
|
|
184
|
+
const remaining = data.slice(mouseEventEnd);
|
|
185
|
+
return { consumed: true, passthrough: remaining };
|
|
186
|
+
}
|
|
140
187
|
// Check for paste start
|
|
141
188
|
if (data.includes(ESC.PASTE_START)) {
|
|
142
189
|
this.isPasting = true;
|
|
@@ -167,6 +214,21 @@ export class TerminalInput extends EventEmitter {
|
|
|
167
214
|
}
|
|
168
215
|
return { consumed: false, passthrough: data };
|
|
169
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* Handle mouse events (button, x, y coordinates, action)
|
|
219
|
+
*/
|
|
220
|
+
handleMouseEvent(button, _x, _y, _action) {
|
|
221
|
+
// Mouse wheel events: button 64 = scroll up, button 65 = scroll down
|
|
222
|
+
if (button === 64) {
|
|
223
|
+
// Scroll up (3 lines per wheel tick)
|
|
224
|
+
this.scrollUp(3);
|
|
225
|
+
}
|
|
226
|
+
else if (button === 65) {
|
|
227
|
+
// Scroll down (3 lines per wheel tick)
|
|
228
|
+
this.scrollDown(3);
|
|
229
|
+
}
|
|
230
|
+
// Ignore other mouse events (clicks, drags, etc.) for now
|
|
231
|
+
}
|
|
170
232
|
/**
|
|
171
233
|
* Handle a keypress event
|
|
172
234
|
*/
|
|
@@ -189,306 +251,36 @@ export class TerminalInput extends EventEmitter {
|
|
|
189
251
|
if (handled)
|
|
190
252
|
return;
|
|
191
253
|
}
|
|
192
|
-
// Handle '?' for help hint (if buffer is empty)
|
|
193
|
-
if (str === '?' && this.buffer.length === 0) {
|
|
194
|
-
this.emit('showHelp');
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
254
|
// Insert printable characters
|
|
198
255
|
if (str && !key?.ctrl && !key?.meta) {
|
|
199
256
|
this.insertText(str);
|
|
200
257
|
}
|
|
201
258
|
}
|
|
202
|
-
// Banner content to write on init (set via setBannerContent before initializeUnifiedUI)
|
|
203
|
-
bannerContent = null;
|
|
204
|
-
/**
|
|
205
|
-
* Set banner content to be written when unified UI initializes.
|
|
206
|
-
*/
|
|
207
|
-
setBannerContent(content) {
|
|
208
|
-
this.bannerContent = content;
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Initialize the unified UI system with BOTTOM PINNED chat box.
|
|
212
|
-
*
|
|
213
|
-
* Layout:
|
|
214
|
-
* 1. Clear screen
|
|
215
|
-
* 2. Write banner at top
|
|
216
|
-
* 3. Set content cursor row after banner
|
|
217
|
-
* 4. Render chat box at bottom (sets up scroll region)
|
|
218
|
-
*/
|
|
219
|
-
initializeUnifiedUI() {
|
|
220
|
-
if (this.unifiedUIInitialized) {
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
// Enter alternate screen buffer for complete terminal control
|
|
224
|
-
this.write(ESC.ALT_SCREEN_ENTER);
|
|
225
|
-
// Hide cursor during setup
|
|
226
|
-
this.write(ESC.HIDE);
|
|
227
|
-
// Clear screen and go home (in alternate buffer)
|
|
228
|
-
this.write(ESC.HOME);
|
|
229
|
-
this.write(ESC.CLEAR_SCREEN);
|
|
230
|
-
// Write banner at top
|
|
231
|
-
let bannerLines = 0;
|
|
232
|
-
if (this.bannerContent) {
|
|
233
|
-
const lines = this.bannerContent.split('\n');
|
|
234
|
-
bannerLines = lines.length + 2; // +2 for trailing \n\n
|
|
235
|
-
process.stdout.write(this.bannerContent + '\n\n');
|
|
236
|
-
}
|
|
237
|
-
// Set content cursor row after banner
|
|
238
|
-
this.contentCursorRow = bannerLines > 0 ? bannerLines + 1 : 1;
|
|
239
|
-
// Content ends at same row initially (no content yet)
|
|
240
|
-
this.contentEndRow = this.contentCursorRow - 1;
|
|
241
|
-
// Mark initialized
|
|
242
|
-
this.unifiedUIInitialized = true;
|
|
243
|
-
// Render floating chat box below content
|
|
244
|
-
this.renderFloatingInputArea();
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* Clear the input area at its tracked position.
|
|
248
|
-
* Returns true if something was cleared.
|
|
249
|
-
*/
|
|
250
|
-
clearInputArea() {
|
|
251
|
-
if (this.inputAreaStartRow > 0 && this.flowModeRenderedLines > 0) {
|
|
252
|
-
for (let i = 0; i < this.flowModeRenderedLines; i++) {
|
|
253
|
-
this.write(ESC.TO(this.inputAreaStartRow + i, 1));
|
|
254
|
-
this.write(ESC.CLEAR_LINE);
|
|
255
|
-
}
|
|
256
|
-
return true;
|
|
257
|
-
}
|
|
258
|
-
return false;
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Reset input area tracking state.
|
|
262
|
-
*/
|
|
263
|
-
resetInputAreaTracking() {
|
|
264
|
-
this.inputAreaStartRow = 0;
|
|
265
|
-
this.flowModeRenderedLines = 0;
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* Render chat box - FLOATING below content (no scroll regions).
|
|
269
|
-
* Chat box appears right after content and moves down as content grows.
|
|
270
|
-
* Content and banner scroll naturally off the top of the screen.
|
|
271
|
-
*/
|
|
272
|
-
renderFloatingInputArea() {
|
|
273
|
-
const { cols } = this.getSize();
|
|
274
|
-
const divider = '─'.repeat(cols);
|
|
275
|
-
const { dim: DIM, reset: R } = UI_COLORS;
|
|
276
|
-
// Chat box is 4 lines: divider + input + divider + controls
|
|
277
|
-
const chatBoxHeight = 4;
|
|
278
|
-
// Chat box starts right after content
|
|
279
|
-
const chatBoxStartRow = this.contentEndRow + 1;
|
|
280
|
-
// Save cursor position before rendering
|
|
281
|
-
this.write('\x1b7');
|
|
282
|
-
// Hide cursor during render
|
|
283
|
-
this.write(ESC.HIDE);
|
|
284
|
-
// Track position
|
|
285
|
-
this.inputAreaStartRow = chatBoxStartRow;
|
|
286
|
-
let currentRow = chatBoxStartRow;
|
|
287
|
-
// Helper to write a line at absolute position (clears then writes)
|
|
288
|
-
const writeLine = (content) => {
|
|
289
|
-
this.write(ESC.TO(currentRow, 1));
|
|
290
|
-
this.write(ESC.CLEAR_LINE);
|
|
291
|
-
this.write(content);
|
|
292
|
-
currentRow++;
|
|
293
|
-
};
|
|
294
|
-
// Top divider
|
|
295
|
-
writeLine(`${DIM}${divider}${R}`);
|
|
296
|
-
// Input line with > prompt
|
|
297
|
-
const { lines, cursorCol } = this.wrapBuffer(cols - 3);
|
|
298
|
-
const displayLine = lines[0] ?? '';
|
|
299
|
-
const inputRow = currentRow;
|
|
300
|
-
writeLine(`${DIM}>${R} ${displayLine}`);
|
|
301
|
-
// Bottom divider
|
|
302
|
-
writeLine(`${DIM}${divider}${R}`);
|
|
303
|
-
// Mode controls line - Claude Code style
|
|
304
|
-
this.write(ESC.TO(currentRow, 1));
|
|
305
|
-
this.write(ESC.CLEAR_LINE);
|
|
306
|
-
this.write(this.buildClaudeStyleControls(cols));
|
|
307
|
-
// Track lines rendered
|
|
308
|
-
this.flowModeRenderedLines = chatBoxHeight;
|
|
309
|
-
// Restore cursor position (back to where content was being written)
|
|
310
|
-
// During streaming, this keeps cursor in content area
|
|
311
|
-
// During idle, cursor was in input area anyway
|
|
312
|
-
this.write('\x1b8');
|
|
313
|
-
// Show cursor
|
|
314
|
-
this.write(ESC.SHOW);
|
|
315
|
-
// Update tracking
|
|
316
|
-
this.lastRenderContent = this.buffer;
|
|
317
|
-
this.lastRenderCursor = this.cursor;
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* Build Claude Code style controls line.
|
|
321
|
-
* Shows: edit mode indicator (shift+tab to cycle)
|
|
322
|
-
*/
|
|
323
|
-
buildClaudeStyleControls(cols) {
|
|
324
|
-
const { dim: DIM, green: GREEN, yellow: YELLOW, cyan: CYAN, reset: R } = UI_COLORS;
|
|
325
|
-
// Edit mode indicator
|
|
326
|
-
let editModeText;
|
|
327
|
-
if (this.editMode === 'display-edits') {
|
|
328
|
-
editModeText = `${GREEN}⏵⏵${R} accept edits on`;
|
|
329
|
-
}
|
|
330
|
-
else {
|
|
331
|
-
editModeText = `${YELLOW}⏸⏸${R} ask before edit`;
|
|
332
|
-
}
|
|
333
|
-
// Build controls line
|
|
334
|
-
const parts = [` ${editModeText} ${DIM}(shift+tab to cycle)${R}`];
|
|
335
|
-
// Add thinking mode if enabled
|
|
336
|
-
if (this.thinkingEnabled) {
|
|
337
|
-
parts.push(`${CYAN}💭${R}`);
|
|
338
|
-
}
|
|
339
|
-
// Add context usage if available
|
|
340
|
-
if (this.contextUsage !== null) {
|
|
341
|
-
const rem = Math.max(0, 100 - this.contextUsage);
|
|
342
|
-
if (rem < 10) {
|
|
343
|
-
parts.push(`${UI_COLORS.red}ctx ${rem}%${R}`);
|
|
344
|
-
}
|
|
345
|
-
else if (rem < 25) {
|
|
346
|
-
parts.push(`${YELLOW}ctx ${rem}%${R}`);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
return parts.join(` ${DIM}·${R} `);
|
|
350
|
-
}
|
|
351
259
|
/**
|
|
352
260
|
* Set the input mode
|
|
353
261
|
*
|
|
354
|
-
*
|
|
355
|
-
* Scroll region protects chat box, content scrolls above it.
|
|
262
|
+
* Content flows naturally - no scroll region pinning.
|
|
356
263
|
*/
|
|
357
264
|
setMode(mode) {
|
|
358
265
|
const prevMode = this.mode;
|
|
359
266
|
this.mode = mode;
|
|
360
267
|
if (mode === 'streaming' && prevMode !== 'streaming') {
|
|
361
|
-
|
|
362
|
-
this.streamingStartTime = Date.now();
|
|
363
|
-
// Ensure unified UI is initialized
|
|
364
|
-
if (!this.unifiedUIInitialized) {
|
|
365
|
-
this.initializeUnifiedUI();
|
|
366
|
-
}
|
|
367
|
-
// Start periodic render timer to keep chat box updated during streaming
|
|
368
|
-
// This updates contentEndRow from display and re-renders chat box
|
|
369
|
-
if (!this.streamingRenderTimer) {
|
|
370
|
-
this.streamingRenderTimer = setInterval(() => {
|
|
371
|
-
// Update contentEndRow from display's line count
|
|
372
|
-
if (this.displayRef?.getTotalWrittenLines) {
|
|
373
|
-
this.contentEndRow = this.displayRef.getTotalWrittenLines();
|
|
374
|
-
}
|
|
375
|
-
// Re-render chat box at updated position
|
|
376
|
-
this.renderFloatingInputArea();
|
|
377
|
-
}, 100); // Update every 100ms
|
|
378
|
-
}
|
|
379
|
-
// Initial render
|
|
268
|
+
this.resetStreamingRenderThrottle();
|
|
380
269
|
this.renderDirty = true;
|
|
381
|
-
this.
|
|
270
|
+
this.render();
|
|
382
271
|
}
|
|
383
272
|
else if (mode !== 'streaming' && prevMode === 'streaming') {
|
|
384
|
-
//
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
this.streamingRenderTimer = null;
|
|
388
|
-
}
|
|
389
|
-
// Reset streaming time
|
|
390
|
-
this.streamingStartTime = null;
|
|
391
|
-
// Final render with accurate position
|
|
392
|
-
this.renderDirty = true;
|
|
393
|
-
this.scheduleRender();
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
/**
|
|
397
|
-
* Set the row where content ends (for idle mode positioning).
|
|
398
|
-
* Input area will render starting from this row + 1.
|
|
399
|
-
*/
|
|
400
|
-
setContentEndRow(row) {
|
|
401
|
-
this.contentEndRow = Math.max(0, row);
|
|
402
|
-
this.renderDirty = true;
|
|
403
|
-
this.scheduleRender();
|
|
404
|
-
}
|
|
405
|
-
/**
|
|
406
|
-
* Set available slash commands for auto-complete suggestions.
|
|
407
|
-
*/
|
|
408
|
-
setCommands(commands) {
|
|
409
|
-
this.commandSuggestions = commands;
|
|
410
|
-
this.updateSuggestions();
|
|
411
|
-
}
|
|
412
|
-
/**
|
|
413
|
-
* Update filtered suggestions based on current input.
|
|
414
|
-
*/
|
|
415
|
-
updateSuggestions() {
|
|
416
|
-
const input = this.buffer.trim();
|
|
417
|
-
// Only show suggestions when input starts with "/"
|
|
418
|
-
if (!input.startsWith('/')) {
|
|
419
|
-
this.showSuggestions = false;
|
|
420
|
-
this.filteredSuggestions = [];
|
|
421
|
-
this.selectedSuggestionIndex = 0;
|
|
422
|
-
return;
|
|
423
|
-
}
|
|
424
|
-
const query = input.toLowerCase();
|
|
425
|
-
this.filteredSuggestions = this.commandSuggestions.filter(cmd => cmd.command.toLowerCase().startsWith(query) ||
|
|
426
|
-
cmd.command.toLowerCase().includes(query.slice(1)));
|
|
427
|
-
// Show suggestions if we have matches
|
|
428
|
-
this.showSuggestions = this.filteredSuggestions.length > 0;
|
|
429
|
-
// Keep selection in bounds
|
|
430
|
-
if (this.selectedSuggestionIndex >= this.filteredSuggestions.length) {
|
|
431
|
-
this.selectedSuggestionIndex = Math.max(0, this.filteredSuggestions.length - 1);
|
|
273
|
+
// Streaming ended - render the input area
|
|
274
|
+
this.resetStreamingRenderThrottle();
|
|
275
|
+
this.forceRender();
|
|
432
276
|
}
|
|
433
277
|
}
|
|
434
278
|
/**
|
|
435
|
-
*
|
|
436
|
-
|
|
437
|
-
selectNextSuggestion() {
|
|
438
|
-
if (!this.showSuggestions || this.filteredSuggestions.length === 0)
|
|
439
|
-
return;
|
|
440
|
-
this.selectedSuggestionIndex = (this.selectedSuggestionIndex + 1) % this.filteredSuggestions.length;
|
|
441
|
-
this.renderDirty = true;
|
|
442
|
-
this.scheduleRender();
|
|
443
|
-
}
|
|
444
|
-
/**
|
|
445
|
-
* Select previous suggestion (arrow up / shift+tab).
|
|
446
|
-
*/
|
|
447
|
-
selectPrevSuggestion() {
|
|
448
|
-
if (!this.showSuggestions || this.filteredSuggestions.length === 0)
|
|
449
|
-
return;
|
|
450
|
-
this.selectedSuggestionIndex = this.selectedSuggestionIndex === 0
|
|
451
|
-
? this.filteredSuggestions.length - 1
|
|
452
|
-
: this.selectedSuggestionIndex - 1;
|
|
453
|
-
this.renderDirty = true;
|
|
454
|
-
this.scheduleRender();
|
|
455
|
-
}
|
|
456
|
-
/**
|
|
457
|
-
* Accept current suggestion and insert into buffer.
|
|
279
|
+
* Legacy method - no longer used (content flows naturally).
|
|
280
|
+
* @deprecated Use setContentRow instead
|
|
458
281
|
*/
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
return false;
|
|
462
|
-
const selected = this.filteredSuggestions[this.selectedSuggestionIndex];
|
|
463
|
-
if (!selected)
|
|
464
|
-
return false;
|
|
465
|
-
// Replace buffer with selected command
|
|
466
|
-
this.buffer = selected.command + ' ';
|
|
467
|
-
this.cursor = this.buffer.length;
|
|
468
|
-
this.showSuggestions = false;
|
|
469
|
-
this.renderDirty = true;
|
|
470
|
-
this.scheduleRender();
|
|
471
|
-
return true;
|
|
472
|
-
}
|
|
473
|
-
/**
|
|
474
|
-
* Check if suggestions are visible.
|
|
475
|
-
*/
|
|
476
|
-
areSuggestionsVisible() {
|
|
477
|
-
return this.showSuggestions && this.filteredSuggestions.length > 0;
|
|
478
|
-
}
|
|
479
|
-
/**
|
|
480
|
-
* Toggle thinking/reasoning mode
|
|
481
|
-
*/
|
|
482
|
-
toggleThinking() {
|
|
483
|
-
this.thinkingEnabled = !this.thinkingEnabled;
|
|
484
|
-
this.emit('thinkingToggle', this.thinkingEnabled);
|
|
485
|
-
this.scheduleRender();
|
|
486
|
-
}
|
|
487
|
-
/**
|
|
488
|
-
* Get thinking enabled state
|
|
489
|
-
*/
|
|
490
|
-
isThinkingEnabled() {
|
|
491
|
-
return this.thinkingEnabled;
|
|
282
|
+
setPinnedHeaderLines(_count) {
|
|
283
|
+
// No-op: scroll region pinning removed
|
|
492
284
|
}
|
|
493
285
|
/**
|
|
494
286
|
* Get current mode
|
|
@@ -521,17 +313,14 @@ export class TerminalInput extends EventEmitter {
|
|
|
521
313
|
}
|
|
522
314
|
/**
|
|
523
315
|
* Clear the buffer
|
|
524
|
-
* @param skipRender - If true, don't trigger a re-render (used during submit flow)
|
|
525
316
|
*/
|
|
526
|
-
clear(
|
|
317
|
+
clear() {
|
|
527
318
|
this.buffer = '';
|
|
528
319
|
this.cursor = 0;
|
|
529
320
|
this.historyIndex = -1;
|
|
530
321
|
this.tempInput = '';
|
|
531
322
|
this.pastePlaceholders = [];
|
|
532
|
-
|
|
533
|
-
this.scheduleRender();
|
|
534
|
-
}
|
|
323
|
+
this.scheduleRender();
|
|
535
324
|
}
|
|
536
325
|
/**
|
|
537
326
|
* Get queued inputs
|
|
@@ -602,6 +391,37 @@ export class TerminalInput extends EventEmitter {
|
|
|
602
391
|
this.streamingLabel = next;
|
|
603
392
|
this.scheduleRender();
|
|
604
393
|
}
|
|
394
|
+
/**
|
|
395
|
+
* Surface meta status just above the divider (e.g., elapsed time or token usage).
|
|
396
|
+
*/
|
|
397
|
+
setMetaStatus(meta) {
|
|
398
|
+
const nextElapsed = typeof meta.elapsedSeconds === 'number' && Number.isFinite(meta.elapsedSeconds) && meta.elapsedSeconds >= 0
|
|
399
|
+
? Math.floor(meta.elapsedSeconds)
|
|
400
|
+
: null;
|
|
401
|
+
const nextTokens = typeof meta.tokensUsed === 'number' && Number.isFinite(meta.tokensUsed) && meta.tokensUsed >= 0
|
|
402
|
+
? Math.floor(meta.tokensUsed)
|
|
403
|
+
: null;
|
|
404
|
+
const nextLimit = typeof meta.tokenLimit === 'number' && Number.isFinite(meta.tokenLimit) && meta.tokenLimit > 0
|
|
405
|
+
? Math.floor(meta.tokenLimit)
|
|
406
|
+
: null;
|
|
407
|
+
const nextThinking = typeof meta.thinkingMs === 'number' && Number.isFinite(meta.thinkingMs) && meta.thinkingMs >= 0
|
|
408
|
+
? Math.floor(meta.thinkingMs)
|
|
409
|
+
: null;
|
|
410
|
+
const nextThinkingHasContent = !!meta.thinkingHasContent;
|
|
411
|
+
if (this.metaElapsedSeconds === nextElapsed &&
|
|
412
|
+
this.metaTokensUsed === nextTokens &&
|
|
413
|
+
this.metaTokenLimit === nextLimit &&
|
|
414
|
+
this.metaThinkingMs === nextThinking &&
|
|
415
|
+
this.metaThinkingHasContent === nextThinkingHasContent) {
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
this.metaElapsedSeconds = nextElapsed;
|
|
419
|
+
this.metaTokensUsed = nextTokens;
|
|
420
|
+
this.metaTokenLimit = nextLimit;
|
|
421
|
+
this.metaThinkingMs = nextThinking;
|
|
422
|
+
this.metaThinkingHasContent = nextThinkingHasContent;
|
|
423
|
+
this.scheduleRender();
|
|
424
|
+
}
|
|
605
425
|
/**
|
|
606
426
|
* Keep mode toggles (verification/auto-continue) visible in the control bar.
|
|
607
427
|
* Hotkey labels remain stable so the bar looks the same before/during streaming.
|
|
@@ -611,26 +431,22 @@ export class TerminalInput extends EventEmitter {
|
|
|
611
431
|
const nextAutoContinue = !!options.autoContinueEnabled;
|
|
612
432
|
const nextVerifyHotkey = options.verificationHotkey ?? this.verificationHotkey;
|
|
613
433
|
const nextAutoHotkey = options.autoContinueHotkey ?? this.autoContinueHotkey;
|
|
434
|
+
const nextThinkingHotkey = options.thinkingHotkey ?? this.thinkingHotkey;
|
|
435
|
+
const nextThinkingLabel = options.thinkingModeLabel === undefined ? this.thinkingModeLabel : (options.thinkingModeLabel || null);
|
|
614
436
|
if (this.verificationEnabled === nextVerification &&
|
|
615
437
|
this.autoContinueEnabled === nextAutoContinue &&
|
|
616
438
|
this.verificationHotkey === nextVerifyHotkey &&
|
|
617
|
-
this.autoContinueHotkey === nextAutoHotkey
|
|
439
|
+
this.autoContinueHotkey === nextAutoHotkey &&
|
|
440
|
+
this.thinkingHotkey === nextThinkingHotkey &&
|
|
441
|
+
this.thinkingModeLabel === nextThinkingLabel) {
|
|
618
442
|
return;
|
|
619
443
|
}
|
|
620
444
|
this.verificationEnabled = nextVerification;
|
|
621
445
|
this.autoContinueEnabled = nextAutoContinue;
|
|
622
446
|
this.verificationHotkey = nextVerifyHotkey;
|
|
623
447
|
this.autoContinueHotkey = nextAutoHotkey;
|
|
624
|
-
this.
|
|
625
|
-
|
|
626
|
-
/**
|
|
627
|
-
* Set the model info string (e.g., "OpenAI · gpt-4")
|
|
628
|
-
* This is displayed persistently above the input area.
|
|
629
|
-
*/
|
|
630
|
-
setModelInfo(info) {
|
|
631
|
-
if (this.modelInfo === info)
|
|
632
|
-
return;
|
|
633
|
-
this.modelInfo = info;
|
|
448
|
+
this.thinkingHotkey = nextThinkingHotkey;
|
|
449
|
+
this.thinkingModeLabel = nextThinkingLabel;
|
|
634
450
|
this.scheduleRender();
|
|
635
451
|
}
|
|
636
452
|
/**
|
|
@@ -643,33 +459,171 @@ export class TerminalInput extends EventEmitter {
|
|
|
643
459
|
this.scheduleRender();
|
|
644
460
|
}
|
|
645
461
|
/**
|
|
646
|
-
*
|
|
647
|
-
|
|
648
|
-
|
|
462
|
+
* Surface model/provider context in the controls bar.
|
|
463
|
+
*/
|
|
464
|
+
setModelContext(options) {
|
|
465
|
+
const nextModel = options.model?.trim() || null;
|
|
466
|
+
const nextProvider = options.provider?.trim() || null;
|
|
467
|
+
if (this.modelLabel === nextModel && this.providerLabel === nextProvider) {
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
this.modelLabel = nextModel;
|
|
471
|
+
this.providerLabel = nextProvider;
|
|
472
|
+
this.scheduleRender();
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Render the floating input area at contentRow.
|
|
476
|
+
*
|
|
477
|
+
* The chat box "floats" - it renders right below the last streamed content.
|
|
478
|
+
* As content is added, contentRow advances, and the chat box moves down.
|
|
479
|
+
* No scroll regions - pure floating behavior.
|
|
649
480
|
*/
|
|
650
481
|
render() {
|
|
651
482
|
if (!this.canRender())
|
|
652
483
|
return;
|
|
653
484
|
if (this.isRendering)
|
|
654
485
|
return;
|
|
486
|
+
const streamingActive = this.mode === 'streaming' || isStreamingMode();
|
|
487
|
+
// During streaming, throttle re-renders
|
|
488
|
+
if (streamingActive && this.lastStreamingRender > 0) {
|
|
489
|
+
const elapsed = Date.now() - this.lastStreamingRender;
|
|
490
|
+
const waitMs = Math.max(0, this.streamingRenderInterval - elapsed);
|
|
491
|
+
if (waitMs > 0) {
|
|
492
|
+
this.renderDirty = true;
|
|
493
|
+
this.scheduleStreamingRender(waitMs);
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
655
497
|
const shouldSkip = !this.renderDirty &&
|
|
656
498
|
this.buffer === this.lastRenderContent &&
|
|
657
499
|
this.cursor === this.lastRenderCursor;
|
|
658
500
|
this.renderDirty = false;
|
|
659
|
-
// Skip if nothing changed (unless explicitly forced)
|
|
660
501
|
if (shouldSkip) {
|
|
661
502
|
return;
|
|
662
503
|
}
|
|
663
|
-
// If write lock is held, defer render
|
|
664
504
|
if (writeLock.isLocked()) {
|
|
665
505
|
writeLock.safeWrite(() => this.render());
|
|
666
506
|
return;
|
|
667
507
|
}
|
|
508
|
+
this.renderPinnedChatBox();
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Unified scroll region renderer.
|
|
512
|
+
* Chat box is ALWAYS pinned at the bottom of the terminal.
|
|
513
|
+
* Content scrolls in the region above the chat box.
|
|
514
|
+
*/
|
|
515
|
+
renderPinnedChatBox() {
|
|
516
|
+
const { rows, cols } = this.getSize();
|
|
517
|
+
const maxWidth = Math.max(8, cols - 4);
|
|
518
|
+
const streamingActive = this.mode === 'streaming' || isStreamingMode();
|
|
519
|
+
// Wrap buffer into display lines
|
|
520
|
+
const { lines, cursorLine, cursorCol } = this.wrapBuffer(maxWidth);
|
|
521
|
+
const maxVisible = Math.max(1, Math.min(this.config.maxLines, rows - 3));
|
|
522
|
+
const displayLines = Math.min(lines.length, maxVisible);
|
|
523
|
+
const metaLines = this.buildMetaLines(cols - 2);
|
|
524
|
+
// Calculate display window (keep cursor visible)
|
|
525
|
+
let startLine = 0;
|
|
526
|
+
if (lines.length > displayLines) {
|
|
527
|
+
startLine = Math.max(0, cursorLine - displayLines + 1);
|
|
528
|
+
startLine = Math.min(startLine, lines.length - displayLines);
|
|
529
|
+
}
|
|
530
|
+
const visibleLines = lines.slice(startLine, startLine + displayLines);
|
|
531
|
+
const adjustedCursorLine = cursorLine - startLine;
|
|
532
|
+
// Chat box height
|
|
533
|
+
const chatBoxHeight = this.getChatBoxHeight();
|
|
534
|
+
// ALWAYS pin chat box at absolute bottom
|
|
535
|
+
const chatBoxStartRow = Math.max(1, rows - chatBoxHeight + 1);
|
|
536
|
+
const scrollEnd = chatBoxStartRow - 1;
|
|
537
|
+
writeLock.lock('terminalInput.renderPinned');
|
|
668
538
|
this.isRendering = true;
|
|
669
|
-
writeLock.lock('terminalInput.render');
|
|
670
539
|
try {
|
|
671
|
-
|
|
672
|
-
this.
|
|
540
|
+
this.write(ESC.SAVE);
|
|
541
|
+
this.write(ESC.HIDE);
|
|
542
|
+
// Temporarily reset scroll region to write chat box cleanly
|
|
543
|
+
if (this.scrollRegionActive) {
|
|
544
|
+
this.write(ESC.RESET_SCROLL);
|
|
545
|
+
}
|
|
546
|
+
// Clear the chat box area
|
|
547
|
+
for (let i = 0; i < chatBoxHeight; i++) {
|
|
548
|
+
const row = chatBoxStartRow + i;
|
|
549
|
+
if (row <= rows) {
|
|
550
|
+
this.write(ESC.TO(row, 1));
|
|
551
|
+
this.write(ESC.CLEAR_LINE);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
let currentRow = chatBoxStartRow;
|
|
555
|
+
// Meta/status header
|
|
556
|
+
for (const metaLine of metaLines) {
|
|
557
|
+
this.write(ESC.TO(currentRow, 1));
|
|
558
|
+
this.write(metaLine);
|
|
559
|
+
currentRow += 1;
|
|
560
|
+
}
|
|
561
|
+
// Separator line
|
|
562
|
+
this.write(ESC.TO(currentRow, 1));
|
|
563
|
+
this.write(renderDivider(cols - 2));
|
|
564
|
+
currentRow += 1;
|
|
565
|
+
// Render input lines
|
|
566
|
+
let finalRow = currentRow;
|
|
567
|
+
let finalCol = 3;
|
|
568
|
+
for (let i = 0; i < visibleLines.length; i++) {
|
|
569
|
+
const rowNum = currentRow + i;
|
|
570
|
+
this.write(ESC.TO(rowNum, 1));
|
|
571
|
+
const line = visibleLines[i] ?? '';
|
|
572
|
+
const isFirstLine = (startLine + i) === 0;
|
|
573
|
+
const isCursorLine = i === adjustedCursorLine;
|
|
574
|
+
this.write(ESC.BG_DARK);
|
|
575
|
+
this.write(ESC.DIM);
|
|
576
|
+
this.write(isFirstLine ? this.config.promptChar : this.config.continuationChar);
|
|
577
|
+
this.write(ESC.RESET);
|
|
578
|
+
this.write(ESC.BG_DARK);
|
|
579
|
+
if (isCursorLine) {
|
|
580
|
+
const col = Math.min(cursorCol, line.length);
|
|
581
|
+
const before = line.slice(0, col);
|
|
582
|
+
const at = col < line.length ? line[col] : ' ';
|
|
583
|
+
const after = col < line.length ? line.slice(col + 1) : '';
|
|
584
|
+
this.write(before);
|
|
585
|
+
this.write(ESC.REVERSE + ESC.BOLD);
|
|
586
|
+
this.write(at);
|
|
587
|
+
this.write(ESC.RESET + ESC.BG_DARK);
|
|
588
|
+
this.write(after);
|
|
589
|
+
finalRow = rowNum;
|
|
590
|
+
finalCol = this.config.promptChar.length + col + 1;
|
|
591
|
+
}
|
|
592
|
+
else {
|
|
593
|
+
this.write(line);
|
|
594
|
+
}
|
|
595
|
+
// Pad to edge
|
|
596
|
+
const lineLen = this.config.promptChar.length + line.length + (isCursorLine && cursorCol >= line.length ? 1 : 0);
|
|
597
|
+
const padding = Math.max(0, cols - lineLen - 1);
|
|
598
|
+
if (padding > 0)
|
|
599
|
+
this.write(' '.repeat(padding));
|
|
600
|
+
this.write(ESC.RESET);
|
|
601
|
+
}
|
|
602
|
+
// Mode controls line with all keyboard shortcuts
|
|
603
|
+
const controlRow = currentRow + visibleLines.length;
|
|
604
|
+
this.write(ESC.TO(controlRow, 1));
|
|
605
|
+
this.write(this.buildModeControls(cols));
|
|
606
|
+
// Restore scroll region and cursor
|
|
607
|
+
if (this.scrollRegionActive) {
|
|
608
|
+
// Restore scroll region
|
|
609
|
+
this.write(ESC.SET_SCROLL(1, scrollEnd));
|
|
610
|
+
// Restore cursor to where it was before rendering (preserves column position)
|
|
611
|
+
this.write(ESC.RESTORE);
|
|
612
|
+
}
|
|
613
|
+
else {
|
|
614
|
+
// Not streaming - position cursor in input box
|
|
615
|
+
this.write(ESC.RESTORE);
|
|
616
|
+
this.write(ESC.TO(finalRow, Math.min(finalCol, cols)));
|
|
617
|
+
}
|
|
618
|
+
this.write(ESC.SHOW);
|
|
619
|
+
// Update state
|
|
620
|
+
this.lastRenderContent = this.buffer;
|
|
621
|
+
this.lastRenderCursor = this.cursor;
|
|
622
|
+
this.lastStreamingRender = streamingActive ? Date.now() : 0;
|
|
623
|
+
if (this.streamingRenderTimer) {
|
|
624
|
+
clearTimeout(this.streamingRenderTimer);
|
|
625
|
+
this.streamingRenderTimer = null;
|
|
626
|
+
}
|
|
673
627
|
}
|
|
674
628
|
finally {
|
|
675
629
|
writeLock.unlock();
|
|
@@ -677,99 +631,208 @@ export class TerminalInput extends EventEmitter {
|
|
|
677
631
|
}
|
|
678
632
|
}
|
|
679
633
|
/**
|
|
680
|
-
* Build
|
|
681
|
-
*
|
|
634
|
+
* Build compact meta line above the divider.
|
|
635
|
+
* Shows model/provider and key metrics in a single line.
|
|
682
636
|
*/
|
|
683
|
-
|
|
684
|
-
const
|
|
685
|
-
const
|
|
686
|
-
//
|
|
687
|
-
if (this.
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
637
|
+
buildMetaLines(width) {
|
|
638
|
+
const leftParts = [];
|
|
639
|
+
const rightParts = [];
|
|
640
|
+
// Model/provider info (left side)
|
|
641
|
+
if (this.modelLabel) {
|
|
642
|
+
const modelText = this.providerLabel
|
|
643
|
+
? `${this.modelLabel} @ ${this.providerLabel}`
|
|
644
|
+
: this.modelLabel;
|
|
645
|
+
leftParts.push({ text: modelText, tone: 'info' });
|
|
646
|
+
}
|
|
647
|
+
// Elapsed time (right side)
|
|
648
|
+
if (this.metaElapsedSeconds !== null) {
|
|
649
|
+
rightParts.push({ text: `⏱ ${this.formatElapsedLabel(this.metaElapsedSeconds)}`, tone: 'muted' });
|
|
650
|
+
}
|
|
651
|
+
// Token usage (right side)
|
|
652
|
+
if (this.metaTokensUsed !== null) {
|
|
653
|
+
const formattedUsed = this.formatTokenCount(this.metaTokensUsed);
|
|
654
|
+
const formattedLimit = this.metaTokenLimit ? `/${this.formatTokenCount(this.metaTokenLimit)}` : '';
|
|
655
|
+
rightParts.push({ text: `⊛ ${formattedUsed}${formattedLimit}`, tone: 'muted' });
|
|
656
|
+
}
|
|
657
|
+
// Context remaining warning
|
|
658
|
+
const tokensRemaining = this.computeTokensRemaining();
|
|
659
|
+
if (tokensRemaining !== null) {
|
|
660
|
+
const contextPct = this.contextUsage !== null ? `${100 - this.contextUsage}%` : '';
|
|
661
|
+
rightParts.push({ text: `↓${tokensRemaining} ${contextPct}`, tone: this.contextUsage && this.contextUsage > 80 ? 'warn' : 'muted' });
|
|
662
|
+
}
|
|
663
|
+
// Thinking indicator
|
|
664
|
+
if (this.metaThinkingMs !== null) {
|
|
665
|
+
leftParts.push({ text: formatThinking(this.metaThinkingMs, this.metaThinkingHasContent), tone: 'info' });
|
|
666
|
+
}
|
|
667
|
+
if (!leftParts.length && !rightParts.length) {
|
|
668
|
+
return [];
|
|
669
|
+
}
|
|
670
|
+
// Render left and right aligned
|
|
671
|
+
if (!rightParts.length || width < 50) {
|
|
672
|
+
return [renderStatusLine([...leftParts, ...rightParts], width)];
|
|
673
|
+
}
|
|
674
|
+
const leftWidth = Math.max(12, Math.floor(width * 0.5));
|
|
675
|
+
const rightWidth = Math.max(14, width - leftWidth - 1);
|
|
676
|
+
const leftText = renderStatusLine(leftParts, leftWidth);
|
|
677
|
+
const rightText = renderStatusLine(rightParts, rightWidth);
|
|
678
|
+
const spacing = Math.max(1, width - this.visibleLength(leftText) - this.visibleLength(rightText));
|
|
679
|
+
return [`${leftText}${' '.repeat(spacing)}${rightText}`];
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Build mode controls line with all keyboard shortcuts.
|
|
683
|
+
* Shows status, all toggles, and contextual information.
|
|
684
|
+
*/
|
|
685
|
+
buildModeControls(cols) {
|
|
686
|
+
const width = Math.max(8, cols - 2);
|
|
687
|
+
const leftParts = [];
|
|
688
|
+
const rightParts = [];
|
|
689
|
+
// Streaming indicator
|
|
690
|
+
if (this.streamingLabel) {
|
|
691
|
+
leftParts.push({ text: `◐ ${this.streamingLabel}`, tone: 'info' });
|
|
692
|
+
}
|
|
693
|
+
// Override status (warnings, errors)
|
|
694
|
+
if (this.overrideStatusMessage) {
|
|
695
|
+
leftParts.push({ text: `⚠ ${this.overrideStatusMessage}`, tone: 'warn' });
|
|
696
|
+
}
|
|
697
|
+
// Main status message
|
|
698
|
+
if (this.statusMessage) {
|
|
699
|
+
leftParts.push({ text: this.statusMessage, tone: this.streamingLabel ? 'muted' : 'info' });
|
|
700
|
+
}
|
|
701
|
+
// === KEYBOARD SHORTCUTS ===
|
|
702
|
+
// Interrupt shortcut (during streaming)
|
|
703
|
+
if (this.mode === 'streaming' || this.scrollRegionActive) {
|
|
704
|
+
leftParts.push({ text: `${this.formatHotkey('esc')} stop`, tone: 'warn' });
|
|
705
|
+
}
|
|
706
|
+
// Edit mode toggle (Shift+Tab)
|
|
707
|
+
const editHotkey = this.formatHotkey('shift+tab');
|
|
708
|
+
const editLabel = this.editMode === 'display-edits' ? 'edits:accept' : 'edits:ask';
|
|
709
|
+
const editTone = this.editMode === 'display-edits' ? 'success' : 'muted';
|
|
710
|
+
leftParts.push({ text: `${editHotkey} ${editLabel}`, tone: editTone });
|
|
711
|
+
// Verification toggle (Alt+V)
|
|
712
|
+
const verifyHotkey = this.formatHotkey(this.verificationHotkey || 'alt+v');
|
|
713
|
+
const verifyLabel = this.verificationEnabled ? 'verify:on' : 'verify:off';
|
|
714
|
+
leftParts.push({ text: `${verifyHotkey} ${verifyLabel}`, tone: this.verificationEnabled ? 'success' : 'muted' });
|
|
715
|
+
// Auto-continue toggle (Alt+C)
|
|
716
|
+
const continueHotkey = this.formatHotkey(this.autoContinueHotkey || 'alt+c');
|
|
717
|
+
const continueLabel = this.autoContinueEnabled ? 'auto:on' : 'auto:off';
|
|
718
|
+
leftParts.push({ text: `${continueHotkey} ${continueLabel}`, tone: this.autoContinueEnabled ? 'info' : 'muted' });
|
|
719
|
+
// Thinking mode toggle (if available)
|
|
720
|
+
if (this.thinkingModeLabel) {
|
|
721
|
+
const thinkingHotkey = this.formatHotkey(this.thinkingHotkey || 'alt+t');
|
|
722
|
+
rightParts.push({ text: `${thinkingHotkey} think:${this.thinkingModeLabel}`, tone: 'info' });
|
|
723
|
+
}
|
|
724
|
+
// === CONTEXTUAL INFO ===
|
|
725
|
+
// Queued commands
|
|
726
|
+
if (this.queue.length > 0 && this.mode !== 'streaming') {
|
|
727
|
+
leftParts.push({ text: `queued:${this.queue.length}`, tone: 'info' });
|
|
696
728
|
}
|
|
697
|
-
//
|
|
698
|
-
if (this.
|
|
699
|
-
|
|
729
|
+
// Multi-line indicator
|
|
730
|
+
if (this.buffer.includes('\n')) {
|
|
731
|
+
const lineCount = this.buffer.split('\n').length;
|
|
732
|
+
rightParts.push({ text: `${lineCount}L`, tone: 'muted' });
|
|
700
733
|
}
|
|
701
734
|
// Paste indicator
|
|
702
735
|
if (this.pastePlaceholders.length > 0) {
|
|
703
|
-
const
|
|
704
|
-
|
|
736
|
+
const latest = this.pastePlaceholders[this.pastePlaceholders.length - 1];
|
|
737
|
+
rightParts.push({
|
|
738
|
+
text: `paste#${latest.id} +${latest.lineCount}L ${this.formatHotkey('backspace')}drop`,
|
|
739
|
+
tone: 'info',
|
|
740
|
+
});
|
|
705
741
|
}
|
|
706
|
-
//
|
|
707
|
-
|
|
708
|
-
|
|
742
|
+
// Context remaining warning
|
|
743
|
+
const contextRemaining = this.computeContextRemaining();
|
|
744
|
+
if (contextRemaining !== null) {
|
|
745
|
+
const tone = contextRemaining <= 10 ? 'warn' : 'muted';
|
|
746
|
+
const label = contextRemaining === 0 && this.contextUsage !== null
|
|
747
|
+
? 'compact imminent'
|
|
748
|
+
: `ctx:${contextRemaining}%`;
|
|
749
|
+
rightParts.push({ text: label, tone });
|
|
750
|
+
}
|
|
751
|
+
// Render: left-aligned shortcuts, right-aligned context info
|
|
752
|
+
if (!rightParts.length || width < 60) {
|
|
753
|
+
const merged = rightParts.length ? [...leftParts, ...rightParts] : leftParts;
|
|
754
|
+
return renderStatusLine(merged, width);
|
|
755
|
+
}
|
|
756
|
+
const leftWidth = Math.max(12, Math.floor(width * 0.65));
|
|
757
|
+
const rightWidth = Math.max(14, width - leftWidth - 1);
|
|
758
|
+
const leftText = renderStatusLine(leftParts, leftWidth);
|
|
759
|
+
const rightText = renderStatusLine(rightParts, rightWidth);
|
|
760
|
+
const spacing = Math.max(1, width - this.visibleLength(leftText) - this.visibleLength(rightText));
|
|
761
|
+
return `${leftText}${' '.repeat(spacing)}${rightText}`;
|
|
762
|
+
}
|
|
763
|
+
formatHotkey(hotkey) {
|
|
764
|
+
const normalized = hotkey.trim().toLowerCase();
|
|
765
|
+
if (!normalized)
|
|
766
|
+
return hotkey;
|
|
767
|
+
const parts = normalized.split('+').filter(Boolean);
|
|
768
|
+
const map = {
|
|
769
|
+
shift: '⇧',
|
|
770
|
+
sh: '⇧',
|
|
771
|
+
alt: '⌥',
|
|
772
|
+
option: '⌥',
|
|
773
|
+
opt: '⌥',
|
|
774
|
+
ctrl: '⌃',
|
|
775
|
+
control: '⌃',
|
|
776
|
+
cmd: '⌘',
|
|
777
|
+
meta: '⌘',
|
|
778
|
+
};
|
|
779
|
+
const formatted = parts
|
|
780
|
+
.map((part) => {
|
|
781
|
+
const symbol = map[part];
|
|
782
|
+
if (symbol)
|
|
783
|
+
return symbol;
|
|
784
|
+
return part.length === 1 ? part.toUpperCase() : part.toUpperCase();
|
|
785
|
+
})
|
|
786
|
+
.join('');
|
|
787
|
+
return formatted || hotkey;
|
|
788
|
+
}
|
|
789
|
+
computeContextRemaining() {
|
|
790
|
+
if (this.contextUsage === null) {
|
|
791
|
+
return null;
|
|
709
792
|
}
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
793
|
+
return Math.max(0, this.contextAutoCompactThreshold - this.contextUsage);
|
|
794
|
+
}
|
|
795
|
+
computeTokensRemaining() {
|
|
796
|
+
if (this.metaTokensUsed === null || this.metaTokenLimit === null) {
|
|
797
|
+
return null;
|
|
713
798
|
}
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
799
|
+
const remaining = Math.max(0, this.metaTokenLimit - this.metaTokensUsed);
|
|
800
|
+
return this.formatTokenCount(remaining);
|
|
801
|
+
}
|
|
802
|
+
formatElapsedLabel(seconds) {
|
|
803
|
+
if (seconds < 60) {
|
|
804
|
+
return `${seconds}s`;
|
|
805
|
+
}
|
|
806
|
+
const mins = Math.floor(seconds / 60);
|
|
807
|
+
const secs = seconds % 60;
|
|
808
|
+
return secs > 0 ? `${mins}m ${secs}s` : `${mins}m`;
|
|
809
|
+
}
|
|
810
|
+
formatTokenCount(value) {
|
|
811
|
+
if (!Number.isFinite(value)) {
|
|
812
|
+
return `${value}`;
|
|
813
|
+
}
|
|
814
|
+
if (value >= 1_000_000) {
|
|
815
|
+
return `${(value / 1_000_000).toFixed(1)}M`;
|
|
717
816
|
}
|
|
718
|
-
if (
|
|
719
|
-
return
|
|
817
|
+
if (value >= 1_000) {
|
|
818
|
+
return `${(value / 1_000).toFixed(1)}k`;
|
|
720
819
|
}
|
|
721
|
-
|
|
722
|
-
|
|
820
|
+
return `${Math.round(value)}`;
|
|
821
|
+
}
|
|
822
|
+
visibleLength(value) {
|
|
823
|
+
const ansiPattern = /\u001B\[[0-?]*[ -/]*[@-~]/g;
|
|
824
|
+
return value.replace(ansiPattern, '').length;
|
|
723
825
|
}
|
|
724
826
|
/**
|
|
725
|
-
*
|
|
726
|
-
*
|
|
727
|
-
*
|
|
728
|
-
* Layout: [toggles on left] ... [context info on right]
|
|
827
|
+
* Debug-only snapshot used by tests to assert rendered strings without
|
|
828
|
+
* needing a TTY. Not used by production code.
|
|
729
829
|
*/
|
|
730
|
-
|
|
731
|
-
const
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
// Edit mode (green=auto, yellow=ask) - per schema.editMode
|
|
737
|
-
if (this.editMode === 'display-edits') {
|
|
738
|
-
toggles.push(`${GREEN}⏵⏵ auto-edit${R}`);
|
|
739
|
-
}
|
|
740
|
-
else {
|
|
741
|
-
toggles.push(`${YELLOW}⏸⏸ ask-first${R}`);
|
|
742
|
-
}
|
|
743
|
-
// Thinking mode (cyan when on) - per schema.thinkingMode
|
|
744
|
-
toggles.push(this.thinkingEnabled ? `${CYAN}💭 think${R}` : `${DIM}○ think${R}`);
|
|
745
|
-
// Verification (green when on) - per schema.verificationMode
|
|
746
|
-
toggles.push(this.verificationEnabled ? `${GREEN}✓ verify${R}` : `${DIM}○ verify${R}`);
|
|
747
|
-
// Auto-continue (magenta when on) - per schema.autoContinueMode
|
|
748
|
-
toggles.push(this.autoContinueEnabled ? `${MAGENTA}↻ auto${R}` : `${DIM}○ auto${R}`);
|
|
749
|
-
const leftPart = toggles.join(`${DIM} · ${R}`) + `${DIM} (⇧⇥)${R}`;
|
|
750
|
-
// Context usage with color - per schema.contextUsage thresholds
|
|
751
|
-
let rightPart = '';
|
|
752
|
-
if (this.contextUsage !== null) {
|
|
753
|
-
const rem = Math.max(0, 100 - this.contextUsage);
|
|
754
|
-
// Thresholds: critical < 10%, warning < 25%
|
|
755
|
-
if (rem < 10)
|
|
756
|
-
rightPart = `${RED}⚠ ctx: ${rem}%${R}`;
|
|
757
|
-
else if (rem < 25)
|
|
758
|
-
rightPart = `${YELLOW}! ctx: ${rem}%${R}`;
|
|
759
|
-
else
|
|
760
|
-
rightPart = `${DIM}ctx: ${rem}%${R}`;
|
|
761
|
-
}
|
|
762
|
-
// Calculate visible lengths (strip ANSI)
|
|
763
|
-
const strip = (s) => s.replace(/\x1b\[[0-9;]*m/g, '');
|
|
764
|
-
const leftLen = strip(leftPart).length;
|
|
765
|
-
const rightLen = strip(rightPart).length;
|
|
766
|
-
if (leftLen + rightLen < maxWidth - 4) {
|
|
767
|
-
return `${leftPart}${' '.repeat(maxWidth - leftLen - rightLen)}${rightPart}`;
|
|
768
|
-
}
|
|
769
|
-
if (rightLen > 0 && leftLen + 8 < maxWidth) {
|
|
770
|
-
return `${leftPart} ${rightPart}`;
|
|
771
|
-
}
|
|
772
|
-
return leftPart;
|
|
830
|
+
getDebugUiSnapshot(width) {
|
|
831
|
+
const cols = Math.max(8, width ?? this.getSize().cols);
|
|
832
|
+
return {
|
|
833
|
+
meta: this.buildMetaLines(cols - 2),
|
|
834
|
+
controls: this.buildModeControls(cols),
|
|
835
|
+
};
|
|
773
836
|
}
|
|
774
837
|
/**
|
|
775
838
|
* Force a re-render
|
|
@@ -792,56 +855,224 @@ export class TerminalInput extends EventEmitter {
|
|
|
792
855
|
handleResize() {
|
|
793
856
|
this.lastRenderContent = '';
|
|
794
857
|
this.lastRenderCursor = -1;
|
|
795
|
-
this.
|
|
858
|
+
this.resetStreamingRenderThrottle();
|
|
859
|
+
// If in scrollback mode, re-render the scrollback view with new dimensions
|
|
860
|
+
if (this.isInScrollbackMode) {
|
|
861
|
+
this.renderScrollbackView();
|
|
862
|
+
}
|
|
863
|
+
else {
|
|
864
|
+
this.scheduleRender();
|
|
865
|
+
}
|
|
796
866
|
}
|
|
797
|
-
// Track current content row for writing
|
|
798
|
-
contentCursorRow = 1;
|
|
799
867
|
/**
|
|
800
|
-
*
|
|
801
|
-
*
|
|
868
|
+
* Enter streaming mode with scroll region.
|
|
869
|
+
* Sets up terminal scroll region to exclude chat box.
|
|
802
870
|
*/
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
871
|
+
enterStreamingScrollRegion() {
|
|
872
|
+
const { rows } = this.getSize();
|
|
873
|
+
const chatBoxHeight = this.getChatBoxHeight();
|
|
874
|
+
const scrollEnd = Math.max(1, rows - chatBoxHeight);
|
|
875
|
+
writeLock.lock('enterStreamingScrollRegion');
|
|
876
|
+
try {
|
|
877
|
+
// Set scroll region for content area (above chat box)
|
|
878
|
+
this.write(ESC.SET_SCROLL(1, scrollEnd));
|
|
879
|
+
// Position cursor at current content row
|
|
880
|
+
this.write(ESC.TO(Math.min(this.contentRow, scrollEnd), 1));
|
|
881
|
+
this.scrollRegionActive = true;
|
|
882
|
+
this.setStatusMessage('esc to interrupt');
|
|
883
|
+
}
|
|
884
|
+
finally {
|
|
885
|
+
writeLock.unlock();
|
|
886
|
+
}
|
|
887
|
+
// Render pinned chat box at bottom
|
|
888
|
+
this.forceRender();
|
|
820
889
|
}
|
|
821
890
|
/**
|
|
822
|
-
*
|
|
891
|
+
* Exit streaming mode and restore normal operation.
|
|
823
892
|
*/
|
|
824
|
-
|
|
825
|
-
|
|
893
|
+
exitStreamingScrollRegion() {
|
|
894
|
+
writeLock.lock('exitStreamingScrollRegion');
|
|
895
|
+
try {
|
|
896
|
+
// Reset scroll region to full terminal
|
|
897
|
+
this.write(ESC.RESET_SCROLL);
|
|
898
|
+
this.scrollRegionActive = false;
|
|
899
|
+
this.setStatusMessage('Ready for prompts');
|
|
900
|
+
}
|
|
901
|
+
finally {
|
|
902
|
+
writeLock.unlock();
|
|
903
|
+
}
|
|
904
|
+
// Final render
|
|
905
|
+
this.forceRender();
|
|
906
|
+
}
|
|
907
|
+
/**
|
|
908
|
+
* Render chat box at bottom - now uses unified renderer.
|
|
909
|
+
* @deprecated Use renderPinnedChatBox() directly via render()/forceRender()
|
|
910
|
+
*/
|
|
911
|
+
renderChatBoxAtBottom() {
|
|
912
|
+
this.renderPinnedChatBox();
|
|
913
|
+
}
|
|
914
|
+
/**
|
|
915
|
+
* Stream content within the scroll region.
|
|
916
|
+
* Content is written directly and scrolls naturally.
|
|
917
|
+
*/
|
|
918
|
+
streamContent(content) {
|
|
919
|
+
if (!content)
|
|
826
920
|
return;
|
|
827
|
-
//
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
921
|
+
// Capture content in scrollback buffer
|
|
922
|
+
this.addToScrollback(content);
|
|
923
|
+
writeLock.lock('streamContent');
|
|
924
|
+
try {
|
|
925
|
+
// Write content - scroll region handles scrolling
|
|
926
|
+
this.write(content);
|
|
927
|
+
// Track newlines
|
|
928
|
+
const newlines = (content.match(/\n/g) || []).length;
|
|
929
|
+
this.contentRow += newlines;
|
|
930
|
+
}
|
|
931
|
+
finally {
|
|
932
|
+
writeLock.unlock();
|
|
933
|
+
}
|
|
934
|
+
// Throttle chat box updates during streaming
|
|
935
|
+
this.scheduleStreamingRender(200);
|
|
936
|
+
}
|
|
937
|
+
/**
|
|
938
|
+
* Enable scroll region (no-op in floating mode).
|
|
939
|
+
*/
|
|
940
|
+
enableScrollRegion() {
|
|
941
|
+
// No-op: using pure floating approach
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
944
|
+
* Disable scroll region (no-op in floating mode).
|
|
945
|
+
*/
|
|
946
|
+
disableScrollRegion() {
|
|
947
|
+
// No-op: using pure floating approach
|
|
948
|
+
}
|
|
949
|
+
/**
|
|
950
|
+
* Calculate chat box height.
|
|
951
|
+
*/
|
|
952
|
+
getChatBoxHeight() {
|
|
953
|
+
return 6; // Fixed: meta + divider + input + controls + buffer
|
|
954
|
+
}
|
|
955
|
+
/**
|
|
956
|
+
* @deprecated Use streamContent() instead
|
|
957
|
+
* Register with display's output interceptor - kept for backwards compatibility
|
|
958
|
+
*/
|
|
959
|
+
registerOutputInterceptor(_display) {
|
|
960
|
+
// No-op: Use streamContent() for cleaner floating chat box behavior
|
|
961
|
+
}
|
|
962
|
+
/**
|
|
963
|
+
* Write content above the floating chat box.
|
|
964
|
+
* Works both during streaming and when idle.
|
|
965
|
+
*/
|
|
966
|
+
writeToScrollRegion(content) {
|
|
967
|
+
if (!content)
|
|
968
|
+
return;
|
|
969
|
+
// Capture content in scrollback buffer
|
|
970
|
+
this.addToScrollback(content);
|
|
971
|
+
writeLock.lock('writeToScrollRegion');
|
|
972
|
+
try {
|
|
973
|
+
// Position cursor at content row and write
|
|
974
|
+
this.write(ESC.TO(this.contentRow, 1));
|
|
975
|
+
this.write(content);
|
|
976
|
+
// Track newlines
|
|
977
|
+
const newlines = (content.match(/\n/g) || []).length;
|
|
978
|
+
this.contentRow += newlines;
|
|
979
|
+
}
|
|
980
|
+
finally {
|
|
981
|
+
writeLock.unlock();
|
|
982
|
+
}
|
|
983
|
+
// Re-render chat box below new content (only when not streaming)
|
|
984
|
+
if (!this.scrollRegionActive) {
|
|
985
|
+
this.forceRender();
|
|
831
986
|
}
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
987
|
+
}
|
|
988
|
+
/**
|
|
989
|
+
* Enter alternate screen buffer and clear it.
|
|
990
|
+
* This gives us full control over the terminal without affecting user's history.
|
|
991
|
+
*/
|
|
992
|
+
enterAlternateScreen() {
|
|
993
|
+
writeLock.lock('enterAltScreen');
|
|
994
|
+
try {
|
|
995
|
+
this.write(ESC.ENTER_ALT_SCREEN);
|
|
996
|
+
this.write(ESC.HOME);
|
|
997
|
+
this.write(ESC.CLEAR_SCREEN);
|
|
998
|
+
this.contentRow = 1;
|
|
999
|
+
this.alternateScreenActive = true;
|
|
1000
|
+
}
|
|
1001
|
+
finally {
|
|
1002
|
+
writeLock.unlock();
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
/**
|
|
1006
|
+
* Exit alternate screen buffer.
|
|
1007
|
+
* Restores the user's previous terminal content.
|
|
1008
|
+
*/
|
|
1009
|
+
exitAlternateScreen() {
|
|
1010
|
+
writeLock.lock('exitAltScreen');
|
|
1011
|
+
try {
|
|
1012
|
+
this.write(ESC.EXIT_ALT_SCREEN);
|
|
1013
|
+
this.alternateScreenActive = false;
|
|
1014
|
+
}
|
|
1015
|
+
finally {
|
|
1016
|
+
writeLock.unlock();
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
/**
|
|
1020
|
+
* Check if alternate screen buffer is currently active.
|
|
1021
|
+
*/
|
|
1022
|
+
isAlternateScreenActive() {
|
|
1023
|
+
return this.alternateScreenActive;
|
|
1024
|
+
}
|
|
1025
|
+
/**
|
|
1026
|
+
* Get a snapshot of the scrollback buffer (for display on exit).
|
|
1027
|
+
*/
|
|
1028
|
+
getScrollbackSnapshot() {
|
|
1029
|
+
return [...this.scrollbackBuffer];
|
|
1030
|
+
}
|
|
1031
|
+
/**
|
|
1032
|
+
* Clear the entire terminal screen and reset content position.
|
|
1033
|
+
* This removes all content including the launching command.
|
|
1034
|
+
*/
|
|
1035
|
+
clearScreen() {
|
|
1036
|
+
writeLock.lock('clearScreen');
|
|
1037
|
+
try {
|
|
1038
|
+
this.write(ESC.HOME);
|
|
1039
|
+
this.write(ESC.CLEAR_SCREEN);
|
|
1040
|
+
this.contentRow = 1;
|
|
836
1041
|
}
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
// Exit alternate screen buffer (restores main terminal)
|
|
840
|
-
if (this.unifiedUIInitialized) {
|
|
841
|
-
this.write(ESC.ALT_SCREEN_EXIT);
|
|
1042
|
+
finally {
|
|
1043
|
+
writeLock.unlock();
|
|
842
1044
|
}
|
|
1045
|
+
}
|
|
1046
|
+
/**
|
|
1047
|
+
* Reset content position to row 1.
|
|
1048
|
+
* Does NOT clear the terminal - content starts from current position.
|
|
1049
|
+
*/
|
|
1050
|
+
resetContentPosition() {
|
|
1051
|
+
this.contentRow = 1;
|
|
1052
|
+
}
|
|
1053
|
+
/**
|
|
1054
|
+
* Set the content row explicitly (used after banner is written).
|
|
1055
|
+
* This tells the input where content should start flowing from.
|
|
1056
|
+
*/
|
|
1057
|
+
setContentRow(row) {
|
|
1058
|
+
this.contentRow = Math.max(1, row);
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* Get the current content row position.
|
|
1062
|
+
*/
|
|
1063
|
+
getContentRow() {
|
|
1064
|
+
return this.contentRow;
|
|
1065
|
+
}
|
|
1066
|
+
/**
|
|
1067
|
+
* Dispose and clean up
|
|
1068
|
+
*/
|
|
1069
|
+
dispose() {
|
|
1070
|
+
if (this.disposed)
|
|
1071
|
+
return;
|
|
843
1072
|
this.disposed = true;
|
|
844
1073
|
this.enabled = false;
|
|
1074
|
+
this.disableScrollRegion();
|
|
1075
|
+
this.resetStreamingRenderThrottle();
|
|
845
1076
|
this.disableBracketedPaste();
|
|
846
1077
|
this.buffer = '';
|
|
847
1078
|
this.queue = [];
|
|
@@ -936,32 +1167,35 @@ export class TerminalInput extends EventEmitter {
|
|
|
936
1167
|
this.handleDown();
|
|
937
1168
|
return true;
|
|
938
1169
|
case 'home':
|
|
939
|
-
|
|
1170
|
+
// Ctrl+Home or in scrollback mode: scroll to top
|
|
1171
|
+
if (key.ctrl || this.isInScrollbackMode) {
|
|
1172
|
+
this.scrollToTop();
|
|
1173
|
+
}
|
|
1174
|
+
else {
|
|
1175
|
+
this.moveCursorToLineStart();
|
|
1176
|
+
}
|
|
940
1177
|
return true;
|
|
941
1178
|
case 'end':
|
|
942
|
-
|
|
1179
|
+
// Ctrl+End or in scrollback mode: scroll to bottom (live mode)
|
|
1180
|
+
if (key.ctrl || this.isInScrollbackMode) {
|
|
1181
|
+
this.scrollToBottom();
|
|
1182
|
+
}
|
|
1183
|
+
else {
|
|
1184
|
+
this.moveCursorToLineEnd();
|
|
1185
|
+
}
|
|
1186
|
+
return true;
|
|
1187
|
+
case 'pageup':
|
|
1188
|
+
this.scrollUp(20); // Scroll up by 20 lines
|
|
1189
|
+
return true;
|
|
1190
|
+
case 'pagedown':
|
|
1191
|
+
this.scrollDown(20); // Scroll down by 20 lines
|
|
943
1192
|
return true;
|
|
944
1193
|
case 'tab':
|
|
945
1194
|
if (key.shift) {
|
|
946
1195
|
this.toggleEditMode();
|
|
947
1196
|
return true;
|
|
948
1197
|
}
|
|
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
|
-
}
|
|
1198
|
+
this.insertText(' ');
|
|
965
1199
|
return true;
|
|
966
1200
|
}
|
|
967
1201
|
return false;
|
|
@@ -979,7 +1213,6 @@ export class TerminalInput extends EventEmitter {
|
|
|
979
1213
|
this.insertPlainText(chunk, insertPos);
|
|
980
1214
|
this.cursor = insertPos + chunk.length;
|
|
981
1215
|
this.emit('change', this.buffer);
|
|
982
|
-
this.updateSuggestions();
|
|
983
1216
|
this.scheduleRender();
|
|
984
1217
|
}
|
|
985
1218
|
insertNewline() {
|
|
@@ -1004,7 +1237,6 @@ export class TerminalInput extends EventEmitter {
|
|
|
1004
1237
|
this.cursor = Math.max(0, this.cursor - 1);
|
|
1005
1238
|
}
|
|
1006
1239
|
this.emit('change', this.buffer);
|
|
1007
|
-
this.updateSuggestions();
|
|
1008
1240
|
this.scheduleRender();
|
|
1009
1241
|
}
|
|
1010
1242
|
deleteForward() {
|
|
@@ -1232,13 +1464,12 @@ export class TerminalInput extends EventEmitter {
|
|
|
1232
1464
|
timestamp: Date.now(),
|
|
1233
1465
|
});
|
|
1234
1466
|
this.emit('queue', text);
|
|
1235
|
-
this.clear(); // Clear immediately for queued input
|
|
1467
|
+
this.clear(); // Clear immediately for queued input
|
|
1236
1468
|
}
|
|
1237
1469
|
else {
|
|
1238
|
-
// In idle mode, clear the input
|
|
1239
|
-
// The
|
|
1240
|
-
|
|
1241
|
-
this.clear(true); // Skip render - streaming will handle display
|
|
1470
|
+
// In idle mode, clear the input first, then emit submit.
|
|
1471
|
+
// The prompt will be logged as a visible message by the caller.
|
|
1472
|
+
this.clear();
|
|
1242
1473
|
this.emit('submit', text);
|
|
1243
1474
|
}
|
|
1244
1475
|
}
|
|
@@ -1255,7 +1486,9 @@ export class TerminalInput extends EventEmitter {
|
|
|
1255
1486
|
if (available <= 0)
|
|
1256
1487
|
return;
|
|
1257
1488
|
const chunk = clean.slice(0, available);
|
|
1258
|
-
|
|
1489
|
+
const isMultiline = isMultilinePaste(chunk);
|
|
1490
|
+
const isShortMultiline = isMultiline && this.shouldInlineMultiline(chunk);
|
|
1491
|
+
if (isMultiline && !isShortMultiline) {
|
|
1259
1492
|
this.insertPastePlaceholder(chunk);
|
|
1260
1493
|
}
|
|
1261
1494
|
else {
|
|
@@ -1319,6 +1552,180 @@ export class TerminalInput extends EventEmitter {
|
|
|
1319
1552
|
return { lines, cursorLine, cursorCol };
|
|
1320
1553
|
}
|
|
1321
1554
|
// ===========================================================================
|
|
1555
|
+
// SCROLLBACK BUFFER
|
|
1556
|
+
// ===========================================================================
|
|
1557
|
+
/**
|
|
1558
|
+
* Add content to the scrollback buffer for history retention
|
|
1559
|
+
*/
|
|
1560
|
+
addToScrollback(content) {
|
|
1561
|
+
if (!content)
|
|
1562
|
+
return;
|
|
1563
|
+
// Split content into lines and add to buffer
|
|
1564
|
+
const lines = content.split('\n');
|
|
1565
|
+
for (let i = 0; i < lines.length; i++) {
|
|
1566
|
+
const line = lines[i];
|
|
1567
|
+
if (line !== undefined) {
|
|
1568
|
+
// Only add non-empty lines or preserve newlines between content
|
|
1569
|
+
if (i < lines.length - 1 || line.length > 0) {
|
|
1570
|
+
this.scrollbackBuffer.push(line);
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
// Trim buffer if it exceeds max size
|
|
1575
|
+
while (this.scrollbackBuffer.length > this.maxScrollbackLines) {
|
|
1576
|
+
this.scrollbackBuffer.shift();
|
|
1577
|
+
}
|
|
1578
|
+
// If we're in live mode (not scrolled up), keep offset at 0
|
|
1579
|
+
if (this.scrollbackOffset === 0) {
|
|
1580
|
+
this.isInScrollbackMode = false;
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
/**
|
|
1584
|
+
* Scroll up by a number of lines (PageUp)
|
|
1585
|
+
*/
|
|
1586
|
+
scrollUp(lines = 10) {
|
|
1587
|
+
const { rows } = this.getSize();
|
|
1588
|
+
const chatBoxHeight = this.getChatBoxHeight();
|
|
1589
|
+
const visibleLines = Math.max(1, rows - chatBoxHeight);
|
|
1590
|
+
// Calculate max scroll offset
|
|
1591
|
+
const maxOffset = Math.max(0, this.scrollbackBuffer.length - visibleLines);
|
|
1592
|
+
this.scrollbackOffset = Math.min(this.scrollbackOffset + lines, maxOffset);
|
|
1593
|
+
this.isInScrollbackMode = this.scrollbackOffset > 0;
|
|
1594
|
+
if (this.isInScrollbackMode) {
|
|
1595
|
+
this.renderScrollbackView();
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
/**
|
|
1599
|
+
* Scroll down by a number of lines (PageDown)
|
|
1600
|
+
*/
|
|
1601
|
+
scrollDown(lines = 10) {
|
|
1602
|
+
this.scrollbackOffset = Math.max(0, this.scrollbackOffset - lines);
|
|
1603
|
+
this.isInScrollbackMode = this.scrollbackOffset > 0;
|
|
1604
|
+
if (this.isInScrollbackMode) {
|
|
1605
|
+
this.renderScrollbackView();
|
|
1606
|
+
}
|
|
1607
|
+
else {
|
|
1608
|
+
// Returned to live mode - force re-render
|
|
1609
|
+
this.forceRender();
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
/**
|
|
1613
|
+
* Jump to the top of scrollback buffer
|
|
1614
|
+
*/
|
|
1615
|
+
scrollToTop() {
|
|
1616
|
+
const { rows } = this.getSize();
|
|
1617
|
+
const chatBoxHeight = this.getChatBoxHeight();
|
|
1618
|
+
const visibleLines = Math.max(1, rows - chatBoxHeight);
|
|
1619
|
+
const maxOffset = Math.max(0, this.scrollbackBuffer.length - visibleLines);
|
|
1620
|
+
this.scrollbackOffset = maxOffset;
|
|
1621
|
+
this.isInScrollbackMode = true;
|
|
1622
|
+
this.renderScrollbackView();
|
|
1623
|
+
}
|
|
1624
|
+
/**
|
|
1625
|
+
* Jump to the bottom (live mode)
|
|
1626
|
+
*/
|
|
1627
|
+
scrollToBottom() {
|
|
1628
|
+
this.scrollbackOffset = 0;
|
|
1629
|
+
this.isInScrollbackMode = false;
|
|
1630
|
+
this.forceRender();
|
|
1631
|
+
}
|
|
1632
|
+
/**
|
|
1633
|
+
* Render the scrollback buffer view with enhanced visuals
|
|
1634
|
+
*/
|
|
1635
|
+
renderScrollbackView() {
|
|
1636
|
+
const { rows, cols } = this.getSize();
|
|
1637
|
+
const chatBoxHeight = this.getChatBoxHeight();
|
|
1638
|
+
const contentHeight = Math.max(1, rows - chatBoxHeight);
|
|
1639
|
+
writeLock.lock('renderScrollback');
|
|
1640
|
+
try {
|
|
1641
|
+
this.write(ESC.SAVE);
|
|
1642
|
+
this.write(ESC.HIDE);
|
|
1643
|
+
// Clear content area
|
|
1644
|
+
for (let i = 1; i <= contentHeight; i++) {
|
|
1645
|
+
this.write(ESC.TO(i, 1));
|
|
1646
|
+
this.write(ESC.CLEAR_LINE);
|
|
1647
|
+
}
|
|
1648
|
+
// Calculate which lines to show
|
|
1649
|
+
const startIdx = Math.max(0, this.scrollbackBuffer.length - this.scrollbackOffset - contentHeight);
|
|
1650
|
+
const endIdx = Math.max(0, this.scrollbackBuffer.length - this.scrollbackOffset);
|
|
1651
|
+
const visibleLines = this.scrollbackBuffer.slice(startIdx, endIdx);
|
|
1652
|
+
// Render visible lines with subtle left border
|
|
1653
|
+
for (let i = 0; i < Math.min(visibleLines.length, contentHeight); i++) {
|
|
1654
|
+
const line = visibleLines[i] ?? '';
|
|
1655
|
+
this.write(ESC.TO(i + 1, 1));
|
|
1656
|
+
// Add subtle left border for scrollback mode
|
|
1657
|
+
this.write(theme.ui.muted('▌ '));
|
|
1658
|
+
// Truncate if needed
|
|
1659
|
+
const maxLen = cols - 6;
|
|
1660
|
+
const displayLine = line.length > maxLen ? line.slice(0, maxLen - 3) + '...' : line;
|
|
1661
|
+
this.write(displayLine);
|
|
1662
|
+
}
|
|
1663
|
+
// Add enhanced scroll indicator with animation
|
|
1664
|
+
if (this.scrollbackOffset > 0) {
|
|
1665
|
+
const totalLines = this.scrollbackBuffer.length;
|
|
1666
|
+
const currentPos = totalLines - this.scrollbackOffset;
|
|
1667
|
+
const percentage = Math.round((currentPos / totalLines) * 100);
|
|
1668
|
+
// Animated scroll arrows
|
|
1669
|
+
const scrollFrames = ['⬆', '⇡', '↟', '⇡'];
|
|
1670
|
+
this.scrollIndicatorFrame = (this.scrollIndicatorFrame + 1) % scrollFrames.length;
|
|
1671
|
+
const arrow = scrollFrames[this.scrollIndicatorFrame];
|
|
1672
|
+
// Build indicator with progress bar
|
|
1673
|
+
const progressBar = this.buildProgressBar(percentage, 10);
|
|
1674
|
+
const indicator = theme.accent(`${arrow} `) +
|
|
1675
|
+
theme.info(`Scrollback `) +
|
|
1676
|
+
theme.ui.muted(`[${this.scrollbackOffset}↑] `) +
|
|
1677
|
+
progressBar +
|
|
1678
|
+
theme.ui.muted(` ${percentage}%`);
|
|
1679
|
+
// Position at top right
|
|
1680
|
+
const indicatorRow = 1;
|
|
1681
|
+
const indicatorCol = Math.max(1, cols - 50);
|
|
1682
|
+
this.write(ESC.TO(indicatorRow, indicatorCol));
|
|
1683
|
+
this.write(indicator);
|
|
1684
|
+
}
|
|
1685
|
+
this.write(ESC.RESTORE);
|
|
1686
|
+
this.write(ESC.SHOW);
|
|
1687
|
+
}
|
|
1688
|
+
finally {
|
|
1689
|
+
writeLock.unlock();
|
|
1690
|
+
}
|
|
1691
|
+
// Re-render chat box
|
|
1692
|
+
this.forceRender();
|
|
1693
|
+
}
|
|
1694
|
+
/**
|
|
1695
|
+
* Build a visual progress bar
|
|
1696
|
+
*/
|
|
1697
|
+
buildProgressBar(percentage, width = 10) {
|
|
1698
|
+
const filled = Math.round((percentage / 100) * width);
|
|
1699
|
+
const empty = width - filled;
|
|
1700
|
+
const bar = theme.accent('█'.repeat(filled)) +
|
|
1701
|
+
theme.ui.muted('░'.repeat(empty));
|
|
1702
|
+
return `${theme.ui.muted('[')}${bar}${theme.ui.muted(']')}`;
|
|
1703
|
+
}
|
|
1704
|
+
/**
|
|
1705
|
+
* Get scrollback buffer content (for persistence)
|
|
1706
|
+
*/
|
|
1707
|
+
getScrollbackBuffer() {
|
|
1708
|
+
return [...this.scrollbackBuffer];
|
|
1709
|
+
}
|
|
1710
|
+
/**
|
|
1711
|
+
* Load scrollback buffer (for restoration)
|
|
1712
|
+
*/
|
|
1713
|
+
loadScrollbackBuffer(lines) {
|
|
1714
|
+
this.scrollbackBuffer = [...lines];
|
|
1715
|
+
// Trim if necessary
|
|
1716
|
+
while (this.scrollbackBuffer.length > this.maxScrollbackLines) {
|
|
1717
|
+
this.scrollbackBuffer.shift();
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
/**
|
|
1721
|
+
* Clear scrollback buffer
|
|
1722
|
+
*/
|
|
1723
|
+
clearScrollbackBuffer() {
|
|
1724
|
+
this.scrollbackBuffer = [];
|
|
1725
|
+
this.scrollbackOffset = 0;
|
|
1726
|
+
this.isInScrollbackMode = false;
|
|
1727
|
+
}
|
|
1728
|
+
// ===========================================================================
|
|
1322
1729
|
// UTILITIES
|
|
1323
1730
|
// ===========================================================================
|
|
1324
1731
|
getComposedLength() {
|
|
@@ -1391,17 +1798,19 @@ export class TerminalInput extends EventEmitter {
|
|
|
1391
1798
|
this.shiftPlaceholders(position, text.length);
|
|
1392
1799
|
this.buffer = this.buffer.slice(0, position) + text + this.buffer.slice(position);
|
|
1393
1800
|
}
|
|
1801
|
+
shouldInlineMultiline(content) {
|
|
1802
|
+
const lines = content.split('\n').length;
|
|
1803
|
+
const maxInlineLines = 4;
|
|
1804
|
+
const maxInlineChars = 240;
|
|
1805
|
+
return lines <= maxInlineLines && content.length <= maxInlineChars;
|
|
1806
|
+
}
|
|
1394
1807
|
findPlaceholderAt(position) {
|
|
1395
1808
|
return this.pastePlaceholders.find((ph) => position >= ph.start && position < ph.end) ?? null;
|
|
1396
1809
|
}
|
|
1397
|
-
buildPlaceholder(
|
|
1810
|
+
buildPlaceholder(lineCount) {
|
|
1398
1811
|
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}"`;
|
|
1812
|
+
const plural = lineCount === 1 ? '' : 's';
|
|
1813
|
+
const placeholder = `[Pasted text #${id} +${lineCount} line${plural}]`;
|
|
1405
1814
|
return { id, placeholder };
|
|
1406
1815
|
}
|
|
1407
1816
|
insertPastePlaceholder(content) {
|
|
@@ -1409,67 +1818,21 @@ export class TerminalInput extends EventEmitter {
|
|
|
1409
1818
|
if (available <= 0)
|
|
1410
1819
|
return;
|
|
1411
1820
|
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);
|
|
1821
|
+
const lineCount = cleanContent.split('\n').length;
|
|
1822
|
+
const { id, placeholder } = this.buildPlaceholder(lineCount);
|
|
1422
1823
|
const insertPos = this.cursor;
|
|
1423
1824
|
this.shiftPlaceholders(insertPos, placeholder.length);
|
|
1424
1825
|
this.pastePlaceholders.push({
|
|
1425
1826
|
id,
|
|
1426
1827
|
content: cleanContent,
|
|
1427
|
-
lineCount
|
|
1828
|
+
lineCount,
|
|
1428
1829
|
placeholder,
|
|
1429
1830
|
start: insertPos,
|
|
1430
1831
|
end: insertPos + placeholder.length,
|
|
1431
|
-
summary,
|
|
1432
|
-
expanded: false,
|
|
1433
1832
|
});
|
|
1434
1833
|
this.buffer = this.buffer.slice(0, insertPos) + placeholder + this.buffer.slice(insertPos);
|
|
1435
1834
|
this.cursor = insertPos + placeholder.length;
|
|
1436
1835
|
}
|
|
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
1836
|
deletePlaceholder(placeholder) {
|
|
1474
1837
|
const length = placeholder.end - placeholder.start;
|
|
1475
1838
|
this.buffer = this.buffer.slice(0, placeholder.start) + this.buffer.slice(placeholder.end);
|
|
@@ -1477,7 +1840,11 @@ export class TerminalInput extends EventEmitter {
|
|
|
1477
1840
|
this.shiftPlaceholders(placeholder.end, -length, placeholder.id);
|
|
1478
1841
|
this.cursor = placeholder.start;
|
|
1479
1842
|
}
|
|
1480
|
-
updateContextUsage(value) {
|
|
1843
|
+
updateContextUsage(value, autoCompactThreshold) {
|
|
1844
|
+
if (typeof autoCompactThreshold === 'number' && Number.isFinite(autoCompactThreshold)) {
|
|
1845
|
+
const boundedThreshold = Math.max(1, Math.min(100, Math.round(autoCompactThreshold)));
|
|
1846
|
+
this.contextAutoCompactThreshold = boundedThreshold;
|
|
1847
|
+
}
|
|
1481
1848
|
if (value === null || !Number.isFinite(value)) {
|
|
1482
1849
|
this.contextUsage = null;
|
|
1483
1850
|
}
|
|
@@ -1504,6 +1871,28 @@ export class TerminalInput extends EventEmitter {
|
|
|
1504
1871
|
const next = this.editMode === 'display-edits' ? 'ask-permission' : 'display-edits';
|
|
1505
1872
|
this.setEditMode(next);
|
|
1506
1873
|
}
|
|
1874
|
+
scheduleStreamingRender(delayMs) {
|
|
1875
|
+
if (this.streamingRenderTimer)
|
|
1876
|
+
return;
|
|
1877
|
+
const wait = Math.max(16, delayMs);
|
|
1878
|
+
this.streamingRenderTimer = setTimeout(() => {
|
|
1879
|
+
this.streamingRenderTimer = null;
|
|
1880
|
+
// During streaming, only update chat box (not full render)
|
|
1881
|
+
if (this.scrollRegionActive) {
|
|
1882
|
+
this.renderChatBoxAtBottom();
|
|
1883
|
+
}
|
|
1884
|
+
else {
|
|
1885
|
+
this.render();
|
|
1886
|
+
}
|
|
1887
|
+
}, wait);
|
|
1888
|
+
}
|
|
1889
|
+
resetStreamingRenderThrottle() {
|
|
1890
|
+
if (this.streamingRenderTimer) {
|
|
1891
|
+
clearTimeout(this.streamingRenderTimer);
|
|
1892
|
+
this.streamingRenderTimer = null;
|
|
1893
|
+
}
|
|
1894
|
+
this.lastStreamingRender = 0;
|
|
1895
|
+
}
|
|
1507
1896
|
scheduleRender() {
|
|
1508
1897
|
if (!this.canRender())
|
|
1509
1898
|
return;
|