@complior/engine 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.well-known/ai-compliance.json +16 -0
- package/COMPLIANCE.md +64 -0
- package/data/data-integrity.test.ts +75 -0
- package/data/eval/eval-mappings.json +33 -0
- package/data/llm/model-pricing.json +15 -0
- package/data/llm/model-routing.json +36 -0
- package/data/onboarding/risk-profile.json +17 -0
- package/data/regulations/eu-ai-act/README.md +245 -0
- package/data/regulations/eu-ai-act/applicability-tree.json +160 -0
- package/data/regulations/eu-ai-act/cross-mapping.json +175 -0
- package/data/regulations/eu-ai-act/localization.json +186 -0
- package/data/regulations/eu-ai-act/obligations.json +3981 -0
- package/data/regulations/eu-ai-act/regulation-meta.json +482 -0
- package/data/regulations/eu-ai-act/scoring.json +342 -0
- package/data/regulations/eu-ai-act/technical-requirements.json +2590 -0
- package/data/regulations/eu-ai-act/timeline.json +160 -0
- package/data/regulations/jurisdictions/at.json +15 -0
- package/data/regulations/jurisdictions/be.json +15 -0
- package/data/regulations/jurisdictions/bg.json +15 -0
- package/data/regulations/jurisdictions/cy.json +15 -0
- package/data/regulations/jurisdictions/cz.json +15 -0
- package/data/regulations/jurisdictions/de.json +15 -0
- package/data/regulations/jurisdictions/dk.json +15 -0
- package/data/regulations/jurisdictions/ee.json +15 -0
- package/data/regulations/jurisdictions/es.json +15 -0
- package/data/regulations/jurisdictions/fi.json +15 -0
- package/data/regulations/jurisdictions/fr.json +15 -0
- package/data/regulations/jurisdictions/gr.json +15 -0
- package/data/regulations/jurisdictions/hr.json +15 -0
- package/data/regulations/jurisdictions/hu.json +15 -0
- package/data/regulations/jurisdictions/ie.json +15 -0
- package/data/regulations/jurisdictions/is.json +15 -0
- package/data/regulations/jurisdictions/it.json +15 -0
- package/data/regulations/jurisdictions/li.json +15 -0
- package/data/regulations/jurisdictions/lt.json +15 -0
- package/data/regulations/jurisdictions/lu.json +15 -0
- package/data/regulations/jurisdictions/lv.json +15 -0
- package/data/regulations/jurisdictions/mt.json +15 -0
- package/data/regulations/jurisdictions/nl.json +15 -0
- package/data/regulations/jurisdictions/no.json +15 -0
- package/data/regulations/jurisdictions/pl.json +15 -0
- package/data/regulations/jurisdictions/pt.json +15 -0
- package/data/regulations/jurisdictions/ro.json +15 -0
- package/data/regulations/jurisdictions/se.json +15 -0
- package/data/regulations/jurisdictions/si.json +15 -0
- package/data/regulations/jurisdictions/sk.json +15 -0
- package/data/scanner/check-id-categories.json +81 -0
- package/data/scanner/confidence-params.json +16 -0
- package/data/scanner/limits.json +4 -0
- package/data/schemas/http-contract-sample.json +79 -0
- package/data/schemas/http-contract.json +144 -0
- package/data/semgrep-rules/bare-call.yaml +37 -0
- package/data/semgrep-rules/injection.yaml +73 -0
- package/data/semgrep-rules/missing-error-handling.yaml +58 -0
- package/data/semgrep-rules/unsafe-deser.yaml +65 -0
- package/data/templates/eu-ai-act/ai-literacy.md +184 -0
- package/data/templates/eu-ai-act/art5-screening.md +131 -0
- package/data/templates/eu-ai-act/data-governance.md +145 -0
- package/data/templates/eu-ai-act/declaration-of-conformity.md +161 -0
- package/data/templates/eu-ai-act/fria.md +127 -0
- package/data/templates/eu-ai-act/gpai-systemic-risk.md +150 -0
- package/data/templates/eu-ai-act/gpai-transparency.md +166 -0
- package/data/templates/eu-ai-act/incident-report.md +188 -0
- package/data/templates/eu-ai-act/instructions-for-use.md +202 -0
- package/data/templates/eu-ai-act/monitoring-policy.md +110 -0
- package/data/templates/eu-ai-act/qms.md +180 -0
- package/data/templates/eu-ai-act/risk-management-system.md +123 -0
- package/data/templates/eu-ai-act/technical-documentation.md +287 -0
- package/data/templates/eu-ai-act/worker-notification.md +143 -0
- package/data/templates/policies/biometrics-ai-policy.md +214 -0
- package/data/templates/policies/critical-infra-ai-policy.md +228 -0
- package/data/templates/policies/education-ai-policy.md +184 -0
- package/data/templates/policies/finance-ai-policy.md +191 -0
- package/data/templates/policies/healthcare-ai-policy.md +197 -0
- package/data/templates/policies/hr-ai-policy.md +178 -0
- package/data/templates/policies/legal-ai-policy.md +189 -0
- package/data/templates/policies/migration-ai-policy.md +239 -0
- package/engine.log +7 -0
- package/package.json +74 -0
- package/src/composition-root.ts +791 -0
- package/src/data/eval/conformity-tests.test.ts +122 -0
- package/src/data/eval/ct-1-transparency.ts +106 -0
- package/src/data/eval/ct-10-gpai.ts +25 -0
- package/src/data/eval/ct-11-industry.ts +42 -0
- package/src/data/eval/ct-2-oversight.ts +41 -0
- package/src/data/eval/ct-3-explanation.ts +14 -0
- package/src/data/eval/ct-4-bias.ts +83 -0
- package/src/data/eval/ct-5-accuracy.ts +41 -0
- package/src/data/eval/ct-6-robustness.ts +81 -0
- package/src/data/eval/ct-7-prohibited.ts +52 -0
- package/src/data/eval/ct-8-logging.ts +68 -0
- package/src/data/eval/ct-9-risk-awareness.ts +33 -0
- package/src/data/eval/deterministic-evaluator.ts +120 -0
- package/src/data/eval/index.ts +55 -0
- package/src/data/eval/judge-prompts.ts +146 -0
- package/src/data/eval/llm-judged-tests.ts +279 -0
- package/src/data/eval/llm-tests.test.ts +83 -0
- package/src/data/eval/remediation/ct-1-transparency.ts +91 -0
- package/src/data/eval/remediation/ct-10-gpai.ts +94 -0
- package/src/data/eval/remediation/ct-11-industry.ts +94 -0
- package/src/data/eval/remediation/ct-2-oversight.ts +71 -0
- package/src/data/eval/remediation/ct-3-explanation.ts +70 -0
- package/src/data/eval/remediation/ct-4-bias.ts +70 -0
- package/src/data/eval/remediation/ct-5-accuracy.ts +70 -0
- package/src/data/eval/remediation/ct-6-robustness.ts +70 -0
- package/src/data/eval/remediation/ct-7-prohibited.ts +94 -0
- package/src/data/eval/remediation/ct-8-logging.ts +94 -0
- package/src/data/eval/remediation/ct-9-risk-awareness.ts +94 -0
- package/src/data/eval/remediation/index.ts +89 -0
- package/src/data/eval/remediation/owasp-art5.ts +15 -0
- package/src/data/eval/remediation/owasp-llm01.ts +72 -0
- package/src/data/eval/remediation/owasp-llm02.ts +72 -0
- package/src/data/eval/remediation/owasp-llm03.ts +15 -0
- package/src/data/eval/remediation/owasp-llm04.ts +15 -0
- package/src/data/eval/remediation/owasp-llm05.ts +15 -0
- package/src/data/eval/remediation/owasp-llm06.ts +15 -0
- package/src/data/eval/remediation/owasp-llm07.ts +15 -0
- package/src/data/eval/remediation/owasp-llm08.ts +15 -0
- package/src/data/eval/remediation/owasp-llm09.ts +15 -0
- package/src/data/eval/remediation/owasp-llm10.ts +15 -0
- package/src/data/eval/remediation/remediation.test.ts +229 -0
- package/src/data/eval/remediation/test-mapping.ts +290 -0
- package/src/data/eval/security-rubrics.ts +381 -0
- package/src/data/finding-explanations.json +453 -0
- package/src/data/industry-patterns.ts +161 -0
- package/src/data/registry-cards.ts +368 -0
- package/src/data/regulation/index.ts +5 -0
- package/src/data/regulation/jurisdiction-data.test.ts +73 -0
- package/src/data/regulation/jurisdiction-data.ts +65 -0
- package/src/data/regulation/regulation-data.ts +19 -0
- package/src/data/regulation/regulation-loader.test.ts +107 -0
- package/src/data/regulation/regulation-loader.ts +56 -0
- package/src/data/scanner-constants.ts +46 -0
- package/src/data/schemas/schemas-core.ts +140 -0
- package/src/data/schemas/schemas-supplementary.ts +211 -0
- package/src/data/schemas/schemas.ts +28 -0
- package/src/data/security/attack-probes.test.ts +62 -0
- package/src/data/security/attack-probes.ts +496 -0
- package/src/data/security/eu-ai-act-security.ts +40 -0
- package/src/data/security/index.ts +19 -0
- package/src/data/security/mitre-atlas.test.ts +43 -0
- package/src/data/security/mitre-atlas.ts +93 -0
- package/src/data/security/nist-ai-rmf.ts +43 -0
- package/src/data/security/owasp-llm-top10.test.ts +60 -0
- package/src/data/security/owasp-llm-top10.ts +138 -0
- package/src/data/template-registry.ts +53 -0
- package/src/data/tool-versions.json +22 -0
- package/src/domain/audit/audit-package.test.ts +152 -0
- package/src/domain/audit/audit-package.ts +166 -0
- package/src/domain/audit/audit-trail.test.ts +121 -0
- package/src/domain/audit/audit-trail.ts +174 -0
- package/src/domain/audit/index.ts +8 -0
- package/src/domain/audit/permissions-matrix.test.ts +136 -0
- package/src/domain/audit/permissions-matrix.ts +121 -0
- package/src/domain/certification/adversarial/bias-tests.ts +95 -0
- package/src/domain/certification/adversarial/evaluators.ts +304 -0
- package/src/domain/certification/adversarial/index.ts +11 -0
- package/src/domain/certification/adversarial/prompt-injection.ts +103 -0
- package/src/domain/certification/adversarial/safety-boundary.ts +132 -0
- package/src/domain/certification/aiuc1-readiness.test.ts +236 -0
- package/src/domain/certification/aiuc1-readiness.ts +298 -0
- package/src/domain/certification/aiuc1-requirements.ts +235 -0
- package/src/domain/certification/index.ts +10 -0
- package/src/domain/certification/redteam-runner.test.ts +97 -0
- package/src/domain/certification/redteam-runner.ts +205 -0
- package/src/domain/certification/test-runner.test.ts +232 -0
- package/src/domain/certification/test-runner.ts +289 -0
- package/src/domain/cost/cost-estimator.test.ts +187 -0
- package/src/domain/cost/cost-estimator.ts +133 -0
- package/src/domain/disclaimer.test.ts +52 -0
- package/src/domain/disclaimer.ts +39 -0
- package/src/domain/documents/ai-enricher.test.ts +120 -0
- package/src/domain/documents/ai-enricher.ts +159 -0
- package/src/domain/documents/document-generator.test.ts +318 -0
- package/src/domain/documents/document-generator.ts +239 -0
- package/src/domain/documents/index.ts +9 -0
- package/src/domain/documents/passport-helpers.ts +25 -0
- package/src/domain/documents/policy-generator.test.ts +252 -0
- package/src/domain/documents/policy-generator.ts +94 -0
- package/src/domain/documents/worker-notification-generator.test.ts +162 -0
- package/src/domain/documents/worker-notification-generator.ts +141 -0
- package/src/domain/eval/adapters/adapter-port.ts +94 -0
- package/src/domain/eval/adapters/adapters.test.ts +303 -0
- package/src/domain/eval/adapters/anthropic-adapter.ts +57 -0
- package/src/domain/eval/adapters/auto-detect.ts +104 -0
- package/src/domain/eval/adapters/create-chat-adapter.ts +106 -0
- package/src/domain/eval/adapters/custom-adapter.ts +74 -0
- package/src/domain/eval/adapters/http-adapter.ts +66 -0
- package/src/domain/eval/adapters/index.ts +7 -0
- package/src/domain/eval/adapters/ollama-adapter.ts +48 -0
- package/src/domain/eval/adapters/openai-adapter.ts +58 -0
- package/src/domain/eval/adapters/with-timeout.ts +25 -0
- package/src/domain/eval/conformity-score.test.ts +161 -0
- package/src/domain/eval/conformity-score.ts +135 -0
- package/src/domain/eval/eval-constants.ts +55 -0
- package/src/domain/eval/eval-evidence.test.ts +85 -0
- package/src/domain/eval/eval-evidence.ts +103 -0
- package/src/domain/eval/eval-fix-generator.test.ts +421 -0
- package/src/domain/eval/eval-fix-generator.ts +205 -0
- package/src/domain/eval/eval-passport.test.ts +82 -0
- package/src/domain/eval/eval-passport.ts +89 -0
- package/src/domain/eval/eval-remediation-report.test.ts +682 -0
- package/src/domain/eval/eval-remediation-report.ts +170 -0
- package/src/domain/eval/eval-report.ts +108 -0
- package/src/domain/eval/eval-runner.test.ts +609 -0
- package/src/domain/eval/eval-runner.ts +593 -0
- package/src/domain/eval/eval-to-findings.test.ts +293 -0
- package/src/domain/eval/eval-to-findings.ts +83 -0
- package/src/domain/eval/index.ts +31 -0
- package/src/domain/eval/llm-judge.test.ts +139 -0
- package/src/domain/eval/llm-judge.ts +168 -0
- package/src/domain/eval/remediation-types.ts +90 -0
- package/src/domain/eval/security-integration.test.ts +196 -0
- package/src/domain/eval/security-integration.ts +136 -0
- package/src/domain/eval/types.test.ts +173 -0
- package/src/domain/eval/types.ts +244 -0
- package/src/domain/eval/verdict-utils.ts +45 -0
- package/src/domain/fixer/create-fixer.ts +101 -0
- package/src/domain/fixer/diff.ts +70 -0
- package/src/domain/fixer/fix-history.ts +23 -0
- package/src/domain/fixer/fixer.test.ts +306 -0
- package/src/domain/fixer/index.ts +9 -0
- package/src/domain/fixer/strategies/bandit-fix.ts +61 -0
- package/src/domain/fixer/strategies/bias-testing.ts +49 -0
- package/src/domain/fixer/strategies/ci-compliance.ts +57 -0
- package/src/domain/fixer/strategies/content-marking.ts +45 -0
- package/src/domain/fixer/strategies/cve-upgrade.ts +66 -0
- package/src/domain/fixer/strategies/data-governance.ts +65 -0
- package/src/domain/fixer/strategies/disclosure.ts +69 -0
- package/src/domain/fixer/strategies/doc-code-sync.ts +53 -0
- package/src/domain/fixer/strategies/documentation.ts +59 -0
- package/src/domain/fixer/strategies/error-handler.ts +63 -0
- package/src/domain/fixer/strategies/hitl-gate.ts +67 -0
- package/src/domain/fixer/strategies/index.ts +61 -0
- package/src/domain/fixer/strategies/kill-switch-test.ts +85 -0
- package/src/domain/fixer/strategies/kill-switch.ts +53 -0
- package/src/domain/fixer/strategies/license-fix.ts +57 -0
- package/src/domain/fixer/strategies/log-retention.ts +40 -0
- package/src/domain/fixer/strategies/logging.ts +59 -0
- package/src/domain/fixer/strategies/metadata.ts +45 -0
- package/src/domain/fixer/strategies/permission-guard.ts +84 -0
- package/src/domain/fixer/strategies/record-keeping.ts +69 -0
- package/src/domain/fixer/strategies/secret-rotation.ts +52 -0
- package/src/domain/fixer/strategies.test.ts +341 -0
- package/src/domain/fixer/template-engine.test.ts +64 -0
- package/src/domain/fixer/template-engine.ts +38 -0
- package/src/domain/fixer/types.ts +88 -0
- package/src/domain/frameworks/aiuc1-framework.test.ts +159 -0
- package/src/domain/frameworks/aiuc1-framework.ts +126 -0
- package/src/domain/frameworks/collect-foundation-metrics.test.ts +96 -0
- package/src/domain/frameworks/collect-foundation-metrics.ts +34 -0
- package/src/domain/frameworks/eu-ai-act-framework.test.ts +117 -0
- package/src/domain/frameworks/eu-ai-act-framework.ts +100 -0
- package/src/domain/frameworks/framework-registry.test.ts +91 -0
- package/src/domain/frameworks/framework-registry.ts +38 -0
- package/src/domain/frameworks/index.ts +8 -0
- package/src/domain/frameworks/mitre-atlas-framework.test.ts +53 -0
- package/src/domain/frameworks/mitre-atlas-framework.ts +53 -0
- package/src/domain/frameworks/owasp-llm-framework.test.ts +77 -0
- package/src/domain/frameworks/owasp-llm-framework.ts +54 -0
- package/src/domain/frameworks/score-plugin-framework.ts +117 -0
- package/src/domain/fria/fria-generator.test.ts +273 -0
- package/src/domain/fria/fria-generator.ts +366 -0
- package/src/domain/import/promptfoo-importer.test.ts +103 -0
- package/src/domain/import/promptfoo-importer.ts +151 -0
- package/src/domain/onboarding/guided-onboarding.test.ts +144 -0
- package/src/domain/onboarding/guided-onboarding.ts +135 -0
- package/src/domain/passport/builder/domain-mapper.ts +9 -0
- package/src/domain/passport/builder/manifest-builder.test.ts +546 -0
- package/src/domain/passport/builder/manifest-builder.ts +535 -0
- package/src/domain/passport/builder/manifest-diff.test.ts +105 -0
- package/src/domain/passport/builder/manifest-diff.ts +89 -0
- package/src/domain/passport/builder/manifest-files.ts +17 -0
- package/src/domain/passport/crypto-signer.test.ts +93 -0
- package/src/domain/passport/crypto-signer.ts +157 -0
- package/src/domain/passport/discovery/agent-discovery.test.ts +296 -0
- package/src/domain/passport/discovery/agent-discovery.ts +325 -0
- package/src/domain/passport/discovery/autonomy-analyzer.test.ts +141 -0
- package/src/domain/passport/discovery/autonomy-analyzer.ts +113 -0
- package/src/domain/passport/discovery/permission-scanner.test.ts +191 -0
- package/src/domain/passport/discovery/permission-scanner.ts +414 -0
- package/src/domain/passport/export/a2a-mapper.ts +75 -0
- package/src/domain/passport/export/aiuc1-mapper.ts +126 -0
- package/src/domain/passport/export/export.test.ts +207 -0
- package/src/domain/passport/export/index.ts +41 -0
- package/src/domain/passport/export/nist-mapper.ts +227 -0
- package/src/domain/passport/import/a2a-importer.test.ts +133 -0
- package/src/domain/passport/import/a2a-importer.ts +156 -0
- package/src/domain/passport/import/index.ts +2 -0
- package/src/domain/passport/index.ts +32 -0
- package/src/domain/passport/obligation-field-map.test.ts +113 -0
- package/src/domain/passport/obligation-field-map.ts +117 -0
- package/src/domain/passport/passport-validator.test.ts +156 -0
- package/src/domain/passport/passport-validator.ts +126 -0
- package/src/domain/passport/scan-to-compliance.test.ts +336 -0
- package/src/domain/passport/scan-to-compliance.ts +166 -0
- package/src/domain/passport/test-generator.test.ts +93 -0
- package/src/domain/passport/test-generator.ts +136 -0
- package/src/domain/proxy/index.ts +11 -0
- package/src/domain/proxy/json-rpc.test.ts +72 -0
- package/src/domain/proxy/json-rpc.ts +53 -0
- package/src/domain/proxy/policy-engine.test.ts +259 -0
- package/src/domain/proxy/policy-engine.ts +137 -0
- package/src/domain/proxy/proxy-bridge.ts +125 -0
- package/src/domain/proxy/proxy-interceptor.test.ts +184 -0
- package/src/domain/proxy/proxy-interceptor.ts +120 -0
- package/src/domain/proxy/proxy-types.ts +35 -0
- package/src/domain/registry/compute-agent-score.test.ts +279 -0
- package/src/domain/registry/compute-agent-score.ts +162 -0
- package/src/domain/reporter/audit-report.test.ts +87 -0
- package/src/domain/reporter/audit-report.ts +116 -0
- package/src/domain/reporter/badge-generator.test.ts +54 -0
- package/src/domain/reporter/badge-generator.ts +40 -0
- package/src/domain/reporter/compliance-md.ts +45 -0
- package/src/domain/reporter/index.ts +7 -0
- package/src/domain/reporter/pdf-renderer.ts +282 -0
- package/src/domain/reporter/share.test.ts +92 -0
- package/src/domain/reporter/share.ts +80 -0
- package/src/domain/scanner/ast/swc-analyzer.test.ts +49 -0
- package/src/domain/scanner/ast/swc-analyzer.ts +124 -0
- package/src/domain/scanner/attestations.ts +97 -0
- package/src/domain/scanner/checks/ai-disclosure.test.ts +90 -0
- package/src/domain/scanner/checks/ai-disclosure.ts +54 -0
- package/src/domain/scanner/checks/ai-literacy.ts +163 -0
- package/src/domain/scanner/checks/behavioral-constraints.test.ts +167 -0
- package/src/domain/scanner/checks/behavioral-constraints.ts +86 -0
- package/src/domain/scanner/checks/compliance-metadata.ts +63 -0
- package/src/domain/scanner/checks/content-marking.ts +74 -0
- package/src/domain/scanner/checks/dep-deep-scan.test.ts +318 -0
- package/src/domain/scanner/checks/dep-deep-scan.ts +137 -0
- package/src/domain/scanner/checks/documentation.test.ts +88 -0
- package/src/domain/scanner/checks/documentation.ts +79 -0
- package/src/domain/scanner/checks/git-history.test.ts +120 -0
- package/src/domain/scanner/checks/git-history.ts +163 -0
- package/src/domain/scanner/checks/gpai-systemic-risk.test.ts +84 -0
- package/src/domain/scanner/checks/gpai-systemic-risk.ts +98 -0
- package/src/domain/scanner/checks/gpai-transparency.ts +94 -0
- package/src/domain/scanner/checks/index.ts +28 -0
- package/src/domain/scanner/checks/industry/index.ts +40 -0
- package/src/domain/scanner/checks/industry/industry.test.ts +287 -0
- package/src/domain/scanner/checks/interaction-logging.test.ts +113 -0
- package/src/domain/scanner/checks/interaction-logging.ts +142 -0
- package/src/domain/scanner/checks/nhi-scanner.test.ts +158 -0
- package/src/domain/scanner/checks/nhi-scanner.ts +78 -0
- package/src/domain/scanner/checks/passport-completeness.test.ts +127 -0
- package/src/domain/scanner/checks/passport-completeness.ts +82 -0
- package/src/domain/scanner/checks/passport-presence.test.ts +56 -0
- package/src/domain/scanner/checks/passport-presence.ts +78 -0
- package/src/domain/scanner/checks/pattern-check-factory.ts +70 -0
- package/src/domain/scanner/checks/permission-scanner.test.ts +279 -0
- package/src/domain/scanner/checks/permission-scanner.ts +90 -0
- package/src/domain/scanner/checks/presence-check-factory.test.ts +124 -0
- package/src/domain/scanner/checks/presence-check-factory.ts +275 -0
- package/src/domain/scanner/compliance-diff.test.ts +165 -0
- package/src/domain/scanner/compliance-diff.ts +138 -0
- package/src/domain/scanner/confidence.test.ts +235 -0
- package/src/domain/scanner/confidence.ts +156 -0
- package/src/domain/scanner/constants.ts +13 -0
- package/src/domain/scanner/create-scanner.ts +573 -0
- package/src/domain/scanner/cross-layer.test.ts +372 -0
- package/src/domain/scanner/cross-layer.ts +232 -0
- package/src/domain/scanner/data/ai-packages.ts +82 -0
- package/src/domain/scanner/debt-calculator.test.ts +89 -0
- package/src/domain/scanner/debt-calculator.ts +111 -0
- package/src/domain/scanner/drift.test.ts +191 -0
- package/src/domain/scanner/drift.ts +73 -0
- package/src/domain/scanner/evidence-store.test.ts +207 -0
- package/src/domain/scanner/evidence-store.ts +195 -0
- package/src/domain/scanner/evidence.test.ts +104 -0
- package/src/domain/scanner/evidence.ts +71 -0
- package/src/domain/scanner/external/bandit-runner.test.ts +45 -0
- package/src/domain/scanner/external/bandit-runner.ts +90 -0
- package/src/domain/scanner/external/checks.ts +321 -0
- package/src/domain/scanner/external/dedup.test.ts +79 -0
- package/src/domain/scanner/external/dedup.ts +94 -0
- package/src/domain/scanner/external/detect-secrets-runner.test.ts +58 -0
- package/src/domain/scanner/external/detect-secrets-runner.ts +81 -0
- package/src/domain/scanner/external/external-scanner.test.ts +221 -0
- package/src/domain/scanner/external/external-scanner.ts +36 -0
- package/src/domain/scanner/external/finding-mapper.test.ts +95 -0
- package/src/domain/scanner/external/finding-mapper.ts +138 -0
- package/src/domain/scanner/external/index.ts +15 -0
- package/src/domain/scanner/external/mappings.ts +93 -0
- package/src/domain/scanner/external/modelscan-runner.test.ts +35 -0
- package/src/domain/scanner/external/modelscan-runner.ts +101 -0
- package/src/domain/scanner/external/path-utils.ts +8 -0
- package/src/domain/scanner/external/runner-port.ts +45 -0
- package/src/domain/scanner/external/semgrep-runner.test.ts +52 -0
- package/src/domain/scanner/external/semgrep-runner.ts +94 -0
- package/src/domain/scanner/external/types.ts +32 -0
- package/src/domain/scanner/finding-attribution.test.ts +444 -0
- package/src/domain/scanner/finding-attribution.ts +195 -0
- package/src/domain/scanner/finding-explainer.test.ts +157 -0
- package/src/domain/scanner/finding-explainer.ts +73 -0
- package/src/domain/scanner/fix-diff-builder.test.ts +272 -0
- package/src/domain/scanner/fix-diff-builder.ts +477 -0
- package/src/domain/scanner/import-graph.test.ts +162 -0
- package/src/domain/scanner/import-graph.ts +198 -0
- package/src/domain/scanner/languages/adapter.test.ts +105 -0
- package/src/domain/scanner/languages/adapter.ts +239 -0
- package/src/domain/scanner/layers/index.ts +24 -0
- package/src/domain/scanner/layers/layer1-files.ts +54 -0
- package/src/domain/scanner/layers/layer2-docs.test.ts +1207 -0
- package/src/domain/scanner/layers/layer2-docs.ts +297 -0
- package/src/domain/scanner/layers/layer2-parsing.ts +217 -0
- package/src/domain/scanner/layers/layer3-config.test.ts +187 -0
- package/src/domain/scanner/layers/layer3-config.ts +279 -0
- package/src/domain/scanner/layers/layer3-parsers.ts +73 -0
- package/src/domain/scanner/layers/layer4-patterns.test.ts +397 -0
- package/src/domain/scanner/layers/layer4-patterns.ts +216 -0
- package/src/domain/scanner/layers/layer5-docs.test.ts +99 -0
- package/src/domain/scanner/layers/layer5-docs.ts +250 -0
- package/src/domain/scanner/layers/layer5-llm.test.ts +146 -0
- package/src/domain/scanner/layers/layer5-llm.ts +262 -0
- package/src/domain/scanner/layers/layer5-targeted.test.ts +93 -0
- package/src/domain/scanner/layers/layer5-targeted.ts +233 -0
- package/src/domain/scanner/layers/lockfile-parsers.test.ts +320 -0
- package/src/domain/scanner/layers/lockfile-parsers.ts +184 -0
- package/src/domain/scanner/regulation-version.test.ts +54 -0
- package/src/domain/scanner/regulation-version.ts +23 -0
- package/src/domain/scanner/role-filter.test.ts +116 -0
- package/src/domain/scanner/role-filter.ts +51 -0
- package/src/domain/scanner/rules/banned-packages-data.ts +553 -0
- package/src/domain/scanner/rules/banned-packages-sdk.ts +65 -0
- package/src/domain/scanner/rules/banned-packages.test.ts +249 -0
- package/src/domain/scanner/rules/banned-packages.ts +55 -0
- package/src/domain/scanner/rules/comment-filter.test.ts +115 -0
- package/src/domain/scanner/rules/comment-filter.ts +297 -0
- package/src/domain/scanner/rules/index.ts +9 -0
- package/src/domain/scanner/rules/nhi-patterns.test.ts +128 -0
- package/src/domain/scanner/rules/nhi-patterns.ts +60 -0
- package/src/domain/scanner/rules/pattern-rules.ts +1152 -0
- package/src/domain/scanner/sbom.test.ts +136 -0
- package/src/domain/scanner/sbom.ts +103 -0
- package/src/domain/scanner/scan-cache.test.ts +136 -0
- package/src/domain/scanner/scan-cache.ts +115 -0
- package/src/domain/scanner/scanner.test.ts +125 -0
- package/src/domain/scanner/score-calculator.test.ts +363 -0
- package/src/domain/scanner/score-calculator.ts +189 -0
- package/src/domain/scanner/security-score.test.ts +107 -0
- package/src/domain/scanner/security-score.ts +116 -0
- package/src/domain/scanner/source-filter.ts +24 -0
- package/src/domain/scanner/validators.ts +223 -0
- package/src/domain/shared/compliance-constants.ts +48 -0
- package/src/domain/shared/disclosure-patterns.ts +16 -0
- package/src/domain/shared/index.ts +6 -0
- package/src/domain/shared/parse-dependencies.ts +21 -0
- package/src/domain/supply-chain/dependency-analyzer.ts +138 -0
- package/src/domain/supply-chain/index.ts +3 -0
- package/src/domain/supply-chain/supply-chain.test.ts +211 -0
- package/src/domain/supply-chain/types.ts +32 -0
- package/src/domain/whatif/config-fixer.ts +187 -0
- package/src/domain/whatif/index.ts +6 -0
- package/src/domain/whatif/scenario-engine.ts +121 -0
- package/src/domain/whatif/simulate-actions.test.ts +161 -0
- package/src/domain/whatif/simulate-actions.ts +114 -0
- package/src/domain/whatif/whatif.test.ts +135 -0
- package/src/e2e/gaps-e2e.test.ts +259 -0
- package/src/e2e/smoke.test.ts +101 -0
- package/src/hooks/hooks-export.test.ts +81 -0
- package/src/hooks/installer.ts +113 -0
- package/src/http/cors.test.ts +38 -0
- package/src/http/create-router.ts +259 -0
- package/src/http/routes/agent.route.ts +380 -0
- package/src/http/routes/audit.route.ts +66 -0
- package/src/http/routes/badge.route.ts +23 -0
- package/src/http/routes/cert.route.ts +66 -0
- package/src/http/routes/chat.route.ts +228 -0
- package/src/http/routes/cost.route.ts +33 -0
- package/src/http/routes/debt.route.ts +29 -0
- package/src/http/routes/disclaimer.route.ts +64 -0
- package/src/http/routes/eval.route.ts +161 -0
- package/src/http/routes/events.route.test.ts +108 -0
- package/src/http/routes/events.route.ts +71 -0
- package/src/http/routes/external-scan.route.ts +24 -0
- package/src/http/routes/file.route.ts +54 -0
- package/src/http/routes/fix.route.ts +219 -0
- package/src/http/routes/frameworks.route.test.ts +66 -0
- package/src/http/routes/frameworks.route.ts +36 -0
- package/src/http/routes/git.route.ts +27 -0
- package/src/http/routes/guided-onboarding.route.ts +65 -0
- package/src/http/routes/import.route.ts +64 -0
- package/src/http/routes/jurisdiction.route.ts +22 -0
- package/src/http/routes/obligations.route.test.ts +122 -0
- package/src/http/routes/obligations.route.ts +110 -0
- package/src/http/routes/onboarding.route.ts +53 -0
- package/src/http/routes/provider.route.ts +42 -0
- package/src/http/routes/proxy.route.ts +40 -0
- package/src/http/routes/redteam.route.ts +84 -0
- package/src/http/routes/report.route.ts +29 -0
- package/src/http/routes/scan.route.ts +104 -0
- package/src/http/routes/share.route.ts +44 -0
- package/src/http/routes/shell.route.ts +27 -0
- package/src/http/routes/status.route.ts +66 -0
- package/src/http/routes/supply-chain.route.ts +121 -0
- package/src/http/routes/sync.route.ts +328 -0
- package/src/http/routes/tools.route.ts +29 -0
- package/src/http/routes/whatif.route.ts +96 -0
- package/src/http/utils/validation.ts +31 -0
- package/src/index.ts +1 -0
- package/src/infra/bundle-fetcher.ts +77 -0
- package/src/infra/cache-storage.ts +34 -0
- package/src/infra/event-bus.ts +31 -0
- package/src/infra/file-collector.ts +61 -0
- package/src/infra/file-ops-adapter.ts +95 -0
- package/src/infra/file-watcher.test.ts +90 -0
- package/src/infra/file-watcher.ts +106 -0
- package/src/infra/git-adapter.ts +93 -0
- package/src/infra/git-history-adapter.ts +41 -0
- package/src/infra/headless-browser.ts +178 -0
- package/src/infra/llm-adapter.test.ts +83 -0
- package/src/infra/llm-adapter.ts +86 -0
- package/src/infra/logger.ts +27 -0
- package/src/infra/project-config.test.ts +74 -0
- package/src/infra/project-config.ts +35 -0
- package/src/infra/rate-limiter.test.ts +36 -0
- package/src/infra/rate-limiter.ts +34 -0
- package/src/infra/retry.ts +46 -0
- package/src/infra/saas-client.ts +123 -0
- package/src/infra/search-adapter.ts +113 -0
- package/src/infra/shell-adapter.ts +68 -0
- package/src/infra/tool-manager.test.ts +99 -0
- package/src/infra/tool-manager.ts +197 -0
- package/src/llm/agents/agent-modes.test.ts +44 -0
- package/src/llm/agents/modes.ts +68 -0
- package/src/llm/routing/cost-routing.test.ts +37 -0
- package/src/llm/routing/cost-tracker.ts +74 -0
- package/src/llm/routing/model-routing.test.ts +79 -0
- package/src/llm/routing/model-routing.ts +38 -0
- package/src/llm/routing/pricing.ts +19 -0
- package/src/llm/sse-protocol.ts +77 -0
- package/src/llm/tool-definitions.ts +83 -0
- package/src/llm/tool-executors.ts +80 -0
- package/src/llm/tools/types.ts +13 -0
- package/src/mcp/create-mcp-stack.ts +82 -0
- package/src/mcp/handlers.ts +245 -0
- package/src/mcp/index.ts +28 -0
- package/src/mcp/mcp-server.test.ts +80 -0
- package/src/mcp/server.ts +79 -0
- package/src/mcp/tools.ts +48 -0
- package/src/onboarding/auto-detect.ts +164 -0
- package/src/onboarding/onboarding.test.ts +89 -0
- package/src/onboarding/profile.ts +169 -0
- package/src/onboarding/questions.ts +112 -0
- package/src/onboarding/wizard.ts +66 -0
- package/src/output/github-issue.ts +32 -0
- package/src/output/json-output.ts +67 -0
- package/src/ports/browser.port.ts +23 -0
- package/src/ports/events.port.ts +28 -0
- package/src/ports/llm.port.ts +23 -0
- package/src/ports/logger.port.ts +6 -0
- package/src/ports/process.port.ts +6 -0
- package/src/ports/scanner.port.ts +15 -0
- package/src/server.ts +134 -0
- package/src/services/badge-service.ts +67 -0
- package/src/services/chat-service.test.ts +162 -0
- package/src/services/chat-service.ts +152 -0
- package/src/services/cost-service.ts +52 -0
- package/src/services/debt-service.ts +65 -0
- package/src/services/eval-integration.test.ts +132 -0
- package/src/services/eval-service.test.ts +373 -0
- package/src/services/eval-service.ts +463 -0
- package/src/services/external-scan-service.ts +60 -0
- package/src/services/file-service.ts +37 -0
- package/src/services/fix-service.test.ts +470 -0
- package/src/services/fix-service.ts +648 -0
- package/src/services/framework-service.test.ts +159 -0
- package/src/services/framework-service.ts +67 -0
- package/src/services/onboarding-service.ts +165 -0
- package/src/services/passport-audit.ts +244 -0
- package/src/services/passport-documents.ts +258 -0
- package/src/services/passport-service-utils.ts +72 -0
- package/src/services/passport-service.test.ts +251 -0
- package/src/services/passport-service.ts +339 -0
- package/src/services/proxy-service.ts +81 -0
- package/src/services/report-service.ts +72 -0
- package/src/services/scan-service.test.ts +470 -0
- package/src/services/scan-service.ts +335 -0
- package/src/services/share-service.ts +108 -0
- package/src/services/shared/backup.ts +23 -0
- package/src/services/status-service.ts +38 -0
- package/src/services/undo-service.test.ts +190 -0
- package/src/services/undo-service.ts +144 -0
- package/src/test-helpers/factories.ts +116 -0
- package/src/types/common.schemas.ts +147 -0
- package/src/types/common.types.ts +292 -0
- package/src/types/contract.test.ts +217 -0
- package/src/types/errors.ts +52 -0
- package/src/types/framework.types.ts +87 -0
- package/src/types/passport-schemas.ts +241 -0
- package/src/types/passport.types.ts +296 -0
- package/src/version.ts +1 -0
- package/tsconfig.json +20 -0
- package/vitest.config.ts +9 -0
|
@@ -0,0 +1,573 @@
|
|
|
1
|
+
import type { CheckResult, Finding, ScanResult, Severity, ExternalToolResult } from '../../types/common.types.js';
|
|
2
|
+
import type { ScanContext } from '../../ports/scanner.port.js';
|
|
3
|
+
import type { ScoringData } from '../../data/schemas/schemas.js';
|
|
4
|
+
import { calculateScore } from './score-calculator.js';
|
|
5
|
+
import { L1_CHECKS } from './layers/layer1-files.js';
|
|
6
|
+
import { runLayer2, layer2ToCheckResults } from './layers/layer2-docs.js';
|
|
7
|
+
import { runLayer3, layer3ToCheckResults } from './layers/layer3-config.js';
|
|
8
|
+
import { runLayer4, layer4ToCheckResults } from './layers/layer4-patterns.js';
|
|
9
|
+
import type { Layer5Analyzer } from './layers/layer5-llm.js';
|
|
10
|
+
import { runNhiScan, nhiToCheckResults } from './checks/nhi-scanner.js';
|
|
11
|
+
import { runDepDeepScan, depScanToCheckResults } from './checks/dep-deep-scan.js';
|
|
12
|
+
import { runCrossLayerChecks, crossLayerToCheckResults } from './cross-layer.js';
|
|
13
|
+
import { createEvidence, createEvidenceCollector } from './evidence.js';
|
|
14
|
+
import { createRegulationVersion } from './regulation-version.js';
|
|
15
|
+
import {
|
|
16
|
+
l1Confidence,
|
|
17
|
+
l2Confidence,
|
|
18
|
+
l3Confidence,
|
|
19
|
+
l4Confidence,
|
|
20
|
+
summarizeConfidence,
|
|
21
|
+
} from './confidence.js';
|
|
22
|
+
import type { CheckWithConfidence } from './confidence.js';
|
|
23
|
+
import { buildFixDiff, buildCodeContext } from './fix-diff-builder.js';
|
|
24
|
+
import { explainFindings } from './finding-explainer.js';
|
|
25
|
+
import { applyAttestations } from './attestations.js';
|
|
26
|
+
// S08/S09: New scanner modules
|
|
27
|
+
import { buildImportGraph } from './import-graph.js';
|
|
28
|
+
import { analyzeStructure } from './ast/swc-analyzer.js';
|
|
29
|
+
import { detectProjectLanguages } from './languages/adapter.js';
|
|
30
|
+
import { selectUncertainFindings, buildTargetedPrompts, estimateTargetedCost } from './layers/layer5-targeted.js';
|
|
31
|
+
import type { GitHistoryPort } from './checks/git-history.js';
|
|
32
|
+
import { analyzeGitHistory, gitHistoryToCheckResults } from './checks/git-history.js';
|
|
33
|
+
import { detectDocType, getChecklist, buildDocValidationPrompt, parseDocValidationResponse, docValidationToFindings } from './layers/layer5-docs.js';
|
|
34
|
+
import type { ExternalRunners } from './external/runner-port.js';
|
|
35
|
+
import { mapExternalFindings } from './external/finding-mapper.js';
|
|
36
|
+
import { deduplicateFindings, mergeFindings } from './external/dedup.js';
|
|
37
|
+
import type { ProcessRunner } from '../../ports/process.port.js';
|
|
38
|
+
|
|
39
|
+
const DEFAULT_SEVERITY: Severity = 'info';
|
|
40
|
+
|
|
41
|
+
const toFinding = (result: CheckResult, confidence?: CheckWithConfidence): Finding => {
|
|
42
|
+
const base = {
|
|
43
|
+
confidence: confidence?.confidence,
|
|
44
|
+
confidenceLevel: confidence?.level,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
if (result.type === 'pass') {
|
|
48
|
+
return {
|
|
49
|
+
checkId: result.checkId,
|
|
50
|
+
type: 'pass',
|
|
51
|
+
message: result.message,
|
|
52
|
+
severity: DEFAULT_SEVERITY,
|
|
53
|
+
...base,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (result.type === 'fail') {
|
|
58
|
+
return {
|
|
59
|
+
checkId: result.checkId,
|
|
60
|
+
type: 'fail',
|
|
61
|
+
message: result.message,
|
|
62
|
+
severity: result.severity,
|
|
63
|
+
obligationId: result.obligationId,
|
|
64
|
+
articleReference: result.articleReference,
|
|
65
|
+
fix: result.fix,
|
|
66
|
+
file: result.file,
|
|
67
|
+
line: result.line,
|
|
68
|
+
...base,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (result.type === 'info') {
|
|
73
|
+
return {
|
|
74
|
+
checkId: result.checkId,
|
|
75
|
+
type: 'info',
|
|
76
|
+
message: result.message,
|
|
77
|
+
severity: result.severity,
|
|
78
|
+
obligationId: result.obligationId,
|
|
79
|
+
articleReference: result.articleReference,
|
|
80
|
+
fix: result.fix,
|
|
81
|
+
file: result.file,
|
|
82
|
+
line: result.line,
|
|
83
|
+
...base,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// skip
|
|
88
|
+
return {
|
|
89
|
+
checkId: result.checkId,
|
|
90
|
+
type: 'skip',
|
|
91
|
+
message: result.reason,
|
|
92
|
+
severity: DEFAULT_SEVERITY,
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/** Enrich findings with codeContext and fixDiff using file contents from scan. */
|
|
97
|
+
const enrichFindings = (
|
|
98
|
+
findings: readonly Finding[],
|
|
99
|
+
fileMap: ReadonlyMap<string, string>,
|
|
100
|
+
): readonly Finding[] => {
|
|
101
|
+
return findings.map((f) => {
|
|
102
|
+
if (f.file === undefined || f.type !== 'fail') return f;
|
|
103
|
+
|
|
104
|
+
const content = fileMap.get(f.file);
|
|
105
|
+
if (content === undefined) return f;
|
|
106
|
+
|
|
107
|
+
const codeContext = f.line !== undefined ? buildCodeContext(content, f.line) : undefined;
|
|
108
|
+
const fixDiff = buildFixDiff(content, f.line ?? 0, f.file, f.checkId);
|
|
109
|
+
|
|
110
|
+
if (codeContext === undefined && fixDiff === undefined) return f;
|
|
111
|
+
return { ...f, codeContext, fixDiff };
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/** Convert Finding[] → CheckResult[] for score recalculation. */
|
|
116
|
+
const findingsToCheckResults = (findings: readonly Finding[]): readonly CheckResult[] =>
|
|
117
|
+
findings.map((f): CheckResult => {
|
|
118
|
+
if (f.type === 'pass') return { type: 'pass', checkId: f.checkId, message: f.message };
|
|
119
|
+
if (f.type === 'fail') return {
|
|
120
|
+
type: 'fail', checkId: f.checkId, message: f.message,
|
|
121
|
+
severity: f.severity, obligationId: f.obligationId, articleReference: f.articleReference, fix: f.fix,
|
|
122
|
+
};
|
|
123
|
+
if (f.type === 'info') return {
|
|
124
|
+
type: 'info', checkId: f.checkId, message: f.message,
|
|
125
|
+
severity: f.severity, obligationId: f.obligationId, articleReference: f.articleReference, fix: f.fix,
|
|
126
|
+
};
|
|
127
|
+
return { type: 'skip', checkId: f.checkId, reason: f.message };
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const createFallbackScore = (findings: readonly Finding[]) => {
|
|
131
|
+
const passed = findings.filter((f) => f.type === 'pass').length;
|
|
132
|
+
const failed = findings.filter((f) => f.type === 'fail').length;
|
|
133
|
+
const skipped = findings.filter((f) => f.type === 'skip').length;
|
|
134
|
+
const total = findings.length;
|
|
135
|
+
const applicable = passed + failed;
|
|
136
|
+
const score = applicable === 0 ? 100 : Math.round((passed / applicable) * 100);
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
totalScore: score,
|
|
140
|
+
zone: score >= 80 ? 'green' as const : score >= 50 ? 'yellow' as const : 'red' as const,
|
|
141
|
+
categoryScores: [],
|
|
142
|
+
criticalCapApplied: false,
|
|
143
|
+
totalChecks: total,
|
|
144
|
+
passedChecks: passed,
|
|
145
|
+
failedChecks: failed,
|
|
146
|
+
skippedChecks: skipped,
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export interface Scanner {
|
|
151
|
+
readonly scan: (ctx: ScanContext) => ScanResult;
|
|
152
|
+
readonly scanDeep?: (ctx: ScanContext, fileContents: ReadonlyMap<string, string>) => Promise<ScanResult>;
|
|
153
|
+
readonly scanTier2?: (ctx: ScanContext) => Promise<ScanResult>;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export const createScanner = (
|
|
157
|
+
scoringData?: ScoringData,
|
|
158
|
+
layer5?: Layer5Analyzer,
|
|
159
|
+
gitHistory?: GitHistoryPort,
|
|
160
|
+
externalRunners?: ExternalRunners,
|
|
161
|
+
runProcess?: ProcessRunner,
|
|
162
|
+
): Scanner => {
|
|
163
|
+
// Cache import graph from last scan() for reuse in scanDeep()
|
|
164
|
+
let lastImportGraph: ReturnType<typeof buildImportGraph> | null = null;
|
|
165
|
+
|
|
166
|
+
const scan = (ctx: ScanContext): ScanResult => {
|
|
167
|
+
const startTime = Date.now();
|
|
168
|
+
|
|
169
|
+
const allResults: CheckResult[] = [];
|
|
170
|
+
const allConfidence: CheckWithConfidence[] = [];
|
|
171
|
+
const evidenceCollector = createEvidenceCollector();
|
|
172
|
+
|
|
173
|
+
// L1: File presence checks
|
|
174
|
+
for (const check of L1_CHECKS) {
|
|
175
|
+
const results = check(ctx);
|
|
176
|
+
for (const result of results) {
|
|
177
|
+
allResults.push(result);
|
|
178
|
+
if (result.type !== 'skip') {
|
|
179
|
+
allConfidence.push({
|
|
180
|
+
...l1Confidence(result.type === 'pass'),
|
|
181
|
+
obligationId: result.type === 'fail' ? result.obligationId : undefined,
|
|
182
|
+
});
|
|
183
|
+
evidenceCollector.add(createEvidence(result.checkId, 'L1', 'file-presence', {
|
|
184
|
+
snippet: result.type === 'pass' ? `File check passed: ${result.message}` : undefined,
|
|
185
|
+
}));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// L2: Document structure validation
|
|
191
|
+
const l2Results = runLayer2(ctx);
|
|
192
|
+
const l2Checks = layer2ToCheckResults(l2Results);
|
|
193
|
+
allResults.push(...l2Checks);
|
|
194
|
+
for (const l2r of l2Results) {
|
|
195
|
+
allConfidence.push({
|
|
196
|
+
...l2Confidence(l2r.status),
|
|
197
|
+
obligationId: l2r.obligationId,
|
|
198
|
+
});
|
|
199
|
+
evidenceCollector.add(createEvidence(`l2-${l2r.document}`, 'L2', 'heading-match', {
|
|
200
|
+
snippet: `Status: ${l2r.status}, matched ${l2r.matchedRequired}/${l2r.totalRequired} sections`,
|
|
201
|
+
}));
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// L3: Config & dependency scanning
|
|
205
|
+
const l3Results = runLayer3(ctx);
|
|
206
|
+
const l3Checks = layer3ToCheckResults(l3Results);
|
|
207
|
+
allResults.push(...l3Checks);
|
|
208
|
+
for (const l3r of l3Results) {
|
|
209
|
+
allConfidence.push({
|
|
210
|
+
...l3Confidence(l3r.status),
|
|
211
|
+
obligationId: l3r.obligationId,
|
|
212
|
+
});
|
|
213
|
+
evidenceCollector.add(createEvidence(`l3-${l3r.type}`, 'L3', 'dependency', {
|
|
214
|
+
snippet: l3r.message,
|
|
215
|
+
file: l3r.file,
|
|
216
|
+
}));
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// L3-ext: Dependency deep scan (lock file analysis)
|
|
220
|
+
const depScanResult = runDepDeepScan(ctx);
|
|
221
|
+
const depChecks = depScanToCheckResults(depScanResult);
|
|
222
|
+
allResults.push(...depChecks);
|
|
223
|
+
if (depScanResult.totalDeps > 0) {
|
|
224
|
+
evidenceCollector.add(createEvidence('l3-dep-scan', 'L3', 'dependency', {
|
|
225
|
+
snippet: `Analyzed ${depScanResult.totalDeps} deps: ${depScanResult.vulnerabilities.length} vulns, ${depScanResult.licenseIssues.length} license issues`,
|
|
226
|
+
}));
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// E-109: Build import graph for AI-relevance filtering
|
|
230
|
+
const importGraph = buildImportGraph(ctx.files);
|
|
231
|
+
lastImportGraph = importGraph;
|
|
232
|
+
|
|
233
|
+
// E-111: Detect additional languages (Go, Rust, Java) and add their deps
|
|
234
|
+
const extraLangs = detectProjectLanguages(ctx.files);
|
|
235
|
+
for (const adapter of extraLangs) {
|
|
236
|
+
for (const file of ctx.files) {
|
|
237
|
+
const filename = file.relativePath.split('/').pop() ?? '';
|
|
238
|
+
if (adapter.depFiles.includes(filename)) {
|
|
239
|
+
const deps = adapter.detectDeps(file.content);
|
|
240
|
+
for (const dep of deps) {
|
|
241
|
+
if (dep.isAiSdk) {
|
|
242
|
+
allResults.push({
|
|
243
|
+
type: 'pass',
|
|
244
|
+
checkId: 'l3-ai-sdk-detected',
|
|
245
|
+
message: `AI SDK detected: ${dep.name} (${dep.version}) in ${adapter.name}`,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
if (dep.isBanned) {
|
|
249
|
+
allResults.push({
|
|
250
|
+
type: 'fail',
|
|
251
|
+
checkId: 'l3-banned-dep',
|
|
252
|
+
message: `Banned dependency: ${dep.name} — ${dep.bannedReason ?? 'prohibited'}`,
|
|
253
|
+
severity: 'high',
|
|
254
|
+
obligationId: 'OBL-001',
|
|
255
|
+
articleReference: 'Art. 5',
|
|
256
|
+
fix: `Remove ${dep.name} or document exemption`,
|
|
257
|
+
file: file.relativePath,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// L4: Pattern matching (with comment-filtered content)
|
|
266
|
+
const l4Results = runLayer4(ctx, l3Results);
|
|
267
|
+
const l4Checks = layer4ToCheckResults(l4Results);
|
|
268
|
+
allResults.push(...l4Checks);
|
|
269
|
+
for (const l4r of l4Results) {
|
|
270
|
+
allConfidence.push({
|
|
271
|
+
...l4Confidence(l4r.patternType, l4r.status),
|
|
272
|
+
obligationId: l4r.obligationId,
|
|
273
|
+
});
|
|
274
|
+
evidenceCollector.add(createEvidence(`l4-${l4r.category}`, 'L4', 'pattern-match', {
|
|
275
|
+
snippet: `${l4r.patternType} pattern "${l4r.matchedPattern}" ${l4r.status}`,
|
|
276
|
+
file: l4r.file,
|
|
277
|
+
line: l4r.line,
|
|
278
|
+
}));
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// E-110: Structural analysis (bare calls, wrappers, safety mutations)
|
|
282
|
+
for (const file of ctx.files) {
|
|
283
|
+
if (importGraph.aiRelevantFiles.has(file.relativePath) || importGraph.directAiFiles.has(file.relativePath)) {
|
|
284
|
+
const structFindings = analyzeStructure(file.content, file.relativePath, file.extension);
|
|
285
|
+
for (const sf of structFindings) {
|
|
286
|
+
if (sf.type === 'safety-mutation' || sf.type === 'missing-error-handling') {
|
|
287
|
+
allResults.push({
|
|
288
|
+
type: 'fail',
|
|
289
|
+
checkId: `l4-ast-${sf.type}`,
|
|
290
|
+
message: sf.description,
|
|
291
|
+
severity: sf.type === 'safety-mutation' ? 'high' : 'medium',
|
|
292
|
+
obligationId: sf.type === 'safety-mutation' ? 'OBL-006' : 'OBL-015',
|
|
293
|
+
articleReference: sf.type === 'safety-mutation' ? 'Art. 15' : 'Art. 14',
|
|
294
|
+
fix: sf.type === 'safety-mutation'
|
|
295
|
+
? 'Remove safety config mutation or document exemption'
|
|
296
|
+
: 'Add try-catch error handling around LLM calls',
|
|
297
|
+
file: sf.file,
|
|
298
|
+
line: sf.line,
|
|
299
|
+
});
|
|
300
|
+
allConfidence.push({
|
|
301
|
+
...l4Confidence('negative', 'FOUND'),
|
|
302
|
+
obligationId: sf.type === 'safety-mutation' ? 'OBL-006' : 'OBL-015',
|
|
303
|
+
});
|
|
304
|
+
} else if (sf.type === 'wrapped-call' || sf.type === 'decorator-pattern') {
|
|
305
|
+
allResults.push({
|
|
306
|
+
type: 'pass',
|
|
307
|
+
checkId: `l4-ast-${sf.type}`,
|
|
308
|
+
message: `${sf.description} in ${sf.file}:${sf.line}`,
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// NHI: Non-human identity / secret scanning
|
|
316
|
+
const nhiResults = runNhiScan(ctx);
|
|
317
|
+
const nhiChecks = nhiToCheckResults(nhiResults);
|
|
318
|
+
allResults.push(...nhiChecks);
|
|
319
|
+
for (const nhi of nhiResults) {
|
|
320
|
+
evidenceCollector.add(createEvidence(`l4-nhi-${nhi.category}`, 'L4', 'nhi-scan', {
|
|
321
|
+
snippet: `${nhi.description}: ${nhi.match}`,
|
|
322
|
+
file: nhi.file,
|
|
323
|
+
line: nhi.line,
|
|
324
|
+
}));
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// E-112: Git history analysis (document freshness, bulk commits, author diversity)
|
|
328
|
+
if (gitHistory !== undefined) {
|
|
329
|
+
const historyResult = analyzeGitHistory(ctx.projectPath, gitHistory);
|
|
330
|
+
const historyChecks = gitHistoryToCheckResults(historyResult);
|
|
331
|
+
allResults.push(...historyChecks);
|
|
332
|
+
for (const check of historyChecks) {
|
|
333
|
+
if (check.type !== 'skip') {
|
|
334
|
+
evidenceCollector.add(createEvidence(check.checkId, 'git-history', 'git-analysis', {
|
|
335
|
+
snippet: check.type === 'pass' ? check.message : `${check.message}`,
|
|
336
|
+
file: check.type === 'fail' ? check.file : undefined,
|
|
337
|
+
}));
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// Cross-layer verification
|
|
343
|
+
const l1Checks = allResults.slice(0, allResults.length - l2Checks.length - l3Checks.length - l4Checks.length - nhiChecks.length);
|
|
344
|
+
const crossLayerFindings = runCrossLayerChecks(l1Checks, l2Results, l3Results, l4Results, ctx);
|
|
345
|
+
const crossLayerCheckResults = crossLayerToCheckResults(crossLayerFindings);
|
|
346
|
+
allResults.push(...crossLayerCheckResults);
|
|
347
|
+
for (const clf of crossLayerFindings) {
|
|
348
|
+
evidenceCollector.add(createEvidence(clf.ruleId, 'cross-layer', 'cross-layer', {
|
|
349
|
+
snippet: clf.description,
|
|
350
|
+
}));
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// Build findings with confidence and evidence attached
|
|
354
|
+
const findings: Finding[] = [];
|
|
355
|
+
let confidenceIdx = 0;
|
|
356
|
+
for (let i = 0; i < allResults.length; i++) {
|
|
357
|
+
const result = allResults[i];
|
|
358
|
+
if (result.type === 'skip') {
|
|
359
|
+
findings.push(toFinding(result));
|
|
360
|
+
} else {
|
|
361
|
+
const conf = confidenceIdx < allConfidence.length ? allConfidence[confidenceIdx] : undefined;
|
|
362
|
+
const evidence = evidenceCollector.getByFinding(result.checkId);
|
|
363
|
+
const finding = toFinding(result, conf);
|
|
364
|
+
findings.push(evidence.length > 0 ? { ...finding, evidence } : finding);
|
|
365
|
+
confidenceIdx++;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// Attach docQuality from L2 results to corresponding findings
|
|
370
|
+
const l2QualityMap = new Map(l2Results.map((r) => [`l2-${r.document}`, r.docQuality]));
|
|
371
|
+
const findingsWithQuality = findings.map((f) => {
|
|
372
|
+
const quality = l2QualityMap.get(f.checkId);
|
|
373
|
+
return quality !== undefined ? { ...f, docQuality: quality } : f;
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
// Enrich findings with code context from files already in memory
|
|
377
|
+
const fileMap = new Map<string, string>();
|
|
378
|
+
for (const f of ctx.files) {
|
|
379
|
+
fileMap.set(f.relativePath, f.content);
|
|
380
|
+
}
|
|
381
|
+
const enrichedFindings = enrichFindings(findingsWithQuality, fileMap);
|
|
382
|
+
|
|
383
|
+
// Apply manual attestations from .complior/attestations.json
|
|
384
|
+
const attestedFindings = applyAttestations(enrichedFindings, ctx);
|
|
385
|
+
|
|
386
|
+
// US-S05-07: Attach explanations (article, penalty, deadline, business_impact)
|
|
387
|
+
const explainedFindings = explainFindings(attestedFindings);
|
|
388
|
+
|
|
389
|
+
const duration = Date.now() - startTime;
|
|
390
|
+
|
|
391
|
+
const score = scoringData !== undefined
|
|
392
|
+
? calculateScore(allResults, scoringData)
|
|
393
|
+
: createFallbackScore(explainedFindings);
|
|
394
|
+
|
|
395
|
+
// Attach confidence summary to score
|
|
396
|
+
const confidenceSummary = summarizeConfidence(allConfidence);
|
|
397
|
+
|
|
398
|
+
return {
|
|
399
|
+
score: { ...score, confidenceSummary },
|
|
400
|
+
findings: explainedFindings,
|
|
401
|
+
projectPath: ctx.projectPath,
|
|
402
|
+
scannedAt: new Date().toISOString(),
|
|
403
|
+
duration,
|
|
404
|
+
filesScanned: ctx.files.length,
|
|
405
|
+
regulationVersion: createRegulationVersion(allResults.length),
|
|
406
|
+
};
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
const scanDeep = layer5 !== undefined
|
|
410
|
+
? async (ctx: ScanContext, fileContents: ReadonlyMap<string, string>): Promise<ScanResult> => {
|
|
411
|
+
// Run L1-L4 synchronously first
|
|
412
|
+
const baseResult = scan(ctx);
|
|
413
|
+
|
|
414
|
+
// E-113: Targeted L5 — only uncertain findings (confidence 50-80%)
|
|
415
|
+
const uncertainFindings = selectUncertainFindings(baseResult.findings);
|
|
416
|
+
let totalL5Cost = 0;
|
|
417
|
+
|
|
418
|
+
if (uncertainFindings.length > 0) {
|
|
419
|
+
// Reuse import graph from base scan() instead of rebuilding
|
|
420
|
+
const importGraph = lastImportGraph ?? buildImportGraph(ctx.files);
|
|
421
|
+
const prompts = buildTargetedPrompts(uncertainFindings, fileContents, importGraph);
|
|
422
|
+
totalL5Cost += estimateTargetedCost(prompts);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// Pass uncertain findings to L5 for deeper analysis
|
|
426
|
+
const l5Results = await layer5.analyzeFindings(baseResult.findings, fileContents);
|
|
427
|
+
|
|
428
|
+
// E-114a: L5 Document content validation — check .md docs against regulation checklists
|
|
429
|
+
const docValidationResults = await Promise.all(
|
|
430
|
+
ctx.files
|
|
431
|
+
.filter((f) => f.extension === '.md')
|
|
432
|
+
.map(async (file) => {
|
|
433
|
+
const docType = detectDocType(file.relativePath);
|
|
434
|
+
if (!docType) return null;
|
|
435
|
+
const checklist = getChecklist(docType);
|
|
436
|
+
if (!checklist) return null;
|
|
437
|
+
|
|
438
|
+
try {
|
|
439
|
+
const prompt = buildDocValidationPrompt(file.content, checklist);
|
|
440
|
+
const { text, cost } = await layer5.callRaw(prompt);
|
|
441
|
+
totalL5Cost += cost;
|
|
442
|
+
return parseDocValidationResponse(text, docType, file.relativePath, checklist.elements.length);
|
|
443
|
+
} catch {
|
|
444
|
+
return null; // Skip doc validation on LLM/parse error — non-critical
|
|
445
|
+
}
|
|
446
|
+
}),
|
|
447
|
+
);
|
|
448
|
+
const docFindings = docValidationToFindings(
|
|
449
|
+
docValidationResults.filter((r): r is NonNullable<typeof r> => r !== null),
|
|
450
|
+
);
|
|
451
|
+
|
|
452
|
+
if (l5Results.length === 0 && docFindings.length === 0) return baseResult;
|
|
453
|
+
|
|
454
|
+
// Merge L5 results back into findings
|
|
455
|
+
const l5Enhanced = layer5.applyResults(baseResult.findings, l5Results);
|
|
456
|
+
const enhancedFindings = [...l5Enhanced, ...docFindings];
|
|
457
|
+
|
|
458
|
+
// Recalculate score with enhanced findings
|
|
459
|
+
const enhancedCheckResults = findingsToCheckResults(enhancedFindings);
|
|
460
|
+
|
|
461
|
+
const score = scoringData !== undefined
|
|
462
|
+
? calculateScore(enhancedCheckResults, scoringData)
|
|
463
|
+
: createFallbackScore(enhancedFindings);
|
|
464
|
+
|
|
465
|
+
const deepResult: ScanResult = {
|
|
466
|
+
score: { ...score, confidenceSummary: baseResult.score.confidenceSummary },
|
|
467
|
+
findings: enhancedFindings,
|
|
468
|
+
projectPath: baseResult.projectPath,
|
|
469
|
+
scannedAt: baseResult.scannedAt,
|
|
470
|
+
duration: baseResult.duration,
|
|
471
|
+
filesScanned: baseResult.filesScanned,
|
|
472
|
+
regulationVersion: baseResult.regulationVersion,
|
|
473
|
+
deepAnalysis: true,
|
|
474
|
+
l5Cost: totalL5Cost + layer5.getTotalCost(l5Results),
|
|
475
|
+
};
|
|
476
|
+
return deepResult;
|
|
477
|
+
}
|
|
478
|
+
: undefined;
|
|
479
|
+
|
|
480
|
+
const scanTier2 = externalRunners !== undefined && runProcess !== undefined
|
|
481
|
+
? async (ctx: ScanContext): Promise<ScanResult> => {
|
|
482
|
+
const tier2Start = Date.now();
|
|
483
|
+
|
|
484
|
+
// 1. Run Tier 1 (L1-L4) synchronously
|
|
485
|
+
const baseResult = scan(ctx);
|
|
486
|
+
|
|
487
|
+
// 2. Run external tools in parallel
|
|
488
|
+
const runnerDeps = {
|
|
489
|
+
projectPath: ctx.projectPath,
|
|
490
|
+
runProcess,
|
|
491
|
+
files: ctx.files.map((f) => ({ relativePath: f.relativePath, extension: f.extension })),
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
const externalResults = await Promise.allSettled([
|
|
495
|
+
externalRunners.semgrep.run(runnerDeps),
|
|
496
|
+
externalRunners.bandit.run(runnerDeps),
|
|
497
|
+
externalRunners.modelscan.run(runnerDeps),
|
|
498
|
+
externalRunners.detectSecrets.run(runnerDeps),
|
|
499
|
+
]);
|
|
500
|
+
|
|
501
|
+
// 3. Collect results and map to findings
|
|
502
|
+
const toolResults: ExternalToolResult[] = [];
|
|
503
|
+
let allExternalFindings: Finding[] = [];
|
|
504
|
+
|
|
505
|
+
for (const settled of externalResults) {
|
|
506
|
+
if (settled.status === 'rejected') continue;
|
|
507
|
+
const result = settled.value;
|
|
508
|
+
const mappedFindings = mapExternalFindings(result.rawFindings, result.tool);
|
|
509
|
+
|
|
510
|
+
toolResults.push({
|
|
511
|
+
tool: result.tool,
|
|
512
|
+
version: result.version,
|
|
513
|
+
findings: mappedFindings,
|
|
514
|
+
duration: result.duration,
|
|
515
|
+
exitCode: result.exitCode,
|
|
516
|
+
error: result.error,
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
allExternalFindings.push(...mappedFindings);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// 4. Deduplicate external findings against base
|
|
523
|
+
const dedupedExternal = deduplicateFindings(baseResult.findings, allExternalFindings);
|
|
524
|
+
|
|
525
|
+
// 5. Merge
|
|
526
|
+
const mergedFindings = mergeFindings(baseResult.findings, dedupedExternal);
|
|
527
|
+
|
|
528
|
+
// 5b. Filter semgrep bare-call from files already wrapped with @complior/sdk.
|
|
529
|
+
// After fix, source files have complior() wrapper but semgrep still flags method calls.
|
|
530
|
+
const wrappedFiles = new Set<string>();
|
|
531
|
+
for (const f of ctx.files) {
|
|
532
|
+
if (f.content.includes('@complior/sdk') && /complior\s*\(/.test(f.content)) {
|
|
533
|
+
wrappedFiles.add(f.relativePath);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
const filteredMerged = mergedFindings.filter((f) => {
|
|
537
|
+
if (f.checkId.startsWith('ext-semgrep-complior-bare-call') && f.file && wrappedFiles.has(f.file)) return false;
|
|
538
|
+
return true;
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
// 5c. Enrich external findings with fixDiff and codeContext
|
|
542
|
+
const fileMap = new Map<string, string>();
|
|
543
|
+
for (const f of ctx.files) {
|
|
544
|
+
fileMap.set(f.relativePath, f.content);
|
|
545
|
+
}
|
|
546
|
+
const enrichedMerged = enrichFindings(filteredMerged, fileMap);
|
|
547
|
+
|
|
548
|
+
// 6. Recalculate score
|
|
549
|
+
const mergedCheckResults = findingsToCheckResults(enrichedMerged);
|
|
550
|
+
|
|
551
|
+
const score = scoringData !== undefined
|
|
552
|
+
? calculateScore(mergedCheckResults, scoringData)
|
|
553
|
+
: createFallbackScore(mergedFindings);
|
|
554
|
+
|
|
555
|
+
return {
|
|
556
|
+
score: { ...score, confidenceSummary: baseResult.score.confidenceSummary },
|
|
557
|
+
findings: enrichedMerged,
|
|
558
|
+
projectPath: baseResult.projectPath,
|
|
559
|
+
scannedAt: baseResult.scannedAt,
|
|
560
|
+
duration: Date.now() - tier2Start,
|
|
561
|
+
filesScanned: baseResult.filesScanned,
|
|
562
|
+
regulationVersion: baseResult.regulationVersion,
|
|
563
|
+
tier: 2,
|
|
564
|
+
externalToolResults: toolResults,
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
: undefined;
|
|
568
|
+
|
|
569
|
+
return Object.freeze({ scan, scanDeep, scanTier2 });
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
// Re-export types for backward compatibility
|
|
573
|
+
export type { CheckFunction, ScanContext, FileInfo } from '../../ports/scanner.port.js';
|