import type { CapabilityToken } from "./capabilities.js"; import type { ProcessLaunchConfig, ProcessLaunchProjectConfig, ProcessSnapshotContext, } from "./extension-api.js"; /** Initial repository bindings resolved before the first execution. @public */ export type InitialProcessBinding = Pick< ProcessLaunchConfig, "params" | "metadata" | "settingsContext" > & { /** Complete, nonempty repository set. @public */ projects: readonly ProcessLaunchProjectConfig[]; }; /** A server-owned readiness decision, with no worker attempt. @public */ export type TurnWaitDecision = | TurnWaitCompletion | TurnWaitNotice | TurnWaitBinding; /** A readiness condition or source cancellation with operator guidance. @public */ export interface TurnWaitNotice { /** @internal */ readonly kind: "waiting" | "abort"; /** Safe operator guidance. @public */ readonly message: string; } /** Initial bindings staged by a successful readiness check. @public */ export interface TurnWaitBinding { /** @internal */ readonly kind: "bind"; /** @internal */ readonly binding: InitialProcessBinding; } /** A terminal decision returned from a turn's server-side waiting condition. @public */ export interface TurnWaitCompletion { /** @internal */ readonly kind: "complete"; } /** Server context for a repeatable condition. External operations must be read-only. @public */ export interface TurnWaitContext extends ProcessSnapshotContext { /** Cancelled on timeout or server shutdown. @public */ readonly signal: AbortSignal; /** Resolve an extension-owned server adapter. Never perform external writes here. @public */ require(token: CapabilityToken): T | T[]; /** Stage process state with this check; stale and failed checks discard it. @public */ setState(state: TState): void; /** Wait at the normal polling interval with safe operator guidance. Return this decision. @public */ waiting(message: string): TurnWaitDecision; /** Abort without a worker when the source is cancelled. Return this decision. @public */ abort(message: string): TurnWaitDecision; /** Bind initial params and projects atomically, then check again before starting a worker. Only available before any project or execution exists. @public */ bindInitialProjects(binding: InitialProcessBinding): TurnWaitDecision; /** Finish the process without allocating a worker. Return this decision. @public */ complete(): TurnWaitCompletion; } /** False keeps this turn waiting; true permits execution; complete ends the process. @public */ export type TurnWaitPredicate = ( process: TurnWaitContext, ) => boolean | TurnWaitDecision | Promise>; /** A temporary observation failure. Other predicate errors require an explicit retry. @public */ export class RetryableWaitError extends Error { /** The message must be safe to show to an operator. @public */ constructor(message: string, options?: ErrorOptions) { super(message, options); this.name = "RetryableWaitError"; } }