chatroom-cli 1.4.2 → 1.4.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.
Files changed (2) hide show
  1. package/dist/index.js +40 -17
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -10391,23 +10391,23 @@ var init_daemon_state = __esm(() => {
10391
10391
  function agentKey2(chatroomId, role) {
10392
10392
  return `${chatroomId}:${role.toLowerCase()}`;
10393
10393
  }
10394
- function markIntentionalStop(chatroomId, role) {
10395
- intentionalStops.add(agentKey2(chatroomId, role));
10394
+ function markIntentionalStop(chatroomId, role, reason = "intentional_stop") {
10395
+ pendingStops.set(agentKey2(chatroomId, role), reason);
10396
10396
  }
10397
10397
  function consumeIntentionalStop(chatroomId, role) {
10398
10398
  const key = agentKey2(chatroomId, role);
10399
- if (intentionalStops.has(key)) {
10400
- intentionalStops.delete(key);
10401
- return true;
10399
+ const reason = pendingStops.get(key) ?? null;
10400
+ if (reason !== null) {
10401
+ pendingStops.delete(key);
10402
10402
  }
10403
- return false;
10403
+ return reason;
10404
10404
  }
10405
10405
  function clearIntentionalStop(chatroomId, role) {
10406
- intentionalStops.delete(agentKey2(chatroomId, role));
10406
+ pendingStops.delete(agentKey2(chatroomId, role));
10407
10407
  }
10408
- var intentionalStops;
10408
+ var pendingStops;
10409
10409
  var init_intentional_stops = __esm(() => {
10410
- intentionalStops = new Set;
10410
+ pendingStops = new Map;
10411
10411
  });
10412
10412
 
10413
10413
  // src/infrastructure/machine/index.ts
@@ -10613,6 +10613,7 @@ class PiRpcReader {
10613
10613
  thinkingDeltaCallbacks = [];
10614
10614
  agentEndCallbacks = [];
10615
10615
  toolCallCallbacks = [];
10616
+ toolResultCallbacks = [];
10616
10617
  anyEventCallbacks = [];
10617
10618
  constructor(stream) {
10618
10619
  const rl = createInterface({ input: stream, crlfDelay: Infinity });
@@ -10630,6 +10631,9 @@ class PiRpcReader {
10630
10631
  onToolCall(cb) {
10631
10632
  this.toolCallCallbacks.push(cb);
10632
10633
  }
10634
+ onToolResult(cb) {
10635
+ this.toolResultCallbacks.push(cb);
10636
+ }
10633
10637
  onAnyEvent(cb) {
10634
10638
  this.anyEventCallbacks.push(cb);
10635
10639
  }
@@ -10677,6 +10681,15 @@ class PiRpcReader {
10677
10681
  }
10678
10682
  return;
10679
10683
  }
10684
+ if (type === "tool_execution_end") {
10685
+ const toolName = event["toolName"];
10686
+ const toolResult = event["toolResult"] ?? event["output"] ?? event;
10687
+ if (typeof toolName === "string") {
10688
+ for (const cb of this.toolResultCallbacks)
10689
+ cb(toolName, toolResult);
10690
+ }
10691
+ return;
10692
+ }
10680
10693
  }
10681
10694
  }
10682
10695
  var init_pi_rpc_reader = () => {};
@@ -10813,10 +10826,16 @@ var init_pi_agent_service = __esm(() => {
10813
10826
  process.stdout.write(`${logPrefix} agent_end]
10814
10827
  `);
10815
10828
  });
10816
- reader.onToolCall((name) => {
10829
+ reader.onToolCall((name, args2) => {
10817
10830
  flushText();
10818
10831
  flushThinking();
10819
- process.stdout.write(`${logPrefix} tool: ${name}]
10832
+ const argsStr = args2 != null ? ` args: ${JSON.stringify(args2)}` : "";
10833
+ process.stdout.write(`${logPrefix} tool: ${name}${argsStr}]
10834
+ `);
10835
+ });
10836
+ reader.onToolResult((name, result) => {
10837
+ const resultStr = typeof result === "string" ? result : JSON.stringify(result);
10838
+ process.stdout.write(`${logPrefix} tool_result: ${name} result: ${resultStr}]
10820
10839
  `);
10821
10840
  });
10822
10841
  if (childProcess.stderr) {
@@ -13680,7 +13699,7 @@ function formatTimestamp() {
13680
13699
  async function onAgentShutdown(ctx, options) {
13681
13700
  const { chatroomId, role, pid, skipKill } = options;
13682
13701
  try {
13683
- ctx.deps.stops.mark(chatroomId, role);
13702
+ ctx.deps.stops.mark(chatroomId, role, options.stopReason ?? "intentional_stop");
13684
13703
  } catch (e) {
13685
13704
  console.log(` ⚠️ Failed to mark intentional stop for ${role}: ${e.message}`);
13686
13705
  }
@@ -13841,7 +13860,7 @@ async function executeStartAgent(ctx, args) {
13841
13860
  const isAlive = anyService ? anyService.isAlive(pid2) : false;
13842
13861
  if (isAlive) {
13843
13862
  console.log(` ⚠️ Existing agent detected (PID: ${pid2}) — stopping before respawn`);
13844
- await onAgentShutdown(ctx, { chatroomId, role, pid: pid2 });
13863
+ await onAgentShutdown(ctx, { chatroomId, role, pid: pid2, stopReason: "daemon_respawn_stop" });
13845
13864
  console.log(` ✅ Existing agent stopped (PID: ${pid2})`);
13846
13865
  }
13847
13866
  }
@@ -13906,8 +13925,8 @@ async function executeStartAgent(ctx, args) {
13906
13925
  model
13907
13926
  });
13908
13927
  spawnResult.onExit(({ code: code2, signal }) => {
13909
- const wasIntentional = ctx.deps.stops.consume(chatroomId, role);
13910
- const stopReason = resolveStopReason(code2, signal, wasIntentional);
13928
+ const pendingReason = ctx.deps.stops.consume(chatroomId, role);
13929
+ const stopReason = pendingReason ?? resolveStopReason(code2, signal, false);
13911
13930
  ctx.events.emit("agent:exited", {
13912
13931
  chatroomId,
13913
13932
  role,
@@ -13915,7 +13934,7 @@ async function executeStartAgent(ctx, args) {
13915
13934
  code: code2,
13916
13935
  signal,
13917
13936
  stopReason,
13918
- intentional: wasIntentional
13937
+ intentional: pendingReason !== null
13919
13938
  });
13920
13939
  });
13921
13940
  if (spawnResult.onAgentEnd) {
@@ -14361,8 +14380,12 @@ function onAgentExited(ctx, payload) {
14361
14380
  const { chatroomId, role, pid, code: code2, signal, stopReason, intentional } = payload;
14362
14381
  const ts = formatTimestamp();
14363
14382
  console.log(`[${ts}] Agent stopped: ${stopReason} (${role})`);
14364
- if (intentional) {
14383
+ const isDaemonRespawn = stopReason === "daemon_respawn_stop";
14384
+ const isIntentional = intentional && !isDaemonRespawn;
14385
+ if (isIntentional) {
14365
14386
  console.log(`[${ts}] ℹ️ Agent process exited after intentional stop ` + `(PID: ${pid}, role: ${role}, code: ${code2}, signal: ${signal})`);
14387
+ } else if (isDaemonRespawn) {
14388
+ console.log(`[${ts}] \uD83D\uDD04 Agent process stopped for respawn ` + `(PID: ${pid}, role: ${role}, code: ${code2}, signal: ${signal})`);
14366
14389
  } else {
14367
14390
  console.log(`[${ts}] ⚠️ Agent process exited ` + `(PID: ${pid}, role: ${role}, code: ${code2}, signal: ${signal})`);
14368
14391
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chatroom-cli",
3
- "version": "1.4.2",
3
+ "version": "1.4.4",
4
4
  "description": "CLI for multi-agent chatroom collaboration",
5
5
  "type": "module",
6
6
  "bin": {