dsh-opencode-status 0.4.1 → 0.4.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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.2
4
+
5
+ - **估算时长按两位有效数字粗化**:`<1h` 取 5 分钟、`1–10h` 取 30 分钟、`≥10h` 取 1 小时、`≥48h` 取 1 天(下限 5 分钟,不会出现「约 0m」)。上游只给整数 percent,量化误差会让 ETA 的真实区间比点值宽 2–3 倍,分钟级精度属于虚假精确;现在 `约 13h10m 后耗尽` 显示为 `约 13h 后耗尽`,`约 1h54m` 显示为 `约 2h`。
6
+ - 修复 220ms 悬停定时器在组件卸载时未清理的问题(原先可能在卸载后对已卸载组件 `setState`)。
7
+ - 修复底部操作条「刷新」按钮缺少 React `key` 导致的开发期警告。
8
+ - 测试 47 → 48:新增 ETA 粗化的四档边界用例与最小 5 分钟下限断言。
9
+
3
10
  ## 0.4.1
4
11
 
5
12
  - 新增**按当前消耗速率的可用时长估算**:用量面板的窗口行在「剩余 %」与「⏱ 重置倒计时」之间给出「按现在的用法还能撑多久」。估算用最近的实测采样外推(只用首尾两点,不做回归),三种状态严格区分:
package/README.md CHANGED
@@ -10,15 +10,16 @@ OpenCode GO 套餐用量与配额状态监控面板插件(DeepSeek Harness)
10
10
  - `⚙ 设置`:进入面板内的独立连接设置视图,可随时 `← 返回用量`。
11
11
  - 右侧显示相对时间「上次同步 12s 前」(刚刚 / Ns 前 / N 分钟前 / N 小时前 / N 天前),绝对时刻 HH:MM:SS 保留在 `title`;同步数据超过 2 分钟追加「· 可能已过期」并用警告色,避免把旧额度当成实时值。
12
12
  - **3 维度用量行**:主百分比只给剩余额度,进度条条长与它同源(条长 = 剩余占比,条色 = 剩余档位),「已用」放在 `title` 与 `aria-valuetext` 里,同一行不再重复表达同一个数字;窗口状态非 `ok` 时给出可见提示。
13
- - **滚动窗口 (5h)**:`剩余 70% · 约 13h10m 后耗尽 · ⏱ 4h20m`
13
+ - **滚动窗口 (5h)**:`剩余 70% · 约 13h 后耗尽 · ⏱ 4h20m`
14
14
  - **周窗口 (Weekly)**:周额度剩余 % + 可用时长估算 + ⏱ 重置倒计时
15
15
  - **月窗口 (Monthly)**:月额度剩余 % + 可用时长估算 + ⏱ 重置倒计时
16
16
  - 面板头部只给判断性摘要「最紧张 <窗口> N%」(取剩余最小的窗口),具体数字留在窗口行。
17
17
  - **可用时长估算(按当前速率,仅供参考)**:窗口行会顺带告诉你「按现在的用法还能撑多久」。三种状态严格区分,不存在第四种:
18
- - `约 13h10m 后耗尽`(警告色):按当前速率会在窗口重置前用完;
18
+ - `约 13h 后耗尽`(警告色):按当前速率会在窗口重置前用完;
19
19
  - `可支撑到重置`(中性色):按当前速率能撑到重置,此时不再显示具体时长;
20
20
  - **不显示**:采样点少于 3 个、首尾跨度不足 10 分钟、速率为 0、剩余为 0,或重置时间缺失/已过期时,这个位置直接不出现,也不会用「估算中」「--」占位。
21
21
  - 鼠标悬停会说明依据:「按最近 N 分钟的消耗速率估算(按当前速率),仅供参考」。它是对已有采样点的机械外推(只用首尾两点,不做回归),**不是预测或承诺**。
22
+ - 时长按两位有效数字粗化:<1h 取 5 分钟、1–10h 取 30 分钟、≥10h 取 1 小时、≥48h 取 1 天。上游只有整数百分比,分钟级精度属于虚假精确,粗化后不再暗示比实际更准。
22
23
  - 采样只存在于页面打开期间的内存里(每窗口最近 60 分钟、最多 120 个点),刷新页面即清空,需要重新积累约 10 分钟才可能再次出现;上游只给整数百分比,样本不足时宁可不出数,也不给看起来精确的假时长。
