chatroom-cli 1.2.0 → 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.
Files changed (2) hide show
  1. package/dist/index.js +69 -18
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -11152,18 +11152,22 @@ var init_cli = __esm(() => {
11152
11152
  });
11153
11153
 
11154
11154
  // ../../services/backend/config/errorCodes.ts
11155
- var BACKEND_ERROR_CODES, FATAL_ERROR_CODES;
11155
+ var BACKEND_ERROR_CODES, FATAL_ERROR_CODES, NON_FATAL_ERROR_CODES;
11156
11156
  var init_errorCodes = __esm(() => {
11157
11157
  BACKEND_ERROR_CODES = {
11158
11158
  PARTICIPANT_NOT_FOUND: "PARTICIPANT_NOT_FOUND",
11159
11159
  CHATROOM_NOT_FOUND: "CHATROOM_NOT_FOUND",
11160
- SESSION_INVALID: "SESSION_INVALID"
11160
+ SESSION_INVALID: "SESSION_INVALID",
11161
+ CONTEXT_NO_HANDOFF_SINCE_LAST_CONTEXT: "CONTEXT_NO_HANDOFF_SINCE_LAST_CONTEXT"
11161
11162
  };
11162
11163
  FATAL_ERROR_CODES = [
11163
11164
  BACKEND_ERROR_CODES.PARTICIPANT_NOT_FOUND,
11164
11165
  BACKEND_ERROR_CODES.CHATROOM_NOT_FOUND,
11165
11166
  BACKEND_ERROR_CODES.SESSION_INVALID
11166
11167
  ];
11168
+ NON_FATAL_ERROR_CODES = [
11169
+ BACKEND_ERROR_CODES.CONTEXT_NO_HANDOFF_SINCE_LAST_CONTEXT
11170
+ ];
11167
11171
  });
11168
11172
 
11169
11173
  // ../../services/backend/prompts/base/cli/get-next-task/command.ts
@@ -12888,6 +12892,24 @@ async function newContext(chatroomId, options, deps) {
12888
12892
  console.log(`
12889
12893
  \uD83D\uDCCC This context is now pinned for all agents in this chatroom.`);
12890
12894
  } catch (err) {
12895
+ const errData = err.data;
12896
+ if (errData?.code === "CONTEXT_NO_HANDOFF_SINCE_LAST_CONTEXT" && errData.existingContext) {
12897
+ const { content, createdAt, createdBy } = errData.existingContext;
12898
+ console.error(`❌ Cannot create new context: no handoff sent since last context was created.`);
12899
+ console.error(`
12900
+ \uD83D\uDCCC Current Context (resume from here):`);
12901
+ console.error(` Created by: ${sanitizeForTerminal(createdBy)}`);
12902
+ console.error(` Created at: ${new Date(createdAt).toLocaleString()}`);
12903
+ console.error(` Content:`);
12904
+ const safeContent = sanitizeForTerminal(content);
12905
+ console.error(safeContent.split(`
12906
+ `).map((l) => ` ${l}`).join(`
12907
+ `));
12908
+ console.error(`
12909
+ \uD83D\uDCA1 Send a handoff first, then create a new context.`);
12910
+ process.exit(1);
12911
+ return;
12912
+ }
12891
12913
  console.error(`❌ Failed to create context: ${err.message}`);
12892
12914
  process.exit(1);
12893
12915
  return;
@@ -13386,12 +13408,23 @@ function parseMachineCommand(raw) {
13386
13408
  // src/commands/machine/events/on-agent-shutdown/index.ts
13387
13409
  async function onAgentShutdown(ctx, options) {
13388
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
+ }
13389
13416
  let killed = false;
13390
13417
  if (!skipKill) {
13391
13418
  try {
13392
13419
  ctx.deps.processes.kill(-pid, "SIGTERM");
13393
- } catch {
13394
- killed = true;
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
+ }
13395
13428
  }
13396
13429
  if (!killed) {
13397
13430
  const SIGTERM_TIMEOUT_MS = 1e4;
@@ -13424,20 +13457,27 @@ async function onAgentShutdown(ctx, options) {
13424
13457
  }
13425
13458
  }
13426
13459
  }
13427
- ctx.deps.stops.mark(chatroomId, role);
13428
- ctx.deps.machine.clearAgentPid(ctx.machineId, chatroomId, role);
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
+ }
13429
13467
  let spawnedAgentCleared = false;
13430
- try {
13431
- await ctx.deps.backend.mutation(api.machines.updateSpawnedAgent, {
13432
- sessionId: ctx.sessionId,
13433
- machineId: ctx.machineId,
13434
- chatroomId,
13435
- role,
13436
- pid: undefined
13437
- });
13438
- spawnedAgentCleared = true;
13439
- } catch (e) {
13440
- console.log(` ⚠️ Failed to clear spawnedAgent for ${role}: ${e.message}`);
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
+ }
13441
13481
  }
13442
13482
  let participantRemoved = false;
13443
13483
  try {
@@ -13450,7 +13490,10 @@ async function onAgentShutdown(ctx, options) {
13450
13490
  } catch (e) {
13451
13491
  console.log(` ⚠️ Failed to remove participant for ${role}: ${e.message}`);
13452
13492
  }
13453
- return { killed, cleaned: spawnedAgentCleared && participantRemoved };
13493
+ return {
13494
+ killed: killed || (skipKill ?? false),
13495
+ cleaned: spawnedAgentCleared && participantRemoved
13496
+ };
13454
13497
  }
13455
13498
  var init_on_agent_shutdown = __esm(() => {
13456
13499
  init_api3();
@@ -14174,6 +14217,14 @@ Run any chatroom command first to register this machine,`);
14174
14217
  }
14175
14218
  const client2 = await getConvexClient();
14176
14219
  const typedSessionId = sessionId;
14220
+ const validation = await client2.query(api.cliAuth.validateSession, { sessionId: typedSessionId });
14221
+ if (!validation.valid) {
14222
+ console.error(`❌ Session invalid: ${validation.reason}`);
14223
+ console.error(`
14224
+ Run: chatroom auth login`);
14225
+ releaseLock();
14226
+ process.exit(1);
14227
+ }
14177
14228
  const config3 = loadMachineConfig();
14178
14229
  const remoteAgentService = new OpenCodeAgentService;
14179
14230
  const availableModels = await discoverModels(remoteAgentService);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chatroom-cli",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "CLI for multi-agent chatroom collaboration",
5
5
  "type": "module",
6
6
  "bin": {