skilltally 1.0.3 → 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.
@@ -24,10 +24,25 @@ function formatHostLine(hosts) {
24
24
  return entries.map(([h, n]) => `${h} ${n}`).join(' · ');
25
25
  }
26
26
 
27
+ export function renderMeter(ratio, width = 16) {
28
+ const r = Number.isFinite(ratio) ? Math.max(0, Math.min(1, ratio)) : 0;
29
+ const filled = Math.round(r * width);
30
+ return '█'.repeat(filled) + '░'.repeat(Math.max(0, width - filled));
31
+ }
32
+
27
33
  export function formatStats(report, { limit = null, heading = 'skilltally', bySource = false } = {}) {
28
34
  const lines = [];
29
35
  lines.push(`${heading} — ${formatWindow(report.window)}`);
30
36
  lines.push(`hosts: ${formatHostLine(report.totals.hosts)}`);
37
+ if (
38
+ report.totals?.via &&
39
+ Object.keys(report.totals.via).length > 0 &&
40
+ ((report.totals.autoReads || 0) > 0 || (report.totals.manualReads || 0) > 0)
41
+ ) {
42
+ lines.push(
43
+ `triggers: auto ${report.totals.autoReads || 0} · manual ${report.totals.manualReads || 0}`
44
+ );
45
+ }
31
46
  lines.push('');
32
47
 
33
48
  const displayRows = limit && limit > 0 ? report.rows.slice(0, limit) : report.rows;
@@ -39,14 +54,15 @@ export function formatStats(report, { limit = null, heading = 'skilltally', bySo
39
54
  10,
40
55
  ...displayRows.map((r) => (bySource ? `${r.skill} (${r.source})` : r.skill).length)
41
56
  );
57
+ const hostsCol = Math.max(5, ...displayRows.map((r) => (r.hosts || []).join(', ').length));
42
58
  const rankW = Math.max(2, String(displayRows.length).length + 1);
43
59
  lines.push(
44
- ` ${padLeft('#', rankW)} ${padRight('skill', skillCol)} ${padLeft('activations', 11)} ${padLeft('reads', 5)} ${padRight('last used', 16)} hosts`
60
+ ` ${padLeft('#', rankW)} ${padRight('skill', skillCol)} ${padLeft('activations', 11)} ${padLeft('reads', 5)} ${padRight('last used', 16)} ${padRight('hosts', hostsCol)} trend (14d)`
45
61
  );
46
62
  displayRows.forEach((r, idx) => {
47
63
  const label = bySource ? `${r.skill} (${r.source})` : r.skill;
48
64
  lines.push(
49
- ` ${padLeft(idx + 1, rankW)} ${padRight(label, skillCol)} ${padLeft(r.activations, 11)} ${padLeft(r.reads, 5)} ${padRight(formatDateCompact(r.last_used), 16)} ${r.hosts.join(', ')}`
65
+ ` ${padLeft(idx + 1, rankW)} ${padRight(label, skillCol)} ${padLeft(r.activations, 11)} ${padLeft(r.reads, 5)} ${padRight(formatDateCompact(r.last_used), 16)} ${padRight((r.hosts || []).join(', '), hostsCol)} ${r.sparkline || '··············'}`
50
66
  );
51
67
  });
52
68
  if (limit && report.rows.length > limit) {
@@ -72,6 +88,13 @@ export function formatUnused(report, { showAll = false } = {}) {
72
88
  lines.push(
73
89
  `Unused enabled skills — ${formatWindow(report.window)}: ${u.total} (${kb} KB ≈ ~${u.totalEstTokens.toLocaleString()} tok/session)`
74
90
  );
91
+ if ((report.inventory?.enabledEstTokens || 0) > 0) {
92
+ const ratio = u.totalEstTokens / report.inventory.enabledEstTokens;
93
+ const pct = Math.round(ratio * 100);
94
+ lines.push(
95
+ `context tax: [${renderMeter(ratio, 16)}] ${pct}% unused (~${u.totalEstTokens.toLocaleString()} / ~${report.inventory.enabledEstTokens.toLocaleString()} tok/session)`
96
+ );
97
+ }
75
98
 
76
99
  if (u.total === 0) {
77
100
  lines.push('All enabled installed skills were used in this window.');
@@ -269,3 +292,201 @@ export function formatDebug(status) {
269
292
  }
270
293
  return lines.join('\n');
271
294
  }
295
+
296
+ function formatGapSeconds(sec) {
297
+ if (!Number.isFinite(sec) || sec <= 0) return '0s';
298
+ if (sec < 60) return `${sec}s`;
299
+ const m = Math.floor(sec / 60);
300
+ const s = sec % 60;
301
+ return s > 0 ? `${m}m${s}s` : `${m}m`;
302
+ }
303
+
304
+ export function formatChains(chainsReport) {
305
+ const lines = [];
306
+ lines.push(`skilltally chains — ${formatWindow(chainsReport.window)}`);
307
+ lines.push(
308
+ `sessions: ${chainsReport.totals.sessions} · multi-skill: ${chainsReport.totals.multiSkillSessions} · transitions: ${chainsReport.totals.transitions} · pairs: ${chainsReport.totals.pairs}`
309
+ );
310
+ lines.push('');
311
+
312
+ if (
313
+ chainsReport.transitions.length === 0 &&
314
+ chainsReport.pairs.length === 0 &&
315
+ chainsReport.sequences.length === 0
316
+ ) {
317
+ lines.push('No multi-skill session chains found in this window.');
318
+ return lines.join('\n');
319
+ }
320
+
321
+ if (chainsReport.transitions.length > 0) {
322
+ lines.push('Top ordered transitions (A -> B):');
323
+ const labels = chainsReport.transitions.map((t) => `${t.from} -> ${t.to}`);
324
+ const labelW = Math.max(16, ...labels.map((l) => l.length));
325
+ lines.push(
326
+ ` ${padRight('transition', labelW)} ${padLeft('sessions', 8)} ${padLeft('prob', 6)} ${padLeft('avg gap', 8)}`
327
+ );
328
+ for (let i = 0; i < chainsReport.transitions.length; i++) {
329
+ const t = chainsReport.transitions[i];
330
+ const pct = `${Math.round((t.probability || 0) * 100)}%`;
331
+ lines.push(
332
+ ` ${padRight(labels[i], labelW)} ${padLeft(t.sessions, 8)} ${padLeft(pct, 6)} ${padLeft(formatGapSeconds(t.avgGapSeconds), 8)}`
333
+ );
334
+ }
335
+ lines.push('');
336
+ }
337
+
338
+ if (chainsReport.pairs.length > 0) {
339
+ lines.push('Top co-occurring pairs (same session):');
340
+ const pairLabels = chainsReport.pairs.map((p) => `${p.skills[0]} + ${p.skills[1]}`);
341
+ const pairW = Math.max(16, ...pairLabels.map((l) => l.length));
342
+ lines.push(` ${padRight('pair', pairW)} ${padLeft('sessions', 8)} ${padLeft('jaccard', 7)}`);
343
+ for (let i = 0; i < chainsReport.pairs.length; i++) {
344
+ const p = chainsReport.pairs[i];
345
+ lines.push(
346
+ ` ${padRight(pairLabels[i], pairW)} ${padLeft(p.sessions, 8)} ${padLeft(p.jaccard.toFixed(2), 7)}`
347
+ );
348
+ }
349
+ lines.push('');
350
+ }
351
+
352
+ if (chainsReport.sequences.length > 0) {
353
+ lines.push('Common 3-step workflows:');
354
+ const seqW = Math.max(20, ...chainsReport.sequences.map((s) => s.label.length));
355
+ for (const s of chainsReport.sequences) {
356
+ lines.push(` ${padRight(s.label, seqW)} ${padLeft(s.sessions, 3)} session(s)`);
357
+ }
358
+ }
359
+
360
+ return lines.join('\n').trimEnd();
361
+ }
362
+
363
+ export function formatInsights(report) {
364
+ const lines = [];
365
+ lines.push(`skilltally insights — ${formatWindow(report.window)}`);
366
+ lines.push(
367
+ `hosts: ${formatHostLine(report.totals.hosts)} · sessions: ${report.totals.sessions || 0} · skills used: ${report.totals.uniqueSkills || 0}`
368
+ );
369
+ lines.push('');
370
+
371
+ // 1. Context Tax & ROI Efficiency
372
+ lines.push('1. Context Tax & ROI Efficiency');
373
+ const enabledTok = report.inventory?.enabledEstTokens || 0;
374
+ const unusedTok = report.unused?.totalEstTokens || 0;
375
+ if (enabledTok > 0) {
376
+ const ratio = unusedTok / enabledTok;
377
+ const pct = Math.round(ratio * 100);
378
+ lines.push(
379
+ ` context tax: [${renderMeter(ratio, 18)}] ${pct}% unused (~${unusedTok.toLocaleString()} / ~${enabledTok.toLocaleString()} tok/session)`
380
+ );
381
+ } else {
382
+ lines.push(' No enabled skill inventory descriptions found.');
383
+ }
384
+
385
+ const highCost = report.insights?.highCostSkills || [];
386
+ if (highCost.length > 0) {
387
+ const w = Math.max(12, ...highCost.map((s) => s.skill.length));
388
+ lines.push(' Highest cumulative context cost per activation:');
389
+ for (const s of highCost.slice(0, 6)) {
390
+ lines.push(
391
+ ` ${padRight(s.skill, w)} ~${padLeft(s.est_tokens, 4)} tok/sess ${padLeft(s.activations, 4)} act ~${s.tokenCostPerActivation.toLocaleString()} tok/activation`
392
+ );
393
+ }
394
+ }
395
+ lines.push('');
396
+
397
+ // 2. Trigger Mode Breakdown (via)
398
+ lines.push('2. Trigger Mode Breakdown (via)');
399
+ const autoReads = report.totals?.autoReads || 0;
400
+ const manualReads = report.totals?.manualReads || 0;
401
+ const totalReads = autoReads + manualReads;
402
+ if (totalReads > 0) {
403
+ const autoPct = Math.round((autoReads / totalReads) * 100);
404
+ const manualPct = 100 - autoPct;
405
+ lines.push(` auto: ${autoReads} (${autoPct}%) · manual: ${manualReads} (${manualPct}%)`);
406
+ const viaEntries = Object.entries(report.totals.via || {}).sort((a, b) => b[1] - a[1]);
407
+ if (viaEntries.length > 0) {
408
+ lines.push(` via breakdown: ${viaEntries.map(([k, v]) => `${k} ${v}`).join(' · ')}`);
409
+ }
410
+ } else {
411
+ lines.push(' No trigger events recorded in this window.');
412
+ }
413
+
414
+ const manualOnly = report.insights?.manualOnlySkills || [];
415
+ if (manualOnly.length > 0) {
416
+ lines.push(' Manual-only skills (0% auto-match — review SKILL.md description triggers):');
417
+ for (const s of manualOnly.slice(0, 8)) {
418
+ lines.push(
419
+ ` ${s.skill} (${s.source}) — ${s.reads} read(s), ~${s.est_tokens} tok/session`
420
+ );
421
+ }
422
+ }
423
+ lines.push('');
424
+
425
+ // 3. Project-Scoping Candidates
426
+ lines.push('3. Project-Scoping Candidates');
427
+ const projCand = report.insights?.projectScopeCandidates || [];
428
+ if (projCand.length > 0) {
429
+ lines.push(' Global/plugin skills used in only 1 project (consider moving to repo .agents/skills or .claude/skills):');
430
+ for (const c of projCand.slice(0, 8)) {
431
+ lines.push(
432
+ ` ${c.skill} (${c.source}) -> only in "${c.project}" (${c.activations} act, ~${c.est_tokens} tok/session)`
433
+ );
434
+ }
435
+ } else {
436
+ lines.push(' None detected (skills are either multi-project or already project-scoped).');
437
+ }
438
+
439
+ // 4. Model Breakdown
440
+ const modelEntries = Object.entries(report.totals?.models || {}).sort((a, b) => b[1] - a[1]);
441
+ if (modelEntries.length > 0) {
442
+ lines.push('');
443
+ lines.push('4. Model Breakdown');
444
+ const mw = Math.max(12, ...modelEntries.map(([m]) => m.length));
445
+ for (const [model, count] of modelEntries) {
446
+ lines.push(` ${padRight(model, mw)} ${padLeft(count, 5)} read(s)`);
447
+ }
448
+ }
449
+
450
+ return lines.join('\n');
451
+ }
452
+
453
+ export function formatPrune(res) {
454
+ const lines = [];
455
+ lines.push(`skilltally prune${res.dryRun ? ' (dry-run)' : ''} — ${formatWindow(res.window)}`);
456
+ lines.push(
457
+ `estimated savings: ${res.savedKb} KB (~${(res.savedTokensPerSession || 0).toLocaleString()} tok/session)`
458
+ );
459
+ lines.push('');
460
+
461
+ if (res.disabledPlugins.length === 0 && res.disabledSkills.length === 0) {
462
+ lines.push('No matching unused plugins or skills to disable.');
463
+ return lines.join('\n');
464
+ }
465
+
466
+ if (res.disabledPlugins.length > 0) {
467
+ lines.push(res.dryRun ? 'Plugins to disable:' : 'Disabled plugins:');
468
+ for (const p of res.disabledPlugins) {
469
+ lines.push(
470
+ ` ${padRight(p.source, 28)} [${p.host}] ${p.skillCount} skill(s) ~${p.estTokens} tok/session`
471
+ );
472
+ }
473
+ lines.push('');
474
+ }
475
+
476
+ if (res.disabledSkills.length > 0) {
477
+ lines.push(res.dryRun ? 'Skills to disable:' : 'Disabled skills:');
478
+ for (const s of res.disabledSkills) {
479
+ lines.push(` ${padRight(s.name, 28)} [${s.host}] ~${s.est_tokens} tok/session`);
480
+ }
481
+ lines.push('');
482
+ }
483
+
484
+ if (res.backups && res.backups.length > 0) {
485
+ lines.push('Backups:');
486
+ for (const b of res.backups) {
487
+ lines.push(` ${b}`);
488
+ }
489
+ }
490
+
491
+ return lines.join('\n').trimEnd();
492
+ }