Skip to content

Commit c681654

Browse files
committed
feat: more compact usage info
1 parent ca743a3 commit c681654

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

src/check-usage.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import consola from "consola"
33

44
import { ensurePaths } from "./lib/paths"
55
import { 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

811
export 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)

src/services/github/get-copilot-usage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const getCopilotUsage = async (): Promise<CopilotUsageResponse> => {
1414
return (await response.json()) as CopilotUsageResponse
1515
}
1616

17-
interface QuotaDetail {
17+
export interface QuotaDetail {
1818
entitlement: number
1919
overage_count: number
2020
overage_permitted: boolean

0 commit comments

Comments
 (0)