Files
orca/src/shared/agent-command-plan.ts
T
Neilandcarlosbaraza 15baf86660 fix(agents): honor environment prefixes in generation commands (#22427)
* fix(agents): preserve environment prefixes in generation commands

Adapted from the proposal by @carlosbaraza.

Co-authored-by: carlosbaraza <carlosbaraza@users.noreply.github.com>

* test(agents): respect Windows environment key normalization

---------

Co-authored-by: carlosbaraza <carlosbaraza@users.noreply.github.com>
2026-09-25 20:50:39 -07:00

30 lines
1.0 KiB
TypeScript

import { extractLeadingEnvAssignments } from './command-environment'
import {
tokenizeCustomCommandTemplate,
type CommandTemplateBackslash
} from './commit-message-prompt'
export function planAgentBinary(
defaultBinary: string,
commandOverride: string | undefined,
backslash: CommandTemplateBackslash = 'escape'
):
| { ok: true; binary: string; prefixArgs: string[]; env?: Record<string, string> }
| { ok: false; error: string } {
const command = commandOverride?.trim()
if (!command) {
return { ok: true, binary: defaultBinary, prefixArgs: [] }
}
const tokenized = tokenizeCustomCommandTemplate(command, backslash)
if (!tokenized.ok) {
return { ok: false, error: `Agent command override is invalid: ${tokenized.error}` }
}
const { env, rest } = extractLeadingEnvAssignments(tokenized.tokens)
const [binary, ...prefixArgs] = rest
if (!binary) {
return { ok: false, error: 'Agent command override must start with a binary name.' }
}
return { ok: true, binary, prefixArgs, ...(env ? { env } : {}) }
}