MCPcopy
hub / github.com/codeaashu/claude-code / trackSessionBranchingAnalytics

Function trackSessionBranchingAnalytics

src/utils/sessionStorage.ts:2526–2557  ·  view source on GitHub ↗
(
  logs: LogOption[],
)

Source from the content-addressed store, hash-verified

2524}
2525
2526async function trackSessionBranchingAnalytics(
2527 logs: LogOption[],
2528): Promise<void> {
2529 const sessionIdCounts = new Map<string, number>()
2530 let maxCount = 0
2531 for (const log of logs) {
2532 const sessionId = getSessionIdFromLog(log)
2533 if (sessionId) {
2534 const newCount = (sessionIdCounts.get(sessionId) || 0) + 1
2535 sessionIdCounts.set(sessionId, newCount)
2536 maxCount = Math.max(newCount, maxCount)
2537 }
2538 }
2539
2540 // Early exit if no duplicates detected
2541 if (maxCount <= 1) {
2542 return
2543 }
2544
2545 // Count sessions with branches and calculate stats using functional approach
2546 const branchCounts = Array.from(sessionIdCounts.values()).filter(c => c > 1)
2547 const sessionsWithBranches = branchCounts.length
2548 const totalBranches = branchCounts.reduce((sum, count) => sum + count, 0)
2549
2550 logEvent('tengu_session_forked_branches_fetched', {
2551 total_sessions: sessionIdCounts.size,
2552 sessions_with_branches: sessionsWithBranches,
2553 max_branches_per_session: Math.max(...branchCounts),
2554 avg_branches_per_session: Math.round(totalBranches / sessionsWithBranches),
2555 total_transcript_count: logs.length,
2556 })
2557}
2558
2559export async function fetchLogs(limit?: number): Promise<LogOption[]> {
2560 const projectDir = getProjectDir(getOriginalCwd())

Callers 1

fetchLogsFunction · 0.85

Calls 6

getSessionIdFromLogFunction · 0.85
logEventFunction · 0.85
maxMethod · 0.80
valuesMethod · 0.80
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected