{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/Living-Proof-Labs/robot-capability-specs/specs/worlds/hallway-result.schema.json",
  "title": "livingproof-world-result/0.2",
  "description": "Engine-neutral result of one engine loading one versioned world fixture. Every engine adapter emits this shape; a verifier joins two records on quantity name. Revision 0.2 supersedes the adapter-local 0.1 draft in livingproof-sim-mujoco.",
  "type": "object",
  "required": ["format", "status", "fixture", "contract", "catalog", "engine", "adapter", "quantities"],
  "properties": {
    "format": {"const": "livingproof-world-result/0.2"},
    "status": {"enum": ["PASS", "FAIL", "UNSUPPORTED"], "description": "PASS only if every quantity passes. UNSUPPORTED is never a pass."},
    "feature": {"type": "string", "minLength": 1, "description": "Required when status is UNSUPPORTED: the declared feature that could not be mapped."},
    "fixture": {
      "type": "object",
      "required": ["id", "content_version"],
      "properties": {"id": {"type": "string", "minLength": 1}, "content_version": {"$ref": "#/$defs/semver"}}
    },
    "content_version": {"type": "string", "description": "Optional copy of fixture.content_version for UNSUPPORTED records."},
    "contract": {
      "type": "object",
      "required": ["world_contract_revision"],
      "properties": {
        "world_contract_revision": {"type": "string"},
        "document": {"type": "string"},
        "document_revision": {"type": "string"},
        "result_format": {"type": "string"}
      }
    },
    "catalog": {
      "type": "object",
      "required": ["repository", "tag", "commit"],
      "properties": {"repository": {"type": "string"}, "tag": {"type": "string"}, "commit": {"$ref": "#/$defs/sha"}}
    },
    "worlds": {
      "type": "object",
      "description": "Pinned world-content release.",
      "required": ["repository", "tag", "commit", "release_sha256"],
      "properties": {"commit": {"$ref": "#/$defs/sha"}, "release_sha256": {"type": "string", "pattern": "^[0-9a-f]{64}$"}}
    },
    "engine": {
      "type": "object",
      "required": ["name", "version"],
      "properties": {"name": {"type": "string", "minLength": 1}, "version": {"type": "string", "minLength": 1}}
    },
    "adapter": {
      "type": "object",
      "required": ["name", "version", "commit"],
      "description": "The adapter that produced the record: semver version plus the full commit it was built from.",
      "properties": {
        "name": {"type": "string", "minLength": 1},
        "version": {"$ref": "#/$defs/semver", "description": "Semantic version, e.g. 1.2.0 or 1.1.0-dev.5+g696d9601e1a4. Never a bare commit."},
        "commit": {"oneOf": [{"$ref": "#/$defs/sha"}, {"type": "null"}], "description": "Full 40-character commit, or null when the adapter commit is unknown (for example no git checkout and no build provenance)."},
        "provenance": {"enum": ["git", "package"], "description": "Optional: where version and commit came from: a git checkout or installed package metadata."}
      }
    },
    "compile": {"type": "object", "description": "Engine-native compile or load check."},
    "settings": {"type": "object", "description": "Gravity/contact settings, drive method, sampling rate, measurement method and probe parameters."},
    "screenshots": {
      "type": "object",
      "required": ["status"],
      "properties": {"status": {"enum": ["PASS", "BLOCKED", "NOT-RUN"]}}
    },
    "quantities": {"type": "array", "items": {"$ref": "#/$defs/quantity"}}
  },
  "allOf": [
    {"if": {"properties": {"status": {"const": "UNSUPPORTED"}}, "required": ["status"]}, "then": {"required": ["feature"]}}
  ],
  "$defs": {
    "sha": {"type": "string", "pattern": "^[0-9a-f]{40}$"},
    "semver": {
      "type": "string",
      "pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?$"
    },
    "quantity": {
      "type": "object",
      "required": ["name", "kind", "unit", "comparison", "canonical", "measured", "deviation", "tolerance", "pass", "method"],
      "properties": {
        "name": {"type": "string", "pattern": "^[a-z][a-z0-9_]*(?:/[A-Za-z0-9_+.-]+)*$", "description": "Engine-neutral key from hallway-quantities.json, e.g. clear_width, place/spawn-exit/yaw, collision/open_end/+x/final_x. Names under reset/ are reserved for the reset checks."},
        "kind": {"enum": ["dimension", "frame", "place", "collision", "drive", "reset"]},
        "unit": {"enum": ["m", "deg", "m/s", "count", "bool"]},
        "comparison": {"enum": ["within", "at_most"], "description": "within: pass when |measured - canonical| <= tolerance. at_most: pass when measured <= canonical + tolerance."},
        "canonical": {"type": "number", "description": "Canonical value or target from the fixture (for open_end/+x/final_x the target 2.80)."},
        "measured": {"type": ["number", "null"]},
        "deviation": {"type": ["number", "null"], "description": "measured - canonical"},
        "tolerance": {"type": "number", "minimum": 0},
        "pass": {"type": "boolean"},
        "method": {"type": "string"},
        "contacts": {"type": "array", "items": {"type": "string"}}
      }
    }
  }
}
