@cbartens/bkit 5.2.1 → 5.2.3

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.
Files changed (90) hide show
  1. package/.bkit/README.md +1 -1
  2. package/.bkit/core/.agents/context.md +2 -2
  3. package/.bkit/core/.agents/plugins/bkit/hooks/bkit-guardrails.cjs +7 -1
  4. package/.bkit/core/.bkit/comparison.md +114 -45
  5. package/.bkit/core/.bkit/install.md +8 -5
  6. package/.bkit/core/.bkit/jsonl.md +3 -3
  7. package/.bkit/core/.bkit/prompts.md +6 -5
  8. package/.bkit/core/.bkit/providers.md +5 -4
  9. package/.bkit/core/.bkit/templates.md +11 -10
  10. package/.bkit/core/.bkit/workflows.md +8 -6
  11. package/.bkit/core/.codex/hooks/bkit-guardrails.cjs +5 -1
  12. package/.bkit/core/.cursor/hooks/bkit-guardrails.cjs +8 -2
  13. package/.bkit/core/docs/templates/bkit-audit-accessibility.md +5 -2
  14. package/.bkit/core/docs/templates/bkit-audit-adoption.md +5 -2
  15. package/.bkit/core/docs/templates/bkit-audit-agents.md +5 -2
  16. package/.bkit/core/docs/templates/bkit-audit-aio-seo.md +5 -2
  17. package/.bkit/core/docs/templates/bkit-audit-analytics.md +5 -2
  18. package/.bkit/core/docs/templates/bkit-audit-annotations.md +6 -3
  19. package/.bkit/core/docs/templates/bkit-audit-app-performance.md +5 -2
  20. package/.bkit/core/docs/templates/bkit-audit-app-store.md +5 -2
  21. package/.bkit/core/docs/templates/bkit-audit-architecture.md +5 -2
  22. package/.bkit/core/docs/templates/bkit-audit-ci-performance.md +5 -2
  23. package/.bkit/core/docs/templates/bkit-audit-config.md +5 -2
  24. package/.bkit/core/docs/templates/bkit-audit-cost.md +5 -2
  25. package/.bkit/core/docs/templates/bkit-audit-coverage.md +5 -2
  26. package/.bkit/core/docs/templates/bkit-audit-database.md +5 -2
  27. package/.bkit/core/docs/templates/bkit-audit-dead-code.md +5 -2
  28. package/.bkit/core/docs/templates/bkit-audit-deferrals.md +5 -2
  29. package/.bkit/core/docs/templates/bkit-audit-dependencies.md +5 -2
  30. package/.bkit/core/docs/templates/bkit-audit-documentation.md +5 -2
  31. package/.bkit/core/docs/templates/bkit-audit-duplication.md +5 -2
  32. package/.bkit/core/docs/templates/bkit-audit-failures.md +6 -3
  33. package/.bkit/core/docs/templates/bkit-audit-flakes.md +6 -3
  34. package/.bkit/core/docs/templates/bkit-audit-gates.md +5 -2
  35. package/.bkit/core/docs/templates/bkit-audit-issues.md +5 -2
  36. package/.bkit/core/docs/templates/bkit-audit-llm.md +5 -2
  37. package/.bkit/core/docs/templates/bkit-audit-logs.md +16 -12
  38. package/.bkit/core/docs/templates/bkit-audit-models.md +5 -2
  39. package/.bkit/core/docs/templates/bkit-audit-privacy.md +5 -2
  40. package/.bkit/core/docs/templates/bkit-audit-prompts.md +5 -2
  41. package/.bkit/core/docs/templates/bkit-audit-red-team.md +5 -2
  42. package/.bkit/core/docs/templates/bkit-audit-reliability.md +6 -3
  43. package/.bkit/core/docs/templates/bkit-audit-repo.md +5 -2
  44. package/.bkit/core/docs/templates/bkit-audit-security.md +6 -3
  45. package/.bkit/core/docs/templates/bkit-audit-slop.md +5 -2
  46. package/.bkit/core/docs/templates/bkit-audit-testing.md +5 -2
  47. package/.bkit/core/docs/templates/bkit-audit-usability.md +5 -2
  48. package/.bkit/core/docs/templates/bkit-plan.md +1 -1
  49. package/.bkit/core/engine/checks/after/index.ts +2 -2
  50. package/.bkit/core/engine/commands/install/check.ts +3 -11
  51. package/.bkit/core/engine/commands/install/doctor.ts +2 -3
  52. package/.bkit/core/engine/commands/install/install.ts +44 -11
  53. package/.bkit/core/engine/commands/install/uninstall.ts +60 -44
  54. package/.bkit/core/engine/commands/install/upgrade.ts +8 -1
  55. package/.bkit/core/engine/commands/workflow/branches.ts +13 -4
  56. package/.bkit/core/engine/install/hosts.ts +14 -4
  57. package/.bkit/core/engine/install/manifest.ts +2 -2
  58. package/.bkit/core/engine/install/modules/core.ts +9 -6
  59. package/.bkit/core/engine/ledgers/telemetry.ts +3 -4
  60. package/.bkit/core/hooks/guardrails-read.js +4 -9
  61. package/.bkit/core/hooks/guardrails-tiers.js +312 -28
  62. package/.bkit/core/prompts/bkit-audit-generate.md +19 -5
  63. package/.bkit/shared/.claude/settings.json +19 -0
  64. package/.bkit/shared/.opencode/opencode.json +21 -1
  65. package/.bkit/shared/docs/deployments.md +14 -0
  66. package/.bkit/templates/.github/workflows/bkit-ci.yml +9 -0
  67. package/.bkit/templates/context/bkit-cloudrun.md +28 -19
  68. package/.bkit/templates/context/bkit-expo.md +30 -13
  69. package/.bkit/templates/context/bkit-inngest.md +54 -17
  70. package/.bkit/templates/context/bkit-resend.md +36 -8
  71. package/.bkit/templates/context/bkit-sentry.md +11 -4
  72. package/.bkit/templates/context/bkit-stripe.md +39 -22
  73. package/.bkit/templates/context/bkit-supabase.md +45 -20
  74. package/.bkit/templates/context/bkit-vercel.md +45 -16
  75. package/.bkit/templates/scripts/ci/accepted-advisories.json +7 -0
  76. package/.bkit/templates/scripts/ci/check-dependency-audit.mjs +200 -0
  77. package/.bkit/templates/scripts/ci/check-dependency-audit.test.mjs +127 -0
  78. package/CHANGELOG.md +45 -0
  79. package/README.md +76 -20
  80. package/dist/checks/after/index.js +1 -1
  81. package/dist/commands/install/check.js +3 -15
  82. package/dist/commands/install/doctor.js +2 -1
  83. package/dist/commands/install/install.js +42 -8
  84. package/dist/commands/install/uninstall.js +52 -45
  85. package/dist/commands/install/upgrade.js +8 -2
  86. package/dist/commands/workflow/branches.js +13 -5
  87. package/dist/install/hosts.js +11 -4
  88. package/dist/install/manifest.js +2 -2
  89. package/dist/install/modules/core.js +9 -7
  90. package/package.json +1 -1
