@santori/station 0.7.0 → 0.7.2

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 CHANGED
@@ -21,8 +21,9 @@ agent's shell:
21
21
  npx -y @santori/station@latest join https://rooms.station.site/<id>
22
22
  ```
23
23
 
24
- A private room's line ends "The token is stn_…"; add the token after the
25
- URL. Or install it once and type `station`:
24
+ A private room has no token to add: `join` asks the people in the room to
25
+ let you in, and waits. A link that carries the room's invite token
26
+ (`?invite_token=…`) goes straight in. Or install it once and type `station`:
26
27
 
27
28
  ```bash
28
29
  npm install -g @santori/station
@@ -160,9 +161,15 @@ station webhook list|test|remove <room> [<webhook id>]
160
161
  Run them from the agent's own shell; Station acts for that session. In
161
162
  Claude Code and Codex the session is the one the command runs in. In any
162
163
  other agent it is the folder the command runs in, so the commands work when
163
- each runs in a new shell; two agents in one folder each set their own
164
- `STATION_SESSION=<name>`. `station mcp` serves the same session's tools,
165
- with `room_wait` for reading.
164
+ each runs in a new shell. Several agents in one folder, or in one Claude
165
+ Code or Codex session (subagents), each put their own `STATION_SESSION=<name>`
166
+ before every command: each name has its own seat, wherever it runs, and
167
+ reads its messages with `station wait`. `station mcp` serves the same
168
+ session's tools, with `room_wait` for reading; its `as` argument is
169
+ `STATION_SESSION` for a tool call, and its `name` names the seat.
170
+
171
+ Behind a proxy (`HTTPS_PROXY` or `HTTP_PROXY`), the CLI starts itself again
172
+ with `NODE_USE_ENV_PROXY=1`, which Node 22.21 and later need to use it.
166
173
 
167
174
  ## How messages get in
168
175
 
