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

Function trackSessionBranchingAnalytics

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

Source from the content-addressed store, hash-verified

2686}
2687
2688async function trackSessionBranchingAnalytics(
2689 logs: LogOption[],
2690): Promise<void> {
2691 const sessionIdCounts = new Map<string, number>()
2692 let maxCount = 0
2693 for (const log of logs) {
2694 const sessionId = getSessionIdFromLog(log)
2695 if (sessionId) {
2696 const newCount = (sessionIdCounts.get(sessionId) || 0) + 1
2697 sessionIdCounts.set(sessionId, newCount)
2698 maxCount = Math.max(newCount, maxCount)
2699 }
2700 }
2701
2702 // Early exit if no duplicates detected
2703 if (maxCount <= 1) {
2704 return
2705 }
2706
2707 // Count sessions with branches and calculate stats using functional approach
2708 const branchCounts = Array.from(sessionIdCounts.values()).filter(c => c > 1)
2709 const sessionsWithBranches = branchCounts.length
2710 const totalBranches = branchCounts.reduce((sum, count) => sum + count, 0)
2711
2712 logEvent('ncode_session_forked_branches_fetched', {
2713 total_sessions: sessionIdCounts.size,
2714 sessions_with_branches: sessionsWithBranches,
2715 max_branches_per_session: Math.max(...branchCounts),
2716 avg_branches_per_session: Math.round(totalBranches / sessionsWithBranches),
2717 total_transcript_count: logs.length,
2718 })
2719}
2720
2721export async function fetchLogs(limit?: number): Promise<LogOption[]> {
2722 const projectDir = getProjectDir(getOriginalCwd())

Callers 1

fetchLogsFunction · 0.85

Calls 5

getSessionIdFromLogFunction · 0.85
setMethod · 0.80
maxMethod · 0.80
logEventFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected