meowapi-statusline 1.0.1 → 1.0.3

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,10 @@ 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` 是个会随刷新递减的真实时刻。只有当它落在「窗口长度 + 5 分钟」之内
92
+ 才会画 `↻`:超出这个范围的数字不是倒计时,而是把窗口长度原样回显(网关在每次
93
+ 请求时重新锚定窗口就会这样),那种值不显示。
91
94
  - 可选字段 `seven_day_opus` / `seven_day_sonnet` 存在时额外画独立条。
92
95
 
93
96
  ## 开发
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,25 @@ export function normalizeUsage(data) {
99
103
  return periods
100
104
  }
101
105
 
106
+ // Clock skew between this machine and the gateway is normally sub-second, but a
107
+ // reset read moments after a window opened can still land a hair past "one
108
+ // window from now" on the client's clock. A little slack keeps that real
109
+ // countdown visible. What still gets rejected is a reset far beyond one window,
110
+ // which is not a boundary at all — the window length echoed back on every
111
+ // refresh, the shape this guard was written for.
112
+ export const RESET_SKEW_SECONDS = 120
113
+
114
+ export function isPlausibleReset(resetsAt, nowSeconds, windowSeconds) {
115
+ const remaining = resetsAt - nowSeconds
116
+ return remaining > 0 && remaining <= windowSeconds + RESET_SKEW_SECONDS
117
+ }
118
+
102
119
  export function renderLine(data, nowSeconds = Date.now() / 1000) {
103
120
  const segments = []
104
121
  for (const period of normalizeUsage(data)) {
105
122
  const percent = Math.round(period.utilization)
106
123
  let segment = colorize(period.utilization, `${period.label} ${bar(period.utilization)} ${percent}%`)
107
- if (period.resetsAt > 0) {
124
+ if (period.resetsAt > 0 && isPlausibleReset(period.resetsAt, nowSeconds, period.windowSeconds)) {
108
125
  segment += ` ${DIM}↻${human(period.resetsAt - nowSeconds)}${RESET}`
109
126
  }
110
127
  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.3",
4
4
  "description": "Claude Code status line: show subscription quota bars on API-key / gateway sessions",
5
5
  "keywords": [
6
6
  "claude-code",