{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://agentmug.com/schemas/agent.v2.json",
  "title": "AgentMug Agent File v2",
  "description": "AgentMug v1 plus explicit quarantined executable capability capsules. The capsule is portable evidence, never execution authority.",
  "type": "object",
  "required": [
    "$schema",
    "id",
    "name",
    "description",
    "version",
    "exportedAt",
    "blueprint",
    "inputs",
    "capabilityCapsules"
  ],
  "additionalProperties": true,
  "properties": {
    "$schema": {
      "const": "https://agentmug.com/schemas/agent.v2.json",
      "description": "Mandatory v2 marker. A v1-only host must reject this file before interpreting any other member."
    },
    "id": {
      "$ref": "https://agentmug.com/schemas/agent.v1.json#/properties/id"
    },
    "name": {
      "$ref": "https://agentmug.com/schemas/agent.v1.json#/properties/name"
    },
    "description": {
      "$ref": "https://agentmug.com/schemas/agent.v1.json#/properties/description"
    },
    "emoji": {
      "$ref": "https://agentmug.com/schemas/agent.v1.json#/properties/emoji"
    },
    "version": {
      "$ref": "https://agentmug.com/schemas/agent.v1.json#/properties/version"
    },
    "exportedAt": {
      "$ref": "https://agentmug.com/schemas/agent.v1.json#/properties/exportedAt"
    },
    "execution": {
      "$ref": "https://agentmug.com/schemas/agent.v1.json#/properties/execution"
    },
    "blueprint": {
      "$ref": "https://agentmug.com/schemas/agent.v1.json#/properties/blueprint"
    },
    "parameters": {
      "$ref": "https://agentmug.com/schemas/agent.v1.json#/properties/parameters"
    },
    "inputs": {
      "$ref": "https://agentmug.com/schemas/agent.v1.json#/properties/inputs"
    },
    "outputs": {
      "$ref": "https://agentmug.com/schemas/agent.v1.json#/properties/outputs"
    },
    "triggers": {
      "$ref": "https://agentmug.com/schemas/agent.v1.json#/properties/triggers"
    },
    "connectivity": {
      "$ref": "https://agentmug.com/schemas/agent.v1.json#/properties/connectivity"
    },
    "sources": {
      "$ref": "https://agentmug.com/schemas/agent.v1.json#/properties/sources"
    },
    "evaluation": {
      "$ref": "https://agentmug.com/schemas/agent.v1.json#/properties/evaluation"
    },
    "metadata": {
      "$ref": "https://agentmug.com/schemas/agent.v1.json#/properties/metadata"
    },
    "brain": {
      "$ref": "https://agentmug.com/schemas/agent.v1.json#/properties/brain"
    },
    "memory": {
      "$ref": "https://agentmug.com/schemas/agent.v1.json#/properties/memory"
    },
    "capabilityCapsules": {
      "type": "array",
      "minItems": 1,
      "maxItems": 60,
      "description": "Digest-pinned executable artifacts and redacted proof. Every receiving host quarantines these until it establishes local trust and an isolated no-network sandbox.",
      "items": {
        "type": "object",
        "required": ["version", "name", "proof", "artifact"],
        "additionalProperties": false,
        "properties": {
          "version": { "const": 1 },
          "name": { "type": "string", "minLength": 1, "maxLength": 100 },
          "proof": {
            "type": "object",
            "required": [
              "version",
              "receiptId",
              "status",
              "capabilityKind",
              "harnessId",
              "sandboxId",
              "contractMatched",
              "criteriaPassed",
              "criteriaTotal",
              "judgeId",
              "judgeModel",
              "verifiedAt",
              "artifactDigest",
              "reusableInputVerified"
            ],
            "additionalProperties": false,
            "properties": {
              "version": { "const": 2 },
              "receiptId": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128
              },
              "status": { "const": "passed" },
              "capabilityKind": {
                "type": "string",
                "minLength": 1,
                "maxLength": 64
              },
              "harnessId": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128
              },
              "sandboxId": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128
              },
              "contractMatched": { "const": true },
              "criteriaPassed": { "type": "integer", "minimum": 1 },
              "criteriaTotal": { "type": "integer", "minimum": 1 },
              "judgeId": { "type": "string", "minLength": 1, "maxLength": 128 },
              "judgeModel": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128
              },
              "verifiedAt": { "type": "string", "format": "date-time" },
              "artifactDigest": {
                "type": "string",
                "pattern": "^sha256:[a-f0-9]{64}$"
              },
              "reusableInputVerified": { "const": true }
            }
          },
          "artifact": {
            "type": "object",
            "required": [
              "version",
              "kind",
              "language",
              "entrypoint",
              "policy",
              "source",
              "digest",
              "contract",
              "permissions"
            ],
            "additionalProperties": false,
            "properties": {
              "version": { "const": 1 },
              "kind": { "const": "portable_python_v1" },
              "language": { "const": "python" },
              "entrypoint": { "const": "run" },
              "policy": { "const": "deterministic-transform-v1" },
              "source": {
                "type": "string",
                "minLength": 1,
                "maxLength": 12000
              },
              "digest": {
                "type": "string",
                "pattern": "^sha256:[a-f0-9]{64}$"
              },
              "contract": {
                "type": "object",
                "required": ["inputSchema", "outputSchema"],
                "additionalProperties": false,
                "properties": {
                  "inputSchema": { "type": "object" },
                  "outputSchema": { "type": "object" }
                }
              },
              "permissions": {
                "type": "object",
                "required": ["network", "secrets", "filesystemWrites"],
                "additionalProperties": false,
                "properties": {
                  "network": { "const": false },
                  "secrets": { "type": "array", "maxItems": 0 },
                  "filesystemWrites": { "const": false }
                }
              }
            }
          }
        }
      }
    }
  }
}
