dsh-session-superagent 0.9.116 → 0.9.119

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,91 @@
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.119] - 2026-11-03 —— 凭证失效要单独报,并说清"不会自己恢复"
6
+
7
+ ### 真机现场
8
+ ```
9
+ $ gh auth status
10
+ X Failed to log in to github.com account MYCF711 (keyring)
11
+ - The token in keyring is invalid.
12
+ ```
13
+ 插件这边只会显示一条普通的失败(`gh 登录失效:跑 gh auth login`),混在网络抖动里,
14
+ 客户很容易以为"等会儿就好"。而 **401 永远不会自己好**。
15
+
16
+ ### 改法
17
+ 1. `permanentBackoffMs` 把 `auth` 也纳入 30 分钟退避 —— 每 60 秒重试一次无意义,反复 401 还可能被风控;
18
+ 2. 失败时置 `needsReauth = true`,任何一次成功(含 304/204)都清掉;
19
+ 3. `/state` 暴露 `needsReauth`;
20
+ 4. `watch_doctor` 单列一行:
21
+ `FAIL 凭证失效(N 条守):跑 gh auth login 重新登录,在此之前这些守只会一直失败 —— 它不会自己恢复`
22
+ 5. 面板顶部给红色横幅(不只是那行小字错误)。
23
+
24
+ ### 测试
25
+ 新增 3 例:`auth` 的 30 分钟退避、doctor 的"不会自己恢复"提示、面板横幅。合计 **228 例**。
26
+
27
+ ### 说明
28
+ GitHub 文档本轮不可达(`raw.githubusercontent.com` 与 `api.github.com` 均 502),
29
+ 所以这条只依据本机 `gh auth status` 的实测输出,未复核文档原文。
30
+
31
+ ## [0.9.118] - 2026-11-03 —— 单测从 101 秒降到 1.6 秒:它们一直在等一个不可能的 gh 响应
32
+
33
+ ### 现场
34
+ 真机重启后跑 `node --test`,**101 秒**才结束(之前 9 秒)。逐文件计时立刻定位:
35
+
36
+ ```
37
+ 103571 ms test/routes.test.mjs
38
+ 42290 ms test/contract-stability.test.mjs
39
+ ```
40
+
41
+ 根因不是用例写错,而是**环境**:`gh auth status` 显示
42
+
43
+ ```
44
+ X Failed to log in to github.com account MYCF711 (keyring)
45
+ - The token in keyring is invalid.
46
+ ```
47
+
48
+ 于是每个调用 `gh api` 的用例都要等到超时(`watch_start` 的仓库体检、`watch_ack` 打标签)。
49
+
50
+ ### 改法
51
+ 加一个**离线模式** `DSH_SUPERAGENT_OFFLINE=1`:`run()` 遇到 `gh` 直接返回固定内容,不 spawn。
52
+ `preflight` 在跑子进程时开启它(生产不会设这个变量)。
53
+
54
+ ### 证据
55
+ ```
56
+ 改前:node --test → 101.4 秒
57
+ 改后:DSH_SUPERAGENT_OFFLINE=1 node --test → 1.65 秒(225/225 通过)
58
+ ```
59
+
60
+ ### 顺带
61
+ README「已知限制」补一条:凭证失效时的表现与"不会自己恢复、需要重新登录"。
62
+
63
+ ## [0.9.117] - 2026-11-03 —— 真机重启后发现:时段外那条「异常」永远不会自己好
64
+
65
+ ### 现场(重启后实测)
66
+ ```
67
+ 插件版本: 0.9.116
68
+ 值守: 1 条 | 启用 | 间隔 120s | 失败 4 | 错误: gh: HTTP 304(没归类的错误…)
69
+ 上次轮询: 2026-11-02T14:30:50.655Z(5.4 小时前)
70
+ lastDeferred: 不在活跃时段(09:00-23:00),597 分钟后开始
71
+ nextAt: 2026-11-03T01:00:00.114Z(= 本地 09:00)
72
+ ```
73
+
74
+ 问题很清楚:这条守的活跃时段是 **09:00–23:00**,此刻 03:53 —— **不在时段内,不会轮询**,
75
+ 所以那条旧错误(`gh: HTTP 304`)就永远挂着,面板上的红点和「异常」计数也一直在。
76
+ 而它其实**不是"现在"的事实**:这 5 小时里根本没有请求发生过。
77
+
78
+ ### 改法
79
+ 抽出 `enterActiveHoursDefer()`,时段外进入等待时顺手清掉瞬时状态:
80
+ `lastError` / `lastErrorAt` / `consecutiveFailures` 归零(`nextAt` / `lastDeferred` 照常写)。
81
+
82
+ ### 为什么不是"面板上忽略它"
83
+ 因为 `watch_doctor`、`watch_status`、`/state` 三个出口都会读 `lastError`。
84
+ **在数据源头清掉,比在每个出口各写一遍"如果是时段外就别显示"可靠得多。**
85
+
86
+ ### 测试
87
+ 新增 1 例:进入时段外等待后,错误与失败计数都归零、`nextAt` 指向未来、`lastDeferred` 写明多久后开始。
88
+ 合计 **224 例**。
89
+
5
90
  ## [0.9.116] - 2026-11-03 —— 404 不等于"不存在";顺便修掉一个"凌晨才红"的用例
