Skip to content

Commit 1b9e8f8

Browse files
chore: tighten the view-identity comments
1 parent 60c5400 commit 1b9e8f8

4 files changed

Lines changed: 16 additions & 65 deletions

File tree

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,8 @@ export const viewStateSchema = z.object({
122122
currentApiConfigName: z.string().optional(),
123123
updatedAt: z.number().optional(),
124124
/**
125-
* Host-minted capability token binding this entry to the webview that wrote it.
126-
* Minted by the extension host (`crypto.randomUUID()`), delivered to that webview and
127-
* never accepted from webview input. An entry is only re-adopted for a webview that
128-
* presents this token, so a view cannot read another (e.g. closed) view's selections.
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.
129127
*/
130128
claimToken: z.string().optional(),
131129
})

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -681,10 +681,7 @@ export interface WebviewMessage {
681681
viewStateId?: string
682682
/**
683683
* For `webviewDidLaunch`: the host-minted claim previously delivered for `viewStateId`.
684-
* The webview only echoes what it was given; the host enforces the match in
685-
* `ClineProvider.setViewStateId` when a view registers this id, so a view cannot adopt
686-
* another view's persisted selections. Forwarding these fields from the launch handler
687-
* is wired by the follow-up launch unit.
684+
* Enforced by `ClineProvider.setViewStateId`; launch forwarding ships in the wiring unit.
688685
*/
689686
viewStateClaim?: string
690687
taskId?: string

‎src/core/config/ProviderSettingsManager.ts‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,7 @@ export const providerProfilesSchema = z.object({
5555

5656
export type ProviderProfiles = z.infer<typeof providerProfilesSchema>
5757

58-
/**
59-
* Signals that a profile's configuration no longer exists. Callers that treat an
60-
* already-deleted profile as an idempotent no-op branch on this type instead of
61-
* matching error message text, which a profile name containing the phrase could
62-
* otherwise spoof.
63-
*/
58+
/** Already-deleted profile: callers branch on this type instead of matching message text. */
6459
export class ProviderSettingsNotFoundError extends Error {
6560
constructor(message: string) {
6661
super(message)

‎src/core/webview/ClineProvider.ts‎

Lines changed: 12 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -377,12 +377,8 @@ export class ClineProvider
377377
public readonly viewId: string
378378

379379
/**
380-
* Stable identifier for persisted per-view state keys.
381-
* Defaults to viewId until the webview reports its VS Code-persisted id.
382-
* A durable entry under this id is bound to the webview that wrote it by a host-minted
383-
* claim token (see setViewStateId), so the entry - and the profile its pin brings back
384-
* into the state post - can outlive this instance without becoming adoptable by any
385-
* other webview.
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.
386382
*/
387383
private viewStateId: string
388384

@@ -602,13 +598,8 @@ export class ClineProvider
602598
}
603599

604600
/**
605-
* Persists this view's non-secret selections through the serialized write queue.
606-
* The write re-reads the map fresh and merges into the existing entry, removing the
607-
* entry entirely when nothing persistable remains, so concurrent views cannot clobber it.
608-
* The entry is keyed by the view id active when the change was made. Writes captured
609-
* while the provider still holds its temporary (pre-launch) id persist under that id
610-
* and are re-keyed to the stable view id when the webview registers one, so a change
611-
* that lands before the launch message stays durable instead of being lost.
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.
612603
*/
613604
private async savePersistedViewState(values: Partial<PersistedViewState>): Promise<void> {
614605
// Capture the id at change time: a write belongs to the view that was active
@@ -696,11 +687,8 @@ export class ClineProvider
696687
}
697688

698689
/**
699-
* Re-binds a claim-less viewStates entry to this webview with a freshly minted claim.
700-
* Entries written before claims existed cannot be attributed to any webview, so their
701-
* selections are dropped instead of being carried over: keeping them would let the new
702-
* token re-expose them on a later launch, which is exactly the disclosure this binding
703-
* exists to prevent. Runs through the serialized write queue like every other mutation.
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.
704692
*/
705693
private async rebindUnboundViewStateEntry(viewStateId: string): Promise<string | undefined> {
706694
const claimToken = crypto.randomUUID()
@@ -746,18 +734,7 @@ export class ClineProvider
746734
)
747735
}
748736

749-
/**
750-
* Re-keys this provider's temporary pre-launch viewStates entry to the newly
751-
* registered stable id so pre-launch writes become durable under the stable key
752-
* instead of orphaning under a session-local temporary id. Only the provider's own
753-
* temporary id is eligible: an entry under a previously registered stable id belongs
754-
* to that webview's storage and is left alone. When the stable entry already exists
755-
* it wins and the temporary entry is dropped, because temporary ids are session
756-
* counters that can collide across window reloads. Runs through the serialized write
757-
* queue like every other viewStates mutation. An entry this instance never wrote is
758-
* left alone, so a stale entry that happens to carry the same session-local name is
759-
* not adopted.
760-
*/
737+
/** Re-key this instance's authored pre-launch entry to the stable id. */
761738
private async rekeyPersistedViewStateEntry(nextViewStateId: string): Promise<void> {
762739
const previousViewStateId = this.viewId
763740

@@ -805,14 +782,8 @@ export class ClineProvider
805782
}
806783

807784
/**
808-
* Registers this provider's stable view identifier and loads any persisted selections it owns.
809-
* The identifier is sanitized so it remains a safe object key in the shared viewStates map.
810-
*
811-
* `presentedClaim` is the host-minted token this webview was given for that id. It is the
812-
* only proof of ownership: an entry that carries a claim is loaded only when the presented
813-
* token matches it, so a webview cannot adopt another (e.g. disposed, still durable) view's
814-
* id and read that view's pinned profile - and the profile secrets copied into the state
815-
* post - back out of it. The check runs before any re-keying or loading.
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.
816787
*/
817788
public async setViewStateId(viewStateId: string | undefined, presentedClaim?: string): Promise<void> {
818789
// The webview generates this id on purpose - it has to survive a webview reload,
@@ -5239,12 +5210,7 @@ export class ClineProvider
52395210
void this.loadViewState()
52405211
}
52415212

5242-
/**
5243-
* Loads non-secret persisted selections from the registered viewStates map.
5244-
* Missing entries are intentionally left unset so getState() falls back to shared ContextProxy values.
5245-
* Fields mutated while the async profile lookup is in flight are reapplied on top of the
5246-
* loaded state, field by field, so in-flight user selections are not clobbered by the load.
5247-
*/
5213+
/** Load non-secret persisted selections; in-flight buffer edits are reapplied on top. */
52485214
private async loadViewState(): Promise<void> {
52495215
// Capture the id this load is for: a newer id registered while an async
52505216
// profile lookup is in flight must not be overwritten by this stale load.
@@ -5298,13 +5264,8 @@ export class ClineProvider
52985264
return
52995265
}
53005266

5301-
// Reapply the buffer fields that changed while the load was in flight,
5302-
// tracking the change instead of testing against undefined: a field cleared
5303-
// during the load window must stay cleared (the loaded value must not
5304-
// resurrect it), and a field written to a new value must win over it.
5305-
// Untouched fields keep the persisted values authoritative, and the
5306-
// pre-load buffer is never merged wholesale so stale temporary-id state
5307-
// cannot override the stable persisted state.
5267+
// Diff each field so in-flight edits win over the loaded values (including clears)
5268+
// while untouched fields keep the persisted values authoritative.
53085269
const postLoadBuffer = this.viewLocalState
53095270
const mergedState: Partial<ExtensionState> = { ...loadedState }
53105271

0 commit comments

Comments
 (0)