diff --git a/frontend/src/pages/task-attempt-compare.tsx b/frontend/src/pages/task-attempt-compare.tsx index 39fe2334..a6738fa9 100644 --- a/frontend/src/pages/task-attempt-compare.tsx +++ b/frontend/src/pages/task-attempt-compare.tsx @@ -18,6 +18,8 @@ import { RefreshCw, GitBranch, Trash2, + Eye, + EyeOff, } from "lucide-react"; import { makeRequest } from "@/lib/api"; import type { @@ -53,6 +55,7 @@ export function TaskAttemptComparePage() { const [expandedSections, setExpandedSections] = useState>( new Set() ); + const [showAllUnchanged, setShowAllUnchanged] = useState(false); const [deletingFiles, setDeletingFiles] = useState>(new Set()); const [fileToDelete, setFileToDelete] = useState(null); @@ -184,7 +187,7 @@ export function TaskAttemptComparePage() { }; const getChunkClassName = (chunkType: DiffChunkType) => { - const baseClass = "font-mono text-sm whitespace-pre px-3 py-1"; + const baseClass = "font-mono text-sm whitespace-pre py-1 flex"; switch (chunkType) { case "Insert": @@ -212,7 +215,8 @@ export function TaskAttemptComparePage() { interface ProcessedLine { content: string; chunkType: DiffChunkType; - lineNumber: number; + oldLineNumber?: number; + newLineNumber?: number; } interface ProcessedSection { @@ -226,7 +230,8 @@ export function TaskAttemptComparePage() { const processFileChunks = (chunks: DiffChunk[], fileIndex: number) => { const CONTEXT_LINES = 3; const lines: ProcessedLine[] = []; - let currentLineNumber = 1; + let oldLineNumber = 1; + let newLineNumber = 1; // Convert chunks to lines with line numbers chunks.forEach((chunk) => { @@ -234,11 +239,28 @@ export function TaskAttemptComparePage() { chunkLines.forEach((line, index) => { if (index < chunkLines.length - 1 || line !== "") { // Skip empty last line from split - lines.push({ + const processedLine: ProcessedLine = { content: line, chunkType: chunk.chunk_type, - lineNumber: currentLineNumber++, - }); + }; + + // Set line numbers based on chunk type + switch (chunk.chunk_type) { + case "Equal": + processedLine.oldLineNumber = oldLineNumber++; + processedLine.newLineNumber = newLineNumber++; + break; + case "Delete": + processedLine.oldLineNumber = oldLineNumber++; + // No new line number for deletions + break; + case "Insert": + processedLine.newLineNumber = newLineNumber++; + // No old line number for insertions + break; + } + + lines.push(processedLine); } }); }); @@ -267,9 +289,10 @@ export function TaskAttemptComparePage() { if ( contextLength <= CONTEXT_LINES * 2 || - (!hasPrevChange && !hasNextChange) + (!hasPrevChange && !hasNextChange) || + showAllUnchanged ) { - // Show all context if it's short or if there are no changes around it + // Show all context if it's short, no changes around it, or global toggle is on sections.push({ type: "context", lines: lines.slice(i, nextChangeIndex), @@ -292,7 +315,7 @@ export function TaskAttemptComparePage() { if (expandEnd > expandStart) { const expandKey = `${fileIndex}-${expandStart}-${expandEnd}`; - const isExpanded = expandedSections.has(expandKey); + const isExpanded = expandedSections.has(expandKey) || showAllUnchanged; if (isExpanded) { sections.push({ @@ -514,13 +537,35 @@ export function TaskAttemptComparePage() { - - Diff: Base Commit vs. Current Worktree - -

- Shows changes made in the task attempt worktree compared to the base - commit -

+
+
+ + Diff: Base Commit vs. Current Worktree + +

+ Shows changes made in the task attempt worktree compared to the base + commit +

+
+ +
{!diff || diff.files.length === 0 ? ( @@ -562,36 +607,38 @@ export function TaskAttemptComparePage() { {processFileChunks(file.chunks, fileIndex).map( (section, sectionIndex) => { if ( - section.type === "context" && - section.lines.length === 0 && - section.expandKey + section.type === "context" && + section.lines.length === 0 && + section.expandKey && + !showAllUnchanged ) { - // Render expand button - const lineCount = - parseInt(section.expandKey.split("-")[2]) - - parseInt(section.expandKey.split("-")[1]); - return ( -
- -
- ); + // Render expand button (only when global toggle is off) + const lineCount = + parseInt(section.expandKey.split("-")[2]) - + parseInt(section.expandKey.split("-")[1]); + return ( +
+ +
+ ); + } // Render lines (context, change, or expanded) return (
{section.type === "expanded" && - section.expandKey && ( + section.expandKey && + !showAllUnchanged && (
))}