dsh-session-superagent 0.9.116 → 0.9.118

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,65 @@
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.118] - 2026-11-03 —— 单测从 101 秒降到 1.6 秒:它们一直在等一个不可能的 gh 响应
6
+
7
+ ### 现场
8
+ 真机重启后跑 `node --test`,**101 秒**才结束(之前 9 秒)。逐文件计时立刻定位:
9
+
10
+ ```
11
+ 103571 ms test/routes.test.mjs
12
+ 42290 ms test/contract-stability.test.mjs
13
+ ```
14
+
15
+ 根因不是用例写错,而是**环境**:`gh auth status` 显示
16
+
17
+ ```
18
+ X Failed to log in to github.com account MYCF711 (keyring)
19
+ - The token in keyring is invalid.
20
+ ```
21
+
22
+ 于是每个调用 `gh api` 的用例都要等到超时(`watch_start` 的仓库体检、`watch_ack` 打标签)。
23
+
24
+ ### 改法
25
+ 加一个**离线模式** `DSH_SUPERAGENT_OFFLINE=1`:`run()` 遇到 `gh` 直接返回固定内容,不 spawn。
26
+ `preflight` 在跑子进程时开启它(生产不会设这个变量)。
27
+
28
+ ### 证据
29
+ ```
30
+ 改前:node --test → 101.4 秒
31
+ 改后:DSH_SUPERAGENT_OFFLINE=1 node --test → 1.65 秒(225/225 通过)
32
+ ```
33
+
34
+ ### 顺带
35
+ README「已知限制」补一条:凭证失效时的表现与"不会自己恢复、需要重新登录"。
36
+
37
+ ## [0.9.117] - 2026-11-03 —— 真机重启后发现:时段外那条「异常」永远不会自己好
38
+
39
+ ### 现场(重启后实测)
40
+ ```
41
+ 插件版本: 0.9.116
42
+ 值守: 1 条 | 启用 | 间隔 120s | 失败 4 | 错误: gh: HTTP 304(没归类的错误…)
43
+ 上次轮询: 2026-11-02T14:30:50.655Z(5.4 小时前)
44
+ lastDeferred: 不在活跃时段(09:00-23:00),597 分钟后开始
45
+ nextAt: 2026-11-03T01:00:00.114Z(= 本地 09:00)
46
+ ```
47
+
48
+ 问题很清楚:这条守的活跃时段是 **09:00–23:00**,此刻 03:53 —— **不在时段内,不会轮询**,
49
+ 所以那条旧错误(`gh: HTTP 304`)就永远挂着,面板上的红点和「异常」计数也一直在。
50
+ 而它其实**不是"现在"的事实**:这 5 小时里根本没有请求发生过。
51
+
52
+ ### 改法
53
+ 抽出 `enterActiveHoursDefer()`,时段外进入等待时顺手清掉瞬时状态:
54
+ `lastError` / `lastErrorAt` / `consecutiveFailures` 归零(`nextAt` / `lastDeferred` 照常写)。
55
+
56
+ ### 为什么不是"面板上忽略它"
57
+ 因为 `watch_doctor`、`watch_status`、`/state` 三个出口都会读 `lastError`。
58
+ **在数据源头清掉,比在每个出口各写一遍"如果是时段外就别显示"可靠得多。**
59
+
60
+ ### 测试
61
+ 新增 1 例:进入时段外等待后,错误与失败计数都归零、`nextAt` 指向未来、`lastDeferred` 写明多久后开始。
62
+ 合计 **224 例**。
63
+
5
64
  ## [0.9.116] - 2026-11-03 —— 404 不等于"不存在";顺便修掉一个"凌晨才红"的用例
6
65
 
7
66
  ### 学到什么(出处)
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.118-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 # 225 项单测
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.118'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
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.118'
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
  }
package/lib/watch.js CHANGED
@@ -319,6 +319,22 @@ 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
339
  const PERMANENT = new Set(['notfound', 'moved'])
324
340
  if (!PERMANENT.has(kind)) return 0
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.118",
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",