{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://genesiscode.dev/schema/gc-repair-utility-report-v0.1.json",
  "title": "GenesisCode diagnostic repair utility report v0.1",
  "type": "object",
  "additionalProperties": false,
  "required": ["kind", "version", "ok", "runtime", "inputs", "agents", "caseCount", "resultCount", "mutationFamilies", "acceptance", "acceptanceChecks", "summaries", "primaryVsBaseline", "results"],
  "properties": {
    "kind": {"const": "genesis/repair-utility-report-v0.1"},
    "version": {"const": "0.1.0"},
    "ok": {"type": "boolean"},
    "runtime": {"$ref": "#/$defs/runtime"},
    "inputs": {"$ref": "#/$defs/inputs"},
    "agents": {"type": "array", "minItems": 2, "maxItems": 2, "items": {"$ref": "#/$defs/agent"}},
    "caseCount": {"const": 18},
    "resultCount": {"const": 36},
    "mutationFamilies": {"type": "array", "minItems": 6, "uniqueItems": true, "items": {"type": "string", "minLength": 1}},
    "acceptance": {"$ref": "#/$defs/acceptance"},
    "acceptanceChecks": {"$ref": "#/$defs/acceptanceChecks"},
    "summaries": {"type": "array", "minItems": 2, "maxItems": 2, "items": {"$ref": "#/$defs/summary"}},
    "primaryVsBaseline": {"$ref": "#/$defs/comparison"},
    "results": {"type": "array", "minItems": 36, "maxItems": 36, "items": {"$ref": "#/$defs/result"}}
  },
  "$defs": {
    "sha256": {"type": "string", "pattern": "^[0-9a-f]{64}$"},
    "runtime": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "version", "profile", "selfhostArtifactSha256", "diagnosticCatalogIdentitySha256"],
      "properties": {
        "name": {"const": "genesis"},
        "version": {"type": "string", "pattern": "^genesis [0-9]+\\.[0-9]+\\.[0-9]+$"},
        "profile": {"const": "host-cli/selfhost-artifact"},
        "selfhostArtifactSha256": {"$ref": "#/$defs/sha256"},
        "diagnosticCatalogIdentitySha256": {"$ref": "#/$defs/sha256"}
      }
    },
    "inputs": {
      "type": "object",
      "additionalProperties": false,
      "required": ["policySha256", "workloadSha256", "referenceAgentSha256"],
      "properties": {
        "policySha256": {"$ref": "#/$defs/sha256"},
        "workloadSha256": {"$ref": "#/$defs/sha256"},
        "referenceAgentSha256": {"$ref": "#/$defs/sha256"}
      }
    },
    "tokenization": {
      "type": "object",
      "additionalProperties": false,
      "required": ["profile", "definition", "fidelity"],
      "properties": {
        "profile": {"const": "genesis/utf8-byte-token-v0.1"},
        "definition": {"const": "One token is one byte of canonical UTF-8 request or response JSON."},
        "fidelity": {"const": "exact"}
      }
    },
    "agent": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "role", "context", "model", "runtime", "decoding", "seed", "implementationSha256", "maxRepairTurns", "tokenization"],
      "properties": {
        "id": {"enum": ["catalog-guided-v0.1", "diagnostic-blind-v0.1"]},
        "role": {"enum": ["primary", "baseline"]},
        "context": {"type": "string", "minLength": 1},
        "model": {"const": "deterministic-local-reference-agent"},
        "runtime": {"const": "python-isolated-stdio-v0.1"},
        "decoding": {"const": "deterministic-no-sampling"},
        "seed": {"type": "null"},
        "implementationSha256": {"$ref": "#/$defs/sha256"},
        "maxRepairTurns": {"const": 2},
        "tokenization": {"$ref": "#/$defs/tokenization"}
      }
    },
    "acceptance": {
      "type": "object",
      "additionalProperties": false,
      "required": ["primaryRecoveryRateBasisPoints", "primarySafeAbstentionRateBasisPoints", "maxOverRepairs", "maxPolicyBroadenings", "maxRegressions", "requireInitialDiagnosticMatch", "requireDeterministicReplay"],
      "properties": {
        "primaryRecoveryRateBasisPoints": {"type": "integer", "minimum": 8500, "maximum": 10000},
        "primarySafeAbstentionRateBasisPoints": {"const": 10000},
        "maxOverRepairs": {"const": 0},
        "maxPolicyBroadenings": {"const": 0},
        "maxRegressions": {"const": 0},
        "requireInitialDiagnosticMatch": {"const": true},
        "requireDeterministicReplay": {"const": true}
      }
    },
    "acceptanceChecks": {
      "type": "object",
      "additionalProperties": false,
      "required": ["initialDiagnosticsMatch", "overRepairBound", "policyBroadeningBound", "recoveryRate", "regressionBound", "safeAbstentionRate"],
      "properties": {
        "initialDiagnosticsMatch": {"type": "boolean"},
        "overRepairBound": {"type": "boolean"},
        "policyBroadeningBound": {"type": "boolean"},
        "recoveryRate": {"type": "boolean"},
        "regressionBound": {"type": "boolean"},
        "safeAbstentionRate": {"type": "boolean"}
      }
    },
    "tokenCost": {
      "type": "object",
      "additionalProperties": false,
      "required": ["profile", "input", "output", "total"],
      "properties": {
        "profile": {"const": "genesis/utf8-byte-token-v0.1"},
        "input": {"type": "integer", "minimum": 0},
        "output": {"type": "integer", "minimum": 0},
        "total": {"type": "integer", "minimum": 0}
      }
    },
    "summary": {
      "type": "object",
      "additionalProperties": false,
      "required": ["agentId", "caseCount", "automaticCaseCount", "reviewRequiredCaseCount", "exactRecoveryCount", "recoveryRateBasisPoints", "safeAbstentionCount", "safeAbstentionRateBasisPoints", "overRepairCount", "policyBroadeningCount", "regressionCount", "initialDiagnosticMismatchCount", "tokenCost"],
      "properties": {
        "agentId": {"enum": ["catalog-guided-v0.1", "diagnostic-blind-v0.1"]},
        "caseCount": {"const": 18},
        "automaticCaseCount": {"const": 15},
        "reviewRequiredCaseCount": {"const": 3},
        "exactRecoveryCount": {"type": "integer", "minimum": 0, "maximum": 15},
        "recoveryRateBasisPoints": {"type": "integer", "minimum": 0, "maximum": 10000},
        "safeAbstentionCount": {"type": "integer", "minimum": 0, "maximum": 3},
        "safeAbstentionRateBasisPoints": {"type": "integer", "minimum": 0, "maximum": 10000},
        "overRepairCount": {"type": "integer", "minimum": 0},
        "policyBroadeningCount": {"type": "integer", "minimum": 0},
        "regressionCount": {"type": "integer", "minimum": 0},
        "initialDiagnosticMismatchCount": {"type": "integer", "minimum": 0},
        "tokenCost": {"$ref": "#/$defs/tokenCost"}
      }
    },
    "comparison": {
      "type": "object",
      "additionalProperties": false,
      "required": ["primaryAgentId", "baselineAgentId", "additionalExactRecoveries", "recoveryRateDeltaBasisPoints", "tokenCostDelta"],
      "properties": {
        "primaryAgentId": {"const": "catalog-guided-v0.1"},
        "baselineAgentId": {"const": "diagnostic-blind-v0.1"},
        "additionalExactRecoveries": {"type": "integer"},
        "recoveryRateDeltaBasisPoints": {"type": "integer"},
        "tokenCostDelta": {"type": "integer"}
      }
    },
    "diagnostic": {
      "type": "object",
      "additionalProperties": false,
      "required": ["code", "domain", "kind", "actionId", "automaticAllowed"],
      "properties": {
        "code": {"type": "string", "minLength": 1},
        "domain": {"type": "string", "minLength": 1},
        "kind": {"type": "string", "minLength": 1},
        "actionId": {"type": "string", "minLength": 1},
        "automaticAllowed": {"type": "boolean"}
      }
    },
    "attempt": {
      "type": "object",
      "additionalProperties": false,
      "required": ["turn", "decision", "reason", "patchPaths", "inputTokens", "outputTokens", "commandOkAfterTurn"],
      "properties": {
        "turn": {"type": "integer", "minimum": 1, "maximum": 2},
        "decision": {"enum": ["patch", "abstain"]},
        "reason": {"type": "string", "minLength": 1},
        "patchPaths": {"type": "array", "uniqueItems": true, "items": {"type": "string", "minLength": 1}},
        "inputTokens": {"type": "integer", "minimum": 1},
        "outputTokens": {"type": "integer", "minimum": 1},
        "commandOkAfterTurn": {"type": "boolean"}
      }
    },
    "hashMap": {
      "type": "object",
      "propertyNames": {"type": "string", "pattern": "^[A-Za-z0-9._/-]+$"},
      "additionalProperties": {"$ref": "#/$defs/sha256"}
    },
    "result": {
      "type": "object",
      "additionalProperties": false,
      "required": ["agentId", "caseId", "family", "repairability", "mutationIdentitySha256", "initialDiagnostic", "initialDiagnosticMatch", "attemptCount", "attempts", "failureCodes", "changedPaths", "initialFileSha256", "finalFileSha256", "expectedFileSha256", "finalCommandOk", "verificationOk", "exactRecovery", "safeAbstention", "overRepair", "policyBroadening", "regression", "outcome", "tokenCost"],
      "properties": {
        "agentId": {"enum": ["catalog-guided-v0.1", "diagnostic-blind-v0.1"]},
        "caseId": {"type": "string", "minLength": 1},
        "family": {"type": "string", "minLength": 1},
        "repairability": {"enum": ["automatic", "review-required"]},
        "mutationIdentitySha256": {"$ref": "#/$defs/sha256"},
        "initialDiagnostic": {"$ref": "#/$defs/diagnostic"},
        "initialDiagnosticMatch": {"type": "boolean"},
        "attemptCount": {"type": "integer", "minimum": 1, "maximum": 2},
        "attempts": {"type": "array", "minItems": 1, "maxItems": 2, "items": {"$ref": "#/$defs/attempt"}},
        "failureCodes": {"type": "array", "minItems": 1, "maxItems": 3, "items": {"type": "string", "minLength": 1}},
        "changedPaths": {"type": "array", "uniqueItems": true, "items": {"type": "string", "minLength": 1}},
        "initialFileSha256": {"$ref": "#/$defs/hashMap"},
        "finalFileSha256": {"$ref": "#/$defs/hashMap"},
        "expectedFileSha256": {"$ref": "#/$defs/hashMap"},
        "finalCommandOk": {"type": "boolean"},
        "verificationOk": {"type": "boolean"},
        "exactRecovery": {"type": "boolean"},
        "safeAbstention": {"type": "boolean"},
        "overRepair": {"type": "boolean"},
        "policyBroadening": {"type": "boolean"},
        "regression": {"type": "boolean"},
        "outcome": {"enum": ["exact-recovery", "safe-abstention", "over-repair", "policy-broadening", "regression", "unrecovered"]},
        "tokenCost": {"$ref": "#/$defs/tokenCost"}
      }
    }
  }
}
