@causyne/agent 1.20.62 → 1.20.65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/package.json +1 -1
- package/src/acp/client.js +48 -0
- package/src/acp/client.ts +44 -0
- package/src/agentLoop.js +181 -11
- package/src/agentLoop.ts +184 -11
- package/src/approvalPolicy.js +19 -0
- package/src/approvalPolicy.ts +18 -0
- package/src/browser/causyneBrowser.js +34 -4
- package/src/browser/causyneBrowser.ts +32 -4
- package/src/cliMode.js +12 -28
- package/src/commands.js +33 -0
- package/src/decisionPolicy.js +18 -1
- package/src/decisionPolicy.ts +18 -1
- package/src/implementationPlan.js +26 -0
- package/src/implementationPlan.ts +25 -0
- package/src/observer/coldObserver.js +6 -1
- package/src/observer/coldObserver.ts +6 -1
- package/src/observer.js +24 -2
- package/src/observer.ts +24 -2
- package/src/providers/acp.js +2 -8
- package/src/providers/acp.ts +2 -8
- package/src/providers/antigravity.js +7 -10
- package/src/providers/antigravity.ts +7 -10
- package/src/smartToolsUse.js +1 -1
- package/src/smartToolsUse.ts +1 -1
- package/src/toolPacks.js +1 -1
- package/src/toolPacks.ts +1 -1
- package/src/tools/toolSelfRepair.js +51 -8
- package/src/tools/toolSelfRepair.ts +42 -9
- package/src/tui/CausyneRotor.js +234 -0
- package/src/tui/CausyneRotor.ts +280 -0
- package/src/tui/activityLayout.js +1 -1
- package/src/tui/activityLayout.ts +1 -1
- package/src/tui/chatRenderer.js +56 -7
- package/src/tui/chatboxClipboard.js +96 -10
- package/src/tui/chatboxClipboard.ts +121 -11
- package/src/tui/clipboardImage.js +308 -0
- package/src/tui/clipboardImage.ts +320 -0
- package/src/tui/codeStreamRenderer.js +89 -1
- package/src/tui/codeStreamRenderer.ts +109 -1
- package/src/tui/composerControls.js +2 -0
- package/src/tui/composerControls.ts +2 -0
- package/src/tui/dialogs.js +41 -6
- package/src/tui/engineSpinner.js +20 -0
- package/src/tui/engineSpinner.ts +46 -0
- package/src/tui/lineEditor.js +44 -12
- package/src/tui/messageInteraction.js +16 -5
- package/src/tui/messageInteraction.ts +14 -5
- package/src/tui/observerPicker.js +4 -8
- package/src/tui/observerPicker.ts +4 -8
- package/src/tui/prompt.js +80 -43
- package/src/tui/runningLight.js +213 -0
- package/src/tui/runningLight.ts +271 -0
- package/src/tui/sessionSidebar.js +7 -1
- package/src/tui/sessionSidebar.ts +7 -1
- package/src/tui/stage.js +4 -4
- package/src/tui/stageSurface.js +21 -14
- package/src/tui/statusLine.js +27 -4
- package/src/tui/statusLine.ts +27 -4
- package/src/tui/theme.js +5 -2
- package/src/tui/thinkingBox.js +41 -10
- package/src/tui/thinkingBox.ts +43 -10
- package/src/tui/turnRail.js +155 -24
- package/src/tui/turnRail.ts +170 -22
package/src/tui/statusLine.ts
CHANGED
|
@@ -23,6 +23,8 @@ import { paint, dim, GLYPHS } from './theme.js';
|
|
|
23
23
|
import { truncate, visibleWidth, safeDisplay, shortenHome } from './text.js';
|
|
24
24
|
import { contextMeter } from './block.js';
|
|
25
25
|
import { CHARS_PER_TOKEN } from '../contextManager.js';
|
|
26
|
+
import { formatAnimatedStatus } from './engineSpinner.js';
|
|
27
|
+
import { renderRunningLight } from './runningLight.js';
|
|
26
28
|
|
|
27
29
|
/** 1234 -> "1.2k", 1234567 -> "1.2M". Token counts are read, not summed. */
|
|
28
30
|
export function compactCount(value: unknown): string {
|
|
@@ -76,6 +78,7 @@ export interface StatusLineRenderOptions {
|
|
|
76
78
|
steps?: number | undefined;
|
|
77
79
|
width?: number | undefined;
|
|
78
80
|
spinnerFrame?: string | undefined;
|
|
81
|
+
tick?: number | undefined;
|
|
79
82
|
}
|
|
80
83
|
|
|
81
84
|
export interface StatusLineIdleOptions {
|
|
@@ -95,6 +98,7 @@ export class StatusLine {
|
|
|
95
98
|
turnTokens = 0;
|
|
96
99
|
turnCost = 0;
|
|
97
100
|
cachedTokens = 0;
|
|
101
|
+
onTick: ((nowMs: number, tick?: number) => void) | null = null;
|
|
98
102
|
|
|
99
103
|
constructor() {
|
|
100
104
|
this.reset();
|
|
@@ -172,8 +176,12 @@ export class StatusLine {
|
|
|
172
176
|
/**
|
|
173
177
|
* Build the line.
|
|
174
178
|
*/
|
|
175
|
-
render({ message = '', elapsedMs = 0, steps = 0, width = 80, spinnerFrame = '' }: StatusLineRenderOptions = {}): string {
|
|
176
|
-
const head = spinnerFrame
|
|
179
|
+
render({ message = '', elapsedMs = 0, steps = 0, width = 80, spinnerFrame = '', tick }: StatusLineRenderOptions = {}): string {
|
|
180
|
+
const head = spinnerFrame
|
|
181
|
+
? (typeof spinnerFrame === 'string' && spinnerFrame.includes('\x1b')
|
|
182
|
+
? `${spinnerFrame} `
|
|
183
|
+
: `${paint('accent', spinnerFrame)} `)
|
|
184
|
+
: '';
|
|
177
185
|
const budget = Math.max(10, width - visibleWidth(head) - 1);
|
|
178
186
|
|
|
179
187
|
const segments: string[] = [];
|
|
@@ -185,7 +193,10 @@ export class StatusLine {
|
|
|
185
193
|
if (this.model) segments.push(this.model);
|
|
186
194
|
|
|
187
195
|
const separator = ` ${GLYPHS.dot} `;
|
|
188
|
-
const
|
|
196
|
+
const rawMessage = tick !== undefined
|
|
197
|
+
? formatAnimatedStatus(message || 'working', tick)
|
|
198
|
+
: (message || (spinnerFrame ? 'working' : ''));
|
|
199
|
+
const text = safeDisplay(rawMessage);
|
|
189
200
|
|
|
190
201
|
const kept = segments.slice();
|
|
191
202
|
const wanted = Math.min(visibleWidth(text), Math.max(18, Math.floor(budget / 2)));
|
|
@@ -201,7 +212,19 @@ export class StatusLine {
|
|
|
201
212
|
: budget;
|
|
202
213
|
const body = truncate(text, messageBudget, GLYPHS.ellipsis);
|
|
203
214
|
|
|
204
|
-
const
|
|
215
|
+
const isAnimating = tick !== undefined || elapsedMs > 0 || Boolean(spinnerFrame);
|
|
216
|
+
const shimmerNowMs = elapsedMs > 0 ? elapsedMs : (tick !== undefined ? tick * 80 : 320);
|
|
217
|
+
if (isAnimating && this.onTick) {
|
|
218
|
+
try {
|
|
219
|
+
this.onTick(shimmerNowMs, tick);
|
|
220
|
+
} catch {
|
|
221
|
+
// Never allow a tick observer to disrupt status rendering
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
const styledBody = isAnimating
|
|
225
|
+
? renderRunningLight(body, { nowMs: shimmerNowMs, baseRole: 'muted' })
|
|
226
|
+
: paint('muted', body);
|
|
227
|
+
const left = `${head}${styledBody}`;
|
|
205
228
|
if (!tail) return left;
|
|
206
229
|
|
|
207
230
|
const gap = Math.max(
|
package/src/tui/theme.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
// Pure Node: no dependency, no shell. Readable by construction.
|
|
14
14
|
|
|
15
15
|
import os from 'os';
|
|
16
|
+
import { getEngineFrames, getEngineFrame } from './engineSpinner.js';
|
|
16
17
|
|
|
17
18
|
// ---------------------------------------------------------------------------
|
|
18
19
|
// Capability detection
|
|
@@ -248,7 +249,7 @@ export function badge(role, text) {
|
|
|
248
249
|
export const GLYPHS = HAS_UNICODE
|
|
249
250
|
? {
|
|
250
251
|
arrow: '▸', check: '✓', cross: '✕', dot: '·', bullet: '•',
|
|
251
|
-
spinner:
|
|
252
|
+
spinner: getEngineFrames({ unicode: true }),
|
|
252
253
|
hLine: '─', vLine: '│', corner: '└', tee: '├', ellipsis: '…',
|
|
253
254
|
// The left accent bar of a block. Uses box-drawing heavy vertical ('┃')
|
|
254
255
|
// so it joins seamlessly from row to row without font line-height leading gaps.
|
|
@@ -268,7 +269,7 @@ export const GLYPHS = HAS_UNICODE
|
|
|
268
269
|
}
|
|
269
270
|
: {
|
|
270
271
|
arrow: '>', check: 'v', cross: 'x', dot: '.', bullet: '*',
|
|
271
|
-
spinner:
|
|
272
|
+
spinner: getEngineFrames({ unicode: false }),
|
|
272
273
|
hLine: '-', vLine: '|', corner: '`', tee: '+', ellipsis: '...',
|
|
273
274
|
bar: '|', step: '*',
|
|
274
275
|
warnMark: '!',
|
|
@@ -396,3 +397,5 @@ export const READABLE_MAX = 100;
|
|
|
396
397
|
export function readableWidth(available = terminalWidth()) {
|
|
397
398
|
return Math.max(40, Math.min(available, READABLE_MAX));
|
|
398
399
|
}
|
|
400
|
+
|
|
401
|
+
export { getEngineFrames, getEngineFrame };
|
package/src/tui/thinkingBox.js
CHANGED
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
//
|
|
7
7
|
// Pure TypeScript under strict mode.
|
|
8
8
|
// @ts-expect-error theme.js has no TypeScript declaration yet.
|
|
9
|
-
import { paint,
|
|
9
|
+
import { paint, dim, GLYPHS, HAS_UNICODE } from './theme.js';
|
|
10
10
|
import { padEnd, truncate, visibleWidth, wrapBlock } from './text.js';
|
|
11
|
+
import { renderRunningLight } from './runningLight.js';
|
|
11
12
|
export const DEFAULT_MAX_STREAMING_LINES = 8;
|
|
12
13
|
export const DEFAULT_MAX_EXPANDED_LINES = 12;
|
|
13
14
|
/**
|
|
@@ -19,7 +20,7 @@ export function calculateThinkingLineCount(content, width) {
|
|
|
19
20
|
return 0;
|
|
20
21
|
const safeWidth = Math.max(20, Math.floor(width));
|
|
21
22
|
const contentBudget = Math.max(10, safeWidth - 4);
|
|
22
|
-
return wrapBlock(text, contentBudget).length;
|
|
23
|
+
return wrapBlock(text, contentBudget, { hang: 0 }).length;
|
|
23
24
|
}
|
|
24
25
|
/**
|
|
25
26
|
* Resolves dynamic contextual activity labels for streaming and completed badges.
|
|
@@ -83,7 +84,17 @@ export function renderCollapsedThinkingBadge(options, totalLines) {
|
|
|
83
84
|
const { activeLabel, completedLabel } = resolveActivityLabels(options);
|
|
84
85
|
if (isStreaming) {
|
|
85
86
|
const timePart = durationText ? ` · ${durationText}` : '';
|
|
86
|
-
|
|
87
|
+
const shimmerNowMs = options.nowMs !== undefined
|
|
88
|
+
? options.nowMs
|
|
89
|
+
: options.tick !== undefined
|
|
90
|
+
? options.tick * 80
|
|
91
|
+
: 320;
|
|
92
|
+
const styledLabel = renderRunningLight(activeLabel, {
|
|
93
|
+
nowMs: shimmerNowMs,
|
|
94
|
+
baseRole: 'warn',
|
|
95
|
+
boldActive: true
|
|
96
|
+
});
|
|
97
|
+
return `${paint('warn', arrow)} ${styledLabel}${dim(timePart)} ${dim('· click to expand')}`;
|
|
87
98
|
}
|
|
88
99
|
const timePart = durationText ? ` for ${durationText}` : '';
|
|
89
100
|
const lineWord = totalLines === 1 ? 'line' : 'lines';
|
|
@@ -144,9 +155,9 @@ export function renderThinkingFrame(content, options = {}) {
|
|
|
144
155
|
const isStreaming = Boolean(options.streaming);
|
|
145
156
|
const isCollapsed = Boolean(options.collapsed);
|
|
146
157
|
const durationText = options.durationText ? String(options.durationText).trim() : '';
|
|
147
|
-
// Wrap lines for inner box width (w - 4)
|
|
158
|
+
// Wrap lines for inner box width (w - 4) with zero hanging indent
|
|
148
159
|
const contentBudget = Math.max(10, width - 4);
|
|
149
|
-
const allRows = wrapBlock(text, contentBudget);
|
|
160
|
+
const allRows = wrapBlock(text, contentBudget, { hang: 0 });
|
|
150
161
|
const totalLines = allRows.length;
|
|
151
162
|
if (isCollapsed) {
|
|
152
163
|
return [renderCollapsedThinkingBadge(options, totalLines)];
|
|
@@ -159,10 +170,30 @@ export function renderThinkingFrame(content, options = {}) {
|
|
|
159
170
|
const maxLines = options.maxVisibleLines ?? DEFAULT_MAX_STREAMING_LINES;
|
|
160
171
|
const timePart = durationText ? ` · ${durationText}` : '';
|
|
161
172
|
const { activeLabel } = resolveActivityLabels(options);
|
|
162
|
-
const
|
|
173
|
+
const shimmerNowMs = options.nowMs !== undefined
|
|
174
|
+
? options.nowMs
|
|
175
|
+
: options.tick !== undefined
|
|
176
|
+
? options.tick * 80
|
|
177
|
+
: 320;
|
|
178
|
+
const styledActiveLabel = renderRunningLight(activeLabel, {
|
|
179
|
+
nowMs: shimmerNowMs,
|
|
180
|
+
baseRole: 'warn',
|
|
181
|
+
boldActive: true
|
|
182
|
+
});
|
|
183
|
+
const title = `${styledActiveLabel}${dim(timePart)}`;
|
|
163
184
|
const footer = collapseHint;
|
|
164
185
|
const { top, bottom, wrapRow } = buildThinkingBoxBorders(title, footer, width, role);
|
|
165
186
|
const rows = [top];
|
|
187
|
+
const renderStreamingRow = (row, isActiveTail) => {
|
|
188
|
+
if (!isActiveTail)
|
|
189
|
+
return wrapRow(dim(row));
|
|
190
|
+
const truncated = truncate(row, contentBudget, GLYPHS.ellipsis || '…');
|
|
191
|
+
const shimmered = renderRunningLight(truncated, {
|
|
192
|
+
nowMs: shimmerNowMs,
|
|
193
|
+
baseRole: 'muted'
|
|
194
|
+
});
|
|
195
|
+
return wrapRow(shimmered);
|
|
196
|
+
};
|
|
166
197
|
if (totalLines > maxLines) {
|
|
167
198
|
const hiddenCount = totalLines - (maxLines - 1);
|
|
168
199
|
const scrollIndicator = HAS_UNICODE ? '↑' : '^';
|
|
@@ -170,13 +201,13 @@ export function renderThinkingFrame(content, options = {}) {
|
|
|
170
201
|
const hiddenNotice = `${paint('rule', scrollIndicator)} ${dim(`${hiddenCount} earlier ${activityWord}line${hiddenCount === 1 ? '' : 's'} scrolled`)}`;
|
|
171
202
|
rows.push(wrapRow(hiddenNotice));
|
|
172
203
|
const tailRows = allRows.slice(totalLines - (maxLines - 1));
|
|
173
|
-
for (
|
|
174
|
-
rows.push(
|
|
204
|
+
for (let i = 0; i < tailRows.length; i++) {
|
|
205
|
+
rows.push(renderStreamingRow(tailRows[i], i === tailRows.length - 1));
|
|
175
206
|
}
|
|
176
207
|
}
|
|
177
208
|
else {
|
|
178
|
-
for (
|
|
179
|
-
rows.push(
|
|
209
|
+
for (let i = 0; i < allRows.length; i++) {
|
|
210
|
+
rows.push(renderStreamingRow(allRows[i], i === allRows.length - 1));
|
|
180
211
|
}
|
|
181
212
|
}
|
|
182
213
|
rows.push(bottom);
|
package/src/tui/thinkingBox.ts
CHANGED
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
// Pure TypeScript under strict mode.
|
|
8
8
|
|
|
9
9
|
// @ts-expect-error theme.js has no TypeScript declaration yet.
|
|
10
|
-
import { paint,
|
|
10
|
+
import { paint, dim, GLYPHS, HAS_UNICODE } from './theme.js';
|
|
11
11
|
import { padEnd, truncate, visibleWidth, wrapBlock } from './text.js';
|
|
12
|
+
import { renderRunningLight } from './runningLight.js';
|
|
12
13
|
|
|
13
14
|
export interface ThinkingFrameOptions {
|
|
14
15
|
width?: number;
|
|
@@ -21,6 +22,8 @@ export interface ThinkingFrameOptions {
|
|
|
21
22
|
activity?: string;
|
|
22
23
|
title?: string;
|
|
23
24
|
completedTitle?: string;
|
|
25
|
+
nowMs?: number;
|
|
26
|
+
tick?: number;
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
export const DEFAULT_MAX_STREAMING_LINES = 8;
|
|
@@ -34,7 +37,7 @@ export function calculateThinkingLineCount(content: string, width: number): numb
|
|
|
34
37
|
if (!text) return 0;
|
|
35
38
|
const safeWidth = Math.max(20, Math.floor(width));
|
|
36
39
|
const contentBudget = Math.max(10, safeWidth - 4);
|
|
37
|
-
return wrapBlock(text, contentBudget).length;
|
|
40
|
+
return wrapBlock(text, contentBudget, { hang: 0 }).length;
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
/**
|
|
@@ -92,7 +95,17 @@ export function renderCollapsedThinkingBadge(
|
|
|
92
95
|
|
|
93
96
|
if (isStreaming) {
|
|
94
97
|
const timePart = durationText ? ` · ${durationText}` : '';
|
|
95
|
-
|
|
98
|
+
const shimmerNowMs = options.nowMs !== undefined
|
|
99
|
+
? options.nowMs
|
|
100
|
+
: options.tick !== undefined
|
|
101
|
+
? options.tick * 80
|
|
102
|
+
: 320;
|
|
103
|
+
const styledLabel = renderRunningLight(activeLabel, {
|
|
104
|
+
nowMs: shimmerNowMs,
|
|
105
|
+
baseRole: 'warn',
|
|
106
|
+
boldActive: true
|
|
107
|
+
});
|
|
108
|
+
return `${paint('warn', arrow)} ${styledLabel}${dim(timePart)} ${dim('· click to expand')}`;
|
|
96
109
|
}
|
|
97
110
|
|
|
98
111
|
const timePart = durationText ? ` for ${durationText}` : '';
|
|
@@ -177,9 +190,9 @@ export function renderThinkingFrame(
|
|
|
177
190
|
const isCollapsed = Boolean(options.collapsed);
|
|
178
191
|
const durationText = options.durationText ? String(options.durationText).trim() : '';
|
|
179
192
|
|
|
180
|
-
// Wrap lines for inner box width (w - 4)
|
|
193
|
+
// Wrap lines for inner box width (w - 4) with zero hanging indent
|
|
181
194
|
const contentBudget = Math.max(10, width - 4);
|
|
182
|
-
const allRows = wrapBlock(text, contentBudget);
|
|
195
|
+
const allRows = wrapBlock(text, contentBudget, { hang: 0 });
|
|
183
196
|
const totalLines = allRows.length;
|
|
184
197
|
|
|
185
198
|
if (isCollapsed) {
|
|
@@ -195,12 +208,32 @@ export function renderThinkingFrame(
|
|
|
195
208
|
const maxLines = options.maxVisibleLines ?? DEFAULT_MAX_STREAMING_LINES;
|
|
196
209
|
const timePart = durationText ? ` · ${durationText}` : '';
|
|
197
210
|
const { activeLabel } = resolveActivityLabels(options);
|
|
198
|
-
const
|
|
211
|
+
const shimmerNowMs = options.nowMs !== undefined
|
|
212
|
+
? options.nowMs
|
|
213
|
+
: options.tick !== undefined
|
|
214
|
+
? options.tick * 80
|
|
215
|
+
: 320;
|
|
216
|
+
const styledActiveLabel = renderRunningLight(activeLabel, {
|
|
217
|
+
nowMs: shimmerNowMs,
|
|
218
|
+
baseRole: 'warn',
|
|
219
|
+
boldActive: true
|
|
220
|
+
});
|
|
221
|
+
const title = `${styledActiveLabel}${dim(timePart)}`;
|
|
199
222
|
const footer = collapseHint;
|
|
200
223
|
|
|
201
224
|
const { top, bottom, wrapRow } = buildThinkingBoxBorders(title, footer, width, role);
|
|
202
225
|
const rows: string[] = [top];
|
|
203
226
|
|
|
227
|
+
const renderStreamingRow = (row: string, isActiveTail: boolean): string => {
|
|
228
|
+
if (!isActiveTail) return wrapRow(dim(row));
|
|
229
|
+
const truncated = truncate(row, contentBudget, GLYPHS.ellipsis || '…');
|
|
230
|
+
const shimmered = renderRunningLight(truncated, {
|
|
231
|
+
nowMs: shimmerNowMs,
|
|
232
|
+
baseRole: 'muted'
|
|
233
|
+
});
|
|
234
|
+
return wrapRow(shimmered);
|
|
235
|
+
};
|
|
236
|
+
|
|
204
237
|
if (totalLines > maxLines) {
|
|
205
238
|
const hiddenCount = totalLines - (maxLines - 1);
|
|
206
239
|
const scrollIndicator = HAS_UNICODE ? '↑' : '^';
|
|
@@ -209,12 +242,12 @@ export function renderThinkingFrame(
|
|
|
209
242
|
rows.push(wrapRow(hiddenNotice));
|
|
210
243
|
|
|
211
244
|
const tailRows = allRows.slice(totalLines - (maxLines - 1));
|
|
212
|
-
for (
|
|
213
|
-
rows.push(
|
|
245
|
+
for (let i = 0; i < tailRows.length; i++) {
|
|
246
|
+
rows.push(renderStreamingRow(tailRows[i]!, i === tailRows.length - 1));
|
|
214
247
|
}
|
|
215
248
|
} else {
|
|
216
|
-
for (
|
|
217
|
-
rows.push(
|
|
249
|
+
for (let i = 0; i < allRows.length; i++) {
|
|
250
|
+
rows.push(renderStreamingRow(allRows[i]!, i === allRows.length - 1));
|
|
218
251
|
}
|
|
219
252
|
}
|
|
220
253
|
|
package/src/tui/turnRail.js
CHANGED
|
@@ -74,7 +74,7 @@ export function collectSessionTurns(transcript, contentWidth = 80) {
|
|
|
74
74
|
turnIndex,
|
|
75
75
|
totalTurns,
|
|
76
76
|
userPrompt: userPrompt.replace(/\s+/g, ' ').trim(),
|
|
77
|
-
assistantSummary: assistantSummary
|
|
77
|
+
assistantSummary: formatPreviewCardMarkdown(assistantSummary),
|
|
78
78
|
timestamp: frame.ts || Date.now(),
|
|
79
79
|
formattedDate: formatTurnTimestamp(frame.ts || Date.now()),
|
|
80
80
|
frameId: frame.id,
|
|
@@ -204,6 +204,51 @@ export function buildTurnRailCells(turns, height, activeTurnIndex, hoveredTurnIn
|
|
|
204
204
|
}
|
|
205
205
|
return { cells, layout: { dotRows, rowToTurn } };
|
|
206
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* Render and clean markdown for display within the Floating Turn Preview Card.
|
|
209
|
+
* Strips raw syntax markers (###, **, *, `, table delimiters) and renders
|
|
210
|
+
* clean, readable, professional text without leaking markdown source code.
|
|
211
|
+
*/
|
|
212
|
+
export function formatPreviewCardMarkdown(raw) {
|
|
213
|
+
if (!raw)
|
|
214
|
+
return '';
|
|
215
|
+
let text = String(raw);
|
|
216
|
+
// Strip code block fences
|
|
217
|
+
text = text.replace(/```[a-zA-Z0-9_-]*\n?/g, ' ');
|
|
218
|
+
// Strip headings: ### Heading -> Heading
|
|
219
|
+
text = text.replace(/(?:^|\n)\s*#{1,6}\s+/g, '\n');
|
|
220
|
+
// Strip blockquotes: > quote -> quote
|
|
221
|
+
text = text.replace(/(?:^|\n)\s*>\s?/g, '\n');
|
|
222
|
+
// Strip horizontal rules: --- or ***
|
|
223
|
+
text = text.replace(/(?:^|\n)\s*[-*_]{3,}\s*(?=\n|$)/g, '\n');
|
|
224
|
+
// Strip table separator lines: | :--- | :--- |
|
|
225
|
+
text = text.replace(/(?:^|\n)\s*\|?(\s*:?-+:?\s*\|)+\s*(?=\n|$)/g, '\n');
|
|
226
|
+
// Convert table row pipes: | a | b | -> a · b
|
|
227
|
+
text = text.replace(/(?:^|\n)\s*\|\s*(.+?)\s*\|\s*(?=\n|$)/g, (_m, content) => {
|
|
228
|
+
return '\n' + content.split(/\s*\|\s*/).filter(Boolean).join(' · ');
|
|
229
|
+
});
|
|
230
|
+
// Convert list bullets: - item, * item -> • item
|
|
231
|
+
text = text.replace(/(?:^|\n)\s*[-*+]\s+/g, '\n• ');
|
|
232
|
+
// Convert numbered lists: 1. item -> 1. item
|
|
233
|
+
text = text.replace(/(?:^|\n)\s*(\d+)\.\s+/g, '\n$1. ');
|
|
234
|
+
// Strip links: [label](url) -> label
|
|
235
|
+
text = text.replace(/\[([^\]\n]+)\]\([^\)\s]+\)/g, '$1');
|
|
236
|
+
// Strip images:  -> alt
|
|
237
|
+
text = text.replace(/!\[([^\]\n]*)\]\([^\)\s]+\)/g, '$1');
|
|
238
|
+
// Strip inline code backticks: `code` -> code
|
|
239
|
+
text = text.replace(/`([^`\n]+)`/g, '$1');
|
|
240
|
+
// Format bold and italic: ***text***, **text**, *text*, ___text___, __text__, _text_
|
|
241
|
+
text = text.replace(/\*\*\*([^*]+)\*\*\*/g, '$1');
|
|
242
|
+
text = text.replace(/\*\*([^*]+)\*\*/g, '$1');
|
|
243
|
+
text = text.replace(/(?:^|[^*])\*([^*]+)\*(?!\*)/g, (m, inner) => m.startsWith('*') ? inner : `${m[0]}${inner}`);
|
|
244
|
+
text = text.replace(/___([^_]+)___/g, '$1');
|
|
245
|
+
text = text.replace(/__([^_]+)__/g, '$1');
|
|
246
|
+
text = text.replace(/(?:^|[^_])_([^_]+)_(?!_)/g, (m, inner) => m.startsWith('_') ? inner : `${m[0]}${inner}`);
|
|
247
|
+
// Strip strikethrough: ~~text~~ -> text
|
|
248
|
+
text = text.replace(/~~([^~]+)~~/g, '$1');
|
|
249
|
+
// Collapse multiple spaces/newlines cleanly into single space
|
|
250
|
+
return text.replace(/\s+/g, ' ').trim();
|
|
251
|
+
}
|
|
207
252
|
/**
|
|
208
253
|
* Render the Floating Turn Preview Card popover.
|
|
209
254
|
* Exactly matches the UX/UI in Screen Recording 2026-10-30 at 02.42.17:
|
|
@@ -218,16 +263,17 @@ export function renderTurnPreviewCard(turn, maxCardWidth = 50) {
|
|
|
218
263
|
const cardBg = '\x1b[48;2;28;28;32m';
|
|
219
264
|
const borderStyle = `${cardBg}\x1b[38;2;75;75;82m`;
|
|
220
265
|
const reset = '\x1b[0m';
|
|
221
|
-
// Format header: User Prompt (bold primary)
|
|
222
|
-
const rawPrompt = turn.userPrompt || 'User request';
|
|
223
|
-
const promptLines = wrapBlock(rawPrompt, innerWidth).slice(0, 2);
|
|
266
|
+
// Format header: User Prompt (bold primary) rendered cleanly without raw markdown, strictly flush-left with hang: 0
|
|
267
|
+
const rawPrompt = formatPreviewCardMarkdown(turn.userPrompt || 'User request');
|
|
268
|
+
const promptLines = wrapBlock(rawPrompt, innerWidth, { hang: 0 }).slice(0, 2);
|
|
224
269
|
if (promptLines.length === 2 && promptLines[1]) {
|
|
225
270
|
promptLines[1] = truncate(promptLines[1], innerWidth - 3, '...');
|
|
226
271
|
}
|
|
227
|
-
// Format body: Assistant Summary (muted secondary)
|
|
272
|
+
// Format body: Assistant Summary (muted secondary) rendered cleanly without raw markdown, strictly flush-left with hang: 0
|
|
228
273
|
let bodyLines = [];
|
|
229
274
|
if (turn.assistantSummary) {
|
|
230
|
-
|
|
275
|
+
const formattedSummary = formatPreviewCardMarkdown(turn.assistantSummary);
|
|
276
|
+
bodyLines = wrapBlock(formattedSummary, innerWidth, { hang: 0 }).slice(0, 3);
|
|
231
277
|
if (bodyLines.length === 3 && bodyLines[2]) {
|
|
232
278
|
bodyLines[2] = truncate(bodyLines[2], innerWidth - 3, '...');
|
|
233
279
|
}
|
|
@@ -270,10 +316,11 @@ export function overlayTurnPreviewCard(viewportRows, cardRows, anchorY, railX, s
|
|
|
270
316
|
if (cardRows.length === 0 || viewportRows.length === 0)
|
|
271
317
|
return viewportRows;
|
|
272
318
|
const cardWidth = visibleWidth(cardRows[0] || '');
|
|
273
|
-
// Clamp card placement horizontally:
|
|
319
|
+
// Clamp card placement horizontally: flush-left with transcript baseline at column 3
|
|
320
|
+
const cardSpacing = 2; // railX + 2 gives x = 3, perfectly flush left with transcript content
|
|
274
321
|
let x = railX - cardWidth - 1;
|
|
275
|
-
if (x < 0 || (railX <= 4 && railX +
|
|
276
|
-
x = Math.max(0, Math.min(screenWidth - cardWidth - 1, railX +
|
|
322
|
+
if (x < 0 || (railX <= 4 && railX + cardSpacing + cardWidth <= screenWidth)) {
|
|
323
|
+
x = Math.max(0, Math.min(screenWidth - cardWidth - 1, railX + cardSpacing));
|
|
277
324
|
}
|
|
278
325
|
// Center vertically around anchorY
|
|
279
326
|
const startY = Math.max(0, Math.min(viewportRows.length - cardRows.length, anchorY - Math.floor(cardRows.length / 2)));
|
|
@@ -284,10 +331,40 @@ export function overlayTurnPreviewCard(viewportRows, cardRows, anchorY, railX, s
|
|
|
284
331
|
break;
|
|
285
332
|
const baseRow = out[targetY] || '';
|
|
286
333
|
const cardRow = cardRows[i] || '';
|
|
287
|
-
// Composite cardRow onto baseRow at column x
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
334
|
+
// Composite cardRow onto baseRow at column x.
|
|
335
|
+
// To the left of the card, NEVER allow severed underlying characters (like '▸' or text) to leak!
|
|
336
|
+
// Maintain a perfectly clean, flush, symmetrical margin:
|
|
337
|
+
// Only preserve the rail dot (if present at railX) and whitespace padding up to column x.
|
|
338
|
+
let beforePart = '';
|
|
339
|
+
if (x <= 6 && railX <= 4) {
|
|
340
|
+
const plainBase = stripAnsi(baseRow);
|
|
341
|
+
const dotChar = plainBase[railX] || ' ';
|
|
342
|
+
const isDot = dotChar === '●' || dotChar === '•' || dotChar === '·' || dotChar === '[' || dotChar === ']';
|
|
343
|
+
let dotCell = ' ';
|
|
344
|
+
if (isDot) {
|
|
345
|
+
const sliceDot = sliceFromColumn(baseRow, railX);
|
|
346
|
+
dotCell = sliceDot ? truncate(sliceDot, 1, '') : dotChar;
|
|
347
|
+
}
|
|
348
|
+
const leadingSpace = ' '.repeat(Math.max(0, railX));
|
|
349
|
+
const trailingSpace = ' '.repeat(Math.max(0, x - railX - 1));
|
|
350
|
+
beforePart = `${leadingSpace}${dotCell}${trailingSpace}`;
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
beforePart = padEnd(truncate(baseRow, x, ''), x);
|
|
354
|
+
}
|
|
355
|
+
let restOfRow = '';
|
|
356
|
+
if (x <= 6) {
|
|
357
|
+
// For left-placed turn cards, do not leave severed text tails sticking out
|
|
358
|
+
const totalRowWidth = Math.max(screenWidth, visibleWidth(baseRow));
|
|
359
|
+
const rightCell = sliceFromColumn(baseRow, totalRowWidth - 1);
|
|
360
|
+
const rightCellWidth = visibleWidth(rightCell);
|
|
361
|
+
const gap = Math.max(0, totalRowWidth - x - cardWidth - rightCellWidth);
|
|
362
|
+
restOfRow = `${' '.repeat(gap)}${rightCell}`;
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
restOfRow = sliceFromColumn(baseRow, x + cardWidth);
|
|
366
|
+
}
|
|
367
|
+
out[targetY] = `${beforePart}${cardRow}${restOfRow}`;
|
|
291
368
|
}
|
|
292
369
|
return out;
|
|
293
370
|
}
|
|
@@ -310,26 +387,67 @@ export function handleTurnRailMouse(event, surface, host) {
|
|
|
310
387
|
const isRail = layout.railX <= 2
|
|
311
388
|
? (mouseX >= 0 && mouseX <= Math.max(3, layout.railX + 2))
|
|
312
389
|
: (mouseX >= layout.railX - 1 && mouseX <= layout.railX + 2);
|
|
313
|
-
if
|
|
390
|
+
// Check if currently showing a card and mouse is hovering over the card or bridge tunnel
|
|
391
|
+
const hasActiveCard = surface.hoveredTurnIndex !== null && surface.hoveredTurnIndex !== undefined;
|
|
392
|
+
let isCard = false;
|
|
393
|
+
let isBridge = false;
|
|
394
|
+
if (hasActiveCard) {
|
|
395
|
+
const cardRect = layout.cardRect;
|
|
396
|
+
if (cardRect && cardRect.turnIndex === surface.hoveredTurnIndex) {
|
|
397
|
+
isCard = mouseX >= cardRect.x && mouseX < cardRect.x + cardRect.width &&
|
|
398
|
+
relY >= cardRect.y && relY < cardRect.y + cardRect.height;
|
|
399
|
+
isBridge = layout.railX <= 4 &&
|
|
400
|
+
mouseX >= 0 && mouseX < cardRect.x &&
|
|
401
|
+
relY >= cardRect.y && relY < cardRect.y + cardRect.height;
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
const cardWidth = 52;
|
|
405
|
+
const cardX = layout.railX <= 4 ? layout.railX + 2 : Math.max(0, layout.railX - cardWidth - 1);
|
|
406
|
+
const anchorY = surface.hoveredTurnAnchorY ?? Math.floor(layout.viewportHeight / 2);
|
|
407
|
+
const cardHeight = 9;
|
|
408
|
+
const cardStartY = Math.max(0, Math.min(layout.viewportHeight - cardHeight, anchorY - Math.floor(cardHeight / 2)));
|
|
409
|
+
const cardEndY = cardStartY + cardHeight;
|
|
410
|
+
isCard = mouseX >= cardX && mouseX < cardX + cardWidth &&
|
|
411
|
+
relY >= cardStartY && relY < cardEndY;
|
|
412
|
+
isBridge = layout.railX <= 4 &&
|
|
413
|
+
mouseX >= 0 && mouseX < cardX &&
|
|
414
|
+
relY >= cardStartY && relY < cardEndY;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
const inHoverZone = isRail || isCard || isBridge;
|
|
418
|
+
if (!inHoverZone || relY < 0 || relY >= layout.viewportHeight) {
|
|
314
419
|
surface.turnRailHoverSuppressed = false;
|
|
315
420
|
if (surface.hoveredTurnIndex !== null && surface.hoveredTurnIndex !== undefined) {
|
|
316
|
-
surface.
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
421
|
+
if (!surface._turnCardLeaveTimer) {
|
|
422
|
+
surface._turnCardLeaveTimer = setTimeout(() => {
|
|
423
|
+
surface._turnCardLeaveTimer = null;
|
|
424
|
+
if (surface.hoveredTurnIndex !== null && surface.hoveredTurnIndex !== undefined) {
|
|
425
|
+
surface.hoveredTurnIndex = null;
|
|
426
|
+
surface.hoveredTurnAnchorY = null;
|
|
427
|
+
if (typeof host?.scheduleDraw === 'function')
|
|
428
|
+
host.scheduleDraw();
|
|
429
|
+
else if (typeof host?.draw === 'function')
|
|
430
|
+
host.draw();
|
|
431
|
+
}
|
|
432
|
+
}, 120);
|
|
433
|
+
}
|
|
322
434
|
}
|
|
323
435
|
return false;
|
|
324
436
|
}
|
|
437
|
+
// Inside hover zone - cancel any pending leave timer
|
|
438
|
+
if (surface._turnCardLeaveTimer) {
|
|
439
|
+
clearTimeout(surface._turnCardLeaveTimer);
|
|
440
|
+
surface._turnCardLeaveTimer = null;
|
|
441
|
+
}
|
|
325
442
|
// If hover is temporarily suppressed after a click, swallow rail mouse events until suppression ends
|
|
326
443
|
if (surface.turnRailHoverSuppressed) {
|
|
327
444
|
return true;
|
|
328
445
|
}
|
|
329
|
-
|
|
446
|
+
// Rail takes precedence when mouse is on the rail track
|
|
447
|
+
let turnNum = isRail ? layout.rowToTurn?.get(relY) : ((isCard || isBridge) ? surface.hoveredTurnIndex : undefined);
|
|
330
448
|
let anchorY = relY;
|
|
331
|
-
// If not an exact row hit, resolve closest dot within proximity
|
|
332
|
-
if (!turnNum && layout.dotRows && layout.dotRows.size > 0) {
|
|
449
|
+
// If on rail and not an exact row hit, resolve closest dot within proximity
|
|
450
|
+
if (!turnNum && isRail && layout.dotRows && layout.dotRows.size > 0) {
|
|
333
451
|
let minDistance = Infinity;
|
|
334
452
|
let closestTurn;
|
|
335
453
|
let closestRow;
|
|
@@ -341,13 +459,26 @@ export function handleTurnRailMouse(event, surface, host) {
|
|
|
341
459
|
closestRow = row;
|
|
342
460
|
}
|
|
343
461
|
}
|
|
344
|
-
if (minDistance <=
|
|
462
|
+
if (minDistance <= 1 && closestTurn !== undefined && closestRow !== undefined) {
|
|
345
463
|
turnNum = closestTurn;
|
|
346
464
|
anchorY = closestRow;
|
|
347
465
|
}
|
|
348
466
|
}
|
|
349
467
|
if (turnNum) {
|
|
350
468
|
if (isMouseMotion(event.sequence)) {
|
|
469
|
+
// While a turn is streaming, a hover card would sit on top of live output
|
|
470
|
+
// (thinking, code edits, tool frames). Clicking a dot still navigates.
|
|
471
|
+
if (host?.busy) {
|
|
472
|
+
if (surface.hoveredTurnIndex !== null && surface.hoveredTurnIndex !== undefined) {
|
|
473
|
+
surface.hoveredTurnIndex = null;
|
|
474
|
+
surface.hoveredTurnAnchorY = null;
|
|
475
|
+
if (typeof host?.scheduleDraw === 'function')
|
|
476
|
+
host.scheduleDraw();
|
|
477
|
+
else if (typeof host?.draw === 'function')
|
|
478
|
+
host.draw();
|
|
479
|
+
}
|
|
480
|
+
return true;
|
|
481
|
+
}
|
|
351
482
|
if (surface.hoveredTurnIndex !== turnNum) {
|
|
352
483
|
surface.hoveredTurnIndex = turnNum;
|
|
353
484
|
surface.hoveredTurnAnchorY = anchorY;
|