@causyne/agent 1.20.35 → 1.20.38
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/LICENSE +1 -1
- package/package.json +1 -1
- package/src/agentLoop.js +77 -9
- package/src/agentLoop.ts +68 -8
- package/src/contextManager.js +15 -1
- package/src/historyPruner.js +43 -5
- package/src/historyPruner.ts +38 -5
- package/src/smartToolsUse.js +9 -5
- package/src/smartToolsUse.ts +10 -5
- package/src/tools/sysRun.js +22 -6
- package/src/tools/sysRun.ts +23 -6
- package/src/tui/chatRenderer.js +39 -46
- package/src/tui/homeView.js +0 -1
- package/src/tui/homeView.ts +0 -1
- package/src/tui/markdownMath.js +250 -0
- package/src/tui/markdownMath.ts +263 -0
- package/src/tui/messageActionPlacement.js +79 -8
- package/src/tui/messageActionPlacement.ts +102 -9
- package/src/tui/messageInteraction.js +43 -9
- package/src/tui/messageInteraction.ts +51 -17
- package/src/tui/overlay.js +191 -192
- package/src/tui/overlay.ts +320 -0
- package/src/tui/prompt.js +4 -1
- package/src/tui/stageSurface.js +4 -1
- package/src/tui/text.js +204 -208
- package/src/tui/text.ts +360 -0
- package/src/tui/toolOutputNormalizer.js +210 -0
- package/src/tui/toolOutputNormalizer.ts +229 -0
- package/src/tui/turnRail.js +11 -1
- package/src/tui/turnRail.ts +11 -1
- package/src/tui/text.d.ts +0 -7
|
@@ -1,21 +1,92 @@
|
|
|
1
1
|
import { padEnd, truncate, visibleWidth } from './text.js';
|
|
2
2
|
import { sliceFromColumn } from './turnRail.js';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
// @ts-expect-error theme has no TypeScript declarations yet
|
|
4
|
+
import { HAS_COLOR } from './theme.js';
|
|
5
|
+
function dimBackdropRow(row) {
|
|
6
|
+
if (!row || !row.trim())
|
|
7
|
+
return row;
|
|
8
|
+
return `\x1b[2m${row.replace(/\x1b\[0m/g, '\x1b[0m\x1b[2m')}\x1b[0m`;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Overlay a message action menu in the transcript viewport with adaptive,
|
|
12
|
+
* context-aware positioning and elevated backdrop isolation.
|
|
13
|
+
*/
|
|
14
|
+
export function placeMessageActionPanel(viewportRows, panel, contentWidth, stageTop, anchorY, count, options) {
|
|
5
15
|
if (!panel.length || viewportRows.length < panel.length || contentWidth < 8) {
|
|
6
16
|
return { rows: viewportRows, layout: null };
|
|
7
17
|
}
|
|
18
|
+
const totalRows = viewportRows.length;
|
|
19
|
+
const panelHeight = panel.length;
|
|
8
20
|
const width = Math.min(contentWidth, Math.max(...panel.map(visibleWidth)));
|
|
9
21
|
const x = Math.max(0, Math.floor((contentWidth - width) / 2));
|
|
10
|
-
|
|
11
|
-
const
|
|
22
|
+
// Vertical constraints and comfortable ergonomic margins
|
|
23
|
+
const maxAllowedY = totalRows - panelHeight;
|
|
24
|
+
const topMargin = Math.max(1, Math.floor(totalRows * 0.05));
|
|
25
|
+
const bottomMargin = Math.max(1, Math.min(3, Math.floor(totalRows * 0.10)));
|
|
26
|
+
// Optical focal center of the transcript viewport (38% to 42% down reads as eye-level natural center)
|
|
27
|
+
const opticalCenterY = Math.max(topMargin, Math.floor(maxAllowedY * 0.40));
|
|
28
|
+
let targetY;
|
|
29
|
+
if (options?.messageBounds) {
|
|
30
|
+
const { startRow, endRow } = options.messageBounds;
|
|
31
|
+
const msgTop = Math.max(0, Math.min(totalRows - 1, startRow));
|
|
32
|
+
const msgBottom = Math.max(0, Math.min(totalRows - 1, endRow));
|
|
33
|
+
const msgCenter = Math.floor((msgTop + msgBottom) / 2);
|
|
34
|
+
// If message is near the bottom of viewport (bottom rows or starting below the max panel top):
|
|
35
|
+
// Never squash the popup against the bottom composer! Float upward into the clear reading zone.
|
|
36
|
+
if (msgBottom >= totalRows - 3 || msgTop >= maxAllowedY - 1) {
|
|
37
|
+
if (msgTop >= panelHeight + topMargin) {
|
|
38
|
+
// Float directly above the message if room permits, biased towards optical center
|
|
39
|
+
const floatAbove = msgTop - panelHeight;
|
|
40
|
+
targetY = Math.max(topMargin, Math.min(floatAbove, opticalCenterY + 2));
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
// Message spans the bottom or is tight: place at the viewport optical center
|
|
44
|
+
targetY = opticalCenterY;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else if (msgTop <= topMargin + 1) {
|
|
48
|
+
// Message is at the very top: place with comfortable top margin
|
|
49
|
+
targetY = Math.max(topMargin, Math.min(maxAllowedY - bottomMargin, msgCenter - Math.floor(panelHeight / 2)));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
// Message is in the middle: center around message visual mass, softly blended with optical center
|
|
53
|
+
const msgIdealY = msgCenter - Math.floor(panelHeight / 2);
|
|
54
|
+
targetY = Math.round(0.75 * msgIdealY + 0.25 * opticalCenterY);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else if (anchorY !== null) {
|
|
58
|
+
const anchor = anchorY - stageTop;
|
|
59
|
+
if (anchor >= totalRows - 2) {
|
|
60
|
+
// Click at the extreme bottom edge: float upward into the reading zone
|
|
61
|
+
targetY = Math.max(topMargin, Math.min(maxAllowedY - bottomMargin, opticalCenterY + 2));
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// Standard anchor centering
|
|
65
|
+
targetY = anchor - Math.floor(panelHeight / 2);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
targetY = opticalCenterY;
|
|
70
|
+
}
|
|
71
|
+
const y = Math.max(0, Math.min(maxAllowedY, targetY));
|
|
72
|
+
const shouldDim = options?.dimBackdrop === true;
|
|
12
73
|
const rows = viewportRows.slice();
|
|
13
|
-
for (let
|
|
14
|
-
const
|
|
74
|
+
for (let r = 0; r < rows.length; r++) {
|
|
75
|
+
const isPanelRow = r >= y && r < y + panelHeight;
|
|
76
|
+
if (!isPanelRow) {
|
|
77
|
+
if (shouldDim) {
|
|
78
|
+
rows[r] = dimBackdropRow(rows[r] ?? '');
|
|
79
|
+
}
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const panelIdx = r - y;
|
|
83
|
+
const baseRow = rows[r] ?? '';
|
|
15
84
|
const leftPrefix = padEnd(truncate(baseRow, x, ''), x);
|
|
16
|
-
const cardChunk = padEnd(truncate(panel[
|
|
85
|
+
const cardChunk = padEnd(truncate(panel[panelIdx] ?? '', width, ''), width);
|
|
17
86
|
const rightSuffix = sliceFromColumn(baseRow, x + width);
|
|
18
|
-
|
|
87
|
+
const styledLeft = shouldDim ? dimBackdropRow(leftPrefix) : leftPrefix;
|
|
88
|
+
const styledRight = shouldDim ? dimBackdropRow(rightSuffix) : rightSuffix;
|
|
89
|
+
rows[r] = `${styledLeft}${cardChunk}${styledRight}`;
|
|
19
90
|
}
|
|
20
91
|
return { rows, layout: { x, y: stageTop + y, width, count } };
|
|
21
92
|
}
|
|
@@ -1,30 +1,123 @@
|
|
|
1
1
|
import { padEnd, truncate, visibleWidth } from './text.js';
|
|
2
2
|
import { sliceFromColumn } from './turnRail.js';
|
|
3
|
+
// @ts-expect-error theme has no TypeScript declarations yet
|
|
4
|
+
import { HAS_COLOR } from './theme.js';
|
|
5
|
+
|
|
6
|
+
export interface MessageBounds {
|
|
7
|
+
startRow: number;
|
|
8
|
+
endRow: number;
|
|
9
|
+
textLength?: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface MessageActionPlacementOptions {
|
|
13
|
+
messageBounds?: MessageBounds | null;
|
|
14
|
+
dimBackdrop?: boolean;
|
|
15
|
+
}
|
|
3
16
|
|
|
4
17
|
export interface MessageActionPlacement {
|
|
5
18
|
rows: string[];
|
|
6
19
|
layout: { x: number; y: number; width: number; count: number } | null;
|
|
7
20
|
}
|
|
8
21
|
|
|
9
|
-
|
|
22
|
+
function dimBackdropRow(row: string): string {
|
|
23
|
+
if (!row || !row.trim()) return row;
|
|
24
|
+
return `\x1b[2m${row.replace(/\x1b\[0m/g, '\x1b[0m\x1b[2m')}\x1b[0m`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Overlay a message action menu in the transcript viewport with adaptive,
|
|
29
|
+
* context-aware positioning and elevated backdrop isolation.
|
|
30
|
+
*/
|
|
10
31
|
export function placeMessageActionPanel(
|
|
11
|
-
viewportRows: string[],
|
|
12
|
-
|
|
32
|
+
viewportRows: string[],
|
|
33
|
+
panel: string[],
|
|
34
|
+
contentWidth: number,
|
|
35
|
+
stageTop: number,
|
|
36
|
+
anchorY: number | null,
|
|
37
|
+
count: number,
|
|
38
|
+
options?: MessageActionPlacementOptions
|
|
13
39
|
): MessageActionPlacement {
|
|
14
40
|
if (!panel.length || viewportRows.length < panel.length || contentWidth < 8) {
|
|
15
41
|
return { rows: viewportRows, layout: null };
|
|
16
42
|
}
|
|
43
|
+
|
|
44
|
+
const totalRows = viewportRows.length;
|
|
45
|
+
const panelHeight = panel.length;
|
|
17
46
|
const width = Math.min(contentWidth, Math.max(...panel.map(visibleWidth)));
|
|
18
47
|
const x = Math.max(0, Math.floor((contentWidth - width) / 2));
|
|
19
|
-
|
|
20
|
-
|
|
48
|
+
|
|
49
|
+
// Vertical constraints and comfortable ergonomic margins
|
|
50
|
+
const maxAllowedY = totalRows - panelHeight;
|
|
51
|
+
const topMargin = Math.max(1, Math.floor(totalRows * 0.05));
|
|
52
|
+
const bottomMargin = Math.max(1, Math.min(3, Math.floor(totalRows * 0.10)));
|
|
53
|
+
|
|
54
|
+
// Optical focal center of the transcript viewport (38% to 42% down reads as eye-level natural center)
|
|
55
|
+
const opticalCenterY = Math.max(topMargin, Math.floor(maxAllowedY * 0.40));
|
|
56
|
+
|
|
57
|
+
let targetY: number;
|
|
58
|
+
|
|
59
|
+
if (options?.messageBounds) {
|
|
60
|
+
const { startRow, endRow } = options.messageBounds;
|
|
61
|
+
const msgTop = Math.max(0, Math.min(totalRows - 1, startRow));
|
|
62
|
+
const msgBottom = Math.max(0, Math.min(totalRows - 1, endRow));
|
|
63
|
+
const msgCenter = Math.floor((msgTop + msgBottom) / 2);
|
|
64
|
+
|
|
65
|
+
// If message is near the bottom of viewport (bottom rows or starting below the max panel top):
|
|
66
|
+
// Never squash the popup against the bottom composer! Float upward into the clear reading zone.
|
|
67
|
+
if (msgBottom >= totalRows - 3 || msgTop >= maxAllowedY - 1) {
|
|
68
|
+
if (msgTop >= panelHeight + topMargin) {
|
|
69
|
+
// Float directly above the message if room permits, biased towards optical center
|
|
70
|
+
const floatAbove = msgTop - panelHeight;
|
|
71
|
+
targetY = Math.max(topMargin, Math.min(floatAbove, opticalCenterY + 2));
|
|
72
|
+
} else {
|
|
73
|
+
// Message spans the bottom or is tight: place at the viewport optical center
|
|
74
|
+
targetY = opticalCenterY;
|
|
75
|
+
}
|
|
76
|
+
} else if (msgTop <= topMargin + 1) {
|
|
77
|
+
// Message is at the very top: place with comfortable top margin
|
|
78
|
+
targetY = Math.max(topMargin, Math.min(maxAllowedY - bottomMargin, msgCenter - Math.floor(panelHeight / 2)));
|
|
79
|
+
} else {
|
|
80
|
+
// Message is in the middle: center around message visual mass, softly blended with optical center
|
|
81
|
+
const msgIdealY = msgCenter - Math.floor(panelHeight / 2);
|
|
82
|
+
targetY = Math.round(0.75 * msgIdealY + 0.25 * opticalCenterY);
|
|
83
|
+
}
|
|
84
|
+
} else if (anchorY !== null) {
|
|
85
|
+
const anchor = anchorY - stageTop;
|
|
86
|
+
if (anchor >= totalRows - 2) {
|
|
87
|
+
// Click at the extreme bottom edge: float upward into the reading zone
|
|
88
|
+
targetY = Math.max(topMargin, Math.min(maxAllowedY - bottomMargin, opticalCenterY + 2));
|
|
89
|
+
} else {
|
|
90
|
+
// Standard anchor centering
|
|
91
|
+
targetY = anchor - Math.floor(panelHeight / 2);
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
targetY = opticalCenterY;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const y = Math.max(0, Math.min(maxAllowedY, targetY));
|
|
98
|
+
const shouldDim = options?.dimBackdrop === true;
|
|
21
99
|
const rows = viewportRows.slice();
|
|
22
|
-
|
|
23
|
-
|
|
100
|
+
|
|
101
|
+
for (let r = 0; r < rows.length; r++) {
|
|
102
|
+
const isPanelRow = r >= y && r < y + panelHeight;
|
|
103
|
+
if (!isPanelRow) {
|
|
104
|
+
if (shouldDim) {
|
|
105
|
+
rows[r] = dimBackdropRow(rows[r] ?? '');
|
|
106
|
+
}
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const panelIdx = r - y;
|
|
111
|
+
const baseRow = rows[r] ?? '';
|
|
24
112
|
const leftPrefix = padEnd(truncate(baseRow, x, ''), x);
|
|
25
|
-
const cardChunk = padEnd(truncate(panel[
|
|
113
|
+
const cardChunk = padEnd(truncate(panel[panelIdx] ?? '', width, ''), width);
|
|
26
114
|
const rightSuffix = sliceFromColumn(baseRow, x + width);
|
|
27
|
-
|
|
115
|
+
|
|
116
|
+
const styledLeft = shouldDim ? dimBackdropRow(leftPrefix) : leftPrefix;
|
|
117
|
+
const styledRight = shouldDim ? dimBackdropRow(rightSuffix) : rightSuffix;
|
|
118
|
+
|
|
119
|
+
rows[r] = `${styledLeft}${cardChunk}${styledRight}`;
|
|
28
120
|
}
|
|
121
|
+
|
|
29
122
|
return { rows, layout: { x, y: stageTop + y, width, count } };
|
|
30
123
|
}
|
|
@@ -6,22 +6,25 @@ import { writeClipboardSync } from './clipboardSync.js';
|
|
|
6
6
|
import { registerStageConsoleGuard, setTransientNotice } from './consoleGuard.js';
|
|
7
7
|
import { detectLinkAtPoint, openDetectedLink } from './smartLinkClick.js';
|
|
8
8
|
import { sidebarVisible, sessionMainWidth } from './sessionSidebar.js';
|
|
9
|
-
import { stripAnsi, truncate, padEnd } from './text.js';
|
|
10
|
-
// @ts-expect-error Legacy overlay has no declaration yet.
|
|
9
|
+
import { stripAnsi, truncate, padEnd, visibleWidth } from './text.js';
|
|
11
10
|
import { Layer } from './overlay.js';
|
|
11
|
+
import {} from './messageActionPlacement.js';
|
|
12
12
|
// @ts-expect-error Legacy theme has no declaration yet.
|
|
13
|
-
import { paint, bold, fill } from './theme.js';
|
|
13
|
+
import { paint, bold, dim, fill } from './theme.js';
|
|
14
14
|
/** Multi-action message menu overlay supporting Copy, Fork, and Revert. */
|
|
15
15
|
export class MessageActionsLayer extends Layer {
|
|
16
16
|
messageActions = true;
|
|
17
17
|
actionLayout = null;
|
|
18
18
|
anchorY;
|
|
19
|
+
messageBounds = null;
|
|
20
|
+
borderRole = 'muted';
|
|
21
|
+
surfaceRole = 'surfaceHi';
|
|
19
22
|
items;
|
|
20
23
|
list;
|
|
21
24
|
onPick;
|
|
22
25
|
settled = false;
|
|
23
26
|
constructor(items, onPick, anchorY = null) {
|
|
24
|
-
super({ title: 'Message Actions', width:
|
|
27
|
+
super({ title: 'Message Actions', width: 64, height: items.length + 2, footer: '↑↓ move · enter select · esc close' });
|
|
25
28
|
this.items = items;
|
|
26
29
|
this.onPick = onPick;
|
|
27
30
|
this.anchorY = anchorY;
|
|
@@ -32,14 +35,29 @@ export class MessageActionsLayer extends Layer {
|
|
|
32
35
|
};
|
|
33
36
|
}
|
|
34
37
|
preferredHeight() { return this.items.length + 2; }
|
|
38
|
+
preferredWidth(maxWidth) {
|
|
39
|
+
const maxItemContent = this.items.reduce((max, item) => {
|
|
40
|
+
const labelW = visibleWidth(`▸ ${item.label}`);
|
|
41
|
+
const descW = item.description ? visibleWidth(item.description) + 4 : 0;
|
|
42
|
+
return Math.max(max, labelW + descW);
|
|
43
|
+
}, 0);
|
|
44
|
+
const wanted = Math.max(48, maxItemContent + 6);
|
|
45
|
+
return Math.max(36, Math.min(maxWidth, wanted));
|
|
46
|
+
}
|
|
35
47
|
body(width) {
|
|
48
|
+
const labelWidth = this.items.reduce((max, item) => Math.max(max, visibleWidth(`▸ ${item.label}`)), 0);
|
|
36
49
|
return this.items.map((item, index) => {
|
|
37
50
|
const selected = index === this.list.selected;
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
51
|
+
const rawLabel = `${selected ? '▸' : ' '} ${item.label}`;
|
|
52
|
+
const pad = ' '.repeat(Math.max(0, labelWidth - visibleWidth(rawLabel)));
|
|
53
|
+
const styledLabel = selected
|
|
54
|
+
? `${paint('accent', bold(rawLabel))}${pad}`
|
|
55
|
+
: `${paint('ink', rawLabel)}${pad}`;
|
|
56
|
+
const descBudget = Math.max(0, width - labelWidth - 2);
|
|
57
|
+
const description = item.description && descBudget > 3
|
|
58
|
+
? ` ${dim(truncate(item.description, descBudget, '…'))}`
|
|
59
|
+
: '';
|
|
60
|
+
return truncate(`${styledLabel}${description}`, width, '…');
|
|
43
61
|
});
|
|
44
62
|
}
|
|
45
63
|
key(event) {
|
|
@@ -294,6 +312,21 @@ export function openMessageActions(host, loop, marker, anchorY = null) {
|
|
|
294
312
|
]
|
|
295
313
|
: [])
|
|
296
314
|
];
|
|
315
|
+
let messageBounds = null;
|
|
316
|
+
if (host.surface?.viewport && host.surface?.transcript) {
|
|
317
|
+
const flat = host.surface.transcript.flatten(host.surface.viewport.width);
|
|
318
|
+
const mIdx = flat.markers.findIndex(m => m.id === marker.id);
|
|
319
|
+
if (mIdx >= 0) {
|
|
320
|
+
const nextM = flat.markers[mIdx + 1];
|
|
321
|
+
const rawStart = marker.row;
|
|
322
|
+
const rawEnd = nextM ? nextM.row - 1 : flat.rows.length - 1;
|
|
323
|
+
const visible = Math.max(0, Math.min(host.surface.viewport.height, flat.rows.length - host.surface.viewport.scrollTop));
|
|
324
|
+
const padding = host.surface.viewport.height - visible;
|
|
325
|
+
const startRow = rawStart - host.surface.viewport.scrollTop + padding;
|
|
326
|
+
const endRow = rawEnd - host.surface.viewport.scrollTop + padding;
|
|
327
|
+
messageBounds = { startRow, endRow, textLength: text.length };
|
|
328
|
+
}
|
|
329
|
+
}
|
|
297
330
|
const layer = new MessageActionsLayer(options, (choice) => {
|
|
298
331
|
if (host.surface) {
|
|
299
332
|
host.surface.hoveredMessageFrameId = null;
|
|
@@ -367,6 +400,7 @@ export function openMessageActions(host, loop, marker, anchorY = null) {
|
|
|
367
400
|
}
|
|
368
401
|
host.scheduleDraw();
|
|
369
402
|
}, anchorY);
|
|
403
|
+
layer.messageBounds = messageBounds;
|
|
370
404
|
host.openLayer(layer);
|
|
371
405
|
}
|
|
372
406
|
/** Mouse selection for the small message menu; other dialogs retain their own input handling. */
|
|
@@ -12,11 +12,11 @@ import { writeClipboardSync } from './clipboardSync.js';
|
|
|
12
12
|
import { registerStageConsoleGuard, setTransientNotice } from './consoleGuard.js';
|
|
13
13
|
import { detectLinkAtPoint, openDetectedLink } from './smartLinkClick.js';
|
|
14
14
|
import { sidebarVisible, sessionMainWidth } from './sessionSidebar.js';
|
|
15
|
-
import { stripAnsi, truncate, padEnd } from './text.js';
|
|
16
|
-
// @ts-expect-error Legacy overlay has no declaration yet.
|
|
15
|
+
import { stripAnsi, truncate, padEnd, visibleWidth } from './text.js';
|
|
17
16
|
import { Layer } from './overlay.js';
|
|
17
|
+
import { type MessageBounds } from './messageActionPlacement.js';
|
|
18
18
|
// @ts-expect-error Legacy theme has no declaration yet.
|
|
19
|
-
import { paint, bold, fill } from './theme.js';
|
|
19
|
+
import { paint, bold, dim, fill } from './theme.js';
|
|
20
20
|
|
|
21
21
|
export interface MessageMarker {
|
|
22
22
|
id: number;
|
|
@@ -58,21 +58,19 @@ export interface MessageAction {
|
|
|
58
58
|
|
|
59
59
|
/** Multi-action message menu overlay supporting Copy, Fork, and Revert. */
|
|
60
60
|
export class MessageActionsLayer extends Layer {
|
|
61
|
-
declare title: string;
|
|
62
|
-
declare footer: string;
|
|
63
|
-
declare width: number;
|
|
64
|
-
declare height: number;
|
|
65
|
-
declare cursor: null;
|
|
66
61
|
readonly messageActions = true;
|
|
67
62
|
actionLayout: { x: number; y: number; width: number; count: number } | null = null;
|
|
68
63
|
anchorY: number | null;
|
|
64
|
+
messageBounds: MessageBounds | null = null;
|
|
65
|
+
override readonly borderRole = 'muted';
|
|
66
|
+
override readonly surfaceRole = 'surfaceHi';
|
|
69
67
|
readonly items: MessageAction[];
|
|
70
68
|
readonly list: { filtered: MessageAction[]; selected: number; moveTo: (index: number, rows?: number) => void };
|
|
71
69
|
private readonly onPick: (choice: MessageAction | null) => void;
|
|
72
70
|
private settled = false;
|
|
73
71
|
|
|
74
72
|
constructor(items: MessageAction[], onPick: (choice: MessageAction | null) => void, anchorY: number | null = null) {
|
|
75
|
-
super({ title: 'Message Actions', width:
|
|
73
|
+
super({ title: 'Message Actions', width: 64, height: items.length + 2, footer: '↑↓ move · enter select · esc close' });
|
|
76
74
|
this.items = items;
|
|
77
75
|
this.onPick = onPick;
|
|
78
76
|
this.anchorY = anchorY;
|
|
@@ -83,20 +81,39 @@ export class MessageActionsLayer extends Layer {
|
|
|
83
81
|
};
|
|
84
82
|
}
|
|
85
83
|
|
|
86
|
-
preferredHeight(): number { return this.items.length + 2; }
|
|
84
|
+
override preferredHeight(): number { return this.items.length + 2; }
|
|
87
85
|
|
|
88
|
-
|
|
86
|
+
preferredWidth(maxWidth: number): number {
|
|
87
|
+
const maxItemContent = this.items.reduce((max, item) => {
|
|
88
|
+
const labelW = visibleWidth(`▸ ${item.label}`);
|
|
89
|
+
const descW = item.description ? visibleWidth(item.description) + 4 : 0;
|
|
90
|
+
return Math.max(max, labelW + descW);
|
|
91
|
+
}, 0);
|
|
92
|
+
const wanted = Math.max(48, maxItemContent + 6);
|
|
93
|
+
return Math.max(36, Math.min(maxWidth, wanted));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
override body(width: number): string[] {
|
|
97
|
+
const labelWidth = this.items.reduce(
|
|
98
|
+
(max, item) => Math.max(max, visibleWidth(`▸ ${item.label}`)),
|
|
99
|
+
0
|
|
100
|
+
);
|
|
89
101
|
return this.items.map((item, index) => {
|
|
90
102
|
const selected = index === this.list.selected;
|
|
91
|
-
const
|
|
92
|
-
const
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
103
|
+
const rawLabel = `${selected ? '▸' : ' '} ${item.label}`;
|
|
104
|
+
const pad = ' '.repeat(Math.max(0, labelWidth - visibleWidth(rawLabel)));
|
|
105
|
+
const styledLabel = selected
|
|
106
|
+
? `${paint('accent', bold(rawLabel))}${pad}`
|
|
107
|
+
: `${paint('ink', rawLabel)}${pad}`;
|
|
108
|
+
const descBudget = Math.max(0, width - labelWidth - 2);
|
|
109
|
+
const description = item.description && descBudget > 3
|
|
110
|
+
? ` ${dim(truncate(item.description, descBudget, '…'))}`
|
|
111
|
+
: '';
|
|
112
|
+
return truncate(`${styledLabel}${description}`, width, '…');
|
|
96
113
|
});
|
|
97
114
|
}
|
|
98
115
|
|
|
99
|
-
key(event: { name: string; ctrl?: boolean; alt?: boolean }): string {
|
|
116
|
+
override key(event: { name: string; ctrl?: boolean; alt?: boolean }): string {
|
|
100
117
|
if (event.name === 'escape') {
|
|
101
118
|
this.settled = true;
|
|
102
119
|
this.onPick(null);
|
|
@@ -364,6 +381,22 @@ export function openMessageActions(host: MessageHost, loop: MessageLoop, marker:
|
|
|
364
381
|
: [])
|
|
365
382
|
];
|
|
366
383
|
|
|
384
|
+
let messageBounds: MessageBounds | null = null;
|
|
385
|
+
if (host.surface?.viewport && host.surface?.transcript) {
|
|
386
|
+
const flat = host.surface.transcript.flatten(host.surface.viewport.width);
|
|
387
|
+
const mIdx = flat.markers.findIndex(m => m.id === marker.id);
|
|
388
|
+
if (mIdx >= 0) {
|
|
389
|
+
const nextM = flat.markers[mIdx + 1];
|
|
390
|
+
const rawStart = marker.row;
|
|
391
|
+
const rawEnd = nextM ? nextM.row - 1 : flat.rows.length - 1;
|
|
392
|
+
const visible = Math.max(0, Math.min(host.surface.viewport.height, flat.rows.length - host.surface.viewport.scrollTop));
|
|
393
|
+
const padding = host.surface.viewport.height - visible;
|
|
394
|
+
const startRow = rawStart - host.surface.viewport.scrollTop + padding;
|
|
395
|
+
const endRow = rawEnd - host.surface.viewport.scrollTop + padding;
|
|
396
|
+
messageBounds = { startRow, endRow, textLength: text.length };
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
367
400
|
const layer = new MessageActionsLayer(options, (choice) => {
|
|
368
401
|
if (host.surface) {
|
|
369
402
|
host.surface.hoveredMessageFrameId = null;
|
|
@@ -439,6 +472,7 @@ export function openMessageActions(host: MessageHost, loop: MessageLoop, marker:
|
|
|
439
472
|
|
|
440
473
|
host.scheduleDraw();
|
|
441
474
|
}, anchorY);
|
|
475
|
+
layer.messageBounds = messageBounds;
|
|
442
476
|
host.openLayer(layer);
|
|
443
477
|
}
|
|
444
478
|
|