{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://raw.githubusercontent.com/tofutools/tclaude/main/docs/paf/schema/v0.1/manifest.schema.json",
  "title": "PAF manifest.json",
  "type": "object",
  "required": [
    "format",
    "paf_version",
    "kind",
    "created_at",
    "producer",
    "agents",
    "entries"
  ],
  "properties": {
    "format": {
      "const": "paf"
    },
    "paf_version": {
      "type": "string",
      "pattern": "^0\\.(0|[1-9][0-9]*)$",
      "description": "The version the file was written as. A 0.x reader reads every 0.y: minor versions only add."
    },
    "min_reader_version": {
      "type": "string",
      "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$",
      "description": "Set only by a writer that deliberately breaks compatibility: the oldest PAF version whose reader can import the file. An older reader refuses to import it and inspects it best effort."
    },
    "kind": {
      "enum": [
        "agent",
        "group",
        "bundle"
      ]
    },
    "created_at": {
      "$ref": "common.schema.json#/$defs/timestamp"
    },
    "producer": {
      "type": "object",
      "required": [
        "name"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1
        },
        "version": {
          "type": "string"
        }
      }
    },
    "requires": {
      "type": "array",
      "uniqueItems": true,
      "items": {
        "type": "string",
        "pattern": "^[a-z0-9][a-z0-9.-]*$"
      }
    },
    "agents": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "$ref": "common.schema.json#/$defs/agentKey"
      }
    },
    "workflows": {
      "type": "array",
      "description": "PAF 0.2: workflows carried beside the agents, each under workflows/<key>/ in PWF's layout.",
      "items": {
        "type": "object",
        "required": [
          "key",
          "root",
          "requires",
          "digest"
        ],
        "properties": {
          "key": {
            "$ref": "common.schema.json#/$defs/agentKey"
          },
          "root": {
            "type": "string",
            "minLength": 1
          },
          "requires": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "digest": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          }
        }
      }
    },
    "links": {
      "type": "array",
      "description": "PAF 0.2: references between agents and workflows, by key and by hash.",
      "items": {
        "type": "object",
        "required": [
          "type",
          "workflow",
          "agent",
          "digest"
        ],
        "properties": {
          "type": {
            "type": "string",
            "minLength": 1
          },
          "workflow": {
            "$ref": "common.schema.json#/$defs/agentKey"
          },
          "agent": {
            "$ref": "common.schema.json#/$defs/agentKey"
          },
          "role": {
            "type": "string",
            "minLength": 1
          },
          "digest": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          }
        }
      }
    },
    "entries": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "path",
          "bytes",
          "sha256"
        ],
        "properties": {
          "path": {
            "$ref": "common.schema.json#/$defs/entryPath"
          },
          "bytes": {
            "type": "integer",
            "minimum": 0
          },
          "sha256": {
            "$ref": "common.schema.json#/$defs/sha256"
          },
          "media_type": {
            "type": "string"
          },
          "extensions": {
            "$ref": "common.schema.json#/$defs/extensions"
          }
        }
      }
    },
    "extensions_required": {
      "type": "array",
      "uniqueItems": true,
      "items": {
        "$ref": "common.schema.json#/$defs/extensionId"
      }
    },
    "extensions_used": {
      "type": "object",
      "propertyNames": {
        "$ref": "common.schema.json#/$defs/extensionId"
      },
      "additionalProperties": {
        "type": "object",
        "required": [
          "version",
          "system",
          "spec"
        ],
        "properties": {
          "version": {
            "type": "string",
            "pattern": "^[0-9]+\\.[0-9]+$"
          },
          "system": {
            "type": "string",
            "minLength": 1
          },
          "system_version": {
            "type": "string"
          },
          "spec": {
            "type": "string",
            "minLength": 1
          },
          "schema": {
            "type": "string"
          },
          "copy": {
            "type": "string",
            "description": "Open set; unknown values mean unsafe. Known: safe, unsafe (default)."
          }
        }
      }
    },
    "extensions": {
      "$ref": "common.schema.json#/$defs/extensions"
    }
  },
  "if": {
    "properties": {
      "kind": {
        "const": "agent"
      }
    }
  },
  "then": {
    "properties": {
      "agents": {
        "maxItems": 1
      }
    }
  }
}
