{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://lvlltd.com/schemas/esp-cycle.v1.schema.json",
  "title": "ESP Cycle (Evaluate → Settle → Prove)",
  "description": "Native protocol primitive for LVL sealed capability markets. Free evaluation is always available before settlement. Settlement is atomic x402. Proof is public ledger only — never invent unlock counts or success without /api/proof.",
  "type": "object",
  "required": ["schema", "protocol", "skill_id", "evaluate", "settle", "prove"],
  "additionalProperties": true,
  "properties": {
    "schema": {
      "const": "lvl-esp-cycle-v1"
    },
    "protocol": {
      "const": "ESP"
    },
    "protocol_version": {
      "type": "string",
      "const": "1.0.0"
    },
    "skill_id": {
      "type": "string",
      "minLength": 1
    },
    "kind": {
      "type": "string",
      "enum": ["skill", "bundle", "judge", "memory_pack", "intent_node", "tool"]
    },
    "name": { "type": "string" },
    "price_usd": { "type": "number", "minimum": 0 },
    "invariants": {
      "type": "object",
      "properties": {
        "free_eval_always": { "const": true },
        "settlement_atomic": { "const": true },
        "proof_public_only": { "const": true },
        "no_invented_metrics": { "const": true }
      }
    },
    "evaluate": {
      "type": "object",
      "required": ["cost", "endpoints"],
      "properties": {
        "cost": { "const": "free" },
        "endpoints": {
          "type": "object",
          "properties": {
            "outline": { "type": "string", "format": "uri" },
            "sample": { "type": "string", "format": "uri" },
            "pack_meta": { "type": "string", "format": "uri" },
            "canary_challenge": { "type": "string", "format": "uri" },
            "listing": { "type": "string", "format": "uri" }
          }
        },
        "available": {
          "type": "object",
          "properties": {
            "outline": { "type": "boolean" },
            "sample": { "type": "boolean" },
            "teaser": { "type": "boolean" }
          }
        },
        "decision_criteria": {
          "type": "array",
          "items": { "type": "string" }
        },
        "when_to_use": {
          "type": "array",
          "items": { "type": "string" }
        }
      }
    },
    "settle": {
      "type": "object",
      "required": ["protocol", "challenge", "atomic"],
      "properties": {
        "protocol": { "const": "x402" },
        "atomic": { "const": true },
        "network": { "type": "string" },
        "network_caip2": { "type": "string" },
        "asset": { "type": "string" },
        "asset_contract": { "type": "string" },
        "pay_to": { "type": "string" },
        "maxAmountRequired": { "type": "string", "pattern": "^[0-9]+$" },
        "price_usd": { "type": "number" },
        "challenge": { "type": "string", "format": "uri" },
        "unlock": {
          "type": "string",
          "description": "POST /api/pay with X-PAYMENT {txHash, skill}"
        },
        "one_shot": { "type": "boolean" }
      }
    },
    "prove": {
      "type": "object",
      "required": ["source_of_truth", "ledger"],
      "properties": {
        "source_of_truth": { "const": "https://lvlltd.com/api/proof" },
        "ledger": { "type": "string", "format": "uri" },
        "skill_filter": { "type": "string", "format": "uri" },
        "confirmed_unlocks": {
          "type": "integer",
          "minimum": 0,
          "description": "From public ledger only — never fabricated"
        },
        "last_verified": {
          "type": ["string", "null"],
          "description": "ISO timestamp of last confirmed unlock for this skill, or null"
        },
        "volume_usd": {
          "type": "number",
          "minimum": 0,
          "description": "Confirmed ledger volume only"
        },
        "quality_score": {
          "type": ["number", "null"],
          "description": "Derived only from confirmed deliveries; null if zero unlocks"
        },
        "reverify": {
          "type": "array",
          "items": { "type": "string" }
        }
      }
    },
    "agent_sequence": {
      "type": "array",
      "items": { "type": "string" }
    },
    "human_path": {
      "type": "object",
      "properties": {
        "evaluate": { "type": "string", "format": "uri" },
        "settle": { "type": "string", "format": "uri" },
        "prove": { "type": "string", "format": "uri" }
      }
    }
  }
}
