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
This commit is contained in:
kuitos
2026-03-25 23:35:40 +08:00
parent 5e9231e251
commit 5befb60229
2 changed files with 21 additions and 10 deletions
@@ -60,6 +60,7 @@ describe("applyAgentConfig builtin override protection", () => {
name: "Builtin Sisyphus", name: "Builtin Sisyphus",
prompt: "builtin prompt", prompt: "builtin prompt",
mode: "primary", mode: "primary",
order: 1,
} }
const builtinOracleConfig: AgentConfig = { const builtinOracleConfig: AgentConfig = {
+20 -10
View File
@@ -1,11 +1,21 @@
import { getAgentDisplayName } from "../shared/agent-display-names"; import { getAgentDisplayName } from "../shared/agent-display-names";
const CORE_AGENT_ORDER = [ const CORE_AGENT_ORDER: ReadonlyArray<{ displayName: string; order: number }> = [
getAgentDisplayName("sisyphus"), { displayName: getAgentDisplayName("sisyphus"), order: 1 },
getAgentDisplayName("hephaestus"), { displayName: getAgentDisplayName("hephaestus"), order: 2 },
getAgentDisplayName("prometheus"), { displayName: getAgentDisplayName("prometheus"), order: 3 },
getAgentDisplayName("atlas"), { displayName: getAgentDisplayName("atlas"), order: 4 },
] as const; ];
function injectOrderField(
agentConfig: unknown,
order: number,
): unknown {
if (typeof agentConfig === "object" && agentConfig !== null) {
return { ...agentConfig, order };
}
return agentConfig;
}
export function reorderAgentsByPriority( export function reorderAgentsByPriority(
agents: Record<string, unknown>, agents: Record<string, unknown>,
@@ -13,10 +23,10 @@ export function reorderAgentsByPriority(
const ordered: Record<string, unknown> = {}; const ordered: Record<string, unknown> = {};
const seen = new Set<string>(); const seen = new Set<string>();
for (const key of CORE_AGENT_ORDER) { for (const { displayName, order } of CORE_AGENT_ORDER) {
if (Object.prototype.hasOwnProperty.call(agents, key)) { if (Object.prototype.hasOwnProperty.call(agents, displayName)) {
ordered[key] = agents[key]; ordered[displayName] = injectOrderField(agents[displayName], order);
seen.add(key); seen.add(displayName);
} }
} }