fix: cache plugin component loading results
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -27,12 +27,33 @@ export interface PluginComponentsResult {
|
|||||||
errors: PluginLoadError[]
|
errors: PluginLoadError[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cachedPluginComponentsByKey = new Map<string, PluginComponentsResult>()
|
||||||
|
|
||||||
|
function clonePluginComponentsResult(
|
||||||
|
result: PluginComponentsResult,
|
||||||
|
): PluginComponentsResult {
|
||||||
|
return structuredClone(result)
|
||||||
|
}
|
||||||
|
|
||||||
function isClaudeCodePluginsDisabled(): boolean {
|
function isClaudeCodePluginsDisabled(): boolean {
|
||||||
const disableFlag = process.env.OPENCODE_DISABLE_CLAUDE_CODE
|
const disableFlag = process.env.OPENCODE_DISABLE_CLAUDE_CODE
|
||||||
const disablePluginsFlag = process.env.OPENCODE_DISABLE_CLAUDE_CODE_PLUGINS
|
const disablePluginsFlag = process.env.OPENCODE_DISABLE_CLAUDE_CODE_PLUGINS
|
||||||
return disableFlag === "true" || disableFlag === "1" || disablePluginsFlag === "true" || disablePluginsFlag === "1"
|
return disableFlag === "true" || disableFlag === "1" || disablePluginsFlag === "true" || disablePluginsFlag === "1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getPluginComponentsCacheKey(options?: PluginLoaderOptions): string {
|
||||||
|
const overrideEntries = Object.entries(options?.enabledPluginsOverride ?? {})
|
||||||
|
.sort(([leftKey], [rightKey]) => leftKey.localeCompare(rightKey))
|
||||||
|
|
||||||
|
return JSON.stringify({
|
||||||
|
enabledPluginsOverride: overrideEntries,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function clearPluginComponentsCache(): void {
|
||||||
|
cachedPluginComponentsByKey.clear()
|
||||||
|
}
|
||||||
|
|
||||||
export async function loadAllPluginComponents(options?: PluginLoaderOptions): Promise<PluginComponentsResult> {
|
export async function loadAllPluginComponents(options?: PluginLoaderOptions): Promise<PluginComponentsResult> {
|
||||||
if (isClaudeCodePluginsDisabled()) {
|
if (isClaudeCodePluginsDisabled()) {
|
||||||
log("Claude Code plugin loading disabled via OPENCODE_DISABLE_CLAUDE_CODE env var")
|
log("Claude Code plugin loading disabled via OPENCODE_DISABLE_CLAUDE_CODE env var")
|
||||||
@@ -47,6 +68,12 @@ export async function loadAllPluginComponents(options?: PluginLoaderOptions): Pr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cacheKey = getPluginComponentsCacheKey(options)
|
||||||
|
const cachedPluginComponents = cachedPluginComponentsByKey.get(cacheKey)
|
||||||
|
if (cachedPluginComponents) {
|
||||||
|
return clonePluginComponentsResult(cachedPluginComponents)
|
||||||
|
}
|
||||||
|
|
||||||
const { plugins, errors } = discoverInstalledPlugins(options)
|
const { plugins, errors } = discoverInstalledPlugins(options)
|
||||||
|
|
||||||
const [commands, skills, agents, mcpServers, hooksConfigs] = await Promise.all([
|
const [commands, skills, agents, mcpServers, hooksConfigs] = await Promise.all([
|
||||||
@@ -59,7 +86,7 @@ export async function loadAllPluginComponents(options?: PluginLoaderOptions): Pr
|
|||||||
|
|
||||||
log(`Loaded ${plugins.length} plugins with ${Object.keys(commands).length} commands, ${Object.keys(skills).length} skills, ${Object.keys(agents).length} agents, ${Object.keys(mcpServers).length} MCP servers`)
|
log(`Loaded ${plugins.length} plugins with ${Object.keys(commands).length} commands, ${Object.keys(skills).length} skills, ${Object.keys(agents).length} agents, ${Object.keys(mcpServers).length} MCP servers`)
|
||||||
|
|
||||||
return {
|
const result = {
|
||||||
commands,
|
commands,
|
||||||
skills,
|
skills,
|
||||||
agents,
|
agents,
|
||||||
@@ -68,4 +95,8 @@ export async function loadAllPluginComponents(options?: PluginLoaderOptions): Pr
|
|||||||
plugins,
|
plugins,
|
||||||
errors,
|
errors,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cachedPluginComponentsByKey.set(cacheKey, clonePluginComponentsResult(result))
|
||||||
|
|
||||||
|
return clonePluginComponentsResult(result)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user