UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

56 lines • 3.37 kB
/** * Process-wide cache for compiled extension module graphs. * * A module registry has no eviction API, so every extension source evaluated under a fresh * importer generation stays resident for the life of the process. A daemon that loads extensions * per session therefore pays that cost per session forever (senpi#1948). The graph is a pure * function of its source files, so this cache keeps ONE live generation and hands the same factory * to every later load whose sources are byte-for-byte unchanged; every load still runs the factory, * so sessions keep their own extension instances. * * Freshness is preserved by invalidation: a changed, added or removed source file drops the * generation, and the next load compiles a new one. An importer that cannot report the files it * compiled (the Node jiti path) is never cached, because its graph cannot be checked for staleness. * * The check runs on every cached lookup - once per extension per session open - so it must not * re-read the graph (senpi#6256: hashing a large extension graph cost ~10 ms per extension per open). * A file whose content was proven to match is remembered with its stat identity; a later lookup * re-hashes it only when that identity moved. ctime cannot be set from userland and moves on every * write, and a file modified too recently to trust its timestamps is never remembered (git's "racy * clean" rule), so an edit within one timestamp tick is still caught by the hash. * * @module core/extensions/extension-module-cache */ export type ExtensionModuleImporter = { import(path: string, options: { default: true; }): Promise<unknown>; /** SHA-256 of the exact source strings compiled, including dependencies imported later. */ compiledSources?: () => ReadonlyMap<string, string>; dispose?: () => void; }; export type ExtensionModuleImporterFactory = () => Promise<ExtensionModuleImporter>; type CachedFactory = (...args: never[]) => unknown; /** * The cached factory for this source, or `undefined` when it must be compiled. * * A source change invalidates the whole generation: its modules already reference each other, so * one stale file makes every factory in that generation suspect. */ export declare function cachedExtensionFactory(resolvedPath: string): CachedFactory | undefined; /** The live importer, created on demand. Callers share one generation until it is invalidated. */ export declare function extensionModuleImporter(create: ExtensionModuleImporterFactory): Promise<ExtensionModuleImporter>; /** * Remember a freshly compiled factory. Source identity belongs to the importer: reading disk * here would label an old compiled module with newer bytes if a dependency changed meanwhile. * * `compiledBy` is the importer that produced the factory: a load already in flight when a source * change dropped the generation must not file its result under the successor, whose fingerprint * describes different bytes. */ export declare function rememberExtensionFactory(resolvedPath: string, factory: CachedFactory, compiledBy: ExtensionModuleImporter): void; export declare function clearExtensionCache(): void; /** Test seam: how many module generations this process has compiled. */ export declare function extensionModuleGenerationCount(): number; export {}; //# sourceMappingURL=extension-module-cache.d.ts.map