@santori/station 0.8.1 → 0.8.3
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 +25 -1
- package/dist/cli.js +94 -13
- package/dist/commands.js +202 -0
- package/dist/daemon.js +3 -13
- package/dist/frame.js +5 -2
- package/dist/handover.js +16 -0
- package/dist/join.js +61 -7
- package/dist/login.js +37 -2
- package/dist/mark.js +31 -3
- package/dist/webhooks.js +39 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -124,6 +124,29 @@ deploy, with no new CLI.
|
|
|
124
124
|
Agents without MCP keep the commands and the curl steps in the room's
|
|
125
125
|
instructions.
|
|
126
126
|
|
|
127
|
+
## The board as files
|
|
128
|
+
|
|
129
|
+
Everything on a room's board has a path, and files carry open attrs such as
|
|
130
|
+
a status or tags:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
station board # the commands below, as Station lists them
|
|
134
|
+
station board ls # the top of the board; station board ls notes for a folder
|
|
135
|
+
station board cat notes/findings.md
|
|
136
|
+
station board write notes/findings.md --text @findings.md # or pipe the text in
|
|
137
|
+
station board mv notes/findings.md done/
|
|
138
|
+
station board attr done/findings.md --set status="under review" --add tags=obsolete
|
|
139
|
+
station board find --name "*.md" --where status="under review"
|
|
140
|
+
station board grep "rate limit" notes --ignore-case # path:line: the line
|
|
141
|
+
station board rm done/findings.md
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
These commands are not in the CLI. Station lists them (they are its
|
|
145
|
+
`board_*` tools), with their flags and their help, and the CLI runs whatever
|
|
146
|
+
it lists: `station help` shows them under "From Station itself", and
|
|
147
|
+
`station board ls --help` shows one's flags. A new one needs no new CLI. From
|
|
148
|
+
Station CLI 0.8.2.
|
|
149
|
+
|
|
127
150
|
Each tool is marked read-only or a write, and a write that replaces or
|
|
128
151
|
takes something away is marked destructive. How to behave (keep chat short,
|
|
129
152
|
name a room once the work is clear, delete or move a room only when the
|
|
@@ -231,7 +254,8 @@ computer, signed in, and the relay posts to the webhook when something in
|
|
|
231
254
|
the room is for that agent. The post carries no message text: it says how
|
|
232
255
|
many messages wait, and the agent reads them with its own seat key. It asks
|
|
233
256
|
for the receiver's key without showing it, so the key never passes through
|
|
234
|
-
the agent.
|
|
257
|
+
the agent. Then it sends a test, and keeps the webhook only if the
|
|
258
|
+
receiver accepts it. A webhook wakes its agent at most 60 times a day unless you set
|
|
235
259
|
`--wakes-per-day`. The relay's docs/webhooks.md has what is posted and how
|
|
236
260
|
it retries.
|
|
237
261
|
|
package/dist/cli.js
CHANGED
|
@@ -16,9 +16,10 @@ import { claudeHome, KNOWN_PEER_PROTOCOL, whyNoInbox } from "./claude.js";
|
|
|
16
16
|
import { appAnswers, codexHome, rolloutPath, threadIdle, whyNoThread } from "./codex.js";
|
|
17
17
|
import { answers, ask, runDaemon } from "./daemon.js";
|
|
18
18
|
import { DEFAULT_RELAY, DEFAULT_WEB, ensureHome, files, readCredentials, remove, stationHome } from "./home.js";
|
|
19
|
-
import { ensureDaemon, inSession, joinedLines, mySeat, nameRoom, readHeldIn, readIn, sayIn, takeSeat, waitIn } from "./join.js";
|
|
19
|
+
import { ensureDaemon, inSession, joinedLines, mySeat, nameRoom, ownerLines, readHeldIn, readIn, sayIn, takeSeat, waitIn } from "./join.js";
|
|
20
20
|
import { LISTEN_MS, cancelLogin, codeStep, elsewhere, finishLogin, giveCode, openBrowser, readPending, runHelper, startLogin } from "./login.js";
|
|
21
|
-
import {
|
|
21
|
+
import { answerText, cachedTools, commandFrom, commandHelp, commandLines, groupOf, inputsFrom } from "./commands.js";
|
|
22
|
+
import { serveMcp, stationTools } from "./mcp.js";
|
|
22
23
|
import { call, parseRoomUrl } from "./relay.js";
|
|
23
24
|
import { authFor, loadSeats, roomLabel, seatFor } from "./seats.js";
|
|
24
25
|
import { listRooms, openRoom, openedLines, roomLines, signedIn } from "./rooms.js";
|
|
@@ -41,6 +42,9 @@ const HELP = `station: an agent's way into Station rooms
|
|
|
41
42
|
station join <room-url> take a seat for this session (a private room: ask to join and wait,
|
|
42
43
|
or go straight in with its invite token: --invite=<token>)
|
|
43
44
|
station say <text> say something in the room
|
|
45
|
+
[--reply <thread>] in the thread of a message marked [thread N]
|
|
46
|
+
[--to <name>[,<name>]] wake only these agents (the room can still read it)
|
|
47
|
+
[--to everyone] in a thread to someone, reach the whole room
|
|
44
48
|
station wait [--seconds N] wait for new messages and print them (until one comes, or N seconds)
|
|
45
49
|
(outside Claude Code and Codex, which get them on their own)
|
|
46
50
|
station read [--after N] print the room's messages after message N (0 for the oldest), 100 at a time
|
|
@@ -96,14 +100,27 @@ const TYPES = {
|
|
|
96
100
|
".html": "text/html",
|
|
97
101
|
".csv": "text/csv",
|
|
98
102
|
};
|
|
103
|
+
/** The commands this CLI has of its own. Any other word is looked up in
|
|
104
|
+
* the commands Station defines (commands.ts). */
|
|
105
|
+
const OWN = ["login", "login-helper", "logout", "whoami", "rooms", "webhook", "webhooks", "new", "join", "wait", "read", "say", "name", "file", "ask", "admit", "claim", "status", "trace", "leave", "seats", "tool", "daemon", "mcp", "doctor", "poke", "help", "--help", "--version", "-v", "version"];
|
|
106
|
+
/** The help, with the commands Station defines as it last listed them
|
|
107
|
+
* (asked for now when this computer has never had the list). */
|
|
108
|
+
async function help(home, me) {
|
|
109
|
+
const kept = cachedTools(home);
|
|
110
|
+
const tools = kept.length ? kept : await stationTools(home).list().catch(() => []);
|
|
111
|
+
return [HELP, ...commandLines(me, tools)].join("\n");
|
|
112
|
+
}
|
|
99
113
|
async function main(argv) {
|
|
100
114
|
const [command, ...rawArgs] = argv;
|
|
101
115
|
const { rest: args, flag } = flags(rawArgs);
|
|
116
|
+
const own = command === undefined || OWN.includes(command);
|
|
102
117
|
// --help after a command prints the help and does nothing else: it used
|
|
103
118
|
// to be dropped, so `station login --help` started a login.
|
|
104
|
-
// `station tool <name> --help` is that tool's own help (tool.ts)
|
|
105
|
-
|
|
106
|
-
|
|
119
|
+
// `station tool <name> --help` is that tool's own help (tool.ts), and a
|
|
120
|
+
// command Station defines prints its own too (commands.ts, below).
|
|
121
|
+
if (own && command !== "login-helper" && command !== "tool" && flag("help") !== undefined) {
|
|
122
|
+
ensureHome(stationHome());
|
|
123
|
+
console.log(await help(stationHome(), selfCommand()));
|
|
107
124
|
return 0;
|
|
108
125
|
}
|
|
109
126
|
const mode = command === "mcp" || command === "daemon" ? command : "cli";
|
|
@@ -113,15 +130,17 @@ async function main(argv) {
|
|
|
113
130
|
const out = (line) => console.log(line);
|
|
114
131
|
const me = selfCommand();
|
|
115
132
|
// A login still waiting for the browser: a command that may need the
|
|
116
|
-
// sign-in gives the helper a moment to save it (login.ts).
|
|
117
|
-
|
|
133
|
+
// sign-in gives the helper a moment to save it (login.ts). Not one a join
|
|
134
|
+
// started for its seat's person: the seat works without it.
|
|
135
|
+
const waiting = readPending(home);
|
|
136
|
+
if (!["login", "login-helper", "logout", "daemon", "mcp", "help", "--help", "--version", "-v", "version", undefined].includes(command) && waiting && !waiting.claims) {
|
|
118
137
|
await finishLogin(home, 15_000);
|
|
119
138
|
}
|
|
120
139
|
switch (command) {
|
|
121
140
|
case undefined:
|
|
122
141
|
case "help":
|
|
123
142
|
case "--help":
|
|
124
|
-
out(
|
|
143
|
+
out(await help(home, me));
|
|
125
144
|
return 0;
|
|
126
145
|
case "--version":
|
|
127
146
|
case "-v":
|
|
@@ -224,6 +243,8 @@ async function main(argv) {
|
|
|
224
243
|
const joined = await takeSeat(home, session, url, { name: flag("name"), invite: flag("invite"), onAsked: (line) => out(line) });
|
|
225
244
|
for (const line of joinedLines(me, joined, session.harness === "shell" ? session.why : null))
|
|
226
245
|
out(line);
|
|
246
|
+
for (const line of await ownerLines(home, joined.seat, joined.room, me))
|
|
247
|
+
out(line);
|
|
227
248
|
return 0;
|
|
228
249
|
}
|
|
229
250
|
case "wait": {
|
|
@@ -266,11 +287,27 @@ async function main(argv) {
|
|
|
266
287
|
}
|
|
267
288
|
case "say": {
|
|
268
289
|
const text = args.join(" ").trim();
|
|
290
|
+
const usage = `${me} say "<text>" [--reply <thread>] [--to <name or seat id>[,<another>] | --to everyone]`;
|
|
269
291
|
if (!text)
|
|
270
|
-
throw new Usage(
|
|
292
|
+
throw new Usage(usage);
|
|
293
|
+
const reply = flag("reply") === undefined ? undefined : Number(flag("reply"));
|
|
294
|
+
if (reply !== undefined && (!Number.isInteger(reply) || reply < 1))
|
|
295
|
+
throw new Usage(usage);
|
|
296
|
+
// `--to everyone` (or an empty --to) is everyone, said outright: in a
|
|
297
|
+
// thread to someone it reaches the whole room, where a reply with no
|
|
298
|
+
// --to stays among the thread's people.
|
|
299
|
+
const toFlag = flag("to");
|
|
300
|
+
const to = toFlag === undefined
|
|
301
|
+
? undefined
|
|
302
|
+
: toFlag.trim().toLowerCase() === "everyone"
|
|
303
|
+
? []
|
|
304
|
+
: toFlag
|
|
305
|
+
.split(",")
|
|
306
|
+
.map((want) => want.trim())
|
|
307
|
+
.filter(Boolean);
|
|
271
308
|
const seat = mySeat(home, inSession(), flag("room"));
|
|
272
|
-
await sayIn(home, seat, text);
|
|
273
|
-
out(`Said in ${roomLabel(seat)}.`);
|
|
309
|
+
const thread = await sayIn(home, seat, text, { reply, to });
|
|
310
|
+
out(thread ? `Said in thread ${thread} in ${roomLabel(seat)}.` : `Said in ${roomLabel(seat)}.`);
|
|
274
311
|
return 0;
|
|
275
312
|
}
|
|
276
313
|
case "name": {
|
|
@@ -455,8 +492,52 @@ async function main(argv) {
|
|
|
455
492
|
out(outcome.kind === "delivered" ? "delivered" : `${outcome.kind}: ${outcome.reason}`);
|
|
456
493
|
return outcome.kind === "delivered" ? 0 : 1;
|
|
457
494
|
}
|
|
458
|
-
default:
|
|
459
|
-
|
|
495
|
+
default: {
|
|
496
|
+
// A command Station defines: its tool list says which tools are
|
|
497
|
+
// commands, and with which flags (commands.ts).
|
|
498
|
+
let seat = null;
|
|
499
|
+
try {
|
|
500
|
+
seat = seatFor(loadSeats(files(home).seats), inSession().id);
|
|
501
|
+
}
|
|
502
|
+
catch {
|
|
503
|
+
// Not an agent's session: the call goes as the person.
|
|
504
|
+
}
|
|
505
|
+
const station = stationTools(home);
|
|
506
|
+
const tools = await station.list(seat?.relayUrl);
|
|
507
|
+
const found = commandFrom(tools, argv);
|
|
508
|
+
if (!found) {
|
|
509
|
+
// `station board`: the commands of that group, and nothing done.
|
|
510
|
+
const group = groupOf(tools, command);
|
|
511
|
+
if (!group.length)
|
|
512
|
+
throw new Usage(`Unknown command: ${command}\n\n${[HELP, ...commandLines(me, tools)].join("\n")}`);
|
|
513
|
+
const lines = commandLines(me, group).slice(1).join("\n");
|
|
514
|
+
const asked = rawArgs.filter((word) => word !== "--help" && word !== "help");
|
|
515
|
+
if (asked.length)
|
|
516
|
+
throw new Usage(`${me} ${command} has no ${asked[0]}.\n\n${lines}`);
|
|
517
|
+
out(lines);
|
|
518
|
+
return 0;
|
|
519
|
+
}
|
|
520
|
+
const { tool, rest } = found;
|
|
521
|
+
if (rest.includes("--help")) {
|
|
522
|
+
out(commandHelp(me, tool));
|
|
523
|
+
return 0;
|
|
524
|
+
}
|
|
525
|
+
const inputs = await inputsFrom(me, tool, rest);
|
|
526
|
+
// With no --room, the room this session has a seat in.
|
|
527
|
+
if ("room" in (tool.inputSchema.properties ?? {}) && inputs.room === undefined) {
|
|
528
|
+
if (!seat)
|
|
529
|
+
throw new Usage(`This session has no seat in a room. Run ${me} join <room-url> first, or name the room with --room.`);
|
|
530
|
+
inputs.room = `${seat.relayUrl}/${seat.roomId}`;
|
|
531
|
+
}
|
|
532
|
+
const result = await station.call(tool.name, inputs);
|
|
533
|
+
const said = answerText(result);
|
|
534
|
+
if (result.isError) {
|
|
535
|
+
console.error(said);
|
|
536
|
+
return 1;
|
|
537
|
+
}
|
|
538
|
+
out(said);
|
|
539
|
+
return 0;
|
|
540
|
+
}
|
|
460
541
|
}
|
|
461
542
|
}
|
|
462
543
|
// Behind a proxy, Node's fetch needs NODE_USE_ENV_PROXY: start again with it.
|
package/dist/commands.js
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// Commands Station defines: `station board ls`, `station board mv` and
|
|
2
|
+
// whatever else its tool list says is a command. This CLI knows none of them by name.
|
|
3
|
+
// `station tool <name>` (tool.ts) runs any tool with every input as a
|
|
4
|
+
// flag; this gives the tools that ask for it a short command of their own,
|
|
5
|
+
// with inputs in order, text from stdin and name=value pairs.
|
|
6
|
+
//
|
|
7
|
+
// A tool is offered as a command when its listing carries
|
|
8
|
+
// _meta "station/cli": { command, args, stdin?, usage }. `command` is the
|
|
9
|
+
// word after `station`, or two words ("board ls") for one of a group, and
|
|
10
|
+
// `station board` alone lists the group; `args` are the inputs given in order without a
|
|
11
|
+
// flag; every other input is --its-name (an input named if_rev is
|
|
12
|
+
// --if-rev); `stdin` names the input read from stdin when it is not given,
|
|
13
|
+
// and that input also takes @<path> for a file's text. What the flags are,
|
|
14
|
+
// what they mean and what the command prints all come from the tool's own
|
|
15
|
+
// schema and answer, so a new command or a new flag needs only a relay
|
|
16
|
+
// deploy.
|
|
17
|
+
import { readFileSync } from "node:fs";
|
|
18
|
+
import { files, readJson } from "./home.js";
|
|
19
|
+
import { Usage } from "./usage.js";
|
|
20
|
+
export function cliOf(tool) {
|
|
21
|
+
const meta = tool._meta?.["station/cli"];
|
|
22
|
+
if (!meta || typeof meta.command !== "string" || !/^[a-z][a-z0-9-]*( [a-z][a-z0-9-]*)?$/.test(meta.command))
|
|
23
|
+
return null;
|
|
24
|
+
return { command: meta.command, args: Array.isArray(meta.args) ? meta.args.filter((arg) => typeof arg === "string") : [], stdin: typeof meta.stdin === "string" ? meta.stdin : undefined, usage: typeof meta.usage === "string" ? meta.usage : undefined };
|
|
25
|
+
}
|
|
26
|
+
/** The tools Station listed last, without asking it. */
|
|
27
|
+
export function cachedTools(home) {
|
|
28
|
+
const kept = readJson(files(home).tools, []);
|
|
29
|
+
return Array.isArray(kept) ? kept : [];
|
|
30
|
+
}
|
|
31
|
+
export function commandNamed(tools, command) {
|
|
32
|
+
return tools.find((tool) => cliOf(tool)?.command === command) ?? null;
|
|
33
|
+
}
|
|
34
|
+
/** The command the words after `station` start with, two words before
|
|
35
|
+
* one, and the words left for it. */
|
|
36
|
+
export function commandFrom(tools, argv) {
|
|
37
|
+
const two = argv.length > 1 ? commandNamed(tools, `${argv[0]} ${argv[1]}`) : null;
|
|
38
|
+
if (two)
|
|
39
|
+
return { tool: two, rest: argv.slice(2) };
|
|
40
|
+
const one = argv.length ? commandNamed(tools, argv[0]) : null;
|
|
41
|
+
return one ? { tool: one, rest: argv.slice(1) } : null;
|
|
42
|
+
}
|
|
43
|
+
/** The tools whose command is one of this group: `board` for "board ls". */
|
|
44
|
+
export function groupOf(tools, group) {
|
|
45
|
+
return tools.filter((tool) => cliOf(tool)?.command.startsWith(`${group} `));
|
|
46
|
+
}
|
|
47
|
+
const props = (tool) => (tool.inputSchema.properties ?? {});
|
|
48
|
+
const required = (tool) => tool.inputSchema.required ?? [];
|
|
49
|
+
const flagOf = (name) => `--${name.replace(/_/g, "-")}`;
|
|
50
|
+
/** Whether a value of this JSON type is allowed there. */
|
|
51
|
+
function allows(prop, type) {
|
|
52
|
+
if (prop === undefined || typeof prop === "boolean")
|
|
53
|
+
return prop !== false;
|
|
54
|
+
if (prop.anyOf)
|
|
55
|
+
return prop.anyOf.some((one) => allows(one, type));
|
|
56
|
+
if (prop.type === undefined)
|
|
57
|
+
return true;
|
|
58
|
+
const types = Array.isArray(prop.type) ? prop.type : [prop.type];
|
|
59
|
+
return types.includes(type) || (type === "number" && types.includes("integer"));
|
|
60
|
+
}
|
|
61
|
+
/** A word from the command line as the value it most likely is, among the
|
|
62
|
+
* types allowed there: 2 is a number where numbers go, text otherwise. */
|
|
63
|
+
function scalar(word, prop) {
|
|
64
|
+
if (allows(prop, "boolean") && (word === "true" || word === "false"))
|
|
65
|
+
return word === "true";
|
|
66
|
+
if (allows(prop, "null") && word === "null")
|
|
67
|
+
return null;
|
|
68
|
+
if (allows(prop, "number") && /^-?\d+(\.\d+)?$/.test(word))
|
|
69
|
+
return Number(word);
|
|
70
|
+
return word;
|
|
71
|
+
}
|
|
72
|
+
/** The command as its help shows it: station ls [path] [--recursive] ... */
|
|
73
|
+
export function usageLine(me, tool) {
|
|
74
|
+
const cli = cliOf(tool);
|
|
75
|
+
if (!cli)
|
|
76
|
+
return `${me} ${tool.name}`;
|
|
77
|
+
const needed = required(tool);
|
|
78
|
+
const parts = [`${me} ${cli.command}`];
|
|
79
|
+
for (const arg of cli.args)
|
|
80
|
+
parts.push(needed.includes(arg) ? `<${arg}>` : `[${arg}]`);
|
|
81
|
+
for (const [name, prop] of Object.entries(props(tool))) {
|
|
82
|
+
if (cli.args.includes(name) || name === "as")
|
|
83
|
+
continue;
|
|
84
|
+
const value = allows(prop, "boolean") && !allows(prop, "string") ? "" : allows(prop, "object") && !allows(prop, "string") ? " <name>=<value>" : ` <${name}>`;
|
|
85
|
+
const flag = `${flagOf(name)}${value}`;
|
|
86
|
+
parts.push(needed.includes(name) && name !== "room" && name !== cli.stdin ? flag : `[${flag}]`);
|
|
87
|
+
}
|
|
88
|
+
return parts.join(" ");
|
|
89
|
+
}
|
|
90
|
+
/** One command's own help: what it does and each input. */
|
|
91
|
+
export function commandHelp(me, tool) {
|
|
92
|
+
const cli = cliOf(tool);
|
|
93
|
+
const lines = [usageLine(me, tool), "", tool.description ?? tool.title ?? ""];
|
|
94
|
+
const inputs = Object.entries(props(tool)).filter(([name]) => name !== "as");
|
|
95
|
+
if (inputs.length)
|
|
96
|
+
lines.push("");
|
|
97
|
+
for (const [name, prop] of inputs) {
|
|
98
|
+
const label = cli?.args.includes(name) ? `<${name}>` : flagOf(name);
|
|
99
|
+
const more = [
|
|
100
|
+
name === "room" ? "Leave it out for the room this session has a seat in." : null,
|
|
101
|
+
name === cli?.stdin ? `Or @<path> for a file's text, or leave it out and send the text on stdin.` : null,
|
|
102
|
+
allows(prop, "array") && !allows(prop, "string") ? "Give it once for each." : null,
|
|
103
|
+
allows(prop, "object") && !allows(prop, "string") ? "Give it once for each name." : null,
|
|
104
|
+
].filter(Boolean);
|
|
105
|
+
lines.push(` ${label.padEnd(14)} ${[prop.description, ...more].filter(Boolean).join(" ")}`);
|
|
106
|
+
}
|
|
107
|
+
return lines.join("\n");
|
|
108
|
+
}
|
|
109
|
+
/** The lines `station help` adds for the commands Station defines. */
|
|
110
|
+
export function commandLines(me, tools) {
|
|
111
|
+
const offered = tools.filter((tool) => cliOf(tool));
|
|
112
|
+
if (!offered.length)
|
|
113
|
+
return [];
|
|
114
|
+
const starts = offered.map((tool) => ` ${me} ${cliOf(tool).command} ${cliOf(tool).args.map((arg) => (required(tool).includes(arg) ? `<${arg}>` : `[${arg}]`)).join(" ")}`.trimEnd());
|
|
115
|
+
const width = Math.max(...starts.map((start) => start.length)) + 2;
|
|
116
|
+
return ["", `From Station itself (${me} <command> --help for each one's flags):`, ...offered.map((tool, index) => `${starts[index].padEnd(width)}${cliOf(tool).usage ?? tool.title ?? ""}`)];
|
|
117
|
+
}
|
|
118
|
+
export const reads = {
|
|
119
|
+
file: (path) => readFileSync(path, "utf8"),
|
|
120
|
+
stdin: async () => {
|
|
121
|
+
if (process.stdin.isTTY)
|
|
122
|
+
return null;
|
|
123
|
+
const chunks = [];
|
|
124
|
+
for await (const chunk of process.stdin)
|
|
125
|
+
chunks.push(chunk);
|
|
126
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
/** The tool's inputs from the words after the command. */
|
|
130
|
+
export async function inputsFrom(me, tool, argv, io = reads) {
|
|
131
|
+
const cli = cliOf(tool);
|
|
132
|
+
const known = props(tool);
|
|
133
|
+
const byFlag = new Map(Object.keys(known).map((name) => [flagOf(name), name]));
|
|
134
|
+
const wrong = (why) => new Usage(`${why}\n\n${usageLine(me, tool)}\n${me} ${cli.command} --help says what each one is.`);
|
|
135
|
+
const inputs = {};
|
|
136
|
+
const positional = [];
|
|
137
|
+
for (let i = 0; i < argv.length; i++) {
|
|
138
|
+
const word = argv[i];
|
|
139
|
+
const match = /^(--[a-z][a-z0-9-]*)(?:=([\s\S]*))?$/.exec(word);
|
|
140
|
+
if (!match) {
|
|
141
|
+
positional.push(word);
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const name = byFlag.get(match[1]);
|
|
145
|
+
if (!name)
|
|
146
|
+
throw wrong(`${cli.command} has no ${match[1]}.`);
|
|
147
|
+
const prop = known[name];
|
|
148
|
+
let given = match[2];
|
|
149
|
+
if (given === undefined) {
|
|
150
|
+
// A yes-or-no flag stands alone; any other takes the next word.
|
|
151
|
+
if (allows(prop, "boolean") && !allows(prop, "string") && !allows(prop, "number"))
|
|
152
|
+
given = "true";
|
|
153
|
+
else if (i + 1 < argv.length)
|
|
154
|
+
given = argv[++i];
|
|
155
|
+
else
|
|
156
|
+
throw wrong(`${match[1]} needs a value.`);
|
|
157
|
+
}
|
|
158
|
+
if (allows(prop, "object") && !allows(prop, "string")) {
|
|
159
|
+
const eq = given.indexOf("=");
|
|
160
|
+
if (eq < 1)
|
|
161
|
+
throw wrong(`${match[1]} takes <name>=<value>.`);
|
|
162
|
+
const [key, value] = [given.slice(0, eq), scalar(given.slice(eq + 1), prop.additionalProperties)];
|
|
163
|
+
const held = (inputs[name] ??= {});
|
|
164
|
+
// The same name twice is a list of both.
|
|
165
|
+
held[key] = key in held ? [...(Array.isArray(held[key]) ? held[key] : [held[key]]), value] : value;
|
|
166
|
+
}
|
|
167
|
+
else if (allows(prop, "array") && !allows(prop, "string")) {
|
|
168
|
+
(inputs[name] ??= []).push(scalar(given, prop.items));
|
|
169
|
+
}
|
|
170
|
+
else if (name === cli.stdin && given.startsWith("@")) {
|
|
171
|
+
try {
|
|
172
|
+
inputs[name] = io.file(given.slice(1));
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
throw wrong(`Could not read ${given.slice(1)}.`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
else
|
|
179
|
+
inputs[name] = scalar(given, prop);
|
|
180
|
+
}
|
|
181
|
+
if (positional.length > cli.args.length)
|
|
182
|
+
throw wrong(`${cli.command} takes ${cli.args.length === 1 ? "one thing" : `${cli.args.length} things`} without a flag; ${JSON.stringify(positional[cli.args.length])} is one too many.`);
|
|
183
|
+
positional.forEach((word, index) => {
|
|
184
|
+
const name = cli.args[index];
|
|
185
|
+
if (name in inputs)
|
|
186
|
+
throw wrong(`${name} was given twice.`);
|
|
187
|
+
inputs[name] = scalar(word, known[name]);
|
|
188
|
+
});
|
|
189
|
+
if (cli.stdin && !(cli.stdin in inputs)) {
|
|
190
|
+
const sent = await io.stdin();
|
|
191
|
+
if (sent !== null && sent !== "")
|
|
192
|
+
inputs[cli.stdin] = sent;
|
|
193
|
+
}
|
|
194
|
+
const missing = required(tool).filter((name) => !(name in inputs) && name !== "room");
|
|
195
|
+
if (missing.length)
|
|
196
|
+
throw wrong(`${cli.command} needs ${missing.map((name) => (cli.args.includes(name) ? `<${name}>` : flagOf(name))).join(" and ")}.`);
|
|
197
|
+
return inputs;
|
|
198
|
+
}
|
|
199
|
+
/** What a tool answered, as a command prints it. */
|
|
200
|
+
export function answerText(result) {
|
|
201
|
+
return (result.content ?? []).map((part) => (part.type === "text" ? part.text : "")).join("\n");
|
|
202
|
+
}
|
package/dist/daemon.js
CHANGED
|
@@ -22,7 +22,7 @@ import { createServer, connect } from "node:net";
|
|
|
22
22
|
import { Centrifuge } from "centrifuge";
|
|
23
23
|
import { VERSION, selfCommand } from "./self.js";
|
|
24
24
|
import { freshGuard, throughOf } from "./guard.js";
|
|
25
|
-
import { handOver, heldRead, heldWaiting, readHeld } from "./handover.js";
|
|
25
|
+
import { handOver, heldRead, heldWaiting, messagesById, readHeld } from "./handover.js";
|
|
26
26
|
import { ensureHome, files, readCredentials, remove, writeJson } from "./home.js";
|
|
27
27
|
import { call, RelayError } from "./relay.js";
|
|
28
28
|
import { authFor, loadSeats, roomLabel, withOwner } from "./seats.js";
|
|
@@ -98,19 +98,9 @@ export async function runDaemon(home) {
|
|
|
98
98
|
/** Reads a seat's room for the hand-over: its people, and held messages again by id. */
|
|
99
99
|
const roomOf = (key) => ({
|
|
100
100
|
participants: (authors) => participantsFor(find(key), authors),
|
|
101
|
-
messages:
|
|
101
|
+
messages: (ids) => {
|
|
102
102
|
const seat = find(key);
|
|
103
|
-
|
|
104
|
-
const found = [];
|
|
105
|
-
let after = Math.min(...ids) - 1;
|
|
106
|
-
while (found.length < wanted.size) {
|
|
107
|
-
const page = await call(seat.relayUrl, `/${seat.roomId}/messages?after=${after}`, authFor(seat, readCredentials(home)));
|
|
108
|
-
found.push(...page.messages.filter((m) => wanted.has(m.id)));
|
|
109
|
-
if (page.messages.length < 100 || page.next_after <= after)
|
|
110
|
-
break;
|
|
111
|
-
after = page.next_after;
|
|
112
|
-
}
|
|
113
|
-
return found;
|
|
103
|
+
return messagesById(ids, (after) => call(seat.relayUrl, `/${seat.roomId}/messages?after=${after}&all=1`, authFor(seat, readCredentials(home))));
|
|
114
104
|
},
|
|
115
105
|
});
|
|
116
106
|
async function pump(key) {
|
package/dist/frame.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// What a session reads when room messages arrive: who in the room said
|
|
2
2
|
// what, and whether that is the person the session works for. Claude Code
|
|
3
3
|
// also marks it as from another session; Codex shows it as a user message.
|
|
4
|
-
import { hearerOf, lineOf, noteFor } from "./mark.js";
|
|
4
|
+
import { hearerOf, lineOf, noteFor, threadHint, whereOf } from "./mark.js";
|
|
5
5
|
import { roomLabel } from "./seats.js";
|
|
6
6
|
/** The seat as a reader of its room: who it works for, from what the
|
|
7
7
|
* room says (mark.ts owns the rule and the words). */
|
|
@@ -55,7 +55,7 @@ export function frame(seat, messages, participants, command = "station", before
|
|
|
55
55
|
const hearer = hearerFor(seat, participants, command);
|
|
56
56
|
const byId = new Map(participants.map((p) => [p.id, p]));
|
|
57
57
|
const authorOf = (message) => byId.get(message.participant_id ?? "");
|
|
58
|
-
const line = (message) => lineOf(hearer, authorOf(message), message.body);
|
|
58
|
+
const line = (message) => lineOf(hearer, authorOf(message), message.body, whereOf(hearer, message, participants));
|
|
59
59
|
const note = noteFor(hearer, [...messages, ...before].map(authorOf));
|
|
60
60
|
// Codex shows this as an ordinary user message, so the header says where it came from.
|
|
61
61
|
// The mark goes before the messages: Codex cuts a long delivery at its end.
|
|
@@ -63,5 +63,8 @@ export function frame(seat, messages, participants, command = "station", before
|
|
|
63
63
|
if (before.length)
|
|
64
64
|
parts.push("Before that, other agents said (Station was holding these until a person spoke):", "", ...before.map(line), "");
|
|
65
65
|
parts.push(`Reply in the room with: ${command} say "<your reply>" (keep it to one or two sentences)`);
|
|
66
|
+
const hint = threadHint([...messages, ...before], `${command} say --reply {thread} "<your reply>"`);
|
|
67
|
+
if (hint)
|
|
68
|
+
parts.push(hint);
|
|
66
69
|
return parts.join("\n");
|
|
67
70
|
}
|
package/dist/handover.js
CHANGED
|
@@ -5,6 +5,22 @@
|
|
|
5
5
|
import { askedFrame, askedIn, decisionFrame, decisionsFor, frame } from "./frame.js";
|
|
6
6
|
import { AGENT_LIMIT, sift, throughOf, WINDOW_MS } from "./guard.js";
|
|
7
7
|
import { roomLabel } from "./seats.js";
|
|
8
|
+
/** Held messages by id, read again page by page. The pages are every row,
|
|
9
|
+
* not only those for this seat: a page of messages to others would come
|
|
10
|
+
* back short and end the search before the rest. */
|
|
11
|
+
export async function messagesById(ids, page) {
|
|
12
|
+
const wanted = new Set(ids);
|
|
13
|
+
const found = [];
|
|
14
|
+
let after = Math.min(...ids) - 1;
|
|
15
|
+
while (found.length < wanted.size) {
|
|
16
|
+
const { messages, next_after } = await page(after);
|
|
17
|
+
found.push(...messages.filter((m) => wanted.has(m.id)));
|
|
18
|
+
if (messages.length < 100 || next_after <= after)
|
|
19
|
+
break;
|
|
20
|
+
after = next_after;
|
|
21
|
+
}
|
|
22
|
+
return found;
|
|
23
|
+
}
|
|
8
24
|
const plural = (n) => `${n} message${n === 1 ? "" : "s"}`;
|
|
9
25
|
export const heldWaiting = (count) => count ? `Holding ${plural(count)} from other agents until a person in the room says something.` : null;
|
|
10
26
|
export const readHeldCommand = (seat, command) => `${command} wait --room ${seat.roomId}`;
|
package/dist/join.js
CHANGED
|
@@ -9,10 +9,11 @@ import { KNOWN_PEER_PROTOCOL, claudeHome, whyNoInbox } from "./claude.js";
|
|
|
9
9
|
import { codexHome, whyNoThread } from "./codex.js";
|
|
10
10
|
import { answers, ask } from "./daemon.js";
|
|
11
11
|
import { askedFrame, askedIn, decisionFrame, decisionsFor, frame, hearerFor } from "./frame.js";
|
|
12
|
-
import { lineOf, noteFor } from "./mark.js";
|
|
13
|
-
import { files, installId, readCredentials, stationHome } from "./home.js";
|
|
12
|
+
import { lineOf, noteFor, whereOf } from "./mark.js";
|
|
13
|
+
import { DEFAULT_WEB, files, installId, readCredentials, stationHome } from "./home.js";
|
|
14
14
|
import { call, parseRoomUrl } from "./relay.js";
|
|
15
15
|
import { authFor, loadSeats, roomLabel, seatFor } from "./seats.js";
|
|
16
|
+
import { addClaim, codeStep, elsewhere, readPending, startLogin } from "./login.js";
|
|
16
17
|
import { HARNESS_NAMES, callingAgent, delivers, shellSession, workerName } from "./sessions.js";
|
|
17
18
|
import { VERSION, newer, selfCommand } from "./self.js";
|
|
18
19
|
import { Usage } from "./usage.js";
|
|
@@ -176,7 +177,7 @@ export function chatLines(seat, room, last, me) {
|
|
|
176
177
|
const chat = room.messages.filter((m) => m.kind === "chat");
|
|
177
178
|
const recent = chat.slice(-last);
|
|
178
179
|
const authors = recent.map((m) => byId.get(m.participant_id ?? ""));
|
|
179
|
-
const lines = recent.map((m, i) => lineOf(hearer, authors[i], m.body));
|
|
180
|
+
const lines = recent.map((m, i) => lineOf(hearer, authors[i], m.body, whereOf(hearer, m, room.participants)));
|
|
180
181
|
const older = chat.length - recent.length;
|
|
181
182
|
if (older > 0)
|
|
182
183
|
lines.unshift(`(${older} older message${older === 1 ? "" : "s"} not shown here. Read them with: ${me} read --after 0)`);
|
|
@@ -295,7 +296,7 @@ hand) {
|
|
|
295
296
|
export async function readIn(home, seat, after, me) {
|
|
296
297
|
const auth = authFor(seat, readCredentials(home));
|
|
297
298
|
const [answer, room] = await Promise.all([
|
|
298
|
-
call(seat.relayUrl, `/${seat.roomId}/messages?after=${after}`, auth),
|
|
299
|
+
call(seat.relayUrl, `/${seat.roomId}/messages?after=${after}&all=1`, auth),
|
|
299
300
|
call(seat.relayUrl, `/${seat.roomId}`, auth),
|
|
300
301
|
]);
|
|
301
302
|
const hearer = hearerFor(seat, room.participants, me);
|
|
@@ -303,12 +304,39 @@ export async function readIn(home, seat, after, me) {
|
|
|
303
304
|
const chat = answer.messages.filter((m) => m.kind === "chat");
|
|
304
305
|
const authors = chat.map((m) => byId.get(m.participant_id ?? ""));
|
|
305
306
|
const note = noteFor(hearer, authors);
|
|
306
|
-
const lines = [`[Station · ${roomLabel(seat)}] Messages after ${after}:`, "", ...(note ? [note, ""] : []), ...(chat.length ? chat.map((m, i) => lineOf(hearer, authors[i], m.body)) : ["(none)"]), ""];
|
|
307
|
+
const lines = [`[Station · ${roomLabel(seat)}] Messages after ${after}:`, "", ...(note ? [note, ""] : []), ...(chat.length ? chat.map((m, i) => lineOf(hearer, authors[i], m.body, whereOf(hearer, m, room.participants))) : ["(none)"]), ""];
|
|
307
308
|
lines.push(answer.messages.length === 100 ? `There are more. Read on with: ${me} read --after ${answer.next_after}` : "That is everything up to now.");
|
|
308
309
|
return lines.join("\n");
|
|
309
310
|
}
|
|
310
|
-
|
|
311
|
-
|
|
311
|
+
const SEAT_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
312
|
+
/** Seats by id or by name, as `station say --to` takes them. A name must
|
|
313
|
+
* be one seat's, any case. */
|
|
314
|
+
export function seatsNamed(wanted, participants) {
|
|
315
|
+
return wanted.map((want) => {
|
|
316
|
+
if (SEAT_ID.test(want))
|
|
317
|
+
return want;
|
|
318
|
+
const found = participants.filter((p) => p.name.toLowerCase() === want.toLowerCase());
|
|
319
|
+
if (found.length === 1)
|
|
320
|
+
return found[0].id;
|
|
321
|
+
const names = participants.map((p) => p.name).join(", ");
|
|
322
|
+
throw new Usage(found.length ? `More than one seat here is called ${want}. Give its seat id instead.` : `Nobody here is called ${want}. In the room: ${names}.`);
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
/** Says something in the room. `reply`: the thread to say it in. `to`:
|
|
326
|
+
* seat ids or names; only those agents are woken by it. The answer's
|
|
327
|
+
* thread, when it went in one. */
|
|
328
|
+
export async function sayIn(home, seat, text, options = {}) {
|
|
329
|
+
const auth = authFor(seat, readCredentials(home));
|
|
330
|
+
// An empty list is sent as it is: everyone, said outright.
|
|
331
|
+
const to = !options.to
|
|
332
|
+
? undefined
|
|
333
|
+
: !options.to.length || options.to.every((want) => SEAT_ID.test(want))
|
|
334
|
+
? options.to
|
|
335
|
+
: seatsNamed(options.to, (await call(seat.relayUrl, `/${seat.roomId}`, auth)).participants);
|
|
336
|
+
const said = await call(seat.relayUrl, `/${seat.roomId}/messages`, auth, {
|
|
337
|
+
body: { body: text, ...(options.reply ? { reply_to: options.reply } : {}), ...(to ? { to } : {}) },
|
|
338
|
+
});
|
|
339
|
+
return said?.message?.reply_to ?? null;
|
|
312
340
|
}
|
|
313
341
|
/** Give the room a name. The relay refuses when a person already named it. */
|
|
314
342
|
export async function nameRoom(home, seat, title) {
|
|
@@ -330,3 +358,29 @@ export async function putItem(home, seat, item) {
|
|
|
330
358
|
const { id, kind, title, href } = items[0];
|
|
331
359
|
return { id, kind, title, href };
|
|
332
360
|
}
|
|
361
|
+
/** What `station join` says when the room records nobody as this agent's
|
|
362
|
+
* person: a sign-in link for them. Whoever opens it, with an account or
|
|
363
|
+
* only their browser, signs this computer in, and the seat becomes theirs;
|
|
364
|
+
* later agents here join as theirs from the start. */
|
|
365
|
+
export async function ownerLines(home, seat, room, me, webUrl = process.env.STATION_WEB_URL ?? DEFAULT_WEB, start = startLogin, remote = elsewhere()) {
|
|
366
|
+
if (seat.via !== "room" || !seat.roomToken)
|
|
367
|
+
return [];
|
|
368
|
+
if (room.participants.find((one) => one.id === seat.participantId)?.for)
|
|
369
|
+
return [];
|
|
370
|
+
const claim = { roomId: seat.roomId, key: seat.roomToken };
|
|
371
|
+
// A link already waiting (another seat's, or the person's own login) takes this seat too.
|
|
372
|
+
let url = addClaim(home, seat.relayUrl, claim);
|
|
373
|
+
if (url)
|
|
374
|
+
remote = Boolean(readPending(home)?.remote);
|
|
375
|
+
try {
|
|
376
|
+
url ??= (await start(home, seat.relayUrl, webUrl, false, undefined, remote, [claim])).url;
|
|
377
|
+
}
|
|
378
|
+
catch {
|
|
379
|
+
return [`Station does not know whose agent this is. For a link that makes it your person's, run: ${me} claim`];
|
|
380
|
+
}
|
|
381
|
+
return [
|
|
382
|
+
`Station does not know whose agent this is. Give this link to the person you work for, in your own chat, never the room: ${url}`,
|
|
383
|
+
"Opening it and clicking Connect makes this agent theirs and signs this computer in, so their next agents here are theirs from the start. They need no account. The link works for ten minutes.",
|
|
384
|
+
codeStep(me, remote),
|
|
385
|
+
];
|
|
386
|
+
}
|
package/dist/login.js
CHANGED
|
@@ -179,8 +179,12 @@ export async function runHelper(home, waitMs = LISTEN_MS) {
|
|
|
179
179
|
const credentials = { relayUrl: pending.relayUrl, ...site, token: answer.token, userId: answer.user_id, name: answer.name };
|
|
180
180
|
if (!mine())
|
|
181
181
|
return;
|
|
182
|
+
// Seats that joined while this link waited were added to it (join.ts).
|
|
183
|
+
const claims = readPending(home)?.claims ?? [];
|
|
182
184
|
writeJson(files(home).credentials, credentials);
|
|
183
185
|
remove(files(home).login);
|
|
186
|
+
for (const claim of claims)
|
|
187
|
+
await claimSeat(pending.relayUrl, claim, answer.token);
|
|
184
188
|
};
|
|
185
189
|
try {
|
|
186
190
|
const { port, done } = await listen(pending.state, waitMs, trade);
|
|
@@ -191,12 +195,31 @@ export async function runHelper(home, waitMs = LISTEN_MS) {
|
|
|
191
195
|
report({ error: error instanceof Error ? error.message : String(error) });
|
|
192
196
|
}
|
|
193
197
|
}
|
|
198
|
+
/** Makes a seat this computer took with no sign-in the signed-in person's:
|
|
199
|
+
* the seat asks for its claim link and the person's new token answers it.
|
|
200
|
+
* One that cannot be claimed (let go, or a private room the person cannot
|
|
201
|
+
* open) stays as it was. */
|
|
202
|
+
export async function claimSeat(relayUrl, claim, token) {
|
|
203
|
+
try {
|
|
204
|
+
const { url } = await call(relayUrl, `/${claim.roomId}/claim`, { token: claim.key }, { body: {} });
|
|
205
|
+
const code = new URL(url).searchParams.get("code");
|
|
206
|
+
const answer = await call(relayUrl, `/${claim.roomId}/claim/answer`, { token }, { body: { code, confirm: true } });
|
|
207
|
+
return answer.claimed;
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
console.error(`Could not claim the seat in room ${claim.roomId}: ${error instanceof Error ? error.message : String(error)}`);
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
194
214
|
/** Starts a sign-in: the helper listens, and this returns its link. */
|
|
195
|
-
export async function startLogin(home, relayUrl, webUrl, signUp, launch = spawnHelper, remote = false) {
|
|
215
|
+
export async function startLogin(home, relayUrl, webUrl, signUp, launch = spawnHelper, remote = false, claims = []) {
|
|
196
216
|
// A newer login replaces one still listening.
|
|
197
217
|
const before = readPending(home);
|
|
198
|
-
if (before?.pid && alive(before.pid))
|
|
218
|
+
if (before?.pid && before.pid !== process.pid && alive(before.pid))
|
|
199
219
|
process.kill(before.pid, "SIGTERM");
|
|
220
|
+
// Seats an earlier link was to make the person's stay on the new one.
|
|
221
|
+
if (before?.relayUrl === relayUrl)
|
|
222
|
+
claims = [...(before.claims ?? []).filter((one) => !claims.some((it) => it.key === one.key)), ...claims];
|
|
200
223
|
const pending = {
|
|
201
224
|
relayUrl,
|
|
202
225
|
webUrl,
|
|
@@ -206,6 +229,7 @@ export async function startLogin(home, relayUrl, webUrl, signUp, launch = spawnH
|
|
|
206
229
|
signUp,
|
|
207
230
|
startedAt: Date.now(),
|
|
208
231
|
...(remote ? { remote } : {}),
|
|
232
|
+
...(claims.length ? { claims } : {}),
|
|
209
233
|
};
|
|
210
234
|
writeJson(files(home).login, pending);
|
|
211
235
|
launch(home);
|
|
@@ -301,6 +325,17 @@ export function cancelLogin(home) {
|
|
|
301
325
|
if (pending?.pid && pending.pid !== process.pid && alive(pending.pid))
|
|
302
326
|
process.kill(pending.pid, "SIGTERM");
|
|
303
327
|
}
|
|
328
|
+
/** Adds a seat to a login still waiting for its person, so its link makes
|
|
329
|
+
* that seat theirs too; the link, or null when none is waiting. */
|
|
330
|
+
export function addClaim(home, relayUrl, claim) {
|
|
331
|
+
const pending = readPending(home);
|
|
332
|
+
const url = waitingAt(home);
|
|
333
|
+
if (!pending || !url || pending.relayUrl !== relayUrl)
|
|
334
|
+
return null;
|
|
335
|
+
const claims = [...(pending.claims ?? []).filter((one) => one.key !== claim.key), claim];
|
|
336
|
+
writeJson(files(home).login, { ...pending, claims });
|
|
337
|
+
return url;
|
|
338
|
+
}
|
|
304
339
|
/** The link of a login still waiting for the person, if there is one. */
|
|
305
340
|
export function waitingAt(home) {
|
|
306
341
|
const pending = readPending(home);
|
package/dist/mark.js
CHANGED
|
@@ -38,9 +38,28 @@ function theirs(body) {
|
|
|
38
38
|
.map((line) => (line ? `${THEIRS}${line}` : THEIRS.trimEnd()))
|
|
39
39
|
.join("\n");
|
|
40
40
|
}
|
|
41
|
+
function together(names) {
|
|
42
|
+
return names.length < 2 ? (names[0] ?? "") : `${names.slice(0, -1).join(", ")} and ${names[names.length - 1]}`;
|
|
43
|
+
}
|
|
44
|
+
/** Where a message sits, for the line's name: " [thread 12, to you and
|
|
45
|
+
* Codex]". Empty for a message in the main chat to everyone, which is
|
|
46
|
+
* how every message read before threads. A message to someone opens a
|
|
47
|
+
* thread of its own, so its line names that thread to reply in. */
|
|
48
|
+
export function whereOf(hearer, message, seats) {
|
|
49
|
+
const to = message.to ?? [];
|
|
50
|
+
const thread = message.reply_to ?? (to.length ? message.id : null);
|
|
51
|
+
if (thread === null)
|
|
52
|
+
return "";
|
|
53
|
+
const byId = new Map(seats.map((seat) => [seat.id, seat]));
|
|
54
|
+
const names = to.map((id) => (id === hearer.seat ? "you" : (byId.get(id)?.name ?? "someone who left")));
|
|
55
|
+
// "you" first: it is what the reader looks for.
|
|
56
|
+
const sorted = [...names.filter((name) => name === "you"), ...names.filter((name) => name !== "you")];
|
|
57
|
+
return ` [thread ${thread}${sorted.length ? `, to ${together(sorted)}` : ""}]`;
|
|
58
|
+
}
|
|
41
59
|
/** One message: who said it, then its whole text. From someone else, the
|
|
42
|
-
* text goes under the name with THEIRS at the start of each line.
|
|
43
|
-
|
|
60
|
+
* text goes under the name with THEIRS at the start of each line. `where`
|
|
61
|
+
* is whereOf's bracket, when the message is in a thread or to someone. */
|
|
62
|
+
export function lineOf(hearer, author, body, where = "") {
|
|
44
63
|
const name = author?.name ?? "Someone";
|
|
45
64
|
const side = sideOf(hearer, author);
|
|
46
65
|
const who = side === "you"
|
|
@@ -52,7 +71,16 @@ export function lineOf(hearer, author, body) {
|
|
|
52
71
|
: author?.kind === "agent"
|
|
53
72
|
? `${name} (an agent)`
|
|
54
73
|
: name;
|
|
55
|
-
return side === "someone else" ? `${who}:\n${theirs(body)}` : `${who}: ${body}`;
|
|
74
|
+
return side === "someone else" ? `${who}${where}:\n${theirs(body)}` : `${who}${where}: ${body}`;
|
|
75
|
+
}
|
|
76
|
+
/** What to say after messages in a thread: how to answer in it. `say` is
|
|
77
|
+
* the reader's way to post, with `{thread}` where the thread's id goes. */
|
|
78
|
+
export function threadHint(messages, say) {
|
|
79
|
+
const threads = messages.flatMap((message) => (message.reply_to ? [message.reply_to] : message.to?.length ? [message.id] : []));
|
|
80
|
+
if (!threads.length)
|
|
81
|
+
return null;
|
|
82
|
+
const example = say.replace("{thread}", String(threads[threads.length - 1]));
|
|
83
|
+
return `To answer a message marked [thread N], reply in that thread: ${example}`;
|
|
56
84
|
}
|
|
57
85
|
/** How to check with the person the agent works for. A seat a signed-in
|
|
58
86
|
* CLI made can also ask on a card in the room, which only that person can
|
package/dist/webhooks.js
CHANGED
|
@@ -34,15 +34,41 @@ export async function readSecret(prompt, input = process.stdin, output = process
|
|
|
34
34
|
text += chunk;
|
|
35
35
|
return text.trim();
|
|
36
36
|
}
|
|
37
|
-
output.write(prompt);
|
|
38
37
|
const rl = createInterface({ input, output, terminal: true });
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
// readline clears the line before it draws the question, so the question
|
|
39
|
+
// goes through readline too. After that, nothing typed is shown.
|
|
40
|
+
let muted = false;
|
|
41
|
+
rl._writeToOutput = (s) => {
|
|
42
|
+
if (!muted)
|
|
43
|
+
output.write(s);
|
|
44
|
+
};
|
|
45
|
+
const answer = new Promise((resolve) => rl.question(prompt, resolve));
|
|
46
|
+
muted = true;
|
|
47
|
+
const value = await answer;
|
|
42
48
|
rl.close();
|
|
43
49
|
output.write("\n");
|
|
44
50
|
return value.trim();
|
|
45
51
|
}
|
|
52
|
+
/** What `webhook add` says after its test send: whether it works, and if not,
|
|
53
|
+
* why, in the person's terms. */
|
|
54
|
+
export function addResult(webhook, result) {
|
|
55
|
+
const host = new URL(webhook.url).host;
|
|
56
|
+
if (result.sent) {
|
|
57
|
+
const debounce = webhook.debounce_seconds ? `, ${webhook.debounce_seconds}s after the first new message` : "";
|
|
58
|
+
return [
|
|
59
|
+
`It works: ${host} accepted a test (${result.status}).`,
|
|
60
|
+
`Webhook ${webhook.id} for "${webhook.agent}": Station posts there on ${webhook.on.join(", ")}${debounce}, at most ${webhook.wakes_per_day} times a day.`,
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
if (result.status === 401 || result.status === 403) {
|
|
64
|
+
return [
|
|
65
|
+
`It did not work: ${host} refused the key (${result.status}). Nothing was saved.`,
|
|
66
|
+
`Run the command again with the right key. For a Grok Bot routine, type Bearer, a space, then the routine's key.`,
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
const why = result.status ? `${host} answered ${result.status}.` : result.error ?? `nothing reached ${host}.`;
|
|
70
|
+
return [`It did not work: ${why} Nothing was saved.`, `Fix that, then run the command again.`];
|
|
71
|
+
}
|
|
46
72
|
export function webhookLines(hooks) {
|
|
47
73
|
if (!hooks.length)
|
|
48
74
|
return ["No webhooks in this room."];
|
|
@@ -76,7 +102,7 @@ ${me} webhook remove <room> <webhook id>`;
|
|
|
76
102
|
const headerName = flag("header-name");
|
|
77
103
|
let header;
|
|
78
104
|
if (headerName) {
|
|
79
|
-
const value = await readSecret(
|
|
105
|
+
const value = await readSecret(`${headerName} header value, hidden as you type: `);
|
|
80
106
|
if (!value)
|
|
81
107
|
throw new Usage(`No value given for ${headerName}.`);
|
|
82
108
|
header = { name: headerName, value };
|
|
@@ -86,9 +112,14 @@ ${me} webhook remove <room> <webhook id>`;
|
|
|
86
112
|
const { webhook } = await call(relayUrl, base, auth, {
|
|
87
113
|
body: { participant: agent.id, url, header, on: flag("on")?.split(","), debounce_seconds: debounce === undefined ? undefined : Number(debounce.replace(/s$/, "")), wakes_per_day: wakes === undefined ? undefined : Number(wakes) },
|
|
88
114
|
});
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
115
|
+
// Send the test now, so the person learns here whether the key works. A
|
|
116
|
+
// webhook the receiver refuses is removed: it would only fail on every wake.
|
|
117
|
+
const result = await call(relayUrl, `${base}/${webhook.id}/test`, auth, { body: {} });
|
|
118
|
+
if (!result.sent)
|
|
119
|
+
await call(relayUrl, `${base}/${webhook.id}`, auth, { method: "DELETE" });
|
|
120
|
+
for (const line of addResult(webhook, result))
|
|
121
|
+
out(line);
|
|
122
|
+
return result.sent ? 0 : 1;
|
|
92
123
|
}
|
|
93
124
|
if (sub === "list") {
|
|
94
125
|
const { webhooks } = await call(relayUrl, base, auth);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@santori/station",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3",
|
|
4
4
|
"description": "Meeting rooms for your agents. They can share context with each other and work together. This CLI brings any agent into a Station room. In Claude Code and Codex, messages from the room arrive in the session on their own.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"station",
|