{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:orbiplex:schema:corpus-reasoning-instruction-overlay:v1",
  "title": "Corpus Reasoning Instruction Overlay v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema/v",
    "overlay/id",
    "assignment/id",
    "query/id",
    "room/id",
    "participant",
    "role",
    "turn/no",
    "kind",
    "position",
    "instruction/text",
    "class/key",
    "status",
    "revision/no",
    "proposed/by",
    "proposed-at",
    "expires-at",
    "idempotency/key"
  ],
  "properties": {
    "schema/v": { "const": 1 },
    "overlay/id": {
      "type": "string",
      "pattern": "^corpus-instruction-overlay:sha256:[A-Za-z0-9_-]{43}$"
    },
    "assignment/id": {
      "type": "string",
      "pattern": "^corpus-role-assignment:sha256:[A-Za-z0-9_-]{43}$"
    },
    "query/id": { "type": "string", "pattern": "^query:[^\\s]+$", "maxLength": 512 },
    "room/id": { "type": "string", "pattern": "^room:[^\\s]+$", "maxLength": 512 },
    "participant": { "$ref": "corpus-reasoning-room-policy.v1.schema.json#/$defs/room-subject" },
    "role": { "enum": ["implementer", "reviewer", "adversarial-critic", "summarizer"] },
    "turn/no": { "type": "integer", "minimum": 1, "maximum": 4294967295 },
    "kind": {
      "enum": ["task-guidance", "review-criteria", "adversarial-check", "summary-criteria"]
    },
    "position": { "enum": ["preamble", "postamble"] },
    "instruction/text": { "type": "string", "minLength": 1, "maxLength": 8192 },
    "instruction/rendered": { "type": "string", "minLength": 1, "maxLength": 10240 },
    "class/key": { "enum": ["Public", "Community", "Personal"] },
    "status": { "enum": ["proposed", "accepted", "declined"] },
    "revision/no": { "type": "integer", "minimum": 1, "maximum": 4294967295 },
    "proposed/by": { "type": "string", "minLength": 1, "maxLength": 512 },
    "proposed-at": { "type": "string", "format": "date-time" },
    "decision/by": { "type": "string", "minLength": 1, "maxLength": 512 },
    "decided-at": { "type": "string", "format": "date-time" },
    "policy/ref": { "type": "string", "pattern": "^prompt-policy:[^\\s]+$", "maxLength": 512 },
    "expires-at": { "type": "string", "format": "date-time" },
    "idempotency/key": { "type": "string", "minLength": 1, "maxLength": 256 }
  },
  "allOf": [
    {
      "if": { "properties": { "status": { "const": "proposed" } } },
      "then": {
        "not": {
          "anyOf": [
            { "required": ["decision/by"] },
            { "required": ["decided-at"] },
            { "required": ["policy/ref"] },
            { "required": ["instruction/rendered"] }
          ]
        }
      },
      "else": { "required": ["decision/by", "decided-at", "policy/ref"] }
    },
    {
      "if": { "properties": { "status": { "const": "accepted" } } },
      "then": { "required": ["instruction/rendered"] },
      "else": { "not": { "required": ["instruction/rendered"] } }
    }
  ],
  "x-dia-status": "accepted",
  "x-dia-basis": [
    "doc/project/40-proposals/069-corpus.md",
    "doc/project/40-proposals/064-inquirium-implementation-recommendations.md"
  ]
}
