@cbartens/bkit 5.2.2 → 5.2.4
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/.bkit/README.md +4 -2
- package/.bkit/core/.agents/context.md +2 -2
- package/.bkit/core/.agents/plugins/bkit/hooks/bkit-guardrails.cjs +7 -1
- package/.bkit/core/.bkit/README.md +3 -1
- package/.bkit/core/.bkit/comparison.md +114 -45
- package/.bkit/core/.bkit/install.md +6 -6
- package/.bkit/core/.bkit/jsonl.md +3 -3
- package/.bkit/core/.bkit/prompts.md +6 -5
- package/.bkit/core/.bkit/providers.md +5 -4
- package/.bkit/core/.bkit/templates.md +30 -11
- package/.bkit/core/.bkit/workflows.md +14 -7
- package/.bkit/core/.codex/hooks/bkit-guardrails.cjs +5 -1
- package/.bkit/core/.cursor/hooks/bkit-guardrails.cjs +8 -2
- package/.bkit/core/docs/templates/bkit-audit-accessibility.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-adoption.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-agents.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-aio-seo.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-analytics.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-annotations.md +15 -4
- package/.bkit/core/docs/templates/bkit-audit-app-performance.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-app-store.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-architecture.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-ci-performance.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-config.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-cost.md +14 -3
- package/.bkit/core/docs/templates/bkit-audit-coverage.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-database.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-dead-code.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-deferrals.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-dependencies.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-documentation.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-duplication.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-failures.md +14 -3
- package/.bkit/core/docs/templates/bkit-audit-flakes.md +15 -4
- package/.bkit/core/docs/templates/bkit-audit-gates.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-issues.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-llm.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-logs.md +25 -13
- package/.bkit/core/docs/templates/bkit-audit-models.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-privacy.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-prompts.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-red-team.md +14 -3
- package/.bkit/core/docs/templates/bkit-audit-reliability.md +14 -3
- package/.bkit/core/docs/templates/bkit-audit-repo.md +14 -3
- package/.bkit/core/docs/templates/bkit-audit-security.md +15 -4
- package/.bkit/core/docs/templates/bkit-audit-slop.md +13 -2
- package/.bkit/core/docs/templates/bkit-audit-testing.md +14 -3
- package/.bkit/core/docs/templates/bkit-audit-usability.md +13 -2
- package/.bkit/core/docs/templates/bkit-plan.md +1 -1
- package/.bkit/core/engine/checks/tips/catalogue.ts +10 -0
- package/.bkit/core/engine/commands/install/check.ts +3 -11
- package/.bkit/core/engine/commands/install/doctor.ts +2 -3
- package/.bkit/core/engine/commands/install/uninstall.ts +60 -44
- package/.bkit/core/engine/commands/install/upgrade.ts +13 -11
- package/.bkit/core/engine/commands/workflow/branches.ts +72 -9
- package/.bkit/core/engine/commands/workflow/repo.ts +16 -2
- package/.bkit/core/engine/commands/workflow/workflows.ts +4 -3
- package/.bkit/core/engine/install/hosts.ts +14 -4
- package/.bkit/core/engine/ledgers/telemetry.ts +3 -4
- package/.bkit/core/engine/shared/bkit-latest.ts +164 -0
- package/.bkit/core/engine/shared/timeouts.ts +6 -0
- package/.bkit/core/hooks/guardrails-read.js +4 -9
- package/.bkit/core/hooks/guardrails-tiers.js +312 -28
- package/.bkit/core/prompts/bkit-audit-generate.md +21 -5
- package/.bkit/core/workflows/bkit-build.md +1 -1
- package/.bkit/core/workflows/bkit-debug.md +1 -1
- package/.bkit/core/workflows/bkit-design.md +1 -1
- package/.bkit/core/workflows/bkit-plan.md +1 -1
- package/.bkit/core/workflows/bkit-ship.md +1 -1
- package/.bkit/shared/.claude/settings.json +19 -0
- package/.bkit/shared/.opencode/opencode.json +21 -1
- package/.bkit/shared/docs/deployments.md +14 -0
- package/.bkit/templates/.github/workflows/bkit-ci.yml +9 -0
- package/.bkit/templates/.husky/pre-push +7 -0
- package/.bkit/templates/context/bkit-cloudrun.md +28 -19
- package/.bkit/templates/context/bkit-expo.md +30 -13
- package/.bkit/templates/context/bkit-inngest.md +54 -17
- package/.bkit/templates/context/bkit-resend.md +36 -8
- package/.bkit/templates/context/bkit-sentry.md +11 -4
- package/.bkit/templates/context/bkit-stripe.md +39 -22
- package/.bkit/templates/context/bkit-supabase.md +45 -20
- package/.bkit/templates/context/bkit-vercel.md +45 -16
- package/.bkit/templates/scripts/ci/accepted-advisories.json +7 -0
- package/.bkit/templates/scripts/ci/check-dependency-audit.mjs +200 -0
- package/.bkit/templates/scripts/ci/check-dependency-audit.test.mjs +127 -0
- package/.bkit/templates/scripts/cleanup/bkit-tmp-prune.mjs +115 -0
- package/CHANGELOG.md +56 -0
- package/README.md +76 -20
- package/dist/checks/tips/catalogue.js +9 -0
- package/dist/commands/install/check.js +3 -15
- package/dist/commands/install/doctor.js +2 -1
- package/dist/commands/install/uninstall.js +52 -45
- package/dist/commands/install/upgrade.js +13 -11
- package/dist/commands/workflow/branches.js +64 -10
- package/dist/commands/workflow/repo.js +14 -2
- package/dist/commands/workflow/workflows.js +4 -3
- package/dist/install/hosts.js +11 -4
- package/dist/shared/bkit-latest.js +150 -0
- package/dist/shared/timeouts.js +6 -0
- package/package.json +1 -1
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
Fits: services running on Google Cloud Run. `context=runtime`: `gcloud logging read` on `cloud_run_revision` — `severity>=ERROR` plus the platform's `Memory limit … exceeded` lines. Those are container kills (503 / SIGKILL exit 137) the app itself never logs and an error tracker never sees: the container dies before its SDK flushes.
|
|
7
7
|
|
|
8
|
-
- Secret: none locally after `gcloud auth login`. Headless (cloud agents): `GCP_CLIENT_EMAIL` + `GCP_PRIVATE_KEY` of a service account with `roles/logging.viewer`; the block activates it only when
|
|
9
|
-
- Non-secret: `GCP_PROJECT_ID` — uncomment the line in the block so cloud agents inherit it. Separate dev / prod projects: use the id whose logs you want. Optional `GCP_SERVICE` narrows to one service; `SINCE`, `GCP_N`.
|
|
8
|
+
- Secret: none locally after `gcloud auth login`. Headless (cloud agents): `GCP_CLIENT_EMAIL` + `GCP_PRIVATE_KEY` of a service account with `roles/logging.viewer`; the block activates it only when the gcloud login cannot mint a token (none, or a stale one), in a throwaway gcloud config it deletes on exit, so your own gcloud config is never switched.
|
|
9
|
+
- Non-secret: `GCP_PROJECT_ID` — uncomment the line in the block so cloud agents inherit it. Separate dev / prod projects: use the id whose logs you want. Optional `GCP_SERVICE` narrows to one service; `SINCE`, `GCP_N`, `GCP_FILTER`.
|
|
10
10
|
- CLI: `gcloud`; the provision block installs it in cloud (GitHub-hosted Ubuntu runners already ship it). Uses `node` to build the key file.
|
|
11
11
|
|
|
12
12
|
Copy the blocks below into `.agents/context.md`, below `<!-- bkit:end -->`.
|
|
@@ -21,20 +21,23 @@ Copy the blocks below into `.agents/context.md`, below `<!-- bkit:end -->`.
|
|
|
21
21
|
# Optional GCP_SERVICE narrows to one service; unset = every cloud_run_revision in the project:
|
|
22
22
|
# GCP_PROJECT_ID="your-gcp-project-id"
|
|
23
23
|
# GCP_SERVICE="your-service-name"
|
|
24
|
-
# Headless auth:
|
|
25
|
-
#
|
|
26
|
-
#
|
|
27
|
-
#
|
|
24
|
+
# Headless auth: active gcloud login used ONLY when `print-access-token` works; a stale user
|
|
25
|
+
# login lists ACTIVE yet fails every read with reauth. No working login → service account from
|
|
26
|
+
# GCP_CLIENT_EMAIL + GCP_PRIVATE_KEY (`\n`-escaped PEM un-escaped) in a throwaway CLOUDSDK_CONFIG;
|
|
27
|
+
# operator's gcloud config untouched. Locally: `gcloud auth login` once, skip both. Failed
|
|
28
|
+
# `gcloud logging read` → `skipped`. PII-safe: scalar / id fields only, never the raw payload.
|
|
29
|
+
# Customise: GCP_SERVICE; SINCE freshness; GCP_N; GCP_FILTER (add textPayload:"<prefix>" for app stdout). Positive control (suggested): run once with GCP_FILTER widened to a known log line; nothing back = reader broken, not clean.
|
|
28
30
|
command -v gcloud >/dev/null 2>&1 \
|
|
29
31
|
|| { echo "[context-fetch:cloudrun] skipped — gcloud CLI missing" >&2; exit 0; }
|
|
30
32
|
[ -n "${GCP_PROJECT_ID:-}" ] \
|
|
31
33
|
|| { echo "[context-fetch:cloudrun] skipped — GCP_PROJECT_ID unset" >&2; exit 0; }
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
GCLOUD_TMP="$(mktemp -d)"; chmod 700 "$GCLOUD_TMP"
|
|
35
|
+
trap 'rm -rf "$GCLOUD_TMP"' EXIT # live credential on the SA path; NEVER print it
|
|
36
|
+
if ! gcloud auth print-access-token >/dev/null 2>&1; then
|
|
34
37
|
[ -n "${GCP_CLIENT_EMAIL:-}" ] && [ -n "${GCP_PRIVATE_KEY:-}" ] \
|
|
35
|
-
|| { echo "[context-fetch:cloudrun] skipped — no
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
|| { echo "[context-fetch:cloudrun] skipped — no gcloud login that can mint a token (run \`gcloud auth login\`) and GCP_CLIENT_EMAIL/GCP_PRIVATE_KEY unset" >&2; exit 0; }
|
|
39
|
+
export CLOUDSDK_CONFIG="$GCLOUD_TMP/config"
|
|
40
|
+
KEYFILE="$GCLOUD_TMP/sa.json"
|
|
38
41
|
GCP_CLIENT_EMAIL="$GCP_CLIENT_EMAIL" GCP_PRIVATE_KEY="$GCP_PRIVATE_KEY" \
|
|
39
42
|
GCP_PROJECT_ID="$GCP_PROJECT_ID" KEYFILE="$KEYFILE" node -e '
|
|
40
43
|
const crypto=require("crypto"), fs=require("fs");
|
|
@@ -49,17 +52,23 @@ if [ -z "$(gcloud auth list --filter=status:ACTIVE --format='value(account)' 2>/
|
|
|
49
52
|
gcloud auth activate-service-account --key-file="$KEYFILE" --project="$GCP_PROJECT_ID" >/dev/null 2>&1 \
|
|
50
53
|
|| { echo "[context-fetch:cloudrun] skipped — gcloud SA activation failed" >&2; exit 0; }
|
|
51
54
|
fi
|
|
52
|
-
|
|
53
|
-
[ -n "${GCP_SERVICE:-}" ] &&
|
|
54
|
-
|
|
55
|
+
GCP_FILTER="${GCP_FILTER:-resource.type=\"cloud_run_revision\" AND (severity>=ERROR OR textPayload:\"Memory limit\")}"
|
|
56
|
+
[ -n "${GCP_SERVICE:-}" ] && GCP_FILTER="${GCP_FILTER} AND resource.labels.service_name=\"${GCP_SERVICE}\""
|
|
57
|
+
GCLOUD_OUT="$GCLOUD_TMP/entries.json"
|
|
58
|
+
gcloud logging read "$GCP_FILTER" \
|
|
55
59
|
--project="$GCP_PROJECT_ID" \
|
|
56
60
|
--freshness="${SINCE:-4h}" \
|
|
57
61
|
--limit="${GCP_N:-50}" \
|
|
58
|
-
--format=json
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
--format=json > "$GCLOUD_OUT" 2>/dev/null
|
|
63
|
+
GCLOUD_RC=$?
|
|
64
|
+
[ "$GCLOUD_RC" -eq 0 ] && jq -e 'type == "array"' "$GCLOUD_OUT" >/dev/null 2>&1 \
|
|
65
|
+
|| { echo "[context-fetch:cloudrun] skipped — gcloud logging read exited $GCLOUD_RC on $GCP_PROJECT_ID (reauth needed, identity lacks roles/logging.viewer, or API unreachable)" >&2; exit 0; }
|
|
66
|
+
printf '===== cloud run %s%s, freshness %s — %s entr(ies), newest %s max =====\n' \
|
|
67
|
+
"$GCP_PROJECT_ID" "${GCP_SERVICE:+ service $GCP_SERVICE}" "${SINCE:-4h}" "$(jq length "$GCLOUD_OUT")" "${GCP_N:-50}"
|
|
68
|
+
jq '[.[] | {timestamp, severity,
|
|
69
|
+
service: .resource.labels.service_name,
|
|
70
|
+
revision: .resource.labels.revision_name,
|
|
71
|
+
message: (.jsonPayload.message // .textPayload)}]' "$GCLOUD_OUT"
|
|
63
72
|
```
|
|
64
73
|
|
|
65
74
|
<!-- context-fetch:end -->
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
Fits: React Native / Expo apps on EAS. `context=runtime` (`expo` block): recent EAS Build status (id, platform, status, profile, commit, error), then the error-level lines of the latest errored builds' logs. `context=e2e` (`expo-workflows` block): for the latest failed EAS Workflow runs (`eas workflow:run`, Maestro) — job status and errors, step-log tails, the per-flow exception for every flow and retry (EAS GraphQL), JUnit, failure screenshot URLs, and from `artifacts.tar.gz` the failing Maestro commands, the view-hierarchy dump list, per-attempt JUnit, the XCUITest runner's own errors and the app's JS console. EAS drains build failures and Workflow runs nowhere else — no host log, no error tracker — so this is the only place they surface.
|
|
7
7
|
|
|
8
8
|
- Secret: `EXPO_TOKEN` (an EAS access token), in the app's env (e.g. `apps/mobile/.env.local`), not `.bkit/.env`.
|
|
9
|
-
- Non-secret: `EXPO_APP_DIR` (the EAS-linked app folder, default `apps/mobile`), both blocks; `expo`: `EAS_PLATFORM`, `EAS_PROFILE`, `EAS_N
|
|
9
|
+
- Non-secret: `EXPO_APP_DIR` (the EAS-linked app folder, default `apps/mobile`), both blocks; `expo`: `EAS_PLATFORM`, `EAS_PROFILE`, `EAS_N` (default and max 50, the CLI limit), `EAS_ERR_N`, `EAS_LOG_N`; `expo-workflows`: `EAS_WF_FILE`, `EAS_WF_N` and `EAS_WF_FAIL_N` (each at most 100, the CLI limit), `EAS_WF_ERR_N`, `EAS_JUNIT_N`.
|
|
10
10
|
- CLI: `eas` (`eas-cli`); each block's same-named provision block installs it in cloud, self-guarded, so copying both installs once. `expo` also uses `node` to decompress logs.
|
|
11
11
|
- Domains: `expo.dev` (both), `googleapis.com` (`expo`), `eascdn.net` (`expo-workflows`); each section carries its own `allowed-domains` block.
|
|
12
12
|
- `expo`: build logs are pre-signed, brotli-encoded storage URLs valid ~15 min; macOS curl has no brotli, so the block decompresses with Node zlib and filters the JSON lines with `jq`.
|
|
@@ -24,7 +24,8 @@ Copy the blocks below into `.agents/context.md`, below `<!-- bkit:end -->`. The
|
|
|
24
24
|
# Expo EAS native build status + errored-build logs (read-only).
|
|
25
25
|
# EXPO_TOKEN is an app/stack cred (it builds and ships the native apps) — app env, not .bkit/.env.
|
|
26
26
|
# Run `eas` from the EAS-linked app folder: from anywhere else it writes a stub app.json there.
|
|
27
|
-
#
|
|
27
|
+
# Failed `eas build:list` (bad token, EAS_N > 50, network) → `skipped`.
|
|
28
|
+
# Customise: EXPO_APP_DIR; EAS_PLATFORM (android|ios|all); EAS_PROFILE (build profile, e.g. preview / production); EAS_N (builds listed, default and max 50); EAS_ERR_N; EAS_LOG_N (log lines per build); the log-line filter. Positive control (suggested): newest build on expo.dev must be the first line; missing = reader broken, not clean.
|
|
28
29
|
EXPO_APP_DIR="${EXPO_APP_DIR:-apps/mobile}"
|
|
29
30
|
command -v eas >/dev/null && [ -n "${EXPO_TOKEN:-}" ] \
|
|
30
31
|
|| { echo "[context-fetch:expo] skipped — eas CLI / EXPO_TOKEN missing" >&2; exit 0; }
|
|
@@ -32,11 +33,14 @@ grep -qs 'projectId' "$EXPO_APP_DIR"/app.json "$EXPO_APP_DIR"/app.config.* \
|
|
|
32
33
|
|| { echo "[context-fetch:expo] skipped — $EXPO_APP_DIR not EAS-linked (run \`eas init\` there)" >&2; exit 0; }
|
|
33
34
|
cd "$EXPO_APP_DIR" || exit 0
|
|
34
35
|
# 1) Recent build status. --status new|in-queue|in-progress|pending-cancel|errored|finished|canceled.
|
|
35
|
-
eas build:list \
|
|
36
|
+
EAS_BUILDS=$(eas build:list \
|
|
36
37
|
--platform "${EAS_PLATFORM:-all}" \
|
|
37
38
|
${EAS_PROFILE:+--build-profile "$EAS_PROFILE"} \
|
|
38
|
-
--limit "${EAS_N:-
|
|
39
|
-
--json --non-interactive \
|
|
39
|
+
--limit "${EAS_N:-50}" \
|
|
40
|
+
--json --non-interactive 2>/dev/null) && printf '%s' "$EAS_BUILDS" | jq -e 'type == "array"' >/dev/null 2>&1 \
|
|
41
|
+
|| { echo "[context-fetch:expo] skipped — eas build:list failed (bad EXPO_TOKEN, EAS_N above 50, or expo.dev unreachable)" >&2; exit 0; }
|
|
42
|
+
printf '===== eas builds, newest %s (%s) — %s build(s) =====\n' "${EAS_N:-50}" "${EAS_PLATFORM:-all}" "$(printf '%s' "$EAS_BUILDS" | jq length)"
|
|
43
|
+
printf '%s' "$EAS_BUILDS" \
|
|
40
44
|
| jq -c '.[] | {id, platform, status, createdAt, buildProfile, gitCommitHash, error}' # gitCommitHash stitches to the CI run
|
|
41
45
|
# 2) LOGS for recent failures. No `eas build:logs`; build:view exposes `logFiles`: pre-signed
|
|
42
46
|
# URLs (signature in the query string, no auth header), valid ~900s, BROTLI-encoded JSON lines.
|
|
@@ -78,7 +82,8 @@ googleapis.com
|
|
|
78
82
|
```bash
|
|
79
83
|
# EAS WORKFLOW runs — the native e2e (Maestro) lane (read-only). SEPARATE from the expo block:
|
|
80
84
|
# that one covers `eas build`, this one covers `eas workflow:run`.
|
|
81
|
-
#
|
|
85
|
+
# Failed `eas workflow:runs` (bad token, network) → `skipped`.
|
|
86
|
+
# Customise: EXPO_APP_DIR; EAS_WF_FILE (e2e workflow file; unset = all); EAS_WF_N (all-status runs listed, max 100); EAS_WF_FAIL_N (FAILURE runs listed, max 100; reaches further back than the all-status list); EAS_WF_ERR_N (failed runs read in detail); EAS_JUNIT_N (lines per JUnit file); which artifacts to inline; the log greps. Positive control (suggested): a known failed run must appear in the FAILURE list; missing = reader broken, not clean.
|
|
82
87
|
EXPO_APP_DIR="${EXPO_APP_DIR:-apps/mobile}"
|
|
83
88
|
command -v eas >/dev/null && [ -n "${EXPO_TOKEN:-}" ] \
|
|
84
89
|
|| { echo "[context-fetch:expo-workflows] skipped — eas CLI / EXPO_TOKEN missing" >&2; exit 0; }
|
|
@@ -89,17 +94,29 @@ WORK=$(mktemp -d)
|
|
|
89
94
|
trap 'rm -rf "$WORK"' EXIT
|
|
90
95
|
# 1) Recent workflow runs, newest first. `workflow:runs` does NOT accept --non-interactive
|
|
91
96
|
# (unlike its sibling commands): passing it errors out with no output, which reads exactly
|
|
92
|
-
# like "no runs found". Its flags are only --json --limit --status --workflow
|
|
93
|
-
|
|
94
|
-
|
|
97
|
+
# like "no runs found". Its flags are only --json --limit --status --workflow; --limit above
|
|
98
|
+
# 100 errors. The date field is `startedAt` (there is no `createdAt`).
|
|
99
|
+
WF_N="${EAS_WF_N:-10}"; [ "$WF_N" -le 100 ] || WF_N=100
|
|
100
|
+
WF_FAIL_N="${EAS_WF_FAIL_N:-100}"; [ "$WF_FAIL_N" -le 100 ] || WF_FAIL_N=100
|
|
101
|
+
eas workflow:runs --json ${EAS_WF_FILE:+--workflow "$EAS_WF_FILE"} --limit "$WF_N" > "$WORK/runs.json" 2>/dev/null \
|
|
102
|
+
&& jq -e 'type == "array"' "$WORK/runs.json" >/dev/null 2>&1 \
|
|
103
|
+
|| { echo "[context-fetch:expo-workflows] skipped — eas workflow:runs failed (bad EXPO_TOKEN or expo.dev unreachable)" >&2; exit 0; }
|
|
104
|
+
eas workflow:runs --json ${EAS_WF_FILE:+--workflow "$EAS_WF_FILE"} --status FAILURE --limit "$WF_FAIL_N" > "$WORK/failures.json" 2>/dev/null \
|
|
105
|
+
&& jq -e 'type == "array"' "$WORK/failures.json" >/dev/null 2>&1 \
|
|
106
|
+
|| { echo "[context-fetch:expo-workflows] skipped — eas workflow:runs --status FAILURE failed" >&2; exit 0; }
|
|
107
|
+
printf '===== eas workflow runs, newest %s — %s run(s) =====\n' "$WF_N" "$(jq length "$WORK/runs.json")"
|
|
108
|
+
jq -c '.[] | {id, status, workflowName, gitCommitHash, startedAt}' "$WORK/runs.json"
|
|
109
|
+
printf '===== FAILURE runs, newest %s — %s run(s) =====\n' "$WF_FAIL_N" "$(jq length "$WORK/failures.json")"
|
|
110
|
+
jq -c '.[] | {id, workflowName, gitCommitHash, startedAt}' "$WORK/failures.json"
|
|
95
111
|
# 2) Per-run detail. `workflow:status` is the only command that yields BOTH job ids and artifact URLs.
|
|
96
|
-
for run in $(
|
|
97
|
-
--limit "${EAS_WF_ERR_N:-2}" 2>/dev/null | jq -r '.[]?.id'); do
|
|
112
|
+
for run in $(jq -r --argjson n "${EAS_WF_ERR_N:-2}" '.[:$n][].id' "$WORK/failures.json"); do
|
|
98
113
|
echo "===== failed workflow run $run ====="
|
|
99
114
|
STATUS="$WORK/status-$run.json"
|
|
100
|
-
# `workflow:status`
|
|
115
|
+
# `workflow:status` prints its JSON, then exits 11 FAILED / 12 canceled: test the JSON, NEVER
|
|
116
|
+
# the exit code; an exit-code guard skips every failed run's detail.
|
|
101
117
|
eas workflow:status "$run" --json --non-interactive > "$STATUS" 2>/dev/null
|
|
102
|
-
|
|
118
|
+
jq -e '.id' "$STATUS" >/dev/null 2>&1 \
|
|
119
|
+
|| { echo "===== run $run: workflow:status returned no JSON — detail NOT read ====="; continue; }
|
|
103
120
|
jq -r '.jobs[]? | "job \(.id) key=\(.key // "?") \(.status)", (.turtleJobRun.errors[]? | " \(.errorCode): \(.message)")' "$STATUS"
|
|
104
121
|
# 2a) Step logs. `workflow:logs` takes the JOB id, not the run id (the run id returns "No
|
|
105
122
|
# workflow job found"). --all-steps is required or it prompts for a step and hangs headless.
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
# Inngest — failed function runs
|
|
5
5
|
|
|
6
|
-
Fits: apps running durable functions on Inngest Cloud. `context=runtime`: `inngest/function.failed` system events
|
|
6
|
+
Fits: apps running durable functions on Inngest Cloud. `context=runtime`: `inngest/function.failed` system events across a time window (default last 4 h), paged — a count per day and function, then the newest events with function id, run id, error class, and the opaque `*Id` keys of the triggering event. Never the error message: it can carry secrets.
|
|
7
7
|
|
|
8
8
|
- Secret: `INNGEST_SIGNING_KEY` — reuse the app's existing key. It is environment-scoped (branch environments and production have separate keys): use the key whose runs you want.
|
|
9
|
-
- Non-secret: `
|
|
9
|
+
- Non-secret: `SINCE_ISO` / `UNTIL_ISO` (window, default last 4 h; the API alone looks back only 1 h), `INNGEST_ENV` (branch environment name; required with a branch key, ignored otherwise), `INNGEST_N` (newest events listed, default 25), `INNGEST_MAX_PAGES` (pages of up to 51 events, default 40).
|
|
10
10
|
- CLI: none (`curl` + `jq`), no provision block.
|
|
11
11
|
- PII: the projection keeps only keys ending in `Id` from the triggering event's data. Keep free text and personal data out of `*Id` keys in your event payloads, or narrow the projection.
|
|
12
12
|
|
|
@@ -17,23 +17,60 @@ Copy the blocks below into `.agents/context.md`, below `<!-- bkit:end -->`.
|
|
|
17
17
|
```bash
|
|
18
18
|
# Inngest Cloud — failed durable-function runs, exhausted retries (read-only).
|
|
19
19
|
# INNGEST_SIGNING_KEY is ENV-SCOPED (branch env vs production) — use the key for the env whose
|
|
20
|
-
# runs you want.
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
#
|
|
20
|
+
# runs you want. Branch key (`signkey-branch-…`) reads the env in header `x-inngest-env`; without
|
|
21
|
+
# it the API reads env `branch` and returns nothing → block refuses a branch key with INNGEST_ENV
|
|
22
|
+
# unset. Lists `inngest/function.failed` events from received_after, paged by
|
|
23
|
+
# cursor=<last internal_id>; pages stop at 51 events whatever `limit` says; API default window 1 h.
|
|
24
|
+
# Non-200 first page → `skipped`; failed later page or page cap → TRUNCATED line.
|
|
25
|
+
# NEVER prints `.data.error.message` / `.stack`: error strings can carry secrets from request
|
|
26
|
+
# headers or URLs. Prints function id, run id, time, error class (`.data.error.name`, ONLY when
|
|
27
|
+
# class-shaped), ONLY /Id$/ keys from the triggering event.
|
|
28
|
+
# Customise: INNGEST_ENV (branch environment name, with a branch key); SINCE_ISO / UNTIL_ISO (window, default last 4 h); INNGEST_N (newest events listed); INNGEST_MAX_PAGES (x 51 events); the ids projection (narrow it if any *Id key in your events carries PII). Positive control (suggested): run once over a window holding a run the dashboard shows Failed; nothing back = reader broken, not clean.
|
|
24
29
|
[ -n "${INNGEST_SIGNING_KEY:-}" ] \
|
|
25
30
|
|| { echo "[context-fetch:inngest] skipped — INNGEST_SIGNING_KEY unset" >&2; exit 0; }
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
case "$INNGEST_SIGNING_KEY" in
|
|
32
|
+
signkey-branch-*) [ -n "${INNGEST_ENV:-}" ] \
|
|
33
|
+
|| { echo "[context-fetch:inngest] skipped — branch signing key with INNGEST_ENV unset (it would read the empty env 'branch')" >&2; exit 0; } ;;
|
|
34
|
+
*) INNGEST_ENV="" ;;
|
|
35
|
+
esac
|
|
36
|
+
INNGEST_START="${SINCE_ISO:-$(date -u -v-4H +%FT%TZ 2>/dev/null || date -u -d '4 hours ago' +%FT%TZ)}"
|
|
37
|
+
INNGEST_RESP=$(mktemp); INNGEST_ALL=$(mktemp)
|
|
38
|
+
trap 'rm -f "$INNGEST_RESP" "$INNGEST_ALL"' EXIT
|
|
39
|
+
INNGEST_CURSOR=""; INNGEST_PAGES=0; INNGEST_NOTE=""
|
|
40
|
+
while :; do
|
|
41
|
+
INNGEST_PAGES=$((INNGEST_PAGES + 1))
|
|
42
|
+
INNGEST_CODE=$(curl -sG -o "$INNGEST_RESP" -w '%{http_code}' "https://api.inngest.com/v1/events" \
|
|
43
|
+
--data-urlencode "name=inngest/function.failed" \
|
|
44
|
+
--data-urlencode "limit=100" \
|
|
45
|
+
--data-urlencode "received_after=${INNGEST_START}" \
|
|
46
|
+
${UNTIL_ISO:+--data-urlencode "received_before=${UNTIL_ISO}"} \
|
|
47
|
+
${INNGEST_CURSOR:+--data-urlencode "cursor=${INNGEST_CURSOR}"} \
|
|
48
|
+
${INNGEST_ENV:+-H "x-inngest-env: ${INNGEST_ENV}"} \
|
|
49
|
+
-H "Authorization: Bearer ${INNGEST_SIGNING_KEY}")
|
|
50
|
+
if [ "$INNGEST_CODE" != "200" ] || ! jq -e '.data | type == "array"' "$INNGEST_RESP" >/dev/null 2>&1; then
|
|
51
|
+
[ "$INNGEST_PAGES" -gt 1 ] \
|
|
52
|
+
|| { echo "[context-fetch:inngest] skipped — api.inngest.com HTTP ${INNGEST_CODE:-000} (401 = bad or wrong-env key, 000 = unreachable)" >&2; exit 0; }
|
|
53
|
+
INNGEST_NOTE="page $INNGEST_PAGES answered HTTP ${INNGEST_CODE:-000}; older events NOT read"; break
|
|
54
|
+
fi
|
|
55
|
+
[ "$(jq '.data | length' "$INNGEST_RESP")" -gt 0 ] || break
|
|
56
|
+
jq -c '.data[]
|
|
57
|
+
| {internal_id, time: (.ts / 1000 | floor | todate), function_id: .data.function_id, run_id: .data.run_id,
|
|
58
|
+
error_class: ((.data.error | if type == "object" then (.name // "") else "" end) as $n
|
|
59
|
+
| if ($n | test("^[A-Za-z][A-Za-z0-9 _.-]{0,60}$")) then $n elif $n == "" then null else "(unprintable)" end),
|
|
60
|
+
ids: (.data.event.data // {} | with_entries(select(.key | test("Id$"))))}' "$INNGEST_RESP" >> "$INNGEST_ALL"
|
|
61
|
+
INNGEST_CURSOR=$(jq -r '.data[-1].internal_id' "$INNGEST_RESP")
|
|
62
|
+
[ "$INNGEST_PAGES" -lt "${INNGEST_MAX_PAGES:-40}" ] \
|
|
63
|
+
|| { INNGEST_NOTE="stopped at INNGEST_MAX_PAGES=${INNGEST_MAX_PAGES:-40}; events before $(jq -r '.data[-1].ts / 1000 | floor | todate' "$INNGEST_RESP") NOT read"; break; }
|
|
64
|
+
done
|
|
65
|
+
INNGEST_EVENTS=$(jq -sc 'unique_by(.internal_id) | sort_by(.time) | reverse' "$INNGEST_ALL")
|
|
66
|
+
printf '===== inngest function.failed%s, %s → %s — %s event(s), %s page(s) =====\n' \
|
|
67
|
+
"${INNGEST_ENV:+ (env $INNGEST_ENV)}" "$INNGEST_START" "${UNTIL_ISO:-now}" \
|
|
68
|
+
"$(printf '%s' "$INNGEST_EVENTS" | jq 'length')" "$INNGEST_PAGES"
|
|
69
|
+
[ -z "$INNGEST_NOTE" ] || { printf '===== TRUNCATED: %s =====\n' "$INNGEST_NOTE"; echo "[context-fetch:inngest] truncated — $INNGEST_NOTE" >&2; }
|
|
70
|
+
echo "===== count per day and function ====="
|
|
71
|
+
printf '%s' "$INNGEST_EVENTS" | jq -r 'group_by([.time[0:10], .function_id]) | .[] | "\(length)\t\(.[0].time[0:10])\t\(.[0].function_id)"'
|
|
72
|
+
echo "===== newest ${INNGEST_N:-25} ====="
|
|
73
|
+
printf '%s' "$INNGEST_EVENTS" | jq -c --argjson n "${INNGEST_N:-25}" '.[:$n][] | del(.internal_id)'
|
|
37
74
|
```
|
|
38
75
|
|
|
39
76
|
<!-- context-fetch:end -->
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
Fits: apps sending email through Resend. `context=runtime`: recent sends whose last delivery event is a bounce, complaint, failure or delay (id, last_event, created_at only — never to, from or subject).
|
|
7
7
|
|
|
8
8
|
- Secret: `RESEND_API_KEY` (`re_…`) — reuse the app's existing key.
|
|
9
|
-
- Non-secret: `
|
|
9
|
+
- Non-secret: `SINCE_ISO` (window start, default 24 h ago), `RESEND_MAX_PAGES` (pages of 100 sends, default 30).
|
|
10
10
|
- CLI: none (`curl` + `jq`), no provision block.
|
|
11
11
|
|
|
12
12
|
Copy the blocks below into `.agents/context.md`, below `<!-- bkit:end -->`.
|
|
@@ -15,16 +15,44 @@ Copy the blocks below into `.agents/context.md`, below `<!-- bkit:end -->`.
|
|
|
15
15
|
|
|
16
16
|
```bash
|
|
17
17
|
# Resend email delivery log — bounces / complaints / delays / failures (read-only GET).
|
|
18
|
-
# GET /emails lists
|
|
18
|
+
# GET /emails lists sends newest first; `last_event` = delivery status. One page of 100 can cover
|
|
19
|
+
# under a day → pages with after=<last id> until a send predates the window. Non-200 page →
|
|
20
|
+
# `skipped`; page cap → TRUNCATED line.
|
|
19
21
|
# PII-safe: to / from / subject are never surfaced — only id / last_event / created_at.
|
|
20
|
-
# Customise:
|
|
22
|
+
# Customise: SINCE_ISO (window start, default 24 h ago; retention is 30 days); RESEND_MAX_PAGES (x 100 sends); the last_event filter. Positive control (suggested): run once over a window holding a known bounce (e.g. to Resend's bounce test address); nothing back = reader broken, not clean.
|
|
21
23
|
[ -n "${RESEND_API_KEY:-}" ] \
|
|
22
24
|
|| { echo "[context-fetch:resend] skipped — RESEND_API_KEY unset" >&2; exit 0; }
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
RESEND_FROM=$(jq -rn --arg t "${SINCE_ISO:-}" --argjson d "$(( $(date -u +%s) - 86400 ))" 'if $t == "" then $d else ($t | sub("\\.[0-9]+"; "") | fromdateiso8601) end' 2>/dev/null)
|
|
26
|
+
[ -n "$RESEND_FROM" ] \
|
|
27
|
+
|| { echo "[context-fetch:resend] skipped — SINCE_ISO not ISO-8601 (2026-01-31T00:00:00Z)" >&2; exit 0; }
|
|
28
|
+
RESEND_RESP=$(mktemp); RESEND_ALL=$(mktemp)
|
|
29
|
+
trap 'rm -f "$RESEND_RESP" "$RESEND_ALL"' EXIT
|
|
30
|
+
RESEND_AFTER=""; RESEND_PAGES=0; RESEND_NOTE=""
|
|
31
|
+
while :; do
|
|
32
|
+
RESEND_PAGES=$((RESEND_PAGES + 1))
|
|
33
|
+
RESEND_CODE=$(curl -s -o "$RESEND_RESP" -w '%{http_code}' \
|
|
34
|
+
"https://api.resend.com/emails?limit=100${RESEND_AFTER:+&after=${RESEND_AFTER}}" \
|
|
35
|
+
-H "Authorization: Bearer ${RESEND_API_KEY}")
|
|
36
|
+
[ "$RESEND_CODE" = "200" ] \
|
|
37
|
+
|| { echo "[context-fetch:resend] skipped — api.resend.com HTTP ${RESEND_CODE:-000} on page $RESEND_PAGES (400/401 = bad key, 429 = rate limit, 000 = unreachable)" >&2; exit 0; }
|
|
38
|
+
# created_at looks like "2026-01-31 02:50:14.901000+00"; epoch it for the window test.
|
|
39
|
+
jq -c --argjson from "$RESEND_FROM" '.data[]
|
|
40
|
+
| . + {epoch: (.created_at[0:19] | sub(" "; "T") + "Z" | fromdateiso8601)}
|
|
41
|
+
| select(.epoch >= $from)' "$RESEND_RESP" >> "$RESEND_ALL"
|
|
42
|
+
RESEND_OLDEST=$(jq -r '[.data[].created_at[0:19] | sub(" "; "T") + "Z" | fromdateiso8601] | min // 0' "$RESEND_RESP")
|
|
43
|
+
[ "$(jq -r '.has_more' "$RESEND_RESP")" = "true" ] && [ "$RESEND_OLDEST" -ge "$RESEND_FROM" ] || break
|
|
44
|
+
[ "$RESEND_PAGES" -lt "${RESEND_MAX_PAGES:-30}" ] \
|
|
45
|
+
|| { RESEND_NOTE="stopped at RESEND_MAX_PAGES=${RESEND_MAX_PAGES:-30}; sends before $(jq -rn --argjson s "$RESEND_OLDEST" '$s | todate') NOT read"; break; }
|
|
46
|
+
RESEND_AFTER=$(jq -r '.data[-1].id' "$RESEND_RESP")
|
|
47
|
+
sleep 0.6 # Resend allows ~2 requests/s
|
|
48
|
+
done
|
|
49
|
+
printf '===== resend outbound since %s — %s send(s), %s page(s) =====\n' \
|
|
50
|
+
"$(jq -rn --argjson s "$RESEND_FROM" '$s | todate')" "$(grep -c . "$RESEND_ALL")" "$RESEND_PAGES"
|
|
51
|
+
[ -z "$RESEND_NOTE" ] || { printf '===== TRUNCATED: %s =====\n' "$RESEND_NOTE"; echo "[context-fetch:resend] truncated — $RESEND_NOTE" >&2; }
|
|
52
|
+
echo "===== count by last_event ====="
|
|
53
|
+
jq -r '.last_event // "none"' "$RESEND_ALL" | sort | uniq -c | sort -rn
|
|
54
|
+
echo "===== bounce / complaint / failure / delay ====="
|
|
55
|
+
jq -c 'select((.last_event // "") | test("bounce|complain|fail|delay"; "i")) | {id, last_event, created_at}' "$RESEND_ALL"
|
|
28
56
|
```
|
|
29
57
|
|
|
30
58
|
<!-- context-fetch:end -->
|
|
@@ -24,14 +24,21 @@ Copy the blocks below into `.agents/context.md`, below `<!-- bkit:end -->`.
|
|
|
24
24
|
# SENTRY_HOST="de.sentry.io" # EU-region org; the global host 404s on its issue ids
|
|
25
25
|
# An empty array is NOT "no errors": a spent quota drops events silently — check the org's
|
|
26
26
|
# quota usage (or /api/0/organizations/{org}/stats_v2/) before concluding silence = clean.
|
|
27
|
-
#
|
|
27
|
+
# Non-200, or a non-array body → `skipped`, never `[]`.
|
|
28
|
+
# Detector configs (`organizations/<org>/detectors/`) carry uptime-check request headers, secrets
|
|
29
|
+
# included: strip with jq `del(.[].dataSources[]?.queryObj.headers)` before printing.
|
|
30
|
+
# Customise: SENTRY_SINCE window (1h / 24h / 7d); SENTRY_ENV (environment name, e.g. production; unset = all); SENTRY_N (<= 100); jq keys. Positive control (suggested): run once over a window holding an issue the UI shows unresolved and seen in it; nothing back = reader broken, not clean.
|
|
28
31
|
SENTRY_HOST="${SENTRY_HOST:-sentry.io}"
|
|
29
32
|
[ -n "${SENTRY_AUTH_TOKEN:-}" ] && [ -n "${SENTRY_ORG:-}" ] && [ -n "${SENTRY_PROJECT:-}" ] \
|
|
30
33
|
|| { echo "[context-fetch:sentry] skipped — SENTRY_AUTH_TOKEN / SENTRY_ORG / SENTRY_PROJECT unset" >&2; exit 0; }
|
|
31
|
-
|
|
34
|
+
SENTRY_RESP=$(mktemp)
|
|
35
|
+
trap 'rm -f "$SENTRY_RESP"' EXIT
|
|
36
|
+
SENTRY_CODE=$(curl -s -o "$SENTRY_RESP" -w '%{http_code}' \
|
|
32
37
|
-H "Authorization: Bearer ${SENTRY_AUTH_TOKEN}" \
|
|
33
|
-
"https://${SENTRY_HOST}/api/0/organizations/${SENTRY_ORG}/issues/?project=${SENTRY_PROJECT}&query=is%3Aunresolved&statsPeriod=${SENTRY_SINCE:-24h}&sort=date&limit=${SENTRY_N:-25}&collapse=stats${SENTRY_ENV:+&environment=${SENTRY_ENV}}"
|
|
34
|
-
|
|
38
|
+
"https://${SENTRY_HOST}/api/0/organizations/${SENTRY_ORG}/issues/?project=${SENTRY_PROJECT}&query=is%3Aunresolved&statsPeriod=${SENTRY_SINCE:-24h}&sort=date&limit=${SENTRY_N:-25}&collapse=stats${SENTRY_ENV:+&environment=${SENTRY_ENV}}")
|
|
39
|
+
[ "$SENTRY_CODE" = "200" ] && jq -e 'type == "array"' "$SENTRY_RESP" >/dev/null 2>&1 \
|
|
40
|
+
|| { echo "[context-fetch:sentry] skipped — ${SENTRY_HOST} HTTP ${SENTRY_CODE:-000} (000 = unreachable, 401/403 = bad token or scope, 404 = wrong org / project / region host)" >&2; exit 0; }
|
|
41
|
+
jq '[.[] | {id, title, culprit, count: .count, firstSeen, lastSeen, permalink}]' "$SENTRY_RESP"
|
|
35
42
|
|
|
36
43
|
# Trace correlation — one issue's latest event → its trace_id. The same id appears in the
|
|
37
44
|
# vercel block's `traceId` (the sentry-trace propagation header), linking the browser stack to
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
# Stripe — failed payment events
|
|
5
5
|
|
|
6
|
-
Fits: apps taking payments with Stripe. `context=runtime`: Events API entries in a window (default last day) whose type names a failure, dispute or refund, filtered by the API (id, type, created, livemode only — never customer, card or metadata). The Events API keeps about 30 days.
|
|
6
|
+
Fits: apps taking payments with Stripe. `context=runtime`: Events API entries in a window (default last day) whose type names a failure, dispute or refund, filtered by the API and paged across the whole window, plus every event whose webhook delivery failed (id, type, created, livemode only — never customer, card or metadata). The Events API keeps about 30 days.
|
|
7
7
|
|
|
8
8
|
- Secret: `STRIPE_SECRET_KEY` — reuse the app's existing key, or a restricted key with read access to Events. The `sk_live_` / `sk_test_` prefix selects live vs test mode.
|
|
9
|
-
- Non-secret: `
|
|
9
|
+
- Non-secret: `STRIPE_SINCE_S` (window in seconds, default 86400), `STRIPE_MAX_PAGES` (pages of 100 events per type list, default 10).
|
|
10
10
|
- CLI: none (`curl` + `jq`), no provision block.
|
|
11
11
|
|
|
12
12
|
Copy the blocks below into `.agents/context.md`, below `<!-- bkit:end -->`.
|
|
@@ -17,37 +17,54 @@ Copy the blocks below into `.agents/context.md`, below `<!-- bkit:end -->`.
|
|
|
17
17
|
# Stripe event stream — payment / subscription / dispute / refund failures (read-only GET).
|
|
18
18
|
# Headless: STRIPE_SECRET_KEY (secret, from env); the key prefix (sk_live_ / sk_test_) selects
|
|
19
19
|
# live vs test mode. PII-safe: only id / type / created / livemode surfaced.
|
|
20
|
-
# Filters at
|
|
21
|
-
#
|
|
22
|
-
#
|
|
20
|
+
# Filters at source: every failure / dispute / refund event type, in two lists; API takes at most
|
|
21
|
+
# 20 `types[]` per call. Each list pages with starting_after while has_more. Second pass: events
|
|
22
|
+
# with failed webhook delivery (delivery_success=false), any type. Non-200 page → `skipped`; page
|
|
23
|
+
# cap → TRUNCATED line.
|
|
24
|
+
# Customise: STRIPE_SINCE_S window in seconds (default 1 day; the API keeps ~30 days); STRIPE_MAX_PAGES (x 100 events per list); the two type lists. Positive control (suggested): run once over a window holding a known event (e.g. test-mode `charge.failed` from a declined test card); nothing back = reader broken, not clean.
|
|
23
25
|
[ -n "${STRIPE_SECRET_KEY:-}" ] \
|
|
24
26
|
|| { echo "[context-fetch:stripe] skipped — STRIPE_SECRET_KEY unset" >&2; exit 0; }
|
|
25
27
|
SINCE_TS=$(( $(date +%s) - ${STRIPE_SINCE_S:-86400} ))
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
$
|
|
28
|
+
STRIPE_RESP=$(mktemp); STRIPE_FAILED=$(mktemp); STRIPE_UNDELIVERED=$(mktemp)
|
|
29
|
+
trap 'rm -f "$STRIPE_RESP" "$STRIPE_FAILED" "$STRIPE_UNDELIVERED"' EXIT
|
|
30
|
+
# stripe_pages <out-file> <extra curl args as one string>: pages the window into <out-file>.
|
|
31
|
+
stripe_pages() {
|
|
32
|
+
out="$1"; extra="$2"; after=""; pages=0
|
|
33
|
+
while [ "$pages" -lt "${STRIPE_MAX_PAGES:-10}" ]; do
|
|
34
|
+
pages=$((pages + 1))
|
|
35
|
+
# $extra unquoted on purpose: one `-d types[]=<name>` per word; type names hold no spaces.
|
|
36
|
+
code=$(curl -sgG -o "$STRIPE_RESP" -w '%{http_code}' "https://api.stripe.com/v1/events" \
|
|
37
|
+
-u "${STRIPE_SECRET_KEY}:" \
|
|
38
|
+
--data-urlencode "limit=100" \
|
|
39
|
+
--data-urlencode "created[gte]=${SINCE_TS}" \
|
|
40
|
+
${after:+--data-urlencode "starting_after=${after}"} $extra)
|
|
41
|
+
[ "$code" = "200" ] \
|
|
42
|
+
|| { echo "[context-fetch:stripe] skipped — api.stripe.com HTTP ${code:-000} on page $pages (401 = bad key, 000 = unreachable)" >&2; return 1; }
|
|
43
|
+
jq -c '.data[]' "$STRIPE_RESP" >> "$out"
|
|
44
|
+
[ "$(jq -r '.has_more' "$STRIPE_RESP")" = "true" ] || return 0
|
|
45
|
+
after=$(jq -r '.data[-1].id' "$STRIPE_RESP")
|
|
46
|
+
done
|
|
47
|
+
printf '===== TRUNCATED: stopped at STRIPE_MAX_PAGES=%s; events older than %s NOT read =====\n' "${STRIPE_MAX_PAGES:-10}" "$after"
|
|
48
|
+
echo "[context-fetch:stripe] truncated — STRIPE_MAX_PAGES reached" >&2
|
|
34
49
|
}
|
|
35
|
-
{
|
|
36
|
-
|
|
50
|
+
types() { for t in "$@"; do printf ' -d types[]=%s' "$t"; done; }
|
|
51
|
+
stripe_pages "$STRIPE_FAILED" "$(types charge.failed charge.refunded charge.refund.updated \
|
|
37
52
|
charge.dispute.created charge.dispute.updated charge.dispute.closed \
|
|
38
53
|
charge.dispute.funds_withdrawn charge.dispute.funds_reinstated \
|
|
39
54
|
payment_intent.payment_failed invoice.payment_failed invoice.finalization_failed \
|
|
40
55
|
checkout.session.async_payment_failed setup_intent.setup_failed \
|
|
41
|
-
refund.created refund.updated refund.failed
|
|
42
|
-
|
|
56
|
+
refund.created refund.updated refund.failed)" || exit 0
|
|
57
|
+
stripe_pages "$STRIPE_FAILED" "$(types application_fee.refunded application_fee.refund.updated \
|
|
43
58
|
payout.failed topup.failed source.failed source.refund_attributes_required \
|
|
44
59
|
issuing_dispute.created issuing_dispute.updated issuing_dispute.closed \
|
|
45
60
|
issuing_dispute.submitted issuing_dispute.funds_reinstated issuing_dispute.funds_rescinded \
|
|
46
|
-
reporting.report_run.failed terminal.reader.action_failed test_helpers.test_clock.internal_failure
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
61
|
+
reporting.report_run.failed terminal.reader.action_failed test_helpers.test_clock.internal_failure)" || exit 0
|
|
62
|
+
stripe_pages "$STRIPE_UNDELIVERED" "-d delivery_success=false" || exit 0
|
|
63
|
+
printf '===== stripe failure-class events since %s — %s event(s) =====\n' \
|
|
64
|
+
"$(jq -rn --argjson s "$SINCE_TS" '$s | todate')" "$(grep -c . "$STRIPE_FAILED")"
|
|
65
|
+
jq -sc 'unique_by(.id) | sort_by(-.created) | .[] | {id, type, created: (.created | todate), livemode}' "$STRIPE_FAILED"
|
|
66
|
+
printf '===== webhook deliveries failed (delivery_success=false) — %s event(s) =====\n' "$(grep -c . "$STRIPE_UNDELIVERED")"
|
|
67
|
+
jq -c '{id, type, created: (.created | todate), pending_webhooks}' "$STRIPE_UNDELIVERED"
|
|
51
68
|
```
|
|
52
69
|
|
|
53
70
|
<!-- context-fetch:end -->
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
# Supabase — Postgres errors
|
|
5
5
|
|
|
6
|
-
Fits: apps on a hosted Supabase project. `context=runtime`: Postgres `ERROR` / `FATAL` / `PANIC`
|
|
6
|
+
Fits: apps on a hosted Supabase project. `context=runtime`: Postgres `ERROR` / `FATAL` / `PANIC` counts per hour, severity, SQLSTATE and role from the Management API logs endpoint (default last 4 h; any longer window is read one day per call, the API's limit). No message text is read. Swap the SQL to `source = 'edge_logs'` for API 5xx.
|
|
7
7
|
|
|
8
8
|
- Secret: `SUPABASE_ACCESS_TOKEN` (personal access token; one token covers preview and production).
|
|
9
|
-
- Non-secret: `SUPABASE_PROJECT_ID` (project ref) — uncomment the line in the block so cloud agents inherit it. Preview and production are separate projects: use the ref whose logs you want. `SINCE_ISO`
|
|
9
|
+
- Non-secret: `SUPABASE_PROJECT_ID` (project ref) — uncomment the line in the block so cloud agents inherit it. Preview and production are separate projects: use the ref whose logs you want. `SINCE_ISO` / `UNTIL_ISO` set the window.
|
|
10
10
|
- CLI: none (`curl` + `jq`), no provision block.
|
|
11
11
|
|
|
12
12
|
Copy the block below into `.agents/context.md`, below `<!-- bkit:end -->`.
|
|
@@ -14,33 +14,58 @@ Copy the block below into `.agents/context.md`, below `<!-- bkit:end -->`.
|
|
|
14
14
|
<!-- context-fetch:start supabase context=runtime -->
|
|
15
15
|
|
|
16
16
|
```bash
|
|
17
|
-
# Supabase Postgres errors
|
|
18
|
-
#
|
|
17
|
+
# Supabase Postgres errors — Management API `GET /v1/projects/{ref}/analytics/endpoints/logs`
|
|
18
|
+
# (`logs.all` removed). ClickHouse SQL over one `logs` table; fields via log_attributes['…']
|
|
19
|
+
# (strings). One call covers at most 24 h, silently drops the rest → loop walks the window a day at
|
|
20
|
+
# a time. Counts per hour + severity + SQLSTATE + role; message text never read. Rejected query =
|
|
21
|
+
# HTTP 200 with `.error`; both checked, either → `skipped`.
|
|
22
|
+
# API 5xx instead: source = 'edge_logs' and toInt32OrZero(log_attributes['response.status_code']) >= 500.
|
|
19
23
|
# SUPABASE_PROJECT_ID is non-secret — uncomment + set the line below so local AND
|
|
20
24
|
# cloud agents inherit it (headless cloud agents never read .bkit/.env). Preview and
|
|
21
25
|
# production are SEPARATE projects — use the ref for the env whose logs you want:
|
|
22
26
|
# SUPABASE_PROJECT_ID="your-project-ref"
|
|
23
|
-
# Customise: SUPABASE_PROJECT_ID (preview vs prod); SINCE_ISO window; SQL
|
|
27
|
+
# Customise: SUPABASE_PROJECT_ID (preview vs prod); SINCE_ISO / UNTIL_ISO (window, default last 4 h); the SQL (source, severities, grouping). Positive control (suggested): run once over a window holding a known error (e.g. a test triggering permission-denied 42501); nothing back = reader broken, not clean.
|
|
24
28
|
[ -n "${SUPABASE_PROJECT_ID:-}" ] && [ -n "${SUPABASE_ACCESS_TOKEN:-}" ] \
|
|
25
29
|
|| { echo "[context-fetch:supabase] skipped — SUPABASE_PROJECT_ID or SUPABASE_ACCESS_TOKEN unset" >&2; exit 0; }
|
|
26
|
-
|
|
27
|
-
|
|
30
|
+
SUPA_NOW=$(date -u +%s)
|
|
31
|
+
SUPA_FROM=$(jq -rn --arg t "${SINCE_ISO:-}" --argjson d "$((SUPA_NOW - 14400))" 'if $t == "" then $d else ($t | sub("\\.[0-9]+"; "") | fromdateiso8601) end' 2>/dev/null)
|
|
32
|
+
SUPA_END=$(jq -rn --arg t "${UNTIL_ISO:-}" --argjson d "$SUPA_NOW" 'if $t == "" then $d else ($t | sub("\\.[0-9]+"; "") | fromdateiso8601) end' 2>/dev/null)
|
|
33
|
+
[ -n "$SUPA_FROM" ] && [ -n "$SUPA_END" ] && [ "$SUPA_FROM" -lt "$SUPA_END" ] \
|
|
34
|
+
|| { echo "[context-fetch:supabase] skipped — SINCE_ISO / UNTIL_ISO not ISO-8601 (2026-01-31T00:00:00Z) or window empty" >&2; exit 0; }
|
|
28
35
|
SQL=$(cat <<'SQL_EOF'
|
|
29
|
-
select
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
select toStartOfHour(timestamp) as hour,
|
|
37
|
+
log_attributes['parsed.error_severity'] as severity,
|
|
38
|
+
log_attributes['parsed.sql_state_code'] as sqlstate,
|
|
39
|
+
log_attributes['parsed.user_name'] as role,
|
|
40
|
+
count() as n
|
|
41
|
+
from logs
|
|
42
|
+
where source = 'postgres_logs'
|
|
43
|
+
and log_attributes['parsed.error_severity'] in ('ERROR', 'FATAL', 'PANIC')
|
|
44
|
+
group by hour, severity, sqlstate, role
|
|
45
|
+
order by hour desc
|
|
46
|
+
limit 1000
|
|
36
47
|
SQL_EOF
|
|
37
48
|
)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
49
|
+
SUPA_RESP=$(mktemp); SUPA_ROWS=$(mktemp)
|
|
50
|
+
trap 'rm -f "$SUPA_RESP" "$SUPA_ROWS"' EXIT
|
|
51
|
+
SUPA_CALLS=0
|
|
52
|
+
while [ "$SUPA_FROM" -lt "$SUPA_END" ]; do
|
|
53
|
+
SUPA_TO=$((SUPA_FROM + 86400)); [ "$SUPA_TO" -le "$SUPA_END" ] || SUPA_TO="$SUPA_END"
|
|
54
|
+
SUPA_CALLS=$((SUPA_CALLS + 1))
|
|
55
|
+
SUPA_CODE=$(curl -sG -o "$SUPA_RESP" -w '%{http_code}' \
|
|
56
|
+
"https://api.supabase.com/v1/projects/${SUPABASE_PROJECT_ID}/analytics/endpoints/logs" \
|
|
57
|
+
-H "Authorization: Bearer ${SUPABASE_ACCESS_TOKEN}" \
|
|
58
|
+
--data-urlencode "sql=${SQL}" \
|
|
59
|
+
--data-urlencode "iso_timestamp_start=$(jq -rn --argjson s "$SUPA_FROM" '$s | todate')" \
|
|
60
|
+
--data-urlencode "iso_timestamp_end=$(jq -rn --argjson s "$SUPA_TO" '$s | todate')")
|
|
61
|
+
[ "$SUPA_CODE" = "200" ] && jq -e '.error == null and (.result | type == "array")' "$SUPA_RESP" >/dev/null 2>&1 \
|
|
62
|
+
|| { echo "[context-fetch:supabase] skipped — logs endpoint HTTP ${SUPA_CODE:-000} on call $SUPA_CALLS$( [ "$SUPA_CODE" = "200" ] && echo ' (query rejected: .error set)') — 401 = bad token, 403/404 = wrong project ref, 000 = unreachable" >&2; exit 0; }
|
|
63
|
+
jq -c '.result[]' "$SUPA_RESP" >> "$SUPA_ROWS"
|
|
64
|
+
SUPA_FROM="$SUPA_TO"
|
|
65
|
+
done
|
|
66
|
+
printf '===== supabase %s postgres ERROR/FATAL/PANIC per hour, %s → %s — %s row(s), %s call(s) =====\n' \
|
|
67
|
+
"$SUPABASE_PROJECT_ID" "${SINCE_ISO:-last 4 h}" "${UNTIL_ISO:-now}" "$(grep -c . "$SUPA_ROWS")" "$SUPA_CALLS"
|
|
68
|
+
jq -rs 'sort_by(.hour) | reverse | .[] | [.hour, .severity, .sqlstate, .role, .n] | @tsv' "$SUPA_ROWS"
|
|
44
69
|
```
|
|
45
70
|
|
|
46
71
|
<!-- context-fetch:end -->
|