"use strict";
/**
 * WorkflowSchema — TypeScript types for OpenLife workflows.
 *
 * A workflow is a YAML-declared executable sequence of steps. Each step
 * names an agent (or squad), an action to perform, and the artifacts it
 * is expected to create or update. Workflows are loaded by the
 * WorkflowEngine, validated by the WorkflowParser, and persisted as runs
 * under `.openlife/workflows/<runId>.json`.
 *
 * Story 4.1 — OpenLife v1.2 Royal Stack.
 *
 * The schema is intentionally close to community story-cycle workflow
 * conventions so the four ported workflows in dist-templates/workflows/
 * (Story 4.4) round-trip without contortion. Two OpenLife-specific
 * extensions:
 *
 *   1. `squad: <id>` — a step may dispatch to a Squad instead of a
 *      single agent, so the design-squad / qa-squad can be addressed as
 *      a single unit.
 *   2. `idempotent: true` — declares the step is safe to re-execute on
 *      resume after a partial-run crash. WorkflowEngine.resume() uses
 *      this flag to decide whether to retry or skip a partially-
 *      completed step.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.WORKFLOW_ERRORS = void 0;
exports.isPhaseMarker = isPhaseMarker;
exports.isExecutableStep = isExecutableStep;
// ─────────────────────────────────────────────────────────────
// Type guards — used by the parser to discriminate sequence entries
// ─────────────────────────────────────────────────────────────
function isPhaseMarker(entry) {
    if (entry === null || typeof entry !== 'object')
        return false;
    const e = entry;
    return typeof e.phase === 'number' && typeof e.name === 'string' && e.id === undefined;
}
function isExecutableStep(entry) {
    if (entry === null || typeof entry !== 'object')
        return false;
    const e = entry;
    return typeof e.id === 'string';
}
// ─────────────────────────────────────────────────────────────
// Stable error codes — exported so callers + tests assert on strings,
// not error messages.
// ─────────────────────────────────────────────────────────────
exports.WORKFLOW_ERRORS = {
    INVALID_YAML: 'workflow_invalid_yaml',
    INVALID_SCHEMA: 'workflow_invalid_schema',
    MISSING_ROOT: 'workflow_missing_root',
    MISSING_REQUIRED_FIELD: 'workflow_missing_required_field',
    INVALID_TYPE: 'workflow_invalid_type',
    DUPLICATE_STEP_ID: 'workflow_duplicate_step_id',
    CIRCULAR_REQUIRES: 'workflow_circular_requires',
    UNKNOWN_REQUIRES: 'workflow_unknown_requires',
    AGENT_AND_SQUAD: 'workflow_agent_and_squad',
    NEITHER_AGENT_NOR_SQUAD: 'workflow_neither_agent_nor_squad',
    // v1.3 additions (Story 2.2)
    INVALID_MODE: 'workflow_invalid_mode',
    INVALID_TOOLS_POLICY: 'workflow_invalid_tools_policy',
    INVALID_TRIGGERS: 'workflow_invalid_triggers',
    INVALID_SUCCESS_CRITERIA: 'workflow_invalid_success_criteria',
};
