/**
 * reopen.ts — TS port of the auto-reopen-on-regression decision.
 *
 * Ports the decision embedded in cmd_apply_clusters (the-portal/.claude/scripts/
 * feedback-processor.py, the regression branch ~:1543) out of the DB-write code
 * into a pure function. When the clustering driver (cluster.ts) merges a new
 * report into a cluster that was already fixed/resolved/deferred (a "possible
 * regression" note), the cluster is auto-reopened. This computes the reopen
 * outcome from the cluster's prior status:
 *
 *   - deferred  → AGED-REOPEN  → status 'new',          annotate actionTaken,   no recurrence bump
 *   - otherwise → REGRESSION   → status 'investigating', annotate researchNotes, bump recurrenceCount
 *
 * The DB writes (the prisma update with `{ increment: 1 }` etc.) stay in the
 * adapter; this is the pure decision + the audit-note text. `now` is injected.
 * Reference is interleaved with DB I/O, so equivalence is by faithful
 * transcription + exhaustive unit tests (no clean isolated reference function to
 * run a cross-runtime harness against).
 */
/**
 * Compute the auto-reopen outcome for a cluster being merged into on a regression.
 * `wasStatus` is the cluster's status before reopen; `feedbackId` is the incoming
 * report; `now` is the injected ISO timestamp (reference uses new Date().toISOString()).
 */
export function computeReopen(cluster, feedbackId, now) {
    const wasStatus = cluster.status ?? null;
    const isAged = wasStatus === 'deferred';
    const newStatus = isAged ? 'new' : 'investigating';
    const noteTag = isAged ? 'AGED-REOPEN' : 'REGRESSION';
    const fixedInVersion = cluster.fixedInVersion || 'n/a';
    // Verbatim from the reference's regressionNote template.
    const note = `[${noteTag} ${now}] New report matched cluster previously marked '${wasStatus}' (fixedInVersion=${fixedInVersion}). Auto-reopened to '${newStatus}' for review. Report: ${feedbackId}`;
    return {
        newStatus,
        bumpRecurrence: !isAged,
        annotateField: isAged ? 'actionTaken' : 'researchNotes',
        noteTag,
        note,
    };
}
//# sourceMappingURL=reopen.js.map