mirror of
https://github.com/stablyai/orca.git
synced 2026-11-01 01:27:35 +00:00
* fix(terminal): preserve preparation and discovery for delayed agent launches * refactor(agents): centralize launch intent recognition * refactor(agents): keep launch intent in one module apart from process recognition Move recognizeAgentLaunchCommand next to the sleep-prefix scanner so the strict process-table matcher is untouched, name the module away from the agent-launch funnel files, share one executable-name normalizer, and colocate the preparation tests with their modules.
57 lines
1.8 KiB
TypeScript
57 lines
1.8 KiB
TypeScript
import { recognizeAgentLaunchCommand } from './agent-command-line-intent'
|
|
import { gitCredentialPromptGuardEnv } from './git-credential-prompt-env'
|
|
|
|
const GIT_CONFIG_PROTOCOL_KEY_RE = /^GIT_CONFIG_(?:COUNT|KEY_\d+|VALUE_\d+)$/
|
|
|
|
export const TERMINAL_GIT_CREDENTIAL_GUARD_POLICY_ENV =
|
|
'ORCA_INTERNAL_TERMINAL_GIT_CREDENTIAL_GUARD_POLICY'
|
|
|
|
/** Disable credential UI only for recognized agents and marked automation. */
|
|
export function applyTerminalGitCredentialPromptGuard(
|
|
env: Record<string, string>,
|
|
opts: {
|
|
launchCommand?: string | null
|
|
isUnattended?: boolean
|
|
platform?: NodeJS.Platform
|
|
/** A detached host appends indexed config after its authoritative env merge. */
|
|
deferGitConfigGuardToHost?: boolean
|
|
}
|
|
): boolean {
|
|
const explicitlyGuarded = env[TERMINAL_GIT_CREDENTIAL_GUARD_POLICY_ENV] === 'guard'
|
|
delete env[TERMINAL_GIT_CREDENTIAL_GUARD_POLICY_ENV]
|
|
|
|
const shouldGuard =
|
|
opts.isUnattended === true ||
|
|
Boolean(
|
|
recognizeAgentLaunchCommand(opts.launchCommand, {
|
|
includeHeadlessOneShot: true
|
|
})
|
|
)
|
|
if (!explicitlyGuarded && !shouldGuard) {
|
|
return false
|
|
}
|
|
|
|
const guarded = gitCredentialPromptGuardEnv(env, opts.platform ?? process.platform)
|
|
if (!opts.deferGitConfigGuardToHost) {
|
|
Object.assign(env, guarded)
|
|
return true
|
|
}
|
|
|
|
// Why: the daemon must append indexed config after merging its own inherited
|
|
// environment; the sparse wire carries only the guard decision and scalars.
|
|
env[TERMINAL_GIT_CREDENTIAL_GUARD_POLICY_ENV] = 'guard'
|
|
for (const [key, value] of Object.entries(guarded)) {
|
|
if (typeof value !== 'string' || GIT_CONFIG_PROTOCOL_KEY_RE.test(key)) {
|
|
continue
|
|
}
|
|
if (key === 'WSLENV') {
|
|
continue
|
|
}
|
|
if ((key === 'GIT_ASKPASS' || key === 'SSH_ASKPASS') && !Object.hasOwn(env, key)) {
|
|
continue
|
|
}
|
|
env[key] = value
|
|
}
|
|
return true
|
|
}
|