{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://dangirsh.org/swarm-science/protocol.schema.json",
  "title": "Contributed Agent Coordination Protocol v0.3 task manifest",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "protocol_version",
    "project",
    "tasks"
  ],
  "properties": {
    "protocol_version": {
      "const": "0.3.0"
    },
    "project": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "name",
        "purpose",
        "visibility",
        "owner",
        "coordinator"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^prj_[A-Za-z0-9_-]+$",
          "maxLength": 80
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "purpose": {
          "type": "string",
          "minLength": 1,
          "maxLength": 1200
        },
        "visibility": {
          "const": "private"
        },
        "owner": {
          "$ref": "#/$defs/principal"
        },
        "coordinator": {
          "$ref": "#/$defs/coordinator"
        }
      }
    },
    "tasks": {
      "type": "array",
      "maxItems": 5000,
      "items": {
        "$ref": "#/$defs/task"
      }
    },
    "allowance_defaults": {
      "$ref": "#/$defs/allowance"
    }
  },
  "$defs": {
    "principal": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "display_name"
      ],
      "properties": {
        "id": {
          "type": "string",
          "maxLength": 80
        },
        "display_name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "revocable": {
          "type": "boolean"
        }
      }
    },
    "coordinator": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "display_name",
        "revocable",
        "owner_bound",
        "heartbeat_ttl_seconds"
      ],
      "properties": {
        "id": {
          "type": "string",
          "maxLength": 80
        },
        "display_name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "revocable": {
          "const": true
        },
        "owner_bound": {
          "const": true
        },
        "heartbeat_ttl_seconds": {
          "type": "integer",
          "minimum": 60
        }
      }
    },
    "capabilities": {
      "type": "array",
      "maxItems": 24,
      "uniqueItems": true,
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 80
      }
    },
    "task": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "title",
        "description",
        "depends_on",
        "required_capabilities",
        "prohibited_capabilities",
        "risk",
        "estimated_credits",
        "priority",
        "acceptance",
        "artifact_types"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 80
        },
        "title": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160
        },
        "description": {
          "type": "string",
          "minLength": 1,
          "maxLength": 4000
        },
        "depends_on": {
          "type": "array",
          "maxItems": 24,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          }
        },
        "required_capabilities": {
          "$ref": "#/$defs/capabilities"
        },
        "prohibited_capabilities": {
          "$ref": "#/$defs/capabilities"
        },
        "risk": {
          "enum": [
            "low",
            "medium",
            "high"
          ]
        },
        "estimated_credits": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000000
        },
        "priority": {
          "type": "integer",
          "minimum": 0,
          "maximum": 100
        },
        "acceptance": {
          "type": "array",
          "maxItems": 16,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          }
        },
        "artifact_types": {
          "type": "array",
          "minItems": 1,
          "maxItems": 12,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          }
        },
        "extensions": {
          "type": "object",
          "propertyNames": {
            "pattern": "^[a-z0-9.-]+/v[0-9]+$"
          }
        }
      }
    },
    "allowance": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "unit",
        "window",
        "cap_pct",
        "reserve_pct"
      ],
      "properties": {
        "unit": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]{0,79}$"
        },
        "window": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]{0,79}$"
        },
        "cap_pct": {
          "type": "number",
          "minimum": 1,
          "maximum": 50
        },
        "reserve_pct": {
          "type": "number",
          "minimum": 5,
          "maximum": 90
        }
      }
    },
    "authorization": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "version",
        "project_id",
        "cap_pct",
        "reserve_pct",
        "max_risk",
        "tool_namespace",
        "boundary_sha256",
        "granted_at"
      ],
      "properties": {
        "version": {
          "const": "0.3.0"
        },
        "project_id": {
          "type": "string",
          "pattern": "^prj_[A-Za-z0-9_-]+$",
          "maxLength": 80
        },
        "cap_pct": {
          "type": "number",
          "minimum": 1,
          "maximum": 50
        },
        "reserve_pct": {
          "type": "number",
          "minimum": 5,
          "maximum": 90
        },
        "max_risk": {
          "enum": [
            "low",
            "medium",
            "high"
          ]
        },
        "tool_namespace": {
          "const": "mcp__swarm__"
        },
        "boundary_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "granted_at": {
          "type": "integer",
          "minimum": 1
        }
      }
    }
  }
}
