Roo-Code/src/core/diff/DiffStrategy.ts
Chris Estreich 2303f67afb
Clean up the way we compute the current diff strategy (#2049)
* Clean up the way we compute the current diff strategy

* Add changeset
2025-03-30 02:08:37 -04:00

28 lines
1.2 KiB
TypeScript

import type { DiffStrategy } from "./types"
import { SearchReplaceDiffStrategy } from "./strategies/search-replace"
import { NewUnifiedDiffStrategy } from "./strategies/new-unified"
import { MultiSearchReplaceDiffStrategy } from "./strategies/multi-search-replace"
import { EXPERIMENT_IDS, ExperimentId } from "../../shared/experiments"
export type { DiffStrategy }
/**
* Get the appropriate diff strategy for the given model
* @param model The name of the model being used (e.g., 'gpt-4', 'claude-3-opus')
* @returns The appropriate diff strategy for the model
*/
export type DiffStrategyName = "unified" | "multi-search-and-replace" | "search-and-replace"
type GetDiffStrategyOptions = {
model: string
experiments: Partial<Record<ExperimentId, boolean>>
fuzzyMatchThreshold?: number
}
export const getDiffStrategy = ({ fuzzyMatchThreshold, experiments }: GetDiffStrategyOptions): DiffStrategy =>
experiments[EXPERIMENT_IDS.DIFF_STRATEGY_UNIFIED]
? new NewUnifiedDiffStrategy(fuzzyMatchThreshold)
: experiments[EXPERIMENT_IDS.DIFF_STRATEGY_MULTI_SEARCH_AND_REPLACE]
? new MultiSearchReplaceDiffStrategy(fuzzyMatchThreshold)
: new SearchReplaceDiffStrategy(fuzzyMatchThreshold)