{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.anchorgate.ai/schemas/des.schema.json",
  "title": "DecisionEvent",
  "description": "Decision Event Schema (DES) v1 — the canonical, signable record of a single agentic decision. This file is the single source of truth: Go structs, Pydantic models, and TypeScript types are generated from it.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "eventId",
    "timestamp",
    "actorId",
    "authorityContext",
    "actionPayload",
    "policyState",
    "decisionBasis",
    "resourceTouch"
  ],
  "properties": {
    "eventId": {
      "type": "string",
      "format": "uuid",
      "description": "Unique identifier of this decision event."
    },
    "timestamp": {
      "type": "string",
      "format": "date-time",
      "description": "ISO-8601 timestamp of the decision (UTC)."
    },
    "actorId": {
      "type": "string",
      "minLength": 1,
      "description": "Identifier of the agent, service, or user that initiated the action."
    },
    "authorityContext": {
      "$ref": "#/$defs/AuthorityContext"
    },
    "actionPayload": {
      "$ref": "#/$defs/ActionPayload"
    },
    "policyState": {
      "$ref": "#/$defs/PolicyState"
    },
    "decisionBasis": {
      "$ref": "#/$defs/DecisionBasis"
    },
    "resourceTouch": {
      "$ref": "#/$defs/ResourceTouch"
    }
  },
  "$defs": {
    "Verdict": {
      "type": "string",
      "description": "Strict deontic verdict set. Any value outside this set must be rejected.",
      "enum": [
        "admitted",
        "held",
        "narrowed",
        "refused",
        "escalated",
        "quarantined"
      ]
    },
    "AuthorityContext": {
      "type": "object",
      "additionalProperties": false,
      "required": ["delegationToken", "permissionsUsed"],
      "properties": {
        "delegationToken": {
          "type": "string",
          "description": "Opaque reference to the delegation/TBAC token under which the actor acted (never the raw secret)."
        },
        "permissionsUsed": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Permission scopes actually exercised by this action."
        }
      }
    },
    "ActionPayload": {
      "type": "object",
      "additionalProperties": false,
      "required": ["toolName", "arguments"],
      "properties": {
        "toolName": {
          "type": "string",
          "minLength": 1,
          "description": "Name of the tool, model endpoint, or MCP method invoked."
        },
        "arguments": {
          "type": "object",
          "description": "Arguments passed to the tool/model, post-redaction.",
          "additionalProperties": true
        }
      }
    },
    "PolicyState": {
      "type": "object",
      "additionalProperties": false,
      "required": ["policyVersion", "rulesApplied", "verdict"],
      "properties": {
        "policyVersion": {
          "type": "string",
          "description": "Version identifier of the active policy bundle at decision time."
        },
        "rulesApplied": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Identifiers of the rules that matched/fired during evaluation."
        },
        "verdict": {
          "$ref": "#/$defs/Verdict"
        }
      }
    },
    "DecisionBasis": {
      "type": "object",
      "additionalProperties": false,
      "required": ["promptTemplate", "modelConfig", "reasoningTrace"],
      "properties": {
        "promptTemplate": {
          "type": "string",
          "description": "Template or identifier of the prompt that framed the decision."
        },
        "modelConfig": {
          "type": "object",
          "description": "Model and inference configuration (model id, temperature, provider, ...).",
          "additionalProperties": true
        },
        "reasoningTrace": {
          "type": "string",
          "description": "Reasoning/trace excerpt supporting the decision (post-redaction; may be empty)."
        }
      }
    },
    "ResourceTouch": {
      "type": "object",
      "additionalProperties": false,
      "required": ["dataSources", "modifiedTargets"],
      "properties": {
        "dataSources": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Data sources read during the action (RAG stores, DBs, URLs)."
        },
        "modifiedTargets": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Resources written to or mutated by the action."
        }
      }
    }
  }
}
