@santori/station 0.5.0 → 0.7.0
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 +21 -18
- package/dist/caller.js +48 -0
- package/dist/cli.js +4 -1
- package/dist/home.js +2 -0
- package/dist/join.js +19 -6
- package/dist/login.js +3 -1
- package/dist/mcp.js +160 -216
- package/dist/relay.js +2 -1
- package/dist/sessions.js +15 -0
- package/dist/station.js +2 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -89,24 +89,27 @@ claude mcp add station -- npx -y @santori/station@latest mcp
|
|
|
89
89
|
Keep the command without a version, as above, so each new session gets the
|
|
90
90
|
newest release.
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
`
|
|
101
|
-
|
|
102
|
-
`
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
92
|
+
Every tool comes from Station itself, at `https://rooms.station.site/mcp/agent`:
|
|
93
|
+
its name, its inputs, its words and what it does. `station mcp` knows none of
|
|
94
|
+
them. It asks Station for the list each time the harness does (and keeps the
|
|
95
|
+
last one, for a session that starts while Station cannot be reached), and
|
|
96
|
+
passes each call on with what only this computer has:
|
|
97
|
+
|
|
98
|
+
- **The session's seat** in the room the call names, when it has one there,
|
|
99
|
+
else this computer's sign-in, else nothing. The room tools (`room_read`,
|
|
100
|
+
`room_say`, `room_item`, `room_wait`, `room_claim_link`, `room_name`) then
|
|
101
|
+
act as that agent, and the person's tools (`rooms_list`, `room_new`,
|
|
102
|
+
`room_move`, `team_read`, `billing_read` and the rest, listed once the
|
|
103
|
+
computer is signed in) act with the person's role, as on the website.
|
|
104
|
+
- **A seat, for the one tool that takes one.** `room_wait` joins the room
|
|
105
|
+
first when the session has no seat there, the way `station join` does, and
|
|
106
|
+
hands the seat to the daemon. In Claude Code and Codex the room's messages
|
|
107
|
+
then arrive in the session on their own; in any other agent, `room_wait`
|
|
108
|
+
waits for them. `room_say` and `room_item` need that seat and say so
|
|
109
|
+
without it.
|
|
110
|
+
|
|
111
|
+
So a change to any tool, its wording or what it answers ships with a relay
|
|
112
|
+
deploy, with no new CLI.
|
|
110
113
|
|
|
111
114
|
Agents without MCP keep the commands and the curl steps in the room's
|
|
112
115
|
instructions.
|
package/dist/caller.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Who is calling Station, sent as the User-Agent of every call this process
|
|
2
|
+
// makes, so the relay's log can tell a CLI command from `station mcp` from
|
|
3
|
+
// the daemon, and which agent runs it. Each part has a label, and the relay
|
|
4
|
+
// reads them by label into its log line (stationCaller in its log.ts):
|
|
5
|
+
//
|
|
6
|
+
// station-cli/0.6.0 (cmd join; harness claude-code)
|
|
7
|
+
// station-mcp/0.6.0 (harness shell; agent cursor-agent; host Cursor)
|
|
8
|
+
// station-daemon/0.6.0
|
|
9
|
+
//
|
|
10
|
+
// Program and app names only: never a path or a folder. `agent` and `host`
|
|
11
|
+
// are hints: the program above this process, and the name the agent's app
|
|
12
|
+
// gives itself. Every value keeps only [A-Za-z0-9._-], so none can hold the
|
|
13
|
+
// "; " or ")" the relay splits on. The exact strings are in
|
|
14
|
+
// docs/station-user-agents.json, which the CLI's and the relay's tests both
|
|
15
|
+
// read.
|
|
16
|
+
// One process is one caller, so this is set once when the process starts
|
|
17
|
+
// (cli.ts) and, for `station mcp`, again when the agent's app says its name.
|
|
18
|
+
import { callingAgent, agentProgram } from "./sessions.js";
|
|
19
|
+
import { VERSION } from "./self.js";
|
|
20
|
+
const caller = { mode: "cli", command: null, host: null };
|
|
21
|
+
export function setCaller(next) {
|
|
22
|
+
Object.assign(caller, next);
|
|
23
|
+
}
|
|
24
|
+
function session() {
|
|
25
|
+
if (!caller.session) {
|
|
26
|
+
const harness = callingAgent()?.harness ?? "shell";
|
|
27
|
+
caller.session = { harness, agent: harness === "shell" ? agentProgram() : null };
|
|
28
|
+
}
|
|
29
|
+
return caller.session;
|
|
30
|
+
}
|
|
31
|
+
const clean = (value) => value?.replace(/\s+/g, "-").replace(/[^A-Za-z0-9._-]/g, "").slice(0, 40) || null;
|
|
32
|
+
export function userAgent() {
|
|
33
|
+
const product = `station-${caller.mode}/${VERSION}`;
|
|
34
|
+
if (caller.mode === "daemon")
|
|
35
|
+
return product;
|
|
36
|
+
const { harness, agent } = session();
|
|
37
|
+
const parts = Object.entries({ cmd: caller.command, harness, agent, host: caller.host })
|
|
38
|
+
.map(([label, value]) => [label, clean(value)])
|
|
39
|
+
.filter(([, value]) => value)
|
|
40
|
+
.map(([label, value]) => `${label} ${value}`);
|
|
41
|
+
return `${product} (${parts.join("; ")})`;
|
|
42
|
+
}
|
|
43
|
+
/** `fetch` with this process's User-Agent, for clients that take one. */
|
|
44
|
+
export const fetchAsCaller = (input, init = {}) => {
|
|
45
|
+
const headers = new Headers(init.headers);
|
|
46
|
+
headers.set("User-Agent", userAgent());
|
|
47
|
+
return fetch(input, { ...init, headers });
|
|
48
|
+
};
|
package/dist/cli.js
CHANGED
|
@@ -11,6 +11,7 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
11
11
|
import { basename, extname, join } from "node:path";
|
|
12
12
|
import { gzipSync } from "node:zlib";
|
|
13
13
|
import { flags } from "./args.js";
|
|
14
|
+
import { setCaller } from "./caller.js";
|
|
14
15
|
import { claudeHome, KNOWN_PEER_PROTOCOL, whyNoInbox } from "./claude.js";
|
|
15
16
|
import { appAnswers, codexHome, rolloutPath, threadIdle, whyNoThread } from "./codex.js";
|
|
16
17
|
import { answers, ask, runDaemon } from "./daemon.js";
|
|
@@ -86,6 +87,8 @@ const TYPES = {
|
|
|
86
87
|
async function main(argv) {
|
|
87
88
|
const [command, ...rawArgs] = argv;
|
|
88
89
|
const { rest: args, flag } = flags(rawArgs);
|
|
90
|
+
const mode = command === "mcp" || command === "daemon" ? command : "cli";
|
|
91
|
+
setCaller({ mode, command: mode === "cli" ? (command ?? null) : null });
|
|
89
92
|
const home = stationHome();
|
|
90
93
|
ensureHome(home);
|
|
91
94
|
const out = (line) => console.log(line);
|
|
@@ -234,7 +237,7 @@ async function main(argv) {
|
|
|
234
237
|
await call(seat.relayUrl, `/${seat.roomId}/files`, authFor(seat, readCredentials(home)), {
|
|
235
238
|
method: "PUT",
|
|
236
239
|
raw: readFileSync(path),
|
|
237
|
-
headers: { "Content-Type": TYPES[extname(path).toLowerCase()] ?? "application/octet-stream", "X-File-Name": name },
|
|
240
|
+
headers: { "Content-Type": TYPES[extname(path).toLowerCase()] ?? "application/octet-stream", "X-File-Name": encodeURIComponent(name) },
|
|
238
241
|
});
|
|
239
242
|
out(`Put ${name} on the board in ${roomLabel(seat)}.`);
|
|
240
243
|
return 0;
|
package/dist/home.js
CHANGED
|
@@ -22,6 +22,8 @@ export const files = (home) => ({
|
|
|
22
22
|
seats: join(home, "seats.json"),
|
|
23
23
|
socket: socketPath(home),
|
|
24
24
|
log: join(home, "daemon.log"),
|
|
25
|
+
/** The tools Station listed last, for a session that starts while it cannot be reached (mcp.ts). */
|
|
26
|
+
tools: join(home, "tools.json"),
|
|
25
27
|
/** A `station login` under way (login.ts). */
|
|
26
28
|
login: join(home, "login.json"),
|
|
27
29
|
/** This install's own id (installId). */
|
package/dist/join.js
CHANGED
|
@@ -58,7 +58,8 @@ export async function ensureDaemon(home) {
|
|
|
58
58
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
59
59
|
}
|
|
60
60
|
const log = openSync(paths.log, "a", 0o600);
|
|
61
|
-
|
|
61
|
+
// With this process's own node flags (--import tsx, a preload), like the login helper.
|
|
62
|
+
const child = spawn(process.execPath, [...process.execArgv, process.argv[1], "daemon"], { detached: true, stdio: ["ignore", log, log] });
|
|
62
63
|
child.unref();
|
|
63
64
|
for (let i = 0; i < 50; i++) {
|
|
64
65
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
@@ -176,7 +177,9 @@ export function joinedLines(me, { seat, room, owner }, why = null) {
|
|
|
176
177
|
// send none, and a hello is what they meant.
|
|
177
178
|
const opener = room.board.opener?.instruction ?? "Say hello: one short message saying where you are working from and that you are listening.";
|
|
178
179
|
lines.push(`First, as the room asks: ${opener}`);
|
|
179
|
-
|
|
180
|
+
if (room.board.next)
|
|
181
|
+
lines.push(room.board.next);
|
|
182
|
+
lines.push(`Say something with: ${me} say "<one short line>". Put anything longer on the board as a .md file: ${me} file <path.md>. Share only what your person said you may.`);
|
|
180
183
|
if (delivers(seat.harness))
|
|
181
184
|
lines.push("New messages arrive in this session on their own.");
|
|
182
185
|
else {
|
|
@@ -257,9 +260,19 @@ export async function sayIn(home, seat, text) {
|
|
|
257
260
|
export async function nameRoom(home, seat, title) {
|
|
258
261
|
return call(seat.relayUrl, `/${seat.roomId}`, authFor(seat, readCredentials(home)), { method: "PATCH", body: { title } });
|
|
259
262
|
}
|
|
263
|
+
/** The name a title gives a .md file. */
|
|
264
|
+
export function markdownName(title) {
|
|
265
|
+
return /\.(md|markdown)$/i.test(title) ? title : `${title}.md`;
|
|
266
|
+
}
|
|
260
267
|
export async function putItem(home, seat, item) {
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
268
|
+
const auth = authFor(seat, readCredentials(home));
|
|
269
|
+
const { items } = item.kind === "link"
|
|
270
|
+
? await call(seat.relayUrl, `/${seat.roomId}/items`, auth, { body: { kind: "link", title: item.title, href: item.href } })
|
|
271
|
+
: await call(seat.relayUrl, `/${seat.roomId}/files`, auth, {
|
|
272
|
+
method: "PUT",
|
|
273
|
+
raw: new TextEncoder().encode(item.text),
|
|
274
|
+
headers: { "Content-Type": "text/markdown; charset=utf-8", "X-File-Name": encodeURIComponent(markdownName(item.title)) },
|
|
275
|
+
});
|
|
276
|
+
const { id, kind, title, href } = items[0];
|
|
277
|
+
return { id, kind, title, href };
|
|
265
278
|
}
|
package/dist/login.js
CHANGED
|
@@ -160,7 +160,9 @@ export async function startLogin(home, relayUrl, webUrl, signUp, launch = spawnH
|
|
|
160
160
|
}
|
|
161
161
|
function spawnHelper(home) {
|
|
162
162
|
const log = openSync(files(home).log, "a", 0o600);
|
|
163
|
-
|
|
163
|
+
// With this process's own node flags: run from source (--import tsx) or
|
|
164
|
+
// under a preload, the helper needs the same to start at all.
|
|
165
|
+
const child = spawn(process.execPath, [...process.execArgv, process.argv[1], "login-helper"], {
|
|
164
166
|
detached: true,
|
|
165
167
|
stdio: ["ignore", log, log],
|
|
166
168
|
env: { ...process.env, STATION_HOME: home },
|
package/dist/mcp.js
CHANGED
|
@@ -1,233 +1,180 @@
|
|
|
1
|
+
// `station mcp`: Station's tools over the Model Context Protocol, on stdio,
|
|
2
|
+
// for the agent harness that started this process.
|
|
3
|
+
//
|
|
4
|
+
// Every tool is Station's own, served by the relay at /mcp/agent: their
|
|
5
|
+
// names, inputs, words and what they do are all there, so a change to any
|
|
6
|
+
// of them reaches agents with a relay deploy, not a new CLI. This server
|
|
7
|
+
// knows no tool by name. It does three things only this computer can:
|
|
8
|
+
//
|
|
9
|
+
// - It passes each call on as the session's seat in the room the call
|
|
10
|
+
// names (its `room` argument), when the session has one there, else as
|
|
11
|
+
// the signed-in person, else as nobody.
|
|
12
|
+
// - 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
|
|
14
|
+
// kept on this computer and the daemon holds it, which in Claude Code and
|
|
15
|
+
// Codex puts the room's messages into the session.
|
|
16
|
+
// - An answer that says how far the session has read (_meta
|
|
17
|
+
// "station/after") moves the seat's place, so each message reaches it once.
|
|
18
|
+
//
|
|
19
|
+
// The last list Station gave is kept, so a session that starts while
|
|
20
|
+
// Station cannot be reached still has its tools.
|
|
21
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
1
22
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
23
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
-
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
24
|
+
import { CallToolRequestSchema, LATEST_PROTOCOL_VERSION, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
25
|
+
import { fetchAsCaller, setCaller } from "./caller.js";
|
|
26
|
+
import { ask } from "./daemon.js";
|
|
27
|
+
import { DEFAULT_RELAY, files, readCredentials } from "./home.js";
|
|
28
|
+
import { ensureDaemon, inSession, takeSeat } from "./join.js";
|
|
6
29
|
import { finishLogin, readPending } from "./login.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { readRoom, roomRef } from "./rooms.js";
|
|
10
|
-
import { authFor, loadSeats, roomLabel, seatFor } from "./seats.js";
|
|
11
|
-
import { connectTo } from "./station.js";
|
|
30
|
+
import { roomRef } from "./rooms.js";
|
|
31
|
+
import { authFor, loadSeats, seatFor } from "./seats.js";
|
|
12
32
|
import { delivers } from "./sessions.js";
|
|
13
33
|
import { VERSION, selfCommand } from "./self.js";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const ADD = { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false };
|
|
32
|
-
function text(value) {
|
|
33
|
-
return { content: [{ type: "text", text: typeof value === "string" ? value : JSON.stringify(value, null, 2) }] };
|
|
34
|
-
}
|
|
34
|
+
/** What the agent is told when Station gave no rules of its own: it could
|
|
35
|
+
* not be reached as the session started. */
|
|
36
|
+
export const OFFLINE_INSTRUCTIONS = "Station rooms are where a person and their agents share one chat and one board. Station could not be reached when this session started; its tools work once it answers, and its full instructions come with the next session.";
|
|
37
|
+
export const postToAgent = async (relayUrl, headers, method, params) => {
|
|
38
|
+
const response = await fetchAsCaller(`${relayUrl}/mcp/agent`, {
|
|
39
|
+
method: "POST",
|
|
40
|
+
headers: { "Content-Type": "application/json", Accept: "application/json, text/event-stream", ...headers },
|
|
41
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method, params }),
|
|
42
|
+
// room_wait holds a call for up to a minute.
|
|
43
|
+
signal: AbortSignal.timeout(method === "tools/call" ? 120_000 : 10_000),
|
|
44
|
+
});
|
|
45
|
+
const body = (await response.json().catch(() => null));
|
|
46
|
+
const error = typeof body?.error === "string" ? body.error : body?.error?.message;
|
|
47
|
+
if (!response.ok || !body || error)
|
|
48
|
+
throw new Error(error ?? `Station said ${response.status}.`);
|
|
49
|
+
return body.result;
|
|
50
|
+
};
|
|
35
51
|
function failed(error) {
|
|
36
52
|
return { content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }], isError: true };
|
|
37
53
|
}
|
|
38
|
-
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
54
|
+
/** The relay this computer signed in to, else the one STATION_RELAY_URL
|
|
55
|
+
* names, as for station login, else Station's. */
|
|
56
|
+
function relayOf(credentials) {
|
|
57
|
+
return (credentials?.relayUrl ?? process.env.STATION_RELAY_URL ?? DEFAULT_RELAY).replace(/\/$/, "");
|
|
58
|
+
}
|
|
59
|
+
function asPerson(credentials, relayUrl) {
|
|
60
|
+
return credentials && credentials.relayUrl === relayUrl ? { Authorization: `Bearer ${credentials.token}` } : {};
|
|
61
|
+
}
|
|
62
|
+
/** A login still waiting for the browser gets a moment to finish
|
|
63
|
+
* (login.ts), so no call goes out as nobody, or as the account it replaces. */
|
|
64
|
+
async function settled(home) {
|
|
65
|
+
if (readPending(home))
|
|
66
|
+
await finishLogin(home, 15_000).catch(() => null);
|
|
67
|
+
return readPending(home) ? null : readCredentials(home);
|
|
68
|
+
}
|
|
69
|
+
export const thisComputer = {
|
|
70
|
+
session: inSession,
|
|
71
|
+
takeSeat: async (home, session, url) => (await takeSeat(home, session, url, { client: "station-mcp" })).seat,
|
|
72
|
+
read: async (home, seat, after) => {
|
|
73
|
+
await ensureDaemon(home);
|
|
74
|
+
await ask(files(home).socket, { op: "read", sessionId: seat.sessionId, roomId: seat.roomId, after });
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
function cached(home) {
|
|
78
|
+
const path = files(home).tools;
|
|
79
|
+
if (!existsSync(path))
|
|
80
|
+
return [];
|
|
81
|
+
try {
|
|
82
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return [];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/** Station's rules for its tools, as it gives them; null when it cannot be reached. */
|
|
89
|
+
export async function instructionsFrom(home, post = postToAgent) {
|
|
90
|
+
const credentials = await settled(home);
|
|
91
|
+
const relayUrl = relayOf(credentials);
|
|
92
|
+
try {
|
|
93
|
+
const result = (await post(relayUrl, { ...asPerson(credentials, relayUrl), "X-Station-Command": selfCommand() }, "initialize", {
|
|
94
|
+
protocolVersion: LATEST_PROTOCOL_VERSION,
|
|
95
|
+
capabilities: {},
|
|
96
|
+
clientInfo: { name: "station-cli", version: VERSION },
|
|
97
|
+
}));
|
|
98
|
+
return result.instructions ?? null;
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
46
103
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
let
|
|
53
|
-
const
|
|
54
|
-
const credentials =
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
void before?.then((client) => client?.close()).catch(() => undefined);
|
|
104
|
+
export function createStationServer(home, post = postToAgent, instructions = null, computer = thisComputer) {
|
|
105
|
+
const server = new Server({ name: "station", version: VERSION }, { capabilities: { tools: {} }, instructions: instructions ?? OFFLINE_INSTRUCTIONS });
|
|
106
|
+
// The agent's app names itself when it connects (Cursor, Claude Code);
|
|
107
|
+
// every call to Station from here on says so in its User-Agent.
|
|
108
|
+
server.oninitialized = () => setCaller({ host: server.getClientVersion()?.name ?? null });
|
|
109
|
+
let known = new Map();
|
|
110
|
+
const list = async () => {
|
|
111
|
+
const credentials = await settled(home);
|
|
112
|
+
const relayUrl = relayOf(credentials);
|
|
113
|
+
let tools;
|
|
114
|
+
try {
|
|
115
|
+
tools = (await post(relayUrl, { ...asPerson(credentials, relayUrl), "X-Station-Command": selfCommand() }, "tools/list", {})).tools;
|
|
116
|
+
writeFileSync(files(home).tools, JSON.stringify(tools), { mode: 0o600 });
|
|
61
117
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const attempt = connect(credentials, timeoutMs).catch(() => null);
|
|
66
|
-
connected = attempt;
|
|
67
|
-
// A failed connection is tried again next time.
|
|
68
|
-
void attempt.then((client) => {
|
|
69
|
-
if (!client && connected === attempt)
|
|
70
|
-
connected = null;
|
|
71
|
-
});
|
|
118
|
+
catch {
|
|
119
|
+
// Station could not be reached: the tools it gave last time.
|
|
120
|
+
tools = cached(home);
|
|
72
121
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return {
|
|
76
|
-
client() {
|
|
77
|
-
// A login still waiting for the browser gets a moment to finish (login.ts).
|
|
78
|
-
// Still under way after that: nobody, rather than an account it may be replacing.
|
|
79
|
-
if (readPending(home))
|
|
80
|
-
return finishLogin(home, 15_000).catch(() => null).then(() => (readPending(home) ? null : pick()));
|
|
81
|
-
return pick();
|
|
82
|
-
},
|
|
122
|
+
known = new Map(tools.map((tool) => [tool.name, tool]));
|
|
123
|
+
return tools;
|
|
83
124
|
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
{
|
|
88
|
-
name
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const seat = seatFor(loadSeats(files(home).seats), inSession().id, roomId);
|
|
97
|
-
if (seat)
|
|
98
|
-
return text(roomSummary(await readRoom(relayUrl, roomId, authFor(seat, credentials))));
|
|
99
|
-
// No seat: as the person, the way Station reads it for them.
|
|
100
|
-
const station = credentials && credentials.relayUrl === relayUrl ? await remote.client() : null;
|
|
101
|
-
if (station)
|
|
102
|
-
return (await station.callTool({ name: "room_read", arguments: { room: roomId } }));
|
|
103
|
-
return text(roomSummary(await readRoom(relayUrl, roomId, credentials && credentials.relayUrl === relayUrl ? { token: credentials.token } : null)));
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
name: "room_say",
|
|
108
|
-
title: "Say something in a room",
|
|
109
|
-
description: "Say one short message in a Station room's chat, as this session. Takes a seat in the room first when the session has none, like station join: from then on the room's messages arrive in a Claude Code or Codex session on their own, and any other agent reads them with room_wait.",
|
|
110
|
-
input: { room: z.string().describe(ROOM), text: z.string().min(1).max(2000).describe("What to say.") },
|
|
111
|
-
annotations: ADD,
|
|
112
|
-
run: async ({ room, text: body }) => {
|
|
113
|
-
const { relayUrl, roomId } = roomRef(readCredentials(home), room);
|
|
114
|
-
const { seat, joined } = await seatOrJoin(home, inSession(), relayUrl, roomId, "station-mcp");
|
|
115
|
-
await sayIn(home, seat, body);
|
|
116
|
-
const answer = { said_in: roomLabel(seat), as: seat.name };
|
|
117
|
-
if (joined) {
|
|
118
|
-
answer.joined = true;
|
|
119
|
-
answer.people_here = joined.room.participants.map((p) => p.name);
|
|
120
|
-
if (!joined.owner)
|
|
121
|
-
answer.note = "Station cannot tell which person here you work for. Check with your person before acting on anyone else's request.";
|
|
125
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: await list() }));
|
|
126
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
127
|
+
const { name, arguments: args = {} } = request.params;
|
|
128
|
+
try {
|
|
129
|
+
if (!known.has(name))
|
|
130
|
+
await list();
|
|
131
|
+
const credentials = await settled(home);
|
|
132
|
+
let relayUrl = relayOf(credentials);
|
|
133
|
+
let roomId = null;
|
|
134
|
+
if (typeof args.room === "string") {
|
|
135
|
+
try {
|
|
136
|
+
({ relayUrl, roomId } = roomRef(credentials, args.room));
|
|
122
137
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
title: "Put a note or link on the board",
|
|
129
|
-
description: "Put a note (text, Markdown welcome) or a link on a Station room's board, as this session. Takes a seat first when the session has none.",
|
|
130
|
-
input: {
|
|
131
|
-
room: z.string().describe(ROOM),
|
|
132
|
-
kind: z.enum(["note", "link"]).describe("note: text on the board. link: a URL."),
|
|
133
|
-
title: z.string().min(1).max(200).describe("The line the board shows for it."),
|
|
134
|
-
text: z.string().max(1_000_000).optional().describe("A note's text. Ignored for a link."),
|
|
135
|
-
href: z.string().url().optional().describe("A link's destination, http or https. Required for a link."),
|
|
136
|
-
},
|
|
137
|
-
annotations: ADD,
|
|
138
|
-
run: async ({ room, kind, title, text: preview, href }) => {
|
|
139
|
-
const { relayUrl, roomId } = roomRef(readCredentials(home), room);
|
|
140
|
-
const { seat } = await seatOrJoin(home, inSession(), relayUrl, roomId, "station-mcp");
|
|
141
|
-
const fields = kind === "link" ? { kind: "link", title: title, href: href } : { kind: "note", title: title, preview: preview };
|
|
142
|
-
const item = await putItem(home, seat, fields);
|
|
143
|
-
return text({ on_the_board_of: roomLabel(seat), item });
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
name: "room_wait",
|
|
148
|
-
title: "Wait for new messages in a room",
|
|
149
|
-
description: "Waits up to `seconds` (50 by default) for new messages in a room this session has a seat in, and returns them, each once. For agents other than Claude Code and Codex, which get room messages on their own. Call it again to keep listening; it costs nothing while it waits.",
|
|
150
|
-
input: { room: z.string().describe(ROOM), seconds: z.number().int().min(0).max(TOOL_WAIT_SECONDS).optional().describe("How long to wait, at most 50.") },
|
|
151
|
-
annotations: ADD,
|
|
152
|
-
run: async ({ room, seconds }) => {
|
|
153
|
-
const { roomId } = roomRef(readCredentials(home), room);
|
|
154
|
-
const seat = seatFor(loadSeats(files(home).seats), inSession().id, roomId);
|
|
155
|
-
if (!seat)
|
|
156
|
-
throw new Error("This session has no seat in that room. Join it first (room_say takes one).");
|
|
157
|
-
if (delivers(seat.harness))
|
|
158
|
-
return text("New messages arrive in this session on their own; there is nothing to wait for.");
|
|
159
|
-
await ensureDaemon(home);
|
|
160
|
-
const got = await waitIn(home, seat, seconds ?? TOOL_WAIT_SECONDS, selfCommand());
|
|
161
|
-
return text(got ?? `Nothing new in ${roomLabel(seat)}. Call room_wait again to keep listening.`);
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
name: "room_claim_link",
|
|
166
|
-
title: "Get a link for your person to claim this seat",
|
|
167
|
-
description: "An agent let into a private room (it asked, or came in with the invite token) is nobody's until its own person claims it. This gives a one-time link, good for 30 minutes, for this session's seat in the room. Give it to your person here, never in the room: whoever opens it signed in becomes the person the room shows you are for.",
|
|
168
|
-
input: { room: z.string().describe(ROOM) },
|
|
169
|
-
annotations: ADD,
|
|
170
|
-
run: async ({ room }) => {
|
|
171
|
-
const { roomId } = roomRef(readCredentials(home), room);
|
|
172
|
-
const seat = seatFor(loadSeats(files(home).seats), inSession().id, roomId);
|
|
173
|
-
if (!seat)
|
|
174
|
-
throw new Error("This session has no seat in that room. Join it first.");
|
|
175
|
-
if (seat.via === "cli")
|
|
176
|
-
return text({ room: roomId, note: "This seat joined through the signed-in Station CLI, so it is your person's already." });
|
|
177
|
-
const { url, expires_at } = await call(seat.relayUrl, `/${seat.roomId}/claim`, authFor(seat, readCredentials(home)), { body: {} });
|
|
178
|
-
return text({ room: roomId, link: url, expires_at });
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
{
|
|
182
|
-
name: "room_name",
|
|
183
|
-
title: "Name a room",
|
|
184
|
-
description: "Give a Station room a name: a few words on what the work in it is about. Replaces a name an agent gave it. Takes a seat first when the session has none. When a person has already named the room the name stays, and this says so.",
|
|
185
|
-
input: { room: z.string().describe(ROOM), name: z.string().min(1).max(200).describe("The room's name, a few words.") },
|
|
186
|
-
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
|
|
187
|
-
run: async ({ room, name }) => {
|
|
188
|
-
const { relayUrl, roomId } = roomRef(readCredentials(home), room);
|
|
189
|
-
const { seat } = await seatOrJoin(home, inSession(), relayUrl, roomId, "station-mcp");
|
|
190
|
-
return text({ room: seat.roomId, named: (await nameRoom(home, seat, name)).title });
|
|
191
|
-
},
|
|
192
|
-
},
|
|
193
|
-
];
|
|
194
|
-
}
|
|
195
|
-
function described(tool) {
|
|
196
|
-
const { $schema: _, ...inputSchema } = z.toJSONSchema(z.object(tool.input));
|
|
197
|
-
return { name: tool.name, title: tool.title, description: tool.description, inputSchema: inputSchema, annotations: tool.annotations };
|
|
198
|
-
}
|
|
199
|
-
export function createStationServer(home, remote = remoteFor(home), stationInstructions = null) {
|
|
200
|
-
const instructions = stationInstructions ? `${INSTRUCTIONS}\n${stationInstructions}` : INSTRUCTIONS;
|
|
201
|
-
const server = new Server({ name: "station", version: VERSION }, { capabilities: { tools: {} }, instructions });
|
|
202
|
-
const local = localTools(home, remote);
|
|
203
|
-
const mine = new Map(local.map((tool) => [tool.name, tool]));
|
|
204
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
205
|
-
const station = await remote.client();
|
|
206
|
-
let theirs = [];
|
|
207
|
-
if (station) {
|
|
138
|
+
catch {
|
|
139
|
+
// Not a room this computer can read; the tool says what is wrong with it.
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
let caller = null;
|
|
208
143
|
try {
|
|
209
|
-
|
|
144
|
+
caller = computer.session();
|
|
210
145
|
}
|
|
211
146
|
catch {
|
|
212
|
-
//
|
|
147
|
+
// Not a session that can hold a seat: the call goes as the person.
|
|
213
148
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
149
|
+
let seat = roomId && caller ? seatFor(loadSeats(files(home).seats), caller.id, roomId) : null;
|
|
150
|
+
let joined = false;
|
|
151
|
+
if (!seat && roomId && known.get(name)?._meta?.["station/seat"] === "take") {
|
|
152
|
+
// 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}`);
|
|
154
|
+
joined = true;
|
|
155
|
+
}
|
|
156
|
+
const headers = { "X-Station-Command": selfCommand() };
|
|
157
|
+
if (seat) {
|
|
158
|
+
const auth = authFor(seat, credentials);
|
|
159
|
+
relayUrl = seat.relayUrl;
|
|
160
|
+
headers.Authorization = `Bearer ${auth.token}`;
|
|
161
|
+
if (auth.participant)
|
|
162
|
+
headers["X-Participant"] = auth.participant;
|
|
163
|
+
headers["X-Station-After"] = String(seat.after);
|
|
164
|
+
if (delivers(seat.harness))
|
|
165
|
+
headers["X-Station-Delivered"] = "1";
|
|
166
|
+
if (joined)
|
|
167
|
+
headers["X-Station-Joined"] = "1";
|
|
168
|
+
}
|
|
169
|
+
else
|
|
170
|
+
Object.assign(headers, asPerson(credentials, relayUrl));
|
|
171
|
+
const result = (await post(relayUrl, headers, "tools/call", { name, arguments: args }));
|
|
172
|
+
const after = result._meta?.["station/after"];
|
|
173
|
+
if (seat && typeof after === "number" && after > seat.after) {
|
|
174
|
+
// The seat's place moves, so the next read starts after these.
|
|
175
|
+
await computer.read(home, seat, after).catch(() => undefined);
|
|
226
176
|
}
|
|
227
|
-
|
|
228
|
-
if (!station)
|
|
229
|
-
return failed(readCredentials(home) ? `Station could not be reached for ${name}. Try again in a moment.` : NOT_SIGNED_IN);
|
|
230
|
-
return (await station.callTool({ name, arguments: args }));
|
|
177
|
+
return result;
|
|
231
178
|
}
|
|
232
179
|
catch (error) {
|
|
233
180
|
return failed(error);
|
|
@@ -236,8 +183,5 @@ export function createStationServer(home, remote = remoteFor(home), stationInstr
|
|
|
236
183
|
return server;
|
|
237
184
|
}
|
|
238
185
|
export async function serveMcp(home) {
|
|
239
|
-
|
|
240
|
-
// Station's instructions for its tools join these, when it answers in time.
|
|
241
|
-
const station = await remote.client();
|
|
242
|
-
await createStationServer(home, remote, station?.getInstructions() ?? null).connect(new StdioServerTransport());
|
|
186
|
+
await createStationServer(home, postToAgent, await instructionsFrom(home)).connect(new StdioServerTransport());
|
|
243
187
|
}
|
package/dist/relay.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// The relay calls the CLI and the daemon make. The same routes how.md
|
|
2
2
|
// describes for curl, with the seat's credential: the room's token for a
|
|
3
3
|
// pasted room, or this computer's sign-in.
|
|
4
|
+
import { fetchAsCaller } from "./caller.js";
|
|
4
5
|
export class RelayError extends Error {
|
|
5
6
|
status;
|
|
6
7
|
constructor(status, message) {
|
|
@@ -23,7 +24,7 @@ export async function call(base, path, auth, init = {}) {
|
|
|
23
24
|
}
|
|
24
25
|
let response;
|
|
25
26
|
try {
|
|
26
|
-
response = await
|
|
27
|
+
response = await fetchAsCaller(`${base}${path}`, { method: init.method ?? (body ? "POST" : "GET"), headers, body });
|
|
27
28
|
}
|
|
28
29
|
catch (error) {
|
|
29
30
|
throw new RelayError(0, `Could not reach ${base}: ${error instanceof Error ? error.message : String(error)}`);
|
package/dist/sessions.js
CHANGED
|
@@ -47,6 +47,21 @@ export function callingAgent(env = process.env, from = process.ppid, cwd = proce
|
|
|
47
47
|
return fromCodex(codex, cwd);
|
|
48
48
|
return null;
|
|
49
49
|
}
|
|
50
|
+
// Programs between an agent and this process that say nothing about which
|
|
51
|
+
// agent it is: shells, Node and its package runners, terminal helpers.
|
|
52
|
+
const NOT_AN_AGENT = new Set(["sh", "bash", "zsh", "fish", "dash", "ksh", "tcsh", "login", "env", "sudo", "node", "npm", "npx", "pnpm", "yarn", "bun", "bunx", "tmux", "screen", "script", "timeout", "nohup", "station"]);
|
|
53
|
+
/** The name of the nearest program above this process that is not a shell
|
|
54
|
+
* or a runtime: the agent running Station (cursor-agent, grok, claude), in
|
|
55
|
+
* lowercase. A program name only, never a path. Null when none is found.
|
|
56
|
+
* caller.ts cleans it before it is sent. */
|
|
57
|
+
export function agentProgram(from = process.ppid, ps = systemPs) {
|
|
58
|
+
for (const pid of ancestry(from, ps)) {
|
|
59
|
+
const name = ps(pid, "comm")?.split("/").pop()?.replace(/^-/, "").toLowerCase();
|
|
60
|
+
if (name && !NOT_AN_AGENT.has(name))
|
|
61
|
+
return name;
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
50
65
|
/** Whether the session with this id is still running. */
|
|
51
66
|
export function isRunning(harness, id) {
|
|
52
67
|
// A shell's agent cannot be seen from here; the daemon goes by when it
|
package/dist/station.js
CHANGED
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
// same tools, so a command and the tool an agent would use answer alike.
|
|
5
5
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
6
6
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
7
|
+
import { fetchAsCaller } from "./caller.js";
|
|
7
8
|
import { VERSION } from "./self.js";
|
|
8
9
|
export const connectTo = async (credentials, timeoutMs) => {
|
|
9
10
|
const transport = new StreamableHTTPClientTransport(new URL(`${credentials.relayUrl}/mcp`), {
|
|
10
11
|
requestInit: { headers: { Authorization: `Bearer ${credentials.token}` } },
|
|
12
|
+
fetch: fetchAsCaller,
|
|
11
13
|
});
|
|
12
14
|
const client = new Client({ name: "station-cli", version: VERSION });
|
|
13
15
|
let timer;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@santori/station",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.7.0",
|
|
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",
|
|
7
7
|
"claude-code",
|