git-contribution-analyzer 0.8.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. git_contribution_analyzer/__init__.py +3 -0
  2. git_contribution_analyzer/adapters/__init__.py +1 -0
  3. git_contribution_analyzer/adapters/git/__init__.py +1 -0
  4. git_contribution_analyzer/adapters/git/local_identity.py +51 -0
  5. git_contribution_analyzer/adapters/git/native_git.py +353 -0
  6. git_contribution_analyzer/adapters/git/pydriller_history.py +57 -0
  7. git_contribution_analyzer/adapters/git/repository_discovery.py +75 -0
  8. git_contribution_analyzer/adapters/gui/__init__.py +1 -0
  9. git_contribution_analyzer/adapters/gui/app.py +63 -0
  10. git_contribution_analyzer/adapters/gui/controller.py +1084 -0
  11. git_contribution_analyzer/adapters/gui/models/__init__.py +3 -0
  12. git_contribution_analyzer/adapters/gui/models/base_table.py +108 -0
  13. git_contribution_analyzer/adapters/gui/settings.py +53 -0
  14. git_contribution_analyzer/adapters/gui/task_runner.py +196 -0
  15. git_contribution_analyzer/adapters/llm/__init__.py +1 -0
  16. git_contribution_analyzer/adapters/llm/anthropic.py +52 -0
  17. git_contribution_analyzer/adapters/llm/base.py +142 -0
  18. git_contribution_analyzer/adapters/llm/cache.py +148 -0
  19. git_contribution_analyzer/adapters/llm/claude_cli.py +52 -0
  20. git_contribution_analyzer/adapters/llm/codex_cli.py +52 -0
  21. git_contribution_analyzer/adapters/llm/command_base.py +153 -0
  22. git_contribution_analyzer/adapters/llm/mock.py +82 -0
  23. git_contribution_analyzer/adapters/llm/ollama.py +53 -0
  24. git_contribution_analyzer/adapters/llm/openai_compatible.py +61 -0
  25. git_contribution_analyzer/adapters/llm/registry.py +117 -0
  26. git_contribution_analyzer/adapters/mcp/__init__.py +13 -0
  27. git_contribution_analyzer/adapters/mcp/installer.py +175 -0
  28. git_contribution_analyzer/adapters/mcp/prompts_resources.py +218 -0
  29. git_contribution_analyzer/adapters/mcp/protocol.py +361 -0
  30. git_contribution_analyzer/adapters/mcp/server.py +52 -0
  31. git_contribution_analyzer/adapters/mcp/tools.py +621 -0
  32. git_contribution_analyzer/adapters/outcomes/__init__.py +1 -0
  33. git_contribution_analyzer/adapters/outcomes/yaml_loader.py +55 -0
  34. git_contribution_analyzer/adapters/outcomes/yaml_store.py +104 -0
  35. git_contribution_analyzer/adapters/reporting/__init__.py +1 -0
  36. git_contribution_analyzer/adapters/reporting/brag_markdown.py +115 -0
  37. git_contribution_analyzer/adapters/reporting/html_report.py +1413 -0
  38. git_contribution_analyzer/adapters/reporting/markdown.py +217 -0
  39. git_contribution_analyzer/adapters/reporting/portfolio_markdown.py +167 -0
  40. git_contribution_analyzer/adapters/reporting/recap_markdown.py +212 -0
  41. git_contribution_analyzer/adapters/reporting/resume_markdown.py +37 -0
  42. git_contribution_analyzer/adapters/reporting/work_assessment_csv.py +117 -0
  43. git_contribution_analyzer/adapters/reporting/work_assessment_markdown.py +90 -0
  44. git_contribution_analyzer/adapters/reporting/work_assessment_series_markdown.py +31 -0
  45. git_contribution_analyzer/adapters/storage/__init__.py +1 -0
  46. git_contribution_analyzer/adapters/storage/sqlite/__init__.py +1 -0
  47. git_contribution_analyzer/adapters/storage/sqlite/analysis.py +708 -0
  48. git_contribution_analyzer/adapters/storage/sqlite/database.py +98 -0
  49. git_contribution_analyzer/adapters/storage/sqlite/git_index.py +482 -0
  50. git_contribution_analyzer/adapters/storage/sqlite/identity_merge.py +373 -0
  51. git_contribution_analyzer/adapters/storage/sqlite/llm_audit.py +109 -0
  52. git_contribution_analyzer/adapters/storage/sqlite/migrations/env.py +34 -0
  53. git_contribution_analyzer/adapters/storage/sqlite/migrations/script.py.mako +22 -0
  54. git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0001_initial.py +51 -0
  55. git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0002_git_index.py +146 -0
  56. git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0003_analysis.py +79 -0
  57. git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0004_llm_audit.py +69 -0
  58. git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0005_run_types.py +42 -0
  59. git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0006_identity_merges.py +83 -0
  60. git_contribution_analyzer/adapters/storage/sqlite/migrations/versions/0007_structural_baselines.py +173 -0
  61. git_contribution_analyzer/adapters/storage/sqlite/models.py +354 -0
  62. git_contribution_analyzer/adapters/storage/sqlite/structural_baseline.py +841 -0
  63. git_contribution_analyzer/adapters/workspace/__init__.py +1 -0
  64. git_contribution_analyzer/adapters/workspace/config.py +135 -0
  65. git_contribution_analyzer/adapters/workspace/git_exclude.py +32 -0
  66. git_contribution_analyzer/adapters/workspace/layout.py +40 -0
  67. git_contribution_analyzer/adapters/workspace/locks.py +27 -0
  68. git_contribution_analyzer/adapters/workspace/portfolio_workspace.py +380 -0
  69. git_contribution_analyzer/adapters/workspace/ranking_config.py +17 -0
  70. git_contribution_analyzer/application/__init__.py +1 -0
  71. git_contribution_analyzer/application/dto/__init__.py +19 -0
  72. git_contribution_analyzer/application/dto/gui.py +86 -0
  73. git_contribution_analyzer/application/dto/results.py +21 -0
  74. git_contribution_analyzer/application/facades/__init__.py +3 -0
  75. git_contribution_analyzer/application/facades/gui.py +568 -0
  76. git_contribution_analyzer/application/ports/__init__.py +22 -0
  77. git_contribution_analyzer/application/ports/cancellation.py +50 -0
  78. git_contribution_analyzer/application/ports/git_history.py +22 -0
  79. git_contribution_analyzer/application/ports/llm.py +44 -0
  80. git_contribution_analyzer/application/ports/portfolio_store.py +34 -0
  81. git_contribution_analyzer/application/ports/progress.py +43 -0
  82. git_contribution_analyzer/application/ports/structural_baseline.py +93 -0
  83. git_contribution_analyzer/application/services/__init__.py +1 -0
  84. git_contribution_analyzer/application/services/assessment_explanation.py +127 -0
  85. git_contribution_analyzer/application/services/default_person.py +61 -0
  86. git_contribution_analyzer/application/services/evidence_snapshot.py +64 -0
  87. git_contribution_analyzer/application/services/person_selection.py +88 -0
  88. git_contribution_analyzer/application/services/resume_generation.py +318 -0
  89. git_contribution_analyzer/application/services/semantic_enhancement.py +157 -0
  90. git_contribution_analyzer/application/services/time_boundaries.py +49 -0
  91. git_contribution_analyzer/application/use_cases/__init__.py +1 -0
  92. git_contribution_analyzer/application/use_cases/analyze_contributions.py +276 -0
  93. git_contribution_analyzer/application/use_cases/analyze_project.py +295 -0
  94. git_contribution_analyzer/application/use_cases/assess_portfolio.py +327 -0
  95. git_contribution_analyzer/application/use_cases/assess_work.py +602 -0
  96. git_contribution_analyzer/application/use_cases/assess_work_series.py +212 -0
  97. git_contribution_analyzer/application/use_cases/compare_assessment_runs.py +121 -0
  98. git_contribution_analyzer/application/use_cases/export_report.py +49 -0
  99. git_contribution_analyzer/application/use_cases/generate_brag.py +308 -0
  100. git_contribution_analyzer/application/use_cases/generate_portfolio_recap.py +244 -0
  101. git_contribution_analyzer/application/use_cases/generate_portfolio_resume.py +152 -0
  102. git_contribution_analyzer/application/use_cases/generate_recap.py +316 -0
  103. git_contribution_analyzer/application/use_cases/generate_report.py +32 -0
  104. git_contribution_analyzer/application/use_cases/generate_resume.py +209 -0
  105. git_contribution_analyzer/application/use_cases/get_portfolio_status.py +83 -0
  106. git_contribution_analyzer/application/use_cases/get_run.py +16 -0
  107. git_contribution_analyzer/application/use_cases/get_status.py +69 -0
  108. git_contribution_analyzer/application/use_cases/index_repository.py +267 -0
  109. git_contribution_analyzer/application/use_cases/init_portfolio.py +89 -0
  110. git_contribution_analyzer/application/use_cases/init_project.py +71 -0
  111. git_contribution_analyzer/application/use_cases/list_identities.py +16 -0
  112. git_contribution_analyzer/application/use_cases/list_providers.py +29 -0
  113. git_contribution_analyzer/application/use_cases/list_runs.py +17 -0
  114. git_contribution_analyzer/application/use_cases/manage_identity_merges.py +48 -0
  115. git_contribution_analyzer/application/use_cases/manage_outcomes.py +189 -0
  116. git_contribution_analyzer/application/use_cases/manage_structural_baselines.py +262 -0
  117. git_contribution_analyzer/application/use_cases/map_identity.py +28 -0
  118. git_contribution_analyzer/application/use_cases/recover_runs.py +22 -0
  119. git_contribution_analyzer/application/use_cases/run_doctor.py +81 -0
  120. git_contribution_analyzer/application/use_cases/sync_portfolio.py +232 -0
  121. git_contribution_analyzer/application/use_cases/test_provider.py +22 -0
  122. git_contribution_analyzer/application/use_cases/uninit_project.py +23 -0
  123. git_contribution_analyzer/application/use_cases/verify_portfolio.py +165 -0
  124. git_contribution_analyzer/cli/__init__.py +1 -0
  125. git_contribution_analyzer/cli/app.py +1430 -0
  126. git_contribution_analyzer/cli/exit_codes.py +13 -0
  127. git_contribution_analyzer/cli/output.py +26 -0
  128. git_contribution_analyzer/cli/portfolio_commands.py +629 -0
  129. git_contribution_analyzer/domain/__init__.py +1 -0
  130. git_contribution_analyzer/domain/errors.py +55 -0
  131. git_contribution_analyzer/domain/models/__init__.py +3 -0
  132. git_contribution_analyzer/domain/models/analysis.py +29 -0
  133. git_contribution_analyzer/domain/models/assessment.py +12 -0
  134. git_contribution_analyzer/domain/models/brag.py +148 -0
  135. git_contribution_analyzer/domain/models/contribution.py +55 -0
  136. git_contribution_analyzer/domain/models/git_history.py +69 -0
  137. git_contribution_analyzer/domain/models/person_selection.py +46 -0
  138. git_contribution_analyzer/domain/models/portfolio.py +498 -0
  139. git_contribution_analyzer/domain/models/ranking.py +48 -0
  140. git_contribution_analyzer/domain/models/recap.py +235 -0
  141. git_contribution_analyzer/domain/models/repository.py +10 -0
  142. git_contribution_analyzer/domain/models/resume.py +59 -0
  143. git_contribution_analyzer/domain/models/run.py +10 -0
  144. git_contribution_analyzer/domain/models/semantic.py +34 -0
  145. git_contribution_analyzer/domain/models/snapshot.py +208 -0
  146. git_contribution_analyzer/domain/models/structural_baseline.py +120 -0
  147. git_contribution_analyzer/domain/models/work_assessment.py +81 -0
  148. git_contribution_analyzer/domain/services/assessment_periods.py +182 -0
  149. git_contribution_analyzer/domain/services/brag_rules.py +250 -0
  150. git_contribution_analyzer/domain/services/capability_rules.py +91 -0
  151. git_contribution_analyzer/domain/services/contribution_clustering.py +98 -0
  152. git_contribution_analyzer/domain/services/contribution_rules.py +79 -0
  153. git_contribution_analyzer/domain/services/difficulty_rules.py +191 -0
  154. git_contribution_analyzer/domain/services/dimensional_summary.py +117 -0
  155. git_contribution_analyzer/domain/services/portfolio_aggregation.py +250 -0
  156. git_contribution_analyzer/domain/services/portfolio_resume_rules.py +265 -0
  157. git_contribution_analyzer/domain/services/portfolio_verifier.py +238 -0
  158. git_contribution_analyzer/domain/services/ranking_rules.py +226 -0
  159. git_contribution_analyzer/domain/services/recap_rules.py +268 -0
  160. git_contribution_analyzer/domain/services/resume_claim_rules.py +70 -0
  161. git_contribution_analyzer/domain/services/structural_baseline.py +317 -0
  162. git_contribution_analyzer/domain/services/structural_signals.py +151 -0
  163. git_contribution_analyzer/domain/services/workload_rules.py +185 -0
  164. git_contribution_analyzer/gui/__init__.py +1 -0
  165. git_contribution_analyzer/gui/qml/Main.qml +1141 -0
  166. git_contribution_analyzer/gui/qml/__init__.py +1 -0
  167. git_contribution_analyzer/prompts/__init__.py +1 -0
  168. git_contribution_analyzer/prompts/assessment/__init__.py +1 -0
  169. git_contribution_analyzer/prompts/assessment/v1/__init__.py +1 -0
  170. git_contribution_analyzer/prompts/assessment/v1/explanation.txt +4 -0
  171. git_contribution_analyzer/prompts/resume/__init__.py +1 -0
  172. git_contribution_analyzer/prompts/resume/v1/__init__.py +1 -0
  173. git_contribution_analyzer/prompts/resume/v1/style-concise.txt +1 -0
  174. git_contribution_analyzer/prompts/resume/v1/style-star.txt +1 -0
  175. git_contribution_analyzer/prompts/resume/v1/style-xyz.txt +1 -0
  176. git_contribution_analyzer/prompts/resume/v1/system.txt +3 -0
  177. git_contribution_analyzer/prompts/v1/__init__.py +1 -0
  178. git_contribution_analyzer/prompts/v1/capability_explanation.txt +2 -0
  179. git_contribution_analyzer/prompts/v1/contribution_summary.txt +2 -0
  180. git_contribution_analyzer/prompts/v1/overall_summary.txt +2 -0
  181. git_contribution_analyzer/prompts/v1/resume_bullet.txt +2 -0
  182. git_contribution_analyzer-0.8.0.dist-info/METADATA +667 -0
  183. git_contribution_analyzer-0.8.0.dist-info/RECORD +187 -0
  184. git_contribution_analyzer-0.8.0.dist-info/WHEEL +4 -0
  185. git_contribution_analyzer-0.8.0.dist-info/entry_points.txt +3 -0
  186. git_contribution_analyzer-0.8.0.dist-info/licenses/LICENSE +201 -0
  187. git_contribution_analyzer-0.8.0.dist-info/licenses/NOTICE +6 -0
