/** * dashboard-client/src/tabs/MaintenanceTab/DebugBundleCard.tsx — Debug Bundle card. * * Extracted from MaintenanceTab.tsx (delegate-shell split). Gather a diagnostic * bundle (events, config, schema health, store stats) and let the user copy or * download it for bug reports. */ import type React from "react"; import { useState, useCallback } from "react"; import type { DebugBundleResponse } from "@contracts"; import { fetchDebugBundle } from "../../api/client"; import { Button } from "../../components/ui/button"; import { Card, CardHeader, CardTitle, CardContent, } from "../../components/ui/card"; // --------------------------------------------------------------------------- // Debug bundle card — gather diagnostic info for bug reports // --------------------------------------------------------------------------- export function DebugBundleCard(): React.ReactElement { const [bundle, setBundle] = useState(null); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [showJson, setShowJson] = useState(false); const gather = useCallback(async () => { setLoading(true); setError(null); try { const res = await fetchDebugBundle(); setBundle(res); setShowJson(true); } catch (err) { setError(err instanceof Error ? err.message : String(err)); } finally { setLoading(false); } }, []); const copyToClipboard = useCallback(() => { if (!bundle) return; const text = JSON.stringify(bundle, null, 2); void navigator.clipboard.writeText(text).catch(() => {}); }, [bundle]); const downloadJson = useCallback(() => { if (!bundle) return; const text = JSON.stringify(bundle, null, 2); const blob = new Blob([text], { type: "application/json" }); const url = URL.createObjectURL(blob); const a = document.createElement("a"); a.href = url; a.download = `mega-compact-debug-bundle-${bundle.builtAt}.json`; a.click(); URL.revokeObjectURL(url); }, [bundle]); const criticalCount = bundle?.criticalEvents.length ?? 0; return ( Debug Bundle {criticalCount > 0 && ( {criticalCount} critical event{criticalCount !== 1 ? "s" : ""} found )}

Gather a diagnostic bundle (recent events, config flags, schema health, store stats) to attach to a bug report. Critical/compaction events are highlighted.

{error &&
{error}
} {bundle && showJson && ( <>
{criticalCount > 0 && (
Critical events ({criticalCount})
									{JSON.stringify(bundle.criticalEvents, null, 2)}
								
)}
							{JSON.stringify(bundle, null, 2)}
						
)}
); }