47283f9238
Agent names in the config.agent object (which becomes the /agent API response) contained invisible Zero-Width Space (U+200B) characters baked in by getAgentListDisplayName(). These ZWSP prefixes were used for TUI sort ordering, but they leaked into the public API surface. Impact: any prompt_async consumer that discovered agent names via the /agent endpoint and passed them back to prompt_async without manual ZWSP stripping got silent message drops — the agent name didn't match. hy-pony's feishu-bridge integration went dark after upgrading to 3.16.0 with no error, no warning, and no indication that invisible Unicode characters in agent names were the cause. Fix: switch all four callsites from getAgentListDisplayName() (which prepends \u200B×N) to getAgentDisplayName() (clean names): - agent-key-remapper.ts: config keys → display names (was the primary injection point) - agent-priority-order.ts: CORE_AGENT_ORDER lookup (must agree with the keys emitted by the remapper) - command-config-handler.ts: command agent field normalization - tool-config-handler.ts: agent config lookup (simplified fallback chain since the primary lookup is now clean) Sort ordering is preserved by: 1. JS object insertion order from reorderAgentsByPriority() 2. The injected `order` field (1-4) added by injectOrderField() getAgentListDisplayName() is marked @deprecated with a link to #3238. AGENT_LIST_SORT_PREFIXES and stripAgentListSortPrefix() are kept for any internal callers that strip prefixes from legacy data. Closes #3238
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import { getAgentDisplayName } from "../shared/agent-display-names";
|
|
|
|
const CORE_AGENT_ORDER: ReadonlyArray<{ displayName: string; order: number }> = [
|
|
{ displayName: getAgentDisplayName("sisyphus"), order: 1 },
|
|
{ displayName: getAgentDisplayName("hephaestus"), order: 2 },
|
|
{ displayName: getAgentDisplayName("prometheus"), order: 3 },
|
|
{ displayName: getAgentDisplayName("atlas"), order: 4 },
|
|
];
|
|
|
|
function injectOrderField(
|
|
agentConfig: unknown,
|
|
order: number,
|
|
): unknown {
|
|
if (typeof agentConfig === "object" && agentConfig !== null) {
|
|
return { ...agentConfig, order };
|
|
}
|
|
return agentConfig;
|
|
}
|
|
|
|
export function reorderAgentsByPriority(
|
|
agents: Record<string, unknown>,
|
|
): Record<string, unknown> {
|
|
const ordered: Record<string, unknown> = {};
|
|
const seen = new Set<string>();
|
|
|
|
for (const { displayName, order } of CORE_AGENT_ORDER) {
|
|
if (Object.prototype.hasOwnProperty.call(agents, displayName)) {
|
|
ordered[displayName] = injectOrderField(agents[displayName], order);
|
|
seen.add(displayName);
|
|
}
|
|
}
|
|
|
|
for (const [key, value] of Object.entries(agents)) {
|
|
if (!seen.has(key)) {
|
|
ordered[key] = value;
|
|
}
|
|
}
|
|
|
|
return ordered;
|
|
}
|