/** * `agent-relay new NAME CLI [args...] [--attach [--mode …] [--ephemeral]]` * — spawn verb with optional session attach. * * Name is the first positional argument, matching every other verb in * this taxonomy (`drive Alice`, `view Alice`, `passthrough Alice`, `rm Alice`). * * Without `--attach`, this is spawn-only: POST `/api/spawn` and exit. * The agent keeps running headless under the broker; the user attaches * later with `view` / `drive` / `passthrough`. * * With `--attach`, the command composes spawn + a session verb in one * shot. Defaults to `--mode drive` (the safer queue-and-flush default * for the spawn-and-watch case). `--ephemeral` registers a teardown * that calls `DELETE /api/spawned/{name}` on client exit (clean * detach, SIGINT, SIGTERM, abnormal WS close) so the agent dies with * the terminal — useful for ad-hoc experiments. * * The composition uses `runSpawnAndAttach` from * `src/cli/lib/spawn-and-attach.ts`. That same helper is what the * verbless `-n` alias dispatcher in `bootstrap.ts` calls — single code * path, byte-equivalent alias. * * The longer-form `spawn` command in `agent-management.ts` layers broker * autostart and more flags on top of the same SDK client; `new` is the * lighter "I already have a broker, just spawn this" entry point. */ import { Command } from 'commander'; import { type BrokerConnection } from '../lib/broker-connection.js'; import { type AttachChildDependencies } from '../lib/spawn-and-attach.js'; type ExitFn = (code: number) => never; export interface NewDependencies { readConnectionFile: (stateDir: string) => unknown; getDefaultStateDir: () => string; env: NodeJS.ProcessEnv; fetch: typeof globalThis.fetch; log: (...args: unknown[]) => void; error: (...args: unknown[]) => void; exit: ExitFn; } /** Body shape for `POST /api/spawn`. Mirrors the Rust broker's `listen_api_spawn`. */ export interface SpawnRequestBody { name: string; cli: string; args?: string[]; task?: string; channels?: string[]; cwd?: string; team?: string; model?: string; } /** Outcome of `spawnAgent` — used by `new` and by the spawn-and-attach helper. */ export interface SpawnResult { ok: boolean; status: number; message?: string; /** The parsed `{ name }` etc. body the broker returned, when it returned one. */ body?: Record; } /** * Spawn through the SDK client against the resolved broker. Exported so * the spawn-and-attach helper (and any other caller) can use the same * transport / error mapping. */ export declare function spawnAgent(connection: BrokerConnection, body: SpawnRequestBody, fetchFn: typeof globalThis.fetch): Promise; /** Options the `new` command accepts on the CLI. */ export interface NewOptions { brokerUrl?: string; apiKey?: string; stateDir?: string; task?: string; channels?: string; cwd?: string; team?: string; model?: string; attach?: boolean; mode?: string; ephemeral?: boolean; } /** * Run the headless-spawn path. Used when `--attach` is NOT set. * Resolves with the exit code the CLI should propagate. * * `name` and `cli` are positional commander arguments — both required, * commander surfaces the missing-argument error before we run. */ export declare function runNew(name: string | undefined, cli: string | undefined, args: string[], options: NewOptions, deps: NewDependencies): Promise; /** * Run the spawn-and-attach path. Used when `--attach` IS set. * Validates `--mode` / `--ephemeral` and hands off to the shared * `runSpawnAndAttach` helper. Resolves with the exit code the CLI * should propagate. * * Separate function (rather than baking the branch into the action * closure) so it can be tested in isolation and so the failure modes * stay legible. */ export declare function runNewWithAttach(name: string | undefined, cli: string | undefined, args: string[], options: NewOptions, childDeps: AttachChildDependencies): Promise; /** * Register `agent-relay new NAME CLI [args...]` on the supplied * commander program. Name and CLI are positional, matching every other * verb in the attach-style taxonomy (`drive`, `view`, `passthrough`, `rm`). * When `--attach` is set, the action composes spawn + session via * `runSpawnAndAttach`; otherwise it's spawn-only. * * `attachChildDeps` is the bundle of child-module deps used in * `--attach` mode; tests pass a stub bundle here while production * lets `buildDefaultAttachChildDeps()` provide the real ones. */ export declare function registerNewCommands(program: Command, overrides?: Partial, attachChildDeps?: AttachChildDependencies): void; export {}; //# sourceMappingURL=new.d.ts.map