feat(conversation): replicate WorkBuddy rewind-to-message action (TODO 05)

This commit is contained in:
xiaohan.yuan committed 2026-10-17 06:52:56 +08:00
1 parent 074523a501
commit c7ab047d52
11 files changed
+293 -60

No files matched your search

+3 -2
View File
@@ -509,12 +509,13 @@ export function registerIpc(getWindow: () => BrowserWindow | null): void {
if ([...runTasks.values()].some((run) => run.sessionId === sessionId)) throw new Error('请先停止当前运行')
const history = [...await sessions.getMessages(sessionId)]
const index = history.findIndex((item) => item.id === messageId && item.role === 'user')
if (index < 0) throw new Error('未找到用户消息')
const changes = getRevertChanges(history, messageId)
if (!changes.length) throw new Error('此版本没有可恢复的文件修改')
const workspace = await sessionRoot(sessionId)
const kernel = await getOmpKernel(sessionId, workspace, await models.resolveModel((await sessions.getSessionContext(sessionId)).modelId))
if (kernel && !history[index].nativeEntryId) throw new Error('缺少原生会话分支,无法同时恢复上下文')
const undo = await restoreWorkspaceFiles(workspace, changes)
// 原版 rewind 的 no-version 变体:没有产物版本时仅回退对话内容,不触碰文件。
const undo = changes.length ? await restoreWorkspaceFiles(workspace, changes) : async () => undefined
try {
if (kernel) {
const response = await kernel.branch(history[index].nativeEntryId!)