{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.connectsoft.ai/reference/schemas/context-snapshot.schema.json",
  "title": "ContextSnapshot (context-package-v1)",
  "description": "The governed, ranked, budgeted knowledge bundle assembled for one attempt (BC-09): what was retrieved, from which source revision and index version, under which scope, and how the token budget was spent. Scope is enforced by the backend before ranking (ADR-0013).",
  "type": "object",
  "required": ["snapshotId", "runId", "attemptId", "scope", "budget", "items", "hash"],
  "additionalProperties": false,
  "properties": {
    "snapshotId": { "type": "string", "format": "uuid" },
    "runId": { "type": "string", "format": "uuid" },
    "stepId": { "type": "string", "format": "uuid" },
    "attemptId": { "type": "string", "format": "uuid" },
    "scope": { "$ref": "execution-scope.schema.json" },
    "strategy": { "type": "string", "description": "Context strategy id from the agent definition." },
    "budget": { "type": "object", "required": ["maxTokens", "usedTokens"], "properties": { "maxTokens": { "type": "integer" }, "usedTokens": { "type": "integer" }, "reservedForOutput": { "type": "integer" } } },
    "items": {
      "type": "array",
      "items": {
        "type": "object", "required": ["class", "sourceId", "sourceRevision", "chunkId", "tokens", "rank"],
        "properties": {
          "class": { "enum": ["task", "instructions", "skill", "code", "documents", "schema", "graph", "memory", "history", "tool-result", "policy"] },
          "sourceId": { "type": "string" }, "sourceRevision": { "type": "string" }, "chunkId": { "type": "string" },
          "indexVersion": { "type": "string" }, "embeddingProfile": { "type": "string" },
          "tokens": { "type": "integer" }, "rank": { "type": "number" },
          "trustTier": { "enum": ["system-policy", "agent", "skill", "user", "trusted-knowledge", "tool-result", "untrusted-external"] },
          "classification": { "enum": ["public", "internal", "confidential", "restricted"] },
          "compressed": { "type": "boolean" }, "provenance": { "type": "string" }
        }
      }
    },
    "exclusions": { "type": "array", "items": { "type": "object", "properties": { "sourceId": { "type": "string" }, "reason": { "enum": ["denied", "stale", "budget", "classification", "duplicate"] } } } },
    "hash": { "type": "string" }
  }
}
