@santori/station 0.9.3 → 0.9.5
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 +6 -0
- package/dist/caller.js +7 -0
- package/dist/cli.js +47 -6
- package/dist/daemon.js +20 -8
- package/dist/guest.js +45 -0
- package/dist/home.js +2 -0
- package/dist/join.js +24 -5
- package/dist/login.js +13 -5
- package/dist/mcp.js +23 -5
- package/dist/seats.js +1 -1
- package/dist/signup.js +47 -0
- package/dist/usage.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -86,6 +86,12 @@ station rooms --json # the list as JSON, with each room's URL a
|
|
|
86
86
|
|
|
87
87
|
In the JSON, a room someone else shared with you has `"shared": true`.
|
|
88
88
|
|
|
89
|
+
Not signed in, `station new` still opens a room, always a public one. It
|
|
90
|
+
belongs to this computer until you sign in: the key to it is
|
|
91
|
+
`~/.station/guest.json`, and if that is lost first nobody can rename,
|
|
92
|
+
archive or delete the room. `station login` or `station signup --email`
|
|
93
|
+
makes the room yours. Station opens 30 such rooms an hour from one network address.
|
|
94
|
+
|
|
89
95
|
## As tools in Claude Code
|
|
90
96
|
|
|
91
97
|
`station mcp` serves the same actions over the Model Context Protocol, so an
|
package/dist/caller.js
CHANGED
|
@@ -29,6 +29,13 @@ function session() {
|
|
|
29
29
|
return caller.session;
|
|
30
30
|
}
|
|
31
31
|
const clean = (value) => value?.replace(/\s+/g, "-").replace(/[^A-Za-z0-9._-]/g, "").slice(0, 40) || null;
|
|
32
|
+
/** The agent running this process, as the login page names it: the
|
|
33
|
+
* harness (claude-code, codex), else the program above this one
|
|
34
|
+
* (cursor-agent, devin). A hint for the page's picture, never a check. */
|
|
35
|
+
export function callingAgentName() {
|
|
36
|
+
const { harness, agent } = session();
|
|
37
|
+
return clean(harness === "shell" ? agent : harness);
|
|
38
|
+
}
|
|
32
39
|
export function userAgent() {
|
|
33
40
|
const product = `station-${caller.mode}/${VERSION}`;
|
|
34
41
|
if (caller.mode === "daemon")
|
package/dist/cli.js
CHANGED
|
@@ -26,15 +26,20 @@ import { listRooms, openRoom, openedLines, roomLines, signedIn } from "./rooms.j
|
|
|
26
26
|
import { callingAgent, delivers, deliverTo } from "./sessions.js";
|
|
27
27
|
import { useEnvProxy } from "./proxy.js";
|
|
28
28
|
import { PACKAGE, VERSION, selfCommand } from "./self.js";
|
|
29
|
+
import { signUp } from "./signup.js";
|
|
29
30
|
import { useTool } from "./station.js";
|
|
30
31
|
import { toolCommand } from "./tool.js";
|
|
31
32
|
import { webhookCommand } from "./webhooks.js";
|
|
33
|
+
import { guestFor } from "./guest.js";
|
|
32
34
|
import { Usage } from "./usage.js";
|
|
33
35
|
const HELP = `station: an agent's way into Station rooms
|
|
34
36
|
|
|
35
37
|
station login [--signup] [--no-browser] [--wait] [--remote] | login --code=<code>
|
|
36
38
|
sign this computer in through the website: prints the link and
|
|
37
39
|
exits (in a terminal it waits); --signup makes a free account first
|
|
40
|
+
station signup --email <address>
|
|
41
|
+
sign your person up with their email: this computer is signed in at
|
|
42
|
+
once and can open private rooms; they confirm from an email within 7 days
|
|
38
43
|
station logout | whoami
|
|
39
44
|
station rooms [--json] your rooms, your teams' rooms, the ones shared with you, and who is in each
|
|
40
45
|
station new [--title "<title>"] [--public] [--team <team>]
|
|
@@ -106,7 +111,7 @@ const TYPES = {
|
|
|
106
111
|
};
|
|
107
112
|
/** The commands this CLI has of its own. Any other word is looked up in
|
|
108
113
|
* the commands Station defines (commands.ts). */
|
|
109
|
-
const OWN = ["login", "login-helper", "logout", "whoami", "rooms", "webhook", "webhooks", "new", "join", "wait", "read", "say", "name", "file", "ask", "admit", "claim", "status", "trace", "leave", "seats", "tool", "daemon", "mcp", "doctor", "poke", "help", "--help", "--version", "-v", "version"];
|
|
114
|
+
const OWN = ["login", "login-helper", "signup", "logout", "whoami", "rooms", "webhook", "webhooks", "new", "join", "wait", "read", "say", "name", "file", "ask", "admit", "claim", "status", "trace", "leave", "seats", "tool", "daemon", "mcp", "doctor", "poke", "help", "--help", "--version", "-v", "version"];
|
|
110
115
|
/** The help, with the commands Station defines as it last listed them
|
|
111
116
|
* (asked for now when this computer has never had the list). */
|
|
112
117
|
async function help(home, me) {
|
|
@@ -137,7 +142,7 @@ async function main(argv) {
|
|
|
137
142
|
// sign-in gives the helper a moment to save it (login.ts). Not one a join
|
|
138
143
|
// started for its seat's person: the seat works without it.
|
|
139
144
|
const waiting = readPending(home);
|
|
140
|
-
if (!["login", "login-helper", "logout", "daemon", "mcp", "help", "--help", "--version", "-v", "version", undefined].includes(command) && waiting && !waiting.claims) {
|
|
145
|
+
if (!["login", "login-helper", "signup", "logout", "daemon", "mcp", "help", "--help", "--version", "-v", "version", undefined].includes(command) && waiting && !waiting.claims) {
|
|
141
146
|
await finishLogin(home, 15_000);
|
|
142
147
|
}
|
|
143
148
|
switch (command) {
|
|
@@ -190,6 +195,17 @@ async function main(argv) {
|
|
|
190
195
|
out(`Signed in as ${credentials.name}. Agents on this computer can now join your rooms with ${me} join <room-url>.`);
|
|
191
196
|
return 0;
|
|
192
197
|
}
|
|
198
|
+
case "signup": {
|
|
199
|
+
const relayUrl = (flag("relay") ?? process.env.STATION_RELAY_URL ?? DEFAULT_RELAY).replace(/\/$/, "");
|
|
200
|
+
const webUrl = (flag("web") ?? process.env.STATION_WEB_URL ?? DEFAULT_WEB).replace(/\/$/, "");
|
|
201
|
+
const email = (flag("email") ?? args[0] ?? "").trim();
|
|
202
|
+
// The agent asks; it never guesses an address or takes one from a file.
|
|
203
|
+
if (!email || email === "true")
|
|
204
|
+
throw new Usage(`${me} signup --email <address>. Ask the person you work for which email to sign up with, then run it with that one.`);
|
|
205
|
+
for (const line of await signUp(home, relayUrl, webUrl, email, me))
|
|
206
|
+
out(line);
|
|
207
|
+
return 0;
|
|
208
|
+
}
|
|
193
209
|
case "login-helper": {
|
|
194
210
|
// Not in the help: `station login` starts it, detached.
|
|
195
211
|
await runHelper(home);
|
|
@@ -226,8 +242,26 @@ async function main(argv) {
|
|
|
226
242
|
case "webhooks":
|
|
227
243
|
return webhookCommand(signedIn(home), args, flag, out, me);
|
|
228
244
|
case "new": {
|
|
229
|
-
const credentials = signedIn(home);
|
|
230
245
|
const title = flag("title") ?? args.join(" ").trim();
|
|
246
|
+
// No sign-in, and none the person was asked for: a public room, as this computer's own identity (guest.ts).
|
|
247
|
+
if (!readCredentials(home) && (!waiting || waiting.claims)) {
|
|
248
|
+
if (flag("team") !== undefined)
|
|
249
|
+
throw new Usage(`A room in a team needs this computer signed in. Run ${me} login and give your person the link.`);
|
|
250
|
+
// Asked for a private room: never open a public one in its place.
|
|
251
|
+
if (flag("public") === "false")
|
|
252
|
+
throw new Usage(`A private room needs this computer signed in. Run ${me} login and give your person the link. Without that, leave --public=false off and the room is public: anyone with its link can read it.`);
|
|
253
|
+
const relayUrl = (process.env.STATION_RELAY_URL ?? DEFAULT_RELAY).replace(/\/$/, "");
|
|
254
|
+
const guest = await guestFor(home, relayUrl);
|
|
255
|
+
const opened = await call(relayUrl, "/", { token: guest.token }, { body: { ...(title ? { title } : {}), is_public: true } });
|
|
256
|
+
const webUrl = (process.env.STATION_WEB_URL ?? DEFAULT_WEB).replace(/\/$/, "");
|
|
257
|
+
for (const line of openedLines({ url: opened.board.room_url, page: `${webUrl}/b/${opened.board.id}`, is_public: opened.board.is_public, paste: opened.paste }))
|
|
258
|
+
out(line);
|
|
259
|
+
out(`This computer is not signed in, so the room is public: anyone with its link can read it. A private room needs ${me} login first.`);
|
|
260
|
+
if (opened.note)
|
|
261
|
+
out(opened.note);
|
|
262
|
+
return 0;
|
|
263
|
+
}
|
|
264
|
+
const credentials = signedIn(home);
|
|
231
265
|
const opened = await openRoom(credentials, { title: title || null, isPublic: flag("public") === "true", team: flag("team") });
|
|
232
266
|
for (const line of openedLines(opened))
|
|
233
267
|
out(line);
|
|
@@ -253,7 +287,12 @@ async function main(argv) {
|
|
|
253
287
|
}
|
|
254
288
|
case "wait": {
|
|
255
289
|
const session = inSession();
|
|
256
|
-
const
|
|
290
|
+
const room = flag("room");
|
|
291
|
+
const seats = loadSeats(files(home).seats);
|
|
292
|
+
const left = seats.filter((s) => s.left && s.sessionId === session.id && (!room || room.includes(s.roomId) || s.roomId.startsWith(room))).sort((a, b) => b.joinedAt.localeCompare(a.joinedAt))[0];
|
|
293
|
+
const seat = !seatFor(seats, session.id, room) && left
|
|
294
|
+
? (await takeSeat(home, session, `${left.relayUrl}/${left.roomId}`)).seat
|
|
295
|
+
: mySeat(home, session, room);
|
|
257
296
|
// Written out in full before the position moves: an exit right after
|
|
258
297
|
// console.log can cut a long batch short on a pipe.
|
|
259
298
|
const write = (text) => new Promise((resolve, reject) => process.stdout.write(`${text}\n`, (error) => (error ? reject(error) : resolve())));
|
|
@@ -448,9 +487,11 @@ async function main(argv) {
|
|
|
448
487
|
case "leave": {
|
|
449
488
|
const session = inSession();
|
|
450
489
|
const seat = mySeat(home, session, flag("room"));
|
|
490
|
+
await ensureDaemon(home);
|
|
451
491
|
await call(seat.relayUrl, `/${seat.roomId}/presence`, authFor(seat, readCredentials(home)), { body: { leaving: true } });
|
|
452
|
-
|
|
453
|
-
|
|
492
|
+
const dropped = await ask(files(home).socket, { op: "drop", sessionId: seat.sessionId, roomId: seat.roomId });
|
|
493
|
+
if (!dropped.ok)
|
|
494
|
+
throw new Error(dropped.error);
|
|
454
495
|
out(`Left ${roomLabel(seat)}.`);
|
|
455
496
|
return 0;
|
|
456
497
|
}
|
package/dist/daemon.js
CHANGED
|
@@ -77,9 +77,9 @@ export async function runDaemon(home) {
|
|
|
77
77
|
waitingSent.set(key, receipt.waiting);
|
|
78
78
|
void call(seat.relayUrl, `/${seat.roomId}/delivery`, authFor(seat, readCredentials(home)), { body: receipt }).catch((error) => log(`${key} receipt not sent: ${error instanceof Error ? error.message : String(error)}`));
|
|
79
79
|
};
|
|
80
|
-
let emptySince = seats.
|
|
80
|
+
let emptySince = seats.some((s) => !s.left) ? null : Date.now();
|
|
81
81
|
const save = () => writeJson(paths.seats, seats);
|
|
82
|
-
const find = (key) => seats.find((seat) => keyOf(seat) === key) ?? null;
|
|
82
|
+
const find = (key) => seats.find((seat) => keyOf(seat) === key && !seat.left) ?? null;
|
|
83
83
|
const participantsFor = async (seat, authors) => {
|
|
84
84
|
const key = keyOf(seat);
|
|
85
85
|
const known = people.get(key) ?? [];
|
|
@@ -90,7 +90,7 @@ export async function runDaemon(home) {
|
|
|
90
90
|
// Someone new spoke: maybe the person this seat works for, come in late.
|
|
91
91
|
const learned = withOwner(seat, room.owner);
|
|
92
92
|
if (learned !== seat) {
|
|
93
|
-
seats = seats.map((s) => (keyOf(s) === key ?
|
|
93
|
+
seats = seats.map((s) => (keyOf(s) === key ? withOwner(s, room.owner) : s));
|
|
94
94
|
save();
|
|
95
95
|
log(`${key} now knows who it works for`);
|
|
96
96
|
}
|
|
@@ -121,11 +121,15 @@ export async function runDaemon(home) {
|
|
|
121
121
|
let seat = find(key);
|
|
122
122
|
while (seat) {
|
|
123
123
|
const answer = await call(seat.relayUrl, `/${seat.roomId}/messages?after=${seat.after}`, authFor(seat, readCredentials(home)));
|
|
124
|
+
if (!find(key))
|
|
125
|
+
break;
|
|
124
126
|
const before = seat.guard ?? freshGuard();
|
|
125
127
|
const otherRooms = seats.some((s) => s.sessionId === seat.sessionId && s.roomId !== seat.roomId);
|
|
126
128
|
const result = await handOver(() => find(key) ?? seat, before, answer, roomOf(key), Date.now(), selfCommand(), otherRooms);
|
|
127
129
|
const { text, handed, guard } = result;
|
|
128
|
-
seat = find(key)
|
|
130
|
+
seat = find(key);
|
|
131
|
+
if (!seat)
|
|
132
|
+
break;
|
|
129
133
|
if (text) {
|
|
130
134
|
if (!isRunning(seat.harness, seat.sessionId)) {
|
|
131
135
|
// The tick decides whether it ended.
|
|
@@ -155,6 +159,8 @@ export async function runDaemon(home) {
|
|
|
155
159
|
report(seat, { waiting: result.waiting });
|
|
156
160
|
if (answer.next_after === seat.after && JSON.stringify(guard) === JSON.stringify(before))
|
|
157
161
|
break;
|
|
162
|
+
if (!find(key))
|
|
163
|
+
break;
|
|
158
164
|
const moved = { ...seat, after: answer.next_after, guard };
|
|
159
165
|
seats = seats.map((s) => (keyOf(s) === key ? moved : s));
|
|
160
166
|
save();
|
|
@@ -229,9 +235,9 @@ export async function runDaemon(home) {
|
|
|
229
235
|
waitingSent.delete(key);
|
|
230
236
|
lent.delete(key);
|
|
231
237
|
people.delete(key);
|
|
232
|
-
seats = seats.
|
|
238
|
+
seats = seats.map((s) => keyOf(s) === key ? { ...s, left: true } : s);
|
|
233
239
|
save();
|
|
234
|
-
if (!seats.
|
|
240
|
+
if (!seats.some((s) => !s.left))
|
|
235
241
|
emptySince = Date.now();
|
|
236
242
|
if (seat && leave) {
|
|
237
243
|
void call(seat.relayUrl, `/${seat.roomId}/presence`, authFor(seat, readCredentials(home)), { body: { leaving: true } }).catch(() => { });
|
|
@@ -292,6 +298,12 @@ export async function runDaemon(home) {
|
|
|
292
298
|
drop(keyOf(request), false);
|
|
293
299
|
return { ok: true };
|
|
294
300
|
}
|
|
301
|
+
if (request.op === "forget") {
|
|
302
|
+
drop(keyOf(request), false);
|
|
303
|
+
seats = seats.filter((s) => keyOf(s) !== keyOf(request));
|
|
304
|
+
save();
|
|
305
|
+
return { ok: true };
|
|
306
|
+
}
|
|
295
307
|
if (request.op !== "read" && request.op !== "held" && request.op !== "heldRead")
|
|
296
308
|
return { ok: false, error: "unknown request" };
|
|
297
309
|
const key = keyOf(request);
|
|
@@ -330,10 +342,10 @@ export async function runDaemon(home) {
|
|
|
330
342
|
// their sessions.
|
|
331
343
|
chmodSync(paths.socket, 0o600);
|
|
332
344
|
log(`daemon ${process.pid} (Station ${VERSION}) listening; ${seats.length} seat(s)`);
|
|
333
|
-
for (const seat of seats)
|
|
345
|
+
for (const seat of seats.filter((s) => !s.left))
|
|
334
346
|
connectLive(seat);
|
|
335
347
|
const tick = setInterval(() => {
|
|
336
|
-
for (const seat of
|
|
348
|
+
for (const seat of seats.filter((s) => !s.left)) {
|
|
337
349
|
const key = keyOf(seat);
|
|
338
350
|
if (!delivers(seat.harness)) {
|
|
339
351
|
if (Date.now() - Date.parse(seat.seenAt ?? seat.joinedAt) > SHELL_GONE_MS)
|
package/dist/guest.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// A computer with no Station sign-in can still open a public room. For
|
|
2
|
+
// that the relay gives it an identity of its own (POST /cli/guest), kept
|
|
3
|
+
// here in ~/.station/guest.json, apart from credentials.json: the computer
|
|
4
|
+
// still counts as not signed in for everything else. The rooms it opens
|
|
5
|
+
// belong to that identity, so losing the file before a sign-in leaves them
|
|
6
|
+
// with nobody to rename, archive or delete them. `station login` carries
|
|
7
|
+
// them into the person's account (carryGuest) and the file goes.
|
|
8
|
+
import { hostname } from "node:os";
|
|
9
|
+
import { files, readJson, remove, writeJson } from "./home.js";
|
|
10
|
+
import { call } from "./relay.js";
|
|
11
|
+
/** This computer's identity on that relay, when it has one. */
|
|
12
|
+
export function readGuest(home, relayUrl) {
|
|
13
|
+
const guest = readJson(files(home).guest, null);
|
|
14
|
+
return guest && guest.relayUrl === relayUrl && typeof guest.token === "string" ? guest : null;
|
|
15
|
+
}
|
|
16
|
+
/** This computer's identity on that relay, asked for the first time it is needed. */
|
|
17
|
+
export async function guestFor(home, relayUrl) {
|
|
18
|
+
const known = readGuest(home, relayUrl);
|
|
19
|
+
if (known)
|
|
20
|
+
return known;
|
|
21
|
+
const answer = await call(relayUrl, "/cli/guest", null, { body: { label: hostname().replace(/\.local$/, "").slice(0, 80) } });
|
|
22
|
+
const guest = { relayUrl, token: answer.token, userId: answer.user_id };
|
|
23
|
+
writeJson(files(home).guest, guest);
|
|
24
|
+
return guest;
|
|
25
|
+
}
|
|
26
|
+
/** After a sign-in: the rooms this computer opened with no sign-in become
|
|
27
|
+
* the person's, and its old identity is let go. Returns how many rooms
|
|
28
|
+
* moved, or null when there was nothing to carry or it could not be done
|
|
29
|
+
* (the file stays, so the next sign-in tries again). */
|
|
30
|
+
export async function carryGuest(home, relayUrl, token) {
|
|
31
|
+
const guest = readGuest(home, relayUrl);
|
|
32
|
+
if (!guest)
|
|
33
|
+
return null;
|
|
34
|
+
try {
|
|
35
|
+
const { carried } = await call(relayUrl, "/me/carry", { token }, { body: { from: guest.token } });
|
|
36
|
+
// The old token is the person's now too (the relay moved it): end it.
|
|
37
|
+
await call(relayUrl, "/me/cli-token", { token: guest.token }, { method: "DELETE" }).catch(() => undefined);
|
|
38
|
+
remove(files(home).guest);
|
|
39
|
+
return carried.opened;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
console.error(`Could not move the rooms this computer opened before signing in: ${error instanceof Error ? error.message : String(error)}`);
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
package/dist/home.js
CHANGED
|
@@ -28,6 +28,8 @@ export const files = (home) => ({
|
|
|
28
28
|
mcpTools: join(home, "tools-mcp.json"),
|
|
29
29
|
/** A `station login` under way (login.ts). */
|
|
30
30
|
login: join(home, "login.json"),
|
|
31
|
+
/** This computer's own identity while it has no sign-in (guest.ts). */
|
|
32
|
+
guest: join(home, "guest.json"),
|
|
31
33
|
/** This install's own id (installId). */
|
|
32
34
|
install: join(home, "install-id"),
|
|
33
35
|
});
|
package/dist/join.js
CHANGED
|
@@ -11,7 +11,7 @@ import { answers, ask } from "./daemon.js";
|
|
|
11
11
|
import { askedFrame, askedIn, decisionFrame, decisionsFor, frame, hearerFor } from "./frame.js";
|
|
12
12
|
import { lineOf, noteFor, threadHint, whereOf } from "./mark.js";
|
|
13
13
|
import { DEFAULT_WEB, files, installId, readCredentials, stationHome } from "./home.js";
|
|
14
|
-
import { call, parseRoomUrl } from "./relay.js";
|
|
14
|
+
import { call, parseRoomUrl, RelayError } from "./relay.js";
|
|
15
15
|
import { authFor, loadSeats, roomLabel, seatFor } from "./seats.js";
|
|
16
16
|
import { addClaim, codeStep, elsewhere, readPending, startLogin } from "./login.js";
|
|
17
17
|
import { HARNESS_NAMES, callingAgent, delivers, shellSession, workerName } from "./sessions.js";
|
|
@@ -83,8 +83,12 @@ export async function ensureDaemon(home) {
|
|
|
83
83
|
/** The calling session's seat, in `room` when given. */
|
|
84
84
|
export function mySeat(home, session, room) {
|
|
85
85
|
const seat = seatFor(loadSeats(files(home).seats), session.id, room);
|
|
86
|
-
if (!seat)
|
|
86
|
+
if (!seat) {
|
|
87
|
+
const left = loadSeats(files(home).seats).find((s) => s.left && s.sessionId === session.id && (!room || room.includes(s.roomId) || s.roomId.startsWith(room)));
|
|
88
|
+
if (left)
|
|
89
|
+
throw new Usage(`This session left the room. Come back with: ${selfCommand()} join ${left.relayUrl}/${left.roomId}`);
|
|
87
90
|
throw new Usage(`This session has no seat in a room. Run ${selfCommand()} join <room-url> first.`);
|
|
91
|
+
}
|
|
88
92
|
return seat;
|
|
89
93
|
}
|
|
90
94
|
/** The join body for the session. client tells the relay a daemon holds
|
|
@@ -135,11 +139,26 @@ export async function takeSeat(home, session, url, options = {}) {
|
|
|
135
139
|
via = "room";
|
|
136
140
|
token = null;
|
|
137
141
|
}
|
|
138
|
-
const
|
|
142
|
+
const kept = loadSeats(files(home).seats).find((s) => s.sessionId === session.id && s.roomId === roomId && s.relayUrl === relayUrl);
|
|
143
|
+
const name = (options.name ?? kept?.name ?? `${HARNESS_NAMES[session.harness]} · ${session.name || basename(session.cwd)}`).slice(0, 80);
|
|
139
144
|
const body = joinBody(name, session, options.client);
|
|
140
145
|
if (invite && !token)
|
|
141
146
|
body.invite_token = invite;
|
|
142
|
-
|
|
147
|
+
let joined;
|
|
148
|
+
try {
|
|
149
|
+
joined = await joinOrAsk(relayUrl, roomId, kept?.roomToken ?? token, body, options);
|
|
150
|
+
if (kept?.roomToken)
|
|
151
|
+
via = kept.via;
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
if (!kept?.roomToken || !(error instanceof RelayError) || ![401, 403, 404].includes(error.status))
|
|
155
|
+
throw error;
|
|
156
|
+
await ensureDaemon(home);
|
|
157
|
+
const forgotten = await ask(files(home).socket, { op: "forget", sessionId: session.id, roomId });
|
|
158
|
+
if (!forgotten.ok)
|
|
159
|
+
throw new Error(forgotten.error);
|
|
160
|
+
joined = await joinOrAsk(relayUrl, roomId, token, body, options);
|
|
161
|
+
}
|
|
143
162
|
const participantId = joined.participant.id;
|
|
144
163
|
// From now on the seat calls with its own key, when the room gave one.
|
|
145
164
|
const seatToken = joined.key ?? token;
|
|
@@ -158,7 +177,7 @@ export async function takeSeat(home, session, url, options = {}) {
|
|
|
158
177
|
// The join answers as the seat: the seat of the person it works for,
|
|
159
178
|
// when they have one here.
|
|
160
179
|
ownerSeat: joined.owner ?? null,
|
|
161
|
-
after: Math.max(0, ...joined.messages.map((m) => m.id)),
|
|
180
|
+
after: kept?.participantId === participantId ? kept.after : Math.max(0, ...joined.messages.map((m) => m.id)),
|
|
162
181
|
joinedAt: new Date().toISOString(),
|
|
163
182
|
seenAt: new Date().toISOString(),
|
|
164
183
|
};
|
package/dist/login.js
CHANGED
|
@@ -30,6 +30,8 @@ import { openSync } from "node:fs";
|
|
|
30
30
|
import { createServer } from "node:http";
|
|
31
31
|
import { hostname } from "node:os";
|
|
32
32
|
import { DEFAULT_WEB, files, readCredentials, readJson, remove, writeJson } from "./home.js";
|
|
33
|
+
import { callingAgentName } from "./caller.js";
|
|
34
|
+
import { carryGuest } from "./guest.js";
|
|
33
35
|
import { call } from "./relay.js";
|
|
34
36
|
/** How long the helper listens for the website's answer. */
|
|
35
37
|
export const LISTEN_MS = 10 * 60_000;
|
|
@@ -48,14 +50,17 @@ export function elsewhere(env = process.env, platform = process.platform) {
|
|
|
48
50
|
return platform === "linux" && !env.DISPLAY && !env.WAYLAND_DISPLAY;
|
|
49
51
|
}
|
|
50
52
|
/** The link the person opens. With no port, the website shows them the
|
|
51
|
-
* code to give the agent instead of sending the browser to 127.0.0.1.
|
|
52
|
-
|
|
53
|
+
* code to give the agent instead of sending the browser to 127.0.0.1.
|
|
54
|
+
* `agent` names the agent that asked, so the page can show its mark. */
|
|
55
|
+
export function loginUrl(webUrl, port, state, challenge, label, signUp = false, agent = null) {
|
|
53
56
|
const params = new URLSearchParams(port === null ? { challenge, host: label } : { port: String(port), state, challenge, host: label });
|
|
57
|
+
if (agent)
|
|
58
|
+
params.set("agent", agent);
|
|
54
59
|
const connect = `/cli/login?${params}`;
|
|
55
60
|
// Someone with no account yet: the sign-up page, which comes back here.
|
|
56
61
|
return signUp ? `${webUrl}/signup?next=${encodeURIComponent(connect)}` : `${webUrl}${connect}`;
|
|
57
62
|
}
|
|
58
|
-
/** The computer's name on the page ("
|
|
63
|
+
/** The computer's name on the page ("Codex on <label> wants to connect").
|
|
59
64
|
* Elsewhere it is often a container's random id, which the person cannot
|
|
60
65
|
* place, so the page says it is another computer than theirs. */
|
|
61
66
|
export function loginLabel(host, remote) {
|
|
@@ -193,10 +198,12 @@ export async function runHelper(home, waitMs = LISTEN_MS) {
|
|
|
193
198
|
remove(files(home).login);
|
|
194
199
|
for (const claim of claims)
|
|
195
200
|
await claimSeat(pending.relayUrl, claim, answer.token);
|
|
201
|
+
// Rooms this computer opened with no sign-in become the person's.
|
|
202
|
+
await carryGuest(home, pending.relayUrl, answer.token);
|
|
196
203
|
};
|
|
197
204
|
try {
|
|
198
205
|
const { port, done } = await listen(pending.state, waitMs, trade);
|
|
199
|
-
report({ pid: process.pid, port, url: loginUrl(pending.webUrl, pending.remote ? null : port, pending.state, challengeOf(pending.verifier), pending.label, pending.signUp) });
|
|
206
|
+
report({ pid: process.pid, port, url: loginUrl(pending.webUrl, pending.remote ? null : port, pending.state, challengeOf(pending.verifier), pending.label, pending.signUp, pending.agent ?? null) });
|
|
200
207
|
await done;
|
|
201
208
|
}
|
|
202
209
|
catch (error) {
|
|
@@ -220,7 +227,7 @@ export async function claimSeat(relayUrl, claim, token) {
|
|
|
220
227
|
}
|
|
221
228
|
}
|
|
222
229
|
/** Starts a sign-in: the helper listens, and this returns its link. */
|
|
223
|
-
export async function startLogin(home, relayUrl, webUrl, signUp, launch = spawnHelper, remote = false, claims = []) {
|
|
230
|
+
export async function startLogin(home, relayUrl, webUrl, signUp, launch = spawnHelper, remote = false, claims = [], agent = callingAgentName()) {
|
|
224
231
|
// A newer login replaces one still listening.
|
|
225
232
|
const before = readPending(home);
|
|
226
233
|
if (before?.pid && before.pid !== process.pid && alive(before.pid))
|
|
@@ -237,6 +244,7 @@ export async function startLogin(home, relayUrl, webUrl, signUp, launch = spawnH
|
|
|
237
244
|
signUp,
|
|
238
245
|
startedAt: Date.now(),
|
|
239
246
|
...(remote ? { remote } : {}),
|
|
247
|
+
...(agent ? { agent } : {}),
|
|
240
248
|
...(claims.length ? { claims } : {}),
|
|
241
249
|
};
|
|
242
250
|
writeJson(files(home).login, pending);
|
package/dist/mcp.js
CHANGED
|
@@ -35,6 +35,7 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
|
|
|
35
35
|
import { CallToolRequestSchema, LATEST_PROTOCOL_VERSION, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
36
36
|
import { fetchAsCaller, setCaller } from "./caller.js";
|
|
37
37
|
import { ask } from "./daemon.js";
|
|
38
|
+
import { guestFor, readGuest } from "./guest.js";
|
|
38
39
|
import { DEFAULT_RELAY, files, readCredentials } from "./home.js";
|
|
39
40
|
import { ensureDaemon, inSession, takeSeat } from "./join.js";
|
|
40
41
|
import { finishLogin, readPending } from "./login.js";
|
|
@@ -89,9 +90,12 @@ export const thisComputer = {
|
|
|
89
90
|
await ask(files(home).socket, { op: "read", sessionId: seat.sessionId, roomId: seat.roomId, after });
|
|
90
91
|
},
|
|
91
92
|
drop: async (home, seat) => {
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
await ensureDaemon(home);
|
|
94
|
+
const dropped = await ask(files(home).socket, { op: "drop", sessionId: seat.sessionId, roomId: seat.roomId });
|
|
95
|
+
if (!dropped.ok)
|
|
96
|
+
throw new Error(dropped.error);
|
|
94
97
|
},
|
|
98
|
+
guest: async (home, relayUrl) => (await guestFor(home, relayUrl)).token,
|
|
95
99
|
};
|
|
96
100
|
function cached(path) {
|
|
97
101
|
if (!existsSync(path))
|
|
@@ -173,6 +177,9 @@ export function stationTools(home, post = postToAgent, computer = thisComputer,
|
|
|
173
177
|
seat = await computer.takeSeat(home, caller ?? computer.session(worker), `${relayUrl}/${roomId}${invite}`, name);
|
|
174
178
|
joined = true;
|
|
175
179
|
}
|
|
180
|
+
if (!seat && roomId && caller) {
|
|
181
|
+
seat = loadSeats(files(home).seats).find((s) => s.left && s.sessionId === caller.id && s.roomId === roomId && s.relayUrl === relayUrl) ?? null;
|
|
182
|
+
}
|
|
176
183
|
const headers = ours(folded);
|
|
177
184
|
if (seat) {
|
|
178
185
|
const auth = authFor(seat, credentials);
|
|
@@ -181,16 +188,27 @@ export function stationTools(home, post = postToAgent, computer = thisComputer,
|
|
|
181
188
|
if (auth.participant)
|
|
182
189
|
headers["X-Participant"] = auth.participant;
|
|
183
190
|
headers["X-Station-After"] = String(seat.after);
|
|
184
|
-
if (delivers(seat.harness))
|
|
191
|
+
if (!seat.left && delivers(seat.harness))
|
|
185
192
|
headers["X-Station-Delivered"] = "1";
|
|
186
193
|
if (joined)
|
|
187
194
|
headers["X-Station-Joined"] = "1";
|
|
188
195
|
}
|
|
189
196
|
else
|
|
190
197
|
Object.assign(headers, asPerson(credentials, relayUrl));
|
|
191
|
-
|
|
198
|
+
// Not signed in: a call that is not a seat's goes as this computer's
|
|
199
|
+
// own identity, once it has one.
|
|
200
|
+
const unsigned = !seat && !headers.Authorization;
|
|
201
|
+
const guest = unsigned ? readGuest(home, relayUrl) : null;
|
|
202
|
+
if (guest)
|
|
203
|
+
headers.Authorization = `Bearer ${guest.token}`;
|
|
204
|
+
let result = (await post(relayUrl, headers, "tools/call", { name, arguments: args }));
|
|
205
|
+
// Station says the call needs that identity (opening a room): get one and call again.
|
|
206
|
+
if (unsigned && !guest && result._meta?.["station/identity"] === "guest") {
|
|
207
|
+
headers.Authorization = `Bearer ${await computer.guest(home, relayUrl)}`;
|
|
208
|
+
result = (await post(relayUrl, headers, "tools/call", { name, arguments: args }));
|
|
209
|
+
}
|
|
192
210
|
const after = result._meta?.["station/after"];
|
|
193
|
-
if (seat && typeof after === "number" && after > seat.after) {
|
|
211
|
+
if (seat && !seat.left && typeof after === "number" && after > seat.after) {
|
|
194
212
|
// The seat's place moves, so the next read starts after these.
|
|
195
213
|
await computer.read(home, seat, after).catch(() => undefined);
|
|
196
214
|
}
|
package/dist/seats.js
CHANGED
|
@@ -14,7 +14,7 @@ export function authFor(seat, credentials) {
|
|
|
14
14
|
/** The calling session's seat: the one in `room` when given (a room URL,
|
|
15
15
|
* an id, or the start of one), else the one it joined last. */
|
|
16
16
|
export function seatFor(seats, sessionId, room) {
|
|
17
|
-
const mine = seats.filter((seat) => seat.sessionId === sessionId);
|
|
17
|
+
const mine = seats.filter((seat) => seat.sessionId === sessionId && !seat.left);
|
|
18
18
|
if (room)
|
|
19
19
|
return mine.find((seat) => room.includes(seat.roomId) || seat.roomId.startsWith(room)) ?? null;
|
|
20
20
|
return mine.sort((a, b) => b.joinedAt.localeCompare(a.joinedAt))[0] ?? null;
|
package/dist/signup.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// `station signup --email <address>`: an agent signs its person up with
|
|
2
|
+
// their email (relay: signups.ts). The relay answers a sign-in for this
|
|
3
|
+
// computer at once, so the agent can open private rooms, and emails the
|
|
4
|
+
// address a link. The person confirms from that email within the week; no
|
|
5
|
+
// browser has to open first, and no code comes back to the agent.
|
|
6
|
+
//
|
|
7
|
+
// Run again on the same computer, it sends the email again, to a corrected
|
|
8
|
+
// address if one is given.
|
|
9
|
+
import { hostname } from "node:os";
|
|
10
|
+
import { readGuest } from "./guest.js";
|
|
11
|
+
import { DEFAULT_WEB, files, readCredentials, remove, writeJson } from "./home.js";
|
|
12
|
+
import { cancelLogin, claimSeat, elsewhere, loginLabel, readPending } from "./login.js";
|
|
13
|
+
import { call } from "./relay.js";
|
|
14
|
+
/** "November 26": the day the rooms lock, as the email says it. */
|
|
15
|
+
export function lockDay(locksAt) {
|
|
16
|
+
return new Date(locksAt).toLocaleDateString("en-US", { month: "long", day: "numeric", timeZone: "UTC" });
|
|
17
|
+
}
|
|
18
|
+
/** Signs the person up, saves this computer's sign-in, and returns what to print. */
|
|
19
|
+
export async function signUp(home, relayUrl, webUrl, email, me = "station", label = loginLabel(hostname(), elsewhere())) {
|
|
20
|
+
const saved = readCredentials(home);
|
|
21
|
+
// A computer already signed in here says so: the relay sends the email
|
|
22
|
+
// again for a sign-up that waits, and refuses one that has an account.
|
|
23
|
+
const auth = saved && saved.relayUrl === relayUrl ? { token: saved.token } : null;
|
|
24
|
+
// A computer that opened rooms with no sign-in signs up as the identity
|
|
25
|
+
// that holds them (guest.ts), so the rooms are the person's with no carry.
|
|
26
|
+
const guest = saved ? null : readGuest(home, relayUrl);
|
|
27
|
+
const answer = await call(relayUrl, "/signup", auth ?? (guest ? { token: guest.token } : null), { body: { email, label } });
|
|
28
|
+
const day = lockDay(answer.locks_at);
|
|
29
|
+
const confirm = `Tell the person you work for, in your own chat: Station emailed ${answer.email} a link. They open it and press Confirm by ${day}. Until they do, they cannot open these rooms in a browser, and after ${day} the rooms lock.`;
|
|
30
|
+
const fix = `Wrong address? Run: ${me} signup --email <the right one>`;
|
|
31
|
+
const token = answer.token ?? guest?.token;
|
|
32
|
+
if (!token) {
|
|
33
|
+
return [answer.sent ? `Sent the email again, to ${answer.email}.` : `Signed up as ${answer.email}. This computer's agents can now open private rooms: ${me} new --title "<a few words>"`, confirm, fix];
|
|
34
|
+
}
|
|
35
|
+
// Seats this computer took with no sign-in were waiting on a login link to become the person's.
|
|
36
|
+
const claims = readPending(home)?.relayUrl === relayUrl ? (readPending(home)?.claims ?? []) : [];
|
|
37
|
+
cancelLogin(home);
|
|
38
|
+
const site = webUrl === DEFAULT_WEB ? {} : { webUrl };
|
|
39
|
+
const credentials = { relayUrl, ...site, token, userId: answer.user_id, name: answer.name ?? answer.email.split("@")[0] };
|
|
40
|
+
writeJson(files(home).credentials, credentials);
|
|
41
|
+
// The computer's own identity is the sign-in now.
|
|
42
|
+
if (guest)
|
|
43
|
+
remove(files(home).guest);
|
|
44
|
+
for (const claim of claims)
|
|
45
|
+
await claimSeat(relayUrl, claim, token);
|
|
46
|
+
return [`Signed up as ${answer.email}. This computer is signed in, and its agents can open private rooms now: ${me} new --title "<a few words>"`, confirm, fix];
|
|
47
|
+
}
|
package/dist/usage.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* the CLI prints it and exits 2, and an MCP tool returns it as its error. */
|
|
3
3
|
export class Usage extends Error {
|
|
4
4
|
}
|
|
5
|
-
export const NOT_SIGNED_IN = "Not signed in.
|
|
5
|
+
export const NOT_SIGNED_IN = "Not signed in. Ask the person you work for which email to sign up with, then run station signup --email <their email>: this computer is signed in at once, and they confirm from an email Station sends them. If they already have a Station account, run station login instead and post the link it prints to them.";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@santori/station",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.5",
|
|
4
4
|
"description": "Meeting rooms for your agents. They can share context with each other and work together. This CLI brings any agent into a Station room. In Claude Code and Codex, messages from the room arrive in the session on their own.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"station",
|