{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://fernandovergara.com/escala-vergara/autonomy-statement.schema.json",
  "title": "VAAS Autonomy Statement",
  "description": "Machine-readable Autonomy Statement for the Vergara Agentic Autonomy Scale (VAAS) v1.0. Ten required fields; a statement missing any of them does not support a level claim. Spec: https://fernandovergara.com/escala-vergara",
  "type": "object",
  "required": [
    "scale",
    "product",
    "statementVersion",
    "date",
    "maxLevelOffered",
    "vendorReservedLevels",
    "defaultLevel",
    "whoMayChange",
    "riskCriteria",
    "actionCatalogue",
    "invariantCeiling",
    "undoWindowDays",
    "auditRecord",
    "gates",
    "descent",
    "conformsToProperties"
  ],
  "additionalProperties": true,
  "properties": {
    "scale": {
      "const": "VAAS-1.0",
      "description": "Scale and version this statement is written against."
    },
    "product": {
      "type": "object",
      "required": ["name", "agentName", "url"],
      "properties": {
        "name": { "type": "string" },
        "agentName": { "type": "string" },
        "url": { "type": "string", "format": "uri" }
      }
    },
    "statementVersion": { "type": "string" },
    "date": { "type": "string", "format": "date" },

    "maxLevelOffered": { "$ref": "#/$defs/level" },
    "vendorReservedLevels": {
      "type": "array",
      "items": { "$ref": "#/$defs/level" },
      "description": "Levels the customer cannot self-serve. Must be visibly marked as such in the UI (P6)."
    },
    "defaultLevel": {
      "const": 0,
      "description": "P4 requires V0 on provisioning."
    },
    "whoMayChange": {
      "type": "object",
      "required": ["roles", "vendorMayChangeUnilaterally"],
      "properties": {
        "roles": { "type": "array", "items": { "type": "string" }, "minItems": 1 },
        "vendorMayChangeUnilaterally": { "type": "boolean" },
        "notes": { "type": "string" }
      }
    },

    "riskCriteria": {
      "type": "object",
      "required": ["low", "medium", "high", "uncataloguedAction"],
      "properties": {
        "low": { "type": "string" },
        "medium": { "type": "string" },
        "high": { "type": "string" },
        "uncataloguedAction": {
          "const": "high",
          "description": "P4: fail-closed classification."
        }
      }
    },

    "actionCatalogue": {
      "type": "array",
      "minItems": 1,
      "description": "Every write action the agent can perform. The field that gives the level meaning.",
      "items": {
        "type": "object",
        "required": ["action", "risk", "reversible"],
        "properties": {
          "action": { "type": "string" },
          "risk": { "enum": ["low", "medium", "high"] },
          "reversible": { "enum": ["yes", "with-effort", "no"] },
          "undoMechanism": { "type": "string" },
          "notes": { "type": "string" }
        },
        "allOf": [
          {
            "if": { "properties": { "risk": { "const": "low" } }, "required": ["risk"] },
            "then": {
              "properties": { "reversible": { "const": "yes" } },
              "description": "P3: an action that cannot describe its own reversal cannot be classified low."
            }
          }
        ]
      }
    },

    "invariantCeiling": {
      "type": "array",
      "minItems": 1,
      "description": "P2: actions requiring a human at EVERY level, including the highest. Must be non-empty.",
      "items": {
        "type": "object",
        "required": ["action", "reason"],
        "properties": {
          "action": { "type": "string" },
          "reason": { "type": "string" }
        }
      }
    },

    "undoWindowDays": {
      "type": "integer",
      "minimum": 1,
      "description": "P3: window during which an autonomously executed action can be reversed."
    },
    "irreversibleActions": {
      "type": "array",
      "items": { "type": "string" },
      "description": "Actions explicitly declared as not covered by the undo window."
    },

    "auditRecord": {
      "type": "object",
      "required": ["fields", "location", "retention", "readableBy"],
      "properties": {
        "fields": { "type": "array", "items": { "type": "string" }, "minItems": 1 },
        "location": { "type": "string" },
        "retention": { "type": "string" },
        "readableBy": { "type": "array", "items": { "type": "string" } }
      }
    },

    "gates": {
      "type": "object",
      "required": ["locations", "classificationTest"],
      "description": "P7: gates live in code, under regression test — not in a prompt.",
      "properties": {
        "locations": { "type": "array", "items": { "type": "string" }, "minItems": 1 },
        "classificationTest": { "type": "string" },
        "ladderVsGatesTest": {
          "type": "string",
          "description": "P6: test asserting this document against the same constants the gates use."
        }
      }
    },

    "descent": {
      "type": "object",
      "required": ["latency", "workInFlight", "killSwitch"],
      "properties": {
        "latency": { "type": "string", "description": "P5: lowering a level must bind immediately." },
        "workInFlight": { "type": "string" },
        "killSwitch": { "type": "string" }
      }
    },

    "conformsToProperties": {
      "type": "array",
      "description": "Properties the product claims to satisfy. All seven are required for a conformance claim.",
      "items": { "enum": ["P1", "P2", "P3", "P4", "P5", "P6", "P7"] },
      "uniqueItems": true
    },

    "deployedDistribution": {
      "type": "object",
      "description": "Optional but recommended: how many customers actually run at each level.",
      "additionalProperties": { "type": "integer", "minimum": 0 }
    }
  },

  "$defs": {
    "level": {
      "type": "integer",
      "minimum": 0,
      "maximum": 5,
      "description": "V0 Responder · V1 Briefer · V2 Proposer · V3 Bounded executor · V4 Mission manager · V5 Orchestrator"
    }
  }
}
