@causyne/agent 1.20.62 → 1.20.65
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 +2 -2
- package/package.json +1 -1
- package/src/acp/client.js +48 -0
- package/src/acp/client.ts +44 -0
- package/src/agentLoop.js +181 -11
- package/src/agentLoop.ts +184 -11
- package/src/approvalPolicy.js +19 -0
- package/src/approvalPolicy.ts +18 -0
- package/src/browser/causyneBrowser.js +34 -4
- package/src/browser/causyneBrowser.ts +32 -4
- package/src/cliMode.js +12 -28
- package/src/commands.js +33 -0
- package/src/decisionPolicy.js +18 -1
- package/src/decisionPolicy.ts +18 -1
- package/src/implementationPlan.js +26 -0
- package/src/implementationPlan.ts +25 -0
- package/src/observer/coldObserver.js +6 -1
- package/src/observer/coldObserver.ts +6 -1
- package/src/observer.js +24 -2
- package/src/observer.ts +24 -2
- package/src/providers/acp.js +2 -8
- package/src/providers/acp.ts +2 -8
- package/src/providers/antigravity.js +7 -10
- package/src/providers/antigravity.ts +7 -10
- package/src/smartToolsUse.js +1 -1
- package/src/smartToolsUse.ts +1 -1
- package/src/toolPacks.js +1 -1
- package/src/toolPacks.ts +1 -1
- package/src/tools/toolSelfRepair.js +51 -8
- package/src/tools/toolSelfRepair.ts +42 -9
- package/src/tui/CausyneRotor.js +234 -0
- package/src/tui/CausyneRotor.ts +280 -0
- package/src/tui/activityLayout.js +1 -1
- package/src/tui/activityLayout.ts +1 -1
- package/src/tui/chatRenderer.js +56 -7
- package/src/tui/chatboxClipboard.js +96 -10
- package/src/tui/chatboxClipboard.ts +121 -11
- package/src/tui/clipboardImage.js +308 -0
- package/src/tui/clipboardImage.ts +320 -0
- package/src/tui/codeStreamRenderer.js +89 -1
- package/src/tui/codeStreamRenderer.ts +109 -1
- package/src/tui/composerControls.js +2 -0
- package/src/tui/composerControls.ts +2 -0
- package/src/tui/dialogs.js +41 -6
- package/src/tui/engineSpinner.js +20 -0
- package/src/tui/engineSpinner.ts +46 -0
- package/src/tui/lineEditor.js +44 -12
- package/src/tui/messageInteraction.js +16 -5
- package/src/tui/messageInteraction.ts +14 -5
- package/src/tui/observerPicker.js +4 -8
- package/src/tui/observerPicker.ts +4 -8
- package/src/tui/prompt.js +80 -43
- package/src/tui/runningLight.js +213 -0
- package/src/tui/runningLight.ts +271 -0
- package/src/tui/sessionSidebar.js +7 -1
- package/src/tui/sessionSidebar.ts +7 -1
- package/src/tui/stage.js +4 -4
- package/src/tui/stageSurface.js +21 -14
- package/src/tui/statusLine.js +27 -4
- package/src/tui/statusLine.ts +27 -4
- package/src/tui/theme.js +5 -2
- package/src/tui/thinkingBox.js +41 -10
- package/src/tui/thinkingBox.ts +43 -10
- package/src/tui/turnRail.js +155 -24
- package/src/tui/turnRail.ts +170 -22
package/src/tui/dialogs.js
CHANGED
|
@@ -77,8 +77,11 @@ export class SelectLayer extends Layer {
|
|
|
77
77
|
const item = this.list.current;
|
|
78
78
|
this.settled = true;
|
|
79
79
|
const result = this.onPick ? this.onPick(item) : null;
|
|
80
|
-
if (result === 'keep'
|
|
81
|
-
|
|
80
|
+
if (result === 'keep' || result === 'handled') {
|
|
81
|
+
this.settled = false;
|
|
82
|
+
return 'handled';
|
|
83
|
+
}
|
|
84
|
+
return 'close';
|
|
82
85
|
}
|
|
83
86
|
if (action === 'cancel') return 'close';
|
|
84
87
|
return action ? 'handled' : null;
|
|
@@ -392,11 +395,18 @@ export class ApprovalLayer extends Layer {
|
|
|
392
395
|
|
|
393
396
|
/** The chip row: the selected option is filled, the rest are dimmed. */
|
|
394
397
|
optionRow() {
|
|
395
|
-
|
|
396
|
-
|
|
398
|
+
let col = 0;
|
|
399
|
+
this.optionBounds = [];
|
|
400
|
+
const parts = this.options.map((option, index) => {
|
|
401
|
+
const rendered = index === this.selected
|
|
397
402
|
? badge(option.id === 'reject' ? 'danger' : 'success', option.label)
|
|
398
|
-
: dim(` ${option.label} `)
|
|
399
|
-
|
|
403
|
+
: dim(` ${option.label} `);
|
|
404
|
+
const width = visibleWidth(rendered);
|
|
405
|
+
this.optionBounds.push({ index, option, startCol: col, endCol: col + width - 1 });
|
|
406
|
+
col += width + 1;
|
|
407
|
+
return rendered;
|
|
408
|
+
});
|
|
409
|
+
return parts.join(' ');
|
|
400
410
|
}
|
|
401
411
|
|
|
402
412
|
body(width, fullHeight) {
|
|
@@ -491,6 +501,31 @@ export class ApprovalLayer extends Layer {
|
|
|
491
501
|
return 'close';
|
|
492
502
|
}
|
|
493
503
|
|
|
504
|
+
if (event.name === 'mouse' && event.mouse && event.mouse.pressed && event.mouse.button === 0) {
|
|
505
|
+
if (!Array.isArray(this.optionBounds) || this.optionBounds.length === 0) {
|
|
506
|
+
this.optionRow();
|
|
507
|
+
}
|
|
508
|
+
const geom = this.panelGeometry;
|
|
509
|
+
if (geom && Number.isFinite(event.mouse.row) && Number.isFinite(geom.optionScreenRow)) {
|
|
510
|
+
if (Math.abs(event.mouse.row - geom.optionScreenRow) > 1) return 'handled';
|
|
511
|
+
}
|
|
512
|
+
const rawCol = Number.isFinite(event.mouse.col) ? event.mouse.col : -1;
|
|
513
|
+
const bodyCol = geom ? rawCol - 1 - (geom.inset || 0) - 2 : rawCol;
|
|
514
|
+
const hit = (this.optionBounds || []).find(b => bodyCol >= b.startCol && bodyCol <= b.endCol);
|
|
515
|
+
if (hit) {
|
|
516
|
+
this.selected = hit.index;
|
|
517
|
+
this.answer(Boolean(hit.option.answer), hit.option.id);
|
|
518
|
+
return 'close';
|
|
519
|
+
}
|
|
520
|
+
return 'handled';
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
if (event.name === 'wheel') {
|
|
524
|
+
if (event.wheel?.direction === 'up') this.scroll--;
|
|
525
|
+
else if (event.wheel?.direction === 'down') this.scroll++;
|
|
526
|
+
return 'handled';
|
|
527
|
+
}
|
|
528
|
+
|
|
494
529
|
switch (event.name) {
|
|
495
530
|
case 'up': this.scroll--; return 'handled';
|
|
496
531
|
case 'down': this.scroll++; return 'handled';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Engine Spinner Adapter for CausyneRotor.
|
|
3
|
+
*
|
|
4
|
+
* Bridges the terminal spinner interfaces directly to CausyneRotor.ts.
|
|
5
|
+
*/
|
|
6
|
+
export { renderCausyneRotor, startCausyneRotor, getRotorSpinnerFrames, getRotorSpinnerFrame, getAnimatedDots, formatAnimatedStatus, COLORS, } from './CausyneRotor.js';
|
|
7
|
+
import { getRotorSpinnerFrames, getRotorSpinnerFrame, } from './CausyneRotor.js';
|
|
8
|
+
export function detectSpinnerStyle() {
|
|
9
|
+
return 'turbine';
|
|
10
|
+
}
|
|
11
|
+
export function getEngineFrames(options = {}) {
|
|
12
|
+
const unicode = options.unicode !== false;
|
|
13
|
+
const color = options.color !== false && options.color !== 'none';
|
|
14
|
+
return getRotorSpinnerFrames(color, unicode);
|
|
15
|
+
}
|
|
16
|
+
export function getEngineFrame(tick, options = {}) {
|
|
17
|
+
const unicode = options.unicode !== false;
|
|
18
|
+
const color = options.color !== false && options.color !== 'none';
|
|
19
|
+
return getRotorSpinnerFrame(tick, color, unicode);
|
|
20
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Engine Spinner Adapter for CausyneRotor.
|
|
3
|
+
*
|
|
4
|
+
* Bridges the terminal spinner interfaces directly to CausyneRotor.ts.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
renderCausyneRotor,
|
|
9
|
+
startCausyneRotor,
|
|
10
|
+
getRotorSpinnerFrames,
|
|
11
|
+
getRotorSpinnerFrame,
|
|
12
|
+
getAnimatedDots,
|
|
13
|
+
formatAnimatedStatus,
|
|
14
|
+
COLORS,
|
|
15
|
+
type RotorMotion,
|
|
16
|
+
type RotorOptions,
|
|
17
|
+
} from './CausyneRotor.js';
|
|
18
|
+
|
|
19
|
+
import {
|
|
20
|
+
getRotorSpinnerFrames,
|
|
21
|
+
getRotorSpinnerFrame,
|
|
22
|
+
} from './CausyneRotor.js';
|
|
23
|
+
|
|
24
|
+
export type EngineSpinnerStyle = 'turbine' | 'iris' | 'reactor' | 'compact' | 'ascii';
|
|
25
|
+
|
|
26
|
+
export interface EngineSpinnerOptions {
|
|
27
|
+
style?: EngineSpinnerStyle | undefined;
|
|
28
|
+
unicode?: boolean | undefined;
|
|
29
|
+
color?: boolean | 'truecolor' | '256' | '16' | 'none' | undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function detectSpinnerStyle(): EngineSpinnerStyle {
|
|
33
|
+
return 'turbine';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function getEngineFrames(options: EngineSpinnerOptions = {}): readonly string[] {
|
|
37
|
+
const unicode = options.unicode !== false;
|
|
38
|
+
const color = options.color !== false && options.color !== 'none';
|
|
39
|
+
return getRotorSpinnerFrames(color, unicode);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function getEngineFrame(tick: number, options: EngineSpinnerOptions = {}): string {
|
|
43
|
+
const unicode = options.unicode !== false;
|
|
44
|
+
const color = options.color !== false && options.color !== 'none';
|
|
45
|
+
return getRotorSpinnerFrame(tick, color, unicode);
|
|
46
|
+
}
|
package/src/tui/lineEditor.js
CHANGED
|
@@ -366,38 +366,70 @@ export class LineEditor {
|
|
|
366
366
|
const prefixWidth = visibleWidth(prefix);
|
|
367
367
|
const budget = Math.max(1, usable - prefixWidth);
|
|
368
368
|
const line = this.lines[index];
|
|
369
|
+
const isCurrentLine = index === this.line;
|
|
369
370
|
|
|
370
371
|
let row = prefix;
|
|
371
372
|
let used = 0;
|
|
372
373
|
let placed = false;
|
|
373
374
|
|
|
374
|
-
|
|
375
|
-
|
|
375
|
+
let pos = 0;
|
|
376
|
+
while (pos <= line.length) {
|
|
377
|
+
if (isCurrentLine && pos === this.col && !placed) {
|
|
376
378
|
cursorRow = rows.length;
|
|
377
379
|
cursorCol = prefixWidth + used;
|
|
378
380
|
placed = true;
|
|
379
381
|
}
|
|
380
|
-
if (
|
|
382
|
+
if (pos === line.length) break;
|
|
383
|
+
|
|
384
|
+
const isSpace = /\s/.test(line[pos]);
|
|
385
|
+
let nextPos = pos;
|
|
386
|
+
let tokenWidth = 0;
|
|
387
|
+
while (nextPos < line.length && (/\s/.test(line[nextPos]) === isSpace)) {
|
|
388
|
+
tokenWidth += visibleWidth(line[nextPos]);
|
|
389
|
+
nextPos++;
|
|
390
|
+
}
|
|
381
391
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
if (used + charWidth > budget) {
|
|
392
|
+
// If non-whitespace word exceeds remaining space on non-empty line: wrap to next line!
|
|
393
|
+
if (used > 0 && used + tokenWidth > budget && !isSpace) {
|
|
385
394
|
rows.push(row);
|
|
386
395
|
row = prefix;
|
|
387
396
|
used = 0;
|
|
388
|
-
|
|
389
|
-
if (placed && cursorRow === rows.length - 1 && cursorCol === prefixWidth + budget) {
|
|
397
|
+
if (isCurrentLine && pos === this.col && !placed) {
|
|
390
398
|
cursorRow = rows.length;
|
|
391
399
|
cursorCol = prefixWidth;
|
|
400
|
+
placed = true;
|
|
392
401
|
}
|
|
393
402
|
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
403
|
+
|
|
404
|
+
while (pos < nextPos) {
|
|
405
|
+
if (isCurrentLine && pos === this.col && !placed) {
|
|
406
|
+
cursorRow = rows.length;
|
|
407
|
+
cursorCol = prefixWidth + used;
|
|
408
|
+
placed = true;
|
|
409
|
+
}
|
|
410
|
+
const char = line[pos];
|
|
411
|
+
const charWidth = visibleWidth(char);
|
|
412
|
+
|
|
413
|
+
if (used + charWidth > budget && used > 0) {
|
|
414
|
+
rows.push(row);
|
|
415
|
+
row = prefix;
|
|
416
|
+
used = 0;
|
|
417
|
+
if (isCurrentLine && pos === this.col && !placed) {
|
|
418
|
+
cursorRow = rows.length;
|
|
419
|
+
cursorCol = prefixWidth;
|
|
420
|
+
placed = true;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
const isSelected = range ? isInsideRange(index, pos, range) : false;
|
|
425
|
+
row += isSelected ? `\x1b[7m${char}\x1b[27m` : char;
|
|
426
|
+
used += charWidth;
|
|
427
|
+
pos++;
|
|
428
|
+
}
|
|
397
429
|
}
|
|
398
430
|
|
|
399
431
|
rows.push(row);
|
|
400
|
-
if (
|
|
432
|
+
if (isCurrentLine && !placed) {
|
|
401
433
|
cursorRow = rows.length - 1;
|
|
402
434
|
cursorCol = prefixWidth + used;
|
|
403
435
|
}
|
|
@@ -224,11 +224,22 @@ export function markHoveredMessage(rows, surface, contentWidth) {
|
|
|
224
224
|
if (row < padding || row >= rows.length)
|
|
225
225
|
continue;
|
|
226
226
|
const existingRow = rows[row] ?? '';
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
227
|
+
let content = existingRow;
|
|
228
|
+
if (transcriptRow === firstContentRow) {
|
|
229
|
+
const plainTrimmed = stripAnsi(existingRow).trimStart();
|
|
230
|
+
const alreadyHasMarker = /^[▸│┃|▌┌└├╭╰▪●•]/.test(plainTrimmed);
|
|
231
|
+
if (!alreadyHasMarker) {
|
|
232
|
+
if (existingRow.startsWith(' ')) {
|
|
233
|
+
content = ` ${paint('accent', '▸')} ${existingRow.slice(3)}`;
|
|
234
|
+
}
|
|
235
|
+
else if (existingRow.startsWith(' ')) {
|
|
236
|
+
content = ` ${paint('accent', '▸')}${existingRow.slice(2)}`;
|
|
237
|
+
}
|
|
238
|
+
else if (existingRow.startsWith(' ')) {
|
|
239
|
+
content = `${paint('accent', '▸')}${existingRow.slice(1)}`;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
232
243
|
rows[row] = fill('surfaceHi', padEnd(content, contentWidth));
|
|
233
244
|
}
|
|
234
245
|
}
|
|
@@ -308,11 +308,20 @@ export function markHoveredMessage(
|
|
|
308
308
|
const row = transcriptRow - surface.viewport.scrollTop + padding;
|
|
309
309
|
if (row < padding || row >= rows.length) continue;
|
|
310
310
|
const existingRow = rows[row] ?? '';
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
311
|
+
let content = existingRow;
|
|
312
|
+
if (transcriptRow === firstContentRow) {
|
|
313
|
+
const plainTrimmed = stripAnsi(existingRow).trimStart();
|
|
314
|
+
const alreadyHasMarker = /^[▸│┃|▌┌└├╭╰▪●•]/.test(plainTrimmed);
|
|
315
|
+
if (!alreadyHasMarker) {
|
|
316
|
+
if (existingRow.startsWith(' ')) {
|
|
317
|
+
content = ` ${paint('accent', '▸')} ${existingRow.slice(3)}`;
|
|
318
|
+
} else if (existingRow.startsWith(' ')) {
|
|
319
|
+
content = ` ${paint('accent', '▸')}${existingRow.slice(2)}`;
|
|
320
|
+
} else if (existingRow.startsWith(' ')) {
|
|
321
|
+
content = `${paint('accent', '▸')}${existingRow.slice(1)}`;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
316
325
|
rows[row] = fill('surfaceHi', padEnd(content, contentWidth));
|
|
317
326
|
}
|
|
318
327
|
}
|
|
@@ -184,7 +184,6 @@ export function runInteractiveObserverPicker(prompt) {
|
|
|
184
184
|
// 4. Advisory Endpoint Input
|
|
185
185
|
if (action === 'endpoint') {
|
|
186
186
|
const current = coldObserver.getConfig();
|
|
187
|
-
prompt.closeLayer();
|
|
188
187
|
prompt.openLayer(new InputLayer({
|
|
189
188
|
title: 'Advisory Loopback Endpoint',
|
|
190
189
|
placeholder: 'http://localhost:11434/v1 (or "none" to clear)',
|
|
@@ -211,12 +210,11 @@ export function runInteractiveObserverPicker(prompt) {
|
|
|
211
210
|
openMenu();
|
|
212
211
|
}
|
|
213
212
|
}));
|
|
214
|
-
return;
|
|
213
|
+
return 'handled';
|
|
215
214
|
}
|
|
216
215
|
// 5. Advisory Model Input
|
|
217
216
|
if (action === 'model') {
|
|
218
217
|
const current = coldObserver.getConfig();
|
|
219
|
-
prompt.closeLayer();
|
|
220
218
|
prompt.openLayer(new InputLayer({
|
|
221
219
|
title: 'Advisory Model Name',
|
|
222
220
|
placeholder: 'model name (e.g. tiny, qwen2.5-coder) or "none"',
|
|
@@ -237,11 +235,10 @@ export function runInteractiveObserverPicker(prompt) {
|
|
|
237
235
|
openMenu();
|
|
238
236
|
}
|
|
239
237
|
}));
|
|
240
|
-
return;
|
|
238
|
+
return 'handled';
|
|
241
239
|
}
|
|
242
240
|
// 6. Test Advisory Endpoint
|
|
243
241
|
if (action === 'test') {
|
|
244
|
-
prompt.closeLayer();
|
|
245
242
|
void coldObserver.healthCheck().then((health) => {
|
|
246
243
|
const textLines = health.endpoint
|
|
247
244
|
? [
|
|
@@ -266,11 +263,10 @@ export function runInteractiveObserverPicker(prompt) {
|
|
|
266
263
|
onDismiss: () => openMenu()
|
|
267
264
|
}));
|
|
268
265
|
});
|
|
269
|
-
return;
|
|
266
|
+
return 'handled';
|
|
270
267
|
}
|
|
271
268
|
// 7. Audit History
|
|
272
269
|
if (action === 'audit') {
|
|
273
|
-
prompt.closeLayer();
|
|
274
270
|
const recentAudits = coldObserver.getAuditHistory();
|
|
275
271
|
const lines = recentAudits.length === 0
|
|
276
272
|
? ['No Cold Observer audit records yet.', '', 'Press Esc or Enter to return to Observer setup.']
|
|
@@ -288,7 +284,7 @@ export function runInteractiveObserverPicker(prompt) {
|
|
|
288
284
|
height: 18,
|
|
289
285
|
onDismiss: () => openMenu()
|
|
290
286
|
}));
|
|
291
|
-
return;
|
|
287
|
+
return 'handled';
|
|
292
288
|
}
|
|
293
289
|
// 8. Reset Defaults
|
|
294
290
|
if (action === 'reset') {
|
|
@@ -238,7 +238,6 @@ export function runInteractiveObserverPicker(prompt: PromptHost): Promise<string
|
|
|
238
238
|
// 4. Advisory Endpoint Input
|
|
239
239
|
if (action === 'endpoint') {
|
|
240
240
|
const current = coldObserver.getConfig();
|
|
241
|
-
prompt.closeLayer();
|
|
242
241
|
prompt.openLayer(new InputLayer({
|
|
243
242
|
title: 'Advisory Loopback Endpoint',
|
|
244
243
|
placeholder: 'http://localhost:11434/v1 (or "none" to clear)',
|
|
@@ -264,13 +263,12 @@ export function runInteractiveObserverPicker(prompt: PromptHost): Promise<string
|
|
|
264
263
|
openMenu();
|
|
265
264
|
}
|
|
266
265
|
}));
|
|
267
|
-
return;
|
|
266
|
+
return 'handled';
|
|
268
267
|
}
|
|
269
268
|
|
|
270
269
|
// 5. Advisory Model Input
|
|
271
270
|
if (action === 'model') {
|
|
272
271
|
const current = coldObserver.getConfig();
|
|
273
|
-
prompt.closeLayer();
|
|
274
272
|
prompt.openLayer(new InputLayer({
|
|
275
273
|
title: 'Advisory Model Name',
|
|
276
274
|
placeholder: 'model name (e.g. tiny, qwen2.5-coder) or "none"',
|
|
@@ -291,12 +289,11 @@ export function runInteractiveObserverPicker(prompt: PromptHost): Promise<string
|
|
|
291
289
|
openMenu();
|
|
292
290
|
}
|
|
293
291
|
}));
|
|
294
|
-
return;
|
|
292
|
+
return 'handled';
|
|
295
293
|
}
|
|
296
294
|
|
|
297
295
|
// 6. Test Advisory Endpoint
|
|
298
296
|
if (action === 'test') {
|
|
299
|
-
prompt.closeLayer();
|
|
300
297
|
void coldObserver.healthCheck().then((health) => {
|
|
301
298
|
const textLines = health.endpoint
|
|
302
299
|
? [
|
|
@@ -322,12 +319,11 @@ export function runInteractiveObserverPicker(prompt: PromptHost): Promise<string
|
|
|
322
319
|
onDismiss: () => openMenu()
|
|
323
320
|
}));
|
|
324
321
|
});
|
|
325
|
-
return;
|
|
322
|
+
return 'handled';
|
|
326
323
|
}
|
|
327
324
|
|
|
328
325
|
// 7. Audit History
|
|
329
326
|
if (action === 'audit') {
|
|
330
|
-
prompt.closeLayer();
|
|
331
327
|
const recentAudits = coldObserver.getAuditHistory();
|
|
332
328
|
const lines = recentAudits.length === 0
|
|
333
329
|
? ['No Cold Observer audit records yet.', '', 'Press Esc or Enter to return to Observer setup.']
|
|
@@ -346,7 +342,7 @@ export function runInteractiveObserverPicker(prompt: PromptHost): Promise<string
|
|
|
346
342
|
height: 18,
|
|
347
343
|
onDismiss: () => openMenu()
|
|
348
344
|
}));
|
|
349
|
-
return;
|
|
345
|
+
return 'handled';
|
|
350
346
|
}
|
|
351
347
|
|
|
352
348
|
// 8. Reset Defaults
|
package/src/tui/prompt.js
CHANGED
|
@@ -30,6 +30,8 @@ import { renderUsageCardRows, collectUsageCardData } from './usageCard.js';
|
|
|
30
30
|
import { commandPalette, skillPicker, ApprovalLayer, DecisionLayer, ConfirmLayer, HomeLayer, TextLayer } from './dialogs.js';
|
|
31
31
|
import { describeTool } from './toolDisplay.js';
|
|
32
32
|
import { readClipboardSync, writeClipboardSync } from './clipboardSync.js';
|
|
33
|
+
import { readClipboardImageSync, formatByteSize, loadLocalImageAttachment } from './clipboardImage.js';
|
|
34
|
+
import { pasteIntoChatbox } from './chatboxClipboard.js';
|
|
33
35
|
import { handleViewportWheel, handleScrollbarMouse } from './scrollInteraction.js';
|
|
34
36
|
import { centerRows, sessionRows, dialogWidth, dialogHeight } from './layout.js';
|
|
35
37
|
import { settleStageResize } from './resizeRecovery.js';
|
|
@@ -169,6 +171,7 @@ export class ChatPrompt {
|
|
|
169
171
|
this.redrawScheduled = false;
|
|
170
172
|
this.resizeTimer = null;
|
|
171
173
|
this.suspendedSurface = null;
|
|
174
|
+
this.pendingAttachments = [];
|
|
172
175
|
}
|
|
173
176
|
|
|
174
177
|
// -------------------------------------------------------------------------
|
|
@@ -383,7 +386,8 @@ export class ChatPrompt {
|
|
|
383
386
|
elapsedMs: since ? Date.now() - since : 0,
|
|
384
387
|
steps: this.renderer.stepCount || 0,
|
|
385
388
|
width: Math.max(10, width - 1),
|
|
386
|
-
spinnerFrame: frame
|
|
389
|
+
spinnerFrame: frame,
|
|
390
|
+
tick: this.tick
|
|
387
391
|
})];
|
|
388
392
|
}
|
|
389
393
|
|
|
@@ -437,7 +441,7 @@ export class ChatPrompt {
|
|
|
437
441
|
this.tickTimer = setInterval(() => {
|
|
438
442
|
this.tick++;
|
|
439
443
|
if (this.busy) this.scheduleDraw();
|
|
440
|
-
},
|
|
444
|
+
}, 125);
|
|
441
445
|
if (this.tickTimer.unref) this.tickTimer.unref();
|
|
442
446
|
}
|
|
443
447
|
|
|
@@ -545,7 +549,7 @@ export class ChatPrompt {
|
|
|
545
549
|
showText(title, text, options = {}) {
|
|
546
550
|
const panelWidth = dialogWidth(this.width(), options.width || 76);
|
|
547
551
|
const contentWidth = Math.max(12, panelWidth - 4);
|
|
548
|
-
let lines = wrapBlock(safeDisplay(String(text == null ? '' : text)), contentWidth);
|
|
552
|
+
let lines = wrapBlock(safeDisplay(String(text == null ? '' : text)), contentWidth, { hang: 0 });
|
|
549
553
|
if (lines.length > 0 && lines[0].trim().toLowerCase() === String(title || '').trim().toLowerCase()) {
|
|
550
554
|
lines = lines.slice(1);
|
|
551
555
|
if (lines.length > 0 && /^[-─═_]+$/.test(lines[0].trim())) {
|
|
@@ -696,6 +700,22 @@ export class ChatPrompt {
|
|
|
696
700
|
return false;
|
|
697
701
|
}
|
|
698
702
|
|
|
703
|
+
/**
|
|
704
|
+
* Consume and return any pending multimodal attachments (e.g. pasted screenshots).
|
|
705
|
+
*/
|
|
706
|
+
consumeAttachments() {
|
|
707
|
+
const list = Array.isArray(this.pendingAttachments) ? this.pendingAttachments.slice() : [];
|
|
708
|
+
this.pendingAttachments = [];
|
|
709
|
+
return list;
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
/**
|
|
713
|
+
* Paste clipboard content: seamlessly supports text and screenshot images.
|
|
714
|
+
*/
|
|
715
|
+
pasteClipboard() {
|
|
716
|
+
pasteIntoChatbox(this);
|
|
717
|
+
}
|
|
718
|
+
|
|
699
719
|
setBusy(busy) {
|
|
700
720
|
this.busy = busy;
|
|
701
721
|
resetTurnInterruptState(this, busy);
|
|
@@ -715,6 +735,22 @@ export class ChatPrompt {
|
|
|
715
735
|
this.usageCard = null;
|
|
716
736
|
}
|
|
717
737
|
|
|
738
|
+
// Instant slash command shortcuts that operate directly on the prompt surface
|
|
739
|
+
if (text === '/usage') {
|
|
740
|
+
void this.toggleUsageCard();
|
|
741
|
+
return;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
if (text === '/observer' || text === '/observer status') {
|
|
745
|
+
import('./observerPicker.js').then(({ runInteractiveObserverPicker }) => {
|
|
746
|
+
void runInteractiveObserverPicker(this);
|
|
747
|
+
}).catch((err) => {
|
|
748
|
+
this.notice = err instanceof Error ? err.message : String(err);
|
|
749
|
+
this.scheduleDraw();
|
|
750
|
+
});
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
|
|
718
754
|
// Control commands take priority over busy turns so the user is never locked out.
|
|
719
755
|
// Commands like /stop, /new, /model, /session, /sessions, /continuum, /clear can interrupt
|
|
720
756
|
// a stalled/long-running turn and execute immediately.
|
|
@@ -741,9 +777,15 @@ export class ChatPrompt {
|
|
|
741
777
|
}
|
|
742
778
|
|
|
743
779
|
if (this.busy) {
|
|
744
|
-
//
|
|
780
|
+
// If user typed another slash command while busy, notify them rather than queuing
|
|
781
|
+
// it as a chat prompt to the model.
|
|
782
|
+
if (this.isCommand(text)) {
|
|
783
|
+
this.notice = `Command ${text} queued — will execute when current turn completes`;
|
|
784
|
+
} else {
|
|
785
|
+
this.notice = `queued (${this.queue.length + 1}) — sends when this turn ends`;
|
|
786
|
+
}
|
|
745
787
|
this.queue.push(text);
|
|
746
|
-
this.
|
|
788
|
+
this.scheduleDraw();
|
|
747
789
|
return;
|
|
748
790
|
}
|
|
749
791
|
|
|
@@ -847,24 +889,19 @@ export class ChatPrompt {
|
|
|
847
889
|
if (this.surface && typeof this.surface.captureMouse === 'function') {
|
|
848
890
|
this.surface.captureMouse();
|
|
849
891
|
}
|
|
850
|
-
this
|
|
851
|
-
if (typeof key.text === 'string' && !key.text.includes('\n') && key.text.length < 60) {
|
|
852
|
-
this.refreshCompletion();
|
|
853
|
-
} else {
|
|
854
|
-
this.completion = null;
|
|
855
|
-
}
|
|
856
|
-
this.scheduleDraw();
|
|
892
|
+
pasteIntoChatbox(this, key.text);
|
|
857
893
|
return;
|
|
858
894
|
}
|
|
859
895
|
|
|
860
896
|
if (this.completion && this.handleCompletionKey(key)) return;
|
|
861
897
|
if (this.handleScrollKey(key)) return;
|
|
862
898
|
|
|
863
|
-
const
|
|
899
|
+
const isModeControl = Boolean(key.ctrl && key.name === 'g');
|
|
900
|
+
const control = isModeControl ? this.onOpenMode
|
|
864
901
|
: key.alt && key.name === 'm' ? this.onOpenModel
|
|
865
902
|
: key.ctrl && key.name === 't' ? this.onOpenVariant : null;
|
|
866
903
|
if (control) {
|
|
867
|
-
if (this.busy) {
|
|
904
|
+
if (this.busy && !isModeControl) {
|
|
868
905
|
this.notice = 'Finish or interrupt the current turn before switching controls';
|
|
869
906
|
this.scheduleDraw();
|
|
870
907
|
} else {
|
|
@@ -931,18 +968,7 @@ export class ChatPrompt {
|
|
|
931
968
|
case 'p': return this.openPalette();
|
|
932
969
|
case 'l': return this.clearScreen();
|
|
933
970
|
case 'o': return this.expand();
|
|
934
|
-
case 'v':
|
|
935
|
-
const text = readClipboardSync();
|
|
936
|
-
if (text) {
|
|
937
|
-
this.editor.insert(text);
|
|
938
|
-
this.refreshCompletion();
|
|
939
|
-
this.notice = 'pasted from clipboard';
|
|
940
|
-
} else {
|
|
941
|
-
this.notice = 'clipboard is empty';
|
|
942
|
-
}
|
|
943
|
-
this.scheduleDraw();
|
|
944
|
-
return;
|
|
945
|
-
}
|
|
971
|
+
case 'v': return this.pasteClipboard();
|
|
946
972
|
default: break;
|
|
947
973
|
}
|
|
948
974
|
}
|
|
@@ -979,18 +1005,7 @@ export class ChatPrompt {
|
|
|
979
1005
|
this.scheduleDraw();
|
|
980
1006
|
return;
|
|
981
1007
|
}
|
|
982
|
-
if (key.alt && key.name === 'v')
|
|
983
|
-
const text = readClipboardSync();
|
|
984
|
-
if (text) {
|
|
985
|
-
this.editor.insert(text);
|
|
986
|
-
this.refreshCompletion();
|
|
987
|
-
this.notice = 'pasted from clipboard';
|
|
988
|
-
} else {
|
|
989
|
-
this.notice = 'clipboard is empty';
|
|
990
|
-
}
|
|
991
|
-
this.scheduleDraw();
|
|
992
|
-
return;
|
|
993
|
-
}
|
|
1008
|
+
if (key.alt && key.name === 'v') return this.pasteClipboard();
|
|
994
1009
|
if (key.alt && key.name === 'b') return this.editor.moveWordLeft();
|
|
995
1010
|
if (key.alt && key.name === 'f') return this.editor.moveWordRight();
|
|
996
1011
|
}
|
|
@@ -1505,8 +1520,9 @@ export class ChatPrompt {
|
|
|
1505
1520
|
// surface you are writing INTO. Every row of the block is inset by the same
|
|
1506
1521
|
// gutter, so the caret column is a constant rather than a special case for
|
|
1507
1522
|
// row 0 — which is also one fewer thing for erase() to get wrong.
|
|
1523
|
+
const boxWidth = Math.max(20, width - 1);
|
|
1508
1524
|
const inset = visibleWidth(GLYPHS.bar) + GUTTER;
|
|
1509
|
-
const inner = Math.max(8,
|
|
1525
|
+
const inner = Math.max(8, boxWidth - inset);
|
|
1510
1526
|
const layout = this.editor.render(inner, '');
|
|
1511
1527
|
|
|
1512
1528
|
// Scroll the editor internally rather than growing without bound: keep a
|
|
@@ -1518,8 +1534,17 @@ export class ChatPrompt {
|
|
|
1518
1534
|
const caretRow = layout.cursorRow - top;
|
|
1519
1535
|
let body = window.slice();
|
|
1520
1536
|
|
|
1537
|
+
if (!this.editor.isEmpty) {
|
|
1538
|
+
body = body.map((line) => {
|
|
1539
|
+
if (typeof line !== 'string' || !line.includes('[Image ')) return line;
|
|
1540
|
+
return line.replace(/\[Image (\d+)\]/g, (_m, num) => {
|
|
1541
|
+
return paint('warn', bold(`[Image ${num}]`));
|
|
1542
|
+
});
|
|
1543
|
+
});
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1521
1546
|
if (this.editor.isEmpty && !this.completion) {
|
|
1522
|
-
const idle = fitHints([`try "${this.example}"`, '/ commands', '@ files'], Math.max(8, inner), 'ask anything');
|
|
1547
|
+
const idle = fitHints([`try "${this.example}"`, '/ commands', '@ files', '^V image'], Math.max(8, inner), 'ask anything');
|
|
1523
1548
|
body = [dim(this.busy ? 'type to queue a message…' : idle)];
|
|
1524
1549
|
}
|
|
1525
1550
|
|
|
@@ -1546,7 +1571,7 @@ export class ChatPrompt {
|
|
|
1546
1571
|
const padded = new Array(padTop).fill('')
|
|
1547
1572
|
.concat(body, new Array(padBottom).fill(''));
|
|
1548
1573
|
const boxRows = barBlock(padded, {
|
|
1549
|
-
width,
|
|
1574
|
+
width: boxWidth,
|
|
1550
1575
|
role: this.busy ? 'accent' : 'user',
|
|
1551
1576
|
filled: true,
|
|
1552
1577
|
surface: 'surface',
|
|
@@ -1596,10 +1621,11 @@ export class ChatPrompt {
|
|
|
1596
1621
|
* nothing of ours is on the terminal for erase() to walk back over.
|
|
1597
1622
|
*/
|
|
1598
1623
|
present(all, caretRow, caretCol) {
|
|
1624
|
+
const hideCursor = Boolean(this.busy && this.editor.isEmpty);
|
|
1599
1625
|
if (this.surface) {
|
|
1600
1626
|
this.drawnRows = 0;
|
|
1601
1627
|
this.cursorRow = 0;
|
|
1602
|
-
this.surface.present(all, { row: caretRow, col: caretCol,
|
|
1628
|
+
this.surface.present(all, { row: caretRow, col: caretCol, hideCursor,
|
|
1603
1629
|
modal: Boolean(this.layer), inline: Boolean(this.layer && !isStartupDialog(this.surface)) });
|
|
1604
1630
|
return;
|
|
1605
1631
|
}
|
|
@@ -1612,6 +1638,11 @@ export class ChatPrompt {
|
|
|
1612
1638
|
this.cursorRow = caretRow;
|
|
1613
1639
|
this.out.write('\r');
|
|
1614
1640
|
if (caretCol > 0) this.out.write(`\x1b[${caretCol}C`);
|
|
1641
|
+
if (hideCursor) {
|
|
1642
|
+
this.out.write('\x1b[?25l');
|
|
1643
|
+
} else {
|
|
1644
|
+
this.out.write('\x1b[?25h');
|
|
1645
|
+
}
|
|
1615
1646
|
}
|
|
1616
1647
|
|
|
1617
1648
|
/**
|
|
@@ -1662,11 +1693,17 @@ export class ChatPrompt {
|
|
|
1662
1693
|
const panelWidth = dialogWidth(availableWidth, this.layer.width || 64);
|
|
1663
1694
|
const maxHeight = dialogHeight(this.surface?.stage?.maxHeight || this.out?.rows, this.layer.preferredHeight());
|
|
1664
1695
|
const panel = panelRows(this.layer, panelWidth, maxHeight);
|
|
1665
|
-
const
|
|
1696
|
+
const status = this.statusRow(width);
|
|
1697
|
+
const all = this.clampRows(panel.concat(status), width);
|
|
1666
1698
|
|
|
1667
1699
|
// panelRows() called body(), which is where a layer publishes its cursor.
|
|
1668
1700
|
const cursor = this.layer.cursor;
|
|
1669
1701
|
const centered = this.surface ? centerRows(all, availableWidth) : { rows: all, inset: 0 };
|
|
1702
|
+
const stageHeight = this.surface?.stage?.height || this.out?.rows || all.length;
|
|
1703
|
+
this.layer.panelGeometry = {
|
|
1704
|
+
inset: centered.inset,
|
|
1705
|
+
optionScreenRow: stageHeight - status.length - 1
|
|
1706
|
+
};
|
|
1670
1707
|
this.present(centered.rows, cursor ? 1 + cursor.y : 0,
|
|
1671
1708
|
(cursor ? 2 + cursor.x : 0) + centered.inset);
|
|
1672
1709
|
}
|