// Quality Intelligence workflow descriptors (Epic #270, Issue #273, ADR-0023 D6).
//
// Four reviewable QI workflows executed through `@oscharko-dev/keiko-harness` and
// `@oscharko-dev/keiko-workflows`. Each descriptor enumerates the deterministic
// stage sequence, the emitted event kinds, and the typed limits the run entry
// honours. NO model SDK reaches this module: stage runtime composes the gateway
// dispatcher seam shipped in #279.
//
// Structurally inspired by Test Intelligence reference (TI) workflow staging,
// but the Keiko port stays envelope-shaped, descriptor-driven, and free of
// any TI runtime / IR.
//
// The descriptors here are pure value records — they intentionally do NOT
// instantiate the WorkflowDescriptor shape from `../descriptor.js` because that
// shape is tuned to the apply/dry-run developer-assist workflows (#8/#9) and
// would force fictional input slots onto QI runs. The QI surface re-exports
// `QualityIntelligenceWorkflowDescriptor` from this file directly.
export const QUALITY_INTELLIGENCE_DEFAULT_WORKFLOW_LIMITS = Object.freeze({
    stageTimeoutMs: 45_000,
    maxCandidatesPerRun: 256,
    maxFindingsPerRun: 512,
    maxModelCallsPerRun: 32,
    maxJudgeCallsPerRun: 256,
});
const FROZEN_DEFAULT_LIMITS = QUALITY_INTELLIGENCE_DEFAULT_WORKFLOW_LIMITS;
function freezeStringArray(values) {
    return Object.freeze([...values]);
}
function freezeEventKinds(values) {
    return Object.freeze([...values]);
}
function freezeDescriptor(descriptor) {
    return Object.freeze({
        ...descriptor,
        stageNames: freezeStringArray(descriptor.stageNames),
        emittedEventKinds: freezeEventKinds(descriptor.emittedEventKinds),
        defaultLimits: descriptor.defaultLimits,
    });
}
// Shared run-lifecycle envelope event kinds. Every QI workflow emits this set;
// stage-specific extra kinds are added per descriptor below.
const LIFECYCLE_EVENT_KINDS = [
    "run:queued",
    "run:started",
    "stage:started",
    "stage:completed",
    "stage:failed",
    "run:succeeded",
    "run:failed",
    "run:cancelled",
];
export const QI_TEST_DESIGN_WORKFLOW_DESCRIPTOR = freezeDescriptor({
    workflowId: "qi:test-design",
    displayName: "Quality Intelligence — Test Design",
    description: "Draft test-case candidates, adversarially judge their quality, build coverage map, validate, " +
        "persist evidence. Stages: plan, candidates, judge, coverage, validate, finalize.",
    stageNames: ["plan", "candidates", "judge", "coverage", "validate", "finalize"],
    emittedEventKinds: [...LIFECYCLE_EVENT_KINDS, "candidate:proposed", "finding:recorded"],
    defaultLimits: FROZEN_DEFAULT_LIMITS,
    preferredCostClass: "medium",
});
export const QI_COVERAGE_REVIEW_WORKFLOW_DESCRIPTOR = freezeDescriptor({
    workflowId: "qi:coverage-review",
    displayName: "Quality Intelligence — Coverage Review",
    description: "Build and report a coverage map across existing candidates and atoms. " +
        "Stages: plan, analyse, report.",
    stageNames: ["plan", "analyse", "report"],
    emittedEventKinds: [...LIFECYCLE_EVENT_KINDS],
    defaultLimits: FROZEN_DEFAULT_LIMITS,
    preferredCostClass: "low",
});
export const QI_VALIDATION_WORKFLOW_DESCRIPTOR = freezeDescriptor({
    workflowId: "qi:validation",
    displayName: "Quality Intelligence — Validation",
    description: "Run schema/logic validators and optional model judges over existing candidates, reconcile, persist. " +
        "Stages: plan, run-judges, reconcile, report.",
    stageNames: ["plan", "run-judges", "reconcile", "report"],
    emittedEventKinds: [...LIFECYCLE_EVENT_KINDS, "finding:recorded"],
    defaultLimits: FROZEN_DEFAULT_LIMITS,
    preferredCostClass: "high",
});
export const QI_ARTIFACT_REFINEMENT_WORKFLOW_DESCRIPTOR = freezeDescriptor({
    workflowId: "qi:artifact-refinement",
    displayName: "Quality Intelligence — Artifact Refinement",
    description: "Refine existing candidates by re-applying the policy profile and deduplication, then validate. " +
        "Stages: plan, refine, validate, report.",
    stageNames: ["plan", "refine", "validate", "report"],
    emittedEventKinds: [...LIFECYCLE_EVENT_KINDS, "candidate:proposed", "finding:recorded"],
    defaultLimits: FROZEN_DEFAULT_LIMITS,
    preferredCostClass: "medium",
});
export const QUALITY_INTELLIGENCE_WORKFLOW_DESCRIPTORS = Object.freeze([
    QI_TEST_DESIGN_WORKFLOW_DESCRIPTOR,
    QI_COVERAGE_REVIEW_WORKFLOW_DESCRIPTOR,
    QI_VALIDATION_WORKFLOW_DESCRIPTOR,
    QI_ARTIFACT_REFINEMENT_WORKFLOW_DESCRIPTOR,
]);
export function findQualityIntelligenceWorkflowDescriptor(workflowId) {
    for (const descriptor of QUALITY_INTELLIGENCE_WORKFLOW_DESCRIPTORS) {
        if (descriptor.workflowId === workflowId) {
            return descriptor;
        }
    }
    throw new Error(`Unknown Quality Intelligence workflow id: ${workflowId}`);
}
