{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://x07.io/spec/x07.xtal.ingest_summary@0.1.0.schema.json",
  "title": "x07.xtal.ingest_summary@0.1.0",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema_version", "generated_at", "ok", "input", "ingested", "files"],
  "properties": {
    "schema_version": {
      "type": "string",
      "const": "x07.xtal.ingest_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" },
    "ingested": { "$ref": "#/$defs/ingested_ref" },
    "files": { "type": "array", "items": { "$ref": "#/$defs/file_digest" } },
    "integrity": { "$ref": "#/$defs/integrity_ref" }
  },
  "$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 }
      }
    },
    "tool_ref": {
      "type": "object",
      "additionalProperties": false,
      "required": ["x07_version", "x07c_version"],
      "properties": {
        "x07_version": { "type": "string" },
        "x07c_version": { "type": "string" },
        "git_sha": { "type": "string", "pattern": "^[0-9a-fA-F]{7,40}$" }
      }
    },
    "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_ptr", "witness_count"],
      "properties": {
        "fn": { "type": "string", "minLength": 1, "maxLength": 2048 },
        "contract_kind": {
          "type": "string",
          "enum": ["requires", "ensures", "invariant_entry", "invariant_exit"]
        },
        "clause_ptr": { "type": "string", "minLength": 1, "maxLength": 2048 },
        "witness_count": { "type": "integer", "minimum": 0 }
      }
    },
    "integrity_check": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "ok"],
      "properties": {
        "name": { "type": "string", "minLength": 1, "maxLength": 128 },
        "ok": { "type": "boolean" },
        "details": {}
      }
    },
    "integrity_ref": {
      "type": "object",
      "additionalProperties": false,
      "required": ["ok", "checks"],
      "properties": {
        "ok": { "type": "boolean" },
        "expected_repro_sha256": { "$ref": "#/$defs/sha256_hex" },
        "actual_repro_sha256": { "$ref": "#/$defs/sha256_hex" },
        "checks": {
          "type": "array",
          "default": [],
          "items": { "$ref": "#/$defs/integrity_check" }
        }
      }
    },
    "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"]
        },
        "violation": { "$ref": "#/$defs/file_digest" },
        "repro": { "$ref": "#/$defs/file_digest" },
        "events": { "$ref": "#/$defs/file_digest" }
      }
    },
    "ingested_ref": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "dir", "violation_path", "repro_path", "clause_id", "world"],
      "properties": {
        "id": { "$ref": "#/$defs/sha256_hex" },
        "dir": { "type": "string", "minLength": 1, "maxLength": 4096 },
        "violation_path": { "type": "string", "minLength": 1, "maxLength": 4096 },
        "repro_path": { "type": "string", "minLength": 1, "maxLength": 4096 },
        "clause_id": { "type": "string", "minLength": 1, "maxLength": 512 },
        "world": { "type": "string", "minLength": 1, "maxLength": 256 },
        "violation": { "$ref": "#/$defs/file_digest" },
        "repro": { "$ref": "#/$defs/file_digest" },
        "events": { "$ref": "#/$defs/file_digest" },
        "tool": { "$ref": "#/$defs/tool_ref" },
        "source": { "$ref": "#/$defs/source_ref" },
        "contract": { "$ref": "#/$defs/contract_ref" }
      }
    }
  }
}
