@@ -26,7 +26,8 @@ import { useOpenInPreferredEditor } from "../editorPreferences";
2626import { useFileContextMenuHandler } from "../fileContextMenu" ;
2727import { type DraftId } from "../composerDraftStore" ;
2828import { openDiffFilePrimaryAction } from "../diffFileActions" ;
29- import { useCheckpointDiff } from "~/state/queries" ;
29+ import { toolCallPatch } from "../lib/toolCallDiff" ;
30+ import { useCheckpointDiff , useTurnItemDetail } from "~/state/queries" ;
3031import { revisionedQuery } from "~/state/revisionedQuery" ;
3132import { cn } from "~/lib/utils" ;
3233import {
@@ -252,6 +253,14 @@ export default function DiffPanel({
252253 const diffSelection = useDiffPanelStore ( ( state ) =>
253254 selectThreadDiffPanelSelection ( state . byThreadKey , routeThreadRef ) ,
254255 ) ;
256+ const toolCallSelection = diffSelection . kind === "tool-call" ? diffSelection : null ;
257+ const isGitSelection = diffSelection . kind === "branch" || diffSelection . kind === "unstaged" ;
258+ const toolCallDetail = useTurnItemDetail (
259+ toolCallSelection && routeThreadRef
260+ ? { ...toolCallSelection , environmentId : routeThreadRef . environmentId }
261+ : null ,
262+ ) ;
263+ const toolCallItem = toolCallDetail . data ?. item ;
255264 const isGitRepo = gitStatusQuery . data ?. isRepo ?? true ;
256265 const turnDiffSummaries = useThreadCheckpointSummaries ( routeThreadRef ) ;
257266 const orderedTurnDiffSummaries = turnDiffSummaries . toSorted ( ( left , right ) => {
@@ -283,24 +292,31 @@ export default function DiffPanel({
283292 orderedTurnDiffSummaries [ 0 ] ) ;
284293 const selectedCheckpointTurnCount = selectedTurn ?. checkpointTurnCount ;
285294 const latestTurn = orderedTurnDiffSummaries [ 0 ] ;
286- const selectedScopeLabel =
287- selectedRunId === null
295+ const selectedScopeLabel = toolCallSelection
296+ ? "Tool call"
297+ : selectedRunId === null
288298 ? selectedGitScope === "unstaged"
289299 ? "Uncommitted"
290300 : "Changes"
291301 : selectedTurn ?. runId === latestTurn ?. runId
292302 ? "Latest turn"
293303 : `Turn ${ selectedCheckpointTurnCount ?? "?" } ` ;
294- const reviewSectionId = selectedTurn ? `turn:${ selectedTurn . runId } ` : selectedGitScope ;
304+ const reviewSectionId = toolCallSelection
305+ ? `tool-call:${ toolCallSelection . threadId } :${ toolCallSelection . itemId } `
306+ : selectedTurn
307+ ? `turn:${ selectedTurn . runId } `
308+ : selectedGitScope ;
295309 const collapseScopeKey = routeThreadRef
296310 ? `${ routeThreadRef . environmentId } :${ routeThreadRef . threadId } :${ reviewSectionId } `
297311 : null ;
298312 const codeViewMountKey = `${ collapseScopeKey ?? reviewSectionId } :${ codeViewRevision } ` ;
299- const reviewSectionTitle = selectedTurn
300- ? `Turn ${ selectedCheckpointTurnCount ?? "?" } `
301- : selectedGitScope === "unstaged"
302- ? "Uncommitted"
303- : "Changes" ;
313+ const reviewSectionTitle = toolCallSelection
314+ ? "Tool call"
315+ : selectedTurn
316+ ? `Turn ${ selectedCheckpointTurnCount ?? "?" } `
317+ : selectedGitScope === "unstaged"
318+ ? "Uncommitted"
319+ : "Changes" ;
304320 const selectedCheckpointRange =
305321 typeof selectedCheckpointTurnCount === "number"
306322 ? {
@@ -320,15 +336,15 @@ export default function DiffPanel({
320336 { enabled : isGitRepo && selectedTurn !== undefined } ,
321337 ) ;
322338 const branchDiffPreviewInput =
323- canReadFiles && selectedRunId === null && activeThread && activeCwd
339+ canReadFiles && isGitSelection && activeThread && activeCwd
324340 ? {
325341 cwd : activeCwd ,
326342 ...( selectedBaseRef ? { baseRef : selectedBaseRef } : { } ) ,
327343 ignoreWhitespace : diffIgnoreWhitespace ,
328344 }
329345 : undefined ;
330346 const canRefreshGitDiff =
331- isGitRepo && selectedRunId === null && activeThread != null && activeCwd != null ;
347+ isGitRepo && isGitSelection && activeThread != null && activeCwd != null ;
332348 // Read under the workspace mutation id, so each mutation refetches the diff; the panel stays
333349 // mounted while hidden, so a mutation made then is already reflected when it shows.
334350 const branchDiffPreview = useEnvironmentQuery (
@@ -355,25 +371,42 @@ export default function DiffPanel({
355371 const preview = branchDiffPreview . data ;
356372 const gitDiff = selectedGitSource ?. diff ;
357373
358- const selectedPatch = selectedTurn ? activeCheckpointDiff . data ?. diff : gitDiff ;
359- const isSelectedPatchTruncated = ! selectedTurn && selectedGitSource ?. truncated === true ;
360- const selectedPatchQuery = selectedTurn ? activeCheckpointDiff : branchDiffPreview ;
374+ const selectedPatch = toolCallSelection
375+ ? toolCallItem ?. type === "file_change"
376+ ? toolCallPatch ( toolCallItem )
377+ : undefined
378+ : selectedTurn
379+ ? activeCheckpointDiff . data ?. diff
380+ : gitDiff ;
381+ const isSelectedPatchTruncated = isGitSelection && selectedGitSource ?. truncated === true ;
382+ const selectedPatchQuery = toolCallSelection
383+ ? toolCallDetail
384+ : selectedTurn
385+ ? activeCheckpointDiff
386+ : branchDiffPreview ;
361387 const isLoadingSelectedPatch = selectedPatchQuery . isPending && selectedPatchQuery . data === null ;
362- const selectedPatchError = selectedTurn ? activeCheckpointDiff . error : branchDiffPreview . error ;
388+ const selectedPatchError = toolCallSelection
389+ ? toolCallDetail . error
390+ : selectedTurn
391+ ? activeCheckpointDiff . error
392+ : branchDiffPreview . error ;
363393 const hasResolvedPatch = typeof selectedPatch === "string" ;
364394 const hasNoNetChanges = hasResolvedPatch && selectedPatch . trim ( ) . length === 0 ;
365395 const lazySource =
366- ! selectedTurn && selectedGitSource ?. truncated && selectedGitSource . files
396+ isGitSelection && selectedGitSource ?. truncated && selectedGitSource . files
367397 ? selectedGitSource
368398 : null ;
369399 const renderablePatch = getRenderablePatch (
370400 lazySource ? undefined : selectedPatch ,
371401 `diff-panel:${ resolvedTheme } ` ,
372- { compactPartialHunkOffsets : selectedRunId === null } ,
402+ {
403+ compactPartialHunkOffsets : isGitSelection ,
404+ ...( toolCallSelection ? { ignoreWhitespace : diffIgnoreWhitespace } : { } ) ,
405+ } ,
373406 ) ;
374407 const fileStats = new Map ( lazySource ?. files ?. map ( ( file ) => [ file . path , file ] ) ) ;
375408 const sourceLineStat =
376- ! selectedTurn && selectedGitSource ?. files
409+ isGitSelection && selectedGitSource ?. files
377410 ? selectedGitSource . files . reduce (
378411 ( total , file ) => ( {
379412 additions : total . additions + file . additions ,
@@ -383,7 +416,7 @@ export default function DiffPanel({
383416 )
384417 : null ;
385418 const currentLoadDiffFiles =
386- selectedRunId === null && activeThread && preview && selectedGitSource && canReadFiles
419+ isGitSelection && activeThread && preview && selectedGitSource && canReadFiles
387420 ? createGitDiffFileContentsLoader ( getDiffFileContents , {
388421 environmentId : activeThread . environmentId ,
389422 cwd : preview . cwd ,
@@ -400,10 +433,7 @@ export default function DiffPanel({
400433 return currentLoadDiffFiles ( fileDiff ) ;
401434 } ) ;
402435 const localBranchRefs = useEnvironmentQuery (
403- selectedRunId === null &&
404- selectedGitScope === "branch" &&
405- activeThread &&
406- branchDiffPreview . data ?. cwd
436+ isGitSelection && selectedGitScope === "branch" && activeThread && branchDiffPreview . data ?. cwd
407437 ? vcsEnvironment . listRefs ( {
408438 environmentId : activeThread . environmentId ,
409439 input : {
@@ -417,10 +447,7 @@ export default function DiffPanel({
417447 : null ,
418448 ) ;
419449 const remoteBranchRefs = useEnvironmentQuery (
420- selectedRunId === null &&
421- selectedGitScope === "branch" &&
422- activeThread &&
423- branchDiffPreview . data ?. cwd
450+ isGitSelection && selectedGitScope === "branch" && activeThread && branchDiffPreview . data ?. cwd
424451 ? vcsEnvironment . listRefs ( {
425452 environmentId : activeThread . environmentId ,
426453 input : {
@@ -630,8 +657,9 @@ export default function DiffPanel({
630657 useDiffPanelStore . getState ( ) . selectBranchBaseRef ( routeThreadRef , baseRef ) ;
631658 } ;
632659 const selectedTurnValue = selectedTurn ? `turn:${ selectedTurn . runId } ` : "" ;
633- const selectedScopeValue =
634- selectedRunId === null
660+ const selectedScopeValue = toolCallSelection
661+ ? ""
662+ : selectedRunId === null
635663 ? selectedGitScope
636664 : selectedTurn ?. runId === latestTurn ?. runId
637665 ? "latest"
@@ -698,7 +726,7 @@ export default function DiffPanel({
698726 </ DropdownMenuSub >
699727 </ DropdownMenuContent >
700728 </ DropdownMenu >
701- { selectedRunId === null && selectedGitScope === "branch" && selectedGitSource ?. baseRef && (
729+ { isGitSelection && selectedGitScope === "branch" && selectedGitSource ?. baseRef && (
702730 < div
703731 className = "flex min-w-0 max-w-full items-center gap-2 overflow-hidden text-xs text-muted-foreground"
704732 aria-label = { `Comparing ${ selectedGitSource . headRef ?? "HEAD" } against ${ selectedGitSource . baseRef } ` }
@@ -831,7 +859,7 @@ export default function DiffPanel({
831859 ) }
832860 </ div >
833861 < div className = "flex shrink-0 items-center gap-1 [-webkit-app-region:no-drag]" >
834- { codeViewFiles . length > 0 || ( ! selectedTurn && selectedGitSource ?. files ?. length ) ? (
862+ { codeViewFiles . length > 0 || ( isGitSelection && selectedGitSource ?. files ?. length ) ? (
835863 < DiffStatLabel
836864 additions = { diffLineStat . additions }
837865 deletions = { diffLineStat . deletions }
@@ -973,15 +1001,15 @@ export default function DiffPanel({
9731001 < div className = "flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70" >
9741002 Select a thread to inspect turn diffs.
9751003 </ div >
976- ) : ! isGitRepo ? (
1004+ ) : ! isGitRepo && ! toolCallSelection ? (
9771005 < div className = "flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70" >
9781006 Turn diffs are unavailable because this project is not a git repository.
9791007 </ div >
9801008 ) : selectedRunId !== null && orderedTurnDiffSummaries . length === 0 ? (
9811009 < div className = "flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70" >
9821010 No completed turns yet.
9831011 </ div >
984- ) : selectedRunId === null && ! canReadFiles ? (
1012+ ) : isGitSelection && ! canReadFiles ? (
9851013 fileAccess . isPending ? (
9861014 < DiffPanelLoadingState label = "Checking file access..." />
9871015 ) : (
@@ -1007,11 +1035,13 @@ export default function DiffPanel({
10071035 isLoadingSelectedPatch ? (
10081036 < DiffPanelLoadingState
10091037 label = {
1010- selectedTurn
1011- ? "Loading checkpoint diff..."
1012- : selectedGitScope === "unstaged"
1013- ? "Loading uncommitted changes..."
1014- : "Loading changes..."
1038+ toolCallSelection
1039+ ? "Loading tool call diff..."
1040+ : selectedTurn
1041+ ? "Loading checkpoint diff..."
1042+ : selectedGitScope === "unstaged"
1043+ ? "Loading uncommitted changes..."
1044+ : "Loading changes..."
10151045 }
10161046 />
10171047 ) : (
0 commit comments