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.resolve.missing_field",
143        blurb: "A record must be constructed with every one of its fields. Bynk \
144                records have no defaults and no partial construction: a value of a \
145                record type is only valid once all its fields are present, so a \
146                downstream reader never has to wonder whether a field was set. \
147                Omitting a field is therefore an error, not a fill-in-later.",
148        example: "type User = { name: Text, age: Int }\n\n\
149                  User { name: \"Ada\" }            // ✗ missing `age`\n\
150                  User { name: \"Ada\", age: 36 }   // ✓ every field present",
151        page: "/book/reference/types",
152        anchor: "record-types",
153    },
154    Explain {
155        code: "bynk.resolve.unknown_field",
156        blurb: "A field access names a field the record type does not have. A \
157                record's fields are fixed by its type declaration; only those \
158                names exist on the value. This is usually a typo in the field \
159                name, or an access meant for a different type.",
160        example: "type User = { name: Text }\n\n\
161                  user.nmae   // ✗ no field `nmae`\n\
162                  user.name   // ✓ the declared field",
163        page: "/book/reference/types",
164        anchor: "record-types",
165    },
166    Explain {
167        code: "bynk.resolve.unknown_name",
168        blurb: "A name was referenced that is not in scope. Every name in Bynk \
169                must be introduced before use — as a `let` binding, a parameter, \
170                a `fn`, a type, or a member brought in through `uses`/`consumes`. \
171                An unknown name is typically a typo, a missing declaration, or a \
172                reference to something defined in a module that has not been \
173                brought into scope.",
174        example: "let greeting = \"hi\"\n\
175                  greetng          // ✗ no name `greetng` in scope\n\
176                  greeting         // ✓ the bound name",
177        page: "/book/guides/program-structure/how-a-program-is-shaped",
178        anchor: "",
179    },
180    Explain {
181        code: "bynk.resolve.unknown_type",
182        blurb: "A type name was referenced that does not exist. Types must be \
183                declared (with `type`), be one of Bynk's built-in types, or be \
184                brought into scope from another module before they can be named. \
185                An unknown type is usually a typo or a missing declaration/import.",
186        example: "fn greet(u: Usr) -> Text { … }   // ✗ no type `Usr`\n\
187                  fn greet(u: User) -> Text { … }  // ✓ the declared type",
188        page: "/book/reference/types",
189        anchor: "",
190    },
191];
192
193/// The curated explanation for a diagnostic `code`, or `None` when the code has
194/// no explanation yet (the designed graceful-fallback state, DECISION B).
195pub fn explain(code: &str) -> Option<&'static Explain> {
196    EXPLANATIONS.iter().find(|e| e.code == code)
197}
198
199/// Look up a code's registry entry by exact match — the one place
200/// [`crate::error::Severity::for_error`] reads a code's severity, instead of
201/// hardcoding its own copy of the (small) warning set.
202pub fn lookup(code: &str) -> Option<&'static DiagnosticInfo> {
203    REGISTRY.iter().find(|d| d.code == code)
204}
205
206/// Every diagnostic code the compiler emits, sorted by code.
207pub const REGISTRY: &[DiagnosticInfo] = &[
208    d(
209        "bynk.actor.bearer_identity_not_string_constructible",
210        "A `Bearer` actor's identity is not a string-constructible type.",
211    ),
212    d(
213        "bynk.actor.bearer_missing_secret",
214        "A `Bearer` actor does not name its signing secret.",
215    ),
216    d(
217        "bynk.actor.binder_shadows_param",
218        "A `by` actor binder collides with a handler parameter of the same name.",
219    ),
220    d(
221        "bynk.actor.by_on_agent",
222        "A `by` actor clause was placed on an agent `on call` handler, which has no actor.",
223    ),
224    d(
225        "bynk.actor.duplicate_sum_scheme",
226        "Two peers in a multi-actor sum share an authentication scheme.",
227    ),
228    d(
229        "bynk.actor.foreign_context_name_unkeyable",
230        "A context declaring a `Foreign` actor has a name no call key can be named from.",
231    ),
232    d(
233        "bynk.actor.foreign_duplicate_secret",
234        "A `Foreign` actor's secret is also another actor's secret in the same context.",
235    ),
236    d(
237        "bynk.actor.foreign_identity_unsupported",
238        "A `Foreign` actor declares an `identity`.",
239    ),
240    d(
241        "bynk.actor.foreign_missing_secret",
242        "A `Foreign` actor does not name the secret its calls are signed with.",
243    ),
244    d(
245        "bynk.actor.foreign_name_is_context_name",
246        "A `Foreign` actor's name could be read as a context's name.",
247    ),
248    d(
249        "bynk.actor.foreign_reserved_secret",
250        "A `Foreign` actor's secret uses a `BYNK_CALL_` edge key's name.",
251    ),
252    d(
253        "bynk.actor.foreign_secret_not_string",
254        "A `Foreign` actor's secret is not a string.",
255    ),
256    d(
257        "bynk.actor.identity_not_sealed",
258        "An actor identity type is not a context-ownable (sealed) value type.",
259    ),
260    d(
261        "bynk.actor.missing_by_on_http",
262        "An HTTP handler lacks the required `by` actor clause.",
263    ),
264    d(
265        "bynk.actor.oidc_identity_not_string_constructible",
266        "An `Oidc` actor's identity is not a string-constructible type.",
267    ),
268    d(
269        "bynk.actor.oidc_missing_audience",
270        "An `Oidc` actor does not name its `audience`.",
271    ),
272    d(
273        "bynk.actor.oidc_missing_issuer",
274        "An `Oidc` actor does not name its `issuer`.",
275    ),
276    d(
277        "bynk.actor.oidc_missing_jwks",
278        "An `Oidc` actor does not name its `jwks` endpoint.",
279    ),
280    d(
281        "bynk.actor.oidc_not_in_sum",
282        "An `Oidc` actor appears as a member of a multi-actor sum.",
283    ),
284    d(
285        "bynk.actor.outside_context",
286        "An `actor` was declared outside a context (e.g. in a commons).",
287    ),
288    d(
289        "bynk.actor.refinement_base_unsupported",
290        "A refinement actor's base is not a `Bearer` actor (no claims to authorise against).",
291    ),
292    d(
293        "bynk.actor.refinement_in_sum",
294        "A refinement actor appears as a member of a multi-actor sum.",
295    ),
296    d(
297        "bynk.actor.refinement_predicate_unsupported",
298        "A refinement actor's `where` predicate is outside the closed claim-predicate set.",
299    ),
300    d(
301        "bynk.actor.scheme_not_admissible",
302        "An actor's scheme is not admissible on this handler's protocol.",
303    ),
304    d(
305        "bynk.actor.signature_identity_unsupported",
306        "A `Signature` actor declared an `identity`, which is not yet supported.",
307    ),
308    d(
309        "bynk.actor.signature_missing_header",
310        "A `Signature` actor does not name its signature header.",
311    ),
312    d(
313        "bynk.actor.signature_missing_secret",
314        "A `Signature` actor does not name its signing secret.",
315    ),
316    d(
317        "bynk.actor.signature_requires_body",
318        "A `Signature` handler does not take a `body` parameter.",
319    ),
320    d(
321        "bynk.actor.signature_tolerance_without_timestamp",
322        "A `Signature` actor set `tolerance` without a `timestamp` header.",
323    ),
324    d(
325        "bynk.actor.sum_requires_binder",
326        "A multi-actor sum `by` clause has no binder to match the resolved actor.",
327    ),
328    d(
329        "bynk.actor.unknown_actor",
330        "A handler's `by` clause names an actor that is not declared.",
331    ),
332    d(
333        "bynk.actor.unknown_scheme",
334        "An actor declares an authentication scheme that is not compiler-known.",
335    ),
336    d(
337        "bynk.actor.unreachable_sum_arm",
338        "A multi-actor sum has an arm unreachable after a catch-all (`None`) peer.",
339    ),
340    dg(
341        "bynk.adapter.consumes_context",
342        "An `adapter` consumed a context; adapter dependencies are adapter-to-adapter.",
343        &["consumes_decl"],
344    ),
345    dg(
346        "bynk.adapter.consumes_requires_selection",
347        "An `adapter` used a whole-unit or aliased `consumes`; adapters must select capabilities with `consumes U { Cap, … }`.",
348        &["consumes_decl"],
349    ),
350    dg(
351        "bynk.adapter.disallowed_item",
352        "An `adapter` declared a `service`, `agent`, or other item it may not contain.",
353        &["adapter_decl"],
354    ),
355    dg(
356        "bynk.adapter.duplicate_binding",
357        "An `adapter` declared more than one `binding` clause.",
358        &["binding_decl"],
359    ),
360    dg(
361        "bynk.adapter.no_binding",
362        "An `adapter` declares an external provider but no `binding` module to supply it.",
363        &["adapter_decl"],
364    ),
365    dg(
366        "bynk.adapter.provider_has_body",
367        "A provider inside an `adapter` has a Bynk body; adapter providers must be external.",
368        &["provider_decl"],
369    ),
370    d(
371        "bynk.agent.class_removed",
372        "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.",
373    ),
374    dg(
375        "bynk.agent.construction_arity",
376        "An agent was constructed with the wrong number of key arguments.",
377        &["agent_decl"],
378    ),
379    dg(
380        "bynk.agent.handler_arity",
381        "An agent handler was called with the wrong number of arguments.",
382        &["agent_decl"],
383    ),
384    dg(
385        "bynk.agent.handler_not_found",
386        "Called a handler the agent does not declare.",
387        &["agent_decl"],
388    ),
389    dg(
390        "bynk.agent.key_mismatch",
391        "An agent key argument has the wrong type.",
392        &["agent_decl"],
393    ),
394    d(
395        "bynk.agent.non_additive_state_change",
396        "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.",
397    ),
398    dg(
399        "bynk.agent.outside_context",
400        "An `agent` was declared outside a context.",
401        &["agent_decl"],
402    ),
403    warn(d(
404        "bynk.agent.refinement_changed",
405        "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).",
406    )),
407    dg(
408        "bynk.agent.return_not_effect",
409        "An agent handler's return type is not an `Effect`.",
410        &["agent_decl"],
411    ),
412    d(
413        "bynk.agent.state_name_conflict",
414        "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.",
415    ),
416    dg(
417        "bynk.agents.bad_state_initialiser",
418        "An agent `store` field initialiser is not a static value of the field's type.",
419        &["store_field"],
420    ),
421    dg(
422        "bynk.agents.non_zeroable_state_field",
423        "An agent `store` field has no initialiser and no implicit zero value.",
424        &["store_field"],
425    ),
426    d(
427        "bynk.asset.duplicate",
428        "An `asset` name is declared more than once in the same unit.",
429    ),
430    d(
431        "bynk.asset.invalid_at_path",
432        "An `asset`'s `at` path is not a URL path naming one file, or lies under `/_assets/` or `/_bynk/`.",
433    ),
434    warn(d(
435        "bynk.asset.may_shadow_route",
436        "A parameterised HTTP route matches a fixed asset path, so it never sees requests for that path (a warning).",
437    )),
438    d(
439        "bynk.asset.missing_file",
440        "An `asset` names a file that is not in the project's `assets/` folder.",
441    ),
442    d(
443        "bynk.asset.needs_project",
444        "A single-file build met an `asset` declaration; assets need a project build.",
445    ),
446    warn(d(
447        "bynk.asset.not_served",
448        "A deployable Bundle build met an `asset`; a Bundle ships no files, so its `.url` would not be served (a warning).",
449    )),
450    d(
451        "bynk.asset.outside_assets_dir",
452        "An `asset` path does not name a file in the project's `assets/` folder.",
453    ),
454    d(
455        "bynk.asset.outside_context_or_commons",
456        "An `asset` declaration appears outside a context or commons.",
457    ),
458    d(
459        "bynk.asset.path_conflict",
460        "Two different asset files would be served at one fixed path by the same Worker.",
461    ),
462    d(
463        "bynk.asset.shadows_route",
464        "A fixed asset path equals a literal HTTP route, which the platform-served asset makes unreachable.",
465    ),
466    d(
467        "bynk.asset.unreadable_file",
468        "An `asset` names a file in the project's `assets/` folder that could not be read.",
469    ),
470    d(
471        "bynk.asset.unsafe_path",
472        "An `asset` path is empty, absolute, or contains a `..` segment.",
473    ),
474    d(
475        "bynk.boundary.ambiguous_type",
476        "A value's type is declared, with different shapes, by more than one consumed context, so its fields cannot be read.",
477    ),
478    d(
479        "bynk.boundary.structural_mismatch",
480        "Data crossing a context boundary did not match the expected shape.",
481    ),
482    dg(
483        "bynk.capability.base_not_instantiable",
484        "A derived capability's base is not a platform resource that can be instantiated.",
485        &["capability_decl"],
486    ),
487    dg(
488        "bynk.capability.derived_outside_context",
489        "A derived capability was declared outside a context.",
490        &["capability_decl"],
491    ),
492    dg(
493        "bynk.capability.instance_only",
494        "A platform capability that is used only through named instances (`Service`) was used bare, in a `given` clause.",
495        &["given_clause"],
496    ),
497    dg(
498        "bynk.capability.invalid_option",
499        "A derived capability's option is not one string literal, is given twice, or (`@worker`) is not a Worker name outside the project.",
500        &["capability_decl"],
501    ),
502    dg(
503        "bynk.capability.missing_option",
504        "A derived capability lacks an option its base requires, such as a `Service` instance's `@worker`.",
505        &["capability_decl"],
506    ),
507    dg(
508        "bynk.capability.not_provided",
509        "On the Workers target, a capability a context requires has no provider in it.",
510        &["given_clause"],
511    ),
512    dg(
513        "bynk.capability.op_arity",
514        "A capability operation was called with the wrong number of arguments.",
515        &["capability_decl"],
516    ),
517    dg(
518        "bynk.capability.outside_context",
519        "A `capability` was declared outside a context.",
520        &["capability_decl"],
521    ),
522    dg(
523        "bynk.capability.unknown_base",
524        "A derived capability's base is not a capability the context consumes.",
525        &["capability_decl"],
526    ),
527    dg(
528        "bynk.capability.unknown_operation",
529        "Referenced an operation the capability does not declare.",
530        &["capability_decl"],
531    ),
532    dg(
533        "bynk.capability.unknown_option",
534        "A derived capability carries an option its base does not take.",
535        &["capability_decl"],
536    ),
537    d(
538        "bynk.cell.invalid_target",
539        "A `:=` write targets something that is not a `store Cell` field.",
540    ),
541    d(
542        "bynk.cell.self_reference",
543        "A `:=` right-hand side reads the cell being written (a read-modify-write); use `.update`.",
544    ),
545    dg(
546        "bynk.consumes.alias_conflict",
547        "Two `consumes` aliases collide.",
548        &["consumes_decl"],
549    ),
550    dg(
551        "bynk.consumes.capability_name_clash",
552        "Two flattened `consumes U { Cap }` capabilities collide, or one clashes with a local capability.",
553        &["consumes_decl"],
554    ),
555    dg(
556        "bynk.consumes.name_conflict",
557        "A `consumes` name collides with another name in scope.",
558        &["consumes_decl"],
559    ),
560    dg(
561        "bynk.consumes.self_reference",
562        "A context `consumes` itself.",
563        &["consumes_decl"],
564    ),
565    dg(
566        "bynk.consumes.service_arity",
567        "A consumed service was called with the wrong number of arguments.",
568        &["consumes_decl"],
569    ),
570    dg(
571        "bynk.consumes.signature_type_unconsumed",
572        "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.",
573        &["consumes_decl"],
574    ),
575    dg(
576        "bynk.consumes.target_is_commons",
577        "`consumes` targets a `commons` instead of a context.",
578        &["consumes_decl"],
579    ),
580    dg(
581        "bynk.consumes.unknown_context",
582        "`consumes` names a context that does not exist.",
583        &["consumes_decl"],
584    ),
585    dg(
586        "bynk.consumes.unknown_service",
587        "Called a service the consumed context does not declare.",
588        &["consumes_decl"],
589    ),
590    d(
591        "bynk.context.consumes_cycle",
592        "Contexts form a `consumes` dependency cycle.",
593    ),
594    d(
595        "bynk.context.duplicate_binding",
596        "A Worker would declare two bindings with the same name, such as an agent `Kv` and the `bynk.cloudflare` KV namespace (both `KV`).",
597    ),
598    d(
599        "bynk.context.external_construction",
600        "A context-owned type was constructed from outside that context.",
601    ),
602    dg(
603        "bynk.context.external_provider",
604        "A bodiless (external) provider was declared outside an `adapter`.",
605        &["provider_decl"],
606    ),
607    d(
608        "bynk.context.opaque_inspection",
609        "An opaquely-exported type was inspected from outside its context.",
610    ),
611    d(
612        "bynk.context.rebrand_construction",
613        "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.",
614    ),
615    d(
616        "bynk.contract.duplicate_name",
617        "A function declares two contract clauses (`requires`/`ensures`) with the same name.",
618    ),
619    d(
620        "bynk.contract.impure_predicate",
621        "A contract predicate uses an effectful or test-only construct; a contract clause must be pure.",
622    ),
623    d(
624        "bynk.contract.not_bool",
625        "A contract predicate does not have type `Bool`.",
626    ),
627    d(
628        "bynk.contract.restated_by_test",
629        "A `case`/`property` merely restates a contract clause already declared at the function; the test is redundant.",
630    ),
631    d(
632        "bynk.contract.result_in_requires",
633        "A precondition (`requires`) references `result`; the return value is only in scope inside an `ensures`.",
634    ),
635    dg(
636        "bynk.cron.bad_params",
637        "A cron handler declares more than one parameter, or a non-`Int` one.",
638        &["cron_handler"],
639    ),
640    dg(
641        "bynk.cron.duplicate_schedule",
642        "Two cron handlers declare the same schedule.",
643        &["cron_handler"],
644    ),
645    dg(
646        "bynk.cron.invalid_schedule",
647        "A cron expression is not five whitespace-separated fields.",
648        &["cron_handler"],
649    ),
650    dg(
651        "bynk.cron.return_not_effect_result",
652        "A cron handler does not return `Effect[Result[(), E]]`.",
653        &["cron_handler"],
654    ),
655    d(
656        "bynk.dependency.path_outside_root",
657        "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.",
658    ),
659    d(
660        "bynk.deploy.contract_skew",
661        "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.",
662    ),
663    d(
664        "bynk.deploy.foreign_contract_skew",
665        "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.",
666    ),
667    d(
668        "bynk.duration.literal_overflow",
669        "A `Duration` literal (`<int>.<unit>`) exceeds the representable millisecond range.",
670    ),
671    dg(
672        "bynk.effect.bind_in_pure_context",
673        "An `<-` bind was used in a pure (non-effectful) context.",
674        &["effect_let_stmt"],
675    ),
676    dg(
677        "bynk.effect.bind_on_non_effect",
678        "An `<-` bind was applied to a non-`Effect` value.",
679        &["effect_let_stmt"],
680    ),
681    d(
682        "bynk.effect.capability_in_pure_context",
683        "A capability was used in a pure context.",
684    ),
685    d(
686        "bynk.effect.cross_context_in_pure_context",
687        "A cross-context call was made in a pure context.",
688    ),
689    dg(
690        "bynk.effect.do_in_pure_context",
691        "A `do` statement was used in a pure (non-effectful) context.",
692        &["do_stmt"],
693    ),
694    dg(
695        "bynk.effect.do_on_non_effect",
696        "A `do` statement was applied to a non-`Effect` value.",
697        &["do_stmt"],
698    ),
699    dg(
700        "bynk.effect.do_requires_unit",
701        "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.",
702        &["do_stmt"],
703    ),
704    dg(
705        "bynk.effect.fn_value_in_pure_context",
706        "An effectful function value was called in a pure context; like a capability call, it is legal only where the enclosing body is effectful.",
707        &["call"],
708    ),
709    d(
710        "bynk.effect.unbound_effect",
711        "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).",
712    ),
713    d(
714        "bynk.event.bad_field_default",
715        "An 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, or `T.unsafe(lit)` for an opaque type whose literal also satisfies the refinement.",
716    ),
717    d(
718        "bynk.event.bad_params",
719        "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.",
720    ),
721    d(
722        "bynk.event.bad_schema_dispatch",
723        "A `via schema(...)` dispatch clause's argument is malformed — it must be a single, positive, positional `Int` literal.",
724    ),
725    d(
726        "bynk.event.bad_schema_version",
727        "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.",
728    ),
729    d(
730        "bynk.event.default_outside_event",
731        "A field default (`field: T = expr`) was written on a record field outside an `event` declaration — a default is only meaningful on an event's own field, since it exists to let an older wire event missing this key still deserialise.",
732    ),
733    dg(
734        "bynk.event.duplicate_handler",
735        "A `from Events` service declares more than one `on event` handler; it has exactly one.",
736        &["event_handler"],
737    ),
738    d(
739        "bynk.event.emit_not_an_event",
740        "`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.",
741    ),
742    d(
743        "bynk.event.emit_outside_owner",
744        "`Events.emit[E]` named an event `E` not declared in the emitting context — only an event's declaring context may emit it.",
745    ),
746    d(
747        "bynk.event.handler_param_type_mismatch",
748        "An `on event(e: T)` handler's declared parameter type does not match its `from Events(E)` header's event type.",
749    ),
750    d(
751        "bynk.event.non_additive_schema_change",
752        "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.",
753    ),
754    d(
755        "bynk.event.outside_context",
756        "An `event` was declared outside a context.",
757    ),
758    d(
759        "bynk.event.pattern_duplicate_field",
760        "A `from Events(E { ... })` subscription pattern listed the same field more than once.",
761    ),
762    d(
763        "bynk.event.pattern_type_mismatch",
764        "A `from Events(E { ... })` subscription pattern field's matched value is not compatible with that field's declared type.",
765    ),
766    d(
767        "bynk.event.pattern_unknown_field",
768        "A `from Events(E { ... })` subscription pattern named a field that `E` does not declare.",
769    ),
770    d(
771        "bynk.event.pattern_unknown_variant",
772        "A `from Events(E { ... })` subscription pattern's variant value names a variant that does not exist on the field's declared sum type.",
773    ),
774    d(
775        "bynk.event.pattern_variant_payload",
776        "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.",
777    ),
778    dg(
779        "bynk.event.return_not_effect_unit",
780        "An `on event` handler returns an `Effect` of something other than `()`; emission is fire-and-forget, so it returns `Effect[()]`.",
781        &["event_handler"],
782    ),
783    d(
784        "bynk.event.schema_version_mismatch",
785        "An event's `@schema(N)` annotation disagrees with the version the schema registry computes from the event's build history.",
786    ),
787    d(
788        "bynk.event.unknown_annotation",
789        "An `event` declaration carried an `@`-annotation other than `@schema` — event annotations are a closed set.",
790    ),
791    d(
792        "bynk.event.unknown_subscription",
793        "A `from Events(E)` subscription named `E`, which is not a declared event in this context or any consumed context.",
794    ),
795    dg(
796        "bynk.expect.faults_not_effect",
797        "A fault claim's subject (`expect <call> faults`) is not an effectful call: a value, or a call whose type is not `Effect[_]`.",
798        &["faults_expr"],
799    ),
800    dg(
801        "bynk.expect.not_bool",
802        "`expect` was given a non-`Bool` predicate.",
803        &["expect_expr"],
804    ),
805    dg(
806        "bynk.expect.outside_case",
807        "`expect` was used outside a `case` body.",
808        &["expect_expr"],
809    ),
810    dg(
811        "bynk.exports.capability_not_provided",
812        "An exported capability has no provider in its context.",
813        &["exports_decl"],
814    ),
815    dg(
816        "bynk.exports.conflicting_visibility",
817        "A type is exported with conflicting visibilities.",
818        &["exports_decl"],
819    ),
820    dg(
821        "bynk.exports.derived_capability",
822        "`exports capability` names a derived capability, whose instance stays with its context.",
823        &["exports_decl"],
824    ),
825    dg(
826        "bynk.exports.duplicate_export",
827        "The same name is exported more than once.",
828        &["exports_decl"],
829    ),
830    dg(
831        "bynk.exports.duplicate_in_clause",
832        "A name appears twice in one `exports` clause.",
833        &["exports_decl"],
834    ),
835    dg(
836        "bynk.exports.undeclared_capability",
837        "`exports capability` names a capability that is not declared.",
838        &["exports_decl"],
839    ),
840    dg(
841        "bynk.exports.undeclared_type",
842        "`exports` names a type that is not declared.",
843        &["exports_decl"],
844    ),
845    d(
846        "bynk.fmt.comment_loss",
847        "The formatter would drop a comment, so it leaves the file unchanged.",
848    ),
849    d(
850        "bynk.fmt.mixed_comment_syntax",
851        "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.",
852    ),
853    d(
854        "bynk.fmt.roundtrip",
855        "The formatter's output does not re-parse to the same program, so it leaves the file unchanged.",
856    ),
857    dg(
858        "bynk.generics.duplicate_type_param",
859        "A `type` or `fn` declares the same type-parameter name more than once (v0.157, ADR 0183).",
860        &[],
861    ),
862    dg(
863        "bynk.generics.generic_non_record",
864        "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).",
865        &["type_decl"],
866    ),
867    dg(
868        "bynk.generics.generic_record_at_boundary",
869        "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.",
870        &[],
871    ),
872    dg(
873        "bynk.generics.generic_sum_embeds",
874        "A generic sum type carries an `embeds` clause; embedding into a generic sum is not supported (#593).",
875        &["type_decl"],
876    ),
877    dg(
878        "bynk.generics.method_on_generic_type",
879        "A *static* method is attached to a generic type; static methods on generic types are deferred (they have no receiver to supply the type's parameters). Instance methods on generic types are supported (#594).",
880        &["fn_decl"],
881    ),
882    dg(
883        "bynk.generics.no_bounds",
884        "A type parameter carries a bound (`[A: …]`); bounded generics are not in v0.20a.",
885        &["fn_decl"],
886    ),
887    dg(
888        "bynk.generics.recursive_generic_at_boundary",
889        "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).",
890        &[],
891    ),
892    dg(
893        "bynk.generics.type_arg_count",
894        "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).",
895        &["applied_type_ref"],
896    ),
897    dg(
898        "bynk.generics.type_arg_mismatch",
899        "Inferred or explicit type arguments conflict, have the wrong arity, target a non-generic function, or a type parameter shadows a declared type.",
900        &["call"],
901    ),
902    dg(
903        "bynk.generics.uninferable_type_arg",
904        "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.",
905        &["call"],
906    ),
907    dg(
908        "bynk.given.cross_context_unknown_capability",
909        "`given B.Cap` names a capability the consumed context does not export.",
910        &["given_clause"],
911    ),
912    dg(
913        "bynk.given.undeclared_capability",
914        "A handler uses a capability it did not declare with `given`.",
915        &["given_clause"],
916    ),
917    dg(
918        "bynk.given.unknown_capability",
919        "`given` names a capability that does not exist.",
920        &["given_clause"],
921    ),
922    warn(dg(
923        "bynk.given.unused_capability",
924        "A `given` capability is never used (warning).",
925        &["given_clause"],
926    )),
927    d(
928        "bynk.held.branch_divergence",
929        "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).",
930    ),
931    d(
932        "bynk.held.consume_on_borrow",
933        "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).",
934    ),
935    d(
936        "bynk.held.leak",
937        "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).",
938    ),
939    d(
940        "bynk.held.query_accessor_on_held_map",
941        "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.",
942    ),
943    d(
944        "bynk.held.unsupported_map_op",
945        "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).",
946    ),
947    d(
948        "bynk.held.unsupported_storage",
949        "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).",
950    ),
951    d(
952        "bynk.held.use_after_consume",
953        "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).",
954    ),
955    d(
956        "bynk.history.not_an_agent",
957        "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).",
958    ),
959    d(
960        "bynk.history.not_generable",
961        "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).",
962    ),
963    d(
964        "bynk.history.outside_property",
965        "`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).",
966    ),
967    d(
968        "bynk.history.restates_invariant",
969        "A history property merely re-checks a guarantee a declared `invariant`/`transition` already enforces on every reached state (testing track slice 7, ADR 0155).",
970    ),
971    dg(
972        "bynk.http.body_on_get_or_delete",
973        "A GET or DELETE handler declares a `body` parameter.",
974        &["http_handler"],
975    ),
976    d(
977        "bynk.http.cache_bad_max_age",
978        "A `@cache` annotation's `maxAge` is missing or not a positive `Duration` literal.",
979    ),
980    d(
981        "bynk.http.cache_bad_scope",
982        "A `@cache` annotation's `scope` is not `public` or `private`.",
983    ),
984    d(
985        "bynk.http.cache_duplicate",
986        "A handler carries more than one `@cache` annotation.",
987    ),
988    d(
989        "bynk.http.cache_max_age_fractional_seconds",
990        "A `@cache` annotation's `maxAge` is positive but does not resolve to a whole number of seconds.",
991    ),
992    d(
993        "bynk.http.cache_on_non_get",
994        "A `@cache` annotation is placed on a handler that is not `on http GET`.",
995    ),
996    d(
997        "bynk.http.cache_unknown_arg",
998        "A `@cache` annotation has an argument outside the closed set (`maxAge`/`scope`).",
999    ),
1000    d(
1001        "bynk.http.cors_invalid_field",
1002        "A `cors` policy field (`headers`/`credentials`/`maxAge`) has the wrong value shape.",
1003    ),
1004    d(
1005        "bynk.http.cors_invalid_origins",
1006        "A `cors` policy's `origins` is missing, empty, or not a list of string literals.",
1007    ),
1008    d(
1009        "bynk.http.cors_not_http",
1010        "A `cors { }` policy appears on a service that is not `from http`.",
1011    ),
1012    d(
1013        "bynk.http.cors_unknown_field",
1014        "A `cors { }` policy declares a field outside the closed set.",
1015    ),
1016    d(
1017        "bynk.http.cors_wildcard_credentials",
1018        "A `cors` policy combines `credentials: true` with the wildcard origin `[\"*\"]`.",
1019    ),
1020    dg(
1021        "bynk.http.duplicate_route",
1022        "Two handlers share the same method and route.",
1023        &["http_handler"],
1024    ),
1025    dg(
1026        "bynk.http.extra_param",
1027        "A handler parameter is neither a path parameter nor `body`.",
1028        &["http_handler"],
1029    ),
1030    dg(
1031        "bynk.http.invalid_path",
1032        "An HTTP route path is malformed.",
1033        &["http_handler"],
1034    ),
1035    d(
1036        "bynk.http.limit_bad_max_body",
1037        "A `@limit` annotation's `maxBody` is missing or not a positive `Int` literal.",
1038    ),
1039    d(
1040        "bynk.http.limit_duplicate",
1041        "A handler carries more than one `@limit` annotation.",
1042    ),
1043    d(
1044        "bynk.http.limit_on_bodyless",
1045        "A `@limit` annotation is placed on a handler that takes no body (a GET or DELETE).",
1046    ),
1047    d(
1048        "bynk.http.limit_unknown_arg",
1049        "A `@limit` annotation has an argument outside the closed set (`maxBody`).",
1050    ),
1051    d(
1052        "bynk.http.limits_invalid_field",
1053        "A `limits` policy field (`maxBody`) has the wrong value shape.",
1054    ),
1055    d(
1056        "bynk.http.limits_not_http",
1057        "A `limits { }` policy appears on a service that is not `from http`.",
1058    ),
1059    d(
1060        "bynk.http.limits_unknown_field",
1061        "A `limits { }` policy declares a field outside the closed set.",
1062    ),
1063    dg(
1064        "bynk.http.path_param_not_stringy",
1065        "A path parameter's type is not constructible from a string.",
1066        &["http_handler"],
1067    ),
1068    dg(
1069        "bynk.http.reserved_prefix",
1070        "A route uses the reserved `/_bynk/` prefix.",
1071        &["http_handler"],
1072    ),
1073    dg(
1074        "bynk.http.return_not_effect_http_result",
1075        "An HTTP handler does not return `Effect[HttpResult[T]]`.",
1076        &["http_handler"],
1077    ),
1078    d(
1079        "bynk.http.security_invalid_field",
1080        "A `security` policy field (`hsts`/`nosniff`) has the wrong value shape.",
1081    ),
1082    d(
1083        "bynk.http.security_not_http",
1084        "A `security { }` policy appears on a service that is not `from http`.",
1085    ),
1086    d(
1087        "bynk.http.security_unknown_field",
1088        "A `security { }` policy declares a field outside the closed set.",
1089    ),
1090    dg(
1091        "bynk.http.unbound_path_param",
1092        "A `:name` route segment has no matching handler parameter.",
1093        &["http_handler"],
1094    ),
1095    d(
1096        "bynk.http.unknown_handler_annotation",
1097        "A handler carries an annotation outside the closed set (`@cache`/`@limit`).",
1098    ),
1099    d(
1100        "bynk.index.bad_argument",
1101        "An `@indexed` argument is not a `by: <field>` label.",
1102    ),
1103    warn(d(
1104        "bynk.index.missing",
1105        "A query filters a map by equality on a field that is not `@indexed` (a perf-hint warning).",
1106    )),
1107    d(
1108        "bynk.index.unkeyable_key",
1109        "An `@indexed(by: k)` field is not value-keyable.",
1110    ),
1111    d(
1112        "bynk.index.unknown_key",
1113        "An `@indexed(by: k)` field is not a field of the map's value type.",
1114    ),
1115    warn(d(
1116        "bynk.index.unused",
1117        "A declared `@indexed(by: k)` is never used by an equality filter (a hygiene warning).",
1118    )),
1119    d(
1120        "bynk.invariant.cross_agent_reference",
1121        "An invariant predicate references another agent; invariants are per-agent.",
1122    ),
1123    d(
1124        "bynk.invariant.duplicate_name",
1125        "An agent declares two invariants with the same name.",
1126    ),
1127    d(
1128        "bynk.invariant.impure_predicate",
1129        "An invariant predicate uses an effectful or test-only construct.",
1130    ),
1131    d(
1132        "bynk.invariant.not_bool",
1133        "An invariant predicate does not have type `Bool`.",
1134    ),
1135    dg(
1136        "bynk.lambda.unannotated_param",
1137        "A lambda parameter has no type annotation in a position where no function type is expected to infer it from.",
1138        &["lambda_expr"],
1139    ),
1140    dg(
1141        "bynk.lex.bad_escape",
1142        "An invalid escape sequence in a string literal.",
1143        &["string_literal"],
1144    ),
1145    dg(
1146        "bynk.lex.float_literal_overflow",
1147        "A float literal does not fit a finite 64-bit float.",
1148        &["float_literal"],
1149    ),
1150    dg(
1151        "bynk.lex.integer_overflow",
1152        "An integer literal is outside the `Int` range, the JS safe integers ±(2^53 − 1).",
1153        &["number_literal"],
1154    ),
1155    dg(
1156        "bynk.lex.interpolation_too_deep",
1157        "A string interpolation `\\(…)` nests deeper than the lexer's fixed limit.",
1158        &["string_literal"],
1159    ),
1160    d(
1161        "bynk.lex.legacy_comment",
1162        "A `--` line comment, the spelling before #2203; a comment is `//` (auto-fixable; `bynk fmt` rewrites it).",
1163    ),
1164    d(
1165        "bynk.lex.legacy_doc_line",
1166        "A `--|` one-line doc, the spelling before #2203; a one-line doc is `--- text` (auto-fixable; `bynk fmt` rewrites it).",
1167    ),
1168    d(
1169        "bynk.lex.slash_doc",
1170        "A `///` doc comment first on its line; a Bynk doc is `--- text` or a `---` block (auto-fixable).",
1171    ),
1172    d(
1173        "bynk.lex.unclosed_doc_block",
1174        "A documentation block is not closed.",
1175    ),
1176    d(
1177        "bynk.lex.unexpected_character",
1178        "An unexpected character in the source.",
1179    ),
1180    dg(
1181        "bynk.lex.unterminated_interpolation",
1182        "An interpolation hole `\\(…)` is not closed on its line.",
1183        &["string_literal"],
1184    ),
1185    dg(
1186        "bynk.lex.unterminated_string",
1187        "A string literal is not terminated.",
1188        &["string_literal"],
1189    ),
1190    warn(d(
1191        "bynk.list.deprecated_function",
1192        "A `bynk.list` free function (`map`/`filter`/`find`/`any`/`all`) is deprecated in favour of the `List` method form (warning; auto-fixable).",
1193    )),
1194    d(
1195        "bynk.locale.multiple_message_bundles",
1196        "A context consumes `Locale` but its direct `uses` reaches two or more message-bundle commons — there is no single bundle to negotiate against.",
1197    ),
1198    d(
1199        "bynk.messages.format_mismatch",
1200        "A code's placeholder is formatted as a different ICU kind (plain/plural/select/number/date) across declared locales.",
1201    ),
1202    d(
1203        "bynk.messages.incomplete",
1204        "A locale is missing a code the reference locale declares.",
1205    ),
1206    d(
1207        "bynk.messages.invalid_locale_tag",
1208        "A `messages` block's locale tag is not a valid `LocaleTag` (e.g. `messages \"xx\"` where `xx` doesn't match the tag pattern).",
1209    ),
1210    d(
1211        "bynk.messages.malformed_icu_syntax",
1212        "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).",
1213    ),
1214    d(
1215        "bynk.messages.missing_locale_dependency",
1216        "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.",
1217    ),
1218    d(
1219        "bynk.messages.missing_reference",
1220        "A message bundle has no `@reference` block.",
1221    ),
1222    d(
1223        "bynk.messages.multiple_reference",
1224        "A message bundle has more than one `@reference` block.",
1225    ),
1226    d(
1227        "bynk.messages.outside_commons",
1228        "A `messages` declaration appears outside a commons.",
1229    ),
1230    d(
1231        "bynk.messages.placeholder_mismatch",
1232        "A locale's template for a code uses a different set of `{name}` placeholders than the reference locale's.",
1233    ),
1234    d(
1235        "bynk.namespace.reserved",
1236        "A user unit is named `bynk` or `bynk.*`; the `bynk` root is reserved for the toolchain.",
1237    ),
1238    d(
1239        "bynk.observe.impure_with",
1240        "A `with` predicate uses an effectful or test-only construct; it must be pure.",
1241    ),
1242    d(
1243        "bynk.observe.not_a_seam",
1244        "An observation targets a capability the unit under test does not consume.",
1245    ),
1246    d(
1247        "bynk.observe.trace_outside_test",
1248        "`trace(Cap.op)` appears outside a `case` body.",
1249    ),
1250    d(
1251        "bynk.observe.unknown_op",
1252        "An observation names an operation the capability does not declare.",
1253    ),
1254    d(
1255        "bynk.observe.with_not_bool",
1256        "A `with` predicate does not have type `Bool`.",
1257    ),
1258    d(
1259        "bynk.package.alias_shadows_unit",
1260        "A dependency alias in `[dependencies]` is also the first segment of one of the project's own units, so `<alias>.…` would be ambiguous.",
1261    ),
1262    d(
1263        "bynk.package.dependency_cycle",
1264        "The package graph has a cycle: a dependency depends, directly or not, on itself or on the project.",
1265    ),
1266    d(
1267        "bynk.package.dependency_not_found",
1268        "A path dependency's directory has no readable `bynk.toml`, its `bynk.toml` is invalid, or it has no `[package]`.",
1269    ),
1270    d(
1271        "bynk.package.duplicate_source",
1272        "One package is reached from two different directories; a build holds one copy of each package.",
1273    ),
1274    d(
1275        "bynk.package.name_mismatch",
1276        "A path dependency's `package` names a different package than the directory's `[package] name`.",
1277    ),
1278    d(
1279        "bynk.package.unit_not_exported",
1280        "A `uses` or `consumes` reaches a unit its dependency declares but doesn't list in `[package] exports`.",
1281    ),
1282    d(
1283        "bynk.package.unknown_unit",
1284        "A `uses` or `consumes` names, through a dependency alias, a unit the dependency doesn't declare.",
1285    ),
1286    d(
1287        "bynk.package.unsupported_in_dependency",
1288        "A dependency carries something a later packaging slice delivers: an adapter's npm `requires`, or an `asset`.",
1289    ),
1290    d(
1291        "bynk.package.unsupported_source",
1292        "A dependency is a git or registry dependency, which later packaging slices resolve; only `path` dependencies resolve today.",
1293    ),
1294    dg(
1295        "bynk.parse.consumes_after_decls",
1296        "`consumes` appears after other declarations.",
1297        &["consumes_decl"],
1298    ),
1299    d(
1300        "bynk.parse.dangling_handler_annotation",
1301        "A handler-position annotation (e.g. `@cache`) is not followed by an `on` handler.",
1302    ),
1303    d(
1304        "bynk.parse.doc_block_contains_code",
1305        "A documentation block's content (outside Markdown code fences) parses as declarations, so a pair of dash dividers has turned code into documentation.",
1306    ),
1307    dg(
1308        "bynk.parse.duplicate_cors",
1309        "A service declares more than one `cors { }` policy.",
1310        &["service_decl"],
1311    ),
1312    dg(
1313        "bynk.parse.duplicate_limits",
1314        "A service declares more than one `limits { }` policy.",
1315        &["service_decl"],
1316    ),
1317    dg(
1318        "bynk.parse.duplicate_security",
1319        "A service declares more than one `security { }` policy.",
1320        &["service_decl"],
1321    ),
1322    dg(
1323        "bynk.parse.empty_agent",
1324        "An `agent` body is empty.",
1325        &["agent_decl"],
1326    ),
1327    dg(
1328        "bynk.parse.empty_capability",
1329        "A `capability` body is empty.",
1330        &["capability_decl"],
1331    ),
1332    d(
1333        "bynk.parse.empty_interpolation",
1334        "An interpolation hole `\\(…)` contains no expression.",
1335    ),
1336    dg(
1337        "bynk.parse.empty_match",
1338        "A `match` has no arms.",
1339        &["match_expr"],
1340    ),
1341    dg(
1342        "bynk.parse.empty_service",
1343        "A `service` body is empty.",
1344        &["service_decl"],
1345    ),
1346    d(
1347        "bynk.parse.event_pattern_empty",
1348        "A `from Events(E { ... })` subscription pattern listed no fields — use `from Events(E)` (no braces) for an unfiltered subscription.",
1349    ),
1350    dg(
1351        "bynk.parse.expected_agent_key",
1352        "Expected a `key` declaration in an agent.",
1353        &["agent_decl"],
1354    ),
1355    d(
1356        "bynk.parse.expected_agent_storage",
1357        "An agent declares no storage — it has no `store` fields.",
1358    ),
1359    dg(
1360        "bynk.parse.expected_base_type",
1361        "Expected a base type.",
1362        &["base_type"],
1363    ),
1364    dg(
1365        "bynk.parse.expected_capability_op",
1366        "Expected a capability operation.",
1367        &["capability_op"],
1368    ),
1369    d("bynk.parse.expected_expression", "Expected an expression."),
1370    dg(
1371        "bynk.parse.expected_handler",
1372        "Expected a handler.",
1373        &["handler"],
1374    ),
1375    d("bynk.parse.expected_item", "Expected a declaration."),
1376    dg(
1377        "bynk.parse.expected_predicate",
1378        "Expected a refinement predicate.",
1379        &["refinement"],
1380    ),
1381    dg(
1382        "bynk.parse.expected_provider_op",
1383        "Expected a provider operation.",
1384        &["provider_op"],
1385    ),
1386    d("bynk.parse.expected_token", "Expected a specific token."),
1387    d("bynk.parse.expected_type", "Expected a type."),
1388    d(
1389        "bynk.parse.expected_unit_header",
1390        "Expected a `commons` or `context` header.",
1391    ),
1392    dg(
1393        "bynk.parse.expected_visibility",
1394        "Expected a visibility keyword.",
1395        &["exports_decl"],
1396    ),
1397    dg(
1398        "bynk.parse.exports_after_decls",
1399        "`exports` appears after other declarations.",
1400        &["exports_decl"],
1401    ),
1402    d(
1403        "bynk.parse.extra_tokens",
1404        "Unexpected tokens after an otherwise complete construct.",
1405    ),
1406    dg(
1407        "bynk.parse.generic_arg_count",
1408        "Wrong number of generic type arguments.",
1409        &["generic_type_ref"],
1410    ),
1411    dg(
1412        "bynk.parse.handler_in_agent",
1413        "A protocol handler (`on GET`/`schedule`/`message`) was declared in an agent.",
1414        &["handler"],
1415    ),
1416    d(
1417        "bynk.parse.invariant_after_handler",
1418        "An `invariant` was declared after a handler; invariants precede handlers.",
1419    ),
1420    dg(
1421        "bynk.parse.let_else_on_binding",
1422        "An `else` follows a plain `let name = …` binding, which matches every value, so the `else` could never run.",
1423        &["let_stmt", "effect_let_stmt"],
1424    ),
1425    dg(
1426        "bynk.parse.let_pattern_annotation",
1427        "A `let` with a pattern carries a type annotation; the pattern's names take their types from the value.",
1428        &["let_else_stmt"],
1429    ),
1430    dg(
1431        "bynk.parse.let_pattern_without_else",
1432        "A `let` binds a pattern but has no `else` saying what the block produces when the value does not match.",
1433        &["let_else_stmt"],
1434    ),
1435    dg(
1436        "bynk.parse.malformed_float_literal",
1437        "A float literal is missing a digit on one side of the `.` (`1.`, `.5`).",
1438        &["float_literal"],
1439    ),
1440    d(
1441        "bynk.parse.multiple_docs",
1442        "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.",
1443    ),
1444    d(
1445        "bynk.parse.nesting_too_deep",
1446        "An expression or type nests deeper than the parser's fixed limit.",
1447    ),
1448    dg(
1449        "bynk.parse.non_associative",
1450        "A non-associative operator was chained (e.g. `a == b == c`).",
1451        &["binary_expr"],
1452    ),
1453    warn(d(
1454        "bynk.parse.orphan_doc_block",
1455        "A documentation block is not attached to a declaration (warning).",
1456    )),
1457    dg(
1458        "bynk.parse.policy_order",
1459        "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`.",
1460        &["service_decl"],
1461    ),
1462    dg(
1463        "bynk.parse.refined_pattern_inner",
1464        "A refined pattern's inner form is something other than `_`.",
1465        &["refined_pattern"],
1466    ),
1467    dg(
1468        "bynk.parse.reserved_keyword",
1469        "A reserved keyword was used as an identifier.",
1470        &["identifier"],
1471    ),
1472    dg(
1473        "bynk.parse.self_outside_method",
1474        "`self` used outside a method or handler.",
1475        &["self_expr"],
1476    ),
1477    d(
1478        "bynk.parse.storage_after_phase",
1479        "Agent storage (`state` / `store`) is declared after the invariants or handlers.",
1480    ),
1481    d(
1482        "bynk.parse.transition_after_handler",
1483        "A `transition` is declared after an agent handler; step invariants precede the handlers.",
1484    ),
1485    d(
1486        "bynk.parse.unexpected_adapter",
1487        "An `adapter` appeared where it is not allowed.",
1488    ),
1489    dg(
1490        "bynk.parse.unexpected_context",
1491        "A `context` appeared where it is not allowed.",
1492        &["context_decl"],
1493    ),
1494    d("bynk.parse.unexpected_eof", "Unexpected end of input."),
1495    dg(
1496        "bynk.parse.unexpected_suite",
1497        "A `suite` appeared where it is not allowed.",
1498        &["suite_decl"],
1499    ),
1500    d(
1501        "bynk.parse.unknown_effect_method",
1502        "An unknown method on `Effect`.",
1503    ),
1504    dg(
1505        "bynk.parse.unknown_handler_kind",
1506        "An unknown handler form (expected `call`, an HTTP method, `schedule`, or `message`).",
1507        &["handler"],
1508    ),
1509    dg(
1510        "bynk.parse.unknown_predicate",
1511        "An unknown refinement predicate.",
1512        &["predicate_name"],
1513    ),
1514    d(
1515        "bynk.parse.unknown_tier",
1516        "A `case`/`suite` `as <tier>` clause names something other than `unit`, `integration`, or `system`.",
1517    ),
1518    dg(
1519        "bynk.parse.uses_after_decls",
1520        "`uses` appears after other declarations.",
1521        &["uses_decl"],
1522    ),
1523    dg(
1524        "bynk.parse.variant_name_case",
1525        "A sum-type or enum variant name is not capitalised.",
1526        &["sum_variant", "enum_type"],
1527    ),
1528    warn(d(
1529        "bynk.project.duplicate_compatibility_flag",
1530        "`bynk.toml`'s `[workers] compatibility_flags` lists a flag twice, or one every Bynk Worker already has; the duplicate is dropped (warning).",
1531    )),
1532    d(
1533        "bynk.project.duplicate_module_doc",
1534        "More than one file of a multi-file unit carries a module doc.",
1535    ),
1536    d(
1537        "bynk.project.export_context",
1538        "`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.",
1539    ),
1540    d(
1541        "bynk.project.export_unknown",
1542        "`bynk.toml`'s `[package] exports` lists a name that isn't a commons or adapter the project declares.",
1543    ),
1544    d(
1545        "bynk.project.file_and_directory",
1546        "A unit exists as both a file and a directory.",
1547    ),
1548    d(
1549        "bynk.project.inconsistent_commons_name",
1550        "A source file's path does not match its declared name.",
1551    ),
1552    d(
1553        "bynk.project.kind_conflict",
1554        "A name is declared as both a commons and a context.",
1555    ),
1556    d(
1557        "bynk.project.no_root",
1558        "No project root could be determined.",
1559    ),
1560    d(
1561        "bynk.project.no_sources",
1562        "The project contains no source files.",
1563    ),
1564    d(
1565        "bynk.project.read_failed",
1566        "A source file could not be read.",
1567    ),
1568    d(
1569        "bynk.project.schema_registry_corrupt",
1570        "`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.",
1571    ),
1572    warn(d(
1573        "bynk.project.unstable_not_experimental",
1574        "`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).",
1575    )),
1576    d(
1577        "bynk.project.unstable_unknown_item",
1578        "`bynk.toml`'s `[unstable] allow` lists a path that names no standard-library unit, exported item or operation.",
1579    ),
1580    dg(
1581        "bynk.property.restates_refinement",
1582        "A `property` merely re-checks a refinement its type already guarantees.",
1583        &["for_all"],
1584    ),
1585    dg(
1586        "bynk.property.where_not_bool",
1587        "A `for all ... where` filter does not type to `Bool`.",
1588        &["for_all"],
1589    ),
1590    dg(
1591        "bynk.provider.dependency_cycle",
1592        "Providers form a capability dependency cycle through `given`.",
1593        &["provider_decl"],
1594    ),
1595    dg(
1596        "bynk.provider.extra_operation",
1597        "A `provides` block implements an operation not in the capability.",
1598        &["provider_decl"],
1599    ),
1600    dg(
1601        "bynk.provider.generic_op_requires_external",
1602        "A Bynk-bodied `provides` implements a capability operation that declares its own type parameter — only an external (bodiless) provider can.",
1603        &["provider_decl"],
1604    ),
1605    dg(
1606        "bynk.provider.missing_operation",
1607        "A `provides` block is missing a capability operation.",
1608        &["provider_decl"],
1609    ),
1610    dg(
1611        "bynk.provider.outside_context",
1612        "`provides` was declared outside a context.",
1613        &["provider_decl"],
1614    ),
1615    dg(
1616        "bynk.provider.signature_mismatch",
1617        "A `provides` operation's signature does not match the capability.",
1618        &["provider_decl"],
1619    ),
1620    dg(
1621        "bynk.provider.unknown_capability",
1622        "`provides` names a capability that does not exist.",
1623        &["provider_decl"],
1624    ),
1625    d(
1626        "bynk.query.join_key_mismatch",
1627        "A `joinOn`/`leftJoin` left and right key function return different types.",
1628    ),
1629    dg(
1630        "bynk.query.sum_needs_numeric",
1631        "A `sum`/`average` key function does not return a numeric type (`Int`, `Float`, or `Duration`).",
1632        &[],
1633    ),
1634    dg(
1635        "bynk.queue.bad_params",
1636        "An `on message` handler does not take exactly one `message` parameter.",
1637        &["queue_handler"],
1638    ),
1639    dg(
1640        "bynk.queue.duplicate_consumer",
1641        "Two `on message` handlers consume the same queue.",
1642        &["queue_handler"],
1643    ),
1644    dg(
1645        "bynk.queue.invalid_name",
1646        "A `from queue(\"…\")` binding has an empty queue name.",
1647        &["queue_handler"],
1648    ),
1649    dg(
1650        "bynk.queue.return_not_queue_result",
1651        "An `on message` handler does not return `Effect[QueueResult]`.",
1652        &["handler"],
1653    ),
1654    dg(
1655        "bynk.record_spread.field_type_mismatch",
1656        "A record-spread override has the wrong type for the field.",
1657        &["record_spread"],
1658    ),
1659    dg(
1660        "bynk.record_spread.non_record_base",
1661        "The base of a record spread is not a record.",
1662        &["record_spread"],
1663    ),
1664    dg(
1665        "bynk.record_spread.type_mismatch",
1666        "A record spread's base is a different record type.",
1667        &["record_spread"],
1668    ),
1669    dg(
1670        "bynk.record_spread.unknown_field",
1671        "A record spread overrides a field the record does not have.",
1672        &["record_spread"],
1673    ),
1674    dg(
1675        "bynk.refine.literal_violates",
1676        "A literal does not satisfy the refined type's predicate.",
1677        &["refined_type"],
1678    ),
1679    dg(
1680        "bynk.requires.conflicting_range",
1681        "Two adapter `binding … requires { … }` entries give different version ranges for one npm package.",
1682        &["binding_decl"],
1683    ),
1684    dg(
1685        "bynk.requires.unpinned_dependency",
1686        "An adapter `binding … requires { … }` entry has an unpinned version range.",
1687        &["binding_decl"],
1688    ),
1689    d(
1690        "bynk.resolve.ambiguous_variant",
1691        "A variant name is ambiguous across several sum types.",
1692    ),
1693    dg(
1694        "bynk.resolve.arity_mismatch",
1695        "A function was called with the wrong number of arguments.",
1696        &["call"],
1697    ),
1698    d("bynk.resolve.duplicate_actor", "Two actors share a name."),
1699    dg(
1700        "bynk.resolve.duplicate_agent",
1701        "Two agents share a name.",
1702        &["agent_decl"],
1703    ),
1704    dg(
1705        "bynk.resolve.duplicate_capability",
1706        "Two capabilities share a name.",
1707        &["capability_decl"],
1708    ),
1709    dg(
1710        "bynk.resolve.duplicate_field",
1711        "A record declares a field twice.",
1712        &["record_type"],
1713    ),
1714    dg(
1715        "bynk.resolve.duplicate_field_init",
1716        "A record construction initialises a field twice.",
1717        &["record_construction"],
1718    ),
1719    dg(
1720        "bynk.resolve.duplicate_fn",
1721        "Two functions share a name.",
1722        &["fn_decl"],
1723    ),
1724    d(
1725        "bynk.resolve.duplicate_message_code",
1726        "A message bundle declares the same code twice in one block.",
1727    ),
1728    d(
1729        "bynk.resolve.duplicate_message_locale",
1730        "Two `messages` blocks in one bundle declare the same locale tag.",
1731    ),
1732    dg(
1733        "bynk.resolve.duplicate_method",
1734        "Two methods share a name.",
1735        &["fn_decl"],
1736    ),
1737    dg(
1738        "bynk.resolve.duplicate_param",
1739        "A parameter name is repeated.",
1740        &["param"],
1741    ),
1742    dg(
1743        "bynk.resolve.duplicate_provider",
1744        "A capability is provided more than once.",
1745        &["provider_decl"],
1746    ),
1747    dg(
1748        "bynk.resolve.duplicate_service",
1749        "Two services share a name.",
1750        &["service_decl"],
1751    ),
1752    dg(
1753        "bynk.resolve.duplicate_type",
1754        "Two types share a name.",
1755        &["type_decl"],
1756    ),
1757    dg(
1758        "bynk.resolve.duplicate_variant",
1759        "A sum type declares a variant twice.",
1760        &["sum_type"],
1761    ),
1762    d(
1763        "bynk.resolve.fn_without_call",
1764        "A function was referenced without being called.",
1765    ),
1766    dg(
1767        "bynk.resolve.let_shadows_fn",
1768        "A `let` binding shadows a function.",
1769        &["let_stmt"],
1770    ),
1771    dg(
1772        "bynk.resolve.let_shadows_type",
1773        "A `let` binding shadows a type.",
1774        &["let_stmt"],
1775    ),
1776    d(
1777        "bynk.resolve.method_unknown_type",
1778        "A method is defined on an unknown type.",
1779    ),
1780    dg(
1781        "bynk.resolve.missing_field",
1782        "A record construction omits a required field.",
1783        &["record_construction"],
1784    ),
1785    d(
1786        "bynk.resolve.name_conflict",
1787        "Two declarations share a name.",
1788    ),
1789    dg(
1790        "bynk.resolve.not_a_record_type",
1791        "Record syntax was used on a non-record type.",
1792        &["record_construction"],
1793    ),
1794    dg(
1795        "bynk.resolve.opaque_record_construction",
1796        "An opaque type was constructed with record syntax.",
1797        &["record_construction"],
1798    ),
1799    dg(
1800        "bynk.resolve.param_as_function",
1801        "A value (such as a parameter) was called as a function.",
1802        &["call"],
1803    ),
1804    dg(
1805        "bynk.resolve.recursive_record_field",
1806        "A record directly contains a field of its own type.",
1807        &["record_type"],
1808    ),
1809    dg(
1810        "bynk.resolve.reserved_builtin_type",
1811        "A type declaration reuses a compiler-known built-in type name.",
1812        &["type_decl"],
1813    ),
1814    dg(
1815        "bynk.resolve.reserved_host_name",
1816        "A declaration is named `globalThis`, which the generated TypeScript uses to reach host globals.",
1817        &["type_decl", "fn_decl", "agent_decl", "provider_decl"],
1818    ),
1819    dg(
1820        "bynk.resolve.reserved_payload_field",
1821        "A sum variant declares a payload field named `kind`, the variant's wire discriminant.",
1822        &["sum_type"],
1823    ),
1824    dg(
1825        "bynk.resolve.self_outside_method",
1826        "`self` referenced outside a method or handler.",
1827        &["self_expr"],
1828    ),
1829    dg(
1830        "bynk.resolve.type_as_function",
1831        "A type name was called as if it were a function.",
1832        &["call"],
1833    ),
1834    d(
1835        "bynk.resolve.type_in_expr",
1836        "A type name was used where a value is expected.",
1837    ),
1838    dg(
1839        "bynk.resolve.unconsumed_context",
1840        "A context's service was called without a `consumes` declaration.",
1841        &["consumes_decl"],
1842    ),
1843    dg(
1844        "bynk.resolve.unknown_field",
1845        "Accessed a field the record does not have.",
1846        &["field_access"],
1847    ),
1848    dg(
1849        "bynk.resolve.unknown_function",
1850        "Called a function that does not exist.",
1851        &["call"],
1852    ),
1853    d(
1854        "bynk.resolve.unknown_name",
1855        "Referenced a name that is not in scope.",
1856    ),
1857    dg(
1858        "bynk.resolve.unknown_static_member",
1859        "Referenced an unknown static member (e.g. `T.x`).",
1860        &["field_access"],
1861    ),
1862    d(
1863        "bynk.resolve.unknown_type",
1864        "Referenced a type that does not exist.",
1865    ),
1866    warn(d(
1867        "bynk.secrets.computed_name",
1868        "A `bynk.Secrets` read names its secret with a computed expression rather than a literal, so `bynk deploy` cannot plan it (warning).",
1869    )),
1870    dg(
1871        "bynk.send.in_agent_handler",
1872        "A `~>` send was used in an agent handler, which has no execution context to keep a fire-and-forget send alive.",
1873        &["effect_send_stmt"],
1874    ),
1875    dg(
1876        "bynk.send.in_pure_context",
1877        "A `~>` send was used in a pure (non-effectful) context.",
1878        &["effect_send_stmt"],
1879    ),
1880    dg(
1881        "bynk.send.non_effect",
1882        "A `~>` send was applied to a non-`Effect` value.",
1883        &["effect_send_stmt"],
1884    ),
1885    dg(
1886        "bynk.send.requires_unit",
1887        "A `~>` send targets an operation whose reply is not `Effect[()]`.",
1888        &["effect_send_stmt"],
1889    ),
1890    dg(
1891        "bynk.send.store_op",
1892        "A `~>` send targets an agent store operation, which is part of the handler's atomic commit and cannot be sent without waiting.",
1893        &["effect_send_stmt"],
1894    ),
1895    dg(
1896        "bynk.service.missing_from",
1897        "A `from`-less service has a handler other than `on call`.",
1898        &["service_decl"],
1899    ),
1900    dg(
1901        "bynk.service.mixed_protocols",
1902        "A service mixes handler forms that do not match its `from <protocol>`.",
1903        &["service_decl"],
1904    ),
1905    dg(
1906        "bynk.service.outside_context",
1907        "A `service` was declared outside a context.",
1908        &["service_decl"],
1909    ),
1910    dg(
1911        "bynk.service.return_not_effect",
1912        "A service handler's return type is not an `Effect`.",
1913        &["service_decl"],
1914    ),
1915    dg(
1916        "bynk.service.unknown_protocol",
1917        "A `from <protocol>` names an unknown protocol (e.g. a transport like Kafka).",
1918        &["service_decl"],
1919    ),
1920    d(
1921        "bynk.service.unknown_via_clause",
1922        "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.",
1923    ),
1924    d(
1925        "bynk.service.websocket_header",
1926        "The `from websocket` header is malformed — it binds frame types as `websocket(in: <type>, out: <type>)` (real-time track slice 3).",
1927    ),
1928    d(
1929        "bynk.service.websocket_multiple",
1930        "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).",
1931    ),
1932    d(
1933        "bynk.service.websocket_open_arity",
1934        "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).",
1935    ),
1936    d(
1937        "bynk.service.websocket_param_not_stringy",
1938        "A `from websocket` service's `on open` parameter has a type not constructible from `String`; it arrives as a query-string value (#1657).",
1939    ),
1940    d(
1941        "bynk.stability.experimental",
1942        "An experimental standard-library item is used without an `[unstable] allow` entry in `bynk.toml` covering it.",
1943    ),
1944    d(
1945        "bynk.store.annotation_kind_mismatch",
1946        "A storage annotation is used on a kind it does not apply to (e.g. `@ttl` on a `Map`).",
1947    ),
1948    d(
1949        "bynk.store.annotation_unsupported",
1950        "A known storage annotation (`@ttl`/`@retain`/`@indexed`/`@bounded`) is used before the slice that supports it.",
1951    ),
1952    d(
1953        "bynk.store.cache_needs_clock",
1954        "A handler performs a `Cache` operation (TTL expiry reads the clock) without declaring `given Clock`.",
1955    ),
1956    d(
1957        "bynk.store.cache_ttl_required",
1958        "A `Cache` field is missing its required `@ttl(<duration>)` annotation (a keyed store with no expiry is a `Map`).",
1959    ),
1960    d(
1961        "bynk.store.kind_arity",
1962        "A storage kind was applied to the wrong number of type arguments (e.g. `Cell[A, B]`).",
1963    ),
1964    d(
1965        "bynk.store.kind_unsupported",
1966        "A known storage kind (`Queue`) is used before the slice that supports it.",
1967    ),
1968    d(
1969        "bynk.store.log_needs_clock",
1970        "A handler calls `Log.append` (which stamps the current time) without declaring `given Clock`.",
1971    ),
1972    d(
1973        "bynk.store.unkeyable_key",
1974        "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).",
1975    ),
1976    d(
1977        "bynk.store.unknown_annotation",
1978        "A `store` field carries an annotation outside the closed `@indexed`/`@ttl`/`@retain`/`@bounded` set.",
1979    ),
1980    d(
1981        "bynk.store.unknown_kind",
1982        "A `store` field's type is not a known storage kind.",
1983    ),
1984    d(
1985        "bynk.store.unknown_map_accessor",
1986        "A `store Map` field access is not one of its query accessors (`entries`/`keys`/`values`).",
1987    ),
1988    d(
1989        "bynk.store.unknown_op",
1990        "A storage-`Map`/`Set` operation is not a recognised entry/membership method.",
1991    ),
1992    dg(
1993        "bynk.stub.at_system",
1994        "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.",
1995        &["stub_clause"],
1996    ),
1997    d(
1998        "bynk.stub.bad_sequence",
1999        "A `stub … returns each […]` sequence is malformed (e.g. empty).",
2000    ),
2001    d(
2002        "bynk.stub.generic_op",
2003        "A test `stub` targets a capability operation that declares its own type parameter — not supported at v1.",
2004    ),
2005    d(
2006        "bynk.stub.not_a_seam",
2007        "A test `stub` overrides a capability the unit under test does not consume.",
2008    ),
2009    d(
2010        "bynk.stub.rhs_type",
2011        "A test `stub … returns <value>` right-hand side does not match the operation's return type.",
2012    ),
2013    d(
2014        "bynk.stub.unknown_op",
2015        "A test `stub` names an operation the capability does not declare.",
2016    ),
2017    dg(
2018        "bynk.suite.duplicate_case_name",
2019        "Two `case`s share a description.",
2020        &["case"],
2021    ),
2022    dg(
2023        "bynk.suite.duplicate_env",
2024        "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.",
2025        &["env_clause"],
2026    ),
2027    dg(
2028        "bynk.suite.env_binding_clash",
2029        "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`.",
2030        &["env_clause"],
2031    ),
2032    dg(
2033        "bynk.suite.env_not_literal",
2034        "An `env { … }` entry's value is not a `String` literal; a Worker's variables and secrets are strings, given verbatim.",
2035        &["env_clause"],
2036    ),
2037    dg(
2038        "bynk.suite.unknown_target",
2039        "A `suite` targets a unit that does not exist.",
2040        &["suite_decl"],
2041    ),
2042    d(
2043        "bynk.target.browser_bundle_only",
2044        "The `browser` platform builds only the in-process `Bundle` topology; `--target workers` is not a browser build.",
2045    ),
2046    dg(
2047        "bynk.target.vendor_conflict",
2048        "One deployment unit's in-process closure uses platform-native capabilities from two mutually-exclusive platforms.",
2049        &["consumes_decl"],
2050    ),
2051    dg(
2052        "bynk.target.vendor_required",
2053        "A deployment unit uses a platform-native capability but the build selects another `--platform`.",
2054        &["consumes_decl"],
2055    ),
2056    dg(
2057        "bynk.test.actor_identity_required",
2058        "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`.",
2059        &["case"],
2060    ),
2061    dg(
2062        "bynk.test.actor_no_identity",
2063        "A call-site `by <Actor>(x)` supplies an identity to an actor that takes none — a unit-identity actor (e.g. `Visitor`) or `Nobody`.",
2064        &["case"],
2065    ),
2066    dg(
2067        "bynk.test.advance_not_clock",
2068        "An `advance` statement names a capability other than `Clock`; the test harness owns one time source, the first-party `Clock`.",
2069        &["advance_stmt"],
2070    ),
2071    dg(
2072        "bynk.test.advance_not_duration",
2073        "An `advance Clock by` statement's amount is not a `Duration`.",
2074        &["advance_stmt"],
2075    ),
2076    dg(
2077        "bynk.test.advance_outside_case",
2078        "An `advance Clock by` statement appears outside a test `case` body; only the test harness has a clock to move.",
2079        &["advance_stmt"],
2080    ),
2081    dg(
2082        "bynk.test.asset_address_method",
2083        "A suite fetches an asset with a method other than `GET`; the platform serves assets to `GET` and answers other methods with 405.",
2084        &["case"],
2085    ),
2086    dg(
2087        "bynk.test.credential_needs_system",
2088        "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.",
2089        &["case"],
2090    ),
2091    dg(
2092        "bynk.test.event_needs_in_process",
2093        "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`.",
2094        &["case"],
2095    ),
2096    dg(
2097        "bynk.test.event_not_subscribed",
2098        "A test body's `svc.event(e)` delivers an event the `from Events(E)` service does not subscribe to.",
2099        &["case"],
2100    ),
2101    dg(
2102        "bynk.test.event_publisher_ambiguous",
2103        "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.",
2104        &["case"],
2105    ),
2106    dg(
2107        "bynk.test.faults_needs_in_process",
2108        "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`.",
2109        &["case"],
2110    ),
2111    dg(
2112        "bynk.test.forged_needs_signature_route",
2113        "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.",
2114        &["case"],
2115    ),
2116    dg(
2117        "bynk.test.forged_needs_system",
2118        "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.",
2119        &["case"],
2120    ),
2121    dg(
2122        "bynk.test.nobody_needs_secured_route",
2123        "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.",
2124        &["case"],
2125    ),
2126    dg(
2127        "bynk.test.oidc_needs_in_process",
2128        "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`.",
2129        &["case"],
2130    ),
2131    dg(
2132        "bynk.test.principal_identity_mismatch",
2133        "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.",
2134        &["case"],
2135    ),
2136    dg(
2137        "bynk.test.principal_on_asset",
2138        "A suite's asset fetch carries a `by` clause; an asset is public and served before the Worker runs.",
2139        &["case"],
2140    ),
2141    dg(
2142        "bynk.test.principal_on_wrong_method",
2143        "A wrong-method `405` test carries a `by <Actor>` clause; it reaches no handler, so a principal is meaningless.",
2144        &["case"],
2145    ),
2146    dg(
2147        "bynk.test.principal_required",
2148        "A test drives an identity-carrying handler, or one guarded by an actor sum, with no call-site `by <Actor>`.",
2149        &["case"],
2150    ),
2151    warn(dg(
2152        "bynk.test.remote_clock_dependent",
2153        "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.",
2154        &["case"],
2155    )),
2156    dg(
2157        "bynk.test.remote_unsupported_advance",
2158        "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.",
2159        &["case"],
2160    ),
2161    dg(
2162        "bynk.test.remote_unsupported_asset",
2163        "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.",
2164        &["case"],
2165    ),
2166    dg(
2167        "bynk.test.remote_unsupported_call",
2168        "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.",
2169        &["case"],
2170    ),
2171    dg(
2172        "bynk.test.remote_unsupported_env",
2173        "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.",
2174        &["case"],
2175    ),
2176    dg(
2177        "bynk.test.remote_unsupported_queue",
2178        "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.",
2179        &["case"],
2180    ),
2181    dg(
2182        "bynk.test.remote_unsupported_schedule",
2183        "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.",
2184        &["case"],
2185    ),
2186    dg(
2187        "bynk.test.service_bad_address",
2188        "A test body addresses a service the wrong way for its protocol (e.g. an http route without a leading path string).",
2189        &["case"],
2190    ),
2191    dg(
2192        "bynk.test.service_call_arity",
2193        "A test body's `svc.call(...)` passes the wrong number of arguments for the service's `on call` handler.",
2194        &["case"],
2195    ),
2196    dg(
2197        "bynk.test.service_no_call_handler",
2198        "A test body invokes `svc.call(...)` on a service with no `on call` handler (a `from http`/`cron`/`queue` service).",
2199        &["case"],
2200    ),
2201    dg(
2202        "bynk.test.service_unknown_route",
2203        "A test body addresses an http route / cron schedule / queue message the service does not declare.",
2204        &["case"],
2205    ),
2206    dg(
2207        "bynk.test.stale_needs_timestamp",
2208        "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.",
2209        &["case"],
2210    ),
2211    dg(
2212        "bynk.test.unknown_actor",
2213        "A call-site `by <Actor>` names an actor the target context does not declare and that is not a prelude actor.",
2214        &["case"],
2215    ),
2216    dg(
2217        "bynk.test.wire_needs_system",
2218        "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.",
2219        &["case"],
2220    ),
2221    dg(
2222        "bynk.tier.cross_context_needs_system",
2223        "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`.",
2224        &["case"],
2225    ),
2226    dg(
2227        "bynk.tier.mixed_system_suite",
2228        "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.",
2229        &["case"],
2230    ),
2231    d(
2232        "bynk.tier.system_needs_wire",
2233        "An `as system` test stands up fewer than two contexts; the system tier wires across contexts.",
2234    ),
2235    d(
2236        "bynk.transition.cross_agent_reference",
2237        "A transition predicate references another agent; step invariants are per-agent.",
2238    ),
2239    d(
2240        "bynk.transition.duplicate_name",
2241        "An agent declares two transitions with the same name.",
2242    ),
2243    d(
2244        "bynk.transition.impure_predicate",
2245        "A transition predicate uses an effectful or test-only construct; a step invariant must be pure.",
2246    ),
2247    warn(d(
2248        "bynk.transition.may_violate",
2249        "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.",
2250    )),
2251    d(
2252        "bynk.transition.no_step_reference",
2253        "A transition references neither `old` nor `new`; it constrains one state, so it is an `invariant`, not a step.",
2254    ),
2255    d(
2256        "bynk.transition.not_bool",
2257        "A transition predicate does not have type `Bool`.",
2258    ),
2259    dg(
2260        "bynk.types.argument_mismatch",
2261        "A call, method, capability, or constructor argument has the wrong type.",
2262        &["call"],
2263    ),
2264    d(
2265        "bynk.types.asset_at_boundary",
2266        "An `Asset` type appears in a record field, boundary or store position; pass its `.url` instead.",
2267    ),
2268    dg(
2269        "bynk.types.call_arity",
2270        "A function value was applied with the wrong number of arguments.",
2271        &["call"],
2272    ),
2273    dg(
2274        "bynk.types.cannot_infer_option_type_param",
2275        "The value type of `None` could not be inferred.",
2276        &["none_expr"],
2277    ),
2278    d(
2279        "bynk.types.cannot_infer_result_type_params",
2280        "The type parameters of a `Result` could not be inferred.",
2281    ),
2282    dg(
2283        "bynk.types.catastrophic_regex",
2284        "A `Matches` 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).",
2285        &["refinement"],
2286    ),
2287    dg(
2288        "bynk.types.combinator_return_mismatch",
2289        "A callback passed to a combinator (`map`/`andThen`/`flatMap`/`traverseAll`/…) returns the wrong type.",
2290        &["call"],
2291    ),
2292    d(
2293        "bynk.types.constructor_arity",
2294        "A variant constructor got the wrong number of arguments.",
2295    ),
2296    d(
2297        "bynk.types.constructor_base_mismatch",
2298        "A `.of` constructor was given an argument of the wrong base type.",
2299    ),
2300    dg(
2301        "bynk.types.duplicate_literal_arm",
2302        "A `match` has two arms for the same literal value.",
2303        &["match_arm"],
2304    ),
2305    dg(
2306        "bynk.types.duplicate_variant_arm",
2307        "A `match` has two arms for the same variant.",
2308        &["match_arm"],
2309    ),
2310    d(
2311        "bynk.types.embeds_ambiguous",
2312        "A type is embedded by more than one variant of a sum, so `?`'s conversion would be ambiguous.",
2313    ),
2314    d(
2315        "bynk.types.embeds_unknown_variant",
2316        "An `embeds … as V` clause names a variant the sum does not declare.",
2317    ),
2318    d(
2319        "bynk.types.embeds_variant_shape",
2320        "An `embeds E as V` target variant must have exactly one payload field, of type `E`.",
2321    ),
2322    dg(
2323        "bynk.types.empty_refinement",
2324        "A refinement admits no values (contradictory predicates).",
2325        &["refinement"],
2326    ),
2327    dg(
2328        "bynk.types.err_value_mismatch",
2329        "An `Err` payload has the wrong type.",
2330        &["err_expr"],
2331    ),
2332    d(
2333        "bynk.types.extensible_match_needs_wildcard",
2334        "A `match` covers an extensible standard-library enum (`FetchError`, `Method`) without a wildcard; it may gain variants in a minor release.",
2335    ),
2336    dg(
2337        "bynk.types.field_access_on_non_record",
2338        "Field access on a value that is not a record.",
2339        &["field_access"],
2340    ),
2341    dg(
2342        "bynk.types.field_refinement_not_base",
2343        "An inline field refinement requires a base or refined type.",
2344        &["record_field"],
2345    ),
2346    dg(
2347        "bynk.types.field_value_mismatch",
2348        "A record field was given a value of the wrong type.",
2349        &["record_construction"],
2350    ),
2351    dg(
2352        "bynk.types.function_at_boundary",
2353        "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.",
2354        &["function_type_ref"],
2355    ),
2356    dg(
2357        "bynk.types.guard_not_bool",
2358        "A match-arm `if` guard is not a `Bool` expression.",
2359        &["match_arm"],
2360    ),
2361    d(
2362        "bynk.types.held_at_boundary",
2363        "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).",
2364    ),
2365    d(
2366        "bynk.types.held_not_comparable",
2367        "A held value (`Connection[F]`) is compared with `==`/`!=` — held values have identity, not value-equality (§2.9.3, real-time track slice 2).",
2368    ),
2369    dg(
2370        "bynk.types.if_branch_mismatch",
2371        "The branches of an `if` have different types.",
2372        &["if_expr"],
2373    ),
2374    dg(
2375        "bynk.types.if_non_bool_cond",
2376        "An `if` condition is not a `Bool`.",
2377        &["if_expr"],
2378    ),
2379    dg(
2380        "bynk.types.if_without_else_requires_unit",
2381        "An `if` with no `else` branch has a non-unit then-branch; the missing else defaults to `()`, so the branch must be `()` or `Effect[()]`.",
2382        &["if_expr"],
2383    ),
2384    d(
2385        "bynk.types.interpolation_non_scalar",
2386        "An interpolation hole holds a value with no string form.",
2387    ),
2388    dg(
2389        "bynk.types.invalid_regex",
2390        "A `Matches` predicate contains an invalid regular expression.",
2391        &["refinement"],
2392    ),
2393    dg(
2394        "bynk.types.inverted_range",
2395        "An `InRange` predicate has its bounds inverted.",
2396        &["refinement"],
2397    ),
2398    dg(
2399        "bynk.types.is_base_mismatch",
2400        "An `is` refinement check is applied to a value of the wrong base type.",
2401        &["is_expr"],
2402    ),
2403    dg(
2404        "bynk.types.is_literal_pattern",
2405        "A literal was used on the right of `is`; `is` tests type/refinement, not value equality (use `==`).",
2406        &["is_expr"],
2407    ),
2408    dg(
2409        "bynk.types.is_non_sum",
2410        "`is` was applied to a value that is not a sum type.",
2411        &["is_expr"],
2412    ),
2413    dg(
2414        "bynk.types.is_refined_pattern",
2415        "A refined (`where`) pattern was used on the right of `is`; refined patterns are `match`-only.",
2416        &["is_expr"],
2417    ),
2418    dg(
2419        "bynk.types.is_unknown_variant",
2420        "`is` names a variant the type does not have.",
2421        &["is_expr"],
2422    ),
2423    dg(
2424        "bynk.types.json_uncodable",
2425        "A `Json.encode`/`Json.decode` target type cannot pass through the typed JSON codec (functions, effects, error builtins).",
2426        &["method_call"],
2427    ),
2428    dg(
2429        "bynk.types.key_not_orderable",
2430        "A `sortBy`/`min`/`max` key function does not return an orderable type (`Int`, `Float`, `String`, `Duration`, or `Instant`).",
2431        &[],
2432    ),
2433    dg(
2434        "bynk.types.lambda_mismatch",
2435        "A lambda's parameter count, parameter annotations, or body type do not match the expected function type.",
2436        &["lambda_expr"],
2437    ),
2438    dg(
2439        "bynk.types.let_annotation_mismatch",
2440        "A `let` value does not match its type annotation.",
2441        &["let_stmt"],
2442    ),
2443    dg(
2444        "bynk.types.list_element_mismatch",
2445        "A list-literal element has a different type from the list's element type.",
2446        &["list_literal"],
2447    ),
2448    dg(
2449        "bynk.types.match_arm_mismatch",
2450        "A `match` arm has a different type from the others.",
2451        &["match_arm"],
2452    ),
2453    dg(
2454        "bynk.types.match_non_sum_discriminant",
2455        "`match` was applied to a value that is not a sum type.",
2456        &["match_expr"],
2457    ),
2458    dg(
2459        "bynk.types.method_arity",
2460        "A method was called with the wrong number of arguments.",
2461        &["method_call"],
2462    ),
2463    dg(
2464        "bynk.types.method_not_found",
2465        "Called a method the type does not have.",
2466        &["method_call"],
2467    ),
2468    dg(
2469        "bynk.types.method_on_non_named_type",
2470        "A method was called on a built-in type that has no methods.",
2471        &["method_call"],
2472    ),
2473    dg(
2474        "bynk.types.mixed_pattern_bindings",
2475        "A pattern mixes named and positional bindings.",
2476        &["variant_pattern"],
2477    ),
2478    dg(
2479        "bynk.types.negative_length",
2480        "A length predicate was given a negative value.",
2481        &["refinement"],
2482    ),
2483    dg(
2484        "bynk.types.no_numeric_coercion",
2485        "`Int` and `Float` were mixed without an explicit conversion — in an operation or in refinement bounds.",
2486        &["binary_expr", "refinement"],
2487    ),
2488    dg(
2489        "bynk.types.non_exhaustive_match",
2490        "A `match` does not cover every variant.",
2491        &["match_expr"],
2492    ),
2493    d(
2494        "bynk.types.not_comparable",
2495        "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).",
2496    ),
2497    dg(
2498        "bynk.types.ok_value_mismatch",
2499        "An `Ok` payload has the wrong type.",
2500        &["ok_expr"],
2501    ),
2502    dg(
2503        "bynk.types.opaque_raw_outside",
2504        "`.raw` on an opaque type was used outside its defining commons.",
2505        &["field_access"],
2506    ),
2507    dg(
2508        "bynk.types.opaque_unsafe_outside",
2509        "`.unsafe` on an opaque type was used outside its defining context.",
2510        &["field_access"],
2511    ),
2512    dg(
2513        "bynk.types.or_pattern_binding_mismatch",
2514        "An or-pattern's alternatives don't all bind the same set of names.",
2515        &["match_arm", "is_expr"],
2516    ),
2517    dg(
2518        "bynk.types.or_pattern_type_mismatch",
2519        "An or-pattern's alternatives give a shared binding different types (or refinements).",
2520        &["match_arm", "is_expr"],
2521    ),
2522    dg(
2523        "bynk.types.pattern_arity",
2524        "A pattern binds the wrong number of payload fields.",
2525        &["variant_pattern"],
2526    ),
2527    dg(
2528        "bynk.types.pattern_type_mismatch",
2529        "A pattern's type does not match the matched value.",
2530        &["variant_pattern"],
2531    ),
2532    dg(
2533        "bynk.types.polynomial_regex",
2534        "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.",
2535        &["refinement"],
2536    ),
2537    warn(dg(
2538        "bynk.types.polynomial_regex_capped",
2539        "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).",
2540        &["refinement"],
2541    )),
2542    dg(
2543        "bynk.types.predicate_base_mismatch",
2544        "A predicate does not apply to the type's base (e.g. a string predicate on an `Int`).",
2545        &["refinement"],
2546    ),
2547    d(
2548        "bynk.types.query_at_boundary",
2549        "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).",
2550    ),
2551    dg(
2552        "bynk.types.question_error_mismatch",
2553        "`?` propagates an error type incompatible with the function's.",
2554        &["question_expr"],
2555    ),
2556    dg(
2557        "bynk.types.question_on_non_result",
2558        "`?` was applied to a non-`Result` value.",
2559        &["question_expr"],
2560    ),
2561    dg(
2562        "bynk.types.question_option_outside_http",
2563        "`?` lifts an `Option` only inside a handler returning `HttpResult` (`None` becomes `NotFound`); elsewhere use `.okOr(err)`.",
2564        &["question_expr"],
2565    ),
2566    dg(
2567        "bynk.types.question_outside_result",
2568        "`?` used in a function that does not return a `Result`.",
2569        &["question_expr"],
2570    ),
2571    d(
2572        "bynk.types.return_mismatch",
2573        "A returned value does not match the declared return type.",
2574    ),
2575    dg(
2576        "bynk.types.some_value_mismatch",
2577        "A `Some` payload has the wrong type.",
2578        &["some_expr"],
2579    ),
2580    d(
2581        "bynk.types.stream_at_boundary",
2582        "A `Stream` type 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).",
2583    ),
2584    d(
2585        "bynk.types.stream_not_comparable",
2586        "A `Stream` value is compared with `==`/`!=` — a stream is a live value-over-time source, not a comparable value (real-time track slice 0).",
2587    ),
2588    d(
2589        "bynk.types.type_mismatch",
2590        "Two types that were required to match did not.",
2591    ),
2592    dg(
2593        "bynk.types.uninferable_element_type",
2594        "An empty `[]` (or `List.empty()` / `Map.empty()`) has no expected type to infer its element type from.",
2595        &["list_literal"],
2596    ),
2597    dg(
2598        "bynk.types.unkeyable_distinct",
2599        "A `distinct`/`distinctBy` element or key is not value-keyable (`String`, `Int`, or a refined/opaque type over them).",
2600        &[],
2601    ),
2602    dg(
2603        "bynk.types.unkeyable_map_key",
2604        "A `Map` key type is not value-keyable (`String`, `Int`, or a refined/opaque type over them).",
2605        &["generic_type_ref"],
2606    ),
2607    dg(
2608        "bynk.types.unknown_field",
2609        "Referenced a field the record type does not declare.",
2610        &["field_access"],
2611    ),
2612    dg(
2613        "bynk.types.unknown_pattern_field",
2614        "A pattern names a field the variant does not have.",
2615        &["variant_pattern"],
2616    ),
2617    dg(
2618        "bynk.types.unknown_static_member",
2619        "Referenced an unknown static member on a type.",
2620        &["field_access"],
2621    ),
2622    dg(
2623        "bynk.types.unknown_variant_in_pattern",
2624        "A pattern names a variant the sum type does not have.",
2625        &["variant_pattern"],
2626    ),
2627    dg(
2628        "bynk.types.unreachable_arm",
2629        "A `match` arm is unreachable.",
2630        &["match_arm"],
2631    ),
2632    d(
2633        "bynk.types.variant_arity",
2634        "A variant constructor got the wrong number of payload values.",
2635    ),
2636    d(
2637        "bynk.types.variant_missing_payload",
2638        "A variant requiring a payload was used without one.",
2639    ),
2640    d(
2641        "bynk.types.variant_payload_mismatch",
2642        "A variant payload has the wrong type.",
2643    ),
2644    dg(
2645        "bynk.uses.name_conflict",
2646        "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.",
2647        &["uses_decl"],
2648    ),
2649    dg(
2650        "bynk.uses.self_reference",
2651        "A commons `uses` itself.",
2652        &["uses_decl"],
2653    ),
2654    dg(
2655        "bynk.uses.target_is_context",
2656        "`uses` targets a context instead of a commons.",
2657        &["uses_decl"],
2658    ),
2659    dg(
2660        "bynk.uses.unknown_commons",
2661        "`uses` names a commons that does not exist.",
2662        &["uses_decl"],
2663    ),
2664    dg(
2665        "bynk.val.agent_not_generable",
2666        "A `for all`/`Val` cannot generate an agent — fabricated agent states need not be reachable.",
2667        &["for_all"],
2668    ),
2669    dg(
2670        "bynk.val.arity",
2671        "`Val[T]` was given the wrong number of pin arguments.",
2672        &["val_expr"],
2673    ),
2674    dg(
2675        "bynk.val.literal_violates",
2676        "A pinned `Val[T]` value violates the type's refinement.",
2677        &["val_expr"],
2678    ),
2679    dg(
2680        "bynk.val.needs_pin",
2681        "A bare `Val[T]` cannot generate a value (e.g. a `Matches` string); pin one.",
2682        &["val_expr"],
2683    ),
2684    dg(
2685        "bynk.val.outside_test",
2686        "`Val[T]` was used outside a test case body.",
2687        &["val_expr"],
2688    ),
2689    dg(
2690        "bynk.val.pin_not_literal",
2691        "A `Val[T]` pin argument is not a compile-time literal.",
2692        &["val_expr"],
2693    ),
2694    dg(
2695        "bynk.val.pin_unsupported",
2696        "A pin was given for a type kind that does not support pinning.",
2697        &["val_expr"],
2698    ),
2699    dg(
2700        "bynk.val.unknown_type",
2701        "`Val[T]` names a type that does not resolve.",
2702        &["val_expr"],
2703    ),
2704    dg(
2705        "bynk.val.unsupported_kind",
2706        "`Val[T]` cannot fabricate a value for this kind of type.",
2707        &["val_expr"],
2708    ),
2709    d(
2710        "bynk.wasm.panic",
2711        "The in-browser compiler panicked internally (a compiler bug, reported as a diagnostic instead of crashing the page).",
2712    ),
2713    d(
2714        "bynk.wasm.strip_failed",
2715        "The in-browser compiler could not strip the emitted TypeScript to JavaScript.",
2716    ),
2717    d(
2718        "bynk.ws.message_frame_param",
2719        "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).",
2720    ),
2721    d(
2722        "bynk.ws.open_given_unsupported",
2723        "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).",
2724    ),
2725    d(
2726        "bynk.ws.open_transfer_shape",
2727        "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).",
2728    ),
2729    d(
2730        "bynk.ws.route_param_mismatch",
2731        "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).",
2732    ),
2733];
2734
2735/// A diagnostic with no single governing grammar construct. `Error` severity.
2736const fn d(code: &'static str, summary: &'static str) -> DiagnosticInfo {
2737    DiagnosticInfo {
2738        code,
2739        summary,
2740        grammar_symbol: &[],
2741        severity: Severity::Error,
2742    }
2743}
2744
2745/// A diagnostic that constrains one or more grammar productions. `Error` severity.
2746const fn dg(
2747    code: &'static str,
2748    summary: &'static str,
2749    grammar_symbol: &'static [&'static str],
2750) -> DiagnosticInfo {
2751    DiagnosticInfo {
2752        code,
2753        summary,
2754        grammar_symbol,
2755        severity: Severity::Error,
2756    }
2757}
2758
2759/// Downgrades a [`d`]/[`dg`]-built entry to `Warning` severity (ADR 0117) —
2760/// non-failing, surfaced alongside a clean build. Its call sites here are
2761/// the single source of truth [`crate::error::Severity::for_error`] reads.
2762const fn warn(mut info: DiagnosticInfo) -> DiagnosticInfo {
2763    info.severity = Severity::Warning;
2764    info
2765}
2766
2767/// The category segment of a code (the part between the first two dots), e.g.
2768/// `"types"` for `"bynk.types.type_mismatch"`.
2769pub fn category(code: &str) -> &str {
2770    code.split('.').nth(1).unwrap_or("")
2771}
2772
2773/// A human-readable heading for a category segment.
2774fn category_title(cat: &str) -> &'static str {
2775    match cat {
2776        "agent" | "agents" => "Agents",
2777        "asset" => "Static assets",
2778        "boundary" => "Boundaries",
2779        "capability" => "Capabilities",
2780        "consumes" => "Consumes",
2781        "context" => "Contexts",
2782        "contract" => "Contracts",
2783        "cron" => "Cron",
2784        "effect" => "Effects",
2785        "expect" => "Expectations",
2786        "exports" => "Exports",
2787        "given" => "Given capabilities",
2788        "http" => "HTTP",
2789        "lex" => "Lexer",
2790        "messages" => "Message bundles",
2791        "mock" => "Mocks (collaborators)",
2792        "observe" => "Observation",
2793        "parse" => "Parser",
2794        "project" => "Project",
2795        "property" => "Properties (generative tests)",
2796        "provider" => "Providers",
2797        "queue" => "Queue",
2798        "record_spread" => "Record spread",
2799        "refine" => "Refinement",
2800        "resolve" => "Resolution",
2801        "service" => "Services",
2802        "stability" => "Stability",
2803        "suite" => "Suites and cases",
2804        "transition" => "Transitions (step invariants)",
2805        "types" => "Type checking",
2806        "uses" => "Uses",
2807        "val" => "Value fabrication",
2808        _ => "Other",
2809    }
2810}
2811
2812/// Render the diagnostic index as a Markdown reference page, grouped by
2813/// category. This is the generator behind
2814/// `site/src/content/docs/book/reference/diagnostics.md`.
2815pub fn render_markdown() -> String {
2816    use std::collections::BTreeMap;
2817
2818    // Group codes by their category title, preserving sorted code order.
2819    let mut by_category: BTreeMap<&str, Vec<&DiagnosticInfo>> = BTreeMap::new();
2820    for info in REGISTRY {
2821        by_category
2822            .entry(category_title(category(info.code)))
2823            .or_default()
2824            .push(info);
2825    }
2826
2827    let mut out = String::new();
2828    out.push_str("# Diagnostic index\n\n");
2829    out.push_str(
2830        "<!-- GENERATED FILE — do not edit by hand.\n     \
2831         Source: bynkc/src/diagnostics.rs (`render_markdown`).\n     \
2832         Regenerate with: BYNK_BLESS=1 cargo test -p bynkc --test diagnostics_registry -->\n\n",
2833    );
2834    out.push_str(
2835        "Every diagnostic code the compiler can emit, with a one-line summary of \
2836         the cause, grouped by category. For step-by-step cause-and-fix guidance \
2837         on the most common ones, see the [troubleshooting guides](../troubleshooting/index.md). \
2838         For a code with a curated explanation, `bynk explain <code>` prints it in a \
2839         terminal, and in VS Code the diagnostic's **Explain** quick fix (or \
2840         **Bynk: Explain Diagnostic Code…**) shows the same text in a panel, offline.\n\n",
2841    );
2842    out.push_str(&format!(
2843        "There are **{}** codes in total.\n",
2844        REGISTRY.len()
2845    ));
2846
2847    for (title, infos) in &by_category {
2848        out.push_str(&format!("\n## {title}\n\n"));
2849        out.push_str("| Code | Summary | Construct | Severity |\n|---|---|---|---|\n");
2850        for info in infos {
2851            // The construct column deep-links each governing production to its
2852            // entry in the annotated grammar reference; generated from
2853            // `grammar_symbol` (each value is an embeddable rule, so the
2854            // `#rule-<raw>` anchor resolves — enforced in diagnostics_registry).
2855            let construct = info
2856                .grammar_symbol
2857                .iter()
2858                .map(|sym| format!("[`{sym}`](grammar.md#rule-{sym})"))
2859                .collect::<Vec<_>>()
2860                .join(", ");
2861            // A curated (`bynk explain`-able) code links to its Book concept
2862            // page; the in-site link is validated by the site's link checker,
2863            // so a moved page or renamed anchor fails the build (#853). Codes
2864            // without an explanation render as plain inline code.
2865            let code_cell = match explain(info.code) {
2866                Some(e) => format!("[`{}`]({})", info.code, e.in_site_link()),
2867                None => format!("`{}`", info.code),
2868            };
2869            // ADR 0117/finding #50: every code's severity, straight from the
2870            // registry — `Error` (the overwhelming majority) renders as "—"
2871            // to keep the common case unobtrusive; only a `warn`-built entry
2872            // shows "Warning".
2873            let severity = match info.severity {
2874                Severity::Error => "—",
2875                Severity::Warning => "Warning",
2876            };
2877            out.push_str(&format!(
2878                "| {} | {} | {} | {} |\n",
2879                code_cell, info.summary, construct, severity
2880            ));
2881        }
2882    }
2883
2884    out
2885}
2886
2887/// Invert the registry into a `{ "<rule>": [ { code, summary }, … ], … }` map,
2888/// serialised as pretty JSON with sorted keys and sorted codes. Only rules with
2889/// at least one diagnostic appear. This is the generator behind
2890/// `docs/grammar-semantics.json`, which the `{{#grammar-semantics <rule>}}`
2891/// preprocessor directive consumes.
2892pub fn render_grammar_semantics_json() -> String {
2893    use std::collections::BTreeMap;
2894
2895    // REGISTRY is sorted by code, so each rule's vector comes out code-sorted;
2896    // the BTreeMap gives sorted rule names.
2897    let mut by_symbol: BTreeMap<&str, Vec<&DiagnosticInfo>> = BTreeMap::new();
2898    for info in REGISTRY {
2899        for sym in info.grammar_symbol {
2900            by_symbol.entry(sym).or_default().push(info);
2901        }
2902    }
2903
2904    let mut map = serde_json::Map::new();
2905    map.insert(
2906        "_generated".to_string(),
2907        serde_json::Value::String(
2908            "Generated from the grammar_symbol field of bynkc/src/diagnostics.rs. \
2909             Do not edit by hand. Regenerate with: BYNK_BLESS=1 cargo test -p \
2910             bynkc --test diagnostics_registry"
2911                .to_string(),
2912        ),
2913    );
2914    for (sym, infos) in by_symbol {
2915        let arr: Vec<serde_json::Value> = infos
2916            .iter()
2917            .map(|info| serde_json::json!({ "code": info.code, "summary": info.summary }))
2918            .collect();
2919        map.insert(sym.to_string(), serde_json::Value::Array(arr));
2920    }
2921
2922    let mut s =
2923        serde_json::to_string_pretty(&serde_json::Value::Object(map)).expect("serialise semantics");
2924    s.push('\n');
2925    s
2926}