{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://humanisoffline.com/schemas/agent-request.v3.json",
  "title": "Agent Request Envelope v3",
  "oneOf": [
    {
      "title": "Encrypted envelope (API submission)",
      "type": "object",
      "additionalProperties": false,
      "required": [
        "schemaVersion",
        "cardSlug",
        "encryptedPayload",
        "encryption"
      ],
      "properties": {
        "schemaVersion": { "type": "integer", "const": 3 },
        "cardSlug": { "type": "string" },
        "cardUpdatedAtSeen": { "type": "string", "format": "date-time" },
        "cardSchemaVersionSeen": { "type": "integer" },
        "interpretedBoundary": { "$ref": "#/$defs/interpretedBoundary" },
        "publicKeyId": { "type": "string" },
        "encryptedPayload": { "type": "string", "minLength": 1 },
        "encryption": {
          "type": "object",
          "additionalProperties": false,
          "required": ["scheme", "nonce"],
          "properties": {
            "scheme": { "const": "sealed_box_v1" },
            "nonce": { "type": "string" }
          }
        }
      }
    },
    {
      "title": "Plaintext before encryption (client-side only)",
      "type": "object",
      "additionalProperties": false,
      "required": [
        "schemaVersion",
        "type",
        "title",
        "summary",
        "urgency",
        "riskLevel"
      ],
      "properties": {
        "schemaVersion": { "type": "integer", "const": 3 },
        "type": {
          "enum": ["inform", "collect", "authorize", "escalate", "result"]
        },
        "title": { "type": "string", "minLength": 1, "maxLength": 200 },
        "summary": { "type": "string", "minLength": 1, "maxLength": 2000 },
        "urgency": { "enum": ["low", "normal", "high", "critical"] },
        "riskLevel": { "enum": ["low", "medium", "high", "irreversible"] }
      }
    }
  ],
  "$defs": {
    "boundaryOutcome": {
      "enum": ["allowed", "forbidden", "ask_first", "stop"]
    },
    "interpretedBoundary": {
      "type": "object",
      "additionalProperties": false,
      "required": ["outcome"],
      "properties": {
        "outcome": { "$ref": "#/$defs/boundaryOutcome" },
        "sectionId": { "type": "string", "minLength": 1 },
        "riskLevel": { "enum": ["low", "medium", "high", "irreversible"] },
        "summary": { "type": "string", "maxLength": 500 }
      }
    }
  }
}
