{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://dotbabel.dev/schemas/dotbabel.run-receipt.schema.json",
  "title": "dotbabel conductor run receipt",
  "description": "The append-only, SELF-REPORTED history of one pull request's conductor runs (a log, never evidence: the merge gate does not read it), written by `dotbabel pr-stack record` to <git-common-dir>/dotbabel/receipts/pr-<N>.json (never the working tree). Every phase attempt is kept, with the head it ran on, its outcome, its evidence links, the rollback point, and the model its artifact requested. A field nobody observed is null; the receipt never records a cost or a model route it did not see.",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema_version", "tool", "pr", "created_at", "updated_at", "attempts"],
  "properties": {
    "schema_version": {
      "enum": [1, 2]
    },
    "tool": {
      "const": "dotbabel-pr-stack"
    },
    "pr": {
      "type": "integer",
      "minimum": 1
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "updated_at": {
      "type": "string",
      "format": "date-time"
    },
    "attempts": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "phase",
          "n",
          "at",
          "head_sha",
          "base_ref",
          "merge_base",
          "outcome",
          "reason_code",
          "evidence",
          "requested_model",
          "tool_version"
        ],
        "properties": {
          "phase": {
            "enum": ["pre-pr", "open-pr", "post-pr-review", "review-pr", "local-attest", "stop"]
          },
          "n": {
            "type": "integer",
            "minimum": 1
          },
          "at": {
            "type": "string",
            "format": "date-time"
          },
          "head_sha": {
            "type": "string",
            "pattern": "^[0-9a-f]{40}$"
          },
          "base_ref": {
            "oneOf": [{ "type": "string", "pattern": "^[A-Za-z0-9._/-]+$" }, { "type": "null" }]
          },
          "merge_base": {
            "oneOf": [{ "type": "string", "pattern": "^[0-9a-f]{40}$" }, { "type": "null" }]
          },
          "outcome": {
            "enum": ["pass", "fail", "blocked", "skipped"]
          },
          "reason_code": {
            "oneOf": [{ "type": "string", "pattern": "^[A-Z][A-Z0-9_]*$" }, { "type": "null" }]
          },
          "evidence": {
            "type": "array",
            "items": {
              "type": "string",
              "pattern": "^\\S+$"
            }
          },
          "requested_model": {
            "oneOf": [{ "type": "string", "pattern": "^[A-Za-z0-9._:/-]+$" }, { "type": "null" }]
          },
          "tool_version": {
            "oneOf": [{ "type": "string", "pattern": "^[0-9A-Za-z.+-]+$" }, { "type": "null" }]
          },
          "decisions": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": ["step", "answer", "confidence", "decider", "fallback", "shadow"],
              "properties": {
                "step": {
                  "enum": ["review-triage", "retry", "dispatch"]
                },
                "answer": {
                  "oneOf": [
                    {
                      "enum": [
                        "auto-valid",
                        "auto-false-positive",
                        "full-validation",
                        "retry",
                        "fix",
                        "ask-owner"
                      ]
                    },
                    {
                      "type": "array",
                      "maxItems": 100,
                      "items": {
                        "type": "string",
                        "pattern": "^[a-z][a-z0-9-]{0,63}$"
                      }
                    }
                  ]
                },
                "confidence": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 1
                },
                "decider": {
                  "enum": ["builtin", "jev"]
                },
                "fallback": {
                  "type": "boolean"
                },
                "shadow": {
                  "oneOf": [
                    {
                      "type": "null"
                    },
                    {
                      "type": "object",
                      "additionalProperties": false,
                      "required": ["decider", "answer", "confidence"],
                      "properties": {
                        "decider": {
                          "const": "jev"
                        },
                        "answer": {
                          "oneOf": [
                            {
                              "enum": [
                                "auto-valid",
                                "auto-false-positive",
                                "full-validation",
                                "retry",
                                "fix",
                                "ask-owner"
                              ]
                            },
                            {
                              "type": "array",
                              "maxItems": 100,
                              "items": {
                                "type": "string",
                                "pattern": "^[a-z][a-z0-9-]{0,63}$"
                              }
                            }
                          ]
                        },
                        "confidence": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 1
                        }
                      }
                    }
                  ]
                }
              },
              "allOf": [
                {
                  "if": {
                    "properties": {
                      "step": {
                        "const": "review-triage"
                      }
                    }
                  },
                  "then": {
                    "properties": {
                      "answer": {
                        "enum": ["auto-valid", "auto-false-positive", "full-validation"]
                      },
                      "shadow": {
                        "if": {
                          "type": "object"
                        },
                        "then": {
                          "properties": {
                            "answer": {
                              "enum": ["auto-valid", "auto-false-positive", "full-validation"]
                            }
                          },
                          "type": "object"
                        }
                      }
                    }
                  }
                },
                {
                  "if": {
                    "properties": {
                      "step": {
                        "const": "retry"
                      }
                    }
                  },
                  "then": {
                    "properties": {
                      "answer": {
                        "enum": ["retry", "fix", "ask-owner"]
                      },
                      "shadow": {
                        "if": {
                          "type": "object"
                        },
                        "then": {
                          "properties": {
                            "answer": {
                              "enum": ["retry", "fix", "ask-owner"]
                            }
                          },
                          "type": "object"
                        }
                      }
                    }
                  }
                },
                {
                  "if": {
                    "properties": {
                      "step": {
                        "const": "dispatch"
                      }
                    }
                  },
                  "then": {
                    "properties": {
                      "answer": {
                        "type": "array"
                      },
                      "shadow": {
                        "if": {
                          "type": "object"
                        },
                        "then": {
                          "properties": {
                            "answer": {
                              "type": "array"
                            }
                          },
                          "type": "object"
                        }
                      }
                    }
                  }
                }
              ]
            }
          }
        }
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "schema_version": {
            "const": 2
          }
        }
      },
      "then": {
        "properties": {
          "attempts": {
            "items": {
              "required": ["decisions"],
              "type": "object"
            },
            "type": "array"
          }
        }
      }
    }
  ]
}
