import { SpawnOptions } from "child_process"; /** * Shared abortability helpers for stdlib JS implementations whose * underlying API doesn't natively support `AbortSignal`. Used by * `shell.ts`, `speech.ts`, and `system.ts` to (1) thread cancellation * through `child_process.spawn` and `execFile`, and (2) cancel a * `setTimeout`-based sleep on abort. * * Why a separate file: each call site that needs cancellation has to * (a) listen to the signal, (b) tear down the in-flight resource, * (c) translate the resulting "killed by signal" outcome into an * `AgencyCancelledError` so `__tryCall` re-throws it. Doing that * inline once per caller is bug-prone (forget any of the three and * cancellation silently breaks for that function). Centralizing them * keeps the contract identical across the stdlib. */ export type SpawnResult = { stdout: string; stderr: string; exitCode: number; }; export type AbortableSpawnOptions = SpawnOptions & { input?: string; /** Time limit in ms. 0 or undefined = no time limit. */ timeout?: number; /** When set, an abort fires the same teardown path as the timeout * and the returned promise rejects with `AgencyCancelledError`. */ signal?: AbortSignal; /** Max stdout to buffer, in UTF-8 bytes. Once exceeded the child is * killed, stdout is marked truncated (a note is appended), and the * call resolves successfully with the partial output. 0/undefined = * unbounded. Keeps auto-approved reads (e.g. a huge `git diff`) from * buffering unbounded memory. */ maxOutputBytes?: number; }; /** * `child_process.spawn` accepts a `signal` option natively as of * Node 16, but that path only kills the child with SIGTERM and * surfaces an `AbortError` on the child's emitter — it doesn't * give us the "translate to `AgencyCancelledError` and reject the * outer promise" behavior we want. So we register our own listener * and call `child.kill()` explicitly, which is the same code path * the existing timeout uses. */ export declare function abortableSpawn(command: string, args: string[], options: AbortableSpawnOptions): Promise; /** * Spawn a child that we don't need to read output from, with the * same abort-on-signal behavior. Used for `_speak` (the `say` * command), `_screenshot`, `_openUrl`, etc. — anything where we * just want to wait for the child to exit, getting an * `AgencyCancelledError` if the run is cancelled. * * Distinct from `abortableSpawn` so callers that don't want stdout * piping (some of these run for minutes streaming audio to the * speakers and would buffer indefinitely) get the right behavior. */ export declare function abortableExec(command: string, args: string[], signal: AbortSignal | undefined): Promise; /** * Sleep that wakes up early on abort. The default `setTimeout`-based * sleep ignores cancellation entirely; a 10-minute `sleep(10m)` after * Ctrl-C would just sit there for ten minutes. Translates to * `AgencyCancelledError` so `__tryCall` re-throws it. */ export declare function abortableSleep(ms: number, signal: AbortSignal | undefined): Promise;