MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / loadLogList

Function loadLogList

source code/utils/log.ts:233–285  ·  view source on GitHub ↗

* Internal function to load and process logs from a specified path * @param path Directory containing logs * @returns Array of logs sorted by date * @private

(path: string)

Source from the content-addressed store, hash-verified

231 * @private
232 */
233async function loadLogList(path: string): Promise<LogOption[]> {
234 let files: Awaited<ReturnType<typeof readdir>>
235 try {
236 files = await readdir(path, { withFileTypes: true })
237 } catch {
238 logError(new Error(`No logs found at ${path}`))
239 return []
240 }
241 const logData = await Promise.all(
242 files.map(async (file, i) => {
243 const fullPath = join(path, file.name)
244 const content = await readFile(fullPath, { encoding: 'utf8' })
245 const messages = jsonParse(content) as SerializedMessage[]
246 const firstMessage = messages[0]
247 const lastMessage = messages[messages.length - 1]
248 const firstPrompt =
249 firstMessage?.type === 'user' &&
250 typeof firstMessage?.message?.content === 'string'
251 ? firstMessage?.message?.content
252 : 'No prompt'
253
254 // For new random filenames, we'll get stats from the file itself
255 const fileStats = await stat(fullPath)
256
257 // Check if it's a sidechain by looking at filename
258 const isSidechain = fullPath.includes('sidechain')
259
260 // For new files, use the file modified time as date
261 const date = dateToFilename(fileStats.mtime)
262
263 return {
264 date,
265 fullPath,
266 messages,
267 value: i, // hack: overwritten after sorting, right below this
268 created: parseISOString(firstMessage?.timestamp || date),
269 modified: lastMessage?.timestamp
270 ? parseISOString(lastMessage.timestamp)
271 : parseISOString(date),
272 firstPrompt:
273 firstPrompt.split('\n')[0]?.slice(0, 50) +
274 (firstPrompt.length > 50 ? '…' : '') || 'No prompt',
275 messageCount: messages.length,
276 isSidechain,
277 }
278 }),
279 )
280
281 return sortLogs(logData.filter(_ => _ !== null)).map((_, i) => ({
282 ..._,
283 value: i,
284 }))
285}
286
287function parseISOString(s: string): Date {
288 const b = s.split(/\D+/)

Callers 1

loadErrorLogsFunction · 0.85

Calls 8

readdirFunction · 0.85
readFileFunction · 0.85
jsonParseFunction · 0.85
statFunction · 0.85
dateToFilenameFunction · 0.85
parseISOStringFunction · 0.85
sortLogsFunction · 0.85
logErrorFunction · 0.70

Tested by

no test coverage detected