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