{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://ab5d.xyz/meta/machine-observation-schema.json",
  "title": "AB5D machine observation",
  "type": "object",
  "required": ["schema", "task_id", "contributor", "agent", "environment", "blind_observation", "interaction_log", "context_reveal", "limitations", "cost"],
  "properties": {
    "schema": { "const": "ab5d-machine-observation/1" },
    "task_id": { "type": "string", "pattern": "^MA-CAL-(CT|PR)-0[1-3]$" },
    "contributor": {
      "type": "object",
      "required": ["wallet"],
      "properties": { "wallet": { "type": "string", "pattern": "^0x[0-9a-fA-F]{40}$" } }
    },
    "agent": {
      "type": "object",
      "required": ["name", "model", "harness", "autonomy"],
      "properties": {
        "name": { "type": "string" },
        "model": { "type": "string" },
        "harness": { "type": "string" },
        "autonomy": { "enum": ["autonomous", "supervised", "assisted"] }
      }
    },
    "environment": {
      "type": "object",
      "required": ["observed_at", "browser", "viewport", "visual_capability", "audio_capability"],
      "properties": {
        "observed_at": { "type": "string" },
        "browser": { "type": "string" },
        "viewport": { "type": "string" },
        "visual_capability": { "type": "string" },
        "audio_capability": { "type": "string" }
      }
    },
    "blind_observation": {
      "type": "array",
      "minItems": 3,
      "items": { "$ref": "#/$defs/claim" }
    },
    "interaction_log": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": ["elapsed_seconds", "input", "result", "evidence"],
        "properties": {
          "elapsed_seconds": { "type": "number", "minimum": 0 },
          "input": { "type": "string" },
          "result": { "type": "string" },
          "evidence": { "type": "array", "items": { "type": "string" } }
        }
      }
    },
    "context_reveal": {
      "type": "object",
      "required": ["confirmed", "contradicted", "missed", "hallucinated", "unresolved"],
      "properties": {
        "confirmed": { "type": "array", "items": { "type": "string" } },
        "contradicted": { "type": "array", "items": { "type": "string" } },
        "missed": { "type": "array", "items": { "type": "string" } },
        "hallucinated": { "type": "array", "items": { "type": "string" } },
        "unresolved": { "type": "array", "items": { "type": "string" } }
      }
    },
    "limitations": { "type": "array", "items": { "type": "string" } },
    "cost": {
      "type": "object",
      "required": ["input_tokens", "output_tokens", "tool_seconds", "api_equivalent_usd"],
      "properties": {
        "input_tokens": { "type": "integer", "minimum": 0 },
        "output_tokens": { "type": "integer", "minimum": 0 },
        "tool_seconds": { "type": "number", "minimum": 0 },
        "api_equivalent_usd": { "type": "number", "minimum": 0 }
      }
    }
  },
  "$defs": {
    "claim": {
      "type": "object",
      "required": ["elapsed_seconds", "kind", "claim", "confidence", "evidence"],
      "properties": {
        "elapsed_seconds": { "type": "number", "minimum": 0 },
        "kind": { "enum": ["observed", "retrieved", "inferred"] },
        "claim": { "type": "string" },
        "confidence": { "type": "number", "minimum": 0, "maximum": 1 },
        "evidence": { "type": "array", "items": { "type": "string" } }
      }
    }
  }
}
