Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

fix(turnrewind): precise cancel outcomes, separate gone-plan hint from expiry

yingtianlan884f15547bd7
diff --git a/packages/dsh-tauri-turnrewind-ts/src/client/components/command-view.ts b/packages/dsh-tauri-turnrewind-ts/src/client/components/command-view.ts
index ada60056..f8b8f1f7 100644
--- a/packages/dsh-tauri-turnrewind-ts/src/client/components/command-view.ts
+++ b/packages/dsh-tauri-turnrewind-ts/src/client/components/command-view.ts
@@ -300,7 +300,11 @@ export function UndoCommandView(props: CommandViewProps): React.ReactElement {
? `${tr('confirmFailed')}${submitError}`
: resultText || (planStatus === 'applied' || pendingWait
? tr('cardWaitingResult')
- : planStatus === 'expired' || planStatus === 'gone' ? tr('planExpiredHint') : planStatus === 'cancelled' || submitted === 'cancel' ? tr('cancelled') : tr('previewHint'))
+ : planStatus === 'expired'
+ ? tr('planExpiredHint')
+ : planStatus === 'gone'
+ ? tr('planGoneHint')
+ : planStatus === 'cancelled' || submitted === 'cancel' ? tr('cancelled') : tr('previewHint'))
// 执行结果(成功/失败)靠左展示;「已提交,等待执行结果」与预览提示一样
// 贴 footer 右缘——等执行结果落地(resultText/applied)再切到左侧。
const hintLeft = Boolean(resultText || submitError || planStatus === 'applied')
diff --git a/packages/dsh-tauri-turnrewind-ts/src/client/locales/index.ts b/packages/dsh-tauri-turnrewind-ts/src/client/locales/index.ts
index 5184732c..af85a1cc 100644
--- a/packages/dsh-tauri-turnrewind-ts/src/client/locales/index.ts
+++ b/packages/dsh-tauri-turnrewind-ts/src/client/locales/index.ts
@@ -21,6 +21,7 @@ export type LocaleKey
| 'cancelCancelling'
| 'cancelled'
| 'planExpiredHint'
+ | 'planGoneHint'
| 'previewHint'
| 'sessionMissing'
@@ -43,6 +44,7 @@ const DICT_ZH: Record<LocaleKey, string> = {
cancelCancelling: '取消中…',
cancelled: '已取消',
planExpiredHint: '该计划已过期,重新执行 /undo 可生成新预览',
+ planGoneHint: '该计划不存在(可能已被清理或来自旧版本数据)',
previewHint: '执行将恢复下方文件到本轮改动前',
sessionMissing: '无法确定该卡片所属的会话,请刷新页面后重试',
}
@@ -66,6 +68,7 @@ const DICT_EN: Record<LocaleKey, string> = {
cancelCancelling: 'Cancelling…',
cancelled: 'Cancelled',
planExpiredHint: 'This plan has expired; run /undo again for a fresh preview',
+ planGoneHint: 'This plan no longer exists (it may have been purged or comes from older data)',
previewHint: 'Applying restores the files below to their state before this turn',
sessionMissing: 'Cannot determine the session this card belongs to; refresh the page and try again',
}
diff --git a/packages/dsh-tauri-turnrewind-ts/src/host/apply.ts b/packages/dsh-tauri-turnrewind-ts/src/host/apply.ts
index 1d814468..0395ef1b 100644
--- a/packages/dsh-tauri-turnrewind-ts/src/host/apply.ts
+++ b/packages/dsh-tauri-turnrewind-ts/src/host/apply.ts
@@ -564,8 +564,25 @@ export function apply(ctx: HostApplyContext): void {
return [400, { error: 'planId and sessionId are required' }]
if (!validPlanId(planId) || !validSessionId(sessionId))
return [400, { error: 'planId or sessionId is malformed' }]
+ // 非 pending 行返回精确错误而不是 200 假成功:假成功会让客户端先塌缩成
+ // 「已取消」,刷新后又被轮询纠正成别的状态——状态必须一次说清。
+ const row = getPendingPlanRow(ledger, planId)
+ if (row === undefined)
+ return [404, { error: 'plan not found — run /undo again' }]
+ if (row.session_id !== sessionId)
+ return [403, { error: 'the plan belongs to another session' }]
+ if (row.status === 'cancelled')
+ return [200, { ok: true, message: 'Pending undo cancelled.' }]
+ if (row.status === 'expired')
+ return [409, { error: 'this plan has expired — run /undo again to preview a fresh plan' }]
+ if (row.status === 'applied')
+ return [409, { error: 'this plan was already applied' }]
+ if (row.status === 'applying')
+ return [409, { error: 'this plan is being applied — wait for it to finish' }]
const removed = markPendingPlanCancelled(ledger, planId, sessionId)
- return [200, { ok: true, message: removed ? 'Pending undo cancelled.' : 'No pending plan matched (it may have expired).' }]
+ if (!removed)
+ return [409, { error: 'this plan was already applied or cancelled — run /undo again' }]
+ return [200, { ok: true, message: 'Pending undo cancelled.' }]
}
function statusRoute(_body: Record<string, unknown>, req: { url?: string }): [number, unknown] {
diff --git a/packages/dsh-tauri-turnrewind-ts/test/ledger.test.js b/packages/dsh-tauri-turnrewind-ts/test/ledger.test.js
index 00d0073e..c573e5c4 100644
--- a/packages/dsh-tauri-turnrewind-ts/test/ledger.test.js
+++ b/packages/dsh-tauri-turnrewind-ts/test/ledger.test.js
@@ -137,6 +137,44 @@ it('never double-claims notices across concurrent ledger connections', async ()
}
})
+it('keeps cancelled plans archived across newer previews and past their TTL', async () => {
+ const root = await mkdtemp(join(tmpdir(), 'turnrewind-plan-archive-'))
+ const db = openLedger(root)
+ try {
+ const planA = createPendingPlan(db, {
+ sessionId: 'session',
+ workspaceKey: 'workspace',
+ turnId: 'session:1',
+ paths: ['a.txt'],
+ beforeRef: 'refs/turnrewind/turn-session-1-before',
+ afterRef: 'refs/turnrewind/turn-session-1-after',
+ })
+ assert.equal(markPendingPlanCancelled(db, planA, 'session'), true)
+
+ // A newer preview archives only the pending predecessor: the user's
+ // explicit dismissal stays 'cancelled' — refresh must reproduce it.
+ const planB = createPendingPlan(db, {
+ sessionId: 'session',
+ workspaceKey: 'workspace',
+ turnId: 'session:2',
+ paths: ['b.txt'],
+ beforeRef: 'refs/turnrewind/turn-session-2-before',
+ afterRef: 'refs/turnrewind/turn-session-2-after',
+ })
+ assert.equal(getPendingPlanStatus(db, planA, 'session')?.status, 'cancelled')
+
+ // Past-TTL sweeping (startup or lazy) flips only pending rows.
+ db.prepare('UPDATE pending_plans SET expires_at = ?').run(new Date(Date.now() - 1000).toISOString())
+ prunePendingPlans(db)
+ assert.equal(getPendingPlanStatus(db, planA, 'session')?.status, 'cancelled')
+ assert.equal(getPendingPlanStatus(db, planB, 'session')?.status, 'expired')
+ }
+ finally {
+ db.close()
+ await rm(root, { recursive: true, force: true })
+ }
+})
+
it('records a skipped turn with a single unsupported-workspace heads-up', async () => {
const root = await mkdtemp(join(tmpdir(), 'turnrewind-skip-test-'))
const db = openLedger(root)