Skip to main content

bynk_syntax/
diagnostics.rs

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