chatroom-cli 1.2.1 → 1.2.2
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/index.js +37 -16
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -13408,12 +13408,23 @@ function parseMachineCommand(raw) {
|
|
|
13408
13408
|
// src/commands/machine/events/on-agent-shutdown/index.ts
|
|
13409
13409
|
async function onAgentShutdown(ctx, options) {
|
|
13410
13410
|
const { chatroomId, role, pid, skipKill } = options;
|
|
13411
|
+
try {
|
|
13412
|
+
ctx.deps.stops.mark(chatroomId, role);
|
|
13413
|
+
} catch (e) {
|
|
13414
|
+
console.log(` ⚠️ Failed to mark intentional stop for ${role}: ${e.message}`);
|
|
13415
|
+
}
|
|
13411
13416
|
let killed = false;
|
|
13412
13417
|
if (!skipKill) {
|
|
13413
13418
|
try {
|
|
13414
13419
|
ctx.deps.processes.kill(-pid, "SIGTERM");
|
|
13415
|
-
} catch {
|
|
13416
|
-
|
|
13420
|
+
} catch (e) {
|
|
13421
|
+
const isEsrch = e.code === "ESRCH" || e.message?.includes("ESRCH");
|
|
13422
|
+
if (isEsrch) {
|
|
13423
|
+
killed = true;
|
|
13424
|
+
}
|
|
13425
|
+
if (!isEsrch) {
|
|
13426
|
+
console.log(` ⚠️ Failed to send SIGTERM to ${role}: ${e.message}`);
|
|
13427
|
+
}
|
|
13417
13428
|
}
|
|
13418
13429
|
if (!killed) {
|
|
13419
13430
|
const SIGTERM_TIMEOUT_MS = 1e4;
|
|
@@ -13446,20 +13457,27 @@ async function onAgentShutdown(ctx, options) {
|
|
|
13446
13457
|
}
|
|
13447
13458
|
}
|
|
13448
13459
|
}
|
|
13449
|
-
|
|
13450
|
-
|
|
13460
|
+
if (killed || skipKill) {
|
|
13461
|
+
try {
|
|
13462
|
+
ctx.deps.machine.clearAgentPid(ctx.machineId, chatroomId, role);
|
|
13463
|
+
} catch (e) {
|
|
13464
|
+
console.log(` ⚠️ Failed to clear local PID for ${role}: ${e.message}`);
|
|
13465
|
+
}
|
|
13466
|
+
}
|
|
13451
13467
|
let spawnedAgentCleared = false;
|
|
13452
|
-
|
|
13453
|
-
|
|
13454
|
-
|
|
13455
|
-
|
|
13456
|
-
|
|
13457
|
-
|
|
13458
|
-
|
|
13459
|
-
|
|
13460
|
-
|
|
13461
|
-
|
|
13462
|
-
|
|
13468
|
+
if (killed || skipKill) {
|
|
13469
|
+
try {
|
|
13470
|
+
await ctx.deps.backend.mutation(api.machines.updateSpawnedAgent, {
|
|
13471
|
+
sessionId: ctx.sessionId,
|
|
13472
|
+
machineId: ctx.machineId,
|
|
13473
|
+
chatroomId,
|
|
13474
|
+
role,
|
|
13475
|
+
pid: undefined
|
|
13476
|
+
});
|
|
13477
|
+
spawnedAgentCleared = true;
|
|
13478
|
+
} catch (e) {
|
|
13479
|
+
console.log(` ⚠️ Failed to clear spawnedAgent for ${role}: ${e.message}`);
|
|
13480
|
+
}
|
|
13463
13481
|
}
|
|
13464
13482
|
let participantRemoved = false;
|
|
13465
13483
|
try {
|
|
@@ -13472,7 +13490,10 @@ async function onAgentShutdown(ctx, options) {
|
|
|
13472
13490
|
} catch (e) {
|
|
13473
13491
|
console.log(` ⚠️ Failed to remove participant for ${role}: ${e.message}`);
|
|
13474
13492
|
}
|
|
13475
|
-
return {
|
|
13493
|
+
return {
|
|
13494
|
+
killed: killed || (skipKill ?? false),
|
|
13495
|
+
cleaned: spawnedAgentCleared && participantRemoved
|
|
13496
|
+
};
|
|
13476
13497
|
}
|
|
13477
13498
|
var init_on_agent_shutdown = __esm(() => {
|
|
13478
13499
|
init_api3();
|