@causyne/agent 1.20.60 → 1.20.63
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/agentCatalog.js +1 -1
- package/src/acp/agentCatalog.ts +1 -1
- package/src/acp/client.js +48 -0
- package/src/acp/client.ts +44 -0
- package/src/acp/peerProfiles.js +3 -3
- package/src/acp/peerProfiles.ts +3 -3
- package/src/agentLoop.js +239 -33
- package/src/agentLoop.ts +248 -36
- package/src/checkpoints.js +23 -5
- package/src/cliMode.js +13 -2
- package/src/commands.js +534 -78
- package/src/contextManager.d.ts +3 -0
- package/src/contextManager.js +78 -5
- package/src/cortex/autoCondenser.js +105 -145
- package/src/cortex/autoCondenser.ts +185 -0
- package/src/cortex/cortexEngine.js +179 -0
- package/src/cortex/cortexEngine.ts +209 -0
- package/src/cortex/provisioner.js +12 -14
- package/src/cortex/provisioner.ts +29 -0
- package/src/cortex/vectorDb.js +307 -386
- package/src/cortex/vectorDb.ts +473 -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/reporting.js +30 -7
- package/src/sessionJournal.js +13 -0
- package/src/sessionJournal.ts +13 -0
- package/src/smartToolsUse.js +1 -1
- package/src/smartToolsUse.ts +1 -1
- package/src/tokenTracker.js +22 -0
- package/src/tokenTracker.ts +28 -0
- 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 +62 -9
- 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/completion.js +34 -15
- package/src/tui/composerControls.js +5 -0
- package/src/tui/composerControls.ts +5 -0
- package/src/tui/dialogs.js +5 -2
- package/src/tui/engineSpinner.js +20 -0
- package/src/tui/engineSpinner.ts +46 -0
- package/src/tui/layout.js +1 -1
- package/src/tui/layout.ts +1 -1
- 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 +319 -0
- package/src/tui/observerPicker.ts +382 -0
- package/src/tui/prompt.js +247 -55
- 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 +27 -10
- 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/usageCard.js +178 -0
- package/src/tui/usageCard.ts +240 -0
- package/src/utils/paths.js +30 -1
- package/src/utils/paths.ts +32 -1
- package/src/cortex/autoCondenser.d.ts +0 -2
- package/src/cortex/vectorDb.d.ts +0 -1
package/src/tui/prompt.js
CHANGED
|
@@ -23,12 +23,15 @@ import { PromptHistory } from './history.js';
|
|
|
23
23
|
import { FileIndex, suggest, applyCompletion, detectTrigger, renderPicker, MAX_VISIBLE } from './completion.js';
|
|
24
24
|
import { paint, dim, bold, GLYPHS, terminalWidth, HAS_COLOR } from './theme.js';
|
|
25
25
|
import { barBlock, GUTTER } from './block.js';
|
|
26
|
-
import { visibleWidth, truncate, wrapBlock, shortenHome, safeDisplay } from './text.js';
|
|
26
|
+
import { visibleWidth, truncate, wrapBlock, shortenHome, safeDisplay, stripAnsi } from './text.js';
|
|
27
27
|
import { pickExample, fitHints } from './banner.js';
|
|
28
28
|
import { panelRows } from './overlay.js';
|
|
29
|
+
import { renderUsageCardRows, collectUsageCardData } from './usageCard.js';
|
|
29
30
|
import { commandPalette, skillPicker, ApprovalLayer, DecisionLayer, ConfirmLayer, HomeLayer, TextLayer } from './dialogs.js';
|
|
30
31
|
import { describeTool } from './toolDisplay.js';
|
|
31
32
|
import { readClipboardSync, writeClipboardSync } from './clipboardSync.js';
|
|
33
|
+
import { readClipboardImageSync, formatByteSize, loadLocalImageAttachment } from './clipboardImage.js';
|
|
34
|
+
import { pasteIntoChatbox } from './chatboxClipboard.js';
|
|
32
35
|
import { handleViewportWheel, handleScrollbarMouse } from './scrollInteraction.js';
|
|
33
36
|
import { centerRows, sessionRows, dialogWidth, dialogHeight } from './layout.js';
|
|
34
37
|
import { settleStageResize } from './resizeRecovery.js';
|
|
@@ -121,6 +124,7 @@ export class ChatPrompt {
|
|
|
121
124
|
this.busy = false;
|
|
122
125
|
this.active = false;
|
|
123
126
|
this.drawnRows = 0;
|
|
127
|
+
this.usageCard = null;
|
|
124
128
|
|
|
125
129
|
// Which row of the drawn block the caret is parked on.
|
|
126
130
|
//
|
|
@@ -167,6 +171,7 @@ export class ChatPrompt {
|
|
|
167
171
|
this.redrawScheduled = false;
|
|
168
172
|
this.resizeTimer = null;
|
|
169
173
|
this.suspendedSurface = null;
|
|
174
|
+
this.pendingAttachments = [];
|
|
170
175
|
}
|
|
171
176
|
|
|
172
177
|
// -------------------------------------------------------------------------
|
|
@@ -250,7 +255,47 @@ export class ChatPrompt {
|
|
|
250
255
|
|
|
251
256
|
handleData = (chunk) => {
|
|
252
257
|
let motionOnly = true;
|
|
253
|
-
|
|
258
|
+
const str = typeof chunk === 'string' ? chunk : Buffer.isBuffer(chunk) ? chunk.toString('utf8') : '';
|
|
259
|
+
// Unbracketed multi-line or bulk paste safeguard: when a multi-line or bulk block arrives
|
|
260
|
+
// without bracketed paste (e.g. VS Code terminal, native clipboard paste, terminal ANSI logs,
|
|
261
|
+
// or piped stream), handle it atomically as a paste event rather than executing multiple
|
|
262
|
+
// spurious Enter submissions or freezing in per-character completion loops.
|
|
263
|
+
const isBracketedPasteStart = str.startsWith('\x1b[200~');
|
|
264
|
+
const isMouse = str.startsWith('\x1b[<') || str.startsWith('\x1b[M');
|
|
265
|
+
const hasNewlines = str.includes('\n') || str.includes('\r');
|
|
266
|
+
if (!this.layer && !this.decoder.inPaste && !isBracketedPasteStart && !isMouse && (
|
|
267
|
+
(str.length > 2 && hasNewlines) ||
|
|
268
|
+
(str.length >= 64 && !str.startsWith('\x1b'))
|
|
269
|
+
)) {
|
|
270
|
+
const clean = stripAnsi(str).replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
271
|
+
try {
|
|
272
|
+
this.handleKey({ name: 'paste', text: clean, sequence: clean });
|
|
273
|
+
} catch (e) {
|
|
274
|
+
process.stderr.write(`\n[tui] paste failed: ${e.message}\n`);
|
|
275
|
+
}
|
|
276
|
+
this.draw();
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const keys = this.decoder.decode(chunk);
|
|
281
|
+
let charBatch = '';
|
|
282
|
+
|
|
283
|
+
for (let i = 0; i < keys.length; i++) {
|
|
284
|
+
const key = keys[i];
|
|
285
|
+
if (!this.layer && key.name === 'char' && typeof key.text === 'string' && !key.alt && !key.ctrl) {
|
|
286
|
+
charBatch += key.text;
|
|
287
|
+
motionOnly = false;
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
if (charBatch.length > 0) {
|
|
291
|
+
this.editor.insert(charBatch);
|
|
292
|
+
if (charBatch.length < 60 && !charBatch.includes('\n')) {
|
|
293
|
+
this.refreshCompletion();
|
|
294
|
+
} else {
|
|
295
|
+
this.completion = null;
|
|
296
|
+
}
|
|
297
|
+
charBatch = '';
|
|
298
|
+
}
|
|
254
299
|
if (key.name !== 'mouse' || !isMouseMotion(key.sequence)) motionOnly = false;
|
|
255
300
|
try {
|
|
256
301
|
this.handleKey(key);
|
|
@@ -260,6 +305,17 @@ export class ChatPrompt {
|
|
|
260
305
|
process.stderr.write(`\n[tui] key "${key.name}" failed: ${e.message}\n`);
|
|
261
306
|
}
|
|
262
307
|
}
|
|
308
|
+
|
|
309
|
+
if (charBatch.length > 0) {
|
|
310
|
+
this.editor.insert(charBatch);
|
|
311
|
+
if (charBatch.length < 60 && !charBatch.includes('\n')) {
|
|
312
|
+
this.refreshCompletion();
|
|
313
|
+
} else {
|
|
314
|
+
this.completion = null;
|
|
315
|
+
}
|
|
316
|
+
charBatch = '';
|
|
317
|
+
}
|
|
318
|
+
|
|
263
319
|
// All-motion chunks repaint only when the hovered message actually changes.
|
|
264
320
|
if (!motionOnly) this.draw();
|
|
265
321
|
};
|
|
@@ -330,7 +386,8 @@ export class ChatPrompt {
|
|
|
330
386
|
elapsedMs: since ? Date.now() - since : 0,
|
|
331
387
|
steps: this.renderer.stepCount || 0,
|
|
332
388
|
width: Math.max(10, width - 1),
|
|
333
|
-
spinnerFrame: frame
|
|
389
|
+
spinnerFrame: frame,
|
|
390
|
+
tick: this.tick
|
|
334
391
|
})];
|
|
335
392
|
}
|
|
336
393
|
|
|
@@ -384,7 +441,7 @@ export class ChatPrompt {
|
|
|
384
441
|
this.tickTimer = setInterval(() => {
|
|
385
442
|
this.tick++;
|
|
386
443
|
if (this.busy) this.scheduleDraw();
|
|
387
|
-
},
|
|
444
|
+
}, 125);
|
|
388
445
|
if (this.tickTimer.unref) this.tickTimer.unref();
|
|
389
446
|
}
|
|
390
447
|
|
|
@@ -492,7 +549,13 @@ export class ChatPrompt {
|
|
|
492
549
|
showText(title, text, options = {}) {
|
|
493
550
|
const panelWidth = dialogWidth(this.width(), options.width || 76);
|
|
494
551
|
const contentWidth = Math.max(12, panelWidth - 4);
|
|
495
|
-
|
|
552
|
+
let lines = wrapBlock(safeDisplay(String(text == null ? '' : text)), contentWidth, { hang: 0 });
|
|
553
|
+
if (lines.length > 0 && lines[0].trim().toLowerCase() === String(title || '').trim().toLowerCase()) {
|
|
554
|
+
lines = lines.slice(1);
|
|
555
|
+
if (lines.length > 0 && /^[-─═_]+$/.test(lines[0].trim())) {
|
|
556
|
+
lines = lines.slice(1);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
496
559
|
return this.openLayer(new TextLayer({
|
|
497
560
|
title: String(title || 'Details'),
|
|
498
561
|
lines: options.danger ? lines.map((line) => paint('danger', line)) : lines,
|
|
@@ -501,6 +564,31 @@ export class ChatPrompt {
|
|
|
501
564
|
}));
|
|
502
565
|
}
|
|
503
566
|
|
|
567
|
+
/** Toggle the docked usage card directly above the chatbox. */
|
|
568
|
+
async toggleUsageCard(loop = null) {
|
|
569
|
+
if (this.usageCard) {
|
|
570
|
+
this.usageCard = null;
|
|
571
|
+
this.scheduleDraw();
|
|
572
|
+
return false;
|
|
573
|
+
}
|
|
574
|
+
this.usageCard = await collectUsageCardData(loop || this.messageActionLoop);
|
|
575
|
+
this.scheduleDraw();
|
|
576
|
+
return true;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
showUsageCard(loop = null) {
|
|
580
|
+
return this.toggleUsageCard(loop);
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
closeUsageCard() {
|
|
584
|
+
if (this.usageCard) {
|
|
585
|
+
this.usageCard = null;
|
|
586
|
+
this.scheduleDraw();
|
|
587
|
+
return true;
|
|
588
|
+
}
|
|
589
|
+
return false;
|
|
590
|
+
}
|
|
591
|
+
|
|
504
592
|
/**
|
|
505
593
|
* Ask for approval of a tool call: risk, arguments and a scrollable diff.
|
|
506
594
|
*
|
|
@@ -612,6 +700,22 @@ export class ChatPrompt {
|
|
|
612
700
|
return false;
|
|
613
701
|
}
|
|
614
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
|
+
|
|
615
719
|
setBusy(busy) {
|
|
616
720
|
this.busy = busy;
|
|
617
721
|
resetTurnInterruptState(this, busy);
|
|
@@ -627,6 +731,25 @@ export class ChatPrompt {
|
|
|
627
731
|
this.history.add(text);
|
|
628
732
|
this.editor.clear();
|
|
629
733
|
this.completion = null;
|
|
734
|
+
if (this.usageCard && !this.isCommand(text)) {
|
|
735
|
+
this.usageCard = null;
|
|
736
|
+
}
|
|
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
|
+
}
|
|
630
753
|
|
|
631
754
|
// Control commands take priority over busy turns so the user is never locked out.
|
|
632
755
|
// Commands like /stop, /new, /model, /session, /sessions, /continuum, /clear can interrupt
|
|
@@ -641,14 +764,28 @@ export class ChatPrompt {
|
|
|
641
764
|
text === '/clear'
|
|
642
765
|
);
|
|
643
766
|
|
|
767
|
+
// Immediate abort signals interrupt the running turn directly without queuing as a future task.
|
|
768
|
+
if ((text === '/stop' || text === '/interrupt') && this.busy) {
|
|
769
|
+
this.interrupt();
|
|
770
|
+
this.notice = 'Interrupted';
|
|
771
|
+
this.scheduleDraw();
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
|
|
644
775
|
if (isControlCommand && this.busy) {
|
|
645
776
|
this.interrupt();
|
|
646
777
|
}
|
|
647
778
|
|
|
648
779
|
if (this.busy) {
|
|
649
|
-
//
|
|
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
|
+
}
|
|
650
787
|
this.queue.push(text);
|
|
651
|
-
this.
|
|
788
|
+
this.scheduleDraw();
|
|
652
789
|
return;
|
|
653
790
|
}
|
|
654
791
|
|
|
@@ -660,6 +797,10 @@ export class ChatPrompt {
|
|
|
660
797
|
const settle = this.waiter;
|
|
661
798
|
this.waiter = null;
|
|
662
799
|
if (settle) settle(text);
|
|
800
|
+
else {
|
|
801
|
+
if (!Array.isArray(this.queue)) this.queue = [];
|
|
802
|
+
this.queue.push(text); // nobody is reading yet: hold it, never drop it
|
|
803
|
+
}
|
|
663
804
|
return;
|
|
664
805
|
}
|
|
665
806
|
|
|
@@ -669,7 +810,7 @@ export class ChatPrompt {
|
|
|
669
810
|
else this.commit('user', (width) => {
|
|
670
811
|
const blockWidth = Math.max(8, width);
|
|
671
812
|
return barBlock(
|
|
672
|
-
wrapBlock(safeDisplay(text), Math.max(8, blockWidth - visibleWidth(GLYPHS.barHeavy || GLYPHS.bar) - GUTTER)),
|
|
813
|
+
wrapBlock(safeDisplay(text), Math.max(8, blockWidth - visibleWidth(GLYPHS.barHeavy || GLYPHS.bar) - GUTTER), { hang: 0 }),
|
|
673
814
|
{ width: blockWidth, role: 'user', filled: true, surface: 'surfaceHi' }
|
|
674
815
|
);
|
|
675
816
|
});
|
|
@@ -683,6 +824,14 @@ export class ChatPrompt {
|
|
|
683
824
|
// -------------------------------------------------------------------------
|
|
684
825
|
|
|
685
826
|
handleKey(key) {
|
|
827
|
+
// A notice reports the result of the last action. Once the user edits the
|
|
828
|
+
// line again it is stale, and leaving it up made "copied ..." follow every
|
|
829
|
+
// later keystroke for the rest of the session.
|
|
830
|
+
if (this.notice && !this.layer
|
|
831
|
+
&& (key.name === 'char' || key.name === 'paste' || key.name === 'backspace' || key.name === 'delete')) {
|
|
832
|
+
this.notice = '';
|
|
833
|
+
}
|
|
834
|
+
|
|
686
835
|
// The wheel was handed to the terminal at the top of the band; the moment
|
|
687
836
|
// the user types again they are driving this prompt, so take it back.
|
|
688
837
|
if (key.name !== 'wheel' && key.name !== 'mouse') {
|
|
@@ -737,8 +886,10 @@ export class ChatPrompt {
|
|
|
737
886
|
}
|
|
738
887
|
|
|
739
888
|
if (key.name === 'paste') {
|
|
740
|
-
this.
|
|
741
|
-
|
|
889
|
+
if (this.surface && typeof this.surface.captureMouse === 'function') {
|
|
890
|
+
this.surface.captureMouse();
|
|
891
|
+
}
|
|
892
|
+
pasteIntoChatbox(this, key.text);
|
|
742
893
|
return;
|
|
743
894
|
}
|
|
744
895
|
|
|
@@ -816,18 +967,7 @@ export class ChatPrompt {
|
|
|
816
967
|
case 'p': return this.openPalette();
|
|
817
968
|
case 'l': return this.clearScreen();
|
|
818
969
|
case 'o': return this.expand();
|
|
819
|
-
case 'v':
|
|
820
|
-
const text = readClipboardSync();
|
|
821
|
-
if (text) {
|
|
822
|
-
this.editor.insert(text);
|
|
823
|
-
this.refreshCompletion();
|
|
824
|
-
this.notice = 'pasted from clipboard';
|
|
825
|
-
} else {
|
|
826
|
-
this.notice = 'clipboard is empty';
|
|
827
|
-
}
|
|
828
|
-
this.scheduleDraw();
|
|
829
|
-
return;
|
|
830
|
-
}
|
|
970
|
+
case 'v': return this.pasteClipboard();
|
|
831
971
|
default: break;
|
|
832
972
|
}
|
|
833
973
|
}
|
|
@@ -864,18 +1004,7 @@ export class ChatPrompt {
|
|
|
864
1004
|
this.scheduleDraw();
|
|
865
1005
|
return;
|
|
866
1006
|
}
|
|
867
|
-
if (key.alt && key.name === 'v')
|
|
868
|
-
const text = readClipboardSync();
|
|
869
|
-
if (text) {
|
|
870
|
-
this.editor.insert(text);
|
|
871
|
-
this.refreshCompletion();
|
|
872
|
-
this.notice = 'pasted from clipboard';
|
|
873
|
-
} else {
|
|
874
|
-
this.notice = 'clipboard is empty';
|
|
875
|
-
}
|
|
876
|
-
this.scheduleDraw();
|
|
877
|
-
return;
|
|
878
|
-
}
|
|
1007
|
+
if (key.alt && key.name === 'v') return this.pasteClipboard();
|
|
879
1008
|
if (key.alt && key.name === 'b') return this.editor.moveWordLeft();
|
|
880
1009
|
if (key.alt && key.name === 'f') return this.editor.moveWordRight();
|
|
881
1010
|
}
|
|
@@ -983,8 +1112,8 @@ export class ChatPrompt {
|
|
|
983
1112
|
// sit at almost the same seam — a footer is immediately followed by the next
|
|
984
1113
|
// question — so accepting either made the jump land twice two rows apart
|
|
985
1114
|
// instead of once per exchange.
|
|
986
|
-
if (key.name === '[' || (key.alt && key.name === '<')) { viewport.jump(-1, ['user']); return true; }
|
|
987
|
-
if (key.name === ']' || (key.alt && key.name === '>')) { viewport.jump(1, ['user']); return true; }
|
|
1115
|
+
if ((key.alt && key.name === '[') || (key.alt && key.name === '<')) { viewport.jump(-1, ['user']); return true; }
|
|
1116
|
+
if ((key.alt && key.name === ']') || (key.alt && key.name === '>')) { viewport.jump(1, ['user']); return true; }
|
|
988
1117
|
|
|
989
1118
|
if (key.alt && key.name === 'u') { this.offerUndo(); return true; }
|
|
990
1119
|
|
|
@@ -1173,6 +1302,25 @@ export class ChatPrompt {
|
|
|
1173
1302
|
handleCompletionKey(key) {
|
|
1174
1303
|
if (key.name === 'up') { this.moveSelection(-1); return true; }
|
|
1175
1304
|
if (key.name === 'down') { this.moveSelection(1); return true; }
|
|
1305
|
+
// The wheel, PgUp and PgDn belong to the open picker. Letting them fall
|
|
1306
|
+
// through scrolled the transcript behind a frozen menu.
|
|
1307
|
+
if (key.name === 'wheel') {
|
|
1308
|
+
const direction = key.wheel && key.wheel.direction;
|
|
1309
|
+
if (direction === 'up') this.moveSelectionClamped(-1);
|
|
1310
|
+
else if (direction === 'down') this.moveSelectionClamped(1);
|
|
1311
|
+
this.scheduleDraw();
|
|
1312
|
+
return true;
|
|
1313
|
+
}
|
|
1314
|
+
if (key.name === 'pageup' && !key.shift) {
|
|
1315
|
+
this.moveSelectionClamped(-MAX_VISIBLE);
|
|
1316
|
+
this.scheduleDraw();
|
|
1317
|
+
return true;
|
|
1318
|
+
}
|
|
1319
|
+
if (key.name === 'pagedown' && !key.shift) {
|
|
1320
|
+
this.moveSelectionClamped(MAX_VISIBLE);
|
|
1321
|
+
this.scheduleDraw();
|
|
1322
|
+
return true;
|
|
1323
|
+
}
|
|
1176
1324
|
if (key.name === 'mouse') {
|
|
1177
1325
|
if (key.mouse && key.mouse.pressed && key.mouse.button === 0) {
|
|
1178
1326
|
let item = null;
|
|
@@ -1183,7 +1331,11 @@ export class ChatPrompt {
|
|
|
1183
1331
|
const pickerBottom = pickerTop + this.pickerLayout.pickerCount - 1;
|
|
1184
1332
|
|
|
1185
1333
|
if (key.mouse.row >= pickerTop && key.mouse.row <= pickerBottom) {
|
|
1186
|
-
|
|
1334
|
+
// The picker renders a scrolled window (renderPicker); a click maps
|
|
1335
|
+
// to the item under the cursor, not to the first page of items.
|
|
1336
|
+
const total = this.completion.items ? this.completion.items.length : 0;
|
|
1337
|
+
const windowStart = Math.max(0, Math.min(this.selected - MAX_VISIBLE + 1, total - MAX_VISIBLE));
|
|
1338
|
+
const index = windowStart + (key.mouse.row - pickerTop);
|
|
1187
1339
|
item = this.completion.items && this.completion.items[index];
|
|
1188
1340
|
} else {
|
|
1189
1341
|
// Click outside picker closes it
|
|
@@ -1197,16 +1349,17 @@ export class ChatPrompt {
|
|
|
1197
1349
|
|
|
1198
1350
|
if (item) {
|
|
1199
1351
|
if (this.completion.kind === 'command') {
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1352
|
+
// A skill entry goes onto the line so the user can say what to do
|
|
1353
|
+
// with it; clicking it used to invoke it immediately with no task.
|
|
1354
|
+
if (typeof item.value === 'string' && (item.value.startsWith('/skills ') || item.value.startsWith('/skill '))) {
|
|
1355
|
+
this.acceptCompletion();
|
|
1356
|
+
return true;
|
|
1357
|
+
}
|
|
1358
|
+
this.submitPickedCommand(item.value);
|
|
1203
1359
|
return true;
|
|
1204
1360
|
}
|
|
1205
1361
|
if (this.completion.kind === 'command-argument') {
|
|
1206
|
-
|
|
1207
|
-
this.editor.clear();
|
|
1208
|
-
this.completion = null;
|
|
1209
|
-
this.deliver(`/${cmd} ${item.value}`);
|
|
1362
|
+
this.submitPickedCommand(`/${this.completion.command} ${item.value}`);
|
|
1210
1363
|
return true;
|
|
1211
1364
|
}
|
|
1212
1365
|
this.acceptCompletion();
|
|
@@ -1218,10 +1371,12 @@ export class ChatPrompt {
|
|
|
1218
1371
|
if (key.name === 'enter' && !key.alt) {
|
|
1219
1372
|
const item = this.completion.items && this.completion.items[this.selected];
|
|
1220
1373
|
if (this.completion.kind === 'command' && item) {
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1374
|
+
if (typeof item.value === 'string' && (item.value.startsWith('/skills ') || item.value.startsWith('/skill '))) {
|
|
1375
|
+
this.acceptCompletion();
|
|
1376
|
+
return true;
|
|
1377
|
+
}
|
|
1378
|
+
// Instant execution on single Enter for any pure slash command
|
|
1379
|
+
this.submitPickedCommand(item.value);
|
|
1225
1380
|
return true;
|
|
1226
1381
|
}
|
|
1227
1382
|
if (this.completionIsExact()) {
|
|
@@ -1250,6 +1405,26 @@ export class ChatPrompt {
|
|
|
1250
1405
|
this.selected = (this.selected + direction + count) % count;
|
|
1251
1406
|
}
|
|
1252
1407
|
|
|
1408
|
+
/** Move without wrapping: a wheel or page key stops at either end. */
|
|
1409
|
+
moveSelectionClamped(delta) {
|
|
1410
|
+
const count = this.completion.items.length;
|
|
1411
|
+
if (count === 0) return;
|
|
1412
|
+
this.selected = Math.max(0, Math.min(count - 1, this.selected + delta));
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
/**
|
|
1416
|
+
* Run a command chosen in the picker through the same path as typing it.
|
|
1417
|
+
*
|
|
1418
|
+
* deliver() bypassed submit(): during a running turn a picked `/stop` was
|
|
1419
|
+
* queued behind the very turn it was meant to stop, and the command never
|
|
1420
|
+
* reached input history.
|
|
1421
|
+
*/
|
|
1422
|
+
submitPickedCommand(value) {
|
|
1423
|
+
this.completion = null;
|
|
1424
|
+
this.editor.setText(value);
|
|
1425
|
+
this.submit();
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1253
1428
|
acceptCompletion() {
|
|
1254
1429
|
const item = this.completion.items[this.selected];
|
|
1255
1430
|
if (!item) { this.completion = null; return; }
|
|
@@ -1344,8 +1519,9 @@ export class ChatPrompt {
|
|
|
1344
1519
|
// surface you are writing INTO. Every row of the block is inset by the same
|
|
1345
1520
|
// gutter, so the caret column is a constant rather than a special case for
|
|
1346
1521
|
// row 0 — which is also one fewer thing for erase() to get wrong.
|
|
1522
|
+
const boxWidth = Math.max(20, width - 1);
|
|
1347
1523
|
const inset = visibleWidth(GLYPHS.bar) + GUTTER;
|
|
1348
|
-
const inner = Math.max(8,
|
|
1524
|
+
const inner = Math.max(8, boxWidth - inset);
|
|
1349
1525
|
const layout = this.editor.render(inner, '');
|
|
1350
1526
|
|
|
1351
1527
|
// Scroll the editor internally rather than growing without bound: keep a
|
|
@@ -1357,8 +1533,17 @@ export class ChatPrompt {
|
|
|
1357
1533
|
const caretRow = layout.cursorRow - top;
|
|
1358
1534
|
let body = window.slice();
|
|
1359
1535
|
|
|
1536
|
+
if (!this.editor.isEmpty) {
|
|
1537
|
+
body = body.map((line) => {
|
|
1538
|
+
if (typeof line !== 'string' || !line.includes('[Image ')) return line;
|
|
1539
|
+
return line.replace(/\[Image (\d+)\]/g, (_m, num) => {
|
|
1540
|
+
return paint('warn', bold(`[Image ${num}]`));
|
|
1541
|
+
});
|
|
1542
|
+
});
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1360
1545
|
if (this.editor.isEmpty && !this.completion) {
|
|
1361
|
-
const idle = fitHints([`try "${this.example}"`, '/ commands', '@ files'], Math.max(8, inner), 'ask anything');
|
|
1546
|
+
const idle = fitHints([`try "${this.example}"`, '/ commands', '@ files', '^V image'], Math.max(8, inner), 'ask anything');
|
|
1362
1547
|
body = [dim(this.busy ? 'type to queue a message…' : idle)];
|
|
1363
1548
|
}
|
|
1364
1549
|
|
|
@@ -1385,17 +1570,18 @@ export class ChatPrompt {
|
|
|
1385
1570
|
const padded = new Array(padTop).fill('')
|
|
1386
1571
|
.concat(body, new Array(padBottom).fill(''));
|
|
1387
1572
|
const boxRows = barBlock(padded, {
|
|
1388
|
-
width,
|
|
1573
|
+
width: boxWidth,
|
|
1389
1574
|
role: this.busy ? 'accent' : 'user',
|
|
1390
1575
|
filled: true,
|
|
1391
1576
|
surface: 'surface',
|
|
1392
1577
|
punctuate: false
|
|
1393
1578
|
});
|
|
1394
1579
|
|
|
1580
|
+
const usageCardRows = this.usageCard ? renderUsageCardRows(this.usageCard, width) : [];
|
|
1395
1581
|
const planRows = this.planRows(width);
|
|
1396
1582
|
const pickerRows = this.completion ? this.pickerRows(width) : [];
|
|
1397
1583
|
this.pickerLayout = this.completion ? {
|
|
1398
|
-
pickerStart: planRows.length + boxRows.length,
|
|
1584
|
+
pickerStart: usageCardRows.length + planRows.length + boxRows.length,
|
|
1399
1585
|
pickerCount: pickerRows.length,
|
|
1400
1586
|
totalPromptRows: 0
|
|
1401
1587
|
} : null;
|
|
@@ -1409,7 +1595,7 @@ export class ChatPrompt {
|
|
|
1409
1595
|
const gap = status.length > 0 ? new Array(FOOTER_GAP).fill('') : [];
|
|
1410
1596
|
|
|
1411
1597
|
const all = this.clampRows(
|
|
1412
|
-
|
|
1598
|
+
usageCardRows.concat(planRows, boxRows, pickerRows, noticeRows, gap, status), width
|
|
1413
1599
|
);
|
|
1414
1600
|
if (this.pickerLayout) this.pickerLayout.totalPromptRows = all.length;
|
|
1415
1601
|
|
|
@@ -1420,7 +1606,7 @@ export class ChatPrompt {
|
|
|
1420
1606
|
const positioned = this.surface
|
|
1421
1607
|
? (this.surface.homeInfo ? centerRows(all, this.surface.width) : sessionRows(all, availableWidth))
|
|
1422
1608
|
: { rows: all, inset: 0 };
|
|
1423
|
-
this.present(positioned.rows, planRows.length + caretRow + padTop, layout.cursorCol + inset + positioned.inset);
|
|
1609
|
+
this.present(positioned.rows, usageCardRows.length + planRows.length + caretRow + padTop, layout.cursorCol + inset + positioned.inset);
|
|
1424
1610
|
}
|
|
1425
1611
|
|
|
1426
1612
|
/**
|
|
@@ -1434,10 +1620,11 @@ export class ChatPrompt {
|
|
|
1434
1620
|
* nothing of ours is on the terminal for erase() to walk back over.
|
|
1435
1621
|
*/
|
|
1436
1622
|
present(all, caretRow, caretCol) {
|
|
1623
|
+
const hideCursor = Boolean(this.busy && this.editor.isEmpty);
|
|
1437
1624
|
if (this.surface) {
|
|
1438
1625
|
this.drawnRows = 0;
|
|
1439
1626
|
this.cursorRow = 0;
|
|
1440
|
-
this.surface.present(all, { row: caretRow, col: caretCol,
|
|
1627
|
+
this.surface.present(all, { row: caretRow, col: caretCol, hideCursor,
|
|
1441
1628
|
modal: Boolean(this.layer), inline: Boolean(this.layer && !isStartupDialog(this.surface)) });
|
|
1442
1629
|
return;
|
|
1443
1630
|
}
|
|
@@ -1450,6 +1637,11 @@ export class ChatPrompt {
|
|
|
1450
1637
|
this.cursorRow = caretRow;
|
|
1451
1638
|
this.out.write('\r');
|
|
1452
1639
|
if (caretCol > 0) this.out.write(`\x1b[${caretCol}C`);
|
|
1640
|
+
if (hideCursor) {
|
|
1641
|
+
this.out.write('\x1b[?25l');
|
|
1642
|
+
} else {
|
|
1643
|
+
this.out.write('\x1b[?25h');
|
|
1644
|
+
}
|
|
1453
1645
|
}
|
|
1454
1646
|
|
|
1455
1647
|
/**
|