dsh-session-superagent 0.9.20 → 0.9.21

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
@@ -2,6 +2,30 @@
2
2
 
3
3
  格式参照 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),版本号遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
4
4
 
5
+ ## [0.9.21] - 2026-11-02 —— 用原因码替代"匹配提示文案"
6
+
7
+ ### 学到的(知识库第 70 条)
8
+ 把展示层当数据层是反模式。OTel 的 log record 带结构化 attributes,文案只负责给人看。
9
+ 一旦拿文案当判据,任何一次文案优化都会**静默改变统计数据**。
10
+
11
+ ### 修的是什么
12
+ 0.9.20 统计"几条守被上限挡住"用的是 `lastDeferred.includes('上限')`:
13
+ - 文案一改统计归零;
14
+ - "额度紧张(剩余 …)"这类含"上限"但不是频率上限的提示会被误算。
15
+
16
+ ### 改法
17
+ 服务端在各暂停分支写 `entry.deferReason`(`active-hours` / `ratelimit` / `quota` /
18
+ `unchanged` / `observe` / `cap-session` / `cap-watcher` / `busy`),
19
+ 统计改用 `countCapped()` 只认两种 cap 码;`/state` 也回传 `deferReason`。
20
+
21
+ ### 用例锁住的误判
22
+ ```js
23
+ countCapped([{ lastDeferred: '每小时最多唤醒 6 次' }]) === 0 // 文案有"上限"也不算
24
+ ```
25
+
26
+ ### 测试
27
+ - 新增 2 例(计数语义 + `/state` 契约)。合计 **166 例**。
28
+
5
29
  ## [0.9.20] - 2026-11-02 —— 面板显示"还能用几次"(会话唤醒用量)
6
30
 
