Open History to see the last commit
1import { useAtomValue } from "@effect/atom-react";
2import type { FileDiffContentsLoader } from "@pierre/diffs";
3import { useParams } from "@tanstack/react-router";
4import {
5 isAtomCommandInterrupted,
6 squashAtomCommandFailure,
7} from "@t3tools/client-runtime/state/runtime";
8import { safeErrorLogAttributes } from "@t3tools/client-runtime/errors";
9import type { ScopedThreadRef, TurnId } from "@t3tools/contracts";
10import {
11 ArrowRightIcon,
12 CheckIcon,
13 ChevronDownIcon,
14 ChevronRightIcon,
15 ChevronsDownUpIcon,
16 ChevronsUpDownIcon,
17 Columns2Icon,
18 PilcrowIcon,
19 RefreshCwIcon,
20 Rows3Icon,
21 SearchIcon,
22 TextWrapIcon,
23} from "lucide-react";
24import { useCallback, useEffect, useMemo, useRef, useState } from "react";
25import { useOpenInPreferredEditor } from "../editorPreferences";
26import { type DraftId } from "../composerDraftStore";
27import { openDiffFilePrimaryAction } from "../diffFileActions";
28import { useCheckpointDiff } from "~/lib/checkpointDiffState";
29import { cn } from "~/lib/utils";
30import { selectThreadDiffPanelSelection, useDiffPanelStore } from "../diffPanelStore";
31import { useTheme } from "../hooks/useTheme";
32import {
33 buildFileDiffRenderKey,
34 getDiffCollapseIconClassName,
35 getDiffLineStat,
36 getRenderablePatch,
37 resolveDiffThemeName,
38 resolveFileDiffPath,
39} from "../lib/diffRendering";
40import { areAllDiffFilesCollapsed, toggleAllDiffFiles } from "../lib/diffCollapse";
41import { useTurnDiffSummaries } from "../hooks/useTurnDiffSummaries";
42import { useProject, useThread } from "../state/entities";
43import { resolveThreadRouteRef } from "../threadRoutes";
44import { useClientSettings } from "../hooks/useSettings";
45import { formatShortTimestamp } from "../timestampFormat";
46import { DiffPanelLoadingState, DiffPanelShell, type DiffPanelMode } from "./DiffPanelShell";
47import { DiffStatLabel } from "./chat/DiffStatLabel";
48import { AnnotatableCodeView, type AnnotatableCodeViewHandle } from "./diffs/AnnotatableCodeView";
49import { Button } from "./ui/button";
50import { ToggleGroup, Toggle } from "./ui/toggle-group";
51import { Switch } from "./ui/switch";
52import {
53 Combobox,
54 ComboboxEmpty,
55 ComboboxInput,
56 ComboboxItem,
57 ComboboxList,
58 ComboboxPopup,
59 ComboboxTrigger,
60} from "./ui/combobox";
61import {
62 DropdownMenu,
63 DropdownMenuContent,
64 DropdownMenuItem,
65 DropdownMenuSub,
66 DropdownMenuSubContent,
67 DropdownMenuSubTrigger,
68 DropdownMenuTrigger,
69} from "./ui/menu";
70import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
71import { useEnvironmentQuery } from "../state/query";
72import { useAtomCommand } from "../state/use-atom-command";
73import { serverEnvironment } from "../state/server";
74import { reviewEnvironment } from "../state/review";
75import { vcsEnvironment } from "../state/vcs";
76import { buildBaseRefChoices, filterBaseRefChoices } from "../lib/baseRefChoices";
77
78type DiffRenderMode = "stacked" | "split";
79type DiffThemeType = "light" | "dark";
80const AUTOMATIC_BASE_REF = "__automatic_base_ref__";
81
82interface CollapsedDiffFilesState {
83 readonly scopeKey: string | null;
84 readonly fileKeys: ReadonlySet<string>;
85}
86
87const EMPTY_COLLAPSED_DIFF_FILE_KEYS: ReadonlySet<string> = new Set();
88
89const DIFF_PANEL_UNSAFE_CSS = `
90[data-diffs-header],
91[data-diff],
92[data-file],
93[data-error-wrapper],
94[data-virtualizer-buffer] {
95 --diffs-header-font-family: var(--font-sans) !important;
96 --diffs-font-family: var(--font-mono) !important;
97 --diffs-bg: var(--background) !important;
98 --diffs-light-bg: var(--background) !important;
99 --diffs-dark-bg: var(--background) !important;
100 --diffs-token-light-bg: transparent;
101 --diffs-token-dark-bg: transparent;
102
103 --diffs-bg-context-override: color-mix(in srgb, var(--background) 97%, var(--foreground));
104 --diffs-bg-hover-override: color-mix(in srgb, var(--background) 94%, var(--foreground));
105 --diffs-bg-separator-override: color-mix(in srgb, var(--background) 95%, var(--foreground));
106 --diffs-bg-buffer-override: color-mix(in srgb, var(--background) 90%, var(--foreground));
107
108 --diffs-bg-addition-override: light-dark(
109 color-mix(in srgb, var(--background) 50%, var(--success)),
110 color-mix(in srgb, var(--background) 70%, var(--success))
111 );
112 --diffs-bg-addition-number-override: light-dark(
113 color-mix(in srgb, var(--background) 35%, var(--success)),
114 color-mix(in srgb, var(--background) 60%, var(--success))
115 );
116 --diffs-bg-addition-hover-override: color-mix(in srgb, var(--background) 85%, var(--success));
117 --diffs-bg-addition-emphasis-override: color-mix(in srgb, var(--background) 80%, var(--success));
118
119 --diffs-bg-deletion-override: light-dark(
120 color-mix(in srgb, var(--background) 50%, var(--destructive)),
121 color-mix(in srgb, var(--background) 70%, var(--destructive))
122 );
123 --diffs-bg-deletion-number-override: light-dark(
124 color-mix(in srgb, var(--background) 35%, var(--destructive)),
125 color-mix(in srgb, var(--background) 60%, var(--destructive))
126 );
127 --diffs-bg-deletion-hover-override: color-mix(in srgb, var(--background) 85%, var(--destructive));
128 --diffs-bg-deletion-emphasis-override: color-mix(
129 in srgb,
130 var(--background) 80%,
131 var(--destructive)
132 );
133
134 background-color: var(--diffs-bg) !important;
135}
136
137:is(
138 [data-line],
139 [data-line-annotation],
140 [data-merge-conflict],
141 [data-merge-conflict-actions],
142 [data-no-newline]
143)[data-selected-line] {
144 --diffs-line-bg: light-dark(
145 color-mix(
146 in lab,
147 var(--background) 88%,
148 color-mix(in srgb, var(--background) 50%, var(--diffs-modified-base))
149 ),
150 color-mix(
151 in lab,
152 var(--background) 80%,
153 color-mix(in srgb, var(--background) 70%, var(--diffs-modified-base))
154 )
155 ) !important;
156}
157
158:is([data-gutter-buffer], [data-column-number])[data-selected-line] {
159 --diffs-line-bg: light-dark(
160 color-mix(
161 in lab,
162 var(--background) 91%,
163 color-mix(in srgb, var(--background) 35%, var(--diffs-modified-base))
164 ),
165 color-mix(
166 in lab,
167 var(--background) 85%,
168 color-mix(in srgb, var(--background) 60%, var(--diffs-modified-base))
169 )
170 ) !important;
171}
172
173[data-indicators="bars"]
174 :is([data-column-number], [data-gutter-buffer="annotation"])[data-selected-line] {
175 position: relative;
176}
177
178[data-indicators="bars"]
179 :is([data-column-number], [data-gutter-buffer="annotation"])[data-selected-line]::before {
180 position: absolute !important;
181 inset-block: 0 !important;
182 inset-inline-start: 0 !important;
183 display: block !important;
184 width: 4px !important;
185 min-width: 4px !important;
186 max-width: 4px !important;
187 height: auto !important;
188 padding: 0 !important;
189 content: "" !important;
190 background-color: var(--diffs-modified-base) !important;
191 background-image: none !important;
192}
193
194[data-file-info] {
195 background-color: var(--background) !important;
196 border-block-color: transparent !important;
197 color: var(--foreground) !important;
198}
199
200[data-diffs-header] {
201 position: sticky !important;
202 top: 0;
203 z-index: 4;
204 background-color: var(--background) !important;
205 border-bottom-color: transparent !important;
206 align-items: center !important;
207 font-family: var(--font-sans) !important;
208 font-size: 12px !important;
209 line-height: 1 !important;
210 min-height: 32px !important;
211 padding-block: 6px !important;
212 padding-inline: 8px 12px !important;
213}
214
215[data-diffs-header]:hover {
216 background-color: color-mix(in srgb, var(--background) 97%, var(--foreground)) !important;
217}
218
219:is([data-separator="line-info"], [data-separator="line-info-basic"]) {
220 height: 24px !important;
221 margin-block: 0 !important;
222 background-color: var(--background) !important;
223}
224
225:is([data-separator="line-info"], [data-separator="line-info-basic"])
226 [data-separator-wrapper] {
227 padding-inline: 8px 12px !important;
228 background-color: transparent !important;
229}
230
231:is([data-separator="line-info"], [data-separator="line-info-basic"])
232 [data-separator-content] {
233 gap: 8px;
234 padding-inline: 0 !important;
235 background-color: transparent !important;
236 color: color-mix(in srgb, var(--foreground) 52%, var(--background)) !important;
237 font-family: var(--font-sans) !important;
238 font-size: 11px !important;
239 text-decoration: none !important;
240}
241
242:is([data-separator="line-info"], [data-separator="line-info-basic"])
243 [data-unmodified-lines] {
244 display: flex !important;
245 min-width: 0;
246 flex: 1 1 auto;
247 align-items: center;
248 gap: 8px;
249 cursor: pointer;
250}
251
252:is([data-separator="line-info"], [data-separator="line-info-basic"])
253 [data-unmodified-lines]::before,
254:is([data-separator="line-info"], [data-separator="line-info-basic"])
255 [data-unmodified-lines]::after {
256 width: auto;
257 height: 1px;
258 flex: 1 1 auto;
259 content: "";
260 background-color: color-mix(in srgb, var(--background) 92%, var(--foreground));
261}
262
263:is([data-separator="line-info"], [data-separator="line-info-basic"])[data-expand-index]
264 [data-separator-wrapper] {
265 grid-template-columns: 0 minmax(0, 1fr) !important;
266}
267
268:is([data-separator="line-info"], [data-separator="line-info-basic"])[data-expand-index]
269 [data-separator-content] {
270 grid-column: 2 !important;
271}
272
273:is([data-separator="line-info"], [data-separator="line-info-basic"])
274 [data-expand-button] {
275 display: none !important;
276}
277
278:is([data-separator="line-info"], [data-separator="line-info-basic"]):has(
279 [data-expand-button]
280 )
281 [data-separator-content] {
282 cursor: pointer;
283}
284
285:is([data-separator="line-info"], [data-separator="line-info-basic"]):has(
286 [data-expand-button]
287 ):hover
288 [data-separator-content] {
289 color: color-mix(in srgb, var(--foreground) 76%, var(--background)) !important;
290}
291
292:is([data-separator="line-info"], [data-separator="line-info-basic"]):has(
293 [data-expand-button]
294 ):hover
295 [data-unmodified-lines]::before,
296:is([data-separator="line-info"], [data-separator="line-info-basic"]):has(
297 [data-expand-button]
298 ):hover
299 [data-unmodified-lines]::after {
300 background-color: color-mix(in srgb, var(--background) 84%, var(--foreground));
301}
302
303[data-diffs-header] [data-header-content] {
304 align-items: center !important;
305 line-height: 1 !important;
306}
307
308[data-diffs-header] [data-metadata] {
309 align-items: center !important;
310 line-height: 1 !important;
311 font-variant-numeric: tabular-nums;
312}
313
314[data-diffs-header] [data-additions-count],
315[data-diffs-header] [data-deletions-count] {
316 font-family: var(--font-mono) !important;
317 font-size: 11px !important;
318 font-variant-numeric: tabular-nums;
319 line-height: 1 !important;
320}
321
322[data-diffs-header] [data-change-icon],
323[data-diffs-header] [data-rename-icon] {
324 display: block;
325 flex-shrink: 0;
326}
327
328[data-title] {
329 cursor: pointer;
330 transition:
331 color 120ms ease,
332 text-decoration-color 120ms ease;
333 text-decoration: underline;
334 text-decoration-color: transparent;
335 text-underline-offset: 2px;
336 font-family: var(--font-sans) !important;
337}
338
339[data-title]:hover {
340 color: color-mix(in srgb, var(--foreground) 84%, var(--primary)) !important;
341 text-decoration-color: currentColor;
342}
343`;
344
345interface DiffPanelProps {
346 mode?: DiffPanelMode;
347 composerDraftTarget: ScopedThreadRef | DraftId;
348 initialGitScope: "branch" | "unstaged";
349}
350
351export { DiffWorkerPoolProvider } from "./DiffWorkerPoolProvider";
352
353export default function DiffPanel({
354 mode = "inline",
355 composerDraftTarget,
356 initialGitScope: initialGitScopeProp,
357}: DiffPanelProps) {
358 const { resolvedTheme } = useTheme();
359 const settings = useClientSettings();
360 const [initialGitScope] = useState(initialGitScopeProp);
361 const [diffRenderMode, setDiffRenderMode] = useState<DiffRenderMode>("stacked");
362 const [wordWrap, setWordWrap] = useState(settings.wordWrap);
363 const [diffIgnoreWhitespace, setDiffIgnoreWhitespace] = useState(settings.diffIgnoreWhitespace);
364 const [baseRefQuery, setBaseRefQuery] = useState("");
365 const [collapsedDiffFiles, setCollapsedDiffFiles] = useState<CollapsedDiffFilesState>(() => ({
366 scopeKey: null,
367 fileKeys: EMPTY_COLLAPSED_DIFF_FILE_KEYS,
368 }));
369 const [codeViewRevision, setCodeViewRevision] = useState(0);
370 const codeViewRef = useRef<AnnotatableCodeViewHandle>(null);
371 const lastCompletedTurnRefreshRef = useRef<{
372 readonly threadKey: string | null;
373 readonly turnId: TurnId | null;
374 } | null>(null);
375
376 const routeThreadRef = useParams({
377 strict: false,
378 select: (params) => resolveThreadRouteRef(params),
379 });
380 const activeThreadId = routeThreadRef?.threadId ?? null;
381 const activeThread = useThread(routeThreadRef);
382 const activeProjectId = activeThread?.projectId ?? null;
383 const activeProject = useProject(
384 activeThread && activeProjectId
385 ? {
386 environmentId: activeThread.environmentId,
387 projectId: activeProjectId,
388 }
389 : null,
390 );
391 const activeCwd = activeThread?.worktreePath ?? activeProject?.workspaceRoot;
392 const serverConfig = useAtomValue(
393 serverEnvironment.configValueAtom(activeThread?.environmentId ?? null),
394 );
395 const openInPreferredEditor = useOpenInPreferredEditor(
396 activeThread?.environmentId ?? null,
397 serverConfig?.availableEditors ?? [],
398 );
399 const getDiffFileContents = useAtomCommand(reviewEnvironment.diffFileContents);
400 const gitStatusQuery = useEnvironmentQuery(
401 activeThread !== null && activeThread !== undefined && activeCwd != null
402 ? vcsEnvironment.status({
403 environmentId: activeThread.environmentId,
404 input: { cwd: activeCwd },
405 })
406 : null,
407 );
408 const diffSelection = useDiffPanelStore((state) =>
409 selectThreadDiffPanelSelection(
410 state.byThreadKey,
411 routeThreadRef,
412 initialGitScope === "unstaged",
413 ),
414 );
415 const isGitRepo = gitStatusQuery.data?.isRepo ?? true;
416 const { turnDiffSummaries, inferredCheckpointTurnCountByTurnId } =
417 useTurnDiffSummaries(activeThread);
418 const orderedTurnDiffSummaries = useMemo(
419 () =>
420 [...turnDiffSummaries].toSorted((left, right) => {
421 const leftTurnCount =
422 left.checkpointTurnCount ?? inferredCheckpointTurnCountByTurnId[left.turnId] ?? 0;
423 const rightTurnCount =
424 right.checkpointTurnCount ?? inferredCheckpointTurnCountByTurnId[right.turnId] ?? 0;
425 if (leftTurnCount !== rightTurnCount) {
426 return rightTurnCount - leftTurnCount;
427 }
428 return right.completedAt.localeCompare(left.completedAt);
429 }),
430 [inferredCheckpointTurnCountByTurnId, turnDiffSummaries],
431 );
432
433 useEffect(() => {
434 if (!routeThreadRef || diffSelection.kind !== "turn") return;
435 useDiffPanelStore.getState().reconcileTurnSelection(
436 routeThreadRef,
437 orderedTurnDiffSummaries.map((summary) => summary.turnId),
438 );
439 }, [diffSelection, orderedTurnDiffSummaries, routeThreadRef]);
440
441 const selectedTurnId = diffSelection.kind === "turn" ? diffSelection.turnId : null;
442 const selectedGitScope = diffSelection.kind === "unstaged" ? "unstaged" : "branch";
443 const selectedBaseRef = diffSelection.kind === "branch" ? diffSelection.baseRef : null;
444 const selectedFilePath = diffSelection.kind === "turn" ? diffSelection.filePath : null;
445 const selectedFileRevealRequestId =
446 diffSelection.kind === "turn" ? diffSelection.revealRequestId : 0;
447 const selectedTurn =
448 selectedTurnId === null
449 ? undefined
450 : (orderedTurnDiffSummaries.find((summary) => summary.turnId === selectedTurnId) ??
451 orderedTurnDiffSummaries[0]);
452 const selectedCheckpointTurnCount =
453 selectedTurn &&
454 (selectedTurn.checkpointTurnCount ?? inferredCheckpointTurnCountByTurnId[selectedTurn.turnId]);
455 const latestTurn = orderedTurnDiffSummaries[0];
456 const selectedScopeLabel =
457 selectedTurnId === null
458 ? selectedGitScope === "unstaged"
459 ? "Working tree"
460 : "Branch changes"
461 : selectedTurn?.turnId === latestTurn?.turnId
462 ? "Latest turn"
463 : `Turn ${selectedCheckpointTurnCount ?? "?"}`;
464 const reviewSectionId = selectedTurn ? `turn:${selectedTurn.turnId}` : selectedGitScope;
465 const collapseScopeKey = routeThreadRef
466 ? `${routeThreadRef.environmentId}:${routeThreadRef.threadId}:${reviewSectionId}`
467 : null;
468 const codeViewMountKey = `${collapseScopeKey ?? reviewSectionId}:${codeViewRevision}`;
469 const collapsedDiffFileKeys =
470 collapsedDiffFiles.scopeKey === collapseScopeKey
471 ? collapsedDiffFiles.fileKeys
472 : EMPTY_COLLAPSED_DIFF_FILE_KEYS;
473 const reviewSectionTitle = selectedTurn
474 ? `Turn ${selectedCheckpointTurnCount ?? "?"}`
475 : selectedGitScope === "unstaged"
476 ? "Working tree"
477 : "Branch changes";
478 const selectedCheckpointRange = useMemo(
479 () =>
480 typeof selectedCheckpointTurnCount === "number"
481 ? {
482 fromTurnCount: Math.max(0, selectedCheckpointTurnCount - 1),
483 toTurnCount: selectedCheckpointTurnCount,
484 }
485 : null,
486 [selectedCheckpointTurnCount],
487 );
488 const activeCheckpointDiff = useCheckpointDiff(
489 {
490 environmentId: activeThread?.environmentId ?? null,
491 threadId: activeThreadId,
492 fromTurnCount: selectedCheckpointRange?.fromTurnCount ?? null,
493 toTurnCount: selectedCheckpointRange?.toTurnCount ?? null,
494 ignoreWhitespace: diffIgnoreWhitespace,
495 cacheScope: selectedTurn ? `turn:${selectedTurn.turnId}` : null,
496 },
497 { enabled: isGitRepo && selectedTurn !== undefined },
498 );
499 const primaryBranchDiffPreview = useEnvironmentQuery(
500 selectedTurnId === null && activeThread && activeCwd
501 ? reviewEnvironment.diffPreview({
502 environmentId: activeThread.environmentId,
503 input: {
504 cwd: activeCwd,
505 ...(selectedBaseRef ? { baseRef: selectedBaseRef } : {}),
506 ignoreWhitespace: diffIgnoreWhitespace,
507 },
508 })
509 : null,
510 );
511 const shouldRetryBranchDiffAtEnvironmentCwd =
512 selectedTurnId === null &&
513 primaryBranchDiffPreview.error?.includes("configured workspace root") === true &&
514 serverConfig?.cwd !== undefined &&
515 serverConfig.cwd !== activeCwd;
516 const fallbackBranchDiffPreview = useEnvironmentQuery(
517 shouldRetryBranchDiffAtEnvironmentCwd && activeThread && serverConfig
518 ? reviewEnvironment.diffPreview({
519 environmentId: activeThread.environmentId,
520 input: {
521 cwd: serverConfig.cwd,
522 ...(selectedBaseRef ? { baseRef: selectedBaseRef } : {}),
523 ignoreWhitespace: diffIgnoreWhitespace,
524 },
525 })
526 : null,
527 );
528 const branchDiffPreview = shouldRetryBranchDiffAtEnvironmentCwd
529 ? fallbackBranchDiffPreview
530 : primaryBranchDiffPreview;
531 const refreshBranchDiffPreview = branchDiffPreview.refresh;
532 const canRefreshGitDiff =
533 isGitRepo && selectedTurnId === null && activeThread != null && activeCwd != null;
534 const activeThreadRefreshKey = routeThreadRef
535 ? `${routeThreadRef.environmentId}:${routeThreadRef.threadId}`
536 : null;
537
538 useEffect(() => {
539 if (!canRefreshGitDiff) return;
540 const refreshOnFocus = () => refreshBranchDiffPreview();
541 window.addEventListener("focus", refreshOnFocus);
542 return () => window.removeEventListener("focus", refreshOnFocus);
543 }, [canRefreshGitDiff, refreshBranchDiffPreview]);
544
545 useEffect(() => {
546 const current = {
547 threadKey: activeThreadRefreshKey,
548 turnId: latestTurn?.turnId ?? null,
549 };
550 const previous = lastCompletedTurnRefreshRef.current;
551 if (!canRefreshGitDiff) {
552 return;
553 }
554 if (previous === null || previous.threadKey !== current.threadKey) {
555 lastCompletedTurnRefreshRef.current = current;
556 return;
557 }
558 if (previous.turnId === current.turnId) return;
559 refreshBranchDiffPreview();
560 lastCompletedTurnRefreshRef.current = current;
561 }, [activeThreadRefreshKey, canRefreshGitDiff, latestTurn?.turnId, refreshBranchDiffPreview]);
562
563 const selectedGitSource = branchDiffPreview.data?.sources.find(
564 (source) => source.kind === (selectedGitScope === "unstaged" ? "working-tree" : "branch-range"),
565 );
566 const loadDiffFiles = useMemo<FileDiffContentsLoader | undefined>(() => {
567 const preview = branchDiffPreview.data;
568 if (selectedTurnId !== null || !activeThread || !preview || !selectedGitSource) {
569 return undefined;
570 }
571
572 const source = selectedGitSource;
573 return async (fileDiff) => {
574 const newPath = resolveFileDiffPath(fileDiff);
575 const oldPath = fileDiff.prevName
576 ? resolveFileDiffPath({ ...fileDiff, name: fileDiff.prevName })
577 : newPath;
578 const result = await getDiffFileContents({
579 environmentId: activeThread.environmentId,
580 input: {
581 cwd: preview.cwd,
582 sourceKind: source.kind,
583 changeType: fileDiff.type,
584 baseRef: source.baseRef,
585 headRef: source.headRef,
586 oldPath,
587 newPath,
588 },
589 });
590 if (result._tag !== "Success") {
591 throw squashAtomCommandFailure(result);
592 }
593
594 const newFile = {
595 name: newPath,
596 contents: result.value.newContents,
597 cacheKey: `${source.diffHash}:new:${newPath}`,
598 };
599 if (fileDiff.type === "rename-pure") {
600 return { oldFile: null, newFile };
601 }
602 return {
603 oldFile: {
604 name: oldPath,
605 contents: result.value.oldContents,
606 cacheKey: `${source.diffHash}:old:${oldPath}`,
607 },
608 newFile,
609 };
610 };
611 }, [
612 activeThread,
613 branchDiffPreview.data,
614 getDiffFileContents,
615 selectedGitSource,
616 selectedTurnId,
617 ]);
618 const localBranchRefs = useEnvironmentQuery(
619 selectedTurnId === null &&
620 selectedGitScope === "branch" &&
621 activeThread &&
622 branchDiffPreview.data?.cwd
623 ? vcsEnvironment.listRefs({
624 environmentId: activeThread.environmentId,
625 input: {
626 cwd: branchDiffPreview.data.cwd,
627 includeMatchingRemoteRefs: true,
628 refKind: "local",
629 ...(baseRefQuery.trim().length > 0 ? { query: baseRefQuery.trim() } : {}),
630 limit: 100,
631 },
632 })
633 : null,
634 );
635 const remoteBranchRefs = useEnvironmentQuery(
636 selectedTurnId === null &&
637 selectedGitScope === "branch" &&
638 activeThread &&
639 branchDiffPreview.data?.cwd
640 ? vcsEnvironment.listRefs({
641 environmentId: activeThread.environmentId,
642 input: {
643 cwd: branchDiffPreview.data.cwd,
644 includeMatchingRemoteRefs: true,
645 refKind: "remote",
646 ...(baseRefQuery.trim().length > 0 ? { query: baseRefQuery.trim() } : {}),
647 limit: 100,
648 },
649 })
650 : null,
651 );
652 const baseRefChoices = buildBaseRefChoices(
653 localBranchRefs.data?.refs.filter((ref) => ref.name !== selectedGitSource?.headRef) ?? [],
654 remoteBranchRefs.data?.refs ?? [],
655 );
656 const matchingBaseRefChoices = filterBaseRefChoices(baseRefChoices, baseRefQuery);
657 const valueForBaseRefChoice = (choice: (typeof baseRefChoices)[number]) =>
658 selectedBaseRef && selectedBaseRef === choice.remote?.name
659 ? selectedBaseRef
660 : (choice.local?.name ?? choice.remote?.name ?? choice.id);
661 const baseRefItems = [AUTOMATIC_BASE_REF, ...baseRefChoices.map(valueForBaseRefChoice)];
662 const filteredBaseRefItems = [
663 ...(baseRefQuery.trim().length === 0 ? [AUTOMATIC_BASE_REF] : []),
664 ...matchingBaseRefChoices.map(valueForBaseRefChoice),
665 ];
666 const gitDiff = selectedGitSource?.diff;
667
668 const selectedPatch = selectedTurn ? activeCheckpointDiff.data?.diff : gitDiff;
669 const isSelectedPatchTruncated = !selectedTurn && selectedGitSource?.truncated === true;
670 const isLoadingSelectedPatch = selectedTurn
671 ? activeCheckpointDiff.isPending
672 : branchDiffPreview.isPending;
673 const selectedPatchError = selectedTurn ? activeCheckpointDiff.error : branchDiffPreview.error;
674 const hasResolvedPatch = typeof selectedPatch === "string";
675 const hasNoNetChanges = hasResolvedPatch && selectedPatch.trim().length === 0;
676 const renderablePatch = useMemo(
677 () =>
678 getRenderablePatch(selectedPatch, `diff-panel:${resolvedTheme}`, {
679 compactPartialHunkOffsets: selectedTurnId === null,
680 }),
681 [resolvedTheme, selectedPatch, selectedTurnId],
682 );
683 const renderableFiles = useMemo(() => {
684 if (!renderablePatch || renderablePatch.kind !== "files") {
685 return [];
686 }
687 return renderablePatch.files.toSorted((left, right) =>
688 resolveFileDiffPath(left).localeCompare(resolveFileDiffPath(right), undefined, {
689 numeric: true,
690 sensitivity: "base",
691 }),
692 );
693 }, [renderablePatch]);
694 const renderableFileEntries = useMemo(
695 () =>
696 renderableFiles.map((fileDiff) => ({
697 fileDiff,
698 fileKey: buildFileDiffRenderKey(fileDiff),
699 })),
700 [renderableFiles],
701 );
702 const codeViewFiles = useMemo(
703 () =>
704 renderableFileEntries.map(({ fileDiff, fileKey }) => {
705 return {
706 fileDiff,
707 filePath: resolveFileDiffPath(fileDiff),
708 fileKey,
709 collapsed: collapsedDiffFileKeys.has(fileKey),
710 };
711 }),
712 [collapsedDiffFileKeys, renderableFileEntries],
713 );
714 const diffFileKeys = useMemo(() => codeViewFiles.map((file) => file.fileKey), [codeViewFiles]);
715 const allDiffFilesCollapsed = areAllDiffFilesCollapsed(diffFileKeys, collapsedDiffFileKeys);
716 const diffLineStat = useMemo(() => getDiffLineStat(renderableFiles), [renderableFiles]);
717 const selectedDiffFileKey = selectedFilePath
718 ? (codeViewFiles.find((candidate) => candidate.filePath === selectedFilePath)?.fileKey ?? null)
719 : null;
720
721 useEffect(() => {
722 if (!selectedDiffFileKey) return;
723 codeViewRef.current?.scrollTo({ type: "item", id: selectedDiffFileKey, align: "start" });
724 }, [codeViewMountKey, selectedDiffFileKey, selectedFileRevealRequestId]);
725
726 const openDiffFile = useCallback(
727 (filePath: string) => {
728 openDiffFilePrimaryAction({
729 threadRef: routeThreadRef,
730 filePath,
731 activeCwd,
732 openInEditor: (targetPath) => {
733 void (async () => {
734 const result = await openInPreferredEditor(targetPath);
735 if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
736 console.warn("Failed to open diff file in editor.", {
737 operation: "open-diff-file",
738 ...(routeThreadRef
739 ? {
740 environmentId: routeThreadRef.environmentId,
741 threadId: routeThreadRef.threadId,
742 }
743 : {}),
744 ...safeErrorLogAttributes(squashAtomCommandFailure(result)),
745 });
746 }
747 })();
748 },
749 });
750 },
751 [activeCwd, openInPreferredEditor, routeThreadRef],
752 );
753 const toggleDiffFileCollapsed = useCallback(
754 (fileKey: string) => {
755 setCollapsedDiffFiles((current) => {
756 const next = new Set(current.scopeKey === collapseScopeKey ? current.fileKeys : []);
757 if (next.has(fileKey)) {
758 next.delete(fileKey);
759 } else {
760 next.add(fileKey);
761 }
762 return { scopeKey: collapseScopeKey, fileKeys: next };
763 });
764 },
765 [collapseScopeKey],
766 );
767
768 const toggleDiffFileCollapse = useCallback(() => {
769 setCodeViewRevision((current) => current + 1);
770 setCollapsedDiffFiles((current) => {
771 const currentKeys =
772 current.scopeKey === collapseScopeKey ? current.fileKeys : EMPTY_COLLAPSED_DIFF_FILE_KEYS;
773
774 return {
775 scopeKey: collapseScopeKey,
776 fileKeys: toggleAllDiffFiles(diffFileKeys, currentKeys),
777 };
778 });
779 }, [collapseScopeKey, diffFileKeys]);
780
781 const selectTurn = (turnId: TurnId) => {
782 if (!routeThreadRef) return;
783 useDiffPanelStore.getState().selectTurn(routeThreadRef, turnId);
784 };
785 const selectGitScope = (scope: "branch" | "unstaged") => {
786 if (!routeThreadRef) return;
787 useDiffPanelStore.getState().selectGitScope(routeThreadRef, scope);
788 };
789 const selectBranchBaseRef = (baseRef: string | null) => {
790 if (!routeThreadRef) return;
791 useDiffPanelStore.getState().selectBranchBaseRef(routeThreadRef, baseRef);
792 };
793
794 const headerRow = (
795 <>
796 <div className="flex min-w-0 flex-1 items-center gap-3 [-webkit-app-region:no-drag]">
797 <DropdownMenu>
798 <DropdownMenuTrigger
799 className="inline-flex h-6 max-w-full items-center gap-1 rounded-md bg-muted/70 px-2 text-xs font-medium text-foreground outline-none transition-colors hover:bg-muted focus-visible:ring-2 focus-visible:ring-ring"
800 aria-label={`Diff scope: ${selectedScopeLabel}`}
801 >
802 <span className="truncate">{selectedScopeLabel}</span>
803 <ChevronDownIcon className="size-3.5 shrink-0 text-muted-foreground" />
804 </DropdownMenuTrigger>
805 <DropdownMenuContent align="start" className="w-60">
806 <DropdownMenuItem
807 className={
808 selectedTurnId === null && selectedGitScope === "unstaged"
809 ? "bg-foreground/[0.08]"
810 : undefined
811 }
812 onClick={() => selectGitScope("unstaged")}
813 >
814 <span>Working tree</span>
815 </DropdownMenuItem>
816 <DropdownMenuItem
817 className={
818 selectedTurnId === null && selectedGitScope === "branch"
819 ? "bg-foreground/[0.08]"
820 : undefined
821 }
822 onClick={() => selectGitScope("branch")}
823 >
824 <span>Branch changes</span>
825 </DropdownMenuItem>
826 <DropdownMenuItem
827 className={
828 selectedTurnId !== null && selectedTurn?.turnId === latestTurn?.turnId
829 ? "bg-foreground/[0.08]"
830 : undefined
831 }
832 onClick={() => {
833 if (latestTurn) selectTurn(latestTurn.turnId);
834 }}
835 >
836 <span>Latest turn</span>
837 </DropdownMenuItem>
838 <DropdownMenuSub>
839 <DropdownMenuSubTrigger>Turn</DropdownMenuSubTrigger>
840 <DropdownMenuSubContent className="w-64">
841 {orderedTurnDiffSummaries.map((summary) => {
842 const turnCount =
843 summary.checkpointTurnCount ??
844 inferredCheckpointTurnCountByTurnId[summary.turnId] ??
845 "?";
846 return (
847 <DropdownMenuItem
848 key={summary.turnId}
849 className={
850 summary.turnId === selectedTurn?.turnId ? "bg-foreground/[0.08]" : undefined
851 }
852 onClick={() => selectTurn(summary.turnId)}
853 >
854 <span>Turn {turnCount}</span>
855 <span className="ml-auto text-xs tabular-nums text-muted-foreground">
856 {formatShortTimestamp(summary.completedAt, settings.timestampFormat)}
857 </span>
858 </DropdownMenuItem>
859 );
860 })}
861 </DropdownMenuSubContent>
862 </DropdownMenuSub>
863 </DropdownMenuContent>
864 </DropdownMenu>
865 {selectedTurnId === null && selectedGitScope === "branch" && selectedGitSource?.baseRef && (
866 <div
867 className="flex min-w-0 max-w-full items-center gap-2 overflow-hidden text-xs text-muted-foreground"
868 title={`${selectedGitSource.headRef ?? "HEAD"} → ${selectedGitSource.baseRef}`}
869 aria-label={`Comparing ${selectedGitSource.headRef ?? "HEAD"} against ${selectedGitSource.baseRef}`}
870 >
871 <span className="min-w-0 max-w-48 truncate">{selectedGitSource.headRef ?? "HEAD"}</span>
872 <ArrowRightIcon className="size-3.5 shrink-0 opacity-70" />
873 <Combobox
874 items={baseRefItems}
875 filteredItems={filteredBaseRefItems}
876 value={selectedBaseRef ?? AUTOMATIC_BASE_REF}
877 onOpenChange={(open) => {
878 if (!open) setBaseRefQuery("");
879 }}
880 onValueChange={(value) => {
881 if (!value) return;
882 selectBranchBaseRef(value === AUTOMATIC_BASE_REF ? null : value);
883 }}
884 >
885 <ComboboxTrigger
886 className="inline-flex min-w-0 max-w-48 items-center gap-1 overflow-hidden rounded-md px-1.5 py-1 outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring"
887 aria-label={`Change comparison target. Currently ${selectedGitSource.baseRef}`}
888 >
889 <span className="min-w-0 truncate">{selectedGitSource.baseRef}</span>
890 <ChevronDownIcon className="size-3.5 shrink-0 opacity-70" />
891 </ComboboxTrigger>
892 <ComboboxPopup
893 align="start"
894 className="w-72 min-w-0 max-w-[calc(100vw-1rem)] overflow-hidden [&>[data-slot=combobox-popup]]:min-w-0 [&>[data-slot=combobox-popup]]:overflow-hidden"
895 >
896 <div className="min-w-0 shrink-0 px-3 pt-2.5">
897 <div className="relative -translate-y-px border-b border-border/70 pb-1.5 transition-colors focus-within:border-ring">
898 <SearchIcon
899 aria-hidden="true"
900 className="pointer-events-none absolute top-1.5 left-0 size-4 shrink-0 text-muted-foreground/55"
901 />
902 <ComboboxInput
903 className="[&_input]:h-6.5 [&_input]:ps-5 [&_input]:font-sans [&_input]:leading-6.5"
904 inputClassName="rounded-none bg-transparent text-sm"
905 placeholder="Search refs..."
906 showTrigger={false}
907 size="sm"
908 unstyled
909 value={baseRefQuery}
910 onChange={(event) => setBaseRefQuery(event.target.value)}
911 />
912 </div>
913 </div>
914 <div className="grid shrink-0 grid-cols-[1rem_minmax(0,1fr)] items-center gap-2 border-b border-border/70 ps-3 pe-6.5 pt-2 pb-1.5 font-medium text-[10px] text-muted-foreground uppercase tracking-wide">
915 <span aria-hidden="true" />
916 <div className="grid min-w-0 grid-cols-[minmax(0,1fr)_2rem] items-center">
917 <span>Branch</span>
918 <span className="text-right">Remote</span>
919 </div>
920 </div>
921 <ComboboxEmpty>No matching refs.</ComboboxEmpty>
922 <ComboboxList className="max-h-64 min-w-0 overflow-x-hidden">
923 <ComboboxItem
924 className="h-8 w-full min-w-0 grid-cols-[1rem_minmax(0,1fr)] py-0"
925 contentClassName="w-full min-w-0 overflow-hidden"
926 value={AUTOMATIC_BASE_REF}
927 >
928 <span className="block min-w-0 truncate">Automatic</span>
929 </ComboboxItem>
930 {baseRefChoices.map((choice) => {
931 const item = valueForBaseRefChoice(choice);
932 const hasBoth = choice.local !== null && choice.remote !== null;
933 const useRemote = choice.remote?.name === item;
934 return (
935 <ComboboxItem
936 key={choice.id}
937 className="h-8 w-full min-w-0 grid-cols-[1rem_minmax(0,1fr)] py-0"
938 contentClassName="w-full min-w-0 overflow-hidden"
939 value={item}
940 >
941 <div className="grid w-full min-w-0 grid-cols-[minmax(0,1fr)_2rem] items-center overflow-hidden">
942 <span className="block min-w-0 truncate pe-2">{choice.label}</span>
943 {hasBoth ? (
944 <div
945 className="flex justify-end"
946 onClick={(event) => event.stopPropagation()}
947 onPointerDown={(event) => event.stopPropagation()}
948 >
949 <Switch
950 aria-label={`Use remote version of ${choice.label}`}
951 checked={useRemote}
952 className="[--thumb-size:--spacing(3)]"
953 onCheckedChange={(checked) => {
954 const nextRef = checked
955 ? choice.remote?.name
956 : choice.local?.name;
957 if (nextRef) selectBranchBaseRef(nextRef);
958 }}
959 />
960 </div>
961 ) : choice.remote ? (
962 <span
963 className="flex justify-end text-muted-foreground"
964 title="Remote only"
965 >
966 <CheckIcon aria-hidden="true" className="size-3" />
967 </span>
968 ) : null}
969 </div>
970 </ComboboxItem>
971 );
972 })}
973 </ComboboxList>
974 </ComboboxPopup>
975 </Combobox>
976 </div>
977 )}
978 </div>
979 <div className="flex shrink-0 items-center gap-1 [-webkit-app-region:no-drag]">
980 {codeViewFiles.length > 0 && (
981 <DiffStatLabel
982 additions={diffLineStat.additions}
983 deletions={diffLineStat.deletions}
984 className="mr-1 text-[11px]"
985 layout="inline"
986 />
987 )}
988 {canRefreshGitDiff && (
989 <Tooltip>
990 <TooltipTrigger
991 render={
992 <Button
993 type="button"
994 size="icon-sm"
995 variant="ghost"
996 aria-label={branchDiffPreview.isPending ? "Refreshing diff" : "Refresh diff"}
997 onClick={refreshBranchDiffPreview}
998 />
999 }
1000 >
1001 <RefreshCwIcon
1002 className={cn("size-3.5", branchDiffPreview.isPending && "animate-spin")}
1003 />
1004 </TooltipTrigger>
1005 <TooltipPopup side="top">
1006 {branchDiffPreview.isPending ? "Refreshing diff…" : "Refresh diff"}
1007 </TooltipPopup>
1008 </Tooltip>
1009 )}
1010 {codeViewFiles.length > 0 && (
1011 <Tooltip>
1012 <TooltipTrigger
1013 render={
1014 <Button
1015 type="button"
1016 size="icon-sm"
1017 variant="ghost"
1018 aria-label={allDiffFilesCollapsed ? "Expand all files" : "Collapse all files"}
1019 onClick={toggleDiffFileCollapse}
1020 />
1021 }
1022 >
1023 {allDiffFilesCollapsed ? (
1024 <ChevronsUpDownIcon className="size-3.5" />
1025 ) : (
1026 <ChevronsDownUpIcon className="size-3.5" />
1027 )}
1028 </TooltipTrigger>
1029 <TooltipPopup side="top">
1030 {allDiffFilesCollapsed ? "Expand all files" : "Collapse all files"}
1031 </TooltipPopup>
1032 </Tooltip>
1033 )}
1034 <ToggleGroup
1035 className="shrink-0 gap-1"
1036 size="sm"
1037 value={[diffRenderMode]}
1038 onValueChange={(value) => {
1039 const next = value[0];
1040 if (next === "stacked" || next === "split") {
1041 setDiffRenderMode(next);
1042 }
1043 }}
1044 >
1045 <Toggle aria-label="Stacked diff view" value="stacked" variant="ghost">
1046 <Rows3Icon className="size-3.5" />
1047 </Toggle>
1048 <Toggle aria-label="Split diff view" value="split" variant="ghost">
1049 <Columns2Icon className="size-3.5" />
1050 </Toggle>
1051 </ToggleGroup>
1052 <Tooltip>
1053 <TooltipTrigger
1054 render={
1055 <Toggle
1056 aria-label={wordWrap ? "Disable diff line wrapping" : "Enable diff line wrapping"}
1057 variant="ghost"
1058 size="sm"
1059 pressed={wordWrap}
1060 onPressedChange={(pressed) => {
1061 setWordWrap(Boolean(pressed));
1062 }}
1063 />
1064 }
1065 >
1066 <TextWrapIcon className="size-3.5" />
1067 </TooltipTrigger>
1068 <TooltipPopup side="top">
1069 {wordWrap ? "Disable line wrapping" : "Enable line wrapping"}
1070 </TooltipPopup>
1071 </Tooltip>
1072 <Tooltip>
1073 <TooltipTrigger
1074 render={
1075 <Toggle
1076 aria-label={
1077 diffIgnoreWhitespace ? "Show whitespace changes" : "Hide whitespace changes"
1078 }
1079 variant="ghost"
1080 size="sm"
1081 pressed={diffIgnoreWhitespace}
1082 onPressedChange={(pressed) => {
1083 setDiffIgnoreWhitespace(Boolean(pressed));
1084 }}
1085 />
1086 }
1087 >
1088 <PilcrowIcon className="size-3.5" />
1089 </TooltipTrigger>
1090 <TooltipPopup side="top">
1091 {diffIgnoreWhitespace ? "Show whitespace changes" : "Hide whitespace changes"}
1092 </TooltipPopup>
1093 </Tooltip>
1094 </div>
1095 </>
1096 );
1097
1098 return (
1099 <DiffPanelShell mode={mode} header={headerRow}>
1100 {!activeThread ? (
1101 <div className="flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70">
1102 Select a thread to inspect turn diffs.
1103 </div>
1104 ) : !isGitRepo ? (
1105 <div className="flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70">
1106 Turn diffs are unavailable because this project is not a git repository.
1107 </div>
1108 ) : selectedTurnId !== null && orderedTurnDiffSummaries.length === 0 ? (
1109 <div className="flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70">
1110 No completed turns yet.
1111 </div>
1112 ) : (
1113 <>
1114 <div className="diff-panel-viewport flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden">
1115 {isSelectedPatchTruncated && (
1116 <p className="shrink-0 border-b border-border/70 bg-muted/40 px-3 py-1.5 text-[11px] text-muted-foreground">
1117 This diff was truncated because it exceeded the preview limit. The changes shown are
1118 incomplete.
1119 </p>
1120 )}
1121 {selectedPatchError && !renderablePatch && (
1122 <div className="px-3">
1123 <p className="mb-2 text-[11px] text-red-500/80">{selectedPatchError}</p>
1124 </div>
1125 )}
1126 {!renderablePatch ? (
1127 isLoadingSelectedPatch ? (
1128 <DiffPanelLoadingState
1129 label={
1130 selectedTurn
1131 ? "Loading checkpoint diff..."
1132 : selectedGitScope === "unstaged"
1133 ? "Loading working tree diff..."
1134 : "Loading branch diff..."
1135 }
1136 />
1137 ) : (
1138 <div className="flex h-full items-center justify-center px-3 py-2 text-xs text-muted-foreground/70">
1139 <p>
1140 {hasNoNetChanges
1141 ? "No net changes in this selection."
1142 : "No patch available for this selection."}
1143 </p>
1144 </div>
1145 )
1146 ) : renderablePatch.kind === "files" ? (
1147 <div
1148 className="min-h-0 flex-1"
1149 onClickCapture={(event) => {
1150 const composedPath = event.nativeEvent.composedPath?.() ?? [];
1151 const title = composedPath.find(
1152 (node): node is HTMLElement =>
1153 node instanceof HTMLElement && node.hasAttribute("data-title"),
1154 );
1155 const filePath = title?.textContent?.trim();
1156 if (filePath) openDiffFile(filePath);
1157 }}
1158 >
1159 <AnnotatableCodeView
1160 key={collapseScopeKey ?? reviewSectionId}
1161 viewerRef={codeViewRef}
1162 codeViewKey={codeViewMountKey}
1163 className="diff-render-surface h-full min-h-0 overflow-auto"
1164 files={codeViewFiles}
1165 sectionId={reviewSectionId}
1166 sectionTitle={reviewSectionTitle}
1167 composerDraftTarget={composerDraftTarget}
1168 renderHeaderPrefix={(fileDiff, fileKey, collapsed) => {
1169 const filePath = resolveFileDiffPath(fileDiff);
1170 return (
1171 <Tooltip>
1172 <TooltipTrigger
1173 render={
1174 <button
1175 type="button"
1176 className={cn(
1177 "-ms-0.5 inline-flex size-5 shrink-0 cursor-pointer items-center justify-center rounded-sm border-0 bg-transparent p-0 transition-colors hover:bg-foreground/10 focus-visible:outline-hidden",
1178 getDiffCollapseIconClassName(fileDiff),
1179 )}
1180 aria-label={collapsed ? `Expand ${filePath}` : `Collapse ${filePath}`}
1181 aria-expanded={!collapsed}
1182 onClick={(event) => {
1183 event.stopPropagation();
1184 toggleDiffFileCollapsed(fileKey);
1185 }}
1186 />
1187 }
1188 >
1189 {collapsed ? (
1190 <ChevronRightIcon className="size-4" />
1191 ) : (
1192 <ChevronDownIcon className="size-4" />
1193 )}
1194 </TooltipTrigger>
1195 <TooltipPopup side="top">
1196 {collapsed ? "Expand diff" : "Collapse diff"}
1197 </TooltipPopup>
1198 </Tooltip>
1199 );
1200 }}
1201 options={{
1202 diffStyle: diffRenderMode === "split" ? "split" : "unified",
1203 lineDiffType: "none",
1204 overflow: wordWrap ? "wrap" : "scroll",
1205 theme: resolveDiffThemeName(resolvedTheme),
1206 themeType: resolvedTheme as DiffThemeType,
1207 unsafeCSS: DIFF_PANEL_UNSAFE_CSS,
1208 stickyHeaders: true,
1209 ...(loadDiffFiles ? { loadDiffFiles } : {}),
1210 itemMetrics: {
1211 diffHeaderHeight: 32,
1212 hunkSeparatorHeight: 24,
1213 paddingTop: 0,
1214 paddingBottom: 0,
1215 },
1216 layout: { paddingTop: 0, paddingBottom: 0, gap: 0 },
1217 }}
1218 />
1219 </div>
1220 ) : (
1221 <div className="min-h-0 flex-1 overflow-auto p-2">
1222 <div className="space-y-2">
1223 <p className="text-[11px] text-muted-foreground/75">{renderablePatch.reason}</p>
1224 <pre
1225 className={cn(
1226 "max-h-[72vh] rounded-md border border-border/70 bg-background/70 p-3 font-mono text-[11px] leading-relaxed text-muted-foreground/90",
1227 wordWrap
1228 ? "overflow-auto whitespace-pre-wrap wrap-break-word"
1229 : "overflow-auto",
1230 )}
1231 >
1232 {renderablePatch.text}
1233 </pre>
1234 </div>
1235 </div>
1236 )}
1237 </div>
1238 </>
1239 )}
1240 </DiffPanelShell>
1241 );
1242}