fix(config): avoid conflicting typo and migration guidance

This commit is contained in:
edxeth
2026-02-26 21:28:00 +01:00
parent a5749a1392
commit 818fdc490c
2 changed files with 40 additions and 2 deletions

View File

@@ -370,4 +370,30 @@ describe("detectUnknownBuiltinAgentKeys", () => {
expect(unknownKeys).toEqual([])
})
it("excludes typo keys when explicitly provided", () => {
const rawConfig = {
agents: {
sisyphuss: { model: "openai/gpt-5.2" },
translator: { model: "google/gemini-3-flash-preview" },
},
}
const unknownKeys = detectUnknownBuiltinAgentKeys(rawConfig, ["sisyphuss"])
expect(unknownKeys).toEqual(["translator"])
})
it("excludes typo keys case-insensitively", () => {
const rawConfig = {
agents: {
Sisyphuss: { model: "openai/gpt-5.2" },
translator: { model: "google/gemini-3-flash-preview" },
},
}
const unknownKeys = detectUnknownBuiltinAgentKeys(rawConfig, ["sisyphuss"])
expect(unknownKeys).toEqual(["translator"])
})
})

View File

@@ -81,12 +81,21 @@ export function detectLikelyBuiltinAgentTypos(
export function detectUnknownBuiltinAgentKeys(
rawConfig: Record<string, unknown>,
excludeKeys: string[] = [],
): string[] {
const agents = rawConfig.agents;
if (!agents || typeof agents !== "object") return [];
const excluded = new Set(excludeKeys.map((key) => key.toLowerCase()));
return Object.keys(agents).filter(
(key) => !BUILTIN_AGENT_OVERRIDE_KEYS_BY_LOWER.has(key.toLowerCase()),
(key) => {
const lower = key.toLowerCase();
return (
!BUILTIN_AGENT_OVERRIDE_KEYS_BY_LOWER.has(lower)
&& !excluded.has(lower)
);
},
);
}
@@ -194,7 +203,10 @@ export function loadConfigFromPath(
});
}
const unknownAgentKeys = detectUnknownBuiltinAgentKeys(rawConfig);
const unknownAgentKeys = detectUnknownBuiltinAgentKeys(
rawConfig,
typoWarnings.map((warning) => warning.key),
);
if (unknownAgentKeys.length > 0) {
const unknownKeysMsg = unknownAgentKeys.map((key) => `agents.${key}`).join(", ");
const migrationHint = "Move custom entries from agents.* to custom_agents.*";