| 32 | } |
| 33 | |
| 34 | private load(): PersistentStateData { |
| 35 | if (this.cache) { |
| 36 | return this.cache; |
| 37 | } |
| 38 | try { |
| 39 | const filePath = this.getPath(); |
| 40 | if (fs.existsSync(filePath)) { |
| 41 | const content = fs.readFileSync(filePath, 'utf-8'); |
| 42 | // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment |
| 43 | this.cache = JSON.parse(content); |
| 44 | } else { |
| 45 | this.cache = {}; |
| 46 | } |
| 47 | } catch (error) { |
| 48 | debugLogger.warn('Failed to load persistent state:', error); |
| 49 | // If error reading (e.g. corrupt JSON), start fresh |
| 50 | this.cache = {}; |
| 51 | } |
| 52 | return this.cache!; |
| 53 | } |
| 54 | |
| 55 | private save() { |
| 56 | if (!this.cache) return; |