{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://agentfriendlyweb.dev/schemas/cli-response.v1.json",
  "title": "Agent Friendly Web CLI Response v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "contract",
    "cli_version",
    "command",
    "status",
    "dry_run",
    "generated_at",
    "input",
    "limits"
  ],
  "properties": {
    "contract": {
      "const": "agent-friendly-web.cli-response.v1"
    },
    "cli_version": {
      "type": "string",
      "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
    },
    "command": {
      "type": "string",
      "minLength": 1,
      "maxLength": 80
    },
    "status": {
      "enum": ["ok", "planned", "error"]
    },
    "dry_run": {
      "type": "boolean"
    },
    "generated_at": {
      "type": "string",
      "format": "date-time"
    },
    "input": {
      "type": "object"
    },
    "result": {
      "type": "object"
    },
    "error": {
      "type": "object",
      "additionalProperties": false,
      "required": ["code", "message"],
      "properties": {
        "code": {
          "type": "string",
          "minLength": 1,
          "maxLength": 80
        },
        "message": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500
        },
        "details": {
          "type": "object"
        }
      }
    },
    "limits": {
      "type": "array",
      "items": {
        "type": "string",
        "maxLength": 500
      },
      "maxItems": 24
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "status": { "const": "error" }
        }
      },
      "then": {
        "required": ["error"],
        "not": { "required": ["result"] }
      },
      "else": {
        "required": ["result"],
        "not": { "required": ["error"] }
      }
    }
  ]
}
