diff --git a/src/plugin-handlers/agent-config-handler.ts b/src/plugin-handlers/agent-config-handler.ts index 16fcda22f..026afdad2 100644 --- a/src/plugin-handlers/agent-config-handler.ts +++ b/src/plugin-handlers/agent-config-handler.ts @@ -400,9 +400,10 @@ export async function applyAgentConfig(params: { ); } - const resolvedDefault = (params.config as { default_agent?: string }).default_agent; - if (resolvedDefault) { - setDefaultAgentForSort(resolvedDefault); + if (configuredDefaultAgent) { + setDefaultAgentForSort( + (params.config as { default_agent?: string }).default_agent ?? configuredDefaultAgent, + ); } const agentResult = params.config.agent as Record; diff --git a/src/shared/agent-sort-shim.test.ts b/src/shared/agent-sort-shim.test.ts index 233ce19d7..4b26609c4 100644 --- a/src/shared/agent-sort-shim.test.ts +++ b/src/shared/agent-sort-shim.test.ts @@ -265,4 +265,25 @@ describe("agent-sort-shim", () => { }) }) }) + + describe("#given agent_order configured without default_agent", () => { + describe("#when setAgentSortOrder sets a non-canonical order and setDefaultAgentForSort is NOT called", () => { + test("#then the custom agent_order is preserved without implicit override", () => { + // given + setAgentSortOrder(["hephaestus", "sisyphus", "prometheus", "atlas"]) + // setDefaultAgentForSort is intentionally NOT called (user did not set default_agent) + const sisyphus = { name: "Sisyphus - Ultraworker" } + const hephaestus = { name: "Hephaestus - Deep Agent" } + const prometheus = { name: "Prometheus - Plan Builder" } + const atlas = { name: "Atlas - Plan Executor" } + const input = [atlas, sisyphus, prometheus, hephaestus] + + // when + const result = input.toSorted((a, b) => a.name.localeCompare(b.name)) + + // then — Hephaestus must remain first per the user's agent_order + expect(result).toEqual([hephaestus, sisyphus, prometheus, atlas]) + }) + }) + }) })