agent-relay-server 0.3.3 → 0.3.4
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/bin/agent-relay-codex.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
import { chmodSync, cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { appendFileSync, chmodSync, cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { dirname, join, resolve } from "node:path";
|
|
5
5
|
import { createInterface } from "node:readline/promises";
|
|
@@ -149,6 +149,15 @@ function samePath(left: string, right: string): boolean {
|
|
|
149
149
|
return process.platform === "win32" ? a.toLowerCase() === b.toLowerCase() : a === b;
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
+
function isAlive(pid: number): boolean {
|
|
153
|
+
try {
|
|
154
|
+
process.kill(pid, 0);
|
|
155
|
+
return true;
|
|
156
|
+
} catch {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
152
161
|
function candidateNames(command: string): string[] {
|
|
153
162
|
if (process.platform !== "win32") return [command];
|
|
154
163
|
const extensions = (process.env.PATHEXT || ".COM;.EXE;.BAT;.CMD;.PS1").split(";").filter(Boolean);
|
|
@@ -278,6 +287,48 @@ async function waitForPort(url: string, child: ReturnType<typeof Bun.spawn>): Pr
|
|
|
278
287
|
throw new Error(`timed out waiting for ${url}`);
|
|
279
288
|
}
|
|
280
289
|
|
|
290
|
+
async function waitForSidecarPid(runDir: string, timeoutMs: number): Promise<boolean> {
|
|
291
|
+
const pidsPath = join(runDir, "sidecar-pids.txt");
|
|
292
|
+
const deadline = Date.now() + timeoutMs;
|
|
293
|
+
|
|
294
|
+
while (Date.now() < deadline) {
|
|
295
|
+
if (existsSync(pidsPath)) {
|
|
296
|
+
for (const line of readFileSync(pidsPath, "utf8").split("\n")) {
|
|
297
|
+
const pid = Number(line.trim());
|
|
298
|
+
if (Number.isFinite(pid) && pid > 0 && isAlive(pid)) return true;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
await Bun.sleep(100);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function spawnFallbackSidecar(runDir: string, env: Record<string, string | undefined>): number {
|
|
308
|
+
const autoDir = join(runDir, "auto");
|
|
309
|
+
mkdirSync(autoDir, { recursive: true });
|
|
310
|
+
|
|
311
|
+
const sidecarEnv: Record<string, string | undefined> = {
|
|
312
|
+
...env,
|
|
313
|
+
CODEX_THREAD_MODE: "auto",
|
|
314
|
+
CODEX_LIVE_CWD: process.cwd(),
|
|
315
|
+
CODEX_LIVE_STATE_PATH: join(autoDir, "live-state.json"),
|
|
316
|
+
};
|
|
317
|
+
delete sidecarEnv.CODEX_THREAD_ID;
|
|
318
|
+
|
|
319
|
+
const sidecar = Bun.spawn(["bun", "run", join(activePackageRoot(), "codex", "live-sidecar.ts")], {
|
|
320
|
+
env: sidecarEnv,
|
|
321
|
+
stdout: Bun.file(join(autoDir, "sidecar.log")),
|
|
322
|
+
stderr: Bun.file(join(autoDir, "sidecar.log")),
|
|
323
|
+
});
|
|
324
|
+
sidecar.unref();
|
|
325
|
+
|
|
326
|
+
writeFileSync(join(autoDir, "sidecar.pid"), String(sidecar.pid));
|
|
327
|
+
appendFileSync(join(runDir, "sidecar-pids.txt"), `${sidecar.pid}\n`);
|
|
328
|
+
|
|
329
|
+
return sidecar.pid;
|
|
330
|
+
}
|
|
331
|
+
|
|
281
332
|
function cleanupRun(runDir: string, appServer: ReturnType<typeof Bun.spawn> | null): void {
|
|
282
333
|
if (existsSync(runDir)) {
|
|
283
334
|
const pidsPath = join(runDir, "sidecar-pids.txt");
|
|
@@ -482,6 +533,13 @@ async function start(args: string[]): Promise<void> {
|
|
|
482
533
|
stdout: "inherit",
|
|
483
534
|
stderr: "inherit",
|
|
484
535
|
});
|
|
536
|
+
|
|
537
|
+
const sidecarDetected = await waitForSidecarPid(runDir, 2500);
|
|
538
|
+
if (!sidecarDetected && codex.exitCode === null) {
|
|
539
|
+
const pid = spawnFallbackSidecar(runDir, env);
|
|
540
|
+
console.error(`Agent Relay: SessionStart hook did not start sidecar; started fallback sidecar pid ${pid}`);
|
|
541
|
+
}
|
|
542
|
+
|
|
485
543
|
const exitCode = await codex.exited;
|
|
486
544
|
shutdown();
|
|
487
545
|
process.exit(exitCode);
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-relay",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "Agent Relay integration for Codex sessions",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Edin Mujkanovic"
|
|
7
7
|
},
|
|
8
8
|
"repository": "https://github.com/edimuj/agent-relay",
|
|
9
9
|
"license": "MIT",
|
|
10
|
-
"keywords": [
|
|
10
|
+
"keywords": [
|
|
11
|
+
"agent-relay",
|
|
12
|
+
"multi-agent",
|
|
13
|
+
"codex"
|
|
14
|
+
],
|
|
11
15
|
"skills": "./skills/",
|
|
12
16
|
"interface": {
|
|
13
17
|
"displayName": "Agent Relay",
|
|
@@ -15,7 +19,10 @@
|
|
|
15
19
|
"longDescription": "Adds Codex-facing instructions for Agent Relay and pairs with the agent-relay-codex launcher for live incoming messages.",
|
|
16
20
|
"developerName": "Edin Mujkanovic",
|
|
17
21
|
"category": "Productivity",
|
|
18
|
-
"capabilities": [
|
|
22
|
+
"capabilities": [
|
|
23
|
+
"Read",
|
|
24
|
+
"Write"
|
|
25
|
+
],
|
|
19
26
|
"defaultPrompt": [
|
|
20
27
|
"Use Agent Relay to message another coding agent.",
|
|
21
28
|
"Check how this Codex session is connected to Agent Relay."
|