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.messages.incomplete",
898        "A locale is missing a code the reference locale declares.",
899    ),
900    d(
901        "bynk.messages.missing_locale_dependency",
902        "A commons declaring `messages` doesn't `uses bynk.locale`, which its generated `render`'s fallback needs.",
903    ),
904    d(
905        "bynk.messages.missing_reference",
906        "A message bundle has no `@reference` block.",
907    ),
908    d(
909        "bynk.messages.multiple_reference",
910        "A message bundle has more than one `@reference` block.",
911    ),
912    d(
913        "bynk.messages.outside_commons",
914        "A `messages` declaration appears outside a commons.",
915    ),
916    d(
917        "bynk.messages.placeholder_mismatch",
918        "A locale's template for a code uses a different set of `{name}` placeholders than the reference locale's.",
919    ),
920    d(
921        "bynk.namespace.reserved",
922        "A user unit is named `bynk` or `bynk.*`; the `bynk` root is reserved for the toolchain.",
923    ),
924    d(
925        "bynk.observe.bad_count",
926        "An observation call count is not a non-negative integer literal (`called once` / `called <n> times`).",
927    ),
928    d(
929        "bynk.observe.impure_with",
930        "A `with` predicate uses an effectful or test-only construct; it must be pure.",
931    ),
932    d(
933        "bynk.observe.not_a_seam",
934        "An observation targets a capability the unit under test does not consume.",
935    ),
936    d(
937        "bynk.observe.outside_case",
938        "An observation appears outside a `case` body.",
939    ),
940    d(
941        "bynk.observe.trace_outside_test",
942        "`trace(Cap.op)` appears outside a `case` body.",
943    ),
944    d(
945        "bynk.observe.unknown_op",
946        "An observation names an operation the capability does not declare.",
947    ),
948    d(
949        "bynk.observe.with_not_bool",
950        "A `with` predicate does not have type `Bool`.",
951    ),
952    dg(
953        "bynk.parse.consumes_after_decls",
954        "`consumes` appears after other declarations.",
955        &["consumes_decl"],
956    ),
957    d(
958        "bynk.parse.dangling_handler_annotation",
959        "A handler-position annotation (e.g. `@cache`) is not followed by an `on` handler.",
960    ),
961    dg(
962        "bynk.parse.duplicate_cors",
963        "A service declares more than one `cors { }` policy.",
964        &["service_decl"],
965    ),
966    dg(
967        "bynk.parse.duplicate_limits",
968        "A service declares more than one `limits { }` policy.",
969        &["service_decl"],
970    ),
971    dg(
972        "bynk.parse.duplicate_security",
973        "A service declares more than one `security { }` policy.",
974        &["service_decl"],
975    ),
976    dg(
977        "bynk.parse.empty_agent",
978        "An `agent` body is empty.",
979        &["agent_decl"],
980    ),
981    dg(
982        "bynk.parse.empty_capability",
983        "A `capability` body is empty.",
984        &["capability_decl"],
985    ),
986    d(
987        "bynk.parse.empty_interpolation",
988        "An interpolation hole `\\(…)` contains no expression.",
989    ),
990    dg(
991        "bynk.parse.empty_match",
992        "A `match` has no arms.",
993        &["match_expr"],
994    ),
995    dg(
996        "bynk.parse.empty_service",
997        "A `service` body is empty.",
998        &["service_decl"],
999    ),
1000    dg(
1001        "bynk.parse.expected_agent_key",
1002        "Expected a `key` declaration in an agent.",
1003        &["agent_decl"],
1004    ),
1005    d(
1006        "bynk.parse.expected_agent_storage",
1007        "An agent declares no storage — it has no `store` fields.",
1008    ),
1009    dg(
1010        "bynk.parse.expected_base_type",
1011        "Expected a base type.",
1012        &["base_type"],
1013    ),
1014    dg(
1015        "bynk.parse.expected_capability_op",
1016        "Expected a capability operation.",
1017        &["capability_op"],
1018    ),
1019    d("bynk.parse.expected_expression", "Expected an expression."),
1020    dg(
1021        "bynk.parse.expected_handler",
1022        "Expected a handler.",
1023        &["handler"],
1024    ),
1025    d("bynk.parse.expected_item", "Expected a declaration."),
1026    dg(
1027        "bynk.parse.expected_predicate",
1028        "Expected a refinement predicate.",
1029        &["refinement"],
1030    ),
1031    dg(
1032        "bynk.parse.expected_provider_op",
1033        "Expected a provider operation.",
1034        &["provider_op"],
1035    ),
1036    d("bynk.parse.expected_token", "Expected a specific token."),
1037    d("bynk.parse.expected_type", "Expected a type."),
1038    d(
1039        "bynk.parse.expected_unit_header",
1040        "Expected a `commons` or `context` header.",
1041    ),
1042    dg(
1043        "bynk.parse.expected_visibility",
1044        "Expected a visibility keyword.",
1045        &["exports_decl"],
1046    ),
1047    dg(
1048        "bynk.parse.exports_after_decls",
1049        "`exports` appears after other declarations.",
1050        &["exports_decl"],
1051    ),
1052    d(
1053        "bynk.parse.extra_tokens",
1054        "Unexpected tokens after an otherwise complete construct.",
1055    ),
1056    dg(
1057        "bynk.parse.generic_arg_count",
1058        "Wrong number of generic type arguments.",
1059        &["generic_type_ref"],
1060    ),
1061    dg(
1062        "bynk.parse.handler_in_agent",
1063        "A protocol handler (`on GET`/`schedule`/`message`) was declared in an agent.",
1064        &["handler"],
1065    ),
1066    d(
1067        "bynk.parse.invariant_after_handler",
1068        "An `invariant` was declared after a handler; invariants precede handlers.",
1069    ),
1070    dg(
1071        "bynk.parse.malformed_float_literal",
1072        "A float literal is missing a digit on one side of the `.` (`1.`, `.5`).",
1073        &["float_literal"],
1074    ),
1075    d(
1076        "bynk.parse.nesting_too_deep",
1077        "An expression or type nests deeper than the parser's fixed limit.",
1078    ),
1079    dg(
1080        "bynk.parse.non_associative",
1081        "A non-associative operator was chained (e.g. `a == b == c`).",
1082        &["binary_expr"],
1083    ),
1084    d(
1085        "bynk.parse.orphan_doc_block",
1086        "A documentation block is not attached to a declaration (warning).",
1087    ),
1088    dg(
1089        "bynk.parse.refined_pattern_inner",
1090        "A refined pattern's inner form is something other than `_`.",
1091        &["refined_pattern"],
1092    ),
1093    dg(
1094        "bynk.parse.reserved_keyword",
1095        "A reserved keyword was used as an identifier.",
1096        &["identifier"],
1097    ),
1098    dg(
1099        "bynk.parse.self_outside_method",
1100        "`self` used outside a method or handler.",
1101        &["self_expr"],
1102    ),
1103    d(
1104        "bynk.parse.storage_after_phase",
1105        "Agent storage (`state` / `store`) is declared after the invariants or handlers.",
1106    ),
1107    d(
1108        "bynk.parse.transition_after_handler",
1109        "A `transition` is declared after an agent handler; step invariants precede the handlers.",
1110    ),
1111    d(
1112        "bynk.parse.unexpected_adapter",
1113        "An `adapter` appeared where it is not allowed.",
1114    ),
1115    dg(
1116        "bynk.parse.unexpected_context",
1117        "A `context` appeared where it is not allowed.",
1118        &["context_decl"],
1119    ),
1120    d("bynk.parse.unexpected_eof", "Unexpected end of input."),
1121    dg(
1122        "bynk.parse.unexpected_suite",
1123        "A `suite` appeared where it is not allowed.",
1124        &["suite_decl"],
1125    ),
1126    d(
1127        "bynk.parse.unknown_effect_method",
1128        "An unknown method on `Effect`.",
1129    ),
1130    dg(
1131        "bynk.parse.unknown_handler_kind",
1132        "An unknown handler form (expected `call`, an HTTP method, `schedule`, or `message`).",
1133        &["handler"],
1134    ),
1135    dg(
1136        "bynk.parse.unknown_predicate",
1137        "An unknown refinement predicate.",
1138        &["predicate_name"],
1139    ),
1140    d(
1141        "bynk.parse.unknown_tier",
1142        "A `case`/`suite` `as <tier>` clause names something other than `unit`, `integration`, or `system`.",
1143    ),
1144    dg(
1145        "bynk.parse.uses_after_decls",
1146        "`uses` appears after other declarations.",
1147        &["uses_decl"],
1148    ),
1149    dg(
1150        "bynk.parse.variant_name_case",
1151        "A sum-type or enum variant name is not capitalised.",
1152        &["sum_variant", "enum_type"],
1153    ),
1154    d(
1155        "bynk.project.file_and_directory",
1156        "A unit exists as both a file and a directory.",
1157    ),
1158    d(
1159        "bynk.project.inconsistent_commons_name",
1160        "A source file's path does not match its declared name.",
1161    ),
1162    d(
1163        "bynk.project.kind_conflict",
1164        "A name is declared as both a commons and a context.",
1165    ),
1166    d(
1167        "bynk.project.no_root",
1168        "No project root could be determined.",
1169    ),
1170    d(
1171        "bynk.project.no_sources",
1172        "The project contains no source files.",
1173    ),
1174    d(
1175        "bynk.project.read_failed",
1176        "A source file could not be read.",
1177    ),
1178    dg(
1179        "bynk.property.restates_refinement",
1180        "A `property` merely re-checks a refinement its type already guarantees.",
1181        &["for_all"],
1182    ),
1183    dg(
1184        "bynk.property.where_not_bool",
1185        "A `for all ... where` filter does not type to `Bool`.",
1186        &["for_all"],
1187    ),
1188    dg(
1189        "bynk.provider.dependency_cycle",
1190        "Providers form a capability dependency cycle through `given`.",
1191        &["provider_decl"],
1192    ),
1193    dg(
1194        "bynk.provider.extra_operation",
1195        "A `provides` block implements an operation not in the capability.",
1196        &["provider_decl"],
1197    ),
1198    dg(
1199        "bynk.provider.missing_operation",
1200        "A `provides` block is missing a capability operation.",
1201        &["provider_decl"],
1202    ),
1203    dg(
1204        "bynk.provider.outside_context",
1205        "`provides` was declared outside a context.",
1206        &["provider_decl"],
1207    ),
1208    dg(
1209        "bynk.provider.signature_mismatch",
1210        "A `provides` operation's signature does not match the capability.",
1211        &["provider_decl"],
1212    ),
1213    dg(
1214        "bynk.provider.unknown_capability",
1215        "`provides` names a capability that does not exist.",
1216        &["provider_decl"],
1217    ),
1218    d(
1219        "bynk.query.join_key_mismatch",
1220        "A `joinOn`/`leftJoin` left and right key function return different types.",
1221    ),
1222    dg(
1223        "bynk.query.sum_needs_numeric",
1224        "A `sum`/`average` key function does not return a numeric type (`Int`, `Float`, or `Duration`).",
1225        &[],
1226    ),
1227    dg(
1228        "bynk.queue.bad_params",
1229        "An `on message` handler does not take exactly one `message` parameter.",
1230        &["queue_handler"],
1231    ),
1232    dg(
1233        "bynk.queue.duplicate_consumer",
1234        "Two `on message` handlers consume the same queue.",
1235        &["queue_handler"],
1236    ),
1237    dg(
1238        "bynk.queue.invalid_name",
1239        "A `from queue(\"…\")` binding has an empty queue name.",
1240        &["queue_handler"],
1241    ),
1242    dg(
1243        "bynk.queue.return_not_queue_result",
1244        "An `on message` handler does not return `Effect[QueueResult]`.",
1245        &["handler"],
1246    ),
1247    dg(
1248        "bynk.record_spread.field_type_mismatch",
1249        "A record-spread override has the wrong type for the field.",
1250        &["record_spread"],
1251    ),
1252    dg(
1253        "bynk.record_spread.non_record_base",
1254        "The base of a record spread is not a record.",
1255        &["record_spread"],
1256    ),
1257    dg(
1258        "bynk.record_spread.type_mismatch",
1259        "A record spread's base is a different record type.",
1260        &["record_spread"],
1261    ),
1262    dg(
1263        "bynk.record_spread.unknown_field",
1264        "A record spread overrides a field the record does not have.",
1265        &["record_spread"],
1266    ),
1267    dg(
1268        "bynk.refine.literal_violates",
1269        "A literal does not satisfy the refined type's predicate.",
1270        &["refined_type"],
1271    ),
1272    dg(
1273        "bynk.requires.unpinned_dependency",
1274        "An adapter `binding … requires { … }` entry has an unpinned version range.",
1275        &["binding_decl"],
1276    ),
1277    d(
1278        "bynk.resolve.ambiguous_variant",
1279        "A variant name is ambiguous across several sum types.",
1280    ),
1281    dg(
1282        "bynk.resolve.arity_mismatch",
1283        "A function was called with the wrong number of arguments.",
1284        &["call"],
1285    ),
1286    d("bynk.resolve.duplicate_actor", "Two actors share a name."),
1287    dg(
1288        "bynk.resolve.duplicate_agent",
1289        "Two agents share a name.",
1290        &["agent_decl"],
1291    ),
1292    dg(
1293        "bynk.resolve.duplicate_capability",
1294        "Two capabilities share a name.",
1295        &["capability_decl"],
1296    ),
1297    dg(
1298        "bynk.resolve.duplicate_field",
1299        "A record declares a field twice.",
1300        &["record_type"],
1301    ),
1302    dg(
1303        "bynk.resolve.duplicate_field_init",
1304        "A record construction initialises a field twice.",
1305        &["record_construction"],
1306    ),
1307    dg(
1308        "bynk.resolve.duplicate_fn",
1309        "Two functions share a name.",
1310        &["fn_decl"],
1311    ),
1312    d(
1313        "bynk.resolve.duplicate_message_code",
1314        "A message bundle declares the same code twice in one block.",
1315    ),
1316    d(
1317        "bynk.resolve.duplicate_message_locale",
1318        "Two `messages` blocks in one bundle declare the same locale tag.",
1319    ),
1320    dg(
1321        "bynk.resolve.duplicate_method",
1322        "Two methods share a name.",
1323        &["fn_decl"],
1324    ),
1325    dg(
1326        "bynk.resolve.duplicate_param",
1327        "A parameter name is repeated.",
1328        &["param"],
1329    ),
1330    dg(
1331        "bynk.resolve.duplicate_provider",
1332        "A capability is provided more than once.",
1333        &["provider_decl"],
1334    ),
1335    dg(
1336        "bynk.resolve.duplicate_service",
1337        "Two services share a name.",
1338        &["service_decl"],
1339    ),
1340    dg(
1341        "bynk.resolve.duplicate_type",
1342        "Two types share a name.",
1343        &["type_decl"],
1344    ),
1345    dg(
1346        "bynk.resolve.duplicate_variant",
1347        "A sum type declares a variant twice.",
1348        &["sum_type"],
1349    ),
1350    d(
1351        "bynk.resolve.fn_without_call",
1352        "A function was referenced without being called.",
1353    ),
1354    dg(
1355        "bynk.resolve.let_shadows_fn",
1356        "A `let` binding shadows a function.",
1357        &["let_stmt"],
1358    ),
1359    dg(
1360        "bynk.resolve.let_shadows_type",
1361        "A `let` binding shadows a type.",
1362        &["let_stmt"],
1363    ),
1364    d(
1365        "bynk.resolve.method_unknown_type",
1366        "A method is defined on an unknown type.",
1367    ),
1368    dg(
1369        "bynk.resolve.missing_field",
1370        "A record construction omits a required field.",
1371        &["record_construction"],
1372    ),
1373    d(
1374        "bynk.resolve.name_conflict",
1375        "Two declarations share a name.",
1376    ),
1377    dg(
1378        "bynk.resolve.not_a_record_type",
1379        "Record syntax was used on a non-record type.",
1380        &["record_construction"],
1381    ),
1382    dg(
1383        "bynk.resolve.opaque_record_construction",
1384        "An opaque type was constructed with record syntax.",
1385        &["record_construction"],
1386    ),
1387    dg(
1388        "bynk.resolve.param_as_function",
1389        "A value (such as a parameter) was called as a function.",
1390        &["call"],
1391    ),
1392    dg(
1393        "bynk.resolve.recursive_record_field",
1394        "A record directly contains a field of its own type.",
1395        &["record_type"],
1396    ),
1397    dg(
1398        "bynk.resolve.reserved_builtin_type",
1399        "A type declaration reuses a compiler-known built-in type name.",
1400        &["type_decl"],
1401    ),
1402    dg(
1403        "bynk.resolve.self_outside_method",
1404        "`self` referenced outside a method or handler.",
1405        &["self_expr"],
1406    ),
1407    dg(
1408        "bynk.resolve.type_as_function",
1409        "A type name was called as if it were a function.",
1410        &["call"],
1411    ),
1412    d(
1413        "bynk.resolve.type_in_expr",
1414        "A type name was used where a value is expected.",
1415    ),
1416    dg(
1417        "bynk.resolve.unconsumed_context",
1418        "A context's service was called without a `consumes` declaration.",
1419        &["consumes_decl"],
1420    ),
1421    dg(
1422        "bynk.resolve.unknown_field",
1423        "Accessed a field the record does not have.",
1424        &["field_access"],
1425    ),
1426    dg(
1427        "bynk.resolve.unknown_function",
1428        "Called a function that does not exist.",
1429        &["call"],
1430    ),
1431    d(
1432        "bynk.resolve.unknown_name",
1433        "Referenced a name that is not in scope.",
1434    ),
1435    dg(
1436        "bynk.resolve.unknown_static_member",
1437        "Referenced an unknown static member (e.g. `T.x`).",
1438        &["field_access"],
1439    ),
1440    d(
1441        "bynk.resolve.unknown_type",
1442        "Referenced a type that does not exist.",
1443    ),
1444    d(
1445        "bynk.secrets.computed_name",
1446        "A `bynk.Secrets` read names its secret with a computed expression rather than a literal, so `bynk deploy` cannot plan it (warning).",
1447    ),
1448    dg(
1449        "bynk.send.in_pure_context",
1450        "A `~>` send was used in a pure (non-effectful) context.",
1451        &["effect_send_stmt"],
1452    ),
1453    dg(
1454        "bynk.send.non_effect",
1455        "A `~>` send was applied to a non-`Effect` value.",
1456        &["effect_send_stmt"],
1457    ),
1458    dg(
1459        "bynk.send.requires_unit",
1460        "A `~>` send targets an operation whose reply is not `Effect[()]`.",
1461        &["effect_send_stmt"],
1462    ),
1463    dg(
1464        "bynk.service.missing_from",
1465        "A `from`-less service has a handler other than `on call`.",
1466        &["service_decl"],
1467    ),
1468    dg(
1469        "bynk.service.mixed_protocols",
1470        "A service mixes handler forms that do not match its `from <protocol>`.",
1471        &["service_decl"],
1472    ),
1473    dg(
1474        "bynk.service.outside_context",
1475        "A `service` was declared outside a context.",
1476        &["service_decl"],
1477    ),
1478    dg(
1479        "bynk.service.return_not_effect",
1480        "A service handler's return type is not an `Effect`.",
1481        &["service_decl"],
1482    ),
1483    dg(
1484        "bynk.service.unknown_protocol",
1485        "A `from <protocol>` names an unknown protocol (e.g. a transport like Kafka).",
1486        &["service_decl"],
1487    ),
1488    d(
1489        "bynk.service.websocket_header",
1490        "The `from websocket` header is malformed — it binds frame types as `websocket(in: <type>, out: <type>)` (real-time track slice 3).",
1491    ),
1492    d(
1493        "bynk.service.websocket_multiple",
1494        "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).",
1495    ),
1496    d(
1497        "bynk.service.websocket_open_arity",
1498        "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).",
1499    ),
1500    d(
1501        "bynk.store.annotation_kind_mismatch",
1502        "A storage annotation is used on a kind it does not apply to (e.g. `@ttl` on a `Map`).",
1503    ),
1504    d(
1505        "bynk.store.annotation_unsupported",
1506        "A known storage annotation (`@ttl`/`@retain`/`@indexed`/`@bounded`) is used before the slice that supports it.",
1507    ),
1508    d(
1509        "bynk.store.cache_needs_clock",
1510        "A handler performs a `Cache` operation (TTL expiry reads the clock) without declaring `given Clock`.",
1511    ),
1512    d(
1513        "bynk.store.cache_ttl_required",
1514        "A `Cache` field is missing its required `@ttl(<duration>)` annotation (a keyed store with no expiry is a `Map`).",
1515    ),
1516    d(
1517        "bynk.store.kind_arity",
1518        "A storage kind was applied to the wrong number of type arguments (e.g. `Cell[A, B]`).",
1519    ),
1520    d(
1521        "bynk.store.kind_unsupported",
1522        "A known storage kind (`Queue`) is used before the slice that supports it.",
1523    ),
1524    d(
1525        "bynk.store.log_needs_clock",
1526        "A handler calls `Log.append` (which stamps the current time) without declaring `given Clock`.",
1527    ),
1528    d(
1529        "bynk.store.unknown_annotation",
1530        "A `store` field carries an annotation outside the closed `@indexed`/`@ttl`/`@retain`/`@bounded` set.",
1531    ),
1532    d(
1533        "bynk.store.unknown_kind",
1534        "A `store` field's type is not a known storage kind.",
1535    ),
1536    d(
1537        "bynk.store.unknown_map_accessor",
1538        "A `store Map` field access is not one of its query accessors (`entries`/`keys`/`values`).",
1539    ),
1540    d(
1541        "bynk.store.unknown_op",
1542        "A storage-`Map`/`Set` operation is not a recognised entry/membership method.",
1543    ),
1544    d(
1545        "bynk.stub.bad_sequence",
1546        "A `stub … returns each […]` sequence is malformed (e.g. empty).",
1547    ),
1548    d(
1549        "bynk.stub.not_a_seam",
1550        "A test `stub` overrides a capability the unit under test does not consume.",
1551    ),
1552    d(
1553        "bynk.stub.rhs_type",
1554        "A test `stub … returns <value>` right-hand side does not match the operation's return type.",
1555    ),
1556    d(
1557        "bynk.stub.unknown_op",
1558        "A test `stub` names an operation the capability does not declare.",
1559    ),
1560    dg(
1561        "bynk.suite.duplicate_case_name",
1562        "Two `case`s share a description.",
1563        &["case"],
1564    ),
1565    dg(
1566        "bynk.suite.unknown_target",
1567        "A `suite` targets a unit that does not exist.",
1568        &["suite_decl"],
1569    ),
1570    d(
1571        "bynk.target.browser_bundle_only",
1572        "The `browser` platform builds only the in-process `Bundle` topology; `--target workers` is not a browser build.",
1573    ),
1574    dg(
1575        "bynk.target.vendor_conflict",
1576        "One deployment unit's in-process closure uses platform-native capabilities from two mutually-exclusive platforms.",
1577        &["consumes_decl"],
1578    ),
1579    dg(
1580        "bynk.target.vendor_required",
1581        "A deployment unit uses a platform-native capability but the build selects another `--platform`.",
1582        &["consumes_decl"],
1583    ),
1584    dg(
1585        "bynk.test.actor_identity_required",
1586        "A call-site `by <Actor>` omits the identity an identity-carrying actor requires.",
1587        &["case"],
1588    ),
1589    dg(
1590        "bynk.test.actor_no_identity",
1591        "A call-site `by <Actor>(x)` supplies an identity to an actor that takes none — a unit-identity actor (e.g. `Visitor`) or `Nobody`.",
1592        &["case"],
1593    ),
1594    dg(
1595        "bynk.test.credential_needs_system",
1596        "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.",
1597        &["case"],
1598    ),
1599    dg(
1600        "bynk.test.nobody_needs_secured_route",
1601        "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.",
1602        &["case"],
1603    ),
1604    dg(
1605        "bynk.test.principal_identity_mismatch",
1606        "A call-site `by <Actor>` acts as an actor whose identity is incompatible with the addressed handler's actor.",
1607        &["case"],
1608    ),
1609    dg(
1610        "bynk.test.principal_on_wrong_method",
1611        "A wrong-method `405` test carries a `by <Actor>` clause; it reaches no handler, so a principal is meaningless.",
1612        &["case"],
1613    ),
1614    dg(
1615        "bynk.test.principal_required",
1616        "A test drives an identity-carrying handler with no call-site `by <Actor>(<identity>)`.",
1617        &["case"],
1618    ),
1619    dg(
1620        "bynk.test.service_bad_address",
1621        "A test body addresses a service the wrong way for its protocol (e.g. an http route without a leading path string).",
1622        &["case"],
1623    ),
1624    dg(
1625        "bynk.test.service_call_arity",
1626        "A test body's `svc.call(...)` passes the wrong number of arguments for the service's `on call` handler.",
1627        &["case"],
1628    ),
1629    dg(
1630        "bynk.test.service_no_call_handler",
1631        "A test body invokes `svc.call(...)` on a service with no `on call` handler (a `from http`/`cron`/`queue` service).",
1632        &["case"],
1633    ),
1634    dg(
1635        "bynk.test.service_unknown_route",
1636        "A test body addresses an http route / cron schedule / queue message the service does not declare.",
1637        &["case"],
1638    ),
1639    dg(
1640        "bynk.test.unknown_actor",
1641        "A call-site `by <Actor>` names an actor the target context does not declare and that is not a prelude actor.",
1642        &["case"],
1643    ),
1644    dg(
1645        "bynk.test.wire_needs_system",
1646        "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.",
1647        &["case"],
1648    ),
1649    d(
1650        "bynk.tier.property_has_tier",
1651        "A `property` carries an `as <tier>` clause; tiers are a `case`-only affordance.",
1652    ),
1653    d(
1654        "bynk.tier.system_needs_wire",
1655        "An `as system` test stands up fewer than two contexts; the system tier wires across contexts.",
1656    ),
1657    d(
1658        "bynk.transition.cross_agent_reference",
1659        "A transition predicate references another agent; step invariants are per-agent.",
1660    ),
1661    d(
1662        "bynk.transition.duplicate_name",
1663        "An agent declares two transitions with the same name.",
1664    ),
1665    d(
1666        "bynk.transition.impure_predicate",
1667        "A transition predicate uses an effectful or test-only construct; a step invariant must be pure.",
1668    ),
1669    d(
1670        "bynk.transition.no_step_reference",
1671        "A transition references neither `old` nor `new`; it constrains one state, so it is an `invariant`, not a step.",
1672    ),
1673    d(
1674        "bynk.transition.not_bool",
1675        "A transition predicate does not have type `Bool`.",
1676    ),
1677    d(
1678        "bynk.types.ambiguous_constructor",
1679        "`Ok`/`Err` is ambiguous between `Result` and `HttpResult`; qualify it.",
1680    ),
1681    dg(
1682        "bynk.types.argument_mismatch",
1683        "A function argument has the wrong type.",
1684        &["call"],
1685    ),
1686    dg(
1687        "bynk.types.call_arity",
1688        "A function value was applied with the wrong number of arguments.",
1689        &["call"],
1690    ),
1691    dg(
1692        "bynk.types.cannot_infer_option_type_param",
1693        "The value type of `None` could not be inferred.",
1694        &["none_expr"],
1695    ),
1696    d(
1697        "bynk.types.cannot_infer_result_type_params",
1698        "The type parameters of a `Result` could not be inferred.",
1699    ),
1700    dg(
1701        "bynk.types.catastrophic_regex",
1702        "A `Matches` predicate nests unbounded quantifiers, risking catastrophic backtracking (ReDoS).",
1703        &["refinement"],
1704    ),
1705    d(
1706        "bynk.types.constructor_arity",
1707        "A variant constructor got the wrong number of arguments.",
1708    ),
1709    d(
1710        "bynk.types.constructor_base_mismatch",
1711        "A `.of` constructor was given an argument of the wrong base type.",
1712    ),
1713    dg(
1714        "bynk.types.duplicate_literal_arm",
1715        "A `match` has two arms for the same literal value.",
1716        &["match_arm"],
1717    ),
1718    dg(
1719        "bynk.types.duplicate_variant_arm",
1720        "A `match` has two arms for the same variant.",
1721        &["match_arm"],
1722    ),
1723    d(
1724        "bynk.types.embeds_ambiguous",
1725        "A type is embedded by more than one variant of a sum, so `?`'s conversion would be ambiguous.",
1726    ),
1727    d(
1728        "bynk.types.embeds_unknown_variant",
1729        "An `embeds … as V` clause names a variant the sum does not declare.",
1730    ),
1731    d(
1732        "bynk.types.embeds_variant_shape",
1733        "An `embeds E as V` target variant must have exactly one payload field, of type `E`.",
1734    ),
1735    dg(
1736        "bynk.types.empty_refinement",
1737        "A refinement admits no values (contradictory predicates).",
1738        &["refinement"],
1739    ),
1740    dg(
1741        "bynk.types.err_value_mismatch",
1742        "An `Err` payload has the wrong type.",
1743        &["err_expr"],
1744    ),
1745    dg(
1746        "bynk.types.field_access_on_non_record",
1747        "Field access on a value that is not a record.",
1748        &["field_access"],
1749    ),
1750    dg(
1751        "bynk.types.field_refinement_not_base",
1752        "An inline field refinement requires a base or refined type.",
1753        &["record_field"],
1754    ),
1755    dg(
1756        "bynk.types.field_value_mismatch",
1757        "A record field was given a value of the wrong type.",
1758        &["record_construction"],
1759    ),
1760    dg(
1761        "bynk.types.function_at_boundary",
1762        "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.",
1763        &["function_type_ref"],
1764    ),
1765    dg(
1766        "bynk.types.guard_not_bool",
1767        "A match-arm `if` guard is not a `Bool` expression.",
1768        &["match_arm"],
1769    ),
1770    d(
1771        "bynk.types.held_at_boundary",
1772        "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).",
1773    ),
1774    d(
1775        "bynk.types.held_not_comparable",
1776        "A held value (`Connection[F]`) is compared with `==`/`!=` — held values have identity, not value-equality (§2.9.3, real-time track slice 2).",
1777    ),
1778    dg(
1779        "bynk.types.if_branch_mismatch",
1780        "The branches of an `if` have different types.",
1781        &["if_expr"],
1782    ),
1783    dg(
1784        "bynk.types.if_non_bool_cond",
1785        "An `if` condition is not a `Bool`.",
1786        &["if_expr"],
1787    ),
1788    dg(
1789        "bynk.types.if_without_else_requires_unit",
1790        "An `if` with no `else` branch has a non-unit then-branch; the missing else defaults to `()`, so the branch must be `()` or `Effect[()]`.",
1791        &["if_expr"],
1792    ),
1793    d(
1794        "bynk.types.interpolation_non_scalar",
1795        "An interpolation hole holds a value with no string form.",
1796    ),
1797    dg(
1798        "bynk.types.invalid_regex",
1799        "A `Matches` predicate contains an invalid regular expression.",
1800        &["refinement"],
1801    ),
1802    dg(
1803        "bynk.types.inverted_range",
1804        "An `InRange` predicate has its bounds inverted.",
1805        &["refinement"],
1806    ),
1807    dg(
1808        "bynk.types.is_base_mismatch",
1809        "An `is` refinement check is applied to a value of the wrong base type.",
1810        &["is_expr"],
1811    ),
1812    dg(
1813        "bynk.types.is_literal_pattern",
1814        "A literal was used on the right of `is`; `is` tests type/refinement, not value equality (use `==`).",
1815        &["is_expr"],
1816    ),
1817    dg(
1818        "bynk.types.is_non_sum",
1819        "`is` was applied to a value that is not a sum type.",
1820        &["is_expr"],
1821    ),
1822    dg(
1823        "bynk.types.is_refined_pattern",
1824        "A refined (`where`) pattern was used on the right of `is`; refined patterns are `match`-only.",
1825        &["is_expr"],
1826    ),
1827    dg(
1828        "bynk.types.is_unknown_variant",
1829        "`is` names a variant the type does not have.",
1830        &["is_expr"],
1831    ),
1832    dg(
1833        "bynk.types.json_uncodable",
1834        "A `Json.encode`/`Json.decode` target type cannot pass through the typed JSON codec (functions, effects, error builtins).",
1835        &["method_call"],
1836    ),
1837    dg(
1838        "bynk.types.key_not_orderable",
1839        "A `sortBy`/`min`/`max` key function does not return an orderable type (`Int`, `Float`, `String`, `Duration`, or `Instant`).",
1840        &[],
1841    ),
1842    dg(
1843        "bynk.types.lambda_mismatch",
1844        "A lambda's parameter count, parameter annotations, or body type do not match the expected function type.",
1845        &["lambda_expr"],
1846    ),
1847    dg(
1848        "bynk.types.let_annotation_mismatch",
1849        "A `let` value does not match its type annotation.",
1850        &["let_stmt"],
1851    ),
1852    dg(
1853        "bynk.types.list_element_mismatch",
1854        "A list-literal element has a different type from the list's element type.",
1855        &["list_literal"],
1856    ),
1857    dg(
1858        "bynk.types.match_arm_mismatch",
1859        "A `match` arm has a different type from the others.",
1860        &["match_arm"],
1861    ),
1862    dg(
1863        "bynk.types.match_non_sum_discriminant",
1864        "`match` was applied to a value that is not a sum type.",
1865        &["match_expr"],
1866    ),
1867    dg(
1868        "bynk.types.method_arity",
1869        "A method was called with the wrong number of arguments.",
1870        &["method_call"],
1871    ),
1872    dg(
1873        "bynk.types.method_not_found",
1874        "Called a method the type does not have.",
1875        &["method_call"],
1876    ),
1877    dg(
1878        "bynk.types.method_on_non_named_type",
1879        "A method was called on a built-in type that has no methods.",
1880        &["method_call"],
1881    ),
1882    dg(
1883        "bynk.types.mixed_pattern_bindings",
1884        "A pattern mixes named and positional bindings.",
1885        &["variant_pattern"],
1886    ),
1887    dg(
1888        "bynk.types.negative_length",
1889        "A length predicate was given a negative value.",
1890        &["refinement"],
1891    ),
1892    dg(
1893        "bynk.types.no_numeric_coercion",
1894        "`Int` and `Float` were mixed without an explicit conversion — in an operation or in refinement bounds.",
1895        &["binary_expr", "refinement"],
1896    ),
1897    dg(
1898        "bynk.types.non_exhaustive_match",
1899        "A `match` does not cover every variant.",
1900        &["match_expr"],
1901    ),
1902    dg(
1903        "bynk.types.ok_value_mismatch",
1904        "An `Ok` payload has the wrong type.",
1905        &["ok_expr"],
1906    ),
1907    dg(
1908        "bynk.types.opaque_raw_outside",
1909        "`.raw` on an opaque type was used outside its defining commons.",
1910        &["field_access"],
1911    ),
1912    dg(
1913        "bynk.types.opaque_record_construction",
1914        "An opaque type was constructed with record syntax.",
1915        &["record_construction"],
1916    ),
1917    dg(
1918        "bynk.types.opaque_unsafe_outside",
1919        "`.unsafe` on an opaque type was used outside its defining context.",
1920        &["field_access"],
1921    ),
1922    dg(
1923        "bynk.types.or_pattern_binding_mismatch",
1924        "An or-pattern's alternatives don't all bind the same set of names.",
1925        &["match_arm", "is_expr"],
1926    ),
1927    dg(
1928        "bynk.types.or_pattern_type_mismatch",
1929        "An or-pattern's alternatives give a shared binding different types (or refinements).",
1930        &["match_arm", "is_expr"],
1931    ),
1932    dg(
1933        "bynk.types.pattern_arity",
1934        "A pattern binds the wrong number of payload fields.",
1935        &["variant_pattern"],
1936    ),
1937    dg(
1938        "bynk.types.pattern_type_mismatch",
1939        "A pattern's type does not match the matched value.",
1940        &["variant_pattern"],
1941    ),
1942    dg(
1943        "bynk.types.predicate_base_mismatch",
1944        "A predicate does not apply to the type's base (e.g. a string predicate on an `Int`).",
1945        &["refinement"],
1946    ),
1947    d(
1948        "bynk.types.query_at_boundary",
1949        "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).",
1950    ),
1951    dg(
1952        "bynk.types.question_error_mismatch",
1953        "`?` propagates an error type incompatible with the function's.",
1954        &["question_expr"],
1955    ),
1956    dg(
1957        "bynk.types.question_on_non_result",
1958        "`?` was applied to a non-`Result` value.",
1959        &["question_expr"],
1960    ),
1961    dg(
1962        "bynk.types.question_option_outside_http",
1963        "`?` lifts an `Option` only inside a handler returning `HttpResult` (`None` becomes `NotFound`); elsewhere use `.okOr(err)`.",
1964        &["question_expr"],
1965    ),
1966    dg(
1967        "bynk.types.question_outside_result",
1968        "`?` used in a function that does not return a `Result`.",
1969        &["question_expr"],
1970    ),
1971    d(
1972        "bynk.types.return_mismatch",
1973        "A returned value does not match the declared return type.",
1974    ),
1975    dg(
1976        "bynk.types.some_value_mismatch",
1977        "A `Some` payload has the wrong type.",
1978        &["some_expr"],
1979    ),
1980    d(
1981        "bynk.types.stream_at_boundary",
1982        "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).",
1983    ),
1984    d(
1985        "bynk.types.stream_not_comparable",
1986        "A `Stream` value is compared with `==`/`!=` — a stream is a live value-over-time source, not a comparable value (real-time track slice 0).",
1987    ),
1988    d(
1989        "bynk.types.type_mismatch",
1990        "Two types that were required to match did not.",
1991    ),
1992    dg(
1993        "bynk.types.uninferable_element_type",
1994        "An empty `[]` (or `List.empty()` / `Map.empty()`) has no expected type to infer its element type from.",
1995        &["list_literal"],
1996    ),
1997    dg(
1998        "bynk.types.unkeyable_distinct",
1999        "A `distinct`/`distinctBy` element or key is not value-keyable (`String`, `Int`, or a refined/opaque type over them).",
2000        &[],
2001    ),
2002    dg(
2003        "bynk.types.unkeyable_map_key",
2004        "A `Map` key type is not value-keyable (`String`, `Int`, or a refined/opaque type over them).",
2005        &["generic_type_ref"],
2006    ),
2007    dg(
2008        "bynk.types.unknown_field",
2009        "Referenced a field the record type does not declare.",
2010        &["field_access"],
2011    ),
2012    dg(
2013        "bynk.types.unknown_pattern_field",
2014        "A pattern names a field the variant does not have.",
2015        &["variant_pattern"],
2016    ),
2017    dg(
2018        "bynk.types.unknown_static_member",
2019        "Referenced an unknown static member on a type.",
2020        &["field_access"],
2021    ),
2022    dg(
2023        "bynk.types.unknown_variant_in_pattern",
2024        "A pattern names a variant the sum type does not have.",
2025        &["variant_pattern"],
2026    ),
2027    dg(
2028        "bynk.types.unreachable_arm",
2029        "A `match` arm is unreachable.",
2030        &["match_arm"],
2031    ),
2032    d(
2033        "bynk.types.variant_arity",
2034        "A variant constructor got the wrong number of payload values.",
2035    ),
2036    d(
2037        "bynk.types.variant_missing_payload",
2038        "A variant requiring a payload was used without one.",
2039    ),
2040    d(
2041        "bynk.types.variant_payload_mismatch",
2042        "A variant payload has the wrong type.",
2043    ),
2044    dg(
2045        "bynk.uses.name_conflict",
2046        "A `uses` name collides with another name.",
2047        &["uses_decl"],
2048    ),
2049    dg(
2050        "bynk.uses.self_reference",
2051        "A commons `uses` itself.",
2052        &["uses_decl"],
2053    ),
2054    dg(
2055        "bynk.uses.target_is_context",
2056        "`uses` targets a context instead of a commons.",
2057        &["uses_decl"],
2058    ),
2059    dg(
2060        "bynk.uses.unknown_commons",
2061        "`uses` names a commons that does not exist.",
2062        &["uses_decl"],
2063    ),
2064    dg(
2065        "bynk.val.agent_not_generable",
2066        "A `for all`/`Val` cannot generate an agent — fabricated agent states need not be reachable.",
2067        &["for_all"],
2068    ),
2069    dg(
2070        "bynk.val.arity",
2071        "`Val[T]` was given the wrong number of pin arguments.",
2072        &["val_expr"],
2073    ),
2074    dg(
2075        "bynk.val.literal_violates",
2076        "A pinned `Val[T]` value violates the type's refinement.",
2077        &["val_expr"],
2078    ),
2079    dg(
2080        "bynk.val.needs_pin",
2081        "A bare `Val[T]` cannot generate a value (e.g. a `Matches` string); pin one.",
2082        &["val_expr"],
2083    ),
2084    dg(
2085        "bynk.val.outside_test",
2086        "`Val[T]` was used outside a test case body.",
2087        &["val_expr"],
2088    ),
2089    dg(
2090        "bynk.val.pin_not_literal",
2091        "A `Val[T]` pin argument is not a compile-time literal.",
2092        &["val_expr"],
2093    ),
2094    dg(
2095        "bynk.val.pin_unsupported",
2096        "A pin was given for a type kind that does not support pinning.",
2097        &["val_expr"],
2098    ),
2099    dg(
2100        "bynk.val.unknown_type",
2101        "`Val[T]` names a type that does not resolve.",
2102        &["val_expr"],
2103    ),
2104    dg(
2105        "bynk.val.unsupported_kind",
2106        "`Val[T]` cannot fabricate a value for this kind of type.",
2107        &["val_expr"],
2108    ),
2109    d(
2110        "bynk.ws.message_frame_param",
2111        "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).",
2112    ),
2113    d(
2114        "bynk.ws.open_given_unsupported",
2115        "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).",
2116    ),
2117    d(
2118        "bynk.ws.open_transfer_shape",
2119        "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).",
2120    ),
2121    d(
2122        "bynk.ws.route_param_mismatch",
2123        "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).",
2124    ),
2125];
2126
2127/// A diagnostic with no single governing grammar construct.
2128const fn d(code: &'static str, summary: &'static str) -> DiagnosticInfo {
2129    DiagnosticInfo {
2130        code,
2131        summary,
2132        grammar_symbol: &[],
2133    }
2134}
2135
2136/// A diagnostic that constrains one or more grammar productions.
2137const fn dg(
2138    code: &'static str,
2139    summary: &'static str,
2140    grammar_symbol: &'static [&'static str],
2141) -> DiagnosticInfo {
2142    DiagnosticInfo {
2143        code,
2144        summary,
2145        grammar_symbol,
2146    }
2147}
2148
2149/// The category segment of a code (the part between the first two dots), e.g.
2150/// `"types"` for `"bynk.types.type_mismatch"`.
2151pub fn category(code: &str) -> &str {
2152    code.split('.').nth(1).unwrap_or("")
2153}
2154
2155/// A human-readable heading for a category segment.
2156fn category_title(cat: &str) -> &'static str {
2157    match cat {
2158        "agent" | "agents" => "Agents",
2159        "boundary" => "Boundaries",
2160        "capability" => "Capabilities",
2161        "consumes" => "Consumes",
2162        "context" => "Contexts",
2163        "contract" => "Contracts",
2164        "cron" => "Cron",
2165        "effect" => "Effects",
2166        "expect" => "Expectations",
2167        "exports" => "Exports",
2168        "given" => "Given capabilities",
2169        "http" => "HTTP",
2170        "lex" => "Lexer",
2171        "messages" => "Message bundles",
2172        "mock" => "Mocks (collaborators)",
2173        "observe" => "Observation",
2174        "parse" => "Parser",
2175        "project" => "Project",
2176        "property" => "Properties (generative tests)",
2177        "provider" => "Providers",
2178        "queue" => "Queue",
2179        "record_spread" => "Record spread",
2180        "refine" => "Refinement",
2181        "resolve" => "Resolution",
2182        "service" => "Services",
2183        "suite" => "Suites and cases",
2184        "transition" => "Transitions (step invariants)",
2185        "types" => "Type checking",
2186        "uses" => "Uses",
2187        "val" => "Value fabrication",
2188        _ => "Other",
2189    }
2190}
2191
2192/// Render the diagnostic index as a Markdown reference page, grouped by
2193/// category. This is the generator behind
2194/// `site/src/content/docs/book/reference/diagnostics.md`.
2195pub fn render_markdown() -> String {
2196    use std::collections::BTreeMap;
2197
2198    // Group codes by their category title, preserving sorted code order.
2199    let mut by_category: BTreeMap<&str, Vec<&DiagnosticInfo>> = BTreeMap::new();
2200    for info in REGISTRY {
2201        by_category
2202            .entry(category_title(category(info.code)))
2203            .or_default()
2204            .push(info);
2205    }
2206
2207    let mut out = String::new();
2208    out.push_str("# Diagnostic index\n\n");
2209    out.push_str(
2210        "<!-- GENERATED FILE — do not edit by hand.\n     \
2211         Source: bynkc/src/diagnostics.rs (`render_markdown`).\n     \
2212         Regenerate with: BYNK_BLESS=1 cargo test -p bynkc --test diagnostics_registry -->\n\n",
2213    );
2214    out.push_str(
2215        "Every diagnostic code the compiler can emit, with a one-line summary of \
2216         the cause, grouped by category. For step-by-step cause-and-fix guidance \
2217         on the most common ones, see the [troubleshooting guides](../troubleshooting/index.md).\n\n",
2218    );
2219    out.push_str(&format!(
2220        "There are **{}** codes in total.\n",
2221        REGISTRY.len()
2222    ));
2223
2224    for (title, infos) in &by_category {
2225        out.push_str(&format!("\n## {title}\n\n"));
2226        out.push_str("| Code | Summary | Construct |\n|---|---|---|\n");
2227        for info in infos {
2228            // The construct column deep-links each governing production to its
2229            // entry in the annotated grammar reference; generated from
2230            // `grammar_symbol` (each value is an embeddable rule, so the
2231            // `#rule-<raw>` anchor resolves — enforced in diagnostics_registry).
2232            let construct = info
2233                .grammar_symbol
2234                .iter()
2235                .map(|sym| format!("[`{sym}`](grammar.md#rule-{sym})"))
2236                .collect::<Vec<_>>()
2237                .join(", ");
2238            // A curated (`bynk explain`-able) code links to its Book concept
2239            // page; the in-site link is validated by the site's link checker,
2240            // so a moved page or renamed anchor fails the build (#853). Codes
2241            // without an explanation render as plain inline code.
2242            let code_cell = match explain(info.code) {
2243                Some(e) => format!("[`{}`]({})", info.code, e.in_site_link()),
2244                None => format!("`{}`", info.code),
2245            };
2246            out.push_str(&format!(
2247                "| {} | {} | {} |\n",
2248                code_cell, info.summary, construct
2249            ));
2250        }
2251    }
2252
2253    out
2254}
2255
2256/// Invert the registry into a `{ "<rule>": [ { code, summary }, … ], … }` map,
2257/// serialised as pretty JSON with sorted keys and sorted codes. Only rules with
2258/// at least one diagnostic appear. This is the generator behind
2259/// `docs/grammar-semantics.json`, which the `{{#grammar-semantics <rule>}}`
2260/// preprocessor directive consumes.
2261pub fn render_grammar_semantics_json() -> String {
2262    use std::collections::BTreeMap;
2263
2264    // REGISTRY is sorted by code, so each rule's vector comes out code-sorted;
2265    // the BTreeMap gives sorted rule names.
2266    let mut by_symbol: BTreeMap<&str, Vec<&DiagnosticInfo>> = BTreeMap::new();
2267    for info in REGISTRY {
2268        for sym in info.grammar_symbol {
2269            by_symbol.entry(sym).or_default().push(info);
2270        }
2271    }
2272
2273    let mut map = serde_json::Map::new();
2274    map.insert(
2275        "_generated".to_string(),
2276        serde_json::Value::String(
2277            "Generated from the grammar_symbol field of bynkc/src/diagnostics.rs. \
2278             Do not edit by hand. Regenerate with: BYNK_BLESS=1 cargo test -p \
2279             bynkc --test diagnostics_registry"
2280                .to_string(),
2281        ),
2282    );
2283    for (sym, infos) in by_symbol {
2284        let arr: Vec<serde_json::Value> = infos
2285            .iter()
2286            .map(|info| serde_json::json!({ "code": info.code, "summary": info.summary }))
2287            .collect();
2288        map.insert(sym.to_string(), serde_json::Value::Array(arr));
2289    }
2290
2291    let mut s =
2292        serde_json::to_string_pretty(&serde_json::Value::Object(map)).expect("serialise semantics");
2293    s.push('\n');
2294    s
2295}