{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://agla.invalid/schemas/machina-thin-envelope.v1.schema.json",
  "title": "AGLA MACHINA Thin Non-Execution Envelope",
  "version": "1.0.0",
  "status": "CANDIDATE_NON_RUNTIME_NO_AUTHORITY_EFFECT",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "envelope_id",
    "envelope_version",
    "artifact_kind",
    "authority",
    "provenance",
    "profile_refs",
    "bridge_refs",
    "status_surfaces",
    "assembly_refs",
    "validation_refs",
    "unresolved_refs",
    "lifecycle"
  ],
  "properties": {
    "$schema": { "type": "string" },
    "envelope_id": { "type": "string", "minLength": 1 },
    "envelope_version": { "type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$" },
    "artifact_kind": { "const": "MACHINA_REPRESENTATION_ENVELOPE" },
    "authority": { "$ref": "#/$defs/authority" },
    "provenance": { "$ref": "#/$defs/provenance" },
    "profile_refs": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": { "$ref": "#/$defs/versioned_ref" }
    },
    "bridge_refs": {
      "type": "array",
      "uniqueItems": true,
      "items": { "$ref": "#/$defs/versioned_ref" }
    },
    "status_surfaces": { "$ref": "#/$defs/status_surfaces" },
    "assembly_refs": {
      "type": "array",
      "items": { "$ref": "#/$defs/assembly_ref" }
    },
    "validation_refs": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/evidence_ref" }
    },
    "unresolved_refs": {
      "type": "array",
      "items": { "$ref": "#/$defs/evidence_ref" }
    },
    "lifecycle": { "$ref": "#/$defs/lifecycle" }
  },
  "$defs": {
    "versioned_ref": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "version", "path"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "version": { "type": "string", "minLength": 1 },
        "path": { "type": "string", "minLength": 1 },
        "sha256": { "type": ["string", "null"], "pattern": "^[A-F0-9]{64}$" }
      }
    },
    "evidence_ref": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "path", "status"],
      "properties": {
        "id": { "type": "string" },
        "path": { "type": "string" },
        "status": { "enum": ["PRESENT", "ABSENT", "UNRESOLVED", "NOT_APPLICABLE"] }
      }
    },
    "authority": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "canonical_effect",
        "runtime_authority",
        "execution_authority",
        "machina_role",
        "execution_owners",
        "sigma_classification"
      ],
      "properties": {
        "canonical_effect": { "const": "NONE" },
        "runtime_authority": { "const": false },
        "execution_authority": { "const": false },
        "machina_role": { "const": "REPRESENTATION_CAPABILITY_NOT_EXECUTION_OWNER" },
        "execution_owners": {
          "type": "array",
          "minItems": 5,
          "maxItems": 5,
          "uniqueItems": true,
          "prefixItems": [
            { "const": "TENET" },
            { "const": "ROTAS" },
            { "const": "AREPO" },
            { "const": "OPERA" },
            { "const": "SATOR" }
          ],
          "items": false
        },
        "sigma_classification": { "const": "CONTROL_DOSSIER_PENTAGRAMA_NOT_KERNEL" }
      }
    },
    "provenance": {
      "type": "object",
      "additionalProperties": false,
      "required": ["source_artifact_refs", "source_commit", "derivation_kind"],
      "properties": {
        "source_artifact_refs": { "type": "array", "minItems": 1, "items": { "type": "string" } },
        "source_commit": { "type": "string", "pattern": "^[a-f0-9]{40}$" },
        "derivation_kind": { "const": "REFERENTIAL_NON_EXECUTING_REPRESENTATION" }
      }
    },
    "surface": {
      "type": "object",
      "additionalProperties": false,
      "required": ["status", "evidence_refs", "implies_next_surface"],
      "properties": {
        "status": {
          "enum": ["NOT_TESTED", "PASS", "FAIL", "UNRESOLVED", "NOT_REQUESTED", "NOT_APPLICABLE"]
        },
        "evidence_refs": { "type": "array", "items": { "type": "string" } },
        "implies_next_surface": { "const": false }
      }
    },
    "status_surfaces": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "schema_profile_validity",
        "semantic_validity",
        "provider_resolution",
        "arepo_admission",
        "opera_execution",
        "sator_output"
      ],
      "properties": {
        "schema_profile_validity": { "$ref": "#/$defs/surface" },
        "semantic_validity": { "$ref": "#/$defs/surface" },
        "provider_resolution": { "$ref": "#/$defs/surface" },
        "arepo_admission": { "$ref": "#/$defs/surface" },
        "opera_execution": { "$ref": "#/$defs/surface" },
        "sator_output": { "$ref": "#/$defs/surface" }
      }
    },
    "assembly_ref": {
      "type": "object",
      "additionalProperties": false,
      "required": ["assembly_id", "provider_refs", "closure_status"],
      "properties": {
        "assembly_id": { "type": "string" },
        "provider_refs": { "type": "array", "items": { "type": "string" } },
        "closure_status": { "enum": ["UNRESOLVED", "PARTIAL", "RESOLVED_BY_EXTERNAL_REGISTRY"] }
      }
    },
    "lifecycle": {
      "type": "object",
      "additionalProperties": false,
      "required": ["state", "canonicality", "registration", "execution"],
      "properties": {
        "state": { "enum": ["CANDIDATE", "DEPRECATED", "ARCHIVED"] },
        "canonicality": { "const": "NON_CANONICAL" },
        "registration": { "const": "NOT_REGISTERED" },
        "execution": { "const": "NON_RUNTIME" }
      }
    }
  }
}
