Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
Add per-turn diff viewer with file targeting
Julius Marminge582615971ef7
diff --git a/apps/web/package.json b/apps/web/package.jsonindex 8cccaddfe..517a6bba0 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -12,6 +12,7 @@},"dependencies": {"@base-ui/react": "^1.2.0",+ "@pierre/diffs": "^1.0.11","@t3tools/contracts": "workspace:*","@tanstack/react-pacer": "^0.19.4","@tanstack/react-query": "^5.90.0",diff --git a/apps/web/src/App.tsx b/apps/web/src/App.tsxindex 85fc77c00..6a3d09363 100644--- a/apps/web/src/App.tsx+++ b/apps/web/src/App.tsx@@ -1,8 +1,7 @@import { QueryClient, QueryClientProvider, useQueryClient } from "@tanstack/react-query";-import { useEffect, useRef } from "react";+import { Suspense, lazy, useEffect, useRef } from "react";import ChatView from "./components/ChatView";-import DiffPanel from "./components/DiffPanel";import Sidebar from "./components/Sidebar";import { isElectron } from "./env";import { DEFAULT_MODEL } from "./model-logic";@@ -13,6 +12,8 @@ import { useNativeApi } from "./hooks/useNativeApi";import { AnchoredToastProvider, ToastProvider } from "./components/ui/toast";import { invalidateGitQueries } from "./lib/gitReactQuery";+const DiffPanel = lazy(() => import("./components/DiffPanel"));+function EventRouter() {const api = useNativeApi();const { dispatch } = useStore();@@ -195,7 +196,17 @@ function Layout() {<DesktopProjectBootstrap /><Sidebar /><ChatView />- {state.diffOpen && <DiffPanel />}+ {state.diffOpen && (+ <Suspense+ fallback={+ <aside className="flex h-full w-[560px] shrink-0 items-center justify-center border-l border-border bg-card px-4 text-center text-xs text-muted-foreground/70">+ Loading diff viewer...+ </aside>+ }+ >+ <DiffPanel />+ </Suspense>+ )}</div>);}diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsxindex 2fdccc071..dda7d6a5a 100644--- a/apps/web/src/components/ChatView.tsx+++ b/apps/web/src/components/ChatView.tsx@@ -52,7 +52,9 @@ import {import {derivePendingApprovals,derivePhase,+ deriveTurnDiffSummaries,deriveTimelineEntries,+ type TurnDiffSummary,type PendingApproval,deriveWorkLogEntries,formatDuration,@@ -406,6 +408,18 @@ export default function ChatView() {() => deriveTimelineEntries(activeThread?.messages ?? [], workLogEntries),[activeThread?.messages, workLogEntries],);+ const turnDiffSummaries = useMemo(+ () => deriveTurnDiffSummaries(activeThread?.events ?? []),+ [activeThread?.events],+ );+ const turnDiffSummaryByAssistantMessageId = useMemo(() => {+ const byMessageId = new Map<string, TurnDiffSummary>();+ for (const summary of turnDiffSummaries) {+ if (!summary.assistantMessageId) continue;+ byMessageId.set(summary.assistantMessageId, summary);+ }+ return byMessageId;+ }, [turnDiffSummaries]);const completionSummary = useMemo(() => {if (!activeThread?.latestTurnStartedAt) return null;if (!activeThread.latestTurnCompletedAt) return null;@@ -1685,8 +1699,36 @@ export default function ChatView() {setExpandedImage(image);}, []);const onToggleDiff = useCallback(() => {- dispatch({ type: "TOGGLE_DIFF" });- }, [dispatch]);+ if (state.diffOpen) {+ dispatch({ type: "CLOSE_DIFF" });+ return;+ }++ const latestSummary = turnDiffSummaries[0];+ if (!activeThread || !latestSummary) {+ dispatch({ type: "TOGGLE_DIFF" });+ return;+ }++ dispatch({+ type: "OPEN_DIFF",+ threadId: activeThread.id,+ turnId: latestSummary.turnId,+ ...(latestSummary.files[0]?.path ? { filePath: latestSummary.files[0].path } : {}),+ });+ }, [activeThread, dispatch, state.diffOpen, turnDiffSummaries]);+ const onOpenTurnDiff = useCallback(+ (turnId: string, filePath?: string) => {+ if (!activeThread) return;+ dispatch({+ type: "OPEN_DIFF",+ threadId: activeThread.id,+ turnId,+ ...(filePath ? { filePath } : {}),+ });+ },+ [activeThread, dispatch],+ );// Empty state: no active threadif (!activeThread) {@@ -1761,9 +1803,11 @@ export default function ChatView() {completionDividerBeforeEntryId={completionDividerBeforeEntryId}completionSummary={completionSummary}assistantCompletionByItemId={assistantCompletionByItemId}+ turnDiffSummaryByAssistantMessageId={turnDiffSummaryByAssistantMessageId}nowIso={nowIso}expandedWorkGroups={expandedWorkGroups}onToggleWorkGroup={onToggleWorkGroup}+ onOpenTurnDiff={onOpenTurnDiff}onImageExpand={onExpandTimelineImage}messagesEndRef={messagesEndRef}/>@@ -2268,9 +2312,11 @@ interface MessagesTimelineProps {completionDividerBeforeEntryId: string | null;completionSummary: string | null;assistantCompletionByItemId: Map<string, string>;+ turnDiffSummaryByAssistantMessageId: Map<string, TurnDiffSummary>;nowIso: string;expandedWorkGroups: Record<string, boolean>;onToggleWorkGroup: (groupId: string) => void;+ onOpenTurnDiff: (turnId: string, filePath?: string) => void;onImageExpand: (image: ExpandedImagePreview) => void;messagesEndRef: RefObject<HTMLDivElement | null>;}@@ -2282,9 +2328,11 @@ const MessagesTimeline = memo(function MessagesTimeline({completionDividerBeforeEntryId,completionSummary,assistantCompletionByItemId,+ turnDiffSummaryByAssistantMessageId,nowIso,expandedWorkGroups,onToggleWorkGroup,+ onOpenTurnDiff,onImageExpand,messagesEndRef,}: MessagesTimelineProps) {@@ -2446,6 +2494,39 @@ const MessagesTimeline = memo(function MessagesTimeline({(timelineEntry.message.streaming ? "" : "(empty response)")}/>+ {(() => {+ const turnSummary = turnDiffSummaryByAssistantMessageId.get(timelineEntry.message.id);+ if (!turnSummary) return null;+ return (+ <div className="mt-2 rounded-lg border border-border/80 bg-card/45 p-2.5">+ <div className="mb-1.5 flex items-center justify-between gap-2">+ <p className="text-[10px] uppercase tracking-[0.12em] text-muted-foreground/65">+ Changed files ({turnSummary.files.length})+ </p>+ <Button+ type="button"+ size="xs"+ variant="outline"+ onClick={() => onOpenTurnDiff(turnSummary.turnId, turnSummary.files[0]?.path)}+ >+ View diff+ </Button>+ </div>+ <div className="flex flex-wrap gap-1.5">+ {turnSummary.files.map((file) => (+ <button+ key={`${turnSummary.turnId}:${file.path}`}+ type="button"+ className="rounded-md border border-border/70 bg-background/70 px-2 py-1 font-mono text-[11px] text-muted-foreground/80 transition-colors hover:border-border hover:text-foreground/90"+ onClick={() => onOpenTurnDiff(turnSummary.turnId, file.path)}+ >+ {file.path}+ </button>+ ))}+ </div>+ </div>+ );+ })()}<p className="mt-1.5 text-[10px] text-muted-foreground/30">{formatMessageMeta(timelineEntry.message.createdAt,diff --git a/apps/web/src/components/DiffPanel.tsx b/apps/web/src/components/DiffPanel.tsxindex 84a6cad50..8cecdedd5 100644--- a/apps/web/src/components/DiffPanel.tsx+++ b/apps/web/src/components/DiffPanel.tsx@@ -1,58 +1,145 @@+import { PatchDiff } from "@pierre/diffs/react";import { XIcon } from "lucide-react";+import { useMemo } from "react";import { isElectron } from "../env";+import { deriveTurnDiffSummaries, formatTimestamp } from "../session-logic";import { useStore } from "../store";import { Button } from "./ui/button";+import { cn } from "~/lib/utils";export default function DiffPanel() {- const { dispatch } = useStore();+ const { state, dispatch } = useStore();+ const activeThread = state.threads.find((thread) => thread.id === state.activeThreadId);+ const turnDiffSummaries = useMemo(+ () => deriveTurnDiffSummaries(activeThread?.events ?? []),+ [activeThread?.events],+ );++ const canApplyStoredTarget = Boolean(activeThread && state.diffThreadId === activeThread.id);+ const selectedTurnId = canApplyStoredTarget ? state.diffTurnId : null;+ const selectedFilePath = canApplyStoredTarget ? state.diffFilePath : null;+ const selectedTurn =+ turnDiffSummaries.find((summary) => summary.turnId === selectedTurnId) ?? turnDiffSummaries[0];+ const selectedFile =+ selectedTurn?.files.find((file) => file.path === selectedFilePath) ?? selectedTurn?.files[0];+ const selectedPatch = selectedFile?.diff ?? selectedTurn?.unifiedDiff;++ const selectTurn = (turnId: string) => {+ if (!activeThread) return;+ const turn = turnDiffSummaries.find((summary) => summary.turnId === turnId);+ dispatch({+ type: "SET_DIFF_TARGET",+ threadId: activeThread.id,+ turnId,+ ...(turn?.files[0]?.path ? { filePath: turn.files[0].path } : {}),+ });+ };++ const selectFile = (filePath: string) => {+ if (!activeThread || !selectedTurn) return;+ dispatch({+ type: "SET_DIFF_TARGET",+ threadId: activeThread.id,+ turnId: selectedTurn.turnId,+ filePath,+ });+ };return (- <aside className="flex h-full w-[400px] shrink-0 flex-col border-l border-border bg-card">- {/* Header */}+ <aside className="flex h-full w-[560px] shrink-0 flex-col border-l border-border bg-card"><div- className={`flex items-center justify-between border-b border-border px-4 ${isElectron ? "drag-region h-[52px]" : "py-3"}`}+ className={cn(+ "flex items-center justify-between border-b border-border px-4",+ isElectron ? "drag-region h-[52px]" : "py-3",+ )}>- <h3 className="text-xs font-medium text-foreground">Uncommitted changes</h3>- <Button- type="button"- size="icon-xs"- variant="ghost"- onClick={() => dispatch({ type: "TOGGLE_DIFF" })}- >+ <h3 className="text-xs font-medium text-foreground">Turn diffs</h3>+ <Button type="button" size="icon-xs" variant="ghost" onClick={() => dispatch({ type: "CLOSE_DIFF" })}><XIcon /></Button></div>- {/* Placeholder content */}- <div className="flex-1 overflow-y-auto p-4">- <div className="space-y-3">- <div className="rounded-lg border border-border/80 bg-muted p-3">- <div className="mb-2 flex items-center gap-2">- <span className="rounded bg-emerald-500/20 px-1.5 py-0.5 text-[9px] font-medium text-emerald-400">- M- </span>- <span className="font-mono text-xs text-muted-foreground/80">src/App.tsx</span>- </div>- <div className="space-y-0.5 font-mono text-[11px]">- <div className="text-red-400/60">- const oldValue = "hello";</div>- <div className="text-emerald-400/60">+ const newValue = "world";</div>+ {!activeThread ? (+ <div className="flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70">+ Select a thread to inspect turn diffs.+ </div>+ ) : turnDiffSummaries.length === 0 ? (+ <div className="flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70">+ No completed turn file changes yet.+ </div>+ ) : (+ <>+ <div className="border-b border-border px-3 py-2.5">+ <p className="mb-1.5 text-[10px] uppercase tracking-[0.12em] text-muted-foreground/60">+ Turns+ </p>+ <div className="flex flex-wrap gap-1.5">+ {turnDiffSummaries.map((summary, index) => (+ <button+ key={summary.turnId}+ type="button"+ className={cn(+ "rounded-md border px-2 py-1 text-left transition-colors",+ summary.turnId === selectedTurn?.turnId+ ? "border-border bg-accent text-accent-foreground"+ : "border-border/70 bg-background/70 text-muted-foreground/80 hover:border-border hover:text-foreground/80",+ )}+ onClick={() => selectTurn(summary.turnId)}+ title={summary.turnId}+ >+ <div className="text-[10px] font-medium">Turn {turnDiffSummaries.length - index}</div>+ <div className="text-[10px] opacity-70">{formatTimestamp(summary.completedAt)}</div>+ </button>+ ))}</div></div>- <div className="rounded-lg border border-border/80 bg-muted p-3">- <div className="flex items-center gap-2">- <span className="rounded bg-blue-500/20 px-1.5 py-0.5 text-[9px] font-medium text-blue-400">- A- </span>- <span className="font-mono text-xs text-muted-foreground/80">src/utils.ts</span>+ <div className="min-h-0 flex flex-1">+ <div className="w-[220px] shrink-0 border-r border-border px-2 py-2">+ <p className="mb-1.5 px-1 text-[10px] uppercase tracking-[0.12em] text-muted-foreground/60">+ Files+ </p>+ <div className="space-y-1 overflow-y-auto">+ {selectedTurn?.files.map((file) => (+ <button+ key={`${selectedTurn.turnId}:${file.path}`}+ type="button"+ className={cn(+ "flex w-full items-center justify-between gap-2 rounded-md border px-2 py-1.5 text-left font-mono text-[11px] transition-colors",+ selectedFile?.path === file.path+ ? "border-border bg-accent text-accent-foreground"+ : "border-border/60 bg-background/60 text-muted-foreground/85 hover:border-border hover:text-foreground/90",+ )}+ onClick={() => selectFile(file.path)}+ >+ <span className="truncate">{file.path}</span>+ {file.kind && (+ <span className="rounded-sm border border-border/60 px-1 py-0.5 text-[9px] uppercase tracking-[0.08em]">+ {file.kind}+ </span>+ )}+ </button>+ ))}+ </div></div>- </div>- </div>- <p className="mt-6 text-center text-[10px] text-muted-foreground/30">- Diff integration coming soon- </p>- </div>+ <div className="min-w-0 flex-1 overflow-auto px-3 py-2">+ {!canApplyStoredTarget && state.diffThreadId && (+ <p className="mb-2 text-[11px] text-muted-foreground/65">+ Showing diffs for the active thread.+ </p>+ )}+ {!selectedPatch ? (+ <div className="flex h-full items-center justify-center text-xs text-muted-foreground/70">+ No patch available for this selection.+ </div>+ ) : (+ <PatchDiff patch={selectedPatch} />+ )}+ </div>+ </div>+ </>+ )}</aside>);}diff --git a/apps/web/src/session-logic.test.ts b/apps/web/src/session-logic.test.tsindex d488a0557..4b6302b2b 100644--- a/apps/web/src/session-logic.test.ts+++ b/apps/web/src/session-logic.test.ts@@ -5,6 +5,7 @@ import {type WorkLogEntry,applyEventToMessages,derivePendingApprovals,+ deriveTurnDiffSummaries,deriveTimelineEntries,deriveWorkLogEntries,evolveSession,@@ -393,6 +394,109 @@ describe("deriveWorkLogEntries", () => {});});+describe("deriveTurnDiffSummaries", () => {+ it("collects per-turn file changes and links them to assistant message completion", () => {+ const summaries = deriveTurnDiffSummaries([+ makeEvent({+ id: "evt-turn-start",+ method: "turn/started",+ turnId: "turn-1",+ createdAt: "2026-02-08T10:00:00.000Z",+ }),+ makeEvent({+ id: "evt-file-change",+ method: "item/completed",+ turnId: "turn-1",+ createdAt: "2026-02-08T10:00:01.000Z",+ payload: {+ item: {+ id: "item-file-change",+ type: "fileChange",+ status: "completed",+ changes: [+ {+ path: "src/a.ts",+ kind: "modified",+ diff: "diff --git a/src/a.ts b/src/a.ts\n@@ -1 +1 @@\n-old\n+new\n",+ },+ ],+ },+ },+ }),+ makeEvent({+ id: "evt-turn-diff-updated",+ method: "turn/diff/updated",+ turnId: "turn-1",+ createdAt: "2026-02-08T10:00:02.000Z",+ payload: {+ threadId: "thr-1",+ turnId: "turn-1",+ diff: [+ "diff --git a/src/a.ts b/src/a.ts",+ "@@ -1 +1 @@",+ "-old",+ "+new",+ "diff --git a/src/b.ts b/src/b.ts",+ "@@ -0,0 +1 @@",+ "+created",+ ].join("\n"),+ },+ }),+ makeEvent({+ id: "evt-agent-msg",+ method: "item/completed",+ turnId: "turn-1",+ createdAt: "2026-02-08T10:00:03.000Z",+ payload: {+ item: {+ id: "msg-1",+ type: "agentMessage",+ text: "Done",+ },+ },+ }),+ makeEvent({+ id: "evt-turn-completed",+ method: "turn/completed",+ turnId: "turn-1",+ createdAt: "2026-02-08T10:00:04.000Z",+ payload: {+ turn: {+ id: "turn-1",+ status: "completed",+ },+ },+ }),+ makeEvent({+ id: "evt-turn-2-file-change",+ method: "item/completed",+ turnId: "turn-2",+ createdAt: "2026-02-08T10:00:05.000Z",+ payload: {+ item: {+ id: "item-file-change-2",+ type: "fileChange",+ status: "completed",+ changes: [+ {+ path: "src/unfinished.ts",+ kind: "modified",+ diff: "diff --git a/src/unfinished.ts b/src/unfinished.ts",+ },+ ],+ },+ },+ }),+ ]);++ expect(summaries).toHaveLength(1);+ expect(summaries[0]?.turnId).toBe("turn-1");+ expect(summaries[0]?.assistantMessageId).toBe("msg-1");+ expect(summaries[0]?.files.map((file) => file.path)).toEqual(["src/a.ts", "src/b.ts"]);+ expect(summaries[0]?.files[0]?.kind).toBe("modified");+ });+});+describe("derivePendingApprovals", () => {it("returns pending command/file-change approvals", () => {const approvals = derivePendingApprovals([diff --git a/apps/web/src/session-logic.ts b/apps/web/src/session-logic.tsindex 538186e05..ef2855784 100644--- a/apps/web/src/session-logic.ts+++ b/apps/web/src/session-logic.ts@@ -99,12 +99,31 @@ export type TimelineEntry =entry: WorkLogEntry;};+export interface TurnDiffFileChange {+ path: string;+ kind?: string;+ diff?: string;+}++export interface TurnDiffSummary {+ turnId: string;+ completedAt: string;+ status?: string;+ files: TurnDiffFileChange[];+ unifiedDiff?: string;+ assistantMessageId?: string;+}+function normalizeDetail(value: string | undefined): string | undefined {if (!value) return undefined;const trimmed = value.trim();return trimmed.length > 0 ? trimmed : undefined;}+function asArray(value: unknown): unknown[] | undefined {+ return Array.isArray(value) ? value : undefined;+}+function approvalDetail(event: ProviderEvent): string | undefined {const payload = asObject(event.payload);const command = asString(payload?.command);@@ -438,6 +457,217 @@ export function deriveWorkLogEntries(return entries;}+interface MutableTurnDiffFileChange {+ path: string;+ kind: string | undefined;+ diff: string | undefined;+}++interface MutableTurnDiffSummary {+ turnId: string;+ completedAt: string | undefined;+ status: string | undefined;+ unifiedDiff: string | undefined;+ assistantMessageId: string | undefined;+ filesByPath: Map<string, MutableTurnDiffFileChange>;+}++function parsePathFromDiff(diff: string): string | undefined {+ const normalized = diff.replace(/\r\n/g, "\n");+ const gitHeader = normalized.match(/^diff --git a\/(.+) b\/(.+)$/m);+ if (gitHeader && gitHeader[2]) return gitHeader[2];+ const bPath = normalized.match(/^\+\+\+ b\/(.+)$/m);+ if (bPath && bPath[1]) return bPath[1];+ const direct = normalized.match(/^\+\+\+ (.+)$/m);+ if (!direct || !direct[1] || direct[1] === "/dev/null") {+ return undefined;+ }+ return direct[1];+}++function splitUnifiedDiffByFile(diff: string): Map<string, string> {+ const normalized = diff.replace(/\r\n/g, "\n");+ const byPath = new Map<string, string>();+ const headerMatches = [...normalized.matchAll(/^diff --git a\/(.+) b\/(.+)$/gm)];++ if (headerMatches.length === 0) {+ const path = parsePathFromDiff(normalized);+ if (path) {+ byPath.set(path, normalized.trim());+ }+ return byPath;+ }++ for (let index = 0; index < headerMatches.length; index += 1) {+ const match = headerMatches[index];+ if (!match) continue;+ const start = match.index ?? 0;+ const nextStart = headerMatches[index + 1]?.index ?? normalized.length;+ const segment = normalized.slice(start, nextStart).trim();+ const path = match[2] ?? match[1] ?? parsePathFromDiff(segment);+ if (!path || segment.length === 0) continue;+ byPath.set(path, segment);+ }++ return byPath;+}++function parseFileChangeEntriesFromEvent(event: ProviderEvent): TurnDiffFileChange[] {+ if (event.method !== "item/started" && event.method !== "item/completed") {+ return [];+ }++ const payload = asObject(event.payload);+ const item = asObject(payload?.item);+ if (asString(item?.type) !== "fileChange") {+ return [];+ }++ const changes = asArray(item?.changes);+ if (!changes || changes.length === 0) {+ return [];+ }++ const files: TurnDiffFileChange[] = [];+ for (const rawChange of changes) {+ const change = asObject(rawChange);+ if (!change) continue;+ const diff = normalizeDetail(asString(change.diff));+ const path = normalizeDetail(asString(change.path)) ?? (diff ? parsePathFromDiff(diff) : undefined);+ if (!path) continue;+ const kind = normalizeDetail(asString(change.kind));+ files.push({+ path,+ ...(kind ? { kind } : {}),+ ...(diff ? { diff } : {}),+ });+ }++ return files;+}++export function deriveTurnDiffSummaries(events: ProviderEvent[]): TurnDiffSummary[] {+ const ordered = [...events].toReversed();+ const byTurnId = new Map<string, MutableTurnDiffSummary>();++ const ensureSummary = (turnId: string): MutableTurnDiffSummary => {+ const existing = byTurnId.get(turnId);+ if (existing) return existing;+ const next: MutableTurnDiffSummary = {+ turnId,+ completedAt: undefined,+ status: undefined,+ unifiedDiff: undefined,+ assistantMessageId: undefined,+ filesByPath: new Map(),+ };+ byTurnId.set(turnId, next);+ return next;+ };++ for (const event of ordered) {+ const turnId = eventTurnId(event);+ if (!turnId) continue;+ const summary = ensureSummary(turnId);++ if (event.method === "turn/completed") {+ summary.completedAt = event.createdAt;+ const turn = asObject(asObject(event.payload)?.turn);+ summary.status = normalizeDetail(asString(turn?.status));+ continue;+ }++ if (event.method === "turn/diff/updated") {+ const diff = normalizeDetail(asString(asObject(event.payload)?.diff));+ if (diff) summary.unifiedDiff = diff;+ continue;+ }++ if (event.method === "item/completed") {+ const item = asObject(asObject(event.payload)?.item);+ if (asString(item?.type) === "agentMessage") {+ const itemId = normalizeDetail(asString(item?.id));+ if (itemId) {+ summary.assistantMessageId = itemId;+ }+ }+ }++ for (const change of parseFileChangeEntriesFromEvent(event)) {+ const existing = summary.filesByPath.get(change.path);+ if (!existing) {+ summary.filesByPath.set(change.path, {+ path: change.path,+ kind: change.kind,+ diff: change.diff,+ });+ continue;+ }+ summary.filesByPath.set(change.path, {+ path: change.path,+ kind: change.kind ?? existing.kind,+ diff: change.diff ?? existing.diff,+ });+ }+ }++ const summaries: TurnDiffSummary[] = [];+ for (const summary of byTurnId.values()) {+ if (!summary.completedAt) continue;++ const filesByPath = new Map(summary.filesByPath);+ if (summary.unifiedDiff) {+ const fileDiffs = splitUnifiedDiffByFile(summary.unifiedDiff);+ for (const [path, diff] of fileDiffs) {+ const existing = filesByPath.get(path);+ if (!existing) {+ filesByPath.set(path, { path, kind: undefined, diff });+ continue;+ }+ if (!existing.diff) {+ filesByPath.set(path, { ...existing, diff });+ }+ }+ }++ const files: TurnDiffFileChange[] = [];+ for (const file of Array.from(filesByPath.values()).toSorted((a, b) =>+ a.path.localeCompare(b.path),+ )) {+ const nextFile: TurnDiffFileChange = { path: file.path };+ if (file.kind) {+ nextFile.kind = file.kind;+ }+ if (file.diff) {+ nextFile.diff = file.diff;+ }+ files.push(nextFile);+ }++ if (files.length === 0) continue;++ summaries.push({+ turnId: summary.turnId,+ completedAt: summary.completedAt,+ ...(summary.status ? { status: summary.status } : {}),+ files,+ ...(summary.unifiedDiff ? { unifiedDiff: summary.unifiedDiff } : {}),+ ...(summary.assistantMessageId ? { assistantMessageId: summary.assistantMessageId } : {}),+ });+ }++ summaries.sort((a, b) => {+ const aTime = Date.parse(a.completedAt);+ const bTime = Date.parse(b.completedAt);+ if (Number.isNaN(aTime) || Number.isNaN(bTime)) {+ return b.completedAt.localeCompare(a.completedAt);+ }+ return bTime - aTime;+ });++ return summaries;+}+function toTimestamp(isoDate: string): number {const parsed = Date.parse(isoDate);return Number.isNaN(parsed) ? Number.POSITIVE_INFINITY : parsed;diff --git a/apps/web/src/store.test.ts b/apps/web/src/store.test.tsindex 4ba4b4a50..983166fc8 100644--- a/apps/web/src/store.test.ts+++ b/apps/web/src/store.test.ts@@ -81,6 +81,9 @@ function makeState(thread: Thread): AppState {activeThreadId: thread.id,runtimeMode: "full-access",diffOpen: false,+ diffThreadId: null,+ diffTurnId: null,+ diffFilePath: null,};}@@ -145,6 +148,21 @@ describe("store reducer thread continuity", () => {expect(next.threads[0]?.terminalOpen).toBe(true);});+ it("opens diff panel with an explicit turn/file target", () => {+ const state = makeState(makeThread());+ const next = reducer(state, {+ type: "OPEN_DIFF",+ threadId: "thread-local-1",+ turnId: "turn-1",+ filePath: "src/app.ts",+ });++ expect(next.diffOpen).toBe(true);+ expect(next.diffThreadId).toBe("thread-local-1");+ expect(next.diffTurnId).toBe("turn-1");+ expect(next.diffFilePath).toBe("src/app.ts");+ });+it("sets terminal open state per thread", () => {const state = makeState(makeThread({ terminalOpen: true }));const next = reducer(state, {@@ -532,6 +550,9 @@ describe("store reducer thread continuity", () => {activeThreadId: "thread-b",runtimeMode: "full-access",diffOpen: false,+ diffThreadId: null,+ diffTurnId: null,+ diffFilePath: null,};const next = reducer(state, {@@ -661,6 +682,9 @@ describe("store reducer thread continuity", () => {activeThreadId: "thread-a",runtimeMode: "full-access",diffOpen: false,+ diffThreadId: null,+ diffTurnId: null,+ diffFilePath: null,};const next = reducer(state, {diff --git a/apps/web/src/store.ts b/apps/web/src/store.tsindex e3dc1d50d..e37982043 100644--- a/apps/web/src/store.ts+++ b/apps/web/src/store.ts@@ -42,6 +42,19 @@ type Action =| { type: "SET_THREAD_ACTIVE_TERMINAL"; threadId: string; terminalId: string }| { type: "CLOSE_THREAD_TERMINAL"; threadId: string; terminalId: string }| { type: "TOGGLE_DIFF" }+ | {+ type: "OPEN_DIFF";+ threadId: string;+ turnId?: string;+ filePath?: string;+ }+ | {+ type: "SET_DIFF_TARGET";+ threadId: string;+ turnId?: string;+ filePath?: string;+ }+ | { type: "CLOSE_DIFF" }| {type: "APPLY_EVENT";event: ProviderEvent;@@ -83,6 +96,9 @@ export interface AppState {activeThreadId: string | null;runtimeMode: RuntimeMode;diffOpen: boolean;+ diffThreadId: string | null;+ diffTurnId: string | null;+ diffFilePath: string | null;}const PERSISTED_STATE_KEY = "t3code:renderer-state:v7";@@ -103,6 +119,9 @@ const initialState: AppState = {activeThreadId: null,runtimeMode: DEFAULT_RUNTIME_MODE,diffOpen: false,+ diffThreadId: null,+ diffTurnId: null,+ diffFilePath: null,};// ── Helpers ──────────────────────────────────────────────────────────@@ -125,7 +144,15 @@ function readPersistedState(): AppState {? hydrated.activeThreadId: (threads[0]?.id ?? null);- return { ...hydrated, threads, activeThreadId, diffOpen: false };+ return {+ ...hydrated,+ threads,+ activeThreadId,+ diffOpen: false,+ diffThreadId: null,+ diffTurnId: null,+ diffFilePath: null,+ };} catch {return initialState;}@@ -717,6 +744,26 @@ export function reducer(state: AppState, action: Action): AppState {case "TOGGLE_DIFF":return { ...state, diffOpen: !state.diffOpen };+ case "OPEN_DIFF":+ return {+ ...state,+ diffOpen: true,+ diffThreadId: action.threadId,+ diffTurnId: action.turnId ?? null,+ diffFilePath: action.filePath ?? null,+ };++ case "SET_DIFF_TARGET":+ return {+ ...state,+ diffThreadId: action.threadId,+ diffTurnId: action.turnId ?? null,+ diffFilePath: action.filePath ?? null,+ };++ case "CLOSE_DIFF":+ return { ...state, diffOpen: false };+case "APPLY_TERMINAL_EVENT":if (!state.threads.some((thread) => thread.id === action.event.threadId)) {return state;@@ -901,7 +948,20 @@ export function reducer(state: AppState, action: Action): AppState {const threads = state.threads.filter((t) => t.id !== action.threadId);const activeThreadId =state.activeThreadId === action.threadId ? (threads[0]?.id ?? null) : state.activeThreadId;- return { ...state, threads, activeThreadId };+ const shouldClearDiffTarget = state.diffThreadId === action.threadId;+ return {+ ...state,+ threads,+ activeThreadId,+ ...(shouldClearDiffTarget+ ? {+ diffOpen: false,+ diffThreadId: null,+ diffTurnId: null,+ diffFilePath: null,+ }+ : {}),+ };}default:diff --git a/bun.lock b/bun.lockindex 62e324ce8..b6cd4bdae 100644--- a/bun.lock+++ b/bun.lock@@ -52,6 +52,7 @@"version": "0.0.0","dependencies": {"@base-ui/react": "^1.2.0",+ "@pierre/diffs": "^1.0.11","@t3tools/contracts": "workspace:*","@tanstack/react-pacer": "^0.19.4","@tanstack/react-query": "^5.90.0",@@ -304,6 +305,8 @@"@oxlint/binding-win32-x64-msvc": ["@oxlint/[email protected]", "", { "os": "win32", "cpu": "x64" }, "sha512-DJbQsSJUr4KSi9uU0QqOgI7PX2C+fKGZX+YDprt3vM2sC0dWZsgVTLoN2vtkNyEWJSY2mnvRFUshWXT3bmo0Ug=="],+ "@pierre/diffs": ["@pierre/[email protected]", "", { "dependencies": { "@shikijs/core": "^3.0.0", "@shikijs/engine-javascript": "^3.0.0", "@shikijs/transformers": "^3.0.0", "diff": "8.0.3", "hast-util-to-html": "9.0.5", "lru_map": "0.4.1", "shiki": "^3.0.0" }, "peerDependencies": { "react": "^18.3.1 || ^19.0.0", "react-dom": "^18.3.1 || ^19.0.0" } }, "sha512-j6zIEoyImQy1HfcJqbrDwP0O5I7V2VNXAaw53FqQ+SykRfaNwABeZHs9uibXO4supaXPmTx6LEH9Lffr03e1Tw=="],+"@quansync/fs": ["@quansync/[email protected]", "", { "dependencies": { "quansync": "^1.0.0" } }, "sha512-4TJ3DFtlf1L5LDMaM6CanJ/0lckGNtJcMjQ1NAV6zDmA0tEHKZtxNKin8EgPaVX1YzljbxckyT2tJrpQKAtngQ=="],"@rolldown/binding-android-arm64": ["@rolldown/[email protected]", "", { "os": "android", "cpu": "arm64" }, "sha512-0T1k9FinuBZ/t7rZ8jN6OpUKPnUjNdYHoj/cESWrQ3ZraAJ4OMm6z7QjSfCxqj8mOp9kTKc1zHK3kGz5vMu+nQ=="],@@ -384,6 +387,22 @@"@rollup/rollup-win32-x64-msvc": ["@rollup/[email protected]", "", { "os": "win32", "cpu": "x64" }, "sha512-mxRFDdHIWRxg3UfIIAwCm6NzvxG0jDX/wBN6KsQFTvKFqqg9vTrWUE68qEjHt19A5wwx5X5aUi2zuZT7YR0jrA=="],+ "@shikijs/core": ["@shikijs/[email protected]", "", { "dependencies": { "@shikijs/types": "3.22.0", "@shikijs/vscode-textmate": "^10.0.2", "@types/hast": "^3.0.4", "hast-util-to-html": "^9.0.5" } }, "sha512-iAlTtSDDbJiRpvgL5ugKEATDtHdUVkqgHDm/gbD2ZS9c88mx7G1zSYjjOxp5Qa0eaW0MAQosFRmJSk354PRoQA=="],++ "@shikijs/engine-javascript": ["@shikijs/[email protected]", "", { "dependencies": { "@shikijs/types": "3.22.0", "@shikijs/vscode-textmate": "^10.0.2", "oniguruma-to-es": "^4.3.4" } }, "sha512-jdKhfgW9CRtj3Tor0L7+yPwdG3CgP7W+ZEqSsojrMzCjD1e0IxIbwUMDDpYlVBlC08TACg4puwFGkZfLS+56Tw=="],++ "@shikijs/engine-oniguruma": ["@shikijs/[email protected]", "", { "dependencies": { "@shikijs/types": "3.22.0", "@shikijs/vscode-textmate": "^10.0.2" } }, "sha512-DyXsOG0vGtNtl7ygvabHd7Mt5EY8gCNqR9Y7Lpbbd/PbJvgWrqaKzH1JW6H6qFkuUa8aCxoiYVv8/YfFljiQxA=="],++ "@shikijs/langs": ["@shikijs/[email protected]", "", { "dependencies": { "@shikijs/types": "3.22.0" } }, "sha512-x/42TfhWmp6H00T6uwVrdTJGKgNdFbrEdhaDwSR5fd5zhQ1Q46bHq9EO61SCEWJR0HY7z2HNDMaBZp8JRmKiIA=="],++ "@shikijs/themes": ["@shikijs/[email protected]", "", { "dependencies": { "@shikijs/types": "3.22.0" } }, "sha512-o+tlOKqsr6FE4+mYJG08tfCFDS+3CG20HbldXeVoyP+cYSUxDhrFf3GPjE60U55iOkkjbpY2uC3It/eeja35/g=="],++ "@shikijs/transformers": ["@shikijs/[email protected]", "", { "dependencies": { "@shikijs/core": "3.22.0", "@shikijs/types": "3.22.0" } }, "sha512-E7eRV7mwDBjueLF6852n2oYeJYxBq3NSsDk+uyruYAXONv4U8holGmIrT+mPRJQ1J1SNOH6L8G19KRzmBawrFw=="],++ "@shikijs/types": ["@shikijs/[email protected]", "", { "dependencies": { "@shikijs/vscode-textmate": "^10.0.2", "@types/hast": "^3.0.4" } }, "sha512-491iAekgKDBFE67z70Ok5a8KBMsQ2IJwOWw3us/7ffQkIBCyOQfm/aNwVMBUriP02QshIfgHCBSIYAl3u2eWjg=="],++ "@shikijs/vscode-textmate": ["@shikijs/[email protected]", "", {}, "sha512-83yeghZ2xxin3Nj8z1NMd/NCuca+gsYXswywDy5bHvwlWL8tpTQmzGeUuHd9FC3E/SBEMvzJRwWEOz5gGes9Qg=="],+"@sindresorhus/is": ["@sindresorhus/[email protected]", "", {}, "sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw=="],"@standard-schema/spec": ["@standard-schema/[email protected]", "", {}, "sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w=="],@@ -622,6 +641,8 @@"devlop": ["[email protected]", "", { "dependencies": { "dequal": "^2.0.0" } }, "sha512-RWmIqhcFf1lRYBvNmr7qTNuyCt/7/ns2jbpp1+PalgE/rDQcBT0fioSMUpJ93irlUhC5hrg4cYqe6U+0ImW0rA=="],+ "diff": ["[email protected]", "", {}, "sha512-qejHi7bcSD4hQAZE0tNAawRK1ZtafHDmMTMkrrIGgSLl7hTnQHmKCeB45xAcbfTqK2zowkM3j3bHt/4b/ARbYQ=="],+"dts-resolver": ["[email protected]", "", { "peerDependencies": { "oxc-resolver": ">=11.0.0" }, "optionalPeers": ["oxc-resolver"] }, "sha512-bihc7jPC90VrosXNzK0LTE2cuLP6jr0Ro8jk+kMugHReJVLIpHz/xadeq3MhuwyO4TD4OA3L1Q8pBBFRc08Tsw=="],"dunder-proto": ["[email protected]", "", { "dependencies": { "call-bind-apply-helpers": "^1.0.1", "es-errors": "^1.3.0", "gopd": "^1.2.0" } }, "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A=="],@@ -722,6 +743,8 @@"hast-util-is-element": ["[email protected]", "", { "dependencies": { "@types/hast": "^3.0.0" } }, "sha512-Val9mnv2IWpLbNPqc/pUem+a7Ipj2aHacCwgNfTiK0vJKl0LF+4Ba4+v1oPHFpf3bLYmreq0/l3Gud9S5OH42g=="],+ "hast-util-to-html": ["[email protected]", "", { "dependencies": { "@types/hast": "^3.0.0", "@types/unist": "^3.0.0", "ccount": "^2.0.0", "comma-separated-tokens": "^2.0.0", "hast-util-whitespace": "^3.0.0", "html-void-elements": "^3.0.0", "mdast-util-to-hast": "^13.0.0", "property-information": "^7.0.0", "space-separated-tokens": "^2.0.0", "stringify-entities": "^4.0.0", "zwitch": "^2.0.4" } }, "sha512-OguPdidb+fbHQSU4Q4ZiLKnzWo8Wwsf5bZfbvu7//a9oTYoqD/fWpe96NuHkoS9h0ccGOTe0C4NGXdtS0iObOw=="],+"hast-util-to-jsx-runtime": ["[email protected]", "", { "dependencies": { "@types/estree": "^1.0.0", "@types/hast": "^3.0.0", "@types/unist": "^3.0.0", "comma-separated-tokens": "^2.0.0", "devlop": "^1.0.0", "estree-util-is-identifier-name": "^3.0.0", "hast-util-whitespace": "^3.0.0", "mdast-util-mdx-expression": "^2.0.0", "mdast-util-mdx-jsx": "^3.0.0", "mdast-util-mdxjs-esm": "^2.0.0", "property-information": "^7.0.0", "space-separated-tokens": "^2.0.0", "style-to-js": "^1.0.0", "unist-util-position": "^5.0.0", "vfile-message": "^4.0.0" } }, "sha512-zl6s8LwNyo1P9uw+XJGvZtdFF1GdAkOg8ujOw+4Pyb76874fLps4ueHXDhXWdk6YHQ6OgUtinliG7RsYvCbbBg=="],"hast-util-to-text": ["[email protected]", "", { "dependencies": { "@types/hast": "^3.0.0", "@types/unist": "^3.0.0", "hast-util-is-element": "^3.0.0", "unist-util-find-after": "^5.0.0" } }, "sha512-KK6y/BN8lbaq654j7JgBydev7wuNMcID54lkRav1P0CaE1e47P72AWWPiGKXTJU271ooYzcvTAn/Zt0REnvc7A=="],@@ -736,6 +759,8 @@"html-url-attributes": ["[email protected]", "", {}, "sha512-ol6UPyBWqsrO6EJySPz2O7ZSr856WDrEzM5zMqp+FJJLGMW35cLYmmZnl0vztAZxRUoNZJFTCohfjuIJ8I4QBQ=="],+ "html-void-elements": ["[email protected]", "", {}, "sha512-bEqo66MRXsUGxWHV5IP0PUiAWwoEjba4VCzg0LjFJBpchPaTfyfCKTG6bc5F8ucKec3q5y6qOdGyYTSBEvhCrg=="],+"http-cache-semantics": ["[email protected]", "", {}, "sha512-dTxcvPXqPvXBQpq5dUr6mEMJX4oIEFv6bwom3FDwKRDsuIjjJGANqhBuoAn9c1RQJIdAKav33ED65E2ys+87QQ=="],"http2-wrapper": ["[email protected]", "", { "dependencies": { "quick-lru": "^5.1.1", "resolve-alpn": "^1.0.0" } }, "sha512-V+23sDMr12Wnz7iTcDeJr3O6AIxlnvT/bmaAAAP/Xda35C90p9599p0F1eHR/N1KILWSoWVAiOMFjBBXaXSMxg=="],@@ -822,6 +847,8 @@"lru-cache": ["[email protected]", "", { "dependencies": { "yallist": "^3.0.2" } }, "sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w=="],+ "lru_map": ["[email protected]", "", {}, "sha512-I+lBvqMMFfqaV8CJCISjI3wbjmwVu/VyOoU7+qtu9d7ioW5klMgsTTiUOUp+DJvfTTzKXoPbyC6YfgkNcyPSOg=="],+"lucide-react": ["[email protected]", "", { "peerDependencies": { "react": "^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0" } }, "sha512-JJ8GVTQqFwuliifD48U6+h7DXEHdkhJ/E87kksGByII3qHxtPciVb8T8woQONHBQgHVOl7rSMrrip3SeVNy7Fg=="],"magic-string": ["[email protected]", "", { "dependencies": { "@jridgewell/sourcemap-codec": "^1.5.5" } }, "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ=="],@@ -952,6 +979,10 @@"once": ["[email protected]", "", { "dependencies": { "wrappy": "1" } }, "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w=="],+ "oniguruma-parser": ["[email protected]", "", {}, "sha512-8Unqkvk1RYc6yq2WBYRj4hdnsAxVze8i7iPfQr8e4uSP3tRv0rpZcbGUDvxfQQcdwHt/e9PrMvGCsa8OqG9X3w=="],++ "oniguruma-to-es": ["[email protected]", "", { "dependencies": { "oniguruma-parser": "^0.12.1", "regex": "^6.0.1", "regex-recursion": "^6.0.2" } }, "sha512-3VhUGN3w2eYxnTzHn+ikMI+fp/96KoRSVK9/kMTcFqj1NRDh2IhQCKvYxDnWePKRXY/AqH+Fuiyb7VHSzBjHfA=="],+"open": ["[email protected]", "", { "dependencies": { "default-browser": "^5.2.1", "define-lazy-prop": "^3.0.0", "is-inside-container": "^1.0.0", "wsl-utils": "^0.1.0" } }, "sha512-YgBpdJHPyQ2UE5x+hlSXcnejzAvD0b22U2OuAP+8OnlJT+PjWPxtgmGqKKc+RgTM63U9gN0YzrYc71R2WT/hTA=="],"outvariant": ["[email protected]", "", {}, "sha512-+Sl2UErvtsoajRDKCE5/dBz4DIvHXQQnAxtQTF04OJxY0+DyZXSo5P5Bb7XYWOh81syohlYL24hbDwxedPUJCA=="],@@ -998,6 +1029,12 @@"react-refresh": ["[email protected]", "", {}, "sha512-QgT5//D3jfjJb6Gsjxv0Slpj23ip+HtOpnNgnb2S5zU3CB26G/IDPGoy4RJB42wzFE46DRsstbW6tKHoKbhAxw=="],+ "regex": ["[email protected]", "", { "dependencies": { "regex-utilities": "^2.3.0" } }, "sha512-6VwtthbV4o/7+OaAF9I5L5V3llLEsoPyq9P1JVXkedTP33c7MfCG0/5NOPcSJn0TzXcG9YUrR0gQSWioew3LDg=="],++ "regex-recursion": ["[email protected]", "", { "dependencies": { "regex-utilities": "^2.3.0" } }, "sha512-0YCaSCq2VRIebiaUviZNs0cBz1kg5kVS2UKUfNIx8YVs1cN3AV7NTctO5FOKBA+UT2BPJIWZauYHPqJODG50cg=="],++ "regex-utilities": ["[email protected]", "", {}, "sha512-8VhliFJAWRaUiVvREIiW2NXXTmHs4vMNnSzuJVhscgmGav3g9VDxLrQndI3dZZVVdp0ZO/5v0xmX516/7M9cng=="],+"rehype-highlight": ["[email protected]", "", { "dependencies": { "@types/hast": "^3.0.0", "hast-util-to-text": "^4.0.0", "lowlight": "^3.0.0", "unist-util-visit": "^5.0.0", "vfile": "^6.0.0" } }, "sha512-k158pK7wdC2qL3M5NcZROZ2tR/l7zOzjxXd5VGdcfIyoijjQqpHd3JKtYSBDpDZ38UI2WJWuFAtkMDxmx5kstA=="],"remark-gfm": ["[email protected]", "", { "dependencies": { "@types/mdast": "^4.0.0", "mdast-util-gfm": "^3.0.0", "micromark-extension-gfm": "^3.0.0", "remark-parse": "^11.0.0", "remark-stringify": "^11.0.0", "unified": "^11.0.0" } }, "sha512-1quofZ2RQ9EWdeN34S79+KExV1764+wCUGop5CPL1WGdD0ocPpu91lzPGbwWMECpEpd42kJGQwzRfyov9j4yNg=="],@@ -1046,6 +1083,8 @@"serialize-error": ["[email protected]", "", { "dependencies": { "type-fest": "^0.13.1" } }, "sha512-8I8TjW5KMOKsZQTvoxjuSIa7foAwPWGOts+6o7sgjz41/qMD9VQHEDxi6PBvK2l0MXUmqZyNpUK+T2tQaaElvw=="],+ "shiki": ["[email protected]", "", { "dependencies": { "@shikijs/core": "3.22.0", "@shikijs/engine-javascript": "3.22.0", "@shikijs/engine-oniguruma": "3.22.0", "@shikijs/langs": "3.22.0", "@shikijs/themes": "3.22.0", "@shikijs/types": "3.22.0", "@shikijs/vscode-textmate": "^10.0.2", "@types/hast": "^3.0.4" } }, "sha512-LBnhsoYEe0Eou4e1VgJACes+O6S6QC0w71fCSp5Oya79inkwkm15gQ1UF6VtQ8j/taMDh79hAB49WUk8ALQW3g=="],+"siginfo": ["[email protected]", "", {}, "sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g=="],"signal-exit": ["[email protected]", "", {}, "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw=="],