fix(todo-continuation): normalize agent name to config key before promptAsync (#3149)
The todo-continuation-enforcer was passing raw agent names (which could be display names like 'Sisyphus (Ultraworker)') to promptAsync. These names contain spaces/parentheses that violate HTTP header specs, causing the x-opencode-agent-name header validation to fail with 'unknown error' toast. Added normalizeAgentForPromptKey() that converts display names to config keys (e.g., 'Sisyphus (Ultraworker)' -> 'sisyphus') before API calls. TDD: Added regression test that verifies config key is sent to promptAsync.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from "bun:test"
|
||||
import { AGENT_DISPLAY_NAMES, getAgentConfigKey, getAgentDisplayName, getAgentListDisplayName, normalizeAgentForPrompt } from "./agent-display-names"
|
||||
import { AGENT_DISPLAY_NAMES, getAgentConfigKey, getAgentDisplayName, getAgentListDisplayName, normalizeAgentForPrompt, normalizeAgentForPromptKey } from "./agent-display-names"
|
||||
|
||||
describe("getAgentDisplayName", () => {
|
||||
it("returns display name for lowercase config key (new format)", () => {
|
||||
@@ -196,6 +196,16 @@ describe("normalizeAgentForPrompt", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("normalizeAgentForPromptKey", () => {
|
||||
it("converts built-in display names to config keys", () => {
|
||||
expect(normalizeAgentForPromptKey("Sisyphus (Ultraworker)")).toBe("sisyphus")
|
||||
})
|
||||
|
||||
it("preserves custom agents", () => {
|
||||
expect(normalizeAgentForPromptKey("MyCustomAgent")).toBe("MyCustomAgent")
|
||||
})
|
||||
})
|
||||
|
||||
describe("AGENT_DISPLAY_NAMES", () => {
|
||||
it("contains all expected agent mappings", () => {
|
||||
// given expected mappings
|
||||
|
||||
@@ -98,3 +98,25 @@ export function normalizeAgentForPrompt(agentName: string | undefined): string |
|
||||
|
||||
return trimmed
|
||||
}
|
||||
|
||||
export function normalizeAgentForPromptKey(agentName: string | undefined): string | undefined {
|
||||
if (typeof agentName !== "string") {
|
||||
return undefined
|
||||
}
|
||||
|
||||
const trimmed = stripAgentListSortPrefix(agentName.trim())
|
||||
if (!trimmed) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
const lower = trimmed.toLowerCase()
|
||||
const reversed = REVERSE_DISPLAY_NAMES[lower]
|
||||
if (reversed !== undefined) {
|
||||
return reversed
|
||||
}
|
||||
if (AGENT_DISPLAY_NAMES[lower] !== undefined) {
|
||||
return lower
|
||||
}
|
||||
|
||||
return trimmed
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user