From 4bd1ecb232ddca99eeab03b22049410e3cbdb792 Mon Sep 17 00:00:00 2001 From: Aiden Cline Date: Sun, 5 Jul 2026 23:38:43 -0500 Subject: [PATCH] fix(tui): restore prompt from undo autocomplete --- packages/tui/src/routes/session/index.tsx | 6 +----- packages/tui/src/util/revert-prompt.ts | 3 ++- packages/tui/test/util/revert-prompt.test.ts | 4 ++++ 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/tui/src/routes/session/index.tsx b/packages/tui/src/routes/session/index.tsx index e4ca24525f..d4afda850b 100644 --- a/packages/tui/src/routes/session/index.tsx +++ b/packages/tui/src/routes/session/index.tsx @@ -399,13 +399,9 @@ export function Session() { title: "Undo previous message", value: "session.undo", category: "Session", - slash: { name: "undo", aliases: ["revert"] }, + slash: { name: "undo" }, run: () => { void (async () => { - const current = prompt?.current - if (current && current.parts.length === 0 && ["/undo", "/revert"].includes(current.input.trim())) { - prompt?.reset() - } const boundary = session()?.revert?.messageID const list = messages() let target: SessionMessageUser | undefined diff --git a/packages/tui/src/util/revert-prompt.ts b/packages/tui/src/util/revert-prompt.ts index 8ea6533149..1469aa2b64 100644 --- a/packages/tui/src/util/revert-prompt.ts +++ b/packages/tui/src/util/revert-prompt.ts @@ -2,7 +2,8 @@ import type { SessionMessageUser } from "@opencode-ai/sdk/v2" import type { PromptInfo } from "../prompt/history" export function revertedPrompt(current: PromptInfo, message: SessionMessageUser): PromptInfo | undefined { - if (current.input || current.parts.length) return + const input = current.input.trim() + if (current.parts.length || (input && !"/undo".startsWith(input))) return return { input: message.text, diff --git a/packages/tui/test/util/revert-prompt.test.ts b/packages/tui/test/util/revert-prompt.test.ts index 30faed4a4c..7e9085a619 100644 --- a/packages/tui/test/util/revert-prompt.test.ts +++ b/packages/tui/test/util/revert-prompt.test.ts @@ -43,6 +43,10 @@ describe("reverted prompt", () => { }) }) + test.each(["/", "/u", "/un", "/und", "/undo", " /undo "])("replaces the undo autocomplete query %p", (input) => { + expect(revertedPrompt({ input, parts: [] }, message)?.input).toBe("Fix the tests") + }) + test("preserves an existing text draft", () => { expect(revertedPrompt({ input: "Keep this", parts: [] }, message)).toBeUndefined() })