Every runtime message in the extension is declared once, in
apps/extension/utils/messaging.ts, as the ExtensionProtocol interface:
key = message type, parameter = payload, return type = response. Both ends
are typed end to end; never use raw runtime.sendMessage.
Add the method signature to ExtensionProtocol in
apps/extension/utils/messaging.ts.
Register the handler in the owning background module, at the top
level of the file (see
background patterns).
Call it with sendMessage from any surface. The compiler enforces
payload and response types on both ends.
If the message belongs to a prunable module, wrap the protocol lines in
that module’s wiring markers (// module:<id>:start … end) so pruning
keeps the file compiling; see the module system.
State reads. Surfaces don’t ask the background for state; they read
the storage.local snapshots (user, entitlements, gateDecision,
broadcasts) via hooks (useAuth, useEntitlement,
useGateDecision). Messages are for actions.
Backend calls with tokens. UI and content scripts never hold ID
tokens; they send a message, and the background attaches the token to
the API call.