






























@@ -28,6 +28,12 @@ import {
2828} from "./daemon-runtime.js";
2929import { buildGatewayRuntimeHints, formatGatewayRuntimeSummary } from "./doctor-format.js";
3030import type { DoctorOptions, DoctorPrompter } from "./doctor-prompter.js";
31+import {
32+confirmDoctorServiceRepair,
33+EXTERNAL_SERVICE_REPAIR_NOTE,
34+isServiceRepairExternallyManaged,
35+resolveServiceRepairPolicy,
36+} from "./doctor-service-repair-policy.js";
3137import { resolveGatewayInstallToken } from "./gateway-install-token.js";
3238import { formatHealthCheckFailure } from "./health-format.js";
3339import { healthCommand } from "./health.js";
@@ -37,6 +43,7 @@ async function maybeRepairLaunchAgentBootstrap(params: {
3743title: string;
3844runtime: RuntimeEnv;
3945prompter: DoctorPrompter;
46+serviceRepairExternal: boolean;
4047}): Promise<boolean> {
4148if (process.platform !== "darwin") {
4249return false;
@@ -58,8 +65,12 @@ async function maybeRepairLaunchAgentBootstrap(params: {
5865}
59666067note("LaunchAgent is listed but not loaded in launchd.", `${params.title} LaunchAgent`);
68+if (params.serviceRepairExternal) {
69+note(EXTERNAL_SERVICE_REPAIR_NOTE, `${params.title} LaunchAgent`);
70+return false;
71+}
617262-const shouldFix = await params.prompter.confirmRuntimeRepair({
73+const shouldFix = await confirmDoctorServiceRepair(params.prompter, {
6374message: `Repair ${params.title} LaunchAgent bootstrap now?`,
6475initialValue: true,
6576});
@@ -98,6 +109,8 @@ export async function maybeRepairGatewayDaemon(params: {
98109return;
99110}
100111112+const serviceRepairPolicy = resolveServiceRepairPolicy();
113+const serviceRepairExternal = isServiceRepairExternallyManaged(serviceRepairPolicy);
101114const service = resolveGatewayService();
102115// systemd can throw in containers/WSL; treat as "not loaded" and fall back to hints.
103116let loaded = false;
@@ -117,6 +130,7 @@ export async function maybeRepairGatewayDaemon(params: {
117130title: "Gateway",
118131runtime: params.runtime,
119132prompter: params.prompter,
133+ serviceRepairExternal,
120134});
121135await maybeRepairLaunchAgentBootstrap({
122136env: {
@@ -126,6 +140,7 @@ export async function maybeRepairGatewayDaemon(params: {
126140title: "Node",
127141runtime: params.runtime,
128142prompter: params.prompter,
143+ serviceRepairExternal,
129144});
130145if (gatewayRepaired) {
131146loaded = await service.isLoaded({ env: process.env });
@@ -162,10 +177,18 @@ export async function maybeRepairGatewayDaemon(params: {
162177}
163178note("Gateway service not installed.", "Gateway");
164179if (params.cfg.gateway?.mode !== "remote") {
165-const install = await params.prompter.confirmRuntimeRepair({
166-message: "Install gateway service now?",
167-initialValue: true,
168-});
180+if (serviceRepairExternal) {
181+note(EXTERNAL_SERVICE_REPAIR_NOTE, "Gateway");
182+return;
183+}
184+const install = await confirmDoctorServiceRepair(
185+params.prompter,
186+{
187+message: "Install gateway service now?",
188+initialValue: true,
189+},
190+serviceRepairPolicy,
191+);
169192if (install) {
170193const daemonRuntime = await params.prompter.select<GatewayDaemonRuntime>(
171194{
@@ -233,10 +256,18 @@ export async function maybeRepairGatewayDaemon(params: {
233256}
234257235258if (serviceRuntime?.status !== "running") {
236-const start = await params.prompter.confirmRuntimeRepair({
237-message: "Start gateway service now?",
238-initialValue: true,
239-});
259+if (serviceRepairExternal) {
260+note(EXTERNAL_SERVICE_REPAIR_NOTE, "Gateway");
261+return;
262+}
263+const start = await confirmDoctorServiceRepair(
264+params.prompter,
265+{
266+message: "Start gateway service now?",
267+initialValue: true,
268+},
269+serviceRepairPolicy,
270+);
240271if (start) {
241272const restartResult = await service.restart({
242273env: process.env,
@@ -260,10 +291,18 @@ export async function maybeRepairGatewayDaemon(params: {
260291}
261292262293if (serviceRuntime?.status === "running") {
263-const restart = await params.prompter.confirmRuntimeRepair({
264-message: "Restart gateway service now?",
265-initialValue: true,
266-});
294+if (serviceRepairExternal) {
295+note(EXTERNAL_SERVICE_REPAIR_NOTE, "Gateway");
296+return;
297+}
298+const restart = await confirmDoctorServiceRepair(
299+params.prompter,
300+{
301+message: "Restart gateway service now?",
302+initialValue: true,
303+},
304+serviceRepairPolicy,
305+);
267306if (restart) {
268307const restartResult = await service.restart({
269308env: process.env,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。