dsh-session-superagent 0.9.124 → 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 +29 -0
- package/README.md +2 -2
- package/client.js +1 -1
- package/lib/gh-format.js +5 -1
- package/lib/index.js +13 -3
- package/lib/watch.js +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,35 @@
|
|
|
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
|
+
|
|
5
34
|
## [0.9.124] - 2026-11-03 —— 真机实测:令牌失效时我们却在怪代理
|
|
6
35
|
|
|
7
36
|
### 现场(09:00 时段开门后的真实轮询)
|
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
|
@@ -14,11 +14,15 @@
|
|
|
14
14
|
* 依据:GitHub 排障文档在结果不对时要求「confirm that the authentication credentials … have access」
|
|
15
15
|
* 出处:https://docs.github.com/en/rest/using-the-rest-api/troubleshooting-the-rest-api#missing-results
|
|
16
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
|
+
}
|
|
17
21
|
export function diagnoseEmptyBody({ bodyText, authStatusText } = {}) {
|
|
18
22
|
const body = String(bodyText ?? '').trim()
|
|
19
23
|
if (body.length > 0) return null
|
|
20
24
|
const auth = String(authStatusText ?? '')
|
|
21
|
-
if (
|
|
25
|
+
if (isAuthBroken(auth)) {
|
|
22
26
|
return { kind: 'auth', hint: '(gh 没有返回内容,且凭证已失效:跑 gh auth login 重新登录)' }
|
|
23
27
|
}
|
|
24
28
|
return { kind: 'empty', hint: '(gh 没有返回内容:可能是代理拦截或未登录 —— 跑 watch_doctor 看凭证)' }
|
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, 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)
|
|
@@ -2138,6 +2140,10 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2138
2140
|
if (write && args.confirm !== true) {
|
|
2139
2141
|
return `[error: ${method} requires confirm: true — this plugin never writes to GitHub without an explicit flag]`
|
|
2140
2142
|
}
|
|
2143
|
+
// 已知凭证失效时不再 spawn:Fowler 的断路器就是「不发起这次受保护的调用」
|
|
2144
|
+
if (isAuthBroken(authStatusCache.text) && Date.now() - authStatusCache.at < 10 * 60 * 1000) {
|
|
2145
|
+
return AUTH_BROKEN_REPLY
|
|
2146
|
+
}
|
|
2141
2147
|
const res = await run('gh', ['api', '-X', method, args.path, '--header', 'Accept: application/vnd.github+json'], {
|
|
2142
2148
|
input: write && args.body ? args.body : undefined, env: ghEnv(),
|
|
2143
2149
|
})
|
|
@@ -2152,6 +2158,10 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2152
2158
|
description: 'Report the GitHub repository of the current working directory (owner/name, default branch, visibility). Read-only.',
|
|
2153
2159
|
parameters: {},
|
|
2154
2160
|
async execute() {
|
|
2161
|
+
// 已知凭证失效时不再 spawn:Fowler 的断路器就是「不发起这次受保护的调用」
|
|
2162
|
+
if (isAuthBroken(authStatusCache.text) && Date.now() - authStatusCache.at < 10 * 60 * 1000) {
|
|
2163
|
+
return AUTH_BROKEN_REPLY
|
|
2164
|
+
}
|
|
2155
2165
|
const res = await run('gh', ['repo', 'view', '--json', 'nameWithOwner,defaultBranchRef,visibility,url'], { cwd: process.cwd(), env: ghEnv() })
|
|
2156
2166
|
const text = redact([res.stdout, res.stderr].filter(Boolean).join(String.fromCharCode(10)).trim())
|
|
2157
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",
|