aiwg
Version:
Deployment tool and support utility for AI context. Copies agents, skills, commands, rules, and behaviors into the paths each AI platform reads (Claude Code, Codex, Copilot, Cursor, Warp, OpenClaw, and 6 more) so one source of truth works across 10 platfo
83 lines • 3.27 kB
TypeScript
/**
* Agent Spawn Utility
*
* Centralized utility for spawning agentic CLI tools across providers.
* Handles --dangerous, --provider, and --params passthrough flags uniformly
* across all commands that invoke an underlying agent system.
*
* Usage pattern:
* const { opts, remaining } = parseAgentSpawnFlags(ctx.args);
* const config = getProviderConfig(opts.provider);
* const spawnArgs = buildAgentArgs(prompt, opts);
* spawn(config.binary, spawnArgs, { stdio: 'inherit' });
*/
/**
* Per-provider spawn configuration.
*
* binary: CLI binary name (null = IDE-integrated, cannot be spawned)
* dangerousFlag: Flag that enables unrestricted/bypass mode for this provider
* (null = provider does not support a dangerous mode via CLI flag)
* name: Human-readable display name
* guidanceMessage: Shown instead of spawning when binary is null
*/
export interface ProviderConfig {
binary: string | null;
dangerousFlag: string | null;
name: string;
/**
* Args to prepend before the prompt when spawning.
* e.g. opencode requires ['run'] → `opencode run "<prompt>"`
* Defaults to [] (prompt is the first arg).
*/
promptPrefix?: string[];
guidanceMessage?: string;
}
export declare const PROVIDER_CONFIGS: Record<string, ProviderConfig>;
export interface AgentSpawnOptions {
/** Provider override (default: 'claude') */
provider?: string;
/** Enable dangerous/unrestricted mode via provider-specific flag */
dangerous?: boolean;
/**
* Raw args to append to the agent binary call verbatim.
* The user is responsible for correctness — no validation performed.
* Accepts a space-separated string; quoted segments are preserved.
*
* Example: --params "--output-format json --timeout 120"
*/
params?: string;
}
/**
* Extract --provider, --dangerous, and --params from an args array.
* Returns the parsed options and the remaining args with those flags removed.
*
* This is non-destructive — the original array is not modified.
*/
export declare function parseAgentSpawnFlags(args: string[]): {
opts: AgentSpawnOptions;
remaining: string[];
};
/**
* Build the final args array for spawning a provider binary.
*
* Order: [prompt, dangerous-flag?, ...raw-params]
*/
export declare function buildAgentArgs(prompt: string, opts: AgentSpawnOptions): string[];
/**
* Split a params string into individual args, respecting double/single quotes.
* "hello world" → ['hello world']
* --flag value → ['--flag', 'value']
*/
export declare function splitParams(params: string): string[];
/** Get config for a provider, falling back to claude for unknown values. */
export declare function getProviderConfig(provider: string): ProviderConfig;
/** Returns true if the provider has a CLI binary that can be spawned. */
export declare function isSpawnableProvider(provider: string): boolean;
/**
* Warn string if --dangerous was requested but the provider has no
* corresponding flag. Returns null if the combination is valid.
*/
export declare function dangerousWarning(provider: string): string | null;
/** List all spawnable provider names. */
export declare function spawnableProviders(): string[];
//# sourceMappingURL=agent-spawn.d.ts.map