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    d(
373        "bynk.agent.state_name_conflict",
374        "A type is named `<Agent>State` beside agent `<Agent>`; that name is the agent's state record (its `Cell` fields), which its handlers and invariants see in place of the type.",
375    ),
376    dg(
377        "bynk.agents.bad_state_initialiser",
378        "An agent `store` field initialiser is not a static value of the field's type.",
379        &["store_field"],
380    ),
381    dg(
382        "bynk.agents.non_zeroable_state_field",
383        "An agent `store` field has no initialiser and no implicit zero value.",
384        &["store_field"],
385    ),
386    d(
387        "bynk.boundary.structural_mismatch",
388        "Data crossing a context boundary did not match the expected shape.",
389    ),
390    dg(
391        "bynk.capability.op_arity",
392        "A capability operation was called with the wrong number of arguments.",
393        &["capability_decl"],
394    ),
395    dg(
396        "bynk.capability.outside_context",
397        "A `capability` was declared outside a context.",
398        &["capability_decl"],
399    ),
400    dg(
401        "bynk.capability.unknown_operation",
402        "Referenced an operation the capability does not declare.",
403        &["capability_decl"],
404    ),
405    d(
406        "bynk.cell.invalid_target",
407        "A `:=` write targets something that is not a `store Cell` field.",
408    ),
409    d(
410        "bynk.cell.self_reference",
411        "A `:=` right-hand side reads the cell being written (a read-modify-write); use `.update`.",
412    ),
413    dg(
414        "bynk.consumes.alias_conflict",
415        "Two `consumes` aliases collide.",
416        &["consumes_decl"],
417    ),
418    dg(
419        "bynk.consumes.capability_name_clash",
420        "Two flattened `consumes U { Cap }` capabilities collide, or one clashes with a local capability.",
421        &["consumes_decl"],
422    ),
423    dg(
424        "bynk.consumes.name_conflict",
425        "A `consumes` name collides with another name in scope.",
426        &["consumes_decl"],
427    ),
428    dg(
429        "bynk.consumes.self_reference",
430        "A context `consumes` itself.",
431        &["consumes_decl"],
432    ),
433    dg(
434        "bynk.consumes.service_arity",
435        "A consumed service was called with the wrong number of arguments.",
436        &["consumes_decl"],
437    ),
438    dg(
439        "bynk.consumes.target_is_commons",
440        "`consumes` targets a `commons` instead of a context.",
441        &["consumes_decl"],
442    ),
443    dg(
444        "bynk.consumes.unknown_context",
445        "`consumes` names a context that does not exist.",
446        &["consumes_decl"],
447    ),
448    dg(
449        "bynk.consumes.unknown_service",
450        "Called a service the consumed context does not declare.",
451        &["consumes_decl"],
452    ),
453    d(
454        "bynk.context.consumes_cycle",
455        "Contexts form a `consumes` dependency cycle.",
456    ),
457    d(
458        "bynk.context.external_construction",
459        "A context-owned type was constructed from outside that context.",
460    ),
461    dg(
462        "bynk.context.external_provider",
463        "A bodiless (external) provider was declared outside an `adapter`.",
464        &["provider_decl"],
465    ),
466    d(
467        "bynk.context.opaque_inspection",
468        "An opaquely-exported type was inspected from outside its context.",
469    ),
470    d(
471        "bynk.context.rebrand_construction",
472        "A variant of a `uses`-sourced commons sum type was constructed directly inside a context, where the emitter's per-context rebrand leaves its constructors out of scope.",
473    ),
474    d(
475        "bynk.contract.duplicate_name",
476        "A function declares two contract clauses (`requires`/`ensures`) with the same name.",
477    ),
478    d(
479        "bynk.contract.impure_predicate",
480        "A contract predicate uses an effectful or test-only construct; a contract clause must be pure.",
481    ),
482    d(
483        "bynk.contract.not_bool",
484        "A contract predicate does not have type `Bool`.",
485    ),
486    d(
487        "bynk.contract.restated_by_test",
488        "A `case`/`property` merely restates a contract clause already declared at the function; the test is redundant.",
489    ),
490    d(
491        "bynk.contract.result_in_requires",
492        "A precondition (`requires`) references `result`; the return value is only in scope inside an `ensures`.",
493    ),
494    dg(
495        "bynk.cron.bad_params",
496        "A cron handler declares more than one parameter, or a non-`Int` one.",
497        &["cron_handler"],
498    ),
499    dg(
500        "bynk.cron.duplicate_schedule",
501        "Two cron handlers declare the same schedule.",
502        &["cron_handler"],
503    ),
504    dg(
505        "bynk.cron.invalid_schedule",
506        "A cron expression is not five whitespace-separated fields.",
507        &["cron_handler"],
508    ),
509    dg(
510        "bynk.cron.return_not_effect_result",
511        "A cron handler does not return `Effect[Result[(), E]]`.",
512        &["cron_handler"],
513    ),
514    d(
515        "bynk.deploy.contract_skew",
516        "A worker was compiled against a contract its live dependencies no longer provide, so `bynk deploy` refuses to ship it.",
517    ),
518    d(
519        "bynk.duration.literal_overflow",
520        "A `Duration` literal (`<int>.<unit>`) exceeds the representable millisecond range.",
521    ),
522    dg(
523        "bynk.effect.bind_in_pure_context",
524        "An `<-` bind was used in a pure (non-effectful) context.",
525        &["effect_let_stmt"],
526    ),
527    dg(
528        "bynk.effect.bind_on_non_effect",
529        "An `<-` bind was applied to a non-`Effect` value.",
530        &["effect_let_stmt"],
531    ),
532    d(
533        "bynk.effect.capability_in_pure_context",
534        "A capability was used in a pure context.",
535    ),
536    d(
537        "bynk.effect.cross_context_in_pure_context",
538        "A cross-context call was made in a pure context.",
539    ),
540    dg(
541        "bynk.effect.do_in_pure_context",
542        "A `do` statement was used in a pure (non-effectful) context.",
543        &["do_stmt"],
544    ),
545    dg(
546        "bynk.effect.do_on_non_effect",
547        "A `do` statement was applied to a non-`Effect` value.",
548        &["do_stmt"],
549    ),
550    dg(
551        "bynk.effect.do_requires_unit",
552        "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.",
553        &["do_stmt"],
554    ),
555    dg(
556        "bynk.effect.fn_value_in_pure_context",
557        "An effectful function value was called in a pure context; like a capability call, it is legal only where the enclosing body is effectful.",
558        &["call"],
559    ),
560    d(
561        "bynk.effect.unbound_effect",
562        "An `Effect` value in an effectful body was built but not bound with `<-`, sequenced with `do` or returned — in a plain `let`, a list element or a constructor payload — so it runs eagerly and unawaited (#1658).",
563    ),
564    d(
565        "bynk.event.bad_field_default",
566        "An event field's default expression (`field: T = expr`) is not a static, wire-representable value of the field's declared type — a literal (including one admitted to a refined type), a sum variant, `Some`/`None`/`Ok`/`Err`, a record, or `T.unsafe(lit)` for an opaque type whose literal also satisfies the refinement.",
567    ),
568    d(
569        "bynk.event.bad_params",
570        "An `on event` handler declared the wrong number of parameters, or a second parameter whose type is not `EventEnvelope` — it takes the event payload and, optionally, the runtime envelope.",
571    ),
572    d(
573        "bynk.event.bad_schema_dispatch",
574        "A `via schema(...)` dispatch clause's argument is malformed — it must be a single, positive, positional `Int` literal.",
575    ),
576    d(
577        "bynk.event.bad_schema_version",
578        "An event's `@schema(N)` annotation is malformed — `N` must be a single, positive, positional `Int` literal, and `@schema` may appear at most once on an event.",
579    ),
580    d(
581        "bynk.event.default_outside_event",
582        "A field default (`field: T = expr`) was written on a record field outside an `event` declaration — a default is only meaningful on an event's own field, since it exists to let an older wire event missing this key still deserialise.",
583    ),
584    dg(
585        "bynk.event.duplicate_handler",
586        "A `from Events` service declares more than one `on event` handler; it has exactly one.",
587        &["event_handler"],
588    ),
589    d(
590        "bynk.event.emit_not_an_event",
591        "`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.",
592    ),
593    d(
594        "bynk.event.emit_outside_owner",
595        "`Events.emit[E]` named an event `E` not declared in the emitting context — only an event's declaring context may emit it.",
596    ),
597    d(
598        "bynk.event.handler_param_type_mismatch",
599        "An `on event(e: T)` handler's declared parameter type does not match its `from Events(E)` header's event type.",
600    ),
601    d(
602        "bynk.event.non_additive_schema_change",
603        "An event's field shape changed in a way the schema registry cannot evolve additively — a field was removed, retyped, added without a default, or lost a default it previously had. Give the new shape a new event type name, or make the change additive.",
604    ),
605    d(
606        "bynk.event.outside_context",
607        "An `event` was declared outside a context.",
608    ),
609    d(
610        "bynk.event.pattern_duplicate_field",
611        "A `from Events(E { ... })` subscription pattern listed the same field more than once.",
612    ),
613    d(
614        "bynk.event.pattern_type_mismatch",
615        "A `from Events(E { ... })` subscription pattern field's matched value is not compatible with that field's declared type.",
616    ),
617    d(
618        "bynk.event.pattern_unknown_field",
619        "A `from Events(E { ... })` subscription pattern named a field that `E` does not declare.",
620    ),
621    d(
622        "bynk.event.pattern_unknown_variant",
623        "A `from Events(E { ... })` subscription pattern's variant value names a variant that does not exist on the field's declared sum type.",
624    ),
625    d(
626        "bynk.event.pattern_variant_payload",
627        "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.",
628    ),
629    dg(
630        "bynk.event.return_not_effect_unit",
631        "An `on event` handler returns an `Effect` of something other than `()`; emission is fire-and-forget, so it returns `Effect[()]`.",
632        &["event_handler"],
633    ),
634    d(
635        "bynk.event.schema_version_mismatch",
636        "An event's `@schema(N)` annotation disagrees with the version the schema registry computes from the event's build history.",
637    ),
638    d(
639        "bynk.event.unknown_annotation",
640        "An `event` declaration carried an `@`-annotation other than `@schema` — event annotations are a closed set.",
641    ),
642    d(
643        "bynk.event.unknown_subscription",
644        "A `from Events(E)` subscription named `E`, which is not a declared event in this context or any consumed context.",
645    ),
646    dg(
647        "bynk.expect.faults_not_effect",
648        "A fault claim's subject (`expect <call> faults`) is not an effectful call: a value, or a call whose type is not `Effect[_]`.",
649        &["faults_expr"],
650    ),
651    dg(
652        "bynk.expect.not_bool",
653        "`expect` was given a non-`Bool` predicate.",
654        &["expect_expr"],
655    ),
656    dg(
657        "bynk.expect.outside_case",
658        "`expect` was used outside a `case` body.",
659        &["expect_expr"],
660    ),
661    dg(
662        "bynk.exports.capability_not_provided",
663        "An exported capability has no provider in its context.",
664        &["exports_decl"],
665    ),
666    dg(
667        "bynk.exports.conflicting_visibility",
668        "A type is exported with conflicting visibilities.",
669        &["exports_decl"],
670    ),
671    dg(
672        "bynk.exports.duplicate_export",
673        "The same name is exported more than once.",
674        &["exports_decl"],
675    ),
676    dg(
677        "bynk.exports.duplicate_in_clause",
678        "A name appears twice in one `exports` clause.",
679        &["exports_decl"],
680    ),
681    dg(
682        "bynk.exports.undeclared_capability",
683        "`exports capability` names a capability that is not declared.",
684        &["exports_decl"],
685    ),
686    dg(
687        "bynk.exports.undeclared_type",
688        "`exports` names a type that is not declared.",
689        &["exports_decl"],
690    ),
691    d(
692        "bynk.fmt.comment_loss",
693        "The formatter would drop a comment, so it leaves the file unchanged.",
694    ),
695    d(
696        "bynk.fmt.roundtrip",
697        "The formatter's output does not re-parse to the same program, so it leaves the file unchanged.",
698    ),
699    dg(
700        "bynk.generics.duplicate_type_param",
701        "A `type` or `fn` declares the same type-parameter name more than once (v0.157, ADR 0183).",
702        &[],
703    ),
704    dg(
705        "bynk.generics.generic_non_record",
706        "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).",
707        &["type_decl"],
708    ),
709    dg(
710        "bynk.generics.generic_record_at_boundary",
711        "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.",
712        &[],
713    ),
714    dg(
715        "bynk.generics.generic_sum_embeds",
716        "A generic sum type carries an `embeds` clause; embedding into a generic sum is not supported (#593).",
717        &["type_decl"],
718    ),
719    dg(
720        "bynk.generics.method_on_generic_type",
721        "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).",
722        &["fn_decl"],
723    ),
724    dg(
725        "bynk.generics.no_bounds",
726        "A type parameter carries a bound (`[A: …]`); bounded generics are not in v0.20a.",
727        &["fn_decl"],
728    ),
729    dg(
730        "bynk.generics.recursive_generic_at_boundary",
731        "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).",
732        &[],
733    ),
734    dg(
735        "bynk.generics.type_arg_count",
736        "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).",
737        &["applied_type_ref"],
738    ),
739    dg(
740        "bynk.generics.type_arg_mismatch",
741        "Inferred or explicit type arguments conflict, have the wrong arity, target a non-generic function, or a type parameter shadows a declared type.",
742        &["call"],
743    ),
744    dg(
745        "bynk.generics.uninferable_type_arg",
746        "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.",
747        &["call"],
748    ),
749    dg(
750        "bynk.given.cross_context_unknown_capability",
751        "`given B.Cap` names a capability the consumed context does not export.",
752        &["given_clause"],
753    ),
754    dg(
755        "bynk.given.undeclared_capability",
756        "A handler uses a capability it did not declare with `given`.",
757        &["given_clause"],
758    ),
759    dg(
760        "bynk.given.unknown_capability",
761        "`given` names a capability that does not exist.",
762        &["given_clause"],
763    ),
764    warn(dg(
765        "bynk.given.unused_capability",
766        "A `given` capability is never used (warning).",
767        &["given_clause"],
768    )),
769    d(
770        "bynk.held.branch_divergence",
771        "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).",
772    ),
773    d(
774        "bynk.held.consume_on_borrow",
775        "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).",
776    ),
777    d(
778        "bynk.held.leak",
779        "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).",
780    ),
781    d(
782        "bynk.held.query_accessor_on_held_map",
783        "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.",
784    ),
785    d(
786        "bynk.held.unsupported_map_op",
787        "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).",
788    ),
789    d(
790        "bynk.held.unsupported_storage",
791        "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).",
792    ),
793    d(
794        "bynk.held.use_after_consume",
795        "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).",
796    ),
797    d(
798        "bynk.history.not_an_agent",
799        "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).",
800    ),
801    d(
802        "bynk.history.not_generable",
803        "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).",
804    ),
805    d(
806        "bynk.history.outside_property",
807        "`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).",
808    ),
809    d(
810        "bynk.history.restates_invariant",
811        "A history property merely re-checks a guarantee a declared `invariant`/`transition` already enforces on every reached state (testing track slice 7, ADR 0155).",
812    ),
813    dg(
814        "bynk.http.body_on_get_or_delete",
815        "A GET or DELETE handler declares a `body` parameter.",
816        &["http_handler"],
817    ),
818    d(
819        "bynk.http.cache_bad_max_age",
820        "A `@cache` annotation's `maxAge` is missing or not a positive `Duration` literal.",
821    ),
822    d(
823        "bynk.http.cache_bad_scope",
824        "A `@cache` annotation's `scope` is not `public` or `private`.",
825    ),
826    d(
827        "bynk.http.cache_duplicate",
828        "A handler carries more than one `@cache` annotation.",
829    ),
830    d(
831        "bynk.http.cache_max_age_fractional_seconds",
832        "A `@cache` annotation's `maxAge` is positive but does not resolve to a whole number of seconds.",
833    ),
834    d(
835        "bynk.http.cache_on_non_get",
836        "A `@cache` annotation is placed on a handler that is not `on http GET`.",
837    ),
838    d(
839        "bynk.http.cache_unknown_arg",
840        "A `@cache` annotation has an argument outside the closed set (`maxAge`/`scope`).",
841    ),
842    d(
843        "bynk.http.cors_invalid_field",
844        "A `cors` policy field (`headers`/`credentials`/`maxAge`) has the wrong value shape.",
845    ),
846    d(
847        "bynk.http.cors_invalid_origins",
848        "A `cors` policy's `origins` is missing, empty, or not a list of string literals.",
849    ),
850    d(
851        "bynk.http.cors_not_http",
852        "A `cors { }` policy appears on a service that is not `from http`.",
853    ),
854    d(
855        "bynk.http.cors_unknown_field",
856        "A `cors { }` policy declares a field outside the closed set.",
857    ),
858    d(
859        "bynk.http.cors_wildcard_credentials",
860        "A `cors` policy combines `credentials: true` with the wildcard origin `[\"*\"]`.",
861    ),
862    dg(
863        "bynk.http.duplicate_route",
864        "Two handlers share the same method and route.",
865        &["http_handler"],
866    ),
867    dg(
868        "bynk.http.extra_param",
869        "A handler parameter is neither a path parameter nor `body`.",
870        &["http_handler"],
871    ),
872    dg(
873        "bynk.http.invalid_path",
874        "An HTTP route path is malformed.",
875        &["http_handler"],
876    ),
877    d(
878        "bynk.http.limit_bad_max_body",
879        "A `@limit` annotation's `maxBody` is missing or not a positive `Int` literal.",
880    ),
881    d(
882        "bynk.http.limit_duplicate",
883        "A handler carries more than one `@limit` annotation.",
884    ),
885    d(
886        "bynk.http.limit_on_bodyless",
887        "A `@limit` annotation is placed on a handler that takes no body (a GET or DELETE).",
888    ),
889    d(
890        "bynk.http.limit_unknown_arg",
891        "A `@limit` annotation has an argument outside the closed set (`maxBody`).",
892    ),
893    d(
894        "bynk.http.limits_invalid_field",
895        "A `limits` policy field (`maxBody`) has the wrong value shape.",
896    ),
897    d(
898        "bynk.http.limits_not_http",
899        "A `limits { }` policy appears on a service that is not `from http`.",
900    ),
901    d(
902        "bynk.http.limits_unknown_field",
903        "A `limits { }` policy declares a field outside the closed set.",
904    ),
905    dg(
906        "bynk.http.path_param_not_stringy",
907        "A path parameter's type is not constructible from a string.",
908        &["http_handler"],
909    ),
910    dg(
911        "bynk.http.reserved_prefix",
912        "A route uses the reserved `/_bynk/` prefix.",
913        &["http_handler"],
914    ),
915    dg(
916        "bynk.http.return_not_effect_http_result",
917        "An HTTP handler does not return `Effect[HttpResult[T]]`.",
918        &["http_handler"],
919    ),
920    d(
921        "bynk.http.security_invalid_field",
922        "A `security` policy field (`hsts`/`nosniff`) has the wrong value shape.",
923    ),
924    d(
925        "bynk.http.security_not_http",
926        "A `security { }` policy appears on a service that is not `from http`.",
927    ),
928    d(
929        "bynk.http.security_unknown_field",
930        "A `security { }` policy declares a field outside the closed set.",
931    ),
932    dg(
933        "bynk.http.unbound_path_param",
934        "A `:name` route segment has no matching handler parameter.",
935        &["http_handler"],
936    ),
937    d(
938        "bynk.http.unknown_handler_annotation",
939        "A handler carries an annotation outside the closed set (`@cache`/`@limit`).",
940    ),
941    d(
942        "bynk.index.bad_argument",
943        "An `@indexed` argument is not a `by: <field>` label.",
944    ),
945    warn(d(
946        "bynk.index.missing",
947        "A query filters a map by equality on a field that is not `@indexed` (a perf-hint warning).",
948    )),
949    d(
950        "bynk.index.unkeyable_key",
951        "An `@indexed(by: k)` field is not value-keyable.",
952    ),
953    d(
954        "bynk.index.unknown_key",
955        "An `@indexed(by: k)` field is not a field of the map's value type.",
956    ),
957    warn(d(
958        "bynk.index.unused",
959        "A declared `@indexed(by: k)` is never used by an equality filter (a hygiene warning).",
960    )),
961    d(
962        "bynk.invariant.cross_agent_reference",
963        "An invariant predicate references another agent; invariants are per-agent.",
964    ),
965    d(
966        "bynk.invariant.duplicate_name",
967        "An agent declares two invariants with the same name.",
968    ),
969    d(
970        "bynk.invariant.impure_predicate",
971        "An invariant predicate uses an effectful or test-only construct.",
972    ),
973    d(
974        "bynk.invariant.not_bool",
975        "An invariant predicate does not have type `Bool`.",
976    ),
977    dg(
978        "bynk.lambda.unannotated_param",
979        "A lambda parameter has no type annotation in a position where no function type is expected to infer it from.",
980        &["lambda_expr"],
981    ),
982    dg(
983        "bynk.lex.bad_escape",
984        "An invalid escape sequence in a string literal.",
985        &["string_literal"],
986    ),
987    dg(
988        "bynk.lex.float_literal_overflow",
989        "A float literal does not fit a finite 64-bit float.",
990        &["float_literal"],
991    ),
992    dg(
993        "bynk.lex.integer_overflow",
994        "An integer literal is outside the `Int` range, the JS safe integers ±(2^53 − 1).",
995        &["number_literal"],
996    ),
997    dg(
998        "bynk.lex.interpolation_too_deep",
999        "A string interpolation `\\(…)` nests deeper than the lexer's fixed limit.",
1000        &["string_literal"],
1001    ),
1002    d(
1003        "bynk.lex.unclosed_doc_block",
1004        "A documentation block is not closed.",
1005    ),
1006    d(
1007        "bynk.lex.unexpected_character",
1008        "An unexpected character in the source.",
1009    ),
1010    dg(
1011        "bynk.lex.unterminated_interpolation",
1012        "An interpolation hole `\\(…)` is not closed on its line.",
1013        &["string_literal"],
1014    ),
1015    dg(
1016        "bynk.lex.unterminated_string",
1017        "A string literal is not terminated.",
1018        &["string_literal"],
1019    ),
1020    warn(d(
1021        "bynk.list.deprecated_function",
1022        "A `bynk.list` free function (`map`/`filter`/`find`/`any`/`all`) is deprecated in favour of the `List` method form (warning; auto-fixable).",
1023    )),
1024    d(
1025        "bynk.locale.multiple_message_bundles",
1026        "A context consumes `Locale` but its direct `uses` reaches two or more message-bundle commons — there is no single bundle to negotiate against.",
1027    ),
1028    d(
1029        "bynk.messages.format_mismatch",
1030        "A code's placeholder is formatted as a different ICU kind (plain/plural/select/number/date) across declared locales.",
1031    ),
1032    d(
1033        "bynk.messages.incomplete",
1034        "A locale is missing a code the reference locale declares.",
1035    ),
1036    d(
1037        "bynk.messages.invalid_locale_tag",
1038        "A `messages` block's locale tag is not a valid `LocaleTag` (e.g. `messages \"xx\"` where `xx` doesn't match the tag pattern).",
1039    ),
1040    d(
1041        "bynk.messages.malformed_icu_syntax",
1042        "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).",
1043    ),
1044    d(
1045        "bynk.messages.missing_locale_dependency",
1046        "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.",
1047    ),
1048    d(
1049        "bynk.messages.missing_reference",
1050        "A message bundle has no `@reference` block.",
1051    ),
1052    d(
1053        "bynk.messages.multiple_reference",
1054        "A message bundle has more than one `@reference` block.",
1055    ),
1056    d(
1057        "bynk.messages.outside_commons",
1058        "A `messages` declaration appears outside a commons.",
1059    ),
1060    d(
1061        "bynk.messages.placeholder_mismatch",
1062        "A locale's template for a code uses a different set of `{name}` placeholders than the reference locale's.",
1063    ),
1064    d(
1065        "bynk.namespace.reserved",
1066        "A user unit is named `bynk` or `bynk.*`; the `bynk` root is reserved for the toolchain.",
1067    ),
1068    d(
1069        "bynk.observe.impure_with",
1070        "A `with` predicate uses an effectful or test-only construct; it must be pure.",
1071    ),
1072    d(
1073        "bynk.observe.not_a_seam",
1074        "An observation targets a capability the unit under test does not consume.",
1075    ),
1076    d(
1077        "bynk.observe.trace_outside_test",
1078        "`trace(Cap.op)` appears outside a `case` body.",
1079    ),
1080    d(
1081        "bynk.observe.unknown_op",
1082        "An observation names an operation the capability does not declare.",
1083    ),
1084    d(
1085        "bynk.observe.with_not_bool",
1086        "A `with` predicate does not have type `Bool`.",
1087    ),
1088    dg(
1089        "bynk.parse.consumes_after_decls",
1090        "`consumes` appears after other declarations.",
1091        &["consumes_decl"],
1092    ),
1093    d(
1094        "bynk.parse.dangling_handler_annotation",
1095        "A handler-position annotation (e.g. `@cache`) is not followed by an `on` handler.",
1096    ),
1097    dg(
1098        "bynk.parse.duplicate_cors",
1099        "A service declares more than one `cors { }` policy.",
1100        &["service_decl"],
1101    ),
1102    dg(
1103        "bynk.parse.duplicate_limits",
1104        "A service declares more than one `limits { }` policy.",
1105        &["service_decl"],
1106    ),
1107    dg(
1108        "bynk.parse.duplicate_security",
1109        "A service declares more than one `security { }` policy.",
1110        &["service_decl"],
1111    ),
1112    dg(
1113        "bynk.parse.empty_agent",
1114        "An `agent` body is empty.",
1115        &["agent_decl"],
1116    ),
1117    dg(
1118        "bynk.parse.empty_capability",
1119        "A `capability` body is empty.",
1120        &["capability_decl"],
1121    ),
1122    d(
1123        "bynk.parse.empty_interpolation",
1124        "An interpolation hole `\\(…)` contains no expression.",
1125    ),
1126    dg(
1127        "bynk.parse.empty_match",
1128        "A `match` has no arms.",
1129        &["match_expr"],
1130    ),
1131    dg(
1132        "bynk.parse.empty_service",
1133        "A `service` body is empty.",
1134        &["service_decl"],
1135    ),
1136    d(
1137        "bynk.parse.event_pattern_empty",
1138        "A `from Events(E { ... })` subscription pattern listed no fields — use `from Events(E)` (no braces) for an unfiltered subscription.",
1139    ),
1140    dg(
1141        "bynk.parse.expected_agent_key",
1142        "Expected a `key` declaration in an agent.",
1143        &["agent_decl"],
1144    ),
1145    d(
1146        "bynk.parse.expected_agent_storage",
1147        "An agent declares no storage — it has no `store` fields.",
1148    ),
1149    dg(
1150        "bynk.parse.expected_base_type",
1151        "Expected a base type.",
1152        &["base_type"],
1153    ),
1154    dg(
1155        "bynk.parse.expected_capability_op",
1156        "Expected a capability operation.",
1157        &["capability_op"],
1158    ),
1159    d("bynk.parse.expected_expression", "Expected an expression."),
1160    dg(
1161        "bynk.parse.expected_handler",
1162        "Expected a handler.",
1163        &["handler"],
1164    ),
1165    d("bynk.parse.expected_item", "Expected a declaration."),
1166    dg(
1167        "bynk.parse.expected_predicate",
1168        "Expected a refinement predicate.",
1169        &["refinement"],
1170    ),
1171    dg(
1172        "bynk.parse.expected_provider_op",
1173        "Expected a provider operation.",
1174        &["provider_op"],
1175    ),
1176    d("bynk.parse.expected_token", "Expected a specific token."),
1177    d("bynk.parse.expected_type", "Expected a type."),
1178    d(
1179        "bynk.parse.expected_unit_header",
1180        "Expected a `commons` or `context` header.",
1181    ),
1182    dg(
1183        "bynk.parse.expected_visibility",
1184        "Expected a visibility keyword.",
1185        &["exports_decl"],
1186    ),
1187    dg(
1188        "bynk.parse.exports_after_decls",
1189        "`exports` appears after other declarations.",
1190        &["exports_decl"],
1191    ),
1192    d(
1193        "bynk.parse.extra_tokens",
1194        "Unexpected tokens after an otherwise complete construct.",
1195    ),
1196    dg(
1197        "bynk.parse.generic_arg_count",
1198        "Wrong number of generic type arguments.",
1199        &["generic_type_ref"],
1200    ),
1201    dg(
1202        "bynk.parse.handler_in_agent",
1203        "A protocol handler (`on GET`/`schedule`/`message`) was declared in an agent.",
1204        &["handler"],
1205    ),
1206    d(
1207        "bynk.parse.invariant_after_handler",
1208        "An `invariant` was declared after a handler; invariants precede handlers.",
1209    ),
1210    dg(
1211        "bynk.parse.malformed_float_literal",
1212        "A float literal is missing a digit on one side of the `.` (`1.`, `.5`).",
1213        &["float_literal"],
1214    ),
1215    d(
1216        "bynk.parse.nesting_too_deep",
1217        "An expression or type nests deeper than the parser's fixed limit.",
1218    ),
1219    dg(
1220        "bynk.parse.non_associative",
1221        "A non-associative operator was chained (e.g. `a == b == c`).",
1222        &["binary_expr"],
1223    ),
1224    warn(d(
1225        "bynk.parse.orphan_doc_block",
1226        "A documentation block is not attached to a declaration (warning).",
1227    )),
1228    dg(
1229        "bynk.parse.policy_order",
1230        "A service's `cors`/`security`/`limits` policy is out of order or follows a handler; they open the body in the order `cors`, `security`, `limits`.",
1231        &["service_decl"],
1232    ),
1233    dg(
1234        "bynk.parse.refined_pattern_inner",
1235        "A refined pattern's inner form is something other than `_`.",
1236        &["refined_pattern"],
1237    ),
1238    dg(
1239        "bynk.parse.reserved_keyword",
1240        "A reserved keyword was used as an identifier.",
1241        &["identifier"],
1242    ),
1243    dg(
1244        "bynk.parse.self_outside_method",
1245        "`self` used outside a method or handler.",
1246        &["self_expr"],
1247    ),
1248    d(
1249        "bynk.parse.storage_after_phase",
1250        "Agent storage (`state` / `store`) is declared after the invariants or handlers.",
1251    ),
1252    d(
1253        "bynk.parse.transition_after_handler",
1254        "A `transition` is declared after an agent handler; step invariants precede the handlers.",
1255    ),
1256    d(
1257        "bynk.parse.unexpected_adapter",
1258        "An `adapter` appeared where it is not allowed.",
1259    ),
1260    dg(
1261        "bynk.parse.unexpected_context",
1262        "A `context` appeared where it is not allowed.",
1263        &["context_decl"],
1264    ),
1265    d("bynk.parse.unexpected_eof", "Unexpected end of input."),
1266    dg(
1267        "bynk.parse.unexpected_suite",
1268        "A `suite` appeared where it is not allowed.",
1269        &["suite_decl"],
1270    ),
1271    d(
1272        "bynk.parse.unknown_effect_method",
1273        "An unknown method on `Effect`.",
1274    ),
1275    dg(
1276        "bynk.parse.unknown_handler_kind",
1277        "An unknown handler form (expected `call`, an HTTP method, `schedule`, or `message`).",
1278        &["handler"],
1279    ),
1280    dg(
1281        "bynk.parse.unknown_predicate",
1282        "An unknown refinement predicate.",
1283        &["predicate_name"],
1284    ),
1285    d(
1286        "bynk.parse.unknown_tier",
1287        "A `case`/`suite` `as <tier>` clause names something other than `unit`, `integration`, or `system`.",
1288    ),
1289    dg(
1290        "bynk.parse.uses_after_decls",
1291        "`uses` appears after other declarations.",
1292        &["uses_decl"],
1293    ),
1294    dg(
1295        "bynk.parse.variant_name_case",
1296        "A sum-type or enum variant name is not capitalised.",
1297        &["sum_variant", "enum_type"],
1298    ),
1299    d(
1300        "bynk.project.file_and_directory",
1301        "A unit exists as both a file and a directory.",
1302    ),
1303    d(
1304        "bynk.project.inconsistent_commons_name",
1305        "A source file's path does not match its declared name.",
1306    ),
1307    d(
1308        "bynk.project.kind_conflict",
1309        "A name is declared as both a commons and a context.",
1310    ),
1311    d(
1312        "bynk.project.no_root",
1313        "No project root could be determined.",
1314    ),
1315    d(
1316        "bynk.project.no_sources",
1317        "The project contains no source files.",
1318    ),
1319    d(
1320        "bynk.project.read_failed",
1321        "A source file could not be read.",
1322    ),
1323    d(
1324        "bynk.project.schema_registry_corrupt",
1325        "`bynk.schema.lock` (the events schema registry) is missing its version field, empty, truncated, or otherwise unparseable — restore it from version control rather than deleting it, since deleting it would silently re-baseline every event's history.",
1326    ),
1327    dg(
1328        "bynk.property.restates_refinement",
1329        "A `property` merely re-checks a refinement its type already guarantees.",
1330        &["for_all"],
1331    ),
1332    dg(
1333        "bynk.property.where_not_bool",
1334        "A `for all ... where` filter does not type to `Bool`.",
1335        &["for_all"],
1336    ),
1337    dg(
1338        "bynk.provider.dependency_cycle",
1339        "Providers form a capability dependency cycle through `given`.",
1340        &["provider_decl"],
1341    ),
1342    dg(
1343        "bynk.provider.extra_operation",
1344        "A `provides` block implements an operation not in the capability.",
1345        &["provider_decl"],
1346    ),
1347    dg(
1348        "bynk.provider.generic_op_requires_external",
1349        "A Bynk-bodied `provides` implements a capability operation that declares its own type parameter — only an external (bodiless) provider can.",
1350        &["provider_decl"],
1351    ),
1352    dg(
1353        "bynk.provider.missing_operation",
1354        "A `provides` block is missing a capability operation.",
1355        &["provider_decl"],
1356    ),
1357    dg(
1358        "bynk.provider.outside_context",
1359        "`provides` was declared outside a context.",
1360        &["provider_decl"],
1361    ),
1362    dg(
1363        "bynk.provider.signature_mismatch",
1364        "A `provides` operation's signature does not match the capability.",
1365        &["provider_decl"],
1366    ),
1367    dg(
1368        "bynk.provider.unknown_capability",
1369        "`provides` names a capability that does not exist.",
1370        &["provider_decl"],
1371    ),
1372    d(
1373        "bynk.query.join_key_mismatch",
1374        "A `joinOn`/`leftJoin` left and right key function return different types.",
1375    ),
1376    dg(
1377        "bynk.query.sum_needs_numeric",
1378        "A `sum`/`average` key function does not return a numeric type (`Int`, `Float`, or `Duration`).",
1379        &[],
1380    ),
1381    dg(
1382        "bynk.queue.bad_params",
1383        "An `on message` handler does not take exactly one `message` parameter.",
1384        &["queue_handler"],
1385    ),
1386    dg(
1387        "bynk.queue.duplicate_consumer",
1388        "Two `on message` handlers consume the same queue.",
1389        &["queue_handler"],
1390    ),
1391    dg(
1392        "bynk.queue.invalid_name",
1393        "A `from queue(\"…\")` binding has an empty queue name.",
1394        &["queue_handler"],
1395    ),
1396    dg(
1397        "bynk.queue.return_not_queue_result",
1398        "An `on message` handler does not return `Effect[QueueResult]`.",
1399        &["handler"],
1400    ),
1401    dg(
1402        "bynk.record_spread.field_type_mismatch",
1403        "A record-spread override has the wrong type for the field.",
1404        &["record_spread"],
1405    ),
1406    dg(
1407        "bynk.record_spread.non_record_base",
1408        "The base of a record spread is not a record.",
1409        &["record_spread"],
1410    ),
1411    dg(
1412        "bynk.record_spread.type_mismatch",
1413        "A record spread's base is a different record type.",
1414        &["record_spread"],
1415    ),
1416    dg(
1417        "bynk.record_spread.unknown_field",
1418        "A record spread overrides a field the record does not have.",
1419        &["record_spread"],
1420    ),
1421    dg(
1422        "bynk.refine.literal_violates",
1423        "A literal does not satisfy the refined type's predicate.",
1424        &["refined_type"],
1425    ),
1426    dg(
1427        "bynk.requires.unpinned_dependency",
1428        "An adapter `binding … requires { … }` entry has an unpinned version range.",
1429        &["binding_decl"],
1430    ),
1431    d(
1432        "bynk.resolve.ambiguous_variant",
1433        "A variant name is ambiguous across several sum types.",
1434    ),
1435    dg(
1436        "bynk.resolve.arity_mismatch",
1437        "A function was called with the wrong number of arguments.",
1438        &["call"],
1439    ),
1440    d("bynk.resolve.duplicate_actor", "Two actors share a name."),
1441    dg(
1442        "bynk.resolve.duplicate_agent",
1443        "Two agents share a name.",
1444        &["agent_decl"],
1445    ),
1446    dg(
1447        "bynk.resolve.duplicate_capability",
1448        "Two capabilities share a name.",
1449        &["capability_decl"],
1450    ),
1451    dg(
1452        "bynk.resolve.duplicate_field",
1453        "A record declares a field twice.",
1454        &["record_type"],
1455    ),
1456    dg(
1457        "bynk.resolve.duplicate_field_init",
1458        "A record construction initialises a field twice.",
1459        &["record_construction"],
1460    ),
1461    dg(
1462        "bynk.resolve.duplicate_fn",
1463        "Two functions share a name.",
1464        &["fn_decl"],
1465    ),
1466    d(
1467        "bynk.resolve.duplicate_message_code",
1468        "A message bundle declares the same code twice in one block.",
1469    ),
1470    d(
1471        "bynk.resolve.duplicate_message_locale",
1472        "Two `messages` blocks in one bundle declare the same locale tag.",
1473    ),
1474    dg(
1475        "bynk.resolve.duplicate_method",
1476        "Two methods share a name.",
1477        &["fn_decl"],
1478    ),
1479    dg(
1480        "bynk.resolve.duplicate_param",
1481        "A parameter name is repeated.",
1482        &["param"],
1483    ),
1484    dg(
1485        "bynk.resolve.duplicate_provider",
1486        "A capability is provided more than once.",
1487        &["provider_decl"],
1488    ),
1489    dg(
1490        "bynk.resolve.duplicate_service",
1491        "Two services share a name.",
1492        &["service_decl"],
1493    ),
1494    dg(
1495        "bynk.resolve.duplicate_type",
1496        "Two types share a name.",
1497        &["type_decl"],
1498    ),
1499    dg(
1500        "bynk.resolve.duplicate_variant",
1501        "A sum type declares a variant twice.",
1502        &["sum_type"],
1503    ),
1504    d(
1505        "bynk.resolve.fn_without_call",
1506        "A function was referenced without being called.",
1507    ),
1508    dg(
1509        "bynk.resolve.let_shadows_fn",
1510        "A `let` binding shadows a function.",
1511        &["let_stmt"],
1512    ),
1513    dg(
1514        "bynk.resolve.let_shadows_type",
1515        "A `let` binding shadows a type.",
1516        &["let_stmt"],
1517    ),
1518    d(
1519        "bynk.resolve.method_unknown_type",
1520        "A method is defined on an unknown type.",
1521    ),
1522    dg(
1523        "bynk.resolve.missing_field",
1524        "A record construction omits a required field.",
1525        &["record_construction"],
1526    ),
1527    d(
1528        "bynk.resolve.name_conflict",
1529        "Two declarations share a name.",
1530    ),
1531    dg(
1532        "bynk.resolve.not_a_record_type",
1533        "Record syntax was used on a non-record type.",
1534        &["record_construction"],
1535    ),
1536    dg(
1537        "bynk.resolve.opaque_record_construction",
1538        "An opaque type was constructed with record syntax.",
1539        &["record_construction"],
1540    ),
1541    dg(
1542        "bynk.resolve.param_as_function",
1543        "A value (such as a parameter) was called as a function.",
1544        &["call"],
1545    ),
1546    dg(
1547        "bynk.resolve.recursive_record_field",
1548        "A record directly contains a field of its own type.",
1549        &["record_type"],
1550    ),
1551    dg(
1552        "bynk.resolve.reserved_builtin_type",
1553        "A type declaration reuses a compiler-known built-in type name.",
1554        &["type_decl"],
1555    ),
1556    dg(
1557        "bynk.resolve.reserved_host_name",
1558        "A declaration is named `globalThis`, which the generated TypeScript uses to reach host globals.",
1559        &["type_decl", "fn_decl", "agent_decl", "provider_decl"],
1560    ),
1561    dg(
1562        "bynk.resolve.reserved_payload_field",
1563        "A sum variant declares a payload field named `kind`, the variant's wire discriminant.",
1564        &["sum_type"],
1565    ),
1566    dg(
1567        "bynk.resolve.self_outside_method",
1568        "`self` referenced outside a method or handler.",
1569        &["self_expr"],
1570    ),
1571    dg(
1572        "bynk.resolve.type_as_function",
1573        "A type name was called as if it were a function.",
1574        &["call"],
1575    ),
1576    d(
1577        "bynk.resolve.type_in_expr",
1578        "A type name was used where a value is expected.",
1579    ),
1580    dg(
1581        "bynk.resolve.unconsumed_context",
1582        "A context's service was called without a `consumes` declaration.",
1583        &["consumes_decl"],
1584    ),
1585    dg(
1586        "bynk.resolve.unknown_field",
1587        "Accessed a field the record does not have.",
1588        &["field_access"],
1589    ),
1590    dg(
1591        "bynk.resolve.unknown_function",
1592        "Called a function that does not exist.",
1593        &["call"],
1594    ),
1595    d(
1596        "bynk.resolve.unknown_name",
1597        "Referenced a name that is not in scope.",
1598    ),
1599    dg(
1600        "bynk.resolve.unknown_static_member",
1601        "Referenced an unknown static member (e.g. `T.x`).",
1602        &["field_access"],
1603    ),
1604    d(
1605        "bynk.resolve.unknown_type",
1606        "Referenced a type that does not exist.",
1607    ),
1608    warn(d(
1609        "bynk.secrets.computed_name",
1610        "A `bynk.Secrets` read names its secret with a computed expression rather than a literal, so `bynk deploy` cannot plan it (warning).",
1611    )),
1612    dg(
1613        "bynk.send.in_pure_context",
1614        "A `~>` send was used in a pure (non-effectful) context.",
1615        &["effect_send_stmt"],
1616    ),
1617    dg(
1618        "bynk.send.non_effect",
1619        "A `~>` send was applied to a non-`Effect` value.",
1620        &["effect_send_stmt"],
1621    ),
1622    dg(
1623        "bynk.send.requires_unit",
1624        "A `~>` send targets an operation whose reply is not `Effect[()]`.",
1625        &["effect_send_stmt"],
1626    ),
1627    dg(
1628        "bynk.service.missing_from",
1629        "A `from`-less service has a handler other than `on call`.",
1630        &["service_decl"],
1631    ),
1632    dg(
1633        "bynk.service.mixed_protocols",
1634        "A service mixes handler forms that do not match its `from <protocol>`.",
1635        &["service_decl"],
1636    ),
1637    dg(
1638        "bynk.service.outside_context",
1639        "A `service` was declared outside a context.",
1640        &["service_decl"],
1641    ),
1642    dg(
1643        "bynk.service.return_not_effect",
1644        "A service handler's return type is not an `Effect`.",
1645        &["service_decl"],
1646    ),
1647    dg(
1648        "bynk.service.unknown_protocol",
1649        "A `from <protocol>` names an unknown protocol (e.g. a transport like Kafka).",
1650        &["service_decl"],
1651    ),
1652    d(
1653        "bynk.service.unknown_via_clause",
1654        "A `via <name>(...)` clause on a `from Events(...)` header named something other than `schema` — `via` clauses are a closed set, and only `via schema(...)` exists today.",
1655    ),
1656    d(
1657        "bynk.service.websocket_header",
1658        "The `from websocket` header is malformed — it binds frame types as `websocket(in: <type>, out: <type>)` (real-time track slice 3).",
1659    ),
1660    d(
1661        "bynk.service.websocket_multiple",
1662        "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).",
1663    ),
1664    d(
1665        "bynk.service.websocket_open_arity",
1666        "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).",
1667    ),
1668    d(
1669        "bynk.service.websocket_param_not_stringy",
1670        "A `from websocket` service's `on open` parameter has a type not constructible from `String`; it arrives as a query-string value (#1657).",
1671    ),
1672    d(
1673        "bynk.store.annotation_kind_mismatch",
1674        "A storage annotation is used on a kind it does not apply to (e.g. `@ttl` on a `Map`).",
1675    ),
1676    d(
1677        "bynk.store.annotation_unsupported",
1678        "A known storage annotation (`@ttl`/`@retain`/`@indexed`/`@bounded`) is used before the slice that supports it.",
1679    ),
1680    d(
1681        "bynk.store.cache_needs_clock",
1682        "A handler performs a `Cache` operation (TTL expiry reads the clock) without declaring `given Clock`.",
1683    ),
1684    d(
1685        "bynk.store.cache_ttl_required",
1686        "A `Cache` field is missing its required `@ttl(<duration>)` annotation (a keyed store with no expiry is a `Map`).",
1687    ),
1688    d(
1689        "bynk.store.kind_arity",
1690        "A storage kind was applied to the wrong number of type arguments (e.g. `Cell[A, B]`).",
1691    ),
1692    d(
1693        "bynk.store.kind_unsupported",
1694        "A known storage kind (`Queue`) is used before the slice that supports it.",
1695    ),
1696    d(
1697        "bynk.store.log_needs_clock",
1698        "A handler calls `Log.append` (which stamps the current time) without declaring `given Clock`.",
1699    ),
1700    d(
1701        "bynk.store.unkeyable_key",
1702        "A store `Set` element or `Map`/`Cache` key is not value-keyable — it must be `String`, `Int`, or a refined/opaque type over them (#1680).",
1703    ),
1704    d(
1705        "bynk.store.unknown_annotation",
1706        "A `store` field carries an annotation outside the closed `@indexed`/`@ttl`/`@retain`/`@bounded` set.",
1707    ),
1708    d(
1709        "bynk.store.unknown_kind",
1710        "A `store` field's type is not a known storage kind.",
1711    ),
1712    d(
1713        "bynk.store.unknown_map_accessor",
1714        "A `store Map` field access is not one of its query accessors (`entries`/`keys`/`values`).",
1715    ),
1716    d(
1717        "bynk.store.unknown_op",
1718        "A storage-`Map`/`Set` operation is not a recognised entry/membership method.",
1719    ),
1720    d(
1721        "bynk.stub.bad_sequence",
1722        "A `stub … returns each […]` sequence is malformed (e.g. empty).",
1723    ),
1724    d(
1725        "bynk.stub.generic_op",
1726        "A test `stub` targets a capability operation that declares its own type parameter — not supported at v1.",
1727    ),
1728    d(
1729        "bynk.stub.not_a_seam",
1730        "A test `stub` overrides a capability the unit under test does not consume.",
1731    ),
1732    d(
1733        "bynk.stub.rhs_type",
1734        "A test `stub … returns <value>` right-hand side does not match the operation's return type.",
1735    ),
1736    d(
1737        "bynk.stub.unknown_op",
1738        "A test `stub` names an operation the capability does not declare.",
1739    ),
1740    dg(
1741        "bynk.suite.duplicate_case_name",
1742        "Two `case`s share a description.",
1743        &["case"],
1744    ),
1745    dg(
1746        "bynk.suite.unknown_target",
1747        "A `suite` targets a unit that does not exist.",
1748        &["suite_decl"],
1749    ),
1750    d(
1751        "bynk.target.browser_bundle_only",
1752        "The `browser` platform builds only the in-process `Bundle` topology; `--target workers` is not a browser build.",
1753    ),
1754    dg(
1755        "bynk.target.vendor_conflict",
1756        "One deployment unit's in-process closure uses platform-native capabilities from two mutually-exclusive platforms.",
1757        &["consumes_decl"],
1758    ),
1759    dg(
1760        "bynk.target.vendor_required",
1761        "A deployment unit uses a platform-native capability but the build selects another `--platform`.",
1762        &["consumes_decl"],
1763    ),
1764    dg(
1765        "bynk.test.actor_identity_required",
1766        "A call-site `by <Actor>` omits the identity an identity-carrying actor requires.",
1767        &["case"],
1768    ),
1769    dg(
1770        "bynk.test.actor_no_identity",
1771        "A call-site `by <Actor>(x)` supplies an identity to an actor that takes none — a unit-identity actor (e.g. `Visitor`) or `Nobody`.",
1772        &["case"],
1773    ),
1774    dg(
1775        "bynk.test.credential_needs_system",
1776        "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.",
1777        &["case"],
1778    ),
1779    dg(
1780        "bynk.test.faults_needs_in_process",
1781        "A `system`-tier case claims a fault with `expect <call> faults`; at `system` a fault reaches the case as an error response from the deployed Worker, never a throw, so the claim belongs at `unit` or `integration`.",
1782        &["case"],
1783    ),
1784    dg(
1785        "bynk.test.nobody_needs_secured_route",
1786        "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.",
1787        &["case"],
1788    ),
1789    dg(
1790        "bynk.test.principal_identity_mismatch",
1791        "A call-site `by <Actor>` acts as an actor whose identity is incompatible with the addressed handler's actor.",
1792        &["case"],
1793    ),
1794    dg(
1795        "bynk.test.principal_on_wrong_method",
1796        "A wrong-method `405` test carries a `by <Actor>` clause; it reaches no handler, so a principal is meaningless.",
1797        &["case"],
1798    ),
1799    dg(
1800        "bynk.test.principal_required",
1801        "A test drives an identity-carrying handler with no call-site `by <Actor>(<identity>)`.",
1802        &["case"],
1803    ),
1804    dg(
1805        "bynk.test.service_bad_address",
1806        "A test body addresses a service the wrong way for its protocol (e.g. an http route without a leading path string).",
1807        &["case"],
1808    ),
1809    dg(
1810        "bynk.test.service_call_arity",
1811        "A test body's `svc.call(...)` passes the wrong number of arguments for the service's `on call` handler.",
1812        &["case"],
1813    ),
1814    dg(
1815        "bynk.test.service_no_call_handler",
1816        "A test body invokes `svc.call(...)` on a service with no `on call` handler (a `from http`/`cron`/`queue` service).",
1817        &["case"],
1818    ),
1819    dg(
1820        "bynk.test.service_unknown_route",
1821        "A test body addresses an http route / cron schedule / queue message the service does not declare.",
1822        &["case"],
1823    ),
1824    dg(
1825        "bynk.test.unknown_actor",
1826        "A call-site `by <Actor>` names an actor the target context does not declare and that is not a prelude actor.",
1827        &["case"],
1828    ),
1829    dg(
1830        "bynk.test.wire_needs_system",
1831        "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.",
1832        &["case"],
1833    ),
1834    dg(
1835        "bynk.tier.cross_context_needs_system",
1836        "A `unit` or `integration` case, or a `property`, reaches another context's service, directly or through a target service or agent handler that calls one; below `system` no other context is stood up to call, so the flow belongs in a `suite … as system`.",
1837        &["case"],
1838    ),
1839    dg(
1840        "bynk.tier.mixed_system_suite",
1841        "A suite mixes `system` cases with `unit` or `integration` ones; a `system` case runs against deployed Workers and addresses services by context path, so it needs a `suite … as system` of its own.",
1842        &["case"],
1843    ),
1844    d(
1845        "bynk.tier.system_needs_wire",
1846        "An `as system` test stands up fewer than two contexts; the system tier wires across contexts.",
1847    ),
1848    d(
1849        "bynk.transition.cross_agent_reference",
1850        "A transition predicate references another agent; step invariants are per-agent.",
1851    ),
1852    d(
1853        "bynk.transition.duplicate_name",
1854        "An agent declares two transitions with the same name.",
1855    ),
1856    d(
1857        "bynk.transition.impure_predicate",
1858        "A transition predicate uses an effectful or test-only construct; a step invariant must be pure.",
1859    ),
1860    d(
1861        "bynk.transition.no_step_reference",
1862        "A transition references neither `old` nor `new`; it constrains one state, so it is an `invariant`, not a step.",
1863    ),
1864    d(
1865        "bynk.transition.not_bool",
1866        "A transition predicate does not have type `Bool`.",
1867    ),
1868    dg(
1869        "bynk.types.argument_mismatch",
1870        "A call, method, capability, or constructor argument has the wrong type.",
1871        &["call"],
1872    ),
1873    dg(
1874        "bynk.types.call_arity",
1875        "A function value was applied with the wrong number of arguments.",
1876        &["call"],
1877    ),
1878    dg(
1879        "bynk.types.cannot_infer_option_type_param",
1880        "The value type of `None` could not be inferred.",
1881        &["none_expr"],
1882    ),
1883    d(
1884        "bynk.types.cannot_infer_result_type_params",
1885        "The type parameters of a `Result` could not be inferred.",
1886    ),
1887    dg(
1888        "bynk.types.catastrophic_regex",
1889        "A `Matches` pattern can match the same text in exponentially many ways (nested or ambiguous repetition, bounded or not), or cannot be analysed, risking catastrophic backtracking (ReDoS).",
1890        &["refinement"],
1891    ),
1892    dg(
1893        "bynk.types.combinator_return_mismatch",
1894        "A callback passed to a combinator (`map`/`andThen`/`flatMap`/`traverseAll`/…) returns the wrong type.",
1895        &["call"],
1896    ),
1897    d(
1898        "bynk.types.constructor_arity",
1899        "A variant constructor got the wrong number of arguments.",
1900    ),
1901    d(
1902        "bynk.types.constructor_base_mismatch",
1903        "A `.of` constructor was given an argument of the wrong base type.",
1904    ),
1905    dg(
1906        "bynk.types.duplicate_literal_arm",
1907        "A `match` has two arms for the same literal value.",
1908        &["match_arm"],
1909    ),
1910    dg(
1911        "bynk.types.duplicate_variant_arm",
1912        "A `match` has two arms for the same variant.",
1913        &["match_arm"],
1914    ),
1915    d(
1916        "bynk.types.embeds_ambiguous",
1917        "A type is embedded by more than one variant of a sum, so `?`'s conversion would be ambiguous.",
1918    ),
1919    d(
1920        "bynk.types.embeds_unknown_variant",
1921        "An `embeds … as V` clause names a variant the sum does not declare.",
1922    ),
1923    d(
1924        "bynk.types.embeds_variant_shape",
1925        "An `embeds E as V` target variant must have exactly one payload field, of type `E`.",
1926    ),
1927    dg(
1928        "bynk.types.empty_refinement",
1929        "A refinement admits no values (contradictory predicates).",
1930        &["refinement"],
1931    ),
1932    dg(
1933        "bynk.types.err_value_mismatch",
1934        "An `Err` payload has the wrong type.",
1935        &["err_expr"],
1936    ),
1937    dg(
1938        "bynk.types.field_access_on_non_record",
1939        "Field access on a value that is not a record.",
1940        &["field_access"],
1941    ),
1942    dg(
1943        "bynk.types.field_refinement_not_base",
1944        "An inline field refinement requires a base or refined type.",
1945        &["record_field"],
1946    ),
1947    dg(
1948        "bynk.types.field_value_mismatch",
1949        "A record field was given a value of the wrong type.",
1950        &["record_construction"],
1951    ),
1952    dg(
1953        "bynk.types.function_at_boundary",
1954        "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.",
1955        &["function_type_ref"],
1956    ),
1957    dg(
1958        "bynk.types.guard_not_bool",
1959        "A match-arm `if` guard is not a `Bool` expression.",
1960        &["match_arm"],
1961    ),
1962    d(
1963        "bynk.types.held_at_boundary",
1964        "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).",
1965    ),
1966    d(
1967        "bynk.types.held_not_comparable",
1968        "A held value (`Connection[F]`) is compared with `==`/`!=` — held values have identity, not value-equality (§2.9.3, real-time track slice 2).",
1969    ),
1970    dg(
1971        "bynk.types.if_branch_mismatch",
1972        "The branches of an `if` have different types.",
1973        &["if_expr"],
1974    ),
1975    dg(
1976        "bynk.types.if_non_bool_cond",
1977        "An `if` condition is not a `Bool`.",
1978        &["if_expr"],
1979    ),
1980    dg(
1981        "bynk.types.if_without_else_requires_unit",
1982        "An `if` with no `else` branch has a non-unit then-branch; the missing else defaults to `()`, so the branch must be `()` or `Effect[()]`.",
1983        &["if_expr"],
1984    ),
1985    d(
1986        "bynk.types.interpolation_non_scalar",
1987        "An interpolation hole holds a value with no string form.",
1988    ),
1989    dg(
1990        "bynk.types.invalid_regex",
1991        "A `Matches` predicate contains an invalid regular expression.",
1992        &["refinement"],
1993    ),
1994    dg(
1995        "bynk.types.inverted_range",
1996        "An `InRange` predicate has its bounds inverted.",
1997        &["refinement"],
1998    ),
1999    dg(
2000        "bynk.types.is_base_mismatch",
2001        "An `is` refinement check is applied to a value of the wrong base type.",
2002        &["is_expr"],
2003    ),
2004    dg(
2005        "bynk.types.is_literal_pattern",
2006        "A literal was used on the right of `is`; `is` tests type/refinement, not value equality (use `==`).",
2007        &["is_expr"],
2008    ),
2009    dg(
2010        "bynk.types.is_non_sum",
2011        "`is` was applied to a value that is not a sum type.",
2012        &["is_expr"],
2013    ),
2014    dg(
2015        "bynk.types.is_refined_pattern",
2016        "A refined (`where`) pattern was used on the right of `is`; refined patterns are `match`-only.",
2017        &["is_expr"],
2018    ),
2019    dg(
2020        "bynk.types.is_unknown_variant",
2021        "`is` names a variant the type does not have.",
2022        &["is_expr"],
2023    ),
2024    dg(
2025        "bynk.types.json_uncodable",
2026        "A `Json.encode`/`Json.decode` target type cannot pass through the typed JSON codec (functions, effects, error builtins).",
2027        &["method_call"],
2028    ),
2029    dg(
2030        "bynk.types.key_not_orderable",
2031        "A `sortBy`/`min`/`max` key function does not return an orderable type (`Int`, `Float`, `String`, `Duration`, or `Instant`).",
2032        &[],
2033    ),
2034    dg(
2035        "bynk.types.lambda_mismatch",
2036        "A lambda's parameter count, parameter annotations, or body type do not match the expected function type.",
2037        &["lambda_expr"],
2038    ),
2039    dg(
2040        "bynk.types.let_annotation_mismatch",
2041        "A `let` value does not match its type annotation.",
2042        &["let_stmt"],
2043    ),
2044    dg(
2045        "bynk.types.list_element_mismatch",
2046        "A list-literal element has a different type from the list's element type.",
2047        &["list_literal"],
2048    ),
2049    dg(
2050        "bynk.types.match_arm_mismatch",
2051        "A `match` arm has a different type from the others.",
2052        &["match_arm"],
2053    ),
2054    dg(
2055        "bynk.types.match_non_sum_discriminant",
2056        "`match` was applied to a value that is not a sum type.",
2057        &["match_expr"],
2058    ),
2059    dg(
2060        "bynk.types.method_arity",
2061        "A method was called with the wrong number of arguments.",
2062        &["method_call"],
2063    ),
2064    dg(
2065        "bynk.types.method_not_found",
2066        "Called a method the type does not have.",
2067        &["method_call"],
2068    ),
2069    dg(
2070        "bynk.types.method_on_non_named_type",
2071        "A method was called on a built-in type that has no methods.",
2072        &["method_call"],
2073    ),
2074    dg(
2075        "bynk.types.mixed_pattern_bindings",
2076        "A pattern mixes named and positional bindings.",
2077        &["variant_pattern"],
2078    ),
2079    dg(
2080        "bynk.types.negative_length",
2081        "A length predicate was given a negative value.",
2082        &["refinement"],
2083    ),
2084    dg(
2085        "bynk.types.no_numeric_coercion",
2086        "`Int` and `Float` were mixed without an explicit conversion — in an operation or in refinement bounds.",
2087        &["binary_expr", "refinement"],
2088    ),
2089    dg(
2090        "bynk.types.non_exhaustive_match",
2091        "A `match` does not cover every variant.",
2092        &["match_expr"],
2093    ),
2094    d(
2095        "bynk.types.not_comparable",
2096        "A value compared with `==`/`!=` contains a function, `Effect`, or `Query` somewhere inside it — those have no value equality, so the type is not equality-supporting (type-system §2.3.5, #1652).",
2097    ),
2098    dg(
2099        "bynk.types.ok_value_mismatch",
2100        "An `Ok` payload has the wrong type.",
2101        &["ok_expr"],
2102    ),
2103    dg(
2104        "bynk.types.opaque_raw_outside",
2105        "`.raw` on an opaque type was used outside its defining commons.",
2106        &["field_access"],
2107    ),
2108    dg(
2109        "bynk.types.opaque_unsafe_outside",
2110        "`.unsafe` on an opaque type was used outside its defining context.",
2111        &["field_access"],
2112    ),
2113    dg(
2114        "bynk.types.or_pattern_binding_mismatch",
2115        "An or-pattern's alternatives don't all bind the same set of names.",
2116        &["match_arm", "is_expr"],
2117    ),
2118    dg(
2119        "bynk.types.or_pattern_type_mismatch",
2120        "An or-pattern's alternatives give a shared binding different types (or refinements).",
2121        &["match_arm", "is_expr"],
2122    ),
2123    dg(
2124        "bynk.types.pattern_arity",
2125        "A pattern binds the wrong number of payload fields.",
2126        &["variant_pattern"],
2127    ),
2128    dg(
2129        "bynk.types.pattern_type_mismatch",
2130        "A pattern's type does not match the matched value.",
2131        &["variant_pattern"],
2132    ),
2133    dg(
2134        "bynk.types.polynomial_regex",
2135        "A `Matches` pattern can split the same text between repetitions, so matching time grows polynomially with input length, and no length predicate bounds the input small enough for its degree.",
2136        &["refinement"],
2137    ),
2138    warn(dg(
2139        "bynk.types.polynomial_regex_capped",
2140        "A `Matches` pattern's matching time grows polynomially with input length, but a `MaxLength` or `Length` predicate bounds the input small enough for its degree (warning).",
2141        &["refinement"],
2142    )),
2143    dg(
2144        "bynk.types.predicate_base_mismatch",
2145        "A predicate does not apply to the type's base (e.g. a string predicate on an `Int`).",
2146        &["refinement"],
2147    ),
2148    d(
2149        "bynk.types.query_at_boundary",
2150        "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).",
2151    ),
2152    dg(
2153        "bynk.types.question_error_mismatch",
2154        "`?` propagates an error type incompatible with the function's.",
2155        &["question_expr"],
2156    ),
2157    dg(
2158        "bynk.types.question_on_non_result",
2159        "`?` was applied to a non-`Result` value.",
2160        &["question_expr"],
2161    ),
2162    dg(
2163        "bynk.types.question_option_outside_http",
2164        "`?` lifts an `Option` only inside a handler returning `HttpResult` (`None` becomes `NotFound`); elsewhere use `.okOr(err)`.",
2165        &["question_expr"],
2166    ),
2167    dg(
2168        "bynk.types.question_outside_result",
2169        "`?` used in a function that does not return a `Result`.",
2170        &["question_expr"],
2171    ),
2172    d(
2173        "bynk.types.return_mismatch",
2174        "A returned value does not match the declared return type.",
2175    ),
2176    dg(
2177        "bynk.types.some_value_mismatch",
2178        "A `Some` payload has the wrong type.",
2179        &["some_expr"],
2180    ),
2181    d(
2182        "bynk.types.stream_at_boundary",
2183        "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).",
2184    ),
2185    d(
2186        "bynk.types.stream_not_comparable",
2187        "A `Stream` value is compared with `==`/`!=` — a stream is a live value-over-time source, not a comparable value (real-time track slice 0).",
2188    ),
2189    d(
2190        "bynk.types.type_mismatch",
2191        "Two types that were required to match did not.",
2192    ),
2193    dg(
2194        "bynk.types.uninferable_element_type",
2195        "An empty `[]` (or `List.empty()` / `Map.empty()`) has no expected type to infer its element type from.",
2196        &["list_literal"],
2197    ),
2198    dg(
2199        "bynk.types.unkeyable_distinct",
2200        "A `distinct`/`distinctBy` element or key is not value-keyable (`String`, `Int`, or a refined/opaque type over them).",
2201        &[],
2202    ),
2203    dg(
2204        "bynk.types.unkeyable_map_key",
2205        "A `Map` key type is not value-keyable (`String`, `Int`, or a refined/opaque type over them).",
2206        &["generic_type_ref"],
2207    ),
2208    dg(
2209        "bynk.types.unknown_field",
2210        "Referenced a field the record type does not declare.",
2211        &["field_access"],
2212    ),
2213    dg(
2214        "bynk.types.unknown_pattern_field",
2215        "A pattern names a field the variant does not have.",
2216        &["variant_pattern"],
2217    ),
2218    dg(
2219        "bynk.types.unknown_static_member",
2220        "Referenced an unknown static member on a type.",
2221        &["field_access"],
2222    ),
2223    dg(
2224        "bynk.types.unknown_variant_in_pattern",
2225        "A pattern names a variant the sum type does not have.",
2226        &["variant_pattern"],
2227    ),
2228    dg(
2229        "bynk.types.unreachable_arm",
2230        "A `match` arm is unreachable.",
2231        &["match_arm"],
2232    ),
2233    d(
2234        "bynk.types.variant_arity",
2235        "A variant constructor got the wrong number of payload values.",
2236    ),
2237    d(
2238        "bynk.types.variant_missing_payload",
2239        "A variant requiring a payload was used without one.",
2240    ),
2241    d(
2242        "bynk.types.variant_payload_mismatch",
2243        "A variant payload has the wrong type.",
2244    ),
2245    dg(
2246        "bynk.uses.name_conflict",
2247        "A `uses` name collides with another name.",
2248        &["uses_decl"],
2249    ),
2250    dg(
2251        "bynk.uses.self_reference",
2252        "A commons `uses` itself.",
2253        &["uses_decl"],
2254    ),
2255    dg(
2256        "bynk.uses.target_is_context",
2257        "`uses` targets a context instead of a commons.",
2258        &["uses_decl"],
2259    ),
2260    dg(
2261        "bynk.uses.unknown_commons",
2262        "`uses` names a commons that does not exist.",
2263        &["uses_decl"],
2264    ),
2265    dg(
2266        "bynk.val.agent_not_generable",
2267        "A `for all`/`Val` cannot generate an agent — fabricated agent states need not be reachable.",
2268        &["for_all"],
2269    ),
2270    dg(
2271        "bynk.val.arity",
2272        "`Val[T]` was given the wrong number of pin arguments.",
2273        &["val_expr"],
2274    ),
2275    dg(
2276        "bynk.val.literal_violates",
2277        "A pinned `Val[T]` value violates the type's refinement.",
2278        &["val_expr"],
2279    ),
2280    dg(
2281        "bynk.val.needs_pin",
2282        "A bare `Val[T]` cannot generate a value (e.g. a `Matches` string); pin one.",
2283        &["val_expr"],
2284    ),
2285    dg(
2286        "bynk.val.outside_test",
2287        "`Val[T]` was used outside a test case body.",
2288        &["val_expr"],
2289    ),
2290    dg(
2291        "bynk.val.pin_not_literal",
2292        "A `Val[T]` pin argument is not a compile-time literal.",
2293        &["val_expr"],
2294    ),
2295    dg(
2296        "bynk.val.pin_unsupported",
2297        "A pin was given for a type kind that does not support pinning.",
2298        &["val_expr"],
2299    ),
2300    dg(
2301        "bynk.val.unknown_type",
2302        "`Val[T]` names a type that does not resolve.",
2303        &["val_expr"],
2304    ),
2305    dg(
2306        "bynk.val.unsupported_kind",
2307        "`Val[T]` cannot fabricate a value for this kind of type.",
2308        &["val_expr"],
2309    ),
2310    d(
2311        "bynk.wasm.panic",
2312        "The in-browser compiler panicked internally (a compiler bug, reported as a diagnostic instead of crashing the page).",
2313    ),
2314    d(
2315        "bynk.wasm.strip_failed",
2316        "The in-browser compiler could not strip the emitted TypeScript to JavaScript.",
2317    ),
2318    d(
2319        "bynk.ws.message_frame_param",
2320        "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).",
2321    ),
2322    d(
2323        "bynk.ws.open_given_unsupported",
2324        "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).",
2325    ),
2326    d(
2327        "bynk.ws.open_transfer_shape",
2328        "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).",
2329    ),
2330    d(
2331        "bynk.ws.route_param_mismatch",
2332        "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).",
2333    ),
2334];
2335
2336/// A diagnostic with no single governing grammar construct. `Error` severity.
2337const fn d(code: &'static str, summary: &'static str) -> DiagnosticInfo {
2338    DiagnosticInfo {
2339        code,
2340        summary,
2341        grammar_symbol: &[],
2342        severity: Severity::Error,
2343    }
2344}
2345
2346/// A diagnostic that constrains one or more grammar productions. `Error` severity.
2347const fn dg(
2348    code: &'static str,
2349    summary: &'static str,
2350    grammar_symbol: &'static [&'static str],
2351) -> DiagnosticInfo {
2352    DiagnosticInfo {
2353        code,
2354        summary,
2355        grammar_symbol,
2356        severity: Severity::Error,
2357    }
2358}
2359
2360/// Downgrades a [`d`]/[`dg`]-built entry to `Warning` severity (ADR 0117) —
2361/// non-failing, surfaced alongside a clean build. The seven call sites here are
2362/// the single source of truth [`crate::error::Severity::for_error`] reads.
2363const fn warn(mut info: DiagnosticInfo) -> DiagnosticInfo {
2364    info.severity = Severity::Warning;
2365    info
2366}
2367
2368/// The category segment of a code (the part between the first two dots), e.g.
2369/// `"types"` for `"bynk.types.type_mismatch"`.
2370pub fn category(code: &str) -> &str {
2371    code.split('.').nth(1).unwrap_or("")
2372}
2373
2374/// A human-readable heading for a category segment.
2375fn category_title(cat: &str) -> &'static str {
2376    match cat {
2377        "agent" | "agents" => "Agents",
2378        "boundary" => "Boundaries",
2379        "capability" => "Capabilities",
2380        "consumes" => "Consumes",
2381        "context" => "Contexts",
2382        "contract" => "Contracts",
2383        "cron" => "Cron",
2384        "effect" => "Effects",
2385        "expect" => "Expectations",
2386        "exports" => "Exports",
2387        "given" => "Given capabilities",
2388        "http" => "HTTP",
2389        "lex" => "Lexer",
2390        "messages" => "Message bundles",
2391        "mock" => "Mocks (collaborators)",
2392        "observe" => "Observation",
2393        "parse" => "Parser",
2394        "project" => "Project",
2395        "property" => "Properties (generative tests)",
2396        "provider" => "Providers",
2397        "queue" => "Queue",
2398        "record_spread" => "Record spread",
2399        "refine" => "Refinement",
2400        "resolve" => "Resolution",
2401        "service" => "Services",
2402        "suite" => "Suites and cases",
2403        "transition" => "Transitions (step invariants)",
2404        "types" => "Type checking",
2405        "uses" => "Uses",
2406        "val" => "Value fabrication",
2407        _ => "Other",
2408    }
2409}
2410
2411/// Render the diagnostic index as a Markdown reference page, grouped by
2412/// category. This is the generator behind
2413/// `site/src/content/docs/book/reference/diagnostics.md`.
2414pub fn render_markdown() -> String {
2415    use std::collections::BTreeMap;
2416
2417    // Group codes by their category title, preserving sorted code order.
2418    let mut by_category: BTreeMap<&str, Vec<&DiagnosticInfo>> = BTreeMap::new();
2419    for info in REGISTRY {
2420        by_category
2421            .entry(category_title(category(info.code)))
2422            .or_default()
2423            .push(info);
2424    }
2425
2426    let mut out = String::new();
2427    out.push_str("# Diagnostic index\n\n");
2428    out.push_str(
2429        "<!-- GENERATED FILE — do not edit by hand.\n     \
2430         Source: bynkc/src/diagnostics.rs (`render_markdown`).\n     \
2431         Regenerate with: BYNK_BLESS=1 cargo test -p bynkc --test diagnostics_registry -->\n\n",
2432    );
2433    out.push_str(
2434        "Every diagnostic code the compiler can emit, with a one-line summary of \
2435         the cause, grouped by category. For step-by-step cause-and-fix guidance \
2436         on the most common ones, see the [troubleshooting guides](../troubleshooting/index.md).\n\n",
2437    );
2438    out.push_str(&format!(
2439        "There are **{}** codes in total.\n",
2440        REGISTRY.len()
2441    ));
2442
2443    for (title, infos) in &by_category {
2444        out.push_str(&format!("\n## {title}\n\n"));
2445        out.push_str("| Code | Summary | Construct | Severity |\n|---|---|---|---|\n");
2446        for info in infos {
2447            // The construct column deep-links each governing production to its
2448            // entry in the annotated grammar reference; generated from
2449            // `grammar_symbol` (each value is an embeddable rule, so the
2450            // `#rule-<raw>` anchor resolves — enforced in diagnostics_registry).
2451            let construct = info
2452                .grammar_symbol
2453                .iter()
2454                .map(|sym| format!("[`{sym}`](grammar.md#rule-{sym})"))
2455                .collect::<Vec<_>>()
2456                .join(", ");
2457            // A curated (`bynk explain`-able) code links to its Book concept
2458            // page; the in-site link is validated by the site's link checker,
2459            // so a moved page or renamed anchor fails the build (#853). Codes
2460            // without an explanation render as plain inline code.
2461            let code_cell = match explain(info.code) {
2462                Some(e) => format!("[`{}`]({})", info.code, e.in_site_link()),
2463                None => format!("`{}`", info.code),
2464            };
2465            // ADR 0117/finding #50: every code's severity, straight from the
2466            // registry — `Error` (the overwhelming majority) renders as "—"
2467            // to keep the common case unobtrusive; only a `warn`-built entry
2468            // shows "Warning".
2469            let severity = match info.severity {
2470                Severity::Error => "—",
2471                Severity::Warning => "Warning",
2472            };
2473            out.push_str(&format!(
2474                "| {} | {} | {} | {} |\n",
2475                code_cell, info.summary, construct, severity
2476            ));
2477        }
2478    }
2479
2480    out
2481}
2482
2483/// Invert the registry into a `{ "<rule>": [ { code, summary }, … ], … }` map,
2484/// serialised as pretty JSON with sorted keys and sorted codes. Only rules with
2485/// at least one diagnostic appear. This is the generator behind
2486/// `docs/grammar-semantics.json`, which the `{{#grammar-semantics <rule>}}`
2487/// preprocessor directive consumes.
2488pub fn render_grammar_semantics_json() -> String {
2489    use std::collections::BTreeMap;
2490
2491    // REGISTRY is sorted by code, so each rule's vector comes out code-sorted;
2492    // the BTreeMap gives sorted rule names.
2493    let mut by_symbol: BTreeMap<&str, Vec<&DiagnosticInfo>> = BTreeMap::new();
2494    for info in REGISTRY {
2495        for sym in info.grammar_symbol {
2496            by_symbol.entry(sym).or_default().push(info);
2497        }
2498    }
2499
2500    let mut map = serde_json::Map::new();
2501    map.insert(
2502        "_generated".to_string(),
2503        serde_json::Value::String(
2504            "Generated from the grammar_symbol field of bynkc/src/diagnostics.rs. \
2505             Do not edit by hand. Regenerate with: BYNK_BLESS=1 cargo test -p \
2506             bynkc --test diagnostics_registry"
2507                .to_string(),
2508        ),
2509    );
2510    for (sym, infos) in by_symbol {
2511        let arr: Vec<serde_json::Value> = infos
2512            .iter()
2513            .map(|info| serde_json::json!({ "code": info.code, "summary": info.summary }))
2514            .collect();
2515        map.insert(sym.to_string(), serde_json::Value::Array(arr));
2516    }
2517
2518    let mut s =
2519        serde_json::to_string_pretty(&serde_json::Value::Object(map)).expect("serialise semantics");
2520    s.push('\n');
2521    s
2522}