@causyne/agent 1.20.0 → 1.20.7
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 +13 -9
- package/SECURITY.md +1 -4
- package/package.json +1 -1
- package/src/acp/client.js +176 -26
- package/src/acp/client.ts +167 -25
- package/src/acp/protocol.js +116 -0
- package/src/acp/protocol.ts +163 -0
- package/src/acp/server.js +5 -6
- package/src/acp/server.ts +4 -6
- package/src/agentLoop.d.ts +1 -0
- package/src/agentLoop.js +681 -245
- package/src/agentLoop.ts +708 -262
- package/src/agentPolicy.js +9 -0
- package/src/agentPolicy.ts +9 -0
- package/src/approvalPolicy.js +55 -0
- package/src/approvalPolicy.ts +66 -0
- package/src/browser/browserRuntime.js +217 -14
- package/src/browser/browserRuntime.ts +255 -14
- package/src/browser/causyneBrowser.js +1215 -68
- package/src/browser/causyneBrowser.ts +1340 -72
- package/src/cliMode.js +52 -29
- package/src/commands.js +141 -17
- package/src/config.js +22 -12
- package/src/continuum/ui/continuumPicker.js +18 -1
- package/src/continuum/ui/continuumPicker.ts +19 -1
- package/src/dynamicCatalogue.js +87 -20
- package/src/dynamicCatalogue.ts +85 -15
- package/src/launchIntent.js +40 -0
- package/src/launchIntent.ts +49 -0
- package/src/memoryManager.js +26 -2
- package/src/modelCatalogue.js +2 -0
- package/src/planCache.js +320 -11
- package/src/planCache.ts +402 -13
- package/src/providers/acp.js +173 -18
- package/src/providers/acp.ts +169 -19
- package/src/providers/antigravity.d.ts +5 -1
- package/src/providers/antigravity.js +674 -34
- package/src/providers/antigravity.ts +707 -35
- package/src/providers/base.d.ts +10 -0
- package/src/providers/factory.js +2 -0
- package/src/providers/pi.js +161 -0
- package/src/providers/pi.ts +148 -0
- package/src/provisioning/capabilityProvisioner.js +17 -0
- package/src/provisioning/capabilityTools.js +1 -1
- package/src/sandbox.js +30 -39
- package/src/sessionJournal.js +53 -10
- package/src/sessionJournal.ts +64 -10
- package/src/taskShape.js +9 -9
- package/src/taskShape.ts +9 -9
- package/src/timeMachine.js +124 -0
- package/src/timeMachine.ts +141 -0
- package/src/toolPacks.js +4 -10
- package/src/tools/archive.js +196 -59
- package/src/tools/archive.ts +220 -0
- package/src/tools/browserAutomator.js +78 -9
- package/src/tools/browserAutomator.ts +90 -9
- package/src/tools/desktopOpen.js +114 -31
- package/src/tools/desktopOpen.ts +144 -0
- package/src/tools/gitExec.js +5 -3
- package/src/tools/nativeEngine.js +4 -3
- package/src/tools/nativeEngine.ts +5 -3
- package/src/tools/openSourceToolProvisioner.js +5 -4
- package/src/tools/openSourceToolProvisioner.ts +5 -4
- package/src/tools/registry.js +3 -0
- package/src/tools/screenshot.js +55 -71
- package/src/tools/screenshot.ts +70 -0
- package/src/tools/sysRun.js +284 -117
- package/src/tools/sysRun.ts +347 -0
- package/src/tools/toolSelfRepair.js +109 -2
- package/src/tools/toolSelfRepair.ts +100 -2
- package/src/tools/updatePlan.js +49 -1
- package/src/tools/updatePlan.ts +43 -1
- package/src/tools/viewImage.js +93 -78
- package/src/tools/viewImage.ts +116 -0
- package/src/tools/webFetch.js +20 -6
- package/src/tools/webFetch.ts +26 -6
- package/src/tui/activityLayout.js +9 -0
- package/src/tui/activityLayout.ts +10 -0
- package/src/tui/block.d.ts +1 -0
- package/src/tui/chatRenderer.d.ts +23 -0
- package/src/tui/chatRenderer.js +49 -49
- package/src/tui/clipboardSync.js +28 -1
- package/src/tui/clipboardSync.ts +26 -1
- package/src/tui/codeProgress.js +299 -0
- package/src/tui/codeProgress.ts +304 -0
- package/src/tui/codeStreamRenderer.js +132 -0
- package/src/tui/codeStreamRenderer.ts +141 -0
- package/src/tui/commandPresentation.js +11 -0
- package/src/tui/commandPresentation.ts +18 -0
- package/src/tui/completion.js +45 -13
- package/src/tui/composerControls.js +131 -0
- package/src/tui/composerControls.ts +184 -0
- package/src/tui/diff.d.ts +2 -0
- package/src/tui/home.js +4 -2
- package/src/tui/homeTransition.js +21 -0
- package/src/tui/homeTransition.ts +27 -0
- package/src/tui/homeView.js +62 -0
- package/src/tui/homeView.ts +91 -0
- package/src/tui/layout.js +46 -0
- package/src/tui/layout.ts +52 -0
- package/src/tui/messageActionPlacement.js +16 -0
- package/src/tui/messageActionPlacement.ts +25 -0
- package/src/tui/messageInteraction.js +221 -0
- package/src/tui/messageInteraction.ts +275 -0
- package/src/tui/modelPicker.js +4 -24
- package/src/tui/modelPicker.ts +4 -20
- package/src/tui/mouseHover.js +6 -0
- package/src/tui/mouseHover.ts +5 -0
- package/src/tui/prompt.js +175 -101
- package/src/tui/resizeRecovery.js +15 -0
- package/src/tui/resizeRecovery.ts +27 -0
- package/src/tui/scrollInteraction.js +97 -0
- package/src/tui/scrollInteraction.ts +189 -0
- package/src/tui/sessionLayout.js +12 -0
- package/src/tui/sessionLayout.ts +12 -0
- package/src/tui/sessionPicker.js +111 -16
- package/src/tui/sessionPicker.ts +121 -16
- package/src/tui/sessionSidebar.js +78 -0
- package/src/tui/sessionSidebar.ts +95 -0
- package/src/tui/setup.js +1 -1
- package/src/tui/setup.ts +1 -1
- package/src/tui/stageSurface.js +120 -58
- package/src/tui/text.d.ts +6 -0
- package/src/tui/textLayout.js +23 -0
- package/src/tui/textLayout.ts +28 -0
- package/src/tui/viewport.js +204 -279
- package/src/tui/viewport.ts +326 -0
- package/src/types/contracts.ts +54 -0
- package/src/utils/paths.js +5 -4
- package/src/utils/paths.ts +5 -5
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Terminal-wide motion reports allow hover feedback; opt out for native text selection. */
|
|
2
|
+
export function mouseHoverTracking(enabled: boolean, env: NodeJS.ProcessEnv = process.env): string {
|
|
3
|
+
if (String(env.CAUSYNE_MOUSE_HOVER ?? '1') === '0') return '';
|
|
4
|
+
return enabled ? '\x1b[?1003h' : '\x1b[?1003l';
|
|
5
|
+
}
|
package/src/tui/prompt.js
CHANGED
|
@@ -29,6 +29,19 @@ import { panelRows } from './overlay.js';
|
|
|
29
29
|
import { commandPalette, skillPicker, ApprovalLayer, DecisionLayer, ConfirmLayer, HomeLayer, TextLayer } from './dialogs.js';
|
|
30
30
|
import { describeTool } from './toolDisplay.js';
|
|
31
31
|
import { readClipboardSync } from './clipboardSync.js';
|
|
32
|
+
import { handleViewportWheel, handleScrollbarMouse } from './scrollInteraction.js';
|
|
33
|
+
import { centerRows, sessionRows, dialogWidth, dialogHeight } from './layout.js';
|
|
34
|
+
import { settleStageResize } from './resizeRecovery.js';
|
|
35
|
+
import { sidebarVisible, sessionMainWidth } from './sessionSidebar.js';
|
|
36
|
+
import { isStartupDialog, startupDialogView } from './homeView.js';
|
|
37
|
+
import { handleMessageMouse, handleMessageActionMenuMouse, isMouseMotion } from './messageInteraction.js';
|
|
38
|
+
import {
|
|
39
|
+
resetTurnInterruptState,
|
|
40
|
+
shouldAcceptStatusUpdate,
|
|
41
|
+
triggerTurnInterrupt,
|
|
42
|
+
handlePromptCtrlC,
|
|
43
|
+
handlePromptEscape
|
|
44
|
+
} from './composerControls.js';
|
|
32
45
|
|
|
33
46
|
const CTRL_C_WINDOW_MS = 2000;
|
|
34
47
|
|
|
@@ -93,6 +106,11 @@ export class ChatPrompt {
|
|
|
93
106
|
this.surface = options.surface || null;
|
|
94
107
|
this.onExit = options.onExit || (() => process.exit(0));
|
|
95
108
|
this.onExpand = options.onExpand || (() => {});
|
|
109
|
+
this.onOpenMode = options.onOpenMode || null;
|
|
110
|
+
this.onOpenModel = options.onOpenModel || null;
|
|
111
|
+
this.onOpenVariant = options.onOpenVariant || null;
|
|
112
|
+
this.messageActionLoop = options.messageActionLoop || null;
|
|
113
|
+
this.getMode = options.getMode || (() => 'B');
|
|
96
114
|
|
|
97
115
|
this.editor = new LineEditor();
|
|
98
116
|
this.history = options.history || new PromptHistory();
|
|
@@ -126,9 +144,8 @@ export class ChatPrompt {
|
|
|
126
144
|
|
|
127
145
|
// Commands for the palette, and the dialog that currently owns the keyboard.
|
|
128
146
|
//
|
|
129
|
-
//
|
|
130
|
-
//
|
|
131
|
-
// no way to dim what is already in the user's scrollback.
|
|
147
|
+
// Dialogs use the live stage as a centered temporary view and restore the
|
|
148
|
+
// transcript when dismissed. Terminal scrollback is not repainted.
|
|
132
149
|
this.commands = options.commands || [];
|
|
133
150
|
|
|
134
151
|
// Is this line a COMMAND rather than a message?
|
|
@@ -144,9 +161,11 @@ export class ChatPrompt {
|
|
|
144
161
|
this.completion = null;
|
|
145
162
|
this.selected = 0;
|
|
146
163
|
this.lastCtrlC = 0;
|
|
164
|
+
this.interruptedTurn = false;
|
|
147
165
|
this.notice = '';
|
|
148
166
|
this.redrawScheduled = false;
|
|
149
167
|
this.resizeTimer = null;
|
|
168
|
+
this.suspendedSurface = null;
|
|
150
169
|
}
|
|
151
170
|
|
|
152
171
|
// -------------------------------------------------------------------------
|
|
@@ -202,7 +221,7 @@ export class ChatPrompt {
|
|
|
202
221
|
* instead of once per pixel.
|
|
203
222
|
*/
|
|
204
223
|
handleResize = () => {
|
|
205
|
-
this.erase();
|
|
224
|
+
if (!this.resizeTimer) this.erase();
|
|
206
225
|
// The Stage owns its own geometry and cannot repaint a band whose height it
|
|
207
226
|
// no longer knows. Resizing it here, before the settle timer, would do it
|
|
208
227
|
// once per pixel of a drag; it is done in the settled callback below.
|
|
@@ -219,14 +238,19 @@ export class ChatPrompt {
|
|
|
219
238
|
// A stage that can no longer fit gives the band back and hands the
|
|
220
239
|
// session to the scrollback renderer rather than painting into a region
|
|
221
240
|
// too short to hold a viewport.
|
|
222
|
-
|
|
241
|
+
const settled = settleStageResize(this.surface, this.suspendedSurface);
|
|
242
|
+
this.surface = settled.current;
|
|
243
|
+
this.suspendedSurface = settled.suspended;
|
|
244
|
+
if (settled.restored) this.attachSurface(settled.current);
|
|
223
245
|
this.draw();
|
|
224
246
|
}, RESIZE_SETTLE_MS);
|
|
225
247
|
if (this.resizeTimer.unref) this.resizeTimer.unref();
|
|
226
248
|
};
|
|
227
249
|
|
|
228
250
|
handleData = (chunk) => {
|
|
251
|
+
let motionOnly = true;
|
|
229
252
|
for (const key of this.decoder.decode(chunk)) {
|
|
253
|
+
if (key.name !== 'mouse' || !isMouseMotion(key.sequence)) motionOnly = false;
|
|
230
254
|
try {
|
|
231
255
|
this.handleKey(key);
|
|
232
256
|
} catch (e) {
|
|
@@ -235,7 +259,8 @@ export class ChatPrompt {
|
|
|
235
259
|
process.stderr.write(`\n[tui] key "${key.name}" failed: ${e.message}\n`);
|
|
236
260
|
}
|
|
237
261
|
}
|
|
238
|
-
|
|
262
|
+
// All-motion chunks repaint only when the hovered message actually changes.
|
|
263
|
+
if (!motionOnly) this.draw();
|
|
239
264
|
};
|
|
240
265
|
|
|
241
266
|
/**
|
|
@@ -261,12 +286,18 @@ export class ChatPrompt {
|
|
|
261
286
|
// uses in full-screen mode, which reports status instead of animating it.
|
|
262
287
|
// Reuse that and make the status a row of the live region.
|
|
263
288
|
this.renderer = renderer;
|
|
289
|
+
if (this.surface) this.surface.sidebarStatus = renderer.status;
|
|
264
290
|
renderer.quietStatus = true;
|
|
265
291
|
renderer.onStatusChange = (message) => {
|
|
292
|
+
if (!shouldAcceptStatusUpdate(this)) return;
|
|
266
293
|
this.statusMessage = message;
|
|
267
294
|
this.scheduleDraw();
|
|
268
295
|
};
|
|
269
|
-
renderer.onPlanChange = () =>
|
|
296
|
+
renderer.onPlanChange = (plan) => {
|
|
297
|
+
if (this.surface) this.surface.sidebarPlan = plan;
|
|
298
|
+
this.scheduleDraw();
|
|
299
|
+
return this.surface && sidebarVisible(this.surface.width) ? 'sidebar' : undefined;
|
|
300
|
+
};
|
|
270
301
|
}
|
|
271
302
|
|
|
272
303
|
/**
|
|
@@ -315,17 +346,20 @@ export class ChatPrompt {
|
|
|
315
346
|
const status = this.renderer && this.renderer.status;
|
|
316
347
|
if (!status) return null;
|
|
317
348
|
|
|
318
|
-
const mode = this.busy ? 'Working' : 'Build'
|
|
349
|
+
const mode = `${this.busy ? 'Working' : 'Build'} ${this.getMode()}`;
|
|
319
350
|
const parts = [bold(paint('accent', mode))];
|
|
320
351
|
if (status.model) parts.push(bold(paint('ink', status.model)));
|
|
321
352
|
const line = parts.join(dim(` ${GLYPHS.dot} `));
|
|
322
353
|
const trailing = [status.provider, status.tier].filter(Boolean).join(' ');
|
|
323
|
-
const
|
|
354
|
+
const base = trailing ? `${line} ${dim(trailing)}` : line;
|
|
355
|
+
const hints = dim(' Ctrl+G mode · Alt+M model · Ctrl+T variant');
|
|
356
|
+
const full = visibleWidth(base) + visibleWidth(hints) <= width ? base + hints : base;
|
|
324
357
|
return visibleWidth(full) > width ? truncate(full, width, GLYPHS.ellipsis) : full;
|
|
325
358
|
}
|
|
326
359
|
|
|
327
360
|
/** Persistent checklist shown outside the chat transcript. */
|
|
328
361
|
planRows(width) {
|
|
362
|
+
if (this.surface && sidebarVisible(this.surface.width)) return [];
|
|
329
363
|
const plan = this.renderer && Array.isArray(this.renderer.latestPlan) ? this.renderer.latestPlan : [];
|
|
330
364
|
if (plan.length === 0) return [];
|
|
331
365
|
const completed = plan.filter(item => item.status === 'completed').length;
|
|
@@ -455,7 +489,7 @@ export class ChatPrompt {
|
|
|
455
489
|
|
|
456
490
|
/** Show local command output inside the live region, never in chat scrollback. */
|
|
457
491
|
showText(title, text, options = {}) {
|
|
458
|
-
const panelWidth =
|
|
492
|
+
const panelWidth = dialogWidth(this.width(), options.width || 76);
|
|
459
493
|
const contentWidth = Math.max(12, panelWidth - 4);
|
|
460
494
|
const lines = wrapBlock(safeDisplay(String(text == null ? '' : text)), contentWidth);
|
|
461
495
|
return this.openLayer(new TextLayer({
|
|
@@ -521,10 +555,7 @@ export class ChatPrompt {
|
|
|
521
555
|
* count and starts eating the conversation above.
|
|
522
556
|
*/
|
|
523
557
|
width() {
|
|
524
|
-
// The Stage
|
|
525
|
-
// composition, while there is no transcript yet, so the input box lines up
|
|
526
|
-
// with the banner above it instead of stretching past it. Once the session
|
|
527
|
-
// starts it hands back the full width and nothing below here changes.
|
|
558
|
+
// The Stage keeps the composer at one readable measure through the session.
|
|
528
559
|
if (this.surface && typeof this.surface.composeWidth === 'function') {
|
|
529
560
|
const asked = this.surface.composeWidth();
|
|
530
561
|
if (Number.isFinite(asked) && asked > 0) return Math.max(20, asked);
|
|
@@ -582,7 +613,7 @@ export class ChatPrompt {
|
|
|
582
613
|
|
|
583
614
|
setBusy(busy) {
|
|
584
615
|
this.busy = busy;
|
|
585
|
-
|
|
616
|
+
resetTurnInterruptState(this, busy);
|
|
586
617
|
if (busy) this.startTick(); else this.stopTick();
|
|
587
618
|
this.draw();
|
|
588
619
|
}
|
|
@@ -631,22 +662,13 @@ export class ChatPrompt {
|
|
|
631
662
|
return;
|
|
632
663
|
}
|
|
633
664
|
|
|
634
|
-
//
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
// filled block (screenshot 15.02.21), which is the seam that lets the eye
|
|
639
|
-
// find where each exchange begins when scrolling back through a long turn.
|
|
640
|
-
// width - 1, not width. A block built to the FULL terminal width fills the
|
|
641
|
-
// final column, the terminal wraps it, and one drawn row becomes two real
|
|
642
|
-
// ones — so erase() walks back half as far as it should and leaves the
|
|
643
|
-
// remainder on screen. That is why a six-line message came back as six
|
|
644
|
-
// stray fragments of its own tail. barBlock honours whatever width it is
|
|
645
|
-
// given; reserving the column is the caller's job.
|
|
646
|
-
this.commit('user', (width) => {
|
|
665
|
+
// Render live submissions through the same path used when history reflows.
|
|
666
|
+
if (this.surface?.homeInfo) this.surface.leaveHome();
|
|
667
|
+
if (this.renderer?.renderUserMessage) this.renderer.renderUserMessage(text);
|
|
668
|
+
else this.commit('user', (width) => {
|
|
647
669
|
const blockWidth = Math.max(8, width - 1);
|
|
648
670
|
return barBlock(
|
|
649
|
-
wrapBlock(text, Math.max(8, blockWidth - visibleWidth(GLYPHS.bar) - GUTTER)),
|
|
671
|
+
wrapBlock(safeDisplay(text), Math.max(8, blockWidth - visibleWidth(GLYPHS.bar) - GUTTER)),
|
|
650
672
|
{ width: blockWidth, role: 'user', filled: true, surface: 'surfaceHi' }
|
|
651
673
|
);
|
|
652
674
|
});
|
|
@@ -688,7 +710,12 @@ export class ChatPrompt {
|
|
|
688
710
|
// This MUST route before any default key handling (like paste) so modal
|
|
689
711
|
// dialogs (e.g. InputLayer for API keys) receive bracketed paste events.
|
|
690
712
|
if (this.layer) {
|
|
691
|
-
const
|
|
713
|
+
const previousSelection = this.layer.messageActions ? this.layer.list?.selected : null;
|
|
714
|
+
const action = key.name === 'mouse' && this.layer.messageActions
|
|
715
|
+
? handleMessageActionMenuMouse(this.layer, key)
|
|
716
|
+
: this.layer.key(key);
|
|
717
|
+
if (this.layer?.messageActions && isMouseMotion(key.sequence)
|
|
718
|
+
&& previousSelection !== this.layer.list?.selected) this.scheduleDraw();
|
|
692
719
|
if (action === 'close') { this.closeLayer(); return; }
|
|
693
720
|
// A layer may hand a key BACK rather than swallow it. The home menu does
|
|
694
721
|
// this for every printable character, so `↑↓` picks an action while typing
|
|
@@ -710,6 +737,22 @@ export class ChatPrompt {
|
|
|
710
737
|
if (this.completion && this.handleCompletionKey(key)) return;
|
|
711
738
|
if (this.handleScrollKey(key)) return;
|
|
712
739
|
|
|
740
|
+
const control = key.ctrl && key.name === 'g' ? this.onOpenMode
|
|
741
|
+
: key.alt && key.name === 'm' ? this.onOpenModel
|
|
742
|
+
: key.ctrl && key.name === 't' ? this.onOpenVariant : null;
|
|
743
|
+
if (control) {
|
|
744
|
+
if (this.busy) {
|
|
745
|
+
this.notice = 'Finish or interrupt the current turn before switching controls';
|
|
746
|
+
this.scheduleDraw();
|
|
747
|
+
} else {
|
|
748
|
+
Promise.resolve(control()).catch(error => {
|
|
749
|
+
this.notice = error instanceof Error ? error.message : String(error);
|
|
750
|
+
this.scheduleDraw();
|
|
751
|
+
});
|
|
752
|
+
}
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
755
|
+
|
|
713
756
|
switch (key.name) {
|
|
714
757
|
case 'escape': return this.handleEscape();
|
|
715
758
|
case 'enter':
|
|
@@ -786,24 +829,19 @@ export class ChatPrompt {
|
|
|
786
829
|
// fall through would put `mouse` or `wheel` into the switch below, where a
|
|
787
830
|
// future case could act on it by accident — and, worse, a terminal that
|
|
788
831
|
// kept reporting after a failed teardown would type into the user's line.
|
|
789
|
-
if (key.name === 'mouse')
|
|
832
|
+
if (key.name === 'mouse') {
|
|
833
|
+
if (this.messageActionLoop && isMouseMotion(key.sequence)) {
|
|
834
|
+
return handleMessageMouse(this, this.messageActionLoop, key);
|
|
835
|
+
}
|
|
836
|
+
if (handleScrollbarMouse(key, viewport, this.surface, this)) return true;
|
|
837
|
+
if (!this.layer && this.messageActionLoop) return handleMessageMouse(this, this.messageActionLoop, key);
|
|
838
|
+
return true;
|
|
839
|
+
}
|
|
790
840
|
if (key.name === 'wheel') {
|
|
791
841
|
if (!viewport || !key.wheel) return true;
|
|
842
|
+
if (this.renderer?.scrollCodePanel?.(key, this.surface)) return true;
|
|
792
843
|
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
// At the top of the band, an upward wheel belongs to the TERMINAL — the
|
|
796
|
-
// conversation continues above us in its own scrollback. Releasing mouse
|
|
797
|
-
// reporting is the only way to give it back; the bytes for this event are
|
|
798
|
-
// already consumed, so the release takes effect from the next notch.
|
|
799
|
-
if (!viewport.lastWheelMoved && key.wheel.direction === 'up'
|
|
800
|
-
&& this.surface && typeof this.surface.releaseMouse === 'function') {
|
|
801
|
-
if (this.surface.releaseMouse()) {
|
|
802
|
-
this.notice = 'top of this view — scrolling with the terminal now; press any key to come back';
|
|
803
|
-
this.draw();
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
return true;
|
|
844
|
+
return handleViewportWheel(key, viewport, this.surface, this);
|
|
807
845
|
}
|
|
808
846
|
|
|
809
847
|
if (!viewport) return false;
|
|
@@ -895,36 +933,25 @@ export class ChatPrompt {
|
|
|
895
933
|
}
|
|
896
934
|
|
|
897
935
|
handleCtrlC() {
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
}
|
|
904
|
-
if (this.busy) { this.interrupt(); return; }
|
|
905
|
-
if (now - this.lastCtrlC < CTRL_C_WINDOW_MS) return this.onExit();
|
|
906
|
-
this.lastCtrlC = now;
|
|
907
|
-
this.notice = 'press Ctrl+C again to exit';
|
|
936
|
+
handlePromptCtrlC(
|
|
937
|
+
this,
|
|
938
|
+
() => [`${paint('warn', GLYPHS.cross)} ${dim('interrupted')}`],
|
|
939
|
+
CTRL_C_WINDOW_MS
|
|
940
|
+
);
|
|
908
941
|
}
|
|
909
942
|
|
|
910
943
|
handleEscape() {
|
|
911
|
-
|
|
912
|
-
this
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
}
|
|
916
|
-
this.scheduleDraw();
|
|
917
|
-
return;
|
|
918
|
-
}
|
|
919
|
-
if (this.busy) return this.interrupt();
|
|
920
|
-
this.editor.clear();
|
|
944
|
+
handlePromptEscape(
|
|
945
|
+
this,
|
|
946
|
+
() => [`${paint('warn', GLYPHS.cross)} ${dim('interrupted')}`]
|
|
947
|
+
);
|
|
921
948
|
}
|
|
922
949
|
|
|
923
950
|
interrupt() {
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
951
|
+
triggerTurnInterrupt(
|
|
952
|
+
this,
|
|
953
|
+
() => [`${paint('warn', GLYPHS.cross)} ${dim('interrupted')}`]
|
|
954
|
+
);
|
|
928
955
|
}
|
|
929
956
|
|
|
930
957
|
/** Show the last tool output in full, above the prompt. */
|
|
@@ -1039,36 +1066,57 @@ export class ChatPrompt {
|
|
|
1039
1066
|
handleCompletionKey(key) {
|
|
1040
1067
|
if (key.name === 'up') { this.moveSelection(-1); return true; }
|
|
1041
1068
|
if (key.name === 'down') { this.moveSelection(1); return true; }
|
|
1042
|
-
if (key.name === '
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
if (
|
|
1046
|
-
this.
|
|
1047
|
-
this.
|
|
1048
|
-
this.
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
this.completion
|
|
1062
|
-
this.deliver(`/sessions ${item.value}`);
|
|
1063
|
-
return true;
|
|
1069
|
+
if (key.name === 'mouse') {
|
|
1070
|
+
if (key.mouse && key.mouse.pressed && key.mouse.button === 0) {
|
|
1071
|
+
let item = null;
|
|
1072
|
+
if (this.pickerLayout && Number.isFinite(key.mouse.row)) {
|
|
1073
|
+
const stageHeight = this.surface?.stage?.height || process.stdout.rows || 24;
|
|
1074
|
+
const promptTop = Math.max(1, stageHeight - this.pickerLayout.totalPromptRows + 1);
|
|
1075
|
+
const pickerTop = promptTop + this.pickerLayout.pickerStart;
|
|
1076
|
+
const pickerBottom = pickerTop + this.pickerLayout.pickerCount - 1;
|
|
1077
|
+
|
|
1078
|
+
if (key.mouse.row >= pickerTop && key.mouse.row <= pickerBottom) {
|
|
1079
|
+
const index = key.mouse.row - pickerTop;
|
|
1080
|
+
item = this.completion.items && this.completion.items[index];
|
|
1081
|
+
} else {
|
|
1082
|
+
// Click outside picker closes it
|
|
1083
|
+
this.completion = null;
|
|
1084
|
+
this.scheduleDraw();
|
|
1085
|
+
return true;
|
|
1086
|
+
}
|
|
1087
|
+
} else {
|
|
1088
|
+
item = this.completion.items && this.completion.items[this.selected];
|
|
1064
1089
|
}
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
this.completion
|
|
1068
|
-
|
|
1090
|
+
|
|
1091
|
+
if (item) {
|
|
1092
|
+
if (this.completion.kind === 'command') {
|
|
1093
|
+
this.editor.clear();
|
|
1094
|
+
this.completion = null;
|
|
1095
|
+
this.deliver(item.value);
|
|
1096
|
+
return true;
|
|
1097
|
+
}
|
|
1098
|
+
if (this.completion.kind === 'command-argument') {
|
|
1099
|
+
const cmd = this.completion.command;
|
|
1100
|
+
this.editor.clear();
|
|
1101
|
+
this.completion = null;
|
|
1102
|
+
this.deliver(`/${cmd} ${item.value}`);
|
|
1103
|
+
return true;
|
|
1104
|
+
}
|
|
1105
|
+
this.acceptCompletion();
|
|
1069
1106
|
return true;
|
|
1070
1107
|
}
|
|
1071
1108
|
}
|
|
1109
|
+
return true;
|
|
1110
|
+
}
|
|
1111
|
+
if (key.name === 'enter' && !key.alt) {
|
|
1112
|
+
const item = this.completion.items && this.completion.items[this.selected];
|
|
1113
|
+
if (this.completion.kind === 'command' && item) {
|
|
1114
|
+
// Instant execution on single Enter for any slash command
|
|
1115
|
+
this.editor.clear();
|
|
1116
|
+
this.completion = null;
|
|
1117
|
+
this.deliver(item.value);
|
|
1118
|
+
return true;
|
|
1119
|
+
}
|
|
1072
1120
|
if (this.completionIsExact()) {
|
|
1073
1121
|
// Nothing left to complete. Close the picker and let the key through to
|
|
1074
1122
|
// submit, rather than re-offering what is already on the line.
|
|
@@ -1173,6 +1221,7 @@ export class ChatPrompt {
|
|
|
1173
1221
|
}
|
|
1174
1222
|
|
|
1175
1223
|
draw() {
|
|
1224
|
+
if (this.resizeTimer) return;
|
|
1176
1225
|
if (!this.active) return;
|
|
1177
1226
|
this.erase();
|
|
1178
1227
|
|
|
@@ -1236,7 +1285,13 @@ export class ChatPrompt {
|
|
|
1236
1285
|
punctuate: true
|
|
1237
1286
|
});
|
|
1238
1287
|
|
|
1288
|
+
const planRows = this.planRows(width);
|
|
1239
1289
|
const pickerRows = this.completion ? this.pickerRows(width) : [];
|
|
1290
|
+
this.pickerLayout = this.completion ? {
|
|
1291
|
+
pickerStart: planRows.length + boxRows.length,
|
|
1292
|
+
pickerCount: pickerRows.length,
|
|
1293
|
+
totalPromptRows: 0
|
|
1294
|
+
} : null;
|
|
1240
1295
|
const noticeRows = this.notice ? [dim(` ${this.notice}`)] : [];
|
|
1241
1296
|
|
|
1242
1297
|
// And a row of air between the box and the footer. The picker and a notice
|
|
@@ -1246,13 +1301,16 @@ export class ChatPrompt {
|
|
|
1246
1301
|
const status = this.statusRow(width);
|
|
1247
1302
|
const gap = status.length > 0 ? new Array(FOOTER_GAP).fill('') : [];
|
|
1248
1303
|
|
|
1249
|
-
const planRows = this.planRows(width);
|
|
1250
1304
|
const all = this.clampRows(
|
|
1251
1305
|
planRows.concat(boxRows, pickerRows, noticeRows, gap, status), width
|
|
1252
1306
|
);
|
|
1307
|
+
if (this.pickerLayout) this.pickerLayout.totalPromptRows = all.length;
|
|
1253
1308
|
|
|
1254
1309
|
// Park the cursor where the user is typing, not at the end of the picker.
|
|
1255
|
-
|
|
1310
|
+
const positioned = this.surface
|
|
1311
|
+
? (this.surface.homeInfo ? centerRows(all, this.surface.width) : sessionRows(all, sessionMainWidth(this.surface.width)))
|
|
1312
|
+
: { rows: all, inset: 0 };
|
|
1313
|
+
this.present(positioned.rows, planRows.length + caretRow + padTop, layout.cursorCol + inset + positioned.inset);
|
|
1256
1314
|
}
|
|
1257
1315
|
|
|
1258
1316
|
/**
|
|
@@ -1269,7 +1327,8 @@ export class ChatPrompt {
|
|
|
1269
1327
|
if (this.surface) {
|
|
1270
1328
|
this.drawnRows = 0;
|
|
1271
1329
|
this.cursorRow = 0;
|
|
1272
|
-
this.surface.present(all, { row: caretRow, col: caretCol
|
|
1330
|
+
this.surface.present(all, { row: caretRow, col: caretCol,
|
|
1331
|
+
modal: Boolean(this.layer), inline: Boolean(this.layer && !isStartupDialog(this.surface)) });
|
|
1273
1332
|
return;
|
|
1274
1333
|
}
|
|
1275
1334
|
|
|
@@ -1312,14 +1371,29 @@ export class ChatPrompt {
|
|
|
1312
1371
|
|
|
1313
1372
|
/** The live region while a dialog is up: the panel, then the status row. */
|
|
1314
1373
|
drawLayer(width) {
|
|
1315
|
-
|
|
1316
|
-
|
|
1374
|
+
if (this.layer.messageActions && this.surface?.presentMessageActions) {
|
|
1375
|
+
const availableWidth = sessionMainWidth(this.surface.width);
|
|
1376
|
+
const panelWidth = dialogWidth(Math.max(8, availableWidth - 3), this.layer.width || 68);
|
|
1377
|
+
const panel = panelRows(this.layer, panelWidth, this.layer.preferredHeight());
|
|
1378
|
+
this.surface.presentMessageActions(panel, this.layer);
|
|
1379
|
+
return;
|
|
1380
|
+
}
|
|
1381
|
+
if (isStartupDialog(this.surface)) {
|
|
1382
|
+
const view = startupDialogView(this.layer, this.surface.width, this.surface.stage.maxHeight);
|
|
1383
|
+
return this.present(view.rows, view.caretRow, view.caretCol);
|
|
1384
|
+
}
|
|
1385
|
+
const inline = this.surface && !this.surface.homeInfo;
|
|
1386
|
+
const availableWidth = inline ? sessionMainWidth(this.surface.width) : width;
|
|
1387
|
+
const panelWidth = dialogWidth(availableWidth, this.layer.width || 64);
|
|
1388
|
+
const maxHeight = dialogHeight(this.surface?.stage?.maxHeight || this.out?.rows, this.layer.preferredHeight());
|
|
1317
1389
|
const panel = panelRows(this.layer, panelWidth, maxHeight);
|
|
1318
1390
|
const all = this.clampRows(panel.concat(this.statusRow(width)), width);
|
|
1319
1391
|
|
|
1320
1392
|
// panelRows() called body(), which is where a layer publishes its cursor.
|
|
1321
1393
|
const cursor = this.layer.cursor;
|
|
1322
|
-
this.
|
|
1394
|
+
const centered = this.surface ? centerRows(all, availableWidth) : { rows: all, inset: 0 };
|
|
1395
|
+
this.present(centered.rows, cursor ? 1 + cursor.y : 0,
|
|
1396
|
+
(cursor ? 2 + cursor.x : 0) + centered.inset);
|
|
1323
1397
|
}
|
|
1324
1398
|
|
|
1325
1399
|
pickerRows(width) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** A temporary small terminal must not permanently discard the live surface. */
|
|
2
|
+
export function settleStageResize(current, suspended) {
|
|
3
|
+
if (current) {
|
|
4
|
+
return current.resize()
|
|
5
|
+
? { current, suspended: null, restored: false }
|
|
6
|
+
: { current: null, suspended: current, restored: false };
|
|
7
|
+
}
|
|
8
|
+
if (suspended) {
|
|
9
|
+
suspended.resize();
|
|
10
|
+
if (suspended.stage.maxHeight > 0 && suspended.open()) {
|
|
11
|
+
return { current: suspended, suspended: null, restored: true };
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return { current: null, suspended, restored: false };
|
|
15
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface ResizableStage {
|
|
2
|
+
stage: { maxHeight: number };
|
|
3
|
+
resize(): boolean;
|
|
4
|
+
open(): boolean;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface ResizeState<T extends ResizableStage> {
|
|
8
|
+
current: T | null;
|
|
9
|
+
suspended: T | null;
|
|
10
|
+
restored: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** A temporary small terminal must not permanently discard the live surface. */
|
|
14
|
+
export function settleStageResize<T extends ResizableStage>(current: T | null, suspended: T | null): ResizeState<T> {
|
|
15
|
+
if (current) {
|
|
16
|
+
return current.resize()
|
|
17
|
+
? { current, suspended: null, restored: false }
|
|
18
|
+
: { current: null, suspended: current, restored: false };
|
|
19
|
+
}
|
|
20
|
+
if (suspended) {
|
|
21
|
+
suspended.resize();
|
|
22
|
+
if (suspended.stage.maxHeight > 0 && suspended.open()) {
|
|
23
|
+
return { current: suspended, suspended: null, restored: true };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return { current: null, suspended, restored: false };
|
|
27
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Sovereign TUI Scroll & Mouse Isolation Controller
|
|
2
|
+
//
|
|
3
|
+
// Implements OpenCode-compliant viewport containment:
|
|
4
|
+
// 1. Mouse wheel events are strictly confined to the chat box viewport.
|
|
5
|
+
// 2. Overscrolling past the top (0) or bottom (maxScrollTop) saturates cleanly.
|
|
6
|
+
// 3. Mouse reporting is NEVER released to the terminal during an active session,
|
|
7
|
+
// preventing terminal scrollback desync and UI freezes.
|
|
8
|
+
// 4. Scrollbar (rail) mouse interactions clamp cleanly even if clicked above or
|
|
9
|
+
// below the chat box bounds.
|
|
10
|
+
/**
|
|
11
|
+
* Handle mouse wheel scrolling with full viewport containment.
|
|
12
|
+
* Replaces the buggy overscroll release with clean boundary saturation.
|
|
13
|
+
*/
|
|
14
|
+
export function handleViewportWheel(key, viewport, surface, host) {
|
|
15
|
+
if (!viewport || !key.wheel)
|
|
16
|
+
return true;
|
|
17
|
+
// Auto-heal: If the surface was ever detached, immediately re-capture mouse
|
|
18
|
+
// so the session stays responsive and never freezes.
|
|
19
|
+
if (surface && typeof surface.captureMouse === 'function' && surface.detached) {
|
|
20
|
+
surface.captureMouse();
|
|
21
|
+
if (host.notice.startsWith('top of this view')) {
|
|
22
|
+
host.notice = '';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
// Pure isolated scrolling: clamp strictly inside [0, maxScrollTop]
|
|
26
|
+
viewport.wheel(key.wheel.direction === 'down' ? 'down' : 'up');
|
|
27
|
+
// Immediately draw updated viewport
|
|
28
|
+
host.draw();
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Handle mouse clicks on the scrollbar rail.
|
|
33
|
+
* Safely clamps coordinates even when clicking above or below the chat box.
|
|
34
|
+
*/
|
|
35
|
+
export function handleScrollbarMouse(key, viewport, surface, host) {
|
|
36
|
+
if (!viewport || !surface || !key.mouse || !key.mouse.pressed)
|
|
37
|
+
return false;
|
|
38
|
+
if (key.mouse.button !== 0)
|
|
39
|
+
return false; // Left click only
|
|
40
|
+
// If completion picker is active, check if click was on the picker
|
|
41
|
+
if (host.pickerLayout && Number.isFinite(key.mouse.y)) {
|
|
42
|
+
const termRows = host.out?.rows || 24;
|
|
43
|
+
const stageH = surface.stage?.height || termRows;
|
|
44
|
+
const promptTop = Math.max(1, stageH - host.pickerLayout.totalPromptRows + 1);
|
|
45
|
+
const pickerTop = promptTop + host.pickerLayout.pickerStart - 1;
|
|
46
|
+
const pickerBottom = pickerTop + host.pickerLayout.pickerCount;
|
|
47
|
+
if (key.mouse.y >= pickerTop && key.mouse.y <= pickerBottom) {
|
|
48
|
+
return false; // Leave to completion handler
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const termRows = host.out?.rows || 24;
|
|
52
|
+
const stageH = surface.stage?.height || termRows;
|
|
53
|
+
const stageTop = Math.max(0, termRows - stageH);
|
|
54
|
+
const viewportH = viewport.height;
|
|
55
|
+
const stageW = typeof surface.stage?.width === 'function' ? surface.stage.width() : (surface.width || 80);
|
|
56
|
+
const hasRail = typeof surface.railEnabled === 'function' ? surface.railEnabled(stageW) : true;
|
|
57
|
+
const contentW = hasRail ? Math.max(20, stageW - 3) : stageW;
|
|
58
|
+
const mouseX = key.mouse.x;
|
|
59
|
+
const mouseY = key.mouse.y;
|
|
60
|
+
// Rail occupies column contentW - 1 through stageW
|
|
61
|
+
const isRailColumn = mouseX >= contentW - 1 && mouseX <= stageW;
|
|
62
|
+
if (isRailColumn) {
|
|
63
|
+
// Auto-heal if detached
|
|
64
|
+
if (typeof surface.captureMouse === 'function' && surface.detached) {
|
|
65
|
+
surface.captureMouse();
|
|
66
|
+
if (host.notice.startsWith('top of this view'))
|
|
67
|
+
host.notice = '';
|
|
68
|
+
}
|
|
69
|
+
// Boundary clamping:
|
|
70
|
+
// Clicks preceding/above chat box clamp to top (0)
|
|
71
|
+
if (mouseY < stageTop) {
|
|
72
|
+
viewport.scrollTo(0);
|
|
73
|
+
host.draw();
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
// Clicks below viewport clamp to bottom (maxScrollTop) and resume following
|
|
77
|
+
if (mouseY >= stageTop + viewportH) {
|
|
78
|
+
viewport.toBottom();
|
|
79
|
+
host.draw();
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
// Clicks on rail inside viewport: compute proportional scroll
|
|
83
|
+
const relY = mouseY - stageTop;
|
|
84
|
+
const fraction = viewportH > 1 ? relY / (viewportH - 1) : 0;
|
|
85
|
+
const clampedFraction = Math.max(0, Math.min(1, fraction));
|
|
86
|
+
const target = Math.round(clampedFraction * viewport.maxScrollTop());
|
|
87
|
+
if (target >= viewport.maxScrollTop()) {
|
|
88
|
+
viewport.toBottom();
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
viewport.scrollTo(target);
|
|
92
|
+
}
|
|
93
|
+
host.draw();
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
97
|
+
}
|