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

Function findLatestMessage

source code/utils/sessionStorage.ts:2048–2063  ·  view source on GitHub ↗

* O(n) single-pass: find the message with the latest timestamp matching a predicate. * Replaces the `[...values].filter(pred).sort((a,b) => Date(b)-Date(a))[0]` pattern * which is O(n log n) + 2n Date allocations.

(
  messages: Iterable<T>,
  predicate: (m: T) => boolean,
)

Source from the content-addressed store, hash-verified

2046 * which is O(n log n) + 2n Date allocations.
2047 */
2048function findLatestMessage<T extends { timestamp: string }>(
2049 messages: Iterable<T>,
2050 predicate: (m: T) => boolean,
2051): T | undefined {
2052 let latest: T | undefined
2053 let maxTime = -Infinity
2054 for (const m of messages) {
2055 if (!predicate(m)) continue
2056 const t = Date.parse(m.timestamp)
2057 if (t > maxTime) {
2058 maxTime = t
2059 latest = m
2060 }
2061 }
2062 return latest
2063}
2064
2065/**
2066 * Builds a conversation chain from a leaf message to root

Callers 4

loadTranscriptFromFileFunction · 0.85
loadFullLogFunction · 0.85
getLastSessionLogFunction · 0.85
getAgentTranscriptFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected