refactor(agent-display): centralize name normalization resolution

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-04-11 22:28:58 +09:00
parent f5dc1c0eba
commit e9b6bba1d7
2 changed files with 24 additions and 32 deletions
+9 -1
View File
@@ -217,6 +217,10 @@ describe("normalizeAgentForPrompt", () => {
it("removes zero-width characters before returning canonical names", () => { it("removes zero-width characters before returning canonical names", () => {
expect(normalizeAgentForPrompt("Sisyphus\u200B - Ultraworker")).toBe("Sisyphus - Ultraworker") expect(normalizeAgentForPrompt("Sisyphus\u200B - Ultraworker")).toBe("Sisyphus - Ultraworker")
}) })
it("converts legacy parenthesized names to canonical display names", () => {
expect(normalizeAgentForPrompt("Atlas (Plan Executor)")).toBe("Atlas - Plan Executor")
})
}) })
describe("normalizeAgentForPromptKey", () => { describe("normalizeAgentForPromptKey", () => {
@@ -224,6 +228,10 @@ describe("normalizeAgentForPromptKey", () => {
expect(normalizeAgentForPromptKey("Sisyphus (Ultraworker)")).toBe("sisyphus") expect(normalizeAgentForPromptKey("Sisyphus (Ultraworker)")).toBe("sisyphus")
}) })
it("strips UI ordering prefixes before returning config keys", () => {
expect(normalizeAgentForPromptKey(getAgentListDisplayName("atlas"))).toBe("atlas")
})
it("preserves custom agents", () => { it("preserves custom agents", () => {
expect(normalizeAgentForPromptKey("MyCustomAgent")).toBe("MyCustomAgent") expect(normalizeAgentForPromptKey("MyCustomAgent")).toBe("MyCustomAgent")
}) })
@@ -259,7 +267,7 @@ describe("AGENT_DISPLAY_NAMES", () => {
const httpHeaderUnsafe = /[()]/ const httpHeaderUnsafe = /[()]/
// when checking each display name // when checking each display name
for (const [key, displayName] of Object.entries(AGENT_DISPLAY_NAMES)) { for (const [, displayName] of Object.entries(AGENT_DISPLAY_NAMES)) {
// then none should contain parentheses // then none should contain parentheses
expect(httpHeaderUnsafe.test(displayName)).toBe(false) expect(httpHeaderUnsafe.test(displayName)).toBe(false)
} }
+15 -31
View File
@@ -94,18 +94,23 @@ const LEGACY_DISPLAY_NAMES: Record<string, string> = {
"athena-junior (council)": "athena-junior", "athena-junior (council)": "athena-junior",
} }
/** function resolveKnownAgentConfigKey(agentName: string): string | undefined {
* Resolve an agent name (display name or config key) to its lowercase config key.
* "Atlas - Plan Executor" -> "atlas", "Atlas (Plan Executor)" -> "atlas", "atlas" -> "atlas"
*/
export function getAgentConfigKey(agentName: string): string {
const lower = stripAgentListSortPrefix(agentName).trim().toLowerCase() const lower = stripAgentListSortPrefix(agentName).trim().toLowerCase()
const reversed = REVERSE_DISPLAY_NAMES[lower] const reversed = REVERSE_DISPLAY_NAMES[lower]
if (reversed !== undefined) return reversed if (reversed !== undefined) return reversed
const legacy = LEGACY_DISPLAY_NAMES[lower] const legacy = LEGACY_DISPLAY_NAMES[lower]
if (legacy !== undefined) return legacy if (legacy !== undefined) return legacy
if (AGENT_DISPLAY_NAMES[lower] !== undefined) return lower if (AGENT_DISPLAY_NAMES[lower] !== undefined) return lower
return lower return undefined
}
/**
* Resolve an agent name (display name or config key) to its lowercase config key.
* "Atlas - Plan Executor" -> "atlas", "Atlas (Plan Executor)" -> "atlas", "atlas" -> "atlas"
*/
export function getAgentConfigKey(agentName: string): string {
const lower = stripAgentListSortPrefix(agentName).trim().toLowerCase()
return resolveKnownAgentConfigKey(agentName) ?? lower
} }
/** /**
@@ -124,17 +129,9 @@ export function normalizeAgentForPrompt(agentName: string | undefined): string |
return undefined return undefined
} }
const lower = trimmed.toLowerCase() const configKey = resolveKnownAgentConfigKey(trimmed)
const reversed = REVERSE_DISPLAY_NAMES[lower] if (configKey !== undefined) {
if (reversed !== undefined) { return AGENT_DISPLAY_NAMES[configKey] ?? trimmed
return AGENT_DISPLAY_NAMES[reversed] ?? trimmed
}
const legacy = LEGACY_DISPLAY_NAMES[lower]
if (legacy !== undefined) {
return AGENT_DISPLAY_NAMES[legacy] ?? trimmed
}
if (AGENT_DISPLAY_NAMES[lower] !== undefined) {
return AGENT_DISPLAY_NAMES[lower]
} }
return trimmed return trimmed
@@ -150,18 +147,5 @@ export function normalizeAgentForPromptKey(agentName: string | undefined): strin
return undefined return undefined
} }
const lower = trimmed.toLowerCase() return resolveKnownAgentConfigKey(trimmed) ?? trimmed
const reversed = REVERSE_DISPLAY_NAMES[lower]
if (reversed !== undefined) {
return reversed
}
const legacy = LEGACY_DISPLAY_NAMES[lower]
if (legacy !== undefined) {
return legacy
}
if (AGENT_DISPLAY_NAMES[lower] !== undefined) {
return lower
}
return trimmed
} }