websockets

websockets is a cursor rule for Cursor from BetterTyped/hype-stack. It costs 0 tokens per session (1,561 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,561 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.01561
Opus 5 $0.00000 $0.00781
Sonnet 5 $0.00000 $0.00312
Haiku 4.5 $0.00000 $0.00156

Measured yesterday against content hash 9a7b8f1a96ff, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-12, 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 yesterday.

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 · 101 lines

How it starts

The opening of the file, as written. The whole thing — 101 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 opens the socket once, at import time, next to the HTTP client: new Socket({ url: \${wsProtocol}://${wsHost}/ws` }). Admin opens a second one on /ws/admin. HyperFetch reconnects on its own. Never hand-roll new WebSocket` or a retry loop.
  • 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.
  • 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.

Backend: declare events

Event definitions live in src/sockets/<domain>/index.ts, next to but separate from HTTP routes:

import { createSocketRouter } from "@backend/libs/websocket/socket-router";
import { wsValidate } from "@backend/libs/websocket/ws-validate";
import { z } from "zod";

export type WsNotificationPayload = { id: string; title: string; readAt: string | null };

export const notificationSockets = createSocketRouter()
  .emitter("new")<WsNotificationPayload>()
  .listener("mark-read", wsValidate(z.object({ notificationId: z.string() })), async (c) => {
    await markRead({ notificationId: c.data.notificationId, userId: c.userId });
  });

Read the full file on GitHub · 101 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. yesterday 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 (6 stars, last pushed 2d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,561 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.

Related

Other cursor rules, from other repositories

python_tests

We use the unit tests to cover internal behavior that can work without the web / backend counterpart. We aim for 95%+ unit test coverage of our Python code in lib/streamlit.

streamlit/streamlit · 0 tokens

manual-review.backend

The obligations, predicates, evidence schema, failure handling, and review timing in this source are shared. Concrete browser, dispatch, question, filesystem, and command mechanics are target-native and MUST come from the selected runtime fragment at the matching adapter path. A fragment declares only the capability…

YuDefine/nuxt-supabase-starter · 0 tokens

create-a-testable-http-client-service

Cursor rule "create-a-testable-http-client-service" from PaulJPhilp/EffectPatterns, covering create a testable http client service, example, 1. define the service, 2. create the live implementation and 3. create the test implementation.

PaulJPhilp/EffectPatterns · 1,005 tokens

architecture

This document outlines the fundamental architectural principles and patterns for the mcp-debug codebase. Adherence to these guidelines is mandatory to maintain a clean, decoupled, and testable system.

giantswarm/mcp-debug · 333 tokens

issues-tests

Backend test conventions — QuarkusTest, REST Assured, Given, ArchUnit.

vepo/issues · 0 tokens

api-design

API design guidelines — REST principles, GraphQL patterns, versioning, pagination, error handling, documentation, security, caching, and testing. Applied when designing or reviewing API endpoints.

adonai-labs/agent-runway · 0 tokens