chatroom-cli 1.0.83 → 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.
- package/dist/index.js +129 -51
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9617,6 +9617,67 @@ var init_api3 = __esm(() => {
|
|
|
9617
9617
|
init_api2();
|
|
9618
9618
|
});
|
|
9619
9619
|
|
|
9620
|
+
// src/utils/error-formatting.ts
|
|
9621
|
+
function formatError(message, suggestions) {
|
|
9622
|
+
console.error(`❌ ${message}`);
|
|
9623
|
+
if (suggestions && suggestions.length > 0) {
|
|
9624
|
+
console.error("");
|
|
9625
|
+
suggestions.forEach((suggestion) => {
|
|
9626
|
+
console.error(`\uD83D\uDCA1 ${suggestion}`);
|
|
9627
|
+
});
|
|
9628
|
+
}
|
|
9629
|
+
}
|
|
9630
|
+
function formatValidationError(field, value, expected) {
|
|
9631
|
+
formatError(`Invalid ${field}`, [`Got: ${value}`, `Expected: ${expected}`]);
|
|
9632
|
+
}
|
|
9633
|
+
function formatFileError(operation, filePath, reason) {
|
|
9634
|
+
const message = `Cannot ${operation} file: ${filePath}`;
|
|
9635
|
+
if (reason) {
|
|
9636
|
+
formatError(message, [`Reason: ${reason}`]);
|
|
9637
|
+
} else {
|
|
9638
|
+
console.error(`❌ ${message}`);
|
|
9639
|
+
}
|
|
9640
|
+
}
|
|
9641
|
+
function formatAuthError(currentUrl, otherUrls) {
|
|
9642
|
+
console.error(`❌ Not authenticated${currentUrl ? ` for: ${currentUrl}` : ""}`);
|
|
9643
|
+
if (otherUrls && otherUrls.length > 0) {
|
|
9644
|
+
console.error(`
|
|
9645
|
+
\uD83D\uDCA1 You have sessions for other environments:`);
|
|
9646
|
+
for (const url of otherUrls) {
|
|
9647
|
+
console.error(` • ${url}`);
|
|
9648
|
+
}
|
|
9649
|
+
console.error(`
|
|
9650
|
+
To use a different environment, set CHATROOM_CONVEX_URL:`);
|
|
9651
|
+
console.error(` CHATROOM_CONVEX_URL=${otherUrls[0]} chatroom <command>`);
|
|
9652
|
+
console.error(`
|
|
9653
|
+
Or to authenticate for the current environment:`);
|
|
9654
|
+
}
|
|
9655
|
+
console.error(` chatroom auth login`);
|
|
9656
|
+
}
|
|
9657
|
+
function formatChatroomIdError(chatroomId) {
|
|
9658
|
+
formatValidationError("chatroom ID format", `ID must be 20-40 characters (got ${chatroomId?.length || 0})`, "20-40 character string");
|
|
9659
|
+
}
|
|
9660
|
+
function isNetworkError(error) {
|
|
9661
|
+
const msg = error instanceof Error ? error.message.toLowerCase() : String(error).toLowerCase();
|
|
9662
|
+
const code2 = error?.code;
|
|
9663
|
+
return msg.includes("fetch failed") || msg.includes("failed to fetch") || msg.includes("econnrefused") || msg.includes("enotfound") || msg.includes("etimedout") || msg.includes("network") || msg.includes("connection refused") || msg.includes("socket hang up") || msg.includes("dns") || code2 === "ECONNREFUSED" || code2 === "ENOTFOUND" || code2 === "ETIMEDOUT" || code2 === "ECONNRESET";
|
|
9664
|
+
}
|
|
9665
|
+
function formatConnectivityError(error, backendUrl) {
|
|
9666
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
9667
|
+
console.error(`
|
|
9668
|
+
❌ Could not reach the backend${backendUrl ? ` at ${backendUrl}` : ""}`);
|
|
9669
|
+
console.error(` ${err.message}`);
|
|
9670
|
+
console.error(`
|
|
9671
|
+
Your session may still be valid. Please check:`);
|
|
9672
|
+
console.error(` • Network connectivity`);
|
|
9673
|
+
console.error(` • Whether the backend service is running`);
|
|
9674
|
+
if (backendUrl) {
|
|
9675
|
+
console.error(` • CHATROOM_CONVEX_URL is correct (currently: ${backendUrl})`);
|
|
9676
|
+
}
|
|
9677
|
+
console.error(`
|
|
9678
|
+
Try again once the backend is reachable.`);
|
|
9679
|
+
}
|
|
9680
|
+
|
|
9620
9681
|
// src/infrastructure/auth/middleware.ts
|
|
9621
9682
|
var exports_middleware = {};
|
|
9622
9683
|
__export(exports_middleware, {
|
|
@@ -9677,12 +9738,18 @@ async function requireAuth() {
|
|
|
9677
9738
|
userName: validation.userName
|
|
9678
9739
|
};
|
|
9679
9740
|
} catch (error) {
|
|
9741
|
+
if (isNetworkError(error)) {
|
|
9742
|
+
formatConnectivityError(error, getConvexUrl());
|
|
9743
|
+
process.exit(1);
|
|
9744
|
+
}
|
|
9680
9745
|
const err = error;
|
|
9681
9746
|
console.error(`
|
|
9682
9747
|
❌ Error: Could not validate session`);
|
|
9683
9748
|
console.error(` ${err.message}`);
|
|
9684
9749
|
console.error(`
|
|
9685
|
-
Please
|
|
9750
|
+
Please re-authenticate:`);
|
|
9751
|
+
console.error(` $ chatroom auth login
|
|
9752
|
+
`);
|
|
9686
9753
|
process.exit(1);
|
|
9687
9754
|
}
|
|
9688
9755
|
}
|
|
@@ -9707,7 +9774,10 @@ async function checkAuth() {
|
|
|
9707
9774
|
userId: validation.userId,
|
|
9708
9775
|
userName: validation.userName
|
|
9709
9776
|
};
|
|
9710
|
-
} catch {
|
|
9777
|
+
} catch (error) {
|
|
9778
|
+
if (isNetworkError(error)) {
|
|
9779
|
+
throw error;
|
|
9780
|
+
}
|
|
9711
9781
|
return null;
|
|
9712
9782
|
}
|
|
9713
9783
|
}
|
|
@@ -10878,10 +10948,19 @@ async function waitForTask(chatroomId, options) {
|
|
|
10878
10948
|
console.error(`❌ Invalid chatroom ID format: ID must contain only alphanumeric characters and underscores`);
|
|
10879
10949
|
process.exit(1);
|
|
10880
10950
|
}
|
|
10881
|
-
|
|
10882
|
-
|
|
10883
|
-
|
|
10884
|
-
|
|
10951
|
+
let chatroom;
|
|
10952
|
+
try {
|
|
10953
|
+
chatroom = await client2.query(api.chatrooms.get, {
|
|
10954
|
+
sessionId,
|
|
10955
|
+
chatroomId
|
|
10956
|
+
});
|
|
10957
|
+
} catch (error) {
|
|
10958
|
+
if (isNetworkError(error)) {
|
|
10959
|
+
formatConnectivityError(error, convexUrl);
|
|
10960
|
+
process.exit(1);
|
|
10961
|
+
}
|
|
10962
|
+
throw error;
|
|
10963
|
+
}
|
|
10885
10964
|
if (!chatroom) {
|
|
10886
10965
|
console.error(`❌ Chatroom ${chatroomId} not found or access denied`);
|
|
10887
10966
|
process.exit(1);
|
|
@@ -11300,47 +11379,6 @@ var init_task_started2 = __esm(() => {
|
|
|
11300
11379
|
init_client2();
|
|
11301
11380
|
});
|
|
11302
11381
|
|
|
11303
|
-
// src/utils/error-formatting.ts
|
|
11304
|
-
function formatError(message, suggestions) {
|
|
11305
|
-
console.error(`❌ ${message}`);
|
|
11306
|
-
if (suggestions && suggestions.length > 0) {
|
|
11307
|
-
console.error("");
|
|
11308
|
-
suggestions.forEach((suggestion) => {
|
|
11309
|
-
console.error(`\uD83D\uDCA1 ${suggestion}`);
|
|
11310
|
-
});
|
|
11311
|
-
}
|
|
11312
|
-
}
|
|
11313
|
-
function formatValidationError(field, value, expected) {
|
|
11314
|
-
formatError(`Invalid ${field}`, [`Got: ${value}`, `Expected: ${expected}`]);
|
|
11315
|
-
}
|
|
11316
|
-
function formatFileError(operation, filePath, reason) {
|
|
11317
|
-
const message = `Cannot ${operation} file: ${filePath}`;
|
|
11318
|
-
if (reason) {
|
|
11319
|
-
formatError(message, [`Reason: ${reason}`]);
|
|
11320
|
-
} else {
|
|
11321
|
-
console.error(`❌ ${message}`);
|
|
11322
|
-
}
|
|
11323
|
-
}
|
|
11324
|
-
function formatAuthError(currentUrl, otherUrls) {
|
|
11325
|
-
console.error(`❌ Not authenticated${currentUrl ? ` for: ${currentUrl}` : ""}`);
|
|
11326
|
-
if (otherUrls && otherUrls.length > 0) {
|
|
11327
|
-
console.error(`
|
|
11328
|
-
\uD83D\uDCA1 You have sessions for other environments:`);
|
|
11329
|
-
for (const url of otherUrls) {
|
|
11330
|
-
console.error(` • ${url}`);
|
|
11331
|
-
}
|
|
11332
|
-
console.error(`
|
|
11333
|
-
To use a different environment, set CHATROOM_CONVEX_URL:`);
|
|
11334
|
-
console.error(` CHATROOM_CONVEX_URL=${otherUrls[0]} chatroom <command>`);
|
|
11335
|
-
console.error(`
|
|
11336
|
-
Or to authenticate for the current environment:`);
|
|
11337
|
-
}
|
|
11338
|
-
console.error(` chatroom auth login`);
|
|
11339
|
-
}
|
|
11340
|
-
function formatChatroomIdError(chatroomId) {
|
|
11341
|
-
formatValidationError("chatroom ID format", `ID must be 20-40 characters (got ${chatroomId?.length || 0})`, "20-40 character string");
|
|
11342
|
-
}
|
|
11343
|
-
|
|
11344
11382
|
// src/commands/task-complete.ts
|
|
11345
11383
|
var exports_task_complete = {};
|
|
11346
11384
|
__export(exports_task_complete, {
|
|
@@ -13021,6 +13059,42 @@ async function clearAgentPidEverywhere(ctx, chatroomId, role) {
|
|
|
13021
13059
|
}
|
|
13022
13060
|
clearAgentPid(ctx.machineId, chatroomId, role);
|
|
13023
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
|
+
}
|
|
13024
13098
|
async function recoverAgentState(ctx) {
|
|
13025
13099
|
const entries = listAgentEntries(ctx.machineId);
|
|
13026
13100
|
if (entries.length === 0) {
|
|
@@ -13143,8 +13217,8 @@ async function handleStartAgent(ctx, command) {
|
|
|
13143
13217
|
startResult.onExit((code2, signal) => {
|
|
13144
13218
|
const ts = formatTimestamp();
|
|
13145
13219
|
console.log(`[${ts}] ⚠️ Agent process exited unexpectedly ` + `(PID: ${spawnedPid}, role: ${role}, code: ${code2}, signal: ${signal})`);
|
|
13146
|
-
|
|
13147
|
-
console.log(` ⚠️
|
|
13220
|
+
handleAgentCrashRecovery(ctx, command, spawnedPid).catch((err) => {
|
|
13221
|
+
console.log(` ⚠️ Crash recovery failed for ${role}: ${err.message}`);
|
|
13148
13222
|
});
|
|
13149
13223
|
});
|
|
13150
13224
|
}
|
|
@@ -13386,7 +13460,11 @@ Run any chatroom command first to register this machine,`);
|
|
|
13386
13460
|
connected: true
|
|
13387
13461
|
});
|
|
13388
13462
|
} catch (error) {
|
|
13389
|
-
|
|
13463
|
+
if (isNetworkError(error)) {
|
|
13464
|
+
formatConnectivityError(error, convexUrl);
|
|
13465
|
+
} else {
|
|
13466
|
+
console.error(`❌ Failed to update daemon status: ${error.message}`);
|
|
13467
|
+
}
|
|
13390
13468
|
releaseLock();
|
|
13391
13469
|
process.exit(1);
|
|
13392
13470
|
}
|
|
@@ -13513,7 +13591,7 @@ async function daemonStart() {
|
|
|
13513
13591
|
const ctx = await initDaemon();
|
|
13514
13592
|
await startCommandLoop(ctx);
|
|
13515
13593
|
}
|
|
13516
|
-
var MODEL_REFRESH_INTERVAL_MS;
|
|
13594
|
+
var MAX_CRASH_RESTART_ATTEMPTS = 3, CRASH_RESTART_DELAY_MS = 3000, MODEL_REFRESH_INTERVAL_MS;
|
|
13517
13595
|
var init_daemon_start = __esm(() => {
|
|
13518
13596
|
init_pid();
|
|
13519
13597
|
init_api3();
|