import "./tool-display-B7qTeoCS.js";
import "./paths-D4_LjrY7.js";
import { C as shortenHomePath } from "./utils-BnlaT0eO.js";
import { r as theme } from "./theme-CG-K7m8u.js";
import "./thinking-CKGMvVgd.js";
import "./reply-DbpXq1MH.js";
import "./subsystem-ocBR131w.js";
import { n as defaultRuntime } from "./runtime-CRvfzclG.js";
import "./exec-CZr_EJHt.js";
import { k as ensureAgentWorkspace, v as DEFAULT_AGENT_WORKSPACE_DIR } from "./agent-scope-CVnlY0oG.js";
import "./model-selection-p6J3l4qF.js";
import "./github-copilot-token-CjSKohyA.js";
import "./emitter-oHo8y9ow.js";
import "./sqlite-wYNyDR1B.js";
import "./reliability-Dl7hbRzF.js";
import "./boolean-DGGu1sGA.js";
import "./env-CvUd308i.js";
import "./validation-p1IK70TM.js";
import { a as createConfigIO, d as writeConfigFile } from "./config-DJ3A5x_1.js";
import "./manifest-registry-U2EDFVP4.js";
import "./runner-BZrNCxMY.js";
import "./image-tool.helpers-tqRivaKA.js";
import "./models-config-DLUtus3b.js";
import "./pi-model-discovery-4-XyjjxG.js";
import "./pi-embedded-utils-BraP32ED.js";
import "./redact-DcYCKU6u.js";
import "./pi-embedded-helpers-CLkeTWAT.js";
import "./sandbox-C5rKvtrA.js";
import "./chrome-BQkAVfz8.js";
import "./tailscale-CcUMoDkd.js";
import "./auth-BxKMeEw-.js";
import "./server-context-s_zNpSdX.js";
import "./frontmatter-VFr0KMAQ.js";
import "./skills-CHYyY1lO.js";
import "./routes-CT0DmotX.js";
import "./errors-DbYSuCgv.js";
import "./paths-Ct4sqLyX.js";
import "./ssrf-tneKFjA6.js";
import "./image-ops-C0D77XHD.js";
import "./store-Cdm3Z5cQ.js";
import "./ports-DvLDsgl0.js";
import "./trash-BRBQoy9m.js";
import "./sessions-Ct2d_bGl.js";
import "./message-channel-DSU96OKy.js";
import "./dock-DY0TWaYa.js";
import "./normalize-DgwtBdm-.js";
import "./accounts-BZv5WxME.js";
import "./accounts-DFaskvEN.js";
import "./accounts-T7o73ZSN.js";
import "./bindings-BbaWTQJM.js";
import "./logging-wfRfbMvt.js";
import "./client-36a9DTBg.js";
import "./plugins-DYgcd4QJ.js";
import "./targets-qjNLO5UC.js";
import { o as resolveSessionTranscriptsDir } from "./paths-DRyRQF9o.js";
import "./tool-images-CRPqucMe.js";
import "./image-Dx_UDO2W.js";
import "./fetch-guard-C12KgXTM.js";
import "./api-key-rotation-Bl9Larnz.js";
import "./fetch-Dy3Y7lWo.js";
import "./session-files-DroWN-X3.js";
import "./model-catalog-DyP7lvDH.js";
import "./tokens-DuLZdp8u.js";
import "./heartbeat-BJ0mtjXV.js";
import "./helpers-DAXsRcXO.js";
import "./targets-D3Hd_LiZ.js";
import "./with-timeout-BeRjsuGt.js";
import "./diagnostic-Ct9JySKv.js";
import "./diagnostic-session-state-CjvcsE8F.js";
import "./lanes-s-MZ35vD.js";
import "./reply-payloads-Idpqh_HL.js";
import "./route-reply-C3GnJgPP.js";
import "./tts-pLGM3rbp.js";
import "./audio-Cf4_M2_g.js";
import "./model-p-v6-khS.js";
import "./chat-trace-DE0u11RV.js";
import "./response-prefix-template-ZNVQwQzJ.js";
import "./tool-tracking-BeyzFfAx.js";
import "./memory-cli-D_iCajsu.js";
import "./manager-Be4wtySp.js";
import "./retry-BR_e19Qc.js";
import "./hybrid-oFciuzzr.js";
import "./common-oaZdjdal.js";
import "./send-BFMLircB.js";
import "./chunk-CF0Wb8FK.js";
import "./markdown-tables-BkkSACKz.js";
import "./media-Ce9mjBUa.js";
import "./ir-DDJn3mJR.js";
import "./render-Cz3PVxTW.js";
import "./commands-registry-CvAV0O7w.js";
import "./client-DNPnFy4E.js";
import "./call-C206Z-zx.js";
import "./sessions-helpers-DYJnJN3U.js";
import "./external-content-CNcZgk3W.js";
import "./send-BQth8hb0.js";
import "./channel-activity-C8K3u-iy.js";
import "./fetch-CdBeMr8t.js";
import "./tables-GfMspQYU.js";
import "./server-startup-users-Bb0MWaNU.js";
import "./resolve-route-D-YVS8mL.js";
import "./pairing-store-Z_SXyT9W.js";
import "./replies-AgkcH9tU.js";
import "./reply-prefix-DB7HiPpn.js";
import "./workspace-dirs-C1v5ssUA.js";
import "./skill-commands-vM7RDRiG.js";
import "./pi-tools.policy-C7_kjOAN.js";
import "./send-BKH82oGz.js";
import "./onboard-helpers-B0CkVZ2U.js";
import "./prompt-style-D4OL61iD.js";
import "./onboard-helpers-BvqKOAqv.js";
import "./outbound-attachment-DzzKBoks.js";
import "./targets-B17-mYQK.js";
import "./pairing-labels-BoIZlK5l.js";
import "./send-C5tjqyuP.js";
import "./session-cost-usage-UDBgjJvw.js";
import "./send-XU_khFvN.js";
import "./proxy-CjhP7CG1.js";
import { t as formatDocsLink } from "./links-G4gKCCcI.js";
import { n as runCommandWithRuntime } from "./cli-utils-Cps3tWFt.js";
import "./help-format-DukcHIxz.js";
import "./progress-WmzCxxhb.js";
import "./active-listener-CEwpUvTV.js";
import "./exec-approvals-C7AUcy3J.js";
import "./gateway-DKSm1BrZ.js";
import "./nodes-utils-yMGpHJYN.js";
import "./model-fallback-BPqOLk8z.js";
import "./typed-schema-4lv655ii.js";
import "./knowledge-graph-D4-b38d_.js";
import "./runtime-guard-ChZ6T0fk.js";
import "./env-file-jMSm0wPK.js";
import "./deliver-DhB9l23e.js";
import "./delivery-queue-CKcfhYo3.js";
import { t as hasExplicitOptions } from "./command-options-D9zCKyRh.js";
import "./note-U4_LTORH.js";
import "./clack-prompter-C53smn2y.js";
import "./onboard-auth-B_PG9Lfr.js";
import "./openai-model-default-C9zElP81.js";
import "./shared-BwkO5M-b.js";
import { n as logConfigUpdated, t as formatConfigPath } from "./logging-CgrC2xWs.js";
import "./vllm-setup-BE_da5Bx.js";
import "./systemd-CdTDtFWy.js";
import "./service-tzRBQba1.js";
import "./daemon-runtime-CamLzRLO.js";
import "./daemon-install-helpers-OEyMcFNy.js";
import "./systemd-linger-D4DzdniD.js";
import "./model-picker-NSZcd-8b.js";
import "./onboard-custom-B3TKu9Vn.js";
import "./health-u_Dm-5Ek.js";
import "./onboarding--M0Y1eGc.js";
import "./auth-token-DVpOm5kp.js";
import { t as onboardCommand } from "./onboard-NCAWX59J.js";
import JSON5 from "json5";
import fs from "node:fs/promises";

