Skip to content

Commit 0c0bee6

Browse files
committed
fix(ui): update undo messages to improve clarity and user guidance
1 parent 56b2973 commit 0c0bee6

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

‎packages/cli/src/tests/undo-draft.test.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ test("busy /undo keeps history visible but only allows changing pending prompts"
239239
await h.setBusy(true);
240240
await h.submit("/undo");
241241
assert.match(h.latest(), /今天星期几/);
242-
assert.match(h.latest(), /Unavailable while running/);
242+
assert.match(h.latest(), /↑\/↓ navigate · Esc cancel/);
243243
assert.doesNotMatch(h.latest(), /Enter choose/);
244244
assert.doesNotMatch(h.latest(), /Nothing to undo/);
245245
await h.send("\r");
@@ -253,13 +253,13 @@ test("busy /undo keeps history visible but only allows changing pending prompts"
253253
assert.match(h.latest(), /pending input/);
254254
assert.match(h.latest(), / · pending/);
255255
assert.match(h.latest(), /Enter choose/);
256-
assert.doesNotMatch(h.latest(), /Unavailable while running/);
256+
assert.doesNotMatch(h.latest(), /↑\/↓ navigate · Esc cancel/);
257257
await h.send("\x1b[A");
258-
assert.match(h.latest(), /Unavailable while running/);
258+
assert.match(h.latest(), /↑\/↓ navigate · Esc cancel/);
259259
assert.doesNotMatch(h.latest(), /Enter choose/);
260260
await h.send("\x1b[B");
261261
assert.match(h.latest(), /Enter choose/);
262-
assert.doesNotMatch(h.latest(), /Unavailable while running/);
262+
assert.doesNotMatch(h.latest(), /↑\/↓ navigate · Esc cancel/);
263263
await h.send("\r");
264264
assert.match(h.latest(), /Remove/);
265265
assert.match(h.latest(), /Edit/);
@@ -273,7 +273,7 @@ test("busy /undo keeps history visible but only allows changing pending prompts"
273273
await h.setBusy(false);
274274
await h.submit("/undo");
275275
assert.match(h.latest(), /Enter choose/);
276-
assert.doesNotMatch(h.latest(), /Unavailable while running/);
276+
assert.doesNotMatch(h.latest(), /↑\/↓ navigate · Esc cancel/);
277277
await h.send("\r");
278278
assert.match(h.latest(), /Restore conversation/);
279279
});

‎packages/cli/src/ui/views/UndoSelector.tsx‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useMemo, useState } from "react";
22
import { Box, Text, useInput, useWindowSize } from "ink";
3-
import type { UndoTarget, QueuedMessage } from "@vegamo/deepcode-core";
3+
import type { UndoTarget, QueuedMessage, SessionMessage } from "@vegamo/deepcode-core";
4+
import { extractImageUrlsFromContentParams } from "../utils";
45

56
export type UndoRestoreMode = "code-and-conversation" | "conversation" | "remove" | "edit";
67
export type QueueUndoTarget = UndoTarget & { queued?: QueuedMessage };
@@ -145,7 +146,7 @@ export function UndoSelector({ targets, busy = false, onSelect, onCancel }: Prop
145146
<Text color={disabled ? "gray" : "#229ac3"}>{isActive ? "> " : " "}</Text>
146147
<Box flexDirection="column" flexGrow={1}>
147148
<Text color={isActive && !disabled ? "#229ac3" : undefined} bold={isActive} dimColor={disabled}>
148-
{formatUndoMessage(target.message.content)}
149+
{formatUndoMessage(target.message)}
149150
</Text>
150151
<Text dimColor>
151152
{formatTimestamp(target.message.createTime)}
@@ -170,7 +171,7 @@ export function UndoSelector({ targets, busy = false, onSelect, onCancel }: Prop
170171
overflow="hidden"
171172
>
172173
<Text dimColor>Selected message:</Text>
173-
<Text>{formatUndoMessage(selectedTarget?.message.content ?? "")}</Text>
174+
<Text>{formatUndoMessage(selectedTarget?.message)}</Text>
174175
{!selectedTarget ? (
175176
<Text>This message is no longer available.</Text>
176177
) : selectionDisabled ? (
@@ -208,7 +209,7 @@ export function UndoSelector({ targets, busy = false, onSelect, onCancel }: Prop
208209
<Box>
209210
<Text dimColor>
210211
{selectionDisabled
211-
? "Unavailable while running"
212+
? "↑/↓ navigate · Esc cancel"
212213
: phase === "message"
213214
? "↑/↓ navigate · Enter choose · Esc cancel"
214215
: "↑/↓ choose · Enter confirm · Esc back"}
@@ -219,9 +220,13 @@ export function UndoSelector({ targets, busy = false, onSelect, onCancel }: Prop
219220
);
220221
}
221222

222-
function formatUndoMessage(content: unknown): string {
223+
function formatUndoMessage(message?: SessionMessage): string {
224+
const content = message?.content;
225+
const imageCount =
226+
message?.meta?.userPrompt?.imageUrls?.length ?? extractImageUrlsFromContentParams(message?.contentParams).length;
223227
const text = typeof content === "string" && content.trim() ? content.trim() : "(empty message)";
224-
const singleLine = text.replace(/\r?\n/g, " ").replace(/\s+/g, " ");
228+
const prefix = imageCount > 0 ? `(📎 ${imageCount} images) ` : "";
229+
const singleLine = prefix + text.replace(/\r?\n/g, " ").replace(/\s+/g, " ");
225230
return singleLine.length > 90 ? `${singleLine.slice(0, 89)}…` : singleLine;
226231
}
227232

0 commit comments

Comments
 (0)