{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://denial-web.github.io/clawguard/schemas/inter-component-message.schema.json",
  "title": "ClawGuard Inter-Component Message",
  "description": "Envelope for messages crossing ClawGuard component trust boundaries.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "messageId",
    "source",
    "destination",
    "trust",
    "allowedUse",
    "createdAt",
    "payload",
    "provenance"
  ],
  "properties": {
    "schemaVersion": {
      "const": "clawguard.interComponentMessage.v1"
    },
    "messageId": {
      "type": "string",
      "minLength": 1
    },
    "source": {
      "type": "object",
      "additionalProperties": false,
      "required": ["component", "componentType"],
      "properties": {
        "component": {
          "type": "string",
          "enum": [
            "user",
            "planner",
            "data_broker",
            "policy_engine",
            "critic",
            "executor",
            "audit_writer",
            "tool_runtime",
            "approval_system"
          ]
        },
        "componentType": {
          "type": "string",
          "enum": [
            "human",
            "llm_reasoning",
            "deterministic_mediator",
            "deterministic_authority",
            "deterministic_gate",
            "deterministic_executor",
            "deterministic_recorder",
            "external_tool"
          ]
        }
      }
    },
    "destination": {
      "type": "object",
      "additionalProperties": false,
      "required": ["component"],
      "properties": {
        "component": {
          "type": "string",
          "enum": [
            "planner",
            "data_broker",
            "policy_engine",
            "critic",
            "executor",
            "audit_writer",
            "approval_system"
          ]
        }
      }
    },
    "trust": {
      "type": "string",
      "enum": [
        "user_input",
        "llm_proposal",
        "untrusted_tool_output",
        "policy_decision",
        "critic_decision",
        "approval_grant",
        "audit_record"
      ]
    },
    "allowedUse": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "type": "string",
        "enum": [
          "planning_context",
          "policy_evaluation",
          "critic_evaluation",
          "display_to_user",
          "execution_authorization",
          "audit_recording",
          "memory_proposal",
          "data_broker_query"
        ]
      }
    },
    "createdAt": {
      "type": "string",
      "format": "date-time"
    },
    "payload": {
      "type": "object"
    },
    "provenance": {
      "type": "object",
      "additionalProperties": false,
      "required": ["wrappedBy", "verifiedBy", "signature"],
      "properties": {
        "wrappedBy": {
          "type": "string",
          "minLength": 1
        },
        "verifiedBy": {
          "anyOf": [
            {
              "type": "null"
            },
            {
              "type": "object",
              "additionalProperties": false,
              "required": ["component", "traceId"],
              "properties": {
                "component": {
                  "type": "string",
                  "enum": ["policy_engine", "critic", "data_broker", "tool_runtime", "approval_system"]
                },
                "traceId": {
                  "type": "string",
                  "minLength": 1
                }
              }
            }
          ]
        },
        "signature": {
          "anyOf": [
            {
              "type": "null"
            },
            {
              "type": "object",
              "additionalProperties": false,
              "required": ["algorithm", "value"],
              "properties": {
                "algorithm": {
                  "type": "string",
                  "minLength": 1
                },
                "value": {
                  "type": "string",
                  "minLength": 1
                }
              }
            }
          ]
        }
      }
    }
  }
}
