{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/egohygiene/optiflow/schemas/png-candidate-evidence-v1.schema.json",
  "title": "OptiFlow bounded PNG candidate production evidence v1",
  "description": "Host-produced evidence for one source-preserving PNG candidate. This is distinct from the declaration-only PNG candidate contract and does not authorize source mutation or claim physical space savings.",
  "type": "object",
  "required": ["schema", "artifact_set_id", "profile", "source_observation_id", "source", "effective_policy_fingerprint", "producer", "argv", "input_binding", "output_binding", "provider_configuration", "candidate", "limits", "measurements", "validation", "encoded_logical_reduction_bytes", "physical_savings_bytes", "cleanup"],
  "properties": {
    "schema": { "const": "optiflow.png-candidate-evidence.v1" },
    "artifact_set_id": { "type": "string", "format": "uuid" },
    "profile": { "const": "optiflow.png-idat-preserve.v1" },
    "source_observation_id": { "type": "string", "format": "uuid" },
    "source": { "$ref": "#/$defs/source" },
    "effective_policy_fingerprint": { "$ref": "#/$defs/digest" },
    "producer": { "$ref": "#/$defs/producer" },
    "argv": {
      "type": "array",
      "prefixItems": [
        { "const": "--opt" }, { "const": "2" }, { "const": "--nx" },
        { "const": "--interlace" }, { "const": "keep" },
        { "const": "--threads" }, { "const": "1" },
        { "const": "--max-raw-size" },
        { "type": "string", "pattern": "^[1-9][0-9]{0,17}$" },
        { "const": "--quiet" }, { "const": "--stdout" }, { "const": "-" }
      ],
      "items": false,
      "minItems": 12
    },
    "input_binding": { "const": "complete_bounded_source_bytes_on_stdin" },
    "output_binding": { "const": "bounded_stdout_then_independent_validation" },
    "provider_configuration": { "const": "oxipng_v10.2.1_opt2_nx_keep_interlace_one_thread_no_strip" },
    "candidate": { "$ref": "#/$defs/candidate" },
    "limits": { "$ref": "#/$defs/limits" },
    "measurements": { "$ref": "#/$defs/measurements" },
    "validation": { "$ref": "#/$defs/validation" },
    "encoded_logical_reduction_bytes": { "type": "integer", "minimum": 1, "maximum": 16777216 },
    "physical_savings_bytes": { "type": "null" },
    "cleanup": { "$ref": "#/$defs/cleanup" }
  },
  "additionalProperties": false,
  "$defs": {
    "digest": {
      "type": "object",
      "required": ["algorithm", "value"],
      "properties": {
        "algorithm": { "const": "blake3-256" },
        "value": { "type": "string", "pattern": "^[0-9a-f]{64}$" }
      },
      "additionalProperties": false
    },
    "path": {
      "oneOf": [
        {
          "type": "object",
          "required": ["encoding", "value"],
          "properties": {
            "encoding": { "const": "utf8" },
            "value": { "type": "string", "minLength": 1, "maxLength": 4096 }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": ["encoding", "base64"],
          "properties": {
            "encoding": { "const": "unix_bytes" },
            "base64": {
              "type": "string", "minLength": 4, "maxLength": 5464,
              "pattern": "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$"
            }
          },
          "additionalProperties": false
        }
      ]
    },
    "content": {
      "type": "object",
      "required": ["digest", "logical_bytes"],
      "properties": {
        "digest": { "$ref": "#/$defs/digest" },
        "logical_bytes": { "type": "integer", "minimum": 1, "maximum": 16777216 }
      },
      "additionalProperties": false
    },
    "snapshot": {
      "type": "object",
      "required": ["device_id", "inode", "mode", "owner_uid", "group_gid", "link_count", "size_bytes", "modified_unix_ns", "changed_unix_ns"],
      "properties": {
        "device_id": { "type": "integer", "minimum": 0 },
        "inode": { "type": "integer", "minimum": 0 },
        "mode": { "type": "integer", "minimum": 0, "maximum": 4294967295 },
        "owner_uid": { "type": "integer", "minimum": 0, "maximum": 4294967295 },
        "group_gid": { "type": "integer", "minimum": 0, "maximum": 4294967295 },
        "link_count": { "type": "integer", "minimum": 1 },
        "size_bytes": { "type": "integer", "minimum": 1, "maximum": 16777216 },
        "modified_unix_ns": { "type": "integer" },
        "changed_unix_ns": { "type": "integer" }
      },
      "additionalProperties": false
    },
    "source": {
      "type": "object",
      "required": ["path", "before", "after", "content"],
      "properties": {
        "path": { "$ref": "#/$defs/path" },
        "before": { "$ref": "#/$defs/snapshot" },
        "after": { "$ref": "#/$defs/snapshot" },
        "content": { "$ref": "#/$defs/content" }
      },
      "additionalProperties": false
    },
    "producer": {
      "type": "object",
      "required": ["name", "version", "executable", "binary_digest", "invocation_fingerprint"],
      "properties": {
        "name": { "const": "oxipng" },
        "version": { "const": "10.2.1" },
        "executable": { "$ref": "#/$defs/path" },
        "binary_digest": { "$ref": "#/$defs/digest" },
        "invocation_fingerprint": { "$ref": "#/$defs/digest" }
      },
      "additionalProperties": false
    },
    "candidate": {
      "type": "object",
      "required": ["content", "file_name"],
      "properties": {
        "content": { "$ref": "#/$defs/content" },
        "file_name": { "const": "candidate.png" }
      },
      "additionalProperties": false
    },
    "limits": {
      "type": "object",
      "required": ["source_bytes", "candidate_bytes", "decoded_bytes_per_image", "decoder_allocation_bytes", "chunks_per_image", "provider_binary_bytes", "stderr_bytes", "evidence_bytes", "elapsed_ms"],
      "properties": {
        "source_bytes": { "type": "integer", "minimum": 1, "maximum": 16777216 },
        "candidate_bytes": { "type": "integer", "minimum": 1, "maximum": 16777216 },
        "decoded_bytes_per_image": { "type": "integer", "minimum": 1, "maximum": 67108864 },
        "decoder_allocation_bytes": { "type": "integer", "minimum": 1, "maximum": 67108864 },
        "chunks_per_image": { "type": "integer", "minimum": 1, "maximum": 256 },
        "provider_binary_bytes": { "type": "integer", "minimum": 1, "maximum": 67108864 },
        "stderr_bytes": { "type": "integer", "minimum": 1, "maximum": 65536 },
        "evidence_bytes": { "type": "integer", "minimum": 1, "maximum": 1048576 },
        "elapsed_ms": { "type": "integer", "minimum": 1, "maximum": 30000 }
      },
      "additionalProperties": false
    },
    "measurements": {
      "type": "object",
      "required": ["elapsed_ms", "captured_stdout_bytes", "captured_stderr_bytes", "decoded_source_bytes", "decoded_candidate_bytes", "peak_provider_memory_bytes", "peak_provider_temporary_bytes", "provider_resource_enforcement"],
      "properties": {
        "elapsed_ms": { "type": "integer", "minimum": 0 },
        "captured_stdout_bytes": { "type": "integer", "minimum": 1, "maximum": 16777216 },
        "captured_stderr_bytes": { "type": "integer", "minimum": 0, "maximum": 65536 },
        "decoded_source_bytes": { "type": "integer", "minimum": 1, "maximum": 67108864 },
        "decoded_candidate_bytes": { "type": "integer", "minimum": 1, "maximum": 67108864 },
        "peak_provider_memory_bytes": { "type": "null" },
        "peak_provider_temporary_bytes": { "type": "null" },
        "provider_resource_enforcement": { "const": "host_bounds_stdin_stdout_stderr_elapsed_and_validator_buffers;provider_rss_and_private_workdir_usage_unmeasured" }
      },
      "additionalProperties": false
    },
    "png": {
      "type": "object",
      "required": ["width", "height", "bit_depth", "color_type", "frames", "complete_decode", "animation_chunks", "unknown_unsafe_to_copy_chunks", "decoded_bytes", "ihdr_digest", "decoded_samples_digest", "non_idat_chunks_digest"],
      "properties": {
        "width": { "type": "integer", "minimum": 1, "maximum": 2147483647 },
        "height": { "type": "integer", "minimum": 1, "maximum": 2147483647 },
        "bit_depth": { "const": 8 },
        "color_type": { "enum": [2, 6] },
        "frames": { "const": 1 },
        "complete_decode": { "const": true },
        "animation_chunks": { "const": false },
        "unknown_unsafe_to_copy_chunks": { "const": false },
        "decoded_bytes": { "type": "integer", "minimum": 1, "maximum": 67108864 },
        "ihdr_digest": { "$ref": "#/$defs/digest" },
        "decoded_samples_digest": { "$ref": "#/$defs/digest" },
        "non_idat_chunks_digest": { "$ref": "#/$defs/digest" }
      },
      "additionalProperties": false
    },
    "validation": {
      "type": "object",
      "required": ["source_png", "candidate_png", "independent_byte_validation", "exact_decoded_samples", "ordered_non_idat_chunks_preserved", "strict_encoded_reduction"],
      "properties": {
        "source_png": { "$ref": "#/$defs/png" },
        "candidate_png": { "$ref": "#/$defs/png" },
        "independent_byte_validation": { "const": true },
        "exact_decoded_samples": { "const": true },
        "ordered_non_idat_chunks_preserved": { "const": true },
        "strict_encoded_reduction": { "const": true }
      },
      "additionalProperties": false
    },
    "cleanup": {
      "type": "object",
      "required": ["provider_work_directory_removed", "source_mutation"],
      "properties": {
        "provider_work_directory_removed": { "const": true },
        "source_mutation": { "const": false }
      },
      "additionalProperties": false
    }
  }
}