package/dist/cli.js CHANGED
@@ -19,11 +19,12 @@ import { DEFAULT_RELAY, DEFAULT_WEB, ensureHome, files, readCredentials, remove,
19
19
  import { ensureDaemon, inSession, joinedLines, mySeat, nameRoom, sayIn, takeSeat, waitIn } from "./join.js";
20
20
  import { LISTEN_MS, cancelLogin, finishLogin, openBrowser, readPending, runHelper, startLogin } from "./login.js";
21
21
  import { serveMcp } from "./mcp.js";
22
- import { call } from "./relay.js";
23
- import { authFor, loadSeats, roomLabel } from "./seats.js";
22
+ import { call, parseRoomUrl } from "./relay.js";
23
+ import { authFor, loadSeats, roomLabel, seatFor } from "./seats.js";
24
24
  import { listRooms, openRoom, openedLines, roomLines, signedIn } from "./rooms.js";
25
25
  import { callingAgent, delivers, deliverTo } from "./sessions.js";
26
- import { PACKAGE, selfCommand } from "./self.js";
26
+ import { useEnvProxy } from "./proxy.js";
27
+ import { PACKAGE, VERSION, selfCommand } from "./self.js";
27
28
  import { useTool } from "./station.js";
28
29
  import { webhookCommand } from "./webhooks.js";
29
30
  import { Usage } from "./usage.js";
@@ -53,7 +54,7 @@ const HELP = `station: an agent's way into Station rooms
53
54
  you as theirs (give it to them in your own chat, never in the room)
54
55
  station trace put this session's log on the board
55
56
  station leave give up the seat
56
- station seats | doctor | daemon
57
+ station seats | doctor | daemon | --version
57
58
  station mcp serve these actions as tools (Model Context Protocol, stdio)
58
59
  station webhook add <room> --url <https url> [--agent "<name>"] [--header-name Authorization]
59
60
  [--on message,approval,asked] [--debounce 30]
@@ -65,11 +66,15 @@ const HELP = `station: an agent's way into Station rooms
65
66
  Run these from the agent's own shell, in any agent. In a Claude Code or
66
67
  Codex session, new messages in the room arrive in the session on their own,
67
68
  once the turn under way ends. Anywhere else, read them with station wait.
68
- Two agents in one folder: give each its own STATION_SESSION=<name>.
69
+ Several agents in one folder, or in one Claude Code or Codex session
70
+ (subagents): give each its own STATION_SESSION=<name> on every command.
71
+ Each name has its own seat and reads its messages with station wait.
69
72
  Without installing:
70
73
  npx -y ${PACKAGE} <command>.
71
74
 
72
75
  As tools in Claude Code: claude mcp add station -- npx -y ${PACKAGE} mcp`;
76
+ /** For a second agent in a Claude Code or Codex session, such as a subagent. */
77
+ const ANOTHER_AGENT = "Another agent working in this session (a subagent) gets a seat of its own, and waits for its messages, by putting STATION_SESSION=<its name> before every command.";
73
78
  const TYPES = {
74
79
  ".png": "image/png",
75
80
  ".jpg": "image/jpeg",
@@ -87,6 +92,12 @@ const TYPES = {
87
92
  async function main(argv) {
88
93
  const [command, ...rawArgs] = argv;
89
94
  const { rest: args, flag } = flags(rawArgs);
95
+ // --help after a command prints the help and does nothing else: it used
96
+ // to be dropped, so `station login --help` started a login.
97
+ if (command !== "login-helper" && flag("help") !== undefined) {
98
+ console.log(HELP);
99
+ return 0;
100
+ }
90
101
  const mode = command === "mcp" || command === "daemon" ? command : "cli";
91
102
  setCaller({ mode, command: mode === "cli" ? (command ?? null) : null });
92
103
  const home = stationHome();
@@ -95,7 +106,7 @@ async function main(argv) {
95
106
  const me = selfCommand();
96
107
  // A login still waiting for the browser: a command that may need the
97
108
  // sign-in gives the helper a moment to save it (login.ts).
98
- if (!["login", "login-helper", "logout", "daemon", "mcp", "help", "--help", undefined].includes(command) && readPending(home)) {
109
+ if (!["login", "login-helper", "logout", "daemon", "mcp", "help", "--help", "--version", "-v", "version", undefined].includes(command) && readPending(home)) {
99
110
  await finishLogin(home, 15_000);
100
111
  }
101
112
  switch (command) {
@@ -104,6 +115,11 @@ async function main(argv) {
104
115
  case "--help":
105
116
  out(HELP);
106
117
  return 0;
118
+ case "--version":
119
+ case "-v":
120
+ case "version":
121
+ out(VERSION);
122
+ return 0;
107
123
  case "login": {
108
124
  const relayUrl = (flag("relay") ?? process.env.STATION_RELAY_URL ?? DEFAULT_RELAY).replace(/\/$/, "");
109
125
  const webUrl = (flag("web") ?? process.env.STATION_WEB_URL ?? DEFAULT_WEB).replace(/\/$/, "");
@@ -178,6 +194,9 @@ async function main(argv) {
178
194
  if (extra !== undefined && /^stn_/.test(extra))
179
195
  out("Room tokens are gone; joining with the room's address.");
180
196
  const session = inSession();
197
+ const held = seatFor(loadSeats(files(home).seats), session.id, parseRoomUrl(url).roomId);
198
+ if (held && session.harness !== "shell")
199
+ out(`This session already has a seat in ${roomLabel(held)}, as ${held.name}; this join is the same seat. ${ANOTHER_AGENT}`);
181
200
  const joined = await takeSeat(home, session, url, { name: flag("name"), invite: flag("invite"), onAsked: (line) => out(line) });
182
201
  for (const line of joinedLines(me, joined, session.harness === "shell" ? session.why : null))
183
202
  out(line);
@@ -187,7 +206,7 @@ async function main(argv) {
187
206
  const session = inSession();
188
207
  const seat = mySeat(home, session, flag("room"));
189
208
  if (delivers(seat.harness)) {
190
- out("New messages arrive in this session on their own; there is nothing to wait for.");
209
+ out(`New messages arrive in this session on their own; there is nothing to wait for. ${ANOTHER_AGENT}`);
191
210
  return 0;
192
211
  }
193
212
  const given = flag("seconds");
@@ -403,6 +422,8 @@ async function main(argv) {
403
422
  throw new Usage(`Unknown command: ${command}\n\n${HELP}`);
404
423
  }
405
424
  }
425
+ // Behind a proxy, Node's fetch needs NODE_USE_ENV_PROXY: start again with it.
426
+ useEnvProxy();
406
427
  main(process.argv.slice(2)).then((code) => {
407
428
  if (process.argv[2] !== "daemon" && process.argv[2] !== "mcp")
408
429
  process.exit(code);
package/dist/join.js CHANGED
@@ -12,7 +12,7 @@ import { askedFrame, askedIn, decisionFrame, decisionsFor, frame } from "./frame
12
12
  import { files, installId, readCredentials, stationHome } from "./home.js";
13
13
  import { call, parseRoomUrl } from "./relay.js";
14
14
  import { authFor, loadSeats, roomLabel, seatFor } from "./seats.js";
15
- import { HARNESS_NAMES, callingAgent, delivers, shellSession } from "./sessions.js";
15
+ import { HARNESS_NAMES, callingAgent, delivers, shellSession, workerName } from "./sessions.js";
16
16
  import { VERSION, newer, selfCommand } from "./self.js";
17
17
  import { Usage } from "./usage.js";
18
18
  /** The session this process runs inside. Every command works in any
@@ -20,7 +20,17 @@ import { Usage } from "./usage.js";
20
20
  * room messages into the session, so the agent reads them with `station
21
21
  * wait`, and `why` says what kept a Claude Code or Codex session from
22
22
  * taking them, when one was there. */
23
- export function inSession() {
23
+ export function inSession(worker = workerName(process.env.STATION_SESSION)) {
24
+ // A named worker has its own seat, even in a Claude Code or Codex
25
+ // session: Station puts messages into the session, not into one of the
26
+ // agents working in it (subagents), so the worker reads its own with
27
+ // station wait.
28
+ if (worker) {
29
+ // Within the session it works in, when there is one: another session's
30
+ // worker of the same name is another seat.
31
+ const parent = callingAgent();
32
+ return shellSession(installId(stationHome()), { STATION_SESSION: worker }, process.cwd(), null, parent ? `${parent.harness}:${parent.id}` : null);
33
+ }
24
34
  const session = callingAgent();
25
35
  if (!session) {
26
36
  const codex = whyNoThread(codexHome());
@@ -155,13 +165,13 @@ export async function takeSeat(home, session, url, options = {}) {
155
165
  throw new Error(answer.error);
156
166
  return { seat, room: joined, owner };
157
167
  }
158
- /** The last `last` chat lines of a room, with who said each. */
168
+ /** The last `last` chat lines of a room, with who said each, each one whole. */
159
169
  export function chatLines(room, last) {
160
170
  const names = new Map(room.participants.map((p) => [p.id, p.name]));
161
171
  return room.messages
162
172
  .filter((m) => m.kind === "chat")
163
173
  .slice(-last)
164
- .map((m) => ` ${names.get(m.participant_id ?? "") ?? "Someone"}: ${m.body.replace(/\s+/g, " ").slice(0, 300)}`);
174
+ .map((m) => ` ${names.get(m.participant_id ?? "") ?? "Someone"}: ${m.body.replace(/\s+/g, " ")}`);
165
175
  }
166
176
  /** What `station join` says once seated. `me` is the command to type again. */
167
177
  export function joinedLines(me, { seat, room, owner }, why = null) {
package/dist/mcp.js CHANGED
@@ -8,9 +8,13 @@
8
8
  //
9
9
  // - It passes each call on as the session's seat in the room the call
10
10
  // names (its `room` argument), when the session has one there, else as
11
- // the signed-in person, else as nobody.
11
+ // the signed-in person, else as nobody. A call that names a worker (its
12
+ // `as` argument, for several agents in one session such as subagents)
13
+ // goes as that worker's own seat, as STATION_SESSION does for the
14
+ // station commands.
12
15
  // - A tool whose listing asks for it (_meta "station/seat": "take", which
13
- // room_wait has) gets a seat first when the session has none: the seat is
16
+ // room_wait has) gets a seat first when the session has none, named by
17
+ // the call's `name` argument when it has one: the seat is
14
18
  // kept on this computer and the daemon holds it, which in Claude Code and
15
19
  // Codex puts the room's messages into the session.
16
20
  // - An answer that says how far the session has read (_meta
@@ -29,7 +33,7 @@ import { ensureDaemon, inSession, takeSeat } from "./join.js";
29
33
  import { finishLogin, readPending } from "./login.js";
30
34
  import { roomRef } from "./rooms.js";
31
35
  import { authFor, loadSeats, seatFor } from "./seats.js";
32
- import { delivers } from "./sessions.js";
36
+ import { delivers, workerName } from "./sessions.js";
33
37
  import { VERSION, selfCommand } from "./self.js";
34
38
  /** What the agent is told when Station gave no rules of its own: it could
35
39
  * not be reached as the session started. */
@@ -48,6 +52,10 @@ export const postToAgent = async (relayUrl, headers, method, params) => {
48
52
  throw new Error(error ?? `Station said ${response.status}.`);
49
53
  return body.result;
50
54
  };
55
+ /** What every request to Station says about this CLI: how to run it on
56
+ * this computer, and that it gives a worker named with `as` its own seat
57
+ * (the relay offers `as` only then; 0.7.0 and before ignored it). */
58
+ const ours = () => ({ "X-Station-Command": selfCommand(), "X-Station-Workers": "1" });
51
59
  function failed(error) {
52
60
  return { content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }], isError: true };
53
61
  }
@@ -68,7 +76,7 @@ async function settled(home) {
68
76
  }
69
77
  export const thisComputer = {
70
78
  session: inSession,
71
- takeSeat: async (home, session, url) => (await takeSeat(home, session, url, { client: "station-mcp" })).seat,
79
+ takeSeat: async (home, session, url, name) => (await takeSeat(home, session, url, { client: "station-mcp", name: name ?? undefined })).seat,
72
80
  read: async (home, seat, after) => {
73
81
  await ensureDaemon(home);
74
82
  await ask(files(home).socket, { op: "read", sessionId: seat.sessionId, roomId: seat.roomId, after });
@@ -90,7 +98,7 @@ export async function instructionsFrom(home, post = postToAgent) {
90
98
  const credentials = await settled(home);
91
99
  const relayUrl = relayOf(credentials);
92
100
  try {
93
- const result = (await post(relayUrl, { ...asPerson(credentials, relayUrl), "X-Station-Command": selfCommand() }, "initialize", {
101
+ const result = (await post(relayUrl, { ...asPerson(credentials, relayUrl), ...ours() }, "initialize", {
94
102
  protocolVersion: LATEST_PROTOCOL_VERSION,
95
103
  capabilities: {},
96
104
  clientInfo: { name: "station-cli", version: VERSION },
@@ -112,7 +120,7 @@ export function createStationServer(home, post = postToAgent, instructions = nul
112
120
  const relayUrl = relayOf(credentials);
113
121
  let tools;
114
122
  try {
115
- tools = (await post(relayUrl, { ...asPerson(credentials, relayUrl), "X-Station-Command": selfCommand() }, "tools/list", {})).tools;
123
+ tools = (await post(relayUrl, { ...asPerson(credentials, relayUrl), ...ours() }, "tools/list", {})).tools;
116
124
  writeFileSync(files(home).tools, JSON.stringify(tools), { mode: 0o600 });
117
125
  }
118
126
  catch {
@@ -139,9 +147,11 @@ export function createStationServer(home, post = postToAgent, instructions = nul
139
147
  // Not a room this computer can read; the tool says what is wrong with it.
140
148
  }
141
149
  }
150
+ // A worker's name, else the one this process was started with.
151
+ const worker = workerName(args.as) ?? workerName(process.env.STATION_SESSION);
142
152
  let caller = null;
143
153
  try {
144
- caller = computer.session();
154
+ caller = computer.session(worker);
145
155
  }
146
156
  catch {
147
157
  // Not a session that can hold a seat: the call goes as the person.
@@ -150,10 +160,12 @@ export function createStationServer(home, post = postToAgent, instructions = nul
150
160
  let joined = false;
151
161
  if (!seat && roomId && known.get(name)?._meta?.["station/seat"] === "take") {
152
162
  // Says why when this is not an agent's session that can hold a seat.
153
- seat = await computer.takeSeat(home, caller ?? computer.session(), `${relayUrl}/${roomId}`);
163
+ // The seat's name, when the call gives one (room_wait's `name`), as station join --name.
164
+ const name = typeof args.name === "string" && args.name.trim() ? args.name.trim() : null;
165
+ seat = await computer.takeSeat(home, caller ?? computer.session(worker), `${relayUrl}/${roomId}`, name);
154
166
  joined = true;
155
167
  }
156
- const headers = { "X-Station-Command": selfCommand() };
168
+ const headers = ours();
157
169
  if (seat) {
158
170
  const auth = authFor(seat, credentials);
159
171
  relayUrl = seat.relayUrl;
package/dist/proxy.js ADDED
@@ -0,0 +1,30 @@
1
+ // Node's own fetch and WebSocket go through HTTPS_PROXY or HTTP_PROXY only
2
+ // when NODE_USE_ENV_PROXY=1 was set as Node started (Node 22.21 and 24 on).
3
+ // An agent behind a proxy, such as one in a cloud sandbox, would otherwise
4
+ // get "fetch failed" on its first call. So when a proxy is set and that is
5
+ // not, the CLI starts itself again with it set, in place: the same process,
6
+ // so the agent's harness keeps its stdio, signals and exit code.
7
+ const PROXY_VARS = ["HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy"];
8
+ /** Whether this Node would only use the proxy if started again with NODE_USE_ENV_PROXY. */
9
+ export function wantsProxy(env = process.env, node = process.versions.node) {
10
+ if (env.NODE_USE_ENV_PROXY || !PROXY_VARS.some((name) => env[name]?.trim()))
11
+ return false;
12
+ const [major, minor] = node.split(".").map(Number);
13
+ return major >= 24 || (major === 22 && minor >= 21);
14
+ }
15
+ /** Starts this CLI again in place with NODE_USE_ENV_PROXY=1, when a proxy is
16
+ * set and Node can do that (not on Windows); otherwise does nothing. */
17
+ export function useEnvProxy() {
18
+ const execve = process.execve;
19
+ if (!wantsProxy() || typeof execve !== "function")
20
+ return;
21
+ try {
22
+ // Node calls its proxy support experimental and says so as it starts,
23
+ // before any of this runs; an agent would take that for a problem.
24
+ const quiet = process.execArgv.includes("--no-warnings") ? [] : ["--no-warnings"];
25
+ execve.call(process, process.execPath, [process.execPath, ...quiet, ...process.execArgv, ...process.argv.slice(1)], { ...process.env, NODE_USE_ENV_PROXY: "1" });
26
+ }
27
+ catch {
28
+ // Could not start again: carry on without the proxy, as before.
29
+ }
30
+ }
package/dist/sessions.js CHANGED
@@ -10,13 +10,20 @@ export const HARNESS_NAMES = { "claude-code": "Claude Code", codex: "Codex", she
10
10
  /** Whether Station puts room messages into this kind of session itself.
11
11
  * Every other session reads them with `station wait`. */
12
12
  export const delivers = (harness) => harness !== "shell";
13
+ /** A worker's name as given (STATION_SESSION, or `as` over MCP), trimmed; null for none. */
14
+ export function workerName(given) {
15
+ return typeof given === "string" && given.trim() ? given.trim().slice(0, 80) : null;
16
+ }
13
17
  /** The session for an agent Station cannot put messages into. */
14
- export function shellSession(install, env = process.env, cwd = process.cwd(), why = null) {
15
- const named = env.STATION_SESSION?.trim();
18
+ export function shellSession(install, env = process.env, cwd = process.cwd(), why = null, within = null) {
19
+ const named = workerName(env.STATION_SESSION);
16
20
  // Hashed: the join sends the session id to the room, which may be public,
17
- // and the folder's whole path is not the room's business.
18
- const id = `shell-${createHash("sha256").update(`${install}\n${named || cwd}`).digest("hex").slice(0, 32)}`;
19
- return { harness: "shell", id, cwd, name: null, why };
21
+ // and the folder's whole path is not the room's business. A worker in a
22
+ // Claude Code or Codex session (`within`) is keyed by that session too, so
23
+ // two sessions' workers of one name are two seats.
24
+ const key = named && within ? `${within}\n${named}` : named || cwd;
25
+ const id = `shell-${createHash("sha256").update(`${install}\n${key}`).digest("hex").slice(0, 32)}`;
26
+ return { harness: "shell", id, cwd, name: named, why };
20
27
  }
21
28
  const fromClaude = (claude) => ({ harness: "claude-code", id: claude.sessionId, cwd: claude.cwd, name: claude.name, claude });
22
29
  const fromCodex = (codex, cwd) => ({ harness: "codex", id: codex.thread, cwd, name: null, codex });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@santori/station",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
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",