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