import { Cd as isTruthyEnvValue } from "./agent-scope-CLn_Ws3B.js";
import { d as defaultRuntime } from "./errors-Dx3S3Nrp.js";
import { C as walletSetupCommand, D as walletStatusCommand, E as walletSignerServeCommand, S as walletRotateKeysCommand, T as walletSignerDoctorCommand, _ as walletLimitOrdersConfigureCommand, a as walletCustodyInitCommand, b as walletProviderConfigureCommand, c as walletInboundPollCommand, d as walletKeystoreImportCommand, f as walletKeystoreInitCommand, g as walletKeystoreValidateCommand, h as walletKeystoreStatusCommand, i as walletCanaryCommand, l as walletInboundReconcileCommand, m as walletKeystorePassphraseRotateCommand, o as walletCustodyLockCommand, p as walletKeystorePassphraseInitCommand, s as walletInboundListCommand, u as walletKeystoreExportCommand, v as walletMigrateCommand, w as walletSignerBrokerCommand, x as walletRoleSetCommand, y as walletPolicyProfileApplyCommand } from "./wallet-BPiknFdt.js";
import { n as runCommandWithRuntime } from "./cli-utils-DJ7Nfw8J.js";
import { o as hasHelpOrVersion, r as getPrimaryCommand, t as buildParseArgv } from "./argv-BqQeWVYw.js";
import { r as resolveActionArgs } from "./helpers-btYENKQf.js";

//#region src/cli/program/action-reparse.ts
async function reparseProgramFromActionArgs(program, actionArgs) {
	const actionCommand = actionArgs.at(-1);
	const rawArgs = (actionCommand?.parent ?? program).rawArgs;
	const actionArgsList = resolveActionArgs(actionCommand);
	const fallbackArgv = actionCommand?.name() ? [actionCommand.name(), ...actionArgsList] : actionArgsList;
	const parseArgv = buildParseArgv({
		programName: program.name(),
		rawArgs,
		fallbackArgv
	});
	await program.parseAsync(parseArgv);
}

//#endregion
//#region src/cli/program/command-tree.ts
function removeCommand(program, command) {
	const commands = program.commands;
	const index = commands.indexOf(command);
	if (index < 0) return false;
	commands.splice(index, 1);
	return true;
}
function removeCommandByName(program, name) {
	const existing = program.commands.find((command) => command.name() === name);
	if (!existing) return false;
	return removeCommand(program, existing);
}

