td-ai-tools 1.5.2 → 1.6.0

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 (29) hide show
  1. package/package.json +1 -1
  2. package/skills/README.md +2 -7
  3. package/skills/barrage/scripts/__pycache__/build_queue.cpython-312.pyc +0 -0
  4. package/skills/barrage/scripts/__pycache__/manage_queue.cpython-312.pyc +0 -0
  5. package/skills/barrage/scripts/__pycache__/queue_paths.cpython-312.pyc +0 -0
  6. package/skills/cloudflare/SKILL.md +11 -3
  7. package/skills/cloudflare/assets/wrangler.jsonc +11 -9
  8. package/skills/cloudflare/references/auth-and-accounts.md +6 -4
  9. package/skills/cloudflare/references/ci-cd.md +11 -6
  10. package/skills/cloudflare/references/data-d1-kv-r2.md +4 -4
  11. package/skills/cloudflare/references/deploy-and-release.md +2 -2
  12. package/skills/cloudflare/references/domains-and-dns.md +1 -1
  13. package/skills/cloudflare/references/forms-email-turnstile.md +1 -1
  14. package/skills/cloudflare/references/launch-new-site.md +30 -49
  15. package/skills/cloudflare/references/observability-and-incidents.md +1 -1
  16. package/skills/cloudflare/scripts/cf-api.sh +4 -3
  17. package/skills/cloudflare/scripts/preflight.sh +1 -0
  18. package/skills/cloudflare-init/SKILL.md +101 -0
  19. package/skills/cloudflare-init/agents/openai.yaml +4 -0
  20. package/skills/cloudflare-init/assets/placeholder-worker.js +15 -0
  21. package/skills/cloudflare-init/assets/worker.emdash.ts +10 -0
  22. package/skills/cloudflare-init/assets/wrangler.jsonc +65 -0
  23. package/skills/cloudflare-init/scripts/cloudflare-init.mjs +598 -0
  24. package/skills/shopify-lint/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -0
  25. package/skills/shopify-lint/scripts/__pycache__/shopify_lint.cpython-312.pyc +0 -0
  26. package/skills/shopify-lint/tests/__pycache__/test_shopify_lint.cpython-312.pyc +0 -0
  27. package/skills/shopify-pre-pr/scripts/__pycache__/test_vendor_change_audit.cpython-312.pyc +0 -0
  28. package/skills/shopify-pre-pr/scripts/__pycache__/vendor_change_audit.cpython-312.pyc +0 -0
  29. package/skills/visual-regression/scripts/__pycache__/visual_regression.cpython-312.pyc +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "td-ai-tools",
3
- "version": "1.5.2",
3
+ "version": "1.6.0",
4
4
  "description": "Install agent skills and packs into your project",
5
5
  "type": "module",
6
6
  "scripts": {
package/skills/README.md CHANGED
@@ -1,13 +1,11 @@
1
1
  # skills
2
2
 
3
3
  ## Available Skills
4
- - `a11y-audit`: Run script-driven accessibility audits for user-provided URLs with Axe Core and Playwright, targeting…
5
- - `barrage`: Convert a group of Basecamp todos or cards into a td-barrage queue.json task file, and maintain an existing…
4
+ - `barrage`
6
5
  - `basecamp`: Interact with Basecamp via the Basecamp CLI.
7
6
  - `browser-validation`: Before completing a task validate frontend or template changes in a real browser with the Playwright-CLI…
8
- - `cache-reset`: Clear and warm Laravel and Statamic caches (including Statamic Glide image caches) after content or template…
9
- - `client-overview`: Generate a client-facing markdown report that summarizes all changes on the current branch against the…
10
7
  - `cloudflare`: Operate Theory Digital's Cloudflare-hosted sites (Leyline / Astro on Workers) with wrangler and the…
8
+ - `cloudflare-init`: Provision the Cloudflare resources for a new Theory Digital / Leyline site before its domain is set up, with…
11
9
  - `debugging-ios-webkit`: Debugs iOS Safari/Chrome-iOS rendering bugs — stale paints, viewport/browser-chrome clipping, mobile-only CSS…
12
10
  - `forge-cli`: Manage Laravel Forge organizations, servers, sites, and provisioned resources with Forge CLI 2.x, falling…
13
11
  - `horizon-component-migration`: Bundle Shopify Horizon components into a migration package for a different theme, including recursive…
@@ -18,9 +16,6 @@
18
16
  - `shopify-cli`: Shopify CLI workflows for theme development.
19
17
  - `shopify-lint`: Run Shopify CLI Theme Check and Theory Digital's bundled Liquid, JavaScript, and CSS rules together, linting…
20
18
  - `shopify-pre-pr`: Prepare a Shopify theme branch for pull request.
21
- - `stylesheet-migration`: Migrate Shopify Liquid `{% stylesheet %}` blocks into theme CSS assets using bundled Python scripts.
22
- - `td-js-vanilla-rules`: Theory Digital vanilla JavaScript standards for Shopify theme work.
23
- - `td-review`: Run parallel code review agents on a PR (including TD theme compliance) and produce a synthesized findings…
24
19
  - `visual-regression`: Single-site visual regression workflow for comparing a live URL against a preview/staging URL in Playwright…
25
20
 
26
21
  ## Skill Structure Convention
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: cloudflare
3
- version: 1.0.0
3
+ version: 1.1.0
4
4
  description: Operate Theory Digital's Cloudflare-hosted sites (Leyline / Astro on Workers) with wrangler and the Cloudflare API — launch a new site end to end, deploy and roll back, preview branches, manage secrets, D1/KV/R2, custom domains and DNS, zone settings (AI crawlers, redirects, caching, SSL), Turnstile, email routing, logs, CI/CD, account/profile switching, client handoff and decommissioning. Use this whenever the user mentions Cloudflare, wrangler, Workers, deploying/shipping/publishing a site, going live, a domain or DNS change, a rollback, a secret or env var, D1 migrations, "the site is down/500ing", tailing logs, or moving a site to a client's account — even if they don't say "Cloudflare" explicitly.
5
5
  ---
6
6
 
@@ -46,6 +46,7 @@ Read only the file for the task at hand. Each one is self-contained.
46
46
 
47
47
  | Task | Read |
48
48
  |---|---|
49
+ | Set up a new site's Cloudflare resources before it has a domain | the **`cloudflare-init`** skill (one script, standard names) |
49
50
  | Launch a brand-new site (repo → live on its domain) | `references/launch-new-site.md` |
50
51
  | Deploy, gradual rollout, preview a branch, roll back, check what's live | `references/deploy-and-release.md` |
51
52
  | Login, auth profiles, multiple accounts, API tokens, token permissions | `references/auth-and-accounts.md` |
@@ -61,10 +62,17 @@ Read only the file for the task at hand. Each one is self-contained.
61
62
 
62
63
  When a task spans several areas (a launch touches nearly all of them), follow the primary file. It points to the others at the step where they become relevant.
63
64
 
65
+ **Naming standard** (owned by `cloudflare-init`, which enforces it):
66
+ - The Worker is the project slug: the brand in kebab-case, e.g. `access-matting`, not the domain.
67
+ - Resources are `<slug>-<binding>`: D1 `<slug>-db`, KV `<slug>-session`, R2 `<slug>-media`.
68
+ - The Turnstile widget is `<slug>`, and the repo is `Theory-Digital/<slug>`.
69
+ - Each site gets its own rate-limit `namespace_id`.
70
+ - Name anything new you create for a site this way. Existing sites predate the standard; their deviations are listed in Leyline's `docs/sites.md` ("Known inconsistencies"). Use their real names, and don't rename them in passing.
71
+
64
72
  ## 4. Bundled tools
65
73
 
66
74
  - `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.
75
+ - `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
76
  - `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
77
  - `assets/wrangler.jsonc`: annotated starting config for a new Leyline site.
70
78
  - `assets/deploy.yml`: GitHub Actions workflow (preview on PR, deploy on main).
@@ -74,7 +82,7 @@ When a task spans several areas (a launch touches nearly all of them), follow th
74
82
  - **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
83
  - **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
84
  - **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`.
85
+ - **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
86
  - **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
87
  - **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
88
  - 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.
@@ -1,9 +1,10 @@
1
- // Starting config for a Leyline site on Cloudflare Workers.
1
+ // Reference config for a Leyline site on Cloudflare Workers. New sites: run the cloudflare-init skill,
2
+ // which provisions the resources and writes this file with the standard names filled in.
2
3
  // Replace every <PLACEHOLDER>. Don't set "main" or "assets": @astrojs/cloudflare generates them
3
4
  // into dist/server/wrangler.json at build time, and `wrangler deploy` reads that file.
4
5
  {
5
6
  "$schema": "node_modules/wrangler/config-schema.json",
6
- "name": "<client>-site",
7
+ "name": "<slug>",
7
8
  // Pins every wrangler command in this repo to the right account (wrangler whoami lists IDs).
8
9
  "account_id": "<ACCOUNT_ID>",
9
10
  // Pin it and bump it deliberately (see site-lifecycle.md).
@@ -34,29 +35,30 @@
34
35
  // npx wrangler email sending enable <domain>. Remove for the Postmark transport.
35
36
  "send_email": [{ "name": "EMAIL", "allowed_sender_addresses": ["web@<DOMAIN>"] }],
36
37
 
37
- // Forms with `persist`: store submissions. `npx wrangler d1 create <client>-site --location enam`
38
+ // Forms with `persist`: store submissions. `npx wrangler d1 create <slug>-db --location wnam`
38
39
  "d1_databases": [
39
40
  {
40
41
  "binding": "DB",
41
- "database_name": "<client>-site",
42
+ "database_name": "<slug>-db",
42
43
  "database_id": "<DATABASE_ID>",
43
44
  "migrations_dir": "migrations"
44
45
  }
45
46
  ],
46
47
 
47
- // Forms with `rateLimit`. namespace_id: any integer unique among this account's sites.
48
+ // Forms with `rateLimit`. namespace_id: unique in the account (cloudflare-init allocates 1 + the highest in use).
49
+ // Sites sharing an ID share counters.
48
50
  "ratelimits": [
49
- { "name": "FORM_RATE_LIMITER", "namespace_id": "<1001>", "simple": { "limit": 5, "period": 60 } }
51
+ { "name": "FORM_RATE_LIMITER", "namespace_id": "<NAMESPACE_ID>", "simple": { "limit": 5, "period": 60 } }
50
52
  ]
51
53
 
52
54
  // Optional staging Worker. Bindings and vars do NOT inherit, so repeat them here.
53
55
  // "env": {
54
56
  // "staging": {
55
- // "name": "<client>-site-staging",
57
+ // "name": "<slug>-staging",
56
58
  // "routes": [{ "pattern": "staging.<domain>", "custom_domain": true }],
57
59
  // "vars": { "PUBLIC_TURNSTILE_SITE_KEY": "<SITEKEY>" },
58
- // "d1_databases": [{ "binding": "DB", "database_name": "<client>-site-staging", "database_id": "<ID>", "migrations_dir": "migrations" }],
59
- // "ratelimits": [{ "name": "FORM_RATE_LIMITER", "namespace_id": "<1002>", "simple": { "limit": 5, "period": 60 } }]
60
+ // "d1_databases": [{ "binding": "DB", "database_name": "<slug>-staging-db", "database_id": "<ID>", "migrations_dir": "migrations" }],
61
+ // "ratelimits": [{ "name": "FORM_RATE_LIMITER", "namespace_id": "<STAGING_NAMESPACE_ID>", "simple": { "limit": 5, "period": 60 } }]
60
62
  // }
61
63
  // }
62
64
  }
@@ -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
 
@@ -39,7 +41,7 @@ Create tokens at dash.cloudflare.com → My Profile → API Tokens (user-owned),
39
41
  Recommended permission sets:
40
42
 
41
43
  **Site operator token** (used interactively with this skill):
42
- - Account: Workers Scripts Edit · D1 Edit · Workers KV Storage Edit · Workers R2 Storage Edit · Turnstile Sites Edit · Account Settings Read
44
+ - Account: Workers Scripts Edit · D1 Edit · Workers KV Storage Edit · Workers R2 Storage Edit · Turnstile Sites Edit · Workers Builds Configuration Edit · Account Settings Read. This is the set `cloudflare-init` needs. Keep the token **user-owned**: the Builds API rejects account-owned tokens
43
45
  - Zone (specific zones, or all zones in the account): Zone Read · DNS Edit · Zone Settings Edit · Workers Routes Edit · Bot Management Edit · Dynamic URL Redirects Edit (Single Redirects) · Cache Rules Edit · Email Routing Rules Edit · SSL and Certificates Edit
44
46
  - Adding new zones needs **Zone: Edit** at the account level. Grant it only to tokens that launch sites.
45
47
 
@@ -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
 
@@ -6,11 +6,11 @@ There are two ways to deploy automatically. Pick one per site; using both causes
6
6
  |---|---|---|
7
7
  | Setup | Workflow file plus repo secrets | Connect the repo in the dashboard (Worker → Settings → Builds) |
8
8
  | Runs | In GitHub, with your own test steps | In Cloudflare's build environment |
9
- | PR previews | Via `versions upload --preview-alias`, commented on the PR | Built in (non-production branch builds get preview URLs) |
10
- | Migrations / secrets | Scriptable in the workflow | Build command only. Migrations remain a manual step |
11
- | Good for | Sites with lint/tests, D1 migrations, or anything custom | Simple sites where the client account owner wants it all in Cloudflare |
9
+ | PR previews | Via `versions upload --preview-alias`, commented on the PR | "Preview other branches" trigger: `versions upload`, URL posted in the GitHub check |
10
+ | Migrations / secrets | Scriptable in the workflow | Migrations in the deploy command (the standard trigger does this); runtime secrets live on the Worker |
11
+ | Good for | Sites not on Leyline updates that need custom CI steps | Leyline sites (the TD default; the update pipeline reads its preview check) |
12
12
 
13
- The Theory Digital default is **GitHub Actions**: it runs the same `astro check`/build as local, and the account and token are explicit.
13
+ The Theory Digital default for Leyline sites is **Workers Builds**, set up by `cloudflare-init`. The Leyline update pipeline reads the preview URL that Workers Builds posts in its GitHub check. Use GitHub Actions only for a site that isn't on Leyline updates.
14
14
 
15
15
  ## GitHub Actions setup
16
16
 
@@ -36,9 +36,14 @@ Worker runtime secrets (`FORM_SIGNING_SECRET` etc.) stay on the Worker. Set them
36
36
 
37
37
  ## Workers Builds notes
38
38
 
39
- - Build command: `npx astro build`. Deploy command: `npx wrangler deploy`. Non-production branch deploy command: `npx wrangler versions upload`.
39
+ - Standard triggers (created by `cloudflare-init`):
40
+ - **Deploy production** (`main`): `npm run build`, then `npx wrangler d1 migrations apply DB --remote && npx wrangler deploy`.
41
+ - **Preview other branches** (`*` except `main`): `npm run build`, then `npx wrangler versions upload`.
42
+ - Build cache on, and `NPM_TOKEN` a secret on both.
43
+ - The previews beta is off (`previews_enabled: false`). Turning it off deletes non-production triggers, so it's done before the preview trigger is created.
44
+ - The Builds API (`/accounts/{id}/builds/...`) needs a **user-owned** token with Workers Builds Configuration Edit; account-owned tokens get "Invalid token". `GET /builds/workers/{tag}/builds` lists builds, and `GET /builds/builds/{uuid}/logs` returns a build's log.
40
45
  - Builds run in the account that owns the Worker, so the client's account needs the Git connection authorized there. For client-owned accounts, the client may need to approve the GitHub app.
41
- - Inspect builds in the dashboard. There's no first-class wrangler command for build logs.
46
+ - Inspect builds in the dashboard or through the Builds API (above). There is no first-class wrangler command for build logs.
42
47
 
43
48
  ## Troubleshooting CI
44
49
 
@@ -13,8 +13,8 @@
13
13
 
14
14
  ```bash
15
15
  npx wrangler d1 list
16
- npx wrangler d1 info acme-site # size, region, tables
17
- npx wrangler d1 create acme-site --location enam # (confirm) also --jurisdiction eu|us|fedramp for data residency (permanent)
16
+ npx wrangler d1 info acme-db # size, region, tables
17
+ npx wrangler d1 create acme-db --location wnam # (confirm) also --jurisdiction eu|us|fedramp for data residency (permanent)
18
18
  ```
19
19
 
20
20
  ### Migrations
@@ -52,7 +52,7 @@ npx wrangler d1 time-travel restore DB --timestamp 2026-10-01T12:00:00Z # (conf
52
52
  A restore rewinds every table, including legitimate submissions received since then. Before a restore, export the current state, so lost rows can be re-inserted selectively. The restore prints a bookmark for the pre-restore state; record it, because it makes the restore itself undoable.
53
53
 
54
54
  ### Delete
55
- `npx wrangler d1 delete acme-site` (confirm, and export first). Remove the binding from the config, or the next deploy fails.
55
+ `npx wrangler d1 delete acme-db` (confirm, and export first). Remove the binding from the config, or the next deploy fails.
56
56
 
57
57
  ## Form submissions: common queries
58
58
 
@@ -70,7 +70,7 @@ SELECT created_at, flags FROM leyline_submissions WHERE flags <> '[]' ORDER BY c
70
70
 
71
71
  ## EmDash on D1
72
72
 
73
- Production EmDash sites use `@emdash-cms/cloudflare`'s `d1()` driver (see Leyline's `docs/CONTENT-MODEL.md`). They usually have a separate D1 database for CMS content, apart from form submissions; that keeps exports and restores scoped. Content seeding: `leyline-seed` generates seed JSON from a static site, and EmDash's CLI applies it. Treat a content-DB restore as an editor-visible event and tell the client.
73
+ Production EmDash sites use `@emdash-cms/cloudflare`'s `d1()` driver (see Leyline's `docs/CONTENT-MODEL.md`). The standard (`cloudflare-init --emdash`) is one database, `<slug>-db` bound as `DB`, holding both EmDash content and Leyline form submissions, plus an R2 bucket `<slug>-media` bound as `MEDIA`. A restore therefore rewinds both, so export first and re-insert submissions selectively. Content seeding: `leyline-seed` generates seed JSON from a static site, and EmDash's CLI applies it. Treat a content-DB restore as an editor-visible event and tell the client.
74
74
 
75
75
  ## KV
76
76
 
@@ -91,10 +91,10 @@ Optional. Use it for clients who want sign-off before production. In `wrangler.j
91
91
  ```jsonc
92
92
  "env": {
93
93
  "staging": {
94
- "name": "acme-site-staging", // explicit is clearer than the implicit suffix
94
+ "name": "acme-staging", // explicit is clearer than the implicit suffix
95
95
  "routes": [{ "pattern": "staging.acme.com", "custom_domain": true }],
96
96
  "vars": { "PUBLIC_TURNSTILE_SITE_KEY": "1x00000000000000000000AA" },
97
- "d1_databases": [{ "binding": "DB", "database_name": "acme-site-staging", "database_id": "…", "migrations_dir": "migrations" }]
97
+ "d1_databases": [{ "binding": "DB", "database_name": "acme-staging-db", "database_id": "…", "migrations_dir": "migrations" }]
98
98
  }
99
99
  }
100
100
  ```
@@ -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
 
@@ -43,7 +43,7 @@ confirmation: {
43
43
 
44
44
  ```bash
45
45
  npx wrangler turnstile widget list
46
- npx wrangler turnstile widget create "acme site" --domain acme.com --domain www.acme.com --mode managed --json # (confirm)
46
+ npx wrangler turnstile widget create acme --domain acme.com --domain www.acme.com --mode managed --json # (confirm)
47
47
  npx wrangler turnstile widget get <sitekey>
