{
  "$defs": {
    "caller_classification": {
      "enum": ["eligible", "exact_required", "protected", "unknown", "ambiguous", "security_sensitive", "refuse"],
      "type": "string"
    },
    "detector_signals": {
      "items": {"enum": ["exact_required", "protected", "unknown", "ambiguous", "security_sensitive", "secret"], "type": "string"},
      "maxItems": 64,
      "type": "array",
      "uniqueItems": true
    },
    "legacy_descriptor": {
      "additionalProperties": false,
      "properties": {
        "caller_classification": {"$ref": "#/$defs/caller_classification"},
        "detector_signals": {"$ref": "#/$defs/detector_signals"},
        "payload_b64u": {"maxLength": 1200000, "pattern": "^[A-Za-z0-9_-]*$", "type": "string"},
        "schema_version": {"const": "contextguard-receipt-evidence-descriptor/v1"},
        "source": {"$ref": "#/$defs/source"}
      },
      "required": ["caller_classification", "detector_signals", "payload_b64u", "schema_version", "source"],
      "type": "object"
    },
    "pack_descriptor": {
      "additionalProperties": false,
      "properties": {
        "payload_b64u": {"maxLength": 1200000, "pattern": "^[A-Za-z0-9_-]+$", "type": "string"},
        "ranges": {
          "items": {"$ref": "#/$defs/pack_range"},
          "maxItems": 64,
          "minItems": 1,
          "type": "array"
        },
        "schema_version": {"const": "contextguard-receipt-evidence-pack-descriptor/v1"}
      },
      "required": ["payload_b64u", "ranges", "schema_version"],
      "type": "object"
    },
    "pack_range": {
      "additionalProperties": false,
      "properties": {
        "caller_classification": {"$ref": "#/$defs/caller_classification"},
        "detector_signals": {"$ref": "#/$defs/detector_signals"},
        "end_byte": {"maximum": 900000, "minimum": 1, "type": "integer"},
        "mode": {"enum": ["retained", "deferred"], "type": "string"},
        "source": {"$ref": "#/$defs/source"},
        "start_byte": {"maximum": 899999, "minimum": 0, "type": "integer"}
      },
      "required": ["caller_classification", "detector_signals", "end_byte", "mode", "source", "start_byte"],
      "type": "object"
    },
    "selection": {
      "oneOf": [
        {
          "additionalProperties": false,
          "properties": {"kind": {"const": "file"}},
          "required": ["kind"],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "properties": {
            "end_byte": {"minimum": 0, "type": "integer"},
            "kind": {"const": "range"},
            "start_byte": {"minimum": 0, "type": "integer"}
          },
          "required": ["end_byte", "kind", "start_byte"],
          "type": "object"
        },
        {
          "additionalProperties": false,
          "properties": {
            "evidence": {"$ref": "#/$defs/symbol_evidence"},
            "kind": {"const": "symbol"}
          },
          "required": ["evidence", "kind"],
          "type": "object"
        }
      ]
    },
    "source": {
      "additionalProperties": false,
      "properties": {
        "relative_path": {"maxLength": 4096, "minLength": 1, "type": "string"},
        "selection": {"$ref": "#/$defs/selection"}
      },
      "required": ["relative_path", "selection"],
      "type": "object"
    },
    "symbol_candidate": {
      "additionalProperties": false,
      "properties": {
        "end_byte": {"minimum": 0, "type": "integer"},
        "occurrence": {"minimum": 0, "type": "integer"},
        "qualified_name": {"maxLength": 1024, "minLength": 1, "type": "string"},
        "raw_range_sha256": {"pattern": "^[0-9a-f]{64}$", "type": "string"},
        "start_byte": {"minimum": 0, "type": "integer"}
      },
      "required": ["end_byte", "occurrence", "qualified_name", "raw_range_sha256", "start_byte"],
      "type": "object"
    },
    "symbol_evidence": {
      "additionalProperties": false,
      "properties": {
        "candidates": {"items": {"$ref": "#/$defs/symbol_candidate"}, "maxItems": 16, "type": "array"},
        "capped": {"const": false},
        "complete": {"const": true},
        "deterministic": {"const": true},
        "end_byte": {"minimum": 0, "type": "integer"},
        "evidence_kind": {"const": "caller_supplied_symbol_range"},
        "fallback_used": {"const": false},
        "language_id": {"maxLength": 64, "minLength": 1, "type": "string"},
        "occurrence": {"minimum": 0, "type": "integer"},
        "parser_error": {"const": false},
        "producer_id": {"maxLength": 128, "minLength": 1, "type": "string"},
        "qualified_name": {"maxLength": 1024, "minLength": 1, "type": "string"},
        "raw_range_sha256": {"pattern": "^[0-9a-f]{64}$", "type": "string"},
        "scan_complete": {"const": true},
        "schema_version": {"const": "contextguard-receipt-caller-symbol-evidence/v1"},
        "source_sha256": {"pattern": "^[0-9a-f]{64}$", "type": "string"},
        "start_byte": {"minimum": 0, "type": "integer"}
      },
      "required": ["candidates", "capped", "complete", "deterministic", "end_byte", "evidence_kind", "fallback_used", "language_id", "occurrence", "parser_error", "producer_id", "qualified_name", "raw_range_sha256", "scan_complete", "schema_version", "source_sha256", "start_byte"],
      "type": "object"
    }
  },
  "$id": "https://context-guard.local/schemas/evidence-descriptor-v1.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "oneOf": [
    {"$ref": "#/$defs/legacy_descriptor"},
    {"$ref": "#/$defs/pack_descriptor"}
  ],
  "title": "Context Guard Receipt evidence assembly descriptors",
  "type": "object",
  "unevaluatedProperties": false
}
