@causyne/agent 1.20.31 → 1.20.33
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/package.json +1 -1
- package/src/agentLoop.js +8 -0
- package/src/agentLoop.ts +7 -0
- package/src/implementationPlan.js +8 -2
- package/src/implementationPlan.ts +9 -2
- package/src/launchIntent.js +3 -1
- package/src/launchIntent.ts +2 -1
- package/src/mcp/mcpRegistry.js +3 -1
- package/src/mcp/mcpRegistry.ts +3 -1
- package/src/observer/evidence.js +11 -3
- package/src/observer/evidence.ts +9 -3
- package/src/tools/memoryWrite.js +71 -89
- package/src/tools/memoryWrite.ts +108 -0
- package/src/tui/consoleGuard.js +85 -0
- package/src/tui/consoleGuard.ts +102 -0
- package/src/tui/messageActionPlacement.js +8 -3
- package/src/tui/messageActionPlacement.ts +8 -3
- package/src/tui/messageInteraction.js +184 -27
- package/src/tui/messageInteraction.ts +221 -45
- package/src/tui/mouseHover.js +4 -0
- package/src/tui/mouseHover.ts +5 -0
- package/src/tui/smartLinkClick.js +353 -0
- package/src/tui/smartLinkClick.ts +413 -0
- package/src/verificationPlan.js +19 -4
- package/src/verificationPlan.ts +17 -4
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
export interface ConsoleGuardStageHost {
|
|
2
|
+
out?: NodeJS.WriteStream | { rows?: number; columns?: number };
|
|
3
|
+
stage?: { reserved?: boolean; invalidate?: () => void };
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface TransientNoticeHost {
|
|
7
|
+
notice: string;
|
|
8
|
+
scheduleDraw(): void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const activeStageHosts = new Set<ConsoleGuardStageHost>();
|
|
12
|
+
let stageMouseSessionDepth = 0;
|
|
13
|
+
let guardInstalled = false;
|
|
14
|
+
|
|
15
|
+
const originalConsole = {
|
|
16
|
+
log: console.log.bind(console),
|
|
17
|
+
info: console.info.bind(console),
|
|
18
|
+
warn: console.warn.bind(console),
|
|
19
|
+
error: console.error.bind(console)
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export function isAnyStageReservedOnStdout(): boolean {
|
|
23
|
+
if (stageMouseSessionDepth > 0 && process.stdout?.isTTY) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
for (const host of activeStageHosts) {
|
|
27
|
+
if (host.stage?.reserved && (!host.out || host.out === process.stdout)) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function ensureConsoleGuardInstalled(): void {
|
|
35
|
+
if (guardInstalled) return;
|
|
36
|
+
guardInstalled = true;
|
|
37
|
+
|
|
38
|
+
const wrap = (fn: (...args: unknown[]) => void) => (...args: unknown[]): void => {
|
|
39
|
+
if (isAnyStageReservedOnStdout()) {
|
|
40
|
+
// Never write raw console output while the full-screen TUI Stage owns stdout,
|
|
41
|
+
// because the terminal cursor rests inside the composer input box and raw
|
|
42
|
+
// writes corrupt the composer rows and shift the physical cursor.
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
fn(...args);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
console.log = wrap(originalConsole.log);
|
|
49
|
+
console.info = wrap(originalConsole.info);
|
|
50
|
+
console.warn = wrap(originalConsole.warn);
|
|
51
|
+
console.error = wrap(originalConsole.error);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Track TUI Stage open/close lifecycle so raw console writes cannot corrupt the composer box.
|
|
56
|
+
*/
|
|
57
|
+
export function setStageConsoleGuardActive(active: boolean): void {
|
|
58
|
+
ensureConsoleGuardInstalled();
|
|
59
|
+
if (active) {
|
|
60
|
+
stageMouseSessionDepth = Math.max(1, stageMouseSessionDepth + 1);
|
|
61
|
+
} else {
|
|
62
|
+
stageMouseSessionDepth = Math.max(0, stageMouseSessionDepth - 1);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Register a StageSurface host so raw console writes are suppressed while its Stage is reserved.
|
|
68
|
+
*/
|
|
69
|
+
export function registerStageConsoleGuard(host: ConsoleGuardStageHost): () => void {
|
|
70
|
+
ensureConsoleGuardInstalled();
|
|
71
|
+
activeStageHosts.add(host);
|
|
72
|
+
return () => {
|
|
73
|
+
activeStageHosts.delete(host);
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const noticeTimers = new WeakMap<TransientNoticeHost, ReturnType<typeof setTimeout>>();
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Set a transient status notice on the prompt/composer host and auto-clear it after `ttlMs`
|
|
81
|
+
* if nothing else has overwritten `host.notice` in the meantime.
|
|
82
|
+
*/
|
|
83
|
+
export function setTransientNotice(host: TransientNoticeHost, message: string, ttlMs = 4000): void {
|
|
84
|
+
const existing = noticeTimers.get(host);
|
|
85
|
+
if (existing) {
|
|
86
|
+
clearTimeout(existing);
|
|
87
|
+
noticeTimers.delete(host);
|
|
88
|
+
}
|
|
89
|
+
host.notice = message;
|
|
90
|
+
host.scheduleDraw();
|
|
91
|
+
if (!message || ttlMs <= 0) return;
|
|
92
|
+
|
|
93
|
+
const timer = setTimeout(() => {
|
|
94
|
+
noticeTimers.delete(host);
|
|
95
|
+
if (host.notice === message) {
|
|
96
|
+
host.notice = '';
|
|
97
|
+
host.scheduleDraw();
|
|
98
|
+
}
|
|
99
|
+
}, ttlMs);
|
|
100
|
+
timer.unref?.();
|
|
101
|
+
noticeTimers.set(host, timer);
|
|
102
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { truncate, visibleWidth } from './text.js';
|
|
2
|
-
|
|
1
|
+
import { padEnd, truncate, visibleWidth } from './text.js';
|
|
2
|
+
import { sliceFromColumn } from './turnRail.js';
|
|
3
|
+
/** Overlay a compact menu in the transcript viewport, near the selected message, without erasing left/right columns. */
|
|
3
4
|
export function placeMessageActionPanel(viewportRows, panel, contentWidth, stageTop, anchorY, count) {
|
|
4
5
|
if (!panel.length || viewportRows.length < panel.length || contentWidth < 8) {
|
|
5
6
|
return { rows: viewportRows, layout: null };
|
|
@@ -10,7 +11,11 @@ export function placeMessageActionPanel(viewportRows, panel, contentWidth, stage
|
|
|
10
11
|
const y = Math.max(0, Math.min(viewportRows.length - panel.length, anchor - Math.floor(panel.length / 2)));
|
|
11
12
|
const rows = viewportRows.slice();
|
|
12
13
|
for (let i = 0; i < panel.length; i++) {
|
|
13
|
-
rows[y + i]
|
|
14
|
+
const baseRow = rows[y + i] ?? '';
|
|
15
|
+
const leftPrefix = padEnd(truncate(baseRow, x, ''), x);
|
|
16
|
+
const cardChunk = padEnd(truncate(panel[i] ?? '', width, ''), width);
|
|
17
|
+
const rightSuffix = sliceFromColumn(baseRow, x + width);
|
|
18
|
+
rows[y + i] = `${leftPrefix}${cardChunk}${rightSuffix}`;
|
|
14
19
|
}
|
|
15
20
|
return { rows, layout: { x, y: stageTop + y, width, count } };
|
|
16
21
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { truncate, visibleWidth } from './text.js';
|
|
1
|
+
import { padEnd, truncate, visibleWidth } from './text.js';
|
|
2
|
+
import { sliceFromColumn } from './turnRail.js';
|
|
2
3
|
|
|
3
4
|
export interface MessageActionPlacement {
|
|
4
5
|
rows: string[];
|
|
5
6
|
layout: { x: number; y: number; width: number; count: number } | null;
|
|
6
7
|
}
|
|
7
8
|
|
|
8
|
-
/** Overlay a compact menu in the transcript viewport, near the selected message. */
|
|
9
|
+
/** Overlay a compact menu in the transcript viewport, near the selected message, without erasing left/right columns. */
|
|
9
10
|
export function placeMessageActionPanel(
|
|
10
11
|
viewportRows: string[], panel: string[], contentWidth: number,
|
|
11
12
|
stageTop: number, anchorY: number | null, count: number
|
|
@@ -19,7 +20,11 @@ export function placeMessageActionPanel(
|
|
|
19
20
|
const y = Math.max(0, Math.min(viewportRows.length - panel.length, anchor - Math.floor(panel.length / 2)));
|
|
20
21
|
const rows = viewportRows.slice();
|
|
21
22
|
for (let i = 0; i < panel.length; i++) {
|
|
22
|
-
rows[y + i]
|
|
23
|
+
const baseRow = rows[y + i] ?? '';
|
|
24
|
+
const leftPrefix = padEnd(truncate(baseRow, x, ''), x);
|
|
25
|
+
const cardChunk = padEnd(truncate(panel[i] ?? '', width, ''), width);
|
|
26
|
+
const rightSuffix = sliceFromColumn(baseRow, x + width);
|
|
27
|
+
rows[y + i] = `${leftPrefix}${cardChunk}${rightSuffix}`;
|
|
23
28
|
}
|
|
24
29
|
return { rows, layout: { x, y: stageTop + y, width, count } };
|
|
25
30
|
}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import { getActiveSessionId, getSession } from '../sessionJournal.js';
|
|
1
|
+
import { getActiveSessionId, getSession, listSessions, saveSessionMessages } from '../sessionJournal.js';
|
|
2
2
|
import { revokeAllAlways } from '../approvalGrants.js';
|
|
3
|
+
// @ts-expect-error Legacy checkpoints module has no TypeScript declarations yet.
|
|
4
|
+
import { undoLast } from '../checkpoints.js';
|
|
3
5
|
import { writeClipboardSync } from './clipboardSync.js';
|
|
6
|
+
import { registerStageConsoleGuard, setTransientNotice } from './consoleGuard.js';
|
|
7
|
+
import { detectLinkAtPoint, openDetectedLink } from './smartLinkClick.js';
|
|
4
8
|
import { sidebarVisible, sessionMainWidth } from './sessionSidebar.js';
|
|
5
|
-
import { truncate, padEnd } from './text.js';
|
|
9
|
+
import { stripAnsi, truncate, padEnd } from './text.js';
|
|
6
10
|
// @ts-expect-error Legacy overlay has no declaration yet.
|
|
7
11
|
import { Layer } from './overlay.js';
|
|
8
12
|
// @ts-expect-error Legacy theme has no declaration yet.
|
|
9
13
|
import { paint, bold, fill } from './theme.js';
|
|
10
|
-
/**
|
|
14
|
+
/** Multi-action message menu overlay supporting Copy, Fork, and Revert. */
|
|
11
15
|
export class MessageActionsLayer extends Layer {
|
|
12
16
|
messageActions = true;
|
|
13
17
|
actionLayout = null;
|
|
@@ -39,8 +43,11 @@ export class MessageActionsLayer extends Layer {
|
|
|
39
43
|
});
|
|
40
44
|
}
|
|
41
45
|
key(event) {
|
|
42
|
-
if (event.name === 'escape')
|
|
46
|
+
if (event.name === 'escape') {
|
|
47
|
+
this.settled = true;
|
|
48
|
+
this.onPick(null);
|
|
43
49
|
return 'close';
|
|
50
|
+
}
|
|
44
51
|
if (event.name === 'up' || event.name === 'down') {
|
|
45
52
|
const delta = event.name === 'up' ? -1 : 1;
|
|
46
53
|
this.list.moveTo((this.list.selected + delta + this.items.length) % this.items.length);
|
|
@@ -51,8 +58,7 @@ export class MessageActionsLayer extends Layer {
|
|
|
51
58
|
this.onPick(this.items[this.list.selected] ?? null);
|
|
52
59
|
return 'close';
|
|
53
60
|
}
|
|
54
|
-
|
|
55
|
-
if (!e.ctrl && !e.alt && (e.name.length === 1 || e.name === 'space' || e.name === 'backspace')) {
|
|
61
|
+
if (!event.ctrl && !event.alt && (event.name.length === 1 || event.name === 'space' || event.name === 'backspace')) {
|
|
56
62
|
this.settled = true;
|
|
57
63
|
this.onPick(null);
|
|
58
64
|
return 'dismiss';
|
|
@@ -83,8 +89,25 @@ export function handleMessageMouse(host, loop, event) {
|
|
|
83
89
|
// SGR motion carries bit 32; it must update hover without opening the menu.
|
|
84
90
|
if (isMouseMotion(event.sequence))
|
|
85
91
|
return true;
|
|
86
|
-
if (mouse.button === 0 && mouse.pressed
|
|
87
|
-
|
|
92
|
+
if (mouse.button === 0 && mouse.pressed) {
|
|
93
|
+
// Smart link detection: if the user clicked (or Cmd/Ctrl+Clicked) on a URL or OSC 8 hyperlink,
|
|
94
|
+
// open the link directly in the system browser instead of popping up the Message Actions modal.
|
|
95
|
+
const hitLink = detectLinkAtPoint(surface, mouse, marker);
|
|
96
|
+
if (hitLink) {
|
|
97
|
+
openDetectedLink(hitLink.url);
|
|
98
|
+
writeClipboardSync(hitLink.url);
|
|
99
|
+
surface.hoveredMessageFrameId = null;
|
|
100
|
+
setTransientNotice(host, `Opened ${hitLink.url}`);
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
// Never open Message Actions on a modifier click (Ctrl/Alt/Shift+Click) that missed a link by 1 cell.
|
|
104
|
+
if (event.ctrl || event.alt || event.shift) {
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
if (marker) {
|
|
108
|
+
openMessageActions(host, loop, marker, mouse.y);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
88
111
|
return true;
|
|
89
112
|
}
|
|
90
113
|
const isMessage = (marker) => (marker.kind === 'user' || marker.kind === 'assistant')
|
|
@@ -118,8 +141,9 @@ export function messageAt(surface, point) {
|
|
|
118
141
|
}
|
|
119
142
|
return null;
|
|
120
143
|
}
|
|
121
|
-
/** Highlight only the visible rows of the hovered message, without altering transcript data. */
|
|
144
|
+
/** Highlight only the visible non-empty rows of the hovered message, without altering transcript data. */
|
|
122
145
|
export function markHoveredMessage(rows, surface, contentWidth) {
|
|
146
|
+
registerStageConsoleGuard(surface);
|
|
123
147
|
const id = surface.hoveredMessageFrameId;
|
|
124
148
|
if (!id)
|
|
125
149
|
return;
|
|
@@ -130,15 +154,32 @@ export function markHoveredMessage(rows, surface, contentWidth) {
|
|
|
130
154
|
const visible = Math.max(0, Math.min(rows.length, flat.rows.length - surface.viewport.scrollTop));
|
|
131
155
|
const padding = rows.length - visible;
|
|
132
156
|
const next = flat.markers[flat.markers.indexOf(marker) + 1];
|
|
133
|
-
const
|
|
134
|
-
const
|
|
157
|
+
const rawStart = marker.row;
|
|
158
|
+
const rawEnd = next?.row ?? flat.rows.length;
|
|
159
|
+
// Skip leading and trailing blank separator lines inside the message frame
|
|
160
|
+
// so we never paint a stray '▸' on an empty spacing row above '▸ Causyne'.
|
|
161
|
+
let firstContentRow = rawStart;
|
|
162
|
+
while (firstContentRow < rawEnd && stripAnsi(flat.rows[firstContentRow] ?? '').trim() === '') {
|
|
163
|
+
firstContentRow++;
|
|
164
|
+
}
|
|
165
|
+
let lastContentRow = rawEnd - 1;
|
|
166
|
+
while (lastContentRow > firstContentRow && stripAnsi(flat.rows[lastContentRow] ?? '').trim() === '') {
|
|
167
|
+
lastContentRow--;
|
|
168
|
+
}
|
|
169
|
+
if (firstContentRow >= rawEnd)
|
|
170
|
+
return;
|
|
171
|
+
const first = Math.max(firstContentRow, surface.viewport.scrollTop);
|
|
172
|
+
const last = Math.min(lastContentRow + 1, surface.viewport.scrollTop + visible);
|
|
135
173
|
for (let transcriptRow = first; transcriptRow < last; transcriptRow++) {
|
|
136
174
|
const row = transcriptRow - surface.viewport.scrollTop + padding;
|
|
137
175
|
if (row < padding || row >= rows.length)
|
|
138
176
|
continue;
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
177
|
+
const existingRow = rows[row] ?? '';
|
|
178
|
+
const plainTrimmed = stripAnsi(existingRow).trimStart();
|
|
179
|
+
const alreadyHasMarker = plainTrimmed.startsWith('▸') || plainTrimmed.startsWith('│');
|
|
180
|
+
const content = transcriptRow === firstContentRow && !alreadyHasMarker
|
|
181
|
+
? `${paint('accent', '▸')} ${truncate(existingRow, Math.max(0, contentWidth - 2), '')}`
|
|
182
|
+
: existingRow;
|
|
142
183
|
rows[row] = fill('surfaceHi', padEnd(content, contentWidth));
|
|
143
184
|
}
|
|
144
185
|
}
|
|
@@ -150,6 +191,23 @@ function messageText(content) {
|
|
|
150
191
|
? String(part.text) : '').filter(Boolean).join('\n');
|
|
151
192
|
return '';
|
|
152
193
|
}
|
|
194
|
+
function messagesMatch(persistedContent, shownText) {
|
|
195
|
+
if (typeof shownText !== 'string')
|
|
196
|
+
return false;
|
|
197
|
+
const persisted = messageText(persistedContent);
|
|
198
|
+
if (persisted === shownText)
|
|
199
|
+
return true;
|
|
200
|
+
const cleanPersisted = persisted.trim();
|
|
201
|
+
const cleanShown = shownText.trim();
|
|
202
|
+
if (!cleanShown)
|
|
203
|
+
return false;
|
|
204
|
+
if (cleanPersisted === cleanShown)
|
|
205
|
+
return true;
|
|
206
|
+
// Handle messages where an attachment system notification was appended on save
|
|
207
|
+
if (cleanPersisted.startsWith(cleanShown))
|
|
208
|
+
return true;
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
153
211
|
/** Match in conversation order; never guess a fork point from visual row alone. */
|
|
154
212
|
export function persistedMessageIndex(marker, markers, messages) {
|
|
155
213
|
let matched = -1;
|
|
@@ -159,7 +217,7 @@ export function persistedMessageIndex(marker, markers, messages) {
|
|
|
159
217
|
let found = -1;
|
|
160
218
|
for (let i = matched + 1; i < messages.length; i++) {
|
|
161
219
|
const message = messages[i];
|
|
162
|
-
if (message?.role === shown.kind &&
|
|
220
|
+
if (message?.role === shown.kind && messagesMatch(message.content, shown.meta?.messageText)) {
|
|
163
221
|
found = i;
|
|
164
222
|
break;
|
|
165
223
|
}
|
|
@@ -171,28 +229,96 @@ export function persistedMessageIndex(marker, markers, messages) {
|
|
|
171
229
|
}
|
|
172
230
|
return null;
|
|
173
231
|
}
|
|
232
|
+
function computeNextForkTitle(sourceTitle) {
|
|
233
|
+
const cleanBase = (sourceTitle && sourceTitle !== 'Untitled' ? sourceTitle : 'Conversation')
|
|
234
|
+
.replace(/\s*\(fork #\d+\)$/i, '')
|
|
235
|
+
.trim();
|
|
236
|
+
let maxForkNum = 0;
|
|
237
|
+
try {
|
|
238
|
+
const existing = listSessions();
|
|
239
|
+
const escaped = cleanBase.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
240
|
+
const forkRe = new RegExp(`^${escaped}\\s*\\(fork #(\\d+)\\)$`, 'i');
|
|
241
|
+
for (const s of existing) {
|
|
242
|
+
const m = forkRe.exec((s.title || '').trim());
|
|
243
|
+
if (m?.[1]) {
|
|
244
|
+
const n = Number(m[1]);
|
|
245
|
+
if (Number.isFinite(n) && n > maxForkNum)
|
|
246
|
+
maxForkNum = n;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
catch {
|
|
251
|
+
// Ignore session listing failures
|
|
252
|
+
}
|
|
253
|
+
return `${cleanBase} (fork #${maxForkNum + 1})`;
|
|
254
|
+
}
|
|
255
|
+
function syncInFlightMessagesToSession(loop, sourceId) {
|
|
256
|
+
if (!sourceId)
|
|
257
|
+
return null;
|
|
258
|
+
let source = getSession(sourceId);
|
|
259
|
+
const inMemory = Array.isArray(loop.messages)
|
|
260
|
+
? loop.messages.filter(m => m && m.role !== 'system')
|
|
261
|
+
: [];
|
|
262
|
+
const onDiskCount = source?.messages?.length ?? 0;
|
|
263
|
+
if (inMemory.length > onDiskCount) {
|
|
264
|
+
try {
|
|
265
|
+
if (typeof loop.memoryManager?.saveHistory === 'function') {
|
|
266
|
+
loop.memoryManager.saveHistory(loop.messages);
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
saveSessionMessages(sourceId, inMemory);
|
|
270
|
+
}
|
|
271
|
+
source = getSession(sourceId);
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
274
|
+
// Keep existing source record if disk sync fails
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return source;
|
|
278
|
+
}
|
|
174
279
|
export function openMessageActions(host, loop, marker, anchorY = null) {
|
|
175
280
|
const text = marker.meta?.messageText;
|
|
176
281
|
if (typeof text !== 'string')
|
|
177
282
|
return;
|
|
178
283
|
const sourceId = loop.memoryManager?.sessionId || getActiveSessionId();
|
|
179
|
-
const source =
|
|
284
|
+
const source = syncInFlightMessagesToSession(loop, sourceId);
|
|
180
285
|
const markers = host.surface?.transcript.flatten(host.surface.viewport.width).markers || [];
|
|
181
286
|
const index = source ? persistedMessageIndex(marker, markers, source.messages) : null;
|
|
287
|
+
const canModifySession = Boolean(source && index !== null);
|
|
182
288
|
const options = [
|
|
183
289
|
{ label: 'Copy message', description: 'to clipboard', value: 'copy' },
|
|
184
|
-
...(
|
|
290
|
+
...(canModifySession
|
|
291
|
+
? [
|
|
292
|
+
{ label: 'Fork from here', description: 'create a new session · fresh permissions', value: 'fork' },
|
|
293
|
+
{ label: 'Revert to here', description: 'undo messages and file changes', value: 'revert' }
|
|
294
|
+
]
|
|
295
|
+
: [])
|
|
185
296
|
];
|
|
186
297
|
const layer = new MessageActionsLayer(options, (choice) => {
|
|
187
|
-
if (
|
|
188
|
-
host.
|
|
298
|
+
if (host.surface) {
|
|
299
|
+
host.surface.hoveredMessageFrameId = null;
|
|
189
300
|
}
|
|
190
|
-
if (choice
|
|
301
|
+
if (!choice) {
|
|
302
|
+
host.scheduleDraw();
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
if (choice.value === 'copy') {
|
|
306
|
+
const ok = writeClipboardSync(text);
|
|
307
|
+
setTransientNotice(host, ok ? 'Message copied to clipboard' : 'Clipboard unavailable on this terminal');
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
if (choice.value === 'fork' && source && index !== null) {
|
|
311
|
+
if (host.busy) {
|
|
312
|
+
host.interrupt?.();
|
|
313
|
+
loop.abort?.();
|
|
314
|
+
syncInFlightMessagesToSession(loop, source.id);
|
|
315
|
+
}
|
|
316
|
+
const forkTitle = computeNextForkTitle(source.title);
|
|
191
317
|
const forked = loop.memoryManager?.sessionId === source.id && loop.memoryManager.forkSession
|
|
192
|
-
? loop.memoryManager.forkSession(
|
|
318
|
+
? loop.memoryManager.forkSession(forkTitle, index)
|
|
193
319
|
: null;
|
|
194
320
|
if (!forked) {
|
|
195
|
-
host
|
|
321
|
+
setTransientNotice(host, 'Could not fork this message; session was not changed');
|
|
196
322
|
}
|
|
197
323
|
else {
|
|
198
324
|
revokeAllAlways();
|
|
@@ -201,12 +327,43 @@ export function openMessageActions(host, loop, marker, anchorY = null) {
|
|
|
201
327
|
loop.messages = history;
|
|
202
328
|
loop.taskId = `cli_chat_${Date.now()}`;
|
|
203
329
|
loop.tokenTracker?.reset?.();
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
330
|
+
const info = { id: forked.id, title: forked.title, messagesCount: history.length };
|
|
331
|
+
host.renderer?.setSessionInfo?.(info);
|
|
332
|
+
host.renderer?.renderSessionHistory?.(history, info);
|
|
207
333
|
host.surface?.viewport?.toBottom?.();
|
|
208
|
-
host
|
|
334
|
+
setTransientNotice(host, `Forked into "${forked.title}". Permissions reset.`);
|
|
335
|
+
}
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
if (choice.value === 'revert' && source && index !== null) {
|
|
339
|
+
if (host.busy) {
|
|
340
|
+
host.interrupt?.();
|
|
341
|
+
loop.abort?.();
|
|
342
|
+
}
|
|
343
|
+
try {
|
|
344
|
+
undoLast({ dryRun: false, scope: 'code' });
|
|
345
|
+
}
|
|
346
|
+
catch {
|
|
347
|
+
// Checkpoints are optional if no files were modified in the reverted turn.
|
|
348
|
+
}
|
|
349
|
+
const latestSource = getSession(source.id) || source;
|
|
350
|
+
const keptMessages = latestSource.messages.slice(0, index);
|
|
351
|
+
saveSessionMessages(source.id, keptMessages);
|
|
352
|
+
if (loop.memoryManager?.session && loop.memoryManager.session.id === source.id) {
|
|
353
|
+
loop.memoryManager.session.messages = keptMessages;
|
|
354
|
+
}
|
|
355
|
+
const history = keptMessages.filter(m => m.role !== 'system');
|
|
356
|
+
loop.messages = history;
|
|
357
|
+
loop.taskId = `cli_chat_${Date.now()}`;
|
|
358
|
+
const info = { id: latestSource.id, title: latestSource.title, messagesCount: history.length };
|
|
359
|
+
host.renderer?.setSessionInfo?.(info);
|
|
360
|
+
host.renderer?.renderSessionHistory?.(history, info);
|
|
361
|
+
host.surface?.viewport?.toBottom?.();
|
|
362
|
+
if (marker.kind === 'user' && text) {
|
|
363
|
+
host.setText?.(text);
|
|
209
364
|
}
|
|
365
|
+
setTransientNotice(host, 'Reverted messages and file changes to selected point.');
|
|
366
|
+
return;
|
|
210
367
|
}
|
|
211
368
|
host.scheduleDraw();
|
|
212
369
|
}, anchorY);
|
|
@@ -218,7 +375,7 @@ export function handleMessageActionMenuMouse(layer, event) {
|
|
|
218
375
|
return null;
|
|
219
376
|
const { x, y, width, count } = layer.actionLayout;
|
|
220
377
|
const { mouse } = event;
|
|
221
|
-
const index = mouse.y - (y + 1); // only the frame precedes the
|
|
378
|
+
const index = mouse.y - (y + 1); // only the frame precedes the action rows
|
|
222
379
|
if (mouse.x < x || mouse.x >= x + width || index < 0 || index >= count) {
|
|
223
380
|
return mouse.button === 0 && mouse.pressed ? 'close' : 'handled';
|
|
224
381
|
}
|