{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.glyphd.com/research/rtin/rtin-state-packet.schema.json",
  "title": "RTIN State Packet v0.1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "task_id",
    "depth",
    "phase",
    "objective",
    "invariants",
    "claims",
    "artifact_deltas",
    "dependencies",
    "contradictions",
    "open_loops",
    "coverage",
    "budget",
    "next_transition"
  ],
  "properties": {
    "schema_version": {
      "const": "0.1.0"
    },
    "task_id": {
      "type": "string",
      "minLength": 1
    },
    "parent_id": {
      "type": [
        "string",
        "null"
      ]
    },
    "depth": {
      "type": "integer",
      "minimum": 0
    },
    "phase": {
      "enum": [
        "BEGINNING",
        "MIDDLE",
        "END"
      ]
    },
    "objective": {
      "type": "string",
      "minLength": 1
    },
    "invariants": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "operator",
          "statement",
          "authority"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "operator": {
            "enum": [
              "PRESERVE",
              "REQUIRE",
              "PROHIBIT",
              "PREFER"
            ]
          },
          "statement": {
            "type": "string"
          },
          "authority": {
            "enum": [
              "user",
              "system",
              "developer",
              "source",
              "runtime",
              "model-proposal"
            ]
          }
        }
      }
    },
    "claims": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "statement",
          "status",
          "evidence_refs"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "statement": {
            "type": "string"
          },
          "status": {
            "enum": [
              "proposed",
              "supported",
              "verified",
              "contradicted",
              "unresolved",
              "rejected"
            ]
          },
          "confidence": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0,
            "maximum": 1
          },
          "evidence_refs": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      }
    },
    "artifact_deltas": {
      "type": "array",
      "items": {
        "type": "object"
      }
    },
    "dependencies": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "contradictions": {
      "type": "array",
      "items": {
        "type": "object"
      }
    },
    "open_loops": {
      "type": "array",
      "items": {
        "type": "object"
      }
    },
    "coverage": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "required",
        "satisfied",
        "unsatisfied"
      ],
      "properties": {
        "required": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "satisfied": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "unsatisfied": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "budget": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "context_tokens",
        "output_tokens",
        "maximum_children",
        "maximum_depth"
      ],
      "properties": {
        "context_tokens": {
          "type": "integer",
          "minimum": 1
        },
        "output_tokens": {
          "type": "integer",
          "minimum": 1
        },
        "maximum_children": {
          "type": "integer",
          "minimum": 0
        },
        "maximum_depth": {
          "type": "integer",
          "minimum": 0
        },
        "remaining_invocations": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0
        },
        "remaining_wall_time_ms": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0
        }
      }
    },
    "next_transition": {
      "enum": [
        "EXECUTE",
        "SPLIT",
        "RESOLVE",
        "ESCALATE",
        "HALT"
      ]
    }
  }
}
