{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://jig-harness.dev/protocol/repo-commands/v1/schemas/reflection-event.json",
  "anyOf": [
    {
      "type": "object",
      "properties": {
        "v": {
          "const": 1
        },
        "id": {
          "type": "string",
          "pattern": "^(?:[0-9]{8}T[0-9]{6}Z-[0-9a-f]{16}|drv-[0-9a-f]{32})$"
        },
        "at": {
          "type": "string",
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
        },
        "session": {
          "type": "object",
          "properties": {
            "jig_version": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            },
            "skills": {
              "type": "array",
              "items": {
                "type": "string",
                "pattern": "\\S"
              }
            },
            "harness": {
              "anyOf": [
                {
                  "type": "object",
                  "properties": {
                    "name": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "version": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "entrypoint": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "wrapper": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  },
                  "required": ["name", "version", "entrypoint", "wrapper"],
                  "additionalProperties": true
                },
                {
                  "type": "null"
                }
              ]
            },
            "model": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            },
            "mode": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            },
            "stated": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          "required": [
            "jig_version",
            "skills",
            "harness",
            "model",
            "mode",
            "stated"
          ],
          "additionalProperties": true
        },
        "type": {
          "const": "finding"
        },
        "change": {
          "type": "object",
          "properties": {
            "repository": {
              "type": "string",
              "pattern": "\\S"
            },
            "branch": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            },
            "pull_request": {
              "anyOf": [
                {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 9007199254740991
                },
                {
                  "type": "null"
                }
              ]
            },
            "issue": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": ["repository", "branch", "pull_request", "issue"],
          "additionalProperties": true
        },
        "kind": {
          "enum": ["error", "opportunity", "unhelpful-content"]
        },
        "severity": {
          "enum": ["high", "medium", "low"]
        },
        "class": {
          "type": "string",
          "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
        },
        "target": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "scope": {
                  "const": "repository"
                },
                "name": {
                  "type": "string",
                  "pattern": "\\S"
                }
              },
              "required": ["scope", "name"],
              "additionalProperties": true
            },
            {
              "type": "object",
              "properties": {
                "scope": {
                  "const": "tool"
                },
                "tool": {
                  "type": "string",
                  "pattern": "\\S"
                },
                "name": {
                  "type": "string",
                  "pattern": "\\S"
                }
              },
              "required": ["scope", "tool", "name"],
              "additionalProperties": true
            }
          ]
        },
        "title": {
          "type": "string",
          "pattern": "\\S"
        },
        "description": {
          "type": "string",
          "pattern": "\\S"
        },
        "suggested_fix": {
          "type": "string",
          "pattern": "\\S"
        },
        "time_cost_minutes": {
          "type": "number",
          "minimum": 0
        }
      },
      "required": [
        "v",
        "id",
        "at",
        "session",
        "type",
        "change",
        "kind",
        "severity",
        "class",
        "target",
        "title",
        "description",
        "suggested_fix"
      ],
      "additionalProperties": true
    },
    {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "v": {
              "const": 1
            },
            "id": {
              "type": "string",
              "pattern": "^(?:[0-9]{8}T[0-9]{6}Z-[0-9a-f]{16}|drv-[0-9a-f]{32})$"
            },
            "at": {
              "type": "string",
              "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
            },
            "session": {
              "type": "object",
              "properties": {
                "jig_version": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "skills": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "pattern": "\\S"
                  }
                },
                "harness": {
                  "anyOf": [
                    {
                      "type": "object",
                      "properties": {
                        "name": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "version": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "entrypoint": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "wrapper": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        }
                      },
                      "required": ["name", "version", "entrypoint", "wrapper"],
                      "additionalProperties": true
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "model": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "mode": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "stated": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              },
              "required": [
                "jig_version",
                "skills",
                "harness",
                "model",
                "mode",
                "stated"
              ],
              "additionalProperties": true
            },
            "type": {
              "const": "decision"
            },
            "finding": {
              "type": "string",
              "pattern": "^(?:[0-9]{8}T[0-9]{6}Z-[0-9a-f]{16}|drv-[0-9a-f]{32})$"
            },
            "reason": {
              "type": "string",
              "pattern": "\\S"
            },
            "commit": {
              "type": "string",
              "pattern": "\\S"
            },
            "pull_request": {
              "anyOf": [
                {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 9007199254740991
                },
                {
                  "type": "null"
                }
              ]
            },
            "decision": {
              "enum": ["approved", "implemented", "deferred", "dismissed"]
            },
            "issue": {
              "type": "string",
              "pattern": "\\S"
            }
          },
          "required": [
            "v",
            "id",
            "at",
            "session",
            "type",
            "finding",
            "reason",
            "decision"
          ],
          "additionalProperties": true
        },
        {
          "type": "object",
          "properties": {
            "v": {
              "const": 1
            },
            "id": {
              "type": "string",
              "pattern": "^(?:[0-9]{8}T[0-9]{6}Z-[0-9a-f]{16}|drv-[0-9a-f]{32})$"
            },
            "at": {
              "type": "string",
              "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
            },
            "session": {
              "type": "object",
              "properties": {
                "jig_version": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "skills": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "pattern": "\\S"
                  }
                },
                "harness": {
                  "anyOf": [
                    {
                      "type": "object",
                      "properties": {
                        "name": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "version": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "entrypoint": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "wrapper": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        }
                      },
                      "required": ["name", "version", "entrypoint", "wrapper"],
                      "additionalProperties": true
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "model": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "mode": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "stated": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              },
              "required": [
                "jig_version",
                "skills",
                "harness",
                "model",
                "mode",
                "stated"
              ],
              "additionalProperties": true
            },
            "type": {
              "const": "decision"
            },
            "finding": {
              "type": "string",
              "pattern": "^(?:[0-9]{8}T[0-9]{6}Z-[0-9a-f]{16}|drv-[0-9a-f]{32})$"
            },
            "reason": {
              "type": "string",
              "pattern": "\\S"
            },
            "commit": {
              "type": "string",
              "pattern": "\\S"
            },
            "pull_request": {
              "anyOf": [
                {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 9007199254740991
                },
                {
                  "type": "null"
                }
              ]
            },
            "decision": {
              "const": "escalated"
            },
            "issue": {
              "type": "string",
              "pattern": "\\S"
            }
          },
          "required": [
            "v",
            "id",
            "at",
            "session",
            "type",
            "finding",
            "reason",
            "decision",
            "issue"
          ],
          "additionalProperties": true
        }
      ]
    }
  ]
}
