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