import { s as loadSymiPlugins } from "./unified-runner-DXjH-prv.js";
import "./registry-Sbac4a4z.js";
import "./paths-By0XjHBk.js";
import "./utils-CTPsqyE_.js";
import { t as createSubsystemLogger } from "./subsystem-CHbO_DkH.js";
import "./auth-profiles-D5nYBj_Z.js";
import "./exec-DuYbft0z.js";
import { c as resolveAgentWorkspaceDir, l as resolveDefaultAgentId } from "./agent-scope-Bnsyyeci.js";
import "./model-selection-CCTzD29o.js";
import "./file-lock-2AecMjCa.js";
import "./agent-paths-BbZSGrUA.js";
import "./pi-embedded-helpers-j1JrlsI0.js";
import { i as loadConfig } from "./config-BngIfn5l.js";
import "./boolean-CbZoNRMn.js";
import "./env-BRnPI9sO.js";
import "./shell-env-Dc3iU7HK.js";
import "./manifest-registry-D1MLZEjS.js";
import "./sandbox-CZGTCone.js";
import "./chrome-38OnGyuN.js";
import "./tailscale-DpKBMIvx.js";
import "./auth-Bkx-QuRN.js";
import "./server-context-DXdk410X.js";
import "./frontmatter-B_jqcova.js";
import "./skills-CYcBtLGH.js";
import "./routes-BwTUoI5h.js";
import "./redact-B3O-RBO1.js";
import "./errors-bI7Tdx75.js";
import "./fs-safe-B0Is-oLk.js";
import "./paths-BWqg8NZT.js";
import "./ssrf-DOZRI5XH.js";
import "./image-ops-BzCBIakN.js";
import "./ports-CB_Iu83U.js";
import "./trash-_YhavPQI.js";
import "./sessions-BCc3THTm.js";
import "./dock-hF45sewN.js";
import "./message-channel-DgjXWzf-.js";
import "./plugins-CF5skkHh.js";
import "./send-CxjvucMO.js";
import "./paths-BtvQ7JvU.js";
import "./thinking-COroyVA5.js";
import "./tokens-0yh2UnJq.js";
import "./deliver-CWMFmMCv.js";
import "./diagnostic-DbT9t0Sh.js";
import "./diagnostic-session-state-DnkpMfCl.js";
import "./model-auth-_C07_3Yr.js";
import "./github-copilot-token-D-FdDfee.js";
import "./models-config-DlXge3Sd.js";
import "./pi-auth-json-D-vdh-nY.js";
import "./session-cost-usage-D3mgssM_.js";
import "./session-utils-CJhcRx3E.js";
import "./with-timeout-CLrF-Yr_.js";
import "./reply-prefix-CtZtkTJK.js";
import "./memory-BFnx3v3_.js";
import "./manager-DG6PODgu.js";
import "./sqlite-BpogPlQW.js";
import "./chunk-BxfKjCUx.js";
import "./markdown-tables-CS1Tvb3z.js";
import "./fetch-guard-JHxT9355.js";
import "./local-roots-2Jb79HZ8.js";
import "./commands-DUzLGgEZ.js";
import "./commands-registry-CwXsDVuO.js";
import "./client-CTrfpKT3.js";
import "./call-Bpjj5p7I.js";
import "./pairing-token-B703A1U3.js";
import "./tool-display-DFOL6UQ9.js";
import "./skills-remote-BcRQTDsZ.js";
import "./workspace-dirs-DCICLTHx.js";
import "./pi-model-discovery-ClQLvlCW.js";
import "./model-catalog-BWurV7gl.js";
import "./skill-commands-DWvXs3lz.js";
import "./pairing-store-Be-ZQK87.js";
import "./exec-approvals-DioSaIeH.js";
import "./nodes-screen-Cp5QP3ET.js";
import "./breakdown-B_Dhhm3K.js";
import "./control-service-CUreKVeY.js";
import "./stagger-DQs772BN.js";
import "./channel-selection-H1qOf0q-.js";
import "./delivery-queue-OAc7hsIs.js";
import "./bindings-DIhsYGa_.js";
import "./resolve-route-Du0VftVs.js";
import "./links-Bqr0FxXx.js";
import "./cli-utils-CuyGL3rq.js";
import "./help-format-7hFcsqss.js";
import "./progress-swt2y17x.js";
import "./memory-cli-CHNghdrm.js";
import "./logging-BWknayJl.js";
import "./replies-B_3j7R_Q.js";
import "./pi-tools.policy-CvAqjEH9.js";
import "./model-Cwbcw-km.js";

//#region src/plugins/cli.ts
const log = createSubsystemLogger("plugins");
function registerPluginCliCommands(program, cfg) {
	const config = cfg ?? loadConfig();
	const workspaceDir = resolveAgentWorkspaceDir(config, resolveDefaultAgentId(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 = loadSymiPlugins({
		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 };