fix(shared): memoize loadOpencodePlugins by directory

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-04-18 14:10:45 +09:00
parent 428bae632c
commit ac2686ffde
+12
View File
@@ -8,6 +8,8 @@ interface OpencodeConfig {
plugin?: (string | [string, ...unknown[]])[] plugin?: (string | [string, ...unknown[]])[]
} }
const opencodePluginsCache = new Map<string, string[]>()
function getWindowsAppdataDir(): string | null { function getWindowsAppdataDir(): string | null {
return process.env.APPDATA || null return process.env.APPDATA || null
} }
@@ -33,6 +35,11 @@ function getConfigPaths(directory: string): string[] {
} }
export function loadOpencodePlugins(directory: string): string[] { export function loadOpencodePlugins(directory: string): string[] {
const cachedPluginEntries = opencodePluginsCache.get(directory)
if (cachedPluginEntries) {
return cachedPluginEntries
}
const pluginEntries: string[] = [] const pluginEntries: string[] = []
const seenPluginEntries = new Set<string>() const seenPluginEntries = new Set<string>()
@@ -56,5 +63,10 @@ export function loadOpencodePlugins(directory: string): string[] {
} }
} }
opencodePluginsCache.set(directory, pluginEntries)
return pluginEntries return pluginEntries
} }
export function clearOpencodePluginsCache(): void {
opencodePluginsCache.clear()
}