import { o as createSubsystemLogger } from "./entry.js";
import "./auth-profiles-D11Xw15i.js";
import "./exec-CzwIUObA.js";
import { c as resolveAgentWorkspaceDir, l as resolveDefaultAgentId } from "./agent-scope-C-Jte08L.js";
import "./model-selection-CMx1evaF.js";
import "./file-lock-DrmXX3vL.js";
import "./agent-paths-DryQawbH.js";
import "./pi-auth-json-mn8xSJKs.js";
import "./model-B4Btg-Q6.js";
import "./pi-model-discovery-EgBaDO8n.js";
import "./frontmatter-PrEWR41G.js";
import "./skills-cLBEdkqu.js";
import "./manifest-registry-CVLmi8rz.js";
import { i as loadConfig } from "./config-D7TcU4qN.js";
import "./shell-env-CTYaxUs_.js";
import "./client-BOd5o3Kp.js";
import "./call-DTshgdlW.js";
import "./message-channel-DXToSaWK.js";
import "./pairing-token-B-OTYROz.js";
import { m as loadSymiPlugins } from "./subagent-registry-CVhLz4p3.js";
import "./sessions-Dn6VXn4p.js";
import "./plugins-BsEhWvLn.js";
import "./send-Dq252-bi.js";
import "./with-timeout-B9GM8DPj.js";
import "./deliver-DIK2emIV.js";
import "./diagnostic-IdKKvrDQ.js";
import "./diagnostic-session-state-CIjIGxEE.js";
import "./pi-embedded-helpers-BQjRftRI.js";
import "./sandbox-DjKcZavm.js";
import "./chrome-D1eO2jfe.js";
import "./tailscale-FeJ1M0mP.js";
import "./auth-pHRwjgkx.js";
import "./server-context-DrAh6Cgw.js";
import "./routes-wLkmjLj9.js";
import "./redact-Dj3r1_tS.js";
import "./errors-BmdGLmRC.js";
import "./fs-safe-D0xrTzGw.js";
import "./paths-8yCI1Car.js";
import "./ssrf-BZFvPKEu.js";
import "./image-ops-FPBHTBd0.js";
import "./ports-uA7P2qIK.js";
import "./trash-Bx4LIudf.js";
import "./dock-DZ6SgvTh.js";
import "./paths-DtiEyjsC.js";
import "./thinking-BZDIJMl_.js";
import "./model-auth-Byr7Gic_.js";
import "./github-copilot-token-B5y4__YM.js";
import "./models-config-CiR_RUxw.js";
import "./reply-prefix-DV3KhOhL.js";
import "./memory-C02Znuee.js";
import "./manager-DH00nlW8.js";
import "./sqlite-9jF_eajd.js";
import "./chunk-B2lBXhR0.js";
import "./markdown-tables-BEdkErjm.js";
import "./fetch-guard-3_W2W6u_.js";
import "./local-roots-Bm30yHHs.js";
import "./commands-BiW8npr7.js";
import "./commands-registry-D8LQ9fss.js";
import "./tool-display-DxbOx1Kx.js";
import "./tokens-CC6jvm1-.js";
import "./skills-remote-DSGpkPJE.js";
import "./redact-identifier-BOxAUdff.js";
import "./workspace-dirs-wlRR65M3.js";
import "./model-catalog-CzKsiNZA.js";
import "./session-utils-Zpe3t68b.js";
import "./skill-commands-BXP2zJNy.js";
import "./pairing-store-C4KBIVqJ.js";
import "./exec-approvals-DEjIocmZ.js";
import "./nodes-screen-_JvT4DjZ.js";
import "./session-cost-usage-CJWHHY-C.js";
import "./breakdown-Cszrv-Lf.js";
import "./control-service-CG6l_Yap.js";
import "./stagger-DUVGiPYV.js";
import "./channel-selection-CmU8iVio.js";
import "./delivery-queue-B2oigbh4.js";
import "./bindings-BRZBH7eX.js";
import "./resolve-route-BVJ4-d9c.js";
import "./links-Dnmd-RS-.js";
import "./cli-utils-DXfA5936.js";
import "./help-format-Dbp8yEhl.js";
import "./progress-CI19Xh3z.js";
import "./memory-cli-083UJtVJ.js";
import "./logging-UO6tk8Em.js";
import "./replies-CLREUzzB.js";
import "./pi-tools.policy-06k__URR.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 };