"use strict";
/**
 * Build-Structure Score (W1.8 of F-NEW-PRODUCT-AGENT-VISIBILITY-CLUSTER-2026-05-12).
 *
 * Maps the W1.7 OWASP Agentic ScanReport + AgentManifest into the
 * AgentBuildStructureDimensions shape that feeds the third trust-score
 * dimension. Together with agent_activity (runtime behavior) and
 * operator_activity (human reviews), it produces a three-dimensional trust
 * score per Thomas Layer 0 directive 2026-05-12.
 *
 * The composite is intentionally a transparent linear formula so customers can
 * reproduce the math from the scan report alone (auditor-grade).
 *
 * @connexum/ai-governance  F-NEW-PRODUCT-BUILD-SCORE-DIMENSION
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractBuildStructureDimensions = extractBuildStructureDimensions;
const capability_classes_js_1 = require("./capability-classes.js");
/**
 * Derive build-structure dimensions from a manifest + its OWASP scan report.
 *
 * Composite formula (0-100, transparent):
 *   contributors (each 0-100):
 *     owasp_agentic_score                       (weight 0.35)
 *     hook_coverage 0/3 / 1/3 / 2/3 / 3/3 -> 0/33/67/100  (weight 0.20)
 *     capability_class_coverage / 7 * 100       (weight 0.15)
 *     has_human_in_loop ? 100 : 0               (weight 0.10)
 *     plugin_integrity_verified ? 100 : 0       (weight 0.10)
 *     proxy_routed ? 100 : 0                    (weight 0.10)
 */
function extractBuildStructureDimensions(manifest, scan) {
    const hookCount = [
        manifest.hooks?.preToolUse === true,
        manifest.hooks?.postToolUse === true,
        manifest.hooks?.postResponse === true,
    ].filter(Boolean).length;
    const declaredCaps = new Set();
    for (const id of manifest.declaredForbiddenCapabilities ?? [])
        declaredCaps.add(id);
    for (const g of manifest.declaredApprovalGates ?? [])
        declaredCaps.add(g.capability);
    const hasHumanInLoop = (manifest.declaredApprovalGates ?? []).length > 0;
    const pluginVerified = manifest.pluginIntegrityVerified === true;
    const proxyRouted = manifest.llmProvider?.startsWith('connexum-proxy/') ?? false;
    // Composite (weighted, all components in 0-100):
    const hookComponent = Math.round((hookCount / 3) * 100);
    const capCoverage = Math.round((declaredCaps.size / capability_classes_js_1.ALL_CAPABILITY_CLASS_IDS.length) * 100);
    const composite = Math.round(scan.buildStructureScore * 0.35 +
        hookComponent * 0.2 +
        capCoverage * 0.15 +
        (hasHumanInLoop ? 100 : 0) * 0.1 +
        (pluginVerified ? 100 : 0) * 0.1 +
        (proxyRouted ? 100 : 0) * 0.1);
    return {
        owasp_agentic_score: scan.buildStructureScore,
        hook_coverage_count: hookCount,
        declared_capability_class_count: declaredCaps.size,
        has_human_in_loop: hasHumanInLoop,
        plugin_integrity_verified: pluginVerified,
        proxy_routed: proxyRouted,
        composite,
    };
}
//# sourceMappingURL=build-structure-score.js.map