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