rogerrat 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,12 +1,28 @@
1
- # RogerRat
1
+ <p align="center">
2
+ <img src="./assets/logo.svg" width="180" alt="RogerRat" />
3
+ </p>
2
4
 
3
- **Walkie-talkie for AI agents.** A tiny MCP server that lets two (or more)
4
- Claude Code, Cursor, Cline, or Claude Desktop sessions — running on any
5
- machine — talk to each other in real time.
5
+ <h1 align="center">RogerRat</h1>
6
+
7
+ <p align="center">
8
+ <em>Walkie-talkie for your AI agents.</em>
9
+ </p>
10
+
11
+ <p align="center">
12
+ <a href="https://www.npmjs.com/package/rogerrat"><img src="https://img.shields.io/npm/v/rogerrat?color=d6541f&label=npm" alt="npm version" /></a>
13
+ <a href="https://www.npmjs.com/package/rogerrat"><img src="https://img.shields.io/npm/dm/rogerrat?color=d6541f" alt="npm downloads" /></a>
14
+ <a href="./LICENSE"><img src="https://img.shields.io/npm/l/rogerrat?color=d6541f" alt="MIT license" /></a>
15
+ <a href="https://rogerrat.chat"><img src="https://img.shields.io/badge/hosted-rogerrat.chat-d6541f" alt="rogerrat.chat" /></a>
16
+ </p>
17
+
18
+ ---
19
+
20
+ A tiny MCP server that lets two (or more) Claude Code, Cursor, Cline, or Claude
21
+ Desktop sessions — running on any machine — talk to each other in real time.
6
22
 
7
23
  Use the **hosted** version at [rogerrat.chat](https://rogerrat.chat) (no setup,
8
- free) or run your own with **`npx rogerrat`** (local-only, zero dependencies
9
- beyond Node 20).
24
+ free) or run your own with **`npx rogerrat`** (local, zero dependencies beyond
25
+ Node 20).
10
26
 
11
27
  ```
12
28
  agent A ─MCP/HTTPS─┐
@@ -14,37 +30,32 @@ beyond Node 20).
14
30
  agent B ─MCP/HTTPS─┘ (roster + ring buffer)
15
31
  ```
16
32
 
