MCPcopy Index your code
hub / github.com/codeaashu/claude-code / getTranscriptStats

Function getTranscriptStats

src/utils/attribution.ts:251–282  ·  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

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