dev-guru 0.1.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.
- dev_guru/__init__.py +21 -0
- dev_guru/__main__.py +3 -0
- dev_guru/cli.py +149 -0
- dev_guru/client/__init__.py +22 -0
- dev_guru/client/inprocess.py +122 -0
- dev_guru/client/negotiation.py +69 -0
- dev_guru/client/port.py +87 -0
- dev_guru/errors.py +44 -0
- dev_guru/reports/__init__.py +1 -0
- dev_guru/reports/assets/explorer.css +218 -0
- dev_guru/reports/assets/explorer.html +75 -0
- dev_guru/reports/assets/explorer.js +822 -0
- dev_guru/reports/model.py +264 -0
- dev_guru/reports/render.py +137 -0
- dev_guru/sdk.py +56 -0
- dev_guru/service.py +53 -0
- dev_guru/version.py +3 -0
- dev_guru-0.1.0.dist-info/METADATA +113 -0
- dev_guru-0.1.0.dist-info/RECORD +22 -0
- dev_guru-0.1.0.dist-info/WHEEL +4 -0
- dev_guru-0.1.0.dist-info/entry_points.txt +2 -0
- dev_guru-0.1.0.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,822 @@
|
|
|
1
|
+
/* Dev Guru explorer. Offline and view-only: reads the embedded view model, never fetches, never executes.
|
|
2
|
+
Untrusted text (paths, names, docs, source) is only ever assigned through textContent or attributes. */
|
|
3
|
+
(() => {
|
|
4
|
+
"use strict";
|
|
5
|
+
const D = JSON.parse(document.getElementById("dg-data").textContent);
|
|
6
|
+
const M = JSON.parse(document.getElementById("dg-manifest").textContent);
|
|
7
|
+
const $ = (s) => document.querySelector(s);
|
|
8
|
+
const NS = "http://www.w3.org/2000/svg";
|
|
9
|
+
const reduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
10
|
+
|
|
11
|
+
function el(tag, attrs, ...kids) {
|
|
12
|
+
const n = document.createElement(tag);
|
|
13
|
+
for (const [k, v] of Object.entries(attrs || {})) {
|
|
14
|
+
if (v === undefined || v === null || v === false) continue;
|
|
15
|
+
if (k === "text") n.textContent = String(v);
|
|
16
|
+
else if (k === "class") n.className = v;
|
|
17
|
+
else if (k.startsWith("on")) n.addEventListener(k.slice(2), v);
|
|
18
|
+
else n.setAttribute(k, v === true ? "" : String(v));
|
|
19
|
+
}
|
|
20
|
+
for (const kid of kids.flat()) if (kid !== null && kid !== undefined && kid !== false) n.append(kid instanceof Node ? kid : document.createTextNode(String(kid)));
|
|
21
|
+
return n;
|
|
22
|
+
}
|
|
23
|
+
function sv(tag, attrs) {
|
|
24
|
+
const n = document.createElementNS(NS, tag);
|
|
25
|
+
for (const [k, v] of Object.entries(attrs || {})) {
|
|
26
|
+
if (v === undefined || v === null) continue;
|
|
27
|
+
if (k === "text") n.textContent = String(v);
|
|
28
|
+
else if (k.startsWith("on")) n.addEventListener(k.slice(2), v);
|
|
29
|
+
else n.setAttribute(k, String(v));
|
|
30
|
+
}
|
|
31
|
+
return n;
|
|
32
|
+
}
|
|
33
|
+
const fmt = (n) => Number(n).toLocaleString("en");
|
|
34
|
+
const short = (p) => (p.length > 34 ? "…" + p.slice(-33) : p);
|
|
35
|
+
|
|
36
|
+
// ------------------------------------------------------------------ indices
|
|
37
|
+
const files = new Map(D.files.map((f) => [f.id, f]));
|
|
38
|
+
const syms = new Map(D.symbols.map((s) => [s.id, s]));
|
|
39
|
+
const nodeOf = (id) => files.get(id) || syms.get(id);
|
|
40
|
+
const fileOf = (id) => (files.has(id) ? id : syms.get(id)?.file || null);
|
|
41
|
+
const out = new Map(), inn = new Map(), callOut = new Map(), callIn = new Map(), inhOut = new Map(), inhIn = new Map();
|
|
42
|
+
const push = (m, k, v) => { if (!m.has(k)) m.set(k, new Set()); m.get(k).add(v); };
|
|
43
|
+
for (const e of D.edges) {
|
|
44
|
+
if (e.k === "imports") { push(out, e.s, e.t); push(inn, e.t, e.s); }
|
|
45
|
+
else if (e.k === "calls") { push(callOut, e.s, e.t); push(callIn, e.t, e.s); }
|
|
46
|
+
else if (e.k === "inherits") { push(inhOut, e.s, e.t); push(inhIn, e.t, e.s); }
|
|
47
|
+
}
|
|
48
|
+
const get = (m, k) => [...(m.get(k) || [])];
|
|
49
|
+
const PALETTE = ["#ffb347", "#3dd6c6", "#9b87ff", "#ff6f91", "#b7ef6a", "#6cc3ff", "#ffd36e", "#ff9ec7", "#7ee0a1", "#c79bff"];
|
|
50
|
+
const pkgIndex = new Map(D.packages.map((p, i) => [p.id, i]));
|
|
51
|
+
const colorOf = (fid) => PALETTE[(pkgIndex.get(files.get(fid)?.package) ?? 0) % PALETTE.length];
|
|
52
|
+
const cycleFiles = new Set(D.insights.cycles.flat());
|
|
53
|
+
const cyclePairs = new Set();
|
|
54
|
+
for (const cyc of D.insights.cycles) for (const a of cyc) for (const b of get(out, a)) if (cyc.includes(b)) cyclePairs.add(a + "→" + b);
|
|
55
|
+
|
|
56
|
+
// ------------------------------------------------------------------ state (shareable through the URL hash)
|
|
57
|
+
const state = { view: "constellation", sel: null, filters: { imports: true, calls: true, inherits: true }, tour: 0, playing: !reduced };
|
|
58
|
+
try {
|
|
59
|
+
const h = new URLSearchParams(location.hash.slice(1));
|
|
60
|
+
if (h.get("view")) state.view = h.get("view");
|
|
61
|
+
if (h.get("sel") && nodeOf(h.get("sel"))) state.sel = h.get("sel");
|
|
62
|
+
if (h.get("theme")) document.documentElement.dataset.theme = h.get("theme") === "day" ? "day" : "night";
|
|
63
|
+
if (h.get("embed") === "1") document.documentElement.classList.add("embed"); // framed in a page: just tabs and stage
|
|
64
|
+
} catch (_) { /* ignore a malformed hash */ }
|
|
65
|
+
function syncHash() {
|
|
66
|
+
const p = new URLSearchParams();
|
|
67
|
+
p.set("view", state.view);
|
|
68
|
+
if (state.sel) p.set("sel", state.sel);
|
|
69
|
+
if (document.documentElement.dataset.theme === "day") p.set("theme", "day");
|
|
70
|
+
if (document.documentElement.classList.contains("embed")) p.set("embed", "1");
|
|
71
|
+
try { history.replaceState(null, "", "#" + p.toString()); } catch (_) { /* file:// in some browsers */ }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// ------------------------------------------------------------------ SVG stage with pan and zoom
|
|
75
|
+
const svg = $("#svg");
|
|
76
|
+
let world, cam = { x: 0, y: 0, k: 1 };
|
|
77
|
+
function resetStage() {
|
|
78
|
+
svg.replaceChildren();
|
|
79
|
+
const defs = sv("defs");
|
|
80
|
+
const glow = sv("filter", { id: "glow", x: "-50%", y: "-50%", width: "200%", height: "200%" });
|
|
81
|
+
glow.append(sv("feGaussianBlur", { stdDeviation: "6" }));
|
|
82
|
+
defs.append(glow);
|
|
83
|
+
for (const [id, color] of [["arrow", "var(--muted)"], ["arrowHot", "var(--saffron)"]]) {
|
|
84
|
+
const m = sv("marker", { id, viewBox: "0 0 10 10", refX: "9", refY: "5", markerWidth: "6", markerHeight: "6", orient: "auto-start-reverse" });
|
|
85
|
+
m.append(sv("path", { d: "M0,0 L10,5 L0,10 z", fill: color }));
|
|
86
|
+
defs.append(m);
|
|
87
|
+
}
|
|
88
|
+
svg.append(defs);
|
|
89
|
+
world = sv("g", { class: "world" });
|
|
90
|
+
svg.append(world);
|
|
91
|
+
svg.classList.remove("dim");
|
|
92
|
+
applyCam();
|
|
93
|
+
}
|
|
94
|
+
const applyCam = () => world && world.setAttribute("transform", `translate(${cam.x},${cam.y}) scale(${cam.k})`);
|
|
95
|
+
function fit(pad = 40, box) {
|
|
96
|
+
if (!world) return;
|
|
97
|
+
const b = box || world.getBBox();
|
|
98
|
+
const w = svg.clientWidth || 800, h = svg.clientHeight || 600;
|
|
99
|
+
if (!b.width || !b.height) { cam = { x: w / 2, y: h / 2, k: 1 }; applyCam(); return; }
|
|
100
|
+
const k = Math.min((w - pad * 2) / b.width, (h - pad * 2) / b.height, 2.2);
|
|
101
|
+
cam = { k, x: w / 2 - (b.x + b.width / 2) * k, y: h / 2 - (b.y + b.height / 2) * k };
|
|
102
|
+
animateCam();
|
|
103
|
+
}
|
|
104
|
+
let camAnim = null;
|
|
105
|
+
function animateCam() {
|
|
106
|
+
if (reduced) return applyCam();
|
|
107
|
+
const from = parseCam(), to = { ...cam }, t0 = performance.now(), dur = 520;
|
|
108
|
+
cancelAnimationFrame(camAnim);
|
|
109
|
+
const step = (t) => {
|
|
110
|
+
const p = Math.min(1, (t - t0) / dur), e = 1 - Math.pow(1 - p, 3);
|
|
111
|
+
world.setAttribute("transform", `translate(${from.x + (to.x - from.x) * e},${from.y + (to.y - from.y) * e}) scale(${from.k + (to.k - from.k) * e})`);
|
|
112
|
+
if (p < 1) camAnim = requestAnimationFrame(step);
|
|
113
|
+
};
|
|
114
|
+
camAnim = requestAnimationFrame(step);
|
|
115
|
+
}
|
|
116
|
+
function parseCam() {
|
|
117
|
+
const m = /translate\(([-\d.e]+),([-\d.e]+)\) scale\(([-\d.e]+)\)/.exec(world?.getAttribute("transform") || "");
|
|
118
|
+
return m ? { x: +m[1], y: +m[2], k: +m[3] } : { ...cam };
|
|
119
|
+
}
|
|
120
|
+
function zoomBy(f, cx, cy) {
|
|
121
|
+
const w = svg.clientWidth, h = svg.clientHeight;
|
|
122
|
+
cx = cx ?? w / 2; cy = cy ?? h / 2;
|
|
123
|
+
const k = Math.max(0.08, Math.min(6, cam.k * f));
|
|
124
|
+
cam.x = cx - ((cx - cam.x) * k) / cam.k; cam.y = cy - ((cy - cam.y) * k) / cam.k; cam.k = k;
|
|
125
|
+
applyCam();
|
|
126
|
+
}
|
|
127
|
+
svg.addEventListener("wheel", (e) => { e.preventDefault(); const r = svg.getBoundingClientRect(); zoomBy(e.deltaY < 0 ? 1.12 : 1 / 1.12, e.clientX - r.left, e.clientY - r.top); }, { passive: false });
|
|
128
|
+
let drag = null;
|
|
129
|
+
svg.addEventListener("pointerdown", (e) => { if (e.button !== 0) return; drag = { x: e.clientX, y: e.clientY, cx: cam.x, cy: cam.y, moved: false }; svg.setPointerCapture(e.pointerId); });
|
|
130
|
+
svg.addEventListener("pointermove", (e) => {
|
|
131
|
+
if (!drag) return;
|
|
132
|
+
const dx = e.clientX - drag.x, dy = e.clientY - drag.y;
|
|
133
|
+
if (Math.abs(dx) + Math.abs(dy) > 4) { drag.moved = true; svg.classList.add("dragging"); }
|
|
134
|
+
if (drag.moved) { cam.x = drag.cx + dx; cam.y = drag.cy + dy; applyCam(); }
|
|
135
|
+
});
|
|
136
|
+
svg.addEventListener("pointerup", () => { svg.classList.remove("dragging"); setTimeout(() => (drag = null), 0); });
|
|
137
|
+
$("#zoomIn").onclick = () => zoomBy(1.25);
|
|
138
|
+
$("#zoomOut").onclick = () => zoomBy(1 / 1.25);
|
|
139
|
+
$("#fitBtn").onclick = () => fit();
|
|
140
|
+
|
|
141
|
+
// pulses that travel along highlighted paths
|
|
142
|
+
let pulseTimer = null;
|
|
143
|
+
function pulses(paths) {
|
|
144
|
+
cancelAnimationFrame(pulseTimer);
|
|
145
|
+
world?.querySelectorAll(".pulse").forEach((p) => p.remove());
|
|
146
|
+
if (reduced || !paths.length) return;
|
|
147
|
+
const dots = paths.slice(0, 60).map((p, i) => ({ p, len: p.getTotalLength(), off: (i * 0.17) % 1, c: world.appendChild(sv("circle", { r: 3, class: "pulse" })) }));
|
|
148
|
+
const t0 = performance.now();
|
|
149
|
+
const step = (t) => {
|
|
150
|
+
for (const d of dots) {
|
|
151
|
+
if (!d.c.isConnected) return;
|
|
152
|
+
const f = ((t - t0) / 1400 + d.off) % 1, pt = d.p.getPointAtLength(f * d.len);
|
|
153
|
+
d.c.setAttribute("cx", pt.x); d.c.setAttribute("cy", pt.y); d.c.setAttribute("opacity", Math.sin(f * Math.PI));
|
|
154
|
+
}
|
|
155
|
+
pulseTimer = requestAnimationFrame(step);
|
|
156
|
+
};
|
|
157
|
+
pulseTimer = requestAnimationFrame(step);
|
|
158
|
+
}
|
|
159
|
+
const curve = (a, b, bend = 0.18) => {
|
|
160
|
+
const mx = (a.x + b.x) / 2, my = (a.y + b.y) / 2, dx = b.x - a.x, dy = b.y - a.y;
|
|
161
|
+
return `M${a.x},${a.y} Q${mx - dy * bend},${my + dx * bend} ${b.x},${b.y}`;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// ------------------------------------------------------------------ constellation layout (deterministic)
|
|
165
|
+
let constellation = null;
|
|
166
|
+
function layoutConstellation() {
|
|
167
|
+
if (constellation) return constellation;
|
|
168
|
+
const pos = new Map(), radius = new Map(), centers = [];
|
|
169
|
+
const GOLD = Math.PI * (3 - Math.sqrt(5));
|
|
170
|
+
// 1. each package: files on a sunflower around its own origin, then separate any overlaps locally
|
|
171
|
+
const local = new Map();
|
|
172
|
+
for (const p of D.packages) {
|
|
173
|
+
const ids = [...p.files].sort((x, y) => (files.get(y).loc - files.get(x).loc) || x.localeCompare(y));
|
|
174
|
+
ids.forEach((fid) => radius.set(fid, Math.max(4.5, Math.min(22, 3 + Math.sqrt(files.get(fid).loc || 1) * 0.8))));
|
|
175
|
+
const mean = ids.reduce((s, f) => s + radius.get(f), 0) / ids.length;
|
|
176
|
+
const pts = ids.map((fid, j) => ({ fid, x: Math.cos(j * GOLD) * (mean * 2 + 8) * 0.62 * Math.sqrt(j), y: Math.sin(j * GOLD) * (mean * 2 + 8) * 0.62 * Math.sqrt(j) }));
|
|
177
|
+
if (pts.length <= 400) for (let it = 0; it < 30; it++) {
|
|
178
|
+
for (let i = 0; i < pts.length; i++) for (let j = i + 1; j < pts.length; j++) {
|
|
179
|
+
const a = pts[i], b = pts[j], min = radius.get(a.fid) + radius.get(b.fid) + 5;
|
|
180
|
+
let dx = b.x - a.x, dy = b.y - a.y, d = Math.hypot(dx, dy);
|
|
181
|
+
if (d < min) { if (d < 0.01) { dx = 0.6; dy = 0.8; d = 1; } const k = (min - d) / 2 / d; a.x -= dx * k; a.y -= dy * k; b.x += dx * k; b.y += dy * k; }
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const R = Math.max(26, ...pts.map((q) => Math.hypot(q.x, q.y) + radius.get(q.fid))) + 16;
|
|
185
|
+
local.set(p.id, { pts, R });
|
|
186
|
+
}
|
|
187
|
+
// 2. pack packages largest-first along a spiral, never overlapping
|
|
188
|
+
const order = [...D.packages].sort((a, b) => local.get(b.id).R - local.get(a.id).R || a.id.localeCompare(b.id));
|
|
189
|
+
for (const p of order) {
|
|
190
|
+
const R = local.get(p.id).R;
|
|
191
|
+
let x = 0, y = 0;
|
|
192
|
+
if (centers.length) {
|
|
193
|
+
for (let s = 0, a = 0, d = 0; s < 20000; s++, a += 0.32, d += 1.4) {
|
|
194
|
+
x = Math.cos(a) * d; y = Math.sin(a) * d * 0.82;
|
|
195
|
+
if (centers.every((c) => Math.hypot(c.x - x, c.y - y) >= c.r + R + 12)) break;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
centers.push({ id: p.id, x, y, r: R });
|
|
199
|
+
for (const q of local.get(p.id).pts) pos.set(q.fid, { x: x + q.x, y: y + q.y });
|
|
200
|
+
}
|
|
201
|
+
constellation = { pos, radius, centers };
|
|
202
|
+
return constellation;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function drawConstellation({ highlight } = {}) {
|
|
206
|
+
resetStage();
|
|
207
|
+
const { pos, radius, centers } = layoutConstellation();
|
|
208
|
+
const gp = sv("g"), ge = sv("g"), gn = sv("g");
|
|
209
|
+
world.append(gp, ge, gn);
|
|
210
|
+
const bigR = [...centers].sort((a, b) => b.r - a.r)[Math.min(11, centers.length - 1)]?.r ?? 0;
|
|
211
|
+
for (const c of centers) {
|
|
212
|
+
gp.append(sv("circle", { class: "pkg-halo", cx: c.x, cy: c.y, r: c.r }));
|
|
213
|
+
if (c.r >= bigR || centers.length <= 12) gp.append(sv("text", { class: "pkg-label", x: c.x, y: c.y - c.r - 6, "text-anchor": "middle", text: c.id === "." ? "(root)" : c.id.split("/").slice(-2).join("/") }));
|
|
214
|
+
}
|
|
215
|
+
const edgeEls = [];
|
|
216
|
+
if (state.filters.imports) for (const e of D.edges) {
|
|
217
|
+
if (e.k !== "imports") continue;
|
|
218
|
+
const a = pos.get(e.s), b = pos.get(e.t);
|
|
219
|
+
if (!a || !b) continue;
|
|
220
|
+
const path = sv("path", { class: "edge imports" + (cyclePairs.has(e.s + "→" + e.t) ? " cycle" : ""), d: curve(a, b), "marker-end": "url(#arrow)" });
|
|
221
|
+
path.dataset.s = e.s; path.dataset.t = e.t;
|
|
222
|
+
ge.append(path); edgeEls.push(path);
|
|
223
|
+
}
|
|
224
|
+
const nodeEls = new Map();
|
|
225
|
+
for (const f of D.files) {
|
|
226
|
+
const p = pos.get(f.id), r = radius.get(f.id), color = colorOf(f.id);
|
|
227
|
+
const g = sv("g", { class: "node", transform: `translate(${p.x},${p.y})`, tabindex: "-1" });
|
|
228
|
+
g.append(sv("circle", { class: "halo", r: r + 7, fill: color, filter: "url(#glow)" }));
|
|
229
|
+
g.append(sv("circle", { class: "core", r, fill: color }));
|
|
230
|
+
if (r > 9 || f.entry || f.fan_in >= 3) g.append(sv("text", { x: r + 4, y: 4, text: f.name }));
|
|
231
|
+
g.dataset.id = f.id;
|
|
232
|
+
g.addEventListener("mouseenter", () => hoverFile(f.id));
|
|
233
|
+
g.addEventListener("mouseleave", () => hoverFile(null));
|
|
234
|
+
g.addEventListener("click", () => { if (!drag?.moved) select(f.id); });
|
|
235
|
+
gn.append(g); nodeEls.set(f.id, g);
|
|
236
|
+
}
|
|
237
|
+
function hoverFile(fid) {
|
|
238
|
+
const focus = fid || (state.sel && fileOf(state.sel)) || highlight;
|
|
239
|
+
svg.classList.toggle("dim", !!focus);
|
|
240
|
+
nodeEls.forEach((g) => g.classList.remove("hot"));
|
|
241
|
+
edgeEls.forEach((p) => p.classList.remove("hot"));
|
|
242
|
+
if (!focus) { pulses([]); return; }
|
|
243
|
+
const near = new Set([focus, ...get(out, focus), ...get(inn, focus)]);
|
|
244
|
+
near.forEach((id) => nodeEls.get(id)?.classList.add("hot"));
|
|
245
|
+
const hot = edgeEls.filter((p) => p.dataset.s === focus || p.dataset.t === focus);
|
|
246
|
+
hot.forEach((p) => p.classList.add("hot"));
|
|
247
|
+
pulses(hot);
|
|
248
|
+
$("#hint").textContent = `${files.get(focus).path} · imports ${get(out, focus).length} · imported by ${get(inn, focus).length}`;
|
|
249
|
+
}
|
|
250
|
+
const selFile = state.sel && fileOf(state.sel);
|
|
251
|
+
if (selFile) nodeEls.get(selFile)?.classList.add("selected");
|
|
252
|
+
hoverFile(null);
|
|
253
|
+
legend([["imports", "rgba(155,135,255,.7)", "import"], ["cycle", "var(--rose)", "import cycle"], ["dot", "", "size = lines · colour = package"]]);
|
|
254
|
+
return { pos, nodeEls };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// ------------------------------------------------------------------ flow: layered dependency map
|
|
258
|
+
function drawFlow() {
|
|
259
|
+
resetStage();
|
|
260
|
+
if (state.flowLevel === undefined) state.flowLevel = D.files.length > 120 ? "packages" : "files";
|
|
261
|
+
if (state.flowLevel === "packages") return drawPackageFlow();
|
|
262
|
+
const nodes = D.files.filter((f) => get(out, f.id).length || get(inn, f.id).length).map((f) => f.id);
|
|
263
|
+
if (!nodes.length) return emptyStage("No imports between workspace files", "Every file stands alone, so there's no flow to draw.");
|
|
264
|
+
// break cycles with a DFS, then longest-path layering from the importers' side
|
|
265
|
+
const color = new Map(), back = new Set(), order = [];
|
|
266
|
+
const visit = (u) => {
|
|
267
|
+
color.set(u, 1);
|
|
268
|
+
for (const v of get(out, u).sort()) { if (color.get(v) === 1) back.add(u + "→" + v); else if (!color.get(v)) visit(v); }
|
|
269
|
+
color.set(u, 2); order.push(u);
|
|
270
|
+
};
|
|
271
|
+
nodes.sort().forEach((n) => !color.get(n) && visit(n));
|
|
272
|
+
const layer = new Map();
|
|
273
|
+
for (const u of order) { // sinks first: layer = 1 + max(layer of what u imports)
|
|
274
|
+
let L = 0;
|
|
275
|
+
for (const v of get(out, u)) if (!back.has(u + "→" + v)) L = Math.max(L, (layer.get(v) ?? 0) + 1);
|
|
276
|
+
layer.set(u, L);
|
|
277
|
+
}
|
|
278
|
+
const maxL = Math.max(...layer.values());
|
|
279
|
+
const cols = [];
|
|
280
|
+
for (const [id, L] of layer) (cols[maxL - L] ||= []).push(id);
|
|
281
|
+
for (const c of cols) c.sort((a, b) => files.get(a).package.localeCompare(files.get(b).package) || a.localeCompare(b));
|
|
282
|
+
const y = new Map();
|
|
283
|
+
const place = () => cols.forEach((c) => c.forEach((id, i) => y.set(id, i)));
|
|
284
|
+
place();
|
|
285
|
+
for (let sweep = 0; sweep < 4; sweep++) { // barycentre ordering reduces crossings
|
|
286
|
+
cols.forEach((c, ci) => {
|
|
287
|
+
if (!ci) return;
|
|
288
|
+
const bary = (id) => { const ns = [...get(out, id), ...get(inn, id)].filter((n) => y.has(n)); return ns.length ? ns.reduce((s, n) => s + y.get(n), 0) / ns.length : y.get(id); };
|
|
289
|
+
c.sort((a, b) => bary(a) - bary(b) || a.localeCompare(b));
|
|
290
|
+
});
|
|
291
|
+
place();
|
|
292
|
+
}
|
|
293
|
+
const W = 210, H = 34, GX = 110, GY = 14;
|
|
294
|
+
const pos = new Map();
|
|
295
|
+
cols.forEach((c, ci) => c.forEach((id, i) => pos.set(id, { x: ci * (W + GX), y: i * (H + GY) })));
|
|
296
|
+
const ge = sv("g"), gn = sv("g");
|
|
297
|
+
world.append(ge, gn);
|
|
298
|
+
cols.forEach((c, ci) => world.insertBefore(sv("text", { class: "lane-label", x: ci * (W + GX), y: -16, text: ci === 0 ? "entry side" : ci === cols.length - 1 ? "foundations" : `layer ${ci + 1}` }), ge));
|
|
299
|
+
const edgeEls = [];
|
|
300
|
+
for (const [s, ts] of out) for (const t of ts) {
|
|
301
|
+
const a = pos.get(s), b = pos.get(t);
|
|
302
|
+
if (!a || !b) continue;
|
|
303
|
+
const cyc = back.has(s + "→" + t) || cyclePairs.has(s + "→" + t);
|
|
304
|
+
const x1 = a.x + W, y1 = a.y + H / 2, x2 = b.x, y2 = b.y + H / 2, dx = Math.max(40, Math.abs(x2 - x1) / 2);
|
|
305
|
+
const d = x2 > x1 ? `M${x1},${y1} C${x1 + dx},${y1} ${x2 - dx},${y2} ${x2},${y2}` : `M${a.x},${y1} C${a.x - 80},${y1 - 60} ${b.x + W + 80},${y2 - 60} ${b.x + W},${y2}`;
|
|
306
|
+
const p = sv("path", { class: "edge imports" + (cyc ? " cycle" : ""), d, "marker-end": "url(#arrow)" });
|
|
307
|
+
p.dataset.s = s; p.dataset.t = t;
|
|
308
|
+
ge.append(p); edgeEls.push(p);
|
|
309
|
+
}
|
|
310
|
+
const boxes = new Map();
|
|
311
|
+
for (const [id, p] of pos) {
|
|
312
|
+
const f = files.get(id);
|
|
313
|
+
const g = sv("g", { class: "node box", transform: `translate(${p.x},${p.y})` });
|
|
314
|
+
g.append(sv("rect", { width: W, height: H, rx: 10, fill: "var(--panel-solid)", stroke: colorOf(id), "stroke-width": cycleFiles.has(id) ? 2.5 : 1.2 }));
|
|
315
|
+
g.append(sv("circle", { cx: 14, cy: H / 2, r: 5, fill: colorOf(id) }));
|
|
316
|
+
g.append(sv("text", { x: 26, y: H / 2 + 4, text: short(f.path) }));
|
|
317
|
+
g.dataset.id = id;
|
|
318
|
+
g.addEventListener("mouseenter", () => hot(id));
|
|
319
|
+
g.addEventListener("mouseleave", () => hot(null));
|
|
320
|
+
g.addEventListener("click", () => { if (!drag?.moved) select(id); });
|
|
321
|
+
gn.append(g); boxes.set(id, g);
|
|
322
|
+
}
|
|
323
|
+
function hot(id) {
|
|
324
|
+
const focus = id || (state.sel && fileOf(state.sel));
|
|
325
|
+
svg.classList.toggle("dim", !!focus);
|
|
326
|
+
boxes.forEach((g) => g.classList.remove("hot")); edgeEls.forEach((p) => p.classList.remove("hot"));
|
|
327
|
+
if (!focus || !pos.has(focus)) { pulses([]); return; }
|
|
328
|
+
// everything downstream (what it depends on) and upstream (what depends on it)
|
|
329
|
+
const walk = (start, m) => { const seen = new Set([start]), q = [start]; while (q.length) for (const n of get(m, q.shift())) if (!seen.has(n)) { seen.add(n); q.push(n); } return seen; };
|
|
330
|
+
const reach = new Set([...walk(focus, out), ...walk(focus, inn)]);
|
|
331
|
+
reach.forEach((n) => boxes.get(n)?.classList.add("hot"));
|
|
332
|
+
const hotEdges = edgeEls.filter((p) => reach.has(p.dataset.s) && reach.has(p.dataset.t));
|
|
333
|
+
hotEdges.forEach((p) => p.classList.add("hot"));
|
|
334
|
+
pulses(hotEdges);
|
|
335
|
+
$("#hint").textContent = `${files.get(focus).path}: ${walk(focus, out).size - 1} downstream · ${walk(focus, inn).size - 1} upstream`;
|
|
336
|
+
}
|
|
337
|
+
hot(null);
|
|
338
|
+
const isolated = D.files.length - nodes.length;
|
|
339
|
+
legend([["imports", "rgba(155,135,255,.7)", "imports (left → right)"], ["cycle", "var(--rose)", `cycle (${D.insights.cycles.length})`], ["", "", isolated ? `${isolated} file(s) with no imports not shown` : ""]]);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function drawPackageFlow() {
|
|
343
|
+
const pkgOf = (fid) => files.get(fid).package;
|
|
344
|
+
const weight = new Map();
|
|
345
|
+
for (const [s, ts] of out) for (const t of ts) { const a = pkgOf(s), b = pkgOf(t); if (a !== b) weight.set(a + "\u0000" + b, (weight.get(a + "\u0000" + b) || 0) + 1); }
|
|
346
|
+
const pout = new Map(), pin = new Map();
|
|
347
|
+
for (const k of weight.keys()) { const [a, b] = k.split("\u0000"); push(pout, a, b); push(pin, b, a); }
|
|
348
|
+
const ids = D.packages.map((p) => p.id).filter((id) => pout.has(id) || pin.has(id));
|
|
349
|
+
if (!ids.length) return emptyStage("No imports between packages", "Each package stands alone.");
|
|
350
|
+
const color = new Map(), back = new Set(), order = [];
|
|
351
|
+
const visit = (u) => { color.set(u, 1); for (const v of get(pout, u).sort()) { if (color.get(v) === 1) back.add(u + "\u0000" + v); else if (!color.get(v)) visit(v); } color.set(u, 2); order.push(u); };
|
|
352
|
+
ids.sort().forEach((n) => !color.get(n) && visit(n));
|
|
353
|
+
const layer = new Map();
|
|
354
|
+
for (const u of order) { let L = 0; for (const v of get(pout, u)) if (!back.has(u + "\u0000" + v)) L = Math.max(L, (layer.get(v) ?? 0) + 1); layer.set(u, L); }
|
|
355
|
+
const maxL = Math.max(...layer.values()), cols = [];
|
|
356
|
+
for (const [id, L] of layer) (cols[maxL - L] ||= []).push(id);
|
|
357
|
+
cols.forEach((c) => c.sort());
|
|
358
|
+
const W = 230, H = 46, GX = 120, GY = 16, pos = new Map();
|
|
359
|
+
cols.forEach((c, ci) => c.forEach((id, i) => pos.set(id, { x: ci * (W + GX), y: i * (H + GY) - (c.length * (H + GY)) / 2 })));
|
|
360
|
+
const ge = sv("g"), gn = sv("g"); world.append(ge, gn);
|
|
361
|
+
const maxW = Math.max(...weight.values()), edgeEls = [];
|
|
362
|
+
for (const [k, w] of weight) {
|
|
363
|
+
const [s, t] = k.split("\u0000"), a = pos.get(s), b = pos.get(t);
|
|
364
|
+
if (!a || !b) continue;
|
|
365
|
+
const x1 = a.x + W, y1 = a.y + H / 2, x2 = b.x, y2 = b.y + H / 2, dx = Math.max(50, Math.abs(x2 - x1) / 2);
|
|
366
|
+
const d = x2 > x1 ? `M${x1},${y1} C${x1 + dx},${y1} ${x2 - dx},${y2} ${x2},${y2}` : `M${a.x},${y1} C${a.x - 90},${y1 - 70} ${b.x + W + 90},${y2 - 70} ${b.x + W},${y2}`;
|
|
367
|
+
const p = sv("path", { class: "edge imports" + (back.has(k) ? " cycle" : ""), d, "stroke-width": 1 + (5 * w) / maxW });
|
|
368
|
+
p.dataset.s = s; p.dataset.t = t; ge.append(p); edgeEls.push(p);
|
|
369
|
+
}
|
|
370
|
+
const boxes = new Map();
|
|
371
|
+
for (const [id, p] of pos) {
|
|
372
|
+
const pk = D.packages.find((x) => x.id === id), col = PALETTE[pkgIndex.get(id) % PALETTE.length];
|
|
373
|
+
const g = sv("g", { class: "node box", transform: `translate(${p.x},${p.y})` });
|
|
374
|
+
g.append(sv("rect", { width: W, height: H, rx: 12, fill: "var(--panel-solid)", stroke: col, "stroke-width": 1.5 }));
|
|
375
|
+
g.append(sv("text", { x: 14, y: 19, text: id === "." ? "(root)" : (id.length > 30 ? "…" + id.slice(-29) : id) }));
|
|
376
|
+
g.append(sv("text", { x: 14, y: 35, class: "sub", text: `${pk.files.length} files · → ${get(pout, id).length} · ← ${get(pin, id).length}` }));
|
|
377
|
+
g.addEventListener("mouseenter", () => hot(id)); g.addEventListener("mouseleave", () => hot(null));
|
|
378
|
+
g.addEventListener("click", () => { if (!drag?.moved) { state.flowLevel = "files"; select(pk.files[0]); } });
|
|
379
|
+
gn.append(g); boxes.set(id, g);
|
|
380
|
+
}
|
|
381
|
+
function hot(id) {
|
|
382
|
+
svg.classList.toggle("dim", !!id);
|
|
383
|
+
boxes.forEach((g) => g.classList.remove("hot")); edgeEls.forEach((p) => p.classList.remove("hot"));
|
|
384
|
+
if (!id) { pulses([]); $("#hint").textContent = `${ids.length} packages · ${weight.size} package dependencies · click a package to see its files`; return; }
|
|
385
|
+
boxes.get(id)?.classList.add("hot");
|
|
386
|
+
const hotE = edgeEls.filter((p) => p.dataset.s === id || p.dataset.t === id);
|
|
387
|
+
hotE.forEach((p) => { p.classList.add("hot"); boxes.get(p.dataset.s)?.classList.add("hot"); boxes.get(p.dataset.t)?.classList.add("hot"); });
|
|
388
|
+
pulses(hotE);
|
|
389
|
+
$("#hint").textContent = `${id}: depends on ${get(pout, id).length} packages, used by ${get(pin, id).length}`;
|
|
390
|
+
}
|
|
391
|
+
hot(null);
|
|
392
|
+
legend([["imports", "rgba(155,135,255,.7)", "package imports (thicker = more)"], ["cycle", "var(--rose)", "cycle"]]);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// ------------------------------------------------------------------ impact: blast-radius rings
|
|
396
|
+
function dependents(id) {
|
|
397
|
+
const symbolLevel = syms.has(id);
|
|
398
|
+
const methodsOf = (n) => D.symbols.filter((s) => s.kind === "method" && s.file === syms.get(n)?.file && s.name.startsWith(syms.get(n).name + ".")).map((s) => s.id);
|
|
399
|
+
const next = (n) => symbolLevel ? [...get(callIn, n), ...get(inhIn, n), ...(syms.get(n)?.kind === "class" ? methodsOf(n).flatMap((m) => get(callIn, m)) : [])].filter((x) => x !== n) : [...get(inn, n), ...new Set([...(files.get(n)?.symbols || [])].flatMap((s) => get(callIn, s)).map(fileOf).filter((f) => f && f !== n))];
|
|
400
|
+
const dist = new Map([[id, 0]]), parent = new Map(), q = [id];
|
|
401
|
+
while (q.length) { const u = q.shift(); for (const v of next(u)) if (!dist.has(v)) { dist.set(v, dist.get(u) + 1); parent.set(v, u); q.push(v); } }
|
|
402
|
+
return { dist, parent, symbolLevel };
|
|
403
|
+
}
|
|
404
|
+
function drawImpact() {
|
|
405
|
+
resetStage();
|
|
406
|
+
const focus = state.sel || D.insights.most_depended[0] || D.files[0].id;
|
|
407
|
+
const { dist, parent, symbolLevel } = dependents(focus);
|
|
408
|
+
const rings = [];
|
|
409
|
+
for (const [id, d] of dist) if (d) (rings[Math.min(d, 4)] ||= []).push(id);
|
|
410
|
+
const R = 120, pos = new Map([[focus, { x: 0, y: 0 }]]);
|
|
411
|
+
rings.forEach((ids, d) => {
|
|
412
|
+
if (!ids) return;
|
|
413
|
+
world.append(sv("circle", { class: "ring", r: d * R }));
|
|
414
|
+
world.append(sv("text", { class: "ring-label", x: 6, y: -d * R - 6, text: `${d === 4 ? "4+" : d} hop${d === 1 ? "" : "s"} · ${ids.length}` }));
|
|
415
|
+
ids.sort((a, b) => (fileOf(a) || "").localeCompare(fileOf(b) || "") || a.localeCompare(b));
|
|
416
|
+
ids.forEach((id, i) => { const a = (i / ids.length) * Math.PI * 2 - Math.PI / 2 + d * 0.4; pos.set(id, { x: Math.cos(a) * d * R, y: Math.sin(a) * d * R }); });
|
|
417
|
+
});
|
|
418
|
+
const ge = sv("g"), gn = sv("g");
|
|
419
|
+
world.append(ge, gn);
|
|
420
|
+
const paths = [];
|
|
421
|
+
for (const [id, p] of parent) { const a = pos.get(id), b = pos.get(p); if (a && b) { const e = sv("path", { class: "edge hot " + (symbolLevel ? "calls" : "imports"), d: curve(a, b, 0.1), "marker-end": "url(#arrowHot)" }); ge.append(e); paths.push(e); } }
|
|
422
|
+
for (const [id, p] of pos) {
|
|
423
|
+
const n = nodeOf(id), isFocus = id === focus;
|
|
424
|
+
const g = sv("g", { class: "node" + (isFocus ? " selected" : ""), transform: `translate(${p.x},${p.y})` });
|
|
425
|
+
const color = colorOf(fileOf(id));
|
|
426
|
+
g.append(sv("circle", { class: "halo", r: isFocus ? 26 : 13, fill: color, filter: "url(#glow)" }));
|
|
427
|
+
g.append(sv("circle", { class: "core", r: isFocus ? 16 : 7, fill: color }));
|
|
428
|
+
g.append(sv("text", { x: isFocus ? 22 : 11, y: 4, text: n.name }));
|
|
429
|
+
g.addEventListener("click", () => { if (!drag?.moved) select(id); });
|
|
430
|
+
gn.append(g);
|
|
431
|
+
}
|
|
432
|
+
if (!reduced) for (let i = 0; i < 3; i++) { const c = sv("circle", { class: "ripple", r: 10 }); world.append(c); setTimeout(() => c.classList.add("go"), 30 + i * 420); }
|
|
433
|
+
pulses(paths);
|
|
434
|
+
const total = dist.size - 1, pool = symbolLevel ? D.symbols.length : D.files.length;
|
|
435
|
+
$("#hint").textContent = total ? `Changing ${nodeOf(focus).name} can reach ${total} ${symbolLevel ? "symbol" : "file"}${total === 1 ? "" : "s"} (${Math.round((100 * total) / Math.max(1, pool - 1))}% of the ${symbolLevel ? "symbols" : "workspace"})` : `Nothing in the workspace depends on ${nodeOf(focus).name}`;
|
|
436
|
+
legend([["imports", "var(--saffron)", symbolLevel ? "called by" : "imported or called by"], ["", "", "ring = hops from the change"]]);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// ------------------------------------------------------------------ calls: symbol ego network around a file
|
|
440
|
+
function drawCalls() {
|
|
441
|
+
resetStage();
|
|
442
|
+
const fid = (state.sel && fileOf(state.sel)) || D.insights.most_depended[0] || D.files[0].id;
|
|
443
|
+
const own = [...(files.get(fid)?.symbols || [])].sort((a, b) => (syms.get(a).line - syms.get(b).line) || a.localeCompare(b));
|
|
444
|
+
if (!own.length) return emptyStage("No classes or functions here", `${files.get(fid).path} has no top-level symbols to connect.`);
|
|
445
|
+
const ownSet = new Set(own), callers = new Set(), callees = new Set(), edges = [];
|
|
446
|
+
for (const s of own) {
|
|
447
|
+
for (const t of [...get(callOut, s), ...get(inhOut, s)]) { edges.push([s, t, get(inhOut, s).includes(t) ? "inherits" : "calls"]); if (!ownSet.has(t)) callees.add(t); }
|
|
448
|
+
for (const c of [...get(callIn, s), ...get(inhIn, s)]) { if (!ownSet.has(c)) { callers.add(c); edges.push([c, s, get(inhIn, s).includes(c) ? "inherits" : "calls"]); } }
|
|
449
|
+
}
|
|
450
|
+
const COL = 330, ROW = 34, pos = new Map();
|
|
451
|
+
const column = (ids, x) => [...ids].sort().forEach((id, i, arr) => pos.set(id, { x, y: (i - (arr.length - 1) / 2) * ROW }));
|
|
452
|
+
column(callers, -COL); column(own, 0); column(callees, COL);
|
|
453
|
+
world.append(sv("text", { class: "lane-label", x: -COL, y: -(Math.max(callers.size, own.length, callees.size) / 2) * ROW - 24, "text-anchor": "middle", text: `callers · ${callers.size}` }));
|
|
454
|
+
world.append(sv("text", { class: "lane-label", x: 0, y: -(Math.max(callers.size, own.length, callees.size) / 2) * ROW - 24, "text-anchor": "middle", text: files.get(fid).name }));
|
|
455
|
+
world.append(sv("text", { class: "lane-label", x: COL, y: -(Math.max(callers.size, own.length, callees.size) / 2) * ROW - 24, "text-anchor": "middle", text: `calls out · ${callees.size}` }));
|
|
456
|
+
const ge = sv("g"), gn = sv("g");
|
|
457
|
+
world.append(ge, gn);
|
|
458
|
+
const edgeEls = [];
|
|
459
|
+
for (const [s, t, k] of edges) {
|
|
460
|
+
if (!state.filters[k]) continue;
|
|
461
|
+
const a = pos.get(s), b = pos.get(t);
|
|
462
|
+
if (!a || !b) continue;
|
|
463
|
+
const d = a.x === b.x ? `M${a.x + 70},${a.y} C${a.x + 140},${a.y} ${b.x + 140},${b.y} ${b.x + 70},${b.y}` : curve(a, b, 0.06);
|
|
464
|
+
const p = sv("path", { class: "edge " + k, d, "marker-end": "url(#arrow)" });
|
|
465
|
+
p.dataset.s = s; p.dataset.t = t; ge.append(p); edgeEls.push(p);
|
|
466
|
+
}
|
|
467
|
+
const nodeEls = new Map();
|
|
468
|
+
for (const [id, p] of pos) {
|
|
469
|
+
const s = syms.get(id), mine = ownSet.has(id);
|
|
470
|
+
const g = sv("g", { class: "node box" + (state.sel === id ? " selected" : ""), transform: `translate(${p.x - 70},${p.y - 13})` });
|
|
471
|
+
g.append(sv("rect", { width: 140, height: 26, rx: 8, fill: mine ? "var(--raise)" : "var(--panel-solid)", stroke: colorOf(s.file), "stroke-width": mine ? 1.8 : 1 }));
|
|
472
|
+
g.append(sv("text", { x: 10, y: 17, text: (s.kind === "class" ? "◆ " : "ƒ ") + (s.name.length > 18 ? s.name.slice(0, 17) + "…" : s.name) }));
|
|
473
|
+
g.addEventListener("mouseenter", () => hot(id)); g.addEventListener("mouseleave", () => hot(null));
|
|
474
|
+
g.addEventListener("click", () => { if (!drag?.moved) select(id); });
|
|
475
|
+
gn.append(g); nodeEls.set(id, g);
|
|
476
|
+
}
|
|
477
|
+
function hot(id) {
|
|
478
|
+
svg.classList.toggle("dim", !!id);
|
|
479
|
+
nodeEls.forEach((g) => g.classList.remove("hot")); edgeEls.forEach((p) => p.classList.remove("hot"));
|
|
480
|
+
if (!id) { pulses([]); return; }
|
|
481
|
+
nodeEls.get(id)?.classList.add("hot");
|
|
482
|
+
const hotE = edgeEls.filter((p) => p.dataset.s === id || p.dataset.t === id);
|
|
483
|
+
hotE.forEach((p) => { p.classList.add("hot"); nodeEls.get(p.dataset.s)?.classList.add("hot"); nodeEls.get(p.dataset.t)?.classList.add("hot"); });
|
|
484
|
+
pulses(hotE);
|
|
485
|
+
}
|
|
486
|
+
$("#hint").textContent = `${own.length} symbols in ${files.get(fid).path} · ${callers.size} callers · ${callees.size} callees (inferred)`;
|
|
487
|
+
legend([["calls", "rgba(61,214,198,.8)", "calls (inferred)"], ["inherits", "var(--rose)", "inherits"]]);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// ------------------------------------------------------------------ hotspots: squarified treemap
|
|
491
|
+
function drawHotspots() {
|
|
492
|
+
const box = $("#treemap");
|
|
493
|
+
box.replaceChildren();
|
|
494
|
+
const W = box.clientWidth || 800, H = box.clientHeight || 500;
|
|
495
|
+
const items = D.files.filter((f) => f.loc > 0).map((f) => ({ f, v: f.loc })).sort((a, b) => b.v - a.v);
|
|
496
|
+
if (!items.length) { box.append(el("div", { class: "empty" }, el("span", { class: "big", text: "🜂" }), "No lines to measure.")); return; }
|
|
497
|
+
const maxIn = Math.max(1, ...D.files.map((f) => f.fan_in));
|
|
498
|
+
const heat = (n) => { const t = n / maxIn; return t > 0.66 ? "var(--ember)" : t > 0.33 ? "var(--saffron)" : t > 0 ? "#ffd36e" : "var(--teal)"; };
|
|
499
|
+
const total = items.reduce((s, i) => s + i.v, 0);
|
|
500
|
+
let rect = { x: 0, y: 0, w: W, h: H }, row = [], rest = items.map((i) => ({ ...i, a: (i.v / total) * W * H }));
|
|
501
|
+
const worst = (r, side) => { const s = r.reduce((t, i) => t + i.a, 0), mx = Math.max(...r.map((i) => i.a)), mn = Math.min(...r.map((i) => i.a)); return Math.max((side * side * mx) / (s * s), (s * s) / (side * side * mn)); };
|
|
502
|
+
const flush = () => {
|
|
503
|
+
const s = row.reduce((t, i) => t + i.a, 0), horiz = rect.w >= rect.h, side = horiz ? rect.h : rect.w, thick = s / side;
|
|
504
|
+
let off = 0;
|
|
505
|
+
for (const i of row) {
|
|
506
|
+
const len = i.a / thick;
|
|
507
|
+
const cell = horiz ? { x: rect.x, y: rect.y + off, w: thick, h: len } : { x: rect.x + off, y: rect.y, w: len, h: thick };
|
|
508
|
+
off += len;
|
|
509
|
+
const d = el("button", { class: "tm-cell" + (fileOf(state.sel || "") === i.f.id ? " selected" : ""), title: `${i.f.path} · ${i.f.loc} lines · imported by ${i.f.fan_in}`, style: `left:${cell.x}px;top:${cell.y}px;width:${Math.max(0, cell.w - 2)}px;height:${Math.max(0, cell.h - 2)}px;background:${heat(i.f.fan_in)}`, onclick: () => select(i.f.id) });
|
|
510
|
+
if (cell.w > 60 && cell.h > 26) d.append(el("b", { text: i.f.name }), el("small", { text: `${fmt(i.f.loc)} lines · ←${i.f.fan_in}` }));
|
|
511
|
+
box.append(d);
|
|
512
|
+
}
|
|
513
|
+
if (horiz) { rect = { x: rect.x + thick, y: rect.y, w: rect.w - thick, h: rect.h }; } else { rect = { x: rect.x, y: rect.y + thick, w: rect.w, h: rect.h - thick }; }
|
|
514
|
+
row = [];
|
|
515
|
+
};
|
|
516
|
+
while (rest.length) {
|
|
517
|
+
const side = Math.min(rect.w, rect.h), next = rest[0];
|
|
518
|
+
if (!row.length || worst([...row, next], side) <= worst(row, side)) { row.push(next); rest.shift(); } else flush();
|
|
519
|
+
}
|
|
520
|
+
if (row.length) flush();
|
|
521
|
+
$("#hint").textContent = "";
|
|
522
|
+
legend([["", "var(--teal)", "imported by none"], ["", "#ffd36e", "a few"], ["", "var(--saffron)", "many"], ["", "var(--ember)", "most"], ["", "", "area = lines"]]);
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
// ------------------------------------------------------------------ guided tour
|
|
526
|
+
function tourSteps() {
|
|
527
|
+
const P = D.project, steps = [{ title: "Overview", text: `${P.name}: ${fmt(P.files)} files in ${fmt(P.packages)} packages, ${fmt(P.symbols)} classes and functions, ${fmt(P.loc)} lines.`, view: "constellation" }];
|
|
528
|
+
[...D.packages].sort((a, b) => b.files.length - a.files.length).slice(0, 3).forEach((p) => steps.push({ title: "Package", text: `${p.id === "." ? "The root" : p.id} holds ${p.files.length} file${p.files.length === 1 ? "" : "s"}.`, view: "constellation", pkg: p.id }));
|
|
529
|
+
D.insights.entry_points.slice(0, 2).forEach((id) => steps.push({ title: "Entry point", text: `${files.get(id).path} looks like a way in: start reading here.`, view: "constellation", sel: id }));
|
|
530
|
+
const top = D.insights.most_depended[0];
|
|
531
|
+
if (top) steps.push({ title: "Most depended on", text: `${files.get(top).path} is imported by ${files.get(top).fan_in} files. A change here ripples furthest.`, view: "impact", sel: top });
|
|
532
|
+
const big = D.insights.largest[0];
|
|
533
|
+
if (big) steps.push({ title: "Largest file", text: `${files.get(big).path} has ${fmt(files.get(big).loc)} lines and ${files.get(big).symbols.length} symbols.`, view: "hotspots", sel: big });
|
|
534
|
+
if (D.insights.cycles.length) steps.push({ title: "Import cycles", text: `${D.insights.cycles.length} cycle${D.insights.cycles.length === 1 ? "" : "s"}, e.g. ${D.insights.cycles[0].map((id) => files.get(id).name).join(" ↔ ")}. Cycles make modules hard to change alone.`, view: "flow", sel: D.insights.cycles[0][0] });
|
|
535
|
+
if (D.external.length) steps.push({ title: "Outside world", text: `Depends on ${D.external.length} external modules, most used: ${[...D.external].sort((a, b) => b.importers.length - a.importers.length).slice(0, 5).map((e) => e.name).join(", ")}.`, view: "constellation" });
|
|
536
|
+
steps.push({ title: "What this map can't see", text: D.limitations[1] || D.limitations[0], view: "constellation" });
|
|
537
|
+
return steps;
|
|
538
|
+
}
|
|
539
|
+
let tourTimer = null, typeTimer = null;
|
|
540
|
+
function runTour(i) {
|
|
541
|
+
const steps = tourSteps();
|
|
542
|
+
state.tour = (i + steps.length) % steps.length;
|
|
543
|
+
const s = steps[state.tour];
|
|
544
|
+
$("#narration").hidden = false;
|
|
545
|
+
$("#tourStep").textContent = `${state.tour + 1} / ${steps.length} · ${s.title}`;
|
|
546
|
+
$("#tourDots").replaceChildren(...steps.map((_, k) => el("i", { class: k <= state.tour ? "on" : "" })));
|
|
547
|
+
state.sel = s.sel || null;
|
|
548
|
+
renderView(s.view, true);
|
|
549
|
+
if (s.pkg && constellation) { const c = constellation.centers.find((c) => c.id === s.pkg); if (c) fit(30, { x: c.x - c.r, y: c.y - c.r, width: c.r * 2, height: c.r * 2 }); }
|
|
550
|
+
const t = $("#tourText"); clearInterval(typeTimer);
|
|
551
|
+
if (reduced) t.textContent = s.text; else { let k = 0; t.textContent = ""; typeTimer = setInterval(() => { t.textContent = s.text.slice(0, ++k); if (k >= s.text.length) clearInterval(typeTimer); }, 16); }
|
|
552
|
+
clearTimeout(tourTimer);
|
|
553
|
+
if (state.playing) tourTimer = setTimeout(() => runTour(state.tour + 1), 6500);
|
|
554
|
+
}
|
|
555
|
+
$("#tourPrev").onclick = () => runTour(state.tour - 1);
|
|
556
|
+
$("#tourNext").onclick = () => runTour(state.tour + 1);
|
|
557
|
+
$("#tourPlay").onclick = () => { state.playing = !state.playing; $("#tourPlay").textContent = state.playing ? "❚❚ Pause" : "▶ Play"; runTour(state.tour); };
|
|
558
|
+
|
|
559
|
+
// ------------------------------------------------------------------ view switching
|
|
560
|
+
const VIEWS = {
|
|
561
|
+
constellation: { icon: "✦", label: "Constellation", desc: "Every file, clustered by package. Hover to light up what it imports and what imports it.", draw: drawConstellation },
|
|
562
|
+
flow: { icon: "⇶", label: "Flow", desc: "Dependencies left to right, from entry side to foundations. Cycles glow rose.", draw: drawFlow },
|
|
563
|
+
impact: { icon: "◎", label: "Impact", desc: "Blast radius: what could break if the selected file or symbol changes.", draw: drawImpact },
|
|
564
|
+
calls: { icon: "ƒ", label: "Calls", desc: "Who calls into the selected file, and what it calls (inferred from imports).", draw: drawCalls },
|
|
565
|
+
hotspots: { icon: "▦", label: "Hotspots", desc: "Big files that many others depend on are where changes cost the most.", draw: drawHotspots },
|
|
566
|
+
tour: { icon: "☄", label: "Tour", desc: "A guided walk through this codebase.", draw: () => runTour(state.tour) },
|
|
567
|
+
};
|
|
568
|
+
const tabs = $("#tabs");
|
|
569
|
+
for (const [id, v] of Object.entries(VIEWS)) tabs.append(el("button", { class: "tab", role: "tab", "data-view": id, "aria-selected": "false", onclick: () => { if (id !== "tour") { clearTimeout(tourTimer); $("#narration").hidden = true; } renderView(id); } }, el("span", { class: "ic", "aria-hidden": "true", text: v.icon }), v.label));
|
|
570
|
+
function renderView(id, fromTour) {
|
|
571
|
+
if (!VIEWS[id]) id = "constellation";
|
|
572
|
+
if (!fromTour) state.view = id;
|
|
573
|
+
if (id === "tour") { state.view = "tour"; markTabs("tour"); return VIEWS.tour.draw(); }
|
|
574
|
+
markTabs(fromTour ? "tour" : id);
|
|
575
|
+
$("#viewTitle").textContent = VIEWS[id].label;
|
|
576
|
+
$("#viewDesc").textContent = VIEWS[id].desc;
|
|
577
|
+
const tm = id === "hotspots";
|
|
578
|
+
$("#treemap").hidden = !tm; svg.style.display = tm ? "none" : "block"; $("#zoomTools").hidden = tm;
|
|
579
|
+
toolsFor(id);
|
|
580
|
+
$("#hint").textContent = "";
|
|
581
|
+
VIEWS[id].draw();
|
|
582
|
+
if (!tm) fit();
|
|
583
|
+
inspect(state.sel);
|
|
584
|
+
syncHash();
|
|
585
|
+
}
|
|
586
|
+
function markTabs(id) { tabs.querySelectorAll(".tab").forEach((t) => t.setAttribute("aria-selected", String(t.dataset.view === id))); }
|
|
587
|
+
function toolsFor(id) {
|
|
588
|
+
const box = $("#stageTools"); box.replaceChildren();
|
|
589
|
+
const keys = id === "constellation" || id === "flow" ? ["imports"] : id === "calls" ? ["calls", "inherits"] : [];
|
|
590
|
+
for (const k of keys) box.append(el("button", { class: "chip", "aria-pressed": String(state.filters[k]), text: k, onclick: () => { state.filters[k] = !state.filters[k]; renderView(state.view === "tour" ? "constellation" : state.view); } }));
|
|
591
|
+
if (id === "flow") for (const lvl of ["packages", "files"]) box.append(el("button", { class: "chip", "aria-pressed": String((state.flowLevel || (D.files.length > 120 ? "packages" : "files")) === lvl), text: lvl, onclick: () => { state.flowLevel = lvl; renderView("flow"); } }));
|
|
592
|
+
if (id === "impact" || id === "calls") box.append(el("span", { class: "muted", text: state.sel ? "" : "Select a file or symbol to focus" }));
|
|
593
|
+
}
|
|
594
|
+
function legend(items) {
|
|
595
|
+
const L = $("#legend"); L.replaceChildren();
|
|
596
|
+
for (const [, color, label] of items) if (label) L.append(el("span", {}, color ? el("i", { style: `background:${color}` }) : "", label));
|
|
597
|
+
L.hidden = !L.childElementCount;
|
|
598
|
+
}
|
|
599
|
+
function emptyStage(title, text) {
|
|
600
|
+
world.append(sv("text", { x: 0, y: 0, "text-anchor": "middle", class: "pkg-label", text: title }));
|
|
601
|
+
world.append(sv("text", { x: 0, y: 22, "text-anchor": "middle", class: "ring-label", text }));
|
|
602
|
+
legend([]);
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
// ------------------------------------------------------------------ selection and inspector
|
|
606
|
+
function select(id) {
|
|
607
|
+
state.sel = id && nodeOf(id) ? id : null;
|
|
608
|
+
if (state.view !== "tour") renderView(state.view); else inspect(state.sel);
|
|
609
|
+
document.querySelectorAll(".tree-item").forEach((t) => t.setAttribute("aria-current", String(t.dataset.id === (state.sel && fileOf(state.sel)))));
|
|
610
|
+
if (window.innerWidth <= 1180 && state.sel) $("#inspector").classList.add("open");
|
|
611
|
+
syncHash();
|
|
612
|
+
}
|
|
613
|
+
const link = (id, where) => { const n = nodeOf(id); return n ? el("button", { class: "link", onclick: () => select(id) }, el("span", { class: "dot", style: `color:${colorOf(fileOf(id))}` }), el("span", { class: "kind " + (n.kind || "file"), text: n.kind || "file" }), el("span", { text: n.name }), where ? el("span", { class: "where", text: where }) : "") : null; };
|
|
614
|
+
const section = (title, kids) => (kids.filter(Boolean).length ? [el("h3", { class: "eyebrow", text: title }), el("div", { class: "links" }, kids)] : []);
|
|
615
|
+
function inspect(id) {
|
|
616
|
+
const body = $("#inspectBody"); body.replaceChildren();
|
|
617
|
+
const close = el("button", { class: "btn icon", "aria-label": "Close inspector", text: "✕", onclick: () => $("#inspector").classList.remove("open"), style: "margin-left:auto" });
|
|
618
|
+
if (!id) {
|
|
619
|
+
const P = D.project;
|
|
620
|
+
body.append(
|
|
621
|
+
el("div", { class: "ins-head" }, el("h2", { text: P.name }), close),
|
|
622
|
+
el("p", { class: "muted", text: "Pick anything in the graph, the tree or search to see its source, contract and connections." }),
|
|
623
|
+
el("div", { class: "facts" }, ...[["files", P.files], ["symbols", P.symbols], ["lines", P.loc], ["imports", P.imports], ["calls", P.calls], ["external", P.external]].map(([k, v]) => el("div", { class: "fact" }, el("b", { text: fmt(v) }), el("span", { text: k })))),
|
|
624
|
+
...section("Most depended on", D.insights.most_depended.slice(0, 6).map((f) => link(f, `← ${files.get(f).fan_in}`))),
|
|
625
|
+
...section("Entry points", D.insights.entry_points.slice(0, 6).map((f) => link(f))),
|
|
626
|
+
el("h3", { class: "eyebrow", text: "How to read this" }),
|
|
627
|
+
el("ul", { class: "muted" }, el("li", { text: "Circles are files; size is lines of code, colour is the package." }), el("li", { text: "Arrows point from a file to what it imports." }), el("li", { text: "Calls and inheritance are inferred statically by Ananke and may miss dynamic dispatch." })),
|
|
628
|
+
);
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
const f = files.get(id);
|
|
632
|
+
if (f) {
|
|
633
|
+
body.append(
|
|
634
|
+
el("div", { class: "ins-head" }, el("span", { class: "kind file", text: "file" }), el("div", {}, el("h2", { text: f.name }), el("div", { class: "ins-path mono", text: f.path })), close),
|
|
635
|
+
f.doc ? el("div", { class: "ins-doc", text: f.doc }) : "",
|
|
636
|
+
el("div", { class: "facts" }, el("div", { class: "fact" }, el("b", { text: fmt(f.loc) }), el("span", { text: "lines" })), el("div", { class: "fact" }, el("b", { text: f.fan_in }), el("span", { text: "imported by" })), el("div", { class: "fact" }, el("b", { text: f.fan_out }), el("span", { text: "imports" }))),
|
|
637
|
+
el("div", { class: "actions" },
|
|
638
|
+
el("button", { class: "btn primary", text: "◎ Impact", onclick: () => renderView("impact") }),
|
|
639
|
+
el("button", { class: "btn", text: "ƒ Calls", onclick: () => renderView("calls") }),
|
|
640
|
+
el("button", { class: "btn", text: "⇶ Flow", onclick: () => renderView("flow") }),
|
|
641
|
+
el("button", { class: "btn", text: "⧉ Copy path", onclick: () => copy(f.path, "Path copied") })),
|
|
642
|
+
f.parse_error ? el("p", { class: "ins-doc", text: "Ananke couldn't parse this file, so its symbols aren't shown." }) : "",
|
|
643
|
+
cycleFiles.has(f.id) ? el("p", { class: "ins-doc", text: "Part of an import cycle (see Flow)." }) : "",
|
|
644
|
+
...section(`Symbols · ${f.symbols.length}`, f.symbols.map((s) => link(s, `L${syms.get(s).line}`))),
|
|
645
|
+
...section(`Imported by · ${f.fan_in}`, get(inn, f.id).sort().map((x) => link(x))),
|
|
646
|
+
...section(`Imports · ${f.fan_out}`, get(out, f.id).sort().map((x) => link(x))),
|
|
647
|
+
f.external.length ? el("h3", { class: "eyebrow", text: "External modules" }) : "",
|
|
648
|
+
f.external.length ? el("div", { class: "tagline" }, ...f.external.map((m) => el("span", { class: "tag mono", text: m }))) : "",
|
|
649
|
+
);
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
const s = syms.get(id);
|
|
653
|
+
const file = files.get(s.file);
|
|
654
|
+
const src = el("pre", { class: "src", "aria-label": "Source" });
|
|
655
|
+
(s.source || "").split("\n").forEach((line, i) => src.append(el("span", { "data-ln": s.line + i, text: line || " " })));
|
|
656
|
+
body.append(
|
|
657
|
+
el("div", { class: "ins-head" }, el("span", { class: "kind " + s.kind, text: s.kind }), el("div", {}, el("h2", { text: s.name }), el("div", { class: "ins-path mono", text: `${file ? file.path : ""}:${s.line}` })), close),
|
|
658
|
+
s.signature ? el("div", { class: "sig mono", text: s.signature }) : "",
|
|
659
|
+
s.doc ? el("div", { class: "ins-doc", text: s.doc }) : "",
|
|
660
|
+
el("div", { class: "facts" }, el("div", { class: "fact" }, el("b", { text: s.calls_in }), el("span", { text: "called by" })), el("div", { class: "fact" }, el("b", { text: s.calls_out }), el("span", { text: "calls" })), el("div", { class: "fact" }, el("b", { text: Math.max(1, s.end_line - s.line + 1) }), el("span", { text: "lines" }))),
|
|
661
|
+
el("div", { class: "actions" },
|
|
662
|
+
el("button", { class: "btn primary", text: "◎ Who's affected", onclick: () => renderView("impact") }),
|
|
663
|
+
el("button", { class: "btn", text: "ƒ Calls", onclick: () => renderView("calls") }),
|
|
664
|
+
file ? el("button", { class: "btn", text: "↑ File", onclick: () => select(file.id) }) : "",
|
|
665
|
+
el("button", { class: "btn", text: "⤓ Ask for deeper analysis", onclick: () => requestAnalysis(s.id) })),
|
|
666
|
+
s.source ? el("h3", { class: "eyebrow", text: "Source" }) : "",
|
|
667
|
+
s.source ? src : "",
|
|
668
|
+
...section("Called by", get(callIn, s.id).sort().map((x) => link(x, files.get(fileOf(x))?.name))),
|
|
669
|
+
...section("Calls", get(callOut, s.id).sort().map((x) => link(x, files.get(fileOf(x))?.name))),
|
|
670
|
+
...section("Inherits from", get(inhOut, s.id).map((x) => link(x))),
|
|
671
|
+
...section("Subclassed by", get(inhIn, s.id).map((x) => link(x))),
|
|
672
|
+
);
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// ------------------------------------------------------------------ sidebar: insights, tree, search
|
|
676
|
+
function buildSidebar() {
|
|
677
|
+
$("#projectName").textContent = D.project.name;
|
|
678
|
+
const P = D.project;
|
|
679
|
+
$("#stats").replaceChildren(...[["files", P.files], ["packages", P.packages], ["symbols", P.symbols], ["lines", P.loc], ["imports", P.imports], ["calls", P.calls], ["external", P.external]].map(([k, v]) => el("div", { class: "stat" }, el("b", { text: fmt(v) }), el("span", { text: k }))),
|
|
680
|
+
D.insights.cycles.length ? el("div", { class: "stat warn" }, el("b", { text: D.insights.cycles.length }), el("span", { text: "import cycles" })) : "");
|
|
681
|
+
const ins = $("#insights"); ins.replaceChildren(el("h2", { class: "eyebrow", text: "Start here" }));
|
|
682
|
+
const card = (label, text, onclick) => ins.append(el("button", { class: "insight", onclick }, el("b", { text: label }), el("span", { text })));
|
|
683
|
+
card("Guided tour", "Walk through this codebase step by step", () => renderView("tour"));
|
|
684
|
+
if (D.insights.most_depended[0]) card("Most depended on", files.get(D.insights.most_depended[0]).path, () => { state.view = "impact"; select(D.insights.most_depended[0]); });
|
|
685
|
+
if (D.insights.cycles.length) card("Import cycles", `${D.insights.cycles.length} found`, () => { state.view = "flow"; select(D.insights.cycles[0][0]); });
|
|
686
|
+
if (D.insights.largest[0]) card("Largest file", files.get(D.insights.largest[0]).path, () => { state.view = "hotspots"; select(D.insights.largest[0]); });
|
|
687
|
+
const tree = $("#tree"); tree.replaceChildren();
|
|
688
|
+
for (const p of D.packages) {
|
|
689
|
+
const kids = el("div", { class: "tree-children", role: "group", hidden: D.packages.length > 6 ? true : false });
|
|
690
|
+
const head = el("button", { class: "tree-item tree-pkg", role: "treeitem", "aria-expanded": String(D.packages.length <= 6), onclick: () => { kids.hidden = !kids.hidden; head.setAttribute("aria-expanded", String(!kids.hidden)); } },
|
|
691
|
+
el("span", { class: "dot", style: `color:${PALETTE[pkgIndex.get(p.id) % PALETTE.length]}` }), el("span", { text: p.id === "." ? "(root)" : p.id }), el("span", { class: "count", text: p.files.length }));
|
|
692
|
+
for (const fid of p.files) kids.append(el("button", { class: "tree-item", role: "treeitem", "data-id": fid, onclick: () => select(fid) }, el("span", { text: files.get(fid).name }), el("span", { class: "count", text: fmt(files.get(fid).loc) })));
|
|
693
|
+
tree.append(head, kids);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
const searchIndex = [...D.files.map((f) => ({ id: f.id, name: f.name, hay: f.path.toLowerCase(), kind: "file", where: f.package })), ...D.symbols.map((s) => ({ id: s.id, name: s.name, hay: s.name.toLowerCase(), kind: s.kind, where: files.get(s.file)?.name || "" }))];
|
|
697
|
+
function find(q, limit = 30) {
|
|
698
|
+
q = q.trim().toLowerCase();
|
|
699
|
+
if (!q) return [];
|
|
700
|
+
const scored = [];
|
|
701
|
+
for (const it of searchIndex) { const i = it.hay.indexOf(q); if (i < 0) continue; scored.push([(it.name.toLowerCase().startsWith(q) ? 0 : 1) * 1000 + i * 10 + it.name.length, it]); }
|
|
702
|
+
return scored.sort((a, b) => a[0] - b[0] || a[1].id.localeCompare(b[1].id)).slice(0, limit).map((x) => x[1]);
|
|
703
|
+
}
|
|
704
|
+
const search = $("#search"), results = $("#results");
|
|
705
|
+
let active = 0;
|
|
706
|
+
function showResults() {
|
|
707
|
+
const hits = find(search.value);
|
|
708
|
+
results.hidden = !search.value;
|
|
709
|
+
results.replaceChildren(...(hits.length ? hits.map((h, i) => el("button", { class: "result", role: "option", "aria-selected": String(i === active), onclick: () => { select(h.id); search.value = ""; showResults(); search.blur(); } }, el("span", { class: "kind " + h.kind, text: h.kind }), el("span", { text: h.name }), el("span", { class: "where", text: h.where }))) : [el("div", { class: "empty", text: "Nothing matches" })]));
|
|
710
|
+
}
|
|
711
|
+
search.addEventListener("input", () => { active = 0; showResults(); });
|
|
712
|
+
search.addEventListener("keydown", (e) => {
|
|
713
|
+
const opts = results.querySelectorAll(".result");
|
|
714
|
+
if (e.key === "ArrowDown") { active = Math.min(opts.length - 1, active + 1); showResults(); e.preventDefault(); }
|
|
715
|
+
else if (e.key === "ArrowUp") { active = Math.max(0, active - 1); showResults(); e.preventDefault(); }
|
|
716
|
+
else if (e.key === "Enter" && opts[active]) opts[active].click();
|
|
717
|
+
else if (e.key === "Escape") { search.value = ""; showResults(); search.blur(); }
|
|
718
|
+
});
|
|
719
|
+
$("#searchBtn").onclick = () => search.focus();
|
|
720
|
+
|
|
721
|
+
// ------------------------------------------------------------------ command palette
|
|
722
|
+
const palette = $("#palette"), pInput = $("#paletteInput"), pList = $("#paletteList");
|
|
723
|
+
const commands = () => [
|
|
724
|
+
...Object.entries(VIEWS).map(([id, v]) => ({ label: `${v.icon} Go to ${v.label}`, run: () => renderView(id) })),
|
|
725
|
+
{ label: "◐ Toggle theme", run: toggleTheme },
|
|
726
|
+
{ label: "⤢ Fit to screen", run: () => fit() },
|
|
727
|
+
{ label: "⧉ Copy a link to this view", run: () => copy(location.href, "Link copied") },
|
|
728
|
+
{ label: "⤓ Download this view's state (JSON)", run: downloadState },
|
|
729
|
+
{ label: "⤓ Ask for deeper analysis of the selection", run: () => requestAnalysis(state.sel) },
|
|
730
|
+
{ label: "ⓘ About this report and its limitations", run: about },
|
|
731
|
+
];
|
|
732
|
+
let pActive = 0;
|
|
733
|
+
function renderPalette() {
|
|
734
|
+
const q = pInput.value.toLowerCase();
|
|
735
|
+
const cmds = commands().filter((c) => c.label.toLowerCase().includes(q));
|
|
736
|
+
const hits = find(pInput.value, 12).map((h) => ({ label: `${h.kind === "file" ? "▤" : "ƒ"} ${h.name} · ${h.where}`, run: () => select(h.id) }));
|
|
737
|
+
const all = [...cmds, ...hits];
|
|
738
|
+
pActive = Math.min(pActive, Math.max(0, all.length - 1));
|
|
739
|
+
pList.replaceChildren(...all.map((c, i) => el("button", { class: "pl-item", role: "option", "aria-selected": String(i === pActive), onclick: () => { closePalette(); c.run(); } }, c.label)));
|
|
740
|
+
}
|
|
741
|
+
const openPalette = () => { palette.hidden = false; pInput.value = ""; pActive = 0; renderPalette(); pInput.focus(); };
|
|
742
|
+
const closePalette = () => { palette.hidden = true; };
|
|
743
|
+
pInput.addEventListener("input", () => { pActive = 0; renderPalette(); });
|
|
744
|
+
pInput.addEventListener("keydown", (e) => {
|
|
745
|
+
const n = pList.children.length;
|
|
746
|
+
if (e.key === "ArrowDown") { pActive = (pActive + 1) % Math.max(1, n); renderPalette(); e.preventDefault(); }
|
|
747
|
+
else if (e.key === "ArrowUp") { pActive = (pActive - 1 + n) % Math.max(1, n); renderPalette(); e.preventDefault(); }
|
|
748
|
+
else if (e.key === "Enter") pList.children[pActive]?.click();
|
|
749
|
+
else if (e.key === "Escape") closePalette();
|
|
750
|
+
});
|
|
751
|
+
palette.addEventListener("click", (e) => { if (e.target === palette) closePalette(); });
|
|
752
|
+
$("#paletteBtn").onclick = openPalette;
|
|
753
|
+
|
|
754
|
+
// ------------------------------------------------------------------ about, theme, exports, toast
|
|
755
|
+
function about() {
|
|
756
|
+
const b = $("#aboutBody");
|
|
757
|
+
const pre = el("pre", { class: "manifest mono", text: JSON.stringify(M, null, 2) });
|
|
758
|
+
b.replaceChildren(
|
|
759
|
+
el("h2", { id: "aboutTitle", text: "About this report" }),
|
|
760
|
+
el("p", { text: "Generated by Dev Guru from the code graph Ananke Plexus built for this workspace. It works offline and is view-only: it never runs commands or contacts a server." }),
|
|
761
|
+
el("h3", { class: "eyebrow", text: "Limitations" }),
|
|
762
|
+
el("ul", {}, ...D.limitations.map((l) => el("li", { text: l }))),
|
|
763
|
+
el("h3", { class: "eyebrow", text: "Keyboard" }),
|
|
764
|
+
el("ul", {}, el("li", { text: "/ search · Ctrl/⌘ K commands · 1–6 views · F fit · T theme · Esc close" })),
|
|
765
|
+
el("h3", { class: "eyebrow", text: "Manifest" }), pre,
|
|
766
|
+
el("p", {}, el("button", { class: "btn", text: "Close", onclick: () => ($("#about").hidden = true) })),
|
|
767
|
+
);
|
|
768
|
+
$("#about").hidden = false;
|
|
769
|
+
}
|
|
770
|
+
$("#about").addEventListener("click", (e) => { if (e.target.id === "about") $("#about").hidden = true; });
|
|
771
|
+
$("#infoBtn").onclick = about;
|
|
772
|
+
function toggleTheme() { const r = document.documentElement; r.dataset.theme = r.dataset.theme === "day" ? "night" : "day"; syncHash(); }
|
|
773
|
+
$("#themeBtn").onclick = toggleTheme;
|
|
774
|
+
function download(name, obj) {
|
|
775
|
+
const a = el("a", { download: name, href: URL.createObjectURL(new Blob([JSON.stringify(obj, null, 2)], { type: "application/json" })) });
|
|
776
|
+
document.body.append(a); a.click(); a.remove();
|
|
777
|
+
toast(`Saved ${name}`);
|
|
778
|
+
}
|
|
779
|
+
const downloadState = () => download("dev-guru-view.json", { schema: "dev-guru/view-state@1", report: M.input_digest, view: state.view, selection: state.sel, filters: state.filters });
|
|
780
|
+
function requestAnalysis(id) {
|
|
781
|
+
download("dev-guru-analysis-request.json", {
|
|
782
|
+
schema: "dev-guru/analysis-request@1",
|
|
783
|
+
note: "Run this with Dev Guru or Ananke; the report itself never executes anything.",
|
|
784
|
+
workspace: M.workspace, report_digest: M.input_digest, target: id || null,
|
|
785
|
+
requested: id ? ["impact", "callers", "tests-covering"] : ["full-explore"],
|
|
786
|
+
suggested_command: `dev explore ${id ? "--focus " + JSON.stringify(id) : ""}`.trim(),
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
async function copy(text, done) {
|
|
790
|
+
try { await navigator.clipboard.writeText(text); toast(done); }
|
|
791
|
+
catch (_) { window.prompt("Copy:", text); }
|
|
792
|
+
}
|
|
793
|
+
let toastTimer;
|
|
794
|
+
function toast(msg) { const t = $("#toast"); t.textContent = msg; t.classList.add("show"); clearTimeout(toastTimer); toastTimer = setTimeout(() => t.classList.remove("show"), 1800); }
|
|
795
|
+
|
|
796
|
+
// ------------------------------------------------------------------ footer and keyboard
|
|
797
|
+
const rev = M.workspace && M.workspace.commit ? `${M.workspace.commit.slice(0, 8)}${M.workspace.dirty ? " (uncommitted changes)" : ""}` : "not a git checkout";
|
|
798
|
+
$("#foot").replaceChildren(
|
|
799
|
+
el("span", {}, el("b", { text: "Dev Guru " }), String(M.dev_guru)), el("span", {}, el("b", { text: "Ananke " }), String(M.ananke)),
|
|
800
|
+
el("span", {}, el("b", { text: "revision " }), rev), el("span", {}, el("b", { text: "input " }), String(M.input_digest).slice(0, 19) + "…"),
|
|
801
|
+
el("span", {}, el("b", { text: "generated " }), String(M.generated_at)), el("span", { text: "offline · view-only" }),
|
|
802
|
+
);
|
|
803
|
+
document.addEventListener("keydown", (e) => {
|
|
804
|
+
const typing = /INPUT|TEXTAREA/.test(document.activeElement?.tagName || "");
|
|
805
|
+
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "k") { e.preventDefault(); palette.hidden ? openPalette() : closePalette(); return; }
|
|
806
|
+
if (e.key === "Escape") { closePalette(); $("#about").hidden = true; $("#inspector").classList.remove("open"); return; }
|
|
807
|
+
if (typing) return;
|
|
808
|
+
if (e.key === "/") { e.preventDefault(); search.focus(); }
|
|
809
|
+
else if (e.key >= "1" && e.key <= "6") renderView(Object.keys(VIEWS)[+e.key - 1]);
|
|
810
|
+
else if (e.key.toLowerCase() === "f") fit();
|
|
811
|
+
else if (e.key.toLowerCase() === "t") toggleTheme();
|
|
812
|
+
else if (state.view === "tour" && e.key === "ArrowRight") runTour(state.tour + 1);
|
|
813
|
+
else if (state.view === "tour" && e.key === "ArrowLeft") runTour(state.tour - 1);
|
|
814
|
+
});
|
|
815
|
+
let resizeTimer;
|
|
816
|
+
window.addEventListener("resize", () => { clearTimeout(resizeTimer); resizeTimer = setTimeout(() => { if (state.view === "hotspots") drawHotspots(); else fit(); }, 150); });
|
|
817
|
+
|
|
818
|
+
buildSidebar();
|
|
819
|
+
renderView(state.view);
|
|
820
|
+
if (state.sel) select(state.sel);
|
|
821
|
+
window.__devGuru = { state, D, M, renderView, select, find };
|
|
822
|
+
})();
|