48
48
  npx wrangler turnstile widget update <sitekey> --domain acme.com --domain www.acme.com --domain staging.acme.com # (confirm)
49
49
  ```
@@ -6,9 +6,7 @@ The end-to-end runbook, from an empty directory (or a finished repo) to a site l
6
6
  0. Gather inputs
7
7
  1. Account and auth
8
8
  2. Scaffold or adopt the repo
9
- 3. `wrangler.jsonc`
10
- 4. Data: D1 and rate limiting
11
- 5. Secrets and Turnstile
9
+ 3–5. Provision with `cloudflare-init` (resources, secrets, Builds, `wrangler.jsonc`)
12
10
  6. Build and preview locally
13
11
  7. First deploy (workers.dev)
14
12
  8. Get the zone onto Cloudflare
@@ -29,13 +27,15 @@ Ask for whatever the user hasn't supplied. Don't guess the account or the domain
29
27
  | **Which Cloudflare account**: Theory Digital's, or the client's own? | Everything is created there; moving it later is real work (see `site-lifecycle.md`) |
30
28
  | Is the domain **already a zone on Cloudflare**? Who controls the registrar? | Decides whether phase 8 is needed, and who has to change nameservers |
31
29
  | Does the domain receive **email** today (MX records)? | A nameserver switch that drops MX/TXT records breaks the client's email. This is the most common launch disaster |
32
- | Forms? Persist submissions (D1)? Rate limit? Turnstile? | Decides phases 4–5 |
30
+ | Forms? Turnstile? Email transport (Cloudflare or Postmark)? | `cloudflare-init` flags (`--no-turnstile`), and phase 5's transport notes |
33
31
  | Content source: static Markdown or EmDash? | EmDash on Workers needs its own D1 and, usually, R2 (see `data-d1-kv-r2.md`) |
34
32
  | Locales | `site.locales`, and the sitemap check |
35
33
 
36
- Naming conventions (use these unless the repo already does something else):
37
- - Worker: `<client>-site`, e.g. `acme-site`. Staging: `acme-site-staging` (that's what `--env staging` produces).
38
- - D1: `<client>-site`. Turnstile widget: `<client> site`. Auth profile: `td` or `client-<client>`.
34
+ Naming (the `cloudflare-init` standard; its script enforces it):
35
+ - Slug: the brand in kebab-case, not the domain (`acme`, `access-matting`). The Worker is the slug, so it serves at `<slug>.theory-digital.workers.dev`.
36
+ - Resources are `<slug>-<binding>`: D1 `acme-db`, KV `acme-session`, R2 `acme-media`. The Turnstile widget is `acme`, and the repo is `Theory-Digital/acme`.
37
+ - Staging: `acme-staging`, with `acme-staging-db` and so on.
38
+ - Auth profile: `td` or `client-<client>`.
39
39
 
40
40
  ## 1. Account and auth
41
41
 
@@ -64,49 +64,29 @@ Set `site.url` to the **final production origin** now, even before the domain wo
64
64
 
65
65
  Make sure `.gitignore` covers `.wrangler/`, `.dev.vars*`, and `dist/`.
66
66
 
67
- ## 3. `wrangler.jsonc`
67
+ ## 3–5. Provision with `cloudflare-init`
68
68
 
69
- Copy `assets/wrangler.jsonc` from this skill into the site root and fill in the placeholders. It includes observability, `workers_dev` and `preview_urls`, commented-out routes for phase 9, and the bindings Leyline forms expect. Don't set `main` or `assets`: the Astro adapter generates them in `dist/server/wrangler.json`.
69
+ Use the `cloudflare-init` skill. Its script creates everything that doesn't need the domain, under the standard names:
70
+ - D1 `<slug>-db` (WNAM), KV `<slug>-session`, and for EmDash R2 `<slug>-media`.
71
+ - Turnstile widget `<slug>`, on the workers.dev hosts.
72
+ - A rate-limit namespace unique in the account.
73
+ - The Worker, with `FORM_SIGNING_SECRET` and `TURNSTILE_SECRET_KEY` set.
74
+ - Workers Builds triggers, with `NPM_TOKEN`.
75
+ - `wrangler.jsonc` and `.dev.vars`.
70
76
 
71
- ✅ `bash scripts/preflight.sh` parses the config and shows the right name and account.
72
-
73
- ## 4. Data: D1 and rate limiting
74
-
75
- Skip this phase if forms don't use `persist` or `rateLimit`.
76
-
77
- ```bash
78
- npx wrangler d1 create acme-site --location enam # (confirm) choose the location hint nearest the audience; Canada/US East → enam
79
- ```
80
-
81
- Paste the returned `database_id` into `d1_databases`. Alternatively, run `--binding DB --update-config` to let wrangler write it, then check the `migrations_dir`. If the site or client is under EU data rules, use `--jurisdiction eu`. That choice can't be changed later.
77
+ It plans first, and changes nothing until it's re-run with `--apply` after the user agrees. For a client-owned account, pass `--account`.
82
78
 
79
+ Then, in the repo:
83
80
  ```bash
