{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://claudetohost.com/schemas/claudetohost-v1.schema.json",
  "title": "ClaudeToHost manifest v1",
  "description": "Package contract for an HTTP service or long-running worker. Static sites do not need a manifest.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "version",
    "type",
    "runtime",
    "command"
  ],
  "properties": {
    "version": {
      "const": 1
    },
    "type": {
      "enum": [
        "web",
        "worker"
      ]
    },
    "runtime": {
      "enum": [
        "node",
        "python",
        "docker"
      ]
    },
    "command": {
      "description": "Exec-form process command. Shell strings are not accepted.",
      "type": "array",
      "minItems": 1,
      "maxItems": 32,
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 512
      }
    },
    "port": {
      "type": "integer",
      "minimum": 1024,
      "maximum": 65535
    },
    "health": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "path"
      ],
      "properties": {
        "path": {
          "type": "string",
          "pattern": "^/(?:[^\\s?#]*)?$",
          "maxLength": 256
        }
      }
    },
    "env": {
      "description": "Environment variable names only. Values are supplied separately as secrets.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "required": {
          "$ref": "#/$defs/envNames"
        },
        "optional": {
          "$ref": "#/$defs/envNames"
        }
      }
    },
    "resources": {
      "description": "Requested runtime ceiling. The platform maps it to the smallest supported size that satisfies both values.",
      "type": "object",
      "additionalProperties": false,
      "required": [
        "cpu",
        "memory"
      ],
      "properties": {
        "cpu": {
          "enum": [
            "250m",
            "500m",
            "1000m",
            "2000m"
          ]
        },
        "memory": {
          "enum": [
            "256Mi",
            "384Mi",
            "512Mi",
            "768Mi",
            "1Gi",
            "1536Mi"
          ]
        }
      }
    }
  },
  "$defs": {
    "envNames": {
      "type": "array",
      "maxItems": 64,
      "uniqueItems": true,
      "items": {
        "type": "string",
        "pattern": "^[A-Z_][A-Z0-9_]*$",
        "maxLength": 128
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "type": {
            "const": "web"
          }
        },
        "required": [
          "type"
        ]
      },
      "then": {
        "properties": {
          "port": true,
          "health": true
        },
        "required": [
          "port",
          "health"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "worker"
          }
        },
        "required": [
          "type"
        ]
      },
      "then": {
        "not": {
          "anyOf": [
            {
              "properties": {
                "port": true
              },
              "required": [
                "port"
              ]
            },
            {
              "properties": {
                "health": true
              },
              "required": [
                "health"
              ]
            }
          ]
        }
      }
    }
  ]
}
