fix(config): normalize configured default_agent

Agent keys are remapped to display names, so preserving `default_agent`
values could still select a missing key at runtime.

This regression surfaced after d94a739203 remapped `config.agent` keys
to display names without canonicalizing configured defaults.

Normalize configured `default_agent` through display-name mapping before
fallback logic and extend tests to cover canonical and display-name
inputs.
This commit is contained in:
Jason Kölker
2026-02-17 01:42:37 +00:00
parent 72fa2c7e65
commit a562e3aa4b
2 changed files with 39 additions and 5 deletions

View File

@@ -23,9 +23,12 @@ type AgentConfigRecord = Record<string, Record<string, unknown> | undefined> & {
plan?: Record<string, unknown>;
};
function hasConfiguredDefaultAgent(config: Record<string, unknown>): boolean {
function getConfiguredDefaultAgent(config: Record<string, unknown>): string | undefined {
const defaultAgent = config.default_agent;
return typeof defaultAgent === "string" && defaultAgent.trim().length > 0;
if (typeof defaultAgent !== "string") return undefined;
const trimmedDefaultAgent = defaultAgent.trim();
return trimmedDefaultAgent.length > 0 ? trimmedDefaultAgent : undefined;
}
export async function applyAgentConfig(params: {
@@ -107,11 +110,17 @@ export async function applyAgentConfig(params: {
const plannerEnabled = params.pluginConfig.sisyphus_agent?.planner_enabled ?? true;
const replacePlan = params.pluginConfig.sisyphus_agent?.replace_plan ?? true;
const shouldDemotePlan = plannerEnabled && replacePlan;
const configuredDefaultAgent = getConfiguredDefaultAgent(params.config);
if (configuredDefaultAgent) {
(params.config as { default_agent?: string }).default_agent =
getAgentDisplayName(configuredDefaultAgent);
}
const configAgent = params.config.agent as AgentConfigRecord | undefined;
if (isSisyphusEnabled && builtinAgents.sisyphus) {
if (!hasConfiguredDefaultAgent(params.config)) {
if (!configuredDefaultAgent) {
(params.config as { default_agent?: string }).default_agent =
getAgentDisplayName("sisyphus");
}

View File

@@ -350,7 +350,7 @@ describe("Agent permission defaults", () => {
})
describe("default_agent behavior with Sisyphus orchestration", () => {
test("preserves existing default_agent when already set", async () => {
test("canonicalizes configured default_agent key to display name", async () => {
// #given
const pluginConfig: OhMyOpenCodeConfig = {}
const config: Record<string, unknown> = {
@@ -371,7 +371,32 @@ describe("default_agent behavior with Sisyphus orchestration", () => {
await handler(config)
// #then
expect(config.default_agent).toBe("hephaestus")
expect(config.default_agent).toBe(getAgentDisplayName("hephaestus"))
})
test("preserves existing display-name default_agent", async () => {
// #given
const pluginConfig: OhMyOpenCodeConfig = {}
const displayName = getAgentDisplayName("hephaestus")
const config: Record<string, unknown> = {
model: "anthropic/claude-opus-4-6",
default_agent: displayName,
agent: {},
}
const handler = createConfigHandler({
ctx: { directory: "/tmp" },
pluginConfig,
modelCacheState: {
anthropicContext1MEnabled: false,
modelContextLimitsCache: new Map(),
},
})
// #when
await handler(config)
// #then
expect(config.default_agent).toBe(displayName)
})
test("sets default_agent to sisyphus when missing", async () => {