// Scoped regeneration entry (Epic #735, Issue #743).
//
// Invokes the existing model-routed test-design workflow with a NARROWED set of ingested atoms
// — only atoms belonging to stale candidates — and a fresh runId. Does NOT re-implement the
// workflow; composes runQualityIntelligenceModelRoutedTestDesign unchanged.
import { QualityIntelligence as QI } from "@oscharko-dev/keiko-contracts";
import { runQualityIntelligenceModelRoutedTestDesign } from "./modelRoutedTestDesign.js";
const PLAN_STAGES = Object.freeze([
    { name: "plan", descriptor: "qi:plan" },
    { name: "candidates", descriptor: "qi:model-generate" },
    { name: "judge", descriptor: "qi:judge" },
    { name: "coverage", descriptor: "qi:coverage" },
    { name: "validate", descriptor: "qi:validate" },
    { name: "finalize", descriptor: "qi:finalize" },
]);
/**
 * Run the model-routed test-design workflow scoped to a narrowed set of atoms. Returns the full run
 * summary plus a count of narrowed atoms for caller bookkeeping. The caller is responsible for
 * merging the regenerated candidates with preserved-fresh candidates from the original run.
 */
export async function runScopedRegeneration(input, deps) {
    const plan = {
        id: QI.asQualityIntelligenceRunId(input.newRunId),
        requestedAt: input.requestedAt,
        plannerKind: "model-routed",
        stages: PLAN_STAGES,
    };
    const summary = await runQualityIntelligenceModelRoutedTestDesign({
        plan,
        envelopes: input.envelopes,
        ingestedAtoms: input.ingestedAtoms,
        provenanceRefs: input.provenanceRefs,
    }, deps);
    return { summary, narrowedAtomCount: input.ingestedAtoms.length };
}
