(opencodeConfig: OpenCodeConfig, agentName: string)
| 206 | } |
| 207 | |
| 208 | function resolveAgentConfigKey(opencodeConfig: OpenCodeConfig, agentName: string): string { |
| 209 | opencodeConfig.agent ??= {}; |
| 210 | |
| 211 | if (Object.prototype.hasOwnProperty.call(opencodeConfig.agent, agentName)) { |
| 212 | return agentName; |
| 213 | } |
| 214 | |
| 215 | const normalizedTarget = normalizeAgentLookupKey(agentName); |
| 216 | for (const existingKey of Object.keys(opencodeConfig.agent)) { |
| 217 | const normalizedExisting = normalizeAgentLookupKey(existingKey); |
| 218 | if (normalizedExisting === normalizedTarget) { |
| 219 | return existingKey; |
| 220 | } |
| 221 | if (normalizedExisting.startsWith(`${normalizedTarget} -`) || normalizedExisting.startsWith(`${normalizedTarget} (`)) { |
| 222 | return existingKey; |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | return agentName; |
| 227 | } |
| 228 | |
| 229 | function ensureAgentConfig(opencodeConfig: OpenCodeConfig, agentName: string): AgentConfig { |
| 230 | opencodeConfig.agent ??= {}; |
no test coverage detected