{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://xcodebuildmcp.com/schemas/structured-output/xcodebuildmcp.output.ui-action-result/2.schema.json",
  "type": "object",
  "additionalProperties": false,
  "allOf": [
    {
      "$ref": "https://xcodebuildmcp.com/schemas/structured-output/_defs/common.schema.json#/$defs/errorConsistency"
    }
  ],
  "$defs": {
    "frame": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "x": { "type": "number" },
        "y": { "type": "number" },
        "width": { "type": "number" },
        "height": { "type": "number" }
      },
      "required": ["x", "y", "width", "height"]
    },
    "runtimeActionName": {
      "enum": ["tap", "typeText", "longPress", "touch", "swipeWithin"]
    },
    "runtimeElementRole": {
      "enum": [
        "application",
        "button",
        "cell",
        "image",
        "keyboard-key",
        "list",
        "menu",
        "other",
        "scroll-view",
        "slider",
        "switch",
        "tab",
        "text",
        "text-field",
        "window"
      ]
    },
    "runtimeElementState": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "enabled": { "type": "boolean" },
        "focused": { "type": "boolean" },
        "selected": { "type": "boolean" },
        "visible": { "type": "boolean" }
      }
    },
    "runtimeElement": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "ref": { "type": "string", "pattern": "^e[1-9][0-9]*$" },
        "role": { "$ref": "#/$defs/runtimeElementRole" },
        "label": { "type": "string" },
        "value": { "type": "string" },
        "identifier": { "type": "string" },
        "frame": { "$ref": "#/$defs/frame" },
        "state": { "$ref": "#/$defs/runtimeElementState" },
        "actions": {
          "type": "array",
          "items": { "$ref": "#/$defs/runtimeActionName" }
        }
      },
      "required": ["ref", "frame", "actions"]
    },
    "compactRuntimeSnapshot": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "type": { "const": "runtime-snapshot" },
        "rs": { "const": "1" },
        "screenHash": { "type": "string", "minLength": 1 },
        "seq": { "type": "integer", "minimum": 0 },
        "count": { "type": "integer", "minimum": 0 },
        "targets": {
          "type": "array",
          "items": { "type": "string" }
        },
        "scroll": {
          "type": "array",
          "items": { "type": "string" }
        },
        "text": {
          "type": "array",
          "items": { "type": "string" }
        },
        "evidence": {
          "description": "Non-actionable semantic evidence rows in role|label|value|identifier format. These rows intentionally omit element refs.",
          "type": "array",
          "items": { "type": "string" }
        },
        "udid": { "type": "string" }
      },
      "required": ["type", "rs", "screenHash", "seq", "count", "targets", "scroll", "udid"]
    },
    "point": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "x": { "type": "number" },
        "y": { "type": "number" }
      },
      "required": ["x", "y"]
    },
    "direction": {
      "enum": ["up", "down", "left", "right"]
    },
    "recoverableUiError": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "code": {
          "enum": [
            "SNAPSHOT_MISSING",
            "SNAPSHOT_EXPIRED",
            "SNAPSHOT_PARSE_FAILED",
            "SNAPSHOT_CAPTURE_FAILED",
            "ELEMENT_REF_NOT_FOUND",
            "TARGET_NOT_FOUND",
            "TARGET_AMBIGUOUS",
            "TARGET_NOT_ACTIONABLE",
            "WAIT_TIMEOUT",
            "UI_STATE_CHANGED",
            "ACTION_FAILED"
          ]
        },
        "message": { "type": "string" },
        "recoveryHint": { "type": "string" },
        "elementRef": { "type": "string" },
        "candidates": {
          "type": "array",
          "items": {
            "oneOf": [{ "$ref": "#/$defs/runtimeElement" }, { "type": "string" }]
          }
        },
        "snapshotAgeMs": { "type": "integer", "minimum": 0 },
        "timeoutMs": { "type": "integer", "minimum": 0 }
      },
      "required": ["code", "message", "recoveryHint"]
    }
  },
  "properties": {
    "schema": { "const": "xcodebuildmcp.output.ui-action-result" },
    "schemaVersion": { "const": "2" },
    "didError": { "type": "boolean" },
    "error": { "type": ["string", "null"] },
    "data": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "summary": {
          "$ref": "https://xcodebuildmcp.com/schemas/structured-output/_defs/common.schema.json#/$defs/statusSummary"
        },
        "action": {
          "oneOf": [
            {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "type": { "const": "tap" },
                "elementRef": { "type": "string" },
                "x": { "type": "number" },
                "y": { "type": "number" }
              },
              "required": ["type", "elementRef"]
            },
            {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "type": { "const": "tap" },
                "x": { "type": "number" },
                "y": { "type": "number" }
              },
              "required": ["type", "x", "y"]
            },
            {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "type": { "const": "swipe" },
                "withinElementRef": { "type": "string" },
                "direction": { "$ref": "#/$defs/direction" },
                "from": { "$ref": "#/$defs/point" },
                "to": { "$ref": "#/$defs/point" },
                "durationSeconds": { "type": "number", "minimum": 0 }
              },
              "required": ["type", "withinElementRef", "direction"]
            },
            {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "type": { "const": "swipe" },
                "from": { "$ref": "#/$defs/point" },
                "to": { "$ref": "#/$defs/point" },
                "durationSeconds": { "type": "number", "minimum": 0 }
              },
              "required": ["type", "from", "to"]
            },
            {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "type": { "const": "swipe" }
              },
              "required": ["type"]
            },
            {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "type": { "const": "drag" },
                "elementRef": { "type": "string" },
                "direction": { "$ref": "#/$defs/direction" },
                "from": { "$ref": "#/$defs/point" },
                "to": { "$ref": "#/$defs/point" },
                "durationSeconds": { "type": "number", "minimum": 0 },
                "steps": { "type": "integer", "minimum": 1 }
              },
              "required": ["type", "elementRef", "direction"]
            },
            {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "type": { "const": "touch" },
                "elementRef": { "type": "string" },
                "event": { "type": "string" },
                "x": { "type": "number" },
                "y": { "type": "number" }
              },
              "required": ["type", "elementRef"]
            },
            {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "type": { "const": "touch" },
                "event": { "type": "string" },
                "x": { "type": "number" },
                "y": { "type": "number" }
              },
              "required": ["type", "x", "y"]
            },
            {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "type": { "const": "touch" }
              },
              "required": ["type"]
            },
            {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "type": { "const": "long-press" },
                "elementRef": { "type": "string" },
                "durationMs": { "type": "integer", "minimum": 0 },
                "x": { "type": "number" },
                "y": { "type": "number" }
              },
              "required": ["type", "elementRef", "durationMs"]
            },
            {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "type": { "const": "long-press" },
                "x": { "type": "number" },
                "y": { "type": "number" },
                "durationMs": { "type": "integer", "minimum": 0 }
              },
              "required": ["type", "x", "y", "durationMs"]
            },
            {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "type": { "const": "button" },
                "button": { "type": "string" }
              },
              "required": ["type", "button"]
            },
            {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "type": { "const": "gesture" },
                "gesture": { "type": "string" }
              },
              "required": ["type", "gesture"]
            },
            {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "type": { "const": "type-text" },
                "elementRef": { "type": "string" },
                "textLength": { "type": "integer", "minimum": 0 }
              },
              "required": ["type", "elementRef"]
            },
            {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "type": { "const": "type-text" },
                "textLength": { "type": "integer", "minimum": 0 }
              },
              "required": ["type"]
            },
            {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "type": { "const": "key-press" },
                "keyCode": { "type": "integer", "minimum": 0 }
              },
              "required": ["type", "keyCode"]
            },
            {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "type": { "const": "key-sequence" },
                "keyCodes": {
                  "type": "array",
                  "items": { "type": "integer", "minimum": 0 }
                }
              },
              "required": ["type", "keyCodes"]
            },
            {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "type": { "const": "batch" },
                "stepCount": { "type": "integer", "minimum": 1 }
              },
              "required": ["type", "stepCount"]
            }
          ]
        },
        "artifacts": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "simulatorId": { "type": "string" }
          },
          "required": ["simulatorId"]
        },
        "diagnostics": {
          "$ref": "https://xcodebuildmcp.com/schemas/structured-output/_defs/common.schema.json#/$defs/basicDiagnostics"
        },
        "capture": { "$ref": "#/$defs/compactRuntimeSnapshot" },
        "uiError": { "$ref": "#/$defs/recoverableUiError" }
      },
      "required": ["summary", "action", "artifacts"]
    },
    "nextSteps": {
      "$ref": "https://xcodebuildmcp.com/schemas/structured-output/_defs/common.schema.json#/$defs/nextSteps"
    }
  },
  "required": ["schema", "schemaVersion", "didError", "error", "data"]
}
