{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://sk-intellix-wiki.pages.dev/docs/a2a/device-context-v2.schema.json",
  "title": "SK Intellix Device Context v2",
  "description": "Internal semantic device-state contract. Raw media, credentials, unrestricted logs, and user-facing prose are intentionally excluded.",
  "type": "object",
  "required": [
    "schema_version",
    "snapshot_id",
    "generated_at_ms",
    "catalog_version",
    "domains",
    "recent_events"
  ],
  "properties": {
    "schema_version": {
      "const": "device_context.v2"
    },
    "snapshot_id": {
      "type": "string",
      "minLength": 1
    },
    "generated_at_ms": {
      "type": "integer",
      "minimum": 0
    },
    "catalog_version": {
      "type": "string",
      "minLength": 1
    },
    "device": {
      "type": "object",
      "properties": {
        "model_family": {
          "type": "string"
        },
        "software_profile": {
          "type": "string"
        },
        "device_id_hash": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "domains": {
      "type": "object",
      "required": [
        "core",
        "battery",
        "spatial",
        "environment",
        "task_manager",
        "capabilities"
      ],
      "properties": {
        "core": {
          "$ref": "#/$defs/domainEnvelope"
        },
        "battery": {
          "$ref": "#/$defs/domainEnvelope"
        },
        "spatial": {
          "$ref": "#/$defs/domainEnvelope"
        },
        "environment": {
          "$ref": "#/$defs/domainEnvelope"
        },
        "voice_llm": {
          "$ref": "#/$defs/domainEnvelope"
        },
        "policy": {
          "$ref": "#/$defs/domainEnvelope"
        },
        "network": {
          "$ref": "#/$defs/domainEnvelope"
        },
        "perception": {
          "$ref": "#/$defs/domainEnvelope"
        },
        "security": {
          "$ref": "#/$defs/domainEnvelope"
        },
        "streaming": {
          "$ref": "#/$defs/domainEnvelope"
        },
        "application": {
          "$ref": "#/$defs/domainEnvelope"
        },
        "maintenance": {
          "$ref": "#/$defs/domainEnvelope"
        },
        "resource": {
          "$ref": "#/$defs/domainEnvelope"
        },
        "task_manager": {
          "$ref": "#/$defs/domainEnvelope"
        },
        "capabilities": {
          "$ref": "#/$defs/domainEnvelope"
        }
      },
      "additionalProperties": false
    },
    "recent_events": {
      "type": "array",
      "maxItems": 32,
      "items": {
        "$ref": "#/$defs/semanticEvent"
      }
    }
  },
  "$defs": {
    "freshness": {
      "type": "object",
      "required": [
        "observed_at_ms",
        "received_at_ms",
        "age_ms",
        "ttl_ms",
        "state"
      ],
      "properties": {
        "observed_at_ms": {
          "type": "integer",
          "minimum": 0
        },
        "received_at_ms": {
          "type": "integer",
          "minimum": 0
        },
        "age_ms": {
          "type": "integer",
          "minimum": 0
        },
        "ttl_ms": {
          "type": "integer",
          "minimum": 0
        },
        "state": {
          "enum": [
            "fresh",
            "stale",
            "unknown"
          ]
        }
      },
      "additionalProperties": false
    },
    "provenance": {
      "type": "object",
      "required": [
        "source_component",
        "source_symbol",
        "source_kind"
      ],
      "properties": {
        "source_component": {
          "type": "string",
          "minLength": 1
        },
        "source_symbol": {
          "type": "string",
          "minLength": 1
        },
        "source_event": {
          "type": "string"
        },
        "source_kind": {
          "enum": [
            "binder_callback",
            "domain_state",
            "sensor_snapshot",
            "task_event",
            "cached_transport_state",
            "derived_semantic_state",
            "persistent_store"
          ]
        },
        "sequence": {
          "oneOf": [
            {
              "type": "integer"
            },
            {
              "type": "string"
            }
          ]
        }
      },
      "additionalProperties": false
    },
    "fieldEvidence": {
      "type": "object",
      "required": [
        "freshness",
        "provenance"
      ],
      "properties": {
        "freshness": {
          "$ref": "#/$defs/freshness"
        },
        "provenance": {
          "$ref": "#/$defs/provenance"
        },
        "confidence": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        }
      },
      "additionalProperties": false
    },
    "domainEnvelope": {
      "type": "object",
      "required": [
        "available",
        "freshness",
        "provenance",
        "planner_exposure",
        "sensitivity",
        "data"
      ],
      "properties": {
        "available": {
          "type": "boolean"
        },
        "unavailable_reason": {
          "type": "string"
        },
        "freshness": {
          "$ref": "#/$defs/freshness"
        },
        "provenance": {
          "$ref": "#/$defs/provenance"
        },
        "planner_exposure": {
          "enum": [
            "summary",
            "condition_only",
            "internal_only",
            "blocked"
          ]
        },
        "sensitivity": {
          "enum": [
            "normal",
            "sensitive",
            "restricted"
          ]
        },
        "data": {
          "type": "object"
        },
        "field_evidence": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/fieldEvidence"
          }
        }
      },
      "additionalProperties": false
    },
    "semanticEvent": {
      "type": "object",
      "required": [
        "event_id",
        "name",
        "domain",
        "observed_at_ms",
        "severity",
        "terminal",
        "provenance"
      ],
      "properties": {
        "event_id": {
          "type": "string",
          "minLength": 1
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "domain": {
          "type": "string",
          "minLength": 1
        },
        "observed_at_ms": {
          "type": "integer",
          "minimum": 0
        },
        "severity": {
          "enum": [
            "info",
            "warning",
            "critical"
          ]
        },
        "terminal": {
          "type": "boolean"
        },
        "workflow_id": {
          "type": "string"
        },
        "task_id": {
          "type": "string"
        },
        "step_id": {
          "type": "string"
        },
        "reason_code": {
          "type": "string"
        },
        "semantic_payload": {
          "type": "object"
        },
        "provenance": {
          "$ref": "#/$defs/provenance"
        }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
