cli: gateway subcommands, drop ipc probes

This commit is contained in:
Peter Steinberger
2025-12-09 20:26:38 +00:00
parent 8265829105
commit e84ed61339
5 changed files with 88 additions and 61 deletions

View File

@@ -191,6 +191,7 @@ async function probeTelegram(
export async function getHealthSnapshot(
timeoutMs?: number,
opts?: { probe?: boolean },
): Promise<HealthSummary> {
const cfg = loadConfig();
const linked = await webAuthExists();
@@ -210,7 +211,8 @@ export async function getHealthSnapshot(
const start = Date.now();
const cappedTimeout = Math.max(1000, timeoutMs ?? DEFAULT_TIMEOUT_MS);
const connect = linked ? await probeWebConnect(cappedTimeout) : undefined;
const connect =
linked && opts?.probe ? await probeWebConnect(cappedTimeout) : undefined;
const telegramToken =
process.env.TELEGRAM_BOT_TOKEN ?? cfg.telegram?.botToken ?? "";
@@ -237,10 +239,12 @@ export async function getHealthSnapshot(
}
export async function healthCommand(
opts: { json?: boolean; timeoutMs?: number },
opts: { json?: boolean; timeoutMs?: number; probe?: boolean },
runtime: RuntimeEnv,
) {
const summary = await getHealthSnapshot(opts.timeoutMs);
const summary = await getHealthSnapshot(opts.timeoutMs, {
probe: opts.probe,
});
const fatal =
!summary.web.linked ||
(summary.web.connect && !summary.web.connect.ok) ||

View File

@@ -1,4 +1,5 @@
import type { CliDeps } from "../cli/deps.js";
import { listPortListeners } from "../cli/ports.js";
import { info, success } from "../globals.js";
import type { RuntimeEnv } from "../runtime.js";
import { callGateway, randomIdempotencyKey } from "../gateway/call.js";
@@ -78,8 +79,15 @@ export async function sendCommand(
result = await sendViaGateway();
} catch (err) {
if (!opts.spawnGateway) throw err;
await startGatewayServer(18789);
result = await sendViaGateway();
// Only spawn when nothing is listening.
try {
const listeners = listPortListeners(18789);
if (listeners.length > 0) throw err;
await startGatewayServer(18789);
result = await sendViaGateway();
} catch {
throw err;
}
}
runtime.log(