Skip to content

Commit 5befb60

Browse files
committed
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
1 parent 5e9231e commit 5befb60

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

src/plugin-handlers/agent-config-handler.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ describe("applyAgentConfig builtin override protection", () => {
6060
name: "Builtin Sisyphus",
6161
prompt: "builtin prompt",
6262
mode: "primary",
63+
order: 1,
6364
}
6465

6566
const builtinOracleConfig: AgentConfig = {

src/plugin-handlers/agent-priority-order.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
11
import { getAgentDisplayName } from "../shared/agent-display-names";
22

3-
const CORE_AGENT_ORDER = [
4-
getAgentDisplayName("sisyphus"),
5-
getAgentDisplayName("hephaestus"),
6-
getAgentDisplayName("prometheus"),
7-
getAgentDisplayName("atlas"),
8-
] as const;
3+
const CORE_AGENT_ORDER: ReadonlyArray<{ displayName: string; order: number }> = [
4+
{ displayName: getAgentDisplayName("sisyphus"), order: 1 },
5+
{ displayName: getAgentDisplayName("hephaestus"), order: 2 },
6+
{ displayName: getAgentDisplayName("prometheus"), order: 3 },
7+
{ displayName: getAgentDisplayName("atlas"), order: 4 },
8+
];
9+
10+
function injectOrderField(
11+
agentConfig: unknown,
12+
order: number,
13+
): unknown {
14+
if (typeof agentConfig === "object" && agentConfig !== null) {
15+
return { ...agentConfig, order };
16+
}
17+
return agentConfig;
18+
}
919

1020
export function reorderAgentsByPriority(
1121
agents: Record<string, unknown>,
1222
): Record<string, unknown> {
1323
const ordered: Record<string, unknown> = {};
1424
const seen = new Set<string>();
1525

16-
for (const key of CORE_AGENT_ORDER) {
17-
if (Object.prototype.hasOwnProperty.call(agents, key)) {
18-
ordered[key] = agents[key];
19-
seen.add(key);
26+
for (const { displayName, order } of CORE_AGENT_ORDER) {
27+
if (Object.prototype.hasOwnProperty.call(agents, displayName)) {
28+
ordered[displayName] = injectOrderField(agents[displayName], order);
29+
seen.add(displayName);
2030
}
2131
}
2232

0 commit comments

Comments
 (0)