(projectRoot, filters = {})
| 261 | } |
| 262 | |
| 263 | function loadMemoryBlocks(projectRoot, filters = {}) { |
| 264 | const dir = blocksDir(projectRoot); |
| 265 | if (!fs.existsSync(dir)) return []; |
| 266 | const query = filters.query |
| 267 | ? String(filters.query).toLowerCase().split(/\s+/).map((term) => term.trim()).filter(Boolean) |
| 268 | : null; |
| 269 | const scope = filters.scope ? String(filters.scope).toLowerCase() : null; |
| 270 | const type = filters.type ? String(filters.type).toLowerCase() : null; |
| 271 | return fs.readdirSync(dir) |
| 272 | .filter((entry) => entry.endsWith('.json')) |
| 273 | .map((entry) => readBlockFile(path.join(dir, entry))) |
| 274 | .filter((entry) => !type || entry.type === type) |
| 275 | .filter((entry) => !scope || entry.scope.some((item) => String(item).toLowerCase().includes(scope))) |
| 276 | .filter((entry) => !query || query.every((term) => JSON.stringify(entry).toLowerCase().includes(term))) |
| 277 | .sort((a, b) => a.id.localeCompare(b.id)); |
| 278 | } |
| 279 | |
| 280 | function isOlderThan(dateString, days, now = new Date()) { |
| 281 | const time = Date.parse(dateString); |
no test coverage detected