/** * `startCommand`: detach a transport the package does not own. * * `startDownload` IS curl — it needs a URL, and it verifies and renames the * bytes itself. A tool like `ipatool` has none of that to offer: it negotiates * its own auth, never exposes a URL, picks its own filenames and streams the * bytes itself. What it still needs is everything else: surviving the window * closing, a status file to watch, `(pid, startTime)` identity, group cancel, * leases, reconciliation and the finish notification. All of that is * transport-agnostic, so this reuses it, and the status it writes is a * `CommandStatus` in the same directory as every other download. * * What it deliberately does NOT do: * * - Verify size. Success is the exit code. The command owns the bytes, and the * sizes a caller can get (Apple's installed size, for `ipatool`) do not * match the archive. * - Resume. A foreign command's resume semantics are its own. * - Keep secrets out of argv. It cannot: the command's interface is someone * else's. See `argv`. */ import type { CommandProgress } from "./command-runner"; import { type FileMatch } from "./command-files"; import { type DownloadTicket, type StartDownloadOptions } from "./detach"; export interface StartCommandOptions { /** Stable identifier. Defaults to a random UUID. */ id?: string; /** * Executable and arguments. Spawned as-is, with no shell; a bare name is * looked up on the `PATH` of the command's environment (the runner's, with * `env` merged over it). * * **Everything here is visible to every process on the machine** through * `ps`. Never put a credential in argv: pass it through `env`, or through a * `0600` file the command reads. (`ipatool` is fine: its argv carries a * bundle id and a directory, and its session comes from the Keychain.) */ argv: [string, ...string[]]; cwd?: string; /** * Merged over the runner's environment. Travels to the runner over its stdin * pipe like the rest of the payload, so the package never puts a secret here * in argv or a file. What the command itself prints is captured verbatim to * the logs, though, so a command that echoes its token puts it on disk. */ env?: Record; /** Display name for the status and the notification. Defaults to the executable's name. */ filename?: string; /** * Where progress comes from, since a foreign command has no curl meter. * Declarative because it is evaluated inside the detached runner, a separate * process — a callback cannot cross that boundary. * * `watchFiles` reads the sizes of the matching files every 500ms. The * displayed `bytesDownloaded` is the largest file seen; `lastByteAt` * advances whenever any matching file changes. A file left by an earlier * run counts too, so delete stale partials before starting. * * `stdoutPattern` is matched against each line of stdout, and must have a * named group `bytes` and may have one named `total`. */ progress?: CommandProgress; /** Exit codes treated as success. Defaults to `[0]`. */ successExitCodes?: number[]; /** * How the runner learns the final path after a successful exit, for a * command that does not print it. A heuristic: the newest matching file * modified since this run began. Prefer reading the path from `stdoutPath` * when the command prints it. * * When nothing matches, the status still completes, with `outputPath` unset. */ resolveOutput?: { kind: "newestMatch"; dir: string; namePrefix: string; suffix: string; }; /** * Files to delete when the run fails or is canceled. Never on success: the * finished file usually matches the same prefix. Deleted only once the * command in `argv[0]` has exited, so it cannot recreate them; a descendant * it starts is not tracked. Best effort when the runner itself is killed: * `killDownload` and `reconcile` delete them only if the whole process group * is already gone, so delete stale partials before starting too. */ cleanupOnFailure?: FileMatch[]; /** * Fail as `stalled` when no matching file (or no `stdoutPattern` byte count) * has changed for this long. Off by default, and requires `progress`: * without one there is nothing to measure. */ stallSeconds?: number; /** * Fail as `timeout` after this long, whatever the progress. Off by default. * Machine sleep counts against it, so prefer `stallSeconds`. */ maxSeconds?: number; /** Opaque payload echoed into the status file. NEVER put a credential here. */ meta?: Record; statusDir?: string; notifyOnFinish?: StartDownloadOptions["notifyOnFinish"]; } /** * Spawn a detached command. Resolves once the runner has written its first * status, or after 3 seconds without one, once a `starting` status has been * seeded for it (the same contract as `startDownload`). Returns the same ticket * `startDownload` returns: `watchStatus`, `killDownload`, `reconcile`, the * leases and the history layer all work on it. * * Throws before anything is spawned: a `validation` DownloadError for a * malformed option, a `conflict` DownloadError while an attempt under this id * is still running, and a plain Error for an unsafe id (as `startDownload` * does). A command that cannot be started (a missing executable, say) is * reported through the status instead. */ export declare function startCommand(options: StartCommandOptions): Promise; //# sourceMappingURL=command.d.ts.map