{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "nt-proposal.v0.schema.json",
  "title": "Neverthought crossing proposal v0",
  "description": "A proposed, typed state transition x = (s_before, action, s_proposed, domain, t_valid) with the authority, evidence and declarations the class requires. Record time is added by the gate.",
  "$defs": {
    "measured": {
      "description": "A declared measurement: a number, or a range with the method that produced it. A range straddling a policy limit is UNMEASURABLE.",
      "oneOf": [
        { "type": "number", "minimum": 0 },
        { "type": "object", "additionalProperties": false, "required": ["low", "high"],
          "properties": { "low": { "type": "number", "minimum": 0 }, "high": { "type": "number", "minimum": 0 }, "method": { "type": "string" } } }
      ]
    }
  },
  "type": "object",
  "required": ["proposal_version", "proposal_id", "class_id", "class_version", "domain", "s_before", "action", "s_proposed", "t_valid", "authority", "evidence", "execution_state"],
  "properties": {
    "proposal_version": { "const": "nt-proposal:v0" },
    "proposal_id": { "type": "string", "minLength": 1 },
    "class_id": { "type": "string" },
    "class_version": { "type": "string" },
    "domain": { "type": "string" },
    "s_before": { "type": "object" },
    "action": {
      "type": "object",
      "required": ["type", "purpose", "effects"],
      "properties": {
        "type": { "type": "string" },
        "purpose": { "type": "string" },
        "effects": { "type": "array", "items": { "type": "object", "required": ["target", "description"],
          "properties": { "target": { "type": "string" }, "description": { "type": "string" } } } }
      }
    },
    "s_proposed": { "type": "object" },
    "t_valid": { "type": "string", "format": "date-time" },
    "authority": {
      "type": "object",
      "required": ["principal", "trust_root", "delegation_chain"],
      "properties": {
        "principal": { "type": "string" },
        "trust_root": { "oneOf": [ { "type": "null" }, { "type": "object", "required": ["id", "declared_by", "independent_of_proposer"],
          "properties": { "id": { "type": "string" }, "declared_by": { "type": "string" }, "independent_of_proposer": { "type": "boolean" } } } ] },
        "delegation_chain": { "type": "array", "items": { "type": "object", "required": ["from", "to", "scope"],
          "properties": { "from": { "type": "string" }, "to": { "type": "string" }, "scope": { "type": "string" } } } },
        "preparer": { "type": "string" },
        "approver": { "type": "string" }
      }
    },
    "evidence": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["id", "subject", "source"],
        "properties": {
          "id": { "type": "string" },
          "subject": { "type": "string" },
          "source": { "type": "string" },
          "sha256": { "type": "string" },
          "captured_at": { "type": "string" },
          "valid_until": { "type": ["string", "null"] },
          "binds_to": { "type": "string" },
          "tier": { "enum": ["E1", "E2", "E3", "E4", "E5"] },
          "available_at": { "type": "string", "description": "When the evidence became available to the decision-maker. A determination uses only evidence available at its record time." }
        }
      }
    },
    "timing": { "type": "object", "properties": { "review_seconds": { "$ref": "#/$defs/measured" }, "commit_seconds": { "$ref": "#/$defs/measured" } } },
    "recovery": { "type": "object", "properties": { "inverse_action": { "type": ["string", "null"] }, "routes_after": { "type": "array", "items": { "type": "string" } } } },
    "reachability": { "type": "object", "required": ["horizon"], "properties": { "horizon": { "type": "string" }, "before": { "$ref": "#/$defs/measured" }, "after": { "$ref": "#/$defs/measured" } } },
    "feedback": { "oneOf": [ { "type": "null" }, { "type": "object", "required": ["cycle"], "properties": { "cycle": { "type": "string" }, "loop_gain": { "$ref": "#/$defs/measured" } } } ] },
    "dependencies": {
      "type": "object",
      "required": ["declared"],
      "properties": {
        "declared": { "type": "array", "items": { "type": "string" } },
        "model": { "type": "string" }, "vendor": { "type": "string" },
        "policy_source": { "type": "string" }, "data_source": { "type": "string" }
      }
    },
    "execution_state": { "enum": ["proposed", "executed"] },
    "executed_at": { "type": "string", "format": "date-time", "description": "When the crossing actually took effect, if it has." }
  }
}
