/** * WorkflowFunnelLoader — Loads and watches workflows.yaml as the SSOT * for WORKFLOW_FUNNELS definition table. * * D-01: workflows.yaml is the single source of truth (SSOT). * D-02: workflows.yaml lives in .state/ directory per workspace. * D-03: Developers manually maintain workflows.yaml (no auto-registration). * D-04: Code only reads YAML, never writes it. */ import type { RuntimeKind } from './runtime-v2/runtime-protocol.js'; /** * A single stage in a workflow funnel. * Policy fields are optional — existing stages without policy fields remain valid. */ export interface WorkflowStage { /** Stage name within the funnel (e.g., 'dreamer_completed') */ name: string; /** Event type string (e.g., 'rulehost_evaluated') */ eventType: string; /** Event category (e.g., 'completed', 'created', 'blocked') */ eventCategory: string; /** Dot-path to stats field (e.g., 'evolution.rulehostEvaluated') */ statsField: string; /** Optional per-stage timeout in milliseconds (overrides funnel-level timeout) */ timeoutMs?: number; /** Optional success criteria expression for this stage */ successCriteria?: string; /** When true, this stage is disabled and skipped by consumers */ legacyDisabled?: boolean; /** Observability tags for this stage */ observability?: { enabled?: boolean; emitEvents?: string[]; }; } /** * Funnel-level policy that applies to all stages unless overridden per-stage. */ export interface FunnelPolicy { /** Default timeout for all stages in this funnel (ms) */ timeoutMs?: number; /** Stage execution order enforcement */ stageOrder?: 'strict' | 'relaxed'; /** Legacy flag — when true, funnel is superseded by a newer implementation */ legacyDisabled?: boolean; /** Observability configuration for the entire funnel */ observability?: { enabled?: boolean; emitEvents?: string[]; logLevel?: 'debug' | 'info' | 'warn' | 'error'; }; /** Runtime adapter kind. Default: 'pi-ai' (D-04). */ runtimeKind?: RuntimeKind; /** OpenClaw CLI mode — required when runtimeKind is 'openclaw-cli'. */ openclawMode?: 'local' | 'gateway'; /** LLM provider name (e.g., 'openrouter', 'anthropic'). Required for pi-ai. */ provider?: string; /** Model ID (e.g., 'anthropic/claude-sonnet-4'). Required for pi-ai. */ model?: string; /** Name of the environment variable containing the API key. Required for pi-ai. */ apiKeyEnv?: string; /** Maximum retry attempts for transient LLM failures. */ maxRetries?: number; /** Custom base URL for OpenAI-compatible providers not in pi-ai's built-in registry. */ baseUrl?: string; /** Maximum repair attempts for structured output repair loop (PRI-271 A1). Default: 3. */ maxRepairAttempts?: number; /** Output path strategy for structured output (PRI-271 B3). Default: 'tool_call_first'. */ outputPathStrategy?: 'tool_call_first' | 'json_mode_first' | 'free_form_only'; } /** * A workflow funnel definition. */ export interface WorkflowFunnel { workflowId: string; stages: WorkflowStage[]; /** Optional funnel-level policy applied to all stages */ policy?: FunnelPolicy; } /** * Root of workflows.yaml schema. */ export interface WorkflowFunnelConfig { version: string; funnels: WorkflowFunnel[]; } /** * Loads and watches workflows.yaml, building an in-memory WORKFLOW_FUNNELS table. * * Failure semantics: * - Missing file: clears in-memory funnels, uses empty Map * - Malformed YAML: preserves last known-good config, logs warning * - Schema-invalid YAML: same as malformed YAML */ export declare class WorkflowFunnelLoader { /** In-memory WORKFLOW_FUNNELS table: workflowId -> stages */ private readonly funnels; /** Full funnel table with policy: workflowId -> WorkflowFunnel */ private readonly fullFunnels; private readonly configPath; /** fs.watch() handle for cleanup */ private watchHandle?; /** YAML parse warnings from last load() call */ private readonly warnings; constructor(stateDir: string); /** * Load (or reload) workflows.yaml from disk. * On parse/validation failure, preserves the last known-good config. * On missing file, clears to empty. */ load(): void; /** * Start watching workflows.yaml for changes. */ watch(): void; /** Stop watching and clean up the FSWatcher. */ dispose(): void; /** Get all stages for a workflow. */ getStages(workflowId: string): WorkflowStage[]; /** * Get the full funnel definition (including policy) for a workflow. * Returns undefined if the funnel is not found. * Returns a deep clone — consumer mutations do not affect internal state. */ getFunnel(workflowId: string): WorkflowFunnel | undefined; /** * Get the full WORKFLOW_FUNNELS table. * Returns a deep clone — consumer mutations do not affect internal state. */ getAllFunnels(): Map; /** * Get the full WORKFLOW_FUNNELS table including policy. * Returns a Map of workflowId -> WorkflowFunnel (stages and policy cloned). */ getAllFunnelsWithPolicy(): Map; /** Returns warnings from the last load() call. */ getWarnings(): string[]; /** Get the config file path. */ getConfigPath(): string; /** Deep clone a funnel to prevent consumer mutations. */ private static cloneFunnel; } //# sourceMappingURL=workflow-funnel-loader.d.ts.map