@@ -0,0 +1,1413 @@
1
+ from __future__ import annotations
2
+
3
+ import html
4
+ import json
5
+ from dataclasses import dataclass
6
+ from pathlib import Path
7
+ from typing import Any
8
+
9
+
10
+ @dataclass(frozen=True, slots=True)
11
+ class _KpiCard:
12
+ label: str
13
+ value: str
14
+ subtext: str = ""
15
+ tone: str = "neutral"
16
+
17
+
18
+ @dataclass(frozen=True, slots=True)
19
+ class _BarItem:
20
+ label: str
21
+ value: int
22
+ secondary: int = 0
23
+ detail: str = ""
24
+
25
+
26
+ _CSS = """
27
+ :root {
28
+ --bg: #f8fafc;
29
+ --surface: #ffffff;
30
+ --surface-alt: #f1f5f9;
31
+ --border: #e2e8f0;
32
+ --text: #0f172a;
33
+ --muted: #475569;
34
+ --accent: #2563eb;
35
+ --accent-soft: #dbeafe;
36
+ --good: #15803d;
37
+ --good-soft: #dcfce7;
38
+ --warn: #b45309;
39
+ --warn-soft: #fef3c7;
40
+ --danger: #b91c1c;
41
+ --danger-soft: #fee2e2;
42
+ --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
43
+ }
44
+ [data-theme="dark"] {
45
+ --bg: #0b1120;
46
+ --surface: #111827;
47
+ --surface-alt: #1e293b;
48
+ --border: #334155;
49
+ --text: #f1f5f9;
50
+ --muted: #94a3b8;
51
+ --accent: #60a5fa;
52
+ --accent-soft: #1e3a5f;
53
+ --good: #4ade80;
54
+ --good-soft: #14532d;
55
+ --warn: #fbbf24;
56
+ --warn-soft: #451a03;
57
+ --danger: #f87171;
58
+ --danger-soft: #450a0a;
59
+ --shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
60
+ }
61
+ * { box-sizing: border-box; }
62
+ body {
63
+ margin: 0;
64
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC",
65
+ "Microsoft YaHei", sans-serif;
66
+ background: var(--bg);
67
+ color: var(--text);
68
+ line-height: 1.55;
69
+ }
70
+ .container {
71
+ max-width: 1120px;
72
+ margin: 0 auto;
73
+ padding: 24px 20px 64px;
74
+ }
75
+ .header {
76
+ display: flex;
77
+ flex-wrap: wrap;
78
+ justify-content: space-between;
79
+ align-items: flex-start;
80
+ gap: 16px;
81
+ padding-bottom: 18px;
82
+ border-bottom: 1px solid var(--border);
83
+ margin-bottom: 24px;
84
+ }
85
+ .title { margin: 0 0 6px; font-size: 1.65rem; font-weight: 700; }
86
+ .subtitle { margin: 0; color: var(--muted); font-size: 0.92rem; }
87
+ .meta-pills { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
88
+ .pill {
89
+ display: inline-block;
90
+ padding: 2px 10px;
91
+ border-radius: 999px;
92
+ font-size: 0.8rem;
93
+ background: var(--surface-alt);
94
+ border: 1px solid var(--border);
95
+ color: var(--muted);
96
+ }
97
+ .toolbar {
98
+ display: flex;
99
+ flex-wrap: wrap;
100
+ gap: 10px;
101
+ align-items: center;
102
+ }
103
+ .btn {
104
+ appearance: none;
105
+ border: 1px solid var(--border);
106
+ background: var(--surface);
107
+ color: var(--text);
108
+ padding: 6px 12px;
109
+ border-radius: 8px;
110
+ font-size: 0.85rem;
111
+ cursor: pointer;
112
+ }
113
+ .btn:hover { border-color: var(--accent); color: var(--accent); }
114
+ .kpi-grid {
115
+ display: grid;
116
+ grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
117
+ gap: 14px;
118
+ margin-bottom: 24px;
119
+ }
120
+ .kpi-card {
121
+ background: var(--surface);
122
+ border: 1px solid var(--border);
123
+ border-radius: 12px;
124
+ padding: 14px 16px;
125
+ box-shadow: var(--shadow);
126
+ }
127
+ .kpi-label { font-size: 0.8rem; color: var(--muted); margin-bottom: 6px; }
128
+ .kpi-value { font-size: 1.6rem; font-weight: 700; line-height: 1.2; }
129
+ .kpi-sub { font-size: 0.8rem; color: var(--muted); margin-top: 4px; }
130
+ .tone-good .kpi-value { color: var(--good); }
131
+ .tone-warn .kpi-value { color: var(--warn); }
132
+ .tone-danger .kpi-value { color: var(--danger); }
133
+ .section {
134
+ background: var(--surface);
135
+ border: 1px solid var(--border);
136
+ border-radius: 12px;
137
+ padding: 18px 20px;
138
+ margin-bottom: 20px;
139
+ box-shadow: var(--shadow);
140
+ }
141
+ .section h2 {
142
+ margin: 0 0 14px;
143
+ font-size: 1.12rem;
144
+ display: flex;
145
+ align-items: center;
146
+ justify-content: space-between;
147
+ gap: 10px;
148
+ }
149
+ .filter-bar {
150
+ display: flex;
151
+ flex-wrap: wrap;
152
+ gap: 10px;
153
+ margin-bottom: 16px;
154
+ }
155
+ .search-input, .group-select {
156
+ padding: 8px 12px;
157
+ border-radius: 8px;
158
+ border: 1px solid var(--border);
159
+ background: var(--surface);
160
+ color: var(--text);
161
+ font-size: 0.9rem;
162
+ }
163
+ .search-input { flex: 1; min-width: 220px; }
164
+ .table-wrap { overflow-x: auto; }
165
+ table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
166
+ th, td {
167
+ text-align: left;
168
+ padding: 9px 10px;
169
+ border-bottom: 1px solid var(--border);
170
+ }
171
+ th { color: var(--muted); font-weight: 600; background: var(--surface-alt); }
172
+ th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
173
+ .item-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
174
+ .item-card {
175
+ border: 1px solid var(--border);
176
+ background: var(--surface-alt);
177
+ border-radius: 10px;
178
+ padding: 12px 14px;
179
+ }
180
+ .item-head {
181
+ display: flex;
182
+ flex-wrap: wrap;
183
+ justify-content: space-between;
184
+ gap: 8px;
185
+ margin-bottom: 6px;
186
+ }
187
+ .item-title { font-weight: 600; }
188
+ .tag {
189
+ display: inline-block;
190
+ font-size: 0.75rem;
191
+ padding: 2px 8px;
192
+ border-radius: 6px;
193
+ background: var(--surface);
194
+ border: 1px solid var(--border);
195
+ color: var(--muted);
196
+ }
197
+ .tag-high { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
198
+ .tag-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
199
+ .tag-good { background: var(--good-soft); color: var(--good); border-color: transparent; }
200
+ .ev-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
201
+ .ev-badge {
202
+ appearance: none;
203
+ border: 1px solid var(--accent);
204
+ background: var(--accent-soft);
205
+ color: var(--accent);
206
+ border-radius: 6px;
207
+ padding: 2px 8px;
208
+ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
209
+ font-size: 0.78rem;
210
+ cursor: pointer;
211
+ }
212
+ .ev-badge:hover { opacity: 0.85; }
213
+ .notice {
214
+ padding: 10px 14px;
215
+ border-radius: 8px;
216
+ background: var(--surface-alt);
217
+ border-left: 3px solid var(--accent);
218
+ font-size: 0.88rem;
219
+ color: var(--muted);
220
+ }
221
+ .chart-svg { width: 100%; height: auto; display: block; }
222
+ .drawer {
223
+ position: fixed;
224
+ right: 20px;
225
+ bottom: 20px;
226
+ width: min(460px, calc(100vw - 40px));
227
+ max-height: 60vh;
228
+ overflow: auto;
229
+ background: var(--surface);
230
+ border: 1px solid var(--accent);
231
+ border-radius: 12px;
232
+ padding: 16px;
233
+ box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
234
+ z-index: 100;
235
+ }
236
+ .drawer[hidden] { display: none; }
237
+ .drawer-head {
238
+ display: flex;
239
+ justify-content: space-between;
240
+ align-items: center;
241
+ gap: 8px;
242
+ margin-bottom: 10px;
243
+ }
244
+ .drawer-code {
245
+ margin: 0;
246
+ padding: 10px;
247
+ border-radius: 8px;
248
+ background: var(--surface-alt);
249
+ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
250
+ font-size: 0.8rem;
251
+ white-space: pre-wrap;
252
+ word-break: break-word;
253
+ }
254
+ .hidden-row { display: none !important; }
255
+ .footer-limits { font-size: 0.85rem; color: var(--muted); padding-left: 18px; margin: 0; }
256
+ @media print {
257
+ body { background: #ffffff; color: #000000; }
258
+ .toolbar, .filter-bar, .drawer { display: none !important; }
259
+ .section, .kpi-card { box-shadow: none; break-inside: avoid; }
260
+ tr { break-inside: avoid; }
261
+ }
262
+ """
263
+
264
+ _JS = """
265
+ (function () {
266
+ var root = document.documentElement;
267
+ if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) {
268
+ root.setAttribute("data-theme", "dark");
269
+ }
270
+ var themeBtn = document.getElementById("gca-theme-toggle");
271
+ if (themeBtn) {
272
+ themeBtn.addEventListener("click", function () {
273
+ var cur = root.getAttribute("data-theme") === "dark" ? "light" : "dark";
274
+ root.setAttribute("data-theme", cur);
275
+ });
276
+ }
277
+ var printBtn = document.getElementById("gca-print-btn");
278
+ if (printBtn) {
279
+ printBtn.addEventListener("click", function () { window.print(); });
280
+ }
281
+
282
+ var searchInput = document.getElementById("gca-search");
283
+ var groupSelect = document.getElementById("gca-group-filter");
284
+ function applyFilters() {
285
+ var q = searchInput ? searchInput.value.trim().toLowerCase() : "";
286
+ var g = groupSelect ? groupSelect.value : "";
287
+ var nodes = document.querySelectorAll("[data-filterable]");
288
+ for (var i = 0; i < nodes.length; i++) {
289
+ var el = nodes[i];
290
+ var text = (el.getAttribute("data-search") || el.textContent || "").toLowerCase();
291
+ var grp = el.getAttribute("data-group") || "";
292
+ var matchQ = !q || text.indexOf(q) !== -1;
293
+ var matchG = !g || grp === g;
294
+ if (matchQ && matchG) {
295
+ el.classList.remove("hidden-row");
296
+ } else {
297
+ el.classList.add("hidden-row");
298
+ }
299
+ }
300
+ }
301
+ if (searchInput) searchInput.addEventListener("input", applyFilters);
302
+ if (groupSelect) groupSelect.addEventListener("change", applyFilters);
303
+
304
+ var dataEl = document.getElementById("gca-evidence-data");
305
+ var evidenceIndex = {};
306
+ if (dataEl && dataEl.textContent) {
307
+ try {
308
+ evidenceIndex = JSON.parse(dataEl.textContent);
309
+ } catch (_err) {
310
+ evidenceIndex = {};
311
+ }
312
+ }
313
+ var drawer = document.getElementById("gca-evidence-drawer");
314
+ var drawerTitle = document.getElementById("gca-drawer-title");
315
+ var drawerBody = document.getElementById("gca-drawer-body");
316
+ var drawerClose = document.getElementById("gca-drawer-close");
317
+ if (drawerClose && drawer) {
318
+ drawerClose.addEventListener("click", function () {
319
+ drawer.setAttribute("hidden", "");
320
+ });
321
+ }
322
+ document.addEventListener("click", function (ev) {
323
+ var target = ev.target;
324
+ if (!target || !target.getAttribute) return;
325
+ var evId = target.getAttribute("data-ev-id");
326
+ if (!evId || !drawer || !drawerTitle || !drawerBody) return;
327
+ drawerTitle.textContent = evId;
328
+ var detail = evidenceIndex[evId];
329
+ if (detail) {
330
+ drawerBody.textContent = JSON.stringify(detail, null, 2);
331
+ } else {
332
+ drawerBody.textContent = "Evidence ID: " + evId;
333
+ }
334
+ drawer.removeAttribute("hidden");
335
+ });
336
+ })();
337
+ """
338
+
339
+
340
+ def _esc(value: Any) -> str:
341
+ return html.escape(str(value), quote=True)
342
+
343
+
344
+ def _safe_json_for_script(payload: Any) -> str:
345
+ raw = json.dumps(payload, ensure_ascii=False, sort_keys=True)
346
+ return (
347
+ raw.replace("&", "\\u0026")
348
+ .replace("<", "\\u003c")
349
+ .replace(">", "\\u003e")
350
+ .replace("\u2028", "\\u2028")
351
+ .replace("\u2029", "\\u2029")
352
+ )
353
+
354
+
355
+ def _safe_repo_name(raw: Any) -> str:
356
+ text = str(raw or "repository").strip()
357
+ if not text:
358
+ return "repository"
359
+ return Path(text).name or text
360
+
361
+
362
+ def _fmt_delta(value: int) -> str:
363
+ return f"+{value}" if value > 0 else str(value)
364
+
365
+
366
+ def _render_kpi_grid(cards: list[_KpiCard]) -> str:
367
+ parts = ['<section class="kpi-grid">']
368
+ for card in cards:
369
+ tone_cls = f" tone-{_esc(card.tone)}" if card.tone != "neutral" else ""
370
+ sub_html = f'<div class="kpi-sub">{_esc(card.subtext)}</div>' if card.subtext else ""
371
+ parts.append(
372
+ f'<div class="kpi-card{tone_cls}">'
373
+ f'<div class="kpi-label">{_esc(card.label)}</div>'
374
+ f'<div class="kpi-value">{_esc(card.value)}</div>'
375
+ f"{sub_html}</div>"
376
+ )
377
+ parts.append("</section>")
378
+ return "\n".join(parts)
379
+
380
+
381
+ def _render_svg_bar_chart(
382
+ title: str,
383
+ bars: list[_BarItem],
384
+ *,
385
+ primary_label: str = "Primary",
386
+ secondary_label: str | None = None,
387
+ ) -> str:
388
+ if not bars:
389
+ return ""
390
+ max_val = max(max(item.value, item.secondary) for item in bars)
391
+ max_val = max(max_val, 1)
392
+ row_h = 34 if secondary_label is None else 42
393
+ top_pad = 14
394
+ svg_h = top_pad + len(bars) * row_h + 10
395
+ label_w = 180
396
+ bar_max_w = 420
397
+ svg_w = 720
398
+
399
+ svg_lines = [
400
+ f'<div class="section"><h2>{_esc(title)}</h2>',
401
+ f'<svg class="chart-svg" viewBox="0 0 {svg_w} {svg_h}" role="img" '
402
+ f'aria-label="{_esc(title)}">',
403
+ ]
404
+ for idx, item in enumerate(bars):
405
+ y = top_pad + idx * row_h
406
+ w1 = max(2, int((item.value / max_val) * bar_max_w)) if item.value > 0 else 0
407
+ svg_lines.append(
408
+ f'<text x="4" y="{y + 15}" fill="currentColor" font-size="12">'
409
+ f"{_esc(item.label[:24])}</text>"
410
+ )
411
+ svg_lines.append(
412
+ f'<rect x="{label_w}" y="{y + 3}" width="{w1}" height="14" rx="4" '
413
+ f'fill="var(--accent)"></rect>'
414
+ )
415
+ val_text = item.detail or str(item.value)
416
+ svg_lines.append(
417
+ f'<text x="{label_w + w1 + 8}" y="{y + 15}" fill="var(--muted)" font-size="11">'
418
+ f"{_esc(val_text)}</text>"
419
+ )
420
+ if secondary_label is not None:
421
+ w2 = max(2, int((item.secondary / max_val) * bar_max_w)) if item.secondary > 0 else 0
422
+ svg_lines.append(
423
+ f'<rect x="{label_w}" y="{y + 20}" width="{w2}" height="10" rx="3" '
424
+ f'fill="var(--good)" opacity="0.8"></rect>'
425
+ )
426
+ svg_lines.append(
427
+ f'<text x="{label_w + w2 + 8}" y="{y + 29}" fill="var(--muted)" font-size="10">'
428
+ f"{_esc(secondary_label)}: {item.secondary}</text>"
429
+ )
430
+ svg_lines.append("</svg>")
431
+ if secondary_label is not None:
432
+ svg_lines.append(
433
+ f'<div class="subtitle" style="margin-top:6px;">'
434
+ f'{_esc(primary_label)} (blue) / {_esc(secondary_label)} (green)</div>'
435
+ )
436
+ svg_lines.append("</div>")
437
+ return "\n".join(svg_lines)
438
+
439
+
440
+ def _render_ev_badges(evidence_ids: list[str] | tuple[str, ...]) -> str:
441
+ if not evidence_ids:
442
+ return ""
443
+ buttons = [
444
+ f'<button type="button" class="ev-badge" data-ev-id="{_esc(ev)}">{_esc(ev)}</button>'
445
+ for ev in evidence_ids
446
+ ]
447
+ return f'<div class="ev-list">{"".join(buttons)}</div>'
448
+
449
+
450
+ def _render_filter_bar(groups: list[str], *, is_zh: bool) -> str:
451
+ placeholder = "搜索标题、仓库、分组或证据编号..." if is_zh else "Search items, repos, EV IDs..."
452
+ all_label = "全部分组" if is_zh else "All groups"
453
+ parts = [
454
+ '<div class="filter-bar">',
455
+ f'<input id="gca-search" class="search-input" type="search" '
456
+ f'placeholder="{_esc(placeholder)}" aria-label="{_esc(placeholder)}">',
457
+ ]
458
+ if groups:
459
+ opts = [f'<option value="">{_esc(all_label)}</option>']
460
+ opts.extend(f'<option value="{_esc(g)}">{_esc(g)}</option>' for g in sorted(set(groups)))
461
+ parts.append(f'<select id="gca-group-filter" class="group-select">{"".join(opts)}</select>')
462
+ parts.append("</div>")
463
+ return "\n".join(parts)
464
+
465
+
466
+ def _render_limitations(
467
+ limitations: list[str] | tuple[str, ...],
468
+ warnings: list[str] | tuple[str, ...],
469
+ *,
470
+ is_zh: bool,
471
+ ) -> str:
472
+ chunks: list[str] = []
473
+ if warnings:
474
+ w_title = "警告" if is_zh else "Warnings"
475
+ items = "".join(f"<li>{_esc(w)}</li>" for w in warnings)
476
+ chunks.append(
477
+ f'<section class="section"><h2>{w_title}</h2>'
478
+ f'<ul class="footer-limits">{items}</ul></section>'
479
+ )
480
+ if limitations:
481
+ l_title = "证据边界与限制" if is_zh else "Evidence Boundaries & Limitations"
482
+ items = "".join(f"<li>{_esc(lim)}</li>" for lim in limitations)
483
+ chunks.append(
484
+ f'<section class="section"><h2>{l_title}</h2>'
485
+ f'<ul class="footer-limits">{items}</ul></section>'
486
+ )
487
+ return "\n".join(chunks)
488
+
489
+
490
+ def _build_portfolio_summary_body(
491
+ report: dict[str, Any],
492
+ *,
493
+ is_zh: bool,
494
+ evidence_index: dict[str, Any],
495
+ ) -> tuple[str, str, list[str], str]:
496
+ identity = report["identity"]
497
+ scope = report["scope"]
498
+ totals = report["totals"]
499
+ diff = totals["difficulty"]
500
+ structural = report["structuralObservation"]
501
+
502
+ title = (
503
+ f"跨仓贡献汇总 - {report['portfolioName']}"
504
+ if is_zh
505
+ else f"Portfolio Summary - {report['portfolioName']}"
506
+ )
507
+ subtitle = (
508
+ f"{identity['canonicalName']} | {scope.get('firstAuthoredAt') or 'N/A'} .. "
509
+ f"{scope.get('lastAuthoredAt') or 'N/A'}"
510
+ )
511
+ pills = [
512
+ f"GCA {report.get('gcaVersion', '')}",
513
+ str(report.get("mode", "deterministic-no-llm")),
514
+ f"Repos {scope['matchedRepositories']}/{scope['discoveredRepositories']}",
515
+ ]
516
+
517
+ cards = [
518
+ _KpiCard(
519
+ "总提交数" if is_zh else "Total Commits",
520
+ str(totals["commits"]),
521
+ f"Merge: {totals['mergeCommits']}",
522
+ ),
523
+ _KpiCard(
524
+ "已交付提交" if is_zh else "Delivered",
525
+ str(totals["deliveredCommits"]),
526
+ f"LANDED {totals['landedCommits']} / RELEASED {totals['releasedCommits']}",
527
+ tone="good",
528
+ ),
529
+ _KpiCard(
530
+ "未合并提交" if is_zh else "Authored-Only",
531
+ str(totals["authoredOnlyCommits"]),
532
+ "Unmerged branches" if not is_zh else "未合入默认分支",
533
+ tone="warn" if totals["authoredOnlyCommits"] > 0 else "neutral",
534
+ ),
535
+ _KpiCard(
536
+ "已完成工作项" if is_zh else "Completed Items",
537
+ str(totals["completedItems"]),
538
+ f"HIGH_RISK {diff['HIGH_RISK']} / COMPLEX {diff['COMPLEX']}",
539
+ tone="good",
540
+ ),
541
+ _KpiCard(
542
+ "待跟进工作项" if is_zh else "Pending Items",
543
+ str(totals["pendingItems"]),
544
+ f"Rework {totals['reworkItems']} / Integration {totals['integrationItems']}",
545
+ tone="warn" if totals["pendingItems"] > 0 else "neutral",
546
+ ),
547
+ ]
548
+
549
+ group_bars = [
550
+ _BarItem(
551
+ label=str(g["name"]),
552
+ value=int(g["commits"]),
553
+ secondary=int(g["deliveredCommits"]),
554
+ detail=f"{g['commits']} commits ({g['completedItems']} completed)",
555
+ )
556
+ for g in report.get("groups", [])
557
+ ]
558
+ diff_bars = [
559
+ _BarItem("HIGH_RISK", int(diff["HIGH_RISK"])),
560
+ _BarItem("COMPLEX", int(diff["COMPLEX"])),
561
+ _BarItem("STANDARD", int(diff["STANDARD"])),
562
+ _BarItem("ROUTINE", int(diff["ROUTINE"])),
563
+ ]
564
+
565
+ groups = [str(r["group"]) for r in report.get("repositories", [])]
566
+ repo_rows: list[str] = []
567
+ for repo in report.get("repositories", []):
568
+ rk = str(repo["repoKey"])
569
+ grp = str(repo["group"])
570
+ evidence_index[rk] = {
571
+ "repoKey": rk,
572
+ "group": grp,
573
+ "branch": repo.get("branch"),
574
+ "commits": repo.get("commits"),
575
+ "delivered": repo.get("delivered"),
576
+ "authoredOnly": repo.get("authoredOnly"),
577
+ "completedItems": repo.get("completedItems"),
578
+ "pendingItems": repo.get("pendingItems"),
579
+ }
580
+ repo_rows.append(
581
+ f'<tr data-filterable="1" data-group="{_esc(grp)}" '
582
+ f'data-search="{_esc(rk)} {_esc(grp)} {_esc(repo.get("branch", ""))}">'
583
+ f'<td><strong>{_esc(rk)}</strong></td>'
584
+ f'<td><span class="tag">{_esc(grp)}</span></td>'
585
+ f"<td>{_esc(repo.get('branch', ''))}</td>"
586
+ f'<td class="num">{repo["commits"]}</td>'
587
+ f'<td class="num">{repo["delivered"]}</td>'
588
+ f'<td class="num">{repo["authoredOnly"]}</td>'
589
+ f'<td class="num">{repo["completedItems"]}</td>'
590
+ f'<td class="num">{repo["pendingItems"]}</td>'
591
+ "</tr>"
592
+ )
593
+
594
+ obs_text = (
595
+ f"结构信号观察 (仅观察, 不影响难度/排名/简历): "
596
+ f"热点仓库 {structural['hotspotSignalRepositories']}, "
597
+ f"耦合仓库 {structural['couplingSignalRepositories']}, "
598
+ f"历史基线 {structural['historicalBaselineBuilds']}."
599
+ if is_zh
600
+ else (
601
+ f"Structural observation (observation-only, non-scoring): "
602
+ f"{structural['hotspotSignalRepositories']} hotspot repos, "
603
+ f"{structural['couplingSignalRepositories']} coupling repos, "
604
+ f"{structural['historicalBaselineBuilds']} historical baselines."
605
+ )
606
+ )
607
+
608
+ body = "\n".join(
609
+ [
610
+ _render_kpi_grid(cards),
611
+ _render_svg_bar_chart(
612
+ "分组交付分布" if is_zh else "Commits by Group",
613
+ group_bars,
614
+ primary_label="Total Commits" if not is_zh else "总提交",
615
+ secondary_label="Delivered" if not is_zh else "已交付",
616
+ ),
617
+ _render_svg_bar_chart(
618
+ "难度分布" if is_zh else "Difficulty Distribution",
619
+ diff_bars,
620
+ ),
621
+ f'<section class="section"><div class="notice">{_esc(obs_text)}</div></section>',
622
+ '<section class="section">'
623
+ f'<h2>{"仓库明细" if is_zh else "Repository Breakdown"}</h2>'
624
+ f"{_render_filter_bar(groups, is_zh=is_zh)}"
625
+ '<div class="table-wrap"><table><thead><tr>'
626
+ f'<th>{"仓库" if is_zh else "Repo Key"}</th>'
627
+ f'<th>{"分组" if is_zh else "Group"}</th>'
628
+ f'<th>{"分支" if is_zh else "Branch"}</th>'
629
+ f'<th class="num">{"提交" if is_zh else "Commits"}</th>'
630
+ f'<th class="num">{"已交付" if is_zh else "Delivered"}</th>'
631
+ f'<th class="num">{"未合并" if is_zh else "Authored-Only"}</th>'
632
+ f'<th class="num">{"已完成" if is_zh else "Completed"}</th>'
633
+ f'<th class="num">{"待跟进" if is_zh else "Pending"}</th>'
634
+ "</tr></thead>"
635
+ f'<tbody>{"".join(repo_rows)}</tbody></table></div></section>',
636
+ _render_limitations(
637
+ report.get("limitations", ()),
638
+ report.get("warnings", ()),
639
+ is_zh=is_zh,
640
+ ),
641
+ ]
642
+ )
643
+ return title, subtitle, pills, body
644
+
645
+
646
+ def _build_recap_body(
647
+ report: dict[str, Any],
648
+ *,
649
+ is_zh: bool,
650
+ evidence_index: dict[str, Any],
651
+ ) -> tuple[str, str, list[str], str]:
652
+ win = report["window"]
653
+ scope = report["scope"]
654
+ totals = report["totals"]
655
+ prev = report["previousTotals"]
656
+ delta = report["delta"]
657
+ structural = report["structuralObservation"]
658
+ gran = str(win.get("granularity", "custom"))
659
+
660
+ zh_map = {
661
+ "daily": "日报",
662
+ "weekly": "周度复盘",
663
+ "monthly": "月度复盘",
664
+ "quarterly": "季度复盘",
665
+ "custom": "周期复盘",
666
+ }
667
+ en_map = {
668
+ "daily": "Daily Recap",
669
+ "weekly": "Weekly Recap",
670
+ "monthly": "Monthly Recap",
671
+ "quarterly": "Quarterly Recap",
672
+ "custom": "Period Recap",
673
+ }
674
+ kind = zh_map.get(gran, "周期复盘") if is_zh else en_map.get(gran, "Period Recap")
675
+ title = f"{kind} - {report['person']['name']} ({scope['name']})"
676
+ subtitle = (
677
+ f"{win['since'][:10]} .. {win['until'][:10]} "
678
+ f"(vs {win['previousSince'][:10]} .. {win['previousUntil'][:10]})"
679
+ )
680
+ pills = [
681
+ f"Window: {win['label']}",
682
+ f"Scope: {scope['mode']}",
683
+ f"Matched: {scope['matchedRepositories']}/{scope['repositories']}",
684
+ ]
685
+
686
+ cards = [
687
+ _KpiCard(
688
+ "总提交数" if is_zh else "Total Commits",
689
+ str(totals["commits"]),
690
+ f"vs {prev['commits']} ({_fmt_delta(delta['commits'])})",
691
+ ),
692
+ _KpiCard(
693
+ "已交付提交" if is_zh else "Delivered Commits",
694
+ str(totals["deliveredCommits"]),
695
+ f"vs {prev['deliveredCommits']} ({_fmt_delta(delta['deliveredCommits'])})",
696
+ tone="good",
697
+ ),
698
+ _KpiCard(
699
+ "未合并提交" if is_zh else "Authored-Only",
700
+ str(totals["authoredOnlyCommits"]),
701
+ f"vs {prev['authoredOnlyCommits']}",
702
+ tone="warn" if totals["authoredOnlyCommits"] > 0 else "neutral",
703
+ ),
704
+ _KpiCard(
705
+ "已完成工作项" if is_zh else "Completed Items",
706
+ str(totals["completedItems"]),
707
+ f"vs {prev['completedItems']} ({_fmt_delta(delta['completedItems'])})",
708
+ tone="good",
709
+ ),
710
+ _KpiCard(
711
+ "待跟进工作项" if is_zh else "Pending Follow-Ups",
712
+ str(totals["pendingItems"]),
713
+ f"vs {prev['pendingItems']} ({_fmt_delta(delta['pendingItems'])})",
714
+ tone="warn" if totals["pendingItems"] > 0 else "neutral",
715
+ ),
716
+ ]
717
+
718
+ compare_bars = [
719
+ _BarItem(
720
+ "Commits" if not is_zh else "总提交",
721
+ int(totals["commits"]),
722
+ int(prev["commits"]),
723
+ f"Current {totals['commits']} / Prev {prev['commits']}",
724
+ ),
725
+ _BarItem(
726
+ "Delivered" if not is_zh else "已交付",
727
+ int(totals["deliveredCommits"]),
728
+ int(prev["deliveredCommits"]),
729
+ f"Current {totals['deliveredCommits']} / Prev {prev['deliveredCommits']}",
730
+ ),
731
+ _BarItem(
732
+ "Completed Items" if not is_zh else "已完成项",
733
+ int(totals["completedItems"]),
734
+ int(prev["completedItems"]),
735
+ f"Current {totals['completedItems']} / Prev {prev['completedItems']}",
736
+ ),
737
+ ]
738
+
739
+ groups: list[str] = []
740
+ highlight_cards: list[str] = []
741
+ for item in report.get("deliveredHighlights", []):
742
+ grp = str(item["group"])
743
+ groups.append(grp)
744
+ ev_ids = list(item.get("evidenceIds", []))
745
+ for ev in ev_ids:
746
+ evidence_index[ev] = {
747
+ "evidenceId": ev,
748
+ "status": "DELIVERED",
749
+ "repoKey": item["repoKey"],
750
+ "group": grp,
751
+ "itemId": item["itemId"],
752
+ "title": item["title"],
753
+ "difficulty": item.get("difficulty"),
754
+ "size": item.get("size"),
755
+ "commits": item["commits"],
756
+ }
757
+ diff_tag = ""
758
+ if item.get("difficulty"):
759
+ cls = "tag-high" if item["difficulty"] == "HIGH_RISK" else "tag-good"
760
+ diff_tag = f'<span class="tag {cls}">{_esc(item["difficulty"])}</span>'
761
+ size_tag = f'<span class="tag">{_esc(item["size"])}</span>' if item.get("size") else ""
762
+ search_blob = f"{item['repoKey']} {grp} {item['title']} {' '.join(ev_ids)}"
763
+ highlight_cards.append(
764
+ f'<li class="item-card" data-filterable="1" data-group="{_esc(grp)}" '
765
+ f'data-search="{_esc(search_blob)}">'
766
+ f'<div class="item-head">'
767
+ f'<span class="item-title">{_esc(item["title"])}</span>'
768
+ f'<div><span class="tag">{_esc(item["repoKey"])}</span> {diff_tag} {size_tag} '
769
+ f'<span class="tag">{item["commits"]} commits</span></div>'
770
+ f"</div>"
771
+ f"{_render_ev_badges(ev_ids)}"
772
+ "</li>"
773
+ )
774
+
775
+ pending_cards: list[str] = []
776
+ for item in report.get("pendingFollowUps", []):
777
+ grp = str(item["group"])
778
+ groups.append(grp)
779
+ ev_ids = list(item.get("evidenceIds", []))
780
+ for ev in ev_ids:
781
+ evidence_index[ev] = {
782
+ "evidenceId": ev,
783
+ "status": "PENDING_AUTHORED_ONLY",
784
+ "repoKey": item["repoKey"],
785
+ "group": grp,
786
+ "itemId": item["itemId"],
787
+ "title": item["title"],
788
+ "commits": item["commits"],
789
+ }
790
+ search_blob = f"{item['repoKey']} {grp} {item['title']} {' '.join(ev_ids)}"
791
+ pending_cards.append(
792
+ f'<li class="item-card" data-filterable="1" data-group="{_esc(grp)}" '
793
+ f'data-search="{_esc(search_blob)}">'
794
+ f'<div class="item-head">'
795
+ f'<span class="item-title">{_esc(item["title"])}</span>'
796
+ f'<div><span class="tag tag-warn">AUTHORED_ONLY</span> '
797
+ f'<span class="tag">{_esc(item["repoKey"])}</span> '
798
+ f'<span class="tag">{item["commits"]} commits</span></div>'
799
+ f"</div>"
800
+ f"{_render_ev_badges(ev_ids)}"
801
+ "</li>"
802
+ )
803
+
804
+ empty_hi = (
805
+ '<p class="subtitle">本期暂无已合入默认分支的工作项。</p>'
806
+ if is_zh
807
+ else '<p class="subtitle">No delivered work items in this window.</p>'
808
+ )
809
+ empty_pend = (
810
+ '<p class="subtitle">本期无待跟进的未合并工作项。</p>'
811
+ if is_zh
812
+ else '<p class="subtitle">No pending follow-up items in this window.</p>'
813
+ )
814
+ obs_note = (
815
+ f"结构信号观察 (仅观察, 不影响评分): 热点仓库 {structural['hotspotSignalRepositories']}, "
816
+ f"耦合仓库 {structural['couplingSignalRepositories']}."
817
+ if is_zh
818
+ else (
819
+ f"Structural observation (observation-only, non-scoring): "
820
+ f"{structural['hotspotSignalRepositories']} hotspot repos, "
821
+ f"{structural['couplingSignalRepositories']} coupling repos."
822
+ )
823
+ )
824
+
825
+ hi_list_html = (
826
+ f'<ul class="item-list">{chr(10).join(highlight_cards)}</ul>'
827
+ if highlight_cards
828
+ else empty_hi
829
+ )
830
+ pend_list_html = (
831
+ f'<ul class="item-list">{chr(10).join(pending_cards)}</ul>'
832
+ if pending_cards
833
+ else empty_pend
834
+ )
835
+
836
+ body = "\n".join(
837
+ [
838
+ _render_kpi_grid(cards),
839
+ _render_svg_bar_chart(
840
+ "本期与上期对比" if is_zh else "Current vs Previous Period",
841
+ compare_bars,
842
+ primary_label="Current" if not is_zh else "本期",
843
+ secondary_label="Previous" if not is_zh else "上期",
844
+ ),
845
+ f'<section class="section"><div class="notice">{_esc(obs_note)}</div></section>',
846
+ '<section class="section">'
847
+ f'<h2>{"已交付亮点" if is_zh else "Delivered Highlights"}</h2>'
848
+ f"{_render_filter_bar(groups, is_zh=is_zh)}"
849
+ f"{hi_list_html}"
850
+ "</section>",
851
+ '<section class="section">'
852
+ f'<h2>{"待跟进未合并项" if is_zh else "Pending Follow-Ups"}</h2>'
853
+ f"{pend_list_html}"
854
+ "</section>",
855
+ _render_limitations(
856
+ report.get("limitations", ()),
857
+ report.get("warnings", ()),
858
+ is_zh=is_zh,
859
+ ),
860
+ ]
861
+ )
862
+ return title, subtitle, pills, body
863
+
864
+
865
+ def _build_portfolio_resume_body(
866
+ report: dict[str, Any],
867
+ *,
868
+ is_zh: bool,
869
+ evidence_index: dict[str, Any],
870
+ ) -> tuple[str, str, list[str], str]:
871
+ person_name = str(report["person"]["name"])
872
+ title = (
873
+ f"{person_name} 跨项目简历草稿"
874
+ if is_zh
875
+ else f"Cross-Project Resume Draft - {person_name}"
876
+ )
877
+ default_role = "未指定目标岗位" if is_zh else "Target role not set"
878
+ subtitle = str(report.get("targetRole") or default_role)
879
+ groups_data = report.get("projectGroups", [])
880
+ total_bullets = sum(len(g.get("bullets", [])) for g in groups_data)
881
+ pills = [
882
+ f"Style: {report.get('style', 'star')}",
883
+ f"Groups: {len(groups_data)}",
884
+ f"Bullets: {total_bullets}",
885
+ ]
886
+
887
+ cards = [
888
+ _KpiCard("项目分组" if is_zh else "Project Groups", str(len(groups_data))),
889
+ _KpiCard(
890
+ "证据要点" if is_zh else "Evidence-Backed Bullets",
891
+ str(total_bullets),
892
+ tone="good",
893
+ ),
894
+ _KpiCard(
895
+ "代表性能力" if is_zh else "Capabilities",
896
+ str(len(report.get("skills", []))),
897
+ ),
898
+ _KpiCard(
899
+ "待本人补充" if is_zh else "Pending Self-Inputs",
900
+ str(len(report.get("pendingSelfInputs", []))),
901
+ tone="warn" if report.get("pendingSelfInputs") else "neutral",
902
+ ),
903
+ ]
904
+
905
+ group_names = [str(g["group"]) for g in groups_data]
906
+ group_sections: list[str] = []
907
+ for grp_obj in groups_data:
908
+ grp = str(grp_obj["group"])
909
+ bullet_html: list[str] = []
910
+ for bullet in grp_obj.get("bullets", []):
911
+ ev_ids = list(bullet.get("evidenceIds", []))
912
+ for ev in ev_ids:
913
+ evidence_index[ev] = {
914
+ "evidenceId": ev,
915
+ "group": grp,
916
+ "repoKeys": bullet.get("repoKeys", []),
917
+ "claimType": bullet.get("claimType"),
918
+ "text": bullet.get("text"),
919
+ }
920
+ search_blob = f"{grp} {bullet.get('text', '')} {' '.join(ev_ids)}"
921
+ bullet_html.append(
922
+ f'<li class="item-card" data-filterable="1" data-group="{_esc(grp)}" '
923
+ f'data-search="{_esc(search_blob)}">'
924
+ f'<div>{_esc(bullet.get("text", ""))}</div>'
925
+ f"{_render_ev_badges(ev_ids)}"
926
+ "</li>"
927
+ )
928
+ group_sections.append(
929
+ f'<div style="margin-bottom:16px;"><h3>{_esc(grp)}</h3>'
930
+ f'<ul class="item-list">{"".join(bullet_html)}</ul></div>'
931
+ )
932
+
933
+ exp_heading = (
934
+ "项目经历 (点击证据标签可核验)" if is_zh else "Project Experience (Click EV Badges)"
935
+ )
936
+ body = "\n".join(
937
+ [
938
+ _render_kpi_grid(cards),
939
+ '<section class="section">'
940
+ f'<h2>{"专业概述" if is_zh else "Professional Summary"}</h2>'
941
+ f'<p>{_esc(report.get("professionalSummary", ""))}</p></section>',
942
+ '<section class="section">'
943
+ f"<h2>{exp_heading}</h2>"
944
+ f"{_render_filter_bar(group_names, is_zh=is_zh)}"
945
+ f'{"".join(group_sections)}</section>',
946
+ _render_limitations(
947
+ report.get("limitations", ()),
948
+ report.get("warnings", ()),
949
+ is_zh=is_zh,
950
+ ),
951
+ ]
952
+ )
953
+ return title, subtitle, pills, body
954
+
955
+
956
+ def _build_single_repo_body(
957
+ report: dict[str, Any],
958
+ *,
959
+ is_zh: bool,
960
+ include_email: bool,
961
+ evidence_index: dict[str, Any],
962
+ ) -> tuple[str, str, list[str], str]:
963
+ report_type = str(report.get("reportType") or "PERSON")
964
+ for entry in report.get("evidence", []):
965
+ ev_id = str(entry.get("id") or "")
966
+ if ev_id:
967
+ evidence_index[ev_id] = {
968
+ "id": ev_id,
969
+ "type": entry.get("type"),
970
+ "summary": entry.get("summary"),
971
+ "commitHashes": entry.get("commitHashes", []),
972
+ "paths": entry.get("paths", []),
973
+ }
974
+
975
+ if report_type == "WORK_ASSESSMENT":
976
+ workload = report.get("workloadSummary") or {}
977
+ diff = report.get("difficultyDistribution") or {}
978
+ subjects = report.get("subjects") or []
979
+ subject_name = (
980
+ str(subjects[0]["person"]["name"])
981
+ if len(subjects) == 1
982
+ else f"{len(subjects)} contributors"
983
+ )
984
+ title = (
985
+ f"工作量与难度评估 - {subject_name}"
986
+ if is_zh
987
+ else f"Work Assessment - {subject_name}"
988
+ )
989
+ subtitle = f"Scope: {report.get('scopeType', 'PERSON')}"
990
+ pills = [f"Report: {report_type}", f"Schema: {report.get('schemaVersion', '2.0')}"]
991
+ cards = [
992
+ _KpiCard(
993
+ "已完成项" if is_zh else "Completed Items",
994
+ str(workload.get("completedItems", 0)),
995
+ tone="good",
996
+ ),
997
+ _KpiCard(
998
+ "待跟进项" if is_zh else "Pending Items",
999
+ str(workload.get("pendingItems", 0)),
1000
+ tone="warn" if workload.get("pendingItems", 0) else "neutral",
1001
+ ),
1002
+ _KpiCard("返工项" if is_zh else "Rework Items", str(workload.get("reworkItems", 0))),
1003
+ _KpiCard(
1004
+ "集成合并项" if is_zh else "Integration Items",
1005
+ str(workload.get("integrationItems", 0)),
1006
+ ),
1007
+ ]
1008
+ diff_bars = [
1009
+ _BarItem(level, int(diff.get(level, 0)))
1010
+ for level in ("HIGH_RISK", "COMPLEX", "STANDARD", "ROUTINE")
1011
+ ]
1012
+ item_cards: list[str] = []
1013
+ for subj in subjects:
1014
+ pname = str(subj["person"]["name"])
1015
+ for ia in subj.get("itemAssessments", []):
1016
+ ev_ids = list(ia.get("evidenceIds", []))
1017
+ d_level = str((ia.get("difficulty") or {}).get("level") or "ROUTINE")
1018
+ s_band = str((ia.get("size") or {}).get("band") or "S")
1019
+ bucket = str(ia.get("completionBucket") or "")
1020
+ item_id = str(ia.get("contributionItemId") or "")
1021
+ search_blob = f"{pname} {item_id} {bucket} {d_level} {' '.join(ev_ids)}"
1022
+ item_cards.append(
1023
+ f'<li class="item-card" data-filterable="1" data-group="{_esc(bucket)}" '
1024
+ f'data-search="{_esc(search_blob)}">'
1025
+ f'<div class="item-head"><span class="item-title">'
1026
+ f"{_esc(item_id)} ({_esc(pname)})</span>"
1027
+ f'<div><span class="tag">{_esc(bucket)}</span> '
1028
+ f'<span class="tag">{_esc(d_level)}</span> '
1029
+ f'<span class="tag">{_esc(s_band)}</span></div></div>'
1030
+ f"{_render_ev_badges(ev_ids)}</li>"
1031
+ )
1032
+ diff_title = "难度分布" if is_zh else "Difficulty Distribution"
1033
+ body = "\n".join(
1034
+ [
1035
+ _render_kpi_grid(cards),
1036
+ _render_svg_bar_chart(diff_title, diff_bars),
1037
+ '<section class="section">'
1038
+ f'<h2>{"工作项评估明细" if is_zh else "Work Item Assessments"}</h2>'
1039
+ f"{_render_filter_bar(['COMPLETED', 'PENDING', 'REWORK'], is_zh=is_zh)}"
1040
+ f'<ul class="item-list">{"".join(item_cards)}</ul></section>',
1041
+ _render_limitations(
1042
+ report.get("limitations", ()),
1043
+ report.get("warnings", ()),
1044
+ is_zh=is_zh,
1045
+ ),
1046
+ ]
1047
+ )
1048
+ return title, subtitle, pills, body
1049
+
1050
+ if report_type == "RESUME":
1051
+ person = report.get("person") or {}
1052
+ pname = str(person.get("name") or "Candidate")
1053
+ title = f"{pname} 个人简历草稿" if is_zh else f"Resume Draft - {pname}"
1054
+ default_single_role = "未指定岗位" if is_zh else "Target role not set"
1055
+ subtitle = str(report.get("targetRole") or default_single_role)
1056
+ bullets = report.get("experienceBullets") or []
1057
+ pills = [f"Report: {report_type}", f"Bullets: {len(bullets)}"]
1058
+ bullet_cards: list[str] = []
1059
+ for b in bullets:
1060
+ ev_ids = list(b.get("evidenceIds", []))
1061
+ search_blob = f"{b.get('text', '')} {' '.join(ev_ids)}"
1062
+ bullet_cards.append(
1063
+ f'<li class="item-card" data-filterable="1" data-group="bullet" '
1064
+ f'data-search="{_esc(search_blob)}">'
1065
+ f'<div>{_esc(b.get("text", ""))}</div>'
1066
+ f"{_render_ev_badges(ev_ids)}</li>"
1067
+ )
1068
+ body = "\n".join(
1069
+ [
1070
+ '<section class="section">'
1071
+ f'<h2>{"专业概述" if is_zh else "Professional Summary"}</h2>'
1072
+ f'<p>{_esc(report.get("professionalSummary", ""))}</p></section>',
1073
+ '<section class="section">'
1074
+ f'<h2>{"经历要点" if is_zh else "Experience Bullets"}</h2>'
1075
+ f"{_render_filter_bar([], is_zh=is_zh)}"
1076
+ f'<ul class="item-list">{"".join(bullet_cards)}</ul></section>',
1077
+ _render_limitations(
1078
+ report.get("limitations", ()),
1079
+ report.get("warnings", ()),
1080
+ is_zh=is_zh,
1081
+ ),
1082
+ ]
1083
+ )
1084
+ return title, subtitle, pills, body
1085
+
1086
+ # Generic PERSON / PROJECT fallback
1087
+ summary = report.get("summary") or {}
1088
+ if report_type == "PROJECT":
1089
+ repo_name = _safe_repo_name(report.get("repository"))
1090
+ title = f"项目贡献报告 - {repo_name}" if is_zh else f"Project Report - {repo_name}"
1091
+ subtitle = f"Contributors: {summary.get('people', 0)}"
1092
+ else:
1093
+ person = report.get("person") or {}
1094
+ pname = str(person.get("name") or "Contributor")
1095
+ title = f"个人贡献报告 - {pname}" if is_zh else f"Contribution Report - {pname}"
1096
+ subtitle = str(person.get("email", "")) if include_email else "Deterministic Git Evidence"
1097
+ pills = [f"Report: {report_type}"]
1098
+ cards = [
1099
+ _KpiCard("提交数" if is_zh else "Commits", str(summary.get("commits", 0))),
1100
+ _KpiCard("变更文件" if is_zh else "Files Changed", str(summary.get("filesChanged", 0))),
1101
+ _KpiCard(
1102
+ "新增/删除行" if is_zh else "Insertions / Deletions",
1103
+ f"+{summary.get('insertions', 0)} / -{summary.get('deletions', 0)}",
1104
+ ),
1105
+ ]
1106
+ item_cards = []
1107
+ for item in report.get("contributionItems", []):
1108
+ ev_ids = list(item.get("evidenceIds", []))
1109
+ search_blob = f"{item.get('id', '')} {item.get('title', '')} {' '.join(ev_ids)}"
1110
+ item_cards.append(
1111
+ f'<li class="item-card" data-filterable="1" data-group="item" '
1112
+ f'data-search="{_esc(search_blob)}">'
1113
+ f'<div class="item-head"><span class="item-title">'
1114
+ f"{_esc(item.get('id', ''))} - {_esc(item.get('title', ''))}</span>"
1115
+ f'<span class="tag">{_esc(item.get("confidence", ""))}</span></div>'
1116
+ f"{_render_ev_badges(ev_ids)}</li>"
1117
+ )
1118
+ body = "\n".join(
1119
+ [
1120
+ _render_kpi_grid(cards),
1121
+ '<section class="section">'
1122
+ f'<h2>{"贡献工作项" if is_zh else "Contribution Items"}</h2>'
1123
+ f"{_render_filter_bar([], is_zh=is_zh)}"
1124
+ f'<ul class="item-list">{"".join(item_cards)}</ul></section>',
1125
+ _render_limitations(
1126
+ report.get("limitations", ()),
1127
+ report.get("warnings", ()),
1128
+ is_zh=is_zh,
1129
+ ),
1130
+ ]
1131
+ )
1132
+ return title, subtitle, pills, body
1133
+
1134
+
1135
+ def _build_brag_body(
1136
+ report: dict[str, Any],
1137
+ *,
1138
+ is_zh: bool,
1139
+ evidence_index: dict[str, Any],
1140
+ ) -> tuple[str, str, list[str], str]:
1141
+ person_name = str((report.get("person") or {}).get("name") or "Unknown")
1142
+ scope = report.get("scope") or {}
1143
+ scope_name = str(scope.get("name") or "")
1144
+ period = report.get("period") or {}
1145
+ period_label = str(period.get("label") or "")
1146
+ summary = report.get("summary") or {}
1147
+
1148
+ title = (
1149
+ f"工程成果簿 (Brag Document) · {person_name}"
1150
+ if is_zh
1151
+ else f"Engineering Brag Document · {person_name}"
1152
+ )
1153
+ subtitle = (
1154
+ f"{scope_name} · 周期 {period_label} ({period.get('since', '')[:10]} ~ "
1155
+ f"{period.get('until', '')[:10]})"
1156
+ if is_zh
1157
+ else f"{scope_name} · Period {period_label} ({period.get('since', '')[:10]} to "
1158
+ f"{period.get('until', '')[:10]})"
1159
+ )
1160
+ pills = [
1161
+ f"Scope: {scope.get('mode', 'REPOSITORY')}",
1162
+ f"Repos: {scope.get('matchedRepositories', 0)}/{scope.get('repositories', 1)}",
1163
+ f"Rules: {report.get('ruleVersion', 'brag-rules-v1')}",
1164
+ ]
1165
+
1166
+ cards = [
1167
+ _KpiCard(
1168
+ "总提交" if is_zh else "Total Commits",
1169
+ str(summary.get("commits", 0)),
1170
+ f"已交付 {summary.get('deliveredCommits', 0)}"
1171
+ if is_zh
1172
+ else f"Delivered {summary.get('deliveredCommits', 0)}",
1173
+ ),
1174
+ _KpiCard(
1175
+ "完成工作项" if is_zh else "Completed Items",
1176
+ str(summary.get("completedItems", 0)),
1177
+ f"高复杂度/高风险 {summary.get('highDifficultyItems', 0)}"
1178
+ if is_zh
1179
+ else f"Complex/High-Risk {summary.get('highDifficultyItems', 0)}",
1180
+ tone="good",
1181
+ ),
1182
+ _KpiCard(
1183
+ "已核验成果" if is_zh else "Verified Outcomes",
1184
+ str(summary.get("verifiedOutcomes", 0)),
1185
+ f"已绑定证据 {summary.get('linkedOutcomes', 0)}"
1186
+ if is_zh
1187
+ else f"Linked to EV {summary.get('linkedOutcomes', 0)}",
1188
+ tone="good" if int(summary.get("verifiedOutcomes", 0)) > 0 else "warn",
1189
+ ),
1190
+ ]
1191
+
1192
+ outcomes = report.get("verifiedOutcomes") or []
1193
+ outcome_cards: list[str] = []
1194
+ for out in outcomes:
1195
+ out_id = str(out.get("id") or "")
1196
+ ev_ids = [str(ev) for ev in out.get("evidenceIds", [])]
1197
+ for ev in ev_ids:
1198
+ evidence_index.setdefault(
1199
+ ev,
1200
+ {
1201
+ "evidenceId": ev,
1202
+ "outcomeId": out_id,
1203
+ "outcomeText": out.get("text"),
1204
+ "source": out.get("source"),
1205
+ "verifiedBy": out.get("verifiedBy"),
1206
+ "verifiedAt": out.get("verifiedAt"),
1207
+ },
1208
+ )
1209
+ tags_html = "".join(f'<span class="tag">#{_esc(t)}</span> ' for t in out.get("tags", []))
1210
+ outcome_cards.append(
1211
+ '<li class="item-card">'
1212
+ '<div class="item-head">'
1213
+ f'<span class="item-title">[{_esc(out_id)}] {_esc(out.get("text", ""))}</span>'
1214
+ f'<div><span class="tag tag-good">{_esc(out.get("kind", "OUTCOME"))}</span> '
1215
+ f"{tags_html}</div>"
1216
+ "</div>"
1217
+ f'<p class="subtitle">Source: {_esc(out.get("source", ""))} · '
1218
+ f'Verified by {_esc(out.get("verifiedBy", ""))} ({_esc(out.get("verifiedAt", ""))})</p>'
1219
+ f"{_render_ev_badges(ev_ids) if ev_ids else ''}"
1220
+ "</li>"
1221
+ )
1222
+
1223
+ outcomes_html = (
1224
+ f'<ul class="item-list">{chr(10).join(outcome_cards)}</ul>'
1225
+ if outcome_cards
1226
+ else (
1227
+ '<p class="subtitle">暂无已核验成果, 可使用 <code>gca outcome add</code> 补充.</p>'
1228
+ if is_zh
1229
+ else (
1230
+ '<p class="subtitle">No verified outcomes yet. '
1231
+ "Use <code>gca outcome add</code>.</p>"
1232
+ )
1233
+ )
1234
+ )
1235
+
1236
+ sections = report.get("deliveredSections") or []
1237
+ groups = [str(sec.get("group") or "") for sec in sections]
1238
+ group_bars: list[_BarItem] = []
1239
+ delivered_cards: list[str] = []
1240
+ for sec in sections:
1241
+ grp = str(sec.get("group") or "default")
1242
+ sec_items = sec.get("items") or []
1243
+ group_bars.append(
1244
+ _BarItem(
1245
+ label=grp,
1246
+ value=len(sec_items),
1247
+ detail=f"{len(sec_items)} items",
1248
+ )
1249
+ )
1250
+ for item in sec_items:
1251
+ ev_ids = [str(ev) for ev in item.get("evidenceIds", [])]
1252
+ for ev in ev_ids:
1253
+ evidence_index[ev] = {
1254
+ "evidenceId": ev,
1255
+ "repoKey": item.get("repoKey"),
1256
+ "group": grp,
1257
+ "itemId": item.get("itemId"),
1258
+ "title": item.get("title"),
1259
+ "commits": item.get("commits"),
1260
+ "difficulty": item.get("difficulty"),
1261
+ "size": item.get("size"),
1262
+ "outcomeIds": item.get("outcomeIds", []),
1263
+ }
1264
+ out_badges = "".join(
1265
+ f'<span class="tag tag-good">{_esc(oid)}</span> '
1266
+ for oid in item.get("outcomeIds", [])
1267
+ )
1268
+ diff = str(item.get("difficulty") or "")
1269
+ diff_badge = f'<span class="tag">{_esc(diff)}</span> ' if diff else ""
1270
+ search_blob = (
1271
+ f"{item.get('repoKey', '')} {grp} {item.get('title', '')} "
1272
+ f"{' '.join(ev_ids)} {' '.join(item.get('outcomeIds', []))}"
1273
+ )
1274
+ delivered_cards.append(
1275
+ f'<li class="item-card" data-filterable="1" data-group="{_esc(grp)}" '
1276
+ f'data-search="{_esc(search_blob)}">'
1277
+ '<div class="item-head">'
1278
+ f'<span class="item-title">{_esc(item.get("title", ""))}</span>'
1279
+ f'<div>{out_badges}{diff_badge}'
1280
+ f'<span class="tag">{_esc(item.get("repoKey", ""))}</span> '
1281
+ f'<span class="tag">{item.get("commits", 1)} commits</span></div>'
1282
+ "</div>"
1283
+ f"{_render_ev_badges(ev_ids)}"
1284
+ "</li>"
1285
+ )
1286
+
1287
+ delivered_html = (
1288
+ f'<ul class="item-list">{chr(10).join(delivered_cards)}</ul>'
1289
+ if delivered_cards
1290
+ else (
1291
+ '<p class="subtitle">本周期暂无已合入默认分支的工作项。</p>'
1292
+ if is_zh
1293
+ else '<p class="subtitle">No delivered work items in this period.</p>'
1294
+ )
1295
+ )
1296
+
1297
+ disclaimers = "".join(
1298
+ f"<li>{_esc(d)}</li>" for d in report.get("disclaimers", [])
1299
+ )
1300
+ body = "\n".join(
1301
+ [
1302
+ _render_kpi_grid(cards),
1303
+ _render_svg_bar_chart(
1304
+ "按领域分布的已交付工作项" if is_zh else "Delivered Items by Area",
1305
+ group_bars,
1306
+ primary_label="Items" if not is_zh else "工作项",
1307
+ ),
1308
+ '<section class="section">'
1309
+ f'<h2>{"已核验成果 (Verified Outcomes)" if is_zh else "Verified Outcomes"}</h2>'
1310
+ f"{outcomes_html}"
1311
+ "</section>",
1312
+ '<section class="section">'
1313
+ f'<h2>{"已交付核心工作项" if is_zh else "Delivered Highlights"}</h2>'
1314
+ f"{_render_filter_bar(groups, is_zh=is_zh)}"
1315
+ f"{delivered_html}"
1316
+ "</section>",
1317
+ '<section class="section">'
1318
+ f'<h2>{"口径与防幻觉声明" if is_zh else "Boundaries & Disclaimers"}</h2>'
1319
+ f'<ul class="footer-limits">{disclaimers}</ul>'
1320
+ "</section>",
1321
+ ]
1322
+ )
1323
+ return title, subtitle, pills, body
1324
+
1325
+
1326
+ def render_html_report(
1327
+ report: dict[str, Any],
1328
+ *,
1329
+ language: str = "zh-CN",
1330
+ include_email: bool = False,
1331
+ ) -> str:
1332
+ """将 GCA 确定性报告渲染为单文件、零外链、防 XSS 的交互式 HTML 页面."""
1333
+ effective_lang = str(report.get("language") or language)
1334
+ is_zh = effective_lang.lower().startswith("zh")
1335
+ report_type = str(report.get("reportType") or "PERSON")
1336
+ evidence_index: dict[str, Any] = {}
1337
+
1338
+ if report_type == "PORTFOLIO_SUMMARY":
1339
+ title, subtitle, pills, body = _build_portfolio_summary_body(
1340
+ report,
1341
+ is_zh=is_zh,
1342
+ evidence_index=evidence_index,
1343
+ )
1344
+ elif report_type in {"RECAP", "PORTFOLIO_RECAP"}:
1345
+ title, subtitle, pills, body = _build_recap_body(
1346
+ report,
1347
+ is_zh=is_zh,
1348
+ evidence_index=evidence_index,
1349
+ )
1350
+ elif report_type in {"BRAG_DOCUMENT", "PORTFOLIO_BRAG_DOCUMENT"}:
1351
+ title, subtitle, pills, body = _build_brag_body(
1352
+ report,
1353
+ is_zh=is_zh,
1354
+ evidence_index=evidence_index,
1355
+ )
1356
+ elif report_type == "PORTFOLIO_RESUME":
1357
+ title, subtitle, pills, body = _build_portfolio_resume_body(
1358
+ report,
1359
+ is_zh=is_zh,
1360
+ evidence_index=evidence_index,
1361
+ )
1362
+ else:
1363
+ title, subtitle, pills, body = _build_single_repo_body(
1364
+ report,
1365
+ is_zh=is_zh,
1366
+ include_email=include_email,
1367
+ evidence_index=evidence_index,
1368
+ )
1369
+
1370
+ pills_html = "".join(f'<span class="pill">{_esc(p)}</span>' for p in pills if p)
1371
+ theme_label = "切换主题" if is_zh else "Toggle Theme"
1372
+ print_label = "打印 / 导出 PDF" if is_zh else "Print / PDF"
1373
+ close_label = "关闭" if is_zh else "Close"
1374
+ html_lang = "zh-CN" if is_zh else "en"
1375
+
1376
+ return (
1377
+ "<!DOCTYPE html>\n"
1378
+ f'<html lang="{html_lang}">\n'
1379
+ "<head>\n"
1380
+ '<meta charset="utf-8">\n'
1381
+ '<meta name="viewport" content="width=device-width, initial-scale=1">\n'
1382
+ f"<title>{_esc(title)}</title>\n"
1383
+ f"<style>{_CSS}</style>\n"
1384
+ "</head>\n"
1385
+ "<body>\n"
1386
+ '<main class="container">\n'
1387
+ '<header class="header">\n'
1388
+ "<div>\n"
1389
+ f'<h1 class="title">{_esc(title)}</h1>\n'
1390
+ f'<p class="subtitle">{_esc(subtitle)}</p>\n'
1391
+ f'<div class="meta-pills">{pills_html}</div>\n'
1392
+ "</div>\n"
1393
+ '<div class="toolbar">\n'
1394
+ f'<button id="gca-theme-toggle" class="btn" type="button">{_esc(theme_label)}</button>\n'
1395
+ f'<button id="gca-print-btn" class="btn" type="button">{_esc(print_label)}</button>\n'
1396
+ "</div>\n"
1397
+ "</header>\n"
1398
+ f"{body}\n"
1399
+ "</main>\n"
1400
+ '<aside id="gca-evidence-drawer" class="drawer" hidden>\n'
1401
+ '<div class="drawer-head">\n'
1402
+ '<strong id="gca-drawer-title">Evidence</strong>\n'
1403
+ f'<button id="gca-drawer-close" class="btn" type="button">{_esc(close_label)}</button>\n'
1404
+ "</div>\n"
1405
+ '<pre id="gca-drawer-body" class="drawer-code"></pre>\n'
1406
+ "</aside>\n"
1407
+ '<script id="gca-evidence-data" type="application/json">'
1408
+ f"{_safe_json_for_script(evidence_index)}"
1409
+ "</script>\n"
1410
+ f"<script>{_JS}</script>\n"
1411
+ "</body>\n"
1412
+ "</html>\n"
1413
+ )