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