import type { WorkflowRunRow, WorkflowStepRow } from './types.js';
import type { WorkflowDb } from './runner.js';
/**
 * Optional hook: fired whenever a persistence write fails (e.g. EACCES,
 * ENOSPC). Surfaced so the CLI, dashboard, or bootstrap can decide how
 * to react beyond the single console.warn. Not called for the initial
 * "directory unwritable" detection — that's stored in {@link isWritable}.
 */
export type DbWriteFailureListener = (err: unknown, filePath: string) => void;
export interface JsonFileWorkflowDbOptions {
    /** Override the resolved filePath. Kept for tests / advanced callers. */
    filePath?: string;
    /** Notified on every underlying write error. */
    onWriteFailure?: DbWriteFailureListener;
    /**
     * When true, if the preferred file path is unwritable, fall back to
     * `$HOME/.agent-relay/workflow-runs-<basename>.jsonl` so `--resume`
     * still works in environments where the workflow cwd is read-only
     * (cloud sandboxes with restrictive workspace ACLs).
     *
     * Defaults to `false` — strict "write to this path or run in-memory"
     * semantics, matching the pre-cache behavior. Opt-in via `true`.
     */
    homeFallback?: boolean;
}
/**
 * JSONL-backed WorkflowDb for the CLI.
 *
 * Design: the **in-memory cache is the single source of truth** for the
 * process lifetime. Every mutation updates the cache synchronously and
 * then best-effort appends to the jsonl file for durability / `--resume`.
 *
 * This matters because the runtime correctness of a running workflow
 * must not depend on disk writes succeeding. If the storage path is
 * unwritable (ACL-restricted workspace, full disk, ENOSPC), the workflow
 * still progresses through its state machine correctly — we just lose
 * the ability to resume a future process from that run.
 *
 * Read paths used to re-snapshot the jsonl on every call, which meant
 * a failed `updateRun(..., { status: 'completed' })` would leave a
 * subsequent `getRun` returning the stale 'running' row from disk.
 * That bug surfaced as workflows passing per-step but reporting
 * `status: 'running'` to callers.
 *
 * Storage path resolution:
 *   1. Try the caller-supplied file path. If the parent directory is
 *      writable, use it.
 *   2. If (1) fails and `homeFallback` is true (opt-in, default false),
 *      try `$HOME/.agent-relay/workflow-runs-<basename>.jsonl`. This is
 *      outside any workspace mount in cloud sandboxes and almost always
 *      writable by the agent.
 *   3. If both fail, run in memory-only mode. The workflow still
 *      executes correctly; `--resume` won't be available for this run.
 *
 * File: `.agent-relay/workflow-runs.jsonl` in the workflow cwd by default.
 */
export declare class JsonFileWorkflowDb implements WorkflowDb {
    private readonly filePath;
    /** Whether persistence is active. False = in-memory-only mode. */
    private readonly writable;
    private appendFailedOnce;
    private readonly onWriteFailure?;
    /**
     * Authoritative in-memory mirror. Every mutation updates this; reads
     * return from here. The jsonl file is only consulted at construction
     * (to replay prior state for `--resume`) and is otherwise write-only.
     */
    private readonly cache;
    constructor(filePathOrOptions: string | JsonFileWorkflowDbOptions);
    /** Returns false if persistence is not active (in-memory-only mode). */
    isWritable(): boolean;
    /** Resolved path on disk. For tests + diagnostics. */
    getStoragePath(): string;
    hasStepOutputs(runId: string): boolean;
    private static resolveStoragePath;
    private static loadSnapshot;
    private append;
    insertRun(run: WorkflowRunRow): Promise<void>;
    updateRun(id: string, patch: Partial<WorkflowRunRow>): Promise<void>;
    getRun(id: string): Promise<WorkflowRunRow | null>;
    insertStep(step: WorkflowStepRow): Promise<void>;
    updateStep(id: string, patch: Partial<WorkflowStepRow>): Promise<void>;
    getStepsByRunId(runId: string): Promise<WorkflowStepRow[]>;
}
//# sourceMappingURL=file-db.d.ts.map