fix(agent-config): normalize agent names before builtin override filtering to prevent alias bypass

This commit is contained in:
YeonGyu-Kim
2026-03-13 10:55:51 +09:00
parent 9bce6314b1
commit 0015dd88af
3 changed files with 256 additions and 17 deletions
@@ -0,0 +1,29 @@
const PARENTHETICAL_SUFFIX_PATTERN = /\s*(\([^)]*\)\s*)+$/u
export function normalizeProtectedAgentName(agentName: string): string {
return agentName.trim().toLowerCase().replace(PARENTHETICAL_SUFFIX_PATTERN, "").trim()
}
export function createProtectedAgentNameSet(agentNames: Iterable<string>): Set<string> {
const protectedAgentNames = new Set<string>()
for (const agentName of agentNames) {
const normalizedAgentName = normalizeProtectedAgentName(agentName)
if (normalizedAgentName.length === 0) continue
protectedAgentNames.add(normalizedAgentName)
}
return protectedAgentNames
}
export function filterProtectedAgentOverrides<TAgent>(
agents: Record<string, TAgent>,
protectedAgentNames: ReadonlySet<string>,
): Record<string, TAgent> {
return Object.fromEntries(
Object.entries(agents).filter(([agentName]) => {
return !protectedAgentNames.has(normalizeProtectedAgentName(agentName))
}),
)
}