@tablation/crew 0.139.0 → 0.140.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.
Files changed (2) hide show
  1. package/dist/cli.js +131 -57
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -8882,6 +8882,16 @@ var BeforeFirstEditTracker = class {
8882
8882
  }
8883
8883
  };
8884
8884
 
8885
+ // src/run-input.ts
8886
+ var live = /* @__PURE__ */ new Map();
8887
+ var registerRunInput = (run4, input) => {
8888
+ live.set(run4, input);
8889
+ };
8890
+ var unregisterRunInput = (run4) => {
8891
+ live.delete(run4);
8892
+ };
8893
+ var runInputFor = (run4) => live.get(run4);
8894
+
8885
8895
  // src/agent-log.ts
8886
8896
  import { existsSync as existsSync25, mkdirSync as mkdirSync18, readdirSync as readdirSync8, readFileSync as readFileSync25, rmSync as rmSync14, writeFileSync as writeFileSync19 } from "fs";
8887
8897
  import { join as join27 } from "path";
@@ -11029,6 +11039,9 @@ async function markMessage(target, rowId, messageId, state) {
11029
11039
  return false;
11030
11040
  }
11031
11041
  }
11042
+ async function postMessage(target, rowId, text2) {
11043
+ return post(target, `/agents/log/${rowId}/messages`, { text: text2 });
11044
+ }
11032
11045
  async function fetchPendingMessages(target, workItem) {
11033
11046
  try {
11034
11047
  const res = await request(
@@ -13989,7 +14002,8 @@ function spawnPlanned(plan, emit, hintMoved) {
13989
14002
  agentLog: id.agentLog,
13990
14003
  promptVersion: plan.promptVersion,
13991
14004
  promptSha: plan.promptSha,
13992
- ...plan.workspaceRunId ? { workspaceRunId: plan.workspaceRunId } : {}
14005
+ ...plan.workspaceRunId ? { workspaceRunId: plan.workspaceRunId } : {},
14006
+ ...streamsInput(plan) && !promptDelivered && adapter.userMessageLine ? { acceptsInput: true } : {}
13993
14007
  };
13994
14008
  try {
13995
14009
  writeFileSync22(pidPathFor(plan.streamPath), JSON.stringify(sidecar));
@@ -14001,9 +14015,11 @@ function spawnPlanned(plan, emit, hintMoved) {
14001
14015
  const closeInput = () => {
14002
14016
  if (!inputOpen) return;
14003
14017
  inputOpen = false;
14018
+ updateSidecar(plan.streamPath, { acceptsInput: false });
14004
14019
  child.stdin?.end();
14005
14020
  };
14006
14021
  if (inputOpen) obs.onResult = closeInput;
14022
+ const handled2 = /* @__PURE__ */ new Set();
14007
14023
  const writeNote = (text2) => new Promise((done) => {
14008
14024
  const stdin = child.stdin;
14009
14025
  if (!inputOpen || !stdin || !stdin.writable) {
@@ -14016,6 +14032,22 @@ function spawnPlanned(plan, emit, hintMoved) {
14016
14032
  done(false);
14017
14033
  }
14018
14034
  });
14035
+ const runName = basename9(plan.streamPath).replace(/\.jsonl$/, "");
14036
+ if (inputOpen) {
14037
+ registerRunInput(runName, {
14038
+ accepts: () => inputOpen,
14039
+ agentLogRowId: () => id.agentLogRowId,
14040
+ ...plan.agentLog ? { target: plan.agentLog } : {},
14041
+ deliver: async (note, author2) => {
14042
+ if (handled2.has(note.id)) return "delivered";
14043
+ handled2.add(note.id);
14044
+ const landed = await writeNote(frameNote(note, author2));
14045
+ const rowId = id.agentLogRowId;
14046
+ if (plan.agentLog && rowId) await markMessage(plan.agentLog, rowId, note.id, landed ? "delivered" : "carried_forward");
14047
+ return landed ? "delivered" : "carried_forward";
14048
+ }
14049
+ });
14050
+ }
14019
14051
  const startedRow = plan.agentLog ? startAgentRunRow(plan.agentLog, {
14020
14052
  runId: plan.workspaceRunId,
14021
14053
  ticketReference: plan.ticket ?? void 0,
@@ -14033,7 +14065,11 @@ function spawnPlanned(plan, emit, hintMoved) {
14033
14065
  if (row.live && plan.agentLog) {
14034
14066
  const reporter = new LiveRunReporter(plan.agentLog, row.id, {
14035
14067
  onPosted: (n) => updateSidecar(plan.streamPath, { cyclesPosted: n }),
14036
- onMessages: (msgs) => deliverNotes(plan.agentLog, row.id, msgs, writeNote)
14068
+ onMessages: (msgs) => {
14069
+ const fresh = msgs.filter((m) => !handled2.has(m.id));
14070
+ for (const m of fresh) handled2.add(m.id);
14071
+ return deliverNotes(plan.agentLog, row.id, fresh, writeNote);
14072
+ }
14037
14073
  });
14038
14074
  obs.attachReporter(reporter);
14039
14075
  reporter.start();
@@ -14053,6 +14089,7 @@ function spawnPlanned(plan, emit, hintMoved) {
14053
14089
  let spawnFailed = false;
14054
14090
  child.on("error", (err3) => {
14055
14091
  spawnFailed = true;
14092
+ unregisterRunInput(runName);
14056
14093
  clearInterval(timer);
14057
14094
  clearTimeout(limitTimer);
14058
14095
  void runner.release(handle, emit);
@@ -14060,6 +14097,7 @@ function spawnPlanned(plan, emit, hintMoved) {
14060
14097
  });
14061
14098
  child.on("close", async (code) => {
14062
14099
  inputOpen = false;
14100
+ unregisterRunInput(runName);
14063
14101
  clearInterval(timer);
14064
14102
  clearTimeout(limitTimer);
14065
14103
  obs.feed(tail3.poll());
@@ -14293,6 +14331,14 @@ async function settleRunEnd(o) {
14293
14331
  emit.warn(`could not beat ship idle: ${e.message}`, { step: "agent" });
14294
14332
  }
14295
14333
  }
14334
+ function pidAlive2(pid) {
14335
+ try {
14336
+ process.kill(pid, 0);
14337
+ return true;
14338
+ } catch (e) {
14339
+ return e.code === "EPERM";
14340
+ }
14341
+ }
14296
14342
  function describeRun(run4, route2, seatIds, worktreeOf = (d, n) => {
14297
14343
  try {
14298
14344
  return worktreeForNumber(d, n)?.path ?? null;
@@ -14313,7 +14359,10 @@ function describeRun(run4, route2, seatIds, worktreeOf = (d, n) => {
14313
14359
  stream: run4.streamPath,
14314
14360
  pid: run4.pid,
14315
14361
  startedAt: run4.spawnedAt,
14316
- deadline: run4.deadline ?? null
14362
+ deadline: run4.deadline ?? null,
14363
+ // CREW-3119: the harness still reads notes, and the process holding its stdin is alive.
14364
+ acceptsInput: !!run4.acceptsInput && pidAlive2(run4.ownerPid),
14365
+ agentLogId: run4.agentLogRowId ?? null
14317
14366
  };
14318
14367
  }
14319
14368
 
@@ -20126,11 +20175,11 @@ async function confirmExternalReleased(o, closures) {
20126
20175
  }
20127
20176
  const { timeoutSeconds, intervalSeconds } = o.repo.release.verify;
20128
20177
  const deadline = Date.now() + timeoutSeconds * 1e3;
20129
- let live = "";
20178
+ let live2 = "";
20130
20179
  for (; ; ) {
20131
20180
  const r = await hook(o, "released");
20132
- live = r?.output.trim().split("\n").filter(Boolean).pop() ?? "";
20133
- if (live) break;
20181
+ live2 = r?.output.trim().split("\n").filter(Boolean).pop() ?? "";
20182
+ if (live2) break;
20134
20183
  if (Date.now() >= deadline) {
20135
20184
  o.emit.warn(`not confirmed within ${timeoutSeconds}s \u2014 the released hook reported nothing`);
20136
20185
  return closures;
@@ -20139,13 +20188,13 @@ async function confirmExternalReleased(o, closures) {
20139
20188
  }
20140
20189
  return closures.map((c) => {
20141
20190
  if (c.closure.state !== "merged" || !c.closure.mergedAt) return c;
20142
- const confirmed = isAncestor(o.cwd, c.closure.mergedAt, live);
20191
+ const confirmed = isAncestor(o.cwd, c.closure.mergedAt, live2);
20143
20192
  if (!confirmed) {
20144
- o.emit.emit(`not yet carried by ${live.slice(0, 12)}`, { ticket: c.ticket.issue_id });
20193
+ o.emit.emit(`not yet carried by ${live2.slice(0, 12)}`, { ticket: c.ticket.issue_id });
20145
20194
  return { ...c, confirmed };
20146
20195
  }
20147
20196
  const version = o.repo.release.versioning === "none" || !o.repo.release.versionFiles[0] ? void 0 : (() => {
20148
- const content = fileAtRef(o.cwd, live, o.repo.release.versionFiles[0]);
20197
+ const content = fileAtRef(o.cwd, live2, o.repo.release.versionFiles[0]);
20149
20198
  if (!content) return void 0;
20150
20199
  try {
20151
20200
  return JSON.parse(content).version;
@@ -20153,7 +20202,7 @@ async function confirmExternalReleased(o, closures) {
20153
20202
  return void 0;
20154
20203
  }
20155
20204
  })();
20156
- o.emit.emit(`confirmed shipped in ${live.slice(0, 12)}`, { ticket: c.ticket.issue_id, data: { version } });
20205
+ o.emit.emit(`confirmed shipped in ${live2.slice(0, 12)}`, { ticket: c.ticket.issue_id, data: { version } });
20157
20206
  return { ...c, confirmed, version };
20158
20207
  });
20159
20208
  }
@@ -20308,14 +20357,14 @@ async function confirm(o, expected) {
20308
20357
  const deadline = Date.now() + timeoutSeconds * 1e3;
20309
20358
  for (; ; ) {
20310
20359
  const r = await hook(o, "released");
20311
- const live = r?.output.trim().split("\n").filter(Boolean).pop() ?? "";
20312
- const hit = match === "commit" ? live.startsWith(expected.slice(0, 7)) || expected.startsWith(live.slice(0, 7)) : live === expected;
20313
- if (live && hit) {
20314
- o.emit.emit(`confirmed live: ${live.slice(0, 12)}`);
20360
+ const live2 = r?.output.trim().split("\n").filter(Boolean).pop() ?? "";
20361
+ const hit = match === "commit" ? live2.startsWith(expected.slice(0, 7)) || expected.startsWith(live2.slice(0, 7)) : live2 === expected;
20362
+ if (live2 && hit) {
20363
+ o.emit.emit(`confirmed live: ${live2.slice(0, 12)}`);
20315
20364
  return true;
20316
20365
  }
20317
20366
  if (Date.now() >= deadline) {
20318
- o.emit.warn(`not confirmed within ${timeoutSeconds}s \u2014 target reports ${live || "nothing"}`);
20367
+ o.emit.warn(`not confirmed within ${timeoutSeconds}s \u2014 target reports ${live2 || "nothing"}`);
20319
20368
  return false;
20320
20369
  }
20321
20370
  await new Promise((r2) => setTimeout(r2, intervalSeconds * 1e3));
@@ -21753,9 +21802,9 @@ var PeriscopeError = class extends Error {
21753
21802
  };
21754
21803
  var LivePeriscopeError = class extends PeriscopeError {
21755
21804
  data;
21756
- constructor(tag, number, live) {
21757
- super(`${tag} already has a live periscope on ${live.ship}: ${live.url} (worktree ${live.worktree}) \u2014 run \`crew periscope down ${number} --keep|--discard\` on ${live.ship}, or resume it there with \`crew periscope up --resume ${number}\``);
21758
- this.data = { refused: "live_periscope_exists", ...live };
21805
+ constructor(tag, number, live2) {
21806
+ super(`${tag} already has a live periscope on ${live2.ship}: ${live2.url} (worktree ${live2.worktree}) \u2014 run \`crew periscope down ${number} --keep|--discard\` on ${live2.ship}, or resume it there with \`crew periscope up --resume ${number}\``);
21807
+ this.data = { refused: "live_periscope_exists", ...live2 };
21759
21808
  }
21760
21809
  };
21761
21810
  var priorDir = (stateDir) => join49(stateDir, "periscope-priors");
@@ -21827,8 +21876,8 @@ function periscopeCaps(l) {
21827
21876
  };
21828
21877
  }
21829
21878
  async function assertNoLivePeriscope(e, t, number) {
21830
- const live = (await e.liveRows(t.id))[0];
21831
- if (live) throw new LivePeriscopeError(t.tag, number, live);
21879
+ const live2 = (await e.liveRows(t.id))[0];
21880
+ if (live2) throw new LivePeriscopeError(t.tag, number, live2);
21832
21881
  }
21833
21882
  async function existingRefusal(e, t) {
21834
21883
  if (t.closed) return `${t.tag} is ${t.status}; a closed ticket cannot be periscoped`;
@@ -21877,9 +21926,9 @@ async function periscopePreflight(d, repo) {
21877
21926
  if (!d.hasPeriscopesTable) {
21878
21927
  throw new PeriscopeError("this workspace has no Periscopes table \u2014 update the Issues template and run `crew connect`");
21879
21928
  }
21880
- const live = await d.liveCount();
21881
- if (live >= d.caps.max) {
21882
- throw new PeriscopeError(`this ship already hosts ${live} live periscope(s) (ship.maxPeriscopes is ${d.caps.max}) \u2014 discard one first`);
21929
+ const live2 = await d.liveCount();
21930
+ if (live2 >= d.caps.max) {
21931
+ throw new PeriscopeError(`this ship already hosts ${live2} live periscope(s) (ship.maxPeriscopes is ${d.caps.max}) \u2014 discard one first`);
21883
21932
  }
21884
21933
  }
21885
21934
  async function runPeriscopeUp(d, args) {
@@ -22619,23 +22668,23 @@ async function runFleetPass(o) {
22619
22668
  decide: (c) => decide({ ...ctxs.get(c.route.route), emit: c.emit })
22620
22669
  });
22621
22670
  if (fleet.entries.length && fleet.entries.every((e) => e.error)) throw new Error(fleet.entries[0].error);
22622
- const live = [];
22671
+ const live2 = [];
22623
22672
  for (const e of fleet.entries) {
22624
22673
  const ctx = ctxs.get(e.route.route);
22625
22674
  if (e.error || !e.decision) continue;
22626
22675
  await applyRouteDecision(perRoute(e.route), ctx, e.decision);
22627
- live.push({ ctx, decision: e.decision, roles: e.decision.selection.pending });
22676
+ live2.push({ ctx, decision: e.decision, roles: e.decision.selection.pending });
22628
22677
  }
22629
- await Promise.all(live.map(async ({ ctx }) => {
22678
+ await Promise.all(live2.map(async ({ ctx }) => {
22630
22679
  try {
22631
22680
  await new Tracker(ctx.route, o.ship).beatShip(o.ship.name);
22632
22681
  } catch (e) {
22633
22682
  ctx.emit.warn(`could not beat ship for ${ctx.route.route}: ${e.message}`, { step: "poll" });
22634
22683
  }
22635
22684
  }));
22636
- const { started, skipped } = await fillSlots(o, live, fleet.winner && { route: fleet.winner.route.route, role: fleet.winner.role });
22637
- for (const { ctx } of live) await publishShipAttention(o.state, ctx.route, o.ship);
22638
- return { pending: [...new Set(live.flatMap((l) => l.roles))], started, skipped };
22685
+ const { started, skipped } = await fillSlots(o, live2, fleet.winner && { route: fleet.winner.route.route, role: fleet.winner.role });
22686
+ for (const { ctx } of live2) await publishShipAttention(o.state, ctx.route, o.ship);
22687
+ return { pending: [...new Set(live2.flatMap((l) => l.roles))], started, skipped };
22639
22688
  } catch (e) {
22640
22689
  if (!isUpgradeRequired(e)) throw e;
22641
22690
  const route2 = routes[0];
@@ -22654,10 +22703,10 @@ async function fillSlots(o, routes, first) {
22654
22703
  const started = [];
22655
22704
  const skipped = [];
22656
22705
  const roleCap = (role) => TICKET_ROLES.has(role) ? o.roleConcurrency?.[role] ?? 1 : 1;
22657
- const live = new Map(order.map((c) => [c, 0]));
22658
- while (live.size) {
22706
+ const live2 = new Map(order.map((c) => [c, 0]));
22707
+ while (live2.size) {
22659
22708
  for (const cand of order) {
22660
- const count = live.get(cand);
22709
+ const count = live2.get(cand);
22661
22710
  if (count === void 0) continue;
22662
22711
  const { role, ctx, decision } = cand;
22663
22712
  const skip = (reason) => {
@@ -22666,20 +22715,20 @@ async function fillSlots(o, routes, first) {
22666
22715
  if (openShipAttention(state).some((i) => i.key === seatCannotWriteKey(role))) {
22667
22716
  if (await (o.seatWriteRefused ?? ((r) => seatWriteStillRefused(ctx.route, r, { userAgent: o.ship.userAgent })))(role)) {
22668
22717
  skip("seat role cannot write the hand-off fields \u2014 see attention");
22669
- live.delete(cand);
22718
+ live2.delete(cand);
22670
22719
  continue;
22671
22720
  }
22672
22721
  clearShipAttention(state, seatCannotWriteKey(role));
22673
22722
  }
22674
22723
  if (!breaker.allows(role)) {
22675
22724
  skip("agent recently failed to start \u2014 waiting before retry");
22676
- live.delete(cand);
22725
+ live2.delete(cand);
22677
22726
  continue;
22678
22727
  }
22679
22728
  const lock = state.acquireRun(role, o.maxConcurrentAgents, roleCap(role));
22680
22729
  if (!lock.ok) {
22681
22730
  skip(lock.reason);
22682
- live.delete(cand);
22731
+ live2.delete(cand);
22683
22732
  continue;
22684
22733
  }
22685
22734
  let settle = () => {
@@ -22750,11 +22799,11 @@ async function fillSlots(o, routes, first) {
22750
22799
  const tookTicket = reported2 !== false;
22751
22800
  if (tookTicket) started.push(role);
22752
22801
  if (roleCap(role) <= 1) {
22753
- live.delete(cand);
22802
+ live2.delete(cand);
22754
22803
  continue;
22755
22804
  }
22756
- if (tookTicket && count + 1 < roleCap(role)) live.set(cand, count + 1);
22757
- else live.delete(cand);
22805
+ if (tookTicket && count + 1 < roleCap(role)) live2.set(cand, count + 1);
22806
+ else live2.delete(cand);
22758
22807
  }
22759
22808
  }
22760
22809
  return { started, skipped };
@@ -23703,10 +23752,10 @@ function nonReleaserNote(repo, releaser) {
23703
23752
  }
23704
23753
  function missingReleaserWarning(repo, release, ships, now = Date.now()) {
23705
23754
  if (release.ship || release.mode !== "local" && release.mode !== "integrate") return null;
23706
- const live = ships.filter((s) => s.last_seen && now - Date.parse(s.last_seen) <= DAY_MS);
23707
- if (live.length < 2) return null;
23708
- const names = live.map((s) => s.name ?? "?").join(", ");
23709
- return `${repo}: release.mode "${release.mode}" with no release.ship, and ${live.length} ships seen in the last day (${names}) \u2014 every one of them will try to release it. Set release.ship in .crew.yaml.`;
23755
+ const live2 = ships.filter((s) => s.last_seen && now - Date.parse(s.last_seen) <= DAY_MS);
23756
+ if (live2.length < 2) return null;
23757
+ const names = live2.map((s) => s.name ?? "?").join(", ");
23758
+ return `${repo}: release.mode "${release.mode}" with no release.ship, and ${live2.length} ships seen in the last day (${names}) \u2014 every one of them will try to release it. Set release.ship in .crew.yaml.`;
23710
23759
  }
23711
23760
 
23712
23761
  // src/watch.ts
@@ -26782,11 +26831,11 @@ async function handlePeriscopes(h, q2) {
26782
26831
  for (const v of [repo, topic, requestedBy]) if (isErr(v)) return err(400, v.error);
26783
26832
  if (b.isolate !== void 0 && typeof b.isolate !== "boolean") return err(400, "isolate must be a boolean");
26784
26833
  if (!h.previewHost && !h.relayPreviews) return err(409, "this ship has no ship.previewHost, so a Passenger could not reach a periscope");
26785
- const live = await h.run(["periscope", "list", picked.route, "--json"], () => {
26834
+ const live2 = await h.run(["periscope", "list", picked.route, "--json"], () => {
26786
26835
  });
26787
- if (live.code === 0) {
26836
+ if (live2.code === 0) {
26788
26837
  try {
26789
- const n = JSON.parse(live.stdout).length;
26838
+ const n = JSON.parse(live2.stdout).length;
26790
26839
  if (n >= h.maxPeriscopes) return err(409, `this ship already hosts ${n} live periscope(s) (ship.maxPeriscopes is ${h.maxPeriscopes}) \u2014 discard one first`);
26791
26840
  } catch {
26792
26841
  }
@@ -26924,11 +26973,11 @@ function decodeCursor(s) {
26924
26973
  }
26925
26974
  return null;
26926
26975
  }
26927
- function candidates(live, rotated) {
26928
- const out = [live];
26976
+ function candidates(live2, rotated) {
26977
+ const out = [live2];
26929
26978
  if (!rotated) return out;
26930
26979
  try {
26931
- for (const n of readdirSync18(dirname35(live))) if (ROTATED_EVENTS_RE.test(n)) out.push(join58(dirname35(live), n));
26980
+ for (const n of readdirSync18(dirname35(live2))) if (ROTATED_EVENTS_RE.test(n)) out.push(join58(dirname35(live2), n));
26932
26981
  } catch {
26933
26982
  }
26934
26983
  return out;
@@ -26970,20 +27019,20 @@ function lastLines2(path, n) {
26970
27019
  } else lines2.pop();
26971
27020
  return { lines: lines2.slice(-n).filter((l) => l.length), cursor: cursorAt(end), reset: false };
26972
27021
  }
26973
- function readTail(live, opts) {
27022
+ function readTail(live2, opts) {
26974
27023
  const max = opts.maxBytes ?? MAX_TAIL_BYTES;
26975
- if (!existsSync56(live)) {
27024
+ if (!existsSync56(live2)) {
26976
27025
  return { lines: [], cursor: opts.after ?? encodeCursor({ dev: 0, ino: 0, off: 0 }), reset: false };
26977
27026
  }
26978
27027
  const cur = opts.after ? decodeCursor(opts.after) : null;
26979
- if (!opts.after) return lastLines2(live, opts.tail ?? DEFAULT_TAIL_LINES);
27028
+ if (!opts.after) return lastLines2(live2, opts.tail ?? DEFAULT_TAIL_LINES);
26980
27029
  let reset = false;
26981
- let path = live;
27030
+ let path = live2;
26982
27031
  let off = 0;
26983
27032
  if (!cur) {
26984
27033
  reset = true;
26985
27034
  } else {
26986
- const found = candidates(live, opts.rotated ?? false).find((p) => {
27035
+ const found = candidates(live2, opts.rotated ?? false).find((p) => {
26987
27036
  try {
26988
27037
  const s = statSync16(p);
26989
27038
  return s.ino === cur.ino && s.dev === cur.dev;
@@ -27001,8 +27050,8 @@ function readTail(live, opts) {
27001
27050
  off = 0;
27002
27051
  reset = true;
27003
27052
  }
27004
- if (off >= size && path !== live) {
27005
- path = live;
27053
+ if (off >= size && path !== live2) {
27054
+ path = live2;
27006
27055
  off = 0;
27007
27056
  size = statSync16(path).size;
27008
27057
  }
@@ -27093,6 +27142,29 @@ async function tailReply(path, q2, rotated, abort) {
27093
27142
  }
27094
27143
  return reply2(200, r);
27095
27144
  }
27145
+ var NOTE_MAX_CHARS = 4e3;
27146
+ async function postRunMessage(deps, run4, body) {
27147
+ if (!RUN_NAME_RE.test(run4) || run4.includes("..")) return err2(400, "not a run name");
27148
+ const live2 = liveRuns(deps.stateDir).find((r) => basename14(r.streamPath, ".jsonl") === run4.replace(/\.jsonl$/, ""));
27149
+ const carry = "A note for the work item posted from the platform is carried forward into its next run's brief.";
27150
+ if (!live2) return err2(404, `no live run ${run4}: it is unknown or has finished. ${carry}`);
27151
+ if (!body) return err2(400, "body must be a small JSON object");
27152
+ const text2 = typeof body.text === "string" ? body.text.trim() : "";
27153
+ if (!text2 || text2.length > NOTE_MAX_CHARS) return err2(400, `text must be a string of 1 to ${NOTE_MAX_CHARS} characters`);
27154
+ if (body.author !== void 0 && typeof body.author !== "string") return err2(400, "author must be a string");
27155
+ const input = runInputFor(basename14(live2.streamPath, ".jsonl"));
27156
+ const rowId = input?.agentLogRowId();
27157
+ if (!input?.target || !rowId) return err2(409, `run ${run4} is live but this daemon cannot record a note on it (it did not start the run, or the run has no Agent Log row). ${carry}`);
27158
+ try {
27159
+ const recorded = await postMessage(input.target, rowId, text2);
27160
+ const acceptsInput = input.accepts();
27161
+ const state = acceptsInput ? await input.deliver(recorded, body.author || void 0) : "carried_forward";
27162
+ if (!acceptsInput) await markMessage(input.target, rowId, recorded.id, "carried_forward");
27163
+ return reply2(200, { cycleId: recorded.id, state, acceptsInput });
27164
+ } catch (e) {
27165
+ return err2(409, `the platform did not take the note: ${e.message}. ${carry}`);
27166
+ }
27167
+ }
27096
27168
  async function route(deps, method, url, req, abort) {
27097
27169
  const p = url.pathname.replace(/\/+$/, "") || "/";
27098
27170
  const get2 = method === "GET";
@@ -27132,6 +27204,8 @@ async function route(deps, method, url, req, abort) {
27132
27204
  if (!existsSync56(file)) return err2(404, "no such run");
27133
27205
  return tailReply(file, url.searchParams, false, abort);
27134
27206
  }
27207
+ const note = /^\/streams\/([^/]+)\/messages$/.exec(p);
27208
+ if (note && post3) return postRunMessage(deps, decodeURIComponent(note[1]), await readJsonBody(req));
27135
27209
  if ((p === "/pause" || p === "/resume") && post3) {
27136
27210
  const body = await readJsonBody(req);
27137
27211
  if (!body) return err2(400, "body must be a small JSON object");
@@ -31881,9 +31955,9 @@ Signed in as ${result.identity.email} \u2014 minted an API key in workspace "${r
31881
31955
  break;
31882
31956
  }
31883
31957
  for (const r of rows) {
31884
- const live = worktreeExistsIn(where, r.t.n);
31958
+ const live2 = worktreeExistsIn(where, r.t.n);
31885
31959
  process.stdout.write(
31886
- `${String(r.port).padEnd(6)} ${r.t.role.padEnd(9)} ISSUE-${String(r.t.n).padEnd(5)} pid ${String(r.pid).padEnd(7)} ${live ? "worktree present" : "ORPHAN \u2014 worktree gone"}
31960
+ `${String(r.port).padEnd(6)} ${r.t.role.padEnd(9)} ISSUE-${String(r.t.n).padEnd(5)} pid ${String(r.pid).padEnd(7)} ${live2 ? "worktree present" : "ORPHAN \u2014 worktree gone"}
31887
31961
  `
31888
31962
  );
31889
31963
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tablation/crew",
3
- "version": "0.139.0",
3
+ "version": "0.140.0",
4
4
  "description": "A standing team of headless agents that picks work off a Tablation board, does it on a machine you control, and reports back.",
5
5
  "type": "module",
6
6
  "license": "MIT",