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

Function trackSessionBranchingAnalytics

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

Source from the content-addressed store, hash-verified

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

Tested by

no test coverage detected