Skip to main content

lean_ctx/core/intelligence_runtime/
compliance_frameworks.rs

1// SPDX-License-Identifier: Apache-2.0
2//! Enterprise framework coverage over the one engine: the engine sends the
3//! facts of [`crate::core::compliance_evidence::facts`], the licensed runtime
4//! answers with its framework assessment, and the engine checks, signs and
5//! renders it. The mappings never reach this tree.
6use super::InstallError;
7use crate::core::compliance_evidence::{facts::ComplianceFactsV1, frameworks::FrameworksAnswer};
8
9pub(crate) const CAPABILITY_ID: &str = "enterprise.runtime.compliance_frameworks";
10pub(crate) const CAPABILITY_VERSION: &str = "1.0.0";
11
12const CAPABILITY: super::exchange::Capability = super::exchange::Capability {
13    id: CAPABILITY_ID,
14    version: CAPABILITY_VERSION,
15    declared: super::health::supports_compliance_frameworks,
16    deadline_ms: 10_000,
17    tag: "compliance",
18};
19
20/// What a Community install tells the operator instead of a framework report.
21pub(crate) const ENTERPRISE_HINT: &str = "framework coverage (EU AI Act, ISO 42001, SOC 2) is \
22     part of LeanCTX Enterprise and needs the licensed runtime; `lean-ctx compliance facts` \
23     shows what it is assessed on, `lean-ctx compliance verify` works without a license";
24
25/// Ask the licensed runtime for the framework reports of `facts`. The caller
26/// checks the answer against the request ([`FrameworksAnswer::check`]).
27pub fn assess(facts: &ComplianceFactsV1) -> Result<FrameworksAnswer, String> {
28    let input = serde_json::to_string(facts).map_err(|e| format!("compliance facts: {e}"))?;
29    match super::exchange::invoke(&CAPABILITY, &input) {
30        Ok(output) => serde_json::from_str(&output)
31            .map_err(|_| "compliance runtime answer refused: not a frameworks answer".to_string()),
32        Err(InstallError::Policy | InstallError::Manifest) => Err(ENTERPRISE_HINT.to_string()),
33        Err(error) => Err(format!(
34            "compliance runtime failed ({error}); an active LeanCTX Enterprise lease is required"
35        )),
36    }
37}