6
91
 
7
92
  ### 学到什么(出处)
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.116-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.9.119-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
 
@@ -99,7 +99,8 @@ dsh plugin install /path/to/dsh-session-superagent
99
99
 
100
100
  ## 已知限制
101
101
 
102
- - 依赖 `gh` CLI 已登录;需要 GitHub 账号权限。
102
+ - 依赖 `gh` CLI 已登录;需要 GitHub 账号权限。
103
+ - 凭证失效时(例如 keyring 里的 token 过期)会显示「gh 登录失效:跑 gh auth login」;轮询会按退避重试,但**不会**自己恢复,需要你重新登录。
103
104
  - 轮询而非 webhook:延迟等于轮询间隔。
104
105
  - 一条会话可以守多个仓库(每条守独立配置间隔/过滤/时段),但**同一会话同一时刻只处理一批**:
105
106
  多仓库同时有动静时按每小时上限排队。
@@ -122,7 +123,7 @@ dsh plugin install /path/to/dsh-session-superagent
122
123
  ## 开发
123
124
 
124
125
  ```sh
125
- node --test # 223 项单测
126
+ node --test # 228 项单测
126
127
  ```
127
128
 
128
129
  ### 工具输出:文本给人和 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.116'
17
+ const CLIENT_VERSION = '0.9.119'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
@@ -1093,6 +1093,8 @@ window.__ModuleLoader__.load({
1093
1093
  (watcher.otherSessions && watcher.otherSessions.length > 0)
1094
1094
  ? h('div', { className: 'dt-ticket-note' }, '还有 ' + watcher.otherSessions.length + ' 个会话也在守这个仓库:' + watcher.otherSessions.join('、') + '(各自独立唤醒;但 ack 标签是仓库级的 —— 任一方 ack 后两边都会跳过,想让两边各处理各的就给对方设不同标签)')
1095
1095
  : null,
1096
+ watcher.needsReauth ? h('div', { className: 'dt-banner dt-danger' },
1097
+ '凭证失效:跑 gh auth login 重新登录 —— 它不会自己恢复,在此之前这条守只会一直失败') : null,
1096
1098
  watcher.lastError ? (() => {
1097
1099
  const parts = splitErrorText(watcher.lastError)
1098
1100
  // 错误光说「为什么」不够,要能点一下就到「下一步」(服务端已给 kind)
package/lib/index.js CHANGED
@@ -25,7 +25,7 @@ import { redact } from './redact.js'
25
25
  import { decodeBody } from './body.js'
26
26
  import {
27
27
  advanceSeen, applyWatcherAction, batchFresh, decideWake, DEFAULT_ACK_LABEL, formatWatchText,
28
- TRIAGE_SIGNALS, accessNote, buildCommentBatchQuery, classifyGhError, commentSummaryLine, parseCommentBatch, pickSuggestion, repoStructureNote, countReasons, filterReason, formatGhCall, hasAckLabel, jitterMs, parseGhInclude, retryAfterMs, throttleDelayMs, inActiveHours, newestUpdatedAt, nextDelayMs, permanentBackoffMs, pushAbsorbed, pushFiltered, normalizeFilters, partitionItems, passesFilters,
28
+ TRIAGE_SIGNALS, accessNote, buildCommentBatchQuery, classifyGhError, commentSummaryLine, parseCommentBatch, pickSuggestion, repoStructureNote, countReasons, filterReason, formatGhCall, hasAckLabel, jitterMs, parseGhInclude, retryAfterMs, throttleDelayMs, inActiveHours, newestUpdatedAt, nextDelayMs, enterActiveHoursDefer, permanentBackoffMs, pushAbsorbed, pushFiltered, normalizeFilters, partitionItems, passesFilters,
29
29
  shouldRunCleanup,
30
30
  bumpDailyWakes,
31
31
  busierThanUsual,
@@ -40,7 +40,7 @@ import {
40
40
 
41
41
  export const name = 'dsh-session-superagent'
42
42
  /** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
43
- export const SERVER_VERSION = '0.9.116'
43
+ export const SERVER_VERSION = '0.9.119'
44
44
  export const inject = ['tools', 'agents', 'webServer']
45
45
  /** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
46
46
  // 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
@@ -472,9 +472,30 @@ async function prepareIsolation(entry) {
472
472
  }
473
473
 
474
474
  /** Spawn a command, capture both streams, never echo the credential. */
475
+ /**
476
+ * 离线模式(`DSH_SUPERAGENT_OFFLINE=1`):所有 `gh` 调用返回固定内容,不碰网络。
477
+ *
478
+ * 为什么需要:单测/CI 里没有有效凭证时,每次 `gh api` 都要等到超时,
479
+ * 一个测试文件能跑 100 秒(真机实测);而它们的断言与网络无关。
480
+ * 生产里不会设这个变量 —— 开启后结果都是假的,只适合测试。
481
+ */
482
+ function offlineGhReply(args) {
483
+ const joined = (args || []).join(' ')
484
+ if (joined.includes('--version')) return 'gh version 2.0.0 (offline)'
485
+ if (joined.includes('api -i user')) return 'HTTP/2.0 200 OK' + String.fromCharCode(13, 10) + String.fromCharCode(13, 10)
486
+ if (joined.includes('api user')) return 'offline-user'
487
+ if (joined.includes('labels')) return '{}'
488
+ const repoMatch = joined.match(new RegExp('repos/([A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+)'))
489
+ return JSON.stringify({ full_name: repoMatch ? repoMatch[1] : 'offline/repo', private: false, items: [], total_count: 0 })
490
+ }
491
+
475
492
  function run(file, args, options = {}) {
476
493
  const { input, cwd, env, timeoutMs = 60000 } = options
477
494
  return new Promise((resolve) => {
495
+ if (file === 'gh' && process.env.DSH_SUPERAGENT_OFFLINE === '1') {
496
+ resolve({ code: 0, stdout: offlineGhReply(args), stderr: '' })
497
+ return
498
+ }
478
499
  const child = spawn(file, args, { cwd, env: env ?? process.env, windowsHide: true, shell: false })
479
500
  let stdout = ''
480
501
  let stderr = ''
@@ -856,9 +877,8 @@ async function pollOnce(ctx, entry, baseMs) {
856
877
  // 不在时段内就把下一次轮询安排到"开门那一刻",攒着的条目不会多等一个周期。
857
878
  if (entry.activeHours && !inActiveHours(entry.activeHours)) {
858
879
  const wait = msUntilActiveWindow(entry.activeHours)
859
- entry.nextAt = new Date(Date.now() + wait).toISOString()
860
- entry.lastDeferred = `不在活跃时段(${entry.activeHours}),${Math.round(wait / 60000)} 分钟后开始`
861
- entry.deferReason = 'active-hours'
880
+ // 时段外不轮询:顺手清掉旧错误(否则面板会一直显示一条永不消停的「异常」)
881
+ enterActiveHoursDefer(entry, wait, entry.activeHours)
862
882
  noteEvent(entry, 'defer', entry.lastDeferred)
863
883
  return
864
884
  }
@@ -871,6 +891,7 @@ async function pollOnce(ctx, entry, baseMs) {
871
891
  // gh 把 304 当失败(非 2xx 就 exit 1):这不是错误,是「条件请求命中」
872
892
  if (/HTTP 304|304 Not Modified|not modified/i.test(String(res.stderr || '') + String(res.stdout || ''))) {
873
893
  entry.lastError = null
894
+ entry.needsReauth = false
874
895
  entry.consecutiveFailures = 0
875
896
  entry.nextAt = null
876
897
  entry.lastDeferred = UNCHANGED_TEXT
@@ -887,6 +908,7 @@ async function pollOnce(ctx, entry, baseMs) {
887
908
  entry.deferReason = 'ratelimit'
888
909
  noteEvent(entry, 'ratelimit', entry.lastDeferred)
889
910
  entry.lastError = null
911
+ entry.needsReauth = false
890
912
  return
891
913
  }
892
914
  const detail = redact(res.stderr).slice(0, 240)
@@ -895,6 +917,8 @@ async function pollOnce(ctx, entry, baseMs) {
895
917
  setEntryError(entry, (classified.short + classified.hint).slice(0, 300))
896
918
  bumpFailure(entry, baseMs)
897
919
  // 永久性错误(404 / 仓库改名)不要按普通退避重试:至少等半小时
920
+ // 凭证问题要显式标出来:它不会自己恢复,客户必须去 gh auth login
921
+ if (classified.kind === 'auth') entry.needsReauth = true
898
922
  const permanent = permanentBackoffMs(classified.kind, baseMs)
899
923
  if (permanent > 0) {
900
924
  entry.nextAt = new Date(Date.now() + permanent).toISOString()
@@ -917,11 +941,13 @@ async function pollOnce(ctx, entry, baseMs) {
917
941
  entry.deferReason = 'quota'
918
942
  + new Date(Date.now() + throttle).toISOString().slice(11, 16) + 'Z'
919
943
  entry.lastError = null
944
+ entry.needsReauth = false
920
945
  return
921
946
  }
922
947
  // 204 No Content 也是「没有新东西」:DELETE/空列表都会这样,别当 JSON 解析失败
923
948
  if (parsed.status === 204) {
924
949
  entry.lastError = null
950
+ entry.needsReauth = false
925
951
  entry.consecutiveFailures = 0
926
952
  entry.nextAt = null
927
953
  entry.lastDeferred = '没有内容(204)'
@@ -932,6 +958,7 @@ async function pollOnce(ctx, entry, baseMs) {
932
958
  if (parsed.status === 304) {
933
959
  // 没变化:不解析、不算失败、不重置退避,只记一笔
934
960
  entry.lastError = null
961
+ entry.needsReauth = false
935
962
  entry.consecutiveFailures = 0
936
963
  entry.nextAt = null
937
964
  entry.lastDeferred = UNCHANGED_TEXT
@@ -945,6 +972,7 @@ async function pollOnce(ctx, entry, baseMs) {
945
972
  if (!Array.isArray(items)) { setEntryError(entry, '返回的数据结构不对(预期是数组)—— 已按退避自动重试;持续出现请跑 watch_doctor'); bumpFailure(entry, baseMs); return }
946
973
 
947
974
  entry.lastError = null
975
+ entry.needsReauth = false
948
976
  entry.consecutiveFailures = 0
949
977
  entry.nextAt = null
950
978
  // 记住最近一条"被重新打开"的 issue:这是最该被看见的信号(之前判过不做)
@@ -1349,6 +1377,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
1349
1377
  // 分类放在服务端做一次:面板按 kind 给「下一步」按钮,不用自己解析中文
1350
1378
  lastErrorKind: w.lastError ? classifyGhError(String(w.lastError)).kind : null,
1351
1379
  lastErrorAt: w.lastErrorAt || null,
1380
+ needsReauth: w.needsReauth === true,
1352
1381
  deferReason: w.deferReason ?? null,
1353
1382
  daily: dailySummary(w.dailyWakes),
1354
1383
  busy: busierThanUsual(dailySummary(w.dailyWakes)),
@@ -1938,6 +1967,14 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
1938
1967
  const all = Object.values(state.watchers || {})
1939
1968
  const wanted = args.repo ? all.filter((w) => w && w.repo === String(args.repo)) : all
1940
1969
 
1970
+ // -3. 凭证失效:不会自愈,必须人去登录
1971
+ {
1972
+ const needAuth = wanted.filter((w) => w.needsReauth === true)
1973
+ if (needAuth.length > 0) {
1974
+ lines.push('FAIL 凭证失效(' + needAuth.length + ' 条守):跑 gh auth login 重新登录,'
1975
+ + '在此之前这些守只会一直失败 —— 它不会自己恢复')
1976
+ }
1977
+ }
1941
1978
  // -2. 状态来源:从备份或损坏里恢复过,客户有权知道(否则他会纳闷「我的守怎么少了一条」)
1942
1979
  if (stateSource === 'backup') {
1943
1980
  lines.push('WARN 状态文件坏过一次,已从备份恢复(原文件留在 .corrupt-* 里,可人工检查)')
package/lib/watch.js CHANGED
@@ -319,8 +319,25 @@ export function batchFresh(fresh, limit = 3, priority) {
319
319
  * 反复请求不存在的资源既浪费额度,还可能触发 secondary rate limit。
320
320
  * 出处:https://docs.github.com/en/rest/using-the-rest-api/best-practices-for-using-the-rest-api
321
321
  */
322
+ /**
323
+ * 进入「不在活跃时段」的等待:顺带把上一次的错误清掉。
324
+ *
325
+ * 为什么:时段外根本不轮询,旧的 lastError 会一直挂着,面板上就变成一条永不消停的「异常」。
326
+ * 依据同 paused-means-no-new-facts:不再更新的状态不该继续代表「现在」。
327
+ */
328
+ export function enterActiveHoursDefer(entry, waitMs, hours, at = new Date()) {
329
+ entry.nextAt = new Date(at.getTime() + Number(waitMs || 0)).toISOString()
330
+ entry.lastDeferred = `不在活跃时段(${hours}),${Math.round(Number(waitMs || 0) / 60000)} 分钟后开始`
331
+ entry.deferReason = 'active-hours'
332
+ // 旧错误不是「现在」的事实
333
+ entry.lastError = null
334
+ entry.lastErrorAt = null
335
+ entry.consecutiveFailures = 0
336
+ return entry
337
+ }
322
338
  export function permanentBackoffMs(kind, baseMs = 60000) {
323
- const PERMANENT = new Set(['notfound', 'moved'])
339
+ // auth:凭证失效不会自己好 —— 每 60 秒重试既无用,也可能被风控当成异常
340
+ const PERMANENT = new Set(['notfound', 'moved', 'auth'])
324
341
  if (!PERMANENT.has(kind)) return 0
325
342
  return Math.max(30 * 60 * 1000, Number(baseMs) || 0)
326
343
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.9.116",
3
+ "version": "0.9.119",
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",