23
24
  - 纯前端计算:不新增网络请求、不新增依赖,数据仍只来自既有的 30 秒轮询与手动刷新。220ms 悬浮微卡不显示估算(一行放不下五项,缩字号或截断都不可接受,因此有意省略)。
24
25
  - **可访问性与键盘交互**:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-opencode-status",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "OpenCode GO quota status panel for DeepSeek Harness: click to open a usage panel with manual refresh, per-window remaining quota, a hover overview card, and in-app connection settings",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
package/src/client.js CHANGED
@@ -244,6 +244,20 @@ window.__ModuleLoader__.load({
244
244
  return `${days}d${hours % 24 ? `${hours % 24}h` : ''}`
245
245
  }
246
246
 
247
+ /**
248
+ * 估算值粗化:上游只给整数 percent,量化误差会让 ETA 的真实区间比点值宽 2-3 倍,
249
+ * 分钟级精度属于虚假精确。按「两位有效数字」粗化,既保留量级又不再暗示精度:
250
+ * <1h 取 5 分钟、1-10h 取 30 分钟、≥10h 取 1 小时、≥48h 取 1 天。
251
+ */
252
+ function coarsenEta(ms) {
253
+ const minutes = ms / 60_000
254
+ if (minutes < 60) return Math.max(5, Math.round(minutes / 5) * 5) * 60_000
255
+ if (minutes < 600) return Math.round(minutes / 30) * 30 * 60_000
256
+ const hours = minutes / 60
257
+ if (hours < 48) return Math.round(hours) * 3_600_000
258
+ return Math.round(hours / 24) * 86_400_000
259
+ }
260
+
247
261
  /**
248
262
  * 估算文案的三态:不可估算返回 null(调用方完全不渲染节点,不显示 "--"/"估算中" 之类占位);
249
263
  * 撑不到重置用告警色「约 X 后耗尽」,撑得到用中性色「可支撑到重置」。
@@ -265,7 +279,7 @@ window.__ModuleLoader__.load({
265
279
  const title = `按最近 ${minutes} 分钟的消耗速率估算(按当前速率),仅供参考`
266
280
  // 保留完整字面「约 X 后耗尽」:真实 Chrome 实测在 326px/262px 内容宽下都不会截断,只会让标签多收缩。
267
281
  return estimate.exhaustsBeforeReset
268
- ? { text: `约 ${fmtEtaDuration(estimate.etaMs)} 后耗尽`, color: T.warn, title }
282
+ ? { text: `约 ${fmtEtaDuration(coarsenEta(estimate.etaMs))} 后耗尽`, color: T.warn, title }
269
283
  : { text: '可支撑到重置', color: T.secondary, title }
270
284
  }
271
285
 
@@ -434,6 +448,9 @@ window.__ModuleLoader__.load({
434
448
  }
435
449
  }, [])
436
450
 
451
+ // 卸载时清掉待触发的悬停定时器,避免 220ms 后对已卸载组件 setState。
452
+ useEffect(() => () => clearTimeout(hoverTimerRef.current), [])
453
+
437
454
  const onMouseEnter = () => {
438
455
  clearTimeout(hoverTimerRef.current)
439
456
  hoverTimerRef.current = setTimeout(() => setHovering(true), 220)
@@ -935,6 +952,7 @@ window.__ModuleLoader__.load({
935
952
  h(
936
953
  'button',
937
954
  {
955
+ key: 'refresh',
938
956
  className: 'oc-btn',
939
957
  style: btnBase,
940
958
  disabled: state.refreshing,
@@ -1126,7 +1144,7 @@ window.__ModuleLoader__.load({
1126
1144
  exports.apply = apply
1127
1145
  exports.inject = ['slots']
1128
1146
  // 仅供测试与诊断:估算/采样是纯函数 + 模块内状态,导出以便做真实单元测试(宿主侧不消费)。
1129
- exports.__internal = { estimateEta, recordSamples, getSamples, resetEtaSamples, fmtEtaDuration, etaView }
1147
+ exports.__internal = { estimateEta, recordSamples, getSamples, resetEtaSamples, fmtEtaDuration, coarsenEta, etaView }
1130
1148
  return module.exports
1131
1149
  },
1132
1150
  })