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`), and carries a severity
12//! (`Error` unless built via the crate-private `warn` helper). The category
13//! shown in the generated reference is derived from the second dotted segment
14//! of the code; the grammar weave (`docs/grammar-semantics.json`, the
15//! `{{#grammar-semantics}}` directive, and the diagnostics page's Construct
16//! column) is generated from `grammar_symbol`.
17
18use crate::error::Severity;
19
20/// One documented diagnostic: its stable code and a one-line summary of the
21/// cause. Richer "cause and fix" material for the common diagnostics lives in
22/// the troubleshooting how-to guides.
23pub struct DiagnosticInfo {
24    pub code: &'static str,
25    pub summary: &'static str,
26    /// The grammar production(s) this diagnostic constrains, by `tree-sitter`
27    /// rule name (e.g. `http_handler`). This is the single source of the
28    /// "static semantics" weave: a grammar-reference entry embeds the
29    /// diagnostics for a rule via `{{#grammar-semantics <rule>}}`, generated
30    /// from here. Empty for diagnostics with no single governing construct
31    /// (e.g. `bynk.boundary.structural_mismatch`). Every non-empty name is
32    /// checked against the grammar by `tests/diagnostics_registry.rs`.
33    pub grammar_symbol: &'static [&'static str],
34    /// This code's severity (ADR 0117): `Error` rejects the program; `Warning`
35    /// surfaces but never fails the build. The single source of truth for
36    /// [`crate::error::Severity::for_error`], which looks a code up here
37    /// instead of hardcoding its own copy of the (small) warning set —
38    /// `tests/diagnostics_registry.rs` asserts the two never drift apart.
39    /// Defaults to `Error` via the crate-private `d`/`dg` constructors; only
40    /// the crate-private `warn` helper's six call sites override it.
41    pub severity: Severity,
42}
43
44/// The hosted Book, the stable target for `codeDescription` links (#853,
45/// DECISION C). No trailing slash — an [`Explain::page`] path (which begins
46/// with `/`) is appended directly.
47pub const BOOK_BASE_URL: &str = "https://bynk-lang.org";
48
49/// A curated, offline-complete explanation of a diagnostic code (#853).
50///
51/// This is the compiler-owned `code → { blurb, href }` table (DECISION A): the
52/// `blurb`/`example` are the offline answer `bynk explain` prints, while
53/// `page`/`anchor` compose the hosted-Book href the LSP hangs off the code as a
54/// clickable `codeDescription` link (DECISION C). Only the highest-traffic,
55/// newcomer-facing codes are curated; every other code simply has no entry and
56/// falls back gracefully — no link, no error (DECISION B).
57///
58/// The mapping points at *existing* Book concept pages rather than duplicating
59/// their prose; the reference-page generator ([`render_markdown`]) links every
60/// explained code at its `page`/`anchor` as an in-site link, so
61/// `astro build`'s link checker fails if a page moves or an anchor is renamed —
62/// the doc-drift guard the rest of the site already relies on.
63pub struct Explain {
64    /// The diagnostic code this explains. Must be a real [`REGISTRY`] code
65    /// (enforced by `tests/diagnostics_registry.rs`).
66    pub code: &'static str,
67    /// A longer-form paragraph: what the rule is and, crucially, *why* it
68    /// exists. This is the offline-complete answer — useful without network.
69    pub blurb: &'static str,
70    /// A minimal example of the violation and its fix.
71    pub example: &'static str,
72    /// The target Book page as a site-root-relative path, no extension and no
73    /// trailing slash, e.g. `/book/reference/types`. Used verbatim as an
74    /// in-site link by [`render_markdown`] (so the site link checker guards it)
75    /// and prefixed with [`BOOK_BASE_URL`] for the hosted `codeDescription`.
76    pub page: &'static str,
77    /// The in-page heading anchor (slug), or `""` for the page top.
78    pub anchor: &'static str,
79}
80
81impl Explain {
82    /// The hosted-Book URL for this explanation: [`BOOK_BASE_URL`] + the page
83    /// (Starlight serves pages with a trailing slash) + `#anchor` when set.
84    pub fn href(&self) -> String {
85        let mut url = format!("{BOOK_BASE_URL}{}/", self.page);
86        if !self.anchor.is_empty() {
87            url.push('#');
88            url.push_str(self.anchor);
89        }
90        url
91    }
92
93    /// The site-root-relative link used inside the generated reference page,
94    /// e.g. `/book/reference/types/#record-types`. Same shape as [`href`], sans
95    /// the host, so the in-site link checker resolves it.
96    ///
97    /// [`href`]: Explain::href
98    pub fn in_site_link(&self) -> String {
99        let mut link = format!("{}/", self.page);
100        if !self.anchor.is_empty() {
101            link.push('#');
102            link.push_str(self.anchor);
103        }
104        link
105    }
106}
107
108/// The curated explanations, keyed by code (DECISION B: highest-traffic,
109/// newcomer-facing codes first). Kept sorted by code; every `code` must be a
110/// real [`REGISTRY`] entry and every `page` an existing Book page — both
111/// enforced by `tests/diagnostics_registry.rs`.
112pub const EXPLANATIONS: &[Explain] = &[
113    Explain {
114        code: "bynk.given.undeclared_capability",
115        blurb: "A handler may only use a capability it has itself declared with \
116                `given`. Effects in Bynk are explicit: the `given` clause is the \
117                handler's honest, checkable statement of every capability it \
118                reaches for, so a reader (and the compiler) can see a handler's \
119                full reach from its signature alone. Using a capability that is \
120                not in `given` is the missing half of that contract.",
121        example: "on get \"/now\" -> Text {           // ✗ uses Clock without declaring it\n    \
122                    Clock.now()\n}\n\n\
123                  on get \"/now\" given Clock -> Text { // ✓ declared, then used\n    \
124                    Clock.now()\n}",
125        page: "/book/guides/effects-and-capabilities/understand-the-capability-model",
126        anchor: "",
127    },
128    Explain {
129        code: "bynk.given.unknown_capability",
130        blurb: "A `given` clause names a capability that no provider declares. A \
131                capability is a typed interface to the outside world; it has to be \
132                *declared* (as a `capability`, or brought in from a consumed \
133                context) before a handler can ask for it. This usually means a \
134                typo in the capability name, or a missing `uses`/`consumes` that \
135                would bring the capability into scope.",
136        example: "on get \"/\" given Clok -> Text { … }  // ✗ no capability named `Clok`\n\n\
137                  on get \"/\" given Clock -> Text { … }  // ✓ matches the declared capability",
138        page: "/book/reference/capabilities",
139        anchor: "declaring-a-capability",
140    },
141    Explain {
142        code: "bynk.resolve.missing_field",
143        blurb: "A record must be constructed with every one of its fields. Bynk \
144                records have no defaults and no partial construction: a value of a \
145                record type is only valid once all its fields are present, so a \
146                downstream reader never has to wonder whether a field was set. \
147                Omitting a field is therefore an error, not a fill-in-later.",
148        example: "type User = { name: Text, age: Int }\n\n\
149                  User { name: \"Ada\" }            // ✗ missing `age`\n\
150                  User { name: \"Ada\", age: 36 }   // ✓ every field present",
151        page: "/book/reference/types",
152        anchor: "record-types",
153    },
154    Explain {
155        code: "bynk.resolve.unknown_field",
156        blurb: "A field access names a field the record type does not have. A \
157                record's fields are fixed by its type declaration; only those \
158                names exist on the value. This is usually a typo in the field \
159                name, or an access meant for a different type.",
160        example: "type User = { name: Text }\n\n\
161                  user.nmae   // ✗ no field `nmae`\n\
162                  user.name   // ✓ the declared field",
163        page: "/book/reference/types",
164        anchor: "record-types",
165    },
166    Explain {
167        code: "bynk.resolve.unknown_name",
168        blurb: "A name was referenced that is not in scope. Every name in Bynk \
169                must be introduced before use — as a `let` binding, a parameter, \
170                a `fn`, a type, or a member brought in through `uses`/`consumes`. \
171                An unknown name is typically a typo, a missing declaration, or a \
172                reference to something defined in a module that has not been \
173                brought into scope.",
174        example: "let greeting = \"hi\"\n\
175                  greetng          // ✗ no name `greetng` in scope\n\
176                  greeting         // ✓ the bound name",
177        page: "/book/guides/program-structure/how-a-program-is-shaped",
178        anchor: "",
179    },
180    Explain {
181        code: "bynk.resolve.unknown_type",
182        blurb: "A type name was referenced that does not exist. Types must be \
183                declared (with `type`), be one of Bynk's built-in types, or be \
184                brought into scope from another module before they can be named. \
185                An unknown type is usually a typo or a missing declaration/import.",
186        example: "fn greet(u: Usr) -> Text { … }   // ✗ no type `Usr`\n\
187                  fn greet(u: User) -> Text { … }  // ✓ the declared type",
188        page: "/book/reference/types",
189        anchor: "",
190    },
191];
192
193/// The curated explanation for a diagnostic `code`, or `None` when the code has
194/// no explanation yet (the designed graceful-fallback state, DECISION B).
195pub fn explain(code: &str) -> Option<&'static Explain> {
196    EXPLANATIONS.iter().find(|e| e.code == code)
197}
198
199/// Look up a code's registry entry by exact match — the one place
200/// [`crate::error::Severity::for_error`] reads a code's severity, instead of
201/// hardcoding its own copy of the (small) warning set.
202pub fn lookup(code: &str) -> Option<&'static DiagnosticInfo> {
203    REGISTRY.iter().find(|d| d.code == code)
204}
205
206/// Every diagnostic code the compiler emits, sorted by code.
207pub const REGISTRY: &[DiagnosticInfo] = &[
208    d(
209        "bynk.actor.bearer_identity_not_string_constructible",
210        "A `Bearer` actor's identity is not a string-constructible type.",
211    ),
212    d(
213        "bynk.actor.bearer_missing_secret",
214        "A `Bearer` actor does not name its signing secret.",
215    ),
216    d(
217        "bynk.actor.binder_shadows_param",
218        "A `by` actor binder collides with a handler parameter of the same name.",
219    ),
220    d(
221        "bynk.actor.by_on_agent",
222        "A `by` actor clause was placed on an agent `on call` handler, which has no actor.",
223    ),
224    d(
225        "bynk.actor.duplicate_sum_scheme",
226        "Two peers in a multi-actor sum share an authentication scheme.",
227    ),
228    d(
229        "bynk.actor.identity_not_sealed",
230        "An actor identity type is not a context-ownable (sealed) value type.",
231    ),
232    d(
233        "bynk.actor.missing_by_on_http",
234        "An HTTP handler lacks the required `by` actor clause.",
235    ),
236    d(
237        "bynk.actor.oidc_identity_not_string_constructible",
238        "An `Oidc` actor's identity is not a string-constructible type.",
239    ),
240    d(
241        "bynk.actor.oidc_missing_audience",
242        "An `Oidc` actor does not name its `audience`.",
243    ),
244    d(
245        "bynk.actor.oidc_missing_issuer",
246        "An `Oidc` actor does not name its `issuer`.",
247    ),
248    d(
249        "bynk.actor.oidc_missing_jwks",
250        "An `Oidc` actor does not name its `jwks` endpoint.",
251    ),
252    d(
253        "bynk.actor.oidc_not_in_sum",
254        "An `Oidc` actor appears as a member of a multi-actor sum.",
255    ),
256    d(
257        "bynk.actor.outside_context",
258        "An `actor` was declared outside a context (e.g. in a commons).",
259    ),
260    d(
261        "bynk.actor.refinement_base_unsupported",
262        "A refinement actor's base is not a `Bearer` actor (no claims to authorise against).",
263    ),
264    d(
265        "bynk.actor.refinement_in_sum",
266        "A refinement actor appears as a member of a multi-actor sum.",
267    ),
268    d(
269        "bynk.actor.refinement_predicate_unsupported",
270        "A refinement actor's `where` predicate is outside the closed claim-predicate set.",
271    ),
272    d(
273        "bynk.actor.scheme_not_admissible",
274        "An actor's scheme is not admissible on this handler's protocol.",
275    ),
276    d(
277        "bynk.actor.signature_identity_unsupported",
278        "A `Signature` actor declared an `identity`, which is not yet supported.",
279    ),
280    d(
281        "bynk.actor.signature_missing_header",
282        "A `Signature` actor does not name its signature header.",
283    ),
284    d(
285        "bynk.actor.signature_missing_secret",
286        "A `Signature` actor does not name its signing secret.",
287    ),
288    d(
289        "bynk.actor.signature_requires_body",
290        "A `Signature` handler does not take a `body` parameter.",
291    ),
292    d(
293        "bynk.actor.signature_tolerance_without_timestamp",
294        "A `Signature` actor set `tolerance` without a `timestamp` header.",
295    ),
296    d(
297        "bynk.actor.sum_requires_binder",
298        "A multi-actor sum `by` clause has no binder to match the resolved actor.",
299    ),
300    d(
301        "bynk.actor.unknown_actor",
302        "A handler's `by` clause names an actor that is not declared.",
303    ),
304    d(
305        "bynk.actor.unknown_scheme",
306        "An actor declares an authentication scheme that is not compiler-known.",
307    ),
308    d(
309        "bynk.actor.unreachable_sum_arm",
310        "A multi-actor sum has an arm unreachable after a catch-all (`None`) peer.",
311    ),
312    dg(
313        "bynk.adapter.consumes_context",
314        "An `adapter` consumed a context; adapter dependencies are adapter-to-adapter.",
315        &["consumes_decl"],
316    ),
317    dg(
318        "bynk.adapter.consumes_requires_selection",
319        "An `adapter` used a whole-unit or aliased `consumes`; adapters must select capabilities with `consumes U { Cap, … }`.",
320        &["consumes_decl"],
321    ),
322    dg(
323        "bynk.adapter.disallowed_item",
324        "An `adapter` declared a `service`, `agent`, or other item it may not contain.",
325        &["adapter_decl"],
326    ),
327    dg(
328        "bynk.adapter.duplicate_binding",
329        "An `adapter` declared more than one `binding` clause.",
330        &["binding_decl"],
331    ),
332    dg(
333        "bynk.adapter.no_binding",
334        "An `adapter` declares an external provider but no `binding` module to supply it.",
335        &["adapter_decl"],
336    ),
337    dg(
338        "bynk.adapter.provider_has_body",
339        "A provider inside an `adapter` has a Bynk body; adapter providers must be external.",
340        &["provider_decl"],
341    ),
342    dg(
343        "bynk.agent.construction_arity",
344        "An agent was constructed with the wrong number of key arguments.",
345        &["agent_decl"],
346    ),
347    dg(
348        "bynk.agent.handler_arity",
349        "An agent handler was called with the wrong number of arguments.",
350        &["agent_decl"],
351    ),
352    dg(
353        "bynk.agent.handler_not_found",
354        "Called a handler the agent does not declare.",
355        &["agent_decl"],
356    ),
357    dg(
358        "bynk.agent.key_mismatch",
359        "An agent key argument has the wrong type.",
360        &["agent_decl"],
361    ),
362    dg(
363        "bynk.agent.outside_context",
364        "An `agent` was declared outside a context.",
365        &["agent_decl"],
366    ),
367    dg(
368        "bynk.agent.return_not_effect",
369        "An agent handler's return type is not an `Effect`.",
370        &["agent_decl"],
371    ),
372    dg(
373        "bynk.agents.bad_state_initialiser",
374        "An agent `store` field initialiser is not a static value of the field's type.",
375        &["store_field"],
376    ),
377    dg(
378        "bynk.agents.non_zeroable_state_field",
379        "An agent `store` field has no initialiser and no implicit zero value.",
380        &["store_field"],
381    ),
382    d(
383        "bynk.boundary.structural_mismatch",
384        "Data crossing a context boundary did not match the expected shape.",
385    ),
386    dg(
387        "bynk.capability.op_arity",
388        "A capability operation was called with the wrong number of arguments.",
389        &["capability_decl"],
390    ),
391    dg(
392        "bynk.capability.outside_context",
393        "A `capability` was declared outside a context.",
394        &["capability_decl"],
395    ),
396    dg(
397        "bynk.capability.unknown_operation",
398        "Referenced an operation the capability does not declare.",
399        &["capability_decl"],
400    ),
401    d(
402        "bynk.cell.invalid_target",
403        "A `:=` write targets something that is not a `store Cell` field.",
404    ),
405    d(
406        "bynk.cell.self_reference",
407        "A `:=` right-hand side reads the cell being written (a read-modify-write); use `.update`.",
408    ),
409    dg(
410        "bynk.consumes.alias_conflict",
411        "Two `consumes` aliases collide.",
412        &["consumes_decl"],
413    ),
414    dg(
415        "bynk.consumes.capability_name_clash",
416        "Two flattened `consumes U { Cap }` capabilities collide, or one clashes with a local capability.",
417        &["consumes_decl"],
418    ),
419    dg(
420        "bynk.consumes.in_commons",
421        "`consumes` appears in a `commons` (it is only valid in a context).",
422        &["consumes_decl"],
423    ),
424    dg(
425        "bynk.consumes.name_conflict",
426        "A `consumes` name collides with another name in scope.",
427        &["consumes_decl"],
428    ),
429    dg(
430        "bynk.consumes.self_reference",
431        "A context `consumes` itself.",
432        &["consumes_decl"],
433    ),
434    dg(
435        "bynk.consumes.service_arity",
436        "A consumed service was called with the wrong number of arguments.",
437        &["consumes_decl"],
438    ),
439    dg(
440        "bynk.consumes.target_is_commons",
441        "`consumes` targets a `commons` instead of a context.",
442        &["consumes_decl"],
443    ),
444    dg(
445        "bynk.consumes.unknown_context",
446        "`consumes` names a context that does not exist.",
447        &["consumes_decl"],
448    ),
449    dg(
450        "bynk.consumes.unknown_service",
451        "Called a service the consumed context does not declare.",
452        &["consumes_decl"],
453    ),
454    d(
455        "bynk.context.consumes_cycle",
456        "Contexts form a `consumes` dependency cycle.",
457    ),
458    d(
459        "bynk.context.external_construction",
460        "A context-owned type was constructed from outside that context.",
461    ),
462    dg(
463        "bynk.context.external_provider",
464        "A bodiless (external) provider was declared outside an `adapter`.",
465        &["provider_decl"],
466    ),
467    d(
468        "bynk.context.opaque_inspection",
469        "An opaquely-exported type was inspected from outside its context.",
470    ),
471    d(
472        "bynk.context.rebrand_construction",
473        "A `uses`-sourced commons record or sum type was constructed directly inside a context, where the emitter's per-context rebrand leaves its constructors out of scope.",
474    ),
475    d(
476        "bynk.contract.duplicate_name",
477        "A function declares two contract clauses (`requires`/`ensures`) with the same name.",
478    ),
479    d(
480        "bynk.contract.impure_predicate",
481        "A contract predicate uses an effectful or test-only construct; a contract clause must be pure.",
482    ),
483    d(
484        "bynk.contract.not_bool",
485        "A contract predicate does not have type `Bool`.",
486    ),
487    d(
488        "bynk.contract.restated_by_test",
489        "A `case`/`property` merely restates a contract clause already declared at the function; the test is redundant.",
490    ),
491    d(
492        "bynk.contract.result_in_requires",
493        "A precondition (`requires`) references `result`; the return value is only in scope inside an `ensures`.",
494    ),
495    dg(
496        "bynk.cron.bad_params",
497        "A cron handler declares more than one parameter, or a non-`Int` one.",
498        &["cron_handler"],
499    ),
500    dg(
501        "bynk.cron.duplicate_schedule",
502        "Two cron handlers declare the same schedule.",
503        &["cron_handler"],
504    ),
505    dg(
506        "bynk.cron.invalid_schedule",
507        "A cron expression is not five whitespace-separated fields.",
508        &["cron_handler"],
509    ),
510    dg(
511        "bynk.cron.return_not_effect_result",
512        "A cron handler does not return `Effect[Result[(), E]]`.",
513        &["cron_handler"],
514    ),
515    d(
516        "bynk.duration.literal_overflow",
517        "A `Duration` literal (`<int>.<unit>`) exceeds the representable millisecond range.",
518    ),
519    dg(
520        "bynk.effect.bind_in_pure_context",
521        "An `<-` bind was used in a pure (non-effectful) context.",
522        &["effect_let_stmt"],
523    ),
524    dg(
525        "bynk.effect.bind_on_non_effect",
526        "An `<-` bind was applied to a non-`Effect` value.",
527        &["effect_let_stmt"],
528    ),
529    d(
530        "bynk.effect.capability_in_pure_context",
531        "A capability was used in a pure context.",
532    ),
533    d(
534        "bynk.effect.cross_context_in_pure_context",
535        "A cross-context call was made in a pure context.",
536    ),
537    dg(
538        "bynk.effect.do_in_pure_context",
539        "A `do` statement was used in a pure (non-effectful) context.",
540        &["do_stmt"],
541    ),
542    dg(
543        "bynk.effect.do_on_non_effect",
544        "A `do` statement was applied to a non-`Effect` value.",
545        &["do_stmt"],
546    ),
547    dg(
548        "bynk.effect.do_requires_unit",
549        "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.",
550        &["do_stmt"],
551    ),
552    dg(
553        "bynk.effect.fn_value_in_pure_context",
554        "An effectful function value was called in a pure context; like a capability call, it is legal only where the enclosing body is effectful.",
555        &["call"],
556    ),
557    d(
558        "bynk.event.emit_not_an_event",
559        "`Events.emit[E]` named a type `E` that is declared in this context, but is not itself an `event` — only an `event` type may be emitted.",
560    ),
561    d(
562        "bynk.event.emit_outside_owner",
563        "`Events.emit[E]` named an event `E` not declared in the emitting context — only an event's declaring context may emit it.",
564    ),
565    d(
566        "bynk.event.handler_param_type_mismatch",
567        "An `on event(e: T)` handler's declared parameter type does not match its `from Events(E)` header's event type.",
568    ),
569    d(
570        "bynk.event.outside_context",
571        "An `event` was declared outside a context.",
572    ),
573    d(
574        "bynk.event.pattern_duplicate_field",
575        "A `from Events(E { ... })` subscription pattern listed the same field more than once.",
576    ),
577    d(
578        "bynk.event.pattern_type_mismatch",
579        "A `from Events(E { ... })` subscription pattern field's matched value is not compatible with that field's declared type.",
580    ),
581    d(
582        "bynk.event.pattern_unknown_field",
583        "A `from Events(E { ... })` subscription pattern named a field that `E` does not declare.",
584    ),
585    d(
586        "bynk.event.pattern_unknown_variant",
587        "A `from Events(E { ... })` subscription pattern's variant value names a variant that does not exist on the field's declared sum type.",
588    ),
589    d(
590        "bynk.event.pattern_variant_payload",
591        "A `from Events(E { ... })` subscription pattern's variant value names a variant that carries a payload — only nullary variants are admitted, since testing the tag alone would silently ignore the payload.",
592    ),
593    d(
594        "bynk.event.unknown_subscription",
595        "A `from Events(E)` subscription named `E`, which is not a declared event in this context or any consumed context.",
596    ),
597    dg(
598        "bynk.expect.not_bool",
599        "`expect` was given a non-`Bool` predicate.",
600        &["expect_expr"],
601    ),
602    dg(
603        "bynk.expect.outside_case",
604        "`expect` was used outside a `case` body.",
605        &["expect_expr"],
606    ),
607    dg(
608        "bynk.exports.capability_not_provided",
609        "An exported capability has no provider in its context.",
610        &["exports_decl"],
611    ),
612    dg(
613        "bynk.exports.conflicting_visibility",
614        "A type is exported with conflicting visibilities.",
615        &["exports_decl"],
616    ),
617    dg(
618        "bynk.exports.duplicate_export",
619        "The same name is exported more than once.",
620        &["exports_decl"],
621    ),
622    dg(
623        "bynk.exports.duplicate_in_clause",
624        "A name appears twice in one `exports` clause.",
625        &["exports_decl"],
626    ),
627    dg(
628        "bynk.exports.undeclared_capability",
629        "`exports capability` names a capability that is not declared.",
630        &["exports_decl"],
631    ),
632    dg(
633        "bynk.exports.undeclared_type",
634        "`exports` names a type that is not declared.",
635        &["exports_decl"],
636    ),
637    dg(
638        "bynk.generics.duplicate_type_param",
639        "A `type` or `fn` declares the same type-parameter name more than once (v0.157, ADR 0183).",
640        &[],
641    ),
642    dg(
643        "bynk.generics.generic_non_record",
644        "A `type` declaration carries type parameters on a refined or opaque body; only a record (`type Name[T] = { … }`) or sum (`type Name[T] = | … | …`) body may be generic (v0.157/#593, ADRs 0183/0197).",
645        &["type_decl"],
646    ),
647    dg(
648        "bynk.generics.generic_record_at_boundary",
649        "A `Val[…]` fabricates a value of a generic type; per-instantiation value fabrication is not yet wired (ADR 0197). Since v0.174 a generic-record instantiation may otherwise cross a boundary through its monomorphised codec.",
650        &[],
651    ),
652    dg(
653        "bynk.generics.generic_sum_embeds",
654        "A generic sum type carries an `embeds` clause; embedding into a generic sum is not supported (#593).",
655        &["type_decl"],
656    ),
657    dg(
658        "bynk.generics.method_on_generic_type",
659        "A *static* method is attached to a generic type; static methods on generic types are deferred (they have no receiver to supply the type's parameters). Instance methods on generic types are supported (#594).",
660        &["fn_decl"],
661    ),
662    dg(
663        "bynk.generics.no_bounds",
664        "A type parameter carries a bound (`[A: …]`); bounded generics are not in v0.20a.",
665        &["fn_decl"],
666    ),
667    dg(
668        "bynk.generics.recursive_generic_at_boundary",
669        "A recursive generic record (one that transitively contains itself, through any wrapper or generic argument) appears at a boundary; it has no finite set of monomorphised codecs, so it is not yet boundary-serialisable (ADR 0197).",
670        &[],
671    ),
672    dg(
673        "bynk.generics.type_arg_count",
674        "A user-declared generic type is applied to the wrong number of type arguments, or a generic type is named without its `[…]` arguments (v0.157, ADR 0183).",
675        &["applied_type_ref"],
676    ),
677    dg(
678        "bynk.generics.type_arg_mismatch",
679        "Inferred or explicit type arguments conflict, have the wrong arity, target a non-generic function, or a type parameter shadows a declared type.",
680        &["call"],
681    ),
682    dg(
683        "bynk.generics.uninferable_type_arg",
684        "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.",
685        &["call"],
686    ),
687    dg(
688        "bynk.given.cross_context_unknown_capability",
689        "`given B.Cap` names a capability the consumed context does not export.",
690        &["given_clause"],
691    ),
692    dg(
693        "bynk.given.undeclared_capability",
694        "A handler uses a capability it did not declare with `given`.",
695        &["given_clause"],
696    ),
697    dg(
698        "bynk.given.unknown_capability",
699        "`given` names a capability that does not exist.",
700        &["given_clause"],
701    ),
702    warn(dg(
703        "bynk.given.unused_capability",
704        "A `given` capability is never used (warning).",
705        &["given_clause"],
706    )),
707    d(
708        "bynk.held.branch_divergence",
709        "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).",
710    ),
711    d(
712        "bynk.held.consume_on_borrow",
713        "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).",
714    ),
715    d(
716        "bynk.held.leak",
717        "A held value (`Connection[F]`) is still owned at scope exit — it must be disposed (stored, closed, or transferred) before the handler or function returns (§2.9.1, real-time track slice 2).",
718    ),
719    d(
720        "bynk.held.query_accessor_on_held_map",
721        "A key-aware query accessor (`.entries`/`.keys`/`.values`) is used on a held `Map[K, Connection]` — a held resource is iterated with the broadcast ops (`forEach`/`parTraverse`), not a key query.",
722    ),
723    d(
724        "bynk.held.unsupported_map_op",
725        "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).",
726    ),
727    d(
728        "bynk.held.unsupported_storage",
729        "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).",
730    ),
731    d(
732        "bynk.held.use_after_consume",
733        "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).",
734    ),
735    d(
736        "bynk.history.not_an_agent",
737        "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).",
738    ),
739    d(
740        "bynk.history.not_generable",
741        "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).",
742    ),
743    d(
744        "bynk.history.outside_property",
745        "`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).",
746    ),
747    d(
748        "bynk.history.restates_invariant",
749        "A history property merely re-checks a guarantee a declared `invariant`/`transition` already enforces on every reached state (testing track slice 7, ADR 0155).",
750    ),
751    dg(
752        "bynk.http.body_on_get_or_delete",
753        "A GET or DELETE handler declares a `body` parameter.",
754        &["http_handler"],
755    ),
756    d(
757        "bynk.http.cache_bad_max_age",
758        "A `@cache` annotation's `maxAge` is missing or not a positive `Duration` literal.",
759    ),
760    d(
761        "bynk.http.cache_bad_scope",
762        "A `@cache` annotation's `scope` is not `public` or `private`.",
763    ),
764    d(
765        "bynk.http.cache_duplicate",
766        "A handler carries more than one `@cache` annotation.",
767    ),
768    d(
769        "bynk.http.cache_on_non_get",
770        "A `@cache` annotation is placed on a handler that is not `on http GET`.",
771    ),
772    d(
773        "bynk.http.cache_unknown_arg",
774        "A `@cache` annotation has an argument outside the closed set (`maxAge`/`scope`).",
775    ),
776    d(
777        "bynk.http.cors_invalid_field",
778        "A `cors` policy field (`headers`/`credentials`/`maxAge`) has the wrong value shape.",
779    ),
780    d(
781        "bynk.http.cors_invalid_origins",
782        "A `cors` policy's `origins` is missing, empty, or not a list of string literals.",
783    ),
784    d(
785        "bynk.http.cors_not_http",
786        "A `cors { }` policy appears on a service that is not `from http`.",
787    ),
788    d(
789        "bynk.http.cors_unknown_field",
790        "A `cors { }` policy declares a field outside the closed set.",
791    ),
792    d(
793        "bynk.http.cors_wildcard_credentials",
794        "A `cors` policy combines `credentials: true` with the wildcard origin `[\"*\"]`.",
795    ),
796    dg(
797        "bynk.http.duplicate_route",
798        "Two handlers share the same method and route.",
799        &["http_handler"],
800    ),
801    dg(
802        "bynk.http.extra_param",
803        "A handler parameter is neither a path parameter nor `body`.",
804        &["http_handler"],
805    ),
806    dg(
807        "bynk.http.invalid_path",
808        "An HTTP route path is malformed.",
809        &["http_handler"],
810    ),
811    d(
812        "bynk.http.limit_bad_max_body",
813        "A `@limit` annotation's `maxBody` is missing or not a positive `Int` literal.",
814    ),
815    d(
816        "bynk.http.limit_duplicate",
817        "A handler carries more than one `@limit` annotation.",
818    ),
819    d(
820        "bynk.http.limit_on_bodyless",
821        "A `@limit` annotation is placed on a handler that takes no body (a GET or DELETE).",
822    ),
823    d(
824        "bynk.http.limit_unknown_arg",
825        "A `@limit` annotation has an argument outside the closed set (`maxBody`).",
826    ),
827    d(
828        "bynk.http.limits_invalid_field",
829        "A `limits` policy field (`maxBody`) has the wrong value shape.",
830    ),
831    d(
832        "bynk.http.limits_not_http",
833        "A `limits { }` policy appears on a service that is not `from http`.",
834    ),
835    d(
836        "bynk.http.limits_unknown_field",
837        "A `limits { }` policy declares a field outside the closed set.",
838    ),
839    dg(
840        "bynk.http.path_param_not_stringy",
841        "A path parameter's type is not constructible from a string.",
842        &["http_handler"],
843    ),
844    dg(
845        "bynk.http.reserved_prefix",
846        "A route uses the reserved `/_bynk/` prefix.",
847        &["http_handler"],
848    ),
849    dg(
850        "bynk.http.return_not_effect_http_result",
851        "An HTTP handler does not return `Effect[HttpResult[T]]`.",
852        &["http_handler"],
853    ),
854    d(
855        "bynk.http.security_invalid_field",
856        "A `security` policy field (`hsts`/`nosniff`) has the wrong value shape.",
857    ),
858    d(
859        "bynk.http.security_not_http",
860        "A `security { }` policy appears on a service that is not `from http`.",
861    ),
862    d(
863        "bynk.http.security_unknown_field",
864        "A `security { }` policy declares a field outside the closed set.",
865    ),
866    dg(
867        "bynk.http.unbound_path_param",
868        "A `:name` route segment has no matching handler parameter.",
869        &["http_handler"],
870    ),
871    d(
872        "bynk.http.unknown_handler_annotation",
873        "A handler carries an annotation outside the closed set (`@cache`/`@limit`).",
874    ),
875    d(
876        "bynk.index.bad_argument",
877        "An `@indexed` argument is not a `by: <field>` label.",
878    ),
879    warn(d(
880        "bynk.index.missing",
881        "A query filters a map by equality on a field that is not `@indexed` (a perf-hint warning).",
882    )),
883    d(
884        "bynk.index.unkeyable_key",
885        "An `@indexed(by: k)` field is not value-keyable.",
886    ),
887    d(
888        "bynk.index.unknown_key",
889        "An `@indexed(by: k)` field is not a field of the map's value type.",
890    ),
891    warn(d(
892        "bynk.index.unused",
893        "A declared `@indexed(by: k)` is never used by an equality filter (a hygiene warning).",
894    )),
895    d(
896        "bynk.invariant.cross_agent_reference",
897        "An invariant predicate references another agent; invariants are per-agent.",
898    ),
899    d(
900        "bynk.invariant.duplicate_name",
901        "An agent declares two invariants with the same name.",
902    ),
903    d(
904        "bynk.invariant.impure_predicate",
905        "An invariant predicate uses an effectful or test-only construct.",
906    ),
907    d(
908        "bynk.invariant.not_bool",
909        "An invariant predicate does not have type `Bool`.",
910    ),
911    dg(
912        "bynk.lambda.unannotated_param",
913        "A lambda parameter has no type annotation in a position where no function type is expected to infer it from.",
914        &["lambda_expr"],
915    ),
916    dg(
917        "bynk.lex.bad_escape",
918        "An invalid escape sequence in a string literal.",
919        &["string_literal"],
920    ),
921    dg(
922        "bynk.lex.float_literal_overflow",
923        "A float literal does not fit a finite 64-bit float.",
924        &["float_literal"],
925    ),
926    dg(
927        "bynk.lex.integer_overflow",
928        "An integer literal is out of range.",
929        &["number_literal"],
930    ),
931    dg(
932        "bynk.lex.interpolation_too_deep",
933        "A string interpolation `\\(…)` nests deeper than the lexer's fixed limit.",
934        &["string_literal"],
935    ),
936    d(
937        "bynk.lex.unclosed_doc_block",
938        "A documentation block is not closed.",
939    ),
940    d(
941        "bynk.lex.unexpected_character",
942        "An unexpected character in the source.",
943    ),
944    dg(
945        "bynk.lex.unterminated_interpolation",
946        "An interpolation hole `\\(…)` is not closed on its line.",
947        &["string_literal"],
948    ),
949    dg(
950        "bynk.lex.unterminated_string",
951        "A string literal is not terminated.",
952        &["string_literal"],
953    ),
954    warn(d(
955        "bynk.list.deprecated_function",
956        "A `bynk.list` free function (`map`/`filter`/`find`/`any`/`all`) is deprecated in favour of the `List` method form (warning; auto-fixable).",
957    )),
958    d(
959        "bynk.locale.multiple_message_bundles",
960        "A context consumes `Locale` but its direct `uses` reaches two or more message-bundle commons — there is no single bundle to negotiate against.",
961    ),
962    d(
963        "bynk.messages.format_mismatch",
964        "A code's placeholder is formatted as a different ICU kind (plain/plural/select/number/date) across declared locales.",
965    ),
966    d(
967        "bynk.messages.incomplete",
968        "A locale is missing a code the reference locale declares.",
969    ),
970    d(
971        "bynk.messages.invalid_locale_tag",
972        "A `messages` block's locale tag is not a valid `LocaleTag` (e.g. `messages \"xx\"` where `xx` doesn't match the tag pattern).",
973    ),
974    d(
975        "bynk.messages.malformed_icu_syntax",
976        "A message template's ICU placeholder syntax is invalid — unbalanced arm braces, an unknown format keyword, `#` outside a plural arm, a missing mandatory `other` arm, or an explicitly out-of-scope construct (`selectordinal`, `offset:`/`=N`, a CLDR skeleton).",
977    ),
978    d(
979        "bynk.messages.missing_locale_dependency",
980        "A commons declaring `messages` doesn't `uses bynk.locale` and/or `uses bynk.locale.types`, which its generated `render` and the types its signature names need.",
981    ),
982    d(
983        "bynk.messages.missing_reference",
984        "A message bundle has no `@reference` block.",
985    ),
986    d(
987        "bynk.messages.multiple_reference",
988        "A message bundle has more than one `@reference` block.",
989    ),
990    d(
991        "bynk.messages.outside_commons",
992        "A `messages` declaration appears outside a commons.",
993    ),
994    d(
995        "bynk.messages.placeholder_mismatch",
996        "A locale's template for a code uses a different set of `{name}` placeholders than the reference locale's.",
997    ),
998    d(
999        "bynk.namespace.reserved",
1000        "A user unit is named `bynk` or `bynk.*`; the `bynk` root is reserved for the toolchain.",
1001    ),
1002    d(
1003        "bynk.observe.bad_count",
1004        "An observation call count is not a non-negative integer literal (`called once` / `called <n> times`).",
1005    ),
1006    d(
1007        "bynk.observe.impure_with",
1008        "A `with` predicate uses an effectful or test-only construct; it must be pure.",
1009    ),
1010    d(
1011        "bynk.observe.not_a_seam",
1012        "An observation targets a capability the unit under test does not consume.",
1013    ),
1014    d(
1015        "bynk.observe.outside_case",
1016        "An observation appears outside a `case` body.",
1017    ),
1018    d(
1019        "bynk.observe.trace_outside_test",
1020        "`trace(Cap.op)` appears outside a `case` body.",
1021    ),
1022    d(
1023        "bynk.observe.unknown_op",
1024        "An observation names an operation the capability does not declare.",
1025    ),
1026    d(
1027        "bynk.observe.with_not_bool",
1028        "A `with` predicate does not have type `Bool`.",
1029    ),
1030    dg(
1031        "bynk.parse.consumes_after_decls",
1032        "`consumes` appears after other declarations.",
1033        &["consumes_decl"],
1034    ),
1035    d(
1036        "bynk.parse.dangling_handler_annotation",
1037        "A handler-position annotation (e.g. `@cache`) is not followed by an `on` handler.",
1038    ),
1039    dg(
1040        "bynk.parse.duplicate_cors",
1041        "A service declares more than one `cors { }` policy.",
1042        &["service_decl"],
1043    ),
1044    dg(
1045        "bynk.parse.duplicate_limits",
1046        "A service declares more than one `limits { }` policy.",
1047        &["service_decl"],
1048    ),
1049    dg(
1050        "bynk.parse.duplicate_security",
1051        "A service declares more than one `security { }` policy.",
1052        &["service_decl"],
1053    ),
1054    dg(
1055        "bynk.parse.empty_agent",
1056        "An `agent` body is empty.",
1057        &["agent_decl"],
1058    ),
1059    dg(
1060        "bynk.parse.empty_capability",
1061        "A `capability` body is empty.",
1062        &["capability_decl"],
1063    ),
1064    d(
1065        "bynk.parse.empty_interpolation",
1066        "An interpolation hole `\\(…)` contains no expression.",
1067    ),
1068    dg(
1069        "bynk.parse.empty_match",
1070        "A `match` has no arms.",
1071        &["match_expr"],
1072    ),
1073    dg(
1074        "bynk.parse.empty_service",
1075        "A `service` body is empty.",
1076        &["service_decl"],
1077    ),
1078    d(
1079        "bynk.parse.event_pattern_empty",
1080        "A `from Events(E { ... })` subscription pattern listed no fields — use `from Events(E)` (no braces) for an unfiltered subscription.",
1081    ),
1082    dg(
1083        "bynk.parse.expected_agent_key",
1084        "Expected a `key` declaration in an agent.",
1085        &["agent_decl"],
1086    ),
1087    d(
1088        "bynk.parse.expected_agent_storage",
1089        "An agent declares no storage — it has no `store` fields.",
1090    ),
1091    dg(
1092        "bynk.parse.expected_base_type",
1093        "Expected a base type.",
1094        &["base_type"],
1095    ),
1096    dg(
1097        "bynk.parse.expected_capability_op",
1098        "Expected a capability operation.",
1099        &["capability_op"],
1100    ),
1101    d("bynk.parse.expected_expression", "Expected an expression."),
1102    dg(
1103        "bynk.parse.expected_handler",
1104        "Expected a handler.",
1105        &["handler"],
1106    ),
1107    d("bynk.parse.expected_item", "Expected a declaration."),
1108    dg(
1109        "bynk.parse.expected_predicate",
1110        "Expected a refinement predicate.",
1111        &["refinement"],
1112    ),
1113    dg(
1114        "bynk.parse.expected_provider_op",
1115        "Expected a provider operation.",
1116        &["provider_op"],
1117    ),
1118    d("bynk.parse.expected_token", "Expected a specific token."),
1119    d("bynk.parse.expected_type", "Expected a type."),
1120    d(
1121        "bynk.parse.expected_unit_header",
1122        "Expected a `commons` or `context` header.",
1123    ),
1124    dg(
1125        "bynk.parse.expected_visibility",
1126        "Expected a visibility keyword.",
1127        &["exports_decl"],
1128    ),
1129    dg(
1130        "bynk.parse.exports_after_decls",
1131        "`exports` appears after other declarations.",
1132        &["exports_decl"],
1133    ),
1134    d(
1135        "bynk.parse.extra_tokens",
1136        "Unexpected tokens after an otherwise complete construct.",
1137    ),
1138    dg(
1139        "bynk.parse.generic_arg_count",
1140        "Wrong number of generic type arguments.",
1141        &["generic_type_ref"],
1142    ),
1143    dg(
1144        "bynk.parse.handler_in_agent",
1145        "A protocol handler (`on GET`/`schedule`/`message`) was declared in an agent.",
1146        &["handler"],
1147    ),
1148    d(
1149        "bynk.parse.invariant_after_handler",
1150        "An `invariant` was declared after a handler; invariants precede handlers.",
1151    ),
1152    dg(
1153        "bynk.parse.malformed_float_literal",
1154        "A float literal is missing a digit on one side of the `.` (`1.`, `.5`).",
1155        &["float_literal"],
1156    ),
1157    d(
1158        "bynk.parse.nesting_too_deep",
1159        "An expression or type nests deeper than the parser's fixed limit.",
1160    ),
1161    dg(
1162        "bynk.parse.non_associative",
1163        "A non-associative operator was chained (e.g. `a == b == c`).",
1164        &["binary_expr"],
1165    ),
1166    warn(d(
1167        "bynk.parse.orphan_doc_block",
1168        "A documentation block is not attached to a declaration (warning).",
1169    )),
1170    dg(
1171        "bynk.parse.refined_pattern_inner",
1172        "A refined pattern's inner form is something other than `_`.",
1173        &["refined_pattern"],
1174    ),
1175    dg(
1176        "bynk.parse.reserved_keyword",
1177        "A reserved keyword was used as an identifier.",
1178        &["identifier"],
1179    ),
1180    dg(
1181        "bynk.parse.self_outside_method",
1182        "`self` used outside a method or handler.",
1183        &["self_expr"],
1184    ),
1185    d(
1186        "bynk.parse.storage_after_phase",
1187        "Agent storage (`state` / `store`) is declared after the invariants or handlers.",
1188    ),
1189    d(
1190        "bynk.parse.transition_after_handler",
1191        "A `transition` is declared after an agent handler; step invariants precede the handlers.",
1192    ),
1193    d(
1194        "bynk.parse.unexpected_adapter",
1195        "An `adapter` appeared where it is not allowed.",
1196    ),
1197    dg(
1198        "bynk.parse.unexpected_context",
1199        "A `context` appeared where it is not allowed.",
1200        &["context_decl"],
1201    ),
1202    d("bynk.parse.unexpected_eof", "Unexpected end of input."),
1203    dg(
1204        "bynk.parse.unexpected_suite",
1205        "A `suite` appeared where it is not allowed.",
1206        &["suite_decl"],
1207    ),
1208    d(
1209        "bynk.parse.unknown_effect_method",
1210        "An unknown method on `Effect`.",
1211    ),
1212    dg(
1213        "bynk.parse.unknown_handler_kind",
1214        "An unknown handler form (expected `call`, an HTTP method, `schedule`, or `message`).",
1215        &["handler"],
1216    ),
1217    dg(
1218        "bynk.parse.unknown_predicate",
1219        "An unknown refinement predicate.",
1220        &["predicate_name"],
1221    ),
1222    d(
1223        "bynk.parse.unknown_tier",
1224        "A `case`/`suite` `as <tier>` clause names something other than `unit`, `integration`, or `system`.",
1225    ),
1226    dg(
1227        "bynk.parse.uses_after_decls",
1228        "`uses` appears after other declarations.",
1229        &["uses_decl"],
1230    ),
1231    dg(
1232        "bynk.parse.variant_name_case",
1233        "A sum-type or enum variant name is not capitalised.",
1234        &["sum_variant", "enum_type"],
1235    ),
1236    d(
1237        "bynk.project.file_and_directory",
1238        "A unit exists as both a file and a directory.",
1239    ),
1240    d(
1241        "bynk.project.inconsistent_commons_name",
1242        "A source file's path does not match its declared name.",
1243    ),
1244    d(
1245        "bynk.project.kind_conflict",
1246        "A name is declared as both a commons and a context.",
1247    ),
1248    d(
1249        "bynk.project.no_root",
1250        "No project root could be determined.",
1251    ),
1252    d(
1253        "bynk.project.no_sources",
1254        "The project contains no source files.",
1255    ),
1256    d(
1257        "bynk.project.read_failed",
1258        "A source file could not be read.",
1259    ),
1260    dg(
1261        "bynk.property.restates_refinement",
1262        "A `property` merely re-checks a refinement its type already guarantees.",
1263        &["for_all"],
1264    ),
1265    dg(
1266        "bynk.property.where_not_bool",
1267        "A `for all ... where` filter does not type to `Bool`.",
1268        &["for_all"],
1269    ),
1270    dg(
1271        "bynk.provider.dependency_cycle",
1272        "Providers form a capability dependency cycle through `given`.",
1273        &["provider_decl"],
1274    ),
1275    dg(
1276        "bynk.provider.extra_operation",
1277        "A `provides` block implements an operation not in the capability.",
1278        &["provider_decl"],
1279    ),
1280    dg(
1281        "bynk.provider.generic_op_requires_external",
1282        "A Bynk-bodied `provides` implements a capability operation that declares its own type parameter — only an external (bodiless) provider can.",
1283        &["provider_decl"],
1284    ),
1285    dg(
1286        "bynk.provider.missing_operation",
1287        "A `provides` block is missing a capability operation.",
1288        &["provider_decl"],
1289    ),
1290    dg(
1291        "bynk.provider.outside_context",
1292        "`provides` was declared outside a context.",
1293        &["provider_decl"],
1294    ),
1295    dg(
1296        "bynk.provider.signature_mismatch",
1297        "A `provides` operation's signature does not match the capability.",
1298        &["provider_decl"],
1299    ),
1300    dg(
1301        "bynk.provider.unknown_capability",
1302        "`provides` names a capability that does not exist.",
1303        &["provider_decl"],
1304    ),
1305    d(
1306        "bynk.query.join_key_mismatch",
1307        "A `joinOn`/`leftJoin` left and right key function return different types.",
1308    ),
1309    dg(
1310        "bynk.query.sum_needs_numeric",
1311        "A `sum`/`average` key function does not return a numeric type (`Int`, `Float`, or `Duration`).",
1312        &[],
1313    ),
1314    dg(
1315        "bynk.queue.bad_params",
1316        "An `on message` handler does not take exactly one `message` parameter.",
1317        &["queue_handler"],
1318    ),
1319    dg(
1320        "bynk.queue.duplicate_consumer",
1321        "Two `on message` handlers consume the same queue.",
1322        &["queue_handler"],
1323    ),
1324    dg(
1325        "bynk.queue.invalid_name",
1326        "A `from queue(\"…\")` binding has an empty queue name.",
1327        &["queue_handler"],
1328    ),
1329    dg(
1330        "bynk.queue.return_not_queue_result",
1331        "An `on message` handler does not return `Effect[QueueResult]`.",
1332        &["handler"],
1333    ),
1334    dg(
1335        "bynk.record_spread.field_type_mismatch",
1336        "A record-spread override has the wrong type for the field.",
1337        &["record_spread"],
1338    ),
1339    dg(
1340        "bynk.record_spread.non_record_base",
1341        "The base of a record spread is not a record.",
1342        &["record_spread"],
1343    ),
1344    dg(
1345        "bynk.record_spread.type_mismatch",
1346        "A record spread's base is a different record type.",
1347        &["record_spread"],
1348    ),
1349    dg(
1350        "bynk.record_spread.unknown_field",
1351        "A record spread overrides a field the record does not have.",
1352        &["record_spread"],
1353    ),
1354    dg(
1355        "bynk.refine.literal_violates",
1356        "A literal does not satisfy the refined type's predicate.",
1357        &["refined_type"],
1358    ),
1359    dg(
1360        "bynk.requires.unpinned_dependency",
1361        "An adapter `binding … requires { … }` entry has an unpinned version range.",
1362        &["binding_decl"],
1363    ),
1364    d(
1365        "bynk.resolve.ambiguous_variant",
1366        "A variant name is ambiguous across several sum types.",
1367    ),
1368    dg(
1369        "bynk.resolve.arity_mismatch",
1370        "A function was called with the wrong number of arguments.",
1371        &["call"],
1372    ),
1373    d("bynk.resolve.duplicate_actor", "Two actors share a name."),
1374    dg(
1375        "bynk.resolve.duplicate_agent",
1376        "Two agents share a name.",
1377        &["agent_decl"],
1378    ),
1379    dg(
1380        "bynk.resolve.duplicate_capability",
1381        "Two capabilities share a name.",
1382        &["capability_decl"],
1383    ),
1384    dg(
1385        "bynk.resolve.duplicate_field",
1386        "A record declares a field twice.",
1387        &["record_type"],
1388    ),
1389    dg(
1390        "bynk.resolve.duplicate_field_init",
1391        "A record construction initialises a field twice.",
1392        &["record_construction"],
1393    ),
1394    dg(
1395        "bynk.resolve.duplicate_fn",
1396        "Two functions share a name.",
1397        &["fn_decl"],
1398    ),
1399    d(
1400        "bynk.resolve.duplicate_message_code",
1401        "A message bundle declares the same code twice in one block.",
1402    ),
1403    d(
1404        "bynk.resolve.duplicate_message_locale",
1405        "Two `messages` blocks in one bundle declare the same locale tag.",
1406    ),
1407    dg(
1408        "bynk.resolve.duplicate_method",
1409        "Two methods share a name.",
1410        &["fn_decl"],
1411    ),
1412    dg(
1413        "bynk.resolve.duplicate_param",
1414        "A parameter name is repeated.",
1415        &["param"],
1416    ),
1417    dg(
1418        "bynk.resolve.duplicate_provider",
1419        "A capability is provided more than once.",
1420        &["provider_decl"],
1421    ),
1422    dg(
1423        "bynk.resolve.duplicate_service",
1424        "Two services share a name.",
1425        &["service_decl"],
1426    ),
1427    dg(
1428        "bynk.resolve.duplicate_type",
1429        "Two types share a name.",
1430        &["type_decl"],
1431    ),
1432    dg(
1433        "bynk.resolve.duplicate_variant",
1434        "A sum type declares a variant twice.",
1435        &["sum_type"],
1436    ),
1437    d(
1438        "bynk.resolve.fn_without_call",
1439        "A function was referenced without being called.",
1440    ),
1441    dg(
1442        "bynk.resolve.let_shadows_fn",
1443        "A `let` binding shadows a function.",
1444        &["let_stmt"],
1445    ),
1446    dg(
1447        "bynk.resolve.let_shadows_type",
1448        "A `let` binding shadows a type.",
1449        &["let_stmt"],
1450    ),
1451    d(
1452        "bynk.resolve.method_unknown_type",
1453        "A method is defined on an unknown type.",
1454    ),
1455    dg(
1456        "bynk.resolve.missing_field",
1457        "A record construction omits a required field.",
1458        &["record_construction"],
1459    ),
1460    d(
1461        "bynk.resolve.name_conflict",
1462        "Two declarations share a name.",
1463    ),
1464    dg(
1465        "bynk.resolve.not_a_record_type",
1466        "Record syntax was used on a non-record type.",
1467        &["record_construction"],
1468    ),
1469    dg(
1470        "bynk.resolve.opaque_record_construction",
1471        "An opaque type was constructed with record syntax.",
1472        &["record_construction"],
1473    ),
1474    dg(
1475        "bynk.resolve.param_as_function",
1476        "A value (such as a parameter) was called as a function.",
1477        &["call"],
1478    ),
1479    dg(
1480        "bynk.resolve.recursive_record_field",
1481        "A record directly contains a field of its own type.",
1482        &["record_type"],
1483    ),
1484    dg(
1485        "bynk.resolve.reserved_builtin_type",
1486        "A type declaration reuses a compiler-known built-in type name.",
1487        &["type_decl"],
1488    ),
1489    dg(
1490        "bynk.resolve.self_outside_method",
1491        "`self` referenced outside a method or handler.",
1492        &["self_expr"],
1493    ),
1494    dg(
1495        "bynk.resolve.type_as_function",
1496        "A type name was called as if it were a function.",
1497        &["call"],
1498    ),
1499    d(
1500        "bynk.resolve.type_in_expr",
1501        "A type name was used where a value is expected.",
1502    ),
1503    dg(
1504        "bynk.resolve.unconsumed_context",
1505        "A context's service was called without a `consumes` declaration.",
1506        &["consumes_decl"],
1507    ),
1508    dg(
1509        "bynk.resolve.unknown_field",
1510        "Accessed a field the record does not have.",
1511        &["field_access"],
1512    ),
1513    dg(
1514        "bynk.resolve.unknown_function",
1515        "Called a function that does not exist.",
1516        &["call"],
1517    ),
1518    d(
1519        "bynk.resolve.unknown_name",
1520        "Referenced a name that is not in scope.",
1521    ),
1522    dg(
1523        "bynk.resolve.unknown_static_member",
1524        "Referenced an unknown static member (e.g. `T.x`).",
1525        &["field_access"],
1526    ),
1527    d(
1528        "bynk.resolve.unknown_type",
1529        "Referenced a type that does not exist.",
1530    ),
1531    warn(d(
1532        "bynk.secrets.computed_name",
1533        "A `bynk.Secrets` read names its secret with a computed expression rather than a literal, so `bynk deploy` cannot plan it (warning).",
1534    )),
1535    dg(
1536        "bynk.send.in_pure_context",
1537        "A `~>` send was used in a pure (non-effectful) context.",
1538        &["effect_send_stmt"],
1539    ),
1540    dg(
1541        "bynk.send.non_effect",
1542        "A `~>` send was applied to a non-`Effect` value.",
1543        &["effect_send_stmt"],
1544    ),
1545    dg(
1546        "bynk.send.requires_unit",
1547        "A `~>` send targets an operation whose reply is not `Effect[()]`.",
1548        &["effect_send_stmt"],
1549    ),
1550    dg(
1551        "bynk.service.missing_from",
1552        "A `from`-less service has a handler other than `on call`.",
1553        &["service_decl"],
1554    ),
1555    dg(
1556        "bynk.service.mixed_protocols",
1557        "A service mixes handler forms that do not match its `from <protocol>`.",
1558        &["service_decl"],
1559    ),
1560    dg(
1561        "bynk.service.outside_context",
1562        "A `service` was declared outside a context.",
1563        &["service_decl"],
1564    ),
1565    dg(
1566        "bynk.service.return_not_effect",
1567        "A service handler's return type is not an `Effect`.",
1568        &["service_decl"],
1569    ),
1570    dg(
1571        "bynk.service.unknown_protocol",
1572        "A `from <protocol>` names an unknown protocol (e.g. a transport like Kafka).",
1573        &["service_decl"],
1574    ),
1575    d(
1576        "bynk.service.websocket_header",
1577        "The `from websocket` header is malformed — it binds frame types as `websocket(in: <type>, out: <type>)` (real-time track slice 3).",
1578    ),
1579    d(
1580        "bynk.service.websocket_multiple",
1581        "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).",
1582    ),
1583    d(
1584        "bynk.service.websocket_open_arity",
1585        "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).",
1586    ),
1587    d(
1588        "bynk.store.annotation_kind_mismatch",
1589        "A storage annotation is used on a kind it does not apply to (e.g. `@ttl` on a `Map`).",
1590    ),
1591    d(
1592        "bynk.store.annotation_unsupported",
1593        "A known storage annotation (`@ttl`/`@retain`/`@indexed`/`@bounded`) is used before the slice that supports it.",
1594    ),
1595    d(
1596        "bynk.store.cache_needs_clock",
1597        "A handler performs a `Cache` operation (TTL expiry reads the clock) without declaring `given Clock`.",
1598    ),
1599    d(
1600        "bynk.store.cache_ttl_required",
1601        "A `Cache` field is missing its required `@ttl(<duration>)` annotation (a keyed store with no expiry is a `Map`).",
1602    ),
1603    d(
1604        "bynk.store.kind_arity",
1605        "A storage kind was applied to the wrong number of type arguments (e.g. `Cell[A, B]`).",
1606    ),
1607    d(
1608        "bynk.store.kind_unsupported",
1609        "A known storage kind (`Queue`) is used before the slice that supports it.",
1610    ),
1611    d(
1612        "bynk.store.log_needs_clock",
1613        "A handler calls `Log.append` (which stamps the current time) without declaring `given Clock`.",
1614    ),
1615    d(
1616        "bynk.store.unknown_annotation",
1617        "A `store` field carries an annotation outside the closed `@indexed`/`@ttl`/`@retain`/`@bounded` set.",
1618    ),
1619    d(
1620        "bynk.store.unknown_kind",
1621        "A `store` field's type is not a known storage kind.",
1622    ),
1623    d(
1624        "bynk.store.unknown_map_accessor",
1625        "A `store Map` field access is not one of its query accessors (`entries`/`keys`/`values`).",
1626    ),
1627    d(
1628        "bynk.store.unknown_op",
1629        "A storage-`Map`/`Set` operation is not a recognised entry/membership method.",
1630    ),
1631    d(
1632        "bynk.stub.bad_sequence",
1633        "A `stub … returns each […]` sequence is malformed (e.g. empty).",
1634    ),
1635    d(
1636        "bynk.stub.generic_op",
1637        "A test `stub` targets a capability operation that declares its own type parameter — not supported at v1.",
1638    ),
1639    d(
1640        "bynk.stub.not_a_seam",
1641        "A test `stub` overrides a capability the unit under test does not consume.",
1642    ),
1643    d(
1644        "bynk.stub.rhs_type",
1645        "A test `stub … returns <value>` right-hand side does not match the operation's return type.",
1646    ),
1647    d(
1648        "bynk.stub.unknown_op",
1649        "A test `stub` names an operation the capability does not declare.",
1650    ),
1651    dg(
1652        "bynk.suite.duplicate_case_name",
1653        "Two `case`s share a description.",
1654        &["case"],
1655    ),
1656    dg(
1657        "bynk.suite.unknown_target",
1658        "A `suite` targets a unit that does not exist.",
1659        &["suite_decl"],
1660    ),
1661    d(
1662        "bynk.target.browser_bundle_only",
1663        "The `browser` platform builds only the in-process `Bundle` topology; `--target workers` is not a browser build.",
1664    ),
1665    dg(
1666        "bynk.target.vendor_conflict",
1667        "One deployment unit's in-process closure uses platform-native capabilities from two mutually-exclusive platforms.",
1668        &["consumes_decl"],
1669    ),
1670    dg(
1671        "bynk.target.vendor_required",
1672        "A deployment unit uses a platform-native capability but the build selects another `--platform`.",
1673        &["consumes_decl"],
1674    ),
1675    dg(
1676        "bynk.test.actor_identity_required",
1677        "A call-site `by <Actor>` omits the identity an identity-carrying actor requires.",
1678        &["case"],
1679    ),
1680    dg(
1681        "bynk.test.actor_no_identity",
1682        "A call-site `by <Actor>(x)` supplies an identity to an actor that takes none — a unit-identity actor (e.g. `Visitor`) or `Nobody`.",
1683        &["case"],
1684    ),
1685    dg(
1686        "bynk.test.credential_needs_system",
1687        "A case drives `by Nobody` (the no-credential principal, which tests the auth seam's 401) outside a `system`-tier case, where there is no real seam to reject it.",
1688        &["case"],
1689    ),
1690    dg(
1691        "bynk.test.nobody_needs_secured_route",
1692        "A case drives `by Nobody` at a route that is not Bearer-secured (e.g. a public `Visitor` route) — there is no auth seam to reject the missing credential.",
1693        &["case"],
1694    ),
1695    dg(
1696        "bynk.test.principal_identity_mismatch",
1697        "A call-site `by <Actor>` acts as an actor whose identity is incompatible with the addressed handler's actor.",
1698        &["case"],
1699    ),
1700    dg(
1701        "bynk.test.principal_on_wrong_method",
1702        "A wrong-method `405` test carries a `by <Actor>` clause; it reaches no handler, so a principal is meaningless.",
1703        &["case"],
1704    ),
1705    dg(
1706        "bynk.test.principal_required",
1707        "A test drives an identity-carrying handler with no call-site `by <Actor>(<identity>)`.",
1708        &["case"],
1709    ),
1710    dg(
1711        "bynk.test.service_bad_address",
1712        "A test body addresses a service the wrong way for its protocol (e.g. an http route without a leading path string).",
1713        &["case"],
1714    ),
1715    dg(
1716        "bynk.test.service_call_arity",
1717        "A test body's `svc.call(...)` passes the wrong number of arguments for the service's `on call` handler.",
1718        &["case"],
1719    ),
1720    dg(
1721        "bynk.test.service_no_call_handler",
1722        "A test body invokes `svc.call(...)` on a service with no `on call` handler (a `from http`/`cron`/`queue` service).",
1723        &["case"],
1724    ),
1725    dg(
1726        "bynk.test.service_unknown_route",
1727        "A test body addresses an http route / cron schedule / queue message the service does not declare.",
1728        &["case"],
1729    ),
1730    dg(
1731        "bynk.test.unknown_actor",
1732        "A call-site `by <Actor>` names an actor the target context does not declare and that is not a prelude actor.",
1733        &["case"],
1734    ),
1735    dg(
1736        "bynk.test.wire_needs_system",
1737        "A `Wire(...)` raw argument is used outside a `system`-tier service address; `Wire` hands pre-validation input to the boundary and is meaningless at `unit` or in any other position.",
1738        &["case"],
1739    ),
1740    d(
1741        "bynk.tier.property_has_tier",
1742        "A `property` carries an `as <tier>` clause; tiers are a `case`-only affordance.",
1743    ),
1744    d(
1745        "bynk.tier.system_needs_wire",
1746        "An `as system` test stands up fewer than two contexts; the system tier wires across contexts.",
1747    ),
1748    d(
1749        "bynk.transition.cross_agent_reference",
1750        "A transition predicate references another agent; step invariants are per-agent.",
1751    ),
1752    d(
1753        "bynk.transition.duplicate_name",
1754        "An agent declares two transitions with the same name.",
1755    ),
1756    d(
1757        "bynk.transition.impure_predicate",
1758        "A transition predicate uses an effectful or test-only construct; a step invariant must be pure.",
1759    ),
1760    d(
1761        "bynk.transition.no_step_reference",
1762        "A transition references neither `old` nor `new`; it constrains one state, so it is an `invariant`, not a step.",
1763    ),
1764    d(
1765        "bynk.transition.not_bool",
1766        "A transition predicate does not have type `Bool`.",
1767    ),
1768    d(
1769        "bynk.types.ambiguous_constructor",
1770        "`Ok`/`Err` is ambiguous between `Result` and `HttpResult`; qualify it.",
1771    ),
1772    dg(
1773        "bynk.types.argument_mismatch",
1774        "A call, method, capability, or constructor argument has the wrong type.",
1775        &["call"],
1776    ),
1777    dg(
1778        "bynk.types.call_arity",
1779        "A function value was applied with the wrong number of arguments.",
1780        &["call"],
1781    ),
1782    dg(
1783        "bynk.types.cannot_infer_option_type_param",
1784        "The value type of `None` could not be inferred.",
1785        &["none_expr"],
1786    ),
1787    d(
1788        "bynk.types.cannot_infer_result_type_params",
1789        "The type parameters of a `Result` could not be inferred.",
1790    ),
1791    dg(
1792        "bynk.types.catastrophic_regex",
1793        "A `Matches` predicate nests unbounded quantifiers, risking catastrophic backtracking (ReDoS).",
1794        &["refinement"],
1795    ),
1796    dg(
1797        "bynk.types.combinator_return_mismatch",
1798        "A callback passed to a combinator (`map`/`andThen`/`flatMap`/`traverseAll`/…) returns the wrong type.",
1799        &["call"],
1800    ),
1801    d(
1802        "bynk.types.constructor_arity",
1803        "A variant constructor got the wrong number of arguments.",
1804    ),
1805    d(
1806        "bynk.types.constructor_base_mismatch",
1807        "A `.of` constructor was given an argument of the wrong base type.",
1808    ),
1809    dg(
1810        "bynk.types.duplicate_literal_arm",
1811        "A `match` has two arms for the same literal value.",
1812        &["match_arm"],
1813    ),
1814    dg(
1815        "bynk.types.duplicate_variant_arm",
1816        "A `match` has two arms for the same variant.",
1817        &["match_arm"],
1818    ),
1819    d(
1820        "bynk.types.embeds_ambiguous",
1821        "A type is embedded by more than one variant of a sum, so `?`'s conversion would be ambiguous.",
1822    ),
1823    d(
1824        "bynk.types.embeds_unknown_variant",
1825        "An `embeds … as V` clause names a variant the sum does not declare.",
1826    ),
1827    d(
1828        "bynk.types.embeds_variant_shape",
1829        "An `embeds E as V` target variant must have exactly one payload field, of type `E`.",
1830    ),
1831    dg(
1832        "bynk.types.empty_refinement",
1833        "A refinement admits no values (contradictory predicates).",
1834        &["refinement"],
1835    ),
1836    dg(
1837        "bynk.types.err_value_mismatch",
1838        "An `Err` payload has the wrong type.",
1839        &["err_expr"],
1840    ),
1841    dg(
1842        "bynk.types.field_access_on_non_record",
1843        "Field access on a value that is not a record.",
1844        &["field_access"],
1845    ),
1846    dg(
1847        "bynk.types.field_refinement_not_base",
1848        "An inline field refinement requires a base or refined type.",
1849        &["record_field"],
1850    ),
1851    dg(
1852        "bynk.types.field_value_mismatch",
1853        "A record field was given a value of the wrong type.",
1854        &["record_construction"],
1855    ),
1856    dg(
1857        "bynk.types.function_at_boundary",
1858        "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.",
1859        &["function_type_ref"],
1860    ),
1861    dg(
1862        "bynk.types.guard_not_bool",
1863        "A match-arm `if` guard is not a `Bool` expression.",
1864        &["match_arm"],
1865    ),
1866    d(
1867        "bynk.types.held_at_boundary",
1868        "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).",
1869    ),
1870    d(
1871        "bynk.types.held_not_comparable",
1872        "A held value (`Connection[F]`) is compared with `==`/`!=` — held values have identity, not value-equality (§2.9.3, real-time track slice 2).",
1873    ),
1874    dg(
1875        "bynk.types.if_branch_mismatch",
1876        "The branches of an `if` have different types.",
1877        &["if_expr"],
1878    ),
1879    dg(
1880        "bynk.types.if_non_bool_cond",
1881        "An `if` condition is not a `Bool`.",
1882        &["if_expr"],
1883    ),
1884    dg(
1885        "bynk.types.if_without_else_requires_unit",
1886        "An `if` with no `else` branch has a non-unit then-branch; the missing else defaults to `()`, so the branch must be `()` or `Effect[()]`.",
1887        &["if_expr"],
1888    ),
1889    d(
1890        "bynk.types.interpolation_non_scalar",
1891        "An interpolation hole holds a value with no string form.",
1892    ),
1893    dg(
1894        "bynk.types.invalid_regex",
1895        "A `Matches` predicate contains an invalid regular expression.",
1896        &["refinement"],
1897    ),
1898    dg(
1899        "bynk.types.inverted_range",
1900        "An `InRange` predicate has its bounds inverted.",
1901        &["refinement"],
1902    ),
1903    dg(
1904        "bynk.types.is_base_mismatch",
1905        "An `is` refinement check is applied to a value of the wrong base type.",
1906        &["is_expr"],
1907    ),
1908    dg(
1909        "bynk.types.is_literal_pattern",
1910        "A literal was used on the right of `is`; `is` tests type/refinement, not value equality (use `==`).",
1911        &["is_expr"],
1912    ),
1913    dg(
1914        "bynk.types.is_non_sum",
1915        "`is` was applied to a value that is not a sum type.",
1916        &["is_expr"],
1917    ),
1918    dg(
1919        "bynk.types.is_refined_pattern",
1920        "A refined (`where`) pattern was used on the right of `is`; refined patterns are `match`-only.",
1921        &["is_expr"],
1922    ),
1923    dg(
1924        "bynk.types.is_unknown_variant",
1925        "`is` names a variant the type does not have.",
1926        &["is_expr"],
1927    ),
1928    dg(
1929        "bynk.types.json_uncodable",
1930        "A `Json.encode`/`Json.decode` target type cannot pass through the typed JSON codec (functions, effects, error builtins).",
1931        &["method_call"],
1932    ),
1933    dg(
1934        "bynk.types.key_not_orderable",
1935        "A `sortBy`/`min`/`max` key function does not return an orderable type (`Int`, `Float`, `String`, `Duration`, or `Instant`).",
1936        &[],
1937    ),
1938    dg(
1939        "bynk.types.lambda_mismatch",
1940        "A lambda's parameter count, parameter annotations, or body type do not match the expected function type.",
1941        &["lambda_expr"],
1942    ),
1943    dg(
1944        "bynk.types.let_annotation_mismatch",
1945        "A `let` value does not match its type annotation.",
1946        &["let_stmt"],
1947    ),
1948    dg(
1949        "bynk.types.list_element_mismatch",
1950        "A list-literal element has a different type from the list's element type.",
1951        &["list_literal"],
1952    ),
1953    dg(
1954        "bynk.types.match_arm_mismatch",
1955        "A `match` arm has a different type from the others.",
1956        &["match_arm"],
1957    ),
1958    dg(
1959        "bynk.types.match_non_sum_discriminant",
1960        "`match` was applied to a value that is not a sum type.",
1961        &["match_expr"],
1962    ),
1963    dg(
1964        "bynk.types.method_arity",
1965        "A method was called with the wrong number of arguments.",
1966        &["method_call"],
1967    ),
1968    dg(
1969        "bynk.types.method_not_found",
1970        "Called a method the type does not have.",
1971        &["method_call"],
1972    ),
1973    dg(
1974        "bynk.types.method_on_non_named_type",
1975        "A method was called on a built-in type that has no methods.",
1976        &["method_call"],
1977    ),
1978    dg(
1979        "bynk.types.mixed_pattern_bindings",
1980        "A pattern mixes named and positional bindings.",
1981        &["variant_pattern"],
1982    ),
1983    dg(
1984        "bynk.types.negative_length",
1985        "A length predicate was given a negative value.",
1986        &["refinement"],
1987    ),
1988    dg(
1989        "bynk.types.no_numeric_coercion",
1990        "`Int` and `Float` were mixed without an explicit conversion — in an operation or in refinement bounds.",
1991        &["binary_expr", "refinement"],
1992    ),
1993    dg(
1994        "bynk.types.non_exhaustive_match",
1995        "A `match` does not cover every variant.",
1996        &["match_expr"],
1997    ),
1998    dg(
1999        "bynk.types.ok_value_mismatch",
2000        "An `Ok` payload has the wrong type.",
2001        &["ok_expr"],
2002    ),
2003    dg(
2004        "bynk.types.opaque_raw_outside",
2005        "`.raw` on an opaque type was used outside its defining commons.",
2006        &["field_access"],
2007    ),
2008    dg(
2009        "bynk.types.opaque_record_construction",
2010        "An opaque type was constructed with record syntax.",
2011        &["record_construction"],
2012    ),
2013    dg(
2014        "bynk.types.opaque_unsafe_outside",
2015        "`.unsafe` on an opaque type was used outside its defining context.",
2016        &["field_access"],
2017    ),
2018    dg(
2019        "bynk.types.or_pattern_binding_mismatch",
2020        "An or-pattern's alternatives don't all bind the same set of names.",
2021        &["match_arm", "is_expr"],
2022    ),
2023    dg(
2024        "bynk.types.or_pattern_type_mismatch",
2025        "An or-pattern's alternatives give a shared binding different types (or refinements).",
2026        &["match_arm", "is_expr"],
2027    ),
2028    dg(
2029        "bynk.types.pattern_arity",
2030        "A pattern binds the wrong number of payload fields.",
2031        &["variant_pattern"],
2032    ),
2033    dg(
2034        "bynk.types.pattern_type_mismatch",
2035        "A pattern's type does not match the matched value.",
2036        &["variant_pattern"],
2037    ),
2038    dg(
2039        "bynk.types.predicate_base_mismatch",
2040        "A predicate does not apply to the type's base (e.g. a string predicate on an `Int`).",
2041        &["refinement"],
2042    ),
2043    d(
2044        "bynk.types.query_at_boundary",
2045        "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).",
2046    ),
2047    dg(
2048        "bynk.types.question_error_mismatch",
2049        "`?` propagates an error type incompatible with the function's.",
2050        &["question_expr"],
2051    ),
2052    dg(
2053        "bynk.types.question_on_non_result",
2054        "`?` was applied to a non-`Result` value.",
2055        &["question_expr"],
2056    ),
2057    dg(
2058        "bynk.types.question_option_outside_http",
2059        "`?` lifts an `Option` only inside a handler returning `HttpResult` (`None` becomes `NotFound`); elsewhere use `.okOr(err)`.",
2060        &["question_expr"],
2061    ),
2062    dg(
2063        "bynk.types.question_outside_result",
2064        "`?` used in a function that does not return a `Result`.",
2065        &["question_expr"],
2066    ),
2067    d(
2068        "bynk.types.return_mismatch",
2069        "A returned value does not match the declared return type.",
2070    ),
2071    dg(
2072        "bynk.types.some_value_mismatch",
2073        "A `Some` payload has the wrong type.",
2074        &["some_expr"],
2075    ),
2076    d(
2077        "bynk.types.stream_at_boundary",
2078        "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).",
2079    ),
2080    d(
2081        "bynk.types.stream_not_comparable",
2082        "A `Stream` value is compared with `==`/`!=` — a stream is a live value-over-time source, not a comparable value (real-time track slice 0).",
2083    ),
2084    d(
2085        "bynk.types.type_mismatch",
2086        "Two types that were required to match did not.",
2087    ),
2088    dg(
2089        "bynk.types.uninferable_element_type",
2090        "An empty `[]` (or `List.empty()` / `Map.empty()`) has no expected type to infer its element type from.",
2091        &["list_literal"],
2092    ),
2093    dg(
2094        "bynk.types.unkeyable_distinct",
2095        "A `distinct`/`distinctBy` element or key is not value-keyable (`String`, `Int`, or a refined/opaque type over them).",
2096        &[],
2097    ),
2098    dg(
2099        "bynk.types.unkeyable_map_key",
2100        "A `Map` key type is not value-keyable (`String`, `Int`, or a refined/opaque type over them).",
2101        &["generic_type_ref"],
2102    ),
2103    dg(
2104        "bynk.types.unknown_field",
2105        "Referenced a field the record type does not declare.",
2106        &["field_access"],
2107    ),
2108    dg(
2109        "bynk.types.unknown_pattern_field",
2110        "A pattern names a field the variant does not have.",
2111        &["variant_pattern"],
2112    ),
2113    dg(
2114        "bynk.types.unknown_static_member",
2115        "Referenced an unknown static member on a type.",
2116        &["field_access"],
2117    ),
2118    dg(
2119        "bynk.types.unknown_variant_in_pattern",
2120        "A pattern names a variant the sum type does not have.",
2121        &["variant_pattern"],
2122    ),
2123    dg(
2124        "bynk.types.unreachable_arm",
2125        "A `match` arm is unreachable.",
2126        &["match_arm"],
2127    ),
2128    d(
2129        "bynk.types.variant_arity",
2130        "A variant constructor got the wrong number of payload values.",
2131    ),
2132    d(
2133        "bynk.types.variant_missing_payload",
2134        "A variant requiring a payload was used without one.",
2135    ),
2136    d(
2137        "bynk.types.variant_payload_mismatch",
2138        "A variant payload has the wrong type.",
2139    ),
2140    dg(
2141        "bynk.uses.name_conflict",
2142        "A `uses` name collides with another name.",
2143        &["uses_decl"],
2144    ),
2145    dg(
2146        "bynk.uses.self_reference",
2147        "A commons `uses` itself.",
2148        &["uses_decl"],
2149    ),
2150    dg(
2151        "bynk.uses.target_is_context",
2152        "`uses` targets a context instead of a commons.",
2153        &["uses_decl"],
2154    ),
2155    dg(
2156        "bynk.uses.unknown_commons",
2157        "`uses` names a commons that does not exist.",
2158        &["uses_decl"],
2159    ),
2160    dg(
2161        "bynk.val.agent_not_generable",
2162        "A `for all`/`Val` cannot generate an agent — fabricated agent states need not be reachable.",
2163        &["for_all"],
2164    ),
2165    dg(
2166        "bynk.val.arity",
2167        "`Val[T]` was given the wrong number of pin arguments.",
2168        &["val_expr"],
2169    ),
2170    dg(
2171        "bynk.val.literal_violates",
2172        "A pinned `Val[T]` value violates the type's refinement.",
2173        &["val_expr"],
2174    ),
2175    dg(
2176        "bynk.val.needs_pin",
2177        "A bare `Val[T]` cannot generate a value (e.g. a `Matches` string); pin one.",
2178        &["val_expr"],
2179    ),
2180    dg(
2181        "bynk.val.outside_test",
2182        "`Val[T]` was used outside a test case body.",
2183        &["val_expr"],
2184    ),
2185    dg(
2186        "bynk.val.pin_not_literal",
2187        "A `Val[T]` pin argument is not a compile-time literal.",
2188        &["val_expr"],
2189    ),
2190    dg(
2191        "bynk.val.pin_unsupported",
2192        "A pin was given for a type kind that does not support pinning.",
2193        &["val_expr"],
2194    ),
2195    dg(
2196        "bynk.val.unknown_type",
2197        "`Val[T]` names a type that does not resolve.",
2198        &["val_expr"],
2199    ),
2200    dg(
2201        "bynk.val.unsupported_kind",
2202        "`Val[T]` cannot fabricate a value for this kind of type.",
2203        &["val_expr"],
2204    ),
2205    d(
2206        "bynk.ws.message_frame_param",
2207        "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).",
2208    ),
2209    d(
2210        "bynk.ws.open_given_unsupported",
2211        "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).",
2212    ),
2213    d(
2214        "bynk.ws.open_transfer_shape",
2215        "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).",
2216    ),
2217    d(
2218        "bynk.ws.route_param_mismatch",
2219        "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).",
2220    ),
2221];
2222
2223/// A diagnostic with no single governing grammar construct. `Error` severity.
2224const fn d(code: &'static str, summary: &'static str) -> DiagnosticInfo {
2225    DiagnosticInfo {
2226        code,
2227        summary,
2228        grammar_symbol: &[],
2229        severity: Severity::Error,
2230    }
2231}
2232
2233/// A diagnostic that constrains one or more grammar productions. `Error` severity.
2234const fn dg(
2235    code: &'static str,
2236    summary: &'static str,
2237    grammar_symbol: &'static [&'static str],
2238) -> DiagnosticInfo {
2239    DiagnosticInfo {
2240        code,
2241        summary,
2242        grammar_symbol,
2243        severity: Severity::Error,
2244    }
2245}
2246
2247/// Downgrades a [`d`]/[`dg`]-built entry to `Warning` severity (ADR 0117) —
2248/// non-failing, surfaced alongside a clean build. The six call sites here are
2249/// the single source of truth [`crate::error::Severity::for_error`] reads.
2250const fn warn(mut info: DiagnosticInfo) -> DiagnosticInfo {
2251    info.severity = Severity::Warning;
2252    info
2253}
2254
2255/// The category segment of a code (the part between the first two dots), e.g.
2256/// `"types"` for `"bynk.types.type_mismatch"`.
2257pub fn category(code: &str) -> &str {
2258    code.split('.').nth(1).unwrap_or("")
2259}
2260
2261/// A human-readable heading for a category segment.
2262fn category_title(cat: &str) -> &'static str {
2263    match cat {
2264        "agent" | "agents" => "Agents",
2265        "boundary" => "Boundaries",
2266        "capability" => "Capabilities",
2267        "consumes" => "Consumes",
2268        "context" => "Contexts",
2269        "contract" => "Contracts",
2270        "cron" => "Cron",
2271        "effect" => "Effects",
2272        "expect" => "Expectations",
2273        "exports" => "Exports",
2274        "given" => "Given capabilities",
2275        "http" => "HTTP",
2276        "lex" => "Lexer",
2277        "messages" => "Message bundles",
2278        "mock" => "Mocks (collaborators)",
2279        "observe" => "Observation",
2280        "parse" => "Parser",
2281        "project" => "Project",
2282        "property" => "Properties (generative tests)",
2283        "provider" => "Providers",
2284        "queue" => "Queue",
2285        "record_spread" => "Record spread",
2286        "refine" => "Refinement",
2287        "resolve" => "Resolution",
2288        "service" => "Services",
2289        "suite" => "Suites and cases",
2290        "transition" => "Transitions (step invariants)",
2291        "types" => "Type checking",
2292        "uses" => "Uses",
2293        "val" => "Value fabrication",
2294        _ => "Other",
2295    }
2296}
2297
2298/// Render the diagnostic index as a Markdown reference page, grouped by
2299/// category. This is the generator behind
2300/// `site/src/content/docs/book/reference/diagnostics.md`.
2301pub fn render_markdown() -> String {
2302    use std::collections::BTreeMap;
2303
2304    // Group codes by their category title, preserving sorted code order.
2305    let mut by_category: BTreeMap<&str, Vec<&DiagnosticInfo>> = BTreeMap::new();
2306    for info in REGISTRY {
2307        by_category
2308            .entry(category_title(category(info.code)))
2309            .or_default()
2310            .push(info);
2311    }
2312
2313    let mut out = String::new();
2314    out.push_str("# Diagnostic index\n\n");
2315    out.push_str(
2316        "<!-- GENERATED FILE — do not edit by hand.\n     \
2317         Source: bynkc/src/diagnostics.rs (`render_markdown`).\n     \
2318         Regenerate with: BYNK_BLESS=1 cargo test -p bynkc --test diagnostics_registry -->\n\n",
2319    );
2320    out.push_str(
2321        "Every diagnostic code the compiler can emit, with a one-line summary of \
2322         the cause, grouped by category. For step-by-step cause-and-fix guidance \
2323         on the most common ones, see the [troubleshooting guides](../troubleshooting/index.md).\n\n",
2324    );
2325    out.push_str(&format!(
2326        "There are **{}** codes in total.\n",
2327        REGISTRY.len()
2328    ));
2329
2330    for (title, infos) in &by_category {
2331        out.push_str(&format!("\n## {title}\n\n"));
2332        out.push_str("| Code | Summary | Construct | Severity |\n|---|---|---|---|\n");
2333        for info in infos {
2334            // The construct column deep-links each governing production to its
2335            // entry in the annotated grammar reference; generated from
2336            // `grammar_symbol` (each value is an embeddable rule, so the
2337            // `#rule-<raw>` anchor resolves — enforced in diagnostics_registry).
2338            let construct = info
2339                .grammar_symbol
2340                .iter()
2341                .map(|sym| format!("[`{sym}`](grammar.md#rule-{sym})"))
2342                .collect::<Vec<_>>()
2343                .join(", ");
2344            // A curated (`bynk explain`-able) code links to its Book concept
2345            // page; the in-site link is validated by the site's link checker,
2346            // so a moved page or renamed anchor fails the build (#853). Codes
2347            // without an explanation render as plain inline code.
2348            let code_cell = match explain(info.code) {
2349                Some(e) => format!("[`{}`]({})", info.code, e.in_site_link()),
2350                None => format!("`{}`", info.code),
2351            };
2352            // ADR 0117/finding #50: every code's severity, straight from the
2353            // registry — `Error` (the overwhelming majority) renders as "—"
2354            // to keep the common case unobtrusive; only a `warn`-built entry
2355            // shows "Warning".
2356            let severity = match info.severity {
2357                Severity::Error => "—",
2358                Severity::Warning => "Warning",
2359            };
2360            out.push_str(&format!(
2361                "| {} | {} | {} | {} |\n",
2362                code_cell, info.summary, construct, severity
2363            ));
2364        }
2365    }
2366
2367    out
2368}
2369
2370/// Invert the registry into a `{ "<rule>": [ { code, summary }, … ], … }` map,
2371/// serialised as pretty JSON with sorted keys and sorted codes. Only rules with
2372/// at least one diagnostic appear. This is the generator behind
2373/// `docs/grammar-semantics.json`, which the `{{#grammar-semantics <rule>}}`
2374/// preprocessor directive consumes.
2375pub fn render_grammar_semantics_json() -> String {
2376    use std::collections::BTreeMap;
2377
2378    // REGISTRY is sorted by code, so each rule's vector comes out code-sorted;
2379    // the BTreeMap gives sorted rule names.
2380    let mut by_symbol: BTreeMap<&str, Vec<&DiagnosticInfo>> = BTreeMap::new();
2381    for info in REGISTRY {
2382        for sym in info.grammar_symbol {
2383            by_symbol.entry(sym).or_default().push(info);
2384        }
2385    }
2386
2387    let mut map = serde_json::Map::new();
2388    map.insert(
2389        "_generated".to_string(),
2390        serde_json::Value::String(
2391            "Generated from the grammar_symbol field of bynkc/src/diagnostics.rs. \
2392             Do not edit by hand. Regenerate with: BYNK_BLESS=1 cargo test -p \
2393             bynkc --test diagnostics_registry"
2394                .to_string(),
2395        ),
2396    );
2397    for (sym, infos) in by_symbol {
2398        let arr: Vec<serde_json::Value> = infos
2399            .iter()
2400            .map(|info| serde_json::json!({ "code": info.code, "summary": info.summary }))
2401            .collect();
2402        map.insert(sym.to_string(), serde_json::Value::Array(arr));
2403    }
2404
2405    let mut s =
2406        serde_json::to_string_pretty(&serde_json::Value::Object(map)).expect("serialise semantics");
2407    s.push('\n');
2408    s
2409}