{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.connectsoft.ai/reference/schemas/execution-scope.schema.json",
  "title": "ExecutionScope",
  "description": "Trusted scope attached to every Factory command, event, tool invocation, retrieval request and usage record. Derived from the authenticated context (canonical ADR-0100/0101, ADR-0015); never supplied by prompt text or caller-controlled headers.",
  "type": "object",
  "required": ["tenantId", "projectId", "callerId", "callerKind", "policyContext"],
  "additionalProperties": false,
  "properties": {
    "tenantId": { "type": "string", "description": "Tenant from the validated token claim `tid`." },
    "projectId": { "type": "string", "description": "Workspace/project within the tenant." },
    "environmentId": { "type": "string", "description": "Environment within the project, when the workflow targets one." },
    "callerId": { "type": "string", "description": "Subject id of the requester (user) or workload identity (worker, partner agent)." },
    "callerKind": { "enum": ["user", "workload", "partner-agent", "system"] },
    "delegatedUserId": { "type": "string", "description": "User on whose behalf a workload acts; required when callerKind is workload or partner-agent and user scopes apply." },
    "roles": { "type": "array", "items": { "enum": ["Requester", "Reviewer", "AssetMaintainer", "Operator", "WorkspaceAdmin", "PlatformAdmin", "Observer"] }, "description": "Factory roles resolved for the caller in this project (ADR-0015 point 5)." },
    "sourceScope": {
      "type": "object",
      "description": "What a run may touch.",
      "properties": {
        "repositories": { "type": "array", "items": { "type": "string" } },
        "documentCollections": { "type": "array", "items": { "type": "string" } },
        "toolIds": { "type": "array", "items": { "type": "string" } }
      }
    },
    "policyContext": {
      "type": "object",
      "required": ["policyRevision"],
      "properties": {
        "policyRevision": { "type": "string" },
        "dataClassificationCeiling": { "enum": ["public", "internal", "confidential", "restricted"] },
        "region": { "type": "string", "description": "Tenant region (ADR-0019)." }
      }
    }
  }
}
