@soleur/opencode 3.409.1 → 3.410.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/hooks/stop-hook.sh +138 -45
- package/package.json +1 -1
- package/scripts/cloudflare-readonly.sh +136 -31
- package/scripts/retry-budget-ruling.sh +557 -0
- package/scripts/retry-budget-ruling.test.sh +697 -0
- package/skills/brainstorm-techniques/references/standing-delegation.md +3 -3
- package/skills/one-shot/SKILL.md +4 -4
- package/skills/one-shot/references/retry-budget-ruling.md +59 -0
- package/skills/plan/references/plan-sharp-edges.md +1 -0
package/hooks/stop-hook.sh
CHANGED
|
@@ -37,6 +37,12 @@ NOW_EPOCH=$(date +%s)
|
|
|
37
37
|
for state_file in "${PROJECT_ROOT}/.claude"/ralph-loop.*.local.md; do
|
|
38
38
|
[[ -f "$state_file" ]] || continue
|
|
39
39
|
|
|
40
|
+
# The current session file is read for the one grant after this sweep.
|
|
41
|
+
# Dead-owner cleanup of other sessions stays.
|
|
42
|
+
if [[ "$(basename "$state_file")" == "$(basename "$RALPH_STATE_FILE")" ]]; then
|
|
43
|
+
continue
|
|
44
|
+
fi
|
|
45
|
+
|
|
40
46
|
# Extract owner PID from filename: ralph-loop.PID.local.md
|
|
41
47
|
OWNER_PID=$(basename "$state_file" | sed 's/^ralph-loop\.\([0-9]*\)\.local\.md$/\1/')
|
|
42
48
|
|
|
@@ -272,23 +278,114 @@ if [[ -z "$PROMPT_TEXT" ]]; then
|
|
|
272
278
|
exit 0
|
|
273
279
|
fi
|
|
274
280
|
|
|
281
|
+
# Read tally show before the awk rewrite. The grant line is still the value the
|
|
282
|
+
# parent wrote; this pass is what consumes it. Path resolution lives in
|
|
283
|
+
# pipeline-tally.sh — this hook reads `show` output, never the counter file.
|
|
284
|
+
TALLY_SCRIPT="$SCRIPT_DIR/../scripts/pipeline-tally.sh"
|
|
285
|
+
TALLY_OUT=""
|
|
286
|
+
TALLY_CAPPED=""
|
|
287
|
+
TALLY_CAP=""
|
|
288
|
+
downgrade=0
|
|
289
|
+
if [[ -f "$TALLY_SCRIPT" ]]; then
|
|
290
|
+
TALLY_OUT=$(bash "$TALLY_SCRIPT" show 2>/dev/null || true)
|
|
291
|
+
if [[ "$TALLY_OUT" == *"tally:"* && "$TALLY_OUT" != "UNKNOWN"* ]]; then
|
|
292
|
+
_TD="" _TC="" _TN=""
|
|
293
|
+
for _TD in $(printf '%s' "$TALLY_OUT" | grep -o 'capped:[a-z_]*=[0-9]*' | cut -d: -f2 | cut -d= -f1) \
|
|
294
|
+
$(printf '%s' "$TALLY_OUT" | grep -o 'cap:[a-z_]*=[0-9]*' | cut -d: -f2 | cut -d= -f1); do
|
|
295
|
+
[[ -n "$_TD" ]] || continue
|
|
296
|
+
if [[ "$TALLY_OUT" == *"capped:${_TD}="* ]]; then
|
|
297
|
+
TALLY_CAPPED="$_TD"
|
|
298
|
+
TALLY_CAP=$(printf '%s' "$TALLY_OUT" | grep -o "capped:${_TD}=[0-9]*" | cut -d= -f2 || true)
|
|
299
|
+
break
|
|
300
|
+
fi
|
|
301
|
+
# `|| true` on every extraction: a grep no-match under `set -e`/`pipefail`
|
|
302
|
+
# would exit the hook mid-loop — the opposite of this block's fail-open
|
|
303
|
+
# contract.
|
|
304
|
+
_TC=$(printf '%s' "$TALLY_OUT" | grep -o "cap:${_TD}=[0-9]*" | cut -d= -f2 || true)
|
|
305
|
+
_TN=$(printf '%s' "$TALLY_OUT" | grep -o "^tally:.*" | grep -o "${_TD}=[0-9]*" | cut -d= -f2 || true)
|
|
306
|
+
if [[ "$_TC" =~ ^[0-9]+$ ]] && [[ "$_TN" =~ ^[0-9]+$ ]] && (( 10#$_TC > 0 )) && (( 10#$_TN >= 10#$_TC )); then
|
|
307
|
+
TALLY_CAPPED="$_TD"; TALLY_CAP="$_TC"; break
|
|
308
|
+
fi
|
|
309
|
+
done
|
|
310
|
+
fi
|
|
311
|
+
fi
|
|
312
|
+
grant_exact=0
|
|
313
|
+
consumed_set=0
|
|
314
|
+
FRONT_NOW=$(awk '/^---$/{c++; if (c>=2) exit; next} c==1' "$RALPH_STATE_FILE" 2>/dev/null || true)
|
|
315
|
+
if grep -qx 'retry_budget_grant: 1' <<<"$FRONT_NOW"; then
|
|
316
|
+
grant_exact=1
|
|
317
|
+
fi
|
|
318
|
+
if grep -qx 'retry_budget_consumed: 1' <<<"$FRONT_NOW"; then
|
|
319
|
+
consumed_set=1
|
|
320
|
+
fi
|
|
321
|
+
# One consumed grant, and only while the tally is capped. A later 1 does not arm again.
|
|
322
|
+
if [[ -n "$TALLY_CAPPED" && "$grant_exact" -eq 1 && "$consumed_set" -eq 0 ]]; then
|
|
323
|
+
downgrade=1
|
|
324
|
+
fi
|
|
325
|
+
|
|
326
|
+
# TTL of the current file runs after the grant read. A file that is about to
|
|
327
|
+
# spend the grant stays. Any other stale current file is removed, which is the
|
|
328
|
+
# pre-grant behavior for a session that has no grant.
|
|
329
|
+
if [[ "$downgrade" -eq 0 && -f "$RALPH_STATE_FILE" ]]; then
|
|
330
|
+
STARTED_AT=$(printf '%s\n' "$FRONT_NOW" | grep '^started_at:' | sed 's/started_at: *//' | sed 's/^"\(.*\)"$/\1/' || true)
|
|
331
|
+
if [[ -n "$STARTED_AT" ]]; then
|
|
332
|
+
STARTED_EPOCH=$(date -d "$STARTED_AT" +%s 2>/dev/null || true)
|
|
333
|
+
if [[ -n "$STARTED_EPOCH" ]] && [[ $((NOW_EPOCH - STARTED_EPOCH)) -gt $((TTL_HOURS * 3600)) ]]; then
|
|
334
|
+
AGE_MINS=$(( (NOW_EPOCH - STARTED_EPOCH) / 60 ))
|
|
335
|
+
echo "Ralph loop: stale state file detected ($(basename "$RALPH_STATE_FILE"), started ${AGE_MINS}m ago, TTL=${TTL_HOURS}h). Auto-removing." >&2
|
|
336
|
+
rm -f "$RALPH_STATE_FILE"
|
|
337
|
+
exit 0
|
|
338
|
+
fi
|
|
339
|
+
fi
|
|
340
|
+
fi
|
|
341
|
+
|
|
275
342
|
# Update iteration and stuck_count in first frontmatter block only (awk scoped to c==1)
|
|
276
343
|
# Note: on legacy state files without stuck_count field, the awk match is a no-op for that line.
|
|
277
344
|
# The counter will not persist across iterations. Acceptable because legacy files are only
|
|
278
345
|
# created by pre-stuck-detection versions of setup-ralph-loop.sh; all new loops include the field.
|
|
346
|
+
# The same pass rewrites an exact unquoted retry_budget_grant: 1 to 0 and sets
|
|
347
|
+
# retry_budget_consumed: 1. It never clears the consumed line.
|
|
279
348
|
TEMP_FILE="${RALPH_STATE_FILE}.tmp.$$"
|
|
280
|
-
|
|
281
|
-
|
|
349
|
+
awk_rc=0
|
|
350
|
+
awk -v iter="$NEXT_ITERATION" -v sc="$STUCK_COUNT" -v lrh="$LAST_RESPONSE_HASH" -v rc="$REPEAT_COUNT" -v simc="$SIMILARITY_COUNT" -v lrw="$LAST_RESPONSE_WORDS" -v downgrade="$downgrade" '
|
|
351
|
+
BEGIN { seen_consumed = 0 }
|
|
352
|
+
/^---$/ {
|
|
353
|
+
c++
|
|
354
|
+
if (c == 2 && downgrade == 1 && seen_consumed == 0) {
|
|
355
|
+
print "retry_budget_consumed: 1"
|
|
356
|
+
}
|
|
357
|
+
print
|
|
358
|
+
next
|
|
359
|
+
}
|
|
282
360
|
c==1 && /^iteration:/ { print "iteration: " iter; next }
|
|
283
361
|
c==1 && /^stuck_count:/ { print "stuck_count: " sc; next }
|
|
284
362
|
c==1 && /^last_response_hash:/ { print "last_response_hash: " lrh; next }
|
|
285
363
|
c==1 && /^repeat_count:/ { print "repeat_count: " rc; next }
|
|
286
364
|
c==1 && /^similarity_count:/ { print "similarity_count: " simc; next }
|
|
287
365
|
c==1 && /^last_response_words:/ { print "last_response_words: " lrw; next }
|
|
366
|
+
c==1 && /^retry_budget_consumed: 1$/ { seen_consumed = 1; print; next }
|
|
367
|
+
c==1 && downgrade == 1 && /^retry_budget_grant: 1$/ { print "retry_budget_grant: 0"; next }
|
|
288
368
|
{ print }
|
|
289
|
-
' "$RALPH_STATE_FILE" > "$TEMP_FILE" 2>/dev/null ||
|
|
369
|
+
' "$RALPH_STATE_FILE" > "$TEMP_FILE" 2>/dev/null || awk_rc=$?
|
|
370
|
+
awk_rc="${awk_rc:-0}"
|
|
371
|
+
if [[ "$downgrade" -eq 1 ]]; then
|
|
372
|
+
front_closes=0
|
|
373
|
+
consumed_gate=1
|
|
374
|
+
if [[ -f "$TEMP_FILE" ]]; then
|
|
375
|
+
front_closes=$(grep -c '^---$' "$TEMP_FILE" || true)
|
|
376
|
+
consumed_gate=0
|
|
377
|
+
grep -qx 'retry_budget_consumed: 1' "$TEMP_FILE" || consumed_gate=$?
|
|
378
|
+
fi
|
|
379
|
+
if [[ "$awk_rc" -ne 0 || ! -s "$TEMP_FILE" || "$consumed_gate" -ne 0 || "${front_closes:-0}" -lt 2 ]]; then
|
|
380
|
+
if [[ "$consumed_gate" -ge 2 ]]; then
|
|
381
|
+
printf 'SOLEUR_TALLY_GRANT_READ grep-rc=%s\n' "$consumed_gate" >&2
|
|
382
|
+
fi
|
|
383
|
+
rm -f "$TEMP_FILE"
|
|
384
|
+
exit 0
|
|
385
|
+
fi
|
|
386
|
+
fi
|
|
290
387
|
if [[ -s "$TEMP_FILE" ]]; then
|
|
291
|
-
mv "$TEMP_FILE" "$RALPH_STATE_FILE"
|
|
388
|
+
mv "$TEMP_FILE" "$RALPH_STATE_FILE" || { rm -f "$TEMP_FILE"; exit 0; }
|
|
292
389
|
else
|
|
293
390
|
# awk produced empty output (file vanished) -- clean up and exit
|
|
294
391
|
rm -f "$TEMP_FILE"
|
|
@@ -307,50 +404,46 @@ fi
|
|
|
307
404
|
# `capped` latch OR any count >= its cap_<dim> (catches a latch that never got
|
|
308
405
|
# set: a skipped gate, a gate that returned UNKNOWN, a dim nobody gates) — the
|
|
309
406
|
# pipeline is budget-capped and this hook declines to keep the loop alive: it
|
|
310
|
-
# removes the fuel rather than denying a tool.
|
|
311
|
-
#
|
|
312
|
-
# directions: absent/corrupt/UNKNOWN
|
|
313
|
-
# blocks FOR the tally.
|
|
407
|
+
# removes the fuel rather than denying a tool. `show` already ran before the
|
|
408
|
+
# awk rewrite. Placed immediately before the block emit so every terminating
|
|
409
|
+
# path above still wins. Fail-open in BOTH directions: absent/corrupt/UNKNOWN
|
|
410
|
+
# output changes nothing — the hook never blocks FOR the tally.
|
|
314
411
|
#
|
|
315
|
-
#
|
|
316
|
-
#
|
|
317
|
-
#
|
|
318
|
-
|
|
319
|
-
if [[ -
|
|
320
|
-
|
|
321
|
-
TALLY_CAPPED
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
# `|| true` on every extraction: a grep no-match under `set -e`/`pipefail`
|
|
334
|
-
# would exit the hook mid-loop — the opposite of this block's fail-open
|
|
335
|
-
# contract.
|
|
336
|
-
_TC=$(printf '%s' "$TALLY_OUT" | grep -o "cap:${_TD}=[0-9]*" | cut -d= -f2 || true)
|
|
337
|
-
_TN=$(printf '%s' "$TALLY_OUT" | grep -o "^tally:.*" | grep -o "${_TD}=[0-9]*" | cut -d= -f2 || true)
|
|
338
|
-
if [[ "$_TC" =~ ^[0-9]+$ ]] && [[ "$_TN" =~ ^[0-9]+$ ]] && (( 10#$_TC > 0 )) && (( 10#$_TN >= 10#$_TC )); then
|
|
339
|
-
TALLY_CAPPED="$_TD"; TALLY_CAP="$_TC"; break
|
|
340
|
-
fi
|
|
341
|
-
done
|
|
342
|
-
if [[ -n "$TALLY_CAPPED" ]]; then
|
|
343
|
-
_TN=$(printf '%s' "$TALLY_OUT" | grep -o "^tally:.*" | grep -o "${TALLY_CAPPED}=[0-9]*" | cut -d= -f2 || true)
|
|
344
|
-
printf 'SOLEUR_TALLY_CAPPED dim=%s cap=%s\n' "$TALLY_CAPPED" "${TALLY_CAP:-0}" >&2
|
|
345
|
-
# `--reset` deliberately NOT suggested: bare `init --max-<dim> N` takes
|
|
346
|
-
# `capped-reset`, which unlatches but PRESERVES the tally the feature
|
|
347
|
-
# exists to keep.
|
|
348
|
-
printf 'Ralph loop: pipeline tally is budget-capped; resume via pipeline-tally.sh init --max-%s N (raised caps).\n' "$(printf '%s' "$TALLY_CAPPED" | tr '_' '-')" >&2
|
|
349
|
-
# Classified-stop artifact: the state file is the ralph loop's own
|
|
350
|
-
# record — a resume that only reads stderr would never see the stop.
|
|
351
|
-
printf 'budget-capped: %s=%s/%s\n' "$TALLY_CAPPED" "${_TN:-0}" "${TALLY_CAP:-0}" >> "$RALPH_STATE_FILE" 2>/dev/null || true
|
|
412
|
+
# One recorded grant may fall through to the keep-alive block below. That
|
|
413
|
+
# happens only when the read-back after the move is the exact line
|
|
414
|
+
# retry_budget_grant: 0. Any other read-back exits 0 with no block. The hook
|
|
415
|
+
# never clears capped=.
|
|
416
|
+
if [[ -n "$TALLY_CAPPED" ]]; then
|
|
417
|
+
_TN=$(printf '%s' "$TALLY_OUT" | grep -o "^tally:.*" | grep -o "${TALLY_CAPPED}=[0-9]*" | cut -d= -f2 || true)
|
|
418
|
+
printf 'SOLEUR_TALLY_CAPPED dim=%s cap=%s\n' "$TALLY_CAPPED" "${TALLY_CAP:-0}" >&2
|
|
419
|
+
# Classified-stop artifact: the state file is the ralph loop's own
|
|
420
|
+
# record — a resume that only reads stderr would never see the stop.
|
|
421
|
+
printf 'budget-capped: %s=%s/%s\n' "$TALLY_CAPPED" "${_TN:-0}" "${TALLY_CAP:-0}" >> "$RALPH_STATE_FILE" 2>/dev/null || true
|
|
422
|
+
if [[ "$downgrade" -eq 1 ]]; then
|
|
423
|
+
readback=$(awk '/^---$/{c++; if (c>=2) exit; next} c==1' "$RALPH_STATE_FILE" 2>/dev/null || true)
|
|
424
|
+
grant_rc=0
|
|
425
|
+
grep -qx 'retry_budget_grant: 0' <<<"$readback" || grant_rc=$?
|
|
426
|
+
if [[ "$grant_rc" -ge 2 ]]; then
|
|
427
|
+
printf 'SOLEUR_TALLY_GRANT_READ grep-rc=%s\n' "$grant_rc" >&2
|
|
428
|
+
fi
|
|
429
|
+
if [[ "$grant_rc" -ne 0 ]]; then
|
|
352
430
|
exit 0
|
|
353
431
|
fi
|
|
432
|
+
consumed_rc=0
|
|
433
|
+
grep -qx 'retry_budget_consumed: 1' <<<"$readback" || consumed_rc=$?
|
|
434
|
+
if [[ "$consumed_rc" -ge 2 ]]; then
|
|
435
|
+
printf 'SOLEUR_TALLY_GRANT_READ grep-rc=%s\n' "$consumed_rc" >&2
|
|
436
|
+
fi
|
|
437
|
+
if [[ "$consumed_rc" -ne 0 ]]; then
|
|
438
|
+
exit 0
|
|
439
|
+
fi
|
|
440
|
+
else
|
|
441
|
+
# `--reset` deliberately NOT suggested: bare `init --max-<dim> N` takes
|
|
442
|
+
# `capped-reset`, which unlatches but PRESERVES the tally the feature
|
|
443
|
+
# exists to keep. The resume line is the real halt. A grant path falls
|
|
444
|
+
# through to the keep-alive block and does not print it.
|
|
445
|
+
printf 'Ralph loop: pipeline tally is budget-capped; resume via pipeline-tally.sh init --max-%s N (raised caps).\n' "$(printf '%s' "$TALLY_CAPPED" | tr '_' '-')" >&2
|
|
446
|
+
exit 0
|
|
354
447
|
fi
|
|
355
448
|
fi
|
|
356
449
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# cloudflare-readonly.sh -
|
|
3
|
-
# four GET reads and
|
|
2
|
+
# cloudflare-readonly.sh - seven READ-ONLY Cloudflare checks for the Class R live-read acts (#10479, #12441, #12846, Ref #10205):
|
|
3
|
+
# four GET reads and three fixed read-only GraphQL analytics reads (the one documented POST exception, below).
|
|
4
4
|
#
|
|
5
5
|
# Jikigai-internal. It is inert wherever the CF_* token variables are absent, and it refuses unless it runs under the
|
|
6
6
|
# Doppler project `soleur` and config `prd_terraform` (those two variables are a mistake-guard: the environment can be forged).
|
|
@@ -12,12 +12,16 @@
|
|
|
12
12
|
# change-history E. bounded 7-day audit-log read GET /accounts/{account}/logs/audit (counts only)
|
|
13
13
|
# analytics-health <hours> F. /health origin response time per hour POST /graphql, one fixed query (#12441)
|
|
14
14
|
# analytics-edge-errors <hours> G. edge 5xx status counts per hour POST /graphql, one fixed query (#12441)
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
15
|
+
# analytics-health-colo <hours> <end-offset-hours> H. /health origin response time per hour and colo, host app.soleur.ai POST /graphql, one fixed query (#12846)
|
|
16
|
+
# --list print the seven names, exit 0 (no credential, no network)
|
|
17
|
+
# The four GET subcommands take no further argument. analytics-health and analytics-edge-errors take exactly one more: a whole
|
|
18
|
+
# number of hours, 1 to 216 (9 days, the one verified window), no default. analytics-health-colo takes exactly two more: the same
|
|
19
|
+
# hours, then a whole end offset in hours, 0 to 527, with no sign, no leading zero and no default; the window then ends that many
|
|
20
|
+
# hours before the current hour, so hours + offset is at most 743 by construction (inside the documented 31-day retention).
|
|
21
|
+
# Every argument is checked before any credential is read.
|
|
18
22
|
#
|
|
19
23
|
# Invocation (direct exec; never wrap this file in a shell under doppler run, the Credentials paragraph forbids it):
|
|
20
|
-
# doppler run -p soleur -c prd_terraform -- plugins/soleur/scripts/cloudflare-readonly.sh <subcommand> [<hours>]
|
|
24
|
+
# doppler run -p soleur -c prd_terraform -- plugins/soleur/scripts/cloudflare-readonly.sh <subcommand> [<hours> [<end-offset-hours>]]
|
|
21
25
|
# Run it from the repository checkout where `git diff origin/main -- plugins/soleur/scripts/cloudflare-readonly.sh` is
|
|
22
26
|
# empty (a freshly fetched origin/main), never from a plugin-cache copy. Until this file is on origin/main that diff cannot
|
|
23
27
|
# be empty, so the first live read is after the merge.
|
|
@@ -27,7 +31,7 @@
|
|
|
27
31
|
# pagerules-ssl -> CF_API_TOKEN_PAGERULES_READ (zone-scoped Page Rules: Read on soleur.ai only; read-only; no fallback to
|
|
28
32
|
# CF_API_TOKEN_RULESETS, which returned 403 on /pagerules, and no fallback to any other token)
|
|
29
33
|
# change-history -> CF_API_TOKEN_AUDIT plus CF_ACCOUNT_ID the others also need CF_ZONE_ID
|
|
30
|
-
# analytics-health, analytics-edge-errors -> CF_API_TOKEN_ANALYTICS_READ (Analytics:Read on the zone soleur.ai only; read-only;
|
|
34
|
+
# analytics-health, analytics-edge-errors, analytics-health-colo -> CF_API_TOKEN_ANALYTICS_READ (Analytics:Read on the zone soleur.ai only; read-only;
|
|
31
35
|
# expires 2027-02-07, after which a 401 records `token-invalid`; no fallback to any other token). Nothing else reads it.
|
|
32
36
|
# CF_API_TOKEN_ZONE_SETTINGS and CF_API_TOKEN_RULESETS are Terraform-scoped and write-capable (no read-only equivalent exists
|
|
33
37
|
# yet); that exception is removable when read-only equivalents are minted, which is a credential change and the owner's.
|
|
@@ -38,20 +42,36 @@
|
|
|
38
42
|
# environment for curl AND for every jq and date child (`/usr/bin/env -i`; an empty HOME means a planted ~/.jq is not
|
|
39
43
|
# loaded and `$ENV` is empty, verified on jq 1.8.2), the credential on curl's stdin config only, and the xtrace refusal. See standing-delegation.md
|
|
40
44
|
# section 9 (Credentials) for the stated exception. A 403 is recorded as unverified and never answered by a token swap.
|
|
45
|
+
# CLOSED ENVIRONMENT (security fix round 1, Ref #12846): `doppler run` puts every secret of prd_terraform in this script's
|
|
46
|
+
# environment, so after the xtrace refusal the script closes its SHELL-VISIBLE environment to a fixed allowlist (the Doppler pair,
|
|
47
|
+
# CF_ZONE_ID, CF_ACCOUNT_ID, the five bound tokens, PATH and LC_ALL): it re-execs itself once under `/usr/bin/env -u <name>...`,
|
|
48
|
+
# argv unchanged, removing every other name `compgen -e` lists and every exported function `compgen -A function` lists. The decision
|
|
49
|
+
# is made on the set of names present, never on a marker a caller sets; the per-name decisions sit beside the code. CF_API_TOKEN is
|
|
50
|
+
# not kept. Scope: after the re-exec a read of an unlisted name from THIS process's environment finds it unset, whatever its syntax
|
|
51
|
+
# (indirection, nameref, printf -v, arithmetic). It closes nothing else. An environment entry bash does not import (a name that is
|
|
52
|
+
# not an identifier, such as `a-b=1`) is not listed, so it is not removed and stays readable through /proc/self/environ. Reading a
|
|
53
|
+
# file, or another process's environment (/proc/<pid>/environ, the parent's included), is not closed by it either: those are
|
|
54
|
+
# narrowed by the suite's code censuses (no file input redirection, no source or `.`, no tilde, absolute tools only), not here,
|
|
55
|
+
# and not closed: a file named as a tool operand or a builtin's path argument (`date -f FILE`, a jq file operand, `history -r
|
|
56
|
+
# FILE`) is not a redirection, and whether another suite row reds such an edit is unmeasured.
|
|
41
57
|
#
|
|
42
|
-
# READ-ONLY POST EXCEPTION (#12441): a GraphQL read is an HTTP POST that only reads. Exactly
|
|
43
|
-
# file (GQL_HEALTH_TPL, GQL_EDGE_TPL); the only substitutions are the zone id and two window stamps computed
|
|
44
|
-
# caller
|
|
45
|
-
# reaches curl only as a data-raw line of the stdin config, beside the Authorization and Content-Type lines, never
|
|
46
|
-
# window is complete UTC hours, [
|
|
58
|
+
# READ-ONLY POST EXCEPTION (#12441, #12846): a GraphQL read is an HTTP POST that only reads. Exactly three fixed queries are compiled
|
|
59
|
+
# into this file (GQL_HEALTH_TPL, GQL_EDGE_TPL, GQL_COLO_TPL); the only substitutions are the zone id and two window stamps computed
|
|
60
|
+
# from the clock, so no caller integer ever enters the query text and no query text, filter, path, host or method comes from the
|
|
61
|
+
# caller. The body reaches curl only as a data-raw line of the stdin config, beside the Authorization and Content-Type lines, never
|
|
62
|
+
# on argv. The window is complete UTC hours, [E - hours, E), where E is the current hour minus the end offset (0 for F and G), so
|
|
63
|
+
# the newest series point lags by up to one hour. Counts are sampled estimates.
|
|
47
64
|
# A zone the token cannot see and a wrong zone id are not distinguished (`no-zone-access`), like the 401 / 403 note below.
|
|
48
|
-
# Unverified (public docs do not cover them; the first sanctioned read after the merge is the check
|
|
49
|
-
# the edgeResponseStatus dimension and its range operators, orderBy datetimeHour_DESC on this node,
|
|
65
|
+
# Unverified (public docs do not cover them; the first sanctioned read after the merge is the check; fix PRs: F and G at most two in total, #12441; H at most one, #12846):
|
|
66
|
+
# the edgeResponseStatus dimension and its range operators, orderBy datetimeHour_DESC on this node, the duration quantile names, the
|
|
67
|
+
# coloCode dimension, the host and path filters together on this node, and the 10000 row cap.
|
|
50
68
|
#
|
|
51
69
|
# RESIDUAL, not fixed here: BASH_ENV, exported BASH_FUNC_* functions, SHELLOPTS and PS4, LD_PRELOAD and the shebang's PATH lookup
|
|
52
|
-
# (`#!/usr/bin/env bash`) are caller-environment channels that act in this script's OWN bash before and
|
|
53
|
-
#
|
|
54
|
-
#
|
|
70
|
+
# (`#!/usr/bin/env bash`) are caller-environment channels that act in this script's OWN first bash, before and during the xtrace
|
|
71
|
+
# and closed-environment blocks. The re-exec removes their environment entries for the second start, but only when the re-exec
|
|
72
|
+
# runs: an exported function named like a builtin the closed-environment block calls (mapfile, compgen, type, exec, printf, [)
|
|
73
|
+
# can stop the re-exec or fake its result, so the closure itself sits inside this residual. LD_PRELOAD has loaded once by then.
|
|
74
|
+
# The caller is the operator's `doppler run`; nothing in this file claims to defend against a hostile caller environment.
|
|
55
75
|
# ACCEPTED RESIDUAL: a rule ref or an id is operator-authored data and is printed verbatim after a shape check (1 to 64 characters
|
|
56
76
|
# of A-Z a-z 0-9 _ -); it is data under the Boundary paragraph of section 9, never an instruction, and the shapes are bounded.
|
|
57
77
|
#
|
|
@@ -95,7 +115,7 @@
|
|
|
95
115
|
# Records mapping (section 9 Records; the wrapper verdict is NOT a Records verdict). Each check is its own
|
|
96
116
|
# Checked: / Unverified: line with a stable key: `Cloudflare ssl-mode (A) #10479`, `Cloudflare config-entrypoint (B) #10479`,
|
|
97
117
|
# `Cloudflare pagerules-ssl (C) #10479`, `Cloudflare change-history (E) #10479`, `Cloudflare analytics-health (F) #12441`,
|
|
98
|
-
# `Cloudflare analytics-edge-errors (G) #12441`.
|
|
118
|
+
# `Cloudflare analytics-edge-errors (G) #12441`, `Cloudflare analytics-health-colo (H) #12846`.
|
|
99
119
|
# A ssl-mode figure value=<value>; Records ok when value is strict (the runbook claim), bad on any other value.
|
|
100
120
|
# An A ok NEVER stands alone for a flip go: read it together with B.
|
|
101
121
|
# B config-entrypoint figures rule_count, enabled_ssl_rules (the count of rules that are enabled, i.e. `enabled != false`,
|
|
@@ -128,8 +148,13 @@
|
|
|
128
148
|
# G analytics-edge-errors figures by_status (counts per observed 5xx status) and truncated. Same rule: ALWAYS `Unverified:`;
|
|
129
149
|
# `rows: 0` and `by_status: {}` are never recorded as "no edge 5xx" (blank edge-generated 502/503/504 pages
|
|
130
150
|
# may be under-reported by this dataset). Neither computes an exact error rate (counts are sampled).
|
|
131
|
-
#
|
|
132
|
-
#
|
|
151
|
+
# H analytics-health-colo figures zone (the CF_ZONE_ID the read used), window_end and window_hours (the window), rows, truncated
|
|
152
|
+
# and the per-hour, per-colo count, avg_ms, p50_ms and p90_ms. ALWAYS `Unverified:`, never `Checked:`. `rows: 0`
|
|
153
|
+
# is never "no data problem" (a wrong zone or filter returns nothing too). A `zone` that is not the zone the
|
|
154
|
+
# record claims makes the read `other: wrong-zone` for that record. A colo that is not three capital letters
|
|
155
|
+
# prints as null; a truncated read is never a verdict input (re-run with a smaller window).
|
|
156
|
+
# What to do next for F, G and H, by wrapper output (the runbook origin-tls-strict-flip.md holds F and G's copy in its additions-only 2026-11-09 addendum; H's cap and deadline are in its 2026-11-19 addendum):
|
|
157
|
+
# `api-error (graphql: unknown field ...)` -> a wrapper fix PR (F and G: at most two in total, #12441; H: at most one, #12846)
|
|
133
158
|
# plain `api-error` (the message gate refused it) -> re-run once; if it repeats it counts as a wrapper fix PR (same cap)
|
|
134
159
|
# `bad-response (shape)` or `(jq exit n)` -> the vendor shape differs from the query's assumptions: a wrapper fix PR (same cap)
|
|
135
160
|
# `upstream-error` (429, 5xx, curl exit) -> one re-run after a pause, then record; not a fix PR
|
|
@@ -142,7 +167,7 @@
|
|
|
142
167
|
# Reasons to Records vocabulary: exit 10 -> no-credential; `no-tool (...)` -> `no-tool`; every other exit 11 and 14 reason -> `other: <the
|
|
143
168
|
# leading reason token only>` (for example `other: no-zone-access`, `other: api-error`); anything in parentheses is DATA and is never copied
|
|
144
169
|
# into a Records line, an issue, a pull request or a commit message, and for `api-error (graphql: ...)` that means the vendor text above all
|
|
145
|
-
# (a fix PR names the query F or
|
|
170
|
+
# (a fix PR names the query F, G or H and the field as written in this file's compiled-in query, never copied from the vendor text); exit 64 for a
|
|
146
171
|
# usage error records nothing (re-run correctly); exit 64 for a refused source or token shape -> `other: refused-source`;
|
|
147
172
|
# status 78 -> `other: xtrace`; a checkout whose diff against origin/main for this file is non-empty -> `other: wrapper-drift`
|
|
148
173
|
# (fetch, rebase, re-diff, re-run); 429 / 5xx -> one re-run after a pause is allowed, the newest line governs.
|
|
@@ -161,6 +186,42 @@ case "$-" in
|
|
|
161
186
|
;;
|
|
162
187
|
esac
|
|
163
188
|
|
|
189
|
+
# CLOSED ENVIRONMENT (see the header). Runs after the tracing check and before any other variable is read. When the environment
|
|
190
|
+
# holds an exported name outside this allowlist, or any exported shell function, the script re-execs itself ONCE with exactly those
|
|
191
|
+
# removed and argv unchanged. The decision is the SET OF NAMES (compgen), never a variable a caller could set to skip it:
|
|
192
|
+
# CF_RO_ENV_CLOSED is set only by the re-exec, to stop a second one, and a caller who sets it while the environment is still open is
|
|
193
|
+
# refused (64), never let through. Removal is `env -u NAME`, names only, so no credential value is ever on an argv or a traced line.
|
|
194
|
+
# One decision per allowed name:
|
|
195
|
+
# DOPPLER_PROJECT DOPPLER_CONFIG read by guard_source
|
|
196
|
+
# CF_ZONE_ID CF_ACCOUNT_ID read by load_credential and the URL templates
|
|
197
|
+
# CF_API_TOKEN_ZONE_SETTINGS CF_API_TOKEN_RULESETS CF_API_TOKEN_PAGERULES_READ CF_API_TOKEN_AUDIT CF_API_TOKEN_ANALYTICS_READ
|
|
198
|
+
# the five bound tokens, read only through ${!TOKVAR}
|
|
199
|
+
# PATH forwarded as is; reset to /usr/bin:/bin below, and every tool is called by absolute path
|
|
200
|
+
# LC_ALL forwarded; exported as C below (forwarded so a caller locale still meets that line)
|
|
201
|
+
# CF_RO_ENV_CLOSED this block's own one-shot guard
|
|
202
|
+
# PWD SHLVL _ bash's own, re-created by bash at every start and never read here (exempt, so no loop)
|
|
203
|
+
# Removed, among every other name: CF_API_TOKEN (read only by the tracing check above, which has already run; never sent), HOME,
|
|
204
|
+
# LANG and the other LC_*, TZ, TMPDIR, BASH_ENV, SHELLOPTS, BASHOPTS, PS4, the other DOPPLER_* names and every other secret that
|
|
205
|
+
# doppler run injects. Proof of one re-exec: the second start sees only allowed names plus what bash itself adds (PWD SHLVL _).
|
|
206
|
+
[ "$(type -t compgen)" = builtin ] || { printf 'cloudflare-readonly: refused: the environment cannot be listed\n' >&2; exit 64; }
|
|
207
|
+
mapfile -t ENV_NAMES < <(compgen -e)
|
|
208
|
+
mapfile -t ENV_FUNCS < <(compgen -A function)
|
|
209
|
+
ENV_DROP=()
|
|
210
|
+
for ENV_N in ${ENV_NAMES[@]+"${ENV_NAMES[@]}"}; do
|
|
211
|
+
case "$ENV_N" in
|
|
212
|
+
DOPPLER_PROJECT | DOPPLER_CONFIG | CF_ZONE_ID | CF_ACCOUNT_ID | CF_API_TOKEN_ZONE_SETTINGS | CF_API_TOKEN_RULESETS) : ;;
|
|
213
|
+
CF_API_TOKEN_PAGERULES_READ | CF_API_TOKEN_AUDIT | CF_API_TOKEN_ANALYTICS_READ | PATH | LC_ALL | CF_RO_ENV_CLOSED) : ;;
|
|
214
|
+
PWD | SHLVL | _) : ;;
|
|
215
|
+
*) ENV_DROP=(${ENV_DROP[@]+"${ENV_DROP[@]}"} -u "$ENV_N") ;;
|
|
216
|
+
esac
|
|
217
|
+
done
|
|
218
|
+
for ENV_N in ${ENV_FUNCS[@]+"${ENV_FUNCS[@]}"}; do ENV_DROP=(${ENV_DROP[@]+"${ENV_DROP[@]}"} -u "BASH_FUNC_${ENV_N}%%"); done
|
|
219
|
+
if [ "${#ENV_DROP[@]}" -gt 0 ]; then
|
|
220
|
+
if [ -n "${CF_RO_ENV_CLOSED:-}" ]; then printf 'cloudflare-readonly: refused: the environment is still open after the re-exec\n' >&2; exit 64; fi
|
|
221
|
+
exec /usr/bin/env "${ENV_DROP[@]}" CF_RO_ENV_CLOSED=1 "$BASH" "$0" "$@"
|
|
222
|
+
fi
|
|
223
|
+
unset ENV_NAMES ENV_FUNCS ENV_DROP ENV_N
|
|
224
|
+
|
|
164
225
|
export LC_ALL=C
|
|
165
226
|
PATH=/usr/bin:/bin
|
|
166
227
|
# TLS-subverting and resolver environment: closing --disable (curlrc) and --noproxy (proxy vars) does not touch these.
|
|
@@ -172,14 +233,18 @@ CURL=/usr/bin/curl
|
|
|
172
233
|
|
|
173
234
|
BASE='https://api.cloudflare.com/client/v4'
|
|
174
235
|
GQL_URL="$BASE/graphql"
|
|
175
|
-
SUBCOMMANDS=(ssl-mode config-entrypoint pagerules-ssl change-history analytics-health analytics-edge-errors)
|
|
236
|
+
SUBCOMMANDS=(ssl-mode config-entrypoint pagerules-ssl change-history analytics-health analytics-edge-errors analytics-health-colo)
|
|
176
237
|
TOKEN_RE='^[A-Za-z0-9._~+/=-]+$'
|
|
177
238
|
ID_RE='^[0-9a-f]{32}$'
|
|
178
239
|
STAMP_RE='^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$'
|
|
179
240
|
LIMIT=50
|
|
180
|
-
QLIMIT=0 # the edge
|
|
241
|
+
QLIMIT=0 # a row cap; the edge and colo arms each set it to their template's cap (a suite row ties each) so truncated fires at the cap
|
|
181
242
|
HOURS=0
|
|
182
243
|
MAX_HOURS=216
|
|
244
|
+
# the end offset of analytics-health-colo; assigned here unconditionally (an inherited value would be evaluated in arithmetic)
|
|
245
|
+
# MAX_OFFSET is 743 - MAX_HOURS; 743 = 31 x 24 - 1, so a window never reaches past the documented 31-day retention
|
|
246
|
+
MAX_OFFSET=527
|
|
247
|
+
END_OFFSET=0
|
|
183
248
|
GQL_MSG_RE='^[A-Za-z0-9 ._'"'"'"()-]{1,160}$'
|
|
184
249
|
WIN_START=""
|
|
185
250
|
WIN_END=""
|
|
@@ -191,11 +256,13 @@ BODY=""
|
|
|
191
256
|
STATUS=""
|
|
192
257
|
|
|
193
258
|
# Row limits: the health query's (300) covers one row per hour for up to MAX_HOURS (216) hours; the edge query's cap (1000) is ordered DESC so
|
|
194
|
-
# the oldest rows drop first
|
|
195
|
-
#
|
|
259
|
+
# the oldest rows drop first; the colo query's cap (10000) is ordered ASC, so a truncated colo read loses its newest hours and is re-run
|
|
260
|
+
# with a smaller window. A suite row ties each to its constant.
|
|
261
|
+
# The three fixed GraphQL query bodies (compiled in; the only substitutions are the zone id and the two window stamps, each validated
|
|
196
262
|
# upstream). Read-only by construction: no mutation, no subscription, no introspection. Placeholders: @ZONE@ @START@ @END@.
|
|
197
263
|
GQL_HEALTH_TPL='{"query":"query{viewer{zones(filter:{zoneTag:\"@ZONE@\"}){httpRequestsAdaptiveGroups(limit:300,filter:{datetime_geq:\"@START@\",datetime_lt:\"@END@\",clientRequestPath:\"/health\"},orderBy:[datetimeHour_ASC]){count dimensions{datetimeHour} avg{originResponseDurationMs} quantiles{originResponseDurationMsP50 originResponseDurationMsP90}}}}}"}'
|
|
198
264
|
GQL_EDGE_TPL='{"query":"query{viewer{zones(filter:{zoneTag:\"@ZONE@\"}){httpRequestsAdaptiveGroups(limit:1000,filter:{datetime_geq:\"@START@\",datetime_lt:\"@END@\",clientRequestHTTPHost:\"app.soleur.ai\",edgeResponseStatus_geq:500,edgeResponseStatus_lt:600},orderBy:[datetimeHour_DESC]){count dimensions{datetimeHour edgeResponseStatus}}}}}"}'
|
|
265
|
+
GQL_COLO_TPL='{"query":"query{viewer{zones(filter:{zoneTag:\"@ZONE@\"}){httpRequestsAdaptiveGroups(limit:10000,filter:{datetime_geq:\"@START@\",datetime_lt:\"@END@\",clientRequestHTTPHost:\"app.soleur.ai\",clientRequestPath:\"/health\"},orderBy:[datetimeHour_ASC]){count dimensions{datetimeHour coloCode} avg{originResponseDurationMs} quantiles{originResponseDurationMsP50 originResponseDurationMsP90}}}}}"}'
|
|
199
266
|
|
|
200
267
|
die() { # $1 = exit code, $2 = fixed message (never a value)
|
|
201
268
|
printf 'cloudflare-readonly: %s\n' "$2" >&2
|
|
@@ -219,6 +286,7 @@ bad_shape() { # jq succeeded but the body is not the expected shape (or is empty
|
|
|
219
286
|
JQ_DEFS='def enum: if type == "string" and test("\\A(off|flexible|full|strict)\\z") then . else "other" end;
|
|
220
287
|
def sslv: if . == null then null else enum end;
|
|
221
288
|
def idv: if type == "string" and test("\\A[A-Za-z0-9_-]{1,64}\\z") then . else "invalid" end;
|
|
289
|
+
def colo: if type == "string" and test("\\A[A-Z]{3}\\z") then . else null end;
|
|
222
290
|
def rfc: "\\A[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]{1,9})?Z\\z";
|
|
223
291
|
def tsn: if . == null then null elif type == "string" and test(rfc) then . else "invalid" end;
|
|
224
292
|
def gk: if type == "string" and test("\\A[a-z_.]{1,64}\\z") then . else "invalid" end;
|
|
@@ -244,12 +312,18 @@ guard_body() {
|
|
|
244
312
|
*) bad_shape ;;
|
|
245
313
|
esac
|
|
246
314
|
}
|
|
247
|
-
# project <jq program
|
|
315
|
+
# project <jq program> [<JSON members>]: run the projection and emit it; a jq failure never prints jq's diagnostic. The optional
|
|
316
|
+
# second argument (analytics-health-colo only: its zone and window_end, both validated upstream) is spliced in front of the
|
|
317
|
+
# projection's members outside jq, and only when the projection is one JSON object on one line.
|
|
248
318
|
project() {
|
|
249
319
|
local res jrc
|
|
250
320
|
res=$(/usr/bin/env -i /usr/bin/jq -c --argjson limit "$LIMIT" --argjson qlimit "$QLIMIT" --argjson hours "$HOURS" "$JQ_DEFS $1" < <(printf '%s' "$BODY") 2>&1)
|
|
251
321
|
jrc=$?
|
|
252
322
|
if [ "$jrc" -ne 0 ]; then bad_jq "$jrc"; fi
|
|
323
|
+
if [ -n "${2:-}" ]; then
|
|
324
|
+
case "$res" in *$'\n'*) bad_shape ;; '{"'*'}') : ;; *) bad_shape ;; esac
|
|
325
|
+
res="{$2,${res#\{}"
|
|
326
|
+
fi
|
|
253
327
|
emit_ok "$res"
|
|
254
328
|
}
|
|
255
329
|
|
|
@@ -309,7 +383,7 @@ cf_get() { # $1 = full URL ; sets BODY, or exits with the mapped verdict
|
|
|
309
383
|
esac
|
|
310
384
|
}
|
|
311
385
|
|
|
312
|
-
# --- the ONE read-only POST chokepoint (the
|
|
386
|
+
# --- the ONE read-only POST chokepoint (the three analytics subcommands): a compiled-in query, one call, empty curl environment ---
|
|
313
387
|
# A GraphQL read is an HTTP POST. The body is a fixed template with a zone id and two window stamps substituted; it reaches curl
|
|
314
388
|
# only as a `data-raw` line of the stdin config (never argv), beside the Authorization and Content-Type header lines.
|
|
315
389
|
gql_stdin() { # $1 = the escaped body ; the three config lines of the POST
|
|
@@ -393,7 +467,8 @@ gql_fill() {
|
|
|
393
467
|
printf '%s' "$b"
|
|
394
468
|
}
|
|
395
469
|
# gql_window: complete UTC hours only, [end - HOURS h, end), by epoch arithmetic; the partial current hour is excluded, so the
|
|
396
|
-
# series lags by up to one hour
|
|
470
|
+
# series lags by up to one hour, and end moves back END_OFFSET hours (0 on every arm except analytics-health-colo). The caller's
|
|
471
|
+
# integers never enter the query text: only the two computed stamps do.
|
|
397
472
|
gql_window() {
|
|
398
473
|
local t end start rc
|
|
399
474
|
[ -x /usr/bin/date ] || unverified "no-tool (date)" 14
|
|
@@ -401,6 +476,7 @@ gql_window() {
|
|
|
401
476
|
rc=$?
|
|
402
477
|
if [ "$rc" -ne 0 ] || [[ ! "$t" =~ ^[0-9]{10}$ ]]; then die 64 "refused: date produced no valid UTC stamp"; fi
|
|
403
478
|
end=$((10#$t - 10#$t % 3600))
|
|
479
|
+
end=$((end - END_OFFSET * 3600))
|
|
404
480
|
start=$((end - HOURS * 3600))
|
|
405
481
|
WIN_END=$(/usr/bin/env -i /usr/bin/date -u -d "@$end" +%Y-%m-%dT%H:%M:%SZ)
|
|
406
482
|
rc=$?
|
|
@@ -419,8 +495,21 @@ need_hours() {
|
|
|
419
495
|
if [ "$2" -gt "$MAX_HOURS" ]; then die 64 "refused: hours is above the maximum of $MAX_HOURS"; fi
|
|
420
496
|
HOURS="$2"
|
|
421
497
|
}
|
|
498
|
+
# need_colo_args "$@": the analytics-health-colo arity, hours and end-offset grammar, checked before load_credential. The hours go
|
|
499
|
+
# through need_hours (one grammar, one set of messages); the offset is checked by its regex FIRST and only then by a fail-closed
|
|
500
|
+
# bound (an integer test on an overflowing value is rc 2, so the bound passes only when -le succeeds). No (( )) or [[ -gt ]] ever
|
|
501
|
+
# reads a raw argument (both evaluate it as arithmetic). Written with `if`, never a second `case "$SUB"`.
|
|
502
|
+
need_colo_args() {
|
|
503
|
+
if [ "$#" -ne 3 ]; then
|
|
504
|
+
die 64 "usage: cloudflare-readonly.sh analytics-health-colo <hours> <end-offset-hours> (refused: missing or extra argument; hours 1-$MAX_HOURS, end offset 0-$MAX_OFFSET)"
|
|
505
|
+
fi
|
|
506
|
+
need_hours "$1" "$2"
|
|
507
|
+
if [[ ! "$3" =~ ^(0|[1-9][0-9]{0,2})$ ]]; then die 64 "refused: end offset must be a whole number from 0 to $MAX_OFFSET"; fi
|
|
508
|
+
[ "$3" -le "$MAX_OFFSET" ] || die 64 "refused: end offset is above the maximum of $MAX_OFFSET"
|
|
509
|
+
END_OFFSET="$3"
|
|
510
|
+
}
|
|
422
511
|
|
|
423
|
-
# --- the
|
|
512
|
+
# --- the seven reads (four GET, three read-only POST) ---
|
|
424
513
|
sub_ssl_mode() {
|
|
425
514
|
cf_get "$BASE/zones/$CF_ZONE_ID/settings/ssl"
|
|
426
515
|
guard_body '.success == true and (.result | type) == "object"'
|
|
@@ -467,14 +556,29 @@ sub_analytics_edge_errors() {
|
|
|
467
556
|
QLIMIT=1000
|
|
468
557
|
project '.data.viewer.zones[0].httpRequestsAdaptiveGroups as $g | {subcommand: "analytics-edge-errors", window_hours: $hours, rows: ($g | length), truncated: (($g | length) >= $qlimit), note: "counts are sampled estimates (adaptive sampling); edge-generated blank 502/503/504 pages may be under-reported by this dataset", by_status: ([$g[] | {k: (.dimensions.edgeResponseStatus | tostring), c: .count}] | group_by(.k) | map({key: .[0].k, value: (map(.c) | add)}) | from_entries), hourly: ([$g[] | {hour: .dimensions.datetimeHour, status: .dimensions.edgeResponseStatus, count: .count}] | sort_by([.hour, .status]))}'
|
|
469
558
|
}
|
|
559
|
+
# sub_analytics_health_colo: the F query scoped to the host app.soleur.ai and split by coloCode, over a window that ends END_OFFSET
|
|
560
|
+
# hours before the current hour. Hours are accepted only on the hour; a coloCode that is null or a string passes the guard and prints
|
|
561
|
+
# only as three capital letters or null (the raw value is never printed); the series is sorted on the cleaned values.
|
|
562
|
+
# Its row cap is the 10000 of GQL_COLO_TPL (the dataset's documented maxPageSize example). Its truncated test is written with the
|
|
563
|
+
# cap on the left, the reverse of the edge arm's spelling, so each arm's mutation anchor matches exactly once; keep them different.
|
|
564
|
+
sub_analytics_health_colo() {
|
|
565
|
+
local body
|
|
566
|
+
gql_window
|
|
567
|
+
body=$(gql_fill "$GQL_COLO_TPL")
|
|
568
|
+
cf_graphql "$body"
|
|
569
|
+
guard_gql 'all(.[]; type == "object" and (.count | cnt) and ((.dimensions | type) == "object") and (.dimensions.datetimeHour | type == "string" and test("\\A[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:00:00Z\\z")) and (.dimensions.coloCode == null or (.dimensions.coloCode | type) == "string") and ((.avg | type) == "object") and (.avg.originResponseDurationMs | dur) and ((.quantiles | type) == "object") and (.quantiles.originResponseDurationMsP50 | dur) and (.quantiles.originResponseDurationMsP90 | dur))'
|
|
570
|
+
QLIMIT=10000
|
|
571
|
+
project '.data.viewer.zones[0].httpRequestsAdaptiveGroups as $g | {subcommand: "analytics-health-colo", window_hours: $hours, rows: ($g | length), truncated: ($qlimit <= ($g | length)), note: "counts are sampled estimates (adaptive sampling); durations are origin response time per Cloudflare colo for the host app.soleur.ai and the path /health only, with no requestSource filter", series: ([$g[] | {hour: .dimensions.datetimeHour, colo: (.dimensions.coloCode | colo), count: .count, avg_ms: (.avg.originResponseDurationMs | r1), p50_ms: (.quantiles.originResponseDurationMsP50 | r1), p90_ms: (.quantiles.originResponseDurationMsP90 | r1)}] | sort_by([.hour, .colo]))}' "$(printf '"zone":"%s","window_end":"%s"' "$CF_ZONE_ID" "$WIN_END")"
|
|
572
|
+
}
|
|
470
573
|
|
|
471
|
-
# --- argument handling: one argument (the analytics subcommands take hours as a second,
|
|
574
|
+
# --- argument handling: one argument (the analytics subcommands take hours as a second, and analytics-health-colo an end offset as a
|
|
575
|
+
# third, validated by need_hours / need_colo_args in their arm) ---
|
|
472
576
|
if [ "$#" -eq 1 ] && [ "$1" = "--list" ]; then
|
|
473
577
|
printf '%s\n' "${SUBCOMMANDS[@]}"
|
|
474
578
|
exit 0
|
|
475
579
|
fi
|
|
476
580
|
case "${1:-}" in
|
|
477
|
-
analytics-health | analytics-edge-errors) : ;;
|
|
581
|
+
analytics-health | analytics-edge-errors | analytics-health-colo) : ;;
|
|
478
582
|
*)
|
|
479
583
|
if [ "$#" -ne 1 ]; then
|
|
480
584
|
die 64 "usage: cloudflare-readonly.sh <subcommand> | --list (refused: missing or extra argument)"
|
|
@@ -491,6 +595,7 @@ case "$SUB" in
|
|
|
491
595
|
change-history) TOKVAR=CF_API_TOKEN_AUDIT; load_credential account; sub_change_history ;;
|
|
492
596
|
analytics-health) need_hours "$@"; TOKVAR=CF_API_TOKEN_ANALYTICS_READ; load_credential zone; sub_analytics_health ;;
|
|
493
597
|
analytics-edge-errors) need_hours "$@"; TOKVAR=CF_API_TOKEN_ANALYTICS_READ; load_credential zone; sub_analytics_edge_errors ;;
|
|
598
|
+
analytics-health-colo) need_colo_args "$@"; TOKVAR=CF_API_TOKEN_ANALYTICS_READ; load_credential zone; sub_analytics_health_colo ;;
|
|
494
599
|
*) die 64 "refused: unknown subcommand" ;;
|
|
495
600
|
esac
|
|
496
601
|
exit 0
|