{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://kaldenframelabs.com/schemas/attempt-boundary-receipt-v1.schema.json",
  "title": "Attempt Boundary receipt v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema",
    "generated_at",
    "attempt_id",
    "outcome",
    "plan_sha256",
    "working_directory",
    "preflight",
    "execution",
    "execution_invoked",
    "attempt_consumed",
    "protected_before_sha256",
    "protected_after_preflight_sha256",
    "protected_after_execution_sha256",
    "protected_paths_unchanged_during_preflight",
    "preflight_changes",
    "execution_changes",
    "boundary",
    "receipt_sha256"
  ],
  "properties": {
    "schema": { "const": "kaldenframe.attempt-boundary.receipt.v1" },
    "generated_at": { "type": "string", "format": "date-time" },
    "attempt_id": { "type": "string", "minLength": 1, "maxLength": 128 },
    "outcome": { "enum": ["PREFLIGHT_FAILED", "PREFLIGHT_MUTATED_PROTECTED_PATHS", "EXECUTION_SUCCEEDED", "EXECUTION_FAILED"] },
    "plan_sha256": { "$ref": "#/$defs/sha256" },
    "working_directory": { "type": "string", "minLength": 1, "maxLength": 512 },
    "preflight": { "$ref": "#/$defs/commandResult" },
    "execution": { "oneOf": [{ "$ref": "#/$defs/commandResult" }, { "type": "null" }] },
    "execution_invoked": { "type": "boolean" },
    "attempt_consumed": { "type": "boolean" },
    "protected_before_sha256": { "$ref": "#/$defs/sha256" },
    "protected_after_preflight_sha256": { "$ref": "#/$defs/sha256" },
    "protected_after_execution_sha256": { "oneOf": [{ "$ref": "#/$defs/sha256" }, { "type": "null" }] },
    "protected_paths_unchanged_during_preflight": { "type": "boolean" },
    "preflight_changes": { "$ref": "#/$defs/changes" },
    "execution_changes": { "oneOf": [{ "$ref": "#/$defs/changes" }, { "type": "null" }] },
    "boundary": {
      "const": "This receipt proves only what this wrapper observed and controlled; it is not proof of non-access, safety, correctness, authenticity, or host integrity."
    },
    "receipt_sha256": { "$ref": "#/$defs/sha256" }
  },
  "$defs": {
    "sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "changes": {
      "type": "array",
      "maxItems": 20000,
      "items": { "type": "string", "minLength": 1, "maxLength": 1024 }
    },
    "commandResult": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "command_sha256",
        "executable",
        "argument_count",
        "spawned",
        "exit_code",
        "signal",
        "timed_out",
        "output_limit_exceeded",
        "error_code",
        "stdout_bytes",
        "stdout_sha256",
        "stderr_bytes",
        "stderr_sha256",
        "duration_ms"
      ],
      "properties": {
        "command_sha256": { "$ref": "#/$defs/sha256" },
        "executable": { "type": "string", "minLength": 1, "maxLength": 256 },
        "argument_count": { "type": "integer", "minimum": 0, "maximum": 31 },
        "spawned": { "type": "boolean" },
        "exit_code": { "type": ["integer", "null"] },
        "signal": { "type": ["string", "null"] },
        "timed_out": { "type": "boolean" },
        "output_limit_exceeded": { "type": "boolean" },
        "error_code": { "type": ["string", "null"], "maxLength": 64 },
        "stdout_bytes": { "type": "integer", "minimum": 0 },
        "stdout_sha256": { "$ref": "#/$defs/sha256" },
        "stderr_bytes": { "type": "integer", "minimum": 0 },
        "stderr_sha256": { "$ref": "#/$defs/sha256" },
        "duration_ms": { "type": "integer", "minimum": 0 }
      }
    }
  }
}
