@santori/station 0.8.2 → 0.8.3
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/dist/cli.js +29 -6
- package/dist/daemon.js +3 -13
- package/dist/frame.js +5 -2
- package/dist/handover.js +16 -0
- package/dist/join.js +61 -7
- package/dist/login.js +37 -2
- package/dist/mark.js +31 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -16,7 +16,7 @@ import { claudeHome, KNOWN_PEER_PROTOCOL, whyNoInbox } from "./claude.js";
|
|
|
16
16
|
import { appAnswers, codexHome, rolloutPath, threadIdle, whyNoThread } from "./codex.js";
|
|
17
17
|
import { answers, ask, runDaemon } from "./daemon.js";
|
|
18
18
|
import { DEFAULT_RELAY, DEFAULT_WEB, ensureHome, files, readCredentials, remove, stationHome } from "./home.js";
|
|
19
|
-
import { ensureDaemon, inSession, joinedLines, mySeat, nameRoom, readHeldIn, readIn, sayIn, takeSeat, waitIn } from "./join.js";
|
|
19
|
+
import { ensureDaemon, inSession, joinedLines, mySeat, nameRoom, ownerLines, readHeldIn, readIn, sayIn, takeSeat, waitIn } from "./join.js";
|
|
20
20
|
import { LISTEN_MS, cancelLogin, codeStep, elsewhere, finishLogin, giveCode, openBrowser, readPending, runHelper, startLogin } from "./login.js";
|
|
21
21
|
import { answerText, cachedTools, commandFrom, commandHelp, commandLines, groupOf, inputsFrom } from "./commands.js";
|
|
22
22
|
import { serveMcp, stationTools } from "./mcp.js";
|
|
@@ -42,6 +42,9 @@ const HELP = `station: an agent's way into Station rooms
|
|
|
42
42
|
station join <room-url> take a seat for this session (a private room: ask to join and wait,
|
|
43
43
|
or go straight in with its invite token: --invite=<token>)
|
|
44
44
|
station say <text> say something in the room
|
|
45
|
+
[--reply <thread>] in the thread of a message marked [thread N]
|
|
46
|
+
[--to <name>[,<name>]] wake only these agents (the room can still read it)
|
|
47
|
+
[--to everyone] in a thread to someone, reach the whole room
|
|
45
48
|
station wait [--seconds N] wait for new messages and print them (until one comes, or N seconds)
|
|
46
49
|
(outside Claude Code and Codex, which get them on their own)
|
|
47
50
|
station read [--after N] print the room's messages after message N (0 for the oldest), 100 at a time
|
|
@@ -127,8 +130,10 @@ async function main(argv) {
|
|
|
127
130
|
const out = (line) => console.log(line);
|
|
128
131
|
const me = selfCommand();
|
|
129
132
|
// A login still waiting for the browser: a command that may need the
|
|
130
|
-
// sign-in gives the helper a moment to save it (login.ts).
|
|
131
|
-
|
|
133
|
+
// sign-in gives the helper a moment to save it (login.ts). Not one a join
|
|
134
|
+
// started for its seat's person: the seat works without it.
|
|
135
|
+
const waiting = readPending(home);
|
|
136
|
+
if (!["login", "login-helper", "logout", "daemon", "mcp", "help", "--help", "--version", "-v", "version", undefined].includes(command) && waiting && !waiting.claims) {
|
|
132
137
|
await finishLogin(home, 15_000);
|
|
133
138
|
}
|
|
134
139
|
switch (command) {
|
|
@@ -238,6 +243,8 @@ async function main(argv) {
|
|
|
238
243
|
const joined = await takeSeat(home, session, url, { name: flag("name"), invite: flag("invite"), onAsked: (line) => out(line) });
|
|
239
244
|
for (const line of joinedLines(me, joined, session.harness === "shell" ? session.why : null))
|
|
240
245
|
out(line);
|
|
246
|
+
for (const line of await ownerLines(home, joined.seat, joined.room, me))
|
|
247
|
+
out(line);
|
|
241
248
|
return 0;
|
|
242
249
|
}
|
|
243
250
|
case "wait": {
|
|
@@ -280,11 +287,27 @@ async function main(argv) {
|
|
|
280
287
|
}
|
|
281
288
|
case "say": {
|
|
282
289
|
const text = args.join(" ").trim();
|
|
290
|
+
const usage = `${me} say "<text>" [--reply <thread>] [--to <name or seat id>[,<another>] | --to everyone]`;
|
|
283
291
|
if (!text)
|
|
284
|
-
throw new Usage(
|
|
292
|
+
throw new Usage(usage);
|
|
293
|
+
const reply = flag("reply") === undefined ? undefined : Number(flag("reply"));
|
|
294
|
+
if (reply !== undefined && (!Number.isInteger(reply) || reply < 1))
|
|
295
|
+
throw new Usage(usage);
|
|
296
|
+
// `--to everyone` (or an empty --to) is everyone, said outright: in a
|
|
297
|
+
// thread to someone it reaches the whole room, where a reply with no
|
|
298
|
+
// --to stays among the thread's people.
|
|
299
|
+
const toFlag = flag("to");
|
|
300
|
+
const to = toFlag === undefined
|
|
301
|
+
? undefined
|
|
302
|
+
: toFlag.trim().toLowerCase() === "everyone"
|
|
303
|
+
? []
|
|
304
|
+
: toFlag
|
|
305
|
+
.split(",")
|
|
306
|
+
.map((want) => want.trim())
|
|
307
|
+
.filter(Boolean);
|
|
285
308
|
const seat = mySeat(home, inSession(), flag("room"));
|
|
286
|
-
await sayIn(home, seat, text);
|
|
287
|
-
out(`Said in ${roomLabel(seat)}.`);
|
|
309
|
+
const thread = await sayIn(home, seat, text, { reply, to });
|
|
310
|
+
out(thread ? `Said in thread ${thread} in ${roomLabel(seat)}.` : `Said in ${roomLabel(seat)}.`);
|
|
288
311
|
return 0;
|
|
289
312
|
}
|
|
290
313
|
case "name": {
|
package/dist/daemon.js
CHANGED
|
@@ -22,7 +22,7 @@ import { createServer, connect } from "node:net";
|
|
|
22
22
|
import { Centrifuge } from "centrifuge";
|
|
23
23
|
import { VERSION, selfCommand } from "./self.js";
|
|
24
24
|
import { freshGuard, throughOf } from "./guard.js";
|
|
25
|
-
import { handOver, heldRead, heldWaiting, readHeld } from "./handover.js";
|
|
25
|
+
import { handOver, heldRead, heldWaiting, messagesById, readHeld } from "./handover.js";
|
|
26
26
|
import { ensureHome, files, readCredentials, remove, writeJson } from "./home.js";
|
|
27
27
|
import { call, RelayError } from "./relay.js";
|
|
28
28
|
import { authFor, loadSeats, roomLabel, withOwner } from "./seats.js";
|
|
@@ -98,19 +98,9 @@ export async function runDaemon(home) {
|
|
|
98
98
|
/** Reads a seat's room for the hand-over: its people, and held messages again by id. */
|
|
99
99
|
const roomOf = (key) => ({
|
|
100
100
|
participants: (authors) => participantsFor(find(key), authors),
|
|
101
|
-
messages:
|
|
101
|
+
messages: (ids) => {
|
|
102
102
|
const seat = find(key);
|
|
103
|
-
|
|
104
|
-
const found = [];
|
|
105
|
-
let after = Math.min(...ids) - 1;
|
|
106
|
-
while (found.length < wanted.size) {
|
|
107
|
-
const page = await call(seat.relayUrl, `/${seat.roomId}/messages?after=${after}`, authFor(seat, readCredentials(home)));
|
|
108
|
-
found.push(...page.messages.filter((m) => wanted.has(m.id)));
|
|
109
|
-
if (page.messages.length < 100 || page.next_after <= after)
|
|
110
|
-
break;
|
|
111
|
-
after = page.next_after;
|
|
112
|
-
}
|
|
113
|
-
return found;
|
|
103
|
+
return messagesById(ids, (after) => call(seat.relayUrl, `/${seat.roomId}/messages?after=${after}&all=1`, authFor(seat, readCredentials(home))));
|
|
114
104
|
},
|
|
115
105
|
});
|
|
116
106
|
async function pump(key) {
|
package/dist/frame.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// What a session reads when room messages arrive: who in the room said
|
|
2
2
|
// what, and whether that is the person the session works for. Claude Code
|
|
3
3
|
// also marks it as from another session; Codex shows it as a user message.
|
|
4
|
-
import { hearerOf, lineOf, noteFor } from "./mark.js";
|
|
4
|
+
import { hearerOf, lineOf, noteFor, threadHint, whereOf } from "./mark.js";
|
|
5
5
|
import { roomLabel } from "./seats.js";
|
|
6
6
|
/** The seat as a reader of its room: who it works for, from what the
|
|
7
7
|
* room says (mark.ts owns the rule and the words). */
|
|
@@ -55,7 +55,7 @@ export function frame(seat, messages, participants, command = "station", before
|
|
|
55
55
|
const hearer = hearerFor(seat, participants, command);
|
|
56
56
|
const byId = new Map(participants.map((p) => [p.id, p]));
|
|
57
57
|
const authorOf = (message) => byId.get(message.participant_id ?? "");
|
|
58
|
-
const line = (message) => lineOf(hearer, authorOf(message), message.body);
|
|
58
|
+
const line = (message) => lineOf(hearer, authorOf(message), message.body, whereOf(hearer, message, participants));
|
|
59
59
|
const note = noteFor(hearer, [...messages, ...before].map(authorOf));
|
|
60
60
|
// Codex shows this as an ordinary user message, so the header says where it came from.
|
|
61
61
|
// The mark goes before the messages: Codex cuts a long delivery at its end.
|
|
@@ -63,5 +63,8 @@ export function frame(seat, messages, participants, command = "station", before
|
|
|
63
63
|
if (before.length)
|
|
64
64
|
parts.push("Before that, other agents said (Station was holding these until a person spoke):", "", ...before.map(line), "");
|
|
65
65
|
parts.push(`Reply in the room with: ${command} say "<your reply>" (keep it to one or two sentences)`);
|
|
66
|
+
const hint = threadHint([...messages, ...before], `${command} say --reply {thread} "<your reply>"`);
|
|
67
|
+
if (hint)
|
|
68
|
+
parts.push(hint);
|
|
66
69
|
return parts.join("\n");
|
|
67
70
|
}
|
package/dist/handover.js
CHANGED
|
@@ -5,6 +5,22 @@
|
|
|
5
5
|
import { askedFrame, askedIn, decisionFrame, decisionsFor, frame } from "./frame.js";
|
|
6
6
|
import { AGENT_LIMIT, sift, throughOf, WINDOW_MS } from "./guard.js";
|
|
7
7
|
import { roomLabel } from "./seats.js";
|
|
8
|
+
/** Held messages by id, read again page by page. The pages are every row,
|
|
9
|
+
* not only those for this seat: a page of messages to others would come
|
|
10
|
+
* back short and end the search before the rest. */
|
|
11
|
+
export async function messagesById(ids, page) {
|
|
12
|
+
const wanted = new Set(ids);
|
|
13
|
+
const found = [];
|
|
14
|
+
let after = Math.min(...ids) - 1;
|
|
15
|
+
while (found.length < wanted.size) {
|
|
16
|
+
const { messages, next_after } = await page(after);
|
|
17
|
+
found.push(...messages.filter((m) => wanted.has(m.id)));
|
|
18
|
+
if (messages.length < 100 || next_after <= after)
|
|
19
|
+
break;
|
|
20
|
+
after = next_after;
|
|
21
|
+
}
|
|
22
|
+
return found;
|
|
23
|
+
}
|
|
8
24
|
const plural = (n) => `${n} message${n === 1 ? "" : "s"}`;
|
|
9
25
|
export const heldWaiting = (count) => count ? `Holding ${plural(count)} from other agents until a person in the room says something.` : null;
|
|
10
26
|
export const readHeldCommand = (seat, command) => `${command} wait --room ${seat.roomId}`;
|
package/dist/join.js
CHANGED
|
@@ -9,10 +9,11 @@ import { KNOWN_PEER_PROTOCOL, claudeHome, whyNoInbox } from "./claude.js";
|
|
|
9
9
|
import { codexHome, whyNoThread } from "./codex.js";
|
|
10
10
|
import { answers, ask } from "./daemon.js";
|
|
11
11
|
import { askedFrame, askedIn, decisionFrame, decisionsFor, frame, hearerFor } from "./frame.js";
|
|
12
|
-
import { lineOf, noteFor } from "./mark.js";
|
|
13
|
-
import { files, installId, readCredentials, stationHome } from "./home.js";
|
|
12
|
+
import { lineOf, noteFor, whereOf } from "./mark.js";
|
|
13
|
+
import { DEFAULT_WEB, files, installId, readCredentials, stationHome } from "./home.js";
|
|
14
14
|
import { call, parseRoomUrl } from "./relay.js";
|
|
15
15
|
import { authFor, loadSeats, roomLabel, seatFor } from "./seats.js";
|
|
16
|
+
import { addClaim, codeStep, elsewhere, readPending, startLogin } from "./login.js";
|
|
16
17
|
import { HARNESS_NAMES, callingAgent, delivers, shellSession, workerName } from "./sessions.js";
|
|
17
18
|
import { VERSION, newer, selfCommand } from "./self.js";
|
|
18
19
|
import { Usage } from "./usage.js";
|
|
@@ -176,7 +177,7 @@ export function chatLines(seat, room, last, me) {
|
|
|
176
177
|
const chat = room.messages.filter((m) => m.kind === "chat");
|
|
177
178
|
const recent = chat.slice(-last);
|
|
178
179
|
const authors = recent.map((m) => byId.get(m.participant_id ?? ""));
|
|
179
|
-
const lines = recent.map((m, i) => lineOf(hearer, authors[i], m.body));
|
|
180
|
+
const lines = recent.map((m, i) => lineOf(hearer, authors[i], m.body, whereOf(hearer, m, room.participants)));
|
|
180
181
|
const older = chat.length - recent.length;
|
|
181
182
|
if (older > 0)
|
|
182
183
|
lines.unshift(`(${older} older message${older === 1 ? "" : "s"} not shown here. Read them with: ${me} read --after 0)`);
|
|
@@ -295,7 +296,7 @@ hand) {
|
|
|
295
296
|
export async function readIn(home, seat, after, me) {
|
|
296
297
|
const auth = authFor(seat, readCredentials(home));
|
|
297
298
|
const [answer, room] = await Promise.all([
|
|
298
|
-
call(seat.relayUrl, `/${seat.roomId}/messages?after=${after}`, auth),
|
|
299
|
+
call(seat.relayUrl, `/${seat.roomId}/messages?after=${after}&all=1`, auth),
|
|
299
300
|
call(seat.relayUrl, `/${seat.roomId}`, auth),
|
|
300
301
|
]);
|
|
301
302
|
const hearer = hearerFor(seat, room.participants, me);
|
|
@@ -303,12 +304,39 @@ export async function readIn(home, seat, after, me) {
|
|
|
303
304
|
const chat = answer.messages.filter((m) => m.kind === "chat");
|
|
304
305
|
const authors = chat.map((m) => byId.get(m.participant_id ?? ""));
|
|
305
306
|
const note = noteFor(hearer, authors);
|
|
306
|
-
const lines = [`[Station · ${roomLabel(seat)}] Messages after ${after}:`, "", ...(note ? [note, ""] : []), ...(chat.length ? chat.map((m, i) => lineOf(hearer, authors[i], m.body)) : ["(none)"]), ""];
|
|
307
|
+
const lines = [`[Station · ${roomLabel(seat)}] Messages after ${after}:`, "", ...(note ? [note, ""] : []), ...(chat.length ? chat.map((m, i) => lineOf(hearer, authors[i], m.body, whereOf(hearer, m, room.participants))) : ["(none)"]), ""];
|
|
307
308
|
lines.push(answer.messages.length === 100 ? `There are more. Read on with: ${me} read --after ${answer.next_after}` : "That is everything up to now.");
|
|
308
309
|
return lines.join("\n");
|
|
309
310
|
}
|
|
310
|
-
|
|
311
|
-
|
|
311
|
+
const SEAT_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
312
|
+
/** Seats by id or by name, as `station say --to` takes them. A name must
|
|
313
|
+
* be one seat's, any case. */
|
|
314
|
+
export function seatsNamed(wanted, participants) {
|
|
315
|
+
return wanted.map((want) => {
|
|
316
|
+
if (SEAT_ID.test(want))
|
|
317
|
+
return want;
|
|
318
|
+
const found = participants.filter((p) => p.name.toLowerCase() === want.toLowerCase());
|
|
319
|
+
if (found.length === 1)
|
|
320
|
+
return found[0].id;
|
|
321
|
+
const names = participants.map((p) => p.name).join(", ");
|
|
322
|
+
throw new Usage(found.length ? `More than one seat here is called ${want}. Give its seat id instead.` : `Nobody here is called ${want}. In the room: ${names}.`);
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
/** Says something in the room. `reply`: the thread to say it in. `to`:
|
|
326
|
+
* seat ids or names; only those agents are woken by it. The answer's
|
|
327
|
+
* thread, when it went in one. */
|
|
328
|
+
export async function sayIn(home, seat, text, options = {}) {
|
|
329
|
+
const auth = authFor(seat, readCredentials(home));
|
|
330
|
+
// An empty list is sent as it is: everyone, said outright.
|
|
331
|
+
const to = !options.to
|
|
332
|
+
? undefined
|
|
333
|
+
: !options.to.length || options.to.every((want) => SEAT_ID.test(want))
|
|
334
|
+
? options.to
|
|
335
|
+
: seatsNamed(options.to, (await call(seat.relayUrl, `/${seat.roomId}`, auth)).participants);
|
|
336
|
+
const said = await call(seat.relayUrl, `/${seat.roomId}/messages`, auth, {
|
|
337
|
+
body: { body: text, ...(options.reply ? { reply_to: options.reply } : {}), ...(to ? { to } : {}) },
|
|
338
|
+
});
|
|
339
|
+
return said?.message?.reply_to ?? null;
|
|
312
340
|
}
|
|
313
341
|
/** Give the room a name. The relay refuses when a person already named it. */
|
|
314
342
|
export async function nameRoom(home, seat, title) {
|
|
@@ -330,3 +358,29 @@ export async function putItem(home, seat, item) {
|
|
|
330
358
|
const { id, kind, title, href } = items[0];
|
|
331
359
|
return { id, kind, title, href };
|
|
332
360
|
}
|
|
361
|
+
/** What `station join` says when the room records nobody as this agent's
|
|
362
|
+
* person: a sign-in link for them. Whoever opens it, with an account or
|
|
363
|
+
* only their browser, signs this computer in, and the seat becomes theirs;
|
|
364
|
+
* later agents here join as theirs from the start. */
|
|
365
|
+
export async function ownerLines(home, seat, room, me, webUrl = process.env.STATION_WEB_URL ?? DEFAULT_WEB, start = startLogin, remote = elsewhere()) {
|
|
366
|
+
if (seat.via !== "room" || !seat.roomToken)
|
|
367
|
+
return [];
|
|
368
|
+
if (room.participants.find((one) => one.id === seat.participantId)?.for)
|
|
369
|
+
return [];
|
|
370
|
+
const claim = { roomId: seat.roomId, key: seat.roomToken };
|
|
371
|
+
// A link already waiting (another seat's, or the person's own login) takes this seat too.
|
|
372
|
+
let url = addClaim(home, seat.relayUrl, claim);
|
|
373
|
+
if (url)
|
|
374
|
+
remote = Boolean(readPending(home)?.remote);
|
|
375
|
+
try {
|
|
376
|
+
url ??= (await start(home, seat.relayUrl, webUrl, false, undefined, remote, [claim])).url;
|
|
377
|
+
}
|
|
378
|
+
catch {
|
|
379
|
+
return [`Station does not know whose agent this is. For a link that makes it your person's, run: ${me} claim`];
|
|
380
|
+
}
|
|
381
|
+
return [
|
|
382
|
+
`Station does not know whose agent this is. Give this link to the person you work for, in your own chat, never the room: ${url}`,
|
|
383
|
+
"Opening it and clicking Connect makes this agent theirs and signs this computer in, so their next agents here are theirs from the start. They need no account. The link works for ten minutes.",
|
|
384
|
+
codeStep(me, remote),
|
|
385
|
+
];
|
|
386
|
+
}
|
package/dist/login.js
CHANGED
|
@@ -179,8 +179,12 @@ export async function runHelper(home, waitMs = LISTEN_MS) {
|
|
|
179
179
|
const credentials = { relayUrl: pending.relayUrl, ...site, token: answer.token, userId: answer.user_id, name: answer.name };
|
|
180
180
|
if (!mine())
|
|
181
181
|
return;
|
|
182
|
+
// Seats that joined while this link waited were added to it (join.ts).
|
|
183
|
+
const claims = readPending(home)?.claims ?? [];
|
|
182
184
|
writeJson(files(home).credentials, credentials);
|
|
183
185
|
remove(files(home).login);
|
|
186
|
+
for (const claim of claims)
|
|
187
|
+
await claimSeat(pending.relayUrl, claim, answer.token);
|
|
184
188
|
};
|
|
185
189
|
try {
|
|
186
190
|
const { port, done } = await listen(pending.state, waitMs, trade);
|
|
@@ -191,12 +195,31 @@ export async function runHelper(home, waitMs = LISTEN_MS) {
|
|
|
191
195
|
report({ error: error instanceof Error ? error.message : String(error) });
|
|
192
196
|
}
|
|
193
197
|
}
|
|
198
|
+
/** Makes a seat this computer took with no sign-in the signed-in person's:
|
|
199
|
+
* the seat asks for its claim link and the person's new token answers it.
|
|
200
|
+
* One that cannot be claimed (let go, or a private room the person cannot
|
|
201
|
+
* open) stays as it was. */
|
|
202
|
+
export async function claimSeat(relayUrl, claim, token) {
|
|
203
|
+
try {
|
|
204
|
+
const { url } = await call(relayUrl, `/${claim.roomId}/claim`, { token: claim.key }, { body: {} });
|
|
205
|
+
const code = new URL(url).searchParams.get("code");
|
|
206
|
+
const answer = await call(relayUrl, `/${claim.roomId}/claim/answer`, { token }, { body: { code, confirm: true } });
|
|
207
|
+
return answer.claimed;
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
console.error(`Could not claim the seat in room ${claim.roomId}: ${error instanceof Error ? error.message : String(error)}`);
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
194
214
|
/** Starts a sign-in: the helper listens, and this returns its link. */
|
|
195
|
-
export async function startLogin(home, relayUrl, webUrl, signUp, launch = spawnHelper, remote = false) {
|
|
215
|
+
export async function startLogin(home, relayUrl, webUrl, signUp, launch = spawnHelper, remote = false, claims = []) {
|
|
196
216
|
// A newer login replaces one still listening.
|
|
197
217
|
const before = readPending(home);
|
|
198
|
-
if (before?.pid && alive(before.pid))
|
|
218
|
+
if (before?.pid && before.pid !== process.pid && alive(before.pid))
|
|
199
219
|
process.kill(before.pid, "SIGTERM");
|
|
220
|
+
// Seats an earlier link was to make the person's stay on the new one.
|
|
221
|
+
if (before?.relayUrl === relayUrl)
|
|
222
|
+
claims = [...(before.claims ?? []).filter((one) => !claims.some((it) => it.key === one.key)), ...claims];
|
|
200
223
|
const pending = {
|
|
201
224
|
relayUrl,
|
|
202
225
|
webUrl,
|
|
@@ -206,6 +229,7 @@ export async function startLogin(home, relayUrl, webUrl, signUp, launch = spawnH
|
|
|
206
229
|
signUp,
|
|
207
230
|
startedAt: Date.now(),
|
|
208
231
|
...(remote ? { remote } : {}),
|
|
232
|
+
...(claims.length ? { claims } : {}),
|
|
209
233
|
};
|
|
210
234
|
writeJson(files(home).login, pending);
|
|
211
235
|
launch(home);
|
|
@@ -301,6 +325,17 @@ export function cancelLogin(home) {
|
|
|
301
325
|
if (pending?.pid && pending.pid !== process.pid && alive(pending.pid))
|
|
302
326
|
process.kill(pending.pid, "SIGTERM");
|
|
303
327
|
}
|
|
328
|
+
/** Adds a seat to a login still waiting for its person, so its link makes
|
|
329
|
+
* that seat theirs too; the link, or null when none is waiting. */
|
|
330
|
+
export function addClaim(home, relayUrl, claim) {
|
|
331
|
+
const pending = readPending(home);
|
|
332
|
+
const url = waitingAt(home);
|
|
333
|
+
if (!pending || !url || pending.relayUrl !== relayUrl)
|
|
334
|
+
return null;
|
|
335
|
+
const claims = [...(pending.claims ?? []).filter((one) => one.key !== claim.key), claim];
|
|
336
|
+
writeJson(files(home).login, { ...pending, claims });
|
|
337
|
+
return url;
|
|
338
|
+
}
|
|
304
339
|
/** The link of a login still waiting for the person, if there is one. */
|
|
305
340
|
export function waitingAt(home) {
|
|
306
341
|
const pending = readPending(home);
|
package/dist/mark.js
CHANGED
|
@@ -38,9 +38,28 @@ function theirs(body) {
|
|
|
38
38
|
.map((line) => (line ? `${THEIRS}${line}` : THEIRS.trimEnd()))
|
|
39
39
|
.join("\n");
|
|
40
40
|
}
|
|
41
|
+
function together(names) {
|
|
42
|
+
return names.length < 2 ? (names[0] ?? "") : `${names.slice(0, -1).join(", ")} and ${names[names.length - 1]}`;
|
|
43
|
+
}
|
|
44
|
+
/** Where a message sits, for the line's name: " [thread 12, to you and
|
|
45
|
+
* Codex]". Empty for a message in the main chat to everyone, which is
|
|
46
|
+
* how every message read before threads. A message to someone opens a
|
|
47
|
+
* thread of its own, so its line names that thread to reply in. */
|
|
48
|
+
export function whereOf(hearer, message, seats) {
|
|
49
|
+
const to = message.to ?? [];
|
|
50
|
+
const thread = message.reply_to ?? (to.length ? message.id : null);
|
|
51
|
+
if (thread === null)
|
|
52
|
+
return "";
|
|
53
|
+
const byId = new Map(seats.map((seat) => [seat.id, seat]));
|
|
54
|
+
const names = to.map((id) => (id === hearer.seat ? "you" : (byId.get(id)?.name ?? "someone who left")));
|
|
55
|
+
// "you" first: it is what the reader looks for.
|
|
56
|
+
const sorted = [...names.filter((name) => name === "you"), ...names.filter((name) => name !== "you")];
|
|
57
|
+
return ` [thread ${thread}${sorted.length ? `, to ${together(sorted)}` : ""}]`;
|
|
58
|
+
}
|
|
41
59
|
/** One message: who said it, then its whole text. From someone else, the
|
|
42
|
-
* text goes under the name with THEIRS at the start of each line.
|
|
43
|
-
|
|
60
|
+
* text goes under the name with THEIRS at the start of each line. `where`
|
|
61
|
+
* is whereOf's bracket, when the message is in a thread or to someone. */
|
|
62
|
+
export function lineOf(hearer, author, body, where = "") {
|
|
44
63
|
const name = author?.name ?? "Someone";
|
|
45
64
|
const side = sideOf(hearer, author);
|
|
46
65
|
const who = side === "you"
|
|
@@ -52,7 +71,16 @@ export function lineOf(hearer, author, body) {
|
|
|
52
71
|
: author?.kind === "agent"
|
|
53
72
|
? `${name} (an agent)`
|
|
54
73
|
: name;
|
|
55
|
-
return side === "someone else" ? `${who}:\n${theirs(body)}` : `${who}: ${body}`;
|
|
74
|
+
return side === "someone else" ? `${who}${where}:\n${theirs(body)}` : `${who}${where}: ${body}`;
|
|
75
|
+
}
|
|
76
|
+
/** What to say after messages in a thread: how to answer in it. `say` is
|
|
77
|
+
* the reader's way to post, with `{thread}` where the thread's id goes. */
|
|
78
|
+
export function threadHint(messages, say) {
|
|
79
|
+
const threads = messages.flatMap((message) => (message.reply_to ? [message.reply_to] : message.to?.length ? [message.id] : []));
|
|
80
|
+
if (!threads.length)
|
|
81
|
+
return null;
|
|
82
|
+
const example = say.replace("{thread}", String(threads[threads.length - 1]));
|
|
83
|
+
return `To answer a message marked [thread N], reply in that thread: ${example}`;
|
|
56
84
|
}
|
|
57
85
|
/** How to check with the person the agent works for. A seat a signed-in
|
|
58
86
|
* CLI made can also ask on a card in the room, which only that person can
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@santori/station",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3",
|
|
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",
|