Skip to content

Commit 82f5b0f

Browse files
committed
feat(checkpoints): per-step change cards and changeCardDetail setting (B3a, #1375)
1 parent 088ef85 commit 82f5b0f

36 files changed

Lines changed: 881 additions & 53 deletions

‎packages/types/src/global-settings.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from "./provider-settings.js"
1313
import { telemetrySettingsSchema } from "./telemetry.js"
1414
import { toolNamesSchema } from "./tool.js"
15+
import { changeCardDetailSchema, type ChangeCardDetail } from "./message.js"
1516
import { type Keys } from "./type-fu.js"
1617
import { languagesSchema } from "./vscode.js"
1718

@@ -106,6 +107,14 @@ export const DEFAULT_CHECKPOINT_TIMEOUT_SECONDS = 15
106107
*/
107108
export const DEFAULT_PER_WRITE_CHECKPOINTS = true
108109

110+
/**
111+
* Default detail level for per-step change cards (B3a).
112+
* "summary" keeps cards compact (file list with +/− counts; the UI fetches
113+
* diffs lazily); "full" carries the unified diff inline per file.
114+
* @default "summary"
115+
*/
116+
export const DEFAULT_CHANGE_CARD_DETAIL: ChangeCardDetail = "summary"
117+
109118
/**
110119
* GlobalSettings
111120
*/
@@ -213,6 +222,13 @@ export const globalSettingsSchema = z.object({
213222
* @default true
214223
*/
215224
perWriteCheckpoints: z.boolean().optional(),
225+
/**
226+
* Detail level for per-step change cards: "full" includes the unified diff
227+
* inline for every changed file, "summary" carries only the file list with
228+
* +/− counts (diffs are fetched lazily by the UI).
229+
* @default "summary"
230+
*/
231+
changeCardDetail: changeCardDetailSchema.optional(),
216232

217233
ttsEnabled: z.boolean().optional(),
218234
ttsSpeed: z.number().optional(),

‎packages/types/src/message.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export function isNonBlockingAsk(ask: ClineAsk): ask is NonBlockingAsk {
134134
* - `mcp_server_response`: Response received from MCP server
135135
* - `subtask_result`: Result of a completed subtask
136136
* - `checkpoint_saved`: Indicates a checkpoint has been saved
137+
* - `change_card`: Per-step change card summarizing the files a completed tool step wrote (B3a)
137138
* - `rooignore_error`: Error related to .rooignore file processing
138139
* - `diff_error`: Error occurred while applying a diff/patch
139140
* - `condense_context`: Context condensation/summarization has started
@@ -162,6 +163,7 @@ export const clineSays = [
162163
"mcp_server_response",
163164
"subtask_result",
164165
"checkpoint_saved",
166+
"change_card",
165167
"rooignore_error",
166168
"diff_error",
167169
"condense_context",
@@ -235,6 +237,49 @@ export const contextTruncationSchema = z.object({
235237

236238
export type ContextTruncation = z.infer<typeof contextTruncationSchema>
237239

240+
/**
241+
* ChangeCard
242+
*
243+
* Payload of the per-step change card (B3a). The extension host emits one
244+
* `say: "change_card"` message per completed tool write step, keyed by the
245+
* shadow-git checkpoint the step produced. The JSON payload (see
246+
* {@link ChangeCardData}) is carried in the message `text` field, the same
247+
* way tool approval messages carry their serialized ClineSayTool.
248+
*
249+
* `detail: "full"` carries the unified diff inline for every file so the UI
250+
* can render it directly; `detail: "summary"` carries only the file list with
251+
* +/− counts and the UI fetches diffs lazily (B3b). Auto-approved steps are
252+
* always emitted with `detail: "summary"` regardless of the user setting.
253+
*/
254+
export const changeCardDetailSchema = z.enum(["full", "summary"])
255+
256+
export type ChangeCardDetail = z.infer<typeof changeCardDetailSchema>
257+
258+
export const changeCardFileSchema = z.object({
259+
path: z.string(),
260+
additions: z.number(),
261+
deletions: z.number(),
262+
/**
263+
* Unified diff for this file. Only present when the card was emitted with
264+
* `detail: "full"`; summary cards leave it out to stay compact.
265+
*/
266+
diff: z.string().optional(),
267+
})
268+
269+
export type ChangeCardFile = z.infer<typeof changeCardFileSchema>
270+
271+
export const changeCardSchema = z.object({
272+
/** Opaque step identifier, reserved for future tool-step tracking. */
273+
stepId: z.string().optional(),
274+
/** Checkpoint commit SHAs produced by the step (one per per-write checkpoint). */
275+
checkpointIds: z.array(z.string()),
276+
files: z.array(changeCardFileSchema),
277+
totalFiles: z.number(),
278+
detail: changeCardDetailSchema,
279+
})
280+
281+
export type ChangeCardData = z.infer<typeof changeCardSchema>
282+
238283
/**
239284
* ClineMessage
240285
*

‎packages/types/src/vscode-extension-host.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { ProviderSettings, ProviderSettingsEntry } from "./provider-setting
55
import type { HistoryItem } from "./history.js"
66
import type { ModeConfig, PromptComponent } from "./mode.js"
77
import type { Experiments } from "./experiment.js"
8-
import type { ClineMessage, QueuedMessage } from "./message.js"
8+
import type { ChangeCardDetail, ClineMessage, QueuedMessage } from "./message.js"
99
import type { MarketplaceItem, MarketplaceInstalledMetadata, InstallMarketplaceItemOptions } from "./marketplace.js"
1010
import type { TodoItem } from "./todo.js"
1111
import type { CloudUserInfo, CloudOrganizationMembership, OrganizationAllowList, ShareVisibility } from "./cloud.js"
@@ -349,6 +349,7 @@ export type ExtensionState = Pick<
349349
enableCheckpoints: boolean
350350
checkpointTimeout: number // Timeout for checkpoint initialization in seconds (default: 15)
351351
perWriteCheckpoints: boolean
352+
changeCardDetail: ChangeCardDetail
352353
maxOpenTabsContext: number // Maximum number of VSCode open tabs to include in context (0-500)
353354
maxWorkspaceFiles: number // Maximum number of files to include in current working directory details (0-500)
354355
showRooIgnoredFiles: boolean // Whether to show .rooignore'd files in listings
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import { describe, expect, it } from "vitest"
2+
3+
import {
4+
buildChangeCard,
5+
buildChangeCardPayload,
6+
isAutoApprovedStep,
7+
resolveChangeCardDetail,
8+
type ChangeCardWrite,
9+
} from "../changeCard"
10+
11+
describe("changeCard (B3a)", () => {
12+
function write(overrides: Partial<ChangeCardWrite> = {}): ChangeCardWrite {
13+
return {
14+
path: "src/a.ts",
15+
diffStats: { additions: 2, deletions: 1 },
16+
diff: "--- a/src/a.ts\n+++ b/src/a.ts\n@@ -1 +1,2 @@\n-old\n+new-1\n+new-2",
17+
...overrides,
18+
}
19+
}
20+
21+
describe("isAutoApprovedStep", () => {
22+
it("returns false for an empty step", () => {
23+
expect(isAutoApprovedStep([])).toBe(false)
24+
})
25+
26+
it("returns true only when every write was auto-approved", () => {
27+
expect(isAutoApprovedStep([write({ autoApproved: true }), write({ autoApproved: true })])).toBe(true)
28+
expect(isAutoApprovedStep([write({ autoApproved: true }), write()])).toBe(false)
29+
expect(isAutoApprovedStep([write()])).toBe(false)
30+
})
31+
})
32+
33+
describe("resolveChangeCardDetail", () => {
34+
it("forces summary for auto-approved steps even when the setting is full", () => {
35+
const writes = [write({ autoApproved: true })]
36+
expect(resolveChangeCardDetail(writes, "full")).toBe("summary")
37+
expect(resolveChangeCardDetail(writes, undefined)).toBe("summary")
38+
})
39+
40+
it("follows the setting for interactive steps, defaulting to summary when unset", () => {
41+
const writes = [write()]
42+
expect(resolveChangeCardDetail(writes, "full")).toBe("full")
43+
expect(resolveChangeCardDetail(writes, "summary")).toBe("summary")
44+
expect(resolveChangeCardDetail(writes, undefined)).toBe("summary")
45+
})
46+
})
47+
48+
describe("buildChangeCard", () => {
49+
it("carries the inline diff per file for full detail on a multi-file step", () => {
50+
const card = buildChangeCard(
51+
"sha-1",
52+
[write(), write({ path: "src/b.ts", diffStats: { additions: 1, deletions: 0 }, diff: "+b" })],
53+
"full",
54+
)
55+
56+
expect(card).toEqual({
57+
checkpointIds: ["sha-1"],
58+
files: [
59+
{
60+
path: "src/a.ts",
61+
additions: 2,
62+
deletions: 1,
63+
diff: "--- a/src/a.ts\n+++ b/src/a.ts\n@@ -1 +1,2 @@\n-old\n+new-1\n+new-2",
64+
},
65+
{ path: "src/b.ts", additions: 1, deletions: 0, diff: "+b" },
66+
],
67+
totalFiles: 2,
68+
detail: "full",
69+
})
70+
})
71+
72+
it("omits the diff per file for summary detail (lazy fetch is B3b)", () => {
73+
const card = buildChangeCard("sha-1", [write()], "summary")
74+
75+
expect(card.files).toEqual([{ path: "src/a.ts", additions: 2, deletions: 1 }])
76+
expect(card.files[0]).not.toHaveProperty("diff")
77+
expect(card.detail).toBe("summary")
78+
expect(card.totalFiles).toBe(1)
79+
})
80+
81+
it("defaults missing diffStats to zero counts and keeps full detail without diff for a write without one", () => {
82+
const card = buildChangeCard("sha-1", [write({ diffStats: undefined, diff: undefined })], "full")
83+
84+
expect(card.files[0]).toEqual({ path: "src/a.ts", additions: 0, deletions: 0 })
85+
})
86+
})
87+
88+
describe("buildChangeCardPayload", () => {
89+
it("resolves the detail level and builds the payload in one call", () => {
90+
// Interactive step with the full setting: diff inline.
91+
const full = buildChangeCardPayload("sha-1", [write()], "full")
92+
expect(full.detail).toBe("full")
93+
expect(full.files[0].diff).toBe("--- a/src/a.ts\n+++ b/src/a.ts\n@@ -1 +1,2 @@\n-old\n+new-1\n+new-2")
94+
95+
// Auto-approved step with the full setting: compact summary, no diff.
96+
const compact = buildChangeCardPayload("sha-1", [write({ autoApproved: true })], "full")
97+
expect(compact.detail).toBe("summary")
98+
expect(compact.files[0]).not.toHaveProperty("diff")
99+
expect(compact.checkpointIds).toEqual(["sha-1"])
100+
expect(compact.totalFiles).toBe(1)
101+
})
102+
})
103+
})

0 commit comments

Comments
 (0)