Repository navigation
Expand file tree
/
Copy pathcodeslim_observatory.html
More file actions
407 lines (365 loc) · 27.7 KB
/
Copy pathcodeslim_observatory.html
File metadata and controls
407 lines (365 loc) · 27.7 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CodeSlim Project Observatory — G:\Project Directory\AGENTIC AI PROJECT DIRECTORY\CodeSlim\examples\Demo_test_bloated.py</title>
<style>
:root {
--bg-color: #1a1b26;
--card-bg: #24283b;
--text-main: #c0caf5;
--text-dim: #7982a9;
--cyan: #00e5ff;
--emerald: #00e676;
--yellow: #ffd600;
--red: #ff1744;
--magenta: #e040fb;
}
* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; }
body { background: var(--bg-color); color: var(--text-main); padding: 30px; line-height: 1.5; }
header { display: flex; justify-content: space-between; align-items: center; border-bottom: 2px solid #2ac3de; padding-bottom: 20px; margin-bottom: 30px; }
h1 { font-size: 24px; font-weight: 800; color: var(--cyan); letter-spacing: 0.5px; }
.meta-tag { background: #2ac3de22; color: var(--cyan); border: 1px solid var(--cyan); padding: 4px 12px; border-radius: 20px; font-size: 13px; font-weight: 600; }
.grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; margin-bottom: 30px; }
.card { background: var(--card-bg); border-radius: 12px; padding: 20px; border: 1px solid #414868; }
.stat-val { font-size: 32px; font-weight: 800; margin-top: 5px; }
.badge { padding: 2px 8px; border-radius: 4px; font-size: 12px; font-weight: 700; display: inline-block; }
.section-title { font-size: 18px; font-weight: 700; color: var(--cyan); margin-bottom: 15px; display: flex; align-items: center; gap: 8px; }
/* Treemap */
.treemap-container { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 30px; min-height: 120px; }
.tree-box { padding: 12px; border-radius: 8px; min-width: 130px; transition: transform 0.15s ease; cursor: pointer; }
.tree-box:hover { transform: translateY(-3px); filter: brightness(1.2); }
.tree-name { font-weight: 700; font-size: 13px; margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-meta { font-size: 11px; color: var(--text-dim); }
/* Controls & Search */
.controls { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; gap: 15px; }
.search-input { background: #1a1b26; border: 1px solid #414868; color: var(--text-main); padding: 10px 16px; border-radius: 8px; width: 300px; outline: none; }
.search-input:focus { border-color: var(--cyan); }
.btn-group { display: flex; gap: 8px; }
.filter-btn { background: #1a1b26; border: 1px solid #414868; color: var(--text-dim); padding: 8px 14px; border-radius: 6px; cursor: pointer; font-weight: 600; font-size: 13px; }
.filter-btn.active, .filter-btn:hover { border-color: var(--cyan); color: var(--cyan); background: #2ac3de11; }
/* Table */
table { width: 100%; border-collapse: collapse; background: var(--card-bg); border-radius: 12px; overflow: hidden; border: 1px solid #414868; }
th, td { padding: 14px 18px; text-align: left; border-bottom: 1px solid #2f354f; font-size: 14px; }
th { background: #1f2335; color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: 0.8px; }
tr.file-row { cursor: pointer; transition: background 0.15s ease; }
tr.file-row:hover td { background: #2e3440; }
tr:last-child td { border-bottom: none; }
/* Gauge SVG */
.gauge-wrapper { display: flex; align-items: center; gap: 20px; }
/* Fingerprint Bar */
.fingerprint-bar { display: flex; height: 16px; border-radius: 8px; overflow: hidden; background: #1a1b26; margin: 12px 0; }
.fp-segment { height: 100%; }
/* Glassmorphic Modal */
.modal-backdrop { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(15, 16, 22, 0.85); backdrop-filter: blur(6px); display: flex; align-items: center; justify-content: center; z-index: 9999; padding: 20px; }
.modal-card { background: #1f2335; border: 1px solid #414868; border-radius: 16px; width: 100%; max-width: 900px; max-height: 85vh; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 20px 50px rgba(0,0,0,0.6); animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }
.modal-header { padding: 20px 24px; background: #1a1b26; border-bottom: 1px solid #3b4261; display: flex; justify-content: space-between; align-items: center; }
.close-btn { background: transparent; border: none; color: var(--text-dim); font-size: 24px; cursor: pointer; font-weight: bold; padding: 0 8px; }
.close-btn:hover { color: var(--red); }
.modal-tabs { display: flex; background: #16161e; border-bottom: 1px solid #3b4261; padding: 0 24px; gap: 8px; }
.modal-tab { background: transparent; border: none; color: var(--text-dim); padding: 12px 18px; font-size: 13px; font-weight: 700; cursor: pointer; border-bottom: 2px solid transparent; }
.modal-tab.active, .modal-tab:hover { color: var(--cyan); border-bottom-color: var(--cyan); }
.modal-body { padding: 24px; overflow-y: auto; flex-grow: 1; }
/* Diff Display */
.diff-code { background: #1a1b26; padding: 16px; border-radius: 8px; font-family: 'Consolas', 'Fira Code', monospace; font-size: 13px; line-height: 1.6; white-space: pre-wrap; word-break: break-all; border: 1px solid #2f354f; color: #a9b1d6; max-height: 400px; overflow-y: auto; }
.diff-line-add { color: #00e676; background: #00e67615; display: block; padding: 0 4px; border-radius: 2px; }
.diff-line-del { color: #ff1744; background: #ff174415; display: block; padding: 0 4px; border-radius: 2px; }
.diff-line-header { color: #00e5ff; font-weight: bold; }
</style>
</head>
<body>
<header>
<div>
<h1>🔭 CODESLIM PROJECT OBSERVATORY</h1>
<p style="color: var(--text-dim); font-size: 13px; margin-top: 4px;">Target Directory: <code>G:\Project Directory\AGENTIC AI PROJECT DIRECTORY\CodeSlim\examples\Demo_test_bloated.py</code></p>
</div>
<div>
<span class="meta-tag">CodeSlim v2.0 HTML Observatory</span>
</div>
</header>
<div class="grid-stats">
<div class="card gauge-wrapper">
<svg width="90" height="90" viewBox="0 0 100 100">
<circle cx="50" cy="50" r="40" stroke="#1a1b26" stroke-width="12" fill="none"/>
<circle cx="50" cy="50" r="40" stroke="#ffd600" stroke-width="12" fill="none"
stroke-dasharray="251.2" stroke-dashoffset="117.31040000000002"
stroke-linecap="round" transform="rotate(-90 50 50)"/>
<text x="50" y="55" font-size="28" font-weight="800" fill="#ffd600" text-anchor="middle">C</text>
</svg>
<div>
<div style="color: var(--text-dim); font-size: 12px; font-weight: 700; text-transform: uppercase;">Overall Health</div>
<div class="stat-val" style="color: var(--gauge-color, #ffffff);">53.3</div>
<div style="font-size: 12px; color: var(--text-dim);">Bloat Index Score</div>
</div>
</div>
<div class="card">
<div style="color: var(--text-dim); font-size: 12px; font-weight: 700; text-transform: uppercase;">Analyzed Files</div>
<div class="stat-val" style="color: var(--cyan);">1</div>
<div style="font-size: 12px; color: var(--text-dim); margin-top: 4px;">
<span style="color: var(--emerald); font-weight: 700;">0 Clean</span> |
<span style="color: var(--yellow); font-weight: 700;">1 Moderate</span> |
<span style="color: var(--red); font-weight: 700;">0 Severe</span>
</div>
</div>
<div class="card">
<div style="color: var(--text-dim); font-size: 12px; font-weight: 700; text-transform: uppercase;">Cross-File Anomalies</div>
<div class="stat-val" style="color: var(--magenta);">0</div>
<div style="font-size: 12px; color: var(--text-dim); margin-top: 4px;">
Phantom Functions | <span style="color: var(--cyan);">0.0%</span> Spread
</div>
</div>
</div>
<!-- Codebase Fingerprint Bar -->
<div class="card" style="margin-bottom: 30px;">
<div style="color: var(--text-dim); font-size: 12px; font-weight: 700; text-transform: uppercase;">Codebase Composition Fingerprint (311 total lines)</div>
<div class="fingerprint-bar">
<div class="fp-segment" style="width: var(--fp-clean-pct, 0%); background: var(--emerald);" title="Clean Code: 81.0%"></div>
<div class="fp-segment" style="width: var(--fp-dead-pct, 0%); background: var(--yellow);" title="Dead Code: 0.0%"></div>
<div class="fp-segment" style="width: var(--fp-complex-pct, 0%); background: var(--red);" title="Complex Code: 0.0%"></div>
<div class="fp-segment" style="width: var(--fp-dup-pct, 0%); background: var(--cyan);" title="Duplication: 19.0%"></div>
</div>
<div style="display: flex; gap: 20px; font-size: 12px; color: var(--text-dim);">
<span><strong style="color: var(--emerald);">Clean:</strong> 252 (81.0%)</span>
<span><strong style="color: var(--yellow);">Dead:</strong> 0 (0.0%)</span>
<span><strong style="color: var(--red);">Complex:</strong> 0 (0.0%)</span>
<span><strong style="color: var(--cyan);">Duplicate:</strong> 59 (19.0%)</span>
</div>
</div>
<!-- Cross File Anomaly Details (if any exist) -->
<div class="section-title">📊 Codebase Visual Treemap (Click box to inspect diff)</div>
<div class="treemap-container">
<div class="tree-box" style="flex-grow: 311; background: #ffd6001a; border: 1px solid #ffd600;"
title="Click to inspect: G:\Project Directory\AGENTIC AI PROJECT DIRECTORY\CodeSlim\examples\Demo_test_bloated.py (Grade C)"
onclick="openSurgeryModal('G:\\Project Directory\\AGENTIC AI PROJECT DIRECTORY\\CodeSlim\\examples\\Demo_test_bloated.py')">
<div class="tree-name" style="color: #ffd600;">Demo_test_bloated.py</div>
<div class="tree-meta">311 L | CC 11</div>
</div>
</div>
<div class="section-title">⚡ File Bloat Matrix (1 files — Click row to inspect diff)</div>
<div class="controls">
<input type="text" id="searchInput" class="search-input" placeholder="Search file paths..." onkeyup="filterFiles()">
<div class="btn-group">
<button class="filter-btn active" onclick="filterGrade('ALL', this)">All</button>
<button class="filter-btn" onclick="filterGrade('A', this)">Grade A</button>
<button class="filter-btn" onclick="filterGrade('B', this)">Grade B</button>
<button class="filter-btn" onclick="filterGrade('C', this)">Grade C</button>
<button class="filter-btn" onclick="filterGrade('D', this)">Grade D</button>
<button class="filter-btn" onclick="filterGrade('F', this)">Grade F</button>
</div>
</div>
<table>
<thead>
<tr>
<th>File Path</th>
<th>Bloat Health</th>
<th>Total Lines</th>
<th>Max CC</th>
<th>Dead Items</th>
<th>Bloat Score Gauge</th>
</tr>
</thead>
<tbody id="fileTable">
<tr class="file-row" data-grade="C" data-file="g:\project directory\agentic ai project directory\codeslim\examples\demo_test_bloated.py" onclick="openSurgeryModal('G:\\Project Directory\\AGENTIC AI PROJECT DIRECTORY\\CodeSlim\\examples\\Demo_test_bloated.py')">
<td style="font-weight:600; color:#c0caf5;">G:\Project Directory\AGENTIC AI PROJECT DIRECTORY\CodeSlim\examples\Demo_test_bloated.py</td>
<td style="color:#ffd600; font-weight:700;">Grade C (53.3)</td>
<td>311</td>
<td><span class="badge" style="background:#ffd60022; color:#ffd600; border:1px solid #ffd600;">11</span></td>
<td>13</td>
<td style="width:160px;">
<div style="background:#24283b; height:10px; border-radius:5px; overflow:hidden;">
<div style="background:#ffd600; width:53%; height:100%;"></div>
</div>
</td>
</tr>
</tbody>
</table>
<!-- Interactive File Surgery & Diff Inspector Modal -->
<div id="surgeryModal" class="modal-backdrop" style="display:none;" onclick="closeModalOnBackdrop(event)">
<div class="modal-card" onclick="event.stopPropagation()">
<div class="modal-header">
<div>
<h2 id="modalFileName" style="color:var(--cyan); font-size:18px; font-weight:800;">File Inspector</h2>
<p id="modalSubTitle" style="color:var(--text-dim); font-size:12px; margin-top:2px;">Detailed surgery metrics & unified diff preview</p>
</div>
<button class="close-btn" onclick="closeSurgeryModal()">×</button>
</div>
<div class="modal-tabs">
<button id="btnTabImpact" class="modal-tab active" onclick="switchModalTab('impact')">📊 Impact Metrics</button>
<button id="btnTabFindings" class="modal-tab" onclick="switchModalTab('findings')">⚠️ Bloat Findings</button>
<button id="btnTabDiff" class="modal-tab" onclick="switchModalTab('diff')">🔍 Code Diff Viewer</button>
</div>
<div class="modal-body">
<!-- Tab 1: Impact Metrics -->
<div id="tabImpact" class="tab-pane">
<div style="display:grid; grid-template-columns:repeat(auto-fit, minmax(180px, 1fr)); gap:15px; margin-bottom:20px;">
<div style="background:#1a1b26; padding:16px; border-radius:8px; border:1px solid #3b4261;">
<div style="color:var(--text-dim); font-size:11px; font-weight:700;">BLOAT SCORE</div>
<div id="mBloatScore" style="font-size:24px; font-weight:800; margin-top:4px;">-</div>
</div>
<div style="background:#1a1b26; padding:16px; border-radius:8px; border:1px solid #3b4261;">
<div style="color:var(--text-dim); font-size:11px; font-weight:700;">ORIGINAL LINES</div>
<div id="mOrigLines" style="font-size:24px; font-weight:800; color:var(--text-main); margin-top:4px;">-</div>
</div>
<div style="background:#1a1b26; padding:16px; border-radius:8px; border:1px solid #3b4261;">
<div style="color:var(--text-dim); font-size:11px; font-weight:700;">LINES SAVED</div>
<div id="mLinesSaved" style="font-size:24px; font-weight:800; color:var(--emerald); margin-top:4px;">-</div>
</div>
<div style="background:#1a1b26; padding:16px; border-radius:8px; border:1px solid #3b4261;">
<div style="color:var(--text-dim); font-size:11px; font-weight:700;">MAX CYCLOMATIC CC</div>
<div id="mMaxCC" style="font-size:24px; font-weight:800; color:var(--yellow); margin-top:4px;">-</div>
</div>
</div>
</div>
<!-- Tab 2: Bloat Findings -->
<div id="tabFindings" class="tab-pane" style="display:none;">
<div id="mFindingsContainer"></div>
</div>
<!-- Tab 3: Code Diff -->
<div id="tabDiff" class="tab-pane" style="display:none;">
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:10px;">
<span style="font-size:12px; color:var(--text-dim); font-weight:600;">Unified Diff Patch Preview</span>
<button onclick="copyModalDiff()" style="background:#2ac3de22; border:1px solid var(--cyan); color:var(--cyan); padding:4px 10px; border-radius:4px; font-size:11px; font-weight:700; cursor:pointer;">Copy Diff</button>
</div>
<div id="mDiffContainer" class="diff-code">No diff available.</div>
</div>
</div>
</div>
</div>
<script>
const FILE_DATA_MAP = {"G:\\Project Directory\\AGENTIC AI PROJECT DIRECTORY\\CodeSlim\\examples\\Demo_test_bloated.py": {"file_path": "G:\\Project Directory\\AGENTIC AI PROJECT DIRECTORY\\CodeSlim\\examples\\Demo_test_bloated.py", "file_name": "Demo_test_bloated.py", "bloat_score": 53.3, "bloat_grade": "C", "original_lines": 311, "optimized_lines": 305, "lines_saved": 6, "max_cc": 11, "dead_count": 13, "diff": "--- a/G:\\Project Directory\\AGENTIC AI PROJECT DIRECTORY\\CodeSlim\\examples\\Demo_test_bloated.py+++ b/G:\\Project Directory\\AGENTIC AI PROJECT DIRECTORY\\CodeSlim\\examples\\Demo_test_bloated.py@@ -13,15 +13,9 @@ \"\"\"\n \n import os\n-import sys\n import json\n-from datetime import datetime\n-from typing import Optional, List, Dict, Tuple, Any, Union\n-\n-# \u2500\u2500 HALLUCINATED IMPORTS (CodeSlim Stage 2 should flag these) \u2500\u2500\n-import hyperopt_utils # \u274c Fake package\n+from typing import Optional, List, Dict, Tuple, Any\n from ml_optimizer import optimize_pipeline # \u274c Fake package\n-import data_normalizer # \u274c Fake package\n \n \n # \u2500\u2500 OVER-ABSTRACTION: 5 classes where 1 function suffices \u2500\u2500\n", "bloat_map": [{"severity": "high", "bloat_type": "dead_code", "line_start": 16, "line_end": 16, "explanation": "Unused import: sys", "suggestion": "Remove unused import 'sys'"}, {"severity": "high", "bloat_type": "dead_code", "line_start": 18, "line_end": 18, "explanation": "Unused import: datetime", "suggestion": "Remove unused import 'datetime'"}, {"severity": "high", "bloat_type": "dead_code", "line_start": 19, "line_end": 19, "explanation": "Unused import: Union", "suggestion": "Remove unused import 'Union'"}, {"severity": "high", "bloat_type": "dead_code", "line_start": 22, "line_end": 22, "explanation": "Unused import: hyperopt_utils", "suggestion": "Remove unused import 'hyperopt_utils'"}, {"severity": "high", "bloat_type": "dead_code", "line_start": 24, "line_end": 24, "explanation": "Unused import: data_normalizer", "suggestion": "Remove unused import 'data_normalizer'"}, {"severity": "medium", "bloat_type": "dead_code", "line_start": 63, "line_end": 63, "explanation": "Unused method: count_lines", "suggestion": "Remove unused method 'count_lines'"}, {"severity": "medium", "bloat_type": "dead_code", "line_start": 83, "line_end": 83, "explanation": "Unused method: valid_count", "suggestion": "Remove unused method 'valid_count'"}, {"severity": "medium", "bloat_type": "dead_code", "line_start": 86, "line_end": 86, "explanation": "Unused method: invalid_count", "suggestion": "Remove unused method 'invalid_count'"}, {"severity": "medium", "bloat_type": "dead_code", "line_start": 94, "line_end": 94, "explanation": "Unused attribute: transform_count", "suggestion": "Remove unused attribute 'transform_count'"}, {"severity": "medium", "bloat_type": "dead_code", "line_start": 97, "line_end": 97, "explanation": "Unused attribute: transform_count", "suggestion": "Remove unused attribute 'transform_count'"}, {"severity": "medium", "bloat_type": "dead_code", "line_start": 158, "line_end": 158, "explanation": "Unused function: legacy_compatability_shim", "suggestion": "Remove unused function 'legacy_compatability_shim'"}, {"severity": "medium", "bloat_type": "dead_code", "line_start": 166, "line_end": 166, "explanation": "Unused variable: UNUSED_CONSTANT", "suggestion": "Remove unused variable 'UNUSED_CONSTANT'"}, {"severity": "medium", "bloat_type": "dead_code", "line_start": 168, "line_end": 168, "explanation": "Unused variable: DEPRECATED_REGISTRY", "suggestion": "Remove unused variable 'DEPRECATED_REGISTRY'"}, {"severity": "high", "bloat_type": "high_complexity", "line_start": 122, "line_end": 153, "explanation": "High Cyclomatic Complexity (11) in 'deeply_nested'", "suggestion": "Refactor complex control flow using guard clauses and early returns"}, {"severity": "medium", "bloat_type": "duplication", "line_start": 1, "line_end": 311, "explanation": "Code duplication detected: 19.1% of file has copy-pasted blocks", "suggestion": "Extract shared logic into a reusable helper function"}]}};
let currentActiveKey = null;
function openSurgeryModal(fileKey) {
const data = FILE_DATA_MAP[fileKey];
if (!data) return;
currentActiveKey = fileKey;
document.getElementById('modalFileName').textContent = data.file_path;
document.getElementById('modalSubTitle').textContent = 'Bloat Grade ' + data.bloat_grade + ' | ' + data.original_lines + ' lines';
// Metrics
const scoreColor = data.bloat_grade === 'F' ? '#ff1744' : (data.bloat_grade === 'D' ? '#e040fb' : (data.bloat_grade === 'C' ? '#ffd600' : '#00e676'));
document.getElementById('mBloatScore').innerHTML = '<span style="color:' + scoreColor + ';">' + data.bloat_score + '</span> (Grade ' + data.bloat_grade + ')';
document.getElementById('mOrigLines').textContent = data.original_lines;
document.getElementById('mLinesSaved').textContent = '-' + data.lines_saved + ' lines';
document.getElementById('mMaxCC').textContent = data.max_cc;
// Findings
const fContainer = document.getElementById('mFindingsContainer');
if (data.bloat_map && data.bloat_map.length > 0) {
let fHtml = '<ul style="list-style:none; display:flex; flex-direction:column; gap:8px;">';
data.bloat_map.forEach(entry => {
const badgeColor = entry.severity === 'high' ? '#ff1744' : '#ffd600';
fHtml += '<li style="background:#1a1b26; padding:12px; border-radius:6px; border:1px solid #2f354f;">' +
'<span class="badge" style="background:' + badgeColor + '22; color:' + badgeColor + '; border:1px solid ' + badgeColor + '; margin-right:8px;">' + entry.severity.toUpperCase() + '</span>' +
'<strong>Lines ' + entry.line_start + '-' + entry.line_end + ':</strong> ' + escapeHtml(entry.explanation) +
'</li>';
});
fHtml += '</ul>';
fContainer.innerHTML = fHtml;
} else {
fContainer.innerHTML = '<div style="color:var(--emerald); font-weight:700;">No bloat findings reported. File is clean!</div>';
}
// Diff
const dContainer = document.getElementById('mDiffContainer');
if (data.diff && data.diff.trim().length > 0) {
const lines = data.diff.split('\n');
let formattedDiff = '';
lines.forEach(l => {
if (l.startsWith('+') && !l.startsWith('+++')) {
formattedDiff += '<span class="diff-line-add">' + escapeHtml(l) + '</span>\n';
} else if (l.startsWith('-') && !l.startsWith('---')) {
formattedDiff += '<span class="diff-line-del">' + escapeHtml(l) + '</span>\n';
} else if (l.startsWith('@@') || l.startsWith('---') || l.startsWith('+++')) {
formattedDiff += '<span class="diff-line-header">' + escapeHtml(l) + '</span>\n';
} else {
formattedDiff += escapeHtml(l) + '\n';
}
});
dContainer.innerHTML = formattedDiff;
} else {
dContainer.innerHTML = '<div style="color:var(--text-dim);">No code modifications required for this file.</div>';
}
switchModalTab('impact');
document.getElementById('surgeryModal').style.display = 'flex';
}
function closeSurgeryModal() {
document.getElementById('surgeryModal').style.display = 'none';
}
function closeModalOnBackdrop(e) {
if (e.target.id === 'surgeryModal') {
closeSurgeryModal();
}
}
function switchModalTab(tabName) {
document.querySelectorAll('.modal-tab').forEach(t => t.classList.remove('active'));
document.querySelectorAll('.tab-pane').forEach(p => p.style.display = 'none');
if (tabName === 'impact') {
document.getElementById('btnTabImpact').classList.add('active');
document.getElementById('tabImpact').style.display = 'block';
} else if (tabName === 'findings') {
document.getElementById('btnTabFindings').classList.add('active');
document.getElementById('tabFindings').style.display = 'block';
} else if (tabName === 'diff') {
document.getElementById('btnTabDiff').classList.add('active');
document.getElementById('tabDiff').style.display = 'block';
}
}
function copyModalDiff() {
if (!currentActiveKey || !FILE_DATA_MAP[currentActiveKey]) return;
const diffText = FILE_DATA_MAP[currentActiveKey].diff;
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(diffText).then(() => {
alert('Diff copied to clipboard!');
}).catch(() => {
fallbackCopyText(diffText);
});
} else {
fallbackCopyText(diffText);
}
}
function fallbackCopyText(text) {
const textArea = document.createElement('textarea');
textArea.value = text;
document.body.appendChild(textArea);
textArea.select();
try {
document.execCommand('copy');
alert('Diff copied to clipboard!');
} catch (err) {
alert('Failed to copy diff.');
}
document.body.removeChild(textArea);
}
function escapeHtml(str) {
return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
}
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') closeSurgeryModal();
});
function filterFiles() {
const query = document.getElementById('searchInput').value.toLowerCase();
const rows = document.querySelectorAll('.file-row');
rows.forEach(row => {
const filePath = row.getAttribute('data-file');
if (filePath && filePath.includes(query)) {
row.style.display = '';
} else {
row.style.display = 'none';
}
});
}
function filterGrade(grade, btn) {
document.querySelectorAll('.filter-btn').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
const rows = document.querySelectorAll('.file-row');
rows.forEach(row => {
const rowGrade = row.getAttribute('data-grade');
if (grade === 'ALL' || rowGrade === grade) {
row.style.display = '';
} else {
row.style.display = 'none';
}
});
}
</script>
</body>
</html>