{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://aiwg.io/schemas/decision/SdlcScreeningRelease.v2.schema.json",
  "title": "SdlcScreeningRelease",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "preregistration",
    "preregistrationDigest",
    "trustedPreregistrationDigest",
    "heldout",
    "integrity",
    "preregisteredDecision",
    "decision",
    "reasons",
    "digest"
  ],
  "properties": {
    "schemaVersion": {
      "const": "decision-sdlc-screening-release/v2"
    },
    "preregistration": {
      "$ref": "#/$defs/preregistration"
    },
    "preregistrationDigest": {
      "$ref": "#/$defs/digest"
    },
    "trustedPreregistrationDigest": {
      "type": "string"
    },
    "heldout": {
      "oneOf": [
        {
          "type": "null"
        },
        {
          "$ref": "#/$defs/heldout"
        }
      ]
    },
    "integrity": {
      "$ref": "#/$defs/integrity"
    },
    "preregisteredDecision": {
      "enum": [
        "pass",
        "fail",
        "insufficient-evidence"
      ]
    },
    "decision": {
      "enum": [
        "PROMOTE",
        "HOLD",
        "ROLLBACK"
      ]
    },
    "reasons": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "digest": {
      "$ref": "#/$defs/digest"
    }
  },
  "$defs": {
    "digest": {
      "type": "string",
      "pattern": "^sha256:[a-f0-9]{64}$"
    },
    "bps": {
      "type": "integer",
      "minimum": 0,
      "maximum": 10000
    },
    "bpsOrNull": {
      "type": [
        "integer",
        "null"
      ],
      "minimum": 0,
      "maximum": 10000
    },
    "stringId": {
      "type": "string",
      "minLength": 1
    },
    "preregistration": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "schemaVersion",
        "planId",
        "frozenAt",
        "heldoutSplitDigest",
        "slices",
        "gateBlockingSlices",
        "maximumFalseSupportRateBps",
        "maximumFalseReadyRateBps",
        "minimumTotalSupport",
        "minimumSliceSupport",
        "minimumGateBlockingSliceSupport",
        "confidenceInterval",
        "qualityNonInferiorityBps",
        "efficiencyClaim"
      ],
      "properties": {
        "schemaVersion": {
          "const": "decision-sdlc-screening-preregistration/v2"
        },
        "planId": {
          "type": "string",
          "minLength": 1
        },
        "frozenAt": {
          "type": "string",
          "format": "date-time"
        },
        "heldoutSplitDigest": {
          "$ref": "#/$defs/digest"
        },
        "slices": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/stringId"
          }
        },
        "gateBlockingSlices": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/stringId"
          }
        },
        "maximumFalseSupportRateBps": {
          "$ref": "#/$defs/bps"
        },
        "maximumFalseReadyRateBps": {
          "$ref": "#/$defs/bps"
        },
        "minimumTotalSupport": {
          "type": "integer",
          "minimum": 1
        },
        "minimumSliceSupport": {
          "type": "integer",
          "minimum": 1
        },
        "minimumGateBlockingSliceSupport": {
          "type": "integer",
          "minimum": 1
        },
        "confidenceInterval": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "method",
            "levelBps"
          ],
          "properties": {
            "method": {
              "enum": [
                "wilson",
                "exact-binomial"
              ]
            },
            "levelBps": {
              "type": "integer",
              "minimum": 1,
              "maximum": 9999
            }
          }
        },
        "qualityNonInferiorityBps": {
          "$ref": "#/$defs/bpsOrNull"
        },
        "efficiencyClaim": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "enabled",
            "minimumPositiveTotalEconomicsUsd"
          ],
          "properties": {
            "enabled": {
              "type": "boolean"
            },
            "minimumPositiveTotalEconomicsUsd": {
              "type": [
                "number",
                "null"
              ],
              "minimum": 0
            }
          }
        }
      }
    },
    "rate": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "events",
        "n",
        "rateBps",
        "upperBps"
      ],
      "properties": {
        "events": {
          "type": "integer",
          "minimum": 0
        },
        "n": {
          "type": "integer",
          "minimum": 0
        },
        "rateBps": {
          "$ref": "#/$defs/bpsOrNull"
        },
        "upperBps": {
          "$ref": "#/$defs/bpsOrNull"
        }
      }
    },
    "classMetric": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "n",
        "precisionBps",
        "recallBps"
      ],
      "properties": {
        "n": {
          "type": "integer",
          "minimum": 0
        },
        "precisionBps": {
          "$ref": "#/$defs/bpsOrNull"
        },
        "recallBps": {
          "$ref": "#/$defs/bpsOrNull"
        }
      }
    },
    "heldout": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "schemaVersion",
        "evaluatedAt",
        "heldoutSplitDigest",
        "recordsDigest",
        "totalSupport",
        "gateBlockingSliceSupport",
        "classes",
        "falseSupport",
        "falseReady",
        "reviewer",
        "paired",
        "calibrationRiskCoverage",
        "slices",
        "latencyMs",
        "tokens",
        "costUsd",
        "reviewLoad"
      ],
      "properties": {
        "schemaVersion": {
          "const": "decision-sdlc-screening-heldout-report/v1"
        },
        "evaluatedAt": {
          "type": "string"
        },
        "heldoutSplitDigest": {
          "$ref": "#/$defs/digest"
        },
        "recordsDigest": {
          "$ref": "#/$defs/digest"
        },
        "totalSupport": {
          "type": "integer",
          "minimum": 0
        },
        "gateBlockingSliceSupport": {
          "type": "integer",
          "minimum": 0
        },
        "classes": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "support",
            "contradiction",
            "unclear"
          ],
          "properties": {
            "support": {
              "$ref": "#/$defs/classMetric"
            },
            "contradiction": {
              "$ref": "#/$defs/classMetric"
            },
            "unclear": {
              "$ref": "#/$defs/classMetric"
            }
          }
        },
        "falseSupport": {
          "$ref": "#/$defs/rate"
        },
        "falseReady": {
          "$ref": "#/$defs/rate"
        },
        "reviewer": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "n",
            "agreementRateBps",
            "overrideRateBps"
          ],
          "properties": {
            "n": {
              "type": "integer",
              "minimum": 0
            },
            "agreementRateBps": {
              "$ref": "#/$defs/bpsOrNull"
            },
            "overrideRateBps": {
              "$ref": "#/$defs/bpsOrNull"
            }
          }
        },
        "paired": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "n",
            "both",
            "candidateOnly",
            "baselineOnly",
            "neither",
            "interval"
          ],
          "properties": {
            "n": {
              "type": "integer",
              "minimum": 0
            },
            "both": {
              "type": "integer",
              "minimum": 0
            },
            "candidateOnly": {
              "type": "integer",
              "minimum": 0
            },
            "baselineOnly": {
              "type": "integer",
              "minimum": 0
            },
            "neither": {
              "type": "integer",
              "minimum": 0
            },
            "interval": {
              "oneOf": [
                {
                  "type": "null"
                },
                {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "lowerBps",
                    "upperBps",
                    "estimateBps",
                    "n",
                    "method"
                  ],
                  "properties": {
                    "lowerBps": {
                      "type": "integer",
                      "minimum": -10000,
                      "maximum": 10000
                    },
                    "upperBps": {
                      "type": "integer",
                      "minimum": -10000,
                      "maximum": 10000
                    },
                    "estimateBps": {
                      "type": "integer",
                      "minimum": -10000,
                      "maximum": 10000
                    },
                    "n": {
                      "type": "integer",
                      "minimum": 1
                    },
                    "method": {
                      "enum": [
                        "newcombe-hybrid-score",
                        "tango-score",
                        "percentile-bootstrap"
                      ]
                    }
                  }
                }
              ]
            }
          }
        },
        "calibrationRiskCoverage": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "brier",
            "expectedCalibrationError",
            "coverage",
            "selectiveRisk"
          ],
          "properties": {
            "brier": {
              "type": "number",
              "minimum": 0
            },
            "expectedCalibrationError": {
              "type": "number",
              "minimum": 0
            },
            "coverage": {
              "type": "number",
              "minimum": 0
            },
            "selectiveRisk": {
              "type": [
                "number",
                "null"
              ],
              "minimum": 0
            }
          }
        },
        "slices": {
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "n",
              "coverage",
              "selectiveRisk"
            ],
            "properties": {
              "n": {
                "type": "integer",
                "minimum": 0
              },
              "coverage": {
                "type": "number",
                "minimum": 0
              },
              "selectiveRisk": {
                "type": [
                  "number",
                  "null"
                ],
                "minimum": 0
              }
            }
          }
        },
        "latencyMs": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "p50",
            "p95",
            "p99"
          ],
          "properties": {
            "p50": {
              "type": "number",
              "minimum": 0
            },
            "p95": {
              "type": "number",
              "minimum": 0
            },
            "p99": {
              "type": "number",
              "minimum": 0
            }
          }
        },
        "tokens": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "input",
            "output"
          ],
          "properties": {
            "input": {
              "type": [
                "integer",
                "null"
              ],
              "minimum": 0
            },
            "output": {
              "type": [
                "integer",
                "null"
              ],
              "minimum": 0
            }
          }
        },
        "costUsd": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "candidate",
            "baseline",
            "netSavings"
          ],
          "properties": {
            "candidate": {
              "type": [
                "number",
                "null"
              ],
              "minimum": 0
            },
            "baseline": {
              "type": [
                "number",
                "null"
              ],
              "minimum": 0
            },
            "netSavings": {
              "type": [
                "number",
                "null"
              ]
            }
          }
        },
        "reviewLoad": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "reviewRate"
          ],
          "properties": {
            "reviewRate": {
              "type": "number",
              "minimum": 0
            }
          }
        }
      }
    },
    "integrity": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "sample_n",
        "uncertainty",
        "paired_baseline",
        "integrity_mode",
        "fresh_workspace_required",
        "fresh_workspace_verified",
        "integrity_state",
        "trusted_score_source",
        "compromise_labels",
        "weak_signal_reason",
        "release_gate"
      ],
      "properties": {
        "sample_n": {
          "type": "integer",
          "minimum": 0
        },
        "uncertainty": {},
        "paired_baseline": {},
        "integrity_mode": {
          "type": "string",
          "minLength": 1
        },
        "fresh_workspace_required": {
          "type": "boolean"
        },
        "fresh_workspace_verified": {
          "type": "boolean"
        },
        "integrity_state": {
          "type": "string",
          "minLength": 1
        },
        "trusted_score_source": {
          "type": "string",
          "minLength": 1
        },
        "compromise_labels": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "weak_signal_reason": {
          "type": [
            "string",
            "null"
          ]
        },
        "release_gate": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "decision",
            "reasons"
          ],
          "properties": {
            "decision": {
              "enum": [
                "PROMOTE",
                "HOLD",
                "ROLLBACK"
              ]
            },
            "reasons": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}
