diff --git a/src/plugin-handlers/agent-config-handler.test.ts b/src/plugin-handlers/agent-config-handler.test.ts index c557b7955..c29a3245d 100644 --- a/src/plugin-handlers/agent-config-handler.test.ts +++ b/src/plugin-handlers/agent-config-handler.test.ts @@ -9,11 +9,11 @@ import type { OhMyOpenCodeConfig } from "../config" import * as agentLoader from "../features/claude-code-agent-loader" import * as skillLoader from "../features/opencode-skill-loader" import type { LoadedSkill } from "../features/opencode-skill-loader" -import { getAgentDisplayName, getAgentDisplayName } from "../shared/agent-display-names" +import { getAgentDisplayName, getAgentListDisplayName } from "../shared/agent-display-names" import { applyAgentConfig } from "./agent-config-handler" import type { PluginComponents } from "./plugin-components-loader" -const BUILTIN_SISYPHUS_DISPLAY_NAME = getAgentDisplayName("sisyphus") +const BUILTIN_SISYPHUS_DISPLAY_NAME = getAgentListDisplayName("sisyphus") const BUILTIN_SISYPHUS_JUNIOR_DISPLAY_NAME = getAgentDisplayName("sisyphus-junior") const BUILTIN_MULTIMODAL_LOOKER_DISPLAY_NAME = getAgentDisplayName("multimodal-looker") diff --git a/src/plugin-handlers/agent-config-handler.ts b/src/plugin-handlers/agent-config-handler.ts index 75bf062e8..c2da31067 100644 --- a/src/plugin-handlers/agent-config-handler.ts +++ b/src/plugin-handlers/agent-config-handler.ts @@ -24,6 +24,7 @@ import { } from "./agent-override-protection"; import { buildPrometheusAgentConfig } from "./prometheus-agent-config-builder"; import { buildPlanDemoteConfig } from "./plan-model-inheritance"; +import { getAgentListDisplayName } from "../shared/agent-display-names"; type AgentConfigRecord = Record | undefined> & { build?: Record; @@ -159,10 +160,10 @@ export async function applyAgentConfig(params: { if (isSisyphusEnabled && builtinAgents.sisyphus) { if (configuredDefaultAgent) { (params.config as { default_agent?: string }).default_agent = - getAgentDisplayName(configuredDefaultAgent); + getAgentListDisplayName(configuredDefaultAgent); } else { (params.config as { default_agent?: string }).default_agent = - getAgentDisplayName("sisyphus"); + getAgentListDisplayName("sisyphus"); } // Assembly order: Sisyphus -> Hephaestus -> Prometheus -> Atlas diff --git a/src/plugin-handlers/agent-key-remapper.test.ts b/src/plugin-handlers/agent-key-remapper.test.ts index 3b14781c6..d3e95b866 100644 --- a/src/plugin-handlers/agent-key-remapper.test.ts +++ b/src/plugin-handlers/agent-key-remapper.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect } from "bun:test" import { remapAgentKeysToDisplayNames } from "./agent-key-remapper" -import { getAgentDisplayName } from "../shared/agent-display-names" +import { getAgentDisplayName, getAgentListDisplayName } from "../shared/agent-display-names" describe("remapAgentKeysToDisplayNames", () => { it("remaps known agent keys to display names", () => { @@ -14,7 +14,7 @@ describe("remapAgentKeysToDisplayNames", () => { const result = remapAgentKeysToDisplayNames(agents) // then known agents get display name keys only - expect(result[getAgentDisplayName("sisyphus")]).toBeDefined() + expect(result[getAgentListDisplayName("sisyphus")]).toBeDefined() expect(result["oracle"]).toBeDefined() expect(result["sisyphus"]).toBeUndefined() }) @@ -49,13 +49,13 @@ describe("remapAgentKeysToDisplayNames", () => { const result = remapAgentKeysToDisplayNames(agents) // then all get display name keys - expect(result[getAgentDisplayName("sisyphus")]).toBeDefined() + expect(result[getAgentListDisplayName("sisyphus")]).toBeDefined() expect(result["sisyphus"]).toBeUndefined() - expect(result[getAgentDisplayName("hephaestus")]).toBeDefined() + expect(result[getAgentListDisplayName("hephaestus")]).toBeDefined() expect(result["hephaestus"]).toBeUndefined() - expect(result[getAgentDisplayName("prometheus")]).toBeDefined() + expect(result[getAgentListDisplayName("prometheus")]).toBeDefined() expect(result["prometheus"]).toBeUndefined() - expect(result[getAgentDisplayName("atlas")]).toBeDefined() + expect(result[getAgentListDisplayName("atlas")]).toBeDefined() expect(result["atlas"]).toBeUndefined() expect(result[getAgentDisplayName("athena")]).toBeDefined() expect(result["athena"]).toBeUndefined() @@ -77,8 +77,29 @@ describe("remapAgentKeysToDisplayNames", () => { const result = remapAgentKeysToDisplayNames(agents) // then only display key is emitted - expect(Object.keys(result)).toEqual([getAgentDisplayName("sisyphus")]) - expect(result[getAgentDisplayName("sisyphus")]).toBeDefined() + expect(Object.keys(result)).toEqual([getAgentListDisplayName("sisyphus")]) + expect(result[getAgentListDisplayName("sisyphus")]).toBeDefined() expect(result["sisyphus"]).toBeUndefined() }) + + it("keeps the four core agents in canonical order under opencode name sorting", () => { + // given + const result = remapAgentKeysToDisplayNames({ + atlas: {}, + prometheus: {}, + hephaestus: {}, + sisyphus: {}, + }) + + // when + const sortedNames = Object.keys(result).sort() + + // then + expect(sortedNames).toEqual([ + getAgentListDisplayName("sisyphus"), + getAgentListDisplayName("hephaestus"), + getAgentListDisplayName("prometheus"), + getAgentListDisplayName("atlas"), + ]) + }) }) diff --git a/src/plugin-handlers/agent-key-remapper.ts b/src/plugin-handlers/agent-key-remapper.ts index 54d422a4b..1becbcda9 100644 --- a/src/plugin-handlers/agent-key-remapper.ts +++ b/src/plugin-handlers/agent-key-remapper.ts @@ -1,4 +1,4 @@ -import { getAgentDisplayName } from "../shared/agent-display-names" +import { getAgentListDisplayName } from "../shared/agent-display-names" export function remapAgentKeysToDisplayNames( agents: Record, @@ -6,7 +6,7 @@ export function remapAgentKeysToDisplayNames( const result: Record = {} for (const [key, value] of Object.entries(agents)) { - const displayName = getAgentDisplayName(key) + const displayName = getAgentListDisplayName(key) if (displayName && displayName !== key) { result[displayName] = value // Regression guard: do not also assign result[key]. diff --git a/src/plugin-handlers/agent-priority-order.test.ts b/src/plugin-handlers/agent-priority-order.test.ts index d28f6634a..e1727aa95 100644 --- a/src/plugin-handlers/agent-priority-order.test.ts +++ b/src/plugin-handlers/agent-priority-order.test.ts @@ -1,15 +1,15 @@ import { describe, expect, test } from "bun:test" import { reorderAgentsByPriority } from "./agent-priority-order" -import { getAgentDisplayName } from "../shared/agent-display-names" +import { getAgentDisplayName, getAgentListDisplayName } from "../shared/agent-display-names" describe("reorderAgentsByPriority", () => { test("moves core agents to canonical order and injects runtime order fields", () => { // given - const sisyphus = getAgentDisplayName("sisyphus") - const hephaestus = getAgentDisplayName("hephaestus") - const prometheus = getAgentDisplayName("prometheus") - const atlas = getAgentDisplayName("atlas") + const sisyphus = getAgentListDisplayName("sisyphus") + const hephaestus = getAgentListDisplayName("hephaestus") + const prometheus = getAgentListDisplayName("prometheus") + const atlas = getAgentListDisplayName("atlas") const oracle = getAgentDisplayName("oracle") const agents: Record = { @@ -59,8 +59,8 @@ describe("reorderAgentsByPriority", () => { test("leaves non-object agent configs untouched while still reordering keys", () => { // given - const sisyphus = getAgentDisplayName("sisyphus") - const atlas = getAgentDisplayName("atlas") + const sisyphus = getAgentListDisplayName("sisyphus") + const atlas = getAgentListDisplayName("atlas") const agents: Record = { [atlas]: "atlas-config", diff --git a/src/plugin-handlers/agent-priority-order.ts b/src/plugin-handlers/agent-priority-order.ts index c315ad76a..f69b9a13b 100644 --- a/src/plugin-handlers/agent-priority-order.ts +++ b/src/plugin-handlers/agent-priority-order.ts @@ -1,10 +1,10 @@ -import { getAgentDisplayName } from "../shared/agent-display-names"; +import { getAgentListDisplayName } from "../shared/agent-display-names"; 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 }, + { displayName: getAgentListDisplayName("sisyphus"), order: 1 }, + { displayName: getAgentListDisplayName("hephaestus"), order: 2 }, + { displayName: getAgentListDisplayName("prometheus"), order: 3 }, + { displayName: getAgentListDisplayName("atlas"), order: 4 }, ]; function injectOrderField( diff --git a/src/plugin-handlers/command-config-handler.test.ts b/src/plugin-handlers/command-config-handler.test.ts index 7a2c80ad4..41836dc6b 100644 --- a/src/plugin-handlers/command-config-handler.test.ts +++ b/src/plugin-handlers/command-config-handler.test.ts @@ -7,7 +7,7 @@ import type { PluginComponents } from "./plugin-components-loader"; import { applyCommandConfig } from "./command-config-handler"; import { getAgentDisplayName, - getAgentDisplayName, + getAgentListDisplayName, } from "../shared/agent-display-names"; function createPluginComponents(): PluginComponents { @@ -122,7 +122,7 @@ describe("applyCommandConfig", () => { // then const commandConfig = config.command as Record; - expect(commandConfig["start-work"]?.agent).toBe(getAgentDisplayName("atlas")); + expect(commandConfig["start-work"]?.agent).toBe(getAgentListDisplayName("atlas")); }); test("normalizes legacy display-name command agents to the exported list key", async () => { @@ -147,6 +147,6 @@ describe("applyCommandConfig", () => { // then const commandConfig = config.command as Record; - expect(commandConfig["start-work"]?.agent).toBe(getAgentDisplayName("atlas")); + expect(commandConfig["start-work"]?.agent).toBe(getAgentListDisplayName("atlas")); }); }); diff --git a/src/plugin-handlers/command-config-handler.ts b/src/plugin-handlers/command-config-handler.ts index 86fdcfe26..471e4df52 100644 --- a/src/plugin-handlers/command-config-handler.ts +++ b/src/plugin-handlers/command-config-handler.ts @@ -1,7 +1,7 @@ import type { OhMyOpenCodeConfig } from "../config"; import { getAgentConfigKey, - getAgentDisplayName, + getAgentListDisplayName, } from "../shared/agent-display-names"; import { loadUserCommands, @@ -99,7 +99,7 @@ export async function applyCommandConfig(params: { function remapCommandAgentFields(commands: Record>): void { for (const cmd of Object.values(commands)) { if (cmd?.agent && typeof cmd.agent === "string") { - cmd.agent = getAgentDisplayName(getAgentConfigKey(cmd.agent)); + cmd.agent = getAgentListDisplayName(getAgentConfigKey(cmd.agent)); } } } diff --git a/src/plugin-handlers/config-handler.test.ts b/src/plugin-handlers/config-handler.test.ts index 3f1e58a88..54bdda38f 100644 --- a/src/plugin-handlers/config-handler.test.ts +++ b/src/plugin-handlers/config-handler.test.ts @@ -4,7 +4,7 @@ import { describe, test, expect, spyOn, beforeEach, afterEach } from "bun:test" import { resolveCategoryConfig, createConfigHandler } from "./config-handler" import type { CategoryConfig } from "../config/schema" import type { OhMyOpenCodeConfig } from "../config" -import { getAgentDisplayName, getAgentDisplayName } from "../shared/agent-display-names" +import { getAgentDisplayName, getAgentListDisplayName } from "../shared/agent-display-names" import * as agents from "../agents" import * as sisyphusJunior from "../agents/sisyphus-junior" @@ -246,10 +246,10 @@ describe("Plan agent demote behavior", () => { // #then const keys = Object.keys(config.agent as Record) const coreAgents = [ - getAgentDisplayName("sisyphus"), - getAgentDisplayName("hephaestus"), - getAgentDisplayName("prometheus"), - getAgentDisplayName("atlas"), + getAgentListDisplayName("sisyphus"), + getAgentListDisplayName("hephaestus"), + getAgentListDisplayName("prometheus"), + getAgentListDisplayName("atlas"), ] const ordered = keys.filter((key) => coreAgents.includes(key)) expect(ordered).toEqual(coreAgents) @@ -294,10 +294,10 @@ describe("Plan agent demote behavior", () => { reorderSpy.mock.calls.at(0)?.[0] as Record ) expect(assembledAgentKeys.slice(0, 4)).toEqual([ - getAgentDisplayName("sisyphus"), - getAgentDisplayName("hephaestus"), - getAgentDisplayName("prometheus"), - getAgentDisplayName("atlas"), + getAgentListDisplayName("sisyphus"), + getAgentListDisplayName("hephaestus"), + getAgentListDisplayName("prometheus"), + getAgentListDisplayName("atlas"), ]) }) @@ -336,7 +336,7 @@ describe("Plan agent demote behavior", () => { expect(agents.plan).toBeDefined() expect(agents.plan.mode).toBe("subagent") expect(agents.plan.prompt).toBeUndefined() - expect(agents[getAgentDisplayName("prometheus")]?.prompt).toBeDefined() + expect(agents[getAgentListDisplayName("prometheus")]?.prompt).toBeDefined() }) test("plan agent remains unchanged when planner is disabled", async () => { @@ -370,7 +370,7 @@ describe("Plan agent demote behavior", () => { // #then - plan is not touched, prometheus is not created const agents = config.agent as Record - expect(agents[getAgentDisplayName("prometheus")]).toBeUndefined() + expect(agents[getAgentListDisplayName("prometheus")]).toBeUndefined() expect(agents.plan).toBeDefined() expect(agents.plan.mode).toBe("primary") expect(agents.plan.prompt).toBe("original plan prompt") @@ -401,7 +401,7 @@ describe("Plan agent demote behavior", () => { // then const agents = config.agent as Record - const prometheusKey = getAgentDisplayName("prometheus") + const prometheusKey = getAgentListDisplayName("prometheus") expect(agents[prometheusKey]).toBeDefined() expect(agents[prometheusKey].mode).toBe("all") }) @@ -437,7 +437,7 @@ describe("Agent permission defaults", () => { // #then const agentConfig = config.agent as Record }> - const hephaestusKey = getAgentDisplayName("hephaestus") + const hephaestusKey = getAgentListDisplayName("hephaestus") expect(agentConfig[hephaestusKey]).toBeDefined() expect(agentConfig[hephaestusKey].permission?.task).toBe("allow") }) @@ -465,7 +465,7 @@ describe("default_agent behavior with Sisyphus orchestration", () => { await handler(config) // then - expect(config.default_agent).toBe(getAgentDisplayName("hephaestus")) + expect(config.default_agent).toBe(getAgentListDisplayName("hephaestus")) }) test("canonicalizes configured default_agent when key uses mixed case", async () => { @@ -489,7 +489,7 @@ describe("default_agent behavior with Sisyphus orchestration", () => { await handler(config) // then - expect(config.default_agent).toBe(getAgentDisplayName("hephaestus")) + expect(config.default_agent).toBe(getAgentListDisplayName("hephaestus")) }) test("canonicalizes configured default_agent key to display name", async () => { @@ -513,13 +513,13 @@ describe("default_agent behavior with Sisyphus orchestration", () => { await handler(config) // #then - expect(config.default_agent).toBe(getAgentDisplayName("hephaestus")) + expect(config.default_agent).toBe(getAgentListDisplayName("hephaestus")) }) test("preserves existing display-name default_agent", async () => { // #given const pluginConfig = createPluginConfig({}) - const displayName = getAgentDisplayName("hephaestus") + const displayName = getAgentListDisplayName("hephaestus") const config: Record = { model: "anthropic/claude-opus-4-6", default_agent: displayName, @@ -561,7 +561,7 @@ describe("default_agent behavior with Sisyphus orchestration", () => { await handler(config) // #then - expect(config.default_agent).toBe(getAgentDisplayName("sisyphus")) + expect(config.default_agent).toBe(getAgentListDisplayName("sisyphus")) }) test("sets default_agent to sisyphus when configured default_agent is empty after trim", async () => { @@ -585,7 +585,7 @@ describe("default_agent behavior with Sisyphus orchestration", () => { await handler(config) // then - expect(config.default_agent).toBe(getAgentDisplayName("sisyphus")) + expect(config.default_agent).toBe(getAgentListDisplayName("sisyphus")) }) test("preserves custom default_agent names while trimming whitespace", async () => { @@ -779,7 +779,7 @@ describe("Prometheus direct override priority over category", () => { // then - direct override's reasoningEffort wins const agents = config.agent as Record - const pKey = getAgentDisplayName("prometheus") + const pKey = getAgentListDisplayName("prometheus") expect(agents[pKey]).toBeDefined() expect(agents[pKey].reasoningEffort).toBe("low") }) @@ -820,7 +820,7 @@ describe("Prometheus direct override priority over category", () => { // then - category's reasoningEffort is applied const agents = config.agent as Record - const pKey = getAgentDisplayName("prometheus") + const pKey = getAgentListDisplayName("prometheus") expect(agents[pKey]).toBeDefined() expect(agents[pKey].reasoningEffort).toBe("high") }) @@ -862,7 +862,7 @@ describe("Prometheus direct override priority over category", () => { // then - direct temperature wins over category const agents = config.agent as Record - const pKey = getAgentDisplayName("prometheus") + const pKey = getAgentListDisplayName("prometheus") expect(agents[pKey]).toBeDefined() expect(agents[pKey].temperature).toBe(0.1) }) @@ -898,7 +898,7 @@ describe("Prometheus direct override priority over category", () => { // #then - prompt_append is appended to base prompt, not overwriting it const agents = config.agent as Record - const pKey = getAgentDisplayName("prometheus") + const pKey = getAgentListDisplayName("prometheus") expect(agents[pKey]).toBeDefined() expect(agents[pKey].prompt).toContain("Prometheus") expect(agents[pKey].prompt).toContain(customInstructions) @@ -1290,17 +1290,17 @@ describe("command agent routing coherence", () => { //#then const agentConfig = config.agent as Record const commandConfig = config.command as Record - expect(Object.keys(agentConfig)).toContain(getAgentDisplayName("atlas")) - expect(commandConfig["start-work"]?.agent).toBe(getAgentDisplayName("atlas")) + expect(Object.keys(agentConfig)).toContain(getAgentListDisplayName("atlas")) + expect(commandConfig["start-work"]?.agent).toBe(getAgentListDisplayName("atlas")) }) }) describe("per-agent todowrite/todoread deny when task_system enabled", () => { const AGENTS_WITH_TODO_DENY = new Set([ - getAgentDisplayName("sisyphus"), - getAgentDisplayName("hephaestus"), - getAgentDisplayName("prometheus"), - getAgentDisplayName("atlas"), + getAgentListDisplayName("sisyphus"), + getAgentListDisplayName("hephaestus"), + getAgentListDisplayName("prometheus"), + getAgentListDisplayName("atlas"), getAgentDisplayName("sisyphus-junior"), ]) @@ -1381,10 +1381,10 @@ describe("per-agent todowrite/todoread deny when task_system enabled", () => { expect(lastCall?.[11]).toBe(false) const agentResult = config.agent as Record }> - expect(agentResult[getAgentDisplayName("sisyphus")]?.permission?.todowrite).toBeUndefined() - expect(agentResult[getAgentDisplayName("sisyphus")]?.permission?.todoread).toBeUndefined() - expect(agentResult[getAgentDisplayName("hephaestus")]?.permission?.todowrite).toBeUndefined() - expect(agentResult[getAgentDisplayName("hephaestus")]?.permission?.todoread).toBeUndefined() + expect(agentResult[getAgentListDisplayName("sisyphus")]?.permission?.todowrite).toBeUndefined() + expect(agentResult[getAgentListDisplayName("sisyphus")]?.permission?.todoread).toBeUndefined() + expect(agentResult[getAgentListDisplayName("hephaestus")]?.permission?.todowrite).toBeUndefined() + expect(agentResult[getAgentListDisplayName("hephaestus")]?.permission?.todoread).toBeUndefined() }) test("does not deny todowrite/todoread when task_system is undefined", async () => { @@ -1420,8 +1420,8 @@ describe("per-agent todowrite/todoread deny when task_system enabled", () => { expect(lastCall?.[11]).toBe(false) const agentResult = config.agent as Record }> - expect(agentResult[getAgentDisplayName("sisyphus")]?.permission?.todowrite).toBeUndefined() - expect(agentResult[getAgentDisplayName("sisyphus")]?.permission?.todoread).toBeUndefined() + expect(agentResult[getAgentListDisplayName("sisyphus")]?.permission?.todowrite).toBeUndefined() + expect(agentResult[getAgentListDisplayName("sisyphus")]?.permission?.todoread).toBeUndefined() }) }) diff --git a/src/plugin-handlers/tool-config-handler.test.ts b/src/plugin-handlers/tool-config-handler.test.ts index 609d8386f..dd9e63fc6 100644 --- a/src/plugin-handlers/tool-config-handler.test.ts +++ b/src/plugin-handlers/tool-config-handler.test.ts @@ -1,6 +1,7 @@ import { describe, it, expect, beforeEach, afterEach } from "bun:test" import { applyToolConfig } from "./tool-config-handler" import type { OhMyOpenCodeConfig } from "../config" +import { getAgentListDisplayName } from "../shared/agent-display-names" function createParams(overrides: { taskSystem?: boolean @@ -250,6 +251,22 @@ describe("applyToolConfig", () => { }) }) + describe("#given agentResult uses exported list display keys", () => { + it("#then should still resolve atlas permissions through the prefixed key", () => { + const atlasKey = getAgentListDisplayName("atlas") + const params = createParams({ agents: [atlasKey] }) + + applyToolConfig(params) + + const agent = params.agentResult[atlasKey] as { + permission: Record + } + expect(agent.permission.task).toBe("allow") + expect(agent.permission["task_*"]).toBe("allow") + expect(agent.permission.teammate).toBe("allow") + }) + }) + describe("#given disabled_tools includes 'question'", () => { let originalConfigContent: string | undefined let originalCliRunMode: string | undefined diff --git a/src/plugin-handlers/tool-config-handler.ts b/src/plugin-handlers/tool-config-handler.ts index d698e9560..dae34fda6 100644 --- a/src/plugin-handlers/tool-config-handler.ts +++ b/src/plugin-handlers/tool-config-handler.ts @@ -1,5 +1,5 @@ import type { OhMyOpenCodeConfig } from "../config"; -import { getAgentDisplayName } from "../shared/agent-display-names"; +import { getAgentDisplayName, getAgentListDisplayName } from "../shared/agent-display-names"; import { isTaskSystemEnabled } from "../shared"; type AgentWithPermission = { permission?: Record }; @@ -16,7 +16,7 @@ function getConfigQuestionPermission(): string | null { } function agentByKey(agentResult: Record, key: string): AgentWithPermission | undefined { - return (agentResult[getAgentDisplayName(key)] ?? agentResult[key]) as + return (agentResult[getAgentListDisplayName(key)] ?? agentResult[getAgentDisplayName(key)] ?? agentResult[key]) as | AgentWithPermission | undefined; }