The カカシ・プロトコル aka. Kakashi Protocol is how Copy Ninja talks. The Chatterbox userscript and kakashi-server share it through the @laplace.live/kakashi-protocol package in the monorepo. This page is for developers who want to build their own client, server, or debugging tool; to simply use the feature, follow the Copy Ninja page
Overview
- Transport: WebSocket text frames, each one a JSON object with a
typefield - Default address:
ws://127.0.0.1:9697(port 9696 belongs to LAPLACE Event Bridge). Clients use the loopback IP rather thanlocalhost, which may resolve to::1first - Protocol version: currently
1. Any breaking change bumps it, and peers on different versions are refused - Validation: both sides validate every frame strictly; malformed frames are dropped and unknown fields are ignored
- Limits: frames up to 16 KiB; an idle connection closes after 60 seconds, and the server sends pings to keep it alive
- Status check: a plain HTTP
GETto the server returns{ "name": "kakashi-server", "version": "…", "protocol": 1 }
Connection and Handshake
- Origin check: the server checks the WebSocket handshake's
Originheader and accepts onlyhttps://live.bilibili.complus any origins allowed with--allow-origin; anything else gets HTTP 403. Connections without anOriginheader (non-browser clients) are let through - hello: once connected, the client must send
hellowithin 10 seconds, or the socket closes with4003 - Version check: the server reads
hello.protocolbefore full validation, so a newer client gets a clear version error (4002) rather than a parse error - Token check: when the server runs with
--token,hello.tokenmust match exactly (compared in constant time), or the socket closes with4001 - welcome: once the hello passes, the server replies with
welcomeand then broadcasts the latestrosterto every page
Close Codes
| Code | Name | Trigger | Chatterbox Behavior |
|---|---|---|---|
4001 | UNAUTHORIZED | Wrong token | Stops reconnecting until settings change |
4002 | PROTOCOL_MISMATCH | Protocol versions differ | Stops reconnecting until settings change |
4003 | BAD_HELLO | First frame isn't a valid hello, or 10 s timeout | Reconnects |
On any other disconnect, Chatterbox reconnects automatically, starting at 1 second and doubling each time up to 30 seconds
Roles and Master Election
- Each connection declares its role in
hello/presence:masterormirror - The server folds all pages with the same
uidinto one member, whose role in therosteris one of:
| Role | Description |
|---|---|
master | The active master account; there is only ever one |
standby | Claims master while another account holds the seat, so it waits |
mirror | A mirror account |
- With no master, the earliest-connected page among those claiming
masterwins, and its account becomes the master - When every page of the master account disconnects (a page reload, for example), its seat is held for 15 seconds. Reconnecting in that window keeps the seat; after it, a standby account takes over
- When the master account is still online but switches to
mirror, the seat is released at once
Action Routing
- The master page sends one
actionfor each danmaku segment bilibili's send API reports as successful, so a long message split into segments is sent segment by segment. Anactionfrom any other account gets anerrorback and is not relayed - The server assigns each action an
eventId(a UUID). For every mirror account, it picks one of that account's pages in theaction.roomIdlive room to deliver to: a visible page first, then the most recently active one (ahello, a hidden-to-visible switch, or a room change all count as activity) - When a mirror account has no page in that room, the server replies
skipped("not in the same live room") to the master on its behalf - The master's own pages and standby accounts never receive actions
- After handling it, the mirror sends a
resultwith the sameeventId, which the server forwards to the master page that broadcast the action. Results arriving more than 5 minutes later are no longer forwarded
| Status | Meaning |
|---|---|
sent | Copied successfully |
failed | Attempted, but bilibili rejected it |
dropped | Ignored at random by decay |
skipped | Not attempted — for example the source isn't followed, wrong room, expired, paused, or emote unavailable |
Action Sources
DanmakuAction.source names the feature the master sent the danmaku through, and mirrors decide whether to copy based on it:
source | Feature |
|---|---|
manual | Normal send in the "Send" tab |
loop | Auto Send |
repeat | The "+1" button next to a danmaku |
emote | Emote picker |
meme | Memes |
blend | Auto Blend |
ai | AI Blend |
stt | Simultaneous Interpretation |
Copies a mirror sends are tagged copy inside the client, and sends relayed from the LAPLACE Chat dashboard are tagged laplace-chat; neither is ever broadcast
Room Following
roster.masterRoomIdis the live room of the master account's most recently active page- For each mirror account with no page in that room, the server picks one of its pages that has
follow: trueand a resolved room, and sends itfollow followis re-sent on every connection or presence update; a client already waiting to move to that same room ignores the repeat- On
follow, the client re-checks for itself (following on, not paused, still the master's room) and moves after a random 2 to 5 second delay
Message Reference
Client → Server
hello
Prop
Type
presence
Prop
Type
action
Prop
Type
result
Prop
Type
Server → Client
welcome
Prop
Type
roster
Prop
Type
Each entry in members:
Prop
Type
action
Prop
Type
result
Prop
Type
follow
Prop
Type
error
Prop
Type
DanmakuAction
Prop
Type
Example
The master sends a danmaku, the server delivers it to a mirror, and the mirror reports back:
// Master → server
{ "type": "action", "action": { "kind": "danmaku", "roomId": 21452505, "text": "awsl", "source": "manual" } }
// Server → mirror
{
"type": "action",
"eventId": "6f1c2a4e-8d3b-4f5a-9c7e-1b2d3e4f5a6b",
"from": { "uid": "1234567", "uname": "MasterAccount" },
"action": { "kind": "danmaku", "roomId": 21452505, "text": "awsl", "source": "manual" }
}
// Mirror → server
{ "type": "result", "eventId": "6f1c2a4e-8d3b-4f5a-9c7e-1b2d3e4f5a6b", "status": "sent" }
// Server → master
{ "type": "result", "eventId": "6f1c2a4e-8d3b-4f5a-9c7e-1b2d3e4f5a6b", "uid": "7654321", "uname": "MirrorAccount", "status": "sent" }Last updated on November 29, 2026