@@ -3,7 +3,10 @@ import consola from "consola"
33
44import { ensurePaths } from "./lib/paths"
55import { setupGitHubToken } from "./lib/token"
6- import { getCopilotUsage } from "./services/github/get-copilot-usage"
6+ import {
7+ getCopilotUsage ,
8+ type QuotaDetail ,
9+ } from "./services/github/get-copilot-usage"
710
811export const checkUsage = defineCommand ( {
912 meta : {
@@ -21,16 +24,31 @@ export const checkUsage = defineCommand({
2124 const premiumPercentUsed =
2225 premiumTotal > 0 ? ( premiumUsed / premiumTotal ) * 100 : 0
2326 const premiumPercentRemaining = premium . percent_remaining
24- // Highlight: bold yellow
25- const premiumLine = `\u001b[1m\u001b[33mPremium: ${ premiumUsed } /${ premiumTotal } used (${ premiumPercentUsed . toFixed ( 1 ) } % used, ${ premiumPercentRemaining . toFixed ( 1 ) } % remaining)\u001b[0m`
27+
28+ // Helper to summarize a quota snapshot
29+ function summarizeQuota ( name : string , snap : QuotaDetail | undefined ) {
30+ if ( ! snap ) return `${ name } : N/A`
31+ const total = snap . entitlement
32+ const used = total - snap . remaining
33+ const percentUsed = total > 0 ? ( used / total ) * 100 : 0
34+ const percentRemaining = snap . percent_remaining
35+ return `${ name } : ${ used } /${ total } used (${ percentUsed . toFixed ( 1 ) } % used, ${ percentRemaining . toFixed ( 1 ) } % remaining)`
36+ }
37+
38+ const premiumLine = `Premium: ${ premiumUsed } /${ premiumTotal } used (${ premiumPercentUsed . toFixed ( 1 ) } % used, ${ premiumPercentRemaining . toFixed ( 1 ) } % remaining)`
39+ const chatLine = summarizeQuota ( "Chat" , usage . quota_snapshots . chat )
40+ const completionsLine = summarizeQuota (
41+ "Completions" ,
42+ usage . quota_snapshots . completions ,
43+ )
2644
2745 consola . box (
2846 `Copilot Usage (plan: ${ usage . copilot_plan } )\n`
2947 + `Quota resets: ${ usage . quota_reset_date } \n`
30- + `${ premiumLine } \n`
31- + `\nChat: ${ JSON . stringify ( usage . quota_snapshots . chat , null , 2 ) } \n`
32- + `Completions: ${ JSON . stringify ( usage . quota_snapshots . completions , null , 2 ) } \n`
33- + `Premium details: ${ JSON . stringify ( premium , null , 2 ) } ` ,
48+ + `\nQuotas: \n`
49+ + ` ${ premiumLine } \n`
50+ + ` ${ chatLine } \n`
51+ + ` ${ completionsLine } ` ,
3452 )
3553 } catch ( err ) {
3654 consola . error ( "Failed to fetch Copilot usage:" , err )
0 commit comments