//#endregion
//#region src/cli/program/register.subclis.ts
const shouldRegisterPrimaryOnly = (argv) => {
	if (isTruthyEnvValue(process.env.FASED_DISABLE_LAZY_SUBCOMMANDS)) return false;
	if (hasHelpOrVersion(argv)) return false;
	return true;
};
const shouldEagerRegisterSubcommands = (_argv) => {
	return isTruthyEnvValue(process.env.FASED_DISABLE_LAZY_SUBCOMMANDS);
};
const loadConfig = async () => {
	return (await import("./agent-scope-CLn_Ws3B.js").then((n) => n.wn)).loadConfig();
};
const entries = [
	{
		name: "start",
		description: "Start runtime in gateway or managed mode",
		hasSubcommands: false,
		register: async (program) => {
			(await import("./register.start-3R1jzJAg.js")).registerStartCommand(program);
		}
	},
	{
		name: "managed",
		description: "Managed public startup helpers",
		hasSubcommands: true,
		register: async (program) => {
			(await import("./register.managed-CCNGGKgP.js")).registerManagedCommand(program);
		}
	},
	{
		name: "acp",
		description: "Agent Control Protocol tools",
		hasSubcommands: true,
		register: async (program) => {
			(await import("./acp-cli-CILuOXHP.js")).registerAcpCli(program);
		}
	},
	{
		name: "gateway",
		description: "Run, inspect, and query the WebSocket Gateway",
		hasSubcommands: true,
		register: async (program) => {
			(await import("./gateway-cli-CNCA_gcT.js")).registerGatewayCli(program);
		}
	},
	{
		name: "mining",
		description: "Operate SAT mining from the CLI",
		hasSubcommands: true,
		register: async (program) => {
			(await import("./mining-cli-B8r_1Hg9.js")).registerMiningCli(program);
		}
	},
	{
		name: "sat",
		description: "SAT protocol operator tools",
		hasSubcommands: true,
		register: async (program) => {
			(await import("./sat-cli-CzeDDANl.js")).registerSatCli(program);
		}
	},
	{
		name: "federation",
		description: "Inspect federation and hosted routing state",
		hasSubcommands: true,
		register: async (program) => {
			(await import("./federation-cli-C8eLvqXe.js")).registerFederationCli(program);
		}
	},
	{
		name: "daemon",
		description: "Gateway service (legacy alias)",
		hasSubcommands: true,
		register: async (program) => {
			(await import("./daemon-cli-DDUjmEow.js").then((n) => n.t)).registerDaemonCli(program);
		}
	},
	{
		name: "logs",
		description: "Tail gateway file logs via RPC",
		hasSubcommands: false,
		register: async (program) => {
			(await import("./logs-cli-DoKm6M1i.js")).registerLogsCli(program);
		}
	},
	{
		name: "system",
		description: "System events, heartbeat, and presence",
		hasSubcommands: true,
		register: async (program) => {
			(await import("./system-cli-BMpwtYmU.js")).registerSystemCli(program);
		}
	},
	{
		name: "models",
		description: "Discover, scan, and configure models",
		hasSubcommands: true,
		register: async (program) => {
			(await import("./models-cli-Bl8xk6-0.js")).registerModelsCli(program);
		}
	},
	{
		name: "providers",
		description: "Review provider manifests and model catalogs",
		hasSubcommands: true,
		register: async (program) => {
			(await import("./providers-cli-BG5_Tu3M.js")).registerProvidersCli(program);
		}
	},
	{
		name: "approvals",
		description: "Manage exec approvals (gateway or node host)",
		hasSubcommands: true,
		register: async (program) => {
			(await import("./exec-approvals-cli-BHhFcert.js")).registerExecApprovalsCli(program);
		}
	},
	{
		name: "nodes",
		description: "Manage gateway-owned node pairing and node commands",
		hasSubcommands: true,
		register: async (program) => {
			(await import("./nodes-cli-DSZS2m2H.js")).registerNodesCli(program);
		}
	},
	{
		name: "devices",
		description: "Device pairing + token management",
		hasSubcommands: true,
		register: async (program) => {
			(await import("./devices-cli-BGQ5GbPF.js")).registerDevicesCli(program);
		}
	},
	{
		name: "node",
		description: "Run and manage the headless node host service",
		hasSubcommands: true,
		register: async (program) => {
			(await import("./node-cli-Cqh8buCU.js")).registerNodeCli(program);
		}
	},
	{
		name: "sandbox",
		description: "Manage sandbox containers for agent isolation",
		hasSubcommands: true,
		register: async (program) => {
			(await import("./sandbox-cli-CqUHfq55.js")).registerSandboxCli(program);
		}
	},
	{
		name: "tui",
		description: "Open a terminal UI connected to the Gateway",
		hasSubcommands: false,
		register: async (program) => {
			(await import("./tui-cli-dq7xafwR.js")).registerTuiCli(program);
		}
	},
	{
		name: "task",
		description: "Manage scheduled Agent tasks",
		hasSubcommands: true,
		register: async (program) => {
			(await import("./cron-cli-D3Dznk0V.js")).registerTaskCli(program);
		}
	},
	{
		name: "cron",
		description: "Manage scheduled Agent tasks (compatibility alias)",
		hasSubcommands: true,
		register: async (program) => {
			(await import("./cron-cli-D3Dznk0V.js")).registerCronCli(program, {
				commandName: "cron",
				description: "Manage scheduled Agent tasks (compatibility alias)",
				docsPath: "/cli/task",
				docsLabel: "docs.fased.ai/cli/task"
			});
		}
	},
	{
		name: "dns",
		description: "DNS helpers for wide-area discovery (Tailscale + CoreDNS)",
		hasSubcommands: true,
		register: async (program) => {
			(await import("./dns-cli-CYaQ5-P6.js")).registerDnsCli(program);
		}
	},
	{
		name: "docs",
		description: "Search the live FasedAgent docs",
		hasSubcommands: false,
		register: async (program) => {
			(await import("./docs-cli-EvkZDsTD.js")).registerDocsCli(program);
		}
	},
	{
		name: "hooks",
		description: "Manage internal agent hooks",
		hasSubcommands: true,
		register: async (program) => {
			(await import("./hooks-cli-FhVd5CE-.js")).registerHooksCli(program);
		}
	},
	{
		name: "webhooks",
		description: "Webhook helpers and integrations",
		hasSubcommands: true,
		register: async (program) => {
			(await import("./webhooks-cli-BBmeN9Sf.js")).registerWebhooksCli(program);
		}
	},
	{
		name: "qr",
		description: "Generate iOS pairing QR/setup code",
		hasSubcommands: false,
		register: async (program) => {
			(await import("./qr-cli-DT4i03IY.js")).registerQrCli(program);
		}
	},
	{
		name: "pairing",
		description: "Secure DM pairing (approve inbound requests)",
		hasSubcommands: true,
		register: async (program) => {
			const { registerPluginCliCommands } = await import("./cli-Ctvy4-cz.js");
			registerPluginCliCommands(program, await loadConfig());
			(await import("./pairing-cli-Cru49qsb.js")).registerPairingCli(program);
		}
	},
	{
		name: "plugins",
		description: "Manage FasedAgent plugins and extensions",
		hasSubcommands: true,
		register: async (program) => {
			(await import("./plugins-cli-CXa9m7-A.js")).registerPluginsCli(program);
			const { registerPluginCliCommands } = await import("./cli-Ctvy4-cz.js");
			registerPluginCliCommands(program, await loadConfig());
		}
	},
	{
		name: "channels",
		description: "Manage connected chat channels (Telegram, Discord, etc.)",
		hasSubcommands: true,
		register: async (program) => {
			(await import("./channels-cli-NoUnbEgC.js")).registerChannelsCli(program);
		}
	},
	{
		name: "directory",
		description: "Lookup contact and group IDs (self, peers, groups) for supported chat channels",
		hasSubcommands: true,
		register: async (program) => {
			(await import("./directory-cli-BWBaje0Y.js")).registerDirectoryCli(program);
		}
	},
	{
		name: "security",
		description: "Security tools and local config audits",
		hasSubcommands: true,
		register: async (program) => {
			(await import("./security-cli-DNlCSlQR.js")).registerSecurityCli(program);
		}
	},
	{
		name: "secrets",
		description: "Secrets runtime reload controls",
		hasSubcommands: true,
		register: async (program) => {
			(await import("./secrets-cli-B_7An3tW.js")).registerSecretsCli(program);
		}
	},
	{
		name: "skills",
		description: "List and inspect available skills",
		hasSubcommands: true,
		register: async (program) => {
			(await import("./skills-cli-1Sz8GmjX.js")).registerSkillsCli(program);
		}
	},
	{
		name: "update",
		description: "Update FasedAgent and inspect update channel status",
		hasSubcommands: true,
		register: async (program) => {
			(await import("./update-cli-Cq47v0X_.js")).registerUpdateCli(program);
		}
	},
	{
		name: "completion",
		description: "Generate shell completion script",
		hasSubcommands: false,
		register: async (program) => {
			(await import("./completion-cli-Bd9iPo4A.js").then((n) => n.n)).registerCompletionCli(program);
		}
	}
];
function getSubCliEntries() {
	return entries;
}
function getSubCliCommandsWithSubcommands() {
	return entries.filter((entry) => entry.hasSubcommands).map((entry) => entry.name);
}
async function registerSubCliByName(program, name) {
	const entry = entries.find((candidate) => candidate.name === name);
	if (!entry) return false;
	removeCommandByName(program, entry.name);
	await entry.register(program);
	return true;
}
function registerLazyCommand(program, entry) {
	const placeholder = program.command(entry.name).description(entry.description);
	placeholder.allowUnknownOption(true);
	placeholder.allowExcessArguments(true);
	placeholder.action(async (...actionArgs) => {
		removeCommand(program, placeholder);
		await entry.register(program);
		await reparseProgramFromActionArgs(program, actionArgs);
	});
}
function registerSubCliCommands(program, argv = process.argv) {
	if (shouldEagerRegisterSubcommands(argv)) {
		for (const entry of entries) entry.register(program);
		return;
	}
	const primary = getPrimaryCommand(argv);
	if (primary && shouldRegisterPrimaryOnly(argv)) {
		const entry = entries.find((candidate) => candidate.name === primary);
		if (entry) {
			registerLazyCommand(program, entry);
			return;
		}
	}
	for (const candidate of entries) registerLazyCommand(program, candidate);
}

