erosolar-cli 1.7.302 → 1.7.303
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 +148 -24
- package/dist/alpha-zero/agentWrapper.d.ts +84 -0
- package/dist/alpha-zero/agentWrapper.d.ts.map +1 -0
- package/dist/alpha-zero/agentWrapper.js +171 -0
- package/dist/alpha-zero/agentWrapper.js.map +1 -0
- package/dist/alpha-zero/codeEvaluator.d.ts +25 -0
- package/dist/alpha-zero/codeEvaluator.d.ts.map +1 -0
- package/dist/alpha-zero/codeEvaluator.js +273 -0
- package/dist/alpha-zero/codeEvaluator.js.map +1 -0
- package/dist/alpha-zero/competitiveRunner.d.ts +66 -0
- package/dist/alpha-zero/competitiveRunner.d.ts.map +1 -0
- package/dist/alpha-zero/competitiveRunner.js +224 -0
- package/dist/alpha-zero/competitiveRunner.js.map +1 -0
- package/dist/alpha-zero/index.d.ts +67 -0
- package/dist/alpha-zero/index.d.ts.map +1 -0
- package/dist/alpha-zero/index.js +99 -0
- package/dist/alpha-zero/index.js.map +1 -0
- package/dist/alpha-zero/introspection.d.ts +128 -0
- package/dist/alpha-zero/introspection.d.ts.map +1 -0
- package/dist/alpha-zero/introspection.js +300 -0
- package/dist/alpha-zero/introspection.js.map +1 -0
- package/dist/alpha-zero/metricsTracker.d.ts +71 -0
- package/dist/alpha-zero/metricsTracker.d.ts.map +1 -0
- package/dist/{core → alpha-zero}/metricsTracker.js +5 -2
- package/dist/alpha-zero/metricsTracker.js.map +1 -0
- package/dist/alpha-zero/security/core.d.ts +125 -0
- package/dist/alpha-zero/security/core.d.ts.map +1 -0
- package/dist/alpha-zero/security/core.js +271 -0
- package/dist/alpha-zero/security/core.js.map +1 -0
- package/dist/alpha-zero/security/google.d.ts +125 -0
- package/dist/alpha-zero/security/google.d.ts.map +1 -0
- package/dist/alpha-zero/security/google.js +311 -0
- package/dist/alpha-zero/security/google.js.map +1 -0
- package/dist/alpha-zero/security/googleLoader.d.ts +17 -0
- package/dist/alpha-zero/security/googleLoader.d.ts.map +1 -0
- package/dist/alpha-zero/security/googleLoader.js +41 -0
- package/dist/alpha-zero/security/googleLoader.js.map +1 -0
- package/dist/alpha-zero/security/index.d.ts +29 -0
- package/dist/alpha-zero/security/index.d.ts.map +1 -0
- package/dist/alpha-zero/security/index.js +32 -0
- package/dist/alpha-zero/security/index.js.map +1 -0
- package/dist/alpha-zero/security/simulation.d.ts +124 -0
- package/dist/alpha-zero/security/simulation.d.ts.map +1 -0
- package/dist/alpha-zero/security/simulation.js +277 -0
- package/dist/alpha-zero/security/simulation.js.map +1 -0
- package/dist/alpha-zero/selfModification.d.ts +109 -0
- package/dist/alpha-zero/selfModification.d.ts.map +1 -0
- package/dist/alpha-zero/selfModification.js +233 -0
- package/dist/alpha-zero/selfModification.js.map +1 -0
- package/dist/alpha-zero/types.d.ts +170 -0
- package/dist/alpha-zero/types.d.ts.map +1 -0
- package/dist/alpha-zero/types.js +31 -0
- package/dist/alpha-zero/types.js.map +1 -0
- package/dist/bin/erosolar.js +1 -3
- package/dist/bin/erosolar.js.map +1 -1
- package/dist/capabilities/agentSpawningCapability.d.ts.map +1 -1
- package/dist/capabilities/agentSpawningCapability.js +31 -56
- package/dist/capabilities/agentSpawningCapability.js.map +1 -1
- package/dist/capabilities/securityTestingCapability.d.ts +13 -0
- package/dist/capabilities/securityTestingCapability.d.ts.map +1 -0
- package/dist/capabilities/securityTestingCapability.js +25 -0
- package/dist/capabilities/securityTestingCapability.js.map +1 -0
- package/dist/contracts/agent-schemas.json +15 -0
- package/dist/contracts/tools.schema.json +9 -0
- 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/aiFlowOptimizer.d.ts +26 -0
- package/dist/core/aiFlowOptimizer.d.ts.map +1 -0
- package/dist/core/aiFlowOptimizer.js +31 -0
- package/dist/core/aiFlowOptimizer.js.map +1 -0
- package/dist/core/aiOptimizationEngine.d.ts +158 -0
- package/dist/core/aiOptimizationEngine.d.ts.map +1 -0
- package/dist/core/aiOptimizationEngine.js +428 -0
- package/dist/core/aiOptimizationEngine.js.map +1 -0
- package/dist/core/aiOptimizationIntegration.d.ts +93 -0
- package/dist/core/aiOptimizationIntegration.d.ts.map +1 -0
- package/dist/core/aiOptimizationIntegration.js +250 -0
- package/dist/core/aiOptimizationIntegration.js.map +1 -0
- package/dist/core/customCommands.d.ts +0 -1
- package/dist/core/customCommands.d.ts.map +1 -1
- package/dist/core/customCommands.js +0 -3
- package/dist/core/customCommands.js.map +1 -1
- package/dist/core/enhancedErrorRecovery.d.ts +100 -0
- package/dist/core/enhancedErrorRecovery.d.ts.map +1 -0
- package/dist/core/enhancedErrorRecovery.js +345 -0
- package/dist/core/enhancedErrorRecovery.js.map +1 -0
- package/dist/core/hooksSystem.d.ts +65 -0
- package/dist/core/hooksSystem.d.ts.map +1 -0
- package/dist/core/hooksSystem.js +273 -0
- package/dist/core/hooksSystem.js.map +1 -0
- package/dist/core/memorySystem.d.ts +48 -0
- package/dist/core/memorySystem.d.ts.map +1 -0
- package/dist/core/memorySystem.js +271 -0
- package/dist/core/memorySystem.js.map +1 -0
- package/dist/core/toolPreconditions.d.ts.map +1 -1
- package/dist/core/toolPreconditions.js +14 -0
- package/dist/core/toolPreconditions.js.map +1 -1
- package/dist/core/toolRuntime.d.ts +1 -22
- package/dist/core/toolRuntime.d.ts.map +1 -1
- package/dist/core/toolRuntime.js +5 -0
- package/dist/core/toolRuntime.js.map +1 -1
- package/dist/core/toolValidation.d.ts.map +1 -1
- package/dist/core/toolValidation.js +3 -14
- package/dist/core/toolValidation.js.map +1 -1
- package/dist/core/unified/errors.d.ts +189 -0
- package/dist/core/unified/errors.d.ts.map +1 -0
- package/dist/core/unified/errors.js +497 -0
- package/dist/core/unified/errors.js.map +1 -0
- package/dist/core/unified/index.d.ts +19 -0
- package/dist/core/unified/index.d.ts.map +1 -0
- package/dist/core/unified/index.js +68 -0
- package/dist/core/unified/index.js.map +1 -0
- package/dist/core/unified/schema.d.ts +101 -0
- package/dist/core/unified/schema.d.ts.map +1 -0
- package/dist/core/unified/schema.js +350 -0
- package/dist/core/unified/schema.js.map +1 -0
- package/dist/core/unified/toolRuntime.d.ts +179 -0
- package/dist/core/unified/toolRuntime.d.ts.map +1 -0
- package/dist/core/unified/toolRuntime.js +517 -0
- package/dist/core/unified/toolRuntime.js.map +1 -0
- package/dist/core/unified/tools.d.ts +127 -0
- package/dist/core/unified/tools.d.ts.map +1 -0
- package/dist/core/unified/tools.js +1333 -0
- package/dist/core/unified/tools.js.map +1 -0
- package/dist/core/unified/types.d.ts +352 -0
- package/dist/core/unified/types.d.ts.map +1 -0
- package/dist/core/unified/types.js +12 -0
- package/dist/core/unified/types.js.map +1 -0
- package/dist/core/unified/version.d.ts +209 -0
- package/dist/core/unified/version.d.ts.map +1 -0
- package/dist/core/unified/version.js +454 -0
- package/dist/core/unified/version.js.map +1 -0
- package/dist/core/validationRunner.d.ts +3 -1
- package/dist/core/validationRunner.d.ts.map +1 -1
- package/dist/core/validationRunner.js.map +1 -1
- package/dist/headless/headlessApp.d.ts.map +1 -1
- package/dist/headless/headlessApp.js +0 -21
- package/dist/headless/headlessApp.js.map +1 -1
- package/dist/mcp/sseClient.d.ts.map +1 -1
- package/dist/mcp/sseClient.js +18 -9
- package/dist/mcp/sseClient.js.map +1 -1
- package/dist/plugins/tools/build/buildPlugin.d.ts +6 -0
- package/dist/plugins/tools/build/buildPlugin.d.ts.map +1 -1
- package/dist/plugins/tools/build/buildPlugin.js +10 -4
- 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 +2 -0
- package/dist/plugins/tools/nodeDefaults.js.map +1 -1
- package/dist/plugins/tools/security/securityPlugin.d.ts +3 -0
- package/dist/plugins/tools/security/securityPlugin.d.ts.map +1 -0
- package/dist/plugins/tools/security/securityPlugin.js +12 -0
- package/dist/plugins/tools/security/securityPlugin.js.map +1 -0
- 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/security/active-stack-security.d.ts +112 -0
- package/dist/security/active-stack-security.d.ts.map +1 -0
- package/dist/security/active-stack-security.js +296 -0
- package/dist/security/active-stack-security.js.map +1 -0
- package/dist/security/advanced-persistence-research.d.ts +92 -0
- package/dist/security/advanced-persistence-research.d.ts.map +1 -0
- package/dist/security/advanced-persistence-research.js +195 -0
- package/dist/security/advanced-persistence-research.js.map +1 -0
- package/dist/security/advanced-targeting.d.ts +119 -0
- package/dist/security/advanced-targeting.d.ts.map +1 -0
- package/dist/security/advanced-targeting.js +233 -0
- package/dist/security/advanced-targeting.js.map +1 -0
- package/dist/security/assessment/vulnerabilityAssessment.d.ts +104 -0
- package/dist/security/assessment/vulnerabilityAssessment.d.ts.map +1 -0
- package/dist/security/assessment/vulnerabilityAssessment.js +315 -0
- package/dist/security/assessment/vulnerabilityAssessment.js.map +1 -0
- package/dist/security/authorization/securityAuthorization.d.ts +88 -0
- package/dist/security/authorization/securityAuthorization.d.ts.map +1 -0
- package/dist/security/authorization/securityAuthorization.js +172 -0
- package/dist/security/authorization/securityAuthorization.js.map +1 -0
- package/dist/security/comprehensive-targeting.d.ts +85 -0
- package/dist/security/comprehensive-targeting.d.ts.map +1 -0
- package/dist/security/comprehensive-targeting.js +438 -0
- package/dist/security/comprehensive-targeting.js.map +1 -0
- package/dist/security/global-security-integration.d.ts +91 -0
- package/dist/security/global-security-integration.d.ts.map +1 -0
- package/dist/security/global-security-integration.js +218 -0
- package/dist/security/global-security-integration.js.map +1 -0
- package/dist/security/index.d.ts +38 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +47 -0
- package/dist/security/index.js.map +1 -0
- package/dist/security/persistence-analyzer.d.ts +56 -0
- package/dist/security/persistence-analyzer.d.ts.map +1 -0
- package/dist/security/persistence-analyzer.js +187 -0
- package/dist/security/persistence-analyzer.js.map +1 -0
- package/dist/security/persistence-cli.d.ts +36 -0
- package/dist/security/persistence-cli.d.ts.map +1 -0
- package/dist/security/persistence-cli.js +160 -0
- package/dist/security/persistence-cli.js.map +1 -0
- package/dist/security/persistence-research.d.ts +92 -0
- package/dist/security/persistence-research.d.ts.map +1 -0
- package/dist/security/persistence-research.js +364 -0
- package/dist/security/persistence-research.js.map +1 -0
- package/dist/security/research/persistenceResearch.d.ts +97 -0
- package/dist/security/research/persistenceResearch.d.ts.map +1 -0
- package/dist/security/research/persistenceResearch.js +282 -0
- package/dist/security/research/persistenceResearch.js.map +1 -0
- package/dist/security/security-integration.d.ts +74 -0
- package/dist/security/security-integration.d.ts.map +1 -0
- package/dist/security/security-integration.js +137 -0
- package/dist/security/security-integration.js.map +1 -0
- package/dist/security/security-testing-framework.d.ts +112 -0
- package/dist/security/security-testing-framework.d.ts.map +1 -0
- package/dist/security/security-testing-framework.js +364 -0
- package/dist/security/security-testing-framework.js.map +1 -0
- package/dist/security/simulation/attackSimulation.d.ts +93 -0
- package/dist/security/simulation/attackSimulation.d.ts.map +1 -0
- package/dist/security/simulation/attackSimulation.js +341 -0
- package/dist/security/simulation/attackSimulation.js.map +1 -0
- package/dist/security/strategic-operations.d.ts +100 -0
- package/dist/security/strategic-operations.d.ts.map +1 -0
- package/dist/security/strategic-operations.js +276 -0
- package/dist/security/strategic-operations.js.map +1 -0
- package/dist/security/tool-security-wrapper.d.ts +58 -0
- package/dist/security/tool-security-wrapper.d.ts.map +1 -0
- package/dist/security/tool-security-wrapper.js +156 -0
- package/dist/security/tool-security-wrapper.js.map +1 -0
- package/dist/shell/claudeCodeStreamHandler.d.ts +145 -0
- package/dist/shell/claudeCodeStreamHandler.d.ts.map +1 -0
- package/dist/shell/claudeCodeStreamHandler.js +322 -0
- package/dist/shell/claudeCodeStreamHandler.js.map +1 -0
- package/dist/shell/inputQueueManager.d.ts +144 -0
- package/dist/shell/inputQueueManager.d.ts.map +1 -0
- package/dist/shell/inputQueueManager.js +290 -0
- package/dist/shell/inputQueueManager.js.map +1 -0
- package/dist/shell/interactiveShell.d.ts +7 -16
- package/dist/shell/interactiveShell.d.ts.map +1 -1
- package/dist/shell/interactiveShell.js +163 -223
- package/dist/shell/interactiveShell.js.map +1 -1
- package/dist/shell/metricsTracker.d.ts +60 -0
- package/dist/shell/metricsTracker.d.ts.map +1 -0
- package/dist/shell/metricsTracker.js +119 -0
- package/dist/shell/metricsTracker.js.map +1 -0
- package/dist/shell/shellApp.d.ts +0 -2
- package/dist/shell/shellApp.d.ts.map +1 -1
- package/dist/shell/shellApp.js +9 -40
- package/dist/shell/shellApp.js.map +1 -1
- package/dist/shell/streamingOutputManager.d.ts +115 -0
- package/dist/shell/streamingOutputManager.d.ts.map +1 -0
- package/dist/shell/streamingOutputManager.js +225 -0
- package/dist/shell/streamingOutputManager.js.map +1 -0
- package/dist/shell/systemPrompt.d.ts.map +1 -1
- package/dist/shell/systemPrompt.js +4 -1
- package/dist/shell/systemPrompt.js.map +1 -1
- package/dist/shell/terminalInput.d.ts +126 -111
- package/dist/shell/terminalInput.d.ts.map +1 -1
- package/dist/shell/terminalInput.js +639 -496
- package/dist/shell/terminalInput.js.map +1 -1
- package/dist/shell/terminalInputAdapter.d.ts +20 -47
- package/dist/shell/terminalInputAdapter.d.ts.map +1 -1
- package/dist/shell/terminalInputAdapter.js +30 -53
- package/dist/shell/terminalInputAdapter.js.map +1 -1
- package/dist/subagents/taskRunner.d.ts +1 -7
- package/dist/subagents/taskRunner.d.ts.map +1 -1
- package/dist/subagents/taskRunner.js +47 -180
- package/dist/subagents/taskRunner.js.map +1 -1
- package/dist/tools/securityTools.d.ts +22 -0
- package/dist/tools/securityTools.d.ts.map +1 -0
- package/dist/tools/securityTools.js +448 -0
- package/dist/tools/securityTools.js.map +1 -0
- package/dist/ui/ShellUIAdapter.d.ts.map +1 -1
- package/dist/ui/ShellUIAdapter.js +12 -13
- package/dist/ui/ShellUIAdapter.js.map +1 -1
- package/dist/ui/display.d.ts +45 -24
- package/dist/ui/display.d.ts.map +1 -1
- package/dist/ui/display.js +259 -140
- package/dist/ui/display.js.map +1 -1
- package/dist/ui/persistentPrompt.d.ts +50 -0
- package/dist/ui/persistentPrompt.d.ts.map +1 -0
- package/dist/ui/persistentPrompt.js +92 -0
- package/dist/ui/persistentPrompt.js.map +1 -0
- package/dist/ui/terminalUISchema.d.ts +195 -0
- package/dist/ui/terminalUISchema.d.ts.map +1 -0
- package/dist/ui/terminalUISchema.js +113 -0
- package/dist/ui/terminalUISchema.js.map +1 -0
- package/dist/ui/theme.d.ts.map +1 -1
- package/dist/ui/theme.js +8 -6
- package/dist/ui/theme.js.map +1 -1
- package/dist/ui/toolDisplay.d.ts +158 -0
- package/dist/ui/toolDisplay.d.ts.map +1 -1
- package/dist/ui/toolDisplay.js +348 -0
- package/dist/ui/toolDisplay.js.map +1 -1
- package/dist/ui/unified/layout.d.ts +0 -1
- package/dist/ui/unified/layout.d.ts.map +1 -1
- package/dist/ui/unified/layout.js +25 -15
- package/dist/ui/unified/layout.js.map +1 -1
- package/package.json +4 -4
- package/scripts/deploy-security-capabilities.js +178 -0
- package/dist/core/hooks.d.ts +0 -113
- package/dist/core/hooks.d.ts.map +0 -1
- package/dist/core/hooks.js +0 -267
- package/dist/core/hooks.js.map +0 -1
- package/dist/core/metricsTracker.d.ts +0 -122
- package/dist/core/metricsTracker.d.ts.map +0 -1
- package/dist/core/metricsTracker.js.map +0 -1
- package/dist/core/securityAssessment.d.ts +0 -91
- package/dist/core/securityAssessment.d.ts.map +0 -1
- package/dist/core/securityAssessment.js +0 -580
- package/dist/core/securityAssessment.js.map +0 -1
- package/dist/core/verification.d.ts +0 -137
- package/dist/core/verification.d.ts.map +0 -1
- package/dist/core/verification.js +0 -323
- package/dist/core/verification.js.map +0 -1
- package/dist/subagents/agentConfig.d.ts +0 -27
- package/dist/subagents/agentConfig.d.ts.map +0 -1
- package/dist/subagents/agentConfig.js +0 -89
- package/dist/subagents/agentConfig.js.map +0 -1
- package/dist/subagents/agentRegistry.d.ts +0 -33
- package/dist/subagents/agentRegistry.d.ts.map +0 -1
- package/dist/subagents/agentRegistry.js +0 -162
- package/dist/subagents/agentRegistry.js.map +0 -1
- package/dist/utils/frontmatter.d.ts +0 -10
- package/dist/utils/frontmatter.d.ts.map +0 -1
- package/dist/utils/frontmatter.js +0 -78
- package/dist/utils/frontmatter.js.map +0 -1
|
@@ -3,18 +3,15 @@
|
|
|
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)
|
|
7
6
|
* - Native bracketed paste support (no heuristics)
|
|
8
7
|
* - Clean cursor model with render-time wrapping
|
|
9
8
|
* - State machine for different input modes
|
|
10
9
|
* - No readline dependency for display
|
|
11
10
|
*/
|
|
12
11
|
import { EventEmitter } from 'node:events';
|
|
13
|
-
import { isMultilinePaste } from '../core/multilinePasteHandler.js';
|
|
12
|
+
import { isMultilinePaste, generatePasteSummary } from '../core/multilinePasteHandler.js';
|
|
14
13
|
import { writeLock } from '../ui/writeLock.js';
|
|
15
|
-
import {
|
|
16
|
-
import { isStreamingMode } from '../ui/globalWriteLock.js';
|
|
17
|
-
import { formatThinking } from '../ui/toolDisplay.js';
|
|
14
|
+
import { UI_COLORS, DEFAULT_UI_CONFIG, } from '../ui/terminalUISchema.js';
|
|
18
15
|
// ANSI escape codes
|
|
19
16
|
const ESC = {
|
|
20
17
|
// Cursor control
|
|
@@ -24,6 +21,9 @@ const ESC = {
|
|
|
24
21
|
SHOW: '\x1b[?25h',
|
|
25
22
|
TO: (row, col) => `\x1b[${row};${col}H`,
|
|
26
23
|
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,44 +69,48 @@ 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
|
|
77
72
|
lastRenderContent = '';
|
|
78
73
|
lastRenderCursor = -1;
|
|
79
74
|
renderDirty = false;
|
|
80
75
|
isRendering = false;
|
|
76
|
+
flowModeRenderedLines = 0; // Track lines rendered for clearing
|
|
77
|
+
inputAreaStartRow = 0; // Track absolute row position of input area
|
|
78
|
+
contentEndRow = 0; // Row where content ends (for idle mode positioning)
|
|
79
|
+
scrollRegionActive = false; // Track if scroll region is enabled for streaming
|
|
80
|
+
// Command suggestions (Claude Code style auto-complete)
|
|
81
|
+
commandSuggestions = [];
|
|
82
|
+
filteredSuggestions = [];
|
|
83
|
+
selectedSuggestionIndex = 0;
|
|
84
|
+
showSuggestions = false;
|
|
81
85
|
// Lifecycle
|
|
82
86
|
disposed = false;
|
|
83
87
|
enabled = true;
|
|
84
88
|
contextUsage = null;
|
|
85
|
-
contextAutoCompactThreshold = 90;
|
|
86
|
-
// Track current content row in scroll region (starts at top, moves down)
|
|
87
|
-
contentRow = 1;
|
|
88
|
-
thinkingModeLabel = null;
|
|
89
89
|
editMode = 'display-edits';
|
|
90
90
|
verificationEnabled = true;
|
|
91
91
|
autoContinueEnabled = false;
|
|
92
92
|
verificationHotkey = 'alt+v';
|
|
93
93
|
autoContinueHotkey = 'alt+c';
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
94
|
+
// Output interceptor cleanup
|
|
95
|
+
outputInterceptorCleanup;
|
|
96
|
+
// Metrics tracking for status bar
|
|
97
|
+
streamingStartTime = null;
|
|
98
|
+
thinkingEnabled = true;
|
|
99
|
+
modelInfo = null; // Provider · Model info
|
|
100
|
+
// Streaming input area render timer (updates elapsed time display)
|
|
100
101
|
streamingRenderTimer = null;
|
|
102
|
+
// Unified UI initialization flag
|
|
103
|
+
unifiedUIInitialized = false;
|
|
101
104
|
constructor(writeStream = process.stdout, config = {}) {
|
|
102
105
|
super();
|
|
103
106
|
this.out = writeStream;
|
|
107
|
+
// Use schema defaults for configuration consistency
|
|
104
108
|
this.config = {
|
|
105
|
-
maxLines: config.maxLines ??
|
|
106
|
-
maxLength: config.maxLength ??
|
|
109
|
+
maxLines: config.maxLines ?? DEFAULT_UI_CONFIG.inputArea.maxLines,
|
|
110
|
+
maxLength: config.maxLength ?? DEFAULT_UI_CONFIG.inputArea.maxLength,
|
|
107
111
|
maxQueueSize: config.maxQueueSize ?? 100,
|
|
108
|
-
promptChar: config.promptChar ??
|
|
109
|
-
continuationChar: config.continuationChar ??
|
|
112
|
+
promptChar: config.promptChar ?? DEFAULT_UI_CONFIG.inputArea.promptChar,
|
|
113
|
+
continuationChar: config.continuationChar ?? DEFAULT_UI_CONFIG.inputArea.continuationChar,
|
|
110
114
|
};
|
|
111
115
|
}
|
|
112
116
|
// ===========================================================================
|
|
@@ -185,36 +189,429 @@ export class TerminalInput extends EventEmitter {
|
|
|
185
189
|
if (handled)
|
|
186
190
|
return;
|
|
187
191
|
}
|
|
192
|
+
// Handle '?' for help hint (if buffer is empty)
|
|
193
|
+
if (str === '?' && this.buffer.length === 0) {
|
|
194
|
+
this.emit('showHelp');
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
188
197
|
// Insert printable characters
|
|
189
198
|
if (str && !key?.ctrl && !key?.meta) {
|
|
190
199
|
this.insertText(str);
|
|
191
200
|
}
|
|
192
201
|
}
|
|
202
|
+
// Banner content to write on init (set via setBannerContent before initializeUnifiedUI)
|
|
203
|
+
bannerContent = null;
|
|
204
|
+
/**
|
|
205
|
+
* Set banner content to be written when unified UI initializes.
|
|
206
|
+
*/
|
|
207
|
+
setBannerContent(content) {
|
|
208
|
+
this.bannerContent = content;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Initialize the unified UI system.
|
|
212
|
+
*
|
|
213
|
+
* Layout:
|
|
214
|
+
* 1. Clear screen
|
|
215
|
+
* 2. Write banner at top
|
|
216
|
+
* 3. Track content end position
|
|
217
|
+
* 4. Render floating input area below banner
|
|
218
|
+
*/
|
|
219
|
+
initializeUnifiedUI() {
|
|
220
|
+
if (this.unifiedUIInitialized) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
// Hide cursor during setup
|
|
224
|
+
this.write(ESC.HIDE);
|
|
225
|
+
// Clear screen and go home
|
|
226
|
+
this.write(ESC.HOME);
|
|
227
|
+
this.write(ESC.CLEAR_SCREEN);
|
|
228
|
+
// Write banner at top and track where it ends
|
|
229
|
+
let bannerLines = 0;
|
|
230
|
+
if (this.bannerContent) {
|
|
231
|
+
const lines = this.bannerContent.split('\n');
|
|
232
|
+
bannerLines = lines.length + 2; // +2 for the trailing \n\n
|
|
233
|
+
process.stdout.write(this.bannerContent + '\n\n');
|
|
234
|
+
}
|
|
235
|
+
// Set content end row so input renders right after banner
|
|
236
|
+
this.contentEndRow = bannerLines > 0 ? bannerLines : 1;
|
|
237
|
+
// Mark initialized
|
|
238
|
+
this.unifiedUIInitialized = true;
|
|
239
|
+
// Render floating input area below the banner
|
|
240
|
+
this.renderFloatingInputArea();
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Clear the input area at its tracked position.
|
|
244
|
+
* Returns true if something was cleared.
|
|
245
|
+
*/
|
|
246
|
+
clearInputArea() {
|
|
247
|
+
if (this.inputAreaStartRow > 0 && this.flowModeRenderedLines > 0) {
|
|
248
|
+
for (let i = 0; i < this.flowModeRenderedLines; i++) {
|
|
249
|
+
this.write(ESC.TO(this.inputAreaStartRow + i, 1));
|
|
250
|
+
this.write(ESC.CLEAR_LINE);
|
|
251
|
+
}
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Reset input area tracking state.
|
|
258
|
+
*/
|
|
259
|
+
resetInputAreaTracking() {
|
|
260
|
+
this.inputAreaStartRow = 0;
|
|
261
|
+
this.flowModeRenderedLines = 0;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Enable scroll region - content scrolls above, input area protected below.
|
|
265
|
+
* The scroll region ends just above where the chat box will be rendered.
|
|
266
|
+
*/
|
|
267
|
+
enableScrollRegion() {
|
|
268
|
+
const { rows } = this.getSize();
|
|
269
|
+
const linesNeeded = 5 + (this.modelInfo ? 1 : 0);
|
|
270
|
+
// Calculate where chat box will be (floating below content)
|
|
271
|
+
let chatBoxStartRow;
|
|
272
|
+
if (this.contentEndRow > 0) {
|
|
273
|
+
chatBoxStartRow = Math.min(this.contentEndRow + 1, rows - linesNeeded + 1);
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
// Default to terminal bottom if no content yet
|
|
277
|
+
chatBoxStartRow = rows - linesNeeded + 1;
|
|
278
|
+
}
|
|
279
|
+
chatBoxStartRow = Math.max(1, chatBoxStartRow);
|
|
280
|
+
// Scroll region ends just before the chat box
|
|
281
|
+
const scrollBottom = Math.max(1, chatBoxStartRow - 1);
|
|
282
|
+
this.write(ESC.SET_SCROLL(1, scrollBottom));
|
|
283
|
+
this.scrollRegionActive = true;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Disable scroll region - return to normal terminal mode.
|
|
287
|
+
*/
|
|
288
|
+
disableScrollRegion() {
|
|
289
|
+
if (!this.scrollRegionActive)
|
|
290
|
+
return;
|
|
291
|
+
this.write(ESC.RESET_SCROLL);
|
|
292
|
+
this.scrollRegionActive = false;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Render input area floating below content.
|
|
296
|
+
* During streaming, positions based on contentEndRow (persistent bottom floating).
|
|
297
|
+
*/
|
|
298
|
+
renderInputAreaAtBottom() {
|
|
299
|
+
const { rows, cols } = this.getSize();
|
|
300
|
+
const divider = '─'.repeat(cols - 1);
|
|
301
|
+
const { dim: DIM, reset: R } = UI_COLORS;
|
|
302
|
+
// Calculate lines needed
|
|
303
|
+
const linesNeeded = 5 + (this.modelInfo ? 1 : 0);
|
|
304
|
+
// Calculate starting row: float below content, but don't go past terminal bounds
|
|
305
|
+
let startRow;
|
|
306
|
+
if (this.contentEndRow > 0) {
|
|
307
|
+
// Float below content
|
|
308
|
+
startRow = this.contentEndRow + 1;
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
// Default to terminal bottom if no content tracked yet
|
|
312
|
+
startRow = rows - linesNeeded + 1;
|
|
313
|
+
}
|
|
314
|
+
// Ensure we don't exceed terminal bounds
|
|
315
|
+
startRow = Math.min(startRow, rows - linesNeeded + 1);
|
|
316
|
+
startRow = Math.max(1, startRow);
|
|
317
|
+
// Save cursor and hide during render
|
|
318
|
+
this.write(ESC.SAVE);
|
|
319
|
+
this.write(ESC.HIDE);
|
|
320
|
+
let currentRow = startRow;
|
|
321
|
+
// Clear input area lines
|
|
322
|
+
for (let r = startRow; r <= rows; r++) {
|
|
323
|
+
this.write(ESC.TO(r, 1));
|
|
324
|
+
this.write(ESC.CLEAR_LINE);
|
|
325
|
+
}
|
|
326
|
+
// Status bar (shows streaming status)
|
|
327
|
+
this.write(ESC.TO(currentRow, 1));
|
|
328
|
+
this.write(this.buildStatusBar(cols));
|
|
329
|
+
currentRow++;
|
|
330
|
+
// Model info line (if set)
|
|
331
|
+
if (this.modelInfo) {
|
|
332
|
+
this.write(ESC.TO(currentRow, 1));
|
|
333
|
+
let modelLine = `${DIM}${this.modelInfo}${R}`;
|
|
334
|
+
if (this.contextUsage !== null) {
|
|
335
|
+
const rem = Math.max(0, 100 - this.contextUsage);
|
|
336
|
+
if (rem < 10)
|
|
337
|
+
modelLine += ` ${UI_COLORS.red}⚠ ctx: ${rem}%${R}`;
|
|
338
|
+
else if (rem < 25)
|
|
339
|
+
modelLine += ` ${UI_COLORS.yellow}! ctx: ${rem}%${R}`;
|
|
340
|
+
else
|
|
341
|
+
modelLine += ` ${DIM}· ctx: ${rem}%${R}`;
|
|
342
|
+
}
|
|
343
|
+
this.write(modelLine);
|
|
344
|
+
currentRow++;
|
|
345
|
+
}
|
|
346
|
+
// Top divider
|
|
347
|
+
this.write(ESC.TO(currentRow, 1));
|
|
348
|
+
this.write(divider);
|
|
349
|
+
currentRow++;
|
|
350
|
+
// Input line with prompt and buffer content
|
|
351
|
+
const { lines } = this.wrapBuffer(cols - 4);
|
|
352
|
+
const displayLine = lines[0] ?? '';
|
|
353
|
+
this.write(ESC.TO(currentRow, 1));
|
|
354
|
+
this.write(ESC.BG_DARK + ESC.DIM + this.config.promptChar + ESC.RESET);
|
|
355
|
+
this.write(ESC.BG_DARK + displayLine);
|
|
356
|
+
const padding = Math.max(0, cols - this.config.promptChar.length - displayLine.length - 1);
|
|
357
|
+
if (padding > 0)
|
|
358
|
+
this.write(' '.repeat(padding));
|
|
359
|
+
this.write(ESC.RESET);
|
|
360
|
+
currentRow++;
|
|
361
|
+
// Bottom divider
|
|
362
|
+
this.write(ESC.TO(currentRow, 1));
|
|
363
|
+
this.write(divider);
|
|
364
|
+
currentRow++;
|
|
365
|
+
// Mode controls
|
|
366
|
+
this.write(ESC.TO(currentRow, 1));
|
|
367
|
+
this.write(this.buildModeControls(cols));
|
|
368
|
+
// Track position
|
|
369
|
+
this.inputAreaStartRow = startRow;
|
|
370
|
+
this.flowModeRenderedLines = currentRow - startRow + 1;
|
|
371
|
+
// Restore cursor position (back to scroll region if streaming)
|
|
372
|
+
this.write(ESC.RESTORE);
|
|
373
|
+
this.write(ESC.SHOW);
|
|
374
|
+
// Update tracking
|
|
375
|
+
this.lastRenderContent = this.buffer;
|
|
376
|
+
this.lastRenderCursor = this.cursor;
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Render floating input area below current content.
|
|
380
|
+
* This is "bottom floating" - follows content, not pinned to terminal bottom.
|
|
381
|
+
* Uses absolute positioning to prevent duplicates.
|
|
382
|
+
*/
|
|
383
|
+
renderFloatingInputArea() {
|
|
384
|
+
const { rows, cols } = this.getSize();
|
|
385
|
+
const divider = '─'.repeat(cols - 1);
|
|
386
|
+
const { dim: DIM, reset: R } = UI_COLORS;
|
|
387
|
+
// Calculate lines needed for input area
|
|
388
|
+
const linesNeeded = 5 + (this.modelInfo ? 1 : 0);
|
|
389
|
+
// FIRST: Clear any previously rendered input area
|
|
390
|
+
this.clearInputArea();
|
|
391
|
+
// Hide cursor during render
|
|
392
|
+
this.write(ESC.HIDE);
|
|
393
|
+
// Calculate where to render: after current content
|
|
394
|
+
// Use contentEndRow if set, otherwise estimate from terminal bottom
|
|
395
|
+
let startRow;
|
|
396
|
+
if (this.contentEndRow > 0) {
|
|
397
|
+
startRow = this.contentEndRow + 1;
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
// Render near bottom, leaving space for input area
|
|
401
|
+
startRow = Math.max(1, rows - linesNeeded);
|
|
402
|
+
}
|
|
403
|
+
// Ensure we don't go past terminal bounds
|
|
404
|
+
startRow = Math.min(startRow, rows - linesNeeded + 1);
|
|
405
|
+
startRow = Math.max(1, startRow);
|
|
406
|
+
// Track this position
|
|
407
|
+
this.inputAreaStartRow = startRow;
|
|
408
|
+
let currentRow = startRow;
|
|
409
|
+
// Status bar
|
|
410
|
+
this.write(ESC.TO(currentRow, 1));
|
|
411
|
+
this.write(this.buildStatusBar(cols));
|
|
412
|
+
currentRow++;
|
|
413
|
+
// Model info line (if set)
|
|
414
|
+
if (this.modelInfo) {
|
|
415
|
+
this.write(ESC.TO(currentRow, 1));
|
|
416
|
+
let modelLine = `${DIM}${this.modelInfo}${R}`;
|
|
417
|
+
if (this.contextUsage !== null) {
|
|
418
|
+
const rem = Math.max(0, 100 - this.contextUsage);
|
|
419
|
+
if (rem < 10)
|
|
420
|
+
modelLine += ` ${UI_COLORS.red}⚠ ctx: ${rem}%${R}`;
|
|
421
|
+
else if (rem < 25)
|
|
422
|
+
modelLine += ` ${UI_COLORS.yellow}! ctx: ${rem}%${R}`;
|
|
423
|
+
else
|
|
424
|
+
modelLine += ` ${DIM}· ctx: ${rem}%${R}`;
|
|
425
|
+
}
|
|
426
|
+
this.write(modelLine);
|
|
427
|
+
currentRow++;
|
|
428
|
+
}
|
|
429
|
+
// Top divider
|
|
430
|
+
this.write(ESC.TO(currentRow, 1));
|
|
431
|
+
this.write(divider);
|
|
432
|
+
currentRow++;
|
|
433
|
+
// Input line with prompt and buffer content
|
|
434
|
+
const { lines, cursorCol } = this.wrapBuffer(cols - 4);
|
|
435
|
+
const displayLine = lines[0] ?? '';
|
|
436
|
+
const inputRow = currentRow;
|
|
437
|
+
this.write(ESC.TO(currentRow, 1));
|
|
438
|
+
this.write(ESC.BG_DARK + ESC.DIM + this.config.promptChar + ESC.RESET);
|
|
439
|
+
this.write(ESC.BG_DARK + displayLine);
|
|
440
|
+
const padding = Math.max(0, cols - this.config.promptChar.length - displayLine.length - 1);
|
|
441
|
+
if (padding > 0)
|
|
442
|
+
this.write(' '.repeat(padding));
|
|
443
|
+
this.write(ESC.RESET);
|
|
444
|
+
currentRow++;
|
|
445
|
+
// Bottom divider
|
|
446
|
+
this.write(ESC.TO(currentRow, 1));
|
|
447
|
+
this.write(divider);
|
|
448
|
+
currentRow++;
|
|
449
|
+
// Mode controls
|
|
450
|
+
this.write(ESC.TO(currentRow, 1));
|
|
451
|
+
this.write(this.buildModeControls(cols));
|
|
452
|
+
// Track lines rendered
|
|
453
|
+
this.flowModeRenderedLines = currentRow - startRow + 1;
|
|
454
|
+
// Position cursor in input line for typing
|
|
455
|
+
this.write(ESC.TO(inputRow, this.config.promptChar.length + 1 + cursorCol));
|
|
456
|
+
// Show cursor
|
|
457
|
+
this.write(ESC.SHOW);
|
|
458
|
+
// Update tracking
|
|
459
|
+
this.lastRenderContent = this.buffer;
|
|
460
|
+
this.lastRenderCursor = this.cursor;
|
|
461
|
+
}
|
|
193
462
|
/**
|
|
194
463
|
* Set the input mode
|
|
195
464
|
*
|
|
196
|
-
*
|
|
465
|
+
* During streaming: dynamic scroll region + chat box floats below content
|
|
466
|
+
* After streaming: chat box floats below content (no scroll region)
|
|
197
467
|
*/
|
|
198
468
|
setMode(mode) {
|
|
199
469
|
const prevMode = this.mode;
|
|
200
470
|
this.mode = mode;
|
|
201
471
|
if (mode === 'streaming' && prevMode !== 'streaming') {
|
|
202
|
-
|
|
472
|
+
// Track streaming start time for elapsed display
|
|
473
|
+
this.streamingStartTime = Date.now();
|
|
474
|
+
// Ensure unified UI is initialized
|
|
475
|
+
if (!this.unifiedUIInitialized) {
|
|
476
|
+
this.initializeUnifiedUI();
|
|
477
|
+
}
|
|
478
|
+
// Clear any floating input area first
|
|
479
|
+
this.clearInputArea();
|
|
480
|
+
this.resetInputAreaTracking();
|
|
481
|
+
// Enable scroll region - ends just before where chat box will be
|
|
482
|
+
this.enableScrollRegion();
|
|
483
|
+
// Render chat box floating below content
|
|
484
|
+
this.renderInputAreaAtBottom();
|
|
485
|
+
// Position cursor at content end (or start of scroll region) for streaming
|
|
486
|
+
const cursorRow = this.contentEndRow > 0 ? this.contentEndRow : 1;
|
|
487
|
+
this.write(ESC.TO(cursorRow, 1));
|
|
203
488
|
this.renderDirty = true;
|
|
204
|
-
this.render();
|
|
205
489
|
}
|
|
206
490
|
else if (mode !== 'streaming' && prevMode === 'streaming') {
|
|
207
|
-
//
|
|
208
|
-
this.
|
|
209
|
-
|
|
491
|
+
// Stop streaming render timer (if any)
|
|
492
|
+
if (this.streamingRenderTimer) {
|
|
493
|
+
clearInterval(this.streamingRenderTimer);
|
|
494
|
+
this.streamingRenderTimer = null;
|
|
495
|
+
}
|
|
496
|
+
// Reset streaming time
|
|
497
|
+
this.streamingStartTime = null;
|
|
498
|
+
// Disable scroll region
|
|
499
|
+
this.disableScrollRegion();
|
|
500
|
+
// Clear bottom input area
|
|
501
|
+
this.clearInputArea();
|
|
502
|
+
this.resetInputAreaTracking();
|
|
503
|
+
// Render floating input area below content
|
|
504
|
+
writeLock.withLock(() => {
|
|
505
|
+
this.renderFloatingInputArea();
|
|
506
|
+
}, 'terminalInput.streamingEnd');
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Set the row where content ends (for idle mode positioning).
|
|
511
|
+
* Input area will render starting from this row + 1.
|
|
512
|
+
*/
|
|
513
|
+
setContentEndRow(row) {
|
|
514
|
+
const prevRow = this.contentEndRow;
|
|
515
|
+
this.contentEndRow = Math.max(0, row);
|
|
516
|
+
// During streaming, dynamically adjust scroll region and chat box position
|
|
517
|
+
if (this.mode === 'streaming' && this.scrollRegionActive && this.contentEndRow !== prevRow) {
|
|
518
|
+
// Re-enable scroll region with new boundaries
|
|
519
|
+
this.enableScrollRegion();
|
|
520
|
+
// Re-render chat box at new position (floating below content)
|
|
521
|
+
this.renderInputAreaAtBottom();
|
|
522
|
+
}
|
|
523
|
+
else {
|
|
524
|
+
this.renderDirty = true;
|
|
525
|
+
this.scheduleRender();
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Set available slash commands for auto-complete suggestions.
|
|
530
|
+
*/
|
|
531
|
+
setCommands(commands) {
|
|
532
|
+
this.commandSuggestions = commands;
|
|
533
|
+
this.updateSuggestions();
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Update filtered suggestions based on current input.
|
|
537
|
+
*/
|
|
538
|
+
updateSuggestions() {
|
|
539
|
+
const input = this.buffer.trim();
|
|
540
|
+
// Only show suggestions when input starts with "/"
|
|
541
|
+
if (!input.startsWith('/')) {
|
|
542
|
+
this.showSuggestions = false;
|
|
543
|
+
this.filteredSuggestions = [];
|
|
544
|
+
this.selectedSuggestionIndex = 0;
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
const query = input.toLowerCase();
|
|
548
|
+
this.filteredSuggestions = this.commandSuggestions.filter(cmd => cmd.command.toLowerCase().startsWith(query) ||
|
|
549
|
+
cmd.command.toLowerCase().includes(query.slice(1)));
|
|
550
|
+
// Show suggestions if we have matches
|
|
551
|
+
this.showSuggestions = this.filteredSuggestions.length > 0;
|
|
552
|
+
// Keep selection in bounds
|
|
553
|
+
if (this.selectedSuggestionIndex >= this.filteredSuggestions.length) {
|
|
554
|
+
this.selectedSuggestionIndex = Math.max(0, this.filteredSuggestions.length - 1);
|
|
210
555
|
}
|
|
211
556
|
}
|
|
212
557
|
/**
|
|
213
|
-
*
|
|
214
|
-
|
|
558
|
+
* Select next suggestion (arrow down / tab).
|
|
559
|
+
*/
|
|
560
|
+
selectNextSuggestion() {
|
|
561
|
+
if (!this.showSuggestions || this.filteredSuggestions.length === 0)
|
|
562
|
+
return;
|
|
563
|
+
this.selectedSuggestionIndex = (this.selectedSuggestionIndex + 1) % this.filteredSuggestions.length;
|
|
564
|
+
this.renderDirty = true;
|
|
565
|
+
this.scheduleRender();
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Select previous suggestion (arrow up / shift+tab).
|
|
569
|
+
*/
|
|
570
|
+
selectPrevSuggestion() {
|
|
571
|
+
if (!this.showSuggestions || this.filteredSuggestions.length === 0)
|
|
572
|
+
return;
|
|
573
|
+
this.selectedSuggestionIndex = this.selectedSuggestionIndex === 0
|
|
574
|
+
? this.filteredSuggestions.length - 1
|
|
575
|
+
: this.selectedSuggestionIndex - 1;
|
|
576
|
+
this.renderDirty = true;
|
|
577
|
+
this.scheduleRender();
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Accept current suggestion and insert into buffer.
|
|
581
|
+
*/
|
|
582
|
+
acceptSuggestion() {
|
|
583
|
+
if (!this.showSuggestions || this.filteredSuggestions.length === 0)
|
|
584
|
+
return false;
|
|
585
|
+
const selected = this.filteredSuggestions[this.selectedSuggestionIndex];
|
|
586
|
+
if (!selected)
|
|
587
|
+
return false;
|
|
588
|
+
// Replace buffer with selected command
|
|
589
|
+
this.buffer = selected.command + ' ';
|
|
590
|
+
this.cursor = this.buffer.length;
|
|
591
|
+
this.showSuggestions = false;
|
|
592
|
+
this.renderDirty = true;
|
|
593
|
+
this.scheduleRender();
|
|
594
|
+
return true;
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Check if suggestions are visible.
|
|
598
|
+
*/
|
|
599
|
+
areSuggestionsVisible() {
|
|
600
|
+
return this.showSuggestions && this.filteredSuggestions.length > 0;
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* Toggle thinking/reasoning mode
|
|
604
|
+
*/
|
|
605
|
+
toggleThinking() {
|
|
606
|
+
this.thinkingEnabled = !this.thinkingEnabled;
|
|
607
|
+
this.emit('thinkingToggle', this.thinkingEnabled);
|
|
608
|
+
this.scheduleRender();
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Get thinking enabled state
|
|
215
612
|
*/
|
|
216
|
-
|
|
217
|
-
|
|
613
|
+
isThinkingEnabled() {
|
|
614
|
+
return this.thinkingEnabled;
|
|
218
615
|
}
|
|
219
616
|
/**
|
|
220
617
|
* Get current mode
|
|
@@ -247,14 +644,17 @@ export class TerminalInput extends EventEmitter {
|
|
|
247
644
|
}
|
|
248
645
|
/**
|
|
249
646
|
* Clear the buffer
|
|
647
|
+
* @param skipRender - If true, don't trigger a re-render (used during submit flow)
|
|
250
648
|
*/
|
|
251
|
-
clear() {
|
|
649
|
+
clear(skipRender = false) {
|
|
252
650
|
this.buffer = '';
|
|
253
651
|
this.cursor = 0;
|
|
254
652
|
this.historyIndex = -1;
|
|
255
653
|
this.tempInput = '';
|
|
256
654
|
this.pastePlaceholders = [];
|
|
257
|
-
|
|
655
|
+
if (!skipRender) {
|
|
656
|
+
this.scheduleRender();
|
|
657
|
+
}
|
|
258
658
|
}
|
|
259
659
|
/**
|
|
260
660
|
* Get queued inputs
|
|
@@ -325,37 +725,6 @@ export class TerminalInput extends EventEmitter {
|
|
|
325
725
|
this.streamingLabel = next;
|
|
326
726
|
this.scheduleRender();
|
|
327
727
|
}
|
|
328
|
-
/**
|
|
329
|
-
* Surface meta status just above the divider (e.g., elapsed time or token usage).
|
|
330
|
-
*/
|
|
331
|
-
setMetaStatus(meta) {
|
|
332
|
-
const nextElapsed = typeof meta.elapsedSeconds === 'number' && Number.isFinite(meta.elapsedSeconds) && meta.elapsedSeconds >= 0
|
|
333
|
-
? Math.floor(meta.elapsedSeconds)
|
|
334
|
-
: null;
|
|
335
|
-
const nextTokens = typeof meta.tokensUsed === 'number' && Number.isFinite(meta.tokensUsed) && meta.tokensUsed >= 0
|
|
336
|
-
? Math.floor(meta.tokensUsed)
|
|
337
|
-
: null;
|
|
338
|
-
const nextLimit = typeof meta.tokenLimit === 'number' && Number.isFinite(meta.tokenLimit) && meta.tokenLimit > 0
|
|
339
|
-
? Math.floor(meta.tokenLimit)
|
|
340
|
-
: null;
|
|
341
|
-
const nextThinking = typeof meta.thinkingMs === 'number' && Number.isFinite(meta.thinkingMs) && meta.thinkingMs >= 0
|
|
342
|
-
? Math.floor(meta.thinkingMs)
|
|
343
|
-
: null;
|
|
344
|
-
const nextThinkingHasContent = !!meta.thinkingHasContent;
|
|
345
|
-
if (this.metaElapsedSeconds === nextElapsed &&
|
|
346
|
-
this.metaTokensUsed === nextTokens &&
|
|
347
|
-
this.metaTokenLimit === nextLimit &&
|
|
348
|
-
this.metaThinkingMs === nextThinking &&
|
|
349
|
-
this.metaThinkingHasContent === nextThinkingHasContent) {
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
this.metaElapsedSeconds = nextElapsed;
|
|
353
|
-
this.metaTokensUsed = nextTokens;
|
|
354
|
-
this.metaTokenLimit = nextLimit;
|
|
355
|
-
this.metaThinkingMs = nextThinking;
|
|
356
|
-
this.metaThinkingHasContent = nextThinkingHasContent;
|
|
357
|
-
this.scheduleRender();
|
|
358
|
-
}
|
|
359
728
|
/**
|
|
360
729
|
* Keep mode toggles (verification/auto-continue) visible in the control bar.
|
|
361
730
|
* Hotkey labels remain stable so the bar looks the same before/during streaming.
|
|
@@ -365,22 +734,26 @@ export class TerminalInput extends EventEmitter {
|
|
|
365
734
|
const nextAutoContinue = !!options.autoContinueEnabled;
|
|
366
735
|
const nextVerifyHotkey = options.verificationHotkey ?? this.verificationHotkey;
|
|
367
736
|
const nextAutoHotkey = options.autoContinueHotkey ?? this.autoContinueHotkey;
|
|
368
|
-
const nextThinkingHotkey = options.thinkingHotkey ?? this.thinkingHotkey;
|
|
369
|
-
const nextThinkingLabel = options.thinkingModeLabel === undefined ? this.thinkingModeLabel : (options.thinkingModeLabel || null);
|
|
370
737
|
if (this.verificationEnabled === nextVerification &&
|
|
371
738
|
this.autoContinueEnabled === nextAutoContinue &&
|
|
372
739
|
this.verificationHotkey === nextVerifyHotkey &&
|
|
373
|
-
this.autoContinueHotkey === nextAutoHotkey
|
|
374
|
-
this.thinkingHotkey === nextThinkingHotkey &&
|
|
375
|
-
this.thinkingModeLabel === nextThinkingLabel) {
|
|
740
|
+
this.autoContinueHotkey === nextAutoHotkey) {
|
|
376
741
|
return;
|
|
377
742
|
}
|
|
378
743
|
this.verificationEnabled = nextVerification;
|
|
379
744
|
this.autoContinueEnabled = nextAutoContinue;
|
|
380
745
|
this.verificationHotkey = nextVerifyHotkey;
|
|
381
746
|
this.autoContinueHotkey = nextAutoHotkey;
|
|
382
|
-
this.
|
|
383
|
-
|
|
747
|
+
this.scheduleRender();
|
|
748
|
+
}
|
|
749
|
+
/**
|
|
750
|
+
* Set the model info string (e.g., "OpenAI · gpt-4")
|
|
751
|
+
* This is displayed persistently above the input area.
|
|
752
|
+
*/
|
|
753
|
+
setModelInfo(info) {
|
|
754
|
+
if (this.modelInfo === info)
|
|
755
|
+
return;
|
|
756
|
+
this.modelInfo = info;
|
|
384
757
|
this.scheduleRender();
|
|
385
758
|
}
|
|
386
759
|
/**
|
|
@@ -393,154 +766,38 @@ export class TerminalInput extends EventEmitter {
|
|
|
393
766
|
this.scheduleRender();
|
|
394
767
|
}
|
|
395
768
|
/**
|
|
396
|
-
*
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
const nextModel = options.model?.trim() || null;
|
|
400
|
-
const nextProvider = options.provider?.trim() || null;
|
|
401
|
-
if (this.modelLabel === nextModel && this.providerLabel === nextProvider) {
|
|
402
|
-
return;
|
|
403
|
-
}
|
|
404
|
-
this.modelLabel = nextModel;
|
|
405
|
-
this.providerLabel = nextProvider;
|
|
406
|
-
this.scheduleRender();
|
|
407
|
-
}
|
|
408
|
-
/**
|
|
409
|
-
* Render the floating input area at contentRow.
|
|
410
|
-
*
|
|
411
|
-
* The chat box "floats" - it renders right below the last streamed content.
|
|
412
|
-
* As content is added, contentRow advances, and the chat box moves down.
|
|
413
|
-
* No scroll regions - pure floating behavior.
|
|
769
|
+
* Render the input area.
|
|
770
|
+
* During streaming: renders at terminal bottom (with scroll region)
|
|
771
|
+
* After streaming: renders floating below content
|
|
414
772
|
*/
|
|
415
773
|
render() {
|
|
416
774
|
if (!this.canRender())
|
|
417
775
|
return;
|
|
418
776
|
if (this.isRendering)
|
|
419
777
|
return;
|
|
420
|
-
const streamingActive = this.mode === 'streaming' || isStreamingMode();
|
|
421
|
-
// During streaming, throttle re-renders
|
|
422
|
-
if (streamingActive && this.lastStreamingRender > 0) {
|
|
423
|
-
const elapsed = Date.now() - this.lastStreamingRender;
|
|
424
|
-
const waitMs = Math.max(0, this.streamingRenderInterval - elapsed);
|
|
425
|
-
if (waitMs > 0) {
|
|
426
|
-
this.renderDirty = true;
|
|
427
|
-
this.scheduleStreamingRender(waitMs);
|
|
428
|
-
return;
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
778
|
const shouldSkip = !this.renderDirty &&
|
|
432
779
|
this.buffer === this.lastRenderContent &&
|
|
433
780
|
this.cursor === this.lastRenderCursor;
|
|
434
781
|
this.renderDirty = false;
|
|
782
|
+
// Skip if nothing changed (unless explicitly forced)
|
|
435
783
|
if (shouldSkip) {
|
|
436
784
|
return;
|
|
437
785
|
}
|
|
786
|
+
// If write lock is held, defer render
|
|
438
787
|
if (writeLock.isLocked()) {
|
|
439
788
|
writeLock.safeWrite(() => this.render());
|
|
440
789
|
return;
|
|
441
790
|
}
|
|
442
|
-
this.renderFloatingInputArea();
|
|
443
|
-
}
|
|
444
|
-
/**
|
|
445
|
-
* Core floating input area renderer.
|
|
446
|
-
* Chat box always floats at contentRow (below streamed content).
|
|
447
|
-
* This creates "persistent bottom floating" behavior.
|
|
448
|
-
*/
|
|
449
|
-
renderFloatingInputArea() {
|
|
450
|
-
const { rows, cols } = this.getSize();
|
|
451
|
-
const maxWidth = Math.max(8, cols - 4);
|
|
452
|
-
const streamingActive = this.mode === 'streaming' || isStreamingMode();
|
|
453
|
-
// Wrap buffer into display lines
|
|
454
|
-
const { lines, cursorLine, cursorCol } = this.wrapBuffer(maxWidth);
|
|
455
|
-
const maxVisible = Math.max(1, Math.min(this.config.maxLines, rows - 3));
|
|
456
|
-
const displayLines = Math.min(lines.length, maxVisible);
|
|
457
|
-
const metaLines = this.buildMetaLines(cols - 2);
|
|
458
|
-
// Calculate display window (keep cursor visible)
|
|
459
|
-
let startLine = 0;
|
|
460
|
-
if (lines.length > displayLines) {
|
|
461
|
-
startLine = Math.max(0, cursorLine - displayLines + 1);
|
|
462
|
-
startLine = Math.min(startLine, lines.length - displayLines);
|
|
463
|
-
}
|
|
464
|
-
const visibleLines = lines.slice(startLine, startLine + displayLines);
|
|
465
|
-
const adjustedCursorLine = cursorLine - startLine;
|
|
466
|
-
// Chat box height
|
|
467
|
-
const chatBoxHeight = metaLines.length + 1 + displayLines + 1;
|
|
468
|
-
// Chat box floats at contentRow - right below the last content
|
|
469
|
-
// This is "persistent bottom floating" - always at bottom of content
|
|
470
|
-
const chatBoxStartRow = this.contentRow;
|
|
471
|
-
writeLock.lock('terminalInput.renderFloating');
|
|
472
791
|
this.isRendering = true;
|
|
792
|
+
writeLock.lock('terminalInput.render');
|
|
473
793
|
try {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
// Clear the chat box area
|
|
478
|
-
for (let i = 0; i < chatBoxHeight; i++) {
|
|
479
|
-
this.write(ESC.TO(chatBoxStartRow + i, 1));
|
|
480
|
-
this.write(ESC.CLEAR_LINE);
|
|
481
|
-
}
|
|
482
|
-
let currentRow = chatBoxStartRow;
|
|
483
|
-
// Meta/status header
|
|
484
|
-
for (const metaLine of metaLines) {
|
|
485
|
-
this.write(ESC.TO(currentRow, 1));
|
|
486
|
-
this.write(metaLine);
|
|
487
|
-
currentRow += 1;
|
|
794
|
+
if (this.mode === 'streaming' && this.scrollRegionActive) {
|
|
795
|
+
// During streaming: render at bottom (protected by scroll region)
|
|
796
|
+
this.renderInputAreaAtBottom();
|
|
488
797
|
}
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
currentRow += 1;
|
|
493
|
-
// Render input lines
|
|
494
|
-
let finalRow = currentRow;
|
|
495
|
-
let finalCol = 3;
|
|
496
|
-
for (let i = 0; i < visibleLines.length; i++) {
|
|
497
|
-
const rowNum = currentRow + i;
|
|
498
|
-
this.write(ESC.TO(rowNum, 1));
|
|
499
|
-
const line = visibleLines[i] ?? '';
|
|
500
|
-
const isFirstLine = (startLine + i) === 0;
|
|
501
|
-
const isCursorLine = i === adjustedCursorLine;
|
|
502
|
-
this.write(ESC.BG_DARK);
|
|
503
|
-
this.write(ESC.DIM);
|
|
504
|
-
this.write(isFirstLine ? this.config.promptChar : this.config.continuationChar);
|
|
505
|
-
this.write(ESC.RESET);
|
|
506
|
-
this.write(ESC.BG_DARK);
|
|
507
|
-
if (isCursorLine) {
|
|
508
|
-
const col = Math.min(cursorCol, line.length);
|
|
509
|
-
const before = line.slice(0, col);
|
|
510
|
-
const at = col < line.length ? line[col] : ' ';
|
|
511
|
-
const after = col < line.length ? line.slice(col + 1) : '';
|
|
512
|
-
this.write(before);
|
|
513
|
-
this.write(ESC.REVERSE + ESC.BOLD);
|
|
514
|
-
this.write(at);
|
|
515
|
-
this.write(ESC.RESET + ESC.BG_DARK);
|
|
516
|
-
this.write(after);
|
|
517
|
-
finalRow = rowNum;
|
|
518
|
-
finalCol = this.config.promptChar.length + col + 1;
|
|
519
|
-
}
|
|
520
|
-
else {
|
|
521
|
-
this.write(line);
|
|
522
|
-
}
|
|
523
|
-
// Pad to edge
|
|
524
|
-
const lineLen = this.config.promptChar.length + line.length + (isCursorLine && cursorCol >= line.length ? 1 : 0);
|
|
525
|
-
const padding = Math.max(0, cols - lineLen - 1);
|
|
526
|
-
if (padding > 0)
|
|
527
|
-
this.write(' '.repeat(padding));
|
|
528
|
-
this.write(ESC.RESET);
|
|
529
|
-
}
|
|
530
|
-
// Mode controls line
|
|
531
|
-
const controlRow = currentRow + visibleLines.length;
|
|
532
|
-
this.write(ESC.TO(controlRow, 1));
|
|
533
|
-
this.write(this.buildModeControls(cols));
|
|
534
|
-
// Position cursor in input box
|
|
535
|
-
this.write(ESC.TO(finalRow, Math.min(finalCol, cols)));
|
|
536
|
-
this.write(ESC.SHOW);
|
|
537
|
-
// Update state
|
|
538
|
-
this.lastRenderContent = this.buffer;
|
|
539
|
-
this.lastRenderCursor = this.cursor;
|
|
540
|
-
this.lastStreamingRender = streamingActive ? Date.now() : 0;
|
|
541
|
-
if (this.streamingRenderTimer) {
|
|
542
|
-
clearTimeout(this.streamingRenderTimer);
|
|
543
|
-
this.streamingRenderTimer = null;
|
|
798
|
+
else {
|
|
799
|
+
// Idle: render floating below content
|
|
800
|
+
this.renderFloatingInputArea();
|
|
544
801
|
}
|
|
545
802
|
}
|
|
546
803
|
finally {
|
|
@@ -549,217 +806,99 @@ export class TerminalInput extends EventEmitter {
|
|
|
549
806
|
}
|
|
550
807
|
}
|
|
551
808
|
/**
|
|
552
|
-
* Build
|
|
553
|
-
*
|
|
809
|
+
* Build status bar showing streaming/ready status and key info.
|
|
810
|
+
* This is the TOP line above the input area - minimal Claude Code style.
|
|
554
811
|
*/
|
|
555
|
-
|
|
556
|
-
const
|
|
557
|
-
const
|
|
558
|
-
//
|
|
559
|
-
if (this.
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
if (streamingActive) {
|
|
567
|
-
const parts = [];
|
|
568
|
-
// Essential streaming info
|
|
569
|
-
if (this.metaThinkingMs !== null) {
|
|
570
|
-
parts.push({ text: formatThinking(this.metaThinkingMs, this.metaThinkingHasContent), tone: 'info' });
|
|
571
|
-
}
|
|
572
|
-
if (this.metaElapsedSeconds !== null) {
|
|
573
|
-
parts.push({ text: this.formatElapsedLabel(this.metaElapsedSeconds), tone: 'muted' });
|
|
574
|
-
}
|
|
575
|
-
parts.push({ text: 'esc to stop', tone: 'warn' });
|
|
576
|
-
if (parts.length) {
|
|
577
|
-
lines.push(renderStatusLine(parts, width));
|
|
812
|
+
buildStatusBar(cols) {
|
|
813
|
+
const maxWidth = cols - 2;
|
|
814
|
+
const parts = [];
|
|
815
|
+
// Streaming status with elapsed time (left side)
|
|
816
|
+
if (this.mode === 'streaming') {
|
|
817
|
+
let statusText = '● Streaming';
|
|
818
|
+
if (this.streamingStartTime) {
|
|
819
|
+
const elapsed = Math.floor((Date.now() - this.streamingStartTime) / 1000);
|
|
820
|
+
const mins = Math.floor(elapsed / 60);
|
|
821
|
+
const secs = elapsed % 60;
|
|
822
|
+
statusText += mins > 0 ? ` ${mins}m ${secs}s` : ` ${secs}s`;
|
|
578
823
|
}
|
|
579
|
-
|
|
580
|
-
}
|
|
581
|
-
// Non-streaming: show full status info (model line already added above)
|
|
582
|
-
if (this.metaThinkingMs !== null) {
|
|
583
|
-
const thinkingText = formatThinking(this.metaThinkingMs, this.metaThinkingHasContent);
|
|
584
|
-
lines.push(renderStatusLine([{ text: thinkingText, tone: 'info' }], width));
|
|
585
|
-
}
|
|
586
|
-
const statusParts = [];
|
|
587
|
-
const statusLabel = this.statusMessage ?? this.streamingLabel;
|
|
588
|
-
if (statusLabel) {
|
|
589
|
-
statusParts.push({ text: statusLabel, tone: 'info' });
|
|
824
|
+
parts.push(`\x1b[32m${statusText}\x1b[0m`); // Green
|
|
590
825
|
}
|
|
591
|
-
|
|
592
|
-
|
|
826
|
+
// Queue indicator during streaming
|
|
827
|
+
if (this.mode === 'streaming' && this.queue.length > 0) {
|
|
828
|
+
parts.push(`\x1b[36mqueued: ${this.queue.length}\x1b[0m`); // Cyan
|
|
593
829
|
}
|
|
594
|
-
|
|
595
|
-
if (
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
if (statusParts.length) {
|
|
599
|
-
lines.push(renderStatusLine(statusParts, width));
|
|
830
|
+
// Paste indicator
|
|
831
|
+
if (this.pastePlaceholders.length > 0) {
|
|
832
|
+
const totalLines = this.pastePlaceholders.reduce((sum, p) => sum + p.lineCount, 0);
|
|
833
|
+
parts.push(`\x1b[36m📋 ${totalLines}L\x1b[0m`);
|
|
600
834
|
}
|
|
601
|
-
|
|
602
|
-
if (this.
|
|
603
|
-
|
|
604
|
-
const formattedLimit = this.metaTokenLimit ? `/${this.formatTokenCount(this.metaTokenLimit)}` : '';
|
|
605
|
-
usageParts.push({ text: `tokens ${formattedUsed}${formattedLimit}`, tone: 'muted' });
|
|
835
|
+
// Override/warning status
|
|
836
|
+
if (this.overrideStatusMessage) {
|
|
837
|
+
parts.push(`\x1b[33m⚠ ${this.overrideStatusMessage}\x1b[0m`); // Yellow
|
|
606
838
|
}
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
usageParts.push({ text: `context used ${this.contextUsage}% (${left}% left)`, tone });
|
|
839
|
+
// If idle with empty buffer, show quick shortcuts
|
|
840
|
+
if (this.mode !== 'streaming' && this.buffer.length === 0 && parts.length === 0) {
|
|
841
|
+
return `${ESC.DIM}Type a message or / for commands${ESC.RESET}`;
|
|
611
842
|
}
|
|
612
|
-
|
|
613
|
-
|
|
843
|
+
// Multi-line indicator
|
|
844
|
+
if (this.buffer.includes('\n')) {
|
|
845
|
+
parts.push(`${ESC.DIM}${this.buffer.split('\n').length}L${ESC.RESET}`);
|
|
614
846
|
}
|
|
615
|
-
if (
|
|
616
|
-
|
|
847
|
+
if (parts.length === 0) {
|
|
848
|
+
return ''; // Empty status bar when idle
|
|
617
849
|
}
|
|
618
|
-
|
|
850
|
+
const joined = parts.join(`${ESC.DIM} · ${ESC.RESET}`);
|
|
851
|
+
return joined.slice(0, maxWidth);
|
|
619
852
|
}
|
|
620
853
|
/**
|
|
621
|
-
* Build
|
|
622
|
-
*
|
|
854
|
+
* Build mode controls line showing toggles and context info.
|
|
855
|
+
* This is the BOTTOM line below the input area - Claude Code style layout with erosolar features.
|
|
856
|
+
*
|
|
857
|
+
* Layout: [toggles on left] ... [context info on right]
|
|
623
858
|
*/
|
|
624
859
|
buildModeControls(cols) {
|
|
625
|
-
const
|
|
626
|
-
|
|
627
|
-
const
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
if (this.
|
|
632
|
-
|
|
633
|
-
}
|
|
634
|
-
if (this.statusMessage) {
|
|
635
|
-
leftParts.push({ text: this.statusMessage, tone: this.streamingLabel ? 'muted' : 'info' });
|
|
636
|
-
}
|
|
637
|
-
const editHotkey = this.formatHotkey('shift+tab');
|
|
638
|
-
const editLabel = this.editMode === 'display-edits' ? 'edits: accept' : 'edits: ask';
|
|
639
|
-
const editTone = this.editMode === 'display-edits' ? 'success' : 'muted';
|
|
640
|
-
leftParts.push({ text: `${editHotkey} ${editLabel}`, tone: editTone });
|
|
641
|
-
const verifyHotkey = this.formatHotkey(this.verificationHotkey);
|
|
642
|
-
const verifyLabel = this.verificationEnabled ? 'verify:on' : 'verify:off';
|
|
643
|
-
leftParts.push({ text: `${verifyHotkey} ${verifyLabel}`, tone: this.verificationEnabled ? 'success' : 'muted' });
|
|
644
|
-
const continueHotkey = this.formatHotkey(this.autoContinueHotkey);
|
|
645
|
-
const continueLabel = this.autoContinueEnabled ? 'auto:on' : 'auto:off';
|
|
646
|
-
leftParts.push({ text: `${continueHotkey} ${continueLabel}`, tone: this.autoContinueEnabled ? 'info' : 'muted' });
|
|
647
|
-
if (this.queue.length > 0 && this.mode !== 'streaming') {
|
|
648
|
-
leftParts.push({ text: `queued ${this.queue.length}`, tone: 'info' });
|
|
649
|
-
}
|
|
650
|
-
if (this.buffer.includes('\n')) {
|
|
651
|
-
const lineCount = this.buffer.split('\n').length;
|
|
652
|
-
leftParts.push({ text: `${lineCount} lines`, tone: 'muted' });
|
|
653
|
-
}
|
|
654
|
-
if (this.pastePlaceholders.length > 0) {
|
|
655
|
-
const latest = this.pastePlaceholders[this.pastePlaceholders.length - 1];
|
|
656
|
-
leftParts.push({
|
|
657
|
-
text: `paste #${latest.id} +${latest.lineCount} lines (⌫ to drop)`,
|
|
658
|
-
tone: 'info',
|
|
659
|
-
});
|
|
660
|
-
}
|
|
661
|
-
const contextRemaining = this.computeContextRemaining();
|
|
662
|
-
if (this.thinkingModeLabel) {
|
|
663
|
-
const thinkingHotkey = this.formatHotkey(this.thinkingHotkey);
|
|
664
|
-
rightParts.push({ text: `${thinkingHotkey} thinking:${this.thinkingModeLabel}`, tone: 'info' });
|
|
665
|
-
}
|
|
666
|
-
// Show model in controls only when NOT streaming (during streaming it's in meta lines)
|
|
667
|
-
const streamingActive = this.mode === 'streaming' || isStreamingMode();
|
|
668
|
-
if (this.modelLabel && !streamingActive) {
|
|
669
|
-
const modelText = this.providerLabel ? `${this.modelLabel} @ ${this.providerLabel}` : this.modelLabel;
|
|
670
|
-
rightParts.push({ text: modelText, tone: 'muted' });
|
|
671
|
-
}
|
|
672
|
-
if (contextRemaining !== null) {
|
|
673
|
-
const tone = contextRemaining <= 10 ? 'warn' : 'muted';
|
|
674
|
-
const label = contextRemaining === 0 && this.contextUsage !== null
|
|
675
|
-
? 'Context auto-compact imminent'
|
|
676
|
-
: `Context left until auto-compact: ${contextRemaining}%`;
|
|
677
|
-
rightParts.push({ text: label, tone });
|
|
678
|
-
}
|
|
679
|
-
if (!rightParts.length || width < 60) {
|
|
680
|
-
const merged = rightParts.length ? [...leftParts, ...rightParts] : leftParts;
|
|
681
|
-
return renderStatusLine(merged, width);
|
|
682
|
-
}
|
|
683
|
-
const leftWidth = Math.max(12, Math.floor(width * 0.6));
|
|
684
|
-
const rightWidth = Math.max(14, width - leftWidth - 1);
|
|
685
|
-
const leftText = renderStatusLine(leftParts, leftWidth);
|
|
686
|
-
const rightText = renderStatusLine(rightParts, rightWidth);
|
|
687
|
-
const spacing = Math.max(1, width - this.visibleLength(leftText) - this.visibleLength(rightText));
|
|
688
|
-
return `${leftText}${' '.repeat(spacing)}${rightText}`;
|
|
689
|
-
}
|
|
690
|
-
formatHotkey(hotkey) {
|
|
691
|
-
const normalized = hotkey.trim().toLowerCase();
|
|
692
|
-
if (!normalized)
|
|
693
|
-
return hotkey;
|
|
694
|
-
const parts = normalized.split('+').filter(Boolean);
|
|
695
|
-
const map = {
|
|
696
|
-
shift: '⇧',
|
|
697
|
-
sh: '⇧',
|
|
698
|
-
alt: '⌥',
|
|
699
|
-
option: '⌥',
|
|
700
|
-
opt: '⌥',
|
|
701
|
-
ctrl: '⌃',
|
|
702
|
-
control: '⌃',
|
|
703
|
-
cmd: '⌘',
|
|
704
|
-
meta: '⌘',
|
|
705
|
-
};
|
|
706
|
-
const formatted = parts
|
|
707
|
-
.map((part) => {
|
|
708
|
-
const symbol = map[part];
|
|
709
|
-
if (symbol)
|
|
710
|
-
return symbol;
|
|
711
|
-
return part.length === 1 ? part.toUpperCase() : part.toUpperCase();
|
|
712
|
-
})
|
|
713
|
-
.join('');
|
|
714
|
-
return formatted || hotkey;
|
|
715
|
-
}
|
|
716
|
-
computeContextRemaining() {
|
|
717
|
-
if (this.contextUsage === null) {
|
|
718
|
-
return null;
|
|
719
|
-
}
|
|
720
|
-
return Math.max(0, this.contextAutoCompactThreshold - this.contextUsage);
|
|
721
|
-
}
|
|
722
|
-
computeTokensRemaining() {
|
|
723
|
-
if (this.metaTokensUsed === null || this.metaTokenLimit === null) {
|
|
724
|
-
return null;
|
|
725
|
-
}
|
|
726
|
-
const remaining = Math.max(0, this.metaTokenLimit - this.metaTokensUsed);
|
|
727
|
-
return this.formatTokenCount(remaining);
|
|
728
|
-
}
|
|
729
|
-
formatElapsedLabel(seconds) {
|
|
730
|
-
if (seconds < 60) {
|
|
731
|
-
return `${seconds}s`;
|
|
732
|
-
}
|
|
733
|
-
const mins = Math.floor(seconds / 60);
|
|
734
|
-
const secs = seconds % 60;
|
|
735
|
-
return secs > 0 ? `${mins}m ${secs}s` : `${mins}m`;
|
|
736
|
-
}
|
|
737
|
-
formatTokenCount(value) {
|
|
738
|
-
if (!Number.isFinite(value)) {
|
|
739
|
-
return `${value}`;
|
|
740
|
-
}
|
|
741
|
-
if (value >= 1_000_000) {
|
|
742
|
-
return `${(value / 1_000_000).toFixed(1)}M`;
|
|
860
|
+
const maxWidth = cols - 2;
|
|
861
|
+
// Use schema-defined colors for consistency
|
|
862
|
+
const { green: GREEN, yellow: YELLOW, cyan: CYAN, magenta: MAGENTA, red: RED, dim: DIM, reset: R } = UI_COLORS;
|
|
863
|
+
// Mode toggles with colors (following ModeControlsSchema)
|
|
864
|
+
const toggles = [];
|
|
865
|
+
// Edit mode (green=auto, yellow=ask) - per schema.editMode
|
|
866
|
+
if (this.editMode === 'display-edits') {
|
|
867
|
+
toggles.push(`${GREEN}⏵⏵ auto-edit${R}`);
|
|
743
868
|
}
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
869
|
+
else {
|
|
870
|
+
toggles.push(`${YELLOW}⏸⏸ ask-first${R}`);
|
|
871
|
+
}
|
|
872
|
+
// Thinking mode (cyan when on) - per schema.thinkingMode
|
|
873
|
+
toggles.push(this.thinkingEnabled ? `${CYAN}💭 think${R}` : `${DIM}○ think${R}`);
|
|
874
|
+
// Verification (green when on) - per schema.verificationMode
|
|
875
|
+
toggles.push(this.verificationEnabled ? `${GREEN}✓ verify${R}` : `${DIM}○ verify${R}`);
|
|
876
|
+
// Auto-continue (magenta when on) - per schema.autoContinueMode
|
|
877
|
+
toggles.push(this.autoContinueEnabled ? `${MAGENTA}↻ auto${R}` : `${DIM}○ auto${R}`);
|
|
878
|
+
const leftPart = toggles.join(`${DIM} · ${R}`) + `${DIM} (⇧⇥)${R}`;
|
|
879
|
+
// Context usage with color - per schema.contextUsage thresholds
|
|
880
|
+
let rightPart = '';
|
|
881
|
+
if (this.contextUsage !== null) {
|
|
882
|
+
const rem = Math.max(0, 100 - this.contextUsage);
|
|
883
|
+
// Thresholds: critical < 10%, warning < 25%
|
|
884
|
+
if (rem < 10)
|
|
885
|
+
rightPart = `${RED}⚠ ctx: ${rem}%${R}`;
|
|
886
|
+
else if (rem < 25)
|
|
887
|
+
rightPart = `${YELLOW}! ctx: ${rem}%${R}`;
|
|
888
|
+
else
|
|
889
|
+
rightPart = `${DIM}ctx: ${rem}%${R}`;
|
|
890
|
+
}
|
|
891
|
+
// Calculate visible lengths (strip ANSI)
|
|
892
|
+
const strip = (s) => s.replace(/\x1b\[[0-9;]*m/g, '');
|
|
893
|
+
const leftLen = strip(leftPart).length;
|
|
894
|
+
const rightLen = strip(rightPart).length;
|
|
895
|
+
if (leftLen + rightLen < maxWidth - 4) {
|
|
896
|
+
return `${leftPart}${' '.repeat(maxWidth - leftLen - rightLen)}${rightPart}`;
|
|
897
|
+
}
|
|
898
|
+
if (rightLen > 0 && leftLen + 8 < maxWidth) {
|
|
899
|
+
return `${leftPart} ${rightPart}`;
|
|
900
|
+
}
|
|
901
|
+
return leftPart;
|
|
763
902
|
}
|
|
764
903
|
/**
|
|
765
904
|
* Force a re-render
|
|
@@ -782,65 +921,20 @@ export class TerminalInput extends EventEmitter {
|
|
|
782
921
|
handleResize() {
|
|
783
922
|
this.lastRenderContent = '';
|
|
784
923
|
this.lastRenderCursor = -1;
|
|
785
|
-
this.resetStreamingRenderThrottle();
|
|
786
924
|
this.scheduleRender();
|
|
787
925
|
}
|
|
788
926
|
/**
|
|
789
|
-
*
|
|
790
|
-
*
|
|
791
|
-
* This is the CLEAN method for streaming - no output interceptor needed.
|
|
792
|
-
* 1. Position cursor at contentRow
|
|
793
|
-
* 2. Write content directly (overwrites any chat box visually)
|
|
794
|
-
* 3. Advance contentRow by newlines
|
|
795
|
-
* 4. Re-render chat box at new position
|
|
796
|
-
*
|
|
797
|
-
* The chat box always re-renders after content, so it appears to "float" below.
|
|
798
|
-
*/
|
|
799
|
-
streamContent(content) {
|
|
800
|
-
if (!content)
|
|
801
|
-
return;
|
|
802
|
-
// Position cursor at contentRow and write content
|
|
803
|
-
this.write(ESC.TO(this.contentRow, 1));
|
|
804
|
-
this.write(content);
|
|
805
|
-
// Advance contentRow by number of newlines
|
|
806
|
-
const newlines = (content.match(/\n/g) || []).length;
|
|
807
|
-
this.contentRow += newlines;
|
|
808
|
-
// Re-render chat box at new position (below the content just written)
|
|
809
|
-
this.forceRender();
|
|
810
|
-
}
|
|
811
|
-
/**
|
|
812
|
-
* @deprecated Use streamContent() instead
|
|
813
|
-
* Register with display's output interceptor - kept for backwards compatibility
|
|
814
|
-
*/
|
|
815
|
-
registerOutputInterceptor(_display) {
|
|
816
|
-
// No-op: Use streamContent() for cleaner floating chat box behavior
|
|
817
|
-
}
|
|
818
|
-
/**
|
|
819
|
-
* @deprecated Use streamContent() instead
|
|
820
|
-
* Write content above the floating chat box.
|
|
927
|
+
* Register with display's output interceptor (kept for API compatibility).
|
|
928
|
+
* With unified floating input, no special cursor manipulation is needed.
|
|
821
929
|
*/
|
|
822
|
-
|
|
823
|
-
this.
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
this.contentRow = 1;
|
|
831
|
-
}
|
|
832
|
-
/**
|
|
833
|
-
* Set the content row explicitly (used after banner is written).
|
|
834
|
-
* This tells the input where content should start flowing from.
|
|
835
|
-
*/
|
|
836
|
-
setContentRow(row) {
|
|
837
|
-
this.contentRow = Math.max(1, row);
|
|
838
|
-
}
|
|
839
|
-
/**
|
|
840
|
-
* Get the current content row position.
|
|
841
|
-
*/
|
|
842
|
-
getContentRow() {
|
|
843
|
-
return this.contentRow;
|
|
930
|
+
registerOutputInterceptor(display) {
|
|
931
|
+
if (this.outputInterceptorCleanup) {
|
|
932
|
+
this.outputInterceptorCleanup();
|
|
933
|
+
}
|
|
934
|
+
this.outputInterceptorCleanup = display.registerOutputInterceptor({
|
|
935
|
+
beforeWrite: () => { },
|
|
936
|
+
afterWrite: () => { },
|
|
937
|
+
});
|
|
844
938
|
}
|
|
845
939
|
/**
|
|
846
940
|
* Dispose and clean up
|
|
@@ -848,9 +942,18 @@ export class TerminalInput extends EventEmitter {
|
|
|
848
942
|
dispose() {
|
|
849
943
|
if (this.disposed)
|
|
850
944
|
return;
|
|
945
|
+
// Clean up streaming render timer
|
|
946
|
+
if (this.streamingRenderTimer) {
|
|
947
|
+
clearInterval(this.streamingRenderTimer);
|
|
948
|
+
this.streamingRenderTimer = null;
|
|
949
|
+
}
|
|
950
|
+
// Clean up output interceptor
|
|
951
|
+
if (this.outputInterceptorCleanup) {
|
|
952
|
+
this.outputInterceptorCleanup();
|
|
953
|
+
this.outputInterceptorCleanup = undefined;
|
|
954
|
+
}
|
|
851
955
|
this.disposed = true;
|
|
852
956
|
this.enabled = false;
|
|
853
|
-
this.resetStreamingRenderThrottle();
|
|
854
957
|
this.disableBracketedPaste();
|
|
855
958
|
this.buffer = '';
|
|
856
959
|
this.queue = [];
|
|
@@ -955,7 +1058,22 @@ export class TerminalInput extends EventEmitter {
|
|
|
955
1058
|
this.toggleEditMode();
|
|
956
1059
|
return true;
|
|
957
1060
|
}
|
|
958
|
-
|
|
1061
|
+
// Tab: toggle paste expansion if in placeholder, otherwise toggle thinking
|
|
1062
|
+
if (this.findPlaceholderAt(this.cursor)) {
|
|
1063
|
+
this.togglePasteExpansion();
|
|
1064
|
+
}
|
|
1065
|
+
else {
|
|
1066
|
+
this.toggleThinking();
|
|
1067
|
+
}
|
|
1068
|
+
return true;
|
|
1069
|
+
case 'escape':
|
|
1070
|
+
// Esc: interrupt if streaming, otherwise clear buffer
|
|
1071
|
+
if (this.mode === 'streaming') {
|
|
1072
|
+
this.emit('interrupt');
|
|
1073
|
+
}
|
|
1074
|
+
else if (this.buffer.length > 0) {
|
|
1075
|
+
this.clear();
|
|
1076
|
+
}
|
|
959
1077
|
return true;
|
|
960
1078
|
}
|
|
961
1079
|
return false;
|
|
@@ -973,6 +1091,7 @@ export class TerminalInput extends EventEmitter {
|
|
|
973
1091
|
this.insertPlainText(chunk, insertPos);
|
|
974
1092
|
this.cursor = insertPos + chunk.length;
|
|
975
1093
|
this.emit('change', this.buffer);
|
|
1094
|
+
this.updateSuggestions();
|
|
976
1095
|
this.scheduleRender();
|
|
977
1096
|
}
|
|
978
1097
|
insertNewline() {
|
|
@@ -997,6 +1116,7 @@ export class TerminalInput extends EventEmitter {
|
|
|
997
1116
|
this.cursor = Math.max(0, this.cursor - 1);
|
|
998
1117
|
}
|
|
999
1118
|
this.emit('change', this.buffer);
|
|
1119
|
+
this.updateSuggestions();
|
|
1000
1120
|
this.scheduleRender();
|
|
1001
1121
|
}
|
|
1002
1122
|
deleteForward() {
|
|
@@ -1224,12 +1344,13 @@ export class TerminalInput extends EventEmitter {
|
|
|
1224
1344
|
timestamp: Date.now(),
|
|
1225
1345
|
});
|
|
1226
1346
|
this.emit('queue', text);
|
|
1227
|
-
this.clear(); // Clear immediately for queued input
|
|
1347
|
+
this.clear(); // Clear immediately for queued input, re-render to update queue display
|
|
1228
1348
|
}
|
|
1229
1349
|
else {
|
|
1230
|
-
// In idle mode, clear the input
|
|
1231
|
-
// The
|
|
1232
|
-
|
|
1350
|
+
// In idle mode, clear the input WITHOUT rendering.
|
|
1351
|
+
// The caller will display the user message and start streaming.
|
|
1352
|
+
// We'll render the input area again after streaming ends.
|
|
1353
|
+
this.clear(true); // Skip render - streaming will handle display
|
|
1233
1354
|
this.emit('submit', text);
|
|
1234
1355
|
}
|
|
1235
1356
|
}
|
|
@@ -1246,9 +1367,7 @@ export class TerminalInput extends EventEmitter {
|
|
|
1246
1367
|
if (available <= 0)
|
|
1247
1368
|
return;
|
|
1248
1369
|
const chunk = clean.slice(0, available);
|
|
1249
|
-
|
|
1250
|
-
const isShortMultiline = isMultiline && this.shouldInlineMultiline(chunk);
|
|
1251
|
-
if (isMultiline && !isShortMultiline) {
|
|
1370
|
+
if (isMultilinePaste(chunk)) {
|
|
1252
1371
|
this.insertPastePlaceholder(chunk);
|
|
1253
1372
|
}
|
|
1254
1373
|
else {
|
|
@@ -1384,19 +1503,17 @@ export class TerminalInput extends EventEmitter {
|
|
|
1384
1503
|
this.shiftPlaceholders(position, text.length);
|
|
1385
1504
|
this.buffer = this.buffer.slice(0, position) + text + this.buffer.slice(position);
|
|
1386
1505
|
}
|
|
1387
|
-
shouldInlineMultiline(content) {
|
|
1388
|
-
const lines = content.split('\n').length;
|
|
1389
|
-
const maxInlineLines = 4;
|
|
1390
|
-
const maxInlineChars = 240;
|
|
1391
|
-
return lines <= maxInlineLines && content.length <= maxInlineChars;
|
|
1392
|
-
}
|
|
1393
1506
|
findPlaceholderAt(position) {
|
|
1394
1507
|
return this.pastePlaceholders.find((ph) => position >= ph.start && position < ph.end) ?? null;
|
|
1395
1508
|
}
|
|
1396
|
-
buildPlaceholder(
|
|
1509
|
+
buildPlaceholder(summary) {
|
|
1397
1510
|
const id = ++this.pasteCounter;
|
|
1398
|
-
const
|
|
1399
|
-
|
|
1511
|
+
const lang = summary.language ? ` ${summary.language.toUpperCase()}` : '';
|
|
1512
|
+
// Show first line preview (truncated)
|
|
1513
|
+
const preview = summary.preview.length > 30
|
|
1514
|
+
? `${summary.preview.slice(0, 30)}...`
|
|
1515
|
+
: summary.preview;
|
|
1516
|
+
const placeholder = `[📋 #${id}${lang} ${summary.lineCount}L] "${preview}"`;
|
|
1400
1517
|
return { id, placeholder };
|
|
1401
1518
|
}
|
|
1402
1519
|
insertPastePlaceholder(content) {
|
|
@@ -1404,21 +1521,67 @@ export class TerminalInput extends EventEmitter {
|
|
|
1404
1521
|
if (available <= 0)
|
|
1405
1522
|
return;
|
|
1406
1523
|
const cleanContent = content.slice(0, available);
|
|
1407
|
-
const
|
|
1408
|
-
|
|
1524
|
+
const summary = generatePasteSummary(cleanContent);
|
|
1525
|
+
// For short pastes (< 5 lines), show full content instead of placeholder
|
|
1526
|
+
if (summary.lineCount < 5) {
|
|
1527
|
+
const placeholder = this.findPlaceholderAt(this.cursor);
|
|
1528
|
+
const insertPos = placeholder && this.cursor > placeholder.start ? placeholder.end : this.cursor;
|
|
1529
|
+
this.insertPlainText(cleanContent, insertPos);
|
|
1530
|
+
this.cursor = insertPos + cleanContent.length;
|
|
1531
|
+
return;
|
|
1532
|
+
}
|
|
1533
|
+
const { id, placeholder } = this.buildPlaceholder(summary);
|
|
1409
1534
|
const insertPos = this.cursor;
|
|
1410
1535
|
this.shiftPlaceholders(insertPos, placeholder.length);
|
|
1411
1536
|
this.pastePlaceholders.push({
|
|
1412
1537
|
id,
|
|
1413
1538
|
content: cleanContent,
|
|
1414
|
-
lineCount,
|
|
1539
|
+
lineCount: summary.lineCount,
|
|
1415
1540
|
placeholder,
|
|
1416
1541
|
start: insertPos,
|
|
1417
1542
|
end: insertPos + placeholder.length,
|
|
1543
|
+
summary,
|
|
1544
|
+
expanded: false,
|
|
1418
1545
|
});
|
|
1419
1546
|
this.buffer = this.buffer.slice(0, insertPos) + placeholder + this.buffer.slice(insertPos);
|
|
1420
1547
|
this.cursor = insertPos + placeholder.length;
|
|
1421
1548
|
}
|
|
1549
|
+
/**
|
|
1550
|
+
* Toggle expansion of a paste placeholder at the current cursor position.
|
|
1551
|
+
* When expanded, shows first 3 and last 2 lines of the content.
|
|
1552
|
+
*/
|
|
1553
|
+
togglePasteExpansion() {
|
|
1554
|
+
const placeholder = this.findPlaceholderAt(this.cursor);
|
|
1555
|
+
if (!placeholder)
|
|
1556
|
+
return false;
|
|
1557
|
+
placeholder.expanded = !placeholder.expanded;
|
|
1558
|
+
// Update the placeholder text in buffer
|
|
1559
|
+
const newPlaceholder = placeholder.expanded
|
|
1560
|
+
? this.buildExpandedPlaceholder(placeholder)
|
|
1561
|
+
: this.buildPlaceholder(placeholder.summary).placeholder;
|
|
1562
|
+
const lengthDiff = newPlaceholder.length - placeholder.placeholder.length;
|
|
1563
|
+
// Update buffer
|
|
1564
|
+
this.buffer =
|
|
1565
|
+
this.buffer.slice(0, placeholder.start) +
|
|
1566
|
+
newPlaceholder +
|
|
1567
|
+
this.buffer.slice(placeholder.end);
|
|
1568
|
+
// Update placeholder tracking
|
|
1569
|
+
placeholder.placeholder = newPlaceholder;
|
|
1570
|
+
placeholder.end = placeholder.start + newPlaceholder.length;
|
|
1571
|
+
// Shift other placeholders
|
|
1572
|
+
this.shiftPlaceholders(placeholder.end, lengthDiff, placeholder.id);
|
|
1573
|
+
this.scheduleRender();
|
|
1574
|
+
return true;
|
|
1575
|
+
}
|
|
1576
|
+
buildExpandedPlaceholder(ph) {
|
|
1577
|
+
const lines = ph.content.split('\n');
|
|
1578
|
+
const firstLines = lines.slice(0, 3).map(l => l.slice(0, 60)).join('\n');
|
|
1579
|
+
const lastLines = lines.length > 5
|
|
1580
|
+
? '\n...\n' + lines.slice(-2).map(l => l.slice(0, 60)).join('\n')
|
|
1581
|
+
: '';
|
|
1582
|
+
const lang = ph.summary.language ? ` ${ph.summary.language.toUpperCase()}` : '';
|
|
1583
|
+
return `[📋 #${ph.id}${lang} ${ph.lineCount}L ▼]\n${firstLines}${lastLines}\n[/📋 #${ph.id}]`;
|
|
1584
|
+
}
|
|
1422
1585
|
deletePlaceholder(placeholder) {
|
|
1423
1586
|
const length = placeholder.end - placeholder.start;
|
|
1424
1587
|
this.buffer = this.buffer.slice(0, placeholder.start) + this.buffer.slice(placeholder.end);
|
|
@@ -1426,11 +1589,7 @@ export class TerminalInput extends EventEmitter {
|
|
|
1426
1589
|
this.shiftPlaceholders(placeholder.end, -length, placeholder.id);
|
|
1427
1590
|
this.cursor = placeholder.start;
|
|
1428
1591
|
}
|
|
1429
|
-
updateContextUsage(value
|
|
1430
|
-
if (typeof autoCompactThreshold === 'number' && Number.isFinite(autoCompactThreshold)) {
|
|
1431
|
-
const boundedThreshold = Math.max(1, Math.min(100, Math.round(autoCompactThreshold)));
|
|
1432
|
-
this.contextAutoCompactThreshold = boundedThreshold;
|
|
1433
|
-
}
|
|
1592
|
+
updateContextUsage(value) {
|
|
1434
1593
|
if (value === null || !Number.isFinite(value)) {
|
|
1435
1594
|
this.contextUsage = null;
|
|
1436
1595
|
}
|
|
@@ -1457,22 +1616,6 @@ export class TerminalInput extends EventEmitter {
|
|
|
1457
1616
|
const next = this.editMode === 'display-edits' ? 'ask-permission' : 'display-edits';
|
|
1458
1617
|
this.setEditMode(next);
|
|
1459
1618
|
}
|
|
1460
|
-
scheduleStreamingRender(delayMs) {
|
|
1461
|
-
if (this.streamingRenderTimer)
|
|
1462
|
-
return;
|
|
1463
|
-
const wait = Math.max(16, delayMs);
|
|
1464
|
-
this.streamingRenderTimer = setTimeout(() => {
|
|
1465
|
-
this.streamingRenderTimer = null;
|
|
1466
|
-
this.render();
|
|
1467
|
-
}, wait);
|
|
1468
|
-
}
|
|
1469
|
-
resetStreamingRenderThrottle() {
|
|
1470
|
-
if (this.streamingRenderTimer) {
|
|
1471
|
-
clearTimeout(this.streamingRenderTimer);
|
|
1472
|
-
this.streamingRenderTimer = null;
|
|
1473
|
-
}
|
|
1474
|
-
this.lastStreamingRender = 0;
|
|
1475
|
-
}
|
|
1476
1619
|
scheduleRender() {
|
|
1477
1620
|
if (!this.canRender())
|
|
1478
1621
|
return;
|