@specode/pi-subscription-usage 1.1.0 → 1.1.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/README.md CHANGED
@@ -88,7 +88,7 @@ The extension publishes two status layers:
88
88
  - A plain `setStatus` string without provider names or icons, such as `5h 99% ↻2h13m · 1w 85% ↻3d4h · 1m 60%`. `↻` marks the countdown to each window's reset, shown only when the provider reports a future reset time. The footer refreshes every 5 minutes and after each agent turn, so the countdown can lag by up to about 5 minutes.
89
89
  - Structured window data through the `subscription-usage/status/v1` event.
90
90
 
91
- Windows are always ordered as `5h / 1w / 1m / other`. Other extensions can consume the structured event to provide their own icons, colors, and layout without parsing display text. Ready events include `displayMode`; each window includes `displayPercent`, `remainingPercent`, and `usedPercent`. Consumers should render `displayPercent` while using the explicit remaining/used fields for semantic decisions such as colors or alerts.
91
+ Windows are always ordered as `5h / 1w / 1m / other`. Other extensions can consume the structured event to provide their own icons, colors, and layout without parsing display text. Ready events include `displayMode`; each window includes `displayPercent`, `remainingPercent`, and `usedPercent`. Consumers should render `displayPercent` while using the explicit remaining/used fields for semantic decisions such as colors or alerts. When the provider reports a future reset time, a window also carries `resetCountdown` (for example `2h13m`), computed at publish time with the same format and refresh cadence as the footer text; consumers can show it as-is instead of formatting `resetsAt` themselves.
92
92
 
93
93
  ## Security boundaries
94
94
 
package/README.zh-CN.md CHANGED
@@ -88,7 +88,7 @@ Codex 结果会按以下额度域分组:
88
88
  - 不含提供商名称或图标的普通 `setStatus` 文本,例如 `5h 99% ↻2h13m · 1w 85% ↻3d4h · 1m 60%`。`↻` 后是距离该窗口重置的倒计时,仅在提供商返回未来的重置时间时显示。底部状态每 5 分钟及每轮 agent 结束后刷新,因此倒计时最多可能滞后约 5 分钟。
89
89
  - 通过 `subscription-usage/status/v1` 事件发布的结构化窗口数据。
90
90
 
91
- 窗口始终按 `5h / 1w / 1m / other` 排序。其他扩展可以直接消费结构化事件,自定义图标、颜色和布局,而不必解析显示文本。就绪事件包含 `displayMode`,每个窗口包含 `displayPercent`、`remainingPercent` 和 `usedPercent`;消费者应展示 `displayPercent`,并在颜色或告警等语义判断中使用明确的剩余/已用字段。
91
+ 窗口始终按 `5h / 1w / 1m / other` 排序。其他扩展可以直接消费结构化事件,自定义图标、颜色和布局,而不必解析显示文本。就绪事件包含 `displayMode`,每个窗口包含 `displayPercent`、`remainingPercent` 和 `usedPercent`;消费者应展示 `displayPercent`,并在颜色或告警等语义判断中使用明确的剩余/已用字段。提供商返回未来的重置时间时,窗口还包含 `resetCountdown`(例如 `2h13m`),在发布事件时计算,格式和刷新频率与底部状态文本一致;消费者可直接展示,无需自行根据 `resetsAt` 格式化。
92
92
 
93
93
  ## 安全边界
94
94
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@specode/pi-subscription-usage",
3
- "version": "1.1.0",
3
+ "version": "1.1.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/status.ts CHANGED
@@ -27,6 +27,8 @@ export interface UsageStatusWindow {
27
27
  displayPercent: number;
28
28
  windowMinutes?: number;
29
29
  resetsAt?: number;
30
+ /** Countdown to `resetsAt` at publish time, such as `2h13m`; absent once the reset has passed. */
31
+ resetCountdown?: string;
30
32
  }
31
33
 
32
34
  export type UsageStatusEvent =
@@ -51,6 +53,7 @@ export function buildUsageStatusEvent(
51
53
  report: UsageReport,
52
54
  model?: UsageModel,
53
55
  displayMode: UsageDisplayMode = DEFAULT_USAGE_DISPLAY_MODE,
56
+ nowMs: number = Date.now(),
54
57
  ): UsageStatusEvent {
55
58
  const buckets = bucketsForModel(report, model);
56
59
  const windows = sortUsageBuckets(buckets).flatMap((bucket) => {
@@ -64,6 +67,10 @@ export function buildUsageStatusEvent(
64
67
  ) {
65
68
  return [];
66
69
  }
70
+ const resetCountdown =
71
+ bucket.resetsAt === undefined
72
+ ? undefined
73
+ : formatResetCountdown(bucket.resetsAt * 1_000 - nowMs);
67
74
  return [
68
75
  {
69
76
  kind: usageWindowKind(bucket),
@@ -75,6 +82,7 @@ export function buildUsageStatusEvent(
75
82
  ? {}
76
83
  : { windowMinutes: bucket.windowMinutes }),
77
84
  ...(bucket.resetsAt === undefined ? {} : { resetsAt: bucket.resetsAt }),
85
+ ...(resetCountdown === undefined ? {} : { resetCountdown }),
78
86
  } satisfies UsageStatusWindow,
79
87
  ];
80
88
  });
@@ -95,16 +103,14 @@ export function formatUsageStatusline(
95
103
  displayMode: UsageDisplayMode = DEFAULT_USAGE_DISPLAY_MODE,
96
104
  nowMs: number = Date.now(),
97
105
  ): string | undefined {
98
- const event = buildUsageStatusEvent(report, model, displayMode);
106
+ const event = buildUsageStatusEvent(report, model, displayMode, nowMs);
99
107
  if (event.status !== "ready" || event.windows.length === 0) return undefined;
100
108
  return event.windows
101
109
  .map((window) => {
102
- const countdown =
103
- window.resetsAt === undefined
104
- ? undefined
105
- : formatResetCountdown(window.resetsAt * 1_000 - nowMs);
106
110
  const percent = `${window.label} ${formatUsagePercent(window.displayPercent)}%`;
107
- return countdown ? `${percent} ↻${countdown}` : percent;
111
+ return window.resetCountdown
112
+ ? `${percent} ↻${window.resetCountdown}`
113
+ : percent;
108
114
  })
109
115
  .join(" · ");
110
116
  }
package/src/usage.ts CHANGED
@@ -153,10 +153,16 @@ export default function subscriptionUsage(pi: ExtensionAPI): void {
153
153
  }
154
154
  return;
155
155
  }
156
+ const nowMs = Date.now();
156
157
  emitUsageStatus(
157
- buildUsageStatusEvent(outcome.state.report, model, displayMode),
158
+ buildUsageStatusEvent(outcome.state.report, model, displayMode, nowMs),
159
+ );
160
+ const value = formatUsageStatusline(
161
+ outcome.state.report,
162
+ model,
163
+ displayMode,
164
+ nowMs,
158
165
  );
159
- const value = formatUsageStatusline(outcome.state.report, model, displayMode);
160
166
  if (!safeSetStatus(ctx, value)) return;
161
167
  if (schedule && sessionActive) scheduleStatusRefresh(ctx, model);
162
168
  }