@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/turnRail.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { truncate, visibleWidth, wrapBlock, stripAnsi, padEnd } from './text.js';
|
|
1
|
+
import { truncate, visibleWidth, wrapBlock, stripAnsi, padEnd, safeDisplay } from './text.js';
|
|
2
2
|
// @ts-expect-error untyped local TUI theme
|
|
3
3
|
import { paint, bold, dim, GLYPHS } from './theme.js';
|
|
4
4
|
|
|
@@ -11,6 +11,8 @@ export interface SessionTurn {
|
|
|
11
11
|
formattedDate: string;
|
|
12
12
|
frameId: number;
|
|
13
13
|
startRow: number;
|
|
14
|
+
promptRow?: number;
|
|
15
|
+
transcriptHeight?: number;
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
export interface TurnRailLayout {
|
|
@@ -26,6 +28,7 @@ export interface TurnRailLayout {
|
|
|
26
28
|
export function formatTurnTimestamp(ts: number): string {
|
|
27
29
|
if (!ts || !Number.isFinite(ts)) return '';
|
|
28
30
|
const date = new Date(ts);
|
|
31
|
+
if (!Number.isFinite(date.getTime())) return '';
|
|
29
32
|
const now = new Date();
|
|
30
33
|
const sameDay = date.getFullYear() === now.getFullYear() &&
|
|
31
34
|
date.getMonth() === now.getMonth() &&
|
|
@@ -57,6 +60,7 @@ export function collectSessionTurns(transcript: any, contentWidth = 80): Session
|
|
|
57
60
|
}
|
|
58
61
|
const flat = typeof transcript.flatten === 'function' ? transcript.flatten(contentWidth) : null;
|
|
59
62
|
const markers: Array<{ id: number; row: number; kind: string }> = flat?.markers || [];
|
|
63
|
+
const transcriptHeight = Array.isArray(flat?.rows) ? flat.rows.length : undefined;
|
|
60
64
|
const frames: any[] = transcript.frames;
|
|
61
65
|
|
|
62
66
|
const userFrames: Array<{ frame: any; index: number }> = [];
|
|
@@ -95,8 +99,20 @@ export function collectSessionTurns(transcript: any, contentWidth = 80): Session
|
|
|
95
99
|
}
|
|
96
100
|
}
|
|
97
101
|
|
|
98
|
-
const
|
|
102
|
+
const markerIdx = markers.findIndex((m) => m.id === frame.id);
|
|
103
|
+
const marker = markerIdx >= 0 ? markers[markerIdx] : undefined;
|
|
99
104
|
const startRow = marker ? marker.row : 0;
|
|
105
|
+
const nextMarkerRow = markerIdx >= 0 && markerIdx + 1 < markers.length
|
|
106
|
+
? markers[markerIdx + 1]!.row
|
|
107
|
+
: (Array.isArray(flat?.rows) ? flat.rows.length : 0);
|
|
108
|
+
let promptRow = startRow;
|
|
109
|
+
if (Array.isArray(flat?.rows) && startRow + 1 < nextMarkerRow && startRow + 1 < flat.rows.length) {
|
|
110
|
+
const firstLine = stripAnsi(String(flat.rows[startRow] ?? '')).trim();
|
|
111
|
+
const secondLine = stripAnsi(String(flat.rows[startRow + 1] ?? '')).trim();
|
|
112
|
+
if (firstLine === '' && secondLine !== '') {
|
|
113
|
+
promptRow = startRow + 1;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
100
116
|
|
|
101
117
|
turns.push({
|
|
102
118
|
turnIndex,
|
|
@@ -106,7 +122,9 @@ export function collectSessionTurns(transcript: any, contentWidth = 80): Session
|
|
|
106
122
|
timestamp: frame.ts || Date.now(),
|
|
107
123
|
formattedDate: formatTurnTimestamp(frame.ts || Date.now()),
|
|
108
124
|
frameId: frame.id,
|
|
109
|
-
startRow
|
|
125
|
+
startRow,
|
|
126
|
+
promptRow,
|
|
127
|
+
...(transcriptHeight !== undefined ? { transcriptHeight } : {})
|
|
110
128
|
});
|
|
111
129
|
}
|
|
112
130
|
|
|
@@ -126,12 +144,14 @@ export function resolveActiveTurnIndex(
|
|
|
126
144
|
if (isAtBottom) {
|
|
127
145
|
return turns[turns.length - 1]!.turnIndex;
|
|
128
146
|
}
|
|
129
|
-
|
|
147
|
+
const safeScrollTop = Number.isFinite(scrollTop) ? scrollTop : 0;
|
|
148
|
+
const safeViewportHeight = Number.isFinite(viewportHeight) ? Math.max(0, viewportHeight) : 20;
|
|
149
|
+
if (safeScrollTop <= 0) {
|
|
130
150
|
return turns[0]!.turnIndex;
|
|
131
151
|
}
|
|
132
152
|
|
|
133
153
|
let active = turns[turns.length - 1]!.turnIndex;
|
|
134
|
-
const targetRow = Math.max(0,
|
|
154
|
+
const targetRow = Math.max(0, safeScrollTop + Math.floor(safeViewportHeight / 3));
|
|
135
155
|
for (let i = turns.length - 1; i >= 0; i--) {
|
|
136
156
|
const t = turns[i]!;
|
|
137
157
|
if (t.startRow <= targetRow) {
|
|
@@ -146,6 +166,8 @@ export function resolveActiveTurnIndex(
|
|
|
146
166
|
* ANSI-safe column slicing: skips the first startCol visible columns while preserving active styles.
|
|
147
167
|
*/
|
|
148
168
|
export function sliceFromColumn(source: string, startCol: number): string {
|
|
169
|
+
if (startCol === Number.POSITIVE_INFINITY) return '';
|
|
170
|
+
const targetCol = Number.isFinite(startCol) ? Math.max(0, Math.floor(startCol)) : 0;
|
|
149
171
|
let col = 0;
|
|
150
172
|
let index = 0;
|
|
151
173
|
let activeStyles = '';
|
|
@@ -157,7 +179,7 @@ export function sliceFromColumn(source: string, startCol: number): string {
|
|
|
157
179
|
|| rest.match(/^\x1b\[[0-?]*[ -/]*[@-~]/)
|
|
158
180
|
|| rest.match(/^\x1b[@-Z\\-_]/);
|
|
159
181
|
if (match) {
|
|
160
|
-
if (col <
|
|
182
|
+
if (col < targetCol) {
|
|
161
183
|
if (match[0] === '\x1b[0m' || match[0] === '\x1b[m') {
|
|
162
184
|
activeStyles = '';
|
|
163
185
|
} else if (match[0].startsWith('\x1b[')) {
|
|
@@ -169,7 +191,7 @@ export function sliceFromColumn(source: string, startCol: number): string {
|
|
|
169
191
|
}
|
|
170
192
|
}
|
|
171
193
|
|
|
172
|
-
if (col >=
|
|
194
|
+
if (col >= targetCol) {
|
|
173
195
|
const tail = source.slice(index);
|
|
174
196
|
// Ensure any OSC 8 hyperlink opened inside `tail` is closed at the end of the slice
|
|
175
197
|
let openOsc8Term = '';
|
|
@@ -203,27 +225,37 @@ export function buildTurnRailCells(
|
|
|
203
225
|
turns: SessionTurn[],
|
|
204
226
|
height: number,
|
|
205
227
|
activeTurnIndex: number,
|
|
206
|
-
hoveredTurnIndex: number | null
|
|
228
|
+
hoveredTurnIndex: number | null,
|
|
229
|
+
scrollTop?: number
|
|
207
230
|
): { cells: string[]; layout: { dotRows: Map<number, number>; rowToTurn: Map<number, number> } } {
|
|
208
|
-
const
|
|
231
|
+
const safeHeight = Number.isFinite(height) ? Math.max(0, Math.floor(height)) : 0;
|
|
232
|
+
const cells: string[] = new Array(safeHeight).fill(' ');
|
|
209
233
|
const dotRows = new Map<number, number>();
|
|
210
234
|
const rowToTurn = new Map<number, number>();
|
|
211
235
|
|
|
212
|
-
if (turns.length === 0 ||
|
|
236
|
+
if (turns.length === 0 || safeHeight <= 0) {
|
|
213
237
|
return { cells, layout: { dotRows, rowToTurn } };
|
|
214
238
|
}
|
|
215
239
|
|
|
216
240
|
const count = turns.length;
|
|
241
|
+
const rawTranscriptHeight = turns[0]?.transcriptHeight;
|
|
242
|
+
const hasTranscriptHeight = typeof rawTranscriptHeight === 'number' &&
|
|
243
|
+
Number.isFinite(rawTranscriptHeight) &&
|
|
244
|
+
rawTranscriptHeight > 0;
|
|
245
|
+
const topOffset = hasTranscriptHeight && rawTranscriptHeight < safeHeight
|
|
246
|
+
? safeHeight - Math.floor(rawTranscriptHeight)
|
|
247
|
+
: 0;
|
|
248
|
+
const activeHeight = Math.max(1, safeHeight - topOffset);
|
|
217
249
|
// Dense imported histories may contain hundreds of turns. Show a measured
|
|
218
250
|
// set of quiet milestones, while always retaining active/hovered endpoints.
|
|
219
251
|
// All turn objects are preserved for keyboard navigation and preview.
|
|
220
|
-
const quietStep = count > Math.max(16, Math.floor(
|
|
221
|
-
? Math.max(2, Math.ceil(count / Math.max(12, Math.floor(
|
|
252
|
+
const quietStep = count > Math.max(16, Math.floor(activeHeight / 2))
|
|
253
|
+
? Math.max(2, Math.ceil(count / Math.max(12, Math.floor(activeHeight / 3))))
|
|
222
254
|
: 1;
|
|
223
255
|
// If count fits comfortably, stack consecutive dots centered or upper-aligned
|
|
224
|
-
const startRow = count <=
|
|
225
|
-
? Math.max(0, Math.floor((
|
|
226
|
-
:
|
|
256
|
+
const startRow = count <= activeHeight
|
|
257
|
+
? topOffset + Math.max(0, Math.floor((activeHeight - count) / 3))
|
|
258
|
+
: topOffset;
|
|
227
259
|
|
|
228
260
|
for (let i = 0; i < count; i++) {
|
|
229
261
|
const turn = turns[i];
|
|
@@ -231,29 +263,52 @@ export function buildTurnRailCells(
|
|
|
231
263
|
const turnNum = turn.turnIndex;
|
|
232
264
|
|
|
233
265
|
let rowIdx: number;
|
|
234
|
-
if (count
|
|
266
|
+
if (count === 1 && hasTranscriptHeight) {
|
|
267
|
+
const rawAnchor = Number.isFinite(turn.promptRow) ? turn.promptRow! : turn.startRow;
|
|
268
|
+
const anchorRow = Number.isFinite(rawAnchor) ? Math.max(0, Math.floor(rawAnchor)) : 0;
|
|
269
|
+
if (topOffset > 0) {
|
|
270
|
+
rowIdx = topOffset + anchorRow;
|
|
271
|
+
} else if (typeof scrollTop === 'number' && Number.isFinite(scrollTop)) {
|
|
272
|
+
const safeScrollTop = Math.max(0, Math.floor(scrollTop));
|
|
273
|
+
if (anchorRow >= safeScrollTop && anchorRow < safeScrollTop + safeHeight) {
|
|
274
|
+
rowIdx = anchorRow - safeScrollTop;
|
|
275
|
+
} else if (anchorRow < safeScrollTop) {
|
|
276
|
+
rowIdx = 0;
|
|
277
|
+
} else {
|
|
278
|
+
rowIdx = safeHeight - 1;
|
|
279
|
+
}
|
|
280
|
+
} else {
|
|
281
|
+
rowIdx = Math.round((anchorRow / Math.max(1, Math.floor(rawTranscriptHeight) - 1)) * (safeHeight - 1));
|
|
282
|
+
}
|
|
283
|
+
} else if (count <= activeHeight) {
|
|
235
284
|
rowIdx = startRow + i;
|
|
236
285
|
} else {
|
|
237
|
-
rowIdx = Math.round((i / (count - 1)) * (
|
|
286
|
+
rowIdx = topOffset + Math.round((i / (count - 1)) * (activeHeight - 1));
|
|
238
287
|
}
|
|
239
|
-
rowIdx = Math.max(
|
|
288
|
+
rowIdx = Math.max(topOffset, Math.min(safeHeight - 1, rowIdx));
|
|
240
289
|
|
|
241
290
|
dotRows.set(turnNum, rowIdx);
|
|
242
291
|
|
|
243
292
|
const isHovered = hoveredTurnIndex === turnNum;
|
|
244
293
|
const isActive = activeTurnIndex === turnNum;
|
|
245
294
|
const showQuiet = quietStep === 1 || i === 0 || i === count - 1 || i % quietStep === 0;
|
|
246
|
-
|
|
295
|
+
const rowHasHovered = cells[rowIdx]?.includes('230;235;245m');
|
|
296
|
+
const rowHasDot = cells[rowIdx]?.includes('●');
|
|
247
297
|
|
|
248
298
|
if (isHovered) {
|
|
249
299
|
// Hovered dot: bright silver highlighted circle
|
|
250
300
|
cells[rowIdx] = '\x1b[1m\x1b[38;2;230;235;245m●\x1b[0m';
|
|
251
|
-
|
|
301
|
+
rowToTurn.set(rowIdx, turnNum);
|
|
302
|
+
} else if (isActive && !rowHasHovered) {
|
|
252
303
|
// Active / current turn: bright white circle
|
|
253
304
|
cells[rowIdx] = '\x1b[1m\x1b[38;2;250;250;250m●\x1b[0m';
|
|
254
|
-
|
|
305
|
+
rowToTurn.set(rowIdx, turnNum);
|
|
306
|
+
} else if (showQuiet && !rowHasDot) {
|
|
255
307
|
// Muted inactive turns: sparse gray dot in long sessions
|
|
256
308
|
cells[rowIdx] = '\x1b[38;2;115;115;120m•\x1b[0m';
|
|
309
|
+
if (!rowToTurn.has(rowIdx)) {
|
|
310
|
+
rowToTurn.set(rowIdx, turnNum);
|
|
311
|
+
}
|
|
257
312
|
}
|
|
258
313
|
}
|
|
259
314
|
|
|
@@ -267,7 +322,7 @@ export function buildTurnRailCells(
|
|
|
267
322
|
*/
|
|
268
323
|
export function formatPreviewCardMarkdown(raw: string): string {
|
|
269
324
|
if (!raw) return '';
|
|
270
|
-
let text = String(raw);
|
|
325
|
+
let text = safeDisplay(String(raw));
|
|
271
326
|
|
|
272
327
|
// Strip code block fences
|
|
273
328
|
text = text.replace(/```[a-zA-Z0-9_-]*\n?/g, ' ');
|
|
@@ -328,7 +383,9 @@ export function formatPreviewCardMarkdown(raw: string): string {
|
|
|
328
383
|
* - Footer: Left 'X of Y', Right timestamp
|
|
329
384
|
*/
|
|
330
385
|
export function renderTurnPreviewCard(turn: SessionTurn, maxCardWidth = 50): string[] {
|
|
331
|
-
const
|
|
386
|
+
const safeTurn: Partial<SessionTurn> = turn && typeof turn === 'object' ? turn : {};
|
|
387
|
+
const safeWidth = Number.isFinite(maxCardWidth) ? Math.floor(maxCardWidth) : 50;
|
|
388
|
+
const cardWidth = Math.max(38, Math.min(60, safeWidth));
|
|
332
389
|
const innerWidth = cardWidth - 4; // 2 border chars + 2 padding chars
|
|
333
390
|
|
|
334
391
|
const cardBg = '\x1b[48;2;28;28;32m';
|
|
@@ -336,7 +393,7 @@ export function renderTurnPreviewCard(turn: SessionTurn, maxCardWidth = 50): str
|
|
|
336
393
|
const reset = '\x1b[0m';
|
|
337
394
|
|
|
338
395
|
// Format header: User Prompt (bold primary) rendered cleanly without raw markdown, strictly flush-left with hang: 0
|
|
339
|
-
const rawPrompt = formatPreviewCardMarkdown(
|
|
396
|
+
const rawPrompt = formatPreviewCardMarkdown(safeTurn.userPrompt || 'User request');
|
|
340
397
|
const promptLines = wrapBlock(rawPrompt, innerWidth, { hang: 0 }).slice(0, 2);
|
|
341
398
|
if (promptLines.length === 2 && promptLines[1]) {
|
|
342
399
|
promptLines[1] = truncate(promptLines[1], innerWidth - 3, '...');
|
|
@@ -344,8 +401,8 @@ export function renderTurnPreviewCard(turn: SessionTurn, maxCardWidth = 50): str
|
|
|
344
401
|
|
|
345
402
|
// Format body: Assistant Summary (muted secondary) rendered cleanly without raw markdown, strictly flush-left with hang: 0
|
|
346
403
|
let bodyLines: string[] = [];
|
|
347
|
-
if (
|
|
348
|
-
const formattedSummary = formatPreviewCardMarkdown(
|
|
404
|
+
if (safeTurn.assistantSummary) {
|
|
405
|
+
const formattedSummary = formatPreviewCardMarkdown(safeTurn.assistantSummary);
|
|
349
406
|
bodyLines = wrapBlock(formattedSummary, innerWidth, { hang: 0 }).slice(0, 3);
|
|
350
407
|
if (bodyLines.length === 3 && bodyLines[2]) {
|
|
351
408
|
bodyLines[2] = truncate(bodyLines[2], innerWidth - 3, '...');
|
|
@@ -353,10 +410,14 @@ export function renderTurnPreviewCard(turn: SessionTurn, maxCardWidth = 50): str
|
|
|
353
410
|
}
|
|
354
411
|
|
|
355
412
|
// Format footer: 'X of Y' on left, timestamp on right
|
|
356
|
-
const
|
|
357
|
-
const
|
|
358
|
-
const
|
|
359
|
-
const
|
|
413
|
+
const turnNum = Number.isFinite(safeTurn.turnIndex) ? safeTurn.turnIndex : 1;
|
|
414
|
+
const totalTurns = Number.isFinite(safeTurn.totalTurns) ? safeTurn.totalTurns : 1;
|
|
415
|
+
const counterText = truncate(safeDisplay(`${turnNum} of ${totalTurns}`), innerWidth, '');
|
|
416
|
+
const rawDateText = safeDisplay(safeTurn.formattedDate || '');
|
|
417
|
+
const maxDateWidth = Math.max(0, innerWidth - visibleWidth(counterText) - 2);
|
|
418
|
+
const dateText = maxDateWidth > 0 ? truncate(rawDateText, maxDateWidth, '…') : '';
|
|
419
|
+
const footerSpace = Math.max(0, innerWidth - visibleWidth(counterText) - visibleWidth(dateText));
|
|
420
|
+
const footerLine = truncate(`${counterText}${' '.repeat(footerSpace)}${dateText}`, innerWidth, '');
|
|
360
421
|
|
|
361
422
|
// Assemble rows
|
|
362
423
|
const rows: string[] = [];
|
|
@@ -401,20 +462,39 @@ export function overlayTurnPreviewCard(
|
|
|
401
462
|
railX: number,
|
|
402
463
|
screenWidth: number
|
|
403
464
|
): string[] {
|
|
404
|
-
if (
|
|
465
|
+
if (!Array.isArray(viewportRows)) return [];
|
|
466
|
+
if (
|
|
467
|
+
!Array.isArray(cardRows) ||
|
|
468
|
+
cardRows.length === 0 ||
|
|
469
|
+
viewportRows.length === 0 ||
|
|
470
|
+
!Number.isFinite(anchorY) ||
|
|
471
|
+
!Number.isFinite(railX) ||
|
|
472
|
+
!Number.isFinite(screenWidth) ||
|
|
473
|
+
screenWidth <= 0
|
|
474
|
+
) {
|
|
475
|
+
return viewportRows;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
const safeAnchorY = Math.floor(anchorY);
|
|
479
|
+
const safeRailX = Math.max(0, Math.floor(railX));
|
|
480
|
+
const safeScreenWidth = Math.floor(screenWidth);
|
|
405
481
|
|
|
406
482
|
const cardWidth = visibleWidth(cardRows[0] || '');
|
|
407
483
|
// Clamp card placement horizontally: flush-left with transcript baseline at column 3
|
|
408
484
|
const cardSpacing = 2; // railX + 2 gives x = 3, perfectly flush left with transcript content
|
|
409
|
-
let x =
|
|
410
|
-
if (
|
|
411
|
-
x =
|
|
485
|
+
let x = safeRailX - cardWidth - 1;
|
|
486
|
+
if (safeRailX <= 4 && safeRailX + cardSpacing < safeScreenWidth) {
|
|
487
|
+
x = safeRailX + cardSpacing;
|
|
488
|
+
} else if (x < 0) {
|
|
489
|
+
x = Math.max(0, Math.min(safeScreenWidth - cardWidth - 1, safeRailX + cardSpacing));
|
|
412
490
|
}
|
|
413
491
|
|
|
492
|
+
const effectiveCardWidth = Math.max(1, Math.min(cardWidth, Math.max(1, safeScreenWidth - x)));
|
|
493
|
+
|
|
414
494
|
// Center vertically around anchorY
|
|
415
495
|
const startY = Math.max(
|
|
416
496
|
0,
|
|
417
|
-
Math.min(viewportRows.length - cardRows.length,
|
|
497
|
+
Math.min(viewportRows.length - cardRows.length, safeAnchorY - Math.floor(cardRows.length / 2))
|
|
418
498
|
);
|
|
419
499
|
|
|
420
500
|
const out = viewportRows.slice();
|
|
@@ -422,16 +502,19 @@ export function overlayTurnPreviewCard(
|
|
|
422
502
|
const targetY = startY + i;
|
|
423
503
|
if (targetY >= out.length) break;
|
|
424
504
|
const baseRow = out[targetY] || '';
|
|
425
|
-
const
|
|
505
|
+
const rawCardRow = cardRows[i] || '';
|
|
506
|
+
const cardRow = visibleWidth(rawCardRow) > effectiveCardWidth
|
|
507
|
+
? `${padEnd(truncate(rawCardRow, effectiveCardWidth, ''), effectiveCardWidth)}${rawCardRow.includes('\x1b[') ? '\x1b[0m' : ''}`
|
|
508
|
+
: rawCardRow;
|
|
426
509
|
|
|
427
510
|
// Composite cardRow onto baseRow at column x.
|
|
428
511
|
// To the left of the card, NEVER allow severed underlying characters (like '▸' or text) to leak!
|
|
429
512
|
// Maintain a perfectly clean, flush, symmetrical margin:
|
|
430
513
|
// Only preserve the rail dot (if present at railX) and whitespace padding up to column x.
|
|
431
514
|
let beforePart = '';
|
|
432
|
-
if (x <= 6 &&
|
|
515
|
+
if (x <= 6 && safeRailX <= 4 && x > safeRailX) {
|
|
433
516
|
const plainBase = stripAnsi(baseRow);
|
|
434
|
-
const dotChar = plainBase[
|
|
517
|
+
const dotChar = plainBase[safeRailX] || ' ';
|
|
435
518
|
const isDot = dotChar === '●' || dotChar === '•' || dotChar === '·';
|
|
436
519
|
let dotCell = ' ';
|
|
437
520
|
if (isDot) {
|
|
@@ -445,8 +528,8 @@ export function overlayTurnPreviewCard(
|
|
|
445
528
|
dotCell = dotChar;
|
|
446
529
|
}
|
|
447
530
|
}
|
|
448
|
-
const leadingSpace = ' '.repeat(Math.max(0,
|
|
449
|
-
const trailingSpace = ' '.repeat(Math.max(0, x -
|
|
531
|
+
const leadingSpace = ' '.repeat(Math.max(0, safeRailX));
|
|
532
|
+
const trailingSpace = ' '.repeat(Math.max(0, x - safeRailX - 1));
|
|
450
533
|
beforePart = `${leadingSpace}${dotCell}${trailingSpace}`;
|
|
451
534
|
} else {
|
|
452
535
|
beforePart = padEnd(truncate(baseRow, x, ''), x);
|
|
@@ -456,13 +539,16 @@ export function overlayTurnPreviewCard(
|
|
|
456
539
|
if (x <= 6) {
|
|
457
540
|
// For left-placed turn cards, preserve the right overview rail without severed text leaks
|
|
458
541
|
const rowLen = visibleWidth(baseRow);
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
542
|
+
if (rowLen > x + effectiveCardWidth) {
|
|
543
|
+
const rightCell = sliceFromColumn(baseRow, rowLen - 1);
|
|
544
|
+
const rightCellWidth = visibleWidth(rightCell);
|
|
545
|
+
const gap = Math.max(0, rowLen - x - effectiveCardWidth - rightCellWidth);
|
|
546
|
+
restOfRow = `${' '.repeat(gap)}${rightCell}`;
|
|
547
|
+
} else {
|
|
548
|
+
restOfRow = '';
|
|
549
|
+
}
|
|
464
550
|
} else {
|
|
465
|
-
restOfRow = sliceFromColumn(baseRow, x +
|
|
551
|
+
restOfRow = sliceFromColumn(baseRow, x + effectiveCardWidth);
|
|
466
552
|
}
|
|
467
553
|
out[targetY] = `${beforePart}${cardRow}${restOfRow}`;
|
|
468
554
|
}
|
|
@@ -475,6 +561,11 @@ export function isMouseMotion(sequence: string | undefined): boolean {
|
|
|
475
561
|
return Number.isFinite(code) && (code & 32) !== 0;
|
|
476
562
|
}
|
|
477
563
|
|
|
564
|
+
function redrawHost(host: any): void {
|
|
565
|
+
if (typeof host?.scheduleDraw === 'function') host.scheduleDraw();
|
|
566
|
+
else if (typeof host?.draw === 'function') host.draw();
|
|
567
|
+
}
|
|
568
|
+
|
|
478
569
|
/**
|
|
479
570
|
* Handle mouse interaction (hover and click) for the Turn Rail.
|
|
480
571
|
*/
|
|
@@ -483,15 +574,22 @@ export function handleTurnRailMouse(
|
|
|
483
574
|
surface: any,
|
|
484
575
|
host: any
|
|
485
576
|
): boolean {
|
|
486
|
-
if (
|
|
577
|
+
if (
|
|
578
|
+
!surface?.turnRailLayout ||
|
|
579
|
+
!event?.mouse ||
|
|
580
|
+
!Number.isFinite(event.mouse.x) ||
|
|
581
|
+
!Number.isFinite(event.mouse.y)
|
|
582
|
+
) {
|
|
583
|
+
return false;
|
|
584
|
+
}
|
|
487
585
|
const layout = surface.turnRailLayout;
|
|
488
|
-
const mouseX = event.mouse.x;
|
|
489
|
-
const mouseY = event.mouse.y;
|
|
490
|
-
const stageTop = layout.stageTop
|
|
586
|
+
const mouseX = Math.floor(event.mouse.x);
|
|
587
|
+
const mouseY = Math.floor(event.mouse.y);
|
|
588
|
+
const stageTop = Number.isFinite(layout.stageTop) ? Math.floor(layout.stageTop) : 0;
|
|
491
589
|
const relY = mouseY - stageTop;
|
|
492
590
|
|
|
493
591
|
// Rail hit box: if railX <= 4, check columns 0..5 (left margin); otherwise check [railX - 2, railX + 3]
|
|
494
|
-
|
|
592
|
+
let isRail = layout.railX <= 4
|
|
495
593
|
? (mouseX >= 0 && mouseX <= Math.max(5, layout.railX + 3))
|
|
496
594
|
: (mouseX >= layout.railX - 2 && mouseX <= layout.railX + 3);
|
|
497
595
|
|
|
@@ -524,6 +622,9 @@ export function handleTurnRailMouse(
|
|
|
524
622
|
}
|
|
525
623
|
}
|
|
526
624
|
|
|
625
|
+
// The preview partially overlaps the widened rail hit target. A pointer
|
|
626
|
+
// inside the card belongs to the card, including its left border.
|
|
627
|
+
if (isCard && layout.cardRect?.turnIndex === surface.hoveredTurnIndex) isRail = false;
|
|
527
628
|
const inHoverZone = isRail || isCard || isBridge;
|
|
528
629
|
|
|
529
630
|
if (!inHoverZone || relY < 0 || relY >= layout.viewportHeight) {
|
|
@@ -532,13 +633,14 @@ export function handleTurnRailMouse(
|
|
|
532
633
|
if (!surface._turnCardLeaveTimer) {
|
|
533
634
|
surface._turnCardLeaveTimer = setTimeout(() => {
|
|
534
635
|
surface._turnCardLeaveTimer = null;
|
|
636
|
+
if (surface.stage?.reserved === false) return;
|
|
535
637
|
if (surface.hoveredTurnIndex !== null && surface.hoveredTurnIndex !== undefined) {
|
|
536
638
|
surface.hoveredTurnIndex = null;
|
|
537
639
|
surface.hoveredTurnAnchorY = null;
|
|
538
|
-
|
|
539
|
-
else if (typeof host?.draw === 'function') host.draw();
|
|
640
|
+
redrawHost(host);
|
|
540
641
|
}
|
|
541
642
|
}, 120);
|
|
643
|
+
surface._turnCardLeaveTimer.unref?.();
|
|
542
644
|
}
|
|
543
645
|
}
|
|
544
646
|
return false;
|
|
@@ -559,13 +661,14 @@ export function handleTurnRailMouse(
|
|
|
559
661
|
let turnNum = isRail ? layout.rowToTurn?.get(relY) : ((isCard || isBridge) ? surface.hoveredTurnIndex : undefined);
|
|
560
662
|
let anchorY = relY;
|
|
561
663
|
|
|
562
|
-
//
|
|
563
|
-
|
|
664
|
+
// Nearest *visible* dot: the original dotRows includes every compressed
|
|
665
|
+
// turn, including invisible samples. Those must not replace group previews.
|
|
666
|
+
if (!turnNum && isRail && layout.rowToTurn && layout.rowToTurn.size > 0) {
|
|
564
667
|
let minDistance = Infinity;
|
|
565
668
|
let closestTurn: number | undefined;
|
|
566
669
|
let closestRow: number | undefined;
|
|
567
670
|
|
|
568
|
-
for (const [
|
|
671
|
+
for (const [row, tNum] of layout.rowToTurn.entries()) {
|
|
569
672
|
const dist = Math.abs(relY - row);
|
|
570
673
|
if (dist < minDistance) {
|
|
571
674
|
minDistance = dist;
|
|
@@ -582,26 +685,25 @@ export function handleTurnRailMouse(
|
|
|
582
685
|
|
|
583
686
|
if (turnNum) {
|
|
584
687
|
if (isMouseMotion(event.sequence)) {
|
|
585
|
-
//
|
|
586
|
-
//
|
|
587
|
-
if (host?.busy) {
|
|
588
|
-
if (surface.hoveredTurnIndex !== null && surface.hoveredTurnIndex !== undefined) {
|
|
589
|
-
surface.hoveredTurnIndex = null;
|
|
590
|
-
surface.hoveredTurnAnchorY = null;
|
|
591
|
-
if (typeof host?.scheduleDraw === 'function') host.scheduleDraw();
|
|
592
|
-
else if (typeof host?.draw === 'function') host.draw();
|
|
593
|
-
}
|
|
594
|
-
return true;
|
|
595
|
-
}
|
|
688
|
+
// Reading history is independent of ongoing agent work. Never disable
|
|
689
|
+
// the rail merely because a tool is running; previews are read-only.
|
|
596
690
|
if (surface.hoveredTurnIndex !== turnNum) {
|
|
691
|
+
surface.turnRailCardOffset = 0;
|
|
597
692
|
surface.hoveredTurnIndex = turnNum;
|
|
598
693
|
surface.hoveredTurnAnchorY = anchorY;
|
|
599
|
-
|
|
600
|
-
else if (typeof host?.draw === 'function') host.draw();
|
|
694
|
+
redrawHost(host);
|
|
601
695
|
}
|
|
602
696
|
return true;
|
|
603
697
|
}
|
|
604
698
|
if (event.mouse.button === 0 && event.mouse.pressed) {
|
|
699
|
+
// A compressed rail dot opens a timestamped group. Its individual
|
|
700
|
+
// entries are actual navigation targets, not a decorative tooltip.
|
|
701
|
+
if (isCard && layout.cardRect?.entries) {
|
|
702
|
+
const item = relY - layout.cardRect.y - layout.cardRect.entryStart;
|
|
703
|
+
const chosen = layout.cardRect.entries[item];
|
|
704
|
+
if (!chosen) return true; // Header/border clicks leave the chat alone.
|
|
705
|
+
turnNum = chosen.turnIndex;
|
|
706
|
+
}
|
|
605
707
|
const turns: SessionTurn[] = layout.turns || [];
|
|
606
708
|
const turn = turns.find((t: SessionTurn) => t.turnIndex === turnNum);
|
|
607
709
|
const isLatestTurn = turnNum === turns.length || (turn && turns.length > 0 && turn.turnIndex === turns[turns.length - 1]!.turnIndex);
|
|
@@ -623,6 +725,7 @@ export function handleTurnRailMouse(
|
|
|
623
725
|
surface._turnRailSuppressTimer = setTimeout(() => {
|
|
624
726
|
surface.turnRailHoverSuppressed = false;
|
|
625
727
|
}, 400);
|
|
728
|
+
surface._turnRailSuppressTimer.unref?.();
|
|
626
729
|
|
|
627
730
|
if (typeof host?.draw === 'function') host.draw();
|
|
628
731
|
else if (typeof host?.scheduleDraw === 'function') host.scheduleDraw();
|
|
@@ -631,8 +734,7 @@ export function handleTurnRailMouse(
|
|
|
631
734
|
} else if (surface.hoveredTurnIndex !== null && surface.hoveredTurnIndex !== undefined) {
|
|
632
735
|
surface.hoveredTurnIndex = null;
|
|
633
736
|
surface.hoveredTurnAnchorY = null;
|
|
634
|
-
|
|
635
|
-
else if (typeof host?.draw === 'function') host.draw();
|
|
737
|
+
redrawHost(host);
|
|
636
738
|
}
|
|
637
739
|
|
|
638
740
|
return false;
|