meowapi-statusline 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/README.md CHANGED
@@ -87,7 +87,9 @@ base URL 末尾带不带 `/api` 都能识别:
87
87
 
88
88
  - `utilization` 是 0–100 百分比。为了兼容按 Anthropic 原始口径返回 0–1 小数的代理,
89
89
  值 ≤ 1 且 > 0 时按小数处理。
90
- - `resets_at` 是 unix 秒。
90
+ - `resets_at` 是 unix 秒。只有当它落在窗口长度**之内**时才会显示倒计时:滚动窗口的
91
+ 网关每次请求都会把锚点往后推,于是 `resets_at` 恒等于「现在 + 一整个窗口」,
92
+ 那个数字永远不会减小。这种值会被判定为窗口长度而非重置时刻,直接不显示转换。
91
93
  - 可选字段 `seven_day_opus` / `seven_day_sonnet` 存在时额外画独立条。
92
94
 
93
95
  ## 开发
package/lib/statusline.js CHANGED
@@ -77,13 +77,16 @@ export function human(seconds) {
77
77
  // The gateway reports utilization as a 0-100 percentage; Claude Code's own
78
78
  // headers use a 0-1 fraction. normalizeUsage accepts either so the same package
79
79
  // also works against a proxy that mirrors Anthropic's JSON literally.
80
+ //
81
+ // windowSeconds is the length of the window each period covers; it bounds what
82
+ // a believable resets_at can be (see isPlausibleReset).
80
83
  export function normalizeUsage(data) {
81
84
  const periods = []
82
- for (const [key, label] of [
83
- ['five_hour', '5h'],
84
- ['seven_day', '7d'],
85
- ['seven_day_opus', '7d-opus'],
86
- ['seven_day_sonnet', '7d-sonnet'],
85
+ for (const [key, label, windowSeconds] of [
86
+ ['five_hour', '5h', 5 * 3600],
87
+ ['seven_day', '7d', 7 * 86400],
88
+ ['seven_day_opus', '7d-opus', 7 * 86400],
89
+ ['seven_day_sonnet', '7d-sonnet', 7 * 86400],
87
90
  ]) {
88
91
  const period = data?.[key]
89
92
  if (!period || typeof period !== 'object') continue
@@ -92,6 +95,7 @@ export function normalizeUsage(data) {
92
95
  const utilization = raw <= 1 && raw > 0 ? raw * 100 : raw
93
96
  periods.push({
94
97
  label,
98
+ windowSeconds,
95
99
  utilization: Math.min(100, Math.max(0, utilization)),
96
100
  resetsAt: Number(period.resets_at) || 0,
97
101
  })
@@ -99,12 +103,21 @@ export function normalizeUsage(data) {
99
103
  return periods
100
104
  }
101
105
 
106
+ // A gateway that derives resets_at from a rolling window anchor reports
107
+ // "one full window from now" on every request, because each charge restarts the
108
+ // anchor. That countdown never moves, so a reset that is a whole window (or
109
+ // more) away is the window length echoed back at us, not a reset time.
110
+ export function isPlausibleReset(resetsAt, nowSeconds, windowSeconds) {
111
+ const remaining = resetsAt - nowSeconds
112
+ return remaining > 0 && remaining < windowSeconds
113
+ }
114
+
102
115
  export function renderLine(data, nowSeconds = Date.now() / 1000) {
103
116
  const segments = []
104
117
  for (const period of normalizeUsage(data)) {
105
118
  const percent = Math.round(period.utilization)
106
119
  let segment = colorize(period.utilization, `${period.label} ${bar(period.utilization)} ${percent}%`)
107
- if (period.resetsAt > 0) {
120
+ if (period.resetsAt > 0 && isPlausibleReset(period.resetsAt, nowSeconds, period.windowSeconds)) {
108
121
  segment += ` ${DIM}↻${human(period.resetsAt - nowSeconds)}${RESET}`
109
122
  }
110
123
  segments.push(segment)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "meowapi-statusline",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Claude Code status line: show subscription quota bars on API-key / gateway sessions",
5
5
  "keywords": [
6
6
  "claude-code",