(filePath, currentId, currentDir, n)
| 297 | // and stop as soon as we have `n`. Parse count is bounded by where this |
| 298 | // workspace's n-th-most-recent entry sits, not by total file size. |
| 299 | function readRecentWorkspaceEntries(filePath, currentId, currentDir, n) { |
| 300 | let lines; |
| 301 | try { |
| 302 | lines = fs.readFileSync(filePath, 'utf8').trim().split('\n'); |
| 303 | } catch { return []; } |
| 304 | const out = []; |
| 305 | for (let i = lines.length - 1; i >= 0 && out.length < n; i--) { |
| 306 | const line = lines[i]; |
| 307 | if (!line) continue; |
| 308 | let entry; |
| 309 | try { entry = JSON.parse(line); } catch { continue; } |
| 310 | if (belongsToWorkspace(entry, currentId, currentDir)) out.push(entry); |
| 311 | } |
| 312 | return out.reverse(); // newest-collected-first -> chronological |
| 313 | } |
| 314 | |
| 315 | // Does this memory-graph entry belong to the current workspace? |
| 316 | // |
no test coverage detected