{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://example.com/agent-governance-starter/governance-impact-result.schema.json",
  "title": "Governance Impact Recomputed Result",
  "type": "object",
  "required": [
    "schemaVersion",
    "runId",
    "attemptId",
    "repetitionId",
    "seed",
    "scenarioHash",
    "arms",
    "comparison"
  ],
  "properties": {
    "schemaVersion": { "type": "integer", "enum": [1, 2] },
    "runId": { "$ref": "#/$defs/identifier" },
    "attemptId": { "$ref": "#/$defs/sha256" },
    "repetitionId": { "$ref": "#/$defs/identifier" },
    "seed": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991
    },
    "scenarioHash": { "$ref": "#/$defs/sha256" },
    "arms": {
      "type": "object",
      "required": ["baseline", "governed"],
      "properties": {
        "baseline": {},
        "governed": {}
      },
      "additionalProperties": false
    },
    "comparison": { "$ref": "#/$defs/comparison" }
  },
  "allOf": [
    {
      "if": {
        "properties": { "schemaVersion": { "const": 1 } },
        "required": ["schemaVersion"]
      },
      "then": {
        "properties": {
          "arms": {
            "properties": {
              "baseline": { "$ref": "#/$defs/scoredArm" },
              "governed": { "$ref": "#/$defs/scoredArm" }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": { "schemaVersion": { "const": 2 } },
        "required": ["schemaVersion"]
      },
      "then": {
        "properties": {
          "arms": {
            "properties": {
              "baseline": { "$ref": "#/$defs/scoredArmV2" },
              "governed": { "$ref": "#/$defs/scoredArmV2" }
            }
          }
        }
      }
    }
  ],
  "$defs": {
    "sha256": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    },
    "identifier": {
      "type": "string",
      "minLength": 1,
      "pattern": "^(?!\\s)(?!.*\\s$)[^\\u0000]+$"
    },
    "scoredArm": {
      "type": "object",
      "required": [
        "scenarioHash",
        "runtime",
        "model",
        "config",
        "starterCommit",
        "execution",
        "acceptance",
        "requirements",
        "scope",
        "prohibitions",
        "documents",
        "privacy",
        "repairRounds",
        "firstPassSuccess",
        "time",
        "tokens",
        "deliveryScore",
        "deliveryPass"
      ],
      "properties": {
        "scenarioHash": { "$ref": "#/$defs/sha256" },
        "runtime": {
          "type": "string",
          "enum": ["synthetic", "codex", "claude", "antigravity"]
        },
        "model": { "$ref": "#/$defs/identifier" },
        "config": { "$ref": "#/$defs/identifier" },
        "starterCommit": {
          "type": "string",
          "pattern": "^(?:[a-f0-9]{40}|[a-f0-9]{64})$"
        },
        "execution": { "$ref": "#/$defs/execution" },
        "acceptance": { "$ref": "#/$defs/acceptanceSummary" },
        "requirements": { "$ref": "#/$defs/requirementSummary" },
        "scope": { "$ref": "#/$defs/scopeSummary" },
        "prohibitions": { "$ref": "#/$defs/prohibitionSummary" },
        "documents": { "$ref": "#/$defs/documentSummary" },
        "privacy": { "$ref": "#/$defs/checkSummary" },
        "repairRounds": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "firstPassSuccess": { "type": "boolean" },
        "time": { "$ref": "#/$defs/timeTelemetry" },
        "tokens": { "$ref": "#/$defs/tokenTelemetry" },
        "deliveryScore": { "type": "number", "minimum": 0, "maximum": 100 },
        "deliveryPass": { "type": "boolean" }
      },
      "additionalProperties": false
    },
    "scoredArmV2": {
      "type": "object",
      "required": [
        "scenarioHash",
        "runtime",
        "model",
        "config",
        "starterCommit",
        "executionBoundaryId",
        "boundaryEvidence",
        "execution",
        "acceptance",
        "requirements",
        "scope",
        "prohibitions",
        "documents",
        "privacy",
        "repairRounds",
        "firstPassSuccess",
        "time",
        "tokens",
        "deliveryScore",
        "deliveryPass"
      ],
      "properties": {
        "scenarioHash": { "$ref": "#/$defs/sha256" },
        "runtime": { "type": "string", "const": "codex" },
        "model": { "$ref": "#/$defs/identifier" },
        "config": { "$ref": "#/$defs/identifier" },
        "starterCommit": {
          "type": "string",
          "pattern": "^(?:[a-f0-9]{40}|[a-f0-9]{64})$"
        },
        "executionBoundaryId": { "$ref": "#/$defs/sha256" },
        "boundaryEvidence": { "$ref": "#/$defs/boundaryEvidence" },
        "execution": { "$ref": "#/$defs/execution" },
        "acceptance": { "$ref": "#/$defs/acceptanceSummary" },
        "requirements": { "$ref": "#/$defs/requirementSummary" },
        "scope": { "$ref": "#/$defs/scopeSummary" },
        "prohibitions": { "$ref": "#/$defs/prohibitionSummary" },
        "documents": { "$ref": "#/$defs/documentSummary" },
        "privacy": { "$ref": "#/$defs/checkSummary" },
        "repairRounds": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "firstPassSuccess": { "type": "boolean" },
        "time": { "$ref": "#/$defs/timeTelemetry" },
        "tokens": { "$ref": "#/$defs/tokenTelemetry" },
        "deliveryScore": { "type": "number", "minimum": 0, "maximum": 100 },
        "deliveryPass": { "type": "boolean" }
      },
      "additionalProperties": false
    },
    "boundaryEvidence": {
      "type": "object",
      "required": [
        "observedImageDigest",
        "codexVersion",
        "codexBinarySha256",
        "containmentPolicyHash",
        "networkPolicyHash",
        "proxyPolicyHash",
        "hardening",
        "pidNamespaceStopped",
        "cgroupEmpty",
        "cleanupComplete"
      ],
      "properties": {
        "observedImageDigest": { "$ref": "#/$defs/sha256" },
        "codexVersion": {
          "type": "string",
          "minLength": 1,
          "pattern": "^(?!\\s)(?!.*\\s$)[^\\r\\n\\\\/\\u0000]+$"
        },
        "codexBinarySha256": { "$ref": "#/$defs/sha256" },
        "containmentPolicyHash": { "$ref": "#/$defs/sha256" },
        "networkPolicyHash": { "$ref": "#/$defs/sha256" },
        "proxyPolicyHash": { "$ref": "#/$defs/sha256" },
        "hardening": {
          "type": "object",
          "required": [
            "nonRootUser",
            "readOnlyRootFilesystem",
            "capDropAll",
            "noNewPrivileges",
            "privatePidNamespace",
            "privateCgroupNamespace",
            "pidLimit",
            "cpuLimit",
            "memoryLimit",
            "dockerSocketAbsent",
            "devicesAbsent",
            "cgroupMountAbsent"
          ],
          "properties": {
            "nonRootUser": { "type": "boolean", "const": true },
            "readOnlyRootFilesystem": { "type": "boolean", "const": true },
            "capDropAll": { "type": "boolean", "const": true },
            "noNewPrivileges": { "type": "boolean", "const": true },
            "privatePidNamespace": { "type": "boolean", "const": true },
            "privateCgroupNamespace": { "type": "boolean", "const": true },
            "pidLimit": { "type": "boolean", "const": true },
            "cpuLimit": { "type": "boolean", "const": true },
            "memoryLimit": { "type": "boolean", "const": true },
            "dockerSocketAbsent": { "type": "boolean", "const": true },
            "devicesAbsent": { "type": "boolean", "const": true },
            "cgroupMountAbsent": { "type": "boolean", "const": true }
          },
          "additionalProperties": false
        },
        "pidNamespaceStopped": { "type": "boolean", "const": true },
        "cgroupEmpty": { "type": "boolean", "const": true },
        "cleanupComplete": { "type": "boolean", "const": true }
      },
      "additionalProperties": false
    },
    "execution": {
      "type": "object",
      "required": ["status", "errorCode"],
      "properties": {
        "status": {
          "type": "string",
          "enum": ["completed", "failed", "timeout"]
        },
        "errorCode": {
          "type": ["string", "null"],
          "pattern": "^[A-Z][A-Z0-9_]*$"
        }
      },
      "additionalProperties": false
    },
    "acceptanceSummary": {
      "type": "object",
      "required": ["total", "passed", "failed", "rate", "criticalFailureCount"],
      "properties": {
        "total": { "type": "integer", "minimum": 1, "maximum": 9007199254740991 },
        "passed": { "type": "integer", "minimum": 0, "maximum": 9007199254740991 },
        "failed": { "type": "integer", "minimum": 0, "maximum": 9007199254740991 },
        "rate": { "type": "number", "minimum": 0, "maximum": 1 },
        "criticalFailureCount": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        }
      },
      "additionalProperties": false
    },
    "requirementSummary": {
      "type": "object",
      "required": ["total", "omitted", "omissionRate"],
      "properties": {
        "total": { "type": "integer", "minimum": 1, "maximum": 9007199254740991 },
        "omitted": { "type": "integer", "minimum": 0, "maximum": 9007199254740991 },
        "omissionRate": { "type": "number", "minimum": 0, "maximum": 1 }
      },
      "additionalProperties": false
    },
    "scopeSummary": {
      "type": "object",
      "required": ["changedPathCount", "violationCount", "violationRate", "forbiddenPathCount"],
      "properties": {
        "changedPathCount": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "violationCount": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "violationRate": { "type": "number", "minimum": 0, "maximum": 1 },
        "forbiddenPathCount": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        }
      },
      "additionalProperties": false
    },
    "prohibitionSummary": {
      "type": "object",
      "required": ["total", "violated", "violationRate", "criticalFailureCount"],
      "properties": {
        "total": { "type": "integer", "minimum": 1, "maximum": 9007199254740991 },
        "violated": { "type": "integer", "minimum": 0, "maximum": 9007199254740991 },
        "violationRate": { "type": "number", "minimum": 0, "maximum": 1 },
        "criticalFailureCount": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        }
      },
      "additionalProperties": false
    },
    "documentSummary": {
      "type": "object",
      "required": ["total", "drifted", "criticalDriftCount"],
      "properties": {
        "total": { "type": "integer", "minimum": 0, "maximum": 9007199254740991 },
        "drifted": { "type": "integer", "minimum": 0, "maximum": 9007199254740991 },
        "criticalDriftCount": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        }
      },
      "additionalProperties": false
    },
    "checkSummary": {
      "type": "object",
      "required": ["total", "failed", "criticalFailureCount"],
      "properties": {
        "total": { "type": "integer", "minimum": 1, "maximum": 9007199254740991 },
        "failed": { "type": "integer", "minimum": 0, "maximum": 9007199254740991 },
        "criticalFailureCount": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        }
      },
      "additionalProperties": false
    },
    "timeTelemetry": {
      "oneOf": [
        {
          "type": "object",
          "required": ["availability", "wallTimeMs"],
          "properties": {
            "availability": { "type": "string", "const": "available" },
            "wallTimeMs": {
              "type": "number",
              "minimum": 0,
              "maximum": 9007199254740991
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": ["availability", "wallTimeMs"],
          "properties": {
            "availability": { "type": "string", "const": "unavailable" },
            "wallTimeMs": { "type": "null" }
          },
          "additionalProperties": false
        }
      ]
    },
    "tokenTelemetry": {
      "oneOf": [
        {
          "type": "object",
          "required": ["availability", "total"],
          "properties": {
            "availability": { "type": "string", "const": "available" },
            "total": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": ["availability", "total"],
          "properties": {
            "availability": { "type": "string", "const": "unavailable" },
            "total": { "type": "null" }
          },
          "additionalProperties": false
        }
      ]
    },
    "comparison": {
      "type": "object",
      "required": [
        "winner",
        "reason",
        "comparableFields",
        "deliveryPassDelta",
        "scoreDelta",
        "repairRoundsDelta",
        "timeDeltaMs",
        "tokenDelta"
      ],
      "properties": {
        "winner": { "type": "string", "enum": ["baseline", "governed", "tie"] },
        "reason": {
          "type": "string",
          "enum": ["delivery-pass", "delivery-score", "repair-rounds", "tie"]
        },
        "comparableFields": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "type": "string",
            "enum": ["deliveryPass", "deliveryScore", "repairRounds", "time", "tokens"]
          }
        },
        "deliveryPassDelta": { "type": "integer", "minimum": -1, "maximum": 1 },
        "scoreDelta": { "type": "number", "minimum": -100, "maximum": 100 },
        "repairRoundsDelta": {
          "type": "integer",
          "minimum": -9007199254740991,
          "maximum": 9007199254740991
        },
        "timeDeltaMs": {
          "type": ["number", "null"],
          "minimum": -9007199254740991,
          "maximum": 9007199254740991
        },
        "tokenDelta": {
          "type": ["integer", "null"],
          "minimum": -9007199254740991,
          "maximum": 9007199254740991
        }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
