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