Fix invisible characters in agent names
This commit is contained in:
@@ -186,6 +186,11 @@ describe("getAgentConfigKey", () => {
|
||||
it("resolves atlas even when the UI ordering prefix is present", () => {
|
||||
expect(getAgentConfigKey(getAgentListDisplayName("atlas"))).toBe("atlas")
|
||||
})
|
||||
|
||||
it("resolves display names even when zero-width characters are embedded", () => {
|
||||
expect(getAgentConfigKey("Sisyphus\u200B - Ultraworker")).toBe("sisyphus")
|
||||
expect(getAgentConfigKey("\uFEFFAtlas - Plan Executor")).toBe("atlas")
|
||||
})
|
||||
})
|
||||
|
||||
describe("getAgentListDisplayName", () => {
|
||||
@@ -208,6 +213,10 @@ describe("normalizeAgentForPrompt", () => {
|
||||
expect(normalizeAgentForPrompt(getAgentListDisplayName("prometheus"))).toBe("Prometheus - Plan Builder")
|
||||
expect(normalizeAgentForPrompt(getAgentListDisplayName("atlas"))).toBe("Atlas - Plan Executor")
|
||||
})
|
||||
|
||||
it("removes zero-width characters before returning canonical names", () => {
|
||||
expect(normalizeAgentForPrompt("Sisyphus\u200B - Ultraworker")).toBe("Sisyphus - Ultraworker")
|
||||
})
|
||||
})
|
||||
|
||||
describe("normalizeAgentForPromptKey", () => {
|
||||
|
||||
@@ -33,8 +33,14 @@ const AGENT_LIST_SORT_PREFIXES: Record<string, string> = {
|
||||
atlas: "\u200B\u200B\u200B\u200B",
|
||||
}
|
||||
|
||||
const ZERO_WIDTH_AGENT_CHARACTERS_REGEX = /[\u200B\u200C\u200D\uFEFF]/g
|
||||
|
||||
export function stripInvisibleAgentCharacters(agentName: string): string {
|
||||
return agentName.replace(ZERO_WIDTH_AGENT_CHARACTERS_REGEX, "")
|
||||
}
|
||||
|
||||
export function stripAgentListSortPrefix(agentName: string): string {
|
||||
return agentName.replace(/^\u200B+/, "")
|
||||
return stripInvisibleAgentCharacters(agentName)
|
||||
}
|
||||
|
||||
export function getAgentRuntimeName(configKey: string): string {
|
||||
@@ -97,7 +103,7 @@ const LEGACY_DISPLAY_NAMES: Record<string, string> = {
|
||||
* "Atlas - Plan Executor" -> "atlas", "Atlas (Plan Executor)" -> "atlas", "atlas" -> "atlas"
|
||||
*/
|
||||
export function getAgentConfigKey(agentName: string): string {
|
||||
const lower = stripAgentListSortPrefix(agentName).toLowerCase()
|
||||
const lower = stripAgentListSortPrefix(agentName).trim().toLowerCase()
|
||||
const reversed = REVERSE_DISPLAY_NAMES[lower]
|
||||
if (reversed !== undefined) return reversed
|
||||
const legacy = LEGACY_DISPLAY_NAMES[lower]
|
||||
@@ -117,7 +123,7 @@ export function normalizeAgentForPrompt(agentName: string | undefined): string |
|
||||
return undefined
|
||||
}
|
||||
|
||||
const trimmed = stripAgentListSortPrefix(agentName.trim())
|
||||
const trimmed = stripAgentListSortPrefix(agentName).trim()
|
||||
if (!trimmed) {
|
||||
return undefined
|
||||
}
|
||||
@@ -143,7 +149,7 @@ export function normalizeAgentForPromptKey(agentName: string | undefined): strin
|
||||
return undefined
|
||||
}
|
||||
|
||||
const trimmed = stripAgentListSortPrefix(agentName.trim())
|
||||
const trimmed = stripAgentListSortPrefix(agentName).trim()
|
||||
if (!trimmed) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user