import { c as normalizeOptionalString } from "./string-coerce-Bje8XVt9.js";
import { t as isBlockedObjectKey } from "./prototype-keys-B9rjoUHr.js";
import { d as isInstalledPluginEnabled } from "./installed-plugin-index-store-qF5SAerh.js";
import { t as loadPluginManifestRegistryForInstalledIndex } from "./manifest-registry-installed-DvKIF08D.js";
import { v as loadPluginRegistrySnapshot } from "./plugin-registry-D41oHopy.js";
//#region src/channels/plugins/read-only-command-defaults.ts
const SAFE_MANIFEST_CHANNEL_ID_PATTERN = /^[a-z0-9][a-z0-9_-]{0,63}$/i;
function isSafeManifestChannelId(channelId) {
	return SAFE_MANIFEST_CHANNEL_ID_PATTERN.test(channelId) && !isBlockedObjectKey(channelId);
}
function readOwnRecordValue(record, key) {
	if (isBlockedObjectKey(key) || !Object.prototype.hasOwnProperty.call(record, key)) return;
	return record[key];
}
function normalizeChannelCommandDefaults(value) {
	if (!value) return;
	const nativeCommandsAutoEnabled = typeof value.nativeCommandsAutoEnabled === "boolean" ? value.nativeCommandsAutoEnabled : void 0;
	const nativeSkillsAutoEnabled = typeof value.nativeSkillsAutoEnabled === "boolean" ? value.nativeSkillsAutoEnabled : void 0;
	if (nativeCommandsAutoEnabled === void 0 && nativeSkillsAutoEnabled === void 0) return;
	const defaults = {};
	if (nativeCommandsAutoEnabled !== void 0) defaults.nativeCommandsAutoEnabled = nativeCommandsAutoEnabled;
	if (nativeSkillsAutoEnabled !== void 0) defaults.nativeSkillsAutoEnabled = nativeSkillsAutoEnabled;
	return defaults;
}
function resolveReadOnlyChannelCommandDefaults(channelId, options) {
	const normalizedChannelId = normalizeOptionalString(channelId) ?? "";
	if (!normalizedChannelId || !isSafeManifestChannelId(normalizedChannelId)) return;
	const index = loadPluginRegistrySnapshot({
		config: options.config,
		stateDir: options.stateDir,
		workspaceDir: options.workspaceDir,
		env: options.env ?? process.env
	});
	const registry = loadPluginManifestRegistryForInstalledIndex({
		index,
		config: options.config,
		workspaceDir: options.workspaceDir,
		env: options.env ?? process.env,
		includeDisabled: true
	});
	for (const record of registry.plugins) {
		if (!record.channels.includes(normalizedChannelId)) continue;
		if (record.id !== normalizedChannelId && record.channelCatalogMeta?.id !== normalizedChannelId) continue;
		if (!isInstalledPluginEnabled(index, record.id, options.config)) continue;
		const channelConfigValue = record.channelConfigs ? readOwnRecordValue(record.channelConfigs, normalizedChannelId) : void 0;
		const commands = normalizeChannelCommandDefaults((channelConfigValue && typeof channelConfigValue === "object" && !Array.isArray(channelConfigValue) ? channelConfigValue : void 0)?.commands ?? record.channelCatalogMeta?.commands);
		if (commands) return commands;
	}
}
//#endregion
export { resolveReadOnlyChannelCommandDefaults as i, normalizeChannelCommandDefaults as n, readOwnRecordValue as r, isSafeManifestChannelId as t };
