/**
 * Workflow status snapshot — bridges the in-process panel state with
 * out-of-process consumers (e.g. `atomic workflow status`).
 *
 * The orchestrator subscribes to its `PanelStore` and writes a fresh
 * snapshot to `~/.atomic/sessions/<workflowRunId>/status.json` every
 * time the store mutates. Consumers read that file to derive the
 * overall workflow state without needing IPC into the orchestrator.
 */
import type { SessionData, SessionStatus } from "../components/orchestrator-panel-types.ts";
/** File name used for the status snapshot inside each workflow's session directory. */
export declare const STATUS_FILE_NAME = "status.json";
/** High-level workflow state surfaced to the agent / CLI consumer. */
export type WorkflowOverallStatus = "in_progress" | "error" | "completed" | "needs_review";
/** Per-session entry mirrored from the orchestrator's panel store. */
export interface WorkflowStatusSession {
    name: string;
    status: SessionStatus;
    parents: string[];
    error?: string;
    startedAt: number | null;
    endedAt: number | null;
}
/**
 * Snapshot persisted to disk for `atomic workflow status` to read.
 * Schema is versioned so future readers can stay backwards-compatible.
 */
export interface WorkflowStatusSnapshot {
    schemaVersion: 1;
    workflowRunId: string;
    tmuxSession: string;
    workflowName: string;
    agent: string;
    prompt: string;
    /** Overall state derived from per-session status + completion flags. */
    overall: WorkflowOverallStatus;
    /** True when the orchestrator has shown its completion banner. */
    completionReached: boolean;
    /** Fatal-error message set via `panel.showFatalError`, if any. */
    fatalError: string | null;
    /** Wall-clock time of the snapshot in ISO-8601 format. */
    updatedAt: string;
    sessions: WorkflowStatusSession[];
}
/**
 * Inputs the writer needs to render a snapshot — a strict subset of
 * `PanelStore` so the writer doesn't depend on the renderer module.
 */
export interface StatusWriterInputs {
    workflowRunId: string;
    tmuxSession: string;
    workflowName: string;
    agent: string;
    prompt: string;
    fatalError: string | null;
    completionReached: boolean;
    sessions: readonly SessionData[];
}
/**
 * Derive the overall workflow state from per-session statuses + the
 * orchestrator-level completion / fatal-error flags.
 *
 * Precedence (highest first):
 *   1. `error`          — fatal error or any session ended in error
 *   2. `needs_review`   — at least one session is awaiting human input (HIL)
 *   3. `completed`      — completion banner reached and nothing errored
 *   4. `in_progress`    — default
 *
 * `needs_review` outranks `completed` so an agent that pauses for HIL
 * right at the end is never reported as done while still waiting.
 */
export declare function deriveOverallStatus(input: {
    sessions: readonly SessionData[];
    completionReached: boolean;
    fatalError: string | null;
}): WorkflowOverallStatus;
/** Build a snapshot from the writer inputs (pure — exported for tests). */
export declare function buildSnapshot(input: StatusWriterInputs, now?: () => Date): WorkflowStatusSnapshot;
/** Absolute path of the status file for a given workflow run directory. */
export declare function statusFilePath(sessionDir: string): string;
/**
 * Write a snapshot to `<sessionDir>/status.json`. Uses an atomic
 * write-then-rename so concurrent readers never see partial JSON.
 * Errors are swallowed — the orchestrator must keep running even if
 * the status file can't be persisted.
 */
export declare function writeSnapshot(sessionDir: string, snapshot: WorkflowStatusSnapshot): Promise<void>;
/**
 * Read a snapshot from disk. Returns `null` when the file doesn't
 * exist or fails to parse — callers fall back to deriving status from
 * the live tmux session list.
 */
export declare function readSnapshot(sessionDir: string): Promise<WorkflowStatusSnapshot | null>;
/**
 * Extract the `workflowRunId` (the trailing 8-hex segment) from a
 * tmux session name shaped `atomic-wf-<agent>-<name>-<id>`. Returns
 * `null` for non-workflow sessions or names that don't end in a
 * UUID-style suffix.
 */
export declare function workflowRunIdFromTmuxName(name: string): string | null;
//# sourceMappingURL=status-writer.d.ts.map