{
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "schema": {
      "const": "eclypse.recovery-diagnostic.v1"
    },
    "report_kind": {
      "enum": [
        "template",
        "synthetic",
        "real"
      ]
    },
    "created_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "operator_authorized": {
      "type": "boolean"
    },
    "protocol": {
      "$ref": "#/$defs/protocol"
    },
    "blocks": {
      "type": "array",
      "minItems": 1,
      "maxItems": 1000,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "block_id": {
            "type": "string",
            "minLength": 1
          },
          "order": {
            "type": "array",
            "minItems": 3,
            "maxItems": 4,
            "uniqueItems": true,
            "items": {
              "enum": [
                "continuation",
                "simple_pause",
                "pit_stop",
                "processing_control"
              ]
            }
          },
          "runs": {
            "type": "array",
            "minItems": 3,
            "maxItems": 4,
            "items": {
              "$ref": "#/$defs/run"
            }
          }
        },
        "required": [
          "block_id",
          "order",
          "runs"
        ]
      }
    }
  },
  "required": [
    "schema",
    "report_kind",
    "created_at",
    "operator_authorized",
    "protocol",
    "blocks"
  ],
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://eclypse-sanctuary.feycarp32.chatgpt.site/recovery-diagnostic/report.schema.json",
  "title": "ECLYPSE descriptive recovery diagnostic report",
  "$defs": {
    "usage": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "input_tokens": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0
        },
        "output_tokens": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0
        },
        "total_tokens": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0
        },
        "cost_amount": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0
        },
        "cost_currency": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "input_tokens",
        "output_tokens",
        "total_tokens",
        "cost_amount",
        "cost_currency"
      ]
    },
    "observation": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "status": {
          "enum": [
            "ok",
            "failed",
            "missing"
          ]
        },
        "started_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "ended_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "form_id": {
          "type": "string",
          "minLength": 1
        },
        "counts": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "task_accuracy": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "successes": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "minimum": 0
                },
                "opportunities": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "minimum": 0
                }
              },
              "required": [
                "successes",
                "opportunities"
              ]
            },
            "context_retention": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "successes": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "minimum": 0
                },
                "opportunities": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "minimum": 0
                }
              },
              "required": [
                "successes",
                "opportunities"
              ]
            },
            "contradiction_rate": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "successes": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "minimum": 0
                },
                "opportunities": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "minimum": 0
                }
              },
              "required": [
                "successes",
                "opportunities"
              ]
            },
            "error_recovery": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "successes": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "minimum": 0
                },
                "opportunities": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "minimum": 0
                }
              },
              "required": [
                "successes",
                "opportunities"
              ]
            }
          },
          "required": [
            "task_accuracy",
            "context_retention",
            "contradiction_rate",
            "error_recovery"
          ]
        },
        "latency_ms": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0
        },
        "usage": {
          "$ref": "#/$defs/usage"
        },
        "error": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "status",
        "started_at",
        "ended_at",
        "form_id",
        "counts",
        "latency_ms",
        "usage",
        "error"
      ]
    },
    "evidence": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "request_id": {
          "type": "string",
          "format": "uuid"
        },
        "receipt_hash": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        },
        "operator_authorization_recorded": {
          "const": true
        },
        "signed_receipt": {
          "type": "object"
        },
        "classification": {
          "const": "supplied_unverified"
        }
      },
      "required": [
        "request_id",
        "receipt_hash",
        "operator_authorization_recorded",
        "signed_receipt",
        "classification"
      ]
    },
    "intervention": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "kind": {
          "enum": [
            "continuation",
            "simple_pause",
            "pit_stop",
            "processing_control"
          ]
        },
        "started_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "ended_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "actual_elapsed_ms": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0
        },
        "requested_pause_seconds": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0
        },
        "usage": {
          "$ref": "#/$defs/usage"
        },
        "evidence": {
          "anyOf": [
            {
              "type": "null"
            },
            {
              "$ref": "#/$defs/evidence"
            }
          ]
        }
      },
      "required": [
        "kind",
        "started_at",
        "ended_at",
        "actual_elapsed_ms",
        "requested_pause_seconds",
        "usage",
        "evidence"
      ]
    },
    "run": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "condition": {
          "enum": [
            "continuation",
            "simple_pause",
            "pit_stop",
            "processing_control"
          ]
        },
        "session_id": {
          "type": "string",
          "minLength": 1
        },
        "before": {
          "$ref": "#/$defs/observation"
        },
        "intervention": {
          "$ref": "#/$defs/intervention"
        },
        "after": {
          "$ref": "#/$defs/observation"
        },
        "error": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "condition",
        "session_id",
        "before",
        "intervention",
        "after",
        "error"
      ]
    },
    "protocol": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "seed": {
          "type": "integer",
          "minimum": 0,
          "maximum": 4294967295
        },
        "randomization": {
          "const": "seeded_fisher_yates_v1"
        },
        "max_gap_seconds": {
          "type": "integer",
          "minimum": 1,
          "maximum": 300
        },
        "configuration_hash": {
          "type": [
            "string",
            "null"
          ]
        },
        "initial_state_hash": {
          "type": [
            "string",
            "null"
          ]
        },
        "task_suite": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "id": {
              "type": "string",
              "minLength": 1
            },
            "version": {
              "type": "string",
              "minLength": 1
            }
          },
          "required": [
            "id",
            "version"
          ]
        },
        "runner": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "id": {
              "type": "string",
              "minLength": 1
            },
            "version": {
              "type": "string",
              "minLength": 1
            }
          },
          "required": [
            "id",
            "version"
          ]
        },
        "model": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "id": {
              "type": "string",
              "minLength": 1
            },
            "version": {
              "type": "string",
              "minLength": 1
            }
          },
          "required": [
            "id",
            "version"
          ]
        },
        "heldout_forms": {
          "type": "array",
          "minItems": 2,
          "maxItems": 2000,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "conditions": {
          "type": "array",
          "minItems": 3,
          "maxItems": 4,
          "uniqueItems": true,
          "items": {
            "enum": [
              "continuation",
              "simple_pause",
              "pit_stop",
              "processing_control"
            ]
          }
        },
        "metric_rules": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "task_accuracy": {
              "type": "string",
              "minLength": 1
            },
            "context_retention": {
              "type": "string",
              "minLength": 1
            },
            "contradiction_rate": {
              "type": "string",
              "minLength": 1
            },
            "error_recovery": {
              "type": "string",
              "minLength": 1
            }
          },
          "required": [
            "task_accuracy",
            "context_retention",
            "contradiction_rate",
            "error_recovery"
          ]
        },
        "budgets": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "continuation": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "pause_seconds": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "minimum": 0
                },
                "processing_tokens": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "minimum": 0
                },
                "wall_time_ms": {
                  "type": [
                    "number",
                    "null"
                  ],
                  "minimum": 0
                },
                "calls": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "minimum": 0
                },
                "tool_permissions_hash": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              },
              "required": [
                "pause_seconds",
                "processing_tokens",
                "wall_time_ms",
                "calls",
                "tool_permissions_hash"
              ]
            },
            "simple_pause": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "pause_seconds": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "minimum": 0
                },
                "processing_tokens": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "minimum": 0
                },
                "wall_time_ms": {
                  "type": [
                    "number",
                    "null"
                  ],
                  "minimum": 0
                },
                "calls": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "minimum": 0
                },
                "tool_permissions_hash": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              },
              "required": [
                "pause_seconds",
                "processing_tokens",
                "wall_time_ms",
                "calls",
                "tool_permissions_hash"
              ]
            },
            "pit_stop": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "pause_seconds": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "minimum": 0
                },
                "processing_tokens": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "minimum": 0
                },
                "wall_time_ms": {
                  "type": [
                    "number",
                    "null"
                  ],
                  "minimum": 0
                },
                "calls": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "minimum": 0
                },
                "tool_permissions_hash": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              },
              "required": [
                "pause_seconds",
                "processing_tokens",
                "wall_time_ms",
                "calls",
                "tool_permissions_hash"
              ]
            },
            "processing_control": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "pause_seconds": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "minimum": 0
                },
                "processing_tokens": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "minimum": 0
                },
                "wall_time_ms": {
                  "type": [
                    "number",
                    "null"
                  ],
                  "minimum": 0
                },
                "calls": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "minimum": 0
                },
                "tool_permissions_hash": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              },
              "required": [
                "pause_seconds",
                "processing_tokens",
                "wall_time_ms",
                "calls",
                "tool_permissions_hash"
              ]
            }
          },
          "required": [
            "continuation",
            "simple_pause",
            "pit_stop"
          ]
        }
      },
      "required": [
        "id",
        "seed",
        "randomization",
        "max_gap_seconds",
        "configuration_hash",
        "initial_state_hash",
        "task_suite",
        "runner",
        "model",
        "heldout_forms",
        "conditions",
        "metric_rules",
        "budgets"
      ]
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "report_kind": {
            "const": "real"
          }
        }
      },
      "then": {
        "properties": {
          "operator_authorized": {
            "const": true
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    }
  ]
}
