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.unknown_context",
818        "`consumes` names a context that does not exist.",
819        &["consumes_decl"],
820    ),
821    dg(
822        "bynk.consumes.unknown_service",
823        "Called a service the consumed context does not declare.",
824        &["consumes_decl"],
825    ),
826    d(
827        "bynk.context.consumes_cycle",
828        "Contexts form a `consumes` dependency cycle.",
829    ),
830    d(
831        "bynk.context.duplicate_binding",
832        "A Worker would declare two bindings with the same name, such as an agent `Kv` and the `bynk.cloudflare` KV namespace (both `KV`).",
833    ),
834    d(
835        "bynk.context.external_construction",
836        "A context-owned type was constructed from outside that context.",
837    ),
838    d(
839        "bynk.context.external_decode",
840        "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.",
841    ),
842    dg(
843        "bynk.context.external_provider",
844        "A bodiless (external) provider was declared outside an `adapter`.",
845        &["provider_decl"],
846    ),
847    d(
848        "bynk.context.opaque_inspection",
849        "An opaquely-exported type was inspected from outside its context.",
850    ),
851    d(
852        "bynk.context.rebrand_construction",
853        "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.",
854    ),
855    d(
856        "bynk.contract.duplicate_name",
857        "A function declares two contract clauses (`requires`/`ensures`) with the same name.",
858    ),
859    d(
860        "bynk.contract.impure_predicate",
861        "A contract predicate uses an effectful or test-only construct; a contract clause must be pure.",
862    ),
863    d(
864        "bynk.contract.not_bool",
865        "A contract predicate does not have type `Bool`.",
866    ),
867    d(
868        "bynk.contract.restated_by_test",
869        "A `case`/`property` merely restates a contract clause already declared at the function; the test is redundant.",
870    ),
871    d(
872        "bynk.contract.result_in_requires",
873        "A precondition (`requires`) references `result`; the return value is only in scope inside an `ensures`.",
874    ),
875    dg(
876        "bynk.cron.bad_params",
877        "A cron handler declares more than one parameter, or a non-`Int` one.",
878        &["cron_handler"],
879    ),
880    dg(
881        "bynk.cron.duplicate_schedule",
882        "Two cron handlers declare the same schedule.",
883        &["cron_handler"],
884    ),
885    dg(
886        "bynk.cron.invalid_schedule",
887        "A cron expression is not five whitespace-separated fields.",
888        &["cron_handler"],
889    ),
890    dg(
891        "bynk.cron.return_not_effect_result",
892        "A cron handler does not return `Effect[Result[(), E]]`.",
893        &["cron_handler"],
894    ),
895    d(
896        "bynk.d1.migration_name",
897        "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.",
898    ),
899    d(
900        "bynk.d1.migration_unreadable",
901        "A `D1` migration in the project's `migrations/` folder can't be read, or isn't UTF-8 text.",
902    ),
903    warn(d(
904        "bynk.d1.migrations_unused",
905        "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).",
906    )),
907    d(
908        "bynk.dependency.path_outside_root",
909        "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.",
910    ),
911    d(
912        "bynk.deploy.contract_skew",
913        "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.",
914    ),
915    d(
916        "bynk.deploy.foreign_contract_skew",
917        "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.",
918    ),
919    // LSP-only (#2459): published by `bynk-lsp` as a hint (or warning, per the
920    // `bynk.docLinks.reportUnresolved` setting); the compiler never emits it.
921    warn(d(
922        "bynk.doc.unresolved_link",
923        "A `[Name]` doc link resolves to nothing in the unit's scope (editor hint only).",
924    )),
925    d(
926        "bynk.duration.literal_overflow",
927        "A `Duration` literal (`<int>.<unit>`) exceeds the representable millisecond range.",
928    ),
929    dg(
930        "bynk.effect.bind_in_pure_context",
931        "An `<-` bind was used in a pure (non-effectful) context.",
932        &["effect_let_stmt"],
933    ),
934    dg(
935        "bynk.effect.bind_on_non_effect",
936        "An `<-` bind was applied to a non-`Effect` value.",
937        &["effect_let_stmt"],
938    ),
939    d(
940        "bynk.effect.capability_in_pure_context",
941        "A capability was used in a pure context.",
942    ),
943    d(
944        "bynk.effect.cross_context_in_pure_context",
945        "A cross-context call was made in a pure context.",
946    ),
947    dg(
948        "bynk.effect.do_in_pure_context",
949        "A `do` statement was used in a pure (non-effectful) context.",
950        &["do_stmt"],
951    ),
952    dg(
953        "bynk.effect.do_on_non_effect",
954        "A `do` statement was applied to a non-`Effect` value.",
955        &["do_stmt"],
956    ),
957    dg(
958        "bynk.effect.do_requires_unit",
959        "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.",
960        &["do_stmt"],
961    ),
962    dg(
963        "bynk.effect.fn_value_in_pure_context",
964        "An effectful function value was called in a pure context; like a capability call, it is legal only where the enclosing body is effectful.",
965        &["call"],
966    ),
967    d(
968        "bynk.effect.unbound_effect",
969        "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).",
970    ),
971    d(
972        "bynk.embed.binary_content",
973        "An `embed` names a file with a NUL byte, so it is binary, not text.",
974    ),
975    d(
976        "bynk.embed.duplicate",
977        "An `embed` name is declared more than once in the same unit.",
978    ),
979    d(
980        "bynk.embed.invalid_encoding",
981        "An `embed` names a file that is not valid UTF-8.",
982    ),
983    d(
984        "bynk.embed.missing_file",
985        "An `embed` names a file that is not in the project's `embeds/` folder.",
986    ),
987    d(
988        "bynk.embed.needs_project",
989        "A single-file build met an `embed` declaration, which needs a project's `embeds/` folder.",
990    ),
991    d(
992        "bynk.embed.outside_context_or_commons",
993        "An `embed` declaration appears outside a context or commons.",
994    ),
995    d(
996        "bynk.embed.outside_embeds_dir",
997        "An `embed` names a file outside the project's `embeds/` folder.",
998    ),
999    d(
1000        "bynk.embed.too_large",
1001        "An `embed` names a file over 256 KiB, or the project's embedded files total over 1 MiB.",
1002    ),
1003    d(
1004        "bynk.embed.unreadable_file",
1005        "An `embed` names a file in the project's `embeds/` folder that could not be read.",
1006    ),
1007    d(
1008        "bynk.embed.unsafe_path",
1009        "An `embed` path is empty, absolute, or contains a `..` segment.",
1010    ),
1011    d(
1012        "bynk.event.bad_params",
1013        "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.",
1014    ),
1015    d(
1016        "bynk.event.bad_schema_dispatch",
1017        "A `via schema(...)` dispatch clause's argument is malformed — it must be a positive `Int` literal, a range of positive `Int` literals, or `_`.",
1018    ),
1019    d(
1020        "bynk.event.bad_schema_version",
1021        "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.",
1022    ),
1023    dg(
1024        "bynk.event.duplicate_handler",
1025        "A `from Events` service declares more than one `on event` handler; it has exactly one.",
1026        &["event_handler"],
1027    ),
1028    d(
1029        "bynk.event.emit_not_an_event",
1030        "`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.",
1031    ),
1032    d(
1033        "bynk.event.emit_outside_owner",
1034        "`Events.emit[E]` named an event `E` not declared in the emitting context — only an event's declaring context may emit it.",
1035    ),
1036    d(
1037        "bynk.event.handler_param_type_mismatch",
1038        "An `on event(e: T)` handler's declared parameter type does not match its `from Events(E)` header's event type.",
1039    ),
1040    d(
1041        "bynk.event.non_additive_schema_change",
1042        "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.",
1043    ),
1044    d(
1045        "bynk.event.outside_context",
1046        "An `event` was declared outside a context.",
1047    ),
1048    d(
1049        "bynk.event.pattern_duplicate_field",
1050        "A `from Events(E { ... })` subscription pattern listed the same field more than once.",
1051    ),
1052    d(
1053        "bynk.event.pattern_type_mismatch",
1054        "A `from Events(E { ... })` subscription pattern field's matched value is not compatible with that field's declared type.",
1055    ),
1056    d(
1057        "bynk.event.pattern_unknown_field",
1058        "A `from Events(E { ... })` subscription pattern named a field that `E` does not declare.",
1059    ),
1060    d(
1061        "bynk.event.pattern_unknown_variant",
1062        "A `from Events(E { ... })` subscription pattern's variant value names a variant that does not exist on the field's declared sum type.",
1063    ),
1064    d(
1065        "bynk.event.pattern_variant_payload",
1066        "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.",
1067    ),
1068    dg(
1069        "bynk.event.return_not_effect_unit",
1070        "An `on event` handler returns an `Effect` of something other than `()`; emission is fire-and-forget, so it returns `Effect[()]`.",
1071        &["event_handler"],
1072    ),
1073    d(
1074        "bynk.event.schema_version_mismatch",
1075        "An event's `@schema(N)` annotation disagrees with the version the schema registry computes from the event's build history.",
1076    ),
1077    d(
1078        "bynk.event.unknown_annotation",
1079        "An `event` declaration carried an `@`-annotation other than `@schema` — event annotations are a closed set.",
1080    ),
1081    d(
1082        "bynk.event.unknown_subscription",
1083        "A `from Events(E)` subscription named `E`, which is not a declared event in this context or any consumed context.",
1084    ),
1085    d(
1086        "bynk.exec.unavailable",
1087        "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.",
1088    ),
1089    dg(
1090        "bynk.expect.faults_not_effect",
1091        "A fault claim's subject (`expect <call> faults`) is not an effectful call: a value, or a call whose type is not `Effect[_]`.",
1092        &["faults_expr"],
1093    ),
1094    dg(
1095        "bynk.expect.not_bool",
1096        "`expect` was given a non-`Bool` predicate.",
1097        &["expect_expr"],
1098    ),
1099    dg(
1100        "bynk.expect.outside_case",
1101        "`expect` was used outside a `case` body.",
1102        &["expect_expr"],
1103    ),
1104    dg(
1105        "bynk.exports.capability_not_provided",
1106        "An exported capability has no provider in its context.",
1107        &["exports_decl"],
1108    ),
1109    dg(
1110        "bynk.exports.conflicting_visibility",
1111        "A type is exported with conflicting visibilities.",
1112        &["exports_decl"],
1113    ),
1114    dg(
1115        "bynk.exports.derived_capability",
1116        "`exports capability` names a derived capability, whose instance stays with its context.",
1117        &["exports_decl"],
1118    ),
1119    dg(
1120        "bynk.exports.duplicate_export",
1121        "The same name is exported more than once.",
1122        &["exports_decl"],
1123    ),
1124    dg(
1125        "bynk.exports.duplicate_in_clause",
1126        "A name appears twice in one `exports` clause.",
1127        &["exports_decl"],
1128    ),
1129    dg(
1130        "bynk.exports.undeclared_capability",
1131        "`exports capability` names a capability that is not declared.",
1132        &["exports_decl"],
1133    ),
1134    dg(
1135        "bynk.exports.undeclared_type",
1136        "`exports` names a type that is not declared.",
1137        &["exports_decl"],
1138    ),
1139    warn(d(
1140        "bynk.fault.todo",
1141        "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).",
1142    )),
1143    d(
1144        "bynk.fmt.comment_loss",
1145        "The formatter would drop a comment, so it leaves the file unchanged.",
1146    ),
1147    d(
1148        "bynk.fmt.mixed_comment_syntax",
1149        "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.",
1150    ),
1151    d(
1152        "bynk.fmt.roundtrip",
1153        "The formatter's output does not re-parse to the same program, so it leaves the file unchanged.",
1154    ),
1155    dg(
1156        "bynk.generics.ambiguous_instantiation",
1157        "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).",
1158        &["fn_decl"],
1159    ),
1160    dg(
1161        "bynk.generics.bound_on_capability_op",
1162        "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).",
1163        &["capability_op"],
1164    ),
1165    dg(
1166        "bynk.generics.codable_op_return",
1167        "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).",
1168        &["capability_op"],
1169    ),
1170    dg(
1171        "bynk.generics.duplicate_type_param",
1172        "A `type` or `fn` declares the same type-parameter name more than once (v0.157, ADR 0183).",
1173        &[],
1174    ),
1175    dg(
1176        "bynk.generics.generic_non_record",
1177        "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).",
1178        &["type_decl"],
1179    ),
1180    dg(
1181        "bynk.generics.generic_record_at_boundary",
1182        "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.",
1183        &[],
1184    ),
1185    dg(
1186        "bynk.generics.generic_sum_embeds",
1187        "A generic sum type carries an `embeds` clause; embedding into a generic sum is not supported (#593).",
1188        &["type_decl"],
1189    ),
1190    dg(
1191        "bynk.generics.method_on_generic_type",
1192        "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).",
1193        &["fn_decl"],
1194    ),
1195    dg(
1196        "bynk.generics.missing_codable_bound",
1197        "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).",
1198        &["fn_decl"],
1199    ),
1200    dg(
1201        "bynk.generics.missing_eq_bound",
1202        "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).",
1203        &["fn_decl"],
1204    ),
1205    dg(
1206        "bynk.generics.missing_key_bound",
1207        "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).",
1208        &["fn_decl"],
1209    ),
1210    dg(
1211        "bynk.generics.missing_ord_bound",
1212        "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).",
1213        &["fn_decl"],
1214    ),
1215    dg(
1216        "bynk.generics.recursive_generic_at_boundary",
1217        "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).",
1218        &[],
1219    ),
1220    warn(dg(
1221        "bynk.generics.redundant_eq_bound",
1222        "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).",
1223        &["fn_decl"],
1224    )),
1225    dg(
1226        "bynk.generics.type_arg_count",
1227        "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).",
1228        &["applied_type_ref"],
1229    ),
1230    dg(
1231        "bynk.generics.type_arg_mismatch",
1232        "Inferred or explicit type arguments conflict, have the wrong arity, target a non-generic function, or a type parameter shadows a declared type.",
1233        &["call"],
1234    ),
1235    dg(
1236        "bynk.generics.uninferable_type_arg",
1237        "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.",
1238        &["call"],
1239    ),
1240    dg(
1241        "bynk.generics.unknown_constraint",
1242        "A bound names something that is not a constraint; `Eq` is the only one.",
1243        &["type_param"],
1244    ),
1245    dg(
1246        "bynk.generics.unknown_where_param",
1247        "A method's `where` clause bounds a name that is not a type parameter of the method or of its receiver type.",
1248        &["where_clause"],
1249    ),
1250    dg(
1251        "bynk.given.cross_context_unknown_capability",
1252        "`given B.Cap` names a capability the consumed context does not export.",
1253        &["given_clause"],
1254    ),
1255    dg(
1256        "bynk.given.undeclared_capability",
1257        "A handler uses a capability it did not declare with `given`.",
1258        &["given_clause"],
1259    ),
1260    dg(
1261        "bynk.given.unknown_capability",
1262        "`given` names a capability that does not exist.",
1263        &["given_clause"],
1264    ),
1265    warn(dg(
1266        "bynk.given.unused_capability",
1267        "A `given` capability is never used (warning).",
1268        &["given_clause"],
1269    )),
1270    d(
1271        "bynk.held.branch_divergence",
1272        "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).",
1273    ),
1274    d(
1275        "bynk.held.consume_on_borrow",
1276        "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).",
1277    ),
1278    d(
1279        "bynk.held.leak",
1280        "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).",
1281    ),
1282    d(
1283        "bynk.held.query_accessor_on_held_map",
1284        "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.",
1285    ),
1286    d(
1287        "bynk.held.unsupported_map_op",
1288        "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).",
1289    ),
1290    d(
1291        "bynk.held.unsupported_storage",
1292        "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).",
1293    ),
1294    d(
1295        "bynk.held.use_after_consume",
1296        "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).",
1297    ),
1298    d(
1299        "bynk.history.not_an_agent",
1300        "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).",
1301    ),
1302    d(
1303        "bynk.history.not_generable",
1304        "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).",
1305    ),
1306    d(
1307        "bynk.history.outside_property",
1308        "`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).",
1309    ),
1310    d(
1311        "bynk.history.restates_invariant",
1312        "A history property merely re-checks a guarantee a declared `invariant`/`transition` already enforces on every reached state (testing track slice 7, ADR 0155).",
1313    ),
1314    dg(
1315        "bynk.http.body_on_get_or_delete",
1316        "A GET or DELETE handler declares a `body` parameter.",
1317        &["http_handler"],
1318    ),
1319    d(
1320        "bynk.http.cache_bad_immutable",
1321        "A `@cache` annotation's `immutable` is not a `Bool` literal.",
1322    ),
1323    d(
1324        "bynk.http.cache_bad_max_age",
1325        "A `@cache` annotation's `maxAge` is missing or not a positive `Duration` literal.",
1326    ),
1327    d(
1328        "bynk.http.cache_bad_scope",
1329        "A `@cache` annotation's `scope` is not `public` or `private`.",
1330    ),
1331    d(
1332        "bynk.http.cache_duplicate",
1333        "A handler carries more than one `@cache` annotation.",
1334    ),
1335    d(
1336        "bynk.http.cache_max_age_fractional_seconds",
1337        "A `@cache` annotation's `maxAge` is positive but does not resolve to a whole number of seconds.",
1338    ),
1339    d(
1340        "bynk.http.cache_on_non_get",
1341        "A `@cache` annotation is placed on a handler that is not `on http GET`.",
1342    ),
1343    d(
1344        "bynk.http.cache_unknown_arg",
1345        "A `@cache` annotation has an argument outside the closed set (`maxAge`/`scope`/`immutable`).",
1346    ),
1347    d(
1348        "bynk.http.cors_invalid_field",
1349        "A `cors` policy field (`headers`/`credentials`/`maxAge`) has the wrong value shape.",
1350    ),
1351    d(
1352        "bynk.http.cors_invalid_origins",
1353        "A `cors` policy's `origins` is missing, empty, or not a list of string literals.",
1354    ),
1355    d(
1356        "bynk.http.cors_not_http",
1357        "A `cors { }` policy appears on a service that is not `from http`.",
1358    ),
1359    d(
1360        "bynk.http.cors_unknown_field",
1361        "A `cors { }` policy declares a field outside the closed set.",
1362    ),
1363    d(
1364        "bynk.http.cors_wildcard_credentials",
1365        "A `cors` policy combines `credentials: true` with the wildcard origin `[\"*\"]`.",
1366    ),
1367    dg(
1368        "bynk.http.duplicate_rejected",
1369        "A `from http` service declares `on rejected` more than once.",
1370        &["rejected_handler"],
1371    ),
1372    dg(
1373        "bynk.http.duplicate_route",
1374        "Two handlers share the same method and route.",
1375        &["http_handler"],
1376    ),
1377    d(
1378        "bynk.http.error_status_position",
1379        "An `ErrorStatus` name is used anywhere but as `RawError`'s first argument.",
1380    ),
1381    dg(
1382        "bynk.http.extra_param",
1383        "A handler parameter is not a path parameter, `body` or `headers`.",
1384        &["http_handler"],
1385    ),
1386    dg(
1387        "bynk.http.headers_wrong_type",
1388        "An HTTP handler's `headers` parameter is not typed `RequestHeaders`.",
1389        &["http_handler"],
1390    ),
1391    dg(
1392        "bynk.http.invalid_path",
1393        "An HTTP route path is malformed.",
1394        &["http_handler"],
1395    ),
1396    d(
1397        "bynk.http.limit_bad_max_body",
1398        "A `@limit` annotation's `maxBody` is missing or not a positive `Int` literal.",
1399    ),
1400    d(
1401        "bynk.http.limit_duplicate",
1402        "A handler carries more than one `@limit` annotation.",
1403    ),
1404    d(
1405        "bynk.http.limit_on_bodyless",
1406        "A `@limit` annotation is placed on a handler that takes no body (a GET or DELETE).",
1407    ),
1408    d(
1409        "bynk.http.limit_unknown_arg",
1410        "A `@limit` annotation has an argument outside the closed set (`maxBody`).",
1411    ),
1412    d(
1413        "bynk.http.limits_invalid_field",
1414        "A `limits` policy field (`maxBody`) has the wrong value shape.",
1415    ),
1416    d(
1417        "bynk.http.limits_not_http",
1418        "A `limits { }` policy appears on a service that is not `from http`.",
1419    ),
1420    d(
1421        "bynk.http.limits_unknown_field",
1422        "A `limits { }` policy declares a field outside the closed set.",
1423    ),
1424    dg(
1425        "bynk.http.path_param_not_stringy",
1426        "A path parameter's type is not constructible from a string.",
1427        &["http_handler"],
1428    ),
1429    d(
1430        "bynk.http.raw_bad_content_type",
1431        "A `@raw` annotation's `contentType` is missing or not a `type/subtype` (or `\"*/*\"`) string literal.",
1432    ),
1433    d(
1434        "bynk.http.raw_body_not_bytes",
1435        "The `body` of a `@raw` handler is not typed `Bytes`.",
1436    ),
1437    d(
1438        "bynk.http.raw_body_unbounded",
1439        "A `@raw` route has no request-body cap (no `@limit` and no service `limits`).",
1440    ),
1441    d(
1442        "bynk.http.raw_duplicate",
1443        "A handler carries more than one `@raw` annotation.",
1444    ),
1445    d(
1446        "bynk.http.raw_error_status",
1447        "`RawError`'s first argument is not an `ErrorStatus` name (a 4xx or 5xx `HttpResult` variant name).",
1448    ),
1449    d(
1450        "bynk.http.raw_on_bodyless",
1451        "A `@raw` annotation is placed on a handler that takes no body.",
1452    ),
1453    d(
1454        "bynk.http.raw_unknown_arg",
1455        "A `@raw` annotation has an argument outside the closed set (`contentType`).",
1456    ),
1457    dg(
1458        "bynk.http.rejected_signature",
1459        "An `on rejected` handler is not `on rejected(why: BoundaryRejection) -> HttpResult[()]` with no `by` and no `given`.",
1460        &["rejected_handler"],
1461    ),
1462    dg(
1463        "bynk.http.reserved_prefix",
1464        "A route uses the reserved `/_bynk/` prefix.",
1465        &["http_handler"],
1466    ),
1467    dg(
1468        "bynk.http.return_not_effect_http_result",
1469        "An HTTP handler does not return `Effect[HttpResult[T]]`.",
1470        &["http_handler"],
1471    ),
1472    d(
1473        "bynk.http.security_invalid_field",
1474        "A `security` policy field (`hsts`/`nosniff`) has the wrong value shape.",
1475    ),
1476    d(
1477        "bynk.http.security_not_http",
1478        "A `security { }` policy appears on a service that is not `from http`.",
1479    ),
1480    d(
1481        "bynk.http.security_unknown_field",
1482        "A `security { }` policy declares a field outside the closed set.",
1483    ),
1484    dg(
1485        "bynk.http.unbound_path_param",
1486        "A `:name` route segment has no matching handler parameter.",
1487        &["http_handler"],
1488    ),
1489    d(
1490        "bynk.http.unknown_handler_annotation",
1491        "A handler carries an annotation outside the closed set (`@cache`/`@limit`).",
1492    ),
1493    d(
1494        "bynk.index.bad_argument",
1495        "An `@indexed` argument is not a `by: <field>` label.",
1496    ),
1497    warn(d(
1498        "bynk.index.missing",
1499        "A query filters a map by equality on a field that is not `@indexed` (a perf-hint warning).",
1500    )),
1501    d(
1502        "bynk.index.unkeyable_key",
1503        "An `@indexed(by: k)` field is not value-keyable.",
1504    ),
1505    d(
1506        "bynk.index.unknown_key",
1507        "An `@indexed(by: k)` field is not a field of the map's value type.",
1508    ),
1509    warn(d(
1510        "bynk.index.unused",
1511        "A declared `@indexed(by: k)` is never used by an equality filter (a hygiene warning).",
1512    )),
1513    d(
1514        "bynk.invariant.cross_agent_reference",
1515        "An invariant predicate references another agent; invariants are per-agent.",
1516    ),
1517    d(
1518        "bynk.invariant.duplicate_name",
1519        "An agent declares two invariants with the same name.",
1520    ),
1521    d(
1522        "bynk.invariant.impure_predicate",
1523        "An invariant predicate uses an effectful or test-only construct.",
1524    ),
1525    d(
1526        "bynk.invariant.not_bool",
1527        "An invariant predicate does not have type `Bool`.",
1528    ),
1529    dg(
1530        "bynk.lambda.unannotated_param",
1531        "A lambda parameter has no type annotation in a position where no function type is expected to infer it from.",
1532        &["lambda_expr"],
1533    ),
1534    dg(
1535        "bynk.lex.bad_escape",
1536        "An invalid escape sequence in a string literal.",
1537        &["string_literal"],
1538    ),
1539    dg(
1540        "bynk.lex.bad_unicode_escape",
1541        "A `\\u{…}` escape names a surrogate or a value above U+10FFFF.",
1542        &["string_literal"],
1543    ),
1544    dg(
1545        "bynk.lex.decimal_literal_too_large",
1546        "A decimal literal has more than 100 fraction digits or more than 1000 characters, the most any `Decimal` may have (#2622).",
1547        &["decimal_literal"],
1548    ),
1549    dg(
1550        "bynk.lex.float_literal_overflow",
1551        "A float literal does not fit a finite 64-bit float.",
1552        &["float_literal"],
1553    ),
1554    dg(
1555        "bynk.lex.integer_overflow",
1556        "An integer literal is outside the `Int` range, the JS safe integers ±(2^53 − 1).",
1557        &["number_literal"],
1558    ),
1559    dg(
1560        "bynk.lex.interpolation_too_deep",
1561        "A string interpolation `\\(…)` nests deeper than the lexer's fixed limit.",
1562        &["string_literal"],
1563    ),
1564    d(
1565        "bynk.lex.legacy_comment",
1566        "A `--` line comment, the spelling before #2203; a comment is `//` (auto-fixable; `bynk fmt` rewrites it).",
1567    ),
1568    d(
1569        "bynk.lex.legacy_doc_line",
1570        "A `--|` one-line doc, the spelling before #2203; a one-line doc is `--- text` (auto-fixable; `bynk fmt` rewrites it).",
1571    ),
1572    dg(
1573        "bynk.lex.multiline_close_not_own_line",
1574        "A `\"\"\"` inside a multi-line string literal is not on a line of its own.",
1575        &["string_literal"],
1576    ),
1577    dg(
1578        "bynk.lex.multiline_in_hole",
1579        "A multi-line string literal appears inside an interpolation hole, which must close on its own line.",
1580        &["string_literal"],
1581    ),
1582    dg(
1583        "bynk.lex.multiline_indent",
1584        "A line of a multi-line string literal is indented less than its closing `\"\"\"`.",
1585        &["string_literal"],
1586    ),
1587    dg(
1588        "bynk.lex.multiline_open",
1589        "The opening `\"\"\"` of a multi-line string literal is not followed by a newline.",
1590        &["string_literal"],
1591    ),
1592    d(
1593        "bynk.lex.slash_doc",
1594        "A `///` doc comment first on its line; a Bynk doc is `--- text` or a `---` block (auto-fixable).",
1595    ),
1596    d(
1597        "bynk.lex.unclosed_doc_block",
1598        "A documentation block is not closed.",
1599    ),
1600    d(
1601        "bynk.lex.unexpected_character",
1602        "An unexpected character in the source.",
1603    ),
1604    dg(
1605        "bynk.lex.unterminated_interpolation",
1606        "An interpolation hole `\\(…)` is not closed on its line.",
1607        &["string_literal"],
1608    ),
1609    dg(
1610        "bynk.lex.unterminated_string",
1611        "A string literal is not terminated.",
1612        &["string_literal"],
1613    ),
1614    warn(d(
1615        "bynk.list.deprecated_function",
1616        "A `bynk.list` free function (`map`/`filter`/`find`/`any`/`all`) is deprecated in favour of the `List` method form (warning; auto-fixable).",
1617    )),
1618    d(
1619        "bynk.locale.multiple_message_bundles",
1620        "A context consumes `Locale` but its direct `uses` reaches two or more message-bundle commons — there is no single bundle to negotiate against.",
1621    ),
1622    d(
1623        "bynk.messages.format_mismatch",
1624        "A code's placeholder is formatted as a different ICU kind (plain/plural/select/number/date) across declared locales.",
1625    ),
1626    d(
1627        "bynk.messages.incomplete",
1628        "A locale is missing a code the reference locale declares.",
1629    ),
1630    d(
1631        "bynk.messages.invalid_locale_tag",
1632        "A `messages` block's locale tag is not a valid `LocaleTag` (e.g. `messages \"xx\"` where `xx` doesn't match the tag pattern).",
1633    ),
1634    d(
1635        "bynk.messages.malformed_icu_syntax",
1636        "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).",
1637    ),
1638    d(
1639        "bynk.messages.missing_locale_dependency",
1640        "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.",
1641    ),
1642    d(
1643        "bynk.messages.missing_reference",
1644        "A message bundle has no `@reference` block.",
1645    ),
1646    d(
1647        "bynk.messages.multiple_reference",
1648        "A message bundle has more than one `@reference` block.",
1649    ),
1650    d(
1651        "bynk.messages.outside_commons",
1652        "A `messages` declaration appears outside a commons.",
1653    ),
1654    d(
1655        "bynk.messages.placeholder_mismatch",
1656        "A locale's template for a code uses a different set of `{name}` placeholders than the reference locale's.",
1657    ),
1658    d(
1659        "bynk.namespace.reserved",
1660        "A user unit is named `bynk` or `bynk.*`; the `bynk` root is reserved for the toolchain.",
1661    ),
1662    d(
1663        "bynk.observe.impure_with",
1664        "A `with` predicate uses an effectful or test-only construct; it must be pure.",
1665    ),
1666    d(
1667        "bynk.observe.not_a_seam",
1668        "An observation targets a capability the unit under test does not consume.",
1669    ),
1670    d(
1671        "bynk.observe.trace_outside_test",
1672        "`trace(Cap.op)` appears outside a `case` body.",
1673    ),
1674    d(
1675        "bynk.observe.unknown_op",
1676        "An observation names an operation the capability does not declare.",
1677    ),
1678    d(
1679        "bynk.observe.with_not_bool",
1680        "A `with` predicate does not have type `Bool`.",
1681    ),
1682    d(
1683        "bynk.package.alias_shadows_unit",
1684        "A dependency alias in `[dependencies]` is also the first segment of one of the project's own units, so `<alias>.…` would be ambiguous.",
1685    ),
1686    d(
1687        "bynk.package.checksum_mismatch",
1688        "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.",
1689    ),
1690    d(
1691        "bynk.package.dependency_cycle",
1692        "The package graph has a cycle: a dependency depends, directly or not, on itself or on the project.",
1693    ),
1694    d(
1695        "bynk.package.dependency_not_found",
1696        "A path dependency's directory has no readable `bynk.toml`, its `bynk.toml` is invalid, or it has no `[package]`.",
1697    ),
1698    d(
1699        "bynk.package.dev_dependency_in_source",
1700        "A commons, context or adapter reaches a `[dev-dependencies]` alias, which only a suite may use.",
1701    ),
1702    d(
1703        "bynk.package.duplicate_source",
1704        "One package is reached from two different directories; a build holds one copy of each package.",
1705    ),
1706    d(
1707        "bynk.package.git_failed",
1708        "`git` couldn't clone, fetch or check out a git dependency, or the revision it names doesn't exist.",
1709    ),
1710    d(
1711        "bynk.package.lock_invalid",
1712        "`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.",
1713    ),
1714    d(
1715        "bynk.package.lock_out_of_date",
1716        "`--locked` was given, and resolving the manifests would change `bynk.lock`.",
1717    ),
1718    d(
1719        "bynk.package.name_mismatch",
1720        "A path dependency's `package` names a different package than the directory's `[package] name`.",
1721    ),
1722    d(
1723        "bynk.package.not_fetched",
1724        "A git dependency has no `bynk.lock` entry, or its store entry is missing; `bynk fetch` fetches it (refused under `--offline`).",
1725    ),
1726    d(
1727        "bynk.package.unit_not_exported",
1728        "A `uses` or `consumes` reaches a unit its dependency declares but doesn't list in `[package] exports`.",
1729    ),
1730    d(
1731        "bynk.package.unknown_unit",
1732        "A `uses` or `consumes` names, through a dependency alias, a unit the dependency doesn't declare.",
1733    ),
1734    d(
1735        "bynk.package.unsafe_source",
1736        "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).",
1737    ),
1738    d(
1739        "bynk.package.unsupported_in_dependency",
1740        "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.",
1741    ),
1742    d(
1743        "bynk.package.version_conflict",
1744        "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.",
1745    ),
1746    dg(
1747        "bynk.par.invalid_statement",
1748        "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.",
1749        &["par_stmt"],
1750    ),
1751    dg(
1752        "bynk.par.question_in_join",
1753        "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.",
1754        &["par_stmt"],
1755    ),
1756    dg(
1757        "bynk.par.sibling_name",
1758        "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.",
1759        &["par_stmt"],
1760    ),
1761    warn(dg(
1762        "bynk.par.single_binding",
1763        "A `par { … }` block has a single binding, which is a plain `let x <- e` with extra syntax (warning).",
1764        &["par_stmt"],
1765    )),
1766    dg(
1767        "bynk.parse.const_missing_type",
1768        "A `const` declaration has no type annotation; a constant's type is always written (`const Name: Type = …`).",
1769        &["const_decl"],
1770    ),
1771    dg(
1772        "bynk.parse.consumes_after_decls",
1773        "`consumes` appears after other declarations.",
1774        &["consumes_decl"],
1775    ),
1776    d(
1777        "bynk.parse.dangling_handler_annotation",
1778        "A handler-position annotation (e.g. `@cache`) is not followed by an `on` handler.",
1779    ),
1780    d(
1781        "bynk.parse.doc_block_contains_code",
1782        "A documentation block's content (outside Markdown code fences) parses as declarations, so a pair of dash dividers has turned code into documentation.",
1783    ),
1784    dg(
1785        "bynk.parse.duplicate_cors",
1786        "A service declares more than one `cors { }` policy.",
1787        &["service_decl"],
1788    ),
1789    dg(
1790        "bynk.parse.duplicate_limits",
1791        "A service declares more than one `limits { }` policy.",
1792        &["service_decl"],
1793    ),
1794    dg(
1795        "bynk.parse.duplicate_security",
1796        "A service declares more than one `security { }` policy.",
1797        &["service_decl"],
1798    ),
1799    dg(
1800        "bynk.parse.empty_agent",
1801        "An `agent` body is empty.",
1802        &["agent_decl"],
1803    ),
1804    dg(
1805        "bynk.parse.empty_capability",
1806        "A `capability` body is empty.",
1807        &["capability_decl"],
1808    ),
1809    d(
1810        "bynk.parse.empty_interpolation",
1811        "An interpolation hole `\\(…)` contains no expression.",
1812    ),
1813    dg(
1814        "bynk.parse.empty_match",
1815        "A `match` has no arms.",
1816        &["match_expr"],
1817    ),
1818    dg(
1819        "bynk.parse.empty_service",
1820        "A `service` body is empty.",
1821        &["service_decl"],
1822    ),
1823    d(
1824        "bynk.parse.event_pattern_empty",
1825        "A `from Events(E { ... })` subscription pattern listed no fields — use `from Events(E)` (no braces) for an unfiltered subscription.",
1826    ),
1827    dg(
1828        "bynk.parse.expected_agent_key",
1829        "Expected a `key` declaration in an agent.",
1830        &["agent_decl"],
1831    ),
1832    d(
1833        "bynk.parse.expected_agent_storage",
1834        "An agent declares no storage — it has no `store` fields.",
1835    ),
1836    dg(
1837        "bynk.parse.expected_base_type",
1838        "Expected a base type.",
1839        &["base_type"],
1840    ),
1841    dg(
1842        "bynk.parse.expected_capability_op",
1843        "Expected a capability operation.",
1844        &["capability_op"],
1845    ),
1846    d("bynk.parse.expected_expression", "Expected an expression."),
1847    dg(
1848        "bynk.parse.expected_handler",
1849        "Expected a handler.",
1850        &["handler"],
1851    ),
1852    d("bynk.parse.expected_item", "Expected a declaration."),
1853    dg(
1854        "bynk.parse.expected_predicate",
1855        "Expected a refinement predicate.",
1856        &["refinement"],
1857    ),
1858    dg(
1859        "bynk.parse.expected_provider_op",
1860        "Expected a provider operation.",
1861        &["provider_op"],
1862    ),
1863    d("bynk.parse.expected_token", "Expected a specific token."),
1864    d("bynk.parse.expected_type", "Expected a type."),
1865    d(
1866        "bynk.parse.expected_unit_header",
1867        "Expected a `commons` or `context` header.",
1868    ),
1869    dg(
1870        "bynk.parse.expected_visibility",
1871        "Expected a visibility keyword.",
1872        &["exports_decl"],
1873    ),
1874    dg(
1875        "bynk.parse.exports_after_decls",
1876        "`exports` appears after other declarations.",
1877        &["exports_decl"],
1878    ),
1879    d(
1880        "bynk.parse.extra_tokens",
1881        "Unexpected tokens after an otherwise complete construct.",
1882    ),
1883    dg(
1884        "bynk.parse.generic_arg_count",
1885        "Wrong number of generic type arguments.",
1886        &["generic_type_ref"],
1887    ),
1888    dg(
1889        "bynk.parse.handler_in_agent",
1890        "A protocol handler (`on GET`/`schedule`/`message`) was declared in an agent.",
1891        &["handler"],
1892    ),
1893    d(
1894        "bynk.parse.invariant_after_handler",
1895        "An `invariant` was declared after a handler; invariants precede handlers.",
1896    ),
1897    dg(
1898        "bynk.parse.lambda_pattern_annotation",
1899        "A lambda parameter with a record pattern carries a type annotation; the pattern's type name already gives the parameter's type.",
1900        &["lambda_param"],
1901    ),
1902    dg(
1903        "bynk.parse.lambda_pattern_not_record",
1904        "A lambda parameter is a pattern other than a record pattern; only an irrefutable record pattern may stand in for a name.",
1905        &["lambda_param"],
1906    ),
1907    dg(
1908        "bynk.parse.lambda_pattern_refutable",
1909        "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.",
1910        &["lambda_param"],
1911    ),
1912    dg(
1913        "bynk.parse.let_else_on_binding",
1914        "An `else` follows a plain `let name = …` binding, which matches every value, so the `else` could never run.",
1915        &["let_stmt", "effect_let_stmt"],
1916    ),
1917    dg(
1918        "bynk.parse.let_pattern_annotation",
1919        "A `let` with a pattern carries a type annotation; the pattern's names take their types from the value.",
1920        &["let_else_stmt"],
1921    ),
1922    dg(
1923        "bynk.parse.let_pattern_without_else",
1924        "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.",
1925        &["let_else_stmt"],
1926    ),
1927    dg(
1928        "bynk.parse.list_rest_not_last",
1929        "A `..` in a list pattern is not the final element; suffix forms such as `[.., last]` are not available.",
1930        &["list_pattern"],
1931    ),
1932    dg(
1933        "bynk.parse.malformed_float_literal",
1934        "A float literal is missing a digit on one side of the `.` (`1.`, `.5`).",
1935        &["float_literal"],
1936    ),
1937    d(
1938        "bynk.parse.migrate_after_handler",
1939        "A `migrate` step is declared after an agent handler; migration steps precede the handlers.",
1940    ),
1941    d(
1942        "bynk.parse.migrate_item",
1943        "A `migrate` step's body holds something other than `field := value`, `let` or `drop field`.",
1944    ),
1945    d(
1946        "bynk.parse.multiple_docs",
1947        "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.",
1948    ),
1949    d(
1950        "bynk.parse.nesting_too_deep",
1951        "An expression or type nests deeper than the parser's fixed limit.",
1952    ),
1953    d(
1954        "bynk.parse.no_remainder_operator",
1955        "`%` is not an operator; use `Int.rem` (the dividend's sign) or `Int.mod` (the divisor's).",
1956    ),
1957    dg(
1958        "bynk.parse.non_associative",
1959        "A non-associative operator was chained (e.g. `a == b == c`).",
1960        &["binary_expr"],
1961    ),
1962    warn(d(
1963        "bynk.parse.orphan_doc_block",
1964        "A documentation block is not attached to a declaration (warning).",
1965    )),
1966    dg(
1967        "bynk.parse.policy_order",
1968        "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`.",
1969        &["service_decl"],
1970    ),
1971    dg(
1972        "bynk.parse.record_pattern_in_is_unparenthesised",
1973        "A record pattern after `is` is not parenthesised — write `x is (T { f, .. })`.",
1974        &["record_pattern"],
1975    ),
1976    dg(
1977        "bynk.parse.record_pattern_without_rest",
1978        "A record pattern does not end with `..`; every record pattern is open.",
1979        &["record_pattern"],
1980    ),
1981    dg(
1982        "bynk.parse.refined_pattern_inner",
1983        "A refined pattern's inner form is something other than `_`.",
1984        &["refined_pattern"],
1985    ),
1986    dg(
1987        "bynk.parse.reserved_keyword",
1988        "A reserved keyword was used as an identifier.",
1989        &["identifier"],
1990    ),
1991    dg(
1992        "bynk.parse.self_outside_method",
1993        "`self` used outside a method or handler.",
1994        &["self_expr"],
1995    ),
1996    d(
1997        "bynk.parse.storage_after_phase",
1998        "Agent storage (`state` / `store`) is declared after the invariants or handlers.",
1999    ),
2000    d(
2001        "bynk.parse.transition_after_handler",
2002        "A `transition` is declared after an agent handler; step invariants precede the handlers.",
2003    ),
2004    d(
2005        "bynk.parse.unexpected_adapter",
2006        "An `adapter` appeared where it is not allowed.",
2007    ),
2008    dg(
2009        "bynk.parse.unexpected_context",
2010        "A `context` appeared where it is not allowed.",
2011        &["context_decl"],
2012    ),
2013    d("bynk.parse.unexpected_eof", "Unexpected end of input."),
2014    dg(
2015        "bynk.parse.unexpected_suite",
2016        "A `suite` appeared where it is not allowed.",
2017        &["suite_decl"],
2018    ),
2019    d(
2020        "bynk.parse.unknown_effect_method",
2021        "An unknown method on `Effect`.",
2022    ),
2023    dg(
2024        "bynk.parse.unknown_handler_kind",
2025        "An unknown handler form (expected `call`, an HTTP method, `schedule`, or `message`).",
2026        &["handler"],
2027    ),
2028    dg(
2029        "bynk.parse.unknown_predicate",
2030        "An unknown refinement predicate.",
2031        &["predicate_name"],
2032    ),
2033    d(
2034        "bynk.parse.unknown_tier",
2035        "A `case`/`suite` `as <tier>` clause names something other than `unit`, `integration`, or `system`.",
2036    ),
2037    dg(
2038        "bynk.parse.uses_after_decls",
2039        "`uses` appears after other declarations.",
2040        &["uses_decl"],
2041    ),
2042    dg(
2043        "bynk.parse.variant_name_case",
2044        "A sum-type or enum variant name is not capitalised.",
2045        &["sum_variant", "enum_type"],
2046    ),
2047    d(
2048        "bynk.project.contracts_lock_corrupt",
2049        "`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.",
2050    ),
2051    warn(d(
2052        "bynk.project.contracts_lock_oversized",
2053        "`bynk.contracts.lock` has one service accepting more older contracts than the build keeps comfortably (warning).",
2054    )),
2055    warn(d(
2056        "bynk.project.contracts_lock_stale",
2057        "`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).",
2058    )),
2059    warn(d(
2060        "bynk.project.duplicate_compatibility_flag",
2061        "`bynk.toml`'s `[workers] compatibility_flags` lists a flag twice, or one every Bynk Worker already has; the duplicate is dropped (warning).",
2062    )),
2063    d(
2064        "bynk.project.duplicate_module_doc",
2065        "More than one file of a multi-file unit carries a module doc.",
2066    ),
2067    d(
2068        "bynk.project.export_context",
2069        "`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.",
2070    ),
2071    d(
2072        "bynk.project.export_unknown",
2073        "`bynk.toml`'s `[package] exports` lists a name that isn't a commons or adapter the project declares.",
2074    ),
2075    d(
2076        "bynk.project.file_and_directory",
2077        "A unit exists as both a file and a directory.",
2078    ),
2079    d(
2080        "bynk.project.inconsistent_commons_name",
2081        "A source file's path does not match its declared name.",
2082    ),
2083    d(
2084        "bynk.project.kind_conflict",
2085        "A name is declared as both a commons and a context.",
2086    ),
2087    d(
2088        "bynk.project.no_root",
2089        "No project root could be determined.",
2090    ),
2091    d(
2092        "bynk.project.no_sources",
2093        "The project contains no source files.",
2094    ),
2095    d(
2096        "bynk.project.read_failed",
2097        "A source file could not be read.",
2098    ),
2099    d(
2100        "bynk.project.schema_registry_corrupt",
2101        "`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.",
2102    ),
2103    warn(d(
2104        "bynk.project.unstable_not_experimental",
2105        "`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).",
2106    )),
2107    d(
2108        "bynk.project.unstable_unknown_item",
2109        "`bynk.toml`'s `[unstable] allow` lists a path that names no standard-library unit, exported item or operation.",
2110    ),
2111    dg(
2112        "bynk.property.restates_refinement",
2113        "A `property` merely re-checks a refinement its type already guarantees.",
2114        &["for_all"],
2115    ),
2116    dg(
2117        "bynk.property.where_not_bool",
2118        "A `for all ... where` filter does not type to `Bool`.",
2119        &["for_all"],
2120    ),
2121    dg(
2122        "bynk.provider.agent_call_undeclared_capability",
2123        "A provider calls an agent handler that needs a capability the provider's `given` does not list.",
2124        &["provider_decl"],
2125    ),
2126    dg(
2127        "bynk.provider.dependency_cycle",
2128        "Providers form a capability dependency cycle through `given`.",
2129        &["provider_decl"],
2130    ),
2131    dg(
2132        "bynk.provider.extra_operation",
2133        "A `provides` block implements an operation not in the capability.",
2134        &["provider_decl"],
2135    ),
2136    dg(
2137        "bynk.provider.generic_op_requires_external",
2138        "A Bynk-bodied `provides` implements a capability operation that declares its own type parameter — only an external (bodiless) provider can.",
2139        &["provider_decl"],
2140    ),
2141    dg(
2142        "bynk.provider.missing_operation",
2143        "A `provides` block is missing a capability operation.",
2144        &["provider_decl"],
2145    ),
2146    dg(
2147        "bynk.provider.outside_context",
2148        "`provides` was declared outside a context.",
2149        &["provider_decl"],
2150    ),
2151    dg(
2152        "bynk.provider.signature_mismatch",
2153        "A `provides` operation's signature does not match the capability.",
2154        &["provider_decl"],
2155    ),
2156    dg(
2157        "bynk.provider.unknown_capability",
2158        "`provides` names a capability that does not exist.",
2159        &["provider_decl"],
2160    ),
2161    d(
2162        "bynk.query.join_key_mismatch",
2163        "A `joinOn`/`leftJoin` left and right key function return different types.",
2164    ),
2165    dg(
2166        "bynk.query.sum_needs_numeric",
2167        "A `sum`/`average` key function does not return a numeric type (`Int`, `Float`, or `Duration`).",
2168        &[],
2169    ),
2170    dg(
2171        "bynk.queue.bad_params",
2172        "An `on message` handler does not take exactly one `message` parameter.",
2173        &["queue_handler"],
2174    ),
2175    dg(
2176        "bynk.queue.duplicate_consumer",
2177        "Two `on message` handlers consume the same queue.",
2178        &["queue_handler"],
2179    ),
2180    dg(
2181        "bynk.queue.invalid_name",
2182        "A `from queue(\"…\")` binding has an empty queue name, or one Cloudflare refuses.",
2183        &["queue_handler"],
2184    ),
2185    dg(
2186        "bynk.queue.return_not_queue_result",
2187        "An `on message` handler does not return `Effect[QueueResult]`.",
2188        &["handler"],
2189    ),
2190    dg(
2191        "bynk.race.in_agent_handler",
2192        "`a.race(b)` was used in an agent handler, which has no execution context to hand the losing effect to.",
2193        &["method_call"],
2194    ),
2195    dg(
2196        "bynk.race.in_pure_context",
2197        "`a.race(b)` was used in a pure (non-effectful) context.",
2198        &["method_call"],
2199    ),
2200    dg(
2201        "bynk.race.outside_handler",
2202        "`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.",
2203        &["method_call"],
2204    ),
2205    dg(
2206        "bynk.record_spread.field_type_mismatch",
2207        "A record-spread override has the wrong type for the field.",
2208        &["record_spread"],
2209    ),
2210    dg(
2211        "bynk.record_spread.non_record_base",
2212        "The base of a record spread is not a record.",
2213        &["record_spread"],
2214    ),
2215    dg(
2216        "bynk.record_spread.type_mismatch",
2217        "A record spread's base is a different record type.",
2218        &["record_spread"],
2219    ),
2220    dg(
2221        "bynk.record_spread.unknown_field",
2222        "A record spread overrides a field the record does not have.",
2223        &["record_spread"],
2224    ),
2225    dg(
2226        "bynk.refine.literal_violates",
2227        "A literal does not satisfy the refined type's predicate.",
2228        &["refined_type"],
2229    ),
2230    d(
2231        "bynk.registry.account_refused",
2232        "`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).",
2233    ),
2234    d(
2235        "bynk.registry.bad_archive",
2236        "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.",
2237    ),
2238    d(
2239        "bynk.registry.bad_signature",
2240        "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).",
2241    ),
2242    d(
2243        "bynk.registry.http_failed",
2244        "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.",
2245    ),
2246    d(
2247        "bynk.registry.key_mismatch",
2248        "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`.",
2249    ),
2250    d(
2251        "bynk.registry.nonconformant",
2252        "`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.",
2253    ),
2254    d(
2255        "bynk.registry.publish_refused",
2256        "`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).",
2257    ),
2258    d(
2259        "bynk.registry.source_mismatch",
2260        "`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.",
2261    ),
2262    d(
2263        "bynk.registry.unavailable",
2264        "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.",
2265    ),
2266    d(
2267        "bynk.registry.withdrawn",
2268        "`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.",
2269    ),
2270    dg(
2271        "bynk.requires.conflicting_range",
2272        "Two adapter `binding … requires { … }` entries give different version ranges for one npm package.",
2273        &["binding_decl"],
2274    ),
2275    dg(
2276        "bynk.requires.unapproved",
2277        "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>`.",
2278        &["binding_decl"],
2279    ),
2280    dg(
2281        "bynk.requires.unpinned_dependency",
2282        "An adapter `binding … requires { … }` entry has an unpinned version range.",
2283        &["binding_decl"],
2284    ),
2285    d(
2286        "bynk.resolve.ambiguous_variant",
2287        "A variant name is ambiguous across several sum types.",
2288    ),
2289    dg(
2290        "bynk.resolve.arity_mismatch",
2291        "A function was called with the wrong number of arguments.",
2292        &["call"],
2293    ),
2294    dg(
2295        "bynk.resolve.bad_const_initialiser",
2296        "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.",
2297        &["const_decl"],
2298    ),
2299    dg(
2300        "bynk.resolve.const_cycle",
2301        "Constants refer to each other in a cycle, so none of them has a value.",
2302        &["const_decl"],
2303    ),
2304    dg(
2305        "bynk.resolve.const_name_case",
2306        "A constant's name is not upper-camel case (`MaxRetries`, not `maxRetries`).",
2307        &["const_decl"],
2308    ),
2309    dg(
2310        "bynk.resolve.const_outside_context_or_commons",
2311        "A `const` declaration appears outside a context or commons.",
2312        &["const_decl"],
2313    ),
2314    d("bynk.resolve.duplicate_actor", "Two actors share a name."),
2315    dg(
2316        "bynk.resolve.duplicate_agent",
2317        "Two agents share a name.",
2318        &["agent_decl"],
2319    ),
2320    dg(
2321        "bynk.resolve.duplicate_capability",
2322        "Two capabilities share a name.",
2323        &["capability_decl"],
2324    ),
2325    dg(
2326        "bynk.resolve.duplicate_const",
2327        "Two constants share a name.",
2328        &["const_decl"],
2329    ),
2330    dg(
2331        "bynk.resolve.duplicate_field",
2332        "A record declares a field twice.",
2333        &["record_type"],
2334    ),
2335    dg(
2336        "bynk.resolve.duplicate_field_init",
2337        "A record construction initialises a field twice.",
2338        &["record_construction"],
2339    ),
2340    dg(
2341        "bynk.resolve.duplicate_fn",
2342        "Two functions share a name.",
2343        &["fn_decl"],
2344    ),
2345    d(
2346        "bynk.resolve.duplicate_message_code",
2347        "A message bundle declares the same code twice in one block.",
2348    ),
2349    d(
2350        "bynk.resolve.duplicate_message_locale",
2351        "Two `messages` blocks in one bundle declare the same locale tag.",
2352    ),
2353    dg(
2354        "bynk.resolve.duplicate_method",
2355        "Two methods share a name.",
2356        &["fn_decl"],
2357    ),
2358    dg(
2359        "bynk.resolve.duplicate_param",
2360        "A parameter name is repeated.",
2361        &["param"],
2362    ),
2363    dg(
2364        "bynk.resolve.duplicate_provider",
2365        "A capability is provided more than once.",
2366        &["provider_decl"],
2367    ),
2368    dg(
2369        "bynk.resolve.duplicate_service",
2370        "Two services share a name.",
2371        &["service_decl"],
2372    ),
2373    dg(
2374        "bynk.resolve.duplicate_type",
2375        "Two types share a name.",
2376        &["type_decl"],
2377    ),
2378    dg(
2379        "bynk.resolve.duplicate_variant",
2380        "A sum type declares a variant twice.",
2381        &["sum_type"],
2382    ),
2383    d(
2384        "bynk.resolve.fn_without_call",
2385        "A function was referenced without being called.",
2386    ),
2387    dg(
2388        "bynk.resolve.let_shadows_fn",
2389        "A `let` binding shadows a function.",
2390        &["let_stmt"],
2391    ),
2392    dg(
2393        "bynk.resolve.let_shadows_type",
2394        "A `let` binding shadows a type.",
2395        &["let_stmt"],
2396    ),
2397    d(
2398        "bynk.resolve.method_unknown_type",
2399        "A method is defined on an unknown type.",
2400    ),
2401    dg(
2402        "bynk.resolve.missing_field",
2403        "A record construction omits a required field.",
2404        &["record_construction"],
2405    ),
2406    d(
2407        "bynk.resolve.name_conflict",
2408        "Two declarations share a name.",
2409    ),
2410    dg(
2411        "bynk.resolve.not_a_record_type",
2412        "Record syntax was used on a non-record type.",
2413        &["record_construction"],
2414    ),
2415    dg(
2416        "bynk.resolve.opaque_record_construction",
2417        "An opaque type was constructed with record syntax.",
2418        &["record_construction"],
2419    ),
2420    dg(
2421        "bynk.resolve.param_as_function",
2422        "A value (such as a parameter) was called as a function.",
2423        &["call"],
2424    ),
2425    dg(
2426        "bynk.resolve.recursive_record_field",
2427        "A record directly contains a field of its own type.",
2428        &["record_type"],
2429    ),
2430    dg(
2431        "bynk.resolve.reserved_builtin_type",
2432        "A type declaration reuses a compiler-known built-in type name.",
2433        &["type_decl"],
2434    ),
2435    dg(
2436        "bynk.resolve.reserved_host_name",
2437        "A declaration is named `globalThis`, which the generated TypeScript uses to reach host globals.",
2438        &["type_decl", "fn_decl", "agent_decl", "provider_decl"],
2439    ),
2440    dg(
2441        "bynk.resolve.reserved_payload_field",
2442        "A sum variant declares a payload field named `kind`, the variant's wire discriminant.",
2443        &["sum_type"],
2444    ),
2445    dg(
2446        "bynk.resolve.self_outside_method",
2447        "`self` referenced outside a method or handler.",
2448        &["self_expr"],
2449    ),
2450    dg(
2451        "bynk.resolve.type_as_function",
2452        "A type name was called as if it were a function.",
2453        &["call"],
2454    ),
2455    d(
2456        "bynk.resolve.type_in_expr",
2457        "A type name was used where a value is expected.",
2458    ),
2459    dg(
2460        "bynk.resolve.unconsumed_context",
2461        "A context's service was called without a `consumes` declaration.",
2462        &["consumes_decl"],
2463    ),
2464    dg(
2465        "bynk.resolve.unknown_field",
2466        "Accessed a field the record does not have.",
2467        &["field_access"],
2468    ),
2469    dg(
2470        "bynk.resolve.unknown_function",
2471        "Called a function that does not exist.",
2472        &["call"],
2473    ),
2474    d(
2475        "bynk.resolve.unknown_name",
2476        "Referenced a name that is not in scope.",
2477    ),
2478    dg(
2479        "bynk.resolve.unknown_static_member",
2480        "Referenced an unknown static member (e.g. `T.x`).",
2481        &["field_access"],
2482    ),
2483    d(
2484        "bynk.resolve.unknown_type",
2485        "Referenced a type that does not exist.",
2486    ),
2487    warn(d(
2488        "bynk.secrets.computed_name",
2489        "A `bynk.Secrets` read names its secret with a computed expression rather than a literal, so `bynk deploy` cannot plan it (warning).",
2490    )),
2491    dg(
2492        "bynk.send.in_agent_handler",
2493        "A `~>` send was used in an agent handler, which has no execution context to keep a fire-and-forget send alive.",
2494        &["effect_send_stmt"],
2495    ),
2496    dg(
2497        "bynk.send.in_pure_context",
2498        "A `~>` send was used in a pure (non-effectful) context.",
2499        &["effect_send_stmt"],
2500    ),
2501    dg(
2502        "bynk.send.non_effect",
2503        "A `~>` send was applied to a non-`Effect` value.",
2504        &["effect_send_stmt"],
2505    ),
2506    dg(
2507        "bynk.send.requires_unit",
2508        "A `~>` send targets an operation whose reply is not `Effect[()]`.",
2509        &["effect_send_stmt"],
2510    ),
2511    dg(
2512        "bynk.send.store_op",
2513        "A `~>` send targets an agent store operation, which is part of the handler's atomic commit and cannot be sent without waiting.",
2514        &["effect_send_stmt"],
2515    ),
2516    dg(
2517        "bynk.service.missing_from",
2518        "A `from`-less service has a handler other than `on call`.",
2519        &["service_decl"],
2520    ),
2521    dg(
2522        "bynk.service.mixed_protocols",
2523        "A service mixes handler forms that do not match its `from <protocol>`.",
2524        &["service_decl"],
2525    ),
2526    dg(
2527        "bynk.service.outside_context",
2528        "A `service` was declared outside a context.",
2529        &["service_decl"],
2530    ),
2531    dg(
2532        "bynk.service.return_not_effect",
2533        "A service handler's return type is not an `Effect`.",
2534        &["service_decl"],
2535    ),
2536    dg(
2537        "bynk.service.unknown_protocol",
2538        "A `from <protocol>` names an unknown protocol (e.g. a transport like Kafka).",
2539        &["service_decl"],
2540    ),
2541    d(
2542        "bynk.service.unknown_via_clause",
2543        "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.",
2544    ),
2545    d(
2546        "bynk.service.websocket_header",
2547        "The `from websocket` header is malformed — it binds frame types as `websocket(in: <type>, out: <type>)` (real-time track slice 3).",
2548    ),
2549    d(
2550        "bynk.service.websocket_multiple",
2551        "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).",
2552    ),
2553    d(
2554        "bynk.service.websocket_open_arity",
2555        "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).",
2556    ),
2557    d(
2558        "bynk.service.websocket_param_not_stringy",
2559        "A `from websocket` service's `on open` parameter has a type not constructible from `String`; it arrives as a query-string value (#1657).",
2560    ),
2561    d(
2562        "bynk.stability.experimental",
2563        "An experimental standard-library item is used without an `[unstable] allow` entry in `bynk.toml` covering it.",
2564    ),
2565    d(
2566        "bynk.store.annotation_kind_mismatch",
2567        "A storage annotation is used on a kind it does not apply to (e.g. `@ttl` on a `Map`).",
2568    ),
2569    d(
2570        "bynk.store.annotation_unsupported",
2571        "A known storage annotation (`@ttl`/`@retain`/`@indexed`/`@bounded`) is used before the slice that supports it.",
2572    ),
2573    d(
2574        "bynk.store.cache_needs_clock",
2575        "A handler performs a `Cache` operation (TTL expiry reads the clock) without declaring `given Clock`.",
2576    ),
2577    d(
2578        "bynk.store.cache_ttl_required",
2579        "A `Cache` field is missing its required `@ttl(<duration>)` annotation (a keyed store with no expiry is a `Map`).",
2580    ),
2581    d(
2582        "bynk.store.kind_arity",
2583        "A storage kind was applied to the wrong number of type arguments (e.g. `Cell[A, B]`).",
2584    ),
2585    d(
2586        "bynk.store.kind_unsupported",
2587        "A known storage kind (`Queue`) is used before the slice that supports it.",
2588    ),
2589    d(
2590        "bynk.store.log_needs_clock",
2591        "A handler calls `Log.append` (which stamps the current time) without declaring `given Clock`.",
2592    ),
2593    d(
2594        "bynk.store.unkeyable_key",
2595        "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).",
2596    ),
2597    d(
2598        "bynk.store.unknown_annotation",
2599        "A `store` field carries an annotation outside the closed `@indexed`/`@ttl`/`@retain`/`@bounded` set.",
2600    ),
2601    d(
2602        "bynk.store.unknown_kind",
2603        "A `store` field's type is not a known storage kind.",
2604    ),
2605    d(
2606        "bynk.store.unknown_map_accessor",
2607        "A `store Map` field access is not one of its query accessors (`entries`/`keys`/`values`).",
2608    ),
2609    d(
2610        "bynk.store.unknown_op",
2611        "A storage-`Map`/`Set` operation is not a recognised entry/membership method.",
2612    ),
2613    d(
2614        "bynk.stub.after_type",
2615        "A test `stub … returns <value> after <d>` latency is not a `Duration`.",
2616    ),
2617    dg(
2618        "bynk.stub.at_system",
2619        "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.",
2620        &["stub_clause"],
2621    ),
2622    d(
2623        "bynk.stub.bad_sequence",
2624        "A `stub … returns each […]` sequence is malformed (e.g. empty).",
2625    ),
2626    d(
2627        "bynk.stub.generic_op",
2628        "A test `stub` targets a capability operation that declares its own type parameter — not supported at v1.",
2629    ),
2630    d(
2631        "bynk.stub.not_a_seam",
2632        "A test `stub` overrides a capability the unit under test does not consume.",
2633    ),
2634    d(
2635        "bynk.stub.rhs_type",
2636        "A test `stub … returns <value>` right-hand side does not match the operation's return type.",
2637    ),
2638    d(
2639        "bynk.stub.unknown_op",
2640        "A test `stub` names an operation the capability does not declare.",
2641    ),
2642    dg(
2643        "bynk.suite.duplicate_case_name",
2644        "Two `case`s share a description.",
2645        &["case"],
2646    ),
2647    dg(
2648        "bynk.suite.duplicate_env",
2649        "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.",
2650        &["env_clause"],
2651    ),
2652    dg(
2653        "bynk.suite.env_binding_clash",
2654        "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`.",
2655        &["env_clause"],
2656    ),
2657    dg(
2658        "bynk.suite.env_not_literal",
2659        "An `env { … }` entry's value is not a `String` literal; a Worker's variables and secrets are strings, given verbatim.",
2660        &["env_clause"],
2661    ),
2662    dg(
2663        "bynk.suite.unknown_target",
2664        "A `suite` targets a unit that does not exist.",
2665        &["suite_decl"],
2666    ),
2667    d(
2668        "bynk.target.browser_bundle_only",
2669        "The `browser` platform builds only the in-process `Bundle` topology; `--target workers` is not a browser build.",
2670    ),
2671    dg(
2672        "bynk.target.vendor_conflict",
2673        "One deployment unit's in-process closure uses platform-native capabilities from two mutually-exclusive platforms.",
2674        &["consumes_decl"],
2675    ),
2676    dg(
2677        "bynk.target.vendor_required",
2678        "A deployment unit uses a platform-native capability but the build selects another `--platform`.",
2679        &["consumes_decl"],
2680    ),
2681    dg(
2682        "bynk.test.actor_identity_required",
2683        "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`.",
2684        &["case"],
2685    ),
2686    dg(
2687        "bynk.test.actor_no_identity",
2688        "A call-site `by <Actor>(x)` supplies an identity to an actor that takes none — a unit-identity actor (e.g. `Visitor`) or `Nobody`.",
2689        &["case"],
2690    ),
2691    dg(
2692        "bynk.test.advance_not_clock",
2693        "An `advance` statement names a capability other than `Clock`; the test harness owns one time source, the first-party `Clock`.",
2694        &["advance_stmt"],
2695    ),
2696    dg(
2697        "bynk.test.advance_not_duration",
2698        "An `advance Clock by` statement's amount is not a `Duration`.",
2699        &["advance_stmt"],
2700    ),
2701    dg(
2702        "bynk.test.advance_outside_case",
2703        "An `advance Clock by` statement appears outside a test `case` body; only the test harness has a clock to move.",
2704        &["advance_stmt"],
2705    ),
2706    dg(
2707        "bynk.test.asset_address_method",
2708        "A suite fetches an asset with a method other than `GET`; the platform serves assets to `GET` and answers other methods with 405.",
2709        &["case"],
2710    ),
2711    dg(
2712        "bynk.test.call_needs_in_process",
2713        "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`.",
2714        &["case"],
2715    ),
2716    dg(
2717        "bynk.test.credential_needs_system",
2718        "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.",
2719        &["case"],
2720    ),
2721    dg(
2722        "bynk.test.event_needs_in_process",
2723        "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`.",
2724        &["case"],
2725    ),
2726    dg(
2727        "bynk.test.event_not_subscribed",
2728        "A test body's `svc.event(e)` delivers an event the `from Events(E)` service does not subscribe to.",
2729        &["case"],
2730    ),
2731    dg(
2732        "bynk.test.event_publisher_ambiguous",
2733        "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.",
2734        &["case"],
2735    ),
2736    dg(
2737        "bynk.test.faults_needs_in_process",
2738        "A `system`-tier case claims a fault with `expect <call> faults`, or a fault claim at any tier is driven `by Nobody`, `by Forged` or `by Stale`; 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`.",
2739        &["case"],
2740    ),
2741    dg(
2742        "bynk.test.forged_needs_signature_route",
2743        "A case drives `by Forged` or `by Stale` at an address that is not an http route with a `Signature` actor (alone, or as a member of an actor sum); they send a bad signature, so only a `Signature` seam can refuse them.",
2744        &["case"],
2745    ),
2746    dg(
2747        "bynk.test.forged_needs_system",
2748        "A case drives `by Forged` or `by Stale` outside a `system`-tier case; only the `system` driver signs a request, so only there does the real `Signature` seam see the bad signature.",
2749        &["case"],
2750    ),
2751    dg(
2752        "bynk.test.nobody_needs_secured_route",
2753        "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.",
2754        &["case"],
2755    ),
2756    dg(
2757        "bynk.test.oidc_needs_in_process",
2758        "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`.",
2759        &["case"],
2760    ),
2761    d(
2762        "bynk.test.principal_claims_not_oidc",
2763        "A call-site principal passes token claims for an actor that isn't `Oidc`.",
2764    ),
2765    dg(
2766        "bynk.test.principal_identity_mismatch",
2767        "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.",
2768        &["case"],
2769    ),
2770    dg(
2771        "bynk.test.principal_on_asset",
2772        "A suite's asset fetch carries a `by` clause; an asset is public and served before the Worker runs.",
2773        &["case"],
2774    ),
2775    dg(
2776        "bynk.test.principal_on_wrong_method",
2777        "A wrong-method `405` test carries a `by <Actor>` clause; it reaches no handler, so a principal is meaningless.",
2778        &["case"],
2779    ),
2780    dg(
2781        "bynk.test.principal_required",
2782        "A test drives an identity-carrying handler, or one guarded by an actor sum, with no call-site `by <Actor>`.",
2783        &["case"],
2784    ),
2785    warn(dg(
2786        "bynk.test.remote_clock_dependent",
2787        "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.",
2788        &["case"],
2789    )),
2790    dg(
2791        "bynk.test.remote_unsupported_advance",
2792        "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.",
2793        &["case"],
2794    ),
2795    dg(
2796        "bynk.test.remote_unsupported_asset",
2797        "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.",
2798        &["case"],
2799    ),
2800    dg(
2801        "bynk.test.remote_unsupported_call",
2802        "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.",
2803        &["case"],
2804    ),
2805    dg(
2806        "bynk.test.remote_unsupported_env",
2807        "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.",
2808        &["case"],
2809    ),
2810    dg(
2811        "bynk.test.remote_unsupported_queue",
2812        "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.",
2813        &["case"],
2814    ),
2815    dg(
2816        "bynk.test.remote_unsupported_schedule",
2817        "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.",
2818        &["case"],
2819    ),
2820    dg(
2821        "bynk.test.service_bad_address",
2822        "A test body addresses a service the wrong way for its protocol (e.g. an http route without a leading path string).",
2823        &["case"],
2824    ),
2825    dg(
2826        "bynk.test.service_call_arity",
2827        "A test body's `svc.call(...)` passes the wrong number of arguments for the service's `on call` handler.",
2828        &["case"],
2829    ),
2830    dg(
2831        "bynk.test.service_no_call_handler",
2832        "A test body invokes `svc.call(...)` on a service with no `on call` handler (a `from http`/`cron`/`queue` service).",
2833        &["case"],
2834    ),
2835    dg(
2836        "bynk.test.service_unknown_route",
2837        "A test body addresses an http route / cron schedule / queue message the service does not declare.",
2838        &["case"],
2839    ),
2840    warn(dg(
2841        "bynk.test.smoke_undeclared_status",
2842        "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).",
2843        &["case"],
2844    )),
2845    dg(
2846        "bynk.test.stale_needs_timestamp",
2847        "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.",
2848        &["case"],
2849    ),
2850    dg(
2851        "bynk.test.unknown_actor",
2852        "A call-site `by <Actor>` names an actor the target context does not declare and that is not a prelude actor.",
2853        &["case"],
2854    ),
2855    dg(
2856        "bynk.test.wire_needs_system",
2857        "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.",
2858        &["case"],
2859    ),
2860    dg(
2861        "bynk.tier.cross_context_needs_system",
2862        "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`.",
2863        &["case"],
2864    ),
2865    dg(
2866        "bynk.tier.mixed_system_suite",
2867        "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.",
2868        &["case"],
2869    ),
2870    d(
2871        "bynk.tier.system_needs_wire",
2872        "An `as system` test stands up fewer than two contexts; the system tier wires across contexts.",
2873    ),
2874    d(
2875        "bynk.transition.cross_agent_reference",
2876        "A transition predicate references another agent; step invariants are per-agent.",
2877    ),
2878    d(
2879        "bynk.transition.duplicate_name",
2880        "An agent declares two transitions with the same name.",
2881    ),
2882    d(
2883        "bynk.transition.impure_predicate",
2884        "A transition predicate uses an effectful or test-only construct; a step invariant must be pure.",
2885    ),
2886    warn(d(
2887        "bynk.transition.may_violate",
2888        "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.",
2889    )),
2890    d(
2891        "bynk.transition.no_step_reference",
2892        "A transition references neither `old` nor `new`; it constrains one state, so it is an `invariant`, not a step.",
2893    ),
2894    d(
2895        "bynk.transition.not_bool",
2896        "A transition predicate does not have type `Bool`.",
2897    ),
2898    dg(
2899        "bynk.types.argument_mismatch",
2900        "A call, method, capability, or constructor argument has the wrong type.",
2901        &["call"],
2902    ),
2903    d(
2904        "bynk.types.asset_at_boundary",
2905        "An `Asset` type appears in a record field, boundary or store position; pass its `.url` instead.",
2906    ),
2907    d(
2908        "bynk.types.bad_field_default",
2909        "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, `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`.)",
2910    ),
2911    dg(
2912        "bynk.types.call_arity",
2913        "A function value was applied with the wrong number of arguments.",
2914        &["call"],
2915    ),
2916    dg(
2917        "bynk.types.cannot_infer_option_type_param",
2918        "The value type of `None` could not be inferred.",
2919        &["none_expr"],
2920    ),
2921    d(
2922        "bynk.types.cannot_infer_result_type_params",
2923        "The type parameters of a `Result` could not be inferred.",
2924    ),
2925    dg(
2926        "bynk.types.catastrophic_regex",
2927        "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).",
2928        &["refinement"],
2929    ),
2930    d(
2931        "bynk.types.claims_at_boundary",
2932        "`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.",
2933    ),
2934    dg(
2935        "bynk.types.combinator_return_mismatch",
2936        "A callback passed to a combinator (`map`/`andThen`/`flatMap`/`traverseAll`/…) returns the wrong type.",
2937        &["call"],
2938    ),
2939    d(
2940        "bynk.types.constructor_arity",
2941        "A variant constructor got the wrong number of arguments.",
2942    ),
2943    d(
2944        "bynk.types.constructor_base_mismatch",
2945        "A `.of` constructor was given an argument of the wrong base type.",
2946    ),
2947    d(
2948        "bynk.types.decimal_division_unscaled",
2949        "`/` 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).",
2950    ),
2951    d(
2952        "bynk.types.decimal_negation_too_large",
2953        "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).",
2954    ),
2955    dg(
2956        "bynk.types.derives_automatic",
2957        "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).",
2958        &["type_decl"],
2959    ),
2960    dg(
2961        "bynk.types.derives_field_not_orderable",
2962        "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).",
2963        &["type_decl"],
2964    ),
2965    dg(
2966        "bynk.types.duplicate_literal_arm",
2967        "A `match` has two arms for the same literal value.",
2968        &["match_arm"],
2969    ),
2970    dg(
2971        "bynk.types.duplicate_pattern_field",
2972        "A record pattern lists the same field twice.",
2973        &["record_pattern"],
2974    ),
2975    dg(
2976        "bynk.types.duplicate_variant_arm",
2977        "A `match` has two arms for the same variant.",
2978        &["match_arm"],
2979    ),
2980    d(
2981        "bynk.types.embeds_ambiguous",
2982        "A type is embedded by more than one variant of a sum, so `?`'s conversion would be ambiguous.",
2983    ),
2984    d(
2985        "bynk.types.embeds_unknown_variant",
2986        "An `embeds … as V` clause names a variant the sum does not declare.",
2987    ),
2988    d(
2989        "bynk.types.embeds_variant_shape",
2990        "An `embeds E as V` target variant must have exactly one payload field, of type `E`.",
2991    ),
2992    dg(
2993        "bynk.types.empty_range_pattern",
2994        "A range pattern or `via schema(...)` range has its bounds inverted (`lo > hi`), so it can never match.",
2995        &["int_range"],
2996    ),
2997    dg(
2998        "bynk.types.empty_refinement",
2999        "A refinement admits no values (contradictory predicates).",
3000        &["refinement"],
3001    ),
3002    dg(
3003        "bynk.types.err_value_mismatch",
3004        "An `Err` payload has the wrong type.",
3005        &["err_expr"],
3006    ),
3007    d(
3008        "bynk.types.extensible_match_needs_wildcard",
3009        "A `match` covers an extensible standard-library enum (`FetchError`, `Method`) without a wildcard; it may gain variants in a minor release.",
3010    ),
3011    dg(
3012        "bynk.types.field_access_on_non_record",
3013        "Field access on a value that is not a record.",
3014        &["field_access"],
3015    ),
3016    d(
3017        "bynk.types.field_default_on_variant",
3018        "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.",
3019    ),
3020    dg(
3021        "bynk.types.field_refinement_not_base",
3022        "An inline field refinement requires a base or refined type.",
3023        &["record_field"],
3024    ),
3025    dg(
3026        "bynk.types.field_value_mismatch",
3027        "A record field was given a value of the wrong type.",
3028        &["record_construction"],
3029    ),
3030    dg(
3031        "bynk.types.function_at_boundary",
3032        "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.",
3033        &["function_type_ref"],
3034    ),
3035    dg(
3036        "bynk.types.guard_not_bool",
3037        "A match-arm `if` guard is not a `Bool` expression.",
3038        &["match_arm"],
3039    ),
3040    d(
3041        "bynk.types.headers_at_boundary",
3042        "`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.",
3043    ),
3044    d(
3045        "bynk.types.held_at_boundary",
3046        "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).",
3047    ),
3048    d(
3049        "bynk.types.held_not_comparable",
3050        "A held value (`Connection[F]`) is compared with `==`/`!=` — held values have identity, not value-equality (§2.9.3, real-time track slice 2).",
3051    ),
3052    dg(
3053        "bynk.types.if_branch_mismatch",
3054        "The branches of an `if` have different types.",
3055        &["if_expr"],
3056    ),
3057    dg(
3058        "bynk.types.if_non_bool_cond",
3059        "An `if` condition is not a `Bool`.",
3060        &["if_expr"],
3061    ),
3062    dg(
3063        "bynk.types.if_without_else_requires_unit",
3064        "An `if` with no `else` branch has a non-unit then-branch; the missing else defaults to `()`, so the branch must be `()` or `Effect[()]`.",
3065        &["if_expr"],
3066    ),
3067    d(
3068        "bynk.types.interpolation_non_scalar",
3069        "An interpolation hole holds a value with no string form.",
3070    ),
3071    dg(
3072        "bynk.types.invalid_regex",
3073        "A `Matches` predicate, or a regex method's pattern (`containsRegex`, …), contains an invalid regular expression or malformed inline flags.",
3074        &["refinement"],
3075    ),
3076    dg(
3077        "bynk.types.inverted_range",
3078        "An `InRange` predicate has its bounds inverted.",
3079        &["refinement"],
3080    ),
3081    dg(
3082        "bynk.types.is_base_mismatch",
3083        "An `is` refinement check is applied to a value of the wrong base type.",
3084        &["is_expr"],
3085    ),
3086    dg(
3087        "bynk.types.is_literal_pattern",
3088        "A literal was used on the right of `is`; `is` tests type/refinement, not value equality (use `==`).",
3089        &["is_expr"],
3090    ),
3091    dg(
3092        "bynk.types.is_non_sum",
3093        "`is` was applied to a value that is not a sum type.",
3094        &["is_expr"],
3095    ),
3096    dg(
3097        "bynk.types.is_range_pattern",
3098        "A range pattern was used directly on the right of `is`; `is` tests type/refinement, not value ranges (use `match`, a guard or `InRange`).",
3099        &["is_expr"],
3100    ),
3101    dg(
3102        "bynk.types.is_refined_pattern",
3103        "A refined (`where`) pattern was used on the right of `is`; refined patterns are `match`-only.",
3104        &["is_expr"],
3105    ),
3106    dg(
3107        "bynk.types.is_unknown_variant",
3108        "`is` names a variant the type does not have.",
3109        &["is_expr"],
3110    ),
3111    dg(
3112        "bynk.types.json_uncodable",
3113        "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).",
3114        &["method_call"],
3115    ),
3116    d(
3117        "bynk.types.key_at_boundary",
3118        "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).",
3119    ),
3120    dg(
3121        "bynk.types.key_not_orderable",
3122        "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.",
3123        &[],
3124    ),
3125    dg(
3126        "bynk.types.lambda_mismatch",
3127        "A lambda's parameter count, parameter annotations, or body type do not match the expected function type.",
3128        &["lambda_expr"],
3129    ),
3130    dg(
3131        "bynk.types.let_annotation_mismatch",
3132        "A `let` value does not match its type annotation.",
3133        &["let_stmt"],
3134    ),
3135    dg(
3136        "bynk.types.list_element_mismatch",
3137        "A list-literal element has a different type from the list's element type.",
3138        &["list_literal"],
3139    ),
3140    dg(
3141        "bynk.types.list_pattern_on_non_list",
3142        "A list pattern is matched against a value that is not a `List` (a record, sum, base type, `Set` or `Map`).",
3143        &["list_pattern"],
3144    ),
3145    dg(
3146        "bynk.types.match_arm_mismatch",
3147        "A `match` arm has a different type from the others.",
3148        &["match_arm"],
3149    ),
3150    dg(
3151        "bynk.types.match_non_sum_discriminant",
3152        "`match` was applied to a value that is not a sum type.",
3153        &["match_expr"],
3154    ),
3155    dg(
3156        "bynk.types.method_arity",
3157        "A method was called with the wrong number of arguments.",
3158        &["method_call"],
3159    ),
3160    dg(
3161        "bynk.types.method_not_found",
3162        "Called a method the type does not have.",
3163        &["method_call"],
3164    ),
3165    dg(
3166        "bynk.types.method_on_non_named_type",
3167        "A method was called on a built-in type that has no methods.",
3168        &["method_call"],
3169    ),
3170    dg(
3171        "bynk.types.mixed_pattern_bindings",
3172        "A pattern mixes named and positional bindings.",
3173        &["variant_pattern"],
3174    ),
3175    dg(
3176        "bynk.types.negative_length",
3177        "A length predicate was given a negative value.",
3178        &["refinement"],
3179    ),
3180    dg(
3181        "bynk.types.never_inferred",
3182        "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.",
3183        &["let_stmt"],
3184    ),
3185    dg(
3186        "bynk.types.no_numeric_coercion",
3187        "`Int`, `Float` and `Decimal` were mixed without an explicit conversion — in an operation, a comparison or refinement bounds.",
3188        &["binary_expr", "refinement"],
3189    ),
3190    dg(
3191        "bynk.types.non_exhaustive_match",
3192        "A `match` does not cover every value.",
3193        &["match_expr"],
3194    ),
3195    d(
3196        "bynk.types.not_codable",
3197        "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).",
3198    ),
3199    d(
3200        "bynk.types.not_comparable",
3201        "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).",
3202    ),
3203    dg(
3204        "bynk.types.not_keyable",
3205        "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).",
3206        &["generic_type_ref"],
3207    ),
3208    d(
3209        "bynk.types.not_orderable",
3210        "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).",
3211    ),
3212    dg(
3213        "bynk.types.ok_value_mismatch",
3214        "An `Ok` payload has the wrong type.",
3215        &["ok_expr"],
3216    ),
3217    dg(
3218        "bynk.types.opaque_raw_outside",
3219        "`.raw` on an opaque type was used outside its defining commons.",
3220        &["field_access"],
3221    ),
3222    dg(
3223        "bynk.types.opaque_unsafe_outside",
3224        "`.unsafe` on an opaque type was used outside its defining context.",
3225        &["field_access"],
3226    ),
3227    dg(
3228        "bynk.types.or_pattern_binding_mismatch",
3229        "An or-pattern's alternatives don't all bind the same set of names.",
3230        &["match_arm", "is_expr"],
3231    ),
3232    dg(
3233        "bynk.types.or_pattern_type_mismatch",
3234        "An or-pattern's alternatives give a shared binding different types (or refinements).",
3235        &["match_arm", "is_expr"],
3236    ),
3237    dg(
3238        "bynk.types.pattern_arity",
3239        "A pattern binds the wrong number of payload fields.",
3240        &["variant_pattern"],
3241    ),
3242    dg(
3243        "bynk.types.pattern_type_mismatch",
3244        "A pattern's type does not match the matched value.",
3245        &["variant_pattern"],
3246    ),
3247    dg(
3248        "bynk.types.polynomial_regex",
3249        "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.",
3250        &["refinement"],
3251    ),
3252    warn(dg(
3253        "bynk.types.polynomial_regex_capped",
3254        "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).",
3255        &["refinement"],
3256    )),
3257    dg(
3258        "bynk.types.predicate_base_mismatch",
3259        "A predicate does not apply to the type's base (e.g. a string predicate on an `Int`).",
3260        &["refinement"],
3261    ),
3262    d(
3263        "bynk.types.query_at_boundary",
3264        "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).",
3265    ),
3266    dg(
3267        "bynk.types.question_error_mismatch",
3268        "`?` propagates an error type incompatible with the function's.",
3269        &["question_expr"],
3270    ),
3271    dg(
3272        "bynk.types.question_on_non_result",
3273        "`?` was applied to a non-`Result` value.",
3274        &["question_expr"],
3275    ),
3276    dg(
3277        "bynk.types.question_option_outside_http",
3278        "`?` lifts an `Option` only inside a handler returning `HttpResult` (`None` becomes `NotFound`); elsewhere use `.okOr(err)`.",
3279        &["question_expr"],
3280    ),
3281    dg(
3282        "bynk.types.question_outside_result",
3283        "`?` used in a function that does not return a `Result`.",
3284        &["question_expr"],
3285    ),
3286    dg(
3287        "bynk.types.range_pattern_on_non_int",
3288        "A range pattern (`lo..hi`) was matched against a scrutinee that is not an `Int`.",
3289        &["int_range"],
3290    ),
3291    dg(
3292        "bynk.types.record_pattern_on_non_record",
3293        "A record pattern names a type that is not a record (a sum, enum, refined or opaque type, or a built-in).",
3294        &["record_pattern"],
3295    ),
3296    dg(
3297        "bynk.types.regex_not_literal",
3298        "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.",
3299        &["method_call"],
3300    ),
3301    d(
3302        "bynk.types.rejection_at_boundary",
3303        "`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.",
3304    ),
3305    d(
3306        "bynk.types.return_mismatch",
3307        "A returned value does not match the declared return type.",
3308    ),
3309    d(
3310        "bynk.types.rounding_mode_position",
3311        "`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).",
3312    ),
3313    dg(
3314        "bynk.types.sequence_needs_result",
3315        "`sequenceAll`/`sequenceTry` was called on a list whose elements are not `Result`s. They collect a `List[Result[T, E]]`.",
3316        &["method_call"],
3317    ),
3318    dg(
3319        "bynk.types.some_value_mismatch",
3320        "A `Some` payload has the wrong type.",
3321        &["some_expr"],
3322    ),
3323    dg(
3324        "bynk.types.sql_not_literal",
3325        "A `D1` statement's SQL (the first argument of `all`, `first` or `run`, 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).",
3326        &["method_call", "record_construction", "record_spread"],
3327    ),
3328    dg(
3329        "bynk.types.sql_row_shape",
3330        "`Json.decodeSql[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).",
3331        &["method_call"],
3332    ),
3333    d(
3334        "bynk.types.sql_statement_at_boundary",
3335        "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).",
3336    ),
3337    d(
3338        "bynk.types.stream_at_boundary",
3339        "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).",
3340    ),
3341    d(
3342        "bynk.types.stream_not_comparable",
3343        "A `Stream` value is compared with `==`/`!=` — a stream is a live value-over-time source, not a comparable value (real-time track slice 0).",
3344    ),
3345    d(
3346        "bynk.types.type_mismatch",
3347        "Two types that were required to match did not.",
3348    ),
3349    dg(
3350        "bynk.types.uninferable_element_type",
3351        "An empty `[]` (or `List.empty()` / `Map.empty()`) has no expected type to infer its element type from.",
3352        &["list_literal"],
3353    ),
3354    dg(
3355        "bynk.types.unknown_field",
3356        "Referenced a field the record type does not declare.",
3357        &["field_access"],
3358    ),
3359    dg(
3360        "bynk.types.unknown_pattern_field",
3361        "A pattern names a field the variant does not have.",
3362        &["variant_pattern"],
3363    ),
3364    d(
3365        "bynk.types.unknown_rounding_mode",
3366        "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).",
3367    ),
3368    dg(
3369        "bynk.types.unknown_static_member",
3370        "Referenced an unknown static member on a type.",
3371        &["field_access"],
3372    ),
3373    dg(
3374        "bynk.types.unknown_variant_in_pattern",
3375        "A pattern names a variant the sum type does not have.",
3376        &["variant_pattern"],
3377    ),
3378    dg(
3379        "bynk.types.unreachable_arm",
3380        "A `match` arm is unreachable.",
3381        &["match_arm"],
3382    ),
3383    d(
3384        "bynk.types.variant_arity",
3385        "A variant constructor got the wrong number of payload values.",
3386    ),
3387    d(
3388        "bynk.types.variant_missing_payload",
3389        "A variant requiring a payload was used without one.",
3390    ),
3391    d(
3392        "bynk.types.variant_payload_mismatch",
3393        "A variant payload has the wrong type.",
3394    ),
3395    dg(
3396        "bynk.uses.name_conflict",
3397        "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.",
3398        &["uses_decl"],
3399    ),
3400    dg(
3401        "bynk.uses.self_reference",
3402        "A commons `uses` itself.",
3403        &["uses_decl"],
3404    ),
3405    dg(
3406        "bynk.uses.target_is_context",
3407        "`uses` targets a context instead of a commons.",
3408        &["uses_decl"],
3409    ),
3410    dg(
3411        "bynk.uses.unknown_commons",
3412        "`uses` names a commons that does not exist.",
3413        &["uses_decl"],
3414    ),
3415    dg(
3416        "bynk.val.agent_not_generable",
3417        "A `for all`/`Val` cannot generate an agent — fabricated agent states need not be reachable.",
3418        &["for_all"],
3419    ),
3420    dg(
3421        "bynk.val.arity",
3422        "`Val[T]` was given the wrong number of pin arguments.",
3423        &["val_expr"],
3424    ),
3425    dg(
3426        "bynk.val.literal_violates",
3427        "A pinned `Val[T]` value violates the type's refinement.",
3428        &["val_expr"],
3429    ),
3430    dg(
3431        "bynk.val.needs_pin",
3432        "A bare `Val[T]` cannot generate a value (e.g. a `Matches` string); pin one.",
3433        &["val_expr"],
3434    ),
3435    dg(
3436        "bynk.val.outside_test",
3437        "`Val[T]` was used outside a test case body.",
3438        &["val_expr"],
3439    ),
3440    dg(
3441        "bynk.val.pin_not_literal",
3442        "A `Val[T]` pin argument is not a compile-time literal.",
3443        &["val_expr"],
3444    ),
3445    dg(
3446        "bynk.val.pin_unsupported",
3447        "A pin was given for a type kind that does not support pinning.",
3448        &["val_expr"],
3449    ),
3450    dg(
3451        "bynk.val.unknown_type",
3452        "`Val[T]` names a type that does not resolve.",
3453        &["val_expr"],
3454    ),
3455    dg(
3456        "bynk.val.unsupported_kind",
3457        "`Val[T]` cannot fabricate a value for this kind of type.",
3458        &["val_expr"],
3459    ),
3460    dg(
3461        "bynk.visibility.private_in_public",
3462        "A public declaration's signature names a `private` type of its own unit, which an importer could neither name nor build.",
3463        &["visibility_modifier"],
3464    ),
3465    dg(
3466        "bynk.visibility.private_item",
3467        "A reference from another unit names a `private` declaration, which is visible only within its own unit and that unit's suites.",
3468        &["visibility_modifier"],
3469    ),
3470    warn(dg(
3471        "bynk.visibility.private_messages",
3472        "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).",
3473        &["visibility_modifier"],
3474    )),
3475    dg(
3476        "bynk.visibility.private_not_allowed",
3477        "`private` modifies a declaration it does not apply to: anything but a `fn`, `type`, `messages`, `asset`, `embed` or `const` in a commons or context.",
3478        &["visibility_modifier"],
3479    ),
3480    d(
3481        "bynk.wasm.panic",
3482        "The in-browser compiler panicked internally (a compiler bug, reported as a diagnostic instead of crashing the page).",
3483    ),
3484    d(
3485        "bynk.wasm.strip_failed",
3486        "The in-browser compiler could not strip the emitted TypeScript to JavaScript.",
3487    ),
3488    dg(
3489        "bynk.within.in_agent_handler",
3490        "`e.within(d)` was used in an agent handler, which has no execution context to hand the abandoned effect to.",
3491        &["method_call"],
3492    ),
3493    dg(
3494        "bynk.within.in_pure_context",
3495        "`e.within(d)` was used in a pure (non-effectful) context.",
3496        &["method_call"],
3497    ),
3498    dg(
3499        "bynk.within.outside_handler",
3500        "`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.",
3501        &["method_call"],
3502    ),
3503    dg(
3504        "bynk.within.timed_out_not_in_scope",
3505        "`e.within(d)` yields `Result[_, TimedOut]`, but the unit does not consume `bynk`, so `TimedOut` is not in scope.",
3506        &["method_call"],
3507    ),
3508    d(
3509        "bynk.ws.message_frame_param",
3510        "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).",
3511    ),
3512    d(
3513        "bynk.ws.open_given_unsupported",
3514        "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).",
3515    ),
3516    d(
3517        "bynk.ws.open_transfer_cross_file",
3518        "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.",
3519    ),
3520    d(
3521        "bynk.ws.open_transfer_shape",
3522        "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).",
3523    ),
3524    d(
3525        "bynk.ws.route_param_mismatch",
3526        "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).",
3527    ),
3528];
3529
3530/// A diagnostic with no single governing grammar construct. `Error` severity.
3531const fn d(code: &'static str, summary: &'static str) -> DiagnosticInfo {
3532    DiagnosticInfo {
3533        code,
3534        summary,
3535        grammar_symbol: &[],
3536        severity: Severity::Error,
3537    }
3538}
3539
3540/// A diagnostic that constrains one or more grammar productions. `Error` severity.
3541const fn dg(
3542    code: &'static str,
3543    summary: &'static str,
3544    grammar_symbol: &'static [&'static str],
3545) -> DiagnosticInfo {
3546    DiagnosticInfo {
3547        code,
3548        summary,
3549        grammar_symbol,
3550        severity: Severity::Error,
3551    }
3552}
3553
3554/// Downgrades a [`d`]/[`dg`]-built entry to `Warning` severity (ADR 0117) —
3555/// non-failing, surfaced alongside a clean build. Its call sites here are
3556/// the single source of truth [`crate::error::Severity::for_error`] reads.
3557const fn warn(mut info: DiagnosticInfo) -> DiagnosticInfo {
3558    info.severity = Severity::Warning;
3559    info
3560}
3561
3562/// The category segment of a code (the part between the first two dots), e.g.
3563/// `"types"` for `"bynk.types.type_mismatch"`.
3564pub fn category(code: &str) -> &str {
3565    code.split('.').nth(1).unwrap_or("")
3566}
3567
3568/// A human-readable heading for a category segment.
3569fn category_title(cat: &str) -> &'static str {
3570    match cat {
3571        "agent" | "agents" => "Agents",
3572        "asset" => "Static assets",
3573        "boundary" => "Boundaries",
3574        "capability" => "Capabilities",
3575        "cloudflare" => "Cloudflare",
3576        "consumes" => "Consumes",
3577        "context" => "Contexts",
3578        "contract" => "Contracts",
3579        "cron" => "Cron",
3580        "doc" => "Doc comments",
3581        "effect" => "Effects",
3582        "embed" => "Embedded text",
3583        "expect" => "Expectations",
3584        "exports" => "Exports",
3585        "given" => "Given capabilities",
3586        "http" => "HTTP",
3587        "lex" => "Lexer",
3588        "messages" => "Message bundles",
3589        "mock" => "Mocks (collaborators)",
3590        "observe" => "Observation",
3591        "parse" => "Parser",
3592        "project" => "Project",
3593        "property" => "Properties (generative tests)",
3594        "provider" => "Providers",
3595        "queue" => "Queue",
3596        "record_spread" => "Record spread",
3597        "refine" => "Refinement",
3598        "resolve" => "Resolution",
3599        "service" => "Services",
3600        "stability" => "Stability",
3601        "suite" => "Suites and cases",
3602        "transition" => "Transitions (step invariants)",
3603        "types" => "Type checking",
3604        "uses" => "Uses",
3605        "val" => "Value fabrication",
3606        _ => "Other",
3607    }
3608}
3609
3610/// Render the diagnostic index as a Markdown reference page, grouped by
3611/// category. This is the generator behind
3612/// `site/src/content/docs/book/reference/diagnostics.md`.
3613pub fn render_markdown() -> String {
3614    use std::collections::BTreeMap;
3615
3616    // Group codes by their category title, preserving sorted code order.
3617    let mut by_category: BTreeMap<&str, Vec<&DiagnosticInfo>> = BTreeMap::new();
3618    for info in REGISTRY {
3619        by_category
3620            .entry(category_title(category(info.code)))
3621            .or_default()
3622            .push(info);
3623    }
3624
3625    let mut out = String::new();
3626    out.push_str("# Diagnostic index\n\n");
3627    out.push_str(
3628        "<!-- GENERATED FILE — do not edit by hand.\n     \
3629         Source: bynkc/src/diagnostics.rs (`render_markdown`).\n     \
3630         Regenerate with: BYNK_BLESS=1 cargo test -p bynkc --test it diagnostics_registry:: -->\n\n",
3631    );
3632    out.push_str(
3633        "Every diagnostic code the compiler can emit, with a one-line summary of \
3634         the cause, grouped by category. For step-by-step cause-and-fix guidance \
3635         on the most common ones, see the [troubleshooting guides](../troubleshooting/index.md). \
3636         For a code with a curated explanation, `bynk explain <code>` prints it in a \
3637         terminal, and in VS Code the diagnostic's **Explain** quick fix (or \
3638         **Bynk: Explain Diagnostic Code…**) shows the same text in a panel, offline.\n\n",
3639    );
3640    out.push_str(&format!(
3641        "There are **{}** codes in total.\n",
3642        REGISTRY.len()
3643    ));
3644
3645    for (title, infos) in &by_category {
3646        out.push_str(&format!("\n## {title}\n\n"));
3647        out.push_str("| Code | Summary | Construct | Severity |\n|---|---|---|---|\n");
3648        for info in infos {
3649            // The construct column deep-links each governing production to its
3650            // entry in the annotated grammar reference; generated from
3651            // `grammar_symbol` (each value is an embeddable rule, so the
3652            // `#rule-<raw>` anchor resolves — enforced in diagnostics_registry).
3653            let construct = info
3654                .grammar_symbol
3655                .iter()
3656                .map(|sym| format!("[`{sym}`](grammar.md#rule-{sym})"))
3657                .collect::<Vec<_>>()
3658                .join(", ");
3659            // A curated (`bynk explain`-able) code links to its Book concept
3660            // page; the in-site link is validated by the site's link checker,
3661            // so a moved page or renamed anchor fails the build (#853). Codes
3662            // without an explanation render as plain inline code.
3663            let code_cell = match explain(info.code) {
3664                Some(e) => format!("[`{}`]({})", info.code, e.in_site_link()),
3665                None => format!("`{}`", info.code),
3666            };
3667            // ADR 0117/finding #50: every code's severity, straight from the
3668            // registry — `Error` (the overwhelming majority) renders as "—"
3669            // to keep the common case unobtrusive; only a `warn`-built entry
3670            // shows "Warning".
3671            let severity = match info.severity {
3672                Severity::Error => "—",
3673                Severity::Warning => "Warning",
3674            };
3675            out.push_str(&format!(
3676                "| {} | {} | {} | {} |\n",
3677                code_cell, info.summary, construct, severity
3678            ));
3679        }
3680    }
3681
3682    out
3683}
3684
3685/// Invert the registry into a `{ "<rule>": [ { code, summary }, … ], … }` map,
3686/// serialised as pretty JSON with sorted keys and sorted codes. Only rules with
3687/// at least one diagnostic appear. This is the generator behind
3688/// `docs/grammar-semantics.json`, which the `{{#grammar-semantics <rule>}}`
3689/// preprocessor directive consumes.
3690pub fn render_grammar_semantics_json() -> String {
3691    use std::collections::BTreeMap;
3692
3693    // REGISTRY is sorted by code, so each rule's vector comes out code-sorted;
3694    // the BTreeMap gives sorted rule names.
3695    let mut by_symbol: BTreeMap<&str, Vec<&DiagnosticInfo>> = BTreeMap::new();
3696    for info in REGISTRY {
3697        for sym in info.grammar_symbol {
3698            by_symbol.entry(sym).or_default().push(info);
3699        }
3700    }
3701
3702    let mut map = serde_json::Map::new();
3703    map.insert(
3704        "_generated".to_string(),
3705        serde_json::Value::String(
3706            "Generated from the grammar_symbol field of bynkc/src/diagnostics.rs. \
3707             Do not edit by hand. Regenerate with: BYNK_BLESS=1 cargo test -p \
3708             bynkc --test it diagnostics_registry::"
3709                .to_string(),
3710        ),
3711    );
3712    for (sym, infos) in by_symbol {
3713        let arr: Vec<serde_json::Value> = infos
3714            .iter()
3715            .map(|info| serde_json::json!({ "code": info.code, "summary": info.summary }))
3716            .collect();
3717        map.insert(sym.to_string(), serde_json::Value::Array(arr));
3718    }
3719
3720    let mut s =
3721        serde_json::to_string_pretty(&serde_json::Value::Object(map)).expect("serialise semantics");
3722    s.push('\n');
3723    s
3724}