{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://getzero.dev/contracts/zero.vibe_deploy_readiness.v1.schema.json",
  "title": "ZERO Vibe Deploy Readiness v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "kind",
    "public",
    "status",
    "canonical_flow",
    "railway_template",
    "runtime_manifest",
    "lifecycle_contract",
    "install_methods",
    "smoke",
    "recovery_hardening",
    "proof_chain",
    "safety",
    "drift_checks",
    "score_promotion_gate"
  ],
  "properties": {
    "schema_version": { "const": "zero.vibe_deploy_readiness.v1" },
    "kind": { "const": "vibe_deploy_readiness" },
    "public": { "const": true },
    "status": { "enum": ["ready", "attention"] },
    "canonical_flow": {
      "type": "array",
      "minItems": 10,
      "items": { "type": "string", "minLength": 1 }
    },
    "railway_template": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "template_url",
        "default_template_url",
        "configured_template_url",
        "marketplace_url",
        "source_repo",
        "branch",
        "root_directory",
        "builder",
        "public_networking",
        "healthcheck_path",
        "volume_mount_path",
        "start_command",
        "template_matches_runtime_manifest"
      ],
      "properties": {
        "template_url": { "type": "string", "format": "uri" },
        "default_template_url": { "type": "string", "format": "uri" },
        "configured_template_url": { "type": "string", "format": "uri" },
        "marketplace_url": { "type": "string", "format": "uri" },
        "source_repo": { "type": "string", "format": "uri" },
        "branch": { "type": "string", "minLength": 1 },
        "root_directory": { "type": "string", "minLength": 1 },
        "builder": { "type": "string", "minLength": 1 },
        "public_networking": { "type": "boolean" },
        "healthcheck_path": { "const": "/health" },
        "volume_mount_path": { "const": "/data" },
        "start_command": { "type": "string", "minLength": 1 },
        "template_matches_runtime_manifest": { "type": "boolean" }
      }
    },
    "runtime_manifest": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "schema_version",
        "mode",
        "provider",
        "startup_command",
        "healthcheck_path",
        "claim_endpoint",
        "heartbeat_endpoint",
        "runtime_base_url_reporting",
        "required_env_keys",
        "forbidden_env_keys",
        "promotion_gates",
        "paper_run",
        "live_execution_default",
        "live_requires_operator_lease"
      ],
      "properties": {
        "schema_version": { "const": "zero.vibe_deploy.runtime_manifest.v1" },
        "mode": { "const": "paper" },
        "provider": { "const": "railway" },
        "startup_command": { "type": "string", "minLength": 1 },
        "healthcheck_path": { "const": "/health" },
        "claim_endpoint": { "type": "string", "format": "uri" },
        "heartbeat_endpoint": { "type": "string", "format": "uri" },
        "runtime_base_url_reporting": {
          "type": "object",
          "additionalProperties": false,
          "required": ["claim_body_key", "heartbeat_signed_body_key", "validation"],
          "properties": {
            "claim_body_key": { "const": "runtime_base_url" },
            "heartbeat_signed_body_key": { "const": "runtime_base_url" },
            "validation": { "const": "public_http_or_https_no_private_dns" }
          }
        },
        "required_env_keys": {
          "type": "array",
          "minItems": 6,
          "uniqueItems": true,
          "items": { "type": "string", "pattern": "^ZERO_[A-Z0-9_]+$" }
        },
        "forbidden_env_keys": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": { "type": "string", "minLength": 1 }
        },
        "promotion_gates": {
          "type": "array",
          "minItems": 5,
          "items": {
            "type": "object",
            "required": ["key", "status", "evidence"],
            "properties": {
              "key": { "type": "string", "minLength": 1 },
              "status": { "const": "required" },
              "evidence": { "type": "string", "minLength": 1 }
            }
          }
        },
        "paper_run": {
          "type": "object",
          "required": ["endpoint", "audit_path", "journal_path", "sample_payload", "acceptance"],
          "properties": {
            "endpoint": { "const": "/execute" },
            "audit_path": { "const": "/audit/export?limit=100" },
            "journal_path": { "type": "string", "minLength": 1 },
            "sample_payload": { "type": "object" },
            "acceptance": { "type": "object" }
          }
        },
        "live_execution_default": { "const": false },
        "live_requires_operator_lease": { "const": true }
      }
    },
    "lifecycle_contract": {
      "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",
          "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",
            "required": ["step", "method", "path", "auth", "mutates_runtime", "emits_secret", "expected_state_after"],
            "properties": {
              "step": { "type": "string", "minLength": 1 },
              "method": { "const": "POST" },
              "path": { "type": "string", "minLength": 1 },
              "auth": { "type": "string", "minLength": 1 },
              "mutates_runtime": { "type": "boolean" },
              "emits_secret": { "type": ["string", "null"] },
              "expected_state_after": { "type": "string", "minLength": 1 }
            }
          }
        },
        "heartbeat": {
          "type": "object",
          "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",
          "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",
          "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",
          "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
            }
          }
        }
      }
    },
    "install_methods": {
      "type": "object",
      "additionalProperties": false,
      "required": ["docker_image", "ghcr_image", "railway_env_keys", "forbidden_env_keys"],
      "properties": {
        "docker_image": { "type": "string", "minLength": 1 },
        "ghcr_image": { "type": "string", "minLength": 1 },
        "railway_env_keys": {
          "type": "array",
          "minItems": 6,
          "items": { "type": "string", "pattern": "^ZERO_[A-Z0-9_]+$" }
        },
        "forbidden_env_keys": {
          "type": "array",
          "minItems": 1,
          "items": { "type": "string", "minLength": 1 }
        }
      }
    },
    "smoke": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "expected_claimed_state",
        "heartbeat_endpoint",
        "expected_first_heartbeat_s",
        "persistent_state_dir",
        "persistent_volume_mount",
        "local_commands",
        "production_readback"
      ],
      "properties": {
        "expected_claimed_state": { "const": "ready" },
        "heartbeat_endpoint": { "type": "string", "format": "uri" },
        "expected_first_heartbeat_s": { "type": "integer", "minimum": 1, "maximum": 300 },
        "persistent_state_dir": { "type": "string", "minLength": 1 },
        "persistent_volume_mount": { "const": "/data" },
        "local_commands": {
          "type": "array",
          "minItems": 2,
          "items": { "type": "string", "minLength": 1 }
        },
        "production_readback": {
          "type": "array",
          "minItems": 1,
          "items": { "type": "string", "minLength": 1 }
        }
      }
    },
    "recovery_hardening": {
      "type": "object",
      "additionalProperties": false,
      "required": ["schema_version", "status", "route", "cases", "invariants"],
      "properties": {
        "schema_version": { "const": "zero.vibe_deploy.recovery_hardening.v1" },
        "status": { "enum": ["ready", "attention"] },
        "route": { "const": "/api/deployments/vibe-deploy-recovery" },
        "cases": {
          "type": "array",
          "minItems": 6,
          "items": { "type": "string", "minLength": 1 }
        },
        "invariants": { "type": "object" }
      }
    },
    "proof_chain": {
      "type": "object",
      "additionalProperties": false,
      "required": ["schema_version", "schema", "status", "route", "canonical_order", "trust_states", "enforcement"],
      "properties": {
        "schema_version": { "const": "zero.vibe_deploy.proof_chain.v1" },
        "schema": { "const": "https://getzero.dev/contracts/zero.vibe_deploy.proof_chain.v1.schema.json" },
        "status": { "enum": ["ready", "attention"] },
        "route": { "const": "/api/deployments/vibe-deploy-proof-chain" },
        "canonical_order": {
          "type": "array",
          "minItems": 7,
          "items": { "type": "string", "minLength": 1 }
        },
        "trust_states": { "type": "object" },
        "enforcement": { "type": "object" }
      }
    },
    "safety": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "no_private_key_material",
        "signing_boundary",
        "ephemeral_secret_env_keys",
        "live_execution_default",
        "live_requires_operator_lease",
        "auto_execution_before_eligibility_gating"
      ],
      "properties": {
        "no_private_key_material": { "const": true },
        "signing_boundary": { "const": "claim_token_bootstrap" },
        "ephemeral_secret_env_keys": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 }
        },
        "live_execution_default": { "const": false },
        "live_requires_operator_lease": { "const": true },
        "auto_execution_before_eligibility_gating": { "const": false }
      }
    },
    "drift_checks": {
      "type": "array",
      "minItems": 8,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["key", "status", "evidence"],
        "properties": {
          "key": { "type": "string", "minLength": 1 },
          "status": { "enum": ["passed", "failed"] },
          "evidence": { "type": "string", "minLength": 1 }
        }
      }
    },
    "score_promotion_gate": {
      "type": "object",
      "additionalProperties": false,
      "required": ["public_score_moves_when", "implementation_readiness_moves_when"],
      "properties": {
        "public_score_moves_when": { "type": "string", "minLength": 1 },
        "implementation_readiness_moves_when": { "type": "string", "minLength": 1 }
      }
    }
  }
}