84
81
  mkdir -p migrations
85
82
  cp node_modules/@theory-digital/leyline/src/forms/migrations/*.sql migrations/
86
83
  npx wrangler d1 migrations apply DB --local # for wrangler dev
87
84
  ```
85
+ The production trigger applies remote migrations before each deploy.
88
86
 
89
- Hold the remote apply until phase 7.
90
-
91
- Rate limiting: the `ratelimits[].namespace_id` is a number you choose. It only has to be unique among the Workers in that account that shouldn't share counters. Use a distinct one per site (e.g. 1001, 1002, …) and record it in the README.
92
-
93
- ✅ `npx wrangler d1 list` shows the database, and the ID in the config isn't the `0000…` placeholder.
94
-
95
- ## 5. Secrets and Turnstile
87
+ Don't hand-pick a rate-limit `namespace_id` or copy one from another site. Sites that share one also share counters, because Leyline keys limits by `form:ip`.
96
88
 
97
- See `config-secrets-envs.md` and `forms-email-turnstile.md` for detail.
98
-
99
- Local first. Create `.dev.vars` (gitignored):
100
- ```
101
- FORM_SIGNING_SECRET=<openssl rand -base64 48>
102
- POSTMARK_SERVER_TOKEN=<from Postmark → server → API tokens> # Postmark transport only
103
- ```
104
-
105
- Turnstile, if enabled. The widget needs the production hostname, plus `localhost` if you want it to work in dev:
106
- ```bash
107
- npx wrangler turnstile widget create "acme site" --domain acme.com --domain www.acme.com --mode managed --json # (confirm)
108
- ```
109
- Put the returned `sitekey` in `vars.PUBLIC_TURNSTILE_SITE_KEY` in `wrangler.jsonc`, and the `secret` in `.dev.vars` as `TURNSTILE_SECRET_KEY`. Treat the secret like a password. Don't repeat it back in chat beyond writing it to the file. For local development, Cloudflare's always-pass test keys work. The Leyline action check lets them through.
89
+ ✅ The script's summary shows every resource as `exists`/`created`, with no `SKIP`. `bash scripts/preflight.sh` shows the right name and account.
110
90
 
111
91
  Email transport (see `forms-email-turnstile.md` → "Choosing a transport"):
112
92
  - **Cloudflare** (`transport: 'cloudflare'`): add the `send_email` binding to `wrangler.jsonc`. Onboarding the domain (`wrangler email sending enable`) needs the zone on Cloudflare DNS, so it waits for phase 8 if the zone is moving; until then the form only works in `wrangler dev` (logged, not sent).
@@ -124,21 +104,17 @@ Use this, not `astro preview`. In Astro 7.3 it returns 500s for prerendered page
124
104
 
125
105
  ## 7. First deploy (workers.dev) (confirm)
126
106
 
127
- Deploying first to `<name>.<subdomain>.workers.dev` proves the Worker, bindings and secrets work before any DNS changes.
107
+ Deploying first to `<slug>.<subdomain>.workers.dev` proves the Worker, bindings and secrets work before any DNS changes. Until then, `cloudflare-init` leaves a placeholder there (503, noindex).
128
108
 
109
+ Merge or push to `main`. The "Deploy production" Workers Builds trigger applies D1 migrations and deploys. Follow the build in the dashboard, or with `GET /builds/workers/{tag}/builds` (see `ci-cd.md`). Without Workers Builds, do it by hand:
129
110
  ```bash
130
111
  npx wrangler d1 migrations apply DB --remote # (confirm)
131
112
  npx astro build
132
113
  npx wrangler deploy --tag "$(git rev-parse --short HEAD)" --message "Initial deploy" # (confirm)
133
- printf %s "$(grep ^FORM_SIGNING_SECRET= .dev.vars | cut -d= -f2-)" | npx wrangler secret put FORM_SIGNING_SECRET # (confirm)
134
- printf %s "$(grep ^POSTMARK_SERVER_TOKEN= .dev.vars | cut -d= -f2-)" | npx wrangler secret put POSTMARK_SERVER_TOKEN # Postmark transport only
135
- # + TURNSTILE_SECRET_KEY if used
136
114
  ```
137
- Use a *different* `FORM_SIGNING_SECRET` in production than in dev if you like. It only has to be random, 32+ characters, and stable. Rotating it invalidates tokens that are already open in visitors' browsers.
115
+ Secrets were set by `cloudflare-init` and survive deploys. Postmark transport only: `printf %s "$(grep ^POSTMARK_SERVER_TOKEN= .dev.vars | cut -d= -f2-)" | npx wrangler secret put POSTMARK_SERVER_TOKEN` (confirm). Rotating `FORM_SIGNING_SECRET` invalidates tokens that are already open in visitors' browsers.
138
116
 
139
- Note: on the first deploy, wrangler may auto-provision resources that are declared without IDs, such as the adapter's `SESSION` KV namespace. That's expected. Mention it in the report.
140
-
141
- ✅ `bash scripts/verify-site.sh https://acme-site.<sub>.workers.dev --no-www-check`. Expect robots, sitemap and canonical warnings pointing at the production URL; that's correct. The form token endpoint should return 200.
117
+ ✅ `bash scripts/verify-site.sh https://acme.<sub>.workers.dev --no-www-check`. Expect robots, sitemap and canonical warnings pointing at the production URL; that's correct. The form token endpoint should return 200.
142
118
 
143
119
  ## 8. Get the zone onto Cloudflare
144
120
 
@@ -163,7 +139,12 @@ Custom domains create the DNS record and certificate automatically. They **fail
163
139
 
164
140
  Then build and deploy again. Add a www→apex redirect (or the reverse) as described in `zone-settings.md` → "Canonical host redirect". Using both hosts as custom domains plus a redirect rule is the simplest setup that gets an edge certificate on both.
165
141
 
166
- Set `"workers_dev": false` if the client shouldn't have a second public copy of the site. Keep `preview_urls` if you use version previews.
142
+ Then finish what `cloudflare-init` left for launch (confirm each):
143
+ - Add `acme.com` and `www.acme.com` to the Turnstile widget `acme` (`forms-email-turnstile.md`).
144
+ - Run `npx wrangler email sending enable acme.com`, and lock the `EMAIL` binding to `"allowed_sender_addresses": ["web@acme.com"]`.
145
+ - Switch `production-url` in `.github/workflows/leyline-update.yml` to `https://acme.com`.
146
+
147
+ Keep `"workers_dev": true` and `preview_urls` on Leyline sites. The update pipeline tests previews on them, and Leyline serves the workers.dev host with `X-Robots-Tag: noindex`.
167
148
 
168
149
  ## 10. Zone settings (confirm)
169
150
 
@@ -63,7 +63,7 @@ There's also a query API (`/accounts/{account}/workers/observability/telemetry/q
63
63
  ```bash
64
64
  curl -sS https://api.cloudflare.com/client/v4/graphql -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" -H 'Content-Type: application/json' --data '{
65
65
  "query":"query($a:String!,$s:String!,$from:Date!){viewer{accounts(filter:{accountTag:$a}){workersInvocationsAdaptive(limit:31,filter:{scriptName:$s,date_geq:$from},orderBy:[date_ASC]){sum{requests errors} dimensions{date}}}}}",
66
- "variables":{"a":"'"$CLOUDFLARE_ACCOUNT_ID"'","s":"acme-site","from":"2026-09-01"}}' | jq
66
+ "variables":{"a":"'"$CLOUDFLARE_ACCOUNT_ID"'","s":"acme","from":"2026-09-01"}}' | jq
67
67
  ```
68
68
  The token needs Account Analytics Read.
69
69
  - Zone-level traffic (all hostnames, cache ratio, countries): `httpRequests1dGroups` on `zones(filter:{zoneTag:…})`.
@@ -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
@@ -0,0 +1,101 @@
1
+ ---
2
+ name: cloudflare-init
3
+ version: 1.0.0
4
+ description: Provision the Cloudflare resources for a new Theory Digital / Leyline site before its domain is set up, with standard names. Creates the Worker, D1, SESSION KV, R2 media (EmDash), Turnstile widget, rate-limit namespace, Worker secrets and Workers Builds triggers, and writes the site's wrangler.jsonc. Static site by default; pass --emdash for an EmDash site. Use whenever the user is starting, setting up, bootstrapping or provisioning a new site or project on Cloudflare, or asks which names a new site's Worker, database or bucket should have.
5
+ ---
6
+
7
+ # cloudflare-init
8
+
9
+ A new site's Cloudflare setup is done by one idempotent script, not by hand. That keeps names and settings identical across projects. Everything that needs the domain (zone, DNS, routes, Email Sending onboarding, the production Turnstile hostname) happens later, at launch, with the `cloudflare` skill (`references/launch-new-site.md`, phases 8–11).
10
+
11
+ ```bash
12
+ node <skill-dir>/scripts/cloudflare-init.mjs <slug> [--emdash] [--dir <site repo>] # plan (read-only)
13
+ node <skill-dir>/scripts/cloudflare-init.mjs <slug> [--emdash] [--dir <site repo>] --apply # do it
14
+ ```
15
+
16
+ Run it with no arguments, or with `--help`, for every option.
17
+
18
+ ## 1. Pick the slug
19
+
20
+ Everything is named from one slug, so get it right first and confirm it with the user.
21
+
22
+ - Use the client's **brand** words in kebab-case, not the domain: `access-matting`, `rig-mats-alberta`, `house-of-xm`, `plainsman-mfg`. Domains change (landbouw launched as landbouwcivil.com), and a domain isn't known yet anyway.
23
+ - Lowercase `a-z0-9`, single hyphens between words, at most 40 characters. Keep abbreviations the way the brand writes them (`mfg`, `xm`). Don't add `-site`, `-web` or a TLD.
24
+ - The GitHub repo should be `Theory-Digital/<slug>` too. If the repo already exists under another name, pass `--repo`.
25
+
26
+ ## 2. Naming standard
27
+
28
+ The script enforces this standard; it is listed here so you can answer naming questions without running it.
29
+
30
+ | Thing | Name | Example |
31
+ |---|---|---|
32
+ | Worker | `<slug>` | `access-matting` → `access-matting.theory-digital.workers.dev` |
33
+ | D1 (binding `DB`) | `<slug>-db` | `access-matting-db` |
34
+ | KV (binding `SESSION`) | `<slug>-session` | `access-matting-session` |
35
+ | R2 (binding `MEDIA`, EmDash only) | `<slug>-media` | `access-matting-media` |
36
+ | Turnstile widget | `<slug>` | `access-matting` |
37
+ | Rate limit (binding `FORM_RATE_LIMITER`) | `namespace_id` = 1 + the highest in the account | `1004` |
38
+ | Workers Builds triggers | `Deploy production`, `Preview other branches` | |
39
+ | GitHub repo | `Theory-Digital/<slug>` | |
40
+
41
+ The rule: the Worker is the slug, and every resource is `<slug>-<binding in lowercase>`. Binding names are fixed by Leyline and the Astro adapter.
42
+
43
+ **Near-miss guard.** The script compares names with `-`/`_` stripped against every existing Worker, D1, KV, R2, Turnstile widget and `Theory-Digital` repo. If anything matches without being the exact standard name (`accessmatting` vs `access-matting`, or a D1 called `<slug>` instead of `<slug>-db`), it stops with `CLASH` (exit 3). Don't reach for `--allow-similar` by reflex. Tell the user what clashed. Usually either the slug is wrong or the project already exists. Only pass the flag once they've decided.
44
+
45
+ ## 3. Defaults and what gets created
46
+
47
+ | | Static (default) | `--emdash` |
48
+ |---|---|---|
49
+ | Compatibility | today's date, no flags | today's date, `nodejs_compat` |
50
+ | Entry | adapter default | `main: ./src/worker.ts` (written from `assets/worker.emdash.ts` if missing) + cron `* * * * *` for scheduled publishing |
51
+ | D1 `<slug>-db` | form submissions | EmDash content + form submissions |
52
+ | KV `<slug>-session` | ✓ | ✓ |
53
+ | R2 `<slug>-media` | — | ✓ |
54
+ | Email Sending `EMAIL` | binding, no sender allow-list until launch | same |
55
+ | Turnstile `<slug>` (managed) | ✓ unless `--no-turnstile` | same |
56
+ | Rate limit `FORM_RATE_LIMITER` (5/60s) | ✓ | ✓ |
57
+
58
+ On both variants:
59
+ - **Account**: Theory Digital (`cfb16515b630dbcddca02b1f6a2585ca`, Kyle@theorydigital.ca's Account). `--account` is for a client-owned account; confirm the ID with the user first.
60
+ - **Location**: D1 and R2 use `wnam` (closest to Alberta). Use `--location` only when the audience is elsewhere. It can't be changed after creation.
61
+ - **Worker**: if missing, a placeholder (503, `noindex`) is uploaded with the real bindings, `workers_dev`, `preview_urls` and observability. Secrets and Builds need the Worker to exist, and its live bindings reserve the rate-limit ID. The site's first build replaces the placeholder; secrets survive it.
62
+ - **Secrets**: `FORM_SIGNING_SECRET` (random) and `TURNSTILE_SECRET_KEY` (from the widget) go straight to the Worker and are never printed.
63
+ - **Local files** in `--dir`:
64
+ - `wrangler.jsonc`, from `assets/wrangler.jsonc`. An existing file that differs is diffed and kept unless you pass `--write-config`.
65
+ - `.dev.vars`, if missing, with a separate dev signing secret and Cloudflare's Turnstile test secret.
66
+ - **Workers Builds**:
67
+ - Turns the previews beta off.
68
+ - Creates "Deploy production" (`main`: `npm run build` / `npx wrangler d1 migrations apply DB --remote && npx wrangler deploy`) and "Preview other branches" (everything but `main`: `npm run build` / `npx wrangler versions upload`), with build cache on.
69
+ - Sets `NPM_TOKEN` as a secret on both.
70
+ - The repo connection and the account's build token are reused.
71
+ - **Turnstile domains**: `<slug>.theory-digital.workers.dev` and `theory-digital.workers.dev` (preview hosts). The production hostname is added at launch.
72
+
73
+ ## 4. Flow
74
+
75
+ 1. **Inputs.** Get the slug (§1), static or EmDash, and the site repo path. Ask only if the user hasn't said. The repo needs a `package.json`; otherwise the local files are skipped.
76
+ 2. **Credentials** (check, never echo):
77
+ - `[ -n "$CLOUDFLARE_TOKEN" ] && echo set` is the TD shell convention. `CLOUDFLARE_API_TOKEN` overrides it.
78
+ - The token must be **user-owned** (the Builds API rejects account tokens) with edit on Workers Scripts, D1, Workers KV, Workers R2, Turnstile and Workers Builds Configuration.
79
+ - `NPM_TOKEN` (npm read token for `@theory-digital`) must be exported for the Builds env var.
80
+ - `gh auth status` must pass for the repo checks.
81
+ 3. **Plan.** Run without `--apply`. Show the user the plan: names, what's `create` vs `exists`, the rate-limit ID, and any `CLASH`/`SKIP` lines.
82
+ 4. **Apply** after the user says yes: the same command plus `--apply`. Creating Cloudflare resources is a write to the account, so the plan → yes → apply order is not optional.
83
+ 5. **Finish what was skipped.** Builds skip when the repo doesn't exist yet or `NPM_TOKEN` isn't exported. Once fixed, re-run with `--only builds --apply`. Re-running is always safe: existing resources are reused, never recreated.
84
+ 6. **Report and hand off.**
85
+ - The script prints a ready-to-paste `docs/sites.md` entry and next steps: copy Leyline's form migrations, commit `wrangler.jsonc`, push to `main` for the first build, then enrol in Leyline updates (`docs/sites.md`, "Enrolling a site").
86
+ - Relay those steps, along with any `!` warnings it printed.
87
+
88
+ ## 5. Not covered here
89
+
90
+ - Domain, zone, DNS, routes or custom domains, Email Sending onboarding and the sender allow-list, the zone launch baseline: the `cloudflare` skill at launch.
91
+ - Postmark: an external service. The default transport is Cloudflare Email Sending. If a client needs Postmark, add `POSTMARK_SERVER_TOKEN` with `wrangler secret put` and drop the `EMAIL` binding.
92
+ - `IMAGES`: the Astro adapter adds the binding itself.
93
+ - Staging Workers, and moving or renaming an existing site's resources.
94
+
95
+ ## Troubleshooting
96
+
97
+ - `token check failed`: the token is missing, expired, or can't see the account. Check `bash <cloudflare-skill>/scripts/cf-api.sh GET /user/tokens/verify`.
98
+ - `10000 Authentication error` on one step: the token lacks that product's permission. Add it to the token and re-run; finished steps are skipped.
99
+ - `Builds API ... Invalid token`: the token is account-owned. Use a user-owned one.
100
+ - Several build tokens: pass `--build-token <uuid>` (the script lists them).
101
+ - A step's API shape changed: the Builds API reference is at `https://developers.cloudflare.com/workers/ci-cd/builds/api-reference/index.md`.
@@ -0,0 +1,4 @@
1
+ interface:
2
+ display_name: "Cloudflare Init"
3
+ short_description: "Provision a new Leyline site's Cloudflare resources with standard names"
4
+ default_prompt: "Use $cloudflare-init to plan the Cloudflare resources for this new site, then apply after I confirm."
@@ -0,0 +1,15 @@
1
+ // Uploaded by cloudflare-init so the Worker exists (for secrets and Workers Builds) before the
2
+ // site's first build. The first `wrangler deploy` from Workers Builds replaces it; secrets stay.
3
+ export default {
4
+ fetch() {
5
+ return new Response('This site has not been deployed yet.\n', {
6
+ status: 503,
7
+ headers: {
8
+ 'content-type': 'text/plain; charset=utf-8',
9
+ 'cache-control': 'no-store',
10
+ 'retry-after': '3600',
11
+ 'x-robots-tag': 'noindex',
12
+ },
13
+ });
14
+ },
15
+ };
@@ -0,0 +1,10 @@
1
+ // Worker entry for an EmDash site (wrangler.jsonc "main"): the Astro/EmDash handler, plus the
2
+ // scheduled handler that the cron trigger runs for scheduled publishing and cleanup.
3
+ import handler, { createScheduledHandler, PluginBridge } from '@emdash-cms/cloudflare/worker';
4
+
5
+ export { PluginBridge };
6
+
7
+ export default {
8
+ ...handler,
9
+ scheduled: createScheduledHandler(),
10
+ } satisfies ExportedHandler;