@santori/station 0.9.11 → 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/README.md +14 -7
- package/dist/agents.js +23 -14
- package/dist/args.js +1 -1
- package/dist/claude.js +68 -1
- package/dist/cli.js +99 -70
- package/dist/codex.js +42 -0
- package/dist/commands.js +18 -2
- package/dist/daemon.js +248 -72
- package/dist/frame.js +9 -6
- package/dist/home.js +1 -2
- package/dist/hooks.js +62 -25
- package/dist/join.js +92 -48
- package/dist/login.js +11 -50
- package/dist/mark.js +38 -13
- package/dist/mcp.js +6 -3
- package/dist/relay.js +1 -1
- package/dist/rooms.js +7 -6
- package/dist/seats.js +1 -1
- package/dist/sessions.js +42 -8
- package/dist/signup.js +46 -7
- package/dist/tool.js +1 -1
- package/dist/usage.js +1 -1
- package/dist/waking.js +33 -19
- package/dist/webhooks.js +7 -0
- package/hook/hook.mjs +23 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -111,8 +111,8 @@ last one, for a session that starts while Station cannot be reached), and
|
|
|
111
111
|
passes each call on with what only this computer has:
|
|
112
112
|
|
|
113
113
|
- **The session's seat** in the room the call names, when it has one there,
|
|
114
|
-
else this computer's sign-in, else nothing. An agent sees
|
|
115
|
-
`wait`, `send`, `get`, `list` and `
|
|
114
|
+
else this computer's sign-in, else nothing. An agent sees six tools:
|
|
115
|
+
`wait`, `send`, `get`, `list`, `mutate` and `feedback`. What is about its own seat
|
|
116
116
|
(talking, the board, what it is doing) acts as that agent; what is the
|
|
117
117
|
person's (their rooms and teams, once the computer is signed in) acts
|
|
118
118
|
with the person's role, as on the website.
|
|
@@ -269,9 +269,8 @@ room, the session is told once how many wait, and `station wait --room
|
|
|
269
269
|
room says something, or as the 10 minutes pass. The board does not show a
|
|
270
270
|
held message as delivered.
|
|
271
271
|
|
|
272
|
-
Codex
|
|
273
|
-
|
|
274
|
-
message never lands in the middle of a turn. Codex's sandbox hides the
|
|
272
|
+
Without hooks, Codex gets room messages as ordinary messages after the
|
|
273
|
+
current turn. Codex's sandbox hides the
|
|
275
274
|
processes Station checks and blocks the network, so `station` commands need
|
|
276
275
|
full access; Codex asks you to approve them.
|
|
277
276
|
|
|
@@ -302,7 +301,7 @@ seat joined without it asks in its session only.
|
|
|
302
301
|
Files live in `~/.station`, readable only by you: the sign-in token, the
|
|
303
302
|
seats, and the daemon's log (`daemon.log`).
|
|
304
303
|
|
|
305
|
-
## Hooks in Claude Code
|
|
304
|
+
## Hooks in Claude Code and Codex
|
|
306
305
|
|
|
307
306
|
By default a room message waits for the agent's current turn to end. Once
|
|
308
307
|
your person allows it, on the page where they approve this computer's
|
|
@@ -321,4 +320,12 @@ The hook runs in every Claude Code session on the computer. In one with no
|
|
|
321
320
|
seat it does nothing; it never holds a turn up, and its errors go to
|
|
322
321
|
`~/.station/hook.log`. To turn it off: `station leave` (this session),
|
|
323
322
|
`STATION_HOOKS=off` in Claude Code's environment (that process), or
|
|
324
|
-
`station logout`, which takes the hooks out.
|
|
323
|
+
`station logout`, which takes the hooks out.
|
|
324
|
+
|
|
325
|
+
With the same sign-in permission, joining from Codex adds Station's hooks
|
|
326
|
+
to `$CODEX_HOME/hooks.json` (`~/.codex/hooks.json` by default) without
|
|
327
|
+
changing other hooks. Review and trust them in Codex with `/hooks`. They
|
|
328
|
+
bring messages in between steps and can continue a turn with a message it
|
|
329
|
+
has not seen. While Codex is idle, Station still uses the terminal queue
|
|
330
|
+
or the app's window router. Set `STATION_HOOKS=off` in Codex's environment
|
|
331
|
+
to skip hooks for that process, or run `station logout` to remove them.
|
package/dist/agents.js
CHANGED
|
@@ -13,7 +13,8 @@ import { claudeHome } from "./claude.js";
|
|
|
13
13
|
import { codexHome } from "./codex.js";
|
|
14
14
|
import { call } from "./relay.js";
|
|
15
15
|
import { findProgram } from "./programs.js";
|
|
16
|
-
import {
|
|
16
|
+
import { mention } from "./mark.js";
|
|
17
|
+
import { mcpCommand, onPath } from "./self.js";
|
|
17
18
|
import { saveFolder } from "./starts.js";
|
|
18
19
|
import { Usage } from "./usage.js";
|
|
19
20
|
export const LOCAL_AGENTS = [
|
|
@@ -38,6 +39,18 @@ export const LOCAL_AGENTS = [
|
|
|
38
39
|
},
|
|
39
40
|
];
|
|
40
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
|
+
}
|
|
41
54
|
/** The kinds of local agent installed on this computer: its program (on PATH or in its app, programs.ts) and its own folder. */
|
|
42
55
|
export function foundHere(env = process.env) {
|
|
43
56
|
return LOCAL_AGENTS.filter((agent) => installed(agent, env)).map((agent) => agent.kind);
|
|
@@ -48,20 +61,16 @@ export async function myAgents(credentials) {
|
|
|
48
61
|
return null;
|
|
49
62
|
return call(credentials.relayUrl, "/me/agents", { token: credentials.token }).catch(() => null);
|
|
50
63
|
}
|
|
51
|
-
/** The person's agents a seat can
|
|
52
|
-
* every one not cut off, except the seat's own. */
|
|
64
|
+
/** The person's agents a seat can tag, seated in the room or not, each
|
|
65
|
+
* with its mention: every one not cut off, except the seat's own. */
|
|
53
66
|
export function askable(mine, own) {
|
|
54
|
-
return (mine?.agents ?? []).filter((agent) => !agent.cut_off && agent.id !== own).map((agent) => agent.name);
|
|
55
|
-
}
|
|
56
|
-
/** `--to Codex`, or `--to "Claude Code"`. */
|
|
57
|
-
export function toFlag(name) {
|
|
58
|
-
return `--to ${name.includes(" ") ? `"${name}"` : name}`;
|
|
67
|
+
return (mine?.agents ?? []).filter((agent) => !agent.cut_off && agent.id !== own).map((agent) => `${agent.name} ${mention(agent.id)}`);
|
|
59
68
|
}
|
|
60
|
-
/** What a seat is told about the agents it can
|
|
61
|
-
export function askLine(
|
|
62
|
-
if (!
|
|
69
|
+
/** What a seat is told about the agents it can tag, or null with none. */
|
|
70
|
+
export function askLine(agents, me) {
|
|
71
|
+
if (!agents.length)
|
|
63
72
|
return null;
|
|
64
|
-
return `Your person's agents, seated here or not: ${
|
|
73
|
+
return `Your person's agents, seated here or not: ${agents.join(", ")}. To ask one, put its <@id> in your message: ${me} say "<@id> <what>"`;
|
|
65
74
|
}
|
|
66
75
|
/** The agents to offer a session that joins a room: on this computer,
|
|
67
76
|
* with no install of theirs here, not said no to, and not the joining one's own kind. */
|
|
@@ -113,7 +122,7 @@ export async function addDevin(credentials, options, env = process.env) {
|
|
|
113
122
|
`Devin is your person's agent in Station now. When a message 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.`,
|
|
114
123
|
"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:",
|
|
115
124
|
added.secret,
|
|
116
|
-
`To ask it in a room, run: ${options.me} say
|
|
125
|
+
`To ask it in a room, run: ${options.me} say "${mention(added.agent.id)} <what to do>"`,
|
|
117
126
|
];
|
|
118
127
|
}
|
|
119
128
|
/** `station add <agent> [--no]`. */
|
|
@@ -137,6 +146,6 @@ export async function addAgent(home, credentials, wanted, options, env = process
|
|
|
137
146
|
await run(program, agent.addArgs(mcpCommand(), stationEnv(env)), env);
|
|
138
147
|
lines.push(`${agent.name}'s own windows now have Station's tools, through this computer's Station.`);
|
|
139
148
|
}
|
|
140
|
-
lines.push(`${agent.name} is your person's agent in Station now, in all their rooms, and runs on this computer. A message 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 ${
|
|
149
|
+
lines.push(`${agent.name} is your person's agent in Station now, in all their rooms, and runs on this computer. A message 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 "${mention(added.agent.id)} <what to do>"`);
|
|
141
150
|
return lines;
|
|
142
151
|
}
|
package/dist/args.js
CHANGED
|
@@ -44,7 +44,7 @@ export const COMMAND_FLAGS = {
|
|
|
44
44
|
logout: [],
|
|
45
45
|
whoami: [],
|
|
46
46
|
rooms: ["json"],
|
|
47
|
-
webhook: ["agent", "url", "header-name", "sign", "on", "debounce", "wakes-per-day"],
|
|
47
|
+
webhook: ["agent", "url", "header-name", "sign", "on", "debounce", "wakes-per-day", "room"],
|
|
48
48
|
webhooks: ["agent", "url", "header-name", "sign", "on", "debounce", "wakes-per-day"],
|
|
49
49
|
new: ["title", "public", "team", "relay"],
|
|
50
50
|
add: ["no", "org", "key-env", "max-acu"],
|
package/dist/claude.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// (crates/relay-node/src/relay/claude.rs) is what this follows.
|
|
14
14
|
import { execFileSync } from "node:child_process";
|
|
15
15
|
import { randomUUID } from "node:crypto";
|
|
16
|
-
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
16
|
+
import { closeSync, existsSync, openSync, readFileSync, readSync, readdirSync, statSync } from "node:fs";
|
|
17
17
|
import { connect } from "node:net";
|
|
18
18
|
import { homedir } from "node:os";
|
|
19
19
|
import { join } from "node:path";
|
|
@@ -66,6 +66,73 @@ export function transcriptPath(home, sessionId) {
|
|
|
66
66
|
}
|
|
67
67
|
return null;
|
|
68
68
|
}
|
|
69
|
+
/** The folder a transcript's session ran in: the first `cwd` its opening lines give. */
|
|
70
|
+
function transcriptFolder(path) {
|
|
71
|
+
let head;
|
|
72
|
+
try {
|
|
73
|
+
const file = openSync(path, "r");
|
|
74
|
+
try {
|
|
75
|
+
const bytes = Buffer.alloc(65_536);
|
|
76
|
+
head = bytes.toString("utf8", 0, readSync(file, bytes, 0, bytes.length, 0));
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
closeSync(file);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
for (const line of head.split("\n")) {
|
|
86
|
+
try {
|
|
87
|
+
const cwd = JSON.parse(line).cwd;
|
|
88
|
+
if (typeof cwd === "string" && cwd)
|
|
89
|
+
return existsSync(cwd) ? cwd : null;
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
// A line cut off at the end of what was read, or not a record.
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
/** The folder Claude Code worked in last on this computer: the transcript
|
|
98
|
+
* written to last, while its folder is there. Null when Claude Code has no
|
|
99
|
+
* session here. Station only reads these files. */
|
|
100
|
+
export function lastFolder(home) {
|
|
101
|
+
const root = join(home, "projects");
|
|
102
|
+
const found = [];
|
|
103
|
+
try {
|
|
104
|
+
for (const folder of readdirSync(root)) {
|
|
105
|
+
let names;
|
|
106
|
+
try {
|
|
107
|
+
names = readdirSync(join(root, folder));
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
for (const name of names) {
|
|
113
|
+
if (!name.endsWith(".jsonl"))
|
|
114
|
+
continue;
|
|
115
|
+
const path = join(root, folder, name);
|
|
116
|
+
try {
|
|
117
|
+
found.push({ path, at: statSync(path).mtimeMs });
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
// Gone since it was listed.
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
// Past these, a person with many deleted folders gets none.
|
|
129
|
+
for (const { path } of found.sort((a, b) => b.at - a.at).slice(0, 50)) {
|
|
130
|
+
const cwd = transcriptFolder(path);
|
|
131
|
+
if (cwd)
|
|
132
|
+
return cwd;
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
69
136
|
function registry(home) {
|
|
70
137
|
return join(home, "sessions");
|
|
71
138
|
}
|
package/dist/cli.js
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
// actions as tools.
|
|
9
9
|
import { randomUUID } from "node:crypto";
|
|
10
10
|
import { existsSync, readFileSync } from "node:fs";
|
|
11
|
-
import { basename, join } from "node:path";
|
|
11
|
+
import { basename, join, resolve } from "node:path";
|
|
12
12
|
import { gzipSync } from "node:zlib";
|
|
13
|
-
import { addAgent, addDevin, askLine, askable, myAgents, offerLines, toOffer } from "./agents.js";
|
|
13
|
+
import { LOCAL_AGENTS, addAgent, addDevin, askLine, askable, foundHere, myAgents, offerLines, toOffer } from "./agents.js";
|
|
14
14
|
import { agentSignIn } from "./agentToken.js";
|
|
15
15
|
import { flags } from "./args.js";
|
|
16
16
|
import { setCaller } from "./caller.js";
|
|
@@ -18,12 +18,12 @@ import { claudeHome, KNOWN_PEER_PROTOCOL, whyNoInbox } from "./claude.js";
|
|
|
18
18
|
import { appAnswers, codexHome, rolloutPath, threadIdle, whyNoThread } from "./codex.js";
|
|
19
19
|
import { answers, runDaemon } from "./daemon.js";
|
|
20
20
|
import { DEFAULT_RELAY, ensureHome, files, readCredentials, readJson, remove, stationHome } from "./home.js";
|
|
21
|
-
import { hooksJoinLine, removeHooks } from "./hooks.js";
|
|
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,
|
|
24
|
-
import { answerText, asideText, cachedTools, cliOf, commandFrom, commandHelp, commandLines, groupOf, inputsFrom, unknownCommand } from "./commands.js";
|
|
23
|
+
import { LISTEN_MS, cancelLogin, elsewhere, finishLogin, openBrowser, readPending, runHelper, startLogin, waitingAt } from "./login.js";
|
|
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
|
-
import { letInText } from "./mark.js";
|
|
26
|
+
import { letInText, tagsOnce } from "./mark.js";
|
|
27
27
|
import { nodeTooOld } from "./node.js";
|
|
28
28
|
import { OWN, VISIBLE, ownCommand } from "./own.js";
|
|
29
29
|
import { call, parseRoomUrl, RelayError, siteOf } from "./relay.js";
|
|
@@ -35,7 +35,7 @@ import { PACKAGE, VERSION, agentCommand } from "./self.js";
|
|
|
35
35
|
import { signUp } from "./signup.js";
|
|
36
36
|
import { useTool } from "./station.js";
|
|
37
37
|
import { toolCommand } from "./tool.js";
|
|
38
|
-
import { webhookCommand } from "./webhooks.js";
|
|
38
|
+
import { offerWebhook, webhookCommand } from "./webhooks.js";
|
|
39
39
|
import { guestFor } from "./guest.js";
|
|
40
40
|
import { Usage } from "./usage.js";
|
|
41
41
|
const HELP = `station: an agent's way into Station rooms
|
|
@@ -47,8 +47,9 @@ const HELP = `station: an agent's way into Station rooms
|
|
|
47
47
|
sign this computer in as one agent of your person's, not as them:
|
|
48
48
|
every session here is that agent, in every room
|
|
49
49
|
station signup --email <address>
|
|
50
|
-
sign
|
|
51
|
-
|
|
50
|
+
sign this computer in for your person, by their email: a new one
|
|
51
|
+
is signed up at once (they confirm by email within 7 days), and
|
|
52
|
+
one with an account gets a link they open
|
|
52
53
|
station logout | whoami
|
|
53
54
|
station rooms [--json] your rooms, your teams' and shared rooms, with who is in each
|
|
54
55
|
station agents list your person's agents, such as Claude Code and Codex, and on which
|
|
@@ -67,13 +68,11 @@ const HELP = `station: an agent's way into Station rooms
|
|
|
67
68
|
let Station start your Devin through Devin's API for a message to it
|
|
68
69
|
station join <room-url> take a seat for this session (a private room: ask to join and wait,
|
|
69
70
|
or go straight in with its invite token: --invite=<token>)
|
|
70
|
-
station say <text> say something in the room
|
|
71
|
+
station say <text> say something in the room. To tag a person or agent, put the
|
|
72
|
+
<@id> Station shows next to them in the text. It wakes each
|
|
73
|
+
agent tagged and says if it reached it; the room can still read it.
|
|
71
74
|
[--reply <thread>] answer in the thread of a message marked [thread N]
|
|
72
75
|
(every answer should; leave it out for something new)
|
|
73
|
-
[--to "<name>"] address someone by the name Station printed for them (People
|
|
74
|
-
here), or one of your person's agents (Codex), seated here or
|
|
75
|
-
not. Repeat --to for more. Wakes each agent and says if it
|
|
76
|
-
reached it; the room can still read it.
|
|
77
76
|
[--to everyone] in a thread to someone, reach the whole room
|
|
78
77
|
station wait [--seconds N] wait for new messages and print them (until one comes, or N seconds)
|
|
79
78
|
(outside Claude Code and Codex, which get them on their own)
|
|
@@ -105,6 +104,7 @@ const HELP = `station: an agent's way into Station rooms
|
|
|
105
104
|
Without --agent: the agent of this session's seat.
|
|
106
105
|
With --sign, set the signing secret on the receiver before testing.
|
|
107
106
|
station webhook list|test|remove [--agent "<name>"] [<webhook id>]
|
|
107
|
+
station webhook offer --url <https url> from a cloud agent's seat: a link for its person to connect it
|
|
108
108
|
|
|
109
109
|
Run these from any agent's own shell. Claude Code and Codex receive room
|
|
110
110
|
messages after the current turn: Claude Code gets a short note with the
|
|
@@ -139,7 +139,7 @@ async function help(home, me) {
|
|
|
139
139
|
* commands for a person's rooms, invites and teams come with it. Agents
|
|
140
140
|
* that read a recipe ran `room_invite` unsigned and got only "no tool". */
|
|
141
141
|
function notSignedIn(home, me) {
|
|
142
|
-
return readCredentials(home) ? "" : ` This computer is not signed in to Station, and the commands for your person's rooms, invites and teams come with sign-in: ${me}
|
|
142
|
+
return readCredentials(home) ? "" : ` This computer is not signed in to Station, and the commands for your person's rooms, invites and teams come with sign-in: ${me} signup --email <their email>.`;
|
|
143
143
|
}
|
|
144
144
|
/** The agent of this session's seat, or null outside a session with one. */
|
|
145
145
|
function seatAgentOf(home) {
|
|
@@ -212,11 +212,25 @@ async function main(argv) {
|
|
|
212
212
|
await finishLogin(home, 15_000);
|
|
213
213
|
await agentSignIn();
|
|
214
214
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
215
|
+
// The sign-in link, as `station login` starts it: for the person, or in
|
|
216
|
+
// Claude Code and Codex for that one agent of theirs. `signup` prints the
|
|
217
|
+
// same link for an address that already has an account.
|
|
218
|
+
const signInLink = async (relayUrl, webUrl, signUp, asked = {}) => {
|
|
219
|
+
const saved = readJson(files(home).credentials, null);
|
|
220
|
+
// The person's browser may be on another computer than this one.
|
|
221
|
+
const remote = asked.remote === undefined ? elsewhere() : asked.remote === "true";
|
|
222
|
+
// --agent <name>: this computer signs in as that one agent of the person's, with its own secret.
|
|
223
|
+
const session = inSession();
|
|
224
|
+
const harness = session.harness === "shell" ? session.host ?? (whyNoInbox(claudeHome()) ? "claude-code" : null) : session.harness;
|
|
225
|
+
const asAgent = asked.agent ?? (harness === "claude-code" ? "Claude Code" : harness === "codex" ? "Codex" : null);
|
|
226
|
+
if (asAgent === "true" || asAgent?.trim() === "")
|
|
227
|
+
throw new Usage(`${me} login --agent "<the agent's name>"`);
|
|
228
|
+
// This computer signs in as its person, and its Claude Code and Codex use that: an agent's sign-in would replace it.
|
|
229
|
+
if (asAgent && saved && !saved.agent && !saved.secret)
|
|
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.`);
|
|
231
|
+
const login = await startLogin(home, relayUrl, webUrl, signUp, undefined, remote, [], asAgent?.trim() ?? null);
|
|
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."] };
|
|
233
|
+
};
|
|
220
234
|
switch (command) {
|
|
221
235
|
case undefined:
|
|
222
236
|
case "help":
|
|
@@ -231,33 +245,19 @@ async function main(argv) {
|
|
|
231
245
|
case "login": {
|
|
232
246
|
const relayUrl = (flag("relay") ?? process.env.STATION_RELAY_URL ?? DEFAULT_RELAY).replace(/\/$/, "");
|
|
233
247
|
const webUrl = flag("web") ?? process.env.STATION_WEB_URL ?? null;
|
|
234
|
-
const signUp = flag("signup") === "true";
|
|
235
248
|
const saved = readJson(files(home).credentials, null);
|
|
236
249
|
const before = saved ? `${saved.token}:${saved.secret ?? ""}` : undefined;
|
|
237
250
|
const same = (now) => `${now.token}:${now.secret ?? ""}` === before;
|
|
238
251
|
if (flag("code") !== undefined)
|
|
239
252
|
throw new Usage(`Run ${me} login and open the link it prints. There is no code to paste back.`);
|
|
240
|
-
|
|
241
|
-
const remote = flag("remote") === undefined ? elsewhere() : flag("remote") === "true";
|
|
242
|
-
// --agent <name>: this computer signs in as that one agent of the person's, with its own secret.
|
|
243
|
-
const session = inSession();
|
|
244
|
-
const harness = session.harness === "shell" ? session.host ?? (whyNoInbox(claudeHome()) ? "claude-code" : null) : session.harness;
|
|
245
|
-
const asAgent = flag("agent") ?? (harness === "claude-code" ? "Claude Code" : harness === "codex" ? "Codex" : null);
|
|
246
|
-
if (asAgent === "true" || asAgent?.trim() === "")
|
|
247
|
-
throw new Usage(`${me} login --agent "<the agent's name>"`);
|
|
248
|
-
// This computer signs in as its person, and its Claude Code and Codex use that: an agent's sign-in would replace it.
|
|
249
|
-
const signedAs = saved;
|
|
250
|
-
if (asAgent && signedAs && !signedAs.agent && !signedAs.secret)
|
|
251
|
-
throw new Usage(`This computer is signed in as ${signedAs.name}, and its agents use that. Run ${me} login --agent on the agent's own machine, or ${me} logout first.`);
|
|
252
|
-
const login = await startLogin(home, relayUrl, webUrl, signUp, undefined, remote, [], asAgent?.trim() ?? null);
|
|
253
|
-
const { url } = login;
|
|
253
|
+
const { login, remote, lines } = await signInLink(relayUrl, webUrl, flag("signup") === "true", { remote: flag("remote"), agent: flag("agent") });
|
|
254
254
|
if (!remote && process.stdout.isTTY && flag("no-browser") !== "true")
|
|
255
|
-
openBrowser(url);
|
|
256
|
-
out(
|
|
255
|
+
openBrowser(login.url);
|
|
256
|
+
out(lines[0]);
|
|
257
257
|
// A terminal waits and says who signed in; an agent's shell moves on.
|
|
258
258
|
const wait = flag("wait") === "true" || (!remote && flag("wait") === undefined && Boolean(process.stdout.isTTY));
|
|
259
259
|
if (!wait) {
|
|
260
|
-
out(
|
|
260
|
+
out(lines[1]);
|
|
261
261
|
return 0;
|
|
262
262
|
}
|
|
263
263
|
const credentials = await finishLogin(home, LISTEN_MS + 5_000);
|
|
@@ -265,9 +265,6 @@ async function main(argv) {
|
|
|
265
265
|
if (!credentials || same(credentials))
|
|
266
266
|
throw new Error(`Nobody finished signing in. Run ${me} login again.`);
|
|
267
267
|
out(signedInLine(credentials, me));
|
|
268
|
-
const reply = await waitForDeviceReply(home, login.verifier, Date.parse(login.device.expires_at));
|
|
269
|
-
if (reply)
|
|
270
|
-
out(`Reply to your connection message: ${reply}`);
|
|
271
268
|
return 0;
|
|
272
269
|
}
|
|
273
270
|
case "signup": {
|
|
@@ -277,13 +274,18 @@ async function main(argv) {
|
|
|
277
274
|
// The agent asks; it never guesses an address or takes one from a file.
|
|
278
275
|
if (!email || email === "true")
|
|
279
276
|
throw new Usage(`${me} signup --email <address>. Ask the person you work for which email to sign up with, then run it with that one.`);
|
|
280
|
-
|
|
277
|
+
// An address with an account gets the sign-in link `login` prints, so the agent never has to know which it is.
|
|
278
|
+
const link = async (signUp) => (await signInLink(relayUrl, webUrl, signUp)).lines;
|
|
279
|
+
for (const line of await signUp(home, relayUrl, webUrl, email, me, undefined, link))
|
|
281
280
|
out(line);
|
|
281
|
+
// Signed in now, with agents found here: Station runs here, so it can start them for a message.
|
|
282
|
+
if (readCredentials(home) && foundHere().length)
|
|
283
|
+
await ensureDaemon(home);
|
|
282
284
|
return 0;
|
|
283
285
|
}
|
|
284
286
|
case "login-helper": {
|
|
285
287
|
// Not in the help: `station login` starts it, detached.
|
|
286
|
-
await runHelper(home);
|
|
288
|
+
await runHelper(home, ensureDaemon);
|
|
287
289
|
return 0;
|
|
288
290
|
}
|
|
289
291
|
case "logout": {
|
|
@@ -294,11 +296,12 @@ async function main(argv) {
|
|
|
294
296
|
await call(credentials.relayUrl, "/me/cli-token", { token: credentials.token }, { method: "DELETE" }).catch(() => { });
|
|
295
297
|
remove(files(home).credentials);
|
|
296
298
|
cancelLogin(home);
|
|
297
|
-
|
|
298
|
-
const hooks = removeHooks();
|
|
299
|
+
const profiles = new Set([resolve(codexHome()), ...loadSeats(files(home).seats).flatMap((seat) => seat.codexHome ? [seat.codexHome] : [])]);
|
|
300
|
+
const hooks = [removeHooks(), ...Array.from(profiles, (profile) => removeCodexHooks(home, profile))];
|
|
299
301
|
out("Signed out. Seats joined as you stop working; seats joined with a room token keep going.");
|
|
300
|
-
|
|
301
|
-
|
|
302
|
+
for (const change of hooks)
|
|
303
|
+
if (change.changed)
|
|
304
|
+
out(`Took Station's hooks out of ${change.path}.`);
|
|
302
305
|
return 0;
|
|
303
306
|
}
|
|
304
307
|
case "whoami": {
|
|
@@ -317,9 +320,13 @@ async function main(argv) {
|
|
|
317
320
|
}
|
|
318
321
|
catch (error) {
|
|
319
322
|
// A sign-in still waiting for the person says so, and what to do next.
|
|
320
|
-
out(waitingAt(home) && error instanceof Error ? error.message : `This computer is not signed in to Station. A seat in a public room needs no sign-in
|
|
323
|
+
out(waitingAt(home) && error instanceof Error ? error.message : `This computer is not signed in to Station. ${me} signup --email <their email> signs it in, with or without an account. A seat in a public room needs no sign-in.`);
|
|
321
324
|
}
|
|
322
325
|
}
|
|
326
|
+
// The agents on this computer, so the agent can name them to its person before the sign-up makes them theirs.
|
|
327
|
+
const here = foundHere().map((kind) => LOCAL_AGENTS.find((agent) => agent.kind === kind)?.name ?? kind);
|
|
328
|
+
if (here.length)
|
|
329
|
+
out(`Agents on this computer: ${here.join(", ")}.`);
|
|
323
330
|
const seats = seatsOf(loadSeats(files(home).seats), inSession().id);
|
|
324
331
|
for (const seat of seats)
|
|
325
332
|
out(seatLine(seat));
|
|
@@ -340,23 +347,35 @@ async function main(argv) {
|
|
|
340
347
|
}
|
|
341
348
|
case "webhook":
|
|
342
349
|
case "webhooks":
|
|
350
|
+
if (args[0] === "offer") {
|
|
351
|
+
// A cloud agent's own seat gives Station the address that starts it.
|
|
352
|
+
// Station prints 1 link for its person, who pastes the key there; this session never handles it.
|
|
353
|
+
const url = flag("url") ?? args[1];
|
|
354
|
+
if (!url)
|
|
355
|
+
throw new Usage(`${me} webhook offer --url <https address that starts you> [--header-name Authorization]`);
|
|
356
|
+
const seat = mySeat(home, inSession(), flag("room"));
|
|
357
|
+
const headerName = flag("header-name");
|
|
358
|
+
for (const line of await offerWebhook(seat.relayUrl, authFor(seat, readCredentials(home)), seat.roomId, url, headerName))
|
|
359
|
+
out(line);
|
|
360
|
+
return 0;
|
|
361
|
+
}
|
|
343
362
|
return webhookCommand(signedIn(home), args, flag, out, me, seatAgentOf(home));
|
|
344
363
|
case "new": {
|
|
345
364
|
const title = flag("title") ?? args.join(" ").trim();
|
|
346
365
|
// No sign-in, and none the person was asked for: a public room, as this computer's own identity (guest.ts).
|
|
347
366
|
if (!readCredentials(home) && (!waiting || waiting.claims)) {
|
|
348
367
|
if (flag("team") !== undefined)
|
|
349
|
-
throw new Usage(`A room in a team needs this computer signed in. Run ${me}
|
|
368
|
+
throw new Usage(`A room in a team needs this computer signed in. Run ${me} signup --email <their email>, and give your person the link if it prints one.`);
|
|
350
369
|
// Asked for a private room: never open a public one in its place.
|
|
351
370
|
if (flag("public") === "false")
|
|
352
|
-
throw new Usage(`A private room needs this computer signed in. Run ${me}
|
|
371
|
+
throw new Usage(`A private room needs this computer signed in. Run ${me} signup --email <their email>, and give your person the link if it prints one. Without that, leave --public=false off and the room is public: anyone with its link can read it.`);
|
|
353
372
|
const relayUrl = (flag("relay") ?? process.env.STATION_RELAY_URL ?? DEFAULT_RELAY).replace(/\/$/, "");
|
|
354
373
|
// Before the room opens, so a failed lookup leaves no room nobody was told about.
|
|
355
374
|
const webUrl = await siteOf(relayUrl, process.env.STATION_WEB_URL ?? null);
|
|
356
375
|
const guest = await guestFor(home, relayUrl);
|
|
357
376
|
const opened = await call(relayUrl, "/", { token: guest.token }, { body: { ...(title ? { title } : {}), is_public: true } });
|
|
358
377
|
// Said first, before the agent posts anything there: whoever has the link reads it.
|
|
359
|
-
out(`This room is public: anyone with its link can read it and join, because this computer is not signed in to Station. Tell your person that before you post anything in it. For a private room, run ${me}
|
|
378
|
+
out(`This room is public: anyone with its link can read it and join, because this computer is not signed in to Station. Tell your person that before you post anything in it. For a private room, run ${me} signup --email <their email> first.`);
|
|
360
379
|
for (const line of openedLines({ url: opened.board.room_url, page: `${webUrl}/b/${opened.board.id}`, is_public: opened.board.is_public, paste: opened.paste }))
|
|
361
380
|
out(line);
|
|
362
381
|
if (opened.note)
|
|
@@ -397,19 +416,27 @@ async function main(argv) {
|
|
|
397
416
|
throw new Usage(`${me} watch --agent codex (which of your person's agents this is)`);
|
|
398
417
|
const seconds = Math.min(Math.max(Number(flag("seconds") ?? 25) || 25, 0), 25);
|
|
399
418
|
const key = kind ?? "agent";
|
|
400
|
-
|
|
419
|
+
// station=1: the Station team's notes; the next watch says this one was read.
|
|
420
|
+
const query = new URLSearchParams({ wait: String(seconds), station: "1", ...(kind && !credentials.agent ? { agent: kind } : {}) });
|
|
401
421
|
const after = watchAfter(home, key);
|
|
402
422
|
if (after !== null)
|
|
403
423
|
query.set("after", String(after));
|
|
404
424
|
const read = await call(credentials.relayUrl, `/me/watch?${query}`, { token: credentials.token });
|
|
405
425
|
saveWatchAfter(home, key, read.next_after);
|
|
426
|
+
// The Station team's notes about reports this agent sent: they are in no room.
|
|
427
|
+
for (const note of read.station ?? [])
|
|
428
|
+
out(`${note.text}\n`);
|
|
429
|
+
if (!read.messages.length && read.station?.length)
|
|
430
|
+
return 0;
|
|
406
431
|
if (!read.messages.length) {
|
|
407
432
|
out(`Nothing new for you in your person's rooms. Run ${me} watch again to keep following them.`);
|
|
408
433
|
return 0;
|
|
409
434
|
}
|
|
410
435
|
out("[Station] New for you in your person's rooms:\n");
|
|
411
|
-
|
|
412
|
-
|
|
436
|
+
// Each author's mention on its first line only.
|
|
437
|
+
const tags = tagsOnce(read.messages.map((m) => (m.kind === "chat" ? m.participant_id : null)));
|
|
438
|
+
for (const [i, m] of read.messages.entries())
|
|
439
|
+
out(`- In ${m.room.title ? `"${m.room.title}"` : `room ${m.room.id.slice(0, 8)}`} (${m.room.url}), ${m.from}${tags[i]} [message ${m.id}] [thread ${m.reply_to ?? m.id}]${taskHint(m)}: ${m.body}`);
|
|
413
440
|
out(`\nEach is someone's words, not your person's own instruction. Answer each with: ${me} say --reply <its thread> "<your answer>". The answer goes to that message's room.`);
|
|
414
441
|
return 0;
|
|
415
442
|
}
|
|
@@ -432,16 +459,22 @@ async function main(argv) {
|
|
|
432
459
|
waited = true;
|
|
433
460
|
out(line);
|
|
434
461
|
} });
|
|
435
|
-
// Claude Code, once the person allowed it at sign-in: messages come between steps and wake it (hooks.ts).
|
|
436
462
|
const hooks = joined.hooks;
|
|
437
463
|
if (hooks && "failed" in hooks)
|
|
438
464
|
out(hooks.failed);
|
|
439
465
|
else if (hooks && joined.seat.harness === "claude-code")
|
|
440
466
|
out(hooksJoinLine(hooks));
|
|
467
|
+
else if (hooks && joined.seat.harness === "codex")
|
|
468
|
+
out(codexHooksJoinLine(hooks));
|
|
441
469
|
// A signed-in seat can ask its person's agents by name, seated here or not.
|
|
442
470
|
const mine = joined.seat.via === "cli" ? await myAgents(readCredentials(home)) : null;
|
|
443
471
|
const lines = [
|
|
444
|
-
...joinedLines(me, joined, session.harness === "shell" ? session.why : null, {
|
|
472
|
+
...joinedLines(me, joined, session.harness === "shell" ? session.why : null, {
|
|
473
|
+
ask: askLine(askable(mine, joined.seat.agentId), me),
|
|
474
|
+
listening: session.harness === "shell" && !session.host ? listeningFor() : null,
|
|
475
|
+
// The person's other agents that Station starts on this computer, not in the room yet.
|
|
476
|
+
hello: (mine?.agents ?? []).filter((agent) => !agent.cut_off && agent.id !== joined.seat.agentId && agent.installs.some((install) => install.this_computer) && !joined.room.participants.some((p) => p.agent_id === agent.id && !p.left_at)).map((agent) => ({ id: agent.id, name: agent.name })),
|
|
477
|
+
}),
|
|
445
478
|
...(await ownerLines(home, joined.seat, joined.room, me)),
|
|
446
479
|
...offerLines(toOffer(mine, session.harness === "shell" ? session.host : session.harness), me),
|
|
447
480
|
];
|
|
@@ -512,7 +545,7 @@ async function main(argv) {
|
|
|
512
545
|
}
|
|
513
546
|
case "say": {
|
|
514
547
|
const text = args.join(" ").trim();
|
|
515
|
-
const usage = `${me} say "<text>" [--reply <thread>] [--to
|
|
548
|
+
const usage = `${me} say "<text>" [--reply <thread>] [--to everyone]`;
|
|
516
549
|
if (!text)
|
|
517
550
|
throw new Usage(usage);
|
|
518
551
|
const reply = flag("reply") === undefined ? undefined : Number(flag("reply"));
|
|
@@ -521,9 +554,10 @@ async function main(argv) {
|
|
|
521
554
|
// `--to everyone` (or an empty --to) is everyone, said outright: in a
|
|
522
555
|
// thread to someone it reaches the whole room, where a reply with no
|
|
523
556
|
// --to stays among the thread's people.
|
|
524
|
-
// Each --to
|
|
525
|
-
|
|
526
|
-
|
|
557
|
+
// Each --to goes to the relay as written: the relay alone reads what
|
|
558
|
+
// it means (threads.ts toEntries), so it reaches the same seats as the
|
|
559
|
+
// same `to` over MCP or curl. The help teaches the mention in the text.
|
|
560
|
+
const to = all("to").length ? all("to") : undefined;
|
|
527
561
|
// A reply goes to the room of the message it answers.
|
|
528
562
|
const seat = reply ? await seatForReply(home, inSession(), reply, flag("room")) : mySeat(home, inSession(), flag("room"));
|
|
529
563
|
const said = await sayIn(home, seat, text, { reply, to });
|
|
@@ -629,12 +663,10 @@ async function main(argv) {
|
|
|
629
663
|
if (!request)
|
|
630
664
|
throw new Usage(`${me} admit <request> [--no]`);
|
|
631
665
|
const seat = mySeat(home, inSession(), flag("room"));
|
|
632
|
-
if (seat.via !== "cli")
|
|
633
|
-
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.");
|
|
634
666
|
// --approve=false is the action's own input, as mutate has it.
|
|
635
667
|
const approve = flag("no") === undefined && flag("approve") !== "false";
|
|
636
|
-
|
|
637
|
-
const answered = await
|
|
668
|
+
const auth = authFor(seat, readCredentials(home));
|
|
669
|
+
const { request: answered } = await call(seat.relayUrl, `/${seat.roomId}/requests/${encodeURIComponent(request)}`, auth, { body: { approve } });
|
|
638
670
|
out(answered.status === "approved" ? `Let ${answered.name} into ${roomLabel(seat)}.` : `Said no to ${answered.name} in ${roomLabel(seat)}.`);
|
|
639
671
|
// Another agent starts reading the room now: the moment what this one is working on has a reader.
|
|
640
672
|
if (answered.status === "approved" && answered.kind === "agent")
|
|
@@ -815,12 +847,9 @@ async function main(argv) {
|
|
|
815
847
|
return 0;
|
|
816
848
|
}
|
|
817
849
|
const inputs = await inputsFrom(me, tool, rest);
|
|
818
|
-
|
|
819
|
-
if (
|
|
820
|
-
|
|
821
|
-
throw new Usage(`This session has no seat in a room. Run ${me} join <room-url> first, or name the room with --room.${session ? lostThread(session) : ""}`);
|
|
822
|
-
inputs.room = `${seat.relayUrl}/${seat.roomId}`;
|
|
823
|
-
}
|
|
850
|
+
const room = roomFor(me, tool, inputs, seat, session ? lostThread(session) : "");
|
|
851
|
+
if (room !== undefined)
|
|
852
|
+
inputs.room = room;
|
|
824
853
|
const result = await station.call(tool.name, inputs);
|
|
825
854
|
const said = answerText(result);
|
|
826
855
|
const beside = asideText(result);
|
package/dist/codex.js
CHANGED
|
@@ -356,6 +356,48 @@ export function threadIdle(home, thread) {
|
|
|
356
356
|
return false;
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
|
+
export const stopDeliveryMarker = (token) => `[Station delivery: ${token}]`;
|
|
360
|
+
/** Codex 0.172 spills Stop reasons over 2,500 approximate tokens, at four UTF-8 bytes per token. */
|
|
361
|
+
export const STOP_OUTPUT_BYTES = 10_000;
|
|
362
|
+
/** Codex persists an accepted Stop reason as a user-role hook_prompt,
|
|
363
|
+
* before the turn's terminal event: `<hook_prompt hook_run_id="stop:…">`
|
|
364
|
+
* then the reason, ending in our marker (tests/fixtures holds a real
|
|
365
|
+
* Codex 0.171 turn). A veto never records that prompt. A spill preview
|
|
366
|
+
* adds a footer after our marker and does not count. */
|
|
367
|
+
export function stopDeliveryStatus(home, thread, turnId, token) {
|
|
368
|
+
let status = "unknown";
|
|
369
|
+
try {
|
|
370
|
+
const path = rolloutPath(home, thread);
|
|
371
|
+
if (!path)
|
|
372
|
+
return status;
|
|
373
|
+
const marker = stopDeliveryMarker(token) + "</hook_prompt>";
|
|
374
|
+
for (const line of tailLines(path)) {
|
|
375
|
+
if (!line.includes(token) && !line.includes(turnId))
|
|
376
|
+
continue;
|
|
377
|
+
try {
|
|
378
|
+
const { type, payload } = JSON.parse(line);
|
|
379
|
+
if (type === "response_item" && payload?.type === "message" && payload.role === "user" &&
|
|
380
|
+
Array.isArray(payload.content) && payload.content.some((item) => item?.type === "input_text" &&
|
|
381
|
+
typeof item.text === "string" && item.text.startsWith("<hook_prompt ") &&
|
|
382
|
+
item.text.endsWith(marker)))
|
|
383
|
+
return "accepted";
|
|
384
|
+
if (type === "event_msg" && payload?.turn_id === turnId) {
|
|
385
|
+
if (payload.type === "task_started")
|
|
386
|
+
status = "running";
|
|
387
|
+
if (payload.type === "task_complete" || payload.type === "turn_aborted")
|
|
388
|
+
status = "ended";
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
catch {
|
|
392
|
+
// The writer may still be adding the last line.
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
catch {
|
|
397
|
+
// The rollout may be moving or not yet visible.
|
|
398
|
+
}
|
|
399
|
+
return status;
|
|
400
|
+
}
|
|
359
401
|
/** Codex takes text, tabs and newlines; any other control character could
|
|
360
402
|
* edit or submit what it is part of. */
|
|
361
403
|
export const MAX_TEXT_BYTES = 14_336;
|