{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Cortex Agent Inbox Message",
  "type": "object",
  "required": [
    "schema_version",
    "message_id",
    "type",
    "status",
    "sender_id",
    "recipient_ids",
    "subject",
    "body",
    "artifact_refs",
    "relations",
    "created_at",
    "updated_at"
  ],
  "properties": {
    "schema_version": { "const": 1 },
    "message_id": { "type": "string", "pattern": "^IM-[A-Za-z0-9][A-Za-z0-9._-]*$" },
    "type": {
      "type": "string",
      "enum": ["information", "request", "handoff", "decision_request", "alert"]
    },
    "status": {
      "type": "string",
      "enum": ["unread", "read", "acknowledged", "archived"]
    },
    "sender_id": { "type": "string", "minLength": 1 },
    "recipient_ids": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": { "type": "string", "minLength": 1 }
    },
    "subject": { "type": "string", "minLength": 1, "maxLength": 200 },
    "body": {
      "type": "string",
      "maxLength": 4000,
      "description": "Concise message text. Store large content as artifacts and reference it through artifact_refs."
    },
    "artifact_refs": {
      "type": "array",
      "uniqueItems": true,
      "items": { "type": "string", "minLength": 1 }
    },
    "relations": {
      "type": "object",
      "required": ["task_ids", "mission_ids", "run_ids", "queue_ids", "session_ids", "artifact_refs", "worktree_paths"],
      "properties": {
        "task_ids": { "type": "array", "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
        "mission_ids": { "type": "array", "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
        "run_ids": { "type": "array", "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
        "queue_ids": { "type": "array", "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
        "session_ids": { "type": "array", "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
        "artifact_refs": { "type": "array", "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
        "worktree_paths": { "type": "array", "uniqueItems": true, "items": { "type": "string", "minLength": 1 } }
      },
      "additionalProperties": false
    },
    "created_at": { "type": "string", "format": "date-time" },
    "updated_at": { "type": "string", "format": "date-time" },
    "read_at": { "type": ["string", "null"], "format": "date-time" },
    "acknowledged_at": { "type": ["string", "null"], "format": "date-time" },
    "archived_at": { "type": ["string", "null"], "format": "date-time" }
  },
  "additionalProperties": false
}
