websockets

websockets is a cursor rule for Cursor from BetterTyped/hype-stack. It costs 0 tokens per session (1,763 once invoked), scanned A, original, MIT.

A set of project rules for building real-time features with WebSockets, a browser-to-server connection that stays open for live updates. It specifies typed events, session-based login, reconnecting, and tests for the connection.

In plain words
What is it for?
Use it when adding or changing live notifications, dashboards, collaboration features, or other data that must update without page refreshes. It covers the WebSocket server, client connection, event handling, authentication, and testing.
Why use it?
It removes the need to invent separate client and server event names, connection setup, login handling, and retry logic. It also helps keep real-time code consistent across the project.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/.

Good fit Use it when adding or changing live notifications, dashboards, collaboration features, or other data that must update without page refreshes. It covers the WebSocket server, client connection, event handling, authentication, and testing.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/bettertyped/hype-stack/websockets
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/BetterTyped/hype-stack

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for websockets

README.md
[![agentmods](https://agentmods.dev/badge/rules/bettertyped/hype-stack/websockets/github.svg)](https://agentmods.dev/rules/bettertyped/hype-stack/websockets)
Your own site
<a href="https://agentmods.dev/rules/bettertyped/hype-stack/websockets"><img src="https://agentmods.dev/badge/rules/bettertyped/hype-stack/websockets/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for websockets

Your own site · 80×15
<a href="https://agentmods.dev/rules/bettertyped/hype-stack/websockets"><img src="https://agentmods.dev/badge/rules/bettertyped/hype-stack/websockets.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,763 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.01763
Opus 5.5 $0.00000 $0.00705
Sonnet 5.5 $0.00000 $0.00353
Haiku 4.5 $0.00000 $0.00176

Measured 1mo ago against content hash 1f69e2efcabb, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

websockets scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/websockets.mdc · 102 lines

How it starts

The opening of the file, as written. The whole thing — 102 lines — stays where its author put it; the contents beside it link to each section on GitHub.

WebSockets

One socket per client app, typed end to end. The backend declares events with SocketRouter, the type bridge in src/types/hono/hono-ws-converter.ts turns those declarations into WsSocketSdk, and the client consumes them through socketSdk. No topic string is written twice and nothing is wired by hand.

How a connection works

  • src/api/client.ts creates the socket once, at import time, next to the HTTP client: new Socket({ url: \${wsProtocol}://${wsHost}/ws` }). Admin creates a second one on /ws/admin. HyperFetch connects at startup and reconnects on its own. Never hand-roll new WebSocket` or a retry loop.
  • The auth starter binds the socket to the session in features/auth/modules/session-socket/session-socket.ts. Its socket.onConnect interceptor runs before every connection attempt (first connect, automatic and manual reconnect) and calls users/me first: the upgrade authenticates with the session cookie, and only an HTTP request through the auth middleware can rotate an expired access token, so without this a reconnect after an idle hour is refused with 4001 and retried every five seconds for good. A 401 or 403 from that request throws, which abandons the attempt instead of looping for a signed-out visitor. The (private) route guard calls connectSessionSocket in onEnter and disconnectSessionSocket in onLeave (the mobile private layout does the same from an effect), so signing in opens the socket and signing out closes it.
  • Every frame is JSON { topic, data }. Topics are <prefix>/<event> (notification/new, board/op): the prefix comes from .socket("/notification", ...), the event from .emitter() or .listener().
  • The backend serves the upgrade at /ws (createWsRoutes) and calls authenticate(headers) in onOpen. null closes the socket with code 4001. The browser sends the session cookie with the upgrade, so socket auth reuses the HTTP session and nothing goes in the URL. The upgrade never refreshes that cookie; that is what the session-socket interceptor above is for.
  • Connections live in a ConnectionManager per namespace (appWsManager for /ws, adminWsManager for /ws/admin), keyed by user id with the organization id alongside. That registry is what toUser, toOrganization, and broadcast walk. Namespaces never see each other's connections.
  • initWebSocket(app) runs before the routes and serveWebsockets(server) after serve() in main.ts. Both are already there. Do not add a second createNodeWebSocket.

Read the full file on GitHub · 102 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 1mo ago Changed · +1 lines 1f69e2efcabb
  2. 1mo ago First seen · 101 lines · 0 tokens per session scan A 9a7b8f1a96ff

Subscribe to this mod's changes

websockets is a cursor rule published in the GitHub repository BetterTyped/hype-stack (12 stars, last pushed 6d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,763 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-11.