{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://wraithrun.dev/schemas/run-report.schema.json",
  "title": "WraithRun Run Report",
  "type": "object",
  "required": [
    "contract_version",
    "task",
    "turns",
    "final_answer",
    "findings"
  ],
  "properties": {
    "contract_version": {
      "type": "string",
      "const": "1.0.0"
    },
    "task": {
      "type": "string"
    },
    "case_id": {
      "type": ["string", "null"]
    },
    "max_severity": {
      "type": ["string", "null"],
      "enum": ["info", "low", "medium", "high", "critical", null]
    },
    "backend": {
      "type": ["string", "null"],
      "description": "Name of the inference backend used for this run (e.g. CPU, AMD Vitis NPU)."
    },
    "model_capability": {
      "type": ["object", "null"],
      "required": ["tier", "estimated_params_b", "execution_provider", "smoke_latency_ms", "vocab_size"],
      "properties": {
        "tier": {
          "type": "string",
          "enum": ["basic", "moderate", "strong"]
        },
        "estimated_params_b": {
          "type": "number",
          "minimum": 0.0
        },
        "execution_provider": {
          "type": "string"
        },
        "smoke_latency_ms": {
          "type": "integer",
          "minimum": 0
        },
        "vocab_size": {
          "type": "integer",
          "minimum": 0
        },
        "override": {
          "type": "boolean"
        }
      },
      "additionalProperties": false
    },
    "live_fallback_decision": {
      "type": ["object", "null"],
      "required": ["policy", "reason", "reason_code", "live_error", "fallback_mode"],
      "properties": {
        "policy": {
          "type": "string",
          "enum": ["none", "dry-run-on-error"]
        },
        "reason": {
          "type": "string"
        },
        "reason_code": {
          "type": "string",
          "enum": [
            "tokenizer_path_missing",
            "tokenizer_json_invalid",
            "model_path_missing",
            "permission_denied",
            "live_runtime_error",
            "unknown_live_error"
          ]
        },
        "live_error": {
          "type": "string"
        },
        "fallback_mode": {
          "type": "string",
          "enum": ["dry-run"]
        }
      },
      "additionalProperties": false
    },
    "run_timing": {
      "type": ["object", "null"],
      "required": ["total_run_duration_ms"],
      "properties": {
        "first_token_latency_ms": {
          "type": ["integer", "null"],
          "minimum": 0
        },
        "total_run_duration_ms": {
          "type": "integer",
          "minimum": 0
        }
      },
      "additionalProperties": false
    },
    "live_run_metrics": {
      "type": ["object", "null"],
      "required": [
        "total_run_duration_ms",
        "live_attempt_duration_ms",
        "live_attempt_count",
        "live_success_count",
        "fallback_count",
        "live_success_rate",
        "fallback_rate"
      ],
      "properties": {
        "first_token_latency_ms": {
          "type": ["integer", "null"],
          "minimum": 0
        },
        "total_run_duration_ms": {
          "type": "integer",
          "minimum": 0
        },
        "live_attempt_duration_ms": {
          "type": "integer",
          "minimum": 0
        },
        "live_attempt_count": {
          "type": "integer",
          "minimum": 0
        },
        "live_success_count": {
          "type": "integer",
          "minimum": 0
        },
        "fallback_count": {
          "type": "integer",
          "minimum": 0
        },
        "live_success_rate": {
          "type": "number",
          "minimum": 0.0,
          "maximum": 1.0
        },
        "fallback_rate": {
          "type": "number",
          "minimum": 0.0,
          "maximum": 1.0
        },
        "top_failure_reasons": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["reason_code", "count"],
            "properties": {
              "reason_code": {
                "type": "string",
                "enum": [
                  "tokenizer_path_missing",
                  "tokenizer_json_invalid",
                  "model_path_missing",
                  "permission_denied",
                  "live_runtime_error",
                  "unknown_live_error"
                ]
              },
              "count": {
                "type": "integer",
                "minimum": 0
              }
            },
            "additionalProperties": false
          }
        }
      },
      "additionalProperties": false
    },
    "turns": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["thought"],
        "properties": {
          "thought": {
            "type": "string"
          },
          "tool_call": {
            "type": ["object", "null"],
            "required": ["tool", "args"],
            "properties": {
              "tool": {
                "type": "string"
              },
              "args": {
                "type": "object"
              }
            },
            "additionalProperties": true
          },
          "observation": {
            "type": ["object", "array", "string", "number", "boolean", "null"]
          }
        },
        "additionalProperties": false
      }
    },
    "final_answer": {
      "type": "string"
    },
    "findings": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "title",
          "severity",
          "confidence",
          "evidence_pointer",
          "recommended_action"
        ],
        "properties": {
          "title": {
            "type": "string"
          },
          "severity": {
            "type": "string",
            "enum": ["info", "low", "medium", "high", "critical"]
          },
          "confidence": {
            "type": "number",
            "minimum": 0.0,
            "maximum": 1.0
          },
          "confidence_label": {
            "type": "string",
            "enum": ["informational", "possible", "likely", "confirmed"]
          },
          "relevance": {
            "type": "string",
            "enum": ["primary", "supplementary"],
            "default": "primary"
          },
          "evidence_pointer": {
            "type": "object",
            "required": ["turn", "tool", "field"],
            "properties": {
              "turn": {
                "type": ["integer", "null"],
                "minimum": 1
              },
              "tool": {
                "type": ["string", "null"]
              },
              "field": {
                "type": "string"
              }
            },
            "additionalProperties": false
          },
          "recommended_action": {
            "type": "string"
          }
        },
        "additionalProperties": false
      }
    },
    "supplementary_findings": {
      "type": "array",
      "items": {
        "$ref": "#/properties/findings/items"
      }
    }
  },
  "additionalProperties": false
}
