Skip to main content

bynk_syntax/
diagnostics.rs

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