Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(chat): 隐藏无内容的文件变更卡片 (#2259)

DavidShenXDfd64934d107e
diff --git a/apps/desktop/src/main/turn-change-set/store.ts b/apps/desktop/src/main/turn-change-set/store.ts
index f6e287396c..2cd492d568 100644
--- a/apps/desktop/src/main/turn-change-set/store.ts
+++ b/apps/desktop/src/main/turn-change-set/store.ts
@@ -918,13 +918,10 @@ export async function captureKnownFileBefore(input: KnownFileWriteCapture): Prom
const pending = ensurePending(input.sessionId, input.provider, input.cwd);
const target = safeRelativeTarget(input.cwd, input.targetPath);
if (!target) {
- // A known write target literally outside the workspace (agent temp files,
- // scratchpad, OS temp dirs) is a deliberate scope exclusion, not a capture
- // loss: turn change tracking only covers the workspace tree. Recording
- // 'outside-workspace' here spawned a dead-end "+0 -0" partial card for
- // turns that never touched the workspace at all. The realpath escape check
- // below still records the reason — there the workspace tree appears
- // touched, which is worth flagging.
+ // Literal out-of-workspace targets are deliberately skipped without recording
+ // a reason because the workspace tree was never touched. The realpath escape
+ // check below still records 'outside-workspace' when a workspace path resolves
+ // beyond that tree, which is worth flagging.
return;
}
if (detectSensitivePath(target.relativePath, { allowEnvTemplates: true })) {
diff --git a/apps/desktop/src/renderer/__tests__/buildRenderItemsKeyStability.test.ts b/apps/desktop/src/renderer/__tests__/buildRenderItemsKeyStability.test.ts
index a04ad60351..731c69cf5e 100644
--- a/apps/desktop/src/renderer/__tests__/buildRenderItemsKeyStability.test.ts
+++ b/apps/desktop/src/renderer/__tests__/buildRenderItemsKeyStability.test.ts
@@ -327,7 +327,7 @@ describe('buildRenderItems — key stability', () => {
expect(items.indexOf(cards[0])).toBeGreaterThan(items.findIndex((item) => item.key === 'msg-a1'));
});
- it('hides zero-file cards without change evidence but keeps evidence-bearing ones', () => {
+ it('hides all zero-file change cards because they have no reviewable content', () => {
const base: TurnChangeSetSummary = {
id: 'cs-base',
sessionId: 's1',
@@ -346,13 +346,11 @@ describe('buildRenderItems — key stability', () => {
additions: 0,
deletions: 0,
};
- // Only "we might not have seen everything" reasons: review pane would be empty.
- const noEvidence: TurnChangeSetSummary = {
+ const opaque: TurnChangeSetSummary = {
...base,
id: 'cs-noise',
incompleteReasons: ['opaque-tool', 'turn-failed', 'concurrent-workspace'],
};
- // Proof that real changes existed but were not recorded: card must stay.
const truncated: TurnChangeSetSummary = {
...base,
id: 'cs-too-large',
@@ -360,8 +358,6 @@ describe('buildRenderItems — key stability', () => {
createdAt: 3,
completedAt: 4,
};
- // The store only records 'outside-workspace' for suspicious captures (symlink
- // escapes, fail-closed provider diff blocks) — that evidence must stay visible.
const escaped: TurnChangeSetSummary = {
...base,
id: 'cs-escape',
@@ -374,12 +370,12 @@ describe('buildRenderItems — key stability', () => {
[mkUser('u1'), mkAssistant('a1'), mkUser('u2')],
undefined,
undefined,
- { turnChangeSets: [noEvidence, truncated, escaped] },
+ { turnChangeSets: [opaque, truncated, escaped] },
);
const cards = items.filter(
(item): item is Extract<RenderItem, { type: 'turn_changes' }> => item.type === 'turn_changes',
);
- expect(cards.map((card) => card.changeSet.id)).toEqual(['cs-too-large', 'cs-escape']);
+ expect(cards).toEqual([]);
});
it('keeps opaque command artifacts as fallback chips without duplicating exact files', () => {
diff --git a/apps/desktop/src/renderer/components/chat/MessageStream.tsx b/apps/desktop/src/renderer/components/chat/MessageStream.tsx
index 1663db06e9..2896585600 100644
--- a/apps/desktop/src/renderer/components/chat/MessageStream.tsx
+++ b/apps/desktop/src/renderer/components/chat/MessageStream.tsx
@@ -1082,8 +1082,8 @@ export function buildRenderItems(
}
}
for (const changeSet of changeSets) {
- // Zero-file entries without change evidence (e.g. only opaque tools ran)
- // would render a card whose review pane is empty — skip the dead end.
+ // Zero-file entries have nothing the user can inspect or act on. Keep their
+ // diagnostic sidecars in Main, but do not add a warning-only chat card.
if (!hasReviewableTurnChanges(changeSet)) continue;
items.push({
type: 'turn_changes',
diff --git a/apps/desktop/src/shared/turnChangeSet.ts b/apps/desktop/src/shared/turnChangeSet.ts
index 71783d0433..1f9f7f96f1 100644
--- a/apps/desktop/src/shared/turnChangeSet.ts
+++ b/apps/desktop/src/shared/turnChangeSet.ts
@@ -76,28 +76,12 @@ export interface PersistedTurnChangeSetV1 {
}
/**
- * Reasons that only say "the capture may not have seen everything", without any
- * evidence that a change actually happened (opaque tools ran, the turn failed, or
- * another session overlapped). Reasons outside this set prove changes existed but
- * were not recorded — including 'outside-workspace', which the store only records
- * for suspicious cases (a workspace path whose realpath escapes via symlink, or a
- * provider diff block rejected as unsafe); literal out-of-workspace targets are
- * skipped at capture time without recording any reason.
- */
-const NO_CHANGE_EVIDENCE_REASONS: ReadonlySet<TurnChangeIncompleteReason> = new Set([
- 'opaque-tool',
- 'turn-failed',
- 'concurrent-workspace',
-]);
-
-/**
- * Whether a summary carries anything a standalone review card can show. Zero-file
- * entries whose reasons carry no change evidence open an empty review pane — hide
- * the chat-stream card instead of sending users into a dead end.
+ * Whether a summary carries file content a standalone review card can show.
+ * Incomplete zero-file records remain persisted for diagnostics, but rendering a
+ * warning-only card in the chat stream gives the user nothing to inspect or act on.
*/
export function hasReviewableTurnChanges(summary: TurnChangeSetSummary): boolean {
- if (summary.fileCount > 0 || summary.files.length > 0) return true;
- return summary.incompleteReasons.some((reason) => !NO_CHANGE_EVIDENCE_REASONS.has(reason));
+ return summary.fileCount > 0 || summary.files.length > 0;
}
export interface TurnChangeSetUpdatedPayload {