{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://x07.io/spec/x07.xtal.improve_summary@0.1.0.schema.json",
  "title": "x07.xtal.improve_summary@0.1.0",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "generated_at",
    "ok",
    "input",
    "incidents",
    "triage",
    "reduction",
    "verify",
    "repair",
    "certify",
    "governance",
    "files"
  ],
  "properties": {
    "schema_version": { "const": "x07.xtal.improve_summary@0.1.0" },
    "generated_at": {
      "type": "string",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
    },
    "ok": { "type": "boolean" },
    "input": { "$ref": "#/$defs/input_ref" },
    "incidents": { "type": "array", "items": { "$ref": "#/$defs/incident_ref" } },
    "triage": { "$ref": "#/$defs/triage_ref" },
    "reduction": { "$ref": "#/$defs/reduction_ref" },
    "verify": { "$ref": "#/$defs/verify_ref" },
    "repair": { "$ref": "#/$defs/repair_ref" },
    "certify": { "$ref": "#/$defs/certify_ref" },
    "governance": { "$ref": "#/$defs/governance_ref" },
    "files": { "type": "array", "items": { "$ref": "#/$defs/file_digest" } }
  },
  "$defs": {
    "sha256_hex": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "file_digest": {
      "type": "object",
      "additionalProperties": false,
      "required": ["path", "sha256", "bytes_len"],
      "properties": {
        "path": { "type": "string", "minLength": 1, "maxLength": 4096 },
        "sha256": { "$ref": "#/$defs/sha256_hex" },
        "bytes_len": { "type": "integer", "minimum": 0 }
      }
    },
    "input_ref": {
      "type": "object",
      "additionalProperties": false,
      "required": ["path", "kind"],
      "properties": {
        "path": { "type": "string", "minLength": 1, "maxLength": 4096 },
        "kind": {
          "type": "string",
          "enum": ["violation", "contract_repro", "recovery_events", "dir"]
        }
      }
    },
    "source_ref": {
      "type": "object",
      "additionalProperties": true,
      "required": ["mode"],
      "properties": {
        "mode": { "type": "string", "enum": ["x07test", "x07run"] },
        "tests_manifest_path": { "type": "string" },
        "test_id": { "type": "string", "minLength": 1, "maxLength": 2048 },
        "test_entry": { "type": "string", "minLength": 1, "maxLength": 2048 },
        "target_kind": { "type": "string", "enum": ["project", "program", "artifact"] },
        "target_path": { "type": "string" }
      }
    },
    "contract_ref": {
      "type": "object",
      "additionalProperties": false,
      "required": ["fn", "contract_kind", "clause_id", "clause_ptr", "witness_count"],
      "properties": {
        "fn": { "type": "string", "minLength": 1, "maxLength": 2048 },
        "contract_kind": {
          "type": "string",
          "enum": ["requires", "ensures", "invariant_entry", "invariant_exit"]
        },
        "clause_id": { "type": "string", "minLength": 1, "maxLength": 2048 },
        "clause_ptr": { "type": "string", "minLength": 1, "maxLength": 2048 },
        "witness_count": { "type": "integer", "minimum": 0 }
      }
    },
    "incident_ref": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "clause_id", "world", "contract"],
      "properties": {
        "id": { "$ref": "#/$defs/sha256_hex" },
        "clause_id": { "type": "string", "minLength": 1, "maxLength": 2048 },
        "world": { "type": "string", "minLength": 1, "maxLength": 256 },
        "contract": { "$ref": "#/$defs/contract_ref" }
      }
    },
    "triage_ref": {
      "type": "object",
      "additionalProperties": false,
      "required": ["source", "contract"],
      "properties": {
        "source": { "$ref": "#/$defs/source_ref" },
        "contract": { "$ref": "#/$defs/contract_ref" }
      }
    },
    "reduction_ref": {
      "type": "object",
      "additionalProperties": false,
      "required": ["status"],
      "properties": {
        "status": {
          "type": "string",
          "enum": ["skipped", "ok", "failed", "unsupported"]
        },
        "repro_min_path": { "type": "string", "minLength": 1, "maxLength": 4096 },
        "report_path": { "type": "string", "minLength": 1, "maxLength": 4096 }
      }
    },
    "verify_ref": {
      "type": "object",
      "additionalProperties": false,
      "required": ["status"],
      "properties": {
        "status": { "type": "string", "enum": ["skipped", "ok", "failed"] },
        "diag_path": { "type": "string", "minLength": 1, "maxLength": 4096 },
        "summary_path": { "type": "string", "minLength": 1, "maxLength": 4096 }
      }
    },
    "repair_ref": {
      "type": "object",
      "additionalProperties": false,
      "required": ["status"],
      "properties": {
        "status": { "type": "string", "enum": ["skipped", "ok", "failed"] },
        "diag_path": { "type": "string", "minLength": 1, "maxLength": 4096 },
        "summary_path": { "type": "string", "minLength": 1, "maxLength": 4096 },
        "patchset_path": { "type": "string", "minLength": 1, "maxLength": 4096 }
      }
    },
    "certify_ref": {
      "type": "object",
      "additionalProperties": false,
      "required": ["status"],
      "properties": {
        "status": { "type": "string", "enum": ["skipped", "ok", "failed"] },
        "diag_path": { "type": "string", "minLength": 1, "maxLength": 4096 },
        "summary_path": { "type": "string", "minLength": 1, "maxLength": 4096 },
        "bundle_path": { "type": "string", "minLength": 1, "maxLength": 4096 }
      }
    },
    "governance_ref": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "write_requested",
        "spec_change_detected",
        "spec_change_allowed",
        "applied"
      ],
      "properties": {
        "write_requested": { "type": "boolean" },
        "spec_change_detected": { "type": "boolean" },
        "spec_change_allowed": { "type": "boolean" },
        "applied": { "type": "boolean" }
      }
    }
  }
}
