/**
 * Phase 3 — edges pointing to `:Trashed` targets.
 *
 * Maxy's `:Trashed` label is the soft-delete signal. Edges from live
 * nodes to `:Trashed` nodes persist for audit, but they should be
 * marked so operators and downstream readers can filter them out.
 *
 * This phase scans every edge whose target carries `:Trashed`, sets
 * `staleTarget: true` and `staleTargetMarkedAt` on the edge, and counts
 * how many were freshly marked vs already-marked. No edge deletion,
 * ever — audit trail preserved.
 *
 * Reframed from the gbrain spec's "dead :MENTIONS" phase because the
 * maxy ontology has no symmetric :MENTIONS edge; the equivalent
 * cleanup is "edges to soft-deleted targets".
 */
export async function phaseDeadEdges(ctx) {
    const start = Date.now();
    const { accountId, session } = ctx;
    const result = await session.run(`MATCH (src)-[r]->(tgt:Trashed)
     WHERE src.accountId = $accountId
       AND tgt.accountId = $accountId
       AND coalesce(r.staleTarget, false) = false
     SET r.staleTarget = true,
         r.staleTargetMarkedAt = datetime()
     RETURN count(r) AS applied`, { accountId });
    const applied = Number(result.records[0]?.get("applied") ?? 0);
    const durationSec = Math.round((Date.now() - start) / 1000);
    process.stderr.write(`[dream-cycle:phase-3] durationSec=${durationSec} proposed=${applied} applied=${applied} deferred=0\n`);
    return {
        phase: 3,
        name: "dead-edges",
        durationSec,
        proposed: applied,
        applied,
        deferred: 0,
    };
}
//# sourceMappingURL=phase-dead-edges.js.map