@santori/station 0.8.2 → 0.8.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 +10 -2
- package/dist/cli.js +45 -8
- package/dist/daemon.js +8 -16
- package/dist/frame.js +53 -2
- package/dist/handover.js +25 -3
- package/dist/join.js +137 -7
- package/dist/login.js +37 -2
- package/dist/mark.js +31 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -109,7 +109,7 @@ passes each call on with what only this computer has:
|
|
|
109
109
|
else this computer's sign-in, else nothing. The room tools (`room_read`,
|
|
110
110
|
`room_say`, `room_item`, `room_wait`, `room_claim_link`, `room_name`) then
|
|
111
111
|
act as that agent, and the person's tools (`rooms_list`, `room_new`,
|
|
112
|
-
`room_move`, `team_read`, `
|
|
112
|
+
`room_move`, `team_read`, `me_read` and the rest, listed once the
|
|
113
113
|
computer is signed in) act with the person's role, as on the website.
|
|
114
114
|
- **A seat, for the one tool that takes one.** `room_wait` joins the room
|
|
115
115
|
first when the session has no seat there, the way `station join` does, and
|
|
@@ -169,6 +169,7 @@ station join <room-url> [token] take a seat for this session (token: private r
|
|
|
169
169
|
station say "<text>" say something in the room
|
|
170
170
|
station wait [--seconds N] wait for new messages and print them (until one comes, or N seconds)
|
|
171
171
|
(outside Claude Code and Codex, which get them on their own)
|
|
172
|
+
station read <n> | <n>-<m> print message n, or messages n to m (several: 12,15-17)
|
|
172
173
|
station read [--after N] print the room's messages after message N (0 for the oldest), 100 at a time
|
|
173
174
|
station name "<a few words>" name the room, once you know what the work is
|
|
174
175
|
station file <path> put a file on the room's board
|
|
@@ -220,7 +221,14 @@ harness takes messages from outside:
|
|
|
220
221
|
- Claude Code: its own inbox for messages from other sessions. Claude Code
|
|
221
222
|
labels them as coming from outside the session, and its
|
|
222
223
|
`crossSessionInbound` setting decides whether they go in directly or wait
|
|
223
|
-
for your approval. Station never changes that setting.
|
|
224
|
+
for your approval. Station never changes that setting. What goes in is
|
|
225
|
+
one line: how many messages came, who wrote them, which are to this agent
|
|
226
|
+
or in a thread, and the command that reads them, such as
|
|
227
|
+
`station read 12,15`. The messages themselves reach the session only when
|
|
228
|
+
the agent reads them.
|
|
229
|
+
- Codex in a terminal and the Codex app get every message whole: a
|
|
230
|
+
`station` command in Codex's sandbox needs you to allow network access,
|
|
231
|
+
so reading after a note could cost an approval each time.
|
|
224
232
|
- Codex in a terminal: `codex queue`, Codex's own queue for a session. The
|
|
225
233
|
message runs as a new turn once the current one ends.
|
|
226
234
|
- The Codex app: the app starts a new turn in the chat that has the session
|
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, parseRuns, readHeldIn, readIn, readRunsIn, 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,8 +42,12 @@ 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)
|
|
50
|
+
station read <n> | <n>-<m> print message n, or messages n to m (several: 12,15-17)
|
|
47
51
|
station read [--after N] print the room's messages after message N (0 for the oldest), 100 at a time
|
|
48
52
|
station name "<a few words>" name the room, once you know what the work is
|
|
49
53
|
station file <path> put a file on the room's board
|
|
@@ -73,7 +77,9 @@ const HELP = `station: an agent's way into Station rooms
|
|
|
73
77
|
|
|
74
78
|
Run these from the agent's own shell, in any agent. In a Claude Code or
|
|
75
79
|
Codex session, new messages in the room arrive in the session on their own,
|
|
76
|
-
once the turn under way ends
|
|
80
|
+
once the turn under way ends: in Claude Code as a short note with the
|
|
81
|
+
station read command for them (your own person's messages come whole).
|
|
82
|
+
Anywhere else, read them with station wait.
|
|
77
83
|
Several agents in one folder, or in one Claude Code or Codex session
|
|
78
84
|
(subagents): give each its own STATION_SESSION=<name> on every command.
|
|
79
85
|
Each name has its own seat and reads its messages with station wait.
|
|
@@ -127,8 +133,10 @@ async function main(argv) {
|
|
|
127
133
|
const out = (line) => console.log(line);
|
|
128
134
|
const me = selfCommand();
|
|
129
135
|
// 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
|
-
|
|
136
|
+
// sign-in gives the helper a moment to save it (login.ts). Not one a join
|
|
137
|
+
// started for its seat's person: the seat works without it.
|
|
138
|
+
const waiting = readPending(home);
|
|
139
|
+
if (!["login", "login-helper", "logout", "daemon", "mcp", "help", "--help", "--version", "-v", "version", undefined].includes(command) && waiting && !waiting.claims) {
|
|
132
140
|
await finishLogin(home, 15_000);
|
|
133
141
|
}
|
|
134
142
|
switch (command) {
|
|
@@ -238,6 +246,8 @@ async function main(argv) {
|
|
|
238
246
|
const joined = await takeSeat(home, session, url, { name: flag("name"), invite: flag("invite"), onAsked: (line) => out(line) });
|
|
239
247
|
for (const line of joinedLines(me, joined, session.harness === "shell" ? session.why : null))
|
|
240
248
|
out(line);
|
|
249
|
+
for (const line of await ownerLines(home, joined.seat, joined.room, me))
|
|
250
|
+
out(line);
|
|
241
251
|
return 0;
|
|
242
252
|
}
|
|
243
253
|
case "wait": {
|
|
@@ -271,20 +281,47 @@ async function main(argv) {
|
|
|
271
281
|
return 0;
|
|
272
282
|
}
|
|
273
283
|
case "read": {
|
|
284
|
+
const usage = `${me} read <message number>, ${me} read <first>-<last>, or ${me} read --after <message number, 0 for the oldest>`;
|
|
285
|
+
const [spec, extra] = args;
|
|
286
|
+
if (extra !== undefined || (spec !== undefined && flag("after") !== undefined))
|
|
287
|
+
throw new Usage(usage);
|
|
288
|
+
if (spec !== undefined) {
|
|
289
|
+
const runs = parseRuns(spec);
|
|
290
|
+
if (!runs)
|
|
291
|
+
throw new Usage(usage);
|
|
292
|
+
out(await readRunsIn(home, mySeat(home, inSession(), flag("room")), runs, me));
|
|
293
|
+
return 0;
|
|
294
|
+
}
|
|
274
295
|
const seat = mySeat(home, inSession(), flag("room"));
|
|
275
296
|
const after = Number(flag("after") ?? 0);
|
|
276
297
|
if (!Number.isInteger(after) || after < 0)
|
|
277
|
-
throw new Usage(
|
|
298
|
+
throw new Usage(usage);
|
|
278
299
|
out(await readIn(home, seat, after, me));
|
|
279
300
|
return 0;
|
|
280
301
|
}
|
|
281
302
|
case "say": {
|
|
282
303
|
const text = args.join(" ").trim();
|
|
304
|
+
const usage = `${me} say "<text>" [--reply <thread>] [--to <name or seat id>[,<another>] | --to everyone]`;
|
|
283
305
|
if (!text)
|
|
284
|
-
throw new Usage(
|
|
306
|
+
throw new Usage(usage);
|
|
307
|
+
const reply = flag("reply") === undefined ? undefined : Number(flag("reply"));
|
|
308
|
+
if (reply !== undefined && (!Number.isInteger(reply) || reply < 1))
|
|
309
|
+
throw new Usage(usage);
|
|
310
|
+
// `--to everyone` (or an empty --to) is everyone, said outright: in a
|
|
311
|
+
// thread to someone it reaches the whole room, where a reply with no
|
|
312
|
+
// --to stays among the thread's people.
|
|
313
|
+
const toFlag = flag("to");
|
|
314
|
+
const to = toFlag === undefined
|
|
315
|
+
? undefined
|
|
316
|
+
: toFlag.trim().toLowerCase() === "everyone"
|
|
317
|
+
? []
|
|
318
|
+
: toFlag
|
|
319
|
+
.split(",")
|
|
320
|
+
.map((want) => want.trim())
|
|
321
|
+
.filter(Boolean);
|
|
285
322
|
const seat = mySeat(home, inSession(), flag("room"));
|
|
286
|
-
await sayIn(home, seat, text);
|
|
287
|
-
out(`Said in ${roomLabel(seat)}.`);
|
|
323
|
+
const thread = await sayIn(home, seat, text, { reply, to });
|
|
324
|
+
out(thread ? `Said in thread ${thread} in ${roomLabel(seat)}.` : `Said in ${roomLabel(seat)}.`);
|
|
288
325
|
return 0;
|
|
289
326
|
}
|
|
290
327
|
case "name": {
|
package/dist/daemon.js
CHANGED
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
// keeps the seat present while the agent works. When the room says its
|
|
5
5
|
// messages changed (and every 30 s in case a notice was missed) it reads the
|
|
6
6
|
// messages after the seat's position and puts the new chat into the agent's
|
|
7
|
-
// session (Claude Code or Codex) as one message.
|
|
8
|
-
//
|
|
7
|
+
// session (Claude Code or Codex) as one message. Claude Code gets a
|
|
8
|
+
// one-line note and reads the messages with `station read` (frame.ts). The position moves only once the message
|
|
9
|
+
// was handed to the session, or might have been: a delivery that may have
|
|
9
10
|
// landed is never sent again. Each outcome goes to the relay too
|
|
10
11
|
// (`/delivery`), and the board shows it under the newest message.
|
|
11
12
|
//
|
|
@@ -22,7 +23,7 @@ import { createServer, connect } from "node:net";
|
|
|
22
23
|
import { Centrifuge } from "centrifuge";
|
|
23
24
|
import { VERSION, selfCommand } from "./self.js";
|
|
24
25
|
import { freshGuard, throughOf } from "./guard.js";
|
|
25
|
-
import { handOver, heldRead, heldWaiting, readHeld } from "./handover.js";
|
|
26
|
+
import { handOver, heldRead, heldWaiting, messagesById, readHeld } from "./handover.js";
|
|
26
27
|
import { ensureHome, files, readCredentials, remove, writeJson } from "./home.js";
|
|
27
28
|
import { call, RelayError } from "./relay.js";
|
|
28
29
|
import { authFor, loadSeats, roomLabel, withOwner } from "./seats.js";
|
|
@@ -98,19 +99,9 @@ export async function runDaemon(home) {
|
|
|
98
99
|
/** Reads a seat's room for the hand-over: its people, and held messages again by id. */
|
|
99
100
|
const roomOf = (key) => ({
|
|
100
101
|
participants: (authors) => participantsFor(find(key), authors),
|
|
101
|
-
messages:
|
|
102
|
+
messages: (ids) => {
|
|
102
103
|
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;
|
|
104
|
+
return messagesById(ids, (after) => call(seat.relayUrl, `/${seat.roomId}/messages?after=${after}&all=1`, authFor(seat, readCredentials(home))));
|
|
114
105
|
},
|
|
115
106
|
});
|
|
116
107
|
async function pump(key) {
|
|
@@ -131,7 +122,8 @@ export async function runDaemon(home) {
|
|
|
131
122
|
while (seat) {
|
|
132
123
|
const answer = await call(seat.relayUrl, `/${seat.roomId}/messages?after=${seat.after}`, authFor(seat, readCredentials(home)));
|
|
133
124
|
const before = seat.guard ?? freshGuard();
|
|
134
|
-
const
|
|
125
|
+
const otherRooms = seats.some((s) => s.sessionId === seat.sessionId && s.roomId !== seat.roomId);
|
|
126
|
+
const result = await handOver(() => find(key) ?? seat, before, answer, roomOf(key), Date.now(), selfCommand(), otherRooms);
|
|
135
127
|
const { text, handed, guard } = result;
|
|
136
128
|
seat = find(key) ?? seat; // it may have just learned its owner
|
|
137
129
|
if (text) {
|
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,56 @@ 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
|
}
|
|
71
|
+
/** Message numbers as `station read` takes them: one, a run (12-14), or
|
|
72
|
+
* both, joined by commas. Only numbers next to each other make a run, so
|
|
73
|
+
* the command reads exactly these. */
|
|
74
|
+
export function idList(ids) {
|
|
75
|
+
const sorted = [...new Set(ids)].sort((a, b) => a - b);
|
|
76
|
+
const runs = [];
|
|
77
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
78
|
+
let j = i;
|
|
79
|
+
while (j + 1 < sorted.length && sorted[j + 1] === sorted[j] + 1)
|
|
80
|
+
j++;
|
|
81
|
+
runs.push(j === i ? String(sorted[i]) : `${sorted[i]}-${sorted[j]}`);
|
|
82
|
+
i = j;
|
|
83
|
+
}
|
|
84
|
+
return runs.join(",");
|
|
85
|
+
}
|
|
86
|
+
const together = (items) => (items.length < 2 ? (items[0] ?? "") : `${items.slice(0, -1).join(", ")} and ${items[items.length - 1]}`);
|
|
87
|
+
/** What a Claude Code session gets for new room messages: one line
|
|
88
|
+
* saying what came and how to read it, in place of the messages. Nobody's
|
|
89
|
+
* words enter the session until the agent reads them, and a delivery in
|
|
90
|
+
* the middle of other work is one line. `room`: the session has seats in
|
|
91
|
+
* other rooms too, so the command names this one. */
|
|
92
|
+
export function noteFrame(seat, messages, participants, command = "station", before = [], room = false) {
|
|
93
|
+
const hearer = hearerFor(seat, participants, command);
|
|
94
|
+
const byId = new Map(participants.map((p) => [p.id, p]));
|
|
95
|
+
const authorOf = (message) => byId.get(message.participant_id ?? "");
|
|
96
|
+
const rest = [...messages, ...before].sort((a, b) => a.id - b.id);
|
|
97
|
+
// Who wrote them, in the order they first spoke, with what each is to the reader.
|
|
98
|
+
const groups = new Map();
|
|
99
|
+
for (const message of rest) {
|
|
100
|
+
const key = message.participant_id ?? "";
|
|
101
|
+
const group = groups.get(key) ?? { name: authorOf(message)?.name ?? "Someone", count: 0, toYou: false, threads: [] };
|
|
102
|
+
group.count++;
|
|
103
|
+
if (hearer.seat && message.to?.includes(hearer.seat))
|
|
104
|
+
group.toYou = true;
|
|
105
|
+
const thread = message.reply_to ?? (message.to?.length && !message.to.includes(hearer.seat ?? "") ? message.id : null);
|
|
106
|
+
if (thread !== null && !group.threads.includes(thread))
|
|
107
|
+
group.threads.push(thread);
|
|
108
|
+
groups.set(key, group);
|
|
109
|
+
}
|
|
110
|
+
const who = [...groups.values()].map(({ name, count, toYou, threads }) => {
|
|
111
|
+
const marks = [count > 1 ? String(count) : null, toYou ? "to you" : null, threads.length ? `${threads.length > 1 ? "threads" : "thread"} ${together(threads.map(String))}` : null].filter(Boolean);
|
|
112
|
+
return marks.length ? `${name} (${marks.join(", ")})` : name;
|
|
113
|
+
});
|
|
114
|
+
const read = `${command} read ${idList(rest.map((m) => m.id))}${room ? ` --room ${seat.roomId}` : ""}`;
|
|
115
|
+
const count = `${rest.length} new message${rest.length === 1 ? "" : "s"}`;
|
|
116
|
+
const summary = `${who.join(", ")}. Read ${rest.length === 1 ? "it" : "them"}: ${read}`;
|
|
117
|
+
return `[Station · ${roomLabel(seat)}] ${count}: ${summary}`;
|
|
118
|
+
}
|
package/dist/handover.js
CHANGED
|
@@ -2,9 +2,25 @@
|
|
|
2
2
|
// guard lets through, held messages it releases, answers on the seat's
|
|
3
3
|
// cards, people asking to join, and the note about held messages. The
|
|
4
4
|
// daemon does the delivery; this decides what goes in it.
|
|
5
|
-
import { askedFrame, askedIn, decisionFrame, decisionsFor, frame } from "./frame.js";
|
|
5
|
+
import { askedFrame, askedIn, decisionFrame, decisionsFor, frame, noteFrame } 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}`;
|
|
@@ -16,7 +32,9 @@ export function heldNote(seat, count, command) {
|
|
|
16
32
|
`They also come through here on their own when a person in the room says something, or as the ${WINDOW_MS / 60_000} minutes pass.`,
|
|
17
33
|
].join("\n");
|
|
18
34
|
}
|
|
19
|
-
export async function handOver(seat, guard, batch, room, now, command
|
|
35
|
+
export async function handOver(seat, guard, batch, room, now, command,
|
|
36
|
+
/** The session has seats in other rooms too: the note's read command names this room. */
|
|
37
|
+
otherRooms = false) {
|
|
20
38
|
const chat = batch.messages.filter((m) => m.kind === "chat" && m.participant_id !== seat().participantId);
|
|
21
39
|
const decisions = decisionsFor(seat(), batch.messages);
|
|
22
40
|
const asked = askedIn(batch.messages);
|
|
@@ -36,10 +54,14 @@ export async function handOver(seat, guard, batch, room, now, command) {
|
|
|
36
54
|
const person = earlier.length ? chat.find((m) => kinds.get(m.participant_id ?? "") !== "agent") : undefined;
|
|
37
55
|
const before = person ? admitted.filter((m) => m.id < person.id) : [];
|
|
38
56
|
const said = admitted.slice(before.length);
|
|
57
|
+
// Claude Code gets a one-line note and reads the messages with station read. Codex still gets every message
|
|
58
|
+
// whole: a station command in Codex's sandbox needs its person to allow
|
|
59
|
+
// network access, so reading after a note could cost an approval each time.
|
|
60
|
+
const chatFrame = seat().harness === "claude-code" ? noteFrame(seat(), said, participants, command, before, otherRooms) : frame(seat(), said, participants, command, before);
|
|
39
61
|
const parts = [
|
|
40
62
|
// Answers on its cards come first: they are what the agent is waiting for.
|
|
41
63
|
decisions.length ? decisionFrame(seat(), decisions, participants) : null,
|
|
42
|
-
admitted.length ?
|
|
64
|
+
admitted.length ? chatFrame : null,
|
|
43
65
|
// Someone asking to join: the people who can answer may not be looking
|
|
44
66
|
// at the room, so the agents seated there say so.
|
|
45
67
|
asked.length ? askedFrame(seat(), asked, command) : null,
|
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, threadHint, 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,115 @@ 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
|
+
/** What `station read` takes besides --after: a message number (12), a
|
|
312
|
+
* run (12-15), or several joined by commas (12,15-17). Null when it is
|
|
313
|
+
* none of those. */
|
|
314
|
+
export function parseRuns(spec) {
|
|
315
|
+
const runs = [];
|
|
316
|
+
for (const part of spec.split(",")) {
|
|
317
|
+
const found = /^\s*(\d+)\s*(?:-\s*(\d+)\s*)?$/.exec(part);
|
|
318
|
+
if (!found)
|
|
319
|
+
return null;
|
|
320
|
+
const from = Number(found[1]);
|
|
321
|
+
const to = found[2] === undefined ? from : Number(found[2]);
|
|
322
|
+
if (!Number.isSafeInteger(from) || !Number.isSafeInteger(to) || from < 1 || to < from)
|
|
323
|
+
return null;
|
|
324
|
+
runs.push({ from, to });
|
|
325
|
+
}
|
|
326
|
+
return runs.length ? runs : null;
|
|
327
|
+
}
|
|
328
|
+
/** The most `station read` prints at once. */
|
|
329
|
+
const READ_AT_ONCE = 100;
|
|
330
|
+
/** The chat messages in these runs, read page by page (every row, as
|
|
331
|
+
* --after reads them). `more`: the first number not read yet, when there
|
|
332
|
+
* were more than READ_AT_ONCE. */
|
|
333
|
+
export async function messagesIn(runs, page) {
|
|
334
|
+
const inside = (id) => runs.some((run) => id >= run.from && id <= run.to);
|
|
335
|
+
const last = Math.max(...runs.map((run) => run.to));
|
|
336
|
+
const found = [];
|
|
337
|
+
let after = Math.min(...runs.map((run) => run.from)) - 1;
|
|
338
|
+
for (;;) {
|
|
339
|
+
const answer = await page(after);
|
|
340
|
+
for (const message of answer.messages) {
|
|
341
|
+
if (message.id > last)
|
|
342
|
+
return { messages: found, more: null };
|
|
343
|
+
if (message.kind !== "chat" || !inside(message.id))
|
|
344
|
+
continue;
|
|
345
|
+
if (found.length === READ_AT_ONCE)
|
|
346
|
+
return { messages: found, more: message.id };
|
|
347
|
+
found.push(message);
|
|
348
|
+
}
|
|
349
|
+
if (answer.messages.length < 100 || answer.next_after <= after)
|
|
350
|
+
return { messages: found, more: null };
|
|
351
|
+
after = answer.next_after;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
/** What `station read 12,15` prints: those messages, marked as every
|
|
355
|
+
* other read marks them, and how to answer. `otherRooms`: the session has
|
|
356
|
+
* seats in other rooms too, so each command it prints names this room;
|
|
357
|
+
* without it, a reply would go to the room the session joined last. */
|
|
358
|
+
export function numberedText(seat, runs, read, participants, me, otherRooms = false) {
|
|
359
|
+
const room = otherRooms ? ` --room ${seat.roomId}` : "";
|
|
360
|
+
const hearer = hearerFor(seat, participants, me);
|
|
361
|
+
const byId = new Map(participants.map((p) => [p.id, p]));
|
|
362
|
+
const authors = read.messages.map((m) => byId.get(m.participant_id ?? ""));
|
|
363
|
+
const note = noteFor(hearer, authors);
|
|
364
|
+
const asked = runs.map((run) => (run.from === run.to ? String(run.from) : `${run.from}-${run.to}`)).join(", ");
|
|
365
|
+
const lines = [`[Station · ${roomLabel(seat)}] ${runs.length === 1 && runs[0].from === runs[0].to ? "Message" : "Messages"} ${asked}:`, "", ...(note ? [note, ""] : [])];
|
|
366
|
+
lines.push(...(read.messages.length ? read.messages.map((m, i) => lineOf(hearer, authors[i], m.body, whereOf(hearer, m, participants))) : ["(no chat message with that number in this room)"]), "");
|
|
367
|
+
if (read.more !== null) {
|
|
368
|
+
const rest = runs.flatMap((run) => (run.to < read.more ? [] : [{ from: Math.max(run.from, read.more), to: run.to }]));
|
|
369
|
+
lines.push(`There are more. Read on with: ${me} read ${rest.map((run) => (run.from === run.to ? String(run.from) : `${run.from}-${run.to}`)).join(",")}${room}`);
|
|
370
|
+
}
|
|
371
|
+
lines.push(`Reply in the room with: ${me} say${room} "<your reply>" (keep it to one or two sentences)`);
|
|
372
|
+
const hint = threadHint(read.messages, `${me} say${room} --reply {thread} "<your reply>"`);
|
|
373
|
+
if (hint)
|
|
374
|
+
lines.push(hint);
|
|
375
|
+
return lines.join("\n");
|
|
376
|
+
}
|
|
377
|
+
/** `station read 12`, `12-15` or `12,15-17`, as the seat. */
|
|
378
|
+
export async function readRunsIn(home, seat, runs, me) {
|
|
379
|
+
const auth = authFor(seat, readCredentials(home));
|
|
380
|
+
const [read, room] = await Promise.all([
|
|
381
|
+
messagesIn(runs, (after) => call(seat.relayUrl, `/${seat.roomId}/messages?after=${after}&all=1`, auth)),
|
|
382
|
+
call(seat.relayUrl, `/${seat.roomId}`, auth),
|
|
383
|
+
]);
|
|
384
|
+
const otherRooms = loadSeats(files(home).seats).some((other) => other.sessionId === seat.sessionId && other.roomId !== seat.roomId);
|
|
385
|
+
return numberedText(seat, runs, read, room.participants, me, otherRooms);
|
|
386
|
+
}
|
|
387
|
+
const SEAT_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
388
|
+
/** Seats by id or by name, as `station say --to` takes them. A name must
|
|
389
|
+
* be one seat's, any case. */
|
|
390
|
+
export function seatsNamed(wanted, participants) {
|
|
391
|
+
return wanted.map((want) => {
|
|
392
|
+
if (SEAT_ID.test(want))
|
|
393
|
+
return want;
|
|
394
|
+
const found = participants.filter((p) => p.name.toLowerCase() === want.toLowerCase());
|
|
395
|
+
if (found.length === 1)
|
|
396
|
+
return found[0].id;
|
|
397
|
+
const names = participants.map((p) => p.name).join(", ");
|
|
398
|
+
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}.`);
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
/** Says something in the room. `reply`: the thread to say it in. `to`:
|
|
402
|
+
* seat ids or names; only those agents are woken by it. The answer's
|
|
403
|
+
* thread, when it went in one. */
|
|
404
|
+
export async function sayIn(home, seat, text, options = {}) {
|
|
405
|
+
const auth = authFor(seat, readCredentials(home));
|
|
406
|
+
// An empty list is sent as it is: everyone, said outright.
|
|
407
|
+
const to = !options.to
|
|
408
|
+
? undefined
|
|
409
|
+
: !options.to.length || options.to.every((want) => SEAT_ID.test(want))
|
|
410
|
+
? options.to
|
|
411
|
+
: seatsNamed(options.to, (await call(seat.relayUrl, `/${seat.roomId}`, auth)).participants);
|
|
412
|
+
const said = await call(seat.relayUrl, `/${seat.roomId}/messages`, auth, {
|
|
413
|
+
body: { body: text, ...(options.reply ? { reply_to: options.reply } : {}), ...(to ? { to } : {}) },
|
|
414
|
+
});
|
|
415
|
+
return said?.message?.reply_to ?? null;
|
|
312
416
|
}
|
|
313
417
|
/** Give the room a name. The relay refuses when a person already named it. */
|
|
314
418
|
export async function nameRoom(home, seat, title) {
|
|
@@ -330,3 +434,29 @@ export async function putItem(home, seat, item) {
|
|
|
330
434
|
const { id, kind, title, href } = items[0];
|
|
331
435
|
return { id, kind, title, href };
|
|
332
436
|
}
|
|
437
|
+
/** What `station join` says when the room records nobody as this agent's
|
|
438
|
+
* person: a sign-in link for them. Whoever opens it, with an account or
|
|
439
|
+
* only their browser, signs this computer in, and the seat becomes theirs;
|
|
440
|
+
* later agents here join as theirs from the start. */
|
|
441
|
+
export async function ownerLines(home, seat, room, me, webUrl = process.env.STATION_WEB_URL ?? DEFAULT_WEB, start = startLogin, remote = elsewhere()) {
|
|
442
|
+
if (seat.via !== "room" || !seat.roomToken)
|
|
443
|
+
return [];
|
|
444
|
+
if (room.participants.find((one) => one.id === seat.participantId)?.for)
|
|
445
|
+
return [];
|
|
446
|
+
const claim = { roomId: seat.roomId, key: seat.roomToken };
|
|
447
|
+
// A link already waiting (another seat's, or the person's own login) takes this seat too.
|
|
448
|
+
let url = addClaim(home, seat.relayUrl, claim);
|
|
449
|
+
if (url)
|
|
450
|
+
remote = Boolean(readPending(home)?.remote);
|
|
451
|
+
try {
|
|
452
|
+
url ??= (await start(home, seat.relayUrl, webUrl, false, undefined, remote, [claim])).url;
|
|
453
|
+
}
|
|
454
|
+
catch {
|
|
455
|
+
return [`Station does not know whose agent this is. For a link that makes it your person's, run: ${me} claim`];
|
|
456
|
+
}
|
|
457
|
+
return [
|
|
458
|
+
`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}`,
|
|
459
|
+
"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.",
|
|
460
|
+
codeStep(me, remote),
|
|
461
|
+
];
|
|
462
|
+
}
|
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.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",
|