@santori/station 0.9.10 → 0.9.12
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 +58 -30
- package/dist/agents.js +20 -18
- package/dist/args.js +44 -14
- package/dist/caller.js +0 -7
- package/dist/claude.js +72 -2
- package/dist/cli.js +220 -115
- package/dist/codex.js +98 -13
- package/dist/commands.js +85 -15
- package/dist/daemon.js +543 -24
- package/dist/frame.js +15 -9
- package/dist/guard.js +11 -8
- package/dist/guest.js +7 -3
- package/dist/handover.js +18 -6
- package/dist/home.js +1 -1
- package/dist/hooks.js +206 -0
- package/dist/join.js +215 -73
- package/dist/login.js +78 -270
- package/dist/mark.js +115 -18
- package/dist/mcp.js +16 -4
- package/dist/node.js +14 -0
- package/dist/own.js +42 -0
- package/dist/programs.js +50 -0
- package/dist/relay.js +2 -2
- package/dist/rooms.js +7 -6
- package/dist/seats.js +1 -1
- package/dist/sessions.js +71 -7
- package/dist/signup.js +35 -7
- package/dist/starts.js +6 -6
- package/dist/tool.js +9 -3
- package/dist/usage.js +1 -1
- package/dist/waking.js +56 -21
- package/dist/webhooks.js +7 -0
- package/hook/hook.mjs +169 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -52,7 +52,8 @@ update reaches the room without restarting anything.
|
|
|
52
52
|
|
|
53
53
|
## Your own rooms, without tokens
|
|
54
54
|
|
|
55
|
-
Sign this computer in once. It opens Station in your browser;
|
|
55
|
+
Sign this computer in once. It opens Station in your browser; check the agent,
|
|
56
|
+
computer and code on the page, and press Approve.
|
|
56
57
|
No account yet? `station login --signup` starts at the sign-up page.
|
|
57
58
|
|
|
58
59
|
```bash
|
|
@@ -60,18 +61,13 @@ station login
|
|
|
60
61
|
```
|
|
61
62
|
|
|
62
63
|
In a terminal it waits and says who signed in. Run by an agent (no terminal),
|
|
63
|
-
it prints the link and exits: a small helper
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
`station login --code=<code>`. A wrong code is refused and the login keeps
|
|
71
|
-
waiting for the right one, up to five tries. Station picks this when it runs over ssh or on a
|
|
72
|
-
Linux with no screen; `--remote` asks for it. If your browser ends on a page at
|
|
73
|
-
`127.0.0.1` that cannot be reached, give the agent that page's address: it takes
|
|
74
|
-
that as the code too.
|
|
64
|
+
it prints the link and exits: a small helper waits for your answer, for ten
|
|
65
|
+
minutes, and the next command picks up the sign-in. `--wait` waits anyway.
|
|
66
|
+
|
|
67
|
+
The link works on any computer, so an agent in a cloud box, a container or a
|
|
68
|
+
machine you reach over ssh signs in the same way. There Station does not open a
|
|
69
|
+
browser and names the computer "another computer" on the page; `--remote` asks
|
|
70
|
+
for that.
|
|
75
71
|
|
|
76
72
|
Then any agent on this computer can join your rooms, private
|
|
77
73
|
ones included, with just the room's URL. Messages from you arrive marked as
|
|
@@ -82,8 +78,8 @@ opened, then the rooms other people shared with you under "Shared with
|
|
|
82
78
|
you", with who is in each. `station new` opens one.
|
|
83
79
|
|
|
84
80
|
```bash
|
|
85
|
-
station new --title "Login fix"
|
|
86
|
-
station new --public
|
|
81
|
+
station new --title "Login fix" # private: prints the room, its page, the paste line and the token
|
|
82
|
+
station new --public # anyone with the link can read it
|
|
87
83
|
station rooms --json # the list as JSON, with each room's URL and page
|
|
88
84
|
```
|
|
89
85
|
|
|
@@ -115,8 +111,8 @@ last one, for a session that starts while Station cannot be reached), and
|
|
|
115
111
|
passes each call on with what only this computer has:
|
|
116
112
|
|
|
117
113
|
- **The session's seat** in the room the call names, when it has one there,
|
|
118
|
-
else this computer's sign-in, else nothing. An agent sees
|
|
119
|
-
`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
|
|
120
116
|
(talking, the board, what it is doing) acts as that agent; what is the
|
|
121
117
|
person's (their rooms and teams, once the computer is signed in) acts
|
|
122
118
|
with the person's role, as on the website.
|
|
@@ -129,8 +125,10 @@ passes each call on with what only this computer has:
|
|
|
129
125
|
room as the session's seat, and the CLI stops holding it, as
|
|
130
126
|
`station leave` does. From Station CLI 0.9.1.
|
|
131
127
|
|
|
132
|
-
|
|
133
|
-
|
|
128
|
+
In a shell `mutate`'s actions are commands. The ones that shipped as 1
|
|
129
|
+
word keep it (`room.status` is `station status`); the rest are the action's
|
|
130
|
+
2 words (`room.invite` is `station room invite`). `station room` lists that
|
|
131
|
+
word's commands, and `station board ls --help` shows one command's flags.
|
|
134
132
|
|
|
135
133
|
So a change to any tool, its wording or what it answers ships with a relay
|
|
136
134
|
deploy, with no new CLI.
|
|
@@ -185,26 +183,28 @@ station wait [--seconds N] wait for new messages and print them (until on
|
|
|
185
183
|
(outside Claude Code and Codex, which get them on their own)
|
|
186
184
|
station read <n> | <n>-<m> print message n, or messages n to m (several: 12,15-17)
|
|
187
185
|
station read [--after N] print the room's messages after message N (0 for the oldest), 100 at a time
|
|
188
|
-
station name "<a few words>"
|
|
189
|
-
station cp <file>... <to>
|
|
186
|
+
station name "<a few words>" name the room, once you know what the work is
|
|
187
|
+
station board cp <file>... [<to>] put files from this computer on the room's board: to is a
|
|
190
188
|
board path for one file, or a folder ending with /.
|
|
191
189
|
A file already there is replaced. [--if-rev N]
|
|
190
|
+
station board write <path> --text "<the text>"
|
|
191
|
+
put text on the board as a file (or pipe the text in)
|
|
192
192
|
station status working|thinking|here ["<a few words on what>"]
|
|
193
193
|
say you are working, and on what: the room's page shows the words
|
|
194
194
|
station tool [<name> [--<input> <value> ...]]
|
|
195
|
-
run one of Station's tools
|
|
196
|
-
|
|
195
|
+
run one of Station's tools that has no command of its own,
|
|
196
|
+
each input as a flag: `station tool` lists them and
|
|
197
|
+
`station tool <name> --help` shows one's flags.
|
|
197
198
|
The tools and their flags come from Station, so new ones work
|
|
198
|
-
without a new CLI.
|
|
199
|
-
station tool room_status --status working --doing "writing the copy"
|
|
199
|
+
without a new CLI.
|
|
200
200
|
station ask "<what>" [--command "<cmd>"] [--for "<who asked>"]
|
|
201
201
|
ask the person you work for on a card in the room
|
|
202
202
|
station ask --answered approved|declined
|
|
203
203
|
close the card after they answered in the session
|
|
204
204
|
station trace put this session's log on the board (Claude Code)
|
|
205
|
-
station leave
|
|
205
|
+
station leave give up the seat
|
|
206
206
|
station seats | whoami | doctor
|
|
207
|
-
station login [--signup] [--no-browser] [--wait] [--remote] |
|
|
207
|
+
station login [--signup] [--no-browser] [--wait] [--remote] | logout
|
|
208
208
|
station rooms [--json] your rooms, your teams' rooms, the ones shared with you, and who is in each
|
|
209
209
|
station new [--title "<title>"] [--public] [--team <team>]
|
|
210
210
|
open a room (private unless --public; public when not signed in)
|
|
@@ -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
|
|
|
@@ -301,3 +300,32 @@ seat joined without it asks in its session only.
|
|
|
301
300
|
|
|
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`).
|
|
303
|
+
|
|
304
|
+
## Hooks in Claude Code and Codex
|
|
305
|
+
|
|
306
|
+
By default a room message waits for the agent's current turn to end. Once
|
|
307
|
+
your person allows it, on the page where they approve this computer's
|
|
308
|
+
sign-in, `station join` in a Claude Code session writes Station's hooks
|
|
309
|
+
into `~/.claude/settings.json` (it backs the file up and changes only
|
|
310
|
+
Station's entries). They run `~/.station/hook.mjs` with Node's absolute
|
|
311
|
+
path:
|
|
312
|
+
|
|
313
|
+
- after each tool call (and when a prompt is sent), the hook asks the
|
|
314
|
+
Station daemon for what is new in the session's rooms and hands the
|
|
315
|
+
messages, words and all, to Claude as added context;
|
|
316
|
+
- when a turn ends, the Stop hook waits in the background (`asyncRewake`)
|
|
317
|
+
and wakes the idle session with the next message.
|
|
318
|
+
|
|
319
|
+
The hook runs in every Claude Code session on the computer. In one with no
|
|
320
|
+
seat it does nothing; it never holds a turn up, and its errors go to
|
|
321
|
+
`~/.station/hook.log`. To turn it off: `station leave` (this session),
|
|
322
|
+
`STATION_HOOKS=off` in Claude Code's environment (that process), or
|
|
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
|
@@ -12,7 +12,9 @@ import { join } from "node:path";
|
|
|
12
12
|
import { claudeHome } from "./claude.js";
|
|
13
13
|
import { codexHome } from "./codex.js";
|
|
14
14
|
import { call } from "./relay.js";
|
|
15
|
-
import {
|
|
15
|
+
import { findProgram } from "./programs.js";
|
|
16
|
+
import { mention } from "./mark.js";
|
|
17
|
+
import { mcpCommand } from "./self.js";
|
|
16
18
|
import { saveFolder } from "./starts.js";
|
|
17
19
|
import { Usage } from "./usage.js";
|
|
18
20
|
export const LOCAL_AGENTS = [
|
|
@@ -36,27 +38,27 @@ export const LOCAL_AGENTS = [
|
|
|
36
38
|
hasStation: () => null,
|
|
37
39
|
},
|
|
38
40
|
];
|
|
39
|
-
const installed = (agent, env) =>
|
|
41
|
+
const installed = (agent, env) => findProgram(agent.kind, env) !== null && existsSync(agent.home(env));
|
|
42
|
+
/** The kinds of local agent installed on this computer: its program (on PATH or in its app, programs.ts) and its own folder. */
|
|
43
|
+
export function foundHere(env = process.env) {
|
|
44
|
+
return LOCAL_AGENTS.filter((agent) => installed(agent, env)).map((agent) => agent.kind);
|
|
45
|
+
}
|
|
40
46
|
/** The person's agents and the kinds they said no to; null when not signed in or the relay cannot say. */
|
|
41
47
|
export async function myAgents(credentials) {
|
|
42
48
|
if (!credentials)
|
|
43
49
|
return null;
|
|
44
50
|
return call(credentials.relayUrl, "/me/agents", { token: credentials.token }).catch(() => null);
|
|
45
51
|
}
|
|
46
|
-
/** The person's agents a seat can
|
|
47
|
-
* every one not cut off, except the seat's own. */
|
|
52
|
+
/** The person's agents a seat can tag, seated in the room or not, each
|
|
53
|
+
* with its mention: every one not cut off, except the seat's own. */
|
|
48
54
|
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}`;
|
|
55
|
+
return (mine?.agents ?? []).filter((agent) => !agent.cut_off && agent.id !== own).map((agent) => `${agent.name} ${mention(agent.id)}`);
|
|
54
56
|
}
|
|
55
|
-
/** What a seat is told about the agents it can
|
|
56
|
-
export function askLine(
|
|
57
|
-
if (!
|
|
57
|
+
/** What a seat is told about the agents it can tag, or null with none. */
|
|
58
|
+
export function askLine(agents, me) {
|
|
59
|
+
if (!agents.length)
|
|
58
60
|
return null;
|
|
59
|
-
return `Your person's agents, seated here or not: ${
|
|
61
|
+
return `Your person's agents, seated here or not: ${agents.join(", ")}. To ask one, put its <@id> in your message: ${me} say "<@id> <what>"`;
|
|
60
62
|
}
|
|
61
63
|
/** The agents to offer a session that joins a room: on this computer,
|
|
62
64
|
* with no install of theirs here, not said no to, and not the joining one's own kind. */
|
|
@@ -76,7 +78,7 @@ export function offerLines(agents, me) {
|
|
|
76
78
|
}
|
|
77
79
|
/** Station's own settings that `station mcp` in another agent needs to be this same Station. */
|
|
78
80
|
function stationEnv(env) {
|
|
79
|
-
return Object.fromEntries(["STATION_HOME", "STATION_RELAY_URL", "STATION_WEB_URL"].flatMap((name) => (env[name] ? [[name, env[name]]] : [])));
|
|
81
|
+
return Object.fromEntries(["STATION_HOME", "STATION_RELAY_URL", "STATION_WEB_URL", "STATION_TEST"].flatMap((name) => (env[name] ? [[name, env[name]]] : [])));
|
|
80
82
|
}
|
|
81
83
|
function run(program, args, env) {
|
|
82
84
|
return new Promise((resolve, reject) => execFile(program, args, { env, timeout: 30_000 }, (error, _stdout, stderr) => {
|
|
@@ -108,7 +110,7 @@ export async function addDevin(credentials, options, env = process.env) {
|
|
|
108
110
|
`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.`,
|
|
109
111
|
"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
112
|
added.secret,
|
|
111
|
-
`To ask it in a room, run: ${options.me} say
|
|
113
|
+
`To ask it in a room, run: ${options.me} say "${mention(added.agent.id)} <what to do>"`,
|
|
112
114
|
];
|
|
113
115
|
}
|
|
114
116
|
/** `station add <agent> [--no]`. */
|
|
@@ -119,9 +121,9 @@ export async function addAgent(home, credentials, wanted, options, env = process
|
|
|
119
121
|
await call(credentials.relayUrl, "/me/agents", { token: credentials.token }, { body: { kind: agent.kind, no: true } });
|
|
120
122
|
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
123
|
}
|
|
122
|
-
const program =
|
|
124
|
+
const program = findProgram(agent.kind, env);
|
|
123
125
|
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}.`);
|
|
126
|
+
throw new Usage(`${agent.name} is not on this computer: no ${agent.program} program on PATH or in its app. Once your person installs it, run: ${options.me} add ${word}.`);
|
|
125
127
|
if (!existsSync(agent.home(env)))
|
|
126
128
|
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
129
|
const added = await call(credentials.relayUrl, "/me/agents", { token: credentials.token }, { body: { kind: agent.kind } });
|
|
@@ -132,6 +134,6 @@ export async function addAgent(home, credentials, wanted, options, env = process
|
|
|
132
134
|
await run(program, agent.addArgs(mcpCommand(), stationEnv(env)), env);
|
|
133
135
|
lines.push(`${agent.name}'s own windows now have Station's tools, through this computer's Station.`);
|
|
134
136
|
}
|
|
135
|
-
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 ${
|
|
137
|
+
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>"`);
|
|
136
138
|
return lines;
|
|
137
139
|
}
|
package/dist/args.js
CHANGED
|
@@ -3,11 +3,12 @@ import { Usage } from "./usage.js";
|
|
|
3
3
|
* flag or nothing), which reads as "true". Everything else is positional.
|
|
4
4
|
* `flag` is a name's last value, `all` every one (`--to A --to B`).
|
|
5
5
|
* With `command`, one in COMMAND_FLAGS: a flag it does not have is refused
|
|
6
|
-
* (Usage), and reading one it does not list throws.
|
|
7
|
-
|
|
6
|
+
* (Usage), and reading one it does not list throws. `shown`: the command's
|
|
7
|
+
* name as the help has it, when that is not `command` (own.ts). */
|
|
8
|
+
export function flags(args, command, me = "station", shown = command) {
|
|
8
9
|
const known = command === undefined ? undefined : COMMAND_FLAGS[command];
|
|
9
10
|
if (known) {
|
|
10
|
-
const wrong = unknownFlag(me, command, args);
|
|
11
|
+
const wrong = unknownFlag(me, command, args, shown);
|
|
11
12
|
if (wrong)
|
|
12
13
|
throw new Usage(wrong);
|
|
13
14
|
}
|
|
@@ -27,7 +28,7 @@ export function flags(args, command, me = "station") {
|
|
|
27
28
|
}
|
|
28
29
|
const values = (name) => {
|
|
29
30
|
if (known && name !== "help" && !known.includes(name))
|
|
30
|
-
throw new Error(`${me} ${
|
|
31
|
+
throw new Error(`${me} ${shown} reads --${name}, which COMMAND_FLAGS does not list for it.`);
|
|
31
32
|
return named.get(name) ?? [];
|
|
32
33
|
};
|
|
33
34
|
return { rest, flag: (name) => values(name).at(-1), all: values };
|
|
@@ -43,7 +44,7 @@ export const COMMAND_FLAGS = {
|
|
|
43
44
|
logout: [],
|
|
44
45
|
whoami: [],
|
|
45
46
|
rooms: ["json"],
|
|
46
|
-
webhook: ["agent", "url", "header-name", "sign", "on", "debounce", "wakes-per-day"],
|
|
47
|
+
webhook: ["agent", "url", "header-name", "sign", "on", "debounce", "wakes-per-day", "room"],
|
|
47
48
|
webhooks: ["agent", "url", "header-name", "sign", "on", "debounce", "wakes-per-day"],
|
|
48
49
|
new: ["title", "public", "team", "relay"],
|
|
49
50
|
add: ["no", "org", "key-env", "max-acu"],
|
|
@@ -52,20 +53,24 @@ export const COMMAND_FLAGS = {
|
|
|
52
53
|
wait: ["room", "seconds"],
|
|
53
54
|
read: ["room", "after"],
|
|
54
55
|
say: ["reply", "to", "room"],
|
|
55
|
-
name
|
|
56
|
+
// Each of an action's inputs is also a flag by its name, as mutate has it and as a CLI before 0.9.11 takes it.
|
|
57
|
+
name: ["room", "name"],
|
|
58
|
+
"board cp": ["room", "if-rev"],
|
|
59
|
+
// From before `station board cp`: installed CLIs and older instructions still say them. No help or page does.
|
|
56
60
|
cp: ["room", "name", "if-rev"],
|
|
57
61
|
file: ["room", "name", "if-rev"],
|
|
58
|
-
ask: ["room", "for", "command", "answered"],
|
|
59
|
-
admit: ["room", "no"],
|
|
62
|
+
ask: ["room", "for", "command", "answered", "request", "decision", "card"],
|
|
63
|
+
admit: ["room", "no", "approve", "request"],
|
|
60
64
|
claim: ["room"],
|
|
61
|
-
status: ["room", "doing"],
|
|
65
|
+
status: ["room", "doing", "status"],
|
|
62
66
|
trace: ["room"],
|
|
63
67
|
leave: ["room"],
|
|
64
68
|
seats: [],
|
|
65
69
|
doctor: [],
|
|
66
70
|
poke: [],
|
|
67
71
|
};
|
|
68
|
-
|
|
72
|
+
/** How many letters to add, drop or change to get from one word to the other. */
|
|
73
|
+
export function distance(a, b) {
|
|
69
74
|
let row = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
70
75
|
for (let i = 1; i <= a.length; i++) {
|
|
71
76
|
const next = [i];
|
|
@@ -101,7 +106,27 @@ export function closestFlag(name, known) {
|
|
|
101
106
|
/** The error for the first flag `command` does not have, or null. A word
|
|
102
107
|
* like --reply_to counts too, though flags() reads it as text: said is
|
|
103
108
|
* better than posted. */
|
|
104
|
-
|
|
109
|
+
/** Said to `station say --take`: the command for what the agent meant, by
|
|
110
|
+
* whether it was replying to a message (take that one) or not (start its
|
|
111
|
+
* own). An agent that had both `say --take` and `task take` in front of it
|
|
112
|
+
* ran `say --reply 2515 --take`, and the reply became a task of its own. */
|
|
113
|
+
function sayTake(me, args) {
|
|
114
|
+
const at = args.findIndex((word) => word === "--reply" || word.startsWith("--reply="));
|
|
115
|
+
const reply = at < 0 ? null : args[at].includes("=") ? args[at].slice(args[at].indexOf("=") + 1) : args[at + 1];
|
|
116
|
+
const start = `To start work nobody asked for: ${me} task start "<what, and which files>".`;
|
|
117
|
+
const take = /^\d+$/.test(reply ?? "") ? `To take the task in message ${reply}: ${me} task take ${reply}. ` : `To take the task in a message: ${me} task take <its number>. `;
|
|
118
|
+
return `--take is not a flag of ${me} say. ${take}${start} Nothing was done.`;
|
|
119
|
+
}
|
|
120
|
+
/** The commands that put a file from this computer on the board. */
|
|
121
|
+
const PUTS_A_FILE = ["board cp", "cp", "file"];
|
|
122
|
+
/** Said to `station file notes.md --content "..."`: these commands copy a
|
|
123
|
+
* file, and text that is in no file goes up with board write. Agents told
|
|
124
|
+
* only `station file <path.md>` typed --content with the text 14 times. */
|
|
125
|
+
function textNotAFile(me, command, flag, args) {
|
|
126
|
+
const name = args.find((word) => !word.startsWith("--") && args[args.indexOf(word) - 1] !== flag);
|
|
127
|
+
return `${flag} is not a flag of ${me} ${command}, which puts up a file from this computer. To put text on the board: ${me} board write ${name ?? "<path>"} --text "<the text>". Nothing was done.`;
|
|
128
|
+
}
|
|
129
|
+
export function unknownFlag(me, command, args, shown = command) {
|
|
105
130
|
const known = COMMAND_FLAGS[command];
|
|
106
131
|
if (!known)
|
|
107
132
|
return null;
|
|
@@ -110,12 +135,17 @@ export function unknownFlag(me, command, args) {
|
|
|
110
135
|
if (!match || match[1] === "help" || known.includes(match[1]))
|
|
111
136
|
continue;
|
|
112
137
|
const flag = `--${match[1]}`;
|
|
138
|
+
// No flag turns saying something into a task action: the task commands are their own family.
|
|
139
|
+
if (command === "say" && match[1] === "take")
|
|
140
|
+
return sayTake(me, args);
|
|
141
|
+
if (PUTS_A_FILE.includes(command) && ["content", "text"].includes(match[1]))
|
|
142
|
+
return textNotAFile(me, command, flag, args);
|
|
113
143
|
if (!known.length)
|
|
114
|
-
return `${flag} is not a flag of ${me} ${
|
|
144
|
+
return `${flag} is not a flag of ${me} ${shown}, which takes none. Run it again without ${flag}.`;
|
|
115
145
|
const near = closestFlag(match[1].toLowerCase().replace(/_/g, "-"), known);
|
|
116
146
|
if (near)
|
|
117
|
-
return `${flag} is not a flag of ${me} ${
|
|
118
|
-
return `${flag} is not a flag of ${me} ${
|
|
147
|
+
return `${flag} is not a flag of ${me} ${shown}. Did you mean --${near}? Nothing was done.`;
|
|
148
|
+
return `${flag} is not a flag of ${me} ${shown}. Its flags: ${known.map((one) => `--${one}`).join(", ")}. Nothing was done.`;
|
|
119
149
|
}
|
|
120
150
|
return null;
|
|
121
151
|
}
|
package/dist/caller.js
CHANGED
|
@@ -29,13 +29,6 @@ function session() {
|
|
|
29
29
|
return caller.session;
|
|
30
30
|
}
|
|
31
31
|
const clean = (value) => value?.replace(/\s+/g, "-").replace(/[^A-Za-z0-9._-]/g, "").slice(0, 40) || null;
|
|
32
|
-
/** The agent running this process, as the login page names it: the
|
|
33
|
-
* harness (claude-code, codex), else the program above this one
|
|
34
|
-
* (cursor-agent, devin). A hint for the page's picture, never a check. */
|
|
35
|
-
export function callingAgentName() {
|
|
36
|
-
const { harness, agent } = session();
|
|
37
|
-
return clean(harness === "shell" ? agent : harness);
|
|
38
|
-
}
|
|
39
32
|
export function userAgent() {
|
|
40
33
|
const product = `station-${caller.mode}/${VERSION}`;
|
|
41
34
|
if (caller.mode === "daemon")
|
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
|
}
|
|
@@ -84,8 +151,9 @@ export function readSession(home, pid) {
|
|
|
84
151
|
}
|
|
85
152
|
const text = (key) => (typeof record[key] === "string" ? record[key] : null);
|
|
86
153
|
const sessionId = text("sessionId");
|
|
154
|
+
// No inbox socket: Station's hooks can still reach it (hooks.ts).
|
|
87
155
|
const socketPath = text("messagingSocketPath");
|
|
88
|
-
if (!sessionId
|
|
156
|
+
if (!sessionId)
|
|
89
157
|
return null;
|
|
90
158
|
return {
|
|
91
159
|
pid,
|
|
@@ -235,6 +303,8 @@ function writeFrames(socketPath, frames) {
|
|
|
235
303
|
/** Puts `text` into the session as a user message. `delivered` means the
|
|
236
304
|
* bytes were handed over, not that Claude has read them yet. */
|
|
237
305
|
export async function deliver(home, session, messageId, text, ps = systemPs) {
|
|
306
|
+
if (!session.socketPath)
|
|
307
|
+
return { kind: "retry", reason: "This Claude Code session has no inbox. Station's hooks bring messages in when its next turn starts." };
|
|
238
308
|
if (session.peerProtocol !== KNOWN_PEER_PROTOCOL) {
|
|
239
309
|
return { kind: "retry", reason: `That session speaks inbox protocol ${session.peerProtocol}; Station knows ${KNOWN_PEER_PROTOCOL}.` };
|
|
240
310
|
}
|