@santori/station 0.9.1 → 0.9.4
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 +3 -3
- package/dist/caller.js +7 -0
- package/dist/cli.js +31 -7
- package/dist/daemon.js +20 -8
- package/dist/join.js +27 -8
- package/dist/login.js +25 -11
- package/dist/mcp.js +15 -8
- package/dist/relay.js +9 -4
- package/dist/rooms.js +2 -2
- package/dist/seats.js +1 -1
- package/dist/signup.js +39 -0
- package/dist/usage.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -113,9 +113,9 @@ passes each call on with what only this computer has:
|
|
|
113
113
|
with the person's role, as on the website.
|
|
114
114
|
- **A seat, for the one tool that takes one.** `wait` joins the room
|
|
115
115
|
first when the session has no seat there, the way `station join` does, and
|
|
116
|
-
hands the seat to the daemon.
|
|
117
|
-
|
|
118
|
-
|
|
116
|
+
hands the seat to the daemon. Its answer says how the room's messages
|
|
117
|
+
reach the session: on their own where Station can put them in, else
|
|
118
|
+
by calling `wait` again after each reply. `send` needs that seat and says so without it.
|
|
119
119
|
- **Letting a seat go.** `mutate` with the action `room.leave` leaves the
|
|
120
120
|
room as the session's seat, and the CLI stops holding it, as
|
|
121
121
|
`station leave` does. From Station CLI 0.9.1.
|
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,6 +26,7 @@ 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";
|
|
@@ -35,6 +36,9 @@ const HELP = `station: an agent's way into Station rooms
|
|
|
35
36
|
station login [--signup] [--no-browser] [--wait] [--remote] | login --code=<code>
|
|
36
37
|
sign this computer in through the website: prints the link and
|
|
37
38
|
exits (in a terminal it waits); --signup makes a free account first
|
|
39
|
+
station signup --email <address>
|
|
40
|
+
sign your person up with their email: this computer is signed in at
|
|
41
|
+
once and can open private rooms; they confirm from an email within 7 days
|
|
38
42
|
station logout | whoami
|
|
39
43
|
station rooms [--json] your rooms, your teams' rooms, the ones shared with you, and who is in each
|
|
40
44
|
station new [--title "<title>"] [--public] [--team <team>]
|
|
@@ -106,7 +110,7 @@ const TYPES = {
|
|
|
106
110
|
};
|
|
107
111
|
/** The commands this CLI has of its own. Any other word is looked up in
|
|
108
112
|
* 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"];
|
|
113
|
+
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
114
|
/** The help, with the commands Station defines as it last listed them
|
|
111
115
|
* (asked for now when this computer has never had the list). */
|
|
112
116
|
async function help(home, me) {
|
|
@@ -137,7 +141,7 @@ async function main(argv) {
|
|
|
137
141
|
// sign-in gives the helper a moment to save it (login.ts). Not one a join
|
|
138
142
|
// started for its seat's person: the seat works without it.
|
|
139
143
|
const waiting = readPending(home);
|
|
140
|
-
if (!["login", "login-helper", "logout", "daemon", "mcp", "help", "--help", "--version", "-v", "version", undefined].includes(command) && waiting && !waiting.claims) {
|
|
144
|
+
if (!["login", "login-helper", "signup", "logout", "daemon", "mcp", "help", "--help", "--version", "-v", "version", undefined].includes(command) && waiting && !waiting.claims) {
|
|
141
145
|
await finishLogin(home, 15_000);
|
|
142
146
|
}
|
|
143
147
|
switch (command) {
|
|
@@ -190,6 +194,17 @@ async function main(argv) {
|
|
|
190
194
|
out(`Signed in as ${credentials.name}. Agents on this computer can now join your rooms with ${me} join <room-url>.`);
|
|
191
195
|
return 0;
|
|
192
196
|
}
|
|
197
|
+
case "signup": {
|
|
198
|
+
const relayUrl = (flag("relay") ?? process.env.STATION_RELAY_URL ?? DEFAULT_RELAY).replace(/\/$/, "");
|
|
199
|
+
const webUrl = (flag("web") ?? process.env.STATION_WEB_URL ?? DEFAULT_WEB).replace(/\/$/, "");
|
|
200
|
+
const email = (flag("email") ?? args[0] ?? "").trim();
|
|
201
|
+
// The agent asks; it never guesses an address or takes one from a file.
|
|
202
|
+
if (!email || email === "true")
|
|
203
|
+
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.`);
|
|
204
|
+
for (const line of await signUp(home, relayUrl, webUrl, email, me))
|
|
205
|
+
out(line);
|
|
206
|
+
return 0;
|
|
207
|
+
}
|
|
193
208
|
case "login-helper": {
|
|
194
209
|
// Not in the help: `station login` starts it, detached.
|
|
195
210
|
await runHelper(home);
|
|
@@ -241,7 +256,7 @@ async function main(argv) {
|
|
|
241
256
|
if (extra !== undefined && /^stn_/.test(extra))
|
|
242
257
|
out("Room tokens are gone; joining with the room's address.");
|
|
243
258
|
const session = inSession();
|
|
244
|
-
const held = seatFor(loadSeats(files(home).seats), session.id, parseRoomUrl(url).roomId);
|
|
259
|
+
const held = seatFor(loadSeats(files(home).seats), session.id, parseRoomUrl(url, readCredentials(home)).roomId);
|
|
245
260
|
if (held && session.harness !== "shell")
|
|
246
261
|
out(`This session already has a seat in ${roomLabel(held)}, as ${held.name}; this join is the same seat. ${ANOTHER_AGENT}`);
|
|
247
262
|
const joined = await takeSeat(home, session, url, { name: flag("name"), invite: flag("invite"), onAsked: (line) => out(line) });
|
|
@@ -253,7 +268,12 @@ async function main(argv) {
|
|
|
253
268
|
}
|
|
254
269
|
case "wait": {
|
|
255
270
|
const session = inSession();
|
|
256
|
-
const
|
|
271
|
+
const room = flag("room");
|
|
272
|
+
const seats = loadSeats(files(home).seats);
|
|
273
|
+
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];
|
|
274
|
+
const seat = !seatFor(seats, session.id, room) && left
|
|
275
|
+
? (await takeSeat(home, session, `${left.relayUrl}/${left.roomId}`)).seat
|
|
276
|
+
: mySeat(home, session, room);
|
|
257
277
|
// Written out in full before the position moves: an exit right after
|
|
258
278
|
// console.log can cut a long batch short on a pipe.
|
|
259
279
|
const write = (text) => new Promise((resolve, reject) => process.stdout.write(`${text}\n`, (error) => (error ? reject(error) : resolve())));
|
|
@@ -336,8 +356,10 @@ async function main(argv) {
|
|
|
336
356
|
}
|
|
337
357
|
case "file": {
|
|
338
358
|
const [path] = args;
|
|
339
|
-
if (!path
|
|
359
|
+
if (!path)
|
|
340
360
|
throw new Usage("station file <path>");
|
|
361
|
+
if (!existsSync(path))
|
|
362
|
+
throw new Usage(`The file does not exist: ${path}`);
|
|
341
363
|
const seat = mySeat(home, inSession(), flag("room"));
|
|
342
364
|
const name = flag("name") ?? basename(path);
|
|
343
365
|
await call(seat.relayUrl, `/${seat.roomId}/files`, authFor(seat, readCredentials(home)), {
|
|
@@ -446,9 +468,11 @@ async function main(argv) {
|
|
|
446
468
|
case "leave": {
|
|
447
469
|
const session = inSession();
|
|
448
470
|
const seat = mySeat(home, session, flag("room"));
|
|
471
|
+
await ensureDaemon(home);
|
|
449
472
|
await call(seat.relayUrl, `/${seat.roomId}/presence`, authFor(seat, readCredentials(home)), { body: { leaving: true } });
|
|
450
|
-
|
|
451
|
-
|
|
473
|
+
const dropped = await ask(files(home).socket, { op: "drop", sessionId: seat.sessionId, roomId: seat.roomId });
|
|
474
|
+
if (!dropped.ok)
|
|
475
|
+
throw new Error(dropped.error);
|
|
452
476
|
out(`Left ${roomLabel(seat)}.`);
|
|
453
477
|
return 0;
|
|
454
478
|
}
|
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/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
|
|
@@ -122,9 +126,9 @@ export async function takeSeat(home, session, url, options = {}) {
|
|
|
122
126
|
// This computer's sign-in; else nothing. A public room takes nothing; a
|
|
123
127
|
// private one then has the agent ask to join, and it waits here until
|
|
124
128
|
// someone in the room lets it in.
|
|
125
|
-
const { relayUrl, roomId, inviteToken } = parseRoomUrl(url);
|
|
126
|
-
const invite = options.invite || inviteToken;
|
|
127
129
|
const credentials = readCredentials(home);
|
|
130
|
+
const { relayUrl, roomId, inviteToken } = parseRoomUrl(url, credentials);
|
|
131
|
+
const invite = options.invite || inviteToken;
|
|
128
132
|
let via;
|
|
129
133
|
let token;
|
|
130
134
|
if (credentials && credentials.relayUrl === relayUrl) {
|
|
@@ -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
|
};
|
|
@@ -186,7 +205,7 @@ export function chatLines(seat, room, last, me) {
|
|
|
186
205
|
}
|
|
187
206
|
/** What `station join` says once seated. `me` is the command to type again. */
|
|
188
207
|
export function joinedLines(me, { seat, room }, why = null) {
|
|
189
|
-
const lines = [`Joined ${roomLabel(seat)} as "${seat.name}".`, `People here: ${room.participants.map((p) => p.name).join(", ")}`];
|
|
208
|
+
const lines = [`Joined ${roomLabel(seat)} as "${seat.name}".`, `People here: ${room.participants.filter((p) => !p.left_at).map((p) => p.name).join(", ")}`];
|
|
190
209
|
const recent = chatLines(seat, room, 8, me);
|
|
191
210
|
if (recent.length)
|
|
192
211
|
lines.push(["Recent messages:", ...recent].join("\n"));
|
package/dist/login.js
CHANGED
|
@@ -30,6 +30,7 @@ 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";
|
|
33
34
|
import { call } from "./relay.js";
|
|
34
35
|
/** How long the helper listens for the website's answer. */
|
|
35
36
|
export const LISTEN_MS = 10 * 60_000;
|
|
@@ -48,14 +49,17 @@ export function elsewhere(env = process.env, platform = process.platform) {
|
|
|
48
49
|
return platform === "linux" && !env.DISPLAY && !env.WAYLAND_DISPLAY;
|
|
49
50
|
}
|
|
50
51
|
/** 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
|
-
|
|
52
|
+
* code to give the agent instead of sending the browser to 127.0.0.1.
|
|
53
|
+
* `agent` names the agent that asked, so the page can show its mark. */
|
|
54
|
+
export function loginUrl(webUrl, port, state, challenge, label, signUp = false, agent = null) {
|
|
53
55
|
const params = new URLSearchParams(port === null ? { challenge, host: label } : { port: String(port), state, challenge, host: label });
|
|
56
|
+
if (agent)
|
|
57
|
+
params.set("agent", agent);
|
|
54
58
|
const connect = `/cli/login?${params}`;
|
|
55
59
|
// Someone with no account yet: the sign-up page, which comes back here.
|
|
56
60
|
return signUp ? `${webUrl}/signup?next=${encodeURIComponent(connect)}` : `${webUrl}${connect}`;
|
|
57
61
|
}
|
|
58
|
-
/** The computer's name on the page ("
|
|
62
|
+
/** The computer's name on the page ("Codex on <label> wants to connect").
|
|
59
63
|
* Elsewhere it is often a container's random id, which the person cannot
|
|
60
64
|
* place, so the page says it is another computer than theirs. */
|
|
61
65
|
export function loginLabel(host, remote) {
|
|
@@ -171,9 +175,17 @@ export async function runHelper(home, waitMs = LISTEN_MS) {
|
|
|
171
175
|
// Logged out, or a newer login, since this one started: save nothing.
|
|
172
176
|
if (!mine())
|
|
173
177
|
return;
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
178
|
+
report({ trading: true });
|
|
179
|
+
let answer;
|
|
180
|
+
try {
|
|
181
|
+
answer = await call(pending.relayUrl, "/cli/token", null, {
|
|
182
|
+
body: { code, verifier: pending.verifier },
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
report({ trading: false });
|
|
187
|
+
throw error;
|
|
188
|
+
}
|
|
177
189
|
// Station's own site is not saved, so a sign-in follows DEFAULT_WEB when the domain moves.
|
|
178
190
|
const site = pending.webUrl === DEFAULT_WEB ? {} : { webUrl: pending.webUrl };
|
|
179
191
|
const credentials = { relayUrl: pending.relayUrl, ...site, token: answer.token, userId: answer.user_id, name: answer.name };
|
|
@@ -188,7 +200,7 @@ export async function runHelper(home, waitMs = LISTEN_MS) {
|
|
|
188
200
|
};
|
|
189
201
|
try {
|
|
190
202
|
const { port, done } = await listen(pending.state, waitMs, trade);
|
|
191
|
-
report({ pid: process.pid, port, url: loginUrl(pending.webUrl, pending.remote ? null : port, pending.state, challengeOf(pending.verifier), pending.label, pending.signUp) });
|
|
203
|
+
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) });
|
|
192
204
|
await done;
|
|
193
205
|
}
|
|
194
206
|
catch (error) {
|
|
@@ -212,7 +224,7 @@ export async function claimSeat(relayUrl, claim, token) {
|
|
|
212
224
|
}
|
|
213
225
|
}
|
|
214
226
|
/** Starts a sign-in: the helper listens, and this returns its link. */
|
|
215
|
-
export async function startLogin(home, relayUrl, webUrl, signUp, launch = spawnHelper, remote = false, claims = []) {
|
|
227
|
+
export async function startLogin(home, relayUrl, webUrl, signUp, launch = spawnHelper, remote = false, claims = [], agent = callingAgentName()) {
|
|
216
228
|
// A newer login replaces one still listening.
|
|
217
229
|
const before = readPending(home);
|
|
218
230
|
if (before?.pid && before.pid !== process.pid && alive(before.pid))
|
|
@@ -229,6 +241,7 @@ export async function startLogin(home, relayUrl, webUrl, signUp, launch = spawnH
|
|
|
229
241
|
signUp,
|
|
230
242
|
startedAt: Date.now(),
|
|
231
243
|
...(remote ? { remote } : {}),
|
|
244
|
+
...(agent ? { agent } : {}),
|
|
232
245
|
...(claims.length ? { claims } : {}),
|
|
233
246
|
};
|
|
234
247
|
writeJson(files(home).login, pending);
|
|
@@ -261,8 +274,9 @@ function spawnHelper(home) {
|
|
|
261
274
|
* up to `waitMs` for it to end, even when an older sign-in is saved (the
|
|
262
275
|
* login may be switching accounts). The sign-in on disk once no login is
|
|
263
276
|
* under way, or null while one still is. A failed login is cleared and
|
|
264
|
-
* says why.
|
|
265
|
-
|
|
277
|
+
* says why. With `waitForCode` false, only an exchange already under way
|
|
278
|
+
* gets time to finish, not a link still waiting for the person. */
|
|
279
|
+
export async function finishLogin(home, waitMs, waitForCode = true) {
|
|
266
280
|
const deadline = Date.now() + waitMs;
|
|
267
281
|
for (;;) {
|
|
268
282
|
const pending = readPending(home);
|
|
@@ -279,7 +293,7 @@ export async function finishLogin(home, waitMs) {
|
|
|
279
293
|
remove(files(home).login);
|
|
280
294
|
continue;
|
|
281
295
|
}
|
|
282
|
-
if (Date.now() >= deadline)
|
|
296
|
+
if ((!waitForCode && !pending.trading) || Date.now() >= deadline)
|
|
283
297
|
return null;
|
|
284
298
|
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
285
299
|
}
|
package/dist/mcp.js
CHANGED
|
@@ -74,11 +74,11 @@ function relayOf(credentials) {
|
|
|
74
74
|
function asPerson(credentials, relayUrl) {
|
|
75
75
|
return credentials && credentials.relayUrl === relayUrl ? { Authorization: `Bearer ${credentials.token}` } : {};
|
|
76
76
|
}
|
|
77
|
-
/** A login
|
|
77
|
+
/** A login exchanging a code gets a moment to finish
|
|
78
78
|
* (login.ts), so no call goes out as nobody, or as the account it replaces. */
|
|
79
79
|
async function settled(home) {
|
|
80
80
|
if (readPending(home))
|
|
81
|
-
await finishLogin(home, 15_000).catch(() => null);
|
|
81
|
+
await finishLogin(home, 15_000, false).catch(() => null);
|
|
82
82
|
return readPending(home) ? null : readCredentials(home);
|
|
83
83
|
}
|
|
84
84
|
export const thisComputer = {
|
|
@@ -89,8 +89,10 @@ export const thisComputer = {
|
|
|
89
89
|
await ask(files(home).socket, { op: "read", sessionId: seat.sessionId, roomId: seat.roomId, after });
|
|
90
90
|
},
|
|
91
91
|
drop: async (home, seat) => {
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
await ensureDaemon(home);
|
|
93
|
+
const dropped = await ask(files(home).socket, { op: "drop", sessionId: seat.sessionId, roomId: seat.roomId });
|
|
94
|
+
if (!dropped.ok)
|
|
95
|
+
throw new Error(dropped.error);
|
|
94
96
|
},
|
|
95
97
|
};
|
|
96
98
|
function cached(path) {
|
|
@@ -145,9 +147,10 @@ export function stationTools(home, post = postToAgent, computer = thisComputer,
|
|
|
145
147
|
const credentials = await settled(home);
|
|
146
148
|
let relayUrl = relayOf(credentials);
|
|
147
149
|
let roomId = null;
|
|
150
|
+
let inviteToken;
|
|
148
151
|
if (typeof args.room === "string") {
|
|
149
152
|
try {
|
|
150
|
-
({ relayUrl, roomId } = roomRef(credentials, args.room));
|
|
153
|
+
({ relayUrl, roomId, inviteToken } = roomRef(credentials, args.room));
|
|
151
154
|
}
|
|
152
155
|
catch {
|
|
153
156
|
// Not a room this computer can read; the tool says what is wrong with it.
|
|
@@ -168,9 +171,13 @@ export function stationTools(home, post = postToAgent, computer = thisComputer,
|
|
|
168
171
|
// Says why when this is not an agent's session that can hold a seat.
|
|
169
172
|
// The seat's name, when the call gives one (room_wait's `name`), as station join --name.
|
|
170
173
|
const name = typeof args.name === "string" && args.name.trim() ? args.name.trim() : null;
|
|
171
|
-
|
|
174
|
+
const invite = inviteToken ? `?${new URLSearchParams({ invite_token: inviteToken })}` : "";
|
|
175
|
+
seat = await computer.takeSeat(home, caller ?? computer.session(worker), `${relayUrl}/${roomId}${invite}`, name);
|
|
172
176
|
joined = true;
|
|
173
177
|
}
|
|
178
|
+
if (!seat && roomId && caller) {
|
|
179
|
+
seat = loadSeats(files(home).seats).find((s) => s.left && s.sessionId === caller.id && s.roomId === roomId && s.relayUrl === relayUrl) ?? null;
|
|
180
|
+
}
|
|
174
181
|
const headers = ours(folded);
|
|
175
182
|
if (seat) {
|
|
176
183
|
const auth = authFor(seat, credentials);
|
|
@@ -179,7 +186,7 @@ export function stationTools(home, post = postToAgent, computer = thisComputer,
|
|
|
179
186
|
if (auth.participant)
|
|
180
187
|
headers["X-Participant"] = auth.participant;
|
|
181
188
|
headers["X-Station-After"] = String(seat.after);
|
|
182
|
-
if (delivers(seat.harness))
|
|
189
|
+
if (!seat.left && delivers(seat.harness))
|
|
183
190
|
headers["X-Station-Delivered"] = "1";
|
|
184
191
|
if (joined)
|
|
185
192
|
headers["X-Station-Joined"] = "1";
|
|
@@ -188,7 +195,7 @@ export function stationTools(home, post = postToAgent, computer = thisComputer,
|
|
|
188
195
|
Object.assign(headers, asPerson(credentials, relayUrl));
|
|
189
196
|
const result = (await post(relayUrl, headers, "tools/call", { name, arguments: args }));
|
|
190
197
|
const after = result._meta?.["station/after"];
|
|
191
|
-
if (seat && typeof after === "number" && after > seat.after) {
|
|
198
|
+
if (seat && !seat.left && typeof after === "number" && after > seat.after) {
|
|
192
199
|
// The seat's place moves, so the next read starts after these.
|
|
193
200
|
await computer.read(home, seat, after).catch(() => undefined);
|
|
194
201
|
}
|
package/dist/relay.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// describes for curl, with the seat's credential: the room's token for a
|
|
3
3
|
// pasted room, or this computer's sign-in.
|
|
4
4
|
import { fetchAsCaller } from "./caller.js";
|
|
5
|
+
import { DEFAULT_RELAY, DEFAULT_WEB } from "./home.js";
|
|
5
6
|
export class RelayError extends Error {
|
|
6
7
|
status;
|
|
7
8
|
constructor(status, message) {
|
|
@@ -43,8 +44,8 @@ export async function call(base, path, auth, init = {}) {
|
|
|
43
44
|
}
|
|
44
45
|
return (response.status === 204 ? undefined : await response.json());
|
|
45
46
|
}
|
|
46
|
-
/** A room URL
|
|
47
|
-
export function parseRoomUrl(url) {
|
|
47
|
+
/** A relay room URL, or a room page on Station's website. */
|
|
48
|
+
export function parseRoomUrl(url, credentials = null) {
|
|
48
49
|
// The paste is a sentence ("Come join my Station room. To get started, run
|
|
49
50
|
// curl -s <url> and follow the steps there."), so an agent may copy a
|
|
50
51
|
// period, or the link inside quotes or angle brackets.
|
|
@@ -56,9 +57,13 @@ export function parseRoomUrl(url) {
|
|
|
56
57
|
catch {
|
|
57
58
|
throw new Error(`Not a room URL: ${url}`);
|
|
58
59
|
}
|
|
59
|
-
const
|
|
60
|
+
const webRelay = parsed.origin === new URL(credentials?.webUrl ?? DEFAULT_WEB).origin
|
|
61
|
+
? credentials?.relayUrl ?? DEFAULT_RELAY
|
|
62
|
+
: parsed.origin === DEFAULT_WEB ? DEFAULT_RELAY : null;
|
|
63
|
+
const page = webRelay ? parsed.pathname.match(/^\/b\/([0-9a-f-]{36})(?:\/.*)?$/i) : null;
|
|
64
|
+
const roomId = page?.[1] ?? parsed.pathname.replace(/^\/+|\/+$/g, "");
|
|
60
65
|
if (!/^[0-9a-f-]{36}$/i.test(roomId))
|
|
61
66
|
throw new Error(`Not a room URL: ${url}`);
|
|
62
67
|
// The room's invite token, when the link carries it (?invite_token=).
|
|
63
|
-
return { relayUrl: parsed.origin, roomId, inviteToken: parsed.searchParams.get("invite_token") || null };
|
|
68
|
+
return { relayUrl: page && webRelay ? webRelay : parsed.origin, roomId, inviteToken: parsed.searchParams.get("invite_token") || null };
|
|
64
69
|
}
|
package/dist/rooms.js
CHANGED
|
@@ -75,8 +75,8 @@ export function openedLines(opened) {
|
|
|
75
75
|
export function roomRef(credentials, room) {
|
|
76
76
|
const trimmed = room.trim();
|
|
77
77
|
if (/^https?:\/\//i.test(trimmed)) {
|
|
78
|
-
const { relayUrl, roomId } = parseRoomUrl(trimmed);
|
|
79
|
-
return { relayUrl, roomId };
|
|
78
|
+
const { relayUrl, roomId, inviteToken } = parseRoomUrl(trimmed, credentials);
|
|
79
|
+
return { relayUrl, roomId, ...(inviteToken ? { inviteToken } : {}) };
|
|
80
80
|
}
|
|
81
81
|
const id = trimmed.replace(/^[<("'`]+|[>)"'`.,;:!?]+$/g, "");
|
|
82
82
|
if (!/^[0-9a-f-]{36}$/i.test(id))
|
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,39 @@
|
|
|
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 { DEFAULT_WEB, files, readCredentials, writeJson } from "./home.js";
|
|
11
|
+
import { cancelLogin, claimSeat, elsewhere, loginLabel, readPending } from "./login.js";
|
|
12
|
+
import { call } from "./relay.js";
|
|
13
|
+
/** "November 26": the day the rooms lock, as the email says it. */
|
|
14
|
+
export function lockDay(locksAt) {
|
|
15
|
+
return new Date(locksAt).toLocaleDateString("en-US", { month: "long", day: "numeric", timeZone: "UTC" });
|
|
16
|
+
}
|
|
17
|
+
/** Signs the person up, saves this computer's sign-in, and returns what to print. */
|
|
18
|
+
export async function signUp(home, relayUrl, webUrl, email, me = "station", label = loginLabel(hostname(), elsewhere())) {
|
|
19
|
+
const saved = readCredentials(home);
|
|
20
|
+
// A computer already signed in here says so: the relay sends the email
|
|
21
|
+
// again for a sign-up that waits, and refuses one that has an account.
|
|
22
|
+
const auth = saved && saved.relayUrl === relayUrl ? { token: saved.token } : null;
|
|
23
|
+
const answer = await call(relayUrl, "/signup", auth, { body: { email, label } });
|
|
24
|
+
const day = lockDay(answer.locks_at);
|
|
25
|
+
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.`;
|
|
26
|
+
const fix = `Wrong address? Run: ${me} signup --email <the right one>`;
|
|
27
|
+
if (!answer.token) {
|
|
28
|
+
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];
|
|
29
|
+
}
|
|
30
|
+
// Seats this computer took with no sign-in were waiting on a login link to become the person's.
|
|
31
|
+
const claims = readPending(home)?.relayUrl === relayUrl ? (readPending(home)?.claims ?? []) : [];
|
|
32
|
+
cancelLogin(home);
|
|
33
|
+
const site = webUrl === DEFAULT_WEB ? {} : { webUrl };
|
|
34
|
+
const credentials = { relayUrl, ...site, token: answer.token, userId: answer.user_id, name: answer.name ?? answer.email.split("@")[0] };
|
|
35
|
+
writeJson(files(home).credentials, credentials);
|
|
36
|
+
for (const claim of claims)
|
|
37
|
+
await claimSeat(relayUrl, claim, answer.token);
|
|
38
|
+
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];
|
|
39
|
+
}
|
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.4",
|
|
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",
|