erosolar-cli 1.7.249 → 1.7.251
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 +22 -148
- package/dist/core/customCommands.d.ts +1 -0
- package/dist/core/customCommands.d.ts.map +1 -1
- package/dist/core/customCommands.js +3 -0
- package/dist/core/customCommands.js.map +1 -1
- package/dist/core/toolPreconditions.d.ts.map +1 -1
- package/dist/core/toolPreconditions.js +0 -14
- package/dist/core/toolPreconditions.js.map +1 -1
- package/dist/core/toolRuntime.d.ts.map +1 -1
- package/dist/core/toolRuntime.js +0 -5
- package/dist/core/toolRuntime.js.map +1 -1
- package/dist/core/toolValidation.d.ts.map +1 -1
- package/dist/core/toolValidation.js +14 -3
- package/dist/core/toolValidation.js.map +1 -1
- package/dist/mcp/sseClient.d.ts.map +1 -1
- package/dist/mcp/sseClient.js +9 -18
- package/dist/mcp/sseClient.js.map +1 -1
- package/dist/plugins/tools/build/buildPlugin.d.ts +0 -6
- package/dist/plugins/tools/build/buildPlugin.d.ts.map +1 -1
- package/dist/plugins/tools/build/buildPlugin.js +4 -10
- package/dist/plugins/tools/build/buildPlugin.js.map +1 -1
- package/dist/shell/interactiveShell.d.ts +10 -2
- package/dist/shell/interactiveShell.d.ts.map +1 -1
- package/dist/shell/interactiveShell.js +183 -31
- package/dist/shell/interactiveShell.js.map +1 -1
- package/dist/shell/terminalInput.d.ts +54 -123
- package/dist/shell/terminalInput.d.ts.map +1 -1
- package/dist/shell/terminalInput.js +355 -570
- package/dist/shell/terminalInput.js.map +1 -1
- package/dist/shell/terminalInputAdapter.d.ts +12 -15
- package/dist/shell/terminalInputAdapter.d.ts.map +1 -1
- package/dist/shell/terminalInputAdapter.js +8 -22
- package/dist/shell/terminalInputAdapter.js.map +1 -1
- package/dist/ui/display.d.ts +19 -0
- package/dist/ui/display.d.ts.map +1 -1
- package/dist/ui/display.js +115 -2
- package/dist/ui/display.js.map +1 -1
- package/dist/ui/theme.d.ts.map +1 -1
- package/dist/ui/theme.js +6 -8
- package/dist/ui/theme.js.map +1 -1
- package/dist/ui/unified/layout.d.ts +1 -0
- package/dist/ui/unified/layout.d.ts.map +1 -1
- package/dist/ui/unified/layout.js +15 -25
- package/dist/ui/unified/layout.js.map +1 -1
- package/package.json +1 -1
- package/dist/core/aiFlowOptimizer.d.ts +0 -26
- package/dist/core/aiFlowOptimizer.d.ts.map +0 -1
- package/dist/core/aiFlowOptimizer.js +0 -31
- package/dist/core/aiFlowOptimizer.js.map +0 -1
- package/dist/core/aiOptimizationEngine.d.ts +0 -158
- package/dist/core/aiOptimizationEngine.d.ts.map +0 -1
- package/dist/core/aiOptimizationEngine.js +0 -428
- package/dist/core/aiOptimizationEngine.js.map +0 -1
- package/dist/core/aiOptimizationIntegration.d.ts +0 -93
- package/dist/core/aiOptimizationIntegration.d.ts.map +0 -1
- package/dist/core/aiOptimizationIntegration.js +0 -250
- package/dist/core/aiOptimizationIntegration.js.map +0 -1
- package/dist/core/enhancedErrorRecovery.d.ts +0 -100
- package/dist/core/enhancedErrorRecovery.d.ts.map +0 -1
- package/dist/core/enhancedErrorRecovery.js +0 -345
- package/dist/core/enhancedErrorRecovery.js.map +0 -1
- package/dist/shell/claudeCodeStreamHandler.d.ts +0 -145
- package/dist/shell/claudeCodeStreamHandler.d.ts.map +0 -1
- package/dist/shell/claudeCodeStreamHandler.js +0 -322
- package/dist/shell/claudeCodeStreamHandler.js.map +0 -1
- package/dist/shell/inputQueueManager.d.ts +0 -144
- package/dist/shell/inputQueueManager.d.ts.map +0 -1
- package/dist/shell/inputQueueManager.js +0 -290
- package/dist/shell/inputQueueManager.js.map +0 -1
- package/dist/shell/streamingOutputManager.d.ts +0 -115
- package/dist/shell/streamingOutputManager.d.ts.map +0 -1
- package/dist/shell/streamingOutputManager.js +0 -225
- package/dist/shell/streamingOutputManager.js.map +0 -1
- package/dist/ui/persistentPrompt.d.ts +0 -50
- package/dist/ui/persistentPrompt.d.ts.map +0 -1
- package/dist/ui/persistentPrompt.js +0 -92
- package/dist/ui/persistentPrompt.js.map +0 -1
- package/dist/ui/terminalUISchema.d.ts +0 -195
- package/dist/ui/terminalUISchema.d.ts.map +0 -1
- package/dist/ui/terminalUISchema.js +0 -113
- package/dist/ui/terminalUISchema.js.map +0 -1
|
@@ -3,16 +3,18 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Design principles:
|
|
5
5
|
* - Single source of truth for input state
|
|
6
|
+
* - One bottom-pinned chat box for the entire session (no inline anchors)
|
|
6
7
|
* - Native bracketed paste support (no heuristics)
|
|
7
8
|
* - Clean cursor model with render-time wrapping
|
|
8
9
|
* - State machine for different input modes
|
|
9
10
|
* - No readline dependency for display
|
|
10
11
|
*/
|
|
11
12
|
import { EventEmitter } from 'node:events';
|
|
12
|
-
import { isMultilinePaste
|
|
13
|
+
import { isMultilinePaste } from '../core/multilinePasteHandler.js';
|
|
13
14
|
import { writeLock } from '../ui/writeLock.js';
|
|
14
|
-
import { renderDivider } from '../ui/unified/layout.js';
|
|
15
|
-
import {
|
|
15
|
+
import { renderDivider, renderStatusLine } from '../ui/unified/layout.js';
|
|
16
|
+
import { isStreamingMode } from '../ui/globalWriteLock.js';
|
|
17
|
+
import { formatThinking } from '../ui/toolDisplay.js';
|
|
16
18
|
// ANSI escape codes
|
|
17
19
|
const ESC = {
|
|
18
20
|
// Cursor control
|
|
@@ -67,6 +69,11 @@ export class TerminalInput extends EventEmitter {
|
|
|
67
69
|
statusMessage = null;
|
|
68
70
|
overrideStatusMessage = null; // Secondary status (warnings, etc.)
|
|
69
71
|
streamingLabel = null; // Streaming progress indicator
|
|
72
|
+
metaElapsedSeconds = null; // Optional elapsed time for header line
|
|
73
|
+
metaTokensUsed = null; // Optional token usage
|
|
74
|
+
metaTokenLimit = null; // Optional token window
|
|
75
|
+
metaThinkingMs = null; // Optional thinking duration
|
|
76
|
+
metaThinkingHasContent = false; // Whether collapsed thinking content exists
|
|
70
77
|
reservedLines = 2;
|
|
71
78
|
scrollRegionActive = false;
|
|
72
79
|
lastRenderContent = '';
|
|
@@ -74,22 +81,12 @@ export class TerminalInput extends EventEmitter {
|
|
|
74
81
|
renderDirty = false;
|
|
75
82
|
isRendering = false;
|
|
76
83
|
pinnedTopRows = 0;
|
|
77
|
-
inlineAnchorRow = null;
|
|
78
|
-
inlineLayout = false;
|
|
79
|
-
anchorProvider = null;
|
|
80
|
-
// Flow mode: when true, renders inline after content (no absolute positioning)
|
|
81
|
-
flowMode = true;
|
|
82
|
-
flowModeRenderedLines = 0; // Track lines rendered for clearing
|
|
83
|
-
// Command suggestions (Claude Code style auto-complete)
|
|
84
|
-
commandSuggestions = [];
|
|
85
|
-
filteredSuggestions = [];
|
|
86
|
-
selectedSuggestionIndex = 0;
|
|
87
|
-
showSuggestions = false;
|
|
88
|
-
maxVisibleSuggestions = 10;
|
|
89
84
|
// Lifecycle
|
|
90
85
|
disposed = false;
|
|
91
86
|
enabled = true;
|
|
92
87
|
contextUsage = null;
|
|
88
|
+
contextAutoCompactThreshold = 90;
|
|
89
|
+
thinkingModeLabel = null;
|
|
93
90
|
editMode = 'display-edits';
|
|
94
91
|
verificationEnabled = true;
|
|
95
92
|
autoContinueEnabled = false;
|
|
@@ -97,22 +94,19 @@ export class TerminalInput extends EventEmitter {
|
|
|
97
94
|
autoContinueHotkey = 'alt+c';
|
|
98
95
|
// Output interceptor cleanup
|
|
99
96
|
outputInterceptorCleanup;
|
|
100
|
-
//
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
thinkingEnabled = true;
|
|
104
|
-
// Streaming input area render timer (updates elapsed time display)
|
|
97
|
+
// Streaming render throttle
|
|
98
|
+
lastStreamingRender = 0;
|
|
99
|
+
streamingRenderInterval = 250; // ms between renders during streaming
|
|
105
100
|
streamingRenderTimer = null;
|
|
106
101
|
constructor(writeStream = process.stdout, config = {}) {
|
|
107
102
|
super();
|
|
108
103
|
this.out = writeStream;
|
|
109
|
-
// Use schema defaults for configuration consistency
|
|
110
104
|
this.config = {
|
|
111
|
-
maxLines: config.maxLines ??
|
|
112
|
-
maxLength: config.maxLength ??
|
|
105
|
+
maxLines: config.maxLines ?? 1000,
|
|
106
|
+
maxLength: config.maxLength ?? 10000,
|
|
113
107
|
maxQueueSize: config.maxQueueSize ?? 100,
|
|
114
|
-
promptChar: config.promptChar ??
|
|
115
|
-
continuationChar: config.continuationChar ??
|
|
108
|
+
promptChar: config.promptChar ?? '> ',
|
|
109
|
+
continuationChar: config.continuationChar ?? '│ ',
|
|
116
110
|
};
|
|
117
111
|
}
|
|
118
112
|
// ===========================================================================
|
|
@@ -191,11 +185,6 @@ export class TerminalInput extends EventEmitter {
|
|
|
191
185
|
if (handled)
|
|
192
186
|
return;
|
|
193
187
|
}
|
|
194
|
-
// Handle '?' for help hint (if buffer is empty)
|
|
195
|
-
if (str === '?' && this.buffer.length === 0) {
|
|
196
|
-
this.emit('showHelp');
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
188
|
// Insert printable characters
|
|
200
189
|
if (str && !key?.ctrl && !key?.meta) {
|
|
201
190
|
this.insertText(str);
|
|
@@ -204,176 +193,26 @@ export class TerminalInput extends EventEmitter {
|
|
|
204
193
|
/**
|
|
205
194
|
* Set the input mode
|
|
206
195
|
*
|
|
207
|
-
* Streaming
|
|
208
|
-
*
|
|
209
|
-
* the cursor is (below the streamed content).
|
|
196
|
+
* Streaming keeps the scroll region active so the prompt/status stay pinned
|
|
197
|
+
* below the streaming output. When streaming ends, we refresh the input area.
|
|
210
198
|
*/
|
|
211
199
|
setMode(mode) {
|
|
212
200
|
const prevMode = this.mode;
|
|
213
201
|
this.mode = mode;
|
|
214
202
|
if (mode === 'streaming' && prevMode !== 'streaming') {
|
|
215
|
-
//
|
|
216
|
-
this.
|
|
217
|
-
const { rows } = this.getSize();
|
|
218
|
-
// Clear old input area content before streaming (prevents duplicates)
|
|
219
|
-
for (let i = rows - 6; i <= rows; i++) {
|
|
220
|
-
this.write(ESC.TO(i, 1));
|
|
221
|
-
this.write(ESC.CLEAR_LINE);
|
|
222
|
-
}
|
|
223
|
-
// Full input area during streaming (status + divider + input + divider + controls)
|
|
224
|
-
// User can still type and queue messages
|
|
225
|
-
const inputAreaLines = 5;
|
|
226
|
-
this.reservedLines = inputAreaLines;
|
|
227
|
-
// Enable scroll region to keep input area pinned at bottom
|
|
203
|
+
// Keep scroll region active so status/prompt stay pinned while streaming
|
|
204
|
+
this.resetStreamingRenderThrottle();
|
|
228
205
|
this.enableScrollRegion();
|
|
229
|
-
// Render full input area at absolute bottom (user can queue messages)
|
|
230
|
-
this.forceRender();
|
|
231
|
-
// Position cursor at bottom of scroll region for streaming content
|
|
232
|
-
const scrollBottom = Math.max(1, rows - this.reservedLines);
|
|
233
|
-
this.write(ESC.TO(scrollBottom, 1));
|
|
234
|
-
// Start timer to update elapsed time in status bar (every 1 second)
|
|
235
|
-
this.streamingRenderTimer = setInterval(() => {
|
|
236
|
-
if (this.mode === 'streaming') {
|
|
237
|
-
this.renderStreamingStatusOnly();
|
|
238
|
-
}
|
|
239
|
-
}, 1000);
|
|
240
206
|
this.renderDirty = true;
|
|
207
|
+
this.render();
|
|
241
208
|
}
|
|
242
209
|
else if (mode !== 'streaming' && prevMode === 'streaming') {
|
|
243
|
-
//
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
this.streamingRenderTimer = null;
|
|
247
|
-
}
|
|
248
|
-
// Reset streaming time
|
|
249
|
-
this.streamingStartTime = null;
|
|
250
|
-
// Disable scroll region
|
|
251
|
-
this.disableScrollRegion();
|
|
252
|
-
// Show cursor again
|
|
253
|
-
this.write(ESC.SHOW);
|
|
254
|
-
// Position cursor at end of content area and add newline
|
|
255
|
-
const { rows } = this.getSize();
|
|
256
|
-
const contentEnd = Math.max(1, rows - this.reservedLines);
|
|
257
|
-
this.write(ESC.TO(contentEnd, 1));
|
|
258
|
-
this.write('\n');
|
|
259
|
-
// Reset flow mode tracking
|
|
260
|
-
this.flowModeRenderedLines = 0;
|
|
261
|
-
// Re-render the input area in normal mode
|
|
210
|
+
// Streaming ended - render the input area
|
|
211
|
+
this.resetStreamingRenderThrottle();
|
|
212
|
+
this.enableScrollRegion();
|
|
262
213
|
this.forceRender();
|
|
263
214
|
}
|
|
264
215
|
}
|
|
265
|
-
/**
|
|
266
|
-
* Enable or disable flow mode.
|
|
267
|
-
* In flow mode, the input renders immediately after content (wherever cursor is).
|
|
268
|
-
* When disabled, input renders at the absolute bottom of terminal.
|
|
269
|
-
*/
|
|
270
|
-
setFlowMode(enabled) {
|
|
271
|
-
if (this.flowMode === enabled)
|
|
272
|
-
return;
|
|
273
|
-
this.flowMode = enabled;
|
|
274
|
-
this.renderDirty = true;
|
|
275
|
-
this.scheduleRender();
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Check if flow mode is enabled.
|
|
279
|
-
*/
|
|
280
|
-
isFlowMode() {
|
|
281
|
-
return this.flowMode;
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Set available slash commands for auto-complete suggestions.
|
|
285
|
-
*/
|
|
286
|
-
setCommands(commands) {
|
|
287
|
-
this.commandSuggestions = commands;
|
|
288
|
-
this.updateSuggestions();
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Update filtered suggestions based on current input.
|
|
292
|
-
*/
|
|
293
|
-
updateSuggestions() {
|
|
294
|
-
const input = this.buffer.trim();
|
|
295
|
-
// Only show suggestions when input starts with "/"
|
|
296
|
-
if (!input.startsWith('/')) {
|
|
297
|
-
this.showSuggestions = false;
|
|
298
|
-
this.filteredSuggestions = [];
|
|
299
|
-
this.selectedSuggestionIndex = 0;
|
|
300
|
-
return;
|
|
301
|
-
}
|
|
302
|
-
const query = input.toLowerCase();
|
|
303
|
-
this.filteredSuggestions = this.commandSuggestions.filter(cmd => cmd.command.toLowerCase().startsWith(query) ||
|
|
304
|
-
cmd.command.toLowerCase().includes(query.slice(1)));
|
|
305
|
-
// Show suggestions if we have matches
|
|
306
|
-
this.showSuggestions = this.filteredSuggestions.length > 0;
|
|
307
|
-
// Keep selection in bounds
|
|
308
|
-
if (this.selectedSuggestionIndex >= this.filteredSuggestions.length) {
|
|
309
|
-
this.selectedSuggestionIndex = Math.max(0, this.filteredSuggestions.length - 1);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
/**
|
|
313
|
-
* Select next suggestion (arrow down / tab).
|
|
314
|
-
*/
|
|
315
|
-
selectNextSuggestion() {
|
|
316
|
-
if (!this.showSuggestions || this.filteredSuggestions.length === 0)
|
|
317
|
-
return;
|
|
318
|
-
this.selectedSuggestionIndex = (this.selectedSuggestionIndex + 1) % this.filteredSuggestions.length;
|
|
319
|
-
this.renderDirty = true;
|
|
320
|
-
this.scheduleRender();
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* Select previous suggestion (arrow up / shift+tab).
|
|
324
|
-
*/
|
|
325
|
-
selectPrevSuggestion() {
|
|
326
|
-
if (!this.showSuggestions || this.filteredSuggestions.length === 0)
|
|
327
|
-
return;
|
|
328
|
-
this.selectedSuggestionIndex = this.selectedSuggestionIndex === 0
|
|
329
|
-
? this.filteredSuggestions.length - 1
|
|
330
|
-
: this.selectedSuggestionIndex - 1;
|
|
331
|
-
this.renderDirty = true;
|
|
332
|
-
this.scheduleRender();
|
|
333
|
-
}
|
|
334
|
-
/**
|
|
335
|
-
* Accept current suggestion and insert into buffer.
|
|
336
|
-
*/
|
|
337
|
-
acceptSuggestion() {
|
|
338
|
-
if (!this.showSuggestions || this.filteredSuggestions.length === 0)
|
|
339
|
-
return false;
|
|
340
|
-
const selected = this.filteredSuggestions[this.selectedSuggestionIndex];
|
|
341
|
-
if (!selected)
|
|
342
|
-
return false;
|
|
343
|
-
// Replace buffer with selected command
|
|
344
|
-
this.buffer = selected.command + ' ';
|
|
345
|
-
this.cursor = this.buffer.length;
|
|
346
|
-
this.showSuggestions = false;
|
|
347
|
-
this.renderDirty = true;
|
|
348
|
-
this.scheduleRender();
|
|
349
|
-
return true;
|
|
350
|
-
}
|
|
351
|
-
/**
|
|
352
|
-
* Check if suggestions are visible.
|
|
353
|
-
*/
|
|
354
|
-
areSuggestionsVisible() {
|
|
355
|
-
return this.showSuggestions && this.filteredSuggestions.length > 0;
|
|
356
|
-
}
|
|
357
|
-
/**
|
|
358
|
-
* Update token count for metrics display
|
|
359
|
-
*/
|
|
360
|
-
setTokensUsed(tokens) {
|
|
361
|
-
this.tokensUsed = tokens;
|
|
362
|
-
}
|
|
363
|
-
/**
|
|
364
|
-
* Toggle thinking/reasoning mode
|
|
365
|
-
*/
|
|
366
|
-
toggleThinking() {
|
|
367
|
-
this.thinkingEnabled = !this.thinkingEnabled;
|
|
368
|
-
this.emit('thinkingToggle', this.thinkingEnabled);
|
|
369
|
-
this.scheduleRender();
|
|
370
|
-
}
|
|
371
|
-
/**
|
|
372
|
-
* Get thinking enabled state
|
|
373
|
-
*/
|
|
374
|
-
isThinkingEnabled() {
|
|
375
|
-
return this.thinkingEnabled;
|
|
376
|
-
}
|
|
377
216
|
/**
|
|
378
217
|
* Keep the top N rows pinned outside the scroll region (used for the launch banner).
|
|
379
218
|
*/
|
|
@@ -386,42 +225,6 @@ export class TerminalInput extends EventEmitter {
|
|
|
386
225
|
}
|
|
387
226
|
}
|
|
388
227
|
}
|
|
389
|
-
/**
|
|
390
|
-
* Anchor prompt rendering near a specific row (inline layout). Pass null to
|
|
391
|
-
* restore the default bottom-aligned layout.
|
|
392
|
-
*/
|
|
393
|
-
setInlineAnchor(row) {
|
|
394
|
-
if (row === null || row === undefined) {
|
|
395
|
-
this.inlineAnchorRow = null;
|
|
396
|
-
this.inlineLayout = false;
|
|
397
|
-
this.renderDirty = true;
|
|
398
|
-
this.render();
|
|
399
|
-
return;
|
|
400
|
-
}
|
|
401
|
-
const { rows } = this.getSize();
|
|
402
|
-
const clamped = Math.max(1, Math.min(Math.floor(row), rows));
|
|
403
|
-
this.inlineAnchorRow = clamped;
|
|
404
|
-
this.inlineLayout = true;
|
|
405
|
-
this.renderDirty = true;
|
|
406
|
-
this.render();
|
|
407
|
-
}
|
|
408
|
-
/**
|
|
409
|
-
* Provide a dynamic anchor callback. When set, the prompt will follow the
|
|
410
|
-
* output by re-evaluating the anchor before each render.
|
|
411
|
-
*/
|
|
412
|
-
setInlineAnchorProvider(provider) {
|
|
413
|
-
this.anchorProvider = provider;
|
|
414
|
-
if (!provider) {
|
|
415
|
-
this.inlineLayout = false;
|
|
416
|
-
this.inlineAnchorRow = null;
|
|
417
|
-
this.renderDirty = true;
|
|
418
|
-
this.render();
|
|
419
|
-
return;
|
|
420
|
-
}
|
|
421
|
-
this.inlineLayout = true;
|
|
422
|
-
this.renderDirty = true;
|
|
423
|
-
this.render();
|
|
424
|
-
}
|
|
425
228
|
/**
|
|
426
229
|
* Get current mode
|
|
427
230
|
*/
|
|
@@ -531,6 +334,37 @@ export class TerminalInput extends EventEmitter {
|
|
|
531
334
|
this.streamingLabel = next;
|
|
532
335
|
this.scheduleRender();
|
|
533
336
|
}
|
|
337
|
+
/**
|
|
338
|
+
* Surface meta status just above the divider (e.g., elapsed time or token usage).
|
|
339
|
+
*/
|
|
340
|
+
setMetaStatus(meta) {
|
|
341
|
+
const nextElapsed = typeof meta.elapsedSeconds === 'number' && Number.isFinite(meta.elapsedSeconds) && meta.elapsedSeconds >= 0
|
|
342
|
+
? Math.floor(meta.elapsedSeconds)
|
|
343
|
+
: null;
|
|
344
|
+
const nextTokens = typeof meta.tokensUsed === 'number' && Number.isFinite(meta.tokensUsed) && meta.tokensUsed >= 0
|
|
345
|
+
? Math.floor(meta.tokensUsed)
|
|
346
|
+
: null;
|
|
347
|
+
const nextLimit = typeof meta.tokenLimit === 'number' && Number.isFinite(meta.tokenLimit) && meta.tokenLimit > 0
|
|
348
|
+
? Math.floor(meta.tokenLimit)
|
|
349
|
+
: null;
|
|
350
|
+
const nextThinking = typeof meta.thinkingMs === 'number' && Number.isFinite(meta.thinkingMs) && meta.thinkingMs >= 0
|
|
351
|
+
? Math.floor(meta.thinkingMs)
|
|
352
|
+
: null;
|
|
353
|
+
const nextThinkingHasContent = !!meta.thinkingHasContent;
|
|
354
|
+
if (this.metaElapsedSeconds === nextElapsed &&
|
|
355
|
+
this.metaTokensUsed === nextTokens &&
|
|
356
|
+
this.metaTokenLimit === nextLimit &&
|
|
357
|
+
this.metaThinkingMs === nextThinking &&
|
|
358
|
+
this.metaThinkingHasContent === nextThinkingHasContent) {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
this.metaElapsedSeconds = nextElapsed;
|
|
362
|
+
this.metaTokensUsed = nextTokens;
|
|
363
|
+
this.metaTokenLimit = nextLimit;
|
|
364
|
+
this.metaThinkingMs = nextThinking;
|
|
365
|
+
this.metaThinkingHasContent = nextThinkingHasContent;
|
|
366
|
+
this.scheduleRender();
|
|
367
|
+
}
|
|
534
368
|
/**
|
|
535
369
|
* Keep mode toggles (verification/auto-continue) visible in the control bar.
|
|
536
370
|
* Hotkey labels remain stable so the bar looks the same before/during streaming.
|
|
@@ -540,16 +374,19 @@ export class TerminalInput extends EventEmitter {
|
|
|
540
374
|
const nextAutoContinue = !!options.autoContinueEnabled;
|
|
541
375
|
const nextVerifyHotkey = options.verificationHotkey ?? this.verificationHotkey;
|
|
542
376
|
const nextAutoHotkey = options.autoContinueHotkey ?? this.autoContinueHotkey;
|
|
377
|
+
const nextThinkingLabel = options.thinkingModeLabel === undefined ? this.thinkingModeLabel : (options.thinkingModeLabel || null);
|
|
543
378
|
if (this.verificationEnabled === nextVerification &&
|
|
544
379
|
this.autoContinueEnabled === nextAutoContinue &&
|
|
545
380
|
this.verificationHotkey === nextVerifyHotkey &&
|
|
546
|
-
this.autoContinueHotkey === nextAutoHotkey
|
|
381
|
+
this.autoContinueHotkey === nextAutoHotkey &&
|
|
382
|
+
this.thinkingModeLabel === nextThinkingLabel) {
|
|
547
383
|
return;
|
|
548
384
|
}
|
|
549
385
|
this.verificationEnabled = nextVerification;
|
|
550
386
|
this.autoContinueEnabled = nextAutoContinue;
|
|
551
387
|
this.verificationHotkey = nextVerifyHotkey;
|
|
552
388
|
this.autoContinueHotkey = nextAutoHotkey;
|
|
389
|
+
this.thinkingModeLabel = nextThinkingLabel;
|
|
553
390
|
this.scheduleRender();
|
|
554
391
|
}
|
|
555
392
|
/**
|
|
@@ -564,183 +401,91 @@ export class TerminalInput extends EventEmitter {
|
|
|
564
401
|
/**
|
|
565
402
|
* Render the input area - Claude Code style with mode controls
|
|
566
403
|
*
|
|
567
|
-
* During streaming
|
|
568
|
-
*
|
|
404
|
+
* During streaming we keep the scroll region active and repaint only the
|
|
405
|
+
* pinned status/input block (throttled) so streamed content can scroll
|
|
406
|
+
* naturally above while elapsed time and status stay fresh.
|
|
569
407
|
*/
|
|
570
408
|
render() {
|
|
571
409
|
if (!this.canRender())
|
|
572
410
|
return;
|
|
573
411
|
if (this.isRendering)
|
|
574
412
|
return;
|
|
413
|
+
const streamingActive = this.mode === 'streaming' || isStreamingMode();
|
|
414
|
+
// During streaming we still render the pinned input/status region, but throttle
|
|
415
|
+
// to avoid fighting with the streamed content flow.
|
|
416
|
+
if (streamingActive && this.lastStreamingRender > 0) {
|
|
417
|
+
const elapsed = Date.now() - this.lastStreamingRender;
|
|
418
|
+
const waitMs = Math.max(0, this.streamingRenderInterval - elapsed);
|
|
419
|
+
if (waitMs > 0) {
|
|
420
|
+
this.renderDirty = true;
|
|
421
|
+
this.scheduleStreamingRender(waitMs);
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
575
425
|
const shouldSkip = !this.renderDirty &&
|
|
576
426
|
this.buffer === this.lastRenderContent &&
|
|
577
427
|
this.cursor === this.lastRenderCursor;
|
|
578
428
|
this.renderDirty = false;
|
|
579
|
-
// Skip if nothing changed
|
|
429
|
+
// Skip if nothing changed and no explicit refresh requested
|
|
580
430
|
if (shouldSkip) {
|
|
581
431
|
return;
|
|
582
432
|
}
|
|
583
|
-
// If write lock is held, defer render
|
|
433
|
+
// If write lock is held, defer render to avoid race conditions
|
|
584
434
|
if (writeLock.isLocked()) {
|
|
585
435
|
writeLock.safeWrite(() => this.render());
|
|
586
436
|
return;
|
|
587
437
|
}
|
|
588
438
|
this.isRendering = true;
|
|
439
|
+
// Use write lock during render to prevent interleaved output
|
|
589
440
|
writeLock.lock('terminalInput.render');
|
|
590
441
|
try {
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
}
|
|
594
|
-
finally {
|
|
595
|
-
writeLock.unlock();
|
|
596
|
-
this.isRendering = false;
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
/**
|
|
600
|
-
* Render in flow mode - delegates to bottom-pinned for stability.
|
|
601
|
-
*
|
|
602
|
-
* Flow mode attempted inline rendering but caused duplicate renders
|
|
603
|
-
* due to unreliable cursor position tracking. Bottom-pinned is reliable.
|
|
604
|
-
*/
|
|
605
|
-
renderFlowMode() {
|
|
606
|
-
// Use stable bottom-pinned approach
|
|
607
|
-
this.renderBottomPinned();
|
|
608
|
-
}
|
|
609
|
-
/**
|
|
610
|
-
* Render in bottom-pinned mode - Claude Code style with suggestions
|
|
611
|
-
*
|
|
612
|
-
* Layout when suggestions visible:
|
|
613
|
-
* - Top divider
|
|
614
|
-
* - Input line(s)
|
|
615
|
-
* - Bottom divider
|
|
616
|
-
* - Suggestions (command list)
|
|
617
|
-
*
|
|
618
|
-
* Layout when suggestions hidden:
|
|
619
|
-
* - Status bar (Ready/Streaming)
|
|
620
|
-
* - Top divider
|
|
621
|
-
* - Input line(s)
|
|
622
|
-
* - Bottom divider
|
|
623
|
-
* - Mode controls
|
|
624
|
-
*/
|
|
625
|
-
renderBottomPinned() {
|
|
626
|
-
const { rows, cols } = this.getSize();
|
|
627
|
-
const maxWidth = Math.max(8, cols - 4);
|
|
628
|
-
// Wrap buffer into display lines
|
|
629
|
-
const { lines, cursorLine, cursorCol } = this.wrapBuffer(maxWidth);
|
|
630
|
-
const availableForContent = Math.max(1, rows - 3);
|
|
631
|
-
const maxVisible = Math.max(1, Math.min(this.config.maxLines, availableForContent));
|
|
632
|
-
const displayLines = Math.min(lines.length, maxVisible);
|
|
633
|
-
// Calculate display window (keep cursor visible)
|
|
634
|
-
let startLine = 0;
|
|
635
|
-
if (lines.length > displayLines) {
|
|
636
|
-
startLine = Math.max(0, cursorLine - displayLines + 1);
|
|
637
|
-
startLine = Math.min(startLine, lines.length - displayLines);
|
|
638
|
-
}
|
|
639
|
-
const visibleLines = lines.slice(startLine, startLine + displayLines);
|
|
640
|
-
const adjustedCursorLine = cursorLine - startLine;
|
|
641
|
-
// Calculate suggestion display
|
|
642
|
-
const suggestionsToShow = this.showSuggestions
|
|
643
|
-
? this.filteredSuggestions.slice(0, this.maxVisibleSuggestions)
|
|
644
|
-
: [];
|
|
645
|
-
const suggestionLines = suggestionsToShow.length;
|
|
646
|
-
this.write(ESC.HIDE);
|
|
647
|
-
this.write(ESC.RESET);
|
|
648
|
-
const divider = renderDivider(cols - 2);
|
|
649
|
-
// Calculate positions from absolute bottom
|
|
650
|
-
let currentRow;
|
|
651
|
-
if (suggestionLines > 0) {
|
|
652
|
-
// With suggestions: input area + dividers + suggestions
|
|
653
|
-
// Layout: [topDiv] [input] [bottomDiv] [suggestions...]
|
|
654
|
-
const totalHeight = 2 + visibleLines.length + suggestionLines; // 2 dividers
|
|
655
|
-
currentRow = Math.max(1, rows - totalHeight + 1);
|
|
656
|
-
this.updateReservedLines(totalHeight);
|
|
657
|
-
// Top divider
|
|
658
|
-
this.write(ESC.TO(currentRow, 1));
|
|
659
|
-
this.write(ESC.CLEAR_LINE);
|
|
660
|
-
this.write(divider);
|
|
661
|
-
currentRow++;
|
|
662
|
-
// Input lines
|
|
663
|
-
let finalRow = currentRow;
|
|
664
|
-
let finalCol = 3;
|
|
665
|
-
for (let i = 0; i < visibleLines.length; i++) {
|
|
666
|
-
this.write(ESC.TO(currentRow, 1));
|
|
667
|
-
this.write(ESC.CLEAR_LINE);
|
|
668
|
-
const line = visibleLines[i] ?? '';
|
|
669
|
-
const absoluteLineIdx = startLine + i;
|
|
670
|
-
const isFirstLine = absoluteLineIdx === 0;
|
|
671
|
-
const isCursorLine = i === adjustedCursorLine;
|
|
672
|
-
this.write(isFirstLine ? this.config.promptChar : this.config.continuationChar);
|
|
673
|
-
if (isCursorLine) {
|
|
674
|
-
const col = Math.min(cursorCol, line.length);
|
|
675
|
-
this.write(line.slice(0, col));
|
|
676
|
-
this.write(ESC.REVERSE);
|
|
677
|
-
this.write(col < line.length ? line[col] : ' ');
|
|
678
|
-
this.write(ESC.RESET);
|
|
679
|
-
this.write(line.slice(col + 1));
|
|
680
|
-
finalRow = currentRow;
|
|
681
|
-
finalCol = this.config.promptChar.length + col + 1;
|
|
682
|
-
}
|
|
683
|
-
else {
|
|
684
|
-
this.write(line);
|
|
685
|
-
}
|
|
686
|
-
currentRow++;
|
|
442
|
+
if (!this.scrollRegionActive) {
|
|
443
|
+
this.enableScrollRegion();
|
|
687
444
|
}
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
this.
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
445
|
+
const { rows, cols } = this.getSize();
|
|
446
|
+
const maxWidth = Math.max(8, cols - 4);
|
|
447
|
+
// Wrap buffer into display lines
|
|
448
|
+
const { lines, cursorLine, cursorCol } = this.wrapBuffer(maxWidth);
|
|
449
|
+
const availableForContent = Math.max(1, rows - 3); // room for separator + input + controls
|
|
450
|
+
const maxVisible = Math.max(1, Math.min(this.config.maxLines, availableForContent));
|
|
451
|
+
const displayLines = Math.min(lines.length, maxVisible);
|
|
452
|
+
const metaLines = this.buildMetaLines(cols - 2);
|
|
453
|
+
// Reserved lines: optional meta lines + separator(1) + input lines + controls(1)
|
|
454
|
+
this.updateReservedLines(displayLines + 2 + metaLines.length);
|
|
455
|
+
// Calculate display window (keep cursor visible)
|
|
456
|
+
let startLine = 0;
|
|
457
|
+
if (lines.length > displayLines) {
|
|
458
|
+
startLine = Math.max(0, cursorLine - displayLines + 1);
|
|
459
|
+
startLine = Math.min(startLine, lines.length - displayLines);
|
|
460
|
+
}
|
|
461
|
+
const visibleLines = lines.slice(startLine, startLine + displayLines);
|
|
462
|
+
const adjustedCursorLine = cursorLine - startLine;
|
|
463
|
+
// Render
|
|
464
|
+
this.write(ESC.HIDE);
|
|
465
|
+
this.write(ESC.RESET);
|
|
466
|
+
const startRow = Math.max(1, rows - this.reservedLines + 1);
|
|
467
|
+
let currentRow = startRow;
|
|
468
|
+
// Clear the reserved block to avoid stale meta/status lines
|
|
469
|
+
this.clearReservedArea(startRow, this.reservedLines, cols);
|
|
470
|
+
// Meta/status header (elapsed, tokens/context)
|
|
471
|
+
for (const metaLine of metaLines) {
|
|
695
472
|
this.write(ESC.TO(currentRow, 1));
|
|
696
473
|
this.write(ESC.CLEAR_LINE);
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
// Indent and highlight selected
|
|
700
|
-
this.write(' ');
|
|
701
|
-
if (isSelected) {
|
|
702
|
-
this.write(ESC.REVERSE);
|
|
703
|
-
this.write(ESC.BOLD);
|
|
704
|
-
}
|
|
705
|
-
this.write(suggestion.command);
|
|
706
|
-
if (isSelected) {
|
|
707
|
-
this.write(ESC.RESET);
|
|
708
|
-
}
|
|
709
|
-
// Description (dimmed)
|
|
710
|
-
const descSpace = cols - suggestion.command.length - 8;
|
|
711
|
-
if (descSpace > 10 && suggestion.description) {
|
|
712
|
-
const desc = suggestion.description.slice(0, descSpace);
|
|
713
|
-
this.write(ESC.RESET);
|
|
714
|
-
this.write(ESC.DIM);
|
|
715
|
-
this.write(' ');
|
|
716
|
-
this.write(desc);
|
|
717
|
-
this.write(ESC.RESET);
|
|
718
|
-
}
|
|
719
|
-
currentRow++;
|
|
474
|
+
this.write(metaLine);
|
|
475
|
+
currentRow += 1;
|
|
720
476
|
}
|
|
721
|
-
//
|
|
722
|
-
this.write(ESC.TO(finalRow, Math.min(finalCol, cols)));
|
|
723
|
-
}
|
|
724
|
-
else {
|
|
725
|
-
// Without suggestions: normal layout with status bar and controls
|
|
726
|
-
const totalHeight = visibleLines.length + 4; // status + topDiv + input + bottomDiv + controls
|
|
727
|
-
currentRow = Math.max(1, rows - totalHeight + 1);
|
|
728
|
-
this.updateReservedLines(totalHeight);
|
|
729
|
-
// Status bar
|
|
730
|
-
this.write(ESC.TO(currentRow, 1));
|
|
731
|
-
this.write(ESC.CLEAR_LINE);
|
|
732
|
-
this.write(this.buildStatusBar(cols));
|
|
733
|
-
currentRow++;
|
|
734
|
-
// Top divider
|
|
477
|
+
// Separator line
|
|
735
478
|
this.write(ESC.TO(currentRow, 1));
|
|
736
479
|
this.write(ESC.CLEAR_LINE);
|
|
480
|
+
const divider = renderDivider(cols - 2);
|
|
737
481
|
this.write(divider);
|
|
738
|
-
currentRow
|
|
739
|
-
//
|
|
482
|
+
currentRow += 1;
|
|
483
|
+
// Render input lines
|
|
740
484
|
let finalRow = currentRow;
|
|
741
485
|
let finalCol = 3;
|
|
742
486
|
for (let i = 0; i < visibleLines.length; i++) {
|
|
743
|
-
|
|
487
|
+
const rowNum = currentRow + i;
|
|
488
|
+
this.write(ESC.TO(rowNum, 1));
|
|
744
489
|
this.write(ESC.CLEAR_LINE);
|
|
745
490
|
const line = visibleLines[i] ?? '';
|
|
746
491
|
const absoluteLineIdx = startLine + i;
|
|
@@ -754,6 +499,7 @@ export class TerminalInput extends EventEmitter {
|
|
|
754
499
|
this.write(ESC.RESET);
|
|
755
500
|
this.write(ESC.BG_DARK);
|
|
756
501
|
if (isCursorLine) {
|
|
502
|
+
// Render with block cursor
|
|
757
503
|
const col = Math.min(cursorCol, line.length);
|
|
758
504
|
const before = line.slice(0, col);
|
|
759
505
|
const at = col < line.length ? line[col] : ' ';
|
|
@@ -763,149 +509,219 @@ export class TerminalInput extends EventEmitter {
|
|
|
763
509
|
this.write(at);
|
|
764
510
|
this.write(ESC.RESET + ESC.BG_DARK);
|
|
765
511
|
this.write(after);
|
|
766
|
-
finalRow =
|
|
512
|
+
finalRow = rowNum;
|
|
767
513
|
finalCol = this.config.promptChar.length + col + 1;
|
|
768
514
|
}
|
|
769
515
|
else {
|
|
770
516
|
this.write(line);
|
|
771
517
|
}
|
|
772
|
-
// Pad to edge
|
|
518
|
+
// Pad to edge for clean look
|
|
773
519
|
const lineLen = this.config.promptChar.length + line.length + (isCursorLine && cursorCol >= line.length ? 1 : 0);
|
|
774
520
|
const padding = Math.max(0, cols - lineLen - 1);
|
|
775
521
|
if (padding > 0)
|
|
776
522
|
this.write(' '.repeat(padding));
|
|
777
523
|
this.write(ESC.RESET);
|
|
778
|
-
currentRow++;
|
|
779
524
|
}
|
|
780
|
-
//
|
|
781
|
-
|
|
782
|
-
this.write(ESC.
|
|
783
|
-
this.write(divider);
|
|
784
|
-
currentRow++;
|
|
785
|
-
// Mode controls
|
|
786
|
-
this.write(ESC.TO(currentRow, 1));
|
|
525
|
+
// Mode controls line (Claude Code style)
|
|
526
|
+
const controlRow = currentRow + visibleLines.length;
|
|
527
|
+
this.write(ESC.TO(controlRow, 1));
|
|
787
528
|
this.write(ESC.CLEAR_LINE);
|
|
788
529
|
this.write(this.buildModeControls(cols));
|
|
789
|
-
// Position cursor
|
|
530
|
+
// Position cursor
|
|
790
531
|
this.write(ESC.TO(finalRow, Math.min(finalCol, cols)));
|
|
532
|
+
this.write(ESC.SHOW);
|
|
533
|
+
// Update state
|
|
534
|
+
this.lastRenderContent = this.buffer;
|
|
535
|
+
this.lastRenderCursor = this.cursor;
|
|
536
|
+
if (streamingActive) {
|
|
537
|
+
this.lastStreamingRender = Date.now();
|
|
538
|
+
}
|
|
539
|
+
else {
|
|
540
|
+
this.lastStreamingRender = 0;
|
|
541
|
+
}
|
|
542
|
+
if (this.streamingRenderTimer) {
|
|
543
|
+
clearTimeout(this.streamingRenderTimer);
|
|
544
|
+
this.streamingRenderTimer = null;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
finally {
|
|
548
|
+
writeLock.unlock();
|
|
549
|
+
this.isRendering = false;
|
|
791
550
|
}
|
|
792
|
-
this.write(ESC.SHOW);
|
|
793
|
-
// Update state
|
|
794
|
-
this.lastRenderContent = this.buffer;
|
|
795
|
-
this.lastRenderCursor = this.cursor;
|
|
796
551
|
}
|
|
797
552
|
/**
|
|
798
|
-
*
|
|
799
|
-
* Uses cursor save/restore to update elapsed time without disrupting streaming.
|
|
553
|
+
* Build one or more compact meta lines above the divider (thinking, status, usage).
|
|
800
554
|
*/
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
const
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
555
|
+
buildMetaLines(width) {
|
|
556
|
+
const lines = [];
|
|
557
|
+
if (this.metaThinkingMs !== null) {
|
|
558
|
+
const thinkingText = formatThinking(this.metaThinkingMs, this.metaThinkingHasContent);
|
|
559
|
+
lines.push(renderStatusLine([{ text: thinkingText, tone: 'info' }], width));
|
|
560
|
+
}
|
|
561
|
+
const statusParts = [];
|
|
562
|
+
const statusLabel = this.statusMessage ?? this.streamingLabel;
|
|
563
|
+
if (statusLabel) {
|
|
564
|
+
statusParts.push({ text: statusLabel, tone: 'info' });
|
|
565
|
+
}
|
|
566
|
+
if (this.mode === 'streaming' || isStreamingMode()) {
|
|
567
|
+
statusParts.push({ text: 'esc to interrupt', tone: 'warn' });
|
|
568
|
+
}
|
|
569
|
+
if (this.metaElapsedSeconds !== null) {
|
|
570
|
+
statusParts.push({ text: this.formatElapsedLabel(this.metaElapsedSeconds), tone: 'muted' });
|
|
571
|
+
}
|
|
572
|
+
const tokensRemaining = this.computeTokensRemaining();
|
|
573
|
+
if (tokensRemaining !== null) {
|
|
574
|
+
statusParts.push({ text: `↓ ${tokensRemaining}`, tone: 'muted' });
|
|
575
|
+
}
|
|
576
|
+
if (statusParts.length) {
|
|
577
|
+
lines.push(renderStatusLine(statusParts, width));
|
|
578
|
+
}
|
|
579
|
+
const usageParts = [];
|
|
580
|
+
if (this.metaTokensUsed !== null) {
|
|
581
|
+
const formattedUsed = this.formatTokenCount(this.metaTokensUsed);
|
|
582
|
+
const formattedLimit = this.metaTokenLimit ? `/${this.formatTokenCount(this.metaTokenLimit)}` : '';
|
|
583
|
+
usageParts.push({ text: `tokens ${formattedUsed}${formattedLimit}`, tone: 'muted' });
|
|
584
|
+
}
|
|
585
|
+
if (this.contextUsage !== null) {
|
|
586
|
+
const tone = this.contextUsage >= 75 ? 'warn' : 'muted';
|
|
587
|
+
const left = Math.max(0, 100 - this.contextUsage);
|
|
588
|
+
usageParts.push({ text: `context used ${this.contextUsage}% (${left}% left)`, tone });
|
|
589
|
+
}
|
|
590
|
+
if (this.queue.length > 0) {
|
|
591
|
+
usageParts.push({ text: `queued ${this.queue.length}`, tone: 'info' });
|
|
592
|
+
}
|
|
593
|
+
if (usageParts.length) {
|
|
594
|
+
lines.push(renderStatusLine(usageParts, width));
|
|
595
|
+
}
|
|
596
|
+
return lines;
|
|
814
597
|
}
|
|
815
598
|
/**
|
|
816
|
-
*
|
|
817
|
-
* This is the TOP line above the input area - minimal Claude Code style.
|
|
599
|
+
* Clear the reserved bottom block (meta + divider + input + controls) before repainting.
|
|
818
600
|
*/
|
|
819
|
-
|
|
820
|
-
const
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
if (this.streamingStartTime) {
|
|
826
|
-
const elapsed = Math.floor((Date.now() - this.streamingStartTime) / 1000);
|
|
827
|
-
const mins = Math.floor(elapsed / 60);
|
|
828
|
-
const secs = elapsed % 60;
|
|
829
|
-
statusText += mins > 0 ? ` ${mins}m ${secs}s` : ` ${secs}s`;
|
|
830
|
-
}
|
|
831
|
-
parts.push(`\x1b[32m${statusText}\x1b[0m`); // Green
|
|
832
|
-
}
|
|
833
|
-
// Queue indicator during streaming
|
|
834
|
-
if (this.mode === 'streaming' && this.queue.length > 0) {
|
|
835
|
-
parts.push(`\x1b[36mqueued: ${this.queue.length}\x1b[0m`); // Cyan
|
|
601
|
+
clearReservedArea(startRow, reservedLines, cols) {
|
|
602
|
+
const width = Math.max(1, cols);
|
|
603
|
+
for (let i = 0; i < reservedLines; i++) {
|
|
604
|
+
const row = startRow + i;
|
|
605
|
+
this.write(ESC.TO(row, 1));
|
|
606
|
+
this.write(' '.repeat(width));
|
|
836
607
|
}
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Build Claude Code style mode controls line.
|
|
611
|
+
* Combines streaming label + override status + main status for simultaneous display.
|
|
612
|
+
*/
|
|
613
|
+
buildModeControls(cols) {
|
|
614
|
+
const width = Math.max(8, cols - 2);
|
|
615
|
+
const leftParts = [];
|
|
616
|
+
const rightParts = [];
|
|
617
|
+
if (this.streamingLabel) {
|
|
618
|
+
leftParts.push({ text: `◐ ${this.streamingLabel}`, tone: 'info' });
|
|
841
619
|
}
|
|
842
|
-
// Override/warning status
|
|
843
620
|
if (this.overrideStatusMessage) {
|
|
844
|
-
|
|
621
|
+
leftParts.push({ text: `⚠ ${this.overrideStatusMessage}`, tone: 'warn' });
|
|
845
622
|
}
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
623
|
+
if (this.statusMessage) {
|
|
624
|
+
leftParts.push({ text: this.statusMessage, tone: this.streamingLabel ? 'muted' : 'info' });
|
|
625
|
+
}
|
|
626
|
+
const editLabel = this.editMode === 'display-edits' ? 'accept edits on' : 'ask before edits';
|
|
627
|
+
const editIcon = this.editMode === 'display-edits' ? '⏵⏵' : '🛡';
|
|
628
|
+
leftParts.push({
|
|
629
|
+
text: `${editIcon} ${editLabel} (shift+tab to cycle)`,
|
|
630
|
+
tone: this.editMode === 'display-edits' ? 'success' : 'muted',
|
|
631
|
+
});
|
|
632
|
+
const verifyLabel = this.verificationEnabled ? 'verify+build on' : 'verify+build off';
|
|
633
|
+
leftParts.push({
|
|
634
|
+
text: `${verifyLabel} (${this.verificationHotkey.toLowerCase()})`,
|
|
635
|
+
tone: this.verificationEnabled ? 'success' : 'muted',
|
|
636
|
+
});
|
|
637
|
+
const continueLabel = this.autoContinueEnabled ? 'auto-continue on' : 'auto-continue off';
|
|
638
|
+
leftParts.push({
|
|
639
|
+
text: `${continueLabel} (${this.autoContinueHotkey.toLowerCase()})`,
|
|
640
|
+
tone: this.autoContinueEnabled ? 'info' : 'muted',
|
|
641
|
+
});
|
|
642
|
+
if (this.queue.length > 0 && this.mode !== 'streaming') {
|
|
643
|
+
leftParts.push({ text: `queued ${this.queue.length}`, tone: 'info' });
|
|
849
644
|
}
|
|
850
|
-
// Multi-line indicator
|
|
851
645
|
if (this.buffer.includes('\n')) {
|
|
852
|
-
|
|
646
|
+
const lineCount = this.buffer.split('\n').length;
|
|
647
|
+
leftParts.push({ text: `${lineCount} lines`, tone: 'muted' });
|
|
648
|
+
}
|
|
649
|
+
if (this.pastePlaceholders.length > 0) {
|
|
650
|
+
const latest = this.pastePlaceholders[this.pastePlaceholders.length - 1];
|
|
651
|
+
leftParts.push({
|
|
652
|
+
text: `paste #${latest.id} +${latest.lineCount} lines (⌫ to drop)`,
|
|
653
|
+
tone: 'info',
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
const contextRemaining = this.computeContextRemaining();
|
|
657
|
+
if (this.thinkingModeLabel) {
|
|
658
|
+
rightParts.push({ text: `thinking ${this.thinkingModeLabel} (/thinking)`, tone: 'info' });
|
|
659
|
+
}
|
|
660
|
+
if (contextRemaining !== null) {
|
|
661
|
+
const tone = contextRemaining <= 10 ? 'warn' : 'muted';
|
|
662
|
+
const label = contextRemaining === 0 && this.contextUsage !== null
|
|
663
|
+
? 'Context auto-compact imminent'
|
|
664
|
+
: `Context left until auto-compact: ${contextRemaining}%`;
|
|
665
|
+
rightParts.push({ text: label, tone });
|
|
853
666
|
}
|
|
854
|
-
if (
|
|
855
|
-
|
|
667
|
+
if (!rightParts.length || width < 60) {
|
|
668
|
+
const merged = rightParts.length ? [...leftParts, ...rightParts] : leftParts;
|
|
669
|
+
return renderStatusLine(merged, width);
|
|
670
|
+
}
|
|
671
|
+
const leftWidth = Math.max(12, Math.floor(width * 0.6));
|
|
672
|
+
const rightWidth = Math.max(14, width - leftWidth - 1);
|
|
673
|
+
const leftText = renderStatusLine(leftParts, leftWidth);
|
|
674
|
+
const rightText = renderStatusLine(rightParts, rightWidth);
|
|
675
|
+
const spacing = Math.max(1, width - this.visibleLength(leftText) - this.visibleLength(rightText));
|
|
676
|
+
return `${leftText}${' '.repeat(spacing)}${rightText}`;
|
|
677
|
+
}
|
|
678
|
+
computeContextRemaining() {
|
|
679
|
+
if (this.contextUsage === null) {
|
|
680
|
+
return null;
|
|
681
|
+
}
|
|
682
|
+
return Math.max(0, this.contextAutoCompactThreshold - this.contextUsage);
|
|
683
|
+
}
|
|
684
|
+
computeTokensRemaining() {
|
|
685
|
+
if (this.metaTokensUsed === null || this.metaTokenLimit === null) {
|
|
686
|
+
return null;
|
|
856
687
|
}
|
|
857
|
-
const
|
|
858
|
-
return
|
|
688
|
+
const remaining = Math.max(0, this.metaTokenLimit - this.metaTokensUsed);
|
|
689
|
+
return this.formatTokenCount(remaining);
|
|
690
|
+
}
|
|
691
|
+
formatElapsedLabel(seconds) {
|
|
692
|
+
if (seconds < 60) {
|
|
693
|
+
return `${seconds}s`;
|
|
694
|
+
}
|
|
695
|
+
const mins = Math.floor(seconds / 60);
|
|
696
|
+
const secs = seconds % 60;
|
|
697
|
+
return secs > 0 ? `${mins}m ${secs}s` : `${mins}m`;
|
|
698
|
+
}
|
|
699
|
+
formatTokenCount(value) {
|
|
700
|
+
if (!Number.isFinite(value)) {
|
|
701
|
+
return `${value}`;
|
|
702
|
+
}
|
|
703
|
+
if (value >= 1_000_000) {
|
|
704
|
+
return `${(value / 1_000_000).toFixed(1)}M`;
|
|
705
|
+
}
|
|
706
|
+
if (value >= 1_000) {
|
|
707
|
+
return `${(value / 1_000).toFixed(1)}k`;
|
|
708
|
+
}
|
|
709
|
+
return `${Math.round(value)}`;
|
|
710
|
+
}
|
|
711
|
+
visibleLength(value) {
|
|
712
|
+
const ansiPattern = /\u001B\[[0-?]*[ -/]*[@-~]/g;
|
|
713
|
+
return value.replace(ansiPattern, '').length;
|
|
859
714
|
}
|
|
860
715
|
/**
|
|
861
|
-
*
|
|
862
|
-
*
|
|
863
|
-
*
|
|
864
|
-
* Layout: [toggles on left] ... [context info on right]
|
|
716
|
+
* Debug-only snapshot used by tests to assert rendered strings without
|
|
717
|
+
* needing a TTY. Not used by production code.
|
|
865
718
|
*/
|
|
866
|
-
|
|
867
|
-
const
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
// Edit mode (green=auto, yellow=ask) - per schema.editMode
|
|
873
|
-
if (this.editMode === 'display-edits') {
|
|
874
|
-
toggles.push(`${GREEN}⏵⏵ auto-edit${R}`);
|
|
875
|
-
}
|
|
876
|
-
else {
|
|
877
|
-
toggles.push(`${YELLOW}⏸⏸ ask-first${R}`);
|
|
878
|
-
}
|
|
879
|
-
// Thinking mode (cyan when on) - per schema.thinkingMode
|
|
880
|
-
toggles.push(this.thinkingEnabled ? `${CYAN}💭 think${R}` : `${DIM}○ think${R}`);
|
|
881
|
-
// Verification (green when on) - per schema.verificationMode
|
|
882
|
-
toggles.push(this.verificationEnabled ? `${GREEN}✓ verify${R}` : `${DIM}○ verify${R}`);
|
|
883
|
-
// Auto-continue (magenta when on) - per schema.autoContinueMode
|
|
884
|
-
toggles.push(this.autoContinueEnabled ? `${MAGENTA}↻ auto${R}` : `${DIM}○ auto${R}`);
|
|
885
|
-
const leftPart = toggles.join(`${DIM} · ${R}`) + `${DIM} (⇧⇥)${R}`;
|
|
886
|
-
// Context usage with color - per schema.contextUsage thresholds
|
|
887
|
-
let rightPart = '';
|
|
888
|
-
if (this.contextUsage !== null) {
|
|
889
|
-
const rem = Math.max(0, 100 - this.contextUsage);
|
|
890
|
-
// Thresholds: critical < 10%, warning < 25%
|
|
891
|
-
if (rem < 10)
|
|
892
|
-
rightPart = `${RED}⚠ ctx: ${rem}%${R}`;
|
|
893
|
-
else if (rem < 25)
|
|
894
|
-
rightPart = `${YELLOW}! ctx: ${rem}%${R}`;
|
|
895
|
-
else
|
|
896
|
-
rightPart = `${DIM}ctx: ${rem}%${R}`;
|
|
897
|
-
}
|
|
898
|
-
// Calculate visible lengths (strip ANSI)
|
|
899
|
-
const strip = (s) => s.replace(/\x1b\[[0-9;]*m/g, '');
|
|
900
|
-
const leftLen = strip(leftPart).length;
|
|
901
|
-
const rightLen = strip(rightPart).length;
|
|
902
|
-
if (leftLen + rightLen < maxWidth - 4) {
|
|
903
|
-
return `${leftPart}${' '.repeat(maxWidth - leftLen - rightLen)}${rightPart}`;
|
|
904
|
-
}
|
|
905
|
-
if (rightLen > 0 && leftLen + 8 < maxWidth) {
|
|
906
|
-
return `${leftPart} ${rightPart}`;
|
|
907
|
-
}
|
|
908
|
-
return leftPart;
|
|
719
|
+
getDebugUiSnapshot(width) {
|
|
720
|
+
const cols = Math.max(8, width ?? this.getSize().cols);
|
|
721
|
+
return {
|
|
722
|
+
meta: this.buildMetaLines(cols - 2),
|
|
723
|
+
controls: this.buildModeControls(cols),
|
|
724
|
+
};
|
|
909
725
|
}
|
|
910
726
|
/**
|
|
911
727
|
* Force a re-render
|
|
@@ -928,17 +744,19 @@ export class TerminalInput extends EventEmitter {
|
|
|
928
744
|
handleResize() {
|
|
929
745
|
this.lastRenderContent = '';
|
|
930
746
|
this.lastRenderCursor = -1;
|
|
747
|
+
this.resetStreamingRenderThrottle();
|
|
931
748
|
// Re-clamp pinned header rows to the new terminal height
|
|
932
749
|
this.setPinnedHeaderLines(this.pinnedTopRows);
|
|
750
|
+
if (this.scrollRegionActive) {
|
|
751
|
+
this.disableScrollRegion();
|
|
752
|
+
this.enableScrollRegion();
|
|
753
|
+
}
|
|
933
754
|
this.scheduleRender();
|
|
934
755
|
}
|
|
935
756
|
/**
|
|
936
757
|
* Register with display's output interceptor to position cursor correctly.
|
|
937
758
|
* When scroll region is active, output needs to go to the scroll region,
|
|
938
759
|
* not the protected bottom area where the input is rendered.
|
|
939
|
-
*
|
|
940
|
-
* NOTE: With scroll region properly set, content naturally stays within
|
|
941
|
-
* the region boundaries - no cursor manipulation needed per-write.
|
|
942
760
|
*/
|
|
943
761
|
registerOutputInterceptor(display) {
|
|
944
762
|
if (this.outputInterceptorCleanup) {
|
|
@@ -946,11 +764,20 @@ export class TerminalInput extends EventEmitter {
|
|
|
946
764
|
}
|
|
947
765
|
this.outputInterceptorCleanup = display.registerOutputInterceptor({
|
|
948
766
|
beforeWrite: () => {
|
|
949
|
-
//
|
|
950
|
-
//
|
|
767
|
+
// When the scroll region is active, temporarily move the cursor into
|
|
768
|
+
// the scrollable area so streamed output lands above the pinned prompt.
|
|
769
|
+
if (this.scrollRegionActive) {
|
|
770
|
+
const { rows } = this.getSize();
|
|
771
|
+
const scrollBottom = Math.max(this.pinnedTopRows + 1, rows - this.reservedLines);
|
|
772
|
+
this.write(ESC.SAVE);
|
|
773
|
+
this.write(ESC.TO(scrollBottom, 1));
|
|
774
|
+
}
|
|
951
775
|
},
|
|
952
776
|
afterWrite: () => {
|
|
953
|
-
//
|
|
777
|
+
// Restore cursor back to the pinned prompt after output completes.
|
|
778
|
+
if (this.scrollRegionActive) {
|
|
779
|
+
this.write(ESC.RESTORE);
|
|
780
|
+
}
|
|
954
781
|
},
|
|
955
782
|
});
|
|
956
783
|
}
|
|
@@ -960,11 +787,6 @@ export class TerminalInput extends EventEmitter {
|
|
|
960
787
|
dispose() {
|
|
961
788
|
if (this.disposed)
|
|
962
789
|
return;
|
|
963
|
-
// Clean up streaming render timer
|
|
964
|
-
if (this.streamingRenderTimer) {
|
|
965
|
-
clearInterval(this.streamingRenderTimer);
|
|
966
|
-
this.streamingRenderTimer = null;
|
|
967
|
-
}
|
|
968
790
|
// Clean up output interceptor
|
|
969
791
|
if (this.outputInterceptorCleanup) {
|
|
970
792
|
this.outputInterceptorCleanup();
|
|
@@ -972,6 +794,7 @@ export class TerminalInput extends EventEmitter {
|
|
|
972
794
|
}
|
|
973
795
|
this.disposed = true;
|
|
974
796
|
this.enabled = false;
|
|
797
|
+
this.resetStreamingRenderThrottle();
|
|
975
798
|
this.disableScrollRegion();
|
|
976
799
|
this.disableBracketedPaste();
|
|
977
800
|
this.buffer = '';
|
|
@@ -1077,22 +900,7 @@ export class TerminalInput extends EventEmitter {
|
|
|
1077
900
|
this.toggleEditMode();
|
|
1078
901
|
return true;
|
|
1079
902
|
}
|
|
1080
|
-
|
|
1081
|
-
if (this.findPlaceholderAt(this.cursor)) {
|
|
1082
|
-
this.togglePasteExpansion();
|
|
1083
|
-
}
|
|
1084
|
-
else {
|
|
1085
|
-
this.toggleThinking();
|
|
1086
|
-
}
|
|
1087
|
-
return true;
|
|
1088
|
-
case 'escape':
|
|
1089
|
-
// Esc: interrupt if streaming, otherwise clear buffer
|
|
1090
|
-
if (this.mode === 'streaming') {
|
|
1091
|
-
this.emit('interrupt');
|
|
1092
|
-
}
|
|
1093
|
-
else if (this.buffer.length > 0) {
|
|
1094
|
-
this.clear();
|
|
1095
|
-
}
|
|
903
|
+
this.insertText(' ');
|
|
1096
904
|
return true;
|
|
1097
905
|
}
|
|
1098
906
|
return false;
|
|
@@ -1110,7 +918,6 @@ export class TerminalInput extends EventEmitter {
|
|
|
1110
918
|
this.insertPlainText(chunk, insertPos);
|
|
1111
919
|
this.cursor = insertPos + chunk.length;
|
|
1112
920
|
this.emit('change', this.buffer);
|
|
1113
|
-
this.updateSuggestions();
|
|
1114
921
|
this.scheduleRender();
|
|
1115
922
|
}
|
|
1116
923
|
insertNewline() {
|
|
@@ -1135,7 +942,6 @@ export class TerminalInput extends EventEmitter {
|
|
|
1135
942
|
this.cursor = Math.max(0, this.cursor - 1);
|
|
1136
943
|
}
|
|
1137
944
|
this.emit('change', this.buffer);
|
|
1138
|
-
this.updateSuggestions();
|
|
1139
945
|
this.scheduleRender();
|
|
1140
946
|
}
|
|
1141
947
|
deleteForward() {
|
|
@@ -1385,7 +1191,9 @@ export class TerminalInput extends EventEmitter {
|
|
|
1385
1191
|
if (available <= 0)
|
|
1386
1192
|
return;
|
|
1387
1193
|
const chunk = clean.slice(0, available);
|
|
1388
|
-
|
|
1194
|
+
const isMultiline = isMultilinePaste(chunk);
|
|
1195
|
+
const isShortMultiline = isMultiline && this.shouldInlineMultiline(chunk);
|
|
1196
|
+
if (isMultiline && !isShortMultiline) {
|
|
1389
1197
|
this.insertPastePlaceholder(chunk);
|
|
1390
1198
|
}
|
|
1391
1199
|
else {
|
|
@@ -1405,6 +1213,7 @@ export class TerminalInput extends EventEmitter {
|
|
|
1405
1213
|
return;
|
|
1406
1214
|
this.applyScrollRegion();
|
|
1407
1215
|
this.scrollRegionActive = true;
|
|
1216
|
+
this.forceRender();
|
|
1408
1217
|
}
|
|
1409
1218
|
disableScrollRegion() {
|
|
1410
1219
|
if (!this.scrollRegionActive)
|
|
@@ -1555,17 +1364,19 @@ export class TerminalInput extends EventEmitter {
|
|
|
1555
1364
|
this.shiftPlaceholders(position, text.length);
|
|
1556
1365
|
this.buffer = this.buffer.slice(0, position) + text + this.buffer.slice(position);
|
|
1557
1366
|
}
|
|
1367
|
+
shouldInlineMultiline(content) {
|
|
1368
|
+
const lines = content.split('\n').length;
|
|
1369
|
+
const maxInlineLines = 4;
|
|
1370
|
+
const maxInlineChars = 240;
|
|
1371
|
+
return lines <= maxInlineLines && content.length <= maxInlineChars;
|
|
1372
|
+
}
|
|
1558
1373
|
findPlaceholderAt(position) {
|
|
1559
1374
|
return this.pastePlaceholders.find((ph) => position >= ph.start && position < ph.end) ?? null;
|
|
1560
1375
|
}
|
|
1561
|
-
buildPlaceholder(
|
|
1376
|
+
buildPlaceholder(lineCount) {
|
|
1562
1377
|
const id = ++this.pasteCounter;
|
|
1563
|
-
const
|
|
1564
|
-
|
|
1565
|
-
const preview = summary.preview.length > 30
|
|
1566
|
-
? `${summary.preview.slice(0, 30)}...`
|
|
1567
|
-
: summary.preview;
|
|
1568
|
-
const placeholder = `[📋 #${id}${lang} ${summary.lineCount}L] "${preview}"`;
|
|
1378
|
+
const plural = lineCount === 1 ? '' : 's';
|
|
1379
|
+
const placeholder = `[Pasted text #${id} +${lineCount} line${plural}]`;
|
|
1569
1380
|
return { id, placeholder };
|
|
1570
1381
|
}
|
|
1571
1382
|
insertPastePlaceholder(content) {
|
|
@@ -1573,67 +1384,21 @@ export class TerminalInput extends EventEmitter {
|
|
|
1573
1384
|
if (available <= 0)
|
|
1574
1385
|
return;
|
|
1575
1386
|
const cleanContent = content.slice(0, available);
|
|
1576
|
-
const
|
|
1577
|
-
|
|
1578
|
-
if (summary.lineCount < 5) {
|
|
1579
|
-
const placeholder = this.findPlaceholderAt(this.cursor);
|
|
1580
|
-
const insertPos = placeholder && this.cursor > placeholder.start ? placeholder.end : this.cursor;
|
|
1581
|
-
this.insertPlainText(cleanContent, insertPos);
|
|
1582
|
-
this.cursor = insertPos + cleanContent.length;
|
|
1583
|
-
return;
|
|
1584
|
-
}
|
|
1585
|
-
const { id, placeholder } = this.buildPlaceholder(summary);
|
|
1387
|
+
const lineCount = cleanContent.split('\n').length;
|
|
1388
|
+
const { id, placeholder } = this.buildPlaceholder(lineCount);
|
|
1586
1389
|
const insertPos = this.cursor;
|
|
1587
1390
|
this.shiftPlaceholders(insertPos, placeholder.length);
|
|
1588
1391
|
this.pastePlaceholders.push({
|
|
1589
1392
|
id,
|
|
1590
1393
|
content: cleanContent,
|
|
1591
|
-
lineCount
|
|
1394
|
+
lineCount,
|
|
1592
1395
|
placeholder,
|
|
1593
1396
|
start: insertPos,
|
|
1594
1397
|
end: insertPos + placeholder.length,
|
|
1595
|
-
summary,
|
|
1596
|
-
expanded: false,
|
|
1597
1398
|
});
|
|
1598
1399
|
this.buffer = this.buffer.slice(0, insertPos) + placeholder + this.buffer.slice(insertPos);
|
|
1599
1400
|
this.cursor = insertPos + placeholder.length;
|
|
1600
1401
|
}
|
|
1601
|
-
/**
|
|
1602
|
-
* Toggle expansion of a paste placeholder at the current cursor position.
|
|
1603
|
-
* When expanded, shows first 3 and last 2 lines of the content.
|
|
1604
|
-
*/
|
|
1605
|
-
togglePasteExpansion() {
|
|
1606
|
-
const placeholder = this.findPlaceholderAt(this.cursor);
|
|
1607
|
-
if (!placeholder)
|
|
1608
|
-
return false;
|
|
1609
|
-
placeholder.expanded = !placeholder.expanded;
|
|
1610
|
-
// Update the placeholder text in buffer
|
|
1611
|
-
const newPlaceholder = placeholder.expanded
|
|
1612
|
-
? this.buildExpandedPlaceholder(placeholder)
|
|
1613
|
-
: this.buildPlaceholder(placeholder.summary).placeholder;
|
|
1614
|
-
const lengthDiff = newPlaceholder.length - placeholder.placeholder.length;
|
|
1615
|
-
// Update buffer
|
|
1616
|
-
this.buffer =
|
|
1617
|
-
this.buffer.slice(0, placeholder.start) +
|
|
1618
|
-
newPlaceholder +
|
|
1619
|
-
this.buffer.slice(placeholder.end);
|
|
1620
|
-
// Update placeholder tracking
|
|
1621
|
-
placeholder.placeholder = newPlaceholder;
|
|
1622
|
-
placeholder.end = placeholder.start + newPlaceholder.length;
|
|
1623
|
-
// Shift other placeholders
|
|
1624
|
-
this.shiftPlaceholders(placeholder.end, lengthDiff, placeholder.id);
|
|
1625
|
-
this.scheduleRender();
|
|
1626
|
-
return true;
|
|
1627
|
-
}
|
|
1628
|
-
buildExpandedPlaceholder(ph) {
|
|
1629
|
-
const lines = ph.content.split('\n');
|
|
1630
|
-
const firstLines = lines.slice(0, 3).map(l => l.slice(0, 60)).join('\n');
|
|
1631
|
-
const lastLines = lines.length > 5
|
|
1632
|
-
? '\n...\n' + lines.slice(-2).map(l => l.slice(0, 60)).join('\n')
|
|
1633
|
-
: '';
|
|
1634
|
-
const lang = ph.summary.language ? ` ${ph.summary.language.toUpperCase()}` : '';
|
|
1635
|
-
return `[📋 #${ph.id}${lang} ${ph.lineCount}L ▼]\n${firstLines}${lastLines}\n[/📋 #${ph.id}]`;
|
|
1636
|
-
}
|
|
1637
1402
|
deletePlaceholder(placeholder) {
|
|
1638
1403
|
const length = placeholder.end - placeholder.start;
|
|
1639
1404
|
this.buffer = this.buffer.slice(0, placeholder.start) + this.buffer.slice(placeholder.end);
|
|
@@ -1641,7 +1406,11 @@ export class TerminalInput extends EventEmitter {
|
|
|
1641
1406
|
this.shiftPlaceholders(placeholder.end, -length, placeholder.id);
|
|
1642
1407
|
this.cursor = placeholder.start;
|
|
1643
1408
|
}
|
|
1644
|
-
updateContextUsage(value) {
|
|
1409
|
+
updateContextUsage(value, autoCompactThreshold) {
|
|
1410
|
+
if (typeof autoCompactThreshold === 'number' && Number.isFinite(autoCompactThreshold)) {
|
|
1411
|
+
const boundedThreshold = Math.max(1, Math.min(100, Math.round(autoCompactThreshold)));
|
|
1412
|
+
this.contextAutoCompactThreshold = boundedThreshold;
|
|
1413
|
+
}
|
|
1645
1414
|
if (value === null || !Number.isFinite(value)) {
|
|
1646
1415
|
this.contextUsage = null;
|
|
1647
1416
|
}
|
|
@@ -1668,6 +1437,22 @@ export class TerminalInput extends EventEmitter {
|
|
|
1668
1437
|
const next = this.editMode === 'display-edits' ? 'ask-permission' : 'display-edits';
|
|
1669
1438
|
this.setEditMode(next);
|
|
1670
1439
|
}
|
|
1440
|
+
scheduleStreamingRender(delayMs) {
|
|
1441
|
+
if (this.streamingRenderTimer)
|
|
1442
|
+
return;
|
|
1443
|
+
const wait = Math.max(16, delayMs);
|
|
1444
|
+
this.streamingRenderTimer = setTimeout(() => {
|
|
1445
|
+
this.streamingRenderTimer = null;
|
|
1446
|
+
this.render();
|
|
1447
|
+
}, wait);
|
|
1448
|
+
}
|
|
1449
|
+
resetStreamingRenderThrottle() {
|
|
1450
|
+
if (this.streamingRenderTimer) {
|
|
1451
|
+
clearTimeout(this.streamingRenderTimer);
|
|
1452
|
+
this.streamingRenderTimer = null;
|
|
1453
|
+
}
|
|
1454
|
+
this.lastStreamingRender = 0;
|
|
1455
|
+
}
|
|
1671
1456
|
scheduleRender() {
|
|
1672
1457
|
if (!this.canRender())
|
|
1673
1458
|
return;
|