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