agent-theatre 1.1.4 → 1.2.0
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 +37 -3
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +38 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/web/assets/browserAll-MBabRn1_.js +2 -0
- package/web/assets/{browserAll-oXCedPBk.js.map → browserAll-MBabRn1_.js.map} +1 -1
- package/web/assets/{index-BcMndIlk.css → index-DUimS_fe.css} +1 -1
- package/web/assets/index-K7cJxdMz.js +956 -0
- package/web/assets/index-K7cJxdMz.js.map +1 -0
- package/web/assets/webworkerAll-tVQIHJQB.js +2 -0
- package/web/assets/{webworkerAll-BG4khe1M.js.map → webworkerAll-tVQIHJQB.js.map} +1 -1
- package/web/index.html +2 -2
- package/web/assets/browserAll-oXCedPBk.js +0 -2
- package/web/assets/index-CZ8tuB9J.js +0 -956
- package/web/assets/index-CZ8tuB9J.js.map +0 -1
- package/web/assets/webworkerAll-BG4khe1M.js +0 -2
package/dist/cli.js
CHANGED
|
@@ -9,9 +9,10 @@ import pc from "picocolors";
|
|
|
9
9
|
|
|
10
10
|
// src/server.ts
|
|
11
11
|
import { createServer } from "http";
|
|
12
|
-
import { existsSync, mkdirSync, readFileSync as readFileSync2, rmSync, writeFileSync, realpathSync } from "fs";
|
|
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 { spawn, spawnSync } from "child_process";
|
|
15
16
|
import { Hono } from "hono";
|
|
16
17
|
import { getRequestListener } from "@hono/node-server";
|
|
17
18
|
import { WebSocketServer } from "ws";
|
|
@@ -1195,6 +1196,8 @@ var Theatre = class {
|
|
|
1195
1196
|
wss = null;
|
|
1196
1197
|
live;
|
|
1197
1198
|
signal = "ok";
|
|
1199
|
+
/** The most recent Claude Code session that spoke to this stage; what a prompt from the stage resumes. */
|
|
1200
|
+
lastSessionId = null;
|
|
1198
1201
|
timer = null;
|
|
1199
1202
|
port = 0;
|
|
1200
1203
|
routes() {
|
|
@@ -1208,6 +1211,8 @@ var Theatre = class {
|
|
|
1208
1211
|
}
|
|
1209
1212
|
const cwd = typeof payload?.cwd === "string" ? payload.cwd : "";
|
|
1210
1213
|
if (cwd && !isWithin(cwd, this.opts.cwd)) return c.body(null, 204);
|
|
1214
|
+
const sid = payload.session_id;
|
|
1215
|
+
if (typeof sid === "string" && sid) this.lastSessionId = sid;
|
|
1211
1216
|
const { events } = hookPayloadToEvents(payload, { home: homedir2() });
|
|
1212
1217
|
if (events.length) this.ingest(events);
|
|
1213
1218
|
return c.body(null, 204);
|
|
@@ -1232,6 +1237,18 @@ var Theatre = class {
|
|
|
1232
1237
|
const beats = direct(events, world);
|
|
1233
1238
|
return c.json({ mode: "replay", repoId: this.opts.repoId, title: s.title, world, events, beats, warnings: warnings.length });
|
|
1234
1239
|
});
|
|
1240
|
+
a.get("/api/prompt", (c) => c.json({ available: !!claudeBinary() && !!this.lastSessionId, session: this.lastSessionId }));
|
|
1241
|
+
a.post("/api/prompt", async (c) => {
|
|
1242
|
+
const body = await c.req.json().catch(() => ({}));
|
|
1243
|
+
const text = typeof body.text === "string" ? body.text.trim() : "";
|
|
1244
|
+
const bin = claudeBinary();
|
|
1245
|
+
if (!text) return c.json({ ok: false, error: "empty prompt" }, 400);
|
|
1246
|
+
if (!bin) return c.json({ ok: false, error: "Claude Code 2.x not found on PATH" }, 503);
|
|
1247
|
+
if (!this.lastSessionId) return c.json({ ok: false, error: "no session to resume yet" }, 409);
|
|
1248
|
+
const child = spawn(bin, ["-p", "--resume", this.lastSessionId, text], { cwd: this.opts.cwd, stdio: "ignore", detached: true, env: process.env });
|
|
1249
|
+
child.unref();
|
|
1250
|
+
return c.json({ ok: true, session: this.lastSessionId });
|
|
1251
|
+
});
|
|
1235
1252
|
a.get("/healthz", (c) => c.json({ ok: true, port: this.port, events: this.live.events.length }));
|
|
1236
1253
|
if (this.opts.webDir) {
|
|
1237
1254
|
const dir = this.opts.webDir;
|
|
@@ -1325,9 +1342,26 @@ function isWithin(dir, root) {
|
|
|
1325
1342
|
const d = norm3(dir), r = norm3(root);
|
|
1326
1343
|
return d === r || d.startsWith(r.endsWith(sep) ? r : r + sep);
|
|
1327
1344
|
}
|
|
1345
|
+
function claudeBinary() {
|
|
1346
|
+
const cands = [process.env.AGENT_THEATRE_CLAUDE, "claude"].filter((x) => !!x);
|
|
1347
|
+
try {
|
|
1348
|
+
const ext = join2(homedir2(), ".vscode", "extensions");
|
|
1349
|
+
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"));
|
|
1350
|
+
} catch {
|
|
1351
|
+
}
|
|
1352
|
+
for (const c of cands) {
|
|
1353
|
+
try {
|
|
1354
|
+
const r = spawnSync(c, ["--version"], { encoding: "utf8", timeout: 4e3 });
|
|
1355
|
+
const m = /^(\d+)\./.exec(r.stdout.trim());
|
|
1356
|
+
if (r.status === 0 && m && Number(m[1]) >= 2) return c;
|
|
1357
|
+
} catch {
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
return null;
|
|
1361
|
+
}
|
|
1328
1362
|
|
|
1329
1363
|
// src/scan.ts
|
|
1330
|
-
import { readdirSync as
|
|
1364
|
+
import { readdirSync as readdirSync3, readFileSync as readFileSync3, statSync as statSync2 } from "fs";
|
|
1331
1365
|
import { join as join3, relative } from "path";
|
|
1332
1366
|
function scanRepo(root, opts = {}) {
|
|
1333
1367
|
const maxFiles = opts.maxFiles ?? 2e4, maxBytes = opts.maxBytesForLoc ?? 512e3;
|
|
@@ -1336,7 +1370,7 @@ function scanRepo(root, opts = {}) {
|
|
|
1336
1370
|
if (files.length >= maxFiles) return;
|
|
1337
1371
|
let ents;
|
|
1338
1372
|
try {
|
|
1339
|
-
ents =
|
|
1373
|
+
ents = readdirSync3(dir, { withFileTypes: true });
|
|
1340
1374
|
} catch {
|
|
1341
1375
|
return;
|
|
1342
1376
|
}
|