()
| 104 | } |
| 105 | |
| 106 | async function* makeLogEntryReader(): AsyncGenerator<LogEntry> { |
| 107 | const currentSession = getSessionId() |
| 108 | |
| 109 | // Start with entries that have yet to be flushed to disk |
| 110 | for (let i = pendingEntries.length - 1; i >= 0; i--) { |
| 111 | yield pendingEntries[i]! |
| 112 | } |
| 113 | |
| 114 | // Read from global history file (shared across all projects) |
| 115 | const historyPath = join(getClaudeConfigHomeDir(), 'history.jsonl') |
| 116 | |
| 117 | try { |
| 118 | for await (const line of readLinesReverse(historyPath)) { |
| 119 | try { |
| 120 | const entry = deserializeLogEntry(line) |
| 121 | // removeLastFromHistory slow path: entry was flushed before removal, |
| 122 | // so filter here so both getHistory (Up-arrow) and makeHistoryReader |
| 123 | // (ctrl+r search) skip it consistently. |
| 124 | if ( |
| 125 | entry.sessionId === currentSession && |
| 126 | skippedTimestamps.has(entry.timestamp) |
| 127 | ) { |
| 128 | continue |
| 129 | } |
| 130 | yield entry |
| 131 | } catch (error) { |
| 132 | // Not a critical error - just skip malformed lines |
| 133 | logForDebugging(`Failed to parse history line: ${error}`) |
| 134 | } |
| 135 | } |
| 136 | } catch (e: unknown) { |
| 137 | const code = getErrnoCode(e) |
| 138 | if (code === 'ENOENT') { |
| 139 | return |
| 140 | } |
| 141 | throw e |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | export async function* makeHistoryReader(): AsyncGenerator<HistoryEntry> { |
| 146 | for await (const entry of makeLogEntryReader()) { |
no test coverage detected