diff --git a/.changeset/autocomplete-ignore-cache.md b/.changeset/autocomplete-ignore-cache.md new file mode 100644 index 00000000000..39d6046e0fe --- /dev/null +++ b/.changeset/autocomplete-ignore-cache.md @@ -0,0 +1,5 @@ +--- +"kilo-code": patch +--- + +Cap autocomplete ignore path caching so long sessions do not retain unlimited paths. diff --git a/packages/kilo-vscode/src/services/autocomplete/shims/FileIgnoreController.ts b/packages/kilo-vscode/src/services/autocomplete/shims/FileIgnoreController.ts index 1b8c639cb48..9b0e3d9957c 100644 --- a/packages/kilo-vscode/src/services/autocomplete/shims/FileIgnoreController.ts +++ b/packages/kilo-vscode/src/services/autocomplete/shims/FileIgnoreController.ts @@ -14,6 +14,7 @@ const SENSITIVE_PATTERNS = [".env", ".env.*"] // path.isAbsolute() on POSIX does not recognise these, so we check explicitly // to avoid passing them to the `ignore` package which throws a RangeError. const WINDOWS_DRIVE = /^[a-zA-Z]:[/\\]/ +const REALPATH_CACHE_MAX = 1_000 function toPosix(filePath: string): string { return filePath.replace(/\\/g, "/") @@ -32,6 +33,7 @@ export class FileIgnoreController { async initialize(): Promise { this.ignoreInstance = ignore() this.loadedContents = [] + this.realpathCache.clear() if (!this.workspacePath) { return @@ -65,6 +67,14 @@ export class FileIgnoreController { this.ignoreInstance.add(SENSITIVE_PATTERNS) } + private cacheRealpath(input: string, resolved: string): void { + if (this.realpathCache.size >= REALPATH_CACHE_MAX) { + const key = this.realpathCache.keys().next().value + if (key !== undefined) this.realpathCache.delete(key) + } + this.realpathCache.set(input, resolved) + } + private toRelativePath(filePath: string): string | null { if (!filePath) { return null @@ -85,7 +95,7 @@ export class FileIgnoreController { } else { try { resolved = fs.realpathSync(absoluteInput) - this.realpathCache.set(absoluteInput, resolved) + this.cacheRealpath(absoluteInput, resolved) } catch { // Keep unresolved path when file does not exist yet. } @@ -142,6 +152,7 @@ export class FileIgnoreController { dispose(): void { this.loadedContents = [] + this.realpathCache.clear() this.ignoreInstance = ignore() } }