Skip to content

Commit c9f4626

Browse files
chore: tighten the shared view-state docs
1 parent a81e24e commit c9f4626

4 files changed

Lines changed: 8 additions & 31 deletions

File tree

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,7 @@ export const viewStateSchema = z.object({
121121
mode: z.string().optional(),
122122
currentApiConfigName: z.string().optional(),
123123
updatedAt: z.number().optional(),
124-
/**
125-
* Host-minted capability token binding this entry to the webview that wrote it; never
126-
* accepted from webview input and only a matching token re-adopts the entry.
127-
*/
124+
/** Host-minted token binding this entry to the webview that wrote it. */
128125
claimToken: z.string().optional(),
129126
})
130127

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -679,10 +679,7 @@ export interface WebviewMessage {
679679
| "themeFixtureProbeResponse"
680680
text?: string
681681
viewStateId?: string
682-
/**
683-
* For `webviewDidLaunch`: the host-minted claim previously delivered for `viewStateId`.
684-
* Enforced by `ClineProvider.setViewStateId`; launch forwarding ships in the wiring unit.
685-
*/
682+
/** For `webviewDidLaunch`: the claim delivered for `viewStateId`, enforced by setViewStateId. */
686683
viewStateClaim?: string
687684
taskId?: string
688685
editedMessageContent?: string

‎src/core/webview/ClineProvider.ts‎

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,7 @@ export class ClineProvider
376376
*/
377377
public readonly viewId: string
378378

379-
/**
380-
* Stable identifier for persisted per-view state keys; binds a durable entry to the
381-
* webview that wrote it through the host-minted claim token.
382-
*/
379+
/** Stable id for persisted per-view state keys, bound by the host-minted claim. */
383380
private viewStateId: string
384381

385382
/**
@@ -597,10 +594,7 @@ export class ClineProvider
597594
return Object.assign(Object.create(null), viewStates)
598595
}
599596

600-
/**
601-
* Persist the non-secret selections through the serialized write queue, re-keying a
602-
* pre-launch write to the stable id once the webview registers one.
603-
*/
597+
/** Persist the non-secret selections through the serialized write queue. */
604598
private async savePersistedViewState(values: Partial<PersistedViewState>): Promise<void> {
605599
// Capture the id at change time: a write belongs to the view that was active
606600
// when the change was made, even if a newer id is registered while it is queued.
@@ -686,10 +680,7 @@ export class ClineProvider
686680
await write
687681
}
688682

689-
/**
690-
* Re-bind a claim-less viewStates entry with a freshly minted claim; its unowned
691-
* selections are dropped so the new token cannot re-expose them.
692-
*/
683+
/** Re-bind a claim-less entry with a fresh claim; unowned selections are dropped. */
693684
private async rebindUnboundViewStateEntry(viewStateId: string): Promise<string | undefined> {
694685
const claimToken = crypto.randomUUID()
695686
let rebound = false
@@ -781,10 +772,7 @@ export class ClineProvider
781772
await write
782773
}
783774

784-
/**
785-
* Register the stable view id and load its persisted selections. An entry that carries a
786-
* claim is loaded only when the presented host-minted token matches it.
787-
*/
775+
/** Register the stable view id and load its persisted selections; a claim must match. */
788776
public async setViewStateId(viewStateId: string | undefined, presentedClaim?: string): Promise<void> {
789777
// The webview generates this id on purpose - it has to survive a webview reload,
790778
// which recreates the view on both sides - so the host cannot mint it instead.
@@ -892,8 +880,7 @@ export class ClineProvider
892880
this.postViewStateClaimToWebview(this.viewStateId, adoptedClaim)
893881
}
894882

895-
// Registration is only complete once the view's own persisted selections are in the
896-
// buffer; nothing else loads them now that reset/import handling lives downstream.
883+
// Registration is what loads this view's own persisted selections.
897884
await this.loadViewState()
898885
} catch (error) {
899886
// A persistence failure must not leave the provider holding an id that was

‎src/core/webview/__tests__/ClineProvider.spec.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3124,8 +3124,6 @@ describe("ClineProvider", () => {
31243124
}
31253125

31263126
// Spy on log method to verify warning was logged
3127-
const logSpy = vi.spyOn(provider, "log")
3128-
31293127
// Create history item with non-existent mode
31303128
const historyItem = {
31313129
id: "test-id",
@@ -3616,10 +3614,8 @@ describe("ClineProvider", () => {
36163614

36173615
await provider["setViewStateId"]("stable-view", "host-token")
36183616

3619-
// Registration is what loads a view's own selections: the buffer is populated and
3620-
// the load is logged, so a reload restores the pinned mode instead of the shared one.
3617+
// Registration is what loads a view's own selections.
36213618
expect(provider["viewLocalState"].mode).toBe("architect")
3622-
expect(logSpy).toHaveBeenCalledWith(expect.stringContaining("Loaded state for viewId"))
36233619

36243620
await provider.dispose()
36253621
})

0 commit comments

Comments
 (0)