fix: unify agent display names and strip invisible sort prefixes

- Replace getAgentRuntimeName with getAgentDisplayName for consistency
- Add stripAgentListSortPrefix helper to normalize agent names
- Strip sort prefixes in subagent-resolver and sync-executor
- Backfill canonical names for core agents when builtin configs omit name
- Update tests to match new behavior
This commit is contained in:
YeonGyu-Kim
2026-04-11 14:53:01 +09:00
parent c30b058b7e
commit 9f135af41c
9 changed files with 180 additions and 37 deletions
@@ -280,6 +280,27 @@ describe("executeSync", () => {
expect(deps.processMessages).not.toHaveBeenCalled()
})
test("strips invisible sort prefixes before sending sync prompts", async () => {
//#given
const executeSync = await importExecuteSync()
const deps = createDependencies()
const toolContext = createToolContext()
const recorder = createPromptAsyncRecorder()
const args = {
subagent_type: "\u200BSisyphus - Ultraworker",
description: "prefixed agent",
prompt: "find something",
run_in_background: false,
}
//#when
await executeSync(args, toolContext, createContext(recorder.promptAsync) as never, deps)
//#then
const promptInput = recorder.getCapturedInput()
expect(promptInput?.body.agent).toBe("Sisyphus - Ultraworker")
})
test("returns generic prompt failure with task metadata", async () => {
//#given
const executeSync = await importExecuteSync()
+5 -3
View File
@@ -6,6 +6,7 @@ import { getAgentToolRestrictions, log } from "../../shared"
import { applySessionPromptParams } from "../../shared/session-prompt-params-helpers"
import type { DelegatedModelConfig } from "../../shared/model-resolution-types"
import type { FallbackEntry } from "../../shared/model-requirements"
import { stripAgentListSortPrefix } from "../../shared/agent-display-names"
import { waitForCompletion } from "./completion-poller"
import { processMessages } from "./message-processor"
import { createOrGetSession } from "./session-creator"
@@ -99,14 +100,15 @@ export async function executeSync(
log(`[call_omo_agent] Sending prompt to session ${sessionID}`)
log(`[call_omo_agent] Prompt text:`, args.prompt.substring(0, 100))
const normalizedSubagentType = stripAgentListSortPrefix(args.subagent_type)
try {
await (ctx.client.session as unknown as SessionWithPromptAsync).promptAsync({
path: { id: sessionID },
body: {
agent: args.subagent_type,
agent: normalizedSubagentType,
tools: {
...getAgentToolRestrictions(args.subagent_type),
...getAgentToolRestrictions(normalizedSubagentType),
task: false,
question: false,
},
@@ -120,7 +122,7 @@ export async function executeSync(
const errorMessage = error instanceof Error ? error.message : String(error)
log(`[call_omo_agent] Prompt error:`, errorMessage)
if (errorMessage.includes("agent.name") || errorMessage.includes("undefined")) {
return `Error: Agent "${args.subagent_type}" not found. Make sure the agent is registered in your opencode.json or provided by a plugin.\n\n<task_metadata>\nsession_id: ${sessionID}\n</task_metadata>`
return `Error: Agent "${normalizedSubagentType}" not found. Make sure the agent is registered in your opencode.json or provided by a plugin.\n\n<task_metadata>\nsession_id: ${sessionID}\n</task_metadata>`
}
return `Error: Failed to send prompt: ${errorMessage}\n\n<task_metadata>\nsession_id: ${sessionID}\n</task_metadata>`
}
+10 -7
View File
@@ -7,7 +7,7 @@ import { normalizeModelFormat } from "../../shared/model-format-normalizer"
import { AGENT_MODEL_REQUIREMENTS } from "../../shared/model-requirements"
import { normalizeFallbackModels, flattenToFallbackModelStrings } from "../../shared/model-resolver"
import { buildFallbackChainFromModels, findMostSpecificFallbackEntry } from "../../shared/fallback-chain-from-models"
import { getAgentDisplayName, getAgentConfigKey } from "../../shared/agent-display-names"
import { getAgentDisplayName, getAgentConfigKey, stripAgentListSortPrefix } from "../../shared/agent-display-names"
import { normalizeSDKResponse } from "../../shared"
import { log } from "../../shared/logger"
import { getAvailableModelsForDelegateTask } from "./available-models"
@@ -89,15 +89,18 @@ Create the work plan directly - that's your job as the planning agent.`,
const callableAgents = agents.filter((agent) => isTaskCallableAgentMode(agent.mode))
const resolvedDisplayName = getAgentDisplayName(agentToUse).replace(/^\u200B+/, "")
const normalizedAgentToUse = agentToUse.replace(/^\u200B+/, "")
const resolvedDisplayName = stripAgentListSortPrefix(getAgentDisplayName(agentToUse))
const normalizedAgentToUse = stripAgentListSortPrefix(agentToUse)
const matchedAgent = callableAgents.find(
(agent) => agent.name.toLowerCase() === normalizedAgentToUse.toLowerCase()
|| agent.name.toLowerCase() === resolvedDisplayName.toLowerCase()
(agent) => {
const normalizedListedAgentName = stripAgentListSortPrefix(agent.name)
return normalizedListedAgentName.toLowerCase() === normalizedAgentToUse.toLowerCase()
|| normalizedListedAgentName.toLowerCase() === resolvedDisplayName.toLowerCase()
}
)
if (!matchedAgent) {
const availableAgents = callableAgents
.map((a) => a.name)
.map((a) => stripAgentListSortPrefix(a.name))
.sort()
.join(", ")
return {
@@ -107,7 +110,7 @@ Create the work plan directly - that's your job as the planning agent.`,
}
}
agentToUse = matchedAgent.name
agentToUse = stripAgentListSortPrefix(matchedAgent.name)
const agentConfigKey = getAgentConfigKey(agentToUse)
const agentOverride = agentOverrides?.[agentConfigKey as keyof typeof agentOverrides]
@@ -732,4 +732,24 @@ describe("resolveSubagentExecution - agent name sanitization", () => {
expect(result.error).toBeUndefined()
expect(result.agentToUse).toBe("explore")
})
test("matches runtime agent names that include invisible sort prefixes", async () => {
//#given
readProviderModelsCacheMock.mockReturnValue({
models: {},
connected: [],
updatedAt: "2026-03-03T00:00:00.000Z",
})
const args = createBaseArgs({ subagent_type: "Sisyphus - Ultraworker" })
const executorCtx = createExecutorContext(async () => ([
{ name: "\u200BSisyphus - Ultraworker", mode: "subagent", model: "openai/gpt-5.3-codex" },
]))
//#when
const result = await resolveSubagentExecution(args, executorCtx, "oracle", "deep")
//#then
expect(result.error).toBeUndefined()
expect(result.agentToUse).toBe("Sisyphus - Ultraworker")
})
})