grokmap 0.2.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.
@@ -0,0 +1,474 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>grokmap · __GROKMAP_TITLE__</title>
7
+ <style>
8
+ .viz-root {
9
+ color-scheme: light;
10
+ --page: #f9f9f9; --surface: #ffffff; --ink: #191919; --ink-2: #666666;
11
+ --grid: #e7e7e7; --axis: #c2c2c2; --ring: rgba(11,11,11,0.10);
12
+ --human: #c9ced6; --understood: #0aac23; --fading: #fbb315; --skimmed: #f18a59; --unread: #dc3c3d;
13
+ --d0: #fbe9e7; --d1: #f7c4bd; --d2: #ee8f84; --d3: #dc3c3d; --d4: #a31d22;
14
+ --d-none: #e6e9ee; --d-ok: #cdeed3; --accent: #257de0;
15
+ }
16
+ @media (prefers-color-scheme: dark) {
17
+ :root:where(:not([data-theme="light"])) .viz-root {
18
+ color-scheme: dark;
19
+ --page: #0b0b0b; --surface: #191919; --ink: #efefef; --ink-2: #9c9c9c;
20
+ --grid: #303030; --axis: #474747; --ring: rgba(255,255,255,0.10);
21
+ --human: #4a4f58;
22
+ --d0: #3a2422; --d1: #6a2b28; --d2: #a23533; --d3: #dc3c3d; --d4: #ff7a6e;
23
+ --d-none: #2b2e34; --d-ok: #1d4426; --accent: #338ced;
24
+ }
25
+ }
26
+ :root[data-theme="dark"] .viz-root {
27
+ color-scheme: dark;
28
+ --page: #0b0b0b; --surface: #191919; --ink: #efefef; --ink-2: #9c9c9c;
29
+ --grid: #303030; --axis: #474747; --ring: rgba(255,255,255,0.10);
30
+ --human: #4a4f58;
31
+ --d0: #3a2422; --d1: #6a2b28; --d2: #a23533; --d3: #dc3c3d; --d4: #ff7a6e;
32
+ --d-none: #2b2e34; --d-ok: #1d4426; --accent: #338ced;
33
+ }
34
+ * { box-sizing: border-box; }
35
+ html, body { margin: 0; }
36
+ body { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; }
37
+ .viz-root { background: var(--page); color: var(--ink); min-height: 100vh; padding: 28px 20px 48px; }
38
+ .wrap { max-width: 1180px; margin: 0 auto; display: grid; gap: 16px; }
39
+ header { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
40
+ .brand { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
41
+ .brand b { font-size: 15px; letter-spacing: .02em; }
42
+ .brand h1 { margin: 0; font-size: 24px; font-weight: 650; }
43
+ .meta { color: var(--ink-2); font-size: 13px; }
44
+ button.theme { background: var(--surface); color: var(--ink); border: 1px solid var(--ring); border-radius: 8px; padding: 6px 10px; font: inherit; font-size: 13px; cursor: pointer; }
45
+ .card { background: var(--surface); border: 1px solid var(--ring); border-radius: 12px; padding: 20px; }
46
+ .card h2 { margin: 0 0 4px; font-size: 16px; font-weight: 650; }
47
+ .card .sub { margin: 0 0 16px; color: var(--ink-2); font-size: 13px; }
48
+ .hero { display: grid; grid-template-columns: minmax(260px, 1.3fr) repeat(4, minmax(140px, 1fr)); gap: 16px; }
49
+ .hero .big { font-size: 56px; font-weight: 700; line-height: 1; margin: 6px 0 8px; }
50
+ .hero .label { color: var(--ink-2); font-size: 13px; }
51
+ .tile .v { font-size: 28px; font-weight: 650; margin: 6px 0 4px; }
52
+ .tile .s { color: var(--ink-2); font-size: 12px; }
53
+ .bar { display: flex; gap: 2px; height: 22px; border-radius: 4px; overflow: hidden; }
54
+ .bar span { display: block; height: 100%; min-width: 0; }
55
+ .legend { display: flex; flex-wrap: wrap; gap: 8px 20px; margin-top: 12px; font-size: 13px; }
56
+ .legend .k { display: inline-flex; align-items: center; gap: 7px; }
57
+ .legend .n { color: var(--ink-2); font-variant-numeric: tabular-nums; }
58
+ .sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; flex: none; }
59
+ .ico { width: 14px; height: 14px; flex: none; }
60
+ .crumbs { display: flex; gap: 6px; flex-wrap: wrap; font-size: 13px; margin-bottom: 10px; }
61
+ .crumbs a { color: var(--accent); cursor: pointer; text-decoration: none; }
62
+ .crumbs a:hover { text-decoration: underline; }
63
+ .crumbs span { color: var(--ink-2); }
64
+ .tm-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
65
+ .scale { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); }
66
+ .scale .steps { display: flex; gap: 2px; }
67
+ .scale .steps i { width: 26px; height: 10px; display: block; }
68
+ .scale .steps i:first-child { border-radius: 3px 0 0 3px; } .scale .steps i:last-child { border-radius: 0 3px 3px 0; }
69
+ #treemap { position: relative; height: 540px; border-radius: 6px; overflow: hidden; background: var(--surface); }
70
+ .cell { position: absolute; border: 2px solid var(--surface); border-radius: 6px; overflow: hidden; padding: 6px 8px; font-size: 12px; line-height: 1.25; cursor: default; }
71
+ .cell.dir { cursor: zoom-in; }
72
+ .cell .nm { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
73
+ .cell .pc { opacity: .85; font-variant-numeric: tabular-nums; }
74
+ .cell.dir .nm::after { content: " /"; opacity: .6; }
75
+ .cell:hover { outline: 2px solid var(--ink); outline-offset: -2px; z-index: 2; }
76
+ .frame { position: absolute; border-radius: 6px; background: var(--surface); }
77
+ .frame > .lbl { position: absolute; left: 2px; right: 2px; top: 0; height: 20px; padding: 3px 6px; font-size: 12px; font-weight: 600; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: zoom-in; }
78
+ .frame > .lbl:hover { color: var(--accent); }
79
+ .cell.crit::before { content: "★"; position: absolute; right: 6px; top: 4px; font-size: 11px; }
80
+ #tip { position: fixed; pointer-events: none; z-index: 20; background: var(--surface); color: var(--ink); border: 1px solid var(--ring); border-radius: 8px; padding: 10px 12px; font-size: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.18); max-width: 340px; display: none; }
81
+ #tip .t { font-weight: 650; margin-bottom: 6px; word-break: break-all; }
82
+ #tip .r { display: flex; justify-content: space-between; gap: 18px; font-variant-numeric: tabular-nums; }
83
+ #tip .r span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
84
+ #tip .x { color: var(--ink-2); margin-top: 6px; }
85
+ table { width: 100%; border-collapse: collapse; font-size: 13px; }
86
+ th { text-align: left; color: var(--ink-2); font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--axis); white-space: nowrap; }
87
+ td { padding: 8px 10px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
88
+ td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
89
+ td.path { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; word-break: break-all; }
90
+ .mini { display: flex; gap: 2px; height: 10px; width: 140px; border-radius: 3px; overflow: hidden; }
91
+ .mini span { display: block; height: 100%; }
92
+ .pill { display: inline-block; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--ring); font-size: 12px; margin: 1px 2px 1px 0; white-space: nowrap; }
93
+ .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
94
+ .tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
95
+ .tools input[type=search] { flex: 1; min-width: 200px; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--axis); background: var(--surface); color: var(--ink); font: inherit; font-size: 13px; }
96
+ .tools label { font-size: 13px; color: var(--ink-2); display: inline-flex; gap: 6px; align-items: center; }
97
+ .empty { color: var(--ink-2); font-size: 13px; padding: 12px 0; }
98
+ footer { color: var(--ink-2); font-size: 12px; line-height: 1.6; }
99
+ footer code { font-size: 12px; }
100
+ .t1{--c:#257de0}.t2{--c:#f47230}.t3{--c:#00b894}.t4{--c:#f2a600}.t5{--c:#ee7fac}.t6{--c:#6a4ce2}
101
+ :root[data-theme="dark"] .t1{--c:#338ced} :root[data-theme="dark"] .t2{--c:#e76624} :root[data-theme="dark"] .t3{--c:#00a888} :root[data-theme="dark"] .t4{--c:#d28e05} :root[data-theme="dark"] .t5{--c:#e24d8b} :root[data-theme="dark"] .t6{--c:#9887ef}
102
+ @media (prefers-color-scheme: dark) { :root:where(:not([data-theme="light"])) .t1{--c:#338ced} :root:where(:not([data-theme="light"])) .t2{--c:#e76624} :root:where(:not([data-theme="light"])) .t3{--c:#00a888} :root:where(:not([data-theme="light"])) .t4{--c:#d28e05} :root:where(:not([data-theme="light"])) .t5{--c:#e24d8b} :root:where(:not([data-theme="light"])) .t6{--c:#9887ef} }
103
+ #trend svg { display: block; width: 100%; height: 260px; overflow: visible; }
104
+ #trend text { fill: var(--ink-2); font-size: 11px; font-variant-numeric: tabular-nums; }
105
+ #trend .grid line { stroke: var(--grid); } #trend .base { stroke: var(--axis); }
106
+ #trend rect.hit { fill: transparent; } #trend g.col:hover rect.hit { fill: var(--ring); }
107
+ .note { margin-top: 4px; font-size: 13px; color: var(--ink-2); }
108
+ @media (max-width: 900px) { .hero { grid-template-columns: 1fr 1fr; } .hero .main { grid-column: 1 / -1; } .grid2 { grid-template-columns: 1fr; } #treemap { height: 420px; } }
109
+ @media (forced-colors: active) { .cell { border: 1px solid CanvasText; } }
110
+ </style>
111
+ </head>
112
+ <body>
113
+ <div class="viz-root">
114
+ <div class="wrap">
115
+ <header>
116
+ <div><div class="brand"><b>grokmap</b><h1 id="repo"></h1><span class="meta" id="meta"></span></div><div class="note" id="note" hidden></div></div>
117
+ <button class="theme" id="theme" type="button" aria-label="Toggle light and dark theme">Theme: auto</button>
118
+ </header>
119
+
120
+ <section class="hero">
121
+ <div class="card main">
122
+ <div class="label">Comprehension debt</div>
123
+ <div class="big" id="debt"></div>
124
+ <div class="label" id="debt-sub"></div>
125
+ </div>
126
+ <div class="card tile"><div class="label">Written by AI</div><div class="v" id="t-ai"></div><div class="s" id="t-ai-s"></div></div>
127
+ <div class="card tile"><div class="label">AI code understood</div><div class="v" id="t-und"></div><div class="s" id="t-und-s"></div></div>
128
+ <div class="card tile"><div class="label">Lines scanned</div><div class="v" id="t-lines"></div><div class="s" id="t-lines-s"></div></div>
129
+ <div class="card tile"><div class="label" id="t-x-l">People with verified understanding</div><div class="v" id="t-x"></div><div class="s" id="t-x-s"></div></div>
130
+ </section>
131
+
132
+ <section class="card">
133
+ <h2>Every meaningful line, by who understands it</h2>
134
+ <p class="sub">Blank lines and lone brackets are not counted.</p>
135
+ <div class="bar" id="bar" role="img"></div>
136
+ <div class="legend" id="bar-legend"></div>
137
+ </section>
138
+
139
+ <section class="card" id="trend-card" hidden>
140
+ <h2>Who wrote the code, over time</h2>
141
+ <p class="sub" id="trend-sub">Lines added per period, by people and by each coding agent. Merge commits are skipped.</p>
142
+ <div id="trend"></div>
143
+ <div class="legend" id="trend-legend"></div>
144
+ </section>
145
+
146
+ <section class="card">
147
+ <div class="tm-head">
148
+ <div><h2>Where the debt is</h2><p class="sub">Box size = lines of code. Color = comprehension debt. Click a folder to zoom in. ★ = critical path.</p></div>
149
+ <div class="scale" aria-hidden="true"><span>no AI code</span><i class="sw" style="background:var(--d-none)"></i><span style="margin-left:8px">AI, all understood</span><i class="sw" style="background:var(--d-ok)"></i><span style="margin-left:8px">debt &gt;0%</span><span class="steps"><i style="background:var(--d0)"></i><i style="background:var(--d1)"></i><i style="background:var(--d2)"></i><i style="background:var(--d3)"></i><i style="background:var(--d4)"></i></span><span>75%+</span></div>
150
+ </div>
151
+ <nav class="crumbs" id="crumbs" aria-label="Folder path"></nav>
152
+ <div id="treemap" role="img" aria-label="Treemap of files colored by comprehension debt"></div>
153
+ </section>
154
+
155
+ <section class="card">
156
+ <h2>Riskiest files</h2>
157
+ <p class="sub">Sorted by debt lines: AI-written lines nobody has shown they understand (fading and skimmed count half).</p>
158
+ <div class="tools"><input id="q" type="search" placeholder="Filter by path…" aria-label="Filter files by path"><label><input type="checkbox" id="all"> show all files</label></div>
159
+ <div style="overflow-x:auto"><table id="files"><thead><tr><th>File</th><th class="num">Lines</th><th class="num">AI lines</th><th class="num">Unread</th><th class="num">Debt</th><th>Breakdown</th><th>Written by</th><th>Understood by</th></tr></thead><tbody></tbody></table></div>
160
+ </section>
161
+
162
+ <section class="grid2">
163
+ <div class="card"><h2>By coding agent</h2><p class="sub">Which tools wrote the code that is still in the repo.</p><table id="by-tool"><thead><tr><th>Agent</th><th class="num">Lines</th><th class="num">Share of AI code</th><th class="num">Understood</th></tr></thead><tbody></tbody></table></div>
164
+ <div class="card"><h2>By person</h2><p class="sub">AI-written lines each person has shown they understand.</p><table id="by-person"><thead><tr><th>Person</th><th class="num">Lines understood</th><th class="num">Share of AI code</th></tr></thead><tbody></tbody></table></div>
165
+ </section>
166
+
167
+ <footer id="foot"></footer>
168
+ </div>
169
+ <div id="tip" role="tooltip"></div>
170
+ </div>
171
+
172
+ <script>
173
+ const DATA = /*__GROKMAP_DATA__*/null;
174
+ const STATES = [
175
+ { key: "h", name: "Written by people", css: "--human", icon: "circle" },
176
+ { key: "u", name: "AI · understood", css: "--understood", icon: "check" },
177
+ { key: "f", name: "AI · understanding fading", css: "--fading", icon: "clock" },
178
+ { key: "s", name: "AI · only skimmed", css: "--skimmed", icon: "half" },
179
+ { key: "x", name: "AI · nobody has checked", css: "--unread", icon: "alert" },
180
+ ];
181
+ const ICONS = {
182
+ circle: '<circle cx="7" cy="7" r="5" fill="VAR"/>',
183
+ check: '<circle cx="7" cy="7" r="6" fill="VAR"/><path d="M4 7.2l2 2 4-4.4" stroke="#fff" stroke-width="1.8" fill="none" stroke-linecap="round" stroke-linejoin="round"/>',
184
+ clock: '<circle cx="7" cy="7" r="6" fill="VAR"/><path d="M7 3.8V7l2 1.4" stroke="#0b0b0b" stroke-width="1.6" fill="none" stroke-linecap="round"/>',
185
+ half: '<circle cx="7" cy="7" r="5.2" fill="none" stroke="VAR" stroke-width="1.8"/><path d="M7 1.8a5.2 5.2 0 0 1 0 10.4z" fill="VAR"/>',
186
+ alert: '<path d="M7 1l6.3 11H.7z" fill="VAR"/><path d="M7 5v3.2" stroke="#fff" stroke-width="1.6" stroke-linecap="round"/><circle cx="7" cy="10.2" r=".9" fill="#fff"/>',
187
+ };
188
+ const icon = (name, css) => `<svg class="ico" viewBox="0 0 14 14" aria-hidden="true">${ICONS[name].replaceAll("VAR", `var(${css})`)}</svg>`;
189
+ const fmt = n => n.toLocaleString("en-US");
190
+ const pct = (a, b) => b ? (100 * a / b) : 0;
191
+ const p1 = v => (v < 10 && v > 0 ? v.toFixed(1) : Math.round(v)) + "%";
192
+ const esc = s => String(s).replace(/[&<>"]/g, c => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" }[c]));
193
+ const $ = id => document.getElementById(id);
194
+
195
+ // ---------- theme ----------
196
+ (function themeToggle() {
197
+ const order = ["auto", "light", "dark"]; let i = 0;
198
+ try { const saved = localStorage.getItem("grokmap-theme"); if (order.includes(saved)) i = order.indexOf(saved); } catch (e) {}
199
+ const apply = () => {
200
+ const m = order[i];
201
+ if (m === "auto") document.documentElement.removeAttribute("data-theme"); else document.documentElement.setAttribute("data-theme", m);
202
+ $("theme").textContent = "Theme: " + m;
203
+ };
204
+ $("theme").addEventListener("click", () => { i = (i + 1) % 3; try { localStorage.setItem("grokmap-theme", order[i]); } catch (e) {} apply(); });
205
+ apply();
206
+ })();
207
+
208
+ // ---------- header + hero ----------
209
+ const T = DATA.total;
210
+ const ai = T.ai;
211
+ $("repo").textContent = DATA.repo;
212
+ $("meta").textContent = `HEAD ${DATA.head} · ${DATA.generated} · grokmap ${DATA.version}`;
213
+ $("debt").textContent = ai ? p1(T.debt_pct) : "0%";
214
+ $("debt-sub").textContent = ai
215
+ ? `${fmt(Math.round(T.debt_lines))} of ${fmt(T.lines)} lines are AI-written code no one has shown they understand.`
216
+ : "No AI-written code found in this repository's history.";
217
+ $("t-ai").textContent = p1(T.ai_pct);
218
+ $("t-ai-s").textContent = `${fmt(ai)} lines`;
219
+ $("t-und").textContent = ai ? p1(pct(T.understood, ai)) : "–";
220
+ $("t-und-s").textContent = ai ? `${fmt(T.understood)} of ${fmt(ai)} AI lines` : "nothing to understand yet";
221
+ $("t-lines").textContent = fmt(T.lines);
222
+ $("t-lines-s").textContent = `${fmt(DATA.files.length)} files`;
223
+ if (DATA.critical) {
224
+ $("t-x-l").textContent = "Debt on critical paths";
225
+ $("t-x").textContent = DATA.critical.ai ? p1(DATA.critical.debt_pct) : "0%";
226
+ $("t-x-s").textContent = `${fmt(DATA.critical.lines)} lines marked critical`;
227
+ } else {
228
+ const people = Object.keys(T.people);
229
+ $("t-x").textContent = people.length;
230
+ $("t-x-s").textContent = people.length ? people.slice(0, 2).join(", ") + (people.length > 2 ? "…" : "") : "run grokmap quiz";
231
+ }
232
+
233
+ // ---------- stacked bar ----------
234
+ const counts = { h: T.human, u: T.understood, f: T.fading, s: T.skimmed, x: T.unread };
235
+ $("bar").setAttribute("aria-label", STATES.map(s => `${s.name}: ${counts[s.key]} lines`).join(", "));
236
+ $("bar").innerHTML = STATES.filter(s => counts[s.key] > 0)
237
+ .map(s => `<span style="flex:${counts[s.key]} 1 0;background:var(${s.css})" data-k="${s.key}"></span>`).join("");
238
+ $("bar-legend").innerHTML = STATES.map(s =>
239
+ `<span class="k">${icon(s.icon, s.css)}${s.name} <span class="n">${fmt(counts[s.key])} · ${p1(pct(counts[s.key], T.lines))}</span></span>`).join("");
240
+ $("bar").querySelectorAll("span").forEach(el => {
241
+ const s = STATES.find(x => x.key === el.dataset.k);
242
+ el.addEventListener("mousemove", e => showTip(e, `<div class="t">${s.name}</div><div class="r"><span>Lines</span><span>${fmt(counts[s.key])}</span></div><div class="r"><span>Share</span><span>${p1(pct(counts[s.key], T.lines))}</span></div>`));
243
+ el.addEventListener("mouseleave", hideTip);
244
+ });
245
+
246
+ // ---------- tooltip ----------
247
+ const tip = $("tip");
248
+ function showTip(e, html) {
249
+ tip.innerHTML = html; tip.style.display = "block";
250
+ const pad = 14, w = tip.offsetWidth, h = tip.offsetHeight;
251
+ let x = e.clientX + pad, y = e.clientY + pad;
252
+ if (x + w > innerWidth - 8) x = e.clientX - w - pad;
253
+ if (y + h > innerHeight - 8) y = e.clientY - h - pad;
254
+ tip.style.left = x + "px"; tip.style.top = y + "px";
255
+ }
256
+ function hideTip() { tip.style.display = "none"; }
257
+ function nodeTip(n) {
258
+ const rows = STATES.map(s => `<div class="r"><span>${icon(s.icon, s.css)}${s.name}</span><span>${fmt(n[s.key])}</span></div>`).join("");
259
+ const tools = Object.keys(n.t || {}); const people = Object.keys(n.k || {});
260
+ return `<div class="t">${esc(n.path || DATA.repo)}${n.dir ? "/" : ""}</div>
261
+ <div class="r"><span>Comprehension debt</span><span><b>${n.ai ? p1(pct(n.d, n.n)) : "no AI code"}</b></span></div>
262
+ <div class="r"><span>Lines</span><span>${fmt(n.n)}</span></div>${rows}
263
+ ${tools.length ? `<div class="x">Written by ${tools.map(esc).join(", ")}</div>` : ""}
264
+ ${people.length ? `<div class="x">Understood by ${people.map(esc).join(", ")}</div>` : (n.ai ? `<div class="x">Nobody has shown they understand this yet.</div>` : "")}
265
+ ${n.dir ? `<div class="x">Click to zoom in</div>` : ""}`;
266
+ }
267
+
268
+ // ---------- tree ----------
269
+ function buildTree(files) {
270
+ const root = { name: DATA.repo, path: "", dir: true, children: new Map() };
271
+ for (const f of files) {
272
+ const parts = f.p.split("/"); let node = root;
273
+ for (let i = 0; i < parts.length - 1; i++) {
274
+ const path = parts.slice(0, i + 1).join("/");
275
+ if (!node.children.has(parts[i])) node.children.set(parts[i], { name: parts[i], path, dir: true, children: new Map() });
276
+ node = node.children.get(parts[i]);
277
+ }
278
+ node.children.set(parts[parts.length - 1], { name: parts[parts.length - 1], path: f.p, dir: false, ...f });
279
+ }
280
+ (function sum(n) {
281
+ if (!n.dir) { n.ai = n.u + n.f + n.s + n.x; return; }
282
+ Object.assign(n, { n: 0, h: 0, u: 0, f: 0, s: 0, x: 0, d: 0, t: {}, k: {}, c: false });
283
+ for (const c of n.children.values()) {
284
+ sum(c);
285
+ for (const k of ["n", "h", "u", "f", "s", "x", "d"]) n[k] += c[k];
286
+ for (const [a, v] of Object.entries(c.t || {})) n.t[a] = (n.t[a] || 0) + v;
287
+ for (const [a, v] of Object.entries(c.k || {})) n.k[a] = (n.k[a] || 0) + v;
288
+ n.c = n.c || c.c;
289
+ }
290
+ n.ai = n.u + n.f + n.s + n.x;
291
+ })(root);
292
+ // collapse single-child folder chains (src/main/java/... -> one box)
293
+ (function collapse(n) {
294
+ if (!n.dir) return;
295
+ for (const [key, c] of [...n.children]) {
296
+ let cur = c, label = c.name;
297
+ while (cur.dir && cur.children.size === 1 && [...cur.children.values()][0].dir) {
298
+ cur = [...cur.children.values()][0]; label += "/" + cur.name;
299
+ }
300
+ if (cur !== c) { cur = Object.assign({}, cur, { name: label }); n.children.set(key, cur); }
301
+ collapse(cur);
302
+ }
303
+ })(root);
304
+ return root;
305
+ }
306
+ const ROOT = buildTree(DATA.files);
307
+ let current = ROOT; const trail = [ROOT];
308
+
309
+ function debtColor(n) {
310
+ if (!n.ai) return ["var(--d-none)", "var(--ink)"];
311
+ const v = pct(n.d, n.n);
312
+ if (n.d === 0) return ["var(--d-ok)", "var(--ink)"];
313
+ const i = v < 5 ? 0 : v < 15 ? 1 : v < 35 ? 2 : v < 60 ? 3 : 4;
314
+ const dark = document.documentElement.getAttribute("data-theme") === "dark" ||
315
+ (!document.documentElement.getAttribute("data-theme") && matchMedia("(prefers-color-scheme: dark)").matches);
316
+ const ink = dark ? (i >= 3 ? "#0b0b0b" : "#efefef") : (i >= 3 ? "#ffffff" : "#191919");
317
+ return [`var(--d${i})`, ink];
318
+ }
319
+
320
+ // squarified treemap (Bruls, Huizing, van Wijk)
321
+ function squarify(items, x, y, w, h) {
322
+ const out = []; const total = items.reduce((a, b) => a + b.v, 0); if (!total) return out;
323
+ const scale = (w * h) / total; let rest = items.map(it => ({ ...it, a: it.v * scale }));
324
+ while (rest.length) {
325
+ const short = Math.min(w, h); let row = [], best = Infinity;
326
+ for (const it of rest) {
327
+ const trial = [...row, it]; const s = trial.reduce((a, b) => a + b.a, 0);
328
+ const worst = Math.max(...trial.map(t => Math.max((short * short * t.a) / (s * s), (s * s) / (short * short * t.a))));
329
+ if (worst > best) break; best = worst; row = trial;
330
+ }
331
+ const s = row.reduce((a, b) => a + b.a, 0);
332
+ if (w >= h) { const cw = s / h; let cy = y; for (const it of row) { const ch = it.a / cw; out.push({ ...it, x, y: cy, w: cw, h: ch }); cy += ch; } x += cw; w -= cw; }
333
+ else { const ch = s / w; let cx = x; for (const it of row) { const cw = it.a / ch; out.push({ ...it, x: cx, y, w: cw, h: ch }); cx += cw; } y += ch; h -= ch; }
334
+ rest = rest.slice(row.length);
335
+ }
336
+ return out;
337
+ }
338
+
339
+ function leafCell(el, n, r) {
340
+ const [bg, ink] = debtColor(n);
341
+ const d = document.createElement("div");
342
+ d.className = "cell" + (n.dir ? " dir" : "") + (n.c ? " crit" : "");
343
+ Object.assign(d.style, { left: r.x + "px", top: r.y + "px", width: Math.max(0, r.w) + "px", height: Math.max(0, r.h) + "px", background: bg, color: ink });
344
+ if (r.w > 46 && r.h > 22) d.innerHTML = `<div class="nm">${esc(n.name)}</div>` + (r.h > 40 && r.w > 70 ? `<div class="pc">${n.ai ? p1(pct(n.d, n.n)) + " debt" : "no AI"}</div>` : "");
345
+ d.addEventListener("mousemove", e => showTip(e, nodeTip(n)));
346
+ d.addEventListener("mouseleave", hideTip);
347
+ if (n.dir) d.addEventListener("click", () => zoomTo(n));
348
+ el.appendChild(d);
349
+ }
350
+ function zoomTo(n) { hideTip(); current = n; trail.push(n); drawAll(); }
351
+ // lay out a folder's children; folders big enough get their own labelled frame with files inside
352
+ function layout(el, node, x, y, w, h, depth) {
353
+ const kids = [...node.children.values()].filter(c => c.n > 0).sort((a, b) => b.n - a.n);
354
+ const rects = squarify(kids.map(c => ({ v: c.n, node: c })), x, y, w, h);
355
+ for (const r of rects) {
356
+ const n = r.node;
357
+ if (n.dir && depth < 2 && r.w > 90 && r.h > 70 && n.children.size > 1) {
358
+ const f = document.createElement("div");
359
+ f.className = "frame";
360
+ Object.assign(f.style, { left: r.x + "px", top: r.y + "px", width: r.w + "px", height: r.h + "px" });
361
+ const lbl = document.createElement("div");
362
+ lbl.className = "lbl";
363
+ lbl.textContent = `${n.name}/ · ${n.ai ? p1(pct(n.d, n.n)) + " debt" : "no AI"}`;
364
+ lbl.addEventListener("mousemove", e => showTip(e, nodeTip(n)));
365
+ lbl.addEventListener("mouseleave", hideTip);
366
+ lbl.addEventListener("click", () => zoomTo(n));
367
+ f.appendChild(lbl);
368
+ el.appendChild(f);
369
+ layout(el, n, r.x + 2, r.y + 20, r.w - 4, r.h - 22, depth + 1);
370
+ } else {
371
+ leafCell(el, n, r);
372
+ }
373
+ }
374
+ }
375
+ function drawTreemap() {
376
+ const el = $("treemap"); const W = el.clientWidth, H = el.clientHeight;
377
+ el.innerHTML = "";
378
+ if (![...current.children.values()].some(c => c.n > 0)) { el.innerHTML = '<div class="empty" style="padding:20px">No files to show.</div>'; return; }
379
+ layout(el, current, 0, 0, W, H, 0);
380
+ }
381
+ function drawCrumbs() {
382
+ $("crumbs").innerHTML = trail.map((n, i) => i === trail.length - 1
383
+ ? `<span>${esc(n.name)}</span>` : `<a data-i="${i}">${esc(n.name)}</a><span>/</span>`).join("");
384
+ $("crumbs").querySelectorAll("a").forEach(a => a.addEventListener("click", () => { trail.length = +a.dataset.i + 1; current = trail[trail.length - 1]; drawAll(); }));
385
+ }
386
+ function drawAll() { drawCrumbs(); drawTreemap(); }
387
+
388
+ // ---------- tables ----------
389
+ function mini(f) {
390
+ return `<div class="mini" aria-hidden="true">${STATES.filter(s => f[s.key] > 0).map(s => `<span style="flex:${f[s.key]} 1 0;background:var(${s.css})"></span>`).join("")}</div>`;
391
+ }
392
+ function drawFiles() {
393
+ const q = $("q").value.trim().toLowerCase(); const all = $("all").checked;
394
+ let rows = DATA.files.filter(f => !q || f.p.toLowerCase().includes(q));
395
+ rows.sort((a, b) => b.d - a.d || b.n - a.n);
396
+ if (!all) rows = rows.filter(f => f.d > 0).slice(0, 15);
397
+ const tb = $("files").querySelector("tbody");
398
+ if (!rows.length) { tb.innerHTML = `<tr><td colspan="8" class="empty">${q ? "No files match." : "No comprehension debt. Every AI-written line has been understood by someone."}</td></tr>`; return; }
399
+ tb.innerHTML = rows.map(f => {
400
+ const aiN = f.u + f.f + f.s + f.x;
401
+ return `<tr><td class="path">${f.c ? "★ " : ""}${esc(f.p)}</td><td class="num">${fmt(f.n)}</td><td class="num">${fmt(aiN)}</td><td class="num">${fmt(f.x)}</td>
402
+ <td class="num">${aiN ? p1(pct(f.d, f.n)) : "–"}</td><td>${mini(f)}</td>
403
+ <td>${Object.keys(f.t).map(t => `<span class="pill">${esc(t)}</span>`).join("") || "–"}</td>
404
+ <td>${Object.keys(f.k).map(k => `<span class="pill">${esc(k)}</span>`).join("") || (aiN ? "nobody yet" : "–")}</td></tr>`;
405
+ }).join("");
406
+ }
407
+ function drawSide() {
408
+ const tools = Object.entries(T.tools);
409
+ const toolUnd = {};
410
+ for (const f of DATA.files) { const a = f.u + f.f + f.s + f.x; if (!a) continue; for (const [t, v] of Object.entries(f.t)) { toolUnd[t] = (toolUnd[t] || 0) + v * (f.u / a); } }
411
+ $("by-tool").querySelector("tbody").innerHTML = tools.length ? tools.map(([t, v]) =>
412
+ `<tr><td>${esc(t)}</td><td class="num">${fmt(v)}</td><td class="num">${p1(pct(v, ai))}</td><td class="num">${p1(pct(toolUnd[t] || 0, v))}</td></tr>`).join("")
413
+ : `<tr><td colspan="4" class="empty">No AI-written code detected.</td></tr>`;
414
+ const people = Object.entries(T.people);
415
+ $("by-person").querySelector("tbody").innerHTML = people.length ? people.map(([p, v]) =>
416
+ `<tr><td>${esc(p)}</td><td class="num">${fmt(v)}</td><td class="num">${p1(pct(v, ai))}</td></tr>`).join("")
417
+ : `<tr><td colspan="3" class="empty">Nobody yet. Run <code>grokmap quiz</code> in your coding agent to start.</td></tr>`;
418
+ }
419
+ $("q").addEventListener("input", drawFiles);
420
+ $("all").addEventListener("change", drawFiles);
421
+ $("foot").innerHTML = `How this is measured: each meaningful line at HEAD is traced with <code>git blame</code> to the commit that wrote it. Commits carrying an AI agent's marker (for example a <code>Co-Authored-By: Claude</code> trailer, a Copilot or Cursor bot author) count as AI-written. A line counts as understood when someone passed a <code>grokmap quiz</code> on it; if the line changes later, it needs understanding again. Understanding older than the decay window counts as fading. Debt = unread lines + half of skimmed and fading lines, divided by all lines.`;
422
+
423
+ // ---------- trend ----------
424
+ function drawTrend() {
425
+ const tr = DATA.trend; if (!tr || tr.periods.filter(p => p.human + Object.values(p.tools).reduce((a, b) => a + b, 0) > 0).length < 2) return;
426
+ $("trend-card").hidden = false;
427
+ const tools = Object.keys(tr.summary.tools); const shown = tools.slice(0, 5); const other = tools.length > 5;
428
+ const series = [{ key: "human", name: "People", fill: "var(--human)" }]
429
+ .concat(shown.map((t, i) => ({ key: t, name: t, cls: "t" + (i + 1), fill: "var(--c)" })))
430
+ .concat(other ? [{ key: "__other", name: "Other agents", cls: "t6", fill: "var(--c)" }] : []);
431
+ const val = (p, k) => k === "human" ? p.human : k === "__other" ? Object.entries(p.tools).filter(([t]) => !shown.includes(t)).reduce((a, [, v]) => a + v, 0) : (p.tools[k] || 0);
432
+ const P = tr.periods, totals = P.map(p => series.reduce((a, s) => a + val(p, s.key), 0));
433
+ const W = $("trend").clientWidth || 900, H = 260, L = 44, B = 24, T = 8;
434
+ const max = Math.max(...totals, 1), step = Math.pow(10, Math.floor(Math.log10(max))), top = Math.ceil(max / step) * step;
435
+ const y = v => T + (H - T - B) * (1 - v / top), bw = (W - L) / P.length, gap = Math.min(2, bw * 0.2);
436
+ let svg = `<svg viewBox="0 0 ${W} ${H}" role="img" aria-label="Stacked bars of lines added per ${tr.by}"><g class="grid">`;
437
+ for (let i = 0; i <= 4; i++) { const v = top * i / 4; svg += `<line x1="${L}" x2="${W}" y1="${y(v)}" y2="${y(v)}"/><text x="${L - 6}" y="${y(v) + 4}" text-anchor="end">${fmt(Math.round(v))}</text>`; }
438
+ svg += `</g>`;
439
+ const every = Math.max(1, Math.ceil(P.length / 10));
440
+ P.forEach((p, i) => {
441
+ const x = L + i * bw; let acc = 0; svg += `<g class="col" data-i="${i}"><rect class="hit" x="${x}" y="${T}" width="${bw}" height="${H - T - B}"/>`;
442
+ const segs = series.map(s => ({ s, v: val(p, s.key) })).filter(o => o.v > 0);
443
+ segs.forEach((o, j) => {
444
+ const y0 = y(acc), y1 = y(acc + o.v); acc += o.v;
445
+ const h = Math.max(0, y0 - y1 - (j < segs.length - 1 ? 2 : 0));
446
+ const r = j === segs.length - 1 ? Math.min(4, h, (bw - gap) / 2) : 0;
447
+ const w = Math.max(1, bw - gap), xx = x + gap / 2, yy = y1;
448
+ svg += r > 0 ? `<path class="${o.s.cls || ""}" fill="${o.s.fill}" d="M${xx},${yy + h} V${yy + r} Q${xx},${yy} ${xx + r},${yy} H${xx + w - r} Q${xx + w},${yy} ${xx + w},${yy + r} V${yy + h} Z"/>`
449
+ : `<rect class="${o.s.cls || ""}" fill="${o.s.fill}" x="${xx}" y="${yy}" width="${w}" height="${h}"/>`;
450
+ });
451
+ if (i % every === 0) svg += `<text x="${x + bw / 2}" y="${H - 6}" text-anchor="middle">${tr.by === "month" ? p.start.slice(0, 7) : p.start.slice(5)}</text>`;
452
+ svg += `</g>`;
453
+ });
454
+ svg += `<line class="base" x1="${L}" x2="${W}" y1="${y(0)}" y2="${y(0)}"/></svg>`;
455
+ $("trend").innerHTML = svg;
456
+ $("trend").querySelectorAll("g.col").forEach(g => {
457
+ const p = P[+g.dataset.i], tot = totals[+g.dataset.i];
458
+ g.addEventListener("mousemove", e => showTip(e, `<div class="t">${tr.by === "month" ? "Month of " + p.start.slice(0, 7) : "Week of " + p.start}</div>` +
459
+ series.map(s => `<div class="r"><span><i class="sw ${s.cls || ""}" style="background:${s.fill}"></i>${esc(s.name)}</span><span>${fmt(val(p, s.key))}</span></div>`).join("") +
460
+ `<div class="r"><span>AI share</span><span><b>${tot ? p1(pct(tot - p.human, tot)) : "–"}</b></span></div>`));
461
+ g.addEventListener("mouseleave", hideTip);
462
+ });
463
+ $("trend-legend").innerHTML = series.map(s => `<span class="k"><i class="sw ${s.cls || ""}" style="background:${s.fill}"></i>${esc(s.name)} <span class="n">${fmt(s.key === "human" ? tr.summary.human : s.key === "__other" ? tools.slice(5).reduce((a, t) => a + tr.summary.tools[t], 0) : tr.summary.tools[s.key])}</span></span>`).join("");
464
+ $("trend-sub").textContent = `Lines added per ${tr.by}: ${p1(tr.summary.ai_pct)} written by AI agents. Merge commits are skipped.`;
465
+ }
466
+ if (DATA.note) { $("note").textContent = DATA.note; $("note").hidden = false; }
467
+ drawAll(); drawFiles(); drawSide(); drawTrend();
468
+ let rt2; addEventListener("resize", () => { clearTimeout(rt2); rt2 = setTimeout(() => { if (!$("trend-card").hidden) drawTrend(); }, 150); });
469
+ let rt; addEventListener("resize", () => { clearTimeout(rt); rt = setTimeout(drawTreemap, 120); });
470
+ matchMedia("(prefers-color-scheme: dark)").addEventListener("change", drawTreemap);
471
+ new MutationObserver(drawTreemap).observe(document.documentElement, { attributes: true, attributeFilter: ["data-theme"] });
472
+ </script>
473
+ </body>
474
+ </html>