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