import { s as normalizeOptionalString } from "./string-coerce-CIT1-v_a.js";
import { t as formatCliCommand } from "./command-format-BeJUeZeT.js";
import { r as toPosixPath } from "./runtime-parse-BxVBKLwd.js";
import { c as resolveGatewayLogPaths } from "./launchd-3MnZPBRv.js";
import { p as classifySystemdUnavailableDetail } from "./systemd-BzKNKK7i.js";
import { t as formatRuntimeStatusWithDetails } from "./runtime-status-D_UlBa5d.js";
//#region src/daemon/container-context.ts
function resolveDaemonContainerContext(env = process.env) {
	return normalizeOptionalString(env.KAIJIBOT_CONTAINER_HINT) || normalizeOptionalString(env.KAIJIBOT_CONTAINER) || null;
}
//#endregion
//#region src/daemon/runtime-format.ts
function formatRuntimeStatus(runtime) {
	if (!runtime) return null;
	const details = [];
	if (runtime.subState) details.push(`sub ${runtime.subState}`);
	if (runtime.lastExitStatus !== void 0) details.push(`last exit ${runtime.lastExitStatus}`);
	if (runtime.lastExitReason) details.push(`reason ${runtime.lastExitReason}`);
	if (runtime.lastRunResult) details.push(`last run ${runtime.lastRunResult}`);
	if (runtime.lastRunTime) details.push(`last run time ${runtime.lastRunTime}`);
	if (runtime.detail) details.push(runtime.detail);
	return formatRuntimeStatusWithDetails({
		status: runtime.status,
		pid: runtime.pid,
		state: runtime.state,
		details
	});
}
//#endregion
//#region src/daemon/runtime-hints.ts
function toDarwinDisplayPath(value) {
	return toPosixPath(value).replace(/^[A-Za-z]:/, "");
}
function buildPlatformRuntimeLogHints(params) {
	const platform = params.platform ?? process.platform;
	const env = params.env ?? process.env;
	if (platform === "darwin") {
		const logs = resolveGatewayLogPaths(env);
		return [`Launchd stdout (if installed): ${toDarwinDisplayPath(logs.stdoutPath)}`, `Launchd stderr (if installed): ${toDarwinDisplayPath(logs.stderrPath)}`];
	}
	if (platform === "linux") return [`Logs: journalctl --user -u ${params.systemdServiceName}.service -n 200 --no-pager`];
	if (platform === "win32") return [`Logs: schtasks /Query /TN "${params.windowsTaskName}" /V /FO LIST`];
	return [];
}
function buildPlatformServiceStartHints(params) {
	const platform = params.platform ?? process.platform;
	const base = [params.installCommand, params.startCommand];
	switch (platform) {
		case "darwin": return [...base, `launchctl bootstrap gui/$UID ${params.launchAgentPlistPath}`];
		case "linux": return [...base, `systemctl --user start ${params.systemdServiceName}.service`];
		case "win32": return [...base, `schtasks /Run /TN "${params.windowsTaskName}"`];
		default: return base;
	}
}
//#endregion
//#region src/daemon/systemd-hints.ts
function isSystemdUnavailableDetail(detail) {
	return classifySystemdUnavailableDetail(detail) !== null;
}
function renderSystemdHeadlessServerHints() {
	return ["On a headless server (SSH/no desktop session): run `sudo loginctl enable-linger $(whoami)` to persist your systemd user session across logins.", "Also ensure XDG_RUNTIME_DIR is set: `export XDG_RUNTIME_DIR=/run/user/$(id -u)`, then retry."];
}
function renderSystemdUnavailableHints(options = {}) {
	if (options.wsl) return [
		"WSL2 needs systemd enabled: edit /etc/wsl.conf with [boot]\\nsystemd=true",
		"Then run: wsl --shutdown (from PowerShell) and reopen your distro.",
		"Verify: systemctl --user status"
	];
	return [
		"systemd user services are unavailable; install/enable systemd or run the gateway under your supervisor.",
		...options.container || options.kind !== "user_bus_unavailable" ? [] : renderSystemdHeadlessServerHints(),
		`If you're in a container, run the gateway in the foreground instead of \`${formatCliCommand("kaijibot gateway")}\`.`
	];
}
//#endregion
export { formatRuntimeStatus as a, buildPlatformServiceStartHints as i, renderSystemdUnavailableHints as n, resolveDaemonContainerContext as o, buildPlatformRuntimeLogHints as r, isSystemdUnavailableDetail as t };
