{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://getzero.dev/contracts/zero.vibe_deploy.lifecycle_contract.v1.schema.json",
  "title": "ZERO Vibe Deploy Lifecycle Contract v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "claim_token",
    "route_sequence",
    "heartbeat",
    "paper_acceptance",
    "paper_run",
    "refusal_boundary"
  ],
  "properties": {
    "schema_version": { "const": "zero.vibe_deploy.lifecycle_contract.v1" },
    "claim_token": {
      "type": "object",
      "additionalProperties": false,
      "required": ["ttl_s", "storage", "replay_policy", "exposed_in_public_contract", "example_value"],
      "properties": {
        "ttl_s": { "type": "integer", "minimum": 60, "maximum": 3600 },
        "storage": { "const": "sha256_hash_only" },
        "replay_policy": { "const": "single_use" },
        "exposed_in_public_contract": { "const": false },
        "example_value": { "type": "string", "minLength": 1 }
      }
    },
    "route_sequence": {
      "type": "array",
      "minItems": 6,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["step", "method", "path", "auth", "mutates_runtime", "emits_secret", "expected_state_after"],
        "properties": {
          "step": {
            "enum": [
              "create_paper_deployment",
              "claim_runtime",
              "first_heartbeat",
              "run_paper_acceptance",
              "record_paper_acceptance",
              "approve_builder_fee",
              "live_lease"
            ]
          },
          "method": { "enum": ["POST"] },
          "path": { "type": "string", "minLength": 1 },
          "auth": {
            "enum": [
              "operator_session",
              "claim_token",
              "ed25519_runtime_signature",
              "local_runtime_http",
              "operator_session_plus_main_wallet_readback"
            ]
          },
          "mutates_runtime": { "type": "boolean" },
          "emits_secret": {
            "type": ["string", "null"],
            "enum": ["one_time_claim_token", "scoped_foundation_api_key", null]
          },
          "expected_state_after": { "type": "string", "minLength": 1 }
        }
      }
    },
    "heartbeat": {
      "type": "object",
      "additionalProperties": false,
      "required": ["signature", "nonce_policy", "clock_window_s", "expected_first_heartbeat_s", "ack_fields"],
      "properties": {
        "signature": { "const": "ed25519_over_canonical_signed_body" },
        "nonce_policy": { "const": "monotonic_heartbeat_nonce" },
        "clock_window_s": { "type": "integer", "minimum": 1, "maximum": 300 },
        "expected_first_heartbeat_s": { "type": "integer", "minimum": 1, "maximum": 300 },
        "ack_fields": {
          "type": "array",
          "minItems": 6,
          "uniqueItems": true,
          "items": { "type": "string", "minLength": 1 }
        }
      }
    },
    "paper_acceptance": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "runtime_health_path",
        "first_heartbeat_state",
        "persistent_state_dir",
        "persistent_volume_mount",
        "live_execution_default",
        "requires_live_lease_for_live"
      ],
      "properties": {
        "runtime_health_path": { "const": "/health" },
        "first_heartbeat_state": { "const": "ready" },
        "persistent_state_dir": { "type": "string", "minLength": 1 },
        "persistent_volume_mount": { "type": "string", "minLength": 1 },
        "live_execution_default": { "const": false },
        "requires_live_lease_for_live": { "const": true }
      }
    },
    "paper_run": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "schema_version",
        "endpoint",
        "audit_path",
        "control_plane_acceptance_endpoint",
        "go_live_requires_paper_acceptance_event",
        "journal_path",
        "sample_payload",
        "acceptance",
        "evidence_paths",
        "forbidden_before_live_lease"
      ],
      "properties": {
        "schema_version": { "const": "zero.vibe_deploy.paper_run_contract.v1" },
        "endpoint": { "const": "/execute" },
        "audit_path": { "const": "/audit/export?limit=100" },
        "control_plane_acceptance_endpoint": { "const": "/api/deployments/{deploymentId}/events" },
        "go_live_requires_paper_acceptance_event": { "const": true },
        "journal_path": { "type": "string", "minLength": 1 },
        "sample_payload": { "type": "object" },
        "acceptance": { "type": "object" },
        "evidence_paths": {
          "type": "array",
          "minItems": 5,
          "items": { "type": "string", "minLength": 1 }
        },
        "forbidden_before_live_lease": {
          "type": "array",
          "minItems": 3,
          "items": { "type": "string", "minLength": 1 }
        }
      }
    },
    "refusal_boundary": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "auto_execution_before_eligibility_gating",
        "private_key_env_allowed",
        "forbidden_env_keys",
        "live_actions_before_operator_lease"
      ],
      "properties": {
        "auto_execution_before_eligibility_gating": { "const": false },
        "private_key_env_allowed": { "const": false },
        "forbidden_env_keys": {
          "type": "array",
          "minItems": 1,
          "items": { "type": "string", "minLength": 1 }
        },
        "live_actions_before_operator_lease": {
          "type": "array",
          "maxItems": 0
        }
      }
    }
  }
}
