{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://oms.local/schemas/run-start-intent.schema.json",
  "title": "OMS immutable audit run start intent",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "intent_id",
    "operation_id",
    "start_nonce",
    "expected_run_id",
    "run_kind",
    "manager",
    "executable_path",
    "created_at",
    "policy_digest",
    "verification_gate_digest",
    "ticket_set_digest",
    "service_plan_digest",
    "service_plan_directory",
    "state_root",
    "workspace_root",
    "ticket_snapshot"
  ],
  "properties": {
    "schema_version": { "const": 1 },
    "intent_id": { "type": "string", "pattern": "^run-intent-[a-f0-9]{48}$" },
    "operation_id": { "type": "string", "pattern": "^run-start-[a-f0-9]{48}$" },
    "start_nonce": { "type": "string", "pattern": "^[a-f0-9-]{36}$" },
    "expected_run_id": { "type": "string", "pattern": "^run-[a-f0-9]{48}$" },
    "run_kind": { "type": "string", "enum": ["12h", "24h", "until-empty"] },
    "manager": { "type": "string", "enum": ["cron", "systemd", "launchd"] },
    "executable_path": { "type": "string", "pattern": "^/", "maxLength": 4096 },
    "created_at": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{3}Z$" },
    "policy_digest": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "verification_gate_digest": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "ticket_set_digest": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "service_plan_digest": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "service_plan_directory": { "type": "string", "pattern": "^/", "maxLength": 4096 },
    "state_root": { "type": "string", "pattern": "^/", "maxLength": 4096 },
    "workspace_root": { "type": "string", "pattern": "^/", "maxLength": 4096 },
    "ticket_snapshot": {
      "type": "array",
      "maxItems": 10000,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "ticket_id",
          "initial_version",
          "initial_attempt",
          "initial_state",
          "source_ref_sha256",
          "content_sha256",
          "policy_version",
          "policy_digest",
          "gate_digest"
        ],
        "properties": {
          "ticket_id": { "type": "string", "pattern": "^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$" },
          "initial_version": { "type": "integer", "minimum": 0 },
          "initial_attempt": { "type": "integer", "minimum": 1 },
          "initial_state": { "type": "string", "enum": ["pending", "leased", "running", "verifying", "retryable", "parked", "blocked"] },
          "source_ref_sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
          "content_sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
          "policy_version": { "type": "integer", "minimum": 1 },
          "policy_digest": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
          "gate_digest": { "type": ["string", "null"], "pattern": "^[a-f0-9]{64}$" }
        }
      }
    }
  }
}