17
- ## Quickstart — hosted
18
-
19
- 1. Visit [rogerrat.chat](https://rogerrat.chat) → **Create channel**, or:
33
+ ## Quickstart — hosted (no install)
20
34
 
21
- ```bash
22
- curl -X POST https://rogerrat.chat/api/channels
23
- ```
24
-
25
- 2. Take the snippet for your client (Claude Code / Cursor / Cline / Claude
26
- Desktop / Anthropic SDK) and paste it on each machine that should join.
27
-
28
- 3. Each agent calls `join(callsign)`, then `send` / `listen` to talk.
35
+ 1. Visit [rogerrat.chat](https://rogerrat.chat) → click **Create channel**.
36
+ 2. Pick your client (Claude Code / Cursor / Cline / Claude Desktop / Anthropic
37
+ SDK) and copy the snippet.
38
+ 3. Paste it on each machine that should join. Each agent calls `join(callsign)`,
39
+ then `send` / `listen` to talk.
29
40
 
30
41
  ### One-time setup for natural-language channel creation
31
42
 
32
- Add the bootstrap MCP server **once per machine**:
43
+ Install the bootstrap MCP server **once per machine**:
33
44
 
34
45
  ```bash
35
46
  claude mcp add --transport http rogerrat https://rogerrat.chat/mcp
36
47
  ```
37
48
 
38
- Then in any session: *"abrime un canal en rogerrat"* — Claude calls the
49
+ Then in any session, just say *"create a rogerrat channel"* — Claude calls the
39
50
  `create_channel` tool and prints the snippet for the other agent.
40
51
 
41
- ## Quickstart — local (no server, no hosted)
52
+ ## Quickstart — local (`npx`)
42
53
 
43
54
  ```bash
44
55
  npx rogerrat
45
56
  # → http://127.0.0.1:7424
46
57
 
47
- # in another shell, install in your AI client:
58
+ # In another shell, install in your AI client:
48
59
  claude mcp add --transport http rogerrat http://127.0.0.1:7424/mcp
49
60
  ```
50
61
 
@@ -54,6 +65,16 @@ Local mode binds 127.0.0.1, no auth, ephemeral. For LAN sharing:
54
65
  npx rogerrat --host 0.0.0.0 --token mysecret
55
66
  ```
56
67
 
68
+ Options:
69
+
70
+ ```
71
+ --port <n> port to listen on (default: 7424)
72
+ --host <addr> interface to bind (default: 127.0.0.1)
73
+ --token <secret> require Bearer token (required when --host != 127.0.0.1)
74
+ --data <path> channels.json path (default: ~/.rogerrat/channels.json)
75
+ --origin <url> public origin advertised in connect snippets
76
+ ```
77
+
57
78
  ## Tools the agent gets
58
79
 
59
80
  Once a session calls `join`, it gets six tools:
@@ -67,35 +88,105 @@ Once a session calls `join`, it gets six tools:
67
88
  | `history(n)` | last N messages (max 100) |
68
89
  | `leave()` | disconnect cleanly |
69
90
 
70
- The result of `join` includes operating instructions that tell the agent to
91
+ The result of `join` includes operating instructions telling the agent to
71
92
  `listen` after every response — that's what keeps the conversation alive
72
93
  instead of being one-shot.
73
94
 
95
+ ## Example: pair debugging
96
+
97
+ Two terminals, one channel.
98
+
99
+ **Terminal 1 — frontend repo:**
100
+ > *"Join the rogerrat channel as `frontend`. Wait for `backend` to report an
101
+ > error. When they do, find the failing call site in the dashboard and reply
102
+ > with the endpoint+payload. Call `listen` after every action."*
103
+
104
+ **Terminal 2 — backend repo:**
105
+ > *"Join as `backend`. Tell `frontend`: 'dashboard tira 500 en /admin, log del
106
+ > cliente'. When they reply with the endpoint, find the handler, identify the
107
+ > bug, propose a fix. Call `listen` after every action."*
108
+
109
+ The agents ping-pong until one calls `leave()`.
110
+
74
111
  ## Architecture
75
112
 
76
- - Single Node process (Hono + `@hono/node-server`).
77
- - Channels live in memory. Last 100 messages per channel; older drop off the
78
- ring.
113
+ - Single Node process. Hono + `@hono/node-server`. ~500 lines of TypeScript.
114
+ - Channels live in memory. Last 100 messages per channel; older drop off the ring.
79
115
  - Channels themselves persist (id + token hash) to a JSON file so the process
80
116
  can restart without invalidating connect commands.
81
117
  - Transport: MCP **Streamable HTTP** (JSON-RPC over POST; session id in
82
118
  `Mcp-Session-Id` header).
83
119
  - No WebSockets. `listen` is HTTP long-polling — simpler, fits MCP's
84
- JSON-RPC envelope, and survives any HTTP proxy.
120
+ JSON-RPC envelope, survives any HTTP proxy.
121
+ - Bootstrap MCP endpoint at `POST /mcp` (no channel, no auth) exposes a single
122
+ tool `create_channel` for natural-language channel creation.
123
+
124
+ ## Retention (transcripts)
125
+
126
+ By default, channels are **ephemeral** — last 100 messages in memory, nothing
127
+ saved. If you want a transcript, set retention at channel creation:
128
+
129
+ | mode | what the server keeps |
130
+ | ---------- | -------------------------------------------------- |
131
+ | `none` | (default) nothing |
132
+ | `metadata` | joins, leaves, message timestamps + sizes — no content |
133
+ | `prompts` | the first message each agent sends, only |
134
+ | `full` | every message, indefinitely |
135
+
136
+ ```bash
137
+ # via API
138
+ curl -X POST https://rogerrat.chat/api/channels \
139
+ -H 'Content-Type: application/json' \
140
+ -d '{"retention":"full"}'
141
+
142
+ # via the bootstrap MCP tool — just ask Claude:
143
+ # "create a rogerrat channel with full retention"
144
+ # (Claude calls create_channel with retention="full")
145
+ ```
146
+
147
+ Download the transcript with the channel's bearer token:
148
+
149
+ ```bash
150
+ curl -H "Authorization: Bearer <token>" \
151
+ https://rogerrat.chat/api/channels/<channel-id>/transcript
152
+ ```
153
+
154
+ Anyone holding the channel token can pull the transcript. There are no
155
+ accounts — the bearer token is the access control.
156
+
157
+ ### Logger-agent pattern (zero server retention)
158
+
159
+ If you don't want the server to keep anything but still want a log, designate
160
+ one agent on the channel as the "logger":
161
+
162
+ > *"Join as `logger`. Every 30 seconds, call `history(100)` and append new
163
+ > events to `~/conversation-log.jsonl`. Never send anything yourself. Stay until
164
+ > the channel goes idle for 10 minutes, then `leave`."*
165
+
166
+ The transcript lives on the logger's machine, never on the hub. Combine with
167
+ `retention: "none"` for true zero-server-side-storage.
168
+
169
+ ## Admin dashboard
170
+
171
+ Set `ROGERRAT_ADMIN_TOKEN` (hosted) or `--admin-token <secret>` (CLI) to enable
172
+ a dashboard at `/admin` that shows active channels, their roster, message
173
+ counts, and retention setting — **never the message content**. Auto-refreshes
174
+ every 5 s.
85
175
 
86
176
  ## Safety
87
177
 
88
178
  Anything an agent reads from the channel is **untrusted input**. If you give
89
179
  your agent broad tool access (shell, file edits, the works), another agent on
90
- the channel can ask it to do things. Treat channel traffic the way you'd treat
91
- a prompt from a stranger on the internet. Don't put sensitive data into
92
- channels you wouldn't post on a public board.
180
+ the channel can ask it to do things. Treat channel traffic like prompts from a
181
+ stranger on the internet. Don't put sensitive data into channels you wouldn't
182
+ post on a public board.
93
183
 
94
- ## Self-hosting beyond `npx`
184
+ ## Self-hosting
95
185
 
96
186
  The hosted instance at rogerrat.chat is a Node process behind Caddy
97
- (Let's Encrypt). See [deploy/](./deploy/) for the systemd unit and Caddyfile
98
- snippet used in production they're meant as a recipe, not a constraint.
187
+ (Let's Encrypt). See [`deploy/`](./deploy/) for the systemd unit and Caddyfile
188
+ snippet — meant as a recipe, not a constraint. Anything that can reverse-proxy
189
+ HTTP and route to a Node process works.
99
190
 
100
191
  ## Development
101
192
 
@@ -105,6 +196,12 @@ cd rogerrat && npm install
105
196
  npm run dev # tsx watch on src/server.ts
106
197
  ```
107
198
 
199
+ ## Related
200
+
201
+ - [suruseas/walkie-talkie](https://github.com/suruseas/walkie-talkie) — the
202
+ inspiration. Local-first by design. RogerRat is the hosted-friendly variant
203
+ with a simpler transport (no stdio bridge).
204
+
108
205
  ## License
109
206
 
110
- MIT.
207
+ MIT. See [`LICENSE`](./LICENSE).
package/dist/admin.js ADDED
@@ -0,0 +1,295 @@
1
+ export function adminHtml() {
2
+ return `<!doctype html>
3
+ <html lang="en">
4
+ <head>
5
+ <meta charset="utf-8" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
7
+ <title>rogerrat — admin</title>
8
+ <style>
9
+ :root {
10
+ --bg: #f4ede0;
11
+ --ink: #1a1a1a;
12
+ --dim: #7a6f5f;
13
+ --warn: #d6541f;
14
+ --line: #c9b994;
15
+ --paper: #fffaef;
16
+ --ok: #2d8a3e;
17
+ }
18
+ * { box-sizing: border-box; }
19
+ body {
20
+ margin: 0;
21
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
22
+ background: var(--bg);
23
+ color: var(--ink);
24
+ line-height: 1.4;
25
+ }
26
+ .wrap { max-width: 980px; margin: 0 auto; padding: 32px 24px; }
27
+ header { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 24px; gap: 16px; flex-wrap: wrap; }
28
+ .logo { font-size: 16px; font-weight: 700; display: inline-flex; align-items: center; gap: 8px; }
29
+ .logo svg { width: 22px; height: 22px; }
30
+ .updated { font-size: 12px; color: var(--dim); }
31
+ .auth {
32
+ background: var(--paper);
33
+ border: 2px solid var(--ink);
34
+ padding: 24px;
35
+ margin: 48px auto;
36
+ max-width: 460px;
37
+ }
38
+ .auth h2 { margin: 0 0 12px; font-size: 18px; }
39
+ .auth p { color: var(--dim); font-size: 13px; margin: 0 0 16px; }
40
+ .auth input {
41
+ width: 100%;
42
+ padding: 10px 12px;
43
+ border: 1px solid var(--line);
44
+ background: white;
45
+ font-family: inherit;
46
+ font-size: 14px;
47
+ margin-bottom: 12px;
48
+ }
49
+ .auth button {
50
+ width: 100%;
51
+ padding: 10px;
52
+ background: var(--warn);
53
+ color: white;
54
+ border: none;
55
+ font-family: inherit;
56
+ font-size: 14px;
57
+ font-weight: 700;
58
+ cursor: pointer;
59
+ }
60
+ .auth button:hover { background: #b8451a; }
61
+ .stats {
62
+ display: grid;
63
+ grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
64
+ gap: 0;
65
+ margin-bottom: 24px;
66
+ border: 1px solid var(--line);
67
+ background: var(--paper);
68
+ }
69
+ .stat {
70
+ padding: 16px 20px;
71
+ border-right: 1px solid var(--line);
72
+ }
73
+ .stat:last-child { border-right: none; }
74
+ .stat-num {
75
+ font-size: 22px;
76
+ font-weight: 700;
77
+ font-variant-numeric: tabular-nums;
78
+ }
79
+ .stat-label {
80
+ font-size: 11px;
81
+ text-transform: uppercase;
82
+ letter-spacing: 0.08em;
83
+ color: var(--dim);
84
+ margin-top: 2px;
85
+ }
86
+ table {
87
+ width: 100%;
88
+ border-collapse: collapse;
89
+ background: var(--paper);
90
+ border: 1px solid var(--line);
91
+ }
92
+ th, td {
93
+ text-align: left;
94
+ padding: 10px 14px;
95
+ font-size: 13px;
96
+ border-bottom: 1px solid var(--line);
97
+ vertical-align: top;
98
+ }
99
+ th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--dim); font-weight: 600; }
100
+ tr:last-child td { border-bottom: none; }
101
+ .empty {
102
+ text-align: center;
103
+ padding: 40px 0;
104
+ color: var(--dim);
105
+ font-size: 14px;
106
+ }
107
+ .chip {
108
+ display: inline-block;
109
+ padding: 2px 8px;
110
+ background: var(--bg);
111
+ border: 1px solid var(--line);
112
+ border-radius: 3px;
113
+ font-size: 12px;
114
+ margin: 1px 2px 1px 0;
115
+ }
116
+ .channel-id { font-weight: 700; }
117
+ .err {
118
+ color: var(--warn);
119
+ font-size: 12px;
120
+ margin-bottom: 8px;
121
+ }
122
+ footer { margin-top: 32px; color: var(--dim); font-size: 12px; }
123
+ footer a { color: var(--dim); }
124
+ </style>
125
+ </head>
126
+ <body>
127
+ <div class="wrap">
128
+ <header>
129
+ <div class="logo">
130
+ <svg viewBox="0 0 32 32" aria-hidden="true">
131
+ <rect width="32" height="32" rx="6" fill="#1a1a1a"/>
132
+ <path d="M 9 7 Q 16 4 23 7" stroke="#d6541f" stroke-width="1.5" fill="none" stroke-linecap="round"/>
133
+ <ellipse cx="11" cy="14" rx="2" ry="3" fill="#f4ede0" transform="rotate(-15 11 14)"/>
134
+ <ellipse cx="21" cy="14" rx="2" ry="3" fill="#f4ede0" transform="rotate(15 21 14)"/>
135
+ <ellipse cx="16" cy="22" rx="8" ry="6.5" fill="#f4ede0"/>
136
+ <circle cx="13" cy="21" r="1.2" fill="#1a1a1a"/>
137
+ <circle cx="19" cy="21" r="1.2" fill="#1a1a1a"/>
138
+ <ellipse cx="16" cy="25" rx="1.5" ry="1" fill="#d6541f"/>
139
+ </svg>
140
+ <span>rogerrat / admin</span>
141
+ </div>
142
+ <div class="updated" id="updated">—</div>
143
+ </header>
144
+
145
+ <div id="auth-gate" class="auth" hidden>
146
+ <h2>Admin token required</h2>
147
+ <p>Paste the admin token configured on this rogerrat instance. It's the value of <code>ROGERRAT_ADMIN_TOKEN</code> (hosted) or <code>--admin-token</code> (CLI).</p>
148
+ <div id="auth-err" class="err"></div>
149
+ <input id="auth-input" type="password" placeholder="admin token" autocomplete="off" />
150
+ <button id="auth-submit">Unlock</button>
151
+ </div>
152
+
153
+ <div id="dashboard" hidden>
154
+ <div class="stats">
155
+ <div class="stat">
156
+ <div class="stat-num" id="lt-channels">—</div>
157
+ <div class="stat-label">channels (lifetime)</div>
158
+ </div>
159
+ <div class="stat">
160
+ <div class="stat-num" id="lt-joins">—</div>
161
+ <div class="stat-label">joins (lifetime)</div>
162
+ </div>
163
+ <div class="stat">
164
+ <div class="stat-num" id="lt-messages">—</div>
165
+ <div class="stat-label">messages (lifetime)</div>
166
+ </div>
167
+ <div class="stat">
168
+ <div class="stat-num" id="active-channels">—</div>
169
+ <div class="stat-label">channels open now</div>
170
+ </div>
171
+ <div class="stat">
172
+ <div class="stat-num" id="active-agents">—</div>
173
+ <div class="stat-label">agents online</div>
174
+ </div>
175
+ </div>
176
+
177
+ <table>
178
+ <thead>
179
+ <tr>
180
+ <th>Channel</th>
181
+ <th>Retention</th>
182
+ <th>Roster</th>
183
+ <th>Msgs</th>
184
+ <th>Opened</th>
185
+ <th>Last activity</th>
186
+ </tr>
187
+ </thead>
188
+ <tbody id="rows">
189
+ <tr><td colspan="5" class="empty">Loading…</td></tr>
190
+ </tbody>
191
+ </table>
192
+ </div>
193
+
194
+ <footer>
195
+ auto-refreshes every 5s · message content is never exposed by this page, only metadata · <a href="/">← landing</a>
196
+ </footer>
197
+ </div>
198
+
199
+ <script>
200
+ const KEY = 'rogerrat_admin_token';
201
+ let token = sessionStorage.getItem(KEY) || '';
202
+ const $ = (id) => document.getElementById(id);
203
+
204
+ function fmtAgo(ts) {
205
+ if (!ts) return '—';
206
+ const s = Math.max(0, Math.floor((Date.now() - ts) / 1000));
207
+ if (s < 60) return s + 's ago';
208
+ if (s < 3600) return Math.floor(s / 60) + 'm ago';
209
+ if (s < 86400) return Math.floor(s / 3600) + 'h ago';
210
+ return Math.floor(s / 86400) + 'd ago';
211
+ }
212
+
213
+ async function load() {
214
+ if (!token) { showAuthGate(); return; }
215
+ try {
216
+ const [statsR, chR] = await Promise.all([
217
+ fetch('/api/stats', { headers: { Authorization: 'Bearer ' + token } }),
218
+ fetch('/api/admin/channels', { headers: { Authorization: 'Bearer ' + token } }),
219
+ ]);
220
+ if (chR.status === 401) {
221
+ sessionStorage.removeItem(KEY);
222
+ token = '';
223
+ showAuthGate('Invalid or expired token.');
224
+ return;
225
+ }
226
+ const stats = await statsR.json();
227
+ const data = await chR.json();
228
+ renderStats(stats, data.channels);
229
+ renderRows(data.channels);
230
+ $('dashboard').hidden = false;
231
+ $('auth-gate').hidden = true;
232
+ $('updated').textContent = 'updated ' + new Date().toLocaleTimeString();
233
+ } catch (e) {
234
+ $('updated').textContent = 'error: ' + e.message;
235
+ }
236
+ }
237
+
238
+ function renderStats(stats, channels) {
239
+ $('lt-channels').textContent = stats.channels_created.toLocaleString();
240
+ $('lt-joins').textContent = stats.joins_total.toLocaleString();
241
+ $('lt-messages').textContent = stats.messages_total.toLocaleString();
242
+ $('active-channels').textContent = channels.filter(c => c.agent_count > 0).length;
243
+ $('active-agents').textContent = channels.reduce((sum, c) => sum + c.agent_count, 0);
244
+ }
245
+
246
+ function renderRows(channels) {
247
+ const rows = $('rows');
248
+ if (!channels.length) {
249
+ rows.innerHTML = '<tr><td colspan="6" class="empty">No active channels yet.</td></tr>';
250
+ return;
251
+ }
252
+ rows.innerHTML = channels.map(c => {
253
+ const roster = c.roster.length
254
+ ? c.roster.map(cs => '<span class="chip">' + esc(cs) + '</span>').join('')
255
+ : '<span style="color:var(--dim)">empty</span>';
256
+ const opened = c.first_joined_at ? fmtAgo(c.first_joined_at) : '—';
257
+ const retColor = c.retention === 'full' ? '#d6541f' : c.retention === 'none' ? 'var(--dim)' : 'var(--ink)';
258
+ return '<tr>' +
259
+ '<td class="channel-id">' + esc(c.id) + '</td>' +
260
+ '<td><span style="color:' + retColor + '">' + esc(c.retention || 'none') + '</span></td>' +
261
+ '<td>' + roster + '</td>' +
262
+ '<td>' + c.message_count + '</td>' +
263
+ '<td>' + opened + '</td>' +
264
+ '<td>' + fmtAgo(c.last_activity_at) + '</td>' +
265
+ '</tr>';
266
+ }).join('');
267
+ }
268
+
269
+ function esc(s) {
270
+ return String(s).replace(/[&<>"']/g, ch => ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[ch]));
271
+ }
272
+
273
+ function showAuthGate(errMsg) {
274
+ $('dashboard').hidden = true;
275
+ $('auth-gate').hidden = false;
276
+ $('auth-err').textContent = errMsg || '';
277
+ $('auth-input').focus();
278
+ }
279
+
280
+ $('auth-submit').addEventListener('click', () => {
281
+ const v = $('auth-input').value.trim();
282
+ if (!v) return;
283
+ sessionStorage.setItem(KEY, v);
284
+ token = v;
285
+ $('auth-err').textContent = '';
286
+ load();
287
+ });
288
+ $('auth-input').addEventListener('keydown', (e) => { if (e.key === 'Enter') $('auth-submit').click(); });
289
+
290
+ load();
291
+ setInterval(load, 5000);
292
+ </script>
293
+ </body>
294
+ </html>`;
295
+ }
package/dist/app.js CHANGED
@@ -1,15 +1,64 @@
1
1
  import { Hono } from "hono";
2
+ import { adminHtml } from "./admin.js";
3
+ import { listActiveChannels } from "./channel.js";
2
4
  import { buildConnectInfo } from "./connect.js";
3
5
  import { landingHtml } from "./landing.js";
4
6
  import { handleMcpRequest } from "./mcp.js";
5
- import { channelExists, createChannel, verifyChannel } from "./store.js";
7
+ import { getStats } from "./stats.js";
8
+ import { channelExists, createChannel, getChannelRetention, verifyChannel } from "./store.js";
9
+ import { isRetention, readTranscript } from "./transcripts.js";
6
10
  export function createApp(opts) {
7
11
  const app = new Hono();
8
12
  app.get("/", (c) => c.html(landingHtml()));
9
13
  app.get("/healthz", (c) => c.text("ok"));
10
- app.post("/api/channels", (c) => {
11
- const { id, token } = createChannel();
12
- return c.json(buildConnectInfo(id, token, opts.publicOrigin));
14
+ app.get("/api/stats", (c) => c.json(getStats()));
15
+ app.post("/api/channels", async (c) => {
16
+ let body = {};
17
+ try {
18
+ const raw = c.req.header("content-type")?.startsWith("application/json") ? await c.req.json() : {};
19
+ if (raw && typeof raw === "object")
20
+ body = raw;
21
+ }
22
+ catch {
23
+ /* body is optional; ignore parse errors */
24
+ }
25
+ const retentionInput = body.retention;
26
+ if (retentionInput !== undefined && !isRetention(retentionInput)) {
27
+ return c.json({ error: "invalid retention; must be one of none|metadata|prompts|full" }, 400);
28
+ }
29
+ const { id, token, retention } = createChannel({ retention: retentionInput });
30
+ return c.json({ ...buildConnectInfo(id, token, opts.publicOrigin), retention });
31
+ });
32
+ app.get("/api/channels/:channelId/transcript", (c) => {
33
+ const channelId = c.req.param("channelId");
34
+ if (!channelExists(channelId))
35
+ return c.json({ error: "channel not found" }, 404);
36
+ const auth = c.req.header("authorization") ?? c.req.header("Authorization") ?? "";
37
+ const token = auth.startsWith("Bearer ") ? auth.slice(7).trim() : "";
38
+ if (!token || !verifyChannel(channelId, token))
39
+ return c.json({ error: "invalid bearer token" }, 401);
40
+ const retention = getChannelRetention(channelId);
41
+ if (retention === "none")
42
+ return c.json({ error: "this channel has no transcript (retention=none)" }, 404);
43
+ const limit = Number(c.req.query("limit") ?? 1000);
44
+ const events = readTranscript(channelId, limit);
45
+ return c.json({ channel_id: channelId, retention, events });
46
+ });
47
+ function requireAdmin(c) {
48
+ if (!opts.adminToken)
49
+ return c.json({ error: "admin disabled" }, 403);
50
+ const auth = c.req.header("authorization") ?? c.req.header("Authorization") ?? "";
51
+ const token = auth.startsWith("Bearer ") ? auth.slice(7).trim() : "";
52
+ if (token !== opts.adminToken)
53
+ return c.json({ error: "invalid admin token" }, 401);
54
+ return null;
55
+ }
56
+ app.get("/admin", (c) => c.html(adminHtml()));
57
+ app.get("/api/admin/channels", (c) => {
58
+ const denied = requireAdmin(c);
59
+ if (denied)
60
+ return denied;
61
+ return c.json({ channels: listActiveChannels(getChannelRetention) });
13
62
  });
14
63
  async function mcpHandler(c, channelId) {
15
64
  if (channelId !== null) {
package/dist/channel.js CHANGED
@@ -9,11 +9,15 @@ export class Channel {
9
9
  cursorBySession = new Map();
10
10
  listenersBySession = new Map();
11
11
  nextMsgId = 1;
12
+ firstJoinedAt = null;
13
+ lastActivityAt = Date.now();
12
14
  constructor(id) {
13
15
  this.id = id;
14
16
  }
15
17
  touch(sessionId) {
16
- this.lastSeen.set(sessionId, Date.now());
18
+ const now = Date.now();
19
+ this.lastSeen.set(sessionId, now);
20
+ this.lastActivityAt = now;
17
21
  }
18
22
  gcRoster() {
19
23
  const now = Date.now();
@@ -48,6 +52,8 @@ export class Channel {
48
52
  this.callsignBySession.set(sessionId, normalized);
49
53
  this.sessionByCallsign.set(normalized, sessionId);
50
54
  this.touch(sessionId);
55
+ if (this.firstJoinedAt === null)
56
+ this.firstJoinedAt = Date.now();
51
57
  this.cursorBySession.set(sessionId, this.messages.length > 0 ? this.messages[this.messages.length - 1].id : 0);
52
58
  return { roster: this.roster(), history: this.history(20) };
53
59
  }
@@ -162,3 +168,17 @@ export function getOrCreateChannel(id) {
162
168
  }
163
169
  return ch;
164
170
  }
171
+ export function listActiveChannels(retentionFor) {
172
+ return [...channels.values()]
173
+ .filter((c) => c.size() > 0 || c.firstJoinedAt !== null)
174
+ .map((c) => ({
175
+ id: c.id,
176
+ retention: retentionFor(c.id),
177
+ roster: c.roster(),
178
+ agent_count: c.size(),
179
+ message_count: c.history(100).length,
180
+ first_joined_at: c.firstJoinedAt,
181
+ last_activity_at: c.lastActivityAt,
182
+ }))
183
+ .sort((a, b) => b.last_activity_at - a.last_activity_at);
184
+ }
package/dist/cli.js CHANGED
@@ -14,6 +14,8 @@ options:
14
14
  --host <addr> interface to bind (default: 127.0.0.1)
15
15
  --token <secret> require Bearer token on /mcp/* requests
16
16
  (required when --host is not 127.0.0.1 or localhost)
17
+ --admin-token <s> enable /admin dashboard with this token
18
+ (metadata only — never exposes message content)
17
19
  --data <path> channels.json path (default: ~/.rogerrat/channels.json)
18
20
  --origin <url> public origin advertised in connect snippets
19
21
  (default: http://<host>:<port>)
@@ -44,6 +46,7 @@ function main() {
44
46
  port: { type: "string" },
45
47
  host: { type: "string" },
46
48
  token: { type: "string" },
49
+ "admin-token": { type: "string" },
47
50
  data: { type: "string" },
48
51
  origin: { type: "string" },
49
52
  help: { type: "boolean", short: "h" },
@@ -64,6 +67,7 @@ function main() {
64
67
  const port = Number(parsed.values.port ?? 7424);
65
68
  const host = parsed.values.host ?? "127.0.0.1";
66
69
  const token = parsed.values.token;
70
+ const adminToken = parsed.values["admin-token"];
67
71
  const dataPath = parsed.values.data ?? join(homedir(), ".rogerrat", "channels.json");
68
72
  const origin = parsed.values.origin ?? `http://${host === "0.0.0.0" ? "127.0.0.1" : host}:${port}`;
69
73
  if (!isLocalHost(host) && !token) {
@@ -75,12 +79,14 @@ function main() {
75
79
  publicOrigin: origin,
76
80
  authRequired: !!token,
77
81
  staticToken: token,
82
+ adminToken,
78
83
  });
79
- console.log(`rogerrat ${process.env.npm_package_version ?? "0.1.0"} — local walkie-talkie hub`);
84
+ console.log(`rogerrat ${process.env.npm_package_version ?? "0.1.1"} — local walkie-talkie hub`);
80
85
  console.log(` listening on http://${host}:${port}`);
81
86
  console.log(` public origin ${origin}`);
82
87
  console.log(` data file ${dataPath}`);
83
88
  console.log(` auth ${token ? "required (bearer token)" : "disabled (local-only)"}`);
89
+ console.log(` admin UI ${adminToken ? `enabled at ${origin}/admin` : "disabled (use --admin-token to enable)"}`);
84
90
  console.log("");
85
91
  console.log(`install once in your AI client:`);
86
92
  console.log(` claude mcp add --transport http rogerrat ${origin}/mcp${token ? ` --header "Authorization: Bearer ${token}"` : ""}`);
package/dist/landing.js CHANGED
@@ -1,11 +1,13 @@
1
+ const FAVICON_SVG = `<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'><rect width='32' height='32' rx='6' fill='%231a1a1a'/><path d='M 9 7 Q 16 4 23 7' stroke='%23d6541f' stroke-width='1.5' fill='none' stroke-linecap='round'/><path d='M 7 10 Q 16 5 25 10' stroke='%23d6541f' stroke-width='1.5' fill='none' stroke-linecap='round' opacity='0.5'/><ellipse cx='11' cy='14' rx='2' ry='3' fill='%23f4ede0' transform='rotate(-15 11 14)'/><ellipse cx='21' cy='14' rx='2' ry='3' fill='%23f4ede0' transform='rotate(15 21 14)'/><ellipse cx='16' cy='22' rx='8' ry='6.5' fill='%23f4ede0'/><circle cx='13' cy='21' r='1.2' fill='%231a1a1a'/><circle cx='19' cy='21' r='1.2' fill='%231a1a1a'/><ellipse cx='16' cy='25' rx='1.5' ry='1' fill='%23d6541f'/></svg>`;
1
2
  export function landingHtml() {
2
3
  return `<!doctype html>
3
4
  <html lang="en">
4
5
  <head>
5
6
  <meta charset="utf-8" />
6
7
  <meta name="viewport" content="width=device-width, initial-scale=1" />
7
- <title>RogerRat — walkie-talkie for your Claude agents</title>
8
+ <title>RogerRat — walkie-talkie for your AI agents</title>
8
9
  <meta name="description" content="A hosted MCP server that lets multiple AI coding agents (Claude Code, Cursor, Cline, Claude Desktop) talk to each other in real time. One command. No DNS. No tunnels. Just radio." />
10
+ <link rel="icon" type="image/svg+xml" href="data:image/svg+xml,${FAVICON_SVG}" />
9
11
  <style>
10
12
  :root {
11
13
  --bg: #f4ede0;
@@ -26,21 +28,48 @@ export function landingHtml() {
26
28
  }
27
29
  .wrap { max-width: 780px; margin: 0 auto; padding: 48px 24px 96px; }
28
30
  header { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 56px; }
29
- .logo { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; }
30
- .logo::before { content: "📻 "; }
31
+ .logo { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; display: inline-flex; align-items: center; gap: 8px; }
32
+ .logo svg { width: 24px; height: 24px; }
31
33
  nav a { color: var(--dim); text-decoration: none; margin-left: 16px; font-size: 13px; }
32
34
  nav a:hover { color: var(--ink); }
33
35
  h1 { font-size: 44px; line-height: 1.05; letter-spacing: -0.03em; margin: 0 0 16px; font-weight: 700; }
34
36
  .tagline { font-size: 18px; color: var(--dim); margin: 0 0 32px; }
35
- .ratbox {
36
- border: 1px solid var(--line);
37
- background: var(--paper);
38
- padding: 20px;
39
- margin: 24px 0 40px;
40
- white-space: pre;
41
- font-size: 12px;
42
- overflow-x: auto;
43
- line-height: 1.2;
37
+ .hero {
38
+ display: flex;
39
+ align-items: center;
40
+ justify-content: center;
41
+ padding: 32px 0;
42
+ margin: 8px 0 32px;
43
+ }
44
+ .hero svg { width: 220px; height: 220px; }
45
+ .stats {
46
+ display: flex;
47
+ gap: 0;
48
+ margin: 0 0 40px;
49
+ border-top: 1px solid var(--line);
50
+ border-bottom: 1px solid var(--line);
51
+ }
52
+ .stat {
53
+ flex: 1;
54
+ padding: 16px 8px;
55
+ text-align: center;
56
+ border-right: 1px solid var(--line);
57
+ }
58
+ .stat:last-child { border-right: none; }
59
+ .stat-num {
60
+ font-size: 24px;
61
+ font-weight: 700;
62
+ letter-spacing: -0.02em;
63
+ color: var(--ink);
64
+ font-variant-numeric: tabular-nums;
65
+ }
66
+ .stat-label {
67
+ display: block;
68
+ font-size: 11px;
69
+ text-transform: uppercase;
70
+ letter-spacing: 0.08em;
71
+ color: var(--dim);
72
+ margin-top: 4px;
44
73
  }
45
74
  .cta {
46
75
  margin: 32px 0 48px;
@@ -127,7 +156,20 @@ export function landingHtml() {
127
156
  <body>
128
157
  <div class="wrap">
129
158
  <header>
130
- <div class="logo">rogerrat</div>
159
+ <div class="logo">
160
+ <svg viewBox="0 0 32 32" aria-hidden="true">
161
+ <rect width="32" height="32" rx="6" fill="#1a1a1a"/>
162
+ <path d="M 9 7 Q 16 4 23 7" stroke="#d6541f" stroke-width="1.5" fill="none" stroke-linecap="round"/>
163
+ <path d="M 7 10 Q 16 5 25 10" stroke="#d6541f" stroke-width="1.5" fill="none" stroke-linecap="round" opacity="0.5"/>
164
+ <ellipse cx="11" cy="14" rx="2" ry="3" fill="#f4ede0" transform="rotate(-15 11 14)"/>
165
+ <ellipse cx="21" cy="14" rx="2" ry="3" fill="#f4ede0" transform="rotate(15 21 14)"/>
166
+ <ellipse cx="16" cy="22" rx="8" ry="6.5" fill="#f4ede0"/>
167
+ <circle cx="13" cy="21" r="1.2" fill="#1a1a1a"/>
168
+ <circle cx="19" cy="21" r="1.2" fill="#1a1a1a"/>
169
+ <ellipse cx="16" cy="25" rx="1.5" ry="1" fill="#d6541f"/>
170
+ </svg>
171
+ <span>rogerrat</span>
172
+ </div>
131
173
  <nav>
132
174
  <a href="#how">how it works</a>
133
175
  <a href="/docs/quickstart">docs</a>
@@ -137,19 +179,67 @@ export function landingHtml() {
137
179
  <h1>Walkie-talkie for your AI agents.</h1>
138
180
  <p class="tagline">A hosted MCP server. Two Claude Codes, Cursors, or Clines can chat across machines. One command. No DNS. No tunnels. Just radio.</p>
139
181
 
140
- <div class="ratbox"> ___
141
- .-' \`-. _.-._
142
- / .---. \\ (( o ))
143
- | / .-. \\ | \\\\___//
144
- | | ( ) | | | |
145
- | | \`-' | | / \\
146
- \\ '.___.' / / )-( \\
147
- \`'-...-'\` '--' \`--'
148
- roger, ten-four,
149
- rat over. good buddy.</div>
182
+ <div class="hero" aria-hidden="true">
183
+ <svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg" fill="none">
184
+ <!-- radio waves -->
185
+ <path d="M 60 22 Q 100 4 140 22" stroke="#d6541f" stroke-width="4" stroke-linecap="round"/>
186
+ <path d="M 44 36 Q 100 8 156 36" stroke="#d6541f" stroke-width="4" stroke-linecap="round" opacity="0.55"/>
187
+ <path d="M 28 50 Q 100 12 172 50" stroke="#d6541f" stroke-width="4" stroke-linecap="round" opacity="0.25"/>
188
+ <!-- antenna boom -->
189
+ <line x1="150" y1="74" x2="170" y2="34" stroke="#1a1a1a" stroke-width="4" stroke-linecap="round"/>
190
+ <circle cx="170" cy="34" r="5" fill="#d6541f" stroke="#1a1a1a" stroke-width="2"/>
191
+ <!-- headphone band -->
192
+ <path d="M 36 96 Q 100 38 164 96" stroke="#1a1a1a" stroke-width="6" fill="none" stroke-linecap="round"/>
193
+ <!-- left earcup -->
194
+ <rect x="22" y="92" width="28" height="36" rx="7" fill="#1a1a1a"/>
195
+ <rect x="28" y="98" width="16" height="24" rx="4" fill="#d6541f"/>
196
+ <circle cx="36" cy="110" r="3" fill="#1a1a1a"/>
197
+ <!-- right earcup -->
198
+ <rect x="150" y="92" width="28" height="36" rx="7" fill="#1a1a1a"/>
199
+ <rect x="156" y="98" width="16" height="24" rx="4" fill="#d6541f"/>
200
+ <circle cx="164" cy="110" r="3" fill="#1a1a1a"/>
201
+ <!-- rat ears peeking up -->
202
+ <ellipse cx="76" cy="64" rx="8" ry="12" fill="#fffaef" stroke="#1a1a1a" stroke-width="3" transform="rotate(-15 76 64)"/>
203
+ <ellipse cx="76" cy="66" rx="3" ry="6" fill="#d6541f" opacity="0.45" transform="rotate(-15 76 66)"/>
204
+ <ellipse cx="124" cy="64" rx="8" ry="12" fill="#fffaef" stroke="#1a1a1a" stroke-width="3" transform="rotate(15 124 64)"/>
205
+ <ellipse cx="124" cy="66" rx="3" ry="6" fill="#d6541f" opacity="0.45" transform="rotate(15 124 66)"/>
206
+ <!-- rat face -->
207
+ <ellipse cx="100" cy="120" rx="44" ry="38" fill="#fffaef" stroke="#1a1a1a" stroke-width="3.5"/>
208
+ <!-- eyes -->
209
+ <circle cx="84" cy="114" r="5" fill="#1a1a1a"/>
210
+ <circle cx="116" cy="114" r="5" fill="#1a1a1a"/>
211
+ <circle cx="86" cy="112" r="1.6" fill="#fffaef"/>
212
+ <circle cx="118" cy="112" r="1.6" fill="#fffaef"/>
213
+ <!-- snout & nose -->
214
+ <ellipse cx="100" cy="140" rx="10" ry="7" fill="#fffaef" stroke="#1a1a1a" stroke-width="2.5"/>
215
+ <ellipse cx="100" cy="138" rx="4" ry="3" fill="#d6541f"/>
216
+ <path d="M 92 146 Q 100 152 108 146" stroke="#1a1a1a" stroke-width="2" fill="none" stroke-linecap="round"/>
217
+ <!-- whiskers -->
218
+ <path d="M 60 134 L 36 130" stroke="#1a1a1a" stroke-width="2" stroke-linecap="round"/>
219
+ <path d="M 60 140 L 36 142" stroke="#1a1a1a" stroke-width="2" stroke-linecap="round"/>
220
+ <path d="M 140 134 L 164 130" stroke="#1a1a1a" stroke-width="2" stroke-linecap="round"/>
221
+ <path d="M 140 140 L 164 142" stroke="#1a1a1a" stroke-width="2" stroke-linecap="round"/>
222
+ </svg>
223
+ </div>
224
+
225
+ <div class="stats" aria-label="Service stats">
226
+ <div class="stat"><div class="stat-num" id="stat-channels">—</div><span class="stat-label">channels opened</span></div>
227
+ <div class="stat"><div class="stat-num" id="stat-joins">—</div><span class="stat-label">agents joined</span></div>
228
+ <div class="stat"><div class="stat-num" id="stat-messages">—</div><span class="stat-label">messages sent</span></div>
229
+ </div>
150
230
 
151
231
  <div class="cta">
152
232
  <p style="margin-top:0"><strong>Create a private channel</strong> — pick your client below and share the snippet with another agent.</p>
233
+ <div style="display:flex;gap:12px;align-items:center;margin-bottom:12px;flex-wrap:wrap">
234
+ <label style="font-size:13px;color:var(--dim)">retention:
235
+ <select id="retention" style="padding:6px 8px;border:1px solid var(--line);background:var(--paper);font-family:inherit;font-size:13px;margin-left:6px">
236
+ <option value="none" selected>none — ephemeral (default)</option>
237
+ <option value="metadata">metadata — joins/leaves/sizes</option>
238
+ <option value="prompts">prompts — first msg per agent</option>
239
+ <option value="full">full — keep everything</option>
240
+ </select>
241
+ </label>
242
+ </div>
153
243
  <button id="create">Create channel</button>
154
244
 
155
245
  <div class="out" id="out" hidden>
@@ -232,6 +322,12 @@ export function landingHtml() {
232
322
  </div>
233
323
 
234
324
  <script>
325
+ fetch('/api/stats').then(r => r.json()).then(s => {
326
+ document.getElementById('stat-channels').textContent = (s.channels_created ?? 0).toLocaleString();
327
+ document.getElementById('stat-joins').textContent = (s.joins_total ?? 0).toLocaleString();
328
+ document.getElementById('stat-messages').textContent = (s.messages_total ?? 0).toLocaleString();
329
+ }).catch(() => {});
330
+
235
331
  const btn = document.getElementById('create');
236
332
  const out = document.getElementById('out');
237
333
  const tabsRoot = out.querySelector('.tabs');
@@ -248,7 +344,12 @@ export function landingHtml() {
248
344
  btn.disabled = true;
249
345
  btn.textContent = 'Creating…';
250
346
  try {
251
- const r = await fetch('/api/channels', { method: 'POST' });
347
+ const retention = document.getElementById('retention').value;
348
+ const r = await fetch('/api/channels', {
349
+ method: 'POST',
350
+ headers: { 'Content-Type': 'application/json' },
351
+ body: JSON.stringify({ retention }),
352
+ });
252
353
  if (!r.ok) throw new Error('http ' + r.status);
253
354
  const j = await r.json();
254
355
  document.getElementById('channel').textContent = j.channel_id;
package/dist/mcp.js CHANGED
@@ -1,7 +1,9 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
  import { getOrCreateChannel } from "./channel.js";
3
3
  import { buildConnectInfo } from "./connect.js";
4
- import { createChannel } from "./store.js";
4
+ import { recordJoin as statsRecordJoin, recordMessage as statsRecordMessage } from "./stats.js";
5
+ import { createChannel, getChannelRetention } from "./store.js";
6
+ import { isRetention, recordJoin as transcriptRecordJoin, recordLeave as transcriptRecordLeave, recordMessage as transcriptRecordMessage, } from "./transcripts.js";
5
7
  const PROTOCOL_VERSION = "2025-03-26";
6
8
  const SERVER_INFO = { name: "rogerrat", version: "0.1.0" };
7
9
  const LOOP_INSTRUCTIONS = [
@@ -83,8 +85,17 @@ const CHANNEL_TOOLS = [
83
85
  const BOOTSTRAP_TOOLS = [
84
86
  {
85
87
  name: "create_channel",
86
- description: "Create a new RogerRat channel. Returns the channel id, join token, the MCP URL, and a ready-to-paste connect command for Claude Code (and JSON snippets for Cursor / Cline / Claude Desktop / Anthropic SDK). Share the connect info with the other agent(s) that should join the channel. Anyone holding the token can join treat it like a password.",
87
- inputSchema: { type: "object", properties: {} },
88
+ description: "Create a new RogerRat channel. Returns the channel id, join token, MCP URL, and connect snippets for Claude Code / Cursor / Cline / Claude Desktop / Anthropic SDK. Anyone holding the token can join — treat it like a password. Optional retention controls whether the server keeps a transcript: 'none' (default, ephemeral), 'metadata' (joins/leaves/sizes, no content), 'prompts' (first message per agent only), 'full' (everything). Transcripts are downloadable via GET /api/channels/<id>/transcript with the channel token.",
89
+ inputSchema: {
90
+ type: "object",
91
+ properties: {
92
+ retention: {
93
+ type: "string",
94
+ enum: ["none", "metadata", "prompts", "full"],
95
+ description: "Server-side transcript retention. Default: 'none' (ephemeral).",
96
+ },
97
+ },
98
+ },
88
99
  },
89
100
  ];
90
101
  const sessions = new Map();
@@ -113,6 +124,8 @@ async function callChannelTool(channel, sessionId, name, args) {
113
124
  case "join": {
114
125
  const callsign = String(args.callsign ?? "");
115
126
  const { roster, history } = channel.join(sessionId, callsign);
127
+ statsRecordJoin();
128
+ transcriptRecordJoin(channel.id, getChannelRetention(channel.id), callsign);
116
129
  const body = [
117
130
  `Joined channel ${channel.id} as ${callsign}.`,
118
131
  `Roster (${roster.length}): ${roster.join(", ")}`,
@@ -129,6 +142,8 @@ async function callChannelTool(channel, sessionId, name, args) {
129
142
  const to = String(args.to ?? "");
130
143
  const message = String(args.message ?? "");
131
144
  const msg = channel.send(sessionId, to, message);
145
+ statsRecordMessage();
146
+ transcriptRecordMessage(channel.id, getChannelRetention(channel.id), msg);
132
147
  return textContent(`sent #${msg.id} to ${msg.to}`);
133
148
  }
134
149
  case "listen": {
@@ -149,24 +164,34 @@ async function callChannelTool(channel, sessionId, name, args) {
149
164
  return textContent(formatMessages(channel.history(n)));
150
165
  }
151
166
  case "leave": {
167
+ const cs = channel.callsignOf(sessionId);
152
168
  channel.leave(sessionId);
169
+ if (cs)
170
+ transcriptRecordLeave(channel.id, getChannelRetention(channel.id), cs);
153
171
  return textContent("left channel");
154
172
  }
155
173
  default:
156
174
  throw new Error(`unknown tool: ${name}`);
157
175
  }
158
176
  }
159
- function callBootstrapTool(name, _args, publicOrigin) {
177
+ function callBootstrapTool(name, args, publicOrigin) {
160
178
  if (name !== "create_channel") {
161
179
  throw new Error(`unknown tool in bootstrap mode: ${name}`);
162
180
  }
163
- const { id, token } = createChannel();
181
+ const requested = typeof args.retention === "string" ? args.retention : "none";
182
+ if (!isRetention(requested)) {
183
+ throw new Error(`invalid retention: ${requested} (must be one of none|metadata|prompts|full)`);
184
+ }
185
+ const retention = requested;
186
+ const { id, token } = createChannel({ retention });
164
187
  const info = buildConnectInfo(id, token, publicOrigin);
165
188
  const text = [
166
189
  `Created channel: ${id}`,
190
+ `Retention: ${retention}${retention === "none" ? " (ephemeral, default)" : ""}`,
167
191
  "",
168
192
  `MCP URL: ${info.mcp_url}`,
169
193
  `Token: ${token}`,
194
+ retention !== "none" ? `Transcript: ${publicOrigin}/api/channels/${id}/transcript (auth: Bearer ${token})` : "",
170
195
  "",
171
196
  "─── Share with another agent ───",
172
197
  "",
@@ -178,12 +203,12 @@ function callBootstrapTool(name, _args, publicOrigin) {
178
203
  "",
179
204
  "Anthropic SDK (mcp_servers entry):",
180
205
  JSON.stringify(info.connect.anthropic_sdk, null, 2),
181
- "",
182
- `Web view: ${publicOrigin}/c/${id} (status only, no traffic)`,
183
- ].join("\n");
206
+ ]
207
+ .filter(Boolean)
208
+ .join("\n");
184
209
  return {
185
210
  ...textContent(text),
186
- structuredContent: info,
211
+ structuredContent: { ...info, retention },
187
212
  };
188
213
  }
189
214
  export async function handleMcpRequest(channelId, rawMessage, incomingSessionId, publicOrigin) {
package/dist/server.js CHANGED
@@ -3,9 +3,11 @@ import { createApp } from "./app.js";
3
3
  const PORT = Number(process.env.PORT ?? 7424);
4
4
  const HOST = process.env.HOST ?? "127.0.0.1";
5
5
  const PUBLIC_ORIGIN = process.env.PUBLIC_ORIGIN ?? "https://rogerrat.chat";
6
+ const ADMIN_TOKEN = process.env.ROGERRAT_ADMIN_TOKEN || undefined;
6
7
  const app = createApp({
7
8
  publicOrigin: PUBLIC_ORIGIN,
8
9
  authRequired: true,
10
+ adminToken: ADMIN_TOKEN,
9
11
  });
10
- console.log(`[rogerrat] listening on http://${HOST}:${PORT} (public origin: ${PUBLIC_ORIGIN})`);
12
+ console.log(`[rogerrat] listening on http://${HOST}:${PORT} (public origin: ${PUBLIC_ORIGIN}, admin ${ADMIN_TOKEN ? "enabled" : "disabled"})`);
11
13
  serve({ fetch: app.fetch, hostname: HOST, port: PORT });
package/dist/stats.js ADDED
@@ -0,0 +1,67 @@
1
+ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
2
+ import { dirname } from "node:path";
3
+ const STATS_PATH = process.env.ROGERRAT_STATS ?? "./data/stats.json";
4
+ let stats = { channels_created: 0, joins_total: 0, messages_total: 0, started_at: Date.now() };
5
+ let loaded = false;
6
+ let dirty = false;
7
+ let saveTimer = null;
8
+ function load() {
9
+ if (loaded)
10
+ return;
11
+ loaded = true;
12
+ try {
13
+ if (existsSync(STATS_PATH)) {
14
+ const parsed = JSON.parse(readFileSync(STATS_PATH, "utf8"));
15
+ stats = {
16
+ channels_created: parsed.channels_created ?? 0,
17
+ joins_total: parsed.joins_total ?? 0,
18
+ messages_total: parsed.messages_total ?? 0,
19
+ started_at: parsed.started_at ?? Date.now(),
20
+ };
21
+ }
22
+ }
23
+ catch (err) {
24
+ console.error("[stats] failed to load:", err);
25
+ }
26
+ }
27
+ function scheduleSave() {
28
+ dirty = true;
29
+ if (saveTimer)
30
+ return;
31
+ saveTimer = setTimeout(() => {
32
+ saveTimer = null;
33
+ if (!dirty)
34
+ return;
35
+ dirty = false;
36
+ try {
37
+ const dir = dirname(STATS_PATH);
38
+ if (!existsSync(dir))
39
+ mkdirSync(dir, { recursive: true });
40
+ const tmp = `${STATS_PATH}.tmp`;
41
+ writeFileSync(tmp, JSON.stringify(stats, null, 2));
42
+ renameSync(tmp, STATS_PATH);
43
+ }
44
+ catch (err) {
45
+ console.error("[stats] failed to save:", err);
46
+ }
47
+ }, 5000);
48
+ }
49
+ export function recordChannelCreated() {
50
+ load();
51
+ stats.channels_created++;
52
+ scheduleSave();
53
+ }
54
+ export function recordJoin() {
55
+ load();
56
+ stats.joins_total++;
57
+ scheduleSave();
58
+ }
59
+ export function recordMessage() {
60
+ load();
61
+ stats.messages_total++;
62
+ scheduleSave();
63
+ }
64
+ export function getStats() {
65
+ load();
66
+ return { ...stats };
67
+ }
package/dist/store.js CHANGED
@@ -2,6 +2,8 @@ import { createHash } from "node:crypto";
2
2
  import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
3
3
  import { dirname } from "node:path";
4
4
  import { generateChannelId, generateToken } from "./ids.js";
5
+ import { recordChannelCreated as statsRecordChannelCreated } from "./stats.js";
6
+ import { isRetention, recordChannelCreated as transcriptRecordChannelCreated } from "./transcripts.js";
5
7
  const DB_PATH = process.env.ROGERRAT_DB ?? "./data/channels.json";
6
8
  let channels = new Map();
7
9
  let loaded = false;
@@ -16,7 +18,15 @@ function ensureLoaded() {
16
18
  if (existsSync(DB_PATH)) {
17
19
  const raw = readFileSync(DB_PATH, "utf8");
18
20
  const arr = JSON.parse(raw);
19
- channels = new Map(arr.map((r) => [r.id, r]));
21
+ channels = new Map(arr.map((r) => [
22
+ r.id,
23
+ {
24
+ id: r.id,
25
+ tokenHash: r.tokenHash,
26
+ createdAt: r.createdAt,
27
+ retention: isRetention(r.retention) ? r.retention : "none",
28
+ },
29
+ ]));
20
30
  }
21
31
  }
22
32
  catch (err) {
@@ -31,16 +41,19 @@ function persist() {
31
41
  writeFileSync(tmp, JSON.stringify([...channels.values()], null, 2));
32
42
  renameSync(tmp, DB_PATH);
33
43
  }
34
- export function createChannel() {
44
+ export function createChannel(opts = {}) {
35
45
  ensureLoaded();
46
+ const retention = opts.retention ?? "none";
36
47
  let id;
37
48
  do {
38
49
  id = generateChannelId();
39
50
  } while (channels.has(id));
40
51
  const token = generateToken();
41
- channels.set(id, { id, tokenHash: hashToken(token), createdAt: Date.now() });
52
+ channels.set(id, { id, tokenHash: hashToken(token), createdAt: Date.now(), retention });
42
53
  persist();
43
- return { id, token };
54
+ statsRecordChannelCreated();
55
+ transcriptRecordChannelCreated(id, retention);
56
+ return { id, token, retention };
44
57
  }
45
58
  export function verifyChannel(id, token) {
46
59
  ensureLoaded();
@@ -53,3 +66,11 @@ export function channelExists(id) {
53
66
  ensureLoaded();
54
67
  return channels.has(id);
55
68
  }
69
+ export function getChannelRecord(id) {
70
+ ensureLoaded();
71
+ return channels.get(id);
72
+ }
73
+ export function getChannelRetention(id) {
74
+ ensureLoaded();
75
+ return channels.get(id)?.retention ?? "none";
76
+ }
@@ -0,0 +1,68 @@
1
+ import { appendFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ export const RETENTION_VALUES = ["none", "metadata", "prompts", "full"];
4
+ export function isRetention(v) {
5
+ return typeof v === "string" && RETENTION_VALUES.includes(v);
6
+ }
7
+ const TRANSCRIPTS_DIR = process.env.ROGERRAT_TRANSCRIPTS ?? "./data/transcripts";
8
+ const firstSenderByChannel = new Map();
9
+ function pathFor(channelId) {
10
+ return join(TRANSCRIPTS_DIR, `${channelId}.jsonl`);
11
+ }
12
+ function ensureDir() {
13
+ if (!existsSync(TRANSCRIPTS_DIR))
14
+ mkdirSync(TRANSCRIPTS_DIR, { recursive: true });
15
+ }
16
+ function appendLine(channelId, event) {
17
+ ensureDir();
18
+ appendFileSync(pathFor(channelId), JSON.stringify(event) + "\n");
19
+ }
20
+ export function recordChannelCreated(channelId, retention) {
21
+ if (retention === "none")
22
+ return;
23
+ appendLine(channelId, { ts: Date.now(), type: "channel_created", retention });
24
+ }
25
+ export function recordJoin(channelId, retention, callsign) {
26
+ if (retention === "none")
27
+ return;
28
+ appendLine(channelId, { ts: Date.now(), type: "join", callsign });
29
+ }
30
+ export function recordLeave(channelId, retention, callsign) {
31
+ if (retention === "none")
32
+ return;
33
+ appendLine(channelId, { ts: Date.now(), type: "leave", callsign });
34
+ }
35
+ export function recordMessage(channelId, retention, msg) {
36
+ if (retention === "none")
37
+ return;
38
+ if (retention === "metadata") {
39
+ appendLine(channelId, {
40
+ ts: msg.at,
41
+ type: "message_meta",
42
+ from: msg.from,
43
+ to: msg.to,
44
+ bytes: msg.text.length,
45
+ });
46
+ return;
47
+ }
48
+ if (retention === "prompts") {
49
+ const seen = firstSenderByChannel.get(channelId) ?? new Set();
50
+ if (seen.has(msg.from))
51
+ return;
52
+ seen.add(msg.from);
53
+ firstSenderByChannel.set(channelId, seen);
54
+ }
55
+ appendLine(channelId, { ts: msg.at, type: "message", from: msg.from, to: msg.to, text: msg.text });
56
+ }
57
+ export function readTranscript(channelId, limit = 1000) {
58
+ const p = pathFor(channelId);
59
+ if (!existsSync(p))
60
+ return [];
61
+ const lines = readFileSync(p, "utf8").trim().split("\n").filter(Boolean);
62
+ const events = lines.map((line) => JSON.parse(line));
63
+ const clamped = Math.max(1, Math.min(10000, Math.floor(limit)));
64
+ return events.slice(-clamped);
65
+ }
66
+ export function hasTranscript(channelId) {
67
+ return existsSync(pathFor(channelId));
68
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rogerrat",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Walkie-talkie MCP server for AI coding agents. Two Claudes (or Cursor, Cline, Claude Desktop) talk to each other over a hosted hub or your own localhost.",
5
5
  "keywords": [
6
6
  "mcp",