(
data: AggregatedData,
insights: InsightResults,
facets: Map<string, SessionFacets>,
remoteStats?: { hosts: RemoteHostInfo[]; totalCopied: number },
)
| 2677 | * Used by background upload to S3. |
| 2678 | */ |
| 2679 | export function buildExportData( |
| 2680 | data: AggregatedData, |
| 2681 | insights: InsightResults, |
| 2682 | facets: Map<string, SessionFacets>, |
| 2683 | remoteStats?: { hosts: RemoteHostInfo[]; totalCopied: number }, |
| 2684 | ): InsightsExport { |
| 2685 | const version = typeof MACRO !== 'undefined' ? MACRO.VERSION : 'unknown' |
| 2686 | |
| 2687 | const remote_hosts_collected = remoteStats?.hosts |
| 2688 | .filter(h => h.sessionCount > 0) |
| 2689 | .map(h => h.name) |
| 2690 | |
| 2691 | const facets_summary = { |
| 2692 | total: facets.size, |
| 2693 | goal_categories: {} as Record<string, number>, |
| 2694 | outcomes: {} as Record<string, number>, |
| 2695 | satisfaction: {} as Record<string, number>, |
| 2696 | friction: {} as Record<string, number>, |
| 2697 | } |
| 2698 | for (const f of facets.values()) { |
| 2699 | for (const [cat, count] of safeEntries(f.goal_categories)) { |
| 2700 | if (count > 0) { |
| 2701 | facets_summary.goal_categories[cat] = |
| 2702 | (facets_summary.goal_categories[cat] || 0) + count |
| 2703 | } |
| 2704 | } |
| 2705 | facets_summary.outcomes[f.outcome] = |
| 2706 | (facets_summary.outcomes[f.outcome] || 0) + 1 |
| 2707 | for (const [level, count] of safeEntries(f.user_satisfaction_counts)) { |
| 2708 | if (count > 0) { |
| 2709 | facets_summary.satisfaction[level] = |
| 2710 | (facets_summary.satisfaction[level] || 0) + count |
| 2711 | } |
| 2712 | } |
| 2713 | for (const [type, count] of safeEntries(f.friction_counts)) { |
| 2714 | if (count > 0) { |
| 2715 | facets_summary.friction[type] = |
| 2716 | (facets_summary.friction[type] || 0) + count |
| 2717 | } |
| 2718 | } |
| 2719 | } |
| 2720 | |
| 2721 | return { |
| 2722 | metadata: { |
| 2723 | username: process.env.SAFEUSER || process.env.USER || 'unknown', |
| 2724 | generated_at: new Date().toISOString(), |
| 2725 | claude_code_version: version, |
| 2726 | date_range: data.date_range, |
| 2727 | session_count: data.total_sessions, |
| 2728 | ...(remote_hosts_collected && |
| 2729 | remote_hosts_collected.length > 0 && { |
| 2730 | remote_hosts_collected, |
| 2731 | }), |
| 2732 | }, |
| 2733 | aggregated_data: data, |
| 2734 | insights, |
| 2735 | facets_summary, |
| 2736 | } |
nothing calls this directly
no test coverage detected