fix: resolve category delegation and command routing with display name agent keys

Category-based delegation (task(category='quick')) was broken because
SISYPHUS_JUNIOR_AGENT sent 'sisyphus-junior' to session.prompt but
config.agent keys are now display names ('Sisyphus-Junior').

- Use getAgentDisplayName() for SISYPHUS_JUNIOR_AGENT constant
- Replace hardcoded 'sisyphus-junior' strings in tools.ts with constant
- Update background-output local constants to use display names
- Add remapCommandAgentFields() to translate command agent fields
- Add raw-key fallback in tool-config-handler agentByKey()
This commit is contained in:
YeonGyu-Kim 2026-02-16 21:32:33 +09:00
parent be2e45b4cb
commit cb601ddd77
8 changed files with 30 additions and 10 deletions

View File

@ -1,4 +1,5 @@
import type { OhMyOpenCodeConfig } from "../config";
import { getAgentDisplayName } from "../shared/agent-display-names";
import {
loadUserCommands,
loadProjectCommands,
@ -68,4 +69,14 @@ export async function applyCommandConfig(params: {
...params.pluginComponents.commands,
...params.pluginComponents.skills,
};
remapCommandAgentFields(params.config.command as Record<string, Record<string, unknown>>);
}
function remapCommandAgentFields(commands: Record<string, Record<string, unknown>>): void {
for (const cmd of Object.values(commands)) {
if (cmd?.agent && typeof cmd.agent === "string") {
cmd.agent = getAgentDisplayName(cmd.agent);
}
}
}

View File

@ -4,7 +4,9 @@ import { getAgentDisplayName } from "../shared/agent-display-names";
type AgentWithPermission = { permission?: Record<string, unknown> };
function agentByKey(agentResult: Record<string, unknown>, key: string): AgentWithPermission | undefined {
return agentResult[getAgentDisplayName(key)] as AgentWithPermission | undefined;
return (agentResult[key] ?? agentResult[getAgentDisplayName(key)]) as
| AgentWithPermission
| undefined;
}
export function applyToolConfig(params: {

View File

@ -9,7 +9,9 @@ import { formatFullSession } from "./full-session-format"
import { formatTaskResult } from "./task-result-format"
import { formatTaskStatus } from "./task-status-format"
const SISYPHUS_JUNIOR_AGENT = "sisyphus-junior"
import { getAgentDisplayName } from "../../shared/agent-display-names"
const SISYPHUS_JUNIOR_AGENT = getAgentDisplayName("sisyphus-junior")
type ToolContextWithMetadata = {
sessionID: string

View File

@ -8,7 +8,9 @@ import { storeToolMetadata } from "../../../features/tool-metadata-store"
import type { BackgroundTask } from "../../../features/background-agent"
import type { ToolContextWithMetadata } from "./utils"
const SISYPHUS_JUNIOR_AGENT = "sisyphus-junior"
import { getAgentDisplayName } from "../../../shared/agent-display-names"
const SISYPHUS_JUNIOR_AGENT = getAgentDisplayName("sisyphus-junior")
type ToolContextWithCallId = ToolContextWithMetadata & {
callID?: string

View File

@ -85,7 +85,7 @@ describe("background_output full_session", () => {
const task = createTask({
id: "task-1",
agent: "sisyphus-junior",
agent: "Sisyphus-Junior",
category: "quick",
description: "Fix flaky test",
status: "running",

View File

@ -1 +1,3 @@
export const SISYPHUS_JUNIOR_AGENT = "sisyphus-junior"
import { getAgentDisplayName } from "../../shared/agent-display-names"
export const SISYPHUS_JUNIOR_AGENT = getAgentDisplayName("sisyphus-junior")

View File

@ -452,7 +452,7 @@ describe("sisyphus-task", () => {
await tool.execute(args, toolContext)
// then
expect(args.subagent_type).toBe("sisyphus-junior")
expect(args.subagent_type).toBe("Sisyphus-Junior")
}, { timeout: 10000 })
test("category overrides subagent_type and still maps to sisyphus-junior", async () => {
@ -517,7 +517,7 @@ describe("sisyphus-task", () => {
const result = await tool.execute(args, toolContext)
//#then
expect(args.subagent_type).toBe("sisyphus-junior")
expect(args.subagent_type).toBe("Sisyphus-Junior")
expect(result).toContain("Background task launched")
}, { timeout: 10000 })
@ -3718,7 +3718,7 @@ describe("sisyphus-task", () => {
)
// then - title should follow OpenCode format
expect(createBody.title).toBe("Implement feature X (@sisyphus-junior subagent)")
expect(createBody.title).toBe("Implement feature X (@Sisyphus-Junior subagent)")
}, { timeout: 10000 })
test("sync task output includes <task_metadata> block with session_id", async () => {

View File

@ -1,6 +1,7 @@
import { tool, type ToolDefinition } from "@opencode-ai/plugin"
import type { DelegateTaskArgs, ToolContextWithMetadata, DelegateTaskToolOptions } from "./types"
import { CATEGORY_DESCRIPTIONS } from "./constants"
import { SISYPHUS_JUNIOR_AGENT } from "./sisyphus-junior-agent"
import { mergeCategories } from "../../shared/merge-categories"
import { log } from "../../shared/logger"
import { buildSystemContent } from "./prompt-builder"
@ -88,13 +89,13 @@ Prompts MUST be in English.`
const ctx = toolContext as ToolContextWithMetadata
if (args.category) {
if (args.subagent_type && args.subagent_type !== "sisyphus-junior") {
if (args.subagent_type && args.subagent_type !== SISYPHUS_JUNIOR_AGENT) {
log("[task] category provided - overriding subagent_type to sisyphus-junior", {
category: args.category,
subagent_type: args.subagent_type,
})
}
args.subagent_type = "sisyphus-junior"
args.subagent_type = SISYPHUS_JUNIOR_AGENT
}
await ctx.metadata?.({
title: args.description,