{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.driftframe.org/site-reading-governance/v2.0/common.schema.json",
  "title": "Site Reading Common Definitions",
  "$defs": {
    "identifier": {
      "type": "string",
      "pattern": "^[A-Z][A-Z0-9]*(?:-[A-Z0-9]+)*$",
      "minLength": 3,
      "maxLength": 96
    },
    "slug": {
      "type": "string",
      "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$",
      "minLength": 2,
      "maxLength": 96
    },
    "semver": {
      "type": "string",
      "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?$"
    },
    "digest": {
      "type": "string",
      "pattern": "^sha256:[a-f0-9]{64}$"
    },
    "commit": {
      "type": "string",
      "pattern": "^[a-f0-9]{40}$"
    },
    "evidenceMode": {
      "type": "string",
      "enum": [
        "planned",
        "simulated",
        "observed"
      ]
    },
    "assuranceStage": {
      "type": "string",
      "enum": [
        "specified",
        "verified",
        "qualified",
        "validated",
        "accepted"
      ]
    },
    "actor": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "actor_id",
        "display_name",
        "role"
      ],
      "properties": {
        "actor_id": {
          "$ref": "#/$defs/identifier"
        },
        "display_name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160
        },
        "role": {
          "type": "string",
          "minLength": 2,
          "maxLength": 120
        },
        "organization": {
          "type": "string",
          "minLength": 2,
          "maxLength": 160
        }
      }
    },
    "governedLocator": {
      "type": "string",
      "pattern": "^(?:governed|evidence)://[a-z0-9][a-z0-9._/-]*$",
      "minLength": 12,
      "maxLength": 500
    },
    "artifact": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "artifact_id",
        "media_type",
        "digest",
        "locator",
        "sensitivity"
      ],
      "properties": {
        "artifact_id": {
          "$ref": "#/$defs/identifier"
        },
        "media_type": {
          "type": "string",
          "minLength": 3,
          "maxLength": 120
        },
        "digest": {
          "$ref": "#/$defs/digest"
        },
        "locator": {
          "$ref": "#/$defs/governedLocator"
        },
        "sensitivity": {
          "type": "string",
          "enum": [
            "public",
            "internal",
            "confidential",
            "regulated"
          ]
        },
        "retention_class": {
          "type": "string",
          "minLength": 2,
          "maxLength": 96
        }
      }
    },
    "versionedCoordinate": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "release",
        "commit",
        "digest"
      ],
      "properties": {
        "release": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "commit": {
          "$ref": "#/$defs/commit"
        },
        "digest": {
          "$ref": "#/$defs/digest"
        }
      }
    },
    "contractReference": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "contract_id",
        "version",
        "digest"
      ],
      "properties": {
        "contract_id": {
          "$ref": "#/$defs/identifier"
        },
        "version": {
          "$ref": "#/$defs/semver"
        },
        "digest": {
          "$ref": "#/$defs/digest"
        }
      }
    },
    "effectClass": {
      "type": "string",
      "enum": [
        "read",
        "narrow_write",
        "broad_write",
        "irreversible_effect"
      ]
    },
    "evidencePosture": {
      "type": "string",
      "enum": [
        "planned",
        "simulated",
        "observed"
      ]
    },
    "boundedScope": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "tenant_ids",
        "resource_types",
        "record_limit",
        "data_classes",
        "environment_classes"
      ],
      "properties": {
        "tenant_ids": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/identifier"
          }
        },
        "resource_types": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 2,
            "maxLength": 120
          }
        },
        "record_limit": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100000
        },
        "data_classes": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "enum": [
              "synthetic",
              "public",
              "internal",
              "confidential",
              "regulated"
            ]
          }
        },
        "environment_classes": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "enum": [
              "local",
              "continuous_integration",
              "vendor_sandbox",
              "qualification",
              "staging",
              "production"
            ]
          }
        }
      }
    },
    "resourceBudget": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "requests_per_minute",
        "timeout_seconds",
        "retry_attempts",
        "max_payload_bytes"
      ],
      "properties": {
        "requests_per_minute": {
          "type": "integer",
          "minimum": 1,
          "maximum": 10000
        },
        "timeout_seconds": {
          "type": "integer",
          "minimum": 1,
          "maximum": 3600
        },
        "retry_attempts": {
          "type": "integer",
          "minimum": 0,
          "maximum": 20
        },
        "max_payload_bytes": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1073741824
        }
      }
    },
    "executableCheck": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "check_id",
        "command",
        "working_directory",
        "expected_exit_code",
        "artifact_ids"
      ],
      "properties": {
        "check_id": {
          "$ref": "#/$defs/identifier"
        },
        "command": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 300
          }
        },
        "working_directory": {
          "type": "string",
          "pattern": "^(?:[A-Za-z0-9][A-Za-z0-9._-]*/)*[A-Za-z0-9][A-Za-z0-9._-]*$",
          "maxLength": 300
        },
        "expected_exit_code": {
          "type": "integer",
          "minimum": 0,
          "maximum": 255
        },
        "artifact_ids": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/identifier"
          }
        }
      }
    },
    "recoveryRoute": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "owner_role",
        "containment",
        "replacement_behavior",
        "verification"
      ],
      "properties": {
        "owner_role": {
          "type": "string",
          "minLength": 2,
          "maxLength": 120
        },
        "containment": {
          "type": "string",
          "minLength": 10,
          "maxLength": 700
        },
        "replacement_behavior": {
          "type": "string",
          "minLength": 10,
          "maxLength": 700
        },
        "verification": {
          "type": "string",
          "minLength": 10,
          "maxLength": 700
        }
      }
    },
    "environment": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "environment_id",
        "class",
        "region",
        "configuration_digest"
      ],
      "properties": {
        "environment_id": {
          "$ref": "#/$defs/identifier"
        },
        "class": {
          "type": "string",
          "enum": [
            "local",
            "continuous_integration",
            "vendor_sandbox",
            "qualification",
            "staging",
            "production"
          ]
        },
        "region": {
          "type": "string",
          "minLength": 2,
          "maxLength": 80
        },
        "configuration_digest": {
          "$ref": "#/$defs/digest"
        },
        "vendor_build": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "schema_version": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        }
      }
    },
    "metric": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "metric_id",
        "unit",
        "numerator",
        "denominator",
        "comparison",
        "threshold",
        "observed",
        "window"
      ],
      "properties": {
        "metric_id": {
          "$ref": "#/$defs/identifier"
        },
        "unit": {
          "type": "string",
          "minLength": 1,
          "maxLength": 40
        },
        "numerator": {
          "type": "number"
        },
        "denominator": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "comparison": {
          "type": "string",
          "enum": [
            "at_least",
            "at_most",
            "exactly"
          ]
        },
        "threshold": {
          "type": "number"
        },
        "observed": {
          "type": "number"
        },
        "window": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        }
      }
    },
    "boundary": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "boundary_id",
        "boundary_type",
        "protected_state",
        "explicit_constraint",
        "replacement_behavior",
        "verification"
      ],
      "properties": {
        "boundary_id": {
          "$ref": "#/$defs/identifier"
        },
        "boundary_type": {
          "type": "string",
          "enum": [
            "safety",
            "privacy",
            "regulatory"
          ]
        },
        "protected_state": {
          "type": "string",
          "minLength": 10,
          "maxLength": 500
        },
        "explicit_constraint": {
          "type": "string",
          "minLength": 10,
          "maxLength": 500
        },
        "replacement_behavior": {
          "type": "string",
          "minLength": 10,
          "maxLength": 500
        },
        "verification": {
          "type": "string",
          "minLength": 10,
          "maxLength": 500
        }
      }
    },
    "recordMetadata": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "schema_version",
        "created_at",
        "updated_at",
        "owner"
      ],
      "properties": {
        "schema_version": {
          "$ref": "#/$defs/semver"
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        },
        "updated_at": {
          "type": "string",
          "format": "date-time"
        },
        "owner": {
          "$ref": "#/$defs/actor"
        }
      }
    }
  }
}
