{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:orbitspace:cli-tool-result:v1",
  "title": "CLI Tool adapter result",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "execution_id",
    "status",
    "tool",
    "tool_version",
    "duration_ms",
    "input_digest",
    "result",
    "artifacts",
    "warnings",
    "error"
  ],
  "properties": {
    "schema_version": {
      "const": "1"
    },
    "execution_id": {
      "type": "string",
      "format": "uuid"
    },
    "status": {
      "enum": [
        "succeeded",
        "failed",
        "cancelled"
      ]
    },
    "tool": {
      "type": "string",
      "minLength": 1,
      "maxLength": 160
    },
    "tool_version": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128
    },
    "target_platform": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128
    },
    "duration_ms": {
      "type": "integer",
      "minimum": 0
    },
    "input_digest": {
      "type": "string",
      "pattern": "^sha256:[0-9a-f]{64}$"
    },
    "result": {
      "type": [
        "object",
        "null"
      ]
    },
    "artifacts": {
      "type": "array",
      "maxItems": 256,
      "items": {
        "$ref": "#/$defs/artifact"
      }
    },
    "warnings": {
      "type": "array",
      "maxItems": 256,
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 4096
      }
    },
    "error": {
      "oneOf": [
        {
          "type": "null"
        },
        {
          "$ref": "#/$defs/error"
        }
      ]
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "status": {
            "const": "succeeded"
          }
        }
      },
      "then": {
        "properties": {
          "error": {
            "type": "null"
          },
          "result": {
            "type": "object"
          }
        }
      },
      "else": {
        "properties": {
          "error": {
            "$ref": "#/$defs/error"
          },
          "result": {
            "type": "null"
          },
          "artifacts": {
            "maxItems": 0
          }
        }
      }
    }
  ],
  "$defs": {
    "artifact": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "kind",
        "name",
        "path",
        "content_type",
        "size_bytes",
        "checksum_sha256"
      ],
      "properties": {
        "kind": {
          "type": "string",
          "minLength": 1,
          "maxLength": 96,
          "pattern": "^[a-z0-9][a-z0-9._-]*$"
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512
        },
        "path": {
          "type": "string",
          "minLength": 1,
          "maxLength": 4096
        },
        "content_type": {
          "type": "string",
          "minLength": 3,
          "maxLength": 256
        },
        "size_bytes": {
          "type": "integer",
          "minimum": 0
        },
        "checksum_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        }
      }
    },
    "error": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "code",
        "message"
      ],
      "properties": {
        "code": {
          "type": "string",
          "pattern": "^[A-Z][A-Z0-9_]{0,95}$"
        },
        "message": {
          "type": "string",
          "minLength": 1,
          "maxLength": 4096
        },
        "details": {
          "type": "object"
        }
      }
    }
  }
}
