import { booleanField, normalizeWhitespace, stringField, truncateText, } from "@best-agent/foundation";
import { readsSensitiveShellCommand } from "../../policy/runtime-policy.js";
export function extractShellCommandFromEvidence(record, mode = "evaluation") {
    if (mode === "evaluation") {
        return (stringField(record.payload, "commandForEvaluation") ??
            stringField(record.payload, "evaluationCommand") ??
            stringField(record.payload, "command"));
    }
    if (mode === "provider") {
        return stringField(record.payload, "commandForProvider");
    }
    return (stringField(record.payload, "commandDisplay") ??
        stringField(record.payload, "commandForProvider") ??
        stringField(record.payload, "command"));
}
export function isSensitiveShellEvidence(record) {
    if (stringField(record.payload, "sensitivity") === "sensitive-redacted") {
        return true;
    }
    if (booleanField(record.payload, "indexable") === false) {
        return true;
    }
    const command = extractShellCommandFromEvidence(record, "evaluation");
    return command ? readsSensitiveShellCommand(command) : false;
}
export function summarizeShellEvidence(record) {
    const command = extractShellCommandFromEvidence(record, "display") ?? record.summary;
    const outcome = stringField(record.payload, "outcome") ?? "unknown";
    const output = extractRedactedShellOutput(record);
    return [
        `- Shell ${outcome}: ${truncateForReasoning(command)}`,
        output ? `  ${truncateForReasoning(output)}` : undefined,
    ]
        .filter((line) => Boolean(line))
        .join("\n");
}
function extractRedactedShellOutput(record) {
    const candidates = [
        stringField(record.payload, "outputPreview"),
        stringField(record.payload, "stdoutSummary"),
        stringField(record.payload, "stderrSummary"),
    ].filter((value) => Boolean(value?.trim()));
    return candidates.join("\n");
}
function truncateForReasoning(value) {
    return truncateText(normalizeWhitespace(value), 240);
}
//# sourceMappingURL=shell-evidence-summary.js.map