{
	"$schema": "http://json-schema.org/draft-07/schema#",
	"title": "Distillation Contract (request)",
	"description": "The request artifact Amber emits at .amber/context/requests/<id>.json. Amber writes it and judges the result; a host agent executes it. Amber never calls a model. See ADR-0009.",
	"type": "object",
	"required": [
		"schemaVersion",
		"requestId",
		"createdAt",
		"target",
		"sources",
		"contract",
		"acceptance"
	],
	"properties": {
		"schemaVersion": { "type": "string", "enum": ["1.0.0", "1.1.0", "1.2.0"] },
		"requestId": { "type": "string", "pattern": "^[a-z0-9-]+$" },
		"createdAt": { "type": "string", "format": "date-time" },
		"target": {
			"type": "object",
			"required": ["pageId", "title"],
			"properties": {
				"pageId": { "type": "string", "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$" },
				"title": { "type": "string", "minLength": 1 },
				"reason": { "type": "string" },
				"existingHash": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
				"scope": { "type": "array", "items": { "type": "string" }, "uniqueItems": true },
				"knowledgeKind": {
					"enum": [
						"invariant",
						"decision",
						"pattern",
						"failure",
						"rejected-approach",
						"external-constraint",
						"unspecified"
					]
				},
				"supersedes": {
					"type": "array",
					"uniqueItems": true,
					"items": { "type": "string", "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$" }
				}
			}
		},
		"sources": {
			"type": "array",
			"minItems": 1,
			"items": {
				"type": "object",
				"required": ["kind", "ref", "rawHash", "mutable"],
				"properties": {
					"kind": { "type": "string" },
					"ref": { "type": "string", "minLength": 1 },
					"rawHash": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
					"normHash": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
					"mutable": { "type": "boolean" },
					"excerpt": { "type": "string" },
					"excerptHash": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" }
				},
				"allOf": [
					{
						"description": "mutable sources carry normHash; immutable sources carry an excerpt snapshot (ADR-0009 D5/D5a)",
						"if": { "properties": { "mutable": { "const": true } } },
						"then": { "required": ["normHash"] },
						"else": { "required": ["excerpt", "excerptHash"] }
					}
				]
			}
		},
		"contract": {
			"type": "object",
			"required": ["outputSchema", "instructions", "constraints"],
			"properties": {
				"outputSchema": { "type": "string" },
				"instructions": { "type": "string", "minLength": 1 },
				"constraints": {
					"type": "object",
					"properties": {
						"maxWords": { "type": "integer", "minimum": 1 },
						"requireCitationPerClaim": { "type": "boolean" },
						"forbidNewFacts": { "type": "boolean" }
					}
				}
			}
		},
		"acceptance": {
			"type": "array",
			"minItems": 1,
			"items": {
				"type": "object",
				"required": ["check", "code"],
				"properties": {
					"check": { "type": "string" },
					"code": { "type": "string", "pattern": "^AMBER_E_[A-Z_]+$" }
				}
			}
		},
		"amber_protocol_version": { "type": "string" },
		"artifact_sequence": { "type": "integer" },
		"created_at": { "type": "string", "format": "date-time" },
		"artifact_type": { "type": "string" }
	}
}
