@specode/pi-subscription-usage 1.0.2 → 1.1.0
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 +1 -1
- package/README.zh-CN.md +1 -1
- package/package.json +1 -1
- package/src/status.ts +22 -3
package/README.md
CHANGED
|
@@ -85,7 +85,7 @@ Before redeeming a Codex reset credit, the extension:
|
|
|
85
85
|
|
|
86
86
|
The extension publishes two status layers:
|
|
87
87
|
|
|
88
|
-
- A plain `setStatus` string without provider names or icons, such as `5h 99% · 1w 85% · 1m 60%`.
|
|
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
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.
|
package/README.zh-CN.md
CHANGED
|
@@ -85,7 +85,7 @@ Codex 结果会按以下额度域分组:
|
|
|
85
85
|
|
|
86
86
|
本扩展提供两层状态输出:
|
|
87
87
|
|
|
88
|
-
- 不含提供商名称或图标的普通 `setStatus` 文本,例如 `5h 99% · 1w 85% · 1m 60
|
|
88
|
+
- 不含提供商名称或图标的普通 `setStatus` 文本,例如 `5h 99% ↻2h13m · 1w 85% ↻3d4h · 1m 60%`。`↻` 后是距离该窗口重置的倒计时,仅在提供商返回未来的重置时间时显示。底部状态每 5 分钟及每轮 agent 结束后刷新,因此倒计时最多可能滞后约 5 分钟。
|
|
89
89
|
- 通过 `subscription-usage/status/v1` 事件发布的结构化窗口数据。
|
|
90
90
|
|
|
91
91
|
窗口始终按 `5h / 1w / 1m / other` 排序。其他扩展可以直接消费结构化事件,自定义图标、颜色和布局,而不必解析显示文本。就绪事件包含 `displayMode`,每个窗口包含 `displayPercent`、`remainingPercent` 和 `usedPercent`;消费者应展示 `displayPercent`,并在颜色或告警等语义判断中使用明确的剩余/已用字段。
|
package/package.json
CHANGED
package/src/status.ts
CHANGED
|
@@ -93,16 +93,35 @@ export function formatUsageStatusline(
|
|
|
93
93
|
report: UsageReport,
|
|
94
94
|
model?: UsageModel,
|
|
95
95
|
displayMode: UsageDisplayMode = DEFAULT_USAGE_DISPLAY_MODE,
|
|
96
|
+
nowMs: number = Date.now(),
|
|
96
97
|
): string | undefined {
|
|
97
98
|
const event = buildUsageStatusEvent(report, model, displayMode);
|
|
98
99
|
if (event.status !== "ready" || event.windows.length === 0) return undefined;
|
|
99
100
|
return event.windows
|
|
100
|
-
.map(
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
.map((window) => {
|
|
102
|
+
const countdown =
|
|
103
|
+
window.resetsAt === undefined
|
|
104
|
+
? undefined
|
|
105
|
+
: formatResetCountdown(window.resetsAt * 1_000 - nowMs);
|
|
106
|
+
const percent = `${window.label} ${formatUsagePercent(window.displayPercent)}%`;
|
|
107
|
+
return countdown ? `${percent} ↻${countdown}` : percent;
|
|
108
|
+
})
|
|
103
109
|
.join(" · ");
|
|
104
110
|
}
|
|
105
111
|
|
|
112
|
+
/** Compact two-unit countdown such as `3d4h`, `2h13m`, or `<1m`; past resets yield nothing. */
|
|
113
|
+
export function formatResetCountdown(remainingMs: number): string | undefined {
|
|
114
|
+
if (!Number.isFinite(remainingMs) || remainingMs <= 0) return undefined;
|
|
115
|
+
const totalMinutes = Math.floor(remainingMs / 60_000);
|
|
116
|
+
if (totalMinutes < 1) return "<1m";
|
|
117
|
+
const days = Math.floor(totalMinutes / 1_440);
|
|
118
|
+
const hours = Math.floor((totalMinutes % 1_440) / 60);
|
|
119
|
+
const minutes = totalMinutes % 60;
|
|
120
|
+
if (days > 0) return hours > 0 ? `${days}d${hours}h` : `${days}d`;
|
|
121
|
+
if (hours > 0) return minutes > 0 ? `${hours}h${minutes}m` : `${hours}h`;
|
|
122
|
+
return `${minutes}m`;
|
|
123
|
+
}
|
|
124
|
+
|
|
106
125
|
export function usageWindowLabel(bucket: UsageBucket): string {
|
|
107
126
|
const kind = usageWindowKind(bucket);
|
|
108
127
|
if (kind === "weekly") return "1w Window";
|