MCPcopy Create free account
hub / github.com/Noumena-Network/code / getTranscriptStats

Function getTranscriptStats

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

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