@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/dialogs.js
CHANGED
|
@@ -22,9 +22,13 @@ import { LineEditor } from './lineEditor.js';
|
|
|
22
22
|
import { paint, bold, dim, badge, GLYPHS } from './theme.js';
|
|
23
23
|
import { truncate, wrap, visibleWidth, safeDisplay, shortenHome } from './text.js';
|
|
24
24
|
import { approvalDiff } from './diff.js';
|
|
25
|
-
import { isChar } from './keys.js';
|
|
25
|
+
import { isChar, isMouseMotion } from './keys.js';
|
|
26
26
|
import { readClipboardSync } from './clipboardSync.js';
|
|
27
27
|
|
|
28
|
+
const cleanDialogText = (value) => (
|
|
29
|
+
value == null ? '' : safeDisplay(String(value)).replace(/\s+/g, ' ').trim()
|
|
30
|
+
);
|
|
31
|
+
|
|
28
32
|
/**
|
|
29
33
|
* A picker. `items` are SelectList items; `onPick(item)` fires on enter.
|
|
30
34
|
*
|
|
@@ -33,14 +37,16 @@ import { readClipboardSync } from './clipboardSync.js';
|
|
|
33
37
|
*/
|
|
34
38
|
export class SelectLayer extends Layer {
|
|
35
39
|
constructor(options = {}) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
const opts = options && typeof options === 'object' ? options : {};
|
|
41
|
+
super({ width: opts.width || 68, height: opts.height || 18, ...opts });
|
|
42
|
+
this.list = new SelectList(opts.items || [], {
|
|
43
|
+
placeholder: opts.placeholder,
|
|
44
|
+
emptyText: opts.emptyText,
|
|
45
|
+
showFilter: opts.showFilter
|
|
40
46
|
});
|
|
41
|
-
this.onPick =
|
|
47
|
+
this.onPick = opts.onPick || null;
|
|
42
48
|
this.settled = false;
|
|
43
|
-
this.footer =
|
|
49
|
+
this.footer = opts.footer || dialogHint();
|
|
44
50
|
}
|
|
45
51
|
|
|
46
52
|
/** Dismissal must resolve pending picker flows, just like text inputs. */
|
|
@@ -91,14 +97,15 @@ export class SelectLayer extends Layer {
|
|
|
91
97
|
|
|
92
98
|
export class InputLayer extends Layer {
|
|
93
99
|
constructor(options = {}) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
this.
|
|
97
|
-
this.
|
|
98
|
-
this.
|
|
99
|
-
this.
|
|
100
|
-
this.
|
|
101
|
-
this.
|
|
100
|
+
const opts = options && typeof options === 'object' ? options : {};
|
|
101
|
+
super({ width: opts.width || 68, height: opts.height || 10, ...opts });
|
|
102
|
+
this.editor = new LineEditor(String(opts.value == null ? '' : opts.value));
|
|
103
|
+
this.lines = Array.isArray(opts.lines) ? opts.lines : [];
|
|
104
|
+
this.mask = opts.mask === true;
|
|
105
|
+
this.placeholder = opts.placeholder || '';
|
|
106
|
+
this.onSubmit = opts.onSubmit || null;
|
|
107
|
+
this.onCancel = opts.onCancel || null;
|
|
108
|
+
this.footer = opts.footer || `enter accept ${GLYPHS.dot} esc cancel`;
|
|
102
109
|
this.settled = false;
|
|
103
110
|
}
|
|
104
111
|
|
|
@@ -113,19 +120,26 @@ export class InputLayer extends Layer {
|
|
|
113
120
|
}
|
|
114
121
|
|
|
115
122
|
body(width) {
|
|
116
|
-
const
|
|
123
|
+
const safeWidth = Number.isFinite(width) && width > 0 ? Math.floor(width) : 8;
|
|
124
|
+
const rows = this.lines.map((line) => truncate(cleanDialogText(line), safeWidth, GLYPHS.ellipsis));
|
|
117
125
|
if (rows.length) rows.push('');
|
|
118
126
|
|
|
119
127
|
const raw = this.editor.getText();
|
|
120
|
-
const shown = this.mask ? GLYPHS.bullet.repeat(raw.length) : raw;
|
|
121
|
-
const
|
|
128
|
+
const shown = this.mask ? GLYPHS.bullet.repeat(Array.from(raw).length) : cleanDialogText(raw);
|
|
129
|
+
const cleanPlaceholder = cleanDialogText(this.placeholder);
|
|
130
|
+
const text = shown.length === 0 && cleanPlaceholder ? dim(cleanPlaceholder) : shown;
|
|
122
131
|
|
|
123
132
|
const prefix = paint('accent', `${GLYPHS.arrow} `);
|
|
124
|
-
rows.push(truncate(prefix + text,
|
|
133
|
+
rows.push(truncate(prefix + text, safeWidth, GLYPHS.ellipsis));
|
|
125
134
|
|
|
126
135
|
// Park the caret after what is displayed — which for a masked field is the
|
|
127
|
-
// dot count, not the character count, or the caret drifts off the value
|
|
128
|
-
|
|
136
|
+
// dot count, not the character count, or the caret drifts off the value —
|
|
137
|
+
// and never past the rightmost body column.
|
|
138
|
+
const before = this.mask
|
|
139
|
+
? Array.from(raw.slice(0, this.editor.col)).length
|
|
140
|
+
: visibleWidth(cleanDialogText(raw.slice(0, this.editor.col)));
|
|
141
|
+
const maxCol = Math.max(0, safeWidth - 1);
|
|
142
|
+
this.cursor = { x: Math.min(maxCol, 2 + before), y: rows.length - 1 };
|
|
129
143
|
return rows;
|
|
130
144
|
}
|
|
131
145
|
|
|
@@ -227,8 +241,12 @@ export class HomeLayer extends Layer {
|
|
|
227
241
|
// The hint column is right-padded from the widest label so the two columns
|
|
228
242
|
// line up, but it is computed from the ACTUAL labels rather than a constant:
|
|
229
243
|
// a hardcoded inset is what makes a menu look off by one at some widths.
|
|
230
|
-
const
|
|
231
|
-
|
|
244
|
+
const cleanItems = this.items.map((item) => ({
|
|
245
|
+
label: cleanDialogText(item?.label || ''),
|
|
246
|
+
hint: cleanDialogText(item?.hint || '')
|
|
247
|
+
}));
|
|
248
|
+
const labelWidth = cleanItems.reduce((max, item) => Math.max(max, visibleWidth(item.label)), 0);
|
|
249
|
+
return cleanItems.map((item, i) => {
|
|
232
250
|
const selected = i === this.index;
|
|
233
251
|
const marker = selected ? paint('accent', GLYPHS.arrow) : ' ';
|
|
234
252
|
const label = selected ? bold(paint('accent', item.label)) : item.label;
|
|
@@ -244,8 +262,14 @@ export class HomeLayer extends Layer {
|
|
|
244
262
|
if (!event) return null;
|
|
245
263
|
|
|
246
264
|
switch (event.name) {
|
|
247
|
-
case 'up':
|
|
248
|
-
|
|
265
|
+
case 'up':
|
|
266
|
+
if (this.items.length === 0) return 'handled';
|
|
267
|
+
this.index = (this.index - 1 + this.items.length) % this.items.length;
|
|
268
|
+
return 'handled';
|
|
269
|
+
case 'down':
|
|
270
|
+
if (this.items.length === 0) return 'handled';
|
|
271
|
+
this.index = (this.index + 1) % this.items.length;
|
|
272
|
+
return 'handled';
|
|
249
273
|
case 'enter':
|
|
250
274
|
case 'return': {
|
|
251
275
|
const item = this.current;
|
|
@@ -284,17 +308,19 @@ export class TextLayer extends Layer {
|
|
|
284
308
|
preferredHeight() { return this.lines.length + 2; }
|
|
285
309
|
|
|
286
310
|
body(width, height) {
|
|
287
|
-
|
|
288
|
-
const
|
|
311
|
+
const safeWidth = Number.isFinite(width) && width > 0 ? Math.floor(width) : 8;
|
|
312
|
+
const safeHeight = Number.isFinite(height) && height > 0 ? Math.floor(height) : 1;
|
|
313
|
+
this.viewHeight = safeHeight;
|
|
314
|
+
const maximum = Math.max(0, this.lines.length - safeHeight);
|
|
289
315
|
this.scroll = Math.max(0, Math.min(this.scroll, maximum));
|
|
290
316
|
|
|
291
|
-
const window = this.lines.slice(this.scroll, this.scroll +
|
|
292
|
-
.map((line) => truncate(line,
|
|
317
|
+
const window = this.lines.slice(this.scroll, this.scroll + safeHeight)
|
|
318
|
+
.map((line) => truncate(line == null ? '' : safeDisplay(String(line)), safeWidth, GLYPHS.ellipsis));
|
|
293
319
|
|
|
294
|
-
if (this.lines.length >
|
|
295
|
-
const position = `${this.scroll + 1}-${Math.min(this.lines.length, this.scroll +
|
|
296
|
-
while (window.length <
|
|
297
|
-
window[
|
|
320
|
+
if (this.lines.length > safeHeight) {
|
|
321
|
+
const position = `${this.scroll + 1}-${Math.min(this.lines.length, this.scroll + safeHeight)}/${this.lines.length}`;
|
|
322
|
+
while (window.length < safeHeight) window.push('');
|
|
323
|
+
window[safeHeight - 1] = dim(position.padStart(safeWidth));
|
|
298
324
|
}
|
|
299
325
|
this.cursor = null;
|
|
300
326
|
return window;
|
|
@@ -306,12 +332,17 @@ export class TextLayer extends Layer {
|
|
|
306
332
|
switch (event.name) {
|
|
307
333
|
case 'escape':
|
|
308
334
|
case 'q': return 'close';
|
|
309
|
-
case '
|
|
335
|
+
case 'wheel':
|
|
336
|
+
if (event.wheel?.direction === 'up') this.scroll = Math.max(0, this.scroll - 1);
|
|
337
|
+
else if (event.wheel?.direction === 'down') this.scroll++;
|
|
338
|
+
return 'handled';
|
|
339
|
+
case 'up': this.scroll = Math.max(0, this.scroll - 1); return 'handled';
|
|
310
340
|
case 'down': this.scroll++; return 'handled';
|
|
311
|
-
case 'pageup': this.scroll
|
|
341
|
+
case 'pageup': this.scroll = Math.max(0, this.scroll - page); return 'handled';
|
|
312
342
|
case 'pagedown': this.scroll += page; return 'handled';
|
|
313
343
|
case 'home': this.scroll = 0; return 'handled';
|
|
314
344
|
case 'end': this.scroll = this.lines.length; return 'handled';
|
|
345
|
+
case 'enter':
|
|
315
346
|
case 'return': return 'close';
|
|
316
347
|
default: return 'handled';
|
|
317
348
|
}
|
|
@@ -414,10 +445,11 @@ export class ApprovalLayer extends Layer {
|
|
|
414
445
|
// chips, so the diff never grows into the controls and push them off-panel.
|
|
415
446
|
const height = Math.max(1, fullHeight - 2);
|
|
416
447
|
const rows = [];
|
|
417
|
-
|
|
448
|
+
const cleanVerb = this.verb ? cleanDialogText(this.verb) : '';
|
|
449
|
+
rows.push(`${paint(this.role, GLYPHS.warnMark)} ${bold(safeDisplay(this.request.tool || ''))}${cleanVerb ? dim(` ${cleanVerb}`) : ''}`);
|
|
418
450
|
|
|
419
451
|
if (this.detail) {
|
|
420
|
-
for (const line of wrap(paint('ink', this.detail), width).slice(0, 2)) rows.push(line);
|
|
452
|
+
for (const line of wrap(paint('ink', cleanDialogText(this.detail)), width).slice(0, 2)) rows.push(line);
|
|
421
453
|
}
|
|
422
454
|
|
|
423
455
|
if (this.diff) {
|
|
@@ -425,10 +457,10 @@ export class ApprovalLayer extends Layer {
|
|
|
425
457
|
this.diff.added ? paint('success', `+${this.diff.added}`) : '',
|
|
426
458
|
this.diff.removed ? paint('danger', `-${this.diff.removed}`) : ''
|
|
427
459
|
].filter(Boolean).join(' ');
|
|
428
|
-
const note = this.diff.note ? dim(` ${GLYPHS.dot} ${this.diff.note}`) : '';
|
|
460
|
+
const note = this.diff.note ? dim(` ${GLYPHS.dot} ${cleanDialogText(this.diff.note)}`) : '';
|
|
429
461
|
// The detail row above already names the file; printing the path again
|
|
430
462
|
// here just spends a row saying the same thing twice.
|
|
431
|
-
const where = this.detail ? '' : `${dim(this.diff.path)} `;
|
|
463
|
+
const where = this.detail ? '' : `${dim(cleanDialogText(this.diff.path))} `;
|
|
432
464
|
rows.push('');
|
|
433
465
|
rows.push(`${where}${stat}${note}`);
|
|
434
466
|
rows.push(paint('rule', GLYPHS.hLine.repeat(width)));
|
|
@@ -501,16 +533,27 @@ export class ApprovalLayer extends Layer {
|
|
|
501
533
|
return 'close';
|
|
502
534
|
}
|
|
503
535
|
|
|
504
|
-
if (event.name === 'mouse' && event.mouse && event.mouse.pressed && event.mouse.button === 0) {
|
|
536
|
+
if (event.name === 'mouse' && event.mouse && event.mouse.pressed && event.mouse.button === 0 && !isMouseMotion(event.sequence)) {
|
|
505
537
|
if (!Array.isArray(this.optionBounds) || this.optionBounds.length === 0) {
|
|
506
538
|
this.optionRow();
|
|
507
539
|
}
|
|
508
540
|
const geom = this.panelGeometry;
|
|
509
|
-
|
|
510
|
-
|
|
541
|
+
const hasZeroRow = Number.isFinite(event.mouse.y);
|
|
542
|
+
const rawRow = hasZeroRow
|
|
543
|
+
? Math.floor(event.mouse.y)
|
|
544
|
+
: (Number.isFinite(event.mouse.row) ? Math.floor(event.mouse.row) : NaN);
|
|
545
|
+
if (geom && Number.isFinite(rawRow) && Number.isFinite(geom.optionScreenRow)) {
|
|
546
|
+
// drawLayer() computes 0-based screen rows; legacy synthetic callers send 1-based row.
|
|
547
|
+
const zeroBasedRow = hasZeroRow ? rawRow : rawRow - 1;
|
|
548
|
+
if (Math.abs(zeroBasedRow - geom.optionScreenRow) > 1) return 'handled';
|
|
511
549
|
}
|
|
512
|
-
const
|
|
513
|
-
const
|
|
550
|
+
const hasZeroCol = Number.isFinite(event.mouse.x);
|
|
551
|
+
const rawCol = hasZeroCol
|
|
552
|
+
? Math.floor(event.mouse.x)
|
|
553
|
+
: (Number.isFinite(event.mouse.col) ? Math.floor(event.mouse.col) : -1);
|
|
554
|
+
const bodyCol = geom
|
|
555
|
+
? rawCol - (hasZeroCol ? 0 : 1) - (geom.inset || 0) - 2
|
|
556
|
+
: rawCol;
|
|
514
557
|
const hit = (this.optionBounds || []).find(b => bodyCol >= b.startCol && bodyCol <= b.endCol);
|
|
515
558
|
if (hit) {
|
|
516
559
|
this.selected = hit.index;
|
|
@@ -521,15 +564,15 @@ export class ApprovalLayer extends Layer {
|
|
|
521
564
|
}
|
|
522
565
|
|
|
523
566
|
if (event.name === 'wheel') {
|
|
524
|
-
if (event.wheel?.direction === 'up') this.scroll
|
|
567
|
+
if (event.wheel?.direction === 'up') this.scroll = Math.max(0, this.scroll - 1);
|
|
525
568
|
else if (event.wheel?.direction === 'down') this.scroll++;
|
|
526
569
|
return 'handled';
|
|
527
570
|
}
|
|
528
571
|
|
|
529
572
|
switch (event.name) {
|
|
530
|
-
case 'up': this.scroll
|
|
573
|
+
case 'up': this.scroll = Math.max(0, this.scroll - 1); return 'handled';
|
|
531
574
|
case 'down': this.scroll++; return 'handled';
|
|
532
|
-
case 'pageup': this.scroll
|
|
575
|
+
case 'pageup': this.scroll = Math.max(0, this.scroll - page); return 'handled';
|
|
533
576
|
case 'pagedown': this.scroll += page; return 'handled';
|
|
534
577
|
case 'home': this.scroll = 0; return 'handled';
|
|
535
578
|
case 'end': this.scroll = this.diff ? this.diff.rows.length : 0; return 'handled';
|
|
@@ -587,18 +630,27 @@ export class DecisionLayer extends Layer {
|
|
|
587
630
|
if (option.description) rows.push(` ${dim(truncate(safeDisplay(option.description), Math.max(1, width - 2), GLYPHS.ellipsis))}`);
|
|
588
631
|
}
|
|
589
632
|
|
|
633
|
+
const safeWidth = Number.isFinite(width) && width > 0 ? Math.floor(width) : 8;
|
|
634
|
+
const safeHeight = Number.isFinite(height) && height > 0 ? Math.floor(height) : rows.length + 2;
|
|
590
635
|
const customSelected = this.selected === this.customIndex;
|
|
591
636
|
rows.push(`${customSelected ? paint('accent', GLYPHS.arrow) : paint('muted', GLYPHS.dot)} ${customSelected ? bold('Type your own answer') : 'Type your own answer'}`);
|
|
592
637
|
if (this.customMode) {
|
|
593
|
-
const
|
|
594
|
-
|
|
595
|
-
|
|
638
|
+
const raw = this.editor.getText();
|
|
639
|
+
const value = cleanDialogText(raw);
|
|
640
|
+
rows.push(truncate(`${paint('accent', `${GLYPHS.arrow} `)}${value || dim('Describe the direction you want')}`, safeWidth, GLYPHS.ellipsis));
|
|
641
|
+
const rendered = rows.length > safeHeight ? rows.slice(rows.length - safeHeight) : rows;
|
|
642
|
+
const before = visibleWidth(cleanDialogText(raw.slice(0, this.editor.col)));
|
|
643
|
+
this.cursor = {
|
|
644
|
+
x: Math.min(Math.max(0, safeWidth - 1), 2 + before),
|
|
645
|
+
y: Math.max(0, rendered.length - 1)
|
|
646
|
+
};
|
|
596
647
|
this.footer = `enter submit ${GLYPHS.dot} esc choices`;
|
|
648
|
+
return rendered;
|
|
597
649
|
} else {
|
|
598
650
|
this.cursor = null;
|
|
599
651
|
this.footer = `↑↓ choose ${GLYPHS.dot} enter select ${GLYPHS.dot} esc cancel`;
|
|
600
652
|
}
|
|
601
|
-
return rows.slice(0,
|
|
653
|
+
return rows.slice(0, safeHeight);
|
|
602
654
|
}
|
|
603
655
|
|
|
604
656
|
key(event) {
|
|
@@ -695,18 +747,19 @@ export class ConfirmLayer extends Layer {
|
|
|
695
747
|
|
|
696
748
|
/** The command palette — every command in the app, fuzzy-searchable. */
|
|
697
749
|
export function commandPalette(commands, onRun) {
|
|
750
|
+
const safeCommands = Array.isArray(commands) ? commands.filter(Boolean) : [];
|
|
698
751
|
return new SelectLayer({
|
|
699
752
|
title: 'commands',
|
|
700
753
|
placeholder: 'search commands',
|
|
701
754
|
emptyText: 'no command matches',
|
|
702
755
|
width: 72,
|
|
703
756
|
height: 20,
|
|
704
|
-
items:
|
|
705
|
-
label: command.name,
|
|
706
|
-
description: command.description || '',
|
|
707
|
-
category: command.category || '',
|
|
708
|
-
hint: command.hint || '',
|
|
709
|
-
searchText: command.description || '',
|
|
757
|
+
items: safeCommands.map((command) => ({
|
|
758
|
+
label: cleanDialogText(command.name || ''),
|
|
759
|
+
description: cleanDialogText(command.description || ''),
|
|
760
|
+
category: cleanDialogText(command.category || ''),
|
|
761
|
+
hint: cleanDialogText(command.hint || ''),
|
|
762
|
+
searchText: cleanDialogText(command.description || ''),
|
|
710
763
|
value: command
|
|
711
764
|
})),
|
|
712
765
|
onPick: (item) => { if (item && onRun) onRun(item.value); }
|
|
@@ -724,17 +777,18 @@ export function commandPalette(commands, onRun) {
|
|
|
724
777
|
* the pane rather than to the terminal, so overflow is structurally impossible.
|
|
725
778
|
*/
|
|
726
779
|
export function skillPicker(skills, onOpen) {
|
|
780
|
+
const safeSkills = Array.isArray(skills) ? skills.filter(Boolean) : [];
|
|
727
781
|
return new SelectLayer({
|
|
728
|
-
title: `skills (${
|
|
782
|
+
title: `skills (${safeSkills.length})`,
|
|
729
783
|
placeholder: 'search skills',
|
|
730
784
|
emptyText: 'no skill matches',
|
|
731
785
|
width: 76,
|
|
732
786
|
height: 22,
|
|
733
|
-
items:
|
|
734
|
-
label: `${skill.domain}/${skill.id}`,
|
|
735
|
-
description: skill.description || '',
|
|
736
|
-
category: skill.domain,
|
|
737
|
-
searchText: `${skill.name} ${skill.description || ''}
|
|
787
|
+
items: safeSkills.map((skill) => ({
|
|
788
|
+
label: `${cleanDialogText(skill.domain || '')}/${cleanDialogText(skill.id || '')}`,
|
|
789
|
+
description: cleanDialogText(skill.description || ''),
|
|
790
|
+
category: cleanDialogText(skill.domain || ''),
|
|
791
|
+
searchText: cleanDialogText(`${skill.name || ''} ${skill.description || ''}`),
|
|
738
792
|
value: skill
|
|
739
793
|
})),
|
|
740
794
|
onPick: (item) => { if (item && onOpen) onOpen(item.value); }
|
|
@@ -743,10 +797,15 @@ export function skillPicker(skills, onOpen) {
|
|
|
743
797
|
|
|
744
798
|
/** Help: the keys, grouped, in a scrolling pane. */
|
|
745
799
|
export function helpLayer(sections) {
|
|
800
|
+
const safeSections = Array.isArray(sections) ? sections.filter(Boolean) : [];
|
|
746
801
|
const lines = [];
|
|
747
|
-
for (const section of
|
|
748
|
-
lines.push(bold(paint('ink', section.title)));
|
|
749
|
-
|
|
802
|
+
for (const section of safeSections) {
|
|
803
|
+
lines.push(bold(paint('ink', cleanDialogText(section.title || ''))));
|
|
804
|
+
const rows = Array.isArray(section.rows) ? section.rows : [];
|
|
805
|
+
for (const pair of rows) {
|
|
806
|
+
if (!Array.isArray(pair)) continue;
|
|
807
|
+
const keys = cleanDialogText(pair[0] || '');
|
|
808
|
+
const what = cleanDialogText(pair[1] || '');
|
|
750
809
|
lines.push(` ${paint('accent', keys.padEnd(18))}${dim(what)}`);
|
|
751
810
|
}
|
|
752
811
|
lines.push('');
|
|
@@ -756,12 +815,16 @@ export function helpLayer(sections) {
|
|
|
756
815
|
|
|
757
816
|
/** A status pane: session facts that would otherwise need a scrollback hunt. */
|
|
758
817
|
export function statusLayer(rows) {
|
|
759
|
-
const
|
|
760
|
-
const
|
|
761
|
-
|
|
818
|
+
const safeRows = (Array.isArray(rows) ? rows : []).filter(row => Array.isArray(row));
|
|
819
|
+
const labels = safeRows.map(row => cleanDialogText(row[0] == null ? '' : String(row[0])));
|
|
820
|
+
const width = labels.reduce((max, label) => Math.max(max, label.length), 0);
|
|
821
|
+
const lines = safeRows.map((row, index) => {
|
|
822
|
+
const label = labels[index];
|
|
823
|
+
const value = cleanDialogText(row[1] == null ? '' : String(row[1]));
|
|
824
|
+
return label === ''
|
|
762
825
|
? ''
|
|
763
|
-
: `${paint('muted',
|
|
764
|
-
)
|
|
826
|
+
: `${paint('muted', label.padEnd(width + 2))}${paint('ink', value)}`;
|
|
827
|
+
});
|
|
765
828
|
return new TextLayer({ title: 'session', lines, width: 74, height: Math.min(24, lines.length + 3) });
|
|
766
829
|
}
|
|
767
830
|
|
package/src/tui/diff.js
CHANGED
|
@@ -156,8 +156,12 @@ function collapse(ops) {
|
|
|
156
156
|
* meaning on their own, which is what makes the no-colour output still readable.
|
|
157
157
|
*/
|
|
158
158
|
export function renderDiffOps(ops, options = {}) {
|
|
159
|
-
|
|
160
|
-
const
|
|
159
|
+
if (!Array.isArray(ops)) return { rows: [], clipped: false };
|
|
160
|
+
const safeWidth = Number.isFinite(options?.width) && options.width > 0 ? Math.floor(options.width) : 80;
|
|
161
|
+
const width = Math.max(20, safeWidth - 8);
|
|
162
|
+
const maxLines = Number.isFinite(options?.maxLines) && options.maxLines > 0
|
|
163
|
+
? Math.floor(options.maxLines)
|
|
164
|
+
: MAX_RENDER_LINES;
|
|
161
165
|
const collapsed = collapse(ops);
|
|
162
166
|
const rendered = [];
|
|
163
167
|
|
|
@@ -281,8 +285,8 @@ export function approvalDiff(toolName, args, options = {}) {
|
|
|
281
285
|
if (rows.length === 0) return null;
|
|
282
286
|
|
|
283
287
|
return {
|
|
284
|
-
path: plan.path ? shortenHome(plan.path) : '',
|
|
285
|
-
note: plan.note,
|
|
288
|
+
path: plan.path ? safeDisplay(shortenHome(plan.path)).replace(/[\r\n]+/g, ' ') : '',
|
|
289
|
+
note: plan.note ? safeDisplay(plan.note).replace(/[\r\n]+/g, ' ') : '',
|
|
286
290
|
rows,
|
|
287
291
|
added: stat.added,
|
|
288
292
|
removed: stat.removed,
|
package/src/tui/history.js
CHANGED
|
@@ -51,7 +51,7 @@ export class PromptHistory {
|
|
|
51
51
|
return null;
|
|
52
52
|
}
|
|
53
53
|
})
|
|
54
|
-
.filter((entry) => typeof entry === 'string' && entry.length > 0);
|
|
54
|
+
.filter((entry) => typeof entry === 'string' && entry.length > 0 && !looksSensitive(entry));
|
|
55
55
|
} catch (e) {
|
|
56
56
|
this.entries = []; // no history yet is the normal first run
|
|
57
57
|
}
|
|
@@ -90,7 +90,7 @@ export class PromptHistory {
|
|
|
90
90
|
fs.mkdirSync(path.dirname(this.file), { recursive: true });
|
|
91
91
|
const body = this.entries.map((entry) => JSON.stringify(entry)).join('\n') + '\n';
|
|
92
92
|
// Write then rename: a crash mid-write must not truncate the history.
|
|
93
|
-
const temporary = this.file
|
|
93
|
+
const temporary = `${this.file}.${process.pid}.tmp`;
|
|
94
94
|
fs.writeFileSync(temporary, body, { mode: 0o600 });
|
|
95
95
|
fs.renameSync(temporary, this.file);
|
|
96
96
|
} catch (e) {
|
|
@@ -104,13 +104,14 @@ export class PromptHistory {
|
|
|
104
104
|
* Typing `npm ` then pressing Up should walk npm prompts, not everything.
|
|
105
105
|
*/
|
|
106
106
|
matching(prefix) {
|
|
107
|
-
|
|
108
|
-
return this.entries.
|
|
107
|
+
const query = String(prefix == null ? '' : prefix);
|
|
108
|
+
if (!query) return this.entries.slice().reverse();
|
|
109
|
+
return this.entries.filter((entry) => entry.startsWith(query)).reverse();
|
|
109
110
|
}
|
|
110
111
|
|
|
111
112
|
/** Older entry, or null at the end. `draft` is the line being edited. */
|
|
112
113
|
previous(draft) {
|
|
113
|
-
if (this.cursor === -1) this.draft = draft;
|
|
114
|
+
if (this.cursor === -1) this.draft = String(draft == null ? '' : draft);
|
|
114
115
|
const pool = this.matching(this.draft);
|
|
115
116
|
if (pool.length === 0) return null;
|
|
116
117
|
const next = Math.min(this.cursor + 1, pool.length - 1);
|
package/src/tui/home.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { SelectLayer, InputLayer } from './dialogs.js';
|
|
4
4
|
import { paint, dim, bold, badge, GLYPHS } from './theme.js';
|
|
5
|
+
import { safeDisplay } from './text.js';
|
|
5
6
|
import { runSetup } from './setup.js';
|
|
6
7
|
import { DEFAULT_MODEL_BY_PROVIDER } from '../modelCatalogue.js';
|
|
7
8
|
import { isAcpProvider } from '../providers/acp.js';
|
|
@@ -9,14 +10,21 @@ import { isAntigravityProvider, resolveAgyBinary } from '../providers/antigravit
|
|
|
9
10
|
import { isPiProvider, PI_SETUP_PROVIDER } from '../providers/pi.js';
|
|
10
11
|
import { isBinaryOnPath } from '../acp/agentCatalog.js';
|
|
11
12
|
|
|
13
|
+
function cleanSingleLine(value) {
|
|
14
|
+
return safeDisplay(typeof value === 'string' ? value : '').replace(/[\r\n]+/g, ' ').trim();
|
|
15
|
+
}
|
|
16
|
+
|
|
12
17
|
/** Local runtime and provider summary. */
|
|
13
18
|
export function homeStatusLine(arg = {}) {
|
|
14
|
-
const
|
|
15
|
-
const
|
|
19
|
+
const rawObj = arg && typeof arg === 'object' ? arg : {};
|
|
20
|
+
const config = rawObj.config && typeof rawObj.config === 'object' ? rawObj.config : rawObj;
|
|
21
|
+
const provider = cleanSingleLine(config.provider);
|
|
22
|
+
const modelName = cleanSingleLine(config.model);
|
|
23
|
+
const hasProvider = Boolean(provider && provider !== 'unconfigured');
|
|
16
24
|
const model = hasProvider
|
|
17
|
-
? (
|
|
25
|
+
? (modelName ? `${provider}/${modelName}` : provider)
|
|
18
26
|
: 'no provider configured';
|
|
19
|
-
const configured = Boolean((hasProvider && config.apiKey) ||
|
|
27
|
+
const configured = Boolean((hasProvider && config.apiKey) || provider === 'ollama' || isAcpProvider(provider) || isAntigravityProvider(provider) || isPiProvider(provider));
|
|
20
28
|
return ' ' + [
|
|
21
29
|
paint('success', `${GLYPHS.bullet} local desktop`),
|
|
22
30
|
configured
|
|
@@ -118,7 +126,7 @@ export function moreLayer(onPick) {
|
|
|
118
126
|
category: action.category,
|
|
119
127
|
value: action
|
|
120
128
|
})),
|
|
121
|
-
onPick: (item) => onPick(item && item.value)
|
|
129
|
+
onPick: (item) => { if (typeof onPick === 'function') onPick(item && item.value); }
|
|
122
130
|
});
|
|
123
131
|
}
|
|
124
132
|
|
|
@@ -190,14 +198,18 @@ export async function mcpPicker(prompt, onAction) {
|
|
|
190
198
|
|
|
191
199
|
prompt.openLayer(new SelectLayer({
|
|
192
200
|
title: 'MCP servers',
|
|
193
|
-
items: rows.map((server) =>
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
+
items: rows.map((server) => {
|
|
202
|
+
const name = cleanSingleLine(server?.name) || 'server';
|
|
203
|
+
const target = cleanSingleLine(server?.target);
|
|
204
|
+
return {
|
|
205
|
+
id: name,
|
|
206
|
+
label: name,
|
|
207
|
+
description: `${server?.granted ? 'granted' : 'not granted'}${target ? ` ${GLYPHS.dot} ${target}` : ''}`,
|
|
208
|
+
category: server?.granted ? 'granted' : 'available',
|
|
209
|
+
value: server
|
|
210
|
+
};
|
|
211
|
+
}),
|
|
212
|
+
onPick: (item) => { if (item && typeof onAction === 'function') onAction(item.value); }
|
|
201
213
|
}));
|
|
202
214
|
return { empty: false };
|
|
203
215
|
}
|
package/src/tui/homeView.js
CHANGED
|
@@ -12,43 +12,61 @@ export function isStartupDialog(surface) {
|
|
|
12
12
|
}
|
|
13
13
|
/** Keep startup pickers readable without letting a long catalogue resize the UI. */
|
|
14
14
|
export function startupDialogView(layer, columns, terminalRows) {
|
|
15
|
+
const safeLayer = layer && typeof layer === 'object' ? layer : {};
|
|
15
16
|
const availableWidth = Number.isFinite(columns) ? Math.max(8, Math.floor(columns) - 1) : 79;
|
|
16
17
|
const availableHeight = Number.isFinite(terminalRows) ? Math.max(4, Math.floor(terminalRows) - 2) : 20;
|
|
17
|
-
const
|
|
18
|
+
const requestedWidth = typeof safeLayer.width === 'number' && Number.isFinite(safeLayer.width) ? Math.floor(safeLayer.width) : 0;
|
|
19
|
+
const width = Math.min(availableWidth, 96, Math.max(88, requestedWidth));
|
|
18
20
|
const height = Math.min(availableHeight, 30);
|
|
19
21
|
const measuredLayer = {
|
|
20
|
-
title:
|
|
21
|
-
footer:
|
|
22
|
-
preferredHeight: () =>
|
|
23
|
-
|
|
22
|
+
title: safeLayer.title,
|
|
23
|
+
footer: safeLayer.footer,
|
|
24
|
+
preferredHeight: () => {
|
|
25
|
+
const raw = typeof safeLayer.preferredHeight === 'function' ? safeLayer.preferredHeight() : 14;
|
|
26
|
+
return Math.max(10, Number.isFinite(raw) ? raw : 14);
|
|
27
|
+
},
|
|
28
|
+
body: (innerWidth, bodyHeight) => typeof safeLayer.body === 'function' ? safeLayer.body(innerWidth, bodyHeight) : []
|
|
24
29
|
};
|
|
25
|
-
const centered = centerRows(panelRows(measuredLayer, width, height),
|
|
26
|
-
const cursor =
|
|
30
|
+
const centered = centerRows(panelRows(measuredLayer, width, height), availableWidth + 1);
|
|
31
|
+
const cursor = safeLayer.cursor;
|
|
32
|
+
const safeCursorY = cursor && Number.isFinite(cursor.y) ? Math.max(0, Math.floor(cursor.y)) : null;
|
|
33
|
+
const safeCursorX = cursor && Number.isFinite(cursor.x) ? Math.max(0, Math.floor(cursor.x)) : null;
|
|
34
|
+
const maxRow = Math.max(0, centered.rows.length - 1);
|
|
35
|
+
const maxCol = Math.max(0, availableWidth - 1);
|
|
27
36
|
return {
|
|
28
37
|
rows: centered.rows,
|
|
29
|
-
caretRow:
|
|
30
|
-
caretCol: centered.inset + (
|
|
38
|
+
caretRow: safeCursorY !== null ? Math.min(maxRow, 1 + safeCursorY) : 0,
|
|
39
|
+
caretCol: Math.max(0, Math.min(maxCol, centered.inset + (safeCursorX !== null ? 2 + safeCursorX : 0)))
|
|
31
40
|
};
|
|
32
41
|
}
|
|
33
42
|
/** Center a temporary dialog in the available terminal region. */
|
|
34
43
|
export function placeDialog(rows, columns, height, caretRow, caretCol) {
|
|
35
|
-
const available = Math.max(1, Math.floor(height));
|
|
36
|
-
const
|
|
44
|
+
const available = Number.isFinite(height) ? Math.max(1, Math.floor(height)) : 1;
|
|
45
|
+
const safeColumns = Number.isFinite(columns) ? Math.max(2, Math.floor(columns)) : 80;
|
|
46
|
+
const safeCaretRow = Number.isFinite(caretRow) ? Math.floor(caretRow) : 0;
|
|
47
|
+
const safeCaretCol = Number.isFinite(caretCol) ? Math.floor(caretCol) : 0;
|
|
48
|
+
const safeRows = Array.isArray(rows) ? rows : [];
|
|
49
|
+
const shown = safeRows.slice(0, available);
|
|
37
50
|
const top = Math.max(0, Math.floor((available - shown.length) / 2));
|
|
38
51
|
return {
|
|
39
52
|
rows: [...Array(top).fill(''), ...shown],
|
|
40
|
-
caretRow: top + Math.min(Math.max(0,
|
|
41
|
-
caretCol: Math.max(0, Math.min(
|
|
53
|
+
caretRow: top + Math.max(0, Math.min(safeCaretRow, Math.max(0, shown.length - 1))),
|
|
54
|
+
caretCol: Math.max(0, Math.min(safeCaretCol, safeColumns - 2))
|
|
42
55
|
};
|
|
43
56
|
}
|
|
44
57
|
/** A clean first screen; session messages are intentionally absent. */
|
|
45
58
|
export function placeHome(info, promptRows, columns, height, caretRow, caretCol) {
|
|
46
|
-
const
|
|
47
|
-
const
|
|
59
|
+
const safeInfo = info && typeof info === 'object' ? info : {};
|
|
60
|
+
const safePromptRows = Array.isArray(promptRows) ? promptRows : [];
|
|
61
|
+
const safeColumns = Number.isFinite(columns) ? Math.max(1, Math.floor(columns)) : 80;
|
|
62
|
+
const available = Number.isFinite(height) ? Math.max(1, Math.floor(height)) : 24;
|
|
63
|
+
const safeCaretRow = Number.isFinite(caretRow) ? Math.floor(caretRow) : 0;
|
|
64
|
+
const safeCaretCol = Number.isFinite(caretCol) ? Math.floor(caretCol) : 0;
|
|
65
|
+
const logo = centerRows(sessionBanner(safeInfo, safeColumns, { height: available }), safeColumns).rows;
|
|
48
66
|
const spacer = available >= 25 ? 2 : 1;
|
|
49
67
|
// When the window is short, preserve the composer and editing caret first.
|
|
50
68
|
// The logo yields height; it must never push a wrapped draft off-screen.
|
|
51
|
-
const fitted = fitHomeContent(logo,
|
|
69
|
+
const fitted = fitHomeContent(logo, safePromptRows, available, safeCaretRow, spacer);
|
|
52
70
|
const required = fitted.logoRows.length + fitted.spacer + fitted.promptRows.length;
|
|
53
71
|
const top = Math.max(0, Math.floor((available - required) / 2));
|
|
54
72
|
const rows = [
|
|
@@ -57,9 +75,10 @@ export function placeHome(info, promptRows, columns, height, caretRow, caretCol)
|
|
|
57
75
|
...Array(fitted.spacer).fill(''),
|
|
58
76
|
...fitted.promptRows
|
|
59
77
|
];
|
|
78
|
+
const maxRow = Math.max(0, rows.length - 1);
|
|
60
79
|
return {
|
|
61
80
|
rows,
|
|
62
|
-
caretRow: top + fitted.logoRows.length + fitted.spacer + fitted.caretRow,
|
|
63
|
-
caretCol: Math.max(0, Math.min(
|
|
81
|
+
caretRow: Math.max(0, Math.min(maxRow, top + fitted.logoRows.length + fitted.spacer + fitted.caretRow)),
|
|
82
|
+
caretCol: Math.max(0, Math.min(safeCaretCol, Math.max(0, safeColumns - 2)))
|
|
64
83
|
};
|
|
65
84
|
}
|