chatroom-cli 1.2.3 → 1.2.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.
- package/dist/index.js +71 -48
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11284,22 +11284,9 @@ async function registerAgent(chatroomId, options, deps) {
|
|
|
11284
11284
|
harnessVersions: machineInfo.harnessVersions,
|
|
11285
11285
|
availableModels
|
|
11286
11286
|
});
|
|
11287
|
-
const agentHarness = machineInfo.availableHarnesses.length > 0 ? machineInfo.availableHarnesses[0] : undefined;
|
|
11288
|
-
await d.backend.mutation(api.machines.saveTeamAgentConfig, {
|
|
11289
|
-
sessionId,
|
|
11290
|
-
chatroomId,
|
|
11291
|
-
role,
|
|
11292
|
-
type: "remote",
|
|
11293
|
-
machineId: machineInfo.machineId,
|
|
11294
|
-
agentHarness,
|
|
11295
|
-
workingDir: process.cwd()
|
|
11296
|
-
});
|
|
11297
11287
|
console.log(`✅ Registered as remote agent for role "${role}"`);
|
|
11298
11288
|
console.log(` Machine: ${machineInfo.hostname} (${machineInfo.machineId})`);
|
|
11299
11289
|
console.log(` Working directory: ${process.cwd()}`);
|
|
11300
|
-
if (agentHarness) {
|
|
11301
|
-
console.log(` Agent harness: ${agentHarness}`);
|
|
11302
|
-
}
|
|
11303
11290
|
} catch (error) {
|
|
11304
11291
|
console.error(`❌ Registration failed: ${error.message}`);
|
|
11305
11292
|
process.exit(1);
|
|
@@ -13694,9 +13681,14 @@ function parseMachineCommand(raw) {
|
|
|
13694
13681
|
console.error(` ⚠️ Invalid start-agent command: missing chatroomId, role, or agentHarness`);
|
|
13695
13682
|
return null;
|
|
13696
13683
|
}
|
|
13684
|
+
if (!raw.reason) {
|
|
13685
|
+
console.error(` ⚠️ Invalid start-agent command: missing required reason field`);
|
|
13686
|
+
return null;
|
|
13687
|
+
}
|
|
13697
13688
|
return {
|
|
13698
13689
|
_id: raw._id,
|
|
13699
13690
|
type: "start-agent",
|
|
13691
|
+
reason: raw.reason,
|
|
13700
13692
|
payload: {
|
|
13701
13693
|
chatroomId,
|
|
13702
13694
|
role,
|
|
@@ -13713,9 +13705,14 @@ function parseMachineCommand(raw) {
|
|
|
13713
13705
|
console.error(` ⚠️ Invalid stop-agent command: missing chatroomId or role`);
|
|
13714
13706
|
return null;
|
|
13715
13707
|
}
|
|
13708
|
+
if (!raw.reason) {
|
|
13709
|
+
console.error(` ⚠️ Invalid stop-agent command: missing required reason field`);
|
|
13710
|
+
return null;
|
|
13711
|
+
}
|
|
13716
13712
|
return {
|
|
13717
13713
|
_id: raw._id,
|
|
13718
13714
|
type: "stop-agent",
|
|
13715
|
+
reason: raw.reason,
|
|
13719
13716
|
payload: { chatroomId, role },
|
|
13720
13717
|
createdAt: raw.createdAt
|
|
13721
13718
|
};
|
|
@@ -13960,6 +13957,9 @@ async function handleStartAgent(ctx, command) {
|
|
|
13960
13957
|
console.log(` Chatroom: ${chatroomId}`);
|
|
13961
13958
|
console.log(` Role: ${role}`);
|
|
13962
13959
|
console.log(` Harness: ${agentHarness}`);
|
|
13960
|
+
if (command.reason) {
|
|
13961
|
+
console.log(` Reason: ${command.reason}`);
|
|
13962
|
+
}
|
|
13963
13963
|
if (model) {
|
|
13964
13964
|
console.log(` Model: ${model}`);
|
|
13965
13965
|
}
|
|
@@ -13987,14 +13987,19 @@ async function handleStartAgent(ctx, command) {
|
|
|
13987
13987
|
chatroomId
|
|
13988
13988
|
});
|
|
13989
13989
|
const existingConfig = existingConfigs.configs.find((c) => c.machineId === ctx.machineId && c.role.toLowerCase() === role.toLowerCase());
|
|
13990
|
-
|
|
13991
|
-
|
|
13992
|
-
|
|
13993
|
-
|
|
13990
|
+
const backendPid = existingConfig?.spawnedAgentPid;
|
|
13991
|
+
const localEntry = ctx.deps.machine.listAgentEntries(ctx.machineId).find((e) => e.chatroomId === chatroomId && e.role.toLowerCase() === role.toLowerCase());
|
|
13992
|
+
const localPid = localEntry?.entry.pid;
|
|
13993
|
+
const pidsToKill = [
|
|
13994
|
+
...new Set([backendPid, localPid].filter((p) => p !== undefined))
|
|
13995
|
+
];
|
|
13996
|
+
const anyService = ctx.agentServices.values().next().value;
|
|
13997
|
+
for (const pid2 of pidsToKill) {
|
|
13998
|
+
const isAlive = anyService ? anyService.isAlive(pid2) : false;
|
|
13994
13999
|
if (isAlive) {
|
|
13995
|
-
console.log(` ⚠️ Existing agent detected (PID: ${
|
|
13996
|
-
await onAgentShutdown(ctx, { chatroomId, role, pid:
|
|
13997
|
-
console.log(` ✅ Existing agent stopped`);
|
|
14000
|
+
console.log(` ⚠️ Existing agent detected (PID: ${pid2}) — stopping before respawn`);
|
|
14001
|
+
await onAgentShutdown(ctx, { chatroomId, role, pid: pid2 });
|
|
14002
|
+
console.log(` ✅ Existing agent stopped (PID: ${pid2})`);
|
|
13998
14003
|
}
|
|
13999
14004
|
}
|
|
14000
14005
|
} catch (e) {
|
|
@@ -14129,46 +14134,64 @@ async function handleStopAgent(ctx, command) {
|
|
|
14129
14134
|
chatroomId
|
|
14130
14135
|
});
|
|
14131
14136
|
const targetConfig = configsResult.configs.find((c) => c.machineId === ctx.machineId && c.role.toLowerCase() === role.toLowerCase());
|
|
14132
|
-
|
|
14137
|
+
const backendPid = targetConfig?.spawnedAgentPid;
|
|
14138
|
+
const localEntry = ctx.deps.machine.listAgentEntries(ctx.machineId).find((e) => e.chatroomId === chatroomId && e.role.toLowerCase() === role.toLowerCase());
|
|
14139
|
+
const localPid = localEntry?.entry.pid;
|
|
14140
|
+
const allPids = [...new Set([backendPid, localPid].filter((p) => p !== undefined))];
|
|
14141
|
+
if (allPids.length === 0) {
|
|
14133
14142
|
const msg = "No running agent found (no PID recorded)";
|
|
14134
14143
|
console.log(` ⚠️ ${msg}`);
|
|
14135
14144
|
return { result: msg, failed: true };
|
|
14136
14145
|
}
|
|
14137
|
-
const pidToKill = targetConfig.spawnedAgentPid;
|
|
14138
|
-
console.log(` Stopping agent with PID: ${pidToKill}`);
|
|
14139
14146
|
const anyService = ctx.agentServices.values().next().value;
|
|
14140
|
-
|
|
14141
|
-
|
|
14142
|
-
|
|
14143
|
-
|
|
14144
|
-
|
|
14147
|
+
let anyKilled = false;
|
|
14148
|
+
let lastError = null;
|
|
14149
|
+
for (const pid of allPids) {
|
|
14150
|
+
console.log(` Stopping agent with PID: ${pid}`);
|
|
14151
|
+
const isAlive = anyService ? anyService.isAlive(pid) : false;
|
|
14152
|
+
if (!isAlive) {
|
|
14153
|
+
console.log(` ⚠️ PID ${pid} does not appear to belong to the expected agent`);
|
|
14154
|
+
await clearAgentPidEverywhere(ctx, chatroomId, role);
|
|
14155
|
+
console.log(` Cleared stale PID`);
|
|
14156
|
+
try {
|
|
14157
|
+
await ctx.deps.backend.mutation(api.participants.leave, {
|
|
14158
|
+
sessionId: ctx.sessionId,
|
|
14159
|
+
chatroomId,
|
|
14160
|
+
role
|
|
14161
|
+
});
|
|
14162
|
+
console.log(` Removed participant record`);
|
|
14163
|
+
} catch {}
|
|
14164
|
+
continue;
|
|
14165
|
+
}
|
|
14145
14166
|
try {
|
|
14146
|
-
await ctx
|
|
14147
|
-
sessionId: ctx.sessionId,
|
|
14167
|
+
const shutdownResult = await onAgentShutdown(ctx, {
|
|
14148
14168
|
chatroomId,
|
|
14149
|
-
role
|
|
14169
|
+
role,
|
|
14170
|
+
pid
|
|
14150
14171
|
});
|
|
14151
|
-
|
|
14152
|
-
|
|
14153
|
-
|
|
14154
|
-
|
|
14155
|
-
|
|
14156
|
-
}
|
|
14172
|
+
const msg = shutdownResult.killed ? `Agent stopped (PID: ${pid})` : `Agent stop attempted (PID: ${pid}) — process may still be running`;
|
|
14173
|
+
console.log(` ${shutdownResult.killed ? "✅" : "⚠️ "} ${msg}`);
|
|
14174
|
+
if (shutdownResult.killed) {
|
|
14175
|
+
anyKilled = true;
|
|
14176
|
+
}
|
|
14177
|
+
} catch (e) {
|
|
14178
|
+
lastError = e;
|
|
14179
|
+
console.log(` ⚠️ Failed to stop agent (PID: ${pid}): ${e.message}`);
|
|
14180
|
+
}
|
|
14157
14181
|
}
|
|
14158
|
-
|
|
14159
|
-
const
|
|
14160
|
-
chatroomId,
|
|
14161
|
-
role,
|
|
14162
|
-
pid: pidToKill
|
|
14163
|
-
});
|
|
14164
|
-
const msg = shutdownResult.killed ? `Agent stopped (PID: ${pidToKill})` : `Agent stop attempted (PID: ${pidToKill}) — process may still be running`;
|
|
14165
|
-
console.log(` ${shutdownResult.killed ? "✅" : "⚠️ "} ${msg}`);
|
|
14166
|
-
return { result: msg, failed: !shutdownResult.killed };
|
|
14167
|
-
} catch (e) {
|
|
14168
|
-
const msg = `Failed to stop agent: ${e.message}`;
|
|
14182
|
+
if (lastError && !anyKilled) {
|
|
14183
|
+
const msg = `Failed to stop agent: ${lastError.message}`;
|
|
14169
14184
|
console.log(` ⚠️ ${msg}`);
|
|
14170
14185
|
return { result: msg, failed: true };
|
|
14171
14186
|
}
|
|
14187
|
+
if (!anyKilled) {
|
|
14188
|
+
return {
|
|
14189
|
+
result: `All recorded PIDs appear stale (processes not found or belong to different programs)`,
|
|
14190
|
+
failed: true
|
|
14191
|
+
};
|
|
14192
|
+
}
|
|
14193
|
+
const killedCount = allPids.length > 1 ? ` (${allPids.length} PIDs)` : ``;
|
|
14194
|
+
return { result: `Agent stopped${killedCount}`, failed: false };
|
|
14172
14195
|
}
|
|
14173
14196
|
var init_stop_agent = __esm(() => {
|
|
14174
14197
|
init_api3();
|