Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 失败轮次无任何文件活动时不再生成空的变更审查卡
DavidShen1263b6e3cbc0
diff --git a/apps/desktop/src/main/turn-change-set/__tests__/store.git-integration.test.ts b/apps/desktop/src/main/turn-change-set/__tests__/store.git-integration.test.tsindex c86005400f..9611938acc 100644--- a/apps/desktop/src/main/turn-change-set/__tests__/store.git-integration.test.ts+++ b/apps/desktop/src/main/turn-change-set/__tests__/store.git-integration.test.ts@@ -945,6 +945,110 @@ describe('turn change-set sidecar store', () => {});});+ it('drops the change set when a turn fails without any capture activity', async () => {+ await beginTurnChangeSet({+ sessionId: 'session-1',+ anchorClientId: 'user-1',+ provider: 'claude-code',+ cwd: workdir,+ });+ await finalizeTurnChangeSet('session-1', null, 'partial');++ expect(await listTurnChangeSets('session-1')).toHaveLength(0);+ });++ it('drops the change set when a failed turn only touched files without changing them', async () => {+ const target = path.join(workdir, 'a.ts');+ await fs.writeFile(target, 'same\n', 'utf8');+ await beginTurnChangeSet({+ sessionId: 'session-1',+ anchorClientId: 'user-1',+ provider: 'claude-code',+ cwd: workdir,+ });+ await captureKnownFileBefore({+ sessionId: 'session-1',+ provider: 'claude-code',+ cwd: workdir,+ targetPath: 'a.ts',+ });+ await finalizeTurnChangeSet('session-1', null, 'partial');++ expect(await listTurnChangeSets('session-1')).toHaveLength(0);+ });++ it('persists a partial entry with turn-failed when a failed turn changed files', async () => {+ const target = path.join(workdir, 'a.ts');+ await fs.writeFile(target, 'old\n', 'utf8');+ await beginTurnChangeSet({+ sessionId: 'session-1',+ anchorClientId: 'user-1',+ provider: 'claude-code',+ cwd: workdir,+ });+ await captureKnownFileBefore({+ sessionId: 'session-1',+ provider: 'claude-code',+ cwd: workdir,+ targetPath: 'a.ts',+ });+ await fs.writeFile(target, 'new\n', 'utf8');+ await finalizeTurnChangeSet('session-1', null, 'partial');++ const [summary] = await listTurnChangeSets('session-1');+ expect(summary).toMatchObject({+ state: 'partial',+ incompleteReasons: ['turn-failed'],+ fileCount: 1,+ additions: 1,+ deletions: 1,+ });+ });++ it('hides legacy zero-file turn-failed-only entries persisted by earlier builds', async () => {+ await beginTurnChangeSet({+ sessionId: 'session-1',+ anchorClientId: 'user-1',+ provider: 'pi',+ cwd: workdir,+ });+ noteOpaqueTurnChange({ sessionId: 'session-1', provider: 'pi', cwd: workdir });+ await finalizeTurnChangeSet('session-1', null, 'complete');+ expect(await listTurnChangeSets('session-1')).toHaveLength(1);++ // Rewrite the sidecar as an earlier build would have persisted a failed turn+ // with no capture activity: zero files, incompleteReasons = ['turn-failed'].+ const sidecarDir = path.join(mocks.userDataRoot, 'turn-change-sets', 'session-1');+ const indexPath = path.join(sidecarDir, 'index.json');+ const index = JSON.parse(await fs.readFile(indexPath, 'utf8')) as {+ version: number;+ entries: Array<{ id: string; incompleteReasons: string[] }>;+ };+ index.entries[0]!.incompleteReasons = ['turn-failed'];+ await fs.writeFile(indexPath, `${JSON.stringify(index)}\n`, 'utf8');++ expect(await listTurnChangeSets('session-1')).toHaveLength(0);+ });++ it('keeps the zero-file partial entry when a failed turn also ran an opaque tool', async () => {+ await beginTurnChangeSet({+ sessionId: 'session-1',+ anchorClientId: 'user-1',+ provider: 'pi',+ cwd: workdir,+ });+ noteOpaqueTurnChange({ sessionId: 'session-1', provider: 'pi', cwd: workdir });+ await finalizeTurnChangeSet('session-1', null, 'partial');++ const [summary] = await listTurnChangeSets('session-1');+ expect(summary).toMatchObject({+ state: 'partial',+ incompleteReasons: expect.arrayContaining(['opaque-tool', 'turn-failed']),+ fileCount: 0,+ files: [],+ });+ });+it.each([['absolute path', 'diff --git /outside.txt /outside.txt'],['parent traversal', 'diff --git a/../escape.txt b/../escape.txt'],diff --git a/apps/desktop/src/main/turn-change-set/store.ts b/apps/desktop/src/main/turn-change-set/store.tsindex 5cc3dc5a3e..3156ae4c15 100644--- a/apps/desktop/src/main/turn-change-set/store.ts+++ b/apps/desktop/src/main/turn-change-set/store.ts@@ -1096,7 +1096,13 @@ async function persistPending(const files = diffs.length > 0 ? summarizeDiffs(diffs) : pending.nativeFiles;// An opaque tool with no known paths is still important turn metadata. Persist a// zero-file partial entry so the UI never silently represents it as fully tracked.- if (files.length === 0 && pending.incompleteReasons.size === 0) return;+ // 'turn-failed' alone is not such evidence: a turn that failed without any capture+ // activity (no tools, no files) cannot have changed the workspace, so persisting+ // an empty partial card would claim untracked changes that never existed.+ if (+ files.length === 0+ && [...pending.incompleteReasons].every((reason) => reason === 'turn-failed')+ ) return;const anchorClientId = pending.anchorClientId;if (!anchorClientId) {log.warn('turn change-set has no visible user anchor', { sessionId, id: pending.id });@@ -1442,10 +1448,21 @@ async function validAnchorIds(sessionId: string, summaries: readonly TurnChangeSreturn new Set(rows.map((row) => row.clientId));}+/**+ * A zero-file entry whose only incomplete reason is 'turn-failed' carries no change+ * information (see persistPending). Earlier builds persisted such entries for every+ * failed turn; hide them on read so legacy sidecars self-heal without a migration.+ */+function isEmptyFailedTurnEntry(summary: TurnChangeSetSummary): boolean {+ return summary.fileCount === 0+ && summary.incompleteReasons.every((reason) => reason === 'turn-failed');+}+export async function listTurnChangeSets(sessionId: string): Promise<TurnChangeSetSummary[]> {const summaries = await readIndex(sessionId);const anchors = await validAnchorIds(sessionId, summaries);- return summaries.filter((summary) => anchors.has(summary.anchorClientId));+ return summaries.filter((summary) =>+ anchors.has(summary.anchorClientId) && !isEmptyFailedTurnEntry(summary));}export async function getTurnChangeSets(