dsh-session-superagent 0.9.130 → 0.9.132
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 +57 -0
- package/README.md +2 -2
- package/client.js +2 -1
- package/lib/gh-format.js +18 -1
- package/lib/index.js +11 -12
- package/lib/watch.js +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,63 @@
|
|
|
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.132] - 2026-11-03 —— 代理塞回一个网页时,说清"是网页不是 JSON"
|
|
6
|
+
|
|
7
|
+
### 真机复验(重启后)
|
|
8
|
+
```
|
|
9
|
+
serverVersion: 0.9.131
|
|
10
|
+
- MYCF711/dsh-go | 启用 | fails 1 | lastError: (返回内容不是合法 JSON:可能是代理干扰)
|
|
11
|
+
- MYCF711/dsh-go | 已暂停 | fails 0 | lastError: 无 ← 0.9.130 的归一在真机上生效了
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
紧跟着手动跑一次 `gh api --include ...`:`HTTP/2.0 200 OK` + body `[]`(2 字节)—— 说明网络此刻是通的,
|
|
15
|
+
那条错误是代理 502 期间留下的。
|
|
16
|
+
|
|
17
|
+
### 学到什么 / 改了什么
|
|
18
|
+
1. **坏 body 也要分类**:新增 `diagnoseBadBody()` —— 有内容但不是 JSON 时,
|
|
19
|
+
若像 HTML/网关页(`<!DOCTYPE`、`<body`、`Bad Gateway`…)→ 归 `gateway`,
|
|
20
|
+
提示「**返回的是网页而不是 JSON:本地代理/网关拦了请求 —— 检查代理设置**」;
|
|
21
|
+
2. **限流要等够一分钟**:GitHub 对 secondary/abuse 限流要求至少等 1 分钟,
|
|
22
|
+
服务端没给 `Retry-After` 时现在我们兜底 60 秒(此前会立刻重试);
|
|
23
|
+
3. 顺带修一个**自己刚写出的 bug**:先算了 `wait` 才定义 `classified`,
|
|
24
|
+
会在每次失败时抛 `ReferenceError` —— 已把分类提到最前(注释里记了这次顺序错误);
|
|
25
|
+
4. `deferReason` 直接用分类名(此前 auth 也会被写成 `notfound`)。
|
|
26
|
+
|
|
27
|
+
### 测试
|
|
28
|
+
新增 1 例(HTML 坏 body → gateway;合法 JSON 不报;空内容仍先判凭证)。合计 **247 例**。
|
|
29
|
+
|
|
30
|
+
## [0.9.131] - 2026-11-03 —— 403 被我们一律当成"限流",其实一半是权限问题
|
|
31
|
+
|
|
32
|
+
### 学到什么(出处)
|
|
33
|
+
GitHub 排障文档里 403 有两种截然不同的含义,其中一个专节叫 **"Resource not accessible"**:
|
|
34
|
+
- 限流 → 等着就行;
|
|
35
|
+
- **权限不足 / 集成无权访问** → 要改 token 作用域或仓库权限。
|
|
36
|
+
|
|
37
|
+
<https://docs.github.com/en/rest/using-the-rest-api/troubleshooting-the-rest-api#resource-not-accessible>
|
|
38
|
+
|
|
39
|
+
### 现场
|
|
40
|
+
我们的分类器只有一条:
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
if (/HTTP 403|rate limit|API rate limit exceeded/i.test(text)) return { kind: 'ratelimit', … }
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
于是 `HTTP 403: Resource not accessible by integration` 会显示「被 GitHub 限流:等几分钟」——
|
|
47
|
+
客户会一直等,而真正要做的是去加权限。**又是"等一等"与"动手修"的混淆。**
|
|
48
|
+
|
|
49
|
+
### 改法
|
|
50
|
+
1. 先判限流关键词(`rate limit` / `secondary rate limit` / `abuse detection`);
|
|
51
|
+
2. 其余 403 归新分类 `permission`:`(权限不足:检查 token 作用域或这个仓库的访问权限)`;
|
|
52
|
+
3. 面板给 `permission` 配按钮「去填 token」(指向设置页)。
|
|
53
|
+
|
|
54
|
+
### 测试
|
|
55
|
+
新增 1 例:403 限流 / `Resource not accessible` / `Must have admin rights` 三种文本各归其类。
|
|
56
|
+
合计 **246 例**。
|
|
57
|
+
|
|
58
|
+
### 说明
|
|
59
|
+
`gh api` 本轮可用过一阵(成功取到文档大小与 base64 片段),随后再次不可达;
|
|
60
|
+
上面的判据来自本会话早前成功抓取的同一份文档。
|
|
61
|
+
|
|
5
62
|
## [0.9.130] - 2026-11-03 —— 重启后真机复验:新代码生效了,但"暂停的守还挂着旧错误"
|
|
6
63
|
|
|
7
64
|
### 真机复验(重启后)
|
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)
|
|
6
|
-
[](https://github.com/MYCF711/dsh-session-superagent/releases)
|
|
7
7
|
[](https://www.npmjs.com/package/dsh-session-superagent)
|
|
8
8
|
[](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 #
|
|
126
|
+
node --test # 247 项单测
|
|
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.
|
|
17
|
+
const CLIENT_VERSION = '0.9.132'
|
|
18
18
|
let BASE = '/session-superagent'
|
|
19
19
|
/**
|
|
20
20
|
* 挑「最新的那个服务端实例」。
|
|
@@ -1120,6 +1120,7 @@ window.__ModuleLoader__.load({
|
|
|
1120
1120
|
auth: { label: '去填 token', onClick: () => setTab('settings') },
|
|
1121
1121
|
moved: { label: '改仓库地址', onClick: () => setTab('trigger') },
|
|
1122
1122
|
notfound: { label: '改仓库地址', onClick: () => setTab('trigger') },
|
|
1123
|
+
permission: { label: '去填 token', onClick: () => setTab('settings') },
|
|
1123
1124
|
network: { label: '立刻重试', onClick: () => act(watcher, 'poll') },
|
|
1124
1125
|
ratelimit: { label: '立刻重试', onClick: () => act(watcher, 'poll') },
|
|
1125
1126
|
gateway: { label: '立刻重试', onClick: () => act(watcher, 'poll') },
|
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
|
|
@@ -60,9 +72,14 @@ export function classifyGhError(detail) {
|
|
|
60
72
|
if (/HTTP 401|Bad credentials|requires authentication/i.test(text)) {
|
|
61
73
|
return { kind: 'auth', short, hint: '(gh 登录失效:跑 gh auth login,或在面板填 token)' }
|
|
62
74
|
}
|
|
63
|
-
|
|
75
|
+
// 403 有两种完全不同的意思:限流(等着就行)与权限不足(要改 token/仓库设置)。
|
|
76
|
+
// 出处:https://docs.github.com/en/rest/using-the-rest-api/troubleshooting-the-rest-api#resource-not-accessible
|
|
77
|
+
if (/rate limit|secondary rate limit|abuse detection|API rate limit exceeded/i.test(text)) {
|
|
64
78
|
return { kind: 'ratelimit', short, hint: '(被 GitHub 限流:等几分钟,或换成带 token 的凭证)' }
|
|
65
79
|
}
|
|
80
|
+
if (/HTTP 403|Resource not accessible|Must have admin rights|not have permission|forbidden/i.test(text)) {
|
|
81
|
+
return { kind: 'permission', short, hint: '(权限不足:检查 token 作用域或这个仓库的访问权限)' }
|
|
82
|
+
}
|
|
66
83
|
if (/HTTP 50[0234]|Bad Gateway|Service Unavailable|Gateway Time-?out/i.test(text)) {
|
|
67
84
|
return { kind: 'gateway', short, hint: '(GitHub 或本地代理短暂故障:已按退避自动重试,不需要手动处理;持续出现就检查代理)' }
|
|
68
85
|
}
|
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, 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.
|
|
43
|
+
export const SERVER_VERSION = '0.9.132'
|
|
44
44
|
export const inject = ['tools', 'agents', 'webServer']
|
|
45
45
|
/** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
|
|
46
46
|
// 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
|
|
@@ -936,30 +936,29 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
936
936
|
noteEvent(entry, 'unchanged', entry.lastDeferred)
|
|
937
937
|
return
|
|
938
938
|
}
|
|
939
|
-
//
|
|
939
|
+
// 先分类,再决定等多久 —— 顺序反了会引用到未定义的变量(本轮自己踩过)
|
|
940
|
+
const detail = redact(res.stderr).slice(0, 240)
|
|
941
|
+
const classified = classifyGhError(detail)
|
|
940
942
|
const failure = parseGhInclude(res.stdout)
|
|
941
|
-
|
|
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
|
-
|
|
946
|
-
|
|
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
|
|
959
958
|
const permanent = permanentBackoffMs(classified.kind, baseMs)
|
|
960
959
|
if (permanent > 0) {
|
|
961
960
|
entry.nextAt = new Date(Date.now() + permanent).toISOString()
|
|
962
|
-
entry.deferReason = classified.kind
|
|
961
|
+
entry.deferReason = classified.kind
|
|
963
962
|
}
|
|
964
963
|
return
|
|
965
964
|
}
|
|
@@ -1011,7 +1010,7 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
1011
1010
|
// 空/坏内容:先看凭证,再谈代理 —— 真机上令牌失效时 gh 输出为空,
|
|
1012
1011
|
// 而原来的文案一律怪「代理干扰」,客户会去查一个不存在的代理。
|
|
1013
1012
|
const authText = await ghAuthStatusText()
|
|
1014
|
-
const diag =
|
|
1013
|
+
const diag = diagnoseBadBody({ bodyText: parsed.body, authStatusText: authText })
|
|
1015
1014
|
if (diag && diag.kind === 'auth') entry.needsReauth = true
|
|
1016
1015
|
setEntryError(entry, (diag ? diag.hint : '(返回内容不是合法 JSON:可能是代理干扰)') + ' —— 已按退避自动重试;持续出现请跑 watch_doctor')
|
|
1017
1016
|
bumpFailure(entry, diag && diag.kind === 'auth' ? baseMs : baseMs)
|
package/lib/watch.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-superagent",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.132",
|
|
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",
|