()
| 188 | * entries are reordered within that window, not beyond it. |
| 189 | */ |
| 190 | export async function* getHistory(): AsyncGenerator<HistoryEntry> { |
| 191 | const currentProject = getProjectRoot() |
| 192 | const currentSession = getSessionId() |
| 193 | const otherSessionEntries: LogEntry[] = [] |
| 194 | let yielded = 0 |
| 195 | |
| 196 | for await (const entry of makeLogEntryReader()) { |
| 197 | // Skip malformed entries (corrupted file, old format, or invalid JSON structure) |
| 198 | if (!entry || typeof entry.project !== 'string') continue |
| 199 | if (entry.project !== currentProject) continue |
| 200 | |
| 201 | if (entry.sessionId === currentSession) { |
| 202 | yield await logEntryToHistoryEntry(entry) |
| 203 | yielded++ |
| 204 | } else { |
| 205 | otherSessionEntries.push(entry) |
| 206 | } |
| 207 | |
| 208 | // Same MAX_HISTORY_ITEMS window as before — just reordered within it. |
| 209 | if (yielded + otherSessionEntries.length >= MAX_HISTORY_ITEMS) break |
| 210 | } |
| 211 | |
| 212 | for (const entry of otherSessionEntries) { |
| 213 | if (yielded >= MAX_HISTORY_ITEMS) return |
| 214 | yield await logEntryToHistoryEntry(entry) |
| 215 | yielded++ |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | type LogEntry = { |
| 220 | display: string |
no test coverage detected