chatroom-cli 1.0.84 → 1.0.85

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 +39 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -13059,6 +13059,42 @@ async function clearAgentPidEverywhere(ctx, chatroomId, role) {
13059
13059
  }
13060
13060
  clearAgentPid(ctx.machineId, chatroomId, role);
13061
13061
  }
13062
+ async function handleAgentCrashRecovery(ctx, originalCommand, _crashedPid) {
13063
+ const { chatroomId, role } = originalCommand.payload;
13064
+ const ts = formatTimestamp();
13065
+ await clearAgentPidEverywhere(ctx, chatroomId, role).catch((err) => {
13066
+ console.log(` ⚠️ Failed to clear PID after exit: ${err.message}`);
13067
+ });
13068
+ try {
13069
+ await ctx.client.mutation(api.participants.leave, {
13070
+ sessionId: ctx.sessionId,
13071
+ chatroomId,
13072
+ role
13073
+ });
13074
+ console.log(`[${ts}] Marked ${role} as offline (participant removed)`);
13075
+ } catch (leaveErr) {
13076
+ console.log(`[${ts}] ⚠️ Could not remove participant: ${leaveErr.message}`);
13077
+ }
13078
+ console.log(`[${ts}] \uD83D\uDD04 Attempting to restart ${role} (max ${MAX_CRASH_RESTART_ATTEMPTS} attempts)...`);
13079
+ for (let attempt = 1;attempt <= MAX_CRASH_RESTART_ATTEMPTS; attempt++) {
13080
+ const attemptTs = formatTimestamp();
13081
+ console.log(`[${attemptTs}] Restart attempt ${attempt}/${MAX_CRASH_RESTART_ATTEMPTS}...`);
13082
+ await new Promise((resolve2) => setTimeout(resolve2, CRASH_RESTART_DELAY_MS));
13083
+ try {
13084
+ const result = await handleStartAgent(ctx, originalCommand);
13085
+ if (!result.failed) {
13086
+ const successTs = formatTimestamp();
13087
+ console.log(`[${successTs}] ✅ ${role} restarted successfully on attempt ${attempt}`);
13088
+ return;
13089
+ }
13090
+ console.log(`[${attemptTs}] ⚠️ Restart attempt ${attempt} failed: ${result.result}`);
13091
+ } catch (restartErr) {
13092
+ console.log(`[${attemptTs}] ⚠️ Restart attempt ${attempt} error: ${restartErr.message}`);
13093
+ }
13094
+ }
13095
+ const failTs = formatTimestamp();
13096
+ console.log(`[${failTs}] ❌ Failed to restart ${role} after ${MAX_CRASH_RESTART_ATTEMPTS} attempts. ` + `The agent will need to be restarted manually or via the webapp.`);
13097
+ }
13062
13098
  async function recoverAgentState(ctx) {
13063
13099
  const entries = listAgentEntries(ctx.machineId);
13064
13100
  if (entries.length === 0) {
@@ -13181,8 +13217,8 @@ async function handleStartAgent(ctx, command) {
13181
13217
  startResult.onExit((code2, signal) => {
13182
13218
  const ts = formatTimestamp();
13183
13219
  console.log(`[${ts}] ⚠️ Agent process exited unexpectedly ` + `(PID: ${spawnedPid}, role: ${role}, code: ${code2}, signal: ${signal})`);
13184
- clearAgentPidEverywhere(ctx, chatroomId, role).catch((err) => {
13185
- console.log(` ⚠️ Failed to clear PID after exit: ${err.message}`);
13220
+ handleAgentCrashRecovery(ctx, command, spawnedPid).catch((err) => {
13221
+ console.log(` ⚠️ Crash recovery failed for ${role}: ${err.message}`);
13186
13222
  });
13187
13223
  });
13188
13224
  }
@@ -13555,7 +13591,7 @@ async function daemonStart() {
13555
13591
  const ctx = await initDaemon();
13556
13592
  await startCommandLoop(ctx);
13557
13593
  }
13558
- var MODEL_REFRESH_INTERVAL_MS;
13594
+ var MAX_CRASH_RESTART_ATTEMPTS = 3, CRASH_RESTART_DELAY_MS = 3000, MODEL_REFRESH_INTERVAL_MS;
13559
13595
  var init_daemon_start = __esm(() => {
13560
13596
  init_pid();
13561
13597
  init_api3();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chatroom-cli",
3
- "version": "1.0.84",
3
+ "version": "1.0.85",
4
4
  "description": "CLI for multi-agent chatroom collaboration",
5
5
  "type": "module",
6
6
  "bin": {