{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://oshun.invalid/schemas/eve-engineering-outcome-cohort.v1.json",
  "title": "Eve paired engineering outcome cohort preparation documents",
  "oneOf": [
    { "$ref": "#/$defs/protocol" },
    { "$ref": "#/$defs/readiness" },
    { "$ref": "#/$defs/preparationEvidence" }
  ],
  "$defs": {
    "sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
    "sourceBinding": {
      "type": "object",
      "additionalProperties": false,
      "required": ["path", "sha256"],
      "properties": {
        "path": { "type": "string", "minLength": 1 },
        "selector": { "type": "string", "pattern": "^task-clause:[0-9]+\\.[0-9]+$" },
        "sha256": { "$ref": "#/$defs/sha256" }
      }
    },
    "threshold": {
      "type": "object",
      "required": ["operator", "value"],
      "properties": {
        "operator": { "enum": [">=", "<=", "="] },
        "value": { "type": "number" },
        "statistic": { "type": "string", "minLength": 1 },
        "hardLock": { "type": "boolean" }
      }
    },
    "metric": {
      "type": "object",
      "required": [
        "id",
        "status",
        "definition",
        "primaryUnit",
        "target",
        "floor",
        "requiredEvidence",
        "manualComparison"
      ],
      "properties": {
        "id": {
          "enum": [
            "verified-success",
            "human-interventions",
            "escaped-defects",
            "revert-rate",
            "changed-lines-quality",
            "elapsed-time",
            "tokens-and-cost",
            "test-selection",
            "explanation-fidelity"
          ]
        },
        "status": { "const": "preregistered-unmeasured" },
        "definition": { "type": "string", "minLength": 1 },
        "primaryUnit": { "type": "string", "minLength": 1 },
        "target": { "$ref": "#/$defs/threshold" },
        "floor": { "$ref": "#/$defs/threshold" },
        "requiredEvidence": {
          "type": "array",
          "minItems": 1,
          "items": { "type": "string", "minLength": 1 }
        },
        "manualComparison": { "type": "string", "minLength": 1 },
        "observationWindowDays": { "type": "integer", "minimum": 1 },
        "rightCensoredDisposition": { "type": "string", "minLength": 1 },
        "comparison": { "type": "string", "minLength": 1 },
        "hardLocks": { "type": "object", "additionalProperties": { "type": "integer" } },
        "tokenFields": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 }
        },
        "requiredTestMissesAllowed": { "type": "integer", "minimum": 0 },
        "oracleSource": { "type": "string", "minLength": 1 }
      }
    },
    "admission": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "dependencyTasks",
        "taskCheckbox",
        "closureManifestPresent",
        "promotionClaimed"
      ],
      "properties": {
        "status": { "const": "blocked-by-dependencies" },
        "dependencyTasks": {
          "prefixItems": [
            { "const": "11.4" },
            { "const": "11.5" },
            { "const": "11.12" },
            { "const": "12.2" }
          ],
          "items": false,
          "minItems": 4,
          "maxItems": 4
        },
        "taskCheckbox": { "const": "open" },
        "closureManifestPresent": { "const": false },
        "promotionClaimed": { "const": false }
      }
    },
    "protocol": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "schemaVersion",
        "documentType",
        "contractVersion",
        "taskId",
        "frozenAt",
        "status",
        "admission",
        "sourceBindings",
        "benchmark",
        "scorecard",
        "cohortDesign",
        "metrics",
        "promotion",
        "limitations"
      ],
      "properties": {
        "schemaVersion": { "const": "eve.engineering-outcome-cohort.v1" },
        "documentType": { "const": "protocol" },
        "contractVersion": { "const": "1.0.0" },
        "taskId": { "const": "11.6" },
        "frozenAt": { "type": "string", "format": "date-time" },
        "status": { "const": "preparation-frozen" },
        "admission": { "$ref": "#/$defs/admission" },
        "sourceBindings": {
          "type": "array",
          "minItems": 1,
          "items": { "$ref": "#/$defs/sourceBinding" }
        },
        "benchmark": { "type": "object", "minProperties": 8 },
        "scorecard": { "type": "object", "minProperties": 4 },
        "cohortDesign": { "type": "object", "minProperties": 12 },
        "metrics": {
          "type": "array",
          "minItems": 9,
          "maxItems": 9,
          "items": { "$ref": "#/$defs/metric" }
        },
        "promotion": { "type": "object", "minProperties": 7 },
        "limitations": {
          "type": "array",
          "minItems": 4,
          "items": { "type": "string", "minLength": 1 }
        }
      }
    },
    "readiness": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "schemaVersion",
        "documentType",
        "taskId",
        "assessedAt",
        "admission",
        "observations",
        "blockers",
        "nextRequiredEvidence"
      ],
      "properties": {
        "schemaVersion": { "const": "eve.engineering-outcome-cohort.v1" },
        "documentType": { "const": "readiness" },
        "taskId": { "const": "11.6" },
        "assessedAt": { "type": "string", "format": "date-time" },
        "admission": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "status",
            "openDependencies",
            "promotionDecision",
            "taskCheckbox",
            "closureManifestPresent"
          ],
          "properties": {
            "status": { "const": "blocked-by-dependencies" },
            "openDependencies": {
              "type": "array",
              "minItems": 4,
              "maxItems": 4,
              "items": { "type": "string" }
            },
            "promotionDecision": { "const": "HOLD" },
            "taskCheckbox": { "const": "open" },
            "closureManifestPresent": { "const": false }
          }
        },
        "observations": { "type": "object", "minProperties": 10 },
        "blockers": {
          "type": "array",
          "minItems": 5,
          "items": { "type": "string", "minLength": 1 }
        },
        "nextRequiredEvidence": {
          "type": "array",
          "minItems": 4,
          "items": { "type": "string", "minLength": 1 }
        }
      }
    },
    "locatedArtifact": {
      "type": "object",
      "additionalProperties": false,
      "required": ["locator", "sha256", "bytes"],
      "properties": {
        "locator": { "type": "string", "minLength": 1 },
        "selector": { "type": "string", "pattern": "^task-clause:[0-9]+\\.[0-9]+$" },
        "sha256": { "$ref": "#/$defs/sha256" },
        "bytes": { "type": "integer", "minimum": 1 }
      }
    },
    "execution": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "kind",
        "expected",
        "observed",
        "exitCode",
        "startedAt",
        "completedAt",
        "logPath",
        "logSha256"
      ],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "kind": { "enum": ["verification", "negative-control"] },
        "expected": { "enum": ["pass", "fail"] },
        "observed": { "enum": ["pass", "fail"] },
        "exitCode": { "type": "integer" },
        "startedAt": { "type": "string", "format": "date-time" },
        "completedAt": { "type": "string", "format": "date-time" },
        "logPath": { "type": "string", "minLength": 1 },
        "logSha256": { "$ref": "#/$defs/sha256" }
      }
    },
    "preparationEvidence": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "schemaVersion",
        "documentType",
        "taskId",
        "generatedAt",
        "admission",
        "sourceArtifacts",
        "executions",
        "allExpectedOutcomesObserved"
      ],
      "properties": {
        "schemaVersion": { "const": "eve.engineering-outcome-cohort.v1" },
        "documentType": { "const": "preparation-evidence" },
        "taskId": { "const": "11.6" },
        "generatedAt": { "type": "string", "format": "date-time" },
        "admission": { "$ref": "#/$defs/admission" },
        "sourceArtifacts": {
          "type": "array",
          "minItems": 1,
          "items": { "$ref": "#/$defs/locatedArtifact" }
        },
        "executions": {
          "type": "array",
          "minItems": 1,
          "items": { "$ref": "#/$defs/execution" }
        },
        "allExpectedOutcomesObserved": { "const": true }
      }
    }
  }
}
