{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://picorunner.com/schemas/picorunner-manifest-v1.json",
  "title": "PicoRunner manifest v1",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema", "name", "runtime", "launch"],
  "properties": {
    "schema": { "const": 1 },
    "name": { "type": "string", "minLength": 1, "maxLength": 120 },
    "runtime": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "version"],
      "properties": {
        "kind": { "enum": ["node", "python"] },
        "version": { "type": "string", "minLength": 1, "maxLength": 80 },
        "package_manager": { "enum": ["npm", "pnpm", "yarn", "uv"] },
        "workspace": { "$ref": "#/$defs/relativePath", "default": "." }
      }
    },
    "setup": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "steps": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "kind": { "const": "dependencies" },
              "run": { "$ref": "#/$defs/command" },
              "working_directory": { "$ref": "#/$defs/relativePath", "default": "." },
              "locked": { "type": "boolean", "default": false },
              "when": { "const": "install-or-update", "default": "install-or-update" }
            },
            "oneOf": [
              { "required": ["kind"], "not": { "required": ["run"] } },
              { "required": ["run"], "not": { "required": ["kind"] } }
            ]
          }
        }
      }
    },
    "launch": {
      "type": "object",
      "additionalProperties": false,
      "required": ["command", "port"],
      "properties": {
        "command": { "$ref": "#/$defs/command" },
        "working_directory": { "$ref": "#/$defs/relativePath", "default": "." },
        "host": { "const": "127.0.0.1", "default": "127.0.0.1" },
        "host_env": { "$ref": "#/$defs/environmentName" },
        "port": { "type": "integer", "minimum": 1, "maximum": 65535 },
        "port_env": { "$ref": "#/$defs/environmentName", "default": "PORT" },
        "environment": {
          "type": "object",
          "propertyNames": { "$ref": "#/$defs/environmentName" },
          "additionalProperties": { "type": "string", "maxLength": 4096 }
        }
      }
    },
    "health": {
      "type": "object",
      "additionalProperties": false,
      "required": ["type"],
      "properties": {
        "type": { "enum": ["tcp", "http"] },
        "path": { "type": "string", "pattern": "^/(?!/)", "default": "/" },
        "timeout_seconds": { "type": "integer", "minimum": 1, "maximum": 3600, "default": 90 }
      }
    },
    "persistence": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "paths": { "type": "array", "uniqueItems": true, "items": { "$ref": "#/$defs/relativePath" } }
      }
    },
    "inputs": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["name", "kind"],
        "properties": {
          "name": { "$ref": "#/$defs/environmentName" },
          "kind": { "enum": ["configuration", "secret"] },
          "required": { "type": "boolean", "default": false },
          "description": { "type": "string", "maxLength": 500 }
        }
      }
    }
  },
  "$defs": {
    "command": {
      "type": "array",
      "minItems": 1,
      "maxItems": 64,
      "items": { "type": "string", "minLength": 1, "maxLength": 4096 }
    },
    "environmentName": { "type": "string", "pattern": "^[A-Z_][A-Z0-9_]{0,127}$" },
    "relativePath": { "type": "string", "minLength": 1, "not": { "pattern": "(^/|(^|/)\\.\\.(/|$))" } }
  }
}
