seclaw 0.1.2 → 0.1.3
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/cli.js +31 -23
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -61,14 +61,12 @@ async function fetchTunnelUrlFromLogs(cwd) {
|
|
|
61
61
|
try {
|
|
62
62
|
const result = await execa(
|
|
63
63
|
"docker",
|
|
64
|
-
["compose", "logs", "cloudflared", "--no-log-prefix"],
|
|
65
|
-
{ cwd
|
|
64
|
+
["compose", "logs", "cloudflared", "--no-log-prefix", "--tail", "50"],
|
|
65
|
+
{ cwd }
|
|
66
66
|
);
|
|
67
67
|
const combined = result.stdout + "\n" + result.stderr;
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
);
|
|
71
|
-
return match ? match[0] : null;
|
|
68
|
+
const matches = [...combined.matchAll(/https:\/\/[a-z0-9-]+\.trycloudflare\.com/g)];
|
|
69
|
+
return matches.length > 0 ? matches[matches.length - 1][0] : null;
|
|
72
70
|
} catch {
|
|
73
71
|
return null;
|
|
74
72
|
}
|
|
@@ -2272,9 +2270,6 @@ async function doctor() {
|
|
|
2272
2270
|
p9.outro("Run again after fixing manually.");
|
|
2273
2271
|
return;
|
|
2274
2272
|
}
|
|
2275
|
-
s.start("Stopping conflicting containers...");
|
|
2276
|
-
await stopExistingSeclaw();
|
|
2277
|
-
s.stop(`${FIX} Cleared conflicting containers`);
|
|
2278
2273
|
for (const check of fixable) {
|
|
2279
2274
|
s.start(`Fixing: ${check.name}...`);
|
|
2280
2275
|
try {
|
|
@@ -2423,12 +2418,12 @@ async function checkTunnel(projectDir) {
|
|
|
2423
2418
|
try {
|
|
2424
2419
|
const result = await execa8(
|
|
2425
2420
|
"docker",
|
|
2426
|
-
["compose", "logs", "cloudflared", "--no-log-prefix"],
|
|
2421
|
+
["compose", "logs", "cloudflared", "--no-log-prefix", "--tail", "50"],
|
|
2427
2422
|
{ cwd: projectDir, env: { ...process.env, COMPOSE_PROJECT_NAME: getProjectName(projectDir) } }
|
|
2428
2423
|
);
|
|
2429
2424
|
const combined = result.stdout + "\n" + result.stderr;
|
|
2430
|
-
const
|
|
2431
|
-
if (
|
|
2425
|
+
const matches = [...combined.matchAll(/https:\/\/[a-z0-9-]+\.trycloudflare\.com/g)];
|
|
2426
|
+
if (matches.length === 0) {
|
|
2432
2427
|
return {
|
|
2433
2428
|
name: "Tunnel",
|
|
2434
2429
|
ok: false,
|
|
@@ -2442,7 +2437,7 @@ async function checkTunnel(projectDir) {
|
|
|
2442
2437
|
}
|
|
2443
2438
|
};
|
|
2444
2439
|
}
|
|
2445
|
-
const tunnelUrl =
|
|
2440
|
+
const tunnelUrl = matches[matches.length - 1][0];
|
|
2446
2441
|
try {
|
|
2447
2442
|
const res = await fetch(`${tunnelUrl}/health`, {
|
|
2448
2443
|
signal: AbortSignal.timeout(1e4)
|
|
@@ -2461,7 +2456,14 @@ async function checkTunnel(projectDir) {
|
|
|
2461
2456
|
name: "Tunnel",
|
|
2462
2457
|
ok: false,
|
|
2463
2458
|
message: `URL found (${pc9.dim(tunnelUrl)}) but not reachable`,
|
|
2464
|
-
tunnelUrl
|
|
2459
|
+
tunnelUrl,
|
|
2460
|
+
fix: async () => {
|
|
2461
|
+
await clearTunnelCache(projectDir);
|
|
2462
|
+
const env = { ...process.env, COMPOSE_PROJECT_NAME: getProjectName(projectDir) };
|
|
2463
|
+
await execa8("docker", ["compose", "restart", "cloudflared"], { cwd: projectDir, env });
|
|
2464
|
+
const newUrl = await getTunnelUrl(projectDir, 20);
|
|
2465
|
+
return newUrl ? `New tunnel: ${newUrl}` : "Restarted cloudflared \u2014 run doctor again";
|
|
2466
|
+
}
|
|
2465
2467
|
};
|
|
2466
2468
|
}
|
|
2467
2469
|
} catch {
|
|
@@ -2498,15 +2500,18 @@ async function checkTelegram(projectDir, tunnelCheck) {
|
|
|
2498
2500
|
}
|
|
2499
2501
|
const wh = whData.result;
|
|
2500
2502
|
const tunnelUrl = tunnelCheck.tunnelUrl || "";
|
|
2503
|
+
const webhookFix = async () => {
|
|
2504
|
+
const freshUrl = await getTunnelUrl(projectDir, 5);
|
|
2505
|
+
if (!freshUrl) return "No tunnel URL available \u2014 fix tunnel first";
|
|
2506
|
+
const ok = await setTelegramWebhook(botToken, freshUrl);
|
|
2507
|
+
return ok ? `Webhook set to ${freshUrl}` : "Could not set webhook";
|
|
2508
|
+
};
|
|
2501
2509
|
if (!wh.url) {
|
|
2502
2510
|
return {
|
|
2503
2511
|
name: `Telegram (${botName})`,
|
|
2504
2512
|
ok: false,
|
|
2505
2513
|
message: "Webhook not set",
|
|
2506
|
-
fix:
|
|
2507
|
-
const ok = await setTelegramWebhook(botToken, tunnelUrl);
|
|
2508
|
-
return ok ? "Webhook set" : "Could not set webhook";
|
|
2509
|
-
} : void 0
|
|
2514
|
+
fix: webhookFix
|
|
2510
2515
|
};
|
|
2511
2516
|
}
|
|
2512
2517
|
if (tunnelUrl && !wh.url.includes(tunnelUrl.replace("https://", ""))) {
|
|
@@ -2514,10 +2519,7 @@ async function checkTelegram(projectDir, tunnelCheck) {
|
|
|
2514
2519
|
name: `Telegram (${botName})`,
|
|
2515
2520
|
ok: false,
|
|
2516
2521
|
message: "Webhook points to old tunnel",
|
|
2517
|
-
fix:
|
|
2518
|
-
const ok = await setTelegramWebhook(botToken, tunnelUrl);
|
|
2519
|
-
return ok ? "Webhook updated" : "Could not update webhook";
|
|
2520
|
-
}
|
|
2522
|
+
fix: webhookFix
|
|
2521
2523
|
};
|
|
2522
2524
|
}
|
|
2523
2525
|
if (wh.last_error_message) {
|
|
@@ -2525,7 +2527,13 @@ async function checkTelegram(projectDir, tunnelCheck) {
|
|
|
2525
2527
|
return {
|
|
2526
2528
|
name: `Telegram (${botName})`,
|
|
2527
2529
|
ok: false,
|
|
2528
|
-
message: `Error ${age}m ago: ${wh.last_error_message}
|
|
2530
|
+
message: `Error ${age}m ago: ${wh.last_error_message}`,
|
|
2531
|
+
fix: async () => {
|
|
2532
|
+
const freshUrl = await getTunnelUrl(projectDir, 5);
|
|
2533
|
+
if (!freshUrl) return "No tunnel URL available \u2014 fix tunnel first";
|
|
2534
|
+
const ok = await setTelegramWebhook(botToken, freshUrl);
|
|
2535
|
+
return ok ? `Webhook re-set to ${freshUrl}` : "Could not set webhook";
|
|
2536
|
+
}
|
|
2529
2537
|
};
|
|
2530
2538
|
}
|
|
2531
2539
|
return {
|