Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3031dfd122 | ||
|
|
0cb4e75728 | ||
|
|
01accc005e | ||
|
|
0d9c26810f | ||
|
|
564474f927 | ||
|
|
47fcd16003 | ||
|
|
24c617d32e | ||
|
|
22e1a4cf92 | ||
|
|
79382b272c | ||
|
|
90e199d6a7 | ||
|
|
9a8a5b3935 | ||
|
|
58a8d653a8 | ||
|
|
eecb53498a |
No files matched your search
@@ -296,6 +296,82 @@ describe("ProviderManager", () => {
|
|||||||
manager.dispose();
|
manager.dispose();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("emits checkpoint/captured after turn completion checkpoint capture", async () => {
|
||||||
|
const manager = new ProviderManager();
|
||||||
|
const events: Array<{ method: string; payload?: unknown; threadId?: string }> = [];
|
||||||
|
manager.on("event", (event) => {
|
||||||
|
events.push({
|
||||||
|
method: event.method,
|
||||||
|
...(event.payload !== undefined ? { payload: event.payload } : {}),
|
||||||
|
...(event.threadId ? { threadId: event.threadId } : {}),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const internals = manager as unknown as {
|
||||||
|
onCodexEvent: (event: {
|
||||||
|
id: string;
|
||||||
|
kind: "notification";
|
||||||
|
provider: "codex";
|
||||||
|
sessionId: string;
|
||||||
|
createdAt: string;
|
||||||
|
method: string;
|
||||||
|
threadId: string;
|
||||||
|
}) => void;
|
||||||
|
codex: {
|
||||||
|
hasSession: (sessionId: string) => boolean;
|
||||||
|
readThread: (sessionId: string) => Promise<{
|
||||||
|
threadId: string;
|
||||||
|
turns: Array<{ id: string; items: unknown[] }>;
|
||||||
|
}>;
|
||||||
|
};
|
||||||
|
filesystemCheckpointStore: {
|
||||||
|
captureCheckpoint: (input: {
|
||||||
|
cwd: string;
|
||||||
|
threadId: string;
|
||||||
|
turnCount: number;
|
||||||
|
}) => Promise<void>;
|
||||||
|
};
|
||||||
|
sessionCheckpointCwds: Map<string, string>;
|
||||||
|
};
|
||||||
|
|
||||||
|
internals.codex.hasSession = () => true;
|
||||||
|
internals.codex.readThread = async () => ({
|
||||||
|
threadId: "thr_1",
|
||||||
|
turns: [{ id: "turn_1", items: [] }],
|
||||||
|
});
|
||||||
|
const captureCheckpoint = vi.fn(async () => undefined);
|
||||||
|
internals.filesystemCheckpointStore.captureCheckpoint = captureCheckpoint;
|
||||||
|
internals.sessionCheckpointCwds.set("sess_1", "/repo");
|
||||||
|
|
||||||
|
internals.onCodexEvent({
|
||||||
|
id: "evt-turn-complete",
|
||||||
|
kind: "notification",
|
||||||
|
provider: "codex",
|
||||||
|
sessionId: "sess_1",
|
||||||
|
createdAt: "2026-02-19T00:00:00.000Z",
|
||||||
|
method: "turn/completed",
|
||||||
|
threadId: "thr_1",
|
||||||
|
});
|
||||||
|
|
||||||
|
await vi.waitFor(() => {
|
||||||
|
expect(captureCheckpoint).toHaveBeenCalledWith({
|
||||||
|
cwd: "/repo",
|
||||||
|
threadId: "thr_1",
|
||||||
|
turnCount: 1,
|
||||||
|
});
|
||||||
|
expect(events.some((event) => event.method === "checkpoint/captured")).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
const checkpointCapturedEvent = events.find((event) => event.method === "checkpoint/captured");
|
||||||
|
expect(checkpointCapturedEvent?.threadId).toBe("thr_1");
|
||||||
|
expect(checkpointCapturedEvent?.payload).toEqual({
|
||||||
|
threadId: "thr_1",
|
||||||
|
turnCount: 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
manager.dispose();
|
||||||
|
});
|
||||||
|
|
||||||
it("lazily initializes filesystem checkpoints before diffing when cache is missing", async () => {
|
it("lazily initializes filesystem checkpoints before diffing when cache is missing", async () => {
|
||||||
const manager = new ProviderManager();
|
const manager = new ProviderManager();
|
||||||
const internals = manager as unknown as {
|
const internals = manager as unknown as {
|
||||||
|
|||||||
@@ -477,11 +477,19 @@ export class ProviderManager extends EventEmitter<ProviderManagerEvents> {
|
|||||||
|
|
||||||
const checkpointCwd = this.sessionCheckpointCwds.get(event.sessionId);
|
const checkpointCwd = this.sessionCheckpointCwds.get(event.sessionId);
|
||||||
if (!checkpointCwd) {
|
if (!checkpointCwd) {
|
||||||
void this.getOrInitializeFilesystemCheckpointCwd(event.sessionId).catch((error) => {
|
void this.getOrInitializeFilesystemCheckpointCwd(event.sessionId)
|
||||||
const message =
|
.then(async (initializedCwd) => {
|
||||||
error instanceof Error ? error.message : "Failed to initialize filesystem checkpoints.";
|
if (!initializedCwd || !this.codex.hasSession(event.sessionId)) {
|
||||||
this.emitFilesystemCheckpointError(event.sessionId, message, event.threadId);
|
return;
|
||||||
});
|
}
|
||||||
|
const snapshot = await this.codex.readThread(event.sessionId);
|
||||||
|
this.emitCheckpointCaptured(event.sessionId, snapshot.threadId, snapshot.turns.length);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
const message =
|
||||||
|
error instanceof Error ? error.message : "Failed to initialize filesystem checkpoints.";
|
||||||
|
this.emitFilesystemCheckpointError(event.sessionId, message, event.threadId);
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -496,12 +504,29 @@ export class ProviderManager extends EventEmitter<ProviderManagerEvents> {
|
|||||||
threadId: snapshot.threadId,
|
threadId: snapshot.threadId,
|
||||||
turnCount: snapshot.turns.length,
|
turnCount: snapshot.turns.length,
|
||||||
});
|
});
|
||||||
|
this.emitCheckpointCaptured(event.sessionId, snapshot.threadId, snapshot.turns.length);
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
const message = error instanceof Error ? error.message : "Failed to capture checkpoint.";
|
const message = error instanceof Error ? error.message : "Failed to capture checkpoint.";
|
||||||
this.emitFilesystemCheckpointError(event.sessionId, message, event.threadId);
|
this.emitFilesystemCheckpointError(event.sessionId, message, event.threadId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private emitCheckpointCaptured(sessionId: string, threadId: string, turnCount: number): void {
|
||||||
|
this.emit("event", {
|
||||||
|
id: randomUUID(),
|
||||||
|
kind: "notification",
|
||||||
|
provider: "codex",
|
||||||
|
sessionId,
|
||||||
|
createdAt: new Date().toISOString(),
|
||||||
|
method: "checkpoint/captured",
|
||||||
|
threadId,
|
||||||
|
payload: {
|
||||||
|
threadId,
|
||||||
|
turnCount,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private emitFilesystemCheckpointError(
|
private emitFilesystemCheckpointError(
|
||||||
sessionId: string,
|
sessionId: string,
|
||||||
message: string,
|
message: string,
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
import { AUTO_SCROLL_BOTTOM_THRESHOLD_PX, isScrollContainerNearBottom } from "./chat-scroll";
|
import { AUTO_SCROLL_BOTTOM_EPSILON_PX, isScrollContainerAtBottom } from "./chat-scroll";
|
||||||
|
|
||||||
describe("isScrollContainerNearBottom", () => {
|
describe("isScrollContainerAtBottom", () => {
|
||||||
it("returns true when already at bottom", () => {
|
it("returns true when already at bottom", () => {
|
||||||
expect(
|
expect(
|
||||||
isScrollContainerNearBottom({
|
isScrollContainerAtBottom({
|
||||||
scrollTop: 600,
|
scrollTop: 600,
|
||||||
clientHeight: 400,
|
clientHeight: 400,
|
||||||
scrollHeight: 1_000,
|
scrollHeight: 1_000,
|
||||||
@@ -13,31 +13,31 @@ describe("isScrollContainerNearBottom", () => {
|
|||||||
).toBe(true);
|
).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns true when within the auto-scroll threshold", () => {
|
it("returns true when within the bottom epsilon", () => {
|
||||||
expect(
|
expect(
|
||||||
isScrollContainerNearBottom({
|
isScrollContainerAtBottom({
|
||||||
scrollTop: 540,
|
scrollTop: 599,
|
||||||
clientHeight: 400,
|
clientHeight: 400,
|
||||||
scrollHeight: 1_000,
|
scrollHeight: 1_000,
|
||||||
}),
|
}),
|
||||||
).toBe(true);
|
).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns false when the user is meaningfully above the bottom", () => {
|
it("returns false when the user is above the epsilon", () => {
|
||||||
expect(
|
expect(
|
||||||
isScrollContainerNearBottom({
|
isScrollContainerAtBottom({
|
||||||
scrollTop: 520,
|
scrollTop: 597,
|
||||||
clientHeight: 400,
|
clientHeight: 400,
|
||||||
scrollHeight: 1_000,
|
scrollHeight: 1_000,
|
||||||
}),
|
}),
|
||||||
).toBe(false);
|
).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("clamps negative thresholds to zero", () => {
|
it("clamps negative epsilons to zero", () => {
|
||||||
expect(
|
expect(
|
||||||
isScrollContainerNearBottom(
|
isScrollContainerAtBottom(
|
||||||
{
|
{
|
||||||
scrollTop: 539,
|
scrollTop: 599,
|
||||||
clientHeight: 400,
|
clientHeight: 400,
|
||||||
scrollHeight: 1_000,
|
scrollHeight: 1_000,
|
||||||
},
|
},
|
||||||
@@ -46,17 +46,27 @@ describe("isScrollContainerNearBottom", () => {
|
|||||||
).toBe(false);
|
).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("falls back to the default threshold for non-finite values", () => {
|
it("falls back to the default epsilon for non-finite values", () => {
|
||||||
expect(
|
expect(
|
||||||
isScrollContainerNearBottom(
|
isScrollContainerAtBottom(
|
||||||
{
|
{
|
||||||
scrollTop: 540,
|
scrollTop: 599,
|
||||||
clientHeight: 400,
|
clientHeight: 400,
|
||||||
scrollHeight: 1_000,
|
scrollHeight: 1_000,
|
||||||
},
|
},
|
||||||
Number.NaN,
|
Number.NaN,
|
||||||
),
|
),
|
||||||
).toBe(true);
|
).toBe(true);
|
||||||
expect(AUTO_SCROLL_BOTTOM_THRESHOLD_PX).toBe(64);
|
expect(AUTO_SCROLL_BOTTOM_EPSILON_PX).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("treats overscrolled values as bottom", () => {
|
||||||
|
expect(
|
||||||
|
isScrollContainerAtBottom({
|
||||||
|
scrollTop: 610,
|
||||||
|
clientHeight: 400,
|
||||||
|
scrollHeight: 1_000,
|
||||||
|
}),
|
||||||
|
).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
export const AUTO_SCROLL_BOTTOM_THRESHOLD_PX = 64;
|
export const AUTO_SCROLL_BOTTOM_EPSILON_PX = 2;
|
||||||
|
|
||||||
interface ScrollPosition {
|
interface ScrollPosition {
|
||||||
scrollTop: number;
|
scrollTop: number;
|
||||||
@@ -6,19 +6,19 @@ interface ScrollPosition {
|
|||||||
scrollHeight: number;
|
scrollHeight: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isScrollContainerNearBottom(
|
export function isScrollContainerAtBottom(
|
||||||
position: ScrollPosition,
|
position: ScrollPosition,
|
||||||
thresholdPx = AUTO_SCROLL_BOTTOM_THRESHOLD_PX,
|
epsilonPx = AUTO_SCROLL_BOTTOM_EPSILON_PX,
|
||||||
): boolean {
|
): boolean {
|
||||||
const threshold = Number.isFinite(thresholdPx)
|
const epsilon = Number.isFinite(epsilonPx)
|
||||||
? Math.max(0, thresholdPx)
|
? Math.max(0, epsilonPx)
|
||||||
: AUTO_SCROLL_BOTTOM_THRESHOLD_PX;
|
: AUTO_SCROLL_BOTTOM_EPSILON_PX;
|
||||||
|
|
||||||
const { scrollTop, clientHeight, scrollHeight } = position;
|
const { scrollTop, clientHeight, scrollHeight } = position;
|
||||||
if (![scrollTop, clientHeight, scrollHeight].every(Number.isFinite)) {
|
if (![scrollTop, clientHeight, scrollHeight].every(Number.isFinite)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const distanceFromBottom = scrollHeight - clientHeight - scrollTop;
|
const distanceFromBottom = Math.max(0, scrollHeight - clientHeight - scrollTop);
|
||||||
return distanceFromBottom <= threshold;
|
return distanceFromBottom <= epsilon;
|
||||||
}
|
}
|
||||||
@@ -17,6 +17,9 @@ import {
|
|||||||
type DragEvent,
|
type DragEvent,
|
||||||
type FormEvent,
|
type FormEvent,
|
||||||
type KeyboardEvent,
|
type KeyboardEvent,
|
||||||
|
type PointerEvent,
|
||||||
|
type TouchEvent,
|
||||||
|
type WheelEvent,
|
||||||
memo,
|
memo,
|
||||||
type RefObject,
|
type RefObject,
|
||||||
useCallback,
|
useCallback,
|
||||||
@@ -30,8 +33,8 @@ import { useMutation, useQueries, useQuery, useQueryClient } from "@tanstack/rea
|
|||||||
import { useDebouncedValue } from "@tanstack/react-pacer";
|
import { useDebouncedValue } from "@tanstack/react-pacer";
|
||||||
import { type VirtualItem, useVirtualizer } from "@tanstack/react-virtual";
|
import { type VirtualItem, useVirtualizer } from "@tanstack/react-virtual";
|
||||||
import { gitBranchesQueryOptions, gitCreateWorktreeMutationOptions } from "~/lib/gitReactQuery";
|
import { gitBranchesQueryOptions, gitCreateWorktreeMutationOptions } from "~/lib/gitReactQuery";
|
||||||
import { projectSearchEntriesQueryOptions } from "~/lib/projectReactQuery";
|
|
||||||
import { checkpointDiffQueryOptions } from "~/lib/providerReactQuery";
|
import { checkpointDiffQueryOptions } from "~/lib/providerReactQuery";
|
||||||
|
import { projectSearchEntriesQueryOptions } from "~/lib/projectReactQuery";
|
||||||
import { serverConfigQueryOptions, serverQueryKeys } from "~/lib/serverReactQuery";
|
import { serverConfigQueryOptions, serverQueryKeys } from "~/lib/serverReactQuery";
|
||||||
|
|
||||||
import { isElectron } from "../env";
|
import { isElectron } from "../env";
|
||||||
@@ -50,9 +53,9 @@ import {
|
|||||||
resolveModelSlug,
|
resolveModelSlug,
|
||||||
} from "../model-logic";
|
} from "../model-logic";
|
||||||
import {
|
import {
|
||||||
countDiffStat,
|
|
||||||
derivePendingApprovals,
|
derivePendingApprovals,
|
||||||
derivePhase,
|
derivePhase,
|
||||||
|
deriveTurnDiffFilesFromUnifiedDiff,
|
||||||
deriveTimelineEntries,
|
deriveTimelineEntries,
|
||||||
type TurnDiffSummary,
|
type TurnDiffSummary,
|
||||||
type PendingApproval,
|
type PendingApproval,
|
||||||
@@ -61,13 +64,14 @@ import {
|
|||||||
formatElapsed,
|
formatElapsed,
|
||||||
formatTimestamp,
|
formatTimestamp,
|
||||||
} from "../session-logic";
|
} from "../session-logic";
|
||||||
import { isScrollContainerNearBottom } from "../chat-scroll";
|
import { isScrollContainerAtBottom } from "../chat-scroll";
|
||||||
import { useStore } from "../store";
|
import { useStore } from "../store";
|
||||||
import { truncateTitle } from "../truncateTitle";
|
import { truncateTitle } from "../truncateTitle";
|
||||||
import {
|
import {
|
||||||
DEFAULT_THREAD_TERMINAL_ID,
|
DEFAULT_THREAD_TERMINAL_ID,
|
||||||
MAX_THREAD_TERMINAL_COUNT,
|
MAX_THREAD_TERMINAL_COUNT,
|
||||||
type ChatImageAttachment,
|
type ChatImageAttachment,
|
||||||
|
type TurnDiffFileChange,
|
||||||
} from "../types";
|
} from "../types";
|
||||||
import { basenameOfPath, getVscodeIconUrlForEntry } from "../vscode-icons";
|
import { basenameOfPath, getVscodeIconUrlForEntry } from "../vscode-icons";
|
||||||
import { useTheme } from "../hooks/useTheme";
|
import { useTheme } from "../hooks/useTheme";
|
||||||
@@ -182,6 +186,33 @@ interface ExpandedImagePreview {
|
|||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TurnCheckpointFilesState =
|
||||||
|
| {
|
||||||
|
status: "pending" | "loading";
|
||||||
|
files: TurnDiffFileChange[];
|
||||||
|
errorMessage?: undefined;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
status: "error";
|
||||||
|
files: TurnDiffFileChange[];
|
||||||
|
errorMessage: string;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
status: "ready";
|
||||||
|
files: TurnDiffFileChange[];
|
||||||
|
errorMessage?: undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
function checkpointErrorMessage(error: unknown): string {
|
||||||
|
if (error instanceof Error && error.message.trim().length > 0) {
|
||||||
|
return error.message;
|
||||||
|
}
|
||||||
|
if (typeof error === "string" && error.trim().length > 0) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
return "Checkpoint diff is unavailable.";
|
||||||
|
}
|
||||||
|
|
||||||
type ComposerCommandItem =
|
type ComposerCommandItem =
|
||||||
| {
|
| {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -374,12 +405,18 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
|||||||
>(() => readLastInvokedScriptByProjectFromStorage());
|
>(() => readLastInvokedScriptByProjectFromStorage());
|
||||||
const messagesScrollRef = useRef<HTMLDivElement>(null);
|
const messagesScrollRef = useRef<HTMLDivElement>(null);
|
||||||
const shouldAutoScrollRef = useRef(true);
|
const shouldAutoScrollRef = useRef(true);
|
||||||
|
const lastKnownScrollTopRef = useRef(0);
|
||||||
|
const isPointerScrollActiveRef = useRef(false);
|
||||||
|
const lastTouchClientYRef = useRef<number | null>(null);
|
||||||
|
const pendingUserScrollUpIntentRef = useRef(false);
|
||||||
|
const pendingAutoScrollFrameRef = useRef<number | null>(null);
|
||||||
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
||||||
const composerCommandInputRef = useRef<HTMLInputElement>(null);
|
const composerCommandInputRef = useRef<HTMLInputElement>(null);
|
||||||
const composerImagesRef = useRef<ComposerImageAttachment[]>([]);
|
const composerImagesRef = useRef<ComposerImageAttachment[]>([]);
|
||||||
const dragDepthRef = useRef(0);
|
const dragDepthRef = useRef(0);
|
||||||
const terminalOpenByThreadRef = useRef<Record<string, boolean>>({});
|
const terminalOpenByThreadRef = useRef<Record<string, boolean>>({});
|
||||||
const checkpointHydrationSessionRequestRef = useRef(new Set<string>());
|
const checkpointHydrationSessionRequestRef = useRef(new Set<string>());
|
||||||
|
const checkpointTurnCountSyncFingerprintRef = useRef(new Map<string, string>());
|
||||||
|
|
||||||
const activeThread = state.threads.find((t) => t.id === threadId);
|
const activeThread = state.threads.find((t) => t.id === threadId);
|
||||||
const activeThreadId = activeThread?.id ?? null;
|
const activeThreadId = activeThread?.id ?? null;
|
||||||
@@ -429,6 +466,69 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
|||||||
}
|
}
|
||||||
return byMessageId;
|
return byMessageId;
|
||||||
}, [turnDiffSummaries]);
|
}, [turnDiffSummaries]);
|
||||||
|
const checkpointDiffInputsByTurn = useMemo(
|
||||||
|
() =>
|
||||||
|
turnDiffSummaries
|
||||||
|
.filter((summary) => summary.assistantMessageId)
|
||||||
|
.map((summary) => {
|
||||||
|
const checkpointTurnCount =
|
||||||
|
summary.checkpointTurnCount ?? inferredCheckpointTurnCountByTurnId[summary.turnId];
|
||||||
|
return {
|
||||||
|
turnId: summary.turnId,
|
||||||
|
checkpointTurnCount:
|
||||||
|
typeof checkpointTurnCount === "number" ? checkpointTurnCount : null,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
[inferredCheckpointTurnCountByTurnId, turnDiffSummaries],
|
||||||
|
);
|
||||||
|
const checkpointDiffQueriesByTurn = useQueries({
|
||||||
|
queries: checkpointDiffInputsByTurn.map((input) =>
|
||||||
|
checkpointDiffQueryOptions(api, {
|
||||||
|
sessionId: activeSessionId,
|
||||||
|
threadRuntimeId: activeThreadRuntimeId,
|
||||||
|
fromTurnCount:
|
||||||
|
typeof input.checkpointTurnCount === "number"
|
||||||
|
? Math.max(0, input.checkpointTurnCount - 1)
|
||||||
|
: null,
|
||||||
|
toTurnCount: input.checkpointTurnCount,
|
||||||
|
cacheScope: `turn:${input.turnId}`,
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
});
|
||||||
|
const turnCheckpointFilesByTurnId = useMemo(() => {
|
||||||
|
const byTurnId = new Map<string, TurnCheckpointFilesState>();
|
||||||
|
for (let index = 0; index < checkpointDiffInputsByTurn.length; index += 1) {
|
||||||
|
const input = checkpointDiffInputsByTurn[index];
|
||||||
|
const query = checkpointDiffQueriesByTurn[index];
|
||||||
|
if (!input || !query) continue;
|
||||||
|
|
||||||
|
if (!activeSessionId || typeof input.checkpointTurnCount !== "number") {
|
||||||
|
byTurnId.set(input.turnId, { status: "pending", files: [] });
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const diff = query.data?.diff;
|
||||||
|
if (typeof diff === "string") {
|
||||||
|
byTurnId.set(input.turnId, {
|
||||||
|
status: "ready",
|
||||||
|
files: deriveTurnDiffFilesFromUnifiedDiff(diff),
|
||||||
|
});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (query.isError) {
|
||||||
|
byTurnId.set(input.turnId, {
|
||||||
|
status: "error",
|
||||||
|
files: [],
|
||||||
|
errorMessage: checkpointErrorMessage(query.error),
|
||||||
|
});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
byTurnId.set(input.turnId, { status: "loading", files: [] });
|
||||||
|
}
|
||||||
|
return byTurnId;
|
||||||
|
}, [activeSessionId, checkpointDiffInputsByTurn, checkpointDiffQueriesByTurn]);
|
||||||
const revertTurnCountByUserMessageId = useMemo(() => {
|
const revertTurnCountByUserMessageId = useMemo(() => {
|
||||||
const byUserMessageId = new Map<string, number>();
|
const byUserMessageId = new Map<string, number>();
|
||||||
for (let index = 0; index < timelineEntries.length; index += 1) {
|
for (let index = 0; index < timelineEntries.length; index += 1) {
|
||||||
@@ -492,68 +592,6 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
|||||||
});
|
});
|
||||||
}, [activeThreadId, dispatch, inferredCheckpointTurnCountByTurnId, turnDiffSummaries]);
|
}, [activeThreadId, dispatch, inferredCheckpointTurnCountByTurnId, turnDiffSummaries]);
|
||||||
|
|
||||||
const checkpointDiffHydrationTargets = useMemo(() => {
|
|
||||||
if (!api || !activeThreadId || !activeSessionId || turnDiffSummaries.length === 0) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
return turnDiffSummaries.flatMap((summary) => {
|
|
||||||
const turnCount = inferredCheckpointTurnCountByTurnId[summary.turnId];
|
|
||||||
if (summary.checkpointDiffLoaded || typeof turnCount !== "number") {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
turnId: summary.turnId,
|
|
||||||
fromTurnCount: Math.max(0, turnCount - 1),
|
|
||||||
toTurnCount: turnCount,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
});
|
|
||||||
}, [
|
|
||||||
activeSessionId,
|
|
||||||
activeThreadId,
|
|
||||||
api,
|
|
||||||
inferredCheckpointTurnCountByTurnId,
|
|
||||||
turnDiffSummaries,
|
|
||||||
]);
|
|
||||||
|
|
||||||
const checkpointDiffHydrationQueries = useQueries({
|
|
||||||
queries: checkpointDiffHydrationTargets.map((target) =>
|
|
||||||
checkpointDiffQueryOptions(api, {
|
|
||||||
sessionId: activeSessionId,
|
|
||||||
threadRuntimeId: activeThreadRuntimeId,
|
|
||||||
fromTurnCount: target.fromTurnCount,
|
|
||||||
toTurnCount: target.toTurnCount,
|
|
||||||
cacheScope: `turn:${target.turnId}`,
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!activeThreadId || checkpointDiffHydrationTargets.length === 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const checkpointDiffByTurnId: Record<string, string> = {};
|
|
||||||
for (let index = 0; index < checkpointDiffHydrationTargets.length; index += 1) {
|
|
||||||
const target = checkpointDiffHydrationTargets[index];
|
|
||||||
const query = checkpointDiffHydrationQueries[index];
|
|
||||||
const diff = query?.data?.diff;
|
|
||||||
if (!target || !diff) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
checkpointDiffByTurnId[target.turnId] = diff;
|
|
||||||
}
|
|
||||||
if (Object.keys(checkpointDiffByTurnId).length === 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
dispatch({
|
|
||||||
type: "SET_THREAD_TURN_CHECKPOINT_DIFFS",
|
|
||||||
threadId: activeThreadId,
|
|
||||||
checkpointDiffByTurnId,
|
|
||||||
});
|
|
||||||
}, [activeThreadId, checkpointDiffHydrationQueries, checkpointDiffHydrationTargets, dispatch]);
|
|
||||||
|
|
||||||
const completionSummary = useMemo(() => {
|
const completionSummary = useMemo(() => {
|
||||||
if (!activeThread?.latestTurnStartedAt) return null;
|
if (!activeThread?.latestTurnStartedAt) return null;
|
||||||
if (!activeThread.latestTurnCompletedAt) return null;
|
if (!activeThread.latestTurnCompletedAt) return null;
|
||||||
@@ -1064,33 +1102,97 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
|||||||
}
|
}
|
||||||
}, [lastInvokedScriptByProjectId]);
|
}, [lastInvokedScriptByProjectId]);
|
||||||
|
|
||||||
// Auto-scroll on new messages
|
// Auto-tail while the user stays at the bottom.
|
||||||
const messageCount = activeThread?.messages.length ?? 0;
|
|
||||||
const workLogCount = workLogEntries.length;
|
const workLogCount = workLogEntries.length;
|
||||||
const scrollMessagesToBottom = useCallback((behavior: ScrollBehavior = "auto") => {
|
const scrollMessagesToBottom = useCallback((behavior: ScrollBehavior = "auto") => {
|
||||||
const scrollContainer = messagesScrollRef.current;
|
const scrollContainer = messagesScrollRef.current;
|
||||||
if (!scrollContainer) return;
|
if (!scrollContainer) return;
|
||||||
scrollContainer.scrollTo({ top: scrollContainer.scrollHeight, behavior });
|
scrollContainer.scrollTo({ top: scrollContainer.scrollHeight, behavior });
|
||||||
|
lastKnownScrollTopRef.current = scrollContainer.scrollTop;
|
||||||
shouldAutoScrollRef.current = true;
|
shouldAutoScrollRef.current = true;
|
||||||
}, []);
|
}, []);
|
||||||
|
const requestAutoTailToBottom = useCallback(() => {
|
||||||
|
if (pendingAutoScrollFrameRef.current !== null) return;
|
||||||
|
pendingAutoScrollFrameRef.current = window.requestAnimationFrame(() => {
|
||||||
|
pendingAutoScrollFrameRef.current = null;
|
||||||
|
if (!shouldAutoScrollRef.current) return;
|
||||||
|
scrollMessagesToBottom();
|
||||||
|
});
|
||||||
|
}, [scrollMessagesToBottom]);
|
||||||
const onMessagesScroll = useCallback(() => {
|
const onMessagesScroll = useCallback(() => {
|
||||||
const scrollContainer = messagesScrollRef.current;
|
const scrollContainer = messagesScrollRef.current;
|
||||||
if (!scrollContainer) return;
|
if (!scrollContainer) return;
|
||||||
shouldAutoScrollRef.current = isScrollContainerNearBottom(scrollContainer);
|
const currentScrollTop = scrollContainer.scrollTop;
|
||||||
|
const atBottom = isScrollContainerAtBottom(scrollContainer);
|
||||||
|
|
||||||
|
if (!shouldAutoScrollRef.current && atBottom) {
|
||||||
|
shouldAutoScrollRef.current = true;
|
||||||
|
pendingUserScrollUpIntentRef.current = false;
|
||||||
|
} else if (shouldAutoScrollRef.current && pendingUserScrollUpIntentRef.current) {
|
||||||
|
const scrolledUp = currentScrollTop < lastKnownScrollTopRef.current - 1;
|
||||||
|
if (scrolledUp) {
|
||||||
|
shouldAutoScrollRef.current = false;
|
||||||
|
}
|
||||||
|
pendingUserScrollUpIntentRef.current = false;
|
||||||
|
} else if (shouldAutoScrollRef.current && isPointerScrollActiveRef.current) {
|
||||||
|
// Pointer-driven upward scroll means user takes control.
|
||||||
|
const scrolledUp = currentScrollTop < lastKnownScrollTopRef.current - 1;
|
||||||
|
if (scrolledUp) {
|
||||||
|
shouldAutoScrollRef.current = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lastKnownScrollTopRef.current = currentScrollTop;
|
||||||
|
}, []);
|
||||||
|
const onMessagesWheel = useCallback((event: WheelEvent<HTMLDivElement>) => {
|
||||||
|
// Wheel-up indicates user intent to move away from bottom.
|
||||||
|
if (event.deltaY < 0) {
|
||||||
|
pendingUserScrollUpIntentRef.current = true;
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
const onMessagesPointerDown = useCallback((_event: PointerEvent<HTMLDivElement>) => {
|
||||||
|
isPointerScrollActiveRef.current = true;
|
||||||
|
}, []);
|
||||||
|
const onMessagesPointerUp = useCallback((_event: PointerEvent<HTMLDivElement>) => {
|
||||||
|
isPointerScrollActiveRef.current = false;
|
||||||
|
}, []);
|
||||||
|
const onMessagesPointerCancel = useCallback((_event: PointerEvent<HTMLDivElement>) => {
|
||||||
|
isPointerScrollActiveRef.current = false;
|
||||||
|
}, []);
|
||||||
|
const onMessagesTouchStart = useCallback((event: TouchEvent<HTMLDivElement>) => {
|
||||||
|
const touch = event.touches[0];
|
||||||
|
if (!touch) return;
|
||||||
|
lastTouchClientYRef.current = touch.clientY;
|
||||||
|
}, []);
|
||||||
|
const onMessagesTouchMove = useCallback((event: TouchEvent<HTMLDivElement>) => {
|
||||||
|
const touch = event.touches[0];
|
||||||
|
if (!touch) return;
|
||||||
|
const previousTouchY = lastTouchClientYRef.current;
|
||||||
|
if (previousTouchY !== null && touch.clientY > previousTouchY + 1) {
|
||||||
|
// Finger moved downward => user intends to scroll content upward.
|
||||||
|
pendingUserScrollUpIntentRef.current = true;
|
||||||
|
}
|
||||||
|
lastTouchClientYRef.current = touch.clientY;
|
||||||
|
}, []);
|
||||||
|
const onMessagesTouchEnd = useCallback((_event: TouchEvent<HTMLDivElement>) => {
|
||||||
|
lastTouchClientYRef.current = null;
|
||||||
}, []);
|
}, []);
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (!activeThread?.id) return;
|
if (!activeThread?.id) return;
|
||||||
scrollMessagesToBottom();
|
scrollMessagesToBottom();
|
||||||
}, [activeThread?.id, scrollMessagesToBottom]);
|
}, [activeThread?.id, scrollMessagesToBottom]);
|
||||||
useEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (!shouldAutoScrollRef.current) return;
|
if (!shouldAutoScrollRef.current) return;
|
||||||
scrollMessagesToBottom("smooth");
|
requestAutoTailToBottom();
|
||||||
}, [messageCount, scrollMessagesToBottom]);
|
}, [activeThread?.messages, workLogCount, requestAutoTailToBottom]);
|
||||||
useEffect(() => {
|
useEffect(
|
||||||
if (phase !== "running") return;
|
() => () => {
|
||||||
if (!shouldAutoScrollRef.current) return;
|
if (pendingAutoScrollFrameRef.current === null) return;
|
||||||
scrollMessagesToBottom("smooth");
|
window.cancelAnimationFrame(pendingAutoScrollFrameRef.current);
|
||||||
}, [phase, workLogCount, scrollMessagesToBottom]);
|
pendingAutoScrollFrameRef.current = null;
|
||||||
|
},
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setExpandedWorkGroups({});
|
setExpandedWorkGroups({});
|
||||||
@@ -1407,6 +1509,53 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
|||||||
focusComposer();
|
focusComposer();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const syncCheckpointTurnCounts = useCallback(
|
||||||
|
async (input: {
|
||||||
|
threadId: string;
|
||||||
|
sessionId: string;
|
||||||
|
threadRuntimeId: string | null;
|
||||||
|
}): Promise<void> => {
|
||||||
|
if (!api || turnDiffSummaries.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const turnIds = turnDiffSummaries.map((summary) => summary.turnId);
|
||||||
|
if (turnIds.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const syncKey = `${input.threadId}:${input.sessionId}:${input.threadRuntimeId ?? "none"}`;
|
||||||
|
const turnFingerprint = turnIds.join(",");
|
||||||
|
if (checkpointTurnCountSyncFingerprintRef.current.get(syncKey) === turnFingerprint) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
checkpointTurnCountSyncFingerprintRef.current.set(syncKey, turnFingerprint);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await api.providers.listCheckpoints({
|
||||||
|
sessionId: input.sessionId,
|
||||||
|
});
|
||||||
|
const turnIdSet = new Set(turnIds);
|
||||||
|
const checkpointTurnCountByTurnId = Object.fromEntries(
|
||||||
|
result.checkpoints
|
||||||
|
.filter((checkpoint) => checkpoint.turnCount > 0 && turnIdSet.has(checkpoint.id))
|
||||||
|
.map((checkpoint) => [checkpoint.id, checkpoint.turnCount] as const),
|
||||||
|
);
|
||||||
|
if (Object.keys(checkpointTurnCountByTurnId).length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dispatch({
|
||||||
|
type: "SET_THREAD_TURN_CHECKPOINT_COUNTS",
|
||||||
|
threadId: input.threadId,
|
||||||
|
checkpointTurnCountByTurnId,
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
checkpointTurnCountSyncFingerprintRef.current.delete(syncKey);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[api, dispatch, turnDiffSummaries],
|
||||||
|
);
|
||||||
|
|
||||||
const ensureSession = useCallback(
|
const ensureSession = useCallback(
|
||||||
async (cwdOverride?: string): Promise<EnsuredSessionInfo | null> => {
|
async (cwdOverride?: string): Promise<EnsuredSessionInfo | null> => {
|
||||||
if (!api || !activeThread || !activeProject) return null;
|
if (!api || !activeThread || !activeProject) return null;
|
||||||
@@ -1418,6 +1567,11 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
|||||||
: sessionThreadId === activeThread.codexThreadId
|
: sessionThreadId === activeThread.codexThreadId
|
||||||
? "resumed"
|
? "resumed"
|
||||||
: "fallback_new";
|
: "fallback_new";
|
||||||
|
await syncCheckpointTurnCounts({
|
||||||
|
threadId: activeThread.id,
|
||||||
|
sessionId: activeThread.session.sessionId,
|
||||||
|
threadRuntimeId: sessionThreadId,
|
||||||
|
});
|
||||||
return {
|
return {
|
||||||
sessionId: activeThread.session.sessionId,
|
sessionId: activeThread.session.sessionId,
|
||||||
resolvedThreadId: sessionThreadId,
|
resolvedThreadId: sessionThreadId,
|
||||||
@@ -1448,6 +1602,11 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
|||||||
: resolvedThreadId === priorCodexThreadId
|
: resolvedThreadId === priorCodexThreadId
|
||||||
? "resumed"
|
? "resumed"
|
||||||
: "fallback_new";
|
: "fallback_new";
|
||||||
|
await syncCheckpointTurnCounts({
|
||||||
|
threadId: activeThread.id,
|
||||||
|
sessionId: session.sessionId,
|
||||||
|
threadRuntimeId: resolvedThreadId,
|
||||||
|
});
|
||||||
return {
|
return {
|
||||||
sessionId: session.sessionId,
|
sessionId: session.sessionId,
|
||||||
resolvedThreadId,
|
resolvedThreadId,
|
||||||
@@ -1472,6 +1631,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
|||||||
runtimeApprovalPolicy,
|
runtimeApprovalPolicy,
|
||||||
runtimeSandboxMode,
|
runtimeSandboxMode,
|
||||||
selectedModel,
|
selectedModel,
|
||||||
|
syncCheckpointTurnCounts,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -1480,22 +1640,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
|||||||
if (phase === "running" || isSending || isConnecting || isRevertingCheckpoint) return;
|
if (phase === "running" || isSending || isConnecting || isRevertingCheckpoint) return;
|
||||||
const hasThreadIdentity = Boolean(activeThreadRuntimeId);
|
const hasThreadIdentity = Boolean(activeThreadRuntimeId);
|
||||||
if (!hasThreadIdentity) return;
|
if (!hasThreadIdentity) return;
|
||||||
const selectedDiffTurnId =
|
if (turnDiffSummaries.length === 0) return;
|
||||||
state.diffOpen && state.diffThreadId === activeThreadId ? state.diffTurnId : null;
|
|
||||||
const selectedDiffTurn =
|
|
||||||
selectedDiffTurnId === null
|
|
||||||
? undefined
|
|
||||||
: (turnDiffSummaries.find((summary) => summary.turnId === selectedDiffTurnId) ??
|
|
||||||
turnDiffSummaries[0]);
|
|
||||||
const selectedTurnMissingPatchBody = Boolean(
|
|
||||||
selectedDiffTurn &&
|
|
||||||
!selectedDiffTurn.unifiedDiff &&
|
|
||||||
selectedDiffTurn.files.every((file) => !file.diff),
|
|
||||||
);
|
|
||||||
const hasPendingDiffHydration =
|
|
||||||
turnDiffSummaries.some((summary) => !summary.checkpointDiffLoaded) ||
|
|
||||||
selectedTurnMissingPatchBody;
|
|
||||||
if (!hasPendingDiffHydration) return;
|
|
||||||
|
|
||||||
const requestKey = `${activeThreadId}:${activeThreadRuntimeId ?? "none"}`;
|
const requestKey = `${activeThreadId}:${activeThreadRuntimeId ?? "none"}`;
|
||||||
if (checkpointHydrationSessionRequestRef.current.has(requestKey)) {
|
if (checkpointHydrationSessionRequestRef.current.has(requestKey)) {
|
||||||
@@ -1522,9 +1667,6 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
|||||||
isSending,
|
isSending,
|
||||||
phase,
|
phase,
|
||||||
setThreadError,
|
setThreadError,
|
||||||
state.diffOpen,
|
|
||||||
state.diffThreadId,
|
|
||||||
state.diffTurnId,
|
|
||||||
turnDiffSummaries,
|
turnDiffSummaries,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -1980,6 +2122,14 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
|||||||
ref={messagesScrollRef}
|
ref={messagesScrollRef}
|
||||||
className="min-h-0 flex-1 overflow-y-auto px-5 py-4"
|
className="min-h-0 flex-1 overflow-y-auto px-5 py-4"
|
||||||
onScroll={onMessagesScroll}
|
onScroll={onMessagesScroll}
|
||||||
|
onWheel={onMessagesWheel}
|
||||||
|
onPointerDown={onMessagesPointerDown}
|
||||||
|
onPointerUp={onMessagesPointerUp}
|
||||||
|
onPointerCancel={onMessagesPointerCancel}
|
||||||
|
onTouchStart={onMessagesTouchStart}
|
||||||
|
onTouchMove={onMessagesTouchMove}
|
||||||
|
onTouchEnd={onMessagesTouchEnd}
|
||||||
|
onTouchCancel={onMessagesTouchEnd}
|
||||||
>
|
>
|
||||||
<MessagesTimeline
|
<MessagesTimeline
|
||||||
hasMessages={activeThread.messages.length > 0}
|
hasMessages={activeThread.messages.length > 0}
|
||||||
@@ -1990,6 +2140,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
|||||||
completionSummary={completionSummary}
|
completionSummary={completionSummary}
|
||||||
assistantCompletionByItemId={assistantCompletionByItemId}
|
assistantCompletionByItemId={assistantCompletionByItemId}
|
||||||
turnDiffSummaryByAssistantMessageId={turnDiffSummaryByAssistantMessageId}
|
turnDiffSummaryByAssistantMessageId={turnDiffSummaryByAssistantMessageId}
|
||||||
|
turnCheckpointFilesByTurnId={turnCheckpointFilesByTurnId}
|
||||||
nowIso={nowIso}
|
nowIso={nowIso}
|
||||||
expandedWorkGroups={expandedWorkGroups}
|
expandedWorkGroups={expandedWorkGroups}
|
||||||
onToggleWorkGroup={onToggleWorkGroup}
|
onToggleWorkGroup={onToggleWorkGroup}
|
||||||
@@ -2455,6 +2606,7 @@ interface MessagesTimelineProps {
|
|||||||
completionSummary: string | null;
|
completionSummary: string | null;
|
||||||
assistantCompletionByItemId: Map<string, string>;
|
assistantCompletionByItemId: Map<string, string>;
|
||||||
turnDiffSummaryByAssistantMessageId: Map<string, TurnDiffSummary>;
|
turnDiffSummaryByAssistantMessageId: Map<string, TurnDiffSummary>;
|
||||||
|
turnCheckpointFilesByTurnId: Map<string, TurnCheckpointFilesState>;
|
||||||
nowIso: string;
|
nowIso: string;
|
||||||
expandedWorkGroups: Record<string, boolean>;
|
expandedWorkGroups: Record<string, boolean>;
|
||||||
onToggleWorkGroup: (groupId: string) => void;
|
onToggleWorkGroup: (groupId: string) => void;
|
||||||
@@ -2491,6 +2643,7 @@ const MessagesTimeline = memo(function MessagesTimeline({
|
|||||||
completionSummary,
|
completionSummary,
|
||||||
assistantCompletionByItemId,
|
assistantCompletionByItemId,
|
||||||
turnDiffSummaryByAssistantMessageId,
|
turnDiffSummaryByAssistantMessageId,
|
||||||
|
turnCheckpointFilesByTurnId,
|
||||||
nowIso,
|
nowIso,
|
||||||
expandedWorkGroups,
|
expandedWorkGroups,
|
||||||
onToggleWorkGroup,
|
onToggleWorkGroup,
|
||||||
@@ -2739,70 +2892,63 @@ const MessagesTimeline = memo(function MessagesTimeline({
|
|||||||
row.message.id,
|
row.message.id,
|
||||||
);
|
);
|
||||||
if (!turnSummary) return null;
|
if (!turnSummary) return null;
|
||||||
const isCheckpointDiffLoading =
|
const checkpointFilesState = turnCheckpointFilesByTurnId.get(turnSummary.turnId);
|
||||||
!turnSummary.checkpointDiffLoaded && turnSummary.files.length === 0;
|
const checkpointFiles = checkpointFilesState?.files ?? [];
|
||||||
const summaryStat = turnSummary.unifiedDiff
|
const summaryStat = checkpointFiles.reduce(
|
||||||
? countDiffStat(turnSummary.unifiedDiff)
|
(acc, file) => {
|
||||||
: turnSummary.files.reduce(
|
if (typeof file.additions !== "number" || typeof file.deletions !== "number") {
|
||||||
(acc, file) => {
|
return acc;
|
||||||
const next =
|
}
|
||||||
typeof file.additions === "number" &&
|
return {
|
||||||
typeof file.deletions === "number"
|
additions: acc.additions + file.additions,
|
||||||
? { additions: file.additions, deletions: file.deletions }
|
deletions: acc.deletions + file.deletions,
|
||||||
: file.diff
|
};
|
||||||
? countDiffStat(file.diff)
|
},
|
||||||
: null;
|
{ additions: 0, deletions: 0 },
|
||||||
if (!next) {
|
);
|
||||||
return acc;
|
const changedFileCountLabel =
|
||||||
}
|
checkpointFilesState?.status === "ready" ? String(checkpointFiles.length) : "...";
|
||||||
return {
|
|
||||||
additions: acc.additions + next.additions,
|
|
||||||
deletions: acc.deletions + next.deletions,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
{ additions: 0, deletions: 0 },
|
|
||||||
);
|
|
||||||
const changedFileCountLabel = isCheckpointDiffLoading
|
|
||||||
? "..."
|
|
||||||
: String(turnSummary.files.length);
|
|
||||||
return (
|
return (
|
||||||
<div className="mt-2 rounded-lg border border-border/80 bg-card/45 p-2.5">
|
<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">
|
<div className="mb-1.5 flex items-center justify-between gap-2">
|
||||||
<p className="text-[10px] uppercase tracking-[0.12em] text-muted-foreground/65">
|
<p className="text-[10px] uppercase tracking-[0.12em] text-muted-foreground/65">
|
||||||
<span>Changed files ({changedFileCountLabel})</span>
|
<span>Changed files ({changedFileCountLabel})</span>
|
||||||
{!isCheckpointDiffLoading &&
|
{(summaryStat.additions > 0 || summaryStat.deletions > 0) && (
|
||||||
(summaryStat.additions > 0 || summaryStat.deletions > 0) && (
|
<>
|
||||||
<>
|
<span className="mx-1">•</span>
|
||||||
<span className="mx-1">•</span>
|
<span className="text-success">+{summaryStat.additions}</span>
|
||||||
<span className="text-success">
|
<span className="mx-0.5 text-muted-foreground/70">/</span>
|
||||||
+{summaryStat.additions}
|
<span className="text-destructive">-{summaryStat.deletions}</span>
|
||||||
</span>
|
</>
|
||||||
<span className="mx-0.5 text-muted-foreground/70">/</span>
|
)}
|
||||||
<span className="text-destructive">
|
|
||||||
-{summaryStat.deletions}
|
|
||||||
</span>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</p>
|
</p>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
size="xs"
|
size="xs"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
onClick={() =>
|
onClick={() => onOpenTurnDiff(turnSummary.turnId, checkpointFiles[0]?.path)}
|
||||||
onOpenTurnDiff(turnSummary.turnId, turnSummary.files[0]?.path)
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
View diff
|
View diff
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
{isCheckpointDiffLoading && (
|
{!checkpointFilesState || checkpointFilesState.status === "pending" ? (
|
||||||
<p className="mb-1.5 text-[11px] text-muted-foreground/70">
|
<p className="text-[11px] text-muted-foreground/70">
|
||||||
|
Waiting for checkpoint metadata...
|
||||||
|
</p>
|
||||||
|
) : checkpointFilesState?.status === "loading" ? (
|
||||||
|
<p className="text-[11px] text-muted-foreground/70">
|
||||||
Loading checkpoint diff...
|
Loading checkpoint diff...
|
||||||
</p>
|
</p>
|
||||||
)}
|
) : checkpointFilesState?.status === "error" ? (
|
||||||
{turnSummary.files.length > 0 ? (
|
<p
|
||||||
|
className="truncate text-[11px] text-muted-foreground/70"
|
||||||
|
title={checkpointFilesState.errorMessage}
|
||||||
|
>
|
||||||
|
{checkpointFilesState.errorMessage}
|
||||||
|
</p>
|
||||||
|
) : checkpointFiles.length > 0 ? (
|
||||||
<div className="flex flex-wrap gap-1.5">
|
<div className="flex flex-wrap gap-1.5">
|
||||||
{turnSummary.files.map((file) => (
|
{checkpointFiles.map((file) => (
|
||||||
<button
|
<button
|
||||||
key={`${turnSummary.turnId}:${file.path}`}
|
key={`${turnSummary.turnId}:${file.path}`}
|
||||||
type="button"
|
type="button"
|
||||||
@@ -2817,9 +2963,7 @@ const MessagesTimeline = memo(function MessagesTimeline({
|
|||||||
additions: file.additions,
|
additions: file.additions,
|
||||||
deletions: file.deletions,
|
deletions: file.deletions,
|
||||||
}
|
}
|
||||||
: file.diff
|
: null;
|
||||||
? countDiffStat(file.diff)
|
|
||||||
: null;
|
|
||||||
if (!stat) {
|
if (!stat) {
|
||||||
return file.path;
|
return file.path;
|
||||||
}
|
}
|
||||||
@@ -2841,11 +2985,11 @@ const MessagesTimeline = memo(function MessagesTimeline({
|
|||||||
</button>
|
</button>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
) : !isCheckpointDiffLoading ? (
|
) : (
|
||||||
<p className="text-[11px] text-muted-foreground/70">
|
<p className="text-[11px] text-muted-foreground/70">
|
||||||
No changed files.
|
No changed files.
|
||||||
</p>
|
</p>
|
||||||
) : null}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})()}
|
})()}
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import {
|
|||||||
Virtualizer,
|
Virtualizer,
|
||||||
WorkerPoolContextProvider,
|
WorkerPoolContextProvider,
|
||||||
} from "@pierre/diffs/react";
|
} from "@pierre/diffs/react";
|
||||||
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { useParams } from "@tanstack/react-router";
|
import { useParams } from "@tanstack/react-router";
|
||||||
import { Columns2Icon, Rows3Icon } from "lucide-react";
|
import { Columns2Icon, Rows3Icon } from "lucide-react";
|
||||||
import { type ReactNode, useEffect, useMemo, useRef, useState } from "react";
|
import { type ReactNode, useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { checkpointDiffQueryOptions, providerQueryKeys } from "~/lib/providerReactQuery";
|
import { checkpointDiffQueryOptions } from "~/lib/providerReactQuery";
|
||||||
import { cn } from "~/lib/utils";
|
import { cn } from "~/lib/utils";
|
||||||
import { isElectron } from "../env";
|
import { isElectron } from "../env";
|
||||||
import { useNativeApi } from "../hooks/useNativeApi";
|
import { useNativeApi } from "../hooks/useNativeApi";
|
||||||
@@ -103,7 +103,6 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
|
|||||||
const api = useNativeApi();
|
const api = useNativeApi();
|
||||||
const { resolvedTheme } = useTheme();
|
const { resolvedTheme } = useTheme();
|
||||||
const { state, dispatch } = useStore();
|
const { state, dispatch } = useStore();
|
||||||
const queryClient = useQueryClient();
|
|
||||||
const [diffRenderMode, setDiffRenderMode] = useState<DiffRenderMode>("stacked");
|
const [diffRenderMode, setDiffRenderMode] = useState<DiffRenderMode>("stacked");
|
||||||
const patchViewportRef = useRef<HTMLDivElement>(null);
|
const patchViewportRef = useRef<HTMLDivElement>(null);
|
||||||
const params = useParams({ strict: false });
|
const params = useParams({ strict: false });
|
||||||
@@ -193,99 +192,7 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
|
|||||||
? "Failed to load checkpoint diff."
|
? "Failed to load checkpoint diff."
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
useEffect(() => {
|
const selectedPatch = selectedTurn ? selectedTurnCheckpointDiff : conversationCheckpointDiff;
|
||||||
if (!activeThread?.id || !selectedTurn || !selectedTurnCheckpointDiff) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
dispatch({
|
|
||||||
type: "SET_THREAD_TURN_CHECKPOINT_DIFFS",
|
|
||||||
threadId: activeThread.id,
|
|
||||||
checkpointDiffByTurnId: {
|
|
||||||
[selectedTurn.turnId]: selectedTurnCheckpointDiff,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}, [activeThread?.id, dispatch, selectedTurn, selectedTurnCheckpointDiff]);
|
|
||||||
|
|
||||||
const selectedPatch = useMemo(() => {
|
|
||||||
const patchForSummary = (summary: (typeof turnDiffSummaries)[number]): string | undefined => {
|
|
||||||
const checkpointTurnCount =
|
|
||||||
summary.checkpointTurnCount ?? inferredCheckpointTurnCountByTurnId[summary.turnId];
|
|
||||||
if (activeSessionId && typeof checkpointTurnCount === "number") {
|
|
||||||
const checkpointPatch = queryClient.getQueryData<{ diff: string }>(
|
|
||||||
providerQueryKeys.checkpointDiff({
|
|
||||||
sessionId: activeSessionId,
|
|
||||||
threadRuntimeId: activeThreadRuntimeId,
|
|
||||||
fromTurnCount: Math.max(0, checkpointTurnCount - 1),
|
|
||||||
toTurnCount: checkpointTurnCount,
|
|
||||||
cacheScope: `turn:${summary.turnId}`,
|
|
||||||
}),
|
|
||||||
)?.diff;
|
|
||||||
if (checkpointPatch) {
|
|
||||||
return checkpointPatch;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (summary.unifiedDiff) {
|
|
||||||
return summary.unifiedDiff;
|
|
||||||
}
|
|
||||||
const filePatches = summary.files
|
|
||||||
.map((file) => file.diff?.trim())
|
|
||||||
.filter((patch): patch is string => Boolean(patch));
|
|
||||||
if (filePatches.length === 0) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
return filePatches.join("\n\n");
|
|
||||||
};
|
|
||||||
|
|
||||||
if (selectedTurn) {
|
|
||||||
return selectedTurnCheckpointDiff ?? patchForSummary(selectedTurn);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (conversationCheckpointDiff) {
|
|
||||||
return conversationCheckpointDiff;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback when a conversation checkpoint diff isn't available yet:
|
|
||||||
// keep one patch per file path (latest change wins) so files aren't duplicated.
|
|
||||||
const latestPatchByPath = new Map<string, string>();
|
|
||||||
for (const summary of turnDiffSummaries) {
|
|
||||||
for (const file of summary.files) {
|
|
||||||
if (latestPatchByPath.has(file.path)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const patch = file.diff?.trim();
|
|
||||||
if (!patch) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
latestPatchByPath.set(file.path, patch);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (latestPatchByPath.size > 0) {
|
|
||||||
return Array.from(latestPatchByPath.entries())
|
|
||||||
.toSorted(([leftPath], [rightPath]) =>
|
|
||||||
leftPath.localeCompare(rightPath, undefined, { numeric: true, sensitivity: "base" }),
|
|
||||||
)
|
|
||||||
.map(([, patch]) => patch)
|
|
||||||
.join("\n\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
const patches = turnDiffSummaries
|
|
||||||
.toReversed()
|
|
||||||
.map((summary) => patchForSummary(summary)?.trim())
|
|
||||||
.filter((patch): patch is string => Boolean(patch));
|
|
||||||
if (patches.length === 0) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
return patches.join("\n\n");
|
|
||||||
}, [
|
|
||||||
activeSessionId,
|
|
||||||
activeThreadRuntimeId,
|
|
||||||
conversationCheckpointDiff,
|
|
||||||
inferredCheckpointTurnCountByTurnId,
|
|
||||||
queryClient,
|
|
||||||
selectedTurn,
|
|
||||||
selectedTurnCheckpointDiff,
|
|
||||||
turnDiffSummaries,
|
|
||||||
]);
|
|
||||||
const renderablePatch = useMemo(() => getRenderablePatch(selectedPatch), [selectedPatch]);
|
const renderablePatch = useMemo(() => getRenderablePatch(selectedPatch), [selectedPatch]);
|
||||||
const renderableFiles = useMemo(() => {
|
const renderableFiles = useMemo(() => {
|
||||||
if (!renderablePatch || renderablePatch.kind !== "files") {
|
if (!renderablePatch || renderablePatch.kind !== "files") {
|
||||||
|
|||||||
@@ -52,4 +52,60 @@ describe("checkpointDiffQueryOptions", () => {
|
|||||||
toTurnCount: 4,
|
toTurnCount: 4,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("retries checkpoint-not-ready errors longer than generic failures", () => {
|
||||||
|
const options = checkpointDiffQueryOptions(undefined, {
|
||||||
|
sessionId: "session-id",
|
||||||
|
threadRuntimeId: "thread-id",
|
||||||
|
fromTurnCount: 1,
|
||||||
|
toTurnCount: 2,
|
||||||
|
cacheScope: "turn:abc",
|
||||||
|
});
|
||||||
|
const retry = options.retry;
|
||||||
|
expect(typeof retry).toBe("function");
|
||||||
|
if (typeof retry !== "function") {
|
||||||
|
throw new Error("Expected retry to be a function.");
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(retry(1, new Error("Checkpoint turn count 2 exceeds current turn count 1."))).toBe(true);
|
||||||
|
expect(
|
||||||
|
retry(
|
||||||
|
11,
|
||||||
|
new Error("Filesystem checkpoint is unavailable for turn 2 in thread thread-1."),
|
||||||
|
),
|
||||||
|
).toBe(true);
|
||||||
|
expect(
|
||||||
|
retry(
|
||||||
|
12,
|
||||||
|
new Error("Filesystem checkpoint is unavailable for turn 2 in thread thread-1."),
|
||||||
|
),
|
||||||
|
).toBe(false);
|
||||||
|
expect(retry(2, new Error("Something else failed."))).toBe(true);
|
||||||
|
expect(retry(3, new Error("Something else failed."))).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("backs off longer for checkpoint-not-ready errors", () => {
|
||||||
|
const options = checkpointDiffQueryOptions(undefined, {
|
||||||
|
sessionId: "session-id",
|
||||||
|
threadRuntimeId: "thread-id",
|
||||||
|
fromTurnCount: 1,
|
||||||
|
toTurnCount: 2,
|
||||||
|
cacheScope: "turn:abc",
|
||||||
|
});
|
||||||
|
const retryDelay = options.retryDelay;
|
||||||
|
expect(typeof retryDelay).toBe("function");
|
||||||
|
if (typeof retryDelay !== "function") {
|
||||||
|
throw new Error("Expected retryDelay to be a function.");
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkpointDelay = retryDelay(
|
||||||
|
4,
|
||||||
|
new Error("Checkpoint turn count 2 exceeds current turn count 1."),
|
||||||
|
);
|
||||||
|
const genericDelay = retryDelay(4, new Error("Network failure"));
|
||||||
|
|
||||||
|
expect(typeof checkpointDelay).toBe("number");
|
||||||
|
expect(typeof genericDelay).toBe("number");
|
||||||
|
expect((checkpointDelay ?? 0) > (genericDelay ?? 0)).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -23,6 +23,25 @@ export const providerQueryKeys = {
|
|||||||
] as const,
|
] as const,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function asCheckpointErrorMessage(error: unknown): string {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return error.message;
|
||||||
|
}
|
||||||
|
if (typeof error === "string") {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
function isCheckpointTemporarilyUnavailable(error: unknown): boolean {
|
||||||
|
const message = asCheckpointErrorMessage(error).toLowerCase();
|
||||||
|
return (
|
||||||
|
message.includes("exceeds current turn count") ||
|
||||||
|
message.includes("checkpoint is unavailable for turn") ||
|
||||||
|
message.includes("filesystem checkpoint is unavailable")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function checkpointDiffQueryOptions(
|
export function checkpointDiffQueryOptions(
|
||||||
api: NativeApi | undefined,
|
api: NativeApi | undefined,
|
||||||
input: CheckpointDiffQueryInput,
|
input: CheckpointDiffQueryInput,
|
||||||
@@ -54,7 +73,15 @@ export function checkpointDiffQueryOptions(
|
|||||||
},
|
},
|
||||||
enabled: !!api && !!input.sessionId && hasValidRange,
|
enabled: !!api && !!input.sessionId && hasValidRange,
|
||||||
staleTime: Infinity,
|
staleTime: Infinity,
|
||||||
retry: 8,
|
retry: (failureCount, error) => {
|
||||||
retryDelay: (attempt) => Math.min(2_000, 150 * 2 ** (attempt - 1)),
|
if (isCheckpointTemporarilyUnavailable(error)) {
|
||||||
|
return failureCount < 12;
|
||||||
|
}
|
||||||
|
return failureCount < 3;
|
||||||
|
},
|
||||||
|
retryDelay: (attempt, error) =>
|
||||||
|
isCheckpointTemporarilyUnavailable(error)
|
||||||
|
? Math.min(5_000, 250 * 2 ** (attempt - 1))
|
||||||
|
: Math.min(1_000, 100 * 2 ** (attempt - 1)),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -263,7 +263,7 @@ describe("hydratePersistedState", () => {
|
|||||||
expect(hydrated?.threads[0]?.activeTerminalGroupId).toBe(`group-${DEFAULT_THREAD_TERMINAL_ID}`);
|
expect(hydrated?.threads[0]?.activeTerminalGroupId).toBe(`group-${DEFAULT_THREAD_TERMINAL_ID}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("hydrates persisted turn diff summaries and clears persisted loaded flags", () => {
|
it("hydrates persisted turn diff summaries as metadata-only entries", () => {
|
||||||
const payload = JSON.stringify({
|
const payload = JSON.stringify({
|
||||||
version: 7,
|
version: 7,
|
||||||
runtimeMode: "full-access",
|
runtimeMode: "full-access",
|
||||||
@@ -290,7 +290,6 @@ describe("hydratePersistedState", () => {
|
|||||||
turnId: "turn-1",
|
turnId: "turn-1",
|
||||||
completedAt: "2026-02-08T10:05:00.000Z",
|
completedAt: "2026-02-08T10:05:00.000Z",
|
||||||
checkpointTurnCount: 1,
|
checkpointTurnCount: 1,
|
||||||
checkpointDiffLoaded: true,
|
|
||||||
files: [
|
files: [
|
||||||
{
|
{
|
||||||
path: "src/app.ts",
|
path: "src/app.ts",
|
||||||
@@ -421,10 +420,8 @@ describe("toPersistedState", () => {
|
|||||||
kind: "modified",
|
kind: "modified",
|
||||||
additions: 3,
|
additions: 3,
|
||||||
deletions: 1,
|
deletions: 1,
|
||||||
diff: "diff --git a/src/app.ts b/src/app.ts",
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
unifiedDiff: "diff --git a/src/app.ts b/src/app.ts",
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -61,7 +61,6 @@ const persistedTurnDiffSummarySchema = z.object({
|
|||||||
files: z.array(persistedTurnDiffFileChangeSchema),
|
files: z.array(persistedTurnDiffFileChangeSchema),
|
||||||
assistantMessageId: z.string().min(1).optional(),
|
assistantMessageId: z.string().min(1).optional(),
|
||||||
checkpointTurnCount: z.number().int().min(0).optional(),
|
checkpointTurnCount: z.number().int().min(0).optional(),
|
||||||
checkpointDiffLoaded: z.boolean().optional(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const persistedThreadSchema = z.object({
|
const persistedThreadSchema = z.object({
|
||||||
|
|||||||
@@ -57,6 +57,17 @@ function EventRouter() {
|
|||||||
if (event.method === "turn/completed") {
|
if (event.method === "turn/completed") {
|
||||||
void invalidateGitQueries(queryClient);
|
void invalidateGitQueries(queryClient);
|
||||||
}
|
}
|
||||||
|
if (event.method === "checkpoint/captured") {
|
||||||
|
const payload = event.payload as { turnCount?: number } | undefined;
|
||||||
|
const turnCount = payload?.turnCount;
|
||||||
|
void queryClient.invalidateQueries({
|
||||||
|
queryKey: ["providers", "checkpointDiff"] as const,
|
||||||
|
predicate: (query) => {
|
||||||
|
if (typeof turnCount !== "number") return true;
|
||||||
|
return query.queryKey[5] === turnCount;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
if (!activeThreadId) return;
|
if (!activeThreadId) return;
|
||||||
dispatch({
|
dispatch({
|
||||||
type: "APPLY_EVENT",
|
type: "APPLY_EVENT",
|
||||||
@@ -67,6 +78,15 @@ function EventRouter() {
|
|||||||
});
|
});
|
||||||
}, [activeThreadId, api, dispatch, queryClient]);
|
}, [activeThreadId, api, dispatch, queryClient]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!activeThreadId) return;
|
||||||
|
dispatch({
|
||||||
|
type: "MARK_THREAD_VISITED",
|
||||||
|
threadId: activeThreadId,
|
||||||
|
visitedAt: new Date().toISOString(),
|
||||||
|
});
|
||||||
|
}, [activeThreadId, dispatch]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!api) return;
|
if (!api) return;
|
||||||
return api.terminal.onEvent((event) => {
|
return api.terminal.onEvent((event) => {
|
||||||
|
|||||||
@@ -493,11 +493,11 @@ describe("deriveTurnDiffSummaries", () => {
|
|||||||
expect(summaries).toHaveLength(1);
|
expect(summaries).toHaveLength(1);
|
||||||
expect(summaries[0]?.turnId).toBe("turn-1");
|
expect(summaries[0]?.turnId).toBe("turn-1");
|
||||||
expect(summaries[0]?.assistantMessageId).toBe("msg-1");
|
expect(summaries[0]?.assistantMessageId).toBe("msg-1");
|
||||||
expect(summaries[0]?.unifiedDiff).toContain("diff --git a/src/a.ts b/src/a.ts");
|
|
||||||
expect(summaries[0]?.files.map((file) => file.path)).toEqual(["src/a.ts", "src/b.ts"]);
|
expect(summaries[0]?.files.map((file) => file.path)).toEqual(["src/a.ts", "src/b.ts"]);
|
||||||
expect(summaries[0]?.files[0]?.kind).toBe("modified");
|
expect(summaries[0]?.files[0]?.kind).toBe("modified");
|
||||||
expect(summaries[0]?.files[0]?.additions).toBe(1);
|
expect(summaries[0]?.files[0]?.additions).toBe(1);
|
||||||
expect(summaries[0]?.files[0]?.deletions).toBe(1);
|
expect(summaries[0]?.files[0]?.deletions).toBe(1);
|
||||||
|
expect(summaries[0]).not.toHaveProperty("unifiedDiff");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("includes completed turns even when no fileChange tool events were emitted", () => {
|
it("includes completed turns even when no fileChange tool events were emitted", () => {
|
||||||
@@ -537,9 +537,10 @@ describe("deriveTurnDiffSummaries", () => {
|
|||||||
payload: {
|
payload: {
|
||||||
diff: [
|
diff: [
|
||||||
"diff --git a/src/example.ts b/src/example.ts",
|
"diff --git a/src/example.ts b/src/example.ts",
|
||||||
"@@ -1 +1 @@",
|
"@@ -1 +1,2 @@",
|
||||||
"-old",
|
"-old",
|
||||||
"+older",
|
"+older",
|
||||||
|
"+extra",
|
||||||
].join("\n"),
|
].join("\n"),
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@@ -572,8 +573,9 @@ describe("deriveTurnDiffSummaries", () => {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
expect(summaries).toHaveLength(1);
|
expect(summaries).toHaveLength(1);
|
||||||
expect(summaries[0]?.unifiedDiff).toContain("+newest");
|
expect(summaries[0]?.files[0]?.path).toBe("src/example.ts");
|
||||||
expect(summaries[0]?.unifiedDiff).not.toContain("+older");
|
expect(summaries[0]?.files[0]?.additions).toBe(1);
|
||||||
|
expect(summaries[0]?.files[0]?.deletions).toBe(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -593,8 +595,6 @@ describe("deriveTurnDiffFilesFromUnifiedDiff", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(files.map((file) => file.path)).toEqual(["src/a.ts", "src/b.ts"]);
|
expect(files.map((file) => file.path)).toEqual(["src/a.ts", "src/b.ts"]);
|
||||||
expect(files[0]?.diff).toContain("diff --git a/src/a.ts b/src/a.ts");
|
|
||||||
expect(files[1]?.diff).toContain("diff --git a/src/b.ts b/src/b.ts");
|
|
||||||
expect(files[0]?.additions).toBe(1);
|
expect(files[0]?.additions).toBe(1);
|
||||||
expect(files[0]?.deletions).toBe(1);
|
expect(files[0]?.deletions).toBe(1);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -453,7 +453,7 @@ interface MutableTurnDiffSummary {
|
|||||||
completedAt: string | undefined;
|
completedAt: string | undefined;
|
||||||
status: string | undefined;
|
status: string | undefined;
|
||||||
assistantMessageId: string | undefined;
|
assistantMessageId: string | undefined;
|
||||||
unifiedDiff: string | undefined;
|
hasTurnDiffUpdate: boolean;
|
||||||
filesByPath: Map<string, TurnDiffFileChange>;
|
filesByPath: Map<string, TurnDiffFileChange>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -485,7 +485,6 @@ function parseFileChangeEntriesFromEvent(event: ProviderEvent): TurnDiffFileChan
|
|||||||
parsed.push({
|
parsed.push({
|
||||||
path,
|
path,
|
||||||
...(kind ? { kind } : {}),
|
...(kind ? { kind } : {}),
|
||||||
...(diff ? { diff } : {}),
|
|
||||||
...(additions !== undefined ? { additions } : stat ? { additions: stat.additions } : {}),
|
...(additions !== undefined ? { additions } : stat ? { additions: stat.additions } : {}),
|
||||||
...(deletions !== undefined ? { deletions } : stat ? { deletions: stat.deletions } : {}),
|
...(deletions !== undefined ? { deletions } : stat ? { deletions: stat.deletions } : {}),
|
||||||
});
|
});
|
||||||
@@ -507,9 +506,6 @@ function mergeTurnDiffFileChange(
|
|||||||
if (existing.kind === undefined && incoming.kind !== undefined) {
|
if (existing.kind === undefined && incoming.kind !== undefined) {
|
||||||
existing.kind = incoming.kind;
|
existing.kind = incoming.kind;
|
||||||
}
|
}
|
||||||
if (existing.diff === undefined && incoming.diff !== undefined) {
|
|
||||||
existing.diff = incoming.diff;
|
|
||||||
}
|
|
||||||
if (existing.additions === undefined && incoming.additions !== undefined) {
|
if (existing.additions === undefined && incoming.additions !== undefined) {
|
||||||
existing.additions = incoming.additions;
|
existing.additions = incoming.additions;
|
||||||
}
|
}
|
||||||
@@ -565,7 +561,6 @@ export function deriveTurnDiffFilesFromUnifiedDiff(diff: string): TurnDiffFileCh
|
|||||||
const stat = countDiffStat(fileDiff);
|
const stat = countDiffStat(fileDiff);
|
||||||
return {
|
return {
|
||||||
path,
|
path,
|
||||||
diff: fileDiff,
|
|
||||||
additions: stat.additions,
|
additions: stat.additions,
|
||||||
deletions: stat.deletions,
|
deletions: stat.deletions,
|
||||||
};
|
};
|
||||||
@@ -645,7 +640,7 @@ export function deriveTurnDiffSummaries(events: ProviderEvent[]): TurnDiffSummar
|
|||||||
completedAt: undefined,
|
completedAt: undefined,
|
||||||
status: undefined,
|
status: undefined,
|
||||||
assistantMessageId: undefined,
|
assistantMessageId: undefined,
|
||||||
unifiedDiff: undefined,
|
hasTurnDiffUpdate: false,
|
||||||
filesByPath: new Map<string, TurnDiffFileChange>(),
|
filesByPath: new Map<string, TurnDiffFileChange>(),
|
||||||
};
|
};
|
||||||
byTurnId.set(turnId, next);
|
byTurnId.set(turnId, next);
|
||||||
@@ -677,10 +672,10 @@ export function deriveTurnDiffSummaries(events: ProviderEvent[]): TurnDiffSummar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.method === "turn/diff/updated" && summary.unifiedDiff === undefined) {
|
if (event.method === "turn/diff/updated" && !summary.hasTurnDiffUpdate) {
|
||||||
|
summary.hasTurnDiffUpdate = true;
|
||||||
const diff = normalizeDetail(asString(asObject(event.payload)?.diff));
|
const diff = normalizeDetail(asString(asObject(event.payload)?.diff));
|
||||||
if (diff) {
|
if (diff) {
|
||||||
summary.unifiedDiff = diff;
|
|
||||||
for (const file of deriveTurnDiffFilesFromUnifiedDiff(diff)) {
|
for (const file of deriveTurnDiffFilesFromUnifiedDiff(diff)) {
|
||||||
mergeTurnDiffFileChange(summary.filesByPath, file);
|
mergeTurnDiffFileChange(summary.filesByPath, file);
|
||||||
}
|
}
|
||||||
@@ -703,7 +698,6 @@ export function deriveTurnDiffSummaries(events: ProviderEvent[]): TurnDiffSummar
|
|||||||
files: Array.from(summary.filesByPath.values()).toSorted((a, b) =>
|
files: Array.from(summary.filesByPath.values()).toSorted((a, b) =>
|
||||||
a.path.localeCompare(b.path),
|
a.path.localeCompare(b.path),
|
||||||
),
|
),
|
||||||
...(summary.unifiedDiff ? { unifiedDiff: summary.unifiedDiff } : {}),
|
|
||||||
...(summary.assistantMessageId ? { assistantMessageId: summary.assistantMessageId } : {}),
|
...(summary.assistantMessageId ? { assistantMessageId: summary.assistantMessageId } : {}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+75
-24
@@ -815,6 +815,24 @@ describe("store reducer thread continuity", () => {
|
|||||||
expect(next.threads[0]?.lastVisitedAt).toBe(completedAt);
|
expect(next.threads[0]?.lastVisitedAt).toBe(completedAt);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("marks a thread as visited when selected", () => {
|
||||||
|
const state = makeState(
|
||||||
|
makeThread({
|
||||||
|
latestTurnCompletedAt: "2026-02-08T10:00:10.000Z",
|
||||||
|
lastVisitedAt: "2026-02-08T10:00:00.000Z",
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
const nextVisitedAt = "2026-02-08T10:00:20.000Z";
|
||||||
|
const next = reducer(state, {
|
||||||
|
type: "MARK_THREAD_VISITED",
|
||||||
|
threadId: "thread-local-1",
|
||||||
|
visitedAt: nextVisitedAt,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(next.threads[0]?.lastVisitedAt).toBe(nextVisitedAt);
|
||||||
|
});
|
||||||
|
|
||||||
it("reverts thread state to a checkpoint snapshot", () => {
|
it("reverts thread state to a checkpoint snapshot", () => {
|
||||||
const state = makeState(
|
const state = makeState(
|
||||||
makeThread({
|
makeThread({
|
||||||
@@ -893,7 +911,7 @@ describe("store reducer thread continuity", () => {
|
|||||||
expect(next.threads[0]?.turnDiffSummaries.map((summary) => summary.turnId)).toEqual(["turn_1"]);
|
expect(next.threads[0]?.turnDiffSummaries.map((summary) => summary.turnId)).toEqual(["turn_1"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("keeps checkpoint-derived turn files when later events for the same turn arrive", () => {
|
it("keeps existing turn file metadata when later events for the same turn arrive", () => {
|
||||||
const state = makeState(
|
const state = makeState(
|
||||||
makeThread({
|
makeThread({
|
||||||
turnDiffSummaries: [
|
turnDiffSummaries: [
|
||||||
@@ -903,11 +921,10 @@ describe("store reducer thread continuity", () => {
|
|||||||
files: [
|
files: [
|
||||||
{
|
{
|
||||||
path: "src/from-checkpoint.ts",
|
path: "src/from-checkpoint.ts",
|
||||||
diff: "diff --git a/src/from-checkpoint.ts b/src/from-checkpoint.ts",
|
additions: 1,
|
||||||
|
deletions: 1,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
unifiedDiff: "diff --git a/src/from-checkpoint.ts b/src/from-checkpoint.ts",
|
|
||||||
checkpointDiffLoaded: true,
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
@@ -927,11 +944,11 @@ describe("store reducer thread continuity", () => {
|
|||||||
expect(next.threads[0]?.turnDiffSummaries[0]?.files.map((file) => file.path)).toEqual([
|
expect(next.threads[0]?.turnDiffSummaries[0]?.files.map((file) => file.path)).toEqual([
|
||||||
"src/from-checkpoint.ts",
|
"src/from-checkpoint.ts",
|
||||||
]);
|
]);
|
||||||
expect(next.threads[0]?.turnDiffSummaries[0]?.checkpointDiffLoaded).toBe(true);
|
expect(next.threads[0]?.turnDiffSummaries[0]?.files[0]?.additions).toBe(1);
|
||||||
expect(next.threads[0]?.turnDiffSummaries[0]?.unifiedDiff).toContain("from-checkpoint.ts");
|
expect(next.threads[0]?.turnDiffSummaries[0]?.files[0]?.deletions).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("updates turn summaries from checkpoint diffs and marks them as loaded", () => {
|
it("updates checkpoint turn counts from authoritative checkpoint mappings", () => {
|
||||||
const state = makeState(
|
const state = makeState(
|
||||||
makeThread({
|
makeThread({
|
||||||
turnDiffSummaries: [
|
turnDiffSummaries: [
|
||||||
@@ -941,31 +958,65 @@ describe("store reducer thread continuity", () => {
|
|||||||
files: [],
|
files: [],
|
||||||
checkpointTurnCount: 1,
|
checkpointTurnCount: 1,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
turnId: "turn-2",
|
||||||
|
completedAt: "2026-02-09T00:00:04.000Z",
|
||||||
|
files: [],
|
||||||
|
checkpointTurnCount: 2,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
const next = reducer(state, {
|
const next = reducer(state, {
|
||||||
type: "SET_THREAD_TURN_CHECKPOINT_DIFFS",
|
type: "SET_THREAD_TURN_CHECKPOINT_COUNTS",
|
||||||
threadId: "thread-local-1",
|
threadId: "thread-local-1",
|
||||||
checkpointDiffByTurnId: {
|
checkpointTurnCountByTurnId: {
|
||||||
"turn-1": [
|
"turn-1": 2,
|
||||||
"diff --git a/src/a.ts b/src/a.ts",
|
"turn-2": 3,
|
||||||
"@@ -1 +1 @@",
|
|
||||||
"-old-a",
|
|
||||||
"+new-a",
|
|
||||||
"diff --git a/src/b.ts b/src/b.ts",
|
|
||||||
"@@ -1 +1 @@",
|
|
||||||
"-old-b",
|
|
||||||
"+new-b",
|
|
||||||
].join("\n"),
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(next.threads[0]?.turnDiffSummaries[0]?.files.map((file) => file.path)).toEqual([
|
expect(next.threads[0]?.turnDiffSummaries[0]?.checkpointTurnCount).toBe(2);
|
||||||
"src/a.ts",
|
expect(next.threads[0]?.turnDiffSummaries[1]?.checkpointTurnCount).toBe(3);
|
||||||
"src/b.ts",
|
});
|
||||||
]);
|
|
||||||
expect(next.threads[0]?.turnDiffSummaries[0]?.checkpointDiffLoaded).toBe(true);
|
it("does not rederive completed turn summaries from late turn diff events", () => {
|
||||||
|
const completed = reducer(makeState(makeThread()), {
|
||||||
|
type: "APPLY_EVENT",
|
||||||
|
event: makeEvent({
|
||||||
|
method: "turn/completed",
|
||||||
|
turnId: "turn-1",
|
||||||
|
createdAt: "2026-02-09T00:00:03.000Z",
|
||||||
|
payload: { turn: { id: "turn-1", status: "completed" } },
|
||||||
|
}),
|
||||||
|
activeAssistantItemRef: { current: null },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(completed.threads[0]?.turnDiffSummaries[0]?.files).toEqual([]);
|
||||||
|
|
||||||
|
const withLateDiff = reducer(completed, {
|
||||||
|
type: "APPLY_EVENT",
|
||||||
|
event: makeEvent({
|
||||||
|
method: "turn/diff/updated",
|
||||||
|
turnId: "turn-1",
|
||||||
|
createdAt: "2026-02-09T00:00:04.000Z",
|
||||||
|
payload: {
|
||||||
|
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",
|
||||||
|
"@@ -1 +1 @@",
|
||||||
|
"-old",
|
||||||
|
"+new",
|
||||||
|
].join("\n"),
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
activeAssistantItemRef: { current: null },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(withLateDiff.threads[0]?.turnDiffSummaries[0]?.files).toEqual([]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
+21
-75
@@ -15,7 +15,6 @@ import {
|
|||||||
applyEventToMessages,
|
applyEventToMessages,
|
||||||
asObject,
|
asObject,
|
||||||
asString,
|
asString,
|
||||||
deriveTurnDiffFilesFromUnifiedDiff,
|
|
||||||
deriveTurnDiffSummaries,
|
deriveTurnDiffSummaries,
|
||||||
inferCheckpointTurnCountByTurnId,
|
inferCheckpointTurnCountByTurnId,
|
||||||
evolveSession,
|
evolveSession,
|
||||||
@@ -94,17 +93,13 @@ type Action =
|
|||||||
threadId: string;
|
threadId: string;
|
||||||
checkpointTurnCountByTurnId: Record<string, number>;
|
checkpointTurnCountByTurnId: Record<string, number>;
|
||||||
}
|
}
|
||||||
| {
|
|
||||||
type: "SET_THREAD_TURN_CHECKPOINT_DIFFS";
|
|
||||||
threadId: string;
|
|
||||||
checkpointDiffByTurnId: Record<string, string>;
|
|
||||||
}
|
|
||||||
| {
|
| {
|
||||||
type: "SET_THREAD_BRANCH";
|
type: "SET_THREAD_BRANCH";
|
||||||
threadId: string;
|
threadId: string;
|
||||||
branch: string | null;
|
branch: string | null;
|
||||||
worktreePath: string | null;
|
worktreePath: string | null;
|
||||||
}
|
}
|
||||||
|
| { type: "MARK_THREAD_VISITED"; threadId: string; visitedAt?: string }
|
||||||
| { type: "SET_RUNTIME_MODE"; mode: RuntimeMode }
|
| { type: "SET_RUNTIME_MODE"; mode: RuntimeMode }
|
||||||
| { type: "DELETE_THREAD"; threadId: string };
|
| { type: "DELETE_THREAD"; threadId: string };
|
||||||
|
|
||||||
@@ -235,21 +230,12 @@ function mergeTurnDiffSummaries(
|
|||||||
return summary;
|
return summary;
|
||||||
}
|
}
|
||||||
|
|
||||||
const prefersCheckpointDiff = previous.checkpointDiffLoaded || summary.checkpointDiffLoaded;
|
|
||||||
const files =
|
const files =
|
||||||
prefersCheckpointDiff ||
|
summary.files.length === 0 && previous.files.length > 0 ? previous.files : summary.files;
|
||||||
(summary.files.length === 0 && previous.files.length > 0 && summary.unifiedDiff === undefined)
|
|
||||||
? previous.files
|
|
||||||
: summary.files;
|
|
||||||
const unifiedDiff =
|
|
||||||
prefersCheckpointDiff || summary.unifiedDiff === undefined
|
|
||||||
? (previous.unifiedDiff ?? summary.unifiedDiff)
|
|
||||||
: summary.unifiedDiff;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...summary,
|
...summary,
|
||||||
files,
|
files,
|
||||||
...(unifiedDiff !== undefined ? { unifiedDiff } : {}),
|
|
||||||
...(summary.assistantMessageId
|
...(summary.assistantMessageId
|
||||||
? {}
|
? {}
|
||||||
: previous.assistantMessageId
|
: previous.assistantMessageId
|
||||||
@@ -260,9 +246,6 @@ function mergeTurnDiffSummaries(
|
|||||||
: typeof previous.checkpointTurnCount === "number"
|
: typeof previous.checkpointTurnCount === "number"
|
||||||
? { checkpointTurnCount: previous.checkpointTurnCount }
|
? { checkpointTurnCount: previous.checkpointTurnCount }
|
||||||
: {}),
|
: {}),
|
||||||
...(summary.checkpointDiffLoaded || previous.checkpointDiffLoaded
|
|
||||||
? { checkpointDiffLoaded: true }
|
|
||||||
: {}),
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -908,13 +891,18 @@ export function reducer(state: AppState, action: Action): AppState {
|
|||||||
...state,
|
...state,
|
||||||
threads: updateThread(state.threads, target.id, (t) => {
|
threads: updateThread(state.threads, target.id, (t) => {
|
||||||
const nextEvents = [event, ...t.events];
|
const nextEvents = [event, ...t.events];
|
||||||
|
const eventTurnId = getEventTurnId(event);
|
||||||
|
const hasCompletedSummaryForTurn = Boolean(
|
||||||
|
eventTurnId && t.turnDiffSummaries.some((summary) => summary.turnId === eventTurnId),
|
||||||
|
);
|
||||||
const itemType = asString(asObject(asObject(event.payload)?.item)?.type);
|
const itemType = asString(asObject(asObject(event.payload)?.item)?.type);
|
||||||
const normalizedItemType = itemType?.replace(/[_-]/g, "").toLowerCase();
|
const normalizedItemType = itemType?.replace(/[_-]/g, "").toLowerCase();
|
||||||
|
const isMetadataItemCompleted =
|
||||||
|
event.method === "item/completed" &&
|
||||||
|
(normalizedItemType === "agentmessage" || normalizedItemType === "filechange");
|
||||||
const shouldRederiveDiffs =
|
const shouldRederiveDiffs =
|
||||||
event.method === "turn/completed" ||
|
event.method === "turn/completed" ||
|
||||||
event.method === "turn/diff/updated" ||
|
(hasCompletedSummaryForTurn && isMetadataItemCompleted);
|
||||||
(event.method === "item/completed" &&
|
|
||||||
(normalizedItemType === "agentmessage" || normalizedItemType === "filechange"));
|
|
||||||
const turnDiffSummaries = shouldRederiveDiffs
|
const turnDiffSummaries = shouldRederiveDiffs
|
||||||
? mergeTurnDiffSummaries(t.turnDiffSummaries, deriveTurnDiffSummaries(nextEvents))
|
? mergeTurnDiffSummaries(t.turnDiffSummaries, deriveTurnDiffSummaries(nextEvents))
|
||||||
: t.turnDiffSummaries;
|
: t.turnDiffSummaries;
|
||||||
@@ -1070,59 +1058,6 @@ export function reducer(state: AppState, action: Action): AppState {
|
|||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
case "SET_THREAD_TURN_CHECKPOINT_DIFFS":
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
threads: updateThread(state.threads, action.threadId, (t) => {
|
|
||||||
let hasUpdates = false;
|
|
||||||
const updatedSummaries = t.turnDiffSummaries.map((summary) => {
|
|
||||||
const checkpointDiff = action.checkpointDiffByTurnId[summary.turnId];
|
|
||||||
if (checkpointDiff === undefined) {
|
|
||||||
return summary;
|
|
||||||
}
|
|
||||||
|
|
||||||
const files = deriveTurnDiffFilesFromUnifiedDiff(checkpointDiff);
|
|
||||||
const filesUnchanged =
|
|
||||||
files.length === summary.files.length &&
|
|
||||||
files.every((file, index) => {
|
|
||||||
const existing = summary.files[index];
|
|
||||||
return (
|
|
||||||
existing !== undefined &&
|
|
||||||
existing.path === file.path &&
|
|
||||||
existing.diff === file.diff &&
|
|
||||||
existing.kind === file.kind &&
|
|
||||||
existing.additions === file.additions &&
|
|
||||||
existing.deletions === file.deletions
|
|
||||||
);
|
|
||||||
});
|
|
||||||
if (
|
|
||||||
summary.unifiedDiff === checkpointDiff &&
|
|
||||||
filesUnchanged &&
|
|
||||||
summary.checkpointDiffLoaded
|
|
||||||
) {
|
|
||||||
return summary;
|
|
||||||
}
|
|
||||||
|
|
||||||
hasUpdates = true;
|
|
||||||
return {
|
|
||||||
...summary,
|
|
||||||
unifiedDiff: checkpointDiff,
|
|
||||||
files,
|
|
||||||
checkpointDiffLoaded: true,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!hasUpdates) {
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
...t,
|
|
||||||
turnDiffSummaries: updatedSummaries,
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
|
|
||||||
case "SET_THREAD_BRANCH": {
|
case "SET_THREAD_BRANCH": {
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
@@ -1141,6 +1076,17 @@ export function reducer(state: AppState, action: Action): AppState {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case "MARK_THREAD_VISITED": {
|
||||||
|
const visitedAt = action.visitedAt ?? new Date().toISOString();
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
threads: updateThread(state.threads, action.threadId, (t) => ({
|
||||||
|
...t,
|
||||||
|
lastVisitedAt: visitedAt,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
case "SET_RUNTIME_MODE":
|
case "SET_RUNTIME_MODE":
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ export interface ChatMessage {
|
|||||||
export interface TurnDiffFileChange {
|
export interface TurnDiffFileChange {
|
||||||
path: string;
|
path: string;
|
||||||
kind?: string | undefined;
|
kind?: string | undefined;
|
||||||
diff?: string | undefined;
|
|
||||||
additions?: number | undefined;
|
additions?: number | undefined;
|
||||||
deletions?: number | undefined;
|
deletions?: number | undefined;
|
||||||
}
|
}
|
||||||
@@ -50,10 +49,8 @@ export interface TurnDiffSummary {
|
|||||||
completedAt: string;
|
completedAt: string;
|
||||||
status?: string | undefined;
|
status?: string | undefined;
|
||||||
files: TurnDiffFileChange[];
|
files: TurnDiffFileChange[];
|
||||||
unifiedDiff?: string | undefined;
|
|
||||||
assistantMessageId?: string | undefined;
|
assistantMessageId?: string | undefined;
|
||||||
checkpointTurnCount?: number | undefined;
|
checkpointTurnCount?: number | undefined;
|
||||||
checkpointDiffLoaded?: boolean | undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Project {
|
export interface Project {
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
import tailwindcss from "@tailwindcss/vite";
|
|
||||||
import react from "@vitejs/plugin-react";
|
|
||||||
import { tanstackRouter } from "@tanstack/router-plugin/vite";
|
|
||||||
import { defineConfig } from "vite";
|
|
||||||
const port = Number(process.env.PORT ?? 5173);
|
|
||||||
export default defineConfig({
|
|
||||||
plugins: [
|
|
||||||
tanstackRouter(),
|
|
||||||
react({
|
|
||||||
babel: {
|
|
||||||
plugins: [["babel-plugin-react-compiler", { target: "19" }]],
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
tailwindcss(),
|
|
||||||
],
|
|
||||||
define: {
|
|
||||||
// In dev mode, tell the web app where the WebSocket server lives
|
|
||||||
"import.meta.env.VITE_WS_URL": JSON.stringify(process.env.VITE_WS_URL ?? ""),
|
|
||||||
},
|
|
||||||
experimental: {
|
|
||||||
enableNativePlugin: true,
|
|
||||||
},
|
|
||||||
resolve: {
|
|
||||||
tsconfigPaths: true,
|
|
||||||
},
|
|
||||||
server: {
|
|
||||||
port,
|
|
||||||
strictPort: true,
|
|
||||||
hmr: {
|
|
||||||
// Explicit config so Vite's HMR WebSocket connects reliably
|
|
||||||
// inside Electron's BrowserWindow. Vite 8 uses console.debug for
|
|
||||||
// connection logs — enable "Verbose" in DevTools to see them.
|
|
||||||
protocol: "ws",
|
|
||||||
host: "localhost",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
build: {
|
|
||||||
outDir: "dist",
|
|
||||||
emptyOutDir: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
@@ -15,6 +15,9 @@ export default defineConfig({
|
|||||||
}),
|
}),
|
||||||
tailwindcss(),
|
tailwindcss(),
|
||||||
],
|
],
|
||||||
|
optimizeDeps: {
|
||||||
|
include: ["@pierre/diffs", "@pierre/diffs/react", "@pierre/diffs/worker/worker.js"],
|
||||||
|
},
|
||||||
define: {
|
define: {
|
||||||
// In dev mode, tell the web app where the WebSocket server lives
|
// In dev mode, tell the web app where the WebSocket server lives
|
||||||
"import.meta.env.VITE_WS_URL": JSON.stringify(process.env.VITE_WS_URL ?? ""),
|
"import.meta.env.VITE_WS_URL": JSON.stringify(process.env.VITE_WS_URL ?? ""),
|
||||||
|
|||||||
Reference in new issue
Block a user