7
31
  ### 学到的(知识库第 69 条)
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  <img src="assets/icon-180.png" width="88" height="88" alt="">
4
4
 
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
- [![Version](https://img.shields.io/badge/version-0.9.20-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.9.21-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
7
7
  [![npm](https://img.shields.io/npm/v/dsh-session-superagent.svg)](https://www.npmjs.com/package/dsh-session-superagent)
8
8
  [![dsh](https://img.shields.io/badge/DeepSeek%20Harness-plugin-orange.svg)](https://github.com/topics/dsh-plugin)
9
9
 
package/client.js CHANGED
@@ -14,7 +14,7 @@ window.__ModuleLoader__.load({
14
14
  const { useCallback, useEffect, useRef, useState } = React
15
15
 
16
16
  // 客户端版本探针:每次模块加载写一次,用来确认浏览器里跑的是哪一版
17
- const CLIENT_VERSION = '0.9.20'
17
+ const CLIENT_VERSION = '0.9.21'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
package/lib/index.js CHANGED
@@ -27,12 +27,13 @@ import {
27
27
  advanceSeen, applyWatcherAction, batchFresh, decideWake, DEFAULT_ACK_LABEL, formatWatchText,
28
28
  TRIAGE_SIGNALS, accessNote, buildCommentBatchQuery, classifyGhError, commentSummaryLine, parseCommentBatch, pickSuggestion, repoStructureNote, countReasons, filterReason, hasAckLabel, jitterMs, parseGhInclude, retryAfterMs, throttleDelayMs, inActiveHours, newestUpdatedAt, nextDelayMs, pushFiltered, normalizeFilters, partitionItems, passesFilters,
29
29
  shouldRunCleanup,
30
+ countCapped,
30
31
  mergeFilters, mergePollResult, mergeWakeTexts, pushEvent, silentStreak, msUntilActiveWindow, nextWaketimeAt, pruneSeen, sessionWakesLastHour, pruneWakeTimes, pushHistory, recordReported, staleWorktrees, worktreePlan,
31
32
  } from './watch.js'
32
33
 
33
34
  export const name = 'dsh-session-superagent'
34
35
  /** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
35
- export const SERVER_VERSION = '0.9.20'
36
+ export const SERVER_VERSION = '0.9.21'
36
37
  export const inject = ['tools', 'agents', 'webServer']
37
38
  /** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
38
39
  const DEFAULT_SESSION_WAKES = 12
@@ -800,6 +801,7 @@ async function pollOnce(ctx, entry, baseMs) {
800
801
  const wait = msUntilActiveWindow(entry.activeHours)
801
802
  entry.nextAt = new Date(Date.now() + wait).toISOString()
802
803
  entry.lastDeferred = `不在活跃时段(${entry.activeHours}),${Math.round(wait / 60000)} 分钟后开始`
804
+ entry.deferReason = 'active-hours'
803
805
  noteEvent(entry, 'defer', entry.lastDeferred)
804
806
  return
805
807
  }
@@ -815,6 +817,7 @@ async function pollOnce(ctx, entry, baseMs) {
815
817
  if (wait > 0) {
816
818
  entry.nextAt = new Date(Date.now() + wait).toISOString()
817
819
  entry.lastDeferred = '被 GitHub 限流,按 Retry-After 等 ' + Math.round(wait / 1000) + ' 秒'
820
+ entry.deferReason = 'ratelimit'
818
821
  noteEvent(entry, 'ratelimit', entry.lastDeferred)
819
822
  entry.lastError = null
820
823
  return
@@ -832,6 +835,7 @@ async function pollOnce(ctx, entry, baseMs) {
832
835
  if (throttle > 0) {
833
836
  entry.nextAt = new Date(Date.now() + throttle).toISOString()
834
837
  entry.lastDeferred = '额度紧张(剩余 ' + parsed.remaining + '),已推迟到 '
838
+ entry.deferReason = 'quota'
835
839
  + new Date(Date.now() + throttle).toISOString().slice(11, 16) + 'Z'
836
840
  entry.lastError = null
837
841
  return
@@ -842,6 +846,7 @@ async function pollOnce(ctx, entry, baseMs) {
842
846
  entry.consecutiveFailures = 0
843
847
  entry.nextAt = null
844
848
  entry.lastDeferred = '未变化(304,不计入速率限制)'
849
+ entry.deferReason = 'unchanged'
845
850
  noteEvent(entry, 'unchanged', entry.lastDeferred)
846
851
  return
847
852
  }
@@ -894,6 +899,7 @@ async function pollOnce(ctx, entry, baseMs) {
894
899
  // 仅观察模式(对标官方 observe):照常判定,但只记录「本会唤醒哪几条」,不真唤醒
895
900
  if (entry.observe === true) {
896
901
  entry.lastDeferred = '仅观察:本轮本会唤醒 ' + fresh.length + ' 条(' + fresh.slice(0, 5).map((i) => '#' + i.number).join(' ') + ')'
902
+ entry.deferReason = 'observe'
897
903
  noteEvent(entry, 'observe', entry.lastDeferred)
898
904
  entry.history = pushHistory(entry.history, {
899
905
  at: new Date().toISOString(),
@@ -911,6 +917,7 @@ async function pollOnce(ctx, entry, baseMs) {
911
917
  const sessionUsed = sessionWakesLastHour(Object.values(readState().watchers || {}), entry.sessionId)
912
918
  if (sessionUsed >= sessionCap) {
913
919
  entry.lastDeferred = '这条会话一小时内已被唤醒 ' + sessionUsed + ' 次(上限 ' + sessionCap + '),已攒 ' + fresh.length + ' 条待处理'
920
+ entry.deferReason = 'cap-session'
914
921
  noteEvent(entry, 'cap-session', entry.lastDeferred)
915
922
  return
916
923
  }
@@ -923,6 +930,7 @@ async function pollOnce(ctx, entry, baseMs) {
923
930
  const freeAt = nextWaketimeAt(entry.wakeTimes, cap)
924
931
  const waitMin = Math.max(1, Math.round((freeAt - Date.now()) / 60000))
925
932
  entry.lastDeferred = `每小时最多唤醒 ${cap} 次,已攒 ${fresh.length} 条待处理(约 ${waitMin} 分钟后可再唤醒)`
933
+ entry.deferReason = 'cap-watcher'
926
934
  noteEvent(entry, 'cap-watcher', entry.lastDeferred)
927
935
  return
928
936
  }
@@ -1011,6 +1019,7 @@ async function pollOnce(ctx, entry, baseMs) {
1011
1019
  entry.prevWakeAt = new Date().toISOString()
1012
1020
  entry.wakeTimes.push(Date.now())
1013
1021
  entry.lastDeferred = null
1022
+ entry.deferReason = null
1014
1023
  noteEvent(entry, 'wake', '唤醒了 ' + (entry.lastBatch || []).length + ' 条:' + (entry.lastBatch || []).map((n) => '#' + n).join(' '))
1015
1024
  entry.seen = advanceSeen(entry.seen, fresh)
1016
1025
  entry.lastReported = recordReported(entry, fresh)
@@ -1020,6 +1029,7 @@ async function pollOnce(ctx, entry, baseMs) {
1020
1029
  entry.lastError = 'wake failed: ' + String(result.reason || '')
1021
1030
  noteEvent(entry, 'wake-failed', entry.lastError)
1022
1031
  // 会话正忙是暂时的:下一轮直接重试;退避反而会越拖越久
1032
+ entry.deferReason = 'busy'
1023
1033
  if (/busy|running|idle/i.test(String(result.reason || ''))) {
1024
1034
  entry.lastDeferred = '会话正忙,下一轮重试'
1025
1035
  } else {
@@ -1217,6 +1227,7 @@ export function apply(ctx) {
1217
1227
  maxIsolated: w.maxIsolated ?? 5,
1218
1228
  history: (w.history ?? []).slice(-5),
1219
1229
  events: (w.events ?? []).slice(-20),
1230
+ deferReason: w.deferReason ?? null,
1220
1231
  silentWakes: w.silentWakes ?? 0,
1221
1232
  note: w.goal ?? '',
1222
1233
  title: sessionTitle(w.sessionId),
@@ -1234,8 +1245,7 @@ export function apply(ctx) {
1234
1245
  const list = Object.values(state.watchers || {})
1235
1246
  const usage = list.length === 0 ? null : sessionWakesLastHour(list, focusSession)
1236
1247
  const cap = list.length === 0 ? null : (Number(list[0].sessionMaxWakes) || 12)
1237
- const capped = list.filter((w) => w && typeof w.lastDeferred === 'string'
1238
- && (w.lastDeferred.includes('上限') || w.lastDeferred.includes('一小时内已被唤醒'))).length
1248
+ const capped = countCapped(list)
1239
1249
  return usage === null ? null : { used: usage, cap, capped }
1240
1250
  })(),
1241
1251
  // 版本漂移:文件换了但宿主还在跑老模块(客户端热重载会掩盖这件事)
package/lib/watch.js CHANGED
@@ -723,3 +723,16 @@ export function summarizeByRepo(watchers) {
723
723
  const weight = (g) => (g.errors > 0 ? 0 : g.silentWakes >= 2 ? 1 : 2)
724
724
  return [...groups.values()].sort((a, b) => (weight(a) - weight(b)) || a.repo.localeCompare(b.repo))
725
725
  }
726
+
727
+ /**
728
+ * 有几条守正被"频率上限"挡着。
729
+ *
730
+ * 之前是面板去匹配提示文案(`lastDeferred.includes('上限')`)—— 文案一改统计就废。
731
+ * 现在服务端在暂停时写一个明确的 `deferReason`,这里只按字段统计。
732
+ */
733
+ export const CAP_REASONS = ['cap-session', 'cap-watcher']
734
+
735
+ export function countCapped(watchers) {
736
+ const list = Array.isArray(watchers) ? watchers : Object.values(watchers || {})
737
+ return list.filter((w) => w && CAP_REASONS.includes(w.deferReason)).length
738
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.9.20",
3
+ "version": "0.9.21",
4
4
  "description": "Session-level superagent for DeepSeek Harness: watch a GitHub repository and wake a session when something needs doing. Credentials never reach the model.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",