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/// Every diagnostic code the compiler emits, sorted by code.
34pub const REGISTRY: &[DiagnosticInfo] = &[
35    d(
36        "bynk.actor.bearer_identity_not_string_constructible",
37        "A `Bearer` actor's identity is not a string-constructible type.",
38    ),
39    d(
40        "bynk.actor.bearer_missing_secret",
41        "A `Bearer` actor does not name its signing secret.",
42    ),
43    d(
44        "bynk.actor.binder_shadows_param",
45        "A `by` actor binder collides with a handler parameter of the same name.",
46    ),
47    d(
48        "bynk.actor.by_on_agent",
49        "A `by` actor clause was placed on an agent `on call` handler, which has no actor.",
50    ),
51    d(
52        "bynk.actor.duplicate_sum_scheme",
53        "Two peers in a multi-actor sum share an authentication scheme.",
54    ),
55    d(
56        "bynk.actor.identity_not_sealed",
57        "An actor identity type is not a context-ownable (sealed) value type.",
58    ),
59    d(
60        "bynk.actor.missing_by_on_http",
61        "An HTTP handler lacks the required `by` actor clause.",
62    ),
63    d(
64        "bynk.actor.outside_context",
65        "An `actor` was declared outside a context (e.g. in a commons).",
66    ),
67    d(
68        "bynk.actor.refinement_base_unsupported",
69        "A refinement actor's base is not a `Bearer` actor (no claims to authorise against).",
70    ),
71    d(
72        "bynk.actor.refinement_in_sum",
73        "A refinement actor appears as a member of a multi-actor sum.",
74    ),
75    d(
76        "bynk.actor.refinement_predicate_unsupported",
77        "A refinement actor's `where` predicate is outside the closed claim-predicate set.",
78    ),
79    d(
80        "bynk.actor.scheme_not_admissible",
81        "An actor's scheme is not admissible on this handler's protocol.",
82    ),
83    d(
84        "bynk.actor.signature_identity_unsupported",
85        "A `Signature` actor declared an `identity`, which is not yet supported.",
86    ),
87    d(
88        "bynk.actor.signature_missing_header",
89        "A `Signature` actor does not name its signature header.",
90    ),
91    d(
92        "bynk.actor.signature_missing_secret",
93        "A `Signature` actor does not name its signing secret.",
94    ),
95    d(
96        "bynk.actor.signature_requires_body",
97        "A `Signature` handler does not take a `body` parameter.",
98    ),
99    d(
100        "bynk.actor.signature_tolerance_without_timestamp",
101        "A `Signature` actor set `tolerance` without a `timestamp` header.",
102    ),
103    d(
104        "bynk.actor.sum_requires_binder",
105        "A multi-actor sum `by` clause has no binder to match the resolved actor.",
106    ),
107    d(
108        "bynk.actor.unknown_actor",
109        "A handler's `by` clause names an actor that is not declared.",
110    ),
111    d(
112        "bynk.actor.unknown_scheme",
113        "An actor declares an authentication scheme that is not compiler-known.",
114    ),
115    d(
116        "bynk.actor.unreachable_sum_arm",
117        "A multi-actor sum has an arm unreachable after a catch-all (`None`) peer.",
118    ),
119    dg(
120        "bynk.adapter.consumes_context",
121        "An `adapter` consumed a context; adapter dependencies are adapter-to-adapter.",
122        &["consumes_decl"],
123    ),
124    dg(
125        "bynk.adapter.consumes_requires_selection",
126        "An `adapter` used a whole-unit or aliased `consumes`; adapters must select capabilities with `consumes U { Cap, … }`.",
127        &["consumes_decl"],
128    ),
129    dg(
130        "bynk.adapter.disallowed_item",
131        "An `adapter` declared a `service`, `agent`, or other item it may not contain.",
132        &["adapter_decl"],
133    ),
134    dg(
135        "bynk.adapter.duplicate_binding",
136        "An `adapter` declared more than one `binding` clause.",
137        &["binding_decl"],
138    ),
139    dg(
140        "bynk.adapter.no_binding",
141        "An `adapter` declares an external provider but no `binding` module to supply it.",
142        &["adapter_decl"],
143    ),
144    dg(
145        "bynk.adapter.provider_has_body",
146        "A provider inside an `adapter` has a Bynk body; adapter providers must be external.",
147        &["provider_decl"],
148    ),
149    dg(
150        "bynk.agent.construction_arity",
151        "An agent was constructed with the wrong number of key arguments.",
152        &["agent_decl"],
153    ),
154    dg(
155        "bynk.agent.handler_arity",
156        "An agent handler was called with the wrong number of arguments.",
157        &["agent_decl"],
158    ),
159    dg(
160        "bynk.agent.handler_not_found",
161        "Called a handler the agent does not declare.",
162        &["agent_decl"],
163    ),
164    dg(
165        "bynk.agent.key_mismatch",
166        "An agent key argument has the wrong type.",
167        &["agent_decl"],
168    ),
169    dg(
170        "bynk.agent.outside_context",
171        "An `agent` was declared outside a context.",
172        &["agent_decl"],
173    ),
174    dg(
175        "bynk.agent.return_not_effect",
176        "An agent handler's return type is not an `Effect`.",
177        &["agent_decl"],
178    ),
179    dg(
180        "bynk.agents.bad_state_initialiser",
181        "An agent `store` field initialiser is not a static value of the field's type.",
182        &["store_field"],
183    ),
184    dg(
185        "bynk.agents.non_zeroable_state_field",
186        "An agent `store` field has no initialiser and no implicit zero value.",
187        &["store_field"],
188    ),
189    d(
190        "bynk.boundary.structural_mismatch",
191        "Data crossing a context boundary did not match the expected shape.",
192    ),
193    dg(
194        "bynk.capability.op_arity",
195        "A capability operation was called with the wrong number of arguments.",
196        &["capability_decl"],
197    ),
198    dg(
199        "bynk.capability.outside_context",
200        "A `capability` was declared outside a context.",
201        &["capability_decl"],
202    ),
203    dg(
204        "bynk.capability.unknown_operation",
205        "Referenced an operation the capability does not declare.",
206        &["capability_decl"],
207    ),
208    d(
209        "bynk.cell.invalid_target",
210        "A `:=` write targets something that is not a `store Cell` field.",
211    ),
212    d(
213        "bynk.cell.self_reference",
214        "A `:=` right-hand side reads the cell being written (a read-modify-write); use `.update`.",
215    ),
216    dg(
217        "bynk.consumes.alias_conflict",
218        "Two `consumes` aliases collide.",
219        &["consumes_decl"],
220    ),
221    dg(
222        "bynk.consumes.capability_name_clash",
223        "Two flattened `consumes U { Cap }` capabilities collide, or one clashes with a local capability.",
224        &["consumes_decl"],
225    ),
226    dg(
227        "bynk.consumes.in_commons",
228        "`consumes` appears in a `commons` (it is only valid in a context).",
229        &["consumes_decl"],
230    ),
231    dg(
232        "bynk.consumes.name_conflict",
233        "A `consumes` name collides with another name in scope.",
234        &["consumes_decl"],
235    ),
236    dg(
237        "bynk.consumes.self_reference",
238        "A context `consumes` itself.",
239        &["consumes_decl"],
240    ),
241    dg(
242        "bynk.consumes.service_arity",
243        "A consumed service was called with the wrong number of arguments.",
244        &["consumes_decl"],
245    ),
246    dg(
247        "bynk.consumes.target_is_commons",
248        "`consumes` targets a `commons` instead of a context.",
249        &["consumes_decl"],
250    ),
251    dg(
252        "bynk.consumes.unknown_context",
253        "`consumes` names a context that does not exist.",
254        &["consumes_decl"],
255    ),
256    dg(
257        "bynk.consumes.unknown_service",
258        "Called a service the consumed context does not declare.",
259        &["consumes_decl"],
260    ),
261    d(
262        "bynk.context.consumes_cycle",
263        "Contexts form a `consumes` dependency cycle.",
264    ),
265    d(
266        "bynk.context.external_construction",
267        "A context-owned type was constructed from outside that context.",
268    ),
269    dg(
270        "bynk.context.external_provider",
271        "A bodiless (external) provider was declared outside an `adapter`.",
272        &["provider_decl"],
273    ),
274    d(
275        "bynk.context.opaque_inspection",
276        "An opaquely-exported type was inspected from outside its context.",
277    ),
278    dg(
279        "bynk.cron.bad_params",
280        "A cron handler declares more than one parameter, or a non-`Int` one.",
281        &["cron_handler"],
282    ),
283    dg(
284        "bynk.cron.duplicate_schedule",
285        "Two cron handlers declare the same schedule.",
286        &["cron_handler"],
287    ),
288    dg(
289        "bynk.cron.invalid_schedule",
290        "A cron expression is not five whitespace-separated fields.",
291        &["cron_handler"],
292    ),
293    dg(
294        "bynk.cron.return_not_effect_result",
295        "A cron handler does not return `Effect[Result[(), E]]`.",
296        &["cron_handler"],
297    ),
298    d(
299        "bynk.duration.literal_overflow",
300        "A `Duration` literal (`<int>.<unit>`) exceeds the representable millisecond range.",
301    ),
302    dg(
303        "bynk.effect.bind_in_pure_context",
304        "An `<-` bind was used in a pure (non-effectful) context.",
305        &["effect_let_stmt"],
306    ),
307    dg(
308        "bynk.effect.bind_on_non_effect",
309        "An `<-` bind was applied to a non-`Effect` value.",
310        &["effect_let_stmt"],
311    ),
312    d(
313        "bynk.effect.capability_in_pure_context",
314        "A capability was used in a pure context.",
315    ),
316    d(
317        "bynk.effect.cross_context_in_pure_context",
318        "A cross-context call was made in a pure context.",
319    ),
320    dg(
321        "bynk.effect.fn_value_in_pure_context",
322        "An effectful function value was called in a pure context; like a capability call, it is legal only where the enclosing body is effectful.",
323        &["call"],
324    ),
325    dg(
326        "bynk.expect.not_bool",
327        "`expect` was given a non-`Bool` predicate.",
328        &["expect_expr"],
329    ),
330    dg(
331        "bynk.expect.outside_case",
332        "`expect` was used outside a `case` body.",
333        &["expect_expr"],
334    ),
335    dg(
336        "bynk.exports.capability_not_provided",
337        "An exported capability has no provider in its context.",
338        &["exports_decl"],
339    ),
340    dg(
341        "bynk.exports.conflicting_visibility",
342        "A type is exported with conflicting visibilities.",
343        &["exports_decl"],
344    ),
345    dg(
346        "bynk.exports.duplicate_export",
347        "The same name is exported more than once.",
348        &["exports_decl"],
349    ),
350    dg(
351        "bynk.exports.duplicate_in_clause",
352        "A name appears twice in one `exports` clause.",
353        &["exports_decl"],
354    ),
355    dg(
356        "bynk.exports.undeclared_capability",
357        "`exports capability` names a capability that is not declared.",
358        &["exports_decl"],
359    ),
360    dg(
361        "bynk.exports.undeclared_type",
362        "`exports` names a type that is not declared.",
363        &["exports_decl"],
364    ),
365    dg(
366        "bynk.generics.no_bounds",
367        "A type parameter carries a bound (`[A: …]`); bounded generics are not in v0.20a.",
368        &["fn_decl"],
369    ),
370    dg(
371        "bynk.generics.no_generic_types",
372        "A `type` declaration carries a type-parameter list; generic type declarations are not in v0.20a (type parameters belong to functions).",
373        &["type_decl"],
374    ),
375    dg(
376        "bynk.generics.type_arg_mismatch",
377        "Inferred or explicit type arguments conflict, have the wrong arity, target a non-generic function, or a type parameter shadows a declared type.",
378        &["call"],
379    ),
380    dg(
381        "bynk.generics.uninferable_type_arg",
382        "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.",
383        &["call"],
384    ),
385    dg(
386        "bynk.given.cross_context_unknown_capability",
387        "`given B.Cap` names a capability the consumed context does not export.",
388        &["given_clause"],
389    ),
390    dg(
391        "bynk.given.undeclared_capability",
392        "A handler uses a capability it did not declare with `given`.",
393        &["given_clause"],
394    ),
395    dg(
396        "bynk.given.unknown_capability",
397        "`given` names a capability that does not exist.",
398        &["given_clause"],
399    ),
400    dg(
401        "bynk.given.unused_capability",
402        "A `given` capability is never used (warning).",
403        &["given_clause"],
404    ),
405    d(
406        "bynk.held.branch_divergence",
407        "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).",
408    ),
409    d(
410        "bynk.held.consume_on_borrow",
411        "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).",
412    ),
413    d(
414        "bynk.held.leak",
415        "A held value (`Connection[F]`) is still owned at scope exit — it must be disposed (stored, closed, or transferred) before the handler returns (§2.9.1, real-time track slice 2).",
416    ),
417    d(
418        "bynk.held.unsupported_map_op",
419        "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).",
420    ),
421    d(
422        "bynk.held.unsupported_storage",
423        "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).",
424    ),
425    d(
426        "bynk.held.use_after_consume",
427        "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).",
428    ),
429    dg(
430        "bynk.http.body_on_get_or_delete",
431        "A GET or DELETE handler declares a `body` parameter.",
432        &["http_handler"],
433    ),
434    dg(
435        "bynk.http.duplicate_route",
436        "Two handlers share the same method and route.",
437        &["http_handler"],
438    ),
439    dg(
440        "bynk.http.extra_param",
441        "A handler parameter is neither a path parameter nor `body`.",
442        &["http_handler"],
443    ),
444    dg(
445        "bynk.http.invalid_path",
446        "An HTTP route path is malformed.",
447        &["http_handler"],
448    ),
449    dg(
450        "bynk.http.path_param_not_stringy",
451        "A path parameter's type is not constructible from a string.",
452        &["http_handler"],
453    ),
454    dg(
455        "bynk.http.reserved_prefix",
456        "A route uses the reserved `/_bynk/` prefix.",
457        &["http_handler"],
458    ),
459    dg(
460        "bynk.http.return_not_effect_http_result",
461        "An HTTP handler does not return `Effect[HttpResult[T]]`.",
462        &["http_handler"],
463    ),
464    dg(
465        "bynk.http.unbound_path_param",
466        "A `:name` route segment has no matching handler parameter.",
467        &["http_handler"],
468    ),
469    d(
470        "bynk.index.bad_argument",
471        "An `@indexed` argument is not a `by: <field>` label.",
472    ),
473    d(
474        "bynk.index.missing",
475        "A query filters a map by equality on a field that is not `@indexed` (a perf-hint warning).",
476    ),
477    d(
478        "bynk.index.unkeyable_key",
479        "An `@indexed(by: k)` field is not value-keyable.",
480    ),
481    d(
482        "bynk.index.unknown_key",
483        "An `@indexed(by: k)` field is not a field of the map's value type.",
484    ),
485    d(
486        "bynk.index.unused",
487        "A declared `@indexed(by: k)` is never used by an equality filter (a hygiene warning).",
488    ),
489    dg(
490        "bynk.integration.duplicate_participant",
491        "A context is listed more than once in a `wires` clause.",
492        &["wires_decl"],
493    ),
494    dg(
495        "bynk.integration.duplicate_suite",
496        "Two integration tests share the same suite name.",
497        &["integration_decl"],
498    ),
499    dg(
500        "bynk.integration.mock_in_integration",
501        "`mocks` is not allowed in an integration test.",
502        &["mocks_decl"],
503    ),
504    dg(
505        "bynk.integration.too_few_participants",
506        "An integration test wires fewer than two contexts.",
507        &["wires_decl"],
508    ),
509    dg(
510        "bynk.integration.unknown_participant",
511        "A `wires` clause names something that is not a declared context.",
512        &["wires_decl"],
513    ),
514    dg(
515        "bynk.integration.unwired_dependency",
516        "A participant consumes a context that is not wired into the integration test.",
517        &["integration_decl"],
518    ),
519    d(
520        "bynk.invariant.cross_agent_reference",
521        "An invariant predicate references another agent; invariants are per-agent.",
522    ),
523    d(
524        "bynk.invariant.duplicate_name",
525        "An agent declares two invariants with the same name.",
526    ),
527    d(
528        "bynk.invariant.impure_predicate",
529        "An invariant predicate uses an effectful or test-only construct.",
530    ),
531    d(
532        "bynk.invariant.not_bool",
533        "An invariant predicate does not have type `Bool`.",
534    ),
535    dg(
536        "bynk.lambda.unannotated_param",
537        "A lambda parameter has no type annotation in a position where no function type is expected to infer it from.",
538        &["lambda_expr"],
539    ),
540    dg(
541        "bynk.lex.bad_escape",
542        "An invalid escape sequence in a string literal.",
543        &["string_literal"],
544    ),
545    dg(
546        "bynk.lex.float_literal_overflow",
547        "A float literal does not fit a finite 64-bit float.",
548        &["float_literal"],
549    ),
550    dg(
551        "bynk.lex.integer_overflow",
552        "An integer literal is out of range.",
553        &["number_literal"],
554    ),
555    d(
556        "bynk.lex.unclosed_doc_block",
557        "A documentation block is not closed.",
558    ),
559    d(
560        "bynk.lex.unexpected_character",
561        "An unexpected character in the source.",
562    ),
563    dg(
564        "bynk.lex.unterminated_interpolation",
565        "An interpolation hole `\\(…)` is not closed on its line.",
566        &["string_literal"],
567    ),
568    dg(
569        "bynk.lex.unterminated_string",
570        "A string literal is not terminated.",
571        &["string_literal"],
572    ),
573    d(
574        "bynk.list.deprecated_function",
575        "A `bynk.list` free function (`map`/`filter`/`find`/`any`/`all`) is deprecated in favour of the `List` method form (warning; auto-fixable).",
576    ),
577    dg(
578        "bynk.mock.duplicate_target",
579        "A `mocks` target is declared more than once.",
580        &["mocks_decl"],
581    ),
582    dg(
583        "bynk.mock.in_commons_test",
584        "`mocks` used in a commons test, where there is no dependency to inject.",
585        &["mocks_decl"],
586    ),
587    dg(
588        "bynk.mock.signature_mismatch",
589        "A `mocks` implementation's signature does not match the capability.",
590        &["mocks_decl"],
591    ),
592    dg(
593        "bynk.mock.unknown_target",
594        "`mocks` names a capability that is not in scope.",
595        &["mocks_decl"],
596    ),
597    d(
598        "bynk.namespace.reserved",
599        "A user unit is named `bynk` or `bynk.*`; the `bynk` root is reserved for the toolchain.",
600    ),
601    dg(
602        "bynk.parse.consumes_after_decls",
603        "`consumes` appears after other declarations.",
604        &["consumes_decl"],
605    ),
606    dg(
607        "bynk.parse.empty_agent",
608        "An `agent` body is empty.",
609        &["agent_decl"],
610    ),
611    dg(
612        "bynk.parse.empty_capability",
613        "A `capability` body is empty.",
614        &["capability_decl"],
615    ),
616    d(
617        "bynk.parse.empty_interpolation",
618        "An interpolation hole `\\(…)` contains no expression.",
619    ),
620    dg(
621        "bynk.parse.empty_match",
622        "A `match` has no arms.",
623        &["match_expr"],
624    ),
625    dg(
626        "bynk.parse.empty_mock_body",
627        "A `mocks` body is empty.",
628        &["mocks_decl"],
629    ),
630    dg(
631        "bynk.parse.empty_service",
632        "A `service` body is empty.",
633        &["service_decl"],
634    ),
635    dg(
636        "bynk.parse.expected_agent_key",
637        "Expected a `key` declaration in an agent.",
638        &["agent_decl"],
639    ),
640    d(
641        "bynk.parse.expected_agent_storage",
642        "An agent declares no storage — it has no `store` fields.",
643    ),
644    dg(
645        "bynk.parse.expected_base_type",
646        "Expected a base type.",
647        &["base_type"],
648    ),
649    dg(
650        "bynk.parse.expected_capability_op",
651        "Expected a capability operation.",
652        &["capability_op"],
653    ),
654    d("bynk.parse.expected_expression", "Expected an expression."),
655    dg(
656        "bynk.parse.expected_handler",
657        "Expected a handler.",
658        &["handler"],
659    ),
660    d("bynk.parse.expected_item", "Expected a declaration."),
661    dg(
662        "bynk.parse.expected_predicate",
663        "Expected a refinement predicate.",
664        &["refinement"],
665    ),
666    dg(
667        "bynk.parse.expected_provider_op",
668        "Expected a provider operation.",
669        &["provider_op"],
670    ),
671    d("bynk.parse.expected_token", "Expected a specific token."),
672    d("bynk.parse.expected_type", "Expected a type."),
673    d(
674        "bynk.parse.expected_unit_header",
675        "Expected a `commons` or `context` header.",
676    ),
677    dg(
678        "bynk.parse.expected_visibility",
679        "Expected a visibility keyword.",
680        &["exports_decl"],
681    ),
682    dg(
683        "bynk.parse.exports_after_decls",
684        "`exports` appears after other declarations.",
685        &["exports_decl"],
686    ),
687    d(
688        "bynk.parse.extra_tokens",
689        "Unexpected tokens after an otherwise complete construct.",
690    ),
691    dg(
692        "bynk.parse.generic_arg_count",
693        "Wrong number of generic type arguments.",
694        &["generic_type_ref"],
695    ),
696    dg(
697        "bynk.parse.handler_in_agent",
698        "A protocol handler (`on GET`/`schedule`/`message`) was declared in an agent.",
699        &["handler"],
700    ),
701    d(
702        "bynk.parse.invariant_after_handler",
703        "An `invariant` was declared after a handler; invariants precede handlers.",
704    ),
705    dg(
706        "bynk.parse.malformed_float_literal",
707        "A float literal is missing a digit on one side of the `.` (`1.`, `.5`).",
708        &["float_literal"],
709    ),
710    dg(
711        "bynk.parse.non_associative",
712        "A non-associative operator was chained (e.g. `a == b == c`).",
713        &["binary_expr"],
714    ),
715    d(
716        "bynk.parse.orphan_doc_block",
717        "A documentation block is not attached to a declaration (warning).",
718    ),
719    dg(
720        "bynk.parse.reserved_keyword",
721        "A reserved keyword was used as an identifier.",
722        &["identifier"],
723    ),
724    dg(
725        "bynk.parse.self_outside_method",
726        "`self` used outside a method or handler.",
727        &["self_expr"],
728    ),
729    d(
730        "bynk.parse.storage_after_phase",
731        "Agent storage (`state` / `store`) is declared after the invariants or handlers.",
732    ),
733    d(
734        "bynk.parse.unexpected_adapter",
735        "An `adapter` appeared where it is not allowed.",
736    ),
737    dg(
738        "bynk.parse.unexpected_context",
739        "A `context` appeared where it is not allowed.",
740        &["context_decl"],
741    ),
742    d("bynk.parse.unexpected_eof", "Unexpected end of input."),
743    dg(
744        "bynk.parse.unexpected_suite",
745        "A `suite` appeared where it is not allowed.",
746        &["suite_decl"],
747    ),
748    d(
749        "bynk.parse.unknown_effect_method",
750        "An unknown method on `Effect`.",
751    ),
752    dg(
753        "bynk.parse.unknown_handler_kind",
754        "An unknown handler form (expected `call`, an HTTP method, `schedule`, or `message`).",
755        &["handler"],
756    ),
757    dg(
758        "bynk.parse.unknown_predicate",
759        "An unknown refinement predicate.",
760        &["predicate_name"],
761    ),
762    dg(
763        "bynk.parse.uses_after_decls",
764        "`uses` appears after other declarations.",
765        &["uses_decl"],
766    ),
767    d(
768        "bynk.project.file_and_directory",
769        "A unit exists as both a file and a directory.",
770    ),
771    d(
772        "bynk.project.inconsistent_commons_name",
773        "A source file's path does not match its declared name.",
774    ),
775    d(
776        "bynk.project.kind_conflict",
777        "A name is declared as both a commons and a context.",
778    ),
779    d(
780        "bynk.project.no_root",
781        "No project root could be determined.",
782    ),
783    d(
784        "bynk.project.no_sources",
785        "The project contains no source files.",
786    ),
787    d(
788        "bynk.project.read_failed",
789        "A source file could not be read.",
790    ),
791    dg(
792        "bynk.property.restates_refinement",
793        "A `property` merely re-checks a refinement its type already guarantees.",
794        &["for_all"],
795    ),
796    dg(
797        "bynk.property.where_not_bool",
798        "A `for all ... where` filter does not type to `Bool`.",
799        &["for_all"],
800    ),
801    dg(
802        "bynk.provider.dependency_cycle",
803        "Providers form a capability dependency cycle through `given`.",
804        &["provider_decl"],
805    ),
806    dg(
807        "bynk.provider.extra_operation",
808        "A `provides` block implements an operation not in the capability.",
809        &["provider_decl"],
810    ),
811    dg(
812        "bynk.provider.missing_operation",
813        "A `provides` block is missing a capability operation.",
814        &["provider_decl"],
815    ),
816    dg(
817        "bynk.provider.outside_context",
818        "`provides` was declared outside a context.",
819        &["provider_decl"],
820    ),
821    dg(
822        "bynk.provider.signature_mismatch",
823        "A `provides` operation's signature does not match the capability.",
824        &["provider_decl"],
825    ),
826    dg(
827        "bynk.provider.unknown_capability",
828        "`provides` names a capability that does not exist.",
829        &["provider_decl"],
830    ),
831    d(
832        "bynk.query.join_key_mismatch",
833        "A `joinOn`/`leftJoin` left and right key function return different types.",
834    ),
835    dg(
836        "bynk.query.sum_needs_numeric",
837        "A `sum`/`average` key function does not return a numeric type (`Int`, `Float`, or `Duration`).",
838        &[],
839    ),
840    dg(
841        "bynk.queue.bad_params",
842        "An `on message` handler does not take exactly one `message` parameter.",
843        &["queue_handler"],
844    ),
845    dg(
846        "bynk.queue.duplicate_consumer",
847        "Two `on message` handlers consume the same queue.",
848        &["queue_handler"],
849    ),
850    dg(
851        "bynk.queue.invalid_name",
852        "A `from queue(\"…\")` binding has an empty queue name.",
853        &["queue_handler"],
854    ),
855    dg(
856        "bynk.queue.return_not_queue_result",
857        "An `on message` handler does not return `Effect[QueueResult]`.",
858        &["handler"],
859    ),
860    dg(
861        "bynk.record_spread.field_type_mismatch",
862        "A record-spread override has the wrong type for the field.",
863        &["record_spread"],
864    ),
865    dg(
866        "bynk.record_spread.non_record_base",
867        "The base of a record spread is not a record.",
868        &["record_spread"],
869    ),
870    dg(
871        "bynk.record_spread.type_mismatch",
872        "A record spread's base is a different record type.",
873        &["record_spread"],
874    ),
875    dg(
876        "bynk.record_spread.unknown_field",
877        "A record spread overrides a field the record does not have.",
878        &["record_spread"],
879    ),
880    dg(
881        "bynk.refine.literal_violates",
882        "A literal does not satisfy the refined type's predicate.",
883        &["refined_type"],
884    ),
885    dg(
886        "bynk.requires.unpinned_dependency",
887        "An adapter `binding … requires { … }` entry has an unpinned version range.",
888        &["binding_decl"],
889    ),
890    d(
891        "bynk.resolve.ambiguous_variant",
892        "A variant name is ambiguous across several sum types.",
893    ),
894    dg(
895        "bynk.resolve.arity_mismatch",
896        "A function was called with the wrong number of arguments.",
897        &["call"],
898    ),
899    d("bynk.resolve.duplicate_actor", "Two actors share a name."),
900    dg(
901        "bynk.resolve.duplicate_agent",
902        "Two agents share a name.",
903        &["agent_decl"],
904    ),
905    dg(
906        "bynk.resolve.duplicate_capability",
907        "Two capabilities share a name.",
908        &["capability_decl"],
909    ),
910    dg(
911        "bynk.resolve.duplicate_field",
912        "A record declares a field twice.",
913        &["record_type"],
914    ),
915    dg(
916        "bynk.resolve.duplicate_field_init",
917        "A record construction initialises a field twice.",
918        &["record_construction"],
919    ),
920    dg(
921        "bynk.resolve.duplicate_fn",
922        "Two functions share a name.",
923        &["fn_decl"],
924    ),
925    dg(
926        "bynk.resolve.duplicate_method",
927        "Two methods share a name.",
928        &["fn_decl"],
929    ),
930    dg(
931        "bynk.resolve.duplicate_param",
932        "A parameter name is repeated.",
933        &["param"],
934    ),
935    dg(
936        "bynk.resolve.duplicate_provider",
937        "A capability is provided more than once.",
938        &["provider_decl"],
939    ),
940    dg(
941        "bynk.resolve.duplicate_service",
942        "Two services share a name.",
943        &["service_decl"],
944    ),
945    dg(
946        "bynk.resolve.duplicate_type",
947        "Two types share a name.",
948        &["type_decl"],
949    ),
950    dg(
951        "bynk.resolve.duplicate_variant",
952        "A sum type declares a variant twice.",
953        &["sum_type"],
954    ),
955    d(
956        "bynk.resolve.fn_without_call",
957        "A function was referenced without being called.",
958    ),
959    dg(
960        "bynk.resolve.let_shadows_fn",
961        "A `let` binding shadows a function.",
962        &["let_stmt"],
963    ),
964    dg(
965        "bynk.resolve.let_shadows_type",
966        "A `let` binding shadows a type.",
967        &["let_stmt"],
968    ),
969    d(
970        "bynk.resolve.method_unknown_type",
971        "A method is defined on an unknown type.",
972    ),
973    dg(
974        "bynk.resolve.missing_field",
975        "A record construction omits a required field.",
976        &["record_construction"],
977    ),
978    d(
979        "bynk.resolve.name_conflict",
980        "Two declarations share a name.",
981    ),
982    dg(
983        "bynk.resolve.not_a_record_type",
984        "Record syntax was used on a non-record type.",
985        &["record_construction"],
986    ),
987    dg(
988        "bynk.resolve.opaque_record_construction",
989        "An opaque type was constructed with record syntax.",
990        &["record_construction"],
991    ),
992    dg(
993        "bynk.resolve.param_as_function",
994        "A value (such as a parameter) was called as a function.",
995        &["call"],
996    ),
997    dg(
998        "bynk.resolve.recursive_record_field",
999        "A record directly contains a field of its own type.",
1000        &["record_type"],
1001    ),
1002    dg(
1003        "bynk.resolve.self_outside_method",
1004        "`self` referenced outside a method or handler.",
1005        &["self_expr"],
1006    ),
1007    dg(
1008        "bynk.resolve.type_as_function",
1009        "A type name was called as if it were a function.",
1010        &["call"],
1011    ),
1012    d(
1013        "bynk.resolve.type_in_expr",
1014        "A type name was used where a value is expected.",
1015    ),
1016    dg(
1017        "bynk.resolve.unconsumed_context",
1018        "A context's service was called without a `consumes` declaration.",
1019        &["consumes_decl"],
1020    ),
1021    dg(
1022        "bynk.resolve.unknown_field",
1023        "Accessed a field the record does not have.",
1024        &["field_access"],
1025    ),
1026    dg(
1027        "bynk.resolve.unknown_function",
1028        "Called a function that does not exist.",
1029        &["call"],
1030    ),
1031    d(
1032        "bynk.resolve.unknown_name",
1033        "Referenced a name that is not in scope.",
1034    ),
1035    dg(
1036        "bynk.resolve.unknown_static_member",
1037        "Referenced an unknown static member (e.g. `T.x`).",
1038        &["field_access"],
1039    ),
1040    d(
1041        "bynk.resolve.unknown_type",
1042        "Referenced a type that does not exist.",
1043    ),
1044    dg(
1045        "bynk.send.in_pure_context",
1046        "A `~>` send was used in a pure (non-effectful) context.",
1047        &["effect_send_stmt"],
1048    ),
1049    dg(
1050        "bynk.send.non_effect",
1051        "A `~>` send was applied to a non-`Effect` value.",
1052        &["effect_send_stmt"],
1053    ),
1054    dg(
1055        "bynk.send.requires_unit",
1056        "A `~>` send targets an operation whose reply is not `Effect[()]`.",
1057        &["effect_send_stmt"],
1058    ),
1059    dg(
1060        "bynk.service.missing_from",
1061        "A `from`-less service has a handler other than `on call`.",
1062        &["service_decl"],
1063    ),
1064    dg(
1065        "bynk.service.mixed_protocols",
1066        "A service mixes handler forms that do not match its `from <protocol>`.",
1067        &["service_decl"],
1068    ),
1069    dg(
1070        "bynk.service.outside_context",
1071        "A `service` was declared outside a context.",
1072        &["service_decl"],
1073    ),
1074    dg(
1075        "bynk.service.return_not_effect",
1076        "A service handler's return type is not an `Effect`.",
1077        &["service_decl"],
1078    ),
1079    dg(
1080        "bynk.service.unknown_protocol",
1081        "A `from <protocol>` names an unknown protocol (e.g. a transport like Kafka).",
1082        &["service_decl"],
1083    ),
1084    d(
1085        "bynk.service.websocket_header",
1086        "The `from WebSocket` header is malformed — it binds frame types as `WebSocket(in: <type>, out: <type>)` (real-time track slice 3).",
1087    ),
1088    d(
1089        "bynk.service.websocket_multiple",
1090        "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).",
1091    ),
1092    d(
1093        "bynk.service.websocket_open_arity",
1094        "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).",
1095    ),
1096    d(
1097        "bynk.store.annotation_kind_mismatch",
1098        "A storage annotation is used on a kind it does not apply to (e.g. `@ttl` on a `Map`).",
1099    ),
1100    d(
1101        "bynk.store.annotation_unsupported",
1102        "A known storage annotation (`@ttl`/`@retain`/`@indexed`/`@bounded`) is used before the slice that supports it.",
1103    ),
1104    d(
1105        "bynk.store.cache_needs_clock",
1106        "A handler performs a `Cache` operation (TTL expiry reads the clock) without declaring `given Clock`.",
1107    ),
1108    d(
1109        "bynk.store.cache_ttl_required",
1110        "A `Cache` field is missing its required `@ttl(<duration>)` annotation (a keyed store with no expiry is a `Map`).",
1111    ),
1112    d(
1113        "bynk.store.kind_arity",
1114        "A storage kind was applied to the wrong number of type arguments (e.g. `Cell[A, B]`).",
1115    ),
1116    d(
1117        "bynk.store.kind_unsupported",
1118        "A known storage kind (`Queue`) is used before the slice that supports it.",
1119    ),
1120    d(
1121        "bynk.store.log_needs_clock",
1122        "A handler calls `Log.append` (which stamps the current time) without declaring `given Clock`.",
1123    ),
1124    d(
1125        "bynk.store.unknown_annotation",
1126        "A `store` field carries an annotation outside the closed `@indexed`/`@ttl`/`@retain`/`@bounded` set.",
1127    ),
1128    d(
1129        "bynk.store.unknown_kind",
1130        "A `store` field's type is not a known storage kind.",
1131    ),
1132    d(
1133        "bynk.store.unknown_op",
1134        "A storage-`Map`/`Set` operation is not a recognised entry/membership method.",
1135    ),
1136    dg(
1137        "bynk.suite.duplicate_case_name",
1138        "Two `case`s share a description.",
1139        &["case"],
1140    ),
1141    dg(
1142        "bynk.suite.unknown_target",
1143        "A `suite` targets a unit that does not exist.",
1144        &["suite_decl"],
1145    ),
1146    d(
1147        "bynk.target.browser_bundle_only",
1148        "The `browser` platform builds only the in-process `Bundle` topology; `--target workers` is not a browser build.",
1149    ),
1150    dg(
1151        "bynk.target.vendor_conflict",
1152        "One deployment unit's in-process closure uses platform-native capabilities from two mutually-exclusive platforms.",
1153        &["consumes_decl"],
1154    ),
1155    dg(
1156        "bynk.target.vendor_required",
1157        "A deployment unit uses a platform-native capability but the build selects another `--platform`.",
1158        &["consumes_decl"],
1159    ),
1160    d(
1161        "bynk.types.ambiguous_constructor",
1162        "`Ok`/`Err` is ambiguous between `Result` and `HttpResult`; qualify it.",
1163    ),
1164    dg(
1165        "bynk.types.argument_mismatch",
1166        "A function argument has the wrong type.",
1167        &["call"],
1168    ),
1169    d(
1170        "bynk.types.bytes_at_workers_boundary",
1171        "A bare `Bytes` appears in a `workers` wire signature — the erased cross-context boundary does not base64-encode it, so v1 diagnoses it rather than mis-encode. The typed paths (`bundle` calls, `store`/record fields) round-trip a `Bytes` fine (ADR 0142 D8).",
1172    ),
1173    dg(
1174        "bynk.types.call_arity",
1175        "A function value was applied with the wrong number of arguments.",
1176        &["call"],
1177    ),
1178    dg(
1179        "bynk.types.cannot_infer_option_type_param",
1180        "The value type of `None` could not be inferred.",
1181        &["none_expr"],
1182    ),
1183    d(
1184        "bynk.types.cannot_infer_result_type_params",
1185        "The type parameters of a `Result` could not be inferred.",
1186    ),
1187    d(
1188        "bynk.types.constructor_arity",
1189        "A variant constructor got the wrong number of arguments.",
1190    ),
1191    d(
1192        "bynk.types.constructor_base_mismatch",
1193        "A `.of` constructor was given an argument of the wrong base type.",
1194    ),
1195    dg(
1196        "bynk.types.duplicate_variant_arm",
1197        "A `match` has two arms for the same variant.",
1198        &["match_arm"],
1199    ),
1200    dg(
1201        "bynk.types.empty_refinement",
1202        "A refinement admits no values (contradictory predicates).",
1203        &["refinement"],
1204    ),
1205    dg(
1206        "bynk.types.err_value_mismatch",
1207        "An `Err` payload has the wrong type.",
1208        &["err_expr"],
1209    ),
1210    dg(
1211        "bynk.types.field_access_on_non_record",
1212        "Field access on a value that is not a record.",
1213        &["field_access"],
1214    ),
1215    dg(
1216        "bynk.types.field_refinement_not_base",
1217        "An inline field refinement requires a base or refined type.",
1218        &["record_field"],
1219    ),
1220    dg(
1221        "bynk.types.field_value_mismatch",
1222        "A record field was given a value of the wrong type.",
1223        &["record_construction"],
1224    ),
1225    dg(
1226        "bynk.types.function_at_boundary",
1227        "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.",
1228        &["function_type_ref"],
1229    ),
1230    d(
1231        "bynk.types.held_at_boundary",
1232        "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).",
1233    ),
1234    d(
1235        "bynk.types.held_not_comparable",
1236        "A held value (`Connection[F]`) is compared with `==`/`!=` — held values have identity, not value-equality (§2.9.3, real-time track slice 2).",
1237    ),
1238    dg(
1239        "bynk.types.if_branch_mismatch",
1240        "The branches of an `if` have different types.",
1241        &["if_expr"],
1242    ),
1243    dg(
1244        "bynk.types.if_non_bool_cond",
1245        "An `if` condition is not a `Bool`.",
1246        &["if_expr"],
1247    ),
1248    d(
1249        "bynk.types.interpolation_non_scalar",
1250        "An interpolation hole holds a value with no string form.",
1251    ),
1252    dg(
1253        "bynk.types.invalid_regex",
1254        "A `Matches` predicate contains an invalid regular expression.",
1255        &["refinement"],
1256    ),
1257    dg(
1258        "bynk.types.inverted_range",
1259        "An `InRange` predicate has its bounds inverted.",
1260        &["refinement"],
1261    ),
1262    dg(
1263        "bynk.types.is_base_mismatch",
1264        "An `is` refinement check is applied to a value of the wrong base type.",
1265        &["is_expr"],
1266    ),
1267    dg(
1268        "bynk.types.is_non_sum",
1269        "`is` was applied to a value that is not a sum type.",
1270        &["is_expr"],
1271    ),
1272    dg(
1273        "bynk.types.is_unknown_variant",
1274        "`is` names a variant the type does not have.",
1275        &["is_expr"],
1276    ),
1277    dg(
1278        "bynk.types.json_uncodable",
1279        "A `Json.encode`/`Json.decode` target type cannot pass through the typed JSON codec (functions, effects, error builtins).",
1280        &["method_call"],
1281    ),
1282    dg(
1283        "bynk.types.key_not_orderable",
1284        "A `sortBy`/`min`/`max` key function does not return an orderable type (`Int`, `Float`, `String`, `Duration`, or `Instant`).",
1285        &[],
1286    ),
1287    dg(
1288        "bynk.types.lambda_mismatch",
1289        "A lambda's parameter count, parameter annotations, or body type do not match the expected function type.",
1290        &["lambda_expr"],
1291    ),
1292    dg(
1293        "bynk.types.let_annotation_mismatch",
1294        "A `let` value does not match its type annotation.",
1295        &["let_stmt"],
1296    ),
1297    dg(
1298        "bynk.types.list_element_mismatch",
1299        "A list-literal element has a different type from the list's element type.",
1300        &["list_literal"],
1301    ),
1302    dg(
1303        "bynk.types.match_arm_mismatch",
1304        "A `match` arm has a different type from the others.",
1305        &["match_arm"],
1306    ),
1307    dg(
1308        "bynk.types.match_non_sum_discriminant",
1309        "`match` was applied to a value that is not a sum type.",
1310        &["match_expr"],
1311    ),
1312    dg(
1313        "bynk.types.method_arity",
1314        "A method was called with the wrong number of arguments.",
1315        &["method_call"],
1316    ),
1317    dg(
1318        "bynk.types.method_not_found",
1319        "Called a method the type does not have.",
1320        &["method_call"],
1321    ),
1322    dg(
1323        "bynk.types.method_on_non_named_type",
1324        "A method was called on a built-in type that has no methods.",
1325        &["method_call"],
1326    ),
1327    dg(
1328        "bynk.types.mixed_pattern_bindings",
1329        "A pattern mixes named and positional bindings.",
1330        &["variant_pattern"],
1331    ),
1332    dg(
1333        "bynk.types.negative_length",
1334        "A length predicate was given a negative value.",
1335        &["refinement"],
1336    ),
1337    dg(
1338        "bynk.types.no_numeric_coercion",
1339        "`Int` and `Float` were mixed without an explicit conversion — in an operation or in refinement bounds.",
1340        &["binary_expr", "refinement"],
1341    ),
1342    dg(
1343        "bynk.types.non_exhaustive_match",
1344        "A `match` does not cover every variant.",
1345        &["match_expr"],
1346    ),
1347    dg(
1348        "bynk.types.ok_value_mismatch",
1349        "An `Ok` payload has the wrong type.",
1350        &["ok_expr"],
1351    ),
1352    dg(
1353        "bynk.types.opaque_raw_outside",
1354        "`.raw` on an opaque type was used outside its defining commons.",
1355        &["field_access"],
1356    ),
1357    dg(
1358        "bynk.types.opaque_record_construction",
1359        "An opaque type was constructed with record syntax.",
1360        &["record_construction"],
1361    ),
1362    dg(
1363        "bynk.types.opaque_unsafe_outside",
1364        "`.unsafe` on an opaque type was used outside its defining context.",
1365        &["field_access"],
1366    ),
1367    dg(
1368        "bynk.types.pattern_arity",
1369        "A pattern binds the wrong number of payload fields.",
1370        &["variant_pattern"],
1371    ),
1372    dg(
1373        "bynk.types.pattern_type_mismatch",
1374        "A pattern's type does not match the matched value.",
1375        &["variant_pattern"],
1376    ),
1377    dg(
1378        "bynk.types.predicate_base_mismatch",
1379        "A predicate does not apply to the type's base (e.g. a string predicate on an `Int`).",
1380        &["refinement"],
1381    ),
1382    d(
1383        "bynk.types.query_at_boundary",
1384        "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).",
1385    ),
1386    dg(
1387        "bynk.types.question_error_mismatch",
1388        "`?` propagates an error type incompatible with the function's.",
1389        &["question_expr"],
1390    ),
1391    dg(
1392        "bynk.types.question_on_non_result",
1393        "`?` was applied to a non-`Result` value.",
1394        &["question_expr"],
1395    ),
1396    dg(
1397        "bynk.types.question_outside_result",
1398        "`?` used in a function that does not return a `Result`.",
1399        &["question_expr"],
1400    ),
1401    d(
1402        "bynk.types.return_mismatch",
1403        "A returned value does not match the declared return type.",
1404    ),
1405    dg(
1406        "bynk.types.some_value_mismatch",
1407        "A `Some` payload has the wrong type.",
1408        &["some_expr"],
1409    ),
1410    d(
1411        "bynk.types.stream_at_boundary",
1412        "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).",
1413    ),
1414    d(
1415        "bynk.types.stream_not_comparable",
1416        "A `Stream` value is compared with `==`/`!=` — a stream is a live value-over-time source, not a comparable value (real-time track slice 0).",
1417    ),
1418    d(
1419        "bynk.types.type_mismatch",
1420        "Two types that were required to match did not.",
1421    ),
1422    dg(
1423        "bynk.types.uninferable_element_type",
1424        "An empty `[]` (or `List.empty()` / `Map.empty()`) has no expected type to infer its element type from.",
1425        &["list_literal"],
1426    ),
1427    dg(
1428        "bynk.types.unkeyable_distinct",
1429        "A `distinct`/`distinctBy` element or key is not value-keyable (`String`, `Int`, or a refined/opaque type over them).",
1430        &[],
1431    ),
1432    dg(
1433        "bynk.types.unkeyable_map_key",
1434        "A `Map` key type is not value-keyable (`String`, `Int`, or a refined/opaque type over them).",
1435        &["generic_type_ref"],
1436    ),
1437    dg(
1438        "bynk.types.unknown_field",
1439        "Referenced a field the record type does not declare.",
1440        &["field_access"],
1441    ),
1442    dg(
1443        "bynk.types.unknown_pattern_field",
1444        "A pattern names a field the variant does not have.",
1445        &["variant_pattern"],
1446    ),
1447    dg(
1448        "bynk.types.unknown_static_member",
1449        "Referenced an unknown static member on a type.",
1450        &["field_access"],
1451    ),
1452    dg(
1453        "bynk.types.unknown_variant_in_pattern",
1454        "A pattern names a variant the sum type does not have.",
1455        &["variant_pattern"],
1456    ),
1457    dg(
1458        "bynk.types.unreachable_arm",
1459        "A `match` arm is unreachable.",
1460        &["match_arm"],
1461    ),
1462    d(
1463        "bynk.types.variant_arity",
1464        "A variant constructor got the wrong number of payload values.",
1465    ),
1466    d(
1467        "bynk.types.variant_missing_payload",
1468        "A variant requiring a payload was used without one.",
1469    ),
1470    d(
1471        "bynk.types.variant_payload_mismatch",
1472        "A variant payload has the wrong type.",
1473    ),
1474    dg(
1475        "bynk.uses.name_conflict",
1476        "A `uses` name collides with another name.",
1477        &["uses_decl"],
1478    ),
1479    dg(
1480        "bynk.uses.self_reference",
1481        "A commons `uses` itself.",
1482        &["uses_decl"],
1483    ),
1484    dg(
1485        "bynk.uses.target_is_context",
1486        "`uses` targets a context instead of a commons.",
1487        &["uses_decl"],
1488    ),
1489    dg(
1490        "bynk.uses.unknown_commons",
1491        "`uses` names a commons that does not exist.",
1492        &["uses_decl"],
1493    ),
1494    dg(
1495        "bynk.val.agent_not_generable",
1496        "A `for all`/`Val` cannot generate an agent — fabricated agent states need not be reachable.",
1497        &["for_all"],
1498    ),
1499    dg(
1500        "bynk.val.arity",
1501        "`Val[T]` was given the wrong number of pin arguments.",
1502        &["val_expr"],
1503    ),
1504    dg(
1505        "bynk.val.literal_violates",
1506        "A pinned `Val[T]` value violates the type's refinement.",
1507        &["val_expr"],
1508    ),
1509    dg(
1510        "bynk.val.needs_pin",
1511        "A bare `Val[T]` cannot generate a value (e.g. a `Matches` string); pin one.",
1512        &["val_expr"],
1513    ),
1514    dg(
1515        "bynk.val.outside_test",
1516        "`Val[T]` was used outside a test case body.",
1517        &["val_expr"],
1518    ),
1519    dg(
1520        "bynk.val.pin_not_literal",
1521        "A `Val[T]` pin argument is not a compile-time literal.",
1522        &["val_expr"],
1523    ),
1524    dg(
1525        "bynk.val.pin_unsupported",
1526        "A pin was given for a type kind that does not support pinning.",
1527        &["val_expr"],
1528    ),
1529    dg(
1530        "bynk.val.unknown_type",
1531        "`Val[T]` names a type that does not resolve.",
1532        &["val_expr"],
1533    ),
1534    dg(
1535        "bynk.val.unsupported_kind",
1536        "`Val[T]` cannot fabricate a value for this kind of type.",
1537        &["val_expr"],
1538    ),
1539    d(
1540        "bynk.ws.message_frame_param",
1541        "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).",
1542    ),
1543    d(
1544        "bynk.ws.open_given_unsupported",
1545        "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).",
1546    ),
1547    d(
1548        "bynk.ws.open_transfer_shape",
1549        "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).",
1550    ),
1551    d(
1552        "bynk.ws.route_param_mismatch",
1553        "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).",
1554    ),
1555];
1556
1557/// A diagnostic with no single governing grammar construct.
1558const fn d(code: &'static str, summary: &'static str) -> DiagnosticInfo {
1559    DiagnosticInfo {
1560        code,
1561        summary,
1562        grammar_symbol: &[],
1563    }
1564}
1565
1566/// A diagnostic that constrains one or more grammar productions.
1567const fn dg(
1568    code: &'static str,
1569    summary: &'static str,
1570    grammar_symbol: &'static [&'static str],
1571) -> DiagnosticInfo {
1572    DiagnosticInfo {
1573        code,
1574        summary,
1575        grammar_symbol,
1576    }
1577}
1578
1579/// The category segment of a code (the part between the first two dots), e.g.
1580/// `"types"` for `"bynk.types.type_mismatch"`.
1581pub fn category(code: &str) -> &str {
1582    code.split('.').nth(1).unwrap_or("")
1583}
1584
1585/// A human-readable heading for a category segment.
1586fn category_title(cat: &str) -> &'static str {
1587    match cat {
1588        "agent" | "agents" => "Agents",
1589        "boundary" => "Boundaries",
1590        "capability" => "Capabilities",
1591        "consumes" => "Consumes",
1592        "context" => "Contexts",
1593        "cron" => "Cron",
1594        "effect" => "Effects",
1595        "expect" => "Expectations",
1596        "exports" => "Exports",
1597        "given" => "Given capabilities",
1598        "http" => "HTTP",
1599        "lex" => "Lexer",
1600        "mock" => "Mocks (collaborators)",
1601        "parse" => "Parser",
1602        "project" => "Project",
1603        "property" => "Properties (generative tests)",
1604        "provider" => "Providers",
1605        "queue" => "Queue",
1606        "record_spread" => "Record spread",
1607        "refine" => "Refinement",
1608        "resolve" => "Resolution",
1609        "service" => "Services",
1610        "suite" => "Suites and cases",
1611        "types" => "Type checking",
1612        "uses" => "Uses",
1613        "val" => "Value fabrication",
1614        _ => "Other",
1615    }
1616}
1617
1618/// Render the diagnostic index as a Markdown reference page, grouped by
1619/// category. This is the generator behind
1620/// `site/src/content/docs/book/reference/diagnostics.md`.
1621pub fn render_markdown() -> String {
1622    use std::collections::BTreeMap;
1623
1624    // Group codes by their category title, preserving sorted code order.
1625    let mut by_category: BTreeMap<&str, Vec<&DiagnosticInfo>> = BTreeMap::new();
1626    for info in REGISTRY {
1627        by_category
1628            .entry(category_title(category(info.code)))
1629            .or_default()
1630            .push(info);
1631    }
1632
1633    let mut out = String::new();
1634    out.push_str("# Diagnostic index\n\n");
1635    out.push_str(
1636        "<!-- GENERATED FILE — do not edit by hand.\n     \
1637         Source: bynkc/src/diagnostics.rs (`render_markdown`).\n     \
1638         Regenerate with: BYNK_BLESS=1 cargo test -p bynkc --test diagnostics_registry -->\n\n",
1639    );
1640    out.push_str(
1641        "Every diagnostic code the compiler can emit, with a one-line summary of \
1642         the cause, grouped by category. For step-by-step cause-and-fix guidance \
1643         on the most common ones, see the [troubleshooting guides](../troubleshooting/index.md).\n\n",
1644    );
1645    out.push_str(&format!(
1646        "There are **{}** codes in total.\n",
1647        REGISTRY.len()
1648    ));
1649
1650    for (title, infos) in &by_category {
1651        out.push_str(&format!("\n## {title}\n\n"));
1652        out.push_str("| Code | Summary | Construct |\n|---|---|---|\n");
1653        for info in infos {
1654            // The construct column deep-links each governing production to its
1655            // entry in the annotated grammar reference; generated from
1656            // `grammar_symbol` (each value is an embeddable rule, so the
1657            // `#rule-<raw>` anchor resolves — enforced in diagnostics_registry).
1658            let construct = info
1659                .grammar_symbol
1660                .iter()
1661                .map(|sym| format!("[`{sym}`](grammar.md#rule-{sym})"))
1662                .collect::<Vec<_>>()
1663                .join(", ");
1664            out.push_str(&format!(
1665                "| `{}` | {} | {} |\n",
1666                info.code, info.summary, construct
1667            ));
1668        }
1669    }
1670
1671    out
1672}
1673
1674/// Invert the registry into a `{ "<rule>": [ { code, summary }, … ], … }` map,
1675/// serialised as pretty JSON with sorted keys and sorted codes. Only rules with
1676/// at least one diagnostic appear. This is the generator behind
1677/// `docs/grammar-semantics.json`, which the `{{#grammar-semantics <rule>}}`
1678/// preprocessor directive consumes.
1679pub fn render_grammar_semantics_json() -> String {
1680    use std::collections::BTreeMap;
1681
1682    // REGISTRY is sorted by code, so each rule's vector comes out code-sorted;
1683    // the BTreeMap gives sorted rule names.
1684    let mut by_symbol: BTreeMap<&str, Vec<&DiagnosticInfo>> = BTreeMap::new();
1685    for info in REGISTRY {
1686        for sym in info.grammar_symbol {
1687            by_symbol.entry(sym).or_default().push(info);
1688        }
1689    }
1690
1691    let mut map = serde_json::Map::new();
1692    map.insert(
1693        "_generated".to_string(),
1694        serde_json::Value::String(
1695            "Generated from the grammar_symbol field of bynkc/src/diagnostics.rs. \
1696             Do not edit by hand. Regenerate with: BYNK_BLESS=1 cargo test -p \
1697             bynkc --test diagnostics_registry"
1698                .to_string(),
1699        ),
1700    );
1701    for (sym, infos) in by_symbol {
1702        let arr: Vec<serde_json::Value> = infos
1703            .iter()
1704            .map(|info| serde_json::json!({ "code": info.code, "summary": info.summary }))
1705            .collect();
1706        map.insert(sym.to_string(), serde_json::Value::Array(arr));
1707    }
1708
1709    let mut s =
1710        serde_json::to_string_pretty(&serde_json::Value::Object(map)).expect("serialise semantics");
1711    s.push('\n');
1712    s
1713}