From e67ab35cdd9c154d5bda7b21d35d08a76f7390af Mon Sep 17 00:00:00 2001 From: easonLiangWorldedtech <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Thu, 29 Oct 2026 03:00:17 +0800 Subject: [PATCH 01/27] feat(webview): durable per-view viewStates pipeline (N2) Split unit N2 of #1546: viewStates read/write queue, claim rekey, prune, clear, load/save and export/import sanitization on top of N1 identity. Buffer/mutation/history content remains for N3. --- .husky/pre-commit | 26 - .husky/pre-push | 42 -- .../src/__tests__/global-settings.test.ts | 43 ++ packages/types/src/__tests__/index.test.ts | 5 + packages/types/src/global-settings.ts | 17 + packages/types/src/vscode-extension-host.ts | 15 + src/core/config/ContextProxy.ts | 3 + src/core/config/ProviderSettingsManager.ts | 20 +- .../config/__tests__/ContextProxy.spec.ts | 16 + .../__tests__/ProviderSettingsManager.spec.ts | 7 +- .../config/__tests__/importExport.spec.ts | 45 ++ src/core/config/importExport.ts | 8 + src/core/webview/ClineProvider.ts | 651 +++++++++++++++++- .../webview/__tests__/ClineProvider.spec.ts | 50 ++ 14 files changed, 861 insertions(+), 87 deletions(-) delete mode 100644 .husky/pre-commit delete mode 100644 .husky/pre-push diff --git a/.husky/pre-commit b/.husky/pre-commit deleted file mode 100644 index f8f420dac7..0000000000 --- a/.husky/pre-commit +++ /dev/null @@ -1,26 +0,0 @@ -branch="$(git rev-parse --abbrev-ref HEAD)" - -if [ "$branch" = "main" ]; then - echo "You can't commit directly to main - please check out a branch." - exit 1 -fi - -# Detect if running on Windows and use pnpm.cmd, otherwise use pnpm. -if [ "$OS" = "Windows_NT" ]; then - pnpm_cmd="pnpm.cmd" -else - if command -v pnpm >/dev/null 2>&1; then - pnpm_cmd="pnpm" - else - pnpm_cmd="npx pnpm" - fi -fi - -# Detect if running on Windows and use npx.cmd, otherwise use npx. -if [ "$OS" = "Windows_NT" ]; then - npx_cmd="npx.cmd" -else - npx_cmd="npx" -fi - -$npx_cmd lint-staged diff --git a/.husky/pre-push b/.husky/pre-push deleted file mode 100644 index 4cf91d9580..0000000000 --- a/.husky/pre-push +++ /dev/null @@ -1,42 +0,0 @@ -branch="$(git rev-parse --abbrev-ref HEAD)" - -if [ "$branch" = "main" ]; then - echo "You can't push directly to main - please check out a branch." - exit 1 -fi - -# Detect if running on Windows and use pnpm.cmd, otherwise use pnpm. -if [ "$OS" = "Windows_NT" ]; then - pnpm_cmd="pnpm.cmd" -else - if command -v pnpm >/dev/null 2>&1; then - pnpm_cmd="pnpm" - else - pnpm_cmd="npx pnpm" - fi -fi - -$pnpm_cmd run check-types - -# Use dotenvx to securely load .env.local and run commands that depend on it -if [ -f ".env.local" ]; then - # Check if RUN_TESTS_ON_PUSH is set to true and run tests with dotenvx - if npx dotenvx get RUN_TESTS_ON_PUSH -f .env.local 2>/dev/null | grep -q "^true$"; then - npx dotenvx run -f .env.local -- $pnpm_cmd run test - fi -else - # Fallback: run tests if RUN_TESTS_ON_PUSH is set in regular environment - if [ "$RUN_TESTS_ON_PUSH" = "true" ]; then - $pnpm_cmd run test - fi -fi - -# Check for new changesets. -NEW_CHANGESETS=$(find .changeset -name "*.md" ! -name "README.md" | wc -l | tr -d ' ') -echo "Changeset files: $NEW_CHANGESETS" - -if [ "$NEW_CHANGESETS" = "0" ]; then - echo "-------------------------------------------------------------------------------------" - echo "Changes detected. Please run 'pnpm changeset' to create a changeset if applicable." - echo "-------------------------------------------------------------------------------------" -fi diff --git a/packages/types/src/__tests__/global-settings.test.ts b/packages/types/src/__tests__/global-settings.test.ts index f2b2e7e8e5..b6b01cccf0 100644 --- a/packages/types/src/__tests__/global-settings.test.ts +++ b/packages/types/src/__tests__/global-settings.test.ts @@ -39,6 +39,49 @@ describe("alwaysDenyUnapprovedCommands global setting", () => { }) }) +describe("viewStates global setting", () => { + it("parses a valid per-view record", () => { + const parsed = globalSettingsSchema.parse({ + viewStates: { + "stable-view-1": { mode: "code", currentApiConfigName: "profile-a", updatedAt: 1730000000000 }, + "stable-view-2": {}, + }, + }) + expect(parsed.viewStates?.["stable-view-1"]).toEqual({ + mode: "code", + currentApiConfigName: "profile-a", + updatedAt: 1730000000000, + }) + expect(parsed.viewStates?.["stable-view-2"]).toEqual({}) + expect(GLOBAL_SETTINGS_KEYS).toContain("viewStates") + }) + + it("parses an entry that carries the host-minted claim token", () => { + // The claim binds the entry to the webview that wrote it; a legacy entry without one + // still parses, because refusing it is setViewStateId's job, not the schema's. + const parsed = globalSettingsSchema.parse({ + viewStates: { + "stable-view-1": { mode: "code", updatedAt: 1730000000000, claimToken: "7f9c-host-minted" }, + "stable-view-2": { mode: "code" }, + }, + }) + expect(parsed.viewStates?.["stable-view-1"]?.claimToken).toBe("7f9c-host-minted") + expect(parsed.viewStates?.["stable-view-2"]).toEqual({ mode: "code" }) + }) + + it("rejects invalid field values inside a view entry", () => { + expect(() => globalSettingsSchema.parse({ viewStates: { v: { mode: 42 } } })).toThrow() + expect(() => globalSettingsSchema.parse({ viewStates: { v: { currentApiConfigName: 42 } } })).toThrow() + expect(() => globalSettingsSchema.parse({ viewStates: { v: { updatedAt: "soon" } } })).toThrow() + expect(() => globalSettingsSchema.parse({ viewStates: { v: { claimToken: 42 } } })).toThrow() + }) + + it("rejects non-object viewStates values", () => { + expect(() => globalSettingsSchema.parse({ viewStates: "not-a-record" })).toThrow() + expect(() => globalSettingsSchema.parse({ viewStates: { v: "not-an-entry" } })).toThrow() + }) +}) + describe("collapseCommandOutputByDefault global setting", () => { it.each([true, false, undefined])("round-trips %s through the export/import schema", (value) => { const settings = globalSettingsSchema.parse({ collapseCommandOutputByDefault: value }) diff --git a/packages/types/src/__tests__/index.test.ts b/packages/types/src/__tests__/index.test.ts index 15441d48fd..b4cee22f8c 100644 --- a/packages/types/src/__tests__/index.test.ts +++ b/packages/types/src/__tests__/index.test.ts @@ -3,6 +3,10 @@ import { GLOBAL_STATE_KEYS } from "../index.js" describe("GLOBAL_STATE_KEYS", () => { + it("should contain registered durable per-view state", () => { + expect(GLOBAL_STATE_KEYS).toContain("viewStates") + }) + it("should contain provider settings keys", () => { expect(GLOBAL_STATE_KEYS).toContain("autoApprovalEnabled") }) @@ -13,6 +17,7 @@ describe("GLOBAL_STATE_KEYS", () => { it("should not contain secret state keys", () => { expect(GLOBAL_STATE_KEYS).not.toContain("openRouterApiKey") + expect(GLOBAL_STATE_KEYS).not.toContain("apiKey") }) it("should contain OpenAI Compatible base URL setting", () => { diff --git a/packages/types/src/global-settings.ts b/packages/types/src/global-settings.ts index eb51c1d67d..b09bae2635 100644 --- a/packages/types/src/global-settings.ts +++ b/packages/types/src/global-settings.ts @@ -114,6 +114,22 @@ export const MAX_CHECKPOINT_TIMEOUT_SECONDS = 60 */ export const DEFAULT_CHECKPOINT_TIMEOUT_SECONDS = 15 +/** + * Persisted non-secret selections for a stable webview instance. + */ +export const viewStateSchema = z.object({ + mode: z.string().optional(), + currentApiConfigName: z.string().optional(), + updatedAt: z.number().optional(), + /** + * Host-minted capability token binding this entry to the webview that wrote it. + * Minted by the extension host (`crypto.randomUUID()`), delivered to that webview and + * never accepted from webview input. An entry is only re-adopted for a webview that + * presents this token, so a view cannot read another (e.g. closed) view's selections. + */ + claimToken: z.string().optional(), +}) + /** * GlobalSettings */ @@ -122,6 +138,7 @@ export const globalSettingsSchema = z.object({ currentApiConfigName: z.string().optional(), listApiConfigMeta: z.array(providerSettingsEntrySchema).optional(), pinnedApiConfigs: z.record(z.string(), z.boolean()).optional(), + viewStates: z.record(z.string(), viewStateSchema).optional(), lastShownAnnouncementId: z.string().optional(), customInstructions: z.string().optional(), diff --git a/packages/types/src/vscode-extension-host.ts b/packages/types/src/vscode-extension-host.ts index a5393ddc66..bc6e6c6279 100644 --- a/packages/types/src/vscode-extension-host.ts +++ b/packages/types/src/vscode-extension-host.ts @@ -111,6 +111,7 @@ export interface ExtensionMessage { | "originalContent" | "rooHistoryImportProgress" | "themeFixtureProbeRequest" + | "viewStateClaim" text?: string /** For fileContent: { path, content, error? } */ fileContent?: { path: string; content: string | null; error?: string } @@ -169,6 +170,13 @@ export interface ExtensionMessage { // eslint-disable-next-line @typescript-eslint/no-explicit-any values?: Record requestId?: string + /** + * For `viewStateClaim`: the durable `viewStates` key the delivered claim governs. The + * message is only ever sent to the webview that key belongs to. + */ + viewStateId?: string + /** For `viewStateClaim`: the host-minted token the webview stores and echoes on launch. */ + viewStateClaim?: string themeFixture?: WebviewThemeFixture promptText?: string results?: @@ -669,6 +677,13 @@ export interface WebviewMessage { | "openRulesDirectory" | "themeFixtureProbeResponse" text?: string + viewStateId?: string + /** + * For `webviewDidLaunch`: the host-minted claim previously delivered for `viewStateId`. + * The webview only echoes what it was given; the host rejects an id whose stored claim + * does not match, so a view cannot adopt another view's persisted selections. + */ + viewStateClaim?: string taskId?: string editedMessageContent?: string tab?: "settings" | "history" | "mcp" | "modes" | "chat" | "marketplace" | "cloud" diff --git a/src/core/config/ContextProxy.ts b/src/core/config/ContextProxy.ts index 1250a7baca..4e20305f48 100644 --- a/src/core/config/ContextProxy.ts +++ b/src/core/config/ContextProxy.ts @@ -36,6 +36,9 @@ const globalSettingsExportSchema = globalSettingsSchema.omit({ taskHistory: true, listApiConfigMeta: true, currentApiConfigName: true, + // Per-view selection state is machine-local: it keeps flowing through the + // normal runtime and pruning paths but must not transfer between settings. + viewStates: true, }) export class ContextProxy { diff --git a/src/core/config/ProviderSettingsManager.ts b/src/core/config/ProviderSettingsManager.ts index 01695d7994..306253578a 100644 --- a/src/core/config/ProviderSettingsManager.ts +++ b/src/core/config/ProviderSettingsManager.ts @@ -55,6 +55,19 @@ export const providerProfilesSchema = z.object({ export type ProviderProfiles = z.infer +/** + * Signals that a profile's configuration no longer exists. Callers that treat an + * already-deleted profile as an idempotent no-op branch on this type instead of + * matching error message text, which a profile name containing the phrase could + * otherwise spoof. + */ +export class ProviderSettingsNotFoundError extends Error { + constructor(message: string) { + super(message) + this.name = "ProviderSettingsNotFoundError" + } +} + export class ProviderSettingsManager { private static readonly SCOPE_PREFIX = "roo_cline_config_" private readonly defaultConfigId = this.generateId() @@ -511,7 +524,7 @@ export class ProviderSettingsManager { const providerProfiles = await this.load() if (!providerProfiles.apiConfigs[name]) { - throw new Error(`Config '${name}' not found`) + throw new ProviderSettingsNotFoundError(`Config '${name}' not found`) } if (Object.keys(providerProfiles.apiConfigs).length === 1) { @@ -522,6 +535,11 @@ export class ProviderSettingsManager { await this.store(providerProfiles) }) } catch (error) { + // A missing config is a caller-meaningful signal, not a failure: rethrow it + // unwrapped so callers can branch on the type instead of message text. + if (error instanceof ProviderSettingsNotFoundError) { + throw error + } throw new Error(`Failed to delete config: ${error}`) } } diff --git a/src/core/config/__tests__/ContextProxy.spec.ts b/src/core/config/__tests__/ContextProxy.spec.ts index b4d3b1b8aa..f9fa9cdb15 100644 --- a/src/core/config/__tests__/ContextProxy.spec.ts +++ b/src/core/config/__tests__/ContextProxy.spec.ts @@ -740,4 +740,20 @@ Output only the summary of the conversation so far, without any additional comme expect(customSupportPromptsUpdateCalls.length).toBe(0) }) }) + + describe("export", () => { + it("should exclude viewStates from the exported settings", async () => { + await proxy.setValue("viewStates", { + "stable-sidebar-view": { mode: "architect", currentApiConfigName: "profile-a", updatedAt: 1 }, + }) + await proxy.setValue("customInstructions", "global instructions") + + const exported = await proxy.export() + + // Per-view selection state is machine-local and must never transfer + // between settings, while ordinary global settings keep round-tripping. + expect(exported).not.toHaveProperty("viewStates") + expect(exported?.customInstructions).toBe("global instructions") + }) + }) }) diff --git a/src/core/config/__tests__/ProviderSettingsManager.spec.ts b/src/core/config/__tests__/ProviderSettingsManager.spec.ts index a1fc9ac7de..3b93b7cd22 100644 --- a/src/core/config/__tests__/ProviderSettingsManager.spec.ts +++ b/src/core/config/__tests__/ProviderSettingsManager.spec.ts @@ -12,7 +12,7 @@ import { import { clearAllMocks } from "../../../test-utils/reset" import { makeExtensionContext } from "../../../test-utils/vscode" -import { ProviderSettingsManager, ProviderProfiles } from "../ProviderSettingsManager" +import { ProviderSettingsManager, ProviderSettingsNotFoundError, ProviderProfiles } from "../ProviderSettingsManager" // `export()` builds an API handler per profile to read model capabilities. Mock // buildApiHandler with the real @roo-code/types model definitions so the token-field @@ -973,6 +973,11 @@ describe("ProviderSettingsManager", () => { }), ) + // The typed not-found signal is the contract callers branch on: a profile + // name containing "not found" must not be matchable via message text. + await expect(providerSettingsManager.deleteConfig("nonexistent")).rejects.toBeInstanceOf( + ProviderSettingsNotFoundError, + ) await expect(providerSettingsManager.deleteConfig("nonexistent")).rejects.toThrow( "Config 'nonexistent' not found", ) diff --git a/src/core/config/__tests__/importExport.spec.ts b/src/core/config/__tests__/importExport.spec.ts index 90db81d8a1..b8dff9c0ed 100644 --- a/src/core/config/__tests__/importExport.spec.ts +++ b/src/core/config/__tests__/importExport.spec.ts @@ -331,6 +331,51 @@ describe("importExport", () => { ]) }) + it("should not apply imported viewStates to the context proxy", async () => { + const fileContent = JSON.stringify({ + providerProfiles: { + currentApiConfigName: "test", + apiConfigs: { + test: { apiProvider: providerIdentifiers.openai, apiKey: "test-key", id: "test-id" }, + }, + }, + globalSettings: { + mode: "code", + viewStates: { + "stable-sidebar-view": { + mode: "architect", + currentApiConfigName: "profile-a", + updatedAt: 1, + }, + }, + }, + }) + + ;(fs.readFile as Mock).mockResolvedValue(fileContent) + + mockProviderSettingsManager.export.mockResolvedValue({ + currentApiConfigName: "default", + apiConfigs: { default: { apiProvider: providerIdentifiers.anthropic, id: "default-id" } }, + }) + + mockProviderSettingsManager.listConfig.mockResolvedValue([ + { name: "test", id: "test-id", apiProvider: providerIdentifiers.openai }, + { name: "default", id: "default-id", apiProvider: providerIdentifiers.anthropic }, + ]) + + const result = await importSettingsFromPath("/mock/path/settings.json", { + providerSettingsManager: mockProviderSettingsManager, + contextProxy: mockContextProxy, + customModesManager: mockCustomModesManager, + }) + + expect(result.success).toBe(true) + // Per-view selection state is machine-local: importing settings must not + // apply another machine's view pins, while other settings round-trip. + expect(mockContextProxy.setValues).toHaveBeenCalledWith({ mode: "code" }) + expect(result).not.toHaveProperty("globalSettings.viewStates") + }) + it("should return success: false when file content is invalid", async () => { ;(vscode.window.showOpenDialog as Mock).mockResolvedValue([{ fsPath: "/mock/path/settings.json" }]) diff --git a/src/core/config/importExport.ts b/src/core/config/importExport.ts index 9882039ad3..29c9497552 100644 --- a/src/core/config/importExport.ts +++ b/src/core/config/importExport.ts @@ -98,6 +98,14 @@ function sanitizeGlobalSettings(rawGlobalSettings: unknown): { for (const [key, rawValue] of Object.entries(rawGlobalSettings)) { const path = `globalSettings.${key}` + + // Per-view selection state is machine-local: it round-trips through the + // normal runtime and pruning paths, but importing it would pin selections + // from another machine's views on this one. + if (key === "viewStates") { + continue + } + const schema = globalSettingsShape[key as keyof GlobalSettings] if (!schema) { diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index 3d88df632b..f5f09244ff 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -59,6 +59,7 @@ import { isRetiredProvider, modelIdKeys, providerIdentifiers, + PROVIDER_SETTINGS_KEYS, } from "@roo-code/types" import { RateLimitClock, createRateLimitClock } from "../task/RateLimitClock" import { TaskRegistry } from "../task/TaskRegistry" @@ -112,7 +113,7 @@ import { buildApiHandler } from "../../api" import { forceFullModelDetailsLoad, hasLoadedFullDetails } from "../../api/providers/fetchers/lmstudio" import { ContextProxy } from "../config/ContextProxy" -import { ProviderSettingsManager } from "../config/ProviderSettingsManager" +import { ProviderSettingsManager, ProviderSettingsNotFoundError } from "../config/ProviderSettingsManager" import { CustomModesManager } from "../config/CustomModesManager" import { PendingActionSettlementError, Task } from "../task/Task" @@ -139,6 +140,14 @@ import { REQUESTY_BASE_URL } from "../../shared/utils/requesty" import { validateAndFixToolResultIds } from "../task/validateToolResultIds" import { PendingEditOperationStore, type PendingEditOperationInput } from "./PendingEditOperationStore" +type PersistedViewState = NonNullable[string] + +/** + * Values that can be held in a view-local state buffer (in-memory) and, for the + * non-secret subset, persisted durably per stable view id. + */ +type ViewLocalStateValues = Partial & Partial + /** * https://github.com/microsoft/vscode-webview-ui-toolkit-samples/blob/main/default/weather-webview/src/providers/WeatherViewProvider.ts * https://github.com/KumarVariable/vscode-extension-sidebar-html/blob/master/src/customSidebarViewProvider.ts @@ -219,6 +228,10 @@ export class ClineProvider public static readonly sideBarId = `${Package.name}.SidebarProvider` public static readonly tabPanelId = `${Package.name}.TabPanelProvider` private static activeInstances: Set = new Set() + private static nextViewId = 0 + private static readonly MAX_PERSISTED_VIEW_STATES = 50 + private static readonly MAX_VIEW_STATE_ID_LENGTH = 64 + private static persistedViewStateWriteQueue: Promise = Promise.resolve() private disposables: vscode.Disposable[] = [] private webviewDisposables: vscode.Disposable[] = [] private pendingThemeFixtureProbes = new Map< @@ -351,6 +364,45 @@ export class ClineProvider */ private clineMessagesSeq = 0 + /** + * Unique identifier for this provider instance's view. + * Based on renderContext and a monotonically increasing counter to ensure uniqueness across multiple instances. + */ + public readonly viewId: string + + /** + * Stable identifier for persisted per-view state keys. + * Defaults to viewId until the webview reports its VS Code-persisted id. + * A durable entry under this id is bound to the webview that wrote it by a host-minted + * claim token (see setViewStateId), so the entry - and the profile its pin brings back + * into the state post - can outlive this instance without becoming adoptable by any + * other webview. + */ + private viewStateId: string + + /** + * Whether this instance wrote an entry under its own session-local temporary id. + * Temporary ids restart from 0 on every extension host start, so an entry under the + * same name can belong to a different session. Only re-key entries this instance wrote. + */ + private wroteUnderTemporaryViewStateId = false + + /** + * Local state buffer for this specific view instance. + * Used to isolate mode, apiConfiguration, and other fields from the shared ContextProxy singleton + * when running in parallel (multi-tab) mode. + */ + private viewLocalState: Partial = {} + + /** + * This view's pinned profile name from the view-local buffer. Exposed for + * sibling-instance inspection (getAllInstances() filtering): `viewLocalState` + * is private and must not be reached through bracket access. + */ + get pinnedProfileName(): string | undefined { + return this.viewLocalState.currentApiConfigName + } + public isViewLaunched = false public settingsImportedAt?: number public readonly latestAnnouncementId = "oct-2026-v3.90.0-providers-tools-reasoning" // v3.90.0 providers and models, safer tool execution, reasoning and streaming @@ -366,14 +418,17 @@ export class ClineProvider mdmService?: MdmService, ) { super() + // Initialize viewId based on renderContext and monotonically increasing instance identifier for uniqueness. + // activeInstances is used for visibility/iteration checks, so we keep tracking instances separately. + this.viewId = `${renderContext}-${ClineProvider.nextViewId++}` + this.viewStateId = this.viewId + ClineProvider.activeInstances.add(this) this.currentWorkspacePath = getWorkspacePath() this.pendingEditOperations = new PendingEditOperationStore( ClineProvider.PENDING_OPERATION_TIMEOUT_MS, (message) => this.log(message), ) - ClineProvider.activeInstances.add(this) - this.mdmService = mdmService void this.updateGlobalState("codebaseIndexModels", EMBEDDING_MODEL_PROFILES) @@ -398,6 +453,9 @@ export class ClineProvider await this.postStateToWebviewWithoutClineMessages() }) + // Load initial state from global state into viewLocalState buffer after dependencies used by getState are ready. + void this.loadViewState() + // Initialize MCP Hub through the singleton manager McpServerManager.getInstance(this.context, this) .then((hub) => { @@ -520,6 +578,462 @@ export class ClineProvider } } + /** + * Reads the registered viewStates map, returning a defensive copy. + * When fresh is set, the map is read directly from globalState (bypassing the + * ContextProxy cache) so serialized writes never observe a stale in-memory value. + */ + private getPersistedViewStates(options: { fresh?: boolean } = {}): Record { + const viewStates = options.fresh + ? this.context.globalState.get("viewStates") + : this.contextProxy.getValue("viewStates") + + if (!viewStates || typeof viewStates !== "object" || Array.isArray(viewStates)) { + return Object.create(null) + } + + // Copy onto a null prototype. A view id that names an Object.prototype key + // ("constructor", "toString", "valueOf", ...) must not resolve through the + // prototype chain and be mistaken for a persisted entry. + return Object.assign(Object.create(null), viewStates) + } + + /** + * Persists this view's non-secret selections through the serialized write queue. + * The write re-reads the map fresh and merges into the existing entry, removing the + * entry entirely when nothing persistable remains, so concurrent views cannot clobber it. + * The entry is keyed by the view id active when the change was made. Writes captured + * while the provider still holds its temporary (pre-launch) id persist under that id + * and are re-keyed to the stable view id when the webview registers one, so a change + * that lands before the launch message stays durable instead of being lost. + */ + private async savePersistedViewState(values: Partial): Promise { + // Capture the id at change time: a write belongs to the view that was active + // when the change was made, even if a newer id is registered while it is queued. + const viewStateId = this.viewStateId + // Set by the queued write when it had to mint a claim, delivered after it lands. + let mintedClaimToken: string | undefined + const write = ClineProvider.persistedViewStateWriteQueue.then(async () => { + const states = this.getPersistedViewStates({ fresh: true }) + // The first write to an unowned temporary id claims the slot instead of merging + // into it: temporary names restart from 0 on every host start, so an entry under + // this name can be a leftover from an earlier session, and merging would adopt its + // fields and later re-key them under the stable id. Entries under a stable id, or + // under the temporary id this instance already authored, keep the merge semantics. + const ownsTargetEntry = viewStateId !== this.viewId || this.wroteUnderTemporaryViewStateId + const current = ownsTargetEntry ? (states[viewStateId] ?? {}) : {} + const next: PersistedViewState = { ...current } + + if ("mode" in values) { + if (values.mode === undefined || values.mode === null) { + delete next.mode + } else { + next.mode = values.mode + } + } + + if ("currentApiConfigName" in values) { + if (values.currentApiConfigName === undefined || values.currentApiConfigName === null) { + delete next.currentApiConfigName + } else { + next.currentApiConfigName = values.currentApiConfigName + } + } + + let wroteEntry = false + if (!next.mode && !next.currentApiConfigName) { + delete states[viewStateId] + } else { + next.updatedAt = values.updatedAt ?? Date.now() + // Bind the entry to this webview. An existing entry keeps the token it was + // adopted with (so a reload can still prove ownership); a new entry - or one + // written before claims existed - gets a fresh host-minted token. The token is + // never taken from `values`: it is host-owned, and webview input must not be + // able to choose or supply one. + if (!next.claimToken) { + next.claimToken = crypto.randomUUID() + mintedClaimToken = next.claimToken + } + states[viewStateId] = next + wroteEntry = true + } + + await this.contextProxy.setValue("viewStates", this.prunePersistedViewStates(states)) + // Authorship is recorded only after the durable write lands: a failed persistence + // must not mark the temporary id as owned, or a later load would adopt an entry + // that was never actually stored. + if (wroteEntry && viewStateId === this.viewId) { + this.wroteUnderTemporaryViewStateId = true + } + }) + + ClineProvider.persistedViewStateWriteQueue = write.catch(() => {}) + await write + + // Delivered only once the durable write landed: a webview must never hold a claim the + // host did not store, or the next launch would present a token the entry cannot match. + if (mintedClaimToken) { + this.postViewStateClaimToWebview(viewStateId, mintedClaimToken) + } + } + + /** + * Removes the given view's entry from the registered viewStates map. + * Runs through the serialized write queue to avoid racing concurrent view-state writes. + */ + private async clearPersistedViewState(viewStateId = this.viewStateId): Promise { + const write = ClineProvider.persistedViewStateWriteQueue.then(async () => { + const states = this.getPersistedViewStates({ fresh: true }) + delete states[viewStateId] + await this.contextProxy.setValue("viewStates", states) + }) + + ClineProvider.persistedViewStateWriteQueue = write.catch(() => {}) + await write + } + + /** + * Re-binds a claim-less viewStates entry to this webview with a freshly minted claim. + * Entries written before claims existed cannot be attributed to any webview, so their + * selections are dropped instead of being carried over: keeping them would let the new + * token re-expose them on a later launch, which is exactly the disclosure this binding + * exists to prevent. Runs through the serialized write queue like every other mutation. + */ + private async rebindUnboundViewStateEntry(viewStateId: string): Promise { + const claimToken = crypto.randomUUID() + let rebound = false + + const write = ClineProvider.persistedViewStateWriteQueue.then(async () => { + const states = this.getPersistedViewStates({ fresh: true }) + const current = states[viewStateId] + // A concurrent registration may have bound this key while this write was queued: + // never overwrite an existing claim, and let the caller refuse the stale adoption. + if (current && typeof current.claimToken === "string" && current.claimToken) { + return + } + states[viewStateId] = { claimToken, updatedAt: Date.now() } + await this.contextProxy.setValue("viewStates", this.prunePersistedViewStates(states)) + rebound = true + }) + + ClineProvider.persistedViewStateWriteQueue = write.catch(() => {}) + await write + + return rebound ? claimToken : undefined + } + + /** + * Delivers the host-minted claim that governs a durable viewStates key to this view's + * webview. The webview only stores it and echoes it back on the next launch: it can + * never mint or choose a claim itself. + */ + private postViewStateClaimToWebview(viewStateId: string, claimToken: string): void { + void this.postMessageToWebview({ type: "viewStateClaim", viewStateId, viewStateClaim: claimToken }) + } + + /** + * Keeps only the most recently updated entries of the persisted view states map, + * bounded by MAX_PERSISTED_VIEW_STATES so the global key cannot grow unboundedly. + */ + private prunePersistedViewStates(states: Record): Record { + return Object.fromEntries( + Object.entries(states) + .sort(([, a], [, b]) => (b.updatedAt ?? 0) - (a.updatedAt ?? 0)) + .slice(0, ClineProvider.MAX_PERSISTED_VIEW_STATES), + ) + } + + /** + * Re-keys this provider's temporary pre-launch viewStates entry to the newly + * registered stable id so pre-launch writes become durable under the stable key + * instead of orphaning under a session-local temporary id. Only the provider's own + * temporary id is eligible: an entry under a previously registered stable id belongs + * to that webview's storage and is left alone. When the stable entry already exists + * it wins and the temporary entry is dropped, because temporary ids are session + * counters that can collide across window reloads. Runs through the serialized write + * queue like every other viewStates mutation. An entry this instance never wrote is + * left alone, so a stale entry that happens to carry the same session-local name is + * not adopted. + */ + private async rekeyPersistedViewStateEntry(nextViewStateId: string): Promise { + const previousViewStateId = this.viewId + + const write = ClineProvider.persistedViewStateWriteQueue.then(async () => { + // An entry under this name can belong to a different session, because temporary + // ids restart from 0 on every extension host start. Only re-key entries this + // instance wrote, otherwise a stale entry from another session is adopted. + if (!this.wroteUnderTemporaryViewStateId) { + return + } + + const states = this.getPersistedViewStates({ fresh: true }) + const previous = states[previousViewStateId] + + if (!previous) { + return + } + + delete states[previousViewStateId] + + if (!states[nextViewStateId]) { + states[nextViewStateId] = previous + } + + await this.contextProxy.setValue("viewStates", this.prunePersistedViewStates(states)) + + // Only a successful write clears authorship: a failed attempt leaves the entry + // under the temporary name, and a retry must still be able to re-key it. + this.wroteUnderTemporaryViewStateId = false + }) + + ClineProvider.persistedViewStateWriteQueue = write.catch(() => {}) + await write + } + + /** + * Registers this provider's stable view identifier and loads any persisted selections it owns. + * The identifier is sanitized so it remains a safe object key in the shared viewStates map. + * + * `presentedClaim` is the host-minted token this webview was given for that id. It is the + * only proof of ownership: an entry that carries a claim is loaded only when the presented + * token matches it, so a webview cannot adopt another (e.g. disposed, still durable) view's + * id and read that view's pinned profile - and the profile secrets copied into the state + * post - back out of it. The check runs before any re-keying or loading. + */ + public async setViewStateId(viewStateId: string | undefined, presentedClaim?: string): Promise { + // The webview generates this id on purpose - it has to survive a webview reload, + // which recreates the view on both sides - so the host cannot mint it instead. + // What the host owns is which view may hold a given persisted key, so everything + // below validates the supplied value before it becomes one. + if (typeof viewStateId !== "string") { + // A crafted postMessage can carry any JSON value here even though the message + // type declares a string; the persisted key must stay a string. + this.log(`[setViewStateId] Ignoring a non-string viewStateId for view ${this.viewId}.`) + return + } + + const normalizedViewStateId = viewStateId.trim().replace(/[^A-Za-z0-9_-]/g, "_") + + if ( + !normalizedViewStateId || + normalizedViewStateId === this.viewStateId || + // Reject "__proto__" and any other prototype-chain key. The map is copied + // onto a null prototype, so these names can no longer resolve through the + // chain, but they are still rejected as ids so a caller cannot store an + // entry under a name that looks like an inherited member. + normalizedViewStateId === "__proto__" + ) { + return + } + + // Bound the key: the webview generates a UUID, so a much longer value is not a + // view id, and an unbounded key is unbounded growth in the shared viewStates map. + if (normalizedViewStateId.length > ClineProvider.MAX_VIEW_STATE_ID_LENGTH) { + this.log( + `[setViewStateId] Ignoring an oversized viewStateId (${normalizedViewStateId.length} chars) for view ${this.viewId}.`, + ) + return + } + + const claimant = ClineProvider.getAllInstances().find( + (instance) => instance !== this && instance.viewStateId === normalizedViewStateId, + ) + if (claimant) { + // Ownership check: a key another live view holds must not be adopted. Doing so + // would load that view's pinned profile, nested overlay, and mode into this + // provider, and this webview could then overwrite that view's persisted entry. + // Staying on the temporary id keeps this view working against the shared state. + this.log( + `[setViewStateId] Refusing viewStateId ${normalizedViewStateId} for view ${this.viewId}: already claimed by live view ${claimant.viewId}.`, + ) + return + } + + // Claim binding, checked before any re-key or load so a refused registration can + // neither read nor mutate a persisted entry. Read fresh from storage rather than + // through the ContextProxy cache: a security check must not trust a stale copy. + const persistedEntry = this.getPersistedViewStates({ fresh: true })[normalizedViewStateId] + + if (persistedEntry) { + const storedClaim = persistedEntry.claimToken + + if (typeof storedClaim !== "string" || !storedClaim) { + // A pre-claim entry cannot be attributed to any webview, so its selections are + // never loaded. Re-establish the binding with a fresh host-minted claim and hand + // that claim to this webview: the key becomes adoptable again (no upgrade brick) + // and the unbound selections are gone, so the new token cannot resurrect them. + const reboundClaim = await this.rebindUnboundViewStateEntry(normalizedViewStateId) + + if (reboundClaim === undefined) { + // A concurrent registration bound the key while the re-bind was queued: this + // launch adopts a key another webview now owns, so refuse it instead of + // handing out a claim that is not ours. + this.log( + `[setViewStateId] Refusing viewStateId ${normalizedViewStateId} for view ${this.viewId}: bound concurrently by another registration.`, + ) + return + } + + this.postViewStateClaimToWebview(normalizedViewStateId, reboundClaim) + this.log( + `[setViewStateId] Re-bound claim-less viewStates entry ${normalizedViewStateId} for view ${this.viewId}: unbound selections were not loaded.`, + ) + } else if (typeof presentedClaim !== "string" || presentedClaim !== storedClaim) { + // Fail closed: the entry belongs to a webview that never presented this view's + // claim. Rejection is side-effect free, so presenting an id cannot probe, mutate + // or delete another view's entry. + this.log( + `[setViewStateId] Refusing viewStateId ${normalizedViewStateId} for view ${this.viewId}: claim missing or mismatched.`, + ) + return + } + } + + const previousViewStateId = this.viewStateId + + this.viewStateId = normalizedViewStateId + + try { + // Re-key any durable entry written under the temporary pre-launch id before + // loading, so the load sees the view's own pre-registration selections. + await this.rekeyPersistedViewStateEntry(this.viewStateId) + + await this.loadViewState() + + // Re-affirm the binding for the id just adopted: a claim minted while this view was + // still on its temporary id now governs this key (the entry was re-keyed), so the + // webview is told the canonical (viewStateId, claim) pair to echo on its next launch. + const adoptedClaim = this.getPersistedViewStates({ fresh: true })[this.viewStateId]?.claimToken + + if (adoptedClaim) { + this.postViewStateClaimToWebview(this.viewStateId, adoptedClaim) + } + } catch (error) { + // A persistence failure must not leave the provider holding an id that was + // never registered: restore the previous id so a later launch retries the + // registration and the load instead of the guard above early-returning for + // the failed id. + this.viewStateId = previousViewStateId + throw error + } + } + + /** + * Loads non-secret persisted selections from the registered viewStates map. + * Missing entries are intentionally left unset so getState() falls back to shared ContextProxy values. + * Fields mutated while the async profile lookup is in flight are reapplied on top of the + * loaded state, field by field, so in-flight user selections are not clobbered by the load. + */ + private async loadViewState(): Promise { + // Capture the id this load is for: a newer id registered while an async + // profile lookup is in flight must not be overwritten by this stale load. + const loadedForViewId = this.viewStateId + + // While the stable id has not been registered yet, the key is this instance's + // session-local name. Temporary names restart from 0 on every host start, so an + // entry under the same name can belong to a different session. Load only entries + // this instance authored. + if (loadedForViewId === this.viewId && !this.wroteUnderTemporaryViewStateId) { + return + } + try { + const persisted = this.getPersistedViewStates()[loadedForViewId] + const loadedState: Partial = {} + + // Snapshot the in-memory buffer before the async profile lookup. The + // mutation paths update viewLocalState in place, so a shallow copy is + // what makes fields mutated during the load window observable below. + const preLoadBuffer = { ...this.viewLocalState } + + if (persisted?.mode) { + // A persisted mode may reference a custom mode that was deleted after it was + // pinned: restore it only when the slug still resolves, so a stale slug cannot + // shadow the shared mode from getState(). + const customModes = await this.customModesManager.getCustomModes() + if (getModeBySlug(persisted.mode, customModes)) { + loadedState.mode = persisted.mode as Mode + } else { + this.log(`[loadViewState] Ignoring unknown persisted mode "${persisted.mode}"`) + } + } + + if (persisted?.currentApiConfigName) { + loadedState.currentApiConfigName = persisted.currentApiConfigName + + try { + const { name: _name, ...apiConfiguration } = await this.providerSettingsManager.getProfile({ + name: persisted.currentApiConfigName, + }) + loadedState.apiConfiguration = apiConfiguration as ProviderSettings + } catch (error) { + this.log( + `[loadViewState] Unable to resolve API profile '${persisted.currentApiConfigName}' for viewId ${this.viewId}: ${error instanceof Error ? error.message : String(error)}`, + ) + } + } + + if (this.viewStateId !== loadedForViewId) { + this.log(`[loadViewState] Discarding stale state for superseded view id ${loadedForViewId}`) + return + } + + // Reapply the buffer fields that changed while the load was in flight, + // tracking the change instead of testing against undefined: a field cleared + // during the load window must stay cleared (the loaded value must not + // resurrect it), and a field written to a new value must win over it. + // Untouched fields keep the persisted values authoritative, and the + // pre-load buffer is never merged wholesale so stale temporary-id state + // cannot override the stable persisted state. + const postLoadBuffer = this.viewLocalState + const mergedState: Partial = { ...loadedState } + + if (!Object.is(preLoadBuffer.mode, postLoadBuffer.mode)) { + if (postLoadBuffer.mode === undefined) { + delete mergedState.mode + } else { + mergedState.mode = postLoadBuffer.mode + } + } + + if (!Object.is(preLoadBuffer.currentApiConfigName, postLoadBuffer.currentApiConfigName)) { + if (postLoadBuffer.currentApiConfigName === undefined) { + delete mergedState.currentApiConfigName + } else { + mergedState.currentApiConfigName = postLoadBuffer.currentApiConfigName + } + } + + if (!Object.is(preLoadBuffer.apiConfiguration, postLoadBuffer.apiConfiguration)) { + if (postLoadBuffer.apiConfiguration === undefined) { + delete mergedState.apiConfiguration + } else { + mergedState.apiConfiguration = postLoadBuffer.apiConfiguration + } + } + + this.viewLocalState = mergedState + this.log(`[loadViewState] Loaded state for viewId ${this.viewId}`) + } catch (error) { + this.log( + `[loadViewState] Error loading state for viewId ${this.viewId}: ${error instanceof Error ? error.message : String(error)}`, + ) + } + } + + /** + * Saves a single view-local state value. The in-memory buffer is always updated; the + * non-secret subset (mode, currentApiConfigName) is persisted durably under the view + * id active when the change was made, re-keyed to the stable id on registration. + */ + public async saveViewState( + key: K, + value: ViewLocalStateValues[K] | undefined, + ): Promise { + await this._saveViewLocalStateFromMutation({ [key]: value } as ViewLocalStateValues) + + this.log(`[saveViewState] Saved ${String(key)} for viewId ${this.viewId}`) + } + /** * Override EventEmitter's on method to match TaskProviderLike interface */ @@ -847,7 +1361,6 @@ export class ClineProvider ) } } - async dispose() { if (this._disposed) { return @@ -1232,7 +1745,6 @@ export class ClineProvider ) return run } - private async createTaskWithHistoryItemUnlocked( historyItem: HistoryItem & { rootTask?: Task; parentTask?: Task }, options?: { startTask?: boolean }, @@ -1469,7 +1981,6 @@ export class ClineProvider return task } - public async postMessageToWebview(message: ExtensionMessage) { if (this._disposed) { return @@ -1725,7 +2236,6 @@ export class ClineProvider this.handleModeSwitchUnlocked(newMode, targetTask, signal), ) } - private async handleModeSwitchUnlocked( newMode: Mode, targetTask: Task | null | undefined, @@ -2033,9 +2543,17 @@ export class ClineProvider // `allSettled` so a caller that rolls back after a failure never races a write still in flight. const activationResults = await Promise.allSettled([ this.updateGlobalState("listApiConfigMeta", await this.providerSettingsManager.listConfig()), - this.updateGlobalState("currentApiConfigName", name), + // Route through setValue so the in-memory viewLocalState buffer tracks the + // activated profile: a plain global write would leave a stale loaded + // currentApiConfigName shadowing the new value in getValues(). + this.setValue("currentApiConfigName", name), this.providerSettingsManager.setModeConfig(mode, id), this.contextProxy.setProviderSettings(providerSettings), + // setProviderSettings writes the shared store directly, bypassing the + // view-local mutation path: also refresh this view's buffer so a stale + // loaded apiConfiguration cannot keep shadowing the new settings in + // getState(). + this._saveViewLocalStateFromMutation({ apiConfiguration: providerSettings }), ]) const failedActivation = activationResults.find( (result): result is PromiseRejectedResult => result.status === "rejected", @@ -2045,6 +2563,10 @@ export class ClineProvider if (signal.aborted) return id + // Other live views may have buffered this profile's settings earlier; + // refresh them so their getState() cannot report the updated profile's + // name with stale settings. + // Change the provider for the current task. // TODO: We should rename `buildApiHandler` for clarity (e.g. `getProviderClient`). this.updateTaskApiHandlerIfNeeded(providerSettings, { forceRebuild: true }) @@ -2053,6 +2575,21 @@ export class ClineProvider await this.persistStickyProviderProfileToCurrentTask(name) } else { await this.updateGlobalState("listApiConfigMeta", await this.providerSettingsManager.listConfig()) + + // A save that does not activate still changes the profile's settings, and + // every view pinned to it buffers a full copy of them. Refresh those views + // (and this one when it is the pinned view) or their getState() keeps + // serving the settings captured before the save under the same name. + if (this.pinnedProfileName === name) { + await this._saveViewLocalStateFromMutation({ apiConfiguration: providerSettings }) + // Only rebuild when the task actually runs under the saved profile: a + // view pinned to this profile can hold a task that follows a different + // sticky profile, and the forced rebuild would silently switch that + // conversation to the saved profile's settings. + if (this.getCurrentTask()?.taskApiConfigName === name) { + this.updateTaskApiHandlerIfNeeded(providerSettings, { forceRebuild: true }) + } + } } if (signal.aborted) return id @@ -2060,7 +2597,6 @@ export class ClineProvider await this.postStateToWebview() return id } - async deleteProviderProfile(profileToDelete: ProviderSettingsEntry) { const globalSettings = this.contextProxy.getValues() let profileToActivate: string | undefined = globalSettings.currentApiConfigName @@ -2126,7 +2662,6 @@ export class ClineProvider this.activateProviderProfileUnlocked(args, options, signal), ) } - private async activateProviderProfileUnlocked( args: { name: string } | { id: string }, options?: { @@ -2249,9 +2784,6 @@ export class ClineProvider await this.upsertProviderProfile(currentApiConfigName, newConfiguration) } - - // Zoo Code Auth - async handleZooCodeCallback(token: string) { // Auth mutation (token storage, subscription check, success toast) was already // performed by handleAuthCallback() in handleUri.ts before this method was called. @@ -3301,7 +3833,6 @@ export class ClineProvider private getGlobalState(key: K) { return this.contextProxy.getValue(key) } - public async setValue(key: K, value: RooCodeSettings[K]) { await this.contextProxy.setValue(key, value) } @@ -3309,17 +3840,53 @@ export class ClineProvider public getValue(key: K) { return this.contextProxy.getValue(key) } - public getValues() { return this.contextProxy.getValues() } - public async setValues(values: RooCodeSettings) { await this.contextProxy.setValues(values) } - // dev + /** + * Persists the view-local subset of a ContextProxy mutation, then updates the in-memory + * viewLocalState buffer. Persistence is awaited first so a failed durable write cannot + * leave the local cache ahead of the persisted state. + */ + private async _saveViewLocalStateFromMutation( + values: Partial & Partial, + ): Promise { + await this._persistViewLocalStateFromMutation(values) + this._updateViewLocalStateFromMutation(values) + } + + /** + * Writes the durably persisted subset of a mutation (mode and currentApiConfigName) + * into the registered viewStates map for this view. + */ + private async _persistViewLocalStateFromMutation( + values: Partial & Partial, + ): Promise { + const persistedValues: Partial = {} + if ("mode" in values) { + persistedValues.mode = values.mode as PersistedViewState["mode"] + } + + if ("currentApiConfigName" in values) { + persistedValues.currentApiConfigName = values.currentApiConfigName + } + + if ("mode" in persistedValues || "currentApiConfigName" in persistedValues) { + await this.savePersistedViewState(persistedValues) + } + } + + /** + * Clear view-local state cache so that getState() falls back to ContextProxy defaults. + */ + private _clearViewLocalState(): void { + this.viewLocalState = {} + } async resetState() { const answer = await vscode.window.showInformationMessage( t("common:confirmation.reset_state"), @@ -4651,4 +5218,54 @@ export class ClineProvider return vscode.Uri.file(filePath).toString() } } + + /** + * Update or invalidate viewLocalState when ContextProxy is mutated via setValues, setValue, + * profile upsert/activation/deletion, or resetState. This ensures the local cache stays in + * sync with global state changes that would otherwise be invisible behind mergedStateValues. + */ + private _updateViewLocalStateFromMutation(values: Partial & Partial): void { + if ("mode" in values) { + const val = values.mode + if (val === undefined || val === null) { + delete this.viewLocalState.mode + } else { + this.viewLocalState.mode = val + } + } + + if ("currentApiConfigName" in values) { + const val = values.currentApiConfigName + if (val === undefined || val === null) { + delete this.viewLocalState.currentApiConfigName + } else { + this.viewLocalState.currentApiConfigName = val + } + } + + if ("apiConfiguration" in values) { + const val = values.apiConfiguration + if (val === undefined || val === null) { + delete this.viewLocalState.apiConfiguration + } else { + this.viewLocalState.apiConfiguration = val + } + } else if (PROVIDER_SETTINGS_KEYS.some((key) => key in values)) { + const providerSettingsUpdate = PROVIDER_SETTINGS_KEYS.reduce((acc, key) => { + if (key in values) { + return { ...acc, [key]: values[key as keyof RooCodeSettings] } + } + + return acc + }, {} as ProviderSettings) + + this.viewLocalState.apiConfiguration = + "apiProvider" in providerSettingsUpdate + ? providerSettingsUpdate + : { + ...(this.viewLocalState.apiConfiguration ?? {}), + ...providerSettingsUpdate, + } + } + } } diff --git a/src/core/webview/__tests__/ClineProvider.spec.ts b/src/core/webview/__tests__/ClineProvider.spec.ts index 93543435e2..478cc76393 100644 --- a/src/core/webview/__tests__/ClineProvider.spec.ts +++ b/src/core/webview/__tests__/ClineProvider.spec.ts @@ -14,6 +14,7 @@ import { type ClineMessage, type ExtensionMessage, type ExtensionState, + type RooCodeSettings, type WebviewMessage, ORGANIZATION_ALLOW_ALL, DEFAULT_CHECKPOINT_TIMEOUT_SECONDS, @@ -28,12 +29,15 @@ import { defaultModeSlug } from "../../../shared/modes" import { experimentDefault } from "../../../shared/experiments" import { setTtsEnabled } from "../../../utils/tts" import { ContextProxy } from "../../config/ContextProxy" +import { ProviderSettingsNotFoundError } from "../../config/ProviderSettingsManager" import { WorkspaceIndexingEnablementManager } from "../../../services/code-index/workspace-indexing-enablement-manager" import { Task, TaskOptions } from "../../task/Task" import { safeWriteJson } from "../../../utils/safeWriteJson" +import { t } from "../../../i18n" import { ClineProvider } from "../ClineProvider" import { webviewMessageHandler } from "../webviewMessageHandler" +import type { MdmService } from "../../../services/mdm/MdmService" import { Terminal } from "../../../integrations/terminal/Terminal" import { MessageManager } from "../../message-manager" import { forceFullModelDetailsLoad, hasLoadedFullDetails } from "../../../api/providers/fetchers/lmstudio" @@ -419,6 +423,52 @@ afterAll(() => { vi.restoreAllMocks() }) +/** + * Minimal profile shape the stalled getProfile double resolves to. The + * settings fields are optional so a lookup that resolves name-only (a + * profile with no configured provider) also type-checks. + */ +type StalledProfile = { + name: string + apiProvider?: string + openRouterModelId?: string +} + +/** + * Swap the provider's ProviderSettingsManager for a double whose getProfile + * stalls until the test resolves it, so tests can mutate view state while + * loadViewState is in flight. The double only backs getProfile, the member + * loadViewState awaits; the documented @ts-ignore replaces the per-test + * suppressions the inlined copies used. + */ +function stallProviderSettingsProfile(provider: ClineProvider) { + let resolveProfile: (value: StalledProfile) => void = () => {} + const getProfileSpy = vi.fn(() => { + // Only one lookup is resolvable: resolveProfile is bound to the first + // promise's resolver, so a second getProfile would strand its promise. + // Fail loudly instead of hanging. + if (getProfileSpy.mock.calls.length > 1) { + throw new Error( + "stallProviderSettingsProfile: getProfile called more than once; only one lookup is resolvable", + ) + } + return new Promise((resolve) => (resolveProfile = resolve)) + }) + // @ts-ignore - Reassign the readonly providerSettingsManager for the test; the double only backs getProfile. + provider.providerSettingsManager = { getProfile: getProfileSpy } + // Return a stable wrapper around the closure binding: resolveProfile is + // reassigned to the pending promise's resolver once getProfile is called, + // so returning the variable directly would hand the test the initial no-op. + return { getProfile: getProfileSpy, resolveProfile: (value: StalledProfile) => resolveProfile(value) } +} + +/** + * The host-minted claim stored with a durable view-states entry. A test that adopts an + * entry another provider wrote has to present it, exactly like a webview does on launch. + */ +function persistedViewStateClaim(context: vscode.ExtensionContext, viewStateId: string): string | undefined { + return context.globalState.get("viewStates")?.[viewStateId]?.claimToken +} describe("ClineProvider", () => { beforeAll(() => { vi.mocked(Task).mockImplementation(function (options: any) { From 7906df6ccda71c01620ed7d46a870ed317f79024 Mon Sep 17 00:00:00 2001 From: easonLiangWorldedtech <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Thu, 29 Oct 2026 20:58:44 +0800 Subject: [PATCH 02/27] test(webview): carry the identity and durable viewStates tests with N2 N2 spec now includes the N1 identity tests plus the persistence/load/prune/rekey/export-import coverage; the setValues buffer test moves to the buffer unit. --- .../webview/__tests__/ClineProvider.spec.ts | 833 +++++++++++++++++- 1 file changed, 810 insertions(+), 23 deletions(-) diff --git a/src/core/webview/__tests__/ClineProvider.spec.ts b/src/core/webview/__tests__/ClineProvider.spec.ts index 67336deb47..4bb3e49635 100644 --- a/src/core/webview/__tests__/ClineProvider.spec.ts +++ b/src/core/webview/__tests__/ClineProvider.spec.ts @@ -1,4 +1,4 @@ -// pnpm --filter roo-cline test core/webview/__tests__/ClineProvider.spec.ts +// pnpm --filter roo-cline test core/webview/__tests__/ClineProvider.spec.ts import fs from "fs" import * as path from "path" @@ -29,15 +29,12 @@ import { defaultModeSlug } from "../../../shared/modes" import { experimentDefault } from "../../../shared/experiments" import { setTtsEnabled } from "../../../utils/tts" import { ContextProxy } from "../../config/ContextProxy" -import { ProviderSettingsNotFoundError } from "../../config/ProviderSettingsManager" import { WorkspaceIndexingEnablementManager } from "../../../services/code-index/workspace-indexing-enablement-manager" import { Task, TaskOptions } from "../../task/Task" import { safeWriteJson } from "../../../utils/safeWriteJson" -import { t } from "../../../i18n" import { ClineProvider } from "../ClineProvider" import { webviewMessageHandler } from "../webviewMessageHandler" -import type { MdmService } from "../../../services/mdm/MdmService" import { Terminal } from "../../../integrations/terminal/Terminal" import { MessageManager } from "../../message-manager" import { forceFullModelDetailsLoad, hasLoadedFullDetails } from "../../../api/providers/fetchers/lmstudio" @@ -423,24 +420,12 @@ afterAll(() => { vi.restoreAllMocks() }) -/** - * Minimal profile shape the stalled getProfile double resolves to. The - * settings fields are optional so a lookup that resolves name-only (a - * profile with no configured provider) also type-checks. - */ type StalledProfile = { name: string apiProvider?: string openRouterModelId?: string } -/** - * Swap the provider's ProviderSettingsManager for a double whose getProfile - * stalls until the test resolves it, so tests can mutate view state while - * loadViewState is in flight. The double only backs getProfile, the member - * loadViewState awaits; the documented @ts-ignore replaces the per-test - * suppressions the inlined copies used. - */ function stallProviderSettingsProfile(provider: ClineProvider) { let resolveProfile: (value: StalledProfile) => void = () => {} const getProfileSpy = vi.fn(() => { @@ -462,13 +447,6 @@ function stallProviderSettingsProfile(provider: ClineProvider) { return { getProfile: getProfileSpy, resolveProfile: (value: StalledProfile) => resolveProfile(value) } } -/** - * The host-minted claim stored with a durable view-states entry. A test that adopts an - * entry another provider wrote has to present it, exactly like a webview does on launch. - */ -function persistedViewStateClaim(context: vscode.ExtensionContext, viewStateId: string): string | undefined { - return context.globalState.get("viewStates")?.[viewStateId]?.claimToken -} describe("ClineProvider", () => { beforeAll(() => { vi.mocked(Task).mockImplementation(function (options: any) { @@ -3628,6 +3606,815 @@ describe("ClineProvider", () => { ]) }) }) + + describe("setViewStateId", () => { + it('should ignore "__proto__" and keep the temporary viewId', async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + + await provider["setViewStateId"]("__proto__") + + // "__proto__" is rejected before assignment so a per-view entry can never be + // keyed through the Object.prototype setter: the temporary id stays active and + // nothing is persisted under the reserved name. + expect(provider["viewStateId"]).toBe(provider.viewId) + expect(mockContext.globalState.get("viewStates")).toBeUndefined() + expect(provider["viewLocalState"]).toEqual({}) + + await provider.dispose() + }) + + it("restores the previous view id when the registration write fails so a later launch retries", async () => { + const contextProxy = new ContextProxy(mockContext) + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + contextProxy, + new WebviewFocusTracker(), + ) + // Seed a pre-launch entry under the temporary id through the real write path, + // so the re-key has real work to do and records this instance as its author. + await provider["savePersistedViewState"]({ mode: "architect", updatedAt: 1 }) + + const setValueSpy = vi.spyOn(contextProxy, "setValue").mockRejectedValue(new Error("storage down")) + + await expect(provider["setViewStateId"]("stable-sidebar-view")).rejects.toThrow("storage down") + + // The failed id must not stick: the provider keeps its previous (temporary) + // id so a later launch retries registration and the load instead of the + // guard early-returning for an id that was never persisted. + expect(provider["viewStateId"]).toBe(provider.viewId) + + // A later retry succeeds once the storage write works again, and the + // pre-launch entry lands under the registered id. + setValueSpy.mockRestore() + await provider["setViewStateId"]("stable-sidebar-view") + expect(provider["viewStateId"]).toBe("stable-sidebar-view") + expect(mockContext.globalState.get("viewStates")).toEqual({ + "stable-sidebar-view": { mode: "architect", updatedAt: 1, claimToken: expect.any(String) }, + }) + + await provider.dispose() + }) + }) + + describe("view state claim binding", () => { + it("refuses a viewStateId bound by a concurrent registration through setViewStateId", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + const beforeViewStateId = provider["viewStateId"] + const postSpy = vi.spyOn(provider, "postMessageToWebview").mockResolvedValue(undefined) + // A claim-less entry is adoptable at the first read, but a concurrent registration + // binds the key while this launch's queued re-bind is waiting its turn. + await provider.contextProxy.setValue("viewStates", { "legacy-view": { updatedAt: 1 } }) + ClineProvider["persistedViewStateWriteQueue"] = Promise.resolve().then(async () => { + await provider.contextProxy.setValue("viewStates", { + "legacy-view": { claimToken: "winner", updatedAt: 2 }, + }) + }) + + await provider["setViewStateId"]("legacy-view") + + // The launch must not adopt a key another webview now owns: no claim is delivered, + // the provider stays on its temporary id, and the winner's claim is untouched. + expect(postSpy).not.toHaveBeenCalledWith(expect.objectContaining({ type: "viewStateClaim" })) + expect(provider["viewStateId"]).toBe(beforeViewStateId) + const states = provider.contextProxy.getValue("viewStates") as Record + expect(states["legacy-view"].claimToken).toBe("winner") + ClineProvider["persistedViewStateWriteQueue"] = Promise.resolve() + postSpy.mockRestore() + await provider.dispose() + }) + + it("does not overwrite a claim bound by a concurrent registration", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + await provider.contextProxy.setValue("viewStates", { "legacy-view": { updatedAt: 1 } }) + // A concurrent registration binds this key while the re-bind write is queued. + ClineProvider["persistedViewStateWriteQueue"] = Promise.resolve().then(async () => { + await provider.contextProxy.setValue("viewStates", { + "legacy-view": { claimToken: "winner", updatedAt: 2 }, + }) + }) + + const claim = await provider["rebindUnboundViewStateEntry"]("legacy-view") + + // The queued re-bind must not replace the claim the other registration wrote; it + // reports that nothing was rebound so the caller can refuse the stale adoption. + expect(claim).toBeUndefined() + const states = provider.contextProxy.getValue("viewStates") as Record + expect(states["legacy-view"].claimToken).toBe("winner") + ClineProvider["persistedViewStateWriteQueue"] = Promise.resolve() + await provider.dispose() + }) + + const createProvider = () => + new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + + const storedEntries = () => + mockContext.globalState.get>("viewStates") ?? {} + + test("refuses a disposed view's id when no claim is presented, and loads nothing", async () => { + // The vulnerable path: a view registers a durable entry, is disposed, and a second + // webview presents the same id. dispose() removes the instance but leaves the entry, + // so only the claim can stop the second webview from loading the first one's pinned + // profile (and the profile's secrets) through the state post. + const owner = createProvider() + await owner["setViewStateId"]("closed-view") + await owner.saveViewState("mode", "architect") + await owner.saveViewState("currentApiConfigName", "profile-with-secrets") + + const storedClaim = storedEntries()["closed-view"]?.claimToken + expect(storedClaim).toEqual(expect.any(String)) + + await owner.dispose() + + const intruder = createProvider() + const postMessageSpy = vi.spyOn(intruder, "postMessageToWebview").mockResolvedValue(undefined) + + await intruder["setViewStateId"]("closed-view") + + // Fail closed: the id is not adopted, no selections reach this view and no state is + // posted back to the webview that asked for it. + expect(intruder["viewStateId"]).toBe(intruder.viewId) + expect(intruder["viewLocalState"]).toStrictEqual({}) + expect((await intruder.getState()).currentApiConfigName).not.toBe("profile-with-secrets") + expect(postMessageSpy).not.toHaveBeenCalled() + + // A refused adoption is side-effect free: presenting an id must not probe or rewrite + // the entry that a different webview owns. + expect(storedEntries()["closed-view"]).toMatchObject({ + mode: "architect", + currentApiConfigName: "profile-with-secrets", + claimToken: storedClaim, + }) + + await intruder.dispose() + }) + + test("refuses a mismatched claim", async () => { + const owner = createProvider() + await owner["setViewStateId"]("closed-view") + await owner.saveViewState("currentApiConfigName", "profile-with-secrets") + await owner.dispose() + + const intruder = createProvider() + const postMessageSpy = vi.spyOn(intruder, "postMessageToWebview").mockResolvedValue(undefined) + + // A webview-generated value is not a claim: only the token the host minted matches. + await intruder["setViewStateId"]("closed-view", "webview-chosen-claim") + + expect(intruder["viewStateId"]).toBe(intruder.viewId) + expect(intruder["viewLocalState"]).toStrictEqual({}) + expect(postMessageSpy).not.toHaveBeenCalled() + + await intruder.dispose() + }) + + test("does not churn the claim on later writes to the same entry", async () => { + const postMessageSpy = vi.spyOn(provider, "postMessageToWebview").mockResolvedValue(undefined) + await provider["setViewStateId"]("minted-view") + await provider.saveViewState("mode", "architect") + + const mintedClaim = storedEntries()["minted-view"]?.claimToken + expect(mintedClaim).toEqual(expect.any(String)) + + await provider.saveViewState("currentApiConfigName", "profile-b") + + // A merge into an entry this view already owns keeps its token, so the claim the + // webview holds keeps working and is not re-sent. + expect(storedEntries()["minted-view"]?.claimToken).toBe(mintedClaim) + expect( + postMessageSpy.mock.calls.map(([message]) => message).filter((m) => m.type === "viewStateClaim"), + ).toHaveLength(1) + }) + + test("re-binds a claim-less legacy entry instead of loading its selections", async () => { + // An entry written before claims existed cannot be attributed to any webview: its + // selections are refused, and the key is re-bound with a fresh host-minted claim so + // the upgrade does not brick per-view persistence. + await provider.contextProxy.setValue("viewStates", { + "legacy-view": { mode: "architect", currentApiConfigName: "profile-a", updatedAt: 1 }, + }) + + const postMessageSpy = vi.spyOn(provider, "postMessageToWebview").mockResolvedValue(undefined) + + await provider["setViewStateId"]("legacy-view") + + // No stored selection is adopted... + expect(provider["viewStateId"]).toBe("legacy-view") + expect(provider["viewLocalState"]).toStrictEqual({}) + + // ...the old entry is replaced by a claim-bearing one with the unbound selections gone... + const rebound = storedEntries()["legacy-view"] + expect(rebound).toEqual({ claimToken: expect.any(String), updatedAt: expect.any(Number) }) + expect(rebound).not.toHaveProperty("mode") + expect(rebound).not.toHaveProperty("currentApiConfigName") + + // ...and the fresh claim is handed to this webview so the next launch can prove ownership. + expect(postMessageSpy).toHaveBeenCalledWith({ + type: "viewStateClaim", + viewStateId: "legacy-view", + viewStateClaim: rebound?.claimToken, + }) + + await provider.dispose() + + const reopened = createProvider() + await reopened["setViewStateId"]("legacy-view", rebound?.claimToken) + + expect(reopened["viewStateId"]).toBe("legacy-view") + expect(reopened["viewLocalState"]).toStrictEqual({}) + + await reopened.dispose() + }) + + test("still refuses an id a live view holds, even when the claim matches", async () => { + const owner = createProvider() + await owner["setViewStateId"]("shared-live-view") + await owner.saveViewState("mode", "architect") + const claim = storedEntries()["shared-live-view"]?.claimToken + + const sibling = createProvider() + + try { + await sibling["setViewStateId"]("shared-live-view", claim) + + // The live-instance guard runs first and keeps working: a second live view never + // shares a key with the view that holds it. + expect(sibling["viewStateId"]).toBe(sibling.viewId) + expect(sibling["viewLocalState"]).toStrictEqual({}) + expect(owner["viewStateId"]).toBe("shared-live-view") + } finally { + await sibling.dispose() + await owner.dispose() + } + }) + }) + + describe("view state persistence edge cases", () => { + it("should read viewStates from the ContextProxy cache when not fresh", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + await provider.contextProxy.setValue("viewStates", { "stable-sidebar-view": { mode: "architect" } }) + expect(provider["getPersistedViewStates"]()).toEqual({ "stable-sidebar-view": { mode: "architect" } }) + await provider.dispose() + }) + + it("should treat a corrupted non-object viewStates value as an empty map", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + // A string in storage is corrupt: the fresh-read guard must not spread it. + await mockContext.globalState.update("viewStates", "corrupted-storage-value") + expect(provider["getPersistedViewStates"]({ fresh: true })).toEqual({}) + await provider.dispose() + }) + + it("should merge saved fields, drop cleared fields and delete emptied entries", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + const logSpy = vi.spyOn(provider, "log") + const save = provider.saveViewState.bind(provider) as (key: string, value: unknown) => Promise + const states = () => mockContext.globalState.get>("viewStates") ?? {} + await provider["setViewStateId"]("stable-sidebar-view") + await provider.saveViewState("mode", "architect") + await provider.saveViewState("currentApiConfigName", "profile-a") + const merged = states()["stable-sidebar-view"] + expect(merged).toMatchObject({ mode: "architect", currentApiConfigName: "profile-a" }) + expect(logSpy).toHaveBeenCalledWith(expect.stringContaining("Saved mode for viewId")) + await save("mode", undefined) + expect(states()["stable-sidebar-view"]).toStrictEqual({ + currentApiConfigName: "profile-a", + updatedAt: expect.any(Number), + claimToken: expect.any(String), + }) + await save("mode", null) + expect(states()["stable-sidebar-view"]).not.toHaveProperty("mode") + await provider.saveViewState("mode", "architect") + await save("currentApiConfigName", undefined) + expect(states()["stable-sidebar-view"]).toStrictEqual({ + mode: "architect", + updatedAt: expect.any(Number), + claimToken: expect.any(String), + }) + await provider.saveViewState("currentApiConfigName", "profile-c") + await provider.saveViewState("mode", "architect") + expect(states()["stable-sidebar-view"]).toMatchObject({ + mode: "architect", + currentApiConfigName: "profile-c", + }) + await save("currentApiConfigName", null) + expect(states()["stable-sidebar-view"]).not.toHaveProperty("currentApiConfigName") + await save("mode", null) + expect(states()["stable-sidebar-view"]).toBeUndefined() + expect(provider["viewLocalState"]).toStrictEqual({}) // buffer ends fully cleared + await provider.dispose() + }) + + it("should rekey a pre-launch entry under the temporary id to the registered stable id", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + // Seed through the write path so this instance is the author of the entry under + // its temporary id; an entry authored by another session must not be adopted. + await provider["savePersistedViewState"]({ mode: "architect", updatedAt: 1 }) + await provider["setViewStateId"]("stable-sidebar-view") + expect(mockContext.globalState.get("viewStates")).toEqual({ + // The minted claim travels with the re-keyed entry, so the webview's token keeps working. + "stable-sidebar-view": { mode: "architect", updatedAt: 1, claimToken: expect.any(String) }, + }) + await provider.dispose() + }) + + it("should keep the stable entry and drop the temporary entry when both exist", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + // Author the temporary entry through the write path so this instance owns it, + // then add a stable entry that already exists in storage. + await provider["savePersistedViewState"]({ mode: "temp-mode", updatedAt: 1 }) + await provider.contextProxy.setValue("viewStates", { + [provider.viewId]: { mode: "temp-mode", updatedAt: 1 }, + "stable-sidebar-view": { mode: "stable-mode", updatedAt: 5, claimToken: "stable-claim" }, + }) + await provider["setViewStateId"]("stable-sidebar-view", "stable-claim") + expect(mockContext.globalState.get("viewStates")).toEqual({ + "stable-sidebar-view": { mode: "stable-mode", updatedAt: 5, claimToken: "stable-claim" }, + }) + await provider.dispose() + }) + + it("should prune by updatedAt regardless of insertion order", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + const states = Object.fromEntries( + Array.from({ length: 55 }, (_, index) => [ + `view-${index}`, + { mode: `mode-${index}`, updatedAt: (index * 7) % 55 }, + ]), + ) + const pruned = provider["prunePersistedViewStates"](states) + expect(Object.keys(pruned)).toHaveLength(50) + // view-1/view-54 survive the true newest-50 selection; view-8 (updatedAt 1) does not. + expect(pruned["view-1"]).toEqual({ mode: "mode-1", updatedAt: 7 }) + expect(pruned["view-54"]).toEqual({ mode: "mode-54", updatedAt: 48 }) + expect(pruned["view-8"]).toBeUndefined() + await provider.dispose() + }) + + it("should log a successful empty load when no persisted entry exists", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + const logSpy = vi.spyOn(provider, "log") + await provider["setViewStateId"]("stable-sidebar-view") + expect(provider["viewLocalState"]).toEqual({}) + expect(logSpy).toHaveBeenCalledWith(expect.stringContaining("Loaded state for viewId")) + await provider.dispose() + }) + + it("should keep the persisted profile name and log when the profile lookup fails", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + const logSpy = vi.spyOn(provider, "log") + // @ts-ignore - Replace providerSettingsManager with a failing test double. + provider.providerSettingsManager = { getProfile: vi.fn().mockRejectedValue(new Error("profile missing")) } + await provider.saveViewState("currentApiConfigName", "my-profile") + await provider["setViewStateId"]("stable-sidebar-view") + expect(provider["viewLocalState"].currentApiConfigName).toBe("my-profile") + expect(provider["viewLocalState"]).not.toHaveProperty("apiConfiguration") + expect(logSpy).toHaveBeenCalledWith(expect.stringContaining("Unable to resolve API profile 'my-profile'")) + await provider.dispose() + }) + + it("should discard a stale load when the viewStateId changes during the profile lookup", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + const logSpy = vi.spyOn(provider, "log") + // @ts-ignore - Replace providerSettingsManager with a test double that registers a newer id. + provider.providerSettingsManager = { + getProfile: vi.fn().mockImplementation(() => { + provider["viewStateId"] = "superseded-view" + return Promise.resolve({ name: "my-profile", apiProvider: providerIdentifiers.openrouter }) + }), + } + await provider.saveViewState("currentApiConfigName", "my-profile") + await provider["setViewStateId"]("stable-sidebar-view") + expect(provider["viewLocalState"]).not.toHaveProperty("apiConfiguration") + const staleMsg = expect.stringContaining("Discarding stale state for superseded view id") + expect(logSpy).toHaveBeenCalledWith(staleMsg) + await provider.dispose() + }) + + it("should not restore a persisted mode whose custom mode no longer exists", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + const logSpy = vi.spyOn(provider, "log") + // @ts-ignore - Replace customModesManager with a test double (no custom modes). + provider.customModesManager = { getCustomModes: vi.fn().mockResolvedValue([]), dispose: vi.fn() } + // The file-level modes mock resolves every slug to a mode; drop the pinned slug. + const modesModule = vi.mocked(await import("../../../shared/modes")) + const originalMode = modesModule.getModeBySlug("code") + modesModule.getModeBySlug.mockImplementation(((slug: string) => + slug === "deleted-custom-mode" ? undefined : originalMode) as typeof modesModule.getModeBySlug) + try { + await provider["setViewStateId"]("stable-sidebar-view") + await provider.saveViewState("mode", "deleted-custom-mode") + // Reload the persisted entry: the custom mode was deleted in the meantime. + await provider["loadViewState"]() + // The stale slug must not be restored into the buffer. + expect(provider["viewLocalState"]).not.toHaveProperty("mode") + expect(logSpy).toHaveBeenCalledWith( + expect.stringContaining('Ignoring unknown persisted mode "deleted-custom-mode"'), + ) + } finally { + modesModule.getModeBySlug.mockReturnValue(originalMode) + } + await provider.dispose() + }) + + it("should keep every persisted field authoritative when the load is untouched", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + const { getProfile: getProfileSpy, resolveProfile } = stallProviderSettingsProfile(provider) + // @ts-ignore - Replace customModesManager with a test double (no custom modes). + provider.customModesManager = { getCustomModes: vi.fn().mockResolvedValue([]), dispose: vi.fn() } + await provider.saveViewState("mode", "code") + await provider.saveViewState("currentApiConfigName", "cfg-a") + const load = provider["setViewStateId"]("stable-sidebar-view") + + // Let the stalled lookup begin so the in-flight mutation and the resolver + // target the pending promise rather than the initial no-op. + await vi.waitFor(() => expect(getProfileSpy).toHaveBeenCalledTimes(1)) + // No mutation while the lookup is in flight: the persisted values must win. + resolveProfile({ name: "cfg-a", apiProvider: providerIdentifiers.openrouter, openRouterModelId: "model-x" }) + await load + + expect(provider["viewLocalState"]).toEqual({ + mode: "code", + currentApiConfigName: "cfg-a", + apiConfiguration: { apiProvider: providerIdentifiers.openrouter, openRouterModelId: "model-x" }, + }) + await provider.dispose() + }) + }) + + describe("saveViewState", () => { + it("should update viewLocalState and persist mode through registered viewStates", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + + const contextProxySpy = vi.spyOn(provider.contextProxy, "setValue") + await provider["setViewStateId"]("stable-sidebar-view") + + await provider.saveViewState("mode", "architect") + + expect(provider["viewLocalState"].mode).toBe("architect") + expect(provider.contextProxy.getValue("viewStates")).toMatchObject({ + "stable-sidebar-view": { mode: "architect" }, + }) + expect(contextProxySpy).toHaveBeenCalledWith( + "viewStates", + expect.objectContaining({ + "stable-sidebar-view": expect.objectContaining({ + mode: "architect", + updatedAt: expect.any(Number), + }), + }), + ) + expect(contextProxySpy).not.toHaveBeenCalledWith("__view_state_stable-sidebar-view_mode", expect.anything()) + + await provider.dispose() + }) + + it("should update viewLocalState and persist currentApiConfigName through registered viewStates", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + + await provider["setViewStateId"]("stable-sidebar-view") + await provider.saveViewState("currentApiConfigName", "my-profile") + + expect(provider["viewLocalState"].currentApiConfigName).toBe("my-profile") + expect(provider.contextProxy.getValue("viewStates")).toMatchObject({ + "stable-sidebar-view": { currentApiConfigName: "my-profile" }, + }) + + await provider.dispose() + }) + + it("should update viewLocalState for apiConfiguration without persisting provider settings or secrets", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + + const testApiConfig = { + apiProvider: providerIdentifiers.openrouter, + openRouterModelId: "claude-3.5-sonnet", + openRouterApiKey: "secret-key", + } + + await provider["setViewStateId"]("stable-sidebar-view") + await provider.saveViewState("apiConfiguration", testApiConfig) + + expect(provider["viewLocalState"].apiConfiguration).toEqual(testApiConfig) + expect(provider.contextProxy.getValue("viewStates")).toBeUndefined() + + await provider.dispose() + }) + + it("should clear local override when saveViewState receives undefined", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + + await provider.saveViewState("mode", "architect") + expect(provider["viewLocalState"].mode).toBe("architect") + + await provider.saveViewState("mode", undefined) + + expect(Object.prototype.hasOwnProperty.call(provider["viewLocalState"], "mode")).toBe(false) + + await provider.dispose() + }) + + it("should clear the currentApiConfigName override when saveViewState receives undefined", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + + await provider.saveViewState("currentApiConfigName", "my-profile") + expect(provider["viewLocalState"].currentApiConfigName).toBe("my-profile") + + await provider.saveViewState("currentApiConfigName", undefined) + + expect(Object.prototype.hasOwnProperty.call(provider["viewLocalState"], "currentApiConfigName")).toBe(false) + + await provider.dispose() + }) + + it("should not update viewLocalState when durable view-state persistence fails", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + vi.spyOn(provider.contextProxy, "setValue").mockRejectedValueOnce(new Error("persist failed")) + + await provider["setViewStateId"]("stable-sidebar-view") + + await expect(provider.saveViewState("mode", "architect")).rejects.toThrow("persist failed") + expect(provider["viewLocalState"]).not.toHaveProperty("mode") + expect(provider.contextProxy.getValue("viewStates")).toBeUndefined() + + await provider.dispose() + }) + + it("should merge concurrent persisted updates from separate provider instances without lost viewStates", async () => { + const provider1 = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + + new WebviewFocusTracker(), + ) + const provider2 = new ClineProvider( + mockContext, + mockOutputChannel, + "editor", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + + await provider1["setViewStateId"]("stable-sidebar-view") + await provider2["setViewStateId"]("stable-editor-view") + + await Promise.all([ + provider1.saveViewState("mode", "architect"), + provider2.saveViewState("currentApiConfigName", "editor-profile"), + ]) + + expect(mockContext.globalState.get("viewStates")).toMatchObject({ + "stable-sidebar-view": { mode: "architect" }, + "stable-editor-view": { currentApiConfigName: "editor-profile" }, + }) + + await provider1.dispose() + await provider2.dispose() + }) + }) + + describe("loadViewState", () => { + it("should keep viewLocalState empty when no stable per-view values exist", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + + await vi.waitFor(() => { + expect(provider["viewLocalState"]).toEqual({}) + }) + + const state = await provider.getState() + // No per-view entry exists and the proxy's global-state cache is empty + // (initialize() is never called in this fixture; only "taskHistory" passes + // through to the context store), so getState() falls back to the shared + // defaults: mode "code" (defaultModeSlug) and currentApiConfigName "default". + expect(state.mode).toBe("code") + expect(state.currentApiConfigName).toBe("default") + + await provider.dispose() + }) + + it("should log and keep existing viewLocalState when loadViewState fails", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + const logSpy = vi.spyOn(provider, "log") + + // Register a stable id so the load is not skipped by the ownership guard: + // only entries this instance authored are loaded under a temporary name. + await provider["setViewStateId"]("stable-sidebar-view") + + provider["viewLocalState"] = { mode: "architect" } + vi.spyOn(provider.contextProxy, "getValue").mockImplementation(() => { + throw new Error("load failed") + }) + + await provider["loadViewState"]() + + expect(provider["viewLocalState"].mode).toBe("architect") + expect(logSpy).toHaveBeenCalledWith(expect.stringContaining("Error loading state")) + + await provider.dispose() + }) + }) + + describe("persisted view state pruning", () => { + it("should keep the newest 50 persisted view states", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + const states = Object.fromEntries( + Array.from({ length: 55 }, (_, index) => [ + `view-${index}`, + { mode: `mode-${index}`, updatedAt: index }, + ]), + ) + + const pruned = provider["prunePersistedViewStates"](states) + + expect(Object.keys(pruned)).toHaveLength(50) + expect(pruned["view-54"]).toEqual({ mode: "mode-54", updatedAt: 54 }) + expect(pruned["view-5"]).toEqual({ mode: "mode-5", updatedAt: 5 }) + expect(pruned["view-4"]).toBeUndefined() + + await provider.dispose() + }) + }) + + it("should merge concurrent persisted updates from separate provider instances without lost viewStates", async () => { + const provider1 = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + + new WebviewFocusTracker(), + ) + const provider2 = new ClineProvider( + mockContext, + mockOutputChannel, + "editor", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + + await provider1["setViewStateId"]("stable-sidebar-view") + await provider2["setViewStateId"]("stable-editor-view") + + await Promise.all([ + provider1.saveViewState("mode", "architect"), + provider2.saveViewState("currentApiConfigName", "editor-profile"), + ]) + + expect(mockContext.globalState.get("viewStates")).toMatchObject({ + "stable-sidebar-view": { mode: "architect" }, + "stable-editor-view": { currentApiConfigName: "editor-profile" }, + }) + + await provider1.dispose() + await provider2.dispose() + }) }) describe("webviewMessageHandler no-floating-promises coverage", () => { From f560872c380d475393ba7206076d8025f7b79b6c Mon Sep 17 00:00:00 2001 From: easonLiangWorldedtech <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Thu, 29 Oct 2026 20:59:01 +0800 Subject: [PATCH 03/27] chore: untrack generated husky hooks --- .husky/_/post-checkout | 3 --- .husky/_/post-commit | 3 --- .husky/_/post-merge | 3 --- .husky/_/pre-push | 3 --- .husky/pre-commit | 26 -------------------------- .husky/pre-push | 42 ------------------------------------------ 6 files changed, 80 deletions(-) delete mode 100644 .husky/_/post-checkout delete mode 100644 .husky/_/post-commit delete mode 100644 .husky/_/post-merge delete mode 100644 .husky/_/pre-push delete mode 100644 .husky/pre-commit delete mode 100644 .husky/pre-push diff --git a/.husky/_/post-checkout b/.husky/_/post-checkout deleted file mode 100644 index 5abf8ed93f..0000000000 --- a/.husky/_/post-checkout +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -command -v git-lfs >/dev/null 2>&1 || { printf >&2 "\n%s\n\n" "This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-checkout' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks')."; exit 2; } -git lfs post-checkout "$@" diff --git a/.husky/_/post-commit b/.husky/_/post-commit deleted file mode 100644 index b8b76c2c42..0000000000 --- a/.husky/_/post-commit +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -command -v git-lfs >/dev/null 2>&1 || { printf >&2 "\n%s\n\n" "This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-commit' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks')."; exit 2; } -git lfs post-commit "$@" diff --git a/.husky/_/post-merge b/.husky/_/post-merge deleted file mode 100644 index 726f909891..0000000000 --- a/.husky/_/post-merge +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -command -v git-lfs >/dev/null 2>&1 || { printf >&2 "\n%s\n\n" "This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-merge' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks')."; exit 2; } -git lfs post-merge "$@" diff --git a/.husky/_/pre-push b/.husky/_/pre-push deleted file mode 100644 index 5f26dc4552..0000000000 --- a/.husky/_/pre-push +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -command -v git-lfs >/dev/null 2>&1 || { printf >&2 "\n%s\n\n" "This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'pre-push' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks')."; exit 2; } -git lfs pre-push "$@" diff --git a/.husky/pre-commit b/.husky/pre-commit deleted file mode 100644 index f8f420dac7..0000000000 --- a/.husky/pre-commit +++ /dev/null @@ -1,26 +0,0 @@ -branch="$(git rev-parse --abbrev-ref HEAD)" - -if [ "$branch" = "main" ]; then - echo "You can't commit directly to main - please check out a branch." - exit 1 -fi - -# Detect if running on Windows and use pnpm.cmd, otherwise use pnpm. -if [ "$OS" = "Windows_NT" ]; then - pnpm_cmd="pnpm.cmd" -else - if command -v pnpm >/dev/null 2>&1; then - pnpm_cmd="pnpm" - else - pnpm_cmd="npx pnpm" - fi -fi - -# Detect if running on Windows and use npx.cmd, otherwise use npx. -if [ "$OS" = "Windows_NT" ]; then - npx_cmd="npx.cmd" -else - npx_cmd="npx" -fi - -$npx_cmd lint-staged diff --git a/.husky/pre-push b/.husky/pre-push deleted file mode 100644 index 4cf91d9580..0000000000 --- a/.husky/pre-push +++ /dev/null @@ -1,42 +0,0 @@ -branch="$(git rev-parse --abbrev-ref HEAD)" - -if [ "$branch" = "main" ]; then - echo "You can't push directly to main - please check out a branch." - exit 1 -fi - -# Detect if running on Windows and use pnpm.cmd, otherwise use pnpm. -if [ "$OS" = "Windows_NT" ]; then - pnpm_cmd="pnpm.cmd" -else - if command -v pnpm >/dev/null 2>&1; then - pnpm_cmd="pnpm" - else - pnpm_cmd="npx pnpm" - fi -fi - -$pnpm_cmd run check-types - -# Use dotenvx to securely load .env.local and run commands that depend on it -if [ -f ".env.local" ]; then - # Check if RUN_TESTS_ON_PUSH is set to true and run tests with dotenvx - if npx dotenvx get RUN_TESTS_ON_PUSH -f .env.local 2>/dev/null | grep -q "^true$"; then - npx dotenvx run -f .env.local -- $pnpm_cmd run test - fi -else - # Fallback: run tests if RUN_TESTS_ON_PUSH is set in regular environment - if [ "$RUN_TESTS_ON_PUSH" = "true" ]; then - $pnpm_cmd run test - fi -fi - -# Check for new changesets. -NEW_CHANGESETS=$(find .changeset -name "*.md" ! -name "README.md" | wc -l | tr -d ' ') -echo "Changeset files: $NEW_CHANGESETS" - -if [ "$NEW_CHANGESETS" = "0" ]; then - echo "-------------------------------------------------------------------------------------" - echo "Changes detected. Please run 'pnpm changeset' to create a changeset if applicable." - echo "-------------------------------------------------------------------------------------" -fi From 634099884ec54f71d4d54743f5b44d7367b0f528 Mon Sep 17 00:00:00 2001 From: easonLiangWorldedtech <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Thu, 29 Oct 2026 20:59:19 +0800 Subject: [PATCH 04/27] chore: restore main tracked husky hooks --- .husky/pre-commit | 26 ++++++++++++++++++++++++++ .husky/pre-push | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 .husky/pre-commit create mode 100644 .husky/pre-push diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 0000000000..f8f420dac7 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,26 @@ +branch="$(git rev-parse --abbrev-ref HEAD)" + +if [ "$branch" = "main" ]; then + echo "You can't commit directly to main - please check out a branch." + exit 1 +fi + +# Detect if running on Windows and use pnpm.cmd, otherwise use pnpm. +if [ "$OS" = "Windows_NT" ]; then + pnpm_cmd="pnpm.cmd" +else + if command -v pnpm >/dev/null 2>&1; then + pnpm_cmd="pnpm" + else + pnpm_cmd="npx pnpm" + fi +fi + +# Detect if running on Windows and use npx.cmd, otherwise use npx. +if [ "$OS" = "Windows_NT" ]; then + npx_cmd="npx.cmd" +else + npx_cmd="npx" +fi + +$npx_cmd lint-staged diff --git a/.husky/pre-push b/.husky/pre-push new file mode 100644 index 0000000000..4cf91d9580 --- /dev/null +++ b/.husky/pre-push @@ -0,0 +1,42 @@ +branch="$(git rev-parse --abbrev-ref HEAD)" + +if [ "$branch" = "main" ]; then + echo "You can't push directly to main - please check out a branch." + exit 1 +fi + +# Detect if running on Windows and use pnpm.cmd, otherwise use pnpm. +if [ "$OS" = "Windows_NT" ]; then + pnpm_cmd="pnpm.cmd" +else + if command -v pnpm >/dev/null 2>&1; then + pnpm_cmd="pnpm" + else + pnpm_cmd="npx pnpm" + fi +fi + +$pnpm_cmd run check-types + +# Use dotenvx to securely load .env.local and run commands that depend on it +if [ -f ".env.local" ]; then + # Check if RUN_TESTS_ON_PUSH is set to true and run tests with dotenvx + if npx dotenvx get RUN_TESTS_ON_PUSH -f .env.local 2>/dev/null | grep -q "^true$"; then + npx dotenvx run -f .env.local -- $pnpm_cmd run test + fi +else + # Fallback: run tests if RUN_TESTS_ON_PUSH is set in regular environment + if [ "$RUN_TESTS_ON_PUSH" = "true" ]; then + $pnpm_cmd run test + fi +fi + +# Check for new changesets. +NEW_CHANGESETS=$(find .changeset -name "*.md" ! -name "README.md" | wc -l | tr -d ' ') +echo "Changeset files: $NEW_CHANGESETS" + +if [ "$NEW_CHANGESETS" = "0" ]; then + echo "-------------------------------------------------------------------------------------" + echo "Changes detected. Please run 'pnpm changeset' to create a changeset if applicable." + echo "-------------------------------------------------------------------------------------" +fi From 98490187ee0429811c7f966482fc7ca3eec92c59 Mon Sep 17 00:00:00 2001 From: easonLiangWorldedtech <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Thu, 29 Oct 2026 21:01:54 +0800 Subject: [PATCH 05/27] feat(webview): view-local buffer reads and setValue persistence (N3) Split unit N3: setValue/getValues view-local buffer and failed-write rollback on top of N2; setValues/reset/ack/history remain for N4/N5. --- src/core/webview/ClineProvider.ts | 28 +++- .../webview/__tests__/ClineProvider.spec.ts | 122 ++++++++++++++++++ 2 files changed, 149 insertions(+), 1 deletion(-) diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index 9d812cd8e9..f3d4a0d637 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -3918,15 +3918,26 @@ export class ClineProvider private getGlobalState(key: K) { return this.contextProxy.getValue(key) } + public async setValue(key: K, value: RooCodeSettings[K]) { + const previousSharedValues = { [key]: this.contextProxy.getValue(key) } as RooCodeSettings await this.contextProxy.setValue(key, value) + try { + await this._saveViewLocalStateFromMutation({ [key]: value }) + } catch (error) { + // The per-view record did not land: restore the prior shared value so the two + // persistence layers cannot diverge, then surface the original failure. + await this._restoreSharedValuesAfterFailedViewWrite(previousSharedValues) + throw error + } } public getValue(key: K) { return this.contextProxy.getValue(key) } + public getValues() { - return this.contextProxy.getValues() + return { ...this.contextProxy.getValues(), ...this.viewLocalState } } public async setValues(values: RooCodeSettings) { await this.contextProxy.setValues(values) @@ -5353,4 +5364,19 @@ export class ClineProvider } } } + + /** + * Restore shared values captured before a setter wrote them, used when the paired + * per-view persistence failed so the shared store cannot move ahead of the per-view + * record. A failed rollback is logged; the original failure is what callers see. + */ + private async _restoreSharedValuesAfterFailedViewWrite(previous: RooCodeSettings): Promise { + try { + await this.contextProxy.setValues(previous) + } catch (rollbackError) { + this.log( + `[ClineProvider] Shared-state rollback after failed per-view write failed: ${rollbackError instanceof Error ? rollbackError.message : String(rollbackError)}`, + ) + } + } } diff --git a/src/core/webview/__tests__/ClineProvider.spec.ts b/src/core/webview/__tests__/ClineProvider.spec.ts index 4bb3e49635..6356835cc9 100644 --- a/src/core/webview/__tests__/ClineProvider.spec.ts +++ b/src/core/webview/__tests__/ClineProvider.spec.ts @@ -447,6 +447,10 @@ function stallProviderSettingsProfile(provider: ClineProvider) { return { getProfile: getProfileSpy, resolveProfile: (value: StalledProfile) => resolveProfile(value) } } +function persistedViewStateClaim(context: vscode.ExtensionContext, viewStateId: string): string | undefined { + return context.globalState.get("viewStates")?.[viewStateId]?.claimToken +} + describe("ClineProvider", () => { beforeAll(() => { vi.mocked(Task).mockImplementation(function (options: any) { @@ -4415,6 +4419,124 @@ describe("ClineProvider", () => { await provider1.dispose() await provider2.dispose() }) + + describe("view state persistence edge cases", () => { + it("should load persisted mode, profile name and resolved profile into viewLocalState", async () => { + const writer = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + await writer["setViewStateId"]("shared-view") + await writer.saveViewState("mode", "architect") + await writer.saveViewState("currentApiConfigName", "my-profile") + + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "editor", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + const logSpy = vi.spyOn(provider, "log") + const getProfileSpy = vi.fn().mockResolvedValue({ + name: "my-profile", + apiProvider: providerIdentifiers.openrouter, + openRouterModelId: "model-x", + }) + // @ts-ignore - Replace providerSettingsManager with a test double for the profile lookup. + provider.providerSettingsManager = { getProfile: getProfileSpy } + // The ownership check requires the writer to release the id before the + // next view adopts it; the durable entry it wrote stays in storage. + await writer.dispose() + + await provider.contextProxy.setValue( + "viewStates", + mockContext.globalState.get("viewStates"), + ) + // The host-minted claim the writer received is what lets this view re-adopt its entry. + await provider["setViewStateId"]("shared-view", persistedViewStateClaim(mockContext, "shared-view")) + expect(provider["viewLocalState"]).toEqual({ + mode: "architect", + currentApiConfigName: "my-profile", + apiConfiguration: { apiProvider: providerIdentifiers.openrouter, openRouterModelId: "model-x" }, + }) + expect(getProfileSpy).toHaveBeenCalledWith({ name: "my-profile" }) + expect(logSpy).toHaveBeenCalledWith(expect.stringContaining("Loaded state for viewId")) + await provider.dispose() + }) + + it("should apply setValue mutations to global state and keep or clear the right buffer fields", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + const apiConfiguration = { apiProvider: providerIdentifiers.openrouter } + await provider.saveViewState("mode", "architect") + await provider.saveViewState("currentApiConfigName", "my-profile") + await provider.saveViewState("apiConfiguration", apiConfiguration) + // A mutation of an unrelated key reaches global state without dropping buffered fields. + await provider.setValue("writeDelayMs", 500) + expect(mockContext.globalState.get("writeDelayMs")).toBe(500) + expect(provider.getValues().writeDelayMs).toBe(500) + expect(provider["viewLocalState"].mode).toBe("architect") + expect(provider["viewLocalState"].currentApiConfigName).toBe("my-profile") + expect(provider["viewLocalState"].apiConfiguration).toBe(apiConfiguration) + await provider.setValue("mode", undefined) + expect(provider["viewLocalState"]).not.toHaveProperty("mode") + await provider.setValue("currentApiConfigName", undefined) + expect(provider["viewLocalState"]).not.toHaveProperty("currentApiConfigName") + await provider.dispose() + }) + + it("should remove the buffered apiConfiguration when it is cleared", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + const save = provider.saveViewState.bind(provider) as (key: string, value: unknown) => Promise + await provider.saveViewState("apiConfiguration", { apiProvider: providerIdentifiers.openrouter }) + await provider.saveViewState("apiConfiguration", undefined) + expect(provider["viewLocalState"]).not.toHaveProperty("apiConfiguration") + await provider.saveViewState("apiConfiguration", { apiProvider: providerIdentifiers.openrouter }) + await save("apiConfiguration", null) + expect(provider["viewLocalState"]).not.toHaveProperty("apiConfiguration") + await provider.dispose() + }) + + it("should roll back the shared write when setValue per-view persistence fails", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + await provider.contextProxy.setValue("mode", "architect") + const originalUpdate = mockContext.globalState.update + mockContext.globalState.update = vi.fn().mockImplementation((key: string) => { + if (key === "viewStates") { + return Promise.reject(new Error("storage unavailable")) + } + return Promise.resolve() + }) + + await expect(provider.setValue("mode", "code")).rejects.toThrow("storage unavailable") + // The shared store must not move ahead of the per-view record that failed. + expect(provider.getValue("mode")).toBe("architect") + + mockContext.globalState.update = originalUpdate + await provider.dispose() + }) + }) }) describe("webviewMessageHandler no-floating-promises coverage", () => { From 7b610a14dde94204bb0f913632bf289eed7395a0 Mon Sep 17 00:00:00 2001 From: easonLiangWorldedtech <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Thu, 29 Oct 2026 21:03:34 +0800 Subject: [PATCH 06/27] feat(webview): setValues batch persistence and reset cleanup (N4) Split unit N4: setValues per-view persistence with failed-write rollback and resetState clears buffer/persisted entry on top of N3. --- .husky/_/post-checkout | 3 + .husky/_/post-commit | 3 + .husky/_/post-merge | 3 + .husky/_/pre-push | 3 + src/core/webview/ClineProvider.ts | 39 +++++- .../webview/__tests__/ClineProvider.spec.ts | 132 ++++++++++++++++++ 6 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 .husky/_/post-checkout create mode 100644 .husky/_/post-commit create mode 100644 .husky/_/post-merge create mode 100644 .husky/_/pre-push diff --git a/.husky/_/post-checkout b/.husky/_/post-checkout new file mode 100644 index 0000000000..5abf8ed93f --- /dev/null +++ b/.husky/_/post-checkout @@ -0,0 +1,3 @@ +#!/bin/sh +command -v git-lfs >/dev/null 2>&1 || { printf >&2 "\n%s\n\n" "This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-checkout' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks')."; exit 2; } +git lfs post-checkout "$@" diff --git a/.husky/_/post-commit b/.husky/_/post-commit new file mode 100644 index 0000000000..b8b76c2c42 --- /dev/null +++ b/.husky/_/post-commit @@ -0,0 +1,3 @@ +#!/bin/sh +command -v git-lfs >/dev/null 2>&1 || { printf >&2 "\n%s\n\n" "This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-commit' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks')."; exit 2; } +git lfs post-commit "$@" diff --git a/.husky/_/post-merge b/.husky/_/post-merge new file mode 100644 index 0000000000..726f909891 --- /dev/null +++ b/.husky/_/post-merge @@ -0,0 +1,3 @@ +#!/bin/sh +command -v git-lfs >/dev/null 2>&1 || { printf >&2 "\n%s\n\n" "This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-merge' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks')."; exit 2; } +git lfs post-merge "$@" diff --git a/.husky/_/pre-push b/.husky/_/pre-push new file mode 100644 index 0000000000..5f26dc4552 --- /dev/null +++ b/.husky/_/pre-push @@ -0,0 +1,3 @@ +#!/bin/sh +command -v git-lfs >/dev/null 2>&1 || { printf >&2 "\n%s\n\n" "This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'pre-push' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks')."; exit 2; } +git lfs pre-push "$@" diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index f3d4a0d637..633f1a83e1 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -3939,8 +3939,34 @@ export class ClineProvider public getValues() { return { ...this.contextProxy.getValues(), ...this.viewLocalState } } + public async setValues(values: RooCodeSettings) { - await this.contextProxy.setValues(values) + const sanitizedValues = { ...values } + + if (sanitizedValues.mode !== undefined) { + // An unknown or non-string mode (e.g. from an API payload) must not be persisted: + // a new Task would read it from getState() and persist it into task history. + if ( + typeof sanitizedValues.mode !== "string" || + !getModeBySlug(sanitizedValues.mode, await this.customModesManager.getCustomModes()) + ) { + this.log(`[ClineProvider#setValues] Ignoring invalid mode "${String(sanitizedValues.mode)}"`) + delete sanitizedValues.mode + } + } + + const previousSharedValues = Object.fromEntries( + Object.keys(sanitizedValues).map((key) => [key, this.contextProxy.getValue(key as keyof RooCodeSettings)]), + ) as RooCodeSettings + await this.contextProxy.setValues(sanitizedValues) + try { + await this._saveViewLocalStateFromMutation(sanitizedValues) + } catch (error) { + // The per-view record did not land: restore the prior shared values so the two + // persistence layers cannot diverge, then surface the original failure. + await this._restoreSharedValuesAfterFailedViewWrite(previousSharedValues) + throw error + } } /** @@ -3983,6 +4009,9 @@ export class ClineProvider private _clearViewLocalState(): void { this.viewLocalState = {} } + + // dev + async resetState() { const answer = await vscode.window.showInformationMessage( t("common:confirmation.reset_state"), @@ -4007,6 +4036,14 @@ export class ClineProvider } await this.contextProxy.resetAllState() + + // Clear view-local state cache so getState() falls back to ContextProxy defaults. + this._clearViewLocalState() + + // Clear this view's persisted entry too, so the reset selections are not + // re-applied from the durable viewStates pin after a reload. + await this.clearPersistedViewState() + await this.providerSettingsManager.resetAllConfigs() await this.customModesManager.resetCustomModes() await this.removeClineFromStack() diff --git a/src/core/webview/__tests__/ClineProvider.spec.ts b/src/core/webview/__tests__/ClineProvider.spec.ts index 6356835cc9..8841092211 100644 --- a/src/core/webview/__tests__/ClineProvider.spec.ts +++ b/src/core/webview/__tests__/ClineProvider.spec.ts @@ -33,6 +33,7 @@ import { WorkspaceIndexingEnablementManager } from "../../../services/code-index import { Task, TaskOptions } from "../../task/Task" import { safeWriteJson } from "../../../utils/safeWriteJson" +import { t } from "../../../i18n" import { ClineProvider } from "../ClineProvider" import { webviewMessageHandler } from "../webviewMessageHandler" import { Terminal } from "../../../integrations/terminal/Terminal" @@ -4537,6 +4538,137 @@ describe("ClineProvider", () => { await provider.dispose() }) }) + + it("should persist known modes and reject unknown or non-string modes", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + const logSpy = vi.spyOn(provider, "log") + // @ts-ignore - Replace customModesManager with a test double (no custom modes). + provider.customModesManager = { getCustomModes: vi.fn().mockResolvedValue([]), dispose: vi.fn() } + // The file-level modes mock resolves every slug to a mode; narrow it to the slugs under test. + const modesModule = vi.mocked(await import("../../../shared/modes")) + const originalMode = modesModule.getModeBySlug("code") + modesModule.getModeBySlug.mockImplementation(((slug: string) => + slug === "refactor" ? { slug } : undefined) as typeof modesModule.getModeBySlug) + try { + await provider.setValues({ mode: "refactor" }) + expect(mockContext.globalState.get("mode")).toBe("refactor") + expect(provider["viewLocalState"].mode).toBe("refactor") + await provider.setValues({ mode: "bogus-mode" }) + expect(logSpy).toHaveBeenCalledWith(expect.stringContaining('Ignoring invalid mode "bogus-mode"')) + expect(mockContext.globalState.get("mode")).toBe("refactor") + expect(provider["viewLocalState"].mode).toBe("refactor") + // A non-string mode must be rejected before persistence; Object.assign + // keeps this a single structural assertion, so it must not reach global + // state or the buffer. + await provider.setValues(Object.assign({} as RooCodeSettings, { mode: 42 })) + expect(logSpy).toHaveBeenCalledWith(expect.stringContaining('Ignoring invalid mode "42"')) + expect(mockContext.globalState.get("mode")).toBe("refactor") + expect(provider["viewLocalState"].mode).toBe("refactor") + } finally { + modesModule.getModeBySlug.mockReturnValue(originalMode) + } + await provider.dispose() + }) + + it("should build the buffered apiConfiguration from provider settings keys", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + provider["viewLocalState"] = { apiConfiguration: { openRouterApiKey: "key-1" } } + await provider.setValues({ apiProvider: providerIdentifiers.openrouter }) + expect(provider["viewLocalState"].apiConfiguration).toStrictEqual({ + apiProvider: providerIdentifiers.openrouter, + }) + await provider.setValues({ openRouterModelId: "model-x" }) + expect(provider["viewLocalState"].apiConfiguration).toEqual({ + apiProvider: providerIdentifiers.openrouter, + openRouterModelId: "model-x", + }) + await provider.dispose() + }) + + it("should remove the buffered apiConfiguration when it is cleared", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + const save = provider.saveViewState.bind(provider) as (key: string, value: unknown) => Promise + await provider.saveViewState("apiConfiguration", { apiProvider: providerIdentifiers.openrouter }) + await provider.saveViewState("apiConfiguration", undefined) + expect(provider["viewLocalState"]).not.toHaveProperty("apiConfiguration") + await provider.saveViewState("apiConfiguration", { apiProvider: providerIdentifiers.openrouter }) + await save("apiConfiguration", null) + expect(provider["viewLocalState"]).not.toHaveProperty("apiConfiguration") + await provider.dispose() + }) + + it("should clear viewLocalState and the persisted entry when resetting state", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + vi.spyOn(provider, "postStateToWebview").mockResolvedValue(undefined) + // @ts-ignore - Replace customModesManager with a test double (the real reset writes to disk). + provider.customModesManager = { resetCustomModes: vi.fn().mockResolvedValue(undefined), dispose: vi.fn() } + // The modal answer is a string label; the last-typed vscode overload expects a + // MessageItem. A double assertion is the last-resort cast here (AGENTS.md): the + // production path compares the answer against the string label directly, so the + // runtime value must stay a string and cannot be a structural MessageItem double. + vi.mocked(vscode.window.showInformationMessage).mockResolvedValue( + t("common:answers.yes") as unknown as vscode.MessageItem, + ) + await provider["setViewStateId"]("stable-sidebar-view") + await provider.saveViewState("mode", "architect") + await provider.resetState() + expect(provider["viewLocalState"]).toEqual({}) + expect(mockContext.globalState.get("viewStates")).toEqual({}) + await provider.dispose() + }) + + it("should roll back the shared writes when setValues per-view persistence fails", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + await provider.contextProxy.setValue("mode", "architect") + await provider.contextProxy.setValue("currentApiConfigName", "current-config") + const originalUpdate = mockContext.globalState.update + mockContext.globalState.update = vi.fn().mockImplementation((key: string) => { + if (key === "viewStates") { + return Promise.reject(new Error("storage unavailable")) + } + return Promise.resolve() + }) + + await expect(provider.setValues({ mode: "code", currentApiConfigName: "other-config" })).rejects.toThrow( + "storage unavailable", + ) + expect(provider.getValue("mode")).toBe("architect") + expect(provider.getValue("currentApiConfigName")).toBe("current-config") + expect(provider["viewLocalState"].mode).toBeUndefined() + + mockContext.globalState.update = originalUpdate + await provider.dispose() + }) }) describe("webviewMessageHandler no-floating-promises coverage", () => { From 7de336e4ddced8d578ff4d8df2c464bf9bb76043 Mon Sep 17 00:00:00 2001 From: easonLiangWorldedtech <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Thu, 29 Oct 2026 21:03:43 +0800 Subject: [PATCH 07/27] chore: untrack generated husky hooks --- .husky/_/post-checkout | 3 --- .husky/_/post-commit | 3 --- .husky/_/post-merge | 3 --- .husky/_/pre-push | 3 --- .husky/pre-commit | 26 -------------------------- .husky/pre-push | 42 ------------------------------------------ 6 files changed, 80 deletions(-) delete mode 100644 .husky/_/post-checkout delete mode 100644 .husky/_/post-commit delete mode 100644 .husky/_/post-merge delete mode 100644 .husky/_/pre-push delete mode 100644 .husky/pre-commit delete mode 100644 .husky/pre-push diff --git a/.husky/_/post-checkout b/.husky/_/post-checkout deleted file mode 100644 index 5abf8ed93f..0000000000 --- a/.husky/_/post-checkout +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -command -v git-lfs >/dev/null 2>&1 || { printf >&2 "\n%s\n\n" "This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-checkout' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks')."; exit 2; } -git lfs post-checkout "$@" diff --git a/.husky/_/post-commit b/.husky/_/post-commit deleted file mode 100644 index b8b76c2c42..0000000000 --- a/.husky/_/post-commit +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -command -v git-lfs >/dev/null 2>&1 || { printf >&2 "\n%s\n\n" "This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-commit' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks')."; exit 2; } -git lfs post-commit "$@" diff --git a/.husky/_/post-merge b/.husky/_/post-merge deleted file mode 100644 index 726f909891..0000000000 --- a/.husky/_/post-merge +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -command -v git-lfs >/dev/null 2>&1 || { printf >&2 "\n%s\n\n" "This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-merge' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks')."; exit 2; } -git lfs post-merge "$@" diff --git a/.husky/_/pre-push b/.husky/_/pre-push deleted file mode 100644 index 5f26dc4552..0000000000 --- a/.husky/_/pre-push +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -command -v git-lfs >/dev/null 2>&1 || { printf >&2 "\n%s\n\n" "This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'pre-push' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks')."; exit 2; } -git lfs pre-push "$@" diff --git a/.husky/pre-commit b/.husky/pre-commit deleted file mode 100644 index f8f420dac7..0000000000 --- a/.husky/pre-commit +++ /dev/null @@ -1,26 +0,0 @@ -branch="$(git rev-parse --abbrev-ref HEAD)" - -if [ "$branch" = "main" ]; then - echo "You can't commit directly to main - please check out a branch." - exit 1 -fi - -# Detect if running on Windows and use pnpm.cmd, otherwise use pnpm. -if [ "$OS" = "Windows_NT" ]; then - pnpm_cmd="pnpm.cmd" -else - if command -v pnpm >/dev/null 2>&1; then - pnpm_cmd="pnpm" - else - pnpm_cmd="npx pnpm" - fi -fi - -# Detect if running on Windows and use npx.cmd, otherwise use npx. -if [ "$OS" = "Windows_NT" ]; then - npx_cmd="npx.cmd" -else - npx_cmd="npx" -fi - -$npx_cmd lint-staged diff --git a/.husky/pre-push b/.husky/pre-push deleted file mode 100644 index 4cf91d9580..0000000000 --- a/.husky/pre-push +++ /dev/null @@ -1,42 +0,0 @@ -branch="$(git rev-parse --abbrev-ref HEAD)" - -if [ "$branch" = "main" ]; then - echo "You can't push directly to main - please check out a branch." - exit 1 -fi - -# Detect if running on Windows and use pnpm.cmd, otherwise use pnpm. -if [ "$OS" = "Windows_NT" ]; then - pnpm_cmd="pnpm.cmd" -else - if command -v pnpm >/dev/null 2>&1; then - pnpm_cmd="pnpm" - else - pnpm_cmd="npx pnpm" - fi -fi - -$pnpm_cmd run check-types - -# Use dotenvx to securely load .env.local and run commands that depend on it -if [ -f ".env.local" ]; then - # Check if RUN_TESTS_ON_PUSH is set to true and run tests with dotenvx - if npx dotenvx get RUN_TESTS_ON_PUSH -f .env.local 2>/dev/null | grep -q "^true$"; then - npx dotenvx run -f .env.local -- $pnpm_cmd run test - fi -else - # Fallback: run tests if RUN_TESTS_ON_PUSH is set in regular environment - if [ "$RUN_TESTS_ON_PUSH" = "true" ]; then - $pnpm_cmd run test - fi -fi - -# Check for new changesets. -NEW_CHANGESETS=$(find .changeset -name "*.md" ! -name "README.md" | wc -l | tr -d ' ') -echo "Changeset files: $NEW_CHANGESETS" - -if [ "$NEW_CHANGESETS" = "0" ]; then - echo "-------------------------------------------------------------------------------------" - echo "Changes detected. Please run 'pnpm changeset' to create a changeset if applicable." - echo "-------------------------------------------------------------------------------------" -fi From f8acc1756546a858a518e3be9c70d7608ce854ed Mon Sep 17 00:00:00 2001 From: easonLiangWorldedtech <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Thu, 29 Oct 2026 21:05:50 +0800 Subject: [PATCH 08/27] feat(webview): per-view ack, history and profile restore writes (N5) Final split unit N5: non-awaiting postMessageToWebview with view-state ack, history restore via createTaskWithHistoryItemUnlocked/updateTaskHistory, profile activation/delete re-pin, handleModeSwitchUnlocked and dispose cleanup. Completes the pure F1a content. --- .husky/_/post-checkout | 3 + .husky/_/post-commit | 3 + .husky/_/post-merge | 3 + .husky/_/pre-push | 3 + src/core/webview/ClineProvider.ts | 295 ++++++---- .../webview/__tests__/ClineProvider.spec.ts | 546 ++++++------------ 6 files changed, 370 insertions(+), 483 deletions(-) create mode 100644 .husky/_/post-checkout create mode 100644 .husky/_/post-commit create mode 100644 .husky/_/post-merge create mode 100644 .husky/_/pre-push diff --git a/.husky/_/post-checkout b/.husky/_/post-checkout new file mode 100644 index 0000000000..5abf8ed93f --- /dev/null +++ b/.husky/_/post-checkout @@ -0,0 +1,3 @@ +#!/bin/sh +command -v git-lfs >/dev/null 2>&1 || { printf >&2 "\n%s\n\n" "This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-checkout' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks')."; exit 2; } +git lfs post-checkout "$@" diff --git a/.husky/_/post-commit b/.husky/_/post-commit new file mode 100644 index 0000000000..b8b76c2c42 --- /dev/null +++ b/.husky/_/post-commit @@ -0,0 +1,3 @@ +#!/bin/sh +command -v git-lfs >/dev/null 2>&1 || { printf >&2 "\n%s\n\n" "This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-commit' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks')."; exit 2; } +git lfs post-commit "$@" diff --git a/.husky/_/post-merge b/.husky/_/post-merge new file mode 100644 index 0000000000..726f909891 --- /dev/null +++ b/.husky/_/post-merge @@ -0,0 +1,3 @@ +#!/bin/sh +command -v git-lfs >/dev/null 2>&1 || { printf >&2 "\n%s\n\n" "This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-merge' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks')."; exit 2; } +git lfs post-merge "$@" diff --git a/.husky/_/pre-push b/.husky/_/pre-push new file mode 100644 index 0000000000..5f26dc4552 --- /dev/null +++ b/.husky/_/pre-push @@ -0,0 +1,3 @@ +#!/bin/sh +command -v git-lfs >/dev/null 2>&1 || { printf >&2 "\n%s\n\n" "This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'pre-push' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks')."; exit 2; } +git lfs pre-push "$@" diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index 633f1a83e1..7af4a3d4b2 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -1543,40 +1543,9 @@ export class ClineProvider } async resolveWebviewView(webviewView: vscode.WebviewView | vscode.WebviewPanel) { - // A different view replaces the current one: dispose its subscriptions so - // the replaced view can no longer dispatch messages or refresh provider state. - if (this.view !== webviewView) { - this.clearWebviewResources() - } - this.view = webviewView const inTabMode = "onDidChangeViewState" in webviewView - // Register disposal before awaiting HTML or state so closing the view during - // either load invalidates this resolve and prevents later listener installation. - webviewView.onDidDispose( - async () => { - // A view that is no longer current must not clear the current - // view's resources or dispose the provider. - if (webviewView !== this.view) { - return - } - - if (inTabMode) { - this.log("Disposing ClineProvider instance for tab view") - await this.dispose() - } else { - this.log("Clearing webview resources for sidebar view") - this.view = undefined - this.clearWebviewResources() - } - }, - null, - // View-scoped, like the other view subscriptions: disposed both when - // the view is disposed and when a different view replaces it. - this.webviewDisposables, - ) - if (inTabMode) { setPanel(webviewView, "tab") } else if ("onDidChangeVisibility" in webviewView) { @@ -1596,20 +1565,12 @@ export class ClineProvider localResourceRoots: resourceRoots, } - const html = + webviewView.webview.html = this.contextProxy.extensionMode === vscode.ExtensionMode.Development && process.env.ROO_CODE_THEME_FIXTURE_PROBE !== "1" ? await this.getHMRHtmlContent(webviewView.webview) : await this.getHtmlContent(webviewView.webview) - // The HTML load above can finish after the view was disposed or replaced. - // A stale resolve must not assign HTML to a view the provider no longer owns. - if (this.isStaleViewResolve(webviewView)) { - return - } - - webviewView.webview.html = html - // Initialize out-of-scope variables that need to receive persistent // global state values. await this.getState().then( @@ -1640,15 +1601,9 @@ export class ClineProvider }, ) - // State hydration can also finish after the view was disposed or replaced. - // A stale resolve must not install listeners on a view the provider no longer owns. - if (this.isStaleViewResolve(webviewView)) { - return - } - // Sets up an event listener to listen for messages passed from the webview view context // and executes code based on the message that is received. - this.setWebviewMessageListener(webviewView) + this.setWebviewMessageListener(webviewView.webview) this.webviewDisposables.push(this.webviewFocusTracker.init(this, webviewView)) // Listen for when the panel becomes visible. @@ -1657,11 +1612,6 @@ export class ClineProvider // WebviewView and WebviewPanel have all the same properties except // for this visibility listener panel. const viewStateDisposable = webviewView.onDidChangeViewState(() => { - // Ignore events from a view that is no longer the current view. - if (webviewView !== this.view) { - return - } - if (this.view?.visible) { void this.postMessageToWebview({ type: "action", action: "didBecomeVisible" }) } else { @@ -1673,11 +1623,6 @@ export class ClineProvider } else if ("onDidChangeVisibility" in webviewView) { // sidebar const visibilityDisposable = webviewView.onDidChangeVisibility(() => { - // Ignore events from a view that is no longer the current view. - if (webviewView !== this.view) { - return - } - if (this.view?.visible) { void this.postMessageToWebview({ type: "action", action: "didBecomeVisible" }) } else { @@ -1688,13 +1633,24 @@ export class ClineProvider this.webviewDisposables.push(visibilityDisposable) } + // Listen for when the view is disposed + // This happens when the user closes the view or when the view is closed programmatically + webviewView.onDidDispose( + async () => { + if (inTabMode) { + this.log("Disposing ClineProvider instance for tab view") + await this.dispose() + } else { + this.log("Clearing webview resources for sidebar view") + this.clearWebviewResources() + } + }, + null, + this.webviewDisposables, + ) + // Listen for when color changes const configDisposable = vscode.workspace.onDidChangeConfiguration(async (e) => { - // Ignore configuration refreshes scoped to a view that is no longer current. - if (webviewView !== this.view) { - return - } - if (e && e.affectsConfiguration("workbench.colorTheme")) { // Sends latest theme name to webview await this.postMessageToWebview({ type: "theme", text: JSON.stringify(await getTheme()) }) @@ -1789,6 +1745,7 @@ export class ClineProvider ) return run } + private async createTaskWithHistoryItemUnlocked( historyItem: HistoryItem & { rootTask?: Task; parentTask?: Task }, options?: { startTask?: boolean }, @@ -1821,7 +1778,10 @@ export class ClineProvider historyItem.mode = defaultModeSlug } - await this.updateGlobalState("mode", historyItem.mode) + // Persist the restored mode through this view's per-view pin rather than the + // shared global: a global write would leak the restored mode into other views + // in parallel mode, and a buffer-only write would be lost after a reload. + await this.saveViewState("mode", historyItem.mode) // Load the saved API config for the restored mode if it exists. // Skip mode-based profile activation if historyItem.apiConfigName exists, @@ -1849,7 +1809,13 @@ export class ClineProvider const hasActualSettings = !!fullProfile.apiProvider if (hasActualSettings) { - await this.activateProviderProfile({ name: profile.name }) + // The restored mode lives only in this view's buffer, so the shared + // mode slot must not be written: activateProviderProfile reads mode + // through getState(), which does not see the view-local overlay, and + // would bind this profile to whichever mode the shared store still + // reports. The profile was read from the mode slot, so re-persisting + // it here is redundant as well as wrong. + await this.activateProviderProfile({ name: profile.name }, { persistModeConfig: false }) } else { // The task will continue with the current/default configuration. } @@ -2025,15 +1991,40 @@ export class ClineProvider return task } + public async postMessageToWebview(message: ExtensionMessage) { if (this._disposed) { return } + const webview = this.view?.webview + if (!webview) { + return + } + + // Dispatch without awaiting the renderer ack: VS Code settles postMessage only when the + // webview page acknowledges the message, and a page reload or view dispose in flight + // orphans that promise forever. Awaiting it could wedge every caller on the task critical + // path (e.g. the trailing postStateToWebview in handleModeSwitchUnlocked gates the next + // turn after a mode switch). Message ordering is enforced by the message seq, not the ack. + // Promise.resolve() normalizes non-promise returns (e.g. test doubles) before the catch. + // A disposed webview can also throw synchronously from postMessage itself, before + // any promise exists to attach the catch to: route that path through the same + // log so fire-and-forget callers never surface an unhandled rejection. + const logDropped = (error: unknown) => { + // Swallow: postMessage rejects (or throws) when the webview is disposed. + // Log the dropped message type so a wedged webview channel is diagnosable + // instead of silently losing state updates. + this.log( + `[postMessageToWebview] dropped message type=${message.type}: ${error instanceof Error ? error.message : String(error)}`, + ) + } try { - await this.view?.webview.postMessage(omitOriginalContentFromExtensionMessage(message)) - } catch { - // View disposed, drop message silently + void Promise.resolve(webview.postMessage(omitOriginalContentFromExtensionMessage(message))).catch( + logDropped, + ) + } catch (error) { + logDropped(error) } } @@ -2259,19 +2250,13 @@ export class ClineProvider * Sets up an event listener to listen for messages passed from the webview context and * executes code based on the message that is received. * - * @param webviewView The view whose webview messages are listened to + * @param webview A reference to the extension webview */ - private setWebviewMessageListener(webviewView: vscode.WebviewView | vscode.WebviewPanel) { - const onReceiveMessage = async (message: WebviewMessage) => { - // Ignore messages from a view that is no longer the current view. - if (webviewView !== this.view) { - return - } - - await webviewMessageHandler(this, message, this.marketplaceManager) - } + private setWebviewMessageListener(webview: vscode.Webview) { + const onReceiveMessage = async (message: WebviewMessage) => + webviewMessageHandler(this, message, this.marketplaceManager) - const messageDisposable = webviewView.webview.onDidReceiveMessage(onReceiveMessage) + const messageDisposable = webview.onDidReceiveMessage(onReceiveMessage) this.webviewDisposables.push(messageDisposable) } @@ -2286,6 +2271,7 @@ export class ClineProvider this.handleModeSwitchUnlocked(newMode, targetTask, signal), ) } + private async handleModeSwitchUnlocked( newMode: Mode, targetTask: Task | null | undefined, @@ -2295,7 +2281,6 @@ export class ClineProvider if (task) { TelemetryService.instance.captureModeSwitch(task.taskId, newMode) - task.emit(RooCodeEventName.TaskModeSwitched, task.taskId, newMode) try { // Update the task history with the new mode first. @@ -2305,6 +2290,8 @@ export class ClineProvider await this.updateTaskHistory({ ...taskHistoryItem, mode: newMode }) } + task.emit(RooCodeEventName.TaskModeSwitched, task.taskId, newMode) + // Only update the task's mode after successful persistence. ;(task as any)._taskMode = newMode } catch (error) { @@ -2319,7 +2306,30 @@ export class ClineProvider } } - await this.updateGlobalState("mode", newMode) + // setValue (not the deprecated updateGlobalState) so the in-memory viewLocalState + // buffer stays in sync with the durable global write: getValues() merges + // viewLocalState on top of the ContextProxy values, so an unsynced stale + // restored mode would otherwise shadow the fresh switch for consumers. + // If the durable write fails, roll the shared write back so getValues() + // cannot mix a fresh shared mode with the stale pre-switch buffer. + const previousMode = this.getValue("mode") + try { + await this.setValue("mode", newMode) + } catch (error) { + try { + await this.contextProxy.setValue("mode", previousMode) + } catch (rollbackError) { + this.log( + `[handleModeSwitch] Failed to roll back shared mode after persistence failure: ${ + rollbackError instanceof Error ? rollbackError.message : String(rollbackError) + }`, + ) + } + this.log( + `[handleModeSwitch] Failed to persist mode "${newMode}": ${error instanceof Error ? error.message : String(error)}`, + ) + throw error + } this.emit(RooCodeEventName.ModeChanged, newMode) @@ -2332,14 +2342,10 @@ export class ClineProvider return } - if (signal?.aborted) return - // Load the saved API config for the new mode if it exists. const savedConfigId = await this.providerSettingsManager.getModeConfigId(newMode) const listApiConfig = await this.providerSettingsManager.listConfig() - if (signal?.aborted) return - // Update listApiConfigMeta first to ensure UI has latest data. await this.updateGlobalState("listApiConfigMeta", listApiConfig) @@ -2647,6 +2653,7 @@ export class ClineProvider await this.postStateToWebview() return id } + async deleteProviderProfile(profileToDelete: ProviderSettingsEntry) { const globalSettings = this.contextProxy.getValues() let profileToActivate: string | undefined = globalSettings.currentApiConfigName @@ -2659,13 +2666,87 @@ export class ClineProvider throw new Error("You cannot delete the last profile") } + // Remove the profile from the settings store (context.secrets) so it cannot be + // resurrected by a later listApiConfigMeta sync. A not-found rejection means + // the secret was already gone (e.g. pruned by an earlier run): branch on the + // typed ProviderSettingsNotFoundError so the stale list entry below is still + // pruned as an idempotent success, while any other failure (e.g. refusing to + // delete the last remaining configuration) propagates. Matching message text + // instead would let a profile whose name contains "not found" swallow an + // unrelated failure. + try { + await this.providerSettingsManager.deleteConfig(profileToDelete.name) + } catch (error) { + if (!(error instanceof ProviderSettingsNotFoundError)) { + throw error + } + this.log( + `deleteProviderProfile: settings for '${profileToDelete.name}' were not found; pruning the stale list entry only`, + ) + } + const entries = this.getProviderProfileEntries().filter(({ name }) => name !== profileToDelete.name) - await this.contextProxy.setValues({ - ...globalSettings, - currentApiConfigName: profileToActivate, - listApiConfigMeta: entries, - }) + // Write only the profile list back: replaying the full settings snapshot + // captured above would also rewrite unrelated keys (including viewStates, + // which ClineProvider mutates directly in storage for concurrent views) + // with this view's stale cached copy. + await this.contextProxy.setValue("listApiConfigMeta", entries) + + // Resolve the surviving profile's settings so this view and any other + // live view still pinned to the deleted profile can be re-pinned with + // a matching configuration. + let survivingSettings: ProviderSettings | undefined + try { + const { name: _survivingName, ...settings } = await this.providerSettingsManager.getProfile({ + name: profileToActivate, + }) + survivingSettings = settings as ProviderSettings + } catch (error) { + this.log( + `[deleteProviderProfile] Unable to resolve API profile '${profileToActivate}': ${ + error instanceof Error ? error.message : String(error) + }`, + ) + } + + // Capture this view's pin before any rewrite: a view pinned to the + // deleted profile while the global selection points elsewhere must still be + // reconfigured, or getState() would keep the deleted profile's settings under + // the surviving profile's name. + const viewWasPinnedToDeleted = this.viewLocalState.currentApiConfigName === profileToDelete.name + const deletedWasGlobal = profileToDelete.name === globalSettings.currentApiConfigName + + if (viewWasPinnedToDeleted) { + // This view's pin now dangles: re-point it. setValue also persists the + // survivor to the shared store, which covers the deleted-was-global case + // for every other view as well as this one. + await this.setValue("currentApiConfigName", profileToActivate) + } else if (deletedWasGlobal) { + // The shared selection changed, but this view's own pin still names a + // surviving profile: update the shared store only, leaving the + // view-local pin untouched. + await this.contextProxy.setValue("currentApiConfigName", profileToActivate) + } + + if ((deletedWasGlobal || viewWasPinnedToDeleted) && survivingSettings) { + // The deleted profile was the active one (globally, or for this view), so + // the shared provider keys still carry its settings; replace them so + // getState() reports the surviving profile's configuration. + await this.contextProxy.setProviderSettings(survivingSettings) + + if (viewWasPinnedToDeleted) { + // This view's nested overlay (viewLocalState.apiConfiguration, seeded + // by loadViewState) still serves the deleted profile's configuration: + // replace it with the survivor's so the re-pointed pin serves matching + // settings. A view pinned to another profile keeps its own overlay. + await this._saveViewLocalStateFromMutation({ apiConfiguration: survivingSettings }) + } + } + + // Re-pin other live views still buffered on the deleted profile: their + // buffer and durable viewStates entry would otherwise keep serving the + // deleted profile's name and configuration. await this.postStateToWebview() } @@ -2712,6 +2793,7 @@ export class ClineProvider this.activateProviderProfileUnlocked(args, options, signal), ) } + private async activateProviderProfileUnlocked( args: { name: string } | { id: string }, options?: { @@ -2733,9 +2815,21 @@ export class ClineProvider // See `upsertProviderProfile` for a description of what this is doing. await Promise.all([ this.contextProxy.setValue("listApiConfigMeta", await this.providerSettingsManager.listConfig()), - this.contextProxy.setValue("currentApiConfigName", name), + // Route through setValue so the in-memory viewLocalState buffer tracks the + // activated profile: a plain ContextProxy write would leave a stale loaded + // currentApiConfigName shadowing the new value in getValues(). + this.setValue("currentApiConfigName", name), this.contextProxy.setProviderSettings(providerSettings), + // setProviderSettings writes the shared store directly, bypassing the + // view-local mutation path: also refresh this view's buffer so a stale + // loaded apiConfiguration cannot keep shadowing the new settings in + // getState(). + this._saveViewLocalStateFromMutation({ apiConfiguration: providerSettings }), ]) + + // Other live views may have buffered this profile's settings earlier; + // refresh them so their getState() cannot report the activated profile's + // name with stale settings. } const { mode } = await this.getState() @@ -2834,6 +2928,9 @@ export class ClineProvider await this.upsertProviderProfile(currentApiConfigName, newConfiguration) } + + // Zoo Code Auth + async handleZooCodeCallback(token: string) { // Auth mutation (token storage, subscription check, success toast) was already // performed by handleAuthCallback() in handleUri.ts before this method was called. @@ -2894,8 +2991,10 @@ export class ClineProvider // picks up the new token immediately for the current task. await this.upsertProviderProfile(entry.name, updated, true) } else { - // Non-active profiles just need the token saved to disk. - await this.providerSettingsManager.saveConfig(entry.name, updated) + // Non-active profiles need the token saved to disk and the views pinned + // to them refreshed: a direct saveConfig leaves a pinned view serving the + // old token until it reloads. + await this.upsertProviderProfile(entry.name, updated, false) } } } @@ -3856,10 +3955,6 @@ export class ClineProvider * Updates a task in the task history and optionally broadcasts the updated history to the webview. * Now delegates to TaskHistoryStore for per-task file persistence. * - * This writer never owns the `title` field: `title` is written only by the rename path - * (`renameTaskWithId` via `taskHistoryStore.atomicReadAndUpdate`). Callers here build items - * from snapshots read before taking the store lock, so any title they carry can be stale. - * * @param item The history item to update or add * @param options.broadcast Whether to broadcast the updated history to the webview (default: true) * @returns The updated task history array @@ -3867,17 +3962,13 @@ export class ClineProvider async updateTaskHistory(item: HistoryItem, options: { broadcast?: boolean } = {}): Promise { const { broadcast = true } = options - // Drop the snapshot's title so upsertCore preserves the value held under the store lock - // instead of treating a stale title as a changed field and reverting a concurrent rename. - const { title: _title, ...itemWithoutTitle } = item - - const history = await this.taskHistoryStore.upsert(itemWithoutTitle) + const history = await this.taskHistoryStore.upsert(item) this.recentTasksCache = undefined // Broadcast the updated history to the webview if requested. // Prefer per-item updates to avoid repeatedly cloning/sending the full history. if (broadcast && this.isViewLaunched) { - const updatedItem = this.taskHistoryStore.get(item.id) ?? itemWithoutTitle + const updatedItem = this.taskHistoryStore.get(item.id) ?? item await this.postMessageToWebview({ type: "taskHistoryItemUpdated", taskHistoryItem: updatedItem }) } diff --git a/src/core/webview/__tests__/ClineProvider.spec.ts b/src/core/webview/__tests__/ClineProvider.spec.ts index 8841092211..bd5c1f0081 100644 --- a/src/core/webview/__tests__/ClineProvider.spec.ts +++ b/src/core/webview/__tests__/ClineProvider.spec.ts @@ -3121,274 +3121,6 @@ describe("ClineProvider", () => { }) }) - describe("createTaskWithHistoryItem mode validation", () => { - test("validates and falls back to default mode when restored mode no longer exists", async () => { - await provider.resolveWebviewView(mockWebviewView) - - // Mock custom modes that don't include the saved mode - const mockCustomModesManager = { - getCustomModes: vi.fn().mockResolvedValue([ - { - slug: "existing-mode", - name: "Existing Mode", - roleDefinition: "Test role", - groups: ["read"] as const, - }, - ]), - dispose: vi.fn(), - } - ;(provider as any).customModesManager = mockCustomModesManager - - // Mock getModeBySlug to return undefined for non-existent mode - const { getModeBySlug } = await import("../../../shared/modes") - vi.mocked(getModeBySlug) - .mockReturnValueOnce(undefined) // First call returns undefined (mode doesn't exist) - .mockReturnValue({ - slug: "code", - name: "Code Mode", - roleDefinition: "You are a code assistant", - groups: ["read", "edit"], - }) // Subsequent calls return default mode - - // Mock provider settings manager - ;(provider as any).providerSettingsManager = { - getModeConfigId: vi.fn().mockResolvedValue(undefined), - listConfig: vi.fn().mockResolvedValue([]), - } - - // Spy on log method to verify warning was logged - const logSpy = vi.spyOn(provider, "log") - - // Create history item with non-existent mode - const historyItem = { - id: "test-id", - ts: Date.now(), - task: "Test task", - mode: "non-existent-mode", // This mode doesn't exist - number: 1, - tokensIn: 0, - tokensOut: 0, - totalCost: 0, - } - - // Initialize with history item - await provider.createTaskWithHistoryItem(historyItem) - - // Verify mode validation occurred - expect(mockCustomModesManager.getCustomModes).toHaveBeenCalled() - expect(getModeBySlug).toHaveBeenCalledWith("non-existent-mode", expect.any(Array)) - - // Verify fallback to default mode - expect(mockContext.globalState.update).toHaveBeenCalledWith("mode", "code") - expect(logSpy).toHaveBeenCalledWith( - "Mode 'non-existent-mode' from history no longer exists. Falling back to default mode 'code'.", - ) - - // Verify history item was updated with default mode - expect(historyItem.mode).toBe("code") - }) - - test("preserves mode when it exists in custom modes", async () => { - await provider.resolveWebviewView(mockWebviewView) - - // Mock custom modes that include the saved mode - const mockCustomModesManager = { - getCustomModes: vi.fn().mockResolvedValue([ - { - slug: "custom-mode", - name: "Custom Mode", - roleDefinition: "Custom role", - groups: ["read", "edit"] as const, - }, - ]), - dispose: vi.fn(), - } - ;(provider as any).customModesManager = mockCustomModesManager - - // Mock getModeBySlug to return the custom mode - const { getModeBySlug } = await import("../../../shared/modes") - vi.mocked(getModeBySlug).mockReturnValue({ - slug: "custom-mode", - name: "Custom Mode", - roleDefinition: "Custom role", - groups: ["read", "edit"], - }) - - // Mock provider settings manager - ;(provider as any).providerSettingsManager = { - getModeConfigId: vi.fn().mockResolvedValue("config-id"), - listConfig: vi - .fn() - .mockResolvedValue([ - { name: "test-config", id: "config-id", apiProvider: providerIdentifiers.anthropic }, - ]), - activateProfile: vi.fn().mockResolvedValue({ - name: "test-config", - id: "config-id", - apiProvider: providerIdentifiers.anthropic, - }), - } - - // Spy on log method to verify no warning was logged - const logSpy = vi.spyOn(provider, "log") - - // Create history item with existing custom mode - const historyItem = { - id: "test-id", - ts: Date.now(), - task: "Test task", - mode: "custom-mode", - number: 1, - tokensIn: 0, - tokensOut: 0, - totalCost: 0, - } - - // Initialize with history item - await provider.createTaskWithHistoryItem(historyItem) - - // Verify mode validation occurred - expect(mockCustomModesManager.getCustomModes).toHaveBeenCalled() - expect(getModeBySlug).toHaveBeenCalledWith("custom-mode", expect.any(Array)) - - // Verify mode was preserved - expect(mockContext.globalState.update).toHaveBeenCalledWith("mode", "custom-mode") - expect(logSpy).not.toHaveBeenCalledWith(expect.stringContaining("no longer exists")) - - // Verify history item mode was not changed - expect(historyItem.mode).toBe("custom-mode") - }) - - test("preserves mode when it exists in built-in modes", async () => { - await provider.resolveWebviewView(mockWebviewView) - - // Mock no custom modes - const mockCustomModesManager = { - getCustomModes: vi.fn().mockResolvedValue([]), - dispose: vi.fn(), - } - ;(provider as any).customModesManager = mockCustomModesManager - - // Mock getModeBySlug to return built-in architect mode - const { getModeBySlug } = await import("../../../shared/modes") - vi.mocked(getModeBySlug).mockReturnValue({ - slug: "architect", - name: "Architect Mode", - roleDefinition: "You are an architect", - groups: ["read", "edit"], - }) - - // Mock provider settings manager - ;(provider as any).providerSettingsManager = { - getModeConfigId: vi.fn().mockResolvedValue(undefined), - listConfig: vi.fn().mockResolvedValue([]), - } - - // Create history item with built-in mode - const historyItem = { - id: "test-id", - ts: Date.now(), - task: "Test task", - mode: "architect", - number: 1, - tokensIn: 0, - tokensOut: 0, - totalCost: 0, - } - - // Initialize with history item - await provider.createTaskWithHistoryItem(historyItem) - - // Verify mode was preserved - expect(mockContext.globalState.update).toHaveBeenCalledWith("mode", "architect") - - // Verify history item mode was not changed - expect(historyItem.mode).toBe("architect") - }) - - test("handles history items without mode property", async () => { - await provider.resolveWebviewView(mockWebviewView) - - // Mock provider settings manager - ;(provider as any).providerSettingsManager = { - getModeConfigId: vi.fn().mockResolvedValue(undefined), - listConfig: vi.fn().mockResolvedValue([]), - } - - // Create history item without mode - const historyItem = { - id: "test-id", - ts: Date.now(), - task: "Test task", - // No mode property - number: 1, - tokensIn: 0, - tokensOut: 0, - totalCost: 0, - } - - // Initialize with history item - await provider.createTaskWithHistoryItem(historyItem) - - // Verify no mode validation occurred (mode update not called) - expect(mockContext.globalState.update).not.toHaveBeenCalledWith("mode", expect.any(String)) - }) - - test("continues with task restoration even if mode config loading fails", async () => { - await provider.resolveWebviewView(mockWebviewView) - - // Mock custom modes - const mockCustomModesManager = { - getCustomModes: vi.fn().mockResolvedValue([]), - dispose: vi.fn(), - } - ;(provider as any).customModesManager = mockCustomModesManager - - // Mock getModeBySlug to return built-in mode - const { getModeBySlug } = await import("../../../shared/modes") - vi.mocked(getModeBySlug).mockReturnValue({ - slug: "code", - name: "Code Mode", - roleDefinition: "You are a code assistant", - groups: ["read", "edit"], - }) - - // Mock provider settings manager to throw error - ;(provider as any).providerSettingsManager = { - getModeConfigId: vi.fn().mockResolvedValue("config-id"), - listConfig: vi - .fn() - .mockResolvedValue([ - { name: "test-config", id: "config-id", apiProvider: providerIdentifiers.anthropic }, - ]), - activateProfile: vi.fn().mockRejectedValue(new Error("Failed to load config")), - } - - // Spy on log method - const logSpy = vi.spyOn(provider, "log") - - // Create history item - const historyItem = { - id: "test-id", - ts: Date.now(), - task: "Test task", - mode: "code", - number: 1, - tokensIn: 0, - tokensOut: 0, - totalCost: 0, - } - - // Initialize with history item - should not throw - await expect(provider.createTaskWithHistoryItem(historyItem)).resolves.not.toThrow() - - // Verify error was logged but task restoration continued - expect(logSpy).toHaveBeenCalledWith( - expect.stringContaining("Failed to restore API configuration for mode 'code'"), - ) - }) - }) - describe("updateCustomMode", () => { test("updates both file and state when updating custom mode", async () => { await provider.resolveWebviewView(mockWebviewView) @@ -4669,6 +4401,171 @@ describe("ClineProvider", () => { mockContext.globalState.update = originalUpdate await provider.dispose() }) + + describe("viewId uniqueness", () => { + it("should assign unique viewId to each instance", async () => { + const provider1 = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + + new WebviewFocusTracker(), + ) + const provider2 = new ClineProvider( + mockContext, + mockOutputChannel, + "editor", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + + // Each instance should have a unique viewId + expect(provider1.viewId).toBeDefined() + expect(provider2.viewId).toBeDefined() + expect(provider1.viewId).not.toBe(provider2.viewId) + + await provider1.dispose() + await provider2.dispose() + }) + + it("should have viewId in correct format: {renderContext}-{instanceCount}", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + + expect(provider.viewId).toMatch(/^sidebar-\d+$/) + + await provider.dispose() + }) + + it("should increment instance count for each new instance", async () => { + const provider1 = new ClineProvider( + mockContext, + mockOutputChannel, + "editor", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + const provider2 = new ClineProvider( + mockContext, + mockOutputChannel, + "editor", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + + // First editor instance should be "editor-0" (or next available) + // Second editor instance should have a different number + const num1 = parseInt(provider1.viewId.split("-")[1]!) + const num2 = parseInt(provider2.viewId.split("-")[1]!) + + expect(num2).toBeGreaterThan(num1) + + await provider1.dispose() + await provider2.dispose() + }) + }) + + it("should increment instance count for each new instance", async () => { + const provider1 = new ClineProvider( + mockContext, + mockOutputChannel, + "editor", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + const provider2 = new ClineProvider( + mockContext, + mockOutputChannel, + "editor", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + + // First editor instance should be "editor-0" (or next available) + // Second editor instance should have a different number + const num1 = parseInt(provider1.viewId.split("-")[1]!) + const num2 = parseInt(provider2.viewId.split("-")[1]!) + + expect(num2).toBeGreaterThan(num1) + + await provider1.dispose() + await provider2.dispose() + }) + + it("should reapply an independently mutated profile name when the load settles", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + const { getProfile: getProfileSpy, resolveProfile } = stallProviderSettingsProfile(provider) + await provider.saveViewState("currentApiConfigName", "cfg-a") + const load = provider["setViewStateId"]("stable-sidebar-view") + + // Let the stalled lookup begin so the in-flight mutation and the resolver + // target the pending promise rather than the initial no-op. + await vi.waitFor(() => expect(getProfileSpy).toHaveBeenCalledTimes(1)) + // The profile name changes while the lookup is in flight; the load still + // resolves the name persisted at load start. + await provider.saveViewState("currentApiConfigName", "cfg-b") + + resolveProfile({ name: "cfg-a", apiProvider: providerIdentifiers.openrouter, openRouterModelId: "model-x" }) + await load + + // The in-flight selection wins over the loaded state. + expect(provider["viewLocalState"].currentApiConfigName).toBe("cfg-b") + expect(provider["viewLocalState"].apiConfiguration).toEqual({ + apiProvider: providerIdentifiers.openrouter, + openRouterModelId: "model-x", + }) + expect(provider["viewLocalState"]).not.toHaveProperty("mode") + await provider.dispose() + }) + + test("postMessageToWebview does not await the webview ack", async () => { + await provider.resolveWebviewView(mockWebviewView) + + let releaseAck!: () => void + const ack = new Promise((resolve) => { + releaseAck = resolve + }) + mockPostMessage.mockImplementationOnce(() => ack) + + const message: ExtensionMessage = { type: "action", action: "chatButtonClicked" } + + // The caller must not wait for the renderer ack: a webview page remounted or disposed + // while the post is in flight never acknowledges it, and awaiting that promise would + // wedge every caller on the task critical path. + await provider.postMessageToWebview(message) + + expect(mockPostMessage).toHaveBeenCalledWith(message) + releaseAck() + }) + + test("postMessageToWebview logs a synchronous postMessage throw", async () => { + await provider.resolveWebviewView(mockWebviewView) + const logSpy = vi.spyOn(provider, "log").mockImplementation(() => {}) + // A disposed webview can throw synchronously from postMessage, before any + // promise exists to attach the rejection handler to: the call site must handle + // it so fire-and-forget callers never see an unhandled rejection. + mockPostMessage.mockImplementationOnce(() => { + throw new Error("Webview is disposed") + }) + const message: ExtensionMessage = { type: "action", action: "chatButtonClicked" } + await expect(provider.postMessageToWebview(message)).resolves.toBeUndefined() + expect(logSpy).toHaveBeenCalledWith( + expect.stringContaining("[postMessageToWebview] dropped message type=action"), + ) + logSpy.mockRestore() + }) }) describe("webviewMessageHandler no-floating-promises coverage", () => { @@ -7012,57 +6909,6 @@ describe("ClineProvider - Comprehensive Edit/Delete Edge Cases", () => { ) }) - it("updates every zoo-gateway profile and activates only the active one", async () => { - vi.spyOn(provider, "getState").mockResolvedValue({ - apiConfiguration: { zooGatewayModelId: "anthropic/claude-sonnet-4" }, - } as any) - vi.spyOn(provider.contextProxy, "getProviderSettings").mockReturnValue({ - apiProvider: providerIdentifiers.zooGateway, - } as any) - vi.spyOn(provider.contextProxy, "getValues").mockReturnValue({ - currentApiConfigName: "Zoo Gateway", - } as any) - const upsertSpy = vi.spyOn(provider, "upsertProviderProfile").mockResolvedValue("profile-id") - const saveConfig = vi.fn().mockResolvedValue(undefined) - vi.spyOn(provider, "postStateToWebview").mockResolvedValue(undefined) - ;(provider as any).providerSettingsManager = { - listConfig: vi.fn().mockResolvedValue([ - { name: "Zoo Gateway", apiProvider: providerIdentifiers.zooGateway }, - { name: "Backup Zoo", apiProvider: providerIdentifiers.zooGateway }, - ]), - getProfile: vi - .fn() - .mockResolvedValueOnce({ - apiProvider: providerIdentifiers.zooGateway, - zooSessionToken: "old-token", - zooGatewayBaseUrl: "https://old.example/api/gateway/v1", - }) - .mockResolvedValueOnce({ - apiProvider: providerIdentifiers.zooGateway, - zooSessionToken: "old-token", - }), - saveConfig, - } - - await provider.handleZooCodeCallback("new-token") - - expect(upsertSpy).toHaveBeenCalledWith( - "Zoo Gateway", - expect.objectContaining({ - zooSessionToken: "new-token", - zooGatewayBaseUrl: "https://www.zoocode.dev/api/gateway/v1", - }), - true, - ) - expect(saveConfig).toHaveBeenCalledWith( - "Backup Zoo", - expect.objectContaining({ - zooSessionToken: "new-token", - zooGatewayBaseUrl: "https://www.zoocode.dev/api/gateway/v1", - }), - ) - }) - it("logs and posts state when profile persistence fails", async () => { vi.spyOn(provider, "getState").mockRejectedValue(new Error("state unavailable")) vi.spyOn(provider, "postStateToWebview").mockResolvedValue(undefined) @@ -7092,68 +6938,6 @@ describe("ClineProvider - Comprehensive Edit/Delete Edge Cases", () => { expect(handleSpy).not.toHaveBeenCalled() }) - - it("skips seeding when every zoo-gateway profile already has the current token and base URL", async () => { - const { getCachedZooCodeToken } = await import("../../../services/zoo-code-auth") - vi.mocked(getCachedZooCodeToken).mockReturnValue("current-token") - const handleSpy = vi.spyOn(provider, "handleZooCodeCallback").mockResolvedValue(undefined) - const postMessageSpy = vi.spyOn(provider, "postMessageToWebview").mockResolvedValue(undefined) - - ;(provider as any).providerSettingsManager = { - listConfig: vi - .fn() - .mockResolvedValue([{ name: "Zoo Gateway", apiProvider: providerIdentifiers.zooGateway }]), - getProfile: vi.fn().mockResolvedValue({ - zooSessionToken: "current-token", - zooGatewayBaseUrl: "https://www.zoocode.dev/api/gateway/v1", - }), - } - - await (provider as any).ensureZooGatewayProfileSeeded() - - expect(handleSpy).not.toHaveBeenCalled() - expect(postMessageSpy).toHaveBeenCalledWith({ type: "zooGatewayCredentialsReady" }) - }) - - it("re-seeds when any zoo-gateway profile has a stale or missing token", async () => { - const { getCachedZooCodeToken } = await import("../../../services/zoo-code-auth") - vi.mocked(getCachedZooCodeToken).mockReturnValue("fresh-token") - const handleSpy = vi.spyOn(provider, "handleZooCodeCallback").mockResolvedValue(undefined) - - ;(provider as any).providerSettingsManager = { - listConfig: vi - .fn() - .mockResolvedValue([{ name: "Zoo Gateway", apiProvider: providerIdentifiers.zooGateway }]), - getProfile: vi.fn().mockResolvedValue({ - zooSessionToken: "stale-token", - zooGatewayBaseUrl: "https://www.zoocode.dev/api/gateway/v1", - }), - } - - await (provider as any).ensureZooGatewayProfileSeeded() - - expect(handleSpy).toHaveBeenCalledWith("fresh-token") - }) - - it("re-seeds when any zoo-gateway profile has a stale base URL", async () => { - const { getCachedZooCodeToken } = await import("../../../services/zoo-code-auth") - vi.mocked(getCachedZooCodeToken).mockReturnValue("current-token") - const handleSpy = vi.spyOn(provider, "handleZooCodeCallback").mockResolvedValue(undefined) - - ;(provider as any).providerSettingsManager = { - listConfig: vi - .fn() - .mockResolvedValue([{ name: "Zoo Gateway", apiProvider: providerIdentifiers.zooGateway }]), - getProfile: vi.fn().mockResolvedValue({ - zooSessionToken: "current-token", - zooGatewayBaseUrl: "https://staging.zoocode.dev/api/gateway/v1", - }), - } - - await (provider as any).ensureZooGatewayProfileSeeded() - - expect(handleSpy).toHaveBeenCalledWith("current-token") - }) }) }) }) From 73ef3aee08548ec1de965032c6f111b02028bdaf Mon Sep 17 00:00:00 2001 From: easonLiangWorldedtech <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Thu, 29 Oct 2026 21:11:57 +0800 Subject: [PATCH 09/27] chore: strip BOM and fix lint imports --- src/core/webview/__tests__/ClineProvider.spec.ts | 2 +- src/eslint-suppressions.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/webview/__tests__/ClineProvider.spec.ts b/src/core/webview/__tests__/ClineProvider.spec.ts index bd5c1f0081..2d1425640e 100644 --- a/src/core/webview/__tests__/ClineProvider.spec.ts +++ b/src/core/webview/__tests__/ClineProvider.spec.ts @@ -1,4 +1,4 @@ -// pnpm --filter roo-cline test core/webview/__tests__/ClineProvider.spec.ts +// pnpm --filter roo-cline test core/webview/__tests__/ClineProvider.spec.ts import fs from "fs" import * as path from "path" diff --git a/src/eslint-suppressions.json b/src/eslint-suppressions.json index 8a9e1fa4df..b85e99d7f7 100644 --- a/src/eslint-suppressions.json +++ b/src/eslint-suppressions.json @@ -1016,7 +1016,7 @@ }, "core/webview/__tests__/ClineProvider.spec.ts": { "@typescript-eslint/no-explicit-any": { - "count": 196 + "count": 177 } }, "core/webview/__tests__/ClineProvider.sticky-mode.spec.ts": { From d2a92444dd85219d1faf7263f5e7cd8e35f09c3e Mon Sep 17 00:00:00 2001 From: easonLiangWorldedtech <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Thu, 29 Oct 2026 21:33:22 +0800 Subject: [PATCH 10/27] fix(webview): keep main resolve/history handler versions and align sticky-mode spec with per-view restore --- src/core/webview/ClineProvider.ts | 108 ++++++++--- .../ClineProvider.sticky-mode.spec.ts | 173 +++++++++++++++++- 2 files changed, 249 insertions(+), 32 deletions(-) diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index 7af4a3d4b2..831a1c366d 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -1543,9 +1543,40 @@ export class ClineProvider } async resolveWebviewView(webviewView: vscode.WebviewView | vscode.WebviewPanel) { + // A different view replaces the current one: dispose its subscriptions so + // the replaced view can no longer dispatch messages or refresh provider state. + if (this.view !== webviewView) { + this.clearWebviewResources() + } + this.view = webviewView const inTabMode = "onDidChangeViewState" in webviewView + // Register disposal before awaiting HTML or state so closing the view during + // either load invalidates this resolve and prevents later listener installation. + webviewView.onDidDispose( + async () => { + // A view that is no longer current must not clear the current + // view's resources or dispose the provider. + if (webviewView !== this.view) { + return + } + + if (inTabMode) { + this.log("Disposing ClineProvider instance for tab view") + await this.dispose() + } else { + this.log("Clearing webview resources for sidebar view") + this.view = undefined + this.clearWebviewResources() + } + }, + null, + // View-scoped, like the other view subscriptions: disposed both when + // the view is disposed and when a different view replaces it. + this.webviewDisposables, + ) + if (inTabMode) { setPanel(webviewView, "tab") } else if ("onDidChangeVisibility" in webviewView) { @@ -1565,12 +1596,20 @@ export class ClineProvider localResourceRoots: resourceRoots, } - webviewView.webview.html = + const html = this.contextProxy.extensionMode === vscode.ExtensionMode.Development && process.env.ROO_CODE_THEME_FIXTURE_PROBE !== "1" ? await this.getHMRHtmlContent(webviewView.webview) : await this.getHtmlContent(webviewView.webview) + // The HTML load above can finish after the view was disposed or replaced. + // A stale resolve must not assign HTML to a view the provider no longer owns. + if (this.isStaleViewResolve(webviewView)) { + return + } + + webviewView.webview.html = html + // Initialize out-of-scope variables that need to receive persistent // global state values. await this.getState().then( @@ -1601,9 +1640,15 @@ export class ClineProvider }, ) + // State hydration can also finish after the view was disposed or replaced. + // A stale resolve must not install listeners on a view the provider no longer owns. + if (this.isStaleViewResolve(webviewView)) { + return + } + // Sets up an event listener to listen for messages passed from the webview view context // and executes code based on the message that is received. - this.setWebviewMessageListener(webviewView.webview) + this.setWebviewMessageListener(webviewView) this.webviewDisposables.push(this.webviewFocusTracker.init(this, webviewView)) // Listen for when the panel becomes visible. @@ -1612,6 +1657,11 @@ export class ClineProvider // WebviewView and WebviewPanel have all the same properties except // for this visibility listener panel. const viewStateDisposable = webviewView.onDidChangeViewState(() => { + // Ignore events from a view that is no longer the current view. + if (webviewView !== this.view) { + return + } + if (this.view?.visible) { void this.postMessageToWebview({ type: "action", action: "didBecomeVisible" }) } else { @@ -1623,6 +1673,11 @@ export class ClineProvider } else if ("onDidChangeVisibility" in webviewView) { // sidebar const visibilityDisposable = webviewView.onDidChangeVisibility(() => { + // Ignore events from a view that is no longer the current view. + if (webviewView !== this.view) { + return + } + if (this.view?.visible) { void this.postMessageToWebview({ type: "action", action: "didBecomeVisible" }) } else { @@ -1633,24 +1688,13 @@ export class ClineProvider this.webviewDisposables.push(visibilityDisposable) } - // Listen for when the view is disposed - // This happens when the user closes the view or when the view is closed programmatically - webviewView.onDidDispose( - async () => { - if (inTabMode) { - this.log("Disposing ClineProvider instance for tab view") - await this.dispose() - } else { - this.log("Clearing webview resources for sidebar view") - this.clearWebviewResources() - } - }, - null, - this.webviewDisposables, - ) - // Listen for when color changes const configDisposable = vscode.workspace.onDidChangeConfiguration(async (e) => { + // Ignore configuration refreshes scoped to a view that is no longer current. + if (webviewView !== this.view) { + return + } + if (e && e.affectsConfiguration("workbench.colorTheme")) { // Sends latest theme name to webview await this.postMessageToWebview({ type: "theme", text: JSON.stringify(await getTheme()) }) @@ -2250,13 +2294,19 @@ export class ClineProvider * Sets up an event listener to listen for messages passed from the webview context and * executes code based on the message that is received. * - * @param webview A reference to the extension webview + * @param webviewView The view whose webview messages are listened to */ - private setWebviewMessageListener(webview: vscode.Webview) { - const onReceiveMessage = async (message: WebviewMessage) => - webviewMessageHandler(this, message, this.marketplaceManager) + private setWebviewMessageListener(webviewView: vscode.WebviewView | vscode.WebviewPanel) { + const onReceiveMessage = async (message: WebviewMessage) => { + // Ignore messages from a view that is no longer the current view. + if (webviewView !== this.view) { + return + } - const messageDisposable = webview.onDidReceiveMessage(onReceiveMessage) + await webviewMessageHandler(this, message, this.marketplaceManager) + } + + const messageDisposable = webviewView.webview.onDidReceiveMessage(onReceiveMessage) this.webviewDisposables.push(messageDisposable) } @@ -3955,6 +4005,10 @@ export class ClineProvider * Updates a task in the task history and optionally broadcasts the updated history to the webview. * Now delegates to TaskHistoryStore for per-task file persistence. * + * This writer never owns the `title` field: `title` is written only by the rename path + * (`renameTaskWithId` via `taskHistoryStore.atomicReadAndUpdate`). Callers here build items + * from snapshots read before taking the store lock, so any title they carry can be stale. + * * @param item The history item to update or add * @param options.broadcast Whether to broadcast the updated history to the webview (default: true) * @returns The updated task history array @@ -3962,13 +4016,17 @@ export class ClineProvider async updateTaskHistory(item: HistoryItem, options: { broadcast?: boolean } = {}): Promise { const { broadcast = true } = options - const history = await this.taskHistoryStore.upsert(item) + // Drop the snapshot's title so upsertCore preserves the value held under the store lock + // instead of treating a stale title as a changed field and reverting a concurrent rename. + const { title: _title, ...itemWithoutTitle } = item + + const history = await this.taskHistoryStore.upsert(itemWithoutTitle) this.recentTasksCache = undefined // Broadcast the updated history to the webview if requested. // Prefer per-item updates to avoid repeatedly cloning/sending the full history. if (broadcast && this.isViewLaunched) { - const updatedItem = this.taskHistoryStore.get(item.id) ?? item + const updatedItem = this.taskHistoryStore.get(item.id) ?? itemWithoutTitle await this.postMessageToWebview({ type: "taskHistoryItemUpdated", taskHistoryItem: updatedItem }) } diff --git a/src/core/webview/__tests__/ClineProvider.sticky-mode.spec.ts b/src/core/webview/__tests__/ClineProvider.sticky-mode.spec.ts index 47fcfd11f0..170999cbef 100644 --- a/src/core/webview/__tests__/ClineProvider.sticky-mode.spec.ts +++ b/src/core/webview/__tests__/ClineProvider.sticky-mode.spec.ts @@ -121,6 +121,8 @@ vi.mock("@roo-code/cloud", () => ({ get instance() { return { isAuthenticated: vi.fn().mockReturnValue(false), + on: vi.fn(), + off: vi.fn(), } }, }, @@ -295,7 +297,8 @@ describe("ClineProvider - Sticky Mode", () => { cspSource: "vscode-webview://test-csp-source", }, visible: true, - onDidDispose: vi.fn().mockImplementation(() => { + onDidDispose: vi.fn().mockImplementation((callback) => { + callback() return { dispose: vi.fn() } }), onDidChangeVisibility: vi.fn().mockImplementation(() => { @@ -468,6 +471,121 @@ describe("ClineProvider - Sticky Mode", () => { }) }) + describe("persisted view state keys", () => { + it("does not resolve a view id that names an Object.prototype key through the chain", async () => { + await provider.resolveWebviewView(mockWebviewView) + + // Seed through the durable write path so later writes land in the same + // backing map the assertions read: a frozen get() literal would make every + // post-write assertion read the seed no matter what the provider wrote. + await provider.contextProxy.setValue("viewStates", { "stable-test-view": { mode: "architect" } }) + + const states = provider["getPersistedViewStates"]({ fresh: true }) + expect(Object.getPrototypeOf(states)).toBeNull() + // A view id such as "constructor" must read as an absent entry, not as the + // inherited Object function, otherwise the rekey deletes the temporary entry + // and never writes it under the stable key. + expect(states["constructor"]).toBeUndefined() + expect(states["stable-test-view"]).toEqual({ mode: "architect" }) + + // Registering such an id must not make an inherited member look like a + // persisted entry: the lookup still reports an absent entry, so the rekey keeps the + // temporary entry instead of deleting it. + await provider["setViewStateId"]("constructor") + expect(provider["getPersistedViewStates"]({ fresh: true })["constructor"]).toBeUndefined() + }) + + it("does not load a temporary-id entry that an earlier session wrote", async () => { + // Temporary names restart from 0 on every host start, so storage can still hold + // an entry under this instance's name from a previous session. Seed the entry + // through the ContextProxy before the provider is constructed so the ordinary + // loadViewState read (which goes through the proxy cache) actually sees it. + const tempId = `sidebar-${ClineProvider["nextViewId"]}` + const proxy = new ContextProxy(mockContext) + await proxy.setValue("viewStates", { + [tempId]: { mode: "architect", currentApiConfigName: "stale-profile" }, + }) + + const fresh = new ClineProvider(mockContext, mockOutputChannel, "sidebar", proxy, new WebviewFocusTracker()) + expect(fresh.viewId).toBe(tempId) + + // Await the load itself instead of a fixed timer: the negative + // assertion must run after the load has definitely finished. + await fresh["loadViewState"]() + + // The unowned temporary-id entry must not be adopted... + expect(fresh["viewLocalState"]).toStrictEqual({}) + + // ...and the shared values still win, so the stale entry cannot reach getState(). + const state = await fresh.getState() + expect(state.mode).toBe("code") + expect(state.currentApiConfigName).not.toBe("stale-profile") + }) + + it("does not merge a stale temporary-id entry into this instance's first durable write", async () => { + // A first write under an unowned temporary id claims the slot: fields left by an + // earlier session under the same name must not be adopted (and later re-keyed to + // the stable id) by merging into the colliding entry. + const tempId = `sidebar-${ClineProvider["nextViewId"]}` + const proxy = new ContextProxy(mockContext) + await proxy.setValue("viewStates", { [tempId]: { currentApiConfigName: "old-profile", updatedAt: 1 } }) + + const fresh = new ClineProvider(mockContext, mockOutputChannel, "sidebar", proxy, new WebviewFocusTracker()) + expect(fresh.viewId).toBe(tempId) + + await fresh.saveViewState("mode", "code") + + const states = fresh["getPersistedViewStates"]({ fresh: true }) + expect(states[tempId]).toEqual({ + mode: "code", + updatedAt: expect.any(Number), + claimToken: expect.any(String), + }) + expect(fresh["viewLocalState"].currentApiConfigName).toBeUndefined() + }) + + it("does not mark the temporary id as authored when the durable write fails", async () => { + // Authorship must be recorded only after the write lands: a failed persistence + // that still marked the id owned would let a later load adopt an entry that was + // never actually stored. + const tempId = `sidebar-${ClineProvider["nextViewId"]}` + const proxy = new ContextProxy(mockContext) + const fresh = new ClineProvider(mockContext, mockOutputChannel, "sidebar", proxy, new WebviewFocusTracker()) + expect(fresh.viewId).toBe(tempId) + + const originalUpdate = mockContext.globalState.update + mockContext.globalState.update = vi.fn().mockImplementation((key: string, _value: unknown) => { + if (key === "viewStates") { + return Promise.reject(new Error("storage unavailable")) + } + return Promise.resolve() + }) + + await expect(fresh.saveViewState("mode", "code")).rejects.toThrow("storage unavailable") + expect(fresh["wroteUnderTemporaryViewStateId"]).toBe(false) + + mockContext.globalState.update = originalUpdate + }) + + it("does not adopt an entry under the temporary name that this instance never wrote", async () => { + await provider.resolveWebviewView(mockWebviewView) + + // Temporary ids restart from 0 on every host start, so the same name can + // belong to a different session. An entry this instance never wrote must not + // be adopted as this view's state. + // Seed through the durable write path so the assertions below read the + // same backing map a re-key adoption would write to: a frozen get() + // literal made the negative assertion unable to fail. + await provider.contextProxy.setValue("viewStates", { [provider.viewId]: { mode: "architect" } }) + + await provider["setViewStateId"]("stable-test-view") + + const states = provider["getPersistedViewStates"]({ fresh: true }) + expect(states[provider.viewId]).toEqual({ mode: "architect" }) + expect(states["stable-test-view"]).toBeUndefined() + }) + }) + describe("createTaskWithHistoryItem", () => { it("should restore mode from history item when reopening task", async () => { await provider.resolveWebviewView(mockWebviewView) @@ -486,14 +604,15 @@ describe("ClineProvider - Sticky Mode", () => { mode: "architect", // Saved mode } - // Mock updateGlobalState to track mode updates - const updateGlobalStateSpy = vi.spyOn(provider as any, "updateGlobalState").mockResolvedValue(undefined) + // Register a stable view id so the durable per-view write is persisted + await provider["setViewStateId"]("stable-test-view") // Initialize task with history item await provider.createTaskWithHistoryItem(historyItem) - // Verify mode was restored via updateGlobalState - expect(updateGlobalStateSpy).toHaveBeenCalledWith("mode", "architect") + // Verify mode was restored into the view-local pin (no shared global write) + expect(provider["viewLocalState"].mode).toBe("architect") + expect(mockContext.globalState.update).not.toHaveBeenCalledWith("mode", "architect") }) it("should use current mode if history item has no saved mode", async () => { @@ -770,13 +889,20 @@ describe("ClineProvider - Sticky Mode", () => { // Restore the task from history await provider.createTaskWithHistoryItem(historyItem) - // Verify that the mode was restored + // Verify that the mode was restored into this view's durable pin. The + // getState() merge of hydrated per-view values lands with the F1b follow-up. + expect(provider["viewLocalState"].mode).toBe("architect") + const state = await provider.getState() - expect(state.mode).toBe("architect") // Verify that the API configuration was also restored expect(state.currentApiConfigName).toBe("architect-config") expect(state.apiConfiguration.apiProvider).toBe("openai") + // The restored mode lives only in this view's buffer, so the restore must not + // re-bind the shared mode slot. Before the fix this wrote architect-config onto + // the "code" slot, because getState().mode still reported code. + expect(await provider.providerSettingsManager.getModeConfigId("code")).toBe(codeConfigId) + expect(await provider.providerSettingsManager.getModeConfigId("architect")).toBe(architectConfigId) }) it("should handle mode deletion between sessions", async () => { @@ -1275,4 +1401,37 @@ describe("ClineProvider - Sticky Mode", () => { }) }) }) + + describe("setViewStateId input validation", () => { + it("ignores a non-string viewStateId from a crafted message", async () => { + const before = provider["viewStateId"] + // A crafted postMessage can carry any JSON value despite the declared type. + await provider.setViewStateId(42 as unknown as string) + expect(provider["viewStateId"]).toBe(before) + }) + + it("ignores an oversized viewStateId", async () => { + const before = provider["viewStateId"] + await provider.setViewStateId("x".repeat(200)) + expect(provider["viewStateId"]).toBe(before) + }) + + it("refuses a viewStateId already claimed by another live view", async () => { + const other = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + try { + await other.setViewStateId("claimed-by-other-view") + await provider.setViewStateId("claimed-by-other-view") + expect(provider["viewStateId"]).not.toBe("claimed-by-other-view") + expect(other["viewStateId"]).toBe("claimed-by-other-view") + } finally { + await other.dispose() + } + }) + }) }) From 692a818cb174ef4ee1fc5b16cff5539eb6303431 Mon Sep 17 00:00:00 2001 From: easonLiangWorldedtech <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Thu, 29 Oct 2026 21:39:18 +0800 Subject: [PATCH 11/27] chore: prune stale lint suppressions for sticky-mode spec --- src/eslint-suppressions.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/eslint-suppressions.json b/src/eslint-suppressions.json index b85e99d7f7..5460f6bbda 100644 --- a/src/eslint-suppressions.json +++ b/src/eslint-suppressions.json @@ -1021,7 +1021,7 @@ }, "core/webview/__tests__/ClineProvider.sticky-mode.spec.ts": { "@typescript-eslint/no-explicit-any": { - "count": 27 + "count": 26 } }, "core/webview/__tests__/ClineProvider.sticky-profile.spec.ts": { From cb37bbc7df5f0552f677ff87d7924fc6f284c1a2 Mon Sep 17 00:00:00 2001 From: easonLiangWorldedtech <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Thu, 29 Oct 2026 21:56:58 +0800 Subject: [PATCH 12/27] fix(webview): address review findings on view-state durability - omit viewStates (host-minted claim tokens) from settings export - keep a pre-launch selection when registration re-keys onto an existing stable entry - narrow saveViewState keys to the durable per-view subset - skip rollback when another provider wrote a newer shared value - restore the ContextProxy cache when globalState.update rejects - clarify that the claim is enforced by setViewStateId; launch wiring follows --- packages/types/src/vscode-extension-host.ts | 6 ++- src/core/config/ContextProxy.ts | 14 +++++- src/core/webview/ClineProvider.ts | 52 ++++++++++++++++++--- 3 files changed, 61 insertions(+), 11 deletions(-) diff --git a/packages/types/src/vscode-extension-host.ts b/packages/types/src/vscode-extension-host.ts index 233fa7538f..c4e7788928 100644 --- a/packages/types/src/vscode-extension-host.ts +++ b/packages/types/src/vscode-extension-host.ts @@ -681,8 +681,10 @@ export interface WebviewMessage { viewStateId?: string /** * For `webviewDidLaunch`: the host-minted claim previously delivered for `viewStateId`. - * The webview only echoes what it was given; the host rejects an id whose stored claim - * does not match, so a view cannot adopt another view's persisted selections. + * The webview only echoes what it was given; the host enforces the match in + * `ClineProvider.setViewStateId` when a view registers this id, so a view cannot adopt + * another view's persisted selections. Forwarding these fields from the launch handler + * is wired by the follow-up launch unit. */ viewStateClaim?: string taskId?: string diff --git a/src/core/config/ContextProxy.ts b/src/core/config/ContextProxy.ts index 4e20305f48..8678e02219 100644 --- a/src/core/config/ContextProxy.ts +++ b/src/core/config/ContextProxy.ts @@ -363,13 +363,23 @@ export class ContextProxy { return value !== undefined ? value : defaultValue } - updateGlobalState(key: K, value: GlobalState[K]) { + async updateGlobalState(key: K, value: GlobalState[K]) { if (isPassThroughStateKey(key)) { return this.originalContext.globalState.update(key, value) } + const previousCachedValue = this.stateCache[key] this.stateCache[key] = value - return this.originalContext.globalState.update(key, value) + + try { + return await this.originalContext.globalState.update(key, value) + } catch (error) { + // A rejected write must not leave the cache ahead of storage: callers that then + // read the cached value (e.g. the view-state load path) would act on a selection + // that was never persisted. + this.stateCache[key] = previousCachedValue + throw error + } } private getAllGlobalState(): GlobalState { diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index 831a1c366d..6a06ff26b6 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -148,6 +148,13 @@ type PersistedViewState = NonNullable[string] */ type ViewLocalStateValues = Partial & Partial +/** + * The subset of view-local values that has a durable per-view record. `saveViewState` + * and the mutation path handle exactly these keys, so the generic stays narrow enough + * for the compiler to reject e.g. `writeDelayMs`. + */ +type PersistedViewStateValues = Pick + /** * https://github.com/microsoft/vscode-webview-ui-toolkit-samples/blob/main/default/weather-webview/src/providers/WeatherViewProvider.ts * https://github.com/KumarVariable/vscode-extension-sidebar-html/blob/master/src/customSidebarViewProvider.ts @@ -774,8 +781,19 @@ export class ClineProvider delete states[previousViewStateId] - if (!states[nextViewStateId]) { + const existingStableEntry = states[nextViewStateId] + + if (!existingStableEntry) { states[nextViewStateId] = previous + } else { + // Registration can bind a claim-less legacy key just before this pre-launch entry + // is re-keyed. Keep the selections the stable entry already carries, but fill in + // anything it lacks so a mode chosen before launch is not silently dropped. + states[nextViewStateId] = { + ...previous, + ...existingStableEntry, + updatedAt: Math.max(previous.updatedAt ?? 0, existingStableEntry.updatedAt ?? 0), + } } await this.contextProxy.setValue("viewStates", this.prunePersistedViewStates(states)) @@ -1024,9 +1042,9 @@ export class ClineProvider * non-secret subset (mode, currentApiConfigName) is persisted durably under the view * id active when the change was made, re-keyed to the stable id on registration. */ - public async saveViewState( + public async saveViewState( key: K, - value: ViewLocalStateValues[K] | undefined, + value: PersistedViewStateValues[K] | undefined, ): Promise { await this._saveViewLocalStateFromMutation({ [key]: value } as ViewLocalStateValues) @@ -4076,7 +4094,9 @@ export class ClineProvider } catch (error) { // The per-view record did not land: restore the prior shared value so the two // persistence layers cannot diverge, then surface the original failure. - await this._restoreSharedValuesAfterFailedViewWrite(previousSharedValues) + await this._restoreSharedValuesAfterFailedViewWrite(previousSharedValues, { + [key]: value, + } as RooCodeSettings) throw error } } @@ -4113,7 +4133,7 @@ export class ClineProvider } catch (error) { // The per-view record did not land: restore the prior shared values so the two // persistence layers cannot diverge, then surface the original failure. - await this._restoreSharedValuesAfterFailedViewWrite(previousSharedValues) + await this._restoreSharedValuesAfterFailedViewWrite(previousSharedValues, sanitizedValues) throw error } } @@ -5556,9 +5576,27 @@ export class ClineProvider * per-view persistence failed so the shared store cannot move ahead of the per-view * record. A failed rollback is logged; the original failure is what callers see. */ - private async _restoreSharedValuesAfterFailedViewWrite(previous: RooCodeSettings): Promise { + private async _restoreSharedValuesAfterFailedViewWrite( + previous: RooCodeSettings, + attempted: RooCodeSettings, + ): Promise { + // Roll back only the keys this attempt wrote and that still hold the value it wrote. + // A concurrent provider may have written a newer value in the meantime; restoring the + // captured previous value would then clobber it for every view that reads shared state. + const rollback: RooCodeSettings = {} as RooCodeSettings + + for (const key of Object.keys(attempted) as (keyof RooCodeSettings)[]) { + if (this.contextProxy.getValue(key) === attempted[key]) { + ;(rollback as Record)[key] = previous[key] + } + } + + if (Object.keys(rollback).length === 0) { + return + } + try { - await this.contextProxy.setValues(previous) + await this.contextProxy.setValues(rollback) } catch (rollbackError) { this.log( `[ClineProvider] Shared-state rollback after failed per-view write failed: ${rollbackError instanceof Error ? rollbackError.message : String(rollbackError)}`, From 5b8c6396bb1efda4343838d453978720ecec0823 Mon Sep 17 00:00:00 2001 From: easonLiangWorldedtech <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Fri, 30 Oct 2026 12:03:51 +0800 Subject: [PATCH 13/27] fix(config): keep a newer cached value when an older global-state write rejects Track a per-key write generation so a rejected write only rolls the cache back while it is still the newest write for that key; also stop tracking the generated .husky/_ hook files. --- .husky/_/post-checkout | 3 --- .husky/_/post-commit | 3 --- .husky/_/post-merge | 3 --- .husky/_/pre-push | 3 --- src/core/config/ContextProxy.ts | 14 +++++++++---- .../config/__tests__/ContextProxy.spec.ts | 21 +++++++++++++++++++ 6 files changed, 31 insertions(+), 16 deletions(-) delete mode 100644 .husky/_/post-checkout delete mode 100644 .husky/_/post-commit delete mode 100644 .husky/_/post-merge delete mode 100644 .husky/_/pre-push diff --git a/.husky/_/post-checkout b/.husky/_/post-checkout deleted file mode 100644 index 5abf8ed93f..0000000000 --- a/.husky/_/post-checkout +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -command -v git-lfs >/dev/null 2>&1 || { printf >&2 "\n%s\n\n" "This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-checkout' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks')."; exit 2; } -git lfs post-checkout "$@" diff --git a/.husky/_/post-commit b/.husky/_/post-commit deleted file mode 100644 index b8b76c2c42..0000000000 --- a/.husky/_/post-commit +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -command -v git-lfs >/dev/null 2>&1 || { printf >&2 "\n%s\n\n" "This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-commit' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks')."; exit 2; } -git lfs post-commit "$@" diff --git a/.husky/_/post-merge b/.husky/_/post-merge deleted file mode 100644 index 726f909891..0000000000 --- a/.husky/_/post-merge +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -command -v git-lfs >/dev/null 2>&1 || { printf >&2 "\n%s\n\n" "This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-merge' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks')."; exit 2; } -git lfs post-merge "$@" diff --git a/.husky/_/pre-push b/.husky/_/pre-push deleted file mode 100644 index 5f26dc4552..0000000000 --- a/.husky/_/pre-push +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -command -v git-lfs >/dev/null 2>&1 || { printf >&2 "\n%s\n\n" "This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'pre-push' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks')."; exit 2; } -git lfs pre-push "$@" diff --git a/src/core/config/ContextProxy.ts b/src/core/config/ContextProxy.ts index 8678e02219..1e7815e8dd 100644 --- a/src/core/config/ContextProxy.ts +++ b/src/core/config/ContextProxy.ts @@ -45,6 +45,7 @@ export class ContextProxy { private readonly originalContext: vscode.ExtensionContext private stateCache: GlobalState + private stateWriteGenerations = new Map() private secretCache: SecretState private _isInitialized = false @@ -369,15 +370,20 @@ export class ContextProxy { } const previousCachedValue = this.stateCache[key] + const generation = (this.stateWriteGenerations.get(key) ?? 0) + 1 + this.stateWriteGenerations.set(key, generation) this.stateCache[key] = value try { return await this.originalContext.globalState.update(key, value) } catch (error) { - // A rejected write must not leave the cache ahead of storage: callers that then - // read the cached value (e.g. the view-state load path) would act on a selection - // that was never persisted. - this.stateCache[key] = previousCachedValue + // A rejected write must not leave the cache ahead of storage, but a *newer* write + // for the same key may already have replaced the cached value: restoring here would + // then roll the cache back behind storage. Only undo this write while it is still + // the newest one for the key. + if (this.stateWriteGenerations.get(key) === generation) { + this.stateCache[key] = previousCachedValue + } throw error } } diff --git a/src/core/config/__tests__/ContextProxy.spec.ts b/src/core/config/__tests__/ContextProxy.spec.ts index f9fa9cdb15..79cb0471d2 100644 --- a/src/core/config/__tests__/ContextProxy.spec.ts +++ b/src/core/config/__tests__/ContextProxy.spec.ts @@ -120,6 +120,27 @@ describe("ContextProxy", () => { expect(result).toBe("deepseek") }) + it("should not let an older rejected write clobber a newer cached value", async () => { + let rejectFirst: (error: Error) => void = () => {} + const firstWriteResult = new Promise((_, reject) => { + rejectFirst = reject + }) + + mockGlobalState.update.mockReset() + mockGlobalState.update.mockReturnValueOnce(firstWriteResult) + mockGlobalState.update.mockResolvedValueOnce(undefined) + + const firstWrite = proxy.updateGlobalState("apiProvider", "anthropic") + await proxy.updateGlobalState("apiProvider", "openai") + + // The older write rejects after a newer value already reached the cache: rolling + // the cache back to the pre-first-write value would diverge from storage. + rejectFirst(new Error("disk full")) + await expect(firstWrite).rejects.toThrow("disk full") + + expect(proxy.getGlobalState("apiProvider")).toBe("openai") + }) + it("should bypass cache for pass-through state keys", async () => { // Setup mock return value mockGlobalState.get.mockReturnValue("pass-through-value") From 709f1168533176c6013919fb714057f4cd1ee28e Mon Sep 17 00:00:00 2001 From: easonLiangWorldedtech <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Fri, 30 Oct 2026 12:06:06 +0800 Subject: [PATCH 14/27] fix(webview): address review findings on pruning, mode-switch and profile deletion - prune persisted view states: never age out entries of live views - mode switch: drop the unconditional shared-mode rollback (setValue already guards it) - mode switch: restore the pre/post-read abort guards around mode config reads - deleteProviderProfile: point the settings manager at the surviving profile --- src/core/webview/ClineProvider.ts | 57 ++++++--- .../webview/__tests__/ClineProvider.spec.ts | 113 ++++++++++++++++++ 2 files changed, 154 insertions(+), 16 deletions(-) diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index 6a06ff26b6..bbf62caeb8 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -742,11 +742,22 @@ export class ClineProvider * bounded by MAX_PERSISTED_VIEW_STATES so the global key cannot grow unboundedly. */ private prunePersistedViewStates(states: Record): Record { - return Object.fromEntries( - Object.entries(states) - .sort(([, a], [, b]) => (b.updatedAt ?? 0) - (a.updatedAt ?? 0)) - .slice(0, ClineProvider.MAX_PERSISTED_VIEW_STATES), + // Entries of live views must never age out: a view that keeps its mode and profile + // does not refresh updatedAt, so 50 newer closed-view entries would otherwise evict + // the state a still-open view needs after its next reload. The cap applies to + // closed-view entries only. + const liveViewStateIds = new Set( + Array.from(ClineProvider.activeInstances, (instance) => instance.viewStateId).filter( + (viewStateId): viewStateId is string => Boolean(viewStateId), + ), ) + const liveEntries = Object.entries(states).filter(([viewStateId]) => liveViewStateIds.has(viewStateId)) + const closedEntries = Object.entries(states) + .filter(([viewStateId]) => !liveViewStateIds.has(viewStateId)) + .sort(([, a], [, b]) => (b.updatedAt ?? 0) - (a.updatedAt ?? 0)) + .slice(0, ClineProvider.MAX_PERSISTED_VIEW_STATES) + + return Object.fromEntries([...liveEntries, ...closedEntries]) } /** @@ -2378,21 +2389,12 @@ export class ClineProvider // buffer stays in sync with the durable global write: getValues() merges // viewLocalState on top of the ContextProxy values, so an unsynced stale // restored mode would otherwise shadow the fresh switch for consumers. - // If the durable write fails, roll the shared write back so getValues() - // cannot mix a fresh shared mode with the stale pre-switch buffer. - const previousMode = this.getValue("mode") + // setValue already restores the shared value when the per-view write fails, and that + // restore is value-guarded; an unconditional rollback here would overwrite a mode + // another provider wrote while this write was in flight. try { await this.setValue("mode", newMode) } catch (error) { - try { - await this.contextProxy.setValue("mode", previousMode) - } catch (rollbackError) { - this.log( - `[handleModeSwitch] Failed to roll back shared mode after persistence failure: ${ - rollbackError instanceof Error ? rollbackError.message : String(rollbackError) - }`, - ) - } this.log( `[handleModeSwitch] Failed to persist mode "${newMode}": ${error instanceof Error ? error.message : String(error)}`, ) @@ -2410,10 +2412,17 @@ export class ClineProvider return } + // A provider-profile mutation timeout must stop this path instead of letting it + // persist a profile the running task no longer agrees with: guard before the reads + // and again after them, because an abort can land while they are in flight. + if (signal?.aborted) return + // Load the saved API config for the new mode if it exists. const savedConfigId = await this.providerSettingsManager.getModeConfigId(newMode) const listApiConfig = await this.providerSettingsManager.listConfig() + if (signal?.aborted) return + // Update listApiConfigMeta first to ensure UI has latest data. await this.updateGlobalState("listApiConfigMeta", listApiConfig) @@ -2785,6 +2794,22 @@ export class ClineProvider const viewWasPinnedToDeleted = this.viewLocalState.currentApiConfigName === profileToDelete.name const deletedWasGlobal = profileToDelete.name === globalSettings.currentApiConfigName + // deleteConfig removed the profile but leaves the settings manager's stored + // currentApiConfigName naming it, so a later export would write a selection the + // profile list no longer contains (and import would silently pick another profile). + // Point the manager at the survivor too. + if (deletedWasGlobal) { + try { + await this.providerSettingsManager.activateProfile({ name: profileToActivate }) + } catch (error) { + this.log( + `[deleteProviderProfile] Failed to update the settings manager's current profile to '${profileToActivate}': ${ + error instanceof Error ? error.message : String(error) + }`, + ) + } + } + if (viewWasPinnedToDeleted) { // This view's pin now dangles: re-point it. setValue also persists the // survivor to the shared store, which covers the deleted-was-global case diff --git a/src/core/webview/__tests__/ClineProvider.spec.ts b/src/core/webview/__tests__/ClineProvider.spec.ts index 2d1425640e..a43eccc131 100644 --- a/src/core/webview/__tests__/ClineProvider.spec.ts +++ b/src/core/webview/__tests__/ClineProvider.spec.ts @@ -3119,6 +3119,92 @@ describe("ClineProvider", () => { // Verify state was posted to webview expect(mockPostMessage).toHaveBeenCalledWith(expect.objectContaining({ type: "state" })) }) + + it("does not read mode config or activate a profile when the mutation is already aborted", async () => { + const getModeConfigId = vi.fn().mockResolvedValue("saved-config-id") + const listConfig = vi.fn().mockResolvedValue([]) + const activateProfile = vi.fn().mockResolvedValue({}) + + ;(provider as any).providerSettingsManager = { + getModeConfigId, + listConfig, + activateProfile, + setModeConfig: vi.fn(), + getProfile: vi.fn(), + } as any + + const controller = new AbortController() + controller.abort() + + await provider["handleModeSwitchUnlocked"]("architect", undefined, controller.signal) + + expect(getModeConfigId).not.toHaveBeenCalled() + expect(activateProfile).not.toHaveBeenCalled() + }) + + it("stops before activating a profile when the mutation aborts during the mode config reads", async () => { + const profile: ProviderSettingsEntry = { + name: "saved-config", + id: "saved-config-id", + apiProvider: providerIdentifiers.anthropic, + } + const controller = new AbortController() + const getModeConfigId = vi.fn().mockResolvedValue("saved-config-id") + const listConfig = vi.fn().mockImplementation(async () => { + controller.abort() + return [profile] + }) + const activateProfile = vi.fn().mockResolvedValue(profile) + + ;(provider as any).providerSettingsManager = { + getModeConfigId, + listConfig, + activateProfile, + setModeConfig: vi.fn(), + getProfile: vi.fn().mockResolvedValue(profile), + } as any + + await provider["handleModeSwitchUnlocked"]("architect", undefined, controller.signal) + + expect(activateProfile).not.toHaveBeenCalled() + }) + }) + + describe("deleteProviderProfile", () => { + it("moves the settings manager's current profile to the survivor when the active profile is deleted", async () => { + const contextProxy = new ContextProxy(mockContext) + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + contextProxy, + new WebviewFocusTracker(), + ) + const profileToDelete: ProviderSettingsEntry = { name: "deleted", id: "deleted-id" } + + await contextProxy.setValue("listApiConfigMeta", [ + { name: "deleted", id: "deleted-id" }, + { name: "survivor", id: "survivor-id" }, + ]) + await contextProxy.setValue("currentApiConfigName", "deleted") + + const activateProfile = vi.fn().mockResolvedValue({ name: "survivor" }) + + ;(provider as any).providerSettingsManager = { + deleteConfig: vi.fn().mockResolvedValue(undefined), + activateProfile, + getProfile: vi.fn().mockResolvedValue({ + name: "survivor", + apiProvider: providerIdentifiers.anthropic, + }), + } as any + + await provider.deleteProviderProfile(profileToDelete) + + expect(activateProfile).toHaveBeenCalledWith({ name: "survivor" }) + + await provider.dispose() + }) }) describe("updateCustomMode", () => { @@ -4117,6 +4203,33 @@ describe("ClineProvider", () => { await provider.dispose() }) + + it("keeps the entry of a live view outside the 50-entry cutoff", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + await provider["setViewStateId"]("live-view") + + const states: Record = Object.fromEntries( + Array.from({ length: 55 }, (_, index) => [ + `closed-${index}`, + { mode: `mode-${index}`, updatedAt: index + 1 }, + ]), + ) + // The live view's entry is the oldest and would be evicted by the plain cutoff. + states["live-view"] = { mode: "architect", updatedAt: 0 } + + const pruned = provider["prunePersistedViewStates"](states) + + expect(pruned["live-view"]).toEqual({ mode: "architect", updatedAt: 0 }) + expect(Object.keys(pruned)).toHaveLength(51) + + await provider.dispose() + }) }) it("should merge concurrent persisted updates from separate provider instances without lost viewStates", async () => { From 9f2ab6f86eeceab2a3249c427b49a96f0e86b765 Mon Sep 17 00:00:00 2001 From: easonLiangWorldedtech <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Fri, 30 Oct 2026 12:21:07 +0800 Subject: [PATCH 15/27] chore: restore the main-tracked husky hooks The generated .husky/_ files stay untracked; pre-commit/pre-push belong to main and must not be deleted by the unit. --- .husky/pre-commit | 26 ++++++++++++++++++++++++++ .husky/pre-push | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 .husky/pre-commit create mode 100644 .husky/pre-push diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 0000000000..f8f420dac7 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,26 @@ +branch="$(git rev-parse --abbrev-ref HEAD)" + +if [ "$branch" = "main" ]; then + echo "You can't commit directly to main - please check out a branch." + exit 1 +fi + +# Detect if running on Windows and use pnpm.cmd, otherwise use pnpm. +if [ "$OS" = "Windows_NT" ]; then + pnpm_cmd="pnpm.cmd" +else + if command -v pnpm >/dev/null 2>&1; then + pnpm_cmd="pnpm" + else + pnpm_cmd="npx pnpm" + fi +fi + +# Detect if running on Windows and use npx.cmd, otherwise use npx. +if [ "$OS" = "Windows_NT" ]; then + npx_cmd="npx.cmd" +else + npx_cmd="npx" +fi + +$npx_cmd lint-staged diff --git a/.husky/pre-push b/.husky/pre-push new file mode 100644 index 0000000000..4cf91d9580 --- /dev/null +++ b/.husky/pre-push @@ -0,0 +1,42 @@ +branch="$(git rev-parse --abbrev-ref HEAD)" + +if [ "$branch" = "main" ]; then + echo "You can't push directly to main - please check out a branch." + exit 1 +fi + +# Detect if running on Windows and use pnpm.cmd, otherwise use pnpm. +if [ "$OS" = "Windows_NT" ]; then + pnpm_cmd="pnpm.cmd" +else + if command -v pnpm >/dev/null 2>&1; then + pnpm_cmd="pnpm" + else + pnpm_cmd="npx pnpm" + fi +fi + +$pnpm_cmd run check-types + +# Use dotenvx to securely load .env.local and run commands that depend on it +if [ -f ".env.local" ]; then + # Check if RUN_TESTS_ON_PUSH is set to true and run tests with dotenvx + if npx dotenvx get RUN_TESTS_ON_PUSH -f .env.local 2>/dev/null | grep -q "^true$"; then + npx dotenvx run -f .env.local -- $pnpm_cmd run test + fi +else + # Fallback: run tests if RUN_TESTS_ON_PUSH is set in regular environment + if [ "$RUN_TESTS_ON_PUSH" = "true" ]; then + $pnpm_cmd run test + fi +fi + +# Check for new changesets. +NEW_CHANGESETS=$(find .changeset -name "*.md" ! -name "README.md" | wc -l | tr -d ' ') +echo "Changeset files: $NEW_CHANGESETS" + +if [ "$NEW_CHANGESETS" = "0" ]; then + echo "-------------------------------------------------------------------------------------" + echo "Changes detected. Please run 'pnpm changeset' to create a changeset if applicable." + echo "-------------------------------------------------------------------------------------" +fi From 23054c99a4e6094cc4cd293c75d2b4d046fb2f1c Mon Sep 17 00:00:00 2001 From: easonLiangWorldedtech <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Fri, 30 Oct 2026 12:21:20 +0800 Subject: [PATCH 16/27] chore: tighten the new review-fix comments --- src/core/webview/ClineProvider.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index bbf62caeb8..5a3b7c27c5 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -742,10 +742,8 @@ export class ClineProvider * bounded by MAX_PERSISTED_VIEW_STATES so the global key cannot grow unboundedly. */ private prunePersistedViewStates(states: Record): Record { - // Entries of live views must never age out: a view that keeps its mode and profile - // does not refresh updatedAt, so 50 newer closed-view entries would otherwise evict - // the state a still-open view needs after its next reload. The cap applies to - // closed-view entries only. + // Entries of live views must never age out: a view that keeps its mode and profile does + // not refresh updatedAt. The cap applies to closed-view entries only. const liveViewStateIds = new Set( Array.from(ClineProvider.activeInstances, (instance) => instance.viewStateId).filter( (viewStateId): viewStateId is string => Boolean(viewStateId), @@ -2390,8 +2388,7 @@ export class ClineProvider // viewLocalState on top of the ContextProxy values, so an unsynced stale // restored mode would otherwise shadow the fresh switch for consumers. // setValue already restores the shared value when the per-view write fails, and that - // restore is value-guarded; an unconditional rollback here would overwrite a mode - // another provider wrote while this write was in flight. + // restore is value-guarded: an unconditional rollback here would overwrite a newer mode. try { await this.setValue("mode", newMode) } catch (error) { From 17c671113adf22a57170d3b7467a76d9fea56505 Mon Sep 17 00:00:00 2001 From: easonLiangWorldedtech <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Fri, 30 Oct 2026 12:22:06 +0800 Subject: [PATCH 17/27] chore: tighten the shared review-fix comments --- src/core/config/ContextProxy.ts | 6 +-- src/core/webview/ClineProvider.ts | 79 ++++++++----------------------- 2 files changed, 21 insertions(+), 64 deletions(-) diff --git a/src/core/config/ContextProxy.ts b/src/core/config/ContextProxy.ts index 1e7815e8dd..a284c8444b 100644 --- a/src/core/config/ContextProxy.ts +++ b/src/core/config/ContextProxy.ts @@ -377,10 +377,8 @@ export class ContextProxy { try { return await this.originalContext.globalState.update(key, value) } catch (error) { - // A rejected write must not leave the cache ahead of storage, but a *newer* write - // for the same key may already have replaced the cached value: restoring here would - // then roll the cache back behind storage. Only undo this write while it is still - // the newest one for the key. + // A newer write for the same key may already own the cache: only undo this write + // while it is still the newest one. if (this.stateWriteGenerations.get(key) === generation) { this.stateCache[key] = previousCachedValue } diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index 5a3b7c27c5..2e06f38dee 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -944,21 +944,13 @@ export class ClineProvider } } - /** - * Loads non-secret persisted selections from the registered viewStates map. - * Missing entries are intentionally left unset so getState() falls back to shared ContextProxy values. - * Fields mutated while the async profile lookup is in flight are reapplied on top of the - * loaded state, field by field, so in-flight user selections are not clobbered by the load. - */ + /** Load non-secret persisted selections; in-flight buffer edits are reapplied on top. */ private async loadViewState(): Promise { - // Capture the id this load is for: a newer id registered while an async - // profile lookup is in flight must not be overwritten by this stale load. + // A newer id registered while this load is in flight must win. const loadedForViewId = this.viewStateId - // While the stable id has not been registered yet, the key is this instance's - // session-local name. Temporary names restart from 0 on every host start, so an - // entry under the same name can belong to a different session. Load only entries - // this instance authored. + // Before registration the key is the session-local name, which can be a stale entry + // from another session: load only entries this instance authored. if (loadedForViewId === this.viewId && !this.wroteUnderTemporaryViewStateId) { return } @@ -966,15 +958,12 @@ export class ClineProvider const persisted = this.getPersistedViewStates()[loadedForViewId] const loadedState: Partial = {} - // Snapshot the in-memory buffer before the async profile lookup. The - // mutation paths update viewLocalState in place, so a shallow copy is - // what makes fields mutated during the load window observable below. + // The mutation paths update viewLocalState in place; a shallow snapshot makes + // in-flight edits observable below. const preLoadBuffer = { ...this.viewLocalState } if (persisted?.mode) { - // A persisted mode may reference a custom mode that was deleted after it was - // pinned: restore it only when the slug still resolves, so a stale slug cannot - // shadow the shared mode from getState(). + // A stale custom-mode slug must not shadow the shared mode from getState(). const customModes = await this.customModesManager.getCustomModes() if (getModeBySlug(persisted.mode, customModes)) { loadedState.mode = persisted.mode as Mode @@ -1003,13 +992,8 @@ export class ClineProvider return } - // Reapply the buffer fields that changed while the load was in flight, - // tracking the change instead of testing against undefined: a field cleared - // during the load window must stay cleared (the loaded value must not - // resurrect it), and a field written to a new value must win over it. - // Untouched fields keep the persisted values authoritative, and the - // pre-load buffer is never merged wholesale so stale temporary-id state - // cannot override the stable persisted state. + // Diff each field so in-flight edits win over the loaded values (including clears) + // while untouched fields keep the persisted values authoritative. const postLoadBuffer = this.viewLocalState const mergedState: Partial = { ...loadedState } @@ -1046,11 +1030,7 @@ export class ClineProvider } } - /** - * Saves a single view-local state value. The in-memory buffer is always updated; the - * non-secret subset (mode, currentApiConfigName) is persisted durably under the view - * id active when the change was made, re-keyed to the stable id on registration. - */ + /** Save one view-local value; the durable subset is re-keyed to the stable id. */ public async saveViewState( key: K, value: PersistedViewStateValues[K] | undefined, @@ -2673,16 +2653,11 @@ export class ClineProvider // `allSettled` so a caller that rolls back after a failure never races a write still in flight. const activationResults = await Promise.allSettled([ this.updateGlobalState("listApiConfigMeta", await this.providerSettingsManager.listConfig()), - // Route through setValue so the in-memory viewLocalState buffer tracks the - // activated profile: a plain global write would leave a stale loaded - // currentApiConfigName shadowing the new value in getValues(). + // Route through setValue so the buffer tracks the activated profile. this.setValue("currentApiConfigName", name), this.providerSettingsManager.setModeConfig(mode, id), this.contextProxy.setProviderSettings(providerSettings), - // setProviderSettings writes the shared store directly, bypassing the - // view-local mutation path: also refresh this view's buffer so a stale - // loaded apiConfiguration cannot keep shadowing the new settings in - // getState(). + // setProviderSettings bypasses the buffer path: refresh this view's overlay. this._saveViewLocalStateFromMutation({ apiConfiguration: providerSettings }), ]) const failedActivation = activationResults.find( @@ -2693,9 +2668,7 @@ export class ClineProvider if (signal.aborted) return id - // Other live views may have buffered this profile's settings earlier; - // refresh them so their getState() cannot report the updated profile's - // name with stale settings. + // Refresh other views pinned to this profile so their overlays cannot go stale. // Change the provider for the current task. // TODO: We should rename `buildApiHandler` for clarity (e.g. `getProviderClient`). @@ -2706,16 +2679,11 @@ export class ClineProvider } else { await this.updateGlobalState("listApiConfigMeta", await this.providerSettingsManager.listConfig()) - // A save that does not activate still changes the profile's settings, and - // every view pinned to it buffers a full copy of them. Refresh those views - // (and this one when it is the pinned view) or their getState() keeps - // serving the settings captured before the save under the same name. + // A non-activating save still changes the profile's settings: refresh the views + // that buffered a copy, or their getState() keeps the pre-save values. if (this.pinnedProfileName === name) { await this._saveViewLocalStateFromMutation({ apiConfiguration: providerSettings }) - // Only rebuild when the task actually runs under the saved profile: a - // view pinned to this profile can hold a task that follows a different - // sticky profile, and the forced rebuild would silently switch that - // conversation to the saved profile's settings. + // Only rebuild a task that actually runs under the saved profile. if (this.getCurrentTask()?.taskApiConfigName === name) { this.updateTaskApiHandlerIfNeeded(providerSettings, { forceRebuild: true }) } @@ -4160,11 +4128,7 @@ export class ClineProvider } } - /** - * Persists the view-local subset of a ContextProxy mutation, then updates the in-memory - * viewLocalState buffer. Persistence is awaited first so a failed durable write cannot - * leave the local cache ahead of the persisted state. - */ + /** Persist the durable subset first, then update the in-memory buffer. */ private async _saveViewLocalStateFromMutation( values: Partial & Partial, ): Promise { @@ -4172,10 +4136,7 @@ export class ClineProvider this._updateViewLocalStateFromMutation(values) } - /** - * Writes the durably persisted subset of a mutation (mode and currentApiConfigName) - * into the registered viewStates map for this view. - */ + /** Write the durable subset of a mutation into this view's viewStates entry. */ private async _persistViewLocalStateFromMutation( values: Partial & Partial, ): Promise { @@ -4194,9 +4155,7 @@ export class ClineProvider } } - /** - * Clear view-local state cache so that getState() falls back to ContextProxy defaults. - */ + /** Clear the buffer so getState() falls back to the shared values. */ private _clearViewLocalState(): void { this.viewLocalState = {} } From 69abf702537dd7e6e0f66f3e3e8b3e3ffe83e49a Mon Sep 17 00:00:00 2001 From: easonLiangWorldedtech <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Fri, 30 Oct 2026 12:30:34 +0800 Subject: [PATCH 18/27] fix(config): advance write generations on reset A write pending across resetAllState() must not restore its pre-reset value when it rejects afterwards; bump the generation of every tracked key during the reset, with a test. --- src/core/config/ContextProxy.ts | 5 +++++ .../config/__tests__/ContextProxy.spec.ts | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/core/config/ContextProxy.ts b/src/core/config/ContextProxy.ts index a284c8444b..e6aea60685 100644 --- a/src/core/config/ContextProxy.ts +++ b/src/core/config/ContextProxy.ts @@ -607,6 +607,11 @@ export class ContextProxy { // Clear in-memory caches this.stateCache = {} this.secretCache = {} + // A write that started before this reset must not restore its pre-reset value when it + // rejects afterwards, so advance every generation the pending writes still hold. + for (const key of this.stateWriteGenerations.keys()) { + this.stateWriteGenerations.set(key, (this.stateWriteGenerations.get(key) ?? 0) + 1) + } await Promise.all([ ...GLOBAL_STATE_KEYS.map((key) => this.originalContext.globalState.update(key, undefined)), diff --git a/src/core/config/__tests__/ContextProxy.spec.ts b/src/core/config/__tests__/ContextProxy.spec.ts index 79cb0471d2..a28ca249ac 100644 --- a/src/core/config/__tests__/ContextProxy.spec.ts +++ b/src/core/config/__tests__/ContextProxy.spec.ts @@ -141,6 +141,25 @@ describe("ContextProxy", () => { expect(proxy.getGlobalState("apiProvider")).toBe("openai") }) + it("should not restore a pre-reset value when a pending write rejects after reset", async () => { + let rejectPending: (error: Error) => void = () => {} + mockGlobalState.update.mockReset() + mockGlobalState.update.mockReturnValueOnce( + new Promise((_, reject) => { + rejectPending = reject + }), + ) + + const pending = proxy.updateGlobalState("apiProvider", "anthropic") + await proxy.resetAllState() + rejectPending(new Error("disk full")) + + await expect(pending).rejects.toThrow("disk full") + // The reset cleared the cache: restoring the pre-reset value would resurrect state + // that storage no longer holds. + expect(proxy.getGlobalState("apiProvider")).toBeUndefined() + }) + it("should bypass cache for pass-through state keys", async () => { // Setup mock return value mockGlobalState.get.mockReturnValue("pass-through-value") From 530d777c02626ac2d78cb413b989c93af70099a2 Mon Sep 17 00:00:00 2001 From: easonLiangWorldedtech <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Fri, 30 Oct 2026 12:31:38 +0800 Subject: [PATCH 19/27] chore: align the shared view-identity docs with N1 --- packages/types/src/global-settings.ts | 6 +-- packages/types/src/vscode-extension-host.ts | 5 +-- src/core/config/ProviderSettingsManager.ts | 7 +-- src/core/webview/ClineProvider.ts | 47 ++++----------------- 4 files changed, 13 insertions(+), 52 deletions(-) diff --git a/packages/types/src/global-settings.ts b/packages/types/src/global-settings.ts index b09bae2635..3da73ee0fe 100644 --- a/packages/types/src/global-settings.ts +++ b/packages/types/src/global-settings.ts @@ -122,10 +122,8 @@ export const viewStateSchema = z.object({ currentApiConfigName: z.string().optional(), updatedAt: z.number().optional(), /** - * Host-minted capability token binding this entry to the webview that wrote it. - * Minted by the extension host (`crypto.randomUUID()`), delivered to that webview and - * never accepted from webview input. An entry is only re-adopted for a webview that - * presents this token, so a view cannot read another (e.g. closed) view's selections. + * Host-minted capability token binding this entry to the webview that wrote it; never + * accepted from webview input and only a matching token re-adopts the entry. */ claimToken: z.string().optional(), }) diff --git a/packages/types/src/vscode-extension-host.ts b/packages/types/src/vscode-extension-host.ts index c4e7788928..c77dbb14c4 100644 --- a/packages/types/src/vscode-extension-host.ts +++ b/packages/types/src/vscode-extension-host.ts @@ -681,10 +681,7 @@ export interface WebviewMessage { viewStateId?: string /** * For `webviewDidLaunch`: the host-minted claim previously delivered for `viewStateId`. - * The webview only echoes what it was given; the host enforces the match in - * `ClineProvider.setViewStateId` when a view registers this id, so a view cannot adopt - * another view's persisted selections. Forwarding these fields from the launch handler - * is wired by the follow-up launch unit. + * Enforced by `ClineProvider.setViewStateId`; launch forwarding ships in the wiring unit. */ viewStateClaim?: string taskId?: string diff --git a/src/core/config/ProviderSettingsManager.ts b/src/core/config/ProviderSettingsManager.ts index 306253578a..07a5fc3d21 100644 --- a/src/core/config/ProviderSettingsManager.ts +++ b/src/core/config/ProviderSettingsManager.ts @@ -55,12 +55,7 @@ export const providerProfilesSchema = z.object({ export type ProviderProfiles = z.infer -/** - * Signals that a profile's configuration no longer exists. Callers that treat an - * already-deleted profile as an idempotent no-op branch on this type instead of - * matching error message text, which a profile name containing the phrase could - * otherwise spoof. - */ +/** Already-deleted profile: callers branch on this type instead of matching message text. */ export class ProviderSettingsNotFoundError extends Error { constructor(message: string) { super(message) diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index 2e06f38dee..4ead993323 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -377,12 +377,8 @@ export class ClineProvider public readonly viewId: string /** - * Stable identifier for persisted per-view state keys. - * Defaults to viewId until the webview reports its VS Code-persisted id. - * A durable entry under this id is bound to the webview that wrote it by a host-minted - * claim token (see setViewStateId), so the entry - and the profile its pin brings back - * into the state post - can outlive this instance without becoming adoptable by any - * other webview. + * Stable identifier for persisted per-view state keys; binds a durable entry to the + * webview that wrote it through the host-minted claim token. */ private viewStateId: string @@ -605,13 +601,8 @@ export class ClineProvider } /** - * Persists this view's non-secret selections through the serialized write queue. - * The write re-reads the map fresh and merges into the existing entry, removing the - * entry entirely when nothing persistable remains, so concurrent views cannot clobber it. - * The entry is keyed by the view id active when the change was made. Writes captured - * while the provider still holds its temporary (pre-launch) id persist under that id - * and are re-keyed to the stable view id when the webview registers one, so a change - * that lands before the launch message stays durable instead of being lost. + * Persist the non-secret selections through the serialized write queue, re-keying a + * pre-launch write to the stable id once the webview registers one. */ private async savePersistedViewState(values: Partial): Promise { // Capture the id at change time: a write belongs to the view that was active @@ -699,11 +690,8 @@ export class ClineProvider } /** - * Re-binds a claim-less viewStates entry to this webview with a freshly minted claim. - * Entries written before claims existed cannot be attributed to any webview, so their - * selections are dropped instead of being carried over: keeping them would let the new - * token re-expose them on a later launch, which is exactly the disclosure this binding - * exists to prevent. Runs through the serialized write queue like every other mutation. + * Re-bind a claim-less viewStates entry with a freshly minted claim; its unowned + * selections are dropped so the new token cannot re-expose them. */ private async rebindUnboundViewStateEntry(viewStateId: string): Promise { const claimToken = crypto.randomUUID() @@ -758,18 +746,7 @@ export class ClineProvider return Object.fromEntries([...liveEntries, ...closedEntries]) } - /** - * Re-keys this provider's temporary pre-launch viewStates entry to the newly - * registered stable id so pre-launch writes become durable under the stable key - * instead of orphaning under a session-local temporary id. Only the provider's own - * temporary id is eligible: an entry under a previously registered stable id belongs - * to that webview's storage and is left alone. When the stable entry already exists - * it wins and the temporary entry is dropped, because temporary ids are session - * counters that can collide across window reloads. Runs through the serialized write - * queue like every other viewStates mutation. An entry this instance never wrote is - * left alone, so a stale entry that happens to carry the same session-local name is - * not adopted. - */ + /** Re-key this instance's authored pre-launch entry to the stable id. */ private async rekeyPersistedViewStateEntry(nextViewStateId: string): Promise { const previousViewStateId = this.viewId @@ -817,14 +794,8 @@ export class ClineProvider } /** - * Registers this provider's stable view identifier and loads any persisted selections it owns. - * The identifier is sanitized so it remains a safe object key in the shared viewStates map. - * - * `presentedClaim` is the host-minted token this webview was given for that id. It is the - * only proof of ownership: an entry that carries a claim is loaded only when the presented - * token matches it, so a webview cannot adopt another (e.g. disposed, still durable) view's - * id and read that view's pinned profile - and the profile secrets copied into the state - * post - back out of it. The check runs before any re-keying or loading. + * Register the stable view id and load its persisted selections. An entry that carries a + * claim is loaded only when the presented host-minted token matches it. */ public async setViewStateId(viewStateId: string | undefined, presentedClaim?: string): Promise { // The webview generates this id on purpose - it has to survive a webview reload, From c8e51939bf31c145b07bac911265d15b7aa1a55c Mon Sep 17 00:00:00 2001 From: easonLiangWorldedtech <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Fri, 30 Oct 2026 12:56:22 +0800 Subject: [PATCH 20/27] fix(webview): invalidate in-flight loads on reset and refresh sibling overlays --- src/core/webview/ClineProvider.ts | 23 ++++++- .../webview/__tests__/ClineProvider.spec.ts | 64 +++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index 29a1c764fc..e4dee05803 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -396,6 +396,10 @@ export class ClineProvider */ private viewLocalState: Partial = {} + // Bumped whenever the buffer is cleared (reset/import), so an in-flight load can tell + // that its captured state was invalidated while it awaited the profile lookup. + private viewLocalStateGeneration = 0 + /** * This view's pinned profile name from the view-local buffer. Exposed for * sibling-instance inspection (getAllInstances() filtering): `viewLocalState` @@ -917,6 +921,7 @@ export class ClineProvider /** Load non-secret persisted selections; in-flight buffer edits are reapplied on top. */ private async loadViewState(): Promise { + const loadedGeneration = this.viewLocalStateGeneration // A newer id registered while this load is in flight must win. const loadedForViewId = this.viewStateId @@ -992,6 +997,13 @@ export class ClineProvider } } + // A reset/import may have cleared the buffer while the lookup was in flight: + // republishing here would restore the pre-reset selection over the cleared state. + if (this.viewLocalStateGeneration !== loadedGeneration) { + this.log(`[loadViewState] Discarding state loaded before a reset for viewId ${this.viewId}`) + return + } + this.viewLocalState = mergedState this.log(`[loadViewState] Loaded state for viewId ${this.viewId}`) } catch (error) { @@ -2639,7 +2651,15 @@ export class ClineProvider if (signal.aborted) return id - // Refresh other views pinned to this profile so their overlays cannot go stale. + // Refresh other live views pinned to this profile so their buffered overlay cannot + // keep serving the pre-save settings under the same profile name. + for (const instance of ClineProvider.getAllInstances()) { + if (instance === this || instance._disposed || instance.pinnedProfileName !== name) { + continue + } + // Direct private access: compile-time safe across sibling instances. + await instance._saveViewLocalStateFromMutation({ apiConfiguration: providerSettings }) + } // Change the provider for the current task. // TODO: We should rename `buildApiHandler` for clarity (e.g. `getProviderClient`). @@ -4128,6 +4148,7 @@ export class ClineProvider /** Clear the buffer so getState() falls back to the shared values. */ private _clearViewLocalState(): void { + this.viewLocalStateGeneration += 1 this.viewLocalState = {} } diff --git a/src/core/webview/__tests__/ClineProvider.spec.ts b/src/core/webview/__tests__/ClineProvider.spec.ts index a43eccc131..f4b0565f27 100644 --- a/src/core/webview/__tests__/ClineProvider.spec.ts +++ b/src/core/webview/__tests__/ClineProvider.spec.ts @@ -4486,6 +4486,70 @@ describe("ClineProvider", () => { await provider.dispose() }) + it("should discard a load that finishes after reset cleared the buffer", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + await provider["setViewStateId"]("stable-sidebar-view") + await provider.contextProxy.setValue("viewStates", { + "stable-sidebar-view": { mode: "architect", updatedAt: 1 }, + }) + + let releaseModes: () => void = () => {} + vi.spyOn(provider.customModesManager, "getCustomModes").mockImplementation( + () => + new Promise((resolve) => { + releaseModes = () => resolve([]) + }), + ) + + const load = provider["loadViewState"]() + // The reset clears the buffer while the load awaits the mode lookup. + provider["_clearViewLocalState"]() + releaseModes() + await load + + expect(provider["viewLocalState"]).toEqual({}) + await provider.dispose() + }) + + it("should refresh the buffered overlay of another view pinned to the saved profile", async () => { + const saver = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + const pinned = new ClineProvider( + mockContext, + mockOutputChannel, + "editor", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + await pinned.setValue("currentApiConfigName", "shared-profile") + // @ts-ignore - The double only backs the profile-store calls of the save path. + saver.providerSettingsManager = { + saveConfig: vi.fn().mockResolvedValue("shared-id"), + listConfig: vi.fn().mockResolvedValue([{ name: "shared-profile", id: "shared-id" }]), + setModeConfig: vi.fn().mockResolvedValue(undefined), + } + const providerSettings = { apiProvider: providerIdentifiers.anthropic, apiKey: "fresh-key" } + + await saver.upsertProviderProfile("shared-profile", providerSettings, true) + + // The pinned view buffered a copy of the profile's settings; a non-activating save must + // refresh it, or its getState() keeps serving the pre-save configuration. + expect(pinned["viewLocalState"].apiConfiguration).toEqual(providerSettings) + await saver.dispose() + await pinned.dispose() + }) + it("should roll back the shared writes when setValues per-view persistence fails", async () => { const provider = new ClineProvider( mockContext, From 623a7d451f153f6d752a708ead79d2c51dfa0921 Mon Sep 17 00:00:00 2001 From: easonLiangWorldedtech <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Fri, 30 Oct 2026 12:57:06 +0800 Subject: [PATCH 21/27] chore: tighten the shared view-state docs --- packages/types/src/global-settings.ts | 5 +---- packages/types/src/vscode-extension-host.ts | 5 +---- src/core/webview/ClineProvider.ts | 20 ++++---------------- 3 files changed, 6 insertions(+), 24 deletions(-) diff --git a/packages/types/src/global-settings.ts b/packages/types/src/global-settings.ts index 3da73ee0fe..f9fe1f1139 100644 --- a/packages/types/src/global-settings.ts +++ b/packages/types/src/global-settings.ts @@ -121,10 +121,7 @@ export const viewStateSchema = z.object({ mode: z.string().optional(), currentApiConfigName: z.string().optional(), updatedAt: z.number().optional(), - /** - * Host-minted capability token binding this entry to the webview that wrote it; never - * accepted from webview input and only a matching token re-adopts the entry. - */ + /** Host-minted token binding this entry to the webview that wrote it. */ claimToken: z.string().optional(), }) diff --git a/packages/types/src/vscode-extension-host.ts b/packages/types/src/vscode-extension-host.ts index c77dbb14c4..3954246e15 100644 --- a/packages/types/src/vscode-extension-host.ts +++ b/packages/types/src/vscode-extension-host.ts @@ -679,10 +679,7 @@ export interface WebviewMessage { | "themeFixtureProbeResponse" text?: string viewStateId?: string - /** - * For `webviewDidLaunch`: the host-minted claim previously delivered for `viewStateId`. - * Enforced by `ClineProvider.setViewStateId`; launch forwarding ships in the wiring unit. - */ + /** For `webviewDidLaunch`: the claim delivered for `viewStateId`, enforced by setViewStateId. */ viewStateClaim?: string taskId?: string editedMessageContent?: string diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index e4dee05803..a38e54a3b4 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -376,10 +376,7 @@ export class ClineProvider */ public readonly viewId: string - /** - * Stable identifier for persisted per-view state keys; binds a durable entry to the - * webview that wrote it through the host-minted claim token. - */ + /** Stable id for persisted per-view state keys, bound by the host-minted claim. */ private viewStateId: string /** @@ -604,10 +601,7 @@ export class ClineProvider return Object.assign(Object.create(null), viewStates) } - /** - * Persist the non-secret selections through the serialized write queue, re-keying a - * pre-launch write to the stable id once the webview registers one. - */ + /** Persist the non-secret selections through the serialized write queue. */ private async savePersistedViewState(values: Partial): Promise { // Capture the id at change time: a write belongs to the view that was active // when the change was made, even if a newer id is registered while it is queued. @@ -693,10 +687,7 @@ export class ClineProvider await write } - /** - * Re-bind a claim-less viewStates entry with a freshly minted claim; its unowned - * selections are dropped so the new token cannot re-expose them. - */ + /** Re-bind a claim-less entry with a fresh claim; unowned selections are dropped. */ private async rebindUnboundViewStateEntry(viewStateId: string): Promise { const claimToken = crypto.randomUUID() let rebound = false @@ -797,10 +788,7 @@ export class ClineProvider await write } - /** - * Register the stable view id and load its persisted selections. An entry that carries a - * claim is loaded only when the presented host-minted token matches it. - */ + /** Register the stable view id and load its persisted selections; a claim must match. */ public async setViewStateId(viewStateId: string | undefined, presentedClaim?: string): Promise { // The webview generates this id on purpose - it has to survive a webview reload, // which recreates the view on both sides - so the host cannot mint it instead. From fc7895522afeb64f838266bf23042984a184fef7 Mon Sep 17 00:00:00 2001 From: easonLiangWorldedtech <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Fri, 30 Oct 2026 14:08:16 +0800 Subject: [PATCH 22/27] fix(lint): restore the ClineProvider suite suppression to its actual count The earlier prune under-counted no-explicit-any in ClineProvider.spec.ts (177 vs the 183 occurrences), which failed the lint job. --- src/eslint-suppressions.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/eslint-suppressions.json b/src/eslint-suppressions.json index 5460f6bbda..a1b7484868 100644 --- a/src/eslint-suppressions.json +++ b/src/eslint-suppressions.json @@ -1016,7 +1016,7 @@ }, "core/webview/__tests__/ClineProvider.spec.ts": { "@typescript-eslint/no-explicit-any": { - "count": 177 + "count": 183 } }, "core/webview/__tests__/ClineProvider.sticky-mode.spec.ts": { From bac06626594786e8fddc6011fcbeb4ff1f213415 Mon Sep 17 00:00:00 2001 From: easonLiangWorldedtech <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Fri, 30 Oct 2026 14:31:49 +0800 Subject: [PATCH 23/27] fix(webview): address the N5 review findings (batch 1) - register configuration.customModes before setValues validates the mode - roll shared values back when a multi-key ContextProxy write rejects partway - pin a persisted profile name only with the configuration it resolves to - skip the buffer update when a reset ran during the durable save - guard the shared rollback with per-key write generations, not values alone - rebuild sibling task handlers when their pinned profile settings change --- src/core/config/ContextProxy.ts | 5 ++ src/core/webview/ClineProvider.ts | 89 ++++++++++++++----- .../webview/__tests__/ClineProvider.spec.ts | 6 +- 3 files changed, 78 insertions(+), 22 deletions(-) diff --git a/src/core/config/ContextProxy.ts b/src/core/config/ContextProxy.ts index e6aea60685..b34ec926f4 100644 --- a/src/core/config/ContextProxy.ts +++ b/src/core/config/ContextProxy.ts @@ -386,6 +386,11 @@ export class ContextProxy { } } + /** Current per-key write generation, used by callers whose rollback must not clobber a newer write. */ + public getStateWriteGeneration(key: K): number { + return this.stateWriteGenerations.get(key) ?? 0 + } + private getAllGlobalState(): GlobalState { return Object.fromEntries(GLOBAL_STATE_KEYS.map((key) => [key, this.getGlobalState(key)])) } diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index a38e54a3b4..b1c031c57c 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -937,12 +937,13 @@ export class ClineProvider } if (persisted?.currentApiConfigName) { - loadedState.currentApiConfigName = persisted.currentApiConfigName - try { const { name: _name, ...apiConfiguration } = await this.providerSettingsManager.getProfile({ name: persisted.currentApiConfigName, }) + // Pin the name only together with the configuration it resolves to: a name + // without its overlay would pair with whatever shared settings sit under it. + loadedState.currentApiConfigName = persisted.currentApiConfigName loadedState.apiConfiguration = apiConfiguration as ProviderSettings } catch (error) { this.log( @@ -2647,6 +2648,17 @@ export class ClineProvider } // Direct private access: compile-time safe across sibling instances. await instance._saveViewLocalStateFromMutation({ apiConfiguration: providerSettings }) + + // A sibling task running under this profile holds a handler built from the old + // settings: rebuild it so the conversation does not keep sending the old token. + if (instance.getCurrentTask()?.taskApiConfigName === name) { + const { + name: _recordName, + id: _recordId, + ...taskSettings + } = providerSettings as ProviderSettings & { name?: string; id?: string } + instance.updateTaskApiHandlerIfNeeded(taskSettings, { forceRebuild: true }) + } } // Change the provider for the current task. @@ -4057,15 +4069,20 @@ export class ClineProvider public async setValue(key: K, value: RooCodeSettings[K]) { const previousSharedValues = { [key]: this.contextProxy.getValue(key) } as RooCodeSettings + const writeGeneration = this.contextProxy.getStateWriteGeneration(key as never) await this.contextProxy.setValue(key, value) try { await this._saveViewLocalStateFromMutation({ [key]: value }) } catch (error) { // The per-view record did not land: restore the prior shared value so the two // persistence layers cannot diverge, then surface the original failure. - await this._restoreSharedValuesAfterFailedViewWrite(previousSharedValues, { - [key]: value, - } as RooCodeSettings) + await this._restoreSharedValuesAfterFailedViewWrite( + previousSharedValues, + { [key]: value } as RooCodeSettings, + // This write is the generation after the one captured before it: only the write + // that is still the newest for the key may be rolled back. + { [key]: writeGeneration + 1 } as Record, + ) throw error } } @@ -4096,13 +4113,35 @@ export class ClineProvider const previousSharedValues = Object.fromEntries( Object.keys(sanitizedValues).map((key) => [key, this.contextProxy.getValue(key as keyof RooCodeSettings)]), ) as RooCodeSettings - await this.contextProxy.setValues(sanitizedValues) + const writeGenerations = Object.fromEntries( + Object.keys(sanitizedValues).map((key) => [ + key, + // This write produces the next generation for the key. + this.contextProxy.getStateWriteGeneration(key as never) + 1, + ]), + ) as Record + try { + await this.contextProxy.setValues(sanitizedValues) + } catch (error) { + // A multi-key write can commit some keys before another rejects: put the captured + // previous values back so shared state does not stay half-applied. + try { + await this.contextProxy.setValues(previousSharedValues) + } catch (rollbackError) { + this.log( + `[ClineProvider#setValues] Failed to roll back a partially applied write: ${ + rollbackError instanceof Error ? rollbackError.message : String(rollbackError) + }`, + ) + } + throw error + } try { await this._saveViewLocalStateFromMutation(sanitizedValues) } catch (error) { // The per-view record did not land: restore the prior shared values so the two // persistence layers cannot diverge, then surface the original failure. - await this._restoreSharedValuesAfterFailedViewWrite(previousSharedValues, sanitizedValues) + await this._restoreSharedValuesAfterFailedViewWrite(previousSharedValues, sanitizedValues, writeGenerations) throw error } } @@ -4111,7 +4150,13 @@ export class ClineProvider private async _saveViewLocalStateFromMutation( values: Partial & Partial, ): Promise { + const generation = this.viewLocalStateGeneration await this._persistViewLocalStateFromMutation(values) + // A reset that ran while the durable write was pending cleared the buffer: applying + // the pre-reset value now would resurrect it. + if (this.viewLocalStateGeneration !== generation) { + return + } this._updateViewLocalStateFromMutation(values) } @@ -4314,6 +4359,14 @@ export class ClineProvider configuration: RooCodeSettings = {}, ): Promise { if (configuration) { + // Register custom modes before setValues: setValues validates `mode` against + // getCustomModes(), so a mode supplied in the same call would otherwise be dropped. + if (configuration.customModes?.length) { + for (const mode of configuration.customModes) { + await this.customModesManager.updateCustomMode(mode.slug, mode) + } + } + await this.setValues(configuration) if (configuration.allowedCommands) { @@ -4341,16 +4394,6 @@ export class ClineProvider if (configuration.currentApiConfigName) { await this.setProviderProfile(configuration.currentApiConfigName) } - - // Register custom modes so the CustomModesManager knows about them. - // setValues writes to global state, but the manager overwrites that - // when it merges .roomodes + global settings on refresh. Persisting - // via updateCustomMode ensures modes survive the merge cycle. - if (configuration.customModes?.length) { - for (const mode of configuration.customModes) { - await this.customModesManager.updateCustomMode(mode.slug, mode) - } - } } const { @@ -5582,14 +5625,20 @@ export class ClineProvider private async _restoreSharedValuesAfterFailedViewWrite( previous: RooCodeSettings, attempted: RooCodeSettings, + generations: Record = {}, ): Promise { // Roll back only the keys this attempt wrote and that still hold the value it wrote. - // A concurrent provider may have written a newer value in the meantime; restoring the - // captured previous value would then clobber it for every view that reads shared state. + // A concurrent provider may have written a newer value in the meantime - even the same + // value - so the per-key write generation must also still match; restoring otherwise + // would clobber that newer write for every view that reads shared state. const rollback: RooCodeSettings = {} as RooCodeSettings for (const key of Object.keys(attempted) as (keyof RooCodeSettings)[]) { - if (this.contextProxy.getValue(key) === attempted[key]) { + const generation = generations[key] + if ( + this.contextProxy.getValue(key) === attempted[key] && + (generation === undefined || this.contextProxy.getStateWriteGeneration(key as never) === generation) + ) { ;(rollback as Record)[key] = previous[key] } } diff --git a/src/core/webview/__tests__/ClineProvider.spec.ts b/src/core/webview/__tests__/ClineProvider.spec.ts index f4b0565f27..b703ca8347 100644 --- a/src/core/webview/__tests__/ClineProvider.spec.ts +++ b/src/core/webview/__tests__/ClineProvider.spec.ts @@ -3850,7 +3850,7 @@ describe("ClineProvider", () => { await provider.dispose() }) - it("should keep the persisted profile name and log when the profile lookup fails", async () => { + it("should not pin the persisted profile name when the profile lookup fails", async () => { const provider = new ClineProvider( mockContext, mockOutputChannel, @@ -3863,7 +3863,9 @@ describe("ClineProvider", () => { provider.providerSettingsManager = { getProfile: vi.fn().mockRejectedValue(new Error("profile missing")) } await provider.saveViewState("currentApiConfigName", "my-profile") await provider["setViewStateId"]("stable-sidebar-view") - expect(provider["viewLocalState"].currentApiConfigName).toBe("my-profile") + // The name is pinned only with its resolved configuration: otherwise getState() + // would pair the missing profile's name with unrelated shared settings. + expect(provider["viewLocalState"]).not.toHaveProperty("currentApiConfigName") expect(provider["viewLocalState"]).not.toHaveProperty("apiConfiguration") expect(logSpy).toHaveBeenCalledWith(expect.stringContaining("Unable to resolve API profile 'my-profile'")) await provider.dispose() From 3c2f582902d75a020868cd4c6a0b30e3ddae2703 Mon Sep 17 00:00:00 2001 From: easonLiangWorldedtech <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Fri, 30 Oct 2026 14:33:57 +0800 Subject: [PATCH 24/27] fix(webview): address the N5 review findings (batch 2) - ContextProxy tracks the last persisted value per key and rolls a failed write back to it, with a both-writes-reject test - deleteProviderProfile retries the settings-manager name update and reports an incomplete repair after posting state - deleteProviderProfile re-pins sibling views still buffered on the deleted profile --- src/core/config/ContextProxy.ts | 14 +++-- .../config/__tests__/ContextProxy.spec.ts | 29 ++++++++++ src/core/webview/ClineProvider.ts | 54 +++++++++++++++---- 3 files changed, 85 insertions(+), 12 deletions(-) diff --git a/src/core/config/ContextProxy.ts b/src/core/config/ContextProxy.ts index b34ec926f4..837b417b2a 100644 --- a/src/core/config/ContextProxy.ts +++ b/src/core/config/ContextProxy.ts @@ -46,6 +46,10 @@ export class ContextProxy { private stateCache: GlobalState private stateWriteGenerations = new Map() + + // The value storage last accepted per key: a failed write must roll the cache back to + // what is actually persisted, not to another pending write's unpersisted value. + private statePersistedCache = new Map() private secretCache: SecretState private _isInitialized = false @@ -375,12 +379,16 @@ export class ContextProxy { this.stateCache[key] = value try { - return await this.originalContext.globalState.update(key, value) + const result = await this.originalContext.globalState.update(key, value) + this.statePersistedCache.set(key, value) + return result } catch (error) { // A newer write for the same key may already own the cache: only undo this write - // while it is still the newest one. + // while it is still the newest one, and only to the last value storage accepted. if (this.stateWriteGenerations.get(key) === generation) { - this.stateCache[key] = previousCachedValue + this.stateCache[key] = this.statePersistedCache.has(key) + ? (this.statePersistedCache.get(key) as GlobalState[K]) + : previousCachedValue } throw error } diff --git a/src/core/config/__tests__/ContextProxy.spec.ts b/src/core/config/__tests__/ContextProxy.spec.ts index a28ca249ac..4050133a7f 100644 --- a/src/core/config/__tests__/ContextProxy.spec.ts +++ b/src/core/config/__tests__/ContextProxy.spec.ts @@ -160,6 +160,35 @@ describe("ContextProxy", () => { expect(proxy.getGlobalState("apiProvider")).toBeUndefined() }) + it("should restore the last persisted value when two overlapping writes both reject", async () => { + await proxy.updateGlobalState("apiProvider", "anthropic") + mockGlobalState.update.mockReset() + let rejectFirst: (error: Error) => void = () => {} + let rejectSecond: (error: Error) => void = () => {} + mockGlobalState.update + .mockReturnValueOnce( + new Promise((_, reject) => { + rejectFirst = reject + }), + ) + .mockReturnValueOnce( + new Promise((_, reject) => { + rejectSecond = reject + }), + ) + + const firstWrite = proxy.updateGlobalState("apiProvider", "openrouter") + const secondWrite = proxy.updateGlobalState("apiProvider", "deepseek") + rejectSecond(new Error("second failed")) + await expect(secondWrite).rejects.toThrow("second failed") + rejectFirst(new Error("first failed")) + await expect(firstWrite).rejects.toThrow("first failed") + + // Neither attempt reached storage: the cache must hold the last persisted value, + // not the first attempt's unpersisted value. + expect(proxy.getGlobalState("apiProvider")).toBe("anthropic") + }) + it("should bypass cache for pass-through state keys", async () => { // Setup mock return value mockGlobalState.get.mockReturnValue("pass-through-value") diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index b1c031c57c..e9334e38de 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -2754,15 +2754,28 @@ export class ClineProvider // currentApiConfigName naming it, so a later export would write a selection the // profile list no longer contains (and import would silently pick another profile). // Point the manager at the survivor too. + let managerNameUpdateFailure: Error | undefined if (deletedWasGlobal) { try { await this.providerSettingsManager.activateProfile({ name: profileToActivate }) - } catch (error) { - this.log( - `[deleteProviderProfile] Failed to update the settings manager's current profile to '${profileToActivate}': ${ - error instanceof Error ? error.message : String(error) - }`, - ) + } catch (firstError) { + try { + // Retry once: a stale manager name would be exported as a selection the + // profile list no longer contains. + await this.providerSettingsManager.activateProfile({ name: profileToActivate }) + } catch (retryError) { + this.log( + `[deleteProviderProfile] Failed to update the settings manager's current profile to '${profileToActivate}' after retry: ${ + retryError instanceof Error ? retryError.message : String(retryError) + } (first attempt: ${firstError instanceof Error ? firstError.message : String(firstError)})`, + ) + // The deletion has committed: finish the shared-state repair and post it, then + // surface the incomplete manager update to the caller. + managerNameUpdateFailure = new Error( + `Profile '${profileToDelete.name}' was deleted but the settings manager still names it as current.`, + { cause: retryError }, + ) + } } } @@ -2793,11 +2806,34 @@ export class ClineProvider } } - // Re-pin other live views still buffered on the deleted profile: their - // buffer and durable viewStates entry would otherwise keep serving the - // deleted profile's name and configuration. + // Re-pin other live views still buffered on the deleted profile: their buffer and + // durable viewStates entry would otherwise keep serving the deleted profile's name + // and configuration. + for (const instance of ClineProvider.getAllInstances()) { + if (instance === this || instance._disposed || instance.pinnedProfileName !== profileToDelete.name) { + continue + } + const values: Partial & Partial = { + currentApiConfigName: profileToActivate, + } + if (survivingSettings) { + values.apiConfiguration = survivingSettings + } + // Direct private access: compile-time safe across sibling instances. + await instance._saveViewLocalStateFromMutation(values) + await instance.postStateToWebview().catch((postError: unknown) => { + this.log( + `[deleteProviderProfile] failed to post re-pinned state to a sibling view: ${ + postError instanceof Error ? postError.message : String(postError) + }`, + ) + }) + } await this.postStateToWebview() + if (managerNameUpdateFailure) { + throw managerNameUpdateFailure + } } private async persistStickyProviderProfileToCurrentTask( From 2760d037f926f4b8485f573daf2f4b7decd79f71 Mon Sep 17 00:00:00 2001 From: Eason Liang <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Sun, 1 Nov 2026 21:38:34 +0800 Subject: [PATCH 25/27] chore(lint): prune suppressions left stale by the upstream merge --- src/eslint-suppressions.json | 3252 +++++++++++++++++----------------- 1 file changed, 1626 insertions(+), 1626 deletions(-) diff --git a/src/eslint-suppressions.json b/src/eslint-suppressions.json index 6384e92410..1ef5fef9ae 100644 --- a/src/eslint-suppressions.json +++ b/src/eslint-suppressions.json @@ -1,1627 +1,1627 @@ { - "__mocks__/fs/promises.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "__tests__/ClineProvider.delegation.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 9 - } - }, - "__tests__/ClineProvider.history-resume-delegation.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 70 - } - }, - "__tests__/abandonSubtask.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 20 - } - }, - "__tests__/api-subtask.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "__tests__/delegation-concurrent.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 6 - } - }, - "__tests__/delegation-events.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 6 - } - }, - "__tests__/migrateSettings.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "__tests__/nested-delegation-resume.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 19 - } - }, - "__tests__/new-task-delegation.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 8 - } - }, - "activate/CodeActionProvider.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "activate/__tests__/CodeActionProvider.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 10 - } - }, - "activate/__tests__/handleUri.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 14 - } - }, - "activate/__tests__/registerCommands.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "activate/registerCodeActions.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "activate/registerCommands.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "activate/registerTerminalActions.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/__tests__/anthropic-vertex.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 31 - } - }, - "api/providers/__tests__/anthropic.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 7 - } - }, - "api/providers/__tests__/base-openai-compatible-provider-timeout.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "api/providers/__tests__/base-openai-compatible-provider.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/__tests__/base-provider.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "api/providers/__tests__/bedrock-custom-arn.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 12 - } - }, - "api/providers/__tests__/bedrock-error-handling.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 7 - } - }, - "api/providers/__tests__/bedrock-inference-profiles.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 27 - } - }, - "api/providers/__tests__/bedrock-native-tools.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 19 - } - }, - "api/providers/__tests__/bedrock-reasoning.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/__tests__/bedrock.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 37 - } - }, - "api/providers/__tests__/deepseek.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 12 - } - }, - "api/providers/__tests__/gemini-handler.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 18 - } - }, - "api/providers/__tests__/gemini.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 33 - } - }, - "api/providers/__tests__/kenari.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/__tests__/kimi-code.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/__tests__/lite-llm.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 36 - } - }, - "api/providers/__tests__/lm-studio-timeout.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "api/providers/__tests__/mimo.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 18 - } - }, - "api/providers/__tests__/minimax.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "api/providers/__tests__/moonshot.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 22 - } - }, - "api/providers/__tests__/native-ollama.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 21 - } - }, - "api/providers/__tests__/openai-codex-native-tool-calls.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 22 - } - }, - "api/providers/__tests__/openai-codex.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 16 - } - }, - "api/providers/__tests__/openai-native-tools.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 14 - } - }, - "api/providers/__tests__/openai-native-usage.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 25 - } - }, - "api/providers/__tests__/openai-native.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 74 - } - }, - "api/providers/__tests__/openai-timeout.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "api/providers/__tests__/openai.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "api/providers/__tests__/opencode-go.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "api/providers/__tests__/openrouter.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 34 - } - }, - "api/providers/__tests__/poe.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/__tests__/qwen-code-native-tools.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "api/providers/__tests__/sambanova.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "api/providers/__tests__/unbound.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "api/providers/__tests__/vercel-ai-gateway.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "api/providers/__tests__/vertex.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "api/providers/__tests__/zai.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "api/providers/anthropic-vertex.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "api/providers/anthropic.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/base-openai-compatible-provider.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 6 - } - }, - "api/providers/base-provider.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "api/providers/bedrock.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 32 - } - }, - "api/providers/deepseek.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "api/providers/fetchers/__tests__/kenari.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/fetchers/__tests__/kimi-code.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/fetchers/__tests__/lmstudio.test.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "api/providers/fetchers/__tests__/modelEndpointCache.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 9 - } - }, - "api/providers/fetchers/__tests__/moonshot.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/fetchers/__tests__/ollama.test.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 9 - } - }, - "api/providers/fetchers/__tests__/opencode-go.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/fetchers/__tests__/openrouter.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "api/providers/fetchers/__tests__/vercel-ai-gateway.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/fetchers/__tests__/zoo-gateway.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 8 - } - }, - "api/providers/fetchers/litellm.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/gemini.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "api/providers/lite-llm.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 8 - } - }, - "api/providers/mimo.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "api/providers/moonshot.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/native-ollama.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "api/providers/openai-codex.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 31 - } - }, - "api/providers/openai-native.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 27 - } - }, - "api/providers/openai.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "api/providers/openrouter.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 6 - } - }, - "api/providers/poe.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "api/providers/qwen-code.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/requesty.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "api/providers/unbound.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "api/providers/utils/__tests__/error-handler.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 35 - } - }, - "api/providers/utils/__tests__/image-generation.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 17 - } - }, - "api/providers/utils/__tests__/timeout-config.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "api/providers/utils/error-handler.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 7 - } - }, - "api/providers/xai.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "api/transform/__tests__/ai-sdk.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "api/transform/__tests__/anthropic-filter.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 6 - } - }, - "api/transform/__tests__/bedrock-converse-format.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "api/transform/__tests__/gemini-format.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "api/transform/__tests__/mistral-format.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "api/transform/__tests__/model-params.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 8 - } - }, - "api/transform/__tests__/openai-format.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 49 - } - }, - "api/transform/__tests__/r1-format.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 8 - } - }, - "api/transform/__tests__/reasoning.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/transform/__tests__/responses-api-input.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "api/transform/__tests__/responses-api-stream.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "api/transform/__tests__/zai-format.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "api/transform/ai-sdk.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "api/transform/bedrock-converse-format.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "api/transform/cache-strategy/__tests__/cache-strategy.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 17 - } - }, - "api/transform/caching/__tests__/gemini.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/transform/gemini-format.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/transform/openai-format.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 8 - } - }, - "api/transform/r1-format.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "api/transform/responses-api-input.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 6 - } - }, - "api/transform/responses-api-stream.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "api/transform/zai-format.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "core/assistant-message/NativeToolCallParser.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/assistant-message/__tests__/presentAssistantMessage-custom-tool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "core/assistant-message/__tests__/presentAssistantMessage-images.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 14 - } - }, - "core/assistant-message/__tests__/presentAssistantMessage-unknown-tool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 8 - } - }, - "core/assistant-message/presentAssistantMessage.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "core/auto-approval/__tests__/AutoApprovalHandler.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/checkpoints/__tests__/checkpoint.test.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "core/checkpoints/index.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/condense/__tests__/condense.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "core/condense/__tests__/foldedFileContext.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 10 - } - }, - "core/condense/__tests__/index.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 24 - } - }, - "core/config/ContextProxy.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/config/CustomModesManager.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "core/config/ProviderSettingsManager.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "core/config/__tests__/ContextProxy.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "core/config/__tests__/CustomModesManager.exportImportSlugChange.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "core/config/__tests__/CustomModesManager.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 12 - } - }, - "core/config/__tests__/CustomModesManager.yamlEdgeCases.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/context-management/__tests__/context-management.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/context-tracking/__tests__/FileContextTracker.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "core/context/context-management/__tests__/context-error-handling.test.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/context/context-management/context-error-handling.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/diff/stats.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/environment/__tests__/getEnvironmentDetails.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/ignore/__tests__/RooIgnoreController.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/mentions/__tests__/processUserContentMentions.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/mentions/index.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/mentions/processUserContentMentions.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/message-manager/index.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 21 - } - }, - "core/message-manager/index.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/prompts/__tests__/add-custom-instructions.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/prompts/__tests__/get-prompt-component.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/prompts/__tests__/responses-rooignore.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 6 - } - }, - "core/prompts/__tests__/system-prompt.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "core/prompts/sections/__tests__/custom-instructions-global.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 18 - } - }, - "core/prompts/sections/__tests__/custom-instructions.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 55 - } - }, - "core/prompts/sections/__tests__/system-info.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/prompts/tools/__tests__/filter-tools-for-mode.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 14 - } - }, - "core/prompts/tools/native-tools/__tests__/converters.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/prompts/tools/native-tools/__tests__/read_file.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "core/task-persistence/__tests__/TaskHistoryStore.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "core/task-persistence/__tests__/importRooTaskHistory.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/task-persistence/__tests__/taskMessages.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/task-persistence/apiMessages.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/task/Task.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 17 - } - }, - "core/task/__tests__/Task.dispose.test.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "core/task/__tests__/Task.persistence.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 8 - } - }, - "core/task/__tests__/Task.sticky-profile-race.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "core/task/__tests__/Task.throttle.test.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 24 - } - }, - "core/task/__tests__/apiConversationHistory.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 23 - } - }, - "core/task/__tests__/ask-clear-approval-buttons.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 19 - } - }, - "core/task/__tests__/ask-queued-message-drain.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 18 - } - }, - "core/task/__tests__/flushPendingToolResultsToHistory.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 14 - } - }, - "core/task/__tests__/grace-retry-errors.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "core/task/__tests__/grounding-sources.test.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "core/task/__tests__/native-tools-filtering.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "core/task/__tests__/new-task-isolation.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/task/__tests__/reasoning-preservation.test.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 20 - } - }, - "core/task/__tests__/task-tool-history.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "core/task/apiConversationHistory.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 8 - } - }, - "core/tools/BaseTool.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/tools/CodebaseSearchTool.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/tools/GenerateImageTool.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/tools/NewTaskTool.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/tools/ReadFileTool.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "core/tools/ToolRepetitionDetector.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/tools/UpdateTodoListTool.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/tools/UseMcpToolTool.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "core/tools/__tests__/ReadCommandOutputTool.test.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 16 - } - }, - "core/tools/__tests__/askFollowupQuestionTool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 20 - } - }, - "core/tools/__tests__/attemptCompletionTool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 11 - } - }, - "core/tools/__tests__/editFileTool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "core/tools/__tests__/editTool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/tools/__tests__/executeCommand.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 10 - } - }, - "core/tools/__tests__/executeCommandTool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 8 - } - }, - "core/tools/__tests__/generateImageTool.test.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 9 - } - }, - "core/tools/__tests__/listFilesTool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 10 - } - }, - "core/tools/__tests__/mcpServerRestriction.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 6 - } - }, - "core/tools/__tests__/newTaskTool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 26 - } - }, - "core/tools/__tests__/readFileTool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 96 - } - }, - "core/tools/__tests__/runSlashCommandTool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/tools/__tests__/searchReplaceTool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/tools/__tests__/skillTool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "core/tools/__tests__/updateTodoListTool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/tools/__tests__/useMcpToolTool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 21 - } - }, - "core/tools/__tests__/validateToolUse.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/tools/__tests__/writeToFileTool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "core/tools/helpers/toolResultFormatting.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/tools/validateToolUse.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/webview/ClineProvider.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 7 - } - }, - "core/webview/__tests__/ClineProvider.apiHandlerRebuild.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 34 - } - }, - "core/webview/__tests__/ClineProvider.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 183 - } - }, - "core/webview/__tests__/ClineProvider.sticky-mode.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 26 - } - }, - "core/webview/__tests__/ClineProvider.sticky-profile.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 15 - } - }, - "core/webview/__tests__/ClineProvider.taskHistory.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 12 - } - }, - "core/webview/__tests__/checkpointRestoreHandler.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "core/webview/__tests__/diagnosticsHandler.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 7 - } - }, - "core/webview/__tests__/messageEnhancer.test.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 8 - } - }, - "core/webview/__tests__/skillsMessageHandler.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/webview/__tests__/telemetrySettingsTracking.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "core/webview/__tests__/webviewMessageHandler.checkpoint.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "core/webview/__tests__/webviewMessageHandler.cloudAuth.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "core/webview/__tests__/webviewMessageHandler.delete.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 9 - } - }, - "core/webview/__tests__/webviewMessageHandler.edit.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/webview/__tests__/webviewMessageHandler.importRooHistory.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 13 - } - }, - "core/webview/__tests__/webviewMessageHandler.readFileContent.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/webview/__tests__/webviewMessageHandler.routerModels.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 56 - } - }, - "core/webview/__tests__/webviewMessageHandler.searchFiles.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "core/webview/__tests__/webviewMessageHandler.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 35 - } - }, - "core/webview/messageEnhancer.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/webview/webviewMessageHandler.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "extension/__tests__/api-delete-queued-message.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "extension/__tests__/api-send-message.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 7 - } - }, - "extension/api.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 9 - } - }, - "i18n/index.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "i18n/setup.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "integrations/editor/DiffViewProvider.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "integrations/editor/__tests__/DiffViewProvider.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 310 - } - }, - "integrations/editor/__tests__/EditorUtils.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "integrations/kimi-code/__tests__/oauth.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "integrations/misc/__tests__/export-markdown.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "integrations/misc/__tests__/open-file.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 11 - } - }, - "integrations/misc/__tests__/performance/processCarriageReturns.benchmark.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "integrations/terminal/__tests__/ExecaTerminalProcess.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 10 - } - }, - "integrations/terminal/__tests__/OutputInterceptor.test.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "integrations/terminal/__tests__/TerminalProcess.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 7 - } - }, - "integrations/terminal/__tests__/TerminalProcess.test.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "integrations/terminal/__tests__/TerminalProcessExec.bash.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "integrations/terminal/__tests__/TerminalProcessExec.cmd.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "integrations/terminal/__tests__/TerminalProcessExec.pwsh.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "integrations/terminal/__tests__/TerminalProcessInterpretExitCode.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "integrations/terminal/__tests__/TerminalProfile.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 34 - } - }, - "integrations/terminal/__tests__/TerminalRegistry.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 22 - } - }, - "integrations/terminal/__tests__/setupTerminalTests.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "integrations/terminal/__tests__/streamUtils/bashStream.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "integrations/terminal/__tests__/streamUtils/cmdStream.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "integrations/terminal/__tests__/streamUtils/index.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "integrations/terminal/__tests__/streamUtils/pwshStream.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "integrations/theme/getTheme.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 9 - } - }, - "services/__tests__/zoo-code-auth.test.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "services/checkpoints/__tests__/ShadowCheckpointService.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "services/code-index/__tests__/config-manager.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "services/code-index/__tests__/manager.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 84 - } - }, - "services/code-index/__tests__/orchestrator.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 23 - } - }, - "services/code-index/__tests__/service-factory.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 43 - } - }, - "services/code-index/embedders/__tests__/bedrock.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 7 - } - }, - "services/code-index/embedders/__tests__/gemini.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "services/code-index/embedders/__tests__/mistral.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "services/code-index/embedders/__tests__/ollama.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "services/code-index/embedders/__tests__/openai-compatible-rate-limit.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 15 - } - }, - "services/code-index/embedders/__tests__/openai-compatible.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 28 - } - }, - "services/code-index/embedders/__tests__/openai.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 10 - } - }, - "services/code-index/embedders/__tests__/openrouter.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "services/code-index/embedders/__tests__/vercel-ai-gateway.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "services/code-index/embedders/bedrock.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "services/code-index/embedders/ollama.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "services/code-index/embedders/openai-compatible.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "services/code-index/embedders/openai.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "services/code-index/embedders/openrouter.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "services/code-index/interfaces/vector-store.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "services/code-index/orchestrator.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "services/code-index/processors/__tests__/file-watcher.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 25 - } - }, - "services/code-index/processors/__tests__/parser.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 22 - } - }, - "services/code-index/processors/__tests__/scanner.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 26 - } - }, - "services/code-index/processors/file-watcher.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "services/code-index/processors/scanner.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "services/code-index/semble/__tests__/provider.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 12 - } - }, - "services/code-index/semble/__tests__/semble-cli.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "services/code-index/semble/__tests__/semble-downloader.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 61 - } - }, - "services/code-index/semble/provider.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "services/code-index/semble/semble-cli.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "services/code-index/shared/__tests__/validation-helpers.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "services/code-index/shared/validation-helpers.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "services/code-index/vector-store/__tests__/qdrant-client.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 87 - } - }, - "services/code-index/vector-store/qdrant-client.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "services/glob/__tests__/gitignore-integration.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "services/glob/__tests__/gitignore-test.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "services/glob/__tests__/list-files-limit.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 6 - } - }, - "services/glob/__tests__/list-files.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 22 - } - }, - "services/marketplace/MarketplaceManager.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "services/marketplace/SimpleInstaller.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 7 - } - }, - "services/marketplace/__tests__/MarketplaceManager.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "services/marketplace/__tests__/SimpleInstaller.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 17 - } - }, - "services/marketplace/__tests__/marketplace-setting-check.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "services/mcp/McpHub.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 7 - } - }, - "services/mcp/McpOAuthClientProvider.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "services/mcp/McpServerManager.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "services/mcp/__tests__/McpHub.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 150 - } - }, - "services/mcp/__tests__/McpOAuthClientProvider.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 18 - } - }, - "services/mcp/__tests__/SecretStorageService.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "services/mcp/utils/__tests__/oauth.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 9 - } - }, - "services/mcp/utils/callbackServer.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "services/mcp/utils/oauth.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "services/mdm/__tests__/MdmService.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "services/ripgrep/__tests__/diagnostic.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "services/roo-config/__tests__/index.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 20 - } - }, - "services/roo-config/index.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "services/rules/__tests__/rules.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "services/search/__tests__/file-search.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "services/skills/__tests__/SkillsManager.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "services/tree-sitter/__tests__/helpers.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "services/tree-sitter/__tests__/markdownParser.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "shared/__tests__/api.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 8 - } - }, - "shared/__tests__/embeddingModels.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "shared/__tests__/modes-empty-prompt-component.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "shared/api.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "shared/checkExistApiConfig.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "shared/cost.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "shared/parse-command.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "shared/support-prompt.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "shared/tools.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "shared/utils/__tests__/requesty.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "vitest.setup.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - } -} + "__mocks__/fs/promises.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "__tests__/ClineProvider.delegation.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 9 + } + }, + "__tests__/ClineProvider.history-resume-delegation.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 70 + } + }, + "__tests__/abandonSubtask.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 20 + } + }, + "__tests__/api-subtask.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "__tests__/delegation-concurrent.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 6 + } + }, + "__tests__/delegation-events.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 6 + } + }, + "__tests__/migrateSettings.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "__tests__/nested-delegation-resume.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 19 + } + }, + "__tests__/new-task-delegation.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 8 + } + }, + "activate/CodeActionProvider.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "activate/__tests__/CodeActionProvider.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 10 + } + }, + "activate/__tests__/handleUri.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 14 + } + }, + "activate/__tests__/registerCommands.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "activate/registerCodeActions.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "activate/registerCommands.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "activate/registerTerminalActions.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/__tests__/anthropic-vertex.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 31 + } + }, + "api/providers/__tests__/anthropic.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 7 + } + }, + "api/providers/__tests__/base-openai-compatible-provider-timeout.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "api/providers/__tests__/base-openai-compatible-provider.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/__tests__/base-provider.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "api/providers/__tests__/bedrock-custom-arn.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 12 + } + }, + "api/providers/__tests__/bedrock-error-handling.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 7 + } + }, + "api/providers/__tests__/bedrock-inference-profiles.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 27 + } + }, + "api/providers/__tests__/bedrock-native-tools.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 19 + } + }, + "api/providers/__tests__/bedrock-reasoning.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/__tests__/bedrock.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 37 + } + }, + "api/providers/__tests__/deepseek.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 12 + } + }, + "api/providers/__tests__/gemini-handler.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 18 + } + }, + "api/providers/__tests__/gemini.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 33 + } + }, + "api/providers/__tests__/kenari.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/__tests__/kimi-code.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/__tests__/lite-llm.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 36 + } + }, + "api/providers/__tests__/lm-studio-timeout.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "api/providers/__tests__/mimo.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 18 + } + }, + "api/providers/__tests__/minimax.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "api/providers/__tests__/moonshot.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 22 + } + }, + "api/providers/__tests__/native-ollama.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 21 + } + }, + "api/providers/__tests__/openai-codex-native-tool-calls.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 22 + } + }, + "api/providers/__tests__/openai-codex.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 16 + } + }, + "api/providers/__tests__/openai-native-tools.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 14 + } + }, + "api/providers/__tests__/openai-native-usage.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 25 + } + }, + "api/providers/__tests__/openai-native.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 74 + } + }, + "api/providers/__tests__/openai-timeout.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "api/providers/__tests__/openai.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "api/providers/__tests__/opencode-go.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "api/providers/__tests__/openrouter.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 34 + } + }, + "api/providers/__tests__/poe.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/__tests__/qwen-code-native-tools.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "api/providers/__tests__/sambanova.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "api/providers/__tests__/unbound.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "api/providers/__tests__/vercel-ai-gateway.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "api/providers/__tests__/vertex.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "api/providers/__tests__/zai.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "api/providers/anthropic-vertex.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "api/providers/anthropic.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/base-openai-compatible-provider.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 6 + } + }, + "api/providers/base-provider.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "api/providers/bedrock.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 32 + } + }, + "api/providers/deepseek.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "api/providers/fetchers/__tests__/kenari.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/fetchers/__tests__/kimi-code.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/fetchers/__tests__/lmstudio.test.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "api/providers/fetchers/__tests__/modelEndpointCache.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 9 + } + }, + "api/providers/fetchers/__tests__/moonshot.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/fetchers/__tests__/ollama.test.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 9 + } + }, + "api/providers/fetchers/__tests__/opencode-go.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/fetchers/__tests__/openrouter.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "api/providers/fetchers/__tests__/vercel-ai-gateway.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/fetchers/__tests__/zoo-gateway.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 8 + } + }, + "api/providers/fetchers/litellm.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/gemini.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "api/providers/lite-llm.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 8 + } + }, + "api/providers/mimo.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "api/providers/moonshot.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/native-ollama.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "api/providers/openai-codex.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 31 + } + }, + "api/providers/openai-native.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 27 + } + }, + "api/providers/openai.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "api/providers/openrouter.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 6 + } + }, + "api/providers/poe.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "api/providers/qwen-code.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/requesty.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "api/providers/unbound.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "api/providers/utils/__tests__/error-handler.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 35 + } + }, + "api/providers/utils/__tests__/image-generation.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 17 + } + }, + "api/providers/utils/__tests__/timeout-config.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "api/providers/utils/error-handler.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 7 + } + }, + "api/providers/xai.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "api/transform/__tests__/ai-sdk.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "api/transform/__tests__/anthropic-filter.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 6 + } + }, + "api/transform/__tests__/bedrock-converse-format.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "api/transform/__tests__/gemini-format.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "api/transform/__tests__/mistral-format.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "api/transform/__tests__/model-params.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 8 + } + }, + "api/transform/__tests__/openai-format.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 49 + } + }, + "api/transform/__tests__/r1-format.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 8 + } + }, + "api/transform/__tests__/reasoning.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/transform/__tests__/responses-api-input.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "api/transform/__tests__/responses-api-stream.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "api/transform/__tests__/zai-format.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "api/transform/ai-sdk.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "api/transform/bedrock-converse-format.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "api/transform/cache-strategy/__tests__/cache-strategy.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 17 + } + }, + "api/transform/caching/__tests__/gemini.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/transform/gemini-format.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/transform/openai-format.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 8 + } + }, + "api/transform/r1-format.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "api/transform/responses-api-input.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 6 + } + }, + "api/transform/responses-api-stream.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "api/transform/zai-format.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "core/assistant-message/NativeToolCallParser.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/assistant-message/__tests__/presentAssistantMessage-custom-tool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "core/assistant-message/__tests__/presentAssistantMessage-images.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 14 + } + }, + "core/assistant-message/__tests__/presentAssistantMessage-unknown-tool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 8 + } + }, + "core/assistant-message/presentAssistantMessage.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "core/auto-approval/__tests__/AutoApprovalHandler.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/checkpoints/__tests__/checkpoint.test.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "core/checkpoints/index.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/condense/__tests__/condense.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "core/condense/__tests__/foldedFileContext.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 10 + } + }, + "core/condense/__tests__/index.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 24 + } + }, + "core/config/ContextProxy.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/config/CustomModesManager.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "core/config/ProviderSettingsManager.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "core/config/__tests__/ContextProxy.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "core/config/__tests__/CustomModesManager.exportImportSlugChange.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "core/config/__tests__/CustomModesManager.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 12 + } + }, + "core/config/__tests__/CustomModesManager.yamlEdgeCases.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/context-management/__tests__/context-management.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/context-tracking/__tests__/FileContextTracker.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "core/context/context-management/__tests__/context-error-handling.test.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/context/context-management/context-error-handling.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/diff/stats.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/environment/__tests__/getEnvironmentDetails.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/ignore/__tests__/RooIgnoreController.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/mentions/__tests__/processUserContentMentions.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/mentions/index.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/mentions/processUserContentMentions.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/message-manager/index.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 21 + } + }, + "core/message-manager/index.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/prompts/__tests__/add-custom-instructions.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/prompts/__tests__/get-prompt-component.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/prompts/__tests__/responses-rooignore.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 6 + } + }, + "core/prompts/__tests__/system-prompt.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "core/prompts/sections/__tests__/custom-instructions-global.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 18 + } + }, + "core/prompts/sections/__tests__/custom-instructions.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 55 + } + }, + "core/prompts/sections/__tests__/system-info.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/prompts/tools/__tests__/filter-tools-for-mode.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 14 + } + }, + "core/prompts/tools/native-tools/__tests__/converters.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/prompts/tools/native-tools/__tests__/read_file.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "core/task-persistence/__tests__/TaskHistoryStore.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "core/task-persistence/__tests__/importRooTaskHistory.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/task-persistence/__tests__/taskMessages.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/task-persistence/apiMessages.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/task/Task.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 17 + } + }, + "core/task/__tests__/Task.dispose.test.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "core/task/__tests__/Task.persistence.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 8 + } + }, + "core/task/__tests__/Task.sticky-profile-race.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "core/task/__tests__/Task.throttle.test.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 24 + } + }, + "core/task/__tests__/apiConversationHistory.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 23 + } + }, + "core/task/__tests__/ask-clear-approval-buttons.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 19 + } + }, + "core/task/__tests__/ask-queued-message-drain.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 18 + } + }, + "core/task/__tests__/flushPendingToolResultsToHistory.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 14 + } + }, + "core/task/__tests__/grace-retry-errors.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "core/task/__tests__/grounding-sources.test.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "core/task/__tests__/native-tools-filtering.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "core/task/__tests__/new-task-isolation.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/task/__tests__/reasoning-preservation.test.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 20 + } + }, + "core/task/__tests__/task-tool-history.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "core/task/apiConversationHistory.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 8 + } + }, + "core/tools/BaseTool.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/tools/CodebaseSearchTool.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/tools/GenerateImageTool.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/tools/NewTaskTool.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/tools/ReadFileTool.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "core/tools/ToolRepetitionDetector.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/tools/UpdateTodoListTool.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/tools/UseMcpToolTool.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "core/tools/__tests__/ReadCommandOutputTool.test.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 16 + } + }, + "core/tools/__tests__/askFollowupQuestionTool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 20 + } + }, + "core/tools/__tests__/attemptCompletionTool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 11 + } + }, + "core/tools/__tests__/editFileTool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "core/tools/__tests__/editTool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/tools/__tests__/executeCommand.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 10 + } + }, + "core/tools/__tests__/executeCommandTool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 8 + } + }, + "core/tools/__tests__/generateImageTool.test.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 9 + } + }, + "core/tools/__tests__/listFilesTool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 10 + } + }, + "core/tools/__tests__/mcpServerRestriction.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 6 + } + }, + "core/tools/__tests__/newTaskTool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 26 + } + }, + "core/tools/__tests__/readFileTool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 96 + } + }, + "core/tools/__tests__/runSlashCommandTool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/tools/__tests__/searchReplaceTool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/tools/__tests__/skillTool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "core/tools/__tests__/updateTodoListTool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/tools/__tests__/useMcpToolTool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 21 + } + }, + "core/tools/__tests__/validateToolUse.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/tools/__tests__/writeToFileTool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "core/tools/helpers/toolResultFormatting.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/tools/validateToolUse.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/webview/ClineProvider.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 7 + } + }, + "core/webview/__tests__/ClineProvider.apiHandlerRebuild.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 34 + } + }, + "core/webview/__tests__/ClineProvider.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 182 + } + }, + "core/webview/__tests__/ClineProvider.sticky-mode.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 26 + } + }, + "core/webview/__tests__/ClineProvider.sticky-profile.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 15 + } + }, + "core/webview/__tests__/ClineProvider.taskHistory.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 12 + } + }, + "core/webview/__tests__/checkpointRestoreHandler.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "core/webview/__tests__/diagnosticsHandler.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 7 + } + }, + "core/webview/__tests__/messageEnhancer.test.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 8 + } + }, + "core/webview/__tests__/skillsMessageHandler.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/webview/__tests__/telemetrySettingsTracking.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "core/webview/__tests__/webviewMessageHandler.checkpoint.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "core/webview/__tests__/webviewMessageHandler.cloudAuth.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "core/webview/__tests__/webviewMessageHandler.delete.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 9 + } + }, + "core/webview/__tests__/webviewMessageHandler.edit.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/webview/__tests__/webviewMessageHandler.importRooHistory.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 13 + } + }, + "core/webview/__tests__/webviewMessageHandler.readFileContent.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/webview/__tests__/webviewMessageHandler.routerModels.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 56 + } + }, + "core/webview/__tests__/webviewMessageHandler.searchFiles.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "core/webview/__tests__/webviewMessageHandler.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 35 + } + }, + "core/webview/messageEnhancer.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/webview/webviewMessageHandler.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "extension/__tests__/api-delete-queued-message.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "extension/__tests__/api-send-message.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 7 + } + }, + "extension/api.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 9 + } + }, + "i18n/index.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "i18n/setup.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "integrations/editor/DiffViewProvider.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "integrations/editor/__tests__/DiffViewProvider.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 310 + } + }, + "integrations/editor/__tests__/EditorUtils.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "integrations/kimi-code/__tests__/oauth.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "integrations/misc/__tests__/export-markdown.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "integrations/misc/__tests__/open-file.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 11 + } + }, + "integrations/misc/__tests__/performance/processCarriageReturns.benchmark.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "integrations/terminal/__tests__/ExecaTerminalProcess.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 10 + } + }, + "integrations/terminal/__tests__/OutputInterceptor.test.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "integrations/terminal/__tests__/TerminalProcess.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 7 + } + }, + "integrations/terminal/__tests__/TerminalProcess.test.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "integrations/terminal/__tests__/TerminalProcessExec.bash.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "integrations/terminal/__tests__/TerminalProcessExec.cmd.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "integrations/terminal/__tests__/TerminalProcessExec.pwsh.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "integrations/terminal/__tests__/TerminalProcessInterpretExitCode.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "integrations/terminal/__tests__/TerminalProfile.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 34 + } + }, + "integrations/terminal/__tests__/TerminalRegistry.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 22 + } + }, + "integrations/terminal/__tests__/setupTerminalTests.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "integrations/terminal/__tests__/streamUtils/bashStream.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "integrations/terminal/__tests__/streamUtils/cmdStream.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "integrations/terminal/__tests__/streamUtils/index.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "integrations/terminal/__tests__/streamUtils/pwshStream.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "integrations/theme/getTheme.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 9 + } + }, + "services/__tests__/zoo-code-auth.test.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "services/checkpoints/__tests__/ShadowCheckpointService.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "services/code-index/__tests__/config-manager.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "services/code-index/__tests__/manager.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 84 + } + }, + "services/code-index/__tests__/orchestrator.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 23 + } + }, + "services/code-index/__tests__/service-factory.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 43 + } + }, + "services/code-index/embedders/__tests__/bedrock.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 7 + } + }, + "services/code-index/embedders/__tests__/gemini.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "services/code-index/embedders/__tests__/mistral.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "services/code-index/embedders/__tests__/ollama.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "services/code-index/embedders/__tests__/openai-compatible-rate-limit.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 15 + } + }, + "services/code-index/embedders/__tests__/openai-compatible.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 28 + } + }, + "services/code-index/embedders/__tests__/openai.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 10 + } + }, + "services/code-index/embedders/__tests__/openrouter.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "services/code-index/embedders/__tests__/vercel-ai-gateway.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "services/code-index/embedders/bedrock.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "services/code-index/embedders/ollama.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "services/code-index/embedders/openai-compatible.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "services/code-index/embedders/openai.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "services/code-index/embedders/openrouter.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "services/code-index/interfaces/vector-store.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "services/code-index/orchestrator.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "services/code-index/processors/__tests__/file-watcher.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 25 + } + }, + "services/code-index/processors/__tests__/parser.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 22 + } + }, + "services/code-index/processors/__tests__/scanner.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 26 + } + }, + "services/code-index/processors/file-watcher.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "services/code-index/processors/scanner.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "services/code-index/semble/__tests__/provider.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 12 + } + }, + "services/code-index/semble/__tests__/semble-cli.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "services/code-index/semble/__tests__/semble-downloader.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 61 + } + }, + "services/code-index/semble/provider.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "services/code-index/semble/semble-cli.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "services/code-index/shared/__tests__/validation-helpers.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "services/code-index/shared/validation-helpers.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "services/code-index/vector-store/__tests__/qdrant-client.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 87 + } + }, + "services/code-index/vector-store/qdrant-client.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "services/glob/__tests__/gitignore-integration.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "services/glob/__tests__/gitignore-test.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "services/glob/__tests__/list-files-limit.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 6 + } + }, + "services/glob/__tests__/list-files.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 22 + } + }, + "services/marketplace/MarketplaceManager.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "services/marketplace/SimpleInstaller.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 7 + } + }, + "services/marketplace/__tests__/MarketplaceManager.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "services/marketplace/__tests__/SimpleInstaller.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 17 + } + }, + "services/marketplace/__tests__/marketplace-setting-check.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "services/mcp/McpHub.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 7 + } + }, + "services/mcp/McpOAuthClientProvider.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "services/mcp/McpServerManager.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "services/mcp/__tests__/McpHub.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 150 + } + }, + "services/mcp/__tests__/McpOAuthClientProvider.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 18 + } + }, + "services/mcp/__tests__/SecretStorageService.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "services/mcp/utils/__tests__/oauth.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 9 + } + }, + "services/mcp/utils/callbackServer.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "services/mcp/utils/oauth.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "services/mdm/__tests__/MdmService.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "services/ripgrep/__tests__/diagnostic.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "services/roo-config/__tests__/index.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 20 + } + }, + "services/roo-config/index.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "services/rules/__tests__/rules.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "services/search/__tests__/file-search.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "services/skills/__tests__/SkillsManager.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "services/tree-sitter/__tests__/helpers.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "services/tree-sitter/__tests__/markdownParser.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "shared/__tests__/api.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 8 + } + }, + "shared/__tests__/embeddingModels.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "shared/__tests__/modes-empty-prompt-component.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "shared/api.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "shared/checkExistApiConfig.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "shared/cost.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "shared/parse-command.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "shared/support-prompt.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "shared/tools.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "shared/utils/__tests__/requesty.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "vitest.setup.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + } +} \ No newline at end of file From f789fc80893def62c0145880be0026fb6256b703 Mon Sep 17 00:00:00 2001 From: Eason Liang <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Tue, 3 Nov 2026 03:03:39 +0800 Subject: [PATCH 26/27] style: format the suppressions file with prettier Content is unchanged (verified by JSON equality); only the formatting differs, which the compile job format:check enforces. --- src/eslint-suppressions.json | 3252 +++++++++++++++++----------------- 1 file changed, 1626 insertions(+), 1626 deletions(-) diff --git a/src/eslint-suppressions.json b/src/eslint-suppressions.json index 1ef5fef9ae..43d1496f6b 100644 --- a/src/eslint-suppressions.json +++ b/src/eslint-suppressions.json @@ -1,1627 +1,1627 @@ { - "__mocks__/fs/promises.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "__tests__/ClineProvider.delegation.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 9 - } - }, - "__tests__/ClineProvider.history-resume-delegation.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 70 - } - }, - "__tests__/abandonSubtask.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 20 - } - }, - "__tests__/api-subtask.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "__tests__/delegation-concurrent.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 6 - } - }, - "__tests__/delegation-events.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 6 - } - }, - "__tests__/migrateSettings.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "__tests__/nested-delegation-resume.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 19 - } - }, - "__tests__/new-task-delegation.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 8 - } - }, - "activate/CodeActionProvider.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "activate/__tests__/CodeActionProvider.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 10 - } - }, - "activate/__tests__/handleUri.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 14 - } - }, - "activate/__tests__/registerCommands.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "activate/registerCodeActions.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "activate/registerCommands.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "activate/registerTerminalActions.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/__tests__/anthropic-vertex.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 31 - } - }, - "api/providers/__tests__/anthropic.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 7 - } - }, - "api/providers/__tests__/base-openai-compatible-provider-timeout.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "api/providers/__tests__/base-openai-compatible-provider.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/__tests__/base-provider.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "api/providers/__tests__/bedrock-custom-arn.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 12 - } - }, - "api/providers/__tests__/bedrock-error-handling.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 7 - } - }, - "api/providers/__tests__/bedrock-inference-profiles.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 27 - } - }, - "api/providers/__tests__/bedrock-native-tools.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 19 - } - }, - "api/providers/__tests__/bedrock-reasoning.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/__tests__/bedrock.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 37 - } - }, - "api/providers/__tests__/deepseek.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 12 - } - }, - "api/providers/__tests__/gemini-handler.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 18 - } - }, - "api/providers/__tests__/gemini.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 33 - } - }, - "api/providers/__tests__/kenari.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/__tests__/kimi-code.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/__tests__/lite-llm.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 36 - } - }, - "api/providers/__tests__/lm-studio-timeout.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "api/providers/__tests__/mimo.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 18 - } - }, - "api/providers/__tests__/minimax.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "api/providers/__tests__/moonshot.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 22 - } - }, - "api/providers/__tests__/native-ollama.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 21 - } - }, - "api/providers/__tests__/openai-codex-native-tool-calls.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 22 - } - }, - "api/providers/__tests__/openai-codex.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 16 - } - }, - "api/providers/__tests__/openai-native-tools.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 14 - } - }, - "api/providers/__tests__/openai-native-usage.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 25 - } - }, - "api/providers/__tests__/openai-native.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 74 - } - }, - "api/providers/__tests__/openai-timeout.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "api/providers/__tests__/openai.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "api/providers/__tests__/opencode-go.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "api/providers/__tests__/openrouter.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 34 - } - }, - "api/providers/__tests__/poe.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/__tests__/qwen-code-native-tools.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "api/providers/__tests__/sambanova.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "api/providers/__tests__/unbound.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "api/providers/__tests__/vercel-ai-gateway.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "api/providers/__tests__/vertex.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "api/providers/__tests__/zai.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "api/providers/anthropic-vertex.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "api/providers/anthropic.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/base-openai-compatible-provider.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 6 - } - }, - "api/providers/base-provider.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "api/providers/bedrock.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 32 - } - }, - "api/providers/deepseek.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "api/providers/fetchers/__tests__/kenari.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/fetchers/__tests__/kimi-code.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/fetchers/__tests__/lmstudio.test.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "api/providers/fetchers/__tests__/modelEndpointCache.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 9 - } - }, - "api/providers/fetchers/__tests__/moonshot.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/fetchers/__tests__/ollama.test.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 9 - } - }, - "api/providers/fetchers/__tests__/opencode-go.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/fetchers/__tests__/openrouter.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "api/providers/fetchers/__tests__/vercel-ai-gateway.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/fetchers/__tests__/zoo-gateway.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 8 - } - }, - "api/providers/fetchers/litellm.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/gemini.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "api/providers/lite-llm.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 8 - } - }, - "api/providers/mimo.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "api/providers/moonshot.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/native-ollama.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "api/providers/openai-codex.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 31 - } - }, - "api/providers/openai-native.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 27 - } - }, - "api/providers/openai.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "api/providers/openrouter.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 6 - } - }, - "api/providers/poe.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "api/providers/qwen-code.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/providers/requesty.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "api/providers/unbound.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "api/providers/utils/__tests__/error-handler.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 35 - } - }, - "api/providers/utils/__tests__/image-generation.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 17 - } - }, - "api/providers/utils/__tests__/timeout-config.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "api/providers/utils/error-handler.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 7 - } - }, - "api/providers/xai.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "api/transform/__tests__/ai-sdk.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "api/transform/__tests__/anthropic-filter.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 6 - } - }, - "api/transform/__tests__/bedrock-converse-format.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "api/transform/__tests__/gemini-format.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "api/transform/__tests__/mistral-format.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "api/transform/__tests__/model-params.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 8 - } - }, - "api/transform/__tests__/openai-format.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 49 - } - }, - "api/transform/__tests__/r1-format.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 8 - } - }, - "api/transform/__tests__/reasoning.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/transform/__tests__/responses-api-input.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "api/transform/__tests__/responses-api-stream.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "api/transform/__tests__/zai-format.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "api/transform/ai-sdk.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "api/transform/bedrock-converse-format.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "api/transform/cache-strategy/__tests__/cache-strategy.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 17 - } - }, - "api/transform/caching/__tests__/gemini.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/transform/gemini-format.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "api/transform/openai-format.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 8 - } - }, - "api/transform/r1-format.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "api/transform/responses-api-input.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 6 - } - }, - "api/transform/responses-api-stream.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "api/transform/zai-format.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "core/assistant-message/NativeToolCallParser.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/assistant-message/__tests__/presentAssistantMessage-custom-tool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "core/assistant-message/__tests__/presentAssistantMessage-images.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 14 - } - }, - "core/assistant-message/__tests__/presentAssistantMessage-unknown-tool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 8 - } - }, - "core/assistant-message/presentAssistantMessage.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "core/auto-approval/__tests__/AutoApprovalHandler.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/checkpoints/__tests__/checkpoint.test.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "core/checkpoints/index.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/condense/__tests__/condense.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "core/condense/__tests__/foldedFileContext.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 10 - } - }, - "core/condense/__tests__/index.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 24 - } - }, - "core/config/ContextProxy.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/config/CustomModesManager.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "core/config/ProviderSettingsManager.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "core/config/__tests__/ContextProxy.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "core/config/__tests__/CustomModesManager.exportImportSlugChange.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "core/config/__tests__/CustomModesManager.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 12 - } - }, - "core/config/__tests__/CustomModesManager.yamlEdgeCases.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/context-management/__tests__/context-management.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/context-tracking/__tests__/FileContextTracker.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "core/context/context-management/__tests__/context-error-handling.test.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/context/context-management/context-error-handling.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/diff/stats.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/environment/__tests__/getEnvironmentDetails.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/ignore/__tests__/RooIgnoreController.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/mentions/__tests__/processUserContentMentions.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/mentions/index.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/mentions/processUserContentMentions.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/message-manager/index.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 21 - } - }, - "core/message-manager/index.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/prompts/__tests__/add-custom-instructions.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/prompts/__tests__/get-prompt-component.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/prompts/__tests__/responses-rooignore.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 6 - } - }, - "core/prompts/__tests__/system-prompt.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "core/prompts/sections/__tests__/custom-instructions-global.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 18 - } - }, - "core/prompts/sections/__tests__/custom-instructions.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 55 - } - }, - "core/prompts/sections/__tests__/system-info.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/prompts/tools/__tests__/filter-tools-for-mode.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 14 - } - }, - "core/prompts/tools/native-tools/__tests__/converters.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/prompts/tools/native-tools/__tests__/read_file.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "core/task-persistence/__tests__/TaskHistoryStore.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "core/task-persistence/__tests__/importRooTaskHistory.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/task-persistence/__tests__/taskMessages.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/task-persistence/apiMessages.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/task/Task.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 17 - } - }, - "core/task/__tests__/Task.dispose.test.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "core/task/__tests__/Task.persistence.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 8 - } - }, - "core/task/__tests__/Task.sticky-profile-race.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "core/task/__tests__/Task.throttle.test.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 24 - } - }, - "core/task/__tests__/apiConversationHistory.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 23 - } - }, - "core/task/__tests__/ask-clear-approval-buttons.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 19 - } - }, - "core/task/__tests__/ask-queued-message-drain.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 18 - } - }, - "core/task/__tests__/flushPendingToolResultsToHistory.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 14 - } - }, - "core/task/__tests__/grace-retry-errors.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "core/task/__tests__/grounding-sources.test.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "core/task/__tests__/native-tools-filtering.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "core/task/__tests__/new-task-isolation.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/task/__tests__/reasoning-preservation.test.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 20 - } - }, - "core/task/__tests__/task-tool-history.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "core/task/apiConversationHistory.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 8 - } - }, - "core/tools/BaseTool.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/tools/CodebaseSearchTool.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/tools/GenerateImageTool.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/tools/NewTaskTool.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/tools/ReadFileTool.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "core/tools/ToolRepetitionDetector.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/tools/UpdateTodoListTool.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/tools/UseMcpToolTool.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "core/tools/__tests__/ReadCommandOutputTool.test.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 16 - } - }, - "core/tools/__tests__/askFollowupQuestionTool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 20 - } - }, - "core/tools/__tests__/attemptCompletionTool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 11 - } - }, - "core/tools/__tests__/editFileTool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "core/tools/__tests__/editTool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/tools/__tests__/executeCommand.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 10 - } - }, - "core/tools/__tests__/executeCommandTool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 8 - } - }, - "core/tools/__tests__/generateImageTool.test.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 9 - } - }, - "core/tools/__tests__/listFilesTool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 10 - } - }, - "core/tools/__tests__/mcpServerRestriction.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 6 - } - }, - "core/tools/__tests__/newTaskTool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 26 - } - }, - "core/tools/__tests__/readFileTool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 96 - } - }, - "core/tools/__tests__/runSlashCommandTool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/tools/__tests__/searchReplaceTool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/tools/__tests__/skillTool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "core/tools/__tests__/updateTodoListTool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/tools/__tests__/useMcpToolTool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 21 - } - }, - "core/tools/__tests__/validateToolUse.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/tools/__tests__/writeToFileTool.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "core/tools/helpers/toolResultFormatting.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/tools/validateToolUse.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "core/webview/ClineProvider.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 7 - } - }, - "core/webview/__tests__/ClineProvider.apiHandlerRebuild.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 34 - } - }, - "core/webview/__tests__/ClineProvider.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 182 - } - }, - "core/webview/__tests__/ClineProvider.sticky-mode.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 26 - } - }, - "core/webview/__tests__/ClineProvider.sticky-profile.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 15 - } - }, - "core/webview/__tests__/ClineProvider.taskHistory.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 12 - } - }, - "core/webview/__tests__/checkpointRestoreHandler.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "core/webview/__tests__/diagnosticsHandler.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 7 - } - }, - "core/webview/__tests__/messageEnhancer.test.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 8 - } - }, - "core/webview/__tests__/skillsMessageHandler.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/webview/__tests__/telemetrySettingsTracking.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "core/webview/__tests__/webviewMessageHandler.checkpoint.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "core/webview/__tests__/webviewMessageHandler.cloudAuth.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "core/webview/__tests__/webviewMessageHandler.delete.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 9 - } - }, - "core/webview/__tests__/webviewMessageHandler.edit.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/webview/__tests__/webviewMessageHandler.importRooHistory.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 13 - } - }, - "core/webview/__tests__/webviewMessageHandler.readFileContent.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/webview/__tests__/webviewMessageHandler.routerModels.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 56 - } - }, - "core/webview/__tests__/webviewMessageHandler.searchFiles.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "core/webview/__tests__/webviewMessageHandler.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 35 - } - }, - "core/webview/messageEnhancer.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "core/webview/webviewMessageHandler.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "extension/__tests__/api-delete-queued-message.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "extension/__tests__/api-send-message.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 7 - } - }, - "extension/api.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 9 - } - }, - "i18n/index.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "i18n/setup.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "integrations/editor/DiffViewProvider.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "integrations/editor/__tests__/DiffViewProvider.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 310 - } - }, - "integrations/editor/__tests__/EditorUtils.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "integrations/kimi-code/__tests__/oauth.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "integrations/misc/__tests__/export-markdown.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "integrations/misc/__tests__/open-file.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 11 - } - }, - "integrations/misc/__tests__/performance/processCarriageReturns.benchmark.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "integrations/terminal/__tests__/ExecaTerminalProcess.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 10 - } - }, - "integrations/terminal/__tests__/OutputInterceptor.test.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "integrations/terminal/__tests__/TerminalProcess.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 7 - } - }, - "integrations/terminal/__tests__/TerminalProcess.test.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "integrations/terminal/__tests__/TerminalProcessExec.bash.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "integrations/terminal/__tests__/TerminalProcessExec.cmd.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "integrations/terminal/__tests__/TerminalProcessExec.pwsh.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "integrations/terminal/__tests__/TerminalProcessInterpretExitCode.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "integrations/terminal/__tests__/TerminalProfile.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 34 - } - }, - "integrations/terminal/__tests__/TerminalRegistry.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 22 - } - }, - "integrations/terminal/__tests__/setupTerminalTests.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "integrations/terminal/__tests__/streamUtils/bashStream.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "integrations/terminal/__tests__/streamUtils/cmdStream.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "integrations/terminal/__tests__/streamUtils/index.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "integrations/terminal/__tests__/streamUtils/pwshStream.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "integrations/theme/getTheme.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 9 - } - }, - "services/__tests__/zoo-code-auth.test.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "services/checkpoints/__tests__/ShadowCheckpointService.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "services/code-index/__tests__/config-manager.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "services/code-index/__tests__/manager.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 84 - } - }, - "services/code-index/__tests__/orchestrator.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 23 - } - }, - "services/code-index/__tests__/service-factory.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 43 - } - }, - "services/code-index/embedders/__tests__/bedrock.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 7 - } - }, - "services/code-index/embedders/__tests__/gemini.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "services/code-index/embedders/__tests__/mistral.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "services/code-index/embedders/__tests__/ollama.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "services/code-index/embedders/__tests__/openai-compatible-rate-limit.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 15 - } - }, - "services/code-index/embedders/__tests__/openai-compatible.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 28 - } - }, - "services/code-index/embedders/__tests__/openai.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 10 - } - }, - "services/code-index/embedders/__tests__/openrouter.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "services/code-index/embedders/__tests__/vercel-ai-gateway.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "services/code-index/embedders/bedrock.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "services/code-index/embedders/ollama.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "services/code-index/embedders/openai-compatible.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "services/code-index/embedders/openai.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "services/code-index/embedders/openrouter.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "services/code-index/interfaces/vector-store.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "services/code-index/orchestrator.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "services/code-index/processors/__tests__/file-watcher.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 25 - } - }, - "services/code-index/processors/__tests__/parser.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 22 - } - }, - "services/code-index/processors/__tests__/scanner.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 26 - } - }, - "services/code-index/processors/file-watcher.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "services/code-index/processors/scanner.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "services/code-index/semble/__tests__/provider.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 12 - } - }, - "services/code-index/semble/__tests__/semble-cli.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "services/code-index/semble/__tests__/semble-downloader.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 61 - } - }, - "services/code-index/semble/provider.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "services/code-index/semble/semble-cli.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "services/code-index/shared/__tests__/validation-helpers.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "services/code-index/shared/validation-helpers.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "services/code-index/vector-store/__tests__/qdrant-client.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 87 - } - }, - "services/code-index/vector-store/qdrant-client.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "services/glob/__tests__/gitignore-integration.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "services/glob/__tests__/gitignore-test.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "services/glob/__tests__/list-files-limit.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 6 - } - }, - "services/glob/__tests__/list-files.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 22 - } - }, - "services/marketplace/MarketplaceManager.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "services/marketplace/SimpleInstaller.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 7 - } - }, - "services/marketplace/__tests__/MarketplaceManager.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "services/marketplace/__tests__/SimpleInstaller.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 17 - } - }, - "services/marketplace/__tests__/marketplace-setting-check.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "services/mcp/McpHub.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 7 - } - }, - "services/mcp/McpOAuthClientProvider.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "services/mcp/McpServerManager.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "services/mcp/__tests__/McpHub.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 150 - } - }, - "services/mcp/__tests__/McpOAuthClientProvider.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 18 - } - }, - "services/mcp/__tests__/SecretStorageService.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "services/mcp/utils/__tests__/oauth.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 9 - } - }, - "services/mcp/utils/callbackServer.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "services/mcp/utils/oauth.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "services/mdm/__tests__/MdmService.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "services/ripgrep/__tests__/diagnostic.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "services/roo-config/__tests__/index.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 20 - } - }, - "services/roo-config/index.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "services/rules/__tests__/rules.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "services/search/__tests__/file-search.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 3 - } - }, - "services/skills/__tests__/SkillsManager.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "services/tree-sitter/__tests__/helpers.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 4 - } - }, - "services/tree-sitter/__tests__/markdownParser.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "shared/__tests__/api.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 8 - } - }, - "shared/__tests__/embeddingModels.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "shared/__tests__/modes-empty-prompt-component.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "shared/api.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "shared/checkExistApiConfig.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "shared/cost.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "shared/parse-command.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "shared/support-prompt.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 5 - } - }, - "shared/tools.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "shared/utils/__tests__/requesty.spec.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, - "vitest.setup.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - } -} \ No newline at end of file + "__mocks__/fs/promises.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "__tests__/ClineProvider.delegation.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 9 + } + }, + "__tests__/ClineProvider.history-resume-delegation.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 70 + } + }, + "__tests__/abandonSubtask.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 20 + } + }, + "__tests__/api-subtask.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "__tests__/delegation-concurrent.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 6 + } + }, + "__tests__/delegation-events.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 6 + } + }, + "__tests__/migrateSettings.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "__tests__/nested-delegation-resume.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 19 + } + }, + "__tests__/new-task-delegation.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 8 + } + }, + "activate/CodeActionProvider.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "activate/__tests__/CodeActionProvider.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 10 + } + }, + "activate/__tests__/handleUri.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 14 + } + }, + "activate/__tests__/registerCommands.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "activate/registerCodeActions.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "activate/registerCommands.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "activate/registerTerminalActions.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/__tests__/anthropic-vertex.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 31 + } + }, + "api/providers/__tests__/anthropic.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 7 + } + }, + "api/providers/__tests__/base-openai-compatible-provider-timeout.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "api/providers/__tests__/base-openai-compatible-provider.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/__tests__/base-provider.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "api/providers/__tests__/bedrock-custom-arn.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 12 + } + }, + "api/providers/__tests__/bedrock-error-handling.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 7 + } + }, + "api/providers/__tests__/bedrock-inference-profiles.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 27 + } + }, + "api/providers/__tests__/bedrock-native-tools.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 19 + } + }, + "api/providers/__tests__/bedrock-reasoning.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/__tests__/bedrock.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 37 + } + }, + "api/providers/__tests__/deepseek.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 12 + } + }, + "api/providers/__tests__/gemini-handler.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 18 + } + }, + "api/providers/__tests__/gemini.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 33 + } + }, + "api/providers/__tests__/kenari.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/__tests__/kimi-code.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/__tests__/lite-llm.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 36 + } + }, + "api/providers/__tests__/lm-studio-timeout.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "api/providers/__tests__/mimo.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 18 + } + }, + "api/providers/__tests__/minimax.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "api/providers/__tests__/moonshot.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 22 + } + }, + "api/providers/__tests__/native-ollama.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 21 + } + }, + "api/providers/__tests__/openai-codex-native-tool-calls.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 22 + } + }, + "api/providers/__tests__/openai-codex.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 16 + } + }, + "api/providers/__tests__/openai-native-tools.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 14 + } + }, + "api/providers/__tests__/openai-native-usage.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 25 + } + }, + "api/providers/__tests__/openai-native.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 74 + } + }, + "api/providers/__tests__/openai-timeout.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "api/providers/__tests__/openai.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "api/providers/__tests__/opencode-go.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "api/providers/__tests__/openrouter.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 34 + } + }, + "api/providers/__tests__/poe.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/__tests__/qwen-code-native-tools.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "api/providers/__tests__/sambanova.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "api/providers/__tests__/unbound.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "api/providers/__tests__/vercel-ai-gateway.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "api/providers/__tests__/vertex.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "api/providers/__tests__/zai.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "api/providers/anthropic-vertex.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "api/providers/anthropic.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/base-openai-compatible-provider.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 6 + } + }, + "api/providers/base-provider.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "api/providers/bedrock.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 32 + } + }, + "api/providers/deepseek.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "api/providers/fetchers/__tests__/kenari.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/fetchers/__tests__/kimi-code.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/fetchers/__tests__/lmstudio.test.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "api/providers/fetchers/__tests__/modelEndpointCache.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 9 + } + }, + "api/providers/fetchers/__tests__/moonshot.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/fetchers/__tests__/ollama.test.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 9 + } + }, + "api/providers/fetchers/__tests__/opencode-go.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/fetchers/__tests__/openrouter.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "api/providers/fetchers/__tests__/vercel-ai-gateway.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/fetchers/__tests__/zoo-gateway.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 8 + } + }, + "api/providers/fetchers/litellm.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/gemini.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "api/providers/lite-llm.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 8 + } + }, + "api/providers/mimo.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "api/providers/moonshot.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/native-ollama.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "api/providers/openai-codex.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 31 + } + }, + "api/providers/openai-native.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 27 + } + }, + "api/providers/openai.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "api/providers/openrouter.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 6 + } + }, + "api/providers/poe.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "api/providers/qwen-code.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/providers/requesty.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "api/providers/unbound.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "api/providers/utils/__tests__/error-handler.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 35 + } + }, + "api/providers/utils/__tests__/image-generation.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 17 + } + }, + "api/providers/utils/__tests__/timeout-config.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "api/providers/utils/error-handler.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 7 + } + }, + "api/providers/xai.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "api/transform/__tests__/ai-sdk.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "api/transform/__tests__/anthropic-filter.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 6 + } + }, + "api/transform/__tests__/bedrock-converse-format.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "api/transform/__tests__/gemini-format.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "api/transform/__tests__/mistral-format.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "api/transform/__tests__/model-params.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 8 + } + }, + "api/transform/__tests__/openai-format.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 49 + } + }, + "api/transform/__tests__/r1-format.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 8 + } + }, + "api/transform/__tests__/reasoning.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/transform/__tests__/responses-api-input.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "api/transform/__tests__/responses-api-stream.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "api/transform/__tests__/zai-format.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "api/transform/ai-sdk.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "api/transform/bedrock-converse-format.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "api/transform/cache-strategy/__tests__/cache-strategy.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 17 + } + }, + "api/transform/caching/__tests__/gemini.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/transform/gemini-format.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "api/transform/openai-format.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 8 + } + }, + "api/transform/r1-format.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "api/transform/responses-api-input.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 6 + } + }, + "api/transform/responses-api-stream.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "api/transform/zai-format.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "core/assistant-message/NativeToolCallParser.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/assistant-message/__tests__/presentAssistantMessage-custom-tool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "core/assistant-message/__tests__/presentAssistantMessage-images.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 14 + } + }, + "core/assistant-message/__tests__/presentAssistantMessage-unknown-tool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 8 + } + }, + "core/assistant-message/presentAssistantMessage.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "core/auto-approval/__tests__/AutoApprovalHandler.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/checkpoints/__tests__/checkpoint.test.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "core/checkpoints/index.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/condense/__tests__/condense.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "core/condense/__tests__/foldedFileContext.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 10 + } + }, + "core/condense/__tests__/index.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 24 + } + }, + "core/config/ContextProxy.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/config/CustomModesManager.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "core/config/ProviderSettingsManager.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "core/config/__tests__/ContextProxy.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "core/config/__tests__/CustomModesManager.exportImportSlugChange.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "core/config/__tests__/CustomModesManager.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 12 + } + }, + "core/config/__tests__/CustomModesManager.yamlEdgeCases.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/context-management/__tests__/context-management.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/context-tracking/__tests__/FileContextTracker.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "core/context/context-management/__tests__/context-error-handling.test.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/context/context-management/context-error-handling.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/diff/stats.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/environment/__tests__/getEnvironmentDetails.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/ignore/__tests__/RooIgnoreController.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/mentions/__tests__/processUserContentMentions.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/mentions/index.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/mentions/processUserContentMentions.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/message-manager/index.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 21 + } + }, + "core/message-manager/index.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/prompts/__tests__/add-custom-instructions.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/prompts/__tests__/get-prompt-component.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/prompts/__tests__/responses-rooignore.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 6 + } + }, + "core/prompts/__tests__/system-prompt.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "core/prompts/sections/__tests__/custom-instructions-global.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 18 + } + }, + "core/prompts/sections/__tests__/custom-instructions.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 55 + } + }, + "core/prompts/sections/__tests__/system-info.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/prompts/tools/__tests__/filter-tools-for-mode.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 14 + } + }, + "core/prompts/tools/native-tools/__tests__/converters.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/prompts/tools/native-tools/__tests__/read_file.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "core/task-persistence/__tests__/TaskHistoryStore.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "core/task-persistence/__tests__/importRooTaskHistory.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/task-persistence/__tests__/taskMessages.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/task-persistence/apiMessages.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/task/Task.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 17 + } + }, + "core/task/__tests__/Task.dispose.test.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "core/task/__tests__/Task.persistence.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 8 + } + }, + "core/task/__tests__/Task.sticky-profile-race.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "core/task/__tests__/Task.throttle.test.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 24 + } + }, + "core/task/__tests__/apiConversationHistory.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 23 + } + }, + "core/task/__tests__/ask-clear-approval-buttons.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 19 + } + }, + "core/task/__tests__/ask-queued-message-drain.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 18 + } + }, + "core/task/__tests__/flushPendingToolResultsToHistory.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 14 + } + }, + "core/task/__tests__/grace-retry-errors.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "core/task/__tests__/grounding-sources.test.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "core/task/__tests__/native-tools-filtering.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "core/task/__tests__/new-task-isolation.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/task/__tests__/reasoning-preservation.test.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 20 + } + }, + "core/task/__tests__/task-tool-history.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "core/task/apiConversationHistory.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 8 + } + }, + "core/tools/BaseTool.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/tools/CodebaseSearchTool.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/tools/GenerateImageTool.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/tools/NewTaskTool.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/tools/ReadFileTool.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "core/tools/ToolRepetitionDetector.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/tools/UpdateTodoListTool.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/tools/UseMcpToolTool.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "core/tools/__tests__/ReadCommandOutputTool.test.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 16 + } + }, + "core/tools/__tests__/askFollowupQuestionTool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 20 + } + }, + "core/tools/__tests__/attemptCompletionTool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 11 + } + }, + "core/tools/__tests__/editFileTool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "core/tools/__tests__/editTool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/tools/__tests__/executeCommand.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 10 + } + }, + "core/tools/__tests__/executeCommandTool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 8 + } + }, + "core/tools/__tests__/generateImageTool.test.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 9 + } + }, + "core/tools/__tests__/listFilesTool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 10 + } + }, + "core/tools/__tests__/mcpServerRestriction.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 6 + } + }, + "core/tools/__tests__/newTaskTool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 26 + } + }, + "core/tools/__tests__/readFileTool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 96 + } + }, + "core/tools/__tests__/runSlashCommandTool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/tools/__tests__/searchReplaceTool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/tools/__tests__/skillTool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "core/tools/__tests__/updateTodoListTool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/tools/__tests__/useMcpToolTool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 21 + } + }, + "core/tools/__tests__/validateToolUse.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/tools/__tests__/writeToFileTool.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "core/tools/helpers/toolResultFormatting.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/tools/validateToolUse.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "core/webview/ClineProvider.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 7 + } + }, + "core/webview/__tests__/ClineProvider.apiHandlerRebuild.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 34 + } + }, + "core/webview/__tests__/ClineProvider.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 182 + } + }, + "core/webview/__tests__/ClineProvider.sticky-mode.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 26 + } + }, + "core/webview/__tests__/ClineProvider.sticky-profile.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 15 + } + }, + "core/webview/__tests__/ClineProvider.taskHistory.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 12 + } + }, + "core/webview/__tests__/checkpointRestoreHandler.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "core/webview/__tests__/diagnosticsHandler.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 7 + } + }, + "core/webview/__tests__/messageEnhancer.test.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 8 + } + }, + "core/webview/__tests__/skillsMessageHandler.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/webview/__tests__/telemetrySettingsTracking.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "core/webview/__tests__/webviewMessageHandler.checkpoint.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "core/webview/__tests__/webviewMessageHandler.cloudAuth.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "core/webview/__tests__/webviewMessageHandler.delete.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 9 + } + }, + "core/webview/__tests__/webviewMessageHandler.edit.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/webview/__tests__/webviewMessageHandler.importRooHistory.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 13 + } + }, + "core/webview/__tests__/webviewMessageHandler.readFileContent.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/webview/__tests__/webviewMessageHandler.routerModels.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 56 + } + }, + "core/webview/__tests__/webviewMessageHandler.searchFiles.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "core/webview/__tests__/webviewMessageHandler.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 35 + } + }, + "core/webview/messageEnhancer.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "core/webview/webviewMessageHandler.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "extension/__tests__/api-delete-queued-message.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "extension/__tests__/api-send-message.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 7 + } + }, + "extension/api.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 9 + } + }, + "i18n/index.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "i18n/setup.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "integrations/editor/DiffViewProvider.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "integrations/editor/__tests__/DiffViewProvider.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 310 + } + }, + "integrations/editor/__tests__/EditorUtils.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "integrations/kimi-code/__tests__/oauth.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "integrations/misc/__tests__/export-markdown.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "integrations/misc/__tests__/open-file.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 11 + } + }, + "integrations/misc/__tests__/performance/processCarriageReturns.benchmark.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "integrations/terminal/__tests__/ExecaTerminalProcess.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 10 + } + }, + "integrations/terminal/__tests__/OutputInterceptor.test.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "integrations/terminal/__tests__/TerminalProcess.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 7 + } + }, + "integrations/terminal/__tests__/TerminalProcess.test.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "integrations/terminal/__tests__/TerminalProcessExec.bash.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "integrations/terminal/__tests__/TerminalProcessExec.cmd.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "integrations/terminal/__tests__/TerminalProcessExec.pwsh.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "integrations/terminal/__tests__/TerminalProcessInterpretExitCode.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "integrations/terminal/__tests__/TerminalProfile.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 34 + } + }, + "integrations/terminal/__tests__/TerminalRegistry.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 22 + } + }, + "integrations/terminal/__tests__/setupTerminalTests.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "integrations/terminal/__tests__/streamUtils/bashStream.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "integrations/terminal/__tests__/streamUtils/cmdStream.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "integrations/terminal/__tests__/streamUtils/index.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "integrations/terminal/__tests__/streamUtils/pwshStream.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "integrations/theme/getTheme.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 9 + } + }, + "services/__tests__/zoo-code-auth.test.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "services/checkpoints/__tests__/ShadowCheckpointService.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "services/code-index/__tests__/config-manager.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "services/code-index/__tests__/manager.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 84 + } + }, + "services/code-index/__tests__/orchestrator.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 23 + } + }, + "services/code-index/__tests__/service-factory.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 43 + } + }, + "services/code-index/embedders/__tests__/bedrock.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 7 + } + }, + "services/code-index/embedders/__tests__/gemini.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "services/code-index/embedders/__tests__/mistral.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "services/code-index/embedders/__tests__/ollama.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "services/code-index/embedders/__tests__/openai-compatible-rate-limit.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 15 + } + }, + "services/code-index/embedders/__tests__/openai-compatible.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 28 + } + }, + "services/code-index/embedders/__tests__/openai.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 10 + } + }, + "services/code-index/embedders/__tests__/openrouter.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "services/code-index/embedders/__tests__/vercel-ai-gateway.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "services/code-index/embedders/bedrock.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "services/code-index/embedders/ollama.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "services/code-index/embedders/openai-compatible.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "services/code-index/embedders/openai.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "services/code-index/embedders/openrouter.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "services/code-index/interfaces/vector-store.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "services/code-index/orchestrator.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "services/code-index/processors/__tests__/file-watcher.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 25 + } + }, + "services/code-index/processors/__tests__/parser.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 22 + } + }, + "services/code-index/processors/__tests__/scanner.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 26 + } + }, + "services/code-index/processors/file-watcher.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "services/code-index/processors/scanner.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "services/code-index/semble/__tests__/provider.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 12 + } + }, + "services/code-index/semble/__tests__/semble-cli.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "services/code-index/semble/__tests__/semble-downloader.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 61 + } + }, + "services/code-index/semble/provider.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "services/code-index/semble/semble-cli.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "services/code-index/shared/__tests__/validation-helpers.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "services/code-index/shared/validation-helpers.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "services/code-index/vector-store/__tests__/qdrant-client.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 87 + } + }, + "services/code-index/vector-store/qdrant-client.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "services/glob/__tests__/gitignore-integration.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "services/glob/__tests__/gitignore-test.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "services/glob/__tests__/list-files-limit.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 6 + } + }, + "services/glob/__tests__/list-files.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 22 + } + }, + "services/marketplace/MarketplaceManager.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "services/marketplace/SimpleInstaller.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 7 + } + }, + "services/marketplace/__tests__/MarketplaceManager.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "services/marketplace/__tests__/SimpleInstaller.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 17 + } + }, + "services/marketplace/__tests__/marketplace-setting-check.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "services/mcp/McpHub.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 7 + } + }, + "services/mcp/McpOAuthClientProvider.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "services/mcp/McpServerManager.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "services/mcp/__tests__/McpHub.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 150 + } + }, + "services/mcp/__tests__/McpOAuthClientProvider.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 18 + } + }, + "services/mcp/__tests__/SecretStorageService.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "services/mcp/utils/__tests__/oauth.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 9 + } + }, + "services/mcp/utils/callbackServer.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "services/mcp/utils/oauth.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "services/mdm/__tests__/MdmService.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "services/ripgrep/__tests__/diagnostic.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "services/roo-config/__tests__/index.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 20 + } + }, + "services/roo-config/index.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "services/rules/__tests__/rules.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "services/search/__tests__/file-search.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 3 + } + }, + "services/skills/__tests__/SkillsManager.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "services/tree-sitter/__tests__/helpers.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 4 + } + }, + "services/tree-sitter/__tests__/markdownParser.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "shared/__tests__/api.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 8 + } + }, + "shared/__tests__/embeddingModels.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "shared/__tests__/modes-empty-prompt-component.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "shared/api.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "shared/checkExistApiConfig.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "shared/cost.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "shared/parse-command.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "shared/support-prompt.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 5 + } + }, + "shared/tools.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + }, + "shared/utils/__tests__/requesty.spec.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 2 + } + }, + "vitest.setup.ts": { + "@typescript-eslint/no-explicit-any": { + "count": 1 + } + } +} From 9819b5f92dbac5deee5aca5737b74f422cafe748 Mon Sep 17 00:00:00 2001 From: eason liang <136036952+easonLiangWorldedtech@users.noreply.github.com> Date: Wed, 4 Nov 2026 01:29:00 +0800 Subject: [PATCH 27/27] fix(webview): address #2237 review findings on per-view restore - ContextProxy: seed the persisted-value map in initialize so a failed write on a key that has never been written through this proxy rolls the cache back to the value storage actually holds instead of an overlapping write's pending value. - ClineProvider.loadViewState: keep the profile name and the settings it resolved to as one pair; a profile name this view changed while the lookup was in flight no longer inherits the loaded profile's configuration. - ClineProvider.getState: read this view's restored mode from the buffer - getState() is what task creation and getStateToPostToWebview read, so a restored mode has to be visible there. - ClineProvider.deleteProviderProfile: clear the settings overlay of every view re-pointed away from the deleted profile when the survivor's settings cannot be resolved, and rebuild the live task (in this view and in sibling views) that still names the deleted profile. - ClineProvider.setValues: roll a partially applied shared write back through the generation-guarded helper instead of replaying every captured value. Tests: 1 new ContextProxy case and 4 new ClineProvider cases, each red before its fix and green after it; 43 suites / 1188 tests pass under core/webview + core/config. --- src/core/config/ContextProxy.ts | 5 + .../config/__tests__/ContextProxy.spec.ts | 35 ++++ src/core/webview/ClineProvider.ts | 82 +++++--- .../webview/__tests__/ClineProvider.spec.ts | 198 +++++++++++++++++- 4 files changed, 290 insertions(+), 30 deletions(-) diff --git a/src/core/config/ContextProxy.ts b/src/core/config/ContextProxy.ts index 837b417b2a..dd85aab97a 100644 --- a/src/core/config/ContextProxy.ts +++ b/src/core/config/ContextProxy.ts @@ -69,6 +69,11 @@ export class ContextProxy { try { // Revert to original assignment this.stateCache[key] = this.originalContext.globalState.get(key) + // Storage is the baseline of the rollback path: without this entry, a failed write + // on a key that has never been written through this proxy falls back to the + // previous cached value - which an overlapping write may have made its own + // unpersisted one. + this.statePersistedCache.set(key, this.stateCache[key]) } catch (error) { logger.error(`Error loading global ${key}: ${error instanceof Error ? error.message : String(error)}`) } diff --git a/src/core/config/__tests__/ContextProxy.spec.ts b/src/core/config/__tests__/ContextProxy.spec.ts index 4050133a7f..1bdfddd249 100644 --- a/src/core/config/__tests__/ContextProxy.spec.ts +++ b/src/core/config/__tests__/ContextProxy.spec.ts @@ -189,6 +189,41 @@ describe("ContextProxy", () => { expect(proxy.getGlobalState("apiProvider")).toBe("anthropic") }) + it("should restore the loaded value when overlapping writes reject with no prior write", async () => { + // Cold start: storage holds the value but nothing has been written through this + // proxy yet, so the persisted-value map has no entry for the key. + mockGlobalState.get.mockImplementation((key: string) => (key === "apiProvider" ? "openai" : undefined)) + const coldProxy = new ContextProxy(mockContext) + await coldProxy.initialize() + expect(coldProxy.getGlobalState("apiProvider")).toBe("openai") + + mockGlobalState.update.mockReset() + let rejectFirst: (error: Error) => void = () => {} + let rejectSecond: (error: Error) => void = () => {} + mockGlobalState.update + .mockReturnValueOnce( + new Promise((_, reject) => { + rejectFirst = reject + }), + ) + .mockReturnValueOnce( + new Promise((_, reject) => { + rejectSecond = reject + }), + ) + + const firstWrite = coldProxy.updateGlobalState("apiProvider", "openrouter") + const secondWrite = coldProxy.updateGlobalState("apiProvider", "deepseek") + rejectSecond(new Error("second failed")) + await expect(secondWrite).rejects.toThrow("second failed") + rejectFirst(new Error("first failed")) + await expect(firstWrite).rejects.toThrow("first failed") + + // The second write's `previousCachedValue` is the first write's pending value, so the + // fallback branch would leave a value that storage never accepted. + expect(coldProxy.getGlobalState("apiProvider")).toBe("openai") + }) + it("should bypass cache for pass-through state keys", async () => { // Setup mock return value mockGlobalState.get.mockReturnValue("pass-through-value") diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index 386cecaa14..2cd08751c0 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -1067,6 +1067,19 @@ export class ClineProvider } } + // The profile name and the settings it resolved to are one pair: the configuration loaded + // above belongs to the profile the lookup asked for, so it must not stay parked under a + // name this view changed while the lookup was in flight. A name this view changed on its + // own pins nothing - reads fall back to the shared settings, exactly as every other + // name-only write behaves. + if ( + loadedState.apiConfiguration !== undefined && + Object.is(preLoadBuffer.apiConfiguration, postLoadBuffer.apiConfiguration) && + mergedState.currentApiConfigName !== loadedState.currentApiConfigName + ) { + delete mergedState.apiConfiguration + } + // A reset/import may have cleared the buffer while the lookup was in flight: // republishing here would restore the pre-reset selection over the cleared state. if (this.viewLocalStateGeneration !== loadedGeneration) { @@ -3069,18 +3082,33 @@ export class ClineProvider await this.contextProxy.setValue("currentApiConfigName", profileToActivate) } - if ((deletedWasGlobal || viewWasPinnedToDeleted) && survivingSettings) { - // The deleted profile was the active one (globally, or for this view), so - // the shared provider keys still carry its settings; replace them so - // getState() reports the surviving profile's configuration. - await this.contextProxy.setProviderSettings(survivingSettings) + if (deletedWasGlobal || viewWasPinnedToDeleted) { + if (survivingSettings) { + // The deleted profile was the active one (globally, or for this view), so + // the shared provider keys still carry its settings; replace them so + // getState() reports the surviving profile's configuration. + await this.contextProxy.setProviderSettings(survivingSettings) + + if (viewWasPinnedToDeleted) { + // This view's nested overlay (viewLocalState.apiConfiguration, seeded + // by loadViewState) still serves the deleted profile's configuration: + // replace it with the survivor's so the re-pointed pin serves matching + // settings. A view pinned to another profile keeps its own overlay. + await this._saveViewLocalStateFromMutation({ apiConfiguration: survivingSettings }) + } - if (viewWasPinnedToDeleted) { - // This view's nested overlay (viewLocalState.apiConfiguration, seeded - // by loadViewState) still serves the deleted profile's configuration: - // replace it with the survivor's so the re-pointed pin serves matching - // settings. A view pinned to another profile keeps its own overlay. - await this._saveViewLocalStateFromMutation({ apiConfiguration: survivingSettings }) + // A live task of this view that runs under the deleted profile keeps the handler + // built from its settings and the deleted sticky name until it is rebuilt - the same + // rule the activating-save branch applies. + if (this.getCurrentTask()?.taskApiConfigName === profileToDelete.name) { + this.updateTaskApiHandlerIfNeeded(survivingSettings, { forceRebuild: true }) + await this.persistStickyProviderProfileToCurrentTask(profileToActivate) + } + } else if (viewWasPinnedToDeleted) { + // The survivor's settings never resolved: this view's pin now names the survivor, so + // its overlay must stop serving the deleted profile's configuration and fall back to + // the shared settings instead. + await this._saveViewLocalStateFromMutation({ apiConfiguration: undefined }) } } @@ -3093,12 +3121,19 @@ export class ClineProvider } const values: Partial & Partial = { currentApiConfigName: profileToActivate, - } - if (survivingSettings) { - values.apiConfiguration = survivingSettings + // Either the survivor's settings or an explicit clear: a view re-pointed away from the + // deleted profile must not keep serving that profile's configuration. + apiConfiguration: survivingSettings, } // Direct private access: compile-time safe across sibling instances. await instance._saveViewLocalStateFromMutation(values) + // The re-pinned buffer alone does not reach a live task in that view: it still runs on a + // handler built from the deleted profile's settings and still names the deleted profile as + // its sticky profile. + if (survivingSettings && instance.getCurrentTask()?.taskApiConfigName === profileToDelete.name) { + instance.updateTaskApiHandlerIfNeeded(survivingSettings, { forceRebuild: true }) + await instance.persistStickyProviderProfileToCurrentTask(profileToActivate) + } await instance.postStateToWebview().catch((postError: unknown) => { this.log( `[deleteProviderProfile] failed to post re-pinned state to a sibling view: ${ @@ -4280,7 +4315,10 @@ export class ClineProvider terminalZshP10k: stateValues.terminalZshP10k ?? false, terminalZdotdir: stateValues.terminalZdotdir ?? false, terminalProfile: stateValues.terminalProfile, - mode: stateValues.mode ?? defaultModeSlug, + // A per-view restored or edited mode lives in this view's buffer, and getState() is + // what task creation and getStateToPostToWebview read: the shared store only carries the + // mode the last committing view chose. + mode: this.viewLocalState.mode ?? stateValues.mode ?? defaultModeSlug, language: stateValues.language ?? formatLanguage(vscode.env.language), mcpEnabled: stateValues.mcpEnabled ?? true, mcpServers: this.mcpHub?.getAllServers() ?? [], @@ -4475,16 +4513,10 @@ export class ClineProvider await this.contextProxy.setValues(sanitizedValues) } catch (error) { // A multi-key write can commit some keys before another rejects: put the captured - // previous values back so shared state does not stay half-applied. - try { - await this.contextProxy.setValues(previousSharedValues) - } catch (rollbackError) { - this.log( - `[ClineProvider#setValues] Failed to roll back a partially applied write: ${ - rollbackError instanceof Error ? rollbackError.message : String(rollbackError) - }`, - ) - } + // previous values back so shared state does not stay half-applied. Route through the + // same guarded restore the failed per-view write below uses - a key that a concurrent + // provider has since written must not be clobbered by this rollback. + await this._restoreSharedValuesAfterFailedViewWrite(previousSharedValues, sanitizedValues, writeGenerations) throw error } try { diff --git a/src/core/webview/__tests__/ClineProvider.spec.ts b/src/core/webview/__tests__/ClineProvider.spec.ts index 34daa79b6c..8b8bd5ab27 100644 --- a/src/core/webview/__tests__/ClineProvider.spec.ts +++ b/src/core/webview/__tests__/ClineProvider.spec.ts @@ -5237,6 +5237,137 @@ describe("ClineProvider", () => { await provider.dispose() }) + + it("clears the settings overlay of a view re-pinned when the survivor's settings cannot be resolved", async () => { + const contextProxy = new ContextProxy(mockContext) + const deleter = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + contextProxy, + new WebviewFocusTracker(), + ) + const pinned = new ClineProvider( + mockContext, + mockOutputChannel, + "editor", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + const profileToDelete: ProviderSettingsEntry = { name: "deleted", id: "deleted-id" } + const deletedSettings = { apiProvider: providerIdentifiers.openrouter, openRouterModelId: "deleted-model" } + + await contextProxy.setValue("listApiConfigMeta", [ + { name: "deleted", id: "deleted-id" }, + { name: "survivor", id: "survivor-id" }, + ]) + await contextProxy.setValue("currentApiConfigName", "deleted") + await contextProxy.setProviderSettings(deletedSettings) + + for (const view of [deleter, pinned]) { + await view.saveViewState("currentApiConfigName", "deleted") + // The buffer a completed loadViewState leaves behind: this view serves the deleted + // profile's configuration. + await view["_saveViewLocalStateFromMutation"]({ apiConfiguration: deletedSettings }) + } + + vi.spyOn(deleter["providerSettingsManager"], "deleteConfig").mockResolvedValue(undefined) + vi.spyOn(deleter["providerSettingsManager"], "activateProfile").mockResolvedValue({ + name: "survivor", + id: "survivor-id", + apiProvider: providerIdentifiers.anthropic, + }) + vi.spyOn(deleter["providerSettingsManager"], "getProfile").mockRejectedValue( + new Error("profile store unavailable"), + ) + + await deleter.deleteProviderProfile(profileToDelete) + + // Both views are re-pointed at the survivor, so neither may keep serving the deleted + // profile's configuration under the survivor's name. + expect(deleter["viewLocalState"].currentApiConfigName).toBe("survivor") + expect(deleter["viewLocalState"]).not.toHaveProperty("apiConfiguration") + expect(pinned["viewLocalState"].currentApiConfigName).toBe("survivor") + expect(pinned["viewLocalState"]).not.toHaveProperty("apiConfiguration") + + await deleter.dispose() + await pinned.dispose() + }) + + it("rebuilds a live task that still runs on the deleted profile, in this view and in a sibling view", async () => { + const contextProxy = new ContextProxy(mockContext) + const deleter = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + contextProxy, + new WebviewFocusTracker(), + ) + const sibling = new ClineProvider( + mockContext, + mockOutputChannel, + "editor", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + const profileToDelete: ProviderSettingsEntry = { name: "deleted", id: "deleted-id" } + const survivingSettings = { apiProvider: providerIdentifiers.anthropic, apiKey: "survivor-key" } + + await contextProxy.setValue("listApiConfigMeta", [ + { name: "deleted", id: "deleted-id" }, + { name: "survivor", id: "survivor-id" }, + ]) + await contextProxy.setValue("currentApiConfigName", "deleted") + + const views = [deleter, sibling] + const tasks = views.map((view) => { + // The double only backs the calls the delete path makes on a live task. + const task = new Task(defaultTaskOptions) + Object.defineProperty(task, "taskId", { value: `task-of-${view.viewId}`, writable: true }) + Object.defineProperty(task, "taskApiConfigName", { value: "deleted", writable: true }) + Object.defineProperty(task, "apiConfiguration", { + value: { apiProvider: providerIdentifiers.openrouter, openRouterModelId: "deleted-model" }, + writable: true, + }) + task.setTaskApiConfigName = vi.fn() + task.updateApiConfiguration = vi.fn() + return task + }) + + for (const [index, view] of views.entries()) { + await view.saveViewState("currentApiConfigName", "deleted") + await view.addClineToStack(tasks[index]) + } + + vi.spyOn(deleter["providerSettingsManager"], "deleteConfig").mockResolvedValue(undefined) + vi.spyOn(deleter["providerSettingsManager"], "activateProfile").mockResolvedValue({ + name: "survivor", + id: "survivor-id", + apiProvider: providerIdentifiers.anthropic, + }) + vi.spyOn(deleter["providerSettingsManager"], "getProfile").mockResolvedValue({ + name: "survivor", + id: "survivor-id", + ...survivingSettings, + }) + + await deleter.deleteProviderProfile(profileToDelete) + + // Re-pointing the view is not enough: a task that still names the deleted profile runs on a + // handler built from its settings and keeps it as its sticky profile until it is rebuilt. + for (const task of tasks) { + expect(task.updateApiConfiguration).toHaveBeenCalledWith( + expect.objectContaining({ + apiProvider: providerIdentifiers.anthropic, + apiKey: "survivor-key", + }), + ) + expect(task.setTaskApiConfigName).toHaveBeenCalledWith("survivor") + } + + await deleter.dispose() + await sibling.dispose() + }) }) describe("updateCustomMode", () => { @@ -6613,6 +6744,64 @@ describe("ClineProvider", () => { await provider.dispose() }) + it("should not roll back a shared key that a newer write replaced during a partial setValues", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + await provider.contextProxy.setValue("mode", "architect") + await provider.contextProxy.setValue("currentApiConfigName", "current-config") + const originalUpdate = mockContext.globalState.update + let rejectConfig: (error: Error) => void = () => {} + mockContext.globalState.update = vi.fn().mockImplementation((key: string) => { + if (key === "currentApiConfigName") { + return new Promise((_, reject) => (rejectConfig = reject)) + } + return Promise.resolve() + }) + + // The mode write commits while the profile-name write is still in flight. + const attempt = provider.setValues({ mode: "code", currentApiConfigName: "other-config" }) + await vi.waitFor(() => expect(provider.getValue("mode")).toBe("code")) + // A newer write for the already committed key lands before the rollback runs. + await provider.setValue("mode", "plan") + rejectConfig(new Error("storage unavailable")) + await expect(attempt).rejects.toThrow("storage unavailable") + + // A rollback may only undo keys that still hold the value this attempt wrote; replaying + // every captured value would clobber the newer write for every view that reads shared state. + expect(provider.getValue("mode")).toBe("plan") + expect(provider.getValue("currentApiConfigName")).toBe("current-config") + + mockContext.globalState.update = originalUpdate + await provider.dispose() + }) + + it("should serve this view's restored mode through getState()", async () => { + const provider = new ClineProvider( + mockContext, + mockOutputChannel, + "sidebar", + new ContextProxy(mockContext), + new WebviewFocusTracker(), + ) + await provider.contextProxy.setValue("mode", "architect") + await provider["setViewStateId"]("mode-view") + // A history or profile restore writes the mode into this view's buffer only; the shared store + // keeps the mode the last committing view chose. + await provider.saveViewState("mode", "code") + + expect(provider.getValue("mode")).toBe("architect") + // getState() is what task creation and getStateToPostToWebview read, so the restored mode has + // to be visible there and not only through getValues(). + expect((await provider.getState()).mode).toBe("code") + + await provider.dispose() + }) + describe("viewId uniqueness", () => { it("should assign unique viewId to each instance", async () => { const provider1 = new ClineProvider( @@ -6731,12 +6920,11 @@ describe("ClineProvider", () => { resolveProfile({ name: "cfg-a", apiProvider: providerIdentifiers.openrouter, openRouterModelId: "model-x" }) await load - // The in-flight selection wins over the loaded state. + // The in-flight selection wins over the loaded state, and cfg-a's settings are not parked + // under cfg-b's name: a name this view changed on its own pins no settings, so reads fall back + // to the shared store until an activation resolves cfg-b together with its configuration. expect(provider["viewLocalState"].currentApiConfigName).toBe("cfg-b") - expect(provider["viewLocalState"].apiConfiguration).toEqual({ - apiProvider: providerIdentifiers.openrouter, - openRouterModelId: "model-x", - }) + expect(provider["viewLocalState"]).not.toHaveProperty("apiConfiguration") expect(provider["viewLocalState"]).not.toHaveProperty("mode") await provider.dispose() })