dsh-session-superagent 0.9.123 → 0.9.125
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 +60 -0
- package/README.md +2 -2
- package/client.js +1 -1
- package/lib/gh-format.js +21 -0
- package/lib/index.js +39 -4
- package/lib/watch.js +2 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,66 @@
|
|
|
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.125] - 2026-11-03 —— 凭证坏了就别再发请求:断路器式短路
|
|
6
|
+
|
|
7
|
+
### 学到什么(出处)
|
|
8
|
+
Martin Fowler《CircuitBreaker》:
|
|
9
|
+
|
|
10
|
+
> Once the failures reach a certain threshold, the circuit breaker trips, and **all further calls to the
|
|
11
|
+
> circuit breaker return with an error, without the protected call being made at all.**
|
|
12
|
+
|
|
13
|
+
<https://martinfowler.com/bliki/CircuitBreaker.html>
|
|
14
|
+
|
|
15
|
+
我们上一版(0.9.124)已经把"凭证失效"识别出来了,但**只有轮询路径**用它:
|
|
16
|
+
`github` 工具和 `repo_here` 仍然会照常 spawn `gh`,拿到空内容再走一遍诊断 —— 这就是"明知会失败还去调"。
|
|
17
|
+
|
|
18
|
+
### 改法
|
|
19
|
+
1. 抽出 `isAuthBroken()`(`diagnoseEmptyBody` 复用它,避免两处正则各写一份);
|
|
20
|
+
2. `gh auth status` 的结论缓存 60 秒,`github` / `repo_here` 在**已知凭证失效**时直接返回:
|
|
21
|
+
`[error: 凭证已失效,本次没有发起请求] 跑 gh auth login 重新登录后再试`
|
|
22
|
+
3. 缓存为空/过期时照常调用。
|
|
23
|
+
|
|
24
|
+
### 真机背景(本轮实测)
|
|
25
|
+
```
|
|
26
|
+
- MYCF711/dsh-go | fails 4 | nextAt 2026-11-03T02:40:27.997Z
|
|
27
|
+
lastError: gh: HTTP 502(GitHub 或本地代理短暂故障)
|
|
28
|
+
```
|
|
29
|
+
外部网络此刻也不健康(502),所以"不发起这次调用"对客户更友好:少一次必然失败的进程。
|
|
30
|
+
|
|
31
|
+
### 测试
|
|
32
|
+
新增 1 例:缓存里是失效结论 → 两个工具短路且提示修复动作;清空缓存 → 恢复调用。合计 **235 例**。
|
|
33
|
+
|
|
34
|
+
## [0.9.124] - 2026-11-03 —— 真机实测:令牌失效时我们却在怪代理
|
|
35
|
+
|
|
36
|
+
### 现场(09:00 时段开门后的真实轮询)
|
|
37
|
+
```
|
|
38
|
+
serverVersion: 0.9.116
|
|
39
|
+
- MYCF711/dsh-go | 启用 | 失败 5 | nextAt 2026-11-03T01:30:27.698Z
|
|
40
|
+
lastError: 返回内容不是合法 JSON(可能是代理干扰)—— 已按退避自动重试
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
时段一到它确实开始轮询了(`nextAt` 排到 09:30),但**失败原因写错了**:
|
|
44
|
+
真实原因是 `gh` 令牌失效 → 输出为空 → `JSON.parse('')` 抛错,于是我们甩锅给"代理"。
|
|
45
|
+
客户会去查一个根本不存在的代理,而真正要做的是 `gh auth login`。
|
|
46
|
+
|
|
47
|
+
### 学到什么(出处)
|
|
48
|
+
GitHub 排障文档在"结果不对"时要求先确认凭证:
|
|
49
|
+
|
|
50
|
+
> If you are using pagination correctly and still do not see all of the results that you expect,
|
|
51
|
+
> you should **confirm that the authentication credentials** that you used have access…
|
|
52
|
+
|
|
53
|
+
<https://docs.github.com/en/rest/using-the-rest-api/troubleshooting-the-rest-api#missing-results>
|
|
54
|
+
|
|
55
|
+
### 改法
|
|
56
|
+
1. 新增纯函数 `diagnoseEmptyBody({ bodyText, authStatusText })`:
|
|
57
|
+
- 空内容 + 凭证失效 → `auth`(提示 `gh auth login`);
|
|
58
|
+
- 空内容 + 凭证正常 → `empty`(提示可能是代理/未登录,去看 `watch_doctor`);
|
|
59
|
+
2. 解析失败时先跑一次 `gh auth status`(60 秒缓存,只在失败路径);
|
|
60
|
+
3. 判为 `auth` 时置 `needsReauth = true` 并走 30 分钟退避。
|
|
61
|
+
|
|
62
|
+
### 测试
|
|
63
|
+
新增 1 例(空 + 凭证失效 → auth;空 + 凭证正常 → empty;有内容 → 不诊断)。合计 **234 例**。
|
|
64
|
+
|
|
5
65
|
## [0.9.123] - 2026-11-03 —— 「已放慢到 2 小时档」不该是写死的文案
|
|
6
66
|
|
|
7
67
|
### 学到什么(出处)
|
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 # 235 项单测
|
|
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.125'
|
|
18
18
|
let BASE = '/session-superagent'
|
|
19
19
|
/**
|
|
20
20
|
* 挑「最新的那个服务端实例」。
|
package/lib/gh-format.js
CHANGED
|
@@ -6,6 +6,27 @@
|
|
|
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
|
+
/** 凭证是否已失效(`gh auth status` 的输出判定)。抽出来给所有入口共用。 */
|
|
18
|
+
export function isAuthBroken(authStatusText) {
|
|
19
|
+
return /token in keyring is invalid|Failed to log in|Bad credentials|requires authentication/i.test(String(authStatusText || ''))
|
|
20
|
+
}
|
|
21
|
+
export function diagnoseEmptyBody({ bodyText, authStatusText } = {}) {
|
|
22
|
+
const body = String(bodyText ?? '').trim()
|
|
23
|
+
if (body.length > 0) return null
|
|
24
|
+
const auth = String(authStatusText ?? '')
|
|
25
|
+
if (isAuthBroken(auth)) {
|
|
26
|
+
return { kind: 'auth', hint: '(gh 没有返回内容,且凭证已失效:跑 gh auth login 重新登录)' }
|
|
27
|
+
}
|
|
28
|
+
return { kind: 'empty', hint: '(gh 没有返回内容:可能是代理拦截或未登录 —— 跑 watch_doctor 看凭证)' }
|
|
29
|
+
}
|
|
9
30
|
/**
|
|
10
31
|
* 把 `gh` 调用的结果整理成给 agent 看的一段文本。
|
|
11
32
|
*
|
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, 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.125'
|
|
44
44
|
export const inject = ['tools', 'agents', 'webServer']
|
|
45
45
|
/** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
|
|
46
46
|
// 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
|
|
@@ -51,6 +51,8 @@ function setEntryError(entry, text) {
|
|
|
51
51
|
entry.lastError = text
|
|
52
52
|
entry.lastErrorAt = new Date().toISOString()
|
|
53
53
|
}
|
|
54
|
+
// 凭证失效时两个工具必须给一模一样的话:写两遍迟早会漂
|
|
55
|
+
const AUTH_BROKEN_REPLY = '[error: 凭证已失效,本次没有发起请求] 跑 gh auth login 重新登录后再试'
|
|
54
56
|
const UNCHANGED_TEXT = '未变化(304,不计入速率限制)'
|
|
55
57
|
// 追溯找不到任何痕迹时的那句话:两个入口(工具 / HTTP)必须一模一样
|
|
56
58
|
const noTraceText = (number, scope) => '#' + number + ' 在' + (scope || '所有守') + ' 里都没有痕迹 —— 可能还没被轮询到,或者编号写错了。'
|
|
@@ -62,7 +64,7 @@ const MAX_WATCHERS_PER_SESSION = 20
|
|
|
62
64
|
const CLEANUP_INTERVAL_MS = 10 * 60 * 1000
|
|
63
65
|
|
|
64
66
|
/** 仅供测试:读写状态文件(生产代码不要用)。 */
|
|
65
|
-
export const __test = { readState, writeState, hardenSecretsFile, wakeMerged }
|
|
67
|
+
export const __test = { readState, writeState, hardenSecretsFile, wakeMerged, setAuthStatusCache: (text) => { authStatusCache = { at: text ? Date.now() : 0, text } } }
|
|
66
68
|
|
|
67
69
|
const STATE_DIR = process.env.DSH_SUPERAGENT_STATE
|
|
68
70
|
? String(process.env.DSH_SUPERAGENT_STATE)
|
|
@@ -323,6 +325,16 @@ function agentsService(ctx) {
|
|
|
323
325
|
|
|
324
326
|
/** gh CLI 可用性探针:5 分钟缓存,别让面板每 5 秒都 spawn 一次 gh。 */
|
|
325
327
|
const ghHealthCache = { at: 0, value: null }
|
|
328
|
+
// 只在失败路径上调用:确认凭证到底还有没有效(真机上令牌失效时 gh 输出为空)
|
|
329
|
+
let authStatusCache = { at: 0, text: '' }
|
|
330
|
+
async function ghAuthStatusText() {
|
|
331
|
+
if (Date.now() - authStatusCache.at < 60000 && authStatusCache.text) return authStatusCache.text
|
|
332
|
+
const res = await run('gh', ['auth', 'status'], { timeoutMs: 8000 })
|
|
333
|
+
const text = [res.stdout, res.stderr].filter(Boolean).join(String.fromCharCode(10))
|
|
334
|
+
authStatusCache = { at: Date.now(), text }
|
|
335
|
+
return text
|
|
336
|
+
}
|
|
337
|
+
|
|
326
338
|
async function ghHealth() {
|
|
327
339
|
if (Date.now() - ghHealthCache.at < 5 * 60 * 1000 && ghHealthCache.value) return ghHealthCache.value
|
|
328
340
|
let value
|
|
@@ -968,7 +980,22 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
968
980
|
}
|
|
969
981
|
if (parsed.etag) entry.etag = parsed.etag
|
|
970
982
|
let items
|
|
971
|
-
try {
|
|
983
|
+
try {
|
|
984
|
+
items = JSON.parse(parsed.body)
|
|
985
|
+
} catch {
|
|
986
|
+
// 空/坏内容:先看凭证,再谈代理 —— 真机上令牌失效时 gh 输出为空,
|
|
987
|
+
// 而原来的文案一律怪「代理干扰」,客户会去查一个不存在的代理。
|
|
988
|
+
const authText = await ghAuthStatusText()
|
|
989
|
+
const diag = diagnoseEmptyBody({ bodyText: parsed.body, authStatusText: authText })
|
|
990
|
+
if (diag && diag.kind === 'auth') entry.needsReauth = true
|
|
991
|
+
setEntryError(entry, (diag ? diag.hint : '(返回内容不是合法 JSON:可能是代理干扰)') + ' —— 已按退避自动重试;持续出现请跑 watch_doctor')
|
|
992
|
+
bumpFailure(entry, diag && diag.kind === 'auth' ? baseMs : baseMs)
|
|
993
|
+
if (diag && diag.kind === 'auth') {
|
|
994
|
+
const wait = permanentBackoffMs('auth', baseMs)
|
|
995
|
+
if (wait > 0) entry.nextAt = new Date(Date.now() + wait).toISOString()
|
|
996
|
+
}
|
|
997
|
+
return
|
|
998
|
+
}
|
|
972
999
|
if (!Array.isArray(items)) { setEntryError(entry, '返回的数据结构不对(预期是数组)—— 已按退避自动重试;持续出现请跑 watch_doctor'); bumpFailure(entry, baseMs); return }
|
|
973
1000
|
|
|
974
1001
|
entry.lastError = null
|
|
@@ -2113,6 +2140,10 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2113
2140
|
if (write && args.confirm !== true) {
|
|
2114
2141
|
return `[error: ${method} requires confirm: true — this plugin never writes to GitHub without an explicit flag]`
|
|
2115
2142
|
}
|
|
2143
|
+
// 已知凭证失效时不再 spawn:Fowler 的断路器就是「不发起这次受保护的调用」
|
|
2144
|
+
if (isAuthBroken(authStatusCache.text) && Date.now() - authStatusCache.at < 10 * 60 * 1000) {
|
|
2145
|
+
return AUTH_BROKEN_REPLY
|
|
2146
|
+
}
|
|
2116
2147
|
const res = await run('gh', ['api', '-X', method, args.path, '--header', 'Accept: application/vnd.github+json'], {
|
|
2117
2148
|
input: write && args.body ? args.body : undefined, env: ghEnv(),
|
|
2118
2149
|
})
|
|
@@ -2127,6 +2158,10 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2127
2158
|
description: 'Report the GitHub repository of the current working directory (owner/name, default branch, visibility). Read-only.',
|
|
2128
2159
|
parameters: {},
|
|
2129
2160
|
async execute() {
|
|
2161
|
+
// 已知凭证失效时不再 spawn:Fowler 的断路器就是「不发起这次受保护的调用」
|
|
2162
|
+
if (isAuthBroken(authStatusCache.text) && Date.now() - authStatusCache.at < 10 * 60 * 1000) {
|
|
2163
|
+
return AUTH_BROKEN_REPLY
|
|
2164
|
+
}
|
|
2130
2165
|
const res = await run('gh', ['repo', 'view', '--json', 'nameWithOwner,defaultBranchRef,visibility,url'], { cwd: process.cwd(), env: ghEnv() })
|
|
2131
2166
|
const text = redact([res.stdout, res.stderr].filter(Boolean).join(String.fromCharCode(10)).trim())
|
|
2132
2167
|
// 与 github 工具同一套:失败带分类与下一步,而不是只贴原始 stderr
|
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.125",
|
|
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",
|