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`). The category shown in the
12//! generated reference is derived from the second dotted segment of the code;
13//! the grammar weave (`docs/grammar-semantics.json`, the
14//! `{{#grammar-semantics}}` directive, and the diagnostics page's Construct
15//! column) is generated from `grammar_symbol`.
16
17/// One documented diagnostic: its stable code and a one-line summary of the
18/// cause. Richer "cause and fix" material for the common diagnostics lives in
19/// the troubleshooting how-to guides.
20pub struct DiagnosticInfo {
21    pub code: &'static str,
22    pub summary: &'static str,
23    /// The grammar production(s) this diagnostic constrains, by `tree-sitter`
24    /// rule name (e.g. `http_handler`). This is the single source of the
25    /// "static semantics" weave: a grammar-reference entry embeds the
26    /// diagnostics for a rule via `{{#grammar-semantics <rule>}}`, generated
27    /// from here. Empty for diagnostics with no single governing construct
28    /// (e.g. `bynk.boundary.structural_mismatch`). Every non-empty name is
29    /// checked against the grammar by `tests/diagnostics_registry.rs`.
30    pub grammar_symbol: &'static [&'static str],
31}
32
33/// The hosted Book, the stable target for `codeDescription` links (#853,
34/// DECISION C). No trailing slash — an [`Explain::page`] path (which begins
35/// with `/`) is appended directly.
36pub const BOOK_BASE_URL: &str = "https://bynk-lang.org";
37
38/// A curated, offline-complete explanation of a diagnostic code (#853).
39///
40/// This is the compiler-owned `code → { blurb, href }` table (DECISION A): the
41/// `blurb`/`example` are the offline answer `bynk explain` prints, while
42/// `page`/`anchor` compose the hosted-Book href the LSP hangs off the code as a
43/// clickable `codeDescription` link (DECISION C). Only the highest-traffic,
44/// newcomer-facing codes are curated; every other code simply has no entry and
45/// falls back gracefully — no link, no error (DECISION B).
46///
47/// The mapping points at *existing* Book concept pages rather than duplicating
48/// their prose; the reference-page generator ([`render_markdown`]) links every
49/// explained code at its `page`/`anchor` as an in-site link, so
50/// `astro build`'s link checker fails if a page moves or an anchor is renamed —
51/// the doc-drift guard the rest of the site already relies on.
52pub struct Explain {
53    /// The diagnostic code this explains. Must be a real [`REGISTRY`] code
54    /// (enforced by `tests/diagnostics_registry.rs`).
55    pub code: &'static str,
56    /// A longer-form paragraph: what the rule is and, crucially, *why* it
57    /// exists. This is the offline-complete answer — useful without network.
58    pub blurb: &'static str,
59    /// A minimal example of the violation and its fix.
60    pub example: &'static str,
61    /// The target Book page as a site-root-relative path, no extension and no
62    /// trailing slash, e.g. `/book/reference/types`. Used verbatim as an
63    /// in-site link by [`render_markdown`] (so the site link checker guards it)
64    /// and prefixed with [`BOOK_BASE_URL`] for the hosted `codeDescription`.
65    pub page: &'static str,
66    /// The in-page heading anchor (slug), or `""` for the page top.
67    pub anchor: &'static str,
68}
69
70impl Explain {
71    /// The hosted-Book URL for this explanation: [`BOOK_BASE_URL`] + the page
72    /// (Starlight serves pages with a trailing slash) + `#anchor` when set.
73    pub fn href(&self) -> String {
74        let mut url = format!("{BOOK_BASE_URL}{}/", self.page);
75        if !self.anchor.is_empty() {
76            url.push('#');
77            url.push_str(self.anchor);
78        }
79        url
80    }
81
82    /// The site-root-relative link used inside the generated reference page,
83    /// e.g. `/book/reference/types/#record-types`. Same shape as [`href`], sans
84    /// the host, so the in-site link checker resolves it.
85    ///
86    /// [`href`]: Explain::href
87    pub fn in_site_link(&self) -> String {
88        let mut link = format!("{}/", self.page);
89        if !self.anchor.is_empty() {
90            link.push('#');
91            link.push_str(self.anchor);
92        }
93        link
94    }
95}
96
97/// The curated explanations, keyed by code (DECISION B: highest-traffic,
98/// newcomer-facing codes first). Kept sorted by code; every `code` must be a
99/// real [`REGISTRY`] entry and every `page` an existing Book page — both
100/// enforced by `tests/diagnostics_registry.rs`.
101pub const EXPLANATIONS: &[Explain] = &[
102    Explain {
103        code: "bynk.given.undeclared_capability",
104        blurb: "A handler may only use a capability it has itself declared with \
105                `given`. Effects in Bynk are explicit: the `given` clause is the \
106                handler's honest, checkable statement of every capability it \
107                reaches for, so a reader (and the compiler) can see a handler's \
108                full reach from its signature alone. Using a capability that is \
109                not in `given` is the missing half of that contract.",
110        example: "on get \"/now\" -> Text {           // ✗ uses Clock without declaring it\n    \
111                    Clock.now()\n}\n\n\
112                  on get \"/now\" given Clock -> Text { // ✓ declared, then used\n    \
113                    Clock.now()\n}",
114        page: "/book/guides/effects-and-capabilities/understand-the-capability-model",
115        anchor: "",
116    },
117    Explain {
118        code: "bynk.given.unknown_capability",
119        blurb: "A `given` clause names a capability that no provider declares. A \
120                capability is a typed interface to the outside world; it has to be \
121                *declared* (as a `capability`, or brought in from a consumed \
122                context) before a handler can ask for it. This usually means a \
123                typo in the capability name, or a missing `uses`/`consumes` that \
124                would bring the capability into scope.",
125        example: "on get \"/\" given Clok -> Text { … }  // ✗ no capability named `Clok`\n\n\
126                  on get \"/\" given Clock -> Text { … }  // ✓ matches the declared capability",
127        page: "/book/reference/capabilities",
128        anchor: "declaring-a-capability",
129    },
130    Explain {
131        code: "bynk.resolve.missing_field",
132        blurb: "A record must be constructed with every one of its fields. Bynk \
133                records have no defaults and no partial construction: a value of a \
134                record type is only valid once all its fields are present, so a \
135                downstream reader never has to wonder whether a field was set. \
136                Omitting a field is therefore an error, not a fill-in-later.",
137        example: "type User = { name: Text, age: Int }\n\n\
138                  User { name: \"Ada\" }            // ✗ missing `age`\n\
139                  User { name: \"Ada\", age: 36 }   // ✓ every field present",
140        page: "/book/reference/types",
141        anchor: "record-types",
142    },
143    Explain {
144        code: "bynk.resolve.unknown_field",
145        blurb: "A field access names a field the record type does not have. A \
146                record's fields are fixed by its type declaration; only those \
147                names exist on the value. This is usually a typo in the field \
148                name, or an access meant for a different type.",
149        example: "type User = { name: Text }\n\n\
150                  user.nmae   // ✗ no field `nmae`\n\
151                  user.name   // ✓ the declared field",
152        page: "/book/reference/types",
153        anchor: "record-types",
154    },
155    Explain {
156        code: "bynk.resolve.unknown_name",
157        blurb: "A name was referenced that is not in scope. Every name in Bynk \
158                must be introduced before use — as a `let` binding, a parameter, \
159                a `fn`, a type, or a member brought in through `uses`/`consumes`. \
160                An unknown name is typically a typo, a missing declaration, or a \
161                reference to something defined in a module that has not been \
162                brought into scope.",
163        example: "let greeting = \"hi\"\n\
164                  greetng          // ✗ no name `greetng` in scope\n\
165                  greeting         // ✓ the bound name",
166        page: "/book/guides/program-structure/how-a-program-is-shaped",
167        anchor: "",
168    },
169    Explain {
170        code: "bynk.resolve.unknown_type",
171        blurb: "A type name was referenced that does not exist. Types must be \
172                declared (with `type`), be one of Bynk's built-in types, or be \
173                brought into scope from another module before they can be named. \
174                An unknown type is usually a typo or a missing declaration/import.",
175        example: "fn greet(u: Usr) -> Text { … }   // ✗ no type `Usr`\n\
176                  fn greet(u: User) -> Text { … }  // ✓ the declared type",
177        page: "/book/reference/types",
178        anchor: "",
179    },
180];
181
182/// The curated explanation for a diagnostic `code`, or `None` when the code has
183/// no explanation yet (the designed graceful-fallback state, DECISION B).
184pub fn explain(code: &str) -> Option<&'static Explain> {
185    EXPLANATIONS.iter().find(|e| e.code == code)
186}
187
188/// Every diagnostic code the compiler emits, sorted by code.
189pub const REGISTRY: &[DiagnosticInfo] = &[
190    d(
191        "bynk.actor.bearer_identity_not_string_constructible",
192        "A `Bearer` actor's identity is not a string-constructible type.",
193    ),
194    d(
195        "bynk.actor.bearer_missing_secret",
196        "A `Bearer` actor does not name its signing secret.",
197    ),
198    d(
199        "bynk.actor.binder_shadows_param",
200        "A `by` actor binder collides with a handler parameter of the same name.",
201    ),
202    d(
203        "bynk.actor.by_on_agent",
204        "A `by` actor clause was placed on an agent `on call` handler, which has no actor.",
205    ),
206    d(
207        "bynk.actor.duplicate_sum_scheme",
208        "Two peers in a multi-actor sum share an authentication scheme.",
209    ),
210    d(
211        "bynk.actor.identity_not_sealed",
212        "An actor identity type is not a context-ownable (sealed) value type.",
213    ),
214    d(
215        "bynk.actor.missing_by_on_http",
216        "An HTTP handler lacks the required `by` actor clause.",
217    ),
218    d(
219        "bynk.actor.oidc_identity_not_string_constructible",
220        "An `Oidc` actor's identity is not a string-constructible type.",
221    ),
222    d(
223        "bynk.actor.oidc_missing_audience",
224        "An `Oidc` actor does not name its `audience`.",
225    ),
226    d(
227        "bynk.actor.oidc_missing_issuer",
228        "An `Oidc` actor does not name its `issuer`.",
229    ),
230    d(
231        "bynk.actor.oidc_missing_jwks",
232        "An `Oidc` actor does not name its `jwks` endpoint.",
233    ),
234    d(
235        "bynk.actor.oidc_not_in_sum",
236        "An `Oidc` actor appears as a member of a multi-actor sum.",
237    ),
238    d(
239        "bynk.actor.outside_context",
240        "An `actor` was declared outside a context (e.g. in a commons).",
241    ),
242    d(
243        "bynk.actor.refinement_base_unsupported",
244        "A refinement actor's base is not a `Bearer` actor (no claims to authorise against).",
245    ),
246    d(
247        "bynk.actor.refinement_in_sum",
248        "A refinement actor appears as a member of a multi-actor sum.",
249    ),
250    d(
251        "bynk.actor.refinement_predicate_unsupported",
252        "A refinement actor's `where` predicate is outside the closed claim-predicate set.",
253    ),
254    d(
255        "bynk.actor.scheme_not_admissible",
256        "An actor's scheme is not admissible on this handler's protocol.",
257    ),
258    d(
259        "bynk.actor.signature_identity_unsupported",
260        "A `Signature` actor declared an `identity`, which is not yet supported.",
261    ),
262    d(
263        "bynk.actor.signature_missing_header",
264        "A `Signature` actor does not name its signature header.",
265    ),
266    d(
267        "bynk.actor.signature_missing_secret",
268        "A `Signature` actor does not name its signing secret.",
269    ),
270    d(
271        "bynk.actor.signature_requires_body",
272        "A `Signature` handler does not take a `body` parameter.",
273    ),
274    d(
275        "bynk.actor.signature_tolerance_without_timestamp",
276        "A `Signature` actor set `tolerance` without a `timestamp` header.",
277    ),
278    d(
279        "bynk.actor.sum_requires_binder",
280        "A multi-actor sum `by` clause has no binder to match the resolved actor.",
281    ),
282    d(
283        "bynk.actor.unknown_actor",
284        "A handler's `by` clause names an actor that is not declared.",
285    ),
286    d(
287        "bynk.actor.unknown_scheme",
288        "An actor declares an authentication scheme that is not compiler-known.",
289    ),
290    d(
291        "bynk.actor.unreachable_sum_arm",
292        "A multi-actor sum has an arm unreachable after a catch-all (`None`) peer.",
293    ),
294    dg(
295        "bynk.adapter.consumes_context",
296        "An `adapter` consumed a context; adapter dependencies are adapter-to-adapter.",
297        &["consumes_decl"],
298    ),
299    dg(
300        "bynk.adapter.consumes_requires_selection",
301        "An `adapter` used a whole-unit or aliased `consumes`; adapters must select capabilities with `consumes U { Cap, … }`.",
302        &["consumes_decl"],
303    ),
304    dg(
305        "bynk.adapter.disallowed_item",
306        "An `adapter` declared a `service`, `agent`, or other item it may not contain.",
307        &["adapter_decl"],
308    ),
309    dg(
310        "bynk.adapter.duplicate_binding",
311        "An `adapter` declared more than one `binding` clause.",
312        &["binding_decl"],
313    ),
314    dg(
315        "bynk.adapter.no_binding",
316        "An `adapter` declares an external provider but no `binding` module to supply it.",
317        &["adapter_decl"],
318    ),
319    dg(
320        "bynk.adapter.provider_has_body",
321        "A provider inside an `adapter` has a Bynk body; adapter providers must be external.",
322        &["provider_decl"],
323    ),
324    dg(
325        "bynk.agent.construction_arity",
326        "An agent was constructed with the wrong number of key arguments.",
327        &["agent_decl"],
328    ),
329    dg(
330        "bynk.agent.handler_arity",
331        "An agent handler was called with the wrong number of arguments.",
332        &["agent_decl"],
333    ),
334    dg(
335        "bynk.agent.handler_not_found",
336        "Called a handler the agent does not declare.",
337        &["agent_decl"],
338    ),
339    dg(
340        "bynk.agent.key_mismatch",
341        "An agent key argument has the wrong type.",
342        &["agent_decl"],
343    ),
344    dg(
345        "bynk.agent.outside_context",
346        "An `agent` was declared outside a context.",
347        &["agent_decl"],
348    ),
349    dg(
350        "bynk.agent.return_not_effect",
351        "An agent handler's return type is not an `Effect`.",
352        &["agent_decl"],
353    ),
354    dg(
355        "bynk.agents.bad_state_initialiser",
356        "An agent `store` field initialiser is not a static value of the field's type.",
357        &["store_field"],
358    ),
359    dg(
360        "bynk.agents.non_zeroable_state_field",
361        "An agent `store` field has no initialiser and no implicit zero value.",
362        &["store_field"],
363    ),
364    d(
365        "bynk.boundary.structural_mismatch",
366        "Data crossing a context boundary did not match the expected shape.",
367    ),
368    dg(
369        "bynk.capability.op_arity",
370        "A capability operation was called with the wrong number of arguments.",
371        &["capability_decl"],
372    ),
373    dg(
374        "bynk.capability.outside_context",
375        "A `capability` was declared outside a context.",
376        &["capability_decl"],
377    ),
378    dg(
379        "bynk.capability.unknown_operation",
380        "Referenced an operation the capability does not declare.",
381        &["capability_decl"],
382    ),
383    d(
384        "bynk.cell.invalid_target",
385        "A `:=` write targets something that is not a `store Cell` field.",
386    ),
387    d(
388        "bynk.cell.self_reference",
389        "A `:=` right-hand side reads the cell being written (a read-modify-write); use `.update`.",
390    ),
391    dg(
392        "bynk.consumes.alias_conflict",
393        "Two `consumes` aliases collide.",
394        &["consumes_decl"],
395    ),
396    dg(
397        "bynk.consumes.capability_name_clash",
398        "Two flattened `consumes U { Cap }` capabilities collide, or one clashes with a local capability.",
399        &["consumes_decl"],
400    ),
401    dg(
402        "bynk.consumes.in_commons",
403        "`consumes` appears in a `commons` (it is only valid in a context).",
404        &["consumes_decl"],
405    ),
406    dg(
407        "bynk.consumes.name_conflict",
408        "A `consumes` name collides with another name in scope.",
409        &["consumes_decl"],
410    ),
411    dg(
412        "bynk.consumes.self_reference",
413        "A context `consumes` itself.",
414        &["consumes_decl"],
415    ),
416    dg(
417        "bynk.consumes.service_arity",
418        "A consumed service was called with the wrong number of arguments.",
419        &["consumes_decl"],
420    ),
421    dg(
422        "bynk.consumes.target_is_commons",
423        "`consumes` targets a `commons` instead of a context.",
424        &["consumes_decl"],
425    ),
426    dg(
427        "bynk.consumes.unknown_context",
428        "`consumes` names a context that does not exist.",
429        &["consumes_decl"],
430    ),
431    dg(
432        "bynk.consumes.unknown_service",
433        "Called a service the consumed context does not declare.",
434        &["consumes_decl"],
435    ),
436    d(
437        "bynk.context.consumes_cycle",
438        "Contexts form a `consumes` dependency cycle.",
439    ),
440    d(
441        "bynk.context.external_construction",
442        "A context-owned type was constructed from outside that context.",
443    ),
444    dg(
445        "bynk.context.external_provider",
446        "A bodiless (external) provider was declared outside an `adapter`.",
447        &["provider_decl"],
448    ),
449    d(
450        "bynk.context.opaque_inspection",
451        "An opaquely-exported type was inspected from outside its context.",
452    ),
453    d(
454        "bynk.contract.duplicate_name",
455        "A function declares two contract clauses (`requires`/`ensures`) with the same name.",
456    ),
457    d(
458        "bynk.contract.impure_predicate",
459        "A contract predicate uses an effectful or test-only construct; a contract clause must be pure.",
460    ),
461    d(
462        "bynk.contract.not_bool",
463        "A contract predicate does not have type `Bool`.",
464    ),
465    d(
466        "bynk.contract.restated_by_test",
467        "A `case`/`property` merely restates a contract clause already declared at the function; the test is redundant.",
468    ),
469    d(
470        "bynk.contract.result_in_requires",
471        "A precondition (`requires`) references `result`; the return value is only in scope inside an `ensures`.",
472    ),
473    dg(
474        "bynk.cron.bad_params",
475        "A cron handler declares more than one parameter, or a non-`Int` one.",
476        &["cron_handler"],
477    ),
478    dg(
479        "bynk.cron.duplicate_schedule",
480        "Two cron handlers declare the same schedule.",
481        &["cron_handler"],
482    ),
483    dg(
484        "bynk.cron.invalid_schedule",
485        "A cron expression is not five whitespace-separated fields.",
486        &["cron_handler"],
487    ),
488    dg(
489        "bynk.cron.return_not_effect_result",
490        "A cron handler does not return `Effect[Result[(), E]]`.",
491        &["cron_handler"],
492    ),
493    d(
494        "bynk.duration.literal_overflow",
495        "A `Duration` literal (`<int>.<unit>`) exceeds the representable millisecond range.",
496    ),
497    dg(
498        "bynk.effect.bind_in_pure_context",
499        "An `<-` bind was used in a pure (non-effectful) context.",
500        &["effect_let_stmt"],
501    ),
502    dg(
503        "bynk.effect.bind_on_non_effect",
504        "An `<-` bind was applied to a non-`Effect` value.",
505        &["effect_let_stmt"],
506    ),
507    d(
508        "bynk.effect.capability_in_pure_context",
509        "A capability was used in a pure context.",
510    ),
511    d(
512        "bynk.effect.cross_context_in_pure_context",
513        "A cross-context call was made in a pure context.",
514    ),
515    dg(
516        "bynk.effect.do_in_pure_context",
517        "A `do` statement was used in a pure (non-effectful) context.",
518        &["do_stmt"],
519    ),
520    dg(
521        "bynk.effect.do_on_non_effect",
522        "A `do` statement was applied to a non-`Effect` value.",
523        &["do_stmt"],
524    ),
525    dg(
526        "bynk.effect.do_requires_unit",
527        "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.",
528        &["do_stmt"],
529    ),
530    dg(
531        "bynk.effect.fn_value_in_pure_context",
532        "An effectful function value was called in a pure context; like a capability call, it is legal only where the enclosing body is effectful.",
533        &["call"],
534    ),
535    dg(
536        "bynk.expect.not_bool",
537        "`expect` was given a non-`Bool` predicate.",
538        &["expect_expr"],
539    ),
540    dg(
541        "bynk.expect.outside_case",
542        "`expect` was used outside a `case` body.",
543        &["expect_expr"],
544    ),
545    dg(
546        "bynk.exports.capability_not_provided",
547        "An exported capability has no provider in its context.",
548        &["exports_decl"],
549    ),
550    dg(
551        "bynk.exports.conflicting_visibility",
552        "A type is exported with conflicting visibilities.",
553        &["exports_decl"],
554    ),
555    dg(
556        "bynk.exports.duplicate_export",
557        "The same name is exported more than once.",
558        &["exports_decl"],
559    ),
560    dg(
561        "bynk.exports.duplicate_in_clause",
562        "A name appears twice in one `exports` clause.",
563        &["exports_decl"],
564    ),
565    dg(
566        "bynk.exports.undeclared_capability",
567        "`exports capability` names a capability that is not declared.",
568        &["exports_decl"],
569    ),
570    dg(
571        "bynk.exports.undeclared_type",
572        "`exports` names a type that is not declared.",
573        &["exports_decl"],
574    ),
575    dg(
576        "bynk.generics.duplicate_type_param",
577        "A `type` or `fn` declares the same type-parameter name more than once (v0.157, ADR 0183).",
578        &[],
579    ),
580    dg(
581        "bynk.generics.generic_non_record",
582        "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).",
583        &["type_decl"],
584    ),
585    dg(
586        "bynk.generics.generic_record_at_boundary",
587        "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.",
588        &[],
589    ),
590    dg(
591        "bynk.generics.generic_sum_embeds",
592        "A generic sum type carries an `embeds` clause; embedding into a generic sum is not supported (#593).",
593        &["type_decl"],
594    ),
595    dg(
596        "bynk.generics.method_on_generic_type",
597        "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).",
598        &["fn_decl"],
599    ),
600    dg(
601        "bynk.generics.no_bounds",
602        "A type parameter carries a bound (`[A: …]`); bounded generics are not in v0.20a.",
603        &["fn_decl"],
604    ),
605    dg(
606        "bynk.generics.recursive_generic_at_boundary",
607        "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).",
608        &[],
609    ),
610    dg(
611        "bynk.generics.type_arg_count",
612        "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).",
613        &["applied_type_ref"],
614    ),
615    dg(
616        "bynk.generics.type_arg_mismatch",
617        "Inferred or explicit type arguments conflict, have the wrong arity, target a non-generic function, or a type parameter shadows a declared type.",
618        &["call"],
619    ),
620    dg(
621        "bynk.generics.uninferable_type_arg",
622        "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.",
623        &["call"],
624    ),
625    dg(
626        "bynk.given.cross_context_unknown_capability",
627        "`given B.Cap` names a capability the consumed context does not export.",
628        &["given_clause"],
629    ),
630    dg(
631        "bynk.given.undeclared_capability",
632        "A handler uses a capability it did not declare with `given`.",
633        &["given_clause"],
634    ),
635    dg(
636        "bynk.given.unknown_capability",
637        "`given` names a capability that does not exist.",
638        &["given_clause"],
639    ),
640    dg(
641        "bynk.given.unused_capability",
642        "A `given` capability is never used (warning).",
643        &["given_clause"],
644    ),
645    d(
646        "bynk.held.branch_divergence",
647        "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).",
648    ),
649    d(
650        "bynk.held.consume_on_borrow",
651        "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).",
652    ),
653    d(
654        "bynk.held.leak",
655        "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).",
656    ),
657    d(
658        "bynk.held.query_accessor_on_held_map",
659        "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.",
660    ),
661    d(
662        "bynk.held.unsupported_map_op",
663        "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).",
664    ),
665    d(
666        "bynk.held.unsupported_storage",
667        "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).",
668    ),
669    d(
670        "bynk.held.use_after_consume",
671        "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).",
672    ),
673    d(
674        "bynk.history.not_an_agent",
675        "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).",
676    ),
677    d(
678        "bynk.history.not_generable",
679        "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).",
680    ),
681    d(
682        "bynk.history.outside_property",
683        "`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).",
684    ),
685    d(
686        "bynk.history.restates_invariant",
687        "A history property merely re-checks a guarantee a declared `invariant`/`transition` already enforces on every reached state (testing track slice 7, ADR 0155).",
688    ),
689    dg(
690        "bynk.http.body_on_get_or_delete",
691        "A GET or DELETE handler declares a `body` parameter.",
692        &["http_handler"],
693    ),
694    d(
695        "bynk.http.cache_bad_max_age",
696        "A `@cache` annotation's `maxAge` is missing or not a positive `Duration` literal.",
697    ),
698    d(
699        "bynk.http.cache_bad_scope",
700        "A `@cache` annotation's `scope` is not `public` or `private`.",
701    ),
702    d(
703        "bynk.http.cache_duplicate",
704        "A handler carries more than one `@cache` annotation.",
705    ),
706    d(
707        "bynk.http.cache_on_non_get",
708        "A `@cache` annotation is placed on a handler that is not `on http GET`.",
709    ),
710    d(
711        "bynk.http.cache_unknown_arg",
712        "A `@cache` annotation has an argument outside the closed set (`maxAge`/`scope`).",
713    ),
714    d(
715        "bynk.http.cors_invalid_field",
716        "A `cors` policy field (`headers`/`credentials`/`maxAge`) has the wrong value shape.",
717    ),
718    d(
719        "bynk.http.cors_invalid_origins",
720        "A `cors` policy's `origins` is missing, empty, or not a list of string literals.",
721    ),
722    d(
723        "bynk.http.cors_not_http",
724        "A `cors { }` policy appears on a service that is not `from http`.",
725    ),
726    d(
727        "bynk.http.cors_unknown_field",
728        "A `cors { }` policy declares a field outside the closed set.",
729    ),
730    d(
731        "bynk.http.cors_wildcard_credentials",
732        "A `cors` policy combines `credentials: true` with the wildcard origin `[\"*\"]`.",
733    ),
734    dg(
735        "bynk.http.duplicate_route",
736        "Two handlers share the same method and route.",
737        &["http_handler"],
738    ),
739    dg(
740        "bynk.http.extra_param",
741        "A handler parameter is neither a path parameter nor `body`.",
742        &["http_handler"],
743    ),
744    dg(
745        "bynk.http.invalid_path",
746        "An HTTP route path is malformed.",
747        &["http_handler"],
748    ),
749    d(
750        "bynk.http.limit_bad_max_body",
751        "A `@limit` annotation's `maxBody` is missing or not a positive `Int` literal.",
752    ),
753    d(
754        "bynk.http.limit_duplicate",
755        "A handler carries more than one `@limit` annotation.",
756    ),
757    d(
758        "bynk.http.limit_on_bodyless",
759        "A `@limit` annotation is placed on a handler that takes no body (a GET or DELETE).",
760    ),
761    d(
762        "bynk.http.limit_unknown_arg",
763        "A `@limit` annotation has an argument outside the closed set (`maxBody`).",
764    ),
765    d(
766        "bynk.http.limits_invalid_field",
767        "A `limits` policy field (`maxBody`) has the wrong value shape.",
768    ),
769    d(
770        "bynk.http.limits_not_http",
771        "A `limits { }` policy appears on a service that is not `from http`.",
772    ),
773    d(
774        "bynk.http.limits_unknown_field",
775        "A `limits { }` policy declares a field outside the closed set.",
776    ),
777    dg(
778        "bynk.http.path_param_not_stringy",
779        "A path parameter's type is not constructible from a string.",
780        &["http_handler"],
781    ),
782    dg(
783        "bynk.http.reserved_prefix",
784        "A route uses the reserved `/_bynk/` prefix.",
785        &["http_handler"],
786    ),
787    dg(
788        "bynk.http.return_not_effect_http_result",
789        "An HTTP handler does not return `Effect[HttpResult[T]]`.",
790        &["http_handler"],
791    ),
792    d(
793        "bynk.http.security_invalid_field",
794        "A `security` policy field (`hsts`/`nosniff`) has the wrong value shape.",
795    ),
796    d(
797        "bynk.http.security_not_http",
798        "A `security { }` policy appears on a service that is not `from http`.",
799    ),
800    d(
801        "bynk.http.security_unknown_field",
802        "A `security { }` policy declares a field outside the closed set.",
803    ),
804    dg(
805        "bynk.http.unbound_path_param",
806        "A `:name` route segment has no matching handler parameter.",
807        &["http_handler"],
808    ),
809    d(
810        "bynk.http.unknown_handler_annotation",
811        "A handler carries an annotation outside the closed set (`@cache`/`@limit`).",
812    ),
813    d(
814        "bynk.index.bad_argument",
815        "An `@indexed` argument is not a `by: <field>` label.",
816    ),
817    d(
818        "bynk.index.missing",
819        "A query filters a map by equality on a field that is not `@indexed` (a perf-hint warning).",
820    ),
821    d(
822        "bynk.index.unkeyable_key",
823        "An `@indexed(by: k)` field is not value-keyable.",
824    ),
825    d(
826        "bynk.index.unknown_key",
827        "An `@indexed(by: k)` field is not a field of the map's value type.",
828    ),
829    d(
830        "bynk.index.unused",
831        "A declared `@indexed(by: k)` is never used by an equality filter (a hygiene warning).",
832    ),
833    d(
834        "bynk.invariant.cross_agent_reference",
835        "An invariant predicate references another agent; invariants are per-agent.",
836    ),
837    d(
838        "bynk.invariant.duplicate_name",
839        "An agent declares two invariants with the same name.",
840    ),
841    d(
842        "bynk.invariant.impure_predicate",
843        "An invariant predicate uses an effectful or test-only construct.",
844    ),
845    d(
846        "bynk.invariant.not_bool",
847        "An invariant predicate does not have type `Bool`.",
848    ),
849    dg(
850        "bynk.lambda.unannotated_param",
851        "A lambda parameter has no type annotation in a position where no function type is expected to infer it from.",
852        &["lambda_expr"],
853    ),
854    dg(
855        "bynk.lex.bad_escape",
856        "An invalid escape sequence in a string literal.",
857        &["string_literal"],
858    ),
859    dg(
860        "bynk.lex.float_literal_overflow",
861        "A float literal does not fit a finite 64-bit float.",
862        &["float_literal"],
863    ),
864    dg(
865        "bynk.lex.integer_overflow",
866        "An integer literal is out of range.",
867        &["number_literal"],
868    ),
869    dg(
870        "bynk.lex.interpolation_too_deep",
871        "A string interpolation `\\(…)` nests deeper than the lexer's fixed limit.",
872        &["string_literal"],
873    ),
874    d(
875        "bynk.lex.unclosed_doc_block",
876        "A documentation block is not closed.",
877    ),
878    d(
879        "bynk.lex.unexpected_character",
880        "An unexpected character in the source.",
881    ),
882    dg(
883        "bynk.lex.unterminated_interpolation",
884        "An interpolation hole `\\(…)` is not closed on its line.",
885        &["string_literal"],
886    ),
887    dg(
888        "bynk.lex.unterminated_string",
889        "A string literal is not terminated.",
890        &["string_literal"],
891    ),
892    d(
893        "bynk.list.deprecated_function",
894        "A `bynk.list` free function (`map`/`filter`/`find`/`any`/`all`) is deprecated in favour of the `List` method form (warning; auto-fixable).",
895    ),
896    d(
897        "bynk.locale.multiple_message_bundles",
898        "A context consumes `Locale` but its direct `uses` reaches two or more message-bundle commons — there is no single bundle to negotiate against.",
899    ),
900    d(
901        "bynk.messages.format_mismatch",
902        "A code's placeholder is formatted as a different ICU kind (plain/plural/select/number/date) across declared locales.",
903    ),
904    d(
905        "bynk.messages.incomplete",
906        "A locale is missing a code the reference locale declares.",
907    ),
908    d(
909        "bynk.messages.invalid_locale_tag",
910        "A `messages` block's locale tag is not a valid `LocaleTag` (e.g. `messages \"xx\"` where `xx` doesn't match the tag pattern).",
911    ),
912    d(
913        "bynk.messages.malformed_icu_syntax",
914        "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).",
915    ),
916    d(
917        "bynk.messages.missing_locale_dependency",
918        "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.",
919    ),
920    d(
921        "bynk.messages.missing_reference",
922        "A message bundle has no `@reference` block.",
923    ),
924    d(
925        "bynk.messages.multiple_reference",
926        "A message bundle has more than one `@reference` block.",
927    ),
928    d(
929        "bynk.messages.outside_commons",
930        "A `messages` declaration appears outside a commons.",
931    ),
932    d(
933        "bynk.messages.placeholder_mismatch",
934        "A locale's template for a code uses a different set of `{name}` placeholders than the reference locale's.",
935    ),
936    d(
937        "bynk.namespace.reserved",
938        "A user unit is named `bynk` or `bynk.*`; the `bynk` root is reserved for the toolchain.",
939    ),
940    d(
941        "bynk.observe.bad_count",
942        "An observation call count is not a non-negative integer literal (`called once` / `called <n> times`).",
943    ),
944    d(
945        "bynk.observe.impure_with",
946        "A `with` predicate uses an effectful or test-only construct; it must be pure.",
947    ),
948    d(
949        "bynk.observe.not_a_seam",
950        "An observation targets a capability the unit under test does not consume.",
951    ),
952    d(
953        "bynk.observe.outside_case",
954        "An observation appears outside a `case` body.",
955    ),
956    d(
957        "bynk.observe.trace_outside_test",
958        "`trace(Cap.op)` appears outside a `case` body.",
959    ),
960    d(
961        "bynk.observe.unknown_op",
962        "An observation names an operation the capability does not declare.",
963    ),
964    d(
965        "bynk.observe.with_not_bool",
966        "A `with` predicate does not have type `Bool`.",
967    ),
968    dg(
969        "bynk.parse.consumes_after_decls",
970        "`consumes` appears after other declarations.",
971        &["consumes_decl"],
972    ),
973    d(
974        "bynk.parse.dangling_handler_annotation",
975        "A handler-position annotation (e.g. `@cache`) is not followed by an `on` handler.",
976    ),
977    dg(
978        "bynk.parse.duplicate_cors",
979        "A service declares more than one `cors { }` policy.",
980        &["service_decl"],
981    ),
982    dg(
983        "bynk.parse.duplicate_limits",
984        "A service declares more than one `limits { }` policy.",
985        &["service_decl"],
986    ),
987    dg(
988        "bynk.parse.duplicate_security",
989        "A service declares more than one `security { }` policy.",
990        &["service_decl"],
991    ),
992    dg(
993        "bynk.parse.empty_agent",
994        "An `agent` body is empty.",
995        &["agent_decl"],
996    ),
997    dg(
998        "bynk.parse.empty_capability",
999        "A `capability` body is empty.",
1000        &["capability_decl"],
1001    ),
1002    d(
1003        "bynk.parse.empty_interpolation",
1004        "An interpolation hole `\\(…)` contains no expression.",
1005    ),
1006    dg(
1007        "bynk.parse.empty_match",
1008        "A `match` has no arms.",
1009        &["match_expr"],
1010    ),
1011    dg(
1012        "bynk.parse.empty_service",
1013        "A `service` body is empty.",
1014        &["service_decl"],
1015    ),
1016    dg(
1017        "bynk.parse.expected_agent_key",
1018        "Expected a `key` declaration in an agent.",
1019        &["agent_decl"],
1020    ),
1021    d(
1022        "bynk.parse.expected_agent_storage",
1023        "An agent declares no storage — it has no `store` fields.",
1024    ),
1025    dg(
1026        "bynk.parse.expected_base_type",
1027        "Expected a base type.",
1028        &["base_type"],
1029    ),
1030    dg(
1031        "bynk.parse.expected_capability_op",
1032        "Expected a capability operation.",
1033        &["capability_op"],
1034    ),
1035    d("bynk.parse.expected_expression", "Expected an expression."),
1036    dg(
1037        "bynk.parse.expected_handler",
1038        "Expected a handler.",
1039        &["handler"],
1040    ),
1041    d("bynk.parse.expected_item", "Expected a declaration."),
1042    dg(
1043        "bynk.parse.expected_predicate",
1044        "Expected a refinement predicate.",
1045        &["refinement"],
1046    ),
1047    dg(
1048        "bynk.parse.expected_provider_op",
1049        "Expected a provider operation.",
1050        &["provider_op"],
1051    ),
1052    d("bynk.parse.expected_token", "Expected a specific token."),
1053    d("bynk.parse.expected_type", "Expected a type."),
1054    d(
1055        "bynk.parse.expected_unit_header",
1056        "Expected a `commons` or `context` header.",
1057    ),
1058    dg(
1059        "bynk.parse.expected_visibility",
1060        "Expected a visibility keyword.",
1061        &["exports_decl"],
1062    ),
1063    dg(
1064        "bynk.parse.exports_after_decls",
1065        "`exports` appears after other declarations.",
1066        &["exports_decl"],
1067    ),
1068    d(
1069        "bynk.parse.extra_tokens",
1070        "Unexpected tokens after an otherwise complete construct.",
1071    ),
1072    dg(
1073        "bynk.parse.generic_arg_count",
1074        "Wrong number of generic type arguments.",
1075        &["generic_type_ref"],
1076    ),
1077    dg(
1078        "bynk.parse.handler_in_agent",
1079        "A protocol handler (`on GET`/`schedule`/`message`) was declared in an agent.",
1080        &["handler"],
1081    ),
1082    d(
1083        "bynk.parse.invariant_after_handler",
1084        "An `invariant` was declared after a handler; invariants precede handlers.",
1085    ),
1086    dg(
1087        "bynk.parse.malformed_float_literal",
1088        "A float literal is missing a digit on one side of the `.` (`1.`, `.5`).",
1089        &["float_literal"],
1090    ),
1091    d(
1092        "bynk.parse.nesting_too_deep",
1093        "An expression or type nests deeper than the parser's fixed limit.",
1094    ),
1095    dg(
1096        "bynk.parse.non_associative",
1097        "A non-associative operator was chained (e.g. `a == b == c`).",
1098        &["binary_expr"],
1099    ),
1100    d(
1101        "bynk.parse.orphan_doc_block",
1102        "A documentation block is not attached to a declaration (warning).",
1103    ),
1104    dg(
1105        "bynk.parse.refined_pattern_inner",
1106        "A refined pattern's inner form is something other than `_`.",
1107        &["refined_pattern"],
1108    ),
1109    dg(
1110        "bynk.parse.reserved_keyword",
1111        "A reserved keyword was used as an identifier.",
1112        &["identifier"],
1113    ),
1114    dg(
1115        "bynk.parse.self_outside_method",
1116        "`self` used outside a method or handler.",
1117        &["self_expr"],
1118    ),
1119    d(
1120        "bynk.parse.storage_after_phase",
1121        "Agent storage (`state` / `store`) is declared after the invariants or handlers.",
1122    ),
1123    d(
1124        "bynk.parse.transition_after_handler",
1125        "A `transition` is declared after an agent handler; step invariants precede the handlers.",
1126    ),
1127    d(
1128        "bynk.parse.unexpected_adapter",
1129        "An `adapter` appeared where it is not allowed.",
1130    ),
1131    dg(
1132        "bynk.parse.unexpected_context",
1133        "A `context` appeared where it is not allowed.",
1134        &["context_decl"],
1135    ),
1136    d("bynk.parse.unexpected_eof", "Unexpected end of input."),
1137    dg(
1138        "bynk.parse.unexpected_suite",
1139        "A `suite` appeared where it is not allowed.",
1140        &["suite_decl"],
1141    ),
1142    d(
1143        "bynk.parse.unknown_effect_method",
1144        "An unknown method on `Effect`.",
1145    ),
1146    dg(
1147        "bynk.parse.unknown_handler_kind",
1148        "An unknown handler form (expected `call`, an HTTP method, `schedule`, or `message`).",
1149        &["handler"],
1150    ),
1151    dg(
1152        "bynk.parse.unknown_predicate",
1153        "An unknown refinement predicate.",
1154        &["predicate_name"],
1155    ),
1156    d(
1157        "bynk.parse.unknown_tier",
1158        "A `case`/`suite` `as <tier>` clause names something other than `unit`, `integration`, or `system`.",
1159    ),
1160    dg(
1161        "bynk.parse.uses_after_decls",
1162        "`uses` appears after other declarations.",
1163        &["uses_decl"],
1164    ),
1165    dg(
1166        "bynk.parse.variant_name_case",
1167        "A sum-type or enum variant name is not capitalised.",
1168        &["sum_variant", "enum_type"],
1169    ),
1170    d(
1171        "bynk.project.file_and_directory",
1172        "A unit exists as both a file and a directory.",
1173    ),
1174    d(
1175        "bynk.project.inconsistent_commons_name",
1176        "A source file's path does not match its declared name.",
1177    ),
1178    d(
1179        "bynk.project.kind_conflict",
1180        "A name is declared as both a commons and a context.",
1181    ),
1182    d(
1183        "bynk.project.no_root",
1184        "No project root could be determined.",
1185    ),
1186    d(
1187        "bynk.project.no_sources",
1188        "The project contains no source files.",
1189    ),
1190    d(
1191        "bynk.project.read_failed",
1192        "A source file could not be read.",
1193    ),
1194    dg(
1195        "bynk.property.restates_refinement",
1196        "A `property` merely re-checks a refinement its type already guarantees.",
1197        &["for_all"],
1198    ),
1199    dg(
1200        "bynk.property.where_not_bool",
1201        "A `for all ... where` filter does not type to `Bool`.",
1202        &["for_all"],
1203    ),
1204    dg(
1205        "bynk.provider.dependency_cycle",
1206        "Providers form a capability dependency cycle through `given`.",
1207        &["provider_decl"],
1208    ),
1209    dg(
1210        "bynk.provider.extra_operation",
1211        "A `provides` block implements an operation not in the capability.",
1212        &["provider_decl"],
1213    ),
1214    dg(
1215        "bynk.provider.missing_operation",
1216        "A `provides` block is missing a capability operation.",
1217        &["provider_decl"],
1218    ),
1219    dg(
1220        "bynk.provider.outside_context",
1221        "`provides` was declared outside a context.",
1222        &["provider_decl"],
1223    ),
1224    dg(
1225        "bynk.provider.signature_mismatch",
1226        "A `provides` operation's signature does not match the capability.",
1227        &["provider_decl"],
1228    ),
1229    dg(
1230        "bynk.provider.unknown_capability",
1231        "`provides` names a capability that does not exist.",
1232        &["provider_decl"],
1233    ),
1234    d(
1235        "bynk.query.join_key_mismatch",
1236        "A `joinOn`/`leftJoin` left and right key function return different types.",
1237    ),
1238    dg(
1239        "bynk.query.sum_needs_numeric",
1240        "A `sum`/`average` key function does not return a numeric type (`Int`, `Float`, or `Duration`).",
1241        &[],
1242    ),
1243    dg(
1244        "bynk.queue.bad_params",
1245        "An `on message` handler does not take exactly one `message` parameter.",
1246        &["queue_handler"],
1247    ),
1248    dg(
1249        "bynk.queue.duplicate_consumer",
1250        "Two `on message` handlers consume the same queue.",
1251        &["queue_handler"],
1252    ),
1253    dg(
1254        "bynk.queue.invalid_name",
1255        "A `from queue(\"…\")` binding has an empty queue name.",
1256        &["queue_handler"],
1257    ),
1258    dg(
1259        "bynk.queue.return_not_queue_result",
1260        "An `on message` handler does not return `Effect[QueueResult]`.",
1261        &["handler"],
1262    ),
1263    dg(
1264        "bynk.record_spread.field_type_mismatch",
1265        "A record-spread override has the wrong type for the field.",
1266        &["record_spread"],
1267    ),
1268    dg(
1269        "bynk.record_spread.non_record_base",
1270        "The base of a record spread is not a record.",
1271        &["record_spread"],
1272    ),
1273    dg(
1274        "bynk.record_spread.type_mismatch",
1275        "A record spread's base is a different record type.",
1276        &["record_spread"],
1277    ),
1278    dg(
1279        "bynk.record_spread.unknown_field",
1280        "A record spread overrides a field the record does not have.",
1281        &["record_spread"],
1282    ),
1283    dg(
1284        "bynk.refine.literal_violates",
1285        "A literal does not satisfy the refined type's predicate.",
1286        &["refined_type"],
1287    ),
1288    dg(
1289        "bynk.requires.unpinned_dependency",
1290        "An adapter `binding … requires { … }` entry has an unpinned version range.",
1291        &["binding_decl"],
1292    ),
1293    d(
1294        "bynk.resolve.ambiguous_variant",
1295        "A variant name is ambiguous across several sum types.",
1296    ),
1297    dg(
1298        "bynk.resolve.arity_mismatch",
1299        "A function was called with the wrong number of arguments.",
1300        &["call"],
1301    ),
1302    d("bynk.resolve.duplicate_actor", "Two actors share a name."),
1303    dg(
1304        "bynk.resolve.duplicate_agent",
1305        "Two agents share a name.",
1306        &["agent_decl"],
1307    ),
1308    dg(
1309        "bynk.resolve.duplicate_capability",
1310        "Two capabilities share a name.",
1311        &["capability_decl"],
1312    ),
1313    dg(
1314        "bynk.resolve.duplicate_field",
1315        "A record declares a field twice.",
1316        &["record_type"],
1317    ),
1318    dg(
1319        "bynk.resolve.duplicate_field_init",
1320        "A record construction initialises a field twice.",
1321        &["record_construction"],
1322    ),
1323    dg(
1324        "bynk.resolve.duplicate_fn",
1325        "Two functions share a name.",
1326        &["fn_decl"],
1327    ),
1328    d(
1329        "bynk.resolve.duplicate_message_code",
1330        "A message bundle declares the same code twice in one block.",
1331    ),
1332    d(
1333        "bynk.resolve.duplicate_message_locale",
1334        "Two `messages` blocks in one bundle declare the same locale tag.",
1335    ),
1336    dg(
1337        "bynk.resolve.duplicate_method",
1338        "Two methods share a name.",
1339        &["fn_decl"],
1340    ),
1341    dg(
1342        "bynk.resolve.duplicate_param",
1343        "A parameter name is repeated.",
1344        &["param"],
1345    ),
1346    dg(
1347        "bynk.resolve.duplicate_provider",
1348        "A capability is provided more than once.",
1349        &["provider_decl"],
1350    ),
1351    dg(
1352        "bynk.resolve.duplicate_service",
1353        "Two services share a name.",
1354        &["service_decl"],
1355    ),
1356    dg(
1357        "bynk.resolve.duplicate_type",
1358        "Two types share a name.",
1359        &["type_decl"],
1360    ),
1361    dg(
1362        "bynk.resolve.duplicate_variant",
1363        "A sum type declares a variant twice.",
1364        &["sum_type"],
1365    ),
1366    d(
1367        "bynk.resolve.fn_without_call",
1368        "A function was referenced without being called.",
1369    ),
1370    dg(
1371        "bynk.resolve.let_shadows_fn",
1372        "A `let` binding shadows a function.",
1373        &["let_stmt"],
1374    ),
1375    dg(
1376        "bynk.resolve.let_shadows_type",
1377        "A `let` binding shadows a type.",
1378        &["let_stmt"],
1379    ),
1380    d(
1381        "bynk.resolve.method_unknown_type",
1382        "A method is defined on an unknown type.",
1383    ),
1384    dg(
1385        "bynk.resolve.missing_field",
1386        "A record construction omits a required field.",
1387        &["record_construction"],
1388    ),
1389    d(
1390        "bynk.resolve.name_conflict",
1391        "Two declarations share a name.",
1392    ),
1393    dg(
1394        "bynk.resolve.not_a_record_type",
1395        "Record syntax was used on a non-record type.",
1396        &["record_construction"],
1397    ),
1398    dg(
1399        "bynk.resolve.opaque_record_construction",
1400        "An opaque type was constructed with record syntax.",
1401        &["record_construction"],
1402    ),
1403    dg(
1404        "bynk.resolve.param_as_function",
1405        "A value (such as a parameter) was called as a function.",
1406        &["call"],
1407    ),
1408    dg(
1409        "bynk.resolve.recursive_record_field",
1410        "A record directly contains a field of its own type.",
1411        &["record_type"],
1412    ),
1413    dg(
1414        "bynk.resolve.reserved_builtin_type",
1415        "A type declaration reuses a compiler-known built-in type name.",
1416        &["type_decl"],
1417    ),
1418    dg(
1419        "bynk.resolve.self_outside_method",
1420        "`self` referenced outside a method or handler.",
1421        &["self_expr"],
1422    ),
1423    dg(
1424        "bynk.resolve.type_as_function",
1425        "A type name was called as if it were a function.",
1426        &["call"],
1427    ),
1428    d(
1429        "bynk.resolve.type_in_expr",
1430        "A type name was used where a value is expected.",
1431    ),
1432    dg(
1433        "bynk.resolve.unconsumed_context",
1434        "A context's service was called without a `consumes` declaration.",
1435        &["consumes_decl"],
1436    ),
1437    dg(
1438        "bynk.resolve.unknown_field",
1439        "Accessed a field the record does not have.",
1440        &["field_access"],
1441    ),
1442    dg(
1443        "bynk.resolve.unknown_function",
1444        "Called a function that does not exist.",
1445        &["call"],
1446    ),
1447    d(
1448        "bynk.resolve.unknown_name",
1449        "Referenced a name that is not in scope.",
1450    ),
1451    dg(
1452        "bynk.resolve.unknown_static_member",
1453        "Referenced an unknown static member (e.g. `T.x`).",
1454        &["field_access"],
1455    ),
1456    d(
1457        "bynk.resolve.unknown_type",
1458        "Referenced a type that does not exist.",
1459    ),
1460    d(
1461        "bynk.secrets.computed_name",
1462        "A `bynk.Secrets` read names its secret with a computed expression rather than a literal, so `bynk deploy` cannot plan it (warning).",
1463    ),
1464    dg(
1465        "bynk.send.in_pure_context",
1466        "A `~>` send was used in a pure (non-effectful) context.",
1467        &["effect_send_stmt"],
1468    ),
1469    dg(
1470        "bynk.send.non_effect",
1471        "A `~>` send was applied to a non-`Effect` value.",
1472        &["effect_send_stmt"],
1473    ),
1474    dg(
1475        "bynk.send.requires_unit",
1476        "A `~>` send targets an operation whose reply is not `Effect[()]`.",
1477        &["effect_send_stmt"],
1478    ),
1479    dg(
1480        "bynk.service.missing_from",
1481        "A `from`-less service has a handler other than `on call`.",
1482        &["service_decl"],
1483    ),
1484    dg(
1485        "bynk.service.mixed_protocols",
1486        "A service mixes handler forms that do not match its `from <protocol>`.",
1487        &["service_decl"],
1488    ),
1489    dg(
1490        "bynk.service.outside_context",
1491        "A `service` was declared outside a context.",
1492        &["service_decl"],
1493    ),
1494    dg(
1495        "bynk.service.return_not_effect",
1496        "A service handler's return type is not an `Effect`.",
1497        &["service_decl"],
1498    ),
1499    dg(
1500        "bynk.service.unknown_protocol",
1501        "A `from <protocol>` names an unknown protocol (e.g. a transport like Kafka).",
1502        &["service_decl"],
1503    ),
1504    d(
1505        "bynk.service.websocket_header",
1506        "The `from websocket` header is malformed — it binds frame types as `websocket(in: <type>, out: <type>)` (real-time track slice 3).",
1507    ),
1508    d(
1509        "bynk.service.websocket_multiple",
1510        "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).",
1511    ),
1512    d(
1513        "bynk.service.websocket_open_arity",
1514        "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).",
1515    ),
1516    d(
1517        "bynk.store.annotation_kind_mismatch",
1518        "A storage annotation is used on a kind it does not apply to (e.g. `@ttl` on a `Map`).",
1519    ),
1520    d(
1521        "bynk.store.annotation_unsupported",
1522        "A known storage annotation (`@ttl`/`@retain`/`@indexed`/`@bounded`) is used before the slice that supports it.",
1523    ),
1524    d(
1525        "bynk.store.cache_needs_clock",
1526        "A handler performs a `Cache` operation (TTL expiry reads the clock) without declaring `given Clock`.",
1527    ),
1528    d(
1529        "bynk.store.cache_ttl_required",
1530        "A `Cache` field is missing its required `@ttl(<duration>)` annotation (a keyed store with no expiry is a `Map`).",
1531    ),
1532    d(
1533        "bynk.store.kind_arity",
1534        "A storage kind was applied to the wrong number of type arguments (e.g. `Cell[A, B]`).",
1535    ),
1536    d(
1537        "bynk.store.kind_unsupported",
1538        "A known storage kind (`Queue`) is used before the slice that supports it.",
1539    ),
1540    d(
1541        "bynk.store.log_needs_clock",
1542        "A handler calls `Log.append` (which stamps the current time) without declaring `given Clock`.",
1543    ),
1544    d(
1545        "bynk.store.unknown_annotation",
1546        "A `store` field carries an annotation outside the closed `@indexed`/`@ttl`/`@retain`/`@bounded` set.",
1547    ),
1548    d(
1549        "bynk.store.unknown_kind",
1550        "A `store` field's type is not a known storage kind.",
1551    ),
1552    d(
1553        "bynk.store.unknown_map_accessor",
1554        "A `store Map` field access is not one of its query accessors (`entries`/`keys`/`values`).",
1555    ),
1556    d(
1557        "bynk.store.unknown_op",
1558        "A storage-`Map`/`Set` operation is not a recognised entry/membership method.",
1559    ),
1560    d(
1561        "bynk.stub.bad_sequence",
1562        "A `stub … returns each […]` sequence is malformed (e.g. empty).",
1563    ),
1564    d(
1565        "bynk.stub.not_a_seam",
1566        "A test `stub` overrides a capability the unit under test does not consume.",
1567    ),
1568    d(
1569        "bynk.stub.rhs_type",
1570        "A test `stub … returns <value>` right-hand side does not match the operation's return type.",
1571    ),
1572    d(
1573        "bynk.stub.unknown_op",
1574        "A test `stub` names an operation the capability does not declare.",
1575    ),
1576    dg(
1577        "bynk.suite.duplicate_case_name",
1578        "Two `case`s share a description.",
1579        &["case"],
1580    ),
1581    dg(
1582        "bynk.suite.unknown_target",
1583        "A `suite` targets a unit that does not exist.",
1584        &["suite_decl"],
1585    ),
1586    d(
1587        "bynk.target.browser_bundle_only",
1588        "The `browser` platform builds only the in-process `Bundle` topology; `--target workers` is not a browser build.",
1589    ),
1590    dg(
1591        "bynk.target.vendor_conflict",
1592        "One deployment unit's in-process closure uses platform-native capabilities from two mutually-exclusive platforms.",
1593        &["consumes_decl"],
1594    ),
1595    dg(
1596        "bynk.target.vendor_required",
1597        "A deployment unit uses a platform-native capability but the build selects another `--platform`.",
1598        &["consumes_decl"],
1599    ),
1600    dg(
1601        "bynk.test.actor_identity_required",
1602        "A call-site `by <Actor>` omits the identity an identity-carrying actor requires.",
1603        &["case"],
1604    ),
1605    dg(
1606        "bynk.test.actor_no_identity",
1607        "A call-site `by <Actor>(x)` supplies an identity to an actor that takes none — a unit-identity actor (e.g. `Visitor`) or `Nobody`.",
1608        &["case"],
1609    ),
1610    dg(
1611        "bynk.test.credential_needs_system",
1612        "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.",
1613        &["case"],
1614    ),
1615    dg(
1616        "bynk.test.nobody_needs_secured_route",
1617        "A case drives `by Nobody` at a route that is not Bearer-secured (e.g. a public `Visitor` route) — there is no auth seam to reject the missing credential.",
1618        &["case"],
1619    ),
1620    dg(
1621        "bynk.test.principal_identity_mismatch",
1622        "A call-site `by <Actor>` acts as an actor whose identity is incompatible with the addressed handler's actor.",
1623        &["case"],
1624    ),
1625    dg(
1626        "bynk.test.principal_on_wrong_method",
1627        "A wrong-method `405` test carries a `by <Actor>` clause; it reaches no handler, so a principal is meaningless.",
1628        &["case"],
1629    ),
1630    dg(
1631        "bynk.test.principal_required",
1632        "A test drives an identity-carrying handler with no call-site `by <Actor>(<identity>)`.",
1633        &["case"],
1634    ),
1635    dg(
1636        "bynk.test.service_bad_address",
1637        "A test body addresses a service the wrong way for its protocol (e.g. an http route without a leading path string).",
1638        &["case"],
1639    ),
1640    dg(
1641        "bynk.test.service_call_arity",
1642        "A test body's `svc.call(...)` passes the wrong number of arguments for the service's `on call` handler.",
1643        &["case"],
1644    ),
1645    dg(
1646        "bynk.test.service_no_call_handler",
1647        "A test body invokes `svc.call(...)` on a service with no `on call` handler (a `from http`/`cron`/`queue` service).",
1648        &["case"],
1649    ),
1650    dg(
1651        "bynk.test.service_unknown_route",
1652        "A test body addresses an http route / cron schedule / queue message the service does not declare.",
1653        &["case"],
1654    ),
1655    dg(
1656        "bynk.test.unknown_actor",
1657        "A call-site `by <Actor>` names an actor the target context does not declare and that is not a prelude actor.",
1658        &["case"],
1659    ),
1660    dg(
1661        "bynk.test.wire_needs_system",
1662        "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.",
1663        &["case"],
1664    ),
1665    d(
1666        "bynk.tier.property_has_tier",
1667        "A `property` carries an `as <tier>` clause; tiers are a `case`-only affordance.",
1668    ),
1669    d(
1670        "bynk.tier.system_needs_wire",
1671        "An `as system` test stands up fewer than two contexts; the system tier wires across contexts.",
1672    ),
1673    d(
1674        "bynk.transition.cross_agent_reference",
1675        "A transition predicate references another agent; step invariants are per-agent.",
1676    ),
1677    d(
1678        "bynk.transition.duplicate_name",
1679        "An agent declares two transitions with the same name.",
1680    ),
1681    d(
1682        "bynk.transition.impure_predicate",
1683        "A transition predicate uses an effectful or test-only construct; a step invariant must be pure.",
1684    ),
1685    d(
1686        "bynk.transition.no_step_reference",
1687        "A transition references neither `old` nor `new`; it constrains one state, so it is an `invariant`, not a step.",
1688    ),
1689    d(
1690        "bynk.transition.not_bool",
1691        "A transition predicate does not have type `Bool`.",
1692    ),
1693    d(
1694        "bynk.types.ambiguous_constructor",
1695        "`Ok`/`Err` is ambiguous between `Result` and `HttpResult`; qualify it.",
1696    ),
1697    dg(
1698        "bynk.types.argument_mismatch",
1699        "A function argument has the wrong type.",
1700        &["call"],
1701    ),
1702    dg(
1703        "bynk.types.call_arity",
1704        "A function value was applied with the wrong number of arguments.",
1705        &["call"],
1706    ),
1707    dg(
1708        "bynk.types.cannot_infer_option_type_param",
1709        "The value type of `None` could not be inferred.",
1710        &["none_expr"],
1711    ),
1712    d(
1713        "bynk.types.cannot_infer_result_type_params",
1714        "The type parameters of a `Result` could not be inferred.",
1715    ),
1716    dg(
1717        "bynk.types.catastrophic_regex",
1718        "A `Matches` predicate nests unbounded quantifiers, risking catastrophic backtracking (ReDoS).",
1719        &["refinement"],
1720    ),
1721    d(
1722        "bynk.types.constructor_arity",
1723        "A variant constructor got the wrong number of arguments.",
1724    ),
1725    d(
1726        "bynk.types.constructor_base_mismatch",
1727        "A `.of` constructor was given an argument of the wrong base type.",
1728    ),
1729    dg(
1730        "bynk.types.duplicate_literal_arm",
1731        "A `match` has two arms for the same literal value.",
1732        &["match_arm"],
1733    ),
1734    dg(
1735        "bynk.types.duplicate_variant_arm",
1736        "A `match` has two arms for the same variant.",
1737        &["match_arm"],
1738    ),
1739    d(
1740        "bynk.types.embeds_ambiguous",
1741        "A type is embedded by more than one variant of a sum, so `?`'s conversion would be ambiguous.",
1742    ),
1743    d(
1744        "bynk.types.embeds_unknown_variant",
1745        "An `embeds … as V` clause names a variant the sum does not declare.",
1746    ),
1747    d(
1748        "bynk.types.embeds_variant_shape",
1749        "An `embeds E as V` target variant must have exactly one payload field, of type `E`.",
1750    ),
1751    dg(
1752        "bynk.types.empty_refinement",
1753        "A refinement admits no values (contradictory predicates).",
1754        &["refinement"],
1755    ),
1756    dg(
1757        "bynk.types.err_value_mismatch",
1758        "An `Err` payload has the wrong type.",
1759        &["err_expr"],
1760    ),
1761    dg(
1762        "bynk.types.field_access_on_non_record",
1763        "Field access on a value that is not a record.",
1764        &["field_access"],
1765    ),
1766    dg(
1767        "bynk.types.field_refinement_not_base",
1768        "An inline field refinement requires a base or refined type.",
1769        &["record_field"],
1770    ),
1771    dg(
1772        "bynk.types.field_value_mismatch",
1773        "A record field was given a value of the wrong type.",
1774        &["record_construction"],
1775    ),
1776    dg(
1777        "bynk.types.function_at_boundary",
1778        "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.",
1779        &["function_type_ref"],
1780    ),
1781    dg(
1782        "bynk.types.guard_not_bool",
1783        "A match-arm `if` guard is not a `Bool` expression.",
1784        &["match_arm"],
1785    ),
1786    d(
1787        "bynk.types.held_at_boundary",
1788        "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).",
1789    ),
1790    d(
1791        "bynk.types.held_not_comparable",
1792        "A held value (`Connection[F]`) is compared with `==`/`!=` — held values have identity, not value-equality (§2.9.3, real-time track slice 2).",
1793    ),
1794    dg(
1795        "bynk.types.if_branch_mismatch",
1796        "The branches of an `if` have different types.",
1797        &["if_expr"],
1798    ),
1799    dg(
1800        "bynk.types.if_non_bool_cond",
1801        "An `if` condition is not a `Bool`.",
1802        &["if_expr"],
1803    ),
1804    dg(
1805        "bynk.types.if_without_else_requires_unit",
1806        "An `if` with no `else` branch has a non-unit then-branch; the missing else defaults to `()`, so the branch must be `()` or `Effect[()]`.",
1807        &["if_expr"],
1808    ),
1809    d(
1810        "bynk.types.interpolation_non_scalar",
1811        "An interpolation hole holds a value with no string form.",
1812    ),
1813    dg(
1814        "bynk.types.invalid_regex",
1815        "A `Matches` predicate contains an invalid regular expression.",
1816        &["refinement"],
1817    ),
1818    dg(
1819        "bynk.types.inverted_range",
1820        "An `InRange` predicate has its bounds inverted.",
1821        &["refinement"],
1822    ),
1823    dg(
1824        "bynk.types.is_base_mismatch",
1825        "An `is` refinement check is applied to a value of the wrong base type.",
1826        &["is_expr"],
1827    ),
1828    dg(
1829        "bynk.types.is_literal_pattern",
1830        "A literal was used on the right of `is`; `is` tests type/refinement, not value equality (use `==`).",
1831        &["is_expr"],
1832    ),
1833    dg(
1834        "bynk.types.is_non_sum",
1835        "`is` was applied to a value that is not a sum type.",
1836        &["is_expr"],
1837    ),
1838    dg(
1839        "bynk.types.is_refined_pattern",
1840        "A refined (`where`) pattern was used on the right of `is`; refined patterns are `match`-only.",
1841        &["is_expr"],
1842    ),
1843    dg(
1844        "bynk.types.is_unknown_variant",
1845        "`is` names a variant the type does not have.",
1846        &["is_expr"],
1847    ),
1848    dg(
1849        "bynk.types.json_uncodable",
1850        "A `Json.encode`/`Json.decode` target type cannot pass through the typed JSON codec (functions, effects, error builtins).",
1851        &["method_call"],
1852    ),
1853    dg(
1854        "bynk.types.key_not_orderable",
1855        "A `sortBy`/`min`/`max` key function does not return an orderable type (`Int`, `Float`, `String`, `Duration`, or `Instant`).",
1856        &[],
1857    ),
1858    dg(
1859        "bynk.types.lambda_mismatch",
1860        "A lambda's parameter count, parameter annotations, or body type do not match the expected function type.",
1861        &["lambda_expr"],
1862    ),
1863    dg(
1864        "bynk.types.let_annotation_mismatch",
1865        "A `let` value does not match its type annotation.",
1866        &["let_stmt"],
1867    ),
1868    dg(
1869        "bynk.types.list_element_mismatch",
1870        "A list-literal element has a different type from the list's element type.",
1871        &["list_literal"],
1872    ),
1873    dg(
1874        "bynk.types.match_arm_mismatch",
1875        "A `match` arm has a different type from the others.",
1876        &["match_arm"],
1877    ),
1878    dg(
1879        "bynk.types.match_non_sum_discriminant",
1880        "`match` was applied to a value that is not a sum type.",
1881        &["match_expr"],
1882    ),
1883    dg(
1884        "bynk.types.method_arity",
1885        "A method was called with the wrong number of arguments.",
1886        &["method_call"],
1887    ),
1888    dg(
1889        "bynk.types.method_not_found",
1890        "Called a method the type does not have.",
1891        &["method_call"],
1892    ),
1893    dg(
1894        "bynk.types.method_on_non_named_type",
1895        "A method was called on a built-in type that has no methods.",
1896        &["method_call"],
1897    ),
1898    dg(
1899        "bynk.types.mixed_pattern_bindings",
1900        "A pattern mixes named and positional bindings.",
1901        &["variant_pattern"],
1902    ),
1903    dg(
1904        "bynk.types.negative_length",
1905        "A length predicate was given a negative value.",
1906        &["refinement"],
1907    ),
1908    dg(
1909        "bynk.types.no_numeric_coercion",
1910        "`Int` and `Float` were mixed without an explicit conversion — in an operation or in refinement bounds.",
1911        &["binary_expr", "refinement"],
1912    ),
1913    dg(
1914        "bynk.types.non_exhaustive_match",
1915        "A `match` does not cover every variant.",
1916        &["match_expr"],
1917    ),
1918    dg(
1919        "bynk.types.ok_value_mismatch",
1920        "An `Ok` payload has the wrong type.",
1921        &["ok_expr"],
1922    ),
1923    dg(
1924        "bynk.types.opaque_raw_outside",
1925        "`.raw` on an opaque type was used outside its defining commons.",
1926        &["field_access"],
1927    ),
1928    dg(
1929        "bynk.types.opaque_record_construction",
1930        "An opaque type was constructed with record syntax.",
1931        &["record_construction"],
1932    ),
1933    dg(
1934        "bynk.types.opaque_unsafe_outside",
1935        "`.unsafe` on an opaque type was used outside its defining context.",
1936        &["field_access"],
1937    ),
1938    dg(
1939        "bynk.types.or_pattern_binding_mismatch",
1940        "An or-pattern's alternatives don't all bind the same set of names.",
1941        &["match_arm", "is_expr"],
1942    ),
1943    dg(
1944        "bynk.types.or_pattern_type_mismatch",
1945        "An or-pattern's alternatives give a shared binding different types (or refinements).",
1946        &["match_arm", "is_expr"],
1947    ),
1948    dg(
1949        "bynk.types.pattern_arity",
1950        "A pattern binds the wrong number of payload fields.",
1951        &["variant_pattern"],
1952    ),
1953    dg(
1954        "bynk.types.pattern_type_mismatch",
1955        "A pattern's type does not match the matched value.",
1956        &["variant_pattern"],
1957    ),
1958    dg(
1959        "bynk.types.predicate_base_mismatch",
1960        "A predicate does not apply to the type's base (e.g. a string predicate on an `Int`).",
1961        &["refinement"],
1962    ),
1963    d(
1964        "bynk.types.query_at_boundary",
1965        "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).",
1966    ),
1967    dg(
1968        "bynk.types.question_error_mismatch",
1969        "`?` propagates an error type incompatible with the function's.",
1970        &["question_expr"],
1971    ),
1972    dg(
1973        "bynk.types.question_on_non_result",
1974        "`?` was applied to a non-`Result` value.",
1975        &["question_expr"],
1976    ),
1977    dg(
1978        "bynk.types.question_option_outside_http",
1979        "`?` lifts an `Option` only inside a handler returning `HttpResult` (`None` becomes `NotFound`); elsewhere use `.okOr(err)`.",
1980        &["question_expr"],
1981    ),
1982    dg(
1983        "bynk.types.question_outside_result",
1984        "`?` used in a function that does not return a `Result`.",
1985        &["question_expr"],
1986    ),
1987    d(
1988        "bynk.types.return_mismatch",
1989        "A returned value does not match the declared return type.",
1990    ),
1991    dg(
1992        "bynk.types.some_value_mismatch",
1993        "A `Some` payload has the wrong type.",
1994        &["some_expr"],
1995    ),
1996    d(
1997        "bynk.types.stream_at_boundary",
1998        "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).",
1999    ),
2000    d(
2001        "bynk.types.stream_not_comparable",
2002        "A `Stream` value is compared with `==`/`!=` — a stream is a live value-over-time source, not a comparable value (real-time track slice 0).",
2003    ),
2004    d(
2005        "bynk.types.type_mismatch",
2006        "Two types that were required to match did not.",
2007    ),
2008    dg(
2009        "bynk.types.uninferable_element_type",
2010        "An empty `[]` (or `List.empty()` / `Map.empty()`) has no expected type to infer its element type from.",
2011        &["list_literal"],
2012    ),
2013    dg(
2014        "bynk.types.unkeyable_distinct",
2015        "A `distinct`/`distinctBy` element or key is not value-keyable (`String`, `Int`, or a refined/opaque type over them).",
2016        &[],
2017    ),
2018    dg(
2019        "bynk.types.unkeyable_map_key",
2020        "A `Map` key type is not value-keyable (`String`, `Int`, or a refined/opaque type over them).",
2021        &["generic_type_ref"],
2022    ),
2023    dg(
2024        "bynk.types.unknown_field",
2025        "Referenced a field the record type does not declare.",
2026        &["field_access"],
2027    ),
2028    dg(
2029        "bynk.types.unknown_pattern_field",
2030        "A pattern names a field the variant does not have.",
2031        &["variant_pattern"],
2032    ),
2033    dg(
2034        "bynk.types.unknown_static_member",
2035        "Referenced an unknown static member on a type.",
2036        &["field_access"],
2037    ),
2038    dg(
2039        "bynk.types.unknown_variant_in_pattern",
2040        "A pattern names a variant the sum type does not have.",
2041        &["variant_pattern"],
2042    ),
2043    dg(
2044        "bynk.types.unreachable_arm",
2045        "A `match` arm is unreachable.",
2046        &["match_arm"],
2047    ),
2048    d(
2049        "bynk.types.variant_arity",
2050        "A variant constructor got the wrong number of payload values.",
2051    ),
2052    d(
2053        "bynk.types.variant_missing_payload",
2054        "A variant requiring a payload was used without one.",
2055    ),
2056    d(
2057        "bynk.types.variant_payload_mismatch",
2058        "A variant payload has the wrong type.",
2059    ),
2060    dg(
2061        "bynk.uses.name_conflict",
2062        "A `uses` name collides with another name.",
2063        &["uses_decl"],
2064    ),
2065    dg(
2066        "bynk.uses.self_reference",
2067        "A commons `uses` itself.",
2068        &["uses_decl"],
2069    ),
2070    dg(
2071        "bynk.uses.target_is_context",
2072        "`uses` targets a context instead of a commons.",
2073        &["uses_decl"],
2074    ),
2075    dg(
2076        "bynk.uses.unknown_commons",
2077        "`uses` names a commons that does not exist.",
2078        &["uses_decl"],
2079    ),
2080    dg(
2081        "bynk.val.agent_not_generable",
2082        "A `for all`/`Val` cannot generate an agent — fabricated agent states need not be reachable.",
2083        &["for_all"],
2084    ),
2085    dg(
2086        "bynk.val.arity",
2087        "`Val[T]` was given the wrong number of pin arguments.",
2088        &["val_expr"],
2089    ),
2090    dg(
2091        "bynk.val.literal_violates",
2092        "A pinned `Val[T]` value violates the type's refinement.",
2093        &["val_expr"],
2094    ),
2095    dg(
2096        "bynk.val.needs_pin",
2097        "A bare `Val[T]` cannot generate a value (e.g. a `Matches` string); pin one.",
2098        &["val_expr"],
2099    ),
2100    dg(
2101        "bynk.val.outside_test",
2102        "`Val[T]` was used outside a test case body.",
2103        &["val_expr"],
2104    ),
2105    dg(
2106        "bynk.val.pin_not_literal",
2107        "A `Val[T]` pin argument is not a compile-time literal.",
2108        &["val_expr"],
2109    ),
2110    dg(
2111        "bynk.val.pin_unsupported",
2112        "A pin was given for a type kind that does not support pinning.",
2113        &["val_expr"],
2114    ),
2115    dg(
2116        "bynk.val.unknown_type",
2117        "`Val[T]` names a type that does not resolve.",
2118        &["val_expr"],
2119    ),
2120    dg(
2121        "bynk.val.unsupported_kind",
2122        "`Val[T]` cannot fabricate a value for this kind of type.",
2123        &["val_expr"],
2124    ),
2125    d(
2126        "bynk.ws.message_frame_param",
2127        "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).",
2128    ),
2129    d(
2130        "bynk.ws.open_given_unsupported",
2131        "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).",
2132    ),
2133    d(
2134        "bynk.ws.open_transfer_shape",
2135        "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).",
2136    ),
2137    d(
2138        "bynk.ws.route_param_mismatch",
2139        "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).",
2140    ),
2141];
2142
2143/// A diagnostic with no single governing grammar construct.
2144const fn d(code: &'static str, summary: &'static str) -> DiagnosticInfo {
2145    DiagnosticInfo {
2146        code,
2147        summary,
2148        grammar_symbol: &[],
2149    }
2150}
2151
2152/// A diagnostic that constrains one or more grammar productions.
2153const fn dg(
2154    code: &'static str,
2155    summary: &'static str,
2156    grammar_symbol: &'static [&'static str],
2157) -> DiagnosticInfo {
2158    DiagnosticInfo {
2159        code,
2160        summary,
2161        grammar_symbol,
2162    }
2163}
2164
2165/// The category segment of a code (the part between the first two dots), e.g.
2166/// `"types"` for `"bynk.types.type_mismatch"`.
2167pub fn category(code: &str) -> &str {
2168    code.split('.').nth(1).unwrap_or("")
2169}
2170
2171/// A human-readable heading for a category segment.
2172fn category_title(cat: &str) -> &'static str {
2173    match cat {
2174        "agent" | "agents" => "Agents",
2175        "boundary" => "Boundaries",
2176        "capability" => "Capabilities",
2177        "consumes" => "Consumes",
2178        "context" => "Contexts",
2179        "contract" => "Contracts",
2180        "cron" => "Cron",
2181        "effect" => "Effects",
2182        "expect" => "Expectations",
2183        "exports" => "Exports",
2184        "given" => "Given capabilities",
2185        "http" => "HTTP",
2186        "lex" => "Lexer",
2187        "messages" => "Message bundles",
2188        "mock" => "Mocks (collaborators)",
2189        "observe" => "Observation",
2190        "parse" => "Parser",
2191        "project" => "Project",
2192        "property" => "Properties (generative tests)",
2193        "provider" => "Providers",
2194        "queue" => "Queue",
2195        "record_spread" => "Record spread",
2196        "refine" => "Refinement",
2197        "resolve" => "Resolution",
2198        "service" => "Services",
2199        "suite" => "Suites and cases",
2200        "transition" => "Transitions (step invariants)",
2201        "types" => "Type checking",
2202        "uses" => "Uses",
2203        "val" => "Value fabrication",
2204        _ => "Other",
2205    }
2206}
2207
2208/// Render the diagnostic index as a Markdown reference page, grouped by
2209/// category. This is the generator behind
2210/// `site/src/content/docs/book/reference/diagnostics.md`.
2211pub fn render_markdown() -> String {
2212    use std::collections::BTreeMap;
2213
2214    // Group codes by their category title, preserving sorted code order.
2215    let mut by_category: BTreeMap<&str, Vec<&DiagnosticInfo>> = BTreeMap::new();
2216    for info in REGISTRY {
2217        by_category
2218            .entry(category_title(category(info.code)))
2219            .or_default()
2220            .push(info);
2221    }
2222
2223    let mut out = String::new();
2224    out.push_str("# Diagnostic index\n\n");
2225    out.push_str(
2226        "<!-- GENERATED FILE — do not edit by hand.\n     \
2227         Source: bynkc/src/diagnostics.rs (`render_markdown`).\n     \
2228         Regenerate with: BYNK_BLESS=1 cargo test -p bynkc --test diagnostics_registry -->\n\n",
2229    );
2230    out.push_str(
2231        "Every diagnostic code the compiler can emit, with a one-line summary of \
2232         the cause, grouped by category. For step-by-step cause-and-fix guidance \
2233         on the most common ones, see the [troubleshooting guides](../troubleshooting/index.md).\n\n",
2234    );
2235    out.push_str(&format!(
2236        "There are **{}** codes in total.\n",
2237        REGISTRY.len()
2238    ));
2239
2240    for (title, infos) in &by_category {
2241        out.push_str(&format!("\n## {title}\n\n"));
2242        out.push_str("| Code | Summary | Construct |\n|---|---|---|\n");
2243        for info in infos {
2244            // The construct column deep-links each governing production to its
2245            // entry in the annotated grammar reference; generated from
2246            // `grammar_symbol` (each value is an embeddable rule, so the
2247            // `#rule-<raw>` anchor resolves — enforced in diagnostics_registry).
2248            let construct = info
2249                .grammar_symbol
2250                .iter()
2251                .map(|sym| format!("[`{sym}`](grammar.md#rule-{sym})"))
2252                .collect::<Vec<_>>()
2253                .join(", ");
2254            // A curated (`bynk explain`-able) code links to its Book concept
2255            // page; the in-site link is validated by the site's link checker,
2256            // so a moved page or renamed anchor fails the build (#853). Codes
2257            // without an explanation render as plain inline code.
2258            let code_cell = match explain(info.code) {
2259                Some(e) => format!("[`{}`]({})", info.code, e.in_site_link()),
2260                None => format!("`{}`", info.code),
2261            };
2262            out.push_str(&format!(
2263                "| {} | {} | {} |\n",
2264                code_cell, info.summary, construct
2265            ));
2266        }
2267    }
2268
2269    out
2270}
2271
2272/// Invert the registry into a `{ "<rule>": [ { code, summary }, … ], … }` map,
2273/// serialised as pretty JSON with sorted keys and sorted codes. Only rules with
2274/// at least one diagnostic appear. This is the generator behind
2275/// `docs/grammar-semantics.json`, which the `{{#grammar-semantics <rule>}}`
2276/// preprocessor directive consumes.
2277pub fn render_grammar_semantics_json() -> String {
2278    use std::collections::BTreeMap;
2279
2280    // REGISTRY is sorted by code, so each rule's vector comes out code-sorted;
2281    // the BTreeMap gives sorted rule names.
2282    let mut by_symbol: BTreeMap<&str, Vec<&DiagnosticInfo>> = BTreeMap::new();
2283    for info in REGISTRY {
2284        for sym in info.grammar_symbol {
2285            by_symbol.entry(sym).or_default().push(info);
2286        }
2287    }
2288
2289    let mut map = serde_json::Map::new();
2290    map.insert(
2291        "_generated".to_string(),
2292        serde_json::Value::String(
2293            "Generated from the grammar_symbol field of bynkc/src/diagnostics.rs. \
2294             Do not edit by hand. Regenerate with: BYNK_BLESS=1 cargo test -p \
2295             bynkc --test diagnostics_registry"
2296                .to_string(),
2297        ),
2298    );
2299    for (sym, infos) in by_symbol {
2300        let arr: Vec<serde_json::Value> = infos
2301            .iter()
2302            .map(|info| serde_json::json!({ "code": info.code, "summary": info.summary }))
2303            .collect();
2304        map.insert(sym.to_string(), serde_json::Value::Array(arr));
2305    }
2306
2307    let mut s =
2308        serde_json::to_string_pretty(&serde_json::Value::Object(map)).expect("serialise semantics");
2309    s.push('\n');
2310    s
2311}