td-ai-tools 1.5.1 → 1.5.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "td-ai-tools",
3
- "version": "1.5.1",
3
+ "version": "1.5.3",
4
4
  "description": "Install agent skills and packs into your project",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -64,7 +64,7 @@ When a task spans several areas (a launch touches nearly all of them), follow th
64
64
  ## 4. Bundled tools
65
65
 
66
66
  - `scripts/preflight.sh [dir]`: read-only orientation report (above).
67
- - `scripts/cf-api.sh METHOD PATH [JSON]`: thin `curl` wrapper for the Cloudflare REST API. It is used for anything wrangler can't do: zones, DNS, zone settings, rulesets, bot management. It reads `CLOUDFLARE_API_TOKEN` (and `CLOUDFLARE_ACCOUNT_ID` for the `{account}` placeholder), and prints the JSON body or a readable error. Run it with no arguments for usage. Reference examples pipe its output through `jq`. If `jq` isn't installed, suggest `sudo apt install jq` (or `brew install jq`), or filter with `node -e` in the meantime.
67
+ - `scripts/cf-api.sh METHOD PATH [JSON]`: thin `curl` wrapper for the Cloudflare REST API. It is used for anything wrangler can't do: zones, DNS, zone settings, rulesets, bot management. It reads `CLOUDFLARE_API_TOKEN`, falling back to `CLOUDFLARE_TOKEN` (the TD convention, normally already set in the agent's shell), plus `CLOUDFLARE_ACCOUNT_ID` for the `{account}` placeholder, and prints the JSON body or a readable error. Run it with no arguments for usage. Reference examples pipe its output through `jq`. If `jq` isn't installed, suggest `sudo apt install jq` (or `brew install jq`), or filter with `node -e` in the meantime.
68
68
  - `scripts/verify-site.sh https://domain [--md /about.md]`: read-only post-deploy smoke test covering status codes, HTTPS/www redirects, robots.txt AI-crawler group, llms.txt, sitemap, the Markdown twin, the form token endpoint, and security headers.
69
69
  - `assets/wrangler.jsonc`: annotated starting config for a new Leyline site.
70
70
  - `assets/deploy.yml`: GitHub Actions workflow (preview on PR, deploy on main).
@@ -74,7 +74,7 @@ When a task spans several areas (a launch touches nearly all of them), follow th
74
74
  - **Build, then deploy.** `npx astro build` writes `dist/server/wrangler.json` and a redirect at `.wrangler/deploy/config.json`. A plain `npx wrangler deploy` from the site root then deploys the *built* config. Running `wrangler deploy` without a fresh build ships stale output. Don't pass `-c wrangler.jsonc` to deploy, because that bypasses the built config.
75
75
  - **Use the project's wrangler** (`npx wrangler`, pinned in `package.json`), not a global one. Flags differ between versions. If a flag in these references is rejected, run `npx wrangler <cmd> --help` and trust that over this skill.
76
76
  - **Tag deploys** with `--tag "$(git rev-parse --short HEAD)" --message "<what changed>"`. The tag and message show up in `deployments list` and make rollbacks legible.
77
- - **Never print secret values** into the transcript. Pipe them in (`printf %s "$VAL" | npx wrangler secret put NAME`) and generate random ones with `openssl rand -base64 48`. Don't echo `CLOUDFLARE_API_TOKEN`.
77
+ - **Never print secret values** into the transcript. Pipe them in (`printf %s "$VAL" | npx wrangler secret put NAME`) and generate random ones with `openssl rand -base64 48`. Don't echo `CLOUDFLARE_TOKEN` or `CLOUDFLARE_API_TOKEN`.
78
78
  - **Prefer config over clicks.** Whatever can live in `wrangler.jsonc` (routes, custom domains, bindings, observability, vars) should, so the repo describes the site. Use the API or dashboard only for zone-level things.
79
79
  - **Report what happened**: the deployed version ID, the URL, and what `verify-site.sh` showed. If a step was skipped or failed, say so plainly.
80
80
  - Cloudflare's docs are large and change often. When you need something not covered here, fetch the product's `llms.txt` (e.g. `https://developers.cloudflare.com/workers/llms.txt`) rather than guessing.
@@ -5,9 +5,11 @@ Theory Digital has a mixed setup: most sites run in the Theory Digital account,
5
5
  | Credential | Used by | Covers |
6
6
  |---|---|---|
7
7
  | **Wrangler OAuth login** (per profile) | `wrangler …` | Workers, D1, KV, R2, secrets, Turnstile, routes/custom domains |
