skilltally 1.0.2 → 1.1.0
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.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/CHANGELOG.md +19 -0
- package/README.md +12 -5
- package/bin/cli.mjs +163 -1
- package/bin/track.mjs +87 -3
- package/gemini-extension.json +1 -1
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/skills/skilltally/SKILL.md +23 -8
- package/src/core/normalize.mjs +1 -1
- package/src/install/antigravity.mjs +1 -1
- package/src/install/prune.mjs +355 -0
- package/src/mcp/server.mjs +345 -0
- package/src/report/aggregate.mjs +206 -17
- package/src/report/chains.mjs +187 -0
- package/src/report/dashboard.mjs +1245 -0
- package/src/report/format.mjs +223 -2
|
@@ -0,0 +1,1245 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
|
|
3
|
+
function serializePayload(data) {
|
|
4
|
+
return JSON.stringify(data)
|
|
5
|
+
.replace(/</g, '\\u003c')
|
|
6
|
+
.replace(/\u2028/g, '\\u2028')
|
|
7
|
+
.replace(/\u2029/g, '\\u2029');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function openInBrowser(filePath, platform = process.platform) {
|
|
11
|
+
try {
|
|
12
|
+
let cmd;
|
|
13
|
+
let args;
|
|
14
|
+
if (platform === 'darwin') {
|
|
15
|
+
cmd = 'open';
|
|
16
|
+
args = [filePath];
|
|
17
|
+
} else if (platform === 'win32') {
|
|
18
|
+
cmd = 'cmd';
|
|
19
|
+
args = ['/c', 'start', '', filePath];
|
|
20
|
+
} else {
|
|
21
|
+
cmd = 'xdg-open';
|
|
22
|
+
args = [filePath];
|
|
23
|
+
}
|
|
24
|
+
const res = spawnSync(cmd, args, { stdio: 'ignore', timeout: 5000 });
|
|
25
|
+
return { opened: res.status === 0, status: res.status };
|
|
26
|
+
} catch (err) {
|
|
27
|
+
return { opened: false, error: err.message };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function generateDashboardHtml({
|
|
32
|
+
stats,
|
|
33
|
+
timeline,
|
|
34
|
+
dailyTimeline,
|
|
35
|
+
chains,
|
|
36
|
+
inventory,
|
|
37
|
+
generatedAt = new Date().toISOString(),
|
|
38
|
+
} = {}) {
|
|
39
|
+
const invSkills = (inventory?.skills || []).map((s) => ({
|
|
40
|
+
name: s.name,
|
|
41
|
+
dir_name: s.dir_name,
|
|
42
|
+
source: s.source,
|
|
43
|
+
hosts: s.hosts || [],
|
|
44
|
+
est_tokens: s.est_tokens || 0,
|
|
45
|
+
desc_chars: s.desc_chars || 0,
|
|
46
|
+
enabled: Boolean(s.enabled),
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
const payload = {
|
|
50
|
+
generatedAt,
|
|
51
|
+
stats: stats || { window: {}, totals: {}, inventory: {}, rows: [], unused: { bySource: [] }, insights: {} },
|
|
52
|
+
timeline: timeline || { window: {}, by: 'day', totals: {}, rows: [] },
|
|
53
|
+
dailyTimeline: dailyTimeline || timeline || { window: {}, by: 'day', totals: {}, rows: [] },
|
|
54
|
+
chains: chains || { window: {}, totals: {}, transitions: [], sequences: [], pairs: [] },
|
|
55
|
+
inventory: { skills: invSkills },
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const jsonScript = serializePayload(payload);
|
|
59
|
+
|
|
60
|
+
return `<!DOCTYPE html>
|
|
61
|
+
<html lang="en">
|
|
62
|
+
<head>
|
|
63
|
+
<meta charset="utf-8" />
|
|
64
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
65
|
+
<title>skilltally Analytics</title>
|
|
66
|
+
<style>
|
|
67
|
+
:root {
|
|
68
|
+
--bg: #000000;
|
|
69
|
+
--pill-bg: #070707;
|
|
70
|
+
--surface: #171717;
|
|
71
|
+
--surface-hover: #1f1f1f;
|
|
72
|
+
--border: #262626;
|
|
73
|
+
--border-subtle: #1a1a1a;
|
|
74
|
+
--text: #f5f5f5;
|
|
75
|
+
--muted: #8e8e93;
|
|
76
|
+
--dim: #52525b;
|
|
77
|
+
--dot-empty: #242424;
|
|
78
|
+
--blue-1: #152c4a;
|
|
79
|
+
--blue-2: #1d4ed8;
|
|
80
|
+
--blue-3: #2b7fff;
|
|
81
|
+
--blue-4: #93c5fd;
|
|
82
|
+
--bloat-fill: #212121;
|
|
83
|
+
--bloat-stroke: #2e2e2e;
|
|
84
|
+
--sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
|
|
85
|
+
--mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
|
86
|
+
}
|
|
87
|
+
[data-theme="light"] {
|
|
88
|
+
--bg: #ffffff;
|
|
89
|
+
--pill-bg: #fafafa;
|
|
90
|
+
--surface: #f4f4f5;
|
|
91
|
+
--surface-hover: #ececef;
|
|
92
|
+
--border: #e4e4e7;
|
|
93
|
+
--border-subtle: #f0f0f2;
|
|
94
|
+
--text: #0d0d0d;
|
|
95
|
+
--muted: #6e6e80;
|
|
96
|
+
--dim: #a1a1aa;
|
|
97
|
+
--dot-empty: #ebebeb;
|
|
98
|
+
--blue-1: #bfdbfe;
|
|
99
|
+
--blue-2: #60a5fa;
|
|
100
|
+
--blue-3: #2563eb;
|
|
101
|
+
--blue-4: #1d4ed8;
|
|
102
|
+
--bloat-fill: #ececef;
|
|
103
|
+
--bloat-stroke: #d4d4d8;
|
|
104
|
+
}
|
|
105
|
+
* { box-sizing: border-box; }
|
|
106
|
+
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--sans); -webkit-font-smoothing: antialiased; }
|
|
107
|
+
body { padding: 40px 20px 72px; font-size: 14px; line-height: 1.5; }
|
|
108
|
+
.wrap { max-width: 760px; margin: 0 auto; }
|
|
109
|
+
|
|
110
|
+
/* Subtle top bar */
|
|
111
|
+
.topbar {
|
|
112
|
+
display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
|
|
113
|
+
margin-bottom: 24px;
|
|
114
|
+
}
|
|
115
|
+
.brand-title { font-size: 15px; font-weight: 500; letter-spacing: -0.01em; color: var(--text); }
|
|
116
|
+
.brand-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
|
|
117
|
+
.top-links { display: flex; align-items: center; gap: 16px; }
|
|
118
|
+
|
|
119
|
+
/* Text link buttons (OpenAI profile switcher pattern) */
|
|
120
|
+
.text-tab {
|
|
121
|
+
background: none; border: none; padding: 0; margin: 0;
|
|
122
|
+
font: inherit; font-size: 13px; font-weight: 400;
|
|
123
|
+
color: var(--muted); cursor: pointer; transition: color 0.15s ease;
|
|
124
|
+
}
|
|
125
|
+
.text-tab:hover { color: var(--text); }
|
|
126
|
+
.text-tab.active { color: var(--text); font-weight: 500; }
|
|
127
|
+
|
|
128
|
+
/* 5-Metric Pill Strip */
|
|
129
|
+
.kpi-strip {
|
|
130
|
+
display: grid;
|
|
131
|
+
grid-template-columns: repeat(5, 1fr);
|
|
132
|
+
background: var(--pill-bg);
|
|
133
|
+
border: 1px solid var(--border);
|
|
134
|
+
border-radius: 12px;
|
|
135
|
+
padding: 14px 0;
|
|
136
|
+
margin-bottom: 36px;
|
|
137
|
+
}
|
|
138
|
+
.kpi-cell {
|
|
139
|
+
text-align: center;
|
|
140
|
+
padding: 0 10px;
|
|
141
|
+
border-right: 1px solid var(--border-subtle);
|
|
142
|
+
}
|
|
143
|
+
.kpi-cell:last-child { border-right: none; }
|
|
144
|
+
.kpi-val { font-size: 16px; font-weight: 500; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; color: var(--text); }
|
|
145
|
+
.kpi-lbl { font-size: 12px; color: var(--muted); margin-top: 3px; white-space: nowrap; }
|
|
146
|
+
|
|
147
|
+
/* Sections */
|
|
148
|
+
section { margin-bottom: 40px; }
|
|
149
|
+
.sec-head {
|
|
150
|
+
display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap;
|
|
151
|
+
margin-bottom: 14px;
|
|
152
|
+
}
|
|
153
|
+
.sec-title { margin: 0; font-size: 15px; font-weight: 500; letter-spacing: -0.01em; color: var(--text); }
|
|
154
|
+
.sec-tabs { display: flex; align-items: center; gap: 16px; }
|
|
155
|
+
|
|
156
|
+
/* Activity Heatmap / Timeline */
|
|
157
|
+
.activity-wrap { width: 100%; overflow-x: auto; }
|
|
158
|
+
svg { width: 100%; display: block; }
|
|
159
|
+
|
|
160
|
+
/* Top Sources / Plugins Squircle Dock */
|
|
161
|
+
.dock {
|
|
162
|
+
display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap;
|
|
163
|
+
}
|
|
164
|
+
.squircle-btn {
|
|
165
|
+
background: none; border: none; padding: 0; cursor: pointer;
|
|
166
|
+
display: flex; flex-direction: column; align-items: center; gap: 6px;
|
|
167
|
+
color: var(--muted); width: 60px;
|
|
168
|
+
}
|
|
169
|
+
.squircle-box {
|
|
170
|
+
width: 54px; height: 54px; border-radius: 14px;
|
|
171
|
+
background: var(--surface);
|
|
172
|
+
border: 1px solid var(--border);
|
|
173
|
+
display: grid; place-items: center;
|
|
174
|
+
font-size: 14px; font-weight: 600; color: var(--text);
|
|
175
|
+
letter-spacing: -0.02em;
|
|
176
|
+
transition: border-color 0.15s ease, background 0.15s ease, transform 0.12s ease;
|
|
177
|
+
}
|
|
178
|
+
.squircle-btn:hover .squircle-box { background: var(--surface-hover); border-color: var(--dim); transform: translateY(-1px); }
|
|
179
|
+
.squircle-btn.active .squircle-box { border-color: var(--blue-3); box-shadow: 0 0 0 1px var(--blue-3); }
|
|
180
|
+
.squircle-btn.active { color: var(--text); }
|
|
181
|
+
.squircle-lbl {
|
|
182
|
+
font-size: 11px; max-width: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/* Showcase Context Footprint Card */
|
|
186
|
+
.showcase-card {
|
|
187
|
+
background: var(--surface);
|
|
188
|
+
border: 1px solid var(--border-subtle);
|
|
189
|
+
border-radius: 16px;
|
|
190
|
+
padding: 18px;
|
|
191
|
+
}
|
|
192
|
+
.showcase-foot {
|
|
193
|
+
display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
|
|
194
|
+
margin-top: 12px; font-size: 12px; color: var(--muted);
|
|
195
|
+
}
|
|
196
|
+
.dot-legend { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
|
|
197
|
+
.swatch { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 5px; vertical-align: middle; }
|
|
198
|
+
|
|
199
|
+
/* Insights Key-Value Ledger */
|
|
200
|
+
.ledger-row {
|
|
201
|
+
display: flex; align-items: baseline; justify-content: space-between; gap: 16px;
|
|
202
|
+
padding: 9px 0;
|
|
203
|
+
}
|
|
204
|
+
.ledger-k { color: var(--muted); font-size: 14px; }
|
|
205
|
+
.ledger-v { color: var(--text); font-size: 14px; font-weight: 500; font-variant-numeric: tabular-nums; text-align: right; }
|
|
206
|
+
|
|
207
|
+
.rec-row {
|
|
208
|
+
display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
|
|
209
|
+
padding: 10px 0;
|
|
210
|
+
border-bottom: 1px solid var(--border-subtle);
|
|
211
|
+
}
|
|
212
|
+
.rec-row:last-child { border-bottom: none; }
|
|
213
|
+
.rec-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
|
|
214
|
+
.code-pill {
|
|
215
|
+
font-family: var(--mono); font-size: 11px; color: var(--muted);
|
|
216
|
+
background: var(--surface); border: 1px solid var(--border);
|
|
217
|
+
padding: 4px 8px; border-radius: 6px; white-space: nowrap;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/* Skills Explorer Table */
|
|
221
|
+
.controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
|
|
222
|
+
input[type="search"], select {
|
|
223
|
+
background: transparent;
|
|
224
|
+
color: var(--text);
|
|
225
|
+
border: 1px solid var(--border);
|
|
226
|
+
border-radius: 8px;
|
|
227
|
+
padding: 6px 10px;
|
|
228
|
+
font-family: inherit;
|
|
229
|
+
font-size: 12px;
|
|
230
|
+
outline: none;
|
|
231
|
+
}
|
|
232
|
+
input[type="search"] { flex: 1; min-width: 180px; }
|
|
233
|
+
input[type="search"]:focus, select:focus { border-color: var(--dim); }
|
|
234
|
+
|
|
235
|
+
.table-wrap { overflow-x: auto; }
|
|
236
|
+
table { width: 100%; border-collapse: collapse; font-size: 13px; }
|
|
237
|
+
th, td {
|
|
238
|
+
text-align: left; padding: 10px 8px;
|
|
239
|
+
border-bottom: 1px solid var(--border-subtle);
|
|
240
|
+
white-space: nowrap;
|
|
241
|
+
}
|
|
242
|
+
th {
|
|
243
|
+
font-size: 11px; font-weight: 500; color: var(--muted);
|
|
244
|
+
cursor: pointer; user-select: none;
|
|
245
|
+
}
|
|
246
|
+
th:hover { color: var(--text); }
|
|
247
|
+
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
|
|
248
|
+
tr:hover td { background: var(--pill-bg); }
|
|
249
|
+
.mono { font-family: var(--mono); font-size: 12px; }
|
|
250
|
+
.status-dot {
|
|
251
|
+
width: 6px; height: 6px; border-radius: 50%; display: inline-block; margin-right: 6px; vertical-align: middle;
|
|
252
|
+
}
|
|
253
|
+
.status-dot.used { background: var(--blue-3); }
|
|
254
|
+
.status-dot.unused { background: var(--dim); }
|
|
255
|
+
|
|
256
|
+
/* Footer */
|
|
257
|
+
footer {
|
|
258
|
+
margin-top: 48px; padding-top: 18px;
|
|
259
|
+
border-top: 1px solid var(--border-subtle);
|
|
260
|
+
display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
|
|
261
|
+
font-size: 12px; color: var(--muted);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/* Tooltip */
|
|
265
|
+
.tooltip {
|
|
266
|
+
position: fixed; pointer-events: none; z-index: 1000; display: none;
|
|
267
|
+
background: #141414; color: #f5f5f5; border: 1px solid #2e2e2e;
|
|
268
|
+
padding: 7px 10px; border-radius: 8px; font-size: 12px; line-height: 1.4;
|
|
269
|
+
max-width: 280px;
|
|
270
|
+
}
|
|
271
|
+
[data-theme="light"] .tooltip { background: #18181b; color: #fafafa; }
|
|
272
|
+
|
|
273
|
+
/* Mermaid Dialog */
|
|
274
|
+
dialog {
|
|
275
|
+
background: var(--surface); color: var(--text);
|
|
276
|
+
border: 1px solid var(--border); border-radius: 14px;
|
|
277
|
+
max-width: 680px; width: 92vw; padding: 20px;
|
|
278
|
+
}
|
|
279
|
+
dialog::backdrop { background: rgba(0, 0, 0, 0.72); }
|
|
280
|
+
pre {
|
|
281
|
+
background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
|
|
282
|
+
padding: 12px; overflow-x: auto; font-family: var(--mono); font-size: 12px; margin: 12px 0;
|
|
283
|
+
}
|
|
284
|
+
.btn-minimal {
|
|
285
|
+
background: var(--text); color: var(--bg); border: none; border-radius: 999px;
|
|
286
|
+
padding: 7px 14px; font-size: 12px; font-weight: 500; cursor: pointer;
|
|
287
|
+
}
|
|
288
|
+
.btn-outline {
|
|
289
|
+
background: transparent; color: var(--text); border: 1px solid var(--border); border-radius: 999px;
|
|
290
|
+
padding: 6px 12px; font-size: 12px; font-weight: 500; cursor: pointer;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
.hidden { display: none !important; }
|
|
294
|
+
|
|
295
|
+
@media (max-width: 640px) {
|
|
296
|
+
.kpi-strip { grid-template-columns: repeat(2, 1fr); row-gap: 12px; }
|
|
297
|
+
.kpi-cell { border-right: none; }
|
|
298
|
+
}
|
|
299
|
+
</style>
|
|
300
|
+
</head>
|
|
301
|
+
<body>
|
|
302
|
+
<div class="wrap">
|
|
303
|
+
<header class="topbar">
|
|
304
|
+
<div>
|
|
305
|
+
<div class="brand-title">skilltally Analytics</div>
|
|
306
|
+
<div class="brand-meta" id="window-subtitle">100% local · zero telemetry</div>
|
|
307
|
+
</div>
|
|
308
|
+
<div class="top-links">
|
|
309
|
+
<button class="text-tab hidden" id="btn-reset-filter">Clear filter</button>
|
|
310
|
+
<button class="text-tab" id="btn-theme">Light mode</button>
|
|
311
|
+
</div>
|
|
312
|
+
</header>
|
|
313
|
+
|
|
314
|
+
<div class="kpi-strip" id="kpi-strip"></div>
|
|
315
|
+
|
|
316
|
+
<section>
|
|
317
|
+
<div class="sec-head">
|
|
318
|
+
<h2 class="sec-title">Skill activity</h2>
|
|
319
|
+
<div class="sec-tabs">
|
|
320
|
+
<button class="text-tab active" data-activity="daily">Daily</button>
|
|
321
|
+
<button class="text-tab" data-activity="weekly">Weekly</button>
|
|
322
|
+
<button class="text-tab" data-activity="cumulative">Cumulative</button>
|
|
323
|
+
</div>
|
|
324
|
+
</div>
|
|
325
|
+
<div class="activity-wrap">
|
|
326
|
+
<svg id="svg-timeline" viewBox="0 0 720 132"></svg>
|
|
327
|
+
</div>
|
|
328
|
+
</section>
|
|
329
|
+
|
|
330
|
+
<section>
|
|
331
|
+
<div class="sec-head">
|
|
332
|
+
<h2 class="sec-title">Top sources</h2>
|
|
333
|
+
<span class="brand-meta" id="dock-subtitle">Click a source to filter</span>
|
|
334
|
+
</div>
|
|
335
|
+
<div class="dock" id="sources-dock"></div>
|
|
336
|
+
</section>
|
|
337
|
+
|
|
338
|
+
<section>
|
|
339
|
+
<div class="sec-head">
|
|
340
|
+
<h2 class="sec-title">Context footprint</h2>
|
|
341
|
+
<div class="sec-tabs">
|
|
342
|
+
<button class="text-tab active" data-treemap-mode="source">By Source</button>
|
|
343
|
+
<button class="text-tab" data-treemap-mode="skill">By Skill</button>
|
|
344
|
+
</div>
|
|
345
|
+
</div>
|
|
346
|
+
<div class="showcase-card">
|
|
347
|
+
<svg id="svg-treemap" viewBox="0 0 720 220" preserveAspectRatio="xMidYMid meet"></svg>
|
|
348
|
+
<div class="showcase-foot">
|
|
349
|
+
<span id="footprint-summary">Area proportional to ~tokens/session</span>
|
|
350
|
+
<div class="dot-legend">
|
|
351
|
+
<span><span class="swatch" style="background:var(--bloat-fill);border:1px solid var(--bloat-stroke)"></span>0 runs</span>
|
|
352
|
+
<span><span class="swatch" style="background:var(--blue-1)"></span>1-2</span>
|
|
353
|
+
<span><span class="swatch" style="background:var(--blue-2)"></span>3-7</span>
|
|
354
|
+
<span><span class="swatch" style="background:var(--blue-3)"></span>8+</span>
|
|
355
|
+
</div>
|
|
356
|
+
</div>
|
|
357
|
+
</div>
|
|
358
|
+
</section>
|
|
359
|
+
|
|
360
|
+
<section>
|
|
361
|
+
<div class="sec-head">
|
|
362
|
+
<h2 class="sec-title">Insights</h2>
|
|
363
|
+
<div class="sec-tabs">
|
|
364
|
+
<button class="text-tab active" data-insights-tab="overview">Overview</button>
|
|
365
|
+
<button class="text-tab" data-insights-tab="workflows">Workflows</button>
|
|
366
|
+
<button class="text-tab" data-insights-tab="pruning">Pruning</button>
|
|
367
|
+
</div>
|
|
368
|
+
</div>
|
|
369
|
+
|
|
370
|
+
<div id="panel-overview"></div>
|
|
371
|
+
|
|
372
|
+
<div id="panel-workflows" class="hidden">
|
|
373
|
+
<div class="showcase-card" style="margin-bottom: 12px;">
|
|
374
|
+
<svg id="svg-chains" viewBox="0 0 720 210"></svg>
|
|
375
|
+
</div>
|
|
376
|
+
<div id="workflows-ledger"></div>
|
|
377
|
+
</div>
|
|
378
|
+
|
|
379
|
+
<div id="panel-pruning" class="hidden"></div>
|
|
380
|
+
</section>
|
|
381
|
+
|
|
382
|
+
<section>
|
|
383
|
+
<div class="sec-head">
|
|
384
|
+
<h2 class="sec-title">Skills</h2>
|
|
385
|
+
<div class="sec-tabs">
|
|
386
|
+
<button class="text-tab active" data-status-tab="all">All</button>
|
|
387
|
+
<button class="text-tab" data-status-tab="used">Used</button>
|
|
388
|
+
<button class="text-tab" data-status-tab="unused">Unused</button>
|
|
389
|
+
</div>
|
|
390
|
+
</div>
|
|
391
|
+
<div class="controls">
|
|
392
|
+
<input type="search" id="filter-search" placeholder="Filter skills or sources..." />
|
|
393
|
+
<select id="filter-host"><option value="all">Host: All</option></select>
|
|
394
|
+
<select id="filter-source"><option value="all">Source: All</option></select>
|
|
395
|
+
</div>
|
|
396
|
+
<div class="table-wrap">
|
|
397
|
+
<table>
|
|
398
|
+
<thead>
|
|
399
|
+
<tr>
|
|
400
|
+
<th data-sort="skill">Skill</th>
|
|
401
|
+
<th data-sort="source">Source</th>
|
|
402
|
+
<th class="num" data-sort="activations">Activations</th>
|
|
403
|
+
<th class="num" data-sort="reads">Reads</th>
|
|
404
|
+
<th class="num" data-sort="est_tokens">Context</th>
|
|
405
|
+
<th class="num" data-sort="manualRatio">Manual</th>
|
|
406
|
+
<th>14d</th>
|
|
407
|
+
<th>Hosts</th>
|
|
408
|
+
</tr>
|
|
409
|
+
</thead>
|
|
410
|
+
<tbody id="skills-tbody"></tbody>
|
|
411
|
+
</table>
|
|
412
|
+
</div>
|
|
413
|
+
<div class="brand-meta" id="table-count" style="margin-top: 10px;"></div>
|
|
414
|
+
</section>
|
|
415
|
+
|
|
416
|
+
<footer>
|
|
417
|
+
<span>skilltally · 100% local · zero telemetry</span>
|
|
418
|
+
<div class="top-links">
|
|
419
|
+
<button class="text-tab" id="btn-mermaid">Export Mermaid</button>
|
|
420
|
+
</div>
|
|
421
|
+
</footer>
|
|
422
|
+
</div>
|
|
423
|
+
|
|
424
|
+
<div class="tooltip" id="tooltip"></div>
|
|
425
|
+
|
|
426
|
+
<dialog id="mermaid-dialog">
|
|
427
|
+
<div class="sec-head" style="margin-bottom: 10px;">
|
|
428
|
+
<h2 class="sec-title">Mermaid Diagrams</h2>
|
|
429
|
+
<button class="btn-outline" id="btn-close-mermaid">Close</button>
|
|
430
|
+
</div>
|
|
431
|
+
<div class="sec-tabs">
|
|
432
|
+
<button class="text-tab active" data-mermaid="pie">Context Tax Pie</button>
|
|
433
|
+
<button class="text-tab" data-mermaid="timeline">Timeline XY Chart</button>
|
|
434
|
+
<button class="text-tab" data-mermaid="chains">Workflow Flowchart</button>
|
|
435
|
+
</div>
|
|
436
|
+
<pre id="mermaid-code"></pre>
|
|
437
|
+
<div style="display:flex; justify-content:flex-end;">
|
|
438
|
+
<button class="btn-minimal" id="btn-copy-mermaid">Copy Snippet</button>
|
|
439
|
+
</div>
|
|
440
|
+
</dialog>
|
|
441
|
+
|
|
442
|
+
<script id="skilltally-data" type="application/json">${jsonScript}</script>
|
|
443
|
+
<script>
|
|
444
|
+
(function() {
|
|
445
|
+
const DATA = JSON.parse(document.getElementById('skilltally-data').textContent);
|
|
446
|
+
const stats = DATA.stats || {};
|
|
447
|
+
const timeline = DATA.timeline || {};
|
|
448
|
+
const dailyTimeline = DATA.dailyTimeline || timeline;
|
|
449
|
+
const chains = DATA.chains || {};
|
|
450
|
+
const invSkills = (DATA.inventory && DATA.inventory.skills) || [];
|
|
451
|
+
|
|
452
|
+
const esc = (s) => String(s ?? '').replace(/[&<>"']/g, (c) => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
|
|
453
|
+
const ns = 'http://www.w3.org/2000/svg';
|
|
454
|
+
const el = (tag, attrs = {}, text = null) => {
|
|
455
|
+
const node = document.createElementNS(ns, tag);
|
|
456
|
+
for (const [k, v] of Object.entries(attrs)) node.setAttribute(k, String(v));
|
|
457
|
+
if (text !== null) node.textContent = String(text);
|
|
458
|
+
return node;
|
|
459
|
+
};
|
|
460
|
+
const fmtCompact = (n) => {
|
|
461
|
+
const v = Number(n || 0);
|
|
462
|
+
if (v >= 1_000_000) return (v / 1_000_000).toFixed(1).replace(/\\.0$/, '') + 'M';
|
|
463
|
+
if (v >= 10_000) return (v / 1_000).toFixed(1).replace(/\\.0$/, '') + 'K';
|
|
464
|
+
if (v >= 1_000) return (v / 1_000).toFixed(1).replace(/\\.0$/, '') + 'K';
|
|
465
|
+
return String(v);
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
const tooltip = document.getElementById('tooltip');
|
|
469
|
+
function showTip(evt, html) {
|
|
470
|
+
tooltip.innerHTML = html;
|
|
471
|
+
tooltip.style.display = 'block';
|
|
472
|
+
const x = Math.min(window.innerWidth - 290, evt.clientX + 12);
|
|
473
|
+
const y = Math.min(window.innerHeight - 100, evt.clientY + 12);
|
|
474
|
+
tooltip.style.left = x + 'px';
|
|
475
|
+
tooltip.style.top = y + 'px';
|
|
476
|
+
}
|
|
477
|
+
function hideTip() { tooltip.style.display = 'none'; }
|
|
478
|
+
|
|
479
|
+
// Theme (Default dark pure black; remembers user override)
|
|
480
|
+
const themeBtn = document.getElementById('btn-theme');
|
|
481
|
+
const applyTheme = (mode) => {
|
|
482
|
+
if (mode === 'light') {
|
|
483
|
+
document.documentElement.setAttribute('data-theme', 'light');
|
|
484
|
+
themeBtn.textContent = 'Dark mode';
|
|
485
|
+
} else {
|
|
486
|
+
document.documentElement.removeAttribute('data-theme');
|
|
487
|
+
themeBtn.textContent = 'Light mode';
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
const savedTheme = localStorage.getItem('skilltally-theme');
|
|
491
|
+
if (savedTheme === 'light') applyTheme('light');
|
|
492
|
+
themeBtn.addEventListener('click', () => {
|
|
493
|
+
const isLight = document.documentElement.getAttribute('data-theme') === 'light';
|
|
494
|
+
const next = isLight ? 'dark' : 'light';
|
|
495
|
+
applyTheme(next);
|
|
496
|
+
localStorage.setItem('skilltally-theme', next);
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
// Subtitle
|
|
500
|
+
const win = stats.window || {};
|
|
501
|
+
const winLabel = win.from ? \`\${win.from} \u2192 \${win.to} (\${win.since})\` : \`all time \u00b7 \${win.to || ''}\`;
|
|
502
|
+
document.getElementById('window-subtitle').textContent = \`\${winLabel}\`;
|
|
503
|
+
|
|
504
|
+
// Compute daily map & streaks
|
|
505
|
+
const dayRows = (dailyTimeline.rows || []).filter((r) => /^\\d{4}-\\d{2}-\\d{2}$/.test(r.bucket));
|
|
506
|
+
const dayMap = new Map();
|
|
507
|
+
for (const r of dayRows) dayMap.set(r.bucket, r);
|
|
508
|
+
|
|
509
|
+
const activeDayMs = dayRows
|
|
510
|
+
.filter((r) => r.activations > 0)
|
|
511
|
+
.map((r) => Date.parse(r.bucket + 'T00:00:00.000Z'))
|
|
512
|
+
.filter(Number.isFinite)
|
|
513
|
+
.sort((a, b) => a - b);
|
|
514
|
+
|
|
515
|
+
let longestStreak = 0;
|
|
516
|
+
let run = 0;
|
|
517
|
+
for (let i = 0; i < activeDayMs.length; i++) {
|
|
518
|
+
if (i === 0 || activeDayMs[i] - activeDayMs[i - 1] === 86400_000) {
|
|
519
|
+
run += 1;
|
|
520
|
+
} else {
|
|
521
|
+
run = 1;
|
|
522
|
+
}
|
|
523
|
+
if (run > longestStreak) longestStreak = run;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
const endStr = (win.to || (DATA.generatedAt || '').slice(0, 10) || new Date().toISOString().slice(0, 10));
|
|
527
|
+
const endMidnight = Date.parse(endStr + 'T00:00:00.000Z');
|
|
528
|
+
let currentStreak = 0;
|
|
529
|
+
if (activeDayMs.length > 0 && Number.isFinite(endMidnight)) {
|
|
530
|
+
const activeSet = new Set(activeDayMs);
|
|
531
|
+
let cursor = activeSet.has(endMidnight)
|
|
532
|
+
? endMidnight
|
|
533
|
+
: activeSet.has(endMidnight - 86400_000)
|
|
534
|
+
? endMidnight - 86400_000
|
|
535
|
+
: null;
|
|
536
|
+
while (cursor !== null && activeSet.has(cursor)) {
|
|
537
|
+
currentStreak += 1;
|
|
538
|
+
cursor -= 86400_000;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// 1. 5-Metric Pill Strip
|
|
543
|
+
const totals = stats.totals || {};
|
|
544
|
+
const inv = stats.inventory || {};
|
|
545
|
+
const unused = stats.unused || {};
|
|
546
|
+
const enabledTok = inv.enabledEstTokens || 0;
|
|
547
|
+
const unusedTok = unused.totalEstTokens || 0;
|
|
548
|
+
const wastePct = enabledTok > 0 ? Math.round((unusedTok / enabledTok) * 100) : 0;
|
|
549
|
+
|
|
550
|
+
document.getElementById('kpi-strip').innerHTML = [
|
|
551
|
+
{ val: fmtCompact(totals.events || 0), lbl: 'Total reads' },
|
|
552
|
+
{ val: fmtCompact(totals.activations || 0), lbl: 'Activations' },
|
|
553
|
+
{ val: '~' + fmtCompact(unusedTok), lbl: 'Unused tok/sess' },
|
|
554
|
+
{ val: longestStreak + (longestStreak === 1 ? ' day' : ' days'), lbl: 'Longest streak' },
|
|
555
|
+
{ val: currentStreak + (currentStreak === 1 ? ' day' : ' days'), lbl: 'Current streak' }
|
|
556
|
+
].map((k) => \`
|
|
557
|
+
<div class="kpi-cell">
|
|
558
|
+
<div class="kpi-val">\${esc(k.val)}</div>
|
|
559
|
+
<div class="kpi-lbl">\${esc(k.lbl)}</div>
|
|
560
|
+
</div>
|
|
561
|
+
\`).join('');
|
|
562
|
+
|
|
563
|
+
// Unified skill dataset
|
|
564
|
+
const usedByKey = new Map();
|
|
565
|
+
for (const r of (stats.rows || [])) {
|
|
566
|
+
usedByKey.set(r.skill + '\\0' + r.source, r);
|
|
567
|
+
if (!usedByKey.has(r.skill)) usedByKey.set(r.skill, r);
|
|
568
|
+
}
|
|
569
|
+
const unified = [];
|
|
570
|
+
const seenUnified = new Set();
|
|
571
|
+
for (const s of invSkills) {
|
|
572
|
+
if (!s.enabled) continue;
|
|
573
|
+
const match = usedByKey.get(s.name + '\\0' + s.source) || usedByKey.get(s.name) || usedByKey.get(s.dir_name);
|
|
574
|
+
const key = s.name + '\\0' + s.source;
|
|
575
|
+
if (seenUnified.has(key)) continue;
|
|
576
|
+
seenUnified.add(key);
|
|
577
|
+
unified.push({
|
|
578
|
+
skill: s.name,
|
|
579
|
+
source: s.source,
|
|
580
|
+
activations: match ? match.activations : 0,
|
|
581
|
+
reads: match ? match.reads : 0,
|
|
582
|
+
est_tokens: s.est_tokens || (match ? match.est_tokens : 0) || 10,
|
|
583
|
+
raw_tokens: s.est_tokens || (match ? match.est_tokens : 0) || 0,
|
|
584
|
+
manualRatio: match ? match.manualRatio : 0,
|
|
585
|
+
sparkline: match ? match.sparkline : '··············',
|
|
586
|
+
hosts: match && match.hosts.length ? match.hosts : s.hosts,
|
|
587
|
+
status: match ? 'used' : 'unused'
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
for (const r of (stats.rows || [])) {
|
|
591
|
+
if (![...seenUnified].some((k) => k.startsWith(r.skill + '\\0'))) {
|
|
592
|
+
unified.push({
|
|
593
|
+
skill: r.skill,
|
|
594
|
+
source: r.source,
|
|
595
|
+
activations: r.activations,
|
|
596
|
+
reads: r.reads,
|
|
597
|
+
est_tokens: r.est_tokens || 10,
|
|
598
|
+
raw_tokens: r.est_tokens || 0,
|
|
599
|
+
manualRatio: r.manualRatio || 0,
|
|
600
|
+
sparkline: r.sparkline || '··············',
|
|
601
|
+
hosts: r.hosts || [],
|
|
602
|
+
status: 'used'
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
// 2. Skill Activity Heatmap / Weekly / Cumulative
|
|
608
|
+
let activityMode = 'daily';
|
|
609
|
+
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
610
|
+
const dotColor = (act, maxAct) => {
|
|
611
|
+
if (!act || act <= 0) return 'var(--dot-empty)';
|
|
612
|
+
const ratio = act / Math.max(1, maxAct);
|
|
613
|
+
if (ratio <= 0.25) return 'var(--blue-1)';
|
|
614
|
+
if (ratio <= 0.55) return 'var(--blue-2)';
|
|
615
|
+
if (ratio <= 0.85) return 'var(--blue-3)';
|
|
616
|
+
return 'var(--blue-4)';
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
function isoWeekKey(dateObj) {
|
|
620
|
+
const d = new Date(Date.UTC(dateObj.getUTCFullYear(), dateObj.getUTCMonth(), dateObj.getUTCDate()));
|
|
621
|
+
const dayNum = d.getUTCDay() || 7;
|
|
622
|
+
d.setUTCDate(d.getUTCDate() + 4 - dayNum);
|
|
623
|
+
const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
|
|
624
|
+
const weekNo = Math.ceil(((d - yearStart) / 86400_000 + 1) / 7);
|
|
625
|
+
return d.getUTCFullYear() + '-W' + String(weekNo).padStart(2, '0');
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
function renderActivity() {
|
|
629
|
+
const svg = document.getElementById('svg-timeline');
|
|
630
|
+
svg.innerHTML = '';
|
|
631
|
+
|
|
632
|
+
if (activityMode === 'daily') {
|
|
633
|
+
svg.setAttribute('viewBox', '0 0 720 128');
|
|
634
|
+
const endDate = Number.isFinite(endMidnight) ? new Date(endMidnight) : new Date();
|
|
635
|
+
const endDow = endDate.getUTCDay();
|
|
636
|
+
const cols = 52;
|
|
637
|
+
const startMs = endDate.getTime() - (51 * 7 + endDow) * 86400_000;
|
|
638
|
+
const maxAct = Math.max(1, ...dayRows.map((r) => r.activations));
|
|
639
|
+
|
|
640
|
+
const pitchX = 13.8;
|
|
641
|
+
const pitchY = 13.8;
|
|
642
|
+
const offsetX = 4;
|
|
643
|
+
const offsetY = 8;
|
|
644
|
+
|
|
645
|
+
let lastMonth = -1;
|
|
646
|
+
let lastLabelX = -100;
|
|
647
|
+
|
|
648
|
+
for (let c = 0; c < cols; c++) {
|
|
649
|
+
const colTopDate = new Date(startMs + c * 7 * 86400_000);
|
|
650
|
+
const m = colTopDate.getUTCMonth();
|
|
651
|
+
const cx = offsetX + c * pitchX + 4;
|
|
652
|
+
if (m !== lastMonth && cx - lastLabelX >= 36) {
|
|
653
|
+
svg.appendChild(el('text', {
|
|
654
|
+
x: cx - 4, y: 120, fill: 'var(--muted)', 'font-size': 11
|
|
655
|
+
}, MONTHS[m]));
|
|
656
|
+
lastMonth = m;
|
|
657
|
+
lastLabelX = cx;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
for (let r = 0; r < 7; r++) {
|
|
661
|
+
if (c === cols - 1 && r > endDow) continue;
|
|
662
|
+
const dMs = startMs + (c * 7 + r) * 86400_000;
|
|
663
|
+
const iso = new Date(dMs).toISOString().slice(0, 10);
|
|
664
|
+
const entry = dayMap.get(iso);
|
|
665
|
+
const act = entry ? entry.activations : 0;
|
|
666
|
+
const reads = entry ? entry.reads : 0;
|
|
667
|
+
const dot = el('circle', {
|
|
668
|
+
cx, cy: offsetY + r * pitchY + 4, r: 4.3,
|
|
669
|
+
fill: dotColor(act, maxAct)
|
|
670
|
+
});
|
|
671
|
+
dot.addEventListener('mousemove', (evt) => {
|
|
672
|
+
showTip(evt, \`<strong>\${esc(iso)}</strong><br/>Activations: \${act}<br/>Reads: \${reads}\`);
|
|
673
|
+
});
|
|
674
|
+
dot.addEventListener('mouseleave', hideTip);
|
|
675
|
+
svg.appendChild(dot);
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
svg.setAttribute('viewBox', '0 0 720 156');
|
|
682
|
+
let series = [];
|
|
683
|
+
if (dayRows.length > 0) {
|
|
684
|
+
const weekBuckets = new Map();
|
|
685
|
+
for (const r of dayRows) {
|
|
686
|
+
const wk = isoWeekKey(new Date(r.bucket + 'T00:00:00.000Z'));
|
|
687
|
+
let b = weekBuckets.get(wk);
|
|
688
|
+
if (!b) { b = { bucket: wk, activations: 0, reads: 0 }; weekBuckets.set(wk, b); }
|
|
689
|
+
b.activations += r.activations;
|
|
690
|
+
b.reads += r.reads;
|
|
691
|
+
}
|
|
692
|
+
series = [...weekBuckets.values()].sort((a, b) => a.bucket.localeCompare(b.bucket));
|
|
693
|
+
} else {
|
|
694
|
+
series = (timeline.rows || []).map((r) => ({ bucket: r.bucket, activations: r.activations, reads: r.reads }));
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
if (series.length === 0) {
|
|
698
|
+
svg.appendChild(el('text', { x: 360, y: 80, 'text-anchor': 'middle', fill: 'var(--muted)', 'font-size': 13 }, 'No activity recorded in this window.'));
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
const padL = 32, padR = 12, padT = 14, padB = 24;
|
|
703
|
+
const W = 720 - padL - padR;
|
|
704
|
+
const H = 156 - padT - padB;
|
|
705
|
+
|
|
706
|
+
if (activityMode === 'weekly') {
|
|
707
|
+
const display = series.slice(-26);
|
|
708
|
+
const maxV = Math.max(1, ...display.map((r) => r.activations));
|
|
709
|
+
const step = W / display.length;
|
|
710
|
+
const barW = Math.max(5, Math.min(24, step * 0.62));
|
|
711
|
+
display.forEach((r, idx) => {
|
|
712
|
+
const bh = Math.max(2, (r.activations / maxV) * H);
|
|
713
|
+
const bx = padL + idx * step + (step - barW) / 2;
|
|
714
|
+
const by = padT + H - bh;
|
|
715
|
+
const rect = el('rect', { x: bx, y: by, width: barW, height: bh, rx: 3, fill: r.activations > 0 ? 'var(--blue-3)' : 'var(--dot-empty)' });
|
|
716
|
+
rect.addEventListener('mousemove', (evt) => {
|
|
717
|
+
showTip(evt, \`<strong>\${esc(r.bucket)}</strong><br/>Activations: \${r.activations}<br/>Reads: \${r.reads}\`);
|
|
718
|
+
});
|
|
719
|
+
rect.addEventListener('mouseleave', hideTip);
|
|
720
|
+
svg.appendChild(rect);
|
|
721
|
+
if (display.length <= 8 || idx === 0 || idx === display.length - 1 || idx % Math.ceil(display.length / 5) === 0) {
|
|
722
|
+
svg.appendChild(el('text', { x: bx + barW / 2, y: 148, 'text-anchor': 'middle', fill: 'var(--muted)', 'font-size': 10 }, r.bucket));
|
|
723
|
+
}
|
|
724
|
+
});
|
|
725
|
+
} else {
|
|
726
|
+
const cumRows = [];
|
|
727
|
+
let sum = 0;
|
|
728
|
+
const src = dayRows.length > 0 ? [...dayRows].sort((a, b) => a.bucket.localeCompare(b.bucket)) : series;
|
|
729
|
+
for (const r of src) {
|
|
730
|
+
sum += r.activations;
|
|
731
|
+
cumRows.push({ bucket: r.bucket, total: sum, delta: r.activations });
|
|
732
|
+
}
|
|
733
|
+
const maxV = Math.max(1, sum);
|
|
734
|
+
const pts = cumRows.map((r, i) => {
|
|
735
|
+
const x = padL + (cumRows.length === 1 ? W / 2 : (i / (cumRows.length - 1)) * W);
|
|
736
|
+
const y = padT + H - (r.total / maxV) * H;
|
|
737
|
+
return { x, y, r };
|
|
738
|
+
});
|
|
739
|
+
const lineD = pts.map((p, i) => (i === 0 ? 'M' : 'L') + p.x.toFixed(1) + ' ' + p.y.toFixed(1)).join(' ');
|
|
740
|
+
const areaD = lineD + \` L \${pts[pts.length - 1].x.toFixed(1)} \${padT + H} L \${pts[0].x.toFixed(1)} \${padT + H} Z\`;
|
|
741
|
+
svg.appendChild(el('path', { d: areaD, fill: 'var(--blue-3)', 'fill-opacity': '0.12' }));
|
|
742
|
+
svg.appendChild(el('path', { d: lineD, fill: 'none', stroke: 'var(--blue-3)', 'stroke-width': 2 }));
|
|
743
|
+
svg.appendChild(el('text', { x: padL - 6, y: padT + 8, 'text-anchor': 'end', fill: 'var(--muted)', 'font-size': 10 }, fmtCompact(maxV)));
|
|
744
|
+
svg.appendChild(el('text', { x: padL, y: 148, fill: 'var(--muted)', 'font-size': 10 }, cumRows[0].bucket));
|
|
745
|
+
svg.appendChild(el('text', { x: 720 - padR, y: 148, 'text-anchor': 'end', fill: 'var(--muted)', 'font-size': 10 }, cumRows[cumRows.length - 1].bucket));
|
|
746
|
+
for (const p of pts) {
|
|
747
|
+
const hit = el('circle', { cx: p.x, cy: p.y, r: 4, fill: 'transparent', style: 'cursor:pointer' });
|
|
748
|
+
hit.addEventListener('mousemove', (evt) => {
|
|
749
|
+
showTip(evt, \`<strong>\${esc(p.r.bucket)}</strong><br/>Cumulative: \${p.r.total} (+\${p.r.delta})\`);
|
|
750
|
+
});
|
|
751
|
+
hit.addEventListener('mouseleave', hideTip);
|
|
752
|
+
svg.appendChild(hit);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
document.querySelectorAll('[data-activity]').forEach((btn) => {
|
|
757
|
+
btn.addEventListener('click', () => {
|
|
758
|
+
document.querySelectorAll('[data-activity]').forEach((b) => b.classList.remove('active'));
|
|
759
|
+
btn.classList.add('active');
|
|
760
|
+
activityMode = btn.dataset.activity;
|
|
761
|
+
renderActivity();
|
|
762
|
+
});
|
|
763
|
+
});
|
|
764
|
+
|
|
765
|
+
// 3. Top Sources / Plugins Squircle Dock
|
|
766
|
+
let selectedSourceFilter = null;
|
|
767
|
+
function sourceShortLabel(src) {
|
|
768
|
+
if (src.startsWith('plugin:')) return src.slice(7);
|
|
769
|
+
return src;
|
|
770
|
+
}
|
|
771
|
+
function sourceMonogram(name) {
|
|
772
|
+
const parts = name.replace(/[^A-Za-z0-9]+/g, ' ').trim().split(/\\s+/);
|
|
773
|
+
if (parts.length >= 2) return (parts[0][0] + parts[1][0]).toUpperCase();
|
|
774
|
+
return name.slice(0, 2).toUpperCase();
|
|
775
|
+
}
|
|
776
|
+
function renderDock() {
|
|
777
|
+
const dock = document.getElementById('sources-dock');
|
|
778
|
+
dock.innerHTML = '';
|
|
779
|
+
const bySrc = new Map();
|
|
780
|
+
for (const u of unified) {
|
|
781
|
+
let g = bySrc.get(u.source);
|
|
782
|
+
if (!g) { g = { source: u.source, activations: 0, skills: 0, tokens: 0 }; bySrc.set(u.source, g); }
|
|
783
|
+
g.activations += u.activations;
|
|
784
|
+
g.skills += 1;
|
|
785
|
+
g.tokens += u.raw_tokens;
|
|
786
|
+
}
|
|
787
|
+
const items = [...bySrc.values()]
|
|
788
|
+
.sort((a, b) => b.activations - a.activations || b.tokens - a.tokens)
|
|
789
|
+
.slice(0, 8);
|
|
790
|
+
|
|
791
|
+
if (items.length === 0) {
|
|
792
|
+
dock.innerHTML = '<span class="brand-meta">No sources found.</span>';
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
for (const item of items) {
|
|
797
|
+
const shortName = sourceShortLabel(item.source);
|
|
798
|
+
const btn = document.createElement('button');
|
|
799
|
+
btn.className = 'squircle-btn' + (selectedSourceFilter === item.source ? ' active' : '');
|
|
800
|
+
btn.innerHTML = \`
|
|
801
|
+
<div class="squircle-box">\${esc(sourceMonogram(shortName))}</div>
|
|
802
|
+
<span class="squircle-lbl">\${esc(shortName)}</span>
|
|
803
|
+
\`;
|
|
804
|
+
btn.addEventListener('mousemove', (evt) => {
|
|
805
|
+
showTip(evt, \`<strong>\${esc(item.source)}</strong><br/>Activations: \${item.activations}<br/>Skills: \${item.skills} · ~\${item.tokens.toLocaleString()} tok/sess\`);
|
|
806
|
+
});
|
|
807
|
+
btn.addEventListener('mouseleave', hideTip);
|
|
808
|
+
btn.addEventListener('click', () => {
|
|
809
|
+
if (selectedSourceFilter === item.source) {
|
|
810
|
+
selectedSourceFilter = null;
|
|
811
|
+
document.getElementById('filter-source').value = 'all';
|
|
812
|
+
} else {
|
|
813
|
+
selectedSourceFilter = item.source;
|
|
814
|
+
document.getElementById('filter-source').value = item.source;
|
|
815
|
+
}
|
|
816
|
+
syncResetVisibility();
|
|
817
|
+
renderDock();
|
|
818
|
+
renderTable();
|
|
819
|
+
});
|
|
820
|
+
dock.appendChild(btn);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
// 4. Context Footprint Treemap
|
|
825
|
+
function layoutTreemap(items, x, y, w, h) {
|
|
826
|
+
if (items.length === 0 || w <= 0 || h <= 0) return [];
|
|
827
|
+
if (items.length === 1) return [{ ...items[0], x, y, w, h }];
|
|
828
|
+
const total = items.reduce((a, b) => a + b.value, 0) || 1;
|
|
829
|
+
let half = 0;
|
|
830
|
+
let split = 1;
|
|
831
|
+
for (let i = 0; i < items.length - 1; i++) {
|
|
832
|
+
half += items[i].value;
|
|
833
|
+
split = i + 1;
|
|
834
|
+
if (half >= total / 2) break;
|
|
835
|
+
}
|
|
836
|
+
const left = items.slice(0, split);
|
|
837
|
+
const right = items.slice(split);
|
|
838
|
+
const ratio = half / total;
|
|
839
|
+
if (w >= h) {
|
|
840
|
+
const w1 = w * ratio;
|
|
841
|
+
return [...layoutTreemap(left, x, y, w1, h), ...layoutTreemap(right, x + w1, y, w - w1, h)];
|
|
842
|
+
} else {
|
|
843
|
+
const h1 = h * ratio;
|
|
844
|
+
return [...layoutTreemap(left, x, y, w, h1), ...layoutTreemap(right, x, y + h1, w, h - h1)];
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
let treemapMode = 'source';
|
|
849
|
+
function fillForBlock(act) {
|
|
850
|
+
if (!act || act <= 0) return 'var(--bloat-fill)';
|
|
851
|
+
if (act <= 2) return 'var(--blue-1)';
|
|
852
|
+
if (act <= 7) return 'var(--blue-2)';
|
|
853
|
+
return 'var(--blue-3)';
|
|
854
|
+
}
|
|
855
|
+
function renderTreemap() {
|
|
856
|
+
const svg = document.getElementById('svg-treemap');
|
|
857
|
+
svg.innerHTML = '';
|
|
858
|
+
let items;
|
|
859
|
+
if (treemapMode === 'source') {
|
|
860
|
+
const bySrc = new Map();
|
|
861
|
+
for (const u of unified) {
|
|
862
|
+
let g = bySrc.get(u.source);
|
|
863
|
+
if (!g) { g = { label: u.source, source: u.source, value: 0, rawTokens: 0, activations: 0 }; bySrc.set(u.source, g); }
|
|
864
|
+
g.value += u.est_tokens;
|
|
865
|
+
g.rawTokens += u.raw_tokens;
|
|
866
|
+
g.activations += u.activations;
|
|
867
|
+
}
|
|
868
|
+
items = [...bySrc.values()].sort((a, b) => b.value - a.value).slice(0, 32);
|
|
869
|
+
} else {
|
|
870
|
+
items = [...unified]
|
|
871
|
+
.map((u) => ({ label: u.skill, source: u.source, value: u.est_tokens, rawTokens: u.raw_tokens, activations: u.activations }))
|
|
872
|
+
.sort((a, b) => b.value - a.value)
|
|
873
|
+
.slice(0, 48);
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
document.getElementById('footprint-summary').textContent =
|
|
877
|
+
\`Enabled: ~\${enabledTok.toLocaleString()} tok/session · Unused: ~\${unusedTok.toLocaleString()} (\${wastePct}%)\`;
|
|
878
|
+
|
|
879
|
+
if (items.length === 0) {
|
|
880
|
+
svg.appendChild(el('text', { x: 360, y: 110, 'text-anchor': 'middle', fill: 'var(--muted)', 'font-size': 13 }, 'No installed skills to visualize.'));
|
|
881
|
+
return;
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
const rects = layoutTreemap(items, 0, 0, 720, 220);
|
|
885
|
+
for (const r of rects) {
|
|
886
|
+
const isBloat = !r.activations || r.activations <= 0;
|
|
887
|
+
const g = el('g', { style: 'cursor:pointer' });
|
|
888
|
+
g.appendChild(el('rect', {
|
|
889
|
+
x: r.x + 1.5, y: r.y + 1.5,
|
|
890
|
+
width: Math.max(0, r.w - 3), height: Math.max(0, r.h - 3),
|
|
891
|
+
rx: 6,
|
|
892
|
+
fill: fillForBlock(r.activations),
|
|
893
|
+
stroke: isBloat ? 'var(--bloat-stroke)' : 'transparent',
|
|
894
|
+
'stroke-width': 1
|
|
895
|
+
}));
|
|
896
|
+
|
|
897
|
+
if (r.w > 56 && r.h > 28) {
|
|
898
|
+
const maxChars = Math.max(4, Math.floor((r.w - 14) / 6.8));
|
|
899
|
+
const txt = r.label.length > maxChars ? r.label.slice(0, maxChars - 1) + '…' : r.label;
|
|
900
|
+
g.appendChild(el('text', {
|
|
901
|
+
x: r.x + 9, y: r.y + 19,
|
|
902
|
+
fill: isBloat ? 'var(--muted)' : '#ffffff',
|
|
903
|
+
'font-size': 11, 'font-weight': 500
|
|
904
|
+
}, txt));
|
|
905
|
+
if (r.h > 44) {
|
|
906
|
+
const subTxt = isBloat ? \`~\${r.rawTokens} tok · 0 runs\` : \`~\${r.rawTokens} tok · \${r.activations}\`;
|
|
907
|
+
g.appendChild(el('text', {
|
|
908
|
+
x: r.x + 9, y: r.y + 34,
|
|
909
|
+
fill: isBloat ? 'var(--dim)' : 'rgba(255,255,255,0.78)',
|
|
910
|
+
'font-size': 10
|
|
911
|
+
}, subTxt));
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
g.addEventListener('mousemove', (evt) => {
|
|
916
|
+
showTip(evt, \`<strong>\${esc(r.label)}</strong><br/>Source: \${esc(r.source)}<br/>Context: ~\${r.rawTokens.toLocaleString()} tok/session<br/>Activations: \${r.activations}\`);
|
|
917
|
+
});
|
|
918
|
+
g.addEventListener('mouseleave', hideTip);
|
|
919
|
+
g.addEventListener('click', () => {
|
|
920
|
+
if (treemapMode === 'source') {
|
|
921
|
+
selectedSourceFilter = r.source;
|
|
922
|
+
document.getElementById('filter-source').value = r.source;
|
|
923
|
+
} else {
|
|
924
|
+
document.getElementById('filter-search').value = r.label;
|
|
925
|
+
}
|
|
926
|
+
syncResetVisibility();
|
|
927
|
+
renderDock();
|
|
928
|
+
renderTable();
|
|
929
|
+
});
|
|
930
|
+
svg.appendChild(g);
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
document.querySelectorAll('[data-treemap-mode]').forEach((btn) => {
|
|
934
|
+
btn.addEventListener('click', () => {
|
|
935
|
+
document.querySelectorAll('[data-treemap-mode]').forEach((b) => b.classList.remove('active'));
|
|
936
|
+
btn.classList.add('active');
|
|
937
|
+
treemapMode = btn.dataset.treemapMode;
|
|
938
|
+
renderTreemap();
|
|
939
|
+
});
|
|
940
|
+
});
|
|
941
|
+
|
|
942
|
+
// 5. Insights Key-Value Ledger + Workflows + Pruning
|
|
943
|
+
function topEntry(mapObj) {
|
|
944
|
+
const entries = Object.entries(mapObj || {}).sort((a, b) => b[1] - a[1]);
|
|
945
|
+
if (entries.length === 0) return null;
|
|
946
|
+
const sum = entries.reduce((a, b) => a + b[1], 0) || 1;
|
|
947
|
+
return { name: entries[0][0], count: entries[0][1], pct: Math.round((entries[0][1] / sum) * 100) };
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
function renderInsights() {
|
|
951
|
+
const autoR = totals.autoReads || 0;
|
|
952
|
+
const manR = totals.manualReads || 0;
|
|
953
|
+
const autoPct = autoR + manR > 0 ? Math.round((autoR / (autoR + manR)) * 100) : 0;
|
|
954
|
+
const topHost = topEntry(totals.hosts);
|
|
955
|
+
const topModel = topEntry(totals.models);
|
|
956
|
+
const topChain = (chains.transitions || [])[0] || null;
|
|
957
|
+
const ins = stats.insights || {};
|
|
958
|
+
const projCands = ins.projectScopeCandidates || [];
|
|
959
|
+
const manualOnly = ins.manualOnlySkills || [];
|
|
960
|
+
|
|
961
|
+
const overviewRows = [
|
|
962
|
+
['Auto-discovery rate', autoPct + '% of runs'],
|
|
963
|
+
['Most active host', topHost ? \`\${topHost.name} · \${topHost.pct}%\` : '—'],
|
|
964
|
+
['Most used model', topModel ? \`\${topModel.name} · \${topModel.pct}%\` : '—'],
|
|
965
|
+
['Top workflow chain', topChain ? \`\${topChain.from} \u2192 \${topChain.to} (\${topChain.sessions}x)\` : 'Single-skill runs'],
|
|
966
|
+
['Reclaimable context tax', \`~\${unusedTok.toLocaleString()} tok/session · \${wastePct}%\`],
|
|
967
|
+
['Single-project global skills', projCands.length + (projCands.length === 1 ? ' candidate' : ' candidates')],
|
|
968
|
+
['Manual-only skills', String(manualOnly.length)],
|
|
969
|
+
['Skills explored', String(inv.used || 0)],
|
|
970
|
+
['Total skills installed', String(inv.enabled || 0)],
|
|
971
|
+
];
|
|
972
|
+
|
|
973
|
+
document.getElementById('panel-overview').innerHTML = overviewRows
|
|
974
|
+
.map(([k, v]) => \`<div class="ledger-row"><span class="ledger-k">\${esc(k)}</span><span class="ledger-v">\${esc(v)}</span></div>\`)
|
|
975
|
+
.join('');
|
|
976
|
+
|
|
977
|
+
// Workflows SVG (#svg-chains)
|
|
978
|
+
const svg = document.getElementById('svg-chains');
|
|
979
|
+
svg.innerHTML = '';
|
|
980
|
+
const transitions = (chains.transitions || []).slice(0, 7);
|
|
981
|
+
if (transitions.length === 0) {
|
|
982
|
+
svg.appendChild(el('text', { x: 360, y: 105, 'text-anchor': 'middle', fill: 'var(--muted)', 'font-size': 13 }, 'No multi-skill transitions recorded in this window.'));
|
|
983
|
+
} else {
|
|
984
|
+
const leftNodes = [...new Set(transitions.map((t) => t.from))];
|
|
985
|
+
const rightNodes = [...new Set(transitions.map((t) => t.to))];
|
|
986
|
+
const maxS = Math.max(1, ...transitions.map((t) => t.sessions));
|
|
987
|
+
const yPos = (arr, name) => 20 + (arr.indexOf(name) * 165) / Math.max(1, arr.length - 1 || 1);
|
|
988
|
+
|
|
989
|
+
for (const t of transitions) {
|
|
990
|
+
const y1 = yPos(leftNodes, t.from) + 10;
|
|
991
|
+
const y2 = yPos(rightNodes, t.to) + 10;
|
|
992
|
+
const sw = Math.max(1.5, (t.sessions / maxS) * 6);
|
|
993
|
+
const path = el('path', {
|
|
994
|
+
d: \`M 190 \${y1} C 310 \${y1}, 410 \${y2}, 530 \${y2}\`,
|
|
995
|
+
fill: 'none', stroke: 'var(--blue-3)', 'stroke-opacity': '0.45', 'stroke-width': sw
|
|
996
|
+
});
|
|
997
|
+
path.addEventListener('mousemove', (evt) => {
|
|
998
|
+
showTip(evt, \`<strong>\${esc(t.from)} \u2192 \${esc(t.to)}</strong><br/>Sessions: \${t.sessions} (\${Math.round(t.probability * 100)}%)<br/>Avg gap: \${t.avgGapSeconds}s\`);
|
|
999
|
+
});
|
|
1000
|
+
path.addEventListener('mouseleave', hideTip);
|
|
1001
|
+
svg.appendChild(path);
|
|
1002
|
+
}
|
|
1003
|
+
for (const name of leftNodes) {
|
|
1004
|
+
const y = yPos(leftNodes, name);
|
|
1005
|
+
svg.appendChild(el('rect', { x: 10, y, width: 180, height: 22, rx: 6, fill: 'var(--bg)', stroke: 'var(--border)' }));
|
|
1006
|
+
svg.appendChild(el('text', { x: 20, y: y + 15, fill: 'var(--text)', 'font-size': 11 }, name.length > 24 ? name.slice(0, 23) + '…' : name));
|
|
1007
|
+
}
|
|
1008
|
+
for (const name of rightNodes) {
|
|
1009
|
+
const y = yPos(rightNodes, name);
|
|
1010
|
+
svg.appendChild(el('rect', { x: 530, y, width: 180, height: 22, rx: 6, fill: 'var(--bg)', stroke: 'var(--border)' }));
|
|
1011
|
+
svg.appendChild(el('text', { x: 540, y: y + 15, fill: 'var(--text)', 'font-size': 11 }, name.length > 24 ? name.slice(0, 23) + '…' : name));
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
const seqs = (chains.sequences || []).slice(0, 4);
|
|
1016
|
+
const pairs = (chains.pairs || []).slice(0, 4);
|
|
1017
|
+
const wfHtml = [];
|
|
1018
|
+
for (const s of seqs) {
|
|
1019
|
+
wfHtml.push(\`<div class="ledger-row"><span class="ledger-k">3-step sequence</span><span class="ledger-v mono">\${esc(s.label)} (\${s.sessions}x)</span></div>\`);
|
|
1020
|
+
}
|
|
1021
|
+
for (const p of pairs) {
|
|
1022
|
+
wfHtml.push(\`<div class="ledger-row"><span class="ledger-k">Co-occurring pair</span><span class="ledger-v">\${esc(p.skills[0])} + \${esc(p.skills[1])} · J=\${p.jaccard.toFixed(2)}</span></div>\`);
|
|
1023
|
+
}
|
|
1024
|
+
document.getElementById('workflows-ledger').innerHTML = wfHtml.join('');
|
|
1025
|
+
|
|
1026
|
+
// Pruning panel
|
|
1027
|
+
const pruneRows = [];
|
|
1028
|
+
for (const g of (unused.bySource || [])) {
|
|
1029
|
+
const cmd = g.source.startsWith('plugin:') ? \`skilltally prune --plugin \${g.source.slice(7)}\` : '';
|
|
1030
|
+
pruneRows.push(\`
|
|
1031
|
+
<div class="rec-row">
|
|
1032
|
+
<div>
|
|
1033
|
+
<div><strong>\${esc(g.source)}</strong> · \${g.skillCount} unused skill(s)</div>
|
|
1034
|
+
<div class="rec-sub">Saves ~\${g.estTokens.toLocaleString()} tok/session (\${(g.descChars / 1024).toFixed(1)} KB)</div>
|
|
1035
|
+
</div>
|
|
1036
|
+
\${cmd ? \`<span class="code-pill">\${esc(cmd)}</span>\` : '<span class="brand-meta">personal</span>'}
|
|
1037
|
+
</div>
|
|
1038
|
+
\`);
|
|
1039
|
+
}
|
|
1040
|
+
for (const s of manualOnly.slice(0, 5)) {
|
|
1041
|
+
pruneRows.push(\`
|
|
1042
|
+
<div class="rec-row">
|
|
1043
|
+
<div>
|
|
1044
|
+
<div><strong>\${esc(s.skill)}</strong> · manual-only (\${s.reads} read(s))</div>
|
|
1045
|
+
<div class="rec-sub">0% auto-match — sharpen SKILL.md description</div>
|
|
1046
|
+
</div>
|
|
1047
|
+
<span class="brand-meta">~\${s.est_tokens} tok</span>
|
|
1048
|
+
</div>
|
|
1049
|
+
\`);
|
|
1050
|
+
}
|
|
1051
|
+
for (const c of projCands.slice(0, 5)) {
|
|
1052
|
+
pruneRows.push(\`
|
|
1053
|
+
<div class="rec-row">
|
|
1054
|
+
<div>
|
|
1055
|
+
<div><strong>\${esc(c.skill)}</strong> · single-project (\${esc(c.project)})</div>
|
|
1056
|
+
<div class="rec-sub">Move from \${esc(c.source)} to repo-local skills</div>
|
|
1057
|
+
</div>
|
|
1058
|
+
<span class="brand-meta">~\${c.est_tokens} tok</span>
|
|
1059
|
+
</div>
|
|
1060
|
+
\`);
|
|
1061
|
+
}
|
|
1062
|
+
document.getElementById('panel-pruning').innerHTML = pruneRows.length > 0
|
|
1063
|
+
? pruneRows.join('')
|
|
1064
|
+
: '<div class="brand-meta">No pruning or optimization candidates detected.</div>';
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
document.querySelectorAll('[data-insights-tab]').forEach((btn) => {
|
|
1068
|
+
btn.addEventListener('click', () => {
|
|
1069
|
+
document.querySelectorAll('[data-insights-tab]').forEach((b) => b.classList.remove('active'));
|
|
1070
|
+
btn.classList.add('active');
|
|
1071
|
+
const tab = btn.dataset.insightsTab;
|
|
1072
|
+
document.getElementById('panel-overview').classList.toggle('hidden', tab !== 'overview');
|
|
1073
|
+
document.getElementById('panel-workflows').classList.toggle('hidden', tab !== 'workflows');
|
|
1074
|
+
document.getElementById('panel-pruning').classList.toggle('hidden', tab !== 'pruning');
|
|
1075
|
+
});
|
|
1076
|
+
});
|
|
1077
|
+
|
|
1078
|
+
// 6. Skills Directory Table
|
|
1079
|
+
const hostSet = new Set();
|
|
1080
|
+
const sourceSet = new Set();
|
|
1081
|
+
for (const u of unified) {
|
|
1082
|
+
for (const h of (u.hosts || [])) hostSet.add(h);
|
|
1083
|
+
if (u.source) sourceSet.add(u.source);
|
|
1084
|
+
}
|
|
1085
|
+
const hostSel = document.getElementById('filter-host');
|
|
1086
|
+
for (const h of [...hostSet].sort()) hostSel.appendChild(new Option(h, h));
|
|
1087
|
+
const srcSel = document.getElementById('filter-source');
|
|
1088
|
+
for (const s of [...sourceSet].sort()) srcSel.appendChild(new Option(s, s));
|
|
1089
|
+
|
|
1090
|
+
let statusFilter = 'all';
|
|
1091
|
+
let sortKey = 'activations';
|
|
1092
|
+
let sortDir = -1;
|
|
1093
|
+
|
|
1094
|
+
function syncResetVisibility() {
|
|
1095
|
+
const active =
|
|
1096
|
+
document.getElementById('filter-search').value.trim() !== '' ||
|
|
1097
|
+
statusFilter !== 'all' ||
|
|
1098
|
+
hostSel.value !== 'all' ||
|
|
1099
|
+
srcSel.value !== 'all';
|
|
1100
|
+
document.getElementById('btn-reset-filter').classList.toggle('hidden', !active);
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
function renderTable() {
|
|
1104
|
+
const q = document.getElementById('filter-search').value.trim().toLowerCase();
|
|
1105
|
+
const hf = hostSel.value;
|
|
1106
|
+
const sf = srcSel.value;
|
|
1107
|
+
|
|
1108
|
+
const filtered = unified.filter((r) => {
|
|
1109
|
+
if (statusFilter !== 'all' && r.status !== statusFilter) return false;
|
|
1110
|
+
if (hf !== 'all' && !(r.hosts || []).includes(hf)) return false;
|
|
1111
|
+
if (sf !== 'all' && r.source !== sf) return false;
|
|
1112
|
+
if (q && !r.skill.toLowerCase().includes(q) && !r.source.toLowerCase().includes(q)) return false;
|
|
1113
|
+
return true;
|
|
1114
|
+
}).sort((a, b) => {
|
|
1115
|
+
const av = a[sortKey];
|
|
1116
|
+
const bv = b[sortKey];
|
|
1117
|
+
if (typeof av === 'number' && typeof bv === 'number') return (av - bv) * sortDir || b.raw_tokens - a.raw_tokens;
|
|
1118
|
+
return String(av).localeCompare(String(bv)) * sortDir;
|
|
1119
|
+
});
|
|
1120
|
+
|
|
1121
|
+
document.getElementById('table-count').textContent = \`Showing \${filtered.length} of \${unified.length} skill(s)\`;
|
|
1122
|
+
document.getElementById('skills-tbody').innerHTML = filtered.slice(0, 250).map((r) => \`
|
|
1123
|
+
<tr>
|
|
1124
|
+
<td><span class="status-dot \${r.status}"></span>\${esc(r.skill)}</td>
|
|
1125
|
+
<td class="mono" style="color:var(--muted)">\${esc(r.source)}</td>
|
|
1126
|
+
<td class="num">\${r.activations}</td>
|
|
1127
|
+
<td class="num" style="color:var(--muted)">\${r.reads}</td>
|
|
1128
|
+
<td class="num" style="color:var(--muted)">~\${r.raw_tokens.toLocaleString()}</td>
|
|
1129
|
+
<td class="num" style="color:var(--muted)">\${r.reads > 0 ? Math.round(r.manualRatio * 100) + '%' : '—'}</td>
|
|
1130
|
+
<td class="mono" style="color:var(--muted)">\${esc(r.sparkline)}</td>
|
|
1131
|
+
<td style="color:var(--muted)">\${esc((r.hosts || []).join(', '))}</td>
|
|
1132
|
+
</tr>
|
|
1133
|
+
\`).join('');
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
document.querySelectorAll('[data-status-tab]').forEach((btn) => {
|
|
1137
|
+
btn.addEventListener('click', () => {
|
|
1138
|
+
document.querySelectorAll('[data-status-tab]').forEach((b) => b.classList.remove('active'));
|
|
1139
|
+
btn.classList.add('active');
|
|
1140
|
+
statusFilter = btn.dataset.statusTab;
|
|
1141
|
+
syncResetVisibility();
|
|
1142
|
+
renderTable();
|
|
1143
|
+
});
|
|
1144
|
+
});
|
|
1145
|
+
|
|
1146
|
+
['filter-search', 'filter-host', 'filter-source'].forEach((id) => {
|
|
1147
|
+
document.getElementById(id).addEventListener('input', () => {
|
|
1148
|
+
if (id === 'filter-source') {
|
|
1149
|
+
selectedSourceFilter = srcSel.value === 'all' ? null : srcSel.value;
|
|
1150
|
+
renderDock();
|
|
1151
|
+
}
|
|
1152
|
+
syncResetVisibility();
|
|
1153
|
+
renderTable();
|
|
1154
|
+
});
|
|
1155
|
+
document.getElementById(id).addEventListener('change', () => {
|
|
1156
|
+
if (id === 'filter-source') {
|
|
1157
|
+
selectedSourceFilter = srcSel.value === 'all' ? null : srcSel.value;
|
|
1158
|
+
renderDock();
|
|
1159
|
+
}
|
|
1160
|
+
syncResetVisibility();
|
|
1161
|
+
renderTable();
|
|
1162
|
+
});
|
|
1163
|
+
});
|
|
1164
|
+
|
|
1165
|
+
document.querySelectorAll('th[data-sort]').forEach((th) => {
|
|
1166
|
+
th.addEventListener('click', () => {
|
|
1167
|
+
const k = th.dataset.sort;
|
|
1168
|
+
if (sortKey === k) sortDir *= -1;
|
|
1169
|
+
else { sortKey = k; sortDir = k === 'skill' || k === 'source' ? 1 : -1; }
|
|
1170
|
+
renderTable();
|
|
1171
|
+
});
|
|
1172
|
+
});
|
|
1173
|
+
|
|
1174
|
+
document.getElementById('btn-reset-filter').addEventListener('click', () => {
|
|
1175
|
+
document.getElementById('filter-search').value = '';
|
|
1176
|
+
statusFilter = 'all';
|
|
1177
|
+
document.querySelectorAll('[data-status-tab]').forEach((b) => b.classList.toggle('active', b.dataset.statusTab === 'all'));
|
|
1178
|
+
hostSel.value = 'all';
|
|
1179
|
+
srcSel.value = 'all';
|
|
1180
|
+
selectedSourceFilter = null;
|
|
1181
|
+
syncResetVisibility();
|
|
1182
|
+
renderDock();
|
|
1183
|
+
renderTable();
|
|
1184
|
+
});
|
|
1185
|
+
|
|
1186
|
+
// 7. Mermaid generator
|
|
1187
|
+
function buildMermaid(kind) {
|
|
1188
|
+
if (kind === 'pie') {
|
|
1189
|
+
const groups = (unused.bySource || []).slice(0, 8);
|
|
1190
|
+
if (groups.length === 0) return 'pie title Unused Context Tax (tokens/session)\\n "All skills active" : 1';
|
|
1191
|
+
return 'pie title Unused Context Tax (~tokens/session)\\n' +
|
|
1192
|
+
groups.map((g) => \` "\${g.source}" : \${Math.max(1, g.estTokens)}\`).join('\\n');
|
|
1193
|
+
}
|
|
1194
|
+
if (kind === 'timeline') {
|
|
1195
|
+
const rows = (timeline.rows || []).slice(-14);
|
|
1196
|
+
if (rows.length === 0) return 'xychart-beta\\n title "Skill Activations"\\n x-axis ["none"]\\n bar [0]';
|
|
1197
|
+
const xs = rows.map((r) => \`"\${r.bucket}"\`).join(', ');
|
|
1198
|
+
const ys = rows.map((r) => r.activations).join(', ');
|
|
1199
|
+
return \`xychart-beta\\n title "Skill Activations (\${timeline.by || 'day'})"\\n x-axis [\${xs}]\\n y-axis "Activations"\\n bar [\${ys}]\`;
|
|
1200
|
+
}
|
|
1201
|
+
const trans = (chains.transitions || []).slice(0, 10);
|
|
1202
|
+
if (trans.length === 0) return 'flowchart LR\\n A[No multi-skill chains recorded]';
|
|
1203
|
+
const sanitize = (s) => s.replace(/[^A-Za-z0-9_]/g, '_');
|
|
1204
|
+
return 'flowchart LR\\n' + trans.map((t) =>
|
|
1205
|
+
\` \${sanitize(t.from)}["\${t.from}"] -->|\${t.sessions}x| \${sanitize(t.to)}["\${t.to}"]\`
|
|
1206
|
+
).join('\\n');
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
const dialog = document.getElementById('mermaid-dialog');
|
|
1210
|
+
let mermaidKind = 'pie';
|
|
1211
|
+
const updateMermaid = () => {
|
|
1212
|
+
document.getElementById('mermaid-code').textContent = buildMermaid(mermaidKind);
|
|
1213
|
+
};
|
|
1214
|
+
document.getElementById('btn-mermaid').addEventListener('click', () => {
|
|
1215
|
+
updateMermaid();
|
|
1216
|
+
dialog.showModal();
|
|
1217
|
+
});
|
|
1218
|
+
document.getElementById('btn-close-mermaid').addEventListener('click', () => dialog.close());
|
|
1219
|
+
document.querySelectorAll('[data-mermaid]').forEach((btn) => {
|
|
1220
|
+
btn.addEventListener('click', () => {
|
|
1221
|
+
document.querySelectorAll('[data-mermaid]').forEach((b) => b.classList.remove('active'));
|
|
1222
|
+
btn.classList.add('active');
|
|
1223
|
+
mermaidKind = btn.dataset.mermaid;
|
|
1224
|
+
updateMermaid();
|
|
1225
|
+
});
|
|
1226
|
+
});
|
|
1227
|
+
document.getElementById('btn-copy-mermaid').addEventListener('click', async () => {
|
|
1228
|
+
try {
|
|
1229
|
+
await navigator.clipboard.writeText(document.getElementById('mermaid-code').textContent);
|
|
1230
|
+
document.getElementById('btn-copy-mermaid').textContent = 'Copied';
|
|
1231
|
+
setTimeout(() => { document.getElementById('btn-copy-mermaid').textContent = 'Copy Snippet'; }, 1500);
|
|
1232
|
+
} catch {}
|
|
1233
|
+
});
|
|
1234
|
+
|
|
1235
|
+
renderActivity();
|
|
1236
|
+
renderDock();
|
|
1237
|
+
renderTreemap();
|
|
1238
|
+
renderInsights();
|
|
1239
|
+
renderTable();
|
|
1240
|
+
})();
|
|
1241
|
+
</script>
|
|
1242
|
+
</body>
|
|
1243
|
+
</html>
|
|
1244
|
+
`;
|
|
1245
|
+
}
|