From 5befb602298aa0597288d6ac4ab2c6fe0d49550f Mon Sep 17 00:00:00 2001 From: kuitos Date: Wed, 25 Mar 2026 23:35:40 +0800 Subject: [PATCH] feat(agent-priority): inject order field for deterministic agent Tab cycling Inject an explicit `order` field (1-4) into the four core agents (Sisyphus, Hephaestus, Prometheus, Atlas) via reorderAgentsByPriority(). This pre-empts OpenCode's alphabetical agent sorting so the intended Tab cycle order is preserved once OpenCode merges order field support (anomalyco/opencode#19127). Refs anomalyco/opencode#7372 --- .../agent-config-handler.test.ts | 1 + src/plugin-handlers/agent-priority-order.ts | 30 ++++++++++++------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/plugin-handlers/agent-config-handler.test.ts b/src/plugin-handlers/agent-config-handler.test.ts index d0d01a897..bacc3fa24 100644 --- a/src/plugin-handlers/agent-config-handler.test.ts +++ b/src/plugin-handlers/agent-config-handler.test.ts @@ -60,6 +60,7 @@ describe("applyAgentConfig builtin override protection", () => { name: "Builtin Sisyphus", prompt: "builtin prompt", mode: "primary", + order: 1, } const builtinOracleConfig: AgentConfig = { diff --git a/src/plugin-handlers/agent-priority-order.ts b/src/plugin-handlers/agent-priority-order.ts index 9ca886130..c315ad76a 100644 --- a/src/plugin-handlers/agent-priority-order.ts +++ b/src/plugin-handlers/agent-priority-order.ts @@ -1,11 +1,21 @@ import { getAgentDisplayName } from "../shared/agent-display-names"; -const CORE_AGENT_ORDER = [ - getAgentDisplayName("sisyphus"), - getAgentDisplayName("hephaestus"), - getAgentDisplayName("prometheus"), - getAgentDisplayName("atlas"), -] as const; +const CORE_AGENT_ORDER: ReadonlyArray<{ displayName: string; order: number }> = [ + { displayName: getAgentDisplayName("sisyphus"), order: 1 }, + { displayName: getAgentDisplayName("hephaestus"), order: 2 }, + { displayName: getAgentDisplayName("prometheus"), order: 3 }, + { displayName: getAgentDisplayName("atlas"), order: 4 }, +]; + +function injectOrderField( + agentConfig: unknown, + order: number, +): unknown { + if (typeof agentConfig === "object" && agentConfig !== null) { + return { ...agentConfig, order }; + } + return agentConfig; +} export function reorderAgentsByPriority( agents: Record, @@ -13,10 +23,10 @@ export function reorderAgentsByPriority( const ordered: Record = {}; const seen = new Set(); - for (const key of CORE_AGENT_ORDER) { - if (Object.prototype.hasOwnProperty.call(agents, key)) { - ordered[key] = agents[key]; - seen.add(key); + for (const { displayName, order } of CORE_AGENT_ORDER) { + if (Object.prototype.hasOwnProperty.call(agents, displayName)) { + ordered[displayName] = injectOrderField(agents[displayName], order); + seen.add(displayName); } }