MCPcopy Create free account
hub / github.com/claude-code-best/claude-code / trackSessionBranchingAnalytics

Function trackSessionBranchingAnalytics

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

Source from the content-addressed store, hash-verified

2563}
2564
2565async function trackSessionBranchingAnalytics(
2566 logs: LogOption[],
2567): Promise<void> {
2568 const sessionIdCounts = new Map<string, number>()
2569 let maxCount = 0
2570 for (const log of logs) {
2571 const sessionId = getSessionIdFromLog(log)
2572 if (sessionId) {
2573 const newCount = (sessionIdCounts.get(sessionId) || 0) + 1
2574 sessionIdCounts.set(sessionId, newCount)
2575 maxCount = Math.max(newCount, maxCount)
2576 }
2577 }
2578
2579 // Early exit if no duplicates detected
2580 if (maxCount <= 1) {
2581 return
2582 }
2583
2584 // Count sessions with branches and calculate stats using functional approach
2585 const branchCounts = Array.from(sessionIdCounts.values()).filter(c => c > 1)
2586 const sessionsWithBranches = branchCounts.length
2587 const totalBranches = branchCounts.reduce((sum, count) => sum + count, 0)
2588
2589 logEvent('tengu_session_forked_branches_fetched', {
2590 total_sessions: sessionIdCounts.size,
2591 sessions_with_branches: sessionsWithBranches,
2592 max_branches_per_session: Math.max(...branchCounts),
2593 avg_branches_per_session: Math.round(totalBranches / sessionsWithBranches),
2594 total_transcript_count: logs.length,
2595 })
2596}
2597
2598export async function fetchLogs(limit?: number): Promise<LogOption[]> {
2599 const projectDir = getProjectDir(getOriginalCwd())

Callers 1

fetchLogsFunction · 0.85

Calls 5

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

Tested by

no test coverage detected