//#region src/cli/commands/setup.ts
async function readConfigFileRaw(configPath) {
	try {
		const raw = await fs.readFile(configPath, "utf-8");
		const parsed = JSON5.parse(raw);
		if (parsed && typeof parsed === "object") return {
			exists: true,
			parsed
		};
		return {
			exists: true,
			parsed: {}
		};
	} catch {
		return {
			exists: false,
			parsed: {}
		};
	}
}
async function setupCommand(opts, runtime = defaultRuntime) {
	const desiredWorkspace = typeof opts?.workspace === "string" && opts.workspace.trim() ? opts.workspace.trim() : void 0;
	const configPath = createConfigIO().configPath;
	const existingRaw = await readConfigFileRaw(configPath);
	const cfg = existingRaw.parsed;
	const defaults = cfg.agents?.defaults ?? {};
	const workspace = desiredWorkspace ?? defaults.workspace ?? DEFAULT_AGENT_WORKSPACE_DIR;
	const next = {
		...cfg,
		agents: {
			...cfg.agents,
			defaults: {
				...defaults,
				workspace
			}
		}
	};
	if (!existingRaw.exists || defaults.workspace !== workspace) {
		await writeConfigFile(next);
		if (!existingRaw.exists) runtime.log(`Wrote ${formatConfigPath(configPath)}`);
		else logConfigUpdated(runtime, {
			path: configPath,
			suffix: "(set agents.defaults.workspace)"
		});
	} else runtime.log(`Config OK: ${formatConfigPath(configPath)}`);
	const ws = await ensureAgentWorkspace({
		dir: workspace,
		ensureBootstrapFiles: !next.agents?.defaults?.skipBootstrap
	});
	runtime.log(`Workspace OK: ${shortenHomePath(ws.dir)}`);
	const sessionsDir = resolveSessionTranscriptsDir();
	await fs.mkdir(sessionsDir, { recursive: true });
	runtime.log(`Sessions OK: ${shortenHomePath(sessionsDir)}`);
}

//#endregion
//#region src/cli/program/register.setup.ts
function registerSetupCommand(program) {
	program.command("setup").description("Initialize ~/.minion/minion.json and the agent workspace").addHelpText("after", () => `\n${theme.muted("Docs:")} ${formatDocsLink("/cli/setup", "docs.minion.ai/cli/setup")}\n`).option("--workspace <dir>", "Agent workspace directory (default: ~/.minion/workspace; stored as agents.defaults.workspace)").option("--wizard", "Run the interactive onboarding wizard", false).option("--non-interactive", "Run the wizard without prompts", false).option("--mode <mode>", "Wizard mode: local|remote").option("--remote-url <url>", "Remote Gateway WebSocket URL").option("--remote-token <token>", "Remote Gateway token (optional)").action(async (opts, command) => {
		await runCommandWithRuntime(defaultRuntime, async () => {
			const hasWizardFlags = hasExplicitOptions(command, [
				"wizard",
				"nonInteractive",
				"mode",
				"remoteUrl",
				"remoteToken"
			]);
			if (opts.wizard || hasWizardFlags) {
				await onboardCommand({
					workspace: opts.workspace,
					nonInteractive: Boolean(opts.nonInteractive),
					mode: opts.mode,
					remoteUrl: opts.remoteUrl,
					remoteToken: opts.remoteToken
				}, defaultRuntime);
				return;
			}
			await setupCommand({ workspace: opts.workspace }, defaultRuntime);
		});
	});
}

//#endregion
export { registerSetupCommand };