@causyne/agent 1.20.112 → 1.20.117
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/docs/ARCHITECTURE.md +29 -0
- package/package.json +1 -1
- package/src/agentLoop.js +153 -68
- package/src/agentLoop.ts +152 -71
- package/src/browser/browserRuntime.js +13 -8
- package/src/browser/browserRuntime.ts +16 -8
- package/src/browser/causyneBrowser.js +37 -9
- package/src/browser/causyneBrowser.ts +37 -9
- package/src/browser/searchProviders.js +18 -7
- package/src/browser/searchProviders.ts +17 -5
- package/src/browser/snapshotWindow.js +1 -1
- package/src/browser/snapshotWindow.ts +1 -1
- package/src/browser/urlPolicy.js +21 -10
- package/src/browser/urlPolicy.ts +19 -10
- package/src/browser/workspacePreview.js +13 -1
- package/src/browser/workspacePreview.ts +11 -1
- package/src/cliMode.js +5 -1
- package/src/computerUse/visionGrounding.js +31 -27
- package/src/computerUse/visionGrounding.ts +27 -27
- package/src/continuum/ui/continuumPicker.js +14 -6
- package/src/continuum/ui/continuumPicker.ts +13 -6
- package/src/continuum/ui/continuumPickerView.js +24 -15
- package/src/continuum/ui/continuumPickerView.ts +24 -16
- package/src/memory/scopedFacts.js +171 -0
- package/src/memory/scopedFacts.ts +214 -0
- package/src/memory.d.ts +13 -1
- package/src/memory.js +9 -12
- package/src/observer/advisory.js +32 -22
- package/src/observer/advisory.ts +30 -18
- package/src/observer/coldObserver.js +21 -33
- package/src/observer/coldObserver.ts +20 -33
- package/src/observer/evidence.js +20 -13
- package/src/observer/evidence.ts +21 -13
- package/src/observer.js +47 -12
- package/src/observer.ts +50 -18
- package/src/perception.js +124 -3
- package/src/perception.ts +128 -4
- package/src/planCache.js +17 -3
- package/src/planCache.ts +17 -3
- package/src/pluginsFactory/discovery.js +28 -16
- package/src/pluginsFactory/discovery.ts +29 -16
- package/src/pluginsFactory/pluginsFactory.js +213 -38
- package/src/pluginsFactory/pluginsFactory.ts +218 -39
- package/src/pluginsFactory/strategy.js +26 -16
- package/src/pluginsFactory/strategy.ts +34 -19
- package/src/pluginsFactory/templates.js +183 -62
- package/src/pluginsFactory/templates.ts +174 -54
- package/src/smartToolsUse.js +4 -5
- package/src/smartToolsUse.ts +4 -6
- package/src/taskShape.js +49 -7
- package/src/taskShape.ts +55 -7
- package/src/timeMachine.js +43 -22
- package/src/timeMachine.ts +44 -22
- package/src/tool-scripts/desktop_act.applescript +1 -0
- package/src/toolPacks.js +27 -5
- package/src/toolPacks.ts +32 -5
- package/src/tools/computerUse.js +23 -10
- package/src/tools/computerUse.ts +19 -8
- package/src/tools/desktopAct.js +12 -1
- package/src/tools/memoryWrite.js +8 -10
- package/src/tools/memoryWrite.ts +13 -11
- package/src/tools/pluginsFactory.js +108 -5
- package/src/tools/pluginsFactory.ts +115 -5
- package/src/tui/CausyneRotor.js +24 -10
- package/src/tui/CausyneRotor.ts +25 -10
- package/src/tui/activityLayout.js +9 -5
- package/src/tui/activityLayout.ts +9 -5
- package/src/tui/ask.js +34 -14
- package/src/tui/banner.js +55 -18
- package/src/tui/banner.ts +52 -17
- package/src/tui/block.js +47 -20
- package/src/tui/block.ts +54 -27
- package/src/tui/chatRenderer.js +139 -84
- package/src/tui/chatboxClipboard.js +12 -5
- package/src/tui/chatboxClipboard.ts +10 -4
- package/src/tui/clipboardImage.js +52 -42
- package/src/tui/clipboardImage.ts +50 -39
- package/src/tui/clipboardSync.js +12 -1
- package/src/tui/clipboardSync.ts +9 -1
- package/src/tui/codeProgress.js +60 -28
- package/src/tui/codeProgress.ts +60 -27
- package/src/tui/codeStreamRenderer.js +94 -23
- package/src/tui/codeStreamRenderer.ts +92 -23
- package/src/tui/commandPresentation.js +9 -2
- package/src/tui/commandPresentation.ts +9 -2
- package/src/tui/completion.js +45 -23
- package/src/tui/composerControls.js +21 -10
- package/src/tui/composerControls.ts +18 -10
- package/src/tui/composerGeometry.js +6 -4
- package/src/tui/composerGeometry.ts +6 -4
- package/src/tui/consoleGuard.js +29 -7
- package/src/tui/consoleGuard.ts +28 -7
- package/src/tui/dialogs.js +134 -71
- package/src/tui/diff.js +8 -4
- package/src/tui/history.js +6 -5
- package/src/tui/home.js +25 -13
- package/src/tui/homeView.js +37 -18
- package/src/tui/homeView.ts +38 -18
- package/src/tui/inlineSlash.js +6 -5
- package/src/tui/inlineSlash.ts +6 -5
- package/src/tui/keys.js +36 -18
- package/src/tui/layout.js +27 -9
- package/src/tui/layout.ts +26 -9
- package/src/tui/lineEditor.js +49 -23
- package/src/tui/markdownMath.js +64 -14
- package/src/tui/markdownMath.ts +69 -13
- package/src/tui/messageActionPlacement.js +28 -13
- package/src/tui/messageActionPlacement.ts +28 -13
- package/src/tui/messageInteraction.js +111 -46
- package/src/tui/messageInteraction.ts +115 -47
- package/src/tui/modelPicker.js +44 -15
- package/src/tui/modelPicker.ts +48 -15
- package/src/tui/observerPicker.js +56 -13
- package/src/tui/observerPicker.ts +73 -30
- package/src/tui/overlay.js +79 -35
- package/src/tui/overlay.ts +81 -34
- package/src/tui/prompt.js +186 -94
- package/src/tui/runningLight.js +1 -1
- package/src/tui/runningLight.ts +1 -1
- package/src/tui/scrollInteraction.js +64 -36
- package/src/tui/scrollInteraction.ts +70 -37
- package/src/tui/selectList.js +60 -32
- package/src/tui/sessionLayout.js +11 -3
- package/src/tui/sessionLayout.ts +10 -3
- package/src/tui/sessionPicker.js +74 -46
- package/src/tui/sessionPicker.ts +73 -48
- package/src/tui/sessionPickerView.js +32 -19
- package/src/tui/sessionPickerView.ts +31 -18
- package/src/tui/sessionSidebar.js +87 -57
- package/src/tui/sessionSidebar.ts +90 -54
- package/src/tui/setup.js +28 -3
- package/src/tui/setup.ts +27 -3
- package/src/tui/skillAuthoring.js +11 -5
- package/src/tui/skillAuthoring.ts +11 -5
- package/src/tui/smartLinkClick.js +75 -23
- package/src/tui/smartLinkClick.ts +86 -26
- package/src/tui/stage.js +47 -16
- package/src/tui/stage.ts +53 -18
- package/src/tui/stageSurface.js +232 -51
- package/src/tui/statusLine.js +85 -53
- package/src/tui/statusLine.ts +82 -46
- package/src/tui/terminalInputFramer.js +5 -2
- package/src/tui/text.js +117 -46
- package/src/tui/text.ts +113 -43
- package/src/tui/textLayout.js +6 -4
- package/src/tui/textLayout.ts +11 -5
- package/src/tui/theme.js +17 -8
- package/src/tui/thinkingBox.js +95 -95
- package/src/tui/thinkingBox.ts +105 -80
- package/src/tui/toolActivityPolicy.js +8 -1
- package/src/tui/toolActivityPolicy.ts +7 -1
- package/src/tui/toolDisplay.js +15 -6
- package/src/tui/toolDisplay.ts +16 -6
- package/src/tui/toolOutputNormalizer.js +16 -3
- package/src/tui/toolOutputNormalizer.ts +13 -3
- package/src/tui/transcript.js +15 -9
- package/src/tui/turnRail.js +176 -80
- package/src/tui/turnRail.ts +173 -71
- package/src/tui/usageCard.js +136 -80
- package/src/tui/usageCard.ts +145 -103
- package/src/tui/viewport.js +48 -23
- package/src/tui/viewport.ts +48 -27
- package/src/tui/viewportAnchor.js +2 -2
- package/src/tui/viewportAnchor.ts +2 -2
- package/src/tui/workspaceFileIndex.js +8 -6
- package/src/tui/workspaceFileIndex.ts +8 -6
- package/src/tui/workspaceSwitch.js +13 -10
- package/src/tui/workspaceSwitch.ts +11 -7
- package/src/types/contracts.ts +3 -0
package/src/tui/prompt.js
CHANGED
|
@@ -42,6 +42,7 @@ import { sidebarVisible, sessionMainWidth } from './sessionSidebar.js';
|
|
|
42
42
|
import { isStartupDialog, startupDialogView } from './homeView.js';
|
|
43
43
|
import { handleMessageMouse, handleMessageActionMenuMouse, isMouseMotion } from './messageInteraction.js';
|
|
44
44
|
import { handleTurnRailMouse } from './turnRail.js';
|
|
45
|
+
import { runWithStageWrite } from './consoleGuard.js';
|
|
45
46
|
import {
|
|
46
47
|
resetTurnInterruptState,
|
|
47
48
|
shouldAcceptStatusUpdate,
|
|
@@ -190,6 +191,13 @@ export class ChatPrompt {
|
|
|
190
191
|
// Lifecycle
|
|
191
192
|
// -------------------------------------------------------------------------
|
|
192
193
|
|
|
194
|
+
writeControl(sequence) {
|
|
195
|
+
if (!sequence) return;
|
|
196
|
+
runWithStageWrite(() => {
|
|
197
|
+
this.out.write(sequence);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
193
201
|
start() {
|
|
194
202
|
if (this.active) return;
|
|
195
203
|
this.active = true;
|
|
@@ -197,11 +205,11 @@ export class ChatPrompt {
|
|
|
197
205
|
this.input.setRawMode(true);
|
|
198
206
|
this.input.resume();
|
|
199
207
|
this.input.on('data', this.handleData);
|
|
200
|
-
this.
|
|
208
|
+
this.writeControl(bracketedPaste(true));
|
|
201
209
|
// Node's normal exit does not guarantee ChatPrompt.stop() is called.
|
|
202
210
|
// Always restore bracketed paste and raw stdin when the process exits.
|
|
203
211
|
this.exitHook = () => {
|
|
204
|
-
try { this.
|
|
212
|
+
try { this.writeControl(bracketedPaste(false)); } catch { /* terminal already closed */ }
|
|
205
213
|
try { this.input.setRawMode(false); } catch { /* stdin already closed */ }
|
|
206
214
|
};
|
|
207
215
|
process.once('exit', this.exitHook);
|
|
@@ -214,6 +222,11 @@ export class ChatPrompt {
|
|
|
214
222
|
stop() {
|
|
215
223
|
if (!this.active) return;
|
|
216
224
|
this.active = false;
|
|
225
|
+
if (this.layer) {
|
|
226
|
+
const layer = this.layer;
|
|
227
|
+
this.layer = null;
|
|
228
|
+
if (typeof layer.answer === 'function') layer.answer(false);
|
|
229
|
+
}
|
|
217
230
|
this.stopTick();
|
|
218
231
|
if (this.inputFrameTimer) { clearTimeout(this.inputFrameTimer); this.inputFrameTimer = null; }
|
|
219
232
|
if (this.decoderRecoveryTimer) { clearTimeout(this.decoderRecoveryTimer); this.decoderRecoveryTimer = null; }
|
|
@@ -225,7 +238,7 @@ export class ChatPrompt {
|
|
|
225
238
|
// session is flushed into real terminal scrollback, so leaving Causyne leaves
|
|
226
239
|
// a transcript behind exactly as it always has.
|
|
227
240
|
if (this.surface) this.surface.close();
|
|
228
|
-
this.
|
|
241
|
+
this.writeControl(bracketedPaste(false));
|
|
229
242
|
if (typeof this.out.removeListener === 'function') this.out.removeListener('resize', this.handleResize);
|
|
230
243
|
this.input.off('data', this.handleData);
|
|
231
244
|
try { this.input.setRawMode(false); } catch (e) { /* already closed */ }
|
|
@@ -297,6 +310,35 @@ export class ChatPrompt {
|
|
|
297
310
|
}
|
|
298
311
|
};
|
|
299
312
|
|
|
313
|
+
flushCharBatch(charBatch) {
|
|
314
|
+
if (!charBatch) return '';
|
|
315
|
+
this.prepareKeyboardState(true);
|
|
316
|
+
this.editor.insert(charBatch);
|
|
317
|
+
if (charBatch.length < 60 && !charBatch.includes('\n')) {
|
|
318
|
+
this.refreshCompletion();
|
|
319
|
+
} else {
|
|
320
|
+
this.completion = null;
|
|
321
|
+
}
|
|
322
|
+
return '';
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
prepareKeyboardState(clearNotice) {
|
|
326
|
+
if (clearNotice && this.notice && !this.layer) this.notice = '';
|
|
327
|
+
if (this.surface && typeof this.surface.captureMouse === 'function') {
|
|
328
|
+
if (this.surface.captureMouse() && typeof this.notice === 'string' && this.notice.startsWith('top of this view')) {
|
|
329
|
+
this.notice = '';
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
if (this.surface) {
|
|
333
|
+
this.surface.turnRailHoverSuppressed = false;
|
|
334
|
+
if (this.surface.hoveredTurnIndex !== null && this.surface.hoveredTurnIndex !== undefined) {
|
|
335
|
+
this.surface.hoveredTurnIndex = null;
|
|
336
|
+
this.surface.hoveredTurnAnchorY = null;
|
|
337
|
+
this.scheduleDraw();
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
300
342
|
handleFramedData = (chunk) => {
|
|
301
343
|
let motionOnly = true;
|
|
302
344
|
const str = typeof chunk === 'string' ? chunk : Buffer.isBuffer(chunk) ? chunk.toString('utf8') : '';
|
|
@@ -338,13 +380,7 @@ export class ChatPrompt {
|
|
|
338
380
|
continue;
|
|
339
381
|
}
|
|
340
382
|
if (charBatch.length > 0) {
|
|
341
|
-
this.
|
|
342
|
-
if (charBatch.length < 60 && !charBatch.includes('\n')) {
|
|
343
|
-
this.refreshCompletion();
|
|
344
|
-
} else {
|
|
345
|
-
this.completion = null;
|
|
346
|
-
}
|
|
347
|
-
charBatch = '';
|
|
383
|
+
charBatch = this.flushCharBatch(charBatch);
|
|
348
384
|
}
|
|
349
385
|
if (key.name !== 'mouse' || !isMouseMotion(key.sequence)) motionOnly = false;
|
|
350
386
|
try {
|
|
@@ -358,13 +394,7 @@ export class ChatPrompt {
|
|
|
358
394
|
}
|
|
359
395
|
|
|
360
396
|
if (charBatch.length > 0) {
|
|
361
|
-
this.
|
|
362
|
-
if (charBatch.length < 60 && !charBatch.includes('\n')) {
|
|
363
|
-
this.refreshCompletion();
|
|
364
|
-
} else {
|
|
365
|
-
this.completion = null;
|
|
366
|
-
}
|
|
367
|
-
charBatch = '';
|
|
397
|
+
charBatch = this.flushCharBatch(charBatch);
|
|
368
398
|
}
|
|
369
399
|
|
|
370
400
|
// All-motion chunks repaint only when the hovered message actually changes.
|
|
@@ -962,28 +992,15 @@ export class ChatPrompt {
|
|
|
962
992
|
// -------------------------------------------------------------------------
|
|
963
993
|
|
|
964
994
|
handleKey(key) {
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
// later keystroke for the rest of the session.
|
|
968
|
-
if (this.notice && !this.layer
|
|
969
|
-
&& (key.name === 'char' || key.name === 'paste' || key.name === 'backspace' || key.name === 'delete')) {
|
|
995
|
+
const clearNotice = key.name === 'char' || key.name === 'paste' || key.name === 'backspace' || key.name === 'delete';
|
|
996
|
+
if (clearNotice && this.notice && !this.layer) {
|
|
970
997
|
this.notice = '';
|
|
971
998
|
}
|
|
972
999
|
|
|
973
1000
|
// The wheel was handed to the terminal at the top of the band; the moment
|
|
974
1001
|
// the user types again they are driving this prompt, so take it back.
|
|
975
1002
|
if (key.name !== 'wheel' && key.name !== 'mouse') {
|
|
976
|
-
|
|
977
|
-
if (this.surface.captureMouse() && this.notice.startsWith('top of this view')) this.notice = '';
|
|
978
|
-
}
|
|
979
|
-
if (this.surface) {
|
|
980
|
-
this.surface.turnRailHoverSuppressed = false;
|
|
981
|
-
if (this.surface.hoveredTurnIndex !== null && this.surface.hoveredTurnIndex !== undefined) {
|
|
982
|
-
this.surface.hoveredTurnIndex = null;
|
|
983
|
-
this.surface.hoveredTurnAnchorY = null;
|
|
984
|
-
this.scheduleDraw();
|
|
985
|
-
}
|
|
986
|
-
}
|
|
1003
|
+
this.prepareKeyboardState(false);
|
|
987
1004
|
}
|
|
988
1005
|
|
|
989
1006
|
if (key.ctrl && key.name === 'c') {
|
|
@@ -1050,7 +1067,7 @@ export class ChatPrompt {
|
|
|
1050
1067
|
this.scheduleDraw();
|
|
1051
1068
|
} else {
|
|
1052
1069
|
Promise.resolve(control()).catch(error => {
|
|
1053
|
-
this.notice = error instanceof Error ? error.message : String(error);
|
|
1070
|
+
this.notice = this.sanitizeSingleLine(error instanceof Error ? error.message : String(error));
|
|
1054
1071
|
this.scheduleDraw();
|
|
1055
1072
|
});
|
|
1056
1073
|
}
|
|
@@ -1060,7 +1077,7 @@ export class ChatPrompt {
|
|
|
1060
1077
|
switch (key.name) {
|
|
1061
1078
|
case 'escape': return this.handleEscape();
|
|
1062
1079
|
case 'enter':
|
|
1063
|
-
if (key.alt || key.shift) { this.editor.newline(); return; }
|
|
1080
|
+
if (key.alt || key.shift) { this.editor.newline(); return this.refreshCompletion(); }
|
|
1064
1081
|
return this.submit();
|
|
1065
1082
|
case 'tab':
|
|
1066
1083
|
if (key.shift) return;
|
|
@@ -1093,20 +1110,12 @@ export class ChatPrompt {
|
|
|
1093
1110
|
switch (key.name) {
|
|
1094
1111
|
case 'a': return this.editor.moveHome();
|
|
1095
1112
|
case 'e': return this.editor.moveEnd();
|
|
1096
|
-
case 'k':
|
|
1097
|
-
case 'u':
|
|
1113
|
+
case 'k': this.editor.killToEnd(); return this.refreshCompletion();
|
|
1114
|
+
case 'u': this.editor.killToStart(); return this.refreshCompletion();
|
|
1098
1115
|
case 'w': this.editor.killWordLeft(); return this.refreshCompletion();
|
|
1099
1116
|
case 'y': this.editor.yank(); return this.refreshCompletion();
|
|
1100
1117
|
case 'x': {
|
|
1101
|
-
if (this.
|
|
1102
|
-
const text = this.editor.getSelectedText();
|
|
1103
|
-
writeClipboardSync(text);
|
|
1104
|
-
this.editor.killRing = text;
|
|
1105
|
-
this.editor.deleteSelection();
|
|
1106
|
-
this.notice = `cut selection (${text.length} chars) to clipboard`;
|
|
1107
|
-
this.scheduleDraw();
|
|
1108
|
-
return;
|
|
1109
|
-
}
|
|
1118
|
+
if (this.cutSelection()) return;
|
|
1110
1119
|
break;
|
|
1111
1120
|
}
|
|
1112
1121
|
case 'p': return this.openPalette();
|
|
@@ -1123,15 +1132,7 @@ export class ChatPrompt {
|
|
|
1123
1132
|
return;
|
|
1124
1133
|
}
|
|
1125
1134
|
if (key.alt && key.name === 'x') {
|
|
1126
|
-
if (this.
|
|
1127
|
-
const text = this.editor.getSelectedText();
|
|
1128
|
-
writeClipboardSync(text);
|
|
1129
|
-
this.editor.killRing = text;
|
|
1130
|
-
this.editor.deleteSelection();
|
|
1131
|
-
this.notice = `cut selection (${text.length} chars) to clipboard`;
|
|
1132
|
-
this.scheduleDraw();
|
|
1133
|
-
return;
|
|
1134
|
-
}
|
|
1135
|
+
if (this.cutSelection()) return;
|
|
1135
1136
|
}
|
|
1136
1137
|
if (key.alt && (key.name === 'c' || key.name === 'w')) {
|
|
1137
1138
|
const text = this.editor.hasSelection
|
|
@@ -1193,6 +1194,30 @@ export class ChatPrompt {
|
|
|
1193
1194
|
}
|
|
1194
1195
|
if (key.name === 'wheel') {
|
|
1195
1196
|
if (!viewport || !key.wheel) return true;
|
|
1197
|
+
// The reference timeline popover is itself scrollable when a dot
|
|
1198
|
+
// represents more turns than can fit. Wheel input over the card must
|
|
1199
|
+
// not move the chat viewport behind it.
|
|
1200
|
+
const layout = this.surface?.turnRailLayout;
|
|
1201
|
+
const card = layout?.cardRect;
|
|
1202
|
+
const pointerX = key.wheel.x;
|
|
1203
|
+
const pointerY = key.wheel.y;
|
|
1204
|
+
const relativeY = pointerY - (Number.isFinite(layout?.stageTop) ? layout.stageTop : 0);
|
|
1205
|
+
if (card && Array.isArray(card.groupTurns) &&
|
|
1206
|
+
Number.isFinite(pointerX) && Number.isFinite(pointerY) &&
|
|
1207
|
+
pointerX >= card.x && pointerX < card.x + card.width &&
|
|
1208
|
+
relativeY >= card.y && relativeY < card.y + card.height &&
|
|
1209
|
+
(key.wheel.direction === 'up' || key.wheel.direction === 'down')) {
|
|
1210
|
+
const previous = Number.isFinite(this.surface.turnRailCardOffset)
|
|
1211
|
+
? this.surface.turnRailCardOffset : 0;
|
|
1212
|
+
const maximum = Number.isFinite(card.maxOffset) ? Math.max(0, card.maxOffset) : 0;
|
|
1213
|
+
const change = key.wheel.direction === 'up' ? -1 : 1;
|
|
1214
|
+
const current = Math.max(0, Math.min(maximum, previous + change));
|
|
1215
|
+
if (current !== previous) {
|
|
1216
|
+
this.surface.turnRailCardOffset = current;
|
|
1217
|
+
this.scheduleDraw();
|
|
1218
|
+
}
|
|
1219
|
+
return true;
|
|
1220
|
+
}
|
|
1196
1221
|
if (this.renderer?.scrollCodePanel?.(key, this.surface)) {
|
|
1197
1222
|
if (typeof this.scheduleDraw === 'function') this.scheduleDraw(); else this.draw();
|
|
1198
1223
|
return true;
|
|
@@ -1207,13 +1232,20 @@ export class ChatPrompt {
|
|
|
1207
1232
|
|
|
1208
1233
|
if (!viewport) return false;
|
|
1209
1234
|
|
|
1235
|
+
const clearTurnRailFocus = () => {
|
|
1236
|
+
if (!this.surface) return;
|
|
1237
|
+
this.surface.activeTurnIndex = null;
|
|
1238
|
+
this.surface.hoveredTurnIndex = null;
|
|
1239
|
+
this.surface.hoveredTurnAnchorY = null;
|
|
1240
|
+
};
|
|
1241
|
+
|
|
1210
1242
|
if (key.name === 'pageup') {
|
|
1211
|
-
|
|
1243
|
+
clearTurnRailFocus();
|
|
1212
1244
|
if (key.shift) viewport.toTop(); else viewport.pageUp();
|
|
1213
1245
|
return true;
|
|
1214
1246
|
}
|
|
1215
1247
|
if (key.name === 'pagedown') {
|
|
1216
|
-
|
|
1248
|
+
clearTurnRailFocus();
|
|
1217
1249
|
// Shift+PgDn is the way back to following, and it is spelled out in the
|
|
1218
1250
|
// affordance the surface draws while the view is held away.
|
|
1219
1251
|
if (key.shift) viewport.toBottom(); else viewport.pageDown();
|
|
@@ -1221,23 +1253,23 @@ export class ChatPrompt {
|
|
|
1221
1253
|
}
|
|
1222
1254
|
if (key.shift && key.name === 'up') {
|
|
1223
1255
|
if (!this.editor.isEmpty) return false;
|
|
1224
|
-
|
|
1256
|
+
clearTurnRailFocus();
|
|
1225
1257
|
viewport.lineUp();
|
|
1226
1258
|
return true;
|
|
1227
1259
|
}
|
|
1228
1260
|
if (key.shift && key.name === 'down') {
|
|
1229
1261
|
if (!this.editor.isEmpty) return false;
|
|
1230
|
-
|
|
1262
|
+
clearTurnRailFocus();
|
|
1231
1263
|
viewport.lineDown();
|
|
1232
1264
|
return true;
|
|
1233
1265
|
}
|
|
1234
1266
|
if (key.alt && key.ctrl && key.name === 'u') {
|
|
1235
|
-
|
|
1267
|
+
clearTurnRailFocus();
|
|
1236
1268
|
viewport.halfPageUp();
|
|
1237
1269
|
return true;
|
|
1238
1270
|
}
|
|
1239
1271
|
if (key.alt && key.ctrl && key.name === 'd') {
|
|
1240
|
-
|
|
1272
|
+
clearTurnRailFocus();
|
|
1241
1273
|
viewport.halfPageDown();
|
|
1242
1274
|
return true;
|
|
1243
1275
|
}
|
|
@@ -1251,14 +1283,19 @@ export class ChatPrompt {
|
|
|
1251
1283
|
// entitled to type; the plan's `[`/`]` could not be bound at all, and
|
|
1252
1284
|
// alt+[ is worse than unbound — ESC [ IS the CSI introducer, so it is
|
|
1253
1285
|
// indistinguishable from the start of an escape sequence.
|
|
1254
|
-
|
|
1255
|
-
|
|
1286
|
+
const jumpViewport = (direction, kinds) => {
|
|
1287
|
+
clearTurnRailFocus();
|
|
1288
|
+
viewport.jump(direction, kinds);
|
|
1289
|
+
return true;
|
|
1290
|
+
};
|
|
1291
|
+
if (key.alt && key.name === ',') return jumpViewport(-1, ['step']);
|
|
1292
|
+
if (key.alt && key.name === '.') return jumpViewport(1, ['step']);
|
|
1256
1293
|
// Exchanges are marked by the USER's message, not by the turn footer. Both
|
|
1257
1294
|
// sit at almost the same seam — a footer is immediately followed by the next
|
|
1258
1295
|
// question — so accepting either made the jump land twice two rows apart
|
|
1259
1296
|
// instead of once per exchange.
|
|
1260
|
-
if ((key.alt && key.name === '[') || (key.alt && key.name === '<'))
|
|
1261
|
-
if ((key.alt && key.name === ']') || (key.alt && key.name === '>'))
|
|
1297
|
+
if ((key.alt && key.name === '[') || (key.alt && key.name === '<')) return jumpViewport(-1, ['user']);
|
|
1298
|
+
if ((key.alt && key.name === ']') || (key.alt && key.name === '>')) return jumpViewport(1, ['user']);
|
|
1262
1299
|
|
|
1263
1300
|
if (key.alt && key.name === 'u') { this.offerUndo(); return true; }
|
|
1264
1301
|
|
|
@@ -1301,8 +1338,9 @@ export class ChatPrompt {
|
|
|
1301
1338
|
const mark = onScreen.length ? onScreen[onScreen.length - 1] : (above.pop() || marks[0]);
|
|
1302
1339
|
const meta = mark.meta || {};
|
|
1303
1340
|
|
|
1304
|
-
const where = meta.path ? shortenHome(meta.path) : 'files changed this task';
|
|
1305
|
-
const
|
|
1341
|
+
const where = meta.path ? this.sanitizeSingleLine(shortenHome(meta.path)) : 'files changed this task';
|
|
1342
|
+
const rawStep = meta.step == null ? '' : this.sanitizeSingleLine(meta.step);
|
|
1343
|
+
const step = rawStep ? ` at step ${rawStep}` : '';
|
|
1306
1344
|
|
|
1307
1345
|
if (this.editor.isEmpty) {
|
|
1308
1346
|
this.editor.setText('/undo');
|
|
@@ -1313,6 +1351,21 @@ export class ChatPrompt {
|
|
|
1313
1351
|
}
|
|
1314
1352
|
}
|
|
1315
1353
|
|
|
1354
|
+
sanitizeSingleLine(value) {
|
|
1355
|
+
return value == null ? '' : safeDisplay(String(value)).replace(/\s+/g, ' ').trim();
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
cutSelection() {
|
|
1359
|
+
if (!this.editor.hasSelection) return false;
|
|
1360
|
+
const text = this.editor.getSelectedText();
|
|
1361
|
+
writeClipboardSync(text);
|
|
1362
|
+
this.editor.killRing = text;
|
|
1363
|
+
this.editor.deleteSelection();
|
|
1364
|
+
this.notice = `cut selection (${text.length} chars) to clipboard`;
|
|
1365
|
+
this.refreshCompletion();
|
|
1366
|
+
return true;
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1316
1369
|
handleCtrlC() {
|
|
1317
1370
|
handlePromptCtrlC(
|
|
1318
1371
|
this,
|
|
@@ -1353,7 +1406,7 @@ export class ChatPrompt {
|
|
|
1353
1406
|
this.erase();
|
|
1354
1407
|
// The one clear Causyne may perform: the user pressed ctrl+L and asked for it.
|
|
1355
1408
|
// UX-01 forbids clearing the terminal on the app's own initiative.
|
|
1356
|
-
this.
|
|
1409
|
+
this.writeControl('\x1b[2J\x1b[H');
|
|
1357
1410
|
this.drawnRows = 0;
|
|
1358
1411
|
this.cursorRow = 0;
|
|
1359
1412
|
}
|
|
@@ -1385,7 +1438,7 @@ export class ChatPrompt {
|
|
|
1385
1438
|
if (!trigger || trigger.kind !== 'file') return;
|
|
1386
1439
|
this.openCompletion(false);
|
|
1387
1440
|
if (index.truncated) this.notice = 'Workspace file index reached its safety limit; narrow the project root.';
|
|
1388
|
-
else if (this.notice === 'Indexing workspace files…') this.notice =
|
|
1441
|
+
else if (this.notice === 'Indexing workspace files…') this.notice = '';
|
|
1389
1442
|
this.scheduleDraw();
|
|
1390
1443
|
});
|
|
1391
1444
|
void index.ensure();
|
|
@@ -1489,21 +1542,40 @@ export class ChatPrompt {
|
|
|
1489
1542
|
return true;
|
|
1490
1543
|
}
|
|
1491
1544
|
if (key.name === 'mouse') {
|
|
1492
|
-
if (key.mouse && key.mouse.pressed && key.mouse.button === 0) {
|
|
1545
|
+
if (key.mouse && key.mouse.pressed && key.mouse.button === 0 && !isMouseMotion(key.sequence)) {
|
|
1493
1546
|
let item = null;
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1547
|
+
const hasZeroY = Number.isFinite(key.mouse.y);
|
|
1548
|
+
const rawMouseRow = hasZeroY
|
|
1549
|
+
? Math.floor(key.mouse.y)
|
|
1550
|
+
: (Number.isFinite(key.mouse.row) ? Math.floor(key.mouse.row) : NaN);
|
|
1551
|
+
if (this.pickerLayout && Number.isFinite(rawMouseRow)) {
|
|
1552
|
+
const stageHeight = this.surface?.stage?.height || this.out?.rows || process.stdout.rows || 24;
|
|
1553
|
+
const termRows = Number.isFinite(this.out?.rows) && this.out.rows > 0
|
|
1554
|
+
? Math.floor(this.out.rows)
|
|
1555
|
+
: stageHeight;
|
|
1556
|
+
// KeyDecoder emits 0-based x/y screen coordinates; legacy unit tests pass 1-based row/col.
|
|
1557
|
+
const promptTop = hasZeroY
|
|
1558
|
+
? Math.max(0, termRows - this.pickerLayout.totalPromptRows)
|
|
1559
|
+
: Math.max(1, stageHeight - this.pickerLayout.totalPromptRows + 1);
|
|
1497
1560
|
const pickerTop = promptTop + this.pickerLayout.pickerStart;
|
|
1498
1561
|
const pickerBottom = pickerTop + this.pickerLayout.pickerCount - 1;
|
|
1562
|
+
const mouseX = Number.isFinite(key.mouse.x) ? Math.floor(key.mouse.x) : NaN;
|
|
1563
|
+
const mainW = this.surface
|
|
1564
|
+
? sessionMainWidth(this.surface.width, Boolean(this.surface.homeInfo), this.surface.env)
|
|
1565
|
+
: Infinity;
|
|
1566
|
+
const inMainColumn = !Number.isFinite(mouseX) || (mouseX >= 0 && mouseX < mainW);
|
|
1499
1567
|
|
|
1500
|
-
if (
|
|
1568
|
+
if (inMainColumn && rawMouseRow >= pickerTop && rawMouseRow <= pickerBottom) {
|
|
1501
1569
|
// The picker renders a scrolled window (renderPicker); a click maps
|
|
1502
1570
|
// to the item under the cursor, not to the first page of items.
|
|
1503
|
-
const
|
|
1571
|
+
const items = Array.isArray(this.completion.items) ? this.completion.items : [];
|
|
1572
|
+
const total = items.length;
|
|
1504
1573
|
const windowStart = Math.max(0, Math.min(this.selected - MAX_VISIBLE + 1, total - MAX_VISIBLE));
|
|
1505
|
-
const index = windowStart + (
|
|
1506
|
-
|
|
1574
|
+
const index = windowStart + (rawMouseRow - pickerTop);
|
|
1575
|
+
if (index >= 0 && index < total) {
|
|
1576
|
+
this.selected = index;
|
|
1577
|
+
item = items[index];
|
|
1578
|
+
}
|
|
1507
1579
|
} else {
|
|
1508
1580
|
// Click outside picker closes it
|
|
1509
1581
|
this.completion = null;
|
|
@@ -1511,7 +1583,8 @@ export class ChatPrompt {
|
|
|
1511
1583
|
return true;
|
|
1512
1584
|
}
|
|
1513
1585
|
} else {
|
|
1514
|
-
|
|
1586
|
+
const items = Array.isArray(this.completion.items) ? this.completion.items : [];
|
|
1587
|
+
item = items[this.selected];
|
|
1515
1588
|
}
|
|
1516
1589
|
|
|
1517
1590
|
if (item) {
|
|
@@ -1592,13 +1665,14 @@ export class ChatPrompt {
|
|
|
1592
1665
|
}
|
|
1593
1666
|
|
|
1594
1667
|
moveSelection(direction) {
|
|
1595
|
-
const count = this.completion.items.length;
|
|
1596
|
-
|
|
1668
|
+
const count = Array.isArray(this.completion?.items) ? this.completion.items.length : 0;
|
|
1669
|
+
if (count === 0) return;
|
|
1670
|
+
this.selected = (((this.selected + direction) % count) + count) % count;
|
|
1597
1671
|
}
|
|
1598
1672
|
|
|
1599
1673
|
/** Move without wrapping: a wheel or page key stops at either end. */
|
|
1600
1674
|
moveSelectionClamped(delta) {
|
|
1601
|
-
const count = this.completion.items.length;
|
|
1675
|
+
const count = Array.isArray(this.completion?.items) ? this.completion.items.length : 0;
|
|
1602
1676
|
if (count === 0) return;
|
|
1603
1677
|
this.selected = Math.max(0, Math.min(count - 1, this.selected + delta));
|
|
1604
1678
|
}
|
|
@@ -1853,7 +1927,8 @@ export class ChatPrompt {
|
|
|
1853
1927
|
totalPromptRows: 0
|
|
1854
1928
|
} : null;
|
|
1855
1929
|
const queuedRows = this.queuedPreviewRows(width);
|
|
1856
|
-
const
|
|
1930
|
+
const cleanNotice = this.notice ? this.sanitizeSingleLine(this.notice) : '';
|
|
1931
|
+
const noticeRows = cleanNotice ? [dim(` ${cleanNotice}`)] : [];
|
|
1857
1932
|
|
|
1858
1933
|
// And a row of air between the box and the footer. The picker and a notice
|
|
1859
1934
|
// belong to the input and stay welded to it — opencode floats its
|
|
@@ -1870,7 +1945,7 @@ export class ChatPrompt {
|
|
|
1870
1945
|
// Park the cursor where the user is typing, not at the end of the picker.
|
|
1871
1946
|
const availableWidth = this.surface?.composeAvailableWidth
|
|
1872
1947
|
? this.surface.composeAvailableWidth()
|
|
1873
|
-
: sessionMainWidth(this.surface?.width || terminalWidth());
|
|
1948
|
+
: sessionMainWidth(this.surface?.width || terminalWidth(), false, this.surface?.env);
|
|
1874
1949
|
const positioned = this.surface
|
|
1875
1950
|
? (this.surface.homeInfo ? centerRows(all, this.surface.width) : sessionRows(all, availableWidth))
|
|
1876
1951
|
: { rows: all, inset: 0 };
|
|
@@ -1888,23 +1963,27 @@ export class ChatPrompt {
|
|
|
1888
1963
|
* nothing of ours is on the terminal for erase() to walk back over.
|
|
1889
1964
|
*/
|
|
1890
1965
|
present(all, caretRow, caretCol) {
|
|
1966
|
+
const rows = Array.isArray(all) ? all : [];
|
|
1967
|
+
const maxRow = Math.max(0, rows.length - 1);
|
|
1968
|
+
const safeRow = Number.isFinite(caretRow) ? Math.max(0, Math.min(maxRow, Math.floor(caretRow))) : 0;
|
|
1969
|
+
const safeCol = Number.isFinite(caretCol) ? Math.max(0, Math.floor(caretCol)) : 0;
|
|
1891
1970
|
const hideCursor = Boolean(this.busy && this.editor.isEmpty);
|
|
1892
1971
|
if (this.surface) {
|
|
1893
1972
|
this.drawnRows = 0;
|
|
1894
1973
|
this.cursorRow = 0;
|
|
1895
|
-
this.surface.present(
|
|
1974
|
+
this.surface.present(rows, { row: safeRow, col: safeCol, hideCursor,
|
|
1896
1975
|
modal: Boolean(this.layer), inline: Boolean(this.layer && !isStartupDialog(this.surface)) });
|
|
1897
1976
|
return;
|
|
1898
1977
|
}
|
|
1899
1978
|
|
|
1900
|
-
this.out.write(
|
|
1901
|
-
this.drawnRows =
|
|
1979
|
+
this.out.write(rows.join('\n'));
|
|
1980
|
+
this.drawnRows = rows.length;
|
|
1902
1981
|
|
|
1903
|
-
const below =
|
|
1982
|
+
const below = rows.length - 1 - safeRow;
|
|
1904
1983
|
if (below > 0) this.out.write(`\x1b[${below}A`);
|
|
1905
|
-
this.cursorRow =
|
|
1984
|
+
this.cursorRow = safeRow;
|
|
1906
1985
|
this.out.write('\r');
|
|
1907
|
-
if (
|
|
1986
|
+
if (safeCol > 0) this.out.write(`\x1b[${safeCol}C`);
|
|
1908
1987
|
if (hideCursor) {
|
|
1909
1988
|
this.out.write('\x1b[?25l');
|
|
1910
1989
|
} else {
|
|
@@ -1941,13 +2020,18 @@ export class ChatPrompt {
|
|
|
1941
2020
|
|
|
1942
2021
|
/** The live region while a dialog is up: the panel, then the status row. */
|
|
1943
2022
|
drawLayer(width) {
|
|
2023
|
+
const preferredHeight = typeof this.layer.preferredHeight === 'function'
|
|
2024
|
+
? this.layer.preferredHeight()
|
|
2025
|
+
: 14;
|
|
1944
2026
|
if (this.layer.messageActions && this.surface?.presentMessageActions) {
|
|
1945
|
-
const availableWidth =
|
|
2027
|
+
const availableWidth = this.surface.composeAvailableWidth
|
|
2028
|
+
? this.surface.composeAvailableWidth()
|
|
2029
|
+
: sessionMainWidth(this.surface.width, false, this.surface.env);
|
|
1946
2030
|
const requestedWidth = typeof this.layer.preferredWidth === 'function'
|
|
1947
2031
|
? this.layer.preferredWidth(Math.max(8, availableWidth - 3))
|
|
1948
2032
|
: (this.layer.width || 64);
|
|
1949
2033
|
const panelWidth = dialogWidth(Math.max(8, availableWidth - 3), requestedWidth);
|
|
1950
|
-
const panel = panelRows(this.layer, panelWidth,
|
|
2034
|
+
const panel = panelRows(this.layer, panelWidth, preferredHeight);
|
|
1951
2035
|
this.surface.presentMessageActions(panel, this.layer);
|
|
1952
2036
|
return;
|
|
1953
2037
|
}
|
|
@@ -1956,12 +2040,16 @@ export class ChatPrompt {
|
|
|
1956
2040
|
return this.present(view.rows, view.caretRow, view.caretCol);
|
|
1957
2041
|
}
|
|
1958
2042
|
const inline = this.surface && !this.surface.homeInfo;
|
|
1959
|
-
const availableWidth = inline
|
|
2043
|
+
const availableWidth = inline
|
|
2044
|
+
? (this.surface.composeAvailableWidth
|
|
2045
|
+
? this.surface.composeAvailableWidth()
|
|
2046
|
+
: sessionMainWidth(this.surface.width, false, this.surface.env))
|
|
2047
|
+
: width;
|
|
1960
2048
|
const panelWidth = dialogWidth(availableWidth, this.layer.width || 64);
|
|
1961
2049
|
const stageMax = this.surface?.stage?.maxHeight || this.out?.rows || 24;
|
|
1962
2050
|
const statusReserve = 2; // status row + margin
|
|
1963
2051
|
const availableDialogRows = Math.max(4, stageMax - statusReserve);
|
|
1964
|
-
const maxHeight = dialogHeight(availableDialogRows,
|
|
2052
|
+
const maxHeight = dialogHeight(availableDialogRows, preferredHeight);
|
|
1965
2053
|
const panel = panelRows(this.layer, panelWidth, maxHeight);
|
|
1966
2054
|
const status = this.statusRow(width);
|
|
1967
2055
|
const all = this.clampRows(panel.concat(status), width);
|
|
@@ -1970,9 +2058,13 @@ export class ChatPrompt {
|
|
|
1970
2058
|
const cursor = this.layer.cursor;
|
|
1971
2059
|
const centered = this.surface ? centerRows(all, availableWidth) : { rows: all, inset: 0 };
|
|
1972
2060
|
const stageHeight = this.surface?.stage?.height || this.out?.rows || all.length;
|
|
2061
|
+
const outRows = Number.isFinite(this.out?.rows) && this.out.rows > 0
|
|
2062
|
+
? Math.floor(this.out.rows)
|
|
2063
|
+
: stageHeight;
|
|
1973
2064
|
this.layer.panelGeometry = {
|
|
1974
2065
|
inset: centered.inset,
|
|
1975
|
-
|
|
2066
|
+
// Anchor at the panel's last body row above the bottom border and status rows (0-based screen row).
|
|
2067
|
+
optionScreenRow: Math.max(0, outRows - status.length - 2)
|
|
1976
2068
|
};
|
|
1977
2069
|
this.present(centered.rows, cursor ? 1 + cursor.y : 0,
|
|
1978
2070
|
(cursor ? 2 + cursor.x : 0) + centered.inset);
|
package/src/tui/runningLight.js
CHANGED
|
@@ -74,7 +74,7 @@ export function resolveRunningLightSpeed(speed = 'medium') {
|
|
|
74
74
|
* - For `runesLen >= 25`: bidirectional ping-pong sweep at `longStepMs`.
|
|
75
75
|
*/
|
|
76
76
|
export function runningLightWindow(runesLen, nowMs, speed = 'medium') {
|
|
77
|
-
const len = Math.max(0, Math.floor(runesLen));
|
|
77
|
+
const len = Number.isFinite(runesLen) ? Math.max(0, Math.floor(runesLen)) : 0;
|
|
78
78
|
const { shortStepMs, longStepMs } = resolveRunningLightSpeed(speed);
|
|
79
79
|
if (len <= 0 || shortStepMs <= 0 || longStepMs <= 0) {
|
|
80
80
|
return { start: 0, width: 0, active: false };
|
package/src/tui/runningLight.ts
CHANGED
|
@@ -110,7 +110,7 @@ export function runningLightWindow(
|
|
|
110
110
|
nowMs: number,
|
|
111
111
|
speed: RunningLightSpeed = 'medium'
|
|
112
112
|
): RunningLightWindow {
|
|
113
|
-
const len = Math.max(0, Math.floor(runesLen));
|
|
113
|
+
const len = Number.isFinite(runesLen) ? Math.max(0, Math.floor(runesLen)) : 0;
|
|
114
114
|
const { shortStepMs, longStepMs } = resolveRunningLightSpeed(speed);
|
|
115
115
|
if (len <= 0 || shortStepMs <= 0 || longStepMs <= 0) {
|
|
116
116
|
return { start: 0, width: 0, active: false };
|