diff --git a/src/plugin-handlers/agent-config-handler.test.ts b/src/plugin-handlers/agent-config-handler.test.ts index b17d02faa..74e0b0632 100644 --- a/src/plugin-handlers/agent-config-handler.test.ts +++ b/src/plugin-handlers/agent-config-handler.test.ts @@ -293,6 +293,81 @@ describe("applyAgentConfig builtin override protection", () => { expect(createSisyphusJuniorAgentSpy).toHaveBeenCalledWith(undefined, "openai/gpt-5.4", false) }) + test("defaults mode to subagent for configAgent entries missing mode", async () => { + // given + const config = createBaseConfig() + ;(config as Record).agent = { + "custom-reviewer": { + name: "custom-reviewer", + prompt: "Review code for security issues", + description: "Custom code reviewer", + }, + } + + // when + const result = await applyAgentConfig({ + config, + pluginConfig: createPluginConfig(), + ctx: { directory: "/tmp" }, + pluginComponents: createPluginComponents(), + }) + + // then + const customAgent = result["custom-reviewer"] as Record + expect(customAgent).toBeDefined() + expect(customAgent.mode).toBe("subagent") + }) + + test("preserves explicit mode on configAgent entries", async () => { + // given + const config = createBaseConfig() + ;(config as Record).agent = { + "custom-primary": { + name: "custom-primary", + prompt: "Primary agent", + mode: "primary", + }, + } + + // when + const result = await applyAgentConfig({ + config, + pluginConfig: createPluginConfig(), + ctx: { directory: "/tmp" }, + pluginComponents: createPluginComponents(), + }) + + // then + const customAgent = result["custom-primary"] as Record + expect(customAgent).toBeDefined() + expect(customAgent.mode).toBe("primary") + }) + + test("defaults mode to subagent for plugin agents missing mode", async () => { + // given + const pluginComponents = createPluginComponents() + pluginComponents.agents = { + "plugin-worker": { + name: "plugin-worker", + prompt: "Do work", + description: "Plugin worker agent", + } as Record, + } + + // when + const result = await applyAgentConfig({ + config: createBaseConfig(), + pluginConfig: createPluginConfig(), + ctx: { directory: "/tmp" }, + pluginComponents, + }) + + // then + const pluginAgent = result["plugin-worker"] as Record + expect(pluginAgent).toBeDefined() + expect(pluginAgent.mode).toBe("subagent") + }) + test("includes project and global .agents skills in builtin agent awareness", async () => { // given const projectAgentsSkill = { diff --git a/src/plugin-handlers/agent-config-handler.ts b/src/plugin-handlers/agent-config-handler.ts index fffa845e3..75bf062e8 100644 --- a/src/plugin-handlers/agent-config-handler.ts +++ b/src/plugin-handlers/agent-config-handler.ts @@ -99,10 +99,12 @@ export async function applyAgentConfig(params: { const rawPluginAgents = params.pluginComponents.agents; const pluginAgents = Object.fromEntries( - Object.entries(rawPluginAgents).map(([key, value]) => [ - key, - value ? migrateAgentConfig(value as Record) : value, - ]), + Object.entries(rawPluginAgents).map(([key, value]) => { + if (!value) return [key, value]; + const migrated = migrateAgentConfig(value as Record); + if (!migrated.mode) migrated.mode = "subagent"; + return [key, migrated]; + }), ); const configAgent = params.config.agent as AgentConfigRecord | undefined; @@ -219,10 +221,12 @@ export async function applyAgentConfig(params: { if (key in builtinAgents) return false; return true; }) - .map(([key, value]) => [ - key, - value ? migrateAgentConfig(value as Record) : value, - ]), + .map(([key, value]) => { + if (!value) return [key, value]; + const migrated = migrateAgentConfig(value as Record); + if (!migrated.mode) migrated.mode = "subagent"; + return [key, migrated]; + }), ) : {}; @@ -285,12 +289,23 @@ export async function applyAgentConfig(params: { protectedBuiltinAgentNames, ); + const defaultedConfigAgents = configAgent + ? Object.fromEntries( + Object.entries(configAgent).map(([key, value]) => { + if (!value) return [key, value]; + const migrated = migrateAgentConfig(value as Record); + if (!migrated.mode) migrated.mode = "subagent"; + return [key, migrated]; + }), + ) + : {}; + params.config.agent = { ...builtinAgents, ...filterDisabledAgents(filteredUserAgents), ...filterDisabledAgents(filteredProjectAgents), ...filterDisabledAgents(filteredPluginAgents), - ...configAgent, + ...defaultedConfigAgents, }; }