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

Function buildExportData

src/commands/insights.ts:2685–2743  ·  view source on GitHub ↗
(
  data: AggregatedData,
  insights: InsightResults,
  facets: Map<string, SessionFacets>,
  remoteStats?: { hosts: RemoteHostInfo[]; totalCopied: number },
)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 1

safeEntriesFunction · 0.85

Tested by

no test coverage detected