{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://agentfriendlyweb.dev/schemas/publication-capsule.v1.json",
  "title": "Agent Friendly Web Publication Capsule v1",
  "description": "Immutable manual handoff package. It does not authorize or perform remote writes.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "contract",
    "capsuleId",
    "version",
    "mode",
    "status",
    "createdAt",
    "expiresAt",
    "target",
    "organization",
    "files",
    "unsupportedResources",
    "approvals",
    "checksums",
    "manifest",
    "integrity",
    "idempotencyKey",
    "limits"
  ],
  "properties": {
    "contract": { "const": "agentfriendly.publication-capsule.v1" },
    "capsuleId": { "type": "string", "minLength": 1, "maxLength": 120 },
    "version": { "type": "integer", "minimum": 1 },
    "mode": { "enum": ["manual_handoff"] },
    "status": {
      "enum": [
        "owner_approval_pending",
        "maintainer_approval_pending",
        "approved_for_manual_handoff",
        "rejected",
        "expired",
        "superseded"
      ]
    },
    "createdAt": { "type": "string", "format": "date-time" },
    "expiresAt": { "type": "string", "format": "date-time" },
    "target": {
      "type": "object",
      "additionalProperties": false,
      "required": ["origin", "hostname"],
      "properties": {
        "origin": { "type": "string", "format": "uri", "pattern": "^https://" },
        "hostname": { "type": "string", "minLength": 1, "maxLength": 253 }
      }
    },
    "organization": { "type": "string", "minLength": 1, "maxLength": 200 },
    "files": {
      "type": "array",
      "minItems": 1,
      "maxItems": 5,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["packagePath", "destinationPath", "operation", "mediaType", "bytes", "sha256", "content"],
        "properties": {
          "packagePath": { "type": "string", "pattern": "^(files|proposals)/[a-z0-9][a-z0-9._-]{0,119}$" },
          "destinationPath": { "enum": ["/", "/llms.txt", "/llms-full.txt", "/robots.txt", "/sitemap.xml"] },
          "operation": { "enum": ["create_or_replace", "manual_merge", "manual_embed"] },
          "mediaType": { "type": "string", "minLength": 1, "maxLength": 100 },
          "bytes": { "type": "integer", "minimum": 1, "maximum": 131072 },
          "sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
          "content": { "type": "string", "minLength": 1, "maxLength": 131072 }
        }
      }
    },
    "unsupportedResources": { "type": "array", "maxItems": 3, "items": { "type": "object" } },
    "approvals": {
      "type": "object",
      "required": ["requiredRoles", "owner", "maintainer"],
      "properties": {
        "requiredRoles": { "type": "array", "items": { "enum": ["owner", "maintainer"] }, "uniqueItems": true },
        "owner": { "enum": ["pending", "approved", "rejected"] },
        "maintainer": { "enum": ["not_required", "pending", "approved", "rejected"] }
      }
    },
    "checksums": { "type": "string", "minLength": 1 },
    "manifest": { "type": "object" },
    "integrity": {
      "type": "object",
      "required": ["algorithm", "manifestSha256", "checksumsSha256", "signature"],
      "properties": {
        "algorithm": { "const": "sha256" },
        "manifestSha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
        "checksumsSha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
        "signature": { "type": "null" }
      }
    },
    "idempotencyKey": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "limits": { "type": "array", "minItems": 1, "maxItems": 12, "items": { "type": "string" } }
  }
}
