/** * Shared agent spawn utilities for watch capabilities. * * Centralises `buildAgentCommand()` and `spawnWithTimeout()` so every * capability uses the same logic, respects `agentCmd` from config, * and works on Windows (shell: true when win32). * * @see https://github.com/bradygaster/squad/issues/920 * @see https://github.com/bradygaster/squad/issues/923 */ import type { WatchContext } from './types.js'; /** True when running on Windows — used to gate `shell: true`. */ export declare const IS_WINDOWS: boolean; /** * Escape an argument for safe use with cmd.exe when `shell: true`. * * Node's `execFile` with `shell: true` on Windows concatenates args with * spaces but does NOT quote them (Node DEP0190). This means multi-word * prompts get split by cmd.exe and the child process receives garbage argv. * * This function wraps any arg containing spaces, quotes, or cmd.exe * metacharacters in double quotes with internal double quotes escaped. * * On non-Windows (shell: false path), args are passed directly to execvp * without shell interpretation, so no escaping is needed. */ export declare function escapeForCmd(arg: string): string; /** * Escape an array of args for cmd.exe shell invocation. * Only applies on Windows — returns args unchanged on other platforms. */ export declare function escapeArgs(args: string[]): string[]; /** * Detect which copilot CLI is available at runtime. * * Tries standalone `copilot` first (modern default). If that fails, * falls back to `gh copilot` (legacy). The result is cached for the * lifetime of the process so we only shell-out once. * * @returns `{ cmd, cmdPrefix }` — e.g. `{ cmd: 'copilot', cmdPrefix: [] }` * or `{ cmd: 'gh', cmdPrefix: ['copilot'] }`. */ export declare function resolveCopilotCmd(): { cmd: string; cmdPrefix: string[]; }; /** * Reset the cached copilot detection. Exported for testing only. * @internal */ export declare function _resetCopilotDetection(): void; export declare function buildCustomAgentCommand(agentCmd: string, prompt: string): { cmd: string; args: string[]; }; /** * Build the command + args array for an agent invocation. * * Resolution order: * 1. `context.agentCmd` (explicit override from config / CLI) * 2. Runtime detection via `resolveCopilotCmd()`: * - standalone `copilot` if available on PATH * - `gh copilot` as fallback */ export declare function buildAgentCommand(prompt: string, context: WatchContext): { cmd: string; args: string[]; }; /** * Build the command + args array for a Copilot session, with the * `--additional-mcp-config`/`--yolo` workaround injected so `squad_state_*` * MCP tools register (see {@link withAdditionalMcpConfig}). * * Unlike {@link buildAgentCommand}, this always defaults to the bare * `copilot` binary rather than probing for a `gh copilot` fallback — used * by capabilities that spawn a full agent session against the repo * (execute, wave-dispatch). */ export declare function buildCopilotCommand(prompt: string, context: WatchContext): { cmd: string; args: string[]; }; /** * Spawn an agent command with a timeout. * * Uses `shell: true` on Windows so that `.cmd`/`.bat` wrappers and * PATH resolution work correctly. Args are escaped via `escapeArgs()` * to prevent Node DEP0190 and cmd.exe metacharacter injection. */ export declare function spawnWithTimeout(cmd: string, args: string[], cwd: string, timeoutMs: number): Promise; /** * Spawn an agent command with a timeout, resolving with success/error * instead of rejecting. Used by execute and wave-dispatch where the * caller wants to handle failure without try/catch. * * Pass `pidTracking` when the caller wants the child process registered * with a {@link WatchContext.pidTracker} for cleanup on exit/crash (e.g. * the `execute` capability, which spawns long-running sessions). */ export declare function spawnAgent(cmd: string, args: string[], cwd: string, timeoutMs: number, pidTracking?: { tracker: NonNullable; label: string; }): Promise<{ success: boolean; error?: string; }>; //# sourceMappingURL=agent-spawn.d.ts.map