fix(runtime-fallback): sort agent names by length to fix hyphenated agent detection

The \b word boundary regex treats '-' as a boundary, causing
'sisyphus-junior-session-123' to incorrectly match 'sisyphus'
instead of 'sisyphus-junior'.

Sorting agent names by length (descending) ensures longer names
are matched first, fixing the hyphenated agent detection issue.

Fixes cubic-dev-ai review issue #8
This commit is contained in:
youming.tang 2026-02-10 14:37:23 +09:00 committed by YeonGyu-Kim
parent d9072b4a98
commit 708b9ce9ff

View File

@ -131,7 +131,10 @@ function getFallbackModelsForSession(
"multimodal-looker",
]
const agentPattern = new RegExp(
`(?:^|[^a-zA-Z0-9_-])(${AGENT_NAMES.map((a) => a.replace(/-/g, "\\-")).join("|")})(?:$|[^a-zA-Z0-9_-])`,
`(?:^|[^a-zA-Z0-9_-])(${AGENT_NAMES
.sort((a, b) => b.length - a.length)
.map((a) => a.replace(/-/g, "\\-"))
.join("|")})(?:$|[^a-zA-Z0-9_-])`,
"i",
)
const sessionAgentMatch = sessionID.match(agentPattern)