tribunal-kit 4.4.0 → 4.4.2

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 (90) hide show
  1. package/.agent/agents/api-architect.md +66 -66
  2. package/.agent/agents/db-latency-auditor.md +216 -216
  3. package/.agent/agents/precedence-reviewer.md +250 -250
  4. package/.agent/agents/resilience-reviewer.md +88 -88
  5. package/.agent/agents/schema-reviewer.md +67 -67
  6. package/.agent/agents/throughput-optimizer.md +299 -299
  7. package/.agent/agents/ui-ux-auditor.md +292 -292
  8. package/.agent/agents/vitals-reviewer.md +223 -223
  9. package/.agent/history/architecture-graph.yaml +32 -1
  10. package/.agent/history/graph-cache.json +66 -19
  11. package/.agent/history/snapshots/bin__tribunal-kit.js.json +19 -0
  12. package/.agent/history/snapshots/eslint.config.js.json +9 -0
  13. package/.agent/history/snapshots/migrate_refs.js.json +3 -3
  14. package/.agent/history/snapshots/scripts__changelog.js.json +2 -1
  15. package/.agent/history/snapshots/scripts__sync-version.js.json +2 -1
  16. package/.agent/history/snapshots/scripts__validate-payload.js.json +1 -0
  17. package/.agent/history/snapshots/test__integration__bridges.test.js.json +2 -1
  18. package/.agent/history/snapshots/test__integration__init.test.js.json +1 -0
  19. package/.agent/history/snapshots/test__integration__routing.test.js.json +1 -0
  20. package/.agent/history/snapshots/test__integration__swarm_dispatcher.test.js.json +2 -1
  21. package/.agent/history/snapshots/test__integration__wave2.test.js.json +2 -1
  22. package/.agent/history/snapshots/test__unit__args.test.js.json +11 -1
  23. package/.agent/history/snapshots/test__unit__case_law_manager.test.js.json +1 -0
  24. package/.agent/history/snapshots/test__unit__context_broker.test.js.json +11 -0
  25. package/.agent/history/snapshots/test__unit__copyDir.test.js.json +11 -1
  26. package/.agent/history/snapshots/test__unit__graph_tools.test.js.json +1 -0
  27. package/.agent/history/snapshots/test__unit__inner_loop_validator.test.js.json +11 -0
  28. package/.agent/history/snapshots/test__unit__selfInstall.test.js.json +11 -1
  29. package/.agent/history/snapshots/test__unit__semver.test.js.json +11 -1
  30. package/.agent/history/snapshots/test__unit__swarm_dispatcher.test.js.json +1 -0
  31. package/.agent/scripts/_colors.js +154 -2
  32. package/.agent/scripts/_utils.js +205 -3
  33. package/.agent/scripts/append_flow.js +72 -72
  34. package/.agent/scripts/auto_preview.js +197 -197
  35. package/.agent/scripts/bundle_analyzer.js +90 -119
  36. package/.agent/scripts/case_law_manager.js +18 -13
  37. package/.agent/scripts/checklist.js +100 -88
  38. package/.agent/scripts/colors.js +7 -13
  39. package/.agent/scripts/compress_skills.js +141 -141
  40. package/.agent/scripts/consolidate_skills.js +149 -149
  41. package/.agent/scripts/context_broker.js +605 -609
  42. package/.agent/scripts/deep_compress.js +150 -150
  43. package/.agent/scripts/dependency_analyzer.js +68 -106
  44. package/.agent/scripts/graph_builder.js +341 -311
  45. package/.agent/scripts/graph_visualizer.js +390 -384
  46. package/.agent/scripts/graph_zoom.js +6 -4
  47. package/.agent/scripts/inner_loop_validator.js +445 -465
  48. package/.agent/scripts/lint_runner.js +27 -28
  49. package/.agent/scripts/minify_context.js +100 -100
  50. package/.agent/scripts/mutation_runner.js +280 -280
  51. package/.agent/scripts/patch_skills_meta.js +156 -156
  52. package/.agent/scripts/patch_skills_output.js +244 -244
  53. package/.agent/scripts/schema_validator.js +280 -297
  54. package/.agent/scripts/security_scan.js +37 -64
  55. package/.agent/scripts/session_manager.js +270 -276
  56. package/.agent/scripts/skill_evolution.js +637 -644
  57. package/.agent/scripts/skill_integrator.js +307 -313
  58. package/.agent/scripts/strengthen_skills.js +193 -193
  59. package/.agent/scripts/strip_tribunal.js +47 -47
  60. package/.agent/scripts/swarm_dispatcher.js +360 -360
  61. package/.agent/scripts/test_runner.js +32 -39
  62. package/.agent/scripts/utils.js +10 -25
  63. package/.agent/scripts/verify_all.js +84 -92
  64. package/.agent/skills/app-builder/templates/astro-static/TEMPLATE.md +1 -1
  65. package/.agent/skills/app-builder/templates/chrome-extension/TEMPLATE.md +1 -1
  66. package/.agent/skills/app-builder/templates/cli-tool/TEMPLATE.md +1 -1
  67. package/.agent/skills/app-builder/templates/electron-desktop/TEMPLATE.md +1 -1
  68. package/.agent/skills/app-builder/templates/express-api/TEMPLATE.md +1 -1
  69. package/.agent/skills/app-builder/templates/flutter-app/TEMPLATE.md +1 -1
  70. package/.agent/skills/app-builder/templates/monorepo-turborepo/TEMPLATE.md +1 -1
  71. package/.agent/skills/app-builder/templates/nextjs-fullstack/TEMPLATE.md +1 -1
  72. package/.agent/skills/app-builder/templates/nextjs-saas/TEMPLATE.md +1 -1
  73. package/.agent/skills/app-builder/templates/nextjs-static/TEMPLATE.md +1 -1
  74. package/.agent/skills/app-builder/templates/nuxt-app/TEMPLATE.md +1 -1
  75. package/.agent/skills/app-builder/templates/python-fastapi/TEMPLATE.md +1 -1
  76. package/.agent/skills/app-builder/templates/react-native-app/TEMPLATE.md +1 -1
  77. package/.agent/skills/doc.md +1 -1
  78. package/.agent/skills/knowledge-graph/SKILL.md +52 -52
  79. package/.agent/skills/ui-ux-pro-max/SKILL.md +562 -562
  80. package/.agent/workflows/generate.md +183 -183
  81. package/.agent/workflows/tribunal-speed.md +183 -183
  82. package/README.md +1 -1
  83. package/bin/tribunal-kit.js +76 -87
  84. package/package.json +6 -3
  85. package/scripts/changelog.js +167 -167
  86. package/scripts/sync-version.js +81 -81
  87. package/.agent/history/architecture-explorer.html +0 -352
  88. package/.agent/scripts/__pycache__/_colors.cpython-311.pyc +0 -0
  89. package/.agent/scripts/__pycache__/_utils.cpython-311.pyc +0 -0
  90. package/.agent/scripts/__pycache__/case_law_manager.cpython-311.pyc +0 -0
