@santori/station 0.9.12 → 0.9.13

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/agents.js CHANGED
@@ -14,7 +14,7 @@ import { codexHome } from "./codex.js";
14
14
  import { call } from "./relay.js";
15
15
  import { findProgram } from "./programs.js";
16
16
  import { mention } from "./mark.js";
17
- import { mcpCommand } from "./self.js";
17
+ import { mcpCommand, onPath } from "./self.js";
18
18
  import { saveFolder } from "./starts.js";
19
19
  import { Usage } from "./usage.js";
20
20
  export const LOCAL_AGENTS = [
@@ -39,6 +39,18 @@ export const LOCAL_AGENTS = [
39
39
  },
40
40
  ];
41
41
  const installed = (agent, env) => findProgram(agent.kind, env) !== null && existsSync(agent.home(env));
42
+ /** The other agent programs Station knows (sessions.ts PROGRAMS), by the command each installs. Station
43
+ * does not start them: on sign-up and sign-in they become the person's agents, shown in their rooms,
44
+ * and each joins a room when it runs Station itself. Devin runs in its own cloud, never here. */
45
+ const PROGRAM_COMMANDS = { cursor: "cursor-agent", gemini: "gemini", copilot: "copilot", grok: "grok" };
46
+ /** The other agent programs on this computer's PATH (PROGRAM_COMMANDS). */
47
+ export function programsHere(env = process.env) {
48
+ return Object.entries(PROGRAM_COMMANDS).filter(([, command]) => onPath(command, env) !== null).map(([kind]) => kind);
49
+ }
50
+ /** Every agent this computer finds on itself, for sign-up and sign-in: the local agents Station starts, then the other programs. */
51
+ export function agentsHere(env = process.env) {
52
+ return [...foundHere(env), ...programsHere(env)];
53
+ }
42
54
  /** The kinds of local agent installed on this computer: its program (on PATH or in its app, programs.ts) and its own folder. */
