global-settings.ts 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. import { z } from "zod"
  2. import { type Keys } from "./type-fu.js"
  3. import {
  4. type ProviderSettings,
  5. PROVIDER_SETTINGS_KEYS,
  6. providerSettingsEntrySchema,
  7. providerSettingsSchema,
  8. } from "./provider-settings.js"
  9. import { historyItemSchema } from "./history.js"
  10. import { codebaseIndexModelsSchema, codebaseIndexConfigSchema } from "./codebase-index.js"
  11. import { experimentsSchema } from "./experiment.js"
  12. import { telemetrySettingsSchema } from "./telemetry.js"
  13. import { modeConfigSchema } from "./mode.js"
  14. import { customModePromptsSchema, customSupportPromptsSchema } from "./mode.js"
  15. import { languagesSchema } from "./vscode.js"
  16. /**
  17. * GlobalSettings
  18. */
  19. export const globalSettingsSchema = z.object({
  20. currentApiConfigName: z.string().optional(),
  21. listApiConfigMeta: z.array(providerSettingsEntrySchema).optional(),
  22. pinnedApiConfigs: z.record(z.string(), z.boolean()).optional(),
  23. lastShownAnnouncementId: z.string().optional(),
  24. customInstructions: z.string().optional(),
  25. taskHistory: z.array(historyItemSchema).optional(),
  26. condensingApiConfigId: z.string().optional(),
  27. customCondensingPrompt: z.string().optional(),
  28. autoApprovalEnabled: z.boolean().optional(),
  29. alwaysAllowReadOnly: z.boolean().optional(),
  30. alwaysAllowReadOnlyOutsideWorkspace: z.boolean().optional(),
  31. alwaysAllowWrite: z.boolean().optional(),
  32. alwaysAllowWriteOutsideWorkspace: z.boolean().optional(),
  33. alwaysAllowWriteProtected: z.boolean().optional(),
  34. writeDelayMs: z.number().optional(),
  35. alwaysAllowBrowser: z.boolean().optional(),
  36. alwaysApproveResubmit: z.boolean().optional(),
  37. requestDelaySeconds: z.number().optional(),
  38. alwaysAllowMcp: z.boolean().optional(),
  39. alwaysAllowModeSwitch: z.boolean().optional(),
  40. alwaysAllowSubtasks: z.boolean().optional(),
  41. alwaysAllowExecute: z.boolean().optional(),
  42. allowedCommands: z.array(z.string()).optional(),
  43. allowedMaxRequests: z.number().nullish(),
  44. autoCondenseContext: z.boolean().optional(),
  45. autoCondenseContextPercent: z.number().optional(),
  46. maxConcurrentFileReads: z.number().optional(),
  47. browserToolEnabled: z.boolean().optional(),
  48. browserViewportSize: z.string().optional(),
  49. screenshotQuality: z.number().optional(),
  50. remoteBrowserEnabled: z.boolean().optional(),
  51. remoteBrowserHost: z.string().optional(),
  52. cachedChromeHostUrl: z.string().optional(),
  53. enableCheckpoints: z.boolean().optional(),
  54. ttsEnabled: z.boolean().optional(),
  55. ttsSpeed: z.number().optional(),
  56. soundEnabled: z.boolean().optional(),
  57. soundVolume: z.number().optional(),
  58. maxOpenTabsContext: z.number().optional(),
  59. maxWorkspaceFiles: z.number().optional(),
  60. showRooIgnoredFiles: z.boolean().optional(),
  61. maxReadFileLine: z.number().optional(),
  62. terminalOutputLineLimit: z.number().optional(),
  63. terminalShellIntegrationTimeout: z.number().optional(),
  64. terminalShellIntegrationDisabled: z.boolean().optional(),
  65. terminalCommandDelay: z.number().optional(),
  66. terminalPowershellCounter: z.boolean().optional(),
  67. terminalZshClearEolMark: z.boolean().optional(),
  68. terminalZshOhMy: z.boolean().optional(),
  69. terminalZshP10k: z.boolean().optional(),
  70. terminalZdotdir: z.boolean().optional(),
  71. terminalCompressProgressBar: z.boolean().optional(),
  72. rateLimitSeconds: z.number().optional(),
  73. diffEnabled: z.boolean().optional(),
  74. fuzzyMatchThreshold: z.number().optional(),
  75. experiments: experimentsSchema.optional(),
  76. codebaseIndexModels: codebaseIndexModelsSchema.optional(),
  77. codebaseIndexConfig: codebaseIndexConfigSchema.optional(),
  78. language: languagesSchema.optional(),
  79. telemetrySetting: telemetrySettingsSchema.optional(),
  80. mcpEnabled: z.boolean().optional(),
  81. enableMcpServerCreation: z.boolean().optional(),
  82. mode: z.string().optional(),
  83. modeApiConfigs: z.record(z.string(), z.string()).optional(),
  84. customModes: z.array(modeConfigSchema).optional(),
  85. customModePrompts: customModePromptsSchema.optional(),
  86. customSupportPrompts: customSupportPromptsSchema.optional(),
  87. enhancementApiConfigId: z.string().optional(),
  88. historyPreviewCollapsed: z.boolean().optional(),
  89. })
  90. export type GlobalSettings = z.infer<typeof globalSettingsSchema>
  91. export const GLOBAL_SETTINGS_KEYS = globalSettingsSchema.keyof().options
  92. /**
  93. * RooCodeSettings
  94. */
  95. export const rooCodeSettingsSchema = providerSettingsSchema.merge(globalSettingsSchema)
  96. export type RooCodeSettings = GlobalSettings & ProviderSettings
  97. /**
  98. * SecretState
  99. */
  100. export const SECRET_STATE_KEYS = [
  101. "apiKey",
  102. "glamaApiKey",
  103. "openRouterApiKey",
  104. "awsAccessKey",
  105. "awsSecretKey",
  106. "awsSessionToken",
  107. "openAiApiKey",
  108. "geminiApiKey",
  109. "openAiNativeApiKey",
  110. "deepSeekApiKey",
  111. "mistralApiKey",
  112. "unboundApiKey",
  113. "requestyApiKey",
  114. "xaiApiKey",
  115. "groqApiKey",
  116. "chutesApiKey",
  117. "litellmApiKey",
  118. "codeIndexOpenAiKey",
  119. "codeIndexQdrantApiKey",
  120. "codebaseIndexOpenAiCompatibleApiKey",
  121. ] as const satisfies readonly (keyof ProviderSettings)[]
  122. export type SecretState = Pick<ProviderSettings, (typeof SECRET_STATE_KEYS)[number]>
  123. export const isSecretStateKey = (key: string): key is Keys<SecretState> =>
  124. SECRET_STATE_KEYS.includes(key as Keys<SecretState>)
  125. /**
  126. * GlobalState
  127. */
  128. export type GlobalState = Omit<RooCodeSettings, Keys<SecretState>>
  129. export const GLOBAL_STATE_KEYS = [...GLOBAL_SETTINGS_KEYS, ...PROVIDER_SETTINGS_KEYS].filter(
  130. (key: Keys<RooCodeSettings>) => !SECRET_STATE_KEYS.includes(key as Keys<SecretState>),
  131. ) as Keys<GlobalState>[]
  132. export const isGlobalStateKey = (key: string): key is Keys<GlobalState> =>
  133. GLOBAL_STATE_KEYS.includes(key as Keys<GlobalState>)
  134. /**
  135. * Evals
  136. */
  137. // Default settings when running evals (unless overridden).
  138. export const EVALS_SETTINGS: RooCodeSettings = {
  139. apiProvider: "openrouter",
  140. openRouterUseMiddleOutTransform: false,
  141. lastShownAnnouncementId: "may-29-2025-3-19",
  142. pinnedApiConfigs: {},
  143. autoApprovalEnabled: true,
  144. alwaysAllowReadOnly: true,
  145. alwaysAllowReadOnlyOutsideWorkspace: false,
  146. alwaysAllowWrite: true,
  147. alwaysAllowWriteOutsideWorkspace: false,
  148. alwaysAllowWriteProtected: false,
  149. writeDelayMs: 1000,
  150. alwaysAllowBrowser: true,
  151. alwaysApproveResubmit: true,
  152. requestDelaySeconds: 10,
  153. alwaysAllowMcp: true,
  154. alwaysAllowModeSwitch: true,
  155. alwaysAllowSubtasks: true,
  156. alwaysAllowExecute: true,
  157. allowedCommands: ["*"],
  158. browserToolEnabled: false,
  159. browserViewportSize: "900x600",
  160. screenshotQuality: 75,
  161. remoteBrowserEnabled: false,
  162. ttsEnabled: false,
  163. ttsSpeed: 1,
  164. soundEnabled: false,
  165. soundVolume: 0.5,
  166. terminalOutputLineLimit: 500,
  167. terminalShellIntegrationTimeout: 30000,
  168. terminalCommandDelay: 0,
  169. terminalPowershellCounter: false,
  170. terminalZshOhMy: true,
  171. terminalZshClearEolMark: true,
  172. terminalZshP10k: false,
  173. terminalZdotdir: true,
  174. terminalCompressProgressBar: true,
  175. terminalShellIntegrationDisabled: true,
  176. diffEnabled: true,
  177. fuzzyMatchThreshold: 1,
  178. enableCheckpoints: false,
  179. rateLimitSeconds: 0,
  180. maxOpenTabsContext: 20,
  181. maxWorkspaceFiles: 200,
  182. showRooIgnoredFiles: true,
  183. maxReadFileLine: -1, // -1 to enable full file reading.
  184. language: "en",
  185. telemetrySetting: "enabled",
  186. mcpEnabled: false,
  187. mode: "code",
  188. customModes: [],
  189. }
  190. export const EVALS_TIMEOUT = 5 * 60 * 1_000