{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://concresca.com/developers/commons/work/planning/plan.schema.json",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "terms",
    "cleanupReserve",
    "operationSlots",
    "steps"
  ],
  "properties": {
    "schemaVersion": {
      "const": "concresca.work_plan.v1"
    },
    "terms": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "schemaVersion",
        "title",
        "purpose",
        "requiredCapabilities",
        "inputs",
        "deliverable",
        "checks",
        "actionScope",
        "resourceBudget",
        "value",
        "audience",
        "expiresAt",
        "retentionUntil",
        "publicationConsent"
      ],
      "properties": {
        "schemaVersion": {
          "const": "concresca.work_terms.v1"
        },
        "title": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160
        },
        "purpose": {
          "type": "string",
          "minLength": 1,
          "maxLength": 1024
        },
        "requiredCapabilities": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 96
          },
          "minItems": 0,
          "maxItems": 24
        },
        "inputs": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "uri",
              "sha256",
              "mediaType"
            ],
            "properties": {
              "uri": {
                "type": "string",
                "minLength": 1,
                "maxLength": 1024,
                "description": "HTTPS reference; hostname required; no userinfo, fragment, whitespace or backslash; explicit port 1..65535. Never fetched by the work runtime."
              },
              "sha256": {
                "type": "string",
                "pattern": "^[0-9a-f]{64}$"
              },
              "mediaType": {
                "type": "string",
                "minLength": 1,
                "maxLength": 100,
                "pattern": "^[a-z0-9!#$&^_.+-]+/[a-z0-9!#$&^_.+-]+$"
              }
            }
          },
          "minItems": 0,
          "maxItems": 8
        },
        "deliverable": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "mediaType",
            "maxBytes"
          ],
          "properties": {
            "mediaType": {
              "type": "string",
              "minLength": 1,
              "maxLength": 100,
              "pattern": "^[a-z0-9!#$&^_.+-]+/[a-z0-9!#$&^_.+-]+$"
            },
            "maxBytes": {
              "type": "integer",
              "minimum": 1,
              "maximum": 8388608
            }
          }
        },
        "checks": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "checkId",
              "description"
            ],
            "properties": {
              "checkId": {
                "type": "string",
                "minLength": 1,
                "maxLength": 64,
                "pattern": "^[a-z][a-z0-9_-]{0,63}$"
              },
              "description": {
                "type": "string",
                "minLength": 1,
                "maxLength": 1024
              }
            }
          },
          "minItems": 1,
          "maxItems": 8
        },
        "actionScope": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 256
          },
          "minItems": 1,
          "maxItems": 8,
          "uniqueItems": true
        },
        "resourceBudget": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "maxRequests",
            "maxRuntimeSeconds"
          ],
          "properties": {
            "maxRequests": {
              "type": "integer",
              "minimum": 0,
              "maximum": 10000
            },
            "maxRuntimeSeconds": {
              "type": "integer",
              "minimum": 1,
              "maximum": 86400
            }
          }
        },
        "value": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "kind",
            "description"
          ],
          "properties": {
            "kind": {
              "enum": [
                "uncompensated",
                "reciprocal"
              ]
            },
            "description": {
              "type": "string",
              "minLength": 1,
              "maxLength": 512
            }
          }
        },
        "audience": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "kind"
          ],
          "properties": {
            "kind": {
              "const": "public"
            }
          }
        },
        "expiresAt": {
          "type": "string",
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
        },
        "retentionUntil": {
          "type": "string",
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
        },
        "publicationConsent": {
          "type": "boolean",
          "description": "False preserves a draft. Preparing a request requires true; actual dispatch separately rechecks rights and authority."
        }
      }
    },
    "cleanupReserve": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "requests",
        "runtimeMilliseconds"
      ],
      "properties": {
        "requests": {
          "type": "integer",
          "minimum": 0,
          "maximum": 10000
        },
        "runtimeMilliseconds": {
          "type": "integer",
          "minimum": 1,
          "maximum": 86400000
        }
      }
    },
    "operationSlots": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "total",
        "cleanup"
      ],
      "properties": {
        "total": {
          "type": "integer",
          "minimum": 2,
          "maximum": 64
        },
        "cleanup": {
          "type": "integer",
          "minimum": 1,
          "maximum": 63
        }
      }
    },
    "steps": {
      "type": "array",
      "minItems": 2,
      "maxItems": 16,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "stepId",
          "phase",
          "attempts",
          "requestsPerAttempt",
          "maxMillisecondsPerAttempt"
        ],
        "properties": {
          "stepId": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_-]{0,31}$"
          },
          "phase": {
            "enum": [
              "discovery",
              "negotiation",
              "execution",
              "verification",
              "recovery",
              "cleanup"
            ]
          },
          "attempts": {
            "type": "integer",
            "minimum": 1,
            "maximum": 64
          },
          "requestsPerAttempt": {
            "type": "integer",
            "minimum": 0,
            "maximum": 10000
          },
          "maxMillisecondsPerAttempt": {
            "type": "integer",
            "minimum": 1,
            "maximum": 86400000
          }
        }
      }
    }
  },
  "description": "Local plan, not a wire request or a durable task ledger. Runtime semantic validation and planning constraints also apply.",
  "$comment": "At most 32 KiB; canonical terms <=12000 bytes. Unique step/check IDs, distinct ASCII case-folded capability labels, ASCII DNS HTTPS input references, cleanup slots less than total, total attempts <=64, work+cleanup both present, valid future UTC windows, per-pool request/time/slot admission, and explicit public contribution are checked by the planner. No schema pass grants authority or proof of execution."
}
