{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://raw.githubusercontent.com/tofutools/tclaude/main/docs/pwf/schema/v0.1/workflow.schema.json",
  "title": "PWF workflow.json",
  "description": "Everything but title, summary, author and licence is derived from the templates; readers recompute it and refuse a mismatch.",
  "type": "object",
  "required": ["title", "root", "templates", "params", "roles", "programs", "assignees", "humans"],
  "additionalProperties": false,
  "properties": {
    "title": {"type": "string", "minLength": 1, "maxLength": 200},
    "summary": {"type": "string", "maxLength": 2000},
    "author": {"type": "string", "maxLength": 200},
    "licence": {"type": "string", "maxLength": 200},
    "root": {"$ref": "manifest.schema.json#/$defs/ref"},
    "templates": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": ["ref", "id", "head"],
        "additionalProperties": false,
        "properties": {
          "ref": {"$ref": "manifest.schema.json#/$defs/ref"},
          "id": {"type": "string"},
          "name": {"type": "string"},
          "head": {"type": "boolean"}
        }
      }
    },
    "params": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["name", "type", "required"],
        "additionalProperties": false,
        "properties": {"name": {"type": "string"}, "type": {"type": "string"}, "required": {"type": "boolean"}, "description": {"type": "string"}}
      }
    },
    "roles": {"$ref": "#/$defs/uses"},
    "assignees": {"$ref": "#/$defs/uses"},
    "programs": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["step", "profile", "run"],
        "additionalProperties": false,
        "properties": {"step": {"type": "string"}, "profile": {"type": "string"}, "run": {"type": "string"}, "args": {"type": "array", "items": {"type": "string"}}}
      }
    },
    "humans": {"type": "array", "items": {"type": "string"}},
    "loops": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["step", "outcome", "to", "maxIterations"],
        "additionalProperties": false,
        "properties": {
          "step": {"type": "string"},
          "outcome": {"type": "string"},
          "to": {"type": "string"},
          "maxIterations": {"type": "integer", "minimum": 2, "maximum": 100},
          "onExhausted": {"type": "string"}
        }
      }
    }
  },
  "$defs": {
    "uses": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["name", "steps"],
        "additionalProperties": false,
        "properties": {"name": {"type": "string"}, "steps": {"type": "array", "items": {"type": "string"}}}
      }
    }
  }
}
