erosolar-cli 1.7.308 → 1.7.309
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 +113 -123
- package/dist/shell/terminalInput.d.ts.map +1 -1
- package/dist/shell/terminalInput.js +521 -564
- package/dist/shell/terminalInput.js.map +1 -1
- package/dist/shell/terminalInputAdapter.d.ts +20 -56
- package/dist/shell/terminalInputAdapter.d.ts.map +1 -1
- package/dist/shell/terminalInputAdapter.js +30 -66
- 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,20 +3,15 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Design principles:
|
|
5
5
|
* - Single source of truth for input state
|
|
6
|
-
* - Hybrid floating/scroll approach:
|
|
7
|
-
* - Initially: chat box floats below content
|
|
8
|
-
* - When terminal fills: scroll region activates, chat box pins to bottom
|
|
9
6
|
* - Native bracketed paste support (no heuristics)
|
|
10
7
|
* - Clean cursor model with render-time wrapping
|
|
11
8
|
* - State machine for different input modes
|
|
12
9
|
* - No readline dependency for display
|
|
13
10
|
*/
|
|
14
11
|
import { EventEmitter } from 'node:events';
|
|
15
|
-
import { isMultilinePaste } from '../core/multilinePasteHandler.js';
|
|
12
|
+
import { isMultilinePaste, generatePasteSummary } from '../core/multilinePasteHandler.js';
|
|
16
13
|
import { writeLock } from '../ui/writeLock.js';
|
|
17
|
-
import {
|
|
18
|
-
import { isStreamingMode } from '../ui/globalWriteLock.js';
|
|
19
|
-
import { formatThinking } from '../ui/toolDisplay.js';
|
|
14
|
+
import { UI_COLORS, DEFAULT_UI_CONFIG, } from '../ui/terminalUISchema.js';
|
|
20
15
|
// ANSI escape codes
|
|
21
16
|
const ESC = {
|
|
22
17
|
// Cursor control
|
|
@@ -26,12 +21,12 @@ const ESC = {
|
|
|
26
21
|
SHOW: '\x1b[?25h',
|
|
27
22
|
TO: (row, col) => `\x1b[${row};${col}H`,
|
|
28
23
|
TO_COL: (col) => `\x1b[${col}G`,
|
|
24
|
+
// Screen control
|
|
25
|
+
CLEAR_SCREEN: '\x1b[2J',
|
|
26
|
+
HOME: '\x1b[H',
|
|
29
27
|
// Line control
|
|
30
28
|
CLEAR_LINE: '\x1b[2K',
|
|
31
29
|
CLEAR_TO_END: '\x1b[0J',
|
|
32
|
-
// Scroll region
|
|
33
|
-
SET_SCROLL: (top, bottom) => `\x1b[${top};${bottom}r`,
|
|
34
|
-
RESET_SCROLL: '\x1b[r',
|
|
35
30
|
// Style
|
|
36
31
|
RESET: '\x1b[0m',
|
|
37
32
|
DIM: '\x1b[2m',
|
|
@@ -71,46 +66,47 @@ export class TerminalInput extends EventEmitter {
|
|
|
71
66
|
statusMessage = null;
|
|
72
67
|
overrideStatusMessage = null; // Secondary status (warnings, etc.)
|
|
73
68
|
streamingLabel = null; // Streaming progress indicator
|
|
74
|
-
metaElapsedSeconds = null; // Optional elapsed time for header line
|
|
75
|
-
metaTokensUsed = null; // Optional token usage
|
|
76
|
-
metaTokenLimit = null; // Optional token window
|
|
77
|
-
metaThinkingMs = null; // Optional thinking duration
|
|
78
|
-
metaThinkingHasContent = false; // Whether collapsed thinking content exists
|
|
79
69
|
lastRenderContent = '';
|
|
80
70
|
lastRenderCursor = -1;
|
|
81
71
|
renderDirty = false;
|
|
82
72
|
isRendering = false;
|
|
73
|
+
flowModeRenderedLines = 0; // Track lines rendered for clearing
|
|
74
|
+
inputAreaStartRow = 0; // Track absolute row position of input area
|
|
75
|
+
contentEndRow = 0; // Row where content ends (chat box renders below this)
|
|
76
|
+
// Command suggestions (Claude Code style auto-complete)
|
|
77
|
+
commandSuggestions = [];
|
|
78
|
+
filteredSuggestions = [];
|
|
79
|
+
selectedSuggestionIndex = 0;
|
|
80
|
+
showSuggestions = false;
|
|
83
81
|
// Lifecycle
|
|
84
82
|
disposed = false;
|
|
85
83
|
enabled = true;
|
|
86
84
|
contextUsage = null;
|
|
87
|
-
contextAutoCompactThreshold = 90;
|
|
88
|
-
// Track current content row (starts at top, moves down)
|
|
89
|
-
contentRow = 1;
|
|
90
|
-
// Track if scroll region is currently active
|
|
91
|
-
scrollRegionActive = false;
|
|
92
|
-
thinkingModeLabel = null;
|
|
93
85
|
editMode = 'display-edits';
|
|
94
86
|
verificationEnabled = true;
|
|
95
87
|
autoContinueEnabled = false;
|
|
96
88
|
verificationHotkey = 'alt+v';
|
|
97
89
|
autoContinueHotkey = 'alt+c';
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
90
|
+
// Output interceptor cleanup
|
|
91
|
+
outputInterceptorCleanup;
|
|
92
|
+
// Metrics tracking for status bar
|
|
93
|
+
streamingStartTime = null;
|
|
94
|
+
thinkingEnabled = true;
|
|
95
|
+
modelInfo = null; // Provider · Model info
|
|
96
|
+
// Streaming input area render timer (updates elapsed time display)
|
|
104
97
|
streamingRenderTimer = null;
|
|
98
|
+
// Unified UI initialization flag
|
|
99
|
+
unifiedUIInitialized = false;
|
|
105
100
|
constructor(writeStream = process.stdout, config = {}) {
|
|
106
101
|
super();
|
|
107
102
|
this.out = writeStream;
|
|
103
|
+
// Use schema defaults for configuration consistency
|
|
108
104
|
this.config = {
|
|
109
|
-
maxLines: config.maxLines ??
|
|
110
|
-
maxLength: config.maxLength ??
|
|
105
|
+
maxLines: config.maxLines ?? DEFAULT_UI_CONFIG.inputArea.maxLines,
|
|
106
|
+
maxLength: config.maxLength ?? DEFAULT_UI_CONFIG.inputArea.maxLength,
|
|
111
107
|
maxQueueSize: config.maxQueueSize ?? 100,
|
|
112
|
-
promptChar: config.promptChar ??
|
|
113
|
-
continuationChar: config.continuationChar ??
|
|
108
|
+
promptChar: config.promptChar ?? DEFAULT_UI_CONFIG.inputArea.promptChar,
|
|
109
|
+
continuationChar: config.continuationChar ?? DEFAULT_UI_CONFIG.inputArea.continuationChar,
|
|
114
110
|
};
|
|
115
111
|
}
|
|
116
112
|
// ===========================================================================
|
|
@@ -189,36 +185,302 @@ export class TerminalInput extends EventEmitter {
|
|
|
189
185
|
if (handled)
|
|
190
186
|
return;
|
|
191
187
|
}
|
|
188
|
+
// Handle '?' for help hint (if buffer is empty)
|
|
189
|
+
if (str === '?' && this.buffer.length === 0) {
|
|
190
|
+
this.emit('showHelp');
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
192
193
|
// Insert printable characters
|
|
193
194
|
if (str && !key?.ctrl && !key?.meta) {
|
|
194
195
|
this.insertText(str);
|
|
195
196
|
}
|
|
196
197
|
}
|
|
198
|
+
// Banner content to write on init (set via setBannerContent before initializeUnifiedUI)
|
|
199
|
+
bannerContent = null;
|
|
200
|
+
/**
|
|
201
|
+
* Set banner content to be written when unified UI initializes.
|
|
202
|
+
*/
|
|
203
|
+
setBannerContent(content) {
|
|
204
|
+
this.bannerContent = content;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Initialize the unified UI system.
|
|
208
|
+
*
|
|
209
|
+
* Layout:
|
|
210
|
+
* 1. Clear screen
|
|
211
|
+
* 2. Write banner at top
|
|
212
|
+
* 3. Track content end position
|
|
213
|
+
* 4. Render floating input area below banner
|
|
214
|
+
*/
|
|
215
|
+
initializeUnifiedUI() {
|
|
216
|
+
if (this.unifiedUIInitialized) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
// Hide cursor during setup
|
|
220
|
+
this.write(ESC.HIDE);
|
|
221
|
+
// Clear screen and go home
|
|
222
|
+
this.write(ESC.HOME);
|
|
223
|
+
this.write(ESC.CLEAR_SCREEN);
|
|
224
|
+
// Write banner at top and track where it ends
|
|
225
|
+
let bannerLines = 0;
|
|
226
|
+
if (this.bannerContent) {
|
|
227
|
+
const lines = this.bannerContent.split('\n');
|
|
228
|
+
bannerLines = lines.length + 2; // +2 for the trailing \n\n
|
|
229
|
+
process.stdout.write(this.bannerContent + '\n\n');
|
|
230
|
+
}
|
|
231
|
+
// Set content end row so input renders right after banner
|
|
232
|
+
this.contentEndRow = bannerLines > 0 ? bannerLines : 1;
|
|
233
|
+
// Mark initialized
|
|
234
|
+
this.unifiedUIInitialized = true;
|
|
235
|
+
// Render floating input area below the banner
|
|
236
|
+
this.renderFloatingInputArea();
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Clear the input area at its tracked position.
|
|
240
|
+
* Returns true if something was cleared.
|
|
241
|
+
*/
|
|
242
|
+
clearInputArea() {
|
|
243
|
+
if (this.inputAreaStartRow > 0 && this.flowModeRenderedLines > 0) {
|
|
244
|
+
for (let i = 0; i < this.flowModeRenderedLines; i++) {
|
|
245
|
+
this.write(ESC.TO(this.inputAreaStartRow + i, 1));
|
|
246
|
+
this.write(ESC.CLEAR_LINE);
|
|
247
|
+
}
|
|
248
|
+
return true;
|
|
249
|
+
}
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Reset input area tracking state.
|
|
254
|
+
*/
|
|
255
|
+
resetInputAreaTracking() {
|
|
256
|
+
this.inputAreaStartRow = 0;
|
|
257
|
+
this.flowModeRenderedLines = 0;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Render chat box - UNIFIED floating approach.
|
|
261
|
+
* Both during and after streaming: chat box floats right below content.
|
|
262
|
+
* Uses scroll region during streaming to protect chat box from content overwrites.
|
|
263
|
+
*/
|
|
264
|
+
renderFloatingInputArea() {
|
|
265
|
+
const { rows, cols } = this.getSize();
|
|
266
|
+
const divider = '─'.repeat(cols - 1);
|
|
267
|
+
const { dim: DIM, reset: R } = UI_COLORS;
|
|
268
|
+
// Calculate lines needed for chat box
|
|
269
|
+
const linesNeeded = 5 + (this.modelInfo ? 1 : 0);
|
|
270
|
+
// FIRST: Clear any previously rendered chat box
|
|
271
|
+
this.clearInputArea();
|
|
272
|
+
// Hide cursor during render
|
|
273
|
+
this.write(ESC.HIDE);
|
|
274
|
+
// Calculate where to render - ALWAYS float right below content
|
|
275
|
+
let startRow;
|
|
276
|
+
if (this.contentEndRow > 0) {
|
|
277
|
+
// Float right below content (no wasted space)
|
|
278
|
+
startRow = this.contentEndRow + 1;
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
// Default: start at row 1 (top of screen)
|
|
282
|
+
startRow = 1;
|
|
283
|
+
}
|
|
284
|
+
// Clamp to ensure chat box fits in terminal
|
|
285
|
+
// (never start so low that chat box would extend past terminal bottom)
|
|
286
|
+
const maxStartRow = rows - linesNeeded + 1;
|
|
287
|
+
startRow = Math.min(startRow, maxStartRow);
|
|
288
|
+
startRow = Math.max(1, startRow);
|
|
289
|
+
// During streaming: set scroll region to protect chat box area
|
|
290
|
+
// Content writes in rows 1 to (startRow - 1), chat box at startRow onwards
|
|
291
|
+
if (this.mode === 'streaming' && startRow > 1) {
|
|
292
|
+
this.write(`\x1b[1;${startRow - 1}r`); // Set scroll region
|
|
293
|
+
}
|
|
294
|
+
else if (this.mode !== 'streaming') {
|
|
295
|
+
this.write('\x1b[r'); // Reset scroll region when not streaming
|
|
296
|
+
}
|
|
297
|
+
// Track this position
|
|
298
|
+
this.inputAreaStartRow = startRow;
|
|
299
|
+
let currentRow = startRow;
|
|
300
|
+
// Status bar
|
|
301
|
+
this.write(ESC.TO(currentRow, 1));
|
|
302
|
+
this.write(this.buildStatusBar(cols));
|
|
303
|
+
currentRow++;
|
|
304
|
+
// Model info line (if set)
|
|
305
|
+
if (this.modelInfo) {
|
|
306
|
+
this.write(ESC.TO(currentRow, 1));
|
|
307
|
+
let modelLine = `${DIM}${this.modelInfo}${R}`;
|
|
308
|
+
if (this.contextUsage !== null) {
|
|
309
|
+
const rem = Math.max(0, 100 - this.contextUsage);
|
|
310
|
+
if (rem < 10)
|
|
311
|
+
modelLine += ` ${UI_COLORS.red}⚠ ctx: ${rem}%${R}`;
|
|
312
|
+
else if (rem < 25)
|
|
313
|
+
modelLine += ` ${UI_COLORS.yellow}! ctx: ${rem}%${R}`;
|
|
314
|
+
else
|
|
315
|
+
modelLine += ` ${DIM}· ctx: ${rem}%${R}`;
|
|
316
|
+
}
|
|
317
|
+
this.write(modelLine);
|
|
318
|
+
currentRow++;
|
|
319
|
+
}
|
|
320
|
+
// Top divider
|
|
321
|
+
this.write(ESC.TO(currentRow, 1));
|
|
322
|
+
this.write(divider);
|
|
323
|
+
currentRow++;
|
|
324
|
+
// Input line with prompt and buffer content
|
|
325
|
+
const { lines, cursorCol } = this.wrapBuffer(cols - 4);
|
|
326
|
+
const displayLine = lines[0] ?? '';
|
|
327
|
+
const inputRow = currentRow;
|
|
328
|
+
this.write(ESC.TO(currentRow, 1));
|
|
329
|
+
this.write(ESC.BG_DARK + ESC.DIM + this.config.promptChar + ESC.RESET);
|
|
330
|
+
this.write(ESC.BG_DARK + displayLine);
|
|
331
|
+
const padding = Math.max(0, cols - this.config.promptChar.length - displayLine.length - 1);
|
|
332
|
+
if (padding > 0)
|
|
333
|
+
this.write(' '.repeat(padding));
|
|
334
|
+
this.write(ESC.RESET);
|
|
335
|
+
currentRow++;
|
|
336
|
+
// Bottom divider
|
|
337
|
+
this.write(ESC.TO(currentRow, 1));
|
|
338
|
+
this.write(divider);
|
|
339
|
+
currentRow++;
|
|
340
|
+
// Mode controls
|
|
341
|
+
this.write(ESC.TO(currentRow, 1));
|
|
342
|
+
this.write(this.buildModeControls(cols));
|
|
343
|
+
// Track lines rendered
|
|
344
|
+
this.flowModeRenderedLines = currentRow - startRow + 1;
|
|
345
|
+
// Position cursor in input line for typing
|
|
346
|
+
this.write(ESC.TO(inputRow, this.config.promptChar.length + 1 + cursorCol));
|
|
347
|
+
// Show cursor
|
|
348
|
+
this.write(ESC.SHOW);
|
|
349
|
+
// Update tracking
|
|
350
|
+
this.lastRenderContent = this.buffer;
|
|
351
|
+
this.lastRenderCursor = this.cursor;
|
|
352
|
+
}
|
|
197
353
|
/**
|
|
198
354
|
* Set the input mode
|
|
199
355
|
*
|
|
200
|
-
*
|
|
356
|
+
* UNIFIED FLOATING: Chat box always floats right below content.
|
|
357
|
+
* During streaming: scroll region protects chat box area.
|
|
358
|
+
* After streaming: scroll region reset, chat box floats below final content.
|
|
201
359
|
*/
|
|
202
360
|
setMode(mode) {
|
|
203
361
|
const prevMode = this.mode;
|
|
204
362
|
this.mode = mode;
|
|
205
363
|
if (mode === 'streaming' && prevMode !== 'streaming') {
|
|
206
|
-
|
|
364
|
+
// Track streaming start time for elapsed display
|
|
365
|
+
this.streamingStartTime = Date.now();
|
|
366
|
+
// Ensure unified UI is initialized
|
|
367
|
+
if (!this.unifiedUIInitialized) {
|
|
368
|
+
this.initializeUnifiedUI();
|
|
369
|
+
}
|
|
207
370
|
this.renderDirty = true;
|
|
208
|
-
this.
|
|
371
|
+
this.scheduleRender();
|
|
209
372
|
}
|
|
210
373
|
else if (mode !== 'streaming' && prevMode === 'streaming') {
|
|
211
|
-
//
|
|
212
|
-
this.
|
|
213
|
-
|
|
374
|
+
// Stop streaming render timer (if any)
|
|
375
|
+
if (this.streamingRenderTimer) {
|
|
376
|
+
clearInterval(this.streamingRenderTimer);
|
|
377
|
+
this.streamingRenderTimer = null;
|
|
378
|
+
}
|
|
379
|
+
// Reset streaming time
|
|
380
|
+
this.streamingStartTime = null;
|
|
381
|
+
// CRITICAL: Reset scroll region when leaving streaming mode
|
|
382
|
+
this.write('\x1b[r');
|
|
383
|
+
// Re-render floating input area below content
|
|
384
|
+
this.renderDirty = true;
|
|
385
|
+
this.scheduleRender();
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Set the row where content ends (for idle mode positioning).
|
|
390
|
+
* Input area will render starting from this row + 1.
|
|
391
|
+
*/
|
|
392
|
+
setContentEndRow(row) {
|
|
393
|
+
this.contentEndRow = Math.max(0, row);
|
|
394
|
+
this.renderDirty = true;
|
|
395
|
+
this.scheduleRender();
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Set available slash commands for auto-complete suggestions.
|
|
399
|
+
*/
|
|
400
|
+
setCommands(commands) {
|
|
401
|
+
this.commandSuggestions = commands;
|
|
402
|
+
this.updateSuggestions();
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Update filtered suggestions based on current input.
|
|
406
|
+
*/
|
|
407
|
+
updateSuggestions() {
|
|
408
|
+
const input = this.buffer.trim();
|
|
409
|
+
// Only show suggestions when input starts with "/"
|
|
410
|
+
if (!input.startsWith('/')) {
|
|
411
|
+
this.showSuggestions = false;
|
|
412
|
+
this.filteredSuggestions = [];
|
|
413
|
+
this.selectedSuggestionIndex = 0;
|
|
414
|
+
return;
|
|
214
415
|
}
|
|
416
|
+
const query = input.toLowerCase();
|
|
417
|
+
this.filteredSuggestions = this.commandSuggestions.filter(cmd => cmd.command.toLowerCase().startsWith(query) ||
|
|
418
|
+
cmd.command.toLowerCase().includes(query.slice(1)));
|
|
419
|
+
// Show suggestions if we have matches
|
|
420
|
+
this.showSuggestions = this.filteredSuggestions.length > 0;
|
|
421
|
+
// Keep selection in bounds
|
|
422
|
+
if (this.selectedSuggestionIndex >= this.filteredSuggestions.length) {
|
|
423
|
+
this.selectedSuggestionIndex = Math.max(0, this.filteredSuggestions.length - 1);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Select next suggestion (arrow down / tab).
|
|
428
|
+
*/
|
|
429
|
+
selectNextSuggestion() {
|
|
430
|
+
if (!this.showSuggestions || this.filteredSuggestions.length === 0)
|
|
431
|
+
return;
|
|
432
|
+
this.selectedSuggestionIndex = (this.selectedSuggestionIndex + 1) % this.filteredSuggestions.length;
|
|
433
|
+
this.renderDirty = true;
|
|
434
|
+
this.scheduleRender();
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Select previous suggestion (arrow up / shift+tab).
|
|
438
|
+
*/
|
|
439
|
+
selectPrevSuggestion() {
|
|
440
|
+
if (!this.showSuggestions || this.filteredSuggestions.length === 0)
|
|
441
|
+
return;
|
|
442
|
+
this.selectedSuggestionIndex = this.selectedSuggestionIndex === 0
|
|
443
|
+
? this.filteredSuggestions.length - 1
|
|
444
|
+
: this.selectedSuggestionIndex - 1;
|
|
445
|
+
this.renderDirty = true;
|
|
446
|
+
this.scheduleRender();
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Accept current suggestion and insert into buffer.
|
|
450
|
+
*/
|
|
451
|
+
acceptSuggestion() {
|
|
452
|
+
if (!this.showSuggestions || this.filteredSuggestions.length === 0)
|
|
453
|
+
return false;
|
|
454
|
+
const selected = this.filteredSuggestions[this.selectedSuggestionIndex];
|
|
455
|
+
if (!selected)
|
|
456
|
+
return false;
|
|
457
|
+
// Replace buffer with selected command
|
|
458
|
+
this.buffer = selected.command + ' ';
|
|
459
|
+
this.cursor = this.buffer.length;
|
|
460
|
+
this.showSuggestions = false;
|
|
461
|
+
this.renderDirty = true;
|
|
462
|
+
this.scheduleRender();
|
|
463
|
+
return true;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Check if suggestions are visible.
|
|
467
|
+
*/
|
|
468
|
+
areSuggestionsVisible() {
|
|
469
|
+
return this.showSuggestions && this.filteredSuggestions.length > 0;
|
|
215
470
|
}
|
|
216
471
|
/**
|
|
217
|
-
*
|
|
218
|
-
* @deprecated Use setContentRow instead
|
|
472
|
+
* Toggle thinking/reasoning mode
|
|
219
473
|
*/
|
|
220
|
-
|
|
221
|
-
|
|
474
|
+
toggleThinking() {
|
|
475
|
+
this.thinkingEnabled = !this.thinkingEnabled;
|
|
476
|
+
this.emit('thinkingToggle', this.thinkingEnabled);
|
|
477
|
+
this.scheduleRender();
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Get thinking enabled state
|
|
481
|
+
*/
|
|
482
|
+
isThinkingEnabled() {
|
|
483
|
+
return this.thinkingEnabled;
|
|
222
484
|
}
|
|
223
485
|
/**
|
|
224
486
|
* Get current mode
|
|
@@ -251,14 +513,17 @@ export class TerminalInput extends EventEmitter {
|
|
|
251
513
|
}
|
|
252
514
|
/**
|
|
253
515
|
* Clear the buffer
|
|
516
|
+
* @param skipRender - If true, don't trigger a re-render (used during submit flow)
|
|
254
517
|
*/
|
|
255
|
-
clear() {
|
|
518
|
+
clear(skipRender = false) {
|
|
256
519
|
this.buffer = '';
|
|
257
520
|
this.cursor = 0;
|
|
258
521
|
this.historyIndex = -1;
|
|
259
522
|
this.tempInput = '';
|
|
260
523
|
this.pastePlaceholders = [];
|
|
261
|
-
|
|
524
|
+
if (!skipRender) {
|
|
525
|
+
this.scheduleRender();
|
|
526
|
+
}
|
|
262
527
|
}
|
|
263
528
|
/**
|
|
264
529
|
* Get queued inputs
|
|
@@ -329,37 +594,6 @@ export class TerminalInput extends EventEmitter {
|
|
|
329
594
|
this.streamingLabel = next;
|
|
330
595
|
this.scheduleRender();
|
|
331
596
|
}
|
|
332
|
-
/**
|
|
333
|
-
* Surface meta status just above the divider (e.g., elapsed time or token usage).
|
|
334
|
-
*/
|
|
335
|
-
setMetaStatus(meta) {
|
|
336
|
-
const nextElapsed = typeof meta.elapsedSeconds === 'number' && Number.isFinite(meta.elapsedSeconds) && meta.elapsedSeconds >= 0
|
|
337
|
-
? Math.floor(meta.elapsedSeconds)
|
|
338
|
-
: null;
|
|
339
|
-
const nextTokens = typeof meta.tokensUsed === 'number' && Number.isFinite(meta.tokensUsed) && meta.tokensUsed >= 0
|
|
340
|
-
? Math.floor(meta.tokensUsed)
|
|
341
|
-
: null;
|
|
342
|
-
const nextLimit = typeof meta.tokenLimit === 'number' && Number.isFinite(meta.tokenLimit) && meta.tokenLimit > 0
|
|
343
|
-
? Math.floor(meta.tokenLimit)
|
|
344
|
-
: null;
|
|
345
|
-
const nextThinking = typeof meta.thinkingMs === 'number' && Number.isFinite(meta.thinkingMs) && meta.thinkingMs >= 0
|
|
346
|
-
? Math.floor(meta.thinkingMs)
|
|
347
|
-
: null;
|
|
348
|
-
const nextThinkingHasContent = !!meta.thinkingHasContent;
|
|
349
|
-
if (this.metaElapsedSeconds === nextElapsed &&
|
|
350
|
-
this.metaTokensUsed === nextTokens &&
|
|
351
|
-
this.metaTokenLimit === nextLimit &&
|
|
352
|
-
this.metaThinkingMs === nextThinking &&
|
|
353
|
-
this.metaThinkingHasContent === nextThinkingHasContent) {
|
|
354
|
-
return;
|
|
355
|
-
}
|
|
356
|
-
this.metaElapsedSeconds = nextElapsed;
|
|
357
|
-
this.metaTokensUsed = nextTokens;
|
|
358
|
-
this.metaTokenLimit = nextLimit;
|
|
359
|
-
this.metaThinkingMs = nextThinking;
|
|
360
|
-
this.metaThinkingHasContent = nextThinkingHasContent;
|
|
361
|
-
this.scheduleRender();
|
|
362
|
-
}
|
|
363
597
|
/**
|
|
364
598
|
* Keep mode toggles (verification/auto-continue) visible in the control bar.
|
|
365
599
|
* Hotkey labels remain stable so the bar looks the same before/during streaming.
|
|
@@ -369,22 +603,26 @@ export class TerminalInput extends EventEmitter {
|
|
|
369
603
|
const nextAutoContinue = !!options.autoContinueEnabled;
|
|
370
604
|
const nextVerifyHotkey = options.verificationHotkey ?? this.verificationHotkey;
|
|
371
605
|
const nextAutoHotkey = options.autoContinueHotkey ?? this.autoContinueHotkey;
|
|
372
|
-
const nextThinkingHotkey = options.thinkingHotkey ?? this.thinkingHotkey;
|
|
373
|
-
const nextThinkingLabel = options.thinkingModeLabel === undefined ? this.thinkingModeLabel : (options.thinkingModeLabel || null);
|
|
374
606
|
if (this.verificationEnabled === nextVerification &&
|
|
375
607
|
this.autoContinueEnabled === nextAutoContinue &&
|
|
376
608
|
this.verificationHotkey === nextVerifyHotkey &&
|
|
377
|
-
this.autoContinueHotkey === nextAutoHotkey
|
|
378
|
-
this.thinkingHotkey === nextThinkingHotkey &&
|
|
379
|
-
this.thinkingModeLabel === nextThinkingLabel) {
|
|
609
|
+
this.autoContinueHotkey === nextAutoHotkey) {
|
|
380
610
|
return;
|
|
381
611
|
}
|
|
382
612
|
this.verificationEnabled = nextVerification;
|
|
383
613
|
this.autoContinueEnabled = nextAutoContinue;
|
|
384
614
|
this.verificationHotkey = nextVerifyHotkey;
|
|
385
615
|
this.autoContinueHotkey = nextAutoHotkey;
|
|
386
|
-
this.
|
|
387
|
-
|
|
616
|
+
this.scheduleRender();
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* Set the model info string (e.g., "OpenAI · gpt-4")
|
|
620
|
+
* This is displayed persistently above the input area.
|
|
621
|
+
*/
|
|
622
|
+
setModelInfo(info) {
|
|
623
|
+
if (this.modelInfo === info)
|
|
624
|
+
return;
|
|
625
|
+
this.modelInfo = info;
|
|
388
626
|
this.scheduleRender();
|
|
389
627
|
}
|
|
390
628
|
/**
|
|
@@ -397,163 +635,33 @@ export class TerminalInput extends EventEmitter {
|
|
|
397
635
|
this.scheduleRender();
|
|
398
636
|
}
|
|
399
637
|
/**
|
|
400
|
-
*
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
const nextModel = options.model?.trim() || null;
|
|
404
|
-
const nextProvider = options.provider?.trim() || null;
|
|
405
|
-
if (this.modelLabel === nextModel && this.providerLabel === nextProvider) {
|
|
406
|
-
return;
|
|
407
|
-
}
|
|
408
|
-
this.modelLabel = nextModel;
|
|
409
|
-
this.providerLabel = nextProvider;
|
|
410
|
-
this.scheduleRender();
|
|
411
|
-
}
|
|
412
|
-
/**
|
|
413
|
-
* Render the floating input area at contentRow.
|
|
414
|
-
*
|
|
415
|
-
* The chat box "floats" - it renders right below the last streamed content.
|
|
416
|
-
* As content is added, contentRow advances, and the chat box moves down.
|
|
417
|
-
* No scroll regions - pure floating behavior.
|
|
638
|
+
* Render the input area.
|
|
639
|
+
* During streaming: renders at terminal bottom (with scroll region)
|
|
640
|
+
* After streaming: renders floating below content
|
|
418
641
|
*/
|
|
419
642
|
render() {
|
|
420
643
|
if (!this.canRender())
|
|
421
644
|
return;
|
|
422
645
|
if (this.isRendering)
|
|
423
646
|
return;
|
|
424
|
-
const streamingActive = this.mode === 'streaming' || isStreamingMode();
|
|
425
|
-
// During streaming, throttle re-renders
|
|
426
|
-
if (streamingActive && this.lastStreamingRender > 0) {
|
|
427
|
-
const elapsed = Date.now() - this.lastStreamingRender;
|
|
428
|
-
const waitMs = Math.max(0, this.streamingRenderInterval - elapsed);
|
|
429
|
-
if (waitMs > 0) {
|
|
430
|
-
this.renderDirty = true;
|
|
431
|
-
this.scheduleStreamingRender(waitMs);
|
|
432
|
-
return;
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
647
|
const shouldSkip = !this.renderDirty &&
|
|
436
648
|
this.buffer === this.lastRenderContent &&
|
|
437
649
|
this.cursor === this.lastRenderCursor;
|
|
438
650
|
this.renderDirty = false;
|
|
651
|
+
// Skip if nothing changed (unless explicitly forced)
|
|
439
652
|
if (shouldSkip) {
|
|
440
653
|
return;
|
|
441
654
|
}
|
|
655
|
+
// If write lock is held, defer render
|
|
442
656
|
if (writeLock.isLocked()) {
|
|
443
657
|
writeLock.safeWrite(() => this.render());
|
|
444
658
|
return;
|
|
445
659
|
}
|
|
446
|
-
this.renderFloatingInputArea();
|
|
447
|
-
}
|
|
448
|
-
/**
|
|
449
|
-
* Core floating input area renderer.
|
|
450
|
-
* Chat box always floats at contentRow (below streamed content).
|
|
451
|
-
* This creates "persistent bottom floating" behavior.
|
|
452
|
-
*/
|
|
453
|
-
renderFloatingInputArea() {
|
|
454
|
-
const { rows, cols } = this.getSize();
|
|
455
|
-
const maxWidth = Math.max(8, cols - 4);
|
|
456
|
-
const streamingActive = this.mode === 'streaming' || isStreamingMode();
|
|
457
|
-
// Wrap buffer into display lines
|
|
458
|
-
const { lines, cursorLine, cursorCol } = this.wrapBuffer(maxWidth);
|
|
459
|
-
const maxVisible = Math.max(1, Math.min(this.config.maxLines, rows - 3));
|
|
460
|
-
const displayLines = Math.min(lines.length, maxVisible);
|
|
461
|
-
const metaLines = this.buildMetaLines(cols - 2);
|
|
462
|
-
// Calculate display window (keep cursor visible)
|
|
463
|
-
let startLine = 0;
|
|
464
|
-
if (lines.length > displayLines) {
|
|
465
|
-
startLine = Math.max(0, cursorLine - displayLines + 1);
|
|
466
|
-
startLine = Math.min(startLine, lines.length - displayLines);
|
|
467
|
-
}
|
|
468
|
-
const visibleLines = lines.slice(startLine, startLine + displayLines);
|
|
469
|
-
const adjustedCursorLine = cursorLine - startLine;
|
|
470
|
-
// Chat box height (must match getChatBoxHeight calculation)
|
|
471
|
-
const chatBoxHeight = metaLines.length + 1 + displayLines + 1;
|
|
472
|
-
// Unified floating: chat box always at contentRow + 1
|
|
473
|
-
// When scroll region is active, contentRow is capped at maxContentRow
|
|
474
|
-
// so chat box ends up at the bottom but still "floats" below content
|
|
475
|
-
const chatBoxStartRow = this.contentRow + 1;
|
|
476
|
-
writeLock.lock('terminalInput.renderFloating');
|
|
477
660
|
this.isRendering = true;
|
|
661
|
+
writeLock.lock('terminalInput.render');
|
|
478
662
|
try {
|
|
479
|
-
//
|
|
480
|
-
this.
|
|
481
|
-
this.write(ESC.RESET);
|
|
482
|
-
// Temporarily reset scroll region to render chat box outside it
|
|
483
|
-
this.write(ESC.RESET_SCROLL);
|
|
484
|
-
// Clear the chat box area
|
|
485
|
-
for (let i = 0; i < chatBoxHeight; i++) {
|
|
486
|
-
this.write(ESC.TO(chatBoxStartRow + i, 1));
|
|
487
|
-
this.write(ESC.CLEAR_LINE);
|
|
488
|
-
}
|
|
489
|
-
let currentRow = chatBoxStartRow;
|
|
490
|
-
// Meta/status header
|
|
491
|
-
for (const metaLine of metaLines) {
|
|
492
|
-
this.write(ESC.TO(currentRow, 1));
|
|
493
|
-
this.write(metaLine);
|
|
494
|
-
currentRow += 1;
|
|
495
|
-
}
|
|
496
|
-
// Separator line
|
|
497
|
-
this.write(ESC.TO(currentRow, 1));
|
|
498
|
-
this.write(renderDivider(cols - 2));
|
|
499
|
-
currentRow += 1;
|
|
500
|
-
// Render input lines
|
|
501
|
-
let finalRow = currentRow;
|
|
502
|
-
let finalCol = 3;
|
|
503
|
-
for (let i = 0; i < visibleLines.length; i++) {
|
|
504
|
-
const rowNum = currentRow + i;
|
|
505
|
-
this.write(ESC.TO(rowNum, 1));
|
|
506
|
-
const line = visibleLines[i] ?? '';
|
|
507
|
-
const isFirstLine = (startLine + i) === 0;
|
|
508
|
-
const isCursorLine = i === adjustedCursorLine;
|
|
509
|
-
this.write(ESC.BG_DARK);
|
|
510
|
-
this.write(ESC.DIM);
|
|
511
|
-
this.write(isFirstLine ? this.config.promptChar : this.config.continuationChar);
|
|
512
|
-
this.write(ESC.RESET);
|
|
513
|
-
this.write(ESC.BG_DARK);
|
|
514
|
-
if (isCursorLine) {
|
|
515
|
-
const col = Math.min(cursorCol, line.length);
|
|
516
|
-
const before = line.slice(0, col);
|
|
517
|
-
const at = col < line.length ? line[col] : ' ';
|
|
518
|
-
const after = col < line.length ? line.slice(col + 1) : '';
|
|
519
|
-
this.write(before);
|
|
520
|
-
this.write(ESC.REVERSE + ESC.BOLD);
|
|
521
|
-
this.write(at);
|
|
522
|
-
this.write(ESC.RESET + ESC.BG_DARK);
|
|
523
|
-
this.write(after);
|
|
524
|
-
finalRow = rowNum;
|
|
525
|
-
finalCol = this.config.promptChar.length + col + 1;
|
|
526
|
-
}
|
|
527
|
-
else {
|
|
528
|
-
this.write(line);
|
|
529
|
-
}
|
|
530
|
-
// Pad to edge
|
|
531
|
-
const lineLen = this.config.promptChar.length + line.length + (isCursorLine && cursorCol >= line.length ? 1 : 0);
|
|
532
|
-
const padding = Math.max(0, cols - lineLen - 1);
|
|
533
|
-
if (padding > 0)
|
|
534
|
-
this.write(' '.repeat(padding));
|
|
535
|
-
this.write(ESC.RESET);
|
|
536
|
-
}
|
|
537
|
-
// Mode controls line
|
|
538
|
-
const controlRow = currentRow + visibleLines.length;
|
|
539
|
-
this.write(ESC.TO(controlRow, 1));
|
|
540
|
-
this.write(this.buildModeControls(cols));
|
|
541
|
-
// Restore scroll region if it was active
|
|
542
|
-
if (this.scrollRegionActive) {
|
|
543
|
-
const scrollBottom = Math.max(1, rows - chatBoxHeight);
|
|
544
|
-
this.write(ESC.SET_SCROLL(1, scrollBottom));
|
|
545
|
-
}
|
|
546
|
-
// Position cursor in input box
|
|
547
|
-
this.write(ESC.TO(finalRow, Math.min(finalCol, cols)));
|
|
548
|
-
this.write(ESC.SHOW);
|
|
549
|
-
// Update state
|
|
550
|
-
this.lastRenderContent = this.buffer;
|
|
551
|
-
this.lastRenderCursor = this.cursor;
|
|
552
|
-
this.lastStreamingRender = streamingActive ? Date.now() : 0;
|
|
553
|
-
if (this.streamingRenderTimer) {
|
|
554
|
-
clearTimeout(this.streamingRenderTimer);
|
|
555
|
-
this.streamingRenderTimer = null;
|
|
556
|
-
}
|
|
663
|
+
// Always render floating right after content (no wasted space)
|
|
664
|
+
this.renderFloatingInputArea();
|
|
557
665
|
}
|
|
558
666
|
finally {
|
|
559
667
|
writeLock.unlock();
|
|
@@ -561,217 +669,99 @@ export class TerminalInput extends EventEmitter {
|
|
|
561
669
|
}
|
|
562
670
|
}
|
|
563
671
|
/**
|
|
564
|
-
* Build
|
|
565
|
-
*
|
|
672
|
+
* Build status bar showing streaming/ready status and key info.
|
|
673
|
+
* This is the TOP line above the input area - minimal Claude Code style.
|
|
566
674
|
*/
|
|
567
|
-
|
|
568
|
-
const
|
|
569
|
-
const
|
|
570
|
-
//
|
|
571
|
-
if (this.
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
if (streamingActive) {
|
|
579
|
-
const parts = [];
|
|
580
|
-
// Essential streaming info
|
|
581
|
-
if (this.metaThinkingMs !== null) {
|
|
582
|
-
parts.push({ text: formatThinking(this.metaThinkingMs, this.metaThinkingHasContent), tone: 'info' });
|
|
583
|
-
}
|
|
584
|
-
if (this.metaElapsedSeconds !== null) {
|
|
585
|
-
parts.push({ text: this.formatElapsedLabel(this.metaElapsedSeconds), tone: 'muted' });
|
|
586
|
-
}
|
|
587
|
-
parts.push({ text: 'esc to stop', tone: 'warn' });
|
|
588
|
-
if (parts.length) {
|
|
589
|
-
lines.push(renderStatusLine(parts, width));
|
|
675
|
+
buildStatusBar(cols) {
|
|
676
|
+
const maxWidth = cols - 2;
|
|
677
|
+
const parts = [];
|
|
678
|
+
// Streaming status with elapsed time (left side)
|
|
679
|
+
if (this.mode === 'streaming') {
|
|
680
|
+
let statusText = '● Streaming';
|
|
681
|
+
if (this.streamingStartTime) {
|
|
682
|
+
const elapsed = Math.floor((Date.now() - this.streamingStartTime) / 1000);
|
|
683
|
+
const mins = Math.floor(elapsed / 60);
|
|
684
|
+
const secs = elapsed % 60;
|
|
685
|
+
statusText += mins > 0 ? ` ${mins}m ${secs}s` : ` ${secs}s`;
|
|
590
686
|
}
|
|
591
|
-
|
|
592
|
-
}
|
|
593
|
-
// Non-streaming: show full status info (model line already added above)
|
|
594
|
-
if (this.metaThinkingMs !== null) {
|
|
595
|
-
const thinkingText = formatThinking(this.metaThinkingMs, this.metaThinkingHasContent);
|
|
596
|
-
lines.push(renderStatusLine([{ text: thinkingText, tone: 'info' }], width));
|
|
687
|
+
parts.push(`\x1b[32m${statusText}\x1b[0m`); // Green
|
|
597
688
|
}
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
statusParts.push({ text: statusLabel, tone: 'info' });
|
|
689
|
+
// Queue indicator during streaming
|
|
690
|
+
if (this.mode === 'streaming' && this.queue.length > 0) {
|
|
691
|
+
parts.push(`\x1b[36mqueued: ${this.queue.length}\x1b[0m`); // Cyan
|
|
602
692
|
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
if (tokensRemaining !== null) {
|
|
608
|
-
statusParts.push({ text: `↓ ${tokensRemaining}`, tone: 'muted' });
|
|
609
|
-
}
|
|
610
|
-
if (statusParts.length) {
|
|
611
|
-
lines.push(renderStatusLine(statusParts, width));
|
|
693
|
+
// Paste indicator
|
|
694
|
+
if (this.pastePlaceholders.length > 0) {
|
|
695
|
+
const totalLines = this.pastePlaceholders.reduce((sum, p) => sum + p.lineCount, 0);
|
|
696
|
+
parts.push(`\x1b[36m📋 ${totalLines}L\x1b[0m`);
|
|
612
697
|
}
|
|
613
|
-
|
|
614
|
-
if (this.
|
|
615
|
-
|
|
616
|
-
const formattedLimit = this.metaTokenLimit ? `/${this.formatTokenCount(this.metaTokenLimit)}` : '';
|
|
617
|
-
usageParts.push({ text: `tokens ${formattedUsed}${formattedLimit}`, tone: 'muted' });
|
|
698
|
+
// Override/warning status
|
|
699
|
+
if (this.overrideStatusMessage) {
|
|
700
|
+
parts.push(`\x1b[33m⚠ ${this.overrideStatusMessage}\x1b[0m`); // Yellow
|
|
618
701
|
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
usageParts.push({ text: `context used ${this.contextUsage}% (${left}% left)`, tone });
|
|
702
|
+
// If idle with empty buffer, show quick shortcuts
|
|
703
|
+
if (this.mode !== 'streaming' && this.buffer.length === 0 && parts.length === 0) {
|
|
704
|
+
return `${ESC.DIM}Type a message or / for commands${ESC.RESET}`;
|
|
623
705
|
}
|
|
624
|
-
|
|
625
|
-
|
|
706
|
+
// Multi-line indicator
|
|
707
|
+
if (this.buffer.includes('\n')) {
|
|
708
|
+
parts.push(`${ESC.DIM}${this.buffer.split('\n').length}L${ESC.RESET}`);
|
|
626
709
|
}
|
|
627
|
-
if (
|
|
628
|
-
|
|
710
|
+
if (parts.length === 0) {
|
|
711
|
+
return ''; // Empty status bar when idle
|
|
629
712
|
}
|
|
630
|
-
|
|
713
|
+
const joined = parts.join(`${ESC.DIM} · ${ESC.RESET}`);
|
|
714
|
+
return joined.slice(0, maxWidth);
|
|
631
715
|
}
|
|
632
716
|
/**
|
|
633
|
-
* Build
|
|
634
|
-
*
|
|
717
|
+
* Build mode controls line showing toggles and context info.
|
|
718
|
+
* This is the BOTTOM line below the input area - Claude Code style layout with erosolar features.
|
|
719
|
+
*
|
|
720
|
+
* Layout: [toggles on left] ... [context info on right]
|
|
635
721
|
*/
|
|
636
722
|
buildModeControls(cols) {
|
|
637
|
-
const
|
|
638
|
-
|
|
639
|
-
const
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
if (this.
|
|
644
|
-
|
|
645
|
-
}
|
|
646
|
-
if (this.statusMessage) {
|
|
647
|
-
leftParts.push({ text: this.statusMessage, tone: this.streamingLabel ? 'muted' : 'info' });
|
|
648
|
-
}
|
|
649
|
-
const editHotkey = this.formatHotkey('shift+tab');
|
|
650
|
-
const editLabel = this.editMode === 'display-edits' ? 'edits: accept' : 'edits: ask';
|
|
651
|
-
const editTone = this.editMode === 'display-edits' ? 'success' : 'muted';
|
|
652
|
-
leftParts.push({ text: `${editHotkey} ${editLabel}`, tone: editTone });
|
|
653
|
-
const verifyHotkey = this.formatHotkey(this.verificationHotkey);
|
|
654
|
-
const verifyLabel = this.verificationEnabled ? 'verify:on' : 'verify:off';
|
|
655
|
-
leftParts.push({ text: `${verifyHotkey} ${verifyLabel}`, tone: this.verificationEnabled ? 'success' : 'muted' });
|
|
656
|
-
const continueHotkey = this.formatHotkey(this.autoContinueHotkey);
|
|
657
|
-
const continueLabel = this.autoContinueEnabled ? 'auto:on' : 'auto:off';
|
|
658
|
-
leftParts.push({ text: `${continueHotkey} ${continueLabel}`, tone: this.autoContinueEnabled ? 'info' : 'muted' });
|
|
659
|
-
if (this.queue.length > 0 && this.mode !== 'streaming') {
|
|
660
|
-
leftParts.push({ text: `queued ${this.queue.length}`, tone: 'info' });
|
|
661
|
-
}
|
|
662
|
-
if (this.buffer.includes('\n')) {
|
|
663
|
-
const lineCount = this.buffer.split('\n').length;
|
|
664
|
-
leftParts.push({ text: `${lineCount} lines`, tone: 'muted' });
|
|
665
|
-
}
|
|
666
|
-
if (this.pastePlaceholders.length > 0) {
|
|
667
|
-
const latest = this.pastePlaceholders[this.pastePlaceholders.length - 1];
|
|
668
|
-
leftParts.push({
|
|
669
|
-
text: `paste #${latest.id} +${latest.lineCount} lines (⌫ to drop)`,
|
|
670
|
-
tone: 'info',
|
|
671
|
-
});
|
|
672
|
-
}
|
|
673
|
-
const contextRemaining = this.computeContextRemaining();
|
|
674
|
-
if (this.thinkingModeLabel) {
|
|
675
|
-
const thinkingHotkey = this.formatHotkey(this.thinkingHotkey);
|
|
676
|
-
rightParts.push({ text: `${thinkingHotkey} thinking:${this.thinkingModeLabel}`, tone: 'info' });
|
|
677
|
-
}
|
|
678
|
-
// Show model in controls only when NOT streaming (during streaming it's in meta lines)
|
|
679
|
-
const streamingActive = this.mode === 'streaming' || isStreamingMode();
|
|
680
|
-
if (this.modelLabel && !streamingActive) {
|
|
681
|
-
const modelText = this.providerLabel ? `${this.modelLabel} @ ${this.providerLabel}` : this.modelLabel;
|
|
682
|
-
rightParts.push({ text: modelText, tone: 'muted' });
|
|
683
|
-
}
|
|
684
|
-
if (contextRemaining !== null) {
|
|
685
|
-
const tone = contextRemaining <= 10 ? 'warn' : 'muted';
|
|
686
|
-
const label = contextRemaining === 0 && this.contextUsage !== null
|
|
687
|
-
? 'Context auto-compact imminent'
|
|
688
|
-
: `Context left until auto-compact: ${contextRemaining}%`;
|
|
689
|
-
rightParts.push({ text: label, tone });
|
|
690
|
-
}
|
|
691
|
-
if (!rightParts.length || width < 60) {
|
|
692
|
-
const merged = rightParts.length ? [...leftParts, ...rightParts] : leftParts;
|
|
693
|
-
return renderStatusLine(merged, width);
|
|
694
|
-
}
|
|
695
|
-
const leftWidth = Math.max(12, Math.floor(width * 0.6));
|
|
696
|
-
const rightWidth = Math.max(14, width - leftWidth - 1);
|
|
697
|
-
const leftText = renderStatusLine(leftParts, leftWidth);
|
|
698
|
-
const rightText = renderStatusLine(rightParts, rightWidth);
|
|
699
|
-
const spacing = Math.max(1, width - this.visibleLength(leftText) - this.visibleLength(rightText));
|
|
700
|
-
return `${leftText}${' '.repeat(spacing)}${rightText}`;
|
|
701
|
-
}
|
|
702
|
-
formatHotkey(hotkey) {
|
|
703
|
-
const normalized = hotkey.trim().toLowerCase();
|
|
704
|
-
if (!normalized)
|
|
705
|
-
return hotkey;
|
|
706
|
-
const parts = normalized.split('+').filter(Boolean);
|
|
707
|
-
const map = {
|
|
708
|
-
shift: '⇧',
|
|
709
|
-
sh: '⇧',
|
|
710
|
-
alt: '⌥',
|
|
711
|
-
option: '⌥',
|
|
712
|
-
opt: '⌥',
|
|
713
|
-
ctrl: '⌃',
|
|
714
|
-
control: '⌃',
|
|
715
|
-
cmd: '⌘',
|
|
716
|
-
meta: '⌘',
|
|
717
|
-
};
|
|
718
|
-
const formatted = parts
|
|
719
|
-
.map((part) => {
|
|
720
|
-
const symbol = map[part];
|
|
721
|
-
if (symbol)
|
|
722
|
-
return symbol;
|
|
723
|
-
return part.length === 1 ? part.toUpperCase() : part.toUpperCase();
|
|
724
|
-
})
|
|
725
|
-
.join('');
|
|
726
|
-
return formatted || hotkey;
|
|
727
|
-
}
|
|
728
|
-
computeContextRemaining() {
|
|
729
|
-
if (this.contextUsage === null) {
|
|
730
|
-
return null;
|
|
723
|
+
const maxWidth = cols - 2;
|
|
724
|
+
// Use schema-defined colors for consistency
|
|
725
|
+
const { green: GREEN, yellow: YELLOW, cyan: CYAN, magenta: MAGENTA, red: RED, dim: DIM, reset: R } = UI_COLORS;
|
|
726
|
+
// Mode toggles with colors (following ModeControlsSchema)
|
|
727
|
+
const toggles = [];
|
|
728
|
+
// Edit mode (green=auto, yellow=ask) - per schema.editMode
|
|
729
|
+
if (this.editMode === 'display-edits') {
|
|
730
|
+
toggles.push(`${GREEN}⏵⏵ auto-edit${R}`);
|
|
731
731
|
}
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
/**
|
|
766
|
-
* Debug-only snapshot used by tests to assert rendered strings without
|
|
767
|
-
* needing a TTY. Not used by production code.
|
|
768
|
-
*/
|
|
769
|
-
getDebugUiSnapshot(width) {
|
|
770
|
-
const cols = Math.max(8, width ?? this.getSize().cols);
|
|
771
|
-
return {
|
|
772
|
-
meta: this.buildMetaLines(cols - 2),
|
|
773
|
-
controls: this.buildModeControls(cols),
|
|
774
|
-
};
|
|
732
|
+
else {
|
|
733
|
+
toggles.push(`${YELLOW}⏸⏸ ask-first${R}`);
|
|
734
|
+
}
|
|
735
|
+
// Thinking mode (cyan when on) - per schema.thinkingMode
|
|
736
|
+
toggles.push(this.thinkingEnabled ? `${CYAN}💭 think${R}` : `${DIM}○ think${R}`);
|
|
737
|
+
// Verification (green when on) - per schema.verificationMode
|
|
738
|
+
toggles.push(this.verificationEnabled ? `${GREEN}✓ verify${R}` : `${DIM}○ verify${R}`);
|
|
739
|
+
// Auto-continue (magenta when on) - per schema.autoContinueMode
|
|
740
|
+
toggles.push(this.autoContinueEnabled ? `${MAGENTA}↻ auto${R}` : `${DIM}○ auto${R}`);
|
|
741
|
+
const leftPart = toggles.join(`${DIM} · ${R}`) + `${DIM} (⇧⇥)${R}`;
|
|
742
|
+
// Context usage with color - per schema.contextUsage thresholds
|
|
743
|
+
let rightPart = '';
|
|
744
|
+
if (this.contextUsage !== null) {
|
|
745
|
+
const rem = Math.max(0, 100 - this.contextUsage);
|
|
746
|
+
// Thresholds: critical < 10%, warning < 25%
|
|
747
|
+
if (rem < 10)
|
|
748
|
+
rightPart = `${RED}⚠ ctx: ${rem}%${R}`;
|
|
749
|
+
else if (rem < 25)
|
|
750
|
+
rightPart = `${YELLOW}! ctx: ${rem}%${R}`;
|
|
751
|
+
else
|
|
752
|
+
rightPart = `${DIM}ctx: ${rem}%${R}`;
|
|
753
|
+
}
|
|
754
|
+
// Calculate visible lengths (strip ANSI)
|
|
755
|
+
const strip = (s) => s.replace(/\x1b\[[0-9;]*m/g, '');
|
|
756
|
+
const leftLen = strip(leftPart).length;
|
|
757
|
+
const rightLen = strip(rightPart).length;
|
|
758
|
+
if (leftLen + rightLen < maxWidth - 4) {
|
|
759
|
+
return `${leftPart}${' '.repeat(maxWidth - leftLen - rightLen)}${rightPart}`;
|
|
760
|
+
}
|
|
761
|
+
if (rightLen > 0 && leftLen + 8 < maxWidth) {
|
|
762
|
+
return `${leftPart} ${rightPart}`;
|
|
763
|
+
}
|
|
764
|
+
return leftPart;
|
|
775
765
|
}
|
|
776
766
|
/**
|
|
777
767
|
* Force a re-render
|
|
@@ -794,115 +784,32 @@ export class TerminalInput extends EventEmitter {
|
|
|
794
784
|
handleResize() {
|
|
795
785
|
this.lastRenderContent = '';
|
|
796
786
|
this.lastRenderCursor = -1;
|
|
797
|
-
this.resetStreamingRenderThrottle();
|
|
798
787
|
this.scheduleRender();
|
|
799
788
|
}
|
|
800
789
|
/**
|
|
801
|
-
*
|
|
802
|
-
*
|
|
803
|
-
*
|
|
804
|
-
* 1. Chat box always floats right below content
|
|
805
|
-
* 2. When terminal fills, scroll region activates to protect chat box
|
|
806
|
-
* 3. Chat box position = min(contentRow + 1, terminalRows - chatBoxHeight + 1)
|
|
807
|
-
*/
|
|
808
|
-
streamContent(content) {
|
|
809
|
-
if (!content)
|
|
810
|
-
return;
|
|
811
|
-
const { rows } = this.getSize();
|
|
812
|
-
const chatBoxHeight = this.getChatBoxHeight();
|
|
813
|
-
const newlines = (content.match(/\n/g) || []).length;
|
|
814
|
-
const maxContentRow = Math.max(1, rows - chatBoxHeight);
|
|
815
|
-
// Will chat box be pushed past terminal bottom?
|
|
816
|
-
const projectedContentRow = this.contentRow + newlines;
|
|
817
|
-
const needsScrolling = projectedContentRow > maxContentRow;
|
|
818
|
-
if (needsScrolling) {
|
|
819
|
-
// Activate scroll region to protect chat box
|
|
820
|
-
if (!this.scrollRegionActive) {
|
|
821
|
-
this.write(ESC.SET_SCROLL(1, maxContentRow));
|
|
822
|
-
this.scrollRegionActive = true;
|
|
823
|
-
}
|
|
824
|
-
// Position at bottom of scroll region - content will scroll up
|
|
825
|
-
this.write(ESC.TO(maxContentRow, 1));
|
|
826
|
-
this.write(content);
|
|
827
|
-
this.contentRow = maxContentRow;
|
|
828
|
-
}
|
|
829
|
-
else {
|
|
830
|
-
// Floating mode - write at current position
|
|
831
|
-
// Disable scroll region if active (to allow natural positioning)
|
|
832
|
-
if (this.scrollRegionActive) {
|
|
833
|
-
this.write(ESC.RESET_SCROLL);
|
|
834
|
-
this.scrollRegionActive = false;
|
|
835
|
-
}
|
|
836
|
-
this.write(ESC.TO(this.contentRow, 1));
|
|
837
|
-
this.write(content);
|
|
838
|
-
this.contentRow = projectedContentRow;
|
|
839
|
-
}
|
|
840
|
-
// Re-render chat box (floats below content)
|
|
841
|
-
this.forceRender();
|
|
842
|
-
}
|
|
843
|
-
/**
|
|
844
|
-
* Enable scroll region to protect chat box area.
|
|
845
|
-
*/
|
|
846
|
-
enableScrollRegion() {
|
|
847
|
-
if (this.scrollRegionActive)
|
|
848
|
-
return;
|
|
849
|
-
const { rows } = this.getSize();
|
|
850
|
-
const chatBoxHeight = this.getChatBoxHeight();
|
|
851
|
-
const scrollBottom = Math.max(1, rows - chatBoxHeight);
|
|
852
|
-
this.write(ESC.SET_SCROLL(1, scrollBottom));
|
|
853
|
-
this.scrollRegionActive = true;
|
|
854
|
-
}
|
|
855
|
-
/**
|
|
856
|
-
* Disable scroll region.
|
|
857
|
-
*/
|
|
858
|
-
disableScrollRegion() {
|
|
859
|
-
if (!this.scrollRegionActive)
|
|
860
|
-
return;
|
|
861
|
-
this.write(ESC.RESET_SCROLL);
|
|
862
|
-
this.scrollRegionActive = false;
|
|
863
|
-
}
|
|
864
|
-
/**
|
|
865
|
-
* Calculate chat box height.
|
|
866
|
-
*/
|
|
867
|
-
getChatBoxHeight() {
|
|
868
|
-
const { cols } = this.getSize();
|
|
869
|
-
const metaLines = this.buildMetaLines(cols - 2);
|
|
870
|
-
// meta + divider + input line + controls + 1 buffer
|
|
871
|
-
return metaLines.length + 1 + 1 + 1 + 1;
|
|
872
|
-
}
|
|
873
|
-
/**
|
|
874
|
-
* @deprecated Use streamContent() instead
|
|
875
|
-
* Register with display's output interceptor - kept for backwards compatibility
|
|
876
|
-
*/
|
|
877
|
-
registerOutputInterceptor(_display) {
|
|
878
|
-
// No-op: Use streamContent() for cleaner floating chat box behavior
|
|
879
|
-
}
|
|
880
|
-
/**
|
|
881
|
-
* @deprecated Use streamContent() instead
|
|
882
|
-
* Write content above the floating chat box.
|
|
883
|
-
*/
|
|
884
|
-
writeToScrollRegion(content) {
|
|
885
|
-
this.streamContent(content);
|
|
886
|
-
}
|
|
887
|
-
/**
|
|
888
|
-
* Reset content position to row 1.
|
|
889
|
-
* Does NOT clear the terminal - content starts from current position.
|
|
890
|
-
*/
|
|
891
|
-
resetContentPosition() {
|
|
892
|
-
this.contentRow = 1;
|
|
893
|
-
}
|
|
894
|
-
/**
|
|
895
|
-
* Set the content row explicitly (used after banner is written).
|
|
896
|
-
* This tells the input where content should start flowing from.
|
|
897
|
-
*/
|
|
898
|
-
setContentRow(row) {
|
|
899
|
-
this.contentRow = Math.max(1, row);
|
|
900
|
-
}
|
|
901
|
-
/**
|
|
902
|
-
* Get the current content row position.
|
|
790
|
+
* Register with display's output interceptor.
|
|
791
|
+
* During streaming: ensures scroll region protects chat box before writes.
|
|
792
|
+
* After streaming: no-op (chat box floats naturally).
|
|
903
793
|
*/
|
|
904
|
-
|
|
905
|
-
|
|
794
|
+
registerOutputInterceptor(display) {
|
|
795
|
+
if (this.outputInterceptorCleanup) {
|
|
796
|
+
this.outputInterceptorCleanup();
|
|
797
|
+
}
|
|
798
|
+
this.outputInterceptorCleanup = display.registerOutputInterceptor({
|
|
799
|
+
beforeWrite: () => {
|
|
800
|
+
// During streaming, ensure scroll region is set to protect chat box
|
|
801
|
+
if (this.mode === 'streaming' && this.inputAreaStartRow > 1) {
|
|
802
|
+
this.write(`\x1b[1;${this.inputAreaStartRow - 1}r`);
|
|
803
|
+
}
|
|
804
|
+
},
|
|
805
|
+
afterWrite: () => {
|
|
806
|
+
// Re-render chat box after content writes during streaming
|
|
807
|
+
if (this.mode === 'streaming') {
|
|
808
|
+
this.renderDirty = true;
|
|
809
|
+
this.scheduleRender();
|
|
810
|
+
}
|
|
811
|
+
},
|
|
812
|
+
});
|
|
906
813
|
}
|
|
907
814
|
/**
|
|
908
815
|
* Dispose and clean up
|
|
@@ -910,10 +817,20 @@ export class TerminalInput extends EventEmitter {
|
|
|
910
817
|
dispose() {
|
|
911
818
|
if (this.disposed)
|
|
912
819
|
return;
|
|
820
|
+
// Clean up streaming render timer
|
|
821
|
+
if (this.streamingRenderTimer) {
|
|
822
|
+
clearInterval(this.streamingRenderTimer);
|
|
823
|
+
this.streamingRenderTimer = null;
|
|
824
|
+
}
|
|
825
|
+
// Clean up output interceptor
|
|
826
|
+
if (this.outputInterceptorCleanup) {
|
|
827
|
+
this.outputInterceptorCleanup();
|
|
828
|
+
this.outputInterceptorCleanup = undefined;
|
|
829
|
+
}
|
|
830
|
+
// Reset scroll region before disposing
|
|
831
|
+
this.write('\x1b[r');
|
|
913
832
|
this.disposed = true;
|
|
914
833
|
this.enabled = false;
|
|
915
|
-
this.disableScrollRegion();
|
|
916
|
-
this.resetStreamingRenderThrottle();
|
|
917
834
|
this.disableBracketedPaste();
|
|
918
835
|
this.buffer = '';
|
|
919
836
|
this.queue = [];
|
|
@@ -1018,7 +935,22 @@ export class TerminalInput extends EventEmitter {
|
|
|
1018
935
|
this.toggleEditMode();
|
|
1019
936
|
return true;
|
|
1020
937
|
}
|
|
1021
|
-
|
|
938
|
+
// Tab: toggle paste expansion if in placeholder, otherwise toggle thinking
|
|
939
|
+
if (this.findPlaceholderAt(this.cursor)) {
|
|
940
|
+
this.togglePasteExpansion();
|
|
941
|
+
}
|
|
942
|
+
else {
|
|
943
|
+
this.toggleThinking();
|
|
944
|
+
}
|
|
945
|
+
return true;
|
|
946
|
+
case 'escape':
|
|
947
|
+
// Esc: interrupt if streaming, otherwise clear buffer
|
|
948
|
+
if (this.mode === 'streaming') {
|
|
949
|
+
this.emit('interrupt');
|
|
950
|
+
}
|
|
951
|
+
else if (this.buffer.length > 0) {
|
|
952
|
+
this.clear();
|
|
953
|
+
}
|
|
1022
954
|
return true;
|
|
1023
955
|
}
|
|
1024
956
|
return false;
|
|
@@ -1036,6 +968,7 @@ export class TerminalInput extends EventEmitter {
|
|
|
1036
968
|
this.insertPlainText(chunk, insertPos);
|
|
1037
969
|
this.cursor = insertPos + chunk.length;
|
|
1038
970
|
this.emit('change', this.buffer);
|
|
971
|
+
this.updateSuggestions();
|
|
1039
972
|
this.scheduleRender();
|
|
1040
973
|
}
|
|
1041
974
|
insertNewline() {
|
|
@@ -1060,6 +993,7 @@ export class TerminalInput extends EventEmitter {
|
|
|
1060
993
|
this.cursor = Math.max(0, this.cursor - 1);
|
|
1061
994
|
}
|
|
1062
995
|
this.emit('change', this.buffer);
|
|
996
|
+
this.updateSuggestions();
|
|
1063
997
|
this.scheduleRender();
|
|
1064
998
|
}
|
|
1065
999
|
deleteForward() {
|
|
@@ -1287,12 +1221,13 @@ export class TerminalInput extends EventEmitter {
|
|
|
1287
1221
|
timestamp: Date.now(),
|
|
1288
1222
|
});
|
|
1289
1223
|
this.emit('queue', text);
|
|
1290
|
-
this.clear(); // Clear immediately for queued input
|
|
1224
|
+
this.clear(); // Clear immediately for queued input, re-render to update queue display
|
|
1291
1225
|
}
|
|
1292
1226
|
else {
|
|
1293
|
-
// In idle mode, clear the input
|
|
1294
|
-
// The
|
|
1295
|
-
|
|
1227
|
+
// In idle mode, clear the input WITHOUT rendering.
|
|
1228
|
+
// The caller will display the user message and start streaming.
|
|
1229
|
+
// We'll render the input area again after streaming ends.
|
|
1230
|
+
this.clear(true); // Skip render - streaming will handle display
|
|
1296
1231
|
this.emit('submit', text);
|
|
1297
1232
|
}
|
|
1298
1233
|
}
|
|
@@ -1309,9 +1244,7 @@ export class TerminalInput extends EventEmitter {
|
|
|
1309
1244
|
if (available <= 0)
|
|
1310
1245
|
return;
|
|
1311
1246
|
const chunk = clean.slice(0, available);
|
|
1312
|
-
|
|
1313
|
-
const isShortMultiline = isMultiline && this.shouldInlineMultiline(chunk);
|
|
1314
|
-
if (isMultiline && !isShortMultiline) {
|
|
1247
|
+
if (isMultilinePaste(chunk)) {
|
|
1315
1248
|
this.insertPastePlaceholder(chunk);
|
|
1316
1249
|
}
|
|
1317
1250
|
else {
|
|
@@ -1447,19 +1380,17 @@ export class TerminalInput extends EventEmitter {
|
|
|
1447
1380
|
this.shiftPlaceholders(position, text.length);
|
|
1448
1381
|
this.buffer = this.buffer.slice(0, position) + text + this.buffer.slice(position);
|
|
1449
1382
|
}
|
|
1450
|
-
shouldInlineMultiline(content) {
|
|
1451
|
-
const lines = content.split('\n').length;
|
|
1452
|
-
const maxInlineLines = 4;
|
|
1453
|
-
const maxInlineChars = 240;
|
|
1454
|
-
return lines <= maxInlineLines && content.length <= maxInlineChars;
|
|
1455
|
-
}
|
|
1456
1383
|
findPlaceholderAt(position) {
|
|
1457
1384
|
return this.pastePlaceholders.find((ph) => position >= ph.start && position < ph.end) ?? null;
|
|
1458
1385
|
}
|
|
1459
|
-
buildPlaceholder(
|
|
1386
|
+
buildPlaceholder(summary) {
|
|
1460
1387
|
const id = ++this.pasteCounter;
|
|
1461
|
-
const
|
|
1462
|
-
|
|
1388
|
+
const lang = summary.language ? ` ${summary.language.toUpperCase()}` : '';
|
|
1389
|
+
// Show first line preview (truncated)
|
|
1390
|
+
const preview = summary.preview.length > 30
|
|
1391
|
+
? `${summary.preview.slice(0, 30)}...`
|
|
1392
|
+
: summary.preview;
|
|
1393
|
+
const placeholder = `[📋 #${id}${lang} ${summary.lineCount}L] "${preview}"`;
|
|
1463
1394
|
return { id, placeholder };
|
|
1464
1395
|
}
|
|
1465
1396
|
insertPastePlaceholder(content) {
|
|
@@ -1467,21 +1398,67 @@ export class TerminalInput extends EventEmitter {
|
|
|
1467
1398
|
if (available <= 0)
|
|
1468
1399
|
return;
|
|
1469
1400
|
const cleanContent = content.slice(0, available);
|
|
1470
|
-
const
|
|
1471
|
-
|
|
1401
|
+
const summary = generatePasteSummary(cleanContent);
|
|
1402
|
+
// For short pastes (< 5 lines), show full content instead of placeholder
|
|
1403
|
+
if (summary.lineCount < 5) {
|
|
1404
|
+
const placeholder = this.findPlaceholderAt(this.cursor);
|
|
1405
|
+
const insertPos = placeholder && this.cursor > placeholder.start ? placeholder.end : this.cursor;
|
|
1406
|
+
this.insertPlainText(cleanContent, insertPos);
|
|
1407
|
+
this.cursor = insertPos + cleanContent.length;
|
|
1408
|
+
return;
|
|
1409
|
+
}
|
|
1410
|
+
const { id, placeholder } = this.buildPlaceholder(summary);
|
|
1472
1411
|
const insertPos = this.cursor;
|
|
1473
1412
|
this.shiftPlaceholders(insertPos, placeholder.length);
|
|
1474
1413
|
this.pastePlaceholders.push({
|
|
1475
1414
|
id,
|
|
1476
1415
|
content: cleanContent,
|
|
1477
|
-
lineCount,
|
|
1416
|
+
lineCount: summary.lineCount,
|
|
1478
1417
|
placeholder,
|
|
1479
1418
|
start: insertPos,
|
|
1480
1419
|
end: insertPos + placeholder.length,
|
|
1420
|
+
summary,
|
|
1421
|
+
expanded: false,
|
|
1481
1422
|
});
|
|
1482
1423
|
this.buffer = this.buffer.slice(0, insertPos) + placeholder + this.buffer.slice(insertPos);
|
|
1483
1424
|
this.cursor = insertPos + placeholder.length;
|
|
1484
1425
|
}
|
|
1426
|
+
/**
|
|
1427
|
+
* Toggle expansion of a paste placeholder at the current cursor position.
|
|
1428
|
+
* When expanded, shows first 3 and last 2 lines of the content.
|
|
1429
|
+
*/
|
|
1430
|
+
togglePasteExpansion() {
|
|
1431
|
+
const placeholder = this.findPlaceholderAt(this.cursor);
|
|
1432
|
+
if (!placeholder)
|
|
1433
|
+
return false;
|
|
1434
|
+
placeholder.expanded = !placeholder.expanded;
|
|
1435
|
+
// Update the placeholder text in buffer
|
|
1436
|
+
const newPlaceholder = placeholder.expanded
|
|
1437
|
+
? this.buildExpandedPlaceholder(placeholder)
|
|
1438
|
+
: this.buildPlaceholder(placeholder.summary).placeholder;
|
|
1439
|
+
const lengthDiff = newPlaceholder.length - placeholder.placeholder.length;
|
|
1440
|
+
// Update buffer
|
|
1441
|
+
this.buffer =
|
|
1442
|
+
this.buffer.slice(0, placeholder.start) +
|
|
1443
|
+
newPlaceholder +
|
|
1444
|
+
this.buffer.slice(placeholder.end);
|
|
1445
|
+
// Update placeholder tracking
|
|
1446
|
+
placeholder.placeholder = newPlaceholder;
|
|
1447
|
+
placeholder.end = placeholder.start + newPlaceholder.length;
|
|
1448
|
+
// Shift other placeholders
|
|
1449
|
+
this.shiftPlaceholders(placeholder.end, lengthDiff, placeholder.id);
|
|
1450
|
+
this.scheduleRender();
|
|
1451
|
+
return true;
|
|
1452
|
+
}
|
|
1453
|
+
buildExpandedPlaceholder(ph) {
|
|
1454
|
+
const lines = ph.content.split('\n');
|
|
1455
|
+
const firstLines = lines.slice(0, 3).map(l => l.slice(0, 60)).join('\n');
|
|
1456
|
+
const lastLines = lines.length > 5
|
|
1457
|
+
? '\n...\n' + lines.slice(-2).map(l => l.slice(0, 60)).join('\n')
|
|
1458
|
+
: '';
|
|
1459
|
+
const lang = ph.summary.language ? ` ${ph.summary.language.toUpperCase()}` : '';
|
|
1460
|
+
return `[📋 #${ph.id}${lang} ${ph.lineCount}L ▼]\n${firstLines}${lastLines}\n[/📋 #${ph.id}]`;
|
|
1461
|
+
}
|
|
1485
1462
|
deletePlaceholder(placeholder) {
|
|
1486
1463
|
const length = placeholder.end - placeholder.start;
|
|
1487
1464
|
this.buffer = this.buffer.slice(0, placeholder.start) + this.buffer.slice(placeholder.end);
|
|
@@ -1489,11 +1466,7 @@ export class TerminalInput extends EventEmitter {
|
|
|
1489
1466
|
this.shiftPlaceholders(placeholder.end, -length, placeholder.id);
|
|
1490
1467
|
this.cursor = placeholder.start;
|
|
1491
1468
|
}
|
|
1492
|
-
updateContextUsage(value
|
|
1493
|
-
if (typeof autoCompactThreshold === 'number' && Number.isFinite(autoCompactThreshold)) {
|
|
1494
|
-
const boundedThreshold = Math.max(1, Math.min(100, Math.round(autoCompactThreshold)));
|
|
1495
|
-
this.contextAutoCompactThreshold = boundedThreshold;
|
|
1496
|
-
}
|
|
1469
|
+
updateContextUsage(value) {
|
|
1497
1470
|
if (value === null || !Number.isFinite(value)) {
|
|
1498
1471
|
this.contextUsage = null;
|
|
1499
1472
|
}
|
|
@@ -1520,22 +1493,6 @@ export class TerminalInput extends EventEmitter {
|
|
|
1520
1493
|
const next = this.editMode === 'display-edits' ? 'ask-permission' : 'display-edits';
|
|
1521
1494
|
this.setEditMode(next);
|
|
1522
1495
|
}
|
|
1523
|
-
scheduleStreamingRender(delayMs) {
|
|
1524
|
-
if (this.streamingRenderTimer)
|
|
1525
|
-
return;
|
|
1526
|
-
const wait = Math.max(16, delayMs);
|
|
1527
|
-
this.streamingRenderTimer = setTimeout(() => {
|
|
1528
|
-
this.streamingRenderTimer = null;
|
|
1529
|
-
this.render();
|
|
1530
|
-
}, wait);
|
|
1531
|
-
}
|
|
1532
|
-
resetStreamingRenderThrottle() {
|
|
1533
|
-
if (this.streamingRenderTimer) {
|
|
1534
|
-
clearTimeout(this.streamingRenderTimer);
|
|
1535
|
-
this.streamingRenderTimer = null;
|
|
1536
|
-
}
|
|
1537
|
-
this.lastStreamingRender = 0;
|
|
1538
|
-
}
|
|
1539
1496
|
scheduleRender() {
|
|
1540
1497
|
if (!this.canRender())
|
|
1541
1498
|
return;
|