dsh-session-superagent 0.9.123 → 0.9.124

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,37 @@
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.124] - 2026-11-03 —— 真机实测:令牌失效时我们却在怪代理
6
+
7
+ ### 现场(09:00 时段开门后的真实轮询)
8
+ ```
9
+ serverVersion: 0.9.116
10
+ - MYCF711/dsh-go | 启用 | 失败 5 | nextAt 2026-11-03T01:30:27.698Z
11
+ lastError: 返回内容不是合法 JSON(可能是代理干扰)—— 已按退避自动重试
12
+ ```
13
+
14
+ 时段一到它确实开始轮询了(`nextAt` 排到 09:30),但**失败原因写错了**:
15
+ 真实原因是 `gh` 令牌失效 → 输出为空 → `JSON.parse('')` 抛错,于是我们甩锅给"代理"。
16
+ 客户会去查一个根本不存在的代理,而真正要做的是 `gh auth login`。
17
+
18
+ ### 学到什么(出处)
19
+ GitHub 排障文档在"结果不对"时要求先确认凭证:
20
+
21
+ > If you are using pagination correctly and still do not see all of the results that you expect,
22
+ > you should **confirm that the authentication credentials** that you used have access…
23
+
24
+ <https://docs.github.com/en/rest/using-the-rest-api/troubleshooting-the-rest-api#missing-results>
25
+
26
+ ### 改法
27
+ 1. 新增纯函数 `diagnoseEmptyBody({ bodyText, authStatusText })`:
28
+ - 空内容 + 凭证失效 → `auth`(提示 `gh auth login`);
29
+ - 空内容 + 凭证正常 → `empty`(提示可能是代理/未登录,去看 `watch_doctor`);
30
+ 2. 解析失败时先跑一次 `gh auth status`(60 秒缓存,只在失败路径);
31
+ 3. 判为 `auth` 时置 `needsReauth = true` 并走 30 分钟退避。
32
+
33
+ ### 测试
34
+ 新增 1 例(空 + 凭证失效 → auth;空 + 凭证正常 → empty;有内容 → 不诊断)。合计 **234 例**。
35
+
5
36
  ## [0.9.123] - 2026-11-03 —— 「已放慢到 2 小时档」不该是写死的文案
6
37
 
7
38
  ### 学到什么(出处)
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.123-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.9.124-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
 
@@ -123,7 +123,7 @@ dsh plugin install /path/to/dsh-session-superagent
123
123
  ## 开发
124
124
 
125
125
  ```sh
126
- node --test # 233 项单测
126
+ node --test # 234 项单测
127
127
  ```
128
128
 
129
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.123'
17
+ const CLIENT_VERSION = '0.9.124'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
package/lib/gh-format.js CHANGED
@@ -6,6 +6,23 @@
6
6
  //
7
7
  // 约定:本文件只做「解析 / 归类 / 措辞」,不发请求、不碰状态。
8
8
 
9
+ /**
10
+ * gh 返回空/坏内容时,先分清是「凭证问题」还是「代理/网络问题」。
11
+ *
12
+ * 真机现场:令牌失效后 `gh api` 输出为空,我们却说「可能是代理干扰」—— 客户会去查代理,
13
+ * 而真正要做的是 `gh auth login`。
14
+ * 依据:GitHub 排障文档在结果不对时要求「confirm that the authentication credentials … have access」
15
+ * 出处:https://docs.github.com/en/rest/using-the-rest-api/troubleshooting-the-rest-api#missing-results
16
+ */
17
+ export function diagnoseEmptyBody({ bodyText, authStatusText } = {}) {
18
+ const body = String(bodyText ?? '').trim()
19
+ if (body.length > 0) return null
20
+ const auth = String(authStatusText ?? '')
21
+ if (/token in keyring is invalid|Failed to log in|Bad credentials|requires authentication/i.test(auth)) {
22
+ return { kind: 'auth', hint: '(gh 没有返回内容,且凭证已失效:跑 gh auth login 重新登录)' }
23
+ }
24
+ return { kind: 'empty', hint: '(gh 没有返回内容:可能是代理拦截或未登录 —— 跑 watch_doctor 看凭证)' }
25
+ }
9
26
  /**
10
27
  * 把 `gh` 调用的结果整理成给 agent 看的一段文本。
11
28
  *
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, enterActiveHoursDefer, permanentBackoffMs, RETRY_BUDGET_ATTEMPTS, RETRY_SLOW_CAP_MINUTES, pushAbsorbed, pushFiltered, normalizeFilters, partitionItems, passesFilters,
28
+ TRIAGE_SIGNALS, accessNote, buildCommentBatchQuery, classifyGhError, commentSummaryLine, parseCommentBatch, pickSuggestion, repoStructureNote, countReasons, filterReason, formatGhCall, diagnoseEmptyBody, hasAckLabel, jitterMs, parseGhInclude, retryAfterMs, throttleDelayMs, inActiveHours, newestUpdatedAt, nextDelayMs, enterActiveHoursDefer, permanentBackoffMs, RETRY_BUDGET_ATTEMPTS, RETRY_SLOW_CAP_MINUTES, 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.123'
43
+ export const SERVER_VERSION = '0.9.124'
44
44
  export const inject = ['tools', 'agents', 'webServer']
45
45
  /** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
46
46
  // 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
@@ -323,6 +323,16 @@ function agentsService(ctx) {
323
323
 
324
324
  /** gh CLI 可用性探针:5 分钟缓存,别让面板每 5 秒都 spawn 一次 gh。 */
