agent-theatre 1.3.7 → 1.3.8
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/dist/cli.js +1 -58
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +1 -5
- package/dist/index.js +1 -59
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/web/assets/browserAll-DQZ9DKi_.js +2 -0
- package/web/assets/{browserAll-B0tuAxkH.js.map → browserAll-DQZ9DKi_.js.map} +1 -1
- package/web/assets/{index-DcaDqrwu.js → index-7R3Kwh2s.js} +38 -38
- package/web/assets/index-7R3Kwh2s.js.map +1 -0
- package/web/assets/{index-CWrWoYA0.css → index-d1I3dd03.css} +1 -1
- package/web/assets/webworkerAll-CxPyBP1l.js +2 -0
- package/web/assets/{webworkerAll-K1SffoNh.js.map → webworkerAll-CxPyBP1l.js.map} +1 -1
- package/web/index.html +2 -2
- package/web/assets/browserAll-B0tuAxkH.js +0 -2
- package/web/assets/index-DcaDqrwu.js.map +0 -1
- package/web/assets/webworkerAll-K1SffoNh.js +0 -2
package/dist/cli.js
CHANGED
|
@@ -12,7 +12,7 @@ import { createServer } from "http";
|
|
|
12
12
|
import { existsSync, mkdirSync, readFileSync as readFileSync2, readdirSync as readdirSync2, rmSync, writeFileSync, realpathSync } from "fs";
|
|
13
13
|
import { homedir as homedir2 } from "os";
|
|
14
14
|
import { join as join2, basename as basename2, resolve, sep } from "path";
|
|
15
|
-
import {
|
|
15
|
+
import { spawnSync } from "child_process";
|
|
16
16
|
import { Hono } from "hono";
|
|
17
17
|
import { getRequestListener } from "@hono/node-server";
|
|
18
18
|
import { WebSocketServer } from "ws";
|
|
@@ -1218,8 +1218,6 @@ var Theatre = class {
|
|
|
1218
1218
|
wss = null;
|
|
1219
1219
|
live;
|
|
1220
1220
|
signal = "ok";
|
|
1221
|
-
/** The most recent Claude Code session that spoke to this stage; what a prompt from the stage resumes. */
|
|
1222
|
-
lastSessionId = null;
|
|
1223
1221
|
/** The most recent cwd of a Claude Code session that is NOT this repo (so an empty stage can point the person there). */
|
|
1224
1222
|
elsewhere = null;
|
|
1225
1223
|
openSessions = /* @__PURE__ */ new Set();
|
|
@@ -1243,7 +1241,6 @@ var Theatre = class {
|
|
|
1243
1241
|
return c.body(null, 204);
|
|
1244
1242
|
}
|
|
1245
1243
|
const sid = payload.session_id;
|
|
1246
|
-
if (typeof sid === "string" && sid) this.lastSessionId = sid;
|
|
1247
1244
|
const hookName = payload.hook_event_name;
|
|
1248
1245
|
if (typeof sid === "string" && sid) {
|
|
1249
1246
|
if (hookName === "SessionEnd") this.openSessions.delete(sid);
|
|
@@ -1274,43 +1271,6 @@ var Theatre = class {
|
|
|
1274
1271
|
const beats = direct(events, world);
|
|
1275
1272
|
return c.json({ mode: "replay", repoId: this.opts.repoId, title: s.title, world, events, beats, warnings: warnings.length });
|
|
1276
1273
|
});
|
|
1277
|
-
a.get("/api/prompt", (c) => c.json({ available: !!claudeBinary() && !!this.lastSessionId, session: this.lastSessionId }));
|
|
1278
|
-
a.post("/api/prompt", async (c) => {
|
|
1279
|
-
const body = await c.req.json().catch(() => ({}));
|
|
1280
|
-
const text = typeof body.text === "string" ? body.text.trim() : "";
|
|
1281
|
-
const bin = claudeBinary();
|
|
1282
|
-
if (!text) return c.json({ ok: false, error: "empty prompt" }, 400);
|
|
1283
|
-
if (!bin) return c.json({ ok: false, error: "Claude Code 2.x not found on PATH" }, 503);
|
|
1284
|
-
if (!this.lastSessionId) return c.json({ ok: false, error: "no session to resume yet" }, 409);
|
|
1285
|
-
const logPath = join2(this.opts.home ?? join2(homedir2(), ".agent-theatre"), "prompt.log");
|
|
1286
|
-
const child = spawn(bin, ["-p", "--resume", this.lastSessionId, text], { cwd: this.opts.cwd, stdio: ["ignore", "pipe", "pipe"], detached: true, env: process.env });
|
|
1287
|
-
let err = "";
|
|
1288
|
-
child.stdout?.on("data", (d) => {
|
|
1289
|
-
try {
|
|
1290
|
-
writeFileSync(logPath, `[${(/* @__PURE__ */ new Date()).toISOString()}] out: ${String(d).slice(0, 2e3)}
|
|
1291
|
-
`, { flag: "a" });
|
|
1292
|
-
} catch {
|
|
1293
|
-
}
|
|
1294
|
-
});
|
|
1295
|
-
child.stderr?.on("data", (d) => {
|
|
1296
|
-
err += String(d);
|
|
1297
|
-
try {
|
|
1298
|
-
writeFileSync(logPath, `[${(/* @__PURE__ */ new Date()).toISOString()}] err: ${String(d).slice(0, 2e3)}
|
|
1299
|
-
`, { flag: "a" });
|
|
1300
|
-
} catch {
|
|
1301
|
-
}
|
|
1302
|
-
});
|
|
1303
|
-
child.unref();
|
|
1304
|
-
const early = await new Promise((res) => {
|
|
1305
|
-
const t = setTimeout(() => res(null), 2500);
|
|
1306
|
-
child.once("exit", (code) => {
|
|
1307
|
-
clearTimeout(t);
|
|
1308
|
-
res(code ?? 1);
|
|
1309
|
-
});
|
|
1310
|
-
});
|
|
1311
|
-
if (early !== null && early !== 0) return c.json({ ok: false, error: `Claude Code exited ${early}: ${err.trim().split("\n").pop() ?? "see ~/.agent-theatre/prompt.log"}` }, 502);
|
|
1312
|
-
return c.json({ ok: true, session: this.lastSessionId });
|
|
1313
|
-
});
|
|
1314
1274
|
a.get("/healthz", (c) => c.json({ ok: true, port: this.port, events: this.live.events.length }));
|
|
1315
1275
|
if (this.opts.webDir) {
|
|
1316
1276
|
const dir = this.opts.webDir;
|
|
@@ -1439,23 +1399,6 @@ function isWithin(dir, root) {
|
|
|
1439
1399
|
const d = norm3(dir), r = norm3(root);
|
|
1440
1400
|
return d === r || d.startsWith(r.endsWith(sep) ? r : r + sep);
|
|
1441
1401
|
}
|
|
1442
|
-
function claudeBinary() {
|
|
1443
|
-
const cands = [process.env.AGENT_THEATRE_CLAUDE, "claude"].filter((x) => !!x);
|
|
1444
|
-
try {
|
|
1445
|
-
const ext = join2(homedir2(), ".vscode", "extensions");
|
|
1446
|
-
for (const d of (existsSync(ext) ? readdirSync2(ext) : []).filter((n) => n.startsWith("anthropic.claude-code-")).sort().reverse()) cands.push(join2(ext, d, "resources", "native-binary", "claude"));
|
|
1447
|
-
} catch {
|
|
1448
|
-
}
|
|
1449
|
-
for (const c of cands) {
|
|
1450
|
-
try {
|
|
1451
|
-
const r = spawnSync(c, ["--version"], { encoding: "utf8", timeout: 4e3 });
|
|
1452
|
-
const m = /^(\d+)\./.exec(r.stdout.trim());
|
|
1453
|
-
if (r.status === 0 && m && Number(m[1]) >= 2) return c;
|
|
1454
|
-
} catch {
|
|
1455
|
-
}
|
|
1456
|
-
}
|
|
1457
|
-
return null;
|
|
1458
|
-
}
|
|
1459
1402
|
function portAlive(port) {
|
|
1460
1403
|
const r = spawnSync("lsof", ["-nP", `-iTCP:${port}`, "-sTCP:LISTEN", "-t"], { encoding: "utf8", timeout: 2e3 });
|
|
1461
1404
|
if (r.status === 0 && r.stdout.trim()) return true;
|