@@ -1,384 +1,390 @@
1
- #!/usr/bin/env node
2
- /**
3
- * graph_visualizer.js — Tribunal Kit Architecture Visualizer
4
- * Reads the graph cache and generates a standalone HTML visualizer.
5
- * Uses a native zero-dependency Canvas force-directed graph.
6
- */
7
-
8
- 'use strict';
9
-
10
- const fs = require('fs');
11
- const path = require('path');
12
-
13
- const AGENT_DIR = path.join(process.cwd(), '.agent');
14
- const HISTORY_DIR = path.join(AGENT_DIR, 'history');
15
- const CACHE_FILE = path.join(HISTORY_DIR, 'graph-cache.json');
16
- const HTML_FILE = path.join(HISTORY_DIR, 'architecture-explorer.html');
17
-
18
- function main() {
19
- if (!fs.existsSync(CACHE_FILE)) {
20
- console.error('\x1b[31m✖ Error: graph-cache.json not found. Run graph_builder.js first.\x1b[0m');
21
- process.exit(1);
22
- }
23
-
24
- const cacheData = fs.readFileSync(CACHE_FILE, 'utf8');
25
-
26
- const htmlContent = `<!DOCTYPE html>
27
- <html lang="en">
28
- <head>
29
- <meta charset="UTF-8">
30
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
31
- <title>Tribunal Architecture Explorer</title>
32
- <style>
33
- :root {
34
- --bg: #09090b;
35
- --panel-bg: rgba(24, 24, 27, 0.8);
36
- --border: #27272a;
37
- --text: #e4e4e7;
38
- --text-dim: #a1a1aa;
39
- --critical: #ef4444;
40
- --high: #f97316;
41
- --medium: #eab308;
42
- --low: #3b82f6;
43
- --edge: rgba(255, 255, 255, 0.1);
44
- }
45
- body {
46
- margin: 0;
47
- padding: 0;
48
- background: var(--bg);
49
- color: var(--text);
50
- font-family: system-ui, -apple-system, sans-serif;
51
- overflow: hidden;
52
- }
53
- canvas {
54
- display: block;
55
- width: 100vw;
56
- height: 100vh;
57
- }
58
- #ui-panel {
59
- position: absolute;
60
- top: 20px;
61
- left: 20px;
62
- width: 320px;
63
- background: var(--panel-bg);
64
- backdrop-filter: blur(12px);
65
- border: 1px solid var(--border);
66
- border-radius: 12px;
67
- padding: 20px;
68
- box-shadow: 0 10px 30px rgba(0,0,0,0.5);
69
- pointer-events: none; /* Let clicks pass to canvas if not on panel */
70
- }
71
- h1 { margin: 0 0 10px 0; font-size: 1.2rem; font-weight: 600; }
72
- .stat { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 0.9rem; }
73
- .stat .val { font-family: monospace; color: white; }
74
- .legend { margin-top: 20px; display: grid; gap: 8px; font-size: 0.85rem; }
75
- .legend-item { display: flex; align-items: center; gap: 8px; }
76
- .dot { width: 10px; height: 10px; border-radius: 50%; }
77
-
78
- #node-details {
79
- margin-top: 20px;
80
- padding-top: 20px;
81
- border-top: 1px solid var(--border);
82
- display: none;
83
- pointer-events: auto;
84
- }
85
- #node-details h2 { margin: 0 0 10px 0; font-size: 1rem; word-break: break-all; }
86
- .detail-row { font-size: 0.85rem; margin-bottom: 4px; color: var(--text-dim); }
87
- .badge { display: inline-block; padding: 2px 6px; border-radius: 4px; font-size: 0.75rem; font-weight: bold; color: black; }
88
- ul { margin: 8px 0; padding-left: 20px; font-size: 0.85rem; color: var(--text-dim); max-height: 150px; overflow-y: auto; }
89
- </style>
90
- </head>
91
- <body>
92
-
93
- <canvas id="graph"></canvas>
94
-
95
- <div id="ui-panel">
96
- <h1>Tribunal Architecture</h1>
97
- <div class="stat"><span>Nodes</span><span class="val" id="stat-nodes">0</span></div>
98
- <div class="stat"><span>Edges</span><span class="val" id="stat-edges">0</span></div>
99
-
100
- <div class="legend">
101
- <div class="legend-item"><div class="dot" style="background: var(--critical)"></div> Critical (>10 dependents)</div>
102
- <div class="legend-item"><div class="dot" style="background: var(--high)"></div> High (5-10 dependents)</div>
103
- <div class="legend-item"><div class="dot" style="background: var(--medium)"></div> Medium (2-4 dependents)</div>
104
- <div class="legend-item"><div class="dot" style="background: var(--low)"></div> Low (0-1 dependents)</div>
105
- </div>
106
-
107
- <div id="node-details">
108
- <h2 id="nd-title">file.js</h2>
109
- <div class="detail-row">Risk Score: <span id="nd-risk" class="badge">Low</span></div>
110
- <div class="detail-row">Blast Radius: <span id="nd-blast" style="color:white;font-weight:bold">0</span> files</div>
111
- <div class="detail-row" style="margin-top:10px">Imports:</div>
112
- <ul id="nd-imports"></ul>
113
- <div class="detail-row">Dependents:</div>
114
- <ul id="nd-dependents"></ul>
115
- </div>
116
- </div>
117
-
118
- <script>
119
- const rawData = JSON.parse(decodeURIComponent("${encodeURIComponent(cacheData)}"));
120
-
121
- const nodes = [];
122
- const edges = [];
123
- const nodeMap = new Map();
124
-
125
- // Build Nodes
126
- Object.keys(rawData).forEach(file => {
127
- const info = rawData[file];
128
- const node = {
129
- id: file,
130
- imports: info.imports || [],
131
- dependents: info.dependents || [],
132
- riskScore: info.riskScore || 'Low',
133
- blastRadius: info.blastRadius || 0,
134
- x: Math.random() * window.innerWidth,
135
- y: Math.random() * window.innerHeight,
136
- vx: 0,
137
- vy: 0,
138
- radius: Math.min(20, Math.max(5, 5 + (info.blastRadius * 1.5)))
139
- };
140
-
141
- if (node.riskScore === 'Critical') node.color = '#ef4444';
142
- else if (node.riskScore === 'High') node.color = '#f97316';
143
- else if (node.riskScore === 'Medium') node.color = '#eab308';
144
- else node.color = '#3b82f6';
145
-
146
- nodes.push(node);
147
- nodeMap.set(file, node);
148
- });
149
-
150
- // Build Edges
151
- nodes.forEach(node => {
152
- node.imports.forEach(imp => {
153
- if (imp.startsWith('.')) {
154
- // Try to resolve
155
- const dir = node.id.split('/').slice(0, -1).join('/');
156
- let resolved = dir ? dir + '/' + imp.replace('./', '') : imp.replace('./', '');
157
-
158
- // Normalize standard paths relative to array
159
- let target = nodes.find(n => n.id === resolved || n.id === resolved + '.js' || n.id === resolved + '.ts');
160
- if (target) {
161
- edges.push({ source: node, target: target });
162
- }
163
- }
164
- });
165
- });
166
-
167
- document.getElementById('stat-nodes').innerText = nodes.length;
168
- document.getElementById('stat-edges').innerText = edges.length;
169
-
170
- // Force Directed Graph Simulation
171
- const canvas = document.getElementById('graph');
172
- const ctx = canvas.getContext('2d');
173
-
174
- function resize() {
175
- canvas.width = window.innerWidth;
176
- canvas.height = window.innerHeight;
177
- }
178
- window.addEventListener('resize', resize);
179
- resize();
180
-
181
- let hoveredNode = null;
182
- let selectedNode = null;
183
- let isDragging = false;
184
-
185
- // Physics constants
186
- const REPULSION = 2000;
187
- const SPRING_LENGTH = 100;
188
- const SPRING_STRENGTH = 0.05;
189
- const DAMPING = 0.85;
190
-
191
- function simulate() {
192
- // Repulsion
193
- for (let i = 0; i < nodes.length; i++) {
194
- for (let j = i + 1; j < nodes.length; j++) {
195
- const n1 = nodes[i];
196
- const n2 = nodes[j];
197
- const dx = n2.x - n1.x;
198
- const dy = n2.y - n1.y;
199
- let dist = Math.sqrt(dx*dx + dy*dy) || 1;
200
- if (dist < 300) {
201
- const force = REPULSION / (dist * dist);
202
- const fx = (dx / dist) * force;
203
- const fy = (dy / dist) * force;
204
- n1.vx -= fx;
205
- n1.vy -= fy;
206
- n2.vx += fx;
207
- n2.vy += fy;
208
- }
209
- }
210
- }
211
-
212
- // Attraction (Springs)
213
- edges.forEach(edge => {
214
- const dx = edge.target.x - edge.source.x;
215
- const dy = edge.target.y - edge.source.y;
216
- const dist = Math.sqrt(dx*dx + dy*dy) || 1;
217
- const force = (dist - SPRING_LENGTH) * SPRING_STRENGTH;
218
- const fx = (dx / dist) * force;
219
- const fy = (dy / dist) * force;
220
-
221
- edge.source.vx += fx;
222
- edge.source.vy += fy;
223
- edge.target.vx -= fx;
224
- edge.target.vy -= fy;
225
- });
226
-
227
- // Center gravity
228
- const cx = canvas.width / 2;
229
- const cy = canvas.height / 2;
230
- nodes.forEach(n => {
231
- n.vx += (cx - n.x) * 0.01;
232
- n.vy += (cy - n.y) * 0.01;
233
- });
234
-
235
- // Update positions
236
- nodes.forEach(n => {
237
- if (n === selectedNode && isDragging) return; // don't move dragged node
238
- n.vx *= DAMPING;
239
- n.vy *= DAMPING;
240
- n.x += n.vx;
241
- n.y += n.vy;
242
- });
243
- }
244
-
245
- function draw() {
246
- ctx.clearRect(0, 0, canvas.width, canvas.height);
247
-
248
- // Draw edges
249
- ctx.lineWidth = 1;
250
- edges.forEach(edge => {
251
- let isHighlighted = false;
252
- if (hoveredNode) {
253
- isHighlighted = (edge.source === hoveredNode || edge.target === hoveredNode);
254
- } else if (selectedNode) {
255
- isHighlighted = (edge.source === selectedNode || edge.target === selectedNode);
256
- }
257
-
258
- if (hoveredNode || selectedNode) {
259
- ctx.strokeStyle = isHighlighted ? 'rgba(255,255,255,0.8)' : 'rgba(255,255,255,0.05)';
260
- ctx.lineWidth = isHighlighted ? 2 : 1;
261
- } else {
262
- ctx.strokeStyle = 'rgba(255,255,255,0.15)';
263
- ctx.lineWidth = 1;
264
- }
265
-
266
- ctx.beginPath();
267
- ctx.moveTo(edge.source.x, edge.source.y);
268
- ctx.lineTo(edge.target.x, edge.target.y);
269
- ctx.stroke();
270
- });
271
-
272
- // Draw nodes
273
- nodes.forEach(n => {
274
- let opacity = 1;
275
- if (hoveredNode && n !== hoveredNode && !edges.some(e => (e.source===hoveredNode && e.target===n) || (e.target===hoveredNode && e.source===n))) {
276
- opacity = 0.2;
277
- } else if (selectedNode && !hoveredNode && n !== selectedNode && !edges.some(e => (e.source===selectedNode && e.target===n) || (e.target===selectedNode && e.source===n))) {
278
- opacity = 0.2;
279
- }
280
-
281
- ctx.beginPath();
282
- ctx.arc(n.x, n.y, n.radius, 0, Math.PI * 2);
283
- ctx.fillStyle = n.color;
284
- ctx.globalAlpha = opacity;
285
- ctx.fill();
286
-
287
- if (n === hoveredNode || n === selectedNode) {
288
- ctx.strokeStyle = '#fff';
289
- ctx.lineWidth = 2;
290
- ctx.stroke();
291
-
292
- ctx.globalAlpha = 1;
293
- ctx.fillStyle = '#fff';
294
- ctx.font = '12px system-ui';
295
- ctx.fillText(n.id.split('/').pop(), n.x + n.radius + 5, n.y + 4);
296
- }
297
- ctx.globalAlpha = 1;
298
- });
299
- }
300
-
301
- function loop() {
302
- simulate();
303
- draw();
304
- requestAnimationFrame(loop);
305
- }
306
- loop();
307
-
308
- // Interaction
309
- canvas.addEventListener('mousemove', e => {
310
- const rect = canvas.getBoundingClientRect();
311
- const mx = e.clientX - rect.left;
312
- const my = e.clientY - rect.top;
313
-
314
- if (isDragging && selectedNode) {
315
- selectedNode.x = mx;
316
- selectedNode.y = my;
317
- return;
318
- }
319
-
320
- hoveredNode = null;
321
- for (let i = nodes.length - 1; i >= 0; i--) {
322
- const n = nodes[i];
323
- const dx = mx - n.x;
324
- const dy = my - n.y;
325
- if (dx*dx + dy*dy < (n.radius + 5)**2) {
326
- hoveredNode = n;
327
- break;
328
- }
329
- }
330
- canvas.style.cursor = hoveredNode ? 'pointer' : 'default';
331
- });
332
-
333
- canvas.addEventListener('mousedown', e => {
334
- if (hoveredNode) {
335
- selectedNode = hoveredNode;
336
- isDragging = true;
337
- showDetails(selectedNode);
338
- } else {
339
- selectedNode = null;
340
- document.getElementById('node-details').style.display = 'none';
341
- }
342
- });
343
-
344
- canvas.addEventListener('mouseup', () => { isDragging = false; });
345
-
346
- function showDetails(n) {
347
- const panel = document.getElementById('node-details');
348
- panel.style.display = 'block';
349
- document.getElementById('nd-title').innerText = n.id;
350
-
351
- const riskEl = document.getElementById('nd-risk');
352
- riskEl.innerText = n.riskScore;
353
- riskEl.style.backgroundColor = n.color;
354
-
355
- document.getElementById('nd-blast').innerText = n.blastRadius;
356
-
357
- const importsUl = document.getElementById('nd-imports');
358
- importsUl.innerHTML = '';
359
- n.imports.forEach(i => {
360
- const li = document.createElement('li');
361
- li.innerText = i;
362
- importsUl.appendChild(li);
363
- });
364
- if(n.imports.length===0) importsUl.innerHTML = '<li>None</li>';
365
-
366
- const depsUl = document.getElementById('nd-dependents');
367
- depsUl.innerHTML = '';
368
- n.dependents.forEach(d => {
369
- const li = document.createElement('li');
370
- li.innerText = d;
371
- depsUl.appendChild(li);
372
- });
373
- if(n.dependents.length===0) depsUl.innerHTML = '<li>None</li>';
374
- }
375
- </script>
376
- </body>
377
- </html>`;
378
-
379
- fs.writeFileSync(HTML_FILE, htmlContent);
380
- console.log(`\x1b[32m✔ Interactive visualizer generated.\x1b[0m`);
381
- console.log(` \x1b[2mSaved to: ${HTML_FILE}\x1b[0m`);
382
- }
383
-
384
- main();
1
+ #!/usr/bin/env node
2
+ /**
3
+ * graph_visualizer.js — Tribunal Kit Architecture Visualizer
4
+ * Reads the graph cache and generates a standalone HTML visualizer.
5
+ * Uses a native zero-dependency Canvas force-directed graph.
6
+ */
7
+
8
+ 'use strict';
9
+
10
+ const fs = require('fs');
11
+ const path = require('path');
12
+
13
+ const { RED, GREEN, DIM, RESET } = require('./_colors');
14
+
15
+ const AGENT_DIR = path.join(process.cwd(), '.agent');
16
+ const HISTORY_DIR = path.join(AGENT_DIR, 'history');
17
+ const CACHE_FILE = path.join(HISTORY_DIR, 'graph-cache.json');
18
+ const HTML_FILE = path.join(HISTORY_DIR, 'architecture-explorer.html');
19
+
20
+ function main() {
21
+ if (!fs.existsSync(CACHE_FILE)) {
22
+ console.error(`${RED}✖ Error: graph-cache.json not found. Run graph_builder.js first.${RESET}`);
23
+ process.exit(1);
24
+ }
25
+
26
+ const cacheData = fs.readFileSync(CACHE_FILE, 'utf8');
27
+
28
+ const htmlContent = `<!DOCTYPE html>
29
+ <html lang="en">
30
+ <head>
31
+ <meta charset="UTF-8">
32
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
33
+ <title>Tribunal Architecture Explorer</title>
34
+ <style>
35
+ :root {
36
+ --bg: #09090b;
37
+ --panel-bg: rgba(24, 24, 27, 0.8);
38
+ --border: #27272a;
39
+ --text: #e4e4e7;
40
+ --text-dim: #a1a1aa;
41
+ --critical: #ef4444;
42
+ --high: #f97316;
43
+ --medium: #eab308;
44
+ --low: #3b82f6;
45
+ --edge: rgba(255, 255, 255, 0.1);
46
+ }
47
+ body {
48
+ margin: 0;
49
+ padding: 0;
50
+ background: var(--bg);
51
+ color: var(--text);
52
+ font-family: system-ui, -apple-system, sans-serif;
53
+ overflow: hidden;
54
+ }
55
+ canvas {
56
+ display: block;
57
+ width: 100vw;
58
+ height: 100vh;
59
+ }
60
+ #ui-panel {
61
+ position: absolute;
62
+ top: 20px;
63
+ left: 20px;
64
+ width: 320px;
65
+ background: var(--panel-bg);
66
+ backdrop-filter: blur(12px);
67
+ border: 1px solid var(--border);
68
+ border-radius: 12px;
69
+ padding: 20px;
70
+ box-shadow: 0 10px 30px rgba(0,0,0,0.5);
71
+ pointer-events: none; /* Let clicks pass to canvas if not on panel */
72
+ }
73
+ h1 { margin: 0 0 10px 0; font-size: 1.2rem; font-weight: 600; }
74
+ .stat { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 0.9rem; }
75
+ .stat .val { font-family: monospace; color: white; }
76
+ .legend { margin-top: 20px; display: grid; gap: 8px; font-size: 0.85rem; }
77
+ .legend-item { display: flex; align-items: center; gap: 8px; }
78
+ .dot { width: 10px; height: 10px; border-radius: 50%; }
79
+
80
+ #node-details {
81
+ margin-top: 20px;
82
+ padding-top: 20px;
83
+ border-top: 1px solid var(--border);
84
+ display: none;
85
+ pointer-events: auto;
86
+ }
87
+ #node-details h2 { margin: 0 0 10px 0; font-size: 1rem; word-break: break-all; }
88
+ .detail-row { font-size: 0.85rem; margin-bottom: 4px; color: var(--text-dim); }
89
+ .badge { display: inline-block; padding: 2px 6px; border-radius: 4px; font-size: 0.75rem; font-weight: bold; color: black; }
90
+ ul { margin: 8px 0; padding-left: 20px; font-size: 0.85rem; color: var(--text-dim); max-height: 150px; overflow-y: auto; }
91
+ </style>
92
+ </head>
93
+ <body>
94
+
95
+ <canvas id="graph"></canvas>
96
+
97
+ <div id="ui-panel">
98
+ <h1>Tribunal Architecture</h1>
99
+ <div class="stat"><span>Nodes</span><span class="val" id="stat-nodes">0</span></div>
100
+ <div class="stat"><span>Edges</span><span class="val" id="stat-edges">0</span></div>
101
+
102
+ <div class="legend">
103
+ <div class="legend-item"><div class="dot" style="background: var(--critical)"></div> Critical (>10 dependents)</div>
104
+ <div class="legend-item"><div class="dot" style="background: var(--high)"></div> High (5-10 dependents)</div>
105
+ <div class="legend-item"><div class="dot" style="background: var(--medium)"></div> Medium (2-4 dependents)</div>
106
+ <div class="legend-item"><div class="dot" style="background: var(--low)"></div> Low (0-1 dependents)</div>
107
+ </div>
108
+
109
+ <div id="node-details">
110
+ <h2 id="nd-title">file.js</h2>
111
+ <div class="detail-row">Risk Score: <span id="nd-risk" class="badge">Low</span></div>
112
+ <div class="detail-row">Blast Radius: <span id="nd-blast" style="color:white;font-weight:bold">0</span> files</div>
113
+ <div class="detail-row" style="margin-top:10px">Imports:</div>
114
+ <ul id="nd-imports"></ul>
115
+ <div class="detail-row">Dependents:</div>
116
+ <ul id="nd-dependents"></ul>
117
+ </div>
118
+ </div>
119
+
120
+ <script>
121
+ const rawData = JSON.parse(decodeURIComponent("${encodeURIComponent(cacheData)}"));
122
+
123
+ const nodes = [];
124
+ const edges = [];
125
+ const nodeMap = new Map();
126
+
127
+ // Build Nodes
128
+ Object.keys(rawData).forEach(file => {
129
+ const info = rawData[file];
130
+ const node = {
131
+ id: file,
132
+ imports: info.imports || [],
133
+ dependents: info.dependents || [],
134
+ riskScore: info.riskScore || 'Low',
135
+ blastRadius: info.blastRadius || 0,
136
+ x: Math.random() * window.innerWidth,
137
+ y: Math.random() * window.innerHeight,
138
+ vx: 0,
139
+ vy: 0,
140
+ radius: Math.min(20, Math.max(5, 5 + (info.blastRadius * 1.5)))
141
+ };
142
+
143
+ if (node.riskScore === 'Critical') node.color = '#ef4444';
144
+ else if (node.riskScore === 'High') node.color = '#f97316';
145
+ else if (node.riskScore === 'Medium') node.color = '#eab308';
146
+ else node.color = '#3b82f6';
147
+
148
+ nodes.push(node);
149
+ nodeMap.set(file, node);
150
+ });
151
+
152
+ // Build Edges
153
+ nodes.forEach(node => {
154
+ node.imports.forEach(imp => {
155
+ if (imp.startsWith('.')) {
156
+ // Try to resolve
157
+ const dir = node.id.split('/').slice(0, -1).join('/');
158
+ let resolved = dir ? dir + '/' + imp.replace('./', '') : imp.replace('./', '');
159
+
160
+ // Normalize standard paths relative to array
161
+ let target = nodes.find(n => n.id === resolved || n.id === resolved + '.js' || n.id === resolved + '.ts');
162
+ if (target) {
163
+ edges.push({ source: node, target: target });
164
+ }
165
+ }
166
+ });
167
+ });
168
+
169
+ document.getElementById('stat-nodes').innerText = nodes.length;
170
+ document.getElementById('stat-edges').innerText = edges.length;
171
+
172
+ // Force Directed Graph Simulation
173
+ const canvas = document.getElementById('graph');
174
+ const ctx = canvas.getContext('2d');
175
+
176
+ function resize() {
177
+ canvas.width = window.innerWidth;
178
+ canvas.height = window.innerHeight;
179
+ }
180
+ window.addEventListener('resize', resize);
181
+ resize();
182
+
183
+ let hoveredNode = null;
184
+ let selectedNode = null;
185
+ let isDragging = false;
186
+
187
+ // Physics constants
188
+ const REPULSION = 2000;
189
+ const SPRING_LENGTH = 100;
190
+ const SPRING_STRENGTH = 0.05;
191
+ const DAMPING = 0.85;
192
+
193
+ function simulate() {
194
+ // Repulsion
195
+ for (let i = 0; i < nodes.length; i++) {
196
+ for (let j = i + 1; j < nodes.length; j++) {
197
+ const n1 = nodes[i];
198
+ const n2 = nodes[j];
199
+ const dx = n2.x - n1.x;
200
+ const dy = n2.y - n1.y;
201
+ let dist = Math.sqrt(dx*dx + dy*dy) || 1;
202
+ if (dist < 300) {
203
+ const force = REPULSION / (dist * dist);
204
+ const fx = (dx / dist) * force;
205
+ const fy = (dy / dist) * force;
206
+ n1.vx -= fx;
207
+ n1.vy -= fy;
208
+ n2.vx += fx;
209
+ n2.vy += fy;
210
+ }
211
+ }
212
+ }
213
+
214
+ // Attraction (Springs)
215
+ edges.forEach(edge => {
216
+ const dx = edge.target.x - edge.source.x;
217
+ const dy = edge.target.y - edge.source.y;
218
+ const dist = Math.sqrt(dx*dx + dy*dy) || 1;
219
+ const force = (dist - SPRING_LENGTH) * SPRING_STRENGTH;
220
+ const fx = (dx / dist) * force;
221
+ const fy = (dy / dist) * force;
222
+
223
+ edge.source.vx += fx;
224
+ edge.source.vy += fy;
225
+ edge.target.vx -= fx;
226
+ edge.target.vy -= fy;
227
+ });
228
+
229
+ // Center gravity
230
+ const cx = canvas.width / 2;
231
+ const cy = canvas.height / 2;
232
+ nodes.forEach(n => {
233
+ n.vx += (cx - n.x) * 0.01;
234
+ n.vy += (cy - n.y) * 0.01;
235
+ });
236
+
237
+ // Update positions
238
+ nodes.forEach(n => {
239
+ if (n === selectedNode && isDragging) return; // don't move dragged node
240
+ n.vx *= DAMPING;
241
+ n.vy *= DAMPING;
242
+ n.x += n.vx;
243
+ n.y += n.vy;
244
+ });
245
+ }
246
+
247
+ function draw() {
248
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
249
+
250
+ // Draw edges
251
+ ctx.lineWidth = 1;
252
+ edges.forEach(edge => {
253
+ let isHighlighted = false;
254
+ if (hoveredNode) {
255
+ isHighlighted = (edge.source === hoveredNode || edge.target === hoveredNode);
256
+ } else if (selectedNode) {
257
+ isHighlighted = (edge.source === selectedNode || edge.target === selectedNode);
258
+ }
259
+
260
+ if (hoveredNode || selectedNode) {
261
+ ctx.strokeStyle = isHighlighted ? 'rgba(255,255,255,0.8)' : 'rgba(255,255,255,0.05)';
262
+ ctx.lineWidth = isHighlighted ? 2 : 1;
263
+ } else {
264
+ ctx.strokeStyle = 'rgba(255,255,255,0.15)';
265
+ ctx.lineWidth = 1;
266
+ }
267
+
268
+ ctx.beginPath();
269
+ ctx.moveTo(edge.source.x, edge.source.y);
270
+ ctx.lineTo(edge.target.x, edge.target.y);
271
+ ctx.stroke();
272
+ });
273
+
274
+ // Draw nodes
275
+ nodes.forEach(n => {
276
+ let opacity = 1;
277
+ if (hoveredNode && n !== hoveredNode && !edges.some(e => (e.source===hoveredNode && e.target===n) || (e.target===hoveredNode && e.source===n))) {
278
+ opacity = 0.2;
279
+ } else if (selectedNode && !hoveredNode && n !== selectedNode && !edges.some(e => (e.source===selectedNode && e.target===n) || (e.target===selectedNode && e.source===n))) {
280
+ opacity = 0.2;
281
+ }
282
+
283
+ ctx.beginPath();
284
+ ctx.arc(n.x, n.y, n.radius, 0, Math.PI * 2);
285
+ ctx.fillStyle = n.color;
286
+ ctx.globalAlpha = opacity;
287
+ ctx.fill();
288
+
289
+ if (n === hoveredNode || n === selectedNode) {
290
+ ctx.strokeStyle = '#fff';
291
+ ctx.lineWidth = 2;
292
+ ctx.stroke();
293
+
294
+ ctx.globalAlpha = 1;
295
+ ctx.fillStyle = '#fff';
296
+ ctx.font = '12px system-ui';
297
+ ctx.fillText(n.id.split('/').pop(), n.x + n.radius + 5, n.y + 4);
298
+ }
299
+ ctx.globalAlpha = 1;
300
+ });
301
+ }
302
+
303
+ function loop() {
304
+ simulate();
305
+ draw();
306
+ requestAnimationFrame(loop);
307
+ }
308
+ loop();
309
+
310
+ // Interaction
311
+ canvas.addEventListener('mousemove', e => {
312
+ const rect = canvas.getBoundingClientRect();
313
+ const mx = e.clientX - rect.left;
314
+ const my = e.clientY - rect.top;
315
+
316
+ if (isDragging && selectedNode) {
317
+ selectedNode.x = mx;
318
+ selectedNode.y = my;
319
+ return;
320
+ }
321
+
322
+ hoveredNode = null;
323
+ for (let i = nodes.length - 1; i >= 0; i--) {
324
+ const n = nodes[i];
325
+ const dx = mx - n.x;
326
+ const dy = my - n.y;
327
+ if (dx*dx + dy*dy < (n.radius + 5)**2) {
328
+ hoveredNode = n;
329
+ break;
330
+ }
331
+ }
332
+ canvas.style.cursor = hoveredNode ? 'pointer' : 'default';
333
+ });
334
+
335
+ canvas.addEventListener('mousedown', e => {
336
+ if (hoveredNode) {
337
+ selectedNode = hoveredNode;
338
+ isDragging = true;
339
+ showDetails(selectedNode);
340
+ } else {
341
+ selectedNode = null;
342
+ document.getElementById('node-details').style.display = 'none';
343
+ }
344
+ });
345
+
346
+ canvas.addEventListener('mouseup', () => { isDragging = false; });
347
+
348
+ function showDetails(n) {
349
+ const panel = document.getElementById('node-details');
350
+ panel.style.display = 'block';
351
+ document.getElementById('nd-title').innerText = n.id;
352
+
353
+ const riskEl = document.getElementById('nd-risk');
354
+ riskEl.innerText = n.riskScore;
355
+ riskEl.style.backgroundColor = n.color;
356
+
357
+ document.getElementById('nd-blast').innerText = n.blastRadius;
358
+
359
+ const importsUl = document.getElementById('nd-imports');
360
+ importsUl.innerHTML = '';
361
+ n.imports.forEach(i => {
362
+ const li = document.createElement('li');
363
+ li.innerText = i;
364
+ importsUl.appendChild(li);
365
+ });
366
+ if(n.imports.length===0) importsUl.innerHTML = '<li>None</li>';
367
+
368
+ const depsUl = document.getElementById('nd-dependents');
369
+ depsUl.innerHTML = '';
370
+ n.dependents.forEach(d => {
371
+ const li = document.createElement('li');
372
+ li.innerText = d;
373
+ depsUl.appendChild(li);
374
+ });
375
+ if(n.dependents.length===0) depsUl.innerHTML = '<li>None</li>';
376
+ }
377
+ </script>
378
+ </body>
379
+ </html>`;
380
+
381
+ fs.writeFileSync(HTML_FILE, htmlContent);
382
+ console.log(`${GREEN}✔ Interactive visualizer generated.${RESET}`);
383
+ console.log(` ${DIM}Saved to: ${HTML_FILE}${RESET}`);
384
+ }
385
+
386
+ module.exports = { main };
387
+
388
+ if (require.main === module) {
389
+ main();
390
+ }