//#endregion
//#region src/cli/program/register.wallet.ts
function resolvePublicWalletSetupChain(raw) {
	const value = typeof raw === "string" ? raw.trim().toLowerCase() : "";
	if (!value) return;
	if (value === "solana") return "solana";
	throw new Error("Wallet setup is Solana-only. Use --chain solana.");
}
function registerWalletCommands(program) {
	const wallet = program.command("wallet").description("Wallet providers, keystore, custody, and policy status").action(() => {
		wallet.help({ error: true });
	});
	wallet.command("setup").description("Guided Solana wallet setup (create/import local signer wallet)").option("--mode <mode>", "embedded-create|embedded-import|local-signer|turnkey (embedded alias allowed)").option("--chain <chain>", "solana", "solana").option("--wallet-id <id>", "Named wallet id (examples: agent, mining, vault)").option("--wallet-name <value>", "Friendly wallet display name (for UI/skills/plugins)").option("--role <role>", "agent|vault. SAT mining is attached separately.").option("--private-key <value>", "Private key for import mode (prefer env)").option("--api-key <value>", "Hosted wallet provider API key (alchemy/privy mode)").option("--rpc-url <url>", "RPC URL hint for embedded create/import").option("--show-private-key-once", "For embedded-create: print generated private key once", false).option("--confirm-private-key-print <text>", "Required with --show-private-key-once; type \"SHOW PRIVATE KEY\"").option("--turnkey-api-public-key <value>", "Turnkey API public key (turnkey mode)").option("--turnkey-api-private-key <value>", "Turnkey API private key (turnkey mode)").option("--turnkey-organization-id <value>", "Turnkey organization ID (turnkey mode)").option("--turnkey-base-url <value>", "Turnkey base URL override (turnkey mode)").option("--enable-limit-orders", "Store Jupiter API key config for policy-gated wallet actions", false).option("--disable-limit-orders", "Remove stored Jupiter wallet-action config", false).option("--jupiter-api-key <value>", "Jupiter API key for policy-gated wallet actions").option("--jupiter-trigger-api-base-url <url>", "Advanced: Jupiter Trigger API base URL override").option("--non-interactive", "Do not prompt; require mode/inputs", false).option("--no-doctor", "Skip signer doctor in local-signer mode", false).option("--json", "Print JSON output", false).action(async (opts) => {
		await runCommandWithRuntime(defaultRuntime, async () => {
			await walletSetupCommand(defaultRuntime, {
				mode: typeof opts.mode === "string" ? opts.mode : void 0,
				chain: resolvePublicWalletSetupChain(opts.chain),
				walletId: typeof opts.walletId === "string" ? opts.walletId : void 0,
				walletName: typeof opts.walletName === "string" ? opts.walletName : void 0,
				role: typeof opts.role === "string" ? opts.role : void 0,
				privateKey: typeof opts.privateKey === "string" ? opts.privateKey : void 0,
				apiKey: typeof opts.apiKey === "string" ? opts.apiKey : void 0,
				rpcUrl: typeof opts.rpcUrl === "string" ? opts.rpcUrl : void 0,
				showPrivateKeyOnce: Boolean(opts.showPrivateKeyOnce),
				confirmPrivateKeyPrint: typeof opts.confirmPrivateKeyPrint === "string" ? opts.confirmPrivateKeyPrint : void 0,
				turnkeyApiPublicKey: typeof opts.turnkeyApiPublicKey === "string" ? opts.turnkeyApiPublicKey : void 0,
				turnkeyApiPrivateKey: typeof opts.turnkeyApiPrivateKey === "string" ? opts.turnkeyApiPrivateKey : void 0,
				turnkeyOrganizationId: typeof opts.turnkeyOrganizationId === "string" ? opts.turnkeyOrganizationId : void 0,
				turnkeyBaseUrl: typeof opts.turnkeyBaseUrl === "string" ? opts.turnkeyBaseUrl : void 0,
				enableLimitOrders: Boolean(opts.enableLimitOrders),
				disableLimitOrders: Boolean(opts.disableLimitOrders),
				jupiterApiKey: typeof opts.jupiterApiKey === "string" ? opts.jupiterApiKey : void 0,
				jupiterTriggerApiBaseUrl: typeof opts.jupiterTriggerApiBaseUrl === "string" ? opts.jupiterTriggerApiBaseUrl : void 0,
				nonInteractive: Boolean(opts.nonInteractive),
				noDoctor: Boolean(opts.noDoctor),
				json: Boolean(opts.json)
			});
		});
	});
	wallet.command("limit-orders").description("Configure Jupiter Trigger support for policy-gated Agent wallet actions").option("--enable", "Enable Jupiter wallet-action support and store API key config", false).option("--disable", "Remove stored Jupiter wallet-action config", false).option("--jupiter-api-key <value>", "Jupiter API key for policy-gated wallet actions").option("--jupiter-trigger-api-base-url <url>", "Advanced: Jupiter Trigger API base URL override").option("--non-interactive", "Do not prompt; require explicit inputs", false).option("--json", "Print JSON output", false).action(async (opts) => {
		await runCommandWithRuntime(defaultRuntime, async () => {
			await walletLimitOrdersConfigureCommand(defaultRuntime, {
				enable: Boolean(opts.enable),
				disable: Boolean(opts.disable),
				jupiterApiKey: typeof opts.jupiterApiKey === "string" ? opts.jupiterApiKey : void 0,
				jupiterTriggerApiBaseUrl: typeof opts.jupiterTriggerApiBaseUrl === "string" ? opts.jupiterTriggerApiBaseUrl : void 0,
				nonInteractive: Boolean(opts.nonInteractive),
				json: Boolean(opts.json)
			});
		});
	});
	wallet.command("status").description("Show wallet service and policy status").option("--json", "Print JSON output", false).action(async (opts) => {
		await runCommandWithRuntime(defaultRuntime, async () => {
			await walletStatusCommand(defaultRuntime, { json: Boolean(opts.json) });
		});
	});
	wallet.command("rotate-keys").description("Rotate local wallet keys (provider-specific; deprecated command name)").option("--json", "Print JSON output", false).action(async (opts) => {
		await runCommandWithRuntime(defaultRuntime, async () => {
			await walletRotateKeysCommand(defaultRuntime, { json: Boolean(opts.json) });
		});
	});
	const keystore = wallet.command("keystore").description("Manage encrypted local Solana keystore wallets");
	keystore.command("init").description("Create a new encrypted keystore and set provider=embedded-keystore").option("--chain <chain>", "Key type: solana", "solana").option("--wallet-id <id>", "Named wallet id (agent, mining, vault, ...)").option("--out <path>", "Output keystore path (default: <state>/wallet/keystore.v1.enc)").option("--passphrase <value>", "Keystore passphrase (prefer env/file in shell history-safe use)").option("--rpc-url <url>", "Optional RPC URL hint (still typically set via env)").option("--show-private-key-once", "Print generated private key once (dangerous)", false).option("--confirm-private-key-print <text>", "Required with --show-private-key-once; type \"SHOW PRIVATE KEY\"").option("--name <value>", "Named wallet label for UI").option("--role <role>", "agent|vault. SAT mining is attached separately.").option("--force", "Overwrite existing keystore", false).option("--json", "Print JSON output", false).action(async (opts) => {
		await runCommandWithRuntime(defaultRuntime, async () => {
			await walletKeystoreInitCommand(defaultRuntime, {
				json: Boolean(opts.json),
				chain: resolvePublicWalletSetupChain(opts.chain) ?? "solana",
				walletId: typeof opts.walletId === "string" ? opts.walletId : void 0,
				out: typeof opts.out === "string" ? opts.out : void 0,
				passphrase: typeof opts.passphrase === "string" ? opts.passphrase : void 0,
				rpcUrl: typeof opts.rpcUrl === "string" ? opts.rpcUrl : void 0,
				showPrivateKeyOnce: Boolean(opts.showPrivateKeyOnce),
				confirmPrivateKeyPrint: typeof opts.confirmPrivateKeyPrint === "string" ? opts.confirmPrivateKeyPrint : void 0,
				name: typeof opts.name === "string" ? opts.name : void 0,
				role: typeof opts.role === "string" ? opts.role : void 0,
				force: Boolean(opts.force)
			});
		});
	});
	keystore.command("import").description("Import a raw Solana private key into an encrypted keystore and set provider").option("--chain <chain>", "Key type: solana", "solana").option("--wallet-id <id>", "Named wallet id (agent, mining, vault, ...)").option("--private-key <value>", "Solana private key (prefer env FASED_WALLET_PRIVATE_KEY)").option("--out <path>", "Output keystore path (default: <state>/wallet/keystore.v1.enc)").option("--passphrase <value>", "Keystore passphrase (prefer env/file in shell history-safe use)").option("--rpc-url <url>", "Optional RPC URL hint (still typically set via env)").option("--name <value>", "Named wallet label for UI").option("--role <role>", "agent|vault. SAT mining is attached separately.").option("--force", "Overwrite existing keystore", false).option("--json", "Print JSON output", false).action(async (opts) => {
		await runCommandWithRuntime(defaultRuntime, async () => {
			await walletKeystoreImportCommand(defaultRuntime, {
				json: Boolean(opts.json),
				walletId: typeof opts.walletId === "string" ? opts.walletId : void 0,
				out: typeof opts.out === "string" ? opts.out : void 0,
				passphrase: typeof opts.passphrase === "string" ? opts.passphrase : void 0,
				rpcUrl: typeof opts.rpcUrl === "string" ? opts.rpcUrl : void 0,
				privateKey: typeof opts.privateKey === "string" ? opts.privateKey : void 0,
				chain: resolvePublicWalletSetupChain(opts.chain) ?? "solana",
				name: typeof opts.name === "string" ? opts.name : void 0,
				role: typeof opts.role === "string" ? opts.role : void 0,
				force: Boolean(opts.force)
			});
		});
	});
	wallet.command("role set <wallet-id> <role>").description("Set primary Agent fallback or initialize a missing Agent/Vault purpose. Existing purpose stays permanent.").option("--primary", "Make this Agent wallet the primary fallback", false).option("--json", "Print JSON output", false).action(async (walletId, role, opts) => {
		await runCommandWithRuntime(defaultRuntime, async () => {
			await walletRoleSetCommand(defaultRuntime, {
				walletId: String(walletId),
				role: String(role),
				primary: Boolean(opts.primary),
				json: Boolean(opts.json)
			});
		});
	});
	keystore.command("passphrase-init").description("Generate keystore passphrase file (0600) and print env export hint").option("--out <path>", "Passphrase file path (default: <state>/wallet/passphrase)").option("--length <bytes>", "Random bytes length", (v) => Number.parseInt(v, 10)).option("--force", "Overwrite existing file", false).option("--json", "Print JSON output", false).action(async (opts) => {
		await runCommandWithRuntime(defaultRuntime, async () => {
			await walletKeystorePassphraseInitCommand(defaultRuntime, {
				out: typeof opts.out === "string" ? opts.out : void 0,
				length: typeof opts.length === "number" && Number.isFinite(opts.length) ? opts.length : void 0,
				force: Boolean(opts.force),
				json: Boolean(opts.json)
			});
		});
	});
	keystore.command("rotate-passphrase").description("Re-encrypt embedded keystore with a new passphrase and update passphrase file").option("--file <path>", "Passphrase file path (default: env or <state>/wallet/passphrase)").option("--old-passphrase <value>", "Old passphrase (avoid shell history; prefer file/env)").option("--new-passphrase <value>", "New passphrase (omit to auto-generate)").option("--json", "Print JSON output", false).action(async (opts) => {
		await runCommandWithRuntime(defaultRuntime, async () => {
			await walletKeystorePassphraseRotateCommand(defaultRuntime, {
				file: typeof opts.file === "string" ? opts.file : void 0,
				oldPassphrase: typeof opts.oldPassphrase === "string" ? opts.oldPassphrase : void 0,
				newPassphrase: typeof opts.newPassphrase === "string" ? opts.newPassphrase : void 0,
				json: Boolean(opts.json)
			});
		});
	});
	keystore.command("export").description("Export encrypted keystore backup (dangerous if printing)").option("--out <path>", "Write backup copy to path").option("--include-secret", "Include encrypted keystore content in JSON output", false).option("--confirm-include-secret <text>", "Required with --include-secret; type \"EXPORT KEYSTORE\"").option("--json", "Print JSON output", false).action(async (opts) => {
		await runCommandWithRuntime(defaultRuntime, async () => {
			await walletKeystoreExportCommand(defaultRuntime, {
				out: typeof opts.out === "string" ? opts.out : void 0,
				includeSecret: Boolean(opts.includeSecret),
				confirmIncludeSecret: typeof opts.confirmIncludeSecret === "string" ? opts.confirmIncludeSecret : void 0,
				json: Boolean(opts.json)
			});
		});
	});
	keystore.command("status").description("Show embedded keystore presence/unlock status").option("--chain <chain>", "Target chain: solana", "solana").option("--wallet-id <id>", "Named wallet id (uses chain-specific signer env fallback paths)").option("--json", "Print JSON output", false).action(async (opts) => {
		await runCommandWithRuntime(defaultRuntime, async () => {
			await walletKeystoreStatusCommand(defaultRuntime, {
				json: Boolean(opts.json),
				walletId: typeof opts.walletId === "string" ? opts.walletId : void 0,
				chain: resolvePublicWalletSetupChain(opts.chain) ?? "solana"
			});
		});
	});
	keystore.command("validate").description("Validate embedded keystore unlock + RPC connectivity + chain + balance").option("--chain <chain>", "Keystore chain override: solana").option("--wallet-id <id>", "Named wallet id (agent, mining, vault, ...)").option("--json", "Print JSON output", false).action(async (opts) => {
		await runCommandWithRuntime(defaultRuntime, async () => {
			await walletKeystoreValidateCommand(defaultRuntime, {
				json: Boolean(opts.json),
				walletId: typeof opts.walletId === "string" ? opts.walletId : void 0,
				chain: resolvePublicWalletSetupChain(opts.chain)
			});
		});
	});
	wallet.command("provider").description("Configure hosted wallet provider credentials (stored encrypted locally)").command("configure <providerId>").description("Configure hosted provider credentials and set wallet.provider.id").option("--set <key=value>", "Credential field (repeatable)", (v, acc) => [...acc, v], []).option("--rpc-url <url>", "Optional RPC URL hint to store with provider credentials").option("--json", "Print JSON output", false).action(async (providerArg, opts) => {
		const providerId = providerArg === "turnkey" || providerArg === "privy" || providerArg === "alchemy" ? providerArg : null;
		if (!providerId) throw new Error("provider must be one of: turnkey, privy, alchemy");
		await runCommandWithRuntime(defaultRuntime, async () => {
			await walletProviderConfigureCommand(defaultRuntime, {
				providerId,
				json: Boolean(opts.json),
				rpcUrl: typeof opts.rpcUrl === "string" ? opts.rpcUrl : void 0,
				values: Array.isArray(opts.set) ? opts.set.map(String) : []
			});
		});
	});
	wallet.command("policy").description("Wallet policy presets and controls").command("profile <name>").description("Apply wallet policy profile (autonomous-strict|autonomous-moderate|manual-owner)").option("--allow-skill <id>", "Allow skill id (repeatable)", (v, acc) => [...acc, v], []).option("--allow-source <id>", "Allow source id (repeatable)", (v, acc) => [...acc, v], []).option("--json", "Print JSON output", false).action(async (name, opts) => {
		if (name !== "autonomous-strict" && name !== "autonomous-moderate" && name !== "manual-owner") throw new Error("profile must be one of: autonomous-strict, autonomous-moderate, manual-owner");
		await runCommandWithRuntime(defaultRuntime, async () => {
			await walletPolicyProfileApplyCommand(defaultRuntime, {
				profile: name,
				allowSkills: Array.isArray(opts.allowSkill) ? opts.allowSkill.map(String) : [],
				allowSources: Array.isArray(opts.allowSource) ? opts.allowSource.map(String) : [],
				json: Boolean(opts.json)
			});
		});
	});
	const signer = wallet.command("signer").description("Local signer daemon utilities");
	signer.command("serve").description("Removed legacy Node signer entrypoint (use native fased-signerd)").option("--socket <path>", "Unix socket path").option("--read-only", "Read-only mode", false).option("--pid-file <path>", "PID file path").option("--audit-log <path>", "Audit log path").action(async (opts) => {
		await runCommandWithRuntime(defaultRuntime, async () => {
			await walletSignerServeCommand(defaultRuntime, {
				socketPath: typeof opts.socket === "string" ? opts.socket : void 0,
				readOnly: Boolean(opts.readOnly),
				pidFile: typeof opts.pidFile === "string" ? opts.pidFile : void 0,
				auditLog: typeof opts.auditLog === "string" ? opts.auditLog : void 0
			});
		});
	});
	signer.command("broker").description("Run the app-facing local signer broker daemon").option("--socket <path>", "App-facing Unix socket path").option("--backend-socket <path>", "Private backend signer socket path").option("--read-only", "Read-only mode", false).option("--pid-file <path>", "PID file path").option("--audit-log <path>", "Audit log path").action(async (opts) => {
		await runCommandWithRuntime(defaultRuntime, async () => {
			await walletSignerBrokerCommand(defaultRuntime, {
				socketPath: typeof opts.socket === "string" ? opts.socket : void 0,
				backendSocketPath: typeof opts.backendSocket === "string" ? opts.backendSocket : void 0,
				readOnly: Boolean(opts.readOnly),
				pidFile: typeof opts.pidFile === "string" ? opts.pidFile : void 0,
				auditLog: typeof opts.auditLog === "string" ? opts.auditLog : void 0
			});
		});
	});
	signer.command("doctor").description("Validate native/local signer socket, pid, audit log, rpc, and keystore readiness").option("--socket <path>", "Unix socket path").option("--json", "Print JSON output", false).action(async (opts) => {
		await runCommandWithRuntime(defaultRuntime, async () => {
			await walletSignerDoctorCommand(defaultRuntime, {
				socketPath: typeof opts.socket === "string" ? opts.socket : void 0,
				json: Boolean(opts.json)
			});
		});
	});
	wallet.command("custody-init").description("Initialize split-key custody ceremony (device/hot/cold share state)").option("--json", "Print JSON output", false).option("--force", "Overwrite existing custody ceremony state", false).option("--wallet <walletId>", "Target wallet id for per-wallet custody state").option("--device-share <base64>", "Optional pre-generated device share (base64/base64url, 32 bytes)").action(async (opts) => {
		await runCommandWithRuntime(defaultRuntime, async () => {
			await walletCustodyInitCommand(defaultRuntime, {
				json: Boolean(opts.json),
				force: Boolean(opts.force),
				walletId: typeof opts.wallet === "string" ? opts.wallet : void 0,
				deviceShare: typeof opts.deviceShare === "string" ? opts.deviceShare : void 0
			});
		});
	});
	wallet.command("custody-lock").description("Immediately end active custody unlock sessions (clears ephemeral signing material)").option("--host <host>", "Only lock unlock sessions for this host").option("--wallet <walletId>", "Only lock unlock sessions for this wallet").option("--json", "Print JSON output", false).action(async (opts) => {
		await runCommandWithRuntime(defaultRuntime, async () => {
			await walletCustodyLockCommand(defaultRuntime, {
				json: Boolean(opts.json),
				host: typeof opts.host === "string" ? opts.host : void 0,
				walletId: typeof opts.wallet === "string" ? opts.wallet : void 0
			});
		});
	});
	wallet.command("migrate").description("Migrate wallet runtime source").requiredOption("--from <runtime>", "Current runtime: external-docker|external-custom").requiredOption("--to <runtime>", "Target runtime: external-docker|external-custom").option("--json", "Print JSON output", false).action(async (opts) => {
		await runCommandWithRuntime(defaultRuntime, async () => {
			await walletMigrateCommand(defaultRuntime, {
				from: String(opts.from),
				to: String(opts.to),
				json: Boolean(opts.json)
			});
		});
	});
	wallet.command("canary").description("Run real-chain canary checks (and optional recovery drill)").option("--json", "Print JSON output", false).option("--no-require-real-chain", "Allow non-real-chain readiness failures in checks").option("--execute-provider-e2e", "Run provider-level E2E checks (create/address/balance/reject/audit; send when enabled)", false).option("--execute-live-send", "Allow real on-chain send execution in provider E2E (requires canary target env vars)", false).option("--providers <ids>", "Comma-separated provider ids (embedded-keystore,alchemy,turnkey,privy)").option("--execute-recovery-drill", "Run stack down/up recovery drill (external-docker runtime only)", false).action(async (opts) => {
		await runCommandWithRuntime(defaultRuntime, async () => {
			await walletCanaryCommand(defaultRuntime, {
				json: Boolean(opts.json),
				requireRealChain: Boolean(opts.requireRealChain),
				executeRecoveryDrill: Boolean(opts.executeRecoveryDrill),
				executeProviderE2E: Boolean(opts.executeProviderE2E),
				executeLiveSend: Boolean(opts.executeLiveSend),
				providers: typeof opts.providers === "string" ? opts.providers.split(",").map((entry) => entry.trim()).filter(Boolean) : []
			});
		});
	});
	const inbound = wallet.command("inbound").description("Inbound receive/deposit monitoring");
	inbound.command("poll").description("Poll balances and detect inbound/outbound delta events").option("--provider <id>", "Provider id (embedded-keystore|alchemy|turnkey|privy)").option("--wallet-id <id>", "Named wallet id scope").option("--wallet-name <name>", "Named wallet name scope").option("--chain <chain>", "solana|all", "all").option("--json", "Print JSON output", false).action(async (opts) => {
		await runCommandWithRuntime(defaultRuntime, async () => {
			await walletInboundPollCommand(defaultRuntime, {
				json: Boolean(opts.json),
				providerId: typeof opts.provider === "string" ? opts.provider : void 0,
				walletId: typeof opts.walletId === "string" ? opts.walletId : void 0,
				walletName: typeof opts.walletName === "string" ? opts.walletName : void 0,
				chain: opts.chain === "all" ? "all" : resolvePublicWalletSetupChain(opts.chain) ?? "all"
			});
		});
	});
	inbound.command("list").description("List inbound/deposit events from local wallet ledger").option("--provider <id>", "Provider id (embedded-keystore|alchemy|turnkey|privy)").option("--wallet-id <id>", "Named wallet id filter").option("--chain <chain>", "solana").option("--status <status>", "all|detected|confirmed|reconciled|ignored", "all").option("--limit <count>", "Result limit", "100").option("--json", "Print JSON output", false).action(async (opts) => {
		const limit = typeof opts.limit === "string" && opts.limit.trim() ? Number.parseInt(opts.limit, 10) : void 0;
		await runCommandWithRuntime(defaultRuntime, async () => {
			await walletInboundListCommand(defaultRuntime, {
				json: Boolean(opts.json),
				providerId: typeof opts.provider === "string" ? opts.provider : void 0,
				walletId: typeof opts.walletId === "string" ? opts.walletId : void 0,
				chain: resolvePublicWalletSetupChain(opts.chain),
				status: opts.status === "all" || opts.status === "detected" || opts.status === "confirmed" || opts.status === "reconciled" || opts.status === "ignored" ? opts.status : "all",
				limit: Number.isFinite(limit) ? limit : void 0
			});
		});
	});
	inbound.command("reconcile").description("Reconcile inbound events against wallet audit history by tx hash").option("--json", "Print JSON output", false).action(async (opts) => {
		await runCommandWithRuntime(defaultRuntime, async () => {
			await walletInboundReconcileCommand(defaultRuntime, { json: Boolean(opts.json) });
		});
	});
}

