{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://grip.foxora.dev/schema/1.0-draft.2/context.schema.json",
  "title": "GRIP Context Envelope",
  "description": "A signed record of the exact input a model-driven agent acted on. §4.3.6.",
  "allOf": [{ "$ref": "common.schema.json#/$defs/envelope" }],
  "type": "object",
  "required": ["grip", "type", "id", "parents", "iss", "purpose", "budget_tokens", "used_tokens", "items", "iat", "sig"],
  "properties": {
    "type": { "const": "context" },
    "purpose": { "type": "string", "minLength": 1 },
    "budget_tokens": { "type": "integer", "minimum": 0 },
    "used_tokens": { "type": "integer", "minimum": 0 },
    "items": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["ref", "digest", "trust"],
        "properties": {
          "ref": { "type": "string", "minLength": 1 },
          "digest": { "$ref": "common.schema.json#/$defs/digest" },
          "trust": {
            "enum": ["principal", "governed", "external"],
            "description": "Normative trust classes. A derived item inherits the LOWEST class among its sources, permanently, absent a receipted declassification. §4.3.6."
          },
          "derived_from": { "type": "array", "items": { "$ref": "common.schema.json#/$defs/digest" } },
          "declassified_by": { "$ref": "common.schema.json#/$defs/digest", "description": "Receipt of the declassification act with a named authority." }
        },
        "additionalProperties": false
      }
    }
  },
  "$comment": "used_tokens <= budget_tokens is checked by grip-verify rule 7; JSON Schema cannot express cross-field comparison."
}
