#!/usr/bin/env bash set -euo pipefail if [[ $# -lt 3 || ( $1 != --prepare && $1 != --paid ) ]]; then printf 'Usage: %s --prepare|--paid BASELINE_IMAGE CANDIDATE_IMAGE [OS/ARCH ...]\n' "$0" >&2 exit 2 fi mode=$1 baseline=$2 candidate=$3 shift 3 if [[ -z $baseline || -z $candidate || $baseline == -* || $candidate == -* ]]; then printf 'Provide two image references. Prefer immutable digest references.\n' >&2 exit 2 fi work=$(mktemp -d) trap 'unlink "$work/baseline.json" 2>/dev/null || true; unlink "$work/candidate.json" 2>/dev/null || true; rmdir "$work"' EXIT docker buildx imagetools inspect --raw "$baseline" > "$work/baseline.json" docker buildx imagetools inspect --raw "$candidate" > "$work/candidate.json" request=$(jq -ecn --slurpfile baseline "$work/baseline.json" \ --slurpfile candidate "$work/candidate.json" --args ' def image_index: type == "object" and .schemaVersion == 2 and (.manifests | type == "array"); if ($baseline | length) != 1 or ($candidate | length) != 1 or ($baseline[0] | image_index | not) or ($candidate[0] | image_index | not) then error("Both image references must resolve to image indexes.") else {baseline: $baseline[0], candidate: $candidate[0], required_platforms: $ARGS.positional} end' "$@") if [[ $mode == --prepare ]]; then printf '%s\n' "$request" exit 0 fi if (( $(LC_ALL=C printf '%s' "$request" | wc -c) > 120000 )); then printf 'Request is too large for this CLI argument. Use --prepare and a file-capable x402 client.\n' >&2 exit 2 fi # Run only in a trusted job with an AgentCash wallet already configured on its runner. # Run once per release candidate. Inspect the receipt before retrying an uncertain call. result=$(npx --yes agentcash@0.17.1 fetch \ 'https://container-image-release-check.defcronyke.workers.dev/v1/compare' \ -m POST -H 'Content-Type: application/json' -b "$request" --format json \ --payment-protocol x402 --payment-network base --max-amount 0.03) printf '%s\n' "$result" | jq -e ' if .success == true and (.data.ready | type) == "boolean" then .data else error("Expected a comparison result from AgentCash.") end' printf '%s\n' "$result" | jq -e '.data.ready == true' > /dev/null