import { t as createLazyImportLoader } from "./lazy-promise-Djskx0qC.js";
import { n as inheritOptionFromParent } from "./command-options-Dhjl7AMa.js";
//#region src/cli/daemon-cli/register-service-commands.ts
const daemonInstallModuleLoader = createLazyImportLoader(() => import("./install.runtime-6bJcjQ33.js"));
const daemonLifecycleModuleLoader = createLazyImportLoader(() => import("./lifecycle.runtime.js"));
const daemonStatusModuleLoader = createLazyImportLoader(() => import("./status.runtime-D8TXD_We.js"));
function loadDaemonInstallModule() {
	return daemonInstallModuleLoader.load();
}
function loadDaemonLifecycleModule() {
	return daemonLifecycleModuleLoader.load();
}
function loadDaemonStatusModule() {
	return daemonStatusModuleLoader.load();
}
function resolveInstallOptions(cmdOpts, command) {
	const parentForce = inheritOptionFromParent(command, "force");
	const parentPort = inheritOptionFromParent(command, "port");
	const parentToken = inheritOptionFromParent(command, "token");
	return {
		...cmdOpts,
		force: Boolean(cmdOpts.force || parentForce),
		port: cmdOpts.port ?? parentPort,
		token: cmdOpts.token ?? parentToken
	};
}
function resolveRpcOptions(cmdOpts, command) {
	const parentToken = inheritOptionFromParent(command, "token");
	const parentPassword = inheritOptionFromParent(command, "password");
	return {
		...cmdOpts,
		token: cmdOpts.token ?? parentToken,
		password: cmdOpts.password ?? parentPassword
	};
}
function resolveRestartOptions(cmdOpts, command) {
	const parentForce = inheritOptionFromParent(command, "force");
	return {
		...cmdOpts,
		force: Boolean(cmdOpts.force || parentForce),
		safe: Boolean(cmdOpts.safe)
	};
}
function addGatewayServiceCommands(parent, opts) {
	parent.command("status").description(opts?.statusDescription ?? "显示网关服务状态并探测连通性/能力").option("--url <url>", "网关 WebSocket URL（默认来自 config/remote/local）").option("--token <token>", "网关令牌（如需要）").option("--password <password>", "网关密码（password 认证）").option("--timeout <ms>", "超时（毫秒）", "10000").option("--no-probe", "跳过 RPC 探测").option("--require-rpc", "RPC 探测失败时返回非零退出码", false).option("--deep", "扫描系统级服务", false).option("--json", "输出 JSON", false).action(async (cmdOpts, command) => {
		const { runDaemonStatus } = await loadDaemonStatusModule();
		await runDaemonStatus({
			rpc: resolveRpcOptions(cmdOpts, command),
			probe: Boolean(cmdOpts.probe),
			requireRpc: Boolean(cmdOpts.requireRpc),
			deep: Boolean(cmdOpts.deep),
			json: Boolean(cmdOpts.json)
		});
	});
	parent.command("install").description("安装网关服务（launchd/systemd/schtasks）").option("--port <port>", "网关端口").option("--runtime <runtime>", "守护进程运行时（node|bun），默认：node").option("--token <token>", "网关令牌（token 认证）").option("--wrapper <path>", "Executable wrapper for generated service ProgramArguments").option("--force", "若已安装则重新安装/覆盖", false).option("--json", "输出 JSON", false).action(async (cmdOpts, command) => {
		const { runDaemonInstall } = await loadDaemonInstallModule();
		await runDaemonInstall(resolveInstallOptions(cmdOpts, command));
	});
	parent.command("uninstall").description("卸载网关服务（launchd/systemd/schtasks）").option("--json", "输出 JSON", false).action(async (cmdOpts) => {
		const { runDaemonUninstall } = await loadDaemonLifecycleModule();
		await runDaemonUninstall(cmdOpts);
	});
	parent.command("start").description("启动网关服务（launchd/systemd/schtasks）").option("--json", "输出 JSON", false).action(async (cmdOpts) => {
		const { runDaemonStart } = await loadDaemonLifecycleModule();
		await runDaemonStart(cmdOpts);
	});
	parent.command("stop").description("停止网关服务（launchd/systemd/schtasks）").option("--json", "输出 JSON", false).option("--disable", "Persistently suppress KeepAlive/RunAtLoad so the gateway does not respawn until next start (launchd only)", false).action(async (cmdOpts) => {
		const { runDaemonStop } = await loadDaemonLifecycleModule();
		await runDaemonStop(cmdOpts);
	});
	parent.command("restart").description("重启网关服务（launchd/systemd/schtasks）").option("--force", "Restart immediately without waiting for active gateway work", false).option("--safe", "Request an OpenClaw-aware restart after active work drains", false).option("--skip-deferral", "Bypass the safe-restart deferral gate; requires --safe", false).option("--wait <duration>", "Wait duration before forcing restart (ms, 10s, 5m; 0 waits indefinitely)").option("--json", "输出 JSON", false).action(async (cmdOpts, command) => {
		const { runDaemonRestart } = await loadDaemonLifecycleModule();
		await runDaemonRestart(resolveRestartOptions(cmdOpts, command));
	});
}
//#endregion
export { addGatewayServiceCommands as t };
