/**
 * Workflow Store — persist workflow definitions + lifecycle state to disk (spec §B4).
 *
 * Stored at `<project>/.qlogicagent/workflows/<workflowId>/workflow.json`. Listing enumerates
 * subdirectories (mirrors product-persistence.ts). The store is the single source of truth for a
 * workflow's definition, its active flag, and its concurrency policy; the gateway re-registers
 * triggers for every active workflow on restart (spec §B4).
 *
 * fail-loud: missing id on save throws; load returns undefined only for a genuinely absent record.
 */
import type { WorkflowDef } from "./node-schema.js";
import type { TriggerDef } from "./workflow-patch.js";
/** What to do when a workflow is triggered while a previous run is still in-flight (spec §B5). */
export type ConcurrencyPolicy = "queue" | "skip" | "parallel";
export interface WorkflowRecord {
    id: string;
    name: string;
    /** Owning user (llmrouter id via resolveActiveOwnerUserId, D38). Absent on legacy records. */
    owner?: string;
    def: WorkflowDef;
    /** Active workflows have their triggers registered by the gateway (spec §B4). */
    active: boolean;
    concurrency: ConcurrencyPolicy;
    /** The workflow's trigger (set via a WorkflowPatch set_trigger op; spec §C/D7). */
    trigger?: TriggerDef | null;
    /**
     * Unattended-run capability grant (spec D30, IT-7): sensitive node kinds this workflow may
     * execute under unattended triggers (schedule/im/webhook). Granted explicitly by the owner
     * at activation time; absent ⇒ unattended runs of sensitive kinds are denied by the gate.
     */
    permissionScope?: {
        allowUnattendedKinds: string[];
        grantedAt: string;
    } | null;
    /** The published (run-by-triggers) snapshot. Absent ⇒ never published ⇒ cannot activate. */
    publishedDef?: WorkflowDef | null;
    /** The draft rev that was published (UI: draft-ahead badge when rev > publishedRev). */
    publishedRev?: number;
    /** Archived workflows keep their data but cannot run or activate (D31 lifecycle). */
    archived?: boolean;
    /** Monotonic revision for optimistic concurrency (LWW); bumped on every patch (spec §C). */
    rev: number;
    createdAt: string;
    updatedAt: string;
}
/** Root dir of all workflow records for a project (shared with the run-history store). */
export declare function workflowsDir(cwd: string): string;
/** Bounded def-revision history depth — enough for undo, small enough to never matter on disk. */
export declare const MAX_REVISIONS = 20;
/** Summary row for revision lists (full snapshot stays behind loadRevision). */
export interface RevisionSummary {
    rev: number;
    updatedAt: string;
    name: string;
    nodeCount: number;
}
export declare class WorkflowStore {
    private readonly cwd;
    constructor(cwd: string);
    save(record: WorkflowRecord): Promise<void>;
    /**
     * Persist a per-rev snapshot alongside the live record (undo/revert 基座).
     * Keyed by rev: a meta-only update (same rev, e.g. setActive) overwrites its own
     * snapshot; a patch (rev bump) appends a new one. Bounded to MAX_REVISIONS.
     * fail-soft: snapshot/prune errors must never block the primary save.
     */
    private snapshotRevision;
    /** Revision numbers, newest first. */
    private revisionNumbers;
    /** Newest-first revision summaries for the undo/history UI. */
    listRevisions(id: string): Promise<RevisionSummary[]>;
    /** Full record snapshot at a given rev (undefined when pruned/absent). */
    loadRevision(id: string, rev: number): Promise<WorkflowRecord | undefined>;
    load(id: string): Promise<WorkflowRecord | undefined>;
    /** Load a record or throw (fail-loud lookup for callers that require existence). */
    require(id: string): Promise<WorkflowRecord>;
    list(): Promise<WorkflowRecord[]>;
    /** Active workflows the gateway must re-register triggers for after a restart (spec §B4). */
    listActive(): Promise<WorkflowRecord[]>;
    delete(id: string): Promise<void>;
}
