agent-theatre 1.3.1 → 1.3.3

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 CHANGED
@@ -63,7 +63,8 @@ var INSTALL = /\b(npm\s+(i|install|ci)|pnpm\s+(i|install|add)|yarn(\s+add|\s+ins
63
63
  var SEARCH = /\b(grep|rg|ag|ack|find|fd|locate)\b/;
64
64
  var READ = /^\s*(cat|head|tail|less|more|bat|wc|stat|jq)\b/;
65
65
  function argv0Of(command) {
66
- const first = command.split(/\s*(?:&&|\|\||;|\|)\s*/)[0] ?? "";
66
+ const segments = command.split(/\s*(?:&&|\|\||;|\|)\s*/);
67
+ const first = (segments.find((s) => !/^\s*(\[|test\b|!)/.test(s)) ?? segments[0] ?? "").replace(/^\s*!\s*/, "");
67
68
  const toks = first.trim().split(/\s+/).map((t) => t.replace(/^[({]+/, "")).filter(Boolean);
68
69
  let i = 0;
69
70
  while (i < toks.length && /^[A-Za-z_][A-Za-z0-9_]*=/.test(toks[i])) i++;
@@ -368,9 +369,17 @@ function hookPayloadToEvents(payload, opts = {}) {
368
369
  }
369
370
  function noteOf(text) {
370
371
  if (!text) return {};
371
- const para = text.trim().split(/\n{2,}/).filter((x) => x.trim()).pop()?.replace(/\s+/g, " ").trim() ?? "";
372
- if (!para) return {};
373
- return { note: para.length > 240 ? "\u2026" + para.slice(-239) : para };
372
+ const clean = text.replace(/```[\s\S]*?```/g, " ").replace(/`([^`]*)`/g, "$1").replace(/\[([^\]]+)\]\([^)]*\)/g, "$1").replace(/\*+|#+|>+/g, "").replace(/(^|\s)_+|_+(?=\s|$)/g, "$1").replace(/^\s*[-•\d.)]+\s+/gm, "").replace(/\s+/g, " ").trim();
373
+ if (!clean) return {};
374
+ const sentences = clean.match(/[^.!?]+[.!?]+(?=\s|$)|[^.!?]+$/g)?.map((x) => x.trim()).filter(Boolean) ?? [clean];
375
+ const questions = sentences.filter((x) => x.endsWith("?"));
376
+ let note = questions.length ? questions[questions.length - 1] : sentences[0];
377
+ if (!questions.length) for (const next of sentences.slice(1)) {
378
+ if (!/[.!?]$/.test(next) || note.length + next.length + 1 > 160) break;
379
+ note = `${note} ${next}`;
380
+ }
381
+ if (note.length > 200) note = note.slice(0, 197).replace(/\s+\S*$/, "") + "\u2026";
382
+ return { note };
374
383
  }
375
384
  var ROW_TYPES = /* @__PURE__ */ new Set(["user", "assistant", "system"]);
376
385
  var obj3 = (x) => x && typeof x === "object" ? x : {};
@@ -1204,6 +1213,8 @@ var Theatre = class {
1204
1213
  signal = "ok";
1205
1214
  /** The most recent Claude Code session that spoke to this stage; what a prompt from the stage resumes. */
1206
1215
  lastSessionId = null;
1216
+ /** The most recent cwd of a Claude Code session that is NOT this repo (so an empty stage can point the person there). */
1217
+ elsewhere = null;
1207
1218
  timer = null;
1208
1219
  port = 0;
1209
1220
  routes() {
@@ -1216,7 +1227,13 @@ var Theatre = class {
1216
1227
  return c.body(null, 204);
1217
1228
  }
1218
1229
  const cwd = typeof payload?.cwd === "string" ? payload.cwd : "";
1219
- if (cwd && !isWithin(cwd, this.opts.cwd)) return c.body(null, 204);
1230
+ if (cwd && !isWithin(cwd, this.opts.cwd)) {
1231
+ if (this.elsewhere !== cwd) {
1232
+ this.elsewhere = cwd;
1233
+ this.broadcast({ type: "elsewhere", cwd });
1234
+ }
1235
+ return c.body(null, 204);
1236
+ }
1220
1237
  const sid = payload.session_id;
1221
1238
  if (typeof sid === "string" && sid) this.lastSessionId = sid;
1222
1239
  const { events } = hookPayloadToEvents(payload, { home: homedir2() });
@@ -1229,7 +1246,7 @@ var Theatre = class {
1229
1246
  for (const [k, v] of Object.entries(cors)) c.res.headers.set(k, v);
1230
1247
  });
1231
1248
  a.options("/api/*", (c) => c.body(null, 204, cors));
1232
- a.get("/api/scene", (c) => c.json({ mode: "live", repoId: this.opts.repoId, world: this.live.world, events: this.live.events, beats: this.live.beats, signal: this.signal }));
1249
+ a.get("/api/scene", (c) => c.json(this.scene()));
1233
1250
  a.get("/api/sessions", (c) => c.json(listSessions(this.opts.cwd).map((s) => ({ id: s.id, title: s.title, mtime: s.mtime, bytes: s.bytes }))));
1234
1251
  a.get("/api/replay/:id", (c) => {
1235
1252
  const id = c.req.param("id");
@@ -1363,7 +1380,7 @@ var Theatre = class {
1363
1380
  }
1364
1381
  /** The live scene as /api/scene returns it. */
1365
1382
  scene() {
1366
- return { mode: "live", repoId: this.opts.repoId, world: this.live.world, events: this.live.events, beats: this.live.beats, signal: this.signal };
1383
+ return { mode: "live", repoId: this.opts.repoId, cwd: this.opts.cwd, elsewhere: this.elsewhere, world: this.live.world, events: this.live.events, beats: this.live.beats, signal: this.signal };
1367
1384
  }
1368
1385
  get url() {
1369
1386
  return `http://127.0.0.1:${this.port}/`;