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