Skip to content

Commit 4ef3675

Browse files
committed
feat(checkpoint): separate upstream merge changes in turn reviews
1 parent a892771 commit 4ef3675

26 files changed

Lines changed: 726 additions & 41 deletions

‎apps/mobile/src/features/review/ReviewSheet.tsx‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,9 @@ export function ReviewSheet(props: ReviewSheetProps) {
477477
selectSection,
478478
isSelectedSectionPending,
479479
diffPreviewRevision,
480+
gitFileCount,
481+
includeGitChanges,
482+
toggleGitChanges,
480483
} = useReviewSections({
481484
enabled: isEnvironmentReady,
482485
environmentId,
@@ -736,6 +739,19 @@ export function ReviewSheet(props: ReviewSheetProps) {
736739

737740
<MaterialScreenContent>
738741
<View className="flex-1 bg-sheet android:bg-sheet-solid">
742+
{gitFileCount > 0 && (
743+
<View className="flex-row flex-wrap items-center gap-2 border-b border-border px-4 py-2">
744+
<Text className="text-xs text-muted-foreground">
745+
{gitFileCount} {gitFileCount === 1 ? "file" : "files"} updated via Git{" "}
746+
{includeGitChanges ? "shown" : "hidden"}.
747+
</Text>
748+
<Pressable accessibilityRole="button" onPress={toggleGitChanges}>
749+
<Text className="text-sm text-primary">
750+
{includeGitChanges ? "Hide Git changes" : "Show Git changes"}
751+
</Text>
752+
</Pressable>
753+
</View>
754+
)}
739755
{showConnectionNotice ? (
740756
<View className="flex-1" style={{ paddingTop: topContentInset }}>
741757
<EnvironmentConnectionNotice

‎apps/mobile/src/features/review/reviewModel.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { parsePatchFiles } from "@pierre/diffs/utils/parsePatchFiles";
22
import type { ChangeTypes, FileDiffMetadata } from "@pierre/diffs/types";
3-
import type { ThreadCheckpointSummary } from "@t3tools/client-runtime/state/thread-checkpoints";
3+
import {
4+
partitionCheckpointFiles,
5+
type ThreadCheckpointSummary,
6+
} from "@t3tools/client-runtime/state/thread-checkpoints";
47
import type { ReviewDiffPreviewSource } from "@t3tools/contracts";
58
import { unquoteGitPatchPath } from "@t3tools/shared/gitPatchPath";
69
import * as Arr from "effect/Array";
@@ -104,7 +107,10 @@ function checkpointSubtitle(checkpoint: ThreadCheckpointSummary): string {
104107
if (checkpoint.status !== "ready") {
105108
return `Diff ${checkpoint.status}`;
106109
}
107-
return `${fileCount} file${fileCount === 1 ? "" : "s"} changed`;
110+
const groups = partitionCheckpointFiles(checkpoint.files);
111+
return groups.gitFiles.length > 0
112+
? `${groups.workspaceFiles.length} changed file${groups.workspaceFiles.length === 1 ? "" : "s"} · ${groups.gitFiles.length} updated via Git`
113+
: `${fileCount} file${fileCount === 1 ? "" : "s"} changed`;
108114
}
109115

110116
function compareCheckpointTurnCountDescending(

‎apps/mobile/src/features/review/useReviewSections.ts‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useEffect, useMemo } from "react";
1+
import { useCallback, useEffect, useMemo, useState } from "react";
22
import * as DateTime from "effect/DateTime";
33

44
import {
@@ -130,13 +130,19 @@ export function useReviewSections(input: {
130130
const activeSectionId = activeCheckpoint
131131
? getReviewSectionIdForCheckpoint(activeCheckpoint)
132132
: null;
133+
const gitScopeKey = `${environmentId}:${threadId}:${activeSectionId}`;
134+
const [gitVisibility, setGitVisibility] = useState<{ scope: string; visible: boolean } | null>(
135+
null,
136+
);
137+
const includeGitChanges = gitVisibility?.scope === gitScopeKey && gitVisibility.visible;
133138
const activeTurnDiff = useCheckpointDiff({
134139
environmentId: enabled ? (environmentId ?? null) : null,
135140
threadId: enabled ? (threadId ?? null) : null,
136141
fromTurnCount:
137142
enabled && activeCheckpoint ? Math.max(0, activeCheckpoint.checkpointTurnCount - 1) : null,
138143
toTurnCount: enabled ? (activeCheckpoint?.checkpointTurnCount ?? null) : null,
139144
ignoreWhitespace: false,
145+
includeGitChanges,
140146
});
141147

142148
useEffect(() => {
@@ -150,9 +156,12 @@ export function useReviewSections(input: {
150156
if (!reviewCache.threadKey || !activeSectionId || !activeTurnDiff.data) {
151157
return;
152158
}
153-
setReviewTurnDiff(reviewCache.threadKey, activeSectionId, activeTurnDiff.data.diff);
159+
// This section cache holds only the default view. Full patches stay in the query's keyed cache.
160+
if (!includeGitChanges) {
161+
setReviewTurnDiff(reviewCache.threadKey, activeSectionId, activeTurnDiff.data.diff);
162+
}
154163
setReviewAsyncError(reviewCache.threadKey, null);
155-
}, [activeSectionId, activeTurnDiff.data, reviewCache.threadKey]);
164+
}, [activeSectionId, activeTurnDiff.data, includeGitChanges, reviewCache.threadKey]);
156165

157166
useEffect(() => {
158167
if (reviewCache.threadKey && activeTurnDiff.error) {
@@ -181,6 +190,9 @@ export function useReviewSections(input: {
181190
);
182191

183192
return {
193+
gitFileCount: selectedSection?.kind === "turn" ? (activeTurnDiff.data?.gitFileCount ?? 0) : 0,
194+
includeGitChanges,
195+
toggleGitChanges: () => setGitVisibility({ scope: gitScopeKey, visible: !includeGitChanges }),
184196
error: diffPreview.error ?? activeTurnDiff.error ?? reviewCache.asyncState.error,
185197
isSelectedSectionPending:
186198
selectedSection?.kind === "turn" ? activeTurnDiff.isPending : diffPreview.isPending,
@@ -190,7 +202,14 @@ export function useReviewSections(input: {
190202
: undefined,
191203
loadingTurnIds,
192204
reviewSections,
193-
selectedSection,
205+
selectedSection:
206+
selectedSection?.kind === "turn"
207+
? {
208+
...selectedSection,
209+
diff: activeTurnDiff.data?.diff ?? (includeGitChanges ? null : selectedSection.diff),
210+
isLoading: activeTurnDiff.isPending,
211+
}
212+
: selectedSection,
194213
refreshSelectedSection,
195214
selectSection,
196215
};

‎apps/mobile/src/lib/threadActivity.test.ts‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ describe("buildThreadFeed", () => {
224224
expect(buildThreadFeed([projected(reply, 0)])[0]?.type).toBe("message");
225225
});
226226

227-
it("does not create a work group for a message and checkpoint", () => {
227+
it("does not create a work group for a message and empty checkpoint", () => {
228228
const checkpoint: OrchestrationV2TurnItem = {
229229
...base("checkpoint", "2026-06-20T00:00:04.000Z", 3),
230230
type: "checkpoint",
@@ -236,6 +236,37 @@ describe("buildThreadFeed", () => {
236236
expect(feed.map((entry) => entry.type)).toEqual(["message"]);
237237
});
238238

239+
it("keeps workspace and Git counts visible in the completed turn feed", () => {
240+
const checkpoint: OrchestrationV2TurnItem = {
241+
...base("checkpoint", "2026-06-20T00:00:04.000Z", 3),
242+
type: "checkpoint",
243+
checkpointId: CheckpointId.make("checkpoint"),
244+
scopeId: CheckpointScopeId.make("scope"),
245+
files: [
246+
{ path: "welcome.txt", kind: "modified", additions: 1, deletions: 1 },
247+
{ path: "upstream.txt", kind: "added", additions: 2, deletions: 0, origin: "git" },
248+
],
249+
};
250+
const feed = deriveThreadFeedPresentation(
251+
buildThreadFeed([projected(assistantMessage(), 0), projected(checkpoint, 1)]),
252+
{
253+
runId,
254+
status: "completed",
255+
startedAt: null,
256+
completedAt: DateTime.formatIso(checkpoint.updatedAt),
257+
},
258+
new Set(),
259+
);
260+
const activities = feed.flatMap((entry) =>
261+
entry.type === "activity-group" ? entry.activities : [],
262+
);
263+
expect(activities).toMatchObject([{ detail: "1 changed file · 1 updated via Git" }]);
264+
expect(activities.map((activity) => workEntryRowLabel(activity.workEntry))).toEqual([
265+
"1 changed file · 1 updated via Git",
266+
]);
267+
expect(activities[0]?.getFullDetail()).toBe("welcome.txt\nupstream.txt (updated via Git)");
268+
});
269+
239270
it("omits cached tool output and patch bodies from expanded and copied activity", () => {
240271
const rawOutput = "RAW_TOOL_OUTPUT";
241272
const items: OrchestrationV2TurnItem[] = [

‎apps/mobile/src/lib/threadActivity.ts‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { partitionCheckpointFiles } from "@t3tools/client-runtime/state/thread-checkpoints";
12
import type {
23
ThreadPendingApproval,
34
ThreadPendingUserInput,
@@ -405,7 +406,12 @@ function itemIsToolLike(item: OrchestrationV2TurnItem): boolean {
405406
}
406407

407408
function itemIsProminent(item: OrchestrationV2TurnItem): boolean {
408-
return item.type === "fork" || item.type === "thread_created" || item.type === "system_notice";
409+
return (
410+
item.type === "fork" ||
411+
item.type === "thread_created" ||
412+
item.type === "system_notice" ||
413+
item.type === "checkpoint"
414+
);
409415
}
410416

411417
function itemStatus(item: OrchestrationV2TurnItem): ThreadFeedActivity["status"] {
@@ -616,10 +622,14 @@ function itemPreview(item: OrchestrationV2TurnItem): string | null {
616622
return item.prompt ?? null;
617623
case "user_input_request":
618624
return item.questions.map((question) => question.question).join(" · ") || null;
619-
case "checkpoint":
625+
case "checkpoint": {
626+
const groups = partitionCheckpointFiles(item.files);
627+
if (groups.gitFiles.length > 0)
628+
return `${groups.workspaceFiles.length} changed file${groups.workspaceFiles.length === 1 ? "" : "s"} · ${groups.gitFiles.length} updated via Git`;
620629
return item.files.length === 1
621630
? (item.files[0]?.path ?? null)
622631
: `${item.files.length} changed files`;
632+
}
623633
case "run_interrupt_request":
624634
case "run_interrupt_result":
625635
case "system_notice":
@@ -702,7 +712,7 @@ function toWorkLogEntry(
702712
toolData: item,
703713
};
704714
case "checkpoint":
705-
return { ...common, changedFiles: item.files.map((file) => file.path), toolData: item };
715+
return { ...common, ...(detail ? { detail } : {}), toolData: item };
706716
case "approval_request":
707717
return {
708718
...common,
@@ -736,6 +746,11 @@ function toFeedActivity(
736746
? collectToolFilePaths(item)
737747
: null;
738748
const getFullDetail = memoizeValue(() => {
749+
if (item.type === "checkpoint") {
750+
return item.files
751+
.map((file) => `${file.path}${file.origin === "git" ? " (updated via Git)" : ""}`)
752+
.join("\n");
753+
}
739754
if (readPaths) {
740755
return readPaths.join("\n") || null;
741756
}
@@ -1663,7 +1678,8 @@ export function buildThreadFeed(
16631678
for (const row of visibleTurnItems) {
16641679
const item = row.item;
16651680
if (turnItemIsWorkspacePreparation(item)) continue;
1666-
if (item.type === "todo_list" || item.type === "checkpoint") continue;
1681+
if (item.type === "todo_list" || (item.type === "checkpoint" && item.files.length === 0))
1682+
continue;
16671683
if (item.type === "user_message" && foldedAnswerMessageIds.has(item.messageId)) continue;
16681684
// Match the web timeline: only the terminal interrupt result is useful to
16691685
// users; the preceding request is transient bookkeeping.

‎apps/mobile/src/state/queries.ts‎

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -331,15 +331,25 @@ export function useComposerPathSearch(target: ComposerPathSearchTarget) {
331331
}
332332

333333
export function useCheckpointDiff(target: CheckpointDiffTarget) {
334+
const {
335+
environmentId,
336+
fromTurnCount,
337+
ignoreWhitespace,
338+
includeGitChanges,
339+
threadId,
340+
toTurnCount,
341+
} = target;
334342
const targets = useMemo(
335-
() => buildCheckpointDiffTargets(target),
336-
[
337-
target.environmentId,
338-
target.fromTurnCount,
339-
target.ignoreWhitespace,
340-
target.threadId,
341-
target.toTurnCount,
342-
],
343+
() =>
344+
buildCheckpointDiffTargets({
345+
environmentId,
346+
fromTurnCount,
347+
ignoreWhitespace,
348+
includeGitChanges,
349+
threadId,
350+
toTurnCount,
351+
}),
352+
[environmentId, fromTurnCount, ignoreWhitespace, includeGitChanges, threadId, toTurnCount],
343353
);
344354
const fullThread = useEnvironmentQuery(
345355
targets.fullThread === null

‎apps/mobile/src/state/queryTargets.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface CheckpointDiffTarget {
66
readonly fromTurnCount: number | null;
77
readonly toTurnCount: number | null;
88
readonly ignoreWhitespace: boolean;
9+
readonly includeGitChanges?: boolean;
910
}
1011

1112
export function normalizeComposerPathSearchQuery(query: string | null): string {
@@ -30,6 +31,9 @@ export function buildCheckpointDiffTargets(target: CheckpointDiffTarget) {
3031
threadId: target.threadId,
3132
toTurnCount: target.toTurnCount,
3233
ignoreWhitespace: target.ignoreWhitespace,
34+
...(target.includeGitChanges === undefined
35+
? {}
36+
: { includeGitChanges: target.includeGitChanges }),
3337
},
3438
},
3539
turn: null,
@@ -45,6 +49,9 @@ export function buildCheckpointDiffTargets(target: CheckpointDiffTarget) {
4549
fromTurnCount: target.fromTurnCount,
4650
toTurnCount: target.toTurnCount,
4751
ignoreWhitespace: target.ignoreWhitespace,
52+
...(target.includeGitChanges === undefined
53+
? {}
54+
: { includeGitChanges: target.includeGitChanges }),
4855
},
4956
},
5057
} as const;

‎apps/server/src/checkpointing/CheckpointDiffQuery.ts‎

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
type CheckpointServiceError,
3131
} from "./Errors.ts";
3232
import * as CheckpointStore from "./CheckpointStore.ts";
33+
import { parseTurnDiffFilesFromNumstat } from "./Diffs.ts";
3334

3435
/** Service tag for checkpoint diff queries. */
3536
export class CheckpointDiffQuery extends Context.Service<
@@ -181,17 +182,48 @@ export const make = Effect.gen(function* () {
181182
});
182183
}
183184

185+
const comparison = {
186+
cwd: toScope.cwd,
187+
fromCheckpointRef,
188+
toCheckpointRef: toCheckpoint.ref,
189+
fallbackFromToHead: false,
190+
ignoreWhitespace,
191+
};
192+
const gitPaths =
193+
input.includeGitChanges === undefined
194+
? []
195+
: yield* checkpointStore
196+
.getGitChangedPaths(comparison)
197+
.pipe(Effect.catch(() => Effect.succeed([])));
198+
const files =
199+
gitPaths.length === 0
200+
? []
201+
: parseTurnDiffFilesFromNumstat(
202+
yield* checkpointStore.diffCheckpoints({ ...comparison, format: "numstat" }),
203+
);
204+
const imported = new Set(gitPaths);
205+
const gitFileCount = files.filter((file) => imported.has(file.path)).length;
206+
const filePaths =
207+
input.includeGitChanges === false && gitPaths.length > 0
208+
? files
209+
.filter((file) => !imported.has(file.path))
210+
.flatMap((file) =>
211+
file.previousPath === undefined ? [file.path] : [file.previousPath, file.path],
212+
)
213+
: undefined;
214+
// Select retained paths before generating a patch, so imported bulk cannot exhaust its output limit.
184215
const diff = yield* checkpointStore
185216
.diffCheckpoints({
186-
cwd: toScope.cwd,
187-
fromCheckpointRef,
188-
toCheckpointRef: toCheckpoint.ref,
189-
fallbackFromToHead: false,
190-
ignoreWhitespace,
217+
...comparison,
218+
...(filePaths ? { filePaths } : {}),
191219
})
192220
.pipe(Effect.withSpan("checkpoint.turnDiff.diffCheckpoints"));
193221

194-
const turnDiff = buildTurnDiffResult(input, diff);
222+
// Older clients keep the complete diff. Updated clients explicitly choose the grouped view.
223+
const turnDiff = {
224+
...buildTurnDiffResult(input, diff),
225+
...(gitFileCount > 0 ? { gitFileCount } : {}),
226+
};
195227
if (!isTurnDiffResult(turnDiff)) {
196228
return yield* new CheckpointDiffResultInvalidError({
197229
operation,
@@ -239,6 +271,9 @@ export const make = Effect.gen(function* () {
239271
fromTurnCount: 0,
240272
toTurnCount: input.toTurnCount,
241273
ignoreWhitespace,
274+
...(input.includeGitChanges === undefined
275+
? {}
276+
: { includeGitChanges: input.includeGitChanges }),
242277
});
243278
if (!isTurnDiffResult(turnDiff)) {
244279
return yield* new CheckpointDiffResultInvalidError({

0 commit comments

Comments
 (0)