/**
 * Gate telemetry — structured event logger for production_gate / task_no_progress
 * / tool_loop / write_scope_block fire sites.
 *
 * Provides observability data for v3 calibration decisions:
 *   - Is the confidence threshold (high/medium/low) correctly classifying prompts?
 *   - What is the ALLOW regex false-positive rate?
 *   - Are hard-stop thresholds appropriate?
 *
 * Events are appended as newline-delimited JSON to
 *   ~/.owlcoda/telemetry/gate-events-YYYY-MM-DD.jsonl
 *
 * fs writes are synchronous and fire-and-forget: any I/O error is silently
 * swallowed so telemetry can never interfere with the main conversation loop.
 *
 * 0.14.18
 */
import { appendFileSync, mkdirSync } from 'node:fs';
import { homedir } from 'node:os';
import { dirname, join } from 'node:path';
export const FIDELITY_ANCHOR_TYPES = [
    'path',
    'filename',
    'command',
    'number',
    'commit_hash',
    'tool_target',
    'line_ref',
];
export const FIDELITY_EVIDENCE_ORIGINS = [
    'tool_call',
    'project_map',
    'instructions',
    'compaction_summary',
    'retained_turn',
    'unknown',
];
export const FIDELITY_FACT_TYPES = [
    'path',
    'number',
    'command',
    'commit_hash',
    'decision',
];
export const FIDELITY_COMPACTION_FACT_REASONS = [
    'dropped',
    'rephrased',
    'kept',
    'uncertain',
];
function telemetryFilePath() {
    const owlcodaHome = process.env['OWLCODA_HOME'] ?? join(homedir(), '.owlcoda');
    const dir = join(owlcodaHome, 'telemetry');
    const date = new Date().toISOString().slice(0, 10); // YYYY-MM-DD
    return join(dir, `gate-events-${date}.jsonl`);
}
export function recordGateEvent(event) {
    try {
        const filePath = telemetryFilePath();
        const dir = dirname(filePath);
        mkdirSync(dir, { recursive: true });
        appendFileSync(filePath, JSON.stringify(event) + '\n', 'utf8');
    }
    catch {
        // Telemetry must never crash the main process. Swallow all errors silently.
    }
}
//# sourceMappingURL=gate-telemetry.js.map