{
	"$schema": "http://json-schema.org/draft-07/schema#",
	"title": "Context Loadout",
	"description": "A deterministic, target-local bundle of required governance artifacts and selected Context Pages. See ADR-0010 and ADR-0015.",
	"type": "object",
	"additionalProperties": false,
	"required": [
		"schemaVersion",
		"route",
		"feature",
		"generatedAt",
		"budgetWords",
		"artifacts",
		"tiers",
		"pages",
		"references",
		"excluded",
		"redactions",
		"deltaSince"
	],
	"properties": {
		"schemaVersion": {
			"const": "1.0.0"
		},
		"route": {
			"type": "string",
			"pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
		},
		"runId": {
			"type": "string",
			"minLength": 1,
			"maxLength": 128,
			"pattern": "^[A-Za-z0-9][A-Za-z0-9._-]*$"
		},
		"redactions": {
			"description": "ContextSnapshot redaction ledger (context/runtime contract §3.2): records THAT a field was omitted inside admitted pages and why — never values, counts, or ordering. Empty when the build omitted nothing.",
			"type": "array",
			"items": {
				"type": "object",
				"additionalProperties": false,
				"required": ["field", "reason"],
				"properties": {
					"field": {
						"type": "string",
						"minLength": 1
					},
					"reason": {
						"enum": ["classification-ceiling", "purpose-mismatch"]
					}
				}
			}
		},
		"feature": {
			"anyOf": [
				{
					"type": "null"
				},
				{
					"type": "string",
					"pattern": "^[A-Za-z0-9]+(-[A-Za-z0-9]+)*$"
				}
			]
		},
		"generatedAt": {
			"type": "string",
			"format": "date-time"
		},
		"budgetWords": {
			"type": "integer",
			"minimum": 1
		},
		"knowledgeKinds": {
			"type": "array",
			"uniqueItems": true,
			"items": {
				"enum": [
					"invariant",
					"decision",
					"pattern",
					"failure",
					"rejected-approach",
					"external-constraint",
					"unspecified"
				]
			}
		},
		"artifacts": {
			"type": "object",
			"additionalProperties": false,
			"required": ["required"],
			"properties": {
				"required": {
					"type": "array",
					"minItems": 3,
					"maxItems": 3,
					"items": {
						"type": "object",
						"additionalProperties": false,
						"required": ["kind", "path", "rawHash", "words", "classification"],
						"properties": {
							"kind": {
								"enum": ["operating-manual", "route-manifest", "loadout-definition"]
							},
							"path": {
								"type": "string",
								"minLength": 1
							},
							"rawHash": {
								"type": "string",
								"pattern": "^sha256:[0-9a-f]{64}$"
							},
							"words": {
								"type": "integer",
								"minimum": 0
							},
							"classification": {
								"description": "Required Artifacts carry the fixed internal classification; not caller-settable (context/runtime contract §3.1).",
								"const": "internal"
							}
						}
					}
				}
			}
		},
		"tiers": {
			"type": "object",
			"additionalProperties": false,
			"required": ["required", "priority", "optional"],
			"properties": {
				"required": {
					"$ref": "#/definitions/pageIds"
				},
				"priority": {
					"$ref": "#/definitions/pageIds"
				},
				"optional": {
					"$ref": "#/definitions/pageIds"
				}
			}
		},
		"pages": {
			"type": "object",
			"propertyNames": {
				"pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
			},
			"additionalProperties": {
				"type": "object",
				"additionalProperties": false,
				"required": ["title", "words", "rawHash", "status", "scope"],
				"properties": {
					"title": {
						"type": "string"
					},
					"words": {
						"type": "integer",
						"minimum": 0
					},
					"rawHash": {
						"type": "string",
						"pattern": "^sha256:[0-9a-f]{64}$"
					},
					"status": {
						"enum": ["ok", "stale"]
					},
					"scope": {
						"type": "array",
						"uniqueItems": true,
						"items": {
							"type": "string"
						}
					},
					"classification": {
						"description": "The effective classification projection (stored value wins; governed pages without a stored label project internal).",
						"enum": ["public", "internal", "confidential", "restricted", "secret", "unknown"]
					},
					"classificationSource": {
						"enum": ["stored", "effective-default", "unlabeled"]
					},
					"purpose": {
						"anyOf": [
							{
								"type": "null"
							},
							{
								"type": "string",
								"minLength": 1
							}
						]
					},
					"expiresAt": {
						"description": "Effective hard expiry derived from the page ttl and its ingest/refresh instant; null when the page carries no ttl.",
						"anyOf": [
							{
								"type": "null"
							},
							{
								"type": "string",
								"format": "date-time"
							}
						]
					}
				}
			}
		},
		"references": {
			"type": "array",
			"items": {
				"type": "object",
				"additionalProperties": false,
				"required": ["pageId", "rawHash"],
				"properties": {
					"pageId": {
						"type": "string",
						"pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
					},
					"rawHash": {
						"type": "string",
						"pattern": "^sha256:[0-9a-f]{64}$"
					}
				}
			}
		},
		"excluded": {
			"type": "array",
			"items": {
				"type": "object",
				"additionalProperties": false,
				"required": ["pageId", "reason", "detail"],
				"properties": {
					"pageId": {
						"type": "string"
					},
					"reason": {
						"enum": [
							"over-budget",
							"tampered",
							"obsolete",
							"stale",
							"superseded",
							"knowledge-kind",
							"classification",
							"expired",
							"firewall"
						]
					},
					"detail": {
						"type": "string",
						"minLength": 1
					}
				}
			}
		},
		"deltaSince": {
			"anyOf": [
				{
					"type": "null"
				},
				{
					"type": "string",
					"format": "date-time"
				}
			]
		},
		"firewall": {
			"type": "object",
			"additionalProperties": false,
			"required": ["mode", "subject", "purpose", "checkedAt", "grants", "deniedCount"],
			"properties": {
				"mode": {
					"const": "on"
				},
				"subject": {
					"type": "string",
					"minLength": 1,
					"maxLength": 128
				},
				"purpose": {
					"type": "string",
					"minLength": 1,
					"maxLength": 128
				},
				"checkedAt": {
					"type": "string",
					"format": "date-time"
				},
				"runId": {
					"type": "string",
					"minLength": 1,
					"maxLength": 128
				},
				"grants": {
					"type": "array",
					"maxItems": 64,
					"items": {
						"type": "object",
						"additionalProperties": false,
						"required": ["id", "validUntil"],
						"properties": {
							"id": {
								"type": "string",
								"minLength": 1,
								"maxLength": 128
							},
							"snapshotHash": {
								"type": "string",
								"pattern": "^sha256:[0-9a-f]{64}$"
							},
							"validUntil": {
								"type": "string",
								"format": "date-time"
							}
						}
					}
				},
				"deniedCount": {
					"type": "integer",
					"minimum": 0
				}
			},
			"description": "F071 H3b (optional): present only when a governing subject was declared — the covering grants cited (id + snapshot + validUntil) and the denied count; absence means the load was not grant-governed."
		}
	},
	"definitions": {
		"pageIds": {
			"type": "array",
			"uniqueItems": true,
			"items": {
				"type": "string",
				"pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
			}
		}
	}
}
