@specode/pi-subscription-usage 1.0.1 → 1.0.2

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.1",
3
+ "version": "1.0.2",
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,11 +45,9 @@ export function usageAmount(
45
45
  : Math.max(0, bucket.limit - opposite);
46
46
  }
47
47
 
48
+ /** Integer presentation only; keep the original number for semantic decisions. */
48
49
  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);
50
+ return String(Math.round(clampPercent(value)));
53
51
  }
54
52
 
55
53
  function clampPercent(value: number): number {
@@ -80,7 +80,13 @@ function parseQuota(
80
80
  let used = asFiniteNumber(record.used);
81
81
  let remaining = asFiniteNumber(record.remaining);
82
82
  if (limit === undefined || limit <= 0) return undefined;
83
- // Kimi omits remaining when used has rounded up to the limit.
83
+ // Missing fields can be derived; present-but-invalid data must not become zero.
84
+ if (
85
+ (record.used !== undefined && used === undefined) ||
86
+ (record.remaining !== undefined && remaining === undefined)
87
+ )
88
+ return undefined;
89
+ // Observed: used=limit=100 with remaining omitted. The cause is undocumented.
84
90
  if (used === undefined && remaining !== undefined) {
85
91
  used = Math.max(0, limit - remaining);
86
92
  }
@@ -137,6 +143,7 @@ function asObject(value: unknown): Record<string, unknown> | undefined {
137
143
 
138
144
  function asFiniteNumber(value: unknown): number | undefined {
139
145
  if (typeof value !== "number" && typeof value !== "string") return undefined;
146
+ if (typeof value === "string" && !value.trim()) return undefined;
140
147
  const parsed = Number(value);
141
148
  return Number.isFinite(parsed) ? parsed : undefined;
142
149
  }