🐛 fix(vscode): 移交回滚顺序、done 信号与无 branch 守卫

Claude-Session: https://claude.ai/code/session_011cEyL6k351U2BzX1Qmygph
This commit is contained in:
cruldra committed 2026-08-26 16:28:44 +08:00
1 parent 605f69f6a5
commit e066c26583
3 files changed
+109 -23

No files matched your search

+23 -3
View File
@@ -34,10 +34,28 @@ export function checkWorktreePushed(input: {
return { ok: true }
}
/**
* 共享墓碑:只写 handoffAttachmentId / handoffFrom 两个共享字段。本机
* sid/profile/worktreePath 墓碑要等本机清理跑完(成功指派后)才落盘,
* 见 handoffLocalTombstones —— 否则④/⑤失败回滚时本机字段已经被清空,
* 用户会话恢复不了。
*/
export function handoffStartedStateExtra(attachmentId: number, from: string): Record<string, unknown> {
const extra: Record<string, unknown> = { handoffAttachmentId: String(attachmentId), handoffFrom: from }
for (const f of LOCAL_STATE_FIELDS)
return { handoffAttachmentId: String(attachmentId), handoffFrom: from }
}
/**
* 本机墓碑:移交流程最后一步(本机清理跑完之后)才调用。worktree 删除失败时
* 保留 worktreePath(keepWorktreePath),别把用户还留在磁盘上的 worktree
* 从 state 里抹掉。
*/
export function handoffLocalTombstones(opts: { keepWorktreePath: boolean }): Record<string, string> {
const extra: Record<string, string> = {}
for (const f of LOCAL_STATE_FIELDS) {
if (f === 'worktreePath' && opts.keepWorktreePath)
continue
extra[f] = ''
}
return extra
}
@@ -89,7 +107,9 @@ export function handoffAcceptedUiPatch(local: {
handoffFrom: null,
...definedEntries(local.sessions),
...definedEntries(local.profiles),
...(local.worktreePath ? { worktreePath: local.worktreePath } : {}),
// 显式 null 而非省略:省略会让 webview 侧留着接管前的旧 worktreePath,
// 与 worktreeExists: false 对不上。
worktreePath: local.worktreePath ?? null,
worktreeExists: local.worktreeExists,
}
}