{"version":3,"file":"config-selector.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/config-selector.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * TUI component for managing package resources (enable/disable)\n */\n\nimport { homedir } from \"node:os\";\nimport { basename, dirname, join, relative } from \"node:path\";\nimport {\n\ttype Component,\n\tContainer,\n\ttype Focusable,\n\tgetKeybindings,\n\tInput,\n\tmatchesKey,\n\tSpacer,\n\ttruncateToWidth,\n\tvisibleWidth,\n} from \"@earendil-works/pi-tui\";\nimport { CONFIG_DIR_NAME } from \"../../../config.ts\";\nimport type { PathMetadata, ResolvedPaths, ResolvedResource } from \"../../../core/package-manager.ts\";\nimport type { PackageSource, SettingsManager } from \"../../../core/settings-manager.ts\";\nimport { canonicalizePath, isLocalPath, resolvePath } from \"../../../utils/paths.ts\";\nimport { theme } from \"../theme/theme.ts\";\nimport { DynamicBorder } from \"./dynamic-border.ts\";\nimport { keyHint, rawKeyHint } from \"./keybinding-hints.ts\";\n\ntype ResourceType = \"extensions\" | \"skills\" | \"prompts\" | \"themes\";\ntype ConfigWriteScope = \"global\" | \"project\";\ntype SettingsScope = \"user\" | \"project\";\ntype ProjectOverrideState = \"inherit\" | \"load\" | \"unload\";\nexport type ScopedResolvedPaths = Record<ConfigWriteScope, ResolvedPaths>;\n\nconst RESOURCE_TYPES = [\"extensions\", \"skills\", \"prompts\", \"themes\"] as const satisfies readonly ResourceType[];\n\nconst RESOURCE_TYPE_LABELS: Record<ResourceType, string> = {\n\textensions: \"Extensions\",\n\tskills: \"Skills\",\n\tprompts: \"Prompts\",\n\tthemes: \"Themes\",\n};\n\ninterface ResourceItem {\n\tpath: string;\n\tenabled: boolean;\n\tmetadata: PathMetadata;\n\tresourceType: ResourceType;\n\tdisplayName: string;\n\tgroupKey: string;\n\tsubgroupKey: string;\n}\n\ninterface ResourceSubgroup {\n\ttype: ResourceType;\n\tlabel: string;\n\titems: ResourceItem[];\n}\n\ninterface ResourceGroup {\n\tkey: string;\n\tlabel: string;\n\tscope: \"user\" | \"project\" | \"temporary\";\n\torigin: \"package\" | \"top-level\";\n\tsource: string;\n\tsubgroups: ResourceSubgroup[];\n}\n\nfunction formatBaseDir(baseDir: string): string {\n\tconst homeDir = homedir();\n\tlet displayPath: string;\n\n\tif (baseDir === homeDir) {\n\t\tdisplayPath = \"~\";\n\t} else if (baseDir.startsWith(homeDir)) {\n\t\t// Replace home prefix with ~, normalize separators for display\n\t\tconst rest = baseDir.slice(homeDir.length);\n\t\tdisplayPath = `~${rest.replace(/\\\\/g, \"/\")}`;\n\t} else {\n\t\tdisplayPath = baseDir.replace(/\\\\/g, \"/\");\n\t}\n\n\treturn displayPath.endsWith(\"/\") ? displayPath : `${displayPath}/`;\n}\n\nfunction getGroupLabel(metadata: PathMetadata, agentDir: string): string {\n\tif (metadata.origin === \"package\") {\n\t\treturn `${metadata.source} (${metadata.scope})`;\n\t}\n\t// Top-level resources\n\tif (metadata.source === \"auto\") {\n\t\tif (metadata.baseDir) {\n\t\t\treturn metadata.scope === \"user\"\n\t\t\t\t? `User (${formatBaseDir(metadata.baseDir)})`\n\t\t\t\t: `Project (${formatBaseDir(metadata.baseDir)})`;\n\t\t}\n\t\treturn metadata.scope === \"user\" ? `User (${formatBaseDir(agentDir)})` : `Project (${CONFIG_DIR_NAME}/)`;\n\t}\n\treturn metadata.scope === \"user\" ? \"User settings\" : \"Project settings\";\n}\n\nfunction buildGroups(resolved: ResolvedPaths, agentDir: string): ResourceGroup[] {\n\tconst groupMap = new Map<string, ResourceGroup>();\n\n\tconst addToGroup = (resources: ResolvedResource[], resourceType: ResourceType) => {\n\t\tfor (const res of resources) {\n\t\t\tconst { path, enabled, metadata } = res;\n\t\t\tconst groupKey = `${metadata.origin}:${metadata.scope}:${metadata.source}:${metadata.baseDir ?? \"\"}`;\n\n\t\t\tif (!groupMap.has(groupKey)) {\n\t\t\t\tgroupMap.set(groupKey, {\n\t\t\t\t\tkey: groupKey,\n\t\t\t\t\tlabel: getGroupLabel(metadata, agentDir),\n\t\t\t\t\tscope: metadata.scope,\n\t\t\t\t\torigin: metadata.origin,\n\t\t\t\t\tsource: metadata.source,\n\t\t\t\t\tsubgroups: [],\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst group = groupMap.get(groupKey)!;\n\t\t\tconst subgroupKey = `${groupKey}:${resourceType}`;\n\n\t\t\tlet subgroup = group.subgroups.find((sg) => sg.type === resourceType);\n\t\t\tif (!subgroup) {\n\t\t\t\tsubgroup = {\n\t\t\t\t\ttype: resourceType,\n\t\t\t\t\tlabel: RESOURCE_TYPE_LABELS[resourceType],\n\t\t\t\t\titems: [],\n\t\t\t\t};\n\t\t\t\tgroup.subgroups.push(subgroup);\n\t\t\t}\n\n\t\t\tconst fileName = basename(path);\n\t\t\tconst parentFolder = basename(dirname(path));\n\t\t\tlet displayName: string;\n\t\t\tif (resourceType === \"extensions\" && parentFolder !== \"extensions\") {\n\t\t\t\tdisplayName = `${parentFolder}/${fileName}`;\n\t\t\t} else if (resourceType === \"skills\" && fileName === \"SKILL.md\") {\n\t\t\t\tdisplayName = parentFolder;\n\t\t\t} else {\n\t\t\t\tdisplayName = fileName;\n\t\t\t}\n\t\t\tsubgroup.items.push({\n\t\t\t\tpath,\n\t\t\t\tenabled,\n\t\t\t\tmetadata,\n\t\t\t\tresourceType,\n\t\t\t\tdisplayName,\n\t\t\t\tgroupKey,\n\t\t\t\tsubgroupKey,\n\t\t\t});\n\t\t}\n\t};\n\n\taddToGroup(resolved.extensions, \"extensions\");\n\taddToGroup(resolved.skills, \"skills\");\n\taddToGroup(resolved.prompts, \"prompts\");\n\taddToGroup(resolved.themes, \"themes\");\n\n\t// Sort groups: packages first, then top-level; user before project\n\tconst groups = Array.from(groupMap.values());\n\tgroups.sort((a, b) => {\n\t\tif (a.origin !== b.origin) {\n\t\t\treturn a.origin === \"package\" ? -1 : 1;\n\t\t}\n\t\tif (a.scope !== b.scope) {\n\t\t\treturn a.scope === \"user\" ? -1 : 1;\n\t\t}\n\t\treturn a.source.localeCompare(b.source);\n\t});\n\n\t// Sort subgroups within each group by type order, and items by name\n\tconst typeOrder: Record<ResourceType, number> = { extensions: 0, skills: 1, prompts: 2, themes: 3 };\n\tfor (const group of groups) {\n\t\tgroup.subgroups.sort((a, b) => typeOrder[a.type] - typeOrder[b.type]);\n\t\tfor (const subgroup of group.subgroups) {\n\t\t\tsubgroup.items.sort((a, b) => a.displayName.localeCompare(b.displayName));\n\t\t}\n\t}\n\n\treturn groups;\n}\n\ntype FlatEntry =\n\t| { type: \"group\"; group: ResourceGroup }\n\t| { type: \"subgroup\"; subgroup: ResourceSubgroup; group: ResourceGroup }\n\t| { type: \"item\"; item: ResourceItem };\n\nclass ConfigSelectorHeader implements Component {\n\tprivate writeScope: ConfigWriteScope;\n\tprivate projectModeAvailable: boolean;\n\n\tconstructor(writeScope: ConfigWriteScope, projectModeAvailable: boolean) {\n\t\tthis.writeScope = writeScope;\n\t\tthis.projectModeAvailable = projectModeAvailable;\n\t}\n\n\tsetWriteScope(writeScope: ConfigWriteScope): void {\n\t\tthis.writeScope = writeScope;\n\t}\n\n\tinvalidate(): void {}\n\n\trender(width: number): string[] {\n\t\tconst title = theme.bold(this.writeScope === \"project\" ? \"Project Local Resources\" : \"Global Resources\");\n\t\tconst sep = theme.fg(\"muted\", \" · \");\n\t\tconst switchHint = this.projectModeAvailable ? keyHint(\"tui.input.tab\", \"switch mode\") + sep : \"\";\n\t\tconst actionHint =\n\t\t\tthis.writeScope === \"project\" ? rawKeyHint(\"space\", \"cycle inherit/+/-\") : rawKeyHint(\"space\", \"toggle\");\n\t\tconst hint = switchHint + actionHint + sep + rawKeyHint(\"esc\", \"close\");\n\t\tconst spacing = Math.max(1, width - visibleWidth(title) - visibleWidth(hint));\n\t\tconst scopeHint =\n\t\t\tthis.writeScope === \"project\"\n\t\t\t\t? theme.fg(\"muted\", `${CONFIG_DIR_NAME}/settings.json · inherited global resources are dimmed`)\n\t\t\t\t: theme.fg(\"muted\", `~/${CONFIG_DIR_NAME}/agent/settings.json`);\n\n\t\treturn [\n\t\t\ttruncateToWidth(`${title}${\" \".repeat(spacing)}${hint}`, width, \"\"),\n\t\t\ttruncateToWidth(scopeHint, width, \"\"),\n\t\t];\n\t}\n}\n\nclass ResourceList implements Component, Focusable {\n\tprivate groupsByScope: Record<ConfigWriteScope, ResourceGroup[]>;\n\tprivate flatItems: FlatEntry[] = [];\n\tprivate filteredItems: FlatEntry[] = [];\n\tprivate selectedIndex = 0;\n\tprivate searchInput: Input;\n\tprivate maxVisible: number;\n\tprivate settingsManager: SettingsManager;\n\tprivate cwd: string;\n\tprivate agentDir: string;\n\tprivate writeScope: ConfigWriteScope;\n\tprivate inheritedEnabledByKey: Map<string, boolean>;\n\n\tpublic onCancel?: () => void;\n\tpublic onExit?: () => void;\n\tpublic onToggle?: (item: ResourceItem, newEnabled: boolean) => void;\n\tpublic onSwitchMode?: () => void;\n\n\tprivate _focused = false;\n\tget focused(): boolean {\n\t\treturn this._focused;\n\t}\n\tset focused(value: boolean) {\n\t\tthis._focused = value;\n\t\tthis.searchInput.focused = value;\n\t}\n\n\tconstructor(\n\t\tgroupsByScope: Record<ConfigWriteScope, ResourceGroup[]>,\n\t\tsettingsManager: SettingsManager,\n\t\tcwd: string,\n\t\tagentDir: string,\n\t\tterminalHeight?: number,\n\t\twriteScope: ConfigWriteScope = \"global\",\n\t) {\n\t\tthis.groupsByScope = groupsByScope;\n\t\tthis.settingsManager = settingsManager;\n\t\tthis.cwd = cwd;\n\t\tthis.agentDir = agentDir;\n\t\tthis.writeScope = writeScope;\n\t\tthis.inheritedEnabledByKey = this.buildInheritedEnabledMap(groupsByScope.global);\n\t\tthis.searchInput = new Input();\n\t\t// 8 lines of chrome: top spacer + top border + spacer + header (2 lines) + spacer + bottom spacer + bottom border\n\t\tconst chrome = 8;\n\t\tthis.maxVisible = Math.max(5, (terminalHeight ?? 24) - chrome);\n\t\tthis.buildFlatList();\n\t\tthis.filteredItems = [...this.flatItems];\n\t}\n\n\tsetWriteScope(writeScope: ConfigWriteScope): void {\n\t\tthis.writeScope = writeScope;\n\t\tthis.buildFlatList();\n\t\tthis.filterItems(this.searchInput.getValue());\n\t}\n\n\tprivate get groups(): ResourceGroup[] {\n\t\treturn this.groupsByScope[this.writeScope];\n\t}\n\n\tprivate buildInheritedEnabledMap(groups: ResourceGroup[]): Map<string, boolean> {\n\t\tconst result = new Map<string, boolean>();\n\t\tfor (const group of groups) {\n\t\t\tfor (const subgroup of group.subgroups) {\n\t\t\t\tfor (const item of subgroup.items) {\n\t\t\t\t\tresult.set(this.getResourceItemKey(item), item.enabled);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tprivate buildFlatList(): void {\n\t\tthis.flatItems = [];\n\t\tfor (const group of this.groups) {\n\t\t\tthis.flatItems.push({ type: \"group\", group });\n\t\t\tfor (const subgroup of group.subgroups) {\n\t\t\t\tthis.flatItems.push({ type: \"subgroup\", subgroup, group });\n\t\t\t\tfor (const item of subgroup.items) {\n\t\t\t\t\tthis.flatItems.push({ type: \"item\", item });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// Start selection on first item (not header)\n\t\tthis.selectedIndex = this.flatItems.findIndex((e) => e.type === \"item\");\n\t\tif (this.selectedIndex < 0) this.selectedIndex = 0;\n\t}\n\n\tprivate findNextItem(fromIndex: number, direction: 1 | -1): number {\n\t\tlet idx = fromIndex + direction;\n\t\twhile (idx >= 0 && idx < this.filteredItems.length) {\n\t\t\tif (this.filteredItems[idx].type === \"item\") {\n\t\t\t\treturn idx;\n\t\t\t}\n\t\t\tidx += direction;\n\t\t}\n\t\treturn fromIndex; // Stay at current if no item found\n\t}\n\n\tprivate filterItems(query: string): void {\n\t\tif (!query.trim()) {\n\t\t\tthis.filteredItems = [...this.flatItems];\n\t\t\tthis.selectFirstItem();\n\t\t\treturn;\n\t\t}\n\n\t\tconst lowerQuery = query.toLowerCase();\n\t\tconst matchingItems = new Set<ResourceItem>();\n\t\tconst matchingSubgroups = new Set<ResourceSubgroup>();\n\t\tconst matchingGroups = new Set<ResourceGroup>();\n\n\t\tfor (const entry of this.flatItems) {\n\t\t\tif (entry.type === \"item\") {\n\t\t\t\tconst item = entry.item;\n\t\t\t\tif (\n\t\t\t\t\titem.displayName.toLowerCase().includes(lowerQuery) ||\n\t\t\t\t\titem.resourceType.toLowerCase().includes(lowerQuery) ||\n\t\t\t\t\titem.path.toLowerCase().includes(lowerQuery)\n\t\t\t\t) {\n\t\t\t\t\tmatchingItems.add(item);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Find which subgroups and groups contain matching items\n\t\tfor (const group of this.groups) {\n\t\t\tfor (const subgroup of group.subgroups) {\n\t\t\t\tfor (const item of subgroup.items) {\n\t\t\t\t\tif (matchingItems.has(item)) {\n\t\t\t\t\t\tmatchingSubgroups.add(subgroup);\n\t\t\t\t\t\tmatchingGroups.add(group);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthis.filteredItems = [];\n\t\tfor (const entry of this.flatItems) {\n\t\t\tif (entry.type === \"group\" && matchingGroups.has(entry.group)) {\n\t\t\t\tthis.filteredItems.push(entry);\n\t\t\t} else if (entry.type === \"subgroup\" && matchingSubgroups.has(entry.subgroup)) {\n\t\t\t\tthis.filteredItems.push(entry);\n\t\t\t} else if (entry.type === \"item\" && matchingItems.has(entry.item)) {\n\t\t\t\tthis.filteredItems.push(entry);\n\t\t\t}\n\t\t}\n\n\t\tthis.selectFirstItem();\n\t}\n\n\tprivate selectFirstItem(): void {\n\t\tconst firstItemIndex = this.filteredItems.findIndex((e) => e.type === \"item\");\n\t\tthis.selectedIndex = firstItemIndex >= 0 ? firstItemIndex : 0;\n\t}\n\n\tupdateItem(item: ResourceItem, enabled: boolean): void {\n\t\titem.enabled = enabled;\n\t\t// Update in groups too\n\t\tfor (const group of this.groups) {\n\t\t\tfor (const subgroup of group.subgroups) {\n\t\t\t\tconst found = subgroup.items.find((i) => i.path === item.path && i.resourceType === item.resourceType);\n\t\t\t\tif (found) {\n\t\t\t\t\tfound.enabled = enabled;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tinvalidate(): void {}\n\n\trender(width: number): string[] {\n\t\tconst lines: string[] = [];\n\n\t\t// Search input\n\t\tlines.push(...this.searchInput.render(width));\n\t\tlines.push(\"\");\n\n\t\tif (this.filteredItems.length === 0) {\n\t\t\tlines.push(theme.fg(\"muted\", \"  No resources found\"));\n\t\t\treturn lines;\n\t\t}\n\n\t\t// Calculate visible range\n\t\tconst startIndex = Math.max(\n\t\t\t0,\n\t\t\tMath.min(this.selectedIndex - Math.floor(this.maxVisible / 2), this.filteredItems.length - this.maxVisible),\n\t\t);\n\t\tconst endIndex = Math.min(startIndex + this.maxVisible, this.filteredItems.length);\n\n\t\tfor (let i = startIndex; i < endIndex; i++) {\n\t\t\tconst entry = this.filteredItems[i];\n\t\t\tconst isSelected = i === this.selectedIndex;\n\n\t\t\tif (entry.type === \"group\") {\n\t\t\t\t// Main group header (no cursor)\n\t\t\t\tconst inherited = this.writeScope === \"project\" && entry.group.scope === \"user\";\n\t\t\t\tconst label = theme.bold(`${entry.group.label}${inherited ? \" · inherited global\" : \"\"}`);\n\t\t\t\tconst groupLine = theme.fg(inherited ? \"dim\" : \"accent\", label);\n\t\t\t\tlines.push(truncateToWidth(`  ${groupLine}`, width, \"\"));\n\t\t\t} else if (entry.type === \"subgroup\") {\n\t\t\t\t// Subgroup header (indented, no cursor)\n\t\t\t\tconst color = this.writeScope === \"project\" && entry.group.scope === \"user\" ? \"dim\" : \"muted\";\n\t\t\t\tconst subgroupLine = theme.fg(color, entry.subgroup.label);\n\t\t\t\tlines.push(truncateToWidth(`    ${subgroupLine}`, width, \"\"));\n\t\t\t} else {\n\t\t\t\t// Resource item (cursor only on items)\n\t\t\t\tconst item = entry.item;\n\t\t\t\tconst cursor = isSelected ? \"> \" : \"  \";\n\t\t\t\tconst dimmed = this.isDimmedItem(item);\n\t\t\t\tconst nameText = isSelected && !dimmed ? theme.bold(item.displayName) : item.displayName;\n\t\t\t\tconst name = dimmed ? theme.fg(\"dim\", nameText) : nameText;\n\t\t\t\tlines.push(\n\t\t\t\t\ttruncateToWidth(\n\t\t\t\t\t\t`${cursor}    ${this.renderCheckbox(item)} ${name}${this.getItemSuffix(item)}`,\n\t\t\t\t\t\twidth,\n\t\t\t\t\t\t\"...\",\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// Scroll indicator\n\t\tif (startIndex > 0 || endIndex < this.filteredItems.length) {\n\t\t\tconst itemCount = this.filteredItems.filter((e) => e.type === \"item\").length;\n\t\t\tconst currentItemIndex =\n\t\t\t\tthis.filteredItems.slice(0, this.selectedIndex).filter((e) => e.type === \"item\").length + 1;\n\t\t\tlines.push(theme.fg(\"dim\", `  (${currentItemIndex}/${itemCount})`));\n\t\t}\n\n\t\treturn lines;\n\t}\n\n\thandleInput(data: string): void {\n\t\tconst kb = getKeybindings();\n\n\t\tif (kb.matches(data, \"tui.select.up\")) {\n\t\t\tthis.selectedIndex = this.findNextItem(this.selectedIndex, -1);\n\t\t\treturn;\n\t\t}\n\t\tif (kb.matches(data, \"tui.select.down\")) {\n\t\t\tthis.selectedIndex = this.findNextItem(this.selectedIndex, 1);\n\t\t\treturn;\n\t\t}\n\t\tif (kb.matches(data, \"tui.select.pageUp\")) {\n\t\t\t// Jump up by maxVisible, then find nearest item\n\t\t\tlet target = Math.max(0, this.selectedIndex - this.maxVisible);\n\t\t\twhile (target < this.filteredItems.length && this.filteredItems[target].type !== \"item\") {\n\t\t\t\ttarget++;\n\t\t\t}\n\t\t\tif (target < this.filteredItems.length) {\n\t\t\t\tthis.selectedIndex = target;\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (kb.matches(data, \"tui.select.pageDown\")) {\n\t\t\t// Jump down by maxVisible, then find nearest item\n\t\t\tlet target = Math.min(this.filteredItems.length - 1, this.selectedIndex + this.maxVisible);\n\t\t\twhile (target >= 0 && this.filteredItems[target].type !== \"item\") {\n\t\t\t\ttarget--;\n\t\t\t}\n\t\t\tif (target >= 0) {\n\t\t\t\tthis.selectedIndex = target;\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (kb.matches(data, \"tui.select.cancel\")) {\n\t\t\tthis.onCancel?.();\n\t\t\treturn;\n\t\t}\n\t\tif (matchesKey(data, \"ctrl+c\")) {\n\t\t\tthis.onExit?.();\n\t\t\treturn;\n\t\t}\n\t\tif (kb.matches(data, \"tui.input.tab\")) {\n\t\t\tthis.onSwitchMode?.();\n\t\t\treturn;\n\t\t}\n\t\tif (data === \" \" || kb.matches(data, \"tui.select.confirm\")) {\n\t\t\tconst entry = this.filteredItems[this.selectedIndex];\n\t\t\tif (entry?.type === \"item\" && (this.writeScope === \"project\" || this.getItemScope(entry.item) === \"user\")) {\n\t\t\t\tconst newEnabled = this.toggleResource(entry.item);\n\t\t\t\tif (newEnabled !== undefined) {\n\t\t\t\t\tthis.updateItem(entry.item, newEnabled);\n\t\t\t\t\tthis.onToggle?.(entry.item, newEnabled);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Pass to search input\n\t\tthis.searchInput.handleInput(data);\n\t\tthis.filterItems(this.searchInput.getValue());\n\t}\n\n\tprivate toggleResource(item: ResourceItem): boolean | undefined {\n\t\tif (this.writeScope === \"project\") {\n\t\t\tconst state = this.getNextOverrideState(item);\n\t\t\tif (!this.setProjectResourceOverride(item, state)) return undefined;\n\t\t\treturn state === \"inherit\" ? this.getInheritedEnabled(item) : state === \"load\";\n\t\t}\n\n\t\tconst enabled = !item.enabled;\n\t\tif (item.metadata.origin === \"top-level\") {\n\t\t\tthis.toggleTopLevelResource(item, enabled);\n\t\t} else {\n\t\t\tthis.togglePackageResource(item, enabled);\n\t\t}\n\t\treturn enabled;\n\t}\n\n\tprivate toggleTopLevelResource(item: ResourceItem, enabled: boolean): void {\n\t\tconst scope = item.metadata.scope as \"user\" | \"project\";\n\t\tconst settings =\n\t\t\tscope === \"project\" ? this.settingsManager.getProjectSettings() : this.settingsManager.getGlobalSettings();\n\n\t\tconst arrayKey = item.resourceType as \"extensions\" | \"skills\" | \"prompts\" | \"themes\";\n\t\tconst current = (settings[arrayKey] ?? []) as string[];\n\n\t\t// Generate pattern for this resource\n\t\tconst pattern = this.getResourcePattern(item);\n\t\tconst disablePattern = `-${pattern}`;\n\t\tconst enablePattern = `+${pattern}`;\n\n\t\t// Filter out existing patterns for this resource\n\t\tconst updated = current.filter((p) => {\n\t\t\tconst stripped = p.startsWith(\"!\") || p.startsWith(\"+\") || p.startsWith(\"-\") ? p.slice(1) : p;\n\t\t\treturn stripped !== pattern;\n\t\t});\n\n\t\tif (enabled) {\n\t\t\tupdated.push(enablePattern);\n\t\t} else {\n\t\t\tupdated.push(disablePattern);\n\t\t}\n\n\t\tif (scope === \"project\") {\n\t\t\tif (arrayKey === \"extensions\") {\n\t\t\t\tthis.settingsManager.setProjectExtensionPaths(updated);\n\t\t\t} else if (arrayKey === \"skills\") {\n\t\t\t\tthis.settingsManager.setProjectSkillPaths(updated);\n\t\t\t} else if (arrayKey === \"prompts\") {\n\t\t\t\tthis.settingsManager.setProjectPromptTemplatePaths(updated);\n\t\t\t} else if (arrayKey === \"themes\") {\n\t\t\t\tthis.settingsManager.setProjectThemePaths(updated);\n\t\t\t}\n\t\t} else {\n\t\t\tif (arrayKey === \"extensions\") {\n\t\t\t\tthis.settingsManager.setExtensionPaths(updated);\n\t\t\t} else if (arrayKey === \"skills\") {\n\t\t\t\tthis.settingsManager.setSkillPaths(updated);\n\t\t\t} else if (arrayKey === \"prompts\") {\n\t\t\t\tthis.settingsManager.setPromptTemplatePaths(updated);\n\t\t\t} else if (arrayKey === \"themes\") {\n\t\t\t\tthis.settingsManager.setThemePaths(updated);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate togglePackageResource(item: ResourceItem, enabled: boolean): void {\n\t\tconst scope = item.metadata.scope as \"user\" | \"project\";\n\t\tconst settings =\n\t\t\tscope === \"project\" ? this.settingsManager.getProjectSettings() : this.settingsManager.getGlobalSettings();\n\n\t\tconst packages = [...(settings.packages ?? [])] as PackageSource[];\n\t\tconst pkgIndex = packages.findIndex((pkg) => {\n\t\t\tconst source = typeof pkg === \"string\" ? pkg : pkg.source;\n\t\t\treturn source === item.metadata.source;\n\t\t});\n\n\t\tif (pkgIndex === -1) return;\n\n\t\tlet pkg = packages[pkgIndex];\n\n\t\t// Convert string to object form if needed\n\t\tif (typeof pkg === \"string\") {\n\t\t\tpkg = { source: pkg };\n\t\t\tpackages[pkgIndex] = pkg;\n\t\t}\n\n\t\t// Get the resource array for this type\n\t\tconst arrayKey = item.resourceType as \"extensions\" | \"skills\" | \"prompts\" | \"themes\";\n\t\tconst current = (pkg[arrayKey] ?? []) as string[];\n\n\t\t// Generate pattern relative to package root\n\t\tconst pattern = this.getPackageResourcePattern(item);\n\t\tconst disablePattern = `-${pattern}`;\n\t\tconst enablePattern = `+${pattern}`;\n\n\t\t// Filter out existing patterns for this resource\n\t\tconst updated = current.filter((p) => {\n\t\t\tconst stripped = p.startsWith(\"!\") || p.startsWith(\"+\") || p.startsWith(\"-\") ? p.slice(1) : p;\n\t\t\treturn stripped !== pattern;\n\t\t});\n\n\t\tif (enabled) {\n\t\t\tupdated.push(enablePattern);\n\t\t} else {\n\t\t\tupdated.push(disablePattern);\n\t\t}\n\n\t\t(pkg as Record<string, unknown>)[arrayKey] = updated.length > 0 ? updated : undefined;\n\n\t\t// Clean up empty filter object\n\t\tconst hasFilters = [\"extensions\", \"skills\", \"prompts\", \"themes\"].some(\n\t\t\t(k) => (pkg as Record<string, unknown>)[k] !== undefined,\n\t\t);\n\t\tif (!hasFilters) {\n\t\t\tpackages[pkgIndex] = (pkg as { source: string }).source;\n\t\t}\n\n\t\tif (scope === \"project\") {\n\t\t\tthis.settingsManager.setProjectPackages(packages);\n\t\t} else {\n\t\t\tthis.settingsManager.setPackages(packages);\n\t\t}\n\t}\n\n\tprivate renderCheckbox(item: ResourceItem): string {\n\t\tif (this.writeScope === \"project\") {\n\t\t\tconst state = this.getProjectOverrideState(item);\n\t\t\tif (state === \"load\") return theme.fg(\"success\", \"[+]\");\n\t\t\tif (state === \"unload\") return theme.fg(\"warning\", \"[-]\");\n\t\t\treturn theme.fg(\"dim\", item.enabled ? \"[x]\" : \"[ ]\");\n\t\t}\n\t\treturn item.enabled ? theme.fg(\"success\", \"[x]\") : theme.fg(\"dim\", \"[ ]\");\n\t}\n\n\tprivate getItemSuffix(item: ResourceItem): string {\n\t\tif (this.writeScope !== \"project\") return \"\";\n\t\tconst state = this.getProjectOverrideState(item);\n\t\tif (state === \"load\") return theme.fg(\"muted\", \"  project load\");\n\t\tif (state === \"unload\") return theme.fg(\"muted\", \"  project unload\");\n\t\treturn this.isInheritedGlobalItem(item) ? theme.fg(\"dim\", \"  inherited global\") : \"\";\n\t}\n\n\tprivate isDimmedItem(item: ResourceItem): boolean {\n\t\treturn (\n\t\t\tthis.writeScope === \"project\" &&\n\t\t\tthis.isInheritedGlobalItem(item) &&\n\t\t\tthis.getProjectOverrideState(item) === \"inherit\"\n\t\t);\n\t}\n\n\tprivate setProjectResourceOverride(item: ResourceItem, state: ProjectOverrideState): boolean {\n\t\treturn item.metadata.origin === \"top-level\"\n\t\t\t? this.setProjectTopLevelOverride(item, state)\n\t\t\t: this.setProjectPackageOverride(item, state);\n\t}\n\n\tprivate setProjectTopLevelOverride(item: ResourceItem, state: ProjectOverrideState): boolean {\n\t\tconst current = (this.settingsManager.getProjectSettings()[item.resourceType] ?? []) as string[];\n\t\tconst pattern = this.isInheritedGlobalItem(item) ? item.path : this.getResourcePatternForScope(item, \"project\");\n\t\tconst patterns = this.getTopLevelOverridePatterns(item, \"project\");\n\t\tconst updated = current.filter((entry) => {\n\t\t\tconst target = this.getPatternEntryTarget(entry);\n\t\t\tif ((entry.startsWith(\"!\") || entry.startsWith(\"+\") || entry.startsWith(\"-\")) && patterns.has(target))\n\t\t\t\treturn false;\n\t\t\treturn !(state === \"inherit\" && this.isInheritedGlobalItem(item) && target === pattern);\n\t\t});\n\t\tif (state !== \"inherit\") {\n\t\t\tif (this.isInheritedGlobalItem(item) && !updated.includes(pattern)) updated.push(pattern);\n\t\t\tupdated.push(`${state === \"load\" ? \"+\" : \"-\"}${pattern}`);\n\t\t}\n\t\tthis.setProjectTopLevelPaths(item.resourceType, updated);\n\t\treturn true;\n\t}\n\n\tprivate setProjectTopLevelPaths(key: ResourceType, paths: string[]): void {\n\t\tif (key === \"extensions\") this.settingsManager.setProjectExtensionPaths(paths);\n\t\telse if (key === \"skills\") this.settingsManager.setProjectSkillPaths(paths);\n\t\telse if (key === \"prompts\") this.settingsManager.setProjectPromptTemplatePaths(paths);\n\t\telse this.settingsManager.setProjectThemePaths(paths);\n\t}\n\n\tprivate setProjectPackageOverride(item: ResourceItem, state: ProjectOverrideState): boolean {\n\t\tconst packages = [...(this.settingsManager.getProjectSettings().packages ?? [])] as PackageSource[];\n\t\tlet pkgIndex = packages.findIndex((pkg) =>\n\t\t\tthis.packageSourceStringMatches(\n\t\t\t\titem.metadata.source,\n\t\t\t\tthis.getItemScope(item),\n\t\t\t\ttypeof pkg === \"string\" ? pkg : pkg.source,\n\t\t\t\t\"project\",\n\t\t\t),\n\t\t);\n\t\tif (pkgIndex === -1) {\n\t\t\tif (state === \"inherit\") return false;\n\t\t\tpackages.push(this.createPackageOverrideSource(item));\n\t\t\tpkgIndex = packages.length - 1;\n\t\t}\n\t\tlet pkg = packages[pkgIndex];\n\t\tif (pkg === undefined) return false;\n\t\tif (typeof pkg === \"string\") {\n\t\t\tpkg = { source: pkg };\n\t\t\tpackages[pkgIndex] = pkg;\n\t\t}\n\t\tconst pattern = this.getPackageResourcePattern(item);\n\t\tconst updated = ((pkg[item.resourceType] ?? []) as string[]).filter(\n\t\t\t(entry) => this.getPatternEntryTarget(entry) !== pattern,\n\t\t);\n\t\tif (state !== \"inherit\") updated.push(`${state === \"load\" ? \"+\" : \"-\"}${pattern}`);\n\t\t(pkg as Record<string, unknown>)[item.resourceType] = updated.length > 0 ? updated : undefined;\n\t\tif (!RESOURCE_TYPES.some((key) => (pkg as Record<string, unknown>)[key] !== undefined)) {\n\t\t\tif (pkg.autoload === false) packages.splice(pkgIndex, 1);\n\t\t\telse packages[pkgIndex] = pkg.source;\n\t\t}\n\t\tthis.settingsManager.setProjectPackages(packages);\n\t\treturn true;\n\t}\n\n\tprivate getNextOverrideState(item: ResourceItem): ProjectOverrideState {\n\t\tconst state = this.getProjectOverrideState(item);\n\t\tconst inheritedEnabled = this.getInheritedEnabled(item);\n\t\tif (state === \"inherit\") return inheritedEnabled ? \"unload\" : \"load\";\n\t\tif (state === \"unload\") return inheritedEnabled ? \"load\" : \"inherit\";\n\t\treturn inheritedEnabled ? \"inherit\" : \"unload\";\n\t}\n\n\tprivate getProjectOverrideState(item: ResourceItem): ProjectOverrideState {\n\t\tif (this.writeScope !== \"project\") return \"inherit\";\n\t\tif (item.metadata.origin === \"top-level\") {\n\t\t\treturn this.getOverrideStateFromEntries(\n\t\t\t\t(this.settingsManager.getProjectSettings()[item.resourceType] ?? []) as string[],\n\t\t\t\tthis.getTopLevelOverridePatterns(item, \"project\"),\n\t\t\t\tfalse,\n\t\t\t);\n\t\t}\n\t\tconst pkg = this.findMatchingPackageSource(item, \"project\");\n\t\tif (typeof pkg !== \"object\") return \"inherit\";\n\t\tconst entries = pkg[item.resourceType];\n\t\tif (entries === undefined) return \"inherit\";\n\t\treturn this.getOverrideStateFromEntries(\n\t\t\tentries,\n\t\t\tnew Set([this.getPackageResourcePattern(item)]),\n\t\t\tpkg.autoload !== false,\n\t\t);\n\t}\n\n\tprivate getOverrideStateFromEntries(\n\t\tentries: string[],\n\t\tpatterns: Set<string>,\n\t\temptyArrayIsUnload: boolean,\n\t): ProjectOverrideState {\n\t\tif (entries.length === 0 && emptyArrayIsUnload) return \"unload\";\n\t\tlet state: ProjectOverrideState = \"inherit\";\n\t\tfor (const entry of entries) {\n\t\t\tif (!patterns.has(this.getPatternEntryTarget(entry))) continue;\n\t\t\tif (entry.startsWith(\"!\") || entry.startsWith(\"-\")) state = \"unload\";\n\t\t\telse state = \"load\";\n\t\t}\n\t\treturn state;\n\t}\n\n\tprivate getInheritedEnabled(item: ResourceItem): boolean {\n\t\treturn (\n\t\t\tthis.inheritedEnabledByKey.get(this.getResourceItemKey(item)) ??\n\t\t\t(this.getItemScope(item) === \"user\" ? item.enabled : true)\n\t\t);\n\t}\n\n\tprivate isInheritedGlobalItem(item: ResourceItem): boolean {\n\t\treturn this.getItemScope(item) === \"user\" || this.inheritedEnabledByKey.has(this.getResourceItemKey(item));\n\t}\n\n\tprivate getTopLevelOverridePatterns(item: ResourceItem, scope: SettingsScope): Set<string> {\n\t\tconst baseDir = this.getTopLevelBaseDir(scope);\n\t\tconst patterns = new Set<string>([\n\t\t\tthis.getResourcePatternForScope(item, scope),\n\t\t\titem.path,\n\t\t\trelative(baseDir, item.path),\n\t\t]);\n\t\tif (item.metadata.baseDir) patterns.add(relative(item.metadata.baseDir, item.path));\n\t\treturn patterns;\n\t}\n\n\tprivate getResourcePatternForScope(item: ResourceItem, scope: SettingsScope): string {\n\t\tconst sourceScope = this.getItemScope(item);\n\t\tif (scope !== sourceScope) return item.path;\n\t\tconst baseDir = item.metadata.baseDir ?? this.getTopLevelBaseDir(sourceScope);\n\t\treturn relative(baseDir, item.path);\n\t}\n\n\tprivate createPackageOverrideSource(item: ResourceItem): PackageSource {\n\t\tconst source = item.metadata.source;\n\t\tif (!isLocalPath(source)) return { source, autoload: false };\n\t\tconst sourcePath = resolvePath(source, this.getTopLevelBaseDir(this.getItemScope(item)), { trim: true });\n\t\treturn { source: relative(this.getTopLevelBaseDir(\"project\"), sourcePath) || \".\", autoload: false };\n\t}\n\n\tprivate packageSourceStringMatches(\n\t\tleftSource: string,\n\t\tleftScope: SettingsScope,\n\t\trightSource: string,\n\t\trightScope: SettingsScope,\n\t): boolean {\n\t\tif (leftSource === rightSource) return true;\n\t\tif (!isLocalPath(leftSource) || !isLocalPath(rightSource)) return false;\n\t\tconst left = resolvePath(leftSource, this.getTopLevelBaseDir(leftScope), { trim: true });\n\t\tconst right = resolvePath(rightSource, this.getTopLevelBaseDir(rightScope), { trim: true });\n\t\treturn left === right;\n\t}\n\n\tprivate findMatchingPackageSource(item: ResourceItem, targetScope: SettingsScope): PackageSource | undefined {\n\t\tconst settings =\n\t\t\ttargetScope === \"project\"\n\t\t\t\t? this.settingsManager.getProjectSettings()\n\t\t\t\t: this.settingsManager.getGlobalSettings();\n\t\treturn (settings.packages ?? []).find((pkg) =>\n\t\t\tthis.packageSourceStringMatches(\n\t\t\t\titem.metadata.source,\n\t\t\t\tthis.getItemScope(item),\n\t\t\t\ttypeof pkg === \"string\" ? pkg : pkg.source,\n\t\t\t\ttargetScope,\n\t\t\t),\n\t\t);\n\t}\n\n\tprivate getPatternEntryTarget(entry: string): string {\n\t\treturn entry.startsWith(\"!\") || entry.startsWith(\"+\") || entry.startsWith(\"-\") ? entry.slice(1) : entry;\n\t}\n\n\tprivate getResourceItemKey(item: ResourceItem): string {\n\t\treturn `${item.resourceType}:${canonicalizePath(item.path)}`;\n\t}\n\n\tprivate getItemScope(item: ResourceItem): SettingsScope {\n\t\treturn item.metadata.scope === \"project\" ? \"project\" : \"user\";\n\t}\n\n\tprivate getTopLevelBaseDir(scope: \"user\" | \"project\"): string {\n\t\treturn scope === \"project\" ? join(this.cwd, CONFIG_DIR_NAME) : this.agentDir;\n\t}\n\n\tprivate getResourcePattern(item: ResourceItem): string {\n\t\tconst scope = item.metadata.scope as \"user\" | \"project\";\n\t\tconst baseDir = item.metadata.baseDir ?? this.getTopLevelBaseDir(scope);\n\t\treturn relative(baseDir, item.path);\n\t}\n\n\tprivate getPackageResourcePattern(item: ResourceItem): string {\n\t\tconst baseDir = item.metadata.baseDir ?? dirname(item.path);\n\t\treturn relative(baseDir, item.path);\n\t}\n}\n\nexport class ConfigSelectorComponent extends Container implements Focusable {\n\tprivate header: ConfigSelectorHeader;\n\tprivate resourceList: ResourceList;\n\tprivate writeScope: ConfigWriteScope;\n\n\tprivate _focused = false;\n\tget focused(): boolean {\n\t\treturn this._focused;\n\t}\n\tset focused(value: boolean) {\n\t\tthis._focused = value;\n\t\tthis.resourceList.focused = value;\n\t}\n\n\tconstructor(\n\t\tresolvedPaths: ScopedResolvedPaths,\n\t\tsettingsManager: SettingsManager,\n\t\tcwd: string,\n\t\tagentDir: string,\n\t\tonClose: () => void,\n\t\tonExit: () => void,\n\t\trequestRender: () => void,\n\t\tterminalHeight?: number,\n\t\twriteScope: ConfigWriteScope = \"global\",\n\t\tprojectModeAvailable = true,\n\t) {\n\t\tsuper();\n\n\t\tthis.writeScope = writeScope;\n\t\tconst groupsByScope = {\n\t\t\tglobal: buildGroups(resolvedPaths.global, agentDir),\n\t\t\tproject: buildGroups(resolvedPaths.project, agentDir),\n\t\t};\n\n\t\t// Add header\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.header = new ConfigSelectorHeader(this.writeScope, projectModeAvailable);\n\t\tthis.addChild(this.header);\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Resource list\n\t\tthis.resourceList = new ResourceList(\n\t\t\tgroupsByScope,\n\t\t\tsettingsManager,\n\t\t\tcwd,\n\t\t\tagentDir,\n\t\t\tterminalHeight,\n\t\t\tthis.writeScope,\n\t\t);\n\t\tthis.resourceList.onCancel = onClose;\n\t\tthis.resourceList.onExit = onExit;\n\t\tthis.resourceList.onToggle = () => requestRender();\n\t\tif (projectModeAvailable) {\n\t\t\tthis.resourceList.onSwitchMode = () => {\n\t\t\t\tthis.switchWriteScope();\n\t\t\t\trequestRender();\n\t\t\t};\n\t\t}\n\t\tthis.addChild(this.resourceList);\n\n\t\t// Bottom border\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new DynamicBorder());\n\t}\n\n\tprivate switchWriteScope(): void {\n\t\tthis.writeScope = this.writeScope === \"global\" ? \"project\" : \"global\";\n\t\tthis.header.setWriteScope(this.writeScope);\n\t\tthis.resourceList.setWriteScope(this.writeScope);\n\t}\n\n\tgetResourceList(): ResourceList {\n\t\treturn this.resourceList;\n\t}\n}\n"]}