Skip to main content

bynk_syntax/
diagnostics.rs

1//! Central registry of diagnostic codes.
2//!
3//! This is the single source of truth for the `bynk.*` codes the compiler can
4//! emit. The reference page `site/src/content/docs/reference/diagnostics.md` is generated
5//! from [`render_markdown`], and the test `tests/diagnostics_registry.rs`
6//! asserts that this table matches exactly the set of codes used across the
7//! compiler source — so a new code cannot be introduced without documenting it
8//! here, and a removed code cannot linger in the docs.
9//!
10//! Each entry is a `(code, summary)` pair, optionally tagged with the grammar
11//! production(s) it constrains (`grammar_symbol`), and carries a severity
12//! (`Error` unless built via the crate-private `warn` helper). The category
13//! shown in the generated reference is derived from the second dotted segment
14//! of the code; the grammar weave (`docs/grammar-semantics.json`, the
15//! `{{#grammar-semantics}}` directive, and the "Grammar rules" line on each
16//! code's own page) is generated from `grammar_symbol`.
17
18use crate::error::Severity;
19
20/// One documented diagnostic: its stable code and a one-line summary of the
21/// cause. The longer lesson, the cause and the fix with an example, is the
22/// code's [`Explain`] entry.
23pub struct DiagnosticInfo {
24    pub code: &'static str,
25    pub summary: &'static str,
26    /// The grammar production(s) this diagnostic constrains, by `tree-sitter`
27    /// rule name (e.g. `http_handler`). This is the single source of the
28    /// "static semantics" weave: a grammar-reference entry embeds the
29    /// diagnostics for a rule via `{{#grammar-semantics <rule>}}`, generated
30    /// from here. Empty for diagnostics with no single governing construct
31    /// (e.g. `bynk.boundary.structural_mismatch`). Every non-empty name is
32    /// checked against the grammar by `tests/diagnostics_registry.rs`.
33    pub grammar_symbol: &'static [&'static str],
34    /// This code's severity (ADR 0117): `Error` rejects the program; `Warning`
35    /// surfaces but never fails the build. The single source of truth for
36    /// [`crate::error::Severity::for_error`], which looks a code up here
37    /// instead of hardcoding its own copy of the (small) warning set —
38    /// `tests/diagnostics_registry.rs` asserts the two never drift apart.
39    /// Defaults to `Error` via the crate-private `d`/`dg` constructors; only
40    /// the crate-private `warn` helper's call sites override it.
41    pub severity: Severity,
42}
43
44/// The hosted site. No trailing slash: a site-root path (which begins with
45/// `/`) is appended directly.
46pub const BOOK_BASE_URL: &str = "https://bynk-lang.org";
47
48/// The link contract between the toolchain and the site (web presence track,
49/// decision D2, #3876): every diagnostic links as `{BOOK_BASE_URL}/d/<code>`,
50/// and `/d/` alone is the index. The site serves a page for every registry
51/// code behind it and decides where that page lives; the compiler names no
52/// docs page.
53pub const D_PATH: &str = "/d/";
54
55/// A curated, offline-complete explanation of a diagnostic code (#853).
56///
57/// The `blurb`/`example` are the offline answer `bynk explain` prints, and the
58/// text of the code's page on the site ([`render_json`]). Where that page
59/// lives, and which reference sections it links to, belong to the docs
60/// (`site/src/data/diagnostic-links.json`), not to this table (#3876): the
61/// toolchain links every code as [`href`], so a docs reorganisation never
62/// edits the compiler.
63pub struct Explain {
64    /// The diagnostic code this explains. Must be a real [`REGISTRY`] code
65    /// (enforced by `tests/diagnostics_registry.rs`).
66    pub code: &'static str,
67    /// A longer-form paragraph: what the rule is and, crucially, *why* it
68    /// exists. This is the offline-complete answer — useful without network.
69    pub blurb: &'static str,
70    /// A minimal example of the violation and its fix: the offending line is
71    /// marked `✗` and the corrected one `✓` in a trailing comment. Written to be
72    /// read, so it may elide with `…`; `bynk-tests`' `explain_examples.rs` holds
73    /// every line of it to a compiled pair of whole programs (#3163).
74    ///
75    /// An example that spans files says which one each snippet is in with a
76    /// comment-only line holding just a path: `// shop.bynk`, the file's path
77    /// under the project's `src/` (`// shop/till.bynk` if nested), or
78    /// `// bynk.toml`. The label applies until the next, and the gate holds each
79    /// line under it to that file (the bad project's if marked `✗`, the good
80    /// project's if `✓`, either's if unmarked). A label must name a file of the
81    /// fixture, and only a directory-form fixture may use one.
82    ///
83    /// The gate also checks the layout of the string as it prints: a line
84    /// inside a `{ … }` block must be indented past the line that opens it, and
85    /// the closing `}` must sit at that line's indentation. A `\` line
86    /// continuation swallows the whitespace that follows it, newlines included,
87    /// so write a nested line's leading spaces as `\x20` (four spaces a level)
88    /// and a blank line as `\n\`, never as a line holding only `\`.
89    pub example: &'static str,
90}
91
92impl Explain {
93    /// The link for this explanation's code: [`href`] of its code.
94    pub fn href(&self) -> String {
95        href(self.code)
96    }
97}
98
99/// The curated explanations, keyed by code (DECISION B: highest-traffic,
100/// newcomer-facing codes first). Kept sorted by code; every `code` must be a
101/// real [`REGISTRY`] entry, enforced by `tests/diagnostics_registry.rs`. Every `example` needs its
102/// compiled pair under `bynk-tests/tests/fixtures/explain/<code>/`: `bad.bynk`
103/// and `good.bynk`, or, for a rule that needs a second unit or a `bynk.toml`,
104/// project trees `bad/` and `good/`.
105pub const EXPLANATIONS: &[Explain] = &[
106    Explain {
107        code: "bynk.actor.bearer_identity_not_string_constructible",
108        blurb: "A `Bearer` actor's identity is minted from the token's `sub` claim, which is a \
109                string, so the identity type must be one a string can become: a refined or \
110                opaque `String`. Any other type has no way to be built from the claim, and an \
111                actor with no `identity` at all is refused for the same reason. Declare a type \
112                over `String`, such as `type UserId = String where NonEmpty`, and name it as the \
113                `identity`. An `Oidc` actor has the same rule under \
114                `bynk.actor.oidc_identity_not_string_constructible`.",
115        example: "type Age = Int where NonNegative\n\
116                  actor User { auth = Bearer(secret = \"JWT_KEY\"), identity = Age }      // ✗ a token's `sub` is a string, not an `Int`\n\
117                  \n\
118                  type UserId = String where NonEmpty\n\
119                  actor User { auth = Bearer(secret = \"JWT_KEY\"), identity = UserId }   // ✓ minted from `sub`",
120    },
121    Explain {
122        code: "bynk.actor.bearer_missing_secret",
123        blurb: "A `Bearer` actor checks a JWT signed with a shared key, so the compiler needs to \
124                know which key. Name the environment variable that holds it: \
125                `Bearer(secret = \"JWT_KEY\")`. The string is the variable's name, never the key \
126                itself, so no secret is written in the source; the `Secrets` capability reads the \
127                value at run time. An `Oidc` actor needs no secret, because it checks the \
128                provider's public keys, and a `Signature` actor has its own \
129                `bynk.actor.signature_missing_secret`.",
130        example: "type UserId = String where NonEmpty\n\n\
131                  actor User { auth = Bearer, identity = UserId }                         // ✗ no signing secret named\n\n\
132                  actor User { auth = Bearer(secret = \"JWT_KEY\"), identity = UserId }     // ✓ the env var that holds the key",
133    },
134    Explain {
135        code: "bynk.actor.binder_shadows_param",
136        blurb: "A `by` clause with a binder, `by who: Visitor`, adds a name to the handler body \
137                beside its parameters. If the binder is spelt like a parameter it would hide it, \
138                so a body that read `body` would silently get the actor instead of the request \
139                body. The compiler refuses the clash rather than choose one. Rename the binder \
140                or the parameter. A `by` with no binder, `by Visitor`, adds no name and cannot \
141                clash.",
142        example: "on POST(\"/echo\") (body: String) -> Effect[HttpResult[String]] by body: Visitor {   // ✗ `body` is already a parameter\n\n\
143                  on POST(\"/echo\") (body: String) -> Effect[HttpResult[String]] by who: Visitor {   // ✓ a name of its own",
144    },
145    Explain {
146        code: "bynk.actor.by_on_agent",
147        blurb: "`by` names who is calling and has the compiler verify it at the edge of the \
148                program: an HTTP request, a queue message, a cron tick. An agent handler is not \
149                an edge. It is reached only from a service or another agent, which has already \
150                been through its own check, so there is no caller left to verify and the clause \
151                would be silently ignored. The compiler refuses it instead of letting it look \
152                like protection. Remove the clause, and put the `by` on the service handler that \
153                calls the agent, passing on whatever the agent needs as an argument.",
154        example: "on call bump() -> Effect[Int] by v: Visitor {   // ✗ an agent handler has no actor\n\n\
155                  on call bump() -> Effect[Int] {                // ✓ the service in front of it holds the `by`",
156    },
157    Explain {
158        code: "bynk.actor.caller_not_admitted",
159        blurb: "A refinement over `Caller`, such as `actor Admin = Caller where IsContext(shop.admin)`, names the contexts that may call a service. The compiler sees every call in the project, so a call from any other context is refused here, at the call, before anything is deployed. The wire format still checks the caller at run time (a `403`), because signing keys are per pair of contexts and a caller from before the restriction may still be deployed. In a test, a call-site `by Admin(\"shop.web\")` is checked the same way. Call a service the context may call, or add the context to the actor's `IsContext(…)`.",
160        example: "// shop/billing.bynk\ncontext shop.billing\n\nactor Admin = Caller where IsContext(shop.admin)\n\nservice refunds {\n\x20 on call(id: String) -> Effect[Int] by Admin {\n\x20   Effect.pure(1)\n\x20 }\n}\n\nservice quote {\n\x20 on call(id: String) -> Effect[Int] by Caller {\n\x20   Effect.pure(2)\n\x20 }\n}\n\n// shop/orders.bynk\ncontext shop.orders\n\nconsumes shop.billing\n\nservice place {\n\x20 on call(id: String) -> Effect[Int] by Caller {\n\x20   shop.billing.refunds(id)   // ✗ `shop.orders` is not `shop.admin`\n\x20   shop.billing.quote(id)   // ✓ `quote` admits any consuming context\n\x20 }\n}",
161    },
162    Explain {
163        code: "bynk.actor.duplicate_sum_scheme",
164        blurb: "Peers in a `by who: A | B` clause are told apart by their authentication scheme, so two peers of the same scheme can't both be reached: the second would never be chosen. Keep one peer per scheme, or fold the two into a single actor. A catch-all peer placed too early is a different mistake, `bynk.actor.unreachable_sum_arm`.",
165        example: "type UserId = String where NonEmpty\nactor One { auth = Bearer(secret = \"KEY_A\"), identity = UserId }\nactor Two { auth = Bearer(secret = \"KEY_B\"), identity = UserId }\n\nservice api from http {\n  on POST(\"/x\") () -> Effect[HttpResult[String]] by who: One | Two {   // ✗ two `Bearer` peers\n\nservice api from http {\n  on POST(\"/x\") () -> Effect[HttpResult[String]] by who: One | Visitor {   // ✓ one peer per scheme",
166    },
167    Explain {
168        code: "bynk.actor.foreign_context_name_unkeyable",
169        blurb: "A foreign caller signs its calls under a key named from the context's name, `BYNK_CALL_TO_<CONTEXT>`. The name must therefore be lower-case letters and digits in dot-separated segments, each starting with a letter, with single underscores between runs: no `__`, and no trailing `_`. Rename the context, or move the foreign actor to one whose name qualifies.",
170        example: "context shop.orders_\nactor Legacy { auth = Foreign(secret = \"LEGACY_CALL_KEY\") }   // ✗ no key can be named from `shop.orders_`\n\ncontext shop.orders\nactor Legacy { auth = Foreign(secret = \"LEGACY_CALL_KEY\") }   // ✓",
171    },
172    Explain {
173        code: "bynk.actor.foreign_duplicate_secret",
174        blurb: "A context tells its foreign callers apart by the secret their calls are signed under, and `bynk deploy` mints one secret per name. Two actors on one secret could each pass for the other, so a foreign actor's secret may be no other actor's. Give each its own variable.",
175        example: "actor Legacy { auth = Foreign(secret = \"SHARED_KEY\") }\nactor Ledger { auth = Foreign(secret = \"SHARED_KEY\") }          // ✗ `Legacy` already uses it\n\nactor Ledger { auth = Foreign(secret = \"LEDGER_CALL_KEY\") }     // ✓ its own variable",
176    },
177    Explain {
178        code: "bynk.actor.foreign_identity_unsupported",
179        blurb: "A `Foreign` actor is its own identity: a handler tells foreign callers apart by matching on its `by` sum, not by a value carried in. So `identity` is refused, where a `Bearer` actor takes one from its token. Remove it.",
180        example: "type Who = String where NonEmpty\n\nactor Legacy { auth = Foreign(secret = \"LEGACY_CALL_KEY\"), identity = Who }   // ✗ the actor is the identity\n\nactor Legacy { auth = Foreign(secret = \"LEGACY_CALL_KEY\") }                   // ✓",
181    },
182    Explain {
183        code: "bynk.actor.foreign_missing_secret",
184        blurb: "A `Foreign` actor is a caller that is not Bynk. Its calls are signed, and the context checks each one against a secret, so the actor must name the environment variable that holds it. The string is the variable's name, never the key, and `bynk deploy` mints the key and sets it. With no name the context has nothing to check a call against. A secret that is not a string is `bynk.actor.foreign_secret_not_string`.",
185        example: "actor Legacy { auth = Foreign }                                // ✗ no secret named\n\nactor Legacy { auth = Foreign(secret = \"LEGACY_CALL_KEY\") }    // ✓ the env var that holds the key",
186    },
187    Explain {
188        code: "bynk.actor.foreign_name_is_context_name",
189        blurb: "A foreign caller sends its actor's name as its caller, and a Bynk context's name is lower case. An actor named like a context could pass for one. Start the actor's name with a capital letter.",
190        example: "actor legacy { auth = Foreign(secret = \"LEGACY_CALL_KEY\") }   // ✗ reads as a context name\n\nactor Legacy { auth = Foreign(secret = \"LEGACY_CALL_KEY\") }   // ✓ capitalised",
191    },
192    Explain {
193        code: "bynk.actor.foreign_reserved_secret",
194        blurb: "`bynk deploy` mints the keys that Bynk contexts sign their calls to each other with, and names them `BYNK_CALL_FROM_…` and `BYNK_CALL_TO_…`. A foreign caller's secret in that range could collide with one of them, so those names are kept for contexts. Pick another name, such as `LEGACY_CALL_KEY`.",
195        example: "actor Legacy { auth = Foreign(secret = \"BYNK_CALL_FROM_LEGACY\") }   // ✗ a `BYNK_CALL_` key name\n\nactor Legacy { auth = Foreign(secret = \"LEGACY_CALL_KEY\") }         // ✓ any other name",
196    },
197    Explain {
198        code: "bynk.actor.foreign_secret_not_string",
199        blurb: "A `Foreign` actor's `secret` is the name of an environment variable, so it is written as a string. A number or any other expression names no variable. Put the variable's name in quotes. A `secret` left out altogether is `bynk.actor.foreign_missing_secret`.",
200        example: "actor Legacy { auth = Foreign(secret = 42) }                   // ✗ not a variable name\n\nactor Legacy { auth = Foreign(secret = \"LEGACY_CALL_KEY\") }    // ✓ a string",
201    },
202    Explain {
203        code: "bynk.actor.identity_not_sealed",
204        blurb: "An actor's identity is a value only its context can mint, from a verified token or caller, so its type has to be one that context owns. A built-in such as `Int`, or a type from another context, could be built by anyone, so the identity would prove nothing. Declare the identity as a type in this context, such as `type PrincipalId = Int where NonNegative`, and name that.",
205        example: "actor Principal { auth = Internal, identity = Int }   // ✗ `Int` is not owned by this context\n\ntype PrincipalId = Int where NonNegative\nactor Principal { auth = Internal, identity = PrincipalId }   // ✓ minted only here",
206    },
207    Explain {
208        code: "bynk.actor.missing_by_on_call",
209        blurb: "An `on call` handler is reachable by every context that consumes this one, and which of them may call it is an access decision, so the handler must say, with a `by` clause. `by Caller` is the explicit \"any consuming context\"; a refinement over `Caller`, a `Foreign` actor or a sum narrows it. The error's fix inserts `by Caller`, which is what the handler did before the clause was required, and `bynk check --fix=bynk.actor.missing_by_on_call` migrates a whole project. A header default, `service pay by Caller`, covers every handler without its own `by`. Agents, cron, queue and `Events` handlers have no caller to name, so they are unchanged.",
210        example: "context shop\n\nservice authorise {\n\x20 on call(total: Int) -> Effect[Int] {   // ✗ who may call this?\n\x20   total\n\x20 }\n}\n\nservice authorise {\n\x20 on call(total: Int) -> Effect[Int] by Caller {   // ✓ any consuming context, said outright\n\x20   total\n\x20 }\n}",
211    },
212    Explain {
213        code: "bynk.actor.missing_by_on_http",
214        blurb: "An HTTP handler can be reached by anyone, and Bynk has no safe default for who \
215                is calling, so each one must say, with a `by` clause, which actor it expects. \
216                The compiler then emits the verification before the body runs. A public route \
217                writes `by v: Visitor`; an authenticated one names an `actor` it declares. Set \
218                it once on the header, `service api from http by Visitor`, and every handler \
219                without its own `by` inherits it. A WebSocket `on open` handler needs one too. \
220                `call` handlers need one too (`bynk.actor.missing_by_on_call`); cron and queue have a default.",
221        example: "service api from http {\n\
222                  \x20 on GET(\"/health\") () -> Effect[HttpResult[String]] {   // ✗ who may call this?\n\
223                  \x20   Ok(\"up\")\n\
224                  \x20 }\n\
225                  }\n\
226                  \n\
227                  service api from http {\n\
228                  \x20 on GET(\"/health\") () -> Effect[HttpResult[String]] by v: Visitor {   // ✓ anyone, said outright\n\
229                  \x20   Ok(\"up\")\n\
230                  \x20 }\n\
231                  }",
232    },
233    Explain {
234        code: "bynk.actor.oidc_identity_not_string_constructible",
235        blurb: "An `Oidc` actor's identity is minted from the verified token's `sub` claim, which is a string, so the identity type must be a refined or opaque `String`. An actor with no `identity` is refused too. Declare a type over `String`, such as `type UserId = String where NonEmpty`, and name it. A `Bearer` actor has the same rule under `bynk.actor.bearer_identity_not_string_constructible`.",
236        example: "type Age = Int where NonNegative\nactor User { auth = Oidc(issuer = \"https://issuer.example\", audience = \"my-api\", jwks = \"https://issuer.example/jwks\"), identity = Age }   // ✗ `sub` is a string, not an `Int`\n\ntype UserId = String where NonEmpty\nactor User { auth = Oidc(issuer = \"https://issuer.example\", audience = \"my-api\", jwks = \"https://issuer.example/jwks\"), identity = UserId }   // ✓ minted from `sub`",
237    },
238    Explain {
239        code: "bynk.actor.oidc_missing_audience",
240        blurb: "A provider signs tokens for many services, and each token is issued for one. An `Oidc` actor therefore names its `audience`, the `aud` claim a token must carry, so a token issued for some other API is refused here even though its signature is valid. Add `audience = \"…\"` with the identifier your provider uses for this API. The issuer and key set have their own codes, `bynk.actor.oidc_missing_issuer` and `bynk.actor.oidc_missing_jwks`.",
241        example: "type UserId = String where NonEmpty\nactor User { auth = Oidc(issuer = \"https://issuer.example\", jwks = \"https://issuer.example/jwks\"), identity = UserId }   // ✗ no audience\n\nactor User { auth = Oidc(issuer = \"https://issuer.example\", audience = \"my-api\", jwks = \"https://issuer.example/jwks\"), identity = UserId }   // ✓ the `aud` this API accepts",
242    },
243    Explain {
244        code: "bynk.actor.oidc_missing_issuer",
245        blurb: "A valid signature shows that some key signed a token, not that your provider issued it. An `Oidc` actor therefore names its `issuer`, the `iss` claim a token must carry, and refuses any other. Add `issuer = \"…\"` with the provider's issuer URL. The other required settings have their own codes, `bynk.actor.oidc_missing_audience` and `bynk.actor.oidc_missing_jwks`.",
246        example: "type UserId = String where NonEmpty\nactor User { auth = Oidc(audience = \"my-api\", jwks = \"https://issuer.example/jwks\"), identity = UserId }   // ✗ no issuer\n\nactor User { auth = Oidc(issuer = \"https://issuer.example\", audience = \"my-api\", jwks = \"https://issuer.example/jwks\"), identity = UserId }   // ✓ the `iss` a token must carry",
247    },
248    Explain {
249        code: "bynk.actor.oidc_missing_jwks",
250        blurb: "An `Oidc` actor holds no shared secret. It checks a token's signature against the provider's public keys, a JSON Web Key Set that the verifier fetches from a URL, so the actor must say where it is. Add `jwks = \"…\"`, for example the provider's `/.well-known/jwks.json`. The `issuer` and `audience` are required as well, under `bynk.actor.oidc_missing_issuer` and `bynk.actor.oidc_missing_audience`.",
251        example: "type UserId = String where NonEmpty\nactor User { auth = Oidc(issuer = \"https://issuer.example\", audience = \"my-api\"), identity = UserId }   // ✗ nowhere to fetch the public keys\n\nactor User { auth = Oidc(issuer = \"https://issuer.example\", audience = \"my-api\", jwks = \"https://issuer.example/jwks\"), identity = UserId }   // ✓ the provider's key set",
252    },
253    Explain {
254        code: "bynk.actor.oidc_not_in_sum",
255        blurb: "A multi-actor `by` clause tries its peers in turn on a request it reads once. An `Oidc` actor must first fetch the provider's keys, which that path does not yet support, so an `Oidc` actor stands alone on its route. Give the route a single `by who: Member`, and serve any anonymous route separately.",
256        example: "type UserId = String where NonEmpty\nactor Member { auth = Oidc(issuer = \"https://issuer.example\", audience = \"my-api\", jwks = \"https://issuer.example/jwks\"), identity = UserId }\n\nservice api from http {\n  on POST(\"/x\") () -> Effect[HttpResult[String]] by who: Member | Visitor {   // ✗ an `Oidc` peer in a sum\n\nservice api from http {\n  on POST(\"/x\") () -> Effect[HttpResult[String]] by who: Member {   // ✓ alone",
257    },
258    Explain {
259        code: "bynk.actor.oidc_trust_from_is_secret",
260        blurb: "`trustFrom` names a variable that holds trust roots as JSON. A variable an actor uses as its `secret` holds a signing key, and one variable cannot be both. Give `trustFrom` a variable of its own.",
261        example: "type UserId = String where NonEmpty\ntype WorkloadId = String where NonEmpty\n\nactor User { auth = Bearer(secret = \"JWT_KEY\"), identity = UserId }\nactor Workload { auth = Oidc(issuer = \"https://i.test\", audience = \"a\", jwks = \"https://i.test/jwks\", trustFrom = \"JWT_KEY\"), identity = WorkloadId }   // ✗ `JWT_KEY` is a key\n\nactor Workload { auth = Oidc(issuer = \"https://i.test\", audience = \"a\", jwks = \"https://i.test/jwks\", trustFrom = \"OIDC_TRUST\"), identity = WorkloadId }   // ✓",
262    },
263    Explain {
264        code: "bynk.actor.oidc_trust_from_not_string",
265        blurb: "`trustFrom` names an environment variable whose JSON, when set, replaces the actor's declared trust roots at run time, as in a test or staging deployment. A variable is named by a string, so a number or other expression names nothing. Write the variable's name in quotes.",
266        example: "type WorkloadId = String where NonEmpty\n\nactor Workload { auth = Oidc(issuer = \"https://i.test\", audience = \"a\", jwks = \"https://i.test/jwks\", trustFrom = 5), identity = WorkloadId }   // ✗ not a name\n\nactor Workload { auth = Oidc(issuer = \"https://i.test\", audience = \"a\", jwks = \"https://i.test/jwks\", trustFrom = \"OIDC_TRUST\"), identity = WorkloadId }   // ✓",
267    },
268    Explain {
269        code: "bynk.actor.outside_context",
270        blurb: "An `actor` says who may call a handler and what the compiler then knows about them. Only a context has handlers, and an actor's identity is sealed to the context that declares it, so only a context may declare one. A `commons` is shared code that other units `uses`. Move the `actor` into the context whose services take it.",
271        example: "commons shop\n\nactor User { auth = None }   // ✗ a commons has no handlers\n\ncontext shop\n\nactor User { auth = None }   // ✓ declared where it is used",
272    },
273    Explain {
274        code: "bynk.actor.refinement_base_unsupported",
275        blurb: "`actor Admin = User where …` adds an authorisation check on a token's claims, and only a `Bearer` actor carries claims. So the base must be a declared `Bearer` actor: not `Visitor`, `Internal` or `Signature`, and not another refinement. Name a `Bearer` actor as the base, declaring it if need be.",
276        example: "type UserId = String where NonEmpty\nactor User { auth = Bearer(secret = \"JWT_KEY\"), identity = UserId }\n\nactor Admin = Visitor where hasClaim(\"admin\")   // ✗ `Visitor` carries no claims\n\nactor Admin = User where hasClaim(\"admin\")   // ✓ a `Bearer` actor",
277    },
278    Explain {
279        code: "bynk.actor.refinement_in_sum",
280        blurb: "A refinement actor has its base's scheme and only narrows it, and peers of a sum are told apart by scheme, so it can't stand beside its base as another choice. Name the base as the peer and test the extra condition in its arm, or give the refined route its own `by who: Admin`.",
281        example: "type UserId = String where NonEmpty\nactor User { auth = Bearer(secret = \"JWT_KEY\"), identity = UserId }\nactor Admin = User where hasClaim(\"admin\")\n\nservice api from http {\n  on POST(\"/x\") () -> Effect[HttpResult[String]] by who: User | Admin {   // ✗ `Admin` refines `User`\n\nservice api from http {\n  on POST(\"/x\") () -> Effect[HttpResult[String]] by who: Admin {   // ✓ its own route",
282    },
283    Explain {
284        code: "bynk.actor.refinement_predicate_unsupported",
285        blurb: "A refinement actor's `where` is checked against a token's claims, which are untyped JSON, so the predicate is a closed vocabulary: `hasClaim(\"name\")` and `claimEquals(\"name\", \"value\")`, composed with `&&`, `||` and `!`. Express the condition with those. Anything else, such as a call to a function of your own, is refused.",
286        example: "type UserId = String where NonEmpty\nactor User { auth = Bearer(secret = \"JWT_KEY\"), identity = UserId }\n\nactor Admin = User where isAdmin(user)   // ✗ not a claim predicate\n\nactor Admin = User where hasClaim(\"admin\")   // ✓",
287    },
288    Explain {
289        code: "bynk.actor.scheme_arg_kind",
290        blurb: "A scheme's config values are strings and integers, except that a `SignedCookie` also takes a duration (`ttl = 12.hours`) and a bare name (`sameSite = Lax`). Every other scheme reads a string or an integer, so a duration or a bare name would be dropped without a word: a `Signature` `tolerance = 5.minutes` would read as no tolerance at all, and the replay window would be off. Write a `Signature` tolerance in whole seconds, and quote a string.",
291        example: "actor Hook { auth = Signature(secret = \"K\", header = \"X-Sig\", timestamp = \"X-Ts\", tolerance = 5.minutes) }   // ✗ a duration\n\nactor Hook { auth = Signature(secret = \"K\", header = \"X-Sig\", timestamp = \"X-Ts\", tolerance = 300) }   // ✓ seconds",
292    },
293    Explain {
294        code: "bynk.actor.scheme_not_admissible",
295        blurb: "Each protocol admits only the schemes that can be verified on it. HTTP takes \
296                `None` (`Visitor`), `Bearer`, `Signature` and `Oidc`; a WebSocket takes `None` \
297                and `Bearer`; `call` takes `Internal` and `Foreign`; cron and queue take \
298                `Internal`. A `Visitor` on cron is wrong because nothing public calls a cron \
299                handler: the platform does. Use the actor made for the protocol: `Scheduler` for \
300                cron, `Producer` for queue, `Caller` for `on call`. `Caller` is admitted on \
301                `on call` only.",
302        example: "service jobs from cron {\n\
303                  \x20 on schedule(\"* * * * *\") () -> Effect[Result[(), String]] by v: Visitor {   // ✗ cron takes an `Internal` actor\n\
304                  \x20   Ok(())\n\
305                  \x20 }\n\
306                  }\n\
307                  \n\
308                  service jobs from cron {\n\
309                  \x20 on schedule(\"* * * * *\") () -> Effect[Result[(), String]] by s: Scheduler {   // ✓ the cron actor\n\
310                  \x20   Ok(())\n\
311                  \x20 }\n\
312                  }",
313    },
314    Explain {
315        code: "bynk.actor.signature_identity_unsupported",
316        blurb: "A signature shows that a request is authentic, not who sent it, so a `Signature` actor has no principal to give an identity. The event is the handler's `body`. Remove `identity`. For an actor that carries a principal, see `bynk.actor.bearer_identity_not_string_constructible`.",
317        example: "actor Hook { auth = Signature(secret = \"WEBHOOK_KEY\", header = \"X-Sig\"), identity = String }   // ✗ no principal\n\nactor Hook { auth = Signature(secret = \"WEBHOOK_KEY\", header = \"X-Sig\") }                       // ✓",
318    },
319    Explain {
320        code: "bynk.actor.signature_missing_header",
321        blurb: "A `Signature` actor reads the sender's signature from a request header, and the header's name is the sender's choice, so the actor must say which one. Add `header = \"…\"` with the name of the header that carries the HMAC. Without it the compiler has no way to find the signature to check the body against.",
322        example: "actor Hook { auth = Signature(secret = \"WEBHOOK_KEY\") }   // ✗ which header holds the signature?\n\nactor Hook { auth = Signature(secret = \"WEBHOOK_KEY\", header = \"X-Sig\") }   // ✓",
323    },
324    Explain {
325        code: "bynk.actor.signature_missing_secret",
326        blurb: "A `Signature` actor checks an HMAC of the request body, so the compiler needs the key to check it against. Name the environment variable that holds it: `secret = \"WEBHOOK_KEY\"`. The string is the variable's name, never the key itself, so no secret is written in the source. A `Bearer` actor has its own `bynk.actor.bearer_missing_secret`.",
327        example: "actor Hook { auth = Signature(header = \"X-Sig\") }   // ✗ no signing secret named\n\nactor Hook { auth = Signature(secret = \"WEBHOOK_KEY\", header = \"X-Sig\") }   // ✓ the env var that holds the key",
328    },
329    Explain {
330        code: "bynk.actor.signature_requires_body",
331        blurb: "A `Signature` is an HMAC over the raw request body, so the handler must take that body: one with no `body` parameter would vouch for data it never reads. Add `(body: T)`, where `T` is the payload's type. A route that takes no payload has nothing for a signature to protect.",
332        example: "actor Hook { auth = Signature(secret = \"WEBHOOK_KEY\", header = \"X-Sig\") }\n\nservice api from http {\n  on POST(\"/x\") () -> Effect[HttpResult[String]] by Hook {   // ✗ no `body` parameter\n  on POST(\"/x\") (body: String) -> Effect[HttpResult[String]] by Hook {   // ✓ the signed payload",
333    },
334    Explain {
335        code: "bynk.actor.signature_tolerance_without_timestamp",
336        blurb: "`tolerance` is how many seconds old a signed request may be before it is refused, which limits replay of a captured one. The age is read from a timestamp header, so `tolerance` needs `timestamp = \"…\"` naming it; alone it has nothing to compare against. Add the `timestamp`, or drop `tolerance` and accept that a captured request can be replayed.",
337        example: "actor Hook { auth = Signature(secret = \"WEBHOOK_KEY\", header = \"X-Sig\", tolerance = 300) }   // ✗ age of what?\n\nactor Hook { auth = Signature(secret = \"WEBHOOK_KEY\", header = \"X-Sig\", timestamp = \"X-Time\", tolerance = 300) }   // ✓",
338    },
339    Explain {
340        code: "bynk.actor.signed_cookie_bad_arg",
341        blurb: "Each `SignedCookie` key takes one kind of value: `secret`, `previous` and `cookie` are strings, `ttl` is a duration, and `sameSite` is `Lax`, `Strict` or `Unrestricted`. Fix the value or remove the key.",
342        example: "actor User { auth = SignedCookie(secret = 5, ttl = 12.hours), identity = UserId }   // ✗\n\nactor User { auth = SignedCookie(secret = \"SESSION_KEY\", ttl = 12.hours), identity = UserId }   // ✓",
343    },
344    Explain {
345        code: "bynk.actor.signed_cookie_bad_name",
346        blurb: "A cookie name is an RFC 6265 token: letters, digits and a few punctuation characters, with no space, `=`, `;`, `,` or quote. A browser would drop or misread anything else. The default, `__Host-session`, is always legal.",
347        example: "actor User { auth = SignedCookie(secret = \"SESSION_KEY\", ttl = 12.hours, cookie = \"my session\"), identity = UserId }   // ✗\n\nactor User { auth = SignedCookie(secret = \"SESSION_KEY\", ttl = 12.hours), identity = UserId }   // ✓",
348    },
349    Explain {
350        code: "bynk.actor.signed_cookie_bad_ttl",
351        blurb: "`ttl` must be a `Duration` literal that is positive and a whole number of seconds, because it becomes both a `Max-Age` and a signed expiry in seconds. Write `12.hours` or `30.minutes`.",
352        example: "actor User { auth = SignedCookie(secret = \"SESSION_KEY\", ttl = 1500.milliseconds), identity = UserId }   // ✗\n\nactor User { auth = SignedCookie(secret = \"SESSION_KEY\", ttl = 12.hours), identity = UserId }   // ✓",
353    },
354    Explain {
355        code: "bynk.actor.signed_cookie_duplicate_key",
356        blurb: "A `SignedCookie` config names each key once. A repeated `secret` or `ttl` would have the first value win and the second ignored without a word, in the scheme that guards a session. Keep the one you mean.",
357        example: "actor User { auth = SignedCookie(secret = \"A\", secret = \"B\", ttl = 12.hours), identity = UserId }   // ✗ two secrets\n\nactor User { auth = SignedCookie(secret = \"A\", ttl = 12.hours), identity = UserId }   // ✓",
358    },
359    Explain {
360        code: "bynk.actor.signed_cookie_identity_not_string_constructible",
361        blurb: "The identity is minted from the cookie's `sub` claim, which is a string, so it must be a refined or opaque `String` type that this context owns. Declare `identity = T`.",
362        example: "actor User { auth = SignedCookie(secret = \"SESSION_KEY\", ttl = 12.hours) }   // ✗\n\nactor User { auth = SignedCookie(secret = \"SESSION_KEY\", ttl = 12.hours), identity = UserId }   // ✓",
363    },
364    Explain {
365        code: "bynk.actor.signed_cookie_issue_needs_clock",
366        blurb: "`User.issue(identity)` signs a cookie that expires, so it reads the current time from the `Clock` capability, and a handler's dependencies are always visible in its `given` clause (and a test can stub the clock to know exactly the cookie it gets). Add `consumes bynk { Clock }` to the context and `given Clock` to the handler.",
367        example: "let c <- User.issue(body)   // ✗ the handler lists no `given Clock`\n\nlet c <- User.issue(body)   // ✓ with `given Clock` on the handler",
368    },
369    Explain {
370        code: "bynk.actor.signed_cookie_issue_outside_handler",
371        blurb: "The signing key reaches a service handler, which is where a request arrives and a `Set-Cookie` is sent. A provider or an agent holds only the capabilities in its `given`, so `User.issue(identity)` there would find no key and fault on every request. Issue the cookie in the handler.",
372        example: "User.issue(id)   // ✗ in a provider or an agent\n\nlet c <- User.issue(body)   // ✓ in a service handler",
373    },
374    Explain {
375        code: "bynk.actor.signed_cookie_missing_secret",
376        blurb: "A `SignedCookie` actor signs the session cookies it issues and verifies the ones it receives, so it needs a key. `secret` names the environment variable holding it, never the key itself. `bynk deploy` mints a random 32-byte key for it when the variable is unset, so you never choose one.",
377        example: "actor User { auth = SignedCookie(ttl = 12.hours), identity = UserId }   // ✗\n\nactor User { auth = SignedCookie(secret = \"SESSION_KEY\", ttl = 12.hours), identity = UserId }   // ✓",
378    },
379    Explain {
380        code: "bynk.actor.signed_cookie_missing_ttl",
381        blurb: "A session cookie that never expires is the failure a language should not allow by omission, so `ttl` is required. It is how long an issued cookie is valid: the browser's `Max-Age` and the signed expiry both come from it. A stateless cookie cannot be revoked before it expires, so keep it short.",
382        example: "actor User { auth = SignedCookie(secret = \"SESSION_KEY\"), identity = UserId }   // ✗\n\nactor User { auth = SignedCookie(secret = \"SESSION_KEY\", ttl = 12.hours), identity = UserId }   // ✓",
383    },
384    Explain {
385        code: "bynk.actor.signed_cookie_not_in_sum",
386        blurb: "A multi-actor `by` clause tries its peers in turn. A cookie is an ambient credential, so the CSRF check must apply only when the cookie is what authenticated the request, and that per-arm rule is not built yet. A `SignedCookie` actor therefore stands alone on its route: give it a single `by who: User` and serve any anonymous route separately.",
387        example: "on POST(\"/x\") () -> Effect[HttpResult[String]] by who: User | Visitor {   // ✗ a `SignedCookie` peer in a sum\n\non POST(\"/x\") () -> Effect[HttpResult[String]] by who: User {   // ✓ alone",
388    },
389    Explain {
390        code: "bynk.actor.signed_cookie_public_cache",
391        blurb: "A route guarded by a session cookie answers one user, so a shared cache must not store its response, or it would serve one user's answer to another. Use `scope: private`, which lets only the browser keep it, or drop `@cache`.",
392        example: "@cache(maxAge: 5.minutes, scope: public)   // ✗ a shared cache would replay it\n\n@cache(maxAge: 5.minutes, scope: private)   // ✓",
393    },
394    Explain {
395        code: "bynk.actor.signed_cookie_read_directly",
396        blurb: "A `SignedCookie` actor reads its session cookie at the boundary, verifies it and hands the handler only the identity, so the signed value never reaches handler code. A `cookies` record on the same route that names that cookie (by its own name or `@name`) would ask for the raw value, so it is refused, and the router leaves the cookie out of a raw `RequestCookies` view too. Read the identity from the `by` binder, and keep other cookies (a theme, a language) in the record.",
397        example: "type Prefs = {\n  @name(\"__Host-session\") session: Option[String],   // ✗ the session cookie\n  theme: Option[String],\n}\n\ntype Prefs = {\n  theme: Option[String],   // ✓ other cookies only\n}",
398    },
399    Explain {
400        code: "bynk.actor.signed_cookie_secret_shared",
401        blurb: "A session key signs one actor's cookies and nothing else. If two actors shared a variable, a cookie issued for one would verify for the other, and a Bearer token could be replayed as a cookie. Give each actor its own variable; `previous` is the key being rotated out, so it differs from `secret` too.",
402        example: "actor User { auth = SignedCookie(secret = \"SESSION_KEY\", ttl = 12.hours), identity = UserId }\nactor Admin { auth = SignedCookie(secret = \"SESSION_KEY\", ttl = 1.hour), identity = UserId }   // ✗ same key\n\nactor Admin { auth = SignedCookie(secret = \"ADMIN_SESSION_KEY\", ttl = 1.hour), identity = UserId }   // ✓",
403    },
404    Explain {
405        code: "bynk.actor.signed_cookie_ttl_long",
406        blurb: "A stateless signed cookie cannot be revoked before it expires: a copy a user already took keeps working for the whole `ttl`. Beyond 30 days that is a long exposure, so it warns. Shorten the `ttl`, or keep the session on the server (see `examples/sessions`) if you need to log out everywhere.",
407        example: "actor User { auth = SignedCookie(secret = \"SESSION_KEY\", ttl = 31.days), identity = UserId }   // ⚠ long-lived\n\nactor User { auth = SignedCookie(secret = \"SESSION_KEY\", ttl = 12.hours), identity = UserId }   // ✓",
408    },
409    Explain {
410        code: "bynk.actor.signed_cookie_unknown_key",
411        blurb: "A `SignedCookie` takes `secret`, `ttl`, `cookie`, `previous` and `sameSite`, and nothing else. The set is closed so a misspelt option is refused rather than ignored. The cookie's `Domain` and `Path` are not configurable on purpose: the issued cookie is always host-only and `Path=/`, which keeps a `__Host-` name valid.",
412        example: "actor User { auth = SignedCookie(secret = \"SESSION_KEY\", ttl = 12.hours, domain = \"example.com\"), identity = UserId }   // ✗\n\nactor User { auth = SignedCookie(secret = \"SESSION_KEY\", ttl = 12.hours), identity = UserId }   // ✓",
413    },
414    Explain {
415        code: "bynk.actor.signed_cookie_unprefixed",
416        blurb: "A `__Host-` cookie name tells the browser to keep the cookie only if it is `Secure`, host-only and `Path=/`, so a sibling subdomain cannot set or overwrite it. An unprefixed session cookie is open to cookie tossing from any subdomain, which is rarely intended. The default is `__Host-session`; drop `cookie` or give it a `__Host-` name.",
417        example: "actor User { auth = SignedCookie(secret = \"SESSION_KEY\", ttl = 12.hours, cookie = \"session\"), identity = UserId }   // ⚠ not `__Host-`\n\nactor User { auth = SignedCookie(secret = \"SESSION_KEY\", ttl = 12.hours), identity = UserId }   // ✓ `__Host-session` by default",
418    },
419    Explain {
420        code: "bynk.actor.signed_cookie_write_directly",
421        blurb: "A `SignedCookie` actor's session cookie is minted by `Actor.issue(identity)`, which signs it with the actor's key, and removed by `Actor.expire()`, and the CSRF check keys off that actor. A cookie record's `R.field.cookie(v)` or `R.field.expire()` whose field is read under the session cookie's name would write or clear the credential without any of that, so it is refused. Keep the session cookie out of the record and use the actor's own members.",
422        example: "type Prefs = {\n  @name(\"__Host-session\") session: Option[String],\n  theme: Option[String],\n}\n\nOk(\"x\").withCookie(Prefs.session.cookie(\"forged\"))   // ✗ the session cookie\n\nOk(\"x\").withCookie(Prefs.theme.cookie(\"dark\"))        // ✓ another cookie",
423    },
424    Explain {
425        code: "bynk.actor.signed_cookie_write_literal",
426        blurb: "A `Cookie { name: \"__Host-session\", … }` literal named like a `SignedCookie` actor's session cookie would write or clear the credential by hand, without the actor's signing key, expiry or CSRF seam, so it is refused. Write it with `Actor.issue(identity)` and remove it with `Actor.expire()`.",
427        example: "Ok(\"x\").withCookie(Cookie { name: \"__Host-session\", value: \"forged\" })   // ✗ the actor's cookie\n\nOk(\"x\").withCookie(Cookie { name: \"theme\", value: \"dark\" })            // ✓ another cookie",
428    },
429    Explain {
430        code: "bynk.actor.sum_requires_binder",
431        blurb: "`by A | B` tries the actors in order and the first that verifies the caller wins. \
432                Which one that was is only known when a request arrives, so the handler learns it \
433                through the binder and `match`es on it. With no binder the answer would be \
434                thrown away and the sum would do nothing a single actor does not. Add one, \
435                `by who: A | B`, and match `who` in the body. A single actor needs no binder.",
436        example: "on GET(\"/x\") () -> Effect[HttpResult[String]] by User | Visitor {       // ✗ which one was it?\n\n\
437                  on GET(\"/x\") () -> Effect[HttpResult[String]] by who: User | Visitor {   // ✓ `who` is the resolved actor",
438    },
439    Explain {
440        code: "bynk.actor.unknown_actor",
441        blurb: "A `by` clause must name an actor the compiler can find: one declared with \
442                `actor` in this context, or a prelude actor (`Visitor`, `Caller`, `Scheduler` or \
443                `Producer`). Anything else is a misspelling or a missing declaration. The \
444                compiler will not guess, because the actor decides how callers are verified. \
445                Fix the spelling, or declare the actor first with `actor Name { auth = … }`.",
446        example: "on GET(\"/health\") () -> Effect[HttpResult[String]] by v: Visitr {     // ✗ no actor of that name\n\n\
447                  on GET(\"/health\") () -> Effect[HttpResult[String]] by v: Visitor {   // ✓ the prelude actor",
448    },
449    Explain {
450        code: "bynk.actor.unknown_context",
451        blurb: "`IsContext(…)` names the project's own contexts, written as qualified names rather than strings, so that a typo is an error here and not a restriction that silently admits nobody. A name that is no context of the project is usually misspelt, or names a context that was renamed. Foreign callers are not contexts of the project: they have their own `Foreign` actors.",
452        example: "// shop/admin.bynk\ncontext shop.admin\n\nservice audit {\n\x20 on call(id: String) -> Effect[Int] by Caller {\n\x20   Effect.pure(1)\n\x20 }\n}\n\n// shop/billing.bynk\ncontext shop.billing\n\nactor Admin = Caller where IsContext(shop.admn)   // ✗ no such context\n\nactor Admin = Caller where IsContext(shop.admin)   // ✓\n\nservice refunds {\n\x20 on call(id: String) -> Effect[Int] by Admin {\n\x20   Effect.pure(1)\n\x20 }\n}",
453    },
454    Explain {
455        code: "bynk.actor.unknown_scheme",
456        blurb: "An actor's `auth` names how its callers are verified, and the compiler writes \
457                that check itself, so the scheme must be one it knows: `None`, `Internal`, \
458                `Bearer`, `Signature`, `Oidc`, `Foreign` or `SignedCookie`. There are no user-defined schemes, \
459                and a name outside the set is usually a typo or a scheme borrowed from another \
460                framework. Choose the one that matches how callers prove who they are, such as \
461                `Bearer` for a JWT signed with a shared key; the actors page lists what each \
462                one needs.",
463        example: "actor Robot { auth = Bogus }   // ✗ not a scheme the compiler knows\n\n\
464                  actor Robot { auth = None }    // ✓ one of the seven",
465    },
466    Explain {
467        code: "bynk.actor.unreachable_sum_arm",
468        blurb: "In `by who: A | B` the peers are tried in order and the first to verify wins. `Visitor`, or any other `None` peer, accepts everyone, so a peer after it can never be reached and its check would never run. Put the catch-all last. A repeated scheme is a different mistake, `bynk.actor.duplicate_sum_scheme`.",
469        example: "type UserId = String where NonEmpty\nactor User { auth = Bearer(secret = \"JWT_KEY\"), identity = UserId }\n\nservice api from http {\n  on POST(\"/x\") () -> Effect[HttpResult[String]] by who: Visitor | User {   // ✗ `Visitor` accepts everyone first\n\nservice api from http {\n  on POST(\"/x\") () -> Effect[HttpResult[String]] by who: User | Visitor {   // ✓ the catch-all last",
470    },
471    Explain {
472        code: "bynk.adapter.consumes_context",
473        blurb: "Adapter dependencies run from adapter to adapter. An adapter sits at the host boundary and is wired in process beside its binding, but a context is a deployment unit with services of its own, so it cannot be consumed from there. Consume a capability that another adapter exports, or put the code that needs a context in a context.",
474        example: "// logging.bynk\ncontext logging { … }\n\n// tokens.bynk\nadapter tokens {\n    consumes logging { Log }    // ✗ `logging` is a context\n}\n\n// logging.bynk\nadapter logging { … }         // ✓ an adapter, so it may be consumed",
475    },
476    Explain {
477        code: "bynk.adapter.consumes_requires_selection",
478        blurb: "An adapter depends on another adapter's capabilities, never on its services, so its `consumes` must say which: `consumes logging { Log }`. The whole-unit form and `as Alias` belong to contexts. Braces that select only types are refused too, since they name no capability. List the capabilities the adapter needs.",
479        example: "adapter tokens {\n    consumes logging              // ✗ which capabilities?\n}\n\nadapter tokens {\n    consumes logging { Log }      // ✓ the capabilities it needs\n}",
480    },
481    Explain {
482        code: "bynk.adapter.disallowed_item",
483        blurb: "An adapter wraps foreign code, so it holds only what describes that boundary: \
484                capabilities, the types that cross it, external providers and helper functions. A \
485                `service`, an `agent` or an `actor` has behaviour, state and an address of its own, \
486                and those belong to a context. Move the item into a context that `consumes` the \
487                adapter's capability, and leave the adapter as an interface to the foreign code.",
488        example: "adapter tokens {\n\
489                \x20 binding \"./tokens.binding.ts\"\n\
490                \x20 provides Jwt = JoseJwt\n\
491                \x20 service login {                       // ✗ an adapter may not declare a service\n\
492                \x20   on call(x: Int) -> Effect[Int] by Caller { … }\n\
493                \x20 }\n\
494                }\n\
495                \n\
496                adapter tokens {\n\
497                \x20 binding \"./tokens.binding.ts\"\n\
498                \x20 provides Jwt = JoseJwt                // ✓ capabilities and providers only\n\
499                }",
500    },
501    Explain {
502        code: "bynk.adapter.duplicate_binding",
503        blurb: "An adapter's `binding` names the one TypeScript module that supplies its external providers, so there is one clause. With two, the compiler would have no way to say which module a provider comes from. Merge them into one clause; the module it names can import whatever others it needs.",
504        example: "adapter weather {\n    binding \"./station.binding.ts\"\n    binding \"./extra.binding.ts\"      // ✗ an adapter has one binding\n}\n\nadapter weather {\n    binding \"./station.binding.ts\"    // ✓ one clause\n}",
505    },
506    Explain {
507        code: "bynk.adapter.include_duplicate",
508        blurb: "Each module is listed once: the compiler generates one loader, `./x.wasm.js`, per file. Two entries for one file add nothing, and `./a.wasm` and `a.wasm` are the same file once the path is normalised. Remove the repeat, or correct the name if a different module was meant.",
509        example: "adapter math {\n    binding \"./math.binding.ts\" includes [\"./a.wasm\", \"a.wasm\"]    // ✗ the same file twice\n}\n\nadapter math {\n    binding \"./math.binding.ts\" includes [\"./a.wasm\"]              // ✓ listed once\n}",
510    },
511    Explain {
512        code: "bynk.adapter.include_kind",
513        blurb: "`includes` is for WebAssembly modules. The compiler generates a loader for each, `./x.wasm.js`, that gives the binding a compiled module, and it picks them by the `.wasm` extension. Any other file has no such loader. Name a `.wasm` module.",
514        example: "adapter math {\n    binding \"./math.binding.ts\" includes [\"./data.bin\"]    // ✗ not a `.wasm` file\n}\n\nadapter math {\n    binding \"./math.binding.ts\" includes [\"./adder.wasm\"]   // ✓ a WebAssembly module\n}",
515    },
516    Explain {
517        code: "bynk.adapter.include_missing",
518        blurb: "`includes` ships WebAssembly modules beside the binding, so each file it names has to exist: the path is read relative to the adapter's source file. A misspelt name, or a module left out of the tree, is the usual cause. Correct the path, or add the file.",
519        example: "adapter math {\n    binding \"./math.binding.ts\" includes [\"./absent.wasm\"]    // ✗ no such file beside the adapter\n}\n\nadapter math {\n    binding \"./math.binding.ts\" includes [\"./adder.wasm\"]     // ✓ the module exists\n}",
520    },
521    Explain {
522        code: "bynk.adapter.include_outside",
523        blurb: "An included module is part of the adapter's own tree, and, for a dependency, of the tree the lock checksums. So each path is relative to the adapter's file and stays inside its directory: no absolute path, and no `..`. Move the module into the adapter's directory, or a subdirectory of it, and name it from there.",
524        example: "adapter math {\n    binding \"./math.binding.ts\" includes [\"../shared.wasm\"]    // ✗ leaves the adapter's directory\n}\n\nadapter math {\n    binding \"./math.binding.ts\" includes [\"./adder.wasm\"]       // ✓ inside it\n}",
525    },
526    Explain {
527        code: "bynk.adapter.no_binding",
528        blurb: "An external provider, `provides Jwt = JoseJwt` with no body, is written in \
529                TypeScript, not Bynk. The adapter's `binding` clause names that TypeScript module, \
530                resolved relative to the adapter's source file, and the compiler reads it to wire \
531                the provider in. The code fires when the clause is missing, and when the named file \
532                cannot be read. Add `binding \"./tokens.binding.ts\"` and create the file, exporting \
533                a class named for the provider.",
534        example: "adapter tokens {                        // ✗ an external provider, but no binding clause\n\
535                \x20 provides Jwt = JoseJwt\n\
536                }\n\
537                \n\
538                adapter tokens {\n\
539                \x20 binding \"./tokens.binding.ts\"         // ✓ names the module that supplies JoseJwt\n\
540                \x20 provides Jwt = JoseJwt\n\
541                }",
542    },
543    Explain {
544        code: "bynk.adapter.provider_has_body",
545        blurb: "An adapter wraps code written in TypeScript. Its provider has no body: `provides Jwt = JoseJwt`, and the binding exports a class of that name. A Bynk body would be a second implementation beside the binding's. Remove the body and implement the operations in the binding, or, for a provider written in Bynk, move it to a context. An external provider in a context is `bynk.context.external_provider`.",
546        example: "adapter tokens {\n    binding \"./tokens.binding.ts\"\n\n    capability Jwt {\n        fn sign(secret: String) -> Effect[String]\n    }\n\n    provides Jwt = JoseJwt {          // ✗ the binding supplies it\n        fn sign(secret: String) -> Effect[String] { secret }\n    }\n}\n\nadapter tokens {\n    binding \"./tokens.binding.ts\"\n\n    capability Jwt {\n        fn sign(secret: String) -> Effect[String]\n    }\n\n    provides Jwt = JoseJwt            // ✓ no body\n}",
547    },
548    Explain {
549        code: "bynk.agent.class_conflict",
550        blurb: "An agent class that bynk.schema.lock records can't just disappear from source: it \
551                must be given one fate, either `agent New replaces Old` (its data moves) or \
552                `removed agent Old` (its data is deleted). Giving a name two fates is a conflict: \
553                renamed twice, renamed and removed, or removed twice. A rename onto a class that \
554                already has recorded history of its own is also refused, since it would merge two \
555                histories and Cloudflare refuses a rename onto an existing namespace. Decide what \
556                becomes of the old class, and declare that once.",
557        example: "agent Basket replaces Cart {\n\
558                  \x20\x20key id: String\n\
559                  }\n\
560                  \n\
561                  agent Trolley replaces Cart {   // ✗ `Cart` is already renamed to `Basket`\n\
562                  \n\
563                  agent Trolley {                 // ✓ a class of its own",
564    },
565    Explain {
566        code: "bynk.agent.construction_arity",
567        blurb: "An agent is addressed by its key, so constructing one takes exactly one \
568                argument: the value of its single `key` field. `Counter(\"a\")` names the \
569                instance with key `\"a\"`. Two arguments or none do not say which instance is \
570                meant. Pass the one key. A key of the wrong type is `bynk.agent.key_mismatch`.",
571        example: "agent Counter {\n\
572                  \x20 key id: String\n\
573                  \x20 store n: Cell[Int]\n\
574                  \n\
575                  \x20 on call get() -> Effect[Int] {\n\
576                  \x20   n\n\
577                  \x20 }\n\
578                  }\n\
579                  \n\
580                  let v <- Counter(\"a\", \"b\").get()   // ✗ one key, two arguments\n\
581                  let v <- Counter(\"a\").get()         // ✓ one key",
582    },
583    Explain {
584        code: "bynk.agent.handler_arity",
585        blurb: "A handler call is checked against the handler's declaration, as a function \
586                call is: it must pass one argument for each parameter, no more and no fewer. \
587                The agent's key is not one of them, since it was given when the agent was \
588                constructed. Match the call to the parameter list. If the handler is missing a \
589                parameter it needs, add it to the declaration and update every caller.",
590        example: "agent Counter {\n\
591                  \x20 key id: String\n\
592                  \x20 store n: Cell[Int]\n\
593                  \n\
594                  \x20 on call get() -> Effect[Int] {\n\
595                  \x20   n\n\
596                  \x20 }\n\
597                  }\n\
598                  \n\
599                  let v <- Counter(\"a\").get(1)   // ✗ `get` takes no arguments\n\
600                  let v <- Counter(\"a\").get()    // ✓",
601    },
602    Explain {
603        code: "bynk.agent.handler_not_found",
604        blurb: "An agent is used through the handlers it declares with `on call`, so a method \
605                name it does not declare is a mistake: usually a misspelling, or a handler that \
606                was never written. Check the name against the agent's declaration, or add the \
607                handler. To read a `store` field from a caller, add a handler that returns it.",
608        example: "agent Counter {\n\
609                  \x20 key id: String\n\
610                  \x20 store n: Cell[Int]\n\
611                  \n\
612                  \x20 on call get() -> Effect[Int] {\n\
613                  \x20   n\n\
614                  \x20 }\n\
615                  }\n\
616                  \n\
617                  let v <- Counter(\"a\").nope()   // ✗ `Counter` declares no `nope`\n\
618                  let v <- Counter(\"a\").get()    // ✓ a declared handler",
619    },
620    Explain {
621        code: "bynk.agent.key_mismatch",
622        blurb: "The key is what picks an instance, so its type is fixed by the agent: the type \
623                of its `key` field. An agent keyed by `String` cannot be addressed by an `Int`, \
624                because `1` and `\"1\"` would otherwise be easy to confuse and could name \
625                different instances. Pass a value of the key's type. The number of key \
626                arguments is `bynk.agent.construction_arity`.",
627        example: "agent Counter {\n\
628                  \x20 key id: String\n\
629                  \x20 store n: Cell[Int]\n\
630                  \n\
631                  \x20 on call get() -> Effect[Int] {\n\
632                  \x20   n\n\
633                  \x20 }\n\
634                  }\n\
635                  \n\
636                  let v <- Counter(1).get()     // ✗ the key is a `String`\n\
637                  let v <- Counter(\"a\").get()   // ✓",
638    },
639    Explain {
640        code: "bynk.agent.migrate_duplicate",
641        blurb: "A stored record carries the schema version it was written at, and is loaded through the one `migrate from N` step for that version. Two steps for the same `N` would leave the compiler to choose between them, so the second is refused. Merge them into one step that assigns every field the move from version `N` needs. A step that assigns one field twice is `bynk.agent.migrate_duplicate_assignment`.",
642        example: "type CartV1 = { owner: String, total: Int }\n\nmigrate from 1 (old: CartV1) {\n    ownerName := old.owner\n}\nmigrate from 1 (old: CartV1) {    // ✗ version 1 again\n    totalCents := old.total * 100\n}\n\nmigrate from 1 (old: CartV1) {\n    ownerName := old.owner\n    totalCents := old.total * 100    // ✓ one step does both\n}",
643    },
644    Explain {
645        code: "bynk.agent.migrate_duplicate_assignment",
646        blurb: "A migration step builds the new state like a record literal: each `store` field takes at most one value. A bare field name in the body reads the value carried over, never an earlier assignment, so a second `:=` to a field cannot build on the first and is refused. Combine the two into one expression of `old` and the carried fields. Two steps for one version is `bynk.agent.migrate_duplicate`.",
647        example: "type CartV1 = { owner: String, total: Int }\n\nmigrate from 1 (old: CartV1) {\n    totalCents := old.total\n    totalCents := old.total * 100    // ✗ `totalCents` again\n}\n\nmigrate from 1 (old: CartV1) {\n    totalCents := old.total * 100    // ✓ one value\n}",
648    },
649    Explain {
650        code: "bynk.agent.migrate_impure",
651        blurb: "A migration step must be pure and must not read the agent's key. A migration sweep wakes each stored instance by its object ID, which does not recover the key, so a step cannot depend on who the instance is, and it cannot use `?`, `expect` or `Effect.pure`. Compute the new value from `old` and the carried fields. If it needs the key, do that in a handler after the migration.",
652        example: "type CartV1 = { owner: String, total: Int }\n\nmigrate from 1 (old: CartV1) {\n    ownerName := id    // ✗ reads the agent's key\n}\n\nmigrate from 1 (old: CartV1) {\n    ownerName := old.owner    // ✓\n}",
653    },
654    Explain {
655        code: "bynk.agent.migrate_incomplete",
656        blurb: "A `migrate from N` step must account for every change between version `N` and the \
657                agent's current shape. A field that is gone has to be read through `old` or \
658                discarded on purpose with `drop`, and a field that changed type has to be \
659                assigned. Otherwise stored data would be carried over silently incomplete. A \
660                `Set`, `Log` or `Cache` field that changed can only be dropped, which starts it \
661                afresh. The message lists what the step leaves out. Read each removed field, \
662                `drop` the ones you mean to lose, and assign the retyped ones.",
663        example: "migrate from 1 (old: CartV1) {      // ✗ the removed `total` is neither read nor dropped\n\
664                  \x20\x20ownerName := old.owner\n\
665                  }\n\
666                  \n\
667                  migrate from 1 (old: CartV1) {\n\
668                  \x20\x20ownerName := old.owner\n\
669                  \x20\x20drop total                         // ✓ discarded on purpose\n\
670                  }",
671    },
672    Explain {
673        code: "bynk.agent.migrate_shape_mismatch",
674        blurb: "A `migrate from N (old: T)` step reads a stored record through `T`, so `T` must \
675                describe the shape version `N` recorded in bynk.schema.lock, which is not \
676                necessarily the shape the code has now. The compiler checks each field of `T` \
677                against that record: its storage kind and its type must match what was stored, and \
678                a field the class never had is refused too. A `drop` of a field that exists \
679                neither then nor now is refused as well. Declare the old type exactly as version \
680                `N` stored it, and give a nested type that has changed since its own copy. Keep \
681                such types for the step alone.",
682        example: "type CartV1 = { owner: Int }      // ✗ version 1 recorded `owner` as a `String`\n\
683                  \n\
684                  type CartV1 = { owner: String }   // ✓ as version 1 stored it",
685    },
686    Explain {
687        code: "bynk.agent.migrate_unknown_version",
688        blurb: "A migrate step reads an older recorded version of the agent's state and carries it \
689                to the current shape. bynk.schema.lock records the versions an agent class has \
690                had, so `from N` must name one of them below the current version, which needs no \
691                step. A step from the current version, or from one the lock never recorded, has \
692                nothing to read. The message gives the range the lock holds. A class with no \
693                history yet, and an unchanged shape, need no step at all. Change the shape first, \
694                build to record the new version, then write the step `from` the version it \
695                replaces.",
696        example: "agent Cart {\n\
697                  \x20\x20key id: String\n\
698                  \n\
699                  \x20\x20store owner: Cell[String]\n\
700                  \n\
701                  \x20\x20migrate from 1 (old: CartV1) {     // ✗ the lock records only version 1, the current one\n\
702                  \x20\x20\x20\x20owner := old.owner\n\
703                  \x20\x20}\n\
704                  }\n\
705                  \n\
706                  agent Cart {\n\
707                  \x20\x20key id: String\n\
708                  \n\
709                  \x20\x20store owner: Cell[String]          // ✓ unchanged since version 1, so no step is needed\n\
710                  }",
711    },
712    Explain {
713        code: "bynk.agent.non_additive_state_change",
714        blurb: "bynk.schema.lock records the stored shape of every agent class, version by version, and a build compares the new shape against it. A deployed instance holds data in the recorded shape, so a change that data can still be read through, such as a new field, is additive and just bumps the version. A change it cannot be read through, such as a field removed, retyped or renamed, would orphan or misread what is stored, so the build refuses it. A rename looks like a removal plus an addition, and the message names the pairing it infers. Give an added record field a default, keep the old field and add the new one, or carry the data across with a `migrate from N` step, which records the change as a non-additive version. For a class that was never deployed, delete its entry from the schema lock, and the next build records the new shape afresh.",
715        example: "agent Cart {                        // ✗ `owner` is gone: its stored value would be orphaned\n\
716                  \x20\x20key id: String\n\
717                  \n\
718                  \x20\x20store ownerName: Cell[String]\n\
719                  }\n\
720                  \n\
721                  agent Cart {\n\
722                  \x20\x20key id: String\n\
723                  \n\
724                  \x20\x20store owner: Cell[String]\n\
725                  \x20\x20store note: Cell[String]        // ✓ a new field is additive\n\
726                  }",
727    },
728    Explain {
729        code: "bynk.agent.outside_context",
730        blurb: "An agent holds state, and a context is the unit that owns it. A `commons` is \
731                code shared between contexts, which each `uses` it, so it is not given an agent, \
732                a service, an actor or a capability: those are only allowed in a `context`. \
733                Declare the agent in a context. A type the agent and other contexts both need \
734                can stay in the commons.",
735        example: "commons shop\n\
736                  \n\
737                  agent Counter { … }   // ✗ a commons has no state\n\
738                  \n\
739                  context shop\n\
740                  \n\
741                  agent Counter { … }   // ✓ a context owns it",
742    },
743    Explain {
744        code: "bynk.agent.removed_live",
745        blurb: "`removed agent Cart` tells the next deploy to delete the class `Cart` and all of its stored data. While `Cart` is still declared, that would delete the data of a class the code still uses, so the two together are refused. Delete the `agent Cart` declaration; the data goes at the next deploy, once you confirm it by name. If the class should stay, delete the `removed agent` line instead.",
746        example: "removed agent Cart    // ✗ `Cart` is still declared\nagent Cart { … }\n\nremoved agent Cart\nagent Basket { … }    // ✓ `Cart` is gone",
747    },
748    Explain {
749        code: "bynk.agent.replaces_live",
750        blurb: "`agent New replaces Old` renames a class: `Old`'s stored data moves to `New`. While `Old` is still declared, both would claim that data, so it is refused. To rename, delete the `Old` declaration. If the two are separate classes, drop `replaces`. Each old name has one fate, as `bynk.agent.class_conflict` says.",
751        example: "agent Cart { … }\nagent Basket replaces Cart { … }    // ✗ `Cart` is still declared\nagent Basket { … }                  // ✓ a separate class; delete `Cart` to rename it",
752    },
753    Explain {
754        code: "bynk.agent.replaces_unknown",
755        blurb: "`agent New replaces Old` renames a class: `Old`'s stored data and its recorded \
756                history move to `New`. That only works for a class bynk.schema.lock records for \
757                this context, so a misspelt old name, or a class that was never built with this \
758                context, is refused rather than quietly starting `New` from nothing. Check the old \
759                name against the `[agents.\"…\"]` entries in the lock. The old class must also be \
760                gone from source, as `bynk.agent.replaces_live` requires.",
761        example: "agent Basket replaces Trolley {   // ✗ the lock records no class `shop.Trolley`\n\
762                  \n\
763                  agent Basket replaces Cart {      // ✓ a recorded class, and no longer declared",
764    },
765    Explain {
766        code: "bynk.agent.return_not_effect",
767        blurb: "An agent handler reads and writes the agent's stored state, and may call other \
768                agents and capabilities, so it does work in the world, not just compute a \
769                value. Bynk marks that in the type: a handler must return `Effect[T]`, and its \
770                caller takes the result with `<-`. A bare `Int` would claim the handler is pure. \
771                Wrap the return type in `Effect`. A plain `fn`, which really is pure, returns an \
772                ordinary value.",
773        example: "on call get() -> Int {           // ✗ a handler that reads state is an effect\n\
774                  \x20 n\n\
775                  }\n\
776                  \n\
777                  on call get() -> Effect[Int] {   // ✓\n\
778                  \x20 n\n\
779                  }",
780    },
781    Explain {
782        code: "bynk.agent.state_name_conflict",
783        blurb: "Inside an agent's handlers and invariants, `<Agent>State` names the record of the \
784                agent's `Cell` fields: for agent `Counter`, `CounterState`. A type you declare \
785                with that name would be silently replaced there, so the compiler refuses it \
786                instead of renaming anything: unlike the names it derives elsewhere, this one \
787                can be written in a program. Rename your type.",
788        example: "type CounterState = { label: String }   // ✗ the name of `Counter`'s state record\n\n\
789                  type CounterLabel = { label: String }   // ✓ any other name\n\n\
790                  agent Counter {\n\
791                  \x20 key id: String\n\
792                  \x20 store n: Cell[Int]\n\
793                  \n\
794                  \x20 on call add(k: Int) -> Effect[Int] { k }\n\
795                  }",
796    },
797    Explain {
798        code: "bynk.agents.bad_state_initialiser",
799        blurb: "A key's state is initialised automatically the first time it is used, before any handler runs, so a `store` field's `= value` must be fixed when the program compiles: a literal, a variant, `Some`/`None`/`Ok`/`Err`, a record, or `T.unsafe(lit)` for an opaque type. It cannot read `self`, a parameter or a capability, or call anything. The code is also reported for a static value of the wrong type. Write the starting value out, and set the real one from a handler. A field with no initialiser and no zero is `bynk.agents.non_zeroable_state_field`.",
800        example: "store label: Cell[String] = self.id   // ✗ `self` is not available to an initialiser\n\nstore label: Cell[String] = \"\"   // ✓ a static starting value",
801    },
802    Explain {
803        code: "bynk.agents.non_zeroable_state_field",
804        blurb: "A key that has never been used is initialised automatically the first time it is touched, so every `store Cell[T]` field needs a starting value. With no initialiser, the compiler supplies a zero (`0`, `false`, `\"\"`, `None`, or a record of zeroed fields), but only where that zero is a valid value of the type. An opaque type, a sum other than `Option`, and a refined type that rules its zero out have none, and the compiler will not invent a value that the type's own constructors might refuse. Say what \"not set yet\" means: wrap the type in `Option`, where `None` is the zero, give the field an initialiser, `store name: Cell[T] = value`, or relax a refinement so that its zero is allowed (`NonNegative` admits `0`; `Positive` does not).",
805        example: "type Secret = opaque String\n\n\
806                  store secret: Cell[Secret]                // ✗ no zero value for an opaque type\n\n\
807                  store secret: Cell[Option[Secret]]        // ✓ `None` until it is set",
808    },
809    Explain {
810        code: "bynk.asset.duplicate",
811        blurb: "An asset is a name for a file, read as a value (`style.url`), so a unit declares each \
812                name once: a second `asset style` would leave `style` meaning two files. Give each \
813                asset its own name, or drop the repeat when it names the same file. An asset whose \
814                name is a function's or a type's is `bynk.resolve.name_conflict` instead.",
815        example: "asset style = \"assets/board.css\"\nasset style = \"assets/print.css\"    // ✗ `style` is already declared\n\nasset style = \"assets/board.css\"\nasset print = \"assets/print.css\"    // ✓ one name each",
816    },
817    Explain {
818        code: "bynk.asset.invalid_at_path",
819        blurb: "`at` serves an asset at a fixed URL, for clients that ask for a file by name, such as \
820                `/favicon.ico`, so the path must be the URL of one file: it starts with `/`, does not \
821                end in `/`, and uses only letters, digits and `._~-` between its slashes. It may \
822                not be under `/_assets/` or `/_bynk/`, which Bynk uses itself, nor be `/_headers`, \
823                `/_redirects` or `/.assetsignore`, which the platform reads as configuration. \
824                Write the path of a single file.",
825        example: "asset favicon = \"assets/favicon.ico\" at \"/icons/\"          // ✗ a folder, not a file\n\nasset favicon = \"assets/favicon.ico\" at \"/favicon.ico\"    // ✓",
826    },
827    Explain {
828        code: "bynk.asset.missing_file",
829        blurb: "An `asset` is a file the build ships, and the compiler reads it to hash its contents \
830                into the asset's URL, so the file must exist when the project is built. The path is \
831                relative to the project root and must name a regular file; a symbolic link is not \
832                followed. Create the file under `assets/`, or correct the path. A file that exists \
833                but cannot be read is `bynk.asset.unreadable_file`.",
834        example: "asset style = \"assets/board.css\"        // ✗ no such file in the project\n\
835                asset style = \"assets/board.css\"        // ✓ once assets/board.css exists",
836    },
837    Explain {
838        code: "bynk.asset.outside_assets_dir",
839        blurb: "An asset is served to anyone who asks, without the Worker running, so it may come \
840                only from the project's `assets/` folder. If any path were allowed, a declaration \
841                could publish `.env` or a source file just by naming it. Move or copy the file into \
842                `assets/` and name it there. A path that is absolute or contains `..` is \
843                `bynk.asset.unsafe_path` instead.",
844        example: "asset style = \"styles/board.css\"        // ✗ not in the assets/ folder\n\
845                asset style = \"assets/board.css\"        // ✓",
846    },
847    Explain {
848        code: "bynk.asset.outside_context_or_commons",
849        blurb: "An `asset` is a file the platform serves, shipped with each context that declares it or `uses` a commons that does. An adapter is the host boundary, not a deployed unit of its own, so an `asset` there is refused. Declare it in a context or a commons. For text compiled into the program rather than served, see `bynk.embed.outside_context_or_commons`.",
850        example: "// app/host.bynk\nadapter app.host\n\nbinding \"./host.binding.ts\"\n\nasset style = \"assets/board.css\"        // ✗ an adapter cannot declare an asset\n\n// app/page.bynk\ncommons app.page\n\nasset style = \"assets/board.css\"        // ✓ in a commons",
851    },
852    Explain {
853        code: "bynk.asset.path_conflict",
854        blurb: "A fixed asset path names one file, and a Worker serves one file at it, so two assets \
855                cannot both claim `/legal.txt`. One path cannot be a folder of another either, as \
856                `/logo` and `/logo/icon.png` would be: a name cannot be both a file and a \
857                directory. Give each asset its own path. Two assets for the same file at the same \
858                path are no conflict. A route at an asset's path is `bynk.asset.shadows_route`.",
859        example: "asset terms = \"assets/a.txt\" at \"/legal.txt\"\nasset privacy = \"assets/b.txt\" at \"/legal.txt\"    // ✗ a second file at `/legal.txt`\n\nasset terms = \"assets/a.txt\" at \"/terms.txt\"\nasset privacy = \"assets/b.txt\" at \"/privacy.txt\"    // ✓",
860    },
861    Explain {
862        code: "bynk.asset.shadows_route",
863        blurb: "The platform answers a fixed asset's path before the Worker runs, and it does so for \
864                every method, so an HTTP handler at exactly that path can never be reached. The \
865                compiler refuses it rather than ship a route that never runs. Move the route, or \
866                give the asset another path. A route with a parameter that matches the asset's \
867                path, such as `/:page`, still serves every other path, and is only the warning \
868                `bynk.asset.may_shadow_route`. The members of a `[deploy.workers.<key>]` group \
869                share one assets directory, so an asset in one member shadows a route of the \
870                same path in another.",
871        example: "asset favicon = \"assets/favicon.ico\" at \"/favicon.ico\"\n\nservice web from http {\n    on GET(\"/favicon.ico\") () -> Effect[HttpResult[String]] by Visitor {    // ✗ the asset answers first\n        Ok(\"never reached\")\n    }\n}\n\nservice web from http {\n    on GET(\"/health\") () -> Effect[HttpResult[String]] by Visitor {    // ✓\n        Ok(\"ok\")\n    }\n}",
872    },
873    Explain {
874        code: "bynk.asset.unsafe_path",
875        blurb: "An asset's path must stay inside the project: it may not be empty or absolute, and it \
876                may not contain a `..` segment. Assets are public, so a path that starts at the filesystem \
877                root or climbs out of the project could publish a file that was never meant to ship. \
878                Write the path relative to the project root, inside `assets/`. A relative path that \
879                is only outside `assets/` is `bynk.asset.outside_assets_dir`.",
880        example: "asset style = \"assets/../board.css\"     // ✗ a `..` segment\n\
881                asset style = \"assets/board.css\"        // ✓",
882    },
883    Explain {
884        code: "bynk.boundary.ambiguous_type",
885        blurb: "A context can export a record whose field has a type it does not export. Reading that field through a value you got from it needs the field's type, and if two contexts you consume each declare a type of that name with different shapes, the compiler cannot tell which is meant. Rename one of the two so a name stands for one shape across the contexts you consume.",
886        example: "// shop/quotes.bynk\ntype Amount = { cents: Int }\ntype Wrap = { inner: Amount }\n\n// shop/other.bynk\ntype Amount = { dollars: Int }\n\n// shop/till.bynk\nconsumes shop.quotes\nconsumes shop.other\n\n    let w <- shop.quotes.wrap()\n    Effect.pure(w.inner.cents)           // ✗ which `Amount` is `inner`?\n\n// shop/other.bynk\ntype Price = { dollars: Int }            // ✓ one name, one shape",
887    },
888    Explain {
889        code: "bynk.boundary.structural_mismatch",
890        blurb: "A value that crosses a context boundary, as an argument to a consumed context's \
891                service or as its result, is matched by shape, not by name. So where both \
892                contexts declare a `Box`, the two must have the same shape, or the value is not \
893                a `Box` on the other side. Give them the same fields, or rename one so the names \
894                stop meeting. A type both sides need can live in a `commons` that each `uses`.",
895        example: "// shop.bynk\n\
896                  context shop\n\
897                  \n\
898                  type Box = { weight: Int }\n\
899                  \n\
900                  service weigh {\n    on call(b: Box) -> Effect[Int] by Caller { … }\n\
901                  }\n\
902                  \n\
903                  // depot.bynk\n\
904                  context depot\n\
905                  \n\
906                  consumes shop\n\
907                  \n\
908                  type Box = { label: String }\n\
909                  \n\
910                  shop.weigh(Box { label: \"a\" })        // ✗ a `depot` `Box` is not shaped like `shop`'s\n\
911                  \n\
912                  type Box = { weight: Int }\n\
913                  \n\
914                  shop.weigh(Box { weight: 3 })         // ✓ the same shape on both sides",
915    },
916    Explain {
917        code: "bynk.capability.base_not_instantiable",
918        blurb: "A derived capability is another instance of a platform resource, with a namespace, bucket or limiter of its own. Only a platform resource kind, such as `Kv` or `R2`, has instances. A capability such as `Clock` has no resource to separate, so there is nothing to derive; use it bare, with `given Clock`.",
919        example: "consumes bynk { Clock }\n\ncapability Ticks = Clock   // ✗ `Clock` has no named instances\n\nservice probe {\n    on call() -> Effect[Instant] by Caller given Clock {   // ✓ use it bare\n        Clock.now()\n    }\n}",
920    },
921    Explain {
922        code: "bynk.capability.derived_outside_context",
923        blurb: "A derived capability is an instance of a platform resource, and the resource's data belongs to a context. An adapter only describes a boundary to foreign code, so it has no data to own. Declare the instance in a context that selects the base with `consumes`.",
924        example: "adapter cache {\n    binding \"./cache.binding.ts\"\n    consumes bynk.cloudflare { Kv }\n    capability Sessions = Kv    // ✗ an adapter cannot own an instance\n}\n\ncontext cache {\n    consumes bynk.cloudflare { Kv }\n    capability Sessions = Kv    // ✓ a context owns its data\n}",
925    },
926    Explain {
927        code: "bynk.capability.instance_only",
928        blurb: "A few platform capabilities (`Service`, `R2`, `RateLimit`, `Queue`, `Analytics`, \
929                `D1` and `EdgeCache`) are never used as the bare kind. Each stands for a \
930                particular resource of its own: a database, a bucket, a limiter with a limit \
931                and a window, a Worker. So you declare a named instance, \
932                `capability Orders = D1`, which gets a binding and a double of its own, and a \
933                handler asks for that instance in `given` instead of the kind. Two instances of \
934                one kind never share data. Some kinds need options on the instance, such as \
935                `RateLimit @limit(20) @period(60.seconds)`.",
936        example: "on call() -> Effect[()] by Caller given D1 {            // ✗ the bare kind names no database\n\n\
937                  capability Orders = D1\n\
938                  on call() -> Effect[()] by Caller given Orders {        // ✓ a named instance",
939    },
940    Explain {
941        code: "bynk.capability.invalid_option",
942        blurb: "A derived capability, `capability Name = Kind`, can take options after the kind, each \
943                one positional literal that the compiler reads while it checks the program: \
944                `Service` takes `@worker(\"name\")`, `R2` an optional `@jurisdiction(\"eu\")`, \
945                `RateLimit` a `@limit(n)` and a `@period(d)`, and `Queue` a `@name(\"queue\")`. \
946                The value must be a literal of the option's kind, and one the platform accepts: \
947                `@limit` a positive `Int`, `@period` `10.seconds` or `60.seconds`, \
948                `@jurisdiction` `\"eu\"` or `\"fedramp\"`, `@tls` (on a `MySql`) `\"required\"`, \
949                `\"verify-ca\"` or `\"verify-identity\"`, `@worker` a Worker name and `@name` a \
950                queue name, each of 1 to 63 lowercase letters, digits and `-` (a Worker name \
951                may also hold `_`). Each option is given once, and an `@worker` must name a Worker \
952                outside the project, since a context of your own is reached with `consumes`. A bad \
953                value would otherwise surface only when the platform refuses the deployment, so \
954                it is refused here. Use one of the values the note lists. `RateLimit` is \
955                experimental, so the project opts in under `[unstable]` in `bynk.toml`.",
956        example: "// bynk.toml\n\
957                  [unstable]\n\
958                  allow = [\"bynk.cloudflare.RateLimit\"]\n\n\
959                  // login.bynk\n\
960                  context login\n\n\
961                  consumes bynk.cloudflare { RateLimit }\n\n\
962                  capability LoginLimit = RateLimit @limit(20) @period(30.seconds)    // ✗ a window is 10 or 60 seconds\n\
963                  capability LoginLimit = RateLimit @limit(20) @period(60.seconds)    // ✓",
964    },
965    Explain {
966        code: "bynk.capability.missing_option",
967        blurb: "A derived capability, `capability Name = Kind`, takes its configuration from \
968                options after the kind, and some kinds cannot work without them: a `Service` \
969                needs the Worker it reaches, `@worker(…)`, a `Queue` its `@name(…)`, a \
970                `RateLimit` its `@limit(…)` and `@period(…)`, and a `StoredSecret` its \
971                `@store(…)` and `@secret(…)`. There is no default. Write the options the note \
972                shows. A value the platform would refuse is `bynk.capability.invalid_option`; an \
973                option the kind does not take is `bynk.capability.unknown_option`.",
974        example: "// bynk.toml\n\
975                  [unstable]\n\
976                  allow = [\"bynk.cloudflare.Queue\"]\n\
977                  \n\
978                  // orders.bynk\n\
979                  context orders\n\
980                  \n\
981                  consumes bynk.cloudflare { Queue }\n\
982                  \n\
983                  capability OrderEvents = Queue                        // ✗ a queue must be named\n\
984                  capability OrderEvents = Queue @name(\"order-events\")  // ✓",
985    },
986    Explain {
987        code: "bynk.capability.not_provided",
988        blurb: "On the Workers target, each context is its own Worker, and a Worker builds every \
989                capability its handlers are given. A handler's `given Mailer` therefore needs a \
990                `provides Mailer = …` in the same context, which says what the capability does \
991                there. Without one the Worker has nothing to hand the handler, so the compiler \
992                refuses it here and does not leave it to fail in the generated TypeScript. The \
993                bundle target (the default) asks only when the program has a composition root \
994                (`composeApp`), which it has once a context consumes another context's service or \
995                capability, emits events, or derives a capability: `composeApp` builds every \
996                context itself, so nothing else can supply the capability, and a test `stub` \
997                covers only the cases that stub it. Without a root, the host program can supply \
998                the capability when it builds the surface. A capability declared in another context is \
999                that context's to provide, and an exported capability with no provider has its own \
1000                `bynk.exports.capability_not_provided`. Add a provider to the context, or, on \
1001                Workers, build for `--target bundle` when the bundle has no composition root.",
1002        example: "service notify {\n\
1003                  \x20\x20on call(to: String) -> Effect[()] by Caller given Mailer {   // ✗ no `provides Mailer` in this context\n\
1004                  \x20\x20\x20\x20Mailer.send(to)\n\
1005                  \x20\x20}\n\
1006                  }\n\
1007                  \n\
1008                  provides Mailer = Smtp {                              // ✓ a provider, so the Worker can build it\n\
1009                  \x20\x20fn send(to: String) -> Effect[()] {\n\
1010                  \x20\x20\x20\x20Effect.pure(())\n\
1011                  \x20\x20}\n\
1012                  }",
1013    },
1014    Explain {
1015        code: "bynk.capability.op_arity",
1016        blurb: "A call to a capability operation passes exactly the parameters its declaration \
1017                lists, so `Clock.now(1)` against `fn now() -> Effect[Int]` has one argument too \
1018                many. Pass the declared number of arguments. If the operation really needs another \
1019                parameter, add it to the capability's declaration and to every provider of it.",
1020        example: "capability Clock {\n\
1021                \x20 fn now() -> Effect[Int]\n\
1022                }\n\
1023                \n\
1024                Clock.now(1)                            // ✗ `now` takes no arguments\n\
1025                Clock.now()                             // ✓",
1026    },
1027    Explain {
1028        code: "bynk.capability.outside_context",
1029        blurb: "A capability is a typed interface to the outside world: a context declares it, \
1030                provides it and asks for it in `given`, and the compiler wires the provider to the \
1031                services that need it. A commons holds only pure declarations, so it cannot declare \
1032                one. Move the capability into the context that uses it, or, for one several contexts \
1033                share, into a context that exports it.",
1034        example: "commons demo\n\
1035                \n\
1036                capability Logger {                     // ✗ a commons cannot declare a capability\n\
1037                \x20 fn log(message: String) -> Effect[()]\n\
1038                }\n\
1039                \n\
1040                context demo\n\
1041                \n\
1042                capability Logger {                     // ✓ a context can\n\
1043                \x20 fn log(message: String) -> Effect[()]\n\
1044                }",
1045    },
1046    Explain {
1047        code: "bynk.capability.provider_agent_cross_context",
1048        blurb: "On the Workers target, each context is its own Worker with its own `env`, and a \
1049                Worker builds the capabilities its handlers are given. If a context requires a \
1050                capability that another context provides, it builds that provider in its own \
1051                Worker. When that provider constructs agents of the context it lives in, it needs \
1052                the Durable Object bindings of that context, which the consumer's `env` does not \
1053                have, so the build would fail, or `bynk dev` would quietly keep the agent's state \
1054                in the isolate. The compiler refuses the requirement instead. Reach the agents \
1055                through a service of the providing context, which runs in its own Worker beside \
1056                its own bindings, or build for `--target bundle`, where every context shares one \
1057                process.",
1058        example: "// registry.bynk\n\
1059                  provides Yanks = AgentYanks {\n\
1060                  \x20\x20fn set(value: Bool) -> Effect[Bool] {\n\
1061                  \x20\x20\x20\x20PackageIndex(\"x\").setYanked(value)   // the provider constructs `registry`'s own agent\n\
1062                  \x20\x20}\n\
1063                  }\n\
1064                  \n\
1065                  // api.bynk\n\
1066                  service yank {\n\
1067                  \x20\x20on call() -> Effect[Bool] by Caller given registry.Yanks {   // ✗ `api`'s Worker would build that provider\n\
1068                  \x20\x20\x20\x20registry.Yanks.set(true)\n\
1069                  \x20\x20}\n\
1070                  }\n\
1071                  \n\
1072                  // api.bynk\n\
1073                  service yank {\n\
1074                  \x20\x20on call() -> Effect[Bool] by Caller {\n\
1075                  \x20\x20\x20\x20registry.yank(true)                              // ✓ a service of `registry`, run in its own Worker\n\
1076                  \x20\x20}\n\
1077                  }",
1078    },
1079    Explain {
1080        code: "bynk.capability.unknown_base",
1081        blurb: "`capability Sessions = Kv` makes a separate instance of a platform capability, so the base has to be one the context has selected: `consumes bynk.cloudflare { Kv }`. A name that is not selected is a misspelling, or a `consumes` that was left out. Correct the name, or select the capability.",
1082        example: "consumes bynk.cloudflare { Kv }\n\ncapability Sessions = Kvv   // ✗ no capability `Kvv` is selected\n\ncapability Sessions = Kv    // ✓ the one that is",
1083    },
1084    Explain {
1085        code: "bynk.capability.unknown_operation",
1086        blurb: "A capability is an interface: its operations are exactly the `fn` signatures in its \
1087                declaration, and a provider supplies nothing more. Calling `Clock.nope()` asks for \
1088                an operation the capability does not declare, which usually means a misspelt name. \
1089                Call one of the declared operations, or add the new operation to the capability and \
1090                to each provider of it.",
1091        example: "capability Clock {\n\
1092                \x20 fn now() -> Effect[Int]\n\
1093                }\n\
1094                \n\
1095                Clock.nope()                            // ✗ `Clock` declares no `nope`\n\
1096                Clock.now()                             // ✓",
1097    },
1098    Explain {
1099        code: "bynk.capability.unknown_option",
1100        blurb: "An option after the kind in `capability Name = Kind @option(…)` must be one that \
1101                kind takes: `Service` takes `@worker`, `R2` `@jurisdiction`, `RateLimit` \
1102                `@limit` and `@period`, `Queue` `@name`, `MySql` `@tls`, and `StoredSecret` `@store` and \
1103                `@secret`, while `Kv`, `Analytics`, `D1`, `EdgeCache` and `Postgres` take none. One the kind \
1104                does not take is refused rather than ignored, since it is probably a misspelling \
1105                or the wrong kind. Drop it, or use one of the options the note lists. An option \
1106                that is known but has a bad value is `bynk.capability.invalid_option`.",
1107        example: "capability Sessions = Kv @ttl          // ✗ `Kv` instances take no options\n\
1108                  capability Sessions = Kv               // ✓",
1109    },
1110    Explain {
1111        code: "bynk.cell.invalid_target",
1112        blurb: "A `:=` replaces the value of a `Cell`, the one store kind that holds a single value. A `Set`, `Map`, `Log` or `Cache` has no one value to replace; each changes through its own operations (`add`, `put`, `append`), and a name that is not a `store` field of the agent has nothing to write. Use the operation the field's kind offers, or declare the field `Cell[T]` if a single replaceable value is what you want. The same check covers a `migrate from` step that assigns a field.",
1113        example: "store ids: Set[Int]\n\nids := n               // ✗ a `Set` has no single value to replace\n\nlet _ <- ids.add(n)    // ✓ the operation the kind offers",
1114    },
1115    Explain {
1116        code: "bynk.cell.self_reference",
1117        blurb: "A `:=` writes a `Cell` store field, and its right-hand side may not read the cell \
1118                it is writing. Computing the new value from the old one is a hidden \
1119                read-modify-write; Bynk asks for `.update(fn)` instead, so the \
1120                dependency on the prior value is written down where a reader (and a \
1121                retry) can see it. A `:=` is for a value that does not depend on what \
1122                the cell held.",
1123        example: "count := count + 1                       // ✗ reads `count` while writing it\n\n\
1124                  let _ <- count.update((c) => c + 1)      // ✓ awaited, as an effect; the combiner gets the old value",
1125    },
1126    Explain {
1127        code: "bynk.cloudflare.edge_cache_duplicate",
1128        blurb: "Workers Cache is one setting for the whole Worker, and a context has one Worker, so a context declares at most one `EdgeCache` instance, which both turns the cache on and purges it. A second would be another handle on the same cache, so it is refused. Delete it and use the first instance wherever you need it, with `given`.",
1129        example: "capability Edge = EdgeCache\ncapability Cdn = EdgeCache    // ✗ one `EdgeCache` per context\n\ncapability Edge = EdgeCache   // ✓ use `Edge` everywhere",
1130    },
1131    Explain {
1132        code: "bynk.cloudflare.edge_cache_exported",
1133        blurb: "A capability you `export` is built by each context that consumes it, in that context's own Worker. A provider that reaches `EdgeCache` would purge from there, and a purge reaches only the cache of the Worker it runs in, so this context's cache would keep the stale response. Keep the capability inside the context and have a service route do the purge, which another context can reach by calling that service.",
1134        example: "exports capability { Takedown }\n\ncapability Edge = EdgeCache\n\ncapability Takedown {   // ✗ exported, but its provider purges through `Edge`\n    fn take(path: String) -> Effect[Bool]\n}\n\nprovides Takedown = Purging given Edge {\n    fn take(path: String) -> Effect[Bool] {\n        Edge.purge([path])\n    }\n}\n\nservice operator from http {\n    on POST(\"/purge/:hex\") (hex: String) -> Effect[HttpResult[Bool]] by v: Visitor given Edge {   // ✓ purge from a service handler\n        let purged <- Edge.purge([\"/dl/\\(hex)\"])\n        Ok(purged)\n    }\n}",
1135    },
1136    Explain {
1137        code: "bynk.cloudflare.edge_cache_in_agent",
1138        blurb: "A purge reaches the edge cache only when it runs in the Worker's own `fetch`. An agent runs in a Durable Object, so an agent handler that reaches `EdgeCache`, with `given Edge` or through a provider that does, would not reach this Worker's cache. Purge from the service handler that calls the agent. A queue consumer and an `on schedule` handler have the same rule: `bynk.cloudflare.edge_cache_in_queue`, `bynk.cloudflare.edge_cache_in_schedule`.",
1139        example: "capability Edge = EdgeCache\n\nagent Index {\n    key name: String\n\n    store hits: Cell[Int]\n\n    on call withdraw(path: String) -> Effect[Bool] given Edge {   // ✗ an agent's purge misses the Worker's cache\n        Edge.purge([path])\n    }\n}\n\nservice operator from http {\n    on POST(\"/purge/:hex\") (hex: String) -> Effect[HttpResult[Bool]] by v: Visitor given Edge {   // ✓ purge from a service handler\n        let purged <- Edge.purge([\"/dl/\\(hex)\"])\n        Ok(purged)\n    }\n}",
1140    },
1141    Explain {
1142        code: "bynk.cloudflare.edge_cache_in_queue",
1143        blurb: "A purge reaches the edge cache only from the Worker's own `fetch`, the entrypoint that serves cached responses. A queue consumer is not that entrypoint, and its purge is not known to reach the cache, so a consumer that reaches `EdgeCache`, with `given Edge` or through a provider that does, is refused. Purge from a service handler instead. An agent and an `on schedule` handler have the same rule: `bynk.cloudflare.edge_cache_in_agent`, `bynk.cloudflare.edge_cache_in_schedule`.",
1144        example: "capability Edge = EdgeCache\n\nservice purges from queue(\"purges\") {\n    on message(path: String) -> Effect[QueueResult] given Edge {   // ✗ not the entrypoint the cache serves\n        let purged <- Edge.purge([path])\n        if purged { Ack } else { Retry(\"refused\") }\n    }\n}\n\nservice operator from http {\n    on POST(\"/purge/:hex\") (hex: String) -> Effect[HttpResult[Bool]] by v: Visitor given Edge {   // ✓ purge from a service handler\n        let purged <- Edge.purge([\"/dl/\\(hex)\"])\n        Ok(purged)\n    }\n}",
1145    },
1146    Explain {
1147        code: "bynk.cloudflare.edge_cache_in_schedule",
1148        blurb: "A purge reaches the edge cache only from the Worker's own `fetch`. Cloudflare accepts a purge from a cron run, but it clears nothing from the cache that `fetch` serves, so the stale responses would stay. An `on schedule` handler that reaches `EdgeCache`, with `given Edge` or through a provider that does, is refused. Purge from a service handler instead. An agent and a queue consumer have the same rule: `bynk.cloudflare.edge_cache_in_agent`, `bynk.cloudflare.edge_cache_in_queue`.",
1149        example: "capability Edge = EdgeCache\n\nservice sweep from cron {\n    on schedule(\"0 * * * *\") () -> Effect[Result[(), String]] given Edge {   // ✗ a cron purge clears nothing\n        let purged <- Edge.purge([\"/dl/\"])\n        if purged { Ok(()) } else { Err(\"refused\") }\n    }\n}\n\nservice operator from http {\n    on POST(\"/purge/:hex\") (hex: String) -> Effect[HttpResult[Bool]] by v: Visitor given Edge {   // ✓ purge from a service handler\n        let purged <- Edge.purge([\"/dl/\\(hex)\"])\n        Ok(purged)\n    }\n}",
1150    },
1151    Explain {
1152        code: "bynk.cloudflare.edge_cache_public_authenticated",
1153        blurb: "In a context with `EdgeCache`, the edge keys a response by its URL alone, and `scope: public` lets it share one response with every later caller. On a route whose actor authenticates, such as a `Bearer` one, that response belongs to one caller, so it would be served to the rest. Use `scope: private`, which is never shared at the edge, or serve the route `by Visitor`. See also `bynk.http.cache_public_reads_cookies`.",
1154        example: "type MemberId = opaque String\n\nactor Member { auth = Bearer(secret = \"AUTH_SECRET\"), identity = MemberId }\n\n@cache(maxAge: 5.minutes, scope: public)\non GET(\"/me\") () -> Effect[HttpResult[String]] by m: Member { … }   // ✗ one member's response, shared with all\n\n@cache(maxAge: 5.minutes, scope: private)   // ✓\non GET(\"/me\") () -> Effect[HttpResult[String]] by m: Member { … }",
1155    },
1156    Explain {
1157        code: "bynk.consumes.alias_conflict",
1158        blurb: "`consumes payment as Pay` gives a context one name to call a unit by, and a name for one unit. Two clauses with the same alias, a unit consumed under two aliases, or an alias that is also a type, function, capability, service or agent of this context, would leave a call such as `Pay.charge(…)` with no single meaning. Give each clause its own alias, or drop it. The same clause in another file of the context is fine.",
1159        example: "// shop.bynk\ncontext shop\n\nconsumes payment as Pay\nconsumes shipping as Pay     // ✗ `Pay` already names `payment`\n\nconsumes payment as Pay\nconsumes shipping as Ship    // ✓ one name each",
1160    },
1161    Explain {
1162        code: "bynk.consumes.capability_name_clash",
1163        blurb: "`consumes payment { Gateway }` brings `Gateway` in by its bare name, so that `given Gateway` reads it. If the context already declares a capability of that name, or a second consumed unit supplies one, the bare name would mean two things. Reach it qualified instead, `given payment.Gateway`, rename the local one, or consume the unit under an alias instead of selecting names from it, `consumes payment as pay`, and write `given pay.Gateway`.",
1164        example: "// shop.bynk\ncontext shop\n\nconsumes payment { Gateway }    // ✗ this context declares a `Gateway` too\n\ncapability Gateway {\n    fn notify() -> Effect[()]\n}\n\nconsumes payment                // ✓ reach it as `payment.Gateway`",
1165    },
1166    Explain {
1167        code: "bynk.consumes.capability_not_selected",
1168        blurb: "Imports are per file, for capabilities as for types. A braced `consumes U { Cap }` brings the capability `Cap` into scope as a bare name, but only in the file that writes it: a `given Cap` clause, a call `Cap.op(…)`, a `provides Cap = …`, a derived capability's base, or a suite's `stub Cap.op`. A file that names one its own `consumes` does not list is an error; `bynk check --fix=bynk.consumes.capability_not_selected` adds the name to this file's `consumes`, or adds one. The unit's wiring and deploy order still follow the union of its files' `consumes`.",
1169        example: "// shop/context.bynk\nconsumes bynk { Clock }\n\n// shop/audit.bynk, another file of the same context\nservice stamp {\n    on call() -> Effect[Instant] by Caller given Clock {   // ✗ this file does not consume `bynk`\n        Clock.now()\n    }\n}\n\nconsumes bynk { Clock }                          // ✓ each file consumes what it names",
1170    },
1171    Explain {
1172        code: "bynk.consumes.name_conflict",
1173        blurb: "`consumes payment` brings every type that `payment` exports into scope under its \
1174                own name, because the services' signatures use them. If this context already has \
1175                something of that name, a type declared here or reached through `uses`, or a \
1176                function, asset, service, agent or provider, a mention would mean two things, so \
1177                the compiler refuses the clause. Rename the imported type with `as`: it is then \
1178                in scope only under the alias, and is still the same type. \
1179                `bynk.consumes.type_alias_conflict` is the same clash with an alias.",
1180        example: "// payment.bynk\n\
1181                  context payment\n\
1182                  \n\
1183                  exports transparent { Amount }\n\
1184                  \n\
1185                  // money.bynk\n\
1186                  commons money\n\
1187                  \n\
1188                  type Amount = Int where NonNegative\n\
1189                  \n\
1190                  // orders.bynk\n\
1191                  context orders\n\
1192                  \n\
1193                  uses money\n\
1194                  consumes payment                           // ✗ `Amount` is also in scope from `money`\n\
1195                  consumes payment { Amount as PayAmount }   // ✓ `PayAmount` is `payment`'s",
1196    },
1197    Explain {
1198        code: "bynk.consumes.self_reference",
1199        blurb: "`consumes` declares that a context depends on a different one. A context's own declarations are already in scope, so consuming itself adds nothing, and a context that depends on itself is a cycle of length one. Delete the clause, or, if you meant another context, name it. A cycle through several contexts is `bynk.context.consumes_cycle`.",
1200        example: "// pay.bynk\ncontext pay\n\n// shop.bynk\ncontext shop\n\nconsumes shop                    // ✗ a context cannot consume itself\nconsumes pay                     // ✓ a different context",
1201    },
1202    Explain {
1203        code: "bynk.consumes.service_arity",
1204        blurb: "A cross-context call has the shape of the `on call` handler it reaches: one argument for each parameter. The consumed context owns that signature, so the caller adapts to it. Pass the arguments the handler declares (the note says where it is declared), or change the handler's parameters if the service needs different input.",
1205        example: "// pay.bynk\ncontext pay\n\nservice charge {\n    on call(amount: Int) -> Effect[Int] by Caller {\n        Effect.pure(amount)\n    }\n}\n\n// shop.bynk\ncontext shop\n\nconsumes pay\n\nservice checkout {\n    on call() -> Effect[Int] by Caller {\n        pay.charge(1, 2)         // ✗ `charge` takes one argument\n    }\n}\n\nservice checkout {\n    on call() -> Effect[Int] by Caller {\n        pay.charge(1)            // ✓ one argument for `amount`\n    }\n}",
1206    },
1207    Explain {
1208        code: "bynk.consumes.signature_type_unconsumed",
1209        blurb: "A service you call may take or return a type declared in a third context. The value crosses the call as that context's type, so your context has to state the dependency itself: it does not inherit it from the service's context. Add `consumes` for the context the error names.",
1210        example: "// shop/ledger.bynk\nconsumes shop.order\n\nservice domestic {\n    on call(id: String) -> Effect[Order] by Caller { … }\n}\n\n// shop/front.bynk\nconsumes shop.ledger\n\n    let o <- shop.ledger.domestic(id)    // ✗ returns `Order`, from `shop.order`\n\nconsumes shop.ledger\nconsumes shop.order                      // ✓ the dependency is stated",
1211    },
1212    Explain {
1213        code: "bynk.consumes.target_is_commons",
1214        blurb: "`consumes` is for depending on a context, or on an adapter: it is how you call a service and use the capabilities the other unit exports. A commons has neither. It is shared types and functions, brought in with `uses`. Replace `consumes` with `uses`.",
1215        example: "// money.bynk\ncommons money\n\ntype Amount = Int where NonNegative\n\n// shop.bynk\ncontext shop\n\nconsumes money                   // ✗ `money` is a commons\nuses money                       // ✓ shared declarations come in with `uses`",
1216    },
1217    Explain {
1218        code: "bynk.consumes.type_alias_capability",
1219        blurb: "`as` renames a type that the consumed context exports, for use in this one. A capability keeps its own name wherever it is used, in `given` and in calls. Select it bare, `consumes payment { Gateway }`, or consume the context without braces and write `given payment.Gateway`.",
1220        example: "// payment.bynk\ncontext payment\n\nexports capability { Gateway }\n\n// shop.bynk\ncontext shop\n\nconsumes payment { Gateway as Pay }   // ✗ a capability cannot be aliased\n\nconsumes payment { Gateway }          // ✓ select it bare",
1221    },
1222    Explain {
1223        code: "bynk.consumes.type_alias_conflict",
1224        blurb: "An alias is a name in this context, so it cannot be one that is already taken: by another alias, by a type or function the context declares or brings in with `uses`, or by a capability. Give each aliased type a name of its own. A consumed type that is not aliased, and clashes with one of these, is `bynk.consumes.name_conflict`.",
1225        example: "// shop.bynk\ncontext shop\n\nconsumes payment { AuthId as Id, Receipt as Id }            // ✗ `Id` already names `AuthId`\n\nconsumes payment { AuthId as Id, Receipt as ReceiptId }     // ✓ distinct aliases",
1226    },
1227    Explain {
1228        code: "bynk.consumes.type_alias_repeated",
1229        blurb: "A type is in scope under one name, so it is selected once in a file: the alias is that name. Selecting it twice, or both bare and aliased, would leave two names for it. Keep one selection. The bare selection of a type is not needed, since `consumes payment` already brings every exported type into scope.",
1230        example: "// shop.bynk\ncontext shop\n\nconsumes payment { AuthId as A, AuthId as B }   // ✗ `AuthId` aliased twice\n\nconsumes payment { AuthId as Auth }             // ✓ one alias",
1231    },
1232    Explain {
1233        code: "bynk.consumes.type_alias_unknown_export",
1234        blurb: "`consumes payment { AuthId as Auth }` brings a type that `payment` exports in under another name, so the type has to be one it exports. A misspelt name, or a type that `payment` keeps to itself, is the usual cause. Correct the name, or ask `payment` to export the type.",
1235        example: "// shop.bynk\ncontext shop\n\nconsumes payment { AuthIdd as Auth }   // ✗ `payment` exports no `AuthIdd`\n\nconsumes payment { AuthId as Auth }    // ✓ a type it exports",
1236    },
1237    Explain {
1238        code: "bynk.consumes.type_not_selected",
1239        blurb: "Imports are per file. A unit's own declarations are shared by all its files, but a name from another unit, a type or a bare variant of one of its sums, is in scope only in a file that itself has a `consumes` bringing it in, and where the list is braced, only if it is listed. Naming a type that this file's own `consumes` does not bring in is an error, whether the clause lists other names or only another file of the unit consumes the unit; `bynk check --fix=bynk.consumes.type_not_selected` adds the name to this file's `consumes`, or adds one. A bare `consumes U`, with no braces, brings in all of `U`'s names for that file.",
1240        example: "// shop/context.bynk\nconsumes bynk { Logger }                   // ✗ `TimedOut` is not listed\n\nconsumes bynk { Logger, TimedOut }          // ✓\n\nfn at(t: TimedOut) -> Bool {\n    true\n}\n\n// shop/audit.bynk, another file of the same context\nfn late(t: TimedOut) -> Bool {   // ✗ this file does not consume `bynk`\n    true\n}\n\nconsumes bynk { TimedOut }        // ✓ each file consumes what it names",
1241    },
1242    Explain {
1243        code: "bynk.consumes.unit_not_consumed",
1244        blurb: "Imports are per file. A call to another unit's service (`pay.charge(…)`, or through the alias of `consumes pay as P`) is in scope only in a file that itself `consumes` that unit, in any form, even when another file of the same context does. A call from a file that does not is an error; `bynk check --fix=bynk.consumes.unit_not_consumed` adds `consumes <unit>` to this file. The unit's wiring and deploy order still follow the union of its files' `consumes`.",
1245        example: "// shop/checkout.bynk\nconsumes pay\n\nservice checkout {\n    on call() -> Effect[Int] by Caller {\n        pay.charge(1)\n    }\n}\n\n// shop/refund.bynk, another file of the same context\nservice refund {\n    on call() -> Effect[Int] by Caller {\n        pay.charge(2)   // ✗ this file does not consume `pay`\n    }\n}\n\nconsumes pay            // ✓ each file consumes what it names",
1246    },
1247    Explain {
1248        code: "bynk.consumes.unknown_context",
1249        blurb: "A `consumes` clause is how one context states that it depends on another, so it has to name a context in the project, and no unit of that name exists. Check the spelling against the `context` line of the unit you mean.",
1250        example: "// pay.bynk\ncontext pay\n\n// shop.bynk\ncontext shop\n\nconsumes paymnet                 // ✗ no context `paymnet`\nconsumes pay                     // ✓ the context's declared name",
1251    },
1252    Explain {
1253        code: "bynk.consumes.unknown_service",
1254        blurb: "A call such as `pay.charge(…)` reaches a service of the consumed context, and `pay` has none by that name. Only a service's `on call` handler can be called across contexts, so check the spelling against the consumed context and that the service has an `on call` handler. A call with the wrong number of arguments is `bynk.consumes.service_arity`.",
1255        example: "// pay.bynk\ncontext pay\n\nservice charge {\n    on call(amount: Int) -> Effect[Int] by Caller {\n        Effect.pure(amount)\n    }\n}\n\n// shop.bynk\ncontext shop\n\nconsumes pay\n\nservice checkout {\n    on call() -> Effect[Int] by Caller {\n        pay.charg(1)             // ✗ `pay` has no service `charg`\n    }\n}\n\nservice checkout {\n    on call() -> Effect[Int] by Caller {\n        pay.charge(1)            // ✓ the declared name\n    }\n}",
1256    },
1257    Explain {
1258        code: "bynk.container.build_missing",
1259        blurb: "A `Container` is built from a Dockerfile: `@build(\"dir\")` names the \
1260                project-relative directory that holds it, and `bynk check` looks for \
1261                `dir/Dockerfile`. A directory with no Dockerfile would fail only when \
1262                `wrangler deploy` tried to build the image, so it is refused here. Create the \
1263                Dockerfile, or correct the path. Bynk does not read or generate the Dockerfile, \
1264                and the image must be built for `linux/amd64`.",
1265        example: "capability Renderer = Container @build(\"containers/renderer\") @port(8080)    // ✗ containers/renderer/Dockerfile does not exist\n\
1266                  capability Renderer = Container @build(\"containers/renderer\") @port(8080)    // ✓ once containers/renderer/Dockerfile exists",
1267    },
1268    Explain {
1269        code: "bynk.container.build_path",
1270        blurb: "`@build` on a `Container` is a directory inside the project, written relative to \
1271                the project root with `/` separators: `@build(\"containers/renderer\")`. An empty \
1272                path, an absolute path, a drive path, a path with `\\` and a path that leaves the \
1273                project with `..` are refused, so the build context can never reach outside the \
1274                project and the emitted configuration stays a function of the source.",
1275        example: "capability Renderer = Container @build(\"../renderer\") @port(8080)       // ✗ leaves the project\n\
1276                  capability Renderer = Container @build(\"containers/renderer\") @port(8080) // ✓",
1277    },
1278    Explain {
1279        code: "bynk.container.output_outside_project",
1280        blurb: "A container's image is built by `wrangler deploy` from the Dockerfile that `@build` \
1281                names. The generated `wrangler.toml` reaches it from the Worker's output directory, \
1282                `<out>/workers/<worker>`, by a relative path back into the project, so the output \
1283                directory has to be inside the project; the path is computed from the directory the \
1284                build is written to. A build into a directory outside the project is refused, naming \
1285                each container and both paths, because a path that climbs out and back in would break \
1286                when the output is moved, and copying the build directory into the output would take \
1287                `node_modules`, secrets and large files with it. Build into a directory inside the \
1288                project: set `[build] out` or pass `--out` a path under the project root.",
1289        example: "# bynk.toml\n\
1290                  [build]\n\
1291                  out = \"../dist\"    # ✗ outside the project\n\
1292                  out = \"dist\"       # ✓ inside it",
1293    },
1294    Explain {
1295        code: "bynk.context.consumes_cycle",
1296        blurb: "Contexts may not form a circle of `consumes` clauses, whether directly or \
1297                through others. `bynk deploy` takes the order in which to upload the Workers \
1298                from the `consumes` clauses, because Cloudflare resolves a Service Binding when \
1299                a Worker is uploaded and so the callee must already exist; a cycle has no such \
1300                order. The error names the cycle and sits on one of its clauses. Remove one \
1301                clause: usually the callee takes what it needs as an argument instead of calling \
1302                back. Logic both contexts need can move into a `commons` that each `uses`.",
1303        example: "// a.bynk\n\
1304                  context a\n\
1305                  \n\
1306                  consumes b                       // ✗ `a` and `b` consume each other (reported on one clause)\n\
1307                  \n\
1308                  // b.bynk\n\
1309                  context b\n\
1310                  \n\
1311                  consumes a                       // ✗\n\
1312                  \n\
1313                  service quote {                  // ✓ no `consumes a`: `quote` takes `rate` as an argument\n    on call(rate: Int) -> Effect[Int] by Caller {\n        Effect.pure(rate * 2)\n    }\n\
1314                  }",
1315    },
1316    Explain {
1317        code: "bynk.context.duplicate_binding",
1318        blurb: "A Worker's bindings share one `env`, so each name can be declared once. Bynk names \
1319                the bindings after what the context declares: an agent, a consumed context, a \
1320                derived capability, and the `Kv` namespace of `bynk.cloudflare`, whose binding is \
1321                `KV`. Here the consumed context `kv` also becomes a Service Binding named `KV`, \
1322                and the two would overwrite each other. Rename the declaration behind one of them. \
1323                The error is on the one you can rename, not on the `bynk.cloudflare` clause. A \
1324                bundle build has no bindings, so only the Workers target checks this.",
1325        example: "// ops/hub.bynk\n\
1326                  consumes bynk.cloudflare { Kv }   // the KV namespace is bound as `KV`\n\
1327                  consumes kv                       // ✗ a Service Binding, also named `KV`\n\
1328                  \n\
1329                  // ops/hub.bynk\n\
1330                  consumes counter                  // ✓ a binding named `COUNTER`",
1331    },
1332    Explain {
1333        code: "bynk.context.external_construction",
1334        blurb: "A context that `consumes` another may hold and pass on the other's types, but \
1335                may not build one. A refined or opaque type can promise an invariant, a \
1336                `Matches` pattern or a smart constructor, and that holds only if every value is \
1337                made by the owner; `.of`, `.unsafe` and a variant constructor are refused from \
1338                outside, as is the record syntax of an opaque type. Ask the owner for the value \
1339                instead: a service that returns it, or takes the plain input and does the check. \
1340                `bynk.context.opaque_inspection` is the other side, looking inside such a value.",
1341        example: "// payment.bynk\n\
1342                  context payment\n\
1343                  \n\
1344                  exports transparent { AuthId }\n\
1345                  \n\
1346                  type AuthId = String where Matches(\"AUTH-[0-9]+\")\n\
1347                  \n\
1348                  service issue {\n    on call() -> Effect[AuthId] by Caller { … }\n\
1349                  }\n\
1350                  \n\
1351                  // orders.bynk\n\
1352                  context orders\n\
1353                  \n\
1354                  consumes payment\n\
1355                  \n\
1356                  AuthId.of(s)             // ✗ only `payment` makes an `AuthId`\n\
1357                  \n\
1358                  payment.issue()          // ✓ ask `payment` for one",
1359    },
1360    Explain {
1361        code: "bynk.context.external_decode",
1362        blurb: "Decoding creates a value, and a context may not create one of a type another \
1363                context owns and exports opaque. A decoder would check no more than the base \
1364                type, because the owner's predicate is the owner's secret. So a handler that \
1365                takes such a type as its input (an HTTP, queue, event or WebSocket handler \
1366                decodes it from bytes), and a `Json.decode`, `Json.decodeSql` or `Codable` \
1367                witness of it, are refused. Take the plain form of the input and let the owner's \
1368                service make the value. A reply from the owner's own service is fine: its decode \
1369                is generated.",
1370        example: "// pay.bynk\n\
1371                  context pay\n\
1372                  \n\
1373                  exports opaque { Token }\n\
1374                  \n\
1375                  type Token = opaque String where Matches(\"T-[0-9]+\")\n\
1376                  \n\
1377                  // shop.bynk\n\
1378                  context shop\n\
1379                  \n\
1380                  consumes pay\n\
1381                  \n\
1382                  service api from http {\n    on POST(\"/t\") (body: Token) -> Effect[HttpResult[String]] by v: Visitor {     // ✗ `Token` cannot be decoded here\n    on POST(\"/t\") (body: String) -> Effect[HttpResult[String]] by v: Visitor {    // ✓ take the plain input",
1383    },
1384    Explain {
1385        code: "bynk.context.external_provider",
1386        blurb: "A provider with no body (`provides Clock = SystemClock`) says its implementation comes from elsewhere, and only an `adapter` has a binding to supply it. In a context every provider is written in Bynk, so it needs a body implementing the capability's operations. Add one, or move the capability into an adapter if the code is TypeScript. The reverse mistake is `bynk.adapter.provider_has_body`.",
1387        example: "provides Clock = SystemClock             // ✗ no body, and a context has no binding\n\nprovides Clock = SystemClock {           // ✓ implemented in Bynk\n    fn now() -> Effect[Int] {\n        Effect.pure(0)\n    }\n}",
1388    },
1389    Explain {
1390        code: "bynk.context.opaque_inspection",
1391        blurb: "A context that writes `exports opaque { T }` lets other contexts hold a `T`, pass it on and \
1392                call its methods, but not look inside it: they cannot `match` on it, read a field, \
1393                match a record pattern against it, or name one of its variants. Only the owning \
1394                context sees the shape, so it can change the representation, or keep an invariant \
1395                the type's constructors enforce, without breaking a consumer. Ask the owner for \
1396                what you need instead: a service that returns the answer as a plain value, such as \
1397                a `Bool`. If the shape is meant to be public, the owner exports it with \
1398                `exports transparent { T }`.",
1399        example: "// pay.bynk\n\
1400                  context pay\n\n\
1401                  exports opaque { Status }        // the owner hides the shape\n\n\
1402                  type Status = | Paid | Declined\n\n\
1403                  // shop.bynk\n\
1404                  context shop\n\n\
1405                  consumes pay\n\n\
1406                  service checkout {\n    on call() -> Effect[Bool] by Caller {\n        let s <- pay.charge(1)\n        match s {                      // ✗ `Status` is opaque here, so its variants are hidden\n            Paid => Effect.pure(true)\n            Declined => Effect.pure(false)\n        }\n    }\n}\n\n\
1407                  // pay.bynk\n\
1408                  exports transparent { Status }   // ✓ the owner shares the shape",
1409    },
1410    Explain {
1411        code: "bynk.context.rebrand_construction",
1412        blurb: "A context that `uses` a commons gets its sum types by name, but not their variant constructors, so `Circle(1.0)` is refused there: the context re-exports the type under its own name, without the constructors. Build the value in the commons, in a function that returns it, and call that function from the context.",
1413        example: "// geo/shapes.bynk\ncommons geo.shapes\n\ntype Shape = | Circle(radius: Float) | Square(side: Float)\n\n// app/main.bynk\ncontext app.main\n\nuses geo.shapes\n\nfn unit() -> Shape {\n    Circle(1.0)                          // ✗ constructors are not in scope here\n}\n\n// geo/shapes.bynk\nfn unitCircle() -> Shape { Circle(1.0) } // ✓ built in the commons\n\n// app/main.bynk\nfn unit() -> Shape {\n    unitCircle()                         // ✓ called from the context\n}",
1414    },
1415    Explain {
1416        code: "bynk.contract.duplicate_name",
1417        blurb: "Every `requires` and `ensures` clause has a name, and a \
1418                failure report points at a clause by that name, so each name \
1419                must be unique within one function, across both kinds. Rename \
1420                the repeat; the error is on its name.",
1421        example: "fn inc(x: Int) -> Int\n\
1422                  \x20\x20requires bigger: x > 0\n\
1423                  \x20\x20ensures bigger: result > x      // ✗ `bigger` is already taken\n\n\
1424                  fn inc(x: Int) -> Int\n\
1425                  \x20\x20requires positive: x > 0\n\
1426                  \x20\x20ensures bigger: result > x      // ✓",
1427    },
1428    Explain {
1429        code: "bynk.contract.impure_predicate",
1430        blurb: "A contract clause is checked on every call in the dev and test \
1431                build, and by the runner on generated inputs, so its predicate \
1432                must be a pure `Bool` over the parameters and `result`. \
1433                Effects (`Effect.pure`, `?`) and test-only constructs \
1434                (`expect`, `val`, observations, `faults`, `trace`) cannot \
1435                appear in it. State the claim as a plain comparison, and keep \
1436                assertions and effects in a `case`.",
1437        example: "fn inc(x: Int) -> Int\n\
1438                  \x20\x20ensures bigger: expect result > x   // ✗ `expect` is a test statement\n\n\
1439                  fn inc(x: Int) -> Int\n\
1440                  \x20\x20ensures bigger: result > x          // ✓ a pure `Bool`",
1441    },
1442    Explain {
1443        code: "bynk.contract.not_bool",
1444        blurb: "A `requires` or `ensures` clause is a claim the function can \
1445                meet or break, so its predicate must be a `Bool`. A value of \
1446                another type, such as an `Int`, claims nothing that could \
1447                fail. Write a comparison or another `Bool` expression over the \
1448                parameters (and `result`, in an `ensures`).",
1449        example: "fn inc(x: Int) -> Int\n\
1450                  \x20\x20ensures bigger: result + 1      // ✗ an `Int`, not a `Bool`\n\n\
1451                  fn inc(x: Int) -> Int\n\
1452                  \x20\x20ensures bigger: result > x      // ✓",
1453    },
1454    Explain {
1455        code: "bynk.contract.restated_by_test",
1456        blurb: "A function's `ensures` is checked at every call, in production and in every test that reaches it. A test that calls the function and `expect`s the same predicate adds nothing and has to be kept in step with the contract. The compiler flags the repeat. The check is narrow: it fires only on a syntactic restatement over the same arguments. Delete the test, or keep a case only for a specific value a reader should see, such as `expect discount(100, 10) == 90`.",
1457        example: "// demo/c.bynk\nfn discount(p: Int, pct: Int) -> Int\n    ensures never_above: result <= p\n    { … }\n\n// tests/c.test.bynk\nlet r = discount(100, 10)\nexpect r <= 100    // ✗ repeats `never_above`\nexpect r == 90     // ✓ a specific witnessed value",
1458    },
1459    Explain {
1460        code: "bynk.contract.result_in_requires",
1461        blurb: "A `requires` clause is checked on entry, before the function \
1462                has returned anything, so `result` is not bound there. Only an \
1463                `ensures` can read it. Either state the condition over the \
1464                parameters, or, if it is a claim about the return value, make \
1465                it an `ensures`. A parameter that is itself named `result` is \
1466                read as that parameter.",
1467        example: "fn inc(x: Int) -> Int\n\
1468                  \x20\x20requires small: result < 100    // ✗ nothing has been returned yet\n\n\
1469                  fn inc(x: Int) -> Int\n\
1470                  \x20\x20ensures small: result < 100     // ✓ checked on exit",
1471    },
1472    Explain {
1473        code: "bynk.cron.bad_params",
1474        blurb: "A scheduled trigger carries one thing, the time it fired, so an `on schedule` handler takes at most one parameter, and it must be an `Instant`: the time the schedule fired. Drop the parameter, or type it `Instant`. A parameter typed `Int` (the old spelling) is this error too: write `at: Instant`, and use `at.toEpochMillis()` where the body needs the number.",
1475        example: "on schedule(\"*/5 * * * *\") (at: Int) -> Effect[Result[(), String]] { … }   // ✗ the time is an `Instant`\n\non schedule(\"*/5 * * * *\") (at: Instant) -> Effect[Result[(), String]] { … }          // ✓",
1476    },
1477    Explain {
1478        code: "bynk.cron.duplicate_schedule",
1479        blurb: "The context's `scheduled` entry point picks the handler by the schedule that fired, so each schedule may be declared once across all its `from cron` services. Two handlers with the same one would leave it with two to run. Merge them into one handler, or give one a different schedule.",
1480        example: "on schedule(\"*/5 * * * *\") () -> Effect[Result[(), String]] { … }\non schedule(\"*/5 * * * *\") () -> Effect[Result[(), String]] { … }   // ✗ already scheduled\n\non schedule(\"0 * * * *\") () -> Effect[Result[(), String]] { … }     // ✓ a different schedule",
1481    },
1482    Explain {
1483        code: "bynk.cron.invalid_schedule",
1484        blurb: "A cron schedule is Cloudflare's five-field syntax: minute `0-59`, hour `0-23`, day of month `1-31` (also `L` and `W`), month `1-12` or `JAN`-`DEC`, and day of week `1-7` with `1` as Sunday, or `SUN`-`SAT` (also `L` and `#`). `*`, `,`, `-` and `/` work in every field. There are no seconds, no year, no `?` and no `@daily`-style macros. Fields are separated by exactly one space, with none leading or trailing, because Cloudflare hands the handler that exact string back and dispatches on it character for character. Bynk checks all of this at compile time, so a schedule Cloudflare would reject is caught before deploy, not when it silently never runs; the message names the failing field. The same rule is the `Cron` refinement predicate, and `CronSchedule` is the type of a valid schedule. A bad parameter or return type on the handler is `bynk.cron.bad_params` or `bynk.cron.return_not_effect_result`.",
1485        example: "on schedule(\"61 * * * *\") () -> Effect[Result[(), String]] { … }   // ✗ minute 61 is outside 0-59\n\non schedule(\"0 3 * * *\") () -> Effect[Result[(), String]] { … }   // ✓ 03:00 UTC every day",
1486    },
1487    Explain {
1488        code: "bynk.cron.numeric_weekday",
1489        blurb: "Standard cron numbers the days `0` or `7` for Sunday, so `5` is Friday. Cloudflare's cron triggers number them `1`-`7` with `1` as Sunday, so `5` is Thursday. A schedule that was copied from standard cron, or written from habit, then runs a day early. Both forms are valid, so this is only a warning; name the day (`FRI`) or list the days explicitly to say what is meant, which also silences it.",
1490        example: "on schedule(\"0 9 * * 5\") () -> Effect[Result[(), String]] { … }     // ⚠ Thursday on Cloudflare, not Friday\n\non schedule(\"0 9 * * FRI\") () -> Effect[Result[(), String]] { … }   // ✓ unambiguous",
1491    },
1492    Explain {
1493        code: "bynk.cron.return_not_effect_result",
1494        blurb: "A cron run has no caller to hand a value to and no retry channel: `Ok(())` completes the run silently and `Err(e)` logs `e` and completes. So the handler must return `Effect[Result[(), E]]`, with `()` on the success side, for some error type `E`. Return `Ok(())` when the work is done and map a failure to `Err`. The queue counterpart is `bynk.queue.return_not_queue_result`.",
1495        example: "on schedule(\"*/5 * * * *\") () -> Effect[Result[Int, String]] { … }   // ✗ a cron run has nowhere to put an `Int`\n\non schedule(\"*/5 * * * *\") () -> Effect[Result[(), String]] { … }   // ✓ unit on success",
1496    },
1497    Explain {
1498        code: "bynk.cron.uneven_step",
1499        blurb: "A step such as `*/45` in the minute field counts from the start of the hour, so it fires at minute 0 and 45 and then starts over at 0 in the next hour: the gaps are 45 and 15 minutes, not an even 45. The same is true of an hour step that does not divide 24. Only a step that divides the field's range (`*/5`, `*/15`, `*/30` for minutes; `*/2`, `*/6`, `*/12` for hours) fires evenly. Both forms are valid, so this is only a warning; list the times you mean (`0,45`) or pick a step that divides the range, which silences it.",
1500        example: "on schedule(\"*/45 * * * *\") () -> Effect[Result[(), String]] { … }   // ⚠ fires at :00 and :45, then :00 again\n\non schedule(\"0,45 * * * *\") () -> Effect[Result[(), String]] { … }   // ✓ says so explicitly",
1501    },
1502    Explain {
1503        code: "bynk.d1.migration_name",
1504        blurb: "A `D1` database's migrations are the SQL files in `migrations/<database>/`, applied in number order, each once. So a file's name must give its place in that order: `NNNN_<name>.sql`, four digits, an underscore, then letters, digits, `_` or `-`, directly in its database's directory. A file named any other way, one in a nested folder, or one whose number another migration of the same database already has could not be put in order, so the build refuses it rather than skip it. Rename the file, or give it the next free number.",
1505        example: "migrations/shop-orders/1_create_orders.sql      // ✗ not four digits\nmigrations/shop-orders/0002_add_note.sql\nmigrations/shop-orders/0002_add_total.sql     // ✗ `0002` is taken\n\nmigrations/shop-orders/0001_create_orders.sql   // ✓\nmigrations/shop-orders/0002_add_note.sql\nmigrations/shop-orders/0003_add_total.sql       // ✓ the next free number",
1506    },
1507    Explain {
1508        code: "bynk.d1.select_field_missing",
1509        blurb: "`select[T]` and `firstAs[T]` read each row into the record `T`, matching columns to \
1510                fields by name, so every field needs a column of that name. `Json.decodeSql` reads \
1511                a literal `all` or `first` the same way, for each required field. Rename the \
1512                field, or alias the column in the SQL (`… AS price`) so the names agree.",
1513        example: "type Order = { id: String, price: Int }\nlet _ <- Orders.select[Order](\"FROM orders\", [])    // ✗ `orders` has no column `price`\n\ntype Order = { id: String, total: Int }\nlet _ <- Orders.select[Order](\"FROM orders\", [])    // ✓",
1514    },
1515    Explain {
1516        code: "bynk.d1.sql_invalid",
1517        blurb: "Bynk prepares each literal SQL statement of a `D1` capability against the schema \
1518                your migrations build, applied to an empty in-memory SQLite, so a syntax error or an \
1519                unknown table or column is a compile error, not a failure on the first request. \
1520                Nothing runs. Correct the statement, or add the migration that creates what it \
1521                names. A project whose schema is made elsewhere can turn the check off with \
1522                `[check] d1_sql = false`.",
1523        example: "let _ <- Orders.all(\"SELECT id, totl FROM orders\", [])     // ✗ no such column: totl\n\nlet _ <- Orders.all(\"SELECT id, total FROM orders\", [])    // ✓",
1524    },
1525    Explain {
1526        code: "bynk.d1.sql_param_count",
1527        blurb: "D1 refuses a statement bound to a different number of values than it has \
1528                parameters, so Bynk counts them at compile time by SQLite's rule: the highest `?N`, \
1529                with a bare `?` taking the next number. It checks a list written out in place, or a \
1530                name `let`-bound to one. Pass one `SqlValue` for each parameter, or change the SQL.",
1531        example: "let _ <- Orders.all(\"SELECT id FROM orders WHERE id = ?1 AND total > ?2\", [Text(id)])                 // ✗ two parameters, one value\n\nlet _ <- Orders.all(\"SELECT id FROM orders WHERE id = ?1 AND total > ?2\", [Text(id), Integer(100)])    // ✓",
1532    },
1533    Explain {
1534        code: "bynk.dependency.path_outside_root",
1535        blurb: "Your own project's path dependencies can point anywhere, but a dependency's own path dependencies are honoured only when they stay inside the workspace: a path out of it names a directory that need not exist where the package is used. A fetched package's path dependencies are never honoured. Move the target into the workspace.",
1536        example: "# lib/bynk.toml, a dependency of the project\n[dependencies]\ncore = { package = \"acme/core\", path = \"../../outside\" }   // ✗ outside the workspace\n\ncore = { package = \"acme/core\", path = \"../core\" }         // ✓ a workspace member",
1537    },
1538    Explain {
1539        code: "bynk.deploy.asset_path_conflict",
1540        blurb: "A `[deploy.workers.<key>]` group folds its members into one Worker, and a Worker has one assets directory. So a fixed asset path (`at \"/…\"`) names one file across the whole group: two members serving different files at one path would leave the Worker unable to say which to send. A path that would be a folder of another member's file is refused for the same reason. Give one of the assets another path, or put the contexts in different groups.",
1541        example: "// bynk.toml\n[deploy.workers.core]\ncontexts = [\"shop.orders\", \"shop.billing\"]\n\n// shop/orders.bynk\nasset terms = \"assets/orders-terms.txt\" at \"/terms.txt\"\n\n// shop/billing.bynk\nasset terms = \"assets/billing-terms.txt\" at \"/terms.txt\"           // ✗ `shop.orders` serves `/terms.txt`\nasset terms = \"assets/billing-terms.txt\" at \"/billing/terms.txt\"   // ✓",
1542    },
1543    Explain {
1544        code: "bynk.deploy.binding_collision",
1545        blurb: "A `[deploy.workers.<key>]` group folds its members into one Worker, and a Worker has one `wrangler.toml`, so its members share one set of binding names. Two members that declare a binding the same way share it. Two that declare different bindings under one name are refused, because one name cannot bind two things. An agent is the usual case: each agent class is a Durable Object binding named after the class, and a class belongs to the context that declares it, so two members cannot each declare an agent of the same name. Rename one, or put the contexts in different groups.",
1546        example: "// bynk.toml\n[deploy.workers.core]\ncontexts = [\"shop.orders\", \"shop.billing\"]\n\n// shop/orders.bynk\nagent Cart { … }\n\n// shop/billing.bynk\nagent Cart { … }     // ✗ `shop.orders` already binds `Cart`\nagent Ledger { … }   // ✓",
1547    },
1548    Explain {
1549        code: "bynk.deploy.context_in_two_groups",
1550        blurb: "Each `[deploy.workers.<key>]` group becomes one Worker, and a context is deployed in exactly one Worker: its routes, its services and its agents' state belong to one script. A context listed in two groups would be deployed twice, as two copies that share nothing. List it in one group. A context in no group stays its own Worker.",
1551        example: "[deploy.workers.core]\ncontexts = [\"shop.orders\", \"shop.billing\"]\n\n[deploy.workers.edge]\ncontexts = [\"shop.orders\"]     // ✗ already in `core`\n\ncontexts = [\"shop.gateway\"]    // ✓",
1552    },
1553    Explain {
1554        code: "bynk.deploy.duplicate_hostname",
1555        blurb: "A route or custom domain sends the requests that match it to one Worker. If two `[deploy.workers.<key>]` groups claimed the same one, only one Worker could have it, and which would depend on the order they were deployed in. So each route and each custom domain is claimed once across all the groups. Hosts are compared without regard to case, and the same host with a different path is a different route. Remove the repeat, or give one group another route.",
1556        example: "[deploy.workers.core]\ncontexts = [\"shop.orders\"]\nroutes = [\"shop.example.com/*\"]\n\n[deploy.workers.edge]\ncontexts = [\"shop.billing\"]\nroutes = [\"shop.example.com/*\"]           // ✗ `core` claims it\n\nroutes = [\"shop.example.com/billing/*\"]   // ✓ another path, another route",
1557    },
1558    Explain {
1559        code: "bynk.deploy.empty_group",
1560        blurb: "A `[deploy.workers.<key>]` group is a Worker made of the contexts it lists. A group that lists none would be a Worker with nothing to run, and its key would still claim a Worker name and a deploy record. That is almost always a mistake: contexts left out, or a group that should have been deleted. List the group's contexts, or remove the table.",
1561        example: "[deploy.workers.core]\ncontexts = []                                  // ✗ no context\n\ncontexts = [\"shop.orders\", \"shop.billing\"]   // ✓",
1562    },
1563    Explain {
1564        code: "bynk.deploy.group_name_conflict",
1565        blurb: "Each Worker on Cloudflare is one script with one name. A group's Worker is named by its `name`, or by its key when it has none, and a context in no group is a Worker of its own, named after the context with each `.` as `-` (`shop.billing` is `shop-billing`). Two Workers with one name would overwrite each other on deploy. So a group's key or `name` may not be another group's Worker name, nor the Worker of a context in no group. Choose another key or `name`, or put that context in the group.",
1566        example: "[deploy.workers.core]\ncontexts = [\"shop.orders\"]\n\n[deploy.workers.edge]\ncontexts = [\"shop.billing\"]\nname = \"core\"         // ✗ `core` is already a Worker's name\n\nname = \"shop-edge\"    // ✓",
1567    },
1568    Explain {
1569        code: "bynk.deploy.multiple_websocket_members",
1570        blurb: "A WebSocket upgrade request names no service, and a `from websocket` service has no path of its own, so a Worker hands every upgrade to its one WebSocket service. A `[deploy.workers.<key>]` group folds its members into one Worker, so at most one member may declare a `from websocket` service, and that one takes every upgrade, whatever its path. Put the contexts in different groups, or leave one in no group so that it is a Worker of its own. Within one context, a second WebSocket service is `bynk.service.websocket_multiple`.",
1571        example: "// bynk.toml\n[deploy.workers.live]\ncontexts = [\"live.chat\", \"live.scores\"]\n\n// live/chat.bynk\nservice chat from websocket(in: Frame, out: Frame) { … }\n\n// live/scores.bynk\ncontext live.scores   // ✗ the second member of `live` with a WebSocket service\nservice scores from websocket(in: Frame, out: Frame) { … }\n\n// bynk.toml\ncontexts = [\"live.chat\"]   // ✓ `live.scores` is a Worker of its own",
1572    },
1573    Explain {
1574        code: "bynk.deploy.not_a_context",
1575        blurb: "A `[deploy.workers.<key>]` group lists the contexts to deploy together as one Worker, and only a context is deployed. A `commons` is compiled into each context that uses it, and an adapter into each context that consumes it, so neither has a Worker of its own to share. Remove the entry: the contexts that use the commons carry it with them.",
1576        example: "[deploy.workers.core]\ncontexts = [\"shop.orders\", \"money\"]   // ✗ `money` is a commons\n\ncontexts = [\"shop.orders\"]            // ✓",
1577    },
1578    Explain {
1579        code: "bynk.deploy.route_conflict",
1580        blurb: "A `[deploy.workers.<key>]` group folds its members into one Worker, which answers each HTTP method and path with one handler. Two members that declare the same method and path would give the Worker two handlers for one request, so the later one is refused. Change one of the routes, often by giving each context a path prefix of its own, or put the contexts in different groups. Within one context the same clash is `bynk.http.duplicate_route`.",
1581        example: "// bynk.toml\n[deploy.workers.core]\ncontexts = [\"shop.orders\", \"shop.billing\"]\n\n// shop/orders.bynk\non GET(\"/status\") () -> Effect[HttpResult[String]] by who: Visitor { … }\n\n// shop/billing.bynk\non GET(\"/status\") () -> Effect[HttpResult[String]] by who: Visitor { … }           // ✗ `shop.orders` answers `GET /status`\non GET(\"/billing/status\") () -> Effect[HttpResult[String]] by who: Visitor { … }   // ✓",
1582    },
1583    Explain {
1584        code: "bynk.deploy.service_name_conflict",
1585        blurb: "A service is called by its name alone: a call from another context goes to `/_bynk/call/<service>`, and the address names no context. A `[deploy.workers.<key>]` group folds its members into one Worker, which answers all their services, so two members with a service of the same name would leave it unable to tell the calls apart. Rename one of the services, or put the contexts in different groups.",
1586        example: "// bynk.toml\n[deploy.workers.core]\ncontexts = [\"shop.orders\", \"shop.billing\"]\n\n// shop/orders.bynk\nservice lookup { … }\n\n// shop/billing.bynk\nservice lookup { … }    // ✗ `shop.orders` has a `lookup`\nservice invoice { … }   // ✓",
1587    },
1588    Explain {
1589        code: "bynk.deploy.unknown_context",
1590        blurb: "A `[deploy.workers.<key>]` group names its members by their qualified context names, and each must be a context the project declares. A name that matches none is usually a typo, or a context that has since been renamed, and a group cannot deploy a context that does not exist. The note suggests the nearest name. Correct the entry, or remove it.",
1591        example: "[deploy.workers.core]\ncontexts = [\"shop.ordres\"]   // ✗ no such context\n\ncontexts = [\"shop.orders\"]   // ✓",
1592    },
1593    Explain {
1594        code: "bynk.deploy.worker_cycle",
1595        blurb: "`bynk deploy` uploads each Worker after the Workers it binds to, since a Service Binding must name a script that already exists. So the Workers' bindings must run one way: a cycle has no order to deploy in. Contexts cannot consume each other in a cycle (that is `bynk.context.consumes_cycle`), but a `[deploy.workers.<key>]` group folds its members into one Worker, and that can close a cycle among contexts that have none: if a member of `front` calls a member of `back`, and another member of `back` calls a member of `front`, the two Workers bind to each other. Move a context out of its group, or into the other, so the calls between Workers run one way. A publisher's Worker also binds to its subscribers, so a subscriber that calls its publisher can close a cycle too.",
1596        example: "// bynk.toml\n[deploy.workers.front]\ncontexts = [\"shop.web\", \"shop.prices\"]\n\n[deploy.workers.back]\ncontexts = [\"shop.stock\", \"shop.reports\"]\n\n// shop/web.bynk\nconsumes shop.stock\n\n// shop/reports.bynk\ncontext shop.reports   // ✗ `back` binds to `front`, and `front` to `back`\nconsumes shop.prices\n\n// bynk.toml\n[deploy.workers.front]\ncontexts = [\"shop.web\"]                                    // ✓\n\n[deploy.workers.back]\ncontexts = [\"shop.stock\", \"shop.reports\", \"shop.prices\"]   // ✓ calls run from `front` to `back` only",
1597    },
1598    Explain {
1599        code: "bynk.detach.in_agent_handler",
1600        blurb: "`detach` stops waiting for an effect and hands it to the execution context, so something must keep the effect alive after the handler returns. A service handler has an execution context that does. An agent handler runs inside the agent's own object, with no such context, and its effects are awaited so that they finish with the handler. So `detach` is refused there, and in a closure there. Await the effect instead, with `do` or `let _ <-`, or move the `detach` to the service handler that calls the agent. A `detach` of a store operation is `bynk.detach.store_op`.",
1601        example: "on call bump() -> Effect[()] given Logger {\n    do Logger.info(\"bump\").detach()   // ✗ an agent handler cannot detach\n    do count.update((n) => n + 1)\n}\n\n\
1602                  on call bump() -> Effect[()] given Logger {\n    do Logger.info(\"bump\")             // ✓ awaited, so it finishes with the handler\n    do count.update((n) => n + 1)\n}",
1603    },
1604    Explain {
1605        code: "bynk.detach.in_pure_context",
1606        blurb: "`detach` hands a running effect to the execution context, and only an effectful body has effects to run: a pure function never runs one. Change the enclosing function's return type to `Effect[…]`. The same rule holds for `bynk.within.in_pure_context` and `bynk.race.in_pure_context`.",
1607        example: "fn twice(ping: Effect[()], n: Int) -> Int {\n    let _ = ping.detach()   // ✗ the body is pure\n    n * 2\n}\n\n\
1608                  fn twice(ping: Effect[()], n: Int) -> Effect[Int] {   // ✓ an effectful body\n    do ping.detach()\n    Effect.pure(n * 2)\n}",
1609    },
1610    Explain {
1611        code: "bynk.detach.store_op",
1612        blurb: "In an agent handler, a store write is not work to detach: it is staged and committed atomically with the rest of the handler, so there is nothing to leave running. `detach` is refused there for any effect, and a store operation gets its own code to point at the fix. Drop the `.detach()` and write `do field.op(…)`; the write is committed with the handler. For a `detach` that is not of a store operation see `bynk.detach.in_agent_handler`.",
1613        example: "on call bump() -> Effect[()] {\n    do count.update((n) => n + 1).detach()   // ✗ a store write is not detached\n}\n\n\
1614                  on call bump() -> Effect[()] {\n    do count.update((n) => n + 1)            // ✓ staged, committed with the handler\n}",
1615    },
1616    Explain {
1617        code: "bynk.duration.literal_overflow",
1618        blurb: "`5.minutes` is a `Duration`, which the compiler stores as a whole number of milliseconds, so it multiplies the count by the unit when it reads the literal. A count whose total does not fit in a 64-bit integer is refused rather than wrapped into a wrong or negative span. No real timeout or interval is that large: write a smaller count, or a smaller unit.",
1619        example: "fn forever() -> Duration { 9007199254740991.days }   // ✗ overflows the millisecond range\n\nfn forever() -> Duration { 365.days }                // ✓",
1620    },
1621    Explain {
1622        code: "bynk.duration.unit_agreement",
1623        blurb: "A `Duration` literal uses the unit that agrees with its number: the singular unit with `1` (`1.hour`, `1.second`) and the plural unit with every other number, `0` included (`2.hours`, `0.seconds`). `1.hours` and `5.hour` read wrongly and give a duration two spellings, so they are refused with a fix that rewrites the unit. The rule reads the literal's own number: a negative duration is the negation of a literal (`-1.hour`).",
1624        example: "fn tick() -> Duration { 1.hours }     // ✗ `1` takes the singular unit
1625
1626fn tick() -> Duration { 1.hour }      // ✓",
1627    },
1628    Explain {
1629        code: "bynk.duration.unknown_unit",
1630        blurb: "An integer literal has no fields, so a word after one (`5.hr`) is always read as the unit of a `Duration` literal. The units are `millisecond(s)`, `second(s)`, `minute(s)`, `hour(s)` and `day(s)`; there is no `week`. The diagnostic lists them and suggests the nearest one. Write the unit out in full, in the form that agrees with the number (`1.hour`, `5.hours`).",
1631        example: "fn wait() -> Duration { 5.hr }        // ✗ `hr` is not a unit
1632
1633fn wait() -> Duration { 5.hours }     // ✓",
1634    },
1635    Explain {
1636        code: "bynk.effect.bind_in_pure_context",
1637        blurb: "`<-` waits for an effect, so it is only allowed in a body that is itself effectful, one whose return type is `Effect[T]`. A function that returns a plain `Int` promises that it waits for nothing and reaches nothing outside, and a `<-` inside it would break that promise for every caller. A `par` block awaits too, and is refused in the same place. Change the return type to `Effect[T]` and return `Effect.pure(…)`, or compute the value without an effect. Calling a function value that returns an `Effect` is `bynk.effect.fn_value_in_pure_context`.",
1638        example: "fn next(n: Int) -> Int {\n    let x <- Effect.pure(n)      // ✗ `<-` in a function that returns a plain `Int`\n    x\n}\n\nfn next(n: Int) -> Effect[Int] {   // ✓ effectful, so it may bind with `<-`\n    let x <- Effect.pure(n)\n    Effect.pure(x)\n}",
1639    },
1640    Explain {
1641        code: "bynk.effect.bind_on_non_effect",
1642        blurb: "`let x <- e` waits for `e` and binds its result, so `e` must be an `Effect[T]`. A plain value has nothing to wait for, and `<-` on one usually means the right-hand side is not the call you meant. Write `let x = …` for a pure binding. Where an effect is required and you hold a plain value, wrap it with `Effect.pure(…)`. A `<-` in a body that is not itself effectful is `bynk.effect.bind_in_pure_context`.",
1643        example: "fn run() -> Effect[Int] {\n    let x <- 42                  // ✗ `42` is an `Int`, not an `Effect[Int]`\n    Effect.pure(x)\n}\n\nfn run() -> Effect[Int] {\n    let x = 42                   // ✓ a pure binding\n    Effect.pure(x)\n}",
1644    },
1645    Explain {
1646        code: "bynk.effect.capability_in_pure_context",
1647        blurb: "Calling a capability operation is an effect, and effects are only allowed in a body that is itself effectful, one that returns `Effect[T]`, so that a type tells you whether a body reaches outside. A lambda checked against a plain function type such as `(Int) -> Int` is a pure body, so a capability call inside it is refused even when the handler around it is effectful. Make the call in the handler, bind it with `<-`, and pass the result in. A call the `given` clause does not cover is `bynk.given.undeclared_capability`.",
1648        example: "let add: (Int) -> Int = (n) => {\n    let t = Clock.now()          // ✗ a capability call in a pure lambda\n    n\n}\n\nlet t <- Clock.now()             // ✓ the handler is effectful, so it makes the call\nlet add: (Int) -> Int = (n) => n + t",
1649    },
1650    Explain {
1651        code: "bynk.effect.cross_context_in_pure_context",
1652        blurb: "A call to a service in a consumed context is an effect, as a capability call is, so it is only allowed in a body that is itself effectful. A handler is effectful, but a lambda inside it is a body of its own, and a service call alone does not make it effectful. Make the call in the handler body, bind it with `<-`, and use the result in the lambda.",
1653        example: "on call() -> Effect[Int] by Caller {\n    let f = (n: Int) => pay.charge(n)   // ✗ a service call in a pure lambda\n    Effect.pure(1)\n}\n\non call() -> Effect[Int] by Caller {\n    let paid <- pay.charge(5)           // ✓ the handler makes the call\n    let f = (n: Int) => n + paid\n    Effect.pure(f(1))\n}",
1654    },
1655    Explain {
1656        code: "bynk.effect.do_discards_result",
1657        blurb: "`do e` awaits an effect and discards what it returns, which is fine for a unit or an ordinary value but not for a `Result`: an `Err` dropped this way is lost without a trace. Bind it and handle the error with `let r <- e` and a `match` (or `?`). If dropping the outcome is really what you want, write `let _ <- e`, which is legal and keeps the discard visible in the source. `do` on a plain value is `bynk.effect.do_on_non_effect`.",
1658        example: "fn send() -> Effect[Result[Int, String]] {\n    Effect.pure(Ok(1))\n}\n\nfn run() -> Effect[()] {\n    do send()                    // ✗ would silently drop an `Err`\n}\n\nfn run() -> Effect[()] {\n    let _ <- send()              // ✓ the discard is written out\n    Effect.pure(())\n}",
1659    },
1660    Explain {
1661        code: "bynk.effect.do_in_pure_context",
1662        blurb: "`do e` runs an effect as a statement, so like `<-` it belongs in a body that is itself effectful, one whose return type is `Effect[T]`. A function that returns a plain `Int` promises to wait for nothing and reach nothing outside, and a `do` inside it would break that promise for every caller. Change the return type to `Effect[T]` and end with `Effect.pure(…)`, or drop the `do`. The same mistake with `<-` is `bynk.effect.bind_in_pure_context`.",
1663        example: "fn ping() -> Effect[()] {\n    Effect.pure(())\n}\n\nfn run() -> Int {\n    do ping()                    // ✗ `do` in a function that returns a plain `Int`\n    5\n}\n\nfn run() -> Effect[Int] {        // ✓ effectful, so `do` is allowed\n    do ping()\n    Effect.pure(5)\n}",
1664    },
1665    Explain {
1666        code: "bynk.effect.do_on_non_effect",
1667        blurb: "`do e` performs an effect, so its operand must be an `Effect[T]`: a call to something effectful. A plain value has nothing to run, which usually means the operand is not the call you meant. Call the effectful function you intended. If you wanted the value, bind it with `let`. An effect whose result is a `Result` is `bynk.effect.do_discards_result`, and `<-` on a plain value is `bynk.effect.bind_on_non_effect`.",
1668        example: "fn ping() -> Effect[()] {\n    Effect.pure(())\n}\n\nfn clear() -> Effect[()] {\n    do 5                         // ✗ `5` is an `Int`, not an `Effect[T]`\n}\n\nfn clear() -> Effect[()] {\n    do ping()                    // ✓ an effect\n}",
1669    },
1670    Explain {
1671        code: "bynk.effect.fn_value_in_pure_context",
1672        blurb: "Calling a function value whose type returns `Effect[T]` is an effect, just as calling a \
1673                capability is, and effects are only allowed in a body that is itself effectful, one \
1674                whose return type is an `Effect`. Bynk makes effects explicit so that a function's \
1675                signature tells you whether it can touch the outside world: a function that returns a \
1676                plain `Int` is pure and can be reasoned about as such. A call through a parameter \
1677                would hide an effect behind that signature, so it is refused. Either make the function \
1678                return `Effect[T]` and bind the call with `<-`, or take a pure function instead. A \
1679                capability call from a handler that has not declared it is a different mistake, \
1680                `bynk.given.undeclared_capability`.",
1681        example: "fn sneak(f: Int -> Effect[Int], x: Int) -> Int {\n    \
1682                    let y = f(x)                          // ✗ an effect inside a pure function\n    \
1683                    x\n}\n\n\
1684                  fn sneak(f: Int -> Effect[Int], x: Int) -> Effect[Int] {   // ✓ the function is effectful\n    \
1685                    let y <- f(x)\n    \
1686                    Effect.pure(y)\n}",
1687    },
1688    Explain {
1689        code: "bynk.effect.unbound_effect",
1690        blurb: "Bynk starts an effectful call as soon as it is built, so an `Effect[T]` that is built and then \
1691                dropped still runs, unawaited, racing every statement after it, and nothing in the \
1692                program shows it. Effects are meant to happen in the order you wrote them, so in an \
1693                effectful body an `Effect` value must be bound with `let x <- …`, run with `do …` (for \
1694                an `Effect[()]`), or returned as the body's value. The error fires where an `Effect` is \
1695                built in a value position that cannot await it: the right-hand side of a plain `let` \
1696                (including `let _ = …`), a list element, and the payload of `Some`, `Ok`, `Err`, a \
1697                variant or a record field. An argument to another call is left alone, because the \
1698                parameter decides what happens to it. If you want the result, use `<-`; if only the \
1699                effect, use `do`.",
1700        example: "on call() -> Effect[()] by Caller {\n    \
1701                    let e = Counter(\"k\").bump()       // ✗ started, never awaited\n    \
1702                    Effect.pure(())\n}\n\n\
1703                  on call() -> Effect[()] by Caller {\n    \
1704                    do Counter(\"k\").bump()           // ✓ run in order\n    \
1705                    Effect.pure(())\n}",
1706    },
1707    Explain {
1708        code: "bynk.email.bad_params",
1709        blurb: "An email `on message` handler takes the message as one `InboundEmail` parameter: inbound email delivers one message per call, so the handler is `on message(mail: InboundEmail) -> Effect[EmailVerdict]`. A parameter of another type, or none, or more than one, is refused. Import `InboundEmail` and `EmailVerdict` from `bynk.cloudflare`.",
1710        example: "service support from email(\"[email protected]\") {\n    on message(mail: String) -> Effect[EmailVerdict] {   // ✗ not an `InboundEmail`\n        Accept\n    }\n}\n\nservice support from email(\"[email protected]\") {\n    on message(mail: InboundEmail) -> Effect[EmailVerdict] {   // ✓\n        Accept\n    }\n}",
1711    },
1712    Explain {
1713        code: "bynk.email.duplicate_address",
1714        blurb: "Inbound mail is dispatched to a service by its envelope recipient, so each address belongs to one service. Addresses compare without regard to case. A literal address and the catch-all `*@domain` for the same domain may both be claimed: the literal address wins, and the catch-all takes everything else. Merge the two handlers, or claim different addresses.",
1715        example: "service support from email(\"[email protected]\") { … }\nservice helpdesk from email(\"[email protected]\") { … }   // ✗ the same address\n\nservice helpdesk from email(\"[email protected]\") { … }   // ✓ its own address",
1716    },
1717    Explain {
1718        code: "bynk.email.duplicate_handler",
1719        blurb: "A `from email` service claims one address and decides each message it is given, so it has exactly one `on message` handler. To treat two addresses differently, declare two services, each with its own address.",
1720        example: "service support from email(\"[email protected]\") {\n    on message(mail: InboundEmail) -> Effect[EmailVerdict] { Accept }\n    on message(mail: InboundEmail) -> Effect[EmailVerdict] { Accept }   // ✗ a second handler\n}\n\nservice support from email(\"[email protected]\") {\n    on message(mail: InboundEmail) -> Effect[EmailVerdict] { Accept }   // ✓ one handler\n}",
1721    },
1722    Explain {
1723        code: "bynk.email.invalid_address",
1724        blurb: "A `from email` service claims a bare address, `local@domain`, or a whole domain with `*@domain`. The domain is dotted labels of letters, digits and `-`. A display name (`Support <[email protected]>`), a list, a wildcard inside the local part, and an address with spaces or quotes are refused: Email Routing matches the bare address.",
1725        example: "service support from email(\"Support <[email protected]>\") { … }   // ✗ a display name\n\nservice support from email(\"[email protected]\") { … }            // ✓",
1726    },
1727    Explain {
1728        code: "bynk.email.return_not_email_verdict",
1729        blurb: "An email handler decides what happens to the message, and the decision is named: `Accept`, `Reject(reason)`, `Forward(to)` or `Reply(message)`, the `EmailVerdict` sum from `bynk.cloudflare`. It is not a `Result` or a `String`, because the decision is independent of success or failure. It is the agency rule that gives a queue handler `QueueResult`.",
1730        example: "on message(mail: InboundEmail) -> Effect[String] {         // ✗ not a verdict\n    \"done\"\n}\n\non message(mail: InboundEmail) -> Effect[EmailVerdict] {   // ✓\n    Accept\n}",
1731    },
1732    Explain {
1733        code: "bynk.embed.binary_content",
1734        blurb: "An embed becomes a `String` in the compiled code, so its file must be text. A file \
1735                holding a NUL byte is binary, and a `String` made from it would be meaningless. \
1736                Binary data belongs in `assets/`, where the platform serves it as a file. Text \
1737                that is not valid UTF-8 is `bynk.embed.invalid_encoding`.",
1738        example: "embed logo = \"embeds/logo.png\"    // ✗ the file has a NUL byte\n\nasset logo = \"assets/logo.png\"    // ✓ a binary file is served, not read",
1739    },
1740    Explain {
1741        code: "bynk.embed.duplicate",
1742        blurb: "An embed is a `String` constant used by its name, so a unit declares each name once: \
1743                a second `embed shell` would leave `shell` meaning two files. Give each embed its \
1744                own name. An embed whose name is an asset's, a function's or a type's is \
1745                `bynk.resolve.name_conflict` instead.",
1746        example: "embed shell = \"embeds/page.html\"\nembed shell = \"embeds/other.html\"     // ✗ `shell` is already declared\n\nembed shell = \"embeds/page.html\"\nembed footer = \"embeds/other.html\"    // ✓ one name each",
1747    },
1748    Explain {
1749        code: "bynk.embed.invalid_encoding",
1750        blurb: "An `embed` becomes a `String`, which is Unicode text, so the file must be valid \
1751                UTF-8. A file saved in another encoding, such as Latin-1, holds bytes that are not \
1752                UTF-8 and cannot be read as text. Re-save it as UTF-8. A file that holds a NUL byte \
1753                is binary and is `bynk.embed.binary_content`; a binary file belongs in `assets/`, as \
1754                an `asset`.",
1755        example: "embed shell = \"embeds/page.html\"        // ✗ the file is Latin-1, not UTF-8\n\
1756                embed shell = \"embeds/page.html\"        // ✓ once the file is saved as UTF-8",
1757    },
1758    Explain {
1759        code: "bynk.embed.missing_file",
1760        blurb: "An `embed` compiles a file's text into the program as a `String`, so the file must \
1761                exist when the project is built, or there is nothing to compile in. The path is \
1762                relative to the project root and must name a regular file under `embeds/`; a \
1763                symbolic link is not followed. Create the file, or correct the path. A file that \
1764                exists but cannot be read is `bynk.embed.unreadable_file`.",
1765        example: "embed shell = \"embeds/page.html\"        // ✗ no such file in the project\n\
1766                embed shell = \"embeds/page.html\"        // ✓ once embeds/page.html exists",
1767    },
1768    Explain {
1769        code: "bynk.embed.outside_context_or_commons",
1770        blurb: "An `embed` is compiled into the Worker of each context that declares it, or that `uses` a commons that does. An adapter is the host boundary, not a Worker, so it has nowhere to carry the text, and an `embed` there is refused. Declare it in a context or a commons, and have the context use that. For a file the platform serves rather than compiles in, see `bynk.asset.outside_context_or_commons`.",
1771        example: "// app/host.bynk\nadapter app.host\n\nbinding \"./host.binding.ts\"\n\nembed shell = \"embeds/page.html\"        // ✗ an adapter cannot embed\n\n// app/page.bynk\ncommons app.page\n\nembed shell = \"embeds/page.html\"        // ✓ in a commons",
1772    },
1773    Explain {
1774        code: "bynk.embed.outside_embeds_dir",
1775        blurb: "An embed is compiled into the deployed code, so it may come only from the project's \
1776                `embeds/` folder. If any path were allowed, a declaration could pull `.env` or a \
1777                source file into the bundle just by naming it. Move the file into `embeds/` and \
1778                name it there. A path that is empty, absolute or contains `..` is \
1779                `bynk.embed.unsafe_path` instead.",
1780        example: "embed shell = \"templates/page.html\"    // ✗ not in the embeds/ folder\n\nembed shell = \"embeds/page.html\"       // ✓",
1781    },
1782    Explain {
1783        code: "bynk.embed.unsafe_path",
1784        blurb: "An embed's path is joined onto the project root to find the file, so it must stay \
1785                inside the project: it may not be empty or absolute, and it may not contain a `..` \
1786                segment, which could climb out of it. Write the path relative to the project root, \
1787                inside `embeds/`. A relative path that is only outside `embeds/` is \
1788                `bynk.embed.outside_embeds_dir`.",
1789        example: "embed shell = \"embeds/../page.html\"    // ✗ a `..` segment\n\nembed shell = \"embeds/page.html\"       // ✓",
1790    },
1791    Explain {
1792        code: "bynk.event.bad_params",
1793        blurb: "An `on event` handler takes the event payload and, optionally, a second parameter of type `EventEnvelope`, which carries the emission's metadata: its event id, publisher, time and schema version. Any other count, or any other type in second place, has nothing to receive it. Remove the extra parameter or type it `EventEnvelope`. A wrong first parameter is `bynk.event.handler_param_type_mismatch`.",
1794        example: "consumes bynk\n\nevent Paid = { id: String }\n\nservice onPaid from Events(Paid) {\n  on event(e: Paid, env: String) -> Effect[()] {   // ✗ the second parameter must be `EventEnvelope`\n  on event(e: Paid, env: EventEnvelope) -> Effect[()] {   // ✓",
1795    },
1796    Explain {
1797        code: "bynk.event.bad_schema_dispatch",
1798        blurb: "`via schema(N)` filters a subscription by the envelope's `schemaVersion`. Versions count up from 1, so every bound must be a positive `Int` literal: `schema(0)` or `schema(0..3)` names a version no event has. Write a version, a range such as `schema(2..4)`, or `_` for every version. A range whose lower bound is above its upper one is `bynk.types.empty_range_pattern`.",
1799        example: "service OnPaid from Events(Paid) via schema(0) {    // ✗ versions start at 1\nservice OnPaid from Events(Paid) via schema(1) {    // ✓\n    on event(e: Paid) -> Effect[()] { … }\n}",
1800    },
1801    Explain {
1802        code: "bynk.event.bad_schema_version",
1803        blurb: "`@schema(N)` states the version an event is at, so that the number can be reviewed in the source and is checked against the version the registry computes. `N` must be one positive `Int` literal, given by position, and `@schema` may appear once on an event: `@schema(0)`, `@schema(\"2\")`, `@schema(v: 2)` and a second `@schema` are all refused. Write `@schema(2)`, or drop the annotation, since the registry tracks the version anyway.",
1804        example: "event Paid @schema(0) = {    // ✗ versions start at 1\nevent Paid @schema(1) = {    // ✓\n    id: String,\n}\n\nconst Version: Int = 1\nevent Refunded @schema(Version) = {    // ✓ an `Int` constant bound to a literal\n    id: String,\n}",
1805    },
1806    Explain {
1807        code: "bynk.event.duplicate_handler",
1808        blurb: "A `from Events(E)` service has exactly one `on event` handler. To react to an event in two ways, declare two services, each subscribing to it: every subscriber is delivered to independently. So the second handler is refused here, and the fix is to move it into a service of its own.",
1809        example: "service onPaid from Events(Paid) {\n    on event(e: Paid) -> Effect[()] { … }\n    on event(e: Paid) -> Effect[()] { … }   // ✗ a service has one `on event` handler\n}\n\nservice onPaidAudit from Events(Paid) {     // ✓ a second subscriber, delivered to separately\n    on event(e: Paid) -> Effect[()] { … }\n}",
1810    },
1811    Explain {
1812        code: "bynk.event.emit_not_an_event",
1813        blurb: "`Events.emit[E]` takes an `event` type. A plain `type` declared in the same context is refused: nothing could subscribe to it, since a `from Events(…)` header names events, so the emission would silently go nowhere. Declare the type with `event` instead, or name the event you meant. A name that is not declared in this context at all is `bynk.event.emit_outside_owner`.",
1814        example: "type Receipt = { id: String }\nevent Paid = { id: String }\n\nEvents.emit[Receipt](Receipt { id: id })   // ✗ `Receipt` is a `type`, not an `event`\nEvents.emit[Paid](Paid { id: id })         // ✓ an `event` of this context",
1815    },
1816    Explain {
1817        code: "bynk.event.emit_outside_owner",
1818        blurb: "Only the context that declares an event may emit it. A consumer can see the event through `consumes`, to subscribe to it with `from Events(…)`, but being able to name a type does not make it yours to forge: other contexts then could not trust that an event came from its owner. Emit an event of your own, or call a service of the owning context and let it emit.",
1819        example: "// orders.bynk\ncontext orders\n\nexports transparent { Paid }\n\nevent Paid = { id: String }\n\n// mailer.bynk\ncontext mailer\n\nconsumes orders\nconsumes bynk { Events }\n\nevent Sent = { id: String }\n\nEvents.emit[Paid](Paid { id: \"x\" })   // ✗ `Paid` belongs to `orders`\nEvents.emit[Sent](Sent { id: \"x\" })   // ✓ `Sent` is declared here",
1820    },
1821    Explain {
1822        code: "bynk.event.handler_param_type_mismatch",
1823        blurb: "An `on event` handler's first parameter is the event itself, so its type must be the one the `from Events(E)` header names. A subscription pattern is checked against that event, and the body reads `e` at that type. Make the parameter `E`, or change the header to the event you mean to handle. The optional second parameter is `EventEnvelope`; other mistakes there are `bynk.event.bad_params`.",
1824        example: "event Paid = { id: String }\nevent Refunded = { id: String }\n\nservice onPaid from Events(Paid) {\n    on event(e: Refunded) -> Effect[()] { … }   // ✗ the header says `Paid`\n    on event(e: Paid) -> Effect[()] { … }       // ✓\n}",
1825    },
1826    Explain {
1827        code: "bynk.event.outside_context",
1828        blurb: "An `event` is declared in a context, and only that context may emit it, so an event belongs to its owner. A `commons` is shared code that other units `uses`, with no owner to emit from, so one may not declare an event. Declare the event in the context that raises it. Other contexts subscribe by consuming that context.",
1829        example: "commons shop\n\nevent Paid = { id: String }   // ✗ a commons has no owner to emit it\n\ncontext shop\n\nevent Paid = { id: String }   // ✓ declared where it is emitted",
1830    },
1831    Explain {
1832        code: "bynk.event.pattern_duplicate_field",
1833        blurb: "A subscription pattern narrows delivery by field: `from Events(Paid { region: Domestic, .. })` runs the handler only when `region` is `Domestic`. The listed fields combine with AND, so naming one twice would ask for two values at once, or say the same thing twice, and is refused rather than guessed at. List each field once. To accept several values, leave the field out of the pattern and `match` on it in the handler.",
1834        example: "service OnPaid from Events(Paid { region: Domestic, region: International, .. }) {    // ✗ `region` twice\nservice OnPaid from Events(Paid { region: Domestic, .. }) {                            // ✓\n    on event(e: Paid) -> Effect[()] { … }\n}",
1835    },
1836    Explain {
1837        code: "bynk.event.pattern_type_mismatch",
1838        blurb: "A subscription pattern compares a field with a literal or a variant, so the value must be of the field's type: an `Int` literal for an `Int` field, a `String` for a `String`, a variant of the field's own sum type. A value of any other type could never match an emission. Write one of the field's type.",
1839        example: "event Paid = { id: String, amount: Int }\n\nservice onPaid from Events(Paid { amount: \"10\", .. }) {   // ✗ `amount` is an `Int`\n\nservice onPaid from Events(Paid { amount: 10, .. }) {   // ✓",
1840    },
1841    Explain {
1842        code: "bynk.event.pattern_unknown_field",
1843        blurb: "A subscription pattern filters on the event's own fields, so each name in it must be one the event declares. A name that matches none could never filter anything, and is usually a misspelling; the diagnostic lists the declared fields. Use one of them.",
1844        example: "event Paid = { id: String, amount: Int }\n\nservice onPaid from Events(Paid { total: 10, .. }) {   // ✗ `Paid` has no field `total`\n\nservice onPaid from Events(Paid { amount: 10, .. }) {   // ✓",
1845    },
1846    Explain {
1847        code: "bynk.event.pattern_unknown_variant",
1848        blurb: "A pattern that tests a sum-typed field names a variant of that type, and an emission can only carry the variants the type declares. A name it lacks, often a misspelling, could never match. Use a variant the type declares. A variant that carries a payload is refused too, as `bynk.event.pattern_variant_payload`.",
1849        example: "type Region =\n    | Domestic\n    | International\n    | Refunded(reason: String)\nevent Paid = { id: String, region: Region }\n\nservice onPaid from Events(Paid { region: Region.Nowhere, .. }) {   // ✗ `Region` has no `Nowhere`\n\nservice onPaid from Events(Paid { region: Region.Domestic, .. }) {   // ✓",
1850    },
1851    Explain {
1852        code: "bynk.event.pattern_variant_payload",
1853        blurb: "A pattern can test only which variant a field holds, not what it carries. For a variant with a payload that would admit emissions the pattern looks as if it excludes, so only payload-free variants are allowed. Subscribe to a payload-free variant, or drop the pattern and read the field in the handler's body.",
1854        example: "type Region =\n    | Domestic\n    | International\n    | Refunded(reason: String)\nevent Paid = { id: String, region: Region }\n\nservice onPaid from Events(Paid { region: Region.Refunded, .. }) {   // ✗ `Refunded` carries a `reason`\n\nservice onPaid from Events(Paid { region: Region.Domestic, .. }) {   // ✓ no payload",
1855    },
1856    Explain {
1857        code: "bynk.event.return_not_effect_unit",
1858        blurb: "Emission is fire-and-forget: nothing receives a subscriber's result, so an `on event` handler returns `Effect[()]` and anything else is refused. Return `Effect.pure(())` once its work is done, and move a value it computes into an effect the handler performs, such as a write. A handler that does not return an `Effect` at all is `bynk.service.return_not_effect`.",
1859        example: "service onPaid from Events(Paid) {\n    on event(e: Paid) -> Effect[Int] { … }   // ✗ the result has nowhere to go\n    on event(e: Paid) -> Effect[()] { … }    // ✓\n}",
1860    },
1861    Explain {
1862        code: "bynk.event.unknown_annotation",
1863        blurb: "The only annotation an event accepts is `@schema(N)`, which asserts its schema version. Names like `@indexed` belong to agent state and mean nothing on an event, so a stray or misspelt one would be silently ignored if it were not refused. Remove the annotation, or use `@schema` with a positive integer.",
1864        example: "event Paid @indexed = { id: String }   // ✗ not an event annotation\n\nevent Paid @schema(1) = { id: String }   // ✓",
1865    },
1866    Explain {
1867        code: "bynk.event.unknown_subscription",
1868        blurb: "A `from Events(E)` header must name an event declared in this context or in a context it `consumes`. A name that matches neither would be a subscription that never receives anything, and nothing would say so; it is almost always a misspelling, or a `consumes` that is missing. Fix the name, or add `consumes` for the context whose `event` it is.",
1869        example: "context mailer\n\nconsumes orders\n\nservice onPaid from Events(Payd) {   // ✗ no event `Payd`\n\nservice onPaid from Events(Paid) {   // ✓ the event `orders` declares",
1870    },
1871    Explain {
1872        code: "bynk.exec.unavailable",
1873        blurb: "A function that uses `detach`, `within` or `race` hands work to the execution context, which a service handler has. An agent handler, a WebSocket handler, a provider operation, a function that is not effectful and a `const`, `store` or predicate initialiser do not. Calling such a function from one of those, directly or through other functions, or naming it as a value, is refused. The note gives the chain of calls down to the construct. Make the call in a service handler, and pass what it returns on.",
1874        example: "fn bounded(e: Effect[Int]) -> Effect[Bool] { … }\n\nagent Counter {\n    key id: String\n    store n: Cell[Int] = 0\n\n    on call check() -> Effect[Bool] {\n        bounded(Effect.pure(1))    // ✗ an agent handler has no execution context\n    }\n}\n\nservice api {\n    on call() -> Effect[Bool] by Caller {\n        bounded(Effect.pure(1))    // ✓ a service handler has\n    }\n}",
1875    },
1876    Explain {
1877        code: "bynk.expect.faults_not_effect",
1878        blurb: "`expect <call> faults` claims that an effectful call throws, for \
1879                instance because a `stub … fails`. Only a call can fault, so the \
1880                subject must be the call itself, with type `Effect[_]`. A value \
1881                already bound, or a pure method on one, has nothing left to throw. \
1882                Write the call inside the claim, not a name bound from it. A fault \
1883                that is not claimed fails the case.",
1884        example: "// tests/vault.test.bynk\n\
1885                  let label = \"sealed\"\n\
1886                  expect label.length() faults   // ✗ a pure method, not an effectful call\n\
1887                  expect box.call() faults       // ✓ the call that faults",
1888    },
1889    Explain {
1890        code: "bynk.expect.impure_predicate",
1891        blurb: "An `expect` predicate is a pure claim: the same predicate surface \
1892                as `invariant` and `ensures`. A capability or service call inside \
1893                it, even one held in a list or returned by a lambda, would run \
1894                when the claim is checked, and its call would be recorded as if \
1895                the unit under test had made it. Run the call before the claim \
1896                with `let x <- …`, then state the claim about `x`. A fault claim \
1897                (`expect <call> faults`) is the one form that runs its call.",
1898        example: "// tests/pay.test.bynk\n\
1899                  expect [Logger.log(\"x\")].length() == 1   // ✗ runs Logger.log\n\
1900                  let r <- authorise.call(100)\n\
1901                  expect r is Ok(_)                         // ✓ the call runs first",
1902    },
1903    Explain {
1904        code: "bynk.expect.not_bool",
1905        blurb: "`expect` states a claim that is checked when the case runs, so its \
1906                predicate must be a `Bool`: true, or the case fails. A count or a \
1907                record is not a claim. Compare the value with what you expect \
1908                (`==`, `<`, `is`), or use a method that returns `Bool`. It is the \
1909                same predicate surface that `invariant` and `ensures` use.",
1910        example: "// demo/count.bynk\n\
1911                  fn bump(n: Int) -> Int { n + 1 }\n\
1912                  \n\
1913                  // tests/count.test.bynk\n\
1914                  expect bump(1)         // ✗ an Int is not a claim\n\
1915                  expect bump(1) == 2    // ✓ compare it",
1916    },
1917    Explain {
1918        code: "bynk.expect.outside_case",
1919        blurb: "`expect` is a test claim, checked when a `case` runs. Production \
1920                code has no test runner to report a failure to, so an `expect` in \
1921                a function, a handler or anywhere else outside a `case` body is \
1922                refused. To check a condition in running code, return a `Bool` or \
1923                a `Result`; to check it in a test, move the `expect` into a case. \
1924                A `requires` or `ensures` contract is the always-on form.",
1925        example: "// demo/rules.bynk\n\
1926                  fn positive(n: Int) -> Bool {\n\
1927                  \x20   expect n > 0           // ✗ not in a case\n\
1928                  \x20   n > 0\n\
1929                  }\n\
1930                  \n\
1931                  // tests/rules.test.bynk\n\
1932                  expect positive(1)       // ✓ in a case",
1933    },
1934    Explain {
1935        code: "bynk.exports.capability_not_provided",
1936        blurb: "`exports capability { Clock }` lets other contexts depend on `Clock` and have it \
1937                built for them, so the exporting context must also say how: a `provides Clock = \
1938                … { … }` declaration. Without one, a consumer would hold a capability that \
1939                nothing in the project can instantiate. Add the provider. (A derived capability, \
1940                `capability Name = Kind`, cannot be exported at all; that is \
1941                `bynk.exports.derived_capability`.)",
1942        example: "exports capability { Clock }       // ✗ nothing provides `Clock`\n\
1943                  \n\
1944                  capability Clock {\n    fn now() -> Effect[Int]\n\
1945                  }\n\
1946                  \n\
1947                  provides Clock = Fixed {           // ✓\n    fn now() -> Effect[Int] { … }\n\
1948                  }",
1949    },
1950    Explain {
1951        code: "bynk.exports.conflicting_visibility",
1952        blurb: "A type is exported `opaque`, so consuming contexts can pass it around but not look inside it, or `transparent`, so they can. It cannot be both, and the compiler will not pick for you. Keep the clause you mean and delete the other. The same visibility twice is `bynk.exports.duplicate_export`.",
1953        example: "exports opaque { OrderId }\nexports transparent { OrderId }    // ✗ already exported `opaque`\n\ntype OrderId = String where Matches(\"ORD-[0-9]+\")\n\nexports opaque { OrderId }         // ✓ one visibility",
1954    },
1955    Explain {
1956        code: "bynk.exports.derived_capability",
1957        blurb: "A derived capability is an instance of a platform resource, such as a KV namespace, and its data belongs to the context that declares it. Exporting it would let another context read and write that data directly. Keep it out of `exports capability`; another context reaches the data through this context's services.",
1958        example: "exports capability { Sessions }\n\ncapability Sessions = Kv   // ✗ an instance cannot be exported\n\ncapability Sessions = Kv   // ✓ private to this context",
1959    },
1960    Explain {
1961        code: "bynk.exports.duplicate_export",
1962        blurb: "A type or capability is exported once. Naming it again in a second `exports` clause with the same visibility adds nothing, and usually means a clause was pasted twice, or a name was meant for another one. Delete the repeat. Within a single clause the repeat is `bynk.exports.duplicate_in_clause`, and the same type under both `opaque` and `transparent` is `bynk.exports.conflicting_visibility`.",
1963        example: "exports transparent { Order }\nexports transparent { Order }    // ✗ already exported above\n\ntype Order = { total: Int }\n\nexports transparent { Order }    // ✓ exported once",
1964    },
1965    Explain {
1966        code: "bynk.exports.duplicate_in_clause",
1967        blurb: "An `exports` clause lists each type once. Naming one twice is a typo or a pasted name, and the second may have been meant for another type. Delete the repeat, or correct the name. The same type in two separate clauses is `bynk.exports.duplicate_export`.",
1968        example: "exports transparent { Order, Order }    // ✗ `Order` listed twice\n\ntype Order = { total: Int }\n\nexports transparent { Order }           // ✓ listed once",
1969    },
1970    Explain {
1971        code: "bynk.exports.undeclared_capability",
1972        blurb: "`exports capability { Clock }` offers a capability of this context to the contexts that consume it, so the capability has to be declared in this context, and provided there too (`bynk.exports.capability_not_provided`). A name that is not declared is usually a misspelling. Correct it, or declare the capability here. A name in a type `exports` clause is `bynk.exports.undeclared_type`.",
1973        example: "exports capability { Cloc }      // ✗ no capability `Cloc` in this context\n\ncapability Clock {\n    fn now() -> Effect[Int]\n}\n\nexports capability { Clock }     // ✓ the declared name\n\nprovides Clock = Fixed {\n    fn now() -> Effect[Int] { Effect.pure(0) }\n}",
1974    },
1975    Explain {
1976        code: "bynk.exports.undeclared_type",
1977        blurb: "An `exports` clause lists types this context declares, to make them visible to the contexts that consume it. A name the context does not declare has nothing to export: it is usually a misspelling, or a type that is declared elsewhere. Correct the name, or declare the type in this context. A name in `exports capability` that is not declared is `bynk.exports.undeclared_capability`.",
1978        example: "exports opaque { Ordr }          // ✗ no type `Ordr` in this context\n\ntype Order = { total: Int }\n\nexports opaque { Order }         // ✓ the declared name",
1979    },
1980    Explain {
1981        code: "bynk.fixture.binary_content",
1982        blurb: "A `fixture` becomes a `String` in the test code, so its file must be text. A file holding a NUL byte is binary, and a `String` made from it would be meaningless. Keep a text form of the data in the fixture, such as base64, and decode it in the case with `Bytes.fromBase64`. Text that is not valid UTF-8 is `bynk.fixture.invalid_encoding`.",
1983        example: "fixture blob = \"fixtures/blob.bin\"    // ✗ the file has a NUL byte\n\nfixture blob = \"fixtures/blob.b64\"    // ✓ its base64 text",
1984    },
1985    Explain {
1986        code: "bynk.fixture.duplicate",
1987        blurb: "A fixture is a `String` constant used by its name in the suite, so a suite declares each name once: a second `fixture note` would leave `note` meaning two files. Give each fixture its own name. A fixture whose name is a declaration already in scope is `bynk.resolve.name_conflict` instead.",
1988        example: "fixture note = \"fixtures/a.txt\"\nfixture note = \"fixtures/b.txt\"      // ✗ `note` is already declared\n\nfixture note = \"fixtures/a.txt\"\nfixture other = \"fixtures/b.txt\"     // ✓ one name each",
1989    },
1990    Explain {
1991        code: "bynk.fixture.invalid_encoding",
1992        blurb: "A `fixture` becomes a `String`, which is Unicode text, so its file must be valid UTF-8. A file saved in another encoding, such as Latin-1, holds bytes that cannot be read as text. Re-save it as UTF-8. A file that holds a NUL byte is binary and is `bynk.fixture.binary_content`.",
1993        example: "fixture note = \"fixtures/note.txt\"    // ✗ the file is Latin-1, not UTF-8\nfixture note = \"fixtures/note.txt\"    // ✓ once the file is saved as UTF-8",
1994    },
1995    Explain {
1996        code: "bynk.fixture.missing_file",
1997        blurb: "A `fixture` reads a file into a `String` for the suite's \
1998                cases, so the file must exist as a regular file in the \
1999                project's `fixtures/` folder. A misspelt name, a file not yet \
2000                added, or a symbolic link (which is not followed) leaves the \
2001                suite without its input. Add the file or correct the path. A \
2002                path outside that folder is \
2003                `bynk.fixture.outside_fixtures_dir`; an empty, absolute or \
2004                `..` path is `bynk.fixture.unsafe_path`.",
2005        example: "// tests/desk.test.bynk\n\
2006                  fixture note = \"fixtures/absent.txt\"    // ✗ no such file in `fixtures/`\n\
2007                  fixture note = \"fixtures/note.txt\"      // ✓",
2008    },
2009    Explain {
2010        code: "bynk.fixture.outside_fixtures_dir",
2011        blurb: "A fixture is test input, and it may come only from the project's `fixtures/` folder. If any path were allowed, a declaration could read `.env` or a source file just by naming it. Move the file into `fixtures/` and name it there. A path that is empty, absolute or contains `..` is `bynk.fixture.unsafe_path` instead.",
2012        example: "fixture note = \"data/note.txt\"        // ✗ not in the fixtures/ folder\n\nfixture note = \"fixtures/note.txt\"    // ✓",
2013    },
2014    Explain {
2015        code: "bynk.fixture.unsafe_path",
2016        blurb: "A fixture's path is joined onto the project root to find the file, so it must stay inside the project: it may not be empty or absolute, and it may not contain a `..` segment, which could climb out of it. Write the path relative to the project root, inside `fixtures/`. A relative path that is only outside `fixtures/` is `bynk.fixture.outside_fixtures_dir`.",
2017        example: "fixture note = \"fixtures/../note.txt\"    // ✗ a `..` segment\n\nfixture note = \"fixtures/note.txt\"       // ✓",
2018    },
2019    Explain {
2020        code: "bynk.generics.ambiguous_instantiation",
2021        blurb: "A generic function with an `Ord` bound, named as a value, is instantiated where it stands, from the function type expected there. When that type is still open, because the receiving parameter's own type is not fixed yet, there is no `T` to choose, and a guess could order by the wrong type. Wrap the function in a lambda, which is checked after the other arguments, or annotate the expected function type.",
2022        example: "fn same[T: Ord](x: T) -> T { x }\n\nfn wrap[A](g: (A) -> A, x: A) -> A { g(x) }\n\nfn pick() -> Int { wrap(same, 1) }              // ✗ `A` is known only from the later argument\n\nfn pick() -> Int { wrap((n) => same(n), 1) }    // ✓ a lambda is checked after it",
2023    },
2024    Explain {
2025        code: "bynk.generics.bound_on_capability_op",
2026        blurb: "A capability operation is carried out by its provider, written in TypeScript, so it has no Bynk body for a bound to serve; an `Ord` bound would also add a hidden comparator argument. Only `Key` and `Codable` are accepted, and both are handled at the call site. Remove the bound, and compare in the code that calls the operation.",
2027        example: "capability Registry {\n    fn lookup[K: Key + Ord](key: K) -> Effect[Option[String]]   // ✗ only `Key` and `Codable`\n}\n\ncapability Registry {\n    fn lookup[K: Key](key: K) -> Effect[Option[String]]         // ✓\n}",
2028    },
2029    Explain {
2030        code: "bynk.generics.codable_op_return_not_first_party",
2031        blurb: "A `Codable` parameter of a capability operation is encoded at the call site, so the provider receives plain JSON. Putting `T` in the return type asks the call site to decode the provider's reply back into `T`, and that is accepted only for the standard library's own operations, whose providers are reviewed with the runtime and which declare what a reply that does not decode means. A capability you declare returns plain data, such as a `String`, and you decode it where the call is made with `Json.decode`.",
2032        example: "capability Store {\n    fn load[T: Codable](id: String) -> Effect[Option[T]]   // ✗ `T` in the return type\n}\n\ncapability Store {\n    fn load(id: String) -> Effect[Option[String]]          // ✓ plain data back\n}",
2033    },
2034    Explain {
2035        code: "bynk.generics.duplicate_type_param",
2036        blurb: "The type parameters of one declaration are told apart by name, and a repeat would collapse into a single parameter, so `Pair[T, T]` would force both fields to the same type with no sign of it. Give each parameter its own name. A method's own type parameter may not reuse a name from its receiver type either, as that would make the two ambiguous.",
2037        example: "type Pair[T, T] = { a: T, b: T }    // ✗ `T` declared twice\n\ntype Pair[A, B] = { a: A, b: B }    // ✓ one name for each",
2038    },
2039    Explain {
2040        code: "bynk.generics.generic_non_record",
2041        blurb: "Type parameters are for a type whose shape can mention them: a record, `{ value: T }`, or a sum whose variants carry payloads. A refined, opaque or alias type has a fixed base, so a parameter would have nowhere to go. Give the type a record or sum body that uses its parameters, or drop the parameters.",
2042        example: "type Wrapped[T] = Int            // ✗ `T` has nowhere to be used\n\ntype Wrapped[T] = { value: T }   // ✓ a record may be generic",
2043    },
2044    Explain {
2045        code: "bynk.generics.generic_sum_embeds",
2046        blurb: "`embeds E as V` lets `?` wrap an `E` error in the variant `V`, picking the variant by the error's type. In a generic sum that conversion would have to hold for every instantiation, which is not supported. Drop the `embeds` clause and wrap the error by hand where it is needed, with `.mapErr(Payment)`, or make the sum non-generic.",
2047        example: "type PayError = enum { Declined }\n\ntype Failure[T] =\n    | Payment(reason: PayError)\n    | Other(value: T)\n    embeds PayError as Payment    // ✗ a generic sum cannot embed\n\ntype Failure[T] =\n    | Payment(reason: PayError)\n    | Other(value: T)             // ✓ no `embeds`; wrap with `.mapErr(Payment)`",
2048    },
2049    Explain {
2050        code: "bynk.generics.internal_op_annotation",
2051        blurb: "A capability operation's reply policy, `@onUndecodable(miss)` or `@onUndecodable(fault)`, says what a reply that does not decode as the operation's payload type means. It belongs to the standard library's own operations, where the provider is reviewed with the runtime, so a capability you declare takes no annotation. Remove it.",
2052        example: "capability Store {\n    fn load(id: String) -> Effect[Option[String]] @onUndecodable(miss)   // ✗ internal\n}\n\ncapability Store {\n    fn load(id: String) -> Effect[Option[String]]                    // ✓\n}",
2053    },
2054    Explain {
2055        code: "bynk.generics.method_on_generic_type",
2056        blurb: "A static method on a generic type (one with no `self`) is generic over the type's parameters, and \
2057                a call has to be able to fix each of them: from its arguments, from the type the call is \
2058                expected to have, or from explicit type arguments. If the method's parameter and return \
2059                types never mention one of the type's parameters, nothing in a call can determine it, so \
2060                the declaration is refused once, here, rather than every call being ambiguous. Mention \
2061                the parameter in the signature, or make the method a free function. An instance method \
2062                (with `self`) is not affected, since the receiver carries the type. A call that leaves a \
2063                parameter open anyway is `bynk.generics.uninferable_type_arg`.",
2064        example: "type Box[T] = { value: T }\n\n\
2065                  fn Box.empty() -> Box[Int] {              // ✗ never mentions `T`\n    \
2066                    Box { value: 0 }\n}\n\n\
2067                  fn Box.empty() -> Box[Option[T]] {        // ✓ `T` appears in the return type\n    \
2068                    Box { value: None }\n}",
2069    },
2070    Explain {
2071        code: "bynk.generics.missing_codable_bound",
2072        blurb: "`Json.encode` and `Json.decode` work only on types that cross the JSON boundary, and a type parameter might be a function, an `Effect` or another type that does not. So a type parameter that is encoded or decoded, or passed to a `Codable`-bounded parameter of another generic or of a capability operation, must be declared `T: Codable` (or `where A: Codable` for a receiver type's parameter), and a call must instantiate it with a type that is `Codable`. At run time the bound costs a hidden codec argument, so a refined type is still revalidated on decode. `Codable` does not imply `Eq`, so the diagnostic's fix writes `T: Eq + Codable` beside an existing `Eq`, and `bynk check --fix` applies it across a project. It is the `Json` counterpart of `bynk.generics.missing_eq_bound`, `bynk.generics.missing_ord_bound` and `bynk.generics.missing_key_bound`.",
2073        example: "fn encode[T](v: T) -> String {\n    \
2074                    Json.encode(v)                  // ✗ `T` could be a function\n}\n\n\
2075                  fn encode[T: Codable](v: T) -> String {\n    \
2076                    Json.encode(v)                  // ✓ the bound is in the signature\n}",
2077    },
2078    Explain {
2079        code: "bynk.generics.missing_eq_bound",
2080        blurb: "`==` and `!=` work on a type parameter only if the function says so with an `Eq` bound. A type parameter stands for any type, and some types cannot be compared: a function, an `Effect`, a `Query`, a `Stream` or a held `Connection`. The bound puts that requirement in the signature, where a caller, hover and signature help can see it, instead of leaving it to fail inside the body. The same rule applies when a generic passes its own parameter to an `Eq`-bounded parameter of another generic, so a bound appears at every link of a chain of calls. Declare `T: Eq`; `T: Ord` and `T: Key` also allow `==`. The diagnostic's fix adds the bound, and `bynk check --fix` applies it across a project.",
2081        example: "fn same[T](a: T, b: T) -> Bool {\n    a == b                  // ✗ `T` could be a function\n}\n\n\
2082                  fn same[T: Eq](a: T, b: T) -> Bool {\n    a == b                  // ✓ the bound is in the signature\n}",
2083    },
2084    Explain {
2085        code: "bynk.generics.missing_key_bound",
2086        blurb: "A `Map` key or a `Set` element must be a type that can be held under a canonical encoding, and \
2087                a type parameter might be a function or another type that cannot. So a type parameter \
2088                that reaches a `Map` key or a `Set` element, in a signature, a generic type's field, or \
2089                a `distinct`, `groupBy` or join key, must be declared `K: Key`, and a call must \
2090                instantiate it with a key type. `Key` implies `Eq`, so an existing `Eq` bound is \
2091                replaced rather than joined (`K: Eq + Key` is a warning). The diagnostic's fix declares \
2092                the bound, and `bynk check --fix` applies it across a project.",
2093        example: "fn single[K](k: K) -> Map[K, Int] {                 // ✗ `K` has no `Key` bound\n    Map.empty().insert(k, 1)\n}\n\n\
2094                  fn single[K: Key](k: K) -> Map[K, Int] {            // ✓ declared\n    Map.empty().insert(k, 1)\n}",
2095    },
2096    Explain {
2097        code: "bynk.generics.missing_ord_bound",
2098        blurb: "`<`, `<=`, `>` and `>=` work on a type parameter only if the function says so with an `Ord` bound. A type parameter stands for any type, and many types have no total order: a function, an `Effect`, a `Bool`, a record that does not `derives Ord`. The bound puts the requirement in the signature, where a caller, hover and signature help can see it, and a call must instantiate it with an orderable type. The same rule covers an ordering key and a parameter passed on to an `Ord`-bounded parameter of another generic, so the bound appears at every link of a chain of calls. Declare `T: Ord`; it implies `Eq`, so an existing `Eq` is replaced (`T: Eq + Ord` is only a warning). The diagnostic's fix adds the bound, and `bynk check --fix` applies it across a project.",
2099        example: "fn bigger[T](a: T, b: T) -> Bool {\n    \
2100                    a > b                            // ✗ `T` has no order\n}\n\n\
2101                  fn bigger[T: Ord](a: T, b: T) -> Bool {\n    \
2102                    a > b                            // ✓ the bound is in the signature\n}",
2103    },
2104    Explain {
2105        code: "bynk.generics.polymorphic_recursion",
2106        blurb: "A generic type may refer to itself only uniformly: the self-reference must pass \
2107                the declaration's own type parameters through unchanged and in order, as \
2108                `Weird[T]` inside `Weird[T]`. Anything else is polymorphic recursion, such as \
2109                `Weird[List[T]]` inside `Weird[T]`, or `Pair[B, A]` inside `Pair[A, B]`, and it \
2110                generates an unbounded set of instantiations, so it is refused at the \
2111                declaration. The same holds for mutually recursive generics: a partner may be \
2112                applied only to the declaration's own parameters or to types that mention none, \
2113                never to a type that wraps one of them.",
2114        example: "type Weird[T] = { value: T, next: Option[Weird[List[T]]] }   // ✗ a different instantiation\n\n\
2115                  type Weird[T] = { value: T, next: Option[Weird[T]] }         // ✓ parameters passed through",
2116    },
2117    Explain {
2118        code: "bynk.generics.recursive_generic_at_boundary",
2119        blurb: "A recursive generic type, a record or sum that contains itself, declares and works \
2120                inside a context, but it has no codec yet. So it is refused wherever a codec is \
2121                required: a service or agent handler signature, an agent `store` field or key, an \
2122                event field, an actor identity type, a `Json.encode` or `Json.decode` target, or a \
2123                `Codable` witness. The error fires once per use, and when the type is reached \
2124                through another type, its note names the field path. To cross a boundary today, \
2125                use a concrete recursive type, or keep the generic one inside the context.",
2126        example: "type Tree[A] =\n    | Leaf\n    | Node(left: Tree[A], value: A, right: Tree[A])\n\n\
2127                  service s {\n    on call(t: Tree[Int]) -> Effect[Int] by Caller { … }   // ✗ no codec for a recursive generic\n}\n\n\
2128                  type IntTree =\n    | Leaf\n    | Node(left: IntTree, value: Int, right: IntTree)\n\n\
2129                  service s {\n    on call(t: IntTree) -> Effect[Int] by Caller { … }     // ✓ a concrete recursive type\n}",
2130    },
2131    Explain {
2132        code: "bynk.generics.type_arg_count",
2133        blurb: "A generic type is applied to exactly as many type arguments as it declares parameters: `Box[T]` takes one. Too many, too few, arguments on a type that is not generic, and a generic type named with no arguments at all are all refused, since each argument fills one parameter. A type parameter such as `T` is not itself generic, so `T[Int]` is refused too. Give the arguments the declaration asks for.",
2134        example: "type Box[T] = { value: T }\n\nfn open(b: Box[Int, String]) -> Int {   // ✗ `Box` takes one type argument\n    0\n}\n\nfn open(b: Box[Int]) -> Int {           // ✓\n    0\n}",
2135    },
2136    Explain {
2137        code: "bynk.generics.type_arg_mismatch",
2138        blurb: "The type arguments of a generic call do not fit. The checker infers each type parameter from \
2139                the arguments, and an argument that contradicts what an earlier one \
2140                settled is refused: `pick(1, \"one\")` cannot make `T` both `Int` and `String`. The same \
2141                code covers explicit type arguments of the wrong number (`pick[Int, Int](…)`), type \
2142                arguments given to a function that is not generic, and a type parameter named like a \
2143                declared type. Make the arguments agree, give the type argument explicitly where the \
2144                inference is not what you meant, or rename the parameter.",
2145        example: "fn pick[T](a: T, b: T) -> T {\n    a\n}\n\n\
2146                  let x = pick(1, \"one\")          // ✗ `T` is `Int` from the first argument\n\n\
2147                  pick(1, 2)                      // ✓ both arguments are `Int`",
2148    },
2149    Explain {
2150        code: "bynk.generics.uninferable_type_arg",
2151        blurb: "A call to a generic function leaves a type parameter undetermined. Bynk fixes a type parameter \
2152                from the arguments and, failing that, from the type the call is expected to have; it \
2153                never guesses. `none()` has no argument that mentions `T`, and `let x = none()` gives it \
2154                no expected type, so there is nothing to choose `T` from. The error also fires when a \
2155                lambda's parameter types depend on a parameter that the other arguments leave open. Give \
2156                the type argument explicitly with `none[Int]()`, or annotate the binding so the expected \
2157                type supplies it: `let x: Option[Int] = none()`.",
2158        example: "fn none[T]() -> Option[T] {\n    None\n}\n\n\
2159                  let x = none()                    // ✗ nothing says what `T` is\n\n\
2160                  let x = none[Int]()               // ✓ given explicitly",
2161    },
2162    Explain {
2163        code: "bynk.generics.unknown_constraint",
2164        blurb: "A bound after a type parameter, `T: C`, must name one of the four constraints Bynk has: `Eq`, \
2165                `Ord`, `Key` and `Codable`. There are no user-defined constraints or interfaces, so a name \
2166                like `Hashable` or `Comparable` is refused rather than silently ignored; ignoring it \
2167                would let a function compile that promised more than the compiler could check. The same \
2168                code is reported for a `derives` clause that names anything but `Ord`; naming `Eq`, \
2169                `Key` or `Codable` there is `bynk.types.derives_automatic`, because they hold \
2170                automatically. Pick the constraint that matches what the body does: `Eq` for `==`, `Ord` \
2171                for ordering, `Key` for a `Map` key or `Set` element, `Codable` for `Json`.",
2172        example: "fn first[A: Hashable](x: A) -> A {       // ✗ `Hashable` is not a constraint\n    \
2173                    x\n}\n\n\
2174                  fn first[A: Key](x: A) -> A {            // ✓ one of `Eq`, `Ord`, `Key`, `Codable`\n    \
2175                    x\n}",
2176    },
2177    Explain {
2178        code: "bynk.generics.unknown_where_param",
2179        blurb: "A `where` clause bounds a type parameter, so it must name one: the function's own, or, for a method, its receiver type's. A name that is neither is usually a misspelling. Correct it, or declare the parameter in the brackets after the function's name. A bound that does not exist is `bynk.generics.unknown_constraint`.",
2180        example: "fn same[T](a: T) -> T where U: Eq { a }   // ✗ `U` is not a parameter here\n\nfn same[T](a: T) -> T where T: Eq { a }   // ✓ bound a parameter that is declared",
2181    },
2182    Explain {
2183        code: "bynk.given.cross_context_unknown_capability",
2184        blurb: "A context may only depend on a capability that the context providing it exports. `exports capability { … }` is the provider's decision about what it offers other contexts, and a capability it leaves out stays its own. So `consumes clock { Clock }`, or a qualified `given clock.Clock`, is refused when `clock` does not list `Clock`. Add the name to the provider's `exports capability` clause (it must declare and provide the capability), or correct the spelling here. A context that is not consumed at all is `bynk.resolve.unconsumed_context`.",
2185        example: "// shop.bynk\ncontext shop\n\nconsumes clock { Clock }   // ✗ `clock` exports no `Clock`\n\n\
2186                  // clock.bynk\ncontext clock\n\nexports capability { Clock }   // ✓ the provider offers it",
2187    },
2188    Explain {
2189        code: "bynk.given.fn_outside_context",
2190        blurb: "`given` lets a function use capabilities, and only a context declares which capabilities it consumes. A commons is shared by every context that uses it, and those may consume different capabilities, so a function in a commons or a suite cannot declare `given`. Take the operation as a parameter instead, and pass `(m) => Logger.error(m)` from the handler, or move the function into the context that consumes the capability. A method cannot declare `given` anywhere: that is `bynk.given.fn_unsupported`.",
2191        example: "fn warn(what: String) -> Effect[()] given Logger { … }   // ✗ a commons function has no `given`\n\nfn warn(log: (String) -> Effect[()], what: String) -> Effect[()] { … }   // ✓ the caller passes the operation in",
2192    },
2193    Explain {
2194        code: "bynk.given.fn_unsupported",
2195        blurb: "Only a free function in a context that returns `Effect[T]` may declare `given`. A capability operation is an effect, so a function that reaches one has to say so in its return type, and a method has no place to carry the capabilities. `Events` is refused too: `Events.emit` buffers until its handler commits, so emit in the handler, or pass the event back to the caller. Return `Effect[T]` and make it a free function, or take the operation as a function-value parameter. A `given` in a commons is `bynk.given.fn_outside_context`.",
2196        example: "fn size(sku: String) -> Int given Logger {   // ✗ it must return an `Effect`\n    3\n}\n\nfn size(sku: String) -> Effect[Int] given Logger {   // ✓\n    Effect.pure(3)\n}",
2197    },
2198    Explain {
2199        code: "bynk.given.missing_for_call",
2200        blurb: "A free function in a context may declare `given`, and then uses those capabilities as a handler \
2201                does. Because a `given` clause is the honest statement of everything a body can reach, a \
2202                caller has to account for what its callee reaches: a call to, or a reference to, such a \
2203                function must occur in a body whose own `given` includes every one of the callee's. \
2204                Otherwise a handler's signature would hide capabilities it uses in effect. The rule is \
2205                checked at every call, so it holds along a whole chain of calls, and the call counts as \
2206                a use of the callee's capabilities. Add the missing capabilities to the caller's \
2207                `given`; the error names which ones. Using a capability directly, without declaring \
2208                it, is `bynk.given.undeclared_capability`.",
2209        example: "fn warn(what: String) -> Effect[()] given Logger { … }\n\n\
2210                  on call(sku: String) -> Effect[()] by Caller {\n    \
2211                    warn(sku)                           // ✗ `warn` needs `given Logger`\n}\n\n\
2212                  on call(sku: String) -> Effect[()] by Caller given Logger {   // ✓ declared on the caller\n    \
2213                    warn(sku)\n}",
2214    },
2215    Explain {
2216        code: "bynk.given.undeclared_capability",
2217        blurb: "A handler may only use a capability it has itself declared with \
2218                `given`. Effects in Bynk are explicit: the `given` clause is the \
2219                handler's honest, checkable statement of every capability it \
2220                reaches for, so a reader (and the compiler) can see a handler's \
2221                full reach from its signature alone. Using a capability that is \
2222                not in `given` is the missing half of that contract.",
2223        example: "on call() -> Effect[()] by Caller {\n    \
2224                    Logger.log(\"hi\")                     // ✗ uses Logger without declaring it\n}\n\n\
2225                  on call() -> Effect[()] by Caller given Logger {   // ✓ declared, then used\n    \
2226                    Logger.log(\"hi\")\n}",
2227    },
2228    Explain {
2229        code: "bynk.given.unknown_capability",
2230        blurb: "A `given` clause names a capability that no provider declares. A \
2231                capability is a typed interface to the outside world; it has to be \
2232                *declared* (as a `capability`, or brought in from a consumed \
2233                context) before a handler can ask for it. This usually means a \
2234                typo in the capability name, or a missing `uses`/`consumes` that \
2235                would bring the capability into scope.",
2236        example: "provides Greeter = Polite given Loger { … }    // ✗ no capability named `Loger`\n\n\
2237                  provides Greeter = Polite given Logger { … }   // ✓ matches the declared capability",
2238    },
2239    Explain {
2240        code: "bynk.held.branch_divergence",
2241        blurb: "A held value, such as a `Connection[F]`, must be disposed of exactly once. If one branch of an `if` or `match` closes, stores or passes it on while another leaves it, the compiler cannot say afterwards whether the value is still open to close, or already gone. Make every branch dispose of it, or none, and dispose of it once after the conditional. A connection that is never disposed of is `bynk.held.leak`.",
2242        example: "let _ <- if m == \"a\" { conn.close() } else { conn.send(ServerFrame { text: \"keep\" }) }   // ✗ one branch closes it\n\nlet _ <- if m == \"a\" { conn.send(ServerFrame { text: \"bye\" }) } else { conn.send(ServerFrame { text: \"keep\" }) }   // ✓ neither does\nlet _ <- conn.close()                                                                                          // ✓ closed once, after",
2243    },
2244    Explain {
2245        code: "bynk.held.consume_on_borrow",
2246        blurb: "A held value such as a `Connection[F]` has exactly one owner, and the owner must \
2247                dispose of it by storing, closing or handing it on. A closure that visits each \
2248                stored connection (`forEach`, `parTraverse` and their variants) is only lent \
2249                each one: it may `send`, which leaves the connection owned, but `close` or any \
2250                transfer would be an owner's act performed on a value the closure does not own. A \
2251                match guard borrows in the same \
2252                way, because it runs before its arm is chosen. To close connections, remove \
2253                them from the store, which closes them, in the owner's code and not in the \
2254                closure.",
2255        example: "conns.forEach((c: Connection[ServerFrame]) => c.close())                          // ✗ `c` is borrowed\n\n\
2256                  conns.forEach((c: Connection[ServerFrame]) => c.send(ServerFrame { text: \"closing\" }))   // ✓ `send` does not consume",
2257    },
2258    Explain {
2259        code: "bynk.held.leak",
2260        blurb: "A held value such as a `Connection[F]` has one owner, who must dispose of it before its scope ends: close it, store it (in a `Map[K, Connection[F]]` or a `Cell[Option[Connection[F]]]`), or pass it to a function or agent call that takes it. A dropped connection would stay open with nothing able to close it. The error is reported at the binding: a handler or function parameter, or a `let`. The connection `on open` receives is owned; the one `on message` and `on close` receive is only lent, so it carries no such duty. See `bynk.held.use_after_consume` (used after disposal) and `bynk.held.consume_on_borrow` (disposed of while borrowed).",
2261        example: "fn ignore(c: Connection[ServerFrame]) -> Effect[()] {   // ✗ `c` is never closed, stored or passed on\n  Effect.pure(())\n}\n\nfn finish(c: Connection[ServerFrame]) -> Effect[()] {   // ✓\n  c.close()\n}",
2262    },
2263    Explain {
2264        code: "bynk.held.query_accessor_on_held_map",
2265        blurb: "A held `Map[K, Connection]` is iterated with the broadcast operations, `forEach` (one at a time) or `parTraverse` (in parallel), not with a key query. `.entries`, `.keys` and `.values` would lift the connections out into a query, which the single-owner rules for held values do not allow. To send to every connection, broadcast over the map; to learn who is connected, keep a separate `Set` of their keys.",
2266        example: "conns.keys.collect()   // ✗ a held map has no key queries\n\nlet _ <- conns.parTraverse((c: Connection[ServerFrame]) => c.send(ServerFrame { text: text }))   // ✓ broadcast",
2267    },
2268    Explain {
2269        code: "bynk.held.unsupported_map_op",
2270        blurb: "`update` and `upsert` rebuild a map entry from its old value with a function. A held connection cannot be rebuilt from another: it is a live handle, stored and found by identity. So a held `Map[K, Connection]` takes `put`, `get`, `remove`, `contains` and `size`, and not these two. To replace an entry, `put` the new connection under the key, and to drop one, `remove` it.",
2271        example: "let _ <- conns.update(u, (c: Connection[ServerFrame]) => c)   // ✗ a connection cannot be derived from another\n\nlet _ <- conns.put(u, c)   // ✓ store the connection itself",
2272    },
2273    Explain {
2274        code: "bynk.held.unsupported_storage",
2275        blurb: "A held value, a `Connection[F]`, is a live handle owned by one place, not data. Only `Cell[Option[Connection]]` and `Map[K, Connection]` can hold one: a `Set` needs value equality, which a connection does not have, and a `Log` or `Cache` could retain or evict one without closing it. Keep connections in a `Map` keyed by something that identifies each, such as a user id, and iterate it with the broadcast operations.",
2276        example: "store conns: Set[Connection[ServerFrame]]   // ✗ a `Set` cannot hold a connection\n\nstore conns: Map[UserId, Connection[ServerFrame]]   // ✓ held by key",
2277    },
2278    Explain {
2279        code: "bynk.held.use_after_consume",
2280        blurb: "Closing, storing or passing on a held value such as a `Connection[F]` hands its single ownership away, and after that the name no longer refers to anything you may use. A later `send`, a second `close`, or any other mention of the binding is an error, reported on that later use, because the connection may already be closed or owned by someone else. Only `send` leaves a connection owned, so do every `send` first and dispose of the connection last. `bynk.held.leak` is the other end of the same rule (never disposed), and `bynk.held.consume_on_borrow` is the case where the code never owned the connection to begin with.",
2281        example: "let _ <- c.close()\nlet _ <- c.send(ServerFrame { text: \"bye\" })   // ✗ `c` was closed on the line above\n\nlet _ <- c.send(ServerFrame { text: \"bye\" })   // ✓ send first\nlet _ <- c.close()",
2282    },
2283    Explain {
2284        code: "bynk.history.not_an_agent",
2285        blurb: "`for all run: History[T]` generates a run of calls to an agent's handlers and drives them against a fresh instance. Only an agent has handlers to sequence, so `T` must be one declared in scope. For a value, a plain `for all x: T` generates the value. Name the agent.",
2286        example: "// tests/t.test.bynk\nfor all run: History[Amount] { … }   // ✗ `Amount` is a value type\nfor all run: History[Wallet] { … }   // ✓ an agent",
2287    },
2288    Explain {
2289        code: "bynk.history.not_generable",
2290        blurb: "To drive an agent the runner must make an argument for every handler, drawing each from its parameter's refinement domain. One parameter with no generator, such as a `Matches` pattern, stops it for the whole agent, since any handler may be chosen. Give that parameter a refinement that has one, such as `Length(3)`, or test that handler with a `case` and a pinned value instead. The same rule applies to a value `for all`, where a type that cannot be generated is `bynk.val.needs_pin`.",
2291        example: "// demo/wallet.bynk\ntype Code = String where Matches(\"[A-Z]{3}\")\n\n// tests/t.test.bynk\nfor all run: History[Wallet] { … }   // ✗ `setLabel` takes a `Code`, which has no generator\n\n// demo/wallet.bynk\ntype Code = String where Length(3)   // ✓ a refinement with a generator",
2292    },
2293    Explain {
2294        code: "bynk.history.outside_property",
2295        blurb: "`History[Agent]` is a generator, not a value type: it stands for a run the test runner makes for a `for all` binding. So it may appear only as the type of that binding inside a `property`, never in a function signature, a field or a `let`. Move the check into a `property` and assert over `run`.",
2296        example: "// demo/wallet.bynk\nfn peek(w: History[Wallet]) -> Int { 0 }   // ✗ not a value type\n\n// tests/t.test.bynk\nfor all run: History[Wallet] { … }         // ✓ in a `property`",
2297    },
2298    Explain {
2299        code: "bynk.history.restates_invariant",
2300        blurb: "Every state a driven run reaches has already passed the agent's `invariant` and `transition` checks, so a history property that only asserts the same thing over `run` cannot fail. The compiler flags it, and the check is deliberately narrow, so a near-copy may pass. Assert something the per-state rules do not say, such as a protocol across steps: a spend is accepted only after a top-up.",
2301        example: "// demo/wallet.bynk\ninvariant nonneg: balance >= 0\n\n// tests/t.test.bynk\nfor all run: History[Wallet] { expect run.all((s) => s.new.balance >= 0) }   // ✗ the invariant says this\nfor all run: History[Wallet] { expect run.all((s) => (s.call is Spend && s.accepted) implies run.upTo(s).any((p) => p.call is TopUp && p.accepted)) }   // ✓ a protocol across steps",
2302    },
2303    Explain {
2304        code: "bynk.http.body_kind_conflict",
2305        blurb: "`@raw`, `@form` and `@multipart` each say how a route's one `body` is read off the wire: untouched octets, a urlencoded form or a multipart upload. A body has one wire format, so a handler carries at most one of them, and the second one written is reported. Keep the annotation that matches what the client sends; a JSON body needs none of them.",
2306        example: "@form\n@raw(contentType: \"image/png\")   // ✗ the body is already a form\n@limit(maxBody: 1_000_000)\non POST(\"/signup\") (body: SignupForm) -> Effect[HttpResult[String]] by v: Visitor { … }\n\n@form                           // ✓ one wire format\non POST(\"/signup\") (body: SignupForm) -> Effect[HttpResult[String]] by v: Visitor { … }",
2307    },
2308    Explain {
2309        code: "bynk.http.body_on_get_or_delete",
2310        blurb: "A `GET` or `DELETE` request carries no body by convention, and proxies and some clients drop one, so a handler for either may not declare a `body` parameter. Send the data in the path or the query string (`query: Filter` decodes a record from it), or make the route a `POST`, `PUT` or `PATCH` if the client has something to upload. `@raw` and `@form` need a body too: `bynk.http.raw_on_bodyless`, `bynk.http.form_on_bodyless`.",
2311        example: "type Filter = { tag: String }\n\non GET(\"/items\") (body: Filter) -> Effect[HttpResult[String]] by v: Visitor { … }    // ✗ a GET has no body\n\non GET(\"/items\") (query: Filter) -> Effect[HttpResult[String]] by v: Visitor { … }   // ✓ read it from the query string",
2312    },
2313    Explain {
2314        code: "bynk.http.cache_bad_immutable",
2315        blurb: "`immutable` on `@cache` promises that the response at this URL never changes, so a cache may reuse it for the whole `maxAge` without asking again. A promise is either made or not, so the value must be the literal `true` or `false`; a bare word, a string or an expression is refused. Write `immutable: true` for a content-addressed path, or leave the argument out. The other arguments are `bynk.http.cache_bad_max_age` and `bynk.http.cache_bad_scope`.",
2316        example: "@cache(maxAge: 365.days, immutable: yes)    // ✗ `true` or `false`\non GET(\"/dl/:hex\") (hex: String) -> Effect[HttpResult[String]] by v: Visitor { … }\n\n@cache(maxAge: 365.days, immutable: true)   // ✓\non GET(\"/dl/:hex\") (hex: String) -> Effect[HttpResult[String]] by v: Visitor { … }",
2317    },
2318    Explain {
2319        code: "bynk.http.cache_bad_max_age",
2320        blurb: "`@cache` says how long a client or cache may reuse a `GET` response without asking again, so it needs a `maxAge`, and that must be a positive `Duration` literal. A bare number or a string is refused; write a `Duration` literal whose unit agrees with its number: `30.seconds`, `5.minutes`, `1.hour`. A positive duration that is not a whole number of seconds is `bynk.http.cache_max_age_fractional_seconds`.",
2321        example: "@cache(maxAge: 3600)      // ✗ a bare number, not a `Duration`\non GET(\"/links\") () -> Effect[HttpResult[String]] by v: Visitor { … }\n\n@cache(maxAge: 1.hour)   // ✓\non GET(\"/links\") () -> Effect[HttpResult[String]] by v: Visitor { … }\n\nconst Fresh: Duration = 1.hour\n@cache(maxAge: Fresh)   // ✓ a `Duration` constant bound to a literal\non GET(\"/docs\") () -> Effect[HttpResult[String]] by v: Visitor { … }",
2322    },
2323    Explain {
2324        code: "bynk.http.cache_bad_scope",
2325        blurb: "`scope` says who may store a cached response: `private` means the user's own browser only, and `public` also lets a shared cache, such as a CDN, keep it. Those are the only two values, written bare rather than as strings, so `shared` or `\"public\"` is refused. Choose one, or omit `scope` for `private`. Use `public` only for a response that is the same for everyone: `bynk.http.cache_public_reads_cookies`.",
2326        example: "@cache(maxAge: 5.minutes, scope: shared)   // ✗ `public` or `private`\non GET(\"/links\") () -> Effect[HttpResult[String]] by v: Visitor { … }\n\n@cache(maxAge: 5.minutes, scope: public)   // ✓",
2327    },
2328    Explain {
2329        code: "bynk.http.cache_duplicate",
2330        blurb: "A handler has one `@cache`, which says how long the response to that route may be reused. Two would give it two freshness windows, and neither could be said to win, so the second is refused. Delete the one you do not want. A handler may likewise carry only one `@limit` (`bynk.http.limit_duplicate`), `@raw` or `@json`.",
2331        example: "@cache(maxAge: 1.minute)\n@cache(maxAge: 5.minutes)   // ✗ already cached above\non GET(\"/links\") () -> Effect[HttpResult[String]] by v: Visitor { … }\n\n@cache(maxAge: 5.minutes)   // ✓ one window\non GET(\"/links\") () -> Effect[HttpResult[String]] by v: Visitor { … }",
2332    },
2333    Explain {
2334        code: "bynk.http.cache_max_age_fractional_seconds",
2335        blurb: "`Cache-Control: max-age` counts whole seconds. A `maxAge` such as `1500.milliseconds` has a remainder that would be dropped, and the header would say `1` for what you wrote as 1.5, so it is refused rather than quietly truncated. Write a whole number of seconds, rounding it yourself. A `maxAge` that is not a positive duration at all is `bynk.http.cache_bad_max_age`.",
2336        example: "@cache(maxAge: 1500.milliseconds)   // ✗ not a whole number of seconds\non GET(\"/links\") () -> Effect[HttpResult[String]] by v: Visitor { … }\n\n@cache(maxAge: 2.seconds)           // ✓",
2337    },
2338    Explain {
2339        code: "bynk.http.cache_on_non_get",
2340        blurb: "`@cache` declares how long the response to a read may be reused, so it is legal only on an `on GET` handler. Conditional caching applies to safe, idempotent reads, and a `POST`, `PUT`, `PATCH` or `DELETE` is neither. Remove the annotation, or, if the route only reads, make it a `GET`. A `GET` is revalidated by its `ETag` with no annotation at all.",
2341        example: "@cache(maxAge: 5.minutes)   // ✗ a `POST` changes something\non POST(\"/refresh\") () -> Effect[HttpResult[String]] by v: Visitor { … }\n\n@cache(maxAge: 5.minutes)   // ✓ a read\non GET(\"/links\") () -> Effect[HttpResult[String]] by v: Visitor { … }",
2342    },
2343    Explain {
2344        code: "bynk.http.cache_public_reads_cookies",
2345        blurb: "`scope: public` lets a shared cache, such as a CDN, store the response and serve it to anyone who asks for the URL. A handler that reads `cookies` answers for whoever is asking, so a shared cache could replay one user's response to another. Use `scope: private`, the default, which only the user's own browser may keep, or drop the `cookies` parameter. A response that sets a cookie is always sent as private.",
2346        example: "type Session = { sid: Option[String] }\n\n@cache(maxAge: 5.minutes, scope: public)    // ✗ the answer depends on who asks\non GET(\"/me\") (cookies: Session) -> Effect[HttpResult[String]] by v: Visitor { … }\n\n@cache(maxAge: 5.minutes, scope: private)   // ✓",
2347    },
2348    Explain {
2349        code: "bynk.http.cache_unknown_arg",
2350        blurb: "`@cache` takes three named arguments: `maxAge`, `scope` and `immutable`. The set is closed, so a misspelt or invented option is refused rather than ignored, which would leave the route with caching you did not ask for. A positional argument is refused too. Rename the argument or remove it. The values are checked by `bynk.http.cache_bad_max_age`, `bynk.http.cache_bad_scope` and `bynk.http.cache_bad_immutable`.",
2351        example: "@cache(maxAge: 5.minutes, stale: true)   // ✗ not an argument of `@cache`\non GET(\"/links\") () -> Effect[HttpResult[String]] by v: Visitor { … }\n\n@cache(maxAge: 5.minutes)                // ✓\non GET(\"/links\") () -> Effect[HttpResult[String]] by v: Visitor { … }",
2352    },
2353    Explain {
2354        code: "bynk.http.cf_wrong_type",
2355        blurb: "`cf` is the name the router reserves for what Cloudflare derived about the request's connection (its country, colo, ASN and the like), so a parameter called `cf` must be typed `RequestCf`, the record from `bynk.cloudflare` whose fields are all optional. Any other type has nothing to be filled from. Retype the parameter and import the type with `consumes bynk.cloudflare { RequestCf }`; that import is also what locks the deployment unit to Cloudflare. An input of your own needs another name, and a name that is neither a path parameter nor one of the reserved ones is `bynk.http.extra_param`. A `:cf` path segment stays a path parameter.",
2356        example: "on GET(\"/hello\") (cf: String) -> Effect[HttpResult[String]] by v: Visitor { … }      // ✗\n\non GET(\"/hello\") (cf: RequestCf) -> Effect[HttpResult[String]] by v: Visitor { … }   // ✓",
2357    },
2358    Explain {
2359        code: "bynk.http.cookie_cross_site_without_credentials",
2360        blurb: "A cookie with `SameSite=None` (`SameSite.Unrestricted`) exists to travel on cross-site requests, and a browser attaches cookies to a cross-origin `fetch` only when the request is credentialed and the response carries `Access-Control-Allow-Credentials: true`. A service with no `cors` policy, or one with `credentials: false`, never sends that header, so a cross-origin `fetch` can never send the cookie back. This is a warning, because a `SameSite=None` cookie is still sent on top-level cross-site navigations, cross-site form posts and in embeds (SSO and payment callbacks, widgets), none of which needs CORS. If a page on another origin must send it back with `fetch`, declare `cors { origins: [...], credentials: true }` (the origins must be exact, not `[\"*\"]`), or use `SameSite.Lax` if the cookie need not cross sites at all.",
2361        example: "service api from http {\n  on POST(\"/login\") () -> Effect[HttpResult[String]] by v: Visitor {\n    Created(\"ok\").withCookie(Cookie { name: \"sid\", value: \"a\", sameSite: SameSite.Unrestricted })   // ⚠ no `cors { credentials: true }`\n  }\n}\n\nservice api from http {\n  cors { origins: [\"https://app.example.com\"], credentials: true }   // ✓\n  …\n}",
2362    },
2363    Explain {
2364        code: "bynk.http.cookie_domain_widens",
2365        blurb: "A cookie with no `Domain` attribute belongs to exactly the host that set it. Setting `domain` makes it available to that domain and every subdomain, so a sibling service, or a subdomain an attacker can take over, receives it and can set a cookie of the same name. That is rarely wanted, so it is a warning. Drop `domain`; or, if the cookie is a session cookie, name it `__Host-…`, which makes the compiler refuse a `domain` altogether (`bynk.http.cookie_host_prefix`). Keep `domain` only when subdomains genuinely share the login.",
2366        example: "Created(\"ok\").withCookie(Cookie { name: \"sid\", value: \"a\", domain: Some(\"example.com\") })   // ⚠ every subdomain receives it\n\nCreated(\"ok\").withCookie(Cookie { name: \"__Host-sid\", value: \"a\" })                           // ✓ this host only",
2367    },
2368    Explain {
2369        code: "bynk.http.cookie_field_arity",
2370        blurb: "`Record.field.cookie(value)` writes a typed cookie from a record's field, so it takes exactly the value to write, and `Record.field.expire()` takes nothing: the field is named by the path, not by an argument. Write `Prefs.theme.cookie(Dark)` to set it and `Prefs.theme.expire()` to remove it.",
2371        example: "Ok(\"x\").withCookie(Prefs.theme.cookie())       // ✗ the value to write is missing\n\nOk(\"x\").withCookie(Prefs.theme.cookie(Dark))   // ✓",
2372    },
2373    Explain {
2374        code: "bynk.http.cookie_field_list",
2375        blurb: "A `List` field of a `cookies` record is a cookie name sent several times, so writing one would be several `Set-Cookie` lines, which one `Cookie` cannot be. The typed write is refused for it. Write each cookie with an untyped `Cookie { name, value }` and `withCookie`.",
2376        example: "Ok(\"x\").withCookie(Prefs.tags.cookie(\"a\"))   // ✗ `tags` is a `List` field\n\nOk(\"x\").withCookie(Prefs.theme.cookie(Dark))   // ✓ a scalar field",
2377    },
2378    Explain {
2379        code: "bynk.http.cookie_field_not_cookie_record",
2380        blurb: "A typed cookie write is named and encoded as its record's decoder reads it, so the record must be the `cookies` parameter of an `on http` handler in this unit: that decoder is what the write agrees with. For a cookie in no record, write an untyped `Cookie { name, value }`.",
2381        example: "type Other = { theme: Theme = Light }\nOk(\"x\").withCookie(Other.theme.cookie(Dark))   // ✗ no handler decodes `Other` as `cookies`\n\nOk(\"x\").withCookie(Prefs.theme.cookie(Dark))    // ✓ `Prefs` is a handler's `cookies` record",
2382    },
2383    Explain {
2384        code: "bynk.http.cookie_field_unknown",
2385        blurb: "`Record.field.cookie(value)` and `Record.field.expire()` name a field of the cookie record, and the field is the one the cookie is named and encoded by. The name given is not a field of the record; the note lists its fields.",
2386        example: "Ok(\"x\").withCookie(Prefs.mode.cookie(Dark))    // ✗ `Prefs` has no field `mode`\n\nOk(\"x\").withCookie(Prefs.theme.cookie(Dark))   // ✓",
2387    },
2388    Explain {
2389        code: "bynk.http.cookie_host_prefix",
2390        blurb: "A cookie named `__Host-…` asks the browser to keep it only if it is `Secure`, has no `Domain` and has `Path=/`. That ties it to this exact host, so a sibling subdomain or an insecure page cannot set or overwrite it. A browser drops one that breaks any of the three, so a literal that does is refused. Remove `secure: false`, the `domain` and any `path` other than `\"/\"`, or rename the cookie.",
2391        example: "Created(\"ok\").withCookie(Cookie { name: \"__Host-sid\", value: \"a\", path: \"/app\" })   // ✗ must be `/`\n\nCreated(\"ok\").withCookie(Cookie { name: \"__Host-sid\", value: \"a\" })                 // ✓",
2392    },
2393    Explain {
2394        code: "bynk.http.cookie_partitioned_insecure",
2395        blurb: "A `partitioned` cookie is stored separately for each top-level site that embeds your service, and browsers accept the `Partitioned` attribute only with `Secure`. A literal that sets `partitioned: true` with `secure: false` would be dropped, so it is refused. Remove `secure: false` (the default is `secure: true`), or drop `partitioned`. See also `bynk.http.cookie_samesite_none_insecure`.",
2396        example: "Created(\"ok\").withCookie(Cookie { name: \"sid\", value: \"a\", partitioned: true, secure: false })   // ✗\n\nCreated(\"ok\").withCookie(Cookie { name: \"sid\", value: \"a\", partitioned: true })                  // ✓",
2397    },
2398    Explain {
2399        code: "bynk.http.cookie_samesite_none_insecure",
2400        blurb: "`SameSite=None` lets a cookie travel on cross-site requests, and browsers accept it only with `Secure`, so it is sent over HTTPS alone. Without it the browser drops the cookie and the login or session quietly fails, so Bynk refuses the literal. Remove `secure: false`, since the default is `secure: true`, or choose `Lax` or `Strict` if the cookie need not cross sites.",
2401        example: "Created(\"ok\").withCookie(Cookie { name: \"sid\", value: \"a\", sameSite: SameSite.Unrestricted, secure: false })   // ✗\n\nCreated(\"ok\").withCookie(Cookie { name: \"sid\", value: \"a\", sameSite: SameSite.Unrestricted })                  // ✓",
2402    },
2403    Explain {
2404        code: "bynk.http.cookie_secure_prefix",
2405        blurb: "A cookie named `__Secure-…` asks the browser to accept it only over HTTPS, and a browser drops one that is not `Secure`, so a literal with `secure: false` would never arrive. It is refused instead. Remove `secure: false`; the default is `secure: true`. A `__Host-` name is stricter: `bynk.http.cookie_host_prefix`.",
2406        example: "Created(\"ok\").withCookie(Cookie { name: \"__Secure-sid\", value: \"a\", secure: false })   // ✗\n\nCreated(\"ok\").withCookie(Cookie { name: \"__Secure-sid\", value: \"a\" })                  // ✓",
2407    },
2408    Explain {
2409        code: "bynk.http.cookie_untyped_has_field",
2410        blurb: "`Cookie { name: \"theme\", value: \"Dark\" }` is a cookie in no record, but here the record `Prefs` reads that cookie by that name, so the name and the value are written twice with nothing relating them: a renamed field or a changed type leaves the write valid and wrong. It is a warning. Write it from the record, `Prefs.theme.cookie(Dark)`, which is named by the field's wire name and valued as its decoder reads it; keep the attributes by spreading it into a `Cookie` literal. Where the literal is only a name and a value that provably decodes, the quick-fix does the rewrite.",
2411        example: "Ok(\"x\").withCookie(Cookie { name: \"theme\", value: \"Dark\" })   // ⚠ `Prefs` reads this cookie\n\nOk(\"x\").withCookie(Prefs.theme.cookie(Dark))                       // ✓",
2412    },
2413    Explain {
2414        code: "bynk.http.cookie_value_undecodable",
2415        blurb: "An untyped `Cookie` literal is named for a field of a `cookies` record, so the next request is read by that field's decoder, and its literal value is one the decoder rejects (an enum is read by its exact, case-sensitive variant name, an `Int` by its digits, a `Bool` by `true` or `false`). The write compiles and is sent, and then every later request is answered `400`. It is an error. Write the cookie from the record, `Prefs.theme.cookie(Dark)`, which checks the value against the field.",
2416        example: "Ok(\"x\").withCookie(Cookie { name: \"mode\", value: \"dark\" })   // ✗ `Mode` is read as `Light` or `Dark`\n\nOk(\"x\").withCookie(Cookie { name: \"mode\", value: \"Dark\" })   // ✓",
2417    },
2418    Explain {
2419        code: "bynk.http.cookies_field_not_stringy",
2420        blurb: "A cookie is a single text value, so each field of the `cookies` record must be one a single value can fill: a `String`, `Int`, `Bool` or `Decimal`, an enum, or a refined or opaque type over one, optionally in an `Option` (a cookie that may be absent) or a `List` (a name sent twice). A nested record or any other type is refused. Flatten the record, or keep structured data in a `String` and decode it yourself. `query` and `@form` records follow the same rule: `bynk.http.query_field_not_stringy`, `bynk.http.form_field_not_stringy`.",
2421        example: "type Prefs = { dark: Bool }\n\ntype Session = { prefs: Prefs }   // ✗ a cookie is one value, not a record\n\ntype Session = { dark: Bool }     // ✓\n\non GET(\"/me\") (cookies: Session) -> Effect[HttpResult[String]] by v: Visitor { … }",
2422    },
2423    Explain {
2424        code: "bynk.http.cookies_not_http",
2425        blurb: "`RequestCookies` is the cookies of an HTTP request, read from its `Cookie` header. A `cron` or other handler that is not an `on http` route answers no request, so there are no cookies for it to take, and the parameter is refused. Remove it, or move the work into an HTTP handler. On an HTTP route, `cookies` is a record or `RequestCookies` and nothing else: `bynk.http.cookies_wrong_type`. `RequestQuery` has the same rule: `bynk.http.query_not_http`.",
2426        example: "service ticker from cron {\n    on schedule(\"*/5 * * * *\") (cookies: RequestCookies) -> Effect[Result[(), String]] { … }   // ✗ no request\n}\n\ntype Session = { sid: Option[String] }\n\nservice ticker from http {\n    on GET(\"/me\") (cookies: Session) -> Effect[HttpResult[String]] by v: Visitor { … }   // ✓\n}",
2427    },
2428    Explain {
2429        code: "bynk.http.cookies_wrong_type",
2430        blurb: "`cookies` is the name the router reserves for the request's cookies. It decodes the `Cookie` header into the record you name, one field per cookie, and answers `400` when they do not fit, so the parameter must be a record type. Declare the cookies you read as a record, with an `Option` for each that may be absent. A field a cookie cannot carry is `bynk.http.cookies_field_not_stringy`.",
2431        example: "type Session = { sid: Option[String] }\n\non GET(\"/me\") (cookies: String) -> Effect[HttpResult[String]] by v: Visitor { … }    // ✗ not a record\n\non GET(\"/me\") (cookies: Session) -> Effect[HttpResult[String]] by v: Visitor { … }   // ✓",
2432    },
2433    Explain {
2434        code: "bynk.http.cors_invalid_field",
2435        blurb: "Each optional `cors` field takes one kind of value: `headers` a list of string literals, `credentials` the literal `true` or `false`, and `maxAge` a `Duration` literal such as `1.hour`. They are written straight into the `Access-Control-*` headers the router sends, so they are fixed at compile time: a string, a number or a computed value is refused. `origins`, the required field, is checked by `bynk.http.cors_invalid_origins`.",
2436        example: "cors { origins: [\"https://app.example.com\"], credentials: \"yes\" }   // ✗ `true` or `false`\n\ncors { origins: [\"https://app.example.com\"], credentials: true }    // ✓",
2437    },
2438    Explain {
2439        code: "bynk.http.cors_invalid_origins",
2440        blurb: "`origins` is the allowlist the router checks each request's `Origin` against, so it is required and must be a non-empty list of string literals: exact origins such as `\"https://app.example.com\"`, or `[\"*\"]` for any site. A single string, an empty list, a computed entry or no `origins` at all leaves nothing to compare, and is refused. The wildcard cannot be combined with `credentials: true`: `bynk.http.cors_wildcard_credentials`.",
2441        example: "cors { origins: \"https://app.example.com\" }     // ✗ a list of strings\n\ncors { origins: [\"https://app.example.com\"] }   // ✓",
2442    },
2443    Explain {
2444        code: "bynk.http.cors_not_http",
2445        blurb: "A `cors { }` block says which other sites a browser may let call the service, and only the HTTP surface has cross-origin browser callers, so it is valid only on a `from http` service. On a `cron` or other service it has no request to apply to. Move it to the `from http` service it was meant for, or delete it. The `security`, `limits` and `json` blocks follow the same rule: `bynk.http.security_not_http`, `bynk.http.limits_not_http`, `bynk.http.json_not_http`.",
2446        example: "service jobs from cron {\n    cors { origins: [\"https://app.example.com\"] }   // ✗ a schedule has no browser callers\n    on schedule(\"0 0 * * *\") () -> Effect[Result[(), String]] { … }\n}\n\nservice api from http {\n    cors { origins: [\"https://app.example.com\"] }   // ✓\n    on GET(\"/items\") () -> Effect[HttpResult[String]] by v: Visitor { … }\n}",
2447    },
2448    Explain {
2449        code: "bynk.http.cors_unknown_field",
2450        blurb: "A `cors { }` policy has four fields: `origins`, `headers`, `credentials` and `maxAge`. The set is closed, so a misspelt or invented field is refused rather than ignored, which would leave the policy different from the one you wrote. `Access-Control-Allow-Methods` is not a field: the compiler derives it from the service's routes. Rename the field or delete it. A field with the wrong kind of value is `bynk.http.cors_invalid_field`.",
2451        example: "cors { origins: [\"https://app.example.com\"], methods: [\"GET\"] }   // ✗ not a field, methods come from the routes\n\ncors { origins: [\"https://app.example.com\"], maxAge: 1.hour }    // ✓",
2452    },
2453    Explain {
2454        code: "bynk.http.cors_wildcard_credentials",
2455        blurb: "`credentials: true` lets a browser send cookies and `Authorization` to the service, and the Fetch standard forbids answering such a request with the wildcard origin `*`: the browser rejects the response at runtime. Bynk refuses the pair at compile time instead. List the origins that may send credentials, or set `credentials: false` if any site may call the service.",
2456        example: "cors { origins: [\"*\"], credentials: true }                        // ✗ credentials need named origins\n\ncors { origins: [\"https://app.example.com\"], credentials: true }   // ✓",
2457    },
2458    Explain {
2459        code: "bynk.http.duplicate_rejected",
2460        blurb: "`on rejected` renders every refusal the router makes for a service's routes, so a service has one and it must handle every case: a second would leave the router choosing between them. Merge the two into one that matches on `why`. Its required shape is `bynk.http.rejected_signature`.",
2461        example: "on rejected(why: BoundaryRejection) -> Effect[HttpResult[()]] { … }\non rejected(why: BoundaryRejection) -> Effect[HttpResult[()]] { … }   // ✗ already declared above\n\non rejected(why: BoundaryRejection) -> Effect[HttpResult[()]] {\n    match why {\n        MethodNotAllowed => RawError(MethodNotAllowed, Bytes.empty(), \"text/plain\")   // ✓ one hook, all cases\n        _ => RawError(BadRequest, Bytes.empty(), \"text/plain\")\n    }\n}",
2462    },
2463    Explain {
2464        code: "bynk.http.duplicate_route",
2465        blurb: "A route is a method and a path, and the router needs exactly one handler to answer it. Two handlers that declare the same pair, in one service or in two services of a context, leave it nothing to choose between, so the later one is refused. Merge them, or give one a different path or method.",
2466        example: "on GET(\"/items\") () -> Effect[HttpResult[String]] by v: Visitor { … }\non GET(\"/items\") () -> Effect[HttpResult[String]] by v: Visitor { … }        // ✗ already declared above\n\non GET(\"/items/:id\") (id: String) -> Effect[HttpResult[String]] by v: Visitor { … }   // ✓ a different path",
2467    },
2468    Explain {
2469        code: "bynk.http.error_status_position",
2470        blurb: "An `ErrorStatus` name such as `Forbidden` stands for a status only as \
2471                `RawError`'s first argument, where the compiler turns it into the \
2472                number it answers. It is not a type, so a status can't be stored or \
2473                passed to a helper. Name the status where the response is built, and \
2474                let a helper build the body.",
2475        example: "let status = ErrorStatus.Forbidden                          // ✗ a status has no value here\n\n\
2476                  fn problem(msg: String) -> Bytes { Bytes.fromUtf8(msg) }\n\
2477                  RawError(Forbidden, problem(\"no access\"), \"text/plain\")     // ✓",
2478    },
2479    Explain {
2480        code: "bynk.http.extra_param",
2481        blurb: "A handler's parameters are not free-form. Each is a path parameter, matching a `:name` in the route, or one of the three the router fills itself: `body`, `headers` and `query`. Any other name has nowhere to come from. Read a value from the query string with `query: RequestQuery` or a record, move it into the path, or drop it. A `:name` with no parameter is `bynk.http.unbound_path_param`.",
2482        example: "on GET(\"/items\") (page: String) -> Effect[HttpResult[String]] by v: Visitor { … }   // ✗ not in the path, and not `body`, `headers` or `query`\n\non GET(\"/items\") (query: RequestQuery) -> Effect[HttpResult[String]] by v: Visitor { … }   // ✓",
2483    },
2484    Explain {
2485        code: "bynk.http.form_body_not_record",
2486        blurb: "`@form` and `@multipart` decode a form body one key at a time, into the fields of a record, so the `body` must be a record type. A `String`, a list or any other type has no fields for the keys to fill. Declare a record with one field per form key and take it as `body`; each field is then held to `bynk.http.form_field_not_stringy`. A JSON body of another shape needs no annotation.",
2487        example: "type Signup = { email: String }\n\n@form\non POST(\"/signup\") (body: String) -> Effect[HttpResult[String]] by v: Visitor { … }   // ✗ a form decodes into a record\n\n@form\non POST(\"/signup\") (body: Signup) -> Effect[HttpResult[String]] by v: Visitor { … }   // ✓",
2488    },
2489    Explain {
2490        code: "bynk.http.form_duplicate",
2491        blurb: "`@form` says the route's one `body` is an HTML form post, and `@multipart` says it is a browser upload. A handler has a single body, so it carries one of the two, once: a second would restate the encoding or contradict it, and the second is refused. Delete the repeat. Pairing `@form` with `@raw` is `bynk.http.body_kind_conflict`, and a repeated `@raw` is `bynk.http.raw_duplicate`.",
2492        example: "type Signup = { email: String }\n\n@form\n@form    // ✗ a second `@form`\non POST(\"/signup\") (body: Signup) -> Effect[HttpResult[()]] by v: Visitor { … }\n\n@form    // ✓\non POST(\"/signup\") (body: Signup) -> Effect[HttpResult[()]] by v: Visitor { … }",
2493    },
2494    Explain {
2495        code: "bynk.http.form_field_not_stringy",
2496        blurb: "A form body is a flat set of keys with text values, so each field of a `@form` or `@multipart` body record must be one a single value can fill: a `String`, `Int`, `Bool` or `Decimal`, an enum, or a refined or opaque type over one, optionally in an `Option` or a `List` (a repeated key). A multipart body may also have `File` fields. A nested record, or any other type, is refused; flatten it. A `query` record follows the same rule: `bynk.http.query_field_not_stringy`.",
2497        example: "type Address = { city: String }\ntype SignupForm = { email: String, address: Address }   // ✗ a form has no nesting\n\ntype SignupForm = { email: String, city: String }       // ✓ flat keys",
2498    },
2499    Explain {
2500        code: "bynk.http.form_on_bodyless",
2501        blurb: "`@form` and `@multipart` read a form post from the request's `body`, so they belong on a `POST`, `PUT` or `PATCH` route with a `body` parameter. On a `GET`, a `DELETE` or a route with no `body` there is nothing to decode. Add a `body` record, or drop the annotation. `@raw` has the same rule: `bynk.http.raw_on_bodyless`.",
2502        example: "type Signup = { email: String }\n\n@form   // ✗ the route takes no body\non POST(\"/signup\") () -> Effect[HttpResult[String]] by v: Visitor { … }\n\n@form\non POST(\"/signup\") (body: Signup) -> Effect[HttpResult[String]] by v: Visitor { … }   // ✓",
2503    },
2504    Explain {
2505        code: "bynk.http.form_on_sum_route",
2506        blurb: "A route `by` a sum of actors, such as `User | Visitor`, reads and verifies the request body as JSON itself. `@form` and `@multipart` have the router decode the body in another format, so the two cannot both own it and the pair is refused. Name one actor on the route, or split it into one route per actor. A route with `@form` and a second wire format is `bynk.http.body_kind_conflict`.",
2507        example: "type UserId = opaque String\ntype Search = { q: String }\n\nactor User { auth = Bearer(secret = \"AUTH_JWT_SECRET\"), identity = UserId }\n\n@form\non POST(\"/search\") (body: Search) -> Effect[HttpResult[String]] by who: User | Visitor { … }   // ✗ a sum of actors\n\n@form\non POST(\"/search\") (body: Search) -> Effect[HttpResult[String]] by who: User { … }             // ✓ one actor",
2508    },
2509    Explain {
2510        code: "bynk.http.form_unknown_arg",
2511        blurb: "`@form` takes no arguments. A form body is always `application/x-www-form-urlencoded`, so there is no media type to name, and a size ceiling belongs to `@limit` or a `limits { }` section, not to the annotation. An argument is refused rather than ignored, which would leave the route behaving otherwise than you wrote. Write `@form` bare. `@multipart` takes none either. `@raw` takes `contentType:`: `bynk.http.raw_unknown_arg`.",
2512        example: "type Signup = { email: String }\n\n@form(contentType: \"application/x-www-form-urlencoded\")    // ✗ `@form` takes no argument\non POST(\"/signup\") (body: Signup) -> Effect[HttpResult[()]] by v: Visitor { … }\n\n@form    // ✓\non POST(\"/signup\") (body: Signup) -> Effect[HttpResult[()]] by v: Visitor { … }",
2513    },
2514    Explain {
2515        code: "bynk.http.headers_wrong_type",
2516        blurb: "`headers` is the name the router reserves for the request's headers, so a parameter called `headers` must be typed `RequestHeaders`, the read-only view with `get(name)`, `bearer()` and `clientIp()`. Any other type has nothing to be filled from. Retype the parameter. An input of your own needs another name, and a name that is neither a path parameter nor one of the reserved ones is `bynk.http.extra_param`.",
2517        example: "on GET(\"/whoami\") (headers: String) -> Effect[HttpResult[String]] by v: Visitor { … }           // ✗\n\non GET(\"/whoami\") (headers: RequestHeaders) -> Effect[HttpResult[String]] by v: Visitor { … }   // ✓",
2518    },
2519    Explain {
2520        code: "bynk.http.invalid_path",
2521        blurb: "The router matches a route against the request's path, which always begins with `/`, so a route that does not is refused rather than guessed at. A `:` segment must also carry a name, since the name is what binds the value to a handler parameter. Start the route with `/` and name each parameter, as in `\"/items/:id\"`. A route under a reserved prefix is `bynk.http.reserved_prefix`.",
2522        example: "on GET(\"items\") () -> Effect[HttpResult[String]] by v: Visitor { … }    // ✗ no leading `/`\n\non GET(\"/items\") () -> Effect[HttpResult[String]] by v: Visitor { … }   // ✓",
2523    },
2524    Explain {
2525        code: "bynk.http.json_duplicate",
2526        blurb: "`@json(options: …)` chooses how one route's response bodies write an `Option`. A handler has one, because two would give the same body two encodings with nothing to say which wins, so the second is refused. Keep the one you mean. To set the encoding for every route of a service, use a `json { }` section instead. A handler may likewise carry only one `@cache` (`bynk.http.cache_duplicate`), `@limit` or `@raw`.",
2527        example: "@json(options: plain)\n@json(options: tagged)    // ✗ a second `@json`\non GET(\"/activity\") () -> Effect[HttpResult[String]] by v: Visitor { … }\n\n@json(options: plain)     // ✓\non GET(\"/activity\") () -> Effect[HttpResult[String]] by v: Visitor { … }",
2528    },
2529    Explain {
2530        code: "bynk.http.json_invalid_arg",
2531        blurb: "`@json` has one argument, `options:`, whose value is the bare word `tagged` or `plain`: tagged writes `Option` as `{\"kind\": \"Some\", …}` (the default), and plain writes `Some(v)` as `v` and `None` as `null`. The annotation is refused with no `options`, or with any other value. Write `@json(options: plain)` or `@json(options: tagged)`. Another argument name is `bynk.http.json_unknown_arg`.",
2532        example: "@json(options: compact)   // ✗ `tagged` or `plain`\non GET(\"/activity\") () -> Effect[HttpResult[String]] by v: Visitor { … }\n\n@json(options: plain)     // ✓\non GET(\"/activity\") () -> Effect[HttpResult[String]] by v: Visitor { … }",
2533    },
2534    Explain {
2535        code: "bynk.http.json_invalid_field",
2536        blurb: "The `options` field of a `json { }` section says how response bodies write an `Option`, and it is read at compile time, so its value is the bare word `tagged` (the default, `{\"kind\": \"Some\", …}`) or `plain` (`Some(v)` as `v`, `None` as `null`). Any other word, a string or a computed value is refused. Write one of the two. The route-level form is `@json(options: …)`, checked by `bynk.http.json_invalid_arg`.",
2537        example: "service api from http {\n    json { options: compact }   // ✗ `tagged` or `plain`\n    on GET(\"/items\") () -> Effect[HttpResult[String]] by v: Visitor { … }\n}\n\nservice api from http {\n    json { options: plain }     // ✓\n    on GET(\"/items\") () -> Effect[HttpResult[String]] by v: Visitor { … }\n}",
2538    },
2539    Explain {
2540        code: "bynk.http.json_not_http",
2541        blurb: "A `json { }` section chooses how a service's HTTP response bodies write `Option`, tagged or plain. Only a `from http` service has response bodies, so on a `cron` or other service the section is refused. Move it to the HTTP service it was meant for, or delete it. The `cors`, `security` and `limits` sections have the same rule: `bynk.http.cors_not_http`, `bynk.http.security_not_http`, `bynk.http.limits_not_http`. For the per-route form, see `bynk.http.json_on_non_http`.",
2542        example: "service jobs from cron {\n    json { options: plain }   // ✗ a schedule has no response body\n    on schedule(\"0 0 * * *\") () -> Effect[Result[(), String]] { … }\n}\n\nservice api from http {\n    json { options: plain }   // ✓\n    on GET(\"/items\") () -> Effect[HttpResult[String]] by v: Visitor { … }\n}",
2543    },
2544    Explain {
2545        code: "bynk.http.json_on_non_http",
2546        blurb: "`@json(options: …)` picks how one HTTP response body writes `Option`, tagged or plain. Only an `on http` handler answers with a response body, so the annotation is refused on a `schedule`, queue or other handler. Move it to an HTTP route, or remove it. The service-wide section, `json { }`, is limited to `from http` services too: `bynk.http.json_not_http`.",
2547        example: "service jobs from cron {\n    @json(options: plain)   // ✗ a schedule has no response body\n    on schedule(\"0 0 * * *\") () -> Effect[Result[(), String]] { … }\n}\n\nservice api from http {\n    @json(options: plain)   // ✓\n    on GET(\"/activity\") () -> Effect[HttpResult[String]] by v: Visitor { … }\n}",
2548    },
2549    Explain {
2550        code: "bynk.http.json_unknown_arg",
2551        blurb: "`@json` has one argument, `options:`. The set is closed, so a misspelt or invented argument is refused rather than ignored, which would leave the route writing `Option` otherwise than you asked. Rename it to `options` or remove it. The value is checked separately: `bynk.http.json_invalid_arg`. The same name in a service's `json { }` section is `bynk.http.json_unknown_field`.",
2552        example: "@json(options: plain, nulls: keep)    // ✗ not an argument of `@json`\non GET(\"/activity\") () -> Effect[HttpResult[String]] by v: Visitor { … }\n\n@json(options: plain)                 // ✓\non GET(\"/activity\") () -> Effect[HttpResult[String]] by v: Visitor { … }",
2553    },
2554    Explain {
2555        code: "bynk.http.json_unknown_field",
2556        blurb: "A `json { }` section sets how every route of a service writes an `Option` in a response body, and `options` is its only field. The set is closed, so a misspelt or invented field is refused rather than ignored, which would leave the service writing bodies otherwise than you wrote. Rename it to `options` or remove it. A bad value is `bynk.http.json_invalid_field`; the route-level `@json` form is `bynk.http.json_unknown_arg`.",
2557        example: "service api from http {\n    json { options: plain, nulls: keep }    // ✗ `options` is the only field\n    on GET(\"/items\") () -> Effect[HttpResult[String]] by v: Visitor { … }\n}\n\nservice api from http {\n    json { options: plain }                 // ✓\n    on GET(\"/items\") () -> Effect[HttpResult[String]] by v: Visitor { … }\n}",
2558    },
2559    Explain {
2560        code: "bynk.http.limit_bad_max_body",
2561        blurb: "`@limit` sets the byte ceiling above which the router answers `413`, so it must give a `maxBody`, and only the author can know the right one: it is a positive `Int` literal counting bytes. There is no size literal yet, so `\"1MB\"` or `1.mb` is refused; write the count, `1_048_576` for 1 MiB. The service-wide default is `limits { maxBody: … }`.",
2562        example: "@limit(maxBody: \"1MB\")    // ✗ a byte count, not a string\non POST(\"/notes\") (body: Note) -> Effect[HttpResult[String]] by v: Visitor { … }\n\n@limit(maxBody: 1_048_576)   // ✓ 1 MiB\non POST(\"/notes\") (body: Note) -> Effect[HttpResult[String]] by v: Visitor { … }\n\nconst NoteCap: Int = 1_048_576\n@limit(maxBody: NoteCap)   // ✓ an `Int` constant bound to a literal\non POST(\"/drafts\") (body: Note) -> Effect[HttpResult[String]] by v: Visitor { … }",
2563    },
2564    Explain {
2565        code: "bynk.http.limit_bad_max_file",
2566        blurb: "On a `@multipart` route, `@limit`'s `maxFile` caps the bytes of one file part and `maxParts` the number of parts. Each must be a positive `Int` literal: zero or a negative number would refuse every upload, and there is no size literal, so `\"5MB\"` is refused too. Write the count, as `5_000_000`. `limits { }` has the same rule (`bynk.http.limits_invalid_field`), and so does `maxBody` (`bynk.http.limit_bad_max_body`).",
2567        example: "consumes bynk { File }\n\ntype Upload = { photo: File }\n\n@multipart\n@limit(maxBody: 5_000_000, maxFile: 0)           // ✗ a positive byte count\non POST(\"/upload\") (body: Upload) -> Effect[HttpResult[String]] by v: Visitor { … }\n\n@multipart\n@limit(maxBody: 5_000_000, maxFile: 1_000_000)   // ✓\non POST(\"/upload\") (body: Upload) -> Effect[HttpResult[String]] by v: Visitor { … }",
2568    },
2569    Explain {
2570        code: "bynk.http.limit_duplicate",
2571        blurb: "A route has one request-body ceiling, so a handler carries one `@limit`. Two would set two ceilings for the same body with nothing to say which applies, and the second is refused. Keep the one you want. To set a default for every body-taking route of a service, write a `limits { }` section: a route's `@limit` overrides it. A handler may likewise carry only one `@cache` (`bynk.http.cache_duplicate`), `@raw` or `@json`.",
2572        example: "type Note = { text: String }\n\n@limit(maxBody: 1_000_000)\n@limit(maxBody: 5_000_000)    // ✗ a second `@limit`\non POST(\"/notes\") (body: Note) -> Effect[HttpResult[String]] by v: Visitor { … }\n\n@limit(maxBody: 5_000_000)    // ✓ one ceiling\non POST(\"/notes\") (body: Note) -> Effect[HttpResult[String]] by v: Visitor { … }",
2573    },
2574    Explain {
2575        code: "bynk.http.limit_on_bodyless",
2576        blurb: "`@limit` caps the size of a request body, so it means something only on a route that reads one: `POST`, `PUT` or `PATCH`. A `GET` or `DELETE` takes no body in Bynk, so there is nothing to cap. Move the annotation to the body-taking route, or remove it. A default for every body-taking route in a service goes in `limits { maxBody: … }`.",
2577        example: "@limit(maxBody: 1_000_000)   // ✗ a `GET` has no body\non GET(\"/notes\") () -> Effect[HttpResult[String]] by v: Visitor { … }\n\ntype Note = { text: String }\n\n@limit(maxBody: 1_000_000)   // ✓ a route that reads a body\non POST(\"/notes\") (body: Note) -> Effect[HttpResult[String]] by v: Visitor { … }",
2578    },
2579    Explain {
2580        code: "bynk.http.limit_on_non_multipart",
2581        blurb: "`maxFile` and `maxParts` cap the parts of a multipart body: the size of one file and the number of parts. A route that is not `@multipart` has no parts, so naming either in `@limit` is refused. Remove the argument and keep `maxBody`, which caps any body, or mark the route `@multipart` if it takes an upload. A `@limit` on a route with no body at all is `bynk.http.limit_on_bodyless`.",
2582        example: "type Signup = { email: String }\n\n@form\n@limit(maxBody: 100_000, maxFile: 10_000)   // ✗ a form has no file parts\non POST(\"/signup\") (body: Signup) -> Effect[HttpResult[String]] by v: Visitor { … }\n\n@form\n@limit(maxBody: 100_000)                    // ✓\non POST(\"/signup\") (body: Signup) -> Effect[HttpResult[String]] by v: Visitor { … }",
2583    },
2584    Explain {
2585        code: "bynk.http.limit_unknown_arg",
2586        blurb: "`@limit` accepts `maxBody` and, on a `@multipart` route, `maxFile` and `maxParts`. The set is closed, so a misspelt or invented cap is refused rather than ignored, which would leave the route with a ceiling you did not set. Rename the argument or remove it. The ceilings are checked by `bynk.http.limit_bad_max_body` and `bynk.http.limit_bad_max_file`.",
2587        example: "type Note = { text: String }\n\n@limit(maxBody: 1_000_000, maxSize: 10)   // ✗ not an argument of `@limit`\non POST(\"/notes\") (body: Note) -> Effect[HttpResult[String]] by v: Visitor { … }\n\n@limit(maxBody: 1_000_000)                // ✓\non POST(\"/notes\") (body: Note) -> Effect[HttpResult[String]] by v: Visitor { … }",
2588    },
2589    Explain {
2590        code: "bynk.http.limits_invalid_field",
2591        blurb: "Every `limits { }` field is a positive `Int` literal: `maxBody` and `maxFile` are byte counts, and `maxParts` counts parts. A string such as `\"1MB\"`, zero or a negative number is refused: there is no size literal yet, and a ceiling of zero would reject every request. Write the count, as `1_048_576` for 1 MiB. A field outside the three is `bynk.http.limits_unknown_field`. The per-route form of the rule is `bynk.http.limit_bad_max_body`.",
2592        example: "type Note = { text: String }\n\nservice api from http {\n    limits { maxBody: \"1MB\" }       // ✗ a byte count, not a string\n    on POST(\"/notes\") (body: Note) -> Effect[HttpResult[String]] by v: Visitor { … }\n}\n\nservice api from http {\n    limits { maxBody: 1_048_576 }   // ✓ 1 MiB\n    on POST(\"/notes\") (body: Note) -> Effect[HttpResult[String]] by v: Visitor { … }\n}",
2593    },
2594    Explain {
2595        code: "bynk.http.limits_not_http",
2596        blurb: "A `limits { }` section sets the request-body ceilings of a service's routes, and only a `from http` service has routes that take requests, so on a `cron` or other service it is refused. Move it to the HTTP service it was meant for, or delete it. The `cors`, `security` and `json` sections have the same rule: `bynk.http.cors_not_http`, `bynk.http.security_not_http`, `bynk.http.json_not_http`.",
2597        example: "type Note = { text: String }\n\nservice jobs from cron {\n    limits { maxBody: 1_000_000 }   // ✗ a schedule takes no request body\n    on schedule(\"0 0 * * *\") () -> Effect[Result[(), String]] { … }\n}\n\nservice api from http {\n    limits { maxBody: 1_000_000 }   // ✓\n    on POST(\"/notes\") (body: Note) -> Effect[HttpResult[String]] by v: Visitor { … }\n}",
2598    },
2599    Explain {
2600        code: "bynk.http.limits_unknown_field",
2601        blurb: "A `limits { }` section sets the request-body ceilings of a service. Its fields are `maxBody` and, for `@multipart` routes, `maxFile` and `maxParts`. The set is closed, so a misspelt or invented field is refused rather than ignored, which would leave the routes with a ceiling you did not set. Rename it or remove it. A field with a bad value is `bynk.http.limits_invalid_field`; the per-route form is `bynk.http.limit_unknown_arg`.",
2602        example: "type Note = { text: String }\n\nservice api from http {\n    limits { maxBody: 1_000_000, maxSize: 10 }    // ✗ not a field of `limits`\n    on POST(\"/notes\") (body: Note) -> Effect[HttpResult[String]] by v: Visitor { … }\n}\n\nservice api from http {\n    limits { maxBody: 1_000_000 }                 // ✓\n    on POST(\"/notes\") (body: Note) -> Effect[HttpResult[String]] by v: Visitor { … }\n}",
2603    },
2604    Explain {
2605        code: "bynk.http.multipart_body_unbounded",
2606        blurb: "A `@multipart` body is buffered whole, with its parsed parts held beside it, so an upload with no ceiling lets one client use up the Worker's memory. A `@multipart` route therefore needs a cap, as a `@raw` one does (`bynk.http.raw_body_unbounded`): `@limit(maxBody: …)` on the handler, or `limits { maxBody: … }` on the service. Choose the largest upload you mean to accept.",
2607        example: "type Upload = { title: String }\n\n@multipart   // ✗ no cap on the handler or the service\non POST(\"/upload\") (body: Upload) -> Effect[HttpResult[String]] by v: Visitor { … }\n\n@multipart\n@limit(maxBody: 1_000_000)   // ✓ capped\non POST(\"/upload\") (body: Upload) -> Effect[HttpResult[String]] by v: Visitor { … }",
2608    },
2609    Explain {
2610        code: "bynk.http.path_param_not_stringy",
2611        blurb: "A path parameter is read from a segment of the URL, which is text, so its type must be one the router can build from a string: `String`, a refined `String`, or an opaque type over `String`. An `Int`, an enum or a record is refused here, though a `query` field may be one. Take the segment as a refined `String` that states its shape.",
2612        example: "on GET(\"/items/:id\") (id: Int) -> Effect[HttpResult[String]] by v: Visitor { … }   // ✗ a path segment is a string\n\ntype ItemId = String where Matches(\"^[0-9]+$\")\non GET(\"/items/:id\") (id: ItemId) -> Effect[HttpResult[String]] by v: Visitor { … }   // ✓",
2613    },
2614    Explain {
2615        code: "bynk.http.query_field_not_stringy",
2616        blurb: "A typed `query` record is filled from a query string, a set of keys with text values, so each field must be one a single value can fill: a `String`, `Int`, `Bool` or `Decimal`, an enum, or a refined or opaque type over one, optionally in an `Option` or a `List` (a repeated key). A nested record or any other type is refused. Flatten the record, or take `query: RequestQuery` and read the keys yourself. A `@form` body has the same rule: `bynk.http.form_field_not_stringy`.",
2617        example: "type Range = { from: Int, to: Int }\ntype Filter = { range: Range }   // ✗ a query string has no nesting\n\ntype Filter = { from: Int, to: Int }   // ✓ flat keys",
2618    },
2619    Explain {
2620        code: "bynk.http.query_not_http",
2621        blurb: "`RequestQuery` is the query string of an HTTP request. A handler that is not an `on http` route, such as a `cron` schedule, answers no request, so it has no query string to take. Remove the parameter, or, if the work is a reply to a caller, make it an `on http` handler. On an HTTP route, `query` is a record or `RequestQuery` and nothing else: `bynk.http.query_wrong_type`.",
2622        example: "service ticker from cron {\n    on schedule(\"*/5 * * * *\") (query: RequestQuery) -> Effect[Result[(), String]] { … }   // ✗ no request\n}\n\nservice ticker from http {\n    on GET(\"/ticks\") (query: RequestQuery) -> Effect[HttpResult[String]] by v: Visitor { … }   // ✓\n}",
2623    },
2624    Explain {
2625        code: "bynk.http.query_wrong_type",
2626        blurb: "A handler's `query` parameter is the request's query string, and the router offers two ways to take it: a record type, which it decodes and validates, answering `400` when the string does not fit, or `RequestQuery`, the raw view. Any other type is refused. Declare the keys you expect as a record, or take `RequestQuery`. The record's fields are held to `bynk.http.query_field_not_stringy`.",
2627        example: "on GET(\"/items\") (query: String) -> Effect[HttpResult[String]] by v: Visitor { … }   // ✗ `query` is a record or `RequestQuery`\n\ntype Filter = { tag: Option[String] }\non GET(\"/items\") (query: Filter) -> Effect[HttpResult[String]] by v: Visitor { … }   // ✓",
2628    },
2629    Explain {
2630        code: "bynk.http.raw_bad_content_type",
2631        blurb: "`@raw(contentType: …)` is the media type the route accepts: the router compares it, ignoring parameters such as `charset`, with each request's `Content-Type` and answers `415` on a mismatch. So it is required, and must be a string literal of the form `type/subtype`. Write `\"image/png\"`, or `\"*/*\"` to accept any type.",
2632        example: "@raw(contentType: \"png\")         // ✗ not `type/subtype`\n@limit(maxBody: 1_000_000)\non POST(\"/avatars\") (body: Bytes) -> Effect[HttpResult[String]] by v: Visitor { … }\n\n@raw(contentType: \"image/png\")   // ✓\n\nconst Png: String = \"image/png\"\n@raw(contentType: Png)   // ✓ a `String` constant bound to a literal\n@limit(maxBody: 1_000_000)\non POST(\"/icons\") (body: Bytes) -> Effect[HttpResult[String]] by v: Visitor { … }",
2633    },
2634    Explain {
2635        code: "bynk.http.raw_body_not_bytes",
2636        blurb: "`@raw` hands the handler the request's octets untouched, so its `body` must be `Bytes` (read whole) or `Stream[Bytes]` (read chunk by chunk); any other type would have to be decoded from them, and decoding is what `@raw` opts out of. Type `body` as `Bytes` and decode it in the handler, or drop `@raw` to have the router decode a JSON body for you. Without `@raw`, a `Bytes` body is base64 inside JSON.",
2637        example: "@raw(contentType: \"image/png\")\n@limit(maxBody: 1_000_000)\non POST(\"/avatars\") (body: String) -> Effect[HttpResult[String]] by v: Visitor { … }   // ✗ raw octets are `Bytes`\n\n@raw(contentType: \"image/png\")\n@limit(maxBody: 1_000_000)\non POST(\"/avatars\") (body: Bytes) -> Effect[HttpResult[String]] by v: Visitor { … }    // ✓",
2638    },
2639    Explain {
2640        code: "bynk.http.raw_body_unbounded",
2641        blurb: "A `@raw` route hands the handler its request body as untouched octets, \
2642                buffered in memory up to a cap. With no cap there is no bound on that \
2643                buffer, which is the denial of service request body limits exist to \
2644                stop, so a raw route must have one: a `@limit(maxBody:)` on the \
2645                handler, or a `limits { maxBody = … }` on the service.",
2646        example: "@raw(contentType: \"image/png\")           // ✗ no cap anywhere\n\
2647                  on POST(\"/avatars\") (body: Bytes) -> Effect[HttpResult[String]] by v: Visitor { … }\n\n\
2648                  @raw(contentType: \"image/png\")           // ✓ capped\n\
2649                  @limit(maxBody: 5_000_000)\n\
2650                  on POST(\"/avatars\") (body: Bytes) -> Effect[HttpResult[String]] by v: Visitor { … }",
2651    },
2652    Explain {
2653        code: "bynk.http.raw_duplicate",
2654        blurb: "`@raw` says the route reads its body as untouched bytes and names the one media type it accepts. A handler has one body, so a second `@raw` has no meaning: the router would have two media types to compare with and nothing to decide between them. Keep one. To accept more than one type, use `\"*/*\"`, or write a route for each. Another body annotation on the same route is `bynk.http.body_kind_conflict`.",
2655        example: "@raw(contentType: \"image/png\")\n@raw(contentType: \"image/jpeg\")    // ✗ a second `@raw`\n@limit(maxBody: 1_000_000)\non POST(\"/avatars\") (body: Bytes) -> Effect[HttpResult[String]] by v: Visitor { … }\n\n@raw(contentType: \"*/*\")           // ✓ one `@raw`, any type\n@limit(maxBody: 1_000_000)\non POST(\"/avatars\") (body: Bytes) -> Effect[HttpResult[String]] by v: Visitor { … }",
2656    },
2657    Explain {
2658        code: "bynk.http.raw_error_status",
2659        blurb: "`RawError` answers with an error status and a body you render yourself, so its first argument must name a 4xx or 5xx `HttpResult` variant, such as `Forbidden` or `ErrorStatus.Conflict`, written as a name. A number, a 2xx name or an expression is refused, so a failure cannot be sent as a success. The diagnostic lists the names. A status name anywhere else is `bynk.http.error_status_position`.",
2660        example: "RawError(200, Bytes.empty(), \"text/plain\")        // ✗ the status is a name, not a number\n\nRawError(NotFound, Bytes.empty(), \"text/plain\")   // ✓",
2661    },
2662    Explain {
2663        code: "bynk.http.raw_on_bodyless",
2664        blurb: "`@raw` marks a request body as untouched octets, so it belongs on a `POST`, `PUT` or `PATCH` route with a `body: Bytes` parameter. On a `GET`, a `DELETE` or a route with no `body` there is nothing for it to mark. It is about the request, not the response: to answer with bytes, return `Raw(body, contentType)`. `@form` on such a route is `bynk.http.form_on_bodyless`.",
2665        example: "@raw(contentType: \"image/png\")   // ✗ a `GET` has no body\non GET(\"/avatars/:id\") (id: String) -> Effect[HttpResult[String]] by v: Visitor { … }\n\n@raw(contentType: \"image/png\")   // ✓ an upload route\n@limit(maxBody: 5_000_000)\non POST(\"/avatars\") (body: Bytes) -> Effect[HttpResult[String]] by v: Visitor { … }",
2666    },
2667    Explain {
2668        code: "bynk.http.raw_unknown_arg",
2669        blurb: "`@raw` takes one argument, `contentType:`, the media type the route accepts. The set is closed, so a misspelt or invented argument is refused rather than ignored, which would leave the route behaving otherwise than you wrote. A size ceiling is not an argument of `@raw`: it is a separate `@limit(maxBody: …)`. Remove the argument. A bad `contentType` is `bynk.http.raw_bad_content_type`.",
2670        example: "@raw(contentType: \"image/png\", maxSize: 10)   // ✗ not an argument of `@raw`\n@limit(maxBody: 1_000_000)\non POST(\"/avatars\") (body: Bytes) -> Effect[HttpResult[String]] by v: Visitor { … }\n\n@raw(contentType: \"image/png\")                // ✓\n@limit(maxBody: 1_000_000)\non POST(\"/avatars\") (body: Bytes) -> Effect[HttpResult[String]] by v: Visitor { … }",
2671    },
2672    Explain {
2673        code: "bynk.http.rejected_signature",
2674        blurb: "`on rejected` renders the router's own refusals, such as a `413` or a `405`, before any handler or actor exists, so it has a fixed shape: one parameter typed `BoundaryRejection`, returning `HttpResult[()]` or `Effect[HttpResult[()]]`, with no `by`, since no actor is known yet, and no `given`, since it only renders a body. Each departure is reported with the form to write. A second `on rejected` is `bynk.http.duplicate_rejected`.",
2675        example: "on rejected(why: String) -> Effect[HttpResult[()]] { … }             // ✗ the parameter is a `BoundaryRejection`\n\non rejected(why: BoundaryRejection) -> Effect[HttpResult[()]] { … }   // ✓",
2676    },
2677    Explain {
2678        code: "bynk.http.reserved_prefix",
2679        blurb: "Two path prefixes belong to the platform. `/_bynk/` is reserved for Bynk's own dispatch, and `/_assets/` is where content-hashed static assets are served before the Worker runs, so a handler there could be shadowed by any asset. A route at either, or at the bare `/_bynk` or `/_assets`, is refused. Choose another path.",
2680        example: "on GET(\"/_bynk/health\") () -> Effect[HttpResult[String]] by v: Visitor { … }   // ✗ reserved for the runtime\n\non GET(\"/health\") () -> Effect[HttpResult[String]] by v: Visitor { … }   // ✓",
2681    },
2682    Explain {
2683        code: "bynk.http.reserved_route_syntax",
2684        blurb: "`*`, `{` and `}` are reserved in a route, both in a literal segment and in a `:name` parameter, for a future form that matches the rest of a path. Matched literally, such a segment would quietly change meaning when that form arrives, so it is refused now. To match a literal `*` or brace, take the segment as a `:name` parameter and check its value in the handler. A route that does not start with `/` is `bynk.http.invalid_path`.",
2685        example: "on GET(\"/files/*key\") () -> Effect[HttpResult[String]] by v: Visitor { … }             // ✗ `*` is reserved\n\non GET(\"/files/:key\") (key: String) -> Effect[HttpResult[String]] by v: Visitor { … }   // ✓",
2686    },
2687    Explain {
2688        code: "bynk.http.return_not_effect_http_result",
2689        blurb: "An `on http` handler returns `Effect[HttpResult[T]]`: `Effect` because it may use capabilities, and `HttpResult[T]` because the status is part of the answer (`Ok`, `Created`, `NotFound`, and so on). An `Effect[T]` with no status is refused. Wrap the type, and return one of the `HttpResult` variants.",
2690        example: "on GET(\"/items\") () -> Effect[String] by v: Visitor { … }   // ✗ no `HttpResult`\n\non GET(\"/items\") () -> Effect[HttpResult[String]] by v: Visitor { … }   // ✓",
2691    },
2692    Explain {
2693        code: "bynk.http.security_invalid_field",
2694        blurb: "The fields of a `security { }` section are fixed at compile time and become response headers. `hsts` must be a positive `Duration` literal such as `180.days`, because it is written as a `max-age` and a zero would clear the browser's HTTPS pin; a bare number has no unit. `nosniff` must be `true` or `false`. Write the value out. A field other than these two is `bynk.http.security_unknown_field`.",
2695        example: "service api from http {\n    security { hsts: 180 }         // ✗ a `Duration`, not a number\n    on GET(\"/items\") () -> Effect[HttpResult[String]] by v: Visitor { … }\n}\n\nservice api from http {\n    security { hsts: 180.days }    // ✓\n    on GET(\"/items\") () -> Effect[HttpResult[String]] by v: Visitor { … }\n}",
2696    },
2697    Explain {
2698        code: "bynk.http.security_not_http",
2699        blurb: "A `security { }` section sets the security headers, `Strict-Transport-Security` and `X-Content-Type-Options`, stamped on a service's HTTP responses. Only a `from http` service sends them, so on a `cron` or other service the section is refused. Move it to the HTTP service it was meant for, or delete it. The `cors`, `limits` and `json` sections have the same rule: `bynk.http.cors_not_http`, `bynk.http.limits_not_http`, `bynk.http.json_not_http`.",
2700        example: "service jobs from cron {\n    security { hsts: 180.days }   // ✗ a schedule sends no response headers\n    on schedule(\"0 0 * * *\") () -> Effect[Result[(), String]] { … }\n}\n\nservice api from http {\n    security { hsts: 180.days }   // ✓\n    on GET(\"/items\") () -> Effect[HttpResult[String]] by v: Visitor { … }\n}",
2701    },
2702    Explain {
2703        code: "bynk.http.security_unknown_field",
2704        blurb: "A `security { }` section has two fields, `hsts` and `nosniff`, and each becomes a response header. The set is closed, so a misspelt or invented field is refused rather than ignored, which would leave the service sending headers you did not intend; no other header is set from this section. Rename the field or remove it. A field with a bad value is `bynk.http.security_invalid_field`.",
2705        example: "service api from http {\n    security { hsts: 180.days, frameOptions: \"DENY\" }    // ✗ `hsts` and `nosniff` only\n    on GET(\"/items\") () -> Effect[HttpResult[String]] by v: Visitor { … }\n}\n\nservice api from http {\n    security { hsts: 180.days }                          // ✓\n    on GET(\"/items\") () -> Effect[HttpResult[String]] by v: Visitor { … }\n}",
2706    },
2707    Explain {
2708        code: "bynk.http.stream_body_not_raw",
2709        blurb: "A `Stream[Bytes]` `body` is a request body handed to the handler chunk by chunk, so the router must be told to leave it as octets: without `@raw` a body is JSON (or base64 inside JSON for `Bytes`), which has no streamed form. Add `@raw(contentType: \"…\")` and a `@limit`, or take the body as a value (`T`, or `Bytes`) to have it read whole.",
2710        example: "@limit(maxBody: 1_000_000)\non PUT(\"/blobs/:id\") (id: String, body: Stream[Bytes]) -> Effect[HttpResult[()]] by v: Visitor { … }   // ✗ not `@raw`\n\n@raw(contentType: \"application/octet-stream\")\n@limit(maxBody: 1_000_000)\non PUT(\"/blobs/:id\") (id: String, body: Stream[Bytes]) -> Effect[HttpResult[()]] by v: Visitor { … }   // ✓",
2711    },
2712    Explain {
2713        code: "bynk.http.stream_body_on_sum_route",
2714        blurb: "A route `by` a sum of actors, such as `User | Visitor`, reads and verifies the request body itself before the handler runs. A streamed `body` is not read until the handler pulls it, so the two cannot both own it and the pair is refused. Name one actor on the route, or split it into one route per actor.",
2715        example: "actor User { auth = Bearer(secret = \"AUTH_JWT_SECRET\"), identity = UserId }\n\n@raw(contentType: \"image/png\")\n@limit(maxBody: 5_000_000)\non PUT(\"/avatars\") (body: Stream[Bytes]) -> Effect[HttpResult[()]] by who: User | Visitor { … }   // ✗ a sum of actors\n\n@raw(contentType: \"image/png\")\n@limit(maxBody: 5_000_000)\non PUT(\"/avatars\") (body: Stream[Bytes]) -> Effect[HttpResult[()]] by who: User { … }             // ✓ one actor",
2716    },
2717    Explain {
2718        code: "bynk.http.stream_body_signature",
2719        blurb: "A `Signature` actor checks an HMAC over the whole request body before the handler runs, so the body has to be held in full. A streamed `body` is read by the handler afterwards, a chunk at a time, and could not have been verified. Take `body: Bytes` on a signed route (a webhook, say), or sign the head (a header or the path) and verify the content another way.",
2720        example: "actor Hook { auth = Signature(secret = \"HOOK_SECRET\", header = \"X-Signature\") }\n\n@raw(contentType: \"application/octet-stream\")\n@limit(maxBody: 1_000_000)\non POST(\"/hook\") (body: Stream[Bytes]) -> Effect[HttpResult[()]] by h: Hook { … }   // ✗ unverifiable\n\n@raw(contentType: \"application/octet-stream\")\n@limit(maxBody: 1_000_000)\non POST(\"/hook\") (body: Bytes) -> Effect[HttpResult[()]] by h: Hook { … }          // ✓",
2721    },
2722    Explain {
2723        code: "bynk.http.unbound_path_param",
2724        blurb: "A `:name` segment in a route promises a value the handler can use, and the value reaches it only through a parameter of the same name. A segment with no such parameter would be matched and then thrown away, which is nearly always a slip, so the route is refused. Add the parameter, typed `String` or a refined `String`, or drop the segment from the path. The reverse, a parameter with no segment, is `bynk.http.extra_param`.",
2725        example: "on GET(\"/items/:id\") () -> Effect[HttpResult[String]] by v: Visitor { … }   // ✗ `:id` has no parameter\n\non GET(\"/items/:id\") (id: String) -> Effect[HttpResult[String]] by v: Visitor { … }   // ✓",
2726    },
2727    Explain {
2728        code: "bynk.http.unknown_handler_annotation",
2729        blurb: "The handler annotations are a closed set: `@cache`, `@limit`, `@raw`, `@form`, `@multipart` and `@json`. Each changes how the router treats the route, so a misspelt one that was ignored would silently lose the behaviour you wanted, such as a freshness window or a body cap. Fix the spelling or remove the annotation. Settings shared by every route belong on the service, in a `cors`, `security`, `limits` or `json` block.",
2730        example: "@cached(maxAge: 5.minutes)   // ✗ no such annotation\non GET(\"/links\") () -> Effect[HttpResult[String]] by v: Visitor { … }\n\n@cache(maxAge: 5.minutes)    // ✓",
2731    },
2732    Explain {
2733        code: "bynk.index.bad_argument",
2734        blurb: "`@indexed` says which field of the map's value type to maintain a secondary index on, and the only form it takes is `by: <field>`. A bare name, another label or an expression leaves the compiler without a field to index. Write `by:` followed by the field's name. A name that is not a field of the value type is `bynk.index.unknown_key`.",
2735        example: "type Order = { id: String, customerId: String }\n\nstore orders: Map[String, Order] @indexed(customerId)       // ✗ not a `by:` label\n\nstore orders: Map[String, Order] @indexed(by: customerId)   // ✓",
2736    },
2737    Explain {
2738        code: "bynk.index.unkeyable_key",
2739        blurb: "An index is looked up by equality on its key, so the field has to be a value the store can compare and key on: `Int`, `String`, or a refined or opaque type over one of them. A `Bool`, a record or a list cannot be. Index another field, or add a field of a keyable type to look up by. The same rule for a `Map` key is `bynk.store.unkeyable_key`.",
2740        example: "type Order = { id: String, paid: Bool, customerId: String }\n\nstore orders: Map[String, Order] @indexed(by: paid)         // ✗ a `Bool` is not keyable\n\nstore orders: Map[String, Order] @indexed(by: customerId)   // ✓ a `String`",
2741    },
2742    Explain {
2743        code: "bynk.internal.missing_checker_fact",
2744        blurb: "This is a compiler fault, not a mistake in your program. The code generator needs a fact the checker should have recorded about a construct (its type, the callee it resolves to, how many arguments it takes, a field's default value) and did not find one. Every program the checker accepts carries these facts, so no source you write can cause this on purpose. The diagnostic points at the construct being compiled when the fact was missing. Please report it at https://github.com/bynk-lang/bynk/issues with the source around that location, which is all that is needed to reproduce it. The compiler stops before it writes any output for the unit, rather than emit a program that might mean something other than what you wrote.",
2745        example: "// bynk internal error: the checker recorded no type for a `fold` call, which the code generator needs here.\n// This is a compiler fault, not a problem in your program; please report it at https://github.com/bynk-lang/bynk/issues\n//\n// There is no program to fix: the report is the fix.",
2746    },
2747    Explain {
2748        code: "bynk.invariant.cross_agent_reference",
2749        blurb: "An invariant is checked inside one agent's commit, against that agent's own state. Reading another agent would mean a call out to it, whose value could change before the commit lands, so the claim could not be held. A property that spans agents belongs in a saga or a scenario. Keep the invariant to this agent's fields. The mirror rule for steps is `bynk.transition.cross_agent_reference`.",
2750        example: "invariant within_total: count <= Total(\"all\").get()   // ✗ reads another agent\n\ninvariant non_negative: count >= 0                    // ✓ this agent's own state",
2751    },
2752    Explain {
2753        code: "bynk.invariant.duplicate_name",
2754        blurb: "Invariants are named so that a violation can say which one was broken. Two with the same name in one agent would make that report ambiguous. Rename one, or merge the two predicates if they are one claim. The same rule for steps is `bynk.transition.duplicate_name`.",
2755        example: "invariant bounded: count >= 0\ninvariant bounded: count < 100   // ✗ `bounded` is already declared\n\ninvariant capped: count < 100    // ✓ a distinct name",
2756    },
2757    Explain {
2758        code: "bynk.invariant.impure_predicate",
2759        blurb: "An invariant is checked at every commit, over the state about to be written, so it may only read: state fields, operators and pure value methods. `Effect.pure`, `?`, `expect`, `Val` and the other test-only forms are refused, as is anything that performs an effect. Rewrite the predicate as a plain `Bool` expression over the fields. The mirror rule for steps is `bynk.transition.impure_predicate`.",
2760        example: "invariant positive: Effect.pure(count >= 0)   // ✗ an effect, not a pure predicate\n\ninvariant positive: count >= 0                // ✓ a plain `Bool` expression",
2761    },
2762    Explain {
2763        code: "bynk.invariant.not_bool",
2764        blurb: "An invariant is a claim that is true or false of every committed state, so its predicate must be a `Bool`. A bare field such as `count` is a value, not a claim, and nothing says what is being asserted about it. Compare or test it: `count >= 0`. A `transition` is held to the same rule (`bynk.transition.not_bool`).",
2765        example: "invariant positive: count        // ✗ an `Int`, not a `Bool`\n\ninvariant positive: count >= 0   // ✓ a claim about `count`",
2766    },
2767    Explain {
2768        code: "bynk.json.encode_plain_generic",
2769        blurb: "`Json.encodePlain` writes an `Option` as its value or `null`, which it can do only when it knows the type. A generic function is compiled once for every `T`, and encodes through its `Codable` witness, which always writes `Option` in the tagged form `{\"kind\":\"Some\",…}`. Encode at a concrete type, or use `Json.encode` if the tagged form will do. A concrete type that is ambiguous in plain form is `bynk.json.nested_option_plain`.",
2770        example: "fn plain[T: Codable](v: T) -> String { Json.encodePlain(v) }   // ✗ `T` could be an `Option`\n\nfn plain(v: Option[Int]) -> String { Json.encodePlain(v) }     // ✓ a concrete type",
2771    },
2772    Explain {
2773        code: "bynk.json.nested_option_plain",
2774        blurb: "Plain JSON writes `Some(v)` as `v` and `None` as `null`, so it can only be read back if `v` is never itself `null`. In an `Option[Option[T]]` or an `Option[()]`, `Some(None)` and `None` (or `Some(())` and `None`) would both be written `null`, and the decoder could not tell them apart. The compiler refuses the type wherever plain encoding is asked for: in the response type of a route whose `json { options: plain }` or `@json(options: plain)` applies, or in the argument of `Json.encodePlain`, through records, sums, containers and generic arguments alike. The tagged form, which `Json.encode` and a route's default use, writes `Option` as `{\"kind\":\"Some\",\"value\":…}` and has no such ambiguity. Either flatten the type, model the distinction as a sum type, or keep that route tagged.",
2775        example: "type Row = { id: String, note: Option[Option[String]] }\n\non GET(\"/rows\") () -> Effect[HttpResult[List[Row]]] by v: Visitor { … }   // ✗ `Some(None)` and `None` both write `null`\n\ntype Row = { id: String, note: Option[String] }   // ✓",
2776    },
2777    Explain {
2778        code: "bynk.lambda.unannotated_param",
2779        blurb: "A lambda's parameter types come from where it is used: passed to `map` over a `List[Int]`, `(x) => x + 1` takes `x: Int`. A lambda standing alone, bound by a `let` for instance, has no such context, and the compiler asks for the type rather than guess it from the body. Annotate the parameter, or pass the lambda directly where a function type is expected.",
2780        example: "let f = (x) => x + x          // ✗ nothing says what `x` is\n\nlet f = (x: Int) => x + x     // ✓ annotated",
2781    },
2782    Explain {
2783        code: "bynk.lex.bad_escape",
2784        blurb: "A backslash in a string literal starts an escape, and this one is \
2785                not in the set: `\\n`, `\\r`, `\\t`, `\\0`, `\\\"`, `\\\\`, \
2786                `\\u{…}` (1 to 6 hex digits in braces) and `\\(…)` for \
2787                interpolation. To write a backslash itself, double it, as in a \
2788                Windows path. A `\\u{…}` naming a surrogate or a value past \
2789                U+10FFFF is `bynk.lex.bad_unicode_escape`.",
2790        example: "const Dir: String = \"C:\\Users\"      // ✗ `\\U` is not an escape\n\
2791                  const Dir: String = \"C:\\\\Users\"     // ✓ a doubled backslash",
2792    },
2793    Explain {
2794        code: "bynk.lex.bad_unicode_escape",
2795        blurb: "A `\\u{…}` escape must name a Unicode scalar value, so a string \
2796                is always valid text. A surrogate (`D800` to `DFFF`) is half of \
2797                a UTF-16 pair and stands for no character on its own, and \
2798                anything above `10FFFF` is outside Unicode. Write the code point \
2799                of the character you mean, such as `\\u{E9}` for `é`. A `\\u` \
2800                with no braces, no digits or more than six digits is \
2801                `bynk.lex.bad_escape`.",
2802        example: "const Mark: String = \"\\u{D800}\"    // ✗ a surrogate is not a character\n\
2803                  const Mark: String = \"\\u{E9}\"      // ✓ `é`",
2804    },
2805    Explain {
2806        code: "bynk.lex.float_literal_overflow",
2807        blurb: "A `Float` is a 64-bit IEEE 754 double, and a literal must be a \
2808                finite one: the largest is about 1.8e308. A literal past that \
2809                would round to infinity, which no `Float` literal can spell, so \
2810                it is refused rather than changed silently. Write a value in \
2811                range.",
2812        example: "const Big: Float = 1e999    // ✗ past the largest double\n\
2813                  const Big: Float = 1e308    // ✓",
2814    },
2815    Explain {
2816        code: "bynk.lex.integer_overflow",
2817        blurb: "An `Int` is a JavaScript safe integer, from -(2^53 - 1) to 2^53 - \
2818                1 (±9007199254740991), the range the runtime holds exactly; a \
2819                larger literal would round silently. The sign is a separate \
2820                operator, so the size of the digits decides. For a larger value \
2821                use a `Float` if rounding is acceptable, or a `String` for the \
2822                exact digits.",
2823        example: "const Big: Int = 9007199254740993    // ✗ past 2^53 - 1\n\
2824                  const Big: Int = 9007199254740991    // ✓ the largest `Int`",
2825    },
2826    Explain {
2827        code: "bynk.lex.legacy_comment",
2828        blurb: "A `--` no longer starts a comment; a line comment is `//`. The old \
2829                spelling is refused rather than reread, so a file written for it \
2830                never changes meaning: `x = 1 -- note` is not quietly taken for `1 \
2831                - -note`. The fix is machine-applicable: `bynk check --fix` \
2832                applies it and `bynk fmt` rewrites a whole project. For a real `a \
2833                - -b`, write the space.",
2834        example: "const Limit: Int = 100 -- the cap     // ✗ `--` is the old comment\n\
2835                  const Limit: Int = 100        // ✓ a comment is `//`",
2836    },
2837    Explain {
2838        code: "bynk.lex.legacy_doc_line",
2839        blurb: "A one-line doc is `--- text`. The older `--|` spelling is \
2840                refused rather than reread, so no file written for it changes \
2841                meaning unnoticed. The fix is machine-applicable: `bynk check \
2842                --fix` applies it and `bynk fmt` rewrites a whole project. A \
2843                `--|` with no text has no one-line form; write a doc block \
2844                between two `---` lines.",
2845        example: "--| Doubles a number.                  // ✗ the old spelling\n\
2846                  fn double(n: Int) -> Int { n * 2 }\n\
2847                  \n\
2848                  --- Doubles a number.                  // ✓\n\
2849                  fn double(n: Int) -> Int { n * 2 }",
2850    },
2851    Explain {
2852        code: "bynk.lex.slash_doc",
2853        blurb: "A `///` is not a doc comment in Bynk. A doc is written with \
2854                dashes: `--- text` for one line, or a block between two `---` \
2855                lines for more. A plain comment is `//`. The fix to `---` is \
2856                machine-applicable: `bynk check --fix` applies it. A run of four \
2857                or more slashes is an ordinary comment.",
2858        example: "/// Doubles a number.                  // ✗ a comment, not a doc\n\
2859                  fn double(n: Int) -> Int { n * 2 }\n\
2860                  \n\
2861                  --- Doubles a number.                  // ✓\n\
2862                  fn double(n: Int) -> Int { n * 2 }",
2863    },
2864    Explain {
2865        code: "bynk.lex.unclosed_doc_block",
2866        blurb: "A line of three or more dashes opens a documentation block, and \
2867                a line of exactly the same number of dashes closes it. Here no \
2868                closing line follows, so the compiler cannot tell where the \
2869                documentation ends. There is no standalone `---` divider; a \
2870                divider is a comment, `// ---`. Add the closing line.",
2871        example: "---                                // ✗ never closed\n\
2872                  Doubles a number.\n\
2873                  fn double(n: Int) -> Int { n * 2 }\n\
2874                  \n\
2875                  ---\n\
2876                  Doubles a number.\n\
2877                  ---                                // ✓ closed with as many dashes\n\
2878                  fn double(n: Int) -> Int { n * 2 }",
2879    },
2880    Explain {
2881        code: "bynk.lex.unexpected_character",
2882        blurb: "The lexer met a character that starts no token in Bynk, such as \
2883                `#`, `$` or `'` outside a string literal. A comment is `//` (not \
2884                `#`) and a string takes double quotes (not single). The character \
2885                is skipped and lexing goes on, so every lexical error in the file \
2886                is reported together.",
2887        example: "const Limit: Int = 100 # the cap       // ✗ `#` is not a comment\n\
2888                  const Limit: Int = 100        // ✓ a comment is `//`",
2889    },
2890    Explain {
2891        code: "bynk.lex.unterminated_string",
2892        blurb: "An ordinary string literal, `\"…\"`, closes on the line it opens on. \
2893                This one reaches the end of the line with no closing `\"`, so the \
2894                lexer reports it at the opening quote and skips the rest of the \
2895                line. Add the closing quote. For a line break in the value write \
2896                `\\n`, or use a multi-line string literal.",
2897        example: "const Greeting: String = \"hello      // ✗ no closing quote\n\
2898                  const Greeting: String = \"hello\"   // ✓",
2899    },
2900    Explain {
2901        code: "bynk.messages.format_mismatch",
2902        blurb: "A placeholder that appears in the reference locale's template and in another \
2903                locale's must be formatted the same way in both: plain `{n}`, `plural`, `select`, \
2904                `number` or `date`. The caller supplies one kind of value for it, and an interface \
2905                cannot sensibly be plural-aware in one language and plain in another. Use the same \
2906                kind in every locale. The arms inside a `plural` or `select` may differ. A different \
2907                placeholder name is `bynk.messages.placeholder_mismatch`.",
2908        example: "messages \"en\" @reference {\n\
2909                \x20 \"cart.count\" => \"{n, plural, one {# item} other {# items}}\"\n\
2910                }\n\
2911                \n\
2912                messages \"fr\" {\n\
2913                \x20 \"cart.count\" => \"{n} articles\"        // ✗ plain here, plural in the reference\n\
2914                \x20 \"cart.count\" => \"{n, plural, one {# article} other {# articles}}\"  // ✓\n\
2915                }",
2916    },
2917    Explain {
2918        code: "bynk.messages.incomplete",
2919        blurb: "Every locale is held to the reference locale: it must supply each code the reference \
2920                declares, so that no locale silently lacks a message the reference has. The \
2921                diagnostic is reported once per missing code, at the locale's block. Add the missing \
2922                code to the locale. When you add a code to the reference, every other locale must \
2923                follow. A code that is present with different placeholders is \
2924                `bynk.messages.placeholder_mismatch`.",
2925        example: "messages \"en\" @reference {\n\
2926                \x20 \"cart.empty\" => \"Your basket is empty.\"\n\
2927                \x20 \"cart.greeting\" => \"Hello, {name}!\"\n\
2928                }\n\
2929                \n\
2930                messages \"fr\" {                         // ✗ lacks \"cart.greeting\"\n\
2931                \x20 \"cart.empty\" => \"Votre panier est vide.\"\n\
2932                \x20 \"cart.greeting\" => \"Bonjour, {name} !\"  // ✓ the code added\n\
2933                }",
2934    },
2935    Explain {
2936        code: "bynk.messages.invalid_locale_tag",
2937        blurb: "A `messages` block's tag must be a `LocaleTag`: a well-formed BCP-47 tag in its \
2938                canonical casing, such as `en`, `fr`, `pt-BR` or `zh-Hans-CN`. The compiler checks \
2939                it because the runtime hands the tag to `Intl`, which throws on a malformed one, and \
2940                `render` must never fail. So `pt-br` is refused where `pt-BR` is accepted, and so is \
2941                a bare word such as `klingon`. Rewrite the tag in canonical form.",
2942        example: "messages \"pt-br\" @reference {           // ✗ a region is upper-case\n\
2943                \x20 \"cart.empty\" => \"A sua cesta está vazia.\"\n\
2944                }\n\
2945                \n\
2946                messages \"pt-BR\" @reference {           // ✓\n\
2947                \x20 \"cart.empty\" => \"A sua cesta está vazia.\"\n\
2948                }",
2949    },
2950    Explain {
2951        code: "bynk.messages.malformed_icu_syntax",
2952        blurb: "A message template is checked as ICU MessageFormat at compile time, because a \
2953                malformed one would otherwise fail only when a request rendered it. A `plural` or \
2954                `select` must close its arm braces, use a known format keyword, give each arm a \
2955                distinct key and have an `other` arm, which is used when no other arm matches; `#` \
2956                stands for the number only inside a `plural` arm. Fix the template. Constructs the \
2957                compiler does not support, such as `selectordinal` and `offset:`, are reported here \
2958                too.",
2959        example: "messages \"en\" @reference {\n\
2960                \x20 \"cart.count\" => \"{n, plural, one {# item}}\"  // ✗ no `other` arm\n\
2961                \x20 \"cart.count\" => \"{n, plural, one {# item} other {# items}}\"  // ✓\n\
2962                }",
2963    },
2964    Explain {
2965        code: "bynk.messages.missing_locale_dependency",
2966        blurb: "A commons that declares `messages` gets a generated `render`, whose signature names \
2967                `LocaleTag` and `Message` and which falls back through `bynk.locale`. So that \
2968                commons must `uses` both locale units, as the example shows; add whichever is \
2969                missing. The context that uses the bundle should not `uses bynk.locale` itself: both \
2970                export a `render`, which is `bynk.uses.name_conflict`.",
2971        example: "commons shop.messages\n\
2972                \n\
2973                messages \"en\" @reference { … }          // ✗ no `uses` of bynk.locale\n\
2974                \n\
2975                uses bynk.locale                        // ✓ both lines are needed\n\
2976                uses bynk.locale.types\n\
2977                messages \"en\" @reference { … }",
2978    },
2979    Explain {
2980        code: "bynk.messages.missing_reference",
2981        blurb: "A message bundle is a set of locale blocks, and the compiler checks every locale \
2982                against one of them, the reference, marked `@reference`. It is also the fallback \
2983                when a requested locale is not declared. With no reference there is nothing to check \
2984                the others against, so exactly one block per commons must carry the mark. Add \
2985                `@reference` to the locale your strings are written in first. Two marked blocks are \
2986                `bynk.messages.multiple_reference`.",
2987        example: "messages \"en\" {                         // ✗ no block is marked @reference\n\
2988                \x20 \"cart.empty\" => \"Your basket is empty.\"\n\
2989                }\n\
2990                \n\
2991                messages \"en\" @reference {              // ✓\n\
2992                \x20 \"cart.empty\" => \"Your basket is empty.\"\n\
2993                }",
2994    },
2995    Explain {
2996        code: "bynk.messages.multiple_reference",
2997        blurb: "A message bundle is checked against one reference locale, which is also the fallback when a requested locale is not declared. With two blocks marked `@reference` there are two answers, so exactly one per commons may carry the mark. Keep `@reference` on the locale your strings are written in first and take it off the others. No block marked at all is `bynk.messages.missing_reference`.",
2998        example: "messages \"en\" @reference { … }\nmessages \"fr\" @reference { … }   // ✗ a second reference\n\nmessages \"fr\" { … }              // ✓",
2999    },
3000    Explain {
3001        code: "bynk.messages.outside_commons",
3002        blurb: "A `messages` block is pure, stateless data, which is what a `commons` holds. A \
3003                context carries services and state and an adapter wraps foreign code, and neither \
3004                takes a bundle. Move the bundle into a commons, with the two `uses` lines it needs, \
3005                and have the context `uses` that commons.",
3006        example: "context shop.web\n\
3007                \n\
3008                messages \"en\" @reference { … }          // ✗ a context cannot hold a bundle\n\
3009                \n\
3010                commons shop.messages\n\
3011                \n\
3012                uses bynk.locale\n\
3013                uses bynk.locale.types\n\
3014                messages \"en\" @reference { … }          // ✓ a commons can",
3015    },
3016    Explain {
3017        code: "bynk.messages.placeholder_mismatch",
3018        blurb: "A caller supplies a message's arguments by name, so every locale's template for a \
3019                code must use the same set of `{name}` placeholders as the reference locale's. A \
3020                translation that renames, drops or adds one would ask for an argument the caller \
3021                never passes. Order is free: translations may reorder placeholders to suit their \
3022                grammar. Rename the placeholder to match the reference. A placeholder of the right \
3023                name but a different ICU kind is `bynk.messages.format_mismatch`.",
3024        example: "messages \"en\" @reference {\n\
3025                \x20 \"cart.greeting\" => \"Hello, {name}!\"\n\
3026                }\n\
3027                \n\
3028                messages \"fr\" {\n\
3029                \x20 \"cart.greeting\" => \"Bonjour, {prenom} !\"  // ✗ the reference uses {name}\n\
3030                \x20 \"cart.greeting\" => \"Bonjour, {name} !\"    // ✓\n\
3031                }",
3032    },
3033    Explain {
3034        code: "bynk.mysql.sql_invalid",
3035        blurb: "When the project has a `schema.sql` at its root, Bynk parses each literal SQL statement of a `MySql` capability, so a syntax error shows up when you check, not on the first request. It also flags a statement of several commands, which the driver does not accept: send each with its own call, or use `transaction`. The parser is a pure-Rust one with a MySQL dialect, not MySQL's own (and MariaDB has forms of its own), so it can refuse valid SQL; that is why this is a warning and never blocks a build. Nothing runs, and the statement is not checked against the schema, which Bynk does not own. Correct the statement, or delete `schema.sql` to turn the check off.",
3036        example: "let _ <- Legacy.all(\"SELEC id FROM orders\", [])        // ✗ expected a statement, found SELEC\n\nlet _ <- Legacy.all(\"SELECT id FROM orders\", [])      // ✓",
3037    },
3038    Explain {
3039        code: "bynk.mysql.sql_param_count",
3040        blurb: "When the project has a `schema.sql`, Bynk counts the parameters of each literal `MySql` statement: each `?` takes the next value. It checks a list written out in place, or a name `let`-bound to one. A `?` inside a single-quoted string literal, a backtick-quoted name or a comment (`-- ` or `/* … */`) is text, not a parameter, as the driver reads it; the driver does not skip a double-quoted string or a `#` comment, so a `?` in one is counted, and string literals are written with single quotes. Pass one `MySqlValue` for each `?`, or change the SQL. `??`, which mysql2 reads as an identifier placeholder, is counted as two parameters and is not supported.",
3041        example: "let _ <- Legacy.all(\"SELECT id FROM orders WHERE id = ? AND qty > ?\", [MySqlInteger(id)])                    // ✗ two parameters, one value\n\nlet _ <- Legacy.all(\"SELECT id FROM orders WHERE id = ? AND qty > ?\", [MySqlInteger(id), MySqlInteger(5)])    // ✓",
3042    },
3043    Explain {
3044        code: "bynk.namespace.reserved",
3045        blurb: "The `bynk` root belongs to the toolchain: its own libraries, such as `bynk.list`, and the platform adapters live there and are added to a build when a unit consumes them. A unit of yours named `bynk` or `bynk.<anything>` could collide with one of them, so the name is refused for every kind of unit. Rename the unit so its first segment is not `bynk`, and move its file to match.",
3046        example: "// bynk/foo.bynk\ncommons bynk.foo    // ✗ `bynk` is the toolchain's namespace\n\n// shop/foo.bynk\ncommons shop.foo    // ✓",
3047    },
3048    Explain {
3049        code: "bynk.observe.impure_with",
3050        blurb: "The `with` predicate of `expect Cap.op called with …` is tested against every recorded call, so it must be a pure expression of the operation's arguments. `trace(…)`, a capability call or anything else effectful or test-only could give a different answer each time. Compare the arguments, or bind `trace(Cap.op)` first and assert on the list.",
3051        example: "// tests/t.test.bynk\nexpect Logger.log called with trace(Logger.log).length() > 0   // ✗ not a pure predicate\nexpect Logger.log called with msg == \"x\"                      // ✓",
3052    },
3053    Explain {
3054        code: "bynk.observe.not_a_seam",
3055        blurb: "`expect Cap.op called` checks the calls the unit under test made through a capability it consumes, whether declared in its context, brought in with `consumes`, or listed in `given`. A name that is not one of those, such as a type or a function, has no recorded calls. Name a consumed capability. An operation it does not declare is `bynk.observe.unknown_op`.",
3056        example: "// tests/t.test.bynk\nexpect AuthId.unsafe called   // ✗ `AuthId` is a type, not a capability\nexpect Logger.log called      // ✓",
3057    },
3058    Explain {
3059        code: "bynk.observe.trace_outside_test",
3060        blurb: "`trace(Cap.op)` reads the calls a test has recorded through a capability. Only a test records them, so it is allowed only in a `case` body, never in a service, an agent or a function. Remove it from the code under test and read the trace in the test, or observe the call with `expect Cap.op called`.",
3061        example: "// demo/pay.bynk\nlet calls = trace(Logger.log)               // ✗ in the service\n\n// tests/t.test.bynk\nexpect trace(Logger.log).length() == 1      // ✓ in a case",
3062    },
3063    Explain {
3064        code: "bynk.observe.unknown_op",
3065        blurb: "`expect Cap.op called` checks the calls recorded for one \
3066                operation of a capability, so `op` must be declared by that \
3067                capability. A misspelt or renamed operation would match no \
3068                call, so it is refused instead of leaving the check vacuous. \
3069                Use the name the capability declares. A capability the unit \
3070                does not consume is `bynk.observe.not_a_seam`.",
3071        example: "// demo/pay.bynk\n\
3072                  capability Logger { … }\n\n\
3073                  // tests/pay.test.bynk\n\
3074                  expect Logger.nope called    // ✗ Logger has no `nope`\n\
3075                  expect Logger.log called     // ✓",
3076    },
3077    Explain {
3078        code: "bynk.observe.with_not_bool",
3079        blurb: "The `with` clause of `expect Cap.op called with …` filters the recorded calls, keeping those for which it is true, so it must be a `Bool`. A bare argument name is a value, not a condition. Compare it with something: `with msg == \"x\"`.",
3080        example: "// tests/t.test.bynk\nexpect Logger.log called with msg           // ✗ a `String`, not a `Bool`\nexpect Logger.log called with msg == \"x\"   // ✓",
3081    },
3082    Explain {
3083        code: "bynk.package.alias_shadows_unit",
3084        blurb: "The key of a `[dependencies]` entry is the alias a unit reaches the package by, as in `lib.notify`. If one of the project's own units also starts with that word, `shop.cart` for an alias `shop`, then `shop.…` could mean the package or the unit, and the compiler will not choose. Rename the alias, which is the key, or rename the unit.",
3085        example: "[dependencies]\nshop = { package = \"acme/lib\", path = \"pkg/lib\" }   // ✗ the project has a unit `shop`\n\nlib = { package = \"acme/lib\", path = \"pkg/lib\" }    // ✓ an alias no unit starts with",
3086    },
3087    Explain {
3088        code: "bynk.package.dependency_cycle",
3089        blurb: "A package's units are resolved against the packages it depends on, so the package graph needs an order: no package may depend, directly or through others, on itself or on the project. A cycle usually means two packages each want something of the other. Move what both need into a third package that each of them depends on, or merge the two.",
3090        example: "# packages/money/bynk.toml\n[dependencies]\ntax = { package = \"acme/tax\", path = \"../tax\" }\n\n# packages/tax/bynk.toml\n[dependencies]\nmoney = { package = \"acme/money\", path = \"../money\" }   // ✗ `acme/money` depends on `acme/tax`\n\ncore = { package = \"acme/core\", path = \"../core\" }      // ✓ what both need, in a package of its own",
3091    },
3092    Explain {
3093        code: "bynk.package.dependency_not_found",
3094        blurb: "A path dependency points at a directory that is a package: it has its own `bynk.toml` with a `[package]` table. The path is read from the manifest that names it. The entry is refused when there is no readable `bynk.toml` there, when it is not valid, or when it has no `[package]`. Correct the path, or add the manifest to the package.",
3095        example: "[dependencies]\nlib = { package = \"acme/lib\", path = \"pkg/libs\" }   // ✗ no `bynk.toml` at `pkg/libs`\n\nlib = { package = \"acme/lib\", path = \"pkg/lib\" }    // ✓ the package's directory",
3096    },
3097    Explain {
3098        code: "bynk.package.dev_dependency_in_source",
3099        blurb: "A `[dev-dependencies]` package is there for the project's suites, and a deployable build leaves suites out, so a package that only suites need is never compiled into it. A context or commons that reached one would break that build, so only a suite may. If the source needs the package, move its entry to `[dependencies]`; otherwise keep the use in a suite.",
3100        example: "// bynk.toml\n[dev-dependencies]\nlib = { package = \"acme/lib\", path = \"pkg/lib\" }\n\n// shop.bynk\nuses lib.notify      // ✗ a `[dev-dependencies]` alias is for suites\n\n// bynk.toml\n[dependencies]       // ✓ the entry moved here\nlib = { package = \"acme/lib\", path = \"pkg/lib\" }",
3101    },
3102    Explain {
3103        code: "bynk.package.duplicate_source",
3104        blurb: "A build holds one copy of each package, so every dependency on a package must reach it in the same directory. Two entries that name one package but point at different directories would give two copies, with two sets of types where there should be one. Point both at the same directory, or drop one. Two aliases onto one directory are fine.",
3105        example: "[dependencies]\nlib = { package = \"acme/lib\", path = \"pkg/lib\" }\nutil = { package = \"acme/lib\", path = \"vendor/lib\" }   // ✗ `acme/lib` from a second directory\n\nutil = { package = \"acme/lib\", path = \"pkg/lib\" }      // ✓ the same directory",
3106    },
3107    Explain {
3108        code: "bynk.package.name_mismatch",
3109        blurb: "A path dependency gives the package's name twice: `package = \"acme/lib\"` in your `[dependencies]`, and `name` under `[package]` in the manifest at that path. They must agree, so that what you asked for is what you get. A mismatch usually means the path is the wrong directory, or the package was renamed. Correct whichever is wrong.",
3110        example: "[dependencies]\nmoney = { package = \"acme/money\", path = \"pkg/lib\" }   // ✗ `pkg/lib` is the package `acme/lib`\n\nmoney = { package = \"acme/lib\", path = \"pkg/lib\" }     // ✓ the name it declares",
3111    },
3112    Explain {
3113        code: "bynk.package.unit_not_exported",
3114        blurb: "A package lists in `exports` the units it offers to its users, and keeps the rest free to change, as a library keeps its internals. A unit that exists but is not listed is refused, so a consumer cannot come to rely on it. Use one of the exported units, or ask the package to export it. Leaving `exports` out shares every commons and adapter. A name the package does not declare at all is `bynk.package.unknown_unit`.",
3115        example: "exports = [\"notify\"]      // in the package's `bynk.toml`\n\nuses lib.internal     // ✗ not in `exports`\n\nuses lib.notify       // ✓ an exported unit",
3116    },
3117    Explain {
3118        code: "bynk.package.unknown_unit",
3119        blurb: "A dependency is reached as `alias.unit`, where the unit is a commons or adapter the package declares. A name after the alias that matches none of them is refused, most often because it is misspelt. The diagnostic's note lists the units the package shares. A unit that exists but is not exported is `bynk.package.unit_not_exported`.",
3120        example: "commons notify          // in the package `acme/lib`\n\nuses lib.notifiy      // ✗ the package declares no `notifiy`\n\nuses lib.notify       // ✓",
3121    },
3122    Explain {
3123        code: "bynk.package.unsupported_in_dependency",
3124        blurb: "A dependency may not declare an `asset` or an `embed`, because the path would be resolved against the project that consumes it, whose `assets/` or `embeds/` folder is not the package's. Move the file into your own project, and have the package take its content as an argument.",
3125        example: "commons board                           // in the package `acme/lib`\n\nasset style = \"assets/board.css\"        // ✗ a dependency cannot declare one\nfn sheet() -> String { style.url }\n\ncommons board\n\nfn sheet(url: String) -> String { url } // ✓ the project supplies the URL",
3126    },
3127    Explain {
3128        code: "bynk.par.invalid_statement",
3129        blurb: "A `par { … }` block issues all its bindings together and waits for them, so it holds only `let x <- e` and `do e`. Anything else has no effect to overlap, nothing to join, or must stay in order: a plain `let`, `:=` or a `store` write, `expect`, `advance`, a nested `par`, a `let … else`, a bare expression (write `do e`) and an empty block. Store writes stay sequential; for `parTraverse` closures the rule is `bynk.par.store_write_in_closure`. Move the statement before or after the block; the names a block binds are in scope after its closing brace. See also `bynk.par.sibling_name` (a binding reading another binding of the same block) and the warning `bynk.par.single_binding`.",
3130        example: "par {\n  let a <- Users.get(id)\n  let b = 1   // ✗ a plain `let` has no effect to overlap\n}\n\nlet b = 1   // ✓ compute it before the block\npar {\n  let a <- Users.get(id)\n  let c <- Users.get(b)\n}",
3131    },
3132    Explain {
3133        code: "bynk.par.question_in_join",
3134        blurb: "The bindings of a `par` block are issued together and the block waits for all of them, so a `?` inside one has no single place to return from. Bind each effect's `Result` in the block and apply `?` after it, where the lines run in source order and the first `Err` propagates. A `?` on an argument can be computed before the block instead.",
3135        example: "par {\n    let a <- Users.find(1)\n    let b <- Orders.forUser(parse(raw)?)   // ✗ `?` inside the block\n}\n\nlet key = parse(raw)?                      // ✓ unwrap it before the block\npar {\n    let a <- Users.find(1)\n    let b <- Orders.forUser(key)\n}",
3136    },
3137    Explain {
3138        code: "bynk.par.sibling_name",
3139        blurb: "The bindings in a `par { … }` block run together, so none can read the result of another: there is no order in which one could be given the other's value. A binding that mentions a name a sibling binds is refused, even where an outer binding of that name exists, so a stale value is never picked up silently. Binding one name twice in a block is refused as well, since later code could not tell which result is meant. Move the dependent binding after the block, where every name is in scope, or rename.",
3140        example: "par {\n    let a <- Effect.pure(1)\n    let b <- Effect.pure(a + 1)   // ✗ `a` is bound by a sibling\n}\n\npar {\n    let a <- Effect.pure(1)\n    let c <- Effect.pure(2)\n}\nlet b <- Effect.pure(a + 1)   // ✓ after the block, `a` is in scope",
3141    },
3142    Explain {
3143        code: "bynk.par.store_write_in_closure",
3144        blurb: "The closure given to `parForEach`, `parTraverse`, `parTraverseAll` or `parTraverseTry` runs \
3145                once per element, all at once, so it may not write a `store` field, which is \
3146                the rule a `par { … }` block already follows. Every `<-` is an await point, \
3147                so a `get` then a `put` in the closure lets the other branches write in \
3148                between, and their updates are lost. A single call such as `update` is atomic \
3149                per key, but it is refused here too, so the two rules stay equal. Run the \
3150                loop with `forEach` (or `traverseAll` / `traverseTry`), where each element \
3151                finishes before the next starts, so a single-call `update` stays atomic. A store \
3152                write reads the entry before it stages the write, so the sequential form \
3153                reads one entry at a time; per-key atomicity is the reason for the rule. To \
3154                keep the concurrent part, collect with `parTraverseAll` and write afterwards.",
3155        example: "xs.parForEach((x: Int) => {\n  let o <- counts.get(\"k\")\n  counts.put(\"k\", o.getOrElse(0) + 1)   // ✗ two increments of three are lost\n})\n\n\
3156                  xs.forEach((x: Int) => counts.update(\"k\", (v) => v + 1))   // ✓ sequential and atomic per key",
3157    },
3158    Explain {
3159        code: "bynk.parse.bare_expression_statement",
3160        blurb: "A block has no expression statements: each statement is a `let`, `do`, \
3161                `expect`, `:=` and so on, and the last expression is the block's \
3162                value. An expression written on its own line with more of the block after \
3163                it would have its value thrown away, so the compiler asks you to say what \
3164                happens to it. Bind it: `let _ = expr` when you only want to discard a \
3165                value, or `let _ <- expr` when it is an effect to run and await (a call \
3166                through a capability or an agent, or a cell's `.update`). The parser \
3167                cannot see types, so it picks the `<-` form for a call that looks like an \
3168                effect and the `=` form otherwise, and its note names the other. The fix \
3169                is machine-applicable, so `bynk check --fix` applies it.",
3170        example: "on call bump() -> Effect[Result[Int, String]] {\n    \
3171                    count.update((c) => c + 1)            // ✗ an expression standing alone\n    \
3172                    Ok(count)\n}\n\n\
3173                  on call bump() -> Effect[Result[Int, String]] {\n    \
3174                    let _ <- count.update((c) => c + 1)   // ✓ the effect is bound\n    \
3175                    Ok(count)\n}\n\n\
3176                  let _ = a + b                           // ✓ a plain value you mean to discard",
3177    },
3178    Explain {
3179        code: "bynk.parse.clause_after_statement",
3180        blurb: "A `stub` or `env` clause sets up the world a test case runs in, \
3181                so it comes at the start of the case body, before any statement. \
3182                One after a `let` or other statement is refused, so the setup \
3183                reads in one place above the steps that depend on it. Move the \
3184                clause above the first statement of the case.",
3185        example: "suite demo {\n\
3186                  \x20\x20case \"x\" {\n\
3187                  \x20\x20\x20\x20let k = 1\n\
3188                  \x20\x20\x20\x20stub Clock.now() returns 0       // ✗ after a statement\n\
3189                  \x20\x20\x20\x20let t <- probe.call()\n\
3190                  \x20\x20\x20\x20expect t == 0\n\
3191                  \x20\x20}\n\
3192                  }\n\
3193                  \n\
3194                  suite demo {\n\
3195                  \x20\x20case \"x\" {\n\
3196                  \x20\x20\x20\x20stub Clock.now() returns 0       // ✓ before the statements\n\
3197                  \x20\x20\x20\x20let k = 1\n\
3198                  \x20\x20\x20\x20let t <- probe.call()\n\
3199                  \x20\x20\x20\x20expect t == 0\n\
3200                  \x20\x20}\n\
3201                  }",
3202    },
3203    Explain {
3204        code: "bynk.parse.const_missing_type",
3205        blurb: "A `const` always states its type: `const Limit: Int = 100`. A \
3206                constant is part of its unit's interface, so a reader, or a unit \
3207                that `uses` it, can see its type without inferring it from the \
3208                initialiser. Write the type after the name, before the `=`.",
3209        example: "const Limit = 100          // ✗ no type annotation\n\
3210                  const Limit: Int = 100     // ✓",
3211    },
3212    Explain {
3213        code: "bynk.parse.consumes_after_decls",
3214        blurb: "In the fragment form of a `context` (the header with no braces), \
3215                the `consumes` clauses come straight after the `uses` lines, \
3216                before any `type` or `fn`, so a unit's dependencies are all \
3217                stated at the top. Move the `consumes` line up. `uses` and \
3218                `exports` follow the same rule, as `bynk.parse.uses_after_decls` \
3219                and `bynk.parse.exports_after_decls`.",
3220        example: "context shop.orders\n\
3221                  type Id = String\n\
3222                  consumes shop.payment            // ✗ a declaration comes first\n\
3223                  \n\
3224                  context shop.orders\n\
3225                  consumes shop.payment            // ✓ clauses straight after the header\n\
3226                  type Id = String",
3227    },
3228    Explain {
3229        code: "bynk.parse.dangling_handler_annotation",
3230        blurb: "A handler annotation, such as `@cache(maxAge: 5.minutes)`, \
3231                applies to the handler after it, so it must sit directly above \
3232                an `on`. Here something else, or the end of the service, follows \
3233                it. Move the annotation to just above its handler.",
3234        example: "service api from http {\n\
3235                  \x20\x20\x20\x20on GET(\"/rows\") () -> Effect[HttpResult[List[Row]]] by v: Visitor { … }\n\
3236                  \x20\x20\x20\x20@cache(maxAge: 5.minutes)\n\
3237                  }                                  // ✗ the annotation has no handler to apply to\n\
3238                  \n\
3239                  service api from http {\n\
3240                  \x20\x20\x20\x20@cache(maxAge: 5.minutes)      // ✓ directly above its handler\n\
3241                  \x20\x20\x20\x20on GET(\"/rows\") () -> Effect[HttpResult[List[Row]]] by v: Visitor { … }\n\
3242                  }",
3243    },
3244    Explain {
3245        code: "bynk.parse.doc_block_contains_code",
3246        blurb: "A line of three or more dashes opens or closes a documentation \
3247                block, so two dash lines turn the code between them into \
3248                documentation, and it is never compiled. Use a line comment for a \
3249                divider. To show code in a documentation block, put it in a \
3250                Markdown code fence.",
3251        example: "--------                             // ✗ opens a doc block, not a divider\n\
3252                  fn double(n: Int) -> Int { n * 2 }\n\
3253                  --------\n\
3254                  fn triple(n: Int) -> Int { n * 3 }\n\n\
3255                  ---\n\
3256                  Doubles a number.                    // ✓ a doc block holds prose\n\
3257                  ---\n\
3258                  fn double(n: Int) -> Int { n * 2 }",
3259    },
3260    Explain {
3261        code: "bynk.parse.duplicate_cors",
3262        blurb: "A service has one CORS policy, and it applies to every route in it. Two `cors` blocks could grant different things, and the reader would not know which holds, so the second is refused. Merge them into one. `security` and `limits` follow the same rule (`bynk.parse.duplicate_security`, `bynk.parse.duplicate_limits`), as does `json` (`bynk.parse.duplicate_json`).",
3263        example: "service api from http {\n    cors { origins: [\"https://a.example\"] }\n    cors { origins: [\"https://b.example\"] }          // ✗ a second `cors`\n    on GET(\"/a\") () -> Effect[HttpResult[Int]] by Visitor { … }\n}\n\nservice api from http {\n    cors { origins: [\"https://a.example\", \"https://b.example\"] }   // ✓ one policy\n    on GET(\"/a\") () -> Effect[HttpResult[Int]] by Visitor { … }\n}",
3264    },
3265    Explain {
3266        code: "bynk.parse.duplicate_json",
3267        blurb: "A service's `json` policy sets whether its response bodies use plain or tagged JSON, so there is one setting for the whole service. A second block would contradict the first, and is refused. Keep one. A single route can still differ with `@json` on its handler. The same rule holds for `cors`, `security` and `limits`, as `bynk.parse.duplicate_cors` shows.",
3268        example: "service api from http {\n    json { options: plain }\n    json { options: tagged }                         // ✗ a second `json`\n    on GET(\"/a\") () -> Effect[HttpResult[Int]] by Visitor { … }\n}\n\nservice api from http {\n    json { options: plain }                          // ✓ one setting\n    on GET(\"/a\") () -> Effect[HttpResult[Int]] by Visitor { … }\n}",
3269    },
3270    Explain {
3271        code: "bynk.parse.duplicate_limits",
3272        blurb: "A service has one `limits` policy, and it sets the body-size cap for its body-taking routes. Two blocks could name different caps, and the reader would not know which holds, so the second is refused. Merge them into one, keeping the cap you mean. A single route can still differ with `@limit` on its handler. `cors`, `security` and `json` follow the same rule (`bynk.parse.duplicate_cors`, `bynk.parse.duplicate_security`, `bynk.parse.duplicate_json`).",
3273        example: "service api from http {\n    limits { maxBody: 1_048_576 }\n    limits { maxBody: 4_194_304 }                    // ✗ a second `limits`\n    on POST(\"/a\") (body: Int) -> Effect[HttpResult[Int]] by Visitor { … }\n}\n\nservice api from http {\n    limits { maxBody: 4_194_304 }                    // ✓ one cap\n    on POST(\"/a\") (body: Int) -> Effect[HttpResult[Int]] by Visitor { … }\n}",
3274    },
3275    Explain {
3276        code: "bynk.parse.duplicate_security",
3277        blurb: "A service has one `security` policy, and it sets the security headers (`hsts`, `nosniff`) stamped on every response. Two blocks could set them differently, and the reader would not know which holds, so the second is refused. Merge them into one. `cors`, `limits` and `json` follow the same rule (`bynk.parse.duplicate_cors`, `bynk.parse.duplicate_limits`, `bynk.parse.duplicate_json`).",
3278        example: "service api from http {\n    security { hsts: 180.days }\n    security { nosniff: true }                       // ✗ a second `security`\n    on GET(\"/a\") () -> Effect[HttpResult[Int]] by Visitor { … }\n}\n\nservice api from http {\n    security { hsts: 180.days, nosniff: true }       // ✓ one policy\n    on GET(\"/a\") () -> Effect[HttpResult[Int]] by Visitor { … }\n}",
3279    },
3280    Explain {
3281        code: "bynk.parse.empty_agent",
3282        blurb: "An agent is its storage and the `on call` handlers that read and \
3283                change it. One with no handler can never be called, so it is \
3284                refused, as is one with no `store` field \
3285                (`bynk.parse.expected_agent_storage`). Add a handler.",
3286        example: "agent Tally {                                              // ✗ no handler\n\
3287                  \x20\x20\x20\x20key id: String\n\
3288                  \x20\x20\x20\x20store count: Cell[Int]\n\
3289                  }\n\
3290                  \n\
3291                  agent Tally {\n\
3292                  \x20\x20\x20\x20key id: String\n\
3293                  \x20\x20\x20\x20store count: Cell[Int]\n\
3294                  \n\
3295                  \x20\x20\x20\x20on call get() -> Effect[Result[Int, String]] {         // ✓\n\
3296                  \x20\x20\x20\x20\x20\x20\x20\x20Ok(count)\n\
3297                  \x20\x20\x20\x20}\n\
3298                  }",
3299    },
3300    Explain {
3301        code: "bynk.parse.empty_capability",
3302        blurb: "A capability is a set of operations that a unit asks for with \
3303                `given` and that a provider supplies. With no operations there \
3304                is nothing to call or to provide, so an empty one is refused. \
3305                Declare at least one operation, or remove the capability.",
3306        example: "capability Clock {                 // ✗ no operations\n\
3307                  }\n\
3308                  \n\
3309                  capability Clock {\n\
3310                  \x20\x20\x20\x20fn now() -> Effect[Int]        // ✓\n\
3311                  }",
3312    },
3313    Explain {
3314        code: "bynk.parse.empty_interpolation",
3315        blurb: "An interpolation hole, `\\(…)`, holds one expression, whose \
3316                value is written into the text. An empty `\\()` has nothing to \
3317                write. Put an expression in the hole. To write the characters \
3318                `\\(` themselves, escape the backslash: `\\\\(`.",
3319        example: "fn label(n: Int) -> String {\n\
3320                  \x20\x20\x20\x20\"total: \\()\"                   // ✗ nothing to interpolate\n\
3321                  }\n\
3322                  \n\
3323                  fn label(n: Int) -> String {\n\
3324                  \x20\x20\x20\x20\"total: \\(n)\"                  // ✓\n\
3325                  }",
3326    },
3327    Explain {
3328        code: "bynk.parse.empty_match",
3329        blurb: "A `match`, or the `else match` of a `let … else`, must have at \
3330                least one arm. Each arm gives the match a value, so one with no \
3331                arms has none to give. Write an arm for each shape the value can \
3332                take; a final `_ =>` arm takes whatever the others leave.",
3333        example: "match xs {           // ✗ no arms\n\
3334                  }\n\n\
3335                  match xs {\n    \
3336                  [x, ..] => x      // ✓ one arm for each shape\n    \
3337                  [] => 0\n\
3338                  }",
3339    },
3340    Explain {
3341        code: "bynk.parse.empty_service",
3342        blurb: "A service is its handlers, so one with none can never be called \
3343                or triggered, and is refused. (A service that subscribes to \
3344                `Events` takes exactly one `on event`.) Add a handler, or remove \
3345                the service.",
3346        example: "service orders {                   // ✗ no handler\n\
3347                  }\n\
3348                  \n\
3349                  service orders {\n\
3350                  \x20\x20\x20\x20on call() -> Effect[Int] by Caller {     // ✓\n\
3351                  \x20\x20\x20\x20\x20\x20\x20\x20Effect.pure(0)\n\
3352                  \x20\x20\x20\x20}\n\
3353                  }",
3354    },
3355    Explain {
3356        code: "bynk.parse.event_pattern_empty",
3357        blurb: "A pattern in `from Events(E { … })` narrows delivery to events whose fields match, so it must name at least one field to match on. An empty `E {}` filters nothing and only looks as if it does. For every event of the type, drop the braces: `from Events(E)`.",
3358        example: "service OnPaid from Events(Paid {}) {         // ✗ a pattern with no fields\n    on event(e: Paid) -> Effect[()] { … }\n}\n\nservice OnPaid from Events(Paid) {            // ✓ every `Paid`\n    on event(e: Paid) -> Effect[()] { … }\n}",
3359    },
3360    Explain {
3361        code: "bynk.parse.expected_agent_key",
3362        blurb: "An agent is addressed by its key, so the key is the first thing in its body: `key id: Type`. Anything else there, usually a `store` field written first, is refused, so that how an agent is found is the first thing a reader sees. Move the `key` line to the top.",
3363        example: "agent Counter {\n    store n: Cell[Int]                   // ✗ the key comes first\n    key id: String\n\n    on call get() -> Effect[Int] { … }\n}\n\nagent Counter {\n    key id: String                       // ✓\n    store n: Cell[Int]\n\n    on call get() -> Effect[Int] { … }\n}",
3364    },
3365    Explain {
3366        code: "bynk.parse.expected_agent_storage",
3367        blurb: "An agent exists to hold state, and its state is its `store` fields, so one with none is refused. Declare at least one. A `store` field has a kind such as `Cell`, `Map` or `Set`. An agent with storage but no handler is `bynk.parse.empty_agent`.",
3368        example: "agent Counter {                          // ✗ no `store` field\n    key id: String\n\n    on call get() -> Effect[Int] { … }\n}\n\nagent Counter {\n    key id: String\n    store n: Cell[Int]                   // ✓\n\n    on call get() -> Effect[Int] { … }\n}",
3369    },
3370    Explain {
3371        code: "bynk.parse.expected_base_type",
3372        blurb: "After `type Name =` the parser found something that is not a record `{ … }`, a sum starting with `|`, an `enum` or an `opaque` type, so it wanted a base type (`Int`, `String`, `Bool`, `Float`, `Duration`, `Instant`, `Bytes` or `Decimal`) to build on. The commonest cause is a sum written without its leading `|`. Another is naming an existing record or sum, as in `type Id = Order`, which a type declaration cannot do; for a distinct type, use `opaque` over a base type. The position is the first token after the `=`.",
3373        example: "type Shape = Circle | Square              // ✗ a sum starts with `|`\ntype Shape = | Circle | Square            // ✓",
3374    },
3375    Explain {
3376        code: "bynk.parse.expected_capability_op",
3377        blurb: "A capability body is a list of operations, each a signature that starts with `fn`: the capability says what can be done, and a provider supplies how. The parser found something else where the next operation should begin. The commonest cause is leaving off the `fn`. An `on` handler, a `type` or a `let` does not belong in a capability either. The message names the token it found, and the position is where the operation should have started. A provider body has the same rule: `bynk.parse.expected_provider_op`.",
3378        example: "capability Clock {\n    now() -> Effect[Int]                  // ✗ an operation starts with `fn`\n}\n\ncapability Clock {\n    fn now() -> Effect[Int]               // ✓\n}",
3379    },
3380    Explain {
3381        code: "bynk.parse.expected_expression",
3382        blurb: "The parser needed an expression, a value, and found a token that cannot start one. The commonest cause is a record written without its type: `{ x: 0 }` is not an expression, so write `Point { x: 0 }`. Others are an operator with nothing after it (`a +`) and a trailing comma in a call (`f(a, )`). The message names the token it found, where the parser gave up. For an operator or a comma with nothing after it that is the token after the mistake, so read what comes before it.",
3383        example: "type Point = { x: Int, y: Int }\n\nfn origin() -> Point {\n    { x: 0, y: 0 }                        // ✗ a record literal needs its type's name\n}\n\nfn origin() -> Point {\n    Point { x: 0, y: 0 }                  // ✓\n}",
3384    },
3385    Explain {
3386        code: "bynk.parse.expected_handler",
3387        blurb: "A service or agent body is its handlers, each starting with `on`, beside its own clauses (a service's policies, an agent's `key` and `store` fields). The parser found something else where a handler should begin. The commonest cause is a helper `fn`, or a `let`, written inside the body: declare a helper beside the service, in the context, and its handlers can call it. Another is a handler with its `on` left off (`GET(\"/a\") …`, `call get() …`). The position is the first token of the item that is not a handler.",
3388        example: "service api from http {\n    fn double(n: Int) -> Int { n * 2 }    // ✗ only handlers go in a service\n    on GET(\"/a\") () -> Effect[HttpResult[Int]] by Visitor { … }\n}\n\nfn double(n: Int) -> Int { n * 2 }        // ✓ beside the service\n\nservice api from http {\n    on GET(\"/a\") () -> Effect[HttpResult[Int]] by Visitor { … }\n}",
3389    },
3390    Explain {
3391        code: "bynk.parse.expected_item",
3392        blurb: "A unit's body is a list of declarations, and the parser found something else where the next one should begin. The message lists what this kind of unit accepts (a commons, a context and a suite differ). The commonest cause is code at the top level, which holds declarations only: a `let` outside any function (a constant is `const Name: Type = …`) or a call. Others are a misspelt keyword (`function`, `pub fn`) and a stray `}` after a fragment-form unit's last declaration. The position is that token, so look just before it too.",
3393        example: "let limit = 100                           // ✗ code at the top level of a unit\nconst Limit: Int = 100                    // ✓ a named constant",
3394    },
3395    Explain {
3396        code: "bynk.parse.expected_predicate",
3397        blurb: "After `where`, and after each `&&`, a refinement takes the name of a predicate from a fixed list (`NonNegative`, `InRange(0, 150)` and so on, which the note gives), not a comparison. The list is closed, so the compiler can check a literal against the refinement at compile time. The commonest cause is a comparison such as `where >= 0`; a name that is not on the list, as in `where n > 0`, is `bynk.parse.unknown_predicate`. The position is the token that is not a predicate name.",
3398        example: "type Age = Int where >= 0                 // ✗ a predicate is a name, not a comparison\ntype Age = Int where NonNegative          // ✓",
3399    },
3400    Explain {
3401        code: "bynk.parse.expected_provider_op",
3402        blurb: "A provider body implements the operations its capability declares, each starting with `fn` and carrying a body. The parser found something else where the next operation should begin. The commonest cause is leaving off the `fn`; an `on` handler, a `type` or a `let` does not belong in a provider either. The message names the token it found, and the position is where the operation should have started. A capability body has the same rule: `bynk.parse.expected_capability_op`.",
3403        example: "capability Clock {\n    fn now() -> Effect[Int]\n}\n\nprovides Clock = FixedClock {\n    now() -> Effect[Int] { Effect.pure(1) }       // ✗ an operation starts with `fn`\n}\n\nprovides Clock = FixedClock {\n    fn now() -> Effect[Int] { Effect.pure(1) }    // ✓\n}",
3404    },
3405    Explain {
3406        code: "bynk.parse.expected_token",
3407        blurb: "The parser was part-way through a construct and the next token had to be one particular token: a `)` closing a list, a `,` between items, a `:`, `=`, `->` or `=>`, or a `}`. The message says which, and what it found instead. The commonest cause is a missing comma: in `fn add(a: Int b: Int)` it finds `b` where `)` was due. Others are `->` for `=>` in a match arm and `:` for `->` before a return type. A missing `)` or `}` is reported at the next token that cannot continue, often on the line below, so read the line above. If the file ended instead, it is `bynk.parse.unexpected_eof`.",
3408        example: "fn add(a: Int b: Int) -> Int { a + b }    // ✗ no `,` between the parameters\nfn add(a: Int, b: Int) -> Int { a + b }   // ✓",
3409    },
3410    Explain {
3411        code: "bynk.parse.expected_type",
3412        blurb: "A type was expected here, and the next token cannot start one. The message says which position wanted it (`as the return type`, `as the parameter type`). The commonest cause is a type left out: a `->` with nothing before the `{`, or a `:` with nothing after it. A trailing comma in a type-argument list (`Map[String, ]`) and a value where a type belongs (`n: 5`) land here too. The position is the token after the gap, so look just before it.",
3413        example: "fn double(n: Int) -> {                    // ✗ no return type after `->`\n    n * 2\n}\n\nfn double(n: Int) -> Int {                // ✓\n    n * 2\n}",
3414    },
3415    Explain {
3416        code: "bynk.parse.expected_visibility",
3417        blurb: "An `exports` clause says how consumers may use what it lists, so it needs a visibility: `exports opaque { … }` keeps a type's shape private to its context, `exports transparent { … }` shows it, and `exports capability { … }` offers a capability. A bare `exports { … }` is refused: the choice decides what other units can rely on, so it is written out. Pick one.",
3418        example: "exports { P }                           // ✗ no visibility\n\nexports transparent { P }               // ✓",
3419    },
3420    Explain {
3421        code: "bynk.parse.exports_after_decls",
3422        blurb: "In the fragment form of a `context` (the header with no braces), \
3423                the `exports` clauses come after the `uses` and `consumes` lines \
3424                and before any `type` or `fn`, so what a unit offers is stated \
3425                at the top. Move the `exports` line up. `uses` and `consumes` \
3426                follow the same rule, as `bynk.parse.uses_after_decls` and \
3427                `bynk.parse.consumes_after_decls`.",
3428        example: "context shop.orders\n\
3429                  type Id = String\n\
3430                  exports transparent { Id }       // ✗ a declaration comes first\n\
3431                  \n\
3432                  context shop.orders\n\
3433                  exports transparent { Id }       // ✓ clauses straight after the header\n\
3434                  type Id = String",
3435    },
3436    Explain {
3437        code: "bynk.parse.extra_tokens",
3438        blurb: "A `.bynk` file holds one `commons` or `context`, and the parser found more after it ended. The commonest cause is a `}` too many: the unit closed early, or an extra brace sits at the end, and the first token after the close is reported, either the stray brace or the next declaration. Count the braces back from there. The other is a second `commons` or `context` in the same file; each goes in its own file. The position is the first token after the unit's end, not the brace that ended it. Inside a string, an interpolation `\\(…)` holds a single expression, and a second token in it lands here too.",
3439        example: "commons demo {\n    fn one() -> Int { 1 }\n}\n}                                         // ✗ nothing can follow the unit\n\ncommons demo {\n    fn one() -> Int { 1 }\n}                                         // ✓ the unit closes once",
3440    },
3441    Explain {
3442        code: "bynk.parse.generic_arg_count",
3443        blurb: "`Result` takes two type arguments, the success type and the \
3444                error type: `Result[T, E]`. `Map` takes two as well, `Map[K, \
3445                V]`, and a type applied to an empty `[]` needs at least one. A \
3446                `Result[Int]` leaves out the error a caller has to handle, so it \
3447                is refused rather than guessed. Give every argument.",
3448        example: "fn parse(s: String) -> Result[Int] {            // ✗ the error type is missing\n\
3449                  \x20\x20\x20\x20Ok(1)\n\
3450                  }\n\
3451                  \n\
3452                  fn parse(s: String) -> Result[Int, String] {    // ✓\n\
3453                  \x20\x20\x20\x20Ok(1)\n\
3454                  }",
3455    },
3456    Explain {
3457        code: "bynk.parse.handler_in_agent",
3458        blurb: "An `agent` has only `on call` handlers. HTTP routes (`on GET`, `on \
3459                POST`, …), schedules and queue messages belong on a `service`, \
3460                which receives the request or event and calls the agent. Move the \
3461                protocol handler to a service and give the agent an `on call` \
3462                operation for it to call.",
3463        example: "agent Tally {\n    \
3464                  key id: String\n    \
3465                  store count: Cell[Int]\n\n    \
3466                  on GET(\"/count\") () -> Effect[Result[Int, String]] {   // ✗ a route is a service's\n        \
3467                  Ok(count)\n    \
3468                  }\n\
3469                  }\n\n\
3470                  agent Tally {\n    \
3471                  key id: String\n    \
3472                  store count: Cell[Int]\n\n    \
3473                  on call get() -> Effect[Result[Int, String]] {         // ✓ the agent's own operation\n        \
3474                  Ok(count)\n    \
3475                  }\n\
3476                  }",
3477    },
3478    Explain {
3479        code: "bynk.parse.invariant_after_handler",
3480        blurb: "An agent's declarations come in phases: `store` fields, then \
3481                `invariant`s, then `on` handlers. An invariant after a handler \
3482                is refused, so that every property the handlers must preserve \
3483                sits together above them. Move the invariant above the first \
3484                handler.",
3485        example: "agent Tally {\n\
3486                  \x20\x20\x20\x20key id: String\n\
3487                  \x20\x20\x20\x20store count: Cell[Int]\n\
3488                  \n\
3489                  \x20\x20\x20\x20on call get() -> Effect[Result[Int, String]] {\n\
3490                  \x20\x20\x20\x20\x20\x20\x20\x20Ok(count)\n\
3491                  \x20\x20\x20\x20}\n\
3492                  \n\
3493                  \x20\x20\x20\x20invariant nonNegative: count >= 0                // ✗ after a handler\n\
3494                  }\n\
3495                  \n\
3496                  agent Tally {\n\
3497                  \x20\x20\x20\x20key id: String\n\
3498                  \x20\x20\x20\x20store count: Cell[Int]\n\
3499                  \n\
3500                  \x20\x20\x20\x20invariant nonNegative: count >= 0                // ✓ before the handlers\n\
3501                  \n\
3502                  \x20\x20\x20\x20on call get() -> Effect[Result[Int, String]] {\n\
3503                  \x20\x20\x20\x20\x20\x20\x20\x20Ok(count)\n\
3504                  \x20\x20\x20\x20}\n\
3505                  }",
3506    },
3507    Explain {
3508        code: "bynk.parse.keyword_field_shorthand",
3509        blurb: "A record pattern or construction may write a field by name alone \
3510                (`{ total }`), which binds a variable of that name. A reserved \
3511                word cannot be a variable, so `{ type, .. }` is refused, though \
3512                `type` is allowed as a field label before a `:`. In a pattern, \
3513                name the binding: `type: type_`; the compiler offers that fix. In \
3514                a construction, give the value: `type: \"Org\"`.",
3515        example: "match a {\n    \
3516                  Account { type, .. } => type             // ✗ shorthand binds a keyword\n    \
3517                  Account { type: type_, .. } => type_     // ✓ name the binding\n\
3518                  }",
3519    },
3520    Explain {
3521        code: "bynk.parse.lambda_pattern_annotation",
3522        blurb: "A lambda parameter written as a record pattern already names its \
3523                type, in `Item { … }`, and its names take their types from that \
3524                record, so a `: Type` after the pattern is refused. Remove the \
3525                annotation; the fix is machine-applicable, so `bynk check --fix` \
3526                applies it.",
3527        example: "items.map((Item { qty, .. }: Item) => qty)    // ✗ the pattern names the type\n\
3528                  items.map((Item { qty, .. }) => qty)          // ✓",
3529    },
3530    Explain {
3531        code: "bynk.parse.lambda_pattern_not_record",
3532        blurb: "A lambda parameter may be a pattern only when it is a record \
3533                pattern that cannot fail, as in `(Item { qty, .. }) => qty`. A \
3534                lambda is given a value and has no `else`, so a pattern that can \
3535                miss, such as `Some(n)`, a list, a literal or a range, has no \
3536                way to say what happens then. Take a name and `match` on it in \
3537                the body.",
3538        example: "xs.map((Some(n)) => n)               // ✗ a lambda has no `else` for `None`\n\
3539                  \n\
3540                  xs.map((o) => match o {              // ✓ the `match` covers both\n\
3541                  \x20\x20\x20\x20Some(n) => n\n\
3542                  \x20\x20\x20\x20None => 0\n\
3543                  })",
3544    },
3545    Explain {
3546        code: "bynk.parse.lambda_pattern_refutable",
3547        blurb: "A lambda parameter pattern must match every value of its type, \
3548                because a lambda has no `else` for the rest. `Item { status: \
3549                Paid, qty, .. }` matches only some items. Use bare names, `f: \
3550                name` or `f: _`; the note names the first field that can fail. \
3551                To handle the other cases, take a name and `match` on it in the \
3552                body.",
3553        example: "items.map((Item { status: Paid, qty, .. }) => qty)   // ✗ not every item is `Paid`\n\
3554                  \n\
3555                  items.map((i) => match i.status {                    // ✓ every status is handled\n\
3556                  \x20\x20\x20\x20Paid => i.qty\n\
3557                  \x20\x20\x20\x20Pending => 0\n\
3558                  })",
3559    },
3560    Explain {
3561        code: "bynk.parse.let_else_on_binding",
3562        blurb: "`else` after a `let` says what the block does when the pattern \
3563                does not match. A plain name matches every value, so this `else` \
3564                could never run, and it is refused rather than ignored. To \
3565                handle a failure, bind a pattern that can fail: `Ok(x)`, \
3566                `Some(x)`, or a qualified variant such as `Status.Pending`. \
3567                Otherwise drop the `else`.",
3568        example: "fn count(r: Result[Int, String]) -> Int {\n\
3569                  \x20\x20\x20\x20let n = r else { 0 }              // ✗ a name always matches\n\
3570                  \x20\x20\x20\x20n\n\
3571                  }\n\
3572                  \n\
3573                  fn count(r: Result[Int, String]) -> Int {\n\
3574                  \x20\x20\x20\x20let Ok(n) = r else { 0 }          // ✓ an `Err` takes the `else`\n\
3575                  \x20\x20\x20\x20n\n\
3576                  }",
3577    },
3578    Explain {
3579        code: "bynk.parse.let_pattern_annotation",
3580        blurb: "A `let` that takes a value apart with a pattern gives its names \
3581                the types they have in the value, so it has no place for an \
3582                annotation after the pattern. Remove the `: Type`. To pin the \
3583                type of the value itself, annotate an ordinary `let` first and \
3584                match on that.",
3585        example: "fn count(r: Result[Int, String]) -> Int {\n\
3586                  \x20\x20\x20\x20let Ok(n): Int = r else { 0 }     // ✗ a pattern takes its types from the value\n\
3587                  \x20\x20\x20\x20n\n\
3588                  }\n\
3589                  \n\
3590                  fn count(r: Result[Int, String]) -> Int {\n\
3591                  \x20\x20\x20\x20let Ok(n) = r else { 0 }          // ✓\n\
3592                  \x20\x20\x20\x20n\n\
3593                  }",
3594    },
3595    Explain {
3596        code: "bynk.parse.let_pattern_without_else",
3597        blurb: "A `let` that takes a value apart with a pattern must say what the \
3598                block produces when the value does not match, so it needs an \
3599                `else`. Only a record pattern that cannot fail (every field a bare \
3600                name, `f: name` or `f: _`) may leave it out. Add `else { … }` \
3601                after the value, or write a `match`. The note names the first \
3602                field that can fail to match.",
3603        example: "fn head(xs: List[Int]) -> Int {\n    \
3604                  let [x, ..] = xs               // ✗ an empty list does not match\n    \
3605                  x\n\
3606                  }\n\n\
3607                  fn head(xs: List[Int]) -> Int {\n    \
3608                  let [x, ..] = xs else { 0 }    // ✓ says what an empty list gives\n    \
3609                  x\n\
3610                  }",
3611    },
3612    Explain {
3613        code: "bynk.parse.list_rest_not_last",
3614        blurb: "In a list pattern the `..` (or `..rest`) stands for the elements \
3615                the pattern does not name, and it must be the last element and \
3616                appear once. A pattern that matches the end of a list, such as \
3617                `[.., last]`, is not available, so match from the front. When only \
3618                `_` patterns follow the `..`, the error offers a \
3619                machine-applicable fix that moves it to the end.",
3620        example: "match xs {\n    \
3621                  [.., a, b] => b    // ✗ `..` must come last\n    \
3622                  [_, b, ..] => b    // ✓ match from the front\n    \
3623                  _ => 0\n\
3624                  }",
3625    },
3626    Explain {
3627        code: "bynk.parse.malformed_float_literal",
3628        blurb: "A `Float` literal has a digit on each side of the point, as in \
3629                `1.0` and `0.5`; `1.` and `.5` are refused. This keeps a method \
3630                call on a number, such as `1.toFloat()` or `2.5.round()`, \
3631                unambiguous. Write the missing digit; the note gives the \
3632                corrected literal.",
3633        example: "const Half: Float = .5     // ✗ no digit before the point\n\
3634                  const Half: Float = 0.5    // ✓",
3635    },
3636    Explain {
3637        code: "bynk.parse.match_ends_block",
3638        blurb: "A block has no expression statements, so a `match` is its final \
3639                value and nothing can follow it; a second `match` straight after \
3640                the first is refused. Bind the first with `let _ = match …`. If \
3641                the steps are fallible and each depends on the one before, `let … \
3642                else` flattens them without nesting.",
3643        example: "fn grade(a: Int, b: Int) -> Int {\n    \
3644                  match a { … }\n    \
3645                  match b { … }              // ✗ a `match` ends its block\n\
3646                  }\n\n\
3647                  fn grade(a: Int, b: Int) -> Int {\n    \
3648                  let _ = match a { … }      // ✓ bound, so the block goes on\n    \
3649                  match b { … }\n\
3650                  }",
3651    },
3652    Explain {
3653        code: "bynk.parse.migrate_after_handler",
3654        blurb: "A `migrate` step carries a stored record from an older schema version to the agent's current shape, so it belongs with the agent's storage and invariants, above the handlers that read the migrated state. One written after a handler is refused. Move it above the first handler. `bynk.parse.invariant_after_handler` and `bynk.parse.transition_after_handler` are the same rule for invariants and transitions.",
3655        example: "type CartV1 = { owner: String, total: Int }\n\nagent Cart {\n    key id: String\n    store ownerName: Cell[String]\n    store totalCents: Cell[Int]\n\n    on call cents() -> Effect[Int] { … }\n\n    migrate from 1 (old: CartV1) {            // ✗ after a handler\n        ownerName := old.owner\n        totalCents := old.total * 100\n    }\n}\n\nagent Cart {\n    key id: String\n    store ownerName: Cell[String]\n    store totalCents: Cell[Int]\n\n    migrate from 1 (old: CartV1) {            // ✓ before the handlers\n        ownerName := old.owner\n        totalCents := old.total * 100\n    }\n\n    on call cents() -> Effect[Int] { … }\n}",
3656    },
3657    Explain {
3658        code: "bynk.parse.migrate_item",
3659        blurb: "A `migrate` step carries a stored record from an older schema version to the agent's current shape, so its body is only a list of what happens to each field: `field := value` assigns a current field, `let x = value` binds a local for later lines, and `drop field` discards a stored field on purpose. A step is pure, so nothing else belongs in it. The commonest mistake is `=` where `:=` is meant; a bare expression lands here too. The position is the first token of the line that is none of the three.",
3660        example: "type CartV1 = { owner: String, total: Int }\n\nagent Cart {\n    key id: String\n    store ownerName: Cell[String]\n    store totalCents: Cell[Int]\n\n    migrate from 1 (old: CartV1) {\n        ownerName = old.owner                 // ✗ a step assigns with `:=`\n        totalCents := old.total * 100\n    }\n\n    on call cents() -> Effect[Int] { … }\n}\n\nagent Cart {\n    key id: String\n    store ownerName: Cell[String]\n    store totalCents: Cell[Int]\n\n    migrate from 1 (old: CartV1) {\n        ownerName := old.owner                // ✓\n        totalCents := old.total * 100\n    }\n\n    on call cents() -> Effect[Int] { … }\n}",
3661    },
3662    Explain {
3663        code: "bynk.parse.multiple_docs",
3664        blurb: "A declaration or member has one doc. Two doc lines in a row are \
3665                two docs, not one of two lines. For more than one line, write a \
3666                doc block: a `---` line, the text, and another `---` line. When \
3667                every doc is a one-line `--- text`, the fix that joins them into \
3668                a block is machine-applicable, so `bynk check --fix` applies it.",
3669        example: "--- Doubles a number.\n\
3670                  --- Used by the pricing code.          // ✗ a second doc\n\
3671                  fn double(n: Int) -> Int { n * 2 }\n\
3672                  \n\
3673                  ---                                    // ✓ one doc block\n\
3674                  Doubles a number.\n\
3675                  Used by the pricing code.\n\
3676                  ---\n\
3677                  fn double(n: Int) -> Int { n * 2 }",
3678    },
3679    Explain {
3680        code: "bynk.parse.no_remainder_operator",
3681        blurb: "Bynk has no `%` operator. Remainder is a method with its sign \
3682                spelled out: `a.rem(b)` takes the dividend's sign (the C, Java and \
3683                JavaScript `%`), `a.mod(b)` takes the divisor's (Python's `%`; use \
3684                it for a cyclic index). When both operands are plain names or \
3685                integer literals the error offers a `.rem` fix, never applied \
3686                automatically: check that the sign is the one you want.",
3687        example: "fn parity(n: Int) -> Int {\n    \
3688                  n % 2          // ✗ there is no `%`\n\
3689                  }\n\n\
3690                  fn parity(n: Int) -> Int {\n    \
3691                  n.rem(2)       // ✓ the dividend's sign, as `%` in C\n\
3692                  }\n\n\
3693                  fn slot(n: Int) -> Int {\n    \
3694                  n.mod(2)       // ✓ the divisor's sign, as `%` in Python\n\
3695                  }",
3696    },
3697    Explain {
3698        code: "bynk.parse.non_associative",
3699        blurb: "Comparisons (`<`, `<=`, `>`, `>=`) and equality tests (`==`, `!=`) \
3700                do not chain, so `a < b < c` is refused rather than given a \
3701                reading you may not have meant. Split a chain of comparisons with \
3702                `&&`; to test the result of an equality, parenthesise it: `(a == \
3703                b) == c`.",
3704        example: "fn ordered(a: Int, b: Int, c: Int) -> Bool {\n    \
3705                  a < b < c         // ✗ comparisons do not chain\n\
3706                  }\n\n\
3707                  fn ordered(a: Int, b: Int, c: Int) -> Bool {\n    \
3708                  a < b && b < c    // ✓ one comparison on each side of `&&`\n\
3709                  }",
3710    },
3711    Explain {
3712        code: "bynk.parse.policy_order",
3713        blurb: "A service's policies open its body, before any handler, in one fixed order: `cors`, `security`, `limits`, then `json`, each optional. One fixed layout means a reader always finds a service's cross-cutting rules at the top, and the formatter has a single form to write. A policy after a later one, or after a handler, is refused. Reorder them. A policy given twice is a separate error, such as `bynk.parse.duplicate_cors`.",
3714        example: "service api from http {\n    limits { maxBody: 1_048_576 }\n    cors { origins: [\"*\"] }               // ✗ `cors` comes before `limits`\n    on GET(\"/a\") () -> Effect[HttpResult[Int]] by Visitor { … }\n}\n\nservice api from http {\n    cors { origins: [\"*\"] }               // ✓ policies in order\n    limits { maxBody: 1_048_576 }\n    on GET(\"/a\") () -> Effect[HttpResult[Int]] by Visitor { … }\n}",
3715    },
3716    Explain {
3717        code: "bynk.parse.record_pattern_in_is_unparenthesised",
3718        blurb: "After `is`, a record pattern is written in parentheses. Bare, \
3719                the `{` that opens its fields could equally open the block of \
3720                the `if`, and the reader could not tell which. Write `x is (Type \
3721                { field, .. })`. The fix is machine-applicable, so `bynk check \
3722                --fix` applies it. A `match` arm needs no parentheses.",
3723        example: "fn isPaid(o: Order) -> Bool {\n\
3724                  \x20\x20\x20\x20if o is Order { status: Paid, .. } { true } else { false }       // ✗ `{` is ambiguous\n\
3725                  }\n\
3726                  \n\
3727                  fn isPaid(o: Order) -> Bool {\n\
3728                  \x20\x20\x20\x20if o is (Order { status: Paid, .. }) { true } else { false }     // ✓\n\
3729                  }",
3730    },
3731    Explain {
3732        code: "bynk.parse.record_pattern_without_rest",
3733        blurb: "Every record pattern ends with `..`. Record patterns are always open: they \
3734                name the fields they care about and ignore the rest, so adding a field \
3735                to the record later never breaks a pattern that was already written. \
3736                The `..` makes that openness visible at the pattern. The compiler offers \
3737                the fix: it adds `..` after the last field.",
3738        example: "match o {\n    Order { total } => total          // ✗ no trailing `..`\n}\n\n\
3739                  match o {\n    Order { total, .. } => total      // ✓ open: other fields ignored\n}",
3740    },
3741    Explain {
3742        code: "bynk.parse.refined_pattern_inner",
3743        blurb: "A `where` guard on a `match` arm is written on the wildcard, as \
3744                `_ where InRange(0, 100)`. In this version no other pattern can \
3745                carry one, a name included, so binding the matched value \
3746                together with a guard is not yet supported. Write `_ where …`, \
3747                and refer to the value by the name it already has.",
3748        example: "match n {\n\
3749                  \x20\x20\x20\x20n where InRange(0, 100) => 1      // ✗ only `_` can take a `where`\n\
3750                  \x20\x20\x20\x20_ => 0\n\
3751                  }\n\
3752                  \n\
3753                  match n {\n\
3754                  \x20\x20\x20\x20_ where InRange(0, 100) => 1      // ✓\n\
3755                  \x20\x20\x20\x20_ => 0\n\
3756                  }",
3757    },
3758    Explain {
3759        code: "bynk.parse.removed_send_arrow",
3760        blurb: "`~>` was removed. It started an effect and carried on without waiting, which `e.detach()` now says as an ordinary effect statement: it works for any `Effect[T]`, inside a lambda, `forEach` or helper, and reports a fault or an `Err` instead of losing it. Write `do e.detach()` where you wrote `~> e`. For a unit effect that does not need to outlive the handler, plain `do e` is enough, since `Logger` calls finish before they return. On v0.603.x, `bynk check --fix` rewrites each `~> e` for you. See the Book's Upgrading page.",
3761        example: "service api from http {\n    on GET(\"/\") () -> Effect[HttpResult[String]] by Visitor given Logger {\n        ~> Logger.info(\"served\")                    // ✗ removed\n        Ok(\"ok\")\n    }\n}\n\n\
3762                  service api from http {\n    on GET(\"/\") () -> Effect[HttpResult[String]] by Visitor given Logger {\n        do Logger.info(\"served\").detach()    // ✓ an ordinary statement\n        Ok(\"ok\")\n    }\n}",
3763    },
3764    Explain {
3765        code: "bynk.parse.reserved_keyword",
3766        blurb: "A hard keyword (`type`, `fn`, `match`, `Int` and so on) was \
3767                written where a name is expected: a parameter, a `let` binding, an \
3768                operation name. Hard keywords are reserved everywhere, so none can \
3769                be a name. Rename it. A keyword is still allowed as a field label \
3770                when a `:` follows it (`{ type: String }`); the shorthand without \
3771                the `:` is `bynk.parse.keyword_field_shorthand`.",
3772        example: "fn describe(type: String) -> String {   // ✗ `type` is a reserved word\n    \
3773                  type\n\
3774                  }\n\n\
3775                  fn describe(kind: String) -> String {   // ✓ any other name\n    \
3776                  kind\n\
3777                  }",
3778    },
3779    Explain {
3780        code: "bynk.parse.self_outside_method",
3781        blurb: "`self` is the receiver of a method, and only the first parameter \
3782                of a method declaration, written `fn Type.method(self, …)`, may be \
3783                named `self`. A free function has no receiver. Either name the \
3784                type the function belongs to, making it a method, or drop `self` \
3785                and take the value as an ordinary parameter.",
3786        example: "fn total(self) -> Int {          // ✗ a free function has no `self`\n    \
3787                  self.total\n\
3788                  }\n\n\
3789                  fn Order.total(self) -> Int {    // ✓ a method of `Order`\n    \
3790                  self.total\n\
3791                  }",
3792    },
3793    Explain {
3794        code: "bynk.parse.storage_after_phase",
3795        blurb: "An agent's body is ordered: its `key`, its storage fields (`state` and `store`), its invariants and migrations, then its handlers. Putting the fields first means the whole shape of the agent's persisted state is read before any code that uses it. A storage field declared after an invariant or a handler is refused. Move it up beside the other fields.",
3796        example: "agent Counter {\n    key id: String\n    store count: Cell[Int]\n\n    on call bump() -> Effect[()] { … }\n\n    store extra: Cell[Int] = 0            // ✗ storage after a handler\n}\n\nagent Counter {\n    key id: String\n    store count: Cell[Int]\n    store extra: Cell[Int] = 0            // ✓ with the other fields\n\n    on call bump() -> Effect[()] { … }\n}",
3797    },
3798    Explain {
3799        code: "bynk.parse.transition_after_handler",
3800        blurb: "A `transition` checks each committed step of an agent against the one before it, so it belongs with the agent's invariants, above the handlers whose steps it constrains. One written after a handler is refused. Move it above the first handler. `bynk.parse.invariant_after_handler` and `bynk.parse.migrate_after_handler` are the same rule for invariants and migrations.",
3801        example: "agent Counter {\n    key id: String\n    store n: Cell[Int]\n\n    on call get() -> Effect[Int] { … }\n\n    transition up:                        // ✗ after a handler\n        new.n >= old.n\n}\n\nagent Counter {\n    key id: String\n    store n: Cell[Int]\n\n    transition up:                        // ✓ before the handlers\n        new.n >= old.n\n\n    on call get() -> Effect[Int] { … }\n}",
3802    },
3803    Explain {
3804        code: "bynk.parse.unexpected_eof",
3805        blurb: "The file ended while the parser still needed something: usually a closing `}`, `)` or `]`, or an expression after an operator or a `,`. The message says what it expected, and the position is the end of the file. The commonest cause is a `}` missing at the end of a braced unit or function. A missing brace with further declarations after it is reported as `bynk.parse.expected_token`, at the next `fn` or `type`, so it may be well above the end: check the nesting from the last declaration you edited.",
3806        example: "commons demo {\n    fn one() -> Int { 1 }                 // ✗ the file ends with the unit still open\n\ncommons demo {\n    fn one() -> Int { 1 }\n}                                         // ✓ closed",
3807    },
3808    Explain {
3809        code: "bynk.parse.unknown_effect_method",
3810        blurb: "`Effect.pure(value)` is the only operation spelled on `Effect` \
3811                itself in an expression: it lifts a plain value into \
3812                `Effect[T]`. An effect otherwise comes from calling a handler or \
3813                a capability's operation. Use `Effect.pure`.",
3814        example: "fn lift(n: Int) -> Effect[Int] {\n\
3815                  \x20\x20\x20\x20Effect.of(n)                     // ✗ the only operation is `pure`\n\
3816                  }\n\
3817                  \n\
3818                  fn lift(n: Int) -> Effect[Int] {\n\
3819                  \x20\x20\x20\x20Effect.pure(n)                   // ✓\n\
3820                  }",
3821    },
3822    Explain {
3823        code: "bynk.parse.unknown_handler_kind",
3824        blurb: "A handler is `on` and a kind the compiler knows: `call`, an HTTP \
3825                method, `schedule`, `message` and the like. An HTTP method is \
3826                written in capitals, `GET`, `POST`, `PUT`, `PATCH` or `DELETE`, \
3827                so `on get(…)` is not a handler. Spell the kind as one of these.",
3828        example: "service api from http {\n\
3829                  \x20\x20\x20\x20on get(\"/rows\") () -> Effect[HttpResult[List[Row]]] by v: Visitor { … }   // ✗ methods are capitals\n\
3830                  }\n\
3831                  \n\
3832                  service api from http {\n\
3833                  \x20\x20\x20\x20on GET(\"/rows\") () -> Effect[HttpResult[List[Row]]] by v: Visitor { … }   // ✓\n\
3834                  }",
3835    },
3836    Explain {
3837        code: "bynk.parse.unknown_predicate",
3838        blurb: "A refined type is a base type plus a rule from a fixed set of \
3839                built-in predicates: `Matches`, `InRange`, `MinLength`, \
3840                `MaxLength`, `Length`, `NonNegative`, `Positive`, `NonEmpty` and \
3841                `IsoDate`. There are no user-defined predicates. Use one of these; \
3842                for a numeric range that is `InRange(lo, hi)`, inclusive at both \
3843                ends.",
3844        example: "type Age = Int where Between(0, 150)    // ✗ not a predicate\n\
3845                  type Age = Int where InRange(0, 150)    // ✓",
3846    },
3847    Explain {
3848        code: "bynk.parse.unknown_tier",
3849        blurb: "A test case's tier says how much of the program it runs against, and there are three: `unit`, `integration` and `system`. Any other name after `as` is refused, usually a misspelling. Leave the clause out for `unit`, the default.",
3850        example: "case \"doubles\" as weird {               // ✗ not a tier\n    expect double(2) == 4\n}\n\ncase \"doubles\" as unit {                // ✓\n    expect double(2) == 4\n}",
3851    },
3852    Explain {
3853        code: "bynk.parse.uses_after_decls",
3854        blurb: "In the fragment form of a `commons` or `context` (the header with \
3855                no braces), the `uses` clauses come straight after the header, \
3856                before any `type` or `fn`. Move the `uses` line up. `consumes` and \
3857                `exports` clauses follow the same rule, as \
3858                `bynk.parse.consumes_after_decls` and \
3859                `bynk.parse.exports_after_decls`: `consumes` after the `uses` \
3860                lines, `exports` after the `consumes` lines.",
3861        example: "commons demo\n\
3862                  type Id = String\n\
3863                  uses util              // ✗ a declaration comes first\n\n\
3864                  commons demo\n\
3865                  uses util              // ✓ clauses straight after the header\n\
3866                  type Id = String",
3867    },
3868    Explain {
3869        code: "bynk.parse.variant_name_case",
3870        blurb: "A variant of a sum type or enum is written like a constant: an \
3871                uppercase letter, then letters, digits or `_` (`Active`, \
3872                `NotFound`). A lowercase variant such as `suspended` is refused. \
3873                Capitalise the name.",
3874        example: "type Status =\n    \
3875                  | Active\n    \
3876                  | suspended   // ✗ a variant starts with a capital\n\n\
3877                  type Status =\n    \
3878                  | Active\n    \
3879                  | Suspended   // ✓",
3880    },
3881    Explain {
3882        code: "bynk.postgres.sql_invalid",
3883        blurb: "When the project has a `schema.sql` at its root, Bynk parses each literal SQL statement of a `Postgres` capability, so a syntax error shows up when you check, not on the first request. It also flags a statement of several commands, which a prepared statement does not accept: send each with its own call, or use `transaction`. The parser is a pure-Rust one with a Postgres dialect, not Postgres' own, so it can refuse valid SQL, a newer or rarer form; that is why this is a warning and never blocks a build. Nothing runs, and the statement is not checked against the schema, which Bynk does not own. Correct the statement, or delete `schema.sql` to turn the check off.",
3884        example: "let _ <- Main.all(\"SELEC id FROM orders\", [])        // ✗ expected a statement, found SELEC\n\nlet _ <- Main.all(\"SELECT id FROM orders\", [])      // ✓",
3885    },
3886    Explain {
3887        code: "bynk.postgres.sql_param_count",
3888        blurb: "When the project has a `schema.sql`, Bynk counts the parameters of each literal `Postgres` statement, by Postgres' rule: the highest `$n`, so `$2` alone still takes two values. It checks a list written out in place, or a name `let`-bound to one. A `$n` inside a string, a quoted name, a comment or a dollar-quoted body is text, not a parameter. Pass one `PgValue` for each, or change the SQL. A gap (`$2` with no `$1`) is counted as two parameters; Postgres refuses it at run time (it cannot type `$1`), which this check does not look for.",
3889        example: "let _ <- Main.all(\"SELECT id FROM orders WHERE id = $1 AND qty > $2\", [PgInteger(id)])                 // ✗ two parameters, one value\n\nlet _ <- Main.all(\"SELECT id FROM orders WHERE id = $1 AND qty > $2\", [PgInteger(id), PgInteger(5)])    // ✓",
3890    },
3891    Explain {
3892        code: "bynk.project.duplicate_module_doc",
3893        blurb: "A unit's module doc is one piece of prose. When a unit is split \
3894                across files, at most one of them may open with it: with two, the \
3895                tools would have to join them in some file order and the result \
3896                would read oddly. The error names every file that carries one. \
3897                Keep the doc in the file that best introduces the unit, and remove \
3898                the others.",
3899        example: "// text/case.bynk\n\
3900                  ---\n\
3901                  Text helpers.\n\
3902                  ---\n\
3903                  commons text\n\n\
3904                  // text/trim.bynk\n\
3905                  ---\n\
3906                  Trimming.\n\
3907                  ---\n\
3908                  commons text       // ✗ a second module doc\n\n\
3909                  commons text       // ✓ the doc stays in case.bynk",
3910    },
3911    Explain {
3912        code: "bynk.project.export_context",
3913        blurb: "A package's `exports` list names the commons and adapters it shares. A context is a deployment unit, owned by the project that deploys it, so a package never shares one, and listing one is refused. Remove it, or move what other projects need into a commons and list that. A name that is no unit of the package at all is `bynk.project.export_unknown`.",
3914        example: "[package]\nname = \"acme/shop\"\nexports = [\"shop.checkout\"]     // ✗ a context\n\nexports = [\"money\"]             // ✓ a commons",
3915    },
3916    Explain {
3917        code: "bynk.project.export_unknown",
3918        blurb: "A package's `[package] exports` lists the units it shares, by their qualified names, and each must be a `commons` or an adapter the package declares. A name that matches none is usually a typo, or a unit that has since been renamed or moved, and a consumer's `uses` of it would fail far from the cause. Correct the name, or remove the entry. Listing a context is `bynk.project.export_context`.",
3919        example: "[package]\nname = \"acme/shop\"\nexports = [\"mony\"]    // ✗ no unit `mony`\n\nexports = [\"money\"]   // ✓ the package's `commons money`",
3920    },
3921    Explain {
3922        code: "bynk.project.file_and_directory",
3923        blurb: "A unit's name comes from its path: `commons money` lives in `money.bynk`, or in the files of a directory `money/`. With both, the path no longer says where `money` lives, or which unit the directory's files belong to, so the project is refused. Keep one: move the file into the directory, or fold the directory into the file.",
3924        example: "src/money.bynk           // ✗ `money/` is a directory too\nsrc/money/rates.bynk\n\nsrc/money/core.bynk      // ✓ one directory, both files `commons money`\nsrc/money/rates.bynk",
3925    },
3926    Explain {
3927        code: "bynk.project.inconsistent_commons_name",
3928        blurb: "A source file's path is its unit's identity: `context \
3929                commerce.orders` lives at `commerce/orders.bynk`, or in a file \
3930                under `commerce/orders/`, relative to an include root. A reader \
3931                can then find a unit from its name alone. Rename the file or \
3932                directory to match the declared name, or change the name. Test \
3933                suites are exempt.",
3934        example: "// pricing.bynk\n\
3935                  commons tax     // ✗ the path says `pricing`\n\n\
3936                  // tax.bynk\n\
3937                  commons tax     // ✓",
3938    },
3939    Explain {
3940        code: "bynk.project.kind_conflict",
3941        blurb: "A name belongs to one unit, so every file declaring it must agree \
3942                on its kind. One file saying `commons shop` and another `context \
3943                shop` would make the name both a library and a deployable unit. \
3944                Give the files different names, or make them the same kind. A \
3945                context is the deployable unit, and a commons is the shared code \
3946                it uses.",
3947        example: "// shop/types.bynk\n\
3948                  commons shop        // ✗ the name is also a context\n\
3949                  commons shop.types  // ✓\n\n\
3950                  // shop/api.bynk\n\
3951                  context shop",
3952    },
3953    Explain {
3954        code: "bynk.project.no_sources",
3955        blurb: "A project compiles the `.bynk` files under its include roots: `src/` (and `tests/`) by default, or the trees that `[paths] include` names. Finding none means there is nothing to build, which almost always means the sources are somewhere the project does not look, or the command was pointed at the wrong directory. Hidden directories, `out/` and `node_modules/` are never searched. Point `[paths] include` at the sources, or run the command from the project's root.",
3956        example: "# the sources are in lib/, and src/ is empty\n[project]\nname = \"shop\"           // ✗ nothing under src/\n\n[paths]\ninclude = [\"lib\"]       // ✓",
3957    },
3958    Explain {
3959        code: "bynk.project.unstable_unknown_item",
3960        blurb: "`[unstable] allow` opts in to experimental standard-library items by path: a unit (`bynk.cloudflare`), an item it exports (`bynk.cloudflare.RateLimit`) or a capability operation (`bynk.cloudflare.Kv.list`). An entry that names nothing in the standard library allows nothing, and is usually a typo, which would leave the `bynk.stability.experimental` error it was meant to clear. Correct the path, or remove the entry. An entry for a real item that is no longer experimental is only a warning.",
3961        example: "[unstable]\nallow = [\"bynk.cloudflare.RateLimt\"]    // ✗ no such item\n\nallow = [\"bynk.cloudflare.RateLimit\"]   // ✓",
3962    },
3963    Explain {
3964        code: "bynk.property.restates_refinement",
3965        blurb: "A `for all q: Quantity` property draws only valid values of `Quantity`, so a body that just asserts the type's refinement, `expect q > 0` over `Int where Positive`, cannot fail and proves nothing about your code. The compiler flags it. The check is narrow: it fires only when the body is that one `expect`, restating `Positive` or `NonNegative` over the bound value, so a near-copy may pass. Assert something about what your code does with the value, or delete the property.",
3966        example: "// demo.bynk\ntype Quantity = Int where Positive\n\n// tests/demo.test.bynk\nfor all q: Quantity { expect q > 0 }            // ✗ the type already says this\nfor all q: Quantity { expect double(q) > q }    // ✓ a claim about `double`",
3967    },
3968    Explain {
3969        code: "bynk.property.where_not_bool",
3970        blurb: "A `where` clause on `for all` discards each generated input \
3971                that fails it, so it must be a `Bool`. A filter of another \
3972                type, such as an `Int`, cannot say whether to keep an input. \
3973                Write a comparison over the bound variables.",
3974        example: "for all n: Int where n + 1 {   // ✗ an `Int`, not a `Bool`\n\n\
3975                  for all n: Int where n > 0 {   // ✓",
3976    },
3977    Explain {
3978        code: "bynk.provider.agent_call_undeclared_capability",
3979        blurb: "A provider calls an agent handler, and the handler needs a capability \
3980                the provider's `given` does not list. A handler's `given` is \
3981                widened to cover the agent handlers it calls, but a provider's is \
3982                not. The provider is constructed with exactly the capabilities in \
3983                its `given`, and those are all it can hand on to the agent. So the \
3984                provider must list everything the agent handler needs: the \
3985                handler's own `given`, and the `given` of any agent handler it \
3986                calls in turn.",
3987        example: "agent Index {\n    \
3988                    key name: String\n    \
3989                    store hits: Cell[Int]\n    \
3990                    on call withdraw() -> Effect[()] given Files { … }\n}\n\n\
3991                  provides Takedown = Bucket given Clock {\n    \
3992                    fn take(name: String) -> Effect[()] { Index(name).withdraw() }   // ✗ `withdraw` needs `Files`\n}\n\n\
3993                  provides Takedown = Bucket given Clock, Files {  // ✓ `Files` is listed\n    \
3994                    fn take(name: String) -> Effect[()] { Index(name).withdraw() }\n}",
3995    },
3996    Explain {
3997        code: "bynk.provider.dependency_cycle",
3998        blurb: "A provider's `given` lists the capabilities it is built from, and the context builds providers in dependency order. A capability that depends on itself, directly or through other providers, has no order to be built in, so every provider on the cycle is reported. Break the cycle: remove a `given` one side does not really need, move the part both need into a third capability that each depends on, or merge the two if they are one thing. Dependencies on other contexts follow `consumes`, which has its own check, `bynk.context.consumes_cycle`.",
3999        example: "capability Clock {\n    fn now() -> Effect[Int]\n}\n\nprovides Clock = Fixed given Clock {   // ✗ `Clock` is built from itself\n    fn now() -> Effect[Int] { Effect.pure(0) }\n}\n\nprovides Clock = Fixed {               // ✓ built from nothing\n    fn now() -> Effect[Int] { Effect.pure(0) }\n}",
4000    },
4001    Explain {
4002        code: "bynk.provider.extra_operation",
4003        blurb: "A `provides` block offers the capability's operations and no others. Callers reach a provider only through the capability, so an operation it does not declare could never be called, and it usually means a misspelt name or an operation added to the wrong capability. Remove it, or declare it on the capability. A capability operation the provider omits is `bynk.provider.missing_operation`.",
4004        example: "capability Clock {\n    fn now() -> Effect[Int]\n}\n\nprovides Clock = Fixed {\n    fn now() -> Effect[Int] { Effect.pure(0) }\n    fn zone() -> Effect[String] { Effect.pure(\"UTC\") }   // ✗ `Clock` declares no `zone`\n}\n\ncapability Clock {\n    fn now() -> Effect[Int]\n    fn zone() -> Effect[String]  // ✓ declared on the capability\n}",
4005    },
4006    Explain {
4007        code: "bynk.provider.generic_op_requires_external",
4008        blurb: "A capability operation with its own type parameter, `fn dedup[T](…)`, can only be implemented by an external provider: a class written in TypeScript in an adapter's binding file. A provider with a Bynk body has no `T` to work with, so it could only return a value it was already given. Declare the capability in an `adapter` and give `provides` no body. An external provider inside a context is refused, as `bynk.context.external_provider`.",
4009        example: "capability Audit {\n    fn note[T](key: String) -> Effect[()]\n}\n\nprovides Audit = MemoAudit {   // ✗ a generic operation cannot have a Bynk body\n    fn note(key: String) -> Effect[()] { … }\n}\n\nadapter audit {\n    binding \"./audit.binding.ts\"\n    provides Audit = MemoAudit   // ✓ the binding supplies it\n}",
4010    },
4011    Explain {
4012        code: "bynk.provider.missing_operation",
4013        blurb: "A `provides` block implements a capability, so it must supply every operation the capability declares: callers are checked against the capability, and an operation the provider lacks would have nothing to run. The error is on the `provides` line and names the missing operation. Add it, with the signature the capability declares. An operation the capability does not declare is `bynk.provider.extra_operation`.",
4014        example: "capability Clock {\n    fn now() -> Effect[Int]\n    fn zone() -> Effect[String]\n}\n\nprovides Clock = Fixed {         // ✗ no `zone`\n    fn now() -> Effect[Int] { Effect.pure(0) }\n}\n\nprovides Clock = Fixed {         // ✓ every operation is provided\n    fn now() -> Effect[Int] { Effect.pure(0) }\n    fn zone() -> Effect[String] { Effect.pure(\"UTC\") }\n}",
4015    },
4016    Explain {
4017        code: "bynk.provider.outside_context",
4018        blurb: "A `provides` block says how a context's own capability is implemented, so it belongs in the context that declares the capability. A commons holds only pure declarations, with no effects to provide. Move the provider into the context. A `capability` in a commons is refused for the same reason, as `bynk.capability.outside_context`.",
4019        example: "commons demo\n\nprovides Clock = FixedClock {   // ✗ a commons cannot provide a capability\n    fn now() -> Effect[Int] { … }\n}\n\ncontext demo\n\ncapability Clock { fn now() -> Effect[Int] }\n\nprovides Clock = FixedClock {   // ✓ in the context that declares `Clock`\n    fn now() -> Effect[Int] { … }\n}",
4020    },
4021    Explain {
4022        code: "bynk.provider.signature_mismatch",
4023        blurb: "A provider operation must have the signature its capability declares: the same number of parameters, the same parameter types and the same return type. Callers are checked against the capability, so a provider that returns something else would hand them a value of the wrong type. The error points at the parameter or return type that differs, or at the operation when the counts differ. Change the provider to match, or change the capability, and with it every provider of it.",
4024        example: "capability Clock {\n    fn now() -> Effect[Int]\n}\n\nprovides Clock = Fixed {\n    fn now() -> Effect[String] { Effect.pure(\"0\") }   // ✗ the capability returns `Effect[Int]`\n}\n\nprovides Clock = Fixed {\n    fn now() -> Effect[Int] { Effect.pure(0) }        // ✓ same signature\n}",
4025    },
4026    Explain {
4027        code: "bynk.provider.unknown_capability",
4028        blurb: "A `provides` block implements a capability that the same context declares, and none of that name is declared here, so there is nothing to check the operations against. This is usually a misspelt name, or a capability that lives in another context: a provider cannot implement one from elsewhere. Declare the capability next to its provider, or correct the name.",
4029        example: "provides Clock = Fixed {         // ✗ this context declares no `Clock`\n    fn now() -> Effect[Int] { Effect.pure(0) }\n}\n\ncapability Clock {               // ✓ declared alongside its provider\n    fn now() -> Effect[Int]\n}",
4030    },
4031    Explain {
4032        code: "bynk.query.join_key_mismatch",
4033        blurb: "`joinOn` and `leftJoin` pair up rows whose two keys are equal, and equality is only meaningful between values of one type. A `String` key on one side and an `Int` on the other can never match, so the join is refused. Change one key function so that both return the same type. A join on a condition rather than equal keys is `join`.",
4034        example: "type Order = { customerId: String, region: Int }\ntype Customer = { code: String, region: Int }\n\norders.joinOn(customers, (o) => o.customerId, (c) => c.region, (o, c) => c.region).count()   // ✗ `String` against `Int`\n\norders.joinOn(customers, (o) => o.customerId, (c) => c.code, (o, c) => c.region).count()     // ✓ both `String`",
4035    },
4036    Explain {
4037        code: "bynk.query.sum_needs_numeric",
4038        blurb: "`sum` and `average` add the values the key function returns, so the key must be numeric: `Int`, `Float` or `Duration`, or a refined type over one of them. A `String` or a record cannot be added. Return a numeric field. `sum` also adds a `Decimal` key, exactly, on a `List` and on a `Query`. `average` does not take one: a mean is a division, and a `Decimal` division needs a scale and a rounding mode, so sum the key, then `div(Decimal.fromInt(n), scale, mode)` by the count. To pick by an ordering rather than add, `min`, `max` and `sortBy` accept any orderable key.",
4039        example: "type Line = { sku: String, qty: Int }\n\nfn total(lines: List[Line]) -> Int {\n    let t = lines.sum((l) => l.sku)   // ✗ a `String` cannot be summed\n    0\n}\n\nfn total(lines: List[Line]) -> Int {\n    lines.sum((l) => l.qty)           // ✓ a numeric key\n}",
4040    },
4041    Explain {
4042        code: "bynk.queue.bad_params",
4043        blurb: "A queue consumer is invoked once per message, so `on message` takes exactly one parameter: the message, of any type that can be decoded from the queue body. Two parameters leave the second with nothing to supply it, and none leaves the handler without the message. Put what you need into the message type itself: a record with those fields is one parameter. Name the parameter `message` by convention.",
4044        example: "type Msg = { a: String }\n\non message(message: Msg, extra: String) -> Effect[QueueResult] { … }   // ✗ two parameters\n\non message(message: Msg) -> Effect[QueueResult] { … }   // ✓ one message",
4045    },
4046    Explain {
4047        code: "bynk.queue.duplicate_consumer",
4048        blurb: "The context's `queue` entry point picks the handler by the queue's name. Two `on message` handlers for the same name would leave it with two to run. Merge them into one handler, or move one to a `from queue` service for another queue. The rule holds across the project too: Cloudflare accepts one consumer Worker per queue, so two contexts consuming one queue, in a `[deploy.workers]` group or not, could never both deploy. Move the queue to one context; any number of contexts may still send to it.",
4049        example: "service worker from queue(\"jobs\") {\n    on message(message: String) -> Effect[QueueResult] { … }\n    on message(message: String) -> Effect[QueueResult] { … }   // ✗ `jobs` already has a consumer\n}\n\nservice audit from queue(\"audit\") {\n    on message(message: String) -> Effect[QueueResult] { … }   // ✓ a queue of its own\n}",
4050    },
4051    Explain {
4052        code: "bynk.queue.invalid_name",
4053        blurb: "`from queue(\"…\")` names a Cloudflare queue, so the name must be one Cloudflare accepts: 1 to 63 lowercase letters, digits or `-`, starting and ending with a letter or digit. An empty name, capitals or `_` are refused here, rather than failing at deploy. Rename it, for example `order-events`.",
4054        example: "service worker from queue(\"Order_Events\") {\n    on message(message: String) -> Effect[QueueResult] { … }   // ✗ capitals and `_` in the name\n}\n\nservice worker from queue(\"order-events\") {\n    on message(message: String) -> Effect[QueueResult] { … }   // ✓\n}",
4055    },
4056    Explain {
4057        code: "bynk.queue.return_not_queue_result",
4058        blurb: "A queue consumer answers the queue, not a caller, and the only answers it understands are `Ack` (the message is handled) and `Retry(reason)` (deliver it again). The handler's return type is therefore fixed at `Effect[QueueResult]`, so a `Result` or a value cannot be mistaken for a verdict. Return `Ack` on success and `Retry` with a reason when the message should come back. The cron counterpart is `bynk.cron.return_not_effect_result`.",
4059        example: "on message(message: String) -> Effect[Result[Int, String]] { … }   // ✗ the queue needs a verdict\n\non message(message: String) -> Effect[QueueResult] { … }   // ✓ `Ack` or `Retry(…)`",
4060    },
4061    Explain {
4062        code: "bynk.race.in_agent_handler",
4063        blurb: "`race` hands the side that loses to the execution context, and an agent handler has none. Call it from the service handler that calls the agent, so the race is run from outside. The same rule holds for `bynk.within.in_agent_handler`.",
4064        example: "agent Feed {\n    key id: String\n\n    on call quote() -> Effect[Int] {\n        Slow(\"a\").get().race(Slow(\"b\").get())   // ✗ an agent handler has no execution context\n    }\n}\n\nservice quotes {\n    on call() -> Effect[Int] by Caller {\n        Slow(\"a\").get().race(Slow(\"b\").get())   // ✓ the service handler has\n    }\n}",
4065    },
4066    Explain {
4067        code: "bynk.race.in_pure_context",
4068        blurb: "`race` starts two effects and hands the loser to the execution context, and only an effectful body has one: a pure function never runs an effect at all. Change the enclosing function's return type to `Effect[…]` so its body can run it. The same rule holds for `bynk.within.in_pure_context`.",
4069        example: "fn first(a: Effect[Int], b: Effect[Int]) -> Int {\n    let c = a.race(b)   // ✗ the body is pure\n    0\n}\n\nfn first(a: Effect[Int], b: Effect[Int]) -> Effect[Int] {   // ✓ an effectful body\n    a.race(b)\n}",
4070    },
4071    Explain {
4072        code: "bynk.race.outside_handler",
4073        blurb: "`race` hands the side that loses to the execution context, which only a service handler's body, or a function's it calls, has. A WebSocket handler, a provider operation and a test `case` have none. Move the `race` into a service handler or a function, and have the case call that, stubbing a slow side with `stub … after`. In an agent handler the rule is `bynk.race.in_agent_handler`.",
4074        example: "// tests/t.test.bynk\nlet r <- Slow(\"a\").get().race(Slow(\"b\").get())   // ✗ a case has no execution context\n\nlet r <- quotes.call()                           // ✓ the service handler races",
4075    },
4076    Explain {
4077        code: "bynk.record_spread.field_type_mismatch",
4078        blurb: "An override in a record spread must have the type its field declares. The spread produces a value of the record's type, and a field of another type would break that type, so the mismatch is refused at the override instead of surfacing later. Give the field a value of its declared type, converting explicitly where needed: nothing converts implicitly.",
4079        example: "type Counter = { n: Int }\n\nfn bump(c: Counter) -> Counter {\n    Counter { ...c, n: \"no\" }   // ✗ `n` is an `Int`\n}\n\nfn bump(c: Counter) -> Counter {\n    Counter { ...c, n: 1 }   // ✓ an `Int`\n}",
4080    },
4081    Explain {
4082        code: "bynk.record_spread.non_record_base",
4083        blurb: "The base of a spread supplies the fields that are not overridden, so it has to be a value of a record type. An `Int`, a `List` or a sum value has no fields to copy. Spread a record, or build the record with every field written out. A base of a different record is `bynk.record_spread.type_mismatch`.",
4084        example: "type Counter = { n: Int }\n\nfn bump(count: Int, c: Counter) -> Counter {\n    Counter { ...count, n: 1 }   // ✗ `count` is an `Int`, not a record\n}\n\nfn bump(count: Int, c: Counter) -> Counter {\n    Counter { ...c, n: count }   // ✓ spread the record, override the field\n}",
4085    },
4086    Explain {
4087        code: "bynk.record_spread.type_mismatch",
4088        blurb: "A spread, `T { ...base, x: 1 }`, copies the fields of `base` that you do not name, so the result has the base's own type. It cannot convert one record type to another, even one with the same fields, and a `T` that names a different type from the base's is refused. Write the base's type, or, to build a different record, give every field: `Point { x: s.x, y: s.y }`. A base that is not a record is `bynk.record_spread.non_record_base`.",
4089        example: "type Point = { x: Int, y: Int }\ntype Size = { x: Int, y: Int }\n\nfn widen(s: Size) -> Size { Point { ...s, x: 1 } }   // ✗ `s` is a `Size`, not a `Point`\n\nfn widen(s: Size) -> Size { Size { ...s, x: 1 } }    // ✓ the base's own type",
4090    },
4091    Explain {
4092        code: "bynk.record_spread.unknown_field",
4093        blurb: "A record spread, `T { ...base, field: value }`, copies every field of `base` and replaces the ones you list. Each listed field has to be one the record declares: a misspelt or invented name would otherwise be dropped silently, or build a value that is not a `T`. Check the field name against the type's declaration. To add a field, declare it on the type first.",
4094        example: "type Counter = { n: Int }\n\nfn bump(c: Counter) -> Counter {\n    Counter { ...c, missing: 0 }   // ✗ `Counter` has no field `missing`\n}\n\nfn bump(c: Counter) -> Counter {\n    Counter { ...c, n: 0 }   // ✓ an existing field\n}",
4095    },
4096    Explain {
4097        code: "bynk.refine.literal_violates",
4098        blurb: "A literal written where a refined type is expected is checked at compile \
4099                time, and this one does not satisfy the type's predicate. A refined \
4100                type is a base type plus a rule (`InRange`, `NonEmpty`, …), and a \
4101                literal that breaks the rule can never be a valid value, so the \
4102                compiler rejects it instead of admitting it. Use a value that \
4103                satisfies the predicate, or loosen the type. A value known only at \
4104                run time goes through `.of`, which returns a `Result`.",
4105        example: "type Age = Int where InRange(0, 150)\n\n\
4106                  fn limit() -> Age { 200 }   // ✗ 200 is outside InRange(0, 150)\n\
4107                  fn limit() -> Age { 150 }   // ✓ admitted at compile time",
4108    },
4109    Explain {
4110        code: "bynk.registry.withdrawn",
4111        blurb: "Your `bynk.lock` locks a version that its registry has withdrawn. A \
4112                withdrawal is a takedown — for a legal request or confirmed malware — \
4113                so unlike a yank, which keeps a version for locked builds, the \
4114                registry has deleted its archive and there is nothing to fetch. The \
4115                message quotes the registry's reason. A machine that already has the \
4116                tree in its store keeps building; elsewhere, move off the version \
4117                with `bynk update` and the dependency's alias. The reason is unsigned, so when it was \
4118                read through a mirror the message says the origin wasn't consulted.",
4119        example: "error[bynk.registry.withdrawn]: `acme/money` 1.4.2 was withdrawn by \
4120                  registry `acme-internal`: \"removed at the copyright holder's request\"\n  \
4121                  = note: `bynk.lock` locks this version; choose another with `bynk update money`\n\n\
4122                  $ bynk update money     # resolves to the newest version not withdrawn",
4123    },
4124    Explain {
4125        code: "bynk.requires.conflicting_range",
4126        blurb: "A project installs one version of each npm package, so every adapter that `requires` a package must give the same range for it. Two adapters that ask for `jose` at `^4` and `^5` leave the build with no version that satisfies both, so the second is refused and names the first. Ranges are compared as written, so `^5` and `^5.0.0` conflict too. The same code reports one adapter that lists a package twice at different ranges. Give both the same range. A package the toolchain itself pins, such as the one its own bindings use, must be required at that exact version.",
4127        example: "// auth.bynk\nbinding \"./auth.binding.ts\" requires { \"jose\": \"^5\" }\n\n// tokens.bynk\nbinding \"./tokens.binding.ts\" requires { \"jose\": \"^4\" }   // ✗ `auth` already requires `^5`\n\nbinding \"./tokens.binding.ts\" requires { \"jose\": \"^5\" }   // ✓ one range",
4128    },
4129    Explain {
4130        code: "bynk.requires.unapproved",
4131        blurb: "An adapter in a git or registry dependency requires an npm package your project hasn't approved. A dependency's adapters bring their npm packages into your build's `package.json`, and the next `npm install` runs whatever those packages run; so an npm package from someone else's code enters only after you approve it once. The approval is one package at one range, recorded in `bynk.lock` (`approved = true`), so a changed range asks again. Review the package (the note names the dependencies that brought it in), run `bynk approve jose`, and commit `bynk.lock`. Your own adapters and path dependencies need no approval.",
4132        example: "# bynk.lock, as a fetch wrote it — the build fails until approved\n\
4133                  [[npm]]\npackage = \"jose\"\nrange = \"^5.2.0\"\n\
4134                  required-by = [\"acme/money:tokens\"]\n\n\
4135                  # after `bynk approve jose` — the build passes\n\
4136                  [[npm]]\npackage = \"jose\"\nrange = \"^5.2.0\"\n\
4137                  required-by = [\"acme/money:tokens\"]\napproved = true",
4138    },
4139    Explain {
4140        code: "bynk.requires.unpinned_dependency",
4141        blurb: "An adapter's `requires` states the npm versions its binding is written against, and the build installs exactly what it says. `*`, `x`, `latest` and a range with no digit in it accept whatever version is newest on the day, so two builds of the same source can differ. Name a range that has a version in it, such as `^5.2.0`.",
4142        example: "binding \"./tokens.binding.ts\" requires { \"jose\": \"*\" }        // ✗ any version at all\n\nbinding \"./tokens.binding.ts\" requires { \"jose\": \"^5.2.0\" }   // ✓ a pinned range",
4143    },
4144    Explain {
4145        code: "bynk.resolve.ambiguous_variant",
4146        blurb: "A bare variant name such as `Failed(\"down\")` builds a value of the sum that declares it. When two sums in scope declare the name (two of your own, or two that a consumed unit exports, like an adapter's error enums), the compiler reads the expected type: an annotated `let`, a parameter, a return type, or a `stub`'s operation. It builds the sum that type names. With nothing expecting either sum it cannot know which you meant, and it never picks one, so the name is refused. Qualify it as `TypeName.Variant`, or give the value a type. A `match` arm needs neither, because it reads its scrutinee's sum.",
4147        example: "type DbError = | Constraint(message: String) | Failed(message: String)\n\
4148                  type MailError = | RateLimited | Failed(message: String)\n\n\
4149                  let e = Failed(\"down\")       // ✗ `DbError` or `MailError`?\n\n\
4150                  fn mail() -> Result[Int, MailError] {\n\
4151                  \x20   Err(Failed(\"down\"))          // ✓ the return type picks `MailError`\n\
4152                  }\n\n\
4153                  DbError.Failed(\"down\")       // ✓ qualified",
4154    },
4155    Explain {
4156        code: "bynk.resolve.arity_mismatch",
4157        blurb: "A call to a declared `fn` must pass exactly as many arguments as it has parameters. Bynk has no optional or variadic parameters and fills nothing in, so a missing or extra argument is always a mistake, and the compiler cannot tell which one was meant. Add or remove the argument, or change the declaration. The error points at the call and labels the declaration. A call through a function value or a built-in operation is `bynk.types.call_arity`, and a method is `bynk.types.method_arity`.",
4158        example: "fn double(x: Int) -> Int {\n    x * 2\n}\n\nfn run(a: Int, b: Int) -> Int {\n    double(a, b)             // ✗ `double` takes one argument\n}\n\nfn run(a: Int, b: Int) -> Int {\n    double(a) + double(b)    // ✓ one argument each call\n}",
4159    },
4160    Explain {
4161        code: "bynk.resolve.bad_const_initialiser",
4162        blurb: "A constant's value is fixed when its module loads, so its initialiser must be static: a literal, a `Duration` literal, a record, list or variant built from static values, `Some`/`None`/`Ok`/`Err`, `T.unsafe(lit)`, an empty `List`/`Map`/`Set`, or another constant. A function call (even a pure one), an operator, an interpolated string, a field access, a lambda, `if` and `match` are not. The code is also reported when a static value is not of the declared type. Write the value out, or make it a `fn` and call it where it is used.",
4163        example: "fn base() -> Int {\n  10\n}\n\nconst Limit: Int = base()   // ✗ a call is not a static value\n\nconst Limit: Int = 10   // ✓",
4164    },
4165    Explain {
4166        code: "bynk.resolve.const_cycle",
4167        blurb: "Constants may refer to each other in any order, across files and through `uses`, but a value cannot depend on itself: in a cycle no member has anything to start from. The error lists the cycle (`First` → `Second` → `First`) and is reported once, at the member declared first. Break the cycle by giving one member a literal or other static value. A reference such as `Second` is itself a static initialiser, so this is the only rule that limits constants naming each other; `bynk.resolve.bad_const_initialiser` covers initialisers that are not static at all.",
4168        example: "const First: Int = Second   // ✗ `First` → `Second` → `First`\nconst Second: Int = First\n\nconst Second: Int = 10   // ✓ end the chain at a literal",
4169    },
4170    Explain {
4171        code: "bynk.resolve.const_name_case",
4172        blurb: "A constant is named in upper-camel case, a capital letter and then letters, digits or `_`, like a variant, so that a constant reads differently from a binding wherever it is used. The grammar accepts any identifier here and leaves the case to the checker, so a lower-case name is reported with a suggested spelling instead of failing to parse. Rename it, and every use of it: `MaxRetries`, not `maxRetries`.",
4173        example: "const maxRetries: Int = 3   // ✗ a constant's name starts with a capital\n\nconst MaxRetries: Int = 3   // ✓",
4174    },
4175    Explain {
4176        code: "bynk.resolve.const_outside_context_or_commons",
4177        blurb: "An adapter is the program's boundary with the host: it declares capabilities and the providers a binding supplies, not values for the program to share, so a `const` is refused there. Declare the constant in a commons, which a unit reads by `uses`, or in the context that needs it, and move it out of the adapter.",
4178        example: "// tokens.bynk\nconst Lifetime: Int = 3600     // ✗ an adapter declares no constants\n\n// limits.bynk\ncommons limits\nconst Lifetime: Int = 3600     // ✓ in a commons",
4179    },
4180    Explain {
4181        code: "bynk.resolve.duplicate_actor",
4182        blurb: "An actor is named by the `by` clause of a handler, and its name is one of the unit's top-level names, so two actors of one name leave a `by` with nothing to choose between. Rename one, or delete the repeat. The same holds for the other named declarations: `bynk.resolve.duplicate_service`, `bynk.resolve.duplicate_agent` and `bynk.resolve.duplicate_capability`.",
4183        example: "actor Admin { auth = None }\nactor Admin { auth = None }      // ✗ `Admin` is already declared\n\nactor Admin { auth = None }\nactor Support { auth = None }    // ✓ a name of its own",
4184    },
4185    Explain {
4186        code: "bynk.resolve.duplicate_agent",
4187        blurb: "An agent is addressed by its name, and the name is one of the unit's top-level names, so two agents of one name leave a call with nothing to choose between. Rename one, or delete the repeat. The same holds for the other named declarations: `bynk.resolve.duplicate_service`, `bynk.resolve.duplicate_actor` and `bynk.resolve.duplicate_capability`.",
4188        example: "agent Counter { … }\nagent Counter { … }    // ✗ `Counter` is already declared\n\nagent Counter { … }\nagent Tally { … }      // ✓ a name of its own",
4189    },
4190    Explain {
4191        code: "bynk.resolve.duplicate_capability",
4192        blurb: "A capability is named by the `given` clauses that ask for it and by the calls made through it, and its name is one of the unit's top-level names, so two capabilities of one name leave those with nothing to choose between. Rename one, or delete the repeat. The same holds for the other named declarations: `bynk.resolve.duplicate_service`, `bynk.resolve.duplicate_agent` and `bynk.resolve.duplicate_actor`. A capability provided twice is `bynk.resolve.duplicate_provider`.",
4193        example: "capability Clock { … }\ncapability Clock { … }       // ✗ `Clock` is already declared\n\ncapability Clock { … }\ncapability Calendar { … }    // ✓ a name of its own",
4194    },
4195    Explain {
4196        code: "bynk.resolve.duplicate_const",
4197        blurb: "A constant is a value that every use of its name reads, so a name is declared once in a unit. With two `Limit`s, a use would have two values to read. Rename one, or delete the repeat. A constant whose name is a function's, a type's or another declaration's in the unit is `bynk.resolve.name_conflict`.",
4198        example: "const Limit: Int = 1\nconst Limit: Int = 2   // ✗ `Limit` is already declared\n\nconst Cap: Int = 2     // ✓ a different name",
4199    },
4200    Explain {
4201        code: "bynk.resolve.duplicate_field",
4202        blurb: "A record is built and read by field name, so each name may appear once in its declaration, and the same holds for the payload fields of one sum variant. A repeat usually means two different fields were intended: rename one, or remove it. A field set twice in a literal is `bynk.resolve.duplicate_field_init`.",
4203        example: "type Order = { id: Int, id: String }      // ✗ `id` declared twice\n\ntype Order = { id: Int, label: String }  // ✓ distinct names",
4204    },
4205    Explain {
4206        code: "bynk.resolve.duplicate_field_init",
4207        blurb: "A record literal gives each field one value. A field set twice leaves it unclear which value is meant, and is nearly always a pasted line or a misspelt name for the field that was meant. Remove the repeat, or correct the name. A field declared twice in the type is `bynk.resolve.duplicate_field`; a field left out of the literal is `bynk.resolve.missing_field`.",
4208        example: "type Point = { x: Int, y: Int }\n\nfn origin() -> Point { Point { x: 0, y: 0, y: 1 } }   // ✗ `y` set twice\n\nfn origin() -> Point { Point { x: 0, y: 0 } }         // ✓ each field once",
4209    },
4210    Explain {
4211        code: "bynk.resolve.duplicate_fn",
4212        blurb: "A function is called by its name, and Bynk has no overloading: two functions of one name in a unit, even with different parameters, would leave a call unable to say which it means. So a unit declares each function name once. Rename one of them. A suite's helpers repeat as `bynk.suite.duplicate_fn`, and a type's methods as `bynk.resolve.duplicate_method`.",
4213        example: "fn total(a: Int, b: Int) -> Int { … }\nfn total(a: Int, b: Int, c: Int) -> Int { … }    // ✗ `total` is already declared\n\nfn total3(a: Int, b: Int, c: Int) -> Int { … }   // ✓",
4214    },
4215    Explain {
4216        code: "bynk.resolve.duplicate_message_code",
4217        blurb: "A message code is the key `render` looks a template up by, so one block can give it only one text. A second entry under the same code leaves two templates for one key, and the second is refused. Delete the repeat, or give it a code of its own. The same code in different locale blocks is how a translation is written, and is not an error. A locale declared twice is `bynk.resolve.duplicate_message_locale`.",
4218        example: "messages \"en\" @reference {\n    \"cart.empty\" => \"Your basket is empty.\"\n    \"cart.empty\" => \"Your cart is empty.\"       // ✗ already declared in this block\n}\n\nmessages \"en\" @reference {\n    \"cart.empty\" => \"Your basket is empty.\"\n    \"cart.total\" => \"Your total is {total}.\"    // ✓ a code of its own\n}",
4219    },
4220    Explain {
4221        code: "bynk.resolve.duplicate_message_locale",
4222        blurb: "A `messages` block holds the templates for one locale, and `render(tag, msg)` picks the block by its tag. Two blocks for one tag leave it two sets of templates to choose from, so the second is refused. Merge them into one block, or correct the tag of the one meant for another language. A code repeated inside a block is `bynk.resolve.duplicate_message_code`.",
4223        example: "messages \"en\" @reference { … }\nmessages \"en\" { … }                 // ✗ `en` is already declared\n\nmessages \"en\" @reference { … }\nmessages \"fr\" { … }                 // ✓ one block for each locale",
4224    },
4225    Explain {
4226        code: "bynk.resolve.duplicate_method",
4227        blurb: "A method is looked up by its type and name, so `p.norm()` has to mean one body. A second `fn Point.norm` would leave the call with nothing to choose between. Delete the repeat, or give it a different name if it does something else.",
4228        example: "type Point = { x: Int }\n\nfn Point.norm(self) -> Int { self.x }\n\nfn Point.norm(self) -> Int { 0 }                  // ✗ `Point.norm` is already declared\n\nfn Point.isOrigin(self) -> Bool { self.x == 0 }   // ✓ a different name",
4229    },
4230    Explain {
4231        code: "bynk.resolve.duplicate_param",
4232        blurb: "A function's parameters are read by name in its body, and a call passes them in order, so each name may appear once in the list. A repeat is usually two different parameters meant, and the body could see only one of them. Rename one of the two, or remove it.",
4233        example: "fn area(w: Int, w: Int) -> Int { w * w }   // ✗ `w` declared twice\n\nfn area(w: Int, h: Int) -> Int { w * h }   // ✓ distinct names",
4234    },
4235    Explain {
4236        code: "bynk.resolve.duplicate_provider",
4237        blurb: "`provides Clock = …` is the one implementation a context supplies for `Clock`, and a handler that is `given Clock` is given that one. Two providers for the same capability leave it nothing to choose between, so the second is refused. Delete the one you do not want, or merge them into one provider. Declaring the capability itself twice is `bynk.resolve.duplicate_capability`.",
4238        example: "provides Clock = FixedClock { … }\nprovides Clock = OtherClock { … }          // ✗ `Clock` already has a provider\n\nprovides Clock = FixedClock { … }\nprovides Calendar = FixedCalendar { … }    // ✓ one provider for each capability",
4239    },
4240    Explain {
4241        code: "bynk.resolve.duplicate_service",
4242        blurb: "A service is called by its name, and the name is one of the unit's top-level names, so two services of one name leave a call with nothing to choose between. Rename one, or delete the repeat. The same holds for the other named declarations: `bynk.resolve.duplicate_agent`, `bynk.resolve.duplicate_actor`, `bynk.resolve.duplicate_capability` and `bynk.resolve.duplicate_provider`, and for the entries of a message bundle, `bynk.resolve.duplicate_message_code` and `bynk.resolve.duplicate_message_locale`.",
4243        example: "service orders { … }\nservice orders { … }     // ✗ `orders` is already declared\n\nservice refunds { … }    // ✓ a name of its own",
4244    },
4245    Explain {
4246        code: "bynk.resolve.duplicate_type",
4247        blurb: "A unit declares two types, or a type and an event, with the same name. A unit's top-level \
4248                declarations share one scope in the emitted module, so a name can mean only one thing, \
4249                and a type name appears in signatures and constructors with no way to say which \
4250                declaration is meant. Rename one of them, or remove the repeated declaration. The check \
4251                spans all of the unit's files, so the second declaration can be in a different file.",
4252        example: "type Money = Int\ntype Money = String          // ✗ `Money` is already declared\n\n\
4253                  type Money = Int\ntype Label = String          // ✓ distinct names",
4254    },
4255    Explain {
4256        code: "bynk.resolve.duplicate_variant",
4257        blurb: "A sum value is identified by its variant name: in a `match` pattern, in a constructor, and as the `kind` of its JSON form. So each variant appears once in a type. A repeat is usually two different variants meant, or a line pasted twice. Rename one of them, or delete the repeat. A payload field repeated within one variant is `bynk.resolve.duplicate_field`.",
4258        example: "type Colour = | Red | Red     // ✗ `Red` declared twice\n\ntype Colour = | Red | Green   // ✓ distinct variants",
4259    },
4260    Explain {
4261        code: "bynk.resolve.fn_without_call",
4262        blurb: "A function's name on its own is the function, not its result. It is a value only where a function type is expected, such as an argument to `map`; anywhere else it is nearly always a forgotten call. Call it with its arguments, or pass it where a function is wanted.",
4263        example: "fn double(x: Int) -> Int { x * 2 }\n\nfn run() -> Int {\n    let d = double      // ✗ the function itself, not a call\n    5\n}\n\nfn run() -> Int {\n    let d = double(5)   // ✓ the result of calling it\n    d\n}",
4264    },
4265    Explain {
4266        code: "bynk.resolve.let_shadows_fn",
4267        blurb: "A `let` may not reuse the name of a function declared in the unit. The name would mean the function in one place and the binding in another, and a reader could not tell which `total` is meant. Choose a different name for the binding. Reusing a type's name is `bynk.resolve.let_shadows_type`.",
4268        example: "fn total() -> Int { 1 }\n\nfn run() -> Int {\n    let total = 2                // ✗ shadows the function `total`\n    total\n}\n\nfn run() -> Int {\n    let sum = total() + 1        // ✓ a new name\n    sum\n}",
4269    },
4270    Explain {
4271        code: "bynk.resolve.let_shadows_type",
4272        blurb: "A `let` may not take the name of a declared type. The same name would then mean a type in one position and a value in another within one body, which is hard to read and easy to get wrong. Choose a different name for the binding, conventionally in lower case. Reusing a function's name is `bynk.resolve.let_shadows_fn`.",
4273        example: "type Reps = Int where InRange(1, 100)\n\nfn run(n: Int) -> Int {\n    let Reps = n                 // ✗ shadows the type `Reps`\n    n\n}\n\nfn run(n: Int) -> Int {\n    let reps = n                 // ✓ a new name\n    reps\n}",
4274    },
4275    Explain {
4276        code: "bynk.resolve.method_unknown_type",
4277        blurb: "A method is declared on a type, as in `fn Order.total(self)`, and the type has to be declared in the same unit, so that every value of it can reach the method. A misspelt or missing type is the usual cause. Correct the name, or declare the type next to the method.",
4278        example: "fn Order.total(self) -> Int { 1 }         // ✗ there is no type `Order` here\n\ntype Order = { id: Int }\n\nfn Order.total(self) -> Int { self.id }   // ✓ `Order` is declared in this unit",
4279    },
4280    Explain {
4281        code: "bynk.resolve.missing_field",
4282        blurb: "A record must be constructed with every field that has no default. \
4283                There is no partial construction: a value of a record type is only \
4284                valid once all its fields are present, so a downstream reader never \
4285                has to wonder whether a field was set. Omitting a required field is \
4286                therefore an error, not a fill-in-later. A field may be left out \
4287                only when its declaration gives it a default, `field: T = expr`.",
4288        example: "type User = { name: String, age: Int }\n\n\
4289                  User { name: \"Ada\" }            // ✗ missing `age`\n\
4290                  User { name: \"Ada\", age: 36 }   // ✓ every field present",
4291    },
4292    Explain {
4293        code: "bynk.resolve.name_conflict",
4294        blurb: "Two declarations of different kinds share a name. A unit's functions, assets, embeds, \
4295                constants, types and events, services, agents and providers with a body (by their \
4296                implementation name) all live in one namespace, across all of the unit's files, because \
4297                they are one scope in the emitted module. Capabilities and actors each keep their own. \
4298                Two types, or a type and an event, are `bynk.resolve.duplicate_type`, and two constants \
4299                `bynk.resolve.duplicate_const`. Rename one of the two.",
4300        example: "fn Limit() -> Int {\n    3\n}\n\n\
4301                  const Limit: Int = 3         // ✗ a function already has this name\n\n\
4302                  const Limit: Int = 3         // ✓ once the function is renamed `limit`",
4303    },
4304    Explain {
4305        code: "bynk.resolve.not_a_record_type",
4306        blurb: "`Name { field: value }` builds a record, so `Name` has to be a record type. A sum is built by naming one of its variants, and a refined type with `Name.of(value)`, which checks the value. A type that is opaque is its own error, `bynk.resolve.opaque_record_construction`.",
4307        example: "type Shape = | Circle | Square\n\nfn make() -> Shape { Shape { side: 1 } }   // ✗ `Shape` is a sum, not a record\n\nfn make() -> Shape { Circle }              // ✓ name a variant",
4308    },
4309    Explain {
4310        code: "bynk.resolve.opaque_record_construction",
4311        blurb: "An opaque type hides its representation so that nothing outside its own checks can produce a value of it, and a record literal `T { value: … }` would go round them. Build one with `T.of(value)`, which validates and returns a `Result`, or, inside the commons that defines the type, with `T.unsafe(value)`.",
4312        example: "type Timestamp = opaque Int\n\nfn Timestamp.fromMillis(n: Int) -> Timestamp {\n    Timestamp { value: n }       // ✗ record syntax on an opaque type\n}\n\nfn Timestamp.fromMillis(n: Int) -> Timestamp {\n    Timestamp.unsafe(n)          // ✓ inside the defining commons\n}",
4313    },
4314    Explain {
4315        code: "bynk.resolve.param_as_function",
4316        blurb: "Only a value of function type can be called. `n(5)` applies `n`, but `n` is an `Int`, so there is nothing to run. It is usually a missing operator or a parameter that was meant to be a function. Give the parameter a function type, such as `f: Int -> Int`, or drop the call. The check covers any local value, not only parameters.",
4317        example: "fn apply(n: Int) -> Int {\n    n(5)                         // ✗ `n` is an `Int`, not a function\n}\n\nfn apply(f: Int -> Int) -> Int {\n    f(5)                         // ✓ a function-typed parameter\n}",
4318    },
4319    Explain {
4320        code: "bynk.resolve.recursive_record_field",
4321        blurb: "A record cannot contain itself through record fields alone, whether directly (`next: Node` in `Node`) or round a cycle (`A` has a `B`, which has an `A`). A value of such a type could never be built, since making one needs one already, and the compiler could not synthesise the default value it needs for one. A cycle through an `Option`, `List`, `Map` or a sum type is fine, because that position can hold a value that ends the chain. Wrap one field in the cycle in `Option[…]`.",
4322        example: "type Node = { value: Int, next: Node }   // ✗ a `Node` would need a `Node`\n\ntype Node = { value: Int, next: Option[Node] }   // ✓ `None` ends the chain",
4323    },
4324    Explain {
4325        code: "bynk.resolve.reserved_builtin_type",
4326        blurb: "The compiler knows a few type names itself, and the type parser reads each one as the built-in wherever it appears in a type. A `type` declaration that reused one would be shadowed at every use, or fail confusingly there, so the declaration is refused. The names are `Asset`, `BoundaryRejection`, `Connection`, `History`, `HttpResult`, `List`, `Map`, `Query`, `QueueResult`, `RequestHeaders`, `RequestQuery`, `Set`, `Stream` and `TokenClaims`. Rename the type. They are reserved in type position only, so a value may still use the word. A constant with such a name is `bynk.resolve.name_conflict` instead, and the base types and words such as `Result` are keywords that the parser refuses earlier.",
4327        example: "type Set = { items: List[Int] }   // ✗ `Set` is the built-in set type\n\ntype IntSet = { items: List[Int] }   // ✓",
4328    },
4329    Explain {
4330        code: "bynk.resolve.reserved_host_name",
4331        blurb: "The generated TypeScript reaches the host's built-in objects as `globalThis.<name>`, so a top-level declaration called `globalThis` (a type, function, agent, provider and so on) would hide all of them in its module. Rename the declaration. Parameters and local bindings may use the name: the compiler renames those itself.",
4332        example: "type globalThis = { n: Int }   // ✗ the name is reserved\n\ntype Counter = { n: Int }      // ✓ any other name",
4333    },
4334    Explain {
4335        code: "bynk.resolve.reserved_payload_field",
4336        blurb: "A sum value is encoded as a flat JSON object whose `kind` field holds the variant's name, so a payload field called `kind` would collide with that tag. Rename the field, for instance to `category`.",
4337        example: "type Shape = | Circle(kind: String, r: Int) | Square(side: Int)   // ✗ `kind` is the variant tag\n\ntype Shape = | Circle(category: String, r: Int) | Square(side: Int)   // ✓ any other name",
4338    },
4339    Explain {
4340        code: "bynk.resolve.self_outside_method",
4341        blurb: "`self` is the value a method was called on, so it exists only in the body of a method, declared as `fn Type.name(self, …)`. A plain function has no receiver. Make the function a method of the type, or take the value as an ordinary parameter.",
4342        example: "type Counter = { n: Int }\n\nfn read(c: Counter) -> Int {\n    self.n                         // ✗ a plain function has no `self`\n}\n\nfn Counter.read(self) -> Int {     // ✓ a method declares `self`\n    self.n\n}",
4343    },
4344    Explain {
4345        code: "bynk.resolve.type_as_function",
4346        blurb: "A type's name is not a function. A refined type is built with `.of(value)`, which checks the value and returns a `Result`, and a record with a literal such as `Order { … }`, so `Amount(5)` has no meaning to fall back on. A sum variant with a payload is the one exception: `Placed(at, total)` constructs it. A name that is not a type at all is `bynk.resolve.unknown_function`.",
4347        example: "type Amount = Int where NonNegative\n\nfn price() -> Amount {\n    Amount(5)                    // ✗ a type is not a function\n}\n\nfn price() -> Result[Amount, ValidationError] {\n    Amount.of(5)                 // ✓ checked construction\n}",
4348    },
4349    Explain {
4350        code: "bynk.resolve.type_in_expr",
4351        blurb: "A type's name stands for a set of values, not for one, so it cannot be used where a value is expected. This is usually a missing constructor. Build a value in the type's own way: `Type { … }` for a record, a variant name for a sum, `Type.of(value)` for a refined type. A type used as a call, `Type(…)`, is `bynk.resolve.type_as_function`.",
4352        example: "type Metres = Int where NonNegative\n\nfn grow(x: Int) -> Int { x + Metres }   // ✗ `Metres` is a type, not a value\n\nfn grow(x: Int) -> Result[Metres, ValidationError] { Metres.of(x + 1) }   // ✓ build a `Metres`",
4353    },
4354    Explain {
4355        code: "bynk.resolve.unconsumed_context",
4356        blurb: "A call such as `platform.pay.charge(1)` reaches into another context, and a context may only do that to one it has declared with `consumes`. The declaration is what makes a dependency between contexts visible and checked, instead of a name that happens to resolve. The same code is reported for a `given platform.pay.Cap` whose context is not consumed. Add `consumes platform.pay` (with an alias, if you want to call it by another name) at the top of the calling context. A consumed context that does not export a capability is `bynk.given.cross_context_unknown_capability`.",
4357        example: "// app/shop.bynk\ncontext app.shop\n\nservice checkout {\n    on call() -> Effect[Int] by Caller {\n        platform.pay.charge(1)   // ✗ `platform.pay` is not in this context's `consumes`\n    }\n}\n\n\
4358                  context app.shop\n\nconsumes platform.pay          // ✓ declared at the top",
4359    },
4360    Explain {
4361        code: "bynk.resolve.unknown_field",
4362        blurb: "A record construction names a field the record type does not declare. \
4363                A record's fields are fixed by its type declaration, and a literal may \
4364                set only those. This is usually a typo in the field name, or a field \
4365                meant for a different type. Reading a field a value does not have is \
4366                the sibling code `bynk.types.unknown_field`.",
4367        example: "type User = { name: String, age: Int }\n\n\
4368                  User { name: \"Ada\", age: 36, admin: true }   // ✗ no field `admin`\n\
4369                  User { name: \"Ada\", age: 36 }                // ✓ only the declared fields",
4370    },
4371    Explain {
4372        code: "bynk.resolve.unknown_function",
4373        blurb: "A call names a function that is not in scope. Only functions declared in the same unit, or \
4374                brought in through `uses`, can be called; a capitalised name, which would construct an \
4375                agent, needs an agent of that name in scope. This is most often a typo or a missing \
4376                `uses`. A lambda cannot call itself through its own `let` name either, because the name \
4377                is not bound until the lambda is built. A type used as a function, as in `Money(5)`, is \
4378                the separate `bynk.resolve.type_as_function`.",
4379        example: "fn double(x: Int) -> Int {\n    x * 2\n}\n\n\
4380                  dubble(4)          // ✗ no function `dubble`\n\n\
4381                  double(4)          // ✓ the declared name",
4382    },
4383    Explain {
4384        code: "bynk.resolve.unknown_name",
4385        blurb: "A name was referenced that is not in scope. Every name in Bynk \
4386                must be introduced before use — as a `let` binding, a parameter, \
4387                a `fn`, a type, or a member brought in through `uses`/`consumes`. \
4388                An unknown name is typically a typo, a missing declaration, or a \
4389                reference to something defined in a module that has not been \
4390                brought into scope.",
4391        example: "let greeting = \"hi\"\n\
4392                  greetng          // ✗ no name `greetng` in scope\n\
4393                  greeting         // ✓ the bound name",
4394    },
4395    Explain {
4396        code: "bynk.resolve.unknown_static_member",
4397        blurb: "A type was named with a `.` and a member it does not have. `T.name` refers to a variant of the \
4398                sum type `T` or to a static method declared on it, and a misspelt variant has no such member. Some built-in types \
4399                have a closed set: `HttpResult`, `ErrorStatus` and `RoundingMode` only their variants, \
4400                `Float` only `parse`, `pi` and `e`, and `Decimal` only `parse` and `fromInt`. Check the spelling against the declaration, or declare the missing \
4401                static method.",
4402        example: "type Colour =\n    | Red\n    | Green\n\n\
4403                  Colour.Gren          // ✗ `Colour` has no variant `Gren`\n\n\
4404                  Colour.Green         // ✓ the declared variant",
4405    },
4406    Explain {
4407        code: "bynk.resolve.unknown_type",
4408        blurb: "A type name was referenced that does not exist. Types must be \
4409                declared (with `type`), be one of Bynk's built-in types, or be \
4410                brought into scope from another module before they can be named. \
4411                An unknown type is usually a typo or a missing declaration/import.",
4412        example: "fn greet(u: Usr) -> String { … }   // ✗ no type `Usr`\n\
4413                  fn greet(u: User) -> String { … }  // ✓ the declared type",
4414    },
4415    Explain {
4416        code: "bynk.revert.agent_schema_older",
4417        blurb: "Agent state is stamped with the schema version of the build that wrote it, and older code faults with `NewerSchema` on records written by newer code. `bynk revert` therefore refuses to go back to a build with an older schema version while stored instances exist, while they are not known to be absent, or when the target is below the class's schema floor. The listing of stored objects lags a write by minutes, so within 30 minutes of the live deploy an empty listing counts as unknown. Deploy a fix forward instead.",
4418        example: "bynk revert --dry-run\n\
4419\x20\x20agent     Cart         refused: the target writes schema v1, the live version v2, and stored instances exist\n\
4420\n\
4421bynk deploy   # fix forward",
4422    },
4423    Explain {
4424        code: "bynk.revert.class_changed",
4425        blurb: "Cloudflare applies Durable Object class additions, removals and renames as migrations, and it cannot roll back across one. If the set of classes differs between the live version and the target, `bynk revert` refuses. Redeploy forward, with the class set you want, instead.",
4426        example: "bynk revert --dry-run\n\
4427\x20\x20classes   shop-orders  refused: the Durable Object classes differ between the two versions\n\
4428\n\
4429bynk deploy   # redeploy forward",
4430    },
4431    Explain {
4432        code: "bynk.revert.contract_skew",
4433        blurb: "Contexts call each other under contract hashes. Reverting one Worker can leave it expecting, or providing, a contract that another live Worker does not, and the runtime would refuse the calls. The check judges the result as if every selected Worker were reverted together, using the post-revert lock. Revert the whole project, or redeploy forward. See `bynk.deploy.contract_skew` for the same skew at deploy time.",
4434        example: "bynk revert --dry-run --context shop.orders\n\
4435\x20\x20contracts shop-orders  refused: the target no longer matches shop-payment\n\
4436\n\
4437bynk revert   # the whole project, so the contexts revert together",
4438    },
4439    Explain {
4440        code: "bynk.revert.database_schema_ahead",
4441        blurb: "D1 migrations only move forward. If the live version applied a migration the target was not built against, the older code would meet a schema it was never written for. Bynk cannot judge a migration's SQL, so it refuses. If every such migration is additive, assert it per database with `--accept-schema-ahead <binding>`; otherwise deploy a fix forward. The same refusal is given when the applied migrations could not be read, because an unread list is never taken to be empty.",
4442        example: "bynk revert --dry-run\n\
4443\x20\x20d1        DB           refused: the live version applied 0003_add_index.sql after the target was built\n\
4444\n\
4445bynk revert --accept-schema-ahead DB   # only if each such migration is additive",
4446    },
4447    Explain {
4448        code: "bynk.revert.facts_missing",
4449        blurb: "`bynk revert` reads the deploy facts that every `bynk deploy` records on the Worker version it pushes. Without them on both the live version and the target it cannot tell what changed in between, and every unknown is a refusal. A version deployed before facts were recorded, or one pushed outside Bynk, has none. Redeploy the version you want from its tag with `git checkout <tag> && bynk deploy`.",
4450        example: "bynk revert --dry-run\n\
4451\x20\x20facts     shop-orders  refused: the target version records no deploy facts\n\
4452\n\
4453git checkout v1.4.0 && bynk deploy   # redeploy the previous tag instead",
4454    },
4455    Explain {
4456        code: "bynk.revert.history_unplaceable",
4457        blurb: "`bynk revert` finds the target in the Worker's deployment history: by default the deployment before the live code's own upload, or the version named by `--to`. It refuses that Worker when it cannot place the live version or the target: a Worker first added in the bad release has nothing before it, the live upload is out of the listed history, a gradual deployment is in progress, or the history could not be read. A version made live outside Bynk has no upload deployment to step back from; name the version to go back to with `--to`. The plan still judges the other Workers.",
4458        example: "bynk revert --dry-run --context shop.orders\n\
4459\x20\x20history   shop-orders  refused: the live version is a gradual deployment\n\
4460\n\
4461bynk revert --context shop.orders --to <version>",
4462    },
4463    Explain {
4464        code: "bynk.revert.id_unrecorded",
4465        blurb: "The target version binds resources (KV namespaces, databases, limiters, Hyperdrive configs) by id. If the deploy lock no longer records the same id for a binding, the resource was re-provisioned or replaced since, and the older code would bind one that is no longer yours, or one `--prune` has deleted. `bynk revert` refuses. Redeploy forward.",
4466        example: "bynk revert --dry-run\n\
4467\x20\x20ids       shop-orders  refused: the target would bind a resource that has since been replaced\n\
4468\n\
4469bynk deploy   # redeploy forward",
4470    },
4471    Explain {
4472        code: "bynk.revert.layout_older",
4473        blurb: "A layout is how an agent's state is placed in storage, and each version's deploy facts record which one it writes. Code that writes an older layout than the live version cannot read records in the newer one: a build with the layout check faults them as `NewerLayout`, and one without it would orphan their entries. `bynk revert` refuses while stored instances exist or are not known to be absent. Deploy a fix forward.",
4474        example: "bynk revert --dry-run\n\
4475\x20\x20layout    Cart         refused: the target writes layout 1, the live version writes layout 2, and stored instances exist\n\
4476\n\
4477bynk deploy   # fix forward",
4478    },
4479    Explain {
4480        code: "bynk.revert.membership_changed",
4481        blurb: "A `[deploy.workers.<key>]` group is one Worker script, so `bynk revert` puts every member back together. It refuses to go back to a version that held other contexts than the live one: a context that has moved into or out of the group since, or a version deployed before groups. Rolling back would take a member's code out from under its traffic. Redeploy forward instead.",
4482        example: "bynk revert --dry-run --worker core\n\
4483\x20\x20members   core  refused: the live version holds [shop.a, shop.b] and the target holds [shop.a]\n\
4484\n\
4485bynk deploy   # redeploy forward",
4486    },
4487    Explain {
4488        code: "bynk.revert.secret_changed",
4489        blurb: "A rollback can restore the old value of a secret that was rotated after the target was live, and its peers no longer accept that value. `bynk revert` counts the secret changes between the target and now and refuses if there are any. After a `bynk migrate sweep`, whose two changes touch only its own temporary key, pass `--accept-secret-changes`. A secret rotated before the release you are leaving is kept and does not count.",
4490        example: "bynk revert --dry-run\n\
4491\x20\x20secrets   shop-orders  refused: 2 secret change(s) since the target\n\
4492\n\
4493bynk revert --accept-secret-changes   # only after a `bynk migrate sweep`",
4494    },
4495    Explain {
4496        code: "bynk.service.duplicate_call_handler",
4497        blurb: "A service with no `from` clause is a call service with one entry: exactly one `on call` handler, which another context calls by the service's name (`payment.authorise(…)`) and a test addresses as `svc.call(…)`. A second would never run, since only one of the two can answer the call. To offer a second operation, declare a second service.",
4498        example: "service greet {\n    on call(name: String) -> Effect[String] by Caller { … }\n    on call(name: String) -> Effect[String] by Caller { … }   // ✗ a second `on call`\n}\n\nservice greet {\n    on call(name: String) -> Effect[String] by Caller { … }   // ✓ one handler\n}\n\nservice farewell {                                  // ✓ a second operation is a second service\n    on call(name: String) -> Effect[String] by Caller { … }\n}",
4499    },
4500    Explain {
4501        code: "bynk.service.missing_from",
4502        blurb: "A service with no `from` clause is a call service, and admits only `on call` handlers; the protocol in the header is what says how a handler is invoked. A handler of another form needs its protocol named: `from http` for a route, `from cron`, `from queue(\"…\")`, `from websocket(…)` or `from Events(E)`. The error suggests the one that fits the handler. If the service really is a mix, split it (see `bynk.service.mixed_protocols`).",
4503        example: "service worker {\n    on message(m: String) -> Effect[QueueResult] { … }   // ✗ no `from` clause\n}\n\nservice worker from queue(\"jobs\") {   // ✓ the protocol is named\n    on message(m: String) -> Effect[QueueResult] { … }\n}",
4504    },
4505    Explain {
4506        code: "bynk.service.mixed_protocols",
4507        blurb: "A service is one protocol adapter: with `from http`, `from cron`, `from queue(…)`, `from websocket(…)` or `from Events(E)` it admits only handlers of that form, and one that does not match is refused. Declare a service per protocol. A handler in a service with no `from` at all is `bynk.service.missing_from`.",
4508        example: "service worker from queue(\"jobs\") {\n    on call(m: String) -> Effect[Int] { … }   // ✗ `on call` is not a queue handler\n}\n\nservice count {                             // ✓ a service of its own\n    on call(m: String) -> Effect[Int] by Caller { … }\n}",
4509    },
4510    Explain {
4511        code: "bynk.service.outside_context",
4512        blurb: "A `service` is a context's entry point: a call, a route, a schedule, a queue consumer, a socket. A `commons` holds only shared types and pure functions, and has no context to serve from. Move the service into a context. Logic it shares can stay in the commons, which the context then `uses`.",
4513        example: "commons shop\n\nservice probe { … }   // ✗ a commons holds no entry points\n\ncontext shop\n\nservice probe { … }   // ✓",
4514    },
4515    Explain {
4516        code: "bynk.service.return_not_effect",
4517        blurb: "Every service handler returns an `Effect[T]`, whatever its protocol. A handler runs as the context answers a call, route, schedule, message or frame, and its effects and `given` capabilities are the runtime's to run, so a bare `Int` is refused. Wrap the result: `Effect.pure(x)` for a value you already hold. An `on event` handler that returns an `Effect` of anything but `()` is `bynk.event.return_not_effect_unit`.",
4518        example: "service probe {\n    on call() -> Int by Caller { … }            // ✗ not an `Effect`\n    on call() -> Effect[Int] by Caller { … }    // ✓\n}",
4519    },
4520    Explain {
4521        code: "bynk.service.unknown_protocol",
4522        blurb: "The protocol after `from` is one of a closed set: `http`, `cron`, `queue`, `websocket` or `Events`. Kafka and MQTT are transports, not protocols: use `from queue(\"…\")` and bind the broker at the platform layer. A service with no `from` takes `on call` handlers.",
4523        example: "service worker from kafka {                // ✗ not a protocol\n\nservice worker from queue(\"jobs\") {        // ✓ the queue protocol",
4524    },
4525    Explain {
4526        code: "bynk.service.unknown_via_clause",
4527        blurb: "A `via` clause narrows which events an `Events` subscriber receives, and the only form is `via schema(N)`, which selects by the event's schema version. The set of `via` clauses is closed, so any other word after `via` is refused. Use `via schema(N)` or drop the clause. A malformed argument to `schema` itself is `bynk.event.bad_schema_dispatch`.",
4528        example: "service OnPaid from Events(Paid) via nope(1) {   // ✗ only `schema` follows `via`\n    on event(e: Paid) -> Effect[()] { … }\n}\n\nservice OnPaid from Events(Paid) via schema(1) {   // ✓ dispatch on the schema version\n    on event(e: Paid) -> Effect[()] { … }\n}",
4529    },
4530    Explain {
4531        code: "bynk.service.websocket_header",
4532        blurb: "A WebSocket service names its two frame types in the header, `from websocket(in: ClientFrame, out: ServerFrame)`: `in` is what the server decodes from the client and `out` is what it sends back. The labels are fixed and in that order, so the compiler can tell the two apart without guessing from the handlers. Spell them `in:` then `out:`.",
4533        example: "service gateway from websocket(input: Frame, out: Frame) {   // ✗ the first label must be `in`\n    on open (room: RoomId) -> Effect[()] by user: Member { … }\n}\n\nservice gateway from websocket(in: Frame, out: Frame) {   // ✓\n    on open (room: RoomId) -> Effect[()] by user: Member { … }\n}",
4534    },
4535    Explain {
4536        code: "bynk.service.websocket_multiple",
4537        blurb: "A WebSocket upgrade reaches the context by its `Upgrade: websocket` header alone, with no path to tell two endpoints apart, so a context can host only one `from websocket` service. The compiler reports every one but the first by name. Keep one, or move the other into a context of its own.",
4538        example: "service lobby from websocket(in: Frame, out: Frame) { … }\nservice rooms from websocket(in: Frame, out: Frame) { … }   // ✗ a second WebSocket service in this context\n\nservice lobby from websocket(in: Frame, out: Frame) { … }   // ✓ one per context",
4539    },
4540    Explain {
4541        code: "bynk.service.websocket_open_arity",
4542        blurb: "A WebSocket service has exactly one `on open`, the handler that accepts the upgrade and receives the connection, and at most one `on message` and one `on close`. A service with no `on open` could never accept a client, and a second of any handler would leave it unclear which one runs. Add the missing `on open`, or remove the duplicate.",
4543        example: "service gateway from websocket(in: Frame, out: Frame) {   // ✗ no `on open`\n    on message (room: RoomId, frame: Frame) -> Effect[()] by user: Member { … }\n}\n\nservice gateway from websocket(in: Frame, out: Frame) {\n    on open (room: RoomId) -> Effect[()] by user: Member { … }   // ✓\n    on message (room: RoomId, frame: Frame) -> Effect[()] by user: Member { … }\n}",
4544    },
4545    Explain {
4546        code: "bynk.service.websocket_param_not_stringy",
4547        blurb: "An `on open` parameter is read from the upgrade request's query string, so it arrives as text, and the compiler builds it with the type's constructor from a `String`. A type that cannot be built from a string, such as `Int`, has no safe way in: a stray `?room=05` would name a different value from `5`. Declare the parameter as a `String`, a refined `String` or an opaque type over `String`, and parse any number in the body. HTTP path parameters follow the same rule, as `bynk.http.path_param_not_stringy`.",
4548        example: "service gateway from websocket(in: Frame, out: Frame) {\n    on open (room: RoomId, limit: Int) -> Effect[()] by user: Member { … }   // ✗ a query value is a string\n}\n\nservice gateway from websocket(in: Frame, out: Frame) {\n    on open (room: RoomId, limit: String) -> Effect[()] by user: Member { … }   // ✓ parse the number in the body\n}",
4549    },
4550    Explain {
4551        code: "bynk.stability.experimental",
4552        blurb: "Some standard-library items are experimental: they may change or disappear in any release, and the compatibility promise does not cover them. Using one is an error until the project opts in, so that relying on it is a choice someone made and can find. Add the item's path, as the error gives it, to `allow` under `[unstable]` in `bynk.toml`, or avoid the item. An entry that names no standard-library item is `bynk.project.unstable_unknown_item`.",
4553        example: "// demo.bynk\nconsumes bynk.cloudflare { Version }    // ✗ experimental\n\n// bynk.toml\n[unstable]\nallow = [\"bynk.cloudflare.Version\"]     // ✓",
4554    },
4555    Explain {
4556        code: "bynk.store.annotation_kind_mismatch",
4557        blurb: "Each storage annotation is for one kind of store: `@ttl` for a `Cache`, `@retain` for a `Log` and `@indexed` for a `Map`. On any other kind it has nothing to act on: a `Map` has no expiry, for one. Move the annotation to a field of the kind it belongs to, or change the field's kind if that is what you meant.",
4558        example: "store sessions: Map[String, Int] @ttl(30.minutes)     // ✗ `@ttl` is for a `Cache`\n\nstore sessions: Cache[String, Int] @ttl(30.minutes)   // ✓",
4559    },
4560    Explain {
4561        code: "bynk.store.annotation_unsupported",
4562        blurb: "A storage annotation has a fixed set of kinds it applies to and a meaning that arrives in stages. `@bounded` is recognised on `Queue` and `Log`, but nothing acts on it yet, so it is refused rather than accepted and ignored. Leave it off. To limit a `Log`, use `@retain`, which drops entries older than a period. A known annotation on the wrong kind is `bynk.store.annotation_kind_mismatch`.",
4563        example: "store trail: Log[Event] @bounded(100)     // ✗ `@bounded` is recognised but has no effect yet\n\nstore trail: Log[Event] @retain(30.days)   // ✓ keep 30 days of entries",
4564    },
4565    Explain {
4566        code: "bynk.store.cache_needs_clock",
4567        blurb: "A `Cache` entry expires, and every operation on it but `remove` reads the clock to decide whether an entry is still live. So a handler that uses a `Cache` must declare `given Clock`, the same way one that reads the time itself would; the dependency is explicit even though the body never names the clock. Add `given Clock` to the handler's signature.",
4568        example: "consumes bynk { Clock }\n\nstore live: Cache[String, Int] @ttl(5.minutes)\n\non call touch() -> Effect[()] {\n    let _ <- live.put(\"a\", 1)   // ✗ expiry reads the clock, which the handler does not declare\n    Effect.pure(())\n}\n\non call touch() -> Effect[()] given Clock {   // ✓ declare the clock\n    let _ <- live.put(\"a\", 1)\n    Effect.pure(())\n}",
4569    },
4570    Explain {
4571        code: "bynk.store.cache_ttl_required",
4572        blurb: "A `Cache` is a keyed store whose entries expire, so it needs `@ttl(<duration>)`, how long an entry lives. Without an expiry it would only be a `Map`. The argument must be a `Duration` literal such as `5.minutes`; a bare number (`@ttl(5)`) or a computed value is refused too, because the lifetime has to be known when the program compiles. Add the annotation, or declare a `Map` if entries should be kept until removed.",
4573        example: "store live: Cache[String, Int]   // ✗ no lifetime for the entries\n\nstore live: Cache[String, Int] @ttl(5.minutes)   // ✓\n\nconst Life: Duration = 5.minutes\nstore quick: Cache[String, Int] @ttl(Life)   // ✓ a `Duration` constant bound to a literal",
4574    },
4575    Explain {
4576        code: "bynk.store.kind_arity",
4577        blurb: "Each storage kind takes a fixed number of type arguments: `Cell[T]`, `Set[T]` and `Log[T]` take one, and `Map[K, V]` and `Cache[K, V]` take two. The checker reads the arguments by position, so a wrong count cannot be guessed at and is refused where the field is declared. Give the kind the arguments it takes. To keep a key with a value use `Map`, and to hold a single value use `Cell[T]`.",
4578        example: "store total: Cell[String, Int]   // ✗ a `Cell` takes one type argument\n\nstore total: Cell[Int]   // ✓ one",
4579    },
4580    Explain {
4581        code: "bynk.store.kind_unsupported",
4582        blurb: "`Queue` is a recognised storage kind but is not yet implemented. The working kinds are `Cell`, `Map`, `Set`, `Log` and `Cache`, so a `store` of any other known kind is refused. Use one of them: an append-only `Log` is the closest to a queue. A name that is no storage kind at all is `bynk.store.unknown_kind`.",
4583        example: "store pending: Queue[Event]                 // ✗ not yet supported\n\nstore pending: Log[Event] @retain(30.days)   // ✓ an append-only sequence",
4584    },
4585    Explain {
4586        code: "bynk.store.log_needs_clock",
4587        blurb: "`Log.append` stamps each entry with the time it was written, so it reads the clock and the handler has to declare `given Clock`. The window reads (`since`, `before`, `between`) take explicit `Instant`s and need no clock. Add `given Clock` to the handler that appends.",
4588        example: "consumes bynk { Clock }\n\nstore trail: Log[String]\n\non call opened() -> Effect[()] {\n    let _ <- trail.append(\"opened\")   // ✗ the stamp reads the clock\n    Effect.pure(())\n}\n\non call opened() -> Effect[()] given Clock {   // ✓ declare the clock\n    let _ <- trail.append(\"opened\")\n    Effect.pure(())\n}",
4589    },
4590    Explain {
4591        code: "bynk.store.unkeyable_key",
4592        blurb: "A store `Map` or `Cache` key, or a store `Set` element, must be `String`, `Int` or a refined or opaque type over them. A store collection is saved as a JSON object keyed by the key's string form, and a record has no stable string form, so it cannot be a key (a composite key is not supported yet). Key by one of the record's id fields, or by an enum's name as a `String`. A value `Map` or `Set` follows a wider rule, `bynk.types.not_keyable`.",
4593        example: "type Point = { x: Int, y: Int }\n\nstore cells: Map[Point, Int]   // ✗ a record has no stable string key\n\nstore cells: Map[String, Int]   // ✓ key by a string, such as an id",
4594    },
4595    Explain {
4596        code: "bynk.store.unknown_annotation",
4597        blurb: "A `store` field takes one of four annotations: `@indexed`, `@ttl`, `@retain` and `@bounded`. The set is closed, so a name outside it, usually a misspelling or one borrowed from another system, is refused rather than ignored. Use the annotation that says what you mean: `@retain` for how long a `Log` keeps entries, `@ttl` for a `Cache`. A known one on the wrong kind is `bynk.store.annotation_kind_mismatch`.",
4598        example: "store audit: Log[String] @keep(7.days)     // ✗ not a storage annotation\n\nstore audit: Log[String] @retain(7.days)   // ✓ how long a `Log` keeps entries",
4599    },
4600    Explain {
4601        code: "bynk.store.unknown_kind",
4602        blurb: "The type of a `store` field names a storage kind, which says how the state is persisted and which operations it has; it is not an ordinary type. The kinds are `Cell`, `Map`, `Set`, `Log` and `Cache`; `Queue` is reserved but not yet supported (`bynk.store.kind_unsupported`). A `List` or a record is not one, because nothing would say how to read or update it atomically. Pick the kind that matches how you use the data: `Set` for membership, `Map` for lookup by key, `Log` to append, `Cell` for one value.",
4603        example: "store tags: List[String]   // ✗ `List` is not a storage kind\n\nstore tags: Set[String]   // ✓ a storage kind",
4604    },
4605    Explain {
4606        code: "bynk.store.unknown_map_accessor",
4607        blurb: "A `store Map` field is read as a lazy query through exactly three accessors: `.entries` (each a `MapEntry` with `.key` and `.value`), `.keys` and `.values`. Any other name after the field is refused. Its effectful operations, such as `put` and `get`, are method calls, not accessors. Use one of the three, or call an operation. A wrong method name on a store is `bynk.store.unknown_op`.",
4608        example: "store items: Map[String, Item]\n\nitems.names.collect()   // ✗ a `Map` has no `.names`\n\nitems.keys.collect()   // ✓ the keys, as a query",
4609    },
4610    Explain {
4611        code: "bynk.store.unknown_op",
4612        blurb: "A `store` field's methods are its storage operations, which are effectful (await with `<-`), and each kind has a fixed set. `Map` and `Cache` take `put`, `get`, `update`, `upsert`, `remove`, `contains` and `size` (a `Map` also takes query operations); `Set` takes `add`, `remove`, `contains` and `size`; a `Cell` takes only `update`, being read by name and written with `:=`; a `Log` takes `append` and lazy query reads. Any other name is refused, even one the same type has as a plain value. For a read-modify-write use `update`, or `upsert` when the key may be absent. A wrong key query (`.entries`, `.keys`, `.values`) is `bynk.store.unknown_map_accessor`.",
4613        example: "let _ <- counts.increment(\"k\")   // ✗ a `Map` store has no `increment`\n\nlet _ <- counts.upsert(\"k\", 1, (v) => v + 1)   // ✓ add one, starting from 1",
4614    },
4615    Explain {
4616        code: "bynk.stub.after_type",
4617        blurb: "`stub … returns <value> after <delay>` makes the stubbed call \
4618                complete only once the harness clock has advanced by that \
4619                delay, so the delay must be a `Duration`, such as `3.seconds`. \
4620                A bare number has no unit, so it is refused rather than \
4621                guessed at as milliseconds or seconds.",
4622        example: "// demo/meter.bynk\n\
4623                  capability Meter { … }\n\n\
4624                  // tests/meter.test.bynk\n\
4625                  stub Meter.read() returns 7 after 3           // ✗ no unit\n\
4626                  stub Meter.read() returns 7 after 3.seconds   // ✓",
4627    },
4628    Explain {
4629        code: "bynk.stub.at_system",
4630        blurb: "At the `system` tier each context runs as the Worker it deploys as, and that Worker builds its own capability providers, so there is no seam for a `stub` to override. A `stub` there would be accepted and then ignored, so it is refused. Move the case to a suite below `system`, where a `stub` replaces the seam, or remove the stub and test the real provider.",
4631        example: "suite demo.desk as system {\n    stub Meter.read() returns 7   // ✗ a `system` suite has no seam to stub\n\n    case \"the desk checks\" { … }\n}\n\nsuite demo.desk {\n    stub Meter.read() returns 7   // ✓ below `system` the seam can be stubbed\n\n    case \"the desk checks\" { … }\n}",
4632    },
4633    Explain {
4634        code: "bynk.stub.bad_sequence",
4635        blurb: "`returns each […]` gives one outcome per call, in order, and the \
4636                last outcome repeats once the list runs out. An empty list has no \
4637                outcome to repeat, so the first call would have nothing to return. \
4638                List at least one. To return an empty list as a single value, \
4639                write `returns []`, without `each`.",
4640        example: "// demo/meter.bynk\n\
4641                  capability Meter { … }\n\
4642                  \n\
4643                  // tests/meter.test.bynk\n\
4644                  stub Meter.read() returns each []    // ✗ no outcomes\n\
4645                  stub Meter.read() returns each [7]   // ✓ at least one",
4646    },
4647    Explain {
4648        code: "bynk.stub.generic_op",
4649        blurb: "A `stub` gives an operation a fixed answer, but an operation with its own type parameter, `fn dedup[T](…)`, answers in whatever type the caller names, and a fixed value cannot be that. Such an operation cannot be stubbed. Test through the capability's real provider, and stub the other, non-generic operations of the capability if you need to.",
4650        example: "// tests/orders.test.bynk\nstub Idempotency.dedup(_) returns None   // ✗ `dedup` has its own type parameter\n\ncase \"reserve returns the cached value\" {\n    let result <- reserve.call()   // ✓ the real provider answers\n    expect result is None\n}",
4651    },
4652    Explain {
4653        code: "bynk.stub.not_a_seam",
4654        blurb: "A `stub` substitutes one of the capabilities the unit under test \
4655                depends on: one the context declares, or reaches through a \
4656                `consumes`. Any other name, including a misspelt one, leaves \
4657                nothing to substitute. A commons has no capabilities, so it cannot \
4658                be stubbed at all. Name a capability of the target, or add the \
4659                `consumes` it needs. See `bynk.stub.unknown_op` for a wrong \
4660                operation.",
4661        example: "// demo/meter.bynk\n\
4662                  capability Meter { … }\n\
4663                  \n\
4664                  // tests/meter.test.bynk\n\
4665                  stub Gauge.read() returns 7   // ✗ the context has no `Gauge`\n\
4666                  stub Meter.read() returns 7   // ✓",
4667    },
4668    Explain {
4669        code: "bynk.stub.rhs_type",
4670        blurb: "A `stub … returns <value>` stands in for a real provider, so the \
4671                value must have the type the operation declares, as the real \
4672                result would. `Meter.read` yields an `Int`, so it returns `7`, not \
4673                a string; the `Effect` is supplied for you. Change the value, or \
4674                stub the operation you meant. To inject a failure, write `fails` \
4675                instead of a value.",
4676        example: "// demo/meter.bynk\n\
4677                  capability Meter { … }\n\
4678                  \n\
4679                  // tests/meter.test.bynk\n\
4680                  stub Meter.read() returns \"seven\"   // ✗ a String, not an Int\n\
4681                  stub Meter.read() returns 7         // ✓",
4682    },
4683    Explain {
4684        code: "bynk.stub.unknown_op",
4685        blurb: "`stub Cap.op(…)` overrides one operation of a capability, so `op` \
4686                must be declared by that capability. A misspelt or renamed \
4687                operation matches nothing, so the stub is refused instead of \
4688                leaving the default provider in place unannounced. Use the \
4689                operation name the capability declares. See `bynk.stub.not_a_seam` \
4690                when the capability itself is the wrong one.",
4691        example: "// demo/meter.bynk\n\
4692                  capability Meter { … }\n\
4693                  \n\
4694                  // tests/meter.test.bynk\n\
4695                  stub Meter.reed() returns 7   // ✗ Meter has no `reed`\n\
4696                  stub Meter.read() returns 7   // ✓",
4697    },
4698    Explain {
4699        code: "bynk.suite.const_name_clash",
4700        blurb: "A suite's cases see the target's own declarations and those of the commons it `uses`, and the suite's constants are used by bare name beside them. A suite constant with one of those names, or with that of a sum variant in scope, would silently change which value a mention reaches, so it is refused instead of shadowing. Rename it. A type clashing is `bynk.suite.type_name_clash`.",
4701        example: "// demo/desk.bynk\nconst Limit: Int = 5\n\n// tests/desk.test.bynk\nconst Limit: Int = 9    // ✗ the target already has a `Limit`\nconst Cap: Int = 9      // ✓ a name of its own",
4702    },
4703    Explain {
4704        code: "bynk.suite.duplicate_case_name",
4705        blurb: "A case is identified by its description in the runner's output and \
4706                in failure reports, so each description must be unique across the \
4707                suites that test one unit. Two cases with the same description \
4708                cannot be told apart. Rename one; the error is on the repeat, with a label at the first.",
4709        example: "// tests/ledger.test.bynk\n\
4710                  case \"an entry\" { … }\n\
4711                  case \"an entry\" { … }          // ✗ same description\n\
4712                  case \"another entry\" { … }     // ✓",
4713    },
4714    Explain {
4715        code: "bynk.suite.duplicate_const",
4716        blurb: "A suite's constants are used by bare name in its cases, so a suite declares each name once: a second `const Limit` would leave `Limit` meaning two values. A `const` named like one of the suite's `type`s counts as a repeat too. Rename one. The same holds for a suite's types, as `bynk.suite.duplicate_type`, and for helper functions, as `bynk.suite.duplicate_fn`.",
4717        example: "const Limit: Int = 5\nconst Limit: Int = 9    // ✗ `Limit` again\nconst Cap: Int = 9      // ✓ a name each",
4718    },
4719    Explain {
4720        code: "bynk.suite.duplicate_env",
4721        blurb: "An `env` clause gives a variable one value in its scope, so naming it twice in the same suite or the same case leaves two values and no way to choose. Keep one. A case's own `env` may still override a name its suite gives; only a repeat within one scope is refused.",
4722        example: "env {\n    MODE = \"fake\"\n    MODE = \"live\"     // ✗ `MODE` is already given in this suite\n}\n\nenv {\n    MODE = \"fake\"\n    REGION = \"eu\"     // ✓ one value per name\n}",
4723    },
4724    Explain {
4725        code: "bynk.suite.duplicate_fn",
4726        blurb: "A case calls a suite helper by its bare name, so two helpers \
4727                of one suite with one name would leave the call ambiguous. \
4728                Give each a distinct name; the error is on the repeat. The \
4729                same holds for a suite's types and constants: see \
4730                `bynk.suite.duplicate_type` and `bynk.suite.duplicate_const`.",
4731        example: "// tests/desk.test.bynk\n\
4732                  fn twice(n: Int) -> Int { n * 2 }\n\
4733                  fn twice(n: Int) -> Int { n + n }     // ✗ `twice` again\n\
4734                  fn thrice(n: Int) -> Int { n * 3 }    // ✓",
4735    },
4736    Explain {
4737        code: "bynk.suite.duplicate_type",
4738        blurb: "A suite's types are used by their bare names in its cases, so a suite declares each name once: a second `type Counted` would leave `Counted` meaning two shapes. Rename one. The same holds for a suite's constants, as `bynk.suite.duplicate_const`, and for helper functions, as `bynk.suite.duplicate_fn`.",
4739        example: "type Counted = { n: Int }\ntype Counted = { total: Int }     // ✗ `Counted` again\n\ntype Counted = { n: Int }\ntype Totalled = { total: Int }    // ✓ a name each",
4740    },
4741    Explain {
4742        code: "bynk.suite.env_binding_clash",
4743        blurb: "A `system` suite runs the participants as Workers, and an `env` entry is put on \
4744                each Worker's `env`, beside the bindings that Worker already has: a Service \
4745                Binding, a KV namespace, a Durable Object namespace, and the keys the test harness \
4746                sets itself, such as a call edge's key or a foreign caller's secret. An entry with \
4747                one of those names would replace the binding, so the compiler refuses it. Rename \
4748                the variable. In this example `shop.ledger` consumes `Kv`, so its Worker already \
4749                has a binding named `KV`.",
4750        example: "consumes bynk.cloudflare { Kv }                  // `shop.ledger` has a binding named `KV`\n\
4751                  \n\
4752                  suite shop.ledger as system {\n\
4753                  \x20\x20case \"an env entry may not replace a binding\" {\n\
4754                  \x20\x20\x20\x20env { KV = \"not a namespace\" }              // ✗ `KV` is a binding of the Worker\n\
4755                  \n\
4756                  \x20\x20\x20\x20env { REGION = \"eu\" }                       // ✓ a name nothing else holds",
4757    },
4758    Explain {
4759        code: "bynk.suite.env_not_literal",
4760        blurb: "A Worker's variables and secrets are strings, so an `env` entry's value must be a `String` literal, `NAME = \"value\"`, or the name of a `fixture` the same suite declares. A number, a call or any other expression is refused, since the value is fixed when the suite is compiled. Write it as a string, and parse a number in the code that reads it.",
4761        example: "env {\n    RETRIES = 3       // ✗ not a `String`\n}\n\nenv {\n    RETRIES = \"3\"     // ✓\n}",
4762    },
4763    Explain {
4764        code: "bynk.suite.fn_effectful",
4765        blurb: "A suite helper is a pure function that builds a value for a \
4766                case: a request, a fixture, an expected result. Returning an \
4767                `Effect` would hide a step of the test inside a helper. Build \
4768                the value in the helper and run the effect in the `case`, \
4769                where each step is visible with `<-`.",
4770        example: "// tests/desk.test.bynk\n\
4771                  fn bump(n: Int) -> Effect[Int] { local.call(n) }   // ✗ returns an `Effect`\n\
4772                  fn start() -> Int { 1 }                            // ✓ build the value\n\
4773                  let n <- local.call(start())                       // ✓ run it in the case",
4774    },
4775    Explain {
4776        code: "bynk.suite.fn_method",
4777        blurb: "A suite helper is a plain function its cases call by name, so \
4778                it is a free `fn`, not a method (`fn Type.name`). A method \
4779                belongs to its type: declare it in the target or in a commons. \
4780                In a suite, take the value as an ordinary parameter.",
4781        example: "// demo/desk.bynk\n\
4782                  type Count = Int where NonNegative\n\n\
4783                  // tests/desk.test.bynk\n\
4784                  fn Count.bump(self) -> Int { 1 }       // ✗ a method\n\
4785                  fn bump(count: Count) -> Int { 1 }     // ✓ a free function",
4786    },
4787    Explain {
4788        code: "bynk.suite.fn_name_clash",
4789        blurb: "A suite helper is called by bare name from the suite's cases, \
4790                which also see the target's declarations (services and agents \
4791                included) and those of the commons it `uses`. A helper with \
4792                one of those names would silently change which function a \
4793                call reaches, so it is refused instead of shadowing. A \
4794                fixture of the suite counts too, and `deps` and names \
4795                beginning `__` are reserved for the runner. Rename the helper. A type or constant clashing is \
4796                `bynk.suite.type_name_clash` or `bynk.suite.const_name_clash`.",
4797        example: "// demo/desk.bynk\n\
4798                  fn double(n: Int) -> Int { n * 2 }\n\n\
4799                  // tests/desk.test.bynk\n\
4800                  fn double(n: Int) -> Int { n * 3 }    // ✗ the target has a `double`\n\
4801                  fn triple(n: Int) -> Int { n * 3 }    // ✓",
4802    },
4803    Explain {
4804        code: "bynk.suite.type_generic",
4805        blurb: "A suite's `type` is a plain shape that only its tests care \
4806                about, such as a row to read back with `select[T]`, so it \
4807                takes no type parameters. If you need a generic type, declare \
4808                it in the target or in a commons, where the suite can use it. \
4809                Otherwise write the concrete type.",
4810        example: "// tests/desk.test.bynk\n\
4811                  type Box[T] = { v: T }       // ✗ a suite type is not generic\n\
4812                  type IntBox = { v: Int }     // ✓",
4813    },
4814    Explain {
4815        code: "bynk.suite.type_name_clash",
4816        blurb: "A suite's cases see the target's own declarations and those of the commons it `uses`, and the suite's types are used by bare name beside them. A suite type with one of those names would silently change which type a mention reaches, so it is refused instead of shadowing. The same goes for a variant of a suite's own sum type. Rename it. A constant clashing is `bynk.suite.const_name_clash`.",
4817        example: "// demo/desk.bynk\ntype Item = { sku: String }\n\n// tests/desk.test.bynk\ntype Item = { n: Int }       // ✗ the target already has an `Item`\ntype Counted = { n: Int }    // ✓ a name of its own",
4818    },
4819    Explain {
4820        code: "bynk.suite.unknown_target",
4821        blurb: "A `suite` names the commons or context it tests, by its full \
4822                dotted name, and that unit must be declared in the project. A name \
4823                that matches none, usually a typo or a unit not written yet, would \
4824                leave the suite testing nothing. Correct the name, or declare the \
4825                unit.",
4826        example: "// demo/ledger.bynk\n\
4827                  commons demo.ledger\n\
4828                  \n\
4829                  // tests/ledger.test.bynk\n\
4830                  suite demo.ledgre { … }    // ✗ no such unit\n\
4831                  suite demo.ledger { … }    // ✓",
4832    },
4833    Explain {
4834        code: "bynk.target.browser_bundle_only",
4835        blurb: "The `browser` platform builds a module that runs in a web page: one in-process bundle, with nothing to deploy. The `workers` target lays a project out as one Cloudflare Worker per context, joined by Service Bindings, which a browser cannot run. So the two do not combine. Build for the browser with the `bundle` target, which is the default, or build Workers for the `cloudflare` platform.",
4836        example: "bynk build --target workers --platform browser   // ✗ Workers are not a browser build\n\nbynk build --target bundle --platform browser    // ✓",
4837    },
4838    Explain {
4839        code: "bynk.test.actor_identity_required",
4840        blurb: "An actor that declares an `identity` stands for one particular \
4841                caller, and the handler reads that identity. A case that acts as \
4842                the actor must therefore say which caller, as in `by \
4843                User(\"bob\")`; a bare `by User` leaves the handler nothing to \
4844                read. A handler that binds its caller (`by c: Caller`) wants the \
4845                calling context's name the same way. Add the identity. The reverse \
4846                mistake is `bynk.test.actor_no_identity`.",
4847        example: "// demo/api.bynk\n\
4848                  type UserId = String where NonEmpty\n\
4849                  actor User { … }\n\n\
4850                  // tests/api.test.bynk\n\
4851                  let r <- api.GET(\"/a\") by User          // ✗ which user?\n\
4852                  let r <- api.GET(\"/a\") by User(\"bob\")   // ✓",
4853    },
4854    Explain {
4855        code: "bynk.test.actor_no_identity",
4856        blurb: "A case supplies an identity only when the actor has one to give. \
4857                An actor that declares no `identity`, and the failure principals \
4858                `Nobody`, `Forged`, `Stale` and `Expired`, which present a missing \
4859                or bad credential and so no verified caller, take no argument. \
4860                Write `by Nobody`, not `by Nobody(\"bob\")`. For an actor that \
4861                does declare an identity and is given none, see \
4862                `bynk.test.actor_identity_required`.",
4863        example: "// tests/api.test.bynk\n\
4864                  let r <- api.GET(\"/a\") by Nobody(\"bob\")   // ✗ no credential, so no identity\n\
4865                  let r <- api.GET(\"/a\") by Nobody          // ✓",
4866    },
4867    Explain {
4868        code: "bynk.test.advance_not_clock",
4869        blurb: "`advance` moves the harness clock, the single time source a test \
4870                owns, so it names `Clock` and nothing else. No other capability \
4871                has virtual time to move. To shape what another capability \
4872                returns, use a `stub`. The clock only moves forward.",
4873        example: "// demo/clock.bynk\n\
4874                  consumes bynk { Clock }\n\
4875                  \n\
4876                  // tests/clock.test.bynk\n\
4877                  advance Random by 5.minutes   // ✗ only the Clock moves\n\
4878                  advance Clock by 5.minutes    // ✓",
4879    },
4880    Explain {
4881        code: "bynk.test.advance_not_duration",
4882        blurb: "`advance Clock by <amount>` moves the harness clock forward by a \
4883                `Duration`. A bare number does not say what unit it counts, so it \
4884                is refused. Write a duration literal such as `5.minutes`. See \
4885                `bynk.test.advance_not_clock` for naming a capability other than \
4886                `Clock`.",
4887        example: "// demo/clock.bynk\n\
4888                  consumes bynk { Clock }\n\
4889                  \n\
4890                  // tests/clock.test.bynk\n\
4891                  advance Clock by 5           // ✗ a number, not a Duration\n\
4892                  advance Clock by 5.minutes   // ✓",
4893    },
4894    Explain {
4895        code: "bynk.test.advance_outside_case",
4896        blurb: "`advance Clock by …` moves the harness clock, which only a \
4897                `case` owns. A `property` runs its body once per generated \
4898                input and has no clock of its own, and non-test code reads \
4899                real time. Put the time-dependent step in a `case`. \
4900                `bynk.test.advance_not_clock` and \
4901                `bynk.test.advance_not_duration` cover the other ways to get \
4902                `advance` wrong.",
4903        example: "property \"time moves on\" {\n\
4904                  \x20\x20for all n: Int {\n\
4905                  \x20\x20\x20\x20advance Clock by 5.minutes    // ✗ a property has no clock\n\
4906                  \x20\x20}\n\
4907                  }\n\n\
4908                  case \"time moves on\" {\n\
4909                  \x20\x20advance Clock by 5.minutes      // ✓\n\
4910                  }",
4911    },
4912    Explain {
4913        code: "bynk.test.asset_address_method",
4914        blurb: "An asset is served by the platform before the Worker runs, and only to `GET`: it answers every other method with `405`. A case fetches one with `api.GET(asset)`, and a different method is refused, since the answer would be the platform's `405` and nothing your code decides. Use `GET`, and pass the asset alone. A `by` clause on the fetch is `bynk.test.principal_on_asset`.",
4915        example: "// demo/web.bynk\nasset style = \"assets/board.css\"\n\n// tests/web.test.bynk\nlet r <- api.POST(style)    // ✗ only `GET` fetches an asset\nlet r <- api.GET(style)     // ✓",
4916    },
4917    Explain {
4918        code: "bynk.test.call_needs_in_process",
4919        blurb: "A service with an `on call` handler is internal to a deployment: \
4920                it has no public route, and a `system` case can only send requests \
4921                through the Worker's front door. So `svc.call(…)` is refused in \
4922                one. Call it at `unit` or `integration`, or drive an http route \
4923                that reaches it. For the event equivalent, see \
4924                `bynk.test.event_needs_in_process`.",
4925        example: "// demo/api.bynk\n\
4926                  service save { … }\n\n\
4927                  // tests/api.test.bynk\n\
4928                  case \"a key is measured\" as system {   // ✗ `save` has no public route\n\
4929                  case \"a key is measured\" {             // ✓\n\
4930                  \x20\x20\x20\x20let n <- save.call(\"abc\")\n\
4931                  }",
4932    },
4933    Explain {
4934        code: "bynk.test.event_needs_in_process",
4935        blurb: "`svc.event(e)` hands an event straight to a subscriber. At \
4936                `system`, an event reaches a subscriber only through its \
4937                publisher's fan-out across the deployed Workers, so there is no \
4938                direct delivery to make. Drive the handler that publishes the \
4939                event, or deliver the event at `unit` or `integration`. For the \
4940                `on call` equivalent, see `bynk.test.call_needs_in_process`.",
4941        example: "// shop/ledger.bynk\n\
4942                  service OnPlaced from Events(Placed) { … }\n\n\
4943                  // tests/ledger.test.bynk\n\
4944                  case \"a placed order is booked\" as system {   // ✗ no direct delivery at `system`\n\
4945                  case \"a placed order is booked\" {             // ✓\n\
4946                  \x20\x20\x20\x20let _ <- OnPlaced.event(Placed { id: \"o1\" })\n\
4947                  }",
4948    },
4949    Explain {
4950        code: "bynk.test.event_not_subscribed",
4951        blurb: "`svc.event(e)` delivers an event through the handler the \
4952                service subscribes with, so it takes the one event named in \
4953                the service's `from Events(E)` header. Delivering a different \
4954                event would test a path the service does not have. Pass the \
4955                subscribed event, or test the service that does subscribe to \
4956                the one you meant.",
4957        example: "// shop/ledger.bynk\n\
4958                  service OnPlaced from Events(Placed) { … }\n\n\
4959                  // tests/ledger.test.bynk\n\
4960                  let _ <- OnPlaced.event(Cancelled { id: \"o1\" })   // ✗ it subscribes to `Placed`\n\
4961                  let _ <- OnPlaced.event(Placed { id: \"o1\" })      // ✓",
4962    },
4963    Explain {
4964        code: "bynk.test.event_publisher_ambiguous",
4965        blurb: "`svc.event(e)` delivers an event in a default envelope, whose `publisherId` is the context that publishes the event to the target: its own, or the one context it consumes that declares it. When two consumed contexts both declare the event there is no single publisher to name, so the case must build the envelope itself. Pass `svc.event(e, env)`, with an `EventEnvelope` whose `publisherId` names the one you mean; the target must consume `EventEnvelope` from `bynk`.",
4966        example: "// shop/ledger.bynk\nconsumes shop.order\nconsumes shop.archive\nconsumes bynk { EventEnvelope }\n\n// tests/ledger.test.bynk\nlet _ <- OnPlaced.event(Placed { id: \"o1\" })         // ✗ `shop.order` or `shop.archive`?\nlet env = EventEnvelope { eventId: \"e1\", publisherId: \"shop.order\", …\nlet _ <- OnPlaced.event(Placed { id: \"o1\" }, env)    // ✓ the envelope names it",
4967    },
4968    Explain {
4969        code: "bynk.test.expired_needs_bearer_route",
4970        blurb: "`by Expired` sends an expired token, so it needs a route whose \
4971                seam checks one: a `Bearer` or `Oidc` actor. A public route, or \
4972                one guarded by a `Signature` actor, has no token to expire; for a \
4973                `Signature` route `by Stale` sends a stale signature. Drive a \
4974                route guarded by a `Bearer` or `Oidc` actor. See \
4975                `bynk.test.nobody_needs_secured_route` for the same limit on \
4976                `Nobody`.",
4977        example: "// demo/api.bynk\n\
4978                  on GET(\"/a\") () -> Effect[HttpResult[Int]] by u: User { … }\n\
4979                  on GET(\"/health\") () -> Effect[HttpResult[Int]] by v: Visitor { … }\n\n\
4980                  // tests/api.test.bynk\n\
4981                  let r <- api.GET(\"/health\") by Expired   // ✗ a public route has no token\n\
4982                  let r <- api.GET(\"/a\") by Expired        // ✓",
4983    },
4984    Explain {
4985        code: "bynk.test.extra_headers_authorization",
4986        blurb: "A case sends a credential only through its `by` clause: the driver \
4987                builds the `Authorization` header (or the signature headers) from \
4988                the actor it acts as. Sending an `Authorization` header as an \
4989                extra request header, in `RequestHeaders.of`, would give the \
4990                request two competing credentials, so it is refused. Choose the \
4991                actor with `by`, and keep `RequestHeaders` for other headers.",
4992        example: "// tests/api.test.bynk\n\
4993                  let r <- api.GET(\"/health\", RequestHeaders.of([\"Authorization: Bearer x\"])) by Visitor   // ✗\n\
4994                  let r <- api.GET(\"/health\", RequestHeaders.of([\"X-Trace: 1\"])) by Visitor                // ✓",
4995    },
4996    Explain {
4997        code: "bynk.test.faults_needs_in_process",
4998        blurb: "`expect <call> faults` claims that a handler throws. At `system` a \
4999                fault reaches the case as an error response from the deployed \
5000                Worker, not a throw, so claim it at `unit` or `integration`, or \
5001                assert the response. A claim driven `by Nobody`, `Forged` or \
5002                `Stale` fails at every tier: only a `system` case reaches the auth \
5003                seam that refuses the request. Assert `Rejected(Unauthorized)` in \
5004                a `system` case instead.",
5005        example: "// tests/api.test.bynk\n\
5006                  expect api.GET(\"/a\") by Nobody faults     // ✗ a seam rejects, nothing throws\n\n\
5007                  case \"no token is refused\" as system {    // ✓\n\
5008                  \x20\x20\x20\x20let r <- api.GET(\"/a\") by Nobody\n\
5009                  \x20\x20\x20\x20expect r is Rejected(Unauthorized)\n\
5010                  }",
5011    },
5012    Explain {
5013        code: "bynk.test.forged_needs_signature_route",
5014        blurb: "`by Forged` and `by Stale` send a bad credential to a real auth seam, so the route must have a seam that can refuse it. `Forged` needs a `Signature`, `Bearer` or `Oidc` actor. `Stale` needs a `Signature` actor, since only a signature carries a timestamp to age. On any other route there is nothing to refuse and the case would test nothing, so it is refused. Drive a route with the right seam. See `bynk.test.stale_needs_timestamp` for a `Signature` actor with no timestamp.",
5015        example: "// demo/api.bynk\non GET(\"/me\") () -> Effect[HttpResult[String]] by u: User { … }\non POST(\"/hook\") (body: String) -> Effect[HttpResult[String]] by Hook { … }\n\n// tests/api.test.bynk\nlet r <- api.GET(\"/me\") by Stale             // ✗ a `Bearer` route has no signature to age\nlet r <- api.POST(\"/hook\", \"x\") by Stale     // ✓ `Hook` is a `Signature` actor",
5016    },
5017    Explain {
5018        code: "bynk.test.forged_needs_system",
5019        blurb: "`by Forged`, `by Stale` and the other bad-credential principals \
5020                send a forged or out-of-date credential to the real auth seam, \
5021                which only a `system` case reaches. In process the seam is skipped \
5022                and the identity is simply given, so there is nothing to refuse. \
5023                Move the case to `system` with `as system`.",
5024        example: "// tests/api.test.bynk\n\
5025                  case \"a forged token is refused\" {            // ✗ not a system case\n\
5026                  case \"a forged token is refused\" as system {  // ✓\n\
5027                  \x20\x20\x20\x20let r <- api.GET(\"/a\") by Forged\n\
5028                  \x20\x20\x20\x20expect r is Rejected(Unauthorized)\n\
5029                  }",
5030    },
5031    Explain {
5032        code: "bynk.test.no_subject_needs_oidc_route",
5033        blurb: "`by NoSubject` sends two correctly signed, unexpired tokens whose `sub` the seam must refuse: one empty, one missing. Only an `Oidc` actor's seam is driven with these tokens, so on any other route, a `Bearer` or `Signature` one or a public one, the case is refused. Drive a route guarded by an `Oidc` actor. The same holds for `bynk.test.wrong_issuer_needs_oidc_route`, `bynk.test.wrong_audience_needs_oidc_route` and `bynk.test.wrong_algorithm_needs_oidc_route`.",
5034        example: "// demo/api.bynk\nactor User { auth = Bearer(secret = \"S\"), identity = UserId }\nactor Workload { auth = Oidc(…\non GET(\"/me\") () -> Effect[HttpResult[String]] by u: User { … }\non GET(\"/who\") () -> Effect[HttpResult[String]] by w: Workload { … }\n\n// tests/api.test.bynk\nlet r <- api.GET(\"/me\") by NoSubject      // ✗ a `Bearer` route is not an `Oidc` one\nlet r <- api.GET(\"/who\") by NoSubject     // ✓",
5035    },
5036    Explain {
5037        code: "bynk.test.nobody_needs_secured_route",
5038        blurb: "`by Nobody` sends no credential so that a route's auth seam \
5039                answers `401`. A public route, guarded by `Visitor`, has no seam \
5040                that refuses anyone, so the case would test nothing and is \
5041                refused. Use `by Nobody` on a route guarded by a `Bearer`, `Oidc` \
5042                or `Signature` actor, and act as `Visitor` on a public one. For \
5043                the other failure principals, see \
5044                `bynk.test.expired_needs_bearer_route`.",
5045        example: "// demo/api.bynk\n\
5046                  on GET(\"/health\") () -> Effect[HttpResult[Int]] by v: Visitor { … }\n\n\
5047                  // tests/api.test.bynk\n\
5048                  let r <- api.GET(\"/health\") by Nobody     // ✗ a public route has no seam\n\
5049                  let r <- api.GET(\"/health\") by Visitor    // ✓",
5050    },
5051    Explain {
5052        code: "bynk.test.peek_not_a_database",
5053        blurb: "`D1.peek` reads a D1 database, so it names a capability derived \
5054                from `D1` (`capability Orders = D1`). A capability on another \
5055                binding, such as `Kv`, has no database for it to read.",
5056        example: "// shop/orders.bynk\n\
5057                  capability Orders = D1\n\
5058                  capability Sessions = Kv\n\
5059                  \n\
5060                  // tests/orders.test.bynk\n\
5061                  suite shop.orders as system {\n\
5062                  \x20\x20case \"peeks\" {\n\
5063                  \x20\x20\x20\x20let db = D1.peek(shop.orders.Sessions)   // ✗ a `Kv`, not a `D1`\n\
5064                  \x20\x20\x20\x20let ok = D1.peek(shop.orders.Orders)     // ✓\n\
5065                  \x20\x20\x20\x20expect true\n\
5066                  \x20\x20}\n\
5067                  }",
5068    },
5069    Explain {
5070        code: "bynk.test.peek_not_bound",
5071        blurb: "`D1.peek(<participant>.<Capability>)` stands as the value of a \
5072                `let`, and the case reads through the handle that binds. A \
5073                `D1.peek` anywhere else, as an argument or the receiver of a \
5074                call, has no handle to keep.",
5075        example: "// tests/orders.test.bynk\n\
5076                  suite shop.orders as system {\n\
5077                  \x20\x20case \"peeks\" {\n\
5078                  \x20\x20\x20\x20let rows <- D1.peek(shop.orders.Orders).all(\"SELECT id FROM orders\", [])   // ✗ the handle is not bound\n\
5079                  \x20\x20\x20\x20let db = D1.peek(shop.orders.Orders)                                      // ✓\n\
5080                  \x20\x20\x20\x20expect true\n\
5081                  \x20\x20}\n\
5082                  }",
5083    },
5084    Explain {
5085        code: "bynk.test.peek_outside_case",
5086        blurb: "`D1.peek(<participant>.<Capability>)` gives an `integration` or \
5087                `system` case a read-only handle on a participant's test \
5088                database. Only those tiers stand one up, so the handle is \
5089                refused in a `unit` case, a `property`, and in the app's own \
5090                code. A `unit` case reads the capability it stubs.",
5091        example: "// tests/orders.test.bynk\n\
5092                  suite shop.orders {\n\
5093                  \x20\x20case \"peeks\" {\n\
5094                  \x20\x20\x20\x20let db = D1.peek(shop.orders.Orders)   // ✗ a unit suite has no participant database\n\
5095                  \x20\x20\x20\x20expect true\n\
5096                  \x20\x20}\n\
5097                  }\n\
5098                  \n\
5099                  suite shop.orders as system {\n\
5100                  \x20\x20case \"peeks\" {\n\
5101                  \x20\x20\x20\x20let db = D1.peek(shop.orders.Orders)   // ✓\n\
5102                  \x20\x20\x20\x20expect true\n\
5103                  \x20\x20}\n\
5104                  }",
5105    },
5106    Explain {
5107        code: "bynk.test.peek_unknown_capability",
5108        blurb: "`D1.peek` names a capability as `<participant>.<Capability>`, \
5109                where the participant is one of the suite's and declares the \
5110                capability. The participant or the capability is not one.",
5111        example: "// tests/orders.test.bynk\n\
5112                  suite shop.orders as system {\n\
5113                  \x20\x20case \"peeks\" {\n\
5114                  \x20\x20\x20\x20let db = D1.peek(shop.orders.Missing)   // ✗ `shop.orders` declares no `Missing`\n\
5115                  \x20\x20\x20\x20let ok = D1.peek(shop.orders.Orders)    // ✓\n\
5116                  \x20\x20\x20\x20expect true\n\
5117                  \x20\x20}\n\
5118                  }",
5119    },
5120    Explain {
5121        code: "bynk.test.peek_write",
5122        blurb: "A `D1.peek` handle is read-only: it offers `all`, `first`, \
5123                `select[T]` and `firstAs[T]`, and a statement that would write \
5124                (`INSERT`, `UPDATE`, `DELETE`, a schema change) is refused, as is \
5125                `run` or `batch`. A case makes the app write by driving the app.",
5126        example: "// tests/orders.test.bynk\n\
5127                  suite shop.orders as system {\n\
5128                  \x20\x20case \"peeks\" {\n\
5129                  \x20\x20\x20\x20let db = D1.peek(shop.orders.Orders)\n\
5130                  \x20\x20\x20\x20let a <- db.all(\"DELETE FROM orders\", [])   // ✗ the statement writes\n\
5131                  \x20\x20\x20\x20let r <- db.all(\"SELECT id FROM orders\", [])   // ✓\n\
5132                  \x20\x20\x20\x20expect true\n\
5133                  \x20\x20}\n\
5134                  }",
5135    },
5136    Explain {
5137        code: "bynk.test.principal_claims_not_oidc",
5138        blurb: "`TokenClaims.of([…])` supplies the claims an `Oidc` actor's token \
5139                carries, which the handler reads and the actor's rules check. A \
5140                `Bearer` actor's token holds an identity and nothing else, so \
5141                there is no claim set to fill, and the argument is refused. Drop \
5142                the claims, or test a route guarded by an `Oidc` actor. See \
5143                `bynk.test.actor_no_identity` for the other extra argument.",
5144        example: "// tests/api.test.bynk\n\
5145                  let r <- api.GET(\"/me\") by User(\"bob\", TokenClaims.of([\"repository: acme/money\"]))   // ✗ a Bearer actor\n\
5146                  let r <- api.GET(\"/me\") by User(\"bob\")                                               // ✓",
5147    },
5148    Explain {
5149        code: "bynk.test.principal_identity_mismatch",
5150        blurb: "A handler guarded by an actor runs as that actor, so a case must \
5151                act as it, with the identity type it declares. `by Visitor` \
5152                carries no identity, so it cannot stand in for `User`, and an \
5153                actor outside the handler's `by` sum is no member of it. Act as \
5154                the actor the handler names. To exercise an unauthenticated \
5155                request instead, use `by Nobody` in a `system` case.",
5156        example: "// demo/api.bynk\n\
5157                  actor User { … }\n\n\
5158                  // tests/api.test.bynk\n\
5159                  let r <- api.GET(\"/a\") by Visitor        // ✗ the handler is `by u: User`\n\
5160                  let r <- api.GET(\"/a\") by User(\"bob\")    // ✓",
5161    },
5162    Explain {
5163        code: "bynk.test.principal_on_asset",
5164        blurb: "An asset is public: the platform serves it before the Worker runs, so no actor's seam ever sees the request. A `by` clause on an asset fetch would name a principal that nothing checks, so it is refused. Drop the `by`. To test who may reach something, drive a route, not an asset. A method other than `GET` is `bynk.test.asset_address_method`.",
5165        example: "// demo/web.bynk\nasset style = \"assets/board.css\"\n\n// tests/web.test.bynk\nlet r <- api.GET(style) by Visitor    // ✗ an asset has no principal\nlet r <- api.GET(style)               // ✓",
5166    },
5167    Explain {
5168        code: "bynk.test.principal_on_wrong_method",
5169        blurb: "A wrong-method test, such as `DELETE` on a path declared only for \
5170                `GET`, expects the `405` the router returns before any handler is \
5171                chosen. No handler runs, so there is no actor to act as, and a \
5172                `by` clause would suggest otherwise. Drop the `by` clause. To test \
5173                who may call a route, address a method it does declare.",
5174        example: "// tests/api.test.bynk\n\
5175                  let r <- api.DELETE(\"/a\") by User(\"bob\")   // ✗ no handler runs\n\
5176                  let r <- api.DELETE(\"/a\")                  // ✓\n\
5177                  expect r is Rejected(MethodNotAllowed)",
5178    },
5179    Explain {
5180        code: "bynk.test.principal_required",
5181        blurb: "A handler declared `by u: User` runs as a verified actor, and \
5182                a `case` has no real caller, so it must say who is calling \
5183                with a call-site `by`. The same applies to a handler guarded \
5184                by an actor sum: name one of its members. Append `by \
5185                <Actor>(<identity>)` to the call.",
5186        example: "// tests/api.test.bynk\n\
5187                  let r <- api.GET(\"/items\")                  // ✗ who is calling?\n\
5188                  let r <- api.GET(\"/items\") by User(\"ada\")   // ✓",
5189    },
5190    Explain {
5191        code: "bynk.test.service_bad_address",
5192        blurb: "A test addresses an http route by method and route pattern, as in \
5193                `api.POST(\"/items\", body)`. The first argument must be that \
5194                pattern as a string literal, so a number or a variable is refused. \
5195                The same code covers other addresses used the wrong way, such as \
5196                fetching an asset through a service that is not `from http`.",
5197        example: "// demo/api.bynk\n\
5198                  service api from http { … }\n\
5199                  \n\
5200                  // tests/api.test.bynk\n\
5201                  let r <- api.POST(1, \"x\") by Visitor          // ✗ not a pattern\n\
5202                  let r <- api.POST(\"/items\", \"x\") by Visitor   // ✓",
5203    },
5204    Explain {
5205        code: "bynk.test.service_call_arity",
5206        blurb: "`svc.call(…)` in a test runs the service's `on call` handler, so \
5207                it takes that handler's parameters, and the number of arguments is \
5208                checked as for any call. Add or remove arguments to match the \
5209                handler. The asset address, `svc.GET(asset)`, takes the asset \
5210                alone, and this code covers extra arguments there too.",
5211        example: "// demo/svc.bynk\n\
5212                  service echo { … }\n\
5213                  \n\
5214                  // tests/svc.test.bynk\n\
5215                  let r <- echo.call(1, 2)   // ✗ the handler takes one\n\
5216                  let r <- echo.call(1)      // ✓",
5217    },
5218    Explain {
5219        code: "bynk.test.service_no_call_handler",
5220        blurb: "A case reaches a service through the address its protocol has. \
5221                `svc.call(…)` runs an `on call` handler, so it needs one; a `from \
5222                http` service is driven by route (`api.POST(\"/items\", body)`), a \
5223                `from cron` service by its schedule, a `from queue` service by \
5224                message. Use the address the service has. The Book's table of \
5225                addresses lists each.",
5226        example: "// demo/api.bynk\n\
5227                  service api from http { … }\n\
5228                  \n\
5229                  // tests/api.test.bynk\n\
5230                  let r <- api.call(\"x\")                      // ✗ no `on call` handler\n\
5231                  let r <- api.POST(\"/items\", \"x\") by Visitor // ✓ its route",
5232    },
5233    Explain {
5234        code: "bynk.test.service_unknown_route",
5235        blurb: "A case addresses an http route by the pattern its handler \
5236                declares, `\"/items\"`, not a concrete URL, and a cron or queue \
5237                service by its own address. A path that no route in the service \
5238                declares, for any method, is refused. To test the `405` for a \
5239                wrong method, use a declared path with a method it lacks.",
5240        example: "// demo/api.bynk\n\
5241                  service api from http { … }\n\
5242                  \n\
5243                  // tests/api.test.bynk\n\
5244                  let r <- api.POST(\"/item\", \"x\") by Visitor    // ✗ no route \"/item\"\n\
5245                  let r <- api.POST(\"/items\", \"x\") by Visitor   // ✓",
5246    },
5247    Explain {
5248        code: "bynk.test.snapshot_duplicate_name",
5249        blurb: "A snapshot is stored under its case and its name, so each \
5250                `matches snapshot` in one case needs a name of its own. Two \
5251                with the same name would compare against, and update, the same \
5252                stored value. Give the repeat a distinct name.",
5253        example: "expect read(\"a\") matches snapshot \"delivery\"\n\
5254                  expect read(\"b\") matches snapshot \"delivery\"   // ✗ name already taken\n\
5255                  expect read(\"b\") matches snapshot \"second\"     // ✓",
5256    },
5257    Explain {
5258        code: "bynk.test.snapshot_in_property",
5259        blurb: "A snapshot is keyed by its case and name, so it holds one value. A \
5260                `property` runs its body once for each generated input, so there \
5261                is no single value to store. Snapshot a fixed value in a `case`, \
5262                and let the property assert what holds for every input.",
5263        example: "// tests/api.test.bynk\n\
5264                  property \"every n\" {\n\
5265                  \x20\x20\x20\x20for all n: Int {\n\
5266                  \x20\x20\x20\x20\x20\x20\x20\x20expect run(n) matches snapshot \"n\"   // ✗ many inputs, one snapshot\n\
5267                  \x20\x20\x20\x20}\n\
5268                  }\n\n\
5269                  case \"one n\" {\n\
5270                  \x20\x20\x20\x20expect run(3) matches snapshot \"n\"       // ✓\n\
5271                  }",
5272    },
5273    Explain {
5274        code: "bynk.test.snapshot_name_not_literal",
5275        blurb: "A snapshot is stored under its name, so the name must be a \
5276                string literal: the compiler then knows every snapshot a suite \
5277                takes. A variable or other expression is refused. Write the \
5278                name as a literal.",
5279        example: "expect read(\"a\") matches snapshot name        // ✗ not a string literal\n\
5280                  expect read(\"a\") matches snapshot \"first\"     // ✓",
5281    },
5282    Explain {
5283        code: "bynk.test.snapshot_needs_unit_suite",
5284        blurb: "A snapshot is stored in a file beside its unit suite and compared \
5285                by the unit harness, so `matches snapshot` works only in a \
5286                unit-tier `case` of a suite that tests a unit. A `system` case, or \
5287                an integration or system suite, has no store to compare against. \
5288                Take the snapshot in a unit case. See \
5289                `bynk.test.snapshot_in_property` for the other place it is \
5290                refused.",
5291        example: "// tests/api.test.bynk\n\
5292                  suite demo.api as system {\n\
5293                  \x20\x20\x20\x20case \"one n\" {\n\
5294                  \x20\x20\x20\x20\x20\x20\x20\x20expect 3 matches snapshot \"n\"   // ✗ no snapshot store at `system`\n\
5295                  \x20\x20\x20\x20}\n\
5296                  }\n\n\
5297                  suite demo.api {                             // ✓ a unit suite\n\
5298                  \x20\x20\x20\x20case \"one n\" {\n\
5299                  \x20\x20\x20\x20\x20\x20\x20\x20expect 3 matches snapshot \"n\"\n\
5300                  \x20\x20\x20\x20}\n\
5301                  }",
5302    },
5303    Explain {
5304        code: "bynk.test.snapshot_not_codable",
5305        blurb: "A snapshot stores the value as the JSON text `Json.encode` \
5306                produces, so the value must be `Codable`: base types, named \
5307                types and the built-in containers over them. A `Stream`, a \
5308                function, an `Effect` or `()` has no such text. Snapshot a \
5309                `Codable` value instead, such as a list.",
5310        example: "expect Stream.of([1, 2]) matches snapshot \"items\"   // ✗ a `Stream`\n\
5311                  expect [1, 2] matches snapshot \"items\"              // ✓ a `List[Int]`",
5312    },
5313    Explain {
5314        code: "bynk.test.stale_needs_timestamp",
5315        blurb: "A `Signature` actor refuses a stale request by reading a timestamp header and comparing it with a `tolerance`. `by Stale` signs a request in the past, so it means something only when the actor declares both; without them the seam has no window to refuse it by, and the case would test nothing. Add `timestamp = \"<Header>\"` and `tolerance = <seconds>` to the actor, or test the signature itself with `by Forged`. On a route with no `Signature` actor, see `bynk.test.forged_needs_signature_route`.",
5316        example: "// demo/api.bynk\nactor Legacy { auth = Signature(secret = \"LEGACY_SECRET\", header = \"X-Legacy-Sig\") }\nactor Hook { auth = Signature(secret = \"HOOK_SECRET\", header = \"X-Sig\", timestamp = \"X-Ts\", tolerance = 300) }\n\n// tests/api.test.bynk\nlet r <- api.POST(\"/legacy\", \"x\") by Stale    // ✗ `Legacy` declares no `timestamp`\nlet r <- api.POST(\"/hook\", \"x\") by Stale      // ✓",
5317    },
5318    Explain {
5319        code: "bynk.test.system_claims_need_literal",
5320        blurb: "At `system` the driver mints an `Oidc` actor's token itself, writing its claims from the `\"name: value\"` lines of the `TokenClaims.of([…])` in the `by` clause. A `TokenClaims` held in a variable is opaque: it can be read with `get` and `has`, but its lines cannot be recovered, so the driver has nothing to mint from and the case is refused rather than sent with no claims. Write `TokenClaims.of([…])` in the principal, or move the case to `integration`, where the handler is given the value as it is.",
5321        example: "// tests/api.test.bynk\nlet claims = TokenClaims.of([\"repository: acme/money\"])\nlet r <- api.GET(\"/who\") by Workload(\"wid\", claims)    // ✗ the claims are in a variable\nlet r <- api.GET(\"/who\") by Workload(\"wid\", TokenClaims.of([\"repository: acme/money\"]))    // ✓",
5322    },
5323    Explain {
5324        code: "bynk.test.unknown_actor",
5325        blurb: "A call-site `by <Actor>` makes the case act as that actor, so \
5326                it must name an `actor` the target context declares, or one of \
5327                the prelude actors such as `Visitor` and `Caller`. Any other \
5328                name, often a misspelling, has no identity to supply. Correct \
5329                the name or declare the actor.",
5330        example: "// demo/api.bynk\n\
5331                  actor User { auth = Bearer(secret = \"S\"), identity = UserId }\n\n\
5332                  // tests/api.test.bynk\n\
5333                  let r <- api.GET(\"/items\") by Ghost(\"x\")   // ✗ no actor `Ghost`\n\
5334                  let r <- api.GET(\"/items\") by User(\"x\")    // ✓",
5335    },
5336    Explain {
5337        code: "bynk.test.wire_http_only",
5338        blurb: "`Wire(…)` delivers raw text to an http body or path segment. A \
5339                queue message, a cron tick, an `on call` or an event has no raw \
5340                text form: it is a typed value, and `Wire` would hand it to a \
5341                typed decoder as a string and fail confusingly at run time. Pass \
5342                the typed value. To drive an http route with raw text, see \
5343                `bynk.test.wire_needs_system`.",
5344        example: "// demo/api.bynk\n\
5345                  service packer from queue(\"packing\") { … }\n\n\
5346                  // tests/api.test.bynk\n\
5347                  let r <- packer.message(Wire(\"{}\"))   // ✗ a queue takes a typed message\n\
5348                  let r <- packer.message(\"{}\")         // ✓",
5349    },
5350    Explain {
5351        code: "bynk.test.wire_needs_system",
5352        blurb: "`Wire(…)` hands raw text to the real boundary, before any \
5353                decoding, so that a case can check what the boundary refuses. Only \
5354                a `system` case has a real boundary: below it the handler is \
5355                called directly, and the text would go in unchecked. Promote the \
5356                case with `as system`, or pass a typed value instead. For other \
5357                addresses, see `bynk.test.wire_http_only`.",
5358        example: "// tests/api.test.bynk\n\
5359                  case \"raw text is refused\" {            // ✗ not a system case\n\
5360                  case \"raw text is refused\" as system {  // ✓\n\
5361                  \x20\x20\x20\x20let r <- api.POST(\"/n\", Wire(\"0\")) by Visitor\n\
5362                  \x20\x20\x20\x20expect r is Rejected(RefinementViolation(_))\n\
5363                  }",
5364    },
5365    Explain {
5366        code: "bynk.test.wrong_algorithm_needs_oidc_route",
5367        blurb: "`by WrongAlgorithm` sends two otherwise valid tokens under an algorithm the seam must refuse: one with `alg: none`, and one `HS256`-signed with the JWKS public key as the secret. Only an `Oidc` actor's seam is driven with these tokens, so on any other route, a `Bearer` or `Signature` one or a public one, the case is refused. Drive a route guarded by an `Oidc` actor. The same holds for `bynk.test.wrong_issuer_needs_oidc_route`, `bynk.test.wrong_audience_needs_oidc_route` and `bynk.test.no_subject_needs_oidc_route`.",
5368        example: "// demo/api.bynk\nactor User { auth = Bearer(secret = \"S\"), identity = UserId }\nactor Workload { auth = Oidc(…\non GET(\"/me\") () -> Effect[HttpResult[String]] by u: User { … }\non GET(\"/who\") () -> Effect[HttpResult[String]] by w: Workload { … }\n\n// tests/api.test.bynk\nlet r <- api.GET(\"/me\") by WrongAlgorithm      // ✗ a `Bearer` route is not an `Oidc` one\nlet r <- api.GET(\"/who\") by WrongAlgorithm     // ✓",
5369    },
5370    Explain {
5371        code: "bynk.test.wrong_audience_needs_oidc_route",
5372        blurb: "`by WrongAudience` sends a correctly signed, unexpired token whose `aud` is not the actor's audience. Only an `Oidc` actor has an audience to check: a `Bearer` token has none, and a `Signature` or public route has no token. On any other route the case is refused. Drive a route guarded by an `Oidc` actor. The same holds for `bynk.test.wrong_issuer_needs_oidc_route`, `bynk.test.wrong_algorithm_needs_oidc_route` and `bynk.test.no_subject_needs_oidc_route`.",
5373        example: "// demo/api.bynk\nactor User { auth = Bearer(secret = \"S\"), identity = UserId }\nactor Workload { auth = Oidc(…\non GET(\"/me\") () -> Effect[HttpResult[String]] by u: User { … }\non GET(\"/who\") () -> Effect[HttpResult[String]] by w: Workload { … }\n\n// tests/api.test.bynk\nlet r <- api.GET(\"/me\") by WrongAudience      // ✗ a `Bearer` token has no audience\nlet r <- api.GET(\"/who\") by WrongAudience     // ✓",
5374    },
5375    Explain {
5376        code: "bynk.test.wrong_issuer_needs_oidc_route",
5377        blurb: "`by WrongIssuer` sends a correctly signed, unexpired token whose `iss` is not the actor's issuer. Only an `Oidc` actor has an issuer to check: a `Bearer` token has none, and a `Signature` or public route has no token. On any other route the case is refused. Drive a route guarded by an `Oidc` actor. The same holds for `bynk.test.wrong_audience_needs_oidc_route`, `bynk.test.wrong_algorithm_needs_oidc_route` and `bynk.test.no_subject_needs_oidc_route`.",
5378        example: "// demo/api.bynk\nactor User { auth = Bearer(secret = \"S\"), identity = UserId }\nactor Workload { auth = Oidc(…\non GET(\"/me\") () -> Effect[HttpResult[String]] by u: User { … }\non GET(\"/who\") () -> Effect[HttpResult[String]] by w: Workload { … }\n\n// tests/api.test.bynk\nlet r <- api.GET(\"/me\") by WrongIssuer      // ✗ a `Bearer` token has no issuer\nlet r <- api.GET(\"/who\") by WrongIssuer     // ✓",
5379    },
5380    Explain {
5381        code: "bynk.test.ws_lifecycle_by",
5382        blurb: "A WebSocket connection's principal is given once, at `open`, and the connection carries it from there, as the platform recovers it from the socket. So `message` and `close` take no `by`: a case that named one could present a principal production never sees. Drop the `by`. To act as another principal, open a new `TestConnection`.",
5383        example: "// tests/room.test.bynk\nlet tc = TestConnection[Frame]()\nlet _ <- Gateway.open(tc, RoomId.unsafe(\"r\")) by Member(UserId.unsafe(\"ann\"))\nlet _ <- Gateway.message(tc, Frame { text: \"hi\" }) by Member(UserId.unsafe(\"ann\"))    // ✗ given at `open`\nlet _ <- Gateway.message(tc, Frame { text: \"hi\" })                                    // ✓",
5384    },
5385    Explain {
5386        code: "bynk.test.ws_needs_in_process",
5387        blurb: "`svc.open(tc, …)`, `svc.message` and `svc.close` drive a `from websocket` service in process, against a `TestConnection`. A deployed WebSocket is a real upgrade through the Worker and a Durable Object, which a `system` case does not drive, so the address has nothing to run. Drive the service in a case at `unit` or `integration` instead.",
5388        example: "// tests/room.test.bynk\ncase \"a join\" as system {         // ✗ a `system` case cannot drive a WebSocket\ncase \"a join\" as integration {    // ✓\n    let tc = TestConnection[Frame]()\n    let _ <- Gateway.open(tc, Val[RoomId]) by Member(Val[UserId])\n}",
5389    },
5390    Explain {
5391        code: "bynk.tier.cross_context_needs_system",
5392        blurb: "Below `system` a case runs in one process. No other context is stood up, so a `unit` or `integration` case, or a `property`, that reaches another context's service, directly or through a service or agent handler, has nothing to call unless the service is stubbed: `stub Pay.authorise(_) returns …` substitutes it, and only the services left unstubbed are reported. Stub each service the case reaches, promote the case to a `system` suite, which wires the contexts, or test the unit that does not cross.",
5393        example: "suite demo.desk {\n    case \"the desk checks\" {\n        let n <- check.call(5)   // ✗ `check` calls `demo.vault`, another context\n    }\n}\n\nsuite demo.desk as system {\n    case \"the desk checks\" {\n        let n <- demo.desk.check(5)   // ✓ both contexts are stood up\n    }\n}",
5394    },
5395    Explain {
5396        code: "bynk.tier.mixed_system_suite",
5397        blurb: "A `system` case runs against deployed Workers and addresses services by their context path, which no `unit` or `integration` case can. So a suite holds either `system` cases only or none: a case of another tier in a `system` suite, or a `system` case among others, is refused. Move it into a suite of its own.",
5398        example: "suite demo.desk as system {\n    case \"a local one\" as unit {   // ✗ not `system`, in a `system` suite\n        let n <- local.call(1)\n    }\n}\n\nsuite demo.desk {\n    case \"a local one\" {   // ✓ in a suite of its own\n        let n <- local.call(1)\n    }\n}",
5399    },
5400    Explain {
5401        code: "bynk.tier.system_needs_wire",
5402        blurb: "A `system` case exists to cross a real serialise, JSON, deserialise boundary. A target has one if it consumes another context, or exposes an `http`, `queue` or `email` service. One with neither has nothing to cross, so a `system` suite adds nothing over `unit`. Run the suite at `unit` or `integration`, or give the target a service that has a boundary.",
5403        example: "suite commerce.payment as system {   // ✗ no other context, and no `http`, `queue` or `email` service\n    case \"authorises\" { … }\n}\n\nsuite commerce.payment as integration {   // ✓ real collaborators, no wire\n    case \"authorises\" { … }\n}",
5404    },
5405    Explain {
5406        code: "bynk.transition.cross_agent_reference",
5407        blurb: "A transition is checked inside one agent's commit, between that agent's own old and new states. Reading another agent would mean a call out to it, whose value could change before the commit lands, so the claim could not be held. A property that spans agents belongs in a saga or a scenario. Keep the transition to this agent's `old` and `new`. The mirror rule for states is `bynk.invariant.cross_agent_reference`.",
5408        example: "transition within_total: new.count <= Total(\"all\").get()   // ✗ reads another agent\n\ntransition grows: new.count >= old.count                   // ✓ this agent's own step",
5409    },
5410    Explain {
5411        code: "bynk.transition.duplicate_name",
5412        blurb: "Transitions are named so that a violation can say which step rule was broken. Two with the same name in one agent would make that report ambiguous. Rename one, or merge the two predicates if they are one claim. The same rule for states is `bynk.invariant.duplicate_name`.",
5413        example: "transition grows: new.count >= old.count\ntransition grows: new.count < 100    // ✗ `grows` is already declared\n\ntransition capped: new.count < 100   // ✓ a distinct name",
5414    },
5415    Explain {
5416        code: "bynk.transition.impure_predicate",
5417        blurb: "A transition is checked at each commit, over the old and new states, so it may only read: `old`, `new`, operators and pure value methods. `Effect.pure`, `?`, `expect`, `Val` and the other test-only forms are refused, as is anything that performs an effect. Rewrite the predicate as a plain `Bool` expression. The mirror rule for states is `bynk.invariant.impure_predicate`.",
5418        example: "transition grows: Effect.pure(new.count >= old.count)   // ✗ an effect, not a pure predicate\n\ntransition grows: new.count >= old.count                // ✓ a plain `Bool` expression",
5419    },
5420    Explain {
5421        code: "bynk.transition.no_step_reference",
5422        blurb: "A transition constrains a step, so it has to compare the state before the commit (`old`) with the state after (`new`). One that mentions neither is a claim about a single state, which an `invariant` states more plainly and checks the same way. Use `old` and `new`, or write it as an `invariant`.",
5423        example: "transition grows: count >= 0               // ✗ names neither `old` nor `new`\n\ntransition grows: new.count >= old.count   // ✓ compares the two states",
5424    },
5425    Explain {
5426        code: "bynk.transition.not_bool",
5427        blurb: "A `transition` is a claim about a step, from `old` to `new`, that is either kept or broken, so its predicate must be a `Bool`. A bare `new.count` is a value, not a claim. Compare it with the old state: `new.count >= old.count`. An `invariant` is held to the same rule (`bynk.invariant.not_bool`).",
5428        example: "transition grows: new.count                // ✗ an `Int`, not a `Bool`\n\ntransition grows: new.count >= old.count   // ✓ a claim about the step",
5429    },
5430    Explain {
5431        code: "bynk.types.argument_mismatch",
5432        blurb: "An argument has a different type from the parameter it is passed to. Bynk \
5433                compares types exactly and converts nothing implicitly, so a `String` is \
5434                never read as an `Int`, and a call that passes the wrong type is refused \
5435                at the call, not left to fail later. The same code covers the arguments of \
5436                methods, capability operations and constructors. Pass a value of the \
5437                parameter's type, or convert it first with an explicit conversion such as \
5438                `Int.parse` (which returns an `Option`, because the text may not be a number).",
5439        example: "fn double(n: Int) -> Int {\n    n * 2\n}\n\n\
5440                  fn run() -> Int {\n    double(\"21\")    // ✗ a `String`, where `Int` is expected\n}\n\n\
5441                  fn run() -> Int {\n    double(21)      // ✓ an `Int`\n}",
5442    },
5443    Explain {
5444        code: "bynk.types.asset_at_boundary",
5445        blurb: "An `Asset` names a file the platform serves; it is not data to keep or send. So an \
5446                `Asset` cannot be a record field, a sum payload, an event field, an agent key or \
5447                store field, or part of a service or agent handler signature. What crosses is its \
5448                `.url`, a `String`: hold that instead. Other types refused there include \
5449                `bynk.types.function_at_boundary` and `bynk.types.held_at_boundary`.",
5450        example: "type Page = {\n    title: String,\n    style: Asset,     // ✗ an asset is not a value to hold\n}\n\ntype Page = {\n    title: String,\n    style: String,    // ✓ keep its `.url`\n}",
5451    },
5452    Explain {
5453        code: "bynk.types.bad_field_default",
5454        blurb: "A field default, `field: T = expr`, is filled in whenever a literal leaves the \
5455                field out and whenever a decoded body omits its key, so it has to be a fixed \
5456                value that has a wire form. The compiler accepts a literal, a variant, \
5457                `Some`, `None`, `Ok` or `Err`, a record or list literal, `Map.empty()`, \
5458                `Set.empty()`, and `T.unsafe(lit)` for an opaque type. A call to your own \
5459                function, or a read of a binding, is refused: a default has to be a value known \
5460                when the program compiles, not something computed at every construction \
5461                and decode. In a generic record, a field whose type is the type parameter itself cannot have a \
5462                default at all, since one value cannot suit every instantiation. Write the \
5463                value out as a literal, or drop the default and require the field.",
5464        example: "fn three() -> Int { 3 }\n\n\
5465                  type Config = {\n  retries: Int = three(),    // ✗ a call is not a static value\n}\n\n\
5466                  type Config = {\n  retries: Int = 3,          // ✓ a literal\n}",
5467    },
5468    Explain {
5469        code: "bynk.types.call_arity",
5470        blurb: "A function value was called with a different number of arguments from the \
5471                number its type declares. A parameter or local of type `(Int, Int) -> Int` \
5472                takes exactly two, and the call is checked against that type, so the \
5473                mismatch is reported where it is made. The same code covers the built-in \
5474                operations of `Map`, `Set`, `Cell`, `Cache` and `Log`, and `unreachable` and \
5475                `todo`, which each take one message. Pass exactly the declared number. A \
5476                declared `fn` called with the wrong number of arguments is the separate code \
5477                `bynk.resolve.arity_mismatch`, and a method is `bynk.types.method_arity`.",
5478        example: "fn apply(f: (Int, Int) -> Int) -> Int {\n    f(1)       // ✗ `f` takes 2 arguments\n}\n\n\
5479                  fn apply(f: (Int, Int) -> Int) -> Int {\n    f(1, 2)    // ✓\n}",
5480    },
5481    Explain {
5482        code: "bynk.types.cannot_infer_option_type_param",
5483        blurb: "`None` carries no value, so its `Option[T]` takes `T` from where it is used: an annotation, a parameter, or the function's return type. A `let` of a bare `None` has none, and the compiler will not guess, because `T` becomes part of everything the binding touches. Annotate it, as in `let missing: Option[Int] = None`, or use `None` where an `Option` is expected.",
5484        example: "fn run() -> Int {\n    let missing = None    // ✗ an `Option` of what?\n    1\n}\n\nfn run() -> Int {\n    let missing: Option[Int] = None    // ✓\n    1\n}",
5485    },
5486    Explain {
5487        code: "bynk.types.cannot_infer_result_type_params",
5488        blurb: "`Ok(v)` fixes only the success type and `Err(e)` only the error type, so the rest of the `Result` has to come from context: an annotation, a parameter type, or the enclosing function's return type. A bare `let r = Ok(1)` has neither, and the compiler will not guess. Annotate the binding, as in `let r: Result[Int, String] = Ok(1)`.",
5489        example: "fn run() -> Int {\n    let r = Ok(1)    // ✗ a `Result` of what error?\n    1\n}\n\nfn run() -> Int {\n    let r: Result[Int, String] = Ok(1)    // ✓\n    1\n}",
5490    },
5491    Explain {
5492        code: "bynk.types.catastrophic_regex",
5493        blurb: "A `Matches` pattern, and the pattern of a regex method such as \
5494                `matchesRegex` or `replaceRegex`, is analysed when the program compiles. \
5495                Patterns run with JavaScript's backtracking `RegExp`, and one in which a \
5496                repetition can split the same text several ways takes exponential time on a \
5497                crafted near miss, so a few dozen characters of input could stall a handler. \
5498                Nested or ambiguous repetition, such as `(a+)+` or `(a|aa)+`, is refused, \
5499                bounded or not, as is a backreference under an unbounded quantifier, an unbounded quantifier over a \
5500                body that can match the empty string, and a pattern too large or complex to \
5501                analyse. Rewrite it so each repetition has one way to match: `a+` for `(a+)+`, \
5502                or a separator the repeated part cannot match, as in `[a-z]+(-[a-z]+)*`. \
5503                Two adjacent repetitions that compete, as in `\\d*\\d*`, are the milder \
5504                `bynk.types.polynomial_regex`.",
5505        example: "type Code = String where Matches(\"(a+)+$\")    // ✗ nested unbounded repetition\n\n\
5506                  type Code = String where Matches(\"a+$\")       // ✓ one way to match",
5507    },
5508    Explain {
5509        code: "bynk.types.claims_at_boundary",
5510        blurb: "An `Oidc` actor's binder carries the verified token's claims (`who.claims`) for the \
5511                handler that received the token. They are read there and never kept: a \
5512                `TokenClaims` can't be a field, or cross a call, a message or an agent. Read the \
5513                claim you need and keep that `String`.",
5514        example: "type Seen = { claims: TokenClaims }                 // ✗\n\n\
5515                  let repo = w.claims.get(\"repository\")            // ✓ keep the String",
5516    },
5517    Explain {
5518        code: "bynk.types.combinator_return_mismatch",
5519        blurb: "The function given to a combinator must return the shape the combinator \
5520                chains on. `Option.andThen` wants an `Option` back and `Result.andThen` a \
5521                `Result` whose error type matches the receiver's, so that the result is \
5522                flattened, not nested. `List.flatMap` wants a `List` and `Query.flatMap` a \
5523                `Query`. The effectful iterators and `flatMapOk` and `flatMapErr` want an \
5524                `Effect[Result[…]]`, and `Option.orElse` wants the receiver's own `Option` \
5525                type. If your function returns a plain value, you want `map`, which wraps it \
5526                for you. Otherwise wrap the value yourself, as `Some(n + 1)`, or fix the \
5527                function's result. A callback of the wrong type for the combinator's own \
5528                signature is `bynk.types.argument_mismatch`.",
5529        example: "fn bump(o: Option[Int]) -> Option[Int] {\n    o.andThen((n) => n + 1)    // ✗ must return an `Option`, not an `Int`\n}\n\n\
5530                  fn bump(o: Option[Int]) -> Option[Int] {\n    o.map((n) => n + 1)        // ✓ `map` wraps a plain value\n}",
5531    },
5532    Explain {
5533        code: "bynk.types.constructor_arity",
5534        blurb: "`T.of(value)` takes exactly one argument, the base value to check, and so does `T.unsafe(value)` on an opaque type: a refined or opaque type wraps a single value. None gives it nothing to check, and two have no meaning. Pass the one value. Building a sum variant with the wrong number of arguments is `bynk.types.variant_arity`.",
5535        example: "type Age = Int where InRange(0, 150)\n\nfn parse(n: Int) -> Result[Age, ValidationError] {\n    Age.of(n, 1)    // ✗ `of` takes 1 argument\n}\n\nfn parse(n: Int) -> Result[Age, ValidationError] {\n    Age.of(n)    // ✓\n}",
5536    },
5537    Explain {
5538        code: "bynk.types.constructor_base_mismatch",
5539        blurb: "`Reps.of(x)` checks a value of the type's base against its predicates, so `x` must already be that base: an `Int` for `Reps`. The constructor validates; it does not convert, so a `String` is refused before any predicate runs. Turn the value into the base first, such as with `Int.parse`, or take it as the base type. `Reps.unsafe` on an opaque type has the same rule.",
5540        example: "type Reps = Int where InRange(1, 100)\n\nfn parse(s: String) -> Result[Reps, ValidationError] {\n    Reps.of(s)        // ✗ `Reps.of` takes an `Int`\n}\n\nfn parse(n: Int) -> Result[Reps, ValidationError] {\n    Reps.of(n)        // ✓\n}",
5541    },
5542    Explain {
5543        code: "bynk.types.decimal_division_unscaled",
5544        blurb: "`Decimal` is exact, and a quotient often has no exact decimal answer (one third), so \
5545                `/` is not defined on it. `div` says what `/` leaves out: how many decimal places to \
5546                keep and how to round. `+`, `-` and `*` stay exact. Write \
5547                `a.div(b, 2, RoundingMode.HalfEven)`, with the scale and mode you need.",
5548        example: "fn share(total: Decimal, ways: Decimal) -> Decimal {\n    total / ways    // ✗ no exact quotient\n}\n\nfn share(total: Decimal, ways: Decimal) -> Decimal {\n    total.div(ways, 2, RoundingMode.HalfEven)    // ✓ two places, rounded\n}",
5549    },
5550    Explain {
5551        code: "bynk.types.derives_automatic",
5552        blurb: "`derives` opts a type into a capability it does not have by default, and `Ord` is the only one: it needs every field to be orderable, so you ask for it. `Eq`, `Key` and `Codable` hold for a type without being asked, so naming one does nothing, and the compiler refuses it rather than leave a clause that suggests it matters. Remove the name, which the compiler's fix does. Any other name is `bynk.generics.unknown_constraint`.",
5553        example: "type Point = { x: Int, y: Int } derives Eq    // ✗ `Eq` holds already\n\ntype Point = { x: Int, y: Int }               // ✓",
5554    },
5555    Explain {
5556        code: "bynk.types.derives_field_not_orderable",
5557        blurb: "`derives Ord` orders a type field by field, in declaration order, so every field or payload must itself have an order. A `Bool`, a `Map`, a `Set`, a function, and a named type that does not derive `Ord` itself have none. Change the field to an orderable type, such as an `Int` rank, or give the field's own type `derives Ord`, or drop `derives Ord` and sort by a key with `sortBy`.",
5558        example: "type Task = { title: String, done: Bool } derives Ord        // ✗ a `Bool` has no order\n\ntype Task = { title: String, priority: Int } derives Ord      // ✓",
5559    },
5560    Explain {
5561        code: "bynk.types.duplicate_example",
5562        blurb: "`@example` gives `Val` the one value to use for a `Matches` or `IsoDate` refinement, which it cannot invent. A second `@example` would leave two candidates and no rule for choosing, so a refinement takes at most one. Keep the one you want. An example that does not satisfy the refinement is `bynk.types.example_violates`.",
5563        example: "type Code = String where Matches(\"[A-Z]{3}\") @example(\"ABC\") @example(\"XYZ\")    // ✗ a second example\n\ntype Code = String where Matches(\"[A-Z]{3}\") @example(\"ABC\")                       // ✓",
5564    },
5565    Explain {
5566        code: "bynk.types.duplicate_literal_arm",
5567        blurb: "A `match` takes the first arm whose pattern fits, so a literal that an earlier unguarded arm already has can never reach a second arm. Bynk refuses the dead arm rather than let it hide a mistake, usually a mistyped value. Change the literal or delete the arm. An or-pattern is checked alternative by alternative, so `1 | 2` followed by `2` is caught as well. The same for a variant is `bynk.types.duplicate_variant_arm`.",
5568        example: "fn word(n: Int) -> String {\n    match n {\n        1 => \"one\"\n        1 => \"uno\"    // ✗ `1` is already matched above\n        _ => \"other\"\n    }\n}\n\nfn word(n: Int) -> String {\n    match n {\n        1 => \"one\"\n        2 => \"two\"    // ✓\n        _ => \"other\"\n    }\n}",
5569    },
5570    Explain {
5571        code: "bynk.types.duplicate_pattern_field",
5572        blurb: "A record pattern lists the fields it reads, and each may be named once. Naming a field twice would bind or test the same value twice, which is almost always a slip for a different field. Keep one mention, and give it the name you want to use, as in `total: t`. The `..` at the end covers every field you leave out.",
5573        example: "type Order = { id: String, total: Int }\n\nfn amount(o: Order) -> Int {\n    match o {\n        Order { total, total: t, .. } => t    // ✗ `total` is named twice\n    }\n}\n\nfn amount(o: Order) -> Int {\n    match o {\n        Order { total: t, .. } => t           // ✓\n    }\n}",
5574    },
5575    Explain {
5576        code: "bynk.types.duplicate_variant_arm",
5577        blurb: "A `match` runs the first arm that fits, so a second unguarded arm for a variant that an earlier arm already covers can never run. Bynk refuses the dead arm rather than let it hide a slip, usually a copied arm whose pattern was never changed. Delete it, or change it to the variant you meant. Arms are compared by shape, so `Err(A)` and `Err(B)` are not duplicates. The same mistake with a literal is `bynk.types.duplicate_literal_arm`.",
5578        example: "type Light = | Red | Green\n\nfn go(l: Light) -> Int {\n    match l {\n        Red => 1\n        Red => 2      // ✗ `Red` is already matched above\n        Green => 3\n    }\n}\n\nfn go(l: Light) -> Int {\n    match l {\n        Red => 1\n        Green => 2    // ✓ each variant once\n    }\n}",
5579    },
5580    Explain {
5581        code: "bynk.types.embeds_ambiguous",
5582        blurb: "`embeds E as V` lets `?` wrap an `E` error in the variant `V`. It picks the variant by \
5583                the error's type, so a type may be embedded once: with two variants wrapping \
5584                `PayError`, `?` could not tell which one an error belongs to. Embed the type in one \
5585                variant, and build the other by hand where you want it.",
5586        example: "type OrderError =\n    | Payment(reason: PayError)\n    | Refund(reason: PayError)\n    embeds PayError as Payment, PayError as Refund    // ✗ `PayError` twice\n\ntype OrderError =\n    | Payment(reason: PayError)\n    | Refund(reason: PayError)\n    embeds PayError as Payment    // ✓ once",
5587    },
5588    Explain {
5589        code: "bynk.types.embeds_unknown_variant",
5590        blurb: "`embeds E as V` lets `?` wrap an `E` error in the variant `V` of the same sum, so `V` \
5591                must be one of that sum's variants. Here it names none, usually a misspelling. \
5592                Correct the name, or add the variant it should wrap into.",
5593        example: "type OrderError =\n    | Payment(reason: PayError)\n    embeds PayError as Pay        // ✗ no variant `Pay`\n\ntype OrderError =\n    | Payment(reason: PayError)\n    embeds PayError as Payment    // ✓",
5594    },
5595    Explain {
5596        code: "bynk.types.embeds_variant_shape",
5597        blurb: "`embeds E as V` has `?` wrap an `E` error into `V`, so `V` must take exactly that: one \
5598                payload field, of type `E`. A variant with a payload of another type, or with more \
5599                or fewer fields, has nowhere to put the error. Give `V` a single field of type `E`, \
5600                or embed a different variant.",
5601        example: "type OrderError =\n    | Payment(reason: String)\n    embeds PayError as Payment    // ✗ the payload is a `String`\n\ntype OrderError =\n    | Payment(reason: PayError)\n    embeds PayError as Payment    // ✓",
5602    },
5603    Explain {
5604        code: "bynk.types.empty_range_pattern",
5605        blurb: "A range pattern `lo..hi` matches every `Int` from `lo` to `hi`, both \
5606                inclusive, so the low bound comes first. With `lo > hi` no value can match, \
5607                so the arm is dead and almost certainly a typo, and the same goes for a range \
5608                in a `via schema(...)` clause. Swap the bounds. A refinement \
5609                written `InRange(150, 0)` is the separate `bynk.types.inverted_range`.",
5610        example: "fn band(n: Int) -> String {\n    match n {\n        9..3 => \"mid\"    // ✗ the low bound is above the high bound\n        _ => \"other\"\n    }\n}\n\n\
5611                  fn band(n: Int) -> String {\n    match n {\n        3..9 => \"mid\"    // ✓\n        _ => \"other\"\n    }\n}",
5612    },
5613    Explain {
5614        code: "bynk.types.empty_refinement",
5615        blurb: "A refinement is a base type plus predicates, and a value must satisfy all of \
5616                them. When the predicates contradict each other, nothing can satisfy them: \
5617                the type has no values, and every `.of` and every boundary check would fail. \
5618                The compiler works out the combined range of `Positive`, `NonNegative` and \
5619                `InRange`, and the combined length of the length predicates, and refuses one \
5620                that is empty. Drop or correct the predicate that conflicts, and read the \
5621                note, which gives the empty range it found.",
5622        example: "type Debt = Int where Positive && InRange(-10, -1)    // ✗ positive, yet at most -1\n\n\
5623                  type Debt = Int where Positive && InRange(1, 10)      // ✓",
5624    },
5625    Explain {
5626        code: "bynk.types.err_value_mismatch",
5627        blurb: "`Err(e)` takes its error type from the surrounding `Result[T, E]`, the annotation or the function's return type, so `Err(404)` where `E` is `String` is refused at the value, with no conversion. Pass an `E`, or change the declared error type. The success half is `bynk.types.ok_value_mismatch`; with nothing to fix the `Result`, it is `bynk.types.cannot_infer_result_type_params`.",
5628        example: "fn total() -> Result[Int, String] {\n    Err(404)    // ✗ an `Int`, where the error type is `String`\n}\n\nfn total() -> Result[Int, String] {\n    Err(\"not found\")    // ✓\n}",
5629    },
5630    Explain {
5631        code: "bynk.types.example_not_literal",
5632        blurb: "`@example` takes exactly one literal of the refinement's base type. It is read where \
5633                the type is declared, not evaluated, so a call such as `Code.of(\"ABC\")`, a name or \
5634                a literal of another type is refused. Write the value itself, as a string for a \
5635                `String` base.",
5636        example: "type Code = String where Matches(\"[A-Z]{3}\") @example(Code.of(\"ABC\"))    // ✗ a call, not a literal\n\ntype Code = String where Matches(\"[A-Z]{3}\") @example(\"ABC\")            // ✓\n\nconst Sample: String = \"ABC\"\ntype Tag = String where Matches(\"[A-Z]{3}\") @example(Sample)   // ✓ a `String` constant bound to a literal",
5637    },
5638    Explain {
5639        code: "bynk.types.example_on_named_field",
5640        blurb: "On a record field, `@example` pins the field's own value, which exists only where \
5641                the field has a base type. A field of a named type takes its value from that type, \
5642                so an example on the field would have no effect and is refused. Put the \
5643                `@example` on the named type's declaration, where `Val` reads it.",
5644        example: "type Code = String where Matches(\"[A-Z]{3}\")\ntype Ticket = { code: Code where Matches(\"[A-Z]+\") @example(\"ABC\") }    // ✗ `Code` is a named type\n\ntype Code = String where Matches(\"[A-Z]{3}\") @example(\"ABC\")    // ✓ pin it on the type\ntype Ticket = { code: Code }",
5645    },
5646    Explain {
5647        code: "bynk.types.example_unneeded",
5648        blurb: "`Val` cannot invent a string that matches a pattern, so a `Matches` or `IsoDate` \
5649                refinement takes an `@example` for it to use. Every other refinement already has a \
5650                value `Val` makes, so there is nothing for the example to do and it is refused. \
5651                Remove the annotation.",
5652        example: "type Sku = String where NonEmpty @example(\"a\")    // ✗ `Val` already makes one\n\ntype Sku = String where NonEmpty                  // ✓",
5653    },
5654    Explain {
5655        code: "bynk.types.example_violates",
5656        blurb: "`@example` is the value `Val` uses for a type it cannot fabricate, so it must be a \
5657                valid one. The compiler checks it where the type is declared, against every \
5658                predicate of the refinement, whether or not a test uses it; an example that fails \
5659                one would give tests a value the type refuses. Write an example that satisfies the \
5660                whole refinement.",
5661        example: "type Code = String where Matches(\"[A-Z]{3}\") @example(\"abc\")    // ✗ lower case\n\ntype Code = String where Matches(\"[A-Z]{3}\") @example(\"ABC\")    // ✓",
5662    },
5663    Explain {
5664        code: "bynk.types.extensible_match_needs_wildcard",
5665        blurb: "Some standard-library enums, among them `FetchError` and `Method`, are \
5666                extensible: a minor release may add a variant. A `match` that names every \
5667                variant they have today would then stop covering them, so the compiler asks \
5668                for a wildcard arm now, and the `match` keeps compiling when a variant \
5669                arrives. Listing every current variant is not enough. Add `_`, or `Err(_)` \
5670                where the enum is wrapped, and put there whatever should happen for a \
5671                variant you did not name. An enum of your own with the same name is not \
5672                extensible; the rule follows the first-party enum. For an ordinary enum, a \
5673                missing arm is `bynk.types.non_exhaustive_match`.",
5674        example: "fn verb(m: Method) -> String {\n    match m {           // ✗ every variant, but no wildcard\n        Get => \"read\"\n        Post => \"write\"\n        Put => \"write\"\n        Delete => \"write\"\n        Patch => \"write\"\n        Head => \"read\"\n        Options => \"read\"\n    }\n}\n\n\
5675                  fn verb(m: Method) -> String {\n    match m {\n        Get => \"read\"\n        _ => \"write\"       // ✓ also covers variants added later\n    }\n}",
5676    },
5677    Explain {
5678        code: "bynk.types.field_access_on_non_record",
5679        blurb: "`.name` reads a field, and only a record has fields. A `String`, an `Int` or a `List` has methods instead, called with parentheses, so `name.length` is not a field read but `name.length()` is a call. A refined type is already its base type, so there is nothing to unwrap. To get at a sum type's payload, use `match`. A field a record lacks is `bynk.types.unknown_field`.",
5680        example: "fn size(name: String) -> Int {\n    name.length    // ✗ `String` is not a record; `length` is a method\n}\n\nfn size(name: String) -> Int {\n    name.length()    // ✓\n}",
5681    },
5682    Explain {
5683        code: "bynk.types.field_annotation_unknown",
5684        blurb: "`@name(\"…\")` is the only annotation a record field takes: it gives the field the key it has on an HTTP request where that key is not an identifier. Any other annotation is refused rather than ignored, so a misspelt one cannot silently do nothing. Write `@name`, or drop the annotation.",
5685        example: "type Filter = {\n    @rename(\"page-size\") pageSize: Option[Int],    // ✗ only `@name` exists\n}\n\ntype Filter = {\n    @name(\"page-size\") pageSize: Option[Int],      // ✓\n}",
5686    },
5687    Explain {
5688        code: "bynk.types.field_default_on_variant",
5689        blurb: "Only a record's fields take defaults. A variant is built like a call, with every \
5690                payload field given, so a default on a payload field would be an optional argument \
5691                by another name. Remove it and give the field wherever the variant is built, or \
5692                hold the optional values in a record, which can have defaults, and make that \
5693                record the payload.",
5694        example: "type Retry =\n    | Never\n    | Times(n: Int = 3)    // ✗ a variant's field has no default\n\ntype Backoff = { n: Int = 3 }\n\ntype Retry =\n    | Never\n    | Times(opts: Backoff)    // ✓ the record carries the default",
5695    },
5696    Explain {
5697        code: "bynk.types.field_name_bad_arg",
5698        blurb: "`@name` renames a field's key on an HTTP request, and the compiler reads that key at compile time, so it takes exactly one string literal, or a `String` constant bound to one: not a number, a computed value, a second argument or none. A constant must be declared exactly `String` (not a refined type) and bound to a string literal or to another such constant. Write the key as a literal, as in `@name(\"__Host-sid\")`, or name it once with a constant.",
5699        example: "type Filter = {\n    @name(1) pageSize: Option[Int],             // ✗ not a string literal\n}\n\nconst PageKey: String = \"page-size\"\n\ntype Filter = {\n    @name(PageKey) pageSize: Option[Int],       // ✓ a `String` constant bound to a literal\n}\n\ntype Filter = {\n    @name(\"page-size\") pageSize: Option[Int],   // ✓\n}",
5700    },
5701    Explain {
5702        code: "bynk.types.field_name_case_conflict",
5703        blurb: "A `cookies` or `query` record is read by name, and names that differ only in case are easily confused: a client that sends `page` would not match `Page`, yet both look like the same parameter. So two fields of such a record may not have wire names that differ only in case. Rename one. Two fields with exactly the same wire name are `bynk.types.field_name_duplicate`.",
5704        example: "type Filter = {\n    @name(\"Page\") a: Option[Int],\n    @name(\"page\") b: Option[Int],    // ✗ differs from `Page` only in case\n}\n\ntype Filter = {\n    @name(\"Page\") a: Option[Int],\n    @name(\"size\") b: Option[Int],    // ✓\n}",
5705    },
5706    Explain {
5707        code: "bynk.types.field_name_duplicate",
5708        blurb: "A field's wire name is the key a request reader looks it up by, so two fields of one record cannot share one: both would read the same value. A field's wire name is its `@name`, or its own name when it has none. A field may also carry only one `@name`. Give each field its own key. Names differing only in case are `bynk.types.field_name_case_conflict`.",
5709        example: "type Filter = {\n    @name(\"page\") a: Option[Int],\n    page: Option[Int],       // ✗ reads `page` again\n}\n\ntype Filter = {\n    @name(\"page\") a: Option[Int],\n    size: Option[Int],       // ✓\n}",
5710    },
5711    Explain {
5712        code: "bynk.types.field_name_invalid",
5713        blurb: "A `@name` has to be usable as a key where the record is read. It may not be empty, and on a `cookies` record it must be a cookie name, an RFC 9110 token: no spaces, quotes or separators such as `;` `,` or `=`. A name the request could never carry would make the field unreachable. Use a valid token, such as `__Host-sid`.",
5714        example: "type Session = {\n    @name(\"session id\") sid: Option[String],    // ✗ a space is not allowed in a cookie name\n}\n\ntype Session = {\n    @name(\"session-id\") sid: Option[String],    // ✓\n}",
5715    },
5716    Explain {
5717        code: "bynk.types.field_name_not_request_record",
5718        blurb: "`@name` renames the key a request reader looks for. Only a record that is the `cookies`, `query` or `@form`/`@multipart` `body` parameter of an `on http` handler is read that way, so on any other record the annotation would do nothing. Remove it, or make the record that parameter. A record used as a JSON body or result may not carry `@name` either: `bynk.types.field_name_record_not_boundary`.",
5719        example: "type Plain = {\n    @name(\"x-y\") a: String,    // ✗ `Plain` is not read from a request\n}\n\ntype Plain = {\n    a: String,                // ✓\n}",
5720    },
5721    Explain {
5722        code: "bynk.types.field_name_record_not_boundary",
5723        blurb: "A record with `@name` fields is read off a request by those names, but its JSON form uses the field names, so using it as a JSON body, a result, a store field, an event or a call argument would make the two forms disagree. It may only be a `cookies`, `query` or `@form`/`@multipart` `body` parameter. Use a second record, without `@name`, for the other position.",
5724        example: "type Filter = {\n    @name(\"page-size\") pageSize: Option[Int],\n}\n\ntype FilterView = {\n    pageSize: Option[Int],\n}\n\non GET(\"/f\") (query: Filter) -> Effect[HttpResult[Filter]] by v: Visitor { … }        // ✗\n\non GET(\"/f\") (query: Filter) -> Effect[HttpResult[FilterView]] by v: Visitor { … }    // ✓",
5725    },
5726    Explain {
5727        code: "bynk.types.field_refinement_not_base",
5728        blurb: "An inline refinement, `price: Money where Positive`, applies predicates to a value of a base type, or of a refined type over one. A record or a sum has no such value for a predicate to test. Put the refinement on the field that holds the number, inside the record, or declare a refined type and use its name.",
5729        example: "type Money = { cents: Int }\ntype Line = { price: Money where Positive }    // ✗ `Money` is a record, which no predicate fits\n\ntype Money = { cents: Int where Positive }     // ✓ refine the field that holds the number\ntype Line = { price: Money }",
5730    },
5731    Explain {
5732        code: "bynk.types.field_value_mismatch",
5733        blurb: "A record literal checks each field against the type the declaration gives it, with no implicit conversion, so `y: \"0\"` for an `Int` field is refused where it is written. Give the field a value of its declared type, or convert it first. A field the type lacks is `bynk.resolve.unknown_field`, and one left out is `bynk.resolve.missing_field`.",
5734        example: "type Point = { x: Int, y: Int }\n\nfn origin() -> Point {\n    Point { x: 0, y: \"0\" }    // ✗ `y` is an `Int`\n}\n\nfn origin() -> Point {\n    Point { x: 0, y: 0 }    // ✓\n}",
5735    },
5736    Explain {
5737        code: "bynk.types.file_at_boundary",
5738        blurb: "A `File` is one uploaded part of a `@multipart` request, held in memory for the handler that receives it. A record may have a `File` field, alone, in an `Option` or in a `List`, which is how a `@multipart` `body` names its parts. But a `File`, or a record carrying one, is refused as an agent store field or key, an event field, a handler result, or any handler parameter but that `body`. Take the part's `bytes`, and the `filename` and `contentType` you need, in the handler, and keep those.",
5739        example: "consumes bynk { File }\n\nagent Gallery {\n    key id: String\n    store photo: Cell[Option[File]]     // ✗ an upload is not kept as a `File`\n}\n\nagent Gallery {\n    key id: String\n    store photo: Cell[Option[Bytes]]    // ✓ keep its bytes\n}",
5740    },
5741    Explain {
5742        code: "bynk.types.form_uncodable",
5743        blurb: "`Form.decode[T]` and `Form.encode` read and write the flat `key=value` text a `@form` route handles, so `T` must be a record of fields a form can carry: a `String`, `Int`, `Bool`, `Decimal`, an enum, or a refined or opaque type over one, optionally in an `Option` or a `List`. Form keys have no nesting, so a nested record, or a type that is not a record, is refused. Put the nested record's fields in `T` itself. A `@form` route's own body has the same rule: `bynk.http.form_field_not_stringy`.",
5744        example: "type Address = { city: String }\ntype Signup = { email: String, address: Address }\n\nForm.decode[Signup](text)    // ✗ `address` is a nested record\n\ntype Signup = { email: String, city: String }\n\nForm.decode[Signup](text)    // ✓",
5745    },
5746    Explain {
5747        code: "bynk.types.function_at_boundary",
5748        blurb: "A function type can be written only where a value stays in the running \
5749                program: as a `fn` or lambda parameter, a return, or a local. A value that is \
5750                serialised, stored or sent has to be data, and a function has no wire form, so \
5751                a function type in a record field, a sum payload, an event field, a service or \
5752                agent handler signature, an agent key or store field, a capability operation \
5753                or an actor identity is refused where it is written. Keep the function out of \
5754                the type: pass it as a parameter to the `fn` that needs it, or store the data \
5755                it is built from, such as a name or a number, and rebuild the behaviour on \
5756                the other side.",
5757        example: "type Job = {\n  name: String,\n  run: Int -> Int,    // ✗ a record field cannot hold a function\n}\n\n\
5758                  type Job = {\n  name: String,\n  step: Int,\n}\n\nfn run(j: Job, f: Int -> Int) -> Int {    // ✓ a parameter can\n    f(j.step)\n}",
5759    },
5760    Explain {
5761        code: "bynk.types.guard_not_bool",
5762        blurb: "A guard, as in `pattern if condition => …`, decides whether an arm applies, so it must be a `Bool`: a number or an `Option` is not read as true or false. Say what you mean with a comparison, such as `r > 10`. A guarded arm covers nothing for exhaustiveness, because its guard may fail. The condition of an `if` expression is `bynk.types.if_non_bool_cond`.",
5763        example: "type Shape =\n  | Circle(radius: Int)\n  | Dot\n\nfn label(s: Shape) -> String {\n    match s {\n        Circle(r) if r => \"round\"    // ✗ `r` is an `Int`\n        Circle(_) => \"small\"\n        Dot => \"dot\"\n    }\n}\n\nfn label(s: Shape) -> String {\n    match s {\n        Circle(r) if r > 10 => \"round\"    // ✓\n        Circle(_) => \"small\"\n        Dot => \"dot\"\n    }\n}",
5764    },
5765    Explain {
5766        code: "bynk.types.headers_at_boundary",
5767        blurb: "`RequestHeaders` is the view of one request's headers, given to the handler that is answering it. It is read there and dropped: headers can carry credentials such as `Authorization`, and a copy kept or sent on would outlive the request. It is accepted only as an HTTP handler's `headers` parameter, and refused as a record, sum or event field, an agent key or store field, a capability operation, or any other handler parameter or result. Read the header you need (`headers.get(\"…\")`) and keep that `String`. See also `bynk.types.request_query_at_boundary`.",
5768        example: "type Seen = {\n    headers: RequestHeaders,    // ✗ a request's headers are not data to keep\n}\n\ntype Seen = {\n    userAgent: String,          // ✓ keep the value you read\n}",
5769    },
5770    Explain {
5771        code: "bynk.types.held_at_boundary",
5772        blurb: "A `Connection` is a held resource, built and disposed of in place, so it is never \
5773                stored or sent: it cannot be a record, sum or event field, or part of a service or \
5774                agent handler signature. An agent may keep one in its own state, as \
5775                `Cell[Option[Connection[F]]]` or `Map[K, Connection[F]]`. Keep it there, and pass \
5776                what you need from it, not the connection.",
5777        example: "type Session = {\n    conn: Connection[Frame],    // ✗ a held resource is not a field\n}\n\nagent Room {\n    key id: String\n\n    store conns: Map[String, Connection[Frame]]    // ✓ held in agent state\n}",
5778    },
5779    Explain {
5780        code: "bynk.types.held_not_comparable",
5781        blurb: "A held `Connection` is a live resource with an identity: two values are the same connection or they are not, so there is no value to compare. So `==` on one, or on a type that holds one, is refused. Compare an id that you keep next to the connection. A `Stream` has `bynk.types.stream_not_comparable`, and functions and effects have `bynk.types.not_comparable`.",
5782        example: "type Frame = { text: String }\n\nfn same(a: Connection[Frame], b: Connection[Frame]) -> Bool {\n    a == b                            // ✗ a connection has identity, not value\n}\n\nfn same(a: String, b: String) -> Bool {    // ✓ compare ids kept beside them\n    a == b\n}",
5783    },
5784    Explain {
5785        code: "bynk.types.if_branch_mismatch",
5786        blurb: "Both branches of an `if` can be its value, so they must have one type: their common supertype, where a refined type and its base agree at the base. With a `String` in one branch and an `Int` in the other, the caller has no single type to rely on. Make the branches agree, converting where needed. A `match` whose arms disagree is `bynk.types.match_arm_mismatch`.",
5787        example: "fn grade(score: Int) -> String {\n    if score >= 50 { \"pass\" } else { 0 }    // ✗ a `String` branch and an `Int` branch\n}\n\nfn grade(score: Int) -> String {\n    if score >= 50 { \"pass\" } else { \"fail\" }    // ✓\n}",
5788    },
5789    Explain {
5790        code: "bynk.types.if_non_bool_cond",
5791        blurb: "An `if` chooses a branch on a `Bool`, and Bynk has no truthiness: a number, a string, an `Option` or a list is never read as true or false. Say what you mean with a comparison (`count > 0`), or test an `Option` with `is Some(…)`. A match-arm guard has the same rule, as `bynk.types.guard_not_bool`.",
5792        example: "fn describe(count: Int) -> String {\n    if count { \"some\" } else { \"none\" }    // ✗ an `Int`, not a `Bool`\n}\n\nfn describe(count: Int) -> String {\n    if count > 0 { \"some\" } else { \"none\" }    // ✓\n}",
5793    },
5794    Explain {
5795        code: "bynk.types.if_without_else_requires_unit",
5796        blurb: "An `if` with no `else` has nothing to produce when its condition is false, so Bynk gives that path the value `()`. The `then` branch must therefore be `()` too, or `Effect[()]` for a branch that only performs effects; a branch that yields a `String` would leave the other path without one. Add an `else` that produces a value of the same type, or make the branch a unit effect.",
5797        example: "fn sign(n: Int) -> String {\n    if n > 0 { \"positive\" }    // ✗ no `else`, so the value would be `()`\n}\n\nfn sign(n: Int) -> String {\n    if n > 0 { \"positive\" } else { \"not positive\" }    // ✓\n}",
5798    },
5799    Explain {
5800        code: "bynk.types.interpolation_non_scalar",
5801        blurb: "A `\\(…)` hole in a string takes a `String`, `Int`, `Float`, `Bool`, \
5802                `Decimal`, or a refined type over one of them, and nothing else. A record or \
5803                sum has no canonical text, and Bynk will not print an unreadable stand-in \
5804                such as `[object Object]`. An opaque type hides its base, so use `.raw` \
5805                first. Turn other values into a `String` yourself: `toHex()` or `toBase64()` \
5806                on `Bytes`, `toString()` on a `Duration`, `toIso()` or `toString()` on an \
5807                `Instant`, or interpolate the fields of a record, a `ValidationError` or a \
5808                `DecodeError`.",
5809        example: "type User = { name: String }\n\n\
5810                  fn label(u: User) -> String {\n    \"user: \\(u)\"         // ✗ a record has no string form\n}\n\n\
5811                  fn label(u: User) -> String {\n    \"user: \\(u.name)\"    // ✓ interpolate the field\n}",
5812    },
5813    Explain {
5814        code: "bynk.types.invalid_regex",
5815        blurb: "A `Matches` pattern, and the pattern of a regex method such as `containsRegex`, \
5816                must be a valid regular expression. The emitted check runs it under \
5817                JavaScript's `RegExp`, so the compiler validates it with those rules: a \
5818                pattern the Rust `regex` crate accepts, such as `(?P<name>…)`, may be refused \
5819                here, and the compiler would otherwise ship a check that throws at run time. \
5820                A regex method's pattern may open with one inline-flag group of `i`, `m` \
5821                and `s`, each at most once. Fix the syntax; the note carries the parser's \
5822                message. A valid but dangerous pattern is `bynk.types.catastrophic_regex`.",
5823        example: "type Code = String where Matches(\"[A-Z\")     // ✗ the class is never closed\n\n\
5824                  type Code = String where Matches(\"[A-Z]+\")   // ✓",
5825    },
5826    Explain {
5827        code: "bynk.types.inverted_range",
5828        blurb: "`InRange(lo, hi)` is inclusive at both ends, so it needs `lo <= hi`. With the \
5829                bounds the wrong way round the refinement admits no value, which is almost \
5830                certainly a slip, so the compiler refuses it. Swap them; the diagnostic \
5831                offers that fix. On an `Int` or `Float` the empty range is also reported as \
5832                `bynk.types.empty_refinement`, which is what contradictory predicates give \
5833                too. An inverted range in a `match` arm is `bynk.types.empty_range_pattern`.",
5834        example: "type Price = Decimal where InRange(100.00d, 0.00d)    // ✗ the minimum is above the maximum\n\n\
5835                  type Price = Decimal where InRange(0.00d, 100.00d)    // ✓",
5836    },
5837    Explain {
5838        code: "bynk.types.is_base_mismatch",
5839        blurb: "`value is Quantity` runs a refined type's predicates against the value. A refined type is a base type plus predicates, so the value must have that base: an `Int` can be checked against `Int where …`, but a `String` has nothing for an `Int` range to test. Check the value against a refined type over its own type, or convert it first, for example by parsing the `String`.",
5840        example: "type Quantity = Int where InRange(1, 100)\n\ns is Quantity    // ✗ `s` is a `String`, `Quantity` is over `Int`\n\nn is Quantity    // ✓ `n` is an `Int`",
5841    },
5842    Explain {
5843        code: "bynk.types.is_literal_pattern",
5844        blurb: "`is` tests a value's variant or refined type, not its value, so `x is 31` would read as a type test while meaning equality. Bynk refuses it rather than let the two readings blur. Compare with `==` instead. In a `match`, a literal is a fine pattern, because a `match` arm tests a value there.",
5845        example: "fn thirty(x: Int) -> Bool {\n    x is 31           // ✗ `is` tests a type, not a value\n}\n\nfn thirty(x: Int) -> Bool {\n    x == 31           // ✓\n}",
5846    },
5847    Explain {
5848        code: "bynk.types.is_non_sum",
5849        blurb: "`value is Variant` asks which variant a sum, `Result` or `Option` holds, so its left side must be one of those. On an `Int`, a `String` or a record there is no variant to ask about. To test a number or a string against a refined type, name that type: `n is Quantity`. To compare by value, use `==`. A variant the sum does not have is `bynk.types.is_unknown_variant`.",
5850        example: "type Light = | Red | Green\n\nfn ready(n: Int) -> Bool {\n    n is Green        // ✗ `n` is an `Int`, not a `Light`\n}\n\nfn ready(l: Light) -> Bool {\n    l is Green        // ✓\n}",
5851    },
5852    Explain {
5853        code: "bynk.types.is_range_pattern",
5854        blurb: "`is` tests a value's variant or refined type, not whether a number lies in a range, so `age is 13..19` would read as a type test while comparing values. Bynk refuses it. Compare the bounds, write a `match` arm `13..19`, or declare a refined type with `InRange(13, 19)` and test against that. The literal case is `bynk.types.is_literal_pattern`.",
5855        example: "fn teen(age: Int) -> Bool {\n    age is 13..19                // ✗ `is` tests a type, not a range\n}\n\nfn teen(age: Int) -> Bool {\n    age >= 13 && age <= 19       // ✓\n}",
5856    },
5857    Explain {
5858        code: "bynk.types.is_refined_pattern",
5859        blurb: "`is` tests a value against a type or a variant. An inline refinement, `_ where Positive`, is a pattern for a `match` arm, and is not accepted after `is`: a rule worth testing is worth a name, which also lets every other place use it. Declare a refined type and write `n is Natural`, or move the test into a `match` arm.",
5860        example: "n is _ where Positive    // ✗ not a pattern for `is`\n\ntype Natural = Int where Positive\n\nn is Natural             // ✓ name the refinement",
5861    },
5862    Explain {
5863        code: "bynk.types.is_unknown_variant",
5864        blurb: "`l is Amber` asks whether a `Light` is its `Amber` variant, which only means something if `Light` has one. A name that is not a variant of the sum is usually a typo or a variant left over from an earlier version of the type. Use one the type declares. On a value that is not a sum at all, the error is `bynk.types.is_non_sum`.",
5865        example: "type Light = | Red | Green\n\nfn ready(l: Light) -> Bool {\n    l is Amber        // ✗ `Light` has no variant `Amber`\n}\n\nfn ready(l: Light) -> Bool {\n    l is Green        // ✓\n}",
5866    },
5867    Explain {
5868        code: "bynk.types.json_uncodable",
5869        blurb: "`Json.encode` and `Json.decode` work on values that have a wire form, and a \
5870                function does not: a value that can run has no JSON text to stand for it. \
5871                The codec covers the base types, named types and the built-in containers \
5872                over them. It does not cover functions, effects, streams or a type that \
5873                carries one, `bynk.crypto` keys or the error builtins. Encode the data the \
5874                function produces, or the record that describes it, not the function itself.",
5875        example: "fn dump(f: Int -> Int) -> String {\n    Json.encode(f)       // ✗ a function has no JSON form\n}\n\n\
5876                  fn dump(f: Int -> Int) -> String {\n    Json.encode(f(1))    // ✓ encode a value it produces\n}",
5877    },
5878    Explain {
5879        code: "bynk.types.key_at_boundary",
5880        blurb: "A `bynk.crypto` `SigningKey` or `VerifyKey` is a handle to a key the platform \
5881                holds non-extractable, and it lives only for the call that imported it. \
5882                Storing, serialising, logging or sending it would either leak the secret or \
5883                mean nothing on the other side, so one cannot be a `store` field, a record or \
5884                event field, or a handler parameter or result. Keep the key's bytes, such as \
5885                the PKCS#8 `Bytes`, in `Secrets` or a field, and import the key again with \
5886                `Crypto.importSigningKey` where you sign. A capability operation may take one.",
5887        example: "type Credentials = {\n    owner: String,\n    key: SigningKey,    // ✗ a key cannot be held in a type\n}\n\n\
5888                  type Credentials = {\n    owner: String,\n    pkcs8: Bytes,       // ✓ keep the bytes, import the key where it signs\n}",
5889    },
5890    Explain {
5891        code: "bynk.types.key_not_orderable",
5892        blurb: "`sortBy`, `sortByDescending`, `min` and `max` order a list, or a storage \
5893                `Query`, by the value the key function returns, so that value needs a \
5894                total order. A record or sum is not ordered by accident, because opting in \
5895                makes field and variant order significant. Return a field that is already \
5896                orderable, or add `derives Ord` to the type. The operators `<` and `>` on an \
5897                unordered type are `bynk.types.not_orderable`.",
5898        example: "type Item = { id: Int }\n\n\
5899                  fn byId(items: List[Item]) -> List[Item] {\n    items.sortBy((i) => i)       // ✗ `Item` has no order\n}\n\n\
5900                  fn byId(items: List[Item]) -> List[Item] {\n    items.sortBy((i) => i.id)    // ✓ `Int` does\n}",
5901    },
5902    Explain {
5903        code: "bynk.types.lambda_mismatch",
5904        blurb: "A lambda is checked against the function type expected where it is written, \
5905                such as the parameter it is passed for. It must take the same number of \
5906                parameters, any annotation on a parameter must match that parameter's type, \
5907                and its body must produce the result type, because the function it is passed \
5908                to calls it with that shape and uses what comes back. Change the lambda to \
5909                fit, or change the function type if that is what is wrong.",
5910        example: "fn apply(f: Int -> Int, x: Int) -> Int {\n    f(x)\n}\n\n\
5911                  fn total() -> Int {\n    apply((a, b) => a + b, 5)    // ✗ `f` takes one argument\n}\n\n\
5912                  fn total() -> Int {\n    apply((a) => a + 1, 5)       // ✓\n}",
5913    },
5914    Explain {
5915        code: "bynk.types.let_annotation_mismatch",
5916        blurb: "A `let` with a type annotation declares what the binding is, and its value \
5917                must have exactly that type. The annotation is the contract that later code \
5918                reads, so a value of another type is refused at the `let`, not where it is \
5919                later used. Nothing is converted for you: change the value, convert it \
5920                explicitly, or correct the annotation if the value is what you meant. The \
5921                same rule governs a function's declared return, which is \
5922                `bynk.types.return_mismatch`.",
5923        example: "fn run() -> Int {\n    let n: Int = \"three\"    // ✗ a `String`, annotated `Int`\n    n\n}\n\n\
5924                  fn run() -> Int {\n    let n: Int = 3          // ✓\n    n\n}",
5925    },
5926    Explain {
5927        code: "bynk.types.list_element_mismatch",
5928        blurb: "A list has one element type, taken from the context if there is one and otherwise from the first element, and every element must have it. `[1, 2, \"3\"]` mixes `Int` and `String`, and the error is on the element that disagrees. Make the elements one type, or wrap them in a sum type if the list really holds more than one kind of value. An empty `[]` with no context is `bynk.types.uninferable_element_type`.",
5929        example: "fn scores() -> List[Int] {\n    [1, 2, \"3\"]    // ✗ a `String` in a `List[Int]`\n}\n\nfn scores() -> List[Int] {\n    [1, 2, 3]    // ✓\n}",
5930    },
5931    Explain {
5932        code: "bynk.types.list_pattern_on_non_list",
5933        blurb: "A list pattern such as `[x, ..]` matches a value by its length and its elements, \
5934                so the value must be a `List[T]`. A `Set`, a `Map`, an `Int` or a record has no \
5935                such shape, and a record or sum is matched by its own pattern. Convert the \
5936                value first, as `s.toList()` does for a `Set`, or match on what the value \
5937                actually is. The same rule applies to a list pattern after `is` and in \
5938                `let … else`.",
5939        example: "fn first(s: Set[Int]) -> Int {\n    match s {\n        [x, ..] => x    // ✗ a `Set` is not a `List`\n        _ => 0\n    }\n}\n\n\
5940                  fn first(s: List[Int]) -> Int {\n    match s {\n        [x, ..] => x    // ✓\n        _ => 0\n    }\n}",
5941    },
5942    Explain {
5943        code: "bynk.types.match_arm_mismatch",
5944        blurb: "A `match` is an expression, so its arms must produce one type: the least upper \
5945                bound of their types, where a refined type and its base agree at the base. If \
5946                one arm gives a `String` and another an `Int`, there is no single type for the \
5947                caller to rely on. Make the arms agree, converting where needed. The rule also \
5948                holds for `let … else`, whose `else` must produce the type of the rest of its \
5949                block.",
5950        example: "type Status = enum { Pending, Active, Done }\n\nfn label(s: Status) -> String {\n    match s {\n        Pending => \"waiting\"\n        Active => 1           // ✗ an `Int`, where the others are `String`\n        Done => \"finished\"\n    }\n}\n\n\
5951                  fn label(s: Status) -> String {\n    match s {\n        Pending => \"waiting\"\n        Active => \"running\"   // ✓\n        Done => \"finished\"\n    }\n}",
5952    },
5953    Explain {
5954        code: "bynk.types.match_non_sum_discriminant",
5955        blurb: "`match` chooses between alternatives, so it needs a value that has some: a sum, an enum, a `Result` or `Option`, an `Int`, `String` or `Bool`, or a list matched by list patterns. A `Float` or a function has none, and a record has a single shape, so it can be matched only with a record pattern such as `Point { x, .. }`. Read a field directly, and use `if` to branch on a condition.",
5956        example: "type Point = { x: Int, y: Int }\n\nfn first(p: Point) -> Int {\n    match p {         // ✗ a record has one shape, not variants\n        _ => 1\n    }\n}\n\nfn first(p: Point) -> Int {\n    p.x               // ✓ read the field\n}",
5957    },
5958    Explain {
5959        code: "bynk.types.method_arity",
5960        blurb: "A method was called with a different number of arguments from the number it \
5961                declares. The count excludes `self`, which the receiver supplies, so \
5962                `fn Box.adjust(self, delta: Int)` takes one argument. Pass exactly that \
5963                many. The same code covers the built-in methods of `String`, `List`, `Map` and the other \
5964                kernel types.",
5965        example: "type Box = { value: Int }\n\n\
5966                  fn Box.adjust(self, delta: Int) -> Box {\n    Box { value: self.value + delta }\n}\n\n\
5967                  fn bump(b: Box) -> Box {\n    b.adjust()     // ✗ expects 1 argument\n}\n\n\
5968                  fn bump(b: Box) -> Box {\n    b.adjust(1)    // ✓\n}",
5969    },
5970    Explain {
5971        code: "bynk.types.method_not_found",
5972        blurb: "A method call names an instance method that the receiver's type does not \
5973                have. An instance method is a function declared with `self` as its first \
5974                parameter. A function declared on a type without `self` is static, and is \
5975                called on the type, as `Counter.zero()`, never on a value. This also fires on \
5976                a typo, and on a built-in type that has methods but not this one, since only the \
5977                methods the type documents exist.",
5978        example: "type Counter = { count: Int }\n\n\
5979                  fn Counter.zero() -> Counter {\n    Counter { count: 0 }\n}\n\n\
5980                  fn reset(c: Counter) -> Counter {\n    c.zero()          // ✗ `zero` has no `self`: not an instance method\n}\n\n\
5981                  fn reset(c: Counter) -> Counter {\n    Counter.zero()    // ✓ a static function is called on the type\n}",
5982    },
5983    Explain {
5984        code: "bynk.types.method_on_non_named_type",
5985        blurb: "A method call needs a type that has methods. A user-declared type does, and so do the built-ins that document them, such as `String` and `List`, but a function value, a `Bool` or `()` has none, so `f.apply(n)` has nothing to look up. A function is called directly, as `f(n)`. For a type that does have methods, a name it lacks is `bynk.types.method_not_found`.",
5986        example: "fn twice(f: (Int) -> Int, n: Int) -> Int {\n    f.apply(f.apply(n))    // ✗ a function value has no methods\n}\n\nfn twice(f: (Int) -> Int, n: Int) -> Int {\n    f(f(n))    // ✓ call it directly\n}",
5987    },
5988    Explain {
5989        code: "bynk.types.mixed_pattern_bindings",
5990        blurb: "A variant pattern binds its payload either by field name, `Circle(r: x, d: y)`, or by position, `Circle(x, y)`. Mixing the two leaves it unclear which field a bare name takes, so Bynk wants one style in each pattern. Name every field, or none.",
5991        example: "type Shape = | Circle(r: Int, d: Int) | Dot\n\nfn size(s: Shape) -> Int {\n    match s {\n        Circle(r: x, y) => x    // ✗ one named binding, one positional\n        Dot => 0\n    }\n}\n\nfn size(s: Shape) -> Int {\n    match s {\n        Circle(x, y) => x       // ✓ all positional\n        Dot => 0\n    }\n}",
5992    },
5993    Explain {
5994        code: "bynk.types.negative_length",
5995        blurb: "`MinLength`, `MaxLength` and `Length` count the characters of a string, and a length cannot be below zero, so `MinLength(-1)` would hold for every string and `MaxLength(-1)` for none. The compiler takes a negative argument to be a mistake and refuses it. Give a length of zero or more. A set of predicates that no value can satisfy is `bynk.types.empty_refinement`.",
5996        example: "type Short = String where MinLength(-1)    // ✗ a length is never negative\n\ntype Short = String where MinLength(8)     // ✓",
5997    },
5998    Explain {
5999        code: "bynk.types.never_inferred",
6000        blurb: "A value that only faults, such as `unreachable(\"…\")` or `todo(\"…\")`, has the \
6001                bottom type `never returns`, which stands in for any type. If an unannotated \
6002                `let` or `<-` binding took it, every later use would type-check whatever it \
6003                was used as, and the type cannot be written in source to say otherwise. Annotate \
6004                the binding with the type it is meant to have. A lambda that only faults is \
6005                annotated with a function type.",
6006        example: "fn later() -> Int {\n    let x = unreachable(\"never\")    // ✗ `x` would have no usable type\n    x\n}\n\n\
6007                  fn later() -> Int {\n    let x: Int = unreachable(\"never\")    // ✓\n    x\n}",
6008    },
6009    Explain {
6010        code: "bynk.types.no_numeric_coercion",
6011        blurb: "`Int`, `Float` and `Decimal` are never mixed implicitly, in an operator, \
6012                a comparison or an `InRange` bound. Each conversion can lose or invent \
6013                precision, so Bynk makes you write it: `.toFloat()` on an `Int`, \
6014                `.round()`, `.floor()`, `.ceil()` or `.truncate()` on a `Float`, \
6015                `Decimal.fromInt(n)` or a decimal literal for a `Decimal`. The same \
6016                code covers a `Duration` or `Instant` used with an operand it does not \
6017                support.",
6018        example: "fn total(count: Int, price: Float) -> Float {\n    count * price                    // ✗ `Int` and `Float` in one operator\n}\n\n\
6019                  fn total(count: Int, price: Float) -> Float {\n    count.toFloat() * price          // ✓ explicit conversion\n}",
6020    },
6021    Explain {
6022        code: "bynk.types.non_exhaustive_match",
6023        blurb: "A `match` must cover every value its subject can take, so it can never \
6024                fall off its end. The compiler names a case that no arm covers: add an \
6025                arm for it, or end the `match` with a wildcard `_` arm. Listing every \
6026                variant a type has today is not a substitute for `_` where the compiler \
6027                says one is needed, and where a `match` is too complex for it to prove \
6028                exhaustive it asks for `_` too.",
6029        example: "type Status = enum { Pending, Active, Done }\n\n\
6030                  match s {                // ✗ `Done` is not covered\n    Pending => \"p\"\n    Active => \"a\"\n}\n\n\
6031                  match s {\n    Pending => \"p\"\n    Active => \"a\"\n    Done => \"d\"        // ✓ every variant covered\n}",
6032    },
6033    Explain {
6034        code: "bynk.types.not_codable",
6035        blurb: "A type parameter declared `T: Codable`, on a generic `fn` or a capability \
6036                operation, accepts only the types `Json.decode` can read. A call that makes `T` \
6037                a function, an `Effect`, a `Stream` or a type carrying one, a `bynk.crypto` \
6038                key or `()` is refused, because such a value has no wire form. Pass a plain \
6039                value, or use a function whose parameter is not `Codable`. Calling \
6040                `Json.encode` or `Json.decode` on such a type directly is \
6041                `bynk.types.json_uncodable`.",
6042        example: "fn keep[T: Codable](x: T) -> T { x }\n\n\
6043                  fn run(f: Int -> Int) -> Int {\n    let _ = keep(f)    // ✗ a function has no wire form\n    1\n}\n\n\
6044                  fn run(n: Int) -> Int {\n    keep(n)    // ✓ an `Int` does\n}",
6045    },
6046    Explain {
6047        code: "bynk.types.not_comparable",
6048        blurb: "`==` and `!=` compare values structurally, which needs a value to compare. \
6049                A function, an `Effect` and a `Query` are computations, and two of them have no \
6050                equality. A type that holds one anywhere inside it, in a field, a payload, an \
6051                element or a generic argument, is refused too. Compare what the computation \
6052                produces, or the data it was built from. A `Stream` and a held connection have \
6053                their own codes, `bynk.types.stream_not_comparable` and \
6054                `bynk.types.held_not_comparable`.",
6055        example: "fn same(f: Int -> Int, g: Int -> Int) -> Bool {\n    f == g          // ✗ functions have no equality\n}\n\n\
6056                  fn same(f: Int -> Int, g: Int -> Int) -> Bool {\n    f(1) == g(1)    // ✓ compare what they produce\n}",
6057    },
6058    Explain {
6059        code: "bynk.types.not_keyable",
6060        blurb: "A `Map` key, a `Set` element, or the key of a `distinct`, `distinctBy`, `groupBy` \
6061                or join, must be a `Key` type, one whose equal values can always be found \
6062                again. `String`, `Int`, `Bool`, `Instant`, `Duration`, `Bytes` and `Decimal` are, as are \
6063                `Option` and `List` of a key and records, sums and enums made only of keys. \
6064                A `Float` never is, at any depth, because `NaN` is not equal to itself, so a \
6065                key holding one could never be looked up. Key on a type that is: an `Int` \
6066                count of cents, say, or a `String`.",
6067        example: "fn distinctPrices(xs: List[Float]) -> Int {\n    let seen: Set[Float] = Set.of(xs)    // ✗ `Float` is not a `Key`\n    seen.length()\n}\n\n\
6068                  fn distinctPrices(xs: List[Int]) -> Int {\n    let seen: Set[Int] = Set.of(xs)      // ✓ `Int` is\n    seen.length()\n}",
6069    },
6070    Explain {
6071        code: "bynk.types.not_orderable",
6072        blurb: "`<`, `<=`, `>` and `>=`, and a parameter declared `T: Ord`, need a type with \
6073                a total order. `Int`, `Float`, `Decimal`, `String`, `Duration`, `Instant` and `Bytes` have \
6074                one, as do refined types over them, `Option` and `List` of an orderable type, \
6075                and any type of your own that declares `derives Ord`. `Bool`, `Result`, `Map`, \
6076                `Set` and functions do not. Your own types are not ordered by accident, \
6077                because opting in makes declaration order significant: reordering the fields \
6078                or variants changes how values sort. Add `derives Ord`, or compare a field \
6079                that is already orderable. A `sortBy`, `min` or `max` key that cannot be \
6080                ordered is `bynk.types.key_not_orderable`.",
6081        example: "type Point = { x: Int, y: Int }\n\n\
6082                  fn before(a: Point, b: Point) -> Bool {\n    a < b    // ✗ `Point` does not derive `Ord`\n}\n\n\
6083                  type Point = { x: Int, y: Int } derives Ord    // ✓ ordered by `x`, then `y`",
6084    },
6085    Explain {
6086        code: "bynk.types.ok_value_mismatch",
6087        blurb: "`Ok(v)` takes its type from where it is used. A return type or annotation of `Result[T, E]` fixes `T`, so `Ok(\"12\")` where `T` is `Int` is refused at the value, with no conversion; so is a value that does not match an `HttpResult[T]` handler's `T`. Pass a `T`, or change the declared type. The error half is `bynk.types.err_value_mismatch`; with nothing to fix `T`, it is `bynk.types.cannot_infer_result_type_params`.",
6088        example: "fn total() -> Result[Int, String] {\n    Ok(\"12\")    // ✗ a `String`, where `Int` is expected\n}\n\nfn total() -> Result[Int, String] {\n    Ok(12)    // ✓\n}",
6089    },
6090    Explain {
6091        code: "bynk.types.opaque_raw_outside",
6092        blurb: "An opaque type hides its base representation from everything but the unit that declares it, so no other code can take a `Token` apart or forge one. `.raw` reads the base value and is allowed only there. Elsewhere, use what the defining unit offers: a method or accessor on the type. To make a value, use `Token.of(value)`.",
6093        example: "// token.bynk\ntype Token = opaque String\n\nfn Token.value(self) -> String {\n    self.raw\n}\n\n// app.bynk\nfn show(t: Token) -> String {\n    t.raw    // ✗ `Token` is opaque outside `token`\n}\n\nfn show(t: Token) -> String {\n    t.value()    // ✓ use the accessor `token` provides\n}",
6094    },
6095    Explain {
6096        code: "bynk.types.opaque_unsafe_outside",
6097        blurb: "`T.unsafe(v)` wraps a base value as an opaque type without checking it, which is sound only where the type's own unit vouches for the value, so it is allowed only in the unit that declares the type. Elsewhere use `T.of(v)`, which returns a `Result` so the check is explicit. Reading the base value back is `bynk.types.opaque_raw_outside`.",
6098        example: "// token.bynk\ntype Token = opaque String\n\n// app.bynk\nfn make(s: String) -> Token {\n    Token.unsafe(s)    // ✗ only `token` may skip the check\n}\n\nfn make(s: String) -> Result[Token, ValidationError] {\n    Token.of(s)    // ✓ the checked constructor\n}",
6099    },
6100    Explain {
6101        code: "bynk.types.or_pattern_binding_mismatch",
6102        blurb: "An or-pattern, `Walk(steps) | Wait`, runs one arm for either alternative, so every alternative must bind the same names. If `steps` came only from `Walk`, the arm's body would read a name that does not exist when `Wait` matched. Bind the name in every alternative, bind it in none with `_`, or split the alternatives into separate arms. A shared name must also have the same type: see `bynk.types.or_pattern_type_mismatch`.",
6103        example: "type Move = | Walk(steps: Int) | Wait\n\nfn cost(m: Move) -> Int {\n    match m {\n        Walk(steps) | Wait => 1    // ✗ `steps` is bound by one alternative only\n    }\n}\n\nfn cost(m: Move) -> Int {\n    match m {\n        Walk(_) | Wait => 1        // ✓ neither alternative binds\n    }\n}",
6104    },
6105    Explain {
6106        code: "bynk.types.or_pattern_type_mismatch",
6107        blurb: "An or-pattern, `A(n) | B(n)`, runs one arm for either alternative, so a name it binds must mean the same thing in both: the arm's body has only one `n` to use. Here `n` is an `Int` in one alternative and a `String` in the other, so the body could not be checked. A refined type and its base count as different too. Give each alternative its own arm, or bind a value of the same type in both.",
6108        example: "type Key = | Id(n: Int) | Name(n: String)\n\nfn show(k: Key) -> String {\n    match k {\n        Id(n) | Name(n) => \"key\"    // ✗ `n` is an `Int` and a `String`\n    }\n}\n\nfn show(k: Key) -> String {\n    match k {\n        Id(n) => \"id\"               // ✓ one arm each\n        Name(n) => n\n    }\n}",
6109    },
6110    Explain {
6111        code: "bynk.types.pattern_arity",
6112        blurb: "A variant pattern takes one binding for each payload field the variant \
6113                declares, in order, or none to ignore the payload. A different count, or any \
6114                binding on a variant with no payload, is refused: an extra name has nothing to \
6115                hold, and a missing one would silently drop a field. Use `_` for a field you \
6116                do not need, or name the fields you want (`radius: r`). Building a variant \
6117                with the wrong number of arguments is `bynk.types.variant_arity`.",
6118        example: "type Shape =\n  | Circle(radius: Int)\n  | Dot\n\n\
6119                  fn size(s: Shape) -> Int {\n    match s {\n        Circle(r, extra) => r    // ✗ `Circle` has one field\n        Dot => 0\n    }\n}\n\n\
6120                  fn size(s: Shape) -> Int {\n    match s {\n        Circle(r) => r           // ✓\n        Dot => 0\n    }\n}",
6121    },
6122    Explain {
6123        code: "bynk.types.pattern_type_mismatch",
6124        blurb: "A pattern can only match values of the type it describes, so a pattern of \
6125                another kind than the value being matched can never succeed and is refused. \
6126                A literal pattern must have the scrutinee's type, so `\"one\"` cannot match an \
6127                `Int`. A variant pattern needs a sum value, a record pattern needs that \
6128                record, and a qualified pattern such as `Status.Active` must name the \
6129                scrutinee's own type. Match on the type the value has, or convert the value \
6130                before the `match`. A pattern with the wrong number of bindings is \
6131                `bynk.types.pattern_arity`.",
6132        example: "fn word(n: Int) -> String {\n    match n {\n        \"one\" => \"uno\"    // ✗ a `String` pattern, an `Int` scrutinee\n        _ => \"other\"\n    }\n}\n\n\
6133                  fn word(n: Int) -> String {\n    match n {\n        1 => \"uno\"        // ✓\n        _ => \"other\"\n    }\n}",
6134    },
6135    Explain {
6136        code: "bynk.types.polynomial_regex",
6137        blurb: "A `Matches` pattern runs under a backtracking `RegExp` on untrusted input. Two \
6138                repetitions in sequence that can match the same characters, as in `\\d*\\d*`, \
6139                let the engine split a run between them many ways, so the time grows as a \
6140                power of the input's length. That is slower to hurt than \
6141                `bynk.types.catastrophic_regex` but can still stall a handler. A `MaxLength`, \
6142                `Length` or `IsoDate` predicate that keeps the input short enough makes it \
6143                the warning `bynk.types.polynomial_regex_capped`; a regex method has no such \
6144                bound. Rewrite it so the repetitions cannot overlap.",
6145        example: "type Digits = String where Matches(\"\\\\d*\\\\d*\")    // ✗ two loops over the same digits\n\n\
6146                  type Digits = String where Matches(\"\\\\d*\")         // ✓ one way to match",
6147    },
6148    Explain {
6149        code: "bynk.types.predicate_base_mismatch",
6150        blurb: "Each predicate checks one kind of value, so it can only refine a base that has such values. `NonEmpty`, `MinLength`, `MaxLength`, `Length`, `Matches` and `IsoDate` apply to a `String`, and `NonNegative`, `Positive` and `InRange` to an `Int`, `Float` or `Decimal`. A mismatch would test something the base cannot have. Change the base type to suit the predicate, or choose the predicate that suits the base.",
6151        example: "type Code = Int where NonEmpty         // ✗ `NonEmpty` is a `String` predicate\n\ntype Code = String where NonEmpty      // ✓",
6152    },
6153    Explain {
6154        code: "bynk.types.query_at_boundary",
6155        blurb: "A `Query[T]` is a lazy read over an agent's stored data: nothing runs until a terminal such as `.collect()` executes it, in the agent that owns the data. Persisted or sent, it would be a description of a read with nothing to read from. A helper may take or return one, but it is refused as a record, sum or event field, an agent key or store field, a capability operation, or a handler's parameter or result. Run it and keep or send the `List` or `Option` it gives. A `Stream` has its own rule: `bynk.types.stream_at_boundary`.",
6156        example: "type Order = { id: String, total: Int }\n\ntype Report = {\n    orders: Query[Order],    // ✗ a lazy read is not data\n}\n\ntype Report = {\n    orders: List[Order],     // ✓ run the query, keep its result\n}",
6157    },
6158    Explain {
6159        code: "bynk.types.question_error_mismatch",
6160        blurb: "`?` returns the `Err` from the enclosing function as it is, so its error type must be one the function declares: a `String` error cannot escape a function whose errors are `Int`. The only automatic conversion is a declared embedding, where the function's error is a sum type with an `embeds` clause for the inner one. Otherwise convert the error before the `?` with `.mapErr(…)`, or change the function's error type.",
6161        example: "fn checked(n: Int) -> Result[Int, String] {\n    if n >= 0 { Ok(n) } else { Err(\"negative\") }\n}\n\nfn run(n: Int) -> Result[Int, Int] {\n    let v = checked(n)?    // ✗ propagates a `String` error, but `run` returns `Int` errors\n    Ok(v + 1)\n}\n\nfn run(n: Int) -> Result[Int, Int] {\n    let v = checked(n).mapErr((e) => e.length())?    // ✓ the error is converted first\n    Ok(v + 1)\n}",
6162    },
6163    Explain {
6164        code: "bynk.types.question_on_non_result",
6165        blurb: "`?` unwraps an `Ok` and returns early from the function on an `Err`, so it needs a `Result[T, E]`: a plain `Int` has no error to return. The one other operand it takes is an `Option`, in an `HttpResult` handler. Apply `?` to the call that produces the `Result`, not to a value already unwrapped. To turn an `Option` into a `Result` elsewhere, use `.okOr(err)`.",
6166        example: "fn checked(n: Int) -> Result[Int, String] {\n    if n >= 0 { Ok(n) } else { Err(\"negative\") }\n}\n\nfn run(n: Int) -> Result[Int, String] {\n    let v = n?    // ✗ `n` is an `Int`, not a `Result`\n    Ok(v + 1)\n}\n\nfn run(n: Int) -> Result[Int, String] {\n    let v = checked(n)?    // ✓\n    Ok(v + 1)\n}",
6167    },
6168    Explain {
6169        code: "bynk.types.question_option_outside_http",
6170        blurb: "`?` on an `Option` turns `None` into an early return, which needs somewhere to return it to. In a handler that returns an `HttpResult`, `None` becomes a `NotFound` response. Elsewhere an `Option` has no error to carry, so `?` is refused. Say what absence means with `.okOr(err)`, which makes a `Result`, and put `?` after that.",
6171        example: "fn lookup(id: Int) -> Option[Int] { … }\n\nfn double(id: Int) -> Result[Int, String] {\n    let n = lookup(id)?                    // ✗ no `HttpResult` to answer `NotFound`\n    Ok(n * 2)\n}\n\nfn double(id: Int) -> Result[Int, String] {\n    let n = lookup(id).okOr(\"missing\")?    // ✓ `None` becomes an `Err`\n    Ok(n * 2)\n}",
6172    },
6173    Explain {
6174        code: "bynk.types.question_outside_result",
6175        blurb: "`?` returns early with the `Err`, so the function around it must be able to return one: its return type has to be a `Result`, or an `Effect` of one. In a function returning `Int` the error has nowhere to go. Change the return type to `Result[T, E]` and wrap the final value in `Ok`, or deal with the `Result` where it arises, with a `match` or `.getOrElse(…)`.",
6176        example: "fn checked(n: Int) -> Result[Int, String] {\n    if n >= 0 { Ok(n) } else { Err(\"negative\") }\n}\n\nfn run(n: Int) -> Int {\n    let v = checked(n)?    // ✗ `run` does not return a `Result`\n    v + 1\n}\n\nfn run(n: Int) -> Result[Int, String] {\n    let v = checked(n)?    // ✓\n    Ok(v + 1)\n}",
6177    },
6178    Explain {
6179        code: "bynk.types.range_pattern_on_non_int",
6180        blurb: "A range pattern `lo..hi` matches an `Int` by comparing it with two bounds. It is not offered for a `Float`, because `NaN` is neither inside nor outside a range, nor for a `String`; both are left out on purpose. Compare with `<` and `>=` in an `if` instead. An empty range is `bynk.types.empty_range_pattern`.",
6181        example: "fn band(x: Float) -> String {\n    match x {\n        1..3 => \"low\"             // ✗ a range pattern matches an `Int`\n        _ => \"high\"\n    }\n}\n\nfn band(x: Float) -> String {\n    if x < 3.0 { \"low\" } else { \"high\" }    // ✓ compare in an `if`\n}",
6182    },
6183    Explain {
6184        code: "bynk.types.record_pattern_on_non_record",
6185        blurb: "A record pattern, `Order { total, .. }`, takes a record apart by its fields, so the name before the braces must be a record type. A sum, an enum, a refined or opaque type and a built-in have no fields to name. Match a sum or an enum by its variants, and read an opaque or built-in value through its methods.",
6186        example: "type Status = enum { Open, Paid }\n\nfn code(s: Status) -> Int {\n    match s {\n        Status { .. } => 1    // ✗ `Status` is an enum, not a record\n        _ => 2\n    }\n}\n\nfn code(s: Status) -> Int {\n    match s {\n        Open => 1             // ✓ name the variants\n        Paid => 2\n    }\n}",
6187    },
6188    Explain {
6189        code: "bynk.types.regex_not_literal",
6190        blurb: "A regex method checks its pattern when the program compiles, to reject one that can take catastrophic time on crafted input (ReDoS). A pattern built at run time would escape that check, so it must be a string literal. Write the pattern in place, as an ordinary or a raw string, `r\"\\d+\"`. To look for text that varies, use `contains`, which takes plain text.",
6191        example: "fn has(s: String, pattern: String) -> Bool {\n    s.containsRegex(pattern)              // ✗ the pattern is not a literal\n}\n\nfn has(s: String) -> Bool {\n    s.containsRegex(\"(?i)error\")          // ✓\n}",
6192    },
6193    Explain {
6194        code: "bynk.types.rejection_at_boundary",
6195        blurb: "A `BoundaryRejection` is the router's account of a request it refused before any handler ran: a malformed or oversized body, an unsupported media type, a wrong method. `on rejected` reads it to render the answer, and it is accepted only as that handler's parameter. It is refused as a record, sum or event field, an agent store field, a capability operation, or any other handler's parameter or result. Match on it in `on rejected` and keep what you need, such as the detail text, as a `String`.",
6196        example: "type Refusal = {\n    why: BoundaryRejection,    // ✗ read by `on rejected`, not kept\n}\n\ntype Refusal = {\n    detail: String,            // ✓ keep what you need from it\n}",
6197    },
6198    Explain {
6199        code: "bynk.types.request_cookies_at_boundary",
6200        blurb: "`RequestCookies` is the raw view of one request's cookies, the `cookies` parameter of a handler that needs a name a record field cannot spell, such as `__Host-sid`. Cookies often carry session credentials, so the view is read where the request arrives and never kept. It is accepted only as an HTTP handler's `cookies` parameter, and refused as a record, sum or event field, an agent key or store field, a capability operation, or any other handler parameter or result. Read the cookie you need (`cookies.get(\"sid\")`) and keep that `String`.",
6201        example: "type Session = {\n    cookies: RequestCookies,    // ✗ a request's cookies are not data to keep\n}\n\ntype Session = {\n    sid: String,                // ✓ keep the value you read\n}",
6202    },
6203    Explain {
6204        code: "bynk.types.request_query_at_boundary",
6205        blurb: "`RequestQuery` is the raw view of one request's query string, the `query` parameter of a handler that reads keys it does not know in advance. It is read where the request arrives and then dropped: a copy kept or sent on would outlive the request. It is accepted only as an HTTP handler's `query` parameter, and refused as a record, sum or event field, an agent key or store field, a capability operation, or any other handler parameter or result. Read the value you need (`query.get(\"q\")`) and keep that `String`.",
6206        example: "type Search = {\n    query: RequestQuery,    // ✗ a request's query string is not data to keep\n}\n\ntype Search = {\n    term: String,           // ✓ keep the value you read\n}",
6207    },
6208    Explain {
6209        code: "bynk.types.return_mismatch",
6210        blurb: "The value a function or handler body ends with does not have the declared \
6211                return type, and the compiler compares the two exactly. Either change the \
6212                body so it produces the declared type, or change the declared return type \
6213                to match what the body produces. A refined type is the same rule with one extra step: an \
6214                `Int` is not an `Age`, because `Age` carries a rule the `Int` has not been \
6215                checked against. Build the refined value with `.of`, which checks the \
6216                predicate and returns a `Result`, and declare that `Result` as the return \
6217                type.",
6218        example: "fn count() -> Int { \"three\" }       // ✗ a `String` where an `Int` is declared\n\n\
6219                  fn count() -> Int { 3 }              // ✓ the body has the declared type\n\n\
6220                  type Age = Int where InRange(0, 150)\n\n\
6221                  fn parse(n: Int) -> Age { n }                           // ✗ an `Int` is not an `Age`\n\n\
6222                  fn parse(n: Int) -> Result[Age, ValidationError] {      // ✓ checked by `.of`\n    Age.of(n)\n}",
6223    },
6224    Explain {
6225        code: "bynk.types.rounding_mode_position",
6226        blurb: "A rounding mode is written `RoundingMode.<mode>` where the rounding happens, as the mode argument of a `Decimal`'s `round` or `div`. It is not a value: it cannot be bound to a name, stored or passed around, so the rounding at each call is visible at that call. Write the mode at the call. A mode that is not a `RoundingMode.<mode>` at all is `bynk.types.unknown_rounding_mode`.",
6227        example: "let mode = RoundingMode.HalfUp         // ✗ a mode is not a value\n\nprice.round(2, RoundingMode.HalfUp)    // ✓ written where it rounds",
6228    },
6229    Explain {
6230        code: "bynk.types.select_tail_has_select",
6231        blurb: "`select[T]` and `firstAs[T]` write the `SELECT` and the column list themselves, from the fields of the row record `T`, so the SQL you give is only the rest, starting at `FROM`. That way the columns are spelt once and cannot drift from the type. Start at `FROM`. A query that cannot (a `WITH` or a parenthesised one) is read with `all` and `Json.decodeSql`, which take the whole statement.",
6232        example: "let _ <- Orders.select[Order](\"SELECT id, total FROM orders\", [])    // ✗ the compiler writes `SELECT`\n\nlet _ <- Orders.select[Order](\"FROM orders\", [])                      // ✓",
6233    },
6234    Explain {
6235        code: "bynk.types.sequence_needs_result",
6236        blurb: "`sequenceAll` and `sequenceTry` fold a `List[Result[T, E]]` into one `Result`, so every element must already be a `Result`. A list of plain values has no failures to collect. Map each element through a function that returns a `Result` first, as in `xs.map(check).sequenceAll()`. `sequenceAll` gathers every error, and `sequenceTry` stops at the first.",
6237        example: "fn check(n: Int) -> Result[Int, String] { … }\n\nfn all(xs: List[Int]) -> Result[List[Int], List[String]] {\n    xs.sequenceAll()                // ✗ the elements are `Int`s, not `Result`s\n}\n\nfn all(xs: List[Int]) -> Result[List[Int], List[String]] {\n    xs.map(check).sequenceAll()     // ✓\n}",
6238    },
6239    Explain {
6240        code: "bynk.types.some_value_mismatch",
6241        blurb: "`Some(v)` takes its type from the surrounding `Option[T]`, the annotation or the function's return type, so `Some(\"a\")` where `T` is `Int` is refused at the value, with no conversion. Pass a `T`, or change the declared type. With nothing to say what the `Option` holds, a bare `None` is `bynk.types.cannot_infer_option_type_param`.",
6242        example: "fn first() -> Option[Int] {\n    Some(\"a\")    // ✗ a `String`, where `Int` is expected\n}\n\nfn first() -> Option[Int] {\n    Some(1)    // ✓\n}",
6243    },
6244    Explain {
6245        code: "bynk.types.sql_not_literal",
6246        blurb: "The SQL of a `D1`, `Postgres` or `MySql` call must be a string literal, or a `String` constant bound to one, so it is fixed when the program compiles and no request data can become part of the statement: that is how SQL injection happens. An interpolated string, a parameter or a `let` binding is refused. Put the value in the parameter list, as `?1` with `Text(id)`, which is always bound and never spliced in.",
6247        example: "let _ <- Orders.all(\"SELECT id FROM orders WHERE id = '\\(id)'\", [])         // ✗ built at run time\n\nlet _ <- Orders.all(\"SELECT id FROM orders WHERE id = ?1\", [Text(id)])      // ✓ bound",
6248    },
6249    Explain {
6250        code: "bynk.types.sql_row_shape",
6251        blurb: "`select[T]`, `firstAs[T]` and `Json.decodeSql` read each SQL row into a record, and a column holds only a plain value. So `T` must be a record whose fields are `Int`, `Float`, `String`, `Bool` or `Bytes`, or a refined or opaque type over one, or an `Option` of either (Postgres and MySQL also read `Decimal`); a nested record, a list or an enum has no column to read. `T` is the row itself, so `select[List[Row]]` is refused too. Flatten the record.",
6252        example: "type Money = { cents: Int }\ntype Order = { id: String, total: Money }\nlet _ <- Orders.select[Order](\"FROM orders\", [])    // ✗ `total` is a record\n\ntype Order = { id: String, total: Int }\nlet _ <- Orders.select[Order](\"FROM orders\", [])    // ✓",
6253    },
6254    Explain {
6255        code: "bynk.types.sql_statement_at_boundary",
6256        blurb: "A `SqlStatement`, `PgStatement` or `MySqlStatement` is a statement a database capability runs, whose SQL the compiler requires to be a literal, so that request data is only ever bound as a parameter. One restored from storage or received from a caller would carry SQL that was never a literal, so it is refused as a record, sum or event field, an agent store field, a handler parameter or result, or a `Json` codec target. A capability operation's signature may name one. Keep or send the values instead, and build the statement where it runs.",
6257        example: "type Job = {\n    statement: SqlStatement,    // ✗ SQL that was never a literal\n}\n\ntype Job = {\n    id: String,                 // ✓ send the value, build the statement where it runs\n}",
6258    },
6259    Explain {
6260        code: "bynk.types.stream_at_boundary",
6261        blurb: "A `Stream[T]` is a live, lazily read source, built and consumed where it is \
6262                made. It cannot be persisted or serialised, so it cannot be a service or agent \
6263                handler parameter or result, a store field or an event field, nor can a record \
6264                or sum that carries one in a field, at any depth. Drain it with `collect()` \
6265                and send or keep the resulting `List`. A capability operation may take or \
6266                return a stream, since its provider runs in the caller's own isolate, and a \
6267                `@raw` HTTP handler's `body` may be a `Stream[Bytes]`, the request body as it \
6268                arrives.",
6269        example: "service s {\n    on call(readings: Stream[Int]) -> Effect[Int] by Caller {    // ✗ a stream cannot be a parameter\n        Effect.pure(0)\n    }\n}\n\n\
6270                  service s {\n    on call(readings: List[Int]) -> Effect[Int] by Caller {      // ✓\n        Effect.pure(readings.length())\n    }\n}",
6271    },
6272    Explain {
6273        code: "bynk.types.stream_not_comparable",
6274        blurb: "A `Stream` is a source of values over time, read once, so two of them have no value to compare. `==` on one, or on a type that holds one, is refused. Read the streams first, with `collect`, and compare the lists, or compare the data each was built from. Functions and effects have `bynk.types.not_comparable`, and a held connection has `bynk.types.held_not_comparable`.",
6275        example: "fn same(a: Stream[Int], b: Stream[Int]) -> Bool {\n    a == b                            // ✗ a stream has no value to compare\n}\n\nfn same(a: Stream[Int], b: Stream[Int]) -> Effect[Bool] {\n    let xs <- a.collect()             // ✓ read them first\n    let ys <- b.collect()\n    Effect.pure(xs == ys)\n}",
6276    },
6277    Explain {
6278        code: "bynk.types.type_mismatch",
6279        blurb: "An operator or a built-in method was given an operand of a type it does not \
6280                accept: `==` between an `Int` and a `String`, `!` on a number, `&&` on \
6281                something that is not a `Bool`. Types are compared exactly, with no implicit \
6282                conversion, so values of different types are never equal and never silently \
6283                coerced. Make the operands the same type, or convert one explicitly. A `Float` \
6284                and an `Int` mixed in arithmetic is the separate code \
6285                `bynk.types.no_numeric_coercion`.",
6286        example: "fn isAdult(age: Int) -> Bool {\n    age == \"18\"    // ✗ `Int` compared with `String`\n}\n\n\
6287                  fn isAdult(age: Int) -> Bool {\n    age == 18      // ✓ both `Int`\n}",
6288    },
6289    Explain {
6290        code: "bynk.types.uninferable_element_type",
6291        blurb: "An empty `[]`, `List.empty()`, `Set.empty()` or `Map.empty()` has no elements to \
6292                take a type from, and the compiler will not guess, because the element type \
6293                becomes part of the type of everything the collection touches. Give it one: \
6294                annotate the binding, as `let xs: List[Int] = []`, or use the empty value \
6295                where a type is expected, such as an argument or a return value.",
6296        example: "fn count() -> Int {\n    let xs = []                  // ✗ a list of what?\n    xs.length()\n}\n\n\
6297                  fn count() -> Int {\n    let xs: List[Int] = []       // ✓\n    xs.length()\n}",
6298    },
6299    Explain {
6300        code: "bynk.types.unknown_annotation",
6301        blurb: "After a refinement, the only annotation Bynk knows is `@example(\"…\")`, a sample value that the compiler checks against the refinement. Any other name is refused rather than ignored, so a misspelling cannot pass as a comment. Use `@example`, or delete the annotation. `@example` is accepted only on `Matches` and `IsoDate`.",
6302        example: "type Code = String where Matches(\"[A-Z]{3}\") @sample(\"ABC\")     // ✗ no annotation `@sample`\n\ntype Code = String where Matches(\"[A-Z]{3}\") @example(\"ABC\")    // ✓",
6303    },
6304    Explain {
6305        code: "bynk.types.unknown_field",
6306        blurb: "A field access names a field the value's type does not declare. A record's \
6307                fields are fixed by its type declaration, so `p.z` on a `Point` of `x` and `y` \
6308                is refused. This is usually a typo, or a value of a different type from the \
6309                one intended. Building a record with a field it lacks is the sibling code \
6310                `bynk.resolve.unknown_field`.",
6311        example: "type Point = { x: Int, y: Int }\n\n\
6312                  fn height(p: Point) -> Int {\n    p.z    // ✗ `Point` has no field `z`\n}\n\n\
6313                  fn height(p: Point) -> Int {\n    p.y    // ✓\n}",
6314    },
6315    Explain {
6316        code: "bynk.types.unknown_pattern_field",
6317        blurb: "When a variant pattern names its bindings, as in `Circle(radius: r)`, each name must be a payload field the variant declares: `Circle` has no `diameter`. Use the declared field name, or bind by position, `Circle(r)`. A count of bindings that does not fit the payload is `bynk.types.pattern_arity`.",
6318        example: "type Shape =\n  | Circle(radius: Int)\n  | Dot\n\nfn size(s: Shape) -> Int {\n    match s {\n        Circle(diameter: d) => d    // ✗ `Circle` has no field `diameter`\n        Dot => 0\n    }\n}\n\nfn size(s: Shape) -> Int {\n    match s {\n        Circle(radius: r) => r    // ✓\n        Dot => 0\n    }\n}",
6319    },
6320    Explain {
6321        code: "bynk.types.unknown_rounding_mode",
6322        blurb: "`Decimal`'s `round` and `div` must be told how to break a tie, and the choice is part of the money arithmetic, so it is named, not defaulted: write `RoundingMode.<mode>` as the last argument, where the mode is one of `Down`, `Up`, `Floor`, `Ceiling`, `HalfUp`, `HalfDown` or `HalfEven`. A number, a string or a variable is refused. A mode kept in a binding is `bynk.types.rounding_mode_position`.",
6323        example: "price.round(2, 1)                        // ✗ not a rounding mode\n\nprice.round(2, RoundingMode.HalfEven)    // ✓",
6324    },
6325    Explain {
6326        code: "bynk.types.unknown_static_member",
6327        blurb: "`HttpResult` is a built-in type with a fixed set of variants, the HTTP statuses a handler can answer with, such as `Ok`, `Created`, `NotFound` and `ServerError`. `HttpResult.Nope` names one that does not exist, usually a misspelling or a status the set does not include. Pick one of the listed variants. A type you declared yourself is checked by `bynk.resolve.unknown_static_member`.",
6328        example: "HttpResult.Nope        // ✗ no such variant\n\nHttpResult.NotFound    // ✓",
6329    },
6330    Explain {
6331        code: "bynk.types.unknown_variant_in_pattern",
6332        blurb: "A pattern on a sum value can only name the variants its type declares, so `Square(side)` against a `Shape` with no `Square` could never match and is refused. This is usually a typo, a variant that was never added, or a value of a different type from the one intended. Fix the name, add the variant to the type, or match on the right value. A pattern of the wrong kind altogether is `bynk.types.pattern_type_mismatch`.",
6333        example: "type Shape =\n  | Circle(radius: Int)\n  | Dot\n\nfn size(s: Shape) -> Int {\n    match s {\n        Circle(r) => r\n        Square(side) => side    // ✗ `Shape` has no `Square`\n        Dot => 0\n    }\n}\n\nfn size(s: Shape) -> Int {\n    match s {\n        Circle(r) => r\n        Dot => 0    // ✓\n    }\n}",
6334    },
6335    Explain {
6336        code: "bynk.types.unreachable_arm",
6337        blurb: "A `match` arm can never run, because the arms before it already match every \
6338                value it would match. The usual cause is a wildcard `_` placed before more \
6339                specific arms: arms are tried in order, so the wildcard takes everything and \
6340                the rest are dead code, which Bynk refuses rather than let hide a mistake. \
6341                Put the specific arms first and the wildcard last, or delete the arm. A \
6342                guarded arm covers nothing, since its guard may fail.",
6343        example: "type Status = enum { Pending, Active, Done }\n\n\
6344                  fn label(s: Status) -> String {\n    match s {\n        _ => \"other\"\n        Pending => \"waiting\"    // ✗ the `_` above already matches it\n    }\n}\n\n\
6345                  fn label(s: Status) -> String {\n    match s {\n        Pending => \"waiting\"\n        _ => \"other\"            // ✓ the catch-all last\n    }\n}",
6346    },
6347    Explain {
6348        code: "bynk.types.variant_arity",
6349        blurb: "A variant is built like a call, with one argument for each payload field it \
6350                declares, so `Circle(radius: Int)` takes one and a variant with no payload \
6351                is written bare. A different number of arguments is refused at the \
6352                construction. Pass one value for each declared field, or change the type \
6353                declaration if the variant should carry more. The same code covers the \
6354                built-in `QueueResult` and `HttpResult` constructors. A `match` arm with the \
6355                wrong number of bindings is the separate code `bynk.types.pattern_arity`.",
6356        example: "type Shape =\n  | Circle(radius: Int)\n  | Square(side: Int)\n\n\
6357                  fn make() -> Shape {\n    Circle(1, 2)    // ✗ `Circle` takes 1 argument\n}\n\n\
6358                  fn make() -> Shape {\n    Circle(1)       // ✓\n}",
6359    },
6360    Explain {
6361        code: "bynk.types.variant_missing_payload",
6362        blurb: "A variant with a payload is built by calling it, with its payload as arguments. Written bare, `Circle` is not a value, since nothing fills `radius`; only a variant with no payload can stand alone. Call it with one argument per field, as `Circle(10)`. The qualified form `Shape.Circle` is refused in the same way. A call with the wrong number of arguments is `bynk.types.variant_arity`.",
6363        example: "type Shape =\n  | Circle(radius: Int)\n  | Dot\n\nfn make() -> Shape {\n    Circle    // ✗ `Circle` carries a payload\n}\n\nfn make() -> Shape {\n    Circle(10)    // ✓\n}",
6364    },
6365    Explain {
6366        code: "bynk.types.variant_payload_mismatch",
6367        blurb: "A variant's payload fields have declared types and are checked like function parameters: `Circle(\"big\")` for `radius: Int` is refused at the argument, with no conversion. Pass a value of the field's type. For a generic sum the type argument is inferred from the arguments first, and the check applies to the result. The wrong number of arguments is `bynk.types.variant_arity`.",
6368        example: "type Shape =\n  | Circle(radius: Int)\n  | Dot\n\nfn make() -> Shape {\n    Circle(\"big\")    // ✗ `radius` is an `Int`\n}\n\nfn make() -> Shape {\n    Circle(10)    // ✓\n}",
6369    },
6370    Explain {
6371        code: "bynk.uses.name_conflict",
6372        blurb: "A unit that `uses` a commons gets what it declares (types, functions, constants, assets \
6373                and embeds) in scope under their own names, with no prefix. If two commons it uses \
6374                both declare the same name, a mention of it could mean either, so the compiler \
6375                refuses the second `uses`. `uses` has no `as` rename yet. Rename one of the \
6376                declarations, drop one of the `uses`, or mark the declaration `private` if only \
6377                its own commons needs it, since a `private` declaration is never imported and so \
6378                never conflicts.",
6379        example: "// billing.bynk\n\
6380                  commons billing\n\n\
6381                  type Amount = Int where Positive\n\n\
6382                  // shipping.bynk\n\
6383                  commons shipping\n\n\
6384                  type Amount = Int where NonNegative    // both declare `Amount`\n\
6385                  type Postage = Int where NonNegative   // ✓ renamed\n\n\
6386                  // orders.bynk\n\
6387                  commons orders\n\n\
6388                  uses billing\n\
6389                  uses shipping                          // ✗ `Amount` is also declared by `billing`",
6390    },
6391    Explain {
6392        code: "bynk.uses.self_reference",
6393        blurb: "`uses` brings another commons into scope. A commons' own declarations are already there, so using itself adds nothing, and a unit that depends on itself is a cycle of length one. Delete the clause, or, if you meant another commons, name it. The mirror of this for contexts is `bynk.consumes.self_reference`.",
6394        example: "// tax.bynk\ncommons tax\n\nfn rate() -> Int { 20 }\n\n// money.bynk\ncommons money\n\nuses money                       // ✗ a commons cannot use itself\nuses tax                         // ✓ a different commons\n\ntype Amount = Int where NonNegative",
6395    },
6396    Explain {
6397        code: "bynk.uses.target_is_context",
6398        blurb: "`uses` is for shared types and functions, and those live in a commons. A context is something to depend on: it has services to call and capabilities to use, and that is `consumes`. Replace `uses` with `consumes`. The mirror of this is `bynk.consumes.target_is_commons`.",
6399        example: "// pay.bynk\ncontext pay\n\n// shop.bynk\ncontext shop\n\nuses pay                         // ✗ `pay` is a context\nconsumes pay                     // ✓ depend on a context with `consumes`",
6400    },
6401    Explain {
6402        code: "bynk.uses.unknown_commons",
6403        blurb: "`uses` brings a commons' types, functions and constants into scope, so it must name a commons in the project, and no unit of that name exists. Check the spelling against the `commons` line of the unit you mean. If the unit is a context, `uses` is the wrong clause: that is `bynk.uses.target_is_context`.",
6404        example: "// money.bynk\ncommons money\n\ntype Amount = Int where NonNegative\n\n// shop.bynk\ncontext shop\n\nuses mony                        // ✗ no commons `mony`\nuses money                       // ✓ the commons' declared name",
6405    },
6406    Explain {
6407        code: "bynk.val.agent_not_generable",
6408        blurb: "A `for all` over a declared type draws values from it, but an agent is not a value: a state that satisfies every invariant need not be one the agent can reach. So an agent cannot be a `for all` binding. To test an agent over generated input, bind a `History` of it, which drives real handler calls and so reaches only real states.",
6409        example: "// tests/t.test.bynk\nfor all w: Wallet { … }              // ✗ an agent is not generated\nfor all run: History[Wallet] { … }   // ✓ a run of its handlers",
6410    },
6411    Explain {
6412        code: "bynk.val.arity",
6413        blurb: "`Val[T]` takes at most one argument, the pin: `Val[Age]` lets the \
6414                compiler choose a value, `Val[Age](20)` fixes it. `Val` makes one \
6415                value of one type, so a second argument has no meaning. Pass one \
6416                pin or none.",
6417        example: "// demo/ages.bynk\n\
6418                  type Age = Int where InRange(0, 150)\n\
6419                  \n\
6420                  // tests/ages.test.bynk\n\
6421                  let a = Val[Age](20, 30)   // ✗ two pins\n\
6422                  let a = Val[Age](20)       // ✓ one",
6423    },
6424    Explain {
6425        code: "bynk.val.generic_type",
6426        blurb: "`Val[T]` fabricates a value for a test from the declaration of `T`. \
6427                That is not yet done for each instantiation of a generic type, so \
6428                `Val` refuses one whether it is written bare, `Val[Box]`, or \
6429                applied, `Val[Box[Int]]`. The type itself is fine, and may cross a \
6430                boundary through its codec; only fabrication is missing. Build the \
6431                value yourself instead: a record literal for a generic record, \
6432                one of its variants for a generic sum.",
6433        example: "type Box[T] = { v: T }\n\nlet b = Val[Box[Int]]    // ✗ a generic type cannot be fabricated\n\nlet b = Box { v: 1 }     // ✓ build it",
6434    },
6435    Explain {
6436        code: "bynk.val.literal_violates",
6437        blurb: "A pinned `Val[T](…)` is checked against the refinement of `T` at \
6438                compile time, and this literal breaks it, so the test would build \
6439                a value the type does not allow. Pin a value that satisfies the \
6440                refinement, or drop the pin and let `Val[T]` choose one. To test \
6441                that an invalid value is refused, call `T.of(…)` and expect an \
6442                `Err`.",
6443        example: "// demo/ages.bynk\n\
6444                  type Age = Int where InRange(0, 150)\n\
6445                  \n\
6446                  // tests/ages.test.bynk\n\
6447                  let a = Val[Age](200)  // ✗ 200 is outside InRange(0, 150)\n\
6448                  let a = Val[Age](20)   // ✓ inside it",
6449    },
6450    Explain {
6451        code: "bynk.val.needs_pin",
6452        blurb: "In a test, a bare `Val[T]` fabricates a valid value of `T`. It can do that for \
6453                most refinements (`Positive` gives `1`, `MinLength(3)` a string of length three) \
6454                but not for a `Matches` pattern or `IsoDate`, so it refuses rather than guess; \
6455                the same goes for a record or sum that reaches one. A `for all` over such a type \
6456                is refused too. Pin a value, `Val[Code](\"abc\")`, which is checked against the \
6457                refinement, or give the type an `@example` and use bare `Val`. See the \
6458                `bynk.val.*` codes for pins that are not literals or do not satisfy the type.",
6459        example: "// demo/codes.bynk\n\
6460                  type Code = String where Matches(\"[a-z]+\")\n\
6461                  \n\
6462                  // tests/codes.test.bynk\n\
6463                  let c = Val[Code]              // ✗ no value can be made from a pattern\n\
6464                  let c = Val[Code](\"abc\")      // ✓ pin one",
6465    },
6466    Explain {
6467        code: "bynk.val.outside_test",
6468        blurb: "`Val[T]` fabricates a value that merely satisfies `T`. That is \
6469                what a test wants and what running code must not do, so `Val` is \
6470                allowed only in test code. In a function or handler, take the \
6471                value as a parameter or build it properly, for instance with \
6472                `Age.of(20)`. See `bynk.val.needs_pin` for a bare `Val` that a \
6473                test cannot generate.",
6474        example: "// demo/ages.bynk\n\
6475                  type Age = Int where InRange(0, 150)\n\
6476                  \n\
6477                  fn sample() -> Age { Val[Age] }   // ✗ not test code\n\
6478                  \n\
6479                  // tests/ages.test.bynk\n\
6480                  let a = Val[Age]                  // ✓ in a case",
6481    },
6482    Explain {
6483        code: "bynk.val.pin_not_literal",
6484        blurb: "A pin on `Val[T]` is checked against the refinement of `T` when \
6485                the program compiles, so it must be a literal of `T`'s base type. \
6486                A name or a call has no value at that point. Write the literal in \
6487                place. For a computed value, build it with `Age.of(…)` and `?`, \
6488                which fails the case if the value is not valid.",
6489        example: "// demo/ages.bynk\n\
6490                  type Age = Int where InRange(0, 150)\n\
6491                  \n\
6492                  // tests/ages.test.bynk\n\
6493                  let n = 20\n\
6494                  let a = Val[Age](n)    // ✗ a name, not a literal\n\
6495                  let a = Val[Age](20)   // ✓ a literal",
6496    },
6497    Explain {
6498        code: "bynk.val.pin_unsupported",
6499        blurb: "A pinned `Val[T](lit)` is accepted only for a refined type, where the literal is checked against the refinement. A sum, record or opaque type takes no pin, so one is refused. Use bare `Val[T]`, which builds the first variant, or every field, itself, or construct the value directly with a variant or a record literal. A pin that is not a literal at all is `bynk.val.pin_not_literal`.",
6500        example: "// tests/demo.test.bynk\nlet s = Val[Status](1)   // ✗ `Status` is a sum\nlet s = Val[Status]      // ✓ bare `Val` picks the first variant",
6501    },
6502    Explain {
6503        code: "bynk.val.unknown_type",
6504        blurb: "`Val[T]` fabricates a value of the type it names, so the name must \
6505                resolve to a type the suite can see. A misspelt name stops here, \
6506                before anything else about the value can be checked. Fix the \
6507                spelling, or declare the type in the target unit or the suite. The \
6508                same code covers a `for all` binder whose type does not resolve.",
6509        example: "// demo/ages.bynk\n\
6510                  type Age = Int where InRange(0, 150)\n\
6511                  \n\
6512                  // tests/ages.test.bynk\n\
6513                  let a = Val[Agee]      // ✗ no such type\n\
6514                  let a = Val[Age]       // ✓ the declared type",
6515    },
6516    Explain {
6517        code: "bynk.val.unsupported_kind",
6518        blurb: "`Val[T]` fabricates a value from a type declaration: a refinement, a sum, a record or an opaque type. A built-in type such as `Int` or `String`, a `List` or a function type has no declaration to draw from, so `Val` refuses it. Write the value, `20`, or declare a type for it, which `Val` can then fabricate.",
6519        example: "type Age = Int where InRange(0, 150)\n\nlet n = Val[Int]   // ✗ a built-in type\nlet a = Val[Age]   // ✓ a declared type",
6520    },
6521    Explain {
6522        code: "bynk.visibility.private_in_public",
6523        blurb: "A public declaration may not mention a `private` type of its own unit in its \
6524                signature: a public function's parameters and return, a public type's fields and \
6525                variant payloads, a public constant's type, or a context's `exports` list. A \
6526                unit that `uses` the commons could neither name that type nor build a value of \
6527                it, so the function would be half-usable. Make the type public, or make the \
6528                declaration `private` too. Services, agents and capabilities are not checked \
6529                here; a context's `exports` governs them.",
6530        example: "private type Tally = { lines: Int, sum: Int }\n\
6531                  \n\
6532                  fn tally(n: Int) -> Tally { … }            // ✗ public, but returns a private type\n\
6533                  private fn tally(n: Int) -> Tally { … }    // ✓ private too",
6534    },
6535    Explain {
6536        code: "bynk.visibility.private_item",
6537        blurb: "A `private` function, type, constant, asset or embed (or a `private` method) is visible only \
6538                within its own unit, across all of that unit's files, and to the unit's suites. It is \
6539                never visible through `uses`, so a unit that uses the commons cannot name it. The \
6540                compiler reports that the name is private, not that it is unknown, so you know it \
6541                exists. `private` keeps a helper out of the public surface, so it can change \
6542                without breaking anyone. Call the commons' public function that does the job, or, \
6543                if the item really belongs to the public surface, remove `private` where it is \
6544                declared.",
6545        example: "// pricing.bynk\n\
6546                  commons pricing\n\n\
6547                  fn total(items: List[Item]) -> Int { … }\n\
6548                  private fn lineTotal(i: Item) -> Int { … }\n\n\
6549                  // shop.bynk\n\
6550                  commons shop\n\n\
6551                  uses pricing\n\n\
6552                  fn cost(i: Item) -> Int {\n    lineTotal(i)      // ✗ `lineTotal` is a private function of `pricing`\n    total([i])        // ✓ the public function does the same job\n}",
6553    },
6554    Explain {
6555        code: "bynk.visibility.private_not_allowed",
6556        blurb: "`private` hides a `fn`, `type`, `messages`, `asset`, `embed` or `const` from the \
6557                units that import its commons or context. It does not apply to a service, agent, \
6558                capability, provider, actor or event, or to anything in an adapter: how far \
6559                those reach is decided by a context's `exports` and `consumes`, and an adapter's \
6560                `exports`. Remove `private`. See `bynk.visibility.private_item` for using \
6561                something that is private.",
6562        example: "private service total { … }        // ✗ `private` does not apply to a service\n\
6563                  service total { … }                // ✓ reach is governed by `exports`",
6564    },
6565    Explain {
6566        code: "bynk.within.in_agent_handler",
6567        blurb: "`within` hands the effect it abandons on a timeout to the execution context, and an agent handler has none. Call it from the service handler that calls the agent, so the agent's work is bounded from outside. For a slow call out, `FetchOptions.timeout` bounds it inside the agent. The same rule holds for `bynk.race.in_agent_handler`.",
6568        example: "agent Feed {\n    key id: String\n\n    on call quote() -> Effect[Result[Int, TimedOut]] {\n        Slow(\"a\").get().within(1.second)   // ✗ an agent handler has no execution context\n    }\n}\n\nservice quotes {\n    on call() -> Effect[Result[Int, TimedOut]] by Caller {\n        Slow(\"a\").get().within(1.second)   // ✓ the service handler has\n    }\n}",
6569    },
6570    Explain {
6571        code: "bynk.within.in_pure_context",
6572        blurb: "`within` hands the effect it abandons on a timeout to the execution context, and only an effectful body has one: a pure function never runs an effect at all. Change the enclosing function's return type to `Effect[…]` so its body can run it. The same rule holds for `bynk.race.in_pure_context`.",
6573        example: "fn bounded(e: Effect[Int]) -> Int {\n    let r = e.within(1.second)   // ✗ the body is pure\n    0\n}\n\nfn bounded(e: Effect[Int]) -> Effect[Result[Int, TimedOut]] {   // ✓ an effectful body\n    e.within(1.second)\n}",
6574    },
6575    Explain {
6576        code: "bynk.within.outside_handler",
6577        blurb: "`within` hands the effect it abandons on a timeout to the execution context, which only a service handler's body, or a function's it calls, has. A WebSocket handler, a provider operation and a test `case` have none. Move the `within` into a service handler or a function, and have the case call that, simulating a slow call with `stub … after`. In an agent handler the rule is `bynk.within.in_agent_handler`.",
6578        example: "// tests/t.test.bynk\nlet r <- Slow(\"a\").get().within(1.second)   // ✗ a case has no execution context\n\nlet r <- quotes.call()                      // ✓ the service handler bounds it",
6579    },
6580    Explain {
6581        code: "bynk.within.timed_out_not_in_scope",
6582        blurb: "`within` returns `Result[_, TimedOut]`, and `TimedOut` is declared in `bynk`, so a unit that wants `within` has to consume it. Without that the result type names a type the unit cannot see. Add `consumes bynk { TimedOut }` to the unit, or add `TimedOut` to its existing `consumes bynk { … }` list.",
6583        example: "let r <- Pricing.quote(id).within(2.seconds)   // ✗ `TimedOut` is not in scope\n\nconsumes bynk { TimedOut }                     // ✓ in the unit's header\nlet r <- Pricing.quote(id).within(2.seconds)",
6584    },
6585    Explain {
6586        code: "bynk.ws.lifecycle_by_mismatch",
6587        blurb: "The connection's principal is verified once, by `on open`'s `by`, and carried for the life of the connection; `on message` and `on close` read it and never verify again. So their `by` must name the same actor as `on open`'s, or the same members of an actor sum. The binder names may differ. Change the lifecycle handler's `by` to match `on open`.",
6588        example: "actor Member { … }\nactor Admin { … }\n\nservice gateway from websocket(in: Frame, out: Frame) {\n    on open (room: RoomId) -> Effect[()] by user: Member { … }\n    on message (room: RoomId, frame: Frame) -> Effect[()] by admin: Admin { … }   // ✗ `on open` is `by` `Member`\n    on message (room: RoomId, frame: Frame) -> Effect[()] by user: Member { … }   // ✓\n}",
6589    },
6590    Explain {
6591        code: "bynk.ws.message_frame_param",
6592        blurb: "A WebSocket `on message` handler is called with a decoded inbound frame, so it needs exactly one parameter of the service's `in:` type. Any other parameters are route values recovered from the connection. Add the frame parameter. A route value whose type differs from `on open`'s is `bynk.ws.route_param_mismatch`.",
6593        example: "service gateway from websocket(in: Frame, out: Frame) {\n    on message (room: RoomId) -> Effect[()] by user: Member { … }                  // ✗ no `Frame` parameter\n    on message (room: RoomId, frame: Frame) -> Effect[()] by user: Member { … }   // ✓\n}",
6594    },
6595    Explain {
6596        code: "bynk.ws.open_given_unsupported",
6597        blurb: "A WebSocket `on open` cannot declare `given` capabilities. It only accepts the upgrade and hands the connection to an agent; on Workers it runs inside the Durable Object that holds the connection, where there is no composition root to supply capabilities. Put the work that needs a capability in the agent handler the connection is transferred to, which carries its own `given`.",
6598        example: "service gateway from websocket(in: Frame, out: Frame) {\n    on open (room: RoomId) -> Effect[()] by user: Member given Clock { … }   // ✗ no capabilities on `on open`\n}\n\nservice gateway from websocket(in: Frame, out: Frame) {\n    on open (room: RoomId) -> Effect[()] by user: Member { … }   // ✓ the agent's handler takes the `given`\n}",
6599    },
6600    Explain {
6601        code: "bynk.ws.open_transfer_cross_file",
6602        blurb: "On the Workers target, a `from websocket` service's `on open` is hosted inside the \
6603                Durable Object of the agent it hands the connection to, and that method is emitted \
6604                from the file the service and the agent share. When a context is split over \
6605                several files, each is emitted on its own, so a service in one file that transfers \
6606                to an agent in another would be routed to the agent's Durable Object and never \
6607                handled there: the upgrade would answer `404`. The compiler refuses the layout. \
6608                Put the service in the agent's file, or build for `--target bundle`, where the \
6609                open is an ordinary method and the layout works.",
6610        example: "// chat/gateway.bynk\n\
6611                  service ChatGateway from websocket(in: ClientFrame, out: ServerFrame) {\n\
6612                  \x20\x20on open (roomId: RoomId) -> Effect[()] by v: Visitor {   // ✗ `Room` is declared in another file\n\
6613                  \x20\x20\x20\x20let _ <- Room(roomId).join(connection)\n\
6614                  \x20\x20\x20\x20()\n\
6615                  \x20\x20}\n\
6616                  }\n\
6617                  \n\
6618                  // chat/room.bynk\n\
6619                  agent Room {\n\
6620                  \x20\x20key id: RoomId\n\
6621                  }\n\
6622                  \n\
6623                  // chat/room.bynk\n\
6624                  service ChatGateway from websocket(in: ClientFrame, out: ServerFrame) {   // ✓ in the agent's file\n\
6625                  \x20\x20on open (roomId: RoomId) -> Effect[()] by v: Visitor {\n\
6626                  \x20\x20\x20\x20let _ <- Room(roomId).join(connection)\n\
6627                  \x20\x20\x20\x20()\n\
6628                  \x20\x20}\n\
6629                  }",
6630    },
6631    Explain {
6632        code: "bynk.ws.open_transfer_key",
6633        blurb: "On Workers the upgrade is routed to the Durable Object that hosts the connection \
6634                before the `on open` body runs, so the edge has to work out the agent's key on its \
6635                own. A route parameter, a `const` of the context or of a commons it `uses`, or a \
6636                literal can be evaluated there. A key computed in the body, such as a `let`, \
6637                cannot, because the body has not run. Key the agent by a parameter of `on open`, a \
6638                constant, or a literal. The bundle target runs the body first, so it does not \
6639                check this.",
6640        example: "on open () -> Effect[()] by v: Visitor {\n\
6641                  \x20\x20let room = \"lobby\"\n\
6642                  \x20\x20let _ <- Room(room).join(connection)          // ✗ `room` is bound in the body, which has not run yet\n\
6643                  \x20\x20()\n\
6644                  }\n\
6645                  \n\
6646                  on open () -> Effect[()] by v: Visitor {\n\
6647                  \x20\x20let _ <- Room(\"lobby\").join(connection)       // ✓ a literal\n\
6648                  \x20\x20()\n\
6649                  }",
6650    },
6651    Explain {
6652        code: "bynk.ws.open_transfer_shape",
6653        blurb: "A WebSocket `on open` must hand its `connection` to exactly one agent, unconditionally, as `Room(room).join(user.identity, connection)`. On Workers the upgrade is routed to that agent's Durable Object, which holds the connection, so it needs a single target the compiler can find. Neither none nor several will do, and a transfer inside an `if` or a `match` is not found. A connection left undisposed is `bynk.held.leak`; a transfer whose key the edge cannot compute is `bynk.ws.open_transfer_key`.",
6654        example: "service gateway from websocket(in: Frame, out: Frame) {\n    on open (room: RoomId) -> Effect[()] by user: Member {   // ✗ `connection` is never transferred\n        let _ <- connection.close()\n        ()\n    }\n}\n\nservice gateway from websocket(in: Frame, out: Frame) {\n    on open (room: RoomId) -> Effect[()] by user: Member {\n        let _ <- Room(room).join(user.identity, connection)   // ✓ handed to one agent\n        ()\n    }\n}",
6655    },
6656    Explain {
6657        code: "bynk.ws.route_param_mismatch",
6658        blurb: "`on message` and `on close` are not given a fresh URL: their route values are recovered, in order, from what `on open` accepted. So the leading parameters of each must have the same types as `on open`'s, in the same order. A different type at some position would reinterpret one route value as another. Match the types of `on open`'s parameters; the names may differ. A missing frame parameter is `bynk.ws.message_frame_param`.",
6659        example: "on open (room: RoomId) -> Effect[()] by user: Member { … }\non close (who: UserId) -> Effect[()] by user: Member { … }   // ✗ the first route value is a `RoomId`\n\non open (room: RoomId) -> Effect[()] by user: Member { … }\non close (room: RoomId) -> Effect[()] by user: Member { … }   // ✓ same leading types",
6660    },
6661];
6662
6663/// The curated explanation for a diagnostic `code`, or `None` when the code has
6664/// no explanation yet (the designed graceful-fallback state, DECISION B).
6665pub fn explain(code: &str) -> Option<&'static Explain> {
6666    EXPLANATIONS.iter().find(|e| e.code == code)
6667}
6668
6669/// The hosted diagnostic index page (the generated `reference/diagnostics`
6670/// page). Each code's own page is `{INDEX_PATH}<code>/`, which `/d/<code>`
6671/// redirects to.
6672pub const INDEX_PATH: &str = "/reference/diagnostics/";
6673
6674/// The anchor slug of a category's `## <title>` heading on the generated
6675/// diagnostic index (Starlight/github-slugger shape: lowercase, spaces to
6676/// hyphens, punctuation dropped), e.g. `"type-checking"`.
6677fn category_anchor(cat: &str) -> String {
6678    category_title(cat)
6679        .chars()
6680        .filter_map(|c| match c {
6681            ' ' => Some('-'),
6682            c if c.is_alphanumeric() || c == '-' => Some(c.to_ascii_lowercase()),
6683            _ => None,
6684        })
6685        .collect()
6686}
6687
6688/// The link for any diagnostic `code` (#3876): `{BOOK_BASE_URL}/d/<code>` for
6689/// a registry code, which the site serves a page for whether or not the code
6690/// has an explanation; otherwise (a host-synthetic code) `{BOOK_BASE_URL}/d/`,
6691/// the index. What the LSP's `codeDescription`, the editor's Explain panel,
6692/// `bynk explain`, the MCP tools and the playground all link.
6693pub fn href(code: &str) -> String {
6694    if lookup(code).is_some() {
6695        format!("{BOOK_BASE_URL}{D_PATH}{code}")
6696    } else {
6697        format!("{BOOK_BASE_URL}{D_PATH}")
6698    }
6699}
6700
6701/// Look up a code's registry entry by exact match — the one place
6702/// [`crate::error::Severity::for_error`] reads a code's severity, instead of
6703/// hardcoding its own copy of the (small) warning set.
6704pub fn lookup(code: &str) -> Option<&'static DiagnosticInfo> {
6705    REGISTRY.iter().find(|d| d.code == code)
6706}
6707
6708/// Every diagnostic code the compiler emits, sorted by code.
6709pub const REGISTRY: &[DiagnosticInfo] = &[
6710    d(
6711        "bynk.actor.bearer_identity_not_string_constructible",
6712        "A `Bearer` actor's identity is not a string-constructible type.",
6713    ),
6714    d(
6715        "bynk.actor.bearer_missing_secret",
6716        "A `Bearer` actor does not name its signing secret.",
6717    ),
6718    d(
6719        "bynk.actor.binder_shadows_param",
6720        "A `by` actor binder collides with a handler parameter of the same name.",
6721    ),
6722    d(
6723        "bynk.actor.by_on_agent",
6724        "A `by` actor clause was placed on an agent `on call` handler, which has no actor.",
6725    ),
6726    d(
6727        "bynk.actor.caller_not_admitted",
6728        "A call is made from a context the callee's `Caller` refinement does not admit.",
6729    ),
6730    d(
6731        "bynk.actor.duplicate_sum_scheme",
6732        "Two peers in a multi-actor sum share an authentication scheme.",
6733    ),
6734    d(
6735        "bynk.actor.foreign_context_name_unkeyable",
6736        "A context declaring a `Foreign` actor has a name no call key can be named from.",
6737    ),
6738    d(
6739        "bynk.actor.foreign_duplicate_secret",
6740        "A `Foreign` actor's secret is also another actor's secret in the same context.",
6741    ),
6742    d(
6743        "bynk.actor.foreign_identity_unsupported",
6744        "A `Foreign` actor declares an `identity`.",
6745    ),
6746    d(
6747        "bynk.actor.foreign_missing_secret",
6748        "A `Foreign` actor does not name the secret its calls are signed with.",
6749    ),
6750    d(
6751        "bynk.actor.foreign_name_is_context_name",
6752        "A `Foreign` actor's name could be read as a context's name.",
6753    ),
6754    d(
6755        "bynk.actor.foreign_reserved_secret",
6756        "A `Foreign` actor's secret uses a `BYNK_CALL_` edge key's name.",
6757    ),
6758    d(
6759        "bynk.actor.foreign_secret_not_string",
6760        "A `Foreign` actor's secret is not a string.",
6761    ),
6762    d(
6763        "bynk.actor.identity_not_sealed",
6764        "An actor identity type is not a context-ownable (sealed) value type.",
6765    ),
6766    d(
6767        "bynk.actor.missing_by_on_call",
6768        "An `on call` handler lacks the required `by` actor clause.",
6769    ),
6770    d(
6771        "bynk.actor.missing_by_on_http",
6772        "An HTTP handler lacks the required `by` actor clause.",
6773    ),
6774    d(
6775        "bynk.actor.oidc_identity_not_string_constructible",
6776        "An `Oidc` actor's identity is not a string-constructible type.",
6777    ),
6778    d(
6779        "bynk.actor.oidc_missing_audience",
6780        "An `Oidc` actor does not name its `audience`.",
6781    ),
6782    d(
6783        "bynk.actor.oidc_missing_issuer",
6784        "An `Oidc` actor does not name its `issuer`.",
6785    ),
6786    d(
6787        "bynk.actor.oidc_missing_jwks",
6788        "An `Oidc` actor does not name its `jwks` endpoint.",
6789    ),
6790    d(
6791        "bynk.actor.oidc_not_in_sum",
6792        "An `Oidc` actor appears as a member of a multi-actor sum.",
6793    ),
6794    d(
6795        "bynk.actor.oidc_trust_from_is_secret",
6796        "An `Oidc` actor's `trustFrom` names an environment variable that an actor uses as its `secret`.",
6797    ),
6798    d(
6799        "bynk.actor.oidc_trust_from_not_string",
6800        "An `Oidc` actor's `trustFrom` isn't a string naming an environment variable.",
6801    ),
6802    d(
6803        "bynk.actor.outside_context",
6804        "An `actor` was declared outside a context (e.g. in a commons).",
6805    ),
6806    d(
6807        "bynk.actor.refinement_base_unsupported",
6808        "A refinement actor's base is not a `Bearer` actor (no claims to authorise against).",
6809    ),
6810    d(
6811        "bynk.actor.refinement_in_sum",
6812        "A refinement actor appears as a member of a multi-actor sum.",
6813    ),
6814    d(
6815        "bynk.actor.refinement_predicate_unsupported",
6816        "A refinement actor's `where` predicate is outside the closed claim-predicate set.",
6817    ),
6818    d(
6819        "bynk.actor.scheme_arg_kind",
6820        "A scheme config value other than `SignedCookie`'s is a duration or a bare name, which only `SignedCookie` takes.",
6821    ),
6822    d(
6823        "bynk.actor.scheme_not_admissible",
6824        "An actor's scheme is not admissible on this handler's protocol.",
6825    ),
6826    d(
6827        "bynk.actor.signature_identity_unsupported",
6828        "A `Signature` actor declared an `identity`, which is not yet supported.",
6829    ),
6830    d(
6831        "bynk.actor.signature_missing_header",
6832        "A `Signature` actor does not name its signature header.",
6833    ),
6834    d(
6835        "bynk.actor.signature_missing_secret",
6836        "A `Signature` actor does not name its signing secret.",
6837    ),
6838    d(
6839        "bynk.actor.signature_requires_body",
6840        "A `Signature` handler does not take a `body` parameter.",
6841    ),
6842    d(
6843        "bynk.actor.signature_tolerance_without_timestamp",
6844        "A `Signature` actor set `tolerance` without a `timestamp` header.",
6845    ),
6846    d(
6847        "bynk.actor.signed_cookie_bad_arg",
6848        "A `SignedCookie` config value has the wrong kind.",
6849    ),
6850    d(
6851        "bynk.actor.signed_cookie_bad_name",
6852        "A `SignedCookie` `cookie` is not a legal cookie name.",
6853    ),
6854    d(
6855        "bynk.actor.signed_cookie_bad_ttl",
6856        "A `SignedCookie` `ttl` is not a positive whole number of seconds.",
6857    ),
6858    d(
6859        "bynk.actor.signed_cookie_duplicate_key",
6860        "A `SignedCookie` config repeats a key.",
6861    ),
6862    d(
6863        "bynk.actor.signed_cookie_identity_not_string_constructible",
6864        "A `SignedCookie` actor's identity is missing or not a string-constructible type.",
6865    ),
6866    d(
6867        "bynk.actor.signed_cookie_issue_needs_clock",
6868        "`Actor.issue(identity)` on a `SignedCookie` actor is called where the handler does not list `Clock` in `given`.",
6869    ),
6870    d(
6871        "bynk.actor.signed_cookie_issue_outside_handler",
6872        "`Actor.issue(identity)` on a `SignedCookie` actor is called outside a service handler (in a provider or an agent).",
6873    ),
6874    d(
6875        "bynk.actor.signed_cookie_missing_secret",
6876        "A `SignedCookie` actor does not name its signing secret.",
6877    ),
6878    d(
6879        "bynk.actor.signed_cookie_missing_ttl",
6880        "A `SignedCookie` actor does not declare a `ttl`.",
6881    ),
6882    d(
6883        "bynk.actor.signed_cookie_not_in_sum",
6884        "A `SignedCookie` actor appears as a member of a multi-actor sum.",
6885    ),
6886    d(
6887        "bynk.actor.signed_cookie_public_cache",
6888        "A `@cache(scope: public)` route is guarded by a `SignedCookie` actor.",
6889    ),
6890    d(
6891        "bynk.actor.signed_cookie_read_directly",
6892        "A typed `cookies` field reads the session cookie that a route's `SignedCookie` actor consumes.",
6893    ),
6894    d(
6895        "bynk.actor.signed_cookie_secret_shared",
6896        "A `SignedCookie` actor's `secret` or `previous` is also used by another actor, or by itself.",
6897    ),
6898    warn(d(
6899        "bynk.actor.signed_cookie_ttl_long",
6900        "A `SignedCookie` `ttl` is longer than 30 days (warning).",
6901    )),
6902    d(
6903        "bynk.actor.signed_cookie_unknown_key",
6904        "A `SignedCookie` config has a key outside the closed set.",
6905    ),
6906    warn(d(
6907        "bynk.actor.signed_cookie_unprefixed",
6908        "A `SignedCookie` `cookie` does not start with `__Host-` (warning).",
6909    )),
6910    d(
6911        "bynk.actor.signed_cookie_write_directly",
6912        "A cookie record's typed write names the session cookie that a `SignedCookie` actor consumes.",
6913    ),
6914    d(
6915        "bynk.actor.signed_cookie_write_literal",
6916        "An untyped `Cookie` literal is named like a `SignedCookie` actor's session cookie.",
6917    ),
6918    d(
6919        "bynk.actor.sum_requires_binder",
6920        "A multi-actor sum `by` clause has no binder to match the resolved actor.",
6921    ),
6922    d(
6923        "bynk.actor.unknown_actor",
6924        "A handler's `by` clause names an actor that is not declared.",
6925    ),
6926    d(
6927        "bynk.actor.unknown_context",
6928        "`IsContext(…)` names something that is not a context of the project.",
6929    ),
6930    d(
6931        "bynk.actor.unknown_scheme",
6932        "An actor declares an authentication scheme that is not compiler-known.",
6933    ),
6934    d(
6935        "bynk.actor.unreachable_sum_arm",
6936        "A multi-actor sum has an arm unreachable after a catch-all (`None`) peer.",
6937    ),
6938    dg(
6939        "bynk.adapter.consumes_context",
6940        "An `adapter` consumed a context; adapter dependencies are adapter-to-adapter.",
6941        &["consumes_decl"],
6942    ),
6943    dg(
6944        "bynk.adapter.consumes_requires_selection",
6945        "An `adapter` used a whole-unit or aliased `consumes`; adapters must select capabilities with `consumes U { Cap, … }`.",
6946        &["consumes_decl"],
6947    ),
6948    dg(
6949        "bynk.adapter.disallowed_item",
6950        "An `adapter` declared a `service`, `agent`, or other item it may not contain.",
6951        &["adapter_decl"],
6952    ),
6953    dg(
6954        "bynk.adapter.duplicate_binding",
6955        "An `adapter` declared more than one `binding` clause.",
6956        &["binding_decl"],
6957    ),
6958    dg(
6959        "bynk.adapter.include_duplicate",
6960        "An adapter `binding … includes [ … ]` list names one file more than once.",
6961        &["binding_decl"],
6962    ),
6963    dg(
6964        "bynk.adapter.include_kind",
6965        "An adapter `binding … includes [ … ]` entry is not a `.wasm` file; only WebAssembly modules can be included.",
6966        &["binding_decl"],
6967    ),
6968    dg(
6969        "bynk.adapter.include_missing",
6970        "An adapter `binding … includes [ … ]` entry names a file that could not be read.",
6971        &["binding_decl"],
6972    ),
6973    dg(
6974        "bynk.adapter.include_outside",
6975        "An adapter `binding … includes [ … ]` path is absolute or climbs out of the adapter's directory with `..`.",
6976        &["binding_decl"],
6977    ),
6978    dg(
6979        "bynk.adapter.no_binding",
6980        "An `adapter` declares an external provider but no `binding` module to supply it.",
6981        &["adapter_decl"],
6982    ),
6983    dg(
6984        "bynk.adapter.provider_has_body",
6985        "A provider inside an `adapter` has a Bynk body; adapter providers must be external.",
6986        &["provider_decl"],
6987    ),
6988    d(
6989        "bynk.agent.class_conflict",
6990        "An agent class has more than one fate: it is renamed twice, both renamed and removed, or renamed onto a class that already has its own recorded history in `bynk.schema.lock`.",
6991    ),
6992    d(
6993        "bynk.agent.class_removed",
6994        "An agent class recorded in `bynk.schema.lock` is no longer declared, so a deployment's stored instances of it would be orphaned. If the class was never deployed, delete its `[agents]` entry from the lock; renaming or removing a deployed class gets its own declaration in a later state-migrations slice.",
6995    ),
6996    dg(
6997        "bynk.agent.construction_arity",
6998        "An agent was constructed with the wrong number of key arguments.",
6999        &["agent_decl"],
7000    ),
7001    dg(
7002        "bynk.agent.handler_arity",
7003        "An agent handler was called with the wrong number of arguments.",
7004        &["agent_decl"],
7005    ),
7006    dg(
7007        "bynk.agent.handler_not_found",
7008        "Called a handler the agent does not declare.",
7009        &["agent_decl"],
7010    ),
7011    dg(
7012        "bynk.agent.key_mismatch",
7013        "An agent key argument has the wrong type.",
7014        &["agent_decl"],
7015    ),
7016    warn(d(
7017        "bynk.agent.migrate_below_floor",
7018        "A `migrate` step reads a schema version below the agent's floor. A complete `bynk migrate sweep` raised the floor past it, so no stored instance can hold that version: the step emits nothing and can be deleted (warning).",
7019    )),
7020    d(
7021        "bynk.agent.migrate_duplicate",
7022        "Two `migrate` steps in one agent read the same schema version.",
7023    ),
7024    d(
7025        "bynk.agent.migrate_duplicate_assignment",
7026        "A `migrate` step assigns the same `store` field more than once; each field takes at most one value per step (record-literal semantics).",
7027    ),
7028    d(
7029        "bynk.agent.migrate_impure",
7030        "A `migrate` step uses an effect, a capability, `?`, `expect`, or the agent's `key`; steps are pure and key-free so a migration sweep can run them by object ID.",
7031    ),
7032    d(
7033        "bynk.agent.migrate_incomplete",
7034        "A `migrate` step does not account for every change between its version and the current shape: a removed field must be read (`old.f`) or dropped, and a retyped or re-kinded field must be assigned (or dropped, for a `Set`, `Log` or `Cache` field).",
7035    ),
7036    d(
7037        "bynk.agent.migrate_shape_mismatch",
7038        "A `migrate` step's declared old shape (or a `drop`) names a field the lock does not record at that version, or records with a different structure.",
7039    ),
7040    d(
7041        "bynk.agent.migrate_unknown_version",
7042        "A `migrate` step reads a schema version the lock does not record below the agent's current version.",
7043    ),
7044    d(
7045        "bynk.agent.non_additive_state_change",
7046        "An agent's stored state changed in a way deployed data cannot be read through — a `store` field was removed, retyped (including inside a stored record or sum), or changed storage kind. A renamed field is a removed field plus an added one. If the class was never deployed, delete its `[agents]` entry from `bynk.schema.lock`; otherwise widen rather than narrow, or stage the change through a new field.",
7047    ),
7048    dg(
7049        "bynk.agent.outside_context",
7050        "An `agent` was declared outside a context.",
7051        &["agent_decl"],
7052    ),
7053    warn(d(
7054        "bynk.agent.refinement_changed",
7055        "A stored `store` field's refinement changed while its structure did not. A widening is safe; a narrowing faults on load for any stored value that no longer satisfies it (`RehydrationViolation`), so migrate the data first (warning).",
7056    )),
7057    d(
7058        "bynk.agent.removed_live",
7059        "A `removed agent` declaration names a class that is still declared; removing a class deletes its stored data.",
7060    ),
7061    d(
7062        "bynk.agent.replaces_live",
7063        "`agent New replaces Old` names an `Old` that is still declared; a rename moves the old class's data to the new one.",
7064    ),
7065    d(
7066        "bynk.agent.replaces_unknown",
7067        "`agent New replaces Old` names an `Old` that `bynk.schema.lock` does not record for this context, so there is no recorded class to rename.",
7068    ),
7069    dg(
7070        "bynk.agent.return_not_effect",
7071        "An agent handler's return type is not an `Effect`.",
7072        &["agent_decl"],
7073    ),
7074    d(
7075        "bynk.agent.state_name_conflict",
7076        "A type is named `<Agent>State` beside agent `<Agent>`; that name is the agent's state record (its `Cell` fields), which its handlers and invariants see in place of the type.",
7077    ),
7078    warn(d(
7079        "bynk.agent.version_without_path",
7080        "A schema version between the agent's floor and its current version has no way forward: no `migrate` step covers it and its path to the current shape is not entirely additive, so a stored record at that version faults on load with `NoMigrationPath` (warning).",
7081    )),
7082    dg(
7083        "bynk.agents.bad_state_initialiser",
7084        "An agent `store` field initialiser is not a static value of the field's type.",
7085        &["store_field"],
7086    ),
7087    dg(
7088        "bynk.agents.non_zeroable_state_field",
7089        "An agent `store` field has no initialiser and no implicit zero value.",
7090        &["store_field"],
7091    ),
7092    d(
7093        "bynk.asset.duplicate",
7094        "An `asset` name is declared more than once in the same unit.",
7095    ),
7096    d(
7097        "bynk.asset.invalid_at_path",
7098        "An `asset`'s `at` path is not a URL path naming one file, or lies under `/_assets/` or `/_bynk/`, or is a file the platform reads as configuration.",
7099    ),
7100    warn(d(
7101        "bynk.asset.may_shadow_route",
7102        "A parameterised HTTP route matches a fixed asset path, so it never sees requests for that path (a warning).",
7103    )),
7104    d(
7105        "bynk.asset.missing_file",
7106        "An `asset` names a file that is not in the project's `assets/` folder.",
7107    ),
7108    d(
7109        "bynk.asset.needs_project",
7110        "A single-file build met an `asset` declaration; assets need a project build.",
7111    ),
7112    warn(d(
7113        "bynk.asset.not_served",
7114        "A deployable Bundle build met an `asset`; a Bundle ships no files, so its `.url` would not be served (a warning).",
7115    )),
7116    d(
7117        "bynk.asset.outside_assets_dir",
7118        "An `asset` path does not name a file in the project's `assets/` folder.",
7119    ),
7120    d(
7121        "bynk.asset.outside_context_or_commons",
7122        "An `asset` declaration appears outside a context or commons.",
7123    ),
7124    d(
7125        "bynk.asset.path_conflict",
7126        "Two different asset files would be served at one fixed path by the same Worker.",
7127    ),
7128    d(
7129        "bynk.asset.shadows_route",
7130        "A fixed asset path equals a literal HTTP route, in the same context or in another member of the same `[deploy.workers.<key>]` group, which the platform-served asset makes unreachable.",
7131    ),
7132    d(
7133        "bynk.asset.unreadable_file",
7134        "An `asset` names a file in the project's `assets/` folder that could not be read.",
7135    ),
7136    d(
7137        "bynk.asset.unsafe_path",
7138        "An `asset` path is empty, absolute, or contains a `..` segment.",
7139    ),
7140    d(
7141        "bynk.boundary.ambiguous_type",
7142        "A value's type is declared, with different shapes, by more than one consumed context, so its fields cannot be read.",
7143    ),
7144    d(
7145        "bynk.boundary.structural_mismatch",
7146        "Data crossing a context boundary did not match the expected shape.",
7147    ),
7148    dg(
7149        "bynk.capability.base_not_instantiable",
7150        "A derived capability's base is not a platform resource that can be instantiated.",
7151        &["capability_decl"],
7152    ),
7153    dg(
7154        "bynk.capability.derived_outside_context",
7155        "A derived capability was declared outside a context.",
7156        &["capability_decl"],
7157    ),
7158    dg(
7159        "bynk.capability.instance_only",
7160        "A platform capability that is used only through named instances (`Service`, `R2`, `RateLimit`, `Queue`, `Analytics`, `D1`, `EdgeCache`) was used bare, in a `given` clause.",
7161        &["given_clause"],
7162    ),
7163    dg(
7164        "bynk.capability.invalid_option",
7165        "A derived capability's option is not a single positional literal of its kind (string, positive `Int`, or an offered window), is given twice, or is a value the kind refuses (an `@worker` that is not a well-formed Worker name outside the project, a malformed queue `@name`, an unknown `@jurisdiction`).",
7166        &["capability_decl"],
7167    ),
7168    dg(
7169        "bynk.capability.missing_option",
7170        "A derived capability lacks an option its base requires, such as a `Service` instance's `@worker`.",
7171        &["capability_decl"],
7172    ),
7173    dg(
7174        "bynk.capability.not_provided",
7175        "A capability a context requires has no provider in it, on the Workers target or in a bundle with a composition root.",
7176        &["given_clause"],
7177    ),
7178    dg(
7179        "bynk.capability.op_arity",
7180        "A capability operation was called with the wrong number of arguments.",
7181        &["capability_decl"],
7182    ),
7183    dg(
7184        "bynk.capability.outside_context",
7185        "A `capability` was declared outside a context.",
7186        &["capability_decl"],
7187    ),
7188    dg(
7189        "bynk.capability.provider_agent_cross_context",
7190        "On the Workers target, a context requires a capability whose provider, in another context, constructs that context's agents; the consumer's Worker would build the provider without a binding for those agents' Durable Objects.",
7191        &["given_clause"],
7192    ),
7193    dg(
7194        "bynk.capability.unknown_base",
7195        "A derived capability's base is not a capability the context consumes.",
7196        &["capability_decl"],
7197    ),
7198    dg(
7199        "bynk.capability.unknown_operation",
7200        "Referenced an operation the capability does not declare.",
7201        &["capability_decl"],
7202    ),
7203    dg(
7204        "bynk.capability.unknown_option",
7205        "A derived capability carries an option its base does not take.",
7206        &["capability_decl"],
7207    ),
7208    d(
7209        "bynk.cell.invalid_target",
7210        "A `:=` write targets something that is not a `store Cell` field.",
7211    ),
7212    d(
7213        "bynk.cell.self_reference",
7214        "A `:=` right-hand side reads the cell being written (a read-modify-write); use `.update`.",
7215    ),
7216    d(
7217        "bynk.cloudflare.edge_cache_duplicate",
7218        "A context declares a second `EdgeCache` instance; the edge cache is one setting for the whole Worker.",
7219    ),
7220    d(
7221        "bynk.cloudflare.edge_cache_exported",
7222        "An exported capability reaches an `EdgeCache` instance through its provider's `given`; a consuming context would build it in its own Worker, whose purge misses this one's cache.",
7223    ),
7224    d(
7225        "bynk.cloudflare.edge_cache_in_agent",
7226        "An agent handler reaches an `EdgeCache` instance, directly or through a provider's `given`; an agent's purge would not reach the Worker's cache.",
7227    ),
7228    d(
7229        "bynk.cloudflare.edge_cache_in_queue",
7230        "A queue consumer reaches an `EdgeCache` instance; purge from a service handler instead.",
7231    ),
7232    d(
7233        "bynk.cloudflare.edge_cache_in_schedule",
7234        "An `on schedule` handler reaches an `EdgeCache` instance; a cron run's purge is accepted but clears nothing from the fetch cache, so purge from a service handler.",
7235    ),
7236    d(
7237        "bynk.cloudflare.edge_cache_public_authenticated",
7238        "In a context with `EdgeCache`, a `@cache(scope: public)` route is served by an actor that authenticates; its response would be shared at the edge with every caller.",
7239    ),
7240    d(
7241        "bynk.codegen.tsc_failed",
7242        "`tsc` rejected the TypeScript the compiler generated for a program that passed the checker. This is a bug in the Bynk compiler, not in the program: the diagnostic points at the Bynk code the failing generated line came from, with the TypeScript error attached (#3068).",
7243    ),
7244    dg(
7245        "bynk.consumes.alias_conflict",
7246        "Two `consumes` aliases collide.",
7247        &["consumes_decl"],
7248    ),
7249    dg(
7250        "bynk.consumes.capability_name_clash",
7251        "Two flattened `consumes U { Cap }` capabilities collide, or one clashes with a local capability.",
7252        &["consumes_decl"],
7253    ),
7254    dg(
7255        "bynk.consumes.capability_not_selected",
7256        "A capability a consumed unit exports is named (a `given` clause, a call, `provides`, a `stub`) in a file whose own `consumes` does not list it.",
7257        &["consumes_decl"],
7258    ),
7259    dg(
7260        "bynk.consumes.name_conflict",
7261        "A `consumes` name collides with another name in scope.",
7262        &["consumes_decl"],
7263    ),
7264    dg(
7265        "bynk.consumes.self_reference",
7266        "A context `consumes` itself.",
7267        &["consumes_decl"],
7268    ),
7269    dg(
7270        "bynk.consumes.service_arity",
7271        "A consumed service was called with the wrong number of arguments.",
7272        &["consumes_decl"],
7273    ),
7274    dg(
7275        "bynk.consumes.signature_type_unconsumed",
7276        "A cross-context call reaches a service whose signature names a type the consumed context itself consumes from a third context, which the caller does not consume.",
7277        &["consumes_decl"],
7278    ),
7279    dg(
7280        "bynk.consumes.target_is_commons",
7281        "`consumes` targets a `commons` instead of a context.",
7282        &["consumes_decl"],
7283    ),
7284    dg(
7285        "bynk.consumes.type_alias_capability",
7286        "A capability was aliased in `consumes U { Cap as Alias }`; only exported types can be aliased.",
7287        &["consumes_decl"],
7288    ),
7289    dg(
7290        "bynk.consumes.type_alias_conflict",
7291        "A `consumes U { T as Alias }` alias collides with a type or value in scope, or with another alias.",
7292        &["consumes_decl"],
7293    ),
7294    dg(
7295        "bynk.consumes.type_alias_repeated",
7296        "An exported type is aliased more than once, or is selected both bare and aliased, in `consumes U { … }`.",
7297        &["consumes_decl"],
7298    ),
7299    dg(
7300        "bynk.consumes.type_alias_unknown_export",
7301        "`consumes U { T as Alias }` names a type `U` does not export.",
7302        &["consumes_decl"],
7303    ),
7304    dg(
7305        "bynk.consumes.type_not_selected",
7306        "A type (or a bare variant of a sum) of a consumed unit is named in a file whose own `consumes` does not bring it in: it lists other names, or only another file of the unit consumes the unit.",
7307        &["consumes_decl"],
7308    ),
7309    dg(
7310        "bynk.consumes.unit_not_consumed",
7311        "A call to another unit's service is written in a file whose own `consumes` does not name that unit.",
7312        &["consumes_decl"],
7313    ),
7314    dg(
7315        "bynk.consumes.unknown_context",
7316        "`consumes` names a context that does not exist.",
7317        &["consumes_decl"],
7318    ),
7319    dg(
7320        "bynk.consumes.unknown_service",
7321        "Called a service the consumed context does not declare.",
7322        &["consumes_decl"],
7323    ),
7324    d(
7325        "bynk.container.build_missing",
7326        "A `Container`'s `@build` directory holds no `Dockerfile`, so there is no image to build.",
7327    ),
7328    d(
7329        "bynk.container.build_path",
7330        "A `Container`'s `@build` is not a directory inside the project: it is empty, absolute, uses `\\`, or leaves the project with `..`.",
7331    ),
7332    d(
7333        "bynk.container.output_outside_project",
7334        "A build with a `Container` is written to an output directory outside the project, so `wrangler` cannot reach the container's Dockerfile from the Worker's output directory by a relative path inside the project.",
7335    ),
7336    d(
7337        "bynk.context.consumes_cycle",
7338        "Contexts form a `consumes` dependency cycle.",
7339    ),
7340    d(
7341        "bynk.context.duplicate_binding",
7342        "A Worker would declare two bindings with the same name, such as an agent `Kv` and the `bynk.cloudflare` KV namespace (both `KV`).",
7343    ),
7344    d(
7345        "bynk.context.external_construction",
7346        "A context-owned type was constructed from outside that context.",
7347    ),
7348    d(
7349        "bynk.context.external_decode",
7350        "A context decoded a type another context owns and exports opaque: through `Json.decode`, `Json.decodeSql` or a `Codable` witness, or as the input of an HTTP, queue, event or WebSocket handler. Decoding creates a value, which only the owning context may do; its codec would check no more than the base type.",
7351    ),
7352    dg(
7353        "bynk.context.external_provider",
7354        "A bodiless (external) provider was declared outside an `adapter`.",
7355        &["provider_decl"],
7356    ),
7357    d(
7358        "bynk.context.opaque_inspection",
7359        "An opaquely-exported type was inspected from outside its context.",
7360    ),
7361    d(
7362        "bynk.context.rebrand_construction",
7363        "A variant of a `uses`-sourced commons sum type was constructed directly inside a context, where the emitter's per-context rebrand leaves its constructors out of scope.",
7364    ),
7365    d(
7366        "bynk.contract.duplicate_name",
7367        "A function declares two contract clauses (`requires`/`ensures`) with the same name.",
7368    ),
7369    d(
7370        "bynk.contract.impure_predicate",
7371        "A contract predicate uses an effectful or test-only construct; a contract clause must be pure.",
7372    ),
7373    d(
7374        "bynk.contract.not_bool",
7375        "A contract predicate does not have type `Bool`.",
7376    ),
7377    d(
7378        "bynk.contract.restated_by_test",
7379        "A `case`/`property` merely restates a contract clause already declared at the function; the test is redundant.",
7380    ),
7381    d(
7382        "bynk.contract.result_in_requires",
7383        "A precondition (`requires`) references `result`; the return value is only in scope inside an `ensures`.",
7384    ),
7385    dg(
7386        "bynk.cron.bad_params",
7387        "A cron handler declares more than one parameter, or a non-`Instant` one.",
7388        &["cron_handler"],
7389    ),
7390    dg(
7391        "bynk.cron.duplicate_schedule",
7392        "Two cron handlers declare the same schedule.",
7393        &["cron_handler"],
7394    ),
7395    dg(
7396        "bynk.cron.invalid_schedule",
7397        "A cron schedule is not valid Cloudflare cron syntax: a field is out of range or malformed, or the fields are not separated by exactly one space.",
7398        &["cron_handler"],
7399    ),
7400    warn(dg(
7401        "bynk.cron.numeric_weekday",
7402        "A cron schedule names a day of the week by number, where Cloudflare's `1` is Sunday, not standard cron's `0`/`7` (warning).",
7403        &["cron_handler"],
7404    )),
7405    dg(
7406        "bynk.cron.return_not_effect_result",
7407        "A cron handler does not return `Effect[Result[(), E]]`.",
7408        &["cron_handler"],
7409    ),
7410    warn(dg(
7411        "bynk.cron.uneven_step",
7412        "A cron schedule's `*/n` step in the minute or hour field does not divide the field's range, so the last gap is shorter than `n` (warning).",
7413        &["cron_handler"],
7414    )),
7415    warn(d(
7416        "bynk.d1.migration_invalid",
7417        "A `D1` migration does not apply to an empty in-memory SQLite, so the binding's literal SQL is not checked against its schema (warning).",
7418    )),
7419    d(
7420        "bynk.d1.migration_name",
7421        "A file in the project's `migrations/` folder isn't `migrations/<database>/NNNN_<name>.sql`, or shares its number with another migration of the same database.",
7422    ),
7423    d(
7424        "bynk.d1.migration_unreadable",
7425        "A `D1` migration in the project's `migrations/` folder can't be read, or isn't UTF-8 text.",
7426    ),
7427    warn(d(
7428        "bynk.d1.migrations_unused",
7429        "A directory in the project's `migrations/` folder matches no `D1` instance's database name, so its migrations are never applied, usually because the capability was renamed (warning).",
7430    )),
7431    d(
7432        "bynk.d1.select_field_missing",
7433        "A record read from a literal D1 statement has a field with no column of that name. For a `select[T]` / `firstAs[T]` row type, the column list the compiler writes from `T` does not prepare against the schema the binding's migrations build; for a `Json.decodeSql[T]` of the rows of a literal `all` / `first`, a required (non-`Option`) field of `T` has no result column.",
7434    ),
7435    d(
7436        "bynk.d1.sql_invalid",
7437        "A literal D1 statement does not prepare against the schema the binding's migrations build: a syntax error, or an unknown table or column.",
7438    ),
7439    d(
7440        "bynk.d1.sql_param_count",
7441        "A literal D1 statement uses a different number of bound parameters (`?N`) than the list literal passed with it holds.",
7442    ),
7443    d(
7444        "bynk.dependency.path_outside_root",
7445        "A path dependency declared by a dependency resolves outside the workspace; a dependency's own path dependencies are honoured only between members of one workspace.",
7446    ),
7447    d(
7448        "bynk.deploy.agent_move_refused",
7449        "`bynk deploy` refused to put a context that hosts agents on a different Worker script than it was last deployed to (into or out of a `[deploy.workers.<key>]` group, between groups, or after a group is renamed or re-keyed): an agent's state belongs to its script, so it would start empty and the old data would stay behind. Start it fresh deliberately with `--accept-fresh-agent <context>`, which a move out of a group that stays cannot use.",
7450    ),
7451    d(
7452        "bynk.deploy.asset_path_conflict",
7453        "Two members of one `[deploy.workers.<key>]` group serve a fixed asset path (`at \"/…\"`) from different files, or one that would be a folder of the other; a group has one assets directory, so each fixed path names one file.",
7454    ),
7455    d(
7456        "bynk.deploy.binding_collision",
7457        "Two members of one `[deploy.workers.<key>]` group declare different bindings under the same name; members share one `wrangler.toml`, so identical declarations share a binding and differing ones are refused.",
7458    ),
7459    d(
7460        "bynk.deploy.context_in_two_groups",
7461        "A context is listed in two `[deploy.workers.<key>]` groups; a context is deployed in one Worker only.",
7462    ),
7463    d(
7464        "bynk.deploy.contract_skew",
7465        "A worker was compiled against a contract its live dependencies no longer provide, or no longer provides the contract its live callers were compiled against, so `bynk deploy --context` refuses to ship it.",
7466    ),
7467    d(
7468        "bynk.deploy.duplicate_hostname",
7469        "A route or custom domain is claimed twice across `[deploy.workers.<key>]` groups.",
7470    ),
7471    d(
7472        "bynk.deploy.empty_group",
7473        "A `[deploy.workers.<key>]` group lists no context.",
7474    ),
7475    d(
7476        "bynk.deploy.foreign_contract_skew",
7477        "A build breaks the contract a declared foreign caller's client was generated at, as pinned in `bynk.foreign.toml`, so `bynk deploy` refuses to ship it.",
7478    ),
7479    d(
7480        "bynk.deploy.group_name_conflict",
7481        "A `[deploy.workers.<key>]` group's key or script name is another group's, or is the Worker of a context in no group.",
7482    ),
7483    d(
7484        "bynk.deploy.multiple_websocket_members",
7485        "More than one member of a `[deploy.workers.<key>]` group declares a `from websocket` service; an upgrade request names no path or service a group could route it by, so a group has at most one such member, which takes every upgrade request whatever the path.",
7486    ),
7487    d(
7488        "bynk.deploy.not_a_context",
7489        "A `[deploy.workers.<key>]` group lists a unit that is not a `context`; only contexts are deployed as Workers.",
7490    ),
7491    d(
7492        "bynk.deploy.route_conflict",
7493        "Two members of one `[deploy.workers.<key>]` group declare the same HTTP method and path; a Worker answers a route with one handler.",
7494    ),
7495    d(
7496        "bynk.deploy.service_name_conflict",
7497        "Two members of one `[deploy.workers.<key>]` group declare a service of the same name; a Worker answers its members' services by name.",
7498    ),
7499    d(
7500        "bynk.deploy.unknown_context",
7501        "A `[deploy.workers.<key>]` group lists a context the project does not declare.",
7502    ),
7503    d(
7504        "bynk.deploy.worker_cycle",
7505        "Workers bind to each other in a cycle that involves a `[deploy.workers.<key>]` group: a group folds its members into one Worker, which can close a cycle among contexts that are themselves acyclic. A Worker is uploaded after the Workers it binds to, so the cycle cannot be deployed.",
7506    ),
7507    warn(d(
7508        "bynk.deploy.workers_ignored_on_bundle",
7509        "`bynk.toml` declares `[deploy.workers]` groups, which only a `workers` build uses; this build is a `bundle`, which has every context in one program and ignores them (warning).",
7510    )),
7511    dg(
7512        "bynk.detach.in_agent_handler",
7513        "A `detach` was used in an agent handler, which has no execution context to keep a detached effect alive.",
7514        &["method_call"],
7515    ),
7516    dg(
7517        "bynk.detach.in_pure_context",
7518        "A `detach` was used in a pure (non-effectful) context.",
7519        &["method_call"],
7520    ),
7521    dg(
7522        "bynk.detach.store_op",
7523        "A `detach` targets an agent store operation, which is part of the handler's atomic commit and cannot be detached.",
7524        &["method_call"],
7525    ),
7526    // LSP-only (#2459): published by `bynk-lsp` as a hint (or warning, per the
7527    // `bynk.docLinks.reportUnresolved` setting); the compiler never emits it.
7528    warn(d(
7529        "bynk.doc.unresolved_link",
7530        "A `[Name]` doc link resolves to nothing in the unit's scope (editor hint only).",
7531    )),
7532    d(
7533        "bynk.duration.literal_overflow",
7534        "A `Duration` literal (`<int>.<unit>`) exceeds the representable millisecond range.",
7535    ),
7536    d(
7537        "bynk.duration.unit_agreement",
7538        "A `Duration` literal's unit does not agree with its number: `1` takes the singular unit, every other number the plural.",
7539    ),
7540    d(
7541        "bynk.duration.unknown_unit",
7542        "An integer literal is followed by a word that is not a `Duration` unit.",
7543    ),
7544    dg(
7545        "bynk.effect.bind_in_pure_context",
7546        "An `<-` bind was used in a pure (non-effectful) context.",
7547        &["effect_let_stmt"],
7548    ),
7549    dg(
7550        "bynk.effect.bind_on_non_effect",
7551        "An `<-` bind was applied to a non-`Effect` value.",
7552        &["effect_let_stmt"],
7553    ),
7554    d(
7555        "bynk.effect.capability_in_pure_context",
7556        "A capability was used in a pure context.",
7557    ),
7558    d(
7559        "bynk.effect.cross_context_in_pure_context",
7560        "A cross-context call was made in a pure context.",
7561    ),
7562    dg(
7563        "bynk.effect.do_discards_result",
7564        "A `do` statement was applied to an `Effect[Result[_, _]]`, which would drop an `Err`; bind it, write `let _ <- e` to discard it deliberately, or `do e.detach()` to stop waiting and have a failure reported.",
7565        &["do_stmt"],
7566    ),
7567    dg(
7568        "bynk.effect.do_in_pure_context",
7569        "A `do` statement was used in a pure (non-effectful) context.",
7570        &["do_stmt"],
7571    ),
7572    dg(
7573        "bynk.effect.do_on_non_effect",
7574        "A `do` statement was applied to a non-`Effect` value.",
7575        &["do_stmt"],
7576    ),
7577    dg(
7578        "bynk.effect.fn_value_in_pure_context",
7579        "An effectful function value was called in a pure context; like a capability call, it is legal only where the enclosing body is effectful.",
7580        &["call"],
7581    ),
7582    d(
7583        "bynk.effect.unbound_effect",
7584        "An `Effect` value in an effectful body was built but not bound with `<-`, sequenced with `do` or returned — in a plain `let`, a list element or a constructor payload — so it runs eagerly and unawaited (#1658).",
7585    ),
7586    d(
7587        "bynk.email.bad_params",
7588        "An email `on message` handler does not take exactly one `InboundEmail` parameter.",
7589    ),
7590    d(
7591        "bynk.email.duplicate_address",
7592        "Two `from email` services claim the same recipient address.",
7593    ),
7594    d(
7595        "bynk.email.duplicate_handler",
7596        "A `from email` service declares more than one `on message` handler; it has exactly one.",
7597    ),
7598    d(
7599        "bynk.email.invalid_address",
7600        "A `from email(\"…\")` binding is not a recipient address a service can claim.",
7601    ),
7602    d(
7603        "bynk.email.return_not_email_verdict",
7604        "An email `on message` handler does not return `Effect[EmailVerdict]`.",
7605    ),
7606    d(
7607        "bynk.embed.binary_content",
7608        "An `embed` names a file with a NUL byte, so it is binary, not text.",
7609    ),
7610    d(
7611        "bynk.embed.duplicate",
7612        "An `embed` name is declared more than once in the same unit.",
7613    ),
7614    d(
7615        "bynk.embed.invalid_encoding",
7616        "An `embed` names a file that is not valid UTF-8.",
7617    ),
7618    d(
7619        "bynk.embed.missing_file",
7620        "An `embed` names a file that is not in the project's `embeds/` folder.",
7621    ),
7622    d(
7623        "bynk.embed.needs_project",
7624        "A single-file build met an `embed` declaration, which needs a project's `embeds/` folder.",
7625    ),
7626    d(
7627        "bynk.embed.outside_context_or_commons",
7628        "An `embed` declaration appears outside a context or commons.",
7629    ),
7630    d(
7631        "bynk.embed.outside_embeds_dir",
7632        "An `embed` names a file outside the project's `embeds/` folder.",
7633    ),
7634    d(
7635        "bynk.embed.too_large",
7636        "An `embed` names a file over 256 KiB, or the project's embedded files total over 1 MiB.",
7637    ),
7638    d(
7639        "bynk.embed.unreadable_file",
7640        "An `embed` names a file in the project's `embeds/` folder that could not be read.",
7641    ),
7642    d(
7643        "bynk.embed.unsafe_path",
7644        "An `embed` path is empty, absolute, or contains a `..` segment.",
7645    ),
7646    d(
7647        "bynk.event.bad_params",
7648        "An `on event` handler declared the wrong number of parameters, or a second parameter whose type is not `EventEnvelope` — it takes the event payload and, optionally, the runtime envelope.",
7649    ),
7650    d(
7651        "bynk.event.bad_schema_dispatch",
7652        "A `via schema(...)` dispatch clause's argument is malformed — it must be a positive `Int` literal, a range of positive `Int` literals, or `_`.",
7653    ),
7654    d(
7655        "bynk.event.bad_schema_version",
7656        "An event's `@schema(N)` annotation is malformed — `N` must be a single, positive, positional `Int` literal, and `@schema` may appear at most once on an event.",
7657    ),
7658    dg(
7659        "bynk.event.duplicate_handler",
7660        "A `from Events` service declares more than one `on event` handler; it has exactly one.",
7661        &["event_handler"],
7662    ),
7663    d(
7664        "bynk.event.emit_not_an_event",
7665        "`Events.emit[E]` named a type `E` that is declared in this context, but is not itself an `event` — only an `event` type may be emitted.",
7666    ),
7667    d(
7668        "bynk.event.emit_outside_owner",
7669        "`Events.emit[E]` named an event `E` not declared in the emitting context — only an event's declaring context may emit it.",
7670    ),
7671    d(
7672        "bynk.event.handler_param_type_mismatch",
7673        "An `on event(e: T)` handler's declared parameter type does not match its `from Events(E)` header's event type.",
7674    ),
7675    d(
7676        "bynk.event.non_additive_schema_change",
7677        "An event's field shape changed in a way the schema registry cannot evolve additively — a field was removed, retyped, added without a default, or lost a default it previously had. Give the new shape a new event type name, or make the change additive.",
7678    ),
7679    d(
7680        "bynk.event.outside_context",
7681        "An `event` was declared outside a context.",
7682    ),
7683    d(
7684        "bynk.event.pattern_duplicate_field",
7685        "A `from Events(E { ... })` subscription pattern listed the same field more than once.",
7686    ),
7687    d(
7688        "bynk.event.pattern_type_mismatch",
7689        "A `from Events(E { ... })` subscription pattern field's matched value is not compatible with that field's declared type.",
7690    ),
7691    d(
7692        "bynk.event.pattern_unknown_field",
7693        "A `from Events(E { ... })` subscription pattern named a field that `E` does not declare.",
7694    ),
7695    d(
7696        "bynk.event.pattern_unknown_variant",
7697        "A `from Events(E { ... })` subscription pattern's variant value names a variant that does not exist on the field's declared sum type.",
7698    ),
7699    d(
7700        "bynk.event.pattern_variant_payload",
7701        "A `from Events(E { ... })` subscription pattern's variant value names a variant that carries a payload — only nullary variants are admitted, since testing the tag alone would silently ignore the payload.",
7702    ),
7703    dg(
7704        "bynk.event.return_not_effect_unit",
7705        "An `on event` handler returns an `Effect` of something other than `()`; emission is fire-and-forget, so it returns `Effect[()]`.",
7706        &["event_handler"],
7707    ),
7708    d(
7709        "bynk.event.schema_version_mismatch",
7710        "An event's `@schema(N)` annotation disagrees with the version the schema registry computes from the event's build history.",
7711    ),
7712    d(
7713        "bynk.event.unknown_annotation",
7714        "An `event` declaration carried an `@`-annotation other than `@schema` — event annotations are a closed set.",
7715    ),
7716    d(
7717        "bynk.event.unknown_subscription",
7718        "A `from Events(E)` subscription named `E`, which is not a declared event in this context or any consumed context.",
7719    ),
7720    d(
7721        "bynk.exec.unavailable",
7722        "A call to, or reference to, a function that hands work to the execution context (`detach`, `within` or `race`, directly or through the functions it calls) appears where no execution context exists: an agent handler, a WebSocket handler or a provider operation.",
7723    ),
7724    dg(
7725        "bynk.expect.faults_not_effect",
7726        "A fault claim's subject (`expect <call> faults`) is not an effectful call: a value, or a call whose type is not `Effect[_]`.",
7727        &["faults_expr"],
7728    ),
7729    dg(
7730        "bynk.expect.impure_predicate",
7731        "An `expect` predicate contains an effectful call (a sub-expression of type `Effect[_]`); a predicate must be pure.",
7732        &["expect_expr"],
7733    ),
7734    dg(
7735        "bynk.expect.not_bool",
7736        "`expect` was given a non-`Bool` predicate.",
7737        &["expect_expr"],
7738    ),
7739    dg(
7740        "bynk.expect.outside_case",
7741        "`expect` was used outside a `case` body.",
7742        &["expect_expr"],
7743    ),
7744    dg(
7745        "bynk.exports.capability_not_provided",
7746        "An exported capability has no provider in its context.",
7747        &["exports_decl"],
7748    ),
7749    dg(
7750        "bynk.exports.conflicting_visibility",
7751        "A type is exported with conflicting visibilities.",
7752        &["exports_decl"],
7753    ),
7754    dg(
7755        "bynk.exports.derived_capability",
7756        "`exports capability` names a derived capability, whose instance stays with its context.",
7757        &["exports_decl"],
7758    ),
7759    dg(
7760        "bynk.exports.duplicate_export",
7761        "The same name is exported more than once.",
7762        &["exports_decl"],
7763    ),
7764    dg(
7765        "bynk.exports.duplicate_in_clause",
7766        "A name appears twice in one `exports` clause.",
7767        &["exports_decl"],
7768    ),
7769    dg(
7770        "bynk.exports.undeclared_capability",
7771        "`exports capability` names a capability that is not declared.",
7772        &["exports_decl"],
7773    ),
7774    dg(
7775        "bynk.exports.undeclared_type",
7776        "`exports` names a type that is not declared.",
7777        &["exports_decl"],
7778    ),
7779    warn(d(
7780        "bynk.fault.todo",
7781        "A `todo(message)` placeholder: the code type-checks but faults when it runs. A non-failing warning, so `check --deny-warnings` refuses unfinished code in CI (warning).",
7782    )),
7783    dg(
7784        "bynk.fixture.binary_content",
7785        "A suite's `fixture` names a file that contains a NUL byte, so it is binary, not text.",
7786        &["fixture_decl"],
7787    ),
7788    dg(
7789        "bynk.fixture.duplicate",
7790        "A suite declares two `fixture`s of the same name.",
7791        &["fixture_decl"],
7792    ),
7793    dg(
7794        "bynk.fixture.invalid_encoding",
7795        "A suite's `fixture` names a file that is not valid UTF-8.",
7796        &["fixture_decl"],
7797    ),
7798    dg(
7799        "bynk.fixture.missing_file",
7800        "A suite's `fixture` names a file that is not in the project's `fixtures/` folder.",
7801        &["fixture_decl"],
7802    ),
7803    dg(
7804        "bynk.fixture.outside_fixtures_dir",
7805        "A suite's `fixture` names a file outside the project's `fixtures/` folder.",
7806        &["fixture_decl"],
7807    ),
7808    dg(
7809        "bynk.fixture.too_large",
7810        "A suite's `fixture` names a file over the 4 MiB limit for one fixture file.",
7811        &["fixture_decl"],
7812    ),
7813    dg(
7814        "bynk.fixture.unreadable_file",
7815        "A suite's `fixture` names a listed file that could not be read.",
7816        &["fixture_decl"],
7817    ),
7818    dg(
7819        "bynk.fixture.unsafe_path",
7820        "A suite's `fixture` path is empty, absolute or contains a `..` segment.",
7821        &["fixture_decl"],
7822    ),
7823    warn(dg(
7824        "bynk.fixture.unused",
7825        "A suite declares a `fixture` that none of its cases, properties or helpers uses (warning).",
7826        &["fixture_decl"],
7827    )),
7828    d(
7829        "bynk.fmt.comment_loss",
7830        "The formatter would drop a comment, so it leaves the file unchanged.",
7831    ),
7832    d(
7833        "bynk.fmt.mixed_comment_syntax",
7834        "A file mixes the retired `--` comment or `--|` doc spellings with a line that reads differently under the old and new comment rules (#2203), so the formatter leaves it unchanged.",
7835    ),
7836    d(
7837        "bynk.fmt.roundtrip",
7838        "The formatter's output does not re-parse to the same program, so it leaves the file unchanged.",
7839    ),
7840    dg(
7841        "bynk.generics.ambiguous_instantiation",
7842        "A generic function with an `Ord` bound is used as a value, and its type arguments cannot be determined from the type expected at that reference; annotate the expected type (constrained-generics slice 1).",
7843        &["fn_decl"],
7844    ),
7845    dg(
7846        "bynk.generics.bound_on_capability_op",
7847        "A generic capability operation's type parameter carries a bound other than `Key` or `Codable`; operations take only those two (constrained-generics slices 2 and 3).",
7848        &["capability_op"],
7849    ),
7850    dg(
7851        "bynk.generics.codable_op_return_not_first_party",
7852        "A user-declared capability operation's `Codable` type parameter appears in its return type. A typed read, the call site decoding the provider's reply as the instantiated payload, is accepted only for the standard library's own operations (#3458, lifting ADR 0696 decision 5).",
7853        &["capability_op"],
7854    ),
7855    dg(
7856        "bynk.generics.duplicate_type_param",
7857        "A `type` or `fn` declares the same type-parameter name more than once (v0.157, ADR 0183).",
7858        &[],
7859    ),
7860    dg(
7861        "bynk.generics.generic_non_record",
7862        "A `type` declaration carries type parameters on a refined, opaque or alias body; only a record (`type Name[T] = { … }`) or sum (`type Name[T] = | … | …`) body may be generic (v0.157/#593, ADRs 0183/0197).",
7863        &["type_decl"],
7864    ),
7865    dg(
7866        "bynk.generics.generic_sum_embeds",
7867        "A generic sum type carries an `embeds` clause; embedding into a generic sum is not supported (#593).",
7868        &["type_decl"],
7869    ),
7870    dg(
7871        "bynk.generics.internal_op_annotation",
7872        "A capability operation carries an annotation outside the standard library, or a first-party operation's is not `@onUndecodable(miss)` or `@onUndecodable(fault)`: the reply policy of a typed read is internal to first-party operations (#3458).",
7873        &["capability_op"],
7874    ),
7875    dg(
7876        "bynk.generics.method_on_generic_type",
7877        "A *static* method on a generic type never mentions one of the type's parameters in its parameter or return types, so no call could determine it from the arguments or the expected type. Mention the parameter in the signature, or make the method a free function (constrained-generics slice 4; instance methods are supported, #594).",
7878        &["fn_decl"],
7879    ),
7880    dg(
7881        "bynk.generics.missing_codable_bound",
7882        "A type parameter is encoded or decoded with `Json.encode`/`Json.decode`, or passed to a `Codable`-bounded parameter of another generic or of a capability operation, but is not declared `Codable` (`[T: Codable]`, or `where A: Codable` for a receiver type\'s parameter). The diagnostic carries a machine-applicable fix that declares `Codable`, beside an existing `Eq`, which `Codable` does not imply (constrained-generics slice 3).",
7883        &["fn_decl"],
7884    ),
7885    dg(
7886        "bynk.generics.missing_eq_bound",
7887        "A type parameter is compared with `==`/`!=`, or passed to an `Eq`-bounded parameter of another generic, but is not declared `Eq` (`[T: Eq]`, or `where A: Eq` for a receiver type's parameter). The diagnostic carries a machine-applicable fix (ADR 0430, amended by constrained-generics slice 0).",
7888        &["fn_decl"],
7889    ),
7890    dg(
7891        "bynk.generics.missing_key_bound",
7892        "A type parameter keys a `Map` or `Set` (a `Map` key, a `Set` element, a `distinct`/`groupBy`/join key), or is passed to a `Key`-bounded parameter of another generic, but is not declared `Key` (`[K: Key]`, or `where A: Key` for a receiver type's parameter; on the type for a generic type's own parameter). The diagnostic carries a machine-applicable fix that declares `Key`, replacing an existing `Eq`, which `Key` implies (constrained-generics slice 2).",
7893        &["fn_decl"],
7894    ),
7895    dg(
7896        "bynk.generics.missing_ord_bound",
7897        "A type parameter is ordered (`<`, `<=`, `>`, `>=`, an ordering kernel key), or passed to an `Ord`-bounded parameter of another generic, but is not declared `Ord` (`[T: Ord]`, or `where A: Ord` for a receiver type's parameter). The diagnostic carries a machine-applicable fix that declares `Ord`, replacing an existing `Eq`, which `Ord` implies (constrained-generics slice 1).",
7898        &["fn_decl"],
7899    ),
7900    dg(
7901        "bynk.generics.polymorphic_recursion",
7902        "A generic type refers to itself with arguments other than its own type parameters, in order (`Weird[List[T]]` inside `Weird[T]`, or `Pair[B, A]` inside `Pair[A, B]`), or to a mutually recursive partner with an argument that wraps one of its own parameters (`Inner[List[T]]` inside `Outer[T]`). Such polymorphic recursion generates an unbounded set of instantiations and is refused at the declaration; a self-reference that passes the parameters through unchanged, and a partner applied to the declaration's own parameters or to types that mention none (of any arity), are accepted (#3192).",
7903        &[],
7904    ),
7905    dg(
7906        "bynk.generics.recursive_generic_at_boundary",
7907        "A recursive generic type (a record or sum that transitively contains itself, through any wrapper or generic argument) is used where a codec is required: a service or agent handler signature, an agent store field or key, an event field, an actor identity type, a `Json.encode`/`decode` target or a `Codable` witness. It declares and works inside a context, but has no codec yet, so it cannot cross a boundary; when it is reached through another type, the note names the field path (#3192, ADR 0197).",
7908        &[],
7909    ),
7910    warn(dg(
7911        "bynk.generics.redundant_eq_bound",
7912        "A type parameter is declared both `Eq` and `Ord` (or `Eq` and `Key`); `Ord` and `Key` imply `Eq`, so the `Eq` is redundant. The diagnostic carries a machine-applicable fix that removes it (constrained-generics slices 1 and 2, warning).",
7913        &["fn_decl"],
7914    )),
7915    dg(
7916        "bynk.generics.type_arg_count",
7917        "A user-declared generic type is applied to the wrong number of type arguments, or a generic type is named without its `[…]` arguments (v0.157, ADR 0183).",
7918        &["applied_type_ref"],
7919    ),
7920    dg(
7921        "bynk.generics.type_arg_mismatch",
7922        "Inferred or explicit type arguments conflict, have the wrong arity, target a non-generic function, or a type parameter shadows a declared type.",
7923        &["call"],
7924    ),
7925    dg(
7926        "bynk.generics.uninferable_type_arg",
7927        "A generic function's type parameter could not be inferred from the arguments and was not given explicitly (`name[T](…)`); a bare generic function also cannot be passed as a value.",
7928        &["call"],
7929    ),
7930    dg(
7931        "bynk.generics.unknown_constraint",
7932        "A bound, or a `derives` entry, names something that is not a constraint; the constraints are `Eq`, `Ord`, `Key` and `Codable`.",
7933        &["type_param"],
7934    ),
7935    dg(
7936        "bynk.generics.unknown_where_param",
7937        "A method's `where` clause bounds a name that is not a type parameter of the method or of its receiver type.",
7938        &["where_clause"],
7939    ),
7940    dg(
7941        "bynk.given.cross_context_unknown_capability",
7942        "`given B.Cap` or `consumes B { Cap }` names a capability the consumed context does not export.",
7943        &["given_clause"],
7944    ),
7945    dg(
7946        "bynk.given.fn_outside_context",
7947        "A function in a commons (or a suite) declares `given`; only a context function can.",
7948        &["given_clause"],
7949    ),
7950    dg(
7951        "bynk.given.fn_unsupported",
7952        "A `given` clause on a method, on a function that does not return `Effect[T]`, or naming `Events`.",
7953        &["given_clause"],
7954    ),
7955    dg(
7956        "bynk.given.missing_for_call",
7957        "A call to a function that declares `given` from a body that does not declare those capabilities.",
7958        &["given_clause"],
7959    ),
7960    dg(
7961        "bynk.given.undeclared_capability",
7962        "A handler uses a capability it did not declare with `given`.",
7963        &["given_clause"],
7964    ),
7965    dg(
7966        "bynk.given.unknown_capability",
7967        "`given` names a capability that does not exist.",
7968        &["given_clause"],
7969    ),
7970    warn(dg(
7971        "bynk.given.unused_capability",
7972        "A `given` capability is never used (warning).",
7973        &["given_clause"],
7974    )),
7975    d(
7976        "bynk.held.branch_divergence",
7977        "Branches of a conditional leave a held value (e.g. `Connection[F]`) in inconsistent ownership states — one consumes or stores it, another leaves it owned (§2.9.5, real-time track slice 2).",
7978    ),
7979    d(
7980        "bynk.held.consume_on_borrow",
7981        "A consuming operation (`close`/`put`/`take`) is called on a *borrowed* held reference — borrows admit only non-consuming operations like `send` (§2.9.3, real-time track slice 2).",
7982    ),
7983    d(
7984        "bynk.held.leak",
7985        "A held value (`Connection[F]`) is still owned at scope exit — it must be disposed (stored, closed, or transferred) before the handler or function returns (§2.9.1, real-time track slice 2).",
7986    ),
7987    d(
7988        "bynk.held.query_accessor_on_held_map",
7989        "A key-aware query accessor (`.entries`/`.keys`/`.values`) is used on a held `Map[K, Connection]` — a held resource is iterated with the broadcast ops (`forEach`/`parTraverse`), not a key query.",
7990    ),
7991    d(
7992        "bynk.held.unsupported_map_op",
7993        "A held `Map[K, Connection]` is given an `update`/`upsert` — a held resource cannot be transformed by a `(Connection) -> Connection` function; use `put`/`get`/`remove` (real-time track slice 3b-ii).",
7994    ),
7995    d(
7996        "bynk.held.unsupported_storage",
7997        "A held value (`Connection[F]`) is stored in a `Set`/`Log`/`Cache` — held values may only live in `Cell[Option[Connection]]` or `Map[K, Connection]` (§2.9.3, real-time track slice 2).",
7998    ),
7999    d(
8000        "bynk.held.use_after_consume",
8001        "A held value (`Connection[F]`) is used after a consuming operation (`close`/`put`/`take`) ended its lifetime (§2.9.2, real-time track slice 2).",
8002    ),
8003    d(
8004        "bynk.history.not_an_agent",
8005        "A `for all run: History[T]` names a `T` that is not an agent — only an agent has handlers to sequence and reachable states to observe (testing track slice 7, ADR 0155).",
8006    ),
8007    d(
8008        "bynk.history.not_generable",
8009        "A `for all run: History[Agent]` targets an agent with a handler parameter whose type cannot be generated (e.g. a `Matches` refinement), so its call-history cannot be driven (testing track slice 7, ADR 0155).",
8010    ),
8011    d(
8012        "bynk.history.outside_property",
8013        "`History[Agent]` appears outside a `property`'s `for all` binding — it is a test-only generator, not a value type (testing track slice 7, ADR 0155).",
8014    ),
8015    d(
8016        "bynk.history.restates_invariant",
8017        "A history property merely re-checks a guarantee a declared `invariant`/`transition` already enforces on every reached state (testing track slice 7, ADR 0155).",
8018    ),
8019    d(
8020        "bynk.http.body_kind_conflict",
8021        "A handler carries both `@raw` and `@form`, which each fix the wire format of its one `body`.",
8022    ),
8023    dg(
8024        "bynk.http.body_on_get_or_delete",
8025        "A GET or DELETE handler declares a `body` parameter.",
8026        &["http_handler"],
8027    ),
8028    d(
8029        "bynk.http.cache_bad_immutable",
8030        "A `@cache` annotation's `immutable` is not a `Bool` literal.",
8031    ),
8032    d(
8033        "bynk.http.cache_bad_max_age",
8034        "A `@cache` annotation's `maxAge` is missing or not a positive `Duration` literal.",
8035    ),
8036    d(
8037        "bynk.http.cache_bad_scope",
8038        "A `@cache` annotation's `scope` is not `public` or `private`.",
8039    ),
8040    d(
8041        "bynk.http.cache_duplicate",
8042        "A handler carries more than one `@cache` annotation.",
8043    ),
8044    d(
8045        "bynk.http.cache_max_age_fractional_seconds",
8046        "A `@cache` annotation's `maxAge` is positive but does not resolve to a whole number of seconds.",
8047    ),
8048    d(
8049        "bynk.http.cache_on_non_get",
8050        "A `@cache` annotation is placed on a handler that is not `on http GET`.",
8051    ),
8052    dg(
8053        "bynk.http.cache_public_reads_cookies",
8054        "A `@cache(scope: public)` handler takes a `cookies` parameter, so a shared cache could replay one user's response to another.",
8055        &["http_handler"],
8056    ),
8057    d(
8058        "bynk.http.cache_unknown_arg",
8059        "A `@cache` annotation has an argument outside the closed set (`maxAge`/`scope`/`immutable`).",
8060    ),
8061    dg(
8062        "bynk.http.cf_wrong_type",
8063        "An HTTP handler's `cf` parameter is not typed `RequestCf`.",
8064        &["http_handler"],
8065    ),
8066    warn(dg(
8067        "bynk.http.cookie_cross_site_without_credentials",
8068        "A service attaches a `SameSite.Unrestricted` cookie but declares no `cors { credentials: true }`, so a cross-origin `fetch` can never send it back (warning).",
8069        &["http_handler"],
8070    )),
8071    warn(dg(
8072        "bynk.http.cookie_domain_widens",
8073        "A cookie literal outside the `__Host-` prefix sets a `domain`, so every subdomain receives it (warning).",
8074        &["http_handler"],
8075    )),
8076    dg(
8077        "bynk.http.cookie_field_arity",
8078        "A typed cookie write or deletion (`Record.field.cookie(v)`, `Record.field.expire()`) is given the wrong number of arguments.",
8079        &["http_handler"],
8080    ),
8081    dg(
8082        "bynk.http.cookie_field_list",
8083        "A typed cookie write names a `List` field of the cookie record.",
8084        &["http_handler"],
8085    ),
8086    dg(
8087        "bynk.http.cookie_field_not_cookie_record",
8088        "A typed cookie write names a record that is not the `cookies` record of an `on http` handler in this unit.",
8089        &["http_handler"],
8090    ),
8091    dg(
8092        "bynk.http.cookie_field_unknown",
8093        "A typed cookie write names a field the cookie record does not have.",
8094        &["http_handler"],
8095    ),
8096    dg(
8097        "bynk.http.cookie_host_prefix",
8098        "A `__Host-` cookie literal is not `secure`, sets a `domain`, or uses a `path` other than `/`.",
8099        &["http_handler"],
8100    ),
8101    dg(
8102        "bynk.http.cookie_partitioned_insecure",
8103        "A `partitioned` cookie literal is not `secure`.",
8104        &["http_handler"],
8105    ),
8106    dg(
8107        "bynk.http.cookie_samesite_none_insecure",
8108        "A cookie literal with `sameSite: SameSite.Unrestricted` is not `secure`.",
8109        &["http_handler"],
8110    ),
8111    warn(dg(
8112        "bynk.http.cookie_script_readable",
8113        "A cookie literal sets `httpOnly: false`, so page scripts can read it (warning).",
8114        &["http_handler"],
8115    )),
8116    dg(
8117        "bynk.http.cookie_secure_prefix",
8118        "A `__Secure-` cookie literal is not `secure`.",
8119        &["http_handler"],
8120    ),
8121    warn(dg(
8122        "bynk.http.cookie_untyped_has_field",
8123        "An untyped `Cookie` literal is named like a field of a cookie record of the unit (a warning).",
8124        &["http_handler"],
8125    )),
8126    dg(
8127        "bynk.http.cookie_value_undecodable",
8128        "An untyped `Cookie` literal's value is one the record field that reads that cookie would reject.",
8129        &["http_handler"],
8130    ),
8131    dg(
8132        "bynk.http.cookies_field_not_stringy",
8133        "A field of an HTTP handler's `cookies` record has a type a cookie cannot carry.",
8134        &["http_handler"],
8135    ),
8136    dg(
8137        "bynk.http.cookies_not_http",
8138        "A `RequestCookies` appears on a handler that is not an HTTP route.",
8139        &["http_handler"],
8140    ),
8141    d(
8142        "bynk.http.cookies_wrong_type",
8143        "An HTTP handler's `cookies` parameter is not a record type.",
8144    ),
8145    d(
8146        "bynk.http.cors_invalid_field",
8147        "A `cors` policy field (`headers`/`credentials`/`maxAge`) has the wrong value shape.",
8148    ),
8149    d(
8150        "bynk.http.cors_invalid_origins",
8151        "A `cors` policy's `origins` is missing, empty, or not a list of string literals.",
8152    ),
8153    d(
8154        "bynk.http.cors_not_http",
8155        "A `cors { }` policy appears on a service that is not `from http`.",
8156    ),
8157    d(
8158        "bynk.http.cors_unknown_field",
8159        "A `cors { }` policy declares a field outside the closed set.",
8160    ),
8161    d(
8162        "bynk.http.cors_wildcard_credentials",
8163        "A `cors` policy combines `credentials: true` with the wildcard origin `[\"*\"]`.",
8164    ),
8165    dg(
8166        "bynk.http.duplicate_rejected",
8167        "A `from http` service declares `on rejected` more than once.",
8168        &["rejected_handler"],
8169    ),
8170    dg(
8171        "bynk.http.duplicate_route",
8172        "Two handlers share the same method and route.",
8173        &["http_handler"],
8174    ),
8175    d(
8176        "bynk.http.error_status_position",
8177        "An `ErrorStatus` name is used anywhere but as `RawError`'s first argument.",
8178    ),
8179    dg(
8180        "bynk.http.extra_param",
8181        "A handler parameter is not a path parameter, `body`, `headers` or `query`.",
8182        &["http_handler"],
8183    ),
8184    dg(
8185        "bynk.http.form_body_not_record",
8186        "The `body` of a `@form` handler is not a record type.",
8187        &["http_handler"],
8188    ),
8189    warn(dg(
8190        "bynk.http.form_bool_without_default",
8191        "A `Bool` field of a `@form` body has no default, so an unchecked checkbox (which a browser sends as nothing) is a `400` (warning).",
8192        &["http_handler"],
8193    )),
8194    d(
8195        "bynk.http.form_duplicate",
8196        "A handler carries more than one `@form` annotation.",
8197    ),
8198    dg(
8199        "bynk.http.form_field_not_stringy",
8200        "A field of a `@form` body record has a type a form cannot carry.",
8201        &["http_handler"],
8202    ),
8203    d(
8204        "bynk.http.form_on_bodyless",
8205        "A `@form` or `@multipart` annotation is placed on a handler that takes no body.",
8206    ),
8207    d(
8208        "bynk.http.form_on_sum_route",
8209        "A `@form` handler's `by` clause is a sum of actors, whose wrapper reads the body as JSON itself.",
8210    ),
8211    d(
8212        "bynk.http.form_unknown_arg",
8213        "A `@form` annotation is given an argument; it takes none.",
8214    ),
8215    warn(d(
8216        "bynk.http.header_question_not_found",
8217        "`?` on `RequestHeaders.get(…)` in an `HttpResult` handler answers `404 NotFound` for a missing header, where `400` is meant (warning; auto-fixable to a `let … else` that answers `BadRequest`).",
8218    )),
8219    dg(
8220        "bynk.http.headers_wrong_type",
8221        "An HTTP handler's `headers` parameter is not typed `RequestHeaders`.",
8222        &["http_handler"],
8223    ),
8224    dg(
8225        "bynk.http.invalid_path",
8226        "An HTTP route path is malformed.",
8227        &["http_handler"],
8228    ),
8229    d(
8230        "bynk.http.json_duplicate",
8231        "A handler carries more than one `@json` annotation.",
8232    ),
8233    d(
8234        "bynk.http.json_invalid_arg",
8235        "A `@json` annotation's `options` argument is missing or is not `tagged` or `plain`.",
8236    ),
8237    d(
8238        "bynk.http.json_invalid_field",
8239        "A `json { }` policy's `options` is not `tagged` or `plain`.",
8240    ),
8241    d(
8242        "bynk.http.json_not_http",
8243        "A `json { }` policy appears on a service that is not `from http`.",
8244    ),
8245    d(
8246        "bynk.http.json_on_non_http",
8247        "A `@json` annotation is placed on a handler that is not `on http`.",
8248    ),
8249    d(
8250        "bynk.http.json_unknown_arg",
8251        "A `@json` annotation has an argument outside the closed set (`options`).",
8252    ),
8253    d(
8254        "bynk.http.json_unknown_field",
8255        "A `json { }` policy declares a field outside the closed set (`options`).",
8256    ),
8257    d(
8258        "bynk.http.limit_bad_max_body",
8259        "A `@limit` annotation's `maxBody` is missing or not a positive `Int` literal.",
8260    ),
8261    d(
8262        "bynk.http.limit_bad_max_file",
8263        "A `@limit` `maxFile` or `maxParts` is not a positive `Int` literal.",
8264    ),
8265    d(
8266        "bynk.http.limit_duplicate",
8267        "A handler carries more than one `@limit` annotation.",
8268    ),
8269    d(
8270        "bynk.http.limit_on_bodyless",
8271        "A `@limit` annotation is placed on a handler that takes no body (a GET or DELETE).",
8272    ),
8273    d(
8274        "bynk.http.limit_on_non_multipart",
8275        "A `@limit` `maxFile` or `maxParts` is placed on a route that is not `@multipart`.",
8276    ),
8277    d(
8278        "bynk.http.limit_unknown_arg",
8279        "A `@limit` annotation has an argument outside the closed set (`maxBody`).",
8280    ),
8281    d(
8282        "bynk.http.limits_invalid_field",
8283        "A `limits` policy field (`maxBody`) has the wrong value shape.",
8284    ),
8285    d(
8286        "bynk.http.limits_not_http",
8287        "A `limits { }` policy appears on a service that is not `from http`.",
8288    ),
8289    d(
8290        "bynk.http.limits_unknown_field",
8291        "A `limits { }` policy declares a field outside the closed set.",
8292    ),
8293    d(
8294        "bynk.http.multipart_body_unbounded",
8295        "A `@multipart` route has no request-body cap (`@limit` or `limits { maxBody }`).",
8296    ),
8297    warn(d(
8298        "bynk.http.multipart_large_cap",
8299        "A `@multipart` route's body cap is over 32 MiB; the body is buffered with a parsed copy beside it, in a Worker's 128 MB (warning).",
8300    )),
8301    dg(
8302        "bynk.http.path_param_not_stringy",
8303        "A path parameter's type is not constructible from a string.",
8304        &["http_handler"],
8305    ),
8306    dg(
8307        "bynk.http.query_field_not_stringy",
8308        "A field of an HTTP handler's `query` record has a type a query string cannot carry.",
8309        &["http_handler"],
8310    ),
8311    dg(
8312        "bynk.http.query_not_http",
8313        "A `RequestQuery` appears on a handler that is not an HTTP route.",
8314        &["http_handler"],
8315    ),
8316    dg(
8317        "bynk.http.query_wrong_type",
8318        "An HTTP handler's `query` parameter is neither a record type nor `RequestQuery`.",
8319        &["http_handler"],
8320    ),
8321    d(
8322        "bynk.http.raw_bad_content_type",
8323        "A `@raw` annotation's `contentType` is missing or not a `type/subtype` (or `\"*/*\"`) string literal.",
8324    ),
8325    d(
8326        "bynk.http.raw_body_not_bytes",
8327        "The `body` of a `@raw` handler is not typed `Bytes` or `Stream[Bytes]`.",
8328    ),
8329    d(
8330        "bynk.http.raw_body_unbounded",
8331        "A `@raw` route has no request-body cap (no `@limit` and no service `limits`).",
8332    ),
8333    d(
8334        "bynk.http.raw_duplicate",
8335        "A handler carries more than one `@raw` annotation.",
8336    ),
8337    d(
8338        "bynk.http.raw_error_status",
8339        "`RawError`'s first argument is not an `ErrorStatus` name (a 4xx or 5xx `HttpResult` variant name).",
8340    ),
8341    d(
8342        "bynk.http.raw_on_bodyless",
8343        "A `@raw` annotation is placed on a handler that takes no body.",
8344    ),
8345    d(
8346        "bynk.http.raw_unknown_arg",
8347        "A `@raw` annotation has an argument outside the closed set (`contentType`).",
8348    ),
8349    dg(
8350        "bynk.http.rejected_signature",
8351        "An `on rejected` handler is not `on rejected(why: BoundaryRejection) -> HttpResult[()]` with no `by` and no `given`.",
8352        &["rejected_handler"],
8353    ),
8354    dg(
8355        "bynk.http.reserved_prefix",
8356        "A route uses a reserved prefix: `/_bynk/` (internal dispatch) or `/_assets/` (static assets).",
8357        &["http_handler"],
8358    ),
8359    dg(
8360        "bynk.http.reserved_route_syntax",
8361        "A route segment contains `*`, `{` or `}`, which are reserved for a future route form.",
8362        &["http_handler"],
8363    ),
8364    dg(
8365        "bynk.http.return_not_effect_http_result",
8366        "An HTTP handler does not return `Effect[HttpResult[T]]`.",
8367        &["http_handler"],
8368    ),
8369    d(
8370        "bynk.http.security_invalid_field",
8371        "A `security` policy field (`hsts`/`nosniff`) has the wrong value shape.",
8372    ),
8373    d(
8374        "bynk.http.security_not_http",
8375        "A `security { }` policy appears on a service that is not `from http`.",
8376    ),
8377    d(
8378        "bynk.http.security_unknown_field",
8379        "A `security { }` policy declares a field outside the closed set.",
8380    ),
8381    d(
8382        "bynk.http.stream_body_not_raw",
8383        "A `Stream[Bytes]` `body` is on a handler that is not `@raw`.",
8384    ),
8385    d(
8386        "bynk.http.stream_body_on_sum_route",
8387        "A route with a streamed `body` has a `by` clause that is a sum of actors, whose wrapper reads the body itself.",
8388    ),
8389    d(
8390        "bynk.http.stream_body_signature",
8391        "A route with a streamed `body` has a `Signature` actor, which verifies an HMAC over the whole body first.",
8392    ),
8393    dg(
8394        "bynk.http.unbound_path_param",
8395        "A `:name` route segment has no matching handler parameter.",
8396        &["http_handler"],
8397    ),
8398    d(
8399        "bynk.http.unknown_handler_annotation",
8400        "A handler carries an annotation outside the closed set (`@cache`/`@limit`).",
8401    ),
8402    d(
8403        "bynk.index.bad_argument",
8404        "An `@indexed` argument is not a `by: <field>` label.",
8405    ),
8406    warn(d(
8407        "bynk.index.missing",
8408        "A query filters a map by equality on a field that is not `@indexed` (a perf-hint warning).",
8409    )),
8410    d(
8411        "bynk.index.unkeyable_key",
8412        "An `@indexed(by: k)` field is not value-keyable.",
8413    ),
8414    d(
8415        "bynk.index.unknown_key",
8416        "An `@indexed(by: k)` field is not a field of the map's value type.",
8417    ),
8418    warn(d(
8419        "bynk.index.unused",
8420        "A declared `@indexed(by: k)` is never used by an equality filter (a hygiene warning).",
8421    )),
8422    d(
8423        "bynk.internal.missing_checker_fact",
8424        "A compiler fault, not a mistake in the program: the code generator needed a fact the checker should have recorded (a type, a callee, an argument count, a field default) and found none. The diagnostic points at the construct being compiled; report it at https://github.com/bynk-lang/bynk/issues.",
8425    ),
8426    d(
8427        "bynk.invariant.cross_agent_reference",
8428        "An invariant predicate references another agent; invariants are per-agent.",
8429    ),
8430    d(
8431        "bynk.invariant.duplicate_name",
8432        "An agent declares two invariants with the same name.",
8433    ),
8434    d(
8435        "bynk.invariant.impure_predicate",
8436        "An invariant predicate uses an effectful or test-only construct.",
8437    ),
8438    d(
8439        "bynk.invariant.not_bool",
8440        "An invariant predicate does not have type `Bool`.",
8441    ),
8442    d(
8443        "bynk.json.encode_plain_generic",
8444        "`Json.encodePlain` is given a value whose type mentions a type parameter. A generic value encodes through its `Codable` witness, which always writes `Option` in the tagged form, so plain encoding is available only at a concrete type.",
8445    ),
8446    d(
8447        "bynk.json.nested_option_plain",
8448        "A plain-JSON route's response type, or the argument of `Json.encodePlain`, contains an `Option[U]` whose payload `U` can itself encode as `null` (`Option[T]` or `()`), so `Some(U)` and `None` would both be written `null`.",
8449    ),
8450    dg(
8451        "bynk.lambda.unannotated_param",
8452        "A lambda parameter has no type annotation in a position where no function type is expected to infer it from.",
8453        &["lambda_expr"],
8454    ),
8455    dg(
8456        "bynk.lex.bad_escape",
8457        "An invalid escape sequence in a string literal.",
8458        &["string_literal"],
8459    ),
8460    dg(
8461        "bynk.lex.bad_unicode_escape",
8462        "A `\\u{…}` escape names a surrogate or a value above U+10FFFF.",
8463        &["string_literal"],
8464    ),
8465    dg(
8466        "bynk.lex.decimal_literal_too_large",
8467        "A decimal literal has more than 100 fraction digits or more than 1000 characters, the most any `Decimal` may have (#2622).",
8468        &["decimal_literal"],
8469    ),
8470    dg(
8471        "bynk.lex.float_literal_overflow",
8472        "A float literal does not fit a finite 64-bit float.",
8473        &["float_literal"],
8474    ),
8475    dg(
8476        "bynk.lex.integer_overflow",
8477        "An integer literal is outside the `Int` range, the JS safe integers ±(2^53 − 1).",
8478        &["number_literal"],
8479    ),
8480    dg(
8481        "bynk.lex.interpolation_too_deep",
8482        "A string interpolation `\\(…)` nests deeper than the lexer's fixed limit.",
8483        &["string_literal"],
8484    ),
8485    d(
8486        "bynk.lex.legacy_comment",
8487        "A `--` line comment, the spelling before #2203; a comment is `//` (auto-fixable; `bynk fmt` rewrites it).",
8488    ),
8489    d(
8490        "bynk.lex.legacy_doc_line",
8491        "A `--|` one-line doc, the spelling before #2203; a one-line doc is `--- text` (auto-fixable; `bynk fmt` rewrites it).",
8492    ),
8493    dg(
8494        "bynk.lex.multiline_close_not_own_line",
8495        "A `\"\"\"` inside a multi-line string literal is not on a line of its own.",
8496        &["string_literal"],
8497    ),
8498    dg(
8499        "bynk.lex.multiline_in_hole",
8500        "A multi-line string literal appears inside an interpolation hole, which must close on its own line.",
8501        &["string_literal"],
8502    ),
8503    dg(
8504        "bynk.lex.multiline_indent",
8505        "A line of a multi-line string literal is indented less than its closing `\"\"\"`.",
8506        &["string_literal"],
8507    ),
8508    dg(
8509        "bynk.lex.multiline_open",
8510        "The opening `\"\"\"` of a multi-line string literal is not followed by a newline, or by a language tag (`\"\"\"sql`) and a newline.",
8511        &["string_literal"],
8512    ),
8513    d(
8514        "bynk.lex.slash_doc",
8515        "A `///` doc comment first on its line; a Bynk doc is `--- text` or a `---` block (auto-fixable).",
8516    ),
8517    d(
8518        "bynk.lex.unclosed_doc_block",
8519        "A documentation block is not closed.",
8520    ),
8521    d(
8522        "bynk.lex.unexpected_character",
8523        "An unexpected character in the source.",
8524    ),
8525    dg(
8526        "bynk.lex.unterminated_interpolation",
8527        "An interpolation hole `\\(…)` is not closed on its line.",
8528        &["string_literal"],
8529    ),
8530    dg(
8531        "bynk.lex.unterminated_string",
8532        "A string literal is not terminated.",
8533        &["string_literal"],
8534    ),
8535    warn(d(
8536        "bynk.list.deprecated_function",
8537        "A `bynk.list` free function is deprecated in favour of the `List` method form (warning; auto-fixable).",
8538    )),
8539    warn(d(
8540        "bynk.list.par_traverse_unit",
8541        "`List.parTraverse` now returns the steps' values, and its step returns `()`: that is `parForEach` (warning; auto-fixable).",
8542    )),
8543    d(
8544        "bynk.locale.multiple_message_bundles",
8545        "A context consumes `Locale` but its direct `uses` reaches two or more message-bundle commons — there is no single bundle to negotiate against.",
8546    ),
8547    warn(d(
8548        "bynk.map.deprecated_function",
8549        "A `bynk.map` free function is deprecated in favour of the `Map` method form (warning; auto-fixable).",
8550    )),
8551    d(
8552        "bynk.messages.format_mismatch",
8553        "A code's placeholder is formatted as a different ICU kind (plain/plural/select/number/date) across declared locales.",
8554    ),
8555    d(
8556        "bynk.messages.incomplete",
8557        "A locale is missing a code the reference locale declares.",
8558    ),
8559    d(
8560        "bynk.messages.invalid_locale_tag",
8561        "A `messages` block's locale tag is not a valid `LocaleTag` (e.g. `messages \"xx\"` where `xx` doesn't match the tag pattern).",
8562    ),
8563    d(
8564        "bynk.messages.malformed_icu_syntax",
8565        "A message template's ICU placeholder syntax is invalid — unbalanced arm braces, an unknown format keyword, `#` outside a plural arm, a missing mandatory `other` arm, or an explicitly out-of-scope construct (`selectordinal`, `offset:`/`=N`, a CLDR skeleton).",
8566    ),
8567    d(
8568        "bynk.messages.missing_locale_dependency",
8569        "A commons declaring `messages` doesn't `uses bynk.locale` and/or `uses bynk.locale.types`, which its generated `render` and the types its signature names need.",
8570    ),
8571    d(
8572        "bynk.messages.missing_reference",
8573        "A message bundle has no `@reference` block.",
8574    ),
8575    d(
8576        "bynk.messages.multiple_reference",
8577        "A message bundle has more than one `@reference` block.",
8578    ),
8579    d(
8580        "bynk.messages.outside_commons",
8581        "A `messages` declaration appears outside a commons.",
8582    ),
8583    d(
8584        "bynk.messages.placeholder_mismatch",
8585        "A locale's template for a code uses a different set of `{name}` placeholders than the reference locale's.",
8586    ),
8587    warn(d(
8588        "bynk.mysql.sql_invalid",
8589        "A literal `MySql` statement does not parse with the MySQL dialect of a pure-Rust SQL parser, or is more than one command, in a project that has a `schema.sql` (warning: the parser is not MySQL's own, so it may refuse valid SQL).",
8590    )),
8591    d(
8592        "bynk.mysql.sql_param_count",
8593        "A literal `MySql` statement has a different number of `?` placeholders than the list literal passed with it holds, in a project that has a `schema.sql`.",
8594    ),
8595    d(
8596        "bynk.namespace.reserved",
8597        "A user unit is named `bynk` or `bynk.*`; the `bynk` root is reserved for the toolchain.",
8598    ),
8599    d(
8600        "bynk.observe.impure_with",
8601        "A `with` predicate uses an effectful or test-only construct, or an effectful call (a sub-expression of type `Effect[_]`); it must be pure.",
8602    ),
8603    d(
8604        "bynk.observe.not_a_seam",
8605        "An observation targets a capability the unit under test does not consume.",
8606    ),
8607    d(
8608        "bynk.observe.trace_outside_test",
8609        "`trace(Cap.op)` appears outside a `case` body.",
8610    ),
8611    d(
8612        "bynk.observe.unknown_op",
8613        "An observation names an operation the capability does not declare.",
8614    ),
8615    d(
8616        "bynk.observe.with_not_bool",
8617        "A `with` predicate does not have type `Bool`.",
8618    ),
8619    d(
8620        "bynk.package.alias_shadows_unit",
8621        "A dependency alias in `[dependencies]` is also the first segment of one of the project's own units, so `<alias>.…` would be ambiguous.",
8622    ),
8623    d(
8624        "bynk.package.checksum_mismatch",
8625        "A git dependency's store entry, or a freshly fetched commit, doesn't hash to the checksum `bynk.lock` records; `bynk` refuses to build it.",
8626    ),
8627    d(
8628        "bynk.package.dependency_cycle",
8629        "The package graph has a cycle: a dependency depends, directly or not, on itself or on the project.",
8630    ),
8631    d(
8632        "bynk.package.dependency_not_found",
8633        "A path dependency's directory has no readable `bynk.toml`, its `bynk.toml` is invalid, or it has no `[package]`.",
8634    ),
8635    d(
8636        "bynk.package.dev_dependency_in_source",
8637        "A commons, context or adapter reaches a `[dev-dependencies]` alias, which only a suite may use.",
8638    ),
8639    d(
8640        "bynk.package.duplicate_source",
8641        "One package is reached from two different directories; a build holds one copy of each package.",
8642    ),
8643    d(
8644        "bynk.package.git_failed",
8645        "`git` couldn't clone, fetch or check out a git dependency, or the revision it names doesn't exist.",
8646    ),
8647    d(
8648        "bynk.package.lock_invalid",
8649        "`bynk.lock` can't be read: it isn't valid TOML, has no `version`, is a version this toolchain doesn't read, or locks a package to something that isn't a commit.",
8650    ),
8651    d(
8652        "bynk.package.lock_out_of_date",
8653        "`--locked` was given, and resolving the manifests would change `bynk.lock`.",
8654    ),
8655    d(
8656        "bynk.package.name_mismatch",
8657        "A path dependency's `package` names a different package than the directory's `[package] name`.",
8658    ),
8659    d(
8660        "bynk.package.not_fetched",
8661        "A git dependency has no `bynk.lock` entry, or its store entry is missing; `bynk fetch` fetches it (refused under `--offline`).",
8662    ),
8663    d(
8664        "bynk.package.unit_not_exported",
8665        "A `uses` or `consumes` reaches a unit its dependency declares but doesn't list in `[package] exports`.",
8666    ),
8667    d(
8668        "bynk.package.unknown_unit",
8669        "A `uses` or `consumes` names, through a dependency alias, a unit the dependency doesn't declare.",
8670    ),
8671    d(
8672        "bynk.package.unsafe_source",
8673        "A git dependency's URL or revision looks like a command-line option, or uses a transport other than `https`, `ssh` (or `file`, from the project's own manifests).",
8674    ),
8675    d(
8676        "bynk.package.unsupported_in_dependency",
8677        "A dependency declares an `asset` or an `embed`, which would resolve against the consuming project's `assets/` or `embeds/`; a per-package namespace for either isn't designed yet.",
8678    ),
8679    d(
8680        "bynk.package.version_conflict",
8681        "One package is reached at two different git revisions (or from git and a path); a build, or a workspace, holds one copy of each package.",
8682    ),
8683    dg(
8684        "bynk.par.invalid_statement",
8685        "A `par { … }` block holds a statement other than `let x <- e` or `do e`: a refutable `let … else`, a plain `let`, `:=` or a store write, `expect`, `advance`, a nested `par`, or anything that is not a statement.",
8686        &["par_stmt"],
8687    ),
8688    dg(
8689        "bynk.par.question_in_join",
8690        "A `?` appears inside a `par { … }` binding. `?` takes a `Result` value, not an effect, so a binding's own result is unwrapped after the block (`let user = userR?`), where the `?` lines run in source order; a `?` on an argument is computed before the block.",
8691        &["par_stmt"],
8692    ),
8693    dg(
8694        "bynk.par.sibling_name",
8695        "A `par { … }` binding mentions a name another binding in the same block binds, or binds a name twice. The bindings run together, so none can read a sibling's result; the rule holds even where the name would resolve to an outer binding.",
8696        &["par_stmt"],
8697    ),
8698    warn(dg(
8699        "bynk.par.single_binding",
8700        "A `par { … }` block has a single binding, which is a plain `let x <- e` with extra syntax (warning).",
8701        &["par_stmt"],
8702    )),
8703    d(
8704        "bynk.par.store_write_in_closure",
8705        "A closure passed to `parForEach`, `parTraverse`, `parTraverseAll` or `parTraverseTry` writes a `store` field (`put`, `remove`, `update`, `upsert`, `add`, `append` or `:=`). Its branches run concurrently, and a `get` then a `put` across them loses updates, so store writes stay sequential, as they do in a `par { … }` block.",
8706    ),
8707    dg(
8708        "bynk.parse.bare_expression_statement",
8709        "An expression stands alone as a statement, followed by more of the block; a block has no expression statements, so its value would be discarded. Bind it with `let _ <-` (an effect) or `let _ =`.",
8710        &["block"],
8711    ),
8712    d(
8713        "bynk.parse.clause_after_statement",
8714        "A `stub` or `env` clause came after a statement in a test case; they lead the case body.",
8715    ),
8716    dg(
8717        "bynk.parse.const_missing_type",
8718        "A `const` declaration has no type annotation; a constant's type is always written (`const Name: Type = …`).",
8719        &["const_decl"],
8720    ),
8721    dg(
8722        "bynk.parse.consumes_after_decls",
8723        "`consumes` appears after other declarations.",
8724        &["consumes_decl"],
8725    ),
8726    d(
8727        "bynk.parse.dangling_handler_annotation",
8728        "A handler-position annotation (e.g. `@cache`) is not followed by an `on` handler.",
8729    ),
8730    d(
8731        "bynk.parse.doc_block_contains_code",
8732        "A documentation block's content (outside Markdown code fences) parses as declarations, so a pair of dash dividers has turned code into documentation.",
8733    ),
8734    dg(
8735        "bynk.parse.duplicate_cors",
8736        "A service declares more than one `cors { }` policy.",
8737        &["service_decl"],
8738    ),
8739    dg(
8740        "bynk.parse.duplicate_json",
8741        "A service declares more than one `json { }` policy.",
8742        &["service_decl"],
8743    ),
8744    dg(
8745        "bynk.parse.duplicate_limits",
8746        "A service declares more than one `limits { }` policy.",
8747        &["service_decl"],
8748    ),
8749    dg(
8750        "bynk.parse.duplicate_security",
8751        "A service declares more than one `security { }` policy.",
8752        &["service_decl"],
8753    ),
8754    dg(
8755        "bynk.parse.empty_agent",
8756        "An `agent` body is empty.",
8757        &["agent_decl"],
8758    ),
8759    dg(
8760        "bynk.parse.empty_capability",
8761        "A `capability` body is empty.",
8762        &["capability_decl"],
8763    ),
8764    d(
8765        "bynk.parse.empty_interpolation",
8766        "An interpolation hole `\\(…)` contains no expression.",
8767    ),
8768    dg(
8769        "bynk.parse.empty_match",
8770        "A `match` has no arms.",
8771        &["match_expr"],
8772    ),
8773    dg(
8774        "bynk.parse.empty_service",
8775        "A `service` body is empty.",
8776        &["service_decl"],
8777    ),
8778    d(
8779        "bynk.parse.event_pattern_empty",
8780        "A `from Events(E { ... })` subscription pattern listed no fields — use `from Events(E)` (no braces) for an unfiltered subscription.",
8781    ),
8782    dg(
8783        "bynk.parse.expected_agent_key",
8784        "Expected a `key` declaration in an agent.",
8785        &["agent_decl"],
8786    ),
8787    d(
8788        "bynk.parse.expected_agent_storage",
8789        "An agent declares no storage — it has no `store` fields.",
8790    ),
8791    dg(
8792        "bynk.parse.expected_base_type",
8793        "Expected a base type.",
8794        &["base_type"],
8795    ),
8796    dg(
8797        "bynk.parse.expected_capability_op",
8798        "Expected a capability operation.",
8799        &["capability_op"],
8800    ),
8801    d("bynk.parse.expected_expression", "Expected an expression."),
8802    dg(
8803        "bynk.parse.expected_handler",
8804        "Expected a handler.",
8805        &["handler"],
8806    ),
8807    d("bynk.parse.expected_item", "Expected a declaration."),
8808    dg(
8809        "bynk.parse.expected_predicate",
8810        "Expected a refinement predicate.",
8811        &["refinement"],
8812    ),
8813    dg(
8814        "bynk.parse.expected_provider_op",
8815        "Expected a provider operation.",
8816        &["provider_op"],
8817    ),
8818    d("bynk.parse.expected_token", "Expected a specific token."),
8819    d("bynk.parse.expected_type", "Expected a type."),
8820    d(
8821        "bynk.parse.expected_unit_header",
8822        "Expected a `commons` or `context` header.",
8823    ),
8824    dg(
8825        "bynk.parse.expected_visibility",
8826        "Expected a visibility keyword.",
8827        &["exports_decl"],
8828    ),
8829    dg(
8830        "bynk.parse.exports_after_decls",
8831        "`exports` appears after other declarations.",
8832        &["exports_decl"],
8833    ),
8834    d(
8835        "bynk.parse.extra_tokens",
8836        "Unexpected tokens after an otherwise complete construct.",
8837    ),
8838    dg(
8839        "bynk.parse.generic_arg_count",
8840        "Wrong number of generic type arguments.",
8841        &["generic_type_ref"],
8842    ),
8843    dg(
8844        "bynk.parse.handler_in_agent",
8845        "A protocol handler (`on GET`/`schedule`/`message`) was declared in an agent.",
8846        &["handler"],
8847    ),
8848    d(
8849        "bynk.parse.invariant_after_handler",
8850        "An `invariant` was declared after a handler; invariants precede handlers.",
8851    ),
8852    dg(
8853        "bynk.parse.keyword_field_shorthand",
8854        "A reserved keyword was used as a field shorthand, which would bind a variable of that name.",
8855        &["identifier"],
8856    ),
8857    dg(
8858        "bynk.parse.lambda_pattern_annotation",
8859        "A lambda parameter with a record pattern carries a type annotation; the pattern's type name already gives the parameter's type.",
8860        &["lambda_param"],
8861    ),
8862    dg(
8863        "bynk.parse.lambda_pattern_not_record",
8864        "A lambda parameter is a pattern other than a record pattern; only an irrefutable record pattern may stand in for a name.",
8865        &["lambda_param"],
8866    ),
8867    dg(
8868        "bynk.parse.lambda_pattern_refutable",
8869        "A lambda parameter's record pattern can fail to match some value of its type, and a lambda has no `else` to fall back on.",
8870        &["lambda_param"],
8871    ),
8872    dg(
8873        "bynk.parse.let_else_on_binding",
8874        "An `else` follows a plain `let name = …` binding, which matches every value, so the `else` could never run.",
8875        &["let_stmt", "effect_let_stmt"],
8876    ),
8877    hint(d(
8878        "bynk.parse.let_else_staircase",
8879        "Nested `match`es on `Option`/`Result` that each carry on in one arm and give up in the other, which `let … else` writes flat. A hint with a machine-applicable rewrite; never fails a build and is hidden from the terminal (hint).",
8880    )),
8881    dg(
8882        "bynk.parse.let_pattern_annotation",
8883        "A `let` with a pattern carries a type annotation; the pattern's names take their types from the value.",
8884        &["let_else_stmt"],
8885    ),
8886    dg(
8887        "bynk.parse.let_pattern_without_else",
8888        "A `let` binds a pattern but has no `else` saying what the block produces when the value does not match; only a record pattern that cannot fail may omit it.",
8889        &["let_else_stmt"],
8890    ),
8891    dg(
8892        "bynk.parse.list_rest_not_last",
8893        "A `..` in a list pattern is not the final element; suffix forms such as `[.., last]` are not available.",
8894        &["list_pattern"],
8895    ),
8896    dg(
8897        "bynk.parse.malformed_float_literal",
8898        "A float literal is missing a digit on one side of the `.` (`1.`, `.5`).",
8899        &["float_literal"],
8900    ),
8901    dg(
8902        "bynk.parse.match_ends_block",
8903        "A `match` ends the block it is in, because a block has no expression statements; a second `match` straight after it cannot follow.",
8904        &["block"],
8905    ),
8906    d(
8907        "bynk.parse.migrate_after_handler",
8908        "A `migrate` step is declared after an agent handler; migration steps precede the handlers.",
8909    ),
8910    d(
8911        "bynk.parse.migrate_item",
8912        "A `migrate` step's body holds something other than `field := value`, `let` or `drop field`.",
8913    ),
8914    d(
8915        "bynk.parse.multiple_docs",
8916        "A declaration or member has two docs directly above it; a target has one doc, so a doc of more than one line is a `---` block.",
8917    ),
8918    d(
8919        "bynk.parse.nesting_too_deep",
8920        "An expression or type nests deeper than the parser's fixed limit.",
8921    ),
8922    d(
8923        "bynk.parse.no_remainder_operator",
8924        "`%` is not an operator; use `Int.rem` (the dividend's sign) or `Int.mod` (the divisor's).",
8925    ),
8926    dg(
8927        "bynk.parse.non_associative",
8928        "A non-associative operator was chained (e.g. `a == b == c`).",
8929        &["binary_expr"],
8930    ),
8931    warn(d(
8932        "bynk.parse.orphan_doc_block",
8933        "A documentation block is not attached to a declaration (warning).",
8934    )),
8935    dg(
8936        "bynk.parse.policy_order",
8937        "A service's `cors`/`security`/`limits` policy is out of order or follows a handler; they open the body in the order `cors`, `security`, `limits`, `json`.",
8938        &["service_decl"],
8939    ),
8940    dg(
8941        "bynk.parse.record_pattern_in_is_unparenthesised",
8942        "A record pattern after `is` is not parenthesised — write `x is (T { f, .. })`.",
8943        &["record_pattern"],
8944    ),
8945    dg(
8946        "bynk.parse.record_pattern_without_rest",
8947        "A record pattern does not end with `..`; every record pattern is open.",
8948        &["record_pattern"],
8949    ),
8950    dg(
8951        "bynk.parse.refined_pattern_inner",
8952        "A refined pattern's inner form is something other than `_`.",
8953        &["refined_pattern"],
8954    ),
8955    dg(
8956        "bynk.parse.removed_send_arrow",
8957        "The `~>` send was removed; write `do e.detach()`.",
8958        &["do_stmt"],
8959    ),
8960    dg(
8961        "bynk.parse.reserved_keyword",
8962        "A reserved keyword was used as an identifier.",
8963        &["identifier"],
8964    ),
8965    dg(
8966        "bynk.parse.self_outside_method",
8967        "`self` is the first parameter of a free function; only a method declaration, `fn Type.method(self, …)`, has a receiver.",
8968        &["self_expr"],
8969    ),
8970    d(
8971        "bynk.parse.storage_after_phase",
8972        "Agent storage (`state` / `store`) is declared after the invariants or handlers.",
8973    ),
8974    d(
8975        "bynk.parse.transition_after_handler",
8976        "A `transition` is declared after an agent handler; step invariants precede the handlers.",
8977    ),
8978    d(
8979        "bynk.parse.unexpected_adapter",
8980        "An `adapter` appeared where it is not allowed.",
8981    ),
8982    dg(
8983        "bynk.parse.unexpected_context",
8984        "A `context` appeared where it is not allowed.",
8985        &["context_decl"],
8986    ),
8987    d("bynk.parse.unexpected_eof", "Unexpected end of input."),
8988    dg(
8989        "bynk.parse.unexpected_suite",
8990        "A `suite` appeared where it is not allowed.",
8991        &["suite_decl"],
8992    ),
8993    d(
8994        "bynk.parse.unknown_effect_method",
8995        "An unknown method on `Effect`.",
8996    ),
8997    dg(
8998        "bynk.parse.unknown_handler_kind",
8999        "An unknown handler form (expected `call`, an HTTP method, `schedule`, or `message`).",
9000        &["handler"],
9001    ),
9002    dg(
9003        "bynk.parse.unknown_predicate",
9004        "An unknown refinement predicate.",
9005        &["predicate_name"],
9006    ),
9007    d(
9008        "bynk.parse.unknown_tier",
9009        "A `case`/`suite` `as <tier>` clause names something other than `unit`, `integration`, or `system`.",
9010    ),
9011    dg(
9012        "bynk.parse.uses_after_decls",
9013        "`uses` appears after other declarations.",
9014        &["uses_decl"],
9015    ),
9016    dg(
9017        "bynk.parse.variant_name_case",
9018        "A sum-type or enum variant name is not capitalised.",
9019        &["sum_variant", "enum_type"],
9020    ),
9021    warn(d(
9022        "bynk.postgres.sql_invalid",
9023        "A literal `Postgres` statement does not parse with the Postgres dialect of a pure-Rust SQL parser, or is more than one command, in a project that has a `schema.sql` (warning: the parser is not Postgres' own, so it may refuse valid SQL).",
9024    )),
9025    d(
9026        "bynk.postgres.sql_param_count",
9027        "A literal `Postgres` statement uses a different number of parameters (its highest `$n`) than the list literal passed with it holds, in a project that has a `schema.sql`.",
9028    ),
9029    d(
9030        "bynk.project.contracts_lock_corrupt",
9031        "`bynk.contracts.lock` (the older service contracts a callee still accepts) is missing its version field, empty, truncated, unparseable, or of an unsupported version — restore it from version control rather than deleting it, since a callee that forgets the contracts it accepts refuses its live callers.",
9032    ),
9033    warn(d(
9034        "bynk.project.contracts_lock_oversized",
9035        "`bynk.contracts.lock` has one service accepting more older contracts than the build keeps comfortably (warning).",
9036    )),
9037    warn(d(
9038        "bynk.project.contracts_lock_stale",
9039        "`bynk.contracts.lock` lists an older contract the service no longer accepts, because it is unreadable or no longer compatible with the contract the service has now; the entry is ignored (warning).",
9040    )),
9041    warn(d(
9042        "bynk.project.duplicate_compatibility_flag",
9043        "`bynk.toml`'s `[workers] compatibility_flags` lists a flag twice, or one every Bynk Worker already has; the duplicate is dropped (warning).",
9044    )),
9045    d(
9046        "bynk.project.duplicate_module_doc",
9047        "More than one file of a multi-file unit carries a module doc.",
9048    ),
9049    d(
9050        "bynk.project.export_context",
9051        "`bynk.toml`'s `[package] exports` lists a context: a package shares commons and adapters, never a context, which belongs to the project that deploys it.",
9052    ),
9053    d(
9054        "bynk.project.export_unknown",
9055        "`bynk.toml`'s `[package] exports` lists a name that isn't a commons or adapter the project declares.",
9056    ),
9057    d(
9058        "bynk.project.file_and_directory",
9059        "A unit exists as both a file and a directory.",
9060    ),
9061    d(
9062        "bynk.project.inconsistent_commons_name",
9063        "A source file's path does not match its declared name.",
9064    ),
9065    d(
9066        "bynk.project.kind_conflict",
9067        "A name is declared as both a commons and a context.",
9068    ),
9069    d(
9070        "bynk.project.no_root",
9071        "No project root could be determined.",
9072    ),
9073    d(
9074        "bynk.project.no_sources",
9075        "The project contains no source files.",
9076    ),
9077    d(
9078        "bynk.project.read_failed",
9079        "A source file could not be read.",
9080    ),
9081    d(
9082        "bynk.project.schema_registry_corrupt",
9083        "`bynk.schema.lock` (the schema registry for events and agent state) is missing its version field, empty, truncated, or otherwise unparseable — restore it from version control rather than deleting it, since deleting it would silently re-baseline every event's and agent's history.",
9084    ),
9085    warn(d(
9086        "bynk.project.unstable_not_experimental",
9087        "`bynk.toml`'s `[unstable] allow` lists an item that nothing experimental lies in or under: it is stable now, so the entry can go (warning).",
9088    )),
9089    d(
9090        "bynk.project.unstable_unknown_item",
9091        "`bynk.toml`'s `[unstable] allow` lists a path that names no standard-library unit, exported item or operation.",
9092    ),
9093    dg(
9094        "bynk.property.restates_refinement",
9095        "A `property` merely re-checks a refinement its type already guarantees.",
9096        &["for_all"],
9097    ),
9098    dg(
9099        "bynk.property.where_not_bool",
9100        "A `for all ... where` filter does not type to `Bool`.",
9101        &["for_all"],
9102    ),
9103    dg(
9104        "bynk.provider.agent_call_undeclared_capability",
9105        "A provider calls an agent handler that needs a capability the provider's `given` does not list.",
9106        &["provider_decl"],
9107    ),
9108    dg(
9109        "bynk.provider.dependency_cycle",
9110        "Providers form a capability dependency cycle through `given`.",
9111        &["provider_decl"],
9112    ),
9113    dg(
9114        "bynk.provider.extra_operation",
9115        "A `provides` block implements an operation not in the capability.",
9116        &["provider_decl"],
9117    ),
9118    dg(
9119        "bynk.provider.generic_op_requires_external",
9120        "A Bynk-bodied `provides` implements a capability operation that declares its own type parameter — only an external (bodiless) provider can.",
9121        &["provider_decl"],
9122    ),
9123    dg(
9124        "bynk.provider.missing_operation",
9125        "A `provides` block is missing a capability operation.",
9126        &["provider_decl"],
9127    ),
9128    dg(
9129        "bynk.provider.outside_context",
9130        "`provides` was declared outside a context.",
9131        &["provider_decl"],
9132    ),
9133    dg(
9134        "bynk.provider.signature_mismatch",
9135        "A `provides` operation's signature does not match the capability.",
9136        &["provider_decl"],
9137    ),
9138    dg(
9139        "bynk.provider.unknown_capability",
9140        "`provides` names a capability that does not exist.",
9141        &["provider_decl"],
9142    ),
9143    d(
9144        "bynk.query.join_key_mismatch",
9145        "A `joinOn`/`leftJoin` left and right key function return different types.",
9146    ),
9147    dg(
9148        "bynk.query.sum_needs_numeric",
9149        "A `sum`/`average` key function does not return a numeric type (`Int`, `Float`, or `Duration`; `sum` also takes a `Decimal`, `average` does not).",
9150        &[],
9151    ),
9152    dg(
9153        "bynk.queue.bad_params",
9154        "An `on message` handler does not take exactly one `message` parameter.",
9155        &["queue_handler"],
9156    ),
9157    dg(
9158        "bynk.queue.duplicate_consumer",
9159        "Two `on message` handlers, in one context or in two, consume the same queue.",
9160        &["queue_handler"],
9161    ),
9162    dg(
9163        "bynk.queue.invalid_name",
9164        "A `from queue(\"…\")` binding has an empty queue name, or one Cloudflare refuses.",
9165        &["queue_handler"],
9166    ),
9167    dg(
9168        "bynk.queue.return_not_queue_result",
9169        "An `on message` handler does not return `Effect[QueueResult]`.",
9170        &["handler"],
9171    ),
9172    dg(
9173        "bynk.race.in_agent_handler",
9174        "`a.race(b)` was used in an agent handler, which has no execution context to hand the losing effect to.",
9175        &["method_call"],
9176    ),
9177    dg(
9178        "bynk.race.in_pure_context",
9179        "`a.race(b)` was used in a pure (non-effectful) context.",
9180        &["method_call"],
9181    ),
9182    dg(
9183        "bynk.race.outside_handler",
9184        "`a.race(b)` was used outside a service handler's body and outside a function (in a provider operation, a WebSocket handler or a test `case` body), where no execution context exists.",
9185        &["method_call"],
9186    ),
9187    dg(
9188        "bynk.record_spread.field_type_mismatch",
9189        "A record-spread override has the wrong type for the field.",
9190        &["record_spread"],
9191    ),
9192    dg(
9193        "bynk.record_spread.non_record_base",
9194        "The base of a record spread is not a record.",
9195        &["record_spread"],
9196    ),
9197    dg(
9198        "bynk.record_spread.type_mismatch",
9199        "A record spread's base is a different record type.",
9200        &["record_spread"],
9201    ),
9202    dg(
9203        "bynk.record_spread.unknown_field",
9204        "A record spread overrides a field the record does not have.",
9205        &["record_spread"],
9206    ),
9207    dg(
9208        "bynk.refine.literal_violates",
9209        "A literal does not satisfy the refined type's predicate.",
9210        &["refined_type"],
9211    ),
9212    d(
9213        "bynk.registry.account_refused",
9214        "`bynk login`, `bynk logout` or a `bynk org` command didn't go through: you aren't signed in or your session expired, the registry has no account API (or is read through a mirror), the sign-in was declined or its code expired, or the registry refused the request (a taken or reserved name, not the owner, an unknown member or token).",
9215    ),
9216    d(
9217        "bynk.registry.bad_archive",
9218        "A registry archive is malformed or hostile: not a `bynk-tree-v1` stream, a path that is absolute or climbs out of the package, an out-of-order or repeated file, or past the size limits.",
9219    ),
9220    d(
9221        "bynk.registry.bad_signature",
9222        "An index line isn't signed by a key the trusted key's rotation chain reaches, or its signed registry `id` or package `name` isn't the one asked for (a forged or replayed line).",
9223    ),
9224    d(
9225        "bynk.registry.http_failed",
9226        "A registry couldn't be read: unreachable, an error status, a refused or missing token, a redirect from https to http, too many redirects, or a response past the size limit.",
9227    ),
9228    d(
9229        "bynk.registry.key_mismatch",
9230        "A registry's keys don't lead from the key trusted for it (pinned in `[registries]`, or recorded in `bynk.lock`), or it now declares a different `id`.",
9231    ),
9232    d(
9233        "bynk.registry.nonconformant",
9234        "`bynk registry conformance` found a registry breaking the protocol: a check failed (a wrong status, an unsigned or mis-signed line, a checksum that isn't the tree sent, a refusal without its JSON body, …); each failure names the check and the protocol section it holds the registry to.",
9235    ),
9236    d(
9237        "bynk.registry.publish_refused",
9238        "`bynk publish` or `bynk yank` didn't go through: the project isn't a versioned package, it has a path or git dependency, its registry has no publish API (or is read through a mirror), or the registry refused the request (no or wrong token, an existing version, an invalid upload).",
9239    ),
9240    d(
9241        "bynk.registry.source_mismatch",
9242        "`bynk.lock` locks a package to one registry, but its organisation now routes to another; a misrouted organisation fails rather than resolving a same-named package elsewhere.",
9243    ),
9244    d(
9245        "bynk.registry.unavailable",
9246        "No registry serves a package: its organisation isn't listed by any `[registries]` entry (the first-party registry isn't live yet), the registry has no `config.json`, or it has no such package or archive.",
9247    ),
9248    d(
9249        "bynk.registry.withdrawn",
9250        "`bynk.lock` locks a registry version that its registry withdrew (a takedown: yanked, and its archive deleted), and its tree isn't in the store.",
9251    ),
9252    dg(
9253        "bynk.requires.conflicting_range",
9254        "Two adapter `binding … requires { … }` entries give different version ranges for one npm package.",
9255        &["binding_decl"],
9256    ),
9257    dg(
9258        "bynk.requires.unapproved",
9259        "A reached adapter of a git or registry dependency requires an npm package, at a range, that the project hasn't approved in `bynk.lock`; review it and run `bynk approve <package>`.",
9260        &["binding_decl"],
9261    ),
9262    dg(
9263        "bynk.requires.unpinned_dependency",
9264        "An adapter `binding … requires { … }` entry has an unpinned version range.",
9265        &["binding_decl"],
9266    ),
9267    d(
9268        "bynk.resolve.ambiguous_variant",
9269        "A bare variant name is declared by several sum types in scope, and no expected type picks one.",
9270    ),
9271    dg(
9272        "bynk.resolve.arity_mismatch",
9273        "A function was called with the wrong number of arguments.",
9274        &["call"],
9275    ),
9276    dg(
9277        "bynk.resolve.bad_const_initialiser",
9278        "A `const` initialiser is not a static value of the declared type: only literals, constructors over static values, `T.unsafe(lit)`, `List.empty()`/`Map.empty()`/`Set.empty()`, `Duration` literals and references to other constants are allowed.",
9279        &["const_decl"],
9280    ),
9281    dg(
9282        "bynk.resolve.const_cycle",
9283        "Constants refer to each other in a cycle, so none of them has a value.",
9284        &["const_decl"],
9285    ),
9286    dg(
9287        "bynk.resolve.const_name_case",
9288        "A constant's name is not upper-camel case (`MaxRetries`, not `maxRetries`).",
9289        &["const_decl"],
9290    ),
9291    dg(
9292        "bynk.resolve.const_outside_context_or_commons",
9293        "A `const` declaration appears outside a context or commons.",
9294        &["const_decl"],
9295    ),
9296    d("bynk.resolve.duplicate_actor", "Two actors share a name."),
9297    dg(
9298        "bynk.resolve.duplicate_agent",
9299        "Two agents share a name.",
9300        &["agent_decl"],
9301    ),
9302    dg(
9303        "bynk.resolve.duplicate_capability",
9304        "Two capabilities share a name.",
9305        &["capability_decl"],
9306    ),
9307    dg(
9308        "bynk.resolve.duplicate_const",
9309        "Two constants share a name.",
9310        &["const_decl"],
9311    ),
9312    dg(
9313        "bynk.resolve.duplicate_field",
9314        "A record, or one variant's payload, declares a field twice.",
9315        &["record_type"],
9316    ),
9317    dg(
9318        "bynk.resolve.duplicate_field_init",
9319        "A record construction initialises a field twice.",
9320        &["record_construction"],
9321    ),
9322    dg(
9323        "bynk.resolve.duplicate_fn",
9324        "Two functions share a name.",
9325        &["fn_decl"],
9326    ),
9327    d(
9328        "bynk.resolve.duplicate_message_code",
9329        "A message bundle declares the same code twice in one block.",
9330    ),
9331    d(
9332        "bynk.resolve.duplicate_message_locale",
9333        "Two `messages` blocks in one bundle declare the same locale tag.",
9334    ),
9335    dg(
9336        "bynk.resolve.duplicate_method",
9337        "Two methods share a name.",
9338        &["fn_decl"],
9339    ),
9340    dg(
9341        "bynk.resolve.duplicate_param",
9342        "A parameter name is repeated.",
9343        &["param"],
9344    ),
9345    dg(
9346        "bynk.resolve.duplicate_provider",
9347        "A capability is provided more than once.",
9348        &["provider_decl"],
9349    ),
9350    dg(
9351        "bynk.resolve.duplicate_service",
9352        "Two services share a name.",
9353        &["service_decl"],
9354    ),
9355    dg(
9356        "bynk.resolve.duplicate_type",
9357        "Two types share a name.",
9358        &["type_decl"],
9359    ),
9360    dg(
9361        "bynk.resolve.duplicate_variant",
9362        "A sum type declares a variant twice.",
9363        &["sum_type"],
9364    ),
9365    d(
9366        "bynk.resolve.fn_without_call",
9367        "A function was referenced without being called.",
9368    ),
9369    dg(
9370        "bynk.resolve.let_shadows_fn",
9371        "A `let` binding shadows a function.",
9372        &["let_stmt"],
9373    ),
9374    dg(
9375        "bynk.resolve.let_shadows_type",
9376        "A `let` binding shadows a type.",
9377        &["let_stmt"],
9378    ),
9379    d(
9380        "bynk.resolve.method_unknown_type",
9381        "A method is defined on an unknown type.",
9382    ),
9383    dg(
9384        "bynk.resolve.missing_field",
9385        "A record construction omits a required field.",
9386        &["record_construction"],
9387    ),
9388    d(
9389        "bynk.resolve.name_conflict",
9390        "Two declarations share a name.",
9391    ),
9392    dg(
9393        "bynk.resolve.not_a_record_type",
9394        "Record syntax was used on a non-record type.",
9395        &["record_construction"],
9396    ),
9397    dg(
9398        "bynk.resolve.opaque_record_construction",
9399        "An opaque type was constructed with record syntax.",
9400        &["record_construction"],
9401    ),
9402    dg(
9403        "bynk.resolve.param_as_function",
9404        "A value (such as a parameter) was called as a function.",
9405        &["call"],
9406    ),
9407    dg(
9408        "bynk.resolve.recursive_record_field",
9409        "A record directly contains a field of its own type.",
9410        &["record_type"],
9411    ),
9412    dg(
9413        "bynk.resolve.reserved_builtin_type",
9414        "A type declaration reuses a compiler-known built-in type name.",
9415        &["type_decl"],
9416    ),
9417    dg(
9418        "bynk.resolve.reserved_host_name",
9419        "A declaration is named `globalThis`, which the generated TypeScript uses to reach host globals.",
9420        &["type_decl", "fn_decl", "agent_decl", "provider_decl"],
9421    ),
9422    dg(
9423        "bynk.resolve.reserved_payload_field",
9424        "A sum variant declares a payload field named `kind`, the variant's wire discriminant.",
9425        &["sum_type"],
9426    ),
9427    dg(
9428        "bynk.resolve.self_outside_method",
9429        "`self` referenced outside a method or handler.",
9430        &["self_expr"],
9431    ),
9432    dg(
9433        "bynk.resolve.type_as_function",
9434        "A type name was called as if it were a function.",
9435        &["call"],
9436    ),
9437    d(
9438        "bynk.resolve.type_in_expr",
9439        "A type name was used where a value is expected.",
9440    ),
9441    dg(
9442        "bynk.resolve.unconsumed_context",
9443        "A context's service was called, or its capability named in `given`, without a `consumes` declaration.",
9444        &["consumes_decl"],
9445    ),
9446    dg(
9447        "bynk.resolve.unknown_field",
9448        "A record construction names a field the record type does not declare.",
9449        &["record_construction"],
9450    ),
9451    dg(
9452        "bynk.resolve.unknown_function",
9453        "Called a function that does not exist.",
9454        &["call"],
9455    ),
9456    d(
9457        "bynk.resolve.unknown_name",
9458        "Referenced a name that is not in scope.",
9459    ),
9460    dg(
9461        "bynk.resolve.unknown_static_member",
9462        "Referenced an unknown static member (e.g. `T.x`).",
9463        &["field_access"],
9464    ),
9465    d(
9466        "bynk.resolve.unknown_type",
9467        "Referenced a type that does not exist.",
9468    ),
9469    d(
9470        "bynk.revert.agent_schema_older",
9471        "`bynk revert` refused because the target writes an older agent schema version than the live one while stored instances exist, are not known to be absent, or the target is below the class's floor, so the older code would fault on newer records.",
9472    ),
9473    d(
9474        "bynk.revert.class_changed",
9475        "`bynk revert` refused because a Durable Object class was added, removed or renamed between the live version and the target, and Cloudflare cannot roll back across a class migration.",
9476    ),
9477    d(
9478        "bynk.revert.contract_skew",
9479        "`bynk revert` refused because the target's contracts would no longer match another live Worker, judged as if every selected Worker were reverted together.",
9480    ),
9481    d(
9482        "bynk.revert.database_schema_ahead",
9483        "`bynk revert` refused because the live version applied D1 migrations the target was not built against, or the applied migrations could not be read; migrations only move forward, so the older code may not run on the newer schema.",
9484    ),
9485    d(
9486        "bynk.revert.facts_missing",
9487        "`bynk revert` refused because the live version or the target version carries no deploy facts (`BYNK_DEPLOY_FACTS`), or the facts could not be read, so nothing can be checked against them.",
9488    ),
9489    d(
9490        "bynk.revert.history_unplaceable",
9491        "`bynk revert` refused for one Worker because its deployment history cannot be placed: it has no earlier deployment, the live upload is outside the listed history, a gradual deployment is in progress, or the history could not be read.",
9492    ),
9493    d(
9494        "bynk.revert.id_unrecorded",
9495        "`bynk revert` refused because the target binds a KV namespace, database, limiter or Hyperdrive config that the deploy lock no longer records, usually because the resource was re-provisioned or replaced since.",
9496    ),
9497    d(
9498        "bynk.revert.layout_older",
9499        "`bynk revert` refused because the target writes an older agent storage layout than the live one while stored instances exist or are not known to be absent, so the older code could not read the newer records.",
9500    ),
9501    d(
9502        "bynk.revert.membership_changed",
9503        "`bynk revert` refused because a `[deploy.workers.<key>]` group's target version held other contexts than the live one (a context moved into or out of the group since, or the version predates groups), so a rollback would take a member's code out of the Worker.",
9504    ),
9505    d(
9506        "bynk.revert.secret_changed",
9507        "`bynk revert` refused because a secret changed after the target was live, so the rollback could restore an old secret value that its peers no longer accept.",
9508    ),
9509    warn(d(
9510        "bynk.secrets.computed_name",
9511        "A `bynk.Secrets` read names its secret with a computed expression rather than a literal, so `bynk deploy` cannot plan it (warning).",
9512    )),
9513    dg(
9514        "bynk.service.duplicate_call_handler",
9515        "A service declares more than one `on call` handler; it has exactly one.",
9516        &["service_decl"],
9517    ),
9518    dg(
9519        "bynk.service.missing_from",
9520        "A `from`-less service has a handler other than `on call`.",
9521        &["service_decl"],
9522    ),
9523    dg(
9524        "bynk.service.mixed_protocols",
9525        "A service mixes handler forms that do not match its `from <protocol>`.",
9526        &["service_decl"],
9527    ),
9528    dg(
9529        "bynk.service.outside_context",
9530        "A `service` was declared outside a context.",
9531        &["service_decl"],
9532    ),
9533    dg(
9534        "bynk.service.return_not_effect",
9535        "A service handler's return type is not an `Effect`.",
9536        &["service_decl"],
9537    ),
9538    dg(
9539        "bynk.service.unknown_protocol",
9540        "A `from <protocol>` names an unknown protocol (e.g. a transport like Kafka).",
9541        &["service_decl"],
9542    ),
9543    d(
9544        "bynk.service.unknown_via_clause",
9545        "A `via <name>(...)` clause on a `from Events(...)` header named something other than `schema` — `via` clauses are a closed set, and only `via schema(...)` exists today.",
9546    ),
9547    d(
9548        "bynk.service.websocket_header",
9549        "The `from websocket` header is malformed — it binds frame types as `websocket(in: <type>, out: <type>)` (real-time track slice 3).",
9550    ),
9551    d(
9552        "bynk.service.websocket_multiple",
9553        "A context holds more than one `from websocket` service — at v1 the Workers upgrade routes by the `Upgrade: websocket` header alone, so one WebSocket service per context (real-time track slice 3b).",
9554    ),
9555    d(
9556        "bynk.service.websocket_open_arity",
9557        "A `from websocket` service must hold exactly one `on open` handler (the edge upgrade), and at most one `on message` (inbound) and one `on close` (real-time track slice 3/3b-iii).",
9558    ),
9559    d(
9560        "bynk.service.websocket_param_not_stringy",
9561        "A `from websocket` service's `on open` parameter has a type not constructible from `String`; it arrives as a query-string value (#1657).",
9562    ),
9563    warn(d(
9564        "bynk.set.deprecated_function",
9565        "A `bynk.set` free function is deprecated in favour of the `Set` method form (warning; auto-fixable).",
9566    )),
9567    d(
9568        "bynk.stability.experimental",
9569        "An experimental standard-library item is used without an `[unstable] allow` entry in `bynk.toml` covering it.",
9570    ),
9571    d(
9572        "bynk.store.annotation_kind_mismatch",
9573        "A storage annotation is used on a kind it does not apply to (e.g. `@ttl` on a `Map`).",
9574    ),
9575    d(
9576        "bynk.store.annotation_unsupported",
9577        "A known storage annotation that nothing acts on yet (`@bounded`) is used; the others (`@ttl`, `@retain`, `@indexed`) are functional.",
9578    ),
9579    d(
9580        "bynk.store.cache_needs_clock",
9581        "A handler performs a `Cache` operation (TTL expiry reads the clock) without declaring `given Clock`.",
9582    ),
9583    d(
9584        "bynk.store.cache_ttl_required",
9585        "A `Cache` field is missing its required `@ttl(<duration>)` annotation (a keyed store with no expiry is a `Map`).",
9586    ),
9587    d(
9588        "bynk.store.kind_arity",
9589        "A storage kind was applied to the wrong number of type arguments (e.g. `Cell[A, B]`).",
9590    ),
9591    d(
9592        "bynk.store.kind_unsupported",
9593        "A known storage kind (`Queue`) is used before the slice that supports it.",
9594    ),
9595    d(
9596        "bynk.store.log_needs_clock",
9597        "A handler calls `Log.append` (which stamps the current time) without declaring `given Clock`.",
9598    ),
9599    d(
9600        "bynk.store.unkeyable_key",
9601        "A store `Set` element or `Map`/`Cache` key is not value-keyable — it must be `String`, `Int`, or a refined/opaque type over them (#1680).",
9602    ),
9603    d(
9604        "bynk.store.unknown_annotation",
9605        "A `store` field carries an annotation outside the closed `@indexed`/`@ttl`/`@retain`/`@bounded` set.",
9606    ),
9607    d(
9608        "bynk.store.unknown_kind",
9609        "A `store` field's type is not a known storage kind.",
9610    ),
9611    d(
9612        "bynk.store.unknown_map_accessor",
9613        "A `store Map` field access is not one of its query accessors (`entries`/`keys`/`values`).",
9614    ),
9615    d(
9616        "bynk.store.unknown_op",
9617        "A method called on a `store` field (`Map`, `Cache`, `Set`, `Cell` or `Log`) is not one of that kind's storage operations.",
9618    ),
9619    d(
9620        "bynk.stub.after_type",
9621        "A test `stub … returns <value> after <d>` latency is not a `Duration`.",
9622    ),
9623    dg(
9624        "bynk.stub.at_system",
9625        "A test `stub` is in a `system`-tier case, or at the scope of a `suite … as system` (or a suite whose cases run `as system`); each context runs as the Worker it deploys as, which builds its own capability providers, so there is no seam to override.",
9626        &["stub_clause"],
9627    ),
9628    d(
9629        "bynk.stub.bad_sequence",
9630        "A `stub … returns each […]` sequence is malformed (e.g. empty).",
9631    ),
9632    d(
9633        "bynk.stub.generic_op",
9634        "A test `stub` targets a capability operation that declares its own type parameter — not supported at v1.",
9635    ),
9636    d(
9637        "bynk.stub.not_a_seam",
9638        "A test `stub` overrides a capability the unit under test does not consume.",
9639    ),
9640    d(
9641        "bynk.stub.rhs_type",
9642        "A test `stub … returns <value>` right-hand side does not match the operation's return type.",
9643    ),
9644    d(
9645        "bynk.stub.unknown_op",
9646        "A test `stub` names an operation the capability does not declare.",
9647    ),
9648    dg(
9649        "bynk.suite.const_name_clash",
9650        "A suite `const` has the name of a declaration or sum variant already in scope in the suite's cases.",
9651        &["const_decl"],
9652    ),
9653    dg(
9654        "bynk.suite.duplicate_case_name",
9655        "Two `case`s share a description.",
9656        &["case"],
9657    ),
9658    dg(
9659        "bynk.suite.duplicate_const",
9660        "A suite declares two `const`s of the same name, or a `const` with the name of one of its `type`s.",
9661        &["const_decl"],
9662    ),
9663    dg(
9664        "bynk.suite.duplicate_env",
9665        "An `env { … }` clause gives the same name twice at one scope (a suite's `env` clauses, or one case's); a case's `env` may override a suite's name, but not repeat its own.",
9666        &["env_clause"],
9667    ),
9668    dg(
9669        "bynk.suite.duplicate_fn",
9670        "A suite declares two helper `fn`s of the same name.",
9671        &["fn_decl"],
9672    ),
9673    dg(
9674        "bynk.suite.duplicate_type",
9675        "A suite declares two `type`s of the same name.",
9676        &["type_decl"],
9677    ),
9678    dg(
9679        "bynk.suite.env_binding_clash",
9680        "A `system`-tier suite's or case's `env` names a binding a participant's Worker already declares (a Service Binding, KV namespace, or Durable Object namespace), or a key the test harness sets on it (a call-edge key, a `Foreign` caller's secret), so the entry would clash with it on the Worker's `env`.",
9681        &["env_clause"],
9682    ),
9683    dg(
9684        "bynk.suite.env_not_literal",
9685        "An `env { … }` entry's value is neither a `String` literal nor a `fixture` the same suite declares; a Worker's variables and secrets are strings, given verbatim.",
9686        &["env_clause"],
9687    ),
9688    dg(
9689        "bynk.suite.fn_effectful",
9690        "A suite helper `fn` returns an `Effect`; suite helpers are pure.",
9691        &["fn_decl"],
9692    ),
9693    dg(
9694        "bynk.suite.fn_method",
9695        "A suite helper `fn` is a method (`fn Type.name`); suite helpers are free functions.",
9696        &["fn_decl"],
9697    ),
9698    dg(
9699        "bynk.suite.fn_name_clash",
9700        "A suite helper `fn` has the name of a declaration already in scope in the suite's cases.",
9701        &["fn_decl"],
9702    ),
9703    dg(
9704        "bynk.suite.type_generic",
9705        "A suite declares a generic `type`; a suite type is a plain, non-generic shape.",
9706        &["type_decl"],
9707    ),
9708    dg(
9709        "bynk.suite.type_name_clash",
9710        "A suite `type`, or a variant of one, has the name of a declaration or sum variant already in scope in the suite's cases, or of another suite item.",
9711        &["type_decl"],
9712    ),
9713    dg(
9714        "bynk.suite.unknown_target",
9715        "A `suite` targets a unit that does not exist.",
9716        &["suite_decl"],
9717    ),
9718    d(
9719        "bynk.target.browser_bundle_only",
9720        "The `browser` platform builds only the in-process `Bundle` topology; `--target workers` is not a browser build.",
9721    ),
9722    dg(
9723        "bynk.target.vendor_conflict",
9724        "One deployment unit's in-process closure uses platform-native capabilities from two mutually-exclusive platforms.",
9725        &["consumes_decl"],
9726    ),
9727    dg(
9728        "bynk.target.vendor_required",
9729        "A deployment unit uses a platform-native capability but the build selects another `--platform`.",
9730        &["consumes_decl"],
9731    ),
9732    dg(
9733        "bynk.test.actor_identity_required",
9734        "A test omits the identity an identity-carrying actor requires: a bare call-site `by <Actor>`, or no `by` at all on a handler that binds its `Caller`.",
9735        &["case"],
9736    ),
9737    dg(
9738        "bynk.test.actor_no_identity",
9739        "A call-site `by <Actor>(x)` supplies an identity to an actor that takes none — a unit-identity actor (e.g. `Visitor`) or `Nobody`.",
9740        &["case"],
9741    ),
9742    dg(
9743        "bynk.test.advance_not_clock",
9744        "An `advance` statement names a capability other than `Clock`; the test harness owns one time source, the first-party `Clock`.",
9745        &["advance_stmt"],
9746    ),
9747    dg(
9748        "bynk.test.advance_not_duration",
9749        "An `advance Clock by` statement's amount is not a `Duration`.",
9750        &["advance_stmt"],
9751    ),
9752    dg(
9753        "bynk.test.advance_outside_case",
9754        "An `advance Clock by` statement appears outside a test `case` body; only the test harness has a clock to move.",
9755        &["advance_stmt"],
9756    ),
9757    dg(
9758        "bynk.test.asset_address_method",
9759        "A suite fetches an asset with a method other than `GET`; the platform serves assets to `GET` and answers other methods with 405.",
9760        &["case"],
9761    ),
9762    dg(
9763        "bynk.test.call_needs_in_process",
9764        "A `system`-tier case calls an `on call` service with `svc.call(…)`; an `on call` service is internal to a deployment and has no public route for a `system` case to drive, so the case drives an `http` route that reaches it, or calls it at `unit` or `integration`.",
9765        &["case"],
9766    ),
9767    dg(
9768        "bynk.test.credential_needs_system",
9769        "A case drives `by Nobody` (the no-credential principal, which tests the auth seam's 401) outside a `system`-tier case, where there is no real seam to reject it.",
9770        &["case"],
9771    ),
9772    dg(
9773        "bynk.test.event_needs_in_process",
9774        "A `system`-tier case delivers an event with `svc.event(e)`; at `system` an event reaches a subscriber only through its publisher's fan-out, so the case drives the emitting handler instead, or delivers the event at `unit` or `integration`.",
9775        &["case"],
9776    ),
9777    dg(
9778        "bynk.test.event_not_subscribed",
9779        "A test body's `svc.event(e)` delivers an event the `from Events(E)` service does not subscribe to.",
9780        &["case"],
9781    ),
9782    dg(
9783        "bynk.test.event_publisher_ambiguous",
9784        "A test body's `svc.event(e)` omits the envelope, but the event's publisher, which the default envelope names, is not one context the target declares or consumes.",
9785        &["case"],
9786    ),
9787    dg(
9788        "bynk.test.expired_needs_bearer_route",
9789        "A case drives `by Expired` at an address that is not an http route with a `Bearer` actor (alone, or as a member of an actor sum) or an `Oidc` actor; it sends a correctly signed token whose `exp` has passed, so only a `Bearer` or `Oidc` seam can refuse it.",
9790        &["case"],
9791    ),
9792    dg(
9793        "bynk.test.extra_headers_authorization",
9794        "A `system` case sends `Authorization` as an extra request header to a route that declares no `headers:` parameter; the case's `by <Actor>` owns the credential the driver sends.",
9795        &["case"],
9796    ),
9797    dg(
9798        "bynk.test.faults_needs_in_process",
9799        "A `system`-tier case claims a fault with `expect <call> faults`, or a fault claim at any tier is driven `by Nobody`, `by Forged`, `by Stale`, `by Expired`, `by WrongIssuer`, `by WrongAudience`, `by WrongAlgorithm` or `by NoSubject`; at `system` a fault reaches the case as an error response from the deployed Worker, never a throw, so the claim belongs at `unit` or `integration`.",
9800        &["case"],
9801    ),
9802    dg(
9803        "bynk.test.forged_needs_signature_route",
9804        "A case drives `by Forged` at an address that is not an http route with a `Signature`, `Bearer` or `Oidc` actor, or `by Stale` at one with no `Signature` actor (alone, or as a member of an actor sum); they send a bad credential, so only a `Signature`, `Bearer` or `Oidc` seam can refuse them.",
9805        &["case"],
9806    ),
9807    dg(
9808        "bynk.test.forged_needs_system",
9809        "A case drives `by Forged`, `by Stale`, `by Expired`, `by WrongIssuer`, `by WrongAudience`, `by WrongAlgorithm` or `by NoSubject` outside a `system`-tier case; only the `system` driver signs a request or mints a token, so only there does the real `Signature`, `Bearer` or `Oidc` seam see the bad credential.",
9810        &["case"],
9811    ),
9812    dg(
9813        "bynk.test.no_subject_needs_oidc_route",
9814        "A case drives `by NoSubject` at an address that is not an http route with an `Oidc` actor; it sends correctly signed tokens whose `sub` is empty and whose `sub` is missing, so only an `Oidc` seam can refuse them.",
9815        &["case"],
9816    ),
9817    dg(
9818        "bynk.test.nobody_needs_secured_route",
9819        "A case drives `by Nobody` at a route with no Bearer, `Oidc` or Signature actor (alone, or as a member of an actor sum) (e.g. a public `Visitor` route) — there is no auth seam to reject the missing credential.",
9820        &["case"],
9821    ),
9822    dg(
9823        "bynk.test.peek_not_a_database",
9824        "`D1.peek` names a capability that is not derived from `D1`; only a D1 binding has a test database to read.",
9825        &["case"],
9826    ),
9827    dg(
9828        "bynk.test.peek_not_bound",
9829        "`D1.peek` is used anywhere but as the value of a `let`; the handle is what a case reads through.",
9830        &["case"],
9831    ),
9832    dg(
9833        "bynk.test.peek_outside_case",
9834        "`D1.peek` is used outside an `integration` or `system` case; only those tiers stand up a participant's test database.",
9835        &["case"],
9836    ),
9837    dg(
9838        "bynk.test.peek_unknown_capability",
9839        "`D1.peek` names a participant or a capability that the suite does not have.",
9840        &["case"],
9841    ),
9842    dg(
9843        "bynk.test.peek_write",
9844        "A `D1.peek` handle is asked to write, by a write operation (`run`, `batch`) or by a statement that would write; the handle is read-only.",
9845        &["case"],
9846    ),
9847    d(
9848        "bynk.test.principal_claims_not_oidc",
9849        "A call-site principal passes token claims for an actor that isn't `Oidc`.",
9850    ),
9851    dg(
9852        "bynk.test.principal_identity_mismatch",
9853        "A call-site `by <Actor>` acts as an actor whose identity is incompatible with the addressed handler's actor, or names no member of the handler's actor sum.",
9854        &["case"],
9855    ),
9856    dg(
9857        "bynk.test.principal_on_asset",
9858        "A suite's asset fetch carries a `by` clause; an asset is public and served before the Worker runs.",
9859        &["case"],
9860    ),
9861    dg(
9862        "bynk.test.principal_on_wrong_method",
9863        "A wrong-method `405` test carries a `by <Actor>` clause; it reaches no handler, so a principal is meaningless.",
9864        &["case"],
9865    ),
9866    dg(
9867        "bynk.test.principal_required",
9868        "A test drives an identity-carrying handler, or one guarded by an actor sum, with no call-site `by <Actor>`.",
9869        &["case"],
9870    ),
9871    warn(dg(
9872        "bynk.test.remote_clock_dependent",
9873        "Under `bynk test --against`, a `system` case's `expect` compares an `Instant` that isn't derived from the run (a constant such as `Instant.fromEpochMillis(0)`); in process the clock starts at the epoch, but a real runtime's Workers read wall-clock time.",
9874        &["case"],
9875    )),
9876    dg(
9877        "bynk.test.remote_unsupported_advance",
9878        "A `system` case moves the harness clock with `advance Clock`, which a run against a real runtime (`bynk test --against`) can't honour: the deployed Workers read wall-clock time.",
9879        &["case"],
9880    ),
9881    dg(
9882        "bynk.test.remote_unsupported_asset",
9883        "A `system` case fetches an asset with `svc.GET(asset)`, which a run against a real runtime (`bynk test --against`) can't honour: the fetch is answered in process.",
9884        &["case"],
9885    ),
9886    dg(
9887        "bynk.test.remote_unsupported_call",
9888        "A `system` case addresses an `on call` service, which a run against a real runtime (`bynk test --against`) can't honour: the service is internal, and each call is signed for one caller.",
9889        &["case"],
9890    ),
9891    dg(
9892        "bynk.test.remote_unsupported_env",
9893        "A `system` case's `env` disagrees with the named target it would run against (`bynk test --against`): it sets a secret, sets a name the target doesn't declare under `vars` or declares with another value, or leaves unset a name the target declares.",
9894        &["case"],
9895    ),
9896    dg(
9897        "bynk.test.remote_unsupported_peek",
9898        "A `system` case reads a participant's test database with `D1.peek`, which a run against a real runtime (`bynk test --against`) can't honour: a deployment has no in-process database.",
9899        &["case"],
9900    ),
9901    dg(
9902        "bynk.test.remote_unsupported_queue",
9903        "A `system` case delivers a queue message with `q.message(m)`, which a run against a real runtime (`bynk test --against`) can't honour: no public wire reaches a queue consumer.",
9904        &["case"],
9905    ),
9906    dg(
9907        "bynk.test.remote_unsupported_schedule",
9908        "A `system` case runs a cron handler with `svc.schedule(…)`, which a run against a real runtime (`bynk test --against`) can't honour: no public wire reaches a cron handler.",
9909        &["case"],
9910    ),
9911    dg(
9912        "bynk.test.service_bad_address",
9913        "A test body addresses a service the wrong way for its protocol (e.g. an http route without a leading path string).",
9914        &["case"],
9915    ),
9916    dg(
9917        "bynk.test.service_call_arity",
9918        "A test body's `svc.call(...)` passes the wrong number of arguments for the service's `on call` handler.",
9919        &["case"],
9920    ),
9921    dg(
9922        "bynk.test.service_no_call_handler",
9923        "A test body invokes `svc.call(...)` on a service with no `on call` handler (a `from http`/`cron`/`queue` service).",
9924        &["case"],
9925    ),
9926    dg(
9927        "bynk.test.service_unknown_route",
9928        "A test body addresses an http route / cron schedule / queue message the service does not declare.",
9929        &["case"],
9930    ),
9931    warn(dg(
9932        "bynk.test.smoke_undeclared_status",
9933        "A smoke case (`bynk test --smoke`) gets a non-5xx answer whose status is not among those its route's handler declares; the case still passes (warning).",
9934        &["case"],
9935    )),
9936    dg(
9937        "bynk.test.snapshot_duplicate_name",
9938        "A case takes two snapshots (`expect v matches snapshot \"name\"`) under one name; a snapshot is keyed by its case and name.",
9939        &["snapshot_expr"],
9940    ),
9941    dg(
9942        "bynk.test.snapshot_in_property",
9943        "A `property` takes a snapshot; its body runs once per generated input, so the snapshot belongs in a `case` over a fixed value.",
9944        &["snapshot_expr"],
9945    ),
9946    dg(
9947        "bynk.test.snapshot_name_not_literal",
9948        "`matches snapshot` is not followed by a string literal; a snapshot is named by a literal so the compiler knows every snapshot a suite takes.",
9949        &["snapshot_expr"],
9950    ),
9951    dg(
9952        "bynk.test.snapshot_needs_unit_suite",
9953        "A snapshot is taken in a `system`-tier case or in an integration or system suite; snapshots are stored per unit suite file and compared in the unit harness.",
9954        &["snapshot_expr"],
9955    ),
9956    dg(
9957        "bynk.test.snapshot_not_codable",
9958        "The value of an `expect … matches snapshot` is not `Codable`: a snapshot stores the value's `Json.encode` text, so it must be in the domain `Json.encode` accepts.",
9959        &["snapshot_expr"],
9960    ),
9961    dg(
9962        "bynk.test.stale_needs_timestamp",
9963        "A case drives `by Stale` at a `Signature` route whose actor declares no `timestamp` header and `tolerance`, so there is no replay window for the seam to refuse a stale signature by.",
9964        &["case"],
9965    ),
9966    dg(
9967        "bynk.test.system_claims_need_literal",
9968        "A `system`-tier case passes token claims to a call-site principal other than as a literal `TokenClaims.of([…])`; the driver mints the `Oidc` token's claims from those lines, which a `TokenClaims` value does not expose.",
9969        &["case"],
9970    ),
9971    dg(
9972        "bynk.test.unknown_actor",
9973        "A call-site `by <Actor>` names an actor the target context does not declare and that is not a prelude actor.",
9974        &["case"],
9975    ),
9976    dg(
9977        "bynk.test.wire_http_only",
9978        "A `Wire(...)` raw argument is passed to a queue, cron, `on call` or event address; `Wire` drives an http body or path segment only, so a queue message, cron tick or event is passed as a typed value.",
9979        &["case"],
9980    ),
9981    dg(
9982        "bynk.test.wire_needs_system",
9983        "A `Wire(...)` raw argument is used outside a `system`-tier service address; `Wire` hands pre-validation input to the boundary and is meaningless at `unit` or in any other position.",
9984        &["case"],
9985    ),
9986    dg(
9987        "bynk.test.wrong_algorithm_needs_oidc_route",
9988        "A case drives `by WrongAlgorithm` at an address that is not an http route with an `Oidc` actor; it sends a token with `alg: none` and an `HS256` token keyed with the JWKS public key, so only an `Oidc` seam can refuse them.",
9989        &["case"],
9990    ),
9991    dg(
9992        "bynk.test.wrong_audience_needs_oidc_route",
9993        "A case drives `by WrongAudience` at an address that is not an http route with an `Oidc` actor; it sends a correctly signed token whose `aud` is not the actor's, so only an `Oidc` seam can refuse it.",
9994        &["case"],
9995    ),
9996    dg(
9997        "bynk.test.wrong_issuer_needs_oidc_route",
9998        "A case drives `by WrongIssuer` at an address that is not an http route with an `Oidc` actor; it sends a correctly signed token whose `iss` is not the actor's, so only an `Oidc` seam can refuse it.",
9999        &["case"],
10000    ),
10001    dg(
10002        "bynk.test.ws_lifecycle_by",
10003        "A case's `svc.message(tc, frame)` or `svc.close(tc)` on a `from websocket` service carries a `by` clause; the connection's principal is given once, at `open`, and carried from there.",
10004        &["case"],
10005    ),
10006    dg(
10007        "bynk.test.ws_needs_in_process",
10008        "A `system`-tier case drives a `from websocket` service by address (`svc.open(tc, …)`, `svc.message(tc, frame)`, `svc.close(tc)`); a deployed WebSocket is a real upgrade through the Worker and a Durable Object, which a `system` case does not drive, so the case runs at `unit` or `integration`.",
10009        &["case"],
10010    ),
10011    dg(
10012        "bynk.tier.cross_context_needs_system",
10013        "A `unit` or `integration` case, or a `property`, reaches another context's service, directly or through a target service or agent handler that calls one; below `system` no other context is stood up to call, so the flow belongs in a `suite … as system`.",
10014        &["case"],
10015    ),
10016    dg(
10017        "bynk.tier.mixed_system_suite",
10018        "A suite mixes `system` cases with `unit` or `integration` ones; a `system` case runs against deployed Workers and addresses services by context path, so it needs a `suite … as system` of its own.",
10019        &["case"],
10020    ),
10021    d(
10022        "bynk.tier.system_needs_wire",
10023        "An `as system` suite whose target has no serialisation edge: it consumes no other context and exposes no `http`, `queue` or `email` service, so there is no wire for a `system` case to cross.",
10024    ),
10025    d(
10026        "bynk.transition.cross_agent_reference",
10027        "A transition predicate references another agent; step invariants are per-agent.",
10028    ),
10029    d(
10030        "bynk.transition.duplicate_name",
10031        "An agent declares two transitions with the same name.",
10032    ),
10033    d(
10034        "bynk.transition.impure_predicate",
10035        "A transition predicate uses an effectful or test-only construct; a step invariant must be pure.",
10036    ),
10037    warn(d(
10038        "bynk.transition.may_violate",
10039        "A handler can make a move that an agent's `transition` refuses, from a state the agent can be in after a commit; at run time that call faults with `InvariantViolation` (warning). Resolve it in code: refuse the move first, with a `match` arm or an `is` test on the state field that the path can't get past.",
10040    )),
10041    d(
10042        "bynk.transition.no_step_reference",
10043        "A transition references neither `old` nor `new`; it constrains one state, so it is an `invariant`, not a step.",
10044    ),
10045    d(
10046        "bynk.transition.not_bool",
10047        "A transition predicate does not have type `Bool`.",
10048    ),
10049    dg(
10050        "bynk.types.argument_mismatch",
10051        "A call, method, capability, or constructor argument has the wrong type.",
10052        &["call"],
10053    ),
10054    d(
10055        "bynk.types.asset_at_boundary",
10056        "An `Asset` type appears in a record field, boundary or store position; pass its `.url` instead.",
10057    ),
10058    d(
10059        "bynk.types.bad_field_default",
10060        "A record or event field's default expression (`field: T = expr`) is not a static, wire-representable value of the field's declared type — a literal (including one admitted to a refined type), a sum variant of a type this context may construct (not a `uses`-sourced commons sum, which is `bynk.context.rebrand_construction`), `Some`/`None`/`Ok`/`Err`, a record, a list literal, `Map.empty()`/`Set.empty()`, or `T.unsafe(lit)` for an opaque type whose literal also satisfies the refinement. A field whose type is a generic record's type parameter has no default, and a default may not hold for one instantiation only: for a record field that applies a user generic (`Page[String]`, or `Page[T]` inside a generic record; an event or old-state field may not) it is a closed-form value at the instantiated type, writing nothing of the enclosing record's own type parameters. (Earlier versions reported this as `bynk.event.bad_field_default`.)",
10061    ),
10062    dg(
10063        "bynk.types.call_arity",
10064        "A function value, a built-in `Map`/`Set`/`Cell`/`Cache`/`Log` operation, or `unreachable`/`todo` was called with the wrong number of arguments (a declared `fn` is `bynk.resolve.arity_mismatch`).",
10065        &["call"],
10066    ),
10067    dg(
10068        "bynk.types.cannot_infer_option_type_param",
10069        "The value type of `None` could not be inferred.",
10070        &["none_expr"],
10071    ),
10072    d(
10073        "bynk.types.cannot_infer_result_type_params",
10074        "The type parameters of a `Result` could not be inferred.",
10075    ),
10076    dg(
10077        "bynk.types.catastrophic_regex",
10078        "A `Matches` pattern, or a regex method's pattern, can match the same text in exponentially many ways (nested or ambiguous repetition, bounded or not), or cannot be analysed, risking catastrophic backtracking (ReDoS).",
10079        &["refinement"],
10080    ),
10081    d(
10082        "bynk.types.claims_at_boundary",
10083        "`TokenClaims` appears where a value is stored or sent: a field of a type, or a boundary such as a call, a message or an agent.",
10084    ),
10085    dg(
10086        "bynk.types.combinator_return_mismatch",
10087        "A callback passed to a combinator (`map`/`andThen`/`flatMap`/`traverseAll`/…) returns the wrong type.",
10088        &["call"],
10089    ),
10090    d(
10091        "bynk.types.constructor_arity",
10092        "`T.of` (or `T.unsafe`) on a refined or opaque type got the wrong number of arguments.",
10093    ),
10094    d(
10095        "bynk.types.constructor_base_mismatch",
10096        "A `.of` constructor was given an argument of the wrong base type.",
10097    ),
10098    d(
10099        "bynk.types.decimal_division_unscaled",
10100        "`/` was used on `Decimal` operands. A quotient has no exact decimal answer, so division states its scale and rounding mode: `a.div(b, 2, RoundingMode.HalfEven)` (#2622).",
10101    ),
10102    d(
10103        "bynk.types.decimal_negation_too_large",
10104        "A negated decimal literal would have more than 1000 characters of canonical text once its sign is counted, the most any `Decimal` may have (#2622).",
10105    ),
10106    warn(d(
10107        "bynk.types.deprecated_json_error",
10108        "`JsonError` is the deprecated spelling of `DecodeError` (warning; auto-fixable).",
10109    )),
10110    dg(
10111        "bynk.types.derives_automatic",
10112        "A `derives` clause names `Eq`, `Key` or `Codable`, which hold for a type automatically; only `Ord` is opted into. The diagnostic carries a machine-applicable fix that removes the name (constrained-generics slice 1).",
10113        &["type_decl"],
10114    ),
10115    dg(
10116        "bynk.types.derives_field_not_orderable",
10117        "A type declares `derives Ord`, but one of its fields or payloads is not `Ord` (for example a `Map`, a `Set`, a `Bool`, a function, or a record that does not itself derive `Ord`); every part must be orderable for the declaration order to be a total order (constrained-generics slice 1).",
10118        &["type_decl"],
10119    ),
10120    dg(
10121        "bynk.types.duplicate_example",
10122        "A refinement carries more than one `@example`.",
10123        &["refinement"],
10124    ),
10125    dg(
10126        "bynk.types.duplicate_literal_arm",
10127        "A `match` has two arms for the same literal value.",
10128        &["match_arm"],
10129    ),
10130    dg(
10131        "bynk.types.duplicate_pattern_field",
10132        "A record pattern lists the same field twice.",
10133        &["record_pattern"],
10134    ),
10135    dg(
10136        "bynk.types.duplicate_variant_arm",
10137        "A `match` has two arms for the same variant.",
10138        &["match_arm"],
10139    ),
10140    d(
10141        "bynk.types.embeds_ambiguous",
10142        "A type is embedded by more than one variant of a sum, so `?`'s conversion would be ambiguous.",
10143    ),
10144    d(
10145        "bynk.types.embeds_unknown_variant",
10146        "An `embeds … as V` clause names a variant the sum does not declare.",
10147    ),
10148    d(
10149        "bynk.types.embeds_variant_shape",
10150        "An `embeds E as V` target variant must have exactly one payload field, of type `E`.",
10151    ),
10152    dg(
10153        "bynk.types.empty_range_pattern",
10154        "A range pattern or `via schema(...)` range has its bounds inverted (`lo > hi`), so it can never match.",
10155        &["int_range"],
10156    ),
10157    dg(
10158        "bynk.types.empty_refinement",
10159        "A refinement admits no values (contradictory predicates).",
10160        &["refinement"],
10161    ),
10162    dg(
10163        "bynk.types.err_value_mismatch",
10164        "An `Err` payload has the wrong type.",
10165        &["err_expr"],
10166    ),
10167    dg(
10168        "bynk.types.example_not_literal",
10169        "An `@example` is not exactly one literal of the base type.",
10170        &["refinement"],
10171    ),
10172    dg(
10173        "bynk.types.example_on_named_field",
10174        "An `@example` on a field whose type is a named type (it belongs on the named type).",
10175        &["refinement"],
10176    ),
10177    dg(
10178        "bynk.types.example_unneeded",
10179        "An `@example` on a refinement `Val` can already generate (only `Matches` and `IsoDate` take one).",
10180        &["refinement"],
10181    ),
10182    dg(
10183        "bynk.types.example_violates",
10184        "An `@example` does not satisfy its refinement's predicates.",
10185        &["refinement"],
10186    ),
10187    d(
10188        "bynk.types.extensible_match_needs_wildcard",
10189        "A `match` covers an extensible standard-library enum (`FetchError`, `Method`) without a wildcard; it may gain variants in a minor release.",
10190    ),
10191    dg(
10192        "bynk.types.field_access_on_non_record",
10193        "Field access on a value that is not a record.",
10194        &["field_access"],
10195    ),
10196    dg(
10197        "bynk.types.field_annotation_unknown",
10198        "A record field carries an annotation other than `@name(\"…\")`.",
10199        &["record_field"],
10200    ),
10201    d(
10202        "bynk.types.field_default_on_variant",
10203        "A sum variant's payload field declares a default (`field: T = expr`). Only a record's fields may; a variant is built like a call, with every payload field given.",
10204    ),
10205    dg(
10206        "bynk.types.field_name_bad_arg",
10207        "A field's `@name` does not take exactly one string literal, or a `String` constant bound to one.",
10208        &["record_field"],
10209    ),
10210    dg(
10211        "bynk.types.field_name_case_conflict",
10212        "Two fields of a `cookies` or `query` record have wire names that differ only in case.",
10213        &["record_field"],
10214    ),
10215    dg(
10216        "bynk.types.field_name_duplicate",
10217        "A field has more than one `@name`, or two fields of a request record read the same wire name.",
10218        &["record_field"],
10219    ),
10220    dg(
10221        "bynk.types.field_name_invalid",
10222        "A field's `@name` is not a valid name for where the record is read (a cookie name that is not a token, or an empty name).",
10223        &["record_field"],
10224    ),
10225    dg(
10226        "bynk.types.field_name_not_request_record",
10227        "`@name` is on a field of a record that is not the `cookies`, `query` or `@form`/`@multipart` `body` record of an HTTP handler.",
10228        &["record_field"],
10229    ),
10230    dg(
10231        "bynk.types.field_name_record_not_boundary",
10232        "A record with `@name` fields is used as a JSON body, a result, a store field, an event or a call argument.",
10233        &["record_field"],
10234    ),
10235    dg(
10236        "bynk.types.field_refinement_not_base",
10237        "An inline field refinement requires a base or refined type.",
10238        &["record_field"],
10239    ),
10240    dg(
10241        "bynk.types.field_value_mismatch",
10242        "A record field was given a value of the wrong type.",
10243        &["record_construction"],
10244    ),
10245    d(
10246        "bynk.types.file_at_boundary",
10247        "A `File` (a file part of a multipart request), or a type carrying one, is used where it would be persisted, sent across a boundary or returned.",
10248    ),
10249    d(
10250        "bynk.types.form_uncodable",
10251        "`Form.decode` or `Form.encode` names a type that is not a record of form fields (a `String`, `Int`, `Bool`, `Decimal`, an enum, or a refined or opaque type over one, optionally in an `Option` or a `List`).",
10252    ),
10253    dg(
10254        "bynk.types.function_at_boundary",
10255        "A function type appeared in a serialisable or boundary position (a record field, sum payload, service/agent handler signature, capability operation signature, agent state field, or agent key); functions cannot serialise or cross a boundary.",
10256        &["function_type_ref"],
10257    ),
10258    dg(
10259        "bynk.types.guard_not_bool",
10260        "A match-arm `if` guard is not a `Bool` expression.",
10261        &["match_arm"],
10262    ),
10263    d(
10264        "bynk.types.headers_at_boundary",
10265        "`RequestHeaders` appears where a value is stored or sent: a field of a type, or a boundary such as a call, a message or an agent.",
10266    ),
10267    d(
10268        "bynk.types.held_at_boundary",
10269        "A held value (`Connection[F]`) appears in a serialisable or boundary position — a held resource is built and disposed in place, never persisted or sent across a boundary (§2.9, real-time track slice 2).",
10270    ),
10271    d(
10272        "bynk.types.held_not_comparable",
10273        "A held value (`Connection[F]`) is compared with `==`/`!=` — held values have identity, not value-equality (§2.9.3, real-time track slice 2).",
10274    ),
10275    dg(
10276        "bynk.types.if_branch_mismatch",
10277        "The branches of an `if` have different types.",
10278        &["if_expr"],
10279    ),
10280    dg(
10281        "bynk.types.if_non_bool_cond",
10282        "An `if` condition is not a `Bool`.",
10283        &["if_expr"],
10284    ),
10285    dg(
10286        "bynk.types.if_without_else_requires_unit",
10287        "An `if` with no `else` branch has a non-unit then-branch; the missing else defaults to `()`, so the branch must be `()` or `Effect[()]`.",
10288        &["if_expr"],
10289    ),
10290    d(
10291        "bynk.types.interpolation_non_scalar",
10292        "An interpolation hole holds a value with no string form.",
10293    ),
10294    dg(
10295        "bynk.types.invalid_regex",
10296        "A `Matches` predicate, or a regex method's pattern (`containsRegex`, …), contains an invalid regular expression or malformed inline flags.",
10297        &["refinement"],
10298    ),
10299    dg(
10300        "bynk.types.inverted_range",
10301        "An `InRange` predicate has its bounds inverted.",
10302        &["refinement"],
10303    ),
10304    dg(
10305        "bynk.types.is_base_mismatch",
10306        "An `is` refinement check is applied to a value of the wrong base type.",
10307        &["is_expr"],
10308    ),
10309    dg(
10310        "bynk.types.is_literal_pattern",
10311        "A literal was used on the right of `is`; `is` tests type/refinement, not value equality (use `==`).",
10312        &["is_expr"],
10313    ),
10314    dg(
10315        "bynk.types.is_non_sum",
10316        "`is` was applied to a value that is not a sum type.",
10317        &["is_expr"],
10318    ),
10319    dg(
10320        "bynk.types.is_range_pattern",
10321        "A range pattern was used directly on the right of `is`; `is` tests type/refinement, not value ranges (use `match`, a guard or `InRange`).",
10322        &["is_expr"],
10323    ),
10324    dg(
10325        "bynk.types.is_refined_pattern",
10326        "A refined (`where`) pattern was used on the right of `is`; refined patterns are `match`-only.",
10327        &["is_expr"],
10328    ),
10329    dg(
10330        "bynk.types.is_unknown_variant",
10331        "`is` names a variant the type does not have.",
10332        &["is_expr"],
10333    ),
10334    dg(
10335        "bynk.types.json_uncodable",
10336        "A `Json.encode`/`Json.decode` target type cannot pass through the typed JSON codec (functions, effects, streams or a type that carries one, `bynk.crypto` keys, error builtins).",
10337        &["method_call"],
10338    ),
10339    d(
10340        "bynk.types.key_at_boundary",
10341        "A `bynk.crypto` `SigningKey` or `VerifyKey` appears in a storable or boundary-crossing position — a key is held non-extractable and lives for the call that imported it, never persisted, logged or sent (standard-library K4).",
10342    ),
10343    dg(
10344        "bynk.types.key_not_orderable",
10345        "A `sortBy`/`sortByDescending`/`min`/`max` key function does not return an orderable type. The key must be an `Ord` type, on a `List` and on a storage `Query` alike.",
10346        &[],
10347    ),
10348    dg(
10349        "bynk.types.lambda_mismatch",
10350        "A lambda's parameter count, parameter annotations, or body type do not match the expected function type.",
10351        &["lambda_expr"],
10352    ),
10353    dg(
10354        "bynk.types.let_annotation_mismatch",
10355        "A `let` value does not match its type annotation.",
10356        &["let_stmt"],
10357    ),
10358    dg(
10359        "bynk.types.list_element_mismatch",
10360        "A list-literal element has a different type from the list's element type.",
10361        &["list_literal"],
10362    ),
10363    dg(
10364        "bynk.types.list_pattern_on_non_list",
10365        "A list pattern is matched against a value that is not a `List` (a record, sum, base type, `Set` or `Map`).",
10366        &["list_pattern"],
10367    ),
10368    dg(
10369        "bynk.types.match_arm_mismatch",
10370        "A `match` arm has a different type from the others.",
10371        &["match_arm"],
10372    ),
10373    dg(
10374        "bynk.types.match_non_sum_discriminant",
10375        "`match` was applied to a value that is not a sum type.",
10376        &["match_expr"],
10377    ),
10378    dg(
10379        "bynk.types.method_arity",
10380        "A method was called with the wrong number of arguments.",
10381        &["method_call"],
10382    ),
10383    dg(
10384        "bynk.types.method_not_found",
10385        "Called a method the type does not have.",
10386        &["method_call"],
10387    ),
10388    dg(
10389        "bynk.types.method_on_non_named_type",
10390        "A method was called on a built-in type that has no methods.",
10391        &["method_call"],
10392    ),
10393    dg(
10394        "bynk.types.mixed_pattern_bindings",
10395        "A pattern mixes named and positional bindings.",
10396        &["variant_pattern"],
10397    ),
10398    dg(
10399        "bynk.types.negative_length",
10400        "A length predicate was given a negative value.",
10401        &["refinement"],
10402    ),
10403    dg(
10404        "bynk.types.never_inferred",
10405        "An unannotated `let` or `<-` binding has a type that is, or contains, the bottom type (`never returns`) because its value only faults (a faulting lambda bound this way included); the type cannot be written in source, so an annotation is needed.",
10406        &["let_stmt"],
10407    ),
10408    dg(
10409        "bynk.types.no_numeric_coercion",
10410        "`Int`, `Float` and `Decimal` were mixed without an explicit conversion — in an operation, a comparison or refinement bounds.",
10411        &["binary_expr", "refinement"],
10412    ),
10413    dg(
10414        "bynk.types.non_exhaustive_match",
10415        "A `match` does not cover every value.",
10416        &["match_expr"],
10417    ),
10418    d(
10419        "bynk.types.not_codable",
10420        "A type is instantiated at a `Codable`-bounded parameter (of a generic function, or of a capability operation) but is outside the domain `Json.decode` accepts: top-level `()`, a function, `Effect`, `Query`, a `Stream` or a type that carries one, a connection, the HTTP and queue result types, `Asset`, request headers, token claims, or an actor (constrained-generics slice 3).",
10421    ),
10422    d(
10423        "bynk.types.not_comparable",
10424        "A value compared with `==`/`!=` contains a function, `Effect`, or `Query` somewhere inside it — those have no value equality, so the type is not equality-supporting (type-system §2.3.5, #1652).",
10425    ),
10426    dg(
10427        "bynk.types.not_keyable",
10428        "A `Map` key, `Set` element, or `distinct`/`distinctBy`/`groupBy`/join key, or an argument to a `Key`-bounded parameter, is not `Key`. `String`, `Int`, `Bool`, `Instant`, `Duration`, `Bytes`, `Option`/`List` of a key type, refined and opaque types over them, and records, sums and enums made only of key types are; a `Float` is never one, at any depth, because `NaN` is not equal to itself (constrained-generics slice 2).",
10429        &["generic_type_ref"],
10430    ),
10431    d(
10432        "bynk.types.not_orderable",
10433        "A value is ordered (`<`, `<=`, `>`, `>=`), or passed to an `Ord`-bounded parameter, but its type is not `Ord`. `Int`, `Float`, `String`, `Duration`, `Instant`, `Bytes`, `Option`/`List` of an orderable type, refined types over those, and types that declare `derives Ord` are; adding `derives Ord` is offered as a fix that is never applied automatically, because it makes declaration order significant (constrained-generics slice 1).",
10434    ),
10435    dg(
10436        "bynk.types.ok_value_mismatch",
10437        "An `Ok` payload has the wrong type.",
10438        &["ok_expr"],
10439    ),
10440    dg(
10441        "bynk.types.opaque_raw_outside",
10442        "`.raw` on an opaque type was used outside its defining commons.",
10443        &["field_access"],
10444    ),
10445    dg(
10446        "bynk.types.opaque_unsafe_outside",
10447        "`.unsafe` on an opaque type was used outside its defining context.",
10448        &["field_access"],
10449    ),
10450    dg(
10451        "bynk.types.or_pattern_binding_mismatch",
10452        "An or-pattern's alternatives don't all bind the same set of names.",
10453        &["match_arm", "is_expr"],
10454    ),
10455    dg(
10456        "bynk.types.or_pattern_type_mismatch",
10457        "An or-pattern's alternatives give a shared binding different types (or refinements).",
10458        &["match_arm", "is_expr"],
10459    ),
10460    dg(
10461        "bynk.types.pattern_arity",
10462        "A pattern binds the wrong number of payload fields.",
10463        &["variant_pattern"],
10464    ),
10465    dg(
10466        "bynk.types.pattern_type_mismatch",
10467        "A pattern's type does not match the matched value.",
10468        &["variant_pattern"],
10469    ),
10470    dg(
10471        "bynk.types.polynomial_regex",
10472        "A `Matches` pattern can split the same text between repetitions, so matching time grows polynomially with input length, and no length predicate bounds the input small enough for its degree; a regex method's pattern has no bound to excuse it.",
10473        &["refinement"],
10474    ),
10475    warn(dg(
10476        "bynk.types.polynomial_regex_capped",
10477        "A `Matches` pattern's matching time grows polynomially with input length, but a `MaxLength` or `Length` predicate bounds the input small enough for its degree (warning).",
10478        &["refinement"],
10479    )),
10480    dg(
10481        "bynk.types.predicate_base_mismatch",
10482        "A predicate does not apply to the type's base (e.g. a string predicate on an `Int`).",
10483        &["refinement"],
10484    ),
10485    d(
10486        "bynk.types.query_at_boundary",
10487        "A `Query` type appears in a storable or boundary-crossing position — a query is built and executed in place, never persisted or sent (ADR 0115).",
10488    ),
10489    dg(
10490        "bynk.types.question_error_mismatch",
10491        "`?` propagates an error type incompatible with the function's.",
10492        &["question_expr"],
10493    ),
10494    dg(
10495        "bynk.types.question_on_non_result",
10496        "`?` was applied to a non-`Result` value.",
10497        &["question_expr"],
10498    ),
10499    dg(
10500        "bynk.types.question_option_outside_http",
10501        "`?` lifts an `Option` only inside a handler returning `HttpResult` (`None` becomes `NotFound`); elsewhere use `.okOr(err)`.",
10502        &["question_expr"],
10503    ),
10504    dg(
10505        "bynk.types.question_outside_result",
10506        "`?` used in a function that does not return a `Result`.",
10507        &["question_expr"],
10508    ),
10509    dg(
10510        "bynk.types.range_pattern_on_non_int",
10511        "A range pattern (`lo..hi`) was matched against a scrutinee that is not an `Int`.",
10512        &["int_range"],
10513    ),
10514    dg(
10515        "bynk.types.record_pattern_on_non_record",
10516        "A record pattern names a type that is not a record (a sum, enum, refined or opaque type, or a built-in).",
10517        &["record_pattern"],
10518    ),
10519    dg(
10520        "bynk.types.regex_not_literal",
10521        "A regex method's pattern (`matchesRegex`, `containsRegex`, `findRegex`, `findAllRegex`, `replaceRegex`, `splitRegex`) is not a string literal, so its ReDoS check cannot run at compile time.",
10522        &["method_call"],
10523    ),
10524    d(
10525        "bynk.types.rejection_at_boundary",
10526        "`BoundaryRejection` appears where a value is stored or sent: a field of a type, or a boundary such as a call, a message or an agent.",
10527    ),
10528    d(
10529        "bynk.types.request_cookies_at_boundary",
10530        "`RequestCookies` appears where a value is stored or sent: a field of a type, or a boundary such as a call, a message or an agent.",
10531    ),
10532    d(
10533        "bynk.types.request_query_at_boundary",
10534        "`RequestQuery` appears where a value is stored or sent: a field of a type, or a boundary such as a call, a message or an agent.",
10535    ),
10536    d(
10537        "bynk.types.return_mismatch",
10538        "A returned value does not match the declared return type.",
10539    ),
10540    d(
10541        "bynk.types.rounding_mode_position",
10542        "`RoundingMode.<mode>` was used outside the mode argument of a `Decimal`'s `round` or `div`. A mode is read where the rounding happens and is not a first-class value (#2622).",
10543    ),
10544    dg(
10545        "bynk.types.select_tail_has_select",
10546        "A `D1`, `Postgres` or `MySql` `select[T]` or `firstAs[T]` statement does not start at `FROM` (for example it begins with `SELECT`, `WITH` or a parenthesis); the compiler writes the `SELECT` and column list from `T`.",
10547        &["method_call"],
10548    ),
10549    dg(
10550        "bynk.types.sequence_needs_result",
10551        "`sequenceAll`/`sequenceTry` was called on a list whose elements are not `Result`s. They collect a `List[Result[T, E]]`.",
10552        &["method_call"],
10553    ),
10554    dg(
10555        "bynk.types.some_value_mismatch",
10556        "A `Some` payload has the wrong type.",
10557        &["some_expr"],
10558    ),
10559    dg(
10560        "bynk.types.sql_not_literal",
10561        "A `D1` or `Postgres` statement's SQL (the first argument of `all`, `first`, `run`, `select` or `firstAs`, or the `sql` of a `SqlStatement` or a `PgStatement`) is neither a string literal nor a bare reference to a `String` constant bound to one, so data could be spliced into it instead of bound as a `SqlValue` or `PgValue` parameter (standard-library P4c, Hyperdrive H1 and H3).",
10562        &["method_call", "record_construction", "record_spread"],
10563    ),
10564    dg(
10565        "bynk.types.sql_row_shape",
10566        "`Json.decodeSql[T]`'s (or `select[T]`'s, `firstAs[T]`'s) `T` is not a SQL row: a record whose fields are `Int`, `Float`, `String`, `Bool` or `Bytes` (or a refined or opaque type over one, or an `Option` of either), or a `List` of such records (standard-library P4c). A `Postgres` row may also hold a `Decimal` or an `Instant` (Hyperdrive H3).",
10567        &["method_call"],
10568    ),
10569    d(
10570        "bynk.types.sql_statement_at_boundary",
10571        "A `bynk.cloudflare` `SqlStatement`, `PgStatement` or `MySqlStatement` appears in a storable or boundary-crossing position, or as a `Json` codec target — a statement from outside would carry SQL that was never a literal (standard-library P4c).",
10572    ),
10573    d(
10574        "bynk.types.stream_at_boundary",
10575        "A `Stream` type, or a record or sum carrying one in a field, appears in a storable or boundary-crossing position — a stream is a live value-over-time source, never persisted or sent across a boundary (real-time track slice 0; #2623 admits it in capability signatures and record fields).",
10576    ),
10577    d(
10578        "bynk.types.stream_not_comparable",
10579        "A `Stream` value is compared with `==`/`!=` — a stream is a live value-over-time source, not a comparable value (real-time track slice 0).",
10580    ),
10581    d(
10582        "bynk.types.type_mismatch",
10583        "An operator or built-in method got an operand of a type it does not accept, or two operands that had to match did not.",
10584    ),
10585    dg(
10586        "bynk.types.uninferable_element_type",
10587        "An empty `[]` (or `List.empty()` / `Map.empty()`) has no expected type to infer its element type from.",
10588        &["list_literal"],
10589    ),
10590    dg(
10591        "bynk.types.unknown_annotation",
10592        "An annotation after a refinement is not `@example`.",
10593        &["refinement"],
10594    ),
10595    dg(
10596        "bynk.types.unknown_field",
10597        "Referenced a field the record type does not declare.",
10598        &["field_access"],
10599    ),
10600    dg(
10601        "bynk.types.unknown_pattern_field",
10602        "A pattern names a field the variant does not have.",
10603        &["variant_pattern"],
10604    ),
10605    d(
10606        "bynk.types.unknown_rounding_mode",
10607        "A `Decimal` `round` or `div` was not given a rounding mode written `RoundingMode.<mode>`; the modes are `Down`, `Up`, `Floor`, `Ceiling`, `HalfUp`, `HalfDown` and `HalfEven` (#2622).",
10608    ),
10609    dg(
10610        "bynk.types.unknown_static_member",
10611        "A name after `HttpResult.` that is not one of its variants. An unknown member of a type you declared is `bynk.resolve.unknown_static_member`.",
10612        &["field_access"],
10613    ),
10614    dg(
10615        "bynk.types.unknown_variant_in_pattern",
10616        "A pattern names a variant the sum type does not have.",
10617        &["variant_pattern"],
10618    ),
10619    dg(
10620        "bynk.types.unreachable_arm",
10621        "A `match` arm is unreachable.",
10622        &["match_arm"],
10623    ),
10624    d(
10625        "bynk.types.variant_arity",
10626        "A variant constructor got the wrong number of arguments for its payload fields (a pattern with the wrong number of bindings is `bynk.types.pattern_arity`).",
10627    ),
10628    d(
10629        "bynk.types.variant_missing_payload",
10630        "A variant requiring a payload was used without one.",
10631    ),
10632    d(
10633        "bynk.types.variant_payload_mismatch",
10634        "A variant payload has the wrong type.",
10635    ),
10636    dg(
10637        "bynk.uses.name_conflict",
10638        "Two commons a unit `uses` declare the same type, function, constant, asset or embed; or a value crosses between a unit's code and an imported declaration's position whose type the unit shadows; or a reference names an import the unit's own declaration shadows.",
10639        &["uses_decl"],
10640    ),
10641    dg(
10642        "bynk.uses.self_reference",
10643        "A commons `uses` itself.",
10644        &["uses_decl"],
10645    ),
10646    dg(
10647        "bynk.uses.target_is_context",
10648        "`uses` targets a context instead of a commons.",
10649        &["uses_decl"],
10650    ),
10651    dg(
10652        "bynk.uses.unknown_commons",
10653        "`uses` names a commons that does not exist.",
10654        &["uses_decl"],
10655    ),
10656    dg(
10657        "bynk.val.agent_not_generable",
10658        "A `for all`/`Val` cannot generate an agent — fabricated agent states need not be reachable.",
10659        &["for_all"],
10660    ),
10661    dg(
10662        "bynk.val.arity",
10663        "`Val[T]` was given the wrong number of pin arguments.",
10664        &["val_expr"],
10665    ),
10666    dg(
10667        "bynk.val.generic_type",
10668        "A `Val[…]` fabricates a value of a generic type; per-instantiation value fabrication is not yet wired (ADR 0197). The type itself may cross a boundary through its monomorphised codec (v0.174). Named `bynk.generics.generic_record_at_boundary` before #3379.",
10669        &["val_expr"],
10670    ),
10671    dg(
10672        "bynk.val.literal_violates",
10673        "A pinned `Val[T]` value violates the type's refinement.",
10674        &["val_expr"],
10675    ),
10676    dg(
10677        "bynk.val.needs_pin",
10678        "A bare `Val[T]` cannot generate a value (e.g. a `Matches` string); pin one.",
10679        &["val_expr"],
10680    ),
10681    dg(
10682        "bynk.val.outside_test",
10683        "`Val[T]` was used outside a test case body.",
10684        &["val_expr"],
10685    ),
10686    dg(
10687        "bynk.val.pin_not_literal",
10688        "A `Val[T]` pin argument is not a compile-time literal.",
10689        &["val_expr"],
10690    ),
10691    dg(
10692        "bynk.val.pin_unsupported",
10693        "A pin was given for a type kind that does not support pinning.",
10694        &["val_expr"],
10695    ),
10696    dg(
10697        "bynk.val.unknown_type",
10698        "`Val[T]` names a type that does not resolve.",
10699        &["val_expr"],
10700    ),
10701    dg(
10702        "bynk.val.unsupported_kind",
10703        "`Val[T]` cannot fabricate a value for this kind of type.",
10704        &["val_expr"],
10705    ),
10706    dg(
10707        "bynk.visibility.private_in_public",
10708        "A public declaration's signature names a `private` type of its own unit, which an importer could neither name nor build.",
10709        &["visibility_modifier"],
10710    ),
10711    dg(
10712        "bynk.visibility.private_item",
10713        "A reference from another unit names a `private` declaration, which is visible only within its own unit and that unit's suites.",
10714        &["visibility_modifier"],
10715    ),
10716    warn(dg(
10717        "bynk.visibility.private_messages",
10718        "A `messages` block in a commons is `private`. A bundle whose `@reference` block is private is never negotiated by a context that uses the commons, and `private` on another block of a bundle whose reference is public has no effect (warning).",
10719        &["visibility_modifier"],
10720    )),
10721    dg(
10722        "bynk.visibility.private_not_allowed",
10723        "`private` modifies a declaration it does not apply to: anything but a `fn`, `type`, `messages`, `asset`, `embed` or `const` in a commons or context.",
10724        &["visibility_modifier"],
10725    ),
10726    d(
10727        "bynk.wasm.panic",
10728        "The in-browser compiler panicked internally (a compiler bug, reported as a diagnostic instead of crashing the page).",
10729    ),
10730    d(
10731        "bynk.wasm.strip_failed",
10732        "The in-browser compiler could not strip the emitted TypeScript to JavaScript.",
10733    ),
10734    dg(
10735        "bynk.within.in_agent_handler",
10736        "`e.within(d)` was used in an agent handler, which has no execution context to hand the abandoned effect to.",
10737        &["method_call"],
10738    ),
10739    dg(
10740        "bynk.within.in_pure_context",
10741        "`e.within(d)` was used in a pure (non-effectful) context.",
10742        &["method_call"],
10743    ),
10744    dg(
10745        "bynk.within.outside_handler",
10746        "`e.within(d)` was used outside a service handler's body and outside a function (in a provider operation, a WebSocket handler or a test `case` body), where no execution context exists.",
10747        &["method_call"],
10748    ),
10749    dg(
10750        "bynk.within.timed_out_not_in_scope",
10751        "`e.within(d)` yields `Result[_, TimedOut]`, but the unit does not consume `bynk`, so `TimedOut` is not in scope.",
10752        &["method_call"],
10753    ),
10754    d(
10755        "bynk.ws.lifecycle_by_mismatch",
10756        "A WebSocket `on message`/`on close` handler's `by` clause does not name the same actor(s) as `on open`'s — the connection's principal is verified once, at `on open`, and carried for its life, so the lifecycle handlers must be the same single actor or the same actor-sum members (binder names may differ).",
10757    ),
10758    d(
10759        "bynk.ws.message_frame_param",
10760        "A WebSocket `on message` handler does not have exactly one parameter of the service's inbound (`in:`) frame type — the decoded frame (real-time track slice 3b-iii).",
10761    ),
10762    d(
10763        "bynk.ws.open_given_unsupported",
10764        "A WebSocket `on open` handler declares `given` capabilities — unsupported at v1, since on Workers the handler runs inside the connection-hosting Durable Object, which has no composition root to supply them (real-time track slice 3b).",
10765    ),
10766    d(
10767        "bynk.ws.open_transfer_cross_file",
10768        "On the Workers target, a WebSocket `on open` handler transfers its `connection` to an agent declared in a different file of the same context — the open is hosted in the agent's Durable Object, which is emitted from the agent's own file, so the upgrade would never be handled; the service and the agent must share a file.",
10769    ),
10770    d(
10771        "bynk.ws.open_transfer_key",
10772        "On the Workers target, the key of a WebSocket `on open` handler's connection transfer is not a route parameter, a constant of the context or of a commons it uses, or a literal — the upgrade is routed to the hosting Durable Object before the body runs, so the edge must be able to evaluate the key on its own.",
10773    ),
10774    d(
10775        "bynk.ws.open_transfer_shape",
10776        "A WebSocket `on open` handler does not transfer its `connection` into exactly one agent, so the Workers upgrade has no single Durable Object to route to (real-time track slice 3b).",
10777    ),
10778    d(
10779        "bynk.ws.route_param_mismatch",
10780        "A WebSocket `on message`/`on close` route parameter does not match the `on open` parameter at the same position — route values are recovered positionally from the connection, so they must be a type-compatible prefix of the `on open` parameters (real-time track slice 3b-iii).",
10781    ),
10782];
10783
10784/// A diagnostic with no single governing grammar construct. `Error` severity.
10785const fn d(code: &'static str, summary: &'static str) -> DiagnosticInfo {
10786    DiagnosticInfo {
10787        code,
10788        summary,
10789        grammar_symbol: &[],
10790        severity: Severity::Error,
10791    }
10792}
10793
10794/// A diagnostic that constrains one or more grammar productions. `Error` severity.
10795const fn dg(
10796    code: &'static str,
10797    summary: &'static str,
10798    grammar_symbol: &'static [&'static str],
10799) -> DiagnosticInfo {
10800    DiagnosticInfo {
10801        code,
10802        summary,
10803        grammar_symbol,
10804        severity: Severity::Error,
10805    }
10806}
10807
10808/// Downgrades a [`d`]/[`dg`]-built entry to `Warning` severity (ADR 0117) —
10809/// non-failing, surfaced alongside a clean build. Its call sites here are
10810/// the single source of truth [`crate::error::Severity::for_error`] reads.
10811const fn warn(mut info: DiagnosticInfo) -> DiagnosticInfo {
10812    info.severity = Severity::Warning;
10813    info
10814}
10815
10816/// Downgrades a [`d`]/[`dg`]-built entry to `Hint` severity (#2838) — a
10817/// non-failing suggestion shown by the editor but not by the terminal.
10818const fn hint(mut info: DiagnosticInfo) -> DiagnosticInfo {
10819    info.severity = Severity::Hint;
10820    info
10821}
10822
10823/// The category segment of a code (the part between the first two dots), e.g.
10824/// `"types"` for `"bynk.types.type_mismatch"`.
10825pub fn category(code: &str) -> &str {
10826    code.split('.').nth(1).unwrap_or("")
10827}
10828
10829/// A human-readable heading for a category segment.
10830fn category_title(cat: &str) -> &'static str {
10831    match cat {
10832        "actor" => "Actors",
10833        "adapter" => "Adapters",
10834        "agent" | "agents" => "Agents",
10835        "asset" => "Static assets",
10836        "boundary" => "Boundaries",
10837        "capability" => "Capabilities",
10838        "cloudflare" => "Cloudflare",
10839        "consumes" => "Consumes",
10840        "context" => "Contexts",
10841        "contract" => "Contracts",
10842        "cron" => "Cron",
10843        "deploy" => "Deployment",
10844        "doc" => "Doc comments",
10845        "effect" => "Effects",
10846        "embed" => "Embedded text",
10847        "event" => "Events",
10848        "expect" => "Expectations",
10849        "exports" => "Exports",
10850        "generics" => "Generics",
10851        "given" => "Given capabilities",
10852        "history" => "History properties",
10853        "http" => "HTTP",
10854        "internal" => "Internal errors",
10855        "lex" => "Lexer",
10856        "messages" => "Message bundles",
10857        "mock" => "Mocks (collaborators)",
10858        "observe" => "Observation",
10859        "package" => "Packages",
10860        "parse" => "Parser",
10861        "namespace" | "project" => "Project",
10862        "property" => "Properties (generative tests)",
10863        "provider" => "Providers",
10864        "queue" => "Queue",
10865        "record_spread" => "Record spread",
10866        "refine" => "Refinement",
10867        "requires" => "npm requirements",
10868        "resolve" => "Resolution",
10869        "service" => "Services",
10870        "stability" => "Stability",
10871        "store" => "Agent storage",
10872        "stub" => "Stubs",
10873        "suite" => "Suites and cases",
10874        "test" => "Tests",
10875        "tier" => "Test tiers",
10876        "transition" => "Transitions (step invariants)",
10877        "types" => "Type checking",
10878        "uses" => "Uses",
10879        "val" => "Value fabrication",
10880        _ => "Other",
10881    }
10882}
10883
10884/// Render the diagnostic index as a Markdown reference page, grouped by
10885/// category. This is the generator behind
10886/// `site/src/content/docs/reference/diagnostics.md`.
10887pub fn render_markdown() -> String {
10888    use std::collections::BTreeMap;
10889
10890    // Group codes by their category title, preserving sorted code order.
10891    let mut by_category: BTreeMap<&str, Vec<&DiagnosticInfo>> = BTreeMap::new();
10892    for info in REGISTRY {
10893        by_category
10894            .entry(category_title(category(info.code)))
10895            .or_default()
10896            .push(info);
10897    }
10898
10899    let mut out = String::new();
10900    out.push_str("# Diagnostic index\n\n");
10901    out.push_str(
10902        "<!-- GENERATED FILE — do not edit by hand.\n     \
10903         Source: bynk-syntax/src/diagnostics.rs (`render_markdown`).\n     \
10904         Regenerate with: BYNK_BLESS=1 cargo test -p xtask --test docs_consistency diagnostics_registry:: -->\n\n",
10905    );
10906    out.push_str(
10907        "Every diagnostic code the compiler can emit, with a one-line summary of \
10908         the cause, grouped by category. Each code links to its own page: what the \
10909         code means, how to fix it and an example where an explanation is written, \
10910         the grammar rules it governs, and the Book pages that explain it. \
10911         `bynk explain <code>` prints a code's explanation in a terminal, and in VS Code the diagnostic's **Explain** quick fix (or \
10912         **Bynk: Explain Diagnostic Code…**) shows the same text in a panel, offline.\n\n",
10913    );
10914    out.push_str(&format!(
10915        "There are **{}** codes in total. Every code is an error unless it is marked \
10916         **Warning** or **Hint**.\n",
10917        REGISTRY.len()
10918    ));
10919    // The site's filter box (`site/public/diagnostic-filter.js`) adds itself
10920    // here, above the first category, and narrows the lists as you type.
10921    out.push_str("\n<script type=\"module\" src=\"/diagnostic-filter.js\"></script>\n");
10922
10923    for (title, infos) in &by_category {
10924        out.push_str(&format!("\n## {title}\n\n"));
10925        // One list item per code, not a table row: nearly 900 codes in a
10926        // table overflowed the content column (#3876 review), and the
10927        // category heading already groups them. A code's grammar constructs
10928        // are on its own page.
10929        for info in infos {
10930            // Every code links to its own page (#3876), which the site
10931            // generates from `render_json` for every registry code.
10932            let code = format!("[`{0}`]({INDEX_PATH}{0}/)", info.code);
10933            // ADR 0117/finding #50: every code's severity, straight from the
10934            // registry. Errors are the overwhelming majority and go unmarked;
10935            // a `warn`-built entry carries a "Warning" badge, a hint "Hint".
10936            let severity = match info.severity {
10937                Severity::Error => "",
10938                Severity::Warning => "<span class=\"diagnostic-severity\">Warning</span> ",
10939                Severity::Hint => "<span class=\"diagnostic-severity\">Hint</span> ",
10940            };
10941            out.push_str(&format!("- {code} — {severity}{}\n", info.summary));
10942        }
10943    }
10944
10945    out
10946}
10947
10948/// Every registry code as JSON, for the site's page per code (#3876): its
10949/// summary, severity, category (title and the index anchor of its heading),
10950/// grammar constructs, and the curated `blurb` and `example` where the code
10951/// has one (else `null`). Sorted by code. This is the generator behind
10952/// `site/src/generated/diagnostics.json`, which the route
10953/// `site/src/pages/reference/diagnostics/[code].astro` renders; the
10954/// docs-consistency test keeps the committed file current.
10955pub fn render_json() -> String {
10956    let mut infos: Vec<&DiagnosticInfo> = REGISTRY.iter().collect();
10957    infos.sort_by_key(|i| i.code);
10958    let codes: Vec<serde_json::Value> = infos
10959        .iter()
10960        .map(|info| {
10961            let cat = category(info.code);
10962            let explained = explain(info.code);
10963            serde_json::json!({
10964                "code": info.code,
10965                "summary": info.summary,
10966                "severity": match info.severity {
10967                    Severity::Error => "error",
10968                    Severity::Warning => "warning",
10969                    Severity::Hint => "hint",
10970                },
10971                "category": category_title(cat),
10972                "categoryAnchor": category_anchor(cat),
10973                "constructs": info.grammar_symbol,
10974                "blurb": explained.map(|e| e.blurb),
10975                "example": explained.map(|e| e.example),
10976            })
10977        })
10978        .collect();
10979    let mut out = serde_json::to_string_pretty(&codes).expect("diagnostics serialise");
10980    out.push('\n');
10981    out
10982}
10983
10984/// Invert the registry into a `{ "<rule>": [ { code, summary }, … ], … }` map,
10985/// serialised as pretty JSON with sorted keys and sorted codes. Only rules with
10986/// at least one diagnostic appear. This is the generator behind
10987/// `docs/grammar-semantics.json`, which the `{{#grammar-semantics <rule>}}`
10988/// preprocessor directive consumes.
10989pub fn render_grammar_semantics_json() -> String {
10990    use std::collections::BTreeMap;
10991
10992    // REGISTRY is sorted by code, so each rule's vector comes out code-sorted;
10993    // the BTreeMap gives sorted rule names.
10994    let mut by_symbol: BTreeMap<&str, Vec<&DiagnosticInfo>> = BTreeMap::new();
10995    for info in REGISTRY {
10996        for sym in info.grammar_symbol {
10997            by_symbol.entry(sym).or_default().push(info);
10998        }
10999    }
11000
11001    let mut map = serde_json::Map::new();
11002    map.insert(
11003        "_generated".to_string(),
11004        serde_json::Value::String(
11005            "Generated from the grammar_symbol field of bynk-syntax/src/diagnostics.rs. \
11006             Do not edit by hand. Regenerate with: BYNK_BLESS=1 cargo test -p \
11007             xtask --test docs_consistency diagnostics_registry::"
11008                .to_string(),
11009        ),
11010    );
11011    for (sym, infos) in by_symbol {
11012        let arr: Vec<serde_json::Value> = infos
11013            .iter()
11014            .map(|info| serde_json::json!({ "code": info.code, "summary": info.summary }))
11015            .collect();
11016        map.insert(sym.to_string(), serde_json::Value::Array(arr));
11017    }
11018
11019    let mut s =
11020        serde_json::to_string_pretty(&serde_json::Value::Object(map)).expect("serialise semantics");
11021    s.push('\n');
11022    s
11023}