/**
 * Auto-Pack Generator (W2.3 of F-NEW-PRODUCT-AGENT-VISIBILITY-CLUSTER-2026-05-12).
 *
 * Closes the loop between W1.7 (OWASP Agentic scanner) and W1.5 (capability-
 * class company packs). Customer scans an agent manifest -> auto-pack
 * generator proposes a company pack -> customer accepts / edits / rejects
 * each rule inline -> resulting pack is publishable.
 *
 * Customer flow:
 *   const manifest = ... ;                                // from W2.1/W2.2 discovery
 *   const { pack, scanReport, proposedRules } =
 *     autoGenerateCompanyPack(manifest, { packIdPrefix: 'agent-mailer' });
 *   // Customer reviews scanReport.findings + proposedRules in the dashboard,
 *   // selects which rules to accept, optionally edits actions:
 *   const acceptedRules = customerSelection;
 *   const final = autoGenerateCompanyPack(manifest, {
 *     packIdPrefix: 'agent-mailer',
 *     acceptedRules,
 *   }).pack;
 *   // final is a CompliancePackWithClassifiers ready to publish via
 *   // PackVersionStore.publishVersion().
 *
 * @connexum/ai-governance  F-NEW-PRODUCT-AUTO-PACK-GENERATOR
 */
import { scanAgent } from './owasp-agentic-scanner.js';
import { buildCompanyPack, } from './company-pack-builder.js';
const ORG_FROM_MANIFEST = (m) => {
    // The manifest doesn't currently carry orgId; in the discovery flow
    // (W2.1/W2.2) the caller knows the org. For the slice we default to
    // 'org-unknown' and require callers to override at activation time.
    return m.orgId ?? 'org-unknown';
};
export function autoGenerateCompanyPack(manifest, options = {}) {
    const scanReport = scanAgent(manifest);
    const proposedRules = scanReport.suggestedRules;
    const acceptedRules = options.acceptedRules
        ? [...options.acceptedRules]
        : options.acceptAllSuggestedRules
            ? [...proposedRules]
            : [];
    const reviewRequiredRisks = Array.from(new Set(scanReport.findings
        .filter((f) => !f.suggestedRule)
        .map((f) => f.risk)));
    const packIdPrefix = options.packIdPrefix ?? 'auto-pack';
    const pack = buildCompanyPack({
        id: `${packIdPrefix}-${manifest.agentId}`,
        name: `Auto-generated pack for ${manifest.name ?? manifest.agentId}`,
        orgId: ORG_FROM_MANIFEST(manifest),
        version: options.version ?? '0.1.0',
        rules: acceptedRules,
        isolation: options.isolation,
        description: `Auto-generated from OWASP Agentic scan on ${new Date().toISOString().slice(0, 10)}. ` +
            `${scanReport.findings.length} findings (CRIT=${scanReport.countsBySeverity.CRIT}, ` +
            `HIGH=${scanReport.countsBySeverity.HIGH}, MED=${scanReport.countsBySeverity.MED}, ` +
            `LOW=${scanReport.countsBySeverity.LOW}). Build-structure score: ` +
            `${scanReport.buildStructureScore}. ${acceptedRules.length}/${proposedRules.length} ` +
            `rules accepted by customer.`,
    });
    return {
        pack,
        scanReport,
        proposedRules,
        acceptedRules,
        reviewRequiredRisks,
    };
}
//# sourceMappingURL=auto-pack-generator.js.map