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