MCPcopy
hub / github.com/codeaashu/claude-code / makeLogEntryReader

Function makeLogEntryReader

src/history.ts:106–143  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

104}
105
106async 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
145export async function* makeHistoryReader(): AsyncGenerator<HistoryEntry> {
146 for await (const entry of makeLogEntryReader()) {

Callers 3

makeHistoryReaderFunction · 0.85
getTimestampedHistoryFunction · 0.85
getHistoryFunction · 0.85

Calls 6

getSessionIdFunction · 0.85
readLinesReverseFunction · 0.85
deserializeLogEntryFunction · 0.85
logForDebuggingFunction · 0.85
getErrnoCodeFunction · 0.85
hasMethod · 0.45

Tested by

no test coverage detected