"use strict";
/**
 * Correlation IDs for linking logs, Sentry events, and Amplitude analytics.
 *
 * - sessionId: stable across the entire CLI invocation (reuses analytics anonymousId)
 * - runId: new UUID per agent attempt (reset on stall-retry)
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.initCorrelation = initCorrelation;
exports.getSessionId = getSessionId;
exports.getRunId = getRunId;
exports.getSessionStartMs = getSessionStartMs;
exports.rotateRunId = rotateRunId;
const uuid_1 = require("uuid");
let _sessionId = null;
let _runId = null;
let _sessionStartMs = null;
/** Initialize with the analytics session ID. Call once at startup. */
function initCorrelation(sessionId) {
    _sessionId = sessionId;
    _runId = (0, uuid_1.v4)().slice(0, 8); // Short for log readability
    _sessionStartMs = Date.now();
}
/** Get the session-level correlation ID. */
function getSessionId() {
    return _sessionId ?? 'unknown';
}
/** Get the current run-level correlation ID. */
function getRunId() {
    return _runId ?? 'unknown';
}
/**
 * Epoch-ms when this wizard session started. Used by the TUI Logs tab to
 * scope the live-tail to lines from the current session (the per-project
 * `log.txt` is append-only across runs, so without scoping users see
 * yesterday's runs above today's). Null until `initCorrelation` runs.
 */
function getSessionStartMs() {
    return _sessionStartMs;
}
/** Create a new run ID (call on agent retry / stall recovery). */
function rotateRunId() {
    _runId = (0, uuid_1.v4)().slice(0, 8);
    return _runId;
}
