{
 "audit": "CAIN-42 L5 Governance \u2014 Part 40: Full Repository Evolution Audit",
 "generated": "2026-09-28",
 "repository": "<redacted-path>/cain-studio-platform",
 "method": {
  "scope": "All 6,518 git-tracked files; 2,476 Python modules scanned by language-aware import + pattern analysis.",
  "boundaries": {
   "MCPGate": "cain/mcp_proxy.py :: MCPTransparentInterceptor (also StdioMCPProxy, create_mcp_proxy_app)",
   "TRUST_KERNEL": "platform-gateway/cain_trust_kernel.py :: CainTrustRuntimeKernel / ActionCapabilityToken",
   "FABRIC": "platform-gateway/fabric_control_plane.py :: TrustFabricControlPlane / record_decision",
   "HYPERVISOR": "cain45/hypervisor.py :: AgentHypervisor (run/call_tool; confine.py bwrap+cgroup)",
   "SDK_GUARD": "cain/guard.py + cain/wrap.py + cain/adapters/* (in-process decorator surface)"
  },
  "governance_reachability": "Two-way import reachability to the four boundary files (plus the cain/guard.py SDK surface). 531 modules transitively import a boundary; 97 are callees of a boundary; union 603. 'GOVERNED' means the file/function is the boundary, a caller of it, or a callee invoked only from it. 'UNGOVERNED' means no import path to a boundary. 'PARTIALLY_GOVERNED' means some entry points route through a boundary and others do not (or governance is opt-in per call).",
  "caveats": [
   "File-level reachability is an approximation of call-site governance: an ungoverned module can be reached from a governed caller only if it is imported by it.",
   "Test coverage is measured by importing test modules, so suites that drive a module over HTTP/subprocess count as zero importers.",
   "Generated/vendored duplicates (build/, private/, quarantine/, cain/substrate/) are reported separately and excluded from per-category counts except where they are the point of the finding."
  ],
  "excluded_from_counts": [
   "build/lib/**",
   "private/unpublished/**",
   "quarantine/**",
   "cain/substrate/** (reported as duplication)"
  ]
 },
 "summary": {
  "consequential_findings": 84,
  "governed": 23,
  "ungoverned": 57,
  "partially_governed": 4,
  "not_applicable": 0,
  "duplicate_findings": 12,
  "dead_code_candidates": 10,
  "undocumented_assumptions": 15,
  "security_gaps": 14,
  "missing_test_groups": 9,
  "performance_findings": 7,
  "canonical_production_modules": 1061,
  "modules_with_zero_importing_tests": 477,
  "canonical_modules_imported_by_nothing": 200,
  "modules_reaching_a_boundary": 603,
  "byte_identical_duplicate_py_files": 457
 },
 "boundary_map": {
  "MCPGate": "cain/mcp_proxy.py :: MCPTransparentInterceptor (also StdioMCPProxy, create_mcp_proxy_app)",
  "TRUST_KERNEL": "platform-gateway/cain_trust_kernel.py :: CainTrustRuntimeKernel / ActionCapabilityToken",
  "FABRIC": "platform-gateway/fabric_control_plane.py :: TrustFabricControlPlane / record_decision",
  "HYPERVISOR": "cain45/hypervisor.py :: AgentHypervisor (run/call_tool; confine.py bwrap+cgroup)",
  "SDK_GUARD": "cain/guard.py + cain/wrap.py + cain/adapters/* (in-process decorator surface)"
 },
 "findings": [
  {
   "id": "SHELL-01",
   "file": "talos-coder/daemon/tools/run_command.py",
   "line": 48,
   "symbol": "RunCommandTool.execute",
   "category": "subprocess/shell",
   "status": "UNGOVERNED",
   "severity": "HIGH",
   "governance_boundary": "none (no CAIN import anywhere in talos-coder/)",
   "note": "shell=True with caller-widened allowed_prefixes; whole talos-coder daemon executes shell, reads/edits files and walks outside the CAIN boundary. Default allowlist in main.py is read-only-ish but the tool itself permits unrestricted shell when allowed_prefixes=None."
  },
  {
   "id": "SHELL-02",
   "file": "talos-coder/daemon/loop.py",
   "line": 285,
   "symbol": "AgentLoop._run_lint_or_test",
   "category": "subprocess/shell",
   "status": "UNGOVERNED",
   "severity": "MEDIUM",
   "governance_boundary": "none",
   "note": "Quality-gate commands (lint_cmd/test_cmd from DaemonConfig) executed via subprocess.run with no CAIN evaluation."
  },
  {
   "id": "SHELL-03",
   "file": "cain/customer_cli.py",
   "line": 372,
   "symbol": "launch_protected_agent",
   "category": "subprocess/shell",
   "status": "PARTIALLY_GOVERNED",
   "severity": "LOW",
   "governance_boundary": "inherits CAIN_MODE=enforce in child env",
   "note": "Launches the customer agent with CAIN_MODE=enforce and CAIN_API_KEY exported; the launch itself is unguarded, governance only applies if the child calls the SDK/MCPGate."
  },
  {
   "id": "SHELL-04",
   "file": "cain/frontier/discovery.py",
   "line": 13,
   "symbol": "_sh",
   "category": "subprocess/shell",
   "status": "UNGOVERNED",
   "severity": "LOW",
   "governance_boundary": "none",
   "note": "shell=True discovery of host processes/MCP configs; fixed command strings, but on the frontier loop, not through a boundary."
  },
  {
   "id": "SHELL-05",
   "file": "cain/frontier/cluster.py",
   "line": 12,
   "symbol": "_sh",
   "category": "subprocess/shell",
   "status": "UNGOVERNED",
   "severity": "MEDIUM",
   "governance_boundary": "none",
   "note": "shell=True `docker inspect $(docker ps -q ...)` string interpolation; host command execution feeding the Trust-BOM. Not on a governed path."
  },
  {
   "id": "SHELL-06",
   "file": "cain/cain_kernel_enforcement.py",
   "line": 403,
   "symbol": "KernelEnforcer/proc launch",
   "category": "subprocess/plugin-exec",
   "status": "UNGOVERNED",
   "severity": "MEDIUM",
   "governance_boundary": "none (ungoverned duplicate)",
   "note": "Duplicate of the governed platform-gateway/cain_kernel_enforcement.py (which IS a callee of mcp_proxy/universal_wrapper). The cain/ copy is not imported by any boundary."
  },
  {
   "id": "SHELL-07",
   "file": "platform-gateway/cain_lab_public.py",
   "line": 81,
   "symbol": "_docker / _running",
   "category": "cloud/infra control",
   "status": "UNGOVERNED",
   "severity": "HIGH",
   "governance_boundary": "none",
   "note": "Public lab API can `docker stop` / `docker start` / `docker inspect` named sandbox containers directly via subprocess, with no CAIN decision."
  },
  {
   "id": "SHELL-08",
   "file": "cain-microservices/swarm-orchestrator/main.py",
   "line": 143,
   "symbol": "_load_k8s_client / apply",
   "category": "cloud/k8s control",
   "status": "UNGOVERNED",
   "severity": "HIGH",
   "governance_boundary": "none",
   "note": "Direct Kubernetes NetworkingV1Api create/delete of NetworkPolicies; no CAIN authorization on the mutation. Sibling of the K8s appliance monetisation channel."
  },
  {
   "id": "SHELL-09",
   "file": "cain-microservices/orchestrator/causal_orchestrator.py",
   "line": 15,
   "symbol": "docker.from_env",
   "category": "cloud/docker control",
   "status": "UNGOVERNED",
   "severity": "HIGH",
   "governance_boundary": "none",
   "note": "Docker daemon client at import; orchestrates containers without a CAIN decision."
  },
  {
   "id": "SHELL-10",
   "file": "cain-microservices/resilience-controller/main.py",
   "line": 163,
   "symbol": "docker.from_env",
   "category": "cloud/docker control",
   "status": "UNGOVERNED",
   "severity": "HIGH",
   "governance_boundary": "none",
   "note": "Restarts/stops containers directly; infrastructure mutation outside the boundary."
  },
  {
   "id": "SHELL-11",
   "file": "platform-gateway/resilience_controller.py",
   "line": 3,
   "symbol": "kubernetes client",
   "category": "cloud/k8s control",
   "status": "UNGOVERNED",
   "severity": "HIGH",
   "governance_boundary": "none",
   "note": "Kubernetes client loaded at module import; controller actions are not routed through fabric/hypervisor."
  },
  {
   "id": "SHELL-12",
   "file": "platform-gateway/cain_runtime_trust.py",
   "line": 6592,
   "symbol": "KMS provider (boto3)",
   "category": "credential/cloud",
   "status": "UNGOVERNED",
   "severity": "MEDIUM",
   "governance_boundary": "none",
   "note": "AWS KMS client constructed in the trust-runtime module; key operations bypass the local KMS boundary (cain_kms.py) and the kernel."
  },
  {
   "id": "SHELL-13",
   "file": "cain-microservices/sparselogic-compiler/src/sparselogic_compiler/synthesis.py",
   "line": 114,
   "symbol": "synthesis (yosys/nextpnr/pack)",
   "category": "subprocess/shell",
   "status": "UNGOVERNED",
   "severity": "LOW",
   "governance_boundary": "none",
   "note": "EDA toolchain subprocesses; tool names/paths are internal, but no CAIN gate."
  },
  {
   "id": "SHELL-14",
   "file": "cain-sandbox/main.py",
   "line": 252,
   "symbol": "execute -> asyncio.create_subprocess_exec",
   "category": "subprocess/agent-code-exec",
   "status": "UNGOVERNED",
   "severity": "MEDIUM",
   "governance_boundary": "none (isolated container, explicitly disclosed)",
   "note": "Executes agent-generated code in a dedicated internal docker network with NO governance boundary, only an isolation boundary. Docstring is honest about the limits (no no-new-privileges, no VM)."
  },
  {
   "id": "SHELL-15",
   "file": "platform-gateway/cain_formal_verifier.py",
   "line": 111,
   "symbol": "verify via subprocess",
   "category": "subprocess/shell",
   "status": "UNGOVERNED",
   "severity": "LOW",
   "governance_boundary": "none",
   "note": "Runs external verifier; audit tooling."
  },
  {
   "id": "SHELL-16",
   "file": "platform-gateway/cain_claim_auditor_19.py",
   "line": 163,
   "symbol": "pytest per claim",
   "category": "subprocess/shell",
   "status": "UNGOVERNED",
   "severity": "LOW",
   "governance_boundary": "none",
   "note": "Spawns `pytest <target>` per claim (see PERF-01)."
  },
  {
   "id": "SHELL-17",
   "file": "platform-gateway/cain_claim_auditor_20.py",
   "line": 176,
   "symbol": "pytest per claim",
   "category": "subprocess/shell",
   "status": "UNGOVERNED",
   "severity": "LOW",
   "governance_boundary": "none",
   "note": "Same pattern."
  },
  {
   "id": "SHELL-18",
   "file": "platform-gateway/cain_claim_auditor_22.py",
   "line": 96,
   "symbol": "pytest per claim",
   "category": "subprocess/shell",
   "status": "UNGOVERNED",
   "severity": "LOW",
   "governance_boundary": "none",
   "note": "Same pattern."
  },
  {
   "id": "SHELL-19",
   "file": "platform-gateway/cain_conformance_23.py",
   "line": 111,
   "symbol": "git/pytest subprocess",
   "category": "subprocess/shell",
   "status": "UNGOVERNED",
   "severity": "LOW",
   "governance_boundary": "none",
   "note": "Conformance harness."
  },
  {
   "id": "SHELL-20",
   "file": "platform-gateway/cain_rfc3161.py",
   "line": 69,
   "symbol": "openssl ts",
   "category": "subprocess/shell",
   "status": "UNGOVERNED",
   "severity": "LOW",
   "governance_boundary": "none",
   "note": "RFC3161 timestamping via openssl; not a boundary callee (cain_pqc.py IS a callee and is governed)."
  },
  {
   "id": "SHELL-21",
   "file": "cain/mcp_proxy.py",
   "line": 855,
   "symbol": "StdioMCPProxy.run -> subprocess.Popen",
   "category": "subprocess/mcp-exec",
   "status": "GOVERNED",
   "severity": "NOT_APPLICABLE",
   "governance_boundary": "MCPGate (this file IS the boundary)",
   "note": "Spawning the downstream MCP server is the boundary's own act, guarded by evaluate_tool_call + JIT consume + optional seccomp preexec."
  },
  {
   "id": "SHELL-22",
   "file": "cain/universal_wrapper.py",
   "line": 149,
   "symbol": "MCPSmartWrapper discovery/dispatch",
   "category": "subprocess/mcp-exec",
   "status": "GOVERNED",
   "severity": "NOT_APPLICABLE",
   "governance_boundary": "MCPGate interceptor used by the wrapper",
   "note": "Both discovery and invoke go through MCPTransparentInterceptor; deny raises CainActionBlockedException in strict mode."
  },
  {
   "id": "SHELL-23",
   "file": "cain/cli_tools.py",
   "line": 122,
   "symbol": "VisualStdioMCPProxy.run",
   "category": "subprocess/mcp-exec",
   "status": "GOVERNED",
   "severity": "NOT_APPLICABLE",
   "governance_boundary": "MCPGate interceptor",
   "note": "Visual firewall wraps the same interceptor; non-TTY fails closed."
  },
  {
   "id": "SHELL-24",
   "file": "platform-gateway/cain_kernel_enforcement.py",
   "line": 403,
   "symbol": "kernel enforcer preexec",
   "category": "subprocess/mcp-exec",
   "status": "GOVERNED",
   "severity": "NOT_APPLICABLE",
   "governance_boundary": "callee of MCPGate/universal_wrapper",
   "note": "libseccomp preexec builder used by the governed stdio proxy."
  },
  {
   "id": "EVAL-01",
   "file": "platform-gateway/cain_control_loop.py",
   "line": 2092,
   "symbol": "SafeExpressionEvaluator.evaluate",
   "category": "eval/exec",
   "status": "UNGOVERNED",
   "severity": "MEDIUM",
   "governance_boundary": "none",
   "note": "eval(compile(...), {'__builtins__': {}}, ctx) \u2014 restricted builtins but still eval on policy expressions; module is not on a governed path. Duplicate at cain/substrate/cain_control_loop.py."
  },
  {
   "id": "EVAL-02",
   "file": "cain/substrate/cain_control_loop.py",
   "line": 2092,
   "symbol": "SafeExpressionEvaluator.evaluate",
   "category": "eval/exec",
   "status": "UNGOVERNED",
   "severity": "MEDIUM",
   "governance_boundary": "none",
   "note": "Stale duplicate of EVAL-01."
  },
  {
   "id": "EVAL-03",
   "file": "platform-gateway/cain_epoch10_public.py",
   "line": 101,
   "symbol": "importlib spec_from_file_location/exec_module",
   "category": "dynamic import",
   "status": "UNGOVERNED",
   "severity": "LOW",
   "governance_boundary": "none",
   "note": "Loads modules by file path at runtime; public evidence builder."
  },
  {
   "id": "DB-01",
   "file": "cain45/hypervisor.py",
   "line": 155,
   "symbol": "AgentHypervisor._transition / _put / terminate",
   "category": "database mutation",
   "status": "GOVERNED",
   "severity": "NOT_APPLICABLE",
   "governance_boundary": "HYPERVISOR",
   "note": "All ZoD/state/evidence/grant/revocation writes are inside the hypervisor authority boundary; raw sqlite writes are the boundary's own evidence store."
  },
  {
   "id": "DB-02",
   "file": "platform-gateway/fabric_control_plane.py",
   "line": 887,
   "symbol": "record_decision / _conn",
   "category": "database mutation",
   "status": "GOVERNED",
   "severity": "NOT_APPLICABLE",
   "governance_boundary": "FABRIC",
   "note": "Decision/principal/approval/kill-switch writes are the control plane itself; uses per-thread pooled WAL connection."
  },
  {
   "id": "DB-03",
   "file": "platform-gateway/cain_trust_kernel.py",
   "line": 2164,
   "symbol": "audit_event_ledger / dual custody",
   "category": "database mutation",
   "status": "GOVERNED",
   "severity": "NOT_APPLICABLE",
   "governance_boundary": "TRUST_KERNEL",
   "note": "Kernel state/evidence persistence is the kernel's own."
  },
  {
   "id": "DB-04",
   "file": "platform-gateway/agent_runtime.py",
   "line": 1520,
   "symbol": "record_tool_call / runtime tables",
   "category": "database mutation",
   "status": "UNGOVERNED",
   "severity": "MEDIUM",
   "governance_boundary": "none",
   "note": "Agent runtime records tool calls and budgets in its own runtime_tool_calls table, but does not consult MCPGate/fabric/kernel before or after; it is an accounting layer, not a gate. DB calls inside loops (see PERF-02)."
  },
  {
   "id": "DB-05",
   "file": "platform-gateway/cain_a2a.py",
   "line": 202,
   "symbol": "_get_conn + session/delegation writes",
   "category": "database mutation / agent delegation",
   "status": "UNGOVERNED",
   "severity": "MEDIUM",
   "governance_boundary": "none",
   "note": "A2A sessions, delegations, capability tokens and audit log persisted directly; A2A server-side path does not route through MCPGate/hypervisor."
  },
  {
   "id": "DB-06",
   "file": "platform-gateway/cain_skills.py",
   "line": 276,
   "symbol": "skill registry writes",
   "category": "database mutation / plugin registry",
   "status": "UNGOVERNED",
   "severity": "MEDIUM",
   "governance_boundary": "none",
   "note": "Skill/plugin registry and executions table written directly; no authorisation on publish/upgrade/revoke."
  },
  {
   "id": "DB-07",
   "file": "platform-gateway/cain_discovery.py",
   "line": null,
   "symbol": "discovery DB writes",
   "category": "database mutation",
   "status": "UNGOVERNED",
   "severity": "LOW",
   "governance_boundary": "none",
   "note": "Inventory persistence."
  },
  {
   "id": "DB-08",
   "file": "platform-gateway/cain_compliance.py",
   "line": null,
   "symbol": "compliance records",
   "category": "database mutation",
   "status": "UNGOVERNED",
   "severity": "LOW",
   "governance_boundary": "none",
   "note": "Compliance-as-a-Service records; no boundary call before write."
  },
  {
   "id": "DB-09",
   "file": "platform-gateway/cain_security_core.py",
   "line": null,
   "symbol": "security core records",
   "category": "database mutation",
   "status": "UNGOVERNED",
   "severity": "LOW",
   "governance_boundary": "none",
   "note": "Persists security state directly."
  },
  {
   "id": "DB-10",
   "file": "cainaccounts/main.py",
   "line": null,
   "symbol": "account DB writes",
   "category": "database mutation",
   "status": "UNGOVERNED",
   "severity": "LOW",
   "governance_boundary": "none",
   "note": "Separate service; identity/billing DB."
  },
  {
   "id": "DB-11",
   "file": "billing-service/db.py",
   "line": null,
   "symbol": "billing DB writes",
   "category": "database mutation",
   "status": "UNGOVERNED",
   "severity": "LOW",
   "governance_boundary": "none",
   "note": "Separate billing service."
  },
  {
   "id": "DB-12",
   "file": "clawx/control_plane/store.py",
   "line": null,
   "symbol": "grant/revocation/ledger store",
   "category": "database mutation",
   "status": "GOVERNED",
   "severity": "NOT_APPLICABLE",
   "governance_boundary": "callee of cain.guard (clawx/cain_boundary.py)",
   "note": "clawx control-plane store is reached through the cain.guard surface."
  },
  {
   "id": "DB-13",
   "file": "platform-gateway/runtime_engine.py",
   "line": 1250,
   "symbol": "delegate_task / runtime DB",
   "category": "database mutation / delegation",
   "status": "UNGOVERNED",
   "severity": "MEDIUM",
   "governance_boundary": "none",
   "note": "Runtime engine persists tasks/steps/costs directly; delegate_task has no assess_call into a boundary."
  },
  {
   "id": "FS-01",
   "file": "platform-gateway/cain_kms.py",
   "line": 138,
   "symbol": "_save_encrypted_private_key / cert write",
   "category": "filesystem mutation / credential",
   "status": "UNGOVERNED",
   "severity": "HIGH",
   "governance_boundary": "none",
   "note": "Writes RSA private key (encrypted, 0600) and public cert to /app/data; key-management is its own module and is not gated. See CRED-01."
  },
  {
   "id": "FS-02",
   "file": "clawx/control_plane/keys.py",
   "line": 37,
   "symbol": "signer rotation os.unlink",
   "category": "filesystem mutation / credential",
   "status": "GOVERNED",
   "severity": "NOT_APPLICABLE",
   "governance_boundary": "callee of cain.guard surface",
   "note": "Atomic signer-key rotation; reached through the guard surface."
  },
  {
   "id": "FS-03",
   "file": "platform-gateway/cain_disaster_recovery_42.py",
   "line": 275,
   "symbol": "shutil.rmtree(temp_dir)",
   "category": "filesystem mutation",
   "status": "UNGOVERNED",
   "severity": "LOW",
   "governance_boundary": "none",
   "note": "Temp cleanup; no gate needed but tracked."
  },
  {
   "id": "FS-04",
   "file": "platform-gateway/cain_frontier_lab_api.py",
   "line": 68,
   "symbol": "close -> shutil.rmtree",
   "category": "filesystem mutation",
   "status": "UNGOVERNED",
   "severity": "LOW",
   "governance_boundary": "none",
   "note": "Lab workspace teardown."
  },
  {
   "id": "FS-05",
   "file": "cain-microservices/visual-ide/main.py",
   "line": 126,
   "symbol": "shutil.rmtree(work_dir)",
   "category": "filesystem mutation",
   "status": "UNGOVERNED",
   "severity": "LOW",
   "governance_boundary": "none",
   "note": "Per-job workspace cleanup."
  },
  {
   "id": "FS-06",
   "file": "cain-microservices/weight-alchemist/main.py",
   "line": null,
   "symbol": "model weight FS writes",
   "category": "filesystem mutation",
   "status": "UNGOVERNED",
   "severity": "MEDIUM",
   "governance_boundary": "none",
   "note": "Writes/removes model artifacts without a boundary call."
  },
  {
   "id": "FS-07",
   "file": "platform-gateway/cain_dual_custody_store.py",
   "line": null,
   "symbol": "dual-custody store writes",
   "category": "filesystem mutation / credential",
   "status": "UNGOVERNED",
   "severity": "MEDIUM",
   "governance_boundary": "none",
   "note": "Dual-custody material on disk; kernel references a separate dual-custody engine."
  },
  {
   "id": "CRED-01",
   "file": "platform-gateway/cain_kms.py",
   "line": 84,
   "symbol": "KeyManager passphrase derivation",
   "category": "credential use",
   "status": "UNGOVERNED",
   "severity": "HIGH",
   "governance_boundary": "none",
   "note": "raw_passphrase = passphrase or CAIN_KMS_MASTER_KEY or CAIN_JWT_SECRET or 'cain-default-secure-vault-passphrase-2026'. A hard-coded, publicly-known fallback passphrase protects the RSA signing key at rest whenever both env vars are unset \u2014 a silent weak-key condition, not a crash."
  },
  {
   "id": "CRED-02",
   "file": "cain/sovereign.py",
   "line": 122,
   "symbol": "LocalRootOfTrust key storage",
   "category": "credential use",
   "status": "UNGOVERNED",
   "severity": "MEDIUM",
   "governance_boundary": "none",
   "note": "Ed25519/ML-DSA keys stored 0600 under /tmp/cain-sovereign-keys by default; no HSM/TEE (documented), but default path is world-writable /tmp."
  },
  {
   "id": "CRED-03",
   "file": "platform-gateway/bin/cain_node_identity.py",
   "line": 58,
   "symbol": "NodeIdentity private key",
   "category": "credential use",
   "status": "UNGOVERNED",
   "severity": "MEDIUM",
   "governance_boundary": "none",
   "note": "Node Ed25519 private key written to <redacted-path>/identity/*.pem (0600); key generation/loading not gated by a boundary."
  },
  {
   "id": "CRED-04",
   "file": "platform-gateway/cain_runtime_trust.py",
   "line": 6592,
   "symbol": "AWS KMS",
   "category": "credential use / cloud",
   "status": "UNGOVERNED",
   "severity": "MEDIUM",
   "governance_boundary": "none",
   "note": "External KMS usage inside trust-runtime."
  },
  {
   "id": "CRED-05",
   "file": "platform-gateway/cain_attestation.py",
   "line": null,
   "symbol": "attestation signing keys",
   "category": "credential use",
   "status": "UNGOVERNED",
   "severity": "MEDIUM",
   "governance_boundary": "none",
   "note": "Signing material handled outside the kernel boundary."
  },
  {
   "id": "CRED-06",
   "file": "platform-gateway/cain_kernel_self_defense.py",
   "line": null,
   "symbol": "dual-custody root keys",
   "category": "credential use",
   "status": "GOVERNED",
   "severity": "NOT_APPLICABLE",
   "governance_boundary": "callee of TRUST_KERNEL",
   "note": "Dual-custody key registration is a kernel surface."
  },
  {
   "id": "CRED-07",
   "file": "cain/quarantine.py",
   "line": null,
   "symbol": "SQLite quarantine state",
   "category": "credential/state",
   "status": "GOVERNED",
   "severity": "NOT_APPLICABLE",
   "governance_boundary": "callee of MCPGate (check_still_authorized) / guard",
   "note": "Containment state read on every MCP call and every guard evaluation."
  },
  {
   "id": "CRED-08",
   "file": "cain5/identity_sdk.py",
   "line": null,
   "symbol": "identity SDK secrets",
   "category": "credential use",
   "status": "UNGOVERNED",
   "severity": "MEDIUM",
   "governance_boundary": "none",
   "note": "cain5 identity SDK handles secrets/tokens without a boundary."
  },
  {
   "id": "CRED-09",
   "file": "content-provenance/main.py",
   "line": null,
   "symbol": "provenance credentials",
   "category": "credential use",
   "status": "UNGOVERNED",
   "severity": "LOW",
   "governance_boundary": "none",
   "note": "Standalone service credentials."
  },
  {
   "id": "CRED-10",
   "file": "taloscrypt-mesh/engine.py",
   "line": null,
   "symbol": "mesh credentials",
   "category": "credential use",
   "status": "UNGOVERNED",
   "severity": "LOW",
   "governance_boundary": "none",
   "note": "Standalone product scaffolding."
  },
  {
   "id": "DEL-01",
   "file": "cain/universal_wrapper.py",
   "line": 492,
   "symbol": "A2AAgentWrapper.send_task",
   "category": "agent delegation",
   "status": "PARTIALLY_GOVERNED",
   "severity": "HIGH",
   "governance_boundary": "MCPGate wrapper (send_task) but self-signed passport check",
   "note": "verify_passport() checks the signature against the SAME fabric's own public key; a delegation is accepted if it is self-consistent, not if the parent actually holds the authority. Capability subset/budget/depth are enforced structurally, but the trust root is the presenter's own key."
  },
  {
   "id": "DEL-02",
   "file": "cain45/hypervisor.py",
   "line": 369,
   "symbol": "create_zod / child_within_parent",
   "category": "agent delegation",
   "status": "GOVERNED",
   "severity": "NOT_APPLICABLE",
   "governance_boundary": "HYPERVISOR",
   "note": "Child authority \u2264 parent authority is enforced at spawn and continuously via _ancestor_problem; delegation is PBFT-ordered and evidenced."
  },
  {
   "id": "DEL-03",
   "file": "cain45/hypervisor.py",
   "line": 649,
   "symbol": "run / call_tool (the two doors)",
   "category": "agent delegation / execution",
   "status": "GOVERNED",
   "severity": "NOT_APPLICABLE",
   "governance_boundary": "HYPERVISOR",
   "note": "Both doors re-check state, grant signature/bindings, expiry, revocation, trust floor, security context and trajectory continuity on every use."
  },
  {
   "id": "DEL-04",
   "file": "platform-gateway/cain_a2a.py",
   "line": 202,
   "symbol": "A2A server (sessions/delegations)",
   "category": "agent delegation",
   "status": "UNGOVERNED",
   "severity": "MEDIUM",
   "governance_boundary": "none",
   "note": "Server-side A2A session/delegation engine not routed through a boundary; separate from the wrapped client path in DEL-01."
  },
  {
   "id": "DEL-05",
   "file": "platform-gateway/a2a_delegation.py",
   "line": null,
   "symbol": "A2A delegation",
   "category": "agent delegation",
   "status": "UNGOVERNED",
   "severity": "MEDIUM",
   "governance_boundary": "none",
   "note": "Parallel A2A delegation implementation."
  },
  {
   "id": "DEL-06",
   "file": "platform-gateway/cain_delegation_sovereignty_19.py",
   "line": null,
   "symbol": "delegation sovereignty",
   "category": "agent delegation",
   "status": "UNGOVERNED",
   "severity": "MEDIUM",
   "governance_boundary": "none",
   "note": "19-series delegation fabric; not wired to MCPGate."
  },
  {
   "id": "DEL-07",
   "file": "platform-gateway/cain_delegation_graph_42.py",
   "line": null,
   "symbol": "delegation graph",
   "category": "agent delegation",
   "status": "UNGOVERNED",
   "severity": "LOW",
   "governance_boundary": "none",
   "note": "Graph analysis of delegation; read-only."
  },
  {
   "id": "DEL-08",
   "file": "clawx/control_plane/grants.py",
   "line": 97,
   "symbol": "Grant.delegate",
   "category": "agent delegation",
   "status": "GOVERNED",
   "severity": "NOT_APPLICABLE",
   "governance_boundary": "callee of cain.guard surface",
   "note": "Monotonic grant delegation inside the clawx control plane."
  },
  {
   "id": "DEL-09",
   "file": "cain/frontier/capability.py",
   "line": 90,
   "symbol": "delegate",
   "category": "agent delegation",
   "status": "GOVERNED",
   "severity": "NOT_APPLICABLE",
   "governance_boundary": "callee of cain.frontier.gate (MCPGate frontier layer)",
   "note": "Capability attenuation with signed tokens."
  },
  {
   "id": "DEL-10",
   "file": "platform-gateway/cain_agi_multiagent.py",
   "line": 32,
   "symbol": "delegate_A_to_B",
   "category": "agent delegation",
   "status": "UNGOVERNED",
   "severity": "MEDIUM",
   "governance_boundary": "none",
   "note": "AGI multi-agent handoff helper; no boundary call."
  },
  {
   "id": "MCP-01",
   "file": "platform-gateway/mcp_enforcement_api.py",
   "line": 36,
   "symbol": "enforce",
   "category": "MCP tool execution",
   "status": "GOVERNED",
   "severity": "NOT_APPLICABLE",
   "governance_boundary": "MCPGate (MCPTransparentInterceptor strict)",
   "note": "HTTP enforcement endpoint runs the real interceptor in strict mode."
  },
  {
   "id": "MCP-02",
   "file": "platform-gateway/mcp_runtime.py",
   "line": 775,
   "symbol": "MCPSecurityRuntime.pre_tool_call / post_tool_call",
   "category": "MCP tool execution",
   "status": "UNGOVERNED",
   "severity": "MEDIUM",
   "governance_boundary": "none (parallel validator, not wired into MCPGate)",
   "note": "A second MCP validation/scanner runtime (tool registry, injection scan, risk score). It is NOT imported by cain/mcp_proxy.py; only by agi_boundary/compliance modules \u2014 two MCP gatekeeping stacks that can drift."
  },
  {
   "id": "MCP-03",
   "file": "cain/tool_metadata_guard.py",
   "line": null,
   "symbol": "ToolMetadataGuard",
   "category": "MCP tool metadata",
   "status": "GOVERNED",
   "severity": "NOT_APPLICABLE",
   "governance_boundary": "MCPGate (used in _evaluate_tool_call_legacy and tools/list filtering)",
   "note": "Pins tool schemas, quarantines rug-pulled/poisoned tools."
  },
  {
   "id": "MCP-04",
   "file": "platform-gateway/cain_skills.py",
   "line": null,
   "symbol": "skill publish/execute/upgrade/revoke",
   "category": "plugin execution / registry",
   "status": "UNGOVERNED",
   "severity": "MEDIUM",
   "governance_boundary": "none",
   "note": "Reusable-capability (skill) registry mutation has no authorization; implies plugin dynamic behaviour not gated."
  },
  {
   "id": "MCP-05",
   "file": "cain/adapters/crewai.py",
   "line": null,
   "symbol": "guard_agent / guard_crew",
   "category": "tool execution (framework)",
   "status": "GOVERNED",
   "severity": "NOT_APPLICABLE",
   "governance_boundary": "cain.guard decorator surface",
   "note": "Opt-in framework wrapping."
  },
  {
   "id": "MCP-06",
   "file": "cain/adapters/langchain.py",
   "line": null,
   "symbol": "CainCallbackHandler/wrap",
   "category": "tool execution (framework)",
   "status": "GOVERNED",
   "severity": "NOT_APPLICABLE",
   "governance_boundary": "cain.guard",
   "note": "Opt-in."
  },
  {
   "id": "MCP-07",
   "file": "cain/adapters/llamaindex.py",
   "line": null,
   "symbol": "guard_tool",
   "category": "tool execution (framework)",
   "status": "GOVERNED",
   "severity": "NOT_APPLICABLE",
   "governance_boundary": "cain.guard",
   "note": "Opt-in."
  },
  {
   "id": "MCP-08",
   "file": "cain/wrap.py",
   "line": null,
   "symbol": "wrap (OpenAI client interception)",
   "category": "tool execution (model)",
   "status": "PARTIALLY_GOVERNED",
   "severity": "MEDIUM",
   "governance_boundary": "cain.guard on the chat-completions tool_calls path",
   "note": "Intercepts only the OpenAI-style client.chat.completions path; per CAIN45_BYPASS_AUDIT strict mode returns the tool call to the agent rather than blocking execution in the UNREACHABLE probe, and non-strict is advisory by design."
  },
  {
   "id": "API-01",
   "file": "platform-gateway/main.py",
   "line": null,
   "symbol": "FastAPI monolith (446 modules, 7138 LOC)",
   "category": "direct API surface",
   "status": "PARTIALLY_GOVERNED",
   "severity": "HIGH",
   "governance_boundary": "fabric_control_plane for /fabric/* and decisions; MCPGate for /mcp/*; many endpoints are direct",
   "note": "The gateway is the largest surface; a subset (fabric decisions, mcp enforcement, sovereign control after the 2026-09-27 fix) is governed, but hundreds of endpoints are direct DB/HTML/ops with no boundary call. The sovereign write fix exists only in this copy (see DUP-02)."
  },
  {
   "id": "API-02",
   "file": "cain/frontier/runtime.py",
   "line": null,
   "symbol": "get_gate / GateDecision",
   "category": "direct API/execution gating",
   "status": "GOVERNED",
   "severity": "NOT_APPLICABLE",
   "governance_boundary": "MCPGate frontier layer (_frontier_check)",
   "note": "Capability chain + world model + session + budget; default mode is 'shadow' (see ASSUME-06)."
  },
  {
   "id": "PERF-01",
   "file": "platform-gateway/cain_claim_auditor_22.py",
   "line": 96,
   "symbol": "audit loop",
   "category": "performance",
   "status": "UNGOVERNED",
   "severity": "MEDIUM",
   "governance_boundary": "none",
   "note": "Spawns a full `pytest <target>` subprocess per claim (120s timeout each); O(claims) interpreter+pytest startups for one audit run."
  },
  {
   "id": "PERF-02",
   "file": "platform-gateway/agent_runtime.py",
   "line": 1520,
   "symbol": "record_tool_call and loop bodies",
   "category": "performance",
   "status": "UNGOVERNED",
   "severity": "LOW",
   "governance_boundary": "none",
   "note": "Multiple execute/fetchone calls inside loops in runtime accounting (AST: 6 loop-DB sites around lines 2329/2575/2631); unbounded full-table SELECT rec loops in sibling modules."
  },
  {
   "id": "PERF-03",
   "file": "platform-gateway/fabric.py",
   "line": 533,
   "symbol": "validate / domain_index",
   "category": "performance",
   "status": "UNGOVERNED",
   "severity": "LOW",
   "governance_boundary": "none",
   "note": "Four-deep nested loops in canonical validation/domain indexing."
  },
  {
   "id": "PERF-04",
   "file": "platform-gateway/cain_control_loop.py",
   "line": 861,
   "symbol": "analyze",
   "category": "performance",
   "status": "UNGOVERNED",
   "severity": "LOW",
   "governance_boundary": "none",
   "note": "Three-deep nested loops in the control-loop analyser."
  },
  {
   "id": "PERF-05",
   "file": "cain/mcp_proxy.py",
   "line": 307,
   "symbol": "_evaluate_tool_call_legacy per call",
   "category": "performance",
   "status": "GOVERNED",
   "severity": "LOW",
   "governance_boundary": "MCPGate",
   "note": "Hot path does a function-local import of trajectory_enforcement, json.dumps canonicalization, and (on capability tokens) a synchronous identity_engine DB lookup per call; acceptable for <15ms target but worth caching."
  },
  {
   "id": "PERF-06",
   "file": "platform-gateway/main.py",
   "line": null,
   "symbol": "import-time monolith",
   "category": "performance",
   "status": "UNGOVERNED",
   "severity": "LOW",
   "governance_boundary": "none",
   "note": "322KB / 7138 LOC single module plus a 12004-line cain_runtime_trust.py and 8342-line cain_control_loop.py imported into one process \u2014 large import/startup and memory footprint per worker."
  },
  {
   "id": "PERF-07",
   "file": "platform-gateway/cain_trust_kernel.py",
   "line": 1319,
   "symbol": "CainTrustRuntimeKernel per evaluate_action",
   "category": "performance",
   "status": "GOVERNED",
   "severity": "LOW",
   "governance_boundary": "TRUST_KERNEL",
   "note": "Canonical JSON, Ed25519 verify, Merkle root and trajectory hash chaining per action; inherent, but no batching for high-throughput."
  }
 ],
 "duplicated_functionality": [
  {
   "kind": "mass duplication",
   "paths": [
    "cain/substrate/* (251 tracked .py modules)",
    "platform-gateway/* (446 .py modules)"
   ],
   "detail": "240 of 251 cain/substrate modules are byte-for-byte identical to the platform-gateway module of the same basename; only 11 diverge (__init__.py, agentops.py, cain_mr_client.py, cain_sovereign_api.py, cain_trust_kernel_api.py, cluster_api.py, company.py, fabric.py, main.py, pages.py, seed_48h_changelog.py).",
   "severity": "HIGH",
   "status": "UNGOVERNED",
   "note": "cain/substrate ships in the cain-trust wheel (pyproject [tool.setuptools.package-data] targets 'cain.substrate'), platform-gateway is what runs live. Divergence is therefore a shipped-vs-live drift, not just repo noise."
  },
  {
   "kind": "security-relevant drift",
   "paths": [
    "cain/substrate/main.py",
    "platform-gateway/main.py"
   ],
   "detail": "platform-gateway/main.py:782 adds '/api/v1/control/sovereign' to the anonymous-write block list (commit 92c2c47, 'close anonymous writes on /api/v1/control/sovereign'); cain/substrate/main.py has no such entry. The wheel copy still exposes the pre-fix behaviour.",
   "severity": "HIGH",
   "status": "UNGOVERNED"
  },
  {
   "kind": "security-relevant drift",
   "paths": [
    "cain/substrate/cain_trust_kernel_api.py:505",
    "platform-gateway/cain_trust_kernel_api.py:505"
   ],
   "detail": "platform-gateway copy was fixed to call api.verify(target_type, payload); the substrate copy still calls api.verify(data, signature_b64, public_key_b64) ('crashed on every call').",
   "severity": "MEDIUM",
   "status": "UNGOVERNED"
  },
  {
   "kind": "security-relevant drift",
   "paths": [
    "cain/substrate/cluster_api.py:1410",
    "platform-gateway/cluster_api.py:1410"
   ],
   "detail": "cluster_api verify_action_proof signatures differ; the substrate copy uses the older call shape.",
   "severity": "MEDIUM",
   "status": "UNGOVERNED"
  },
  {
   "kind": "exact duplicate boundary source",
   "paths": [
    "cain/substrate/cain_trust_kernel.py",
    "platform-gateway/cain_trust_kernel.py"
   ],
   "detail": "Byte-identical (2361 lines each), including the comment 'identical field on cain/substrate/cain_trust_kernel.py's copy of this'. Same for fabric_control_plane.py, cain_kernel_enforcement.py, cain_authority_attenuation.py, cain_computer.py, runtime_policies.py and ~234 others.",
   "severity": "MEDIUM",
   "status": "NOT_APPLICABLE"
  },
  {
   "kind": "parallel MCP gatekeeping",
   "paths": [
    "cain/mcp_proxy.py",
    "platform-gateway/mcp_runtime.py"
   ],
   "detail": "Two independent MCP validation stacks: MCPTransparentInterceptor (live boundary) and MCPSecurityRuntime.pre_tool_call/post_tool_call (registry/injection/risk scanner) which is never imported by mcp_proxy.",
   "severity": "MEDIUM",
   "status": "UNGOVERNED"
  },
  {
   "kind": "parallel adversarial engines",
   "paths": [
    "platform-gateway/adversarial_engine.py",
    "platform-gateway/cain_adversarial_suite.py",
    "platform-gateway/cain_adversarial_simulator_v2.py"
   ],
   "detail": "Three adversarial suites with overlapping categories.",
   "severity": "MEDIUM",
   "status": "NOT_APPLICABLE"
  },
  {
   "kind": "universal wrapper copies",
   "paths": [
    "cain/universal_wrapper.py",
    "platform-gateway/cain_universal_wrapper.py"
   ],
   "detail": "Byte-identical.",
   "severity": "LOW",
   "status": "NOT_APPLICABLE"
  },
  {
   "kind": "kernel enforcement copies",
   "paths": [
    "cain/cain_kernel_enforcement.py",
    "platform-gateway/cain_kernel_enforcement.py"
   ],
   "detail": "Duplicate of the governed seccomp enforcer; the cain/ copy is not a callee of any boundary.",
   "severity": "MEDIUM",
   "status": "UNGOVERNED"
  },
  {
   "kind": "cain5 copies",
   "paths": [
    "cain5/",
    "platform-gateway/cain5/"
   ],
   "detail": "9 files, 4 byte-identical, 5 divergent (cli.py, decision_cli.py, journey_audit.py, observatory.py, onboarding.py, trust_api.py, intelligence_gateway.py, hardening.py, setup.py).",
   "severity": "MEDIUM",
   "status": "UNGOVERNED"
  },
  {
   "kind": "build artifact",
   "paths": [
    "build/lib/cain/**",
    "build/lib/cain5/**",
    "build/lib/cain-microservices/**",
    "build/lib/cainloan/**"
   ],
   "detail": "A full vendored copy of the package tree (357+ duplicate .py files) present on disk; not git-tracked but importable if CWD/sys.path resolves build/.",
   "severity": "LOW",
   "status": "NOT_APPLICABLE"
  },
  {
   "kind": "proof-bundle copies",
   "paths": [
    "platform-gateway/frontend/proof/bundle/cain42-convergence-fabric/*",
    "private/unpublished/platform-gateway/**",
    "clawx-site/evidence/**"
   ],
   "detail": "Verifier/evidence scripts copied into published proof bundles; clawx-site/evidence holds 7 identical copies of cain_37_independent_verifier.py. 457 .py files repo-wide have at least one byte-identical twin.",
   "severity": "LOW",
   "status": "NOT_APPLICABLE"
  }
 ],
 "dead_code_candidates": [
  {
   "path": "cain/substrate/ (whole tree)",
   "reason": "Only a handful of runtime imports reference it (cain/kernel.py sys.path, cain/audit.py cain.substrate.trust_graph, cain_cli). The other ~240 modules are unimported duplicates.",
   "severity": "MEDIUM"
  },
  {
   "path": "platform-gateway/bin/*.py (14 CLIs)",
   "reason": "No canonical module or test imports them; none referenced by pyproject [project.scripts] except cain_cli_entry.",
   "severity": "LOW"
  },
  {
   "path": "cain5/* and platform-gateway/cain5/*",
   "reason": "Standalone CLIs/SDKs imported by nothing canonical.",
   "severity": "LOW"
  },
  {
   "path": "SDK/cain10-python-sdk/**/api/**",
   "reason": "Generated client methods imported by nothing.",
   "severity": "LOW"
  },
  {
   "path": "CAIN_*_VERIFICATION_BUNDLE/standalone_verifier_*.py",
   "reason": "One-shot verifiers, no importers.",
   "severity": "LOW"
  },
  {
   "path": "CAIN42_PUBLIC_VERIFIER/verify_cain42.py",
   "reason": "No importers; evidence-artifact verifier.",
   "severity": "LOW"
  },
  {
   "path": "build/lib/**",
   "reason": "Untracked build output (357+ duplicate .py); should not be importable on the path.",
   "severity": "MEDIUM"
  },
  {
   "path": "actionproof/{db,engine,rules}.py, billing-service/{db,pricing}.py, cainaccounts/migrate.py, derivation-copilot/{db,billing,verifier}.py, caingrid/cainroute/cainwitness engines, echoworkforce/engine.py, mcp-security-scanner/engine.py",
   "reason": "No importers found; product scaffolding.",
   "severity": "LOW"
  },
  {
   "path": "platform-gateway/cain_35/cain_37/cain_41_independent_verifier.py",
   "reason": "Independent verifiers with zero importers.",
   "severity": "LOW"
  },
  {
   "path": "platform-gateway/cain_time_travel.py, cain_distributed_adversarial.py, cain_node_main.py, cain_performance_benchmark_tk3.py, trajectory_benchmark.py",
   "reason": "Zero prod importers and zero importing tests.",
   "severity": "LOW"
  }
 ],
 "undocumented_assumptions": [
  {
   "id": "ASSUME-01",
   "where": "cain/guard.py:477",
   "assumption": "CAIN_ALLOW_OFFLINE_LOCAL defaults to 'true': when the remote gateway is unreachable, guard() does NOT deny \u2014 it falls back to the local deterministic baseline.",
   "impact": "Central decision plane is silently bypassed by default on network failure, contradicting the module docstring's 'Strict fail-closed'. The local baseline still enforces quarantine/self-authoring/HIGH/CRITICAL/allowlist, so it is a partial, not total, fail-open.",
   "severity": "HIGH"
  },
  {
   "id": "ASSUME-02",
   "where": "cain/frontier/gate.py:40",
   "assumption": "resolve_mode() default is CAIN_FRONTIER_MODE='shadow', not 'enforce'.",
   "impact": "The frontier gate (capability chain, world model, session, budget) records what WOULD be blocked but does not block unless the env var is set. Invalid values correctly fall back to enforce.",
   "severity": "HIGH"
  },
  {
   "id": "ASSUME-03",
   "where": "cain/mcp_proxy.py:297-298",
   "assumption": "Exceptions from the trajectory-aware authorization gate are swallowed at debug level and the call proceeds.",
   "impact": "An unreachable/erroring trajectory enforcer is treated as 'no constraint', not as deny \u2014 a fail-open inside an enforcement layer (the legacy baseline still runs afterwards).",
   "severity": "HIGH"
  },
  {
   "id": "ASSUME-04",
   "where": "cain/mcp_proxy.py:597",
   "assumption": "A capability token minted without a bound model_id (default 'UNSPECIFIED') passes model-continuity with a stated 'UNVERIFIED' reason.",
   "impact": "Model substitution is only detectable for tokens that opted into model binding.",
   "severity": "MEDIUM"
  },
  {
   "id": "ASSUME-05",
   "where": "cain/mcp_proxy.py:110 / cain45/hypervisor.py",
   "assumption": "MCP identity/plan binding is opt-in (require_identity_binding=False by default); hypervisor _recover_after_restart demotes RUNNING ZoDs.",
   "impact": "Default MCPGate does not require runtime attestation unless enabled.",
   "severity": "MEDIUM"
  },
  {
   "id": "ASSUME-06",
   "where": "cain45/hypervisor.py:95",
   "assumption": "trust_fn defaults to lambda agent_id: 1.0 (maximum trust) when the caller supplies none.",
   "impact": "A hypervisor constructed without a trust function grants the full trust floor; trust is then not evidence-derived for that deployment.",
   "severity": "MEDIUM"
  },
  {
   "id": "ASSUME-07",
   "where": "cain45/hypervisor.py:377,407",
   "assumption": "'allowlisted egress is not enforced in Evolution 1; only deny-all is'; attestation 'hardware_backed is always False: no TPM/TEE exists here'.",
   "impact": "Documented in code but not surfaced in the public claims matrix; egress allow-listing and hardware attestation are absent.",
   "severity": "MEDIUM"
  },
  {
   "id": "ASSUME-08",
   "where": "cain/substrate/cain_adversarial_worker.py:256",
   "assumption": "Control is 'advisory, not enforced'.",
   "impact": "An adversarial-worker control that does not actually block.",
   "severity": "MEDIUM"
  },
  {
   "id": "ASSUME-09",
   "where": "cain/substrate/containment.py:212",
   "assumption": "Containment actions are 'reported, not enforced, until thresholds are calibrated on real traffic'.",
   "impact": "Moat-7 automated containment may report without acting.",
   "severity": "MEDIUM"
  },
  {
   "id": "ASSUME-10",
   "where": "platform-gateway/cain_cluster_security_properties.py:137",
   "assumption": "git_commit is a known placeholder ('cain-dist-moats-v2') in the cluster identity, so the software-attestation property is self-reported VIOLATED.",
   "impact": "Cluster image provenance is a placeholder; the code honestly flags it.",
   "severity": "MEDIUM"
  },
  {
   "id": "ASSUME-11",
   "where": "cain/mcp_proxy.py:774",
   "assumption": "Postcondition default is UNVERIFIED unless a checker is registered for the tool.",
   "impact": "Honest, but means effect verification is opt-in per tool; most deployments will report UNVERIFIED.",
   "severity": "LOW"
  },
  {
   "id": "ASSUME-12",
   "where": "AGENTS.md (repo root & platform-gateway)",
   "assumption": "200 formal invariants and 120 adversarial vectors are claimed 200/200 and 120/120; the file itself states these were NOT re-verified in the 2026-09-27 audit.",
   "impact": "Public assurance numbers exceed the current verified evidence.",
   "severity": "MEDIUM"
  },
  {
   "id": "ASSUME-13",
   "where": "cain/substrate/cain_distributed_trust.py:196",
   "assumption": "Merged trust 'cannot exceed 2 * the average' ('simple cap for now').",
   "impact": "Ad-hoc cap in federated trust merge.",
   "severity": "LOW"
  },
  {
   "id": "ASSUME-14",
   "where": "platform-gateway/cain_runtime_trust.py:6592",
   "assumption": "AWS KMS path imports boto3 at call time and raises if absent; no local-enclave fallback assertion in the trust path.",
   "impact": "Trust-root key custody depends on an optional dependency.",
   "severity": "LOW"
  },
  {
   "id": "ASSUME-15",
   "where": "CAIN45_BYPASS_AUDIT.json (repo root)",
   "assumption": "RAW: an agent that calls its undecorated tool or opens its own socket always executes.",
   "impact": "The SDK surfaces (guard/wrap/adapters/MCPGate) are opt-in libraries; only the CAIN-45 confined ZoD is non-bypassable. Recorded as GAP by the project's own audit.",
   "severity": "CRITICAL"
  }
 ],
 "security_gaps": [
  {
   "id": "GAP-01",
   "title": "Raw execution bypass (in-process surfaces are opt-in)",
   "severity": "CRITICAL",
   "evidence": "CAIN45_BYPASS_AUDIT.json: raw-process RAW tool_ran=true, GAP; conclusion: 'An agent that calls its tool directly, or opens its own socket, is not stopped by anything in CAIN-42.'",
   "where": "all SDK surfaces: cain/guard.py, cain/wrap.py, cain/adapters/*, cain/mcp_proxy.py"
  },
  {
   "id": "GAP-02",
   "title": "Shipped wheel copy of main.py lacks the anonymous-write fix on /api/v1/control/sovereign",
   "severity": "HIGH",
   "evidence": "cain/substrate/main.py vs platform-gateway/main.py:782 (commit 92c2c47).",
   "where": "cain/substrate/main.py"
  },
  {
   "id": "GAP-03",
   "title": "Hard-coded fallback passphrase for the KMS signing key at rest",
   "severity": "HIGH",
   "evidence": "platform-gateway/cain_kms.py:84.",
   "where": "platform-gateway/cain_kms.py"
  },
  {
   "id": "GAP-04",
   "title": "Offline fallback is allowed by default (CAIN_ALLOW_OFFLINE_LOCAL=true)",
   "severity": "HIGH",
   "evidence": "cain/guard.py:477.",
   "where": "cain/guard.py"
  },
  {
   "id": "GAP-05",
   "title": "Frontier gate defaults to shadow (non-blocking)",
   "severity": "HIGH",
   "evidence": "cain/frontier/gate.py:40 (default 'shadow').",
   "where": "cain/frontier/gate.py"
  },
  {
   "id": "GAP-06",
   "title": "Trajectory gate exceptions fail open",
   "severity": "HIGH",
   "evidence": "cain/mcp_proxy.py:297-298.",
   "where": "cain/mcp_proxy.py"
  },
  {
   "id": "GAP-07",
   "title": "Self-signed A2A delegation passports accepted",
   "severity": "HIGH",
   "evidence": "cain/universal_wrapper.py:455-465,499 (verify with same fabric key).",
   "where": "cain/universal_wrapper.py, cain/substrate/cain_universal_wrapper.py"
  },
  {
   "id": "GAP-08",
   "title": "Shell and infra mutation shipped as ungoverned microservices",
   "severity": "HIGH",
   "evidence": "talos-coder/daemon/tools/run_command.py:48; cain-microservices/swarm-orchestrator, orchestrator, resilience-controller; platform-gateway/resilience_controller.py; platform-gateway/cain_lab_public.py.",
   "where": "listed files"
  },
  {
   "id": "GAP-09",
   "title": "Parallel MCP validation stack not wired to the live interceptor",
   "severity": "MEDIUM",
   "evidence": "platform-gateway/mcp_runtime.py not imported by cain/mcp_proxy.py.",
   "where": "platform-gateway/mcp_runtime.py"
  },
  {
   "id": "GAP-10",
   "title": "eval() on policy expressions in the control loop",
   "severity": "MEDIUM",
   "evidence": "platform-gateway/cain_control_loop.py:2092.",
   "where": "platform-gateway/cain_control_loop.py (and substrate duplicate)"
  },
  {
   "id": "GAP-11",
   "title": "Public assurance counts (200 invariants / 120 vectors) exceed re-verified evidence",
   "severity": "MEDIUM",
   "evidence": "AGENTS.md self-note; CAIN42_L5_BASELINE / truth registry.",
   "where": "AGENTS.md, CAIN42_PUBLIC_CLAIMS_MATRIX.json"
  },
  {
   "id": "GAP-12",
   "title": "Sovereign node keys default to /tmp",
   "severity": "MEDIUM",
   "evidence": "cain/sovereign.py:122.",
   "where": "cain/sovereign.py"
  },
  {
   "id": "GAP-13",
   "title": "Duplicated source is a standing drift risk (2 divergences already introduce regressions)",
   "severity": "HIGH",
   "evidence": "240/251 identical, 11 divergent, 2 security-relevant.",
   "where": "cain/substrate/ vs platform-gateway/"
  },
  {
   "id": "GAP-14",
   "title": "Build artifact tree importable as a second copy of the package",
   "severity": "LOW",
   "evidence": "build/lib/cain/** (357+ duplicate files).",
   "where": "build/"
  }
 ],
 "missing_tests": [
  {
   "path": "platform-gateway/main.py",
   "detail": "7138-line monolith, no importing test (exercised only via HTTP/subprocess by e2e suites); true unit coverage of most routes is therefore indirect.",
   "severity": "HIGH"
  },
  {
   "path": "platform-gateway/cain_sentinel.py",
   "detail": "Moat #7 sentinel; 6 production importers, zero importing tests found.",
   "severity": "HIGH"
  },
  {
   "path": "platform-gateway/proof.py / proof_api.py",
   "detail": "Proof surfaces; no direct importing tests.",
   "severity": "MEDIUM"
  },
  {
   "path": "platform-gateway/events.py",
   "detail": "12 production importers, no importing test.",
   "severity": "MEDIUM"
  },
  {
   "path": "cain45/l5/{authority,boundary,caller_auth,certificate,intent,invariants,autonomy}.py",
   "detail": "L5 governance layer; no importing tests.",
   "severity": "MEDIUM"
  },
  {
   "path": "platform-gateway/cain_trust_state_machine.py",
   "detail": "4 importers, no test.",
   "severity": "MEDIUM"
  },
  {
   "path": "platform-gateway/cain_memory_api.py / cain_planner_api.py / cain_control_loop_api.py / agent_security_api.py / identity_api.py / trajectory_api.py / trust_graph_api.py / mcp_enforcement_api.py",
   "detail": "API routers with no direct importing tests.",
   "severity": "MEDIUM"
  },
  {
   "path": "cain/substrate/* (all modules)",
   "detail": "Zero importing tests; their platform-gateway twins are tested, but the shipped copies are not directly covered (and have already diverged).",
   "severity": "MEDIUM"
  },
  {
   "path": "stats",
   "detail": "Import-graph method: of 1061 canonical production modules, 477 have zero importing tests; 200 canonical modules are imported by nothing at all.",
   "severity": "MEDIUM"
  }
 ],
 "performance_bottlenecks": [
  {
   "id": "PERF-01",
   "where": "platform-gateway/cain_claim_auditor_[19/20/22].py:163/176/96",
   "detail": "Full pytest subprocess per claim (120s timeout each).",
   "severity": "MEDIUM"
  },
  {
   "id": "PERF-02",
   "where": "platform-gateway/agent_runtime.py:1520,2329,2575,2631",
   "detail": "DB execute/fetchone inside loops; runtime accounting hot path.",
   "severity": "LOW"
  },
  {
   "id": "PERF-03",
   "where": "platform-gateway/fabric.py:533 (validate), :407 (domain_index)",
   "detail": "4- and 3-deep nested loops over canonical fabric; also in substrate twin.",
   "severity": "LOW"
  },
  {
   "id": "PERF-04",
   "where": "platform-gateway/cain_control_loop.py:861 (analyze)",
   "detail": "3-deep nested loop analyser.",
   "severity": "LOW"
  },
  {
   "id": "PERF-05",
   "where": "cain/mcp_proxy.py:307 (per call)",
   "detail": "function-local imports + JSON canonicalization + synchronous identity DB lookup on the hot path.",
   "severity": "LOW"
  },
  {
   "id": "PERF-06",
   "where": "platform-gateway/main.py (7138 LOC), cain_runtime_trust.py (12004), cain_control_loop.py (8342)",
   "detail": "Import-time cost / memory per worker of very large modules in one process.",
   "severity": "LOW"
  },
  {
   "id": "PERF-07",
   "where": "cain/mcp_proxy.py:410,443",
   "detail": "json.dumps(sort_keys) for the context digest on every call instead of a pre-serialized canonical form.",
   "severity": "LOW"
  }
 ],
 "top15_prioritized_gaps": [
  {
   "rank": 1,
   "severity": "CRITICAL",
   "gap": "Raw execution bypass: agent code that does not call the SDK/MCPGate is not governed at all.",
   "fix": "Make confinement non-optional: run agents only inside CAIN-45 ZoDs (bwrap+cgroup, broker-only egress) rather than relying on opt-in decorators.",
   "evidence": "CAIN45_BYPASS_AUDIT.json GAP/RAW"
  },
  {
   "rank": 2,
   "severity": "HIGH",
   "gap": "Shipped wheel main.py is missing the /api/v1/control/sovereign anonymous-write fix (security drift in cain/substrate).",
   "fix": "Delete cain/substrate and build the wheel from the live tree, or make the parity test fail the build (tests/test_substrate_gateway_parity.py already exists).",
   "evidence": "cain/substrate/main.py vs platform-gateway/main.py:782"
  },
  {
   "rank": 3,
   "severity": "HIGH",
   "gap": "Hard-coded fallback passphrase protects the KMS signing key at rest when CAIN_KMS_MASTER_KEY / CAIN_JWT_SECRET are unset.",
   "fix": "Generate a random per-host passphrase sealed with the OS root of trust, or refuse to start when no master key is supplied.",
   "evidence": "platform-gateway/cain_kms.py:84"
  },
  {
   "rank": 4,
   "severity": "HIGH",
   "gap": "guard() defaults to offline-local fallback when the gateway is unreachable (CAIN_ALLOW_OFFLINE_LOCAL=true).",
   "fix": "Default CAIN_ALLOW_OFFLINE_LOCAL=false; make the local baseline an explicit operator opt-in with a signed config.",
   "evidence": "cain/guard.py:477"
  },
  {
   "rank": 5,
   "severity": "HIGH",
   "gap": "Frontier gate default mode is 'shadow' \u2014 capability chain, world model, session and budget do not block.",
   "fix": "Default CAIN_FRONTIER_MODE=enforce in production, or refuse production startup when it is shadow.",
   "evidence": "cain/frontier/gate.py:40"
  },
  {
   "rank": 6,
   "severity": "HIGH",
   "gap": "Trajectory authorization gate swallows exceptions (fail-open).",
   "fix": "Treat enforcer errors as DENY when a trajectory is expected (mirror the fabric-gate fail-closed pattern).",
   "evidence": "cain/mcp_proxy.py:297-298"
  },
  {
   "rank": 7,
   "severity": "HIGH",
   "gap": "A2A delegation passports verified against the presenter's own key.",
   "fix": "Verify the passport against the registered root/parent principal key, not the embedded/same-fabric key.",
   "evidence": "cain/universal_wrapper.py:455-465,499"
  },
  {
   "rank": 8,
   "severity": "HIGH",
   "gap": "Ungoverned shell / infra-mutation microservices (talos-coder, swarm-orchestrator k8s, orchestrator/resilience docker, lab docker stop/start, k8s controller).",
   "fix": "Route every infrastructure mutation through a ZoD/grant; or isolate these services behind MCPGate with default-deny.",
   "evidence": "talos-coder/daemon/tools/run_command.py:48; cain-microservices/*; platform-gateway/cain_lab_public.py:81; platform-gateway/resilience_controller.py:3"
  },
  {
   "rank": 9,
   "severity": "HIGH",
   "gap": "Duplicate source (240/251 identical, 11 divergent) is a standing drift risk; two divergences are already regressions.",
   "fix": "Single source of truth: generate cain/substrate from platform-gateway at build time, and gate on tests/test_substrate_gateway_parity.py.",
   "evidence": "cain/substrate vs platform-gateway"
  },
  {
   "rank": 10,
   "severity": "MEDIUM",
   "gap": "Two parallel MCP gatekeeping stacks; mcp_runtime.py is not wired to the live interceptor.",
   "fix": "Route mcp_runtime validation through MCPTransparentInterceptor (or remove it) so there is one gate.",
   "evidence": "platform-gateway/mcp_runtime.py"
  },
  {
   "rank": 11,
   "severity": "MEDIUM",
   "gap": "eval() on policy expressions in cain_control_loop.py (and substrate copy).",
   "fix": "Use the AST-based SafeExpressionEvaluator without eval(compile(...)) or replace with a declarative policy DSL.",
   "evidence": "platform-gateway/cain_control_loop.py:2092"
  },
  {
   "rank": 12,
   "severity": "MEDIUM",
   "gap": "Public assurance counts (200 invariants / 120 vectors) exceed re-verified evidence.",
   "fix": "Re-run and publish per-invariant results, or downgrade the public numbers to what the truth registry evidences.",
   "evidence": "AGENTS.md; CAIN42_PUBLIC_CLAIMS_MATRIX.json"
  },
  {
   "rank": 13,
   "severity": "MEDIUM",
   "gap": "Moat #7 sentinel and the L5 governance layer (+ main.py) have no importing tests.",
   "fix": "Add direct unit/import tests for cain_sentinel, cain45/l5/*, and the main.py route table.",
   "evidence": "import-graph analysis; 477 modules with zero importing tests"
  },
  {
   "rank": 14,
   "severity": "MEDIUM",
   "gap": "Sovereign node keys default to /tmp/cain-sovereign-keys.",
   "fix": "Default to a root-owned 0700 directory with an explicit config; fail if the path is world-writable.",
   "evidence": "cain/sovereign.py:122"
  },
  {
   "rank": 15,
   "severity": "MEDIUM",
   "gap": "Build artifact tree (build/lib/**) importable as a second copy of the package.",
   "fix": "Remove build/ from the repo/working tree and ensure it is never on sys.path/importable.",
   "evidence": "build/lib/cain/**"
  }
 ]
}