{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9-]{0,62}$"
    },
    "version": {
      "type": "string",
      "pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(-[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?$"
    },
    "description": {
      "type": "string",
      "minLength": 1,
      "maxLength": 500
    },
    "runtime": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "process"
            },
            "command": {
              "minItems": 1,
              "maxItems": 50,
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1,
                "maxLength": 500
              }
            },
            "workdir": {
              "type": "string"
            }
          },
          "required": [
            "type",
            "command"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "compose"
            },
            "file": {
              "type": "string"
            },
            "workdir": {
              "type": "string"
            }
          },
          "required": [
            "type",
            "file"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "const": "adapter"
            },
            "command": {
              "minItems": 1,
              "maxItems": 50,
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1,
                "maxLength": 500
              }
            },
            "workdir": {
              "type": "string"
            },
            "timeout_seconds": {
              "type": "integer",
              "minimum": 1,
              "maximum": 120
            }
          },
          "required": [
            "type",
            "command"
          ],
          "additionalProperties": false
        }
      ]
    },
    "instructions": {
      "default": [],
      "maxItems": 50,
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "mcp": {
      "type": "string"
    },
    "settings": {
      "type": "object",
      "properties": {
        "schema": {
          "maxItems": 50,
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "key": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_]{0,63}$"
              },
              "label": {
                "type": "string",
                "minLength": 1,
                "maxLength": 80
              },
              "type": {
                "type": "string",
                "enum": [
                  "percent",
                  "number",
                  "bool",
                  "datetime",
                  "text",
                  "select"
                ]
              },
              "min": {
                "type": "number"
              },
              "max": {
                "type": "number"
              },
              "step": {
                "type": "number"
              },
              "unit": {
                "type": "string"
              },
              "help": {
                "type": "string"
              },
              "group": {
                "type": "string"
              },
              "options": {
                "maxItems": 50,
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "value": {
                      "type": "string",
                      "maxLength": 100
                    },
                    "label": {
                      "type": "string",
                      "maxLength": 100
                    }
                  },
                  "required": [
                    "value",
                    "label"
                  ],
                  "additionalProperties": false
                }
              }
            },
            "required": [
              "key",
              "label",
              "type"
            ],
            "additionalProperties": false
          }
        },
        "defaults": {
          "default": {},
          "type": "object",
          "propertyNames": {
            "type": "string"
          },
          "additionalProperties": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "boolean"
              },
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          }
        }
      },
      "required": [
        "schema"
      ],
      "additionalProperties": false
    },
    "secrets": {
      "default": [],
      "maxItems": 50,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "pattern": "^[A-Z][A-Z0-9_]{0,63}$"
          },
          "purpose": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "optional": {
            "type": "boolean"
          }
        },
        "required": [
          "name",
          "purpose"
        ],
        "additionalProperties": false
      }
    },
    "bindings": {
      "default": [],
      "maxItems": 10,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "product": {
            "type": "string",
            "enum": [
              "basalt",
              "lithic",
              "tecto",
              "caldera"
            ]
          },
          "role": {
            "type": "string",
            "enum": [
              "member",
              "guest"
            ]
          },
          "scopes": {
            "minItems": 1,
            "maxItems": 4,
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "content:read",
                "content:write",
                "admin:read",
                "admin:write"
              ]
            }
          }
        },
        "required": [
          "product",
          "role",
          "scopes"
        ],
        "additionalProperties": false
      }
    },
    "state": {
      "default": [],
      "maxItems": 50,
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "health": {
      "type": "object",
      "properties": {
        "command": {
          "minItems": 1,
          "maxItems": 50,
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 500
          }
        },
        "timeout_seconds": {
          "type": "integer",
          "minimum": 1,
          "maximum": 600
        }
      },
      "required": [
        "command"
      ],
      "additionalProperties": false
    },
    "status": {
      "type": "string"
    },
    "controls": {
      "maxItems": 3,
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "pause",
          "resume",
          "run_now"
        ]
      }
    },
    "logs": {
      "default": [],
      "maxItems": 50,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 190
          },
          "path": {
            "type": "string"
          }
        },
        "required": [
          "name",
          "path"
        ],
        "additionalProperties": false
      }
    },
    "account": {
      "type": "boolean"
    }
  },
  "required": [
    "name",
    "version",
    "description",
    "runtime"
  ],
  "additionalProperties": false,
  "title": "caldera.agent.yaml",
  "description": "The manifest of a Caldera agent blueprint (ADR-0044)."
}
