{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "PersonaDef": {
      "type": "object",
      "properties": {
        "role": { "type": "string" },
        "mandate": {
          "oneOf": [
            { "type": "string" },
            { "type": "array", "items": { "type": "string" } }
          ]
        },
        "checklist": {
          "type": "object",
          "patternProperties": {
            "^.*$": {
              "oneOf": [
                { "type": "string" },
                { "type": "array", "items": { "type": "string" } }
              ]
            }
          }
        }
      },
      "required": ["role", "mandate", "checklist"]
    },
    "ChecklistObject": {
      "type": "object",
      "patternProperties": {
        "^.*$": { "type": "boolean" }
      }
    },
    "EnvironmentDef": {
      "type": "object",
      "properties": {
        "vcs": { "type": "string", "enum": ["GIT", "JJ"] },
        "harness": { "type": "string", "enum": ["JETSKI", "GENERIC_CLI"] },
        "temp_directory": {
          "type": "string",
          "description": "The relative path (recommended for workspace isolation) or absolute path to a directory where interim files are stored."
        }
      },
      "required": ["vcs", "harness", "temp_directory"]
    },
    "ProjectSpec": {
      "type": "object",
      "properties": {
        "goal": {
          "type": "string",
          "description": "High-level objective or title of the change being reviewed."
        },
        "target_files": { "type": "array", "items": { "type": "string" } },
        "environment": { "$ref": "#/definitions/EnvironmentDef" },
        "active_protocol": {
          "type": "string",
          "enum": ["WORKFLOW", "TDD", "REVIEW"],
          "description": "Identifies the active protocol for tagging and tracking."
        },
        "routing_overlay": {
          "type": "string",
          "description": "Optional path to an internal routing overlay file (e.g., in google3) to merge with ROUTING.md."
        }
      },
      "required": ["goal", "target_files", "environment", "active_protocol"]
    },
    "ReviewFeedback": {
      "type": "object",
      "properties": {
        "checklist": { "$ref": "#/definitions/ChecklistObject" },
        "unlisted_issues_found": { "type": "array", "items": { "type": "string" } },
        "verdict": { "type": "string", "enum": ["ACCEPT", "REJECT"] },
        "reasoning": { "type": "array", "items": { "type": "string" } },
        "comments": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "file": { "type": "string" },
              "line": { "type": "integer" },
              "comment": { "type": "string" }
            },
            "required": ["file", "comment"]
          }
        }
      },
      "required": ["checklist", "verdict", "reasoning"]
    },
    "StateBlock": {
      "type": "object",
      "properties": {
        "verdict": { "type": "string", "enum": ["ACCEPT", "REJECT", "PENDING"] },
        "checklist": { "$ref": "#/definitions/ChecklistObject" },
        "unlisted_issues_found": { "type": "array", "items": { "type": "string" } },
        "iteration": { "type": "integer" },
        "oscillation_detected": { "type": "boolean" },
        "conflict_report": { "type": "array", "items": { "type": "string" } },
        "constraints": { "type": "array", "items": { "type": "string" } },
        "next_stage": {
          "type": "string",
          "enum": ["SYNTHESIS", "VALIDATION", "ESCALATION", "COMPLETED"]
        }
      },
      "required": [
        "verdict",
        "checklist",
        "iteration",
        "oscillation_detected",
        "constraints",
        "next_stage"
      ]
    },
    "Constraints": {
      "type": "object",
      "properties": {
        "checklist": { "$ref": "#/definitions/ChecklistObject" },
        "unlisted_issues_found": {
          "type": "array",
          "items": { "type": "string" }
        },
        "iteration": { "type": "integer" },
        "oscillation_detected": { "type": "boolean" },
        "conflict_report": { "type": "array", "items": { "type": "string" } },
        "constraints": { "type": "array", "items": { "type": "string" } },
        "next_stage": {
          "type": "string",
          "enum": ["SYNTHESIS", "VALIDATION", "ESCALATION"]
        }
      },
      "required": [
        "checklist",
        "iteration",
        "oscillation_detected",
        "constraints",
        "next_stage"
      ]
    }
  }
}
