import path from 'node:path';
import { nowIso, writeJsonAtomic } from '../fsx.js';
export const CODEX_0139_REAL_PROBE_NAMES = [
    'code_mode_web_search',
    'rich_tool_schema',
    'doctor_env_redaction',
    'marketplace_source_json',
    'plugin_catalog_cache',
    'sandbox_profile_alias',
    'interrupt_agent_event',
    'image_referenced_path',
    'sandbox_proxy_preservation'
];
export function codex0139ProbeArtifactPath(root) {
    return path.join(root, '.sneakoscope', 'codex-0139-real-probes.json');
}
export function codex0139MissionProbeArtifactPath(root, missionId) {
    return path.join(root, '.sneakoscope', 'missions', missionId, 'codex-0139-real-probes.json');
}
export function codex0139DistProbeArtifactPath(root) {
    return path.join(root, 'dist', 'codex-0139-real-probes.json');
}
export async function writeCodex0139RealProbeResult(root, result, opts = {}) {
    const rootArtifact = codex0139ProbeArtifactPath(root);
    await writeJsonAtomic(rootArtifact, result);
    let missionArtifact = null;
    if (opts.missionId) {
        missionArtifact = codex0139MissionProbeArtifactPath(root, opts.missionId);
        await writeJsonAtomic(missionArtifact, result);
    }
    let distArtifact = null;
    if (opts.writeDist !== false) {
        distArtifact = codex0139DistProbeArtifactPath(root);
        await writeJsonAtomic(distArtifact, result);
    }
    return { root_artifact: rootArtifact, mission_artifact: missionArtifact, dist_artifact: distArtifact };
}
export function skippedCodex0139Probe(blocker, evidence = {}) {
    return {
        ok: false,
        mode: 'skipped',
        duration_ms: 0,
        artifact_paths: [],
        evidence,
        blockers: [blocker]
    };
}
export function codex0139ProbeTail(text, limit = 4000) {
    const raw = String(text || '');
    return raw.length <= limit ? raw : raw.slice(raw.length - limit);
}
export function buildCodex0139RealProbeResult(input) {
    const skipped = CODEX_0139_REAL_PROBE_NAMES.filter((name) => input.probes[name]?.mode === 'skipped');
    const failed = CODEX_0139_REAL_PROBE_NAMES.filter((name) => input.probes[name] && input.probes[name].ok !== true && input.probes[name].mode !== 'skipped');
    const blockers = [
        ...(input.extraBlockers || []),
        ...CODEX_0139_REAL_PROBE_NAMES.flatMap((name) => input.probes[name]?.blockers || []),
        ...(input.requireReal && skipped.length ? skipped.map((name) => `require_real_skipped:${name}`) : [])
    ];
    return {
        schema: 'sks.codex-0139-real-probe-result.v1',
        generated_at: nowIso(),
        codex_bin: input.codexBin,
        version_text: input.versionText,
        parsed_version: input.parsedVersion,
        require_real: input.requireReal,
        overall_ok: input.requireReal ? blockers.length === 0 && failed.length === 0 && skipped.length === 0 : failed.length === 0,
        probe_timeout_ms: input.timeoutMs,
        probes: input.probes,
        skipped,
        blockers: [...new Set(blockers)]
    };
}
//# sourceMappingURL=codex-0139-real-probes.js.map