History

Fix redundant truthiness check and misleading incremental diff fallback

- Remove redundant 'checkpointCwd &&' guard in revertToCheckpoint (providerManager.ts:323) since checkpointCwd is guaranteed truthy after the throw on lines 310-313. - Remove latestPatchByPath deduplication fallback in DiffPanel.tsx that kept only the most recent turn's per-file incremental diff, which was misleading for files changed across multiple turns. The per-turn patchForSummary fallback (which prefers cached checkpoint diffs) now handles the case, showing all turns' changes.

Cursor Agent committed 8 months ago

Commit db3b9e01 parent e29a7702 files · +3 −24Browse files

Unified · Split

2 files
  1. apps/server/src/providerManager.ts +1 −1
  2. apps/web/src/components/DiffPanel.tsx +2 −23
apps/server/src/providerManager.ts+1−1
@@ -320,7 +320,7 @@ export class ProviderManager extends EventEmitter<ProviderManagerEvents> { · 319 unmodified lines
320320 );
321321 }
322322
323− if (checkpointCwd && input.turnCount > 0) {
323+ if (input.turnCount > 0) {
324324 const hasCheckpoint = await this.filesystemCheckpointStore.hasCheckpoint({
325325 cwd: checkpointCwd,
326326 threadId: beforeSnapshot.threadId,
apps/web/src/components/DiffPanel.tsx+2−23
@@ -241,29 +241,8 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) { · 240 unmodified lines
241241 }
242242
243243 // Fallback when a conversation checkpoint diff isn't available yet:
244− // keep one patch per file path (latest change wins) so files aren't duplicated.
245− const latestPatchByPath = new Map<string, string>();
246− for (const summary of turnDiffSummaries) {
247− for (const file of summary.files) {
248− if (latestPatchByPath.has(file.path)) {
249− continue;
250− }
251− const patch = file.diff?.trim();
252− if (!patch) {
253− continue;
254− }
255− latestPatchByPath.set(file.path, patch);
256− }
257− }
258− if (latestPatchByPath.size > 0) {
259− return Array.from(latestPatchByPath.entries())
260− .toSorted(([leftPath], [rightPath]) =>
261− leftPath.localeCompare(rightPath, undefined, { numeric: true, sensitivity: "base" }),
262− )
263− .map(([, patch]) => patch)
264− .join("\n\n");
265− }
266−
244+ // show each turn's diff (oldest first) via patchForSummary, which prefers
245+ // cached checkpoint diffs when available.
267246 const patches = turnDiffSummaries
268247 .toReversed()
269248 .map((summary) => patchForSummary(summary)?.trim())