dsh-session-superagent 0.9.208 → 0.9.210

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,87 @@
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.210] - 2026-11-05 —— 知识库一致性审计:8 篇「还没做的」早就做完了
6
+
7
+ ### ① 知识库条目过期(T21 报的 8 条「必须改」)
8
+
9
+ `docs/kb/` 有 182 篇,**从来没有被整体复查过**。门禁只查「索引篇数对不对得上」这类结构问题,
10
+ 于是出现了这种情况:条目里写着「还没做的:xxx」,而 xxx 在后续版本里已经做掉了 —— **没人回头删**。
11
+
12
+ | 条目 | 它说 | 代码实际 |
13
+ |---|---|---|
14
+ | `github-conditional-requests` | `x-poll-interval` 还没读 | 已读(`gh-format.js:225`) |
15
+ | `measure-before-trimming` | `/state` 没有 ETag/304 | 有(`index.js:1772`) |
16
+ | `triage-signal-table` | `stale` 权重 0 | `weight: 2` + `score += 2` |
17
+ | `show-saturation` | `capped` 靠匹配文案 | 用原因码 |
18
+ | `repo-permissions` / `repo-structure` | 还没有能力徽章 | `client.js:1258` 已渲染 |
19
+ | `archived-repo` | 徽章只读不可点 | 可点筛选 |
20
+ | `pr-blocked-state` | 没取 CI 状态 | 已取 |
21
+
22
+ **这不是文档小毛病**:一个「还没做」会让下一个接手的人重做一遍已经做过的事。
23
+
24
+ ### ② 数字漂移 17 行
25
+
26
+ 最严重的几处:`why-not-split-index` 说 index.js **1795 行**(实际 2877);
27
+ 对比度基线 **34/32**(实际 16/13);单行长度 **102**(实际 108);`preflight`「第 N 项」**20 处全部失效**
28
+ (脚本不打印序号,插入即错位)。
29
+
30
+ ### ③ 顺带清掉两处代码粗糙
31
+
32
+ - `lib/index.js` 里一个**从没用过**的 `const limit`(死代码);
33
+ - 紧邻的 `splitBatch(..., || 3, ...)` 兜底值与创建时的 `batchLimit=5` **口径分裂** —— 统一成 5。
34
+
35
+ ### ④ CI 红了一条:GBK 用例在无 ICU 的 Node 上会挂
36
+
37
+ `new TextDecoder('gbk')` 在 small-icu 构建里**不支持**(CI 的 Linux Node 就是)。
38
+ `decodeBody` 的回退分支按设计会退回 UTF-8,于是那条断言在 CI 上必红。
39
+ 现在按环境跳过(`skip` 带原因),本机(有 gbk)仍然真跑。
40
+
41
+ ### 证据
42
+
43
+ ```
44
+ node --test → 363/363
45
+ ```
46
+
47
+ ## [0.9.209] - 2026-11-05 —— 把「最会丢消息」的那段抽成纯函数并钉上测试
48
+
49
+ ### ① 那段代码恰好是 171 行、0 覆盖里最危险的 40 行
50
+
51
+ T20 的覆盖审计指出 `pollWithItems()` **171 行、0 次调用**。里面最要命的是**唤醒结算**:
52
+
53
+ ```js
54
+ // 会话忙时如果先把 seen 推进、ETag 也提交 ——
55
+ // 下一轮拿到 304 直接 return,那条 PR 评论**永远不会再叫**,而面板还写「运行中」。
56
+ ```
57
+
58
+ 这段以前是内联的闭包,外面调不到、测不了。现在抽成**纯函数** `planWakeSettlement(entry, result)`:
59
+ 给定「这次唤醒成没成」,返回**要写回的字段**(不改入参),调用方只负责落副作用。
60
+
61
+ 关键返回值是两道开关:
62
+
63
+ - `advanceWatermark` —— 只有**真正发出去了**才为 `true`;
64
+ - `commitEtag` —— 同上。失败分支返回 `false`,水位与 ETag 都不动,下一轮重试同一批。
65
+
66
+ ### ② 三条用例钉死行为
67
+
68
+ ```
69
+ 会话忙时不许推进水位(否则下一轮 304,那条评论永远不再叫)
70
+ 真正发出去之后才推进水位,且记账(入队即记账会丢消息)
71
+ 失败的唤醒也要进 history(客户能看到「叫过但没叫醒」)
72
+ ```
73
+
74
+ ### ③ 顺带
75
+
76
+ - 失败分支的「会话忙」不走退避(暂时的,退避只会越拖越久),其余原因才 `bumpFailure`;
77
+ - `planWakeSettlement` 里同时算好 `ackedRecovered`,避免调用方重复算一遍 `silentStreak`。
78
+
79
+ ### 证据
80
+
81
+ ```
82
+ node --test → 363/363(新增 3 条结算用例)
83
+ ui-audit → 11/11(100 分)
84
+ ```
85
+
5
86
  ## [0.9.208] - 2026-11-05 —— 覆盖审计顺手挖出一个真 bug:`deferReason` 被拼成 `quota09:30Z`
