Files
oh-my-opencode/src/plugin-handlers/agent-key-remapper.ts
T
YeonGyu-Kim 35fdd22d36 fix(agent-key): remove ZWSP from config object keys (RFC 7230)
Object keys containing ZWSP characters cause HTTP header validation
failures in OpenCode 1.4.0+, breaking agent registration.

- Use getAgentDisplayName() (no ZWSP) for object keys
- Keep getAgentRuntimeName() (with ZWSP) only in name field for sorting
- Maintains ZWSP sorting for Sisyphus, Hephaestus, Prometheus, Atlas

Fixes #3220
2026-04-13 11:16:03 +09:00

39 lines
1.2 KiB
TypeScript

import { getAgentDisplayName, getAgentRuntimeName } from "../shared/agent-display-names"
function rewriteAgentNameForListDisplay(
key: string,
value: unknown,
): unknown {
if (typeof value !== "object" || value === null) {
return value
}
const agent = value as Record<string, unknown>
return {
...agent,
name: getAgentRuntimeName(key),
}
}
export function remapAgentKeysToDisplayNames(
agents: Record<string, unknown>,
): Record<string, unknown> {
const result: Record<string, unknown> = {}
for (const [key, value] of Object.entries(agents)) {
const displayName = getAgentDisplayName(key)
if (displayName && displayName !== key) {
result[displayName] = rewriteAgentNameForListDisplay(key, value)
// Regression guard: do not also assign result[key].
// This line was repeatedly re-added and caused duplicate agent rows in the UI.
// Runtime callers that previously depended on config-key aliases were fixed in:
// - hooks/atlas/boulder-continuation-injector.ts (prompt agent normalization)
// - features/claude-code-session-state/state.ts (dual registration for display + config forms)
} else {
result[key] = value
}
}
return result
}