feat: scan extra gateways in doctor

This commit is contained in:
Peter Steinberger
2026-01-07 22:31:08 +01:00
parent e70ff671f5
commit 52e3d28ef4
7 changed files with 74 additions and 20 deletions

View File

@@ -60,6 +60,8 @@ const createConfigIO = vi.fn(() => ({
const findLegacyGatewayServices = vi.fn().mockResolvedValue([]);
const uninstallLegacyGatewayServices = vi.fn().mockResolvedValue([]);
const findExtraGatewayServices = vi.fn().mockResolvedValue([]);
const renderGatewayServiceCleanupHints = vi.fn().mockReturnValue(["cleanup"]);
const resolveGatewayProgramArguments = vi.fn().mockResolvedValue({
programArguments: ["node", "cli", "gateway-daemon", "--port", "18789"],
});
@@ -98,6 +100,11 @@ vi.mock("../daemon/legacy.js", () => ({
uninstallLegacyGatewayServices,
}));
vi.mock("../daemon/inspect.js", () => ({
findExtraGatewayServices,
renderGatewayServiceCleanupHints,
}));
vi.mock("../daemon/program-args.js", () => ({
resolveGatewayProgramArguments,
}));

View File

@@ -24,6 +24,10 @@ import {
} from "../config/config.js";
import { resolveGatewayPort, resolveIsNixMode } from "../config/paths.js";
import { GATEWAY_LAUNCH_AGENT_LABEL } from "../daemon/constants.js";
import {
findExtraGatewayServices,
renderGatewayServiceCleanupHints,
} from "../daemon/inspect.js";
import {
findLegacyGatewayServices,
uninstallLegacyGatewayServices,
@@ -351,6 +355,7 @@ type DoctorOptions = {
workspaceSuggestions?: boolean;
yes?: boolean;
nonInteractive?: boolean;
deep?: boolean;
};
type DoctorPrompter = {
@@ -863,6 +868,34 @@ async function maybeMigrateLegacyGatewayService(
});
}
async function maybeScanExtraGatewayServices(options: DoctorOptions) {
const extraServices = await findExtraGatewayServices(process.env, {
deep: options.deep,
});
if (extraServices.length === 0) return;
note(
extraServices
.map((svc) => `- ${svc.label} (${svc.scope}, ${svc.detail})`)
.join("\n"),
"Other gateway-like services detected",
);
const cleanupHints = renderGatewayServiceCleanupHints();
if (cleanupHints.length > 0) {
note(cleanupHints.map((hint) => `- ${hint}`).join("\n"), "Cleanup hints");
}
note(
[
"Recommendation: run a single gateway per machine.",
"One gateway supports multiple agents.",
"If you need multiple gateways, isolate ports + config/state (see docs: /gateway#multiple-gateways-same-host).",
].join("\n"),
"Gateway recommendation",
);
}
export async function doctorCommand(
runtime: RuntimeEnv = defaultRuntime,
options: DoctorOptions = {},
@@ -939,6 +972,7 @@ export async function doctorCommand(
cfg = await maybeRepairSandboxImages(cfg, runtime, prompter);
await maybeMigrateLegacyGatewayService(cfg, runtime, prompter);
await maybeScanExtraGatewayServices(options);
await noteSecurityWarnings(cfg);