@specode/pi-subscription-usage 1.0.0 → 1.0.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@specode/pi-subscription-usage",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Show subscription quota and Codex reset credits for Codex, OpenCode Go, Grok, and Kimi in Pi",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/display.ts CHANGED
@@ -45,6 +45,13 @@ export function usageAmount(
45
45
  : Math.max(0, bucket.limit - opposite);
46
46
  }
47
47
 
48
+ export function formatUsagePercent(value: number): string {
49
+ const hundredths = Math.round(clampPercent(value) * 100) / 100;
50
+ return Number.isInteger(hundredths)
51
+ ? String(hundredths)
52
+ : hundredths.toFixed(2);
53
+ }
54
+
48
55
  function clampPercent(value: number): number {
49
56
  return Math.min(100, Math.max(0, value));
50
57
  }
package/src/format.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  // Formatting model adapted from @narumitw/pi-usage@0.53.0 (MIT).
2
2
  import {
3
3
  DEFAULT_USAGE_DISPLAY_MODE,
4
+ formatUsagePercent,
4
5
  usageAmount,
5
6
  usagePercent,
6
7
  type UsageDisplayMode,
@@ -94,7 +95,7 @@ function formatBucket(
94
95
  if (selectedPercent !== undefined) {
95
96
  const filled = Math.round((selectedPercent / 100) * BAR_SEGMENTS);
96
97
  const bar = `${"█".repeat(filled)}${"░".repeat(BAR_SEGMENTS - filled)}`;
97
- const percent = `${String(Math.round(selectedPercent)).padStart(3)}%`;
98
+ const percent = `${formatUsagePercent(selectedPercent).padStart(3)}%`;
98
99
  if (
99
100
  bucket.unit !== "percent" &&
100
101
  bucket.limit !== undefined &&
@@ -68,9 +68,7 @@ function kimiPlanName(root: Record<string, unknown>): string | undefined {
68
68
  if (typeof membership?.level !== "string") return undefined;
69
69
  const level = sanitizeDisplayText(membership.level, MAX_PLAN_LEVEL_LENGTH);
70
70
  if (!level) return undefined;
71
- return Object.hasOwn(KIMI_PLAN_NAMES, level)
72
- ? KIMI_PLAN_NAMES[level]
73
- : level;
71
+ return Object.hasOwn(KIMI_PLAN_NAMES, level) ? KIMI_PLAN_NAMES[level] : level;
74
72
  }
75
73
 
76
74
  function parseQuota(
@@ -79,13 +77,19 @@ function parseQuota(
79
77
  const record = asObject(value);
80
78
  if (!record) return undefined;
81
79
  const limit = asFiniteNumber(record.limit);
82
- const used = asFiniteNumber(record.used);
83
- const remaining = asFiniteNumber(record.remaining);
80
+ let used = asFiniteNumber(record.used);
81
+ let remaining = asFiniteNumber(record.remaining);
82
+ if (limit === undefined || limit <= 0) return undefined;
83
+ // Kimi omits remaining when used has rounded up to the limit.
84
+ if (used === undefined && remaining !== undefined) {
85
+ used = Math.max(0, limit - remaining);
86
+ }
87
+ if (remaining === undefined && used !== undefined) {
88
+ remaining = Math.max(0, limit - used);
89
+ }
84
90
  if (
85
- limit === undefined ||
86
91
  used === undefined ||
87
92
  remaining === undefined ||
88
- limit <= 0 ||
89
93
  used < 0 ||
90
94
  remaining < 0
91
95
  ) {
package/src/status.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  DEFAULT_USAGE_DISPLAY_MODE,
3
+ formatUsagePercent,
3
4
  usagePercent,
4
5
  usagePercentRemaining,
5
6
  usagePercentUsed,
@@ -97,8 +98,7 @@ export function formatUsageStatusline(
97
98
  if (event.status !== "ready" || event.windows.length === 0) return undefined;
98
99
  return event.windows
99
100
  .map(
100
- (window) =>
101
- `${window.label} ${Math.round(window.displayPercent).toString()}%`,
101
+ (window) => `${window.label} ${formatUsagePercent(window.displayPercent)}%`,
102
102
  )
103
103
  .join(" · ");
104
104
  }