import "./pi-embedded-helpers-Ny2JybJV.js";
import { Tt as loadSKYKOIPlugins } from "./reply-CL83zh9t.js";
import { t as createSubsystemLogger } from "./subsystem-hATE68va.js";
import "./paths-VdmjGGyc.js";
import "./theme-C5EwWDWE.js";
import "./ansi-By7x1TI7.js";
import "./utils-D019Z2NU.js";
import "./exec-xrC0ejqg.js";
import { l as resolveKoiWorkspaceDir, r as resolveDefaultKoiId } from "./koi-scope-D8R_V4oO.js";
import "./model-selection-Bue40sP3.js";
import "./dist-CUiRTtgg.js";
import "./dist-cjs-DKbiqPag.js";
import "./boolean-CBeSt-pi.js";
import "./env-Dliiu-O6.js";
import "./github-copilot-token-CNBLk7kR.js";
import { o as loadConfig } from "./config-CJCyYQfd.js";
import "./manifest-registry-oBOOUSYE.js";
import "./plugins-4Dg2aV3Z.js";
import "./sessions-p608GJQF.js";
import "./image-Cm8pagSS.js";
import "./dist-qohLth5U.js";
import "./lib-DySFL26z.js";
import "./src-CuBVmkDD.js";
import "./core-CYIM8X9C.js";
import "./pi-model-discovery-BJB6xKfm.js";
import "./sandbox-CH6Z4NF9.js";
import "./chrome-qnrH3SE9.js";
import "./skills-belB1fF2.js";
import "./routes-B_ID_OU2.js";
import "./server-context-BfQWGTuX.js";
import "./image-ops-D4trOw4b.js";
import "./message-channel-DFpLxeOe.js";
import "./logging-DbUpYaKc.js";
import "./accounts-Grk0tpBF.js";
import "./paths-DeB-Vw2o.js";
import "./tool-images-BotO6WKu.js";
import "./redact-AS2CBwfj.js";
import "./tool-display-DcE_Uu-6.js";
import "./deliver-DaqlX5n9.js";
import "./dispatcher-CvOxCTiO.js";
import "./dist-Cldz93r6.js";
import "./pi-tool-definition-adapter-Bm-MOj6J.js";
import "./manager-M02jv6fr.js";
import "./sqlite-ciTubP4r.js";
import "./warnings-WXNLPyeJ.js";
import "./proxy-from-env-CZI-BeJ4.js";
import "./login-qr-jct4RHB3.js";
import "./channel-summary-CaRm5ceF.js";
import "./device-identity-Bb4mQJBL.js";
import "./net-CgTtDqcj.js";
import "./call-CJHT-9_x.js";
import "./koi-events-mTBifGCl.js";
import "./pairing-store-C3Jk-2f9.js";
import "./links-RRRDj3kH.js";
import "./progress-DpXGZ7eP.js";
import "./node-pairing-C8IUm3Xm.js";
import "./pi-tools.policy-C2-uMacJ.js";
import "./onboard-helpers-BfbPZ2qa.js";
import "./prompt-style-VlLGOsyw.js";
import "./pairing-labels-gxX2Garz.js";
import "./satisfies-Bvl3f_kk.js";
import "./session-cost-usage-C1dZUsv0.js";
import "./control-service-Deb7vSlB.js";
import "./channel-selection-C4X4L8u3.js";
import "./event-log-Bp_kcsW9.js";

//#region src/plugins/cli.ts
const log = createSubsystemLogger("plugins");
function registerPluginCliCommands(program, cfg) {
	const config = cfg ?? loadConfig();
	const workspaceDir = resolveKoiWorkspaceDir(config, resolveDefaultKoiId(config));
	const logger = {
		info: (msg) => log.info(msg),
		warn: (msg) => log.warn(msg),
		error: (msg) => log.error(msg),
		debug: (msg) => log.debug(msg)
	};
	const registry = loadSKYKOIPlugins({
		config,
		workspaceDir,
		logger
	});
	const existingCommands = new Set(program.commands.map((cmd) => cmd.name()));
	for (const entry of registry.cliRegistrars) {
		if (entry.commands.length > 0) {
			const overlaps = entry.commands.filter((command) => existingCommands.has(command));
			if (overlaps.length > 0) {
				log.debug(`plugin CLI register skipped (${entry.pluginId}): command already registered (${overlaps.join(", ")})`);
				continue;
			}
		}
		try {
			const result = entry.register({
				program,
				config,
				workspaceDir,
				logger
			});
			if (result && typeof result.then === "function") result.catch((err) => {
				log.warn(`plugin CLI register failed (${entry.pluginId}): ${String(err)}`);
			});
			for (const command of entry.commands) existingCommands.add(command);
		} catch (err) {
			log.warn(`plugin CLI register failed (${entry.pluginId}): ${String(err)}`);
		}
	}
}

//#endregion
export { registerPluginCliCommands };