import { Q as theme, V as danger, _ as defaultRuntime } from "./entry.js";
import "./exec-CzwIUObA.js";
import "./agent-scope-C-Jte08L.js";
import "./model-selection-CMx1evaF.js";
import "./manifest-registry-CVLmi8rz.js";
import "./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 { t as formatDocsLink } from "./links-Dnmd-RS-.js";
import "./progress-CI19Xh3z.js";
import { n as callGatewayFromCli, t as addGatewayClientOptions } from "./gateway-rpc-DpRnrv_i.js";
import fs from "node:fs/promises";

//#region src/cli/symframe-cli.ts
function registerSymframeCli(program) {
	addGatewayClientOptions(program.command("symframe").description("Push cards to the Glass UI symframe (right-column dynamic display)").addHelpText("after", () => `\n${theme.muted("Docs:")} ${formatDocsLink("/cli/symframe", "docs.symi.ai/cli/symframe")}\n`).command("push").description("Push (add/update/remove) a card to the symframe").option("--action <add|update|remove|dwell|release|recall|pin|unpin|setMode>", "Action (default: add). Stage-C verbs (dwell|release|recall|pin|unpin) are id-only — no card body. Stage-D verb (setMode) needs --mode.", "add").option("--id <id>", "Card id (required for update/remove; auto-generated for add)").option("--type <type>", "Renderer type — text | markdown | code | email-draft | pdf | audio | video", "text").option("--intent <intent>", "Card intent (mental-state slot) — holding | weighing | producing | awaiting | drafted | reference").option("--title <title>", "Card title (header text)").option("--body <body>", "Card body text (code source if --type=code)").option("--file <path>", "Read body from file (overrides --body)").option("--language <lang>", "Language hint for --type=code (e.g. ts, py, sh)").option("--url <url>", "Media URL for --type=pdf|audio|video").option("--mime <type>", "MIME type for --type=audio|video (e.g. audio/mpeg)").option("--data <json>", "Extra structured fields merged into the card (e.g. email-draft uses { email: { from, to, subject, body } })").option("--sticky", "Anchor at the bottom of the stack (no dismiss button)", false).option("--force", "Required to update or remove a sticky card (use sparingly)", false).option("--mode <ambient|focus|awaiting|quiet>", "Panel posture for --action=setMode").option("--focused-id <id>", "Optional card id to halo when --mode=focus").option("--json", "Output JSON", false)).action(async (opts) => {
		try {
			const action = (opts.action ?? "add").trim();
			if (!new Set([
				"add",
				"update",
				"remove",
				"dwell",
				"release",
				"recall",
				"pin",
				"unpin",
				"setMode"
			]).has(action)) throw new Error(`--action must be one of: add | update | remove | dwell | release | recall | pin | unpin | setMode (got '${action}')`);
			let bodyText = opts.body;
			if (opts.file) bodyText = await fs.readFile(opts.file, "utf8");
			const params = { action };
			if (opts.id) params.id = opts.id;
			if (opts.force) params.force = true;
			if (action === "setMode") {
				const VALID_MODES = new Set([
					"ambient",
					"focus",
					"awaiting",
					"quiet"
				]);
				if (!opts.mode || !VALID_MODES.has(opts.mode)) throw new Error("--mode is required for setMode and must be one of: ambient | focus | awaiting | quiet");
				params.mode = opts.mode;
				if (opts.focusedId) params.focusedId = opts.focusedId;
				const result = await callGatewayFromCli("chat.symframe.push", opts, params, { expectFinal: false });
				if (opts.json) defaultRuntime.log(JSON.stringify(result ?? { ok: true }, null, 2));
				else defaultRuntime.log("ok");
				return;
			}
			const ID_ONLY_VERBS = new Set([
				"remove",
				"dwell",
				"release",
				"recall",
				"pin",
				"unpin"
			]);
			const REQUIRES_ID = new Set([
				"remove",
				"dwell",
				"release",
				"pin",
				"unpin"
			]);
			if (ID_ONLY_VERBS.has(action)) {
				if (REQUIRES_ID.has(action) && !opts.id) throw new Error(`--id is required for ${action}`);
			} else {
				const card = {};
				if (opts.id) card.id = opts.id;
				if (opts.type) card.type = opts.type;
				if (opts.intent) card.intent = opts.intent;
				if (opts.title) card.title = opts.title;
				if (bodyText !== void 0) card.body = bodyText;
				if (opts.language) card.language = opts.language;
				if (opts.url) card.url = opts.url;
				if (opts.mime) card.mimeType = opts.mime;
				if (opts.data) {
					let parsed;
					try {
						parsed = JSON.parse(opts.data);
					} catch (err) {
						throw new Error(`--data must be valid JSON: ${String(err)}`, { cause: err });
					}
					if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) Object.assign(card, parsed);
					else throw new Error("--data must be a JSON object");
				}
				if (opts.sticky) card.sticky = true;
				const hasContent = opts.title || bodyText !== void 0 || opts.url || opts.data && card.email;
				if (action === "add" && !hasContent) throw new Error("add requires at least --title, --body/--file, --url, or --data with structured content");
				if (action === "update" && !opts.id) throw new Error("--id is required for update");
				if (Object.keys(card).length > 0) params.card = card;
			}
			const result = await callGatewayFromCli("chat.symframe.push", opts, params, { expectFinal: false });
			if (opts.json) defaultRuntime.log(JSON.stringify(result ?? { ok: true }, null, 2));
			else defaultRuntime.log("ok");
		} catch (err) {
			defaultRuntime.error(danger(String(err)));
			defaultRuntime.exit(1);
		}
	});
}

//#endregion
export { registerSymframeCli };