@santori/station 0.9.6 → 0.9.8
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 +5 -2
- package/dist/agentToken.js +26 -0
- package/dist/agents.js +137 -0
- package/dist/claude.js +14 -0
- package/dist/cli.js +185 -65
- package/dist/codex.js +76 -5
- package/dist/daemon.js +51 -14
- package/dist/frame.js +18 -6
- package/dist/handover.js +11 -7
- package/dist/home.js +7 -1
- package/dist/join.js +183 -59
- package/dist/limits.js +210 -0
- package/dist/login.js +19 -6
- package/dist/mcp.js +60 -9
- package/dist/proxy.js +5 -0
- package/dist/relay.js +49 -5
- package/dist/rooms.js +6 -5
- package/dist/seats.js +24 -4
- package/dist/self.js +41 -1
- package/dist/sessions.js +14 -5
- package/dist/signup.js +4 -2
- package/dist/starts.js +174 -0
- package/dist/usage.js +1 -1
- package/dist/waking.js +293 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ listen at the same time. Station cannot put messages into other agents'
|
|
|
9
9
|
sessions, so they read them with `station wait`. Every other command works
|
|
10
10
|
the same everywhere.
|
|
11
11
|
|
|
12
|
-
Needs Node
|
|
12
|
+
Needs Node 20 or later. On Node 20 the daemon reads the room every 30 seconds instead of holding a live link, so messages can take that long to arrive.
|
|
13
13
|
|
|
14
14
|
## An agent was sent a room
|
|
15
15
|
|
|
@@ -202,7 +202,8 @@ station seats | whoami | doctor
|
|
|
202
202
|
station login [--signup] [--no-browser] [--wait] [--remote] | login --code=<code> | logout
|
|
203
203
|
station rooms [--json] your rooms, your teams' rooms, the ones shared with you, and who is in each
|
|
204
204
|
station new [--title "<title>"] [--public] [--team <team>]
|
|
205
|
-
open a room
|
|
205
|
+
open a room (private unless --public; public when not signed in)
|
|
206
|
+
and print its link; take a seat in it with station join
|
|
206
207
|
station mcp serve these actions as tools (Model Context Protocol, stdio)
|
|
207
208
|
station webhook add <room> --url <https url> [--agent "<name>"] [--header-name Authorization]
|
|
208
209
|
[--on message,approval,asked] [--debounce 30] [--wakes-per-day 60]
|
|
@@ -222,6 +223,8 @@ session's tools, with `wait` for reading; its `as` argument is
|
|
|
222
223
|
|
|
223
224
|
Behind a proxy (`HTTPS_PROXY` or `HTTP_PROXY`), the CLI starts itself again
|
|
224
225
|
with `NODE_USE_ENV_PROXY=1`, which Node 22.21 and later need to use it.
|
|
226
|
+
Older Node cannot use a proxy from the environment; when a call fails
|
|
227
|
+
there, the CLI says so.
|
|
225
228
|
|
|
226
229
|
## How messages get in
|
|
227
230
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// An agent's own sign-in (decision A). A cloud agent keeps its install's
|
|
2
|
+
// secret as STATION_INSTALL_SECRET; Station trades it for an hour's
|
|
3
|
+
// sign-in as that agent (POST /installs/token) and keeps it in
|
|
4
|
+
// STATION_AGENT_TOKEN for this process. An agent the daemon started gets
|
|
5
|
+
// its sign-in only, in a file (STATION_AGENT_TOKEN_FILE). Either way the agent never holds its person's
|
|
6
|
+
// Station CLI token.
|
|
7
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
8
|
+
import { DEFAULT_RELAY } from "./home.js";
|
|
9
|
+
import { call } from "./relay.js";
|
|
10
|
+
/** Trades the install's secret when there is one and no sign-in yet, or the
|
|
11
|
+
* one there ran out. Changes nothing without a secret. */
|
|
12
|
+
export async function agentSignIn(env = process.env, now = Date.now()) {
|
|
13
|
+
if (env.STATION_AGENT_TOKEN_FILE && !env.STATION_AGENT_TOKEN && existsSync(env.STATION_AGENT_TOKEN_FILE))
|
|
14
|
+
env.STATION_AGENT_TOKEN = readFileSync(env.STATION_AGENT_TOKEN_FILE, "utf8").trim();
|
|
15
|
+
const secret = env.STATION_INSTALL_SECRET;
|
|
16
|
+
if (!secret)
|
|
17
|
+
return;
|
|
18
|
+
const until = Number(env.STATION_AGENT_TOKEN_UNTIL ?? 0);
|
|
19
|
+
if (env.STATION_AGENT_TOKEN && until - now > 60_000)
|
|
20
|
+
return;
|
|
21
|
+
const relay = (env.STATION_RELAY_URL || DEFAULT_RELAY).replace(/\/$/, "");
|
|
22
|
+
const signed = await call(relay, "/installs/token", null, { body: { secret } });
|
|
23
|
+
env.STATION_AGENT_TOKEN = signed.token;
|
|
24
|
+
env.STATION_AGENT_TOKEN_UNTIL = String(Date.parse(signed.expires_at));
|
|
25
|
+
env.STATION_AGENT_NAME = signed.agent.name;
|
|
26
|
+
}
|
package/dist/agents.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// The person's other agents on this computer. A join says when one is here
|
|
2
|
+
// without Station yet, and tells the agent to ask its person. On a yes,
|
|
3
|
+
// `station add codex` brings it in: the relay records the agent and this
|
|
4
|
+
// computer as one of its installs (POST /me/agents), the folder it was run
|
|
5
|
+
// in is where Station starts it for an ask, and Codex gets Station's tools
|
|
6
|
+
// for its own windows. On a no, `station add codex --no` keeps the no on
|
|
7
|
+
// the person, so none of their computers offers it again.
|
|
8
|
+
import { execFile } from "node:child_process";
|
|
9
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
10
|
+
import { homedir } from "node:os";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import { claudeHome } from "./claude.js";
|
|
13
|
+
import { codexHome } from "./codex.js";
|
|
14
|
+
import { call } from "./relay.js";
|
|
15
|
+
import { mcpCommand, onPath } from "./self.js";
|
|
16
|
+
import { saveFolder } from "./starts.js";
|
|
17
|
+
import { Usage } from "./usage.js";
|
|
18
|
+
export const LOCAL_AGENTS = [
|
|
19
|
+
{
|
|
20
|
+
kind: "codex",
|
|
21
|
+
name: "Codex",
|
|
22
|
+
program: "codex",
|
|
23
|
+
home: codexHome,
|
|
24
|
+
hasStation: (env) => {
|
|
25
|
+
const config = join(codexHome(env), "config.toml");
|
|
26
|
+
return existsSync(config) && /^\[mcp_servers\.(?:station|"station")\]/m.test(readFileSync(config, "utf8"));
|
|
27
|
+
},
|
|
28
|
+
addArgs: ([command, ...args], env) => ["mcp", "add", "station", ...Object.entries(env).flatMap(([name, value]) => ["--env", `${name}=${value}`]), "--", command, ...args],
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
kind: "claude-code",
|
|
32
|
+
name: "Claude Code",
|
|
33
|
+
program: "claude",
|
|
34
|
+
home: (env) => (env.CLAUDE_CONFIG_DIR ? claudeHome(env) : join(homedir(), ".claude")),
|
|
35
|
+
// Claude Code gets Station through its plugin or `claude mcp add`; Station leaves its settings alone.
|
|
36
|
+
hasStation: () => null,
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
const installed = (agent, env) => onPath(agent.program, env) !== null && existsSync(agent.home(env));
|
|
40
|
+
/** The person's agents and the kinds they said no to; null when not signed in or the relay cannot say. */
|
|
41
|
+
export async function myAgents(credentials) {
|
|
42
|
+
if (!credentials)
|
|
43
|
+
return null;
|
|
44
|
+
return call(credentials.relayUrl, "/me/agents", { token: credentials.token }).catch(() => null);
|
|
45
|
+
}
|
|
46
|
+
/** The person's agents a seat can ask by name, seated in the room or not:
|
|
47
|
+
* every one not cut off, except the seat's own. */
|
|
48
|
+
export function askable(mine, own) {
|
|
49
|
+
return (mine?.agents ?? []).filter((agent) => !agent.cut_off && agent.id !== own).map((agent) => agent.name);
|
|
50
|
+
}
|
|
51
|
+
/** `--to Codex`, or `--to "Claude Code"`. */
|
|
52
|
+
export function toFlag(name) {
|
|
53
|
+
return `--to ${name.includes(" ") ? `"${name}"` : name}`;
|
|
54
|
+
}
|
|
55
|
+
/** What a seat is told about the agents it can ask, or null with none. */
|
|
56
|
+
export function askLine(names, me) {
|
|
57
|
+
if (!names.length)
|
|
58
|
+
return null;
|
|
59
|
+
return `Your person's agents you can ask, seated here or not: ${names.join(", ")}. Ask with: ${me} say ${toFlag(names[0])} "<what to do>"`;
|
|
60
|
+
}
|
|
61
|
+
/** The agents to offer a session that joins a room: on this computer,
|
|
62
|
+
* with no install of theirs here, not said no to, and not the joining one's own kind. */
|
|
63
|
+
export function toOffer(mine, joining, env = process.env) {
|
|
64
|
+
const here = LOCAL_AGENTS.filter((agent) => agent.kind !== joining && installed(agent, env));
|
|
65
|
+
if (!here.length || !mine)
|
|
66
|
+
return [];
|
|
67
|
+
const hasInstall = (kind) => mine.agents.some((agent) => agent.kind === kind && agent.installs.some((install) => install.this_computer));
|
|
68
|
+
return here.filter((agent) => !mine.declined.includes(agent.kind) && !hasInstall(agent.kind));
|
|
69
|
+
}
|
|
70
|
+
/** One line for each: what Station found and the next move. */
|
|
71
|
+
export function offerLines(agents, me) {
|
|
72
|
+
return agents.map((agent) => {
|
|
73
|
+
const add = `${me} add ${agent.kind === "claude-code" ? "claude" : agent.kind}`;
|
|
74
|
+
return `${agent.name} is also on this computer. Ask your person if Station should start it for asks to it. If yes, run: ${add}. If no, run: ${add} --no, and Station will not ask again on any of their computers.`;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/** Station's own settings that `station mcp` in another agent needs to be this same Station. */
|
|
78
|
+
function stationEnv(env) {
|
|
79
|
+
return Object.fromEntries(["STATION_HOME", "STATION_RELAY_URL", "STATION_WEB_URL"].flatMap((name) => (env[name] ? [[name, env[name]]] : [])));
|
|
80
|
+
}
|
|
81
|
+
function run(program, args, env) {
|
|
82
|
+
return new Promise((resolve, reject) => execFile(program, args, { env, timeout: 30_000 }, (error, _stdout, stderr) => {
|
|
83
|
+
if (!error)
|
|
84
|
+
return resolve();
|
|
85
|
+
const line = String(stderr).split("\n").map((l) => l.trim()).find(Boolean) ?? error.message;
|
|
86
|
+
reject(new Error(`${program} ${args.slice(0, 2).join(" ")} did not work: ${line.slice(0, 300)}`));
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
export function localAgent(wanted) {
|
|
90
|
+
const key = wanted.trim().toLowerCase();
|
|
91
|
+
const agent = LOCAL_AGENTS.find((one) => one.kind === key || one.program === key || one.name.toLowerCase() === key);
|
|
92
|
+
if (!agent)
|
|
93
|
+
throw new Usage(`Station can bring in ${LOCAL_AGENTS.map((one) => one.program).join(" or ")} on this computer, or devin with --org and --key-env, not ${wanted}.`);
|
|
94
|
+
return agent;
|
|
95
|
+
}
|
|
96
|
+
/** `station add devin --org <org> --key-env <variable> [--max-acu <n>]`:
|
|
97
|
+
* the person's Devin, started through Devin's API with their own key. */
|
|
98
|
+
export async function addDevin(credentials, options, env = process.env) {
|
|
99
|
+
const usage = `${options.me} add devin --org <Devin organization id> --key-env <name of the variable holding the Devin API key> [--max-acu 3]`;
|
|
100
|
+
if (!options.org || !options.keyEnv)
|
|
101
|
+
throw new Usage(usage);
|
|
102
|
+
const key = env[options.keyEnv];
|
|
103
|
+
if (!key)
|
|
104
|
+
throw new Usage(`Set ${options.keyEnv} to a Devin API key first. Station never takes the key on the command line. ${usage}`);
|
|
105
|
+
const max = options.maxAcu === undefined ? 3 : Number(options.maxAcu);
|
|
106
|
+
const added = await call(credentials.relayUrl, "/me/agents", { token: credentials.token }, { body: { kind: "devin", devin: { org: options.org, key, max_acu_limit: max } } });
|
|
107
|
+
return [
|
|
108
|
+
`Devin is your person's agent in Station now. When an ask comes for it and no Devin session is listening, Station starts one in ${options.org} with that key, spending at most ${max} ACUs, or messages the session it started last.`,
|
|
109
|
+
"Each session Station starts signs in as Devin for an hour, never as your person. For a session that should keep working past that, save this install secret in Devin as the secret STATION_INSTALL_SECRET. It is shown once:",
|
|
110
|
+
added.secret,
|
|
111
|
+
`To ask it in a room, run: ${options.me} say --to Devin "<what to do>"`,
|
|
112
|
+
];
|
|
113
|
+
}
|
|
114
|
+
/** `station add <agent> [--no]`. */
|
|
115
|
+
export async function addAgent(home, credentials, wanted, options, env = process.env) {
|
|
116
|
+
const agent = localAgent(wanted);
|
|
117
|
+
const word = agent.program;
|
|
118
|
+
if (options.no) {
|
|
119
|
+
await call(credentials.relayUrl, "/me/agents", { token: credentials.token }, { body: { kind: agent.kind, no: true } });
|
|
120
|
+
return [`Station will not offer ${agent.name} again on any of your person's computers. If they change their mind, run: ${options.me} add ${word}.`];
|
|
121
|
+
}
|
|
122
|
+
const program = onPath(agent.program, env);
|
|
123
|
+
if (!program)
|
|
124
|
+
throw new Usage(`${agent.name} is not on this computer: no ${agent.program} program on PATH. Once your person installs it, run: ${options.me} add ${word}.`);
|
|
125
|
+
if (!existsSync(agent.home(env)))
|
|
126
|
+
throw new Usage(`${agent.name} is installed but has never run here (no ${agent.home(env)}). Ask your person to open it once and sign in, then run: ${options.me} add ${word}.`);
|
|
127
|
+
const added = await call(credentials.relayUrl, "/me/agents", { token: credentials.token }, { body: { kind: agent.kind } });
|
|
128
|
+
saveFolder(home, added.agent.id, options.cwd);
|
|
129
|
+
const lines = [];
|
|
130
|
+
const has = agent.hasStation(env);
|
|
131
|
+
if (has === false && agent.addArgs) {
|
|
132
|
+
await run(program, agent.addArgs(mcpCommand(), stationEnv(env)), env);
|
|
133
|
+
lines.push(`${agent.name}'s own windows now have Station's tools, through this computer's Station.`);
|
|
134
|
+
}
|
|
135
|
+
lines.push(`${agent.name} is your person's agent in Station now, in all their rooms, and runs on this computer. An ask for it, from any room, goes into its last chat here when that chat is open, and continues that chat in the background when it is closed. With no chat here yet, Station starts ${agent.name} in ${options.cwd}.`, `To ask it in a room, run: ${options.me} say ${toFlag(agent.name)} "<what to do>"`);
|
|
136
|
+
return lines;
|
|
137
|
+
}
|
package/dist/claude.js
CHANGED
|
@@ -53,6 +53,19 @@ const isTicks = (start) => start !== null && /^\d+$/.test(start.trim());
|
|
|
53
53
|
export function claudeHome(env = process.env) {
|
|
54
54
|
return env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude");
|
|
55
55
|
}
|
|
56
|
+
/** A session's transcript, `projects/<folder>/<id>.jsonl`, found by its id
|
|
57
|
+
* so it does not depend on how Claude Code names the folder. */
|
|
58
|
+
export function transcriptPath(home, sessionId) {
|
|
59
|
+
const root = join(home, "projects");
|
|
60
|
+
if (!existsSync(root))
|
|
61
|
+
return null;
|
|
62
|
+
for (const folder of readdirSync(root)) {
|
|
63
|
+
const path = join(root, folder, `${sessionId}.jsonl`);
|
|
64
|
+
if (existsSync(path))
|
|
65
|
+
return path;
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
56
69
|
function registry(home) {
|
|
57
70
|
return join(home, "sessions");
|
|
58
71
|
}
|
|
@@ -83,6 +96,7 @@ export function readSession(home, pid) {
|
|
|
83
96
|
cwd: text("cwd") ?? "",
|
|
84
97
|
name: text("name"),
|
|
85
98
|
status: text("status"),
|
|
99
|
+
entrypoint: text("entrypoint"),
|
|
86
100
|
};
|
|
87
101
|
}
|
|
88
102
|
/** The live session `pid` runs: registered, and the registry's start time
|