{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://matrixnetwork.me/source/audit/source-semantic-review-resolution.schema.json",
  "title": "Y-Theory source semantic review resolution registry",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema",
    "version",
    "status",
    "authority_boundary",
    "state_model",
    "source_binding",
    "counts",
    "records"
  ],
  "properties": {
    "schema": { "const": "y-theory.source-semantic-review-resolution-registry.v1" },
    "version": { "type": "string", "pattern": "^SSRRES-[0-9]{4}\\.[0-9]{2}\\.[0-9]{2}\\.[0-9]+$" },
    "status": { "const": "governed_resolution_overlay_no_canonical_mutation" },
    "authority_boundary": { "type": "string", "minLength": 80 },
    "state_model": {
      "type": "object",
      "additionalProperties": false,
      "required": ["review_task_state", "epistemic_state", "closure_rule"],
      "properties": {
        "review_task_state": { "type": "string", "minLength": 40 },
        "epistemic_state": { "type": "string", "minLength": 40 },
        "closure_rule": { "type": "string", "minLength": 60 }
      }
    },
    "source_binding": {
      "type": "object",
      "additionalProperties": false,
      "required": ["path", "sha256", "version"],
      "properties": {
        "path": { "const": "atlas/SOURCE_SEMANTIC_REVIEW_REGISTRY.json" },
        "sha256": { "$ref": "#/$defs/sha256" },
        "version": { "type": "string", "minLength": 4 }
      }
    },
    "counts": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "obligations",
        "objective_current_state_audits",
        "author_decisions",
        "formal_or_empirical_research",
        "evidence_dispositioned",
        "pending_author_decision",
        "routed_to_open_research",
        "epistemically_open",
        "theory_status_upgrades"
      ],
      "properties": {
        "obligations": { "type": "integer", "minimum": 0 },
        "objective_current_state_audits": { "type": "integer", "minimum": 0 },
        "author_decisions": { "type": "integer", "minimum": 0 },
        "formal_or_empirical_research": { "type": "integer", "minimum": 0 },
        "evidence_dispositioned": { "type": "integer", "minimum": 0 },
        "pending_author_decision": { "type": "integer", "minimum": 0 },
        "routed_to_open_research": { "type": "integer", "minimum": 0 },
        "epistemically_open": { "type": "integer", "minimum": 0 },
        "theory_status_upgrades": { "const": 0 }
      }
    },
    "records": {
      "type": "array",
      "items": { "$ref": "#/$defs/resolution" }
    }
  },
  "$defs": {
    "sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "evidenceAnchor": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "path", "sha256", "address", "supports"],
      "properties": {
        "kind": {
          "enum": [
            "reviewed_source_snapshot",
            "canonical_claim_registry",
            "canonical_open_question_registry",
            "canonical_correction",
            "governance_artifact",
            "generated_validation_report",
            "runtime_or_product_artifact"
          ]
        },
        "path": { "type": "string", "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$)).+$" },
        "sha256": { "$ref": "#/$defs/sha256" },
        "address": { "type": "string", "minLength": 3 },
        "supports": { "type": "string", "minLength": 20 }
      }
    },
    "testAnchor": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "path", "sha256", "test_id", "state"],
      "properties": {
        "kind": {
          "enum": ["existing_test", "generated_validation_check", "required_test_missing", "required_research_test"]
        },
        "path": { "type": "string", "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$)).+$" },
        "sha256": { "$ref": "#/$defs/sha256" },
        "test_id": { "type": "string", "minLength": 3 },
        "state": { "enum": ["passed", "partial", "required_not_present", "not_run"] }
      }
    },
    "resolution": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "resolution_id",
        "obligation_id",
        "review_id",
        "source_id",
        "source_path",
        "source_sha256",
        "source_registry_sha256",
        "route",
        "review_task_state",
        "epistemic_state",
        "objective_result",
        "theory_status_change",
        "authority_required",
        "resolution_summary",
        "canonical_claim_ids",
        "open_question_ids",
        "evidence_anchors",
        "test_anchors"
      ],
      "properties": {
        "resolution_id": { "type": "string", "pattern": "^SSR-RES-[A-Z0-9-]+$" },
        "obligation_id": { "type": "string", "pattern": "^SSR-OB-[A-Z0-9-]+$" },
        "review_id": { "type": "string", "pattern": "^SSR-[A-Z0-9-]+$" },
        "source_id": { "type": "string", "minLength": 4 },
        "source_path": { "type": "string", "pattern": "^source_snapshot/" },
        "source_sha256": { "$ref": "#/$defs/sha256" },
        "source_registry_sha256": { "$ref": "#/$defs/sha256" },
        "route": {
          "enum": [
            "objective_current_state_audit",
            "author_semantic_or_editorial_decision",
            "formal_or_empirical_research"
          ]
        },
        "review_task_state": {
          "enum": ["evidence_dispositioned", "pending_author_decision", "routed_to_open_research"]
        },
        "epistemic_state": {
          "enum": ["not_a_theory_claim", "unresolved_authorial_meaning", "open_requires_formal_or_empirical_evidence"]
        },
        "objective_result": {
          "type": ["string", "null"],
          "enum": ["verified", "partially_verified", "not_demonstrated", "not_current", "candidate_not_deployed", null]
        },
        "theory_status_change": { "const": false },
        "authority_required": {
          "enum": [
            "repository_evidence_only",
            "canonical_human_steward",
            "formal_or_empirical_evidence_then_canonical_human_for_promotion"
          ]
        },
        "resolution_summary": { "type": "string", "minLength": 40 },
        "canonical_claim_ids": {
          "type": "array",
          "uniqueItems": true,
          "items": { "type": "string", "pattern": "^YT-[A-Z0-9-]+$" }
        },
        "open_question_ids": {
          "type": "array",
          "uniqueItems": true,
          "items": { "type": "string", "pattern": "^OQ-CAN-[0-9]{3}$" }
        },
        "evidence_anchors": {
          "type": "array",
          "minItems": 1,
          "items": { "$ref": "#/$defs/evidenceAnchor" }
        },
        "test_anchors": {
          "type": "array",
          "items": { "$ref": "#/$defs/testAnchor" }
        }
      },
      "allOf": [
        {
          "if": { "properties": { "route": { "const": "objective_current_state_audit" } }, "required": ["route"] },
          "then": {
            "properties": {
              "review_task_state": { "const": "evidence_dispositioned" },
              "epistemic_state": { "const": "not_a_theory_claim" },
              "objective_result": { "type": "string" },
              "authority_required": { "const": "repository_evidence_only" },
              "test_anchors": { "minItems": 1 }
            }
          }
        },
        {
          "if": { "properties": { "route": { "const": "author_semantic_or_editorial_decision" } }, "required": ["route"] },
          "then": {
            "properties": {
              "review_task_state": { "const": "pending_author_decision" },
              "epistemic_state": { "const": "unresolved_authorial_meaning" },
              "objective_result": { "type": "null" },
              "authority_required": { "const": "canonical_human_steward" }
            }
          }
        },
        {
          "if": { "properties": { "route": { "const": "formal_or_empirical_research" } }, "required": ["route"] },
          "then": {
            "properties": {
              "review_task_state": { "const": "routed_to_open_research" },
              "epistemic_state": { "const": "open_requires_formal_or_empirical_evidence" },
              "objective_result": { "type": "null" },
              "authority_required": { "const": "formal_or_empirical_evidence_then_canonical_human_for_promotion" },
              "open_question_ids": { "minItems": 1 },
              "test_anchors": { "minItems": 1 }
            }
          }
        }
      ]
    }
  }
}
