@a2f0/agent-tool 0.1.68 → 0.1.70

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.
@@ -0,0 +1,196 @@
1
+ # Audit usage receipts
2
+
3
+ This procedure applies to any repository audited with audit-trails. It measures
4
+ the audit workflow, not the instruction file's size. Use the
5
+ [report template](report-template.md#audit-usage-receipt) even when all usage is
6
+ unavailable. It does not authorize an audit, model call, issue, or disclosure.
7
+
8
+ ## Start and checkpoint
9
+
10
+ Before work or delegation, create a private checkpoint beside the local report
11
+ (outside the checkout by default). Use a fresh opaque run ID, such as a UUID,
12
+ not a provider session ID. Record:
13
+
14
+ - Run ID and batch ID, start time, full/batch/resumed scope and requested focus.
15
+ - Audited repository and full commit, dirty-path treatment, the audit-trails
16
+ version (the `agentToolVersion` in `.agent-tool-skills.json`) or hashes of
17
+ the loaded skill and references, harness name/version, provider/model and
18
+ effort when exposed; mark missing metadata unavailable.
19
+ - Usage source and its documented semantics, dedicated run identity or the
20
+ before counters and last completed request boundary. Keep raw identities,
21
+ source paths and evidence private; publish only sanitized provenance/digests.
22
+ - Expected coordinator, children, auxiliary model calls and terminal-launched
23
+ CLI auditors, with each source's inclusion in parent totals (or unknown).
24
+ - Report path, canonical issue URL if already published, receipt run marker,
25
+ last verified body and pending update. Do not discard these on interruption.
26
+
27
+ Prefer dedicated run counters. In a mixed session take before/after snapshots;
28
+ if isolation is impossible, say shared-session usage is not attributable to the
29
+ audit. A missing baseline cannot be retroactively invented. At each coverage
30
+ checkpoint and before stopping, save available counters, measured cutoff,
31
+ completed/partial/interrupted status, and remaining scope.
32
+
33
+ Resume the same run with a new batch ID and baseline. Keep prior batches; record
34
+ revision, harness, or model changes and revalidate affected findings. Deltas
35
+ must have disjoint request boundaries. Never add cumulative snapshots from
36
+ multiple resumes as if they were separate runs. Counter resets or changed
37
+ semantics require separate rows, not negative deltas or silent correction.
38
+
39
+ ## Evidence and accounting
40
+
41
+ Use actual harness/provider-reported input/output tokens, cache-read/cache-write,
42
+ reasoning, API-call counts, and duration when exposed. Keep native field names
43
+ and semantics in the evidence; distinguish wall-clock elapsed time from a
44
+ provider's duration. Missing/null fields mean unavailable, not zero. Even a
45
+ numeric zero is not proof of measurement if that harness defaults missing
46
+ provider usage to zero; disclose that source limitation.
47
+
48
+ Do not infer runtime consumption from skill bytes, context size estimates,
49
+ model guesses, agent-tool command duration/log bytes, or a subscription meter.
50
+ Static load size, if useful, belongs in a separately labeled estimate, never
51
+ in the usage total. Optional dollar estimates are neither subscription charges
52
+ nor quota usage.
53
+
54
+ For the installed harness, verify its help and source/schema before naming a
55
+ collector. Do not guess Claude/Codex transcript paths or counter fields; if no
56
+ verified source is exposed, publish `unavailable (no verified usage source)`.
57
+ No new accounting CLI is required by this skill. A demand for exact counters
58
+ that the harness does not expose is a tooling blocker, not permission to
59
+ invent numbers or build a per-repository runtime collector.
60
+
61
+ ### Verified Hermes source
62
+
63
+ An outer launcher can use `hermes -z "$task" --usage-file "$usage_file"` for an
64
+ already authorized child run; the file is written after the run returns, not
65
+ while its final request is still running. Check the installed
66
+ `hermes_cli/oneshot.py` writer and [CLI reference][hermes] for the actual
67
+ version. The fields below were checked against [Hermes
68
+ v0.22.5+2418.g8209674][hermes-source]; verify them again after upgrades.
69
+ One-shot mode bypasses approval prompts: do not switch a live audit
70
+ to it or launch another audit merely to obtain usage. Its execution policy
71
+ needs separate authorization.
72
+
73
+ The writer copies `input_tokens`, `output_tokens`, `cache_read_tokens`,
74
+ `cache_write_tokens`, `reasoning_tokens`, `total_tokens`, `api_calls`, `model`,
75
+ `provider`, `session_id`, `completed`, `partial`, `interrupted`, and
76
+ `turn_exit_reason`. Keep session IDs and free-text failure details private.
77
+ When present, `auxiliary.by_task` breaks down auxiliary calls, and
78
+ `total_including_auxiliary` includes them already: never add it to main or
79
+ auxiliary totals. Those fields alone do not establish child coverage, per-model
80
+ breakdowns, effort, or duration; mark unexposed dimensions unavailable.
81
+
82
+ ### Combine only proven nonoverlapping coverage
83
+
84
+ - Keep coordinator, delegated children, auxiliary calls, and external CLI
85
+ auditors identifiable. External CLI auditors need their own receipts; a
86
+ terminal invocation's elapsed time is not their token usage.
87
+ - Deduplicate repeated assistant events by provider request identity. Keep raw
88
+ IDs private. For cumulative sources use differences, not sums of snapshots.
89
+ - Do not add child usage already rolled into the parent. When inclusion is
90
+ unknown, show separate non-additive rows and explain why no total is valid.
91
+ - Cache and reasoning may be subfields of input/output. Do not add them to
92
+ totals without verified provider semantics. Preserve native totals rather
93
+ than imposing an incompatible token formula.
94
+ - Group by provider/model when switched; if the source only labels the final
95
+ model, call its aggregate mixed/unattributed instead of assigning it all to
96
+ that model. Sum batches only with matching semantics and disjoint coverage.
97
+ - Partial measurements are measurable subtotals, never a workflow grand total.
98
+ Name every missing participant/field and exclude it explicitly.
99
+
100
+ ## Cutoff, not an imaginary final bill
101
+
102
+ A live coordinator cannot see its own post-exit receipt. Freeze the receipt at
103
+ the last completed provider request **before publication** and label that
104
+ cutoff and timestamp. Exclude the in-flight request, publication work and final
105
+ reply, plus anything else not observable. Save what is available at checkpoints
106
+ so an interrupted audit can still report partial usage.
107
+
108
+ Alternatively, an authorized outer launcher can reconcile the same receipt
109
+ after the audited child exits. Include the child's observable tail, but keep
110
+ unmeasured launcher/publication costs excluded. Never recursively invoke the
111
+ audit to produce a receipt or promise an exact final bill inside that run.
112
+
113
+ ## Publish and resume
114
+
115
+ Publish the receipt **in the report body**. This avoids a second comment write
116
+ and a race with bot comments; there is no receipt comment ID. Partial audits,
117
+ zero findings, and unavailable counts still need the section. Retain the existing
118
+ issue-publication and security-disclosure gates. Without authorization, save
119
+ the report and receipt locally, and report that publication was not authorized.
120
+ Allowlist only sanitized run/batch IDs, repository/revision, versions/hashes,
121
+ model/provider/effort, counters, timestamps, outcome and coverage descriptions.
122
+ No secrets, credentials, raw prompts/transcripts, request payloads, production
123
+ rows, private paths/hostnames, raw session/request IDs or free-text failures.
124
+ Review the entire public body, not just the receipt, before sending.
125
+
126
+ The examples require GitHub CLI, jq, and a POSIX shell.
127
+ Set `repo` to the resolved repository, `title` to the report title, `body_file`
128
+ to the private sanitized complete report, and `receipt_dir` to its private
129
+ checkpoint directory. Run snippets with `sh -eu` (or equivalent fail-fast
130
+ handling). They are alternatives/steps, not one script to run indiscriminately.
131
+
132
+ Only for a new authorized report with no previously created issue:
133
+
134
+ ```sh
135
+ gh issue create --repo "$repo" --title "$title" --body-file "$body_file" \
136
+ > "$receipt_dir/issue-url.txt"
137
+ IFS= read -r issue_url < "$receipt_dir/issue-url.txt"
138
+ ```
139
+
140
+ Immediately save the returned URL as `issue_url` in the checkpoint, before any
141
+ later action. For a resumed/existing report use its recorded canonical URL.
142
+ Read back that exact issue after creation and after every edit:
143
+
144
+ ```sh
145
+ gh issue view "$issue_url" --repo "$repo" --json url,number,body \
146
+ > "$receipt_dir/issue-candidate.json"
147
+ jq -e --arg url "$issue_url" --rawfile expected "$body_file" \
148
+ '.url == $url and .body == $expected' "$receipt_dir/issue-candidate.json" > /dev/null
149
+ mv "$receipt_dir/issue-candidate.json" "$receipt_dir/issue-readback.json"
150
+ ```
151
+
152
+ Inspect the returned canonical URL/repository/number and compare the decoded
153
+ `body` exactly with the intended complete body, including both run markers and
154
+ the receipt. A successful write command alone is not verified publication.
155
+ The snippets compare the URL and decoded body, and only then promote the
156
+ candidate to the last-verified checkpoint. A failed read or mismatch leaves
157
+ previous verified evidence intact. Keep one publisher per private directory.
158
+ Record the canonical URL plus `audit-usage:RUN_ID` as the receipt handle; location
159
+ is the issue body, comment URL/ID not applicable.
160
+
161
+ For an authorized resume/retry, read the latest issue body first, replace only
162
+ that run's `<!-- audit-usage:RUN_ID:begin -->` through matching end marker,
163
+ and preserve other runs and unrelated edits. If absent, append that run's
164
+ section once; ambiguous or duplicate markers require manual reconciliation,
165
+ not an overwrite. Serialize publishers for the same issue, recheck the latest
166
+ body before writing, and reconcile concurrent changes instead of blindly
167
+ sending a stale local body. Do not overwrite another run's receipt. Save the
168
+ reconciled full body privately, then edit the existing issue and read back:
169
+
170
+ ```sh
171
+ gh issue edit "$issue_url" --repo "$repo" --body-file "$body_file"
172
+ gh issue view "$issue_url" --repo "$repo" --json url,number,body \
173
+ > "$receipt_dir/issue-candidate.json"
174
+ jq -e --arg url "$issue_url" --rawfile expected "$body_file" \
175
+ '.url == $url and .body == $expected' "$receipt_dir/issue-candidate.json" > /dev/null
176
+ mv "$receipt_dir/issue-candidate.json" "$receipt_dir/issue-readback.json"
177
+ ```
178
+
179
+ On any failed/ambiguous write or readback, retain the intended body, run marker,
180
+ known URL and last verified state locally; report **incomplete publication**.
181
+ Recover an uncertain create by finding the existing issue and checking its
182
+ exact run marker before retrying; never blindly rerun create. A failed receipt
183
+ update must not create another report issue. If an older report used a receipt
184
+ comment, retain its recorded comment ID/URL and reconcile that exact receipt
185
+ before changing placement; never use `--edit-last` to guess ownership.
186
+
187
+ Sources: GitHub CLI [create][create], [edit][edit], and [view][view]. The shell
188
+ examples are exercised with a stub CLI in agent-tool's tests
189
+ (`src/skills/auditTrails.test.ts`); they do not open real issues or execute
190
+ audits.
191
+
192
+ [hermes]: https://hermes-agent.nousresearch.com/docs/reference/cli-commands
193
+ [hermes-source]: https://github.com/NousResearch/hermes-agent/blob/820967473d4d5b6777d3a9419def4be422711d16/hermes_cli/oneshot.py
194
+ [create]: https://cli.github.com/manual/gh_issue_create
195
+ [edit]: https://cli.github.com/manual/gh_issue_edit
196
+ [view]: https://cli.github.com/manual/gh_issue_view
@@ -0,0 +1,162 @@
1
+ ---
2
+ name: seo-optimization
3
+ description: Audit and improve how a repository's websites appear in search results and link previews, covering titles, descriptions, canonical URLs, Open Graph, structured data, robots.txt, sitemaps, status codes, and keeping non-production tiers out of search indexes. Use for an SEO audit or optimization pass, not copywriting or general feature work.
4
+ ---
5
+
6
+ # SEO Optimization
7
+
8
+ Make every production page say what it is in the HTML that is served
9
+ before JavaScript runs, name one canonical URL, and be discoverable through
10
+ robots.txt and a sitemap. Keep every non-production tier out of search
11
+ indexes. Judge the deployed result, not the source: a correct template that
12
+ never reaches the live response is not a fix.
13
+
14
+ ## Establish scope
15
+
16
+ Read the repository's instructions and the docs they point to, including
17
+ setup, validation, versioning, deployment, and title policy. Use the user's
18
+ scope. A report-only request stays read-only. An optimization pass may make
19
+ reversible changes in the repository and ship them through its normal
20
+ workflow when shipping is authorized; existing explicit authorization still
21
+ applies, so do not ask for it again. On a repeat pass, read the previous SEO
22
+ change and its docs, keep the decisions it recorded, and re-check what it
23
+ called compliant against the current standard; when it left no change,
24
+ audit from scratch.
25
+
26
+ This skill does not by itself authorize DNS changes, zone or CDN settings,
27
+ search console registration, store listings, or production content rewrites.
28
+ Write titles and descriptions from copy the site or repository already has.
29
+ Never invent product claims, platforms, prices, ratings, or reviews, and never
30
+ add links to store pages that are not live.
31
+
32
+ ## Inventory hosts
33
+
34
+ List every public hostname the repository serves, by tier, from hosting
35
+ configuration (for example `wrangler.jsonc` routes), infrastructure code,
36
+ deploy workflows, and docs. Classify each one:
37
+
38
+ - **content**: marketing site, landing page, resume, or documentation that
39
+ should rank. A standalone web tool with no separate marketing site is a
40
+ content host for its landing page.
41
+ - **app**: an interactive application or app shell, often `app.*` or
42
+ `demo.*`, whose marketing lives elsewhere.
43
+ - **internal**: admin dashboard, asset gallery, or API host. A package's
44
+ viewer or demo site, whose pages other sites copy, is internal unless the
45
+ repository or the user says it should rank; ask when it is unclear.
46
+ - **non-production**: staging, preview, or any other tier that is not the
47
+ production site.
48
+
49
+ For each host, find how it is built and deployed. Note whether each tier has
50
+ its own build or one artifact is promoted, whether a merge deploys or a
51
+ person runs a command, and whether a Worker or server script answers some
52
+ responses itself. These facts decide where a tier-specific header can live.
53
+ Include hosts the platform adds on its own, such as `*.workers.dev` and
54
+ per-version preview URLs, which serve duplicate copies of the site.
55
+
56
+ Probe each host's current state with `agent-tool seo probe`, run through the
57
+ repository's pinned agent-tool: `bun run agent-tool seo probe <host> [path]`,
58
+ or `node_modules/.bin/agent-tool seo probe <host> [path]` where there is no
59
+ package script. It reports a page's title, description, canonical, robots
60
+ meta, `X-Robots-Tag`, Open Graph and Twitter tags, preview image, JSON-LD
61
+ types, and h1 count, then the site's robots.txt, sitemap, missing path, and
62
+ `http://` behavior. `--page` skips the site files;
63
+ `--headers <host> <path>...` prints one line per path without following
64
+ redirects, for checking headers on assets, redirects, and errors; `--links`
65
+ lists the page's internal links that do not answer 200 directly; and
66
+ `--sitemap` checks every sitemap URL's status, canonical, and robots, and
67
+ reports duplicate titles and descriptions. The mode flag comes first, the
68
+ host is a hostname with an optional port, and each path starts with `/`. The
69
+ probe matches with regular expressions, so confirm anything surprising in the
70
+ raw response before acting on it. Set `SEO_PROBE_USER_AGENT` to a browser user
71
+ agent to see what a zone injects only for browsers.
72
+
73
+ Check whether the default branch already has merged work that has not been
74
+ deployed, because a deploy ships it too. Deployment listings often do not
75
+ name a commit. The strongest check is to build the default branch with
76
+ production settings and compare its files with the live ones byte for byte;
77
+ otherwise compare deploy times with merge times (for CI deploys, the head
78
+ commit of the deploy runs), read a version marker in the live HTML or bundle,
79
+ or run the repository's deploy verifier read-only. A deploy may also apply
80
+ database migrations; list pending ones read-only first.
81
+
82
+ ## Apply the standard
83
+
84
+ Apply [references/standard.md](references/standard.md), which holds the
85
+ checklist for each host class; read "Every host" and the sections for the
86
+ classes you found. Its outcomes, in one line each:
87
+
88
+ - **Non-production**: noindex on every response and page, crawlable, no
89
+ canonical or sitemap. Production is never noindexed, except its error page
90
+ and paths deliberately kept out of search.
91
+ - **Content**: complete static head, preview image, structured data,
92
+ robots.txt, sitemap, and real 404s.
93
+ - **App**: descriptive shell metadata and a real robots.txt; a canonical only
94
+ when routes are not distinct public content.
95
+ - **Internal**: noindex for HTML surfaces; API hosts only when trivial.
96
+
97
+ Platform specifics live in
98
+ [references/cloudflare-workers.md](references/cloudflare-workers.md) (static
99
+ asset headers, trailing slashes, not-found handling, Cloudflare's managed
100
+ robots.txt) and [references/frameworks.md](references/frameworks.md) (Astro,
101
+ Next.js static export, Vite single-page apps, Bun's HTML bundler,
102
+ react-native-web, service workers, and `agent-tool images` for preview
103
+ images). Read the sections that match the repository.
104
+
105
+ Keep changes proportionate: metadata, robots, sitemaps, status codes, and
106
+ light heading or `alt` fixes on pages you touch. Record larger work, such as
107
+ prerendering JavaScript-only content, performance refactors, localized URL
108
+ trees, or redirects that need DNS, as recommendations.
109
+
110
+ ## Validate and verify
111
+
112
+ Run the repository's full documented validation. Build every tier you
113
+ changed and inspect its output: each HTML `<head>`, `_headers` or equivalent,
114
+ robots.txt, the sitemap, and the preview image. Add tests where the
115
+ repository has a natural place for them:
116
+
117
+ - metadata is present in the static HTML with JavaScript disabled;
118
+ - the non-production build carries noindex and the production build does not;
119
+ - every sitemap URL equals the canonical URL of the page it lists;
120
+ - every internal link answers without a redirect;
121
+ - an unknown path returns 404 when served by the real hosting runtime, not a
122
+ development server that answers every path with the app, and the error
123
+ page's own URL (such as `/404`) carries noindex.
124
+
125
+ Before changing a title or description, search the tests for the old text.
126
+ Shell snippets added to docs must not use `path` as a variable name, because
127
+ zsh ties it to `PATH`.
128
+
129
+ After deploying, probe every host on every tier; the probe adds a
130
+ cache-busting query. Confirm that production carries no noindex in headers or
131
+ markup, that the preview image at the URL the page names answers 200 with an
132
+ image type and the declared size, and that every sitemap URL answers 200
133
+ without a redirect. Confirm that each non-production host sends the header
134
+ on HTML, assets, fallbacks, and redirects. Record what the CDN did to
135
+ robots.txt.
136
+
137
+ ## Report
138
+
139
+ Use the repository's report convention, or put the evidence in the PR and
140
+ the final summary:
141
+
142
+ - hosts with their classification and live result, per tier;
143
+ - the changes made, and what was deliberately left unchanged, with reasons;
144
+ - recommendations ordered by impact, with an owner or the decision they need;
145
+ - questions that only the user can answer, such as whether user-generated
146
+ public pages should be indexable, or which URL form legal pages should use.
147
+
148
+ Out-of-scope items belong in recommendations unless the user authorizes
149
+ them: search console and Bing Webmaster verification and sitemap submission,
150
+ infrastructure changes such as `www` redirects and zone settings (see
151
+ [references/cloudflare-workers.md](references/cloudflare-workers.md)), CDN
152
+ robots and AI-crawler settings, store links and smart app banners before
153
+ store IDs exist, app association files, and content or performance work.
154
+ Keep reusable procedure in this skill and dated findings in the report.
155
+
156
+ ## Ownership
157
+
158
+ agent-tool (`a2f0/agent-tool`) owns this skill in `skills/seo-optimization/`,
159
+ and the `seo probe` command with its tests in `src/seo/`. Repositories get
160
+ the skill from `agent-tool skills install --apply`; do not edit the installed
161
+ copy. Change it in agent-tool by PR. A repository's hosts, tiers, and deploy
162
+ checks belong in its own docs.
@@ -0,0 +1,4 @@
1
+ interface:
2
+ display_name: "SEO Optimization"
3
+ short_description: "Audit and fix search metadata and staging noindex"
4
+ default_prompt: "Use $seo-optimization to audit this repository's websites and fix their search and link-preview metadata, keeping staging out of search."
@@ -0,0 +1,211 @@
1
+ # Cloudflare Workers hosting
2
+
3
+ Check these against the current
4
+ [static assets documentation](https://developers.cloudflare.com/workers/static-assets/)
5
+ when behavior matters; wrangler versions change details. Everything here was
6
+ observed on live Workers in 2026 with wrangler 4.
7
+
8
+ ## Static asset headers
9
+
10
+ - `_headers` in the assets directory applies to every hostname of that
11
+ Worker. A tier-specific header therefore needs a tier-specific build, or a
12
+ deploy step that writes the file for each environment.
13
+ - Rules are keyed by path pattern, so a second block with the same pattern
14
+ replaces the first block's headers instead of adding to them. Appending a
15
+ separate `/*` noindex block can silently drop security or cache headers;
16
+ add `X-Robots-Tag` inside the existing `/*` rule.
17
+ - Rules with different patterns merge. When two matching rules set the same
18
+ header, the response carries it twice, so do not add a path rule for a
19
+ header that `/*` already sets on that tier. `/x/*` matches `/x/` and below
20
+ but not `/x`; add both patterns to cover the redirecting form.
21
+ - A `/*` rule reaches everything the asset handler answers: HTML, assets,
22
+ the `html_handling` 307 redirects, single-page fallbacks, 404 responses,
23
+ and robots.txt, including the zone's managed robots.txt when the origin has
24
+ none.
25
+ - `_headers` does not apply to responses a Worker script generates, such as
26
+ its own redirects, sign-in pages, or dynamic routes. A Worker with a `main`
27
+ script needs the header set in code, driven by a tier variable in the
28
+ wrangler `env`. With `run_worker_first: true`, `_headers` never applies;
29
+ set the header in one wrapper around the router so every response gets it.
30
+ - `_headers` itself is never uploaded as an asset or served. Leave it out of
31
+ any deploy check that lists the built files, and out of published packages.
32
+ - An authentication gate redirects robots.txt to the sign-in page unless the
33
+ file is on the gate's public allowlist.
34
+ - `:name` placeholders match exactly one path segment and `*` matches the
35
+ rest. A `! Header-Name` line detaches a header that an earlier matching rule
36
+ set; it only works when it comes after that rule. A file has a limit of 100
37
+ rules, so a build that generates rules per file should fail before reaching
38
+ it.
39
+
40
+ ## URLs and status codes
41
+
42
+ - `html_handling: "auto-trailing-slash"`, the default, answers the other form
43
+ with a 307, so canonical URLs and internal links must use the form that is
44
+ served directly. That form follows the file layout: `page/index.html` is
45
+ served at `/page/`, and a flat `page.html` at `/page`, even when a `page/`
46
+ directory exists; `/page.html` redirects too. `drop-trailing-slash` always
47
+ serves the form without the slash.
48
+ - `not_found_handling: "none"`, the default, answers unknown paths with a 404
49
+ and an empty body. On content hosts, add a `404.html` and switch to
50
+ `"404-page"` so visitors get a helpful page.
51
+ - `"404-page"` serves the nearest `404.html` up the path with status 404,
52
+ including for missing assets such as `/data/x.json`, which then receive
53
+ `text/html`; that is fine for code that checks `response.ok`.
54
+ `/404.html` itself redirects to `/404`, which answers 200, so the error
55
+ page needs a robots noindex, and tests should use a missing path rather
56
+ than the error page's own URL.
57
+ - `"single-page-application"` answers every unknown path with the app shell
58
+ and a 200, a soft 404. It also answers `/robots.txt` and `/sitemap.xml`
59
+ with HTML unless real files exist. Switch to `"404-page"` only when nothing
60
+ depends on client-side routing.
61
+ - With a `main` script, the asset 404 page comes through `env.ASSETS.fetch`,
62
+ while paths routed to the script first keep the script's own 404.
63
+ - A Worker that redirects every unmatched path, for example to keep old app
64
+ links working, also redirects robots.txt and the sitemap. Generate both as
65
+ build assets so the asset handler answers them first.
66
+ - A repository's deploy guard may pin the Worker's asset configuration.
67
+ Update the guard with the change, and run its preview on the exact commit.
68
+
69
+ ## Testing on the real runtime
70
+
71
+ - Development servers such as `vite preview` answer every path with the app,
72
+ so status and header tests must run against `wrangler dev` or a deployed
73
+ Worker. A test that only matches text in the configuration does not prove
74
+ the behavior.
75
+ - A test can spawn `wrangler dev --config <config> --local --ip 127.0.0.1
76
+ --port 0 --inspector-port 0 --persist-to <tmp>
77
+ --show-interactive-dev-session=false`, adding `--assets <build>` when the
78
+ configuration does not name the build directory. `_headers` and the
79
+ configured `not_found_handling` apply, so status codes and the
80
+ non-production `X-Robots-Tag` can be checked end to end. Details that
81
+ matter:
82
+ - spawn it with Node; under `bunx --bun` workerd has been seen to accept
83
+ connections and never answer;
84
+ - strip ANSI codes before matching the `Ready on` line, and keep draining
85
+ stdout and stderr so the pipes do not fill;
86
+ - set `WRANGLER_SEND_METRICS=false` and point `WRANGLER_LOG_PATH` at the
87
+ temporary directory; it still writes a gitignored `.wrangler/tmp`;
88
+ - stop it with SIGTERM, then SIGKILL;
89
+ - prove the test by reverting the setting and watching it fail.
90
+ - `wrangler dev` reloads an edited `_headers` without a restart, which makes
91
+ checking merged rules cheap.
92
+ - Deploying the branch to the non-production tier before merging is a cheap
93
+ way to confirm routing, headers, and status codes on the real runtime.
94
+
95
+ ## Duplicate hosts
96
+
97
+ Every Worker can also answer at `<worker>.<subdomain>.workers.dev` and at
98
+ per-version preview hosts, `<first 8 characters of the version ID>-<worker>.<subdomain>.workers.dev`.
99
+ Both serve full copies of the site.
100
+
101
+ - Set `workers_dev: false` and `preview_urls: false` in every environment
102
+ unless something depends on those URLs: check API base URLs, CORS and
103
+ authentication origins, docs, tests, and CI first.
104
+ - When the configuration has no `routes`, for example because Terraform binds
105
+ the custom domain, wrangler enables `workers_dev` by default. An unset
106
+ `preview_urls` leaves the existing setting alone, so preview hosts can be
107
+ live despite the documented default.
108
+ - When `workers_dev` is on, the deploy output names the `workers.dev` URL;
109
+ probe it and a preview host before and after. With an explicit `false` in
110
+ every environment, a deploy whose output names no `workers.dev` target is
111
+ enough evidence. A disabled or missing Worker on a valid subdomain answers
112
+ error 1042, so a probe cannot tell the two apart. When API credentials are
113
+ already available, the read-only
114
+ `GET /accounts/{id}/workers/scripts/{name}/subdomain` returns `enabled` and
115
+ `previews_enabled`; never read an OAuth token out of wrangler's
116
+ configuration to call it.
117
+
118
+ ## Zone settings and redirects
119
+
120
+ - Zone-wide settings, such as `always_use_https`, belong to exactly one
121
+ Terraform stack, usually production, never a module that both tiers use.
122
+ The Cloudflare provider cannot destroy a `cloudflare_zone_setting`:
123
+ removing it from Terraform leaves the setting as it is.
124
+ - Before turning on Always Use HTTPS, check that nothing depends on plain
125
+ HTTP: API base URLs in web, desktop, and native clients, webhook endpoints
126
+ registered with providers such as Stripe (list them read-only), and OAuth
127
+ or payment return URLs. Providers rarely follow a redirect on a webhook
128
+ POST.
129
+ - A `www` to apex redirect needs no origin: a proxied `AAAA` record for `www`
130
+ with content `100::`, and a `cloudflare_ruleset` in phase
131
+ `http_request_dynamic_redirect` whose rule matches
132
+ `http.host eq "www.<zone>"` and answers 301 with
133
+ `concat("https://<zone>", http.request.uri.path)`, preserving the query
134
+ string. Universal SSL already covers `www`. Single redirects run before
135
+ Workers, so the rule works even while `www` is still a Worker custom
136
+ domain.
137
+ - A zone has one ruleset per phase: extend or import an existing one.
138
+ - The redirect needs the token permission Zone → Single Redirect → Edit
139
+ ("Dynamic URL Redirects Write"). A token without it gets
140
+ `403 request is not authorized` even when reading the phase entrypoint, so
141
+ read it first and stop before writing Terraform the token cannot apply.
142
+ Never widen a token's permissions yourself.
143
+ - When the user authorizes it, the `cf` CLI, signed in as the account owner,
144
+ can create the rule (`cf rulesets entrypoint update
145
+ http_request_dynamic_redirect -z <zone> --name Redirects --rules
146
+ @rules.json`, with `--validate-only` first) and the record
147
+ (`cf dns records create`). Document such configuration in the repository:
148
+ what exists, how to recreate it, and that Terraform must import it later.
149
+ - Repositories whose apply step refuses plans that delete resources need an
150
+ explicit decision before a change that removes a custom domain.
151
+
152
+ ## Cloudflare's managed robots.txt
153
+
154
+ A zone can serve a Cloudflare-managed robots.txt. Observed behavior:
155
+
156
+ - a zone with only the content-signals policy serves a comments-only file
157
+ when the origin has no robots.txt, and the origin file replaces it
158
+ entirely;
159
+ - a zone that also manages AI-crawler rules prepends its block, with
160
+ `Content-Signal` and `Disallow` directives, to the origin file, and serves
161
+ it alone where the origin answers 404;
162
+ - where the origin answers `/robots.txt` with a 404, the managed file is
163
+ served with status 200 and keeps the origin's other headers, including an
164
+ `X-Robots-Tag` from `_headers` or Worker code;
165
+ - a single-page fallback that answers `/robots.txt` with HTML suppresses
166
+ either file.
167
+
168
+ Before serving your own file, record which directives were live, such as
169
+ `Content-Signal` lines or `Disallow` rules for AI crawlers. Keep their effect
170
+ in the origin file, or ask the user. Comments-only managed files carry no
171
+ directives. Do not change the zone setting without explicit authorization.
172
+
173
+ ## Deploys and verification
174
+
175
+ - Merging is not deploying in many repositories: they deploy by hand with an
176
+ existing `wrangler login` session or documented credentials. Check the
177
+ deploy docs and confirm the new version is live. Custom domains owned by
178
+ Terraform make `wrangler deploy` report no targets deployed; that is
179
+ normal.
180
+ - A manual deploy ships everything merged since the last one, so find out
181
+ what is live first, check again just before deploying, and report what else
182
+ went live. Compare pages at the URLs they are served from (`/`, not
183
+ `/index.html`, which redirects with an empty body), and compare with a
184
+ plain client: the zone may inject scripts, such as an analytics beacon,
185
+ only for browser user agents.
186
+ - `wrangler deployments list` shows times and version IDs but usually no
187
+ commit. `_headers` is not served, so compare its rules with live response
188
+ headers rather than bytes. In wrangler's output, "Uploaded N (M already
189
+ uploaded)" counts assets; "Read N files" also counts directories. Passing
190
+ `--message <commit>` to `wrangler deploy` makes later comparisons easy;
191
+ suggest it rather than adding it unasked.
192
+ - A hostname that does not resolve may belong to a Terraform stack that a
193
+ teardown destroyed and no deploy re-applies. Check that stack's state with
194
+ a read-only plan before assuming a DNS fault, and check that the content
195
+ behind it, such as uploaded release files, exists too.
196
+ - A manual deploy can build from gitignored local inputs, such as captured
197
+ screenshots or generated data. Compare them with what is live before
198
+ deploying, so a stale local copy does not regress production.
199
+ - A configuration change to an API Worker, even `workers_dev`, is an API
200
+ release that may pull in migrations, secrets, and infrastructure steps.
201
+ Check pending migrations first (for D1,
202
+ `wrangler d1 migrations list <database> --remote`).
203
+ - Some repositories deploy staging from a branch such as `staging`. Moving it
204
+ is a deploy, so do it only when deploying is authorized and the
205
+ repository's docs name that branch as the staging trigger: fast-forward
206
+ only, never force, and report how far it moved.
207
+ - "Always Use HTTPS" is a zone setting. When `http://` answers 200 instead of
208
+ redirecting, record it rather than changing the zone, and say where the fix
209
+ belongs: Terraform can manage it as a `cloudflare_zone_setting` with
210
+ `setting_id = "always_use_https"`, so check whether the repository or a
211
+ sibling repository already does.