dsh-session-superagent 0.9.131 → 0.9.133

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,58 @@
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.133] - 2026-11-03 —— 系统错误码各归其类;没见过的措辞自动留样本
6
+
7
+ ### 学到什么(出处)
8
+ Node 的系统错误表把每个码的含义写得很具体(本轮用 `gh api` 直接取到 `doc/api/errors.md`):
9
+
10
+ > `EACCES` (Permission denied): An attempt was made to access a file in a way forbidden by its file access permissions.
11
+ > `EPIPE` (Broken pipe): A write on a pipe, socket, or FIFO for which there is no process to read the data.
12
+
13
+ <https://nodejs.org/api/errors.html#common-system-errors>
14
+
15
+ ### 现场
16
+ 这四类原本全落 `other`("没归类的错误:已按退避自动重试"):
17
+
18
+ | 文本 | 改前 | 改后 |
19
+ |---|---|---|
20
+ | `spawn gh EACCES` | other | `permfile`(检查安装权限或重装) |
21
+ | `spawn gh EPERM` | other | `permfile` |
22
+ | `EPIPE: broken pipe` | other | `network`(连接被中断,不需要手动处理) |
23
+ | `ETIMEDOUT connect` | other | `network` |
24
+
25
+ ### 还有一个更根本的问题
26
+ 分类器只认**我们见过的措辞**。没见过的如果只显示"没归类的错误",下次还是收集不到 —— 死循环。
27
+ 所以新增 `recordOtherError()`:`other` 时把原始措辞(≤120 字)记进事件流,最多保留到事件上限。
28
+
29
+ ### 测试
30
+ 新增 2 例:系统错误码分类;`other` 留样本(空内容不记、事件流不无限增长)。合计 **249 例**。
31
+
32
+ ## [0.9.132] - 2026-11-03 —— 代理塞回一个网页时,说清"是网页不是 JSON"
33
+
34
+ ### 真机复验(重启后)
35
+ ```
36
+ serverVersion: 0.9.131
37
+ - MYCF711/dsh-go | 启用 | fails 1 | lastError: (返回内容不是合法 JSON:可能是代理干扰)
38
+ - MYCF711/dsh-go | 已暂停 | fails 0 | lastError: 无 ← 0.9.130 的归一在真机上生效了
39
+ ```
40
+
41
+ 紧跟着手动跑一次 `gh api --include ...`:`HTTP/2.0 200 OK` + body `[]`(2 字节)—— 说明网络此刻是通的,
42
+ 那条错误是代理 502 期间留下的。
43
+
44
+ ### 学到什么 / 改了什么
45
+ 1. **坏 body 也要分类**:新增 `diagnoseBadBody()` —— 有内容但不是 JSON 时,
46
+ 若像 HTML/网关页(`<!DOCTYPE`、`<body`、`Bad Gateway`…)→ 归 `gateway`,
47
+ 提示「**返回的是网页而不是 JSON:本地代理/网关拦了请求 —— 检查代理设置**」;
48
+ 2. **限流要等够一分钟**:GitHub 对 secondary/abuse 限流要求至少等 1 分钟,
49
+ 服务端没给 `Retry-After` 时现在我们兜底 60 秒(此前会立刻重试);
50
+ 3. 顺带修一个**自己刚写出的 bug**:先算了 `wait` 才定义 `classified`,
51
+ 会在每次失败时抛 `ReferenceError` —— 已把分类提到最前(注释里记了这次顺序错误);
52
+ 4. `deferReason` 直接用分类名(此前 auth 也会被写成 `notfound`)。
53
+
54
+ ### 测试
55
+ 新增 1 例(HTML 坏 body → gateway;合法 JSON 不报;空内容仍先判凭证)。合计 **247 例**。
56
+
5
57
  ## [0.9.131] - 2026-11-03 —— 403 被我们一律当成"限流",其实一半是权限问题
6
58
 
7
59
  ### 学到什么(出处)
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.131-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.9.133-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 # 246 项单测
126
+ node --test # 249 项单测
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.131'
17
+ const CLIENT_VERSION = '0.9.133'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
package/lib/gh-format.js CHANGED
@@ -18,6 +18,18 @@
18
18
  export function isAuthBroken(authStatusText) {
19
19
  return /token in keyring is invalid|Failed to log in|Bad credentials|requires authentication/i.test(String(authStatusText || ''))
20
20
  }
21
+ export function diagnoseBadBody({ bodyText, authStatusText } = {}) {
22
+ const body = String(bodyText ?? '').trim()
23
+ // 有内容但不是 JSON:最可能是代理/网关把请求拦了,返回它自己的网页
24
+ if (body.length > 0) {
25
+ if (/^<(!doctype|html)|<body|Bad Gateway|Service Unavailable|Gateway Time-?out/i.test(body)) {
26
+ return { kind: 'gateway', hint: '(返回的是网页而不是 JSON:本地代理/网关拦了请求 —— 检查代理设置)' }
27
+ }
28
+ return null
29
+ }
30
+ return diagnoseEmptyBody({ bodyText, authStatusText })
31
+ }
32
+
21
33
  export function diagnoseEmptyBody({ bodyText, authStatusText } = {}) {
22
34
  const body = String(bodyText ?? '').trim()
23
35
  if (body.length > 0) return null
@@ -71,6 +83,14 @@ export function classifyGhError(detail) {
71
83
  if (/HTTP 50[0234]|Bad Gateway|Service Unavailable|Gateway Time-?out/i.test(text)) {
72
84
  return { kind: 'gateway', short, hint: '(GitHub 或本地代理短暂故障:已按退避自动重试,不需要手动处理;持续出现就检查代理)' }
73
85
  }
86
+ // 系统级错误码:含义与动作各不相同(找不到文件 / 没权限 / 管道断了 / 超时)
87
+ // 出处:https://nodejs.org/api/errors.html#common-system-errors
88
+ if (/EACCES|EPERM/i.test(text)) {
89
+ return { kind: 'permfile', short, hint: '(gh 没有执行权限:检查安装权限或重装 gh)' }
90
+ }
91
+ if (/EPIPE|ETIMEDOUT|ECONNRESET|socket hang up/i.test(text)) {
92
+ return { kind: 'network', short, hint: '(连接被中断:网络或代理不稳,已按退避自动重试,不需要手动处理)' }
93
+ }
74
94
  // Windows 的 cmd 报法不一样:'gh' is not recognized as an internal or external command
75
95
  // 出处(Node 的错误码语义):https://nodejs.org/api/errors.html#common-system-errors
76
96
  if (/ENOENT|not found.*gh|gh: command not found|not recognized as an internal or external command/i.test(text)) {
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, diagnoseEmptyBody, isAuthBroken, 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, 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,
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.131'
43
+ export const SERVER_VERSION = '0.9.133'
44
44
  export const inject = ['tools', 'agents', 'webServer']
45
45
  /** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
46
46
  // 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
@@ -936,30 +936,31 @@ async function pollOnce(ctx, entry, baseMs) {
936
936
  noteEvent(entry, 'unchanged', entry.lastDeferred)
937
937
  return
938
938
  }
939
- // 先看是不是被限流:GH 的 secondary limit 会给 Retry-After,照它等最准
939
+ // 先分类,再决定等多久 —— 顺序反了会引用到未定义的变量(本轮自己踩过)
940
+ const detail = redact(res.stderr).slice(0, 240)
941
+ const classified = classifyGhError(detail)
940
942
  const failure = parseGhInclude(res.stdout)
941
- const wait = retryAfterMs(failure.retryAfter)
943
+ // secondary/abuse 限流:文档要求至少等一分钟;服务端给了 Retry-After 就按它等
944
+ const wait = retryAfterMs(failure.retryAfter) || (classified.kind === 'ratelimit' ? 60 * 1000 : 0)
942
945
  if (wait > 0) {
943
946
  entry.nextAt = new Date(Date.now() + wait).toISOString()
944
947
  entry.lastDeferred = '被 GitHub 限流,按 Retry-After 等 ' + Math.round(wait / 1000) + ' 秒'
945
- entry.deferReason = 'ratelimit'
946
- noteEvent(entry, 'ratelimit', entry.lastDeferred)
948
+ entry.deferReason = 'ratelimit'
949
+ noteEvent(entry, 'ratelimit', entry.lastDeferred)
947
950
  entry.lastError = null
948
951
  entry.needsReauth = false
949
952
  return
950
953
  }
951
- const detail = redact(res.stderr).slice(0, 240)
952
- // 常见失败给一句能照着做的提示,别只丢原始 stderr
953
- const classified = classifyGhError(detail)
954
954
  setEntryError(entry, (classified.short + classified.hint).slice(0, 300))
955
955
  bumpFailure(entry, baseMs)
956
- // 永久性错误(404 / 仓库改名)不要按普通退避重试:至少等半小时
957
956
  // 凭证问题要显式标出来:它不会自己恢复,客户必须去 gh auth login
958
957
  if (classified.kind === 'auth') entry.needsReauth = true
958
+ // 没见过的措辞:留样本,下一轮才好补分类规则
959
+ if (classified.kind === 'other') recordOtherError(entry, detail)
959
960
  const permanent = permanentBackoffMs(classified.kind, baseMs)
960
961
  if (permanent > 0) {
961
962
  entry.nextAt = new Date(Date.now() + permanent).toISOString()
962
- entry.deferReason = classified.kind === 'moved' ? 'moved' : 'notfound'
963
+ entry.deferReason = classified.kind
963
964
  }
964
965
  return
965
966
  }
@@ -1011,7 +1012,7 @@ async function pollOnce(ctx, entry, baseMs) {
1011
1012
  // 空/坏内容:先看凭证,再谈代理 —— 真机上令牌失效时 gh 输出为空,
1012
1013
  // 而原来的文案一律怪「代理干扰」,客户会去查一个不存在的代理。
1013
1014
  const authText = await ghAuthStatusText()
1014
- const diag = diagnoseEmptyBody({ bodyText: parsed.body, authStatusText: authText })
1015
+ const diag = diagnoseBadBody({ bodyText: parsed.body, authStatusText: authText })
1015
1016
  if (diag && diag.kind === 'auth') entry.needsReauth = true
1016
1017
  setEntryError(entry, (diag ? diag.hint : '(返回内容不是合法 JSON:可能是代理干扰)') + ' —— 已按退避自动重试;持续出现请跑 watch_doctor')
1017
1018
  bumpFailure(entry, diag && diag.kind === 'auth' ? baseMs : baseMs)
package/lib/watch.js CHANGED
@@ -325,6 +325,18 @@ export function batchFresh(fresh, limit = 3, priority) {
325
325
  * 为什么:时段外根本不轮询,旧的 lastError 会一直挂着,面板上就变成一条永不消停的「异常」。
326
326
  * 依据同 paused-means-no-new-facts:不再更新的状态不该继续代表「现在」。
327
327
  */
328
+ /**
329
+ * 未归类的错误:把原始措辞留一份样本(最多 3 条)到事件流。
330
+ *
331
+ * 为什么:分类器只认我们见过的措辞。没见过的如果只显示「没归类的错误」,
332
+ * 下次还是收集不到 —— 让它在事件流里留个样本,下一轮才能补规则。
333
+ */
334
+ export function recordOtherError(entry, detail) {
335
+ const text = String(detail || '').trim().slice(0, 120)
336
+ if (!text) return entry
337
+ entry.events = pushEvent(entry.events, { kind: 'other', text })
338
+ return entry
339
+ }
328
340
  export function enterActiveHoursDefer(entry, waitMs, hours, at = new Date()) {
329
341
  entry.nextAt = new Date(at.getTime() + Number(waitMs || 0)).toISOString()
330
342
  entry.lastDeferred = `不在活跃时段(${hours}),${Math.round(Number(waitMs || 0) / 60000)} 分钟后开始`
@@ -570,6 +582,7 @@ export {
570
582
  countReasons,
571
583
  isAuthBroken,
572
584
  diagnoseEmptyBody,
585
+ diagnoseBadBody,
573
586
  formatGhCall,
574
587
  jitterMs,
575
588
  linkedPrNote,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.9.131",
3
+ "version": "0.9.133",
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",