fix(claude-code-command-loader): skip EXCLUDED_DIRS and memoize per 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:13:12 +09:00
parent 3cb1d5d936
commit 89d394ed3e
2 changed files with 65 additions and 2 deletions
@@ -0,0 +1,37 @@
import { promises as fs } from "fs"
import { resolve } from "path"
import type { CommandDefinition } from "./types"
const commandLoaderCache = new Map<string, Promise<Record<string, CommandDefinition>>>()
export async function getCommandLoaderCacheKey(directory?: string): Promise<string> {
const resolvedDirectory = resolve(directory ?? process.cwd())
try {
return await fs.realpath(resolvedDirectory)
} catch {
return resolvedDirectory
}
}
export function getCachedCommands(
cacheKey: string,
): Promise<Record<string, CommandDefinition>> | undefined {
return commandLoaderCache.get(cacheKey)
}
export function setCachedCommands(
cacheKey: string,
commands: Promise<Record<string, CommandDefinition>>,
): void {
commandLoaderCache.set(cacheKey, commands)
}
export function deleteCachedCommands(cacheKey: string): void {
commandLoaderCache.delete(cacheKey)
}
export function clearCommandLoaderCache(): void {
commandLoaderCache.clear()
}