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

Function getTranscriptStats

source code/utils/attribution.ts:253–284  ·  view source on GitHub ↗

* Read session transcript entries and compute prompt count and memory access * count. Pre-compact entries are skipped — the N-shot count and memory-access * count should reflect only the current conversation arc, not accumulated * prompts from before a compaction boundary.

()

Source from the content-addressed store, hash-verified

251 * prompts from before a compaction boundary.
252 */
253async function getTranscriptStats(): Promise<{
254 promptCount: number
255 memoryAccessCount: number
256}> {
257 try {
258 const filePath = getTranscriptPath()
259 const fileSize = (await stat(filePath)).size
260 // Fused reader: attr-snap lines (84% of a long session by bytes) are
261 // skipped at the fd level so peak scales with output, not file size. The
262 // one surviving attr-snap at EOF is a no-op for the count functions
263 // (neither checks type === 'attribution-snapshot'). When the last
264 // boundary has preservedSegment the reader returns full (no truncate);
265 // the findLastIndex below still slices to post-boundary.
266 const scan = await readTranscriptForLoad(filePath, fileSize)
267 const buf = scan.postBoundaryBuf
268 const entries = parseJSONL<Entry>(buf)
269 const lastBoundaryIdx = entries.findLastIndex(
270 e =>
271 e.type === 'system' &&
272 'subtype' in e &&
273 e.subtype === 'compact_boundary',
274 )
275 const postBoundary =
276 lastBoundaryIdx >= 0 ? entries.slice(lastBoundaryIdx + 1) : entries
277 return {
278 promptCount: countUserPromptsFromEntries(postBoundary),
279 memoryAccessCount: countMemoryFileAccessFromEntries(postBoundary),
280 }
281 } catch {
282 return { promptCount: 0, memoryAccessCount: 0 }
283 }
284}
285
286/**
287 * Get enhanced PR attribution text with Claude contribution stats.

Callers 1

getEnhancedPRAttributionFunction · 0.85

Calls 6

parseJSONLFunction · 0.90
getTranscriptPathFunction · 0.85
statFunction · 0.85
readTranscriptForLoadFunction · 0.85

Tested by

no test coverage detected