feat(cli+broker): three-tier peer removal: disconnect, kick, ban
Broker (apps/broker/src/index.ts)
- Unified disconnect/kick handler uses close code 1000 for disconnect
(CLI auto-reconnects) vs 4001 for kick (CLI exits, no reconnect).
- Ban now closes with code 4002.
- Hello handler: revoked members get a specific 'revoked' error with a
'Contact the mesh owner to rejoin' message, then ws.close(4002).
Previously banned users saw the generic 'unauthorized' error.
- list_bans handler returns { name, pubkey, revokedAt } for each
revoked member.
CLI (apps/cli)
- ws-client: close codes 4001 and 4002 set .closed = true and stash
.terminalClose so callers can surface a friendly message instead of
the low-level 'ws terminal close' error. Revoked error in hello is
also captured as a terminal close.
- withMesh catches terminalClose and prints:
4001 → 'Kicked from this mesh. Run claudemesh to rejoin.'
4002 → the broker's 'Contact the mesh owner to rejoin.' message
- kick.ts now exports runDisconnect + runKick with clear hints:
'disconnect' → 'They will auto-reconnect within seconds.'
'kick' → 'They can rejoin anytime by running claudemesh.'
- cli.ts adds 'disconnect' dispatch; HELP updated.
Semantics:
disconnect: session reset, no DB state, auto-reconnects
kick : session ends, no DB state, user must manually rejoin
ban : session ends + revokedAt set, cannot rejoin until unban
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -75,6 +75,21 @@ export async function withMesh<T>(
|
||||
await client.connect();
|
||||
const result = await fn(client, mesh);
|
||||
return result;
|
||||
} catch (e) {
|
||||
// Terminal close from the broker (banned / kicked). Give the user
|
||||
// a clear message instead of the low-level ws error.
|
||||
if (client.terminalClose) {
|
||||
const { code, reason } = client.terminalClose;
|
||||
if (code === 4002) {
|
||||
console.error(`\n ✘ ${reason}\n`);
|
||||
} else if (code === 4001) {
|
||||
console.error(`\n ✘ Kicked from this mesh. Run \`claudemesh\` to rejoin.\n`);
|
||||
} else {
|
||||
console.error(`\n ✘ Broker closed connection: ${reason}\n`);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
throw e;
|
||||
} finally {
|
||||
client.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user