8
- | **API token** (`CLOUDFLARE_API_TOKEN`) | `scripts/cf-api.sh`, CI, and wrangler too when set | Anything with matching permissions, including zone settings and DNS, which wrangler can't touch |
8
+ | **API token** (`CLOUDFLARE_TOKEN` locally, `CLOUDFLARE_API_TOKEN` in CI) | `scripts/cf-api.sh`, CI, and wrangler when `CLOUDFLARE_API_TOKEN` is set | Anything with matching permissions, including zone settings and DNS, which wrangler can't touch |
9
9
 
10
- **Default login: `Kyle@theorydigital.ca`.** Unless the user specifies otherwise (or the site's `account_id` belongs to a different account), assume wrangler and API work run as `Kyle@theorydigital.ca` against the Theory Digital account it owns. `npx wrangler whoami` prints the logged-in email; if it's someone else, tell the user and ask before switching (`npx wrangler logout && npx wrangler login`, or a named profile below). An API token in `CLOUDFLARE_API_TOKEN` should likewise belong to that login or be scoped to that account.
10
+ **Default login: `Kyle@theorydigital.ca`.** Unless the user specifies otherwise (or the site's `account_id` belongs to a different account), assume wrangler and API work run as `Kyle@theorydigital.ca` against the Theory Digital account it owns. `npx wrangler whoami` prints the logged-in email; if it's someone else, tell the user and ask before switching (`npx wrangler logout && npx wrangler login`, or a named profile below). An API token in `CLOUDFLARE_TOKEN` / `CLOUDFLARE_API_TOKEN` should likewise belong to that login or be scoped to that account.
11
+
12
+ **Token naming convention**: in a Theory Digital shell, the operator's Cloudflare API token is exported as **`CLOUDFLARE_TOKEN`** and is normally already available to the agent. Check for it with `[ -n "$CLOUDFLARE_TOKEN" ] && echo set` (never echo the value) before asking the user for a token. `scripts/cf-api.sh` uses `CLOUDFLARE_API_TOKEN` if set, otherwise `CLOUDFLARE_TOKEN`. Wrangler does **not** read `CLOUDFLARE_TOKEN`, so it keeps using the OAuth login. That separation is deliberate. `CLOUDFLARE_API_TOKEN` is the name for CI secrets and for one-off overrides (e.g. a client-account token).
11
13
 
12
14
  When `CLOUDFLARE_API_TOKEN` is set in the environment, **wrangler uses it instead of the OAuth login**. Most "wrong account", "Authentication error [code: 10000]" and "permission denied" confusion comes from a stale token in the shell. Check `env | grep CLOUDFLARE_` first.
13
15
 
@@ -54,7 +56,7 @@ bash scripts/cf-api.sh GET /accounts/{account}/tokens/verify # account-
54
56
  bash scripts/cf-api.sh GET '/zones?per_page=50' # which zones it sees
55
57
  ```
56
58
 
57
- Keeping the token out of the transcript: ask the user to `export CLOUDFLARE_API_TOKEN=…` in their own shell (`! export …` in Claude Code), or to store it in a gitignored file you `source`. Never put it in `wrangler.jsonc`, the repo, or a command line you echo.
59
+ Keeping the token out of the transcript: ask the user to `export CLOUDFLARE_TOKEN=…` in their own shell profile (or `! export …` in Claude Code for the session), or to store it in a gitignored file you `source`. Never put it in `wrangler.jsonc`, the repo, or a command line you echo.
58
60
 
59
61
  ## Clients' own accounts
60
62
 
@@ -47,7 +47,7 @@ The response contains `name_servers`, the two to give to the registrar.
47
47
  ```bash
48
48
  bash scripts/cf-api.sh GET '/zones/{zone:acme.com}/dns_records?per_page=500' | jq -r '.result[] | [.type,.name,.content,.proxied] | @tsv'
49
49
  ```
50
- Add anything missing. MX, SPF, DKIM, DMARC and verification TXT records must be **DNS-only** (`"proxied": false`); MX and TXT can't be proxied anyway. Records for other web hosts (subdomains not served by this Worker) can be proxied if their origin supports HTTPS; if unsure, keep them DNS-only to start.
50
+ Add anything missing. MX, SPF, DKIM, DMARC and verification TXT records must be **DNS-only** (`"proxied": false`); MX and TXT can't be proxied anyway, but the **A/AAAA record of each MX target** (e.g. `mail.acme.com`) can be, and the import often proxies it. A proxied mail host resolves to Cloudflare IPs and all inbound mail bounces, so set those records DNS-only. Records for other web hosts (subdomains not served by this Worker) can be proxied if their origin supports HTTPS; if unsure, keep them DNS-only to start.
51
51
 
52
52
  Bulk alternative: build a BIND zone file and `POST /zones/{id}/dns_records/import` (multipart form, `file=@zone.txt`). That endpoint needs `curl -F` directly; `cf-api.sh` sends JSON only.
53
53
 
@@ -73,7 +73,7 @@ bash scripts/cf-api.sh PATCH '/zones/{zone:acme.com}/dns_records/<record_id>' '{
73
73
  # delete (confirm), get the ID from the list first and show the record to the user
74
74
  bash scripts/cf-api.sh DELETE '/zones/{zone:acme.com}/dns_records/<record_id>'
75
75
  # backup the whole zone as BIND text, worth doing before bulk edits
76
- curl -sS -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" "https://api.cloudflare.com/client/v4/zones/$(bash scripts/cf-api.sh zone-id acme.com)/dns_records/export" > acme.com.zone
76
+ curl -sS -H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN:-$CLOUDFLARE_TOKEN}" "https://api.cloudflare.com/client/v4/zones/$(bash scripts/cf-api.sh zone-id acme.com)/dns_records/export" > acme.com.zone
77
77
  ```
78
78
  `"ttl": 1` means "automatic". TXT content with spaces or quotes: pass it exactly as the provider gives it, and the API handles quoting.
79
79
 
@@ -1,6 +1,6 @@
1
1
  # Forms, email and Turnstile
2
2
 
3
- Leyline forms post to the site's own Worker (`/_leyline/forms/<id>`). It validates the submission, optionally stores it in D1, and sends the notification (plus the optional visitor confirmation) through the form's **transport**: Postmark or Cloudflare Email Sending. Cloudflare's part is Turnstile, rate limiting, D1, the DNS that makes email work, and, with the Cloudflare transport, the sending itself.
3
+ Leyline forms post to the site's own Worker (`/_leyline/forms/<id>`, and fetch a token from `/_leyline/token/<id>`; both take a trailing slash when `site.trailingSlash: 'always'`). It validates the submission, optionally stores it in D1, and sends the notification (plus the optional visitor confirmation) through the form's **transport**: Postmark or Cloudflare Email Sending. Cloudflare's part is Turnstile, rate limiting, D1, the DNS that makes email work, and, with the Cloudflare transport, the sending itself.
4
4
 
5
5
  ## Contents
6
6
  - Choosing a transport
@@ -28,6 +28,17 @@ const mail = { to: 'info@acme.com', from: 'Acme <web@acme.com>', transport: 'clo
28
28
 
29
29
  Default for new sites: `cloudflare` when the zone is on Cloudflare DNS and the account is on Workers Paid; otherwise Postmark. Keep Postmark for clients where a missed lead is costly until Email Sending is GA. The free 3,000 quota is per **account**: a site handed off to a client's own account needs that account on Workers Paid (see `site-lifecycle.md`).
30
30
 
31
+ ### Visitor confirmation
32
+
33
+ Add `confirmation` to the form (or the shared `mail` object) to also email the visitor, at the form's `replyTo` email field. It goes through the same transport, from `confirmation.from` (default: the form's `from`), with Reply-To set to the form's `to`, so a visitor's reply reaches the business inbox:
34
+ ```ts
35
+ confirmation: {
36
+ subject: 'We got your message — Acme',
37
+ body: 'Thanks for getting in touch. We will get back to you as soon as we can.\n\nIf it is urgent, call us at 555-0100.',
38
+ },
39
+ ```
40
+ `body` is plain text; blank lines separate paragraphs. A copy of the answers is appended unless `includeSubmission: false`. Have the user confirm the copy: don't promise a response time the client hasn't. Submissions flagged `[unverified]` get no confirmation, and a failed confirmation is only logged; it never fails the submission.
41
+
31
42
  ## Turnstile widgets
32
43
 
33
44
  ```bash
@@ -63,6 +74,7 @@ npx wrangler email sending dns get acme.com # records it expects; com
63
74
  Don't use `destination_address` / `allowed_destination_addresses` if the form sends visitor confirmations: those go to arbitrary addresses. A different binding name needs `emailBinding: '<NAME>'` in the form config.
64
75
  - No secret is needed. `POSTMARK_SERVER_TOKEN` can be left unset.
65
76
  - `wrangler dev` simulates the binding: emails are logged to the console (`send_email binding called with MessageBuilder`) and **not** sent. To send for real from dev, add `"remote": true` to the binding temporarily. It sends real mail.
77
+ - With `persist`, apply local migrations against the config `wrangler dev` runs (`npx wrangler d1 migrations apply DB --local -c dist/server/wrangler.json`). Applying them with the root `wrangler.jsonc` writes a different local state, and submissions fail with `no such table: leyline_submissions` (a 502 in the browser).
66
78
  - Test end to end on a preview or production deploy: notification arrives, Reply-To is the visitor, headers show SPF/DKIM/DMARC pass.
67
79
 
68
80
  ## Postmark DNS
@@ -105,5 +117,6 @@ Work through these in order and stop at the first failure:
105
117
  - `[leyline] Form "x" misconfigured: send_email binding "EMAIL" is not configured` → the binding is missing from `wrangler.jsonc` (or `emailBinding` doesn't match it).
106
118
  2. **Secrets**: `npx wrangler secret list` shows `FORM_SIGNING_SECRET`, plus `POSTMARK_SERVER_TOKEN` for the Postmark transport.
107
119
  3. **Provider activity**: in the Postmark UI (delivered, bounced, spam-complained; a hard-bounced recipient stays suppressed until reactivated), or the dashboard's Email Service → Email Sending activity log and metrics (about 7 days of message preview).
108
- 4. **Recipient side**: spam folder, or a Microsoft 365 quarantine. Unverified DKIM / Return-Path (Postmark) or `cf-bounce` records (Email Sending) make this much worse.
109
- 5. **Submission marked `[unverified]` or flagged**: Leyline's spam heuristics. See `flags` in D1. That's working as designed unless legitimate messages are being rejected.
120
+ 4. **The `to:` mailbox can't receive.** After a zone import, the MX target host (often `mail.<domain>` on cPanel or GoDaddy) can end up **proxied**. It then resolves to Cloudflare IPs, which don't accept SMTP, so every inbound message to the domain bounces, not just form mail. List the zone's MX records, then confirm each target's A/AAAA record is DNS-only (`"proxied": false`). See `domains-and-dns.md`.
121
+ 5. **Recipient side**: spam folder, or a Microsoft 365 quarantine. Unverified DKIM / Return-Path (Postmark) or `cf-bounce` records (Email Sending) make this much worse.
122
+ 6. **Submission marked `[unverified]` or flagged**: Leyline's spam heuristics. See `flags` in D1. That's working as designed unless legitimate messages are being rejected.
@@ -13,19 +13,20 @@
13
13
  # cf-api.sh POST '/zones/{zone:acme.com}/dns_records' '{"type":"CNAME","name":"www","content":"acme.com","proxied":true}'
14
14
  # cf-api.sh PATCH '/zones/{zone:acme.com}/settings/ssl' '{"value":"strict"}'
15
15
  #
16
- # Auth: CLOUDFLARE_API_TOKEN (never printed). Output: response JSON (pretty via jq if present).
16
+ # Auth: CLOUDFLARE_API_TOKEN, else CLOUDFLARE_TOKEN (TD shell convention; never printed). Output: response JSON (pretty via jq if present).
17
17
  # Exit code 1 when the API reports success:false.
18
18
  set -euo pipefail
19
19
 
20
20
  API="https://api.cloudflare.com/client/v4"
21
21
  usage() { sed -n '2,17p' "$0" | sed 's/^# \{0,1\}//'; exit 2; }
22
22
  [ $# -lt 2 ] && usage
23
- : "${CLOUDFLARE_API_TOKEN:?Set CLOUDFLARE_API_TOKEN (see references/auth-and-accounts.md)}"
23
+ CF_TOKEN="${CLOUDFLARE_API_TOKEN:-${CLOUDFLARE_TOKEN:-}}"
24
+ [ -n "$CF_TOKEN" ] || { echo "Set CLOUDFLARE_TOKEN or CLOUDFLARE_API_TOKEN (see references/auth-and-accounts.md)" >&2; exit 2; }
24
25
 
25
26
  pretty() { if command -v jq >/dev/null; then jq .; else cat; fi; }
26
27
 
27
28
  call() { # method path [body]
28
- local args=(-sS -X "$1" "$API$2" -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" -H "Content-Type: application/json")
29
+ local args=(-sS -X "$1" "$API$2" -H "Authorization: Bearer $CF_TOKEN" -H "Content-Type: application/json")
29
30
  if [ $# -ge 3 ] && [ -n "$3" ]; then
30
31
  if [[ "$3" == @* ]]; then args+=(--data-binary "$3"); else args+=(--data "$3"); fi
31
32
  fi
@@ -78,6 +78,7 @@ fi
78
78
 
79
79
  hr "Auth"
80
80
  [ -n "${CLOUDFLARE_API_TOKEN:-}" ] && echo "CLOUDFLARE_API_TOKEN is set (wrangler will use it instead of OAuth)"
81
+ [ -n "${CLOUDFLARE_TOKEN:-}" ] && echo "CLOUDFLARE_TOKEN is set (used by cf-api.sh; wrangler ignores it)"
81
82
  [ -n "${CLOUDFLARE_ACCOUNT_ID:-}" ] && echo "CLOUDFLARE_ACCOUNT_ID=$CLOUDFLARE_ACCOUNT_ID"
82
83
  $W auth list 2>/dev/null | grep -v '^\s*$' | grep -v 'wrangler' | grep -v '^─' | sed 's/^/profiles: /' | head -10
83
84
  $W whoami 2>&1 | grep -v -E '^\s*$|wrangler [0-9]|^─|Getting User' | head -25