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