rogerrat 0.1.0 → 0.1.1
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 +78 -33
- package/dist/admin.js +292 -0
- package/dist/app.js +20 -0
- package/dist/channel.js +20 -1
- package/dist/cli.js +7 -1
- package/dist/landing.js +109 -23
- package/dist/mcp.js +3 -0
- package/dist/server.js +3 -1
- package/dist/stats.js +67 -0
- package/dist/store.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,12 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="./assets/logo.svg" width="180" alt="RogerRat" />
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
|
9
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
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
|
|
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 (
|
|
52
|
+
## Quickstart — local (`npx`)
|
|
42
53
|
|
|
43
54
|
```bash
|
|
44
55
|
npx rogerrat
|
|
45
56
|
# → http://127.0.0.1:7424
|
|
46
57
|
|
|
47
|
-
#
|
|
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,53 @@ 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
|
|
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
|
|
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,
|
|
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.
|
|
85
123
|
|
|
86
124
|
## Safety
|
|
87
125
|
|
|
88
126
|
Anything an agent reads from the channel is **untrusted input**. If you give
|
|
89
127
|
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
|
|
91
|
-
|
|
92
|
-
|
|
128
|
+
the channel can ask it to do things. Treat channel traffic like prompts from a
|
|
129
|
+
stranger on the internet. Don't put sensitive data into channels you wouldn't
|
|
130
|
+
post on a public board.
|
|
93
131
|
|
|
94
|
-
## Self-hosting
|
|
132
|
+
## Self-hosting
|
|
95
133
|
|
|
96
134
|
The hosted instance at rogerrat.chat is a Node process behind Caddy
|
|
97
|
-
(Let's Encrypt). See [deploy
|
|
98
|
-
snippet
|
|
135
|
+
(Let's Encrypt). See [`deploy/`](./deploy/) for the systemd unit and Caddyfile
|
|
136
|
+
snippet — meant as a recipe, not a constraint. Anything that can reverse-proxy
|
|
137
|
+
HTTP and route to a Node process works.
|
|
99
138
|
|
|
100
139
|
## Development
|
|
101
140
|
|
|
@@ -105,6 +144,12 @@ cd rogerrat && npm install
|
|
|
105
144
|
npm run dev # tsx watch on src/server.ts
|
|
106
145
|
```
|
|
107
146
|
|
|
147
|
+
## Related
|
|
148
|
+
|
|
149
|
+
- [suruseas/walkie-talkie](https://github.com/suruseas/walkie-talkie) — the
|
|
150
|
+
inspiration. Local-first by design. RogerRat is the hosted-friendly variant
|
|
151
|
+
with a simpler transport (no stdio bridge).
|
|
152
|
+
|
|
108
153
|
## License
|
|
109
154
|
|
|
110
|
-
MIT.
|
|
155
|
+
MIT. See [`LICENSE`](./LICENSE).
|
package/dist/admin.js
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
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>Roster</th>
|
|
182
|
+
<th>Msgs</th>
|
|
183
|
+
<th>Opened</th>
|
|
184
|
+
<th>Last activity</th>
|
|
185
|
+
</tr>
|
|
186
|
+
</thead>
|
|
187
|
+
<tbody id="rows">
|
|
188
|
+
<tr><td colspan="5" class="empty">Loading…</td></tr>
|
|
189
|
+
</tbody>
|
|
190
|
+
</table>
|
|
191
|
+
</div>
|
|
192
|
+
|
|
193
|
+
<footer>
|
|
194
|
+
auto-refreshes every 5s · message content is never exposed by this page, only metadata · <a href="/">← landing</a>
|
|
195
|
+
</footer>
|
|
196
|
+
</div>
|
|
197
|
+
|
|
198
|
+
<script>
|
|
199
|
+
const KEY = 'rogerrat_admin_token';
|
|
200
|
+
let token = sessionStorage.getItem(KEY) || '';
|
|
201
|
+
const $ = (id) => document.getElementById(id);
|
|
202
|
+
|
|
203
|
+
function fmtAgo(ts) {
|
|
204
|
+
if (!ts) return '—';
|
|
205
|
+
const s = Math.max(0, Math.floor((Date.now() - ts) / 1000));
|
|
206
|
+
if (s < 60) return s + 's ago';
|
|
207
|
+
if (s < 3600) return Math.floor(s / 60) + 'm ago';
|
|
208
|
+
if (s < 86400) return Math.floor(s / 3600) + 'h ago';
|
|
209
|
+
return Math.floor(s / 86400) + 'd ago';
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
async function load() {
|
|
213
|
+
if (!token) { showAuthGate(); return; }
|
|
214
|
+
try {
|
|
215
|
+
const [statsR, chR] = await Promise.all([
|
|
216
|
+
fetch('/api/stats', { headers: { Authorization: 'Bearer ' + token } }),
|
|
217
|
+
fetch('/api/admin/channels', { headers: { Authorization: 'Bearer ' + token } }),
|
|
218
|
+
]);
|
|
219
|
+
if (chR.status === 401) {
|
|
220
|
+
sessionStorage.removeItem(KEY);
|
|
221
|
+
token = '';
|
|
222
|
+
showAuthGate('Invalid or expired token.');
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const stats = await statsR.json();
|
|
226
|
+
const data = await chR.json();
|
|
227
|
+
renderStats(stats, data.channels);
|
|
228
|
+
renderRows(data.channels);
|
|
229
|
+
$('dashboard').hidden = false;
|
|
230
|
+
$('auth-gate').hidden = true;
|
|
231
|
+
$('updated').textContent = 'updated ' + new Date().toLocaleTimeString();
|
|
232
|
+
} catch (e) {
|
|
233
|
+
$('updated').textContent = 'error: ' + e.message;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function renderStats(stats, channels) {
|
|
238
|
+
$('lt-channels').textContent = stats.channels_created.toLocaleString();
|
|
239
|
+
$('lt-joins').textContent = stats.joins_total.toLocaleString();
|
|
240
|
+
$('lt-messages').textContent = stats.messages_total.toLocaleString();
|
|
241
|
+
$('active-channels').textContent = channels.filter(c => c.agent_count > 0).length;
|
|
242
|
+
$('active-agents').textContent = channels.reduce((sum, c) => sum + c.agent_count, 0);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function renderRows(channels) {
|
|
246
|
+
const rows = $('rows');
|
|
247
|
+
if (!channels.length) {
|
|
248
|
+
rows.innerHTML = '<tr><td colspan="5" class="empty">No active channels yet.</td></tr>';
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
rows.innerHTML = channels.map(c => {
|
|
252
|
+
const roster = c.roster.length
|
|
253
|
+
? c.roster.map(cs => '<span class="chip">' + esc(cs) + '</span>').join('')
|
|
254
|
+
: '<span style="color:var(--dim)">empty</span>';
|
|
255
|
+
const opened = c.first_joined_at ? fmtAgo(c.first_joined_at) : '—';
|
|
256
|
+
return '<tr>' +
|
|
257
|
+
'<td class="channel-id">' + esc(c.id) + '</td>' +
|
|
258
|
+
'<td>' + roster + '</td>' +
|
|
259
|
+
'<td>' + c.message_count + '</td>' +
|
|
260
|
+
'<td>' + opened + '</td>' +
|
|
261
|
+
'<td>' + fmtAgo(c.last_activity_at) + '</td>' +
|
|
262
|
+
'</tr>';
|
|
263
|
+
}).join('');
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function esc(s) {
|
|
267
|
+
return String(s).replace(/[&<>"']/g, ch => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[ch]));
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function showAuthGate(errMsg) {
|
|
271
|
+
$('dashboard').hidden = true;
|
|
272
|
+
$('auth-gate').hidden = false;
|
|
273
|
+
$('auth-err').textContent = errMsg || '';
|
|
274
|
+
$('auth-input').focus();
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
$('auth-submit').addEventListener('click', () => {
|
|
278
|
+
const v = $('auth-input').value.trim();
|
|
279
|
+
if (!v) return;
|
|
280
|
+
sessionStorage.setItem(KEY, v);
|
|
281
|
+
token = v;
|
|
282
|
+
$('auth-err').textContent = '';
|
|
283
|
+
load();
|
|
284
|
+
});
|
|
285
|
+
$('auth-input').addEventListener('keydown', (e) => { if (e.key === 'Enter') $('auth-submit').click(); });
|
|
286
|
+
|
|
287
|
+
load();
|
|
288
|
+
setInterval(load, 5000);
|
|
289
|
+
</script>
|
|
290
|
+
</body>
|
|
291
|
+
</html>`;
|
|
292
|
+
}
|
package/dist/app.js
CHANGED
|
@@ -1,16 +1,36 @@
|
|
|
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";
|
|
7
|
+
import { getStats } from "./stats.js";
|
|
5
8
|
import { channelExists, createChannel, verifyChannel } from "./store.js";
|
|
6
9
|
export function createApp(opts) {
|
|
7
10
|
const app = new Hono();
|
|
8
11
|
app.get("/", (c) => c.html(landingHtml()));
|
|
9
12
|
app.get("/healthz", (c) => c.text("ok"));
|
|
13
|
+
app.get("/api/stats", (c) => c.json(getStats()));
|
|
10
14
|
app.post("/api/channels", (c) => {
|
|
11
15
|
const { id, token } = createChannel();
|
|
12
16
|
return c.json(buildConnectInfo(id, token, opts.publicOrigin));
|
|
13
17
|
});
|
|
18
|
+
function requireAdmin(c) {
|
|
19
|
+
if (!opts.adminToken)
|
|
20
|
+
return c.json({ error: "admin disabled" }, 403);
|
|
21
|
+
const auth = c.req.header("authorization") ?? c.req.header("Authorization") ?? "";
|
|
22
|
+
const token = auth.startsWith("Bearer ") ? auth.slice(7).trim() : "";
|
|
23
|
+
if (token !== opts.adminToken)
|
|
24
|
+
return c.json({ error: "invalid admin token" }, 401);
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
app.get("/admin", (c) => c.html(adminHtml()));
|
|
28
|
+
app.get("/api/admin/channels", (c) => {
|
|
29
|
+
const denied = requireAdmin(c);
|
|
30
|
+
if (denied)
|
|
31
|
+
return denied;
|
|
32
|
+
return c.json({ channels: listActiveChannels() });
|
|
33
|
+
});
|
|
14
34
|
async function mcpHandler(c, channelId) {
|
|
15
35
|
if (channelId !== null) {
|
|
16
36
|
if (!channelExists(channelId))
|
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
|
-
|
|
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,16 @@ export function getOrCreateChannel(id) {
|
|
|
162
168
|
}
|
|
163
169
|
return ch;
|
|
164
170
|
}
|
|
171
|
+
export function listActiveChannels() {
|
|
172
|
+
return [...channels.values()]
|
|
173
|
+
.filter((c) => c.size() > 0 || c.firstJoinedAt !== null)
|
|
174
|
+
.map((c) => ({
|
|
175
|
+
id: c.id,
|
|
176
|
+
roster: c.roster(),
|
|
177
|
+
agent_count: c.size(),
|
|
178
|
+
message_count: c.history(100).length,
|
|
179
|
+
first_joined_at: c.firstJoinedAt,
|
|
180
|
+
last_activity_at: c.lastActivityAt,
|
|
181
|
+
}))
|
|
182
|
+
.sort((a, b) => b.last_activity_at - a.last_activity_at);
|
|
183
|
+
}
|
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.
|
|
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
|
|
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
|
|
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
|
-
.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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">
|
|
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,16 +179,54 @@ 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="
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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>
|
|
@@ -232,6 +312,12 @@ export function landingHtml() {
|
|
|
232
312
|
</div>
|
|
233
313
|
|
|
234
314
|
<script>
|
|
315
|
+
fetch('/api/stats').then(r => r.json()).then(s => {
|
|
316
|
+
document.getElementById('stat-channels').textContent = (s.channels_created ?? 0).toLocaleString();
|
|
317
|
+
document.getElementById('stat-joins').textContent = (s.joins_total ?? 0).toLocaleString();
|
|
318
|
+
document.getElementById('stat-messages').textContent = (s.messages_total ?? 0).toLocaleString();
|
|
319
|
+
}).catch(() => {});
|
|
320
|
+
|
|
235
321
|
const btn = document.getElementById('create');
|
|
236
322
|
const out = document.getElementById('out');
|
|
237
323
|
const tabsRoot = out.querySelector('.tabs');
|
package/dist/mcp.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { getOrCreateChannel } from "./channel.js";
|
|
3
3
|
import { buildConnectInfo } from "./connect.js";
|
|
4
|
+
import { recordJoin, recordMessage } from "./stats.js";
|
|
4
5
|
import { createChannel } from "./store.js";
|
|
5
6
|
const PROTOCOL_VERSION = "2025-03-26";
|
|
6
7
|
const SERVER_INFO = { name: "rogerrat", version: "0.1.0" };
|
|
@@ -113,6 +114,7 @@ async function callChannelTool(channel, sessionId, name, args) {
|
|
|
113
114
|
case "join": {
|
|
114
115
|
const callsign = String(args.callsign ?? "");
|
|
115
116
|
const { roster, history } = channel.join(sessionId, callsign);
|
|
117
|
+
recordJoin();
|
|
116
118
|
const body = [
|
|
117
119
|
`Joined channel ${channel.id} as ${callsign}.`,
|
|
118
120
|
`Roster (${roster.length}): ${roster.join(", ")}`,
|
|
@@ -129,6 +131,7 @@ async function callChannelTool(channel, sessionId, name, args) {
|
|
|
129
131
|
const to = String(args.to ?? "");
|
|
130
132
|
const message = String(args.message ?? "");
|
|
131
133
|
const msg = channel.send(sessionId, to, message);
|
|
134
|
+
recordMessage();
|
|
132
135
|
return textContent(`sent #${msg.id} to ${msg.to}`);
|
|
133
136
|
}
|
|
134
137
|
case "listen": {
|
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,7 @@ 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 } from "./stats.js";
|
|
5
6
|
const DB_PATH = process.env.ROGERRAT_DB ?? "./data/channels.json";
|
|
6
7
|
let channels = new Map();
|
|
7
8
|
let loaded = false;
|
|
@@ -40,6 +41,7 @@ export function createChannel() {
|
|
|
40
41
|
const token = generateToken();
|
|
41
42
|
channels.set(id, { id, tokenHash: hashToken(token), createdAt: Date.now() });
|
|
42
43
|
persist();
|
|
44
|
+
recordChannelCreated();
|
|
43
45
|
return { id, token };
|
|
44
46
|
}
|
|
45
47
|
export function verifyChannel(id, token) {
|
package/package.json
CHANGED