{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:pounceagent:agent-file:1",
  "title": "PounceAgent agent recipe version 1",
  "description": "A declarative recipe. Validation never grants permission or starts an agent.",
  "type": "object",
  "additionalProperties": false,
  "required": ["format", "version", "name", "description", "template", "sources", "places", "schedule", "output_format", "engine", "abilities", "created_with"],
  "properties": {
    "format": {"const": "pounceagent.agent"},
    "version": {"const": 1},
    "name": {"type": "string", "minLength": 1, "maxLength": 120},
    "description": {"type": "string", "minLength": 1, "maxLength": 4000},
    "template": {
      "enum": ["news-digest", "daily-pdf", "weather", "family-checkin", "trip-weather", "site-watcher", "game-maker", "diagram-maker"]
    },
    "sources": {
      "type": "array", "maxItems": 100, "uniqueItems": true,
      "items": {
        "oneOf": [
          {"type": "string", "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$", "maxLength": 100},
          {"type": "object", "additionalProperties": false, "required": ["url", "name"],
           "properties": {
             "url": {"$ref": "#/$defs/sourceUrl"},
             "name": {"type": "string", "minLength": 1, "maxLength": 120}
           }}
        ]
      }
    },
    "places": {
      "type": "array", "maxItems": 50, "uniqueItems": true,
      "items": {
        "type": "object", "additionalProperties": false, "required": ["label"],
        "properties": {
          "label": {"type": "string", "minLength": 1, "maxLength": 120},
          "zip": {"type": "string", "pattern": "^[0-9]{5}(?:-[0-9]{4})?$"},
          "city": {"type": "string", "minLength": 1, "maxLength": 200}
        },
        "oneOf": [{"required": ["zip"]}, {"required": ["city"]}]
      }
    },
    "schedule": {"$ref": "#/$defs/schedule"},
    "output_format": {"enum": ["message", "picture", "pdf"]},
    "engine": {"enum": ["any", "api", "claude-code", "codex"]},
    "abilities": {
      "type": "array", "maxItems": 8, "uniqueItems": true,
      "items": {"enum": ["read-feeds", "read-pages", "web-search", "read-weather", "make-files", "make-pictures", "make-diagrams", "make-games"]}
    },
    "created_with": {"type": "string", "minLength": 1, "maxLength": 120}
  },
  "allOf": [
    {"if": {"properties": {"output_format": {"enum": ["picture", "pdf"]}}},
     "then": {"properties": {"abilities": {"contains": {"const": "make-files"}}}}},
    {"if": {"properties": {"template": {"const": "daily-pdf"}}},
     "then": {"properties": {"output_format": {"const": "pdf"}}}},
    {"if": {"properties": {"template": {"const": "game-maker"}}},
     "then": {"properties": {"abilities": {"allOf": [{"contains": {"const": "make-files"}}, {"contains": {"const": "make-games"}}]}}}},
    {"if": {"properties": {"template": {"const": "diagram-maker"}}},
     "then": {"properties": {"abilities": {"allOf": [{"contains": {"const": "make-files"}}, {"contains": {"const": "make-diagrams"}}]}}}}
  ],
  "$defs": {
    "sourceUrl": {
      "type": "string", "format": "uri", "maxLength": 2048,
      "pattern": "^https://[^\\s/@?#:]+(?::443)?(?:[/?][^\\s#]*)?$",
      "description": "HTTPS only, no userinfo or fragment. Importer must additionally enforce public destinations and reject credentials, templates, and private network targets."
    },
    "schedule": {
      "type": "object", "additionalProperties": false, "required": ["preset"],
      "properties": {
        "preset": {"enum": ["every-morning", "weekdays", "every-evening", "weekly", "hourly", "once", "on-request"]},
        "time": {"type": "string", "pattern": "^(?:[01][0-9]|2[0-3]):[0-5][0-9]$"},
        "days": {"type": "array", "minItems": 1, "maxItems": 7, "uniqueItems": true,
                 "items": {"enum": ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]}},
        "date": {"type": "string", "format": "date", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"}
      },
      "allOf": [
        {"if": {"properties": {"preset": {"enum": ["every-morning", "weekdays", "every-evening", "weekly", "once"]}}},
         "then": {"required": ["time"]},
         "else": {"not": {"required": ["time"]}}},
        {"if": {"properties": {"preset": {"const": "weekly"}}},
         "then": {"required": ["days"]},
         "else": {"not": {"required": ["days"]}}},
        {"if": {"properties": {"preset": {"const": "once"}}},
         "then": {"required": ["date"]},
         "else": {"not": {"required": ["date"]}}}
      ]
    }
  }
}
