fix(custom-agents): preserve summary flags during description merge

This commit is contained in:
edxeth
2026-02-18 20:14:47 +01:00
parent 754a2593f9
commit fb139a7a01
2 changed files with 74 additions and 6 deletions

View File

@@ -351,6 +351,68 @@ describe("custom agent overrides", () => {
expect(agentsConfig[pKey].prompt).toContain("translator")
expect(agentsConfig[pKey].prompt).not.toContain("ghostwriter")
})
test("custom agent summary merge preserves flags when custom_agents adds description", async () => {
// #given
;(agentLoader.loadUserAgents as any).mockReturnValue({
translator: {
name: "translator",
mode: "subagent",
description: "",
hidden: true,
disabled: true,
enabled: false,
prompt: "Translate content",
},
})
const createBuiltinAgentsMock = agents.createBuiltinAgents as unknown as {
mock: { calls: unknown[][] }
}
const pluginConfig: OhMyOpenCodeConfig = {
custom_agents: {
translator: {
description: "Translate and localize locale files",
},
},
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]
const summaries = firstCallArgs[7] as Array<{
name: string
description: string
hidden?: boolean
disabled?: boolean
enabled?: boolean
}>
const translatorSummary = summaries.find((summary) => summary.name === "translator")
expect(translatorSummary).toBeDefined()
expect(translatorSummary?.description).toBe("Translate and localize locale files")
expect(translatorSummary?.hidden).toBe(true)
expect(translatorSummary?.disabled).toBe(true)
expect(translatorSummary?.enabled).toBe(false)
})
})
describe("Plan agent demote behavior", () => {

View File

@@ -74,9 +74,9 @@ export function collectCustomAgentSummariesFromRecord(
summaries.push({
name,
description,
hidden: agentValue.hidden === true,
disabled: agentValue.disabled === true,
enabled: agentValue.enabled === false ? false : true,
hidden: typeof agentValue.hidden === "boolean" ? agentValue.hidden : undefined,
disabled: typeof agentValue.disabled === "boolean" ? agentValue.disabled : undefined,
enabled: typeof agentValue.enabled === "boolean" ? agentValue.enabled : undefined,
});
}
@@ -99,9 +99,15 @@ export function mergeCustomAgentSummaries(...summaryGroups: AgentSummary[][]): A
const existingDescription = existing.description.trim();
const incomingDescription = summary.description.trim();
if (!existingDescription && incomingDescription) {
merged.set(key, summary);
}
merged.set(key, {
...existing,
...summary,
hidden: summary.hidden ?? existing.hidden,
disabled: summary.disabled ?? existing.disabled,
enabled: summary.enabled ?? existing.enabled,
description: incomingDescription || existingDescription,
});
}
}