"use strict";
/**
 * VariantRunPlan — the single, canonical resolution of "what kind of run is
 * this" for an agent-variants session.
 *
 * Historically the lifecycle policy (work-item topology, how variants are
 * provisioned, how they're committed, how they preview) was re-derived
 * independently at every stage from `projectContext.kind`,
 * `executionPlan.mode`, and framework detection — `SessionStore.approve`,
 * `WorktreeOrchestrator` provisioning, the commit path, and the preview
 * wiring each made the same `kind === 'fresh'` / `mode === 'vite_app'`
 * decisions in their own way. That spread the same handful of facts across
 * dozens of call sites and let them drift.
 *
 * This module collapses those facts into a *closed* discriminated union. There
 * are exactly three legal run shapes:
 *
 *   1. existing project              — clone+diff against the user's tree
 *   2. generated project, static     — inline HTML/CSS/JS, no runtime
 *   3. generated project, app (vite) — scaffolded Vite app with a dev server
 *
 * Every other lifecycle policy (topology / provision / commit) is a pure
 * function of which of those three a session is — see `runPlanPolicy`. Callers
 * resolve the plan once (at `approve` time, the first point where every input
 * is known) and read policy off it, rather than re-deriving from raw context.
 *
 * Preview is deliberately *not* a fixed field of the plan. For generated
 * projects it's determined (static → static_artifact, app → dev_server), but
 * for existing projects it's only known at success time — a `framework:'static'`
 * existing project previews as a materialized static artifact, anything else
 * proxies a dev server. That one genuinely-late decision is exposed via
 * `existingPreviewKind` rather than baked into the plan at resolve time.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveRunPlan = resolveRunPlan;
exports.runPlanPolicy = runPlanPolicy;
exports.resolveRunPlanPolicy = resolveRunPlanPolicy;
exports.existingPreviewKind = existingPreviewKind;
/**
 * Resolve the run plan from a project context. This is the single decision
 * point: `source` comes from `projectContext.kind`; for generated projects the
 * `runtime` comes from the agent's reported `executionPlan.mode`, defaulting to
 * `static` for source-less zero-to-one runs (which never report a plan).
 */
function resolveRunPlan(projectContext) {
    if (projectContext.kind === 'existing') {
        return { source: 'existing' };
    }
    // Generated (fresh) project. `executionPlan` is present only for
    // source-grounded runs (reported via `report_source_plan`); source-less
    // zero-to-one runs default to a static preview.
    const runtime = projectContext.executionPlan?.mode === 'vite_app' ? 'app' : 'static';
    return { source: 'generated', runtime };
}
/** Derive the lifecycle policy for a resolved plan. Total over the closed set. */
function runPlanPolicy(plan) {
    if (plan.source === 'existing') {
        return {
            topology: 'code_gen',
            provision: 'git_worktree',
            commit: 'apply_diff',
            needsScaffoldBase: false,
            // preview deferred to success time (static vs dev_server by framework).
        };
    }
    if (plan.runtime === 'static') {
        return {
            topology: 'static_preview',
            provision: 'none',
            commit: 'write_static_site',
            needsScaffoldBase: false,
            preview: 'static_artifact',
        };
    }
    // generated app (vite)
    return {
        topology: 'code_gen',
        provision: 'template_worktree',
        commit: 'materialize_project',
        needsScaffoldBase: true,
        preview: 'dev_server',
    };
}
/** Convenience: resolve and derive policy in one step. */
function resolveRunPlanPolicy(projectContext) {
    return runPlanPolicy(resolveRunPlan(projectContext));
}
/**
 * Preview surface for an existing-project variant, resolved at success time
 * from whether the variant materialized static files (framework `static`, no
 * dev command) or runs a dev server. Generated projects don't use this — their
 * preview is fixed by {@link runPlanPolicy}.
 */
function existingPreviewKind(hasStaticFiles) {
    return hasStaticFiles ? 'static_artifact' : 'dev_server';
}
//# sourceMappingURL=runPlan.js.map