-
Notifications
You must be signed in to change notification settings - Fork 16.6k
[Turnstile] Spin docs: refresh hosted prompt, helper scripts, and spin.mdx #32147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
marinaelmore
merged 25 commits into
cloudflare:production
from
juleslemee:spin-docs-followup
Jul 23, 2026
Merged
Changes from 16 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
884e15f
[Turnstile] Set autocomplete hints on client-side rendering examples …
758ec83
[Turnstile] Spin: document dashboard setup path alongside command-line
a58cd2c
[Turnstile] Spin docs: address style-bot suggestions
e19dffb
[Turnstile] Spin V2 docs: point references at prompt.md
a6edc4f
[Turnstile] Spin V2 docs: dashboard recovery is the primary path, age…
84fd4a2
[Turnstile] Spin docs: pivot to canonical siteverify
da161d3
[Turnstile] Spin V2 sync: prompt.md + Wrangler CLI setup path
e91c08b
[Turnstile] Drop Wrangler version note from Spin CLI section
2a360a6
[Turnstile] Fix Spin docs accuracy (removed column, local dev domains…
82cb7a8
Merge remote-tracking branch 'upstream/production' into spin-docs-fol…
b6cc3b6
[Turnstile] Drop Spin beta tag; bump reviewed date
2985122
[Turnstile] Redirect old Spin index.md to prompt.md
14662f3
Revert "[Turnstile] Redirect old Spin index.md to prompt.md"
05c95a8
[Turnstile] Spin docs: spell out insertion-preference examples per re…
e0c74a5
[Turnstile] Spin: sync prompt.md to SKILL.md and guide token reset fo…
7995c2d
[Turnstile] Spin docs: merge upstream/production and address review w…
f671609
[Turnstile] Spin docs: broaden scope beyond forms per review
7c87c00
Harden Turnstile Spin helper scripts (docs-bot findings)
c179505
Harden Turnstile Spin helper scripts (second pass on docs-bot findings)
fcb4f75
Guard mktemp, malformed errors list, and npx prerequisite
17dfa77
Add cleanup safety net to auth-probe Edit-scope probe
cd0bd66
Correct Step 2 + Troubleshooting prose to match auth-probe behavior
cf1d4e5
[Turnstile] Spin: sync prompt.md to stratus SPIN_SKILL_CONTENT (latest)
db5981f
[Turnstile] Spin: harden hosted prompt, scripts, and spin.mdx
6cb1ef5
Merge remote-tracking branch 'upstream/production' into spin-docs-fol…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| #!/usr/bin/env bash | ||
| # Probes Cloudflare API auth state for the Turnstile Spin agent. | ||
| # | ||
| # Reads: | ||
| # $CLOUDFLARE_API_TOKEN (required) | ||
| # $CLOUDFLARE_ACCOUNT_ID (optional; if set, must be one of the token's accounts) | ||
| # | ||
| # Outputs JSON to stdout, always exits 0. The agent reads `status`: | ||
| # "ok" ; selected account passed the Turnstile scope probe | ||
| # "missing_token" ; no token set, or wrangler whoami failed | ||
| # "missing_scope" ; token lacks Account.Turnstile:Edit on the selected account | ||
| # "multiple_accounts" ; token covers >1 accounts and $CLOUDFLARE_ACCOUNT_ID is unset | ||
| # "account_mismatch" ; $CLOUDFLARE_ACCOUNT_ID is set but is not in the token's accounts list | ||
| # | ||
| # Human-readable diagnostics go to stderr. | ||
|
|
||
| set -uo pipefail | ||
|
|
||
| emit() { | ||
| echo "$1" | ||
| exit 0 | ||
| } | ||
|
|
||
| token="${CLOUDFLARE_API_TOKEN:-}" | ||
| declared_account="${CLOUDFLARE_ACCOUNT_ID:-}" | ||
|
|
||
| if [ -z "$token" ]; then | ||
| echo "auth-probe: \$CLOUDFLARE_API_TOKEN is not set." >&2 | ||
| emit '{"status":"missing_token","reason":"no_env_var"}' | ||
| fi | ||
|
|
||
| whoami_json=$(npx wrangler whoami --json 2>/dev/null || true) | ||
| if [ -z "$whoami_json" ] || [ "$(echo "$whoami_json" | head -c 1)" != "{" ]; then | ||
| echo "auth-probe: wrangler whoami returned no JSON. Token may be invalid or expired." >&2 | ||
| emit '{"status":"missing_token","reason":"whoami_failed"}' | ||
| fi | ||
|
|
||
| accounts_json=$(echo "$whoami_json" | (jq -c '.accounts' 2>/dev/null || python3 -c "import sys,json; print(json.dumps(json.load(sys.stdin)['accounts']))")) | ||
| account_count=$(echo "$accounts_json" | (jq 'length' 2>/dev/null || python3 -c "import sys,json; print(len(json.load(sys.stdin)))")) | ||
|
|
||
| if [ -z "$account_count" ] || [ "$account_count" = "0" ] || [ "$account_count" = "null" ]; then | ||
| echo "auth-probe: wrangler whoami succeeded but no accounts found on the token." >&2 | ||
| emit '{"status":"missing_token","reason":"no_accounts"}' | ||
| fi | ||
|
|
||
| if [ -n "$declared_account" ]; then | ||
| in_list=$(echo "$accounts_json" | (jq --arg id "$declared_account" 'map(.id) | index($id) != null' 2>/dev/null || python3 -c "import sys,json; print('true' if any(a['id']==sys.argv[1] for a in json.load(sys.stdin)) else 'false')" "$declared_account")) | ||
| if [ "$in_list" != "true" ]; then | ||
| echo "auth-probe: \$CLOUDFLARE_ACCOUNT_ID ($declared_account) is not one of the token's accounts." >&2 | ||
| emit "{\"status\":\"account_mismatch\",\"declared\":\"$declared_account\",\"accounts\":$accounts_json}" | ||
| fi | ||
| account_id="$declared_account" | ||
| elif [ "$account_count" = "1" ]; then | ||
| account_id=$(echo "$accounts_json" | (jq -r '.[0].id' 2>/dev/null || python3 -c "import sys,json; print(json.load(sys.stdin)[0]['id'])")) | ||
| else | ||
| echo "auth-probe: token covers $account_count accounts; ask the user to pick one, then export \$CLOUDFLARE_ACCOUNT_ID and re-run." >&2 | ||
| emit "{\"status\":\"multiple_accounts\",\"accounts\":$accounts_json}" | ||
| fi | ||
|
|
||
| # Probe Turnstile scope on the selected account. | ||
| tmp=$(mktemp) | ||
| http_code=$(curl -sS -w "%{http_code}" -o "$tmp" \ | ||
| "https://api.cloudflare.com/client/v4/accounts/$account_id/challenges/widgets" \ | ||
| -H "Authorization: Bearer $token" 2>/dev/null || echo "000") | ||
| body=$(cat "$tmp"); rm -f "$tmp" | ||
| success=$(echo "$body" | (jq -r '.success' 2>/dev/null || echo "false")) | ||
|
|
||
| if [ "$success" != "true" ]; then | ||
| echo "auth-probe: token cannot read /challenges/widgets on account $account_id (HTTP $http_code). Missing Account.Turnstile:Edit." >&2 | ||
| emit "{\"status\":\"missing_scope\",\"account_id\":\"$account_id\",\"http_code\":$http_code}" | ||
| fi | ||
|
|
||
| emit "{\"status\":\"ok\",\"account_id\":\"$account_id\",\"accounts\":$accounts_json}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| #!/usr/bin/env bash | ||
| # Retrieves the secret for an existing Turnstile widget via the Cloudflare API. | ||
| # Used by the recovery flow so the agent can wire canonical server-side | ||
| # siteverify against an existing widget without rotating the sitekey. | ||
| # | ||
| # Reads: | ||
| # $CLOUDFLARE_API_TOKEN (required) | ||
| # | ||
| # Args: | ||
| # --account-id <id> Cloudflare account ID | ||
| # --sitekey <key> Widget sitekey to look up | ||
| # | ||
| # Outputs JSON. Exit 0 on success, 1 on failure. | ||
| # ok: {"status":"ok","secret":"<secret>","clearance_level":"<level>","domains":[<list>]} | ||
| # no_scope: {"status":"missing_read_scope","detail":"token lacks Account.Turnstile:Read"} | ||
| # not_found: {"status":"error","reason":"widget_not_found","http_code":<code>} | ||
| # | ||
| # The agent uses clearance_level to enforce the pre-clearance scope boundary | ||
| # (Spin only applies to widgets where clearance_level == "no_clearance"; for | ||
| # other levels siteverify is optional and the recovery flow should exit). | ||
| # | ||
| # Never propose recreating the widget to get a fresh secret; that breaks | ||
| # the existing sitekey everywhere the user has it deployed in their frontend. | ||
|
|
||
| set -uo pipefail | ||
|
|
||
| while [[ $# -gt 0 ]]; do | ||
| case $1 in | ||
| --account-id) ACCOUNT_ID="$2"; shift 2 ;; | ||
| --sitekey) SITEKEY="$2"; shift 2 ;; | ||
| *) echo "fetch-secret: unknown arg $1" >&2; exit 2 ;; | ||
| esac | ||
| done | ||
|
|
||
| : "${CLOUDFLARE_API_TOKEN:?CLOUDFLARE_API_TOKEN must be set}" | ||
| : "${ACCOUNT_ID:?--account-id required}" | ||
| : "${SITEKEY:?--sitekey required}" | ||
|
|
||
| tmp=$(mktemp) | ||
| http_code=$(curl -sS -w "%{http_code}" -o "$tmp" \ | ||
| "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/challenges/widgets/$SITEKEY" \ | ||
| -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" 2>/dev/null || echo "000") | ||
| body=$(cat "$tmp"); rm -f "$tmp" | ||
|
|
||
| if [ "$http_code" = "200" ]; then | ||
| secret=$(echo "$body" | (jq -r '.result.secret' 2>/dev/null || python3 -c "import sys,json; print(json.load(sys.stdin)['result']['secret'])")) | ||
| clearance=$(echo "$body" | (jq -r '.result.clearance_level // "no_clearance"' 2>/dev/null || python3 -c "import sys,json; print(json.load(sys.stdin)['result'].get('clearance_level','no_clearance'))")) | ||
| domains=$(echo "$body" | (jq -c '.result.domains // []' 2>/dev/null || python3 -c "import sys,json; print(json.dumps(json.load(sys.stdin)['result'].get('domains',[])))")) | ||
| if [ -n "$secret" ] && [ "$secret" != "null" ]; then | ||
| echo "{\"status\":\"ok\",\"secret\":\"$secret\",\"clearance_level\":\"$clearance\",\"domains\":$domains}" | ||
| exit 0 | ||
| fi | ||
| fi | ||
|
|
||
| if [ "$http_code" = "403" ]; then | ||
| code=$(echo "$body" | (jq -r '.errors[0].code // 0' 2>/dev/null || echo "0")) | ||
| if [ "$code" = "10000" ]; then | ||
| echo "fetch-secret: token can edit Turnstile widgets but cannot read this one's secret." >&2 | ||
| echo "fetch-secret: add Account.Turnstile:Read to the token, or fall back to user paste." >&2 | ||
| echo "{\"status\":\"missing_read_scope\",\"detail\":\"token lacks Account.Turnstile:Read\"}" | ||
| exit 1 | ||
| fi | ||
| fi | ||
|
|
||
| echo "fetch-secret: widget lookup failed (HTTP $http_code)." >&2 | ||
| echo "{\"status\":\"error\",\"reason\":\"widget_not_found\",\"http_code\":$http_code}" | ||
| exit 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| #!/usr/bin/env bash | ||
| # Persists the canonical Spin skill bundle (SKILL.md + scripts/ + references/) | ||
| # from cloudflare/skills to the user's repo so the agent can re-load it on | ||
| # follow-up tasks without re-pasting the bootstrap prompt. | ||
| # | ||
| # Args: | ||
| # --path <path> SKILL.md destination, e.g. .claude/skills/turnstile-spin/SKILL.md. | ||
| # The bundle is extracted into the parent directory of <path>, | ||
| # so scripts land at e.g. .claude/skills/turnstile-spin/scripts/. | ||
| # | ||
| # Outputs JSON. Exit 0 if the bundle was written, 1 on failure. | ||
| # ok: {"status":"ok","path":"<path>","bundle_root":"<dir>","scripts":[<list>]} | ||
| # fail: {"status":"error","reason":"<reason>"} | ||
|
|
||
| set -uo pipefail | ||
|
|
||
| PATH_ARG="" | ||
| while [[ $# -gt 0 ]]; do | ||
| case $1 in | ||
| --path) PATH_ARG="$2"; shift 2 ;; | ||
| *) echo "persist-skill: unknown arg $1" >&2; exit 2 ;; | ||
| esac | ||
| done | ||
|
|
||
| : "${PATH_ARG:?--path required}" | ||
|
|
||
| TARGET_DIR=$(dirname "$PATH_ARG") | ||
| mkdir -p "$TARGET_DIR" | ||
|
|
||
| # Install the canonical bundle from cloudflare/skills via degit. This writes | ||
| # SKILL.md, scripts/, references/, templates/, tests/ into $TARGET_DIR. | ||
| if ! npx --yes degit cloudflare/skills/skills/turnstile-spin "$TARGET_DIR" >/dev/null 2>&1; then | ||
| echo "persist-skill: degit failed; cannot fetch cloudflare/skills/skills/turnstile-spin." >&2 | ||
| echo "persist-skill: ensure your network can reach github.com and try again, or install manually." >&2 | ||
| echo "{\"status\":\"error\",\"reason\":\"degit_failed\"}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ ! -f "$TARGET_DIR/SKILL.md" ]; then | ||
| echo "persist-skill: bundle extracted but SKILL.md is missing at $TARGET_DIR/SKILL.md." >&2 | ||
| echo "{\"status\":\"error\",\"reason\":\"skill_missing\"}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Make scripts executable so the agent can invoke them directly. | ||
| if [ -d "$TARGET_DIR/scripts" ]; then | ||
| chmod +x "$TARGET_DIR/scripts"/*.sh 2>/dev/null || true | ||
| fi | ||
|
|
||
| scripts_list=$(ls "$TARGET_DIR/scripts" 2>/dev/null | sed 's/.*/"&"/' | paste -sd, -) | ||
| echo "persist-skill: wrote bundle to $TARGET_DIR" >&2 | ||
| echo "{\"status\":\"ok\",\"path\":\"$PATH_ARG\",\"bundle_root\":\"$TARGET_DIR\",\"scripts\":[$scripts_list]}" | ||
| exit 0 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.