feat(config): add custom_agents overrides and strict agent validation
This commit is contained in:
@@ -162,6 +162,197 @@ describe("Sisyphus-Junior model inheritance", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("custom agent overrides", () => {
|
||||
test("passes custom agent summaries into builtin agent prompt builder", async () => {
|
||||
// #given
|
||||
;(agentLoader.loadUserAgents as any).mockReturnValue({
|
||||
translator: {
|
||||
name: "translator",
|
||||
mode: "subagent",
|
||||
description: "Translate and localize text",
|
||||
prompt: "Translate content",
|
||||
},
|
||||
})
|
||||
const createBuiltinAgentsMock = agents.createBuiltinAgents as unknown as {
|
||||
mock: { calls: unknown[][] }
|
||||
}
|
||||
|
||||
const pluginConfig: OhMyOpenCodeConfig = {
|
||||
sisyphus_agent: {
|
||||
planner_enabled: true,
|
||||
},
|
||||
}
|
||||
const config: Record<string, unknown> = {
|
||||
model: "anthropic/claude-opus-4-6",
|
||||
agent: {},
|
||||
}
|
||||
|
||||
const handler = createConfigHandler({
|
||||
ctx: { directory: "/tmp" },
|
||||
pluginConfig,
|
||||
modelCacheState: {
|
||||
anthropicContext1MEnabled: false,
|
||||
modelContextLimitsCache: new Map(),
|
||||
},
|
||||
})
|
||||
|
||||
// #when
|
||||
await handler(config)
|
||||
|
||||
// #then
|
||||
const firstCallArgs = createBuiltinAgentsMock.mock.calls[0]
|
||||
expect(firstCallArgs).toBeDefined()
|
||||
expect(Array.isArray(firstCallArgs[7])).toBe(true)
|
||||
expect(firstCallArgs[7]).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
name: "translator",
|
||||
description: "Translate and localize text",
|
||||
}),
|
||||
]),
|
||||
)
|
||||
})
|
||||
|
||||
test("applies oh-my-opencode agent overrides to custom Claude agents", async () => {
|
||||
// #given
|
||||
;(agentLoader.loadUserAgents as any).mockReturnValue({
|
||||
translator: {
|
||||
name: "translator",
|
||||
mode: "subagent",
|
||||
description: "(user) translator",
|
||||
prompt: "Base translator prompt",
|
||||
},
|
||||
})
|
||||
|
||||
const pluginConfig: OhMyOpenCodeConfig = {
|
||||
custom_agents: {
|
||||
translator: {
|
||||
model: "google/gemini-3-flash-preview",
|
||||
temperature: 0,
|
||||
prompt_append: "Always preserve placeholders exactly.",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const config: Record<string, unknown> = {
|
||||
model: "anthropic/claude-opus-4-6",
|
||||
agent: {},
|
||||
}
|
||||
|
||||
const handler = createConfigHandler({
|
||||
ctx: { directory: "/tmp" },
|
||||
pluginConfig,
|
||||
modelCacheState: {
|
||||
anthropicContext1MEnabled: false,
|
||||
modelContextLimitsCache: new Map(),
|
||||
},
|
||||
})
|
||||
|
||||
// #when
|
||||
await handler(config)
|
||||
|
||||
// #then
|
||||
const agentConfig = config.agent as Record<string, { model?: string; temperature?: number; prompt?: string }>
|
||||
expect(agentConfig.translator).toBeDefined()
|
||||
expect(agentConfig.translator.model).toBe("google/gemini-3-flash-preview")
|
||||
expect(agentConfig.translator.temperature).toBe(0)
|
||||
expect(agentConfig.translator.prompt).toContain("Base translator prompt")
|
||||
expect(agentConfig.translator.prompt).toContain("Always preserve placeholders exactly.")
|
||||
})
|
||||
|
||||
test("prometheus prompt includes custom agent catalog for planning", async () => {
|
||||
// #given
|
||||
;(agentLoader.loadUserAgents as any).mockReturnValue({
|
||||
translator: {
|
||||
name: "translator",
|
||||
mode: "subagent",
|
||||
description: "Translate and localize locale files",
|
||||
prompt: "Translate content",
|
||||
},
|
||||
})
|
||||
|
||||
const pluginConfig: OhMyOpenCodeConfig = {
|
||||
sisyphus_agent: {
|
||||
planner_enabled: true,
|
||||
},
|
||||
}
|
||||
const config: Record<string, unknown> = {
|
||||
model: "anthropic/claude-opus-4-6",
|
||||
agent: {},
|
||||
}
|
||||
|
||||
const handler = createConfigHandler({
|
||||
ctx: { directory: "/tmp" },
|
||||
pluginConfig,
|
||||
modelCacheState: {
|
||||
anthropicContext1MEnabled: false,
|
||||
modelContextLimitsCache: new Map(),
|
||||
},
|
||||
})
|
||||
|
||||
// #when
|
||||
await handler(config)
|
||||
|
||||
// #then
|
||||
const agentsConfig = config.agent as Record<string, { prompt?: string }>
|
||||
const pKey = getAgentDisplayName("prometheus")
|
||||
expect(agentsConfig[pKey]).toBeDefined()
|
||||
expect(agentsConfig[pKey].prompt).toContain("<custom_agent_catalog>")
|
||||
expect(agentsConfig[pKey].prompt).toContain("translator")
|
||||
expect(agentsConfig[pKey].prompt).toContain("Translate and localize locale files")
|
||||
})
|
||||
|
||||
test("prometheus prompt excludes unknown custom_agents entries", async () => {
|
||||
// #given
|
||||
;(agentLoader.loadUserAgents as any).mockReturnValue({
|
||||
translator: {
|
||||
name: "translator",
|
||||
mode: "subagent",
|
||||
description: "Translate and localize locale files",
|
||||
prompt: "Translate content",
|
||||
},
|
||||
})
|
||||
|
||||
const pluginConfig: OhMyOpenCodeConfig = {
|
||||
custom_agents: {
|
||||
translator: {
|
||||
description: "Translate and localize locale files",
|
||||
},
|
||||
ghostwriter: {
|
||||
description: "This agent does not exist in runtime",
|
||||
},
|
||||
},
|
||||
sisyphus_agent: {
|
||||
planner_enabled: true,
|
||||
},
|
||||
}
|
||||
|
||||
const config: Record<string, unknown> = {
|
||||
model: "anthropic/claude-opus-4-6",
|
||||
agent: {},
|
||||
}
|
||||
|
||||
const handler = createConfigHandler({
|
||||
ctx: { directory: "/tmp" },
|
||||
pluginConfig,
|
||||
modelCacheState: {
|
||||
anthropicContext1MEnabled: false,
|
||||
modelContextLimitsCache: new Map(),
|
||||
},
|
||||
})
|
||||
|
||||
// #when
|
||||
await handler(config)
|
||||
|
||||
// #then
|
||||
const agentsConfig = config.agent as Record<string, { prompt?: string }>
|
||||
const pKey = getAgentDisplayName("prometheus")
|
||||
expect(agentsConfig[pKey]).toBeDefined()
|
||||
expect(agentsConfig[pKey].prompt).toContain("translator")
|
||||
expect(agentsConfig[pKey].prompt).not.toContain("ghostwriter")
|
||||
})
|
||||
})
|
||||
|
||||
describe("Plan agent demote behavior", () => {
|
||||
test("orders core agents as sisyphus -> hephaestus -> prometheus -> atlas", async () => {
|
||||
// #given
|
||||
|
||||
Reference in New Issue
Block a user