erosolar-cli 1.7.333 → 1.7.335
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 +166 -235
- 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 +118 -149
- package/dist/shell/terminalInput.d.ts.map +1 -1
- package/dist/shell/terminalInput.js +540 -689
- package/dist/shell/terminalInput.js.map +1 -1
- package/dist/shell/terminalInputAdapter.d.ts +21 -79
- package/dist/shell/terminalInputAdapter.d.ts.map +1 -1
- package/dist/shell/terminalInputAdapter.js +30 -99
- 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,21 +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';
|
|
20
|
-
import { theme } from '../ui/theme.js';
|
|
14
|
+
import { UI_COLORS, DEFAULT_UI_CONFIG, } from '../ui/terminalUISchema.js';
|
|
21
15
|
// ANSI escape codes
|
|
22
16
|
const ESC = {
|
|
23
17
|
// Cursor control
|
|
@@ -27,18 +21,14 @@ const ESC = {
|
|
|
27
21
|
SHOW: '\x1b[?25h',
|
|
28
22
|
TO: (row, col) => `\x1b[${row};${col}H`,
|
|
29
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
|
|
30
29
|
// Line control
|
|
31
30
|
CLEAR_LINE: '\x1b[2K',
|
|
32
31
|
CLEAR_TO_END: '\x1b[0J',
|
|
33
|
-
// Screen control
|
|
34
|
-
HOME: '\x1b[H',
|
|
35
|
-
CLEAR_SCREEN: '\x1b[2J',
|
|
36
|
-
// Alternate screen buffer (like vim/tmux)
|
|
37
|
-
ENTER_ALT_SCREEN: '\x1b[?1049h',
|
|
38
|
-
EXIT_ALT_SCREEN: '\x1b[?1049l',
|
|
39
|
-
// Scroll region
|
|
40
|
-
SET_SCROLL: (top, bottom) => `\x1b[${top};${bottom}r`,
|
|
41
|
-
RESET_SCROLL: '\x1b[r',
|
|
42
32
|
// Style
|
|
43
33
|
RESET: '\x1b[0m',
|
|
44
34
|
DIM: '\x1b[2m',
|
|
@@ -78,46 +68,47 @@ export class TerminalInput extends EventEmitter {
|
|
|
78
68
|
statusMessage = null;
|
|
79
69
|
overrideStatusMessage = null; // Secondary status (warnings, etc.)
|
|
80
70
|
streamingLabel = null; // Streaming progress indicator
|
|
81
|
-
metaElapsedSeconds = null; // Optional elapsed time for header line
|
|
82
|
-
metaTokensUsed = null; // Optional token usage
|
|
83
|
-
metaTokenLimit = null; // Optional token window
|
|
84
|
-
metaThinkingMs = null; // Optional thinking duration
|
|
85
|
-
metaThinkingHasContent = false; // Whether collapsed thinking content exists
|
|
86
71
|
lastRenderContent = '';
|
|
87
72
|
lastRenderCursor = -1;
|
|
88
73
|
renderDirty = false;
|
|
89
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;
|
|
90
83
|
// Lifecycle
|
|
91
84
|
disposed = false;
|
|
92
85
|
enabled = true;
|
|
93
86
|
contextUsage = null;
|
|
94
|
-
contextAutoCompactThreshold = 90;
|
|
95
|
-
// Track current content row (starts at top, moves down)
|
|
96
|
-
contentRow = 1;
|
|
97
|
-
// Track if scroll region is currently active
|
|
98
|
-
scrollRegionActive = false;
|
|
99
|
-
thinkingModeLabel = null;
|
|
100
87
|
editMode = 'display-edits';
|
|
101
88
|
verificationEnabled = true;
|
|
102
89
|
autoContinueEnabled = false;
|
|
103
90
|
verificationHotkey = 'alt+v';
|
|
104
91
|
autoContinueHotkey = 'alt+c';
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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)
|
|
111
99
|
streamingRenderTimer = null;
|
|
100
|
+
// Unified UI initialization flag
|
|
101
|
+
unifiedUIInitialized = false;
|
|
112
102
|
constructor(writeStream = process.stdout, config = {}) {
|
|
113
103
|
super();
|
|
114
104
|
this.out = writeStream;
|
|
105
|
+
// Use schema defaults for configuration consistency
|
|
115
106
|
this.config = {
|
|
116
|
-
maxLines: config.maxLines ??
|
|
117
|
-
maxLength: config.maxLength ??
|
|
107
|
+
maxLines: config.maxLines ?? DEFAULT_UI_CONFIG.inputArea.maxLines,
|
|
108
|
+
maxLength: config.maxLength ?? DEFAULT_UI_CONFIG.inputArea.maxLength,
|
|
118
109
|
maxQueueSize: config.maxQueueSize ?? 100,
|
|
119
|
-
promptChar: config.promptChar ??
|
|
120
|
-
continuationChar: config.continuationChar ??
|
|
110
|
+
promptChar: config.promptChar ?? DEFAULT_UI_CONFIG.inputArea.promptChar,
|
|
111
|
+
continuationChar: config.continuationChar ?? DEFAULT_UI_CONFIG.inputArea.continuationChar,
|
|
121
112
|
};
|
|
122
113
|
}
|
|
123
114
|
// ===========================================================================
|
|
@@ -196,36 +187,290 @@ export class TerminalInput extends EventEmitter {
|
|
|
196
187
|
if (handled)
|
|
197
188
|
return;
|
|
198
189
|
}
|
|
190
|
+
// Handle '?' for help hint (if buffer is empty)
|
|
191
|
+
if (str === '?' && this.buffer.length === 0) {
|
|
192
|
+
this.emit('showHelp');
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
199
195
|
// Insert printable characters
|
|
200
196
|
if (str && !key?.ctrl && !key?.meta) {
|
|
201
197
|
this.insertText(str);
|
|
202
198
|
}
|
|
203
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
|
+
// Content ends at same row initially (no content yet)
|
|
238
|
+
this.contentEndRow = this.contentCursorRow - 1;
|
|
239
|
+
// Mark initialized
|
|
240
|
+
this.unifiedUIInitialized = true;
|
|
241
|
+
// Render floating chat box below content
|
|
242
|
+
this.renderFloatingInputArea();
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Clear the input area at its tracked position.
|
|
246
|
+
* Returns true if something was cleared.
|
|
247
|
+
*/
|
|
248
|
+
clearInputArea() {
|
|
249
|
+
if (this.inputAreaStartRow > 0 && this.flowModeRenderedLines > 0) {
|
|
250
|
+
for (let i = 0; i < this.flowModeRenderedLines; i++) {
|
|
251
|
+
this.write(ESC.TO(this.inputAreaStartRow + i, 1));
|
|
252
|
+
this.write(ESC.CLEAR_LINE);
|
|
253
|
+
}
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Reset input area tracking state.
|
|
260
|
+
*/
|
|
261
|
+
resetInputAreaTracking() {
|
|
262
|
+
this.inputAreaStartRow = 0;
|
|
263
|
+
this.flowModeRenderedLines = 0;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Render chat box - FLOATING below content (no scroll regions).
|
|
267
|
+
* Chat box appears right after content and moves down as content grows.
|
|
268
|
+
* Content and banner scroll naturally off the top of the screen.
|
|
269
|
+
*/
|
|
270
|
+
renderFloatingInputArea() {
|
|
271
|
+
const { 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
|
+
// Chat box starts right after content
|
|
277
|
+
const chatBoxStartRow = this.contentEndRow + 1;
|
|
278
|
+
// Hide cursor during render
|
|
279
|
+
this.write(ESC.HIDE);
|
|
280
|
+
// Track position
|
|
281
|
+
this.inputAreaStartRow = chatBoxStartRow;
|
|
282
|
+
let currentRow = chatBoxStartRow;
|
|
283
|
+
// Helper to write a line at absolute position (clears then writes)
|
|
284
|
+
const writeLine = (content) => {
|
|
285
|
+
this.write(ESC.TO(currentRow, 1));
|
|
286
|
+
this.write(ESC.CLEAR_LINE);
|
|
287
|
+
this.write(content);
|
|
288
|
+
currentRow++;
|
|
289
|
+
};
|
|
290
|
+
// Top divider
|
|
291
|
+
writeLine(`${DIM}${divider}${R}`);
|
|
292
|
+
// Input line with > prompt
|
|
293
|
+
const { lines, cursorCol } = this.wrapBuffer(cols - 3);
|
|
294
|
+
const displayLine = lines[0] ?? '';
|
|
295
|
+
const inputRow = currentRow;
|
|
296
|
+
writeLine(`${DIM}>${R} ${displayLine}`);
|
|
297
|
+
// Bottom divider
|
|
298
|
+
writeLine(`${DIM}${divider}${R}`);
|
|
299
|
+
// Mode controls line - Claude Code style
|
|
300
|
+
this.write(ESC.TO(currentRow, 1));
|
|
301
|
+
this.write(ESC.CLEAR_LINE);
|
|
302
|
+
this.write(this.buildClaudeStyleControls(cols));
|
|
303
|
+
// Track lines rendered
|
|
304
|
+
this.flowModeRenderedLines = chatBoxHeight;
|
|
305
|
+
// Position cursor at input line for typing
|
|
306
|
+
this.write(ESC.TO(inputRow, 3 + cursorCol));
|
|
307
|
+
// Show cursor
|
|
308
|
+
this.write(ESC.SHOW);
|
|
309
|
+
// Update tracking
|
|
310
|
+
this.lastRenderContent = this.buffer;
|
|
311
|
+
this.lastRenderCursor = this.cursor;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Build Claude Code style controls line.
|
|
315
|
+
* Shows: edit mode indicator (shift+tab to cycle)
|
|
316
|
+
*/
|
|
317
|
+
buildClaudeStyleControls(cols) {
|
|
318
|
+
const { dim: DIM, green: GREEN, yellow: YELLOW, cyan: CYAN, reset: R } = UI_COLORS;
|
|
319
|
+
// Edit mode indicator
|
|
320
|
+
let editModeText;
|
|
321
|
+
if (this.editMode === 'display-edits') {
|
|
322
|
+
editModeText = `${GREEN}⏵⏵${R} accept edits on`;
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
editModeText = `${YELLOW}⏸⏸${R} ask before edit`;
|
|
326
|
+
}
|
|
327
|
+
// Build controls line
|
|
328
|
+
const parts = [` ${editModeText} ${DIM}(shift+tab to cycle)${R}`];
|
|
329
|
+
// Add thinking mode if enabled
|
|
330
|
+
if (this.thinkingEnabled) {
|
|
331
|
+
parts.push(`${CYAN}💭${R}`);
|
|
332
|
+
}
|
|
333
|
+
// Add context usage if available
|
|
334
|
+
if (this.contextUsage !== null) {
|
|
335
|
+
const rem = Math.max(0, 100 - this.contextUsage);
|
|
336
|
+
if (rem < 10) {
|
|
337
|
+
parts.push(`${UI_COLORS.red}ctx ${rem}%${R}`);
|
|
338
|
+
}
|
|
339
|
+
else if (rem < 25) {
|
|
340
|
+
parts.push(`${YELLOW}ctx ${rem}%${R}`);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return parts.join(` ${DIM}·${R} `);
|
|
344
|
+
}
|
|
204
345
|
/**
|
|
205
346
|
* Set the input mode
|
|
206
347
|
*
|
|
207
|
-
*
|
|
348
|
+
* BOTTOM PINNED with SSE: Chat box stays at terminal bottom.
|
|
349
|
+
* Scroll region protects chat box, content scrolls above it.
|
|
208
350
|
*/
|
|
209
351
|
setMode(mode) {
|
|
210
352
|
const prevMode = this.mode;
|
|
211
353
|
this.mode = mode;
|
|
212
354
|
if (mode === 'streaming' && prevMode !== 'streaming') {
|
|
213
|
-
|
|
355
|
+
// Track streaming start time for elapsed display
|
|
356
|
+
this.streamingStartTime = Date.now();
|
|
357
|
+
// Ensure unified UI is initialized
|
|
358
|
+
if (!this.unifiedUIInitialized) {
|
|
359
|
+
this.initializeUnifiedUI();
|
|
360
|
+
}
|
|
361
|
+
// Re-render to ensure scroll region is set correctly
|
|
214
362
|
this.renderDirty = true;
|
|
215
|
-
this.
|
|
363
|
+
this.scheduleRender();
|
|
216
364
|
}
|
|
217
365
|
else if (mode !== 'streaming' && prevMode === 'streaming') {
|
|
218
|
-
//
|
|
219
|
-
this.
|
|
220
|
-
|
|
366
|
+
// Stop streaming render timer (if any)
|
|
367
|
+
if (this.streamingRenderTimer) {
|
|
368
|
+
clearInterval(this.streamingRenderTimer);
|
|
369
|
+
this.streamingRenderTimer = null;
|
|
370
|
+
}
|
|
371
|
+
// Reset streaming time
|
|
372
|
+
this.streamingStartTime = null;
|
|
373
|
+
// Re-render chat box
|
|
374
|
+
this.renderDirty = true;
|
|
375
|
+
this.scheduleRender();
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Set the row where content ends (for idle mode positioning).
|
|
380
|
+
* Input area will render starting from this row + 1.
|
|
381
|
+
*/
|
|
382
|
+
setContentEndRow(row) {
|
|
383
|
+
this.contentEndRow = Math.max(0, row);
|
|
384
|
+
this.renderDirty = true;
|
|
385
|
+
this.scheduleRender();
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Set available slash commands for auto-complete suggestions.
|
|
389
|
+
*/
|
|
390
|
+
setCommands(commands) {
|
|
391
|
+
this.commandSuggestions = commands;
|
|
392
|
+
this.updateSuggestions();
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Update filtered suggestions based on current input.
|
|
396
|
+
*/
|
|
397
|
+
updateSuggestions() {
|
|
398
|
+
const input = this.buffer.trim();
|
|
399
|
+
// Only show suggestions when input starts with "/"
|
|
400
|
+
if (!input.startsWith('/')) {
|
|
401
|
+
this.showSuggestions = false;
|
|
402
|
+
this.filteredSuggestions = [];
|
|
403
|
+
this.selectedSuggestionIndex = 0;
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
const query = input.toLowerCase();
|
|
407
|
+
this.filteredSuggestions = this.commandSuggestions.filter(cmd => cmd.command.toLowerCase().startsWith(query) ||
|
|
408
|
+
cmd.command.toLowerCase().includes(query.slice(1)));
|
|
409
|
+
// Show suggestions if we have matches
|
|
410
|
+
this.showSuggestions = this.filteredSuggestions.length > 0;
|
|
411
|
+
// Keep selection in bounds
|
|
412
|
+
if (this.selectedSuggestionIndex >= this.filteredSuggestions.length) {
|
|
413
|
+
this.selectedSuggestionIndex = Math.max(0, this.filteredSuggestions.length - 1);
|
|
221
414
|
}
|
|
222
415
|
}
|
|
223
416
|
/**
|
|
224
|
-
*
|
|
225
|
-
* @deprecated Use setContentRow instead
|
|
417
|
+
* Select next suggestion (arrow down / tab).
|
|
226
418
|
*/
|
|
227
|
-
|
|
228
|
-
|
|
419
|
+
selectNextSuggestion() {
|
|
420
|
+
if (!this.showSuggestions || this.filteredSuggestions.length === 0)
|
|
421
|
+
return;
|
|
422
|
+
this.selectedSuggestionIndex = (this.selectedSuggestionIndex + 1) % this.filteredSuggestions.length;
|
|
423
|
+
this.renderDirty = true;
|
|
424
|
+
this.scheduleRender();
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Select previous suggestion (arrow up / shift+tab).
|
|
428
|
+
*/
|
|
429
|
+
selectPrevSuggestion() {
|
|
430
|
+
if (!this.showSuggestions || this.filteredSuggestions.length === 0)
|
|
431
|
+
return;
|
|
432
|
+
this.selectedSuggestionIndex = this.selectedSuggestionIndex === 0
|
|
433
|
+
? this.filteredSuggestions.length - 1
|
|
434
|
+
: this.selectedSuggestionIndex - 1;
|
|
435
|
+
this.renderDirty = true;
|
|
436
|
+
this.scheduleRender();
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Accept current suggestion and insert into buffer.
|
|
440
|
+
*/
|
|
441
|
+
acceptSuggestion() {
|
|
442
|
+
if (!this.showSuggestions || this.filteredSuggestions.length === 0)
|
|
443
|
+
return false;
|
|
444
|
+
const selected = this.filteredSuggestions[this.selectedSuggestionIndex];
|
|
445
|
+
if (!selected)
|
|
446
|
+
return false;
|
|
447
|
+
// Replace buffer with selected command
|
|
448
|
+
this.buffer = selected.command + ' ';
|
|
449
|
+
this.cursor = this.buffer.length;
|
|
450
|
+
this.showSuggestions = false;
|
|
451
|
+
this.renderDirty = true;
|
|
452
|
+
this.scheduleRender();
|
|
453
|
+
return true;
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Check if suggestions are visible.
|
|
457
|
+
*/
|
|
458
|
+
areSuggestionsVisible() {
|
|
459
|
+
return this.showSuggestions && this.filteredSuggestions.length > 0;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Toggle thinking/reasoning mode
|
|
463
|
+
*/
|
|
464
|
+
toggleThinking() {
|
|
465
|
+
this.thinkingEnabled = !this.thinkingEnabled;
|
|
466
|
+
this.emit('thinkingToggle', this.thinkingEnabled);
|
|
467
|
+
this.scheduleRender();
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Get thinking enabled state
|
|
471
|
+
*/
|
|
472
|
+
isThinkingEnabled() {
|
|
473
|
+
return this.thinkingEnabled;
|
|
229
474
|
}
|
|
230
475
|
/**
|
|
231
476
|
* Get current mode
|
|
@@ -258,14 +503,17 @@ export class TerminalInput extends EventEmitter {
|
|
|
258
503
|
}
|
|
259
504
|
/**
|
|
260
505
|
* Clear the buffer
|
|
506
|
+
* @param skipRender - If true, don't trigger a re-render (used during submit flow)
|
|
261
507
|
*/
|
|
262
|
-
clear() {
|
|
508
|
+
clear(skipRender = false) {
|
|
263
509
|
this.buffer = '';
|
|
264
510
|
this.cursor = 0;
|
|
265
511
|
this.historyIndex = -1;
|
|
266
512
|
this.tempInput = '';
|
|
267
513
|
this.pastePlaceholders = [];
|
|
268
|
-
|
|
514
|
+
if (!skipRender) {
|
|
515
|
+
this.scheduleRender();
|
|
516
|
+
}
|
|
269
517
|
}
|
|
270
518
|
/**
|
|
271
519
|
* Get queued inputs
|
|
@@ -336,37 +584,6 @@ export class TerminalInput extends EventEmitter {
|
|
|
336
584
|
this.streamingLabel = next;
|
|
337
585
|
this.scheduleRender();
|
|
338
586
|
}
|
|
339
|
-
/**
|
|
340
|
-
* Surface meta status just above the divider (e.g., elapsed time or token usage).
|
|
341
|
-
*/
|
|
342
|
-
setMetaStatus(meta) {
|
|
343
|
-
const nextElapsed = typeof meta.elapsedSeconds === 'number' && Number.isFinite(meta.elapsedSeconds) && meta.elapsedSeconds >= 0
|
|
344
|
-
? Math.floor(meta.elapsedSeconds)
|
|
345
|
-
: null;
|
|
346
|
-
const nextTokens = typeof meta.tokensUsed === 'number' && Number.isFinite(meta.tokensUsed) && meta.tokensUsed >= 0
|
|
347
|
-
? Math.floor(meta.tokensUsed)
|
|
348
|
-
: null;
|
|
349
|
-
const nextLimit = typeof meta.tokenLimit === 'number' && Number.isFinite(meta.tokenLimit) && meta.tokenLimit > 0
|
|
350
|
-
? Math.floor(meta.tokenLimit)
|
|
351
|
-
: null;
|
|
352
|
-
const nextThinking = typeof meta.thinkingMs === 'number' && Number.isFinite(meta.thinkingMs) && meta.thinkingMs >= 0
|
|
353
|
-
? Math.floor(meta.thinkingMs)
|
|
354
|
-
: null;
|
|
355
|
-
const nextThinkingHasContent = !!meta.thinkingHasContent;
|
|
356
|
-
if (this.metaElapsedSeconds === nextElapsed &&
|
|
357
|
-
this.metaTokensUsed === nextTokens &&
|
|
358
|
-
this.metaTokenLimit === nextLimit &&
|
|
359
|
-
this.metaThinkingMs === nextThinking &&
|
|
360
|
-
this.metaThinkingHasContent === nextThinkingHasContent) {
|
|
361
|
-
return;
|
|
362
|
-
}
|
|
363
|
-
this.metaElapsedSeconds = nextElapsed;
|
|
364
|
-
this.metaTokensUsed = nextTokens;
|
|
365
|
-
this.metaTokenLimit = nextLimit;
|
|
366
|
-
this.metaThinkingMs = nextThinking;
|
|
367
|
-
this.metaThinkingHasContent = nextThinkingHasContent;
|
|
368
|
-
this.scheduleRender();
|
|
369
|
-
}
|
|
370
587
|
/**
|
|
371
588
|
* Keep mode toggles (verification/auto-continue) visible in the control bar.
|
|
372
589
|
* Hotkey labels remain stable so the bar looks the same before/during streaming.
|
|
@@ -376,22 +593,26 @@ export class TerminalInput extends EventEmitter {
|
|
|
376
593
|
const nextAutoContinue = !!options.autoContinueEnabled;
|
|
377
594
|
const nextVerifyHotkey = options.verificationHotkey ?? this.verificationHotkey;
|
|
378
595
|
const nextAutoHotkey = options.autoContinueHotkey ?? this.autoContinueHotkey;
|
|
379
|
-
const nextThinkingHotkey = options.thinkingHotkey ?? this.thinkingHotkey;
|
|
380
|
-
const nextThinkingLabel = options.thinkingModeLabel === undefined ? this.thinkingModeLabel : (options.thinkingModeLabel || null);
|
|
381
596
|
if (this.verificationEnabled === nextVerification &&
|
|
382
597
|
this.autoContinueEnabled === nextAutoContinue &&
|
|
383
598
|
this.verificationHotkey === nextVerifyHotkey &&
|
|
384
|
-
this.autoContinueHotkey === nextAutoHotkey
|
|
385
|
-
this.thinkingHotkey === nextThinkingHotkey &&
|
|
386
|
-
this.thinkingModeLabel === nextThinkingLabel) {
|
|
599
|
+
this.autoContinueHotkey === nextAutoHotkey) {
|
|
387
600
|
return;
|
|
388
601
|
}
|
|
389
602
|
this.verificationEnabled = nextVerification;
|
|
390
603
|
this.autoContinueEnabled = nextAutoContinue;
|
|
391
604
|
this.verificationHotkey = nextVerifyHotkey;
|
|
392
605
|
this.autoContinueHotkey = nextAutoHotkey;
|
|
393
|
-
this.
|
|
394
|
-
|
|
606
|
+
this.scheduleRender();
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Set the model info string (e.g., "OpenAI · gpt-4")
|
|
610
|
+
* This is displayed persistently above the input area.
|
|
611
|
+
*/
|
|
612
|
+
setModelInfo(info) {
|
|
613
|
+
if (this.modelInfo === info)
|
|
614
|
+
return;
|
|
615
|
+
this.modelInfo = info;
|
|
395
616
|
this.scheduleRender();
|
|
396
617
|
}
|
|
397
618
|
/**
|
|
@@ -404,161 +625,33 @@ export class TerminalInput extends EventEmitter {
|
|
|
404
625
|
this.scheduleRender();
|
|
405
626
|
}
|
|
406
627
|
/**
|
|
407
|
-
*
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
const nextModel = options.model?.trim() || null;
|
|
411
|
-
const nextProvider = options.provider?.trim() || null;
|
|
412
|
-
if (this.modelLabel === nextModel && this.providerLabel === nextProvider) {
|
|
413
|
-
return;
|
|
414
|
-
}
|
|
415
|
-
this.modelLabel = nextModel;
|
|
416
|
-
this.providerLabel = nextProvider;
|
|
417
|
-
this.scheduleRender();
|
|
418
|
-
}
|
|
419
|
-
/**
|
|
420
|
-
* Render the floating input area at contentRow.
|
|
421
|
-
*
|
|
422
|
-
* The chat box "floats" - it renders right below the last streamed content.
|
|
423
|
-
* As content is added, contentRow advances, and the chat box moves down.
|
|
424
|
-
* No scroll regions - pure floating behavior.
|
|
628
|
+
* Render the input area.
|
|
629
|
+
* During streaming: renders at terminal bottom (with scroll region)
|
|
630
|
+
* After streaming: renders floating below content
|
|
425
631
|
*/
|
|
426
632
|
render() {
|
|
427
633
|
if (!this.canRender())
|
|
428
634
|
return;
|
|
429
635
|
if (this.isRendering)
|
|
430
636
|
return;
|
|
431
|
-
const streamingActive = this.mode === 'streaming' || isStreamingMode();
|
|
432
|
-
// During streaming, throttle re-renders
|
|
433
|
-
if (streamingActive && this.lastStreamingRender > 0) {
|
|
434
|
-
const elapsed = Date.now() - this.lastStreamingRender;
|
|
435
|
-
const waitMs = Math.max(0, this.streamingRenderInterval - elapsed);
|
|
436
|
-
if (waitMs > 0) {
|
|
437
|
-
this.renderDirty = true;
|
|
438
|
-
this.scheduleStreamingRender(waitMs);
|
|
439
|
-
return;
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
637
|
const shouldSkip = !this.renderDirty &&
|
|
443
638
|
this.buffer === this.lastRenderContent &&
|
|
444
639
|
this.cursor === this.lastRenderCursor;
|
|
445
640
|
this.renderDirty = false;
|
|
641
|
+
// Skip if nothing changed (unless explicitly forced)
|
|
446
642
|
if (shouldSkip) {
|
|
447
643
|
return;
|
|
448
644
|
}
|
|
645
|
+
// If write lock is held, defer render
|
|
449
646
|
if (writeLock.isLocked()) {
|
|
450
647
|
writeLock.safeWrite(() => this.render());
|
|
451
648
|
return;
|
|
452
649
|
}
|
|
453
|
-
this.renderFloatingInputArea();
|
|
454
|
-
}
|
|
455
|
-
/**
|
|
456
|
-
* Core floating input area renderer.
|
|
457
|
-
* Chat box always floats at contentRow (below streamed content).
|
|
458
|
-
* This creates "persistent bottom floating" behavior.
|
|
459
|
-
*/
|
|
460
|
-
renderFloatingInputArea() {
|
|
461
|
-
const { rows, cols } = this.getSize();
|
|
462
|
-
const maxWidth = Math.max(8, cols - 4);
|
|
463
|
-
const streamingActive = this.mode === 'streaming' || isStreamingMode();
|
|
464
|
-
// Wrap buffer into display lines
|
|
465
|
-
const { lines, cursorLine, cursorCol } = this.wrapBuffer(maxWidth);
|
|
466
|
-
const maxVisible = Math.max(1, Math.min(this.config.maxLines, rows - 3));
|
|
467
|
-
const displayLines = Math.min(lines.length, maxVisible);
|
|
468
|
-
const metaLines = this.buildMetaLines(cols - 2);
|
|
469
|
-
// Calculate display window (keep cursor visible)
|
|
470
|
-
let startLine = 0;
|
|
471
|
-
if (lines.length > displayLines) {
|
|
472
|
-
startLine = Math.max(0, cursorLine - displayLines + 1);
|
|
473
|
-
startLine = Math.min(startLine, lines.length - displayLines);
|
|
474
|
-
}
|
|
475
|
-
const visibleLines = lines.slice(startLine, startLine + displayLines);
|
|
476
|
-
const adjustedCursorLine = cursorLine - startLine;
|
|
477
|
-
// Chat box height (must match getChatBoxHeight calculation)
|
|
478
|
-
const chatBoxHeight = metaLines.length + 1 + displayLines + 1;
|
|
479
|
-
// During streaming, use renderChatBoxAtBottom instead
|
|
480
|
-
if (this.scrollRegionActive) {
|
|
481
|
-
return;
|
|
482
|
-
}
|
|
483
|
-
// Float chat box below content (not pinned to bottom)
|
|
484
|
-
const chatBoxStartRow = Math.max(1, this.contentRow + 1);
|
|
485
|
-
writeLock.lock('terminalInput.renderFloating');
|
|
486
650
|
this.isRendering = true;
|
|
651
|
+
writeLock.lock('terminalInput.render');
|
|
487
652
|
try {
|
|
488
|
-
//
|
|
489
|
-
this.
|
|
490
|
-
this.write(ESC.RESET);
|
|
491
|
-
// Clear the chat box area
|
|
492
|
-
for (let i = 0; i < chatBoxHeight; i++) {
|
|
493
|
-
const row = chatBoxStartRow + i;
|
|
494
|
-
if (row <= rows) {
|
|
495
|
-
this.write(ESC.TO(row, 1));
|
|
496
|
-
this.write(ESC.CLEAR_LINE);
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
let currentRow = chatBoxStartRow;
|
|
500
|
-
// Meta/status header
|
|
501
|
-
for (const metaLine of metaLines) {
|
|
502
|
-
this.write(ESC.TO(currentRow, 1));
|
|
503
|
-
this.write(metaLine);
|
|
504
|
-
currentRow += 1;
|
|
505
|
-
}
|
|
506
|
-
// Separator line
|
|
507
|
-
this.write(ESC.TO(currentRow, 1));
|
|
508
|
-
this.write(renderDivider(cols - 2));
|
|
509
|
-
currentRow += 1;
|
|
510
|
-
// Render input lines
|
|
511
|
-
let finalRow = currentRow;
|
|
512
|
-
let finalCol = 3;
|
|
513
|
-
for (let i = 0; i < visibleLines.length; i++) {
|
|
514
|
-
const rowNum = currentRow + i;
|
|
515
|
-
this.write(ESC.TO(rowNum, 1));
|
|
516
|
-
const line = visibleLines[i] ?? '';
|
|
517
|
-
const isFirstLine = (startLine + i) === 0;
|
|
518
|
-
const isCursorLine = i === adjustedCursorLine;
|
|
519
|
-
this.write(ESC.BG_DARK);
|
|
520
|
-
this.write(ESC.DIM);
|
|
521
|
-
this.write(isFirstLine ? this.config.promptChar : this.config.continuationChar);
|
|
522
|
-
this.write(ESC.RESET);
|
|
523
|
-
this.write(ESC.BG_DARK);
|
|
524
|
-
if (isCursorLine) {
|
|
525
|
-
const col = Math.min(cursorCol, line.length);
|
|
526
|
-
const before = line.slice(0, col);
|
|
527
|
-
const at = col < line.length ? line[col] : ' ';
|
|
528
|
-
const after = col < line.length ? line.slice(col + 1) : '';
|
|
529
|
-
this.write(before);
|
|
530
|
-
this.write(ESC.REVERSE + ESC.BOLD);
|
|
531
|
-
this.write(at);
|
|
532
|
-
this.write(ESC.RESET + ESC.BG_DARK);
|
|
533
|
-
this.write(after);
|
|
534
|
-
finalRow = rowNum;
|
|
535
|
-
finalCol = this.config.promptChar.length + col + 1;
|
|
536
|
-
}
|
|
537
|
-
else {
|
|
538
|
-
this.write(line);
|
|
539
|
-
}
|
|
540
|
-
// Pad to edge
|
|
541
|
-
const lineLen = this.config.promptChar.length + line.length + (isCursorLine && cursorCol >= line.length ? 1 : 0);
|
|
542
|
-
const padding = Math.max(0, cols - lineLen - 1);
|
|
543
|
-
if (padding > 0)
|
|
544
|
-
this.write(' '.repeat(padding));
|
|
545
|
-
this.write(ESC.RESET);
|
|
546
|
-
}
|
|
547
|
-
// Mode controls line
|
|
548
|
-
const controlRow = currentRow + visibleLines.length;
|
|
549
|
-
this.write(ESC.TO(controlRow, 1));
|
|
550
|
-
this.write(this.buildModeControls(cols));
|
|
551
|
-
// Position cursor in input box
|
|
552
|
-
this.write(ESC.TO(finalRow, Math.min(finalCol, cols)));
|
|
553
|
-
this.write(ESC.SHOW);
|
|
554
|
-
// Update state
|
|
555
|
-
this.lastRenderContent = this.buffer;
|
|
556
|
-
this.lastRenderCursor = this.cursor;
|
|
557
|
-
this.lastStreamingRender = streamingActive ? Date.now() : 0;
|
|
558
|
-
if (this.streamingRenderTimer) {
|
|
559
|
-
clearTimeout(this.streamingRenderTimer);
|
|
560
|
-
this.streamingRenderTimer = null;
|
|
561
|
-
}
|
|
653
|
+
// Always render floating right after content (no wasted space)
|
|
654
|
+
this.renderFloatingInputArea();
|
|
562
655
|
}
|
|
563
656
|
finally {
|
|
564
657
|
writeLock.unlock();
|
|
@@ -566,181 +659,99 @@ export class TerminalInput extends EventEmitter {
|
|
|
566
659
|
}
|
|
567
660
|
}
|
|
568
661
|
/**
|
|
569
|
-
* Build
|
|
570
|
-
*
|
|
571
|
-
* Status message is shown in mode controls to avoid duplication.
|
|
662
|
+
* Build status bar showing streaming/ready status and key info.
|
|
663
|
+
* This is the TOP line above the input area - minimal Claude Code style.
|
|
572
664
|
*/
|
|
573
|
-
|
|
665
|
+
buildStatusBar(cols) {
|
|
666
|
+
const maxWidth = cols - 2;
|
|
574
667
|
const parts = [];
|
|
575
|
-
//
|
|
576
|
-
if (this.
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
parts.push({
|
|
585
|
-
}
|
|
586
|
-
// Token usage (compact)
|
|
587
|
-
if (this.metaTokensUsed !== null) {
|
|
588
|
-
const formattedUsed = this.formatTokenCount(this.metaTokensUsed);
|
|
589
|
-
const formattedLimit = this.metaTokenLimit ? `/${this.formatTokenCount(this.metaTokenLimit)}` : '';
|
|
590
|
-
parts.push({ text: `${formattedUsed}${formattedLimit}`, tone: 'muted' });
|
|
591
|
-
}
|
|
592
|
-
// Context remaining (only show if concerning)
|
|
593
|
-
const tokensRemaining = this.computeTokensRemaining();
|
|
594
|
-
if (tokensRemaining !== null) {
|
|
595
|
-
parts.push({ text: `↓${tokensRemaining}`, tone: 'muted' });
|
|
596
|
-
}
|
|
597
|
-
// Thinking indicator
|
|
598
|
-
if (this.metaThinkingMs !== null) {
|
|
599
|
-
parts.push({ text: formatThinking(this.metaThinkingMs, this.metaThinkingHasContent), tone: 'info' });
|
|
600
|
-
}
|
|
601
|
-
if (!parts.length) {
|
|
602
|
-
return [];
|
|
603
|
-
}
|
|
604
|
-
return [renderStatusLine(parts, width)];
|
|
605
|
-
}
|
|
606
|
-
/**
|
|
607
|
-
* Build Claude Code style mode controls line.
|
|
608
|
-
* Combines streaming label + override status + main status for simultaneous display.
|
|
609
|
-
*/
|
|
610
|
-
buildModeControls(cols) {
|
|
611
|
-
const width = Math.max(8, cols - 2);
|
|
612
|
-
const leftParts = [];
|
|
613
|
-
const rightParts = [];
|
|
614
|
-
if (this.streamingLabel) {
|
|
615
|
-
leftParts.push({ text: `◐ ${this.streamingLabel}`, tone: 'info' });
|
|
616
|
-
}
|
|
617
|
-
if (this.overrideStatusMessage) {
|
|
618
|
-
leftParts.push({ text: `⚠ ${this.overrideStatusMessage}`, tone: 'warn' });
|
|
619
|
-
}
|
|
620
|
-
if (this.statusMessage) {
|
|
621
|
-
leftParts.push({ text: this.statusMessage, tone: this.streamingLabel ? 'muted' : 'info' });
|
|
622
|
-
}
|
|
623
|
-
const editHotkey = this.formatHotkey('shift+tab');
|
|
624
|
-
const editLabel = this.editMode === 'display-edits' ? 'edits: accept' : 'edits: ask';
|
|
625
|
-
const editTone = this.editMode === 'display-edits' ? 'success' : 'muted';
|
|
626
|
-
leftParts.push({ text: `${editHotkey} ${editLabel}`, tone: editTone });
|
|
627
|
-
const verifyHotkey = this.formatHotkey(this.verificationHotkey);
|
|
628
|
-
const verifyLabel = this.verificationEnabled ? 'verify:on' : 'verify:off';
|
|
629
|
-
leftParts.push({ text: `${verifyHotkey} ${verifyLabel}`, tone: this.verificationEnabled ? 'success' : 'muted' });
|
|
630
|
-
const continueHotkey = this.formatHotkey(this.autoContinueHotkey);
|
|
631
|
-
const continueLabel = this.autoContinueEnabled ? 'auto:on' : 'auto:off';
|
|
632
|
-
leftParts.push({ text: `${continueHotkey} ${continueLabel}`, tone: this.autoContinueEnabled ? 'info' : 'muted' });
|
|
633
|
-
if (this.queue.length > 0 && this.mode !== 'streaming') {
|
|
634
|
-
leftParts.push({ text: `queued ${this.queue.length}`, tone: 'info' });
|
|
668
|
+
// Streaming status with elapsed time (left side)
|
|
669
|
+
if (this.mode === 'streaming') {
|
|
670
|
+
let statusText = '● Streaming';
|
|
671
|
+
if (this.streamingStartTime) {
|
|
672
|
+
const elapsed = Math.floor((Date.now() - this.streamingStartTime) / 1000);
|
|
673
|
+
const mins = Math.floor(elapsed / 60);
|
|
674
|
+
const secs = elapsed % 60;
|
|
675
|
+
statusText += mins > 0 ? ` ${mins}m ${secs}s` : ` ${secs}s`;
|
|
676
|
+
}
|
|
677
|
+
parts.push(`\x1b[32m${statusText}\x1b[0m`); // Green
|
|
635
678
|
}
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
679
|
+
// Queue indicator during streaming
|
|
680
|
+
if (this.mode === 'streaming' && this.queue.length > 0) {
|
|
681
|
+
parts.push(`\x1b[36mqueued: ${this.queue.length}\x1b[0m`); // Cyan
|
|
639
682
|
}
|
|
683
|
+
// Paste indicator
|
|
640
684
|
if (this.pastePlaceholders.length > 0) {
|
|
641
|
-
const
|
|
642
|
-
|
|
643
|
-
text: `paste #${latest.id} +${latest.lineCount} lines (⌫ to drop)`,
|
|
644
|
-
tone: 'info',
|
|
645
|
-
});
|
|
685
|
+
const totalLines = this.pastePlaceholders.reduce((sum, p) => sum + p.lineCount, 0);
|
|
686
|
+
parts.push(`\x1b[36m📋 ${totalLines}L\x1b[0m`);
|
|
646
687
|
}
|
|
647
|
-
|
|
648
|
-
if (this.
|
|
649
|
-
|
|
650
|
-
rightParts.push({ text: `${thinkingHotkey} thinking:${this.thinkingModeLabel}`, tone: 'info' });
|
|
651
|
-
}
|
|
652
|
-
// Model info is now in meta lines only - no duplication here
|
|
653
|
-
if (contextRemaining !== null) {
|
|
654
|
-
const tone = contextRemaining <= 10 ? 'warn' : 'muted';
|
|
655
|
-
const label = contextRemaining === 0 && this.contextUsage !== null
|
|
656
|
-
? 'Context auto-compact imminent'
|
|
657
|
-
: `Context left until auto-compact: ${contextRemaining}%`;
|
|
658
|
-
rightParts.push({ text: label, tone });
|
|
659
|
-
}
|
|
660
|
-
if (!rightParts.length || width < 60) {
|
|
661
|
-
const merged = rightParts.length ? [...leftParts, ...rightParts] : leftParts;
|
|
662
|
-
return renderStatusLine(merged, width);
|
|
663
|
-
}
|
|
664
|
-
const leftWidth = Math.max(12, Math.floor(width * 0.6));
|
|
665
|
-
const rightWidth = Math.max(14, width - leftWidth - 1);
|
|
666
|
-
const leftText = renderStatusLine(leftParts, leftWidth);
|
|
667
|
-
const rightText = renderStatusLine(rightParts, rightWidth);
|
|
668
|
-
const spacing = Math.max(1, width - this.visibleLength(leftText) - this.visibleLength(rightText));
|
|
669
|
-
return `${leftText}${' '.repeat(spacing)}${rightText}`;
|
|
670
|
-
}
|
|
671
|
-
formatHotkey(hotkey) {
|
|
672
|
-
const normalized = hotkey.trim().toLowerCase();
|
|
673
|
-
if (!normalized)
|
|
674
|
-
return hotkey;
|
|
675
|
-
const parts = normalized.split('+').filter(Boolean);
|
|
676
|
-
const map = {
|
|
677
|
-
shift: '⇧',
|
|
678
|
-
sh: '⇧',
|
|
679
|
-
alt: '⌥',
|
|
680
|
-
option: '⌥',
|
|
681
|
-
opt: '⌥',
|
|
682
|
-
ctrl: '⌃',
|
|
683
|
-
control: '⌃',
|
|
684
|
-
cmd: '⌘',
|
|
685
|
-
meta: '⌘',
|
|
686
|
-
};
|
|
687
|
-
const formatted = parts
|
|
688
|
-
.map((part) => {
|
|
689
|
-
const symbol = map[part];
|
|
690
|
-
if (symbol)
|
|
691
|
-
return symbol;
|
|
692
|
-
return part.length === 1 ? part.toUpperCase() : part.toUpperCase();
|
|
693
|
-
})
|
|
694
|
-
.join('');
|
|
695
|
-
return formatted || hotkey;
|
|
696
|
-
}
|
|
697
|
-
computeContextRemaining() {
|
|
698
|
-
if (this.contextUsage === null) {
|
|
699
|
-
return null;
|
|
700
|
-
}
|
|
701
|
-
return Math.max(0, this.contextAutoCompactThreshold - this.contextUsage);
|
|
702
|
-
}
|
|
703
|
-
computeTokensRemaining() {
|
|
704
|
-
if (this.metaTokensUsed === null || this.metaTokenLimit === null) {
|
|
705
|
-
return null;
|
|
706
|
-
}
|
|
707
|
-
const remaining = Math.max(0, this.metaTokenLimit - this.metaTokensUsed);
|
|
708
|
-
return this.formatTokenCount(remaining);
|
|
709
|
-
}
|
|
710
|
-
formatElapsedLabel(seconds) {
|
|
711
|
-
if (seconds < 60) {
|
|
712
|
-
return `${seconds}s`;
|
|
688
|
+
// Override/warning status
|
|
689
|
+
if (this.overrideStatusMessage) {
|
|
690
|
+
parts.push(`\x1b[33m⚠ ${this.overrideStatusMessage}\x1b[0m`); // Yellow
|
|
713
691
|
}
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
}
|
|
718
|
-
formatTokenCount(value) {
|
|
719
|
-
if (!Number.isFinite(value)) {
|
|
720
|
-
return `${value}`;
|
|
692
|
+
// If idle with empty buffer, show quick shortcuts
|
|
693
|
+
if (this.mode !== 'streaming' && this.buffer.length === 0 && parts.length === 0) {
|
|
694
|
+
return `${ESC.DIM}Type a message or / for commands${ESC.RESET}`;
|
|
721
695
|
}
|
|
722
|
-
|
|
723
|
-
|
|
696
|
+
// Multi-line indicator
|
|
697
|
+
if (this.buffer.includes('\n')) {
|
|
698
|
+
parts.push(`${ESC.DIM}${this.buffer.split('\n').length}L${ESC.RESET}`);
|
|
724
699
|
}
|
|
725
|
-
if (
|
|
726
|
-
return
|
|
700
|
+
if (parts.length === 0) {
|
|
701
|
+
return ''; // Empty status bar when idle
|
|
727
702
|
}
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
visibleLength(value) {
|
|
731
|
-
const ansiPattern = /\u001B\[[0-?]*[ -/]*[@-~]/g;
|
|
732
|
-
return value.replace(ansiPattern, '').length;
|
|
703
|
+
const joined = parts.join(`${ESC.DIM} · ${ESC.RESET}`);
|
|
704
|
+
return joined.slice(0, maxWidth);
|
|
733
705
|
}
|
|
734
706
|
/**
|
|
735
|
-
*
|
|
736
|
-
*
|
|
707
|
+
* Build mode controls line showing toggles and context info.
|
|
708
|
+
* This is the BOTTOM line below the input area - Claude Code style layout with erosolar features.
|
|
709
|
+
*
|
|
710
|
+
* Layout: [toggles on left] ... [context info on right]
|
|
737
711
|
*/
|
|
738
|
-
|
|
739
|
-
const
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
712
|
+
buildModeControls(cols) {
|
|
713
|
+
const maxWidth = cols - 2;
|
|
714
|
+
// Use schema-defined colors for consistency
|
|
715
|
+
const { green: GREEN, yellow: YELLOW, cyan: CYAN, magenta: MAGENTA, red: RED, dim: DIM, reset: R } = UI_COLORS;
|
|
716
|
+
// Mode toggles with colors (following ModeControlsSchema)
|
|
717
|
+
const toggles = [];
|
|
718
|
+
// Edit mode (green=auto, yellow=ask) - per schema.editMode
|
|
719
|
+
if (this.editMode === 'display-edits') {
|
|
720
|
+
toggles.push(`${GREEN}⏵⏵ auto-edit${R}`);
|
|
721
|
+
}
|
|
722
|
+
else {
|
|
723
|
+
toggles.push(`${YELLOW}⏸⏸ ask-first${R}`);
|
|
724
|
+
}
|
|
725
|
+
// Thinking mode (cyan when on) - per schema.thinkingMode
|
|
726
|
+
toggles.push(this.thinkingEnabled ? `${CYAN}💭 think${R}` : `${DIM}○ think${R}`);
|
|
727
|
+
// Verification (green when on) - per schema.verificationMode
|
|
728
|
+
toggles.push(this.verificationEnabled ? `${GREEN}✓ verify${R}` : `${DIM}○ verify${R}`);
|
|
729
|
+
// Auto-continue (magenta when on) - per schema.autoContinueMode
|
|
730
|
+
toggles.push(this.autoContinueEnabled ? `${MAGENTA}↻ auto${R}` : `${DIM}○ auto${R}`);
|
|
731
|
+
const leftPart = toggles.join(`${DIM} · ${R}`) + `${DIM} (⇧⇥)${R}`;
|
|
732
|
+
// Context usage with color - per schema.contextUsage thresholds
|
|
733
|
+
let rightPart = '';
|
|
734
|
+
if (this.contextUsage !== null) {
|
|
735
|
+
const rem = Math.max(0, 100 - this.contextUsage);
|
|
736
|
+
// Thresholds: critical < 10%, warning < 25%
|
|
737
|
+
if (rem < 10)
|
|
738
|
+
rightPart = `${RED}⚠ ctx: ${rem}%${R}`;
|
|
739
|
+
else if (rem < 25)
|
|
740
|
+
rightPart = `${YELLOW}! ctx: ${rem}%${R}`;
|
|
741
|
+
else
|
|
742
|
+
rightPart = `${DIM}ctx: ${rem}%${R}`;
|
|
743
|
+
}
|
|
744
|
+
// Calculate visible lengths (strip ANSI)
|
|
745
|
+
const strip = (s) => s.replace(/\x1b\[[0-9;]*m/g, '');
|
|
746
|
+
const leftLen = strip(leftPart).length;
|
|
747
|
+
const rightLen = strip(rightPart).length;
|
|
748
|
+
if (leftLen + rightLen < maxWidth - 4) {
|
|
749
|
+
return `${leftPart}${' '.repeat(maxWidth - leftLen - rightLen)}${rightPart}`;
|
|
750
|
+
}
|
|
751
|
+
if (rightLen > 0 && leftLen + 8 < maxWidth) {
|
|
752
|
+
return `${leftPart} ${rightPart}`;
|
|
753
|
+
}
|
|
754
|
+
return leftPart;
|
|
744
755
|
}
|
|
745
756
|
/**
|
|
746
757
|
* Force a re-render
|
|
@@ -763,265 +774,57 @@ export class TerminalInput extends EventEmitter {
|
|
|
763
774
|
handleResize() {
|
|
764
775
|
this.lastRenderContent = '';
|
|
765
776
|
this.lastRenderCursor = -1;
|
|
766
|
-
this.resetStreamingRenderThrottle();
|
|
767
777
|
this.scheduleRender();
|
|
768
778
|
}
|
|
779
|
+
// Track current content row for writing
|
|
780
|
+
contentCursorRow = 1;
|
|
769
781
|
/**
|
|
770
|
-
*
|
|
771
|
-
*
|
|
782
|
+
* Register with display's output interceptor.
|
|
783
|
+
* Clears chat box before writes, re-renders after with updated position.
|
|
772
784
|
*/
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
this.write(ESC.TO(row, 1));
|
|
788
|
-
this.write(ESC.CLEAR_LINE);
|
|
789
|
-
}
|
|
785
|
+
registerOutputInterceptor(display) {
|
|
786
|
+
if (this.outputInterceptorCleanup) {
|
|
787
|
+
this.outputInterceptorCleanup();
|
|
788
|
+
}
|
|
789
|
+
// Track pending render timeout for debouncing
|
|
790
|
+
let pendingRender = null;
|
|
791
|
+
// Track whether we're in a write batch (chat box already cleared)
|
|
792
|
+
let inWriteBatch = false;
|
|
793
|
+
this.outputInterceptorCleanup = display.registerOutputInterceptor({
|
|
794
|
+
beforeWrite: () => {
|
|
795
|
+
// Cancel any pending render - more content is coming
|
|
796
|
+
if (pendingRender) {
|
|
797
|
+
clearTimeout(pendingRender);
|
|
798
|
+
pendingRender = null;
|
|
790
799
|
}
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
}
|
|
819
|
-
// Final render
|
|
820
|
-
this.forceRender();
|
|
821
|
-
}
|
|
822
|
-
/**
|
|
823
|
-
* Render just the chat box at the bottom of terminal.
|
|
824
|
-
* Used during streaming to update status without affecting content.
|
|
825
|
-
*/
|
|
826
|
-
renderChatBoxAtBottom() {
|
|
827
|
-
const { rows, cols: width } = this.getSize();
|
|
828
|
-
const chatBoxHeight = this.getChatBoxHeight();
|
|
829
|
-
const pinnedRow = rows - chatBoxHeight + 1;
|
|
830
|
-
// During streaming: ALWAYS pin to absolute bottom (outside scroll region)
|
|
831
|
-
// When idle: float below content when there's room
|
|
832
|
-
let chatBoxStartRow;
|
|
833
|
-
if (this.scrollRegionActive) {
|
|
834
|
-
chatBoxStartRow = Math.max(1, pinnedRow);
|
|
835
|
-
}
|
|
836
|
-
else {
|
|
837
|
-
const floatingRow = this.contentRow + 1;
|
|
838
|
-
chatBoxStartRow = Math.max(1, Math.min(floatingRow, pinnedRow));
|
|
839
|
-
}
|
|
840
|
-
const metaLines = this.buildMetaLines(width);
|
|
841
|
-
const modeControls = this.buildModeControls(width);
|
|
842
|
-
const divider = theme.ui.muted('─'.repeat(width));
|
|
843
|
-
// Get input area content
|
|
844
|
-
const lines = this.buffer.split('\n');
|
|
845
|
-
const maxDisplayLines = 3;
|
|
846
|
-
const displayLines = Math.min(lines.length, maxDisplayLines);
|
|
847
|
-
const visibleLines = lines.slice(Math.max(0, lines.length - displayLines));
|
|
848
|
-
const scrollEnd = rows - chatBoxHeight;
|
|
849
|
-
writeLock.lock('renderChatBoxAtBottom');
|
|
850
|
-
try {
|
|
851
|
-
this.write(ESC.SAVE);
|
|
852
|
-
this.write(ESC.HIDE);
|
|
853
|
-
// Temporarily reset scroll region to write chat box cleanly
|
|
854
|
-
if (this.scrollRegionActive) {
|
|
855
|
-
this.write(ESC.RESET_SCROLL);
|
|
856
|
-
}
|
|
857
|
-
let row = chatBoxStartRow;
|
|
858
|
-
// Meta lines (single line)
|
|
859
|
-
for (const line of metaLines) {
|
|
860
|
-
this.write(ESC.TO(row++, 1));
|
|
861
|
-
this.write(ESC.CLEAR_LINE);
|
|
862
|
-
this.write(line);
|
|
863
|
-
}
|
|
864
|
-
// Divider
|
|
865
|
-
this.write(ESC.TO(row++, 1));
|
|
866
|
-
this.write(ESC.CLEAR_LINE);
|
|
867
|
-
this.write(divider);
|
|
868
|
-
// Input area
|
|
869
|
-
for (const line of visibleLines) {
|
|
870
|
-
this.write(ESC.TO(row++, 1));
|
|
871
|
-
this.write(ESC.CLEAR_LINE);
|
|
872
|
-
this.write(this.config.promptChar);
|
|
873
|
-
this.write(line);
|
|
874
|
-
}
|
|
875
|
-
// Mode controls
|
|
876
|
-
this.write(ESC.TO(row, 1));
|
|
877
|
-
this.write(ESC.CLEAR_LINE);
|
|
878
|
-
this.write(modeControls);
|
|
879
|
-
// Restore scroll region and cursor position for content
|
|
880
|
-
if (this.scrollRegionActive) {
|
|
881
|
-
this.write(ESC.SET_SCROLL(1, scrollEnd));
|
|
882
|
-
// Position cursor at content row for next write
|
|
883
|
-
this.write(ESC.TO(Math.min(this.contentRow, scrollEnd), 1));
|
|
884
|
-
}
|
|
885
|
-
this.write(ESC.RESTORE);
|
|
886
|
-
this.write(ESC.SHOW);
|
|
887
|
-
}
|
|
888
|
-
finally {
|
|
889
|
-
writeLock.unlock();
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
/**
|
|
893
|
-
* Stream content within the scroll region.
|
|
894
|
-
* Content is written directly and scrolls naturally.
|
|
895
|
-
*/
|
|
896
|
-
streamContent(content) {
|
|
897
|
-
if (!content)
|
|
898
|
-
return;
|
|
899
|
-
writeLock.lock('streamContent');
|
|
900
|
-
try {
|
|
901
|
-
// Write content - scroll region handles scrolling
|
|
902
|
-
this.write(content);
|
|
903
|
-
// Track newlines
|
|
904
|
-
const newlines = (content.match(/\n/g) || []).length;
|
|
905
|
-
this.contentRow += newlines;
|
|
906
|
-
}
|
|
907
|
-
finally {
|
|
908
|
-
writeLock.unlock();
|
|
909
|
-
}
|
|
910
|
-
// Throttle chat box updates during streaming
|
|
911
|
-
this.scheduleStreamingRender(200);
|
|
912
|
-
}
|
|
913
|
-
/**
|
|
914
|
-
* Enable scroll region (no-op in floating mode).
|
|
915
|
-
*/
|
|
916
|
-
enableScrollRegion() {
|
|
917
|
-
// No-op: using pure floating approach
|
|
918
|
-
}
|
|
919
|
-
/**
|
|
920
|
-
* Disable scroll region (no-op in floating mode).
|
|
921
|
-
*/
|
|
922
|
-
disableScrollRegion() {
|
|
923
|
-
// No-op: using pure floating approach
|
|
924
|
-
}
|
|
925
|
-
/**
|
|
926
|
-
* Calculate chat box height.
|
|
927
|
-
*/
|
|
928
|
-
getChatBoxHeight() {
|
|
929
|
-
return 6; // Fixed: meta + divider + input + controls + buffer
|
|
930
|
-
}
|
|
931
|
-
/**
|
|
932
|
-
* @deprecated Use streamContent() instead
|
|
933
|
-
* Register with display's output interceptor - kept for backwards compatibility
|
|
934
|
-
*/
|
|
935
|
-
registerOutputInterceptor(_display) {
|
|
936
|
-
// No-op: Use streamContent() for cleaner floating chat box behavior
|
|
937
|
-
}
|
|
938
|
-
/**
|
|
939
|
-
* Write content above the floating chat box.
|
|
940
|
-
* Works both during streaming and when idle.
|
|
941
|
-
*/
|
|
942
|
-
writeToScrollRegion(content) {
|
|
943
|
-
if (!content)
|
|
944
|
-
return;
|
|
945
|
-
writeLock.lock('writeToScrollRegion');
|
|
946
|
-
try {
|
|
947
|
-
// Position cursor at content row and write
|
|
948
|
-
this.write(ESC.TO(this.contentRow, 1));
|
|
949
|
-
this.write(content);
|
|
950
|
-
// Track newlines
|
|
951
|
-
const newlines = (content.match(/\n/g) || []).length;
|
|
952
|
-
this.contentRow += newlines;
|
|
953
|
-
}
|
|
954
|
-
finally {
|
|
955
|
-
writeLock.unlock();
|
|
956
|
-
}
|
|
957
|
-
// Re-render chat box below new content (only when not streaming)
|
|
958
|
-
if (!this.scrollRegionActive) {
|
|
959
|
-
this.forceRender();
|
|
960
|
-
}
|
|
961
|
-
}
|
|
962
|
-
/**
|
|
963
|
-
* Enter alternate screen buffer and clear it.
|
|
964
|
-
* This gives us full control over the terminal without affecting user's history.
|
|
965
|
-
*/
|
|
966
|
-
enterAlternateScreen() {
|
|
967
|
-
writeLock.lock('enterAltScreen');
|
|
968
|
-
try {
|
|
969
|
-
this.write(ESC.ENTER_ALT_SCREEN);
|
|
970
|
-
this.write(ESC.HOME);
|
|
971
|
-
this.write(ESC.CLEAR_SCREEN);
|
|
972
|
-
this.contentRow = 1;
|
|
973
|
-
}
|
|
974
|
-
finally {
|
|
975
|
-
writeLock.unlock();
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
/**
|
|
979
|
-
* Exit alternate screen buffer.
|
|
980
|
-
* Restores the user's previous terminal content.
|
|
981
|
-
*/
|
|
982
|
-
exitAlternateScreen() {
|
|
983
|
-
writeLock.lock('exitAltScreen');
|
|
984
|
-
try {
|
|
985
|
-
this.write(ESC.EXIT_ALT_SCREEN);
|
|
986
|
-
}
|
|
987
|
-
finally {
|
|
988
|
-
writeLock.unlock();
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
/**
|
|
992
|
-
* Clear the entire terminal screen and reset content position.
|
|
993
|
-
* This removes all content including the launching command.
|
|
994
|
-
*/
|
|
995
|
-
clearScreen() {
|
|
996
|
-
writeLock.lock('clearScreen');
|
|
997
|
-
try {
|
|
998
|
-
this.write(ESC.HOME);
|
|
999
|
-
this.write(ESC.CLEAR_SCREEN);
|
|
1000
|
-
this.contentRow = 1;
|
|
1001
|
-
}
|
|
1002
|
-
finally {
|
|
1003
|
-
writeLock.unlock();
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
/**
|
|
1007
|
-
* Reset content position to row 1.
|
|
1008
|
-
* Does NOT clear the terminal - content starts from current position.
|
|
1009
|
-
*/
|
|
1010
|
-
resetContentPosition() {
|
|
1011
|
-
this.contentRow = 1;
|
|
1012
|
-
}
|
|
1013
|
-
/**
|
|
1014
|
-
* Set the content row explicitly (used after banner is written).
|
|
1015
|
-
* This tells the input where content should start flowing from.
|
|
1016
|
-
*/
|
|
1017
|
-
setContentRow(row) {
|
|
1018
|
-
this.contentRow = Math.max(1, row);
|
|
1019
|
-
}
|
|
1020
|
-
/**
|
|
1021
|
-
* Get the current content row position.
|
|
1022
|
-
*/
|
|
1023
|
-
getContentRow() {
|
|
1024
|
-
return this.contentRow;
|
|
800
|
+
// Only clear chat box and position cursor at START of write batch
|
|
801
|
+
// During batch, let cursor flow naturally
|
|
802
|
+
if (!inWriteBatch) {
|
|
803
|
+
inWriteBatch = true;
|
|
804
|
+
// Clear the floating chat box before writing content
|
|
805
|
+
this.clearInputArea();
|
|
806
|
+
// Position cursor where content should continue
|
|
807
|
+
this.write(ESC.TO(this.contentEndRow + 1, 1));
|
|
808
|
+
}
|
|
809
|
+
// For subsequent writes in batch, cursor is already at correct position
|
|
810
|
+
},
|
|
811
|
+
afterWrite: () => {
|
|
812
|
+
// Debounce render: wait 50ms for more writes before rendering chat box
|
|
813
|
+
if (pendingRender) {
|
|
814
|
+
clearTimeout(pendingRender);
|
|
815
|
+
}
|
|
816
|
+
pendingRender = setTimeout(() => {
|
|
817
|
+
pendingRender = null;
|
|
818
|
+
inWriteBatch = false; // End of write batch
|
|
819
|
+
// Update contentEndRow from display's line count if available
|
|
820
|
+
if (display.getTotalWrittenLines) {
|
|
821
|
+
this.contentEndRow = display.getTotalWrittenLines();
|
|
822
|
+
}
|
|
823
|
+
// Re-render chat box below content
|
|
824
|
+
this.renderFloatingInputArea();
|
|
825
|
+
}, 50);
|
|
826
|
+
},
|
|
827
|
+
});
|
|
1025
828
|
}
|
|
1026
829
|
/**
|
|
1027
830
|
* Dispose and clean up
|
|
@@ -1029,10 +832,24 @@ export class TerminalInput extends EventEmitter {
|
|
|
1029
832
|
dispose() {
|
|
1030
833
|
if (this.disposed)
|
|
1031
834
|
return;
|
|
835
|
+
// Clean up streaming render timer
|
|
836
|
+
if (this.streamingRenderTimer) {
|
|
837
|
+
clearInterval(this.streamingRenderTimer);
|
|
838
|
+
this.streamingRenderTimer = null;
|
|
839
|
+
}
|
|
840
|
+
// Clean up output interceptor
|
|
841
|
+
if (this.outputInterceptorCleanup) {
|
|
842
|
+
this.outputInterceptorCleanup();
|
|
843
|
+
this.outputInterceptorCleanup = undefined;
|
|
844
|
+
}
|
|
845
|
+
// Reset scroll region
|
|
846
|
+
this.write('\x1b[r');
|
|
847
|
+
// Exit alternate screen buffer (restores main terminal)
|
|
848
|
+
if (this.unifiedUIInitialized) {
|
|
849
|
+
this.write(ESC.ALT_SCREEN_EXIT);
|
|
850
|
+
}
|
|
1032
851
|
this.disposed = true;
|
|
1033
852
|
this.enabled = false;
|
|
1034
|
-
this.disableScrollRegion();
|
|
1035
|
-
this.resetStreamingRenderThrottle();
|
|
1036
853
|
this.disableBracketedPaste();
|
|
1037
854
|
this.buffer = '';
|
|
1038
855
|
this.queue = [];
|
|
@@ -1137,7 +954,22 @@ export class TerminalInput extends EventEmitter {
|
|
|
1137
954
|
this.toggleEditMode();
|
|
1138
955
|
return true;
|
|
1139
956
|
}
|
|
1140
|
-
|
|
957
|
+
// Tab: toggle paste expansion if in placeholder, otherwise toggle thinking
|
|
958
|
+
if (this.findPlaceholderAt(this.cursor)) {
|
|
959
|
+
this.togglePasteExpansion();
|
|
960
|
+
}
|
|
961
|
+
else {
|
|
962
|
+
this.toggleThinking();
|
|
963
|
+
}
|
|
964
|
+
return true;
|
|
965
|
+
case 'escape':
|
|
966
|
+
// Esc: interrupt if streaming, otherwise clear buffer
|
|
967
|
+
if (this.mode === 'streaming') {
|
|
968
|
+
this.emit('interrupt');
|
|
969
|
+
}
|
|
970
|
+
else if (this.buffer.length > 0) {
|
|
971
|
+
this.clear();
|
|
972
|
+
}
|
|
1141
973
|
return true;
|
|
1142
974
|
}
|
|
1143
975
|
return false;
|
|
@@ -1155,6 +987,7 @@ export class TerminalInput extends EventEmitter {
|
|
|
1155
987
|
this.insertPlainText(chunk, insertPos);
|
|
1156
988
|
this.cursor = insertPos + chunk.length;
|
|
1157
989
|
this.emit('change', this.buffer);
|
|
990
|
+
this.updateSuggestions();
|
|
1158
991
|
this.scheduleRender();
|
|
1159
992
|
}
|
|
1160
993
|
insertNewline() {
|
|
@@ -1179,6 +1012,7 @@ export class TerminalInput extends EventEmitter {
|
|
|
1179
1012
|
this.cursor = Math.max(0, this.cursor - 1);
|
|
1180
1013
|
}
|
|
1181
1014
|
this.emit('change', this.buffer);
|
|
1015
|
+
this.updateSuggestions();
|
|
1182
1016
|
this.scheduleRender();
|
|
1183
1017
|
}
|
|
1184
1018
|
deleteForward() {
|
|
@@ -1406,12 +1240,13 @@ export class TerminalInput extends EventEmitter {
|
|
|
1406
1240
|
timestamp: Date.now(),
|
|
1407
1241
|
});
|
|
1408
1242
|
this.emit('queue', text);
|
|
1409
|
-
this.clear(); // Clear immediately for queued input
|
|
1243
|
+
this.clear(); // Clear immediately for queued input, re-render to update queue display
|
|
1410
1244
|
}
|
|
1411
1245
|
else {
|
|
1412
|
-
// In idle mode, clear the input
|
|
1413
|
-
// The
|
|
1414
|
-
|
|
1246
|
+
// In idle mode, clear the input WITHOUT rendering.
|
|
1247
|
+
// The caller will display the user message and start streaming.
|
|
1248
|
+
// We'll render the input area again after streaming ends.
|
|
1249
|
+
this.clear(true); // Skip render - streaming will handle display
|
|
1415
1250
|
this.emit('submit', text);
|
|
1416
1251
|
}
|
|
1417
1252
|
}
|
|
@@ -1428,9 +1263,7 @@ export class TerminalInput extends EventEmitter {
|
|
|
1428
1263
|
if (available <= 0)
|
|
1429
1264
|
return;
|
|
1430
1265
|
const chunk = clean.slice(0, available);
|
|
1431
|
-
|
|
1432
|
-
const isShortMultiline = isMultiline && this.shouldInlineMultiline(chunk);
|
|
1433
|
-
if (isMultiline && !isShortMultiline) {
|
|
1266
|
+
if (isMultilinePaste(chunk)) {
|
|
1434
1267
|
this.insertPastePlaceholder(chunk);
|
|
1435
1268
|
}
|
|
1436
1269
|
else {
|
|
@@ -1566,19 +1399,17 @@ export class TerminalInput extends EventEmitter {
|
|
|
1566
1399
|
this.shiftPlaceholders(position, text.length);
|
|
1567
1400
|
this.buffer = this.buffer.slice(0, position) + text + this.buffer.slice(position);
|
|
1568
1401
|
}
|
|
1569
|
-
shouldInlineMultiline(content) {
|
|
1570
|
-
const lines = content.split('\n').length;
|
|
1571
|
-
const maxInlineLines = 4;
|
|
1572
|
-
const maxInlineChars = 240;
|
|
1573
|
-
return lines <= maxInlineLines && content.length <= maxInlineChars;
|
|
1574
|
-
}
|
|
1575
1402
|
findPlaceholderAt(position) {
|
|
1576
1403
|
return this.pastePlaceholders.find((ph) => position >= ph.start && position < ph.end) ?? null;
|
|
1577
1404
|
}
|
|
1578
|
-
buildPlaceholder(
|
|
1405
|
+
buildPlaceholder(summary) {
|
|
1579
1406
|
const id = ++this.pasteCounter;
|
|
1580
|
-
const
|
|
1581
|
-
|
|
1407
|
+
const lang = summary.language ? ` ${summary.language.toUpperCase()}` : '';
|
|
1408
|
+
// Show first line preview (truncated)
|
|
1409
|
+
const preview = summary.preview.length > 30
|
|
1410
|
+
? `${summary.preview.slice(0, 30)}...`
|
|
1411
|
+
: summary.preview;
|
|
1412
|
+
const placeholder = `[📋 #${id}${lang} ${summary.lineCount}L] "${preview}"`;
|
|
1582
1413
|
return { id, placeholder };
|
|
1583
1414
|
}
|
|
1584
1415
|
insertPastePlaceholder(content) {
|
|
@@ -1586,21 +1417,67 @@ export class TerminalInput extends EventEmitter {
|
|
|
1586
1417
|
if (available <= 0)
|
|
1587
1418
|
return;
|
|
1588
1419
|
const cleanContent = content.slice(0, available);
|
|
1589
|
-
const
|
|
1590
|
-
|
|
1420
|
+
const summary = generatePasteSummary(cleanContent);
|
|
1421
|
+
// For short pastes (< 5 lines), show full content instead of placeholder
|
|
1422
|
+
if (summary.lineCount < 5) {
|
|
1423
|
+
const placeholder = this.findPlaceholderAt(this.cursor);
|
|
1424
|
+
const insertPos = placeholder && this.cursor > placeholder.start ? placeholder.end : this.cursor;
|
|
1425
|
+
this.insertPlainText(cleanContent, insertPos);
|
|
1426
|
+
this.cursor = insertPos + cleanContent.length;
|
|
1427
|
+
return;
|
|
1428
|
+
}
|
|
1429
|
+
const { id, placeholder } = this.buildPlaceholder(summary);
|
|
1591
1430
|
const insertPos = this.cursor;
|
|
1592
1431
|
this.shiftPlaceholders(insertPos, placeholder.length);
|
|
1593
1432
|
this.pastePlaceholders.push({
|
|
1594
1433
|
id,
|
|
1595
1434
|
content: cleanContent,
|
|
1596
|
-
lineCount,
|
|
1435
|
+
lineCount: summary.lineCount,
|
|
1597
1436
|
placeholder,
|
|
1598
1437
|
start: insertPos,
|
|
1599
1438
|
end: insertPos + placeholder.length,
|
|
1439
|
+
summary,
|
|
1440
|
+
expanded: false,
|
|
1600
1441
|
});
|
|
1601
1442
|
this.buffer = this.buffer.slice(0, insertPos) + placeholder + this.buffer.slice(insertPos);
|
|
1602
1443
|
this.cursor = insertPos + placeholder.length;
|
|
1603
1444
|
}
|
|
1445
|
+
/**
|
|
1446
|
+
* Toggle expansion of a paste placeholder at the current cursor position.
|
|
1447
|
+
* When expanded, shows first 3 and last 2 lines of the content.
|
|
1448
|
+
*/
|
|
1449
|
+
togglePasteExpansion() {
|
|
1450
|
+
const placeholder = this.findPlaceholderAt(this.cursor);
|
|
1451
|
+
if (!placeholder)
|
|
1452
|
+
return false;
|
|
1453
|
+
placeholder.expanded = !placeholder.expanded;
|
|
1454
|
+
// Update the placeholder text in buffer
|
|
1455
|
+
const newPlaceholder = placeholder.expanded
|
|
1456
|
+
? this.buildExpandedPlaceholder(placeholder)
|
|
1457
|
+
: this.buildPlaceholder(placeholder.summary).placeholder;
|
|
1458
|
+
const lengthDiff = newPlaceholder.length - placeholder.placeholder.length;
|
|
1459
|
+
// Update buffer
|
|
1460
|
+
this.buffer =
|
|
1461
|
+
this.buffer.slice(0, placeholder.start) +
|
|
1462
|
+
newPlaceholder +
|
|
1463
|
+
this.buffer.slice(placeholder.end);
|
|
1464
|
+
// Update placeholder tracking
|
|
1465
|
+
placeholder.placeholder = newPlaceholder;
|
|
1466
|
+
placeholder.end = placeholder.start + newPlaceholder.length;
|
|
1467
|
+
// Shift other placeholders
|
|
1468
|
+
this.shiftPlaceholders(placeholder.end, lengthDiff, placeholder.id);
|
|
1469
|
+
this.scheduleRender();
|
|
1470
|
+
return true;
|
|
1471
|
+
}
|
|
1472
|
+
buildExpandedPlaceholder(ph) {
|
|
1473
|
+
const lines = ph.content.split('\n');
|
|
1474
|
+
const firstLines = lines.slice(0, 3).map(l => l.slice(0, 60)).join('\n');
|
|
1475
|
+
const lastLines = lines.length > 5
|
|
1476
|
+
? '\n...\n' + lines.slice(-2).map(l => l.slice(0, 60)).join('\n')
|
|
1477
|
+
: '';
|
|
1478
|
+
const lang = ph.summary.language ? ` ${ph.summary.language.toUpperCase()}` : '';
|
|
1479
|
+
return `[📋 #${ph.id}${lang} ${ph.lineCount}L ▼]\n${firstLines}${lastLines}\n[/📋 #${ph.id}]`;
|
|
1480
|
+
}
|
|
1604
1481
|
deletePlaceholder(placeholder) {
|
|
1605
1482
|
const length = placeholder.end - placeholder.start;
|
|
1606
1483
|
this.buffer = this.buffer.slice(0, placeholder.start) + this.buffer.slice(placeholder.end);
|
|
@@ -1608,11 +1485,7 @@ export class TerminalInput extends EventEmitter {
|
|
|
1608
1485
|
this.shiftPlaceholders(placeholder.end, -length, placeholder.id);
|
|
1609
1486
|
this.cursor = placeholder.start;
|
|
1610
1487
|
}
|
|
1611
|
-
updateContextUsage(value
|
|
1612
|
-
if (typeof autoCompactThreshold === 'number' && Number.isFinite(autoCompactThreshold)) {
|
|
1613
|
-
const boundedThreshold = Math.max(1, Math.min(100, Math.round(autoCompactThreshold)));
|
|
1614
|
-
this.contextAutoCompactThreshold = boundedThreshold;
|
|
1615
|
-
}
|
|
1488
|
+
updateContextUsage(value) {
|
|
1616
1489
|
if (value === null || !Number.isFinite(value)) {
|
|
1617
1490
|
this.contextUsage = null;
|
|
1618
1491
|
}
|
|
@@ -1639,28 +1512,6 @@ export class TerminalInput extends EventEmitter {
|
|
|
1639
1512
|
const next = this.editMode === 'display-edits' ? 'ask-permission' : 'display-edits';
|
|
1640
1513
|
this.setEditMode(next);
|
|
1641
1514
|
}
|
|
1642
|
-
scheduleStreamingRender(delayMs) {
|
|
1643
|
-
if (this.streamingRenderTimer)
|
|
1644
|
-
return;
|
|
1645
|
-
const wait = Math.max(16, delayMs);
|
|
1646
|
-
this.streamingRenderTimer = setTimeout(() => {
|
|
1647
|
-
this.streamingRenderTimer = null;
|
|
1648
|
-
// During streaming, only update chat box (not full render)
|
|
1649
|
-
if (this.scrollRegionActive) {
|
|
1650
|
-
this.renderChatBoxAtBottom();
|
|
1651
|
-
}
|
|
1652
|
-
else {
|
|
1653
|
-
this.render();
|
|
1654
|
-
}
|
|
1655
|
-
}, wait);
|
|
1656
|
-
}
|
|
1657
|
-
resetStreamingRenderThrottle() {
|
|
1658
|
-
if (this.streamingRenderTimer) {
|
|
1659
|
-
clearTimeout(this.streamingRenderTimer);
|
|
1660
|
-
this.streamingRenderTimer = null;
|
|
1661
|
-
}
|
|
1662
|
-
this.lastStreamingRender = 0;
|
|
1663
|
-
}
|
|
1664
1515
|
scheduleRender() {
|
|
1665
1516
|
if (!this.canRender())
|
|
1666
1517
|
return;
|