@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/dist/starts.js
CHANGED
|
@@ -16,7 +16,7 @@ import { createHash, randomUUID } from "node:crypto";
|
|
|
16
16
|
import { existsSync } from "node:fs";
|
|
17
17
|
import { files, readJson, writeJson } from "./home.js";
|
|
18
18
|
import { fromMessage } from "./limits.js";
|
|
19
|
-
import {
|
|
19
|
+
import { findProgram, programName } from "./programs.js";
|
|
20
20
|
export const startsFile = (home) => `${files(home).seats.replace(/seats\.json$/, "")}starts.json`;
|
|
21
21
|
const keyOf = (agent, room) => `${agent}:${room}`;
|
|
22
22
|
export function loadStarts(home) {
|
|
@@ -43,8 +43,6 @@ export function planFor(home, wake, kind, cwd) {
|
|
|
43
43
|
const known = loadStarts(home)[keyOf(wake.agent.id, wake.room)];
|
|
44
44
|
if (known && existsSync(known.cwd))
|
|
45
45
|
return known;
|
|
46
|
-
if (!cwd || !existsSync(cwd))
|
|
47
|
-
return null;
|
|
48
46
|
return { kind, session: startedSessionId(wake.agent.id, wake.room), cwd, resume: null };
|
|
49
47
|
}
|
|
50
48
|
/** What the started agent is told: the ask, then how to answer it with
|
|
@@ -111,6 +109,8 @@ export function claudeArgs(plan, server, prompt, sessionId) {
|
|
|
111
109
|
"acceptEdits",
|
|
112
110
|
"--allowedTools",
|
|
113
111
|
"mcp__station",
|
|
112
|
+
// --allowedTools takes many values: without --, claude reads the prompt as one of them and starts with none.
|
|
113
|
+
"--",
|
|
114
114
|
prompt,
|
|
115
115
|
];
|
|
116
116
|
}
|
|
@@ -119,10 +119,10 @@ export function claudeArgs(plan, server, prompt, sessionId) {
|
|
|
119
119
|
export function startAgent(plan, wake, relayUrl, server, options = {}) {
|
|
120
120
|
const env = options.env ?? process.env;
|
|
121
121
|
const log = options.log ?? (() => { });
|
|
122
|
-
const program = plan.kind
|
|
123
|
-
const executable =
|
|
122
|
+
const program = programName(plan.kind);
|
|
123
|
+
const executable = findProgram(plan.kind, env);
|
|
124
124
|
if (!executable)
|
|
125
|
-
return Promise.resolve({ code: null, why: `${program} is not on this computer
|
|
125
|
+
return Promise.resolve({ code: null, why: `${program} is not on this computer: not on PATH or in its app`, limit: null, resume: plan.resume });
|
|
126
126
|
const prompt = startPrompt(wake, relayUrl);
|
|
127
127
|
const claudeSession = plan.resume ?? randomUUID();
|
|
128
128
|
const args = plan.kind === "codex" ? codexArgs(plan, server, prompt) : claudeArgs(plan, server, prompt, claudeSession);
|
package/dist/tool.js
CHANGED
|
@@ -82,10 +82,12 @@ function sessionSeat(home) {
|
|
|
82
82
|
function textOf(result) {
|
|
83
83
|
return (result.content ?? []).map((part) => (part.type === "text" ? part.text : "")).join("\n");
|
|
84
84
|
}
|
|
85
|
+
/** The 5 tools `station mcp` gives an agent's app. A shell has commands instead. */
|
|
86
|
+
const MCP_TOOLS = ["wait", "send", "get", "list", "mutate"];
|
|
85
87
|
/** Old tool names, still run as the new ones (the relay's OLD_TOOLS in mcp.ts). */
|
|
86
88
|
const OLD_TOOLS = { ask_take: "task_take", ask_release: "task_release", ask_done: "task_done" };
|
|
87
89
|
/** Runs `station tool ...`: 0 when the tool answered, 1 when it refused. */
|
|
88
|
-
export async function toolCommand({ home, args, out, me, tools = stationTools(home), seat = () => sessionSeat(home) }) {
|
|
90
|
+
export async function toolCommand({ home, args, out, me, tools = stationTools(home), seat = () => sessionSeat(home), signedIn = true }) {
|
|
89
91
|
const { given, rest } = toolFlags(args);
|
|
90
92
|
const [name, ...extra] = rest;
|
|
91
93
|
const mine = seat();
|
|
@@ -101,8 +103,12 @@ export async function toolCommand({ home, args, out, me, tools = stationTools(ho
|
|
|
101
103
|
}
|
|
102
104
|
// Names from before a taken message was called a task, as older wake prompts give them.
|
|
103
105
|
const tool = listed.find((one) => one.name === (OLD_TOOLS[name] ?? name));
|
|
104
|
-
if (!tool)
|
|
105
|
-
|
|
106
|
+
if (!tool) {
|
|
107
|
+
const why = MCP_TOOLS.includes(name)
|
|
108
|
+
? ` ${name} is one of the 5 tools an agent's app gets over MCP. In a shell: ${me} say, ${me} read, ${me} rooms, and each of mutate's actions is a command by its 2 words, such as ${me} task take.`
|
|
109
|
+
: signedIn ? "" : ` This computer is not signed in to Station, and the tools for your person's rooms, invites and teams come with sign-in: ${me} signup --email <their email>.`;
|
|
110
|
+
throw new Usage(`Station has no tool called ${name}.${why} It has: ${listed.map((one) => one.name).join(", ")}.`);
|
|
111
|
+
}
|
|
106
112
|
if (given.has("help")) {
|
|
107
113
|
for (const line of toolHelp(me, tool))
|
|
108
114
|
out(line);
|
package/dist/usage.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* the CLI prints it and exits 2, and an MCP tool returns it as its error. */
|
|
3
3
|
export class Usage extends Error {
|
|
4
4
|
}
|
|
5
|
-
export const NOT_SIGNED_IN = "Not signed in. Ask your person which email to use, then run station signup --email <their email>.
|
|
5
|
+
export const NOT_SIGNED_IN = "Not signed in. Ask your person which email to use, then run station signup --email <their email>. A new address signs this computer in at once, and they confirm using Station's email. An address with an account gets a link to give them.";
|
package/dist/waking.js
CHANGED
|
@@ -21,8 +21,10 @@
|
|
|
21
21
|
//
|
|
22
22
|
// One run at a time for each agent in each room: a wake that comes while
|
|
23
23
|
// one runs waits for it.
|
|
24
|
-
import { rmSync, writeFileSync } from "node:fs";
|
|
24
|
+
import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
25
25
|
import { join } from "node:path";
|
|
26
|
+
import { claudeHome, lastFolder as lastClaudeFolder } from "./claude.js";
|
|
27
|
+
import { codexHome, lastFolder } from "./codex.js";
|
|
26
28
|
import { readCredentials, readJson, writeJson } from "./home.js";
|
|
27
29
|
import { agentLimit, describeLimit } from "./limits.js";
|
|
28
30
|
import { call, RelayError } from "./relay.js";
|
|
@@ -64,9 +66,24 @@ export function createWaking(deps) {
|
|
|
64
66
|
const { home, log } = deps;
|
|
65
67
|
const start = deps.start ?? startAgent;
|
|
66
68
|
const limitOf = deps.limitOf ?? ((harness, id) => agentLimit(harness, id));
|
|
67
|
-
const deliver = deps.deliver ?? deliverTo;
|
|
68
|
-
const isOpen = deps.isOpen ?? ((seat) => delivers(seat.harness) && isRunning(seat.harness, seat.sessionId));
|
|
69
|
+
const deliver = deps.deliver ?? ((chat, messageId, text) => deliverTo(chat.harness, chat.sessionId, messageId, text, chat.codexHome));
|
|
70
|
+
const isOpen = deps.isOpen ?? ((seat) => delivers(seat.harness) && isRunning(seat.harness, seat.sessionId, seat.codexHome));
|
|
69
71
|
const sleep = deps.wait ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
72
|
+
const ownFolder = deps.ownFolder ?? ((kind) => (kind === "codex" ? lastFolder(codexHome()) : lastClaudeFolder(claudeHome())));
|
|
73
|
+
/** Where a run of its own starts: the folder the agent last worked in
|
|
74
|
+
* here (its seat in this room, else its newest), the one `station add`
|
|
75
|
+
* ran in, or where the agent last worked by its own records. With none
|
|
76
|
+
* of those (no window of it joined from this computer and no `station
|
|
77
|
+
* add` here), a folder Station keeps for it, so an ask is never lost for
|
|
78
|
+
* want of a folder. */
|
|
79
|
+
function startFolder(kind, wake) {
|
|
80
|
+
const known = [lastSession(deps.seats(), wake.agent.id, wake.room)?.cwd, folderOf(home, wake.agent.id), ownFolder(kind)].find((dir) => Boolean(dir) && existsSync(dir));
|
|
81
|
+
if (known)
|
|
82
|
+
return known;
|
|
83
|
+
const own = join(home, "work", kind);
|
|
84
|
+
mkdirSync(own, { recursive: true });
|
|
85
|
+
return own;
|
|
86
|
+
}
|
|
70
87
|
/** Runs under way, by agent and room. */
|
|
71
88
|
const runs = new Map();
|
|
72
89
|
/** The asks being started or waiting to be, by agent, room and message. */
|
|
@@ -103,7 +120,19 @@ export function createWaking(deps) {
|
|
|
103
120
|
}
|
|
104
121
|
}
|
|
105
122
|
}
|
|
106
|
-
|
|
123
|
+
async function answer(credentials, wake, outcome, why) {
|
|
124
|
+
const send = () => call(credentials.relayUrl, "/cli/wakes", { token: credentials.token }, { body: { room: wake.room, message: wake.message, agent: wake.agent.id, outcome, ...(why ? { why } : {}) } });
|
|
125
|
+
try {
|
|
126
|
+
await send().catch((error) => {
|
|
127
|
+
if (outcome === "started" && error instanceof RelayError && error.status === 0)
|
|
128
|
+
return send();
|
|
129
|
+
throw error;
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
log(`wake ${wake.message} answer ${outcome} not sent: ${error instanceof Error ? error.message : String(error)}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
107
136
|
/** Out of usage, by the agent's newest session here, or the room's earlier start. */
|
|
108
137
|
function outOfUsage(kind, wake) {
|
|
109
138
|
const sessions = [];
|
|
@@ -130,15 +159,18 @@ export function createWaking(deps) {
|
|
|
130
159
|
// The agent's last chat, closed: the ask continues that same chat in the
|
|
131
160
|
// background, so it is there when the person opens it. Else a run of its own.
|
|
132
161
|
const folder = last?.cwd ?? folderOf(home, wake.agent.id);
|
|
133
|
-
|
|
134
|
-
//
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
162
|
+
let plan;
|
|
163
|
+
// A chat whose folder is gone (a removed worktree) cannot go on there: a run of its own instead.
|
|
164
|
+
const continues = last && folder && existsSync(folder) ? last : null;
|
|
165
|
+
if (continues && folder)
|
|
166
|
+
plan = { kind, session: continues.sessionId, cwd: folder, resume: continues.sessionId };
|
|
167
|
+
else {
|
|
168
|
+
const fresh = planFor(home, wake, kind, startFolder(kind, wake));
|
|
169
|
+
// One agent, one presence in a room: a run of its own acts as the agent's
|
|
170
|
+
// seat there that no session holds now (a codex exec that ended, a closed
|
|
171
|
+
// window), so it takes that seat back rather than a second one.
|
|
172
|
+
const there = deps.seats().find((seat) => seat.agentId === wake.agent.id && seat.roomId === wake.room && !isOpen(seat) && seat.sessionId !== fresh.session);
|
|
173
|
+
plan = there ? { ...fresh, session: there.sessionId } : fresh;
|
|
142
174
|
}
|
|
143
175
|
let seat;
|
|
144
176
|
try {
|
|
@@ -182,7 +214,7 @@ export function createWaking(deps) {
|
|
|
182
214
|
rmSync(tokenFile, { force: true });
|
|
183
215
|
deps.leave(seat);
|
|
184
216
|
if (end.code === 0) {
|
|
185
|
-
if (!
|
|
217
|
+
if (!continues)
|
|
186
218
|
saveStart(home, wake.agent.id, wake.room, { ...plan, resume: end.resume });
|
|
187
219
|
return;
|
|
188
220
|
}
|
|
@@ -243,20 +275,23 @@ export function createWaking(deps) {
|
|
|
243
275
|
* False when the chat closed meanwhile: the ask then continues it in the background. */
|
|
244
276
|
async function intoWindow(credentials, wake, chat) {
|
|
245
277
|
let told = false;
|
|
278
|
+
const messageId = `station-ask-${wake.room}-${wake.message}`;
|
|
279
|
+
const started = async () => {
|
|
280
|
+
log(`wake ${wake.message}: put into ${wake.agent.name}'s open chat ${chat.sessionId}`);
|
|
281
|
+
await answer(credentials, wake, "started");
|
|
282
|
+
return true;
|
|
283
|
+
};
|
|
246
284
|
for (let attempt = 0; attempt < 120 && isOpen(chat); attempt++) {
|
|
247
|
-
const outcome = await deliver(chat
|
|
248
|
-
if (outcome.kind !== "retry")
|
|
249
|
-
|
|
250
|
-
await answer(credentials, wake, "started");
|
|
251
|
-
return true;
|
|
252
|
-
}
|
|
285
|
+
const outcome = await deliver(chat, messageId, startPrompt(wake, credentials.relayUrl, false));
|
|
286
|
+
if (outcome.kind !== "retry")
|
|
287
|
+
return started();
|
|
253
288
|
if (!told) {
|
|
254
289
|
told = true;
|
|
255
290
|
await answer(credentials, wake, "queued");
|
|
256
291
|
}
|
|
257
292
|
await sleep(15_000);
|
|
258
293
|
}
|
|
259
|
-
return false;
|
|
294
|
+
return await deps.releaseAsk?.(chat, messageId) ? started() : false;
|
|
260
295
|
}
|
|
261
296
|
return {
|
|
262
297
|
/** Whether any install on this computer is on: the daemon stays up for it. */
|
package/dist/webhooks.js
CHANGED
|
@@ -141,3 +141,10 @@ Without --agent: the agent of this session's seat.`;
|
|
|
141
141
|
}
|
|
142
142
|
throw new Usage(usage);
|
|
143
143
|
}
|
|
144
|
+
/** `station webhook offer`, from a cloud agent's own seat: it gives Station
|
|
145
|
+
* the address that starts it, and prints the 1 link its person connects it
|
|
146
|
+
* with. The key goes in on that page; this session never handles it. */
|
|
147
|
+
export async function offerWebhook(relayUrl, auth, roomId, url, headerName) {
|
|
148
|
+
const { link, message } = await call(relayUrl, `/${roomId}/webhook`, auth, { body: { url, ...(headerName ? { header_name: headerName } : {}) } });
|
|
149
|
+
return [link, message];
|
|
150
|
+
}
|
package/hook/hook.mjs
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Station's Claude Code and Codex hook. `station join` copies this file to
|
|
3
|
+
// ~/.station/hook.mjs once the person allowed hooks on this computer, and
|
|
4
|
+
// Claude Code runs it by Node's absolute path, with the hook's event as
|
|
5
|
+
// JSON on stdin and the daemon's socket as an argument.
|
|
6
|
+
//
|
|
7
|
+
// It holds no state. It asks the daemon, which owns the seats, their
|
|
8
|
+
// cursors and the receipts, and carries back what the daemon gives it:
|
|
9
|
+
//
|
|
10
|
+
// - UserPromptSubmit, PostToolUse: new room messages for this session's
|
|
11
|
+
// seats, the people's own words, as additionalContext between steps;
|
|
12
|
+
// - Stop (run with asyncRewake, in the background): waits on the daemon
|
|
13
|
+
// until something comes for the session, then exits 2 with it on stderr,
|
|
14
|
+
// which wakes the idle session;
|
|
15
|
+
// - Codex Stop: a short synchronous check for messages before the turn ends;
|
|
16
|
+
// - SessionEnd: tells the daemon the session ended.
|
|
17
|
+
//
|
|
18
|
+
// It never stops Claude Code: any failure exits 0 and goes to hook.log
|
|
19
|
+
// next to this file. STATION_HOOKS=off in Claude Code's environment turns
|
|
20
|
+
// it off for that process. Under any other agent that reads Claude Code's
|
|
21
|
+
// hooks (Grok Build) it does nothing. Plain Node 20+, no packages.
|
|
22
|
+
import { appendFileSync } from "node:fs";
|
|
23
|
+
import { connect } from "node:net";
|
|
24
|
+
import { dirname, join, resolve as absolute } from "node:path";
|
|
25
|
+
import { fileURLToPath } from "node:url";
|
|
26
|
+
|
|
27
|
+
/** The hook and the daemon agree on this; a daemon that does not answers with an error and the hook does nothing. */
|
|
28
|
+
const PROTOCOL = 1;
|
|
29
|
+
const HOME = dirname(fileURLToPath(import.meta.url));
|
|
30
|
+
const SOCKET = process.argv[2] || join(HOME, "daemon.sock");
|
|
31
|
+
const CODEX = process.argv[3] === "codex";
|
|
32
|
+
/** How long one ask between steps may take: past it the step goes on without the messages. */
|
|
33
|
+
const STEP_MS = 1500;
|
|
34
|
+
/** One wait on the daemon. The daemon answers before this with "keep waiting". */
|
|
35
|
+
const WAIT_MS = 60_000;
|
|
36
|
+
|
|
37
|
+
const log = (line) => {
|
|
38
|
+
try {
|
|
39
|
+
appendFileSync(join(HOME, "hook.log"), `${new Date().toISOString()} ${line}\n`, { mode: 0o600 });
|
|
40
|
+
} catch {}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/** One JSON line to the daemon and its one-line answer. */
|
|
44
|
+
function ask(request, timeoutMs) {
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
const socket = connect(SOCKET);
|
|
47
|
+
let buffer = "";
|
|
48
|
+
const timer = setTimeout(() => {
|
|
49
|
+
socket.destroy();
|
|
50
|
+
reject(new Error("the daemon did not answer in time"));
|
|
51
|
+
}, timeoutMs);
|
|
52
|
+
// Claude Code's profile, where the daemon finds whether this session still runs.
|
|
53
|
+
socket.on("connect", () => socket.write(`${JSON.stringify({ ...request, v: PROTOCOL, ...(CODEX ? {} : { configDir: process.env.CLAUDE_CONFIG_DIR ? absolute(process.env.CLAUDE_CONFIG_DIR) : "" }) })}\n`));
|
|
54
|
+
socket.on("data", (chunk) => {
|
|
55
|
+
buffer += chunk.toString("utf8");
|
|
56
|
+
const end = buffer.indexOf("\n");
|
|
57
|
+
if (end < 0) return;
|
|
58
|
+
clearTimeout(timer);
|
|
59
|
+
socket.end();
|
|
60
|
+
try {
|
|
61
|
+
resolve(JSON.parse(buffer.slice(0, end)));
|
|
62
|
+
} catch (error) {
|
|
63
|
+
reject(error);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
socket.on("error", (error) => {
|
|
67
|
+
clearTimeout(timer);
|
|
68
|
+
reject(error);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const write = (stream, text) => new Promise((resolve) => stream.write(text, () => resolve()));
|
|
74
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
75
|
+
|
|
76
|
+
async function main() {
|
|
77
|
+
if ((process.env.STATION_HOOKS ?? "").toLowerCase() === "off") return 0;
|
|
78
|
+
// Grok Build runs the hooks in Claude Code's settings too, and waits on
|
|
79
|
+
// Stop at the end of each turn. It sets GROK_HOOK_EVENT on every hook it
|
|
80
|
+
// runs, after the entry's own env. CLAUDE_PROJECT_DIR is no sign of
|
|
81
|
+
// Claude Code: Grok sets it as well.
|
|
82
|
+
if (process.env.GROK_HOOK_EVENT) return 0;
|
|
83
|
+
let input = "";
|
|
84
|
+
for await (const chunk of process.stdin) input += chunk;
|
|
85
|
+
const event = JSON.parse(input);
|
|
86
|
+
// Inside a subagent the context would go to the subagent, not to the agent that holds the seat.
|
|
87
|
+
if (!event || typeof event !== "object" || event.agent_id) return 0;
|
|
88
|
+
const name = event.hook_event_name;
|
|
89
|
+
const sessionId = typeof event.session_id === "string" ? event.session_id : "";
|
|
90
|
+
if (!sessionId) return 0;
|
|
91
|
+
|
|
92
|
+
if (CODEX) {
|
|
93
|
+
if (!["UserPromptSubmit", "PostToolUse", "Stop"].includes(name) || typeof event.turn_id !== "string" || !event.turn_id) return 0;
|
|
94
|
+
const stopHookActive = name === "Stop" && event.stop_hook_active === true;
|
|
95
|
+
const answer = await ask({ op: "codexHook", sessionId: sessionId.toLowerCase(), event: name, turnId: event.turn_id, stopHookActive }, STEP_MS);
|
|
96
|
+
if (!answer.ok) {
|
|
97
|
+
log(`${name}: ${answer.error}`);
|
|
98
|
+
return 0;
|
|
99
|
+
}
|
|
100
|
+
if (stopHookActive || !answer.text || !answer.token) return 0;
|
|
101
|
+
const output = name === "Stop"
|
|
102
|
+
? { decision: "block", reason: answer.text }
|
|
103
|
+
: { hookSpecificOutput: { hookEventName: name, additionalContext: answer.text } };
|
|
104
|
+
await write(process.stdout, `${JSON.stringify(output)}\n`);
|
|
105
|
+
if (name === "Stop") return 0;
|
|
106
|
+
await ask({ op: "hookRead", harness: "codex", sessionId: sessionId.toLowerCase(), token: answer.token }, STEP_MS).catch((error) => log(`${name} receipt: ${error.message}`));
|
|
107
|
+
return 0;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (name === "UserPromptSubmit" || name === "PostToolUse" || name === "PostToolBatch") {
|
|
111
|
+
const answer = await ask({ op: "hook", sessionId, event: name }, STEP_MS);
|
|
112
|
+
if (!answer.ok) {
|
|
113
|
+
log(`${name}: ${answer.error}`);
|
|
114
|
+
return 0;
|
|
115
|
+
}
|
|
116
|
+
if (!answer.text || !answer.token) return 0;
|
|
117
|
+
await write(process.stdout, `${JSON.stringify({ hookSpecificOutput: { hookEventName: name, additionalContext: answer.text } })}\n`);
|
|
118
|
+
await ask({ op: "hookRead", sessionId, token: answer.token }, STEP_MS).catch((error) => log(`${name} receipt: ${error.message}`));
|
|
119
|
+
return 0;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (name === "SessionEnd") {
|
|
123
|
+
await ask({ op: "hook", sessionId, event: name }, STEP_MS).catch(() => {});
|
|
124
|
+
return 0;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (name !== "Stop") return 0;
|
|
128
|
+
// Waits in the background until something comes for this session. A
|
|
129
|
+
// daemon that restarts is waited for a little; one that is gone ends it.
|
|
130
|
+
let failures = 0;
|
|
131
|
+
// Asked again, it says nothing of the turn: the person may have typed since.
|
|
132
|
+
let again = false;
|
|
133
|
+
for (;;) {
|
|
134
|
+
let answer;
|
|
135
|
+
try {
|
|
136
|
+
answer = await ask({ op: "hookWait", sessionId, ...(again ? { again } : {}) }, WAIT_MS + 5_000);
|
|
137
|
+
again = true;
|
|
138
|
+
failures = 0;
|
|
139
|
+
} catch (error) {
|
|
140
|
+
// No daemon has answered this hook yet: there is none to wait for, and
|
|
141
|
+
// `claude -p` waits on this hook before it exits.
|
|
142
|
+
if (!again || ++failures > 6) {
|
|
143
|
+
log(`Stop: stopped waiting: ${error.message}`);
|
|
144
|
+
return 0;
|
|
145
|
+
}
|
|
146
|
+
await sleep(5_000);
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (!answer.ok) {
|
|
150
|
+
log(`Stop: ${answer.error}`);
|
|
151
|
+
return 0;
|
|
152
|
+
}
|
|
153
|
+
if (answer.wait) continue;
|
|
154
|
+
if (!answer.text || !answer.token) return 0;
|
|
155
|
+
await write(process.stderr, `${answer.text}\n`);
|
|
156
|
+
await ask({ op: "hookRead", sessionId, token: answer.token }, STEP_MS).catch((error) => log(`Stop receipt: ${error.message}`));
|
|
157
|
+
// Exit 2 from an asyncRewake Stop hook wakes the session with stderr.
|
|
158
|
+
return 2;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
process.on("SIGTERM", () => process.exit(0));
|
|
163
|
+
main().then(
|
|
164
|
+
(code) => process.exit(code),
|
|
165
|
+
(error) => {
|
|
166
|
+
log(`failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
167
|
+
process.exit(0);
|
|
168
|
+
},
|
|
169
|
+
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@santori/station",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.12",
|
|
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",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
25
25
|
"dist",
|
|
26
|
+
"hook",
|
|
26
27
|
"README.md"
|
|
27
28
|
],
|
|
28
29
|
"engines": {
|