{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/Living-Proof-Labs/robot-capability-specs/specs/robots/run-assessment.schema.json",
  "title": "livingproof-run-assessment/0.1",
  "description": "Legacy livingproof-run-assessment/0.1 bundle. The verifier's decisions for one evidence bundle: a status and reason per result under a named policy, and per run the grade under a named aggregation. Written by the capability verifier into reporter bundle 1.1.0 as `assessment`; a reporter renders it and never recomputes it. This legacy shape still stores the seeded aggregation (k, n, required passes, a Wilson interval, and a seed on each failure) as capability report v1.10.0 wrote it. The catalog trial model uses identical trials and no seed; replacing this legacy bundle is separate work.",
  "type": "object",
  "additionalProperties": false,
  "required": ["format", "policy", "aggregation", "decisions", "runs"],
  "properties": {
    "$comment": {"type": "string"},
    "format": {"const": "livingproof-run-assessment/0.1"},
    "policy": {"$ref": "#/$defs/versioned"},
    "aggregation": {"$ref": "#/$defs/versioned"},
    "decisions": {
      "description": "One per bundle result, in bundle order.",
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["result_id", "status", "reason", "failures", "assessor_types"],
        "properties": {
          "result_id": {"type": "string", "minLength": 1},
          "status": {"$ref": "#/$defs/status"},
          "reason": {"type": "string", "minLength": 1},
          "failures": {"type": "array", "items": {"$ref": "#/$defs/failure"}},
          "assessor_types": {"type": "array", "uniqueItems": true, "items": {"enum": ["deterministic", "human", "agent"]}}
        }
      }
    },
    "runs": {
      "description": "One per run: results sharing specification commit, system, environment and run id.",
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["capability", "spec", "system", "environment", "run_id", "k", "n", "required_passes", "interval", "grade", "rationale", "result_ids", "failures", "prototype"],
        "properties": {
          "capability": {"type": "string", "minLength": 1},
          "spec": {
            "type": "object", "additionalProperties": false,
            "required": ["repository", "tag", "commit", "capability", "revision"],
            "properties": {
              "repository": {"type": "string"}, "tag": {"type": "string"},
              "commit": {"type": "string", "pattern": "^[0-9a-f]{40}$"},
              "capability": {"type": "string"}, "revision": {"type": "string"}
            }
          },
          "system": {"$ref": "#/$defs/identified"},
          "environment": {"$ref": "#/$defs/identified"},
          "run_id": {"type": ["string", "null"]},
          "k": {"type": "integer", "minimum": 0},
          "n": {"type": "integer", "minimum": 0, "description": "Planned N; the recorded count only when no usable plan exists (then the grade is INSUFFICIENT_EVIDENCE)."},
          "required_passes": {"type": ["integer", "null"]},
          "interval": {
            "type": "object", "additionalProperties": false,
            "required": ["method", "level", "lower", "upper"],
            "properties": {
              "method": {"const": "wilson"},
              "level": {"const": 0.95},
              "lower": {"type": "number", "minimum": 0, "maximum": 1},
              "upper": {"type": "number", "minimum": 0, "maximum": 1}
            }
          },
          "grade": {"$ref": "#/$defs/status"},
          "rationale": {"type": "string", "minLength": 1},
          "result_ids": {"type": "array", "minItems": 1, "items": {"type": "string"}},
          "failures": {"type": "array", "items": {"$ref": "#/$defs/failure"}},
          "prototype": {"type": ["string", "null"]}
        }
      }
    }
  },
  "$defs": {
    "status": {"enum": ["PASS", "FAIL", "INSUFFICIENT_EVIDENCE", "INCOMPATIBLE"]},
    "versioned": {
      "type": "object", "additionalProperties": false, "required": ["id", "version"],
      "properties": {"id": {"type": "string", "pattern": "^[a-z0-9][a-z0-9-]*$"}, "version": {"type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"}}
    },
    "identified": {
      "type": "object", "additionalProperties": false, "required": ["id", "version"],
      "properties": {"id": {"type": "string", "minLength": 1}, "version": {"type": "string", "minLength": 1}}
    },
    "failure": {
      "type": "object", "additionalProperties": false,
      "required": ["check", "observed", "limit", "unit", "t", "seed"],
      "properties": {
        "check": {"type": "string", "minLength": 1},
        "observed": {"type": ["number", "null"]},
        "limit": {"type": "number"},
        "unit": {"type": "string", "minLength": 1},
        "t": {"type": ["number", "null"]},
        "seed": {"type": ["integer", "null"]},
        "wall": {"type": "string"}
      }
    }
  }
}
