dsh-session-superagent 0.9.20 → 0.9.22

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,49 @@
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.22] - 2026-11-02 —— 暂停原因可以按原因码筛选
6
+
7
+ ### 背景
8
+ 0.9.21 让服务端写了结构化的 `deferReason`,但面板还没用它做任何事 —— 只是"数据有了"。
9
+
10
+ ### 改法
11
+ 「判定」页新增一排「暂停原因」Pill(`撞会话上限 ×2` / `被 GitHub 限流 ×1` …),
12
+ 点一下只看那一类;**复用已有的 `reasonFilter` 槽位**(零新增 state),
13
+ 但内部用 `defer:` 前缀与"跳过原因"筛选区分开。
14
+
15
+ 同时把「需要关注」也一起收窄 —— 否则列表只剩一条、上面告警还列着别的仓库,自相矛盾。
16
+
17
+ ### 一个实现顺序问题(被用例抓到)
18
+ `DEFER_LABELS` 一开始定义在组件中段,判定页先用到 → `Cannot access before initialization`。
19
+ 常量要放在**组件最前面**(所有 `useState` 之前),因为它不依赖任何状态。
20
+
21
+ ### 测试
22
+ - 新增 1 例(原因码翻成人话 + 选中后明细只剩那一类)。合计 **167 例**。
23
+
24
+ ## [0.9.21] - 2026-11-02 —— 用原因码替代"匹配提示文案"
25
+
26
+ ### 学到的(知识库第 70 条)
27
+ 把展示层当数据层是反模式。OTel 的 log record 带结构化 attributes,文案只负责给人看。
28
+ 一旦拿文案当判据,任何一次文案优化都会**静默改变统计数据**。
29
+
30
+ ### 修的是什么
31
+ 0.9.20 统计"几条守被上限挡住"用的是 `lastDeferred.includes('上限')`:
32
+ - 文案一改统计归零;
33
+ - "额度紧张(剩余 …)"这类含"上限"但不是频率上限的提示会被误算。
34
+
35
+ ### 改法
36
+ 服务端在各暂停分支写 `entry.deferReason`(`active-hours` / `ratelimit` / `quota` /
37
+ `unchanged` / `observe` / `cap-session` / `cap-watcher` / `busy`),
38
+ 统计改用 `countCapped()` 只认两种 cap 码;`/state` 也回传 `deferReason`。
39
+
40
+ ### 用例锁住的误判
41
+ ```js
42
+ countCapped([{ lastDeferred: '每小时最多唤醒 6 次' }]) === 0 // 文案有"上限"也不算
43
+ ```
44
+
45
+ ### 测试
46
+ - 新增 2 例(计数语义 + `/state` 契约)。合计 **166 例**。
47
+
5
48
  ## [0.9.20] - 2026-11-02 —— 面板显示"还能用几次"(会话唤醒用量)
6
49
 
7
50
  ### 学到的(知识库第 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.22-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.22'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
@@ -831,6 +831,18 @@ window.__ModuleLoader__.load({
831
831
 
832
832
  function ZhuliPanel(props) {
833
833
  const sessionId = props && props.sessionId
834
+ /** 暂停原因码 → 人话(服务端 deferReason 是唯一来源)。 */
835
+ const DEFER_LABELS = {
836
+ 'active-hours': '不在活跃时段',
837
+ ratelimit: '被 GitHub 限流',
838
+ quota: '额度紧张',
839
+ unchanged: '没有变化',
840
+ observe: '仅观察',
841
+ 'cap-session': '撞会话上限',
842
+ 'cap-watcher': '撞单守上限',
843
+ busy: '会话忙',
844
+ }
845
+
834
846
  const [snap, setSnap] = useState({ loading: true, error: null, body: null })
835
847
  const [tab, setTab] = useState('overview')
836
848
  const [notice, setNotice] = useState(null)
@@ -1109,7 +1121,10 @@ window.__ModuleLoader__.load({
1109
1121
  }
1110
1122
 
1111
1123
  const problems = []
1124
+ // 按暂停原因筛选时,「需要关注」也一起收窄(否则列表和告警会自相矛盾)
1125
+ const deferFilter = reasonFilter && reasonFilter.startsWith('defer:') ? reasonFilter.slice(6) : null
1112
1126
  for (const watcher of watchers) {
1127
+ if (deferFilter && watcher.deferReason !== deferFilter) continue
1113
1128
  // 仓库结构问题(关闭 Issues / 是 fork)比轮询失败更早该说:它注定收不到条目
1114
1129
  const structure = repoStructureNote(watcher.repoAccess)
1115
1130
  if (structure) problems.push({ key: 's-' + watcher.repo, text: structure })
@@ -1150,7 +1165,9 @@ window.__ModuleLoader__.load({
1150
1165
  || Number(watcher.silentWakes) >= 2
1151
1166
  || Boolean(repoStructureNote(watcher.repoAccess))
1152
1167
  || repoBadges(watcher.repoAccess).some((badge) => badge.tone === 'warning' || badge.tone === 'danger')
1153
- const visible = watchers.filter((watcher) => matches(watcher) && matchesBadge(watcher) && (!problemsOnly || hasProblem(watcher)))
1168
+ const visible = watchers.filter((watcher) => matches(watcher) && matchesBadge(watcher)
1169
+ && (!problemsOnly || hasProblem(watcher))
1170
+ && (!deferFilter || watcher.deferReason === deferFilter))
1154
1171
 
1155
1172
  const overview = [
1156
1173
  watchers.some((w) => (w.filteredLog || []).length > 0)
@@ -1211,6 +1228,19 @@ window.__ModuleLoader__.load({
1211
1228
  count: watchers.reduce((n, w) => n + (w.history || []).length, 0),
1212
1229
  action: h(InfoTip, { text: '每轮判定都会记一条:唤醒、仅观察,或跳过及其原因。只存最近若干条。' }),
1213
1230
  },
1231
+ (() => {
1232
+ const counts = new Map()
1233
+ for (const w of watchers) if (w.deferReason) counts.set(w.deferReason, (counts.get(w.deferReason) || 0) + 1)
1234
+ if (counts.size === 0) return null
1235
+ return h('div', { className: 'dt-row-meta', key: 'defer-totals' },
1236
+ h('span', null, '暂停原因:'),
1237
+ [...counts.entries()].sort((a, b) => b[1] - a[1]).map(([code, n]) => h(Pill, {
1238
+ key: code,
1239
+ active: deferFilter === code,
1240
+ onClick: () => setReasonFilter(deferFilter === code ? null : 'defer:' + code),
1241
+ }, (DEFER_LABELS[code] || code) + ' × ' + n)),
1242
+ deferFilter ? h(Pill, { key: 'clear-defer', onClick: () => setReasonFilter(null) }, '清除') : null)
1243
+ })(),
1214
1244
  reasonTotals.length > 0
1215
1245
  ? h('div', { className: 'dt-row-meta', key: 'reason-totals' },
1216
1246
  h('span', null, '跳过原因累计:'),
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.22'
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.22",
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",