43
55
  export function foundHere(env = process.env) {
44
56
  return LOCAL_AGENTS.filter((agent) => installed(agent, env)).map((agent) => agent.kind);
package/dist/cli.js CHANGED
@@ -20,7 +20,7 @@ import { answers, runDaemon } from "./daemon.js";
20
20
  import { DEFAULT_RELAY, ensureHome, files, readCredentials, readJson, remove, stationHome } from "./home.js";
21
21
  import { codexHooksJoinLine, hooksJoinLine, removeCodexHooks, removeHooks } from "./hooks.js";
22
22
  import { taskHint, admittedLine, ensureDaemon, inSession, joinedLines, lostThread, saidLines, seatForReply, mySeat, seatsOf, nameRoom, ownerLines, parseRuns, readHeldIn, readIn, readRunsIn, sayIn, leaveSeat, takeSeat, waitIn } from "./join.js";
23
- import { LISTEN_MS, cancelLogin, elsewhere, finishLogin, openBrowser, readPending, runHelper, startLogin, takeDeviceReply, waitingAt, waitForDeviceReply } from "./login.js";
23
+ import { LISTEN_MS, cancelLogin, elsewhere, finishLogin, openBrowser, readPending, runHelper, startLogin, waitingAt } from "./login.js";
24
24
  import { answerText, asideText, cachedTools, cliOf, commandFrom, commandHelp, commandLines, groupOf, inputsFrom, roomFor, unknownCommand } from "./commands.js";
25
25
  import { saveWatchAfter, serveMcp, stationTools, watchAfter } from "./mcp.js";
26
26
  import { letInText, tagsOnce } from "./mark.js";
@@ -212,11 +212,6 @@ async function main(argv) {
212
212
  await finishLogin(home, 15_000);
213
213
  await agentSignIn();
214
214
  }
215
- if (!["login", "login-helper", "signup", "logout", "daemon", "mcp", undefined].includes(command)) {
216
- const reply = takeDeviceReply(home);
217
- if (reply)
218
- console.error(`Reply to your connection message: ${reply}`);
219
- }
220
215
  // The sign-in link, as `station login` starts it: for the person, or in
221
216
  // Claude Code and Codex for that one agent of theirs. `signup` prints the
222
217
  // same link for an address that already has an account.
@@ -234,7 +229,7 @@ async function main(argv) {
234
229
  if (asAgent && saved && !saved.agent && !saved.secret)
235
230
  throw new Usage(`This computer is signed in as ${saved.name}, and its agents use that. Run ${me} login --agent on the agent's own machine, or ${me} logout first.`);
236
231
  const login = await startLogin(home, relayUrl, webUrl, signUp, undefined, remote, [], asAgent?.trim() ?? null);
237
- return { login, remote, lines: [`${signUp ? "Sign up for Station" : "Sign in to Station"}, then click Approve:\n${login.url}`, "The link works for ten minutes. Your person can open it on any computer."] };
232
+ return { login, remote, lines: [`${signUp ? "Sign up for Station" : "Sign in to Station"}, then click Connect:\n${login.url}`, "The link works for ten minutes. Your person can open it on any computer."] };
238
233
  };
239
234
  switch (command) {
240
235
  case undefined:
@@ -270,9 +265,6 @@ async function main(argv) {
270
265
  if (!credentials || same(credentials))
271
266
  throw new Error(`Nobody finished signing in. Run ${me} login again.`);
272
267
  out(signedInLine(credentials, me));
273
- const reply = await waitForDeviceReply(home, login.verifier, Date.parse(login.device.expires_at));
274
- if (reply)
275
- out(`Reply to your connection message: ${reply}`);
276
268
  return 0;
277
269
  }
278
270
  case "signup": {
@@ -671,12 +663,10 @@ async function main(argv) {
671
663
  if (!request)
672
664
  throw new Usage(`${me} admit <request> [--no]`);
673
665
  const seat = mySeat(home, inSession(), flag("room"));
674
- if (seat.via !== "cli")
675
- throw new Usage("This seat joined with a room token, so it cannot let anyone in. The person you work for can, from the card in the room.");
676
666
  // --approve=false is the action's own input, as mutate has it.
677
667
  const approve = flag("no") === undefined && flag("approve") !== "false";
678
- // room_admit, as the person, the same as an agent through station mcp.
679
- const answered = await useTool(signedIn(home), "room_admit", { room: seat.roomId, request, approve });
668
+ const auth = authFor(seat, readCredentials(home));
669
+ const { request: answered } = await call(seat.relayUrl, `/${seat.roomId}/requests/${encodeURIComponent(request)}`, auth, { body: { approve } });
680
670
  out(answered.status === "approved" ? `Let ${answered.name} into ${roomLabel(seat)}.` : `Said no to ${answered.name} in ${roomLabel(seat)}.`);
681
671
  // Another agent starts reading the room now: the moment what this one is working on has a reader.
682
672
  if (answered.status === "approved" && answered.kind === "agent")
package/dist/daemon.js CHANGED
@@ -44,7 +44,7 @@ import { HARNESS_NAMES, delivers, deliverTo, isRunning } from "./sessions.js";
44
44
  import { claudeHome } from "./claude.js";
45
45
  import { codexHome, rolloutPath, STOP_OUTPUT_BYTES, stopDeliveryMarker, stopDeliveryStatus, threadIdle } from "./codex.js";
46
46
  import { clearJoinRequest, daemonEnv, joinRoom } from "./join.js";
47
- import { createWaking } from "./waking.js";
47
+ import { createWaking, wakeCredentials } from "./waking.js";
48
48
  const SAFETY_MS = 30_000;
49
49
  const RETRY_MS = 15_000;
50
50
  /** A session gone this long has ended; its seats leave their rooms. */
@@ -927,7 +927,7 @@ export async function runDaemon(home) {
927
927
  clearInterval(tick);
928
928
  waking.stop();
929
929
  // Station starts nothing on this computer from now: it hears so at once.
930
- const credentials = readCredentials(home);
930
+ const credentials = wakeCredentials(home);
931
931
  if (credentials?.token)
932
932
  void call(credentials.relayUrl, "/cli/wakes", { token: credentials.token }, { method: "DELETE" }).catch(() => { });
933
933
  for (const close of closers.values())
package/dist/home.js CHANGED
@@ -28,7 +28,6 @@ export const files = (home) => ({
28
28
  mcpTools: join(home, "tools-mcp.json"),
29
29
  /** A `station login` under way (login.ts). */
30
30
  login: join(home, "login.json"),
31
- loginReply: join(home, "login-reply.json"),
32
31
  /** This computer's own identity while it has no sign-in (guest.ts). */
33
32
  guest: join(home, "guest.json"),
34
33
  /** This install's own id (installId). */
package/dist/join.js CHANGED
@@ -467,7 +467,7 @@ export function afterThisSession(me, agent, wait) {
467
467
  `- A check on a schedule (cron, an automation): needs this computer signed in to Station. Run \`${me} watch --agent <which agent you are, such as codex>\` every few minutes. It reads all your person's rooms. Messages reach you late this way, and until then the sender may hear that Station could not reach you.`,
468
468
  `- Claude Code or Codex on a computer: needs this computer signed in to Station. \`${me} add claude\` (or codex) lets Station start it for a message to it.`,
469
469
  ...(wait ? [`- A session that stays open: keep ${wait}.`] : []),
470
- `If this computer is not signed in, run \`${me} signup --email <their email>\`. If it prints a link, give it to your person privately, and run the step after they click Approve. If this session ends first, nothing is set up: tell your person so, and give them the step's command, starting with \`cd\` to this folder's full path.`,
470
+ `If this computer is not signed in, run \`${me} signup --email <their email>\`. If it prints a link, give it to your person privately, and run the step after they click Connect. If this session ends first, nothing is set up: tell your person so, and give them the step's command, starting with \`cd\` to this folder's full path.`,
471
471
  ].join("\n");
472
472
  }
473
473
  /** The session's seat in the room, taken now when it has none. */
package/dist/login.js CHANGED
@@ -23,7 +23,7 @@ import { execFile, spawn } from "node:child_process";
23
23
  import { randomBytes } from "node:crypto";
24
24
  import { openSync } from "node:fs";
25
25
  import { hostname } from "node:os";
26
- import { foundHere } from "./agents.js";
26
+ import { agentsHere, foundHere } from "./agents.js";
27
27
  import { DEFAULT_WEB, files, readCredentials, readJson, remove, writeJson } from "./home.js";
28
28
  import { carryGuest } from "./guest.js";
29
29
  import { call, RelayError, siteOf } from "./relay.js";
@@ -81,8 +81,6 @@ async function runDeviceHelper(home, pending, startStation) {
81
81
  const device = pending.device;
82
82
  const file = files(home);
83
83
  const mine = () => readPending(home)?.verifier === pending.verifier;
84
- const replyState = () => readJson(file.loginReply, null);
85
- const tracking = { id: pending.verifier, pid: process.pid };
86
84
  const deadline = Date.parse(device.expires_at);
87
85
  // Why the relay last failed to answer, while it still does not.
88
86
  let down = null;
@@ -125,8 +123,6 @@ async function runDeviceHelper(home, pending, startStation) {
125
123
  };
126
124
  const waited = readPending(home)?.claims ?? [];
127
125
  writeJson(file.credentials, credentials);
128
- if (!waited.length)
129
- writeJson(file.loginReply, tracking);
130
126
  remove(file.login);
131
127
  if (answer.token)
132
128
  await carryGuest(home, pending.relayUrl, answer.token);
@@ -136,25 +132,9 @@ async function runDeviceHelper(home, pending, startStation) {
136
132
  if (answer.token && foundHere().length) {
137
133
  await startStation(home).catch((error) => console.error(`station login: Station did not start on this computer, so it cannot start your agents yet: ${error instanceof Error ? error.message : String(error)}`));
138
134
  }
139
- if (waited.length)
140
- return;
141
- try {
142
- while (replyState()?.id === tracking.id && Date.now() < deadline) {
143
- const result = await poll("/api/device/hello");
144
- if (replyState()?.id !== tracking.id)
145
- return;
146
- if (result?.reply) {
147
- writeJson(file.loginReply, { ...tracking, reply: result.reply });
148
- return;
149
- }
150
- await pause(1500);
151
- }
152
- }
153
- finally {
154
- const last = replyState();
155
- if (last?.id === tracking.id && !last.reply)
156
- remove(file.loginReply);
157
- }
135
+ // Tells the page this computer finished signing in, so it can say Connected. Older pages waited here for a typed reply; there is none to wait for.
136
+ if (!waited.length)
137
+ await poll("/api/device/hello");
158
138
  return;
159
139
  }
160
140
  if (!mine())
@@ -168,26 +148,6 @@ async function runDeviceHelper(home, pending, startStation) {
168
148
  writeJson(file.login, { ...readPending(home), error: error instanceof Error ? error.message : String(error) });
169
149
  }
170
150
  }
171
- export function takeDeviceReply(home, id) {
172
- const path = files(home).loginReply;
173
- const state = readJson(path, null);
174
- if (!state?.reply || (id && state.id !== id))
175
- return null;
176
- remove(path);
177
- return state.reply;
178
- }
179
- export async function waitForDeviceReply(home, id, deadline) {
180
- for (;;) {
181
- const state = readJson(files(home).loginReply, null);
182
- if (state?.id !== id)
183
- return null;
184
- if (state.reply)
185
- return takeDeviceReply(home, id);
186
- if (!alive(state.pid) || Date.now() >= deadline)
187
- return null;
188
- await pause(250);
189
- }
190
- }
191
151
  /** The seats a device sign-in on `relayUrl` sends with it, each once: the
192
152
  * seats a waiting link was given (join.ts), then every seat this computer
193
153
  * still holds there that joined with no sign-in and that, as far as it
@@ -237,13 +197,12 @@ export async function startLogin(home, relayUrl, webUrl, signUp, launch = spawnH
237
197
  ...(claims.length ? { claims } : {}),
238
198
  };
239
199
  const device = await call(relayUrl, "/api/device/start", null, {
240
- body: { label: pending.label, agent: asAgent, ...(asAgent ? {} : { agents: foundHere() }) },
200
+ body: { label: pending.label, agent: asAgent, ...(asAgent ? {} : { agents: agentsHere() }) },
241
201
  });
242
202
  const link = new URL("/cli/login", site);
243
203
  link.searchParams.set("code", device.code);
244
204
  if (signUp)
245
205
  link.searchParams.set("signup", "1");
246
- remove(files(home).loginReply);
247
206
  pending.device = { proof: device.proof, expires_at: device.expires_at };
248
207
  pending.url = link.toString();
249
208
  writeJson(files(home).login, pending);
@@ -293,7 +252,6 @@ export async function finishLogin(home, waitMs, waitForCode = true) {
293
252
  export function cancelLogin(home) {
294
253
  const pending = readPending(home);
295
254
  remove(files(home).login);
296
- remove(files(home).loginReply);
297
255
  if (pending?.pid && pending.pid !== process.pid && alive(pending.pid))
298
256
  process.kill(pending.pid, "SIGTERM");
299
257
  }
package/dist/signup.js CHANGED
@@ -11,7 +11,7 @@
11
11
  // costs a question. So this is the 1 command for both: for an address with
12
12
  // an account it prints the sign-in link `station login` would.
13
13
  import { hostname } from "node:os";
14
- import { foundHere } from "./agents.js";
14
+ import { agentsHere } from "./agents.js";
15
15
  import { readGuest } from "./guest.js";
16
16
  import { DEFAULT_WEB, files, readCredentials, remove, writeJson } from "./home.js";
17
17
  import { cancelLogin, claimSeat, elsewhere, loginLabel, readPending } from "./login.js";
@@ -20,9 +20,20 @@ import { call, RelayError, siteOf } from "./relay.js";
20
20
  export function agentsLine(agents) {
21
21
  if (!agents?.length)
22
22
  return [];
23
- const names = agents.length === 1 ? agents[0] : `${agents.slice(0, -1).join(", ")} and ${agents.at(-1)}`;
24
- const one = agents.length === 1;
25
- return [`${names} on this computer ${one ? "is" : "are"} your person's own agent${one ? "" : "s"} now. When ${one ? "it is" : "one is"} sent a message in your person's rooms, Station starts ${one ? "it" : "that agent"} here, in its own folder, to answer.`];
23
+ const list = (names) => (names.length === 1 ? names[0] : `${names.slice(0, -1).join(", ")} and ${names.at(-1)}`);
24
+ // Station starts Claude Code and Codex here; any other program it found is the person's, and joins when it runs Station itself.
25
+ const started = agents.filter((name) => name === "Claude Code" || name === "Codex");
26
+ const shown = agents.filter((name) => !started.includes(name));
27
+ const lines = [];
28
+ if (started.length) {
29
+ const one = started.length === 1;
30
+ lines.push(`${list(started)} on this computer ${one ? "is" : "are"} your person's own agent${one ? "" : "s"} now. When ${one ? "it is" : "one is"} sent a message in your person's rooms, Station starts ${one ? "it" : "that agent"} here, in its own folder, to answer.`);
31
+ }
32
+ if (shown.length) {
33
+ const one = shown.length === 1;
34
+ lines.push(`${list(shown)} on this computer ${one ? "is" : "are"} your person's agent${one ? "" : "s"} too. Station does not start ${one ? "it" : "them"}: ${one ? "it joins" : "each joins"} a room when it runs Station itself.`);
35
+ }
36
+ return lines;
26
37
  }
27
38
  /** "November 26": the day the rooms lock, as the email says it. */
28
39
  export function lockDay(locksAt) {
@@ -31,7 +42,7 @@ export function lockDay(locksAt) {
31
42
  /** Signs the person up, saves this computer's sign-in, and returns what to
32
43
  * print. An address that has an account gets `link`'s sign-in link, and so
33
44
  * does a new one on a relay that sends no email. */
34
- export async function signUp(home, relayUrl, webUrl, email, me = "station", label = loginLabel(hostname(), elsewhere()), link, agents = foundHere()) {
45
+ export async function signUp(home, relayUrl, webUrl, email, me = "station", label = loginLabel(hostname(), elsewhere()), link, agents = agentsHere()) {
35
46
  const saved = readCredentials(home);
36
47
  // A computer already signed in here says so: the relay sends the email
37
48
  // again for a sign-up that waits, and refuses one that has an account.
@@ -48,7 +59,7 @@ export async function signUp(home, relayUrl, webUrl, email, me = "station", labe
48
59
  catch (error) {
49
60
  if (!link || !(error instanceof RelayError))
50
61
  throw error;
51
- const give = "Give the person you work for this link, in your own chat. This computer is signed in once they click Approve.";
62
+ const give = "Give the person you work for this link, in your own chat. This computer is signed in once they click Connect.";
52
63
  if (error.code === "account_exists")
53
64
  return [`${email} already has a Station account, so nothing new was made. ${give}`, ...(await link(false))];
54
65
  if (error.code === "no_mail")
package/dist/waking.js CHANGED
@@ -62,12 +62,19 @@ export async function installSignIn(home, credentials, install) {
62
62
  export function lastChat(seats, agent) {
63
63
  return seats.filter((seat) => seat.agentId === agent && (seat.harness === "claude-code" || seat.harness === "codex")).sort((a, b) => b.joinedAt.localeCompare(a.joinedAt))[0] ?? null;
64
64
  }
65
+ export function wakeCredentials(home) {
66
+ const credentials = readCredentials(home);
67
+ if (!credentials?.agent)
68
+ return credentials;
69
+ return credentials.allowHooks !== undefined && credentials.secret ? { ...credentials, token: credentials.secret } : null;
70
+ }
65
71
  export function createWaking(deps) {
66
72
  const { home, log } = deps;
67
73
  const start = deps.start ?? startAgent;
68
74
  const limitOf = deps.limitOf ?? ((harness, id) => agentLimit(harness, id));
69
75
  const deliver = deps.deliver ?? ((chat, messageId, text) => deliverTo(chat.harness, chat.sessionId, messageId, text, chat.codexHome));
70
76
  const isOpen = deps.isOpen ?? ((seat) => delivers(seat.harness) && isRunning(seat.harness, seat.sessionId, seat.codexHome));
77
+ const openJoined = (seat) => !seat.left && isOpen(seat);
71
78
  const sleep = deps.wait ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
72
79
  const ownFolder = deps.ownFolder ?? ((kind) => (kind === "codex" ? lastFolder(codexHome()) : lastClaudeFolder(claudeHome())));
73
80
  /** Where a run of its own starts: the folder the agent last worked in
@@ -230,14 +237,11 @@ export function createWaking(deps) {
230
237
  }
231
238
  async function handle(credentials, wake) {
232
239
  const kind = wake.agent.kind;
233
- if (!isLocalKind(kind)) {
234
- await answer(credentials, wake, "failed", `this computer cannot start ${wake.agent.name}`);
235
- return;
236
- }
237
240
  // The session it is for (sent to it, or the one that began the thread), while its window is open;
238
241
  // else the agent's last chat here: its newest Claude Code or Codex window, in any room.
239
- const asked = wake.seat ? deps.seats().find((seat) => seat.participantId === wake.seat && seat.agentId === wake.agent.id) : undefined;
240
- const last = wake.seat_only ? asked ?? null : (asked && isOpen(asked) ? asked : lastChat(deps.seats(), wake.agent.id));
242
+ const seats = credentials.agent ? deps.seats().filter(openJoined) : deps.seats();
243
+ const asked = wake.seat ? seats.find((seat) => seat.participantId === wake.seat && seat.agentId === wake.agent.id) : undefined;
244
+ const last = wake.seat_only ? asked ?? null : (asked && isOpen(asked) ? asked : lastChat(seats, wake.agent.id));
241
245
  const key = `${wake.agent.id}:${last ? last.sessionId : wake.room}`;
242
246
  // One run per ask, however often it is handed out.
243
247
  const ask = `${wake.agent.id}:${wake.room}:${wake.message}`;
@@ -253,8 +257,12 @@ export function createWaking(deps) {
253
257
  return;
254
258
  }
255
259
  // Someone else's ask: Station starts the agent only for its own person.
256
- if (wake.may_start === false) {
257
- await answer(credentials, wake, "failed", `Station starts ${wake.agent.name} only for messages from its own person or their agents, and no window of it is open here`);
260
+ if (credentials.agent || wake.may_start === false) {
261
+ await answer(credentials, wake, "failed", credentials.agent ? "no window of it is open on this computer" : `Station starts ${wake.agent.name} only for messages from its own person or their agents, and no window of it is open here`);
262
+ return;
263
+ }
264
+ if (!isLocalKind(kind)) {
265
+ await answer(credentials, wake, "failed", `this computer cannot start ${wake.agent.name}`);
258
266
  return;
259
267
  }
260
268
  const before = runs.get(key);
@@ -299,9 +307,11 @@ export function createWaking(deps) {
299
307
  running: () => runs.size > 0,
300
308
  /** One read of the relay's wakes. */
301
309
  async once(waitSeconds = 25) {
302
- const credentials = readCredentials(home);
303
- if (!credentials || credentials.agent)
310
+ const credentials = wakeCredentials(home);
311
+ if (!credentials || (credentials.agent && !deps.seats().some(openJoined))) {
312
+ installsOn = false;
304
313
  return null;
314
+ }
305
315
  const got = await call(credentials.relayUrl, `/cli/wakes?wait=${waitSeconds}&seat_only=1`, { token: credentials.token });
306
316
  installsOn = got.installs.some((install) => install.on);
307
317
  for (const wake of got.wakes) {
@@ -317,7 +327,7 @@ export function createWaking(deps) {
317
327
  try {
318
328
  const got = await this.once();
319
329
  if (!got)
320
- await sleep(30_000);
330
+ await sleep(wakeCredentials(home)?.agent ? 1_000 : 30_000);
321
331
  }
322
332
  catch (error) {
323
333
  log(`wakes not read: ${error instanceof Error ? error.message : String(error)}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@santori/station",
3
- "version": "0.9.12",
3
+ "version": "0.9.13",
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",