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