refactor(experiments): improve type safety for experiment configuration

Change ExperimentId type to be value-based rather than key-based
Make experiment record types more strict with proper typing
Pass full experiment config object instead of single boolean flag
Update type definitions and usages across codebase
This commit is contained in:
sam hoang
2025-01-27 14:59:52 +07:00
parent bb84d79af1
commit 3ed8540eba
6 changed files with 28 additions and 24 deletions

View File

@@ -61,7 +61,7 @@ import { OpenRouterHandler } from "../api/providers/openrouter"
import { McpHub } from "../services/mcp/McpHub"
import crypto from "crypto"
import { insertGroups } from "./diff/insert-groups"
import { EXPERIMENT_IDS } from "../shared/experiments"
import { EXPERIMENT_IDS, experiments as Experiments } from "../shared/experiments"
const cwd =
vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0) ?? path.join(os.homedir(), "Desktop") // may or may not exist but fs checking existence would immediately ask for permission which would be bad UX, need to come up with a better solution
@@ -117,7 +117,7 @@ export class Cline {
task?: string | undefined,
images?: string[] | undefined,
historyItem?: HistoryItem | undefined,
experimentalDiffStrategy: boolean = false,
experiments?: Record<string, boolean>,
) {
if (!task && !images && !historyItem) {
throw new Error("Either historyItem or task/images must be provided")
@@ -139,7 +139,7 @@ export class Cline {
}
// Initialize diffStrategy based on current state
this.updateDiffStrategy(experimentalDiffStrategy)
this.updateDiffStrategy(Experiments.isEnabled(experiments ?? {}, EXPERIMENT_IDS.DIFF_STRATEGY))
if (task || images) {
this.startTask(task, images)