/**
 * Workflow orchestrator (pure decision layer).
 *
 * Given a current `Snapshot` and the `WorkflowDefinition`, decide what
 * the runtime should do next.  Returns a list of `OrchestratorAction`
 * descriptors — the executor (Slice D) is responsible for translating
 * those into event-log writes and side-effect dispatches.  Keeping the
 * decision function pure makes the critical-path semantics easy to test
 * without spinning up workers / IM / file IO.
 *
 * v0 scope (UI doc §7 landing #1): focus on the humanGate.stage='before'
 * loop.  Retries / cancel coordination / reconcile already live in
 * `resume.ts`; the orchestrator only emits forward-progress decisions
 * and lets resume own recovery.
 *
 * ────────────────────────────────────────────────────────────────────
 * Activity ID convention
 *
 *   gate activity: `<runId>::gate::<nodeId>`
 *   work activity: `<runId>::work::<nodeId>`
 *
 * One node may own at most one gate (before-gate) and one work
 * activity in v0.  After-gates and re-runs are deferred.
 *
 * v0.2 loop body activities are scoped by a `loop::<loopId>.<N>` segment:
 *
 *   loop work activity: `<runId>::loop::<loopId>.<N>::work::<bodyNodeId>`
 *   loop gate activity: `<runId>::loop::<loopId>.<N>::gate::<bodyNodeId>`
 *
 * `<N>` is the 1-indexed iteration; `<loopId>` is the loop block's
 * nodeId.  All segments stay within `SEGMENT_RE` (allows
 * `[A-Za-z0-9._:-]`), so existing `isValidPathSegment` / attempt-
 * sidecar path guards continue to apply without modification.
 * ────────────────────────────────────────────────────────────────────
 */
import { type HumanGate, type WorkflowDefinition, type WorkflowNode } from './definition.js';
import type { ErrorClass, OutputRef } from './events/payloads.js';
import type { Snapshot } from './events/replay.js';
export declare function gateActivityId(runId: string, nodeId: string): string;
export declare function workActivityId(runId: string, nodeId: string): string;
export declare function loopWorkActivityId(runId: string, loopId: string, iteration: number, bodyNodeId: string): string;
export declare function loopGateActivityId(runId: string, loopId: string, iteration: number, bodyNodeId: string): string;
/**
 * Parsed activity id.  `kind: 'plain'` corresponds to the v0.1 forms
 * (`<runId>::work::<nodeId>` / `<runId>::gate::<nodeId>`).  `kind:
 * 'loop'` corresponds to v0.2 loop-iteration forms.  Returns `undefined`
 * if `s` doesn't match any known shape — callers can treat that as
 * "not a workflow activity id" without throwing.
 */
export type ParsedActivityId = {
    kind: 'plain';
    runId: string;
    activityKind: 'work' | 'gate';
    nodeId: string;
} | {
    kind: 'loop';
    runId: string;
    loopId: string;
    iteration: number;
    activityKind: 'work' | 'gate';
    nodeId: string;
};
export declare function parseActivityId(s: string): ParsedActivityId | undefined;
/**
 * `dispatchGate` — caller writes `attemptCreated` (for the gate activity)
 * + `waitCreated{waitKind:'human-gate'}` + (optionally) `nodeWaiting`.
 */
export type DispatchGateAction = {
    kind: 'dispatchGate';
    nodeId: string;
    activityId: string;
    humanGate: HumanGate;
};
/**
 * `dispatchWork` — caller writes `attemptCreated` for the work activity
 * and spawns the bot worker (subagent) or invokes the executor
 * (hostExecutor).
 */
export type DispatchWorkAction = {
    kind: 'dispatchWork';
    nodeId: string;
    activityId: string;
    node: WorkflowNode;
};
/**
 * `completeNodeSucceeded` — work activity reached terminal success.
 * Caller writes `nodeSucceeded{nodeId, lastActivityId}`.
 */
export type CompleteNodeSucceededAction = {
    kind: 'completeNodeSucceeded';
    nodeId: string;
    lastActivityId: string;
    outputRef: OutputRef;
};
/**
 * `completeNodeFailed` — work activity or gate activity reached terminal
 * failure (incl. gate rejection / deadline).  Caller writes
 * `nodeFailed{nodeId, lastActivityId, errorClass}` and locates
 * `rootCauseEventId` from the underlying terminal event.
 */
export type CompleteNodeFailedAction = {
    kind: 'completeNodeFailed';
    nodeId: string;
    lastActivityId: string;
    errorClass: ErrorClass;
};
/**
 * `completeRunSucceeded` — every node is succeeded and there's a single
 * sink whose output represents the run's product.  Multi-sink workflows
 * are deferred (caller can refuse / extend).
 */
export type CompleteRunSucceededAction = {
    kind: 'completeRunSucceeded';
    outputRef: OutputRef;
    sinkNodeId: string;
};
/**
 * `completeRunFailed` — at least one node failed; the run cannot proceed.
 * Caller writes `runFailed{failedNodeId, rootCauseEventId}` after
 * locating the original failure event.
 */
export type CompleteRunFailedAction = {
    kind: 'completeRunFailed';
    failedNodeId: string;
};
export type StartLoopAction = {
    kind: 'startLoop';
    loopId: string;
    maxIterations: number;
};
export type StartLoopIterationAction = {
    kind: 'startLoopIteration';
    loopId: string;
    iteration: number;
    prevResolution: 'initial' | 'rejected';
};
export type FinishLoopIterationAction = {
    kind: 'finishLoopIteration';
    loopId: string;
    iteration: number;
    resolution: 'approved' | 'rejected';
    decisionActivityId: string;
    waitResolvedEventId: string;
    by: string;
    comment?: string;
    timedOut?: boolean;
};
export type FinishLoopAction = {
    kind: 'finishLoop';
    loopId: string;
    finalIteration: number;
    resolution: 'approved' | 'max-iterations-exceeded' | 'body-failed' | 'cancelled' | 'timeout';
    errorCode?: string;
    errorClass?: ErrorClass;
    outputRef?: OutputRef;
};
export type OrchestratorAction = DispatchGateAction | DispatchWorkAction | CompleteNodeSucceededAction | CompleteNodeFailedAction | CompleteRunSucceededAction | CompleteRunFailedAction | StartLoopAction | StartLoopIterationAction | FinishLoopIterationAction | FinishLoopAction;
/**
 * Pure decision function.  Read-only — never throws on graph cycles
 * (the caller is responsible for using `parseWorkflowDefinition` to
 * validate the graph upstream).  Returns `[]` when:
 *   - run is already terminal (succeeded / failed / cancelled)
 *   - all nodes are pending on dependencies / open waits / in-flight
 *     activities and no advancement is possible
 *
 * Ordering: node-scoped actions follow topological order so callers
 * see deps-ready nodes first.  Run-scoped actions (completeRun*) come
 * only if no per-node actions remain — they're the terminal sweep.
 */
export declare function decideNextActions(snapshot: Snapshot, def: WorkflowDefinition): OrchestratorAction[];
//# sourceMappingURL=orchestrator.d.ts.map