ccus-cli 0.1.25 → 0.1.26

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.
@@ -161,9 +161,11 @@ function renderHeader(value, token) {
161
161
  /**
162
162
  * 智谱 GLM Coding Plan 的内置 extractor 脚本(zhipu provider 的预设)。
163
163
  *
164
- * data.limits 里筛 type==="TOKENS_LIMIT",按 nextResetTime 升序,第 1 条 = 5h、第 2 = 每周。
165
- * 智谱在 5h 桶利用率=0% 时会省略该条的 nextResetTime,缺字段兜底 -Infinity 排最前(归 5h 桶),
166
- * 否则会被当 weekly、和 weekly 槽位互换(对照 cc-switch v3.16.0 的同类修复)。
164
+ * data.limits 里筛 type==="TOKENS_LIMIT",用 number 字段识别桶位:5h number===5、周桶 number===1。
165
+ * 不能用 nextResetTime 大小排序区分——5h 与周窗口的重置时刻互不相关,实测周桶 nextResetTime 可早于 5h
166
+ * 升序会把周桶当 5h、5h 当周桶,5h/7d 互换(曾因「缺 nextResetTime 5h」启发式反复互换)。
167
+ * 5h 桶 = number===5 的那条,周桶 = 余下第一条;number 缺失(老接口)才退回 nextResetTime 稳定排序
168
+ * (有值优先、缺值按原序,不强制归前/后)。对照 deluo/glm-quota-line 的同类实现。
167
169
  * success !== true / code !== 200 / 缺 data.limits 时返回会让归一化判 null 的值。
168
170
  * zhipu 不再单独维护提取函数,与 custom 走同一条 `runExtractor` 路径,只是 extractor 用这组内置脚本。
169
171
  */
@@ -177,13 +179,33 @@ exports.ZHIPU_EXTRACTOR = `function(response) {
177
179
  if (!Array.isArray(limits)) return null;
178
180
  const tokenLimits = limits
179
181
  .filter((l) => l && l.type === "TOKENS_LIMIT")
180
- .map((l) => ({ p: l.percentage, r: l.nextResetTime }))
181
- // nextResetTime 的那条兜底 -Infinity 排最前(= 5h 桶):智谱在 5h=0% 时会省略该字段,
182
- // 若兜底 Infinity 排最后会被当成 weekly,造成 5h/7d 槽位互换(见上方 JSDoc)。
183
- .sort((a, b) => (typeof a.r === "number" ? a.r : -Infinity) - (typeof b.r === "number" ? b.r : -Infinity));
182
+ .map((l, i) => ({ p: l.percentage, n: l.number, r: l.nextResetTime, i }));
183
+ if (tokenLimits.length === 0) return null;
184
+ // 5h number===5、周桶 number===1。nextResetTime 大小不可靠(周桶重置可早于 5h),
185
+ // 必须用 number 显式识别 5h,否则两槽位互换。
186
+ const fiveHour = tokenLimits.find((l) => l.n === 5);
187
+ let first, second;
188
+ if (fiveHour) {
189
+ first = fiveHour;
190
+ second = tokenLimits.find((l) => l !== fiveHour);
191
+ } else if (tokenLimits.length === 1) {
192
+ first = tokenLimits[0];
193
+ } else {
194
+ // 老接口无 number:退回 nextResetTime 稳定排序(有值优先,缺值按原序,不强制归前/后)。
195
+ tokenLimits.sort((a, b) => {
196
+ const ar = typeof a.r === "number";
197
+ const br = typeof b.r === "number";
198
+ if (ar && br && a.r !== b.r) return a.r - b.r;
199
+ if (ar && !br) return -1;
200
+ if (!ar && br) return 1;
201
+ return a.i - b.i;
202
+ });
203
+ first = tokenLimits[0];
204
+ second = tokenLimits[1];
205
+ }
184
206
  return {
185
- fiveHour: tokenLimits[0] ? tokenLimits[0].p : null,
186
- sevenDay: tokenLimits[1] ? tokenLimits[1].p : null,
207
+ fiveHour: first ? first.p : null,
208
+ sevenDay: second ? second.p : null,
187
209
  level: typeof data.level === "string" && data.level !== "" ? data.level : null,
188
210
  };
189
211
  }`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccus-cli",
3
- "version": "0.1.25",
3
+ "version": "0.1.26",
4
4
  "description": "Claude Code statusline usage logger and dashboard CLI",
5
5
  "type": "commonjs",
6
6
  "bin": {