{
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "certification",
    "policy_version",
    "policy_digest",
    "plan_digest",
    "attempt",
    "lease_token",
    "passed",
    "failed_step",
    "steps"
  ],
  "properties": {
    "schema_version": { "const": 1 },
    "certification": { "type": "string", "enum": ["live", "non-certifying"] },
    "policy_version": { "type": "integer", "minimum": 1 },
    "policy_digest": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "plan_digest": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "attempt": { "type": "integer", "minimum": 1 },
    "lease_token": { "type": "string", "pattern": "^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$" },
    "binding": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "goal_id", "goal_version", "dispatch_id", "dispatch_version", "ticket_id", "attempt",
        "lease_token", "session_id", "worker_record_id", "worker_id", "worktree_id",
        "worktree_root", "worktree_branch", "worktree_base_commit", "expected_commit",
        "executor_role", "executor_engine", "executor_evidence"
      ],
      "properties": {
        "goal_id": { "type": "string", "pattern": "^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$" },
        "goal_version": { "type": "integer", "minimum": 0 },
        "dispatch_id": { "type": "string", "pattern": "^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$" },
        "dispatch_version": { "type": "integer", "minimum": 0 },
        "ticket_id": { "type": "string", "pattern": "^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$" },
        "attempt": { "type": "integer", "minimum": 1 },
        "lease_token": { "type": "string", "pattern": "^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$" },
        "session_id": { "type": "string", "pattern": "^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$" },
        "worker_record_id": { "type": "string", "pattern": "^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$" },
        "worker_id": { "type": "string", "pattern": "^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$" },
        "worktree_id": { "type": "string", "pattern": "^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$" },
        "worktree_root": { "type": "string", "pattern": "^/", "maxLength": 4096 },
        "worktree_branch": { "type": "string", "minLength": 1, "maxLength": 255 },
        "worktree_base_commit": { "type": "string", "pattern": "^[a-f0-9]{40}(?:[a-f0-9]{24})?$" },
        "expected_commit": { "type": "string", "pattern": "^[a-f0-9]{40}(?:[a-f0-9]{24})?$" },
        "executor_role": { "enum": ["oms.ticket-executor", "oms.goal-long-executor"] },
        "executor_engine": { "enum": ["claude", "codex"] },
        "executor_evidence": {
          "type": "object",
          "additionalProperties": false,
          "required": ["evidence_id", "sha256", "file_name"],
          "properties": {
            "evidence_id": { "type": "string", "pattern": "^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$" },
            "sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
            "file_name": { "type": "string", "pattern": "^[a-z0-9](?:[a-z0-9.-]{0,132}[a-z0-9])?\\.json$" }
          }
        }
      }
    },
    "preflight": {
      "type": "object",
      "additionalProperties": false,
      "required": ["worktree_root", "worktree_branch", "head_commit", "clean"],
      "properties": {
        "worktree_root": { "type": "string", "pattern": "^/", "maxLength": 4096 },
        "worktree_branch": { "type": "string", "minLength": 1, "maxLength": 255 },
        "head_commit": { "type": "string", "pattern": "^[a-f0-9]{40}(?:[a-f0-9]{24})?$" },
        "clean": { "const": true }
      }
    },
    "postflight": {
      "type": "object",
      "additionalProperties": false,
      "required": ["worktree_root", "worktree_branch", "head_commit", "clean"],
      "properties": {
        "worktree_root": { "type": "string", "pattern": "^/", "maxLength": 4096 },
        "worktree_branch": { "type": "string", "minLength": 1, "maxLength": 255 },
        "head_commit": { "type": "string", "pattern": "^[a-f0-9]{40}(?:[a-f0-9]{24})?$" },
        "clean": { "const": true }
      }
    },
    "passed": { "type": "boolean" },
    "failed_step": { "type": ["string", "null"], "maxLength": 64 },
    "steps": {
      "type": "array",
      "minItems": 1,
      "maxItems": 16,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "status", "signal", "passed", "stdout", "stderr", "error"],
        "properties": {
          "id": { "type": "string", "pattern": "^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$" },
          "status": { "type": ["integer", "null"] },
          "signal": { "type": ["string", "null"], "maxLength": 32 },
          "passed": { "type": "boolean" },
          "stdout": { "type": "string", "maxLength": 1048576 },
          "stderr": { "type": "string", "maxLength": 1048576 },
          "error": { "type": ["string", "null"], "maxLength": 1048576 }
        }
      }
    }
  }
}