6
87
 
7
88
  ### ① 真 bug:额度文案拼接错位
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.208-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.9.210-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
 
@@ -144,7 +144,7 @@ Gitee 私有仓库要在「设置 → 凭证」填私人令牌;公开仓库不
144
144
  ## 开发
145
145
 
146
146
  ```sh
147
- node --test # 360 项单测
147
+ node --test # 363 项单测
148
148
  ```
149
149
 
150
150
  ### 工具输出:文本给人和 agent,JSON 给程序
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.208'
17
+ const CLIENT_VERSION = '0.9.210'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
package/lib/index.js CHANGED
@@ -26,7 +26,7 @@ import { decodeBody, truncateUtf8 } from './body.js'
26
26
  import { quotaDeferText } from './gh-format.js'
27
27
  import { listGiteeItems, fetchGiteeLastComment, addGiteeLabel, ensureGiteeLabel, giteeWhoami, giteeRepo, mapGiteeRepoAccess, DEFAULT_ACK_LABEL_GITEE, giteeLabels, giteeHasLabel, isValidGiteeLabel, suggestGiteeLabel } from './gitee.js'
28
28
  import {
29
- advanceSeen, applyWatcherAction, batchFresh, decideWake, DEFAULT_ACK_LABEL, formatWatchText,
29
+ planWakeSettlement, advanceSeen, applyWatcherAction, batchFresh, decideWake, DEFAULT_ACK_LABEL, formatWatchText,
30
30
  parseRepoSpec, markGiteeReopened,
31
31
  TRIAGE_SIGNALS, accessNote, wakeCriteria, sessionMissingVerdict, buildCommentBatchQuery, classifyGhError, commentSummaryLine, parseCommentBatch, pickSuggestion, repoStructureNote, countReasons, filterReason, formatGhCall, diagnoseEmptyBody, diagnoseBadBody, isAuthBroken, hasAckLabel, jitterMs, parseGhInclude, retryAfterMs, throttleDelayMs, inActiveHours, newestUpdatedAt, nextDelayMs, enterActiveHoursDefer, recordOtherError, permanentBackoffMs, RETRY_BUDGET_ATTEMPTS, RETRY_SLOW_CAP_MINUTES, pushAbsorbed, pushFiltered, normalizeFilters, partitionItems, passesFilters,
32
32
  shouldRunCleanup,
@@ -43,7 +43,7 @@ import {
43
43
 
44
44
  export const name = 'dsh-session-superagent'
45
45
  /** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
46
- export const SERVER_VERSION = '0.9.208'
46
+ export const SERVER_VERSION = '0.9.210'
47
47
  export const inject = ['tools', 'agents', 'webServer']
48
48
  /** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
49
49
  // 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
@@ -1350,8 +1350,10 @@ async function pollWithItems(ctx, entry, baseMs, parsed) {
1350
1350
  }
1351
1351
 
1352
1352
  // 条目不丢:水位照常全部前移,消息里只铺开前 N 条,其余给编号
1353
- const limit = Math.max(1, Number(entry.batchLimit) || 5)
1354
- const { listed, rest } = splitBatch(fresh, Number(entry.batchLimit) || 3, entry.priorityOrder || entry.priority)
1353
+ // 审核 T21:这里原来有个从没用过的 const limit(死代码),且兜底值写成 || 3,
1354
+ // 与创建时的 batchLimit=5 口径分裂。统一成 5,并删掉死变量。
1355
+ const batchLimit = Math.max(1, Number(entry.batchLimit) || 5)
1356
+ const { listed, rest } = splitBatch(fresh, batchLimit, entry.priorityOrder || entry.priority)
1355
1357
  // 暂停/删除可能发生在这一轮轮询期间:以盘上为准
1356
1358
  const liveEntry = (readState().watchers || {})[entry.id]
1357
1359
  if (!liveEntry || !isEnabled(liveEntry)) {
@@ -1441,48 +1443,39 @@ async function pollWithItems(ctx, entry, baseMs, parsed) {
1441
1443
  // 之前是入队即记账 —— 会话忙时 decideWake 会拒绝,次数却已经记了、seen 也已经推进,
1442
1444
  // 于是那几条既不会重试(seen 已推进)又白白占掉名额。这是会丢消息的 bug。
1443
1445
  wakeMerged(ctx, entry.sessionId, wakeText, (result) => {
1444
- entry.lastWake = result.ok ? new Date().toISOString() : 'failed: ' + String(result.reason || '')
1445
- entry.history = pushHistory(entry.history, {
1446
- at: new Date().toISOString(),
1447
- numbers: entry.lastBatch,
1446
+ // 审核 T20:结算逻辑抽成纯函数 planWakeSettlement()(有单测),这里只负责落副作用。
1447
+ const settled = planWakeSettlement(entry, {
1448
1448
  ok: result.ok,
1449
- reason: result.ok ? null : String(result.reason || '').slice(0, 120),
1449
+ reason: result.reason,
1450
+ fresh,
1451
+ firstSync,
1452
+ baseMs,
1450
1453
  })
1451
- if (result.ok) {
1452
- // 上一次唤醒之后有没有 ack?没有就累计"叫醒了没回音"
1453
- entry.silentWakes = silentStreak({
1454
- previousWakeAt: entry.prevWakeAt,
1455
- lastAckedAt: entry.lastAcked && entry.lastAcked.at,
1456
- previousStreak: entry.silentWakes,
1457
- })
1458
- if (entry.silentWakes === 0 && entry.prevWakeAt) noteEvent(entry, 'acked', '上一次唤醒有回音(ack 出现过了)')
1459
- entry.prevWakeAt = new Date().toISOString()
1460
- entry.wakeTimes.push(Date.now())
1461
- entry.dailyWakes = bumpDailyWakes(entry.dailyWakes)
1462
- entry.lastDeferred = null
1463
- entry.deferReason = null
1464
- noteEvent(entry, firstSync ? 'baseline' : 'wake',
1465
- (firstSync ? '首次同步(存量 ' : '唤醒了 ') + (entry.lastBatch || []).length + ' 条' + (firstSync ? ')' : '') +
1466
- ':' + (entry.lastBatch || []).map((n) => '#' + n).join(' '))
1467
- entry.seen = advanceSeen(entry.seen, fresh)
1468
- entry.lastReported = recordReported(entry, fresh)
1469
- entry.cursor = newestUpdatedAt(fresh)
1470
- // 真正发出去了:这一轮被完整消费,ETag 才可以前移。
1471
- // 若在失败分支前移,下一轮会拿到 304 而不再重算 fresh —— 与上面「保留水位」的意图相悖。
1454
+ entry.lastWake = settled.lastWake
1455
+ entry.lastWakeCount = settled.lastWakeCount
1456
+ entry.lastBatch = settled.lastBatch
1457
+ entry.history = settled.history
1458
+ if (settled.error) setEntryError(entry, settled.error)
1459
+ if (settled.advanceWatermark) {
1460
+ entry.silentWakes = settled.silentWakes
1461
+ if (settled.ackedRecovered && entry.prevWakeAt) noteEvent(entry, 'acked', '上一次唤醒有回音(ack 出现过了)')
1462
+ entry.prevWakeAt = settled.prevWakeAt
1463
+ entry.wakeTimes = settled.wakeTimes
1464
+ entry.dailyWakes = settled.dailyWakes
1465
+ entry.lastDeferred = settled.lastDeferred
1466
+ entry.deferReason = settled.deferReason
1467
+ noteEvent(entry, settled.eventKind, settled.eventText)
1468
+ entry.seen = settled.seen
1469
+ entry.lastReported = settled.lastReported
1470
+ entry.cursor = settled.cursor
1472
1471
  commitEtag()
1473
1472
  } else {
1474
1473
  // 保留水位,下一轮重试这次事件
1475
- setEntryError(entry, 'wake failed: ' + String(result.reason || ''))
1476
1474
  noteEvent(entry, 'wake-failed', entry.lastError)
1477
- // 会话正忙是暂时的:下一轮直接重试;退避反而会越拖越久
1478
- entry.deferReason = 'busy'
1479
- if (/busy|running|idle/i.test(String(result.reason || ''))) {
1480
- entry.lastDeferred = '会话正忙,下一轮重试'
1481
- } else {
1482
- bumpFailure(entry, baseMs)
1483
- }
1484
- }
1485
- persistEntry(entry)
1475
+ entry.deferReason = settled.deferReason
1476
+ if (settled.lastDeferred) entry.lastDeferred = settled.lastDeferred
1477
+ if (settled.bumpBackoff) bumpFailure(entry, baseMs)
1478
+ } persistEntry(entry)
1486
1479
  })
1487
1480
  }
1488
1481
 
package/lib/watch.js CHANGED
@@ -1174,3 +1174,73 @@ export function markGiteeReopened(items, lastStates = {}) {
1174
1174
  for (const key of Object.keys(next)) if (!alive.has(key)) delete next[key]
1175
1175
  return next
1176
1176
  }
1177
+
1178
+ /**
1179
+ * 一次唤醒的**结算**:成功才推进水位、失败就保留水位。
1180
+ *
1181
+ * 审核 T20:这段原来是内联在 `pollWithItems()` 里的(171 行、0 覆盖)—— 它恰好是
1182
+ * **最会丢消息**的那段:会话忙时如果先把 `seen` 推进、ETag 也提交,下一轮拿到 304 直接 return,
1183
+ * 那条 PR 评论**永远不会再叫**,而面板还写「运行中」。
1184
+ *
1185
+ * 抽成纯函数:给定 entry 与结果,返回**要写回的字段**(不改入参)。调用方 `Object.assign` 即可。
1186
+ */
1187
+ export function planWakeSettlement(entry, { ok, reason, fresh = [], firstSync = false, baseMs = 60000, now = Date.now() } = {}) {
1188
+ const at = new Date(now).toISOString()
1189
+ const numbers = (fresh || []).map((item) => item && item.number).filter(Boolean)
1190
+ const history = pushHistory(entry.history, {
1191
+ at,
1192
+ numbers,
1193
+ ok: Boolean(ok),
1194
+ reason: ok ? null : String(reason || '').slice(0, 120),
1195
+ })
1196
+ const lastWake = ok ? at : 'failed: ' + String(reason || '')
1197
+
1198
+ if (!ok) {
1199
+ // 保留水位:下一轮重试这一批。**不许**在这里碰 seen / cursor / etag。
1200
+ const busy = /busy|running|idle/i.test(String(reason || ''))
1201
+ return {
1202
+ lastWake,
1203
+ history,
1204
+ lastBatch: numbers,
1205
+ lastWakeCount: (fresh || []).length,
1206
+ commitEtag: false,
1207
+ advanceWatermark: false,
1208
+ deferReason: 'busy',
1209
+ lastDeferred: busy ? '会话正忙,下一轮重试' : (entry.lastDeferred || null),
1210
+ bumpBackoff: !busy,
1211
+ baseMs,
1212
+ error: 'wake failed: ' + String(reason || ''),
1213
+ }
1214
+ }
1215
+
1216
+ return {
1217
+ lastWake,
1218
+ history,
1219
+ lastBatch: numbers,
1220
+ lastWakeCount: (fresh || []).length,
1221
+ // 真正发出去了才允许:水位前移 + ETag 前移
1222
+ commitEtag: true,
1223
+ advanceWatermark: true,
1224
+ seen: advanceSeen(entry.seen, fresh || []),
1225
+ lastReported: recordReported(entry, fresh || []),
1226
+ cursor: newestUpdatedAt(fresh || []),
1227
+ silentWakes: silentStreak({
1228
+ previousWakeAt: entry.prevWakeAt,
1229
+ lastAckedAt: entry.lastAcked && entry.lastAcked.at,
1230
+ previousStreak: entry.silentWakes,
1231
+ }),
1232
+ prevWakeAt: at,
1233
+ wakeTimes: [...(entry.wakeTimes || []), now],
1234
+ dailyWakes: bumpDailyWakes(entry.dailyWakes, at),
1235
+ lastDeferred: null,
1236
+ deferReason: null,
1237
+ ackedRecovered: Boolean(entry.prevWakeAt && silentStreak({
1238
+ previousWakeAt: entry.prevWakeAt,
1239
+ lastAckedAt: entry.lastAcked && entry.lastAcked.at,
1240
+ previousStreak: entry.silentWakes,
1241
+ }) === 0),
1242
+ eventKind: firstSync ? 'baseline' : 'wake',
1243
+ eventText: (firstSync ? '首次同步(存量 ' : '唤醒了 ') + numbers.length + ' 条' + (firstSync ? ')' : '') + ':' + numbers.map((n) => '#' + n).join(' '),
1244
+ error: null,
1245
+ }
1246
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.9.208",
3
+ "version": "0.9.210",
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",