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/book/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 diagnostics page's Construct
16//! column) 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. Richer "cause and fix" material for the common diagnostics lives in
22/// the troubleshooting how-to guides.
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 Book, the stable target for `codeDescription` links (#853,
45/// DECISION C). No trailing slash — an [`Explain::page`] path (which begins
46/// with `/`) is appended directly.
47pub const BOOK_BASE_URL: &str = "https://bynk-lang.org";
48
49/// A curated, offline-complete explanation of a diagnostic code (#853).
50///
51/// This is the compiler-owned `code → { blurb, href }` table (DECISION A): the
52/// `blurb`/`example` are the offline answer `bynk explain` prints, while
53/// `page`/`anchor` compose the hosted-Book href the LSP hangs off the code as a
54/// clickable `codeDescription` link (DECISION C). Only the highest-traffic,
55/// newcomer-facing codes are curated; every other code simply has no entry and
56/// falls back gracefully — no link, no error (DECISION B).
57///
58/// The mapping points at *existing* Book concept pages rather than duplicating
59/// their prose; the reference-page generator ([`render_markdown`]) links every
60/// explained code at its `page`/`anchor` as an in-site link, so
61/// `astro build`'s link checker fails if a page moves or an anchor is renamed —
62/// the doc-drift guard the rest of the site already relies on.
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.
71    pub example: &'static str,
72    /// The target Book page as a site-root-relative path, no extension and no
73    /// trailing slash, e.g. `/book/reference/types`. Used verbatim as an
74    /// in-site link by [`render_markdown`] (so the site link checker guards it)
75    /// and prefixed with [`BOOK_BASE_URL`] for the hosted `codeDescription`.
76    pub page: &'static str,
77    /// The in-page heading anchor (slug), or `""` for the page top.
78    pub anchor: &'static str,
79}
80
81impl Explain {
82    /// The hosted-Book URL for this explanation: [`BOOK_BASE_URL`] + the page
83    /// (Starlight serves pages with a trailing slash) + `#anchor` when set.
84    pub fn href(&self) -> String {
85        let mut url = format!("{BOOK_BASE_URL}{}/", self.page);
86        if !self.anchor.is_empty() {
87            url.push('#');
88            url.push_str(self.anchor);
89        }
90        url
91    }
92
93    /// The site-root-relative link used inside the generated reference page,
94    /// e.g. `/book/reference/types/#record-types`. Same shape as [`href`], sans
95    /// the host, so the in-site link checker resolves it.
96    ///
97    /// [`href`]: Explain::href
98    pub fn in_site_link(&self) -> String {
99        let mut link = format!("{}/", self.page);
100        if !self.anchor.is_empty() {
101            link.push('#');
102            link.push_str(self.anchor);
103        }
104        link
105    }
106}
107
108/// The curated explanations, keyed by code (DECISION B: highest-traffic,
109/// newcomer-facing codes first). Kept sorted by code; every `code` must be a
110/// real [`REGISTRY`] entry and every `page` an existing Book page — both
111/// enforced by `tests/diagnostics_registry.rs`.
112pub const EXPLANATIONS: &[Explain] = &[
113    Explain {
114        code: "bynk.given.undeclared_capability",
115        blurb: "A handler may only use a capability it has itself declared with \
116                `given`. Effects in Bynk are explicit: the `given` clause is the \
117                handler's honest, checkable statement of every capability it \
118                reaches for, so a reader (and the compiler) can see a handler's \
119                full reach from its signature alone. Using a capability that is \
120                not in `given` is the missing half of that contract.",
121        example: "on get \"/now\" -> Text {           // ✗ uses Clock without declaring it\n    \
122                    Clock.now()\n}\n\n\
123                  on get \"/now\" given Clock -> Text { // ✓ declared, then used\n    \
124                    Clock.now()\n}",
125        page: "/book/guides/effects-and-capabilities/understand-the-capability-model",
126        anchor: "",
127    },
128    Explain {
129        code: "bynk.given.unknown_capability",
130        blurb: "A `given` clause names a capability that no provider declares. A \
131                capability is a typed interface to the outside world; it has to be \
132                *declared* (as a `capability`, or brought in from a consumed \
133                context) before a handler can ask for it. This usually means a \
134                typo in the capability name, or a missing `uses`/`consumes` that \
135                would bring the capability into scope.",
136        example: "on get \"/\" given Clok -> Text { … }  // ✗ no capability named `Clok`\n\n\
137                  on get \"/\" given Clock -> Text { … }  // ✓ matches the declared capability",
138        page: "/book/reference/capabilities",
139        anchor: "declaring-a-capability",
140    },
141    Explain {
142        code: "bynk.http.error_status_position",
143        blurb: "An `ErrorStatus` name such as `Forbidden` stands for a status only as \
144                `RawError`'s first argument, where the compiler turns it into the \
145                number it answers. It is not a type, so a status can't be stored or \
146                passed to a helper. Name the status where the response is built, and \
147                let a helper build the body.",
148        example: "fn refusal(status: ErrorStatus, msg: String) -> HttpResult[()] { … }   // ✗\n\n\
149                  fn problem(msg: String) -> Bytes { Bytes.fromUtf8(msg) }\n\
150                  RawError(Forbidden, problem(\"no access\"), \"text/plain\")     // ✓",
151        page: "/book/reference/http",
152        anchor: "error-bodies",
153    },
154    Explain {
155        code: "bynk.http.raw_body_unbounded",
156        blurb: "A `@raw` route hands the handler its request body as untouched octets, \
157                buffered in memory up to a cap. With no cap there is no bound on that \
158                buffer, which is the denial of service request body limits exist to \
159                stop, so a raw route must have one: a `@limit(maxBody:)` on the \
160                handler, or a `limits { maxBody = … }` on the service.",
161        example: "@raw(contentType: \"image/png\")           // ✗ no cap anywhere\n\
162                  on POST(\"/avatars\") (body: Bytes) -> Effect[HttpResult[String]] { … }\n\n\
163                  @raw(contentType: \"image/png\")           // ✓ capped\n\
164                  @limit(maxBody: 5_000_000)\n\
165                  on POST(\"/avatars\") (body: Bytes) -> Effect[HttpResult[String]] { … }",
166        page: "/book/reference/http",
167        anchor: "raw-request-bodies",
168    },
169    Explain {
170        code: "bynk.provider.agent_call_undeclared_capability",
171        blurb: "A provider calls an agent handler, and the handler needs a capability \
172                the provider's `given` does not list. A handler's `given` is \
173                widened to cover the agent handlers it calls, but a provider's is \
174                not. The provider is constructed with exactly the capabilities in \
175                its `given`, and those are all it can hand on to the agent. So the \
176                provider must list everything the agent handler needs: the \
177                handler's own `given`, and the `given` of any agent handler it \
178                calls in turn.",
179        example: "agent Index {\n    \
180                    key name: String\n    \
181                    store hits: Cell[Int]\n    \
182                    on call withdraw() -> Effect[()] given Files { … }\n}\n\n\
183                  provides Takedown = Bucket given Clock {         // ✗ `withdraw` needs `Files`\n    \
184                    fn take(name: String) -> Effect[()] { Index(name).withdraw() }\n}\n\n\
185                  provides Takedown = Bucket given Clock, Files {  // ✓\n    \
186                    fn take(name: String) -> Effect[()] { Index(name).withdraw() }\n}",
187        page: "/book/guides/effects-and-capabilities/compose-a-provider",
188        anchor: "the-rules",
189    },
190    Explain {
191        code: "bynk.registry.withdrawn",
192        blurb: "Your `bynk.lock` locks a version that its registry has withdrawn. A \
193                withdrawal is a takedown — for a legal request or confirmed malware — \
194                so unlike a yank, which keeps a version for locked builds, the \
195                registry has deleted its archive and there is nothing to fetch. The \
196                message quotes the registry's reason. A machine that already has the \
197                tree in its store keeps building; elsewhere, move off the version \
198                with `bynk update` and the dependency's alias. The reason is unsigned, so when it was \
199                read through a mirror the message says the origin wasn't consulted.",
200        example: "error[bynk.registry.withdrawn]: `acme/money` 1.4.2 was withdrawn by \
201                  registry `acme-internal`: \"removed at the copyright holder's request\"\n  \
202                  = note: `bynk.lock` locks this version; choose another with `bynk update money`\n\n\
203                  $ bynk update money     # resolves to the newest version not withdrawn",
204        page: "/book/guides/projects-build-and-deployment/run-a-private-registry",
205        anchor: "withdraw-a-version",
206    },
207    Explain {
208        code: "bynk.requires.unapproved",
209        blurb: "An adapter in a git or registry dependency requires an npm package \
210                your project hasn't approved. A dependency's adapters bring their \
211                npm packages into your build's `package.json`, and the next \
212                `npm install` runs whatever those packages run; so an npm package \
213                from someone else's code enters only after you approve it once. \
214                The approval is one package at one range, recorded in `bynk.lock` \
215                (`approved = true`), so a changed range asks again. Your own \
216                adapters and path dependencies need no approval.",
217        example: "# bynk.lock, as a fetch wrote it — the build fails until approved\n\
218                  [[npm]]\npackage = \"jose\"\nrange = \"^5.2.0\"\n\
219                  required-by = [\"acme/money:tokens\"]\n\n\
220                  # after `bynk approve jose` — the build passes\n\
221                  [[npm]]\npackage = \"jose\"\nrange = \"^5.2.0\"\n\
222                  required-by = [\"acme/money:tokens\"]\napproved = true",
223        page: "/book/guides/projects-build-and-deployment/share-code-between-projects",
224        anchor: "approve-a-dependencys-npm-packages",
225    },
226    Explain {
227        code: "bynk.resolve.missing_field",
228        blurb: "A record must be constructed with every one of its fields. Bynk \
229                records have no defaults and no partial construction: a value of a \
230                record type is only valid once all its fields are present, so a \
231                downstream reader never has to wonder whether a field was set. \
232                Omitting a field is therefore an error, not a fill-in-later.",
233        example: "type User = { name: Text, age: Int }\n\n\
234                  User { name: \"Ada\" }            // ✗ missing `age`\n\
235                  User { name: \"Ada\", age: 36 }   // ✓ every field present",
236        page: "/book/reference/types",
237        anchor: "record-types",
238    },
239    Explain {
240        code: "bynk.resolve.unknown_field",
241        blurb: "A field access names a field the record type does not have. A \
242                record's fields are fixed by its type declaration; only those \
243                names exist on the value. This is usually a typo in the field \
244                name, or an access meant for a different type.",
245        example: "type User = { name: Text }\n\n\
246                  user.nmae   // ✗ no field `nmae`\n\
247                  user.name   // ✓ the declared field",
248        page: "/book/reference/types",
249        anchor: "record-types",
250    },
251    Explain {
252        code: "bynk.resolve.unknown_name",
253        blurb: "A name was referenced that is not in scope. Every name in Bynk \
254                must be introduced before use — as a `let` binding, a parameter, \
255                a `fn`, a type, or a member brought in through `uses`/`consumes`. \
256                An unknown name is typically a typo, a missing declaration, or a \
257                reference to something defined in a module that has not been \
258                brought into scope.",
259        example: "let greeting = \"hi\"\n\
260                  greetng          // ✗ no name `greetng` in scope\n\
261                  greeting         // ✓ the bound name",
262        page: "/book/guides/program-structure/how-a-program-is-shaped",
263        anchor: "",
264    },
265    Explain {
266        code: "bynk.resolve.unknown_type",
267        blurb: "A type name was referenced that does not exist. Types must be \
268                declared (with `type`), be one of Bynk's built-in types, or be \
269                brought into scope from another module before they can be named. \
270                An unknown type is usually a typo or a missing declaration/import.",
271        example: "fn greet(u: Usr) -> Text { … }   // ✗ no type `Usr`\n\
272                  fn greet(u: User) -> Text { … }  // ✓ the declared type",
273        page: "/book/reference/types",
274        anchor: "",
275    },
276    Explain {
277        code: "bynk.types.claims_at_boundary",
278        blurb: "An `Oidc` actor's binder carries the verified token's claims (`who.claims`) for the \
279                handler that received the token. They are read there and never kept: a \
280                `TokenClaims` can't be a field, or cross a call, a message or an agent. Read the \
281                claim you need and keep that `String`.",
282        example: "type Seen = { claims: TokenClaims }                 // ✗\n\n\
283                  let repo = w.claims.get(\"repository\")            // ✓ keep the String",
284        page: "/book/reference/actors",
285        anchor: "reading-claims",
286    },
287];
288
289/// The curated explanation for a diagnostic `code`, or `None` when the code has
290/// no explanation yet (the designed graceful-fallback state, DECISION B).
291pub fn explain(code: &str) -> Option<&'static Explain> {
292    EXPLANATIONS.iter().find(|e| e.code == code)
293}
294
295/// The hosted diagnostic index page (the generated `reference/diagnostics`
296/// page), the link target for a code with no curated [`Explain`] page.
297pub const INDEX_PATH: &str = "/book/reference/diagnostics/";
298
299/// The anchor slug of a category's `## <title>` heading on the generated
300/// diagnostic index (Starlight/github-slugger shape: lowercase, spaces to
301/// hyphens, punctuation dropped), e.g. `"type-checking"`.
302fn category_anchor(cat: &str) -> String {
303    category_title(cat)
304        .chars()
305        .filter_map(|c| match c {
306            ' ' => Some('-'),
307            c if c.is_alphanumeric() || c == '-' => Some(c.to_ascii_lowercase()),
308            _ => None,
309        })
310        .collect()
311}
312
313/// The hosted-Book link for any diagnostic `code`: the curated
314/// [`Explain::href`] when one exists (what the LSP's `codeDescription` uses),
315/// otherwise the diagnostic index, deep-linked to the code's category section
316/// when the code is a registry code (a non-registry code, e.g. a host-synthetic
317/// one, links the index top).
318pub fn href(code: &str) -> String {
319    if let Some(e) = explain(code) {
320        return e.href();
321    }
322    let mut url = format!("{BOOK_BASE_URL}{INDEX_PATH}");
323    if lookup(code).is_some() {
324        url.push('#');
325        url.push_str(&category_anchor(category(code)));
326    }
327    url
328}
329
330/// Look up a code's registry entry by exact match — the one place
331/// [`crate::error::Severity::for_error`] reads a code's severity, instead of
332/// hardcoding its own copy of the (small) warning set.
333pub fn lookup(code: &str) -> Option<&'static DiagnosticInfo> {
334    REGISTRY.iter().find(|d| d.code == code)
335}
336
337/// Every diagnostic code the compiler emits, sorted by code.
338pub const REGISTRY: &[DiagnosticInfo] = &[
339    d(
340        "bynk.actor.bearer_identity_not_string_constructible",
341        "A `Bearer` actor's identity is not a string-constructible type.",
342    ),
343    d(
344        "bynk.actor.bearer_missing_secret",
345        "A `Bearer` actor does not name its signing secret.",
346    ),
347    d(
348        "bynk.actor.binder_shadows_param",
349        "A `by` actor binder collides with a handler parameter of the same name.",
350    ),
351    d(
352        "bynk.actor.by_on_agent",
353        "A `by` actor clause was placed on an agent `on call` handler, which has no actor.",
354    ),
355    d(
356        "bynk.actor.duplicate_sum_scheme",
357        "Two peers in a multi-actor sum share an authentication scheme.",
358    ),
359    d(
360        "bynk.actor.foreign_context_name_unkeyable",
361        "A context declaring a `Foreign` actor has a name no call key can be named from.",
362    ),
363    d(
364        "bynk.actor.foreign_duplicate_secret",
365        "A `Foreign` actor's secret is also another actor's secret in the same context.",
366    ),
367    d(
368        "bynk.actor.foreign_identity_unsupported",
369        "A `Foreign` actor declares an `identity`.",
370    ),
371    d(
372        "bynk.actor.foreign_missing_secret",
373        "A `Foreign` actor does not name the secret its calls are signed with.",
374    ),
375    d(
376        "bynk.actor.foreign_name_is_context_name",
377        "A `Foreign` actor's name could be read as a context's name.",
378    ),
379    d(
380        "bynk.actor.foreign_reserved_secret",
381        "A `Foreign` actor's secret uses a `BYNK_CALL_` edge key's name.",
382    ),
383    d(
384        "bynk.actor.foreign_secret_not_string",
385        "A `Foreign` actor's secret is not a string.",
386    ),
387    d(
388        "bynk.actor.identity_not_sealed",
389        "An actor identity type is not a context-ownable (sealed) value type.",
390    ),
391    d(
392        "bynk.actor.missing_by_on_http",
393        "An HTTP handler lacks the required `by` actor clause.",
394    ),
395    d(
396        "bynk.actor.oidc_identity_not_string_constructible",
397        "An `Oidc` actor's identity is not a string-constructible type.",
398    ),
399    d(
400        "bynk.actor.oidc_missing_audience",
401        "An `Oidc` actor does not name its `audience`.",
402    ),
403    d(
404        "bynk.actor.oidc_missing_issuer",
405        "An `Oidc` actor does not name its `issuer`.",
406    ),
407    d(
408        "bynk.actor.oidc_missing_jwks",
409        "An `Oidc` actor does not name its `jwks` endpoint.",
410    ),
411    d(
412        "bynk.actor.oidc_not_in_sum",
413        "An `Oidc` actor appears as a member of a multi-actor sum.",
414    ),
415    d(
416        "bynk.actor.oidc_trust_from_is_secret",
417        "An `Oidc` actor's `trustFrom` names an environment variable that an actor uses as its `secret`.",
418    ),
419    d(
420        "bynk.actor.oidc_trust_from_not_string",
421        "An `Oidc` actor's `trustFrom` isn't a string naming an environment variable.",
422    ),
423    d(
424        "bynk.actor.outside_context",
425        "An `actor` was declared outside a context (e.g. in a commons).",
426    ),
427    d(
428        "bynk.actor.refinement_base_unsupported",
429        "A refinement actor's base is not a `Bearer` actor (no claims to authorise against).",
430    ),
431    d(
432        "bynk.actor.refinement_in_sum",
433        "A refinement actor appears as a member of a multi-actor sum.",
434    ),
435    d(
436        "bynk.actor.refinement_predicate_unsupported",
437        "A refinement actor's `where` predicate is outside the closed claim-predicate set.",
438    ),
439    d(
440        "bynk.actor.scheme_not_admissible",
441        "An actor's scheme is not admissible on this handler's protocol.",
442    ),
443    d(
444        "bynk.actor.signature_identity_unsupported",
445        "A `Signature` actor declared an `identity`, which is not yet supported.",
446    ),
447    d(
448        "bynk.actor.signature_missing_header",
449        "A `Signature` actor does not name its signature header.",
450    ),
451    d(
452        "bynk.actor.signature_missing_secret",
453        "A `Signature` actor does not name its signing secret.",
454    ),
455    d(
456        "bynk.actor.signature_requires_body",
457        "A `Signature` handler does not take a `body` parameter.",
458    ),
459    d(
460        "bynk.actor.signature_tolerance_without_timestamp",
461        "A `Signature` actor set `tolerance` without a `timestamp` header.",
462    ),
463    d(
464        "bynk.actor.sum_requires_binder",
465        "A multi-actor sum `by` clause has no binder to match the resolved actor.",
466    ),
467    d(
468        "bynk.actor.unknown_actor",
469        "A handler's `by` clause names an actor that is not declared.",
470    ),
471    d(
472        "bynk.actor.unknown_scheme",
473        "An actor declares an authentication scheme that is not compiler-known.",
474    ),
475    d(
476        "bynk.actor.unreachable_sum_arm",
477        "A multi-actor sum has an arm unreachable after a catch-all (`None`) peer.",
478    ),
479    dg(
480        "bynk.adapter.consumes_context",
481        "An `adapter` consumed a context; adapter dependencies are adapter-to-adapter.",
482        &["consumes_decl"],
483    ),
484    dg(
485        "bynk.adapter.consumes_requires_selection",
486        "An `adapter` used a whole-unit or aliased `consumes`; adapters must select capabilities with `consumes U { Cap, … }`.",
487        &["consumes_decl"],
488    ),
489    dg(
490        "bynk.adapter.disallowed_item",
491        "An `adapter` declared a `service`, `agent`, or other item it may not contain.",
492        &["adapter_decl"],
493    ),
494    dg(
495        "bynk.adapter.duplicate_binding",
496        "An `adapter` declared more than one `binding` clause.",
497        &["binding_decl"],
498    ),
499    dg(
500        "bynk.adapter.include_duplicate",
501        "An adapter `binding … includes [ … ]` list names one file more than once.",
502        &["binding_decl"],
503    ),
504    dg(
505        "bynk.adapter.include_kind",
506        "An adapter `binding … includes [ … ]` entry is not a `.wasm` file; only WebAssembly modules can be included.",
507        &["binding_decl"],
508    ),
509    dg(
510        "bynk.adapter.include_missing",
511        "An adapter `binding … includes [ … ]` entry names a file that could not be read.",
512        &["binding_decl"],
513    ),
514    dg(
515        "bynk.adapter.include_outside",
516        "An adapter `binding … includes [ … ]` path is absolute or climbs out of the adapter's directory with `..`.",
517        &["binding_decl"],
518    ),
519    dg(
520        "bynk.adapter.no_binding",
521        "An `adapter` declares an external provider but no `binding` module to supply it.",
522        &["adapter_decl"],
523    ),
524    dg(
525        "bynk.adapter.provider_has_body",
526        "A provider inside an `adapter` has a Bynk body; adapter providers must be external.",
527        &["provider_decl"],
528    ),
529    d(
530        "bynk.agent.class_conflict",
531        "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`.",
532    ),
533    d(
534        "bynk.agent.class_removed",
535        "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.",
536    ),
537    dg(
538        "bynk.agent.construction_arity",
539        "An agent was constructed with the wrong number of key arguments.",
540        &["agent_decl"],
541    ),
542    dg(
543        "bynk.agent.handler_arity",
544        "An agent handler was called with the wrong number of arguments.",
545        &["agent_decl"],
546    ),
547    dg(
548        "bynk.agent.handler_not_found",
549        "Called a handler the agent does not declare.",
550        &["agent_decl"],
551    ),
552    dg(
553        "bynk.agent.key_mismatch",
554        "An agent key argument has the wrong type.",
555        &["agent_decl"],
556    ),
557    warn(d(
558        "bynk.agent.migrate_below_floor",
559        "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).",
560    )),
561    d(
562        "bynk.agent.migrate_duplicate",
563        "Two `migrate` steps in one agent read the same schema version.",
564    ),
565    d(
566        "bynk.agent.migrate_duplicate_assignment",
567        "A `migrate` step assigns the same `store` field more than once; each field takes at most one value per step (record-literal semantics).",
568    ),
569    d(
570        "bynk.agent.migrate_impure",
571        "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.",
572    ),
573    d(
574        "bynk.agent.migrate_incomplete",
575        "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).",
576    ),
577    d(
578        "bynk.agent.migrate_shape_mismatch",
579        "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.",
580    ),
581    d(
582        "bynk.agent.migrate_unknown_version",
583        "A `migrate` step reads a schema version the lock does not record below the agent's current version.",
584    ),
585    d(
586        "bynk.agent.non_additive_state_change",
587        "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.",
588    ),
589    dg(
590        "bynk.agent.outside_context",
591        "An `agent` was declared outside a context.",
592        &["agent_decl"],
593    ),
594    warn(d(
595        "bynk.agent.refinement_changed",
596        "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).",
597    )),
598    d(
599        "bynk.agent.removed_live",
600        "A `removed agent` declaration names a class that is still declared; removing a class deletes its stored data.",
601    ),
602    d(
603        "bynk.agent.replaces_live",
604        "`agent New replaces Old` names an `Old` that is still declared; a rename moves the old class's data to the new one.",
605    ),
606    d(
607        "bynk.agent.replaces_unknown",
608        "`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.",
609    ),
610    dg(
611        "bynk.agent.return_not_effect",
612        "An agent handler's return type is not an `Effect`.",
613        &["agent_decl"],
614    ),
615    d(
616        "bynk.agent.state_name_conflict",
617        "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.",
618    ),
619    warn(d(
620        "bynk.agent.version_without_path",
621        "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).",
622    )),
623    dg(
624        "bynk.agents.bad_state_initialiser",
625        "An agent `store` field initialiser is not a static value of the field's type.",
626        &["store_field"],
627    ),
628    dg(
629        "bynk.agents.non_zeroable_state_field",
630        "An agent `store` field has no initialiser and no implicit zero value.",
631        &["store_field"],
632    ),
633    d(
634        "bynk.asset.duplicate",
635        "An `asset` name is declared more than once in the same unit.",
636    ),
637    d(
638        "bynk.asset.invalid_at_path",
639        "An `asset`'s `at` path is not a URL path naming one file, or lies under `/_assets/` or `/_bynk/`.",
640    ),
641    warn(d(
642        "bynk.asset.may_shadow_route",
643        "A parameterised HTTP route matches a fixed asset path, so it never sees requests for that path (a warning).",
644    )),
645    d(
646        "bynk.asset.missing_file",
647        "An `asset` names a file that is not in the project's `assets/` folder.",
648    ),
649    d(
650        "bynk.asset.needs_project",
651        "A single-file build met an `asset` declaration; assets need a project build.",
652    ),
653    warn(d(
654        "bynk.asset.not_served",
655        "A deployable Bundle build met an `asset`; a Bundle ships no files, so its `.url` would not be served (a warning).",
656    )),
657    d(
658        "bynk.asset.outside_assets_dir",
659        "An `asset` path does not name a file in the project's `assets/` folder.",
660    ),
661    d(
662        "bynk.asset.outside_context_or_commons",
663        "An `asset` declaration appears outside a context or commons.",
664    ),
665    d(
666        "bynk.asset.path_conflict",
667        "Two different asset files would be served at one fixed path by the same Worker.",
668    ),
669    d(
670        "bynk.asset.shadows_route",
671        "A fixed asset path equals a literal HTTP route, which the platform-served asset makes unreachable.",
672    ),
673    d(
674        "bynk.asset.unreadable_file",
675        "An `asset` names a file in the project's `assets/` folder that could not be read.",
676    ),
677    d(
678        "bynk.asset.unsafe_path",
679        "An `asset` path is empty, absolute, or contains a `..` segment.",
680    ),
681    d(
682        "bynk.boundary.ambiguous_type",
683        "A value's type is declared, with different shapes, by more than one consumed context, so its fields cannot be read.",
684    ),
685    d(
686        "bynk.boundary.structural_mismatch",
687        "Data crossing a context boundary did not match the expected shape.",
688    ),
689    dg(
690        "bynk.capability.base_not_instantiable",
691        "A derived capability's base is not a platform resource that can be instantiated.",
692        &["capability_decl"],
693    ),
694    dg(
695        "bynk.capability.derived_outside_context",
696        "A derived capability was declared outside a context.",
697        &["capability_decl"],
698    ),
699    dg(
700        "bynk.capability.instance_only",
701        "A platform capability that is used only through named instances (`Service`, `R2`, `RateLimit`, `EdgeCache`) was used bare, in a `given` clause.",
702        &["given_clause"],
703    ),
704    dg(
705        "bynk.capability.invalid_option",
706        "A derived capability's option is not one string literal, is given twice, or (`@worker`) is not a Worker name outside the project.",
707        &["capability_decl"],
708    ),
709    dg(
710        "bynk.capability.missing_option",
711        "A derived capability lacks an option its base requires, such as a `Service` instance's `@worker`.",
712        &["capability_decl"],
713    ),
714    dg(
715        "bynk.capability.not_provided",
716        "On the Workers target, a capability a context requires has no provider in it.",
717        &["given_clause"],
718    ),
719    dg(
720        "bynk.capability.op_arity",
721        "A capability operation was called with the wrong number of arguments.",
722        &["capability_decl"],
723    ),
724    dg(
725        "bynk.capability.outside_context",
726        "A `capability` was declared outside a context.",
727        &["capability_decl"],
728    ),
729    dg(
730        "bynk.capability.provider_agent_cross_context",
731        "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.",
732        &["given_clause"],
733    ),
734    dg(
735        "bynk.capability.unknown_base",
736        "A derived capability's base is not a capability the context consumes.",
737        &["capability_decl"],
738    ),
739    dg(
740        "bynk.capability.unknown_operation",
741        "Referenced an operation the capability does not declare.",
742        &["capability_decl"],
743    ),
744    dg(
745        "bynk.capability.unknown_option",
746        "A derived capability carries an option its base does not take.",
747        &["capability_decl"],
748    ),
749    d(
750        "bynk.cell.invalid_target",
751        "A `:=` write targets something that is not a `store Cell` field.",
752    ),
753    d(
754        "bynk.cell.self_reference",
755        "A `:=` right-hand side reads the cell being written (a read-modify-write); use `.update`.",
756    ),
757    d(
758        "bynk.cloudflare.edge_cache_duplicate",
759        "A context declares a second `EdgeCache` instance; the edge cache is one setting for the whole Worker.",
760    ),
761    d(
762        "bynk.cloudflare.edge_cache_exported",
763        "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.",
764    ),
765    d(
766        "bynk.cloudflare.edge_cache_in_agent",
767        "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.",
768    ),
769    d(
770        "bynk.cloudflare.edge_cache_in_queue",
771        "A queue consumer reaches an `EdgeCache` instance; purge from a service handler instead.",
772    ),
773    d(
774        "bynk.cloudflare.edge_cache_in_schedule",
775        "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.",
776    ),
777    d(
778        "bynk.cloudflare.edge_cache_public_authenticated",
779        "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.",
780    ),
781    dg(
782        "bynk.consumes.alias_conflict",
783        "Two `consumes` aliases collide.",
784        &["consumes_decl"],
785    ),
786    dg(
787        "bynk.consumes.capability_name_clash",
788        "Two flattened `consumes U { Cap }` capabilities collide, or one clashes with a local capability.",
789        &["consumes_decl"],
790    ),
791    dg(
792        "bynk.consumes.name_conflict",
793        "A `consumes` name collides with another name in scope.",
794        &["consumes_decl"],
795    ),
796    dg(
797        "bynk.consumes.self_reference",
798        "A context `consumes` itself.",
799        &["consumes_decl"],
800    ),
801    dg(
802        "bynk.consumes.service_arity",
803        "A consumed service was called with the wrong number of arguments.",
804        &["consumes_decl"],
805    ),
806    dg(
807        "bynk.consumes.signature_type_unconsumed",
808        "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.",
809        &["consumes_decl"],
810    ),
811    dg(
812        "bynk.consumes.target_is_commons",
813        "`consumes` targets a `commons` instead of a context.",
814        &["consumes_decl"],
815    ),
816    dg(
817        "bynk.consumes.type_alias_capability",
818        "A capability was aliased in `consumes U { Cap as Alias }`; only exported types can be aliased.",
819        &["consumes_decl"],
820    ),
821    dg(
822        "bynk.consumes.type_alias_conflict",
823        "A `consumes U { T as Alias }` alias collides with a type or value in scope, or with another alias.",
824        &["consumes_decl"],
825    ),
826    dg(
827        "bynk.consumes.type_alias_repeated",
828        "An exported type is aliased more than once, or is selected both bare and aliased, in `consumes U { … }`.",
829        &["consumes_decl"],
830    ),
831    dg(
832        "bynk.consumes.type_alias_unknown_export",
833        "`consumes U { T as Alias }` names a type `U` does not export.",
834        &["consumes_decl"],
835    ),
836    dg(
837        "bynk.consumes.unknown_context",
838        "`consumes` names a context that does not exist.",
839        &["consumes_decl"],
840    ),
841    dg(
842        "bynk.consumes.unknown_service",
843        "Called a service the consumed context does not declare.",
844        &["consumes_decl"],
845    ),
846    d(
847        "bynk.context.consumes_cycle",
848        "Contexts form a `consumes` dependency cycle.",
849    ),
850    d(
851        "bynk.context.duplicate_binding",
852        "A Worker would declare two bindings with the same name, such as an agent `Kv` and the `bynk.cloudflare` KV namespace (both `KV`).",
853    ),
854    d(
855        "bynk.context.external_construction",
856        "A context-owned type was constructed from outside that context.",
857    ),
858    d(
859        "bynk.context.external_decode",
860        "A context decoded a type another context owns and exports opaque, through `Json.decode`, `Json.decodeSql` or a `Codable` witness. Decoding creates a value, which only the owning context may do; its codec would check no more than the base type.",
861    ),
862    dg(
863        "bynk.context.external_provider",
864        "A bodiless (external) provider was declared outside an `adapter`.",
865        &["provider_decl"],
866    ),
867    d(
868        "bynk.context.opaque_inspection",
869        "An opaquely-exported type was inspected from outside its context.",
870    ),
871    d(
872        "bynk.context.rebrand_construction",
873        "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.",
874    ),
875    d(
876        "bynk.contract.duplicate_name",
877        "A function declares two contract clauses (`requires`/`ensures`) with the same name.",
878    ),
879    d(
880        "bynk.contract.impure_predicate",
881        "A contract predicate uses an effectful or test-only construct; a contract clause must be pure.",
882    ),
883    d(
884        "bynk.contract.not_bool",
885        "A contract predicate does not have type `Bool`.",
886    ),
887    d(
888        "bynk.contract.restated_by_test",
889        "A `case`/`property` merely restates a contract clause already declared at the function; the test is redundant.",
890    ),
891    d(
892        "bynk.contract.result_in_requires",
893        "A precondition (`requires`) references `result`; the return value is only in scope inside an `ensures`.",
894    ),
895    dg(
896        "bynk.cron.bad_params",
897        "A cron handler declares more than one parameter, or a non-`Int` one.",
898        &["cron_handler"],
899    ),
900    dg(
901        "bynk.cron.duplicate_schedule",
902        "Two cron handlers declare the same schedule.",
903        &["cron_handler"],
904    ),
905    dg(
906        "bynk.cron.invalid_schedule",
907        "A cron expression is not five whitespace-separated fields.",
908        &["cron_handler"],
909    ),
910    dg(
911        "bynk.cron.return_not_effect_result",
912        "A cron handler does not return `Effect[Result[(), E]]`.",
913        &["cron_handler"],
914    ),
915    d(
916        "bynk.d1.migration_name",
917        "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.",
918    ),
919    d(
920        "bynk.d1.migration_unreadable",
921        "A `D1` migration in the project's `migrations/` folder can't be read, or isn't UTF-8 text.",
922    ),
923    warn(d(
924        "bynk.d1.migrations_unused",
925        "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).",
926    )),
927    d(
928        "bynk.dependency.path_outside_root",
929        "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.",
930    ),
931    d(
932        "bynk.deploy.contract_skew",
933        "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.",
934    ),
935    d(
936        "bynk.deploy.foreign_contract_skew",
937        "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.",
938    ),
939    // LSP-only (#2459): published by `bynk-lsp` as a hint (or warning, per the
940    // `bynk.docLinks.reportUnresolved` setting); the compiler never emits it.
941    warn(d(
942        "bynk.doc.unresolved_link",
943        "A `[Name]` doc link resolves to nothing in the unit's scope (editor hint only).",
944    )),
945    d(
946        "bynk.duration.literal_overflow",
947        "A `Duration` literal (`<int>.<unit>`) exceeds the representable millisecond range.",
948    ),
949    dg(
950        "bynk.effect.bind_in_pure_context",
951        "An `<-` bind was used in a pure (non-effectful) context.",
952        &["effect_let_stmt"],
953    ),
954    dg(
955        "bynk.effect.bind_on_non_effect",
956        "An `<-` bind was applied to a non-`Effect` value.",
957        &["effect_let_stmt"],
958    ),
959    d(
960        "bynk.effect.capability_in_pure_context",
961        "A capability was used in a pure context.",
962    ),
963    d(
964        "bynk.effect.cross_context_in_pure_context",
965        "A cross-context call was made in a pure context.",
966    ),
967    dg(
968        "bynk.effect.do_in_pure_context",
969        "A `do` statement was used in a pure (non-effectful) context.",
970        &["do_stmt"],
971    ),
972    dg(
973        "bynk.effect.do_on_non_effect",
974        "A `do` statement was applied to a non-`Effect` value.",
975        &["do_stmt"],
976    ),
977    dg(
978        "bynk.effect.do_requires_unit",
979        "A `do` statement was applied to a valued `Effect[T]`; `do` performs a unit effect, so a real result would be dropped — use `let _ <- e` instead.",
980        &["do_stmt"],
981    ),
982    dg(
983        "bynk.effect.fn_value_in_pure_context",
984        "An effectful function value was called in a pure context; like a capability call, it is legal only where the enclosing body is effectful.",
985        &["call"],
986    ),
987    d(
988        "bynk.effect.unbound_effect",
989        "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).",
990    ),
991    d(
992        "bynk.embed.binary_content",
993        "An `embed` names a file with a NUL byte, so it is binary, not text.",
994    ),
995    d(
996        "bynk.embed.duplicate",
997        "An `embed` name is declared more than once in the same unit.",
998    ),
999    d(
1000        "bynk.embed.invalid_encoding",
1001        "An `embed` names a file that is not valid UTF-8.",
1002    ),
1003    d(
1004        "bynk.embed.missing_file",
1005        "An `embed` names a file that is not in the project's `embeds/` folder.",
1006    ),
1007    d(
1008        "bynk.embed.needs_project",
1009        "A single-file build met an `embed` declaration, which needs a project's `embeds/` folder.",
1010    ),
1011    d(
1012        "bynk.embed.outside_context_or_commons",
1013        "An `embed` declaration appears outside a context or commons.",
1014    ),
1015    d(
1016        "bynk.embed.outside_embeds_dir",
1017        "An `embed` names a file outside the project's `embeds/` folder.",
1018    ),
1019    d(
1020        "bynk.embed.too_large",
1021        "An `embed` names a file over 256 KiB, or the project's embedded files total over 1 MiB.",
1022    ),
1023    d(
1024        "bynk.embed.unreadable_file",
1025        "An `embed` names a file in the project's `embeds/` folder that could not be read.",
1026    ),
1027    d(
1028        "bynk.embed.unsafe_path",
1029        "An `embed` path is empty, absolute, or contains a `..` segment.",
1030    ),
1031    d(
1032        "bynk.event.bad_params",
1033        "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.",
1034    ),
1035    d(
1036        "bynk.event.bad_schema_dispatch",
1037        "A `via schema(...)` dispatch clause's argument is malformed — it must be a positive `Int` literal, a range of positive `Int` literals, or `_`.",
1038    ),
1039    d(
1040        "bynk.event.bad_schema_version",
1041        "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.",
1042    ),
1043    dg(
1044        "bynk.event.duplicate_handler",
1045        "A `from Events` service declares more than one `on event` handler; it has exactly one.",
1046        &["event_handler"],
1047    ),
1048    d(
1049        "bynk.event.emit_not_an_event",
1050        "`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.",
1051    ),
1052    d(
1053        "bynk.event.emit_outside_owner",
1054        "`Events.emit[E]` named an event `E` not declared in the emitting context — only an event's declaring context may emit it.",
1055    ),
1056    d(
1057        "bynk.event.handler_param_type_mismatch",
1058        "An `on event(e: T)` handler's declared parameter type does not match its `from Events(E)` header's event type.",
1059    ),
1060    d(
1061        "bynk.event.non_additive_schema_change",
1062        "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.",
1063    ),
1064    d(
1065        "bynk.event.outside_context",
1066        "An `event` was declared outside a context.",
1067    ),
1068    d(
1069        "bynk.event.pattern_duplicate_field",
1070        "A `from Events(E { ... })` subscription pattern listed the same field more than once.",
1071    ),
1072    d(
1073        "bynk.event.pattern_type_mismatch",
1074        "A `from Events(E { ... })` subscription pattern field's matched value is not compatible with that field's declared type.",
1075    ),
1076    d(
1077        "bynk.event.pattern_unknown_field",
1078        "A `from Events(E { ... })` subscription pattern named a field that `E` does not declare.",
1079    ),
1080    d(
1081        "bynk.event.pattern_unknown_variant",
1082        "A `from Events(E { ... })` subscription pattern's variant value names a variant that does not exist on the field's declared sum type.",
1083    ),
1084    d(
1085        "bynk.event.pattern_variant_payload",
1086        "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.",
1087    ),
1088    dg(
1089        "bynk.event.return_not_effect_unit",
1090        "An `on event` handler returns an `Effect` of something other than `()`; emission is fire-and-forget, so it returns `Effect[()]`.",
1091        &["event_handler"],
1092    ),
1093    d(
1094        "bynk.event.schema_version_mismatch",
1095        "An event's `@schema(N)` annotation disagrees with the version the schema registry computes from the event's build history.",
1096    ),
1097    d(
1098        "bynk.event.unknown_annotation",
1099        "An `event` declaration carried an `@`-annotation other than `@schema` — event annotations are a closed set.",
1100    ),
1101    d(
1102        "bynk.event.unknown_subscription",
1103        "A `from Events(E)` subscription named `E`, which is not a declared event in this context or any consumed context.",
1104    ),
1105    d(
1106        "bynk.exec.unavailable",
1107        "A call to, or reference to, a function that hands work to the execution context (`~>`, `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.",
1108    ),
1109    dg(
1110        "bynk.expect.faults_not_effect",
1111        "A fault claim's subject (`expect <call> faults`) is not an effectful call: a value, or a call whose type is not `Effect[_]`.",
1112        &["faults_expr"],
1113    ),
1114    dg(
1115        "bynk.expect.not_bool",
1116        "`expect` was given a non-`Bool` predicate.",
1117        &["expect_expr"],
1118    ),
1119    dg(
1120        "bynk.expect.outside_case",
1121        "`expect` was used outside a `case` body.",
1122        &["expect_expr"],
1123    ),
1124    dg(
1125        "bynk.exports.capability_not_provided",
1126        "An exported capability has no provider in its context.",
1127        &["exports_decl"],
1128    ),
1129    dg(
1130        "bynk.exports.conflicting_visibility",
1131        "A type is exported with conflicting visibilities.",
1132        &["exports_decl"],
1133    ),
1134    dg(
1135        "bynk.exports.derived_capability",
1136        "`exports capability` names a derived capability, whose instance stays with its context.",
1137        &["exports_decl"],
1138    ),
1139    dg(
1140        "bynk.exports.duplicate_export",
1141        "The same name is exported more than once.",
1142        &["exports_decl"],
1143    ),
1144    dg(
1145        "bynk.exports.duplicate_in_clause",
1146        "A name appears twice in one `exports` clause.",
1147        &["exports_decl"],
1148    ),
1149    dg(
1150        "bynk.exports.undeclared_capability",
1151        "`exports capability` names a capability that is not declared.",
1152        &["exports_decl"],
1153    ),
1154    dg(
1155        "bynk.exports.undeclared_type",
1156        "`exports` names a type that is not declared.",
1157        &["exports_decl"],
1158    ),
1159    warn(d(
1160        "bynk.fault.todo",
1161        "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).",
1162    )),
1163    dg(
1164        "bynk.fixture.binary_content",
1165        "A suite's `fixture` names a file that contains a NUL byte, so it is binary, not text.",
1166        &["fixture_decl"],
1167    ),
1168    dg(
1169        "bynk.fixture.duplicate",
1170        "A suite declares two `fixture`s of the same name.",
1171        &["fixture_decl"],
1172    ),
1173    dg(
1174        "bynk.fixture.invalid_encoding",
1175        "A suite's `fixture` names a file that is not valid UTF-8.",
1176        &["fixture_decl"],
1177    ),
1178    dg(
1179        "bynk.fixture.missing_file",
1180        "A suite's `fixture` names a file that is not in the project's `fixtures/` folder.",
1181        &["fixture_decl"],
1182    ),
1183    dg(
1184        "bynk.fixture.outside_fixtures_dir",
1185        "A suite's `fixture` names a file outside the project's `fixtures/` folder.",
1186        &["fixture_decl"],
1187    ),
1188    dg(
1189        "bynk.fixture.too_large",
1190        "A suite's `fixture` names a file over the 4 MiB limit for one fixture file.",
1191        &["fixture_decl"],
1192    ),
1193    dg(
1194        "bynk.fixture.unreadable_file",
1195        "A suite's `fixture` names a listed file that could not be read.",
1196        &["fixture_decl"],
1197    ),
1198    dg(
1199        "bynk.fixture.unsafe_path",
1200        "A suite's `fixture` path is empty, absolute or contains a `..` segment.",
1201        &["fixture_decl"],
1202    ),
1203    warn(dg(
1204        "bynk.fixture.unused",
1205        "A suite declares a `fixture` that none of its cases, properties or helpers uses (warning).",
1206        &["fixture_decl"],
1207    )),
1208    d(
1209        "bynk.fmt.comment_loss",
1210        "The formatter would drop a comment, so it leaves the file unchanged.",
1211    ),
1212    d(
1213        "bynk.fmt.mixed_comment_syntax",
1214        "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.",
1215    ),
1216    d(
1217        "bynk.fmt.roundtrip",
1218        "The formatter's output does not re-parse to the same program, so it leaves the file unchanged.",
1219    ),
1220    dg(
1221        "bynk.generics.ambiguous_instantiation",
1222        "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).",
1223        &["fn_decl"],
1224    ),
1225    dg(
1226        "bynk.generics.bound_on_capability_op",
1227        "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).",
1228        &["capability_op"],
1229    ),
1230    dg(
1231        "bynk.generics.codable_op_return",
1232        "A capability operation\'s `Codable` type parameter appears in its return type. A `Codable` parameter is encoded at the call site; decoding a provider\'s reply raises a question this slice does not answer (what a failed decode of stored data means), so typed reads are deferred (constrained-generics slice 3).",
1233        &["capability_op"],
1234    ),
1235    dg(
1236        "bynk.generics.duplicate_type_param",
1237        "A `type` or `fn` declares the same type-parameter name more than once (v0.157, ADR 0183).",
1238        &[],
1239    ),
1240    dg(
1241        "bynk.generics.generic_non_record",
1242        "A `type` declaration carries type parameters on a refined or opaque body; only a record (`type Name[T] = { … }`) or sum (`type Name[T] = | … | …`) body may be generic (v0.157/#593, ADRs 0183/0197).",
1243        &["type_decl"],
1244    ),
1245    dg(
1246        "bynk.generics.generic_record_at_boundary",
1247        "A `Val[…]` fabricates a value of a generic type; per-instantiation value fabrication is not yet wired (ADR 0197). Since v0.174 a generic-record instantiation may otherwise cross a boundary through its monomorphised codec.",
1248        &[],
1249    ),
1250    dg(
1251        "bynk.generics.generic_sum_embeds",
1252        "A generic sum type carries an `embeds` clause; embedding into a generic sum is not supported (#593).",
1253        &["type_decl"],
1254    ),
1255    dg(
1256        "bynk.generics.method_on_generic_type",
1257        "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).",
1258        &["fn_decl"],
1259    ),
1260    dg(
1261        "bynk.generics.missing_codable_bound",
1262        "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).",
1263        &["fn_decl"],
1264    ),
1265    dg(
1266        "bynk.generics.missing_eq_bound",
1267        "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).",
1268        &["fn_decl"],
1269    ),
1270    dg(
1271        "bynk.generics.missing_key_bound",
1272        "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).",
1273        &["fn_decl"],
1274    ),
1275    dg(
1276        "bynk.generics.missing_ord_bound",
1277        "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).",
1278        &["fn_decl"],
1279    ),
1280    dg(
1281        "bynk.generics.recursive_generic_at_boundary",
1282        "A recursive generic record (one that transitively contains itself, through any wrapper or generic argument) appears at a boundary; it has no finite set of monomorphised codecs, so it is not yet boundary-serialisable (ADR 0197).",
1283        &[],
1284    ),
1285    warn(dg(
1286        "bynk.generics.redundant_eq_bound",
1287        "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).",
1288        &["fn_decl"],
1289    )),
1290    dg(
1291        "bynk.generics.type_arg_count",
1292        "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).",
1293        &["applied_type_ref"],
1294    ),
1295    dg(
1296        "bynk.generics.type_arg_mismatch",
1297        "Inferred or explicit type arguments conflict, have the wrong arity, target a non-generic function, or a type parameter shadows a declared type.",
1298        &["call"],
1299    ),
1300    dg(
1301        "bynk.generics.uninferable_type_arg",
1302        "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 in v0.20a.",
1303        &["call"],
1304    ),
1305    dg(
1306        "bynk.generics.unknown_constraint",
1307        "A bound names something that is not a constraint; `Eq` is the only one.",
1308        &["type_param"],
1309    ),
1310    dg(
1311        "bynk.generics.unknown_where_param",
1312        "A method's `where` clause bounds a name that is not a type parameter of the method or of its receiver type.",
1313        &["where_clause"],
1314    ),
1315    dg(
1316        "bynk.given.cross_context_unknown_capability",
1317        "`given B.Cap` names a capability the consumed context does not export.",
1318        &["given_clause"],
1319    ),
1320    dg(
1321        "bynk.given.fn_outside_context",
1322        "A function in a commons (or a suite) declares `given`; only a context function can.",
1323        &["given_clause"],
1324    ),
1325    dg(
1326        "bynk.given.fn_unsupported",
1327        "A `given` clause on a method, on a function that does not return `Effect[T]`, or naming `Events`.",
1328        &["given_clause"],
1329    ),
1330    dg(
1331        "bynk.given.missing_for_call",
1332        "A call to a function that declares `given` from a body that does not declare those capabilities.",
1333        &["given_clause"],
1334    ),
1335    dg(
1336        "bynk.given.undeclared_capability",
1337        "A handler uses a capability it did not declare with `given`.",
1338        &["given_clause"],
1339    ),
1340    dg(
1341        "bynk.given.unknown_capability",
1342        "`given` names a capability that does not exist.",
1343        &["given_clause"],
1344    ),
1345    warn(dg(
1346        "bynk.given.unused_capability",
1347        "A `given` capability is never used (warning).",
1348        &["given_clause"],
1349    )),
1350    d(
1351        "bynk.held.branch_divergence",
1352        "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).",
1353    ),
1354    d(
1355        "bynk.held.consume_on_borrow",
1356        "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).",
1357    ),
1358    d(
1359        "bynk.held.leak",
1360        "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).",
1361    ),
1362    d(
1363        "bynk.held.query_accessor_on_held_map",
1364        "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.",
1365    ),
1366    d(
1367        "bynk.held.unsupported_map_op",
1368        "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).",
1369    ),
1370    d(
1371        "bynk.held.unsupported_storage",
1372        "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).",
1373    ),
1374    d(
1375        "bynk.held.use_after_consume",
1376        "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).",
1377    ),
1378    d(
1379        "bynk.history.not_an_agent",
1380        "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).",
1381    ),
1382    d(
1383        "bynk.history.not_generable",
1384        "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).",
1385    ),
1386    d(
1387        "bynk.history.outside_property",
1388        "`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).",
1389    ),
1390    d(
1391        "bynk.history.restates_invariant",
1392        "A history property merely re-checks a guarantee a declared `invariant`/`transition` already enforces on every reached state (testing track slice 7, ADR 0155).",
1393    ),
1394    dg(
1395        "bynk.http.body_on_get_or_delete",
1396        "A GET or DELETE handler declares a `body` parameter.",
1397        &["http_handler"],
1398    ),
1399    d(
1400        "bynk.http.cache_bad_immutable",
1401        "A `@cache` annotation's `immutable` is not a `Bool` literal.",
1402    ),
1403    d(
1404        "bynk.http.cache_bad_max_age",
1405        "A `@cache` annotation's `maxAge` is missing or not a positive `Duration` literal.",
1406    ),
1407    d(
1408        "bynk.http.cache_bad_scope",
1409        "A `@cache` annotation's `scope` is not `public` or `private`.",
1410    ),
1411    d(
1412        "bynk.http.cache_duplicate",
1413        "A handler carries more than one `@cache` annotation.",
1414    ),
1415    d(
1416        "bynk.http.cache_max_age_fractional_seconds",
1417        "A `@cache` annotation's `maxAge` is positive but does not resolve to a whole number of seconds.",
1418    ),
1419    d(
1420        "bynk.http.cache_on_non_get",
1421        "A `@cache` annotation is placed on a handler that is not `on http GET`.",
1422    ),
1423    d(
1424        "bynk.http.cache_unknown_arg",
1425        "A `@cache` annotation has an argument outside the closed set (`maxAge`/`scope`/`immutable`).",
1426    ),
1427    d(
1428        "bynk.http.cors_invalid_field",
1429        "A `cors` policy field (`headers`/`credentials`/`maxAge`) has the wrong value shape.",
1430    ),
1431    d(
1432        "bynk.http.cors_invalid_origins",
1433        "A `cors` policy's `origins` is missing, empty, or not a list of string literals.",
1434    ),
1435    d(
1436        "bynk.http.cors_not_http",
1437        "A `cors { }` policy appears on a service that is not `from http`.",
1438    ),
1439    d(
1440        "bynk.http.cors_unknown_field",
1441        "A `cors { }` policy declares a field outside the closed set.",
1442    ),
1443    d(
1444        "bynk.http.cors_wildcard_credentials",
1445        "A `cors` policy combines `credentials: true` with the wildcard origin `[\"*\"]`.",
1446    ),
1447    dg(
1448        "bynk.http.duplicate_rejected",
1449        "A `from http` service declares `on rejected` more than once.",
1450        &["rejected_handler"],
1451    ),
1452    dg(
1453        "bynk.http.duplicate_route",
1454        "Two handlers share the same method and route.",
1455        &["http_handler"],
1456    ),
1457    d(
1458        "bynk.http.error_status_position",
1459        "An `ErrorStatus` name is used anywhere but as `RawError`'s first argument.",
1460    ),
1461    dg(
1462        "bynk.http.extra_param",
1463        "A handler parameter is not a path parameter, `body`, `headers` or `query`.",
1464        &["http_handler"],
1465    ),
1466    warn(d(
1467        "bynk.http.header_question_not_found",
1468        "`?` 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`).",
1469    )),
1470    dg(
1471        "bynk.http.headers_wrong_type",
1472        "An HTTP handler's `headers` parameter is not typed `RequestHeaders`.",
1473        &["http_handler"],
1474    ),
1475    dg(
1476        "bynk.http.invalid_path",
1477        "An HTTP route path is malformed.",
1478        &["http_handler"],
1479    ),
1480    d(
1481        "bynk.http.json_duplicate",
1482        "A handler carries more than one `@json` annotation.",
1483    ),
1484    d(
1485        "bynk.http.json_invalid_arg",
1486        "A `@json` annotation's `options` argument is missing or is not `tagged` or `plain`.",
1487    ),
1488    d(
1489        "bynk.http.json_invalid_field",
1490        "A `json { }` policy's `options` is not `tagged` or `plain`.",
1491    ),
1492    d(
1493        "bynk.http.json_not_http",
1494        "A `json { }` policy appears on a service that is not `from http`.",
1495    ),
1496    d(
1497        "bynk.http.json_on_non_http",
1498        "A `@json` annotation is placed on a handler that is not `on http`.",
1499    ),
1500    d(
1501        "bynk.http.json_unknown_arg",
1502        "A `@json` annotation has an argument outside the closed set (`options`).",
1503    ),
1504    d(
1505        "bynk.http.json_unknown_field",
1506        "A `json { }` policy declares a field outside the closed set (`options`).",
1507    ),
1508    d(
1509        "bynk.http.limit_bad_max_body",
1510        "A `@limit` annotation's `maxBody` is missing or not a positive `Int` literal.",
1511    ),
1512    d(
1513        "bynk.http.limit_duplicate",
1514        "A handler carries more than one `@limit` annotation.",
1515    ),
1516    d(
1517        "bynk.http.limit_on_bodyless",
1518        "A `@limit` annotation is placed on a handler that takes no body (a GET or DELETE).",
1519    ),
1520    d(
1521        "bynk.http.limit_unknown_arg",
1522        "A `@limit` annotation has an argument outside the closed set (`maxBody`).",
1523    ),
1524    d(
1525        "bynk.http.limits_invalid_field",
1526        "A `limits` policy field (`maxBody`) has the wrong value shape.",
1527    ),
1528    d(
1529        "bynk.http.limits_not_http",
1530        "A `limits { }` policy appears on a service that is not `from http`.",
1531    ),
1532    d(
1533        "bynk.http.limits_unknown_field",
1534        "A `limits { }` policy declares a field outside the closed set.",
1535    ),
1536    dg(
1537        "bynk.http.path_param_not_stringy",
1538        "A path parameter's type is not constructible from a string.",
1539        &["http_handler"],
1540    ),
1541    dg(
1542        "bynk.http.query_field_not_stringy",
1543        "A field of an HTTP handler's `query` record has a type a query string cannot carry.",
1544        &["http_handler"],
1545    ),
1546    dg(
1547        "bynk.http.query_not_http",
1548        "A `RequestQuery` appears on a handler that is not an HTTP route.",
1549        &["http_handler"],
1550    ),
1551    dg(
1552        "bynk.http.query_wrong_type",
1553        "An HTTP handler's `query` parameter is neither a record type nor `RequestQuery`.",
1554        &["http_handler"],
1555    ),
1556    d(
1557        "bynk.http.raw_bad_content_type",
1558        "A `@raw` annotation's `contentType` is missing or not a `type/subtype` (or `\"*/*\"`) string literal.",
1559    ),
1560    d(
1561        "bynk.http.raw_body_not_bytes",
1562        "The `body` of a `@raw` handler is not typed `Bytes`.",
1563    ),
1564    d(
1565        "bynk.http.raw_body_unbounded",
1566        "A `@raw` route has no request-body cap (no `@limit` and no service `limits`).",
1567    ),
1568    d(
1569        "bynk.http.raw_duplicate",
1570        "A handler carries more than one `@raw` annotation.",
1571    ),
1572    d(
1573        "bynk.http.raw_error_status",
1574        "`RawError`'s first argument is not an `ErrorStatus` name (a 4xx or 5xx `HttpResult` variant name).",
1575    ),
1576    d(
1577        "bynk.http.raw_on_bodyless",
1578        "A `@raw` annotation is placed on a handler that takes no body.",
1579    ),
1580    d(
1581        "bynk.http.raw_unknown_arg",
1582        "A `@raw` annotation has an argument outside the closed set (`contentType`).",
1583    ),
1584    dg(
1585        "bynk.http.rejected_signature",
1586        "An `on rejected` handler is not `on rejected(why: BoundaryRejection) -> HttpResult[()]` with no `by` and no `given`.",
1587        &["rejected_handler"],
1588    ),
1589    dg(
1590        "bynk.http.reserved_prefix",
1591        "A route uses the reserved `/_bynk/` prefix.",
1592        &["http_handler"],
1593    ),
1594    dg(
1595        "bynk.http.return_not_effect_http_result",
1596        "An HTTP handler does not return `Effect[HttpResult[T]]`.",
1597        &["http_handler"],
1598    ),
1599    d(
1600        "bynk.http.security_invalid_field",
1601        "A `security` policy field (`hsts`/`nosniff`) has the wrong value shape.",
1602    ),
1603    d(
1604        "bynk.http.security_not_http",
1605        "A `security { }` policy appears on a service that is not `from http`.",
1606    ),
1607    d(
1608        "bynk.http.security_unknown_field",
1609        "A `security { }` policy declares a field outside the closed set.",
1610    ),
1611    dg(
1612        "bynk.http.unbound_path_param",
1613        "A `:name` route segment has no matching handler parameter.",
1614        &["http_handler"],
1615    ),
1616    d(
1617        "bynk.http.unknown_handler_annotation",
1618        "A handler carries an annotation outside the closed set (`@cache`/`@limit`).",
1619    ),
1620    d(
1621        "bynk.index.bad_argument",
1622        "An `@indexed` argument is not a `by: <field>` label.",
1623    ),
1624    warn(d(
1625        "bynk.index.missing",
1626        "A query filters a map by equality on a field that is not `@indexed` (a perf-hint warning).",
1627    )),
1628    d(
1629        "bynk.index.unkeyable_key",
1630        "An `@indexed(by: k)` field is not value-keyable.",
1631    ),
1632    d(
1633        "bynk.index.unknown_key",
1634        "An `@indexed(by: k)` field is not a field of the map's value type.",
1635    ),
1636    warn(d(
1637        "bynk.index.unused",
1638        "A declared `@indexed(by: k)` is never used by an equality filter (a hygiene warning).",
1639    )),
1640    d(
1641        "bynk.invariant.cross_agent_reference",
1642        "An invariant predicate references another agent; invariants are per-agent.",
1643    ),
1644    d(
1645        "bynk.invariant.duplicate_name",
1646        "An agent declares two invariants with the same name.",
1647    ),
1648    d(
1649        "bynk.invariant.impure_predicate",
1650        "An invariant predicate uses an effectful or test-only construct.",
1651    ),
1652    d(
1653        "bynk.invariant.not_bool",
1654        "An invariant predicate does not have type `Bool`.",
1655    ),
1656    d(
1657        "bynk.json.encode_plain_generic",
1658        "`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.",
1659    ),
1660    d(
1661        "bynk.json.nested_option_plain",
1662        "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`.",
1663    ),
1664    dg(
1665        "bynk.lambda.unannotated_param",
1666        "A lambda parameter has no type annotation in a position where no function type is expected to infer it from.",
1667        &["lambda_expr"],
1668    ),
1669    dg(
1670        "bynk.lex.bad_escape",
1671        "An invalid escape sequence in a string literal.",
1672        &["string_literal"],
1673    ),
1674    dg(
1675        "bynk.lex.bad_unicode_escape",
1676        "A `\\u{…}` escape names a surrogate or a value above U+10FFFF.",
1677        &["string_literal"],
1678    ),
1679    dg(
1680        "bynk.lex.decimal_literal_too_large",
1681        "A decimal literal has more than 100 fraction digits or more than 1000 characters, the most any `Decimal` may have (#2622).",
1682        &["decimal_literal"],
1683    ),
1684    dg(
1685        "bynk.lex.float_literal_overflow",
1686        "A float literal does not fit a finite 64-bit float.",
1687        &["float_literal"],
1688    ),
1689    dg(
1690        "bynk.lex.integer_overflow",
1691        "An integer literal is outside the `Int` range, the JS safe integers ±(2^53 − 1).",
1692        &["number_literal"],
1693    ),
1694    dg(
1695        "bynk.lex.interpolation_too_deep",
1696        "A string interpolation `\\(…)` nests deeper than the lexer's fixed limit.",
1697        &["string_literal"],
1698    ),
1699    d(
1700        "bynk.lex.legacy_comment",
1701        "A `--` line comment, the spelling before #2203; a comment is `//` (auto-fixable; `bynk fmt` rewrites it).",
1702    ),
1703    d(
1704        "bynk.lex.legacy_doc_line",
1705        "A `--|` one-line doc, the spelling before #2203; a one-line doc is `--- text` (auto-fixable; `bynk fmt` rewrites it).",
1706    ),
1707    dg(
1708        "bynk.lex.multiline_close_not_own_line",
1709        "A `\"\"\"` inside a multi-line string literal is not on a line of its own.",
1710        &["string_literal"],
1711    ),
1712    dg(
1713        "bynk.lex.multiline_in_hole",
1714        "A multi-line string literal appears inside an interpolation hole, which must close on its own line.",
1715        &["string_literal"],
1716    ),
1717    dg(
1718        "bynk.lex.multiline_indent",
1719        "A line of a multi-line string literal is indented less than its closing `\"\"\"`.",
1720        &["string_literal"],
1721    ),
1722    dg(
1723        "bynk.lex.multiline_open",
1724        "The opening `\"\"\"` of a multi-line string literal is not followed by a newline, or by a language tag (`\"\"\"sql`) and a newline.",
1725        &["string_literal"],
1726    ),
1727    d(
1728        "bynk.lex.slash_doc",
1729        "A `///` doc comment first on its line; a Bynk doc is `--- text` or a `---` block (auto-fixable).",
1730    ),
1731    d(
1732        "bynk.lex.unclosed_doc_block",
1733        "A documentation block is not closed.",
1734    ),
1735    d(
1736        "bynk.lex.unexpected_character",
1737        "An unexpected character in the source.",
1738    ),
1739    dg(
1740        "bynk.lex.unterminated_interpolation",
1741        "An interpolation hole `\\(…)` is not closed on its line.",
1742        &["string_literal"],
1743    ),
1744    dg(
1745        "bynk.lex.unterminated_string",
1746        "A string literal is not terminated.",
1747        &["string_literal"],
1748    ),
1749    warn(d(
1750        "bynk.list.deprecated_function",
1751        "A `bynk.list` free function (`map`/`filter`/`find`/`any`/`all`) is deprecated in favour of the `List` method form (warning; auto-fixable).",
1752    )),
1753    d(
1754        "bynk.locale.multiple_message_bundles",
1755        "A context consumes `Locale` but its direct `uses` reaches two or more message-bundle commons — there is no single bundle to negotiate against.",
1756    ),
1757    d(
1758        "bynk.messages.format_mismatch",
1759        "A code's placeholder is formatted as a different ICU kind (plain/plural/select/number/date) across declared locales.",
1760    ),
1761    d(
1762        "bynk.messages.incomplete",
1763        "A locale is missing a code the reference locale declares.",
1764    ),
1765    d(
1766        "bynk.messages.invalid_locale_tag",
1767        "A `messages` block's locale tag is not a valid `LocaleTag` (e.g. `messages \"xx\"` where `xx` doesn't match the tag pattern).",
1768    ),
1769    d(
1770        "bynk.messages.malformed_icu_syntax",
1771        "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).",
1772    ),
1773    d(
1774        "bynk.messages.missing_locale_dependency",
1775        "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.",
1776    ),
1777    d(
1778        "bynk.messages.missing_reference",
1779        "A message bundle has no `@reference` block.",
1780    ),
1781    d(
1782        "bynk.messages.multiple_reference",
1783        "A message bundle has more than one `@reference` block.",
1784    ),
1785    d(
1786        "bynk.messages.outside_commons",
1787        "A `messages` declaration appears outside a commons.",
1788    ),
1789    d(
1790        "bynk.messages.placeholder_mismatch",
1791        "A locale's template for a code uses a different set of `{name}` placeholders than the reference locale's.",
1792    ),
1793    d(
1794        "bynk.namespace.reserved",
1795        "A user unit is named `bynk` or `bynk.*`; the `bynk` root is reserved for the toolchain.",
1796    ),
1797    d(
1798        "bynk.observe.impure_with",
1799        "A `with` predicate uses an effectful or test-only construct; it must be pure.",
1800    ),
1801    d(
1802        "bynk.observe.not_a_seam",
1803        "An observation targets a capability the unit under test does not consume.",
1804    ),
1805    d(
1806        "bynk.observe.trace_outside_test",
1807        "`trace(Cap.op)` appears outside a `case` body.",
1808    ),
1809    d(
1810        "bynk.observe.unknown_op",
1811        "An observation names an operation the capability does not declare.",
1812    ),
1813    d(
1814        "bynk.observe.with_not_bool",
1815        "A `with` predicate does not have type `Bool`.",
1816    ),
1817    d(
1818        "bynk.package.alias_shadows_unit",
1819        "A dependency alias in `[dependencies]` is also the first segment of one of the project's own units, so `<alias>.…` would be ambiguous.",
1820    ),
1821    d(
1822        "bynk.package.checksum_mismatch",
1823        "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.",
1824    ),
1825    d(
1826        "bynk.package.dependency_cycle",
1827        "The package graph has a cycle: a dependency depends, directly or not, on itself or on the project.",
1828    ),
1829    d(
1830        "bynk.package.dependency_not_found",
1831        "A path dependency's directory has no readable `bynk.toml`, its `bynk.toml` is invalid, or it has no `[package]`.",
1832    ),
1833    d(
1834        "bynk.package.dev_dependency_in_source",
1835        "A commons, context or adapter reaches a `[dev-dependencies]` alias, which only a suite may use.",
1836    ),
1837    d(
1838        "bynk.package.duplicate_source",
1839        "One package is reached from two different directories; a build holds one copy of each package.",
1840    ),
1841    d(
1842        "bynk.package.git_failed",
1843        "`git` couldn't clone, fetch or check out a git dependency, or the revision it names doesn't exist.",
1844    ),
1845    d(
1846        "bynk.package.lock_invalid",
1847        "`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.",
1848    ),
1849    d(
1850        "bynk.package.lock_out_of_date",
1851        "`--locked` was given, and resolving the manifests would change `bynk.lock`.",
1852    ),
1853    d(
1854        "bynk.package.name_mismatch",
1855        "A path dependency's `package` names a different package than the directory's `[package] name`.",
1856    ),
1857    d(
1858        "bynk.package.not_fetched",
1859        "A git dependency has no `bynk.lock` entry, or its store entry is missing; `bynk fetch` fetches it (refused under `--offline`).",
1860    ),
1861    d(
1862        "bynk.package.unit_not_exported",
1863        "A `uses` or `consumes` reaches a unit its dependency declares but doesn't list in `[package] exports`.",
1864    ),
1865    d(
1866        "bynk.package.unknown_unit",
1867        "A `uses` or `consumes` names, through a dependency alias, a unit the dependency doesn't declare.",
1868    ),
1869    d(
1870        "bynk.package.unsafe_source",
1871        "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).",
1872    ),
1873    d(
1874        "bynk.package.unsupported_in_dependency",
1875        "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.",
1876    ),
1877    d(
1878        "bynk.package.version_conflict",
1879        "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.",
1880    ),
1881    dg(
1882        "bynk.par.invalid_statement",
1883        "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.",
1884        &["par_stmt"],
1885    ),
1886    dg(
1887        "bynk.par.question_in_join",
1888        "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.",
1889        &["par_stmt"],
1890    ),
1891    dg(
1892        "bynk.par.sibling_name",
1893        "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.",
1894        &["par_stmt"],
1895    ),
1896    warn(dg(
1897        "bynk.par.single_binding",
1898        "A `par { … }` block has a single binding, which is a plain `let x <- e` with extra syntax (warning).",
1899        &["par_stmt"],
1900    )),
1901    d(
1902        "bynk.parse.clause_after_statement",
1903        "A `stub` or `env` clause came after a statement in a test case; they lead the case body.",
1904    ),
1905    dg(
1906        "bynk.parse.const_missing_type",
1907        "A `const` declaration has no type annotation; a constant's type is always written (`const Name: Type = …`).",
1908        &["const_decl"],
1909    ),
1910    dg(
1911        "bynk.parse.consumes_after_decls",
1912        "`consumes` appears after other declarations.",
1913        &["consumes_decl"],
1914    ),
1915    d(
1916        "bynk.parse.dangling_handler_annotation",
1917        "A handler-position annotation (e.g. `@cache`) is not followed by an `on` handler.",
1918    ),
1919    d(
1920        "bynk.parse.doc_block_contains_code",
1921        "A documentation block's content (outside Markdown code fences) parses as declarations, so a pair of dash dividers has turned code into documentation.",
1922    ),
1923    dg(
1924        "bynk.parse.duplicate_cors",
1925        "A service declares more than one `cors { }` policy.",
1926        &["service_decl"],
1927    ),
1928    dg(
1929        "bynk.parse.duplicate_json",
1930        "A service declares more than one `json { }` policy.",
1931        &["service_decl"],
1932    ),
1933    dg(
1934        "bynk.parse.duplicate_limits",
1935        "A service declares more than one `limits { }` policy.",
1936        &["service_decl"],
1937    ),
1938    dg(
1939        "bynk.parse.duplicate_security",
1940        "A service declares more than one `security { }` policy.",
1941        &["service_decl"],
1942    ),
1943    dg(
1944        "bynk.parse.empty_agent",
1945        "An `agent` body is empty.",
1946        &["agent_decl"],
1947    ),
1948    dg(
1949        "bynk.parse.empty_capability",
1950        "A `capability` body is empty.",
1951        &["capability_decl"],
1952    ),
1953    d(
1954        "bynk.parse.empty_interpolation",
1955        "An interpolation hole `\\(…)` contains no expression.",
1956    ),
1957    dg(
1958        "bynk.parse.empty_match",
1959        "A `match` has no arms.",
1960        &["match_expr"],
1961    ),
1962    dg(
1963        "bynk.parse.empty_service",
1964        "A `service` body is empty.",
1965        &["service_decl"],
1966    ),
1967    d(
1968        "bynk.parse.event_pattern_empty",
1969        "A `from Events(E { ... })` subscription pattern listed no fields — use `from Events(E)` (no braces) for an unfiltered subscription.",
1970    ),
1971    dg(
1972        "bynk.parse.expected_agent_key",
1973        "Expected a `key` declaration in an agent.",
1974        &["agent_decl"],
1975    ),
1976    d(
1977        "bynk.parse.expected_agent_storage",
1978        "An agent declares no storage — it has no `store` fields.",
1979    ),
1980    dg(
1981        "bynk.parse.expected_base_type",
1982        "Expected a base type.",
1983        &["base_type"],
1984    ),
1985    dg(
1986        "bynk.parse.expected_capability_op",
1987        "Expected a capability operation.",
1988        &["capability_op"],
1989    ),
1990    d("bynk.parse.expected_expression", "Expected an expression."),
1991    dg(
1992        "bynk.parse.expected_handler",
1993        "Expected a handler.",
1994        &["handler"],
1995    ),
1996    d("bynk.parse.expected_item", "Expected a declaration."),
1997    dg(
1998        "bynk.parse.expected_predicate",
1999        "Expected a refinement predicate.",
2000        &["refinement"],
2001    ),
2002    dg(
2003        "bynk.parse.expected_provider_op",
2004        "Expected a provider operation.",
2005        &["provider_op"],
2006    ),
2007    d("bynk.parse.expected_token", "Expected a specific token."),
2008    d("bynk.parse.expected_type", "Expected a type."),
2009    d(
2010        "bynk.parse.expected_unit_header",
2011        "Expected a `commons` or `context` header.",
2012    ),
2013    dg(
2014        "bynk.parse.expected_visibility",
2015        "Expected a visibility keyword.",
2016        &["exports_decl"],
2017    ),
2018    dg(
2019        "bynk.parse.exports_after_decls",
2020        "`exports` appears after other declarations.",
2021        &["exports_decl"],
2022    ),
2023    d(
2024        "bynk.parse.extra_tokens",
2025        "Unexpected tokens after an otherwise complete construct.",
2026    ),
2027    dg(
2028        "bynk.parse.generic_arg_count",
2029        "Wrong number of generic type arguments.",
2030        &["generic_type_ref"],
2031    ),
2032    dg(
2033        "bynk.parse.handler_in_agent",
2034        "A protocol handler (`on GET`/`schedule`/`message`) was declared in an agent.",
2035        &["handler"],
2036    ),
2037    d(
2038        "bynk.parse.invariant_after_handler",
2039        "An `invariant` was declared after a handler; invariants precede handlers.",
2040    ),
2041    dg(
2042        "bynk.parse.keyword_field_shorthand",
2043        "A reserved keyword was used as a field shorthand, which would bind a variable of that name.",
2044        &["identifier"],
2045    ),
2046    dg(
2047        "bynk.parse.lambda_pattern_annotation",
2048        "A lambda parameter with a record pattern carries a type annotation; the pattern's type name already gives the parameter's type.",
2049        &["lambda_param"],
2050    ),
2051    dg(
2052        "bynk.parse.lambda_pattern_not_record",
2053        "A lambda parameter is a pattern other than a record pattern; only an irrefutable record pattern may stand in for a name.",
2054        &["lambda_param"],
2055    ),
2056    dg(
2057        "bynk.parse.lambda_pattern_refutable",
2058        "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.",
2059        &["lambda_param"],
2060    ),
2061    dg(
2062        "bynk.parse.let_else_on_binding",
2063        "An `else` follows a plain `let name = …` binding, which matches every value, so the `else` could never run.",
2064        &["let_stmt", "effect_let_stmt"],
2065    ),
2066    hint(d(
2067        "bynk.parse.let_else_staircase",
2068        "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).",
2069    )),
2070    dg(
2071        "bynk.parse.let_pattern_annotation",
2072        "A `let` with a pattern carries a type annotation; the pattern's names take their types from the value.",
2073        &["let_else_stmt"],
2074    ),
2075    dg(
2076        "bynk.parse.let_pattern_without_else",
2077        "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.",
2078        &["let_else_stmt"],
2079    ),
2080    dg(
2081        "bynk.parse.list_rest_not_last",
2082        "A `..` in a list pattern is not the final element; suffix forms such as `[.., last]` are not available.",
2083        &["list_pattern"],
2084    ),
2085    dg(
2086        "bynk.parse.malformed_float_literal",
2087        "A float literal is missing a digit on one side of the `.` (`1.`, `.5`).",
2088        &["float_literal"],
2089    ),
2090    dg(
2091        "bynk.parse.match_ends_block",
2092        "A `match` ends the block it is in, because a block has no expression statements; a second `match` straight after it cannot follow.",
2093        &["block"],
2094    ),
2095    d(
2096        "bynk.parse.migrate_after_handler",
2097        "A `migrate` step is declared after an agent handler; migration steps precede the handlers.",
2098    ),
2099    d(
2100        "bynk.parse.migrate_item",
2101        "A `migrate` step's body holds something other than `field := value`, `let` or `drop field`.",
2102    ),
2103    d(
2104        "bynk.parse.multiple_docs",
2105        "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.",
2106    ),
2107    d(
2108        "bynk.parse.nesting_too_deep",
2109        "An expression or type nests deeper than the parser's fixed limit.",
2110    ),
2111    d(
2112        "bynk.parse.no_remainder_operator",
2113        "`%` is not an operator; use `Int.rem` (the dividend's sign) or `Int.mod` (the divisor's).",
2114    ),
2115    dg(
2116        "bynk.parse.non_associative",
2117        "A non-associative operator was chained (e.g. `a == b == c`).",
2118        &["binary_expr"],
2119    ),
2120    warn(d(
2121        "bynk.parse.orphan_doc_block",
2122        "A documentation block is not attached to a declaration (warning).",
2123    )),
2124    dg(
2125        "bynk.parse.policy_order",
2126        "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`.",
2127        &["service_decl"],
2128    ),
2129    dg(
2130        "bynk.parse.record_pattern_in_is_unparenthesised",
2131        "A record pattern after `is` is not parenthesised — write `x is (T { f, .. })`.",
2132        &["record_pattern"],
2133    ),
2134    dg(
2135        "bynk.parse.record_pattern_without_rest",
2136        "A record pattern does not end with `..`; every record pattern is open.",
2137        &["record_pattern"],
2138    ),
2139    dg(
2140        "bynk.parse.refined_pattern_inner",
2141        "A refined pattern's inner form is something other than `_`.",
2142        &["refined_pattern"],
2143    ),
2144    dg(
2145        "bynk.parse.reserved_keyword",
2146        "A reserved keyword was used as an identifier.",
2147        &["identifier"],
2148    ),
2149    dg(
2150        "bynk.parse.self_outside_method",
2151        "`self` used outside a method or handler.",
2152        &["self_expr"],
2153    ),
2154    d(
2155        "bynk.parse.storage_after_phase",
2156        "Agent storage (`state` / `store`) is declared after the invariants or handlers.",
2157    ),
2158    d(
2159        "bynk.parse.transition_after_handler",
2160        "A `transition` is declared after an agent handler; step invariants precede the handlers.",
2161    ),
2162    d(
2163        "bynk.parse.unexpected_adapter",
2164        "An `adapter` appeared where it is not allowed.",
2165    ),
2166    dg(
2167        "bynk.parse.unexpected_context",
2168        "A `context` appeared where it is not allowed.",
2169        &["context_decl"],
2170    ),
2171    d("bynk.parse.unexpected_eof", "Unexpected end of input."),
2172    dg(
2173        "bynk.parse.unexpected_suite",
2174        "A `suite` appeared where it is not allowed.",
2175        &["suite_decl"],
2176    ),
2177    d(
2178        "bynk.parse.unknown_effect_method",
2179        "An unknown method on `Effect`.",
2180    ),
2181    dg(
2182        "bynk.parse.unknown_handler_kind",
2183        "An unknown handler form (expected `call`, an HTTP method, `schedule`, or `message`).",
2184        &["handler"],
2185    ),
2186    dg(
2187        "bynk.parse.unknown_predicate",
2188        "An unknown refinement predicate.",
2189        &["predicate_name"],
2190    ),
2191    d(
2192        "bynk.parse.unknown_tier",
2193        "A `case`/`suite` `as <tier>` clause names something other than `unit`, `integration`, or `system`.",
2194    ),
2195    dg(
2196        "bynk.parse.uses_after_decls",
2197        "`uses` appears after other declarations.",
2198        &["uses_decl"],
2199    ),
2200    dg(
2201        "bynk.parse.variant_name_case",
2202        "A sum-type or enum variant name is not capitalised.",
2203        &["sum_variant", "enum_type"],
2204    ),
2205    d(
2206        "bynk.project.contracts_lock_corrupt",
2207        "`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.",
2208    ),
2209    warn(d(
2210        "bynk.project.contracts_lock_oversized",
2211        "`bynk.contracts.lock` has one service accepting more older contracts than the build keeps comfortably (warning).",
2212    )),
2213    warn(d(
2214        "bynk.project.contracts_lock_stale",
2215        "`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).",
2216    )),
2217    warn(d(
2218        "bynk.project.duplicate_compatibility_flag",
2219        "`bynk.toml`'s `[workers] compatibility_flags` lists a flag twice, or one every Bynk Worker already has; the duplicate is dropped (warning).",
2220    )),
2221    d(
2222        "bynk.project.duplicate_module_doc",
2223        "More than one file of a multi-file unit carries a module doc.",
2224    ),
2225    d(
2226        "bynk.project.export_context",
2227        "`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.",
2228    ),
2229    d(
2230        "bynk.project.export_unknown",
2231        "`bynk.toml`'s `[package] exports` lists a name that isn't a commons or adapter the project declares.",
2232    ),
2233    d(
2234        "bynk.project.file_and_directory",
2235        "A unit exists as both a file and a directory.",
2236    ),
2237    d(
2238        "bynk.project.inconsistent_commons_name",
2239        "A source file's path does not match its declared name.",
2240    ),
2241    d(
2242        "bynk.project.kind_conflict",
2243        "A name is declared as both a commons and a context.",
2244    ),
2245    d(
2246        "bynk.project.no_root",
2247        "No project root could be determined.",
2248    ),
2249    d(
2250        "bynk.project.no_sources",
2251        "The project contains no source files.",
2252    ),
2253    d(
2254        "bynk.project.read_failed",
2255        "A source file could not be read.",
2256    ),
2257    d(
2258        "bynk.project.schema_registry_corrupt",
2259        "`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.",
2260    ),
2261    warn(d(
2262        "bynk.project.unstable_not_experimental",
2263        "`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).",
2264    )),
2265    d(
2266        "bynk.project.unstable_unknown_item",
2267        "`bynk.toml`'s `[unstable] allow` lists a path that names no standard-library unit, exported item or operation.",
2268    ),
2269    dg(
2270        "bynk.property.restates_refinement",
2271        "A `property` merely re-checks a refinement its type already guarantees.",
2272        &["for_all"],
2273    ),
2274    dg(
2275        "bynk.property.where_not_bool",
2276        "A `for all ... where` filter does not type to `Bool`.",
2277        &["for_all"],
2278    ),
2279    dg(
2280        "bynk.provider.agent_call_undeclared_capability",
2281        "A provider calls an agent handler that needs a capability the provider's `given` does not list.",
2282        &["provider_decl"],
2283    ),
2284    dg(
2285        "bynk.provider.dependency_cycle",
2286        "Providers form a capability dependency cycle through `given`.",
2287        &["provider_decl"],
2288    ),
2289    dg(
2290        "bynk.provider.extra_operation",
2291        "A `provides` block implements an operation not in the capability.",
2292        &["provider_decl"],
2293    ),
2294    dg(
2295        "bynk.provider.generic_op_requires_external",
2296        "A Bynk-bodied `provides` implements a capability operation that declares its own type parameter — only an external (bodiless) provider can.",
2297        &["provider_decl"],
2298    ),
2299    dg(
2300        "bynk.provider.missing_operation",
2301        "A `provides` block is missing a capability operation.",
2302        &["provider_decl"],
2303    ),
2304    dg(
2305        "bynk.provider.outside_context",
2306        "`provides` was declared outside a context.",
2307        &["provider_decl"],
2308    ),
2309    dg(
2310        "bynk.provider.signature_mismatch",
2311        "A `provides` operation's signature does not match the capability.",
2312        &["provider_decl"],
2313    ),
2314    dg(
2315        "bynk.provider.unknown_capability",
2316        "`provides` names a capability that does not exist.",
2317        &["provider_decl"],
2318    ),
2319    d(
2320        "bynk.query.join_key_mismatch",
2321        "A `joinOn`/`leftJoin` left and right key function return different types.",
2322    ),
2323    dg(
2324        "bynk.query.sum_needs_numeric",
2325        "A `sum`/`average` key function does not return a numeric type (`Int`, `Float`, or `Duration`).",
2326        &[],
2327    ),
2328    dg(
2329        "bynk.queue.bad_params",
2330        "An `on message` handler does not take exactly one `message` parameter.",
2331        &["queue_handler"],
2332    ),
2333    dg(
2334        "bynk.queue.duplicate_consumer",
2335        "Two `on message` handlers consume the same queue.",
2336        &["queue_handler"],
2337    ),
2338    dg(
2339        "bynk.queue.invalid_name",
2340        "A `from queue(\"…\")` binding has an empty queue name, or one Cloudflare refuses.",
2341        &["queue_handler"],
2342    ),
2343    dg(
2344        "bynk.queue.return_not_queue_result",
2345        "An `on message` handler does not return `Effect[QueueResult]`.",
2346        &["handler"],
2347    ),
2348    dg(
2349        "bynk.race.in_agent_handler",
2350        "`a.race(b)` was used in an agent handler, which has no execution context to hand the losing effect to.",
2351        &["method_call"],
2352    ),
2353    dg(
2354        "bynk.race.in_pure_context",
2355        "`a.race(b)` was used in a pure (non-effectful) context.",
2356        &["method_call"],
2357    ),
2358    dg(
2359        "bynk.race.outside_handler",
2360        "`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.",
2361        &["method_call"],
2362    ),
2363    dg(
2364        "bynk.record_spread.field_type_mismatch",
2365        "A record-spread override has the wrong type for the field.",
2366        &["record_spread"],
2367    ),
2368    dg(
2369        "bynk.record_spread.non_record_base",
2370        "The base of a record spread is not a record.",
2371        &["record_spread"],
2372    ),
2373    dg(
2374        "bynk.record_spread.type_mismatch",
2375        "A record spread's base is a different record type.",
2376        &["record_spread"],
2377    ),
2378    dg(
2379        "bynk.record_spread.unknown_field",
2380        "A record spread overrides a field the record does not have.",
2381        &["record_spread"],
2382    ),
2383    dg(
2384        "bynk.refine.literal_violates",
2385        "A literal does not satisfy the refined type's predicate.",
2386        &["refined_type"],
2387    ),
2388    d(
2389        "bynk.registry.account_refused",
2390        "`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).",
2391    ),
2392    d(
2393        "bynk.registry.bad_archive",
2394        "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.",
2395    ),
2396    d(
2397        "bynk.registry.bad_signature",
2398        "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).",
2399    ),
2400    d(
2401        "bynk.registry.http_failed",
2402        "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.",
2403    ),
2404    d(
2405        "bynk.registry.key_mismatch",
2406        "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`.",
2407    ),
2408    d(
2409        "bynk.registry.nonconformant",
2410        "`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.",
2411    ),
2412    d(
2413        "bynk.registry.publish_refused",
2414        "`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).",
2415    ),
2416    d(
2417        "bynk.registry.source_mismatch",
2418        "`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.",
2419    ),
2420    d(
2421        "bynk.registry.unavailable",
2422        "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.",
2423    ),
2424    d(
2425        "bynk.registry.withdrawn",
2426        "`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.",
2427    ),
2428    dg(
2429        "bynk.requires.conflicting_range",
2430        "Two adapter `binding … requires { … }` entries give different version ranges for one npm package.",
2431        &["binding_decl"],
2432    ),
2433    dg(
2434        "bynk.requires.unapproved",
2435        "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>`.",
2436        &["binding_decl"],
2437    ),
2438    dg(
2439        "bynk.requires.unpinned_dependency",
2440        "An adapter `binding … requires { … }` entry has an unpinned version range.",
2441        &["binding_decl"],
2442    ),
2443    d(
2444        "bynk.resolve.ambiguous_variant",
2445        "A variant name is ambiguous across several sum types.",
2446    ),
2447    dg(
2448        "bynk.resolve.arity_mismatch",
2449        "A function was called with the wrong number of arguments.",
2450        &["call"],
2451    ),
2452    dg(
2453        "bynk.resolve.bad_const_initialiser",
2454        "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.",
2455        &["const_decl"],
2456    ),
2457    dg(
2458        "bynk.resolve.const_cycle",
2459        "Constants refer to each other in a cycle, so none of them has a value.",
2460        &["const_decl"],
2461    ),
2462    dg(
2463        "bynk.resolve.const_name_case",
2464        "A constant's name is not upper-camel case (`MaxRetries`, not `maxRetries`).",
2465        &["const_decl"],
2466    ),
2467    dg(
2468        "bynk.resolve.const_outside_context_or_commons",
2469        "A `const` declaration appears outside a context or commons.",
2470        &["const_decl"],
2471    ),
2472    d("bynk.resolve.duplicate_actor", "Two actors share a name."),
2473    dg(
2474        "bynk.resolve.duplicate_agent",
2475        "Two agents share a name.",
2476        &["agent_decl"],
2477    ),
2478    dg(
2479        "bynk.resolve.duplicate_capability",
2480        "Two capabilities share a name.",
2481        &["capability_decl"],
2482    ),
2483    dg(
2484        "bynk.resolve.duplicate_const",
2485        "Two constants share a name.",
2486        &["const_decl"],
2487    ),
2488    dg(
2489        "bynk.resolve.duplicate_field",
2490        "A record declares a field twice.",
2491        &["record_type"],
2492    ),
2493    dg(
2494        "bynk.resolve.duplicate_field_init",
2495        "A record construction initialises a field twice.",
2496        &["record_construction"],
2497    ),
2498    dg(
2499        "bynk.resolve.duplicate_fn",
2500        "Two functions share a name.",
2501        &["fn_decl"],
2502    ),
2503    d(
2504        "bynk.resolve.duplicate_message_code",
2505        "A message bundle declares the same code twice in one block.",
2506    ),
2507    d(
2508        "bynk.resolve.duplicate_message_locale",
2509        "Two `messages` blocks in one bundle declare the same locale tag.",
2510    ),
2511    dg(
2512        "bynk.resolve.duplicate_method",
2513        "Two methods share a name.",
2514        &["fn_decl"],
2515    ),
2516    dg(
2517        "bynk.resolve.duplicate_param",
2518        "A parameter name is repeated.",
2519        &["param"],
2520    ),
2521    dg(
2522        "bynk.resolve.duplicate_provider",
2523        "A capability is provided more than once.",
2524        &["provider_decl"],
2525    ),
2526    dg(
2527        "bynk.resolve.duplicate_service",
2528        "Two services share a name.",
2529        &["service_decl"],
2530    ),
2531    dg(
2532        "bynk.resolve.duplicate_type",
2533        "Two types share a name.",
2534        &["type_decl"],
2535    ),
2536    dg(
2537        "bynk.resolve.duplicate_variant",
2538        "A sum type declares a variant twice.",
2539        &["sum_type"],
2540    ),
2541    d(
2542        "bynk.resolve.fn_without_call",
2543        "A function was referenced without being called.",
2544    ),
2545    dg(
2546        "bynk.resolve.let_shadows_fn",
2547        "A `let` binding shadows a function.",
2548        &["let_stmt"],
2549    ),
2550    dg(
2551        "bynk.resolve.let_shadows_type",
2552        "A `let` binding shadows a type.",
2553        &["let_stmt"],
2554    ),
2555    d(
2556        "bynk.resolve.method_unknown_type",
2557        "A method is defined on an unknown type.",
2558    ),
2559    dg(
2560        "bynk.resolve.missing_field",
2561        "A record construction omits a required field.",
2562        &["record_construction"],
2563    ),
2564    d(
2565        "bynk.resolve.name_conflict",
2566        "Two declarations share a name.",
2567    ),
2568    dg(
2569        "bynk.resolve.not_a_record_type",
2570        "Record syntax was used on a non-record type.",
2571        &["record_construction"],
2572    ),
2573    dg(
2574        "bynk.resolve.opaque_record_construction",
2575        "An opaque type was constructed with record syntax.",
2576        &["record_construction"],
2577    ),
2578    dg(
2579        "bynk.resolve.param_as_function",
2580        "A value (such as a parameter) was called as a function.",
2581        &["call"],
2582    ),
2583    dg(
2584        "bynk.resolve.recursive_record_field",
2585        "A record directly contains a field of its own type.",
2586        &["record_type"],
2587    ),
2588    dg(
2589        "bynk.resolve.reserved_builtin_type",
2590        "A type declaration reuses a compiler-known built-in type name.",
2591        &["type_decl"],
2592    ),
2593    dg(
2594        "bynk.resolve.reserved_host_name",
2595        "A declaration is named `globalThis`, which the generated TypeScript uses to reach host globals.",
2596        &["type_decl", "fn_decl", "agent_decl", "provider_decl"],
2597    ),
2598    dg(
2599        "bynk.resolve.reserved_payload_field",
2600        "A sum variant declares a payload field named `kind`, the variant's wire discriminant.",
2601        &["sum_type"],
2602    ),
2603    dg(
2604        "bynk.resolve.self_outside_method",
2605        "`self` referenced outside a method or handler.",
2606        &["self_expr"],
2607    ),
2608    dg(
2609        "bynk.resolve.type_as_function",
2610        "A type name was called as if it were a function.",
2611        &["call"],
2612    ),
2613    d(
2614        "bynk.resolve.type_in_expr",
2615        "A type name was used where a value is expected.",
2616    ),
2617    dg(
2618        "bynk.resolve.unconsumed_context",
2619        "A context's service was called without a `consumes` declaration.",
2620        &["consumes_decl"],
2621    ),
2622    dg(
2623        "bynk.resolve.unknown_field",
2624        "Accessed a field the record does not have.",
2625        &["field_access"],
2626    ),
2627    dg(
2628        "bynk.resolve.unknown_function",
2629        "Called a function that does not exist.",
2630        &["call"],
2631    ),
2632    d(
2633        "bynk.resolve.unknown_name",
2634        "Referenced a name that is not in scope.",
2635    ),
2636    dg(
2637        "bynk.resolve.unknown_static_member",
2638        "Referenced an unknown static member (e.g. `T.x`).",
2639        &["field_access"],
2640    ),
2641    d(
2642        "bynk.resolve.unknown_type",
2643        "Referenced a type that does not exist.",
2644    ),
2645    warn(d(
2646        "bynk.secrets.computed_name",
2647        "A `bynk.Secrets` read names its secret with a computed expression rather than a literal, so `bynk deploy` cannot plan it (warning).",
2648    )),
2649    dg(
2650        "bynk.send.in_agent_handler",
2651        "A `~>` send was used in an agent handler, which has no execution context to keep a fire-and-forget send alive.",
2652        &["effect_send_stmt"],
2653    ),
2654    dg(
2655        "bynk.send.in_pure_context",
2656        "A `~>` send was used in a pure (non-effectful) context.",
2657        &["effect_send_stmt"],
2658    ),
2659    dg(
2660        "bynk.send.non_effect",
2661        "A `~>` send was applied to a non-`Effect` value.",
2662        &["effect_send_stmt"],
2663    ),
2664    dg(
2665        "bynk.send.requires_unit",
2666        "A `~>` send targets an operation whose reply is not `Effect[()]`.",
2667        &["effect_send_stmt"],
2668    ),
2669    dg(
2670        "bynk.send.store_op",
2671        "A `~>` send targets an agent store operation, which is part of the handler's atomic commit and cannot be sent without waiting.",
2672        &["effect_send_stmt"],
2673    ),
2674    dg(
2675        "bynk.service.missing_from",
2676        "A `from`-less service has a handler other than `on call`.",
2677        &["service_decl"],
2678    ),
2679    dg(
2680        "bynk.service.mixed_protocols",
2681        "A service mixes handler forms that do not match its `from <protocol>`.",
2682        &["service_decl"],
2683    ),
2684    dg(
2685        "bynk.service.outside_context",
2686        "A `service` was declared outside a context.",
2687        &["service_decl"],
2688    ),
2689    dg(
2690        "bynk.service.return_not_effect",
2691        "A service handler's return type is not an `Effect`.",
2692        &["service_decl"],
2693    ),
2694    dg(
2695        "bynk.service.unknown_protocol",
2696        "A `from <protocol>` names an unknown protocol (e.g. a transport like Kafka).",
2697        &["service_decl"],
2698    ),
2699    d(
2700        "bynk.service.unknown_via_clause",
2701        "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.",
2702    ),
2703    d(
2704        "bynk.service.websocket_header",
2705        "The `from websocket` header is malformed — it binds frame types as `websocket(in: <type>, out: <type>)` (real-time track slice 3).",
2706    ),
2707    d(
2708        "bynk.service.websocket_multiple",
2709        "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).",
2710    ),
2711    d(
2712        "bynk.service.websocket_open_arity",
2713        "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).",
2714    ),
2715    d(
2716        "bynk.service.websocket_param_not_stringy",
2717        "A `from websocket` service's `on open` parameter has a type not constructible from `String`; it arrives as a query-string value (#1657).",
2718    ),
2719    d(
2720        "bynk.stability.experimental",
2721        "An experimental standard-library item is used without an `[unstable] allow` entry in `bynk.toml` covering it.",
2722    ),
2723    d(
2724        "bynk.store.annotation_kind_mismatch",
2725        "A storage annotation is used on a kind it does not apply to (e.g. `@ttl` on a `Map`).",
2726    ),
2727    d(
2728        "bynk.store.annotation_unsupported",
2729        "A known storage annotation (`@ttl`/`@retain`/`@indexed`/`@bounded`) is used before the slice that supports it.",
2730    ),
2731    d(
2732        "bynk.store.cache_needs_clock",
2733        "A handler performs a `Cache` operation (TTL expiry reads the clock) without declaring `given Clock`.",
2734    ),
2735    d(
2736        "bynk.store.cache_ttl_required",
2737        "A `Cache` field is missing its required `@ttl(<duration>)` annotation (a keyed store with no expiry is a `Map`).",
2738    ),
2739    d(
2740        "bynk.store.kind_arity",
2741        "A storage kind was applied to the wrong number of type arguments (e.g. `Cell[A, B]`).",
2742    ),
2743    d(
2744        "bynk.store.kind_unsupported",
2745        "A known storage kind (`Queue`) is used before the slice that supports it.",
2746    ),
2747    d(
2748        "bynk.store.log_needs_clock",
2749        "A handler calls `Log.append` (which stamps the current time) without declaring `given Clock`.",
2750    ),
2751    d(
2752        "bynk.store.unkeyable_key",
2753        "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).",
2754    ),
2755    d(
2756        "bynk.store.unknown_annotation",
2757        "A `store` field carries an annotation outside the closed `@indexed`/`@ttl`/`@retain`/`@bounded` set.",
2758    ),
2759    d(
2760        "bynk.store.unknown_kind",
2761        "A `store` field's type is not a known storage kind.",
2762    ),
2763    d(
2764        "bynk.store.unknown_map_accessor",
2765        "A `store Map` field access is not one of its query accessors (`entries`/`keys`/`values`).",
2766    ),
2767    d(
2768        "bynk.store.unknown_op",
2769        "A storage-`Map`/`Set` operation is not a recognised entry/membership method.",
2770    ),
2771    d(
2772        "bynk.stub.after_type",
2773        "A test `stub … returns <value> after <d>` latency is not a `Duration`.",
2774    ),
2775    dg(
2776        "bynk.stub.at_system",
2777        "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.",
2778        &["stub_clause"],
2779    ),
2780    d(
2781        "bynk.stub.bad_sequence",
2782        "A `stub … returns each […]` sequence is malformed (e.g. empty).",
2783    ),
2784    d(
2785        "bynk.stub.generic_op",
2786        "A test `stub` targets a capability operation that declares its own type parameter — not supported at v1.",
2787    ),
2788    d(
2789        "bynk.stub.not_a_seam",
2790        "A test `stub` overrides a capability the unit under test does not consume.",
2791    ),
2792    d(
2793        "bynk.stub.rhs_type",
2794        "A test `stub … returns <value>` right-hand side does not match the operation's return type.",
2795    ),
2796    d(
2797        "bynk.stub.unknown_op",
2798        "A test `stub` names an operation the capability does not declare.",
2799    ),
2800    dg(
2801        "bynk.suite.duplicate_case_name",
2802        "Two `case`s share a description.",
2803        &["case"],
2804    ),
2805    dg(
2806        "bynk.suite.duplicate_env",
2807        "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.",
2808        &["env_clause"],
2809    ),
2810    dg(
2811        "bynk.suite.duplicate_fn",
2812        "A suite declares two helper `fn`s of the same name.",
2813        &["fn_decl"],
2814    ),
2815    dg(
2816        "bynk.suite.env_binding_clash",
2817        "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`.",
2818        &["env_clause"],
2819    ),
2820    dg(
2821        "bynk.suite.env_not_literal",
2822        "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.",
2823        &["env_clause"],
2824    ),
2825    dg(
2826        "bynk.suite.fn_effectful",
2827        "A suite helper `fn` returns an `Effect`; suite helpers are pure.",
2828        &["fn_decl"],
2829    ),
2830    dg(
2831        "bynk.suite.fn_method",
2832        "A suite helper `fn` is a method (`fn Type.name`); suite helpers are free functions.",
2833        &["fn_decl"],
2834    ),
2835    dg(
2836        "bynk.suite.fn_name_clash",
2837        "A suite helper `fn` has the name of a declaration already in scope in the suite's cases.",
2838        &["fn_decl"],
2839    ),
2840    dg(
2841        "bynk.suite.unknown_target",
2842        "A `suite` targets a unit that does not exist.",
2843        &["suite_decl"],
2844    ),
2845    d(
2846        "bynk.target.browser_bundle_only",
2847        "The `browser` platform builds only the in-process `Bundle` topology; `--target workers` is not a browser build.",
2848    ),
2849    dg(
2850        "bynk.target.vendor_conflict",
2851        "One deployment unit's in-process closure uses platform-native capabilities from two mutually-exclusive platforms.",
2852        &["consumes_decl"],
2853    ),
2854    dg(
2855        "bynk.target.vendor_required",
2856        "A deployment unit uses a platform-native capability but the build selects another `--platform`.",
2857        &["consumes_decl"],
2858    ),
2859    dg(
2860        "bynk.test.actor_identity_required",
2861        "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`.",
2862        &["case"],
2863    ),
2864    dg(
2865        "bynk.test.actor_no_identity",
2866        "A call-site `by <Actor>(x)` supplies an identity to an actor that takes none — a unit-identity actor (e.g. `Visitor`) or `Nobody`.",
2867        &["case"],
2868    ),
2869    dg(
2870        "bynk.test.advance_not_clock",
2871        "An `advance` statement names a capability other than `Clock`; the test harness owns one time source, the first-party `Clock`.",
2872        &["advance_stmt"],
2873    ),
2874    dg(
2875        "bynk.test.advance_not_duration",
2876        "An `advance Clock by` statement's amount is not a `Duration`.",
2877        &["advance_stmt"],
2878    ),
2879    dg(
2880        "bynk.test.advance_outside_case",
2881        "An `advance Clock by` statement appears outside a test `case` body; only the test harness has a clock to move.",
2882        &["advance_stmt"],
2883    ),
2884    dg(
2885        "bynk.test.asset_address_method",
2886        "A suite fetches an asset with a method other than `GET`; the platform serves assets to `GET` and answers other methods with 405.",
2887        &["case"],
2888    ),
2889    dg(
2890        "bynk.test.call_needs_in_process",
2891        "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`.",
2892        &["case"],
2893    ),
2894    dg(
2895        "bynk.test.credential_needs_system",
2896        "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.",
2897        &["case"],
2898    ),
2899    dg(
2900        "bynk.test.event_needs_in_process",
2901        "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`.",
2902        &["case"],
2903    ),
2904    dg(
2905        "bynk.test.event_not_subscribed",
2906        "A test body's `svc.event(e)` delivers an event the `from Events(E)` service does not subscribe to.",
2907        &["case"],
2908    ),
2909    dg(
2910        "bynk.test.event_publisher_ambiguous",
2911        "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.",
2912        &["case"],
2913    ),
2914    dg(
2915        "bynk.test.expired_needs_bearer_route",
2916        "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); it sends a correctly signed token whose `exp` has passed, so only a `Bearer` seam can refuse it.",
2917        &["case"],
2918    ),
2919    dg(
2920        "bynk.test.extra_headers_authorization",
2921        "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.",
2922        &["case"],
2923    ),
2924    dg(
2925        "bynk.test.faults_needs_in_process",
2926        "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` or `by Expired`; 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`.",
2927        &["case"],
2928    ),
2929    dg(
2930        "bynk.test.forged_needs_signature_route",
2931        "A case drives `by Forged` at an address that is not an http route with a `Signature` or `Bearer` 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` or `Bearer` seam can refuse them.",
2932        &["case"],
2933    ),
2934    dg(
2935        "bynk.test.forged_needs_system",
2936        "A case drives `by Forged`, `by Stale` or `by Expired` outside a `system`-tier case; only the `system` driver signs a request or mints a token, so only there does the real `Signature` or `Bearer` seam see the bad credential.",
2937        &["case"],
2938    ),
2939    dg(
2940        "bynk.test.nobody_needs_secured_route",
2941        "A case drives `by Nobody` at a route with no Bearer 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.",
2942        &["case"],
2943    ),
2944    dg(
2945        "bynk.test.oidc_needs_in_process",
2946        "A `system`-tier case calls an http route whose actor is `Oidc`-secured; the `system` driver has no token issuer yet, so the request without a token could only be refused with a `401`, and the call belongs at `unit` or `integration`.",
2947        &["case"],
2948    ),
2949    d(
2950        "bynk.test.principal_claims_not_oidc",
2951        "A call-site principal passes token claims for an actor that isn't `Oidc`.",
2952    ),
2953    dg(
2954        "bynk.test.principal_identity_mismatch",
2955        "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.",
2956        &["case"],
2957    ),
2958    dg(
2959        "bynk.test.principal_on_asset",
2960        "A suite's asset fetch carries a `by` clause; an asset is public and served before the Worker runs.",
2961        &["case"],
2962    ),
2963    dg(
2964        "bynk.test.principal_on_wrong_method",
2965        "A wrong-method `405` test carries a `by <Actor>` clause; it reaches no handler, so a principal is meaningless.",
2966        &["case"],
2967    ),
2968    dg(
2969        "bynk.test.principal_required",
2970        "A test drives an identity-carrying handler, or one guarded by an actor sum, with no call-site `by <Actor>`.",
2971        &["case"],
2972    ),
2973    warn(dg(
2974        "bynk.test.remote_clock_dependent",
2975        "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.",
2976        &["case"],
2977    )),
2978    dg(
2979        "bynk.test.remote_unsupported_advance",
2980        "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.",
2981        &["case"],
2982    ),
2983    dg(
2984        "bynk.test.remote_unsupported_asset",
2985        "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.",
2986        &["case"],
2987    ),
2988    dg(
2989        "bynk.test.remote_unsupported_call",
2990        "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.",
2991        &["case"],
2992    ),
2993    dg(
2994        "bynk.test.remote_unsupported_env",
2995        "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.",
2996        &["case"],
2997    ),
2998    dg(
2999        "bynk.test.remote_unsupported_queue",
3000        "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.",
3001        &["case"],
3002    ),
3003    dg(
3004        "bynk.test.remote_unsupported_schedule",
3005        "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.",
3006        &["case"],
3007    ),
3008    dg(
3009        "bynk.test.service_bad_address",
3010        "A test body addresses a service the wrong way for its protocol (e.g. an http route without a leading path string).",
3011        &["case"],
3012    ),
3013    dg(
3014        "bynk.test.service_call_arity",
3015        "A test body's `svc.call(...)` passes the wrong number of arguments for the service's `on call` handler.",
3016        &["case"],
3017    ),
3018    dg(
3019        "bynk.test.service_no_call_handler",
3020        "A test body invokes `svc.call(...)` on a service with no `on call` handler (a `from http`/`cron`/`queue` service).",
3021        &["case"],
3022    ),
3023    dg(
3024        "bynk.test.service_unknown_route",
3025        "A test body addresses an http route / cron schedule / queue message the service does not declare.",
3026        &["case"],
3027    ),
3028    warn(dg(
3029        "bynk.test.smoke_undeclared_status",
3030        "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).",
3031        &["case"],
3032    )),
3033    dg(
3034        "bynk.test.snapshot_duplicate_name",
3035        "A case takes two snapshots (`expect v matches snapshot \"name\"`) under one name; a snapshot is keyed by its case and name.",
3036        &["snapshot_expr"],
3037    ),
3038    dg(
3039        "bynk.test.snapshot_in_property",
3040        "A `property` takes a snapshot; its body runs once per generated input, so the snapshot belongs in a `case` over a fixed value.",
3041        &["snapshot_expr"],
3042    ),
3043    dg(
3044        "bynk.test.snapshot_name_not_literal",
3045        "`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.",
3046        &["snapshot_expr"],
3047    ),
3048    dg(
3049        "bynk.test.snapshot_needs_unit_suite",
3050        "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.",
3051        &["snapshot_expr"],
3052    ),
3053    dg(
3054        "bynk.test.snapshot_not_codable",
3055        "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.",
3056        &["snapshot_expr"],
3057    ),
3058    dg(
3059        "bynk.test.stale_needs_timestamp",
3060        "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.",
3061        &["case"],
3062    ),
3063    dg(
3064        "bynk.test.unknown_actor",
3065        "A call-site `by <Actor>` names an actor the target context does not declare and that is not a prelude actor.",
3066        &["case"],
3067    ),
3068    dg(
3069        "bynk.test.wire_http_only",
3070        "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.",
3071        &["case"],
3072    ),
3073    dg(
3074        "bynk.test.wire_needs_system",
3075        "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.",
3076        &["case"],
3077    ),
3078    dg(
3079        "bynk.tier.cross_context_needs_system",
3080        "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`.",
3081        &["case"],
3082    ),
3083    dg(
3084        "bynk.tier.mixed_system_suite",
3085        "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.",
3086        &["case"],
3087    ),
3088    d(
3089        "bynk.tier.system_needs_wire",
3090        "An `as system` test stands up fewer than two contexts; the system tier wires across contexts.",
3091    ),
3092    d(
3093        "bynk.transition.cross_agent_reference",
3094        "A transition predicate references another agent; step invariants are per-agent.",
3095    ),
3096    d(
3097        "bynk.transition.duplicate_name",
3098        "An agent declares two transitions with the same name.",
3099    ),
3100    d(
3101        "bynk.transition.impure_predicate",
3102        "A transition predicate uses an effectful or test-only construct; a step invariant must be pure.",
3103    ),
3104    warn(d(
3105        "bynk.transition.may_violate",
3106        "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.",
3107    )),
3108    d(
3109        "bynk.transition.no_step_reference",
3110        "A transition references neither `old` nor `new`; it constrains one state, so it is an `invariant`, not a step.",
3111    ),
3112    d(
3113        "bynk.transition.not_bool",
3114        "A transition predicate does not have type `Bool`.",
3115    ),
3116    dg(
3117        "bynk.types.argument_mismatch",
3118        "A call, method, capability, or constructor argument has the wrong type.",
3119        &["call"],
3120    ),
3121    d(
3122        "bynk.types.asset_at_boundary",
3123        "An `Asset` type appears in a record field, boundary or store position; pass its `.url` instead.",
3124    ),
3125    d(
3126        "bynk.types.bad_field_default",
3127        "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, or applies a user generic, has no default. (Earlier versions reported this as `bynk.event.bad_field_default`.)",
3128    ),
3129    dg(
3130        "bynk.types.call_arity",
3131        "A function value was applied with the wrong number of arguments.",
3132        &["call"],
3133    ),
3134    dg(
3135        "bynk.types.cannot_infer_option_type_param",
3136        "The value type of `None` could not be inferred.",
3137        &["none_expr"],
3138    ),
3139    d(
3140        "bynk.types.cannot_infer_result_type_params",
3141        "The type parameters of a `Result` could not be inferred.",
3142    ),
3143    dg(
3144        "bynk.types.catastrophic_regex",
3145        "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).",
3146        &["refinement"],
3147    ),
3148    d(
3149        "bynk.types.claims_at_boundary",
3150        "`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.",
3151    ),
3152    dg(
3153        "bynk.types.combinator_return_mismatch",
3154        "A callback passed to a combinator (`map`/`andThen`/`flatMap`/`traverseAll`/…) returns the wrong type.",
3155        &["call"],
3156    ),
3157    d(
3158        "bynk.types.constructor_arity",
3159        "A variant constructor got the wrong number of arguments.",
3160    ),
3161    d(
3162        "bynk.types.constructor_base_mismatch",
3163        "A `.of` constructor was given an argument of the wrong base type.",
3164    ),
3165    d(
3166        "bynk.types.decimal_division_unscaled",
3167        "`/` 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).",
3168    ),
3169    d(
3170        "bynk.types.decimal_negation_too_large",
3171        "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).",
3172    ),
3173    dg(
3174        "bynk.types.derives_automatic",
3175        "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).",
3176        &["type_decl"],
3177    ),
3178    dg(
3179        "bynk.types.derives_field_not_orderable",
3180        "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).",
3181        &["type_decl"],
3182    ),
3183    dg(
3184        "bynk.types.duplicate_literal_arm",
3185        "A `match` has two arms for the same literal value.",
3186        &["match_arm"],
3187    ),
3188    dg(
3189        "bynk.types.duplicate_pattern_field",
3190        "A record pattern lists the same field twice.",
3191        &["record_pattern"],
3192    ),
3193    dg(
3194        "bynk.types.duplicate_variant_arm",
3195        "A `match` has two arms for the same variant.",
3196        &["match_arm"],
3197    ),
3198    d(
3199        "bynk.types.embeds_ambiguous",
3200        "A type is embedded by more than one variant of a sum, so `?`'s conversion would be ambiguous.",
3201    ),
3202    d(
3203        "bynk.types.embeds_unknown_variant",
3204        "An `embeds … as V` clause names a variant the sum does not declare.",
3205    ),
3206    d(
3207        "bynk.types.embeds_variant_shape",
3208        "An `embeds E as V` target variant must have exactly one payload field, of type `E`.",
3209    ),
3210    dg(
3211        "bynk.types.empty_range_pattern",
3212        "A range pattern or `via schema(...)` range has its bounds inverted (`lo > hi`), so it can never match.",
3213        &["int_range"],
3214    ),
3215    dg(
3216        "bynk.types.empty_refinement",
3217        "A refinement admits no values (contradictory predicates).",
3218        &["refinement"],
3219    ),
3220    dg(
3221        "bynk.types.err_value_mismatch",
3222        "An `Err` payload has the wrong type.",
3223        &["err_expr"],
3224    ),
3225    d(
3226        "bynk.types.extensible_match_needs_wildcard",
3227        "A `match` covers an extensible standard-library enum (`FetchError`, `Method`) without a wildcard; it may gain variants in a minor release.",
3228    ),
3229    dg(
3230        "bynk.types.field_access_on_non_record",
3231        "Field access on a value that is not a record.",
3232        &["field_access"],
3233    ),
3234    d(
3235        "bynk.types.field_default_on_variant",
3236        "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.",
3237    ),
3238    dg(
3239        "bynk.types.field_refinement_not_base",
3240        "An inline field refinement requires a base or refined type.",
3241        &["record_field"],
3242    ),
3243    dg(
3244        "bynk.types.field_value_mismatch",
3245        "A record field was given a value of the wrong type.",
3246        &["record_construction"],
3247    ),
3248    dg(
3249        "bynk.types.function_at_boundary",
3250        "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.",
3251        &["function_type_ref"],
3252    ),
3253    dg(
3254        "bynk.types.guard_not_bool",
3255        "A match-arm `if` guard is not a `Bool` expression.",
3256        &["match_arm"],
3257    ),
3258    d(
3259        "bynk.types.headers_at_boundary",
3260        "`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.",
3261    ),
3262    d(
3263        "bynk.types.held_at_boundary",
3264        "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).",
3265    ),
3266    d(
3267        "bynk.types.held_not_comparable",
3268        "A held value (`Connection[F]`) is compared with `==`/`!=` — held values have identity, not value-equality (§2.9.3, real-time track slice 2).",
3269    ),
3270    dg(
3271        "bynk.types.if_branch_mismatch",
3272        "The branches of an `if` have different types.",
3273        &["if_expr"],
3274    ),
3275    dg(
3276        "bynk.types.if_non_bool_cond",
3277        "An `if` condition is not a `Bool`.",
3278        &["if_expr"],
3279    ),
3280    dg(
3281        "bynk.types.if_without_else_requires_unit",
3282        "An `if` with no `else` branch has a non-unit then-branch; the missing else defaults to `()`, so the branch must be `()` or `Effect[()]`.",
3283        &["if_expr"],
3284    ),
3285    d(
3286        "bynk.types.interpolation_non_scalar",
3287        "An interpolation hole holds a value with no string form.",
3288    ),
3289    dg(
3290        "bynk.types.invalid_regex",
3291        "A `Matches` predicate, or a regex method's pattern (`containsRegex`, …), contains an invalid regular expression or malformed inline flags.",
3292        &["refinement"],
3293    ),
3294    dg(
3295        "bynk.types.inverted_range",
3296        "An `InRange` predicate has its bounds inverted.",
3297        &["refinement"],
3298    ),
3299    dg(
3300        "bynk.types.is_base_mismatch",
3301        "An `is` refinement check is applied to a value of the wrong base type.",
3302        &["is_expr"],
3303    ),
3304    dg(
3305        "bynk.types.is_literal_pattern",
3306        "A literal was used on the right of `is`; `is` tests type/refinement, not value equality (use `==`).",
3307        &["is_expr"],
3308    ),
3309    dg(
3310        "bynk.types.is_non_sum",
3311        "`is` was applied to a value that is not a sum type.",
3312        &["is_expr"],
3313    ),
3314    dg(
3315        "bynk.types.is_range_pattern",
3316        "A range pattern was used directly on the right of `is`; `is` tests type/refinement, not value ranges (use `match`, a guard or `InRange`).",
3317        &["is_expr"],
3318    ),
3319    dg(
3320        "bynk.types.is_refined_pattern",
3321        "A refined (`where`) pattern was used on the right of `is`; refined patterns are `match`-only.",
3322        &["is_expr"],
3323    ),
3324    dg(
3325        "bynk.types.is_unknown_variant",
3326        "`is` names a variant the type does not have.",
3327        &["is_expr"],
3328    ),
3329    dg(
3330        "bynk.types.json_uncodable",
3331        "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).",
3332        &["method_call"],
3333    ),
3334    d(
3335        "bynk.types.key_at_boundary",
3336        "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).",
3337    ),
3338    dg(
3339        "bynk.types.key_not_orderable",
3340        "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.",
3341        &[],
3342    ),
3343    dg(
3344        "bynk.types.lambda_mismatch",
3345        "A lambda's parameter count, parameter annotations, or body type do not match the expected function type.",
3346        &["lambda_expr"],
3347    ),
3348    dg(
3349        "bynk.types.let_annotation_mismatch",
3350        "A `let` value does not match its type annotation.",
3351        &["let_stmt"],
3352    ),
3353    dg(
3354        "bynk.types.list_element_mismatch",
3355        "A list-literal element has a different type from the list's element type.",
3356        &["list_literal"],
3357    ),
3358    dg(
3359        "bynk.types.list_pattern_on_non_list",
3360        "A list pattern is matched against a value that is not a `List` (a record, sum, base type, `Set` or `Map`).",
3361        &["list_pattern"],
3362    ),
3363    dg(
3364        "bynk.types.match_arm_mismatch",
3365        "A `match` arm has a different type from the others.",
3366        &["match_arm"],
3367    ),
3368    dg(
3369        "bynk.types.match_non_sum_discriminant",
3370        "`match` was applied to a value that is not a sum type.",
3371        &["match_expr"],
3372    ),
3373    dg(
3374        "bynk.types.method_arity",
3375        "A method was called with the wrong number of arguments.",
3376        &["method_call"],
3377    ),
3378    dg(
3379        "bynk.types.method_not_found",
3380        "Called a method the type does not have.",
3381        &["method_call"],
3382    ),
3383    dg(
3384        "bynk.types.method_on_non_named_type",
3385        "A method was called on a built-in type that has no methods.",
3386        &["method_call"],
3387    ),
3388    dg(
3389        "bynk.types.mixed_pattern_bindings",
3390        "A pattern mixes named and positional bindings.",
3391        &["variant_pattern"],
3392    ),
3393    dg(
3394        "bynk.types.negative_length",
3395        "A length predicate was given a negative value.",
3396        &["refinement"],
3397    ),
3398    dg(
3399        "bynk.types.never_inferred",
3400        "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.",
3401        &["let_stmt"],
3402    ),
3403    dg(
3404        "bynk.types.no_numeric_coercion",
3405        "`Int`, `Float` and `Decimal` were mixed without an explicit conversion — in an operation, a comparison or refinement bounds.",
3406        &["binary_expr", "refinement"],
3407    ),
3408    dg(
3409        "bynk.types.non_exhaustive_match",
3410        "A `match` does not cover every value.",
3411        &["match_expr"],
3412    ),
3413    d(
3414        "bynk.types.not_codable",
3415        "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).",
3416    ),
3417    d(
3418        "bynk.types.not_comparable",
3419        "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).",
3420    ),
3421    dg(
3422        "bynk.types.not_keyable",
3423        "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).",
3424        &["generic_type_ref"],
3425    ),
3426    d(
3427        "bynk.types.not_orderable",
3428        "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).",
3429    ),
3430    dg(
3431        "bynk.types.ok_value_mismatch",
3432        "An `Ok` payload has the wrong type.",
3433        &["ok_expr"],
3434    ),
3435    dg(
3436        "bynk.types.opaque_raw_outside",
3437        "`.raw` on an opaque type was used outside its defining commons.",
3438        &["field_access"],
3439    ),
3440    dg(
3441        "bynk.types.opaque_unsafe_outside",
3442        "`.unsafe` on an opaque type was used outside its defining context.",
3443        &["field_access"],
3444    ),
3445    dg(
3446        "bynk.types.or_pattern_binding_mismatch",
3447        "An or-pattern's alternatives don't all bind the same set of names.",
3448        &["match_arm", "is_expr"],
3449    ),
3450    dg(
3451        "bynk.types.or_pattern_type_mismatch",
3452        "An or-pattern's alternatives give a shared binding different types (or refinements).",
3453        &["match_arm", "is_expr"],
3454    ),
3455    dg(
3456        "bynk.types.pattern_arity",
3457        "A pattern binds the wrong number of payload fields.",
3458        &["variant_pattern"],
3459    ),
3460    dg(
3461        "bynk.types.pattern_type_mismatch",
3462        "A pattern's type does not match the matched value.",
3463        &["variant_pattern"],
3464    ),
3465    dg(
3466        "bynk.types.polynomial_regex",
3467        "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.",
3468        &["refinement"],
3469    ),
3470    warn(dg(
3471        "bynk.types.polynomial_regex_capped",
3472        "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).",
3473        &["refinement"],
3474    )),
3475    dg(
3476        "bynk.types.predicate_base_mismatch",
3477        "A predicate does not apply to the type's base (e.g. a string predicate on an `Int`).",
3478        &["refinement"],
3479    ),
3480    d(
3481        "bynk.types.query_at_boundary",
3482        "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).",
3483    ),
3484    dg(
3485        "bynk.types.question_error_mismatch",
3486        "`?` propagates an error type incompatible with the function's.",
3487        &["question_expr"],
3488    ),
3489    dg(
3490        "bynk.types.question_on_non_result",
3491        "`?` was applied to a non-`Result` value.",
3492        &["question_expr"],
3493    ),
3494    dg(
3495        "bynk.types.question_option_outside_http",
3496        "`?` lifts an `Option` only inside a handler returning `HttpResult` (`None` becomes `NotFound`); elsewhere use `.okOr(err)`.",
3497        &["question_expr"],
3498    ),
3499    dg(
3500        "bynk.types.question_outside_result",
3501        "`?` used in a function that does not return a `Result`.",
3502        &["question_expr"],
3503    ),
3504    dg(
3505        "bynk.types.range_pattern_on_non_int",
3506        "A range pattern (`lo..hi`) was matched against a scrutinee that is not an `Int`.",
3507        &["int_range"],
3508    ),
3509    dg(
3510        "bynk.types.record_pattern_on_non_record",
3511        "A record pattern names a type that is not a record (a sum, enum, refined or opaque type, or a built-in).",
3512        &["record_pattern"],
3513    ),
3514    dg(
3515        "bynk.types.regex_not_literal",
3516        "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.",
3517        &["method_call"],
3518    ),
3519    d(
3520        "bynk.types.rejection_at_boundary",
3521        "`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.",
3522    ),
3523    d(
3524        "bynk.types.request_query_at_boundary",
3525        "`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.",
3526    ),
3527    d(
3528        "bynk.types.return_mismatch",
3529        "A returned value does not match the declared return type.",
3530    ),
3531    d(
3532        "bynk.types.rounding_mode_position",
3533        "`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).",
3534    ),
3535    dg(
3536        "bynk.types.select_tail_has_select",
3537        "A `D1` `select[T]` or `firstAs[T]` statement begins with `SELECT`; the compiler writes the `SELECT` and column list from `T`, so the literal starts at `FROM`.",
3538        &["method_call"],
3539    ),
3540    dg(
3541        "bynk.types.sequence_needs_result",
3542        "`sequenceAll`/`sequenceTry` was called on a list whose elements are not `Result`s. They collect a `List[Result[T, E]]`.",
3543        &["method_call"],
3544    ),
3545    dg(
3546        "bynk.types.some_value_mismatch",
3547        "A `Some` payload has the wrong type.",
3548        &["some_expr"],
3549    ),
3550    dg(
3551        "bynk.types.sql_not_literal",
3552        "A `D1` statement's SQL (the first argument of `all`, `first`, `run`, `select` or `firstAs`, or a `SqlStatement`'s `sql`) is not a string literal, so data could be spliced into it instead of bound as a `SqlValue` parameter (standard-library P4c).",
3553        &["method_call", "record_construction", "record_spread"],
3554    ),
3555    dg(
3556        "bynk.types.sql_row_shape",
3557        "`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).",
3558        &["method_call"],
3559    ),
3560    d(
3561        "bynk.types.sql_statement_at_boundary",
3562        "A `bynk.cloudflare` `SqlStatement` 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).",
3563    ),
3564    d(
3565        "bynk.types.stream_at_boundary",
3566        "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).",
3567    ),
3568    d(
3569        "bynk.types.stream_not_comparable",
3570        "A `Stream` value is compared with `==`/`!=` — a stream is a live value-over-time source, not a comparable value (real-time track slice 0).",
3571    ),
3572    d(
3573        "bynk.types.type_mismatch",
3574        "Two types that were required to match did not.",
3575    ),
3576    dg(
3577        "bynk.types.uninferable_element_type",
3578        "An empty `[]` (or `List.empty()` / `Map.empty()`) has no expected type to infer its element type from.",
3579        &["list_literal"],
3580    ),
3581    dg(
3582        "bynk.types.unknown_field",
3583        "Referenced a field the record type does not declare.",
3584        &["field_access"],
3585    ),
3586    dg(
3587        "bynk.types.unknown_pattern_field",
3588        "A pattern names a field the variant does not have.",
3589        &["variant_pattern"],
3590    ),
3591    d(
3592        "bynk.types.unknown_rounding_mode",
3593        "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).",
3594    ),
3595    dg(
3596        "bynk.types.unknown_static_member",
3597        "Referenced an unknown static member on a type.",
3598        &["field_access"],
3599    ),
3600    dg(
3601        "bynk.types.unknown_variant_in_pattern",
3602        "A pattern names a variant the sum type does not have.",
3603        &["variant_pattern"],
3604    ),
3605    dg(
3606        "bynk.types.unreachable_arm",
3607        "A `match` arm is unreachable.",
3608        &["match_arm"],
3609    ),
3610    d(
3611        "bynk.types.variant_arity",
3612        "A variant constructor got the wrong number of payload values.",
3613    ),
3614    d(
3615        "bynk.types.variant_missing_payload",
3616        "A variant requiring a payload was used without one.",
3617    ),
3618    d(
3619        "bynk.types.variant_payload_mismatch",
3620        "A variant payload has the wrong type.",
3621    ),
3622    dg(
3623        "bynk.uses.name_conflict",
3624        "A `uses` name collides with another name, 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.",
3625        &["uses_decl"],
3626    ),
3627    dg(
3628        "bynk.uses.self_reference",
3629        "A commons `uses` itself.",
3630        &["uses_decl"],
3631    ),
3632    dg(
3633        "bynk.uses.target_is_context",
3634        "`uses` targets a context instead of a commons.",
3635        &["uses_decl"],
3636    ),
3637    dg(
3638        "bynk.uses.unknown_commons",
3639        "`uses` names a commons that does not exist.",
3640        &["uses_decl"],
3641    ),
3642    dg(
3643        "bynk.val.agent_not_generable",
3644        "A `for all`/`Val` cannot generate an agent — fabricated agent states need not be reachable.",
3645        &["for_all"],
3646    ),
3647    dg(
3648        "bynk.val.arity",
3649        "`Val[T]` was given the wrong number of pin arguments.",
3650        &["val_expr"],
3651    ),
3652    dg(
3653        "bynk.val.literal_violates",
3654        "A pinned `Val[T]` value violates the type's refinement.",
3655        &["val_expr"],
3656    ),
3657    dg(
3658        "bynk.val.needs_pin",
3659        "A bare `Val[T]` cannot generate a value (e.g. a `Matches` string); pin one.",
3660        &["val_expr"],
3661    ),
3662    dg(
3663        "bynk.val.outside_test",
3664        "`Val[T]` was used outside a test case body.",
3665        &["val_expr"],
3666    ),
3667    dg(
3668        "bynk.val.pin_not_literal",
3669        "A `Val[T]` pin argument is not a compile-time literal.",
3670        &["val_expr"],
3671    ),
3672    dg(
3673        "bynk.val.pin_unsupported",
3674        "A pin was given for a type kind that does not support pinning.",
3675        &["val_expr"],
3676    ),
3677    dg(
3678        "bynk.val.unknown_type",
3679        "`Val[T]` names a type that does not resolve.",
3680        &["val_expr"],
3681    ),
3682    dg(
3683        "bynk.val.unsupported_kind",
3684        "`Val[T]` cannot fabricate a value for this kind of type.",
3685        &["val_expr"],
3686    ),
3687    dg(
3688        "bynk.visibility.private_in_public",
3689        "A public declaration's signature names a `private` type of its own unit, which an importer could neither name nor build.",
3690        &["visibility_modifier"],
3691    ),
3692    dg(
3693        "bynk.visibility.private_item",
3694        "A reference from another unit names a `private` declaration, which is visible only within its own unit and that unit's suites.",
3695        &["visibility_modifier"],
3696    ),
3697    warn(dg(
3698        "bynk.visibility.private_messages",
3699        "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).",
3700        &["visibility_modifier"],
3701    )),
3702    dg(
3703        "bynk.visibility.private_not_allowed",
3704        "`private` modifies a declaration it does not apply to: anything but a `fn`, `type`, `messages`, `asset`, `embed` or `const` in a commons or context.",
3705        &["visibility_modifier"],
3706    ),
3707    d(
3708        "bynk.wasm.panic",
3709        "The in-browser compiler panicked internally (a compiler bug, reported as a diagnostic instead of crashing the page).",
3710    ),
3711    d(
3712        "bynk.wasm.strip_failed",
3713        "The in-browser compiler could not strip the emitted TypeScript to JavaScript.",
3714    ),
3715    dg(
3716        "bynk.within.in_agent_handler",
3717        "`e.within(d)` was used in an agent handler, which has no execution context to hand the abandoned effect to.",
3718        &["method_call"],
3719    ),
3720    dg(
3721        "bynk.within.in_pure_context",
3722        "`e.within(d)` was used in a pure (non-effectful) context.",
3723        &["method_call"],
3724    ),
3725    dg(
3726        "bynk.within.outside_handler",
3727        "`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.",
3728        &["method_call"],
3729    ),
3730    dg(
3731        "bynk.within.timed_out_not_in_scope",
3732        "`e.within(d)` yields `Result[_, TimedOut]`, but the unit does not consume `bynk`, so `TimedOut` is not in scope.",
3733        &["method_call"],
3734    ),
3735    d(
3736        "bynk.ws.message_frame_param",
3737        "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).",
3738    ),
3739    d(
3740        "bynk.ws.open_given_unsupported",
3741        "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).",
3742    ),
3743    d(
3744        "bynk.ws.open_transfer_cross_file",
3745        "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.",
3746    ),
3747    d(
3748        "bynk.ws.open_transfer_key",
3749        "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.",
3750    ),
3751    d(
3752        "bynk.ws.open_transfer_shape",
3753        "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).",
3754    ),
3755    d(
3756        "bynk.ws.route_param_mismatch",
3757        "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).",
3758    ),
3759];
3760
3761/// A diagnostic with no single governing grammar construct. `Error` severity.
3762const fn d(code: &'static str, summary: &'static str) -> DiagnosticInfo {
3763    DiagnosticInfo {
3764        code,
3765        summary,
3766        grammar_symbol: &[],
3767        severity: Severity::Error,
3768    }
3769}
3770
3771/// A diagnostic that constrains one or more grammar productions. `Error` severity.
3772const fn dg(
3773    code: &'static str,
3774    summary: &'static str,
3775    grammar_symbol: &'static [&'static str],
3776) -> DiagnosticInfo {
3777    DiagnosticInfo {
3778        code,
3779        summary,
3780        grammar_symbol,
3781        severity: Severity::Error,
3782    }
3783}
3784
3785/// Downgrades a [`d`]/[`dg`]-built entry to `Warning` severity (ADR 0117) —
3786/// non-failing, surfaced alongside a clean build. Its call sites here are
3787/// the single source of truth [`crate::error::Severity::for_error`] reads.
3788const fn warn(mut info: DiagnosticInfo) -> DiagnosticInfo {
3789    info.severity = Severity::Warning;
3790    info
3791}
3792
3793/// Downgrades a [`d`]/[`dg`]-built entry to `Hint` severity (#2838) — a
3794/// non-failing suggestion shown by the editor but not by the terminal.
3795const fn hint(mut info: DiagnosticInfo) -> DiagnosticInfo {
3796    info.severity = Severity::Hint;
3797    info
3798}
3799
3800/// The category segment of a code (the part between the first two dots), e.g.
3801/// `"types"` for `"bynk.types.type_mismatch"`.
3802pub fn category(code: &str) -> &str {
3803    code.split('.').nth(1).unwrap_or("")
3804}
3805
3806/// A human-readable heading for a category segment.
3807fn category_title(cat: &str) -> &'static str {
3808    match cat {
3809        "agent" | "agents" => "Agents",
3810        "asset" => "Static assets",
3811        "boundary" => "Boundaries",
3812        "capability" => "Capabilities",
3813        "cloudflare" => "Cloudflare",
3814        "consumes" => "Consumes",
3815        "context" => "Contexts",
3816        "contract" => "Contracts",
3817        "cron" => "Cron",
3818        "doc" => "Doc comments",
3819        "effect" => "Effects",
3820        "embed" => "Embedded text",
3821        "expect" => "Expectations",
3822        "exports" => "Exports",
3823        "given" => "Given capabilities",
3824        "http" => "HTTP",
3825        "lex" => "Lexer",
3826        "messages" => "Message bundles",
3827        "mock" => "Mocks (collaborators)",
3828        "observe" => "Observation",
3829        "parse" => "Parser",
3830        "project" => "Project",
3831        "property" => "Properties (generative tests)",
3832        "provider" => "Providers",
3833        "queue" => "Queue",
3834        "record_spread" => "Record spread",
3835        "refine" => "Refinement",
3836        "resolve" => "Resolution",
3837        "service" => "Services",
3838        "stability" => "Stability",
3839        "suite" => "Suites and cases",
3840        "transition" => "Transitions (step invariants)",
3841        "types" => "Type checking",
3842        "uses" => "Uses",
3843        "val" => "Value fabrication",
3844        _ => "Other",
3845    }
3846}
3847
3848/// Render the diagnostic index as a Markdown reference page, grouped by
3849/// category. This is the generator behind
3850/// `site/src/content/docs/book/reference/diagnostics.md`.
3851pub fn render_markdown() -> String {
3852    use std::collections::BTreeMap;
3853
3854    // Group codes by their category title, preserving sorted code order.
3855    let mut by_category: BTreeMap<&str, Vec<&DiagnosticInfo>> = BTreeMap::new();
3856    for info in REGISTRY {
3857        by_category
3858            .entry(category_title(category(info.code)))
3859            .or_default()
3860            .push(info);
3861    }
3862
3863    let mut out = String::new();
3864    out.push_str("# Diagnostic index\n\n");
3865    out.push_str(
3866        "<!-- GENERATED FILE — do not edit by hand.\n     \
3867         Source: bynk-syntax/src/diagnostics.rs (`render_markdown`).\n     \
3868         Regenerate with: BYNK_BLESS=1 cargo test -p xtask --test docs_consistency diagnostics_registry:: -->\n\n",
3869    );
3870    out.push_str(
3871        "Every diagnostic code the compiler can emit, with a one-line summary of \
3872         the cause, grouped by category. For step-by-step cause-and-fix guidance \
3873         on the most common ones, see the [troubleshooting guides](../troubleshooting/index.md). \
3874         For a code with a curated explanation, `bynk explain <code>` prints it in a \
3875         terminal, and in VS Code the diagnostic's **Explain** quick fix (or \
3876         **Bynk: Explain Diagnostic Code…**) shows the same text in a panel, offline.\n\n",
3877    );
3878    out.push_str(&format!(
3879        "There are **{}** codes in total.\n",
3880        REGISTRY.len()
3881    ));
3882
3883    for (title, infos) in &by_category {
3884        out.push_str(&format!("\n## {title}\n\n"));
3885        out.push_str("| Code | Summary | Construct | Severity |\n|---|---|---|---|\n");
3886        for info in infos {
3887            // The construct column deep-links each governing production to its
3888            // entry in the annotated grammar reference; generated from
3889            // `grammar_symbol` (each value is an embeddable rule, so the
3890            // `#rule-<raw>` anchor resolves — enforced in diagnostics_registry).
3891            let construct = info
3892                .grammar_symbol
3893                .iter()
3894                .map(|sym| format!("[`{sym}`](grammar.md#rule-{sym})"))
3895                .collect::<Vec<_>>()
3896                .join(", ");
3897            // A curated (`bynk explain`-able) code links to its Book concept
3898            // page; the in-site link is validated by the site's link checker,
3899            // so a moved page or renamed anchor fails the build (#853). Codes
3900            // without an explanation render as plain inline code.
3901            let code_cell = match explain(info.code) {
3902                Some(e) => format!("[`{}`]({})", info.code, e.in_site_link()),
3903                None => format!("`{}`", info.code),
3904            };
3905            // ADR 0117/finding #50: every code's severity, straight from the
3906            // registry — `Error` (the overwhelming majority) renders as "—"
3907            // to keep the common case unobtrusive; only a `warn`-built entry
3908            // shows "Warning".
3909            let severity = match info.severity {
3910                Severity::Error => "—",
3911                Severity::Warning => "Warning",
3912                Severity::Hint => "Hint",
3913            };
3914            out.push_str(&format!(
3915                "| {} | {} | {} | {} |\n",
3916                code_cell, info.summary, construct, severity
3917            ));
3918        }
3919    }
3920
3921    out
3922}
3923
3924/// Invert the registry into a `{ "<rule>": [ { code, summary }, … ], … }` map,
3925/// serialised as pretty JSON with sorted keys and sorted codes. Only rules with
3926/// at least one diagnostic appear. This is the generator behind
3927/// `docs/grammar-semantics.json`, which the `{{#grammar-semantics <rule>}}`
3928/// preprocessor directive consumes.
3929pub fn render_grammar_semantics_json() -> String {
3930    use std::collections::BTreeMap;
3931
3932    // REGISTRY is sorted by code, so each rule's vector comes out code-sorted;
3933    // the BTreeMap gives sorted rule names.
3934    let mut by_symbol: BTreeMap<&str, Vec<&DiagnosticInfo>> = BTreeMap::new();
3935    for info in REGISTRY {
3936        for sym in info.grammar_symbol {
3937            by_symbol.entry(sym).or_default().push(info);
3938        }
3939    }
3940
3941    let mut map = serde_json::Map::new();
3942    map.insert(
3943        "_generated".to_string(),
3944        serde_json::Value::String(
3945            "Generated from the grammar_symbol field of bynk-syntax/src/diagnostics.rs. \
3946             Do not edit by hand. Regenerate with: BYNK_BLESS=1 cargo test -p \
3947             xtask --test docs_consistency diagnostics_registry::"
3948                .to_string(),
3949        ),
3950    );
3951    for (sym, infos) in by_symbol {
3952        let arr: Vec<serde_json::Value> = infos
3953            .iter()
3954            .map(|info| serde_json::json!({ "code": info.code, "summary": info.summary }))
3955            .collect();
3956        map.insert(sym.to_string(), serde_json::Value::Array(arr));
3957    }
3958
3959    let mut s =
3960        serde_json::to_string_pretty(&serde_json::Value::Object(map)).expect("serialise semantics");
3961    s.push('\n');
3962    s
3963}