//#endregion
//#region src/cli/program/command-registry.ts
const shouldRegisterCorePrimaryOnly = (argv) => {
	if (hasHelpOrVersion(argv)) return false;
	return true;
};
const coreEntries = [
	{
		commands: [{
			name: "setup",
			description: "Initialize local config and agent workspace",
			hasSubcommands: false
		}],
		register: async ({ program }) => {
			(await import("./register.setup-J2tUgD6C.js")).registerSetupCommand(program);
		}
	},
	{
		commands: [{
			name: "onboard",
			description: "Interactive onboarding wizard for gateway, workspace, and skills",
			hasSubcommands: false
		}],
		register: async ({ program }) => {
			(await import("./register.onboard-C7ysxMn6.js")).registerOnboardCommand(program);
		}
	},
	{
		commands: [{
			name: "configure",
			description: "Interactive setup wizard for credentials, channels, gateway, and agent defaults",
			hasSubcommands: false
		}],
		register: async ({ program }) => {
			(await import("./register.configure-DubkYh7h.js")).registerConfigureCommand(program);
		}
	},
	{
		commands: [{
			name: "config",
			description: "Non-interactive config helpers (get/set/unset). Default: starts setup wizard.",
			hasSubcommands: true
		}],
		register: async ({ program }) => {
			(await import("./config-cli-DUNkddbL.js")).registerConfigCli(program);
		}
	},
	{
		commands: [
			{
				name: "doctor",
				description: "Health checks + quick fixes for the gateway and channels",
				hasSubcommands: false
			},
			{
				name: "dashboard",
				description: "Open the Control UI with your current token",
				hasSubcommands: false
			},
			{
				name: "reset",
				description: "Reset local config/state (keeps the CLI installed)",
				hasSubcommands: false
			},
			{
				name: "uninstall",
				description: "Uninstall the gateway service + local data (CLI remains)",
				hasSubcommands: false
			}
		],
		register: async ({ program }) => {
			(await import("./register.maintenance-Corgqhj5.js")).registerMaintenanceCommands(program);
		}
	},
	{
		commands: [{
			name: "message",
			description: "Send, read, and manage messages",
			hasSubcommands: true
		}],
		register: async ({ program, ctx }) => {
			(await import("./register.message-COK8wYD_.js")).registerMessageCommands(program, ctx);
		}
	},
	{
		commands: [{
			name: "memory",
			description: "Search and reindex memory files",
			hasSubcommands: true
		}],
		register: async ({ program }) => {
			(await import("./memory-cli-mMVfDz8Z.js").then((n) => n.t)).registerMemoryCli(program);
		}
	},
	{
		commands: [{
			name: "agent",
			description: "Run one agent turn via the Gateway",
			hasSubcommands: false
		}, {
			name: "agents",
			description: "Manage isolated agents (workspaces, auth, routing)",
			hasSubcommands: true
		}],
		register: async ({ program, ctx }) => {
			(await import("./register.agent-BYkIkPHf.js")).registerAgentCommands(program, { agentChannelOptions: ctx.agentChannelOptions });
		}
	},
	{
		commands: [
			{
				name: "status",
				description: "Show channel health and recent session recipients",
				hasSubcommands: false
			},
			{
				name: "health",
				description: "Fetch health from the running gateway",
				hasSubcommands: false
			},
			{
				name: "sessions",
				description: "List stored conversation sessions",
				hasSubcommands: true
			}
		],
		register: async ({ program }) => {
			(await import("./register.status-health-sessions-DmjjMrJZ.js")).registerStatusHealthSessionsCommands(program);
		}
	},
	{
		commands: [{
			name: "browser",
			description: "Manage FasedAgent's dedicated browser (Chrome/Chromium)",
			hasSubcommands: true
		}],
		register: async ({ program }) => {
			(await import("./browser-cli-DWPlEDFT.js")).registerBrowserCli(program);
		}
	},
	{
		commands: [{
			name: "wallet",
			description: "Wallet providers, keystore, custody, and policy status",
			hasSubcommands: true
		}],
		register: ({ program }) => {
			registerWalletCommands(program);
		}
	}
];
function collectCoreCliCommandNames(predicate) {
	const seen = /* @__PURE__ */ new Set();
	const names = [];
	for (const entry of coreEntries) for (const command of entry.commands) {
		if (predicate && !predicate(command)) continue;
		if (seen.has(command.name)) continue;
		seen.add(command.name);
		names.push(command.name);
	}
	return names;
}
function getCoreCliCommandNames() {
	return collectCoreCliCommandNames();
}
function getCoreCliCommandsWithSubcommands() {
	return collectCoreCliCommandNames((command) => command.hasSubcommands);
}
function removeEntryCommands(program, entry) {
	for (const cmd of entry.commands) removeCommandByName(program, cmd.name);
}
function registerLazyCoreCommand(program, ctx, entry, command) {
	const placeholder = program.command(command.name).description(command.description);
	placeholder.allowUnknownOption(true);
	placeholder.allowExcessArguments(true);
	placeholder.action(async (...actionArgs) => {
		removeEntryCommands(program, entry);
		await entry.register({
			program,
			ctx,
			argv: process.argv
		});
		await reparseProgramFromActionArgs(program, actionArgs);
	});
}
async function registerCoreCliByName(program, ctx, name, argv = process.argv) {
	const entry = coreEntries.find((candidate) => candidate.commands.some((cmd) => cmd.name === name));
	if (!entry) return false;
	removeEntryCommands(program, entry);
	await entry.register({
		program,
		ctx,
		argv
	});
	return true;
}
function registerCoreCliCommands(program, ctx, argv) {
	const primary = getPrimaryCommand(argv);
	if (primary && shouldRegisterCorePrimaryOnly(argv)) {
		const entry = coreEntries.find((candidate) => candidate.commands.some((cmd) => cmd.name === primary));
		if (entry) {
			const cmd = entry.commands.find((c) => c.name === primary);
			if (cmd) registerLazyCoreCommand(program, ctx, entry, cmd);
			return;
		}
	}
	for (const entry of coreEntries) for (const cmd of entry.commands) registerLazyCoreCommand(program, ctx, entry, cmd);
}
function registerProgramCommands(program, ctx, argv = process.argv) {
	registerCoreCliCommands(program, ctx, argv);
	registerSubCliCommands(program, argv);
}

//#endregion
//#region src/cli/program/program-context.ts
const PROGRAM_CONTEXT_SYMBOL = Symbol.for("fased.cli.programContext");
function setProgramContext(program, ctx) {
	program[PROGRAM_CONTEXT_SYMBOL] = ctx;
}
function getProgramContext(program) {
	return program[PROGRAM_CONTEXT_SYMBOL];
}

//#endregion
export { registerCoreCliByName as a, getSubCliEntries as c, getCoreCliCommandsWithSubcommands as i, registerSubCliByName as l, setProgramContext as n, registerProgramCommands as o, getCoreCliCommandNames as r, getSubCliCommandsWithSubcommands as s, getProgramContext as t };