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