Spaces:
Configuration error
Configuration error
File size: 44,526 Bytes
05251fc 33a4fd2 05251fc 33a4fd2 05251fc 33a4fd2 05251fc 33a4fd2 05251fc 33a4fd2 05251fc 33a4fd2 05251fc 33a4fd2 05251fc 33a4fd2 05251fc 33a4fd2 05251fc 33a4fd2 05251fc d231444 05251fc d231444 05251fc d231444 05251fc d231444 05251fc d231444 05251fc d231444 33a4fd2 d231444 05251fc 33a4fd2 05251fc 33a4fd2 05251fc 33a4fd2 05251fc 33a4fd2 05251fc 33a4fd2 05251fc d231444 05251fc 33a4fd2 05251fc d231444 05251fc d231444 05251fc d231444 05251fc d231444 05251fc d231444 05251fc d231444 05251fc d231444 05251fc 33a4fd2 05251fc d231444 05251fc 33a4fd2 05251fc 33a4fd2 05251fc 33a4fd2 05251fc 33a4fd2 05251fc 33a4fd2 05251fc 33a4fd2 05251fc 33a4fd2 05251fc 33a4fd2 05251fc 33a4fd2 05251fc 33a4fd2 05251fc 33a4fd2 05251fc 33a4fd2 05251fc 33a4fd2 05251fc 33a4fd2 05251fc 33a4fd2 05251fc 33a4fd2 05251fc 33a4fd2 05251fc 33a4fd2 05251fc d231444 05251fc d231444 05251fc d231444 05251fc d231444 05251fc d231444 05251fc 33a4fd2 05251fc 33a4fd2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 | /**
* ReportPanel β Health Report.
*
* Reads as a structured audit rather than a dashboard:
*
* AUDIT (header + score anchor + diagnostic strip)
* β FINDINGS (mode rail: architecture / api / hygiene / onboarding)
* β EVIDENCE (bounded lists, progressive disclosure)
* β PRIORITIES (ranked action issues)
* β ACTION (export)
*
* Every number comes from `/report/{owner}/{repo}/build` unchanged. The one
* score visualisation is the donut; the strip reports the other dimensions so
* the overall figure is never repeated three times.
*/
import React, { useState, useEffect, useMemo, useCallback } from 'react';
import { apiUrl, extractErrorMessage } from '../../lib/api';
import {
FileText, Download, Printer, AlertTriangle, ChevronDown,
Layers, Globe, Trash2, BookOpen, ArrowRight, RefreshCw,
} from 'lucide-react';
import { Button } from '../ui/Button';
import { EmptyState } from '../ui/EmptyState';
import { SkeletonCard, SkeletonGroup, Skeleton } from '../ui/Skeleton';
import { SVGDonut } from '../ui/SVGDonut';
import { AnimatedNumber } from '../ui/AnimatedNumber';
import { FilePath } from '../ui/FilePath';
import { Meter } from '../ui/Meter';
import { Reveal } from '../ui/Reveal';
import { SectionSeam } from '../ui/SectionSeam';
interface ScoreBreakdown {
overall: number;
architecture: number;
api: number;
hygiene: number;
churn: number;
readability: number;
grade: string;
}
interface ReportMetadata {
repo_name: string;
owner: string;
name: string;
total_loc: number;
commits_count: number;
languages: Record<string, number>;
generated_at: string;
execution_time_ms: number;
}
interface ArchReportSection {
cycles_count: number;
cycles: string[][];
strongly_connected_components: number;
smells_count: number;
smells: string[];
}
interface ApiReportSection {
total_exported_symbols: number;
public_private_ratio: number;
average_distance_main_sequence: number;
unstable_modules_count: number;
}
interface HygieneReportSection {
dead_functions_count: number;
dead_functions: string[];
dead_code_ratio: number;
}
interface OnboardingReportSection {
reading_path_completeness: number;
core_entry_points: string[];
recommended_reading_path: string[];
}
interface ReportDataModel {
metadata: ReportMetadata;
scores: ScoreBreakdown;
architecture: ArchReportSection;
api_surface: ApiReportSection;
hygiene: HygieneReportSection;
onboarding: OnboardingReportSection;
refactoring_priorities: string[];
ai_summary?: string;
}
interface ReportPanelProps {
repoName: string;
/**
* Switches the parent dashboard tab. Wired to the dashboard's existing
* `handleTabChange`, so cross-surface links reuse current navigation rather
* than introducing a second mechanism.
*/
onNavigate?: (tab: string) => void;
}
type SubTabId = 'architecture' | 'api' | 'hygiene' | 'onboarding';
const MODES: [SubTabId, string, React.ComponentType<{ className?: string }>][] = [
['architecture', 'ARCHITECTURE', Layers],
['api', 'API SURFACE', Globe],
['hygiene', 'HYGIENE', Trash2],
['onboarding', 'ONBOARDING', BookOpen],
];
function gradeToneClass(grade: string): string {
if (grade === 'A') return 'text-success';
if (grade === 'B') return 'text-primary';
if (grade === 'C') return 'text-warn';
return 'text-danger';
}
function getScoreTone(score: number): 'success' | 'warn' | 'danger' {
if (score >= 80) return 'success';
if (score >= 60) return 'warn';
return 'danger';
}
function scoreBarClass(score: number): string {
if (score >= 80) return 'bg-success';
if (score >= 60) return 'bg-warn';
return 'bg-danger';
}
function relativeTime(iso: string): string {
try {
const diff = Math.round((Date.now() - new Date(iso).getTime()) / 60000);
if (diff < 1) return 'just now';
if (diff < 60) return `${diff} min ago`;
return `${Math.round(diff / 60)}h ago`;
} catch {
return iso;
}
}
/** Cross-surface actions. Both use contracts the dashboard already listens for. */
function openInGraph(owner: string, repo: string, path: string) {
window.dispatchEvent(
new CustomEvent('aria-open-graph', {
detail: { owner, repo, path, source: 'health-report' },
})
);
}
function openInChat(owner: string, repo: string, path: string, prompt: string) {
window.dispatchEvent(
new CustomEvent('aria-open-chat', {
detail: { owner, repo, path, source: 'health-report', prompt },
})
);
}
// ββ Small building blocks ββββββββββββββββββββββββββββββββββββββββββββββββββ
/** A hairline-separated diagnostic cell. */
const Readout: React.FC<{
label: string;
value: React.ReactNode;
detail?: React.ReactNode;
tone?: string;
index?: number;
}> = ({ label, value, detail, tone = 'text-text', index = 0 }) => (
<div
className="min-w-0 px-4 sm:px-5 py-4 border-b border-white/[0.055]
border-l border-white/[0.055]
[&:nth-child(2n+1)]:border-l-0
md:[&:nth-child(2n+1)]:border-l md:[&:nth-child(3n+1)]:border-l-0"
style={{ ['--reveal-delay' as string]: `${index * 60}ms` }}
>
<dt className="mono-label mb-2">{label}</dt>
<dd>
<span className={`readout-value block ${tone}`}>{value}</span>
{detail && (
<span className="mono-detail block mt-1.5 truncate" style={{ fontSize: 10 }}>
{detail}
</span>
)}
</dd>
</div>
);
/** Top-N list with a bounded scroll region behind "view all". */
const BoundedList: React.FC<{
total: number;
preview: number;
label: string;
children: (limit: number | null) => React.ReactNode;
}> = ({ total, preview, label, children }) => {
const [expanded, setExpanded] = useState(false);
const overflow = total > preview;
return (
<>
<div
className={
expanded
? 'max-h-[22rem] overflow-y-auto pr-1 -mr-1 min-w-0'
: 'min-w-0'
}
>
{children(expanded ? null : preview)}
</div>
{overflow && (
<button
type="button"
onClick={() => setExpanded((p) => !p)}
className="api-action link-arrow mt-4"
aria-expanded={expanded}
>
{expanded ? 'SHOW FEWER' : `VIEW ALL ${total.toLocaleString()} ${label}`}
<ArrowRight className="h-3 w-3 arrow" aria-hidden="true" />
</button>
)}
</>
);
};
// ββ Prioritized issue row ββββββββββββββββββββββββββββββββββββββββββββββββββ
interface ParsedIssue {
id: string;
title: string;
severity: 'critical' | 'high' | 'medium' | 'low';
category: string;
icon: React.ComponentType<{ className?: string }>;
affectedFile: string;
impact: string;
fix: string;
}
const SEVERITY_CLASS: Record<ParsedIssue['severity'], string> = {
critical: 'text-danger',
high: 'text-warn',
medium: 'text-primary',
low: 'text-text-muted',
};
const IssueRow: React.FC<{
issue: ParsedIssue;
owner: string;
repo: string;
}> = ({ issue, owner, repo }) => {
const [open, setOpen] = useState(false);
const Icon = issue.icon;
const hasFile = issue.affectedFile !== 'multiple files';
return (
<div className="api-row hair-t last:border-b last:border-white/[0.055] min-w-0">
<button
type="button"
onClick={() => setOpen((p) => !p)}
aria-expanded={open}
className="w-full flex items-start gap-4 py-3.5 px-1 text-left min-w-0
focus-visible:outline-none focus-visible:shadow-ring"
>
{/* Severity + category lead the row */}
<span className="flex items-center gap-2.5 shrink-0 w-32 sm:w-44 pt-0.5">
<span
className={`font-mono text-[10px] uppercase tracking-[0.16em] ${SEVERITY_CLASS[issue.severity]}`}
>
{issue.severity}
</span>
<Icon className="h-3 w-3 shrink-0 text-text-subtle" aria-hidden="true" />
</span>
<span className="min-w-0 flex-1">
<span className="block text-[13px] text-text leading-snug break-words">
{issue.title}
</span>
<span className="mono-label block mt-1.5">{issue.category}</span>
</span>
<ChevronDown
className={`h-3.5 w-3.5 shrink-0 mt-1 text-text-subtle transition-transform duration-200 ${
open ? 'rotate-180' : ''
}`}
aria-hidden="true"
/>
</button>
{open && (
<div className="api-evidence px-1 pb-5 space-y-4 min-w-0 sm:pl-36">
{hasFile && (
<div className="min-w-0">
<span className="mono-label block mb-2">FILE PATH</span>
<FilePath path={issue.affectedFile} tone="primary" size="sm" />
</div>
)}
<div className="pt-4 hair-t">
<span className="mono-label block mb-2">ESTIMATED IMPACT</span>
<p className="text-[12px] text-text-muted leading-relaxed max-w-[70ch]">
{issue.impact}
</p>
</div>
<div className="pt-4 hair-t">
<span className="mono-label block mb-2">RECOMMENDED FIX</span>
<p className="text-[12px] text-text-muted leading-relaxed max-w-[70ch]">
{issue.fix}
</p>
</div>
{hasFile && (
<div className="flex flex-wrap items-center gap-x-6 gap-y-2 pt-4 hair-t">
<button
type="button"
onClick={() => openInGraph(owner, repo, issue.affectedFile)}
className="api-action link-arrow"
>
View in Graph
<ArrowRight className="h-3 w-3 arrow" aria-hidden="true" />
</button>
<button
type="button"
onClick={() =>
openInChat(
owner,
repo,
issue.affectedFile,
`Regarding \`${issue.affectedFile}\`: ${issue.title}. How should I approach this?`
)
}
className="api-action link-arrow"
>
Open in Chat
<ArrowRight className="h-3 w-3 arrow" aria-hidden="true" />
</button>
</div>
)}
</div>
)}
</div>
);
};
// ββ Main component βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
export const ReportPanel: React.FC<ReportPanelProps> = ({ repoName, onNavigate }) => {
const [report, setReport] = useState<ReportDataModel | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [subTab, setSubTab] = useState<SubTabId>('architecture');
const [owner, repo] = repoName.split('/');
/** Same endpoint and method as before; extracted so Refresh can re-run it. */
const loadReport = useCallback(() => {
if (!owner || !repo) {
setError('Invalid repository name');
setReport(null);
setLoading(false);
return;
}
setReport(null);
setLoading(true);
setError(null);
fetch(apiUrl(`/api/v1/report/${owner}/${repo}/build`), { method: 'POST' })
.then((res) => {
if (!res.ok) throw new Error('Failed to generate intelligence report');
return res.json();
})
.then((data) => { setReport(data); setLoading(false); })
.catch((err) => { setError(extractErrorMessage(err)); setLoading(false); });
}, [owner, repo]);
useEffect(() => { loadReport(); }, [loadReport]);
const handleExport = (format: 'html' | 'pdf' | 'markdown') => {
if (!owner || !repo) return;
const downloadUrl = apiUrl(`/api/v1/report/${owner}/${repo}/download?format=${format}`);
window.open(downloadUrl, '_blank');
};
// Severity mapping preserved exactly as before.
const parsedIssues = useMemo<ParsedIssue[]>(() => {
if (!report || !report.refactoring_priorities) return [];
return report.refactoring_priorities.map((item, idx) => {
const lower = item.toLowerCase();
let severity: 'critical' | 'high' | 'medium' | 'low' = 'low';
let category = 'Code Hygiene';
let icon: React.ComponentType<{ className?: string }> = Trash2;
let impact = 'Optimizes code execution path and minimizes static memory leaks';
let fix = 'Refactor local calls and safely delete the unused function symbol';
if (lower.includes('volatile') || lower.includes('cycle') || lower.includes('coupling')) {
severity = lower.includes('volatile') ? 'critical' : 'high';
category = 'Architecture';
icon = Layers;
impact = 'Averts cycle propagation and compiler dependency locks';
fix = 'Abstract call layers into utilities or register interface handlers';
} else if (lower.includes('dead') || lower.includes('unused') || lower.includes('hygiene')) {
severity = 'medium';
category = 'Code Hygiene';
icon = Trash2;
impact = 'Cleans up orphan logic branches and improves project code cleanliness';
fix = 'Locate caller references and safely clean up dead function definitions';
} else if (lower.includes('api') || lower.includes('public') || lower.includes('export')) {
severity = 'medium';
category = 'API Surface';
icon = Globe;
impact = 'Tightens system boundary encapsulation and module stability';
fix = 'Mark exports as private or document usage metrics';
} else if (lower.includes('read') || lower.includes('onboard') || lower.includes('path')) {
severity = 'low';
category = 'Onboarding';
icon = BookOpen;
impact = 'Speeds up developer onboarding paths and code search indexing';
fix = 'Supplement code comments or update recommended reading lists';
}
const pathMatch = item.match(/([a-zA-Z0-9_\-\/]+\.[a-zA-Z0-9]+)/);
const affectedFile = pathMatch ? pathMatch[1] : 'multiple files';
return { id: `issue-${idx}`, title: item, severity, category, icon, affectedFile, impact, fix };
});
}, [report]);
const attentionCount = useMemo(
() => parsedIssues.filter((i) => i.severity === 'critical' || i.severity === 'high' || i.severity === 'medium').length,
[parsedIssues]
);
if (loading) {
return (
<div className="space-y-6 select-none">
<div className="flex items-center gap-3 py-4">
<RefreshCw className="h-4 w-4 text-primary animate-spin" aria-hidden="true" />
<span className="mono-label">COMPILING REPOSITORY INTELLIGENCE REPORT</span>
</div>
<SkeletonGroup label="Generating report">
<div className="grid grid-cols-1 lg:grid-cols-12 gap-6">
<div className="lg:col-span-4 space-y-4"><SkeletonCard /><SkeletonCard /></div>
<div className="lg:col-span-8 space-y-4">
<Skeleton size="h-6 w-1/3" />
<Skeleton size="h-4 w-full" />
<Skeleton size="h-4 w-5/6" />
<Skeleton size="h-4 w-4/5" />
</div>
</div>
</SkeletonGroup>
</div>
);
}
if (error || !report) {
return (
<EmptyState
tone="danger"
icon={<AlertTriangle className="h-6 w-6" />}
title="Report Generation Failed"
description={error || 'Could not compile report metadata.'}
action={<Button onClick={loadReport}>Retry</Button>}
/>
);
}
const scoreTone = getScoreTone(report.scores.overall);
const isHighDebt = report.hygiene.dead_functions_count > 10;
const isHighComplexity = report.scores.architecture < 70;
const api = report.api_surface;
const distanceOutOfRange = api.average_distance_main_sequence > 0.3;
const ratioOutOfRange =
api.public_private_ratio < 0.1 || api.public_private_ratio > 0.5;
const ladder = [
{ label: 'Architecture Stability', value: report.scores.architecture },
{ label: 'API Quality & Encapsulation', value: report.scores.api },
{ label: 'Code Hygiene & Pruning', value: report.scores.hygiene },
{ label: 'Hotspot & Churn Control', value: report.scores.churn },
{ label: 'Onboarding Clarity', value: report.scores.readability },
];
return (
/* pb-24 keeps the sticky footer from ever covering the last section */
<div className="min-w-0 pb-24">
{/* ββ Header βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ */}
<header className="min-w-0">
<div className="flex flex-col lg:flex-row lg:items-end lg:justify-between gap-5">
<div className="min-w-0 max-w-2xl">
<span className="mono-label mono-label-accent block mb-3">AUDIT / HEALTH REPORT</span>
<h2 className="display-3 text-text">Health Report</h2>
<p className="text-[13px] text-text-muted leading-relaxed mt-3 max-w-xl">
Repository architecture, API quality, hygiene, and onboarding readiness.
</p>
<div className="flex flex-wrap items-center gap-x-4 gap-y-2 mt-5">
<span className="font-mono text-[11px] text-text">{report.metadata.repo_name}</span>
<span className="h-2.5 w-px bg-white/[0.09]" aria-hidden="true" />
<span className="mono-label" style={{ color: 'var(--success)' }}>INDEXED</span>
<span className="h-2.5 w-px bg-white/[0.09]" aria-hidden="true" />
<span className="mono-label">
GENERATED {relativeTime(report.metadata.generated_at).toUpperCase()}
</span>
</div>
</div>
<button
type="button"
onClick={loadReport}
className="flex items-center gap-2 mono-label hover:text-text transition-colors
focus-visible:outline-none shrink-0"
>
<RefreshCw className="h-3.5 w-3.5" aria-hidden="true" />
REBUILD
</button>
</div>
</header>
{/* ββ Score anchor + diagnostic strip ββββββββββββββββββββββββββββββββ */}
<div className="mt-10 grid grid-cols-1 lg:grid-cols-12 gap-8 lg:gap-10 items-start">
{/* The single score visualisation */}
<Reveal className="lg:col-span-4 min-w-0">
<div className="flex items-center gap-6">
<SVGDonut
value={report.scores.overall}
size={104}
strokeWidth={8}
tone={scoreTone}
label={
<>
<span className="text-2xl font-bold text-text font-mono leading-none tabular-nums">
<AnimatedNumber value={report.scores.overall} duration={900} />
</span>
<span className="mono-label mt-1" style={{ letterSpacing: '0.2em' }}>
HEALTH
</span>
</>
}
/>
<div className="min-w-0">
<span className="mono-label block mb-2">GRADE</span>
<span
className={`font-mono font-bold leading-none ${gradeToneClass(report.scores.grade)}`}
style={{ fontSize: 'clamp(2.25rem, 5vw, 3rem)' }}
>
{report.scores.grade}
</span>
</div>
</div>
{/* Diagnostic ladder */}
<dl className="mt-8 pt-6 hair-t">
{ladder.map((item, i) => (
<div key={item.label} className="py-2.5">
<div className="flex items-baseline justify-between gap-4">
<dt className="text-[12px] text-text-muted truncate">{item.label}</dt>
<dd className="font-mono text-[12px] text-text tabular-nums shrink-0">
<AnimatedNumber value={item.value} duration={700} startOnView />
<span className="text-text-subtle">/100</span>
</dd>
</div>
<Meter
value={item.value / 100}
barClassName={scoreBarClass(item.value)}
className="mt-2"
delay={i * 70}
/>
</div>
))}
</dl>
</Reveal>
{/* Remaining dimensions β hairline cells, not cards */}
<dl className="lg:col-span-8 grid grid-cols-2 md:grid-cols-3 border-t border-white/[0.055] min-w-0">
<Readout
index={0}
label="MAINTAINABILITY"
value={<><AnimatedNumber value={report.scores.readability} startOnView />%</>}
detail="onboarding path coverage"
/>
<Readout
index={1}
label="COMPLEXITY"
value={isHighComplexity ? 'HIGH' : 'MODERATE'}
detail="AST call-link density"
/>
<Readout
index={2}
label="ARCHITECTURE HEALTH"
value={<><AnimatedNumber value={report.scores.architecture} startOnView />%</>}
detail={report.architecture.cycles_count > 0 ? 'cycles found' : 'acyclic graph'}
tone={report.architecture.cycles_count > 0 ? 'text-warn' : 'text-success'}
/>
<Readout
index={3}
label="TECHNICAL DEBT"
value={isHighDebt ? 'MEDIUM' : 'LOW'}
detail={`${report.hygiene.dead_functions_count.toLocaleString()} orphan / dead symbols`}
tone={isHighDebt ? 'text-warn' : 'text-text'}
/>
{/*
The backend report carries no security scan or performance analysis,
so these are reported as not measured rather than asserting a pass.
*/}
<Readout index={4} label="SECURITY" value="β" detail="not measured" tone="text-text-subtle" />
<Readout index={5} label="PERFORMANCE" value="β" detail="not measured" tone="text-text-subtle" />
</dl>
</div>
<SectionSeam label="DIAGNOSTIC β EVIDENCE" />
{/* ββ Mode rail ββββββββββββββββββββββββββββββββββββββββββββββββββββββ */}
<div
className="inner-scroll-x relative flex items-stretch gap-6 border-y border-white/[0.055]"
role="tablist"
aria-label="Report sections"
>
{MODES.map(([id, label, Icon]) => {
const isActive = subTab === id;
return (
<button
key={id}
role="tab"
type="button"
aria-selected={isActive}
aria-controls={`report-panel-${id}`}
onClick={() => setSubTab(id)}
className={`group relative shrink-0 flex items-center gap-2 py-3
font-mono text-[11px] uppercase tracking-[0.14em] whitespace-nowrap
transition-colors duration-200 focus-visible:outline-none ${
isActive ? 'text-text' : 'text-text-subtle hover:text-text-muted'
}`}
>
<Icon
className={`h-3.5 w-3.5 shrink-0 ${
isActive ? 'text-primary' : 'text-text-subtle group-hover:text-text-muted'
}`}
aria-hidden="true"
/>
{label}
<span
aria-hidden="true"
className="absolute -bottom-px left-0 right-0 h-px origin-left bg-primary"
style={{
transform: `scaleX(${isActive ? 1 : 0})`,
transition: 'transform 240ms cubic-bezier(0.16,1,0.3,1)',
}}
/>
</button>
);
})}
</div>
<div id={`report-panel-${subTab}`} role="tabpanel" className="mt-8 min-w-0 panel-enter">
{/* ββ Architecture βββββββββββββββββββββββββββββββββββββββββββββββββ */}
{subTab === 'architecture' && (
<div className="space-y-9 min-w-0">
<dl className="grid grid-cols-2 md:grid-cols-3 border-t border-white/[0.055]">
<Readout
index={0}
label="CIRCULAR IMPORTS"
value={<AnimatedNumber value={report.architecture.cycles_count} startOnView />}
tone={report.architecture.cycles_count > 0 ? 'text-warn' : 'text-success'}
/>
<Readout
index={1}
label="SCC CLUSTERS"
value={<AnimatedNumber value={report.architecture.strongly_connected_components} startOnView />}
/>
<Readout
index={2}
label="DESIGN SMELLS"
value={<AnimatedNumber value={report.architecture.smells_count} startOnView />}
/>
</dl>
<section className="min-w-0">
<h4 className="mono-label pb-3 hair-b">DEPENDENCY DESIGN VIOLATIONS</h4>
{report.architecture.smells.length > 0 ? (
<ul className="min-w-0">
{report.architecture.smells.map((smell, idx) => (
<li
key={idx}
className="spec-row flex items-start gap-3 py-3 hair-t last:border-b last:border-white/[0.055]"
>
<span className="mono-label shrink-0 pt-0.5" style={{ letterSpacing: '0.16em' }}>
{String(idx + 1).padStart(2, '0')}
</span>
<span className="text-[12px] text-text-muted leading-relaxed max-w-[74ch]">
{smell}
</span>
</li>
))}
</ul>
) : (
<p className="text-[12px] text-text-subtle py-4">No dependency smells detected.</p>
)}
</section>
<section className="min-w-0">
<h4 className="mono-label pb-3 hair-b">CIRCULAR IMPORT PATHS</h4>
{report.architecture.cycles.length > 0 ? (
<BoundedList total={report.architecture.cycles.length} preview={6} label="CYCLES">
{(limit) => (
<ul className="min-w-0">
{(limit === null
? report.architecture.cycles
: report.architecture.cycles.slice(0, limit)
).map((cycle, idx) => {
const entry = cycle[0];
const exit = cycle[cycle.length - 1] ?? entry;
return (
<li
key={idx}
className="topo-item spec-row py-4 hair-t last:border-b last:border-white/[0.055] min-w-0"
>
{/* The loop stated explicitly: source β target β back */}
<FilePath path={entry} tone="primary" size="sm" />
<div className="flex items-center gap-2.5 my-2">
<span className="topo-type font-mono text-[10px] uppercase tracking-[0.24em]">
imports
</span>
<span className="topo-edge h-px flex-1" aria-hidden="true" />
<span className="topo-type text-[10px] shrink-0" aria-hidden="true">β</span>
</div>
<FilePath path={exit} tone="secondary" size="sm" marker="target" />
{cycle.length > 2 && (
<p className="mono-detail mt-2" style={{ fontSize: 10 }}>
VIA {cycle.length - 2} INTERMEDIATE{cycle.length - 2 === 1 ? '' : 'S'}
</p>
)}
<div className="flex flex-wrap items-center gap-x-6 gap-y-2 mt-3">
<button
type="button"
onClick={() => openInGraph(owner, repo, entry)}
className="api-action link-arrow"
>
View in Graph
<ArrowRight className="h-3 w-3 arrow" aria-hidden="true" />
</button>
<button
type="button"
onClick={() =>
openInChat(
owner,
repo,
entry,
`There is a circular import involving \`${entry}\`. How should I break this cycle?`
)
}
className="api-action link-arrow"
>
Open in Chat
<ArrowRight className="h-3 w-3 arrow" aria-hidden="true" />
</button>
</div>
</li>
);
})}
</ul>
)}
</BoundedList>
) : (
<p className="text-[12px] text-text-subtle py-4">
No circular import loops detected.
</p>
)}
</section>
</div>
)}
{/* ββ API Surface ββββββββββββββββββββββββββββββββββββββββββββββββββ */}
{subTab === 'api' && (
<div className="space-y-9 min-w-0">
<dl className="grid grid-cols-2 md:grid-cols-3 border-t border-white/[0.055]">
<Readout
index={0}
label="EXPORTED SYMBOLS"
value={<AnimatedNumber value={api.total_exported_symbols} startOnView />}
/>
<Readout
index={1}
label="PUBLIC / PRIVATE RATIO"
value={<AnimatedNumber value={api.public_private_ratio} decimals={2} startOnView />}
tone={ratioOutOfRange ? 'text-warn' : 'text-success'}
/>
<Readout
index={2}
label="AVG DISTANCE"
value={
<AnimatedNumber value={api.average_distance_main_sequence} decimals={2} startOnView />
}
tone={distanceOutOfRange ? 'text-warn' : 'text-success'}
/>
</dl>
<section className="min-w-0">
<h4 className="mono-label pb-3 hair-b">API PACKAGING STABILITY</h4>
<p className="text-[12px] text-text-muted leading-relaxed mt-4 max-w-[74ch]">
A stable design aligns packaging along the main sequence. A public-to-private symbol
ratio below 0.5 suggests healthy encapsulation.
</p>
{/* Evidence table β emphasis only where a value is out of range */}
<div className="mt-5 min-w-0">
<div className="grid grid-cols-[1fr_auto_auto] gap-x-4 sm:gap-x-8 pb-2 hair-b">
<span className="mono-label">CATEGORY</span>
<span className="mono-label text-right">VALUE</span>
<span className="mono-label text-right">TARGET</span>
</div>
{[
{
k: 'Average Distance',
v: api.average_distance_main_sequence.toFixed(2),
t: 'β€ 0.3',
bad: distanceOutOfRange,
},
{
k: 'Public / Private Ratio',
v: api.public_private_ratio.toFixed(2),
t: '0.1 β 0.5',
bad: ratioOutOfRange,
},
].map((row) => (
<div
key={row.k}
className="grid grid-cols-[1fr_auto_auto] gap-x-4 sm:gap-x-8 py-3 hair-t last:border-b last:border-white/[0.055] items-baseline"
>
<span className="text-[12px] text-text-muted truncate">{row.k}</span>
<span
className={`font-mono text-[13px] tabular-nums text-right ${
row.bad ? 'text-warn' : 'text-text'
}`}
>
{row.v}
</span>
<span className="mono-detail text-right" style={{ fontSize: 10 }}>
{row.t}
</span>
</div>
))}
</div>
{onNavigate && (
<button
type="button"
onClick={() => onNavigate('api_surface')}
className="api-action link-arrow mt-5"
>
View API Surface
<ArrowRight className="h-3 w-3 arrow" aria-hidden="true" />
</button>
)}
</section>
</div>
)}
{/* ββ Hygiene ββββββββββββββββββββββββββββββββββββββββββββββββββββββ */}
{subTab === 'hygiene' && (
<div className="space-y-9 min-w-0">
<dl className="grid grid-cols-2 border-t border-white/[0.055]">
<Readout
index={0}
label="DEAD FUNCTIONS"
value={<AnimatedNumber value={report.hygiene.dead_functions_count} startOnView />}
tone={report.hygiene.dead_functions_count > 0 ? 'text-warn' : 'text-success'}
/>
<Readout
index={1}
label="DEAD CODE RATIO"
value={
<>
<AnimatedNumber value={report.hygiene.dead_code_ratio} decimals={1} startOnView />%
</>
}
/>
</dl>
<section className="min-w-0">
<h4 className="mono-label pb-3 hair-b">DEAD CODE REGISTRY</h4>
{report.hygiene.dead_functions.length > 0 ? (
<BoundedList
total={report.hygiene.dead_functions.length}
preview={8}
label="FINDINGS"
>
{(limit) => (
<ul className="min-w-0">
{(limit === null
? report.hygiene.dead_functions
: report.hygiene.dead_functions.slice(0, limit)
).map((func, idx) => (
<li
key={idx}
className="spec-row flex items-center justify-between gap-4 py-3.5 hair-t last:border-b last:border-white/[0.055] min-w-0"
>
<FilePath path={func} tone="secondary" size="sm" />
<span className="mono-label shrink-0" style={{ color: 'var(--warn)' }}>
UNUSED
</span>
</li>
))}
</ul>
)}
</BoundedList>
) : (
<p className="text-[12px] text-text-subtle py-4">
No unused functions detected in call graph sweep.
</p>
)}
</section>
</div>
)}
{/* ββ Onboarding βββββββββββββββββββββββββββββββββββββββββββββββββββ */}
{subTab === 'onboarding' && (
<div className="space-y-9 min-w-0">
<dl className="grid grid-cols-2 border-t border-white/[0.055]">
<Readout
index={0}
label="READING PATH COVERAGE"
value={
<>
<AnimatedNumber value={report.onboarding.reading_path_completeness} startOnView />%
</>
}
tone={report.onboarding.reading_path_completeness > 0 ? 'text-text' : 'text-warn'}
/>
<Readout
index={1}
label="PRIMARY ENTRY POINTS"
value={<AnimatedNumber value={report.onboarding.core_entry_points.length} startOnView />}
/>
</dl>
<section className="min-w-0">
<h4 className="mono-label pb-3 hair-b">MAIN ENTRY POINTS</h4>
{report.onboarding.core_entry_points.length > 0 ? (
<BoundedList
total={report.onboarding.core_entry_points.length}
preview={10}
label="ENTRY POINTS"
>
{(limit) => (
<ol className="min-w-0">
{(limit === null
? report.onboarding.core_entry_points
: report.onboarding.core_entry_points.slice(0, limit)
).map((entry, idx) => (
<li
key={`${entry}-${idx}`}
className="spec-row flex items-baseline gap-4 py-3 hair-t last:border-b last:border-white/[0.055] min-w-0"
>
<span className="mono-label shrink-0" style={{ letterSpacing: '0.16em' }}>
{String(idx + 1).padStart(2, '0')}
</span>
<FilePath path={entry} tone="secondary" size="sm" />
</li>
))}
</ol>
)}
</BoundedList>
) : (
<p className="text-[12px] text-text-subtle py-4">
No main code entry points detected.
</p>
)}
</section>
<section className="min-w-0">
<h4 className="mono-label pb-3 hair-b">TOPOLOGICAL READING ORDER</h4>
<p className="text-[12px] text-text-muted leading-relaxed mt-4 max-w-[74ch]">
Read these modules in sequence to move from base imports up to high-level
controllers.
</p>
{report.onboarding.recommended_reading_path.length > 0 ? (
<div className="mt-4">
<BoundedList
total={report.onboarding.recommended_reading_path.length}
preview={10}
label="STEPS"
>
{(limit) => (
<ol className="min-w-0">
{(limit === null
? report.onboarding.recommended_reading_path
: report.onboarding.recommended_reading_path.slice(0, limit)
).map((path, idx) => (
<li
key={`${path}-${idx}`}
className="spec-row flex items-baseline gap-4 py-3 hair-t last:border-b last:border-white/[0.055] min-w-0"
>
<span className="mono-label shrink-0" style={{ letterSpacing: '0.16em' }}>
{String(idx + 1).padStart(2, '0')}
</span>
<FilePath path={path} tone="secondary" size="sm" />
</li>
))}
</ol>
)}
</BoundedList>
</div>
) : (
<p className="text-[12px] text-text-subtle py-4">No reading path compiled.</p>
)}
</section>
</div>
)}
</div>
<SectionSeam label="EVIDENCE β PRIORITIES" />
{/* ββ Prioritized action issues ββββββββββββββββββββββββββββββββββββββ */}
<section aria-labelledby="priorities-heading" className="min-w-0">
<div className="flex flex-wrap items-baseline justify-between gap-4 pb-3 hair-b">
<h3 id="priorities-heading" className="mono-label mono-label-accent">
PRIORITIZED ACTION ISSUES
</h3>
<span className="mono-detail tabular-nums shrink-0" style={{ fontSize: 10 }}>
{attentionCount > 0
? `${String(attentionCount).padStart(2, '0')} NEED ATTENTION`
: `${String(parsedIssues.length).padStart(2, '0')} ITEMS`}
</span>
</div>
{parsedIssues.length > 0 ? (
<div className="min-w-0">
{parsedIssues.map((issue) => (
<IssueRow key={issue.id} issue={issue} owner={owner} repo={repo} />
))}
</div>
) : (
<p className="text-[12px] text-text-subtle py-4">No action items required.</p>
)}
</section>
{/* ββ Sticky export footer βββββββββββββββββββββββββββββββββββββββββββ */}
<div
className="sticky bottom-0 z-30 mt-12 -mx-4 sm:-mx-6 lg:-mx-8 px-4 sm:px-6 lg:px-8
border-t border-white/[0.055] bg-canvas/85 backdrop-blur-sm
flex flex-wrap items-center justify-between gap-x-6 gap-y-2 py-2.5"
>
<span className="flex flex-wrap items-center gap-x-3 gap-y-1 min-w-0">
<span className="mono-label">
GRADE{' '}
<span className={`font-bold ${gradeToneClass(report.scores.grade)}`}>
{report.scores.grade}
</span>
</span>
<span className="h-2.5 w-px bg-white/[0.09] hidden sm:block" aria-hidden="true" />
<span className="mono-detail truncate hidden sm:inline" style={{ fontSize: 10 }}>
{report.metadata.repo_name}
</span>
<span className="h-2.5 w-px bg-white/[0.09] hidden md:block" aria-hidden="true" />
<span className="mono-detail hidden md:inline" style={{ fontSize: 10 }}>
{relativeTime(report.metadata.generated_at)}
</span>
</span>
<div className="flex items-center gap-4 shrink-0">
<button
type="button"
onClick={() => handleExport('html')}
className="api-action"
aria-label="Export report as HTML"
>
<Download className="h-3.5 w-3.5" aria-hidden="true" />
<span className="hidden sm:inline">HTML</span>
</button>
<button
type="button"
onClick={() => handleExport('markdown')}
className="api-action"
aria-label="Export report as Markdown"
>
<FileText className="h-3.5 w-3.5" aria-hidden="true" />
<span className="hidden sm:inline">Markdown</span>
</button>
<button
type="button"
onClick={() => handleExport('pdf')}
className="action-chip"
aria-label="Print or save report as PDF"
>
<Printer className="h-3.5 w-3.5" aria-hidden="true" />
<span className="hidden sm:inline">Print / PDF</span>
</button>
</div>
</div>
</div>
);
};
export default ReportPanel;
|