DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix(turnrewind): per-session-once heads-up, archive-backed
yingtianlan9f026caa5155
diff --git a/packages/dsh-tauri-turnrewind-ts/README.md b/packages/dsh-tauri-turnrewind-ts/README.mdindex 77caab62..b816c6d9 100644--- a/packages/dsh-tauri-turnrewind-ts/README.md+++ b/packages/dsh-tauri-turnrewind-ts/README.md@@ -17,7 +17,7 @@- **快照链自愈**:私有快照仓库被删/损坏后,下一次捕获自动降级重建基线(日志有一条 warning),后续 turn 照常可撤销;被清空前留下来的旧 turn 会在 `/undo` 选目标时自动识别为死快照并标记跳过(`snapshot ref missing`),不会甩出 git 原始报错;- **alternates 失效自愈**:私有 repo 通过 alternates 借用源仓库对象,而源仓库 `git gc --prune=now`(amend/rebase 的日常残留)可能删掉被借用且不可达的对象;每次 capture 后做连通性检查(`git rev-list --objects --missing=print`),发现缺对象即降级为自包含存储(不再借用、不再复制源 index)并重建基线,旧 turn 走死快照跳过路径;- **工作区资格守卫(Git 目录模式)**:会话 cwd 必须位于 Git worktree(子目录自动归并到 worktree 根,共享同一快照域);家目录、家目录祖先、盘根等系统目录直接拒绝;非 Git 目录记为 `TURNREWIND_GIT_REQUIRED`,不再做全目录预算扫描(见「工作区资格」);-- **不可用弹窗**:客户端半(`src/client/`)通过 `turnrewind` 会话投影检测到不可用提示时,在 Web UI 内弹出模态对话框(中英双语、跟随应用主题、每个浏览器只弹一次);+- **不可用弹窗**:客户端半(`src/client/`)通过 `turnrewind` 会话投影检测到不可用提示时,在 Web UI 内弹出模态对话框(中英双语、跟随应用主题)。**单会话只报一次**:提示以会话内消息形式永久留档可查,弹窗只对页面存活期间新到达的提示触发,历史提示(重启后重新进入会话)不会重复弹窗;- **两阶段 `/undo`**:先出预览卡(红绿 diff + `+x -y` 徽标 + 文件清单),卡内 ✓/✗ 按钮确认执行或取消——不看预览就不会误执行;计划 5 分钟过期,过期/取消的 plan **永久留档**:卡片保留文件清单与 diff 供随时回看(过期只锁执行、不抹记录),确认时二次校验磁盘与预览绑定;- 恢复前比较当前文件与 turn 完成时的快照,发现变化则拒绝覆盖,并给出「turn 产物 → 当前磁盘」的冲突 diff;- 冲突可用 `--skip-conflicts`(只恢复无冲突文件)或 `--force`(强制覆盖)直接执行;diff --git a/packages/dsh-tauri-turnrewind-ts/src/client/constants/index.ts b/packages/dsh-tauri-turnrewind-ts/src/client/constants/index.tsindex ff5fff07..28e4d4ba 100644--- a/packages/dsh-tauri-turnrewind-ts/src/client/constants/index.ts+++ b/packages/dsh-tauri-turnrewind-ts/src/client/constants/index.ts@@ -29,11 +29,5 @@ export const COMMAND_VIEW_EFFECT = 'turnrewind command view'/** locale 命名空间(不可用弹窗双语)。 */export const TURNREWIND_LOCALE_NS = 'dsh-tauri-turnrewind'-/** 弹窗已读去重的 localStorage key。 */-export const SEEN_NOTICES_KEY = 'turnrewind.seenUnsupportedNotices'--/** 弹窗去重列表长度上限。 */-export const MAX_SEEN_NOTICES = 100-/** 同源 HTTP 路由前缀(Host 注册的 /api/turnrewind/*)。 */export const TURNREWIND_HTTP_BASE = '/api/turnrewind'diff --git a/packages/dsh-tauri-turnrewind-ts/src/client/index.ts b/packages/dsh-tauri-turnrewind-ts/src/client/index.tsindex 711fd594..cdf3a68e 100644--- a/packages/dsh-tauri-turnrewind-ts/src/client/index.ts+++ b/packages/dsh-tauri-turnrewind-ts/src/client/index.ts@@ -13,7 +13,7 @@ import { setSubmitLine } from './components/command-view'import { TURNREWIND_HTTP_BASE, TURNREWIND_LOCALE_NS } from './constants'import { LOCALES } from './locales'import { registerCommandView } from './register/command-view'-import { disposeDialog, pickFreshNotices, showDialog } from './register/dialog'+import { disposeDialog, listNotices, showDialog } from './register/dialog'import { mountCommandViewStyles, mountDialogStyles } from './styles'import { parseUndoOutput, resolvePlanStatus } from './utils/parse'import { resolveOwnerSessionId } from './utils/session'@@ -90,11 +90,15 @@ export function apply(ctx: ClientContext): void {}, 'turnrewind submit line')// ————————————————— 不可用工作区弹窗 runner —————————————————- // 通过 sessions.list 的投影值读取 Host 注入的 unsupported 提示,- // 每条提示在 localStorage 去重——同一浏览器只弹一次。+ // 通过 sessions.list 的投影值读取 Host 注入的 unsupported 提示。+ // 「单会话只报一次」:进入会话(或页面加载)时已存在的提示视为历史留档+ // ——它们已经以会话内消息的形式永久可见,不再重复弹窗(浏览器存储丢+ // 「已读」也不会重弹);只有页面存活期间新到达的提示才弹一次。const sessions = (ctx as unknown as { get?: (name: string) => unknown }).get?.('sessions') as| { list: { getSnapshot: () => unknown, subscribe: (fn: () => void) => () => void } }| undefined+ const knownNoticeIds = new Set<string>()+ let seededSession: unknown = nullfunction checkOnce(): void {if (!sessions)@@ -104,10 +108,19 @@ export function apply(ctx: ClientContext): void {byId?: Record<string, { projectionValues?: { turnrewind?: unknown } }>}const summary = state.current !== undefined ? state.byId?.[state.current] : undefined- const value = summary?.projectionValues?.turnrewind- const fresh = pickFreshNotices(value)+ const notices = listNotices(summary?.projectionValues?.turnrewind)+ // 首次观察到当前会话(页面加载/切换会话):现存提示全部视为已留档历史。+ if (seededSession !== state.current) {+ seededSession = state.current+ for (const notice of notices)+ knownNoticeIds.add(notice.id)+ return+ }+ const fresh = notices.filter(notice => !knownNoticeIds.has(notice.id))if (fresh.length === 0)return+ for (const notice of fresh)+ knownNoticeIds.add(notice.id)console.warn(`[turnrewind] unsupported heads-up visible: ${fresh.map(notice => notice.id).join(', ')}`)showDialog(t, fresh)}diff --git a/packages/dsh-tauri-turnrewind-ts/src/client/register/dialog.ts b/packages/dsh-tauri-turnrewind-ts/src/client/register/dialog.tsindex d66794a5..636beb30 100644--- a/packages/dsh-tauri-turnrewind-ts/src/client/register/dialog.ts+++ b/packages/dsh-tauri-turnrewind-ts/src/client/register/dialog.ts@@ -1,12 +1,16 @@/**- * client/register/dialog.ts — 不可用工作区的模态弹窗(双语 + 主题 token + 去重)。+ * client/register/dialog.ts — 不可用工作区的模态弹窗(双语 + 主题 token)。+ *+ * 弹窗去重不在浏览器存储里做(localStorage 会因换端口/清存储而丢「已读」,+ * 导致历史提示反复重弹):调用方按「单会话一次」种子逻辑只对页面存活期间+ * 新到达的提示弹窗,历史提示以会话内消息形式永久留档、不再打扰。** DOM 直挂(非 React 组件):弹窗只在 apply 生命周期内存在,stop/HMR 时整个* backdrop 子树移除(所有 listener 挂在子树节点上,不会泄漏)。*/import type { LocaleKey } from '../locales'-import { MAX_SEEN_NOTICES, SEEN_NOTICES_KEY, TURNREWIND_CLASS_PREFIX, TURNREWIND_STYLE_ID } from '../constants'+import { TURNREWIND_CLASS_PREFIX, TURNREWIND_STYLE_ID } from '../constants'export interface UnsupportedNotice {id: string@@ -24,31 +28,6 @@ interface DialogElements {let dialog: DialogElements | undefined-// -------------------------------------------------------------------// localStorage 去重:同一浏览器每条提示只弹一次。-// -------------------------------------------------------------------function readSeen(): string[] {- try {- const raw = globalThis.localStorage.getItem(SEEN_NOTICES_KEY)- const list = raw ? JSON.parse(raw) : []- return Array.isArray(list) ? list : []- }- catch {- return []- }-}--function markSeen(id: string): void {- try {- const seen = readSeen().filter(entry => entry !== id)- seen.push(id)- globalThis.localStorage.setItem(SEEN_NOTICES_KEY, JSON.stringify(seen.slice(-MAX_SEEN_NOTICES)))- }- catch {- // Storage 不可用时下次重弹即可。- }-}-// ------------------------------------------------------------------// 弹窗 DOM:所有颜色走 CSS variable(随主题实时切换),fallback 到硬编码值。// ------------------------------------------------------------------@@ -120,17 +99,16 @@ export function showDialog(t: (key: LocaleKey) => string, notices: UnsupportedNoel.backdrop.dataset.visible = 'true'}-/** 从会话投影中筛选未见过的提示并标记已读。 */-export function pickFreshNotices(value: unknown): UnsupportedNotice[] {- const notices = Array.isArray((value as { notices?: unknown[] })?.notices)+/**+ * 从会话投影中提取 unsupported 提示(不去重)。去重由调用方的+ * 「单会话一次」种子逻辑承担:进入会话时已存在的提示视为历史留档+ * (会话内消息永久可见),只有页面存活期间新到达的提示才弹窗。+ */+export function listNotices(value: unknown): UnsupportedNotice[] {+ return (Array.isArray((value as { notices?: unknown[] })?.notices)? (value as { notices: unknown[] }).notices- : []- const fresh = notices.filter((notice): notice is UnsupportedNotice =>- notice != null && typeof (notice as UnsupportedNotice).id === 'string' && !readSeen().includes((notice as UnsupportedNotice).id))- if (fresh.length > 0) {- for (const notice of fresh) markSeen(notice.id)- }- return fresh+ : []).filter((notice): notice is UnsupportedNotice =>+ notice != null && typeof (notice as UnsupportedNotice).id === 'string')}/** style id 导出(供测试断言/未来的 css-render 迁移使用)。 */