@@ -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`, `EAS_ERR_N`, `EAS_LOG_N`; `expo-workflows`: `EAS_WF_FILE`, `EAS_WF_N`, `EAS_WF_ERR_N`, `EAS_JUNIT_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
- # Customise: EXPO_APP_DIR; EAS_PLATFORM (android|ios|all); EAS_PROFILE (build profile, e.g. preview / production); EAS_N (<= 50); EAS_ERR_N; EAS_LOG_N (log lines per build); the log-line filter.
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:-10}" \
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
- # Customise: EXPO_APP_DIR; EAS_WF_FILE (e2e workflow file; unset = all); EAS_WF_N; EAS_WF_ERR_N; EAS_JUNIT_N (lines per JUnit file); which artifacts to inline; the log greps.
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
- eas workflow:runs --json ${EAS_WF_FILE:+--workflow "$EAS_WF_FILE"} --limit "${EAS_WF_N:-10}" 2>/dev/null \
94
- | jq -c '.[]? | {id, status, gitCommitHash, createdAt}'
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 $(eas workflow:runs --json ${EAS_WF_FILE:+--workflow "$EAS_WF_FILE"} --status FAILURE \
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` exits 11 on a FAILED run after printing its JSON: test the output, not the exit code.
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
- [ -s "$STATUS" ] || { echo "[context-fetch:expo-workflows] run $run: workflow:status returned no JSON" >&2; continue; }
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 in a time window (default last 4 h) — function id, run id, error message, and the opaque `*Id` keys of the triggering event.
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: `INNGEST_N` (events, default 25, max 100), `SINCE_ISO` (window start, default 4 h ago; the API alone looks back only 1 h), `INNGEST_ENV` (branch environment name when the key is a branch key).
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. Lists recent `inngest/function.failed` system events → function_id + run_id + error.
21
- # PII-safe: surfaces ONLY /Id$/ keys from the triggering event; every other key is dropped.
22
- # The API's own default window is the last 1 h; the block sets an explicit one.
23
- # Customise: INNGEST_N (<= 100); SINCE_ISO window start (default 4 h ago); INNGEST_ENV (branch environment name, with a branch signing key); the ids projection (narrow it if any *Id key in your events carries PII).
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
- START="${SINCE_ISO:-$(date -u -v-4H +%FT%TZ 2>/dev/null || date -u -d '4 hours ago' +%FT%TZ)}"
27
- curl -sG "https://api.inngest.com/v1/events" \
28
- --data-urlencode "name=inngest/function.failed" \
29
- --data-urlencode "limit=${INNGEST_N:-25}" \
30
- --data-urlencode "received_after=${START}" \
31
- ${INNGEST_ENV:+-H "x-inngest-env: ${INNGEST_ENV}"} \
32
- -H "Authorization: Bearer ${INNGEST_SIGNING_KEY}" \
33
- | jq '[.data[]
34
- | {id, ts, function_id: .data.function_id, run_id: .data.run_id,
35
- error: (.data.error.message // .data.error),
36
- ids: (.data.event.data // {} | with_entries(select(.key | test("Id$"))))}]'
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: `RESEND_N` (sends scanned, default 100).
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 recent sends; each item's `last_event` is its delivery status.
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: RESEND_N; the last_event filter.
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
- curl -s "https://api.resend.com/emails?limit=${RESEND_N:-100}" \
24
- -H "Authorization: Bearer ${RESEND_API_KEY}" \
25
- | jq '[.data[]
26
- | select((.last_event // "") | test("bounce|complain|fail|delay"; "i"))
27
- | {id, last_event, created_at}]'
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
- # Customise: SENTRY_SINCE window (1h / 24h / 7d); SENTRY_ENV (environment name, e.g. production; unset = all); SENTRY_N (<= 100); jq keys.
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
- curl -s \
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
- | jq '[.[] | {id, title, culprit, count: .count, firstSeen, lastSeen, permalink}]'
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: `STRIPE_N` (events returned, default 50, max 100), `STRIPE_SINCE_S` (window in seconds, default 86400).
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 the source: every event type naming a failure, dispute or refund, in two calls
21
- # (the API takes at most 20 `types[]` per call), merged newest first.
22
- # Customise: STRIPE_N (<= 100); STRIPE_SINCE_S window in seconds (default 1 day; the API keeps ~30 days); the two type lists.
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
- stripe_events() {
27
- TYPES=""
28
- for t in "$@"; do TYPES="$TYPES -d types[]=$t"; done
29
- # $TYPES unquoted on purpose: one `-d types[]=<name>` per word; type names hold no spaces.
30
- curl -sgG "https://api.stripe.com/v1/events" -u "${STRIPE_SECRET_KEY}:" \
31
- --data-urlencode "limit=${STRIPE_N:-50}" \
32
- --data-urlencode "created[gte]=${SINCE_TS}" \
33
- $TYPES
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
- stripe_events charge.failed charge.refunded charge.refund.updated \
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
- stripe_events application_fee.refunded application_fee.refund.updated \
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
- } | jq -s --argjson n "${STRIPE_N:-50}" '
48
- [.[] | if .error then error("[context-fetch:stripe] Stripe API error: \(.error.message)") else .data[] end]
49
- | sort_by(-.created) | .[:$n]
50
- | map({id, type, created, livemode})'
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` log lines from the Management API analytics endpoint (window <= 24 h, default last 4 h). Swap the SQL to `edge_logs` with `status_code >= 400` for API 4xx/5xx.
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` overrides the window start.
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 (Management API; window <= 24h).
18
- # Enable: set SUPABASE_PROJECT_ID + SUPABASE_ACCESS_TOKEN. API 4xx/5xx: edge_logs status_code >= 400.
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 severity / limit; postgres_logs vs edge_logs.
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
- START="${SINCE_ISO:-$(date -u -v-4H +%FT%TZ 2>/dev/null || date -u -d '4 hours ago' +%FT%TZ)}"
27
- END="$(date -u +%FT%TZ)"
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 t.timestamp, p.error_severity, event_message
30
- from postgres_logs t
31
- cross join unnest(metadata) m
32
- cross join unnest(m.parsed) p
33
- where p.error_severity in ('ERROR', 'FATAL', 'PANIC')
34
- order by t.timestamp desc
35
- limit 100
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
- curl -sG "https://api.supabase.com/v1/projects/${SUPABASE_PROJECT_ID}/analytics/endpoints/logs.all" \
39
- -H "Authorization: Bearer ${SUPABASE_ACCESS_TOKEN}" \
40
- --data-urlencode "sql=${SQL}" \
41
- --data-urlencode "iso_timestamp_start=${START}" \
42
- --data-urlencode "iso_timestamp_end=${END}" \
43
- | jq '[.result[] | {timestamp, error_severity, event_message}]'
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 -->
@@ -6,9 +6,9 @@
6
6
  Fits: apps deployed on Vercel. `context=runtime`: error and fatal lines from serverless and edge functions in a time window (default last 4 h, preview environment), PII-safe projection with `traceId` to stitch to the `sentry` block.
7
7
 
8
8
  - Secret: `VERCEL_TOKEN` (local env; cloud dashboard). No `vercel login` — headless agents cannot run it.
9
- - Non-secret: `VERCEL_SCOPE` (team slug) — uncomment the line in the block so cloud agents inherit it. `VERCEL_ENV` (`preview` default, `production`), `SINCE` / `UNTIL` (ISO-8601 or relative), `VERCEL_N`.
9
+ - Non-secret: `VERCEL_SCOPE` (team slug) — uncomment the line in the block so cloud agents inherit it. `VERCEL_ENV` (`preview` default, `production`), `SINCE` / `UNTIL` (ISO-8601 or relative), `VERCEL_MAX_PAGES` (pages of 50 lines, default 20).
10
10
  - CLI: `vercel`; the provision block installs it in cloud.
11
- - `--limit` returns the NEWEST N lines inside the window, so a wide window on a busy deployment reads like a tail: narrow the window or raise `VERCEL_N`. For counts over a wide window, the Vercel MCP `get_runtime_logs` with `group_by` beats lines.
11
+ - Each call returns at most 50 lines, the newest inside the window, whatever `--limit` says; the block pages backwards with `--until` up to `VERCEL_MAX_PAGES`. `--no-branch` is required: without it CLI 50.x reads only the checked-out git branch. `--level error` also returns `info` lines, so jq filters `.level`. For counts over a wide window, the Vercel MCP `get_runtime_logs` with `group_by` beats lines.
12
12
 
13
13
  Copy the blocks below into `.agents/context.md`, below `<!-- bkit:end -->`.
14
14
 
@@ -21,22 +21,51 @@ Copy the blocks below into `.agents/context.md`, below `<!-- bkit:end -->`.
21
21
  # VERCEL_SCOPE is non-secret — uncomment + set the line below so local AND cloud
22
22
  # agents inherit it (headless cloud agents never read .bkit/.env):
23
23
  # VERCEL_SCOPE="your-team-slug"
24
- # SINCE / UNTIL take ISO-8601 (2026-01-31T22:50:00Z) or relative (4h). --limit keeps the NEWEST
25
- # N lines inside the window: narrow the window or raise VERCEL_N before widening --level.
26
- # Customise: VERCEL_ENV; SINCE / UNTIL; VERCEL_N; --level / --source; path or status filter; jq keys to the log shape.
24
+ # --no-branch: CLI 50.x otherwise filters to the checked-out git branch; any other branch reads 0
25
+ # lines. Each call returns at most 50 lines, the NEWEST in the window, whatever --limit says → loop
26
+ # pages backwards with --until until a page comes back short. --level error lets `info` through →
27
+ # jq keeps error / fatal only. SINCE / UNTIL: ISO-8601 (2026-01-31T22:50:00Z) or relative (4h).
28
+ # Failed first call → `skipped`; failed later page or page cap → TRUNCATED line naming the unread part.
29
+ # Customise: VERCEL_ENV; SINCE / UNTIL; VERCEL_MAX_PAGES (x 50 lines); --source; path or status filter; jq keys to the log shape. Positive control (suggested): run once over a window holding a known error (e.g. a 5xx seen in the dashboard); nothing back = reader broken, not clean.
27
30
  command -v vercel >/dev/null && [ -n "${VERCEL_TOKEN:-}" ] && [ -n "${VERCEL_SCOPE:-}" ] \
28
31
  || { echo "[context-fetch:vercel] skipped — vercel CLI / VERCEL_TOKEN / VERCEL_SCOPE missing" >&2; exit 0; }
29
- vercel logs \
30
- --token "$VERCEL_TOKEN" \
31
- --scope "$VERCEL_SCOPE" \
32
- --environment "${VERCEL_ENV:-preview}" \
33
- --level error --level fatal \
34
- --source serverless --source edge-function \
35
- --since "${SINCE:-4h}" \
36
- ${UNTIL:+--until "$UNTIL"} \
37
- --limit "${VERCEL_N:-100}" \
38
- --json \
39
- | jq -c '{timestamp, level, source, requestPath, responseStatusCode, traceId, message}' # PII-safe projection; traceId stitches to the sentry block, message is free-text — adjust keys to your log shape
32
+ VERCEL_PAGE=50
33
+ VERCEL_ALL=$(mktemp); VERCEL_CHUNK=$(mktemp)
34
+ trap 'rm -f "$VERCEL_ALL" "$VERCEL_CHUNK"' EXIT
35
+ VERCEL_UNTIL="${UNTIL:-}"; VERCEL_PAGES=0; VERCEL_NOTE=""
36
+ while [ "$VERCEL_PAGES" -lt "${VERCEL_MAX_PAGES:-20}" ]; do
37
+ VERCEL_PAGES=$((VERCEL_PAGES + 1))
38
+ if ! vercel logs \
39
+ --token "$VERCEL_TOKEN" \
40
+ --scope "$VERCEL_SCOPE" \
41
+ --no-branch \
42
+ --environment "${VERCEL_ENV:-preview}" \
43
+ --level error --level fatal \
44
+ --source serverless --source edge-function \
45
+ --since "${SINCE:-4h}" \
46
+ ${VERCEL_UNTIL:+--until "$VERCEL_UNTIL"} \
47
+ --limit "$VERCEL_PAGE" \
48
+ --json > "$VERCEL_CHUNK" 2>/dev/null; then
49
+ [ "$VERCEL_PAGES" -gt 1 ] \
50
+ || { echo "[context-fetch:vercel] skipped — vercel logs exited non-zero (bad token, scope or project, or host unreachable)" >&2; exit 0; }
51
+ VERCEL_NOTE="page $VERCEL_PAGES failed — lines older than $VERCEL_UNTIL NOT read"; break
52
+ fi
53
+ cat "$VERCEL_CHUNK" >> "$VERCEL_ALL"
54
+ [ "$(grep -c . "$VERCEL_CHUNK")" -ge "$VERCEL_PAGE" ] || break
55
+ # Next page ends 1 s after this page's oldest line (overlap, de-duplicated by id below).
56
+ VERCEL_NEXT=$(jq -rs 'map(.timestamp) | min / 1000 | floor + 1 | todate' "$VERCEL_CHUNK")
57
+ [ "$VERCEL_NEXT" != "$VERCEL_UNTIL" ] \
58
+ || { VERCEL_NOTE="over $VERCEL_PAGE lines inside one second at $VERCEL_NEXT — narrow --source or the window"; break; }
59
+ VERCEL_UNTIL="$VERCEL_NEXT"
60
+ [ "$VERCEL_PAGES" -lt "${VERCEL_MAX_PAGES:-20}" ] \
61
+ || VERCEL_NOTE="stopped at VERCEL_MAX_PAGES=${VERCEL_MAX_PAGES:-20} — lines older than $VERCEL_UNTIL NOT read"
62
+ done
63
+ VERCEL_LINES=$(jq -c 'select(.level == "error" or .level == "fatal")' "$VERCEL_ALL" | jq -sc 'unique_by(.id) | sort_by(-.timestamp) | .[]')
64
+ printf '===== vercel %s error/fatal lines, since %s%s — %s lines, %s page(s) =====\n' \
65
+ "${VERCEL_ENV:-preview}" "${SINCE:-4h}" "${UNTIL:+ until $UNTIL}" "$(printf '%s' "$VERCEL_LINES" | grep -c .)" "$VERCEL_PAGES"
66
+ [ -z "$VERCEL_NOTE" ] || { printf '===== TRUNCATED: %s =====\n' "$VERCEL_NOTE"; echo "[context-fetch:vercel] truncated — $VERCEL_NOTE" >&2; }
67
+ printf '%s\n' "$VERCEL_LINES" | grep . \
68
+ | jq -c '{time: (.timestamp / 1000 | floor | todate), level, source, requestPath, responseStatusCode, traceId, message}' # PII-safe projection; traceId stitches to the sentry block, message is free-text — adjust keys to your log shape
40
69
  ```
41
70
 
42
71
  <!-- context-fetch:end -->
@@ -0,0 +1,7 @@
1
+ {
2
+ "blocking": {
3
+ "critical": 7,
4
+ "high": 30
5
+ },
6
+ "accepted": []
7
+ }