Files
openclaw/src/plugins/loader-cache-state.ts
Peter Steinberger 98e3f729bc refactor: remove dead plugin loader exports (#105937)
* refactor(plugins): trim activation and contract exports

* test(plugins): restore fixture cleanup

* refactor(plugins): trim install and loader exports

* test(plugins): fully reset loader caches

* refactor(plugins): trim metadata and catalog exports

* test(plugins): preserve catalog trust coverage

* refactor(plugins): trim provider and plugin exports

* refactor(plugins): trim runtime and tool exports

* test(plugins): update dead-export consumers

* test(plugins): remove empty dead-export suites

* refactor(plugins): align exports with split registry

* refactor(plugins): trim drifted loader exports

* style(plugins): format test fixtures

* refactor(scripts): use supported plugin APIs

* refactor(plugins): finish dead export cleanup

* chore(deadcode): refresh export baseline

* test(cli): mock production memory state

* chore(deadcode): sync latest export baseline

* fix(tests): keep plugin fixtures inside core

* chore(deadcode): refresh rebased export baseline

* chore(deadcode): sync current ratchets

* fix(plugins): retain reserved slot invariant

* fix(plugins): preserve dead-export invariants

* test(plugins): use neutral catalog query fixture

* test(plugins): satisfy catalog lint

* test(plugins): preserve integrity drift coverage

* fix(ci): register skill experience live proof
2026-07-13 01:29:33 -07:00

75 lines
2.1 KiB
TypeScript

/** Cache state helper for plugin loader registries, in-flight loads, and warning suppression. */
import { PluginLruCache } from "./plugin-cache-primitives.js";
/** Error thrown when one plugin registry cache key attempts nested loading. */
class PluginLoadReentryError extends Error {
readonly cacheKey: string;
constructor(cacheKey: string) {
super(`plugin load reentry detected for cache key: ${cacheKey}`);
this.name = "PluginLoadReentryError";
this.cacheKey = cacheKey;
}
}
/** Small registry cache with reentry detection and per-key warning memory. */
export class PluginLoaderCacheState<T> {
readonly #registryCache: PluginLruCache<T>;
readonly #inFlightLoads = new Set<string>();
readonly #openAllowlistWarningCache = new Set<string>();
constructor(defaultMaxEntries: number) {
this.#registryCache = new PluginLruCache<T>(defaultMaxEntries);
}
get maxEntries(): number {
return this.#registryCache.maxEntries;
}
setMaxEntriesForTest(value?: number): void {
this.#registryCache.setMaxEntriesForTest(value);
}
clear(): void {
this.#registryCache.clear();
this.#inFlightLoads.clear();
this.#openAllowlistWarningCache.clear();
}
clearCachedRegistries(): void {
this.#registryCache.clear();
this.#openAllowlistWarningCache.clear();
}
get(cacheKey: string): T | undefined {
return this.#registryCache.get(cacheKey);
}
set(cacheKey: string, state: T): void {
this.#registryCache.set(cacheKey, state);
}
isLoadInFlight(cacheKey: string): boolean {
return this.#inFlightLoads.has(cacheKey);
}
beginLoad(cacheKey: string): void {
if (this.#inFlightLoads.has(cacheKey)) {
throw new PluginLoadReentryError(cacheKey);
}
this.#inFlightLoads.add(cacheKey);
}
finishLoad(cacheKey: string): void {
this.#inFlightLoads.delete(cacheKey);
}
hasOpenAllowlistWarning(cacheKey: string): boolean {
return this.#openAllowlistWarningCache.has(cacheKey);
}
recordOpenAllowlistWarning(cacheKey: string): void {
this.#openAllowlistWarningCache.add(cacheKey);
}
}