import { c as TurnResult, l as TaskLogEntry, o as Task, s as TaskStatus, u as TokenUsage } from "./types-I5Cwtl_K.js"; import { AsyncLocalStorage } from "node:async_hooks"; //#region src/flow/types.d.ts /** Anything with zod's parse shape; the flow runtime never imports zod itself. */ interface FlowSchema { parse(value: unknown): T; } interface FlowTaskResult { taskId: string; status: string; output: string; data?: T; tokens: TokenUsage | null; model: string | null; } interface GateResult { ok: boolean; code: number; output: string; } /** Options shared with `coder run`, plus `returns`. */ interface FlowTaskOptions { engine?: string; model?: string; effort?: string; permissions?: string; name?: string; system?: string; resume?: string; cwd?: string; addDirs?: string[]; returns?: FlowSchema; } type FlowRunStatus = 'queued' | 'running' | 'completed' | 'failed' | 'stopped'; /** * One line of a run's events.jsonl: a hook payload tagged with its kind. The * attached orchestrator appends these; `flow stream` / `flow.stream()` replay * and follow them. */ type FlowEvent = { kind: 'task-start'; taskId: string; name?: string; prompt: string; engine?: string; depth?: number; } | { kind: 'task-end'; taskId: string; status: string; tokens: TokenUsage | null; } | { kind: 'gate-start'; gateId: string; cmd: string; depth?: number; } | { kind: 'gate'; gateId?: string; cmd: string; ok: boolean; code: number; depth?: number; } | { kind: 'log'; message: string; depth?: number; } | { kind: 'flow-start'; name: string; depth: number; } | { kind: 'replay'; count: number; }; interface JournalEntry { seq: number; kind: 'task' | 'gate' | 'flow'; fingerprint: string; result: unknown; taskId?: string; tokens?: TokenUsage | null; startedAt: string; endedAt: string; } /** flow.json: the persisted run record. */ interface FlowRecord { runId: string; name: string; script: string; args: unknown; status: FlowRunStatus; startedAt: string; endedAt?: string; /** Orchestrator process while status is running; cleared on every terminal write. */ pid?: number; pidStartedAt?: string; concurrency: number; maxTasks: number; taskCount: number; ledger: Record; result?: unknown; error?: string; /** Hidden from the default list; set by auto-archive or `flow archive`. */ archived?: boolean; archivedAt?: string; } /** One `flow result` step row: a journaled task with its current status. */ interface FlowStep { taskId: string | null; name: string | null; status: string; tokens: TokenUsage | null; } interface DiscoveredFlow { name: string; path: string; /** `builtin` flows ship with coder; their `path` is `builtin:`. */ scope: 'workspace' | 'global' | 'builtin'; } //#endregion //#region src/flow/runtime.d.ts /** * Dispatch one coder task and await its result. With a `returns` schema the * reply is validated and `data` is guaranteed (validation failure throws). * Inside a flow run, results are journaled and replayed on resume. */ declare function task(prompt: string, opts: FlowTaskOptions & { returns: FlowSchema; }): Promise & { data: T; }>; /** Dispatch one coder task and await its result. Mirrors `coder run`. */ declare function task(prompt: string, opts?: FlowTaskOptions): Promise; /** * Run a shell command as a checkpoint. Never throws. Inspect `ok`/`code`. * output is captured (capped) and journaled for resume. */ declare function gate(cmd: string, opts?: { cwd?: string; }): Promise; type Stage = (prev: any, item: any, index: number) => unknown; type S = (prev: P, item: T, index: number) => R | Promise; /** * Run each item through the stages independently, with no barrier between * stages. Each stage receives `(prev, item, index)`; a thrown stage drops * that item to `null` and skips its remaining stages. */ declare function pipeline(items: T[], s1: S): Promise<(A | null)[]>; declare function pipeline(items: T[], s1: S, s2: S): Promise<(B | null)[]>; declare function pipeline(items: T[], s1: S, s2: S, s3: S): Promise<(C | null)[]>; declare function pipeline(items: T[], s1: S, s2: S, s3: S, s4: S): Promise<(D | null)[]>; declare function pipeline(items: T[], ...stages: Stage[]): Promise; /** Emit a progress line: appended to the run's flow.log and streamed to watchers. */ declare function log(msg: string): void; /** * Run another flow inline as a sub-step and return its result. Nesting is one * level deep. A subflow cannot call `flow()` itself. */ declare function flow(name: string, args?: unknown): Promise; //#endregion //#region src/flow/executor.d.ts interface RunOptions { runId?: string; args?: unknown; concurrency?: number; maxTasks?: number; dryRun?: boolean; cwd?: string; /** Platform credential for built-in integrations; never persisted with the run. */ integrationToken?: string; /** The agent whose permissions cap every task this run starts. */ ceiling?: { agent: string; permissions: string; }; } interface RunSummary { runId: string; name: string; status: 'completed'; result: unknown; tokens: Record; taskCount: number; } interface StopSummary { runId: string; status: FlowRecord['status']; stoppedTasks: string[]; keptTasks: string[]; } //#endregion //#region src/flow/runs.d.ts /** A run's record with its step rows, trimmed journal and recorded events. */ type RunResult = FlowRecord & { steps: FlowStep[]; journal: Array>; events: FlowEvent[]; }; type Archived = { runId: string; archived: true; }; type ArchivedAll = { archived: string[]; count: number; }; /** Archive one stopped run, or with `allStopped` every one. */ declare function archiveRuns(runId: string, opts?: { allStopped?: false; }): Archived; declare function archiveRuns(runId: string | undefined, opts: { allStopped: true; }): ArchivedAll; declare function archiveRuns(runId?: string, opts?: { allStopped?: boolean; }): Archived | ArchivedAll; type Deleted = { runId: string; deleted: boolean; }; type DeletedAll = { deleted: string[]; count: number; }; /** Delete one stopped run's record (its tasks are left alone), or with `allArchived` every archived one. */ declare function deleteRuns(runId: string, opts?: { allArchived?: false; }): Deleted; declare function deleteRuns(runId: string | undefined, opts: { allArchived: true; }): DeletedAll; declare function deleteRuns(runId?: string, opts?: { allArchived?: boolean; }): Deleted | DeletedAll; //#endregion //#region src/core/errors.d.ts /** The run-native-subagent fallback payload the CLI prints on exit 3. */ interface FallbackPayload { error: string; fallback: { action: 'run-native-subagent'; reason: 'no-engine-available'; permissions: string; instructions: string; note: string; system?: string; task: string; }; } /** Recoverable errors with CLI exit codes. */ type CoderErrorCode = 'nested-dispatch' | 'invalid-option' | 'read-only-unavailable' | 'startup-failed' | 'chain-exhausted' | 'approval-pending' | 'task-failed' | 'flow-failed' | /** A Coder server refused or failed a request; `status` carries the HTTP status. */ 'server' | /** Sign-in to a server did not complete. */ 'login-failed'; declare class CoderError extends Error { code: CoderErrorCode; hint?: string | string[]; taskId?: string; /** chain-exhausted: the run-native-subagent payload the CLI prints on exit 3. */ payload?: FallbackPayload; /** approval-pending: the approval to answer. */ approval?: { id: string; summary: string; cwd?: string | null; networkHost?: string | null; }; /** task-failed (flow task()): the failed task's result. */ result?: unknown; /** flow-failed: the run to resume. */ runId?: string; /** server: the HTTP status the server answered with. */ status?: number; constructor(code: CoderErrorCode, message: string, extra?: { hint?: string | string[]; taskId?: string; payload?: FallbackPayload; approval?: { id: string; summary: string; cwd?: string | null; networkHost?: string | null; }; result?: unknown; runId?: string; status?: number; }); } //#endregion //#region src/core/state.d.ts interface TurnResultEntry { at?: string; prompt?: string | null; finalMessage?: string; status?: number; tokens?: TurnResult['tokens']; model?: TurnResult['model']; [key: string]: unknown; } declare function readTurnResults(cwd: string, taskId: string): TurnResultEntry[]; //#endregion //#region src/core/dispatch.d.ts interface TaskResult { taskId: string; status: TaskStatus; result: TurnResult | null; /** The last `tail` progress-log entries; [] at the default tail of 0. */ steps: TaskLogEntry[]; /** One entry per finished turn (a steered task accretes turns). */ turns: TurnResultEntry[]; task: Task; } /** Read a task's current state and result.json without waiting. `tail` fills `steps`. */ declare function readTask(cwd: string, taskId: string, opts?: { tail?: number | 'all'; }): TaskResult; //#endregion //#region src/flow/index.d.ts /** * The flow's `--args` value. A Proxy over the ALS-bound current args, so a * top-level `import { args }` reflects whichever run is executing. */ declare const args: Record; /** Run and inspect flows programmatically; mirrors `coder flow`. */ declare const flowSdk: { /** Run a flow and await its result. */ run(nameOrPath: string, opts?: RunOptions): Promise; /** Recent flow runs (mirrors `coder flow list`). */ list(opts?: { archived?: boolean; limit?: number | "all"; }): FlowRecord[]; /** Flows discoverable from a directory (workspace + global). */ discover(cwd?: string): DiscoveredFlow[]; /** A run's record with its step rows, journal and events (omit the id for the most recent run). `tail` caps steps (default 'all'; 0 → []). */ result(runId?: string, opts?: { tail?: number | "all"; }): RunResult | null; /** Follow a run live: an async iterable of flow events, ending when the run is terminal. `tail` replays only the last n (default 'all'). */ stream(runId?: string, opts?: { tail?: number | "all"; }): AsyncGenerator; /** Stop a running flow (and, by default, its still-running tasks). */ stop(runId?: string, opts?: { keepTasks?: boolean; }): Promise; /** Continue a stopped or edited run from its journal and await the result. */ resume(runId?: string, opts?: RunOptions): Promise; /** Archive a run (hide it from the default list), or with `allStopped` every stopped one. A running run must be stopped first. */ archive: typeof archiveRuns; /** Delete a run's record from disk (its tasks are left alone), or with `allArchived` every archived one. A running run must be stopped first. */ delete: typeof deleteRuns; }; //#endregion export { FlowTaskResult as C, FlowTaskOptions as S, task as _, readTurnResults as a, FlowRecord as b, archiveRuns as c, RunSummary as d, StopSummary as f, pipeline as g, log as h, readTask as i, deleteRuns as l, gate as m, flowSdk as n, CoderError as o, flow as p, TaskResult as r, RunResult as s, args as t, RunOptions as u, DiscoveredFlow as v, GateResult as w, FlowStep as x, FlowEvent as y };