MCPcopy
hub / github.com/claude-code-best/claude-code / getHistory

Function getHistory

src/history.ts:190–217  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

188 * entries are reordered within that window, not beyond it.
189 */
190export 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
219type LogEntry = {
220 display: string

Callers 2

getShellHistoryCommandsFunction · 0.85
loadHistoryEntriesFunction · 0.85

Calls 5

getProjectRootFunction · 0.85
getSessionIdFunction · 0.85
makeLogEntryReaderFunction · 0.85
logEntryToHistoryEntryFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected