DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix(turnrewind): 嵌套仓库不再让运行中读数凭空多出文件
hairyfd371fc3291c9
diff --git a/packages/dsh-tauri-turnrewind/README.md b/packages/dsh-tauri-turnrewind/README.mdindex f060763f..cc6c4aa7 100644--- a/packages/dsh-tauri-turnrewind/README.md+++ b/packages/dsh-tauri-turnrewind/README.md@@ -125,6 +125,11 @@ $DSH_HOME/dsh-tauri-turnrewind/私有仓超过 2048 MB 时整体隔离改名 → 轮换代数 → 删除隔离目录。- **嵌套 Git 仓库**:自动跳过并标注。有界预扫(深度 ≤2 / ≤2000 目录)+ `git add` 报错兜底;这些目录里的改动**不在撤销范围内**,卡片如实提示——gitlink 指针变化会造成「撤销成功但目录内容没变」的假象。+ **运行中读数走同一套排除**(本轮学到的路径在 `entry.exclusions`,嵌套目录另有+ `entry.nestedDirs` 并一并传进 `liveDiff`):目录语义的排除必须带 `:(exclude,glob)dir/**`,+ 漏掉时实时读数的 `git add --all` 会把这些仓库当 gitlink 写进私有 index,而 before 快照里+ 没有它们的条目——提示条于是凭空显示「2 个文件已更改 +2 -0」,工作区却一个字节都没动+ (用户实际反馈;仓库里恰有两个被跟踪的嵌套仓库时正是这个读数)。## 边界与已知限制@@ -238,7 +243,8 @@ pnpm build # 根构建:prebuild 部署插件到 src-tauri/resourcesCRLF/属性往返对称(恢复后与 before 快照树逐字节等价)、冲突预检(含「用户重建已删除文件」)、撤销全路径(含代数不符 / refs 消失 → 过期终态、轮次仍在跑 → 拒绝)、运行中实时读数(含本轮新建文件,且与最终 after 差异文件数一致;**已被排除的路径即使还在-私有 index 里也不计入**)、+私有 index 里也不计入**;**嵌套仓库目录(`nestedDirs`)不算改动**——否则提示条会在工作区+毫无变化时报出「2 个文件已更改 +2 -0」)、**捕获与结算的时序**(正常一轮落账;`turn/end` / idle 落在 before 快照还在飞时这一轮仍被结算;两个事件同时到达只结算一次;idle 之后新开始的一轮不被兜底误结算;没有 before 快照的 turn 不会被凭空记一笔;before 快照抛异常时仍留审计行;结算中途抛错时保留条目、下一次 idle 兜底补上)、diff --git a/packages/dsh-tauri-turnrewind/src/host/service/capture.test.ts b/packages/dsh-tauri-turnrewind/src/host/service/capture.test.tsindex a78011fa..4f5f3f78 100644--- a/packages/dsh-tauri-turnrewind/src/host/service/capture.test.ts+++ b/packages/dsh-tauri-turnrewind/src/host/service/capture.test.ts@@ -342,4 +342,32 @@ describe('运行中提示条的读数生命周期', () => {expect(capture.isTurnPending('s14', 1)).toBe(false)expect(capture.isTurnPending('s14')).toBe(false)})++ it('工作区里的嵌套仓库不会让运行中读数凭空多出文件(提示条假报 +N)', async () => {+ // 回归背景:`entry.nestedDirs` 此前只用于结算时的 after 快照,没传进 liveDiff ——+ // 实时读数的 `git add --all` 会把嵌套仓库当 gitlink 写进私有 index,而 before+ // 快照里没有它们,读数于是报出「2 个文件已更改 +2 -0」这种工作区根本没发生过的+ // 改动(用户实际反馈)。这里钉的是这条**接线**:本轮的改动只有 a.txt 一行。+ const { dshHome, worktree } = await fixture()+ const nested = join(worktree, 'source', 'react-use')+ await mkdir(nested, { recursive: true })+ await run('git', ['-c', 'init.defaultBranch=main', 'init', '--quiet', nested], { windowsHide: true })+ await writeFile(join(nested, 'inner.txt'), 'v1\n', 'utf8')+ const identity = ['-c', '[email protected]', '-c', 'user.name=test']+ await run('git', ['-C', nested, ...identity, 'add', '--all'], { windowsHide: true })+ await run('git', ['-C', nested, ...identity, 'commit', '--quiet', '-m', 'init'], { windowsHide: true })+ // 源仓库登记成 gitlink(被跟踪的嵌套仓库,不是被忽略的参考克隆)。+ await run('git', ['-C', worktree, ...identity, 'add', 'source/react-use'], { windowsHide: true })++ const capture = captureFor(dshHome)+ await capture.beginTurn('s16', 1, worktree)+ await writeFile(join(worktree, 'a.txt'), 'one\ntwo\nthree\n', 'utf8')++ // 等第一次定时刷新(1.5s 起)落地:读数出现就必须正好是 a.txt 这一处改动。+ const deadline = Date.now() + 15_000+ while (capture.liveState('s16').fileCount === 0 && Date.now() < deadline)+ await new Promise(resolve => setTimeout(resolve, 50))++ expect(capture.liveState('s16')).toMatchObject({ active: true, turn: 1, fileCount: 1, insertions: 1, deletions: 0 })+ })})diff --git a/packages/dsh-tauri-turnrewind/src/host/service/capture.ts b/packages/dsh-tauri-turnrewind/src/host/service/capture.tsindex 8a1a348c..99941540 100644--- a/packages/dsh-tauri-turnrewind/src/host/service/capture.ts+++ b/packages/dsh-tauri-turnrewind/src/host/service/capture.ts@@ -296,7 +296,14 @@ export function createTurnCapture(options: TurnCaptureOptions): TurnCapture {const epoch = entry.liveEpochentry.liveBusy = truetry {- const result = await queue.run(workspaceRoot, () => liveDiff(store, beforeCommit, { exclude: entry.exclusions }))+ // 嵌套仓库目录(`entry.nestedDirs`)必须一起传:超限文件在 `exclusions` 里,+ // 而目录语义的排除(`:(exclude,glob)dir/**`)只有独立传入才生效。漏掉时+ // `git add` 会把嵌套仓库当成 gitlink 写进私有 index,读数于是报出+ // 「2 个文件已更改 +2 -0」这种工作区根本没发生过的改动(见 liveDiff 的注释)。+ const result = await queue.run(workspaceRoot, () => liveDiff(store, beforeCommit, {+ exclude: entry.exclusions,+ nestedDirs: entry.nestedDirs,+ }))if (result.ok && entry.liveEpoch === epoch)entry.live = { turn: entry.turn, ...result.stats }}diff --git a/packages/dsh-tauri-turnrewind/src/host/service/snapshot.test.ts b/packages/dsh-tauri-turnrewind/src/host/service/snapshot.test.tsindex 9ab7c0e5..89960eda 100644--- a/packages/dsh-tauri-turnrewind/src/host/service/snapshot.test.ts+++ b/packages/dsh-tauri-turnrewind/src/host/service/snapshot.test.ts@@ -257,6 +257,54 @@ describe('liveDiff(运行中实时读数)', () => {const live = await liveDiff(store, before.commit)expect(live.ok).toBe(false)})++ it('把嵌套仓库目录传给 `nestedDirs` 后,它们不会被算成本轮新增的文件', async () => {+ // 回归背景:`source/react-use`、`source/vueuse` 这类**被跟踪的**嵌套仓库不是+ // 「被忽略的参考克隆」:不含嵌套目录的排除清单时,这里的 `git add --all` 会把它们+ // 作为 gitlink 写进私有 index,而 before 快照(捕获时已排除)里没有这些条目 ——+ // `git diff <before>` 于是报出两条 `1 0` 的「新增文件」:工作区一个字节都没动,+ // 提示条却显示「2 个文件已更改 +2 -0」(用户实际反馈,仓库里恰有两个嵌套仓库)。+ const { dshHome, worktree } = await fixture()+ const identity = ['-c', '[email protected]', '-c', 'user.name=test']+ for (const name of ['react-use', 'vueuse']) {+ const nested = join(worktree, 'source', name)+ await mkdir(nested, { recursive: true })+ await run('git', ['-c', 'init.defaultBranch=main', 'init', '--quiet', nested], { windowsHide: true })+ await writeFile(join(nested, 'inner.txt'), 'v1\n', 'utf8')+ await run('git', ['-C', nested, ...identity, 'add', '--all'], { windowsHide: true })+ await run('git', ['-C', nested, ...identity, 'commit', '--quiet', '-m', 'init'], { windowsHide: true })+ // 源仓库把它登记成 gitlink:与真实仓库里被跟踪的 submodule 同形态。+ await run('git', ['-C', worktree, ...identity, 'add', `source/${name}`], { windowsHide: true })+ }++ const store = snapshotStoreFor(dshHome, worktree)+ const nestedDirs = scanNestedRepos(worktree)+ expect(nestedDirs).toEqual(['source/react-use', 'source/vueuse'])+ const before = await captureSnapshot(store, turnRef('s16', 1, 'before'), 'before', { nestedDirs })+ expect(before.ok).toBe(true)+ if (!before.ok)+ return++ // 没有任何改动:读数必须是空的,私有 index 里也不能留下这两个 gitlink。+ const live = await liveDiff(store, before.commit, { nestedDirs })+ expect(live).toEqual({ ok: true, stats: { fileCount: 0, insertions: 0, deletions: 0 } })+ const listed = await gitInSnapshot(store, ['ls-files', '--', 'source'])+ expect(listed.ok).toBe(true)+ if (listed.ok)+ expect(listed.out.trim()).toBe('')++ // 嵌套仓库内部提交前进(gitlink 指针变化)同样不算这一轮的改动:+ // 它的内容本来就不在撤销范围内,提示条不该为它报数。+ const advanced = join(worktree, 'source', 'react-use')+ await writeFile(join(advanced, 'inner.txt'), 'v2\n', 'utf8')+ await run('git', ['-C', advanced, ...identity, 'add', '--all'], { windowsHide: true })+ await run('git', ['-C', advanced, ...identity, 'commit', '--quiet', '-m', 'advance'], { windowsHide: true })+ expect(await liveDiff(store, before.commit, { nestedDirs })).toEqual({ ok: true, stats: { fileCount: 0, insertions: 0, deletions: 0 } })++ // 真正的改动照常计入(排除不是把整棵树都静音了)。+ await writeFile(join(worktree, 'a.txt'), 'one\ntwo\nthree\n', 'utf8')+ expect(await liveDiff(store, before.commit, { nestedDirs })).toEqual({ ok: true, stats: { fileCount: 1, insertions: 1, deletions: 0 } })+ })})describe('捕获限额(超限文件 / 嵌套仓库)', () => {diff --git a/packages/dsh-tauri-turnrewind/src/host/service/snapshot.ts b/packages/dsh-tauri-turnrewind/src/host/service/snapshot.tsindex 89f6ee02..a093efa3 100644--- a/packages/dsh-tauri-turnrewind/src/host/service/snapshot.ts+++ b/packages/dsh-tauri-turnrewind/src/host/service/snapshot.ts@@ -566,19 +566,29 @@ export async function diffTurnChanges(store: SnapshotStore, beforeCommit: string* (该路径此前被正常捕获过、之后才进入排除清单,例如嵌套仓库/超限文件被学到),* 没有 pathspec 时 `git diff <commit>` 照样按 index 条目把它的改动算进来,* 实时读数就会比最终结算多出这些文件。+ *+ * **嵌套仓库目录必须和 {@link captureSnapshot} 一样排除**(`nestedDirs`,目录语义:+ * `:(exclude)dir` + `:(exclude,glob)dir/**`)。漏掉它们时,before 快照里没有这些条目+ * (捕获时被排除了),而这里的 `git add --all` 会把它们作为 gitlink 写进私有 index,+ * 紧接着 `git diff <beforeCommit>` 就把它们报成「本轮新增的文件」(gitlink 的+ * `--numstat` 是 `1 0`):工作区一个字节都没动,提示条却显示「2 个文件已更改 +2 -0」+ * (用户实际反馈;仓库里恰有两个被跟踪的嵌套仓库时正是这个读数)。*/export async function liveDiff(store: SnapshotStore, beforeCommit: string, options: CaptureOptions = {}): Promise<{ ok: true, stats: { fileCount: number, insertions: number, deletions: number } } | { ok: false, reason: string }> {- const excluded = options.exclude ?? []+ // 目录语义的排除必须知道哪些路径是目录,因此把嵌套仓库目录并进同一份排除清单+ // (超限文件是文件、嵌套仓库是目录,两者在 pathspec 上的写法不同,由 nestedDirs 区分)。+ const nestedDirs = new Set(options.nestedDirs ?? [])+ const excluded = [...new Set([...(options.exclude ?? []), ...nestedDirs])]// 与 captureSnapshot 同一条纪律:被忽略的路径不能出现在 exclude pathspec 里,// 否则 `git add` 直接失败、实时读数永远为空(运行中提示条也就永远不出现)。const activeExclude = await dropIgnoredExclusions(store, excluded)- const added = await gitInSnapshot(store, ['add', '--all', '--', '.', ...excludePathspecs(activeExclude, new Set())])+ const added = await gitInSnapshot(store, ['add', '--all', '--', '.', ...excludePathspecs(activeExclude, nestedDirs)])if (!added.ok)return { ok: false, reason: added.error }// 没有排除项时保持原命令形态(`-- . :(exclude)…` 只在真的需要时才加)。const diffArgs = ['diff', '--numstat', '-z', '--no-renames', beforeCommit]if (excluded.length > 0)- diffArgs.push('--', '.', ...excludePathspecs(excluded, new Set()))+ diffArgs.push('--', '.', ...excludePathspecs(excluded, nestedDirs))const numstat = await gitInSnapshot(store, diffArgs)if (!numstat.ok)return { ok: false, reason: numstat.error }