From db223f07939c47c83b23373da4e050207e6d38e0 Mon Sep 17 00:00:00 2001 From: Eyejoker Date: Wed, 25 Mar 2026 07:18:04 +0900 Subject: [PATCH] fix: clamp bar() and padName() to prevent negative repeat count Usage dashboard crashed with RangeError: Invalid count value: -7 when pct exceeded 100 or name exceeded maxNameWidth. --- src/unified-dashboard.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/unified-dashboard.ts b/src/unified-dashboard.ts index e388cec..cc0db85 100644 --- a/src/unified-dashboard.ts +++ b/src/unified-dashboard.ts @@ -515,7 +515,7 @@ async function buildUsageContent(): Promise { const lines: string[] = ['📊 *ė‚ŽėšĐ량*']; const bar = (pct: number) => { - const filled = Math.round(pct / 10); + const filled = Math.max(0, Math.min(10, Math.round(pct / 10))); return '█'.repeat(filled) + '░'.repeat(10 - filled); }; @@ -591,7 +591,7 @@ async function buildUsageContent(): Promise { const maxNameWidth = Math.max(8, ...rows.map((r) => visualWidth(r.name))) + 1; const padName = (s: string) => - s + ' '.repeat(maxNameWidth - visualWidth(s)); + s + ' '.repeat(Math.max(0, maxNameWidth - visualWidth(s))); lines.push('```'); lines.push(`${' '.repeat(maxNameWidth)}5-Hour 7-Day`); for (const row of rows) {