325
325
  const ghHealthCache = { at: 0, value: null }
326
+ // 只在失败路径上调用:确认凭证到底还有没有效(真机上令牌失效时 gh 输出为空)
327
+ let authStatusCache = { at: 0, text: '' }
328
+ async function ghAuthStatusText() {
329
+ if (Date.now() - authStatusCache.at < 60000 && authStatusCache.text) return authStatusCache.text
330
+ const res = await run('gh', ['auth', 'status'], { timeoutMs: 8000 })
331
+ const text = [res.stdout, res.stderr].filter(Boolean).join(String.fromCharCode(10))
332
+ authStatusCache = { at: Date.now(), text }
333
+ return text
334
+ }
335
+
326
336
  async function ghHealth() {
327
337
  if (Date.now() - ghHealthCache.at < 5 * 60 * 1000 && ghHealthCache.value) return ghHealthCache.value
328
338
  let value
@@ -968,7 +978,22 @@ async function pollOnce(ctx, entry, baseMs) {
968
978
  }
969
979
  if (parsed.etag) entry.etag = parsed.etag
970
980
  let items
971
- try { items = JSON.parse(parsed.body) } catch { setEntryError(entry, '返回内容不是合法 JSON(可能是代理干扰)—— 已按退避自动重试;持续出现请跑 watch_doctor'); bumpFailure(entry, baseMs); return }
981
+ try {
982
+ items = JSON.parse(parsed.body)
983
+ } catch {
984
+ // 空/坏内容:先看凭证,再谈代理 —— 真机上令牌失效时 gh 输出为空,
985
+ // 而原来的文案一律怪「代理干扰」,客户会去查一个不存在的代理。
986
+ const authText = await ghAuthStatusText()
987
+ const diag = diagnoseEmptyBody({ bodyText: parsed.body, authStatusText: authText })
988
+ if (diag && diag.kind === 'auth') entry.needsReauth = true
989
+ setEntryError(entry, (diag ? diag.hint : '(返回内容不是合法 JSON:可能是代理干扰)') + ' —— 已按退避自动重试;持续出现请跑 watch_doctor')
990
+ bumpFailure(entry, diag && diag.kind === 'auth' ? baseMs : baseMs)
991
+ if (diag && diag.kind === 'auth') {
992
+ const wait = permanentBackoffMs('auth', baseMs)
993
+ if (wait > 0) entry.nextAt = new Date(Date.now() + wait).toISOString()
994
+ }
995
+ return
996
+ }
972
997
  if (!Array.isArray(items)) { setEntryError(entry, '返回的数据结构不对(预期是数组)—— 已按退避自动重试;持续出现请跑 watch_doctor'); bumpFailure(entry, baseMs); return }
973
998
 
974
999
  entry.lastError = null
package/lib/watch.js CHANGED
@@ -568,6 +568,7 @@ export {
568
568
  classifyGhError,
569
569
  commentSummaryLine,
570
570
  countReasons,
571
+ diagnoseEmptyBody,
571
572
  formatGhCall,
572
573
  jitterMs,
573
574
  linkedPrNote,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.9.123",
3
+ "version": "0.9.124",
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",