
















@@ -2,6 +2,7 @@ import { isJsonObject, type JsonObject, type JsonValue } from "./protocol.js";
2233const CODEX_LIMIT_ID = "codex";
44const LIMIT_WINDOW_KEYS = ["primary", "secondary"] as const;
5+const ONE_SECOND_MS = 1000;
56const ONE_MINUTE_MS = 60_000;
67const ONE_HOUR_MS = 60 * ONE_MINUTE_MS;
78const ONE_DAY_MS = 24 * ONE_HOUR_MS;
@@ -200,7 +201,7 @@ function summarizeRateLimitSnapshot(snapshot: JsonObject, nowMs: number): string
200201const reachedType =
201202readString(snapshot, "rateLimitReachedType") ?? readString(snapshot, "rate_limit_reached_type");
202203const suffix = reachedType ? ` (${formatReachedType(reachedType)})` : "";
203-return `${label}: ${windows.join(", ") || "available"}${suffix}`;
204+return `${label}: ${windows.join(" · ") || "available"}${suffix}`;
204205}
205206206207function collectCodexRateLimitSnapshots(value: JsonValue | undefined): JsonObject[] {
@@ -331,11 +332,13 @@ function formatRateLimitWindow(key: LimitWindowKey, window: RateLimitReset, nowM
331332}
332333333334function formatRateLimitWindowDetails(window: RateLimitReset, nowMs: number): string {
334-const usedPercent =
335-window.usedPercent === undefined ? "usage unknown" : `${Math.round(window.usedPercent)}%`;
335+const remainingPercent =
336+window.usedPercent === undefined
337+ ? "usage unknown"
338+ : `${Math.max(0, 100 - Math.round(window.usedPercent))}% left`;
336339const reset =
337-window.resetsAtMs > nowMs ? `, resets ${formatResetTime(window.resetsAtMs, nowMs)}` : "";
338-return `${usedPercent}${reset}`;
340+window.resetsAtMs > nowMs ? ` ⏱${formatResetDuration(window.resetsAtMs, nowMs)}` : "";
341+return `${remainingPercent}${reset}`;
339342}
340343341344function formatLimitLabel(snapshot: JsonObject): string {
@@ -495,6 +498,25 @@ function formatRelativeDuration(durationMs: number): string {
495498return `${days} ${days === 1 ? "day" : "days"}`;
496499}
497500501+function formatResetDuration(resetsAtMs: number, nowMs: number): string {
502+const safeMs = Math.max(ONE_SECOND_MS, resetsAtMs - nowMs);
503+const totalSeconds = Math.round(safeMs / ONE_SECOND_MS);
504+const days = Math.floor(totalSeconds / 86_400);
505+const hours = Math.floor((totalSeconds % 86_400) / 3600);
506+const minutes = Math.floor((totalSeconds % 3600) / 60);
507+const seconds = totalSeconds % 60;
508+if (days > 0) {
509+return hours > 0 ? `${days}d ${hours}h` : `${days}d`;
510+}
511+if (hours > 0) {
512+return minutes > 0 ? `${hours}h ${minutes}m` : `${hours}h`;
513+}
514+if (minutes > 0) {
515+return seconds > 0 ? `${minutes}m ${seconds}s` : `${minutes}m`;
516+}
517+return `${seconds}s`;
518+}
519+498520function formatWindowSignature(value: JsonValue | undefined): string {
499521if (!isJsonObject(value)) {
500522return "";
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。