mirror of
https://github.com/stablyai/orca.git
synced 2026-10-08 00:02:38 +00:00
Consolidate override detection and removal into removeAgentArgs. Previously catalogs used agentArgsOverride to detect conflicts and removeAgentArgs to strip them; now removeAgentArgs handles both by returning stripped tokens. This eliminates redundancy and makes the intent clearer. Enhance removeAgentArgOption with optional value filtering to support selective removal for complex cases like Codex config overrides.
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
function matchesOption(token: string, aliases: readonly string[]): boolean {
|
|
return aliases.some(
|
|
(alias) =>
|
|
token === alias ||
|
|
token.startsWith(`${alias}=`) ||
|
|
(alias.startsWith('-') &&
|
|
!alias.startsWith('--') &&
|
|
token.startsWith(alias) &&
|
|
token.length > alias.length)
|
|
)
|
|
}
|
|
|
|
export function findOptionOccurrence(
|
|
tokens: readonly string[],
|
|
aliases: readonly string[],
|
|
stopAtTerminator: boolean
|
|
): { index: number; consumed: number; value?: string } | null {
|
|
for (let index = 0; index < tokens.length; index += 1) {
|
|
const token = tokens[index]
|
|
if (stopAtTerminator && token === '--') {
|
|
break
|
|
}
|
|
if (!matchesOption(token, aliases)) {
|
|
continue
|
|
}
|
|
const nextToken = tokens[index + 1]
|
|
const consumesNext =
|
|
aliases.includes(token) && nextToken !== undefined && !nextToken.startsWith('-')
|
|
const alias = aliases.find((name) => matchesOption(token, [name]))
|
|
const value = consumesNext
|
|
? nextToken
|
|
: alias && token !== alias
|
|
? token.slice(alias.length + (token[alias.length] === '=' ? 1 : 0))
|
|
: undefined
|
|
return { index, consumed: consumesNext ? 2 : 1, value }
|
|
}
|
|
return null
|
|
}
|