experiments.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. export const EXPERIMENT_IDS = {
  2. DIFF_STRATEGY: "experimentalDiffStrategy",
  3. SEARCH_AND_REPLACE: "search_and_replace",
  4. INSERT_BLOCK: "insert_content",
  5. POWER_STEERING: "powerSteering",
  6. } as const
  7. export type ExperimentKey = keyof typeof EXPERIMENT_IDS
  8. export type ExperimentId = valueof<typeof EXPERIMENT_IDS>
  9. export interface ExperimentConfig {
  10. name: string
  11. description: string
  12. enabled: boolean
  13. }
  14. type valueof<X> = X[keyof X]
  15. export const experimentConfigsMap: Record<ExperimentKey, ExperimentConfig> = {
  16. DIFF_STRATEGY: {
  17. name: "Use experimental unified diff strategy",
  18. description:
  19. "Enable the experimental unified diff strategy. This strategy might reduce the number of retries caused by model errors but may cause unexpected behavior or incorrect edits. Only enable if you understand the risks and are willing to carefully review all changes.",
  20. enabled: false,
  21. },
  22. SEARCH_AND_REPLACE: {
  23. name: "Use experimental search and replace tool",
  24. description:
  25. "Enable the experimental search and replace tool, allowing Roo to replace multiple instances of a search term in one request.",
  26. enabled: false,
  27. },
  28. INSERT_BLOCK: {
  29. name: "Use experimental insert content tool",
  30. description:
  31. "Enable the experimental insert content tool, allowing Roo to insert content at specific line numbers without needing to create a diff.",
  32. enabled: false,
  33. },
  34. POWER_STEERING: {
  35. name: 'Use experimental "power steering" mode',
  36. description:
  37. "When enabled, Roo will remind the model about the details of its current mode definition more frequently. This will lead to stronger adherence to role definitions and custom instructions, but will use additional tokens.",
  38. enabled: false,
  39. },
  40. }
  41. export const experimentDefault = Object.fromEntries(
  42. Object.entries(experimentConfigsMap).map(([_, config]) => [
  43. EXPERIMENT_IDS[_ as keyof typeof EXPERIMENT_IDS] as ExperimentId,
  44. config.enabled,
  45. ]),
  46. ) as Record<ExperimentId, boolean>
  47. export const experiments = {
  48. get: (id: ExperimentKey): ExperimentConfig | undefined => {
  49. return experimentConfigsMap[id]
  50. },
  51. isEnabled: (experimentsConfig: Record<ExperimentId, boolean>, id: ExperimentId): boolean => {
  52. return experimentsConfig[id] ?? experimentDefault[id]
  53. },
  54. } as const
  55. // Expose experiment details for UI - pre-compute from map for better performance
  56. export const experimentLabels = Object.fromEntries(
  57. Object.entries(experimentConfigsMap).map(([_, config]) => [
  58. EXPERIMENT_IDS[_ as keyof typeof EXPERIMENT_IDS] as ExperimentId,
  59. config.name,
  60. ]),
  61. ) as Record<string, string>
  62. export const experimentDescriptions = Object.fromEntries(
  63. Object.entries(experimentConfigsMap).map(([_, config]) => [
  64. EXPERIMENT_IDS[_ as keyof typeof EXPERIMENT_IDS] as ExperimentId,
  65. config.description,
  66. ]),
  67. ) as Record<string, string>