{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://matrixnetwork.me/schemas/y-theory-recursive-mind-runtime-v1.json",
  "title": "Y-Theory recursive structural Mind runtime",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema", "status", "release", "blueprint", "system_cells", "recursive_roots", "recursive_addresses", "system_transitions", "iteration", "personal_guide", "counts", "input_hashes", "iteration_run", "state_digest_contract", "state_digest"],
  "properties": {
    "schema": {"const": "y-theory.recursive-mind-runtime.v1"},
    "status": {"const": "executable_structural_runtime_not_cognitive_moral_or_conscious_mind"},
    "release": {
      "type": "object",
      "additionalProperties": false,
      "required": ["living_source_version", "canonical_author", "state"],
      "properties": {
        "living_source_version": {"type": "string", "minLength": 1},
        "canonical_author": {"type": "string", "minLength": 1},
        "state": {"const": "candidate_not_deployed"}
      }
    },
    "blueprint": {
      "type": "object",
      "additionalProperties": false,
      "required": ["equation", "coarising_roles", "recursive_reference_rule", "scale_rule", "relation_rule", "authority_rule"],
      "properties": {
        "equation": {"const": "MindCell(scope)=(inside_role,outside_role,relation_role)"},
        "coarising_roles": {"const": "inside_outside_and_relation_are_roles_of_one_bounded_change_not_three_independent_substances"},
        "recursive_reference_rule": {"type": "string", "minLength": 1},
        "scale_rule": {"type": "string", "minLength": 1},
        "relation_rule": {"type": "string", "minLength": 1},
        "authority_rule": {"type": "string", "minLength": 1}
      }
    },
    "system_cells": {
      "type": "array",
      "minItems": 5,
      "maxItems": 5,
      "prefixItems": [
        {"type": "object", "allOf": [{"$ref": "#/$defs/mind_cell"}], "properties": {"id": {"const": "MC-SOURCE-FIELD"}, "state": {"const": "partial"}, "child_mind_refs": {"const": ["MC-Y-ENGINE-COMPILER"]}}},
        {"type": "object", "allOf": [{"$ref": "#/$defs/mind_cell"}], "properties": {"id": {"const": "MC-Y-ENGINE-COMPILER"}, "state": {"const": "instantiated"}, "child_mind_refs": {"const": []}}},
        {"type": "object", "allOf": [{"$ref": "#/$defs/mind_cell"}], "properties": {"id": {"const": "MC-FIELD-BODY"}, "state": {"const": "instantiated"}, "child_mind_refs": {"const": ["MC-PRESENTATION-TEMPLATE"]}}},
        {"type": "object", "allOf": [{"$ref": "#/$defs/mind_cell"}], "properties": {"id": {"const": "MC-PRESENTATION-TEMPLATE"}, "state": {"const": "instantiated"}, "child_mind_refs": {"const": []}}},
        {"type": "object", "allOf": [{"$ref": "#/$defs/mind_cell"}], "properties": {"id": {"const": "MC-LEARNER-GUIDE"}, "state": {"const": "blueprint_only"}, "child_mind_refs": {"const": []}}}
      ],
      "items": false
    },
    "recursive_roots": {
      "const": ["MC-SOURCE-FIELD", "MC-FIELD-BODY", "MC-LEARNER-GUIDE"]
    },
    "recursive_addresses": {
      "type": "array",
      "minItems": 5,
      "maxItems": 5,
      "uniqueItems": true,
      "items": {"$ref": "#/$defs/recursive_address"}
    },
    "system_transitions": {
      "type": "array",
      "minItems": 2,
      "maxItems": 2,
      "prefixItems": [
        {"type": "object", "allOf": [{"$ref": "#/$defs/system_transition"}], "properties": {"id": {"const": "ST-FIELD-TO-BODY"}, "kind": {"const": "derived_snapshot_handoff"}, "from_cell_id": {"const": "MC-SOURCE-FIELD"}, "from_port": {"const": "residue"}, "artifact_path": {"const": "atlas/model/IDENTITY_GRAPH.json"}, "to_cell_id": {"const": "MC-FIELD-BODY"}, "to_role": {"const": "inside"}, "authority_mode": {"const": "read_only_no_reverse_write"}}},
        {"type": "object", "allOf": [{"$ref": "#/$defs/system_transition"}], "properties": {"id": {"const": "ST-FIELD-TO-GUIDE"}, "kind": {"const": "independent_read_binding"}, "from_cell_id": {"const": "MC-SOURCE-FIELD"}, "from_port": {"const": "residue"}, "artifact_path": {"const": "atlas/model/IDENTITY_GRAPH.json"}, "to_cell_id": {"const": "MC-LEARNER-GUIDE"}, "to_role": {"const": "outside"}, "authority_mode": {"const": "private_overlay_no_canonical_write"}}}
      ],
      "items": false
    },
    "iteration": {
      "type": "object",
      "additionalProperties": false,
      "required": ["execution_scope", "algorithm", "deterministic_stop", "human_review_boundary", "golden_ratio_hypothesis"],
      "properties": {
        "execution_scope": {"const": "runtime_structure_normalization_only_not_source_extraction_relation_approval_or_truth_validation"},
        "algorithm": {"type": "array", "items": {"type": "string"}, "minItems": 1},
        "deterministic_stop": {"type": "string", "minLength": 1},
        "human_review_boundary": {"type": "string", "minLength": 1},
        "golden_ratio_hypothesis": {
          "type": "object",
          "additionalProperties": false,
          "required": ["state", "phi", "used_as_stop_rule", "requirements"],
          "properties": {
            "state": {"const": "open_y_theory_hypothesis_not_derived"},
            "phi": {"type": "number"},
            "used_as_stop_rule": {"const": false},
            "requirements": {"type": "array", "items": {"type": "string"}, "minItems": 1}
          }
        }
      }
    },
    "personal_guide": {
      "type": "object",
      "additionalProperties": false,
      "required": ["state", "overlay_rule", "author_rule", "events", "progress_rule", "teacher_boundary", "canonical_write_boundary"],
      "properties": {
        "state": {"const": "architecture_defined_runtime_and_persistence_not_yet_implemented"},
        "overlay_rule": {"type": "string", "minLength": 1},
        "author_rule": {"type": "string", "minLength": 1},
        "events": {
          "type": "array",
          "minItems": 8,
          "maxItems": 8,
          "uniqueItems": true,
          "items": {"enum": ["question_asked", "explanation_opened", "source_inspected", "self_reported_understanding", "demonstration_attempted", "misconception_corrected", "challenge_created", "learning_objective_closed"]}
        },
        "progress_rule": {"type": "string", "minLength": 1},
        "teacher_boundary": {"type": "string", "minLength": 1},
        "canonical_write_boundary": {"type": "string", "minLength": 1}
      }
    },
    "counts": {
      "type": "object",
      "additionalProperties": false,
      "required": ["system_cells", "field_entities", "source_assertions", "candidate_referent_identities", "reviewed_relations", "derivation_links", "open_diagnostics", "uncompiled_identity_records", "candidate_identity_cells", "candidate_identity_cells_awaiting_role_review", "undispositioned_identity_records", "presentation_records"],
      "properties": {
        "system_cells": {"const": 5},
        "field_entities": {"type": "integer", "minimum": 0},
        "source_assertions": {"type": "integer", "minimum": 0},
        "candidate_referent_identities": {"type": "integer", "minimum": 0},
        "reviewed_relations": {"type": "integer", "minimum": 0},
        "derivation_links": {"type": "integer", "minimum": 0},
        "open_diagnostics": {"type": "integer", "minimum": 0},
        "uncompiled_identity_records": {"type": "integer", "minimum": 0},
        "candidate_identity_cells": {"type": "integer", "minimum": 0},
        "candidate_identity_cells_awaiting_role_review": {"type": "integer", "minimum": 0},
        "undispositioned_identity_records": {"const": 0},
        "presentation_records": {"type": "integer", "minimum": 0}
      }
    },
    "input_hashes": {
      "type": "object",
      "required": ["builder", "engine", "runtime_schema", "release_config", "identity_field", "candidate_identity_cells", "presentation", "source_coherence_diagnostic", "architecture"],
      "additionalProperties": false,
      "properties": {
        "builder": {"$ref": "#/$defs/sha256"},
        "engine": {"$ref": "#/$defs/sha256"},
        "runtime_schema": {"$ref": "#/$defs/sha256"},
        "release_config": {"$ref": "#/$defs/sha256"},
        "identity_field": {"$ref": "#/$defs/sha256"},
        "candidate_identity_cells": {"$ref": "#/$defs/sha256"},
        "presentation": {"$ref": "#/$defs/sha256"},
        "source_coherence_diagnostic": {"$ref": "#/$defs/sha256"},
        "architecture": {"$ref": "#/$defs/sha256"}
      }
    },
    "iteration_run": {
      "type": "object",
      "additionalProperties": false,
      "required": ["scope", "engine_cell_id", "preflight_operations", "executed_operations", "not_executed", "converged", "passes", "initial_digest", "history", "replay_verified", "final_digest"],
      "properties": {
        "scope": {"const": "runtime_structure_normalization_only_not_source_extraction_relation_approval_or_truth_validation"},
        "engine_cell_id": {"const": "MC-Y-ENGINE-COMPILER"},
        "preflight_operations": {"type": "array", "items": {"type": "string", "minLength": 1}, "minItems": 1, "uniqueItems": true},
        "executed_operations": {"type": "array", "items": {"type": "string", "minLength": 1}, "minItems": 1, "uniqueItems": true},
        "not_executed": {"type": "array", "items": {"type": "string", "minLength": 1}, "minItems": 1, "uniqueItems": true},
        "converged": {"const": true},
        "passes": {"type": "integer", "minimum": 1},
        "initial_digest": {"$ref": "#/$defs/sha256"},
        "history": {"type": "array", "items": {"$ref": "#/$defs/sha256"}, "minItems": 2},
        "replay_verified": {"const": true},
        "final_digest": {"$ref": "#/$defs/sha256"}
      }
    },
    "state_digest_contract": {
      "type": "object",
      "additionalProperties": false,
      "required": ["algorithm", "included_fields", "excluded_fields", "boundary"],
      "properties": {
        "algorithm": {"const": "sha256_of_utf8_canonical_json_sorted_keys_no_whitespace"},
        "included_fields": {"const": ["blueprint", "counts", "input_hashes", "iteration", "personal_guide", "recursive_addresses", "recursive_roots", "release", "schema", "status", "system_cells", "system_transitions"]},
        "excluded_fields": {"const": ["iteration_run", "state_digest_contract", "state_digest"]},
        "boundary": {"type": "string", "minLength": 1}
      }
    },
    "state_digest": {"type": "string", "pattern": "^[a-f0-9]{64}$"}
  },
  "$defs": {
    "sha256": {"type": "string", "pattern": "^[a-f0-9]{64}$"},
    "recursive_address": {
      "type": "object",
      "additionalProperties": false,
      "required": ["root_cell_id", "address", "role_path", "steps", "target_cell_id", "depth", "cycle"],
      "properties": {
        "root_cell_id": {"enum": ["MC-SOURCE-FIELD", "MC-FIELD-BODY", "MC-LEARNER-GUIDE"]},
        "address": {"type": "string", "pattern": "^mind://MC-"},
        "role_path": {"type": "array", "items": {"enum": ["inside", "outside", "relation"]}},
        "steps": {"type": "array", "items": {"$ref": "#/$defs/recursive_step"}},
        "target_cell_id": {"type": "string", "pattern": "^MC-"},
        "depth": {"type": "integer", "minimum": 0},
        "cycle": {"type": "boolean"}
      }
    },
    "recursive_step": {
      "type": "object",
      "additionalProperties": false,
      "required": ["from_cell_id", "role", "to_cell_id"],
      "properties": {
        "from_cell_id": {"type": "string", "pattern": "^MC-"},
        "role": {"enum": ["inside", "outside", "relation"]},
        "to_cell_id": {"type": "string", "pattern": "^MC-"}
      }
    },
    "system_transition": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "kind", "from_cell_id", "from_port", "artifact_path", "artifact_sha256", "to_cell_id", "to_role", "authority_mode", "recursive_or_semantic_edge"],
      "properties": {
        "id": {"type": "string", "pattern": "^ST-"},
        "kind": {"enum": ["derived_snapshot_handoff", "independent_read_binding"]},
        "from_cell_id": {"type": "string", "pattern": "^MC-"},
        "from_port": {"const": "residue"},
        "artifact_path": {"type": "string", "minLength": 1},
        "artifact_sha256": {"$ref": "#/$defs/sha256"},
        "to_cell_id": {"type": "string", "pattern": "^MC-"},
        "to_role": {"enum": ["inside", "outside", "relation"]},
        "authority_mode": {"enum": ["read_only_no_reverse_write", "private_overlay_no_canonical_write"]},
        "recursive_or_semantic_edge": {"const": false}
      }
    },
    "role": {
      "type": "object",
      "additionalProperties": false,
      "required": ["role", "occupant_type", "refs", "description"],
      "properties": {
        "role": {"enum": ["inside", "outside", "relation"]},
        "occupant_type": {"enum": ["identity", "identity_set", "mind_cell", "channel", "private_learner_state", "comparison_context"]},
        "refs": {"type": "array", "items": {"type": "string"}, "minItems": 1, "uniqueItems": true},
        "description": {"type": "string", "minLength": 1}
      }
    },
    "mind_cell": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "title", "reference_scope", "state", "roles", "change_cycle", "child_mind_refs", "capability_boundary"],
      "properties": {
        "id": {"type": "string", "pattern": "^MC-"},
        "title": {"type": "string", "minLength": 1},
        "reference_scope": {"type": "string", "minLength": 1},
        "state": {"enum": ["instantiated", "blueprint_only", "partial"]},
        "roles": {
          "type": "object",
          "additionalProperties": false,
          "required": ["inside", "outside", "relation"],
          "properties": {
            "inside": {"type": "object", "allOf": [{"$ref": "#/$defs/role"}], "properties": {"role": {"const": "inside"}}},
            "outside": {"type": "object", "allOf": [{"$ref": "#/$defs/role"}], "properties": {"role": {"const": "outside"}}},
            "relation": {"type": "object", "allOf": [{"$ref": "#/$defs/role"}], "properties": {"role": {"const": "relation"}}}
          }
        },
        "change_cycle": {
          "type": "object",
          "additionalProperties": false,
          "required": ["contact", "difference", "transformation", "residue", "return", "closure"],
          "properties": {
            "contact": {"type": "string", "minLength": 1},
            "difference": {"type": "string", "minLength": 1},
            "transformation": {"type": "string", "minLength": 1},
            "residue": {"type": "string", "minLength": 1},
            "return": {"type": "string", "minLength": 1},
            "closure": {"type": "string", "minLength": 1}
          }
        },
        "child_mind_refs": {"type": "array", "items": {"type": "string", "pattern": "^MC-"}, "uniqueItems": true},
        "capability_boundary": {"type": "string", "minLength": 1}
      }
    }
  }
}
