Skip to content

Conversation

@cte
Copy link
Collaborator

@cte cte commented Mar 26, 2025

Context

  • Move all settings-related types to roo-code.d.ts.
  • Strongly type our global settings (only the ApiConfiguration was strongly typed previously).
  • Disambiguate between "provider" settings and "global" settings (now called ProviderSettings and GlobalSettings). Provider settings are specific to a given API provider profile and change when you select a different profile. Global settings apply irrespective of your current profile.
  • Add zod schemas for all settings-related types. See this note for context.
  • Use the zod schemas to implement settings import and export.

Possible TODOs:

  • Add support for importing and exporting all provider profiles and not just the current one.
  • Add a version number to the settings schemas so that we can support importing old versions of the schema.
  • Would it make more sense to generate roo-code.d.ts and make the zod schemas the source of truth? I think that would significantly reduce the amount of typing boilerplate.

Implementation

How to Test

Get in Touch


Important

Refactor settings management by introducing ProviderSettings and GlobalSettings, adding import/export functionality, and updating related tests and UI components.

  • Settings Management:
    • Move all settings-related types to roo-code.d.ts.
    • Introduce ProviderSettings and GlobalSettings to differentiate between provider-specific and global settings.
    • Add zod schemas for settings types in globalState.ts.
    • Implement settings import/export in importExport.ts.
  • Code Refactoring:
    • Replace ConfigManager with ProviderSettingsManager in ClineProvider.ts.
    • Use ContextProxy for managing global and secret state.
  • Tests:
    • Update tests in ContextProxy.test.ts and ProviderSettingsManager.test.ts to reflect new settings management.
    • Add importExport.test.ts for testing import/export functionality.
  • UI and i18n:
    • Add import/export buttons in About.tsx.
    • Update i18n files for new settings-related strings.

This description was created by Ellipsis for 316bfce. It will automatically update as commits are pushed.

@changeset-bot
Copy link

changeset-bot bot commented Mar 26, 2025

🦋 Changeset detected

Latest commit: 316bfce

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
roo-cline Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. enhancement New feature or request labels Mar 26, 2025
@ellipsis-dev
Copy link
Contributor

ellipsis-dev bot commented Mar 26, 2025

This pull request is quite large, with 26 changed files, 1622 lines added, and 769 lines removed. It includes various refactors, feature additions, and test updates across multiple files and modules. To make it easier to review and manage, consider splitting the changes into smaller, more focused pull requests. For example, you could separate the feature additions related to settings import/export from the refactoring of type definitions and state management. This would help reviewers focus on specific areas and ensure thorough review of each part.

awsRegion: true,
awsUseCrossRegionInference: true,
awsUsePromptCache: true,
awspromptCacheId: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key awspromptCacheId appears to have inconsistent camel casing compared to other AWS keys (e.g., awsAccessKey). Consider renaming it to awsPromptCacheId for consistency.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes; unfortunate that we named it like this. We need a playbook for settings migrations.

cte and others added 4 commits March 26, 2025 00:25
Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>

export type Values<T> = T[keyof T]

export type Equals<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false
Copy link
Collaborator Author

@cte cte Mar 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Equals utility type is doing a lot of heavy lifting in this PR to ensure that our zod schemas match the roo-code.d.ts type definitions. Ideally we'd infer the types from the schema and nicely DRY things up, but the type definition file can only have type declarations in it.

}

export interface ExtensionState {
export type ExtensionState = Pick<
Copy link
Collaborator Author

@cte cte Mar 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ExtensionState can mostly be generate by Picking from GlobalSettings (this is better since it ensures that all the types match between the two), but there are some annoying differences that we can eventually clean up and make this look tidy.

const providerNamesEnum: [ProviderName, ...ProviderName[]] = [
PROVIDER_NAMES[0],
...PROVIDER_NAMES.slice(1).map((p) => p),
]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll see this technique employed in a few places. This a trick that allows you to convert a typescript string union type to an array that can be passed to zod.enum. I've named all of these to reflect this.

modes: true,
}

const TOOL_GROUPS = Object.keys(toolGroups) as ToolGroup[]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pattern converting Object.keys(...) to a tuple (used for z.enum) is repeated (also seen with languages and telemetry settings). Consider extracting this logic into a reusable helper function to reduce duplication and improve maintainability.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ellipsis-dev Can you respond to this comment with a quick example of how you might do that in a strongly-typed and fully type-safe way?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a quick example of converting Object.keys to a tuple for z.enum in a strongly-typed and type-safe way:

const myEnumValues = {
  value1: true,
  value2: true,
  value3: true,
};

const MY_ENUM = Object.keys(myEnumValues) as (keyof typeof myEnumValues)[];

const myEnumSchema = z.enum(MY_ENUM);

This approach ensures that the keys are strongly typed and can be used safely with z.enum. Let me know if you need further clarification!

Copy link
Collaborator Author

@cte cte Mar 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ellipsis-dev This isn't exactly what you mentioned; you said this can be done with a reusable helper. Where's the helper?

const uri = await vscode.window.showSaveDialog({
filters: { JSON: ["json"] },
defaultUri: vscode.Uri.file(
path.join(os.homedir(), "Documents", `roo-code-${message.text}.json`),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this default make sense in all OSes? What happens if we don't set a default?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't set a default then it defaults to the last directory you saved something to (if any), and the named is "Untitled.json".

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Mar 26, 2025
"custom_storage_path_set": "自定義存儲路徑已設置:{{path}}",
"default_storage_path": "已恢復使用默認存儲路徑"
"default_storage_path": "已恢復使用默認存儲路徑",
"settings_imported": "設置已成功導入。"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newly added translation for settings_imported ends with a Chinese full stop (。) which is inconsistent with similar entries in this file (e.g., default_storage_path does not end with punctuation). Consider making the punctuation consistent across these messages.

Suggested change
"settings_imported": "設置已成功導入"
"settings_imported": "設置已成功導入"

@cte cte merged commit a414c7d into main Mar 26, 2025
10 checks passed
@cte cte deleted the cte/wrangle-settings branch March 26, 2025 23:29
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Mar 26, 2025
alasano added a commit to alasano/Roo-Code that referenced this pull request Apr 30, 2025
…iles

- Backfill `modeApiConfigs` on initialize if absent, seeding with the current profile
- Ensure `setModeConfig()` always mutates and persists the real modeApiConfigs map
- Addresses regression introduced in PR RooCodeInc#1997
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants