Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 83 additions & 1 deletion packages/types/src/__tests__/global-settings.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions packages/types/src/global-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ 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(),
})

/**
* GlobalSettings
*/
Expand All @@ -125,6 +134,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(),
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/vscode-extension-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ export interface WebviewMessage {
| "themeFixtureProbeResponse"
| "diagnosticsResponse"
text?: string
viewStateId?: string
taskId?: string
editedMessageContent?: string
tab?: "settings" | "history" | "mcp" | "modes" | "chat" | "marketplace" | "cloud"
Expand Down
3 changes: 3 additions & 0 deletions src/core/config/ContextProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,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,
Comment thread
easonLiangWorldedtech marked this conversation as resolved.
Resolved
})

export class ContextProxy {
Expand Down
45 changes: 42 additions & 3 deletions src/core/config/ProviderSettingsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ export const providerProfilesSchema = z.object({

export type ProviderProfiles = z.infer<typeof providerProfilesSchema>

/**
* 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()
Expand Down Expand Up @@ -459,7 +472,7 @@ export class ProviderSettingsManager {
name = params.name

if (!providerProfiles.apiConfigs[name]) {
throw new Error(`Config with name '${name}' not found`)
throw new ProviderSettingsNotFoundError(`Config with name '${name}' not found`)
}

providerSettings = providerProfiles.apiConfigs[name]
Expand All @@ -471,7 +484,7 @@ export class ProviderSettingsManager {
)

if (!entry) {
throw new Error(`Config with ID '${id}' not found`)
throw new ProviderSettingsNotFoundError(`Config with ID '${id}' not found`)
}

name = entry[0]
Expand All @@ -481,10 +494,31 @@ export class ProviderSettingsManager {
return { name, ...providerSettings }
})
} catch (error) {
// Keep the typed not-found signal: callers branch on it to treat an already
// deleted profile as an idempotent no-op instead of matching message text.
if (error instanceof ProviderSettingsNotFoundError) {
throw error
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
throw new Error(`Failed to get profile: ${error instanceof Error ? error.message : error}`)
}
}

/**
* Read the manager-owned current profile selection. Exposed for callers that
* snapshot the full activation state before a mutation group so a failure can
* compensate the manager store as well as its ContextProxy copies.
*/
public async getCurrentProfileName(): Promise<string | undefined> {
try {
return await this.lock(async () => {
const providerProfiles = await this.load()
return providerProfiles.currentApiConfigName
})
} catch (error) {
throw new Error(`Failed to read the active profile: ${error instanceof Error ? error.message : error}`)
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

/**
* Activate a profile by name or ID.
*/
Expand Down Expand Up @@ -514,7 +548,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) {
Expand All @@ -525,6 +559,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}`)
}
}
Expand Down
27 changes: 27 additions & 0 deletions src/core/config/__tests__/ContextProxy.spec.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

109 changes: 108 additions & 1 deletion src/core/config/__tests__/ProviderSettingsManager.spec.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading