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