{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://miruntime.com/downloads/miruntime-tool-contract.schema.json",
  "title": "MiRuntime Conceptual Tool Contract",
  "description": "Editorial reference schema for a runtime-governed tool. Protocol discovery is not authorization.",
  "type": "object",
  "additionalProperties": false,
  "required": ["name", "version", "description", "permissionClass", "inputSchema", "outputSchema", "sideEffects", "execution", "evidence"],
  "properties": {
    "name": { "type": "string", "pattern": "^[a-z][a-z0-9_.-]{1,127}$" },
    "version": { "type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$" },
    "description": { "type": "string", "minLength": 1, "maxLength": 2000 },
    "permissionClass": { "type": "string", "enum": ["read-only", "draft", "reversible-write", "irreversible-write"] },
    "inputSchema": { "type": "object" },
    "outputSchema": { "type": "object" },
    "sideEffects": {
      "type": "object",
      "additionalProperties": false,
      "required": ["changesExternalState", "description"],
      "properties": {
        "changesExternalState": { "type": "boolean" },
        "description": { "type": "string" },
        "reversible": { "type": "boolean" },
        "compensationTool": { "type": ["string", "null"] }
      }
    },
    "authorization": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "allowedSubjects": { "type": "array", "items": { "type": "string" } },
        "requiredApprovals": { "type": "array", "items": { "type": "string" } },
        "credentialAudience": { "type": "string" },
        "credentialTtlSeconds": { "type": "integer", "minimum": 1 },
        "allowedResources": { "type": "array", "items": { "type": "string" } },
        "allowedEgress": { "type": "array", "items": { "type": "string" } }
      }
    },
    "execution": {
      "type": "object",
      "additionalProperties": false,
      "required": ["timeoutSeconds", "idempotency", "isolation"],
      "properties": {
        "timeoutSeconds": { "type": "integer", "minimum": 1 },
        "idempotency": { "type": "string", "enum": ["required", "supported", "not-applicable"] },
        "isolation": { "type": "string", "enum": ["in-process", "container", "sandbox", "microvm", "external-service"] },
        "retryPolicy": { "type": "string" },
        "checkpointBeforeExecution": { "type": "boolean" },
        "rateLimit": { "type": "string" }
      }
    },
    "evidence": {
      "type": "object",
      "additionalProperties": false,
      "required": ["requiredEvents", "sensitiveFields"],
      "properties": {
        "requiredEvents": { "type": "array", "items": { "type": "string" } },
        "sensitiveFields": { "type": "array", "items": { "type": "string" } },
        "artifactTypes": { "type": "array", "items": { "type": "string" } }
      }
    }
  }
}
