dsh-session-superagent 0.9.122 → 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 +55 -0
- package/README.md +2 -2
- package/client.js +7 -2
- package/lib/gh-format.js +17 -0
- package/lib/index.js +29 -3
- package/lib/watch.js +4 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,61 @@
|
|
|
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
|
+
|
|
36
|
+
## [0.9.123] - 2026-11-03 —— 「已放慢到 2 小时档」不该是写死的文案
|
|
37
|
+
|
|
38
|
+
### 学到什么(出处)
|
|
39
|
+
Kubernetes Job 的做法:重试策略写在 `spec`(`backoffLimit`、退避上限),**状态由控制器按它算出来再写进 `status`**:
|
|
40
|
+
|
|
41
|
+
> The `.spec.backoffLimit` is set by default to 6 … The number of retries is calculated in two ways …
|
|
42
|
+
|
|
43
|
+
<https://kubernetes.io/docs/concepts/workloads/controllers/job/>
|
|
44
|
+
|
|
45
|
+
政策只有一处定义,派生的数字另算 —— 而不是在 UI 里再抄一份。
|
|
46
|
+
|
|
47
|
+
### 现场
|
|
48
|
+
0.9.122 的面板写着「已放慢到 **2 小时**档」,而这个 2 小时是 `nextDelayMs` 里的字面量。
|
|
49
|
+
一旦有人把上限改成 90 分钟(或把预算从 6 改掉),**这句话立刻变成谎话,而且没有任何门禁会红**。
|
|
50
|
+
|
|
51
|
+
### 改法
|
|
52
|
+
1. `lib/watch.js` 导出 `RETRY_SLOW_CAP_MINUTES = 120`,`nextDelayMs` 用它算上限;
|
|
53
|
+
2. `/state` 顶层新增 `retryPolicy: { budgetAttempts, slowCapMinutes }`(一次请求,逐守可用);
|
|
54
|
+
3. 面板的档位文案由这三个数字算出来(≥60 分钟显示小时,否则显示分钟)。
|
|
55
|
+
|
|
56
|
+
### 测试
|
|
57
|
+
新增 1 例:默认 → 「2 小时档」;改成 90 分钟 → 「1.5 小时档」;预算调到 20 → 8 次失败**不该**说"已放慢"。
|
|
58
|
+
合计 **233 例**。
|
|
59
|
+
|
|
5
60
|
## [0.9.122] - 2026-11-03 —— 面板上写出「第几次失败 + 下次什么时候重试」
|
|
6
61
|
|
|
7
62
|
### 学到什么(出处)
|
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 # 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.
|
|
17
|
+
const CLIENT_VERSION = '0.9.124'
|
|
18
18
|
let BASE = '/session-superagent'
|
|
19
19
|
/**
|
|
20
20
|
* 挑「最新的那个服务端实例」。
|
|
@@ -1100,7 +1100,12 @@ window.__ModuleLoader__.load({
|
|
|
1100
1100
|
const wait = Math.max(0, Date.now() - Date.parse(watcher.nextAt))
|
|
1101
1101
|
const left = Date.parse(watcher.nextAt) - Date.now()
|
|
1102
1102
|
const mins = Math.max(0, Math.round((left > 0 ? left : wait) / 60000))
|
|
1103
|
-
|
|
1103
|
+
// 档位文案从后端给的 retryPolicy 算:写死「2 小时」会在有人改常量后变成谎话
|
|
1104
|
+
const policy = (body && body.retryPolicy) || {}
|
|
1105
|
+
const budget = Number(policy.budgetAttempts) || 6
|
|
1106
|
+
const capMin = Number(policy.slowCapMinutes) || 120
|
|
1107
|
+
const capText = capMin >= 60 ? (capMin / 60) + ' 小时' : capMin + ' 分钟'
|
|
1108
|
+
const slow = fails >= budget ? '(已放慢到 ' + capText + '档)' : ''
|
|
1104
1109
|
return h('div', { className: 'dt-hint' },
|
|
1105
1110
|
'已连续失败 ' + fails + ' 次 · ' + (left > 0 ? '下次重试约 ' + mins + ' 分钟后' : '等待重试') + slow)
|
|
1106
1111
|
})(),
|
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, 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.
|
|
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 {
|
|
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
|
|
@@ -1410,6 +1435,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
1410
1435
|
tokenScopes: scopesCache.value || null,
|
|
1411
1436
|
isolation: isolationReport(Object.values(state.watchers || {})),
|
|
1412
1437
|
sessionTitle: sessionTitle(focusSession),
|
|
1438
|
+
retryPolicy: { budgetAttempts: RETRY_BUDGET_ATTEMPTS, slowCapMinutes: RETRY_SLOW_CAP_MINUTES },
|
|
1413
1439
|
watchers: watchers.map((w) => ({ ...w, goal: goalView(ctx, w.sessionId) })),
|
|
1414
1440
|
}
|
|
1415
1441
|
// ETag/304:面板每 5 秒拉一次 /state,没变化时没必要重传整份 JSON ——
|
package/lib/watch.js
CHANGED
|
@@ -350,13 +350,15 @@ export function permanentBackoffMs(kind, baseMs = 60000) {
|
|
|
350
350
|
* 出处:https://sre.google/sre-book/handling-overload/
|
|
351
351
|
*/
|
|
352
352
|
export const RETRY_BUDGET_ATTEMPTS = 6
|
|
353
|
+
// 预算外的等待上限(分钟):面板上的「已放慢到 X 小时档」从这里算,不再写死文案
|
|
354
|
+
export const RETRY_SLOW_CAP_MINUTES = 120
|
|
353
355
|
export function nextDelayMs(entry, baseMs) {
|
|
354
356
|
const failures = Number((entry && entry.consecutiveFailures) || 0)
|
|
355
357
|
if (failures <= 0) return baseMs
|
|
356
358
|
const overBudget = failures >= RETRY_BUDGET_ATTEMPTS
|
|
357
359
|
// 预算内:最多 60 倍(默认 60s 间隔 → 1 小时);超出预算:最多 120 倍(→ 2 小时)
|
|
358
360
|
const factor = Math.min(2 ** failures, overBudget ? 120 : 60)
|
|
359
|
-
const cap = overBudget ?
|
|
361
|
+
const cap = overBudget ? RETRY_SLOW_CAP_MINUTES * 60 * 1000 : 30 * 60 * 1000
|
|
360
362
|
return Math.min(Math.max(baseMs * factor, baseMs), cap)
|
|
361
363
|
}
|
|
362
364
|
|
|
@@ -566,6 +568,7 @@ export {
|
|
|
566
568
|
classifyGhError,
|
|
567
569
|
commentSummaryLine,
|
|
568
570
|
countReasons,
|
|
571
|
+
diagnoseEmptyBody,
|
|
569
572
|
formatGhCall,
|
|
570
573
|
jitterMs,
|
|
571
574
|
linkedPrNote,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-superagent",
|
|
3
|
-
"version": "0.9.
|
|
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",
|