@santori/station 0.9.11 → 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 +14 -7
- package/dist/agents.js +10 -13
- package/dist/args.js +1 -1
- package/dist/claude.js +68 -1
- package/dist/cli.js +96 -57
- package/dist/codex.js +42 -0
- package/dist/commands.js +18 -2
- package/dist/daemon.js +246 -70
- package/dist/frame.js +9 -6
- package/dist/home.js +1 -1
- package/dist/hooks.js +62 -25
- package/dist/join.js +92 -48
- package/dist/login.js +7 -4
- package/dist/mark.js +38 -13
- package/dist/mcp.js +6 -3
- package/dist/relay.js +1 -1
- package/dist/rooms.js +7 -6
- package/dist/seats.js +1 -1
- package/dist/sessions.js +42 -8
- package/dist/signup.js +35 -7
- package/dist/tool.js +1 -1
- package/dist/usage.js +1 -1
- package/dist/waking.js +12 -8
- package/dist/webhooks.js +7 -0
- package/hook/hook.mjs +23 -3
- package/package.json +1 -1
package/dist/relay.js
CHANGED
|
@@ -36,7 +36,7 @@ export async function call(base, path, auth, init = {}) {
|
|
|
36
36
|
}
|
|
37
37
|
let response;
|
|
38
38
|
try {
|
|
39
|
-
response = await fetchAsCaller(`${base}${path}`, { method: init.method ?? (body ? "POST" : "GET"), headers, body });
|
|
39
|
+
response = await fetchAsCaller(`${base}${path}`, { method: init.method ?? (body ? "POST" : "GET"), headers, body, signal: init.signal });
|
|
40
40
|
}
|
|
41
41
|
catch (error) {
|
|
42
42
|
const why = error instanceof Error ? error.message : String(error);
|
package/dist/rooms.js
CHANGED
|
@@ -61,13 +61,14 @@ export async function openRoom(credentials, options = {}, connect = connectTo) {
|
|
|
61
61
|
export function roomPage(credentials, roomId) {
|
|
62
62
|
return `${credentials?.webUrl ?? DEFAULT_WEB}/b/${roomId}`;
|
|
63
63
|
}
|
|
64
|
-
/** What `station new` prints: the room
|
|
65
|
-
*
|
|
64
|
+
/** What `station new` prints: the room and its page. No paste line: at
|
|
65
|
+
* setup it named an address only this computer can reach, and agents gave it
|
|
66
|
+
* to their person as a step (real runs, Nov 28). Bringing an agent in has
|
|
67
|
+
* its own way (the join's tags, the bring recipe). */
|
|
66
68
|
export function openedLines(opened) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return lines;
|
|
69
|
+
// A private room's page carries its watch code (the relay's watchLink.ts): it opens for the person with no sign-in, so it is theirs alone.
|
|
70
|
+
const page = opened.is_public ? `Its page: ${opened.page}` : `Its page, for your person only (it opens the room with no sign-in): ${opened.page}`;
|
|
71
|
+
return [`Opened a ${opened.is_public ? "public" : "private"} room: ${opened.url}`, page];
|
|
71
72
|
}
|
|
72
73
|
/** A room named by its URL or its id. An id alone is on this computer's
|
|
73
74
|
* relay (the one it signed in to), else Station's. */
|
package/dist/seats.js
CHANGED
|
@@ -32,7 +32,7 @@ export function keepAgentSeat(seatsPath, seat) {
|
|
|
32
32
|
export function authFor(seat, credentials) {
|
|
33
33
|
const token = seat.via === "room" ? seat.roomToken : credentials?.relayUrl === seat.relayUrl ? credentials.token : null;
|
|
34
34
|
if (!token)
|
|
35
|
-
throw new RelayError(401, "This computer is not signed in to this room's relay. Run station
|
|
35
|
+
throw new RelayError(401, "This computer is not signed in to this room's relay. Run station signup --email <their email>, then station join again.");
|
|
36
36
|
return { token, participant: seat.participantId };
|
|
37
37
|
}
|
|
38
38
|
/** The calling session's seat: the one in `room` when given (a room URL,
|
package/dist/sessions.js
CHANGED
|
@@ -76,6 +76,13 @@ const NOT_AN_AGENT = new Set(["sh", "bash", "zsh", "fish", "dash", "ksh", "tcsh"
|
|
|
76
76
|
* lowercase. A program name only, never a path. Null when none is found.
|
|
77
77
|
* caller.ts cleans it before it is sent. */
|
|
78
78
|
export function agentProgram(from = process.ppid, ps = systemPs) {
|
|
79
|
+
// One process has one tree: the join and the User-Agent (caller.ts) both ask.
|
|
80
|
+
if (ps === systemPs && from === process.ppid)
|
|
81
|
+
return (ownProgram ??= { name: programAbove(from, ps) }).name;
|
|
82
|
+
return programAbove(from, ps);
|
|
83
|
+
}
|
|
84
|
+
let ownProgram;
|
|
85
|
+
function programAbove(from, ps) {
|
|
79
86
|
for (const pid of ancestry(from, ps)) {
|
|
80
87
|
const name = ps(pid, "comm")?.split("/").pop()?.replace(/^-/, "").toLowerCase();
|
|
81
88
|
// A runner that renames itself shows its title, such as npx's
|
|
@@ -85,30 +92,57 @@ export function agentProgram(from = process.ppid, ps = systemPs) {
|
|
|
85
92
|
}
|
|
86
93
|
return null;
|
|
87
94
|
}
|
|
95
|
+
export const PROGRAMS = {
|
|
96
|
+
// Devin's process is devin-remote-<version>, cut to 15 characters on Linux ("devin-remote-0.").
|
|
97
|
+
devin: { name: "Devin", programs: [], prefix: "devin-remote" },
|
|
98
|
+
// Cursor sets CURSOR_AGENT on its shell commands; Gemini CLI sets GEMINI_CLI (its 0.71.1 bundle, baseEnv).
|
|
99
|
+
cursor: { name: "Cursor", programs: ["cursor-agent"], env: "CURSOR_AGENT" },
|
|
100
|
+
gemini: { name: "Gemini CLI", programs: ["gemini"], env: "GEMINI_CLI" },
|
|
101
|
+
// Copilot CLI's own process is named MainThread, so only the COPILOT_CLI its shells carry finds it (env read inside Copilot CLI 1.0.116's bash tool, #409).
|
|
102
|
+
copilot: { name: "Copilot", programs: [], env: "COPILOT_CLI" },
|
|
103
|
+
// Grok Build's process is grok: the harness matrix's Grok cells reported it (User-Agent "agent grok", 871 relay calls to Nov 25).
|
|
104
|
+
grok: { name: "Grok Build", programs: ["grok"] },
|
|
105
|
+
};
|
|
106
|
+
/** Which known agent program this shell runs in: the nearest program above
|
|
107
|
+
* it first, then a variable the program set. Null for any other. */
|
|
108
|
+
export function shellProgram(env = process.env, program = agentProgram()) {
|
|
109
|
+
const entries = Object.entries(PROGRAMS);
|
|
110
|
+
const named = program ? entries.find(([, one]) => one.programs.includes(program) || (one.prefix !== undefined && program.startsWith(one.prefix))) : undefined;
|
|
111
|
+
return named?.[0] ?? entries.find(([, one]) => one.env && env[one.env])?.[0] ?? null;
|
|
112
|
+
}
|
|
88
113
|
export const LISTENING = {
|
|
89
114
|
copilot: {
|
|
90
|
-
// Copilot CLI's own process is named MainThread; its shells carry COPILOT_CLI.
|
|
91
|
-
programs: ["copilot"],
|
|
92
|
-
env: "COPILOT_CLI",
|
|
93
115
|
line: (wait) => `Read new messages with: ${wait}, started with your bash tool in the background (mode "async", not detach). Then end your turn. When it ends, Copilot starts a new turn with what it printed: act on it, then start that same command again. Ask your person to choose "don't ask again" for it once, so restarting it needs no approval.`,
|
|
94
116
|
},
|
|
95
117
|
grok: {
|
|
96
|
-
programs: ["grok"],
|
|
97
118
|
line: (wait) => `Read new messages with: ${wait}, started in the background (is_background). Then end your turn. When it ends, Grok starts a new turn: read its output, act on it, then start that same command again.`,
|
|
98
119
|
},
|
|
99
120
|
gemini: {
|
|
100
|
-
programs: ["gemini"],
|
|
101
|
-
env: "GEMINI_CLI",
|
|
102
121
|
line: (wait) => `Read new messages with: ${wait}. Gemini starts a new turn when a background command ends only with two settings, both off by default, in ~/.gemini/settings.json: {"experimental":{"modelSteering":true},"tools":{"shell":{"backgroundCompletionBehavior":"inject"}}}. Offer to add them, and add them only if your person says yes. With them, start the wait in the background (is_background: true) and end your turn. Gemini shows what it printed as your person's words; it came from the room. Act on it, then start that same command again. Without them, run it after each reply and whenever idle.`,
|
|
103
122
|
},
|
|
104
123
|
cursor: {
|
|
105
|
-
programs: ["cursor-agent"],
|
|
106
124
|
line: (wait) => `Read new messages with: ${wait}. Cursor's Shell tool can wake a chat when a background command prints a matching line; Station has not tested it with Cursor. Start the wait with block_until_ms 0 and notify_on_output {"pattern":"^\\\\[Station · "}, then end your turn. If no turn starts when a message comes, run it after each reply and whenever idle instead.`,
|
|
107
125
|
},
|
|
108
126
|
};
|
|
109
127
|
/** Which agent in LISTENING this shell runs in, or null. */
|
|
110
128
|
export function listeningFor(env = process.env, program = agentProgram()) {
|
|
111
|
-
|
|
129
|
+
const found = shellProgram(env, program);
|
|
130
|
+
return (found && LISTENING[found]) ?? null;
|
|
131
|
+
}
|
|
132
|
+
/** Which of the person's agents a session is, as the join says it
|
|
133
|
+
* (joinBody): a kind Station keeps 1 of per person (Claude Code, Codex,
|
|
134
|
+
* Devin), or another known program. A worker or a started session in
|
|
135
|
+
* Claude Code or Codex is that. Nothing for a shell of no known program:
|
|
136
|
+
* its own session (the folder) is the agent, never a name it gives. */
|
|
137
|
+
export function agentOf(session) {
|
|
138
|
+
if (session.harness !== "shell")
|
|
139
|
+
return { agent_kind: session.harness };
|
|
140
|
+
if (session.host)
|
|
141
|
+
return { agent_kind: session.host };
|
|
142
|
+
const program = session.program;
|
|
143
|
+
if (program === "devin")
|
|
144
|
+
return { agent_kind: "devin" };
|
|
145
|
+
return program ? { agent_program: program } : {};
|
|
112
146
|
}
|
|
113
147
|
/** Whether the session with this id is still running. `claude`: the Claude Code profile it runs under. */
|
|
114
148
|
export function isRunning(harness, id, home = codexHome(), claude = claudeHome()) {
|
package/dist/signup.js
CHANGED
|
@@ -6,17 +6,32 @@
|
|
|
6
6
|
//
|
|
7
7
|
// Run again on the same computer, it sends the email again, to a corrected
|
|
8
8
|
// address if one is given.
|
|
9
|
+
//
|
|
10
|
+
// The agent cannot know whether its person has an account, and asking them
|
|
11
|
+
// costs a question. So this is the 1 command for both: for an address with
|
|
12
|
+
// an account it prints the sign-in link `station login` would.
|
|
9
13
|
import { hostname } from "node:os";
|
|
14
|
+
import { foundHere } from "./agents.js";
|
|
10
15
|
import { readGuest } from "./guest.js";
|
|
11
16
|
import { DEFAULT_WEB, files, readCredentials, remove, writeJson } from "./home.js";
|
|
12
17
|
import { cancelLogin, claimSeat, elsewhere, loginLabel, readPending } from "./login.js";
|
|
13
|
-
import { call, siteOf } from "./relay.js";
|
|
18
|
+
import { call, RelayError, siteOf } from "./relay.js";
|
|
19
|
+
/** What the agent is told about the person's agents on this computer, or nothing with none. */
|
|
20
|
+
export function agentsLine(agents) {
|
|
21
|
+
if (!agents?.length)
|
|
22
|
+
return [];
|
|
23
|
+
const names = agents.length === 1 ? agents[0] : `${agents.slice(0, -1).join(", ")} and ${agents.at(-1)}`;
|
|
24
|
+
const one = agents.length === 1;
|
|
25
|
+
return [`${names} on this computer ${one ? "is" : "are"} your person's own agent${one ? "" : "s"} now. When ${one ? "it is" : "one is"} sent a message in your person's rooms, Station starts ${one ? "it" : "that agent"} here, in its own folder, to answer.`];
|
|
26
|
+
}
|
|
14
27
|
/** "November 26": the day the rooms lock, as the email says it. */
|
|
15
28
|
export function lockDay(locksAt) {
|
|
16
29
|
return new Date(locksAt).toLocaleDateString("en-US", { month: "long", day: "numeric", timeZone: "UTC" });
|
|
17
30
|
}
|
|
18
|
-
/** Signs the person up, saves this computer's sign-in, and returns what to
|
|
19
|
-
|
|
31
|
+
/** Signs the person up, saves this computer's sign-in, and returns what to
|
|
32
|
+
* print. An address that has an account gets `link`'s sign-in link, and so
|
|
33
|
+
* does a new one on a relay that sends no email. */
|
|
34
|
+
export async function signUp(home, relayUrl, webUrl, email, me = "station", label = loginLabel(hostname(), elsewhere()), link, agents = foundHere()) {
|
|
20
35
|
const saved = readCredentials(home);
|
|
21
36
|
// A computer already signed in here says so: the relay sends the email
|
|
22
37
|
// again for a sign-up that waits, and refuses one that has an account.
|
|
@@ -26,13 +41,26 @@ export async function signUp(home, relayUrl, webUrl, email, me = "station", labe
|
|
|
26
41
|
const guest = saved ? null : readGuest(home, relayUrl);
|
|
27
42
|
// Before the sign-up: its answer holds a new token, which a failed lookup after it would lose.
|
|
28
43
|
const web = await siteOf(relayUrl, webUrl);
|
|
29
|
-
|
|
44
|
+
let answer;
|
|
45
|
+
try {
|
|
46
|
+
answer = await call(relayUrl, "/signup", auth ?? (guest ? { token: guest.token } : null), { body: { email, label, agents } });
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
if (!link || !(error instanceof RelayError))
|
|
50
|
+
throw error;
|
|
51
|
+
const give = "Give the person you work for this link, in your own chat. This computer is signed in once they click Approve.";
|
|
52
|
+
if (error.code === "account_exists")
|
|
53
|
+
return [`${email} already has a Station account, so nothing new was made. ${give}`, ...(await link(false))];
|
|
54
|
+
if (error.code === "no_mail")
|
|
55
|
+
return [`Station cannot send email from here, so the person signs up on its site. ${give}`, ...(await link(true))];
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
30
58
|
const day = lockDay(answer.locks_at);
|
|
31
|
-
const confirm = `
|
|
59
|
+
const confirm = `Station emailed ${answer.email} a link to confirm by ${day}. Nothing waits on it: tell your person 1 time, at the end. After ${day} their rooms lock until they confirm.`;
|
|
32
60
|
const fix = `Wrong address? Run: ${me} signup --email <the right one>`;
|
|
33
61
|
const token = answer.token ?? guest?.token;
|
|
34
62
|
if (!token) {
|
|
35
|
-
return [answer.sent ? `Sent the email again, to ${answer.email}.` : `Signed up as ${answer.email}. This computer's agents can now open private rooms: ${me} new --title "<a few words>"`, confirm, fix];
|
|
63
|
+
return [answer.sent ? `Sent the email again, to ${answer.email}.` : `Signed up as ${answer.email}. This computer's agents can now open private rooms: ${me} new --title "<a few words>"`, ...agentsLine(answer.agents), confirm, fix];
|
|
36
64
|
}
|
|
37
65
|
// Seats this computer took with no sign-in were waiting on a login link to become the person's.
|
|
38
66
|
const claims = readPending(home)?.relayUrl === relayUrl ? (readPending(home)?.claims ?? []) : [];
|
|
@@ -45,5 +73,5 @@ export async function signUp(home, relayUrl, webUrl, email, me = "station", labe
|
|
|
45
73
|
remove(files(home).guest);
|
|
46
74
|
for (const claim of claims)
|
|
47
75
|
await claimSeat(relayUrl, claim, token);
|
|
48
|
-
return [`Signed up as ${answer.email}. This computer is signed in, and its agents can open private rooms now: ${me} new --title "<a few words>"`, confirm, fix];
|
|
76
|
+
return [`Signed up as ${answer.email}. This computer is signed in, and its agents can open private rooms now: ${me} new --title "<a few words>"`, ...agentsLine(answer.agents), confirm, fix];
|
|
49
77
|
}
|
package/dist/tool.js
CHANGED
|
@@ -106,7 +106,7 @@ export async function toolCommand({ home, args, out, me, tools = stationTools(ho
|
|
|
106
106
|
if (!tool) {
|
|
107
107
|
const why = MCP_TOOLS.includes(name)
|
|
108
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}
|
|
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
110
|
throw new Usage(`Station has no tool called ${name}.${why} It has: ${listed.map((one) => one.name).join(", ")}.`);
|
|
111
111
|
}
|
|
112
112
|
if (given.has("help")) {
|
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
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
// one runs waits for it.
|
|
24
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";
|
|
26
27
|
import { codexHome, lastFolder } from "./codex.js";
|
|
27
28
|
import { readCredentials, readJson, writeJson } from "./home.js";
|
|
28
29
|
import { agentLimit, describeLimit } from "./limits.js";
|
|
@@ -68,7 +69,7 @@ export function createWaking(deps) {
|
|
|
68
69
|
const deliver = deps.deliver ?? ((chat, messageId, text) => deliverTo(chat.harness, chat.sessionId, messageId, text, chat.codexHome));
|
|
69
70
|
const isOpen = deps.isOpen ?? ((seat) => delivers(seat.harness) && isRunning(seat.harness, seat.sessionId, seat.codexHome));
|
|
70
71
|
const sleep = deps.wait ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
71
|
-
const ownFolder = deps.ownFolder ?? ((kind) => (kind === "codex" ? lastFolder(codexHome()) :
|
|
72
|
+
const ownFolder = deps.ownFolder ?? ((kind) => (kind === "codex" ? lastFolder(codexHome()) : lastClaudeFolder(claudeHome())));
|
|
72
73
|
/** Where a run of its own starts: the folder the agent last worked in
|
|
73
74
|
* here (its seat in this room, else its newest), the one `station add`
|
|
74
75
|
* ran in, or where the agent last worked by its own records. With none
|
|
@@ -274,20 +275,23 @@ export function createWaking(deps) {
|
|
|
274
275
|
* False when the chat closed meanwhile: the ask then continues it in the background. */
|
|
275
276
|
async function intoWindow(credentials, wake, chat) {
|
|
276
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
|
+
};
|
|
277
284
|
for (let attempt = 0; attempt < 120 && isOpen(chat); attempt++) {
|
|
278
|
-
const outcome = await deliver(chat,
|
|
279
|
-
if (outcome.kind !== "retry")
|
|
280
|
-
|
|
281
|
-
await answer(credentials, wake, "started");
|
|
282
|
-
return true;
|
|
283
|
-
}
|
|
285
|
+
const outcome = await deliver(chat, messageId, startPrompt(wake, credentials.relayUrl, false));
|
|
286
|
+
if (outcome.kind !== "retry")
|
|
287
|
+
return started();
|
|
284
288
|
if (!told) {
|
|
285
289
|
told = true;
|
|
286
290
|
await answer(credentials, wake, "queued");
|
|
287
291
|
}
|
|
288
292
|
await sleep(15_000);
|
|
289
293
|
}
|
|
290
|
-
return false;
|
|
294
|
+
return await deps.releaseAsk?.(chat, messageId) ? started() : false;
|
|
291
295
|
}
|
|
292
296
|
return {
|
|
293
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
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// Station's Claude Code hook. `station join` copies this file to
|
|
2
|
+
// Station's Claude Code and Codex hook. `station join` copies this file to
|
|
3
3
|
// ~/.station/hook.mjs once the person allowed hooks on this computer, and
|
|
4
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
|
|
5
|
+
// JSON on stdin and the daemon's socket as an argument.
|
|
6
6
|
//
|
|
7
7
|
// It holds no state. It asks the daemon, which owns the seats, their
|
|
8
8
|
// cursors and the receipts, and carries back what the daemon gives it:
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
// - Stop (run with asyncRewake, in the background): waits on the daemon
|
|
13
13
|
// until something comes for the session, then exits 2 with it on stderr,
|
|
14
14
|
// which wakes the idle session;
|
|
15
|
+
// - Codex Stop: a short synchronous check for messages before the turn ends;
|
|
15
16
|
// - SessionEnd: tells the daemon the session ended.
|
|
16
17
|
//
|
|
17
18
|
// It never stops Claude Code: any failure exits 0 and goes to hook.log
|
|
@@ -27,6 +28,7 @@ import { fileURLToPath } from "node:url";
|
|
|
27
28
|
const PROTOCOL = 1;
|
|
28
29
|
const HOME = dirname(fileURLToPath(import.meta.url));
|
|
29
30
|
const SOCKET = process.argv[2] || join(HOME, "daemon.sock");
|
|
31
|
+
const CODEX = process.argv[3] === "codex";
|
|
30
32
|
/** How long one ask between steps may take: past it the step goes on without the messages. */
|
|
31
33
|
const STEP_MS = 1500;
|
|
32
34
|
/** One wait on the daemon. The daemon answers before this with "keep waiting". */
|
|
@@ -48,7 +50,7 @@ function ask(request, timeoutMs) {
|
|
|
48
50
|
reject(new Error("the daemon did not answer in time"));
|
|
49
51
|
}, timeoutMs);
|
|
50
52
|
// Claude Code's profile, where the daemon finds whether this session still runs.
|
|
51
|
-
socket.on("connect", () => socket.write(`${JSON.stringify({ ...request, v: PROTOCOL, configDir: process.env.CLAUDE_CONFIG_DIR ? absolute(process.env.CLAUDE_CONFIG_DIR) : "" })}\n`));
|
|
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`));
|
|
52
54
|
socket.on("data", (chunk) => {
|
|
53
55
|
buffer += chunk.toString("utf8");
|
|
54
56
|
const end = buffer.indexOf("\n");
|
|
@@ -87,6 +89,24 @@ async function main() {
|
|
|
87
89
|
const sessionId = typeof event.session_id === "string" ? event.session_id : "";
|
|
88
90
|
if (!sessionId) return 0;
|
|
89
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
|
+
|
|
90
110
|
if (name === "UserPromptSubmit" || name === "PostToolUse" || name === "PostToolBatch") {
|
|
91
111
|
const answer = await ask({ op: "hook", sessionId, event: name }, STEP_MS);
|
|
92
112
|
if (!answer.ok) {
|
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",
|