Duplicate Code Opportunity
Summary
- Pattern:
getCopilotModel() is a near-exact duplicate of the more general getConfigEnvValue() defined four lines below it in the same file
- Locations:
src/services/api-proxy-service.ts lines 39–61
- Impact: Two functions doing the same env-precedence lookup logic (
additionalEnv ?? envFile ?? process.env); any future change to the lookup priority must be applied to both
Evidence
getCopilotModel (lines 39–49):
function getCopilotModel(config: WrapperConfig): string | undefined {
const envFileModel = config.envFile
? readEnvFile(config.envFile).COPILOT_MODEL
: undefined;
const model =
config.additionalEnv?.COPILOT_MODEL ??
envFileModel ??
(config.envAll ? process.env.COPILOT_MODEL : undefined);
const normalizedModel = model?.trim();
return normalizedModel || undefined;
}
getConfigEnvValue (lines 51–61):
function getConfigEnvValue(config: WrapperConfig, key: string): string | undefined {
const envFileValue = config.envFile
? readEnvFile(config.envFile)[key]
: undefined;
const value =
config.additionalEnv?.[key] ??
envFileValue ??
(config.envAll ? process.env[key] : undefined);
const normalizedValue = value?.trim();
return normalizedValue || undefined;
}
getCopilotModel is exactly getConfigEnvValue(config, 'COPILOT_MODEL').
Suggested Refactoring
Remove getCopilotModel and replace its single call site (line 297) with:
const copilotModel = getConfigEnvValue(config, 'COPILOT_MODEL');
This is a one-line change plus deleting the 10-line function. The getConfigEnvValue name already communicates the intent clearly.
If the specialised name is valued for readability, keep it as a one-liner wrapper:
const getCopilotModel = (config: WrapperConfig) => getConfigEnvValue(config, 'COPILOT_MODEL');
Affected Files
src/services/api-proxy-service.ts — lines 39–49 (function to remove), line 297 (call site to update)
Effort Estimate
Low — one-line fix; the function has a single call site.
Detected by Duplicate Code Detector workflow. Run date: 2026-05-17
Generated by Duplicate Code Detector · ● 8M · ◷
Duplicate Code Opportunity
Summary
getCopilotModel()is a near-exact duplicate of the more generalgetConfigEnvValue()defined four lines below it in the same filesrc/services/api-proxy-service.tslines 39–61additionalEnv ?? envFile ?? process.env); any future change to the lookup priority must be applied to bothEvidence
getCopilotModel(lines 39–49):getConfigEnvValue(lines 51–61):getCopilotModelis exactlygetConfigEnvValue(config, 'COPILOT_MODEL').Suggested Refactoring
Remove
getCopilotModeland replace its single call site (line 297) with:This is a one-line change plus deleting the 10-line function. The
getConfigEnvValuename already communicates the intent clearly.If the specialised name is valued for readability, keep it as a one-liner wrapper:
Affected Files
src/services/api-proxy-service.ts— lines 39–49 (function to remove), line 297 (call site to update)Effort Estimate
Low — one-line fix; the function has a single call site.
Detected by Duplicate Code Detector workflow. Run date: 2026-05-17