From f5e063b00a7966367fcd74e2daaeb150e58e903d Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Mon, 18 May 2026 13:42:59 +0900 Subject: [PATCH] fix: only call setDefaultAgentForSort when user explicitly sets default_agent The previous code read params.config.default_agent which is always populated to "Sisyphus - Ultraworker" by existing logic (lines 196-204) even when the user never configured default_agent. This silently overrode any custom agent_order. Now we gate on configuredDefaultAgent (the user's explicit value) so the sort shim rank map is only mutated when the user actually set default_agent. Add regression test: agent_order without default_agent must preserve order. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- src/plugin-handlers/agent-config-handler.ts | 7 ++++--- src/shared/agent-sort-shim.test.ts | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) 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]) + }) + }) + }) })