channel

A coding command for adding a WebSocket channel to a TriadJS router. WebSockets keep a live connection between a client and server so they can exchange messages in real time.

In plain words
What is it for?
Use it to create a channel file, define the messages clients send and servers emit, validate connections, manage connection changes, and add message handlers.
Why use it?
It removes the need to manually wire connection setup, message handlers, connection events, and shared channel state. It also checks that the project uses the required Fastify adapter.

Command

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.

agentmods
npx agentmods add commands/justhamade/triadjs/channel
Clone the repo
git clone --depth 1 https://github.com/justhamade/triadjs
Per session 39 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 918 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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 $0.00039 $0.00918
Opus 5 $0.00019 $0.00459
Sonnet 5 $0.00008 $0.00184
Haiku 4.5 $0.00004 $0.00092

Measured 2d ago against content hash 1e5ca1581b18, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

channel 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 2d 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.

plugin/commands/channel.md · 79 lines

How it starts

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

Load the triad-channel skill for the authoritative channel() signature and state typing rules. Load triad-behaviors for channel-specific assertion phrases.

Add a new WebSocket channel to the project based on the user's description ($ARGUMENTS).

Prerequisites

  1. Confirm the project uses @triadjs/fastify — Express and Hono adapters do NOT support channels. If the project is on a non-Fastify adapter, tell the user and stop.
  2. Install @fastify/websocket if not already present: npm install @fastify/websocket.

Steps

  1. Place the channel in src/channels/<name>.ts.

  2. Define the state interface and use the phantom witness pattern:

    interface ChatRoomState {
      userId: string;
      userName: string;
      roomId: string;
    }
    
    channel({
      state: {} as ChatRoomState, // phantom — value ignored, type used for ctx.state
      // ...
    });
    

    Without the witness, ctx.state is Record<string, any>.

  3. Declare clientMessages (what clients send) and serverMessages (what the server emits). Every clientMessages key must have a matching handlers[key] — missing or extra keys are compile errors.

  4. Implement onConnect — validate the handshake (via schemas or ctx.reject(code, msg)), seed ctx.state, optionally broadcast a join event.

  5. Implement onDisconnect — optionally broadcast a leave event. Don't throw.

  6. Implement per-message handlers — call repositories via ctx.services, then:

    • ctx.broadcast.eventName(payload) to send to everyone including the sender
    • ctx.broadcastOthers.eventName(payload) to exclude the sender
    • ctx.send.eventName(payload) to reply only to this client
  7. If the channel is browser-facing, use auth.strategy: 'first-message' — browsers cannot set custom headers on new WebSocket(). Declare an __auth client message and cast ctx.authPayload inside onConnect.

  8. Add channel behaviors:

    behaviors: [
      scenario('broadcasting a message reaches every client')
        .given('two connected clients')
        .setup(async () => ({ /* ... */ }))
        .when('alice sends a sendMessage')
        .then('all clients receive a message event')
        .and('bob receives a message with text "hello"'),
    ]
    

    Use channel-specific phrases from the triad-behaviors skill — <client> receives a <type> event, all clients receive..., connection is rejected with code N.

Read the full file on GitHub · 79 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. 2d ago First seen · 79 lines · 39 tokens per session scan A 1e5ca1581b18

Subscribe to this mod's changes

channel is a command published in the GitHub repository justhamade/triadjs (23 stars, last pushed 4mo ago), licensed MIT. It adds 39 tokens to every session and 918 once invoked, about $0.0002 per session on Opus 5. 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-08-30.