Skip to content

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

fix(turnrewind): address external review findings (redo deferred)

yingtianlancd683a0a458d
diff --git a/docs/TURN_REWIND_GIT_DIR_PROGRESS.md b/docs/TURN_REWIND_GIT_DIR_PROGRESS.md
index 66fe047c..8581fec9 100644
--- a/docs/TURN_REWIND_GIT_DIR_PROGRESS.md
+++ b/docs/TURN_REWIND_GIT_DIR_PROGRESS.md
@@ -90,6 +90,14 @@ Failed: 0
本分支功能与真机验证已完成,可作为实验分支评审;合并前仍需上游评估取舍(Git-only workspace、ignore 委托、预算守卫移除)。
+### 已按外部审查修复(2026-09-02)
+
+- P1 README 矛盾:删除旧「默认排除项」清单,改为「快照范围与敏感文件」——明确插件不提供敏感文件保护、未 ignore 的 .env/密钥会被快照,与 Git 目录模式实现一致;
+- P1 TURNREWIND_GIT_UNAVAILABLE 死代码:gitWorkspace 区分 spawn ENOENT(git 不在 PATH)与非 worktree,probeWorkspace/createSnapshotStore 报告真实原因(guard.test.js 新增空 PATH 用例);原先正常 worktree 但没装 git 的用户会看到误导性的 not a Git worktree;
+- P2 客户端空格路径:parseUndoOutput 的 (S+) 改为整行匹配并剥离 [conflict]/[too large] 标记,含空格路径正确进入文件清单(client-view.test.js 新增用例);
+- P2 测试超时统一为 120s(package.json 与 vitest.config.js,Windows 实测有用例超 30s);
+- P0 redo 无 operation/回滚/needs-recovery:**按决策暂缓**(功能冻结,README 标注「已知缺陷:redo」与启用条件)。
+
### 可选优化
1. 连通性检查的性能优化:当前每次 capture 走全链 `rev-list`(O(链上对象总数))。优化方向:常态走 `--not <parent>` 的增量检查 + 源对象库 mtime 变化时触发全链检查。大仓库上需先实测 capture 耗时;
diff --git a/plugins/dsh-tauri-turnrewind/README.md b/plugins/dsh-tauri-turnrewind/README.md
index d115b305..4f93130f 100644
--- a/plugins/dsh-tauri-turnrewind/README.md
+++ b/plugins/dsh-tauri-turnrewind/README.md
@@ -25,7 +25,7 @@
- 注册人类命令 `/undo`;
- `/undo` 默认处理当前会话最新的单个可恢复 turn,也可指定完整 turn ID;
- 同一 workspace 的活动 turn 或 undo 操作互斥;
-- 插件重启时将未完成 turn 标记为 abandoned;未完成的 Undo/Redo operation 会标记为 `needs-recovery`,对应 workspace 在清理前拒绝新的 rewind 操作,避免未知磁盘状态被继续覆盖;当前只能先人工检查 workspace,再停止 Host 并使用 `purge-workspace.js` 清理该 workspace 的 turnrewind 数据后恢复使用;
+- 插件重启时将未完成 turn 标记为 abandoned;未完成的 **Undo** operation 会标记为 `needs-recovery`,对应 workspace 在清理前拒绝新的 rewind 操作,避免未知磁盘状态被继续覆盖;**redo 路径尚未接入该机制**(已知缺陷,功能冻结中,见「已知缺陷:redo」);当前只能先人工检查 workspace,再停止 Host 并使用 `purge-workspace.js` 清理该 workspace 的 turnrewind 数据后恢复使用;
- 每次 Undo/Redo 的回退提示独立持久化;下一次模型 step 一次性注入全部 pending notice;
- 不修改用户项目的 HEAD、分支、index、stash 或提交历史。
@@ -295,42 +295,30 @@ stash
commit history
```
-## 默认排除项
+## 快照范围与敏感文件(Git 目录模式)
-为降低敏感信息和无关产物进入私有 snapshot 的风险,默认排除:
+> ⚠️ **插件不提供敏感文件保护。** 旧版本的自定义排除清单(`.env`、`*.pem`、`credentials.*`、`*token*` 等)已随 Git 目录模式**全部移除**。当前快照范围完全委托给源仓库的 ignore 规则:**未写进 `.gitignore` / `.git/info/exclude` / global excludes 的文件——包括 `.env`、密钥、证书——都会被捕获进私有快照**,并可被 `/undo` 恢复。
+
+插件自身只额外排除(不属于项目内容的部分):
```text
-.git/
-node_modules/
-dist/
-build/
-coverage/
-.turnrewind/
-.env
-.env.*
-*.pem
-*.key
-id_rsa*
-credentials.json # 任意深度
-credentials.yaml
-credentials.yml
-credentials.toml
-credentials.ini
-credentials.cfg
-secrets.json # 任意深度
-secrets.yaml
-secrets.yml
-secrets.toml
-secrets.ini
-secrets.cfg
+.git/ # Git 元数据
+.turnrewind/ # 插件临时目录
+**/*.turnrewind-*.tmp # 恢复过程中的临时文件
```
-注意两点边界:
+`node_modules/`、`dist/`、`build/` 等不再由插件排除——由你仓库自己的 `.gitignore` 决定(普通项目都会忽略它们,快照语义因此与源仓库一致)。
+
+两点边界:
-- 工作区自己的 `.gitignore` 和用户全局 gitignore 同样生效(`git add` 语义),被忽略的文件不会进入快照,也不会被 undo 恢复;
+- 被源仓库 ignore 的文件不会进入快照,也不会被 undo 恢复;ignore 规则每次 capture 重新读取(`.git/info/exclude` 还会同步进私有 repo);
- 曾经使用的 `*token*`、`*secret*` 等子串规则已移除——它们会静默排除 `token.ts`、`tokenizer.py` 这类正当源码,且被排除路径不出现在 dry-run 列表中,导致 undo 静默漏恢复。
-这些规则意味着:被排除文件的变化不会进入本 turn 的 Undo 范围。插件仍是实验原型,不应把它当作秘密信息保护工具。
+**如果不希望秘密文件进入快照**:把它们加进源仓库的 ignore 规则(对 git 和本插件同时生效)。也可以在 `/undo --dry-run` 的文件清单里核对实际被追踪的范围。插件仍是实验原型,不应把它当作秘密信息保护工具。
+
+### 已知缺陷:redo(暂缓)
+
+`/undo --redo` 的执行段**尚未**接入 operation 记录与失败回滚:执行中任一文件恢复失败(超大文件、目标路径变为 symlink/目录、rename 失败)会留下「部分 redo」状态,无回滚、无 `needs-recovery` 标记,重启后围栏不会拦截该 workspace。该功能目前按计划冻结、后续启用时与 undo 路径对齐(`createOperation` → 失败回滚 → `needs-recovery`)后再开放;在此之前请勿在含 >64 MB 文件或路径状态复杂的 turn 上使用 redo。
## Debug 安装
diff --git a/plugins/dsh-tauri-turnrewind/lib/client.js b/plugins/dsh-tauri-turnrewind/lib/client.js
index 0974a252..e49e2a45 100644
--- a/plugins/dsh-tauri-turnrewind/lib/client.js
+++ b/plugins/dsh-tauri-turnrewind/lib/client.js
@@ -63,9 +63,23 @@ function createTurnrewindClient(require) {
result.dividers.push(line)
continue
}
- const listed = /^ {2,}(modified|created|deleted) (\S+)$/.exec(line)
+ // Paths may contain spaces ("my notes.txt"), and the plan also appends
+ // " [conflict]" / " [too large]" flags. Match the whole remainder and
+ // split the flags off so such files land in the file list with the right
+ // classification instead of falling through to the diff-separator
+ // branch (which would misclassify them as conflicts).
+ const listed = /^ {2,}(modified|created|deleted) (.*\S)\s*$/.exec(line)
if (listed && !inDiffs) {
- result.files.push({ path: listed[2], change: listed[1], additions: 0, deletions: 0, diff: [] })
+ let path = listed[2]
+ let conflict = false
+ if (/\s{2,}\[conflict\]$/.test(path)) {
+ conflict = true
+ path = path.replace(/\s{2,}\[conflict\]$/, '')
+ }
+ if (/\s{2,}\[too large\]$/.test(path)) {
+ path = path.replace(/\s{2,}\[too large\]$/, '')
+ }
+ result.files.push({ path, change: listed[1], additions: 0, deletions: 0, diff: [], conflict })
continue
}
const separator = /^--- (?!a\/)(?!b\/)(.+)$/.exec(line)
diff --git a/plugins/dsh-tauri-turnrewind/lib/core/git-snapshot.js b/plugins/dsh-tauri-turnrewind/lib/core/git-snapshot.js
index 05faa1c3..c83f7c69 100644
--- a/plugins/dsh-tauri-turnrewind/lib/core/git-snapshot.js
+++ b/plugins/dsh-tauri-turnrewind/lib/core/git-snapshot.js
@@ -6,7 +6,7 @@ import { tmpdir } from 'node:os'
import { dirname, join, relative, resolve, sep } from 'node:path'
import process from 'node:process'
import { TextDecoder, TextEncoder } from 'node:util'
-import { gitWorkspace } from './git-workspace.js'
+import { gitUnavailableReason, gitWorkspace } from './git-workspace.js'
const MAX_FILE_BYTES = 64 * 1024 * 1024
const MAX_OUTPUT_BYTES = 64 * 1024 * 1024
@@ -203,7 +203,7 @@ export function workspaceHash(workspaceDir) {
export function createSnapshotStore(rootDir, workspaceDir) {
const source = gitWorkspace(workspaceDir)
if (!source)
- throw new Error(`TURNREWIND_GIT_REQUIRED: ${resolve(workspaceDir)} is not a Git worktree`)
+ throw new Error(gitUnavailableReason() ?? `TURNREWIND_GIT_REQUIRED: ${resolve(workspaceDir)} is not a Git worktree`)
const normalizedWorkspace = source.workspaceDir
const repoDir = join(rootDir, 'snapshots', `${workspaceHash(normalizedWorkspace)}.git`)
return {
@@ -224,7 +224,7 @@ export function createSnapshotStore(rootDir, workspaceDir) {
export function probeWorkspace(workspaceDir) {
const source = gitWorkspace(workspaceDir)
if (!source)
- return { ok: false, reason: 'TURNREWIND_GIT_REQUIRED: workspace is not a Git worktree' }
+ return { ok: false, reason: gitUnavailableReason() ?? 'TURNREWIND_GIT_REQUIRED: workspace is not a Git worktree' }
return { ok: true, workspaceDir: source.workspaceDir, commonDir: source.commonDir }
}
diff --git a/plugins/dsh-tauri-turnrewind/lib/core/git-workspace.js b/plugins/dsh-tauri-turnrewind/lib/core/git-workspace.js
index 5fa8618d..0eef57b8 100644
--- a/plugins/dsh-tauri-turnrewind/lib/core/git-workspace.js
+++ b/plugins/dsh-tauri-turnrewind/lib/core/git-workspace.js
@@ -23,10 +23,29 @@ function runGitSync(workspaceDir, args) {
* Resolve the canonical Git worktree and its metadata without changing Git
* state. The caller can use this to require a project Git boundary and to
* reuse Git objects/ignore behavior without touching the user's index.
+ *
+ * Returns undefined when the directory is not a Git worktree. A missing git
+ * executable (ENOENT on spawn) is distinguished by the module-level
+ * `gitExecutableMissing` flag: `gitUnavailableReason()` exposes it so callers
+ * report TURNREWIND_GIT_UNAVAILABLE instead of the misleading "not a Git
+ * worktree" message.
*/
+let gitExecutableMissing = false
+
+export function gitUnavailableReason() {
+ return gitExecutableMissing
+ ? 'TURNREWIND_GIT_UNAVAILABLE: the git executable was not found on PATH; file undo is disabled'
+ : undefined
+}
+
export function gitWorkspace(workspaceDir) {
const requestedDir = resolve(workspaceDir)
+ gitExecutableMissing = false
const inside = runGitSync(requestedDir, ['rev-parse', '--is-inside-work-tree'])
+ if (inside.error?.code === 'ENOENT') {
+ gitExecutableMissing = true
+ return undefined
+ }
const top = runGitSync(requestedDir, ['rev-parse', '--show-toplevel'])
const gitDir = runGitSync(requestedDir, ['rev-parse', '--git-dir'])
const commonDir = runGitSync(requestedDir, ['rev-parse', '--git-common-dir'])
diff --git a/plugins/dsh-tauri-turnrewind/package.json b/plugins/dsh-tauri-turnrewind/package.json
index e6dd7513..f8c6167b 100644
--- a/plugins/dsh-tauri-turnrewind/package.json
+++ b/plugins/dsh-tauri-turnrewind/package.json
@@ -28,7 +28,7 @@
"node": ">=22.15.0"
},
"scripts": {
- "test": "vitest run test --testTimeout=30000"
+ "test": "vitest run test --testTimeout=120000"
},
"devDependencies": {
"vitest": "^4.1.11"
diff --git a/plugins/dsh-tauri-turnrewind/test/client-view.test.js b/plugins/dsh-tauri-turnrewind/test/client-view.test.js
index 6612dff8..a823d294 100644
--- a/plugins/dsh-tauri-turnrewind/test/client-view.test.js
+++ b/plugins/dsh-tauri-turnrewind/test/client-view.test.js
@@ -92,3 +92,41 @@ it('parseUndoOutput still extracts the pending plan id', () => {
assert.equal(parsed.summary, 'Undo preflight: turn s:1; 1 file(s); 0 conflicts.')
assert.equal(parsed.files.length, 1)
})
+
+it('parseUndoOutput keeps paths with spaces and plan flags out of the conflict fallback', () => {
+ const bundle = loadBundle()
+ const parsed = bundle.parseUndoOutput([
+ 'Undo preflight: turn s:1; 3 file(s) (modified 2, created 1, deleted 0); 1 conflict(s).',
+ ' modified my notes.txt',
+ ' created reports/q3 summary.md',
+ ' modified assets/logo.png [conflict]',
+ ' modified assets/hero.png [too large]',
+ '',
+ 'Oversized files (over the 64 MB restore limit) cannot be restored by this undo; they will be reported as not restored:',
+ ' assets/hero.png',
+ '',
+ 'Undo will apply (turn output → restored state):',
+ '--- my notes.txt',
+ ' -new',
+ ' +old',
+ 'plan 0f1e2d3c',
+ 'Send /undo --confirm 0f1e2d3c to apply, or /undo --cancel 0f1e2d3c to dismiss.',
+ ].join('\n'))
+
+ assert.equal(parsed.files.length, 4)
+ assert.deepEqual(
+ parsed.files.map(file => [file.path, file.change, file.conflict]),
+ [
+ ['my notes.txt', 'modified', false],
+ ['reports/q3 summary.md', 'created', false],
+ ['assets/logo.png', 'modified', true],
+ ['assets/hero.png', 'modified', false],
+ ],
+ )
+ // The diff section attaches to the spaced path instead of creating a
+ // duplicate "conflict" entry for it.
+ const spaced = parsed.files.find(file => file.path === 'my notes.txt')
+ assert.equal(spaced.diff.length, 2)
+ assert.equal(spaced.additions, 1)
+ assert.equal(spaced.deletions, 1)
+})
diff --git a/plugins/dsh-tauri-turnrewind/test/guard.test.js b/plugins/dsh-tauri-turnrewind/test/guard.test.js
index 40d9f7ce..c90ecdfb 100644
--- a/plugins/dsh-tauri-turnrewind/test/guard.test.js
+++ b/plugins/dsh-tauri-turnrewind/test/guard.test.js
@@ -70,3 +70,33 @@ it('canonicalizes a session cwd below the worktree root to the Git root', async
await rm(root, { recursive: true, force: true })
}
})
+
+it('reports the missing git executable instead of a misleading not-a-worktree reason', async () => {
+ const root = await mkdtemp(join(tmpdir(), 'turnrewind-guard-nogit-'))
+ try {
+ await writeFile(join(root, 'plain.txt'), 'x')
+ const savedPath = process.env.PATH
+ // An empty PATH makes the synchronous spawn fail with ENOENT, exactly
+ // like a machine without git on PATH.
+ process.env.PATH = ''
+ try {
+ const probe = probeWorkspace(root)
+ assert.equal(probe.ok, false)
+ assert.match(probe.reason, /TURNREWIND_GIT_UNAVAILABLE/)
+ assert.throws(
+ () => createSnapshotStore(join(root, 'data'), root),
+ /TURNREWIND_GIT_UNAVAILABLE/,
+ )
+ }
+ finally {
+ process.env.PATH = savedPath
+ }
+ // With git back on PATH the same directory reports the ordinary reason.
+ const probe = probeWorkspace(root)
+ assert.equal(probe.ok, false)
+ assert.match(probe.reason, /TURNREWIND_GIT_REQUIRED/)
+ }
+ finally {
+ await rm(root, { recursive: true, force: true })
+ }
+})
diff --git a/plugins/dsh-tauri-turnrewind/vitest.config.js b/plugins/dsh-tauri-turnrewind/vitest.config.js
index f615125f..b5e21240 100644
--- a/plugins/dsh-tauri-turnrewind/vitest.config.js
+++ b/plugins/dsh-tauri-turnrewind/vitest.config.js
@@ -5,6 +5,6 @@ import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
include: ['test/**/*.test.js'],
- testTimeout: 30000,
+ testTimeout: 120000,
},
})