dsh-session-superagent 0.9.124 → 0.9.126

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,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.126] - 2026-11-03 —— 断路器下沉到 `run()`:一处生效,所有调用点都覆盖
6
+
7
+ ### 为什么
8
+ 0.9.125 只给 `github` / `repo_here` 两个工具加了短路。但**真正会发请求的地方有七八处**
9
+ (轮询、`watch_ack` 打标签、仓库体检、评论查询…),漏掉任何一处,"明知凭证坏了还去调"就还在。
10
+
11
+ 上一轮刚立下的规矩(`policy-numbers-have-one-home.md`)同样适用:**政策只该有一处**。
12
+
13
+ ### 改法
14
+ 把断路器移进 `run()` —— 所有 `gh` 调用的唯一出口:
15
+
16
+ ```js
17
+ if (file === 'gh' && !argv.includes('--version') && argv[1] !== 'auth') {
18
+ if (isAuthBroken(authStatusCache.text) && fresh) {
19
+ resolve({ code: 1, stdout: '', stderr: '凭证已失效,本次没有发起请求:跑 gh auth login 重新登录后再试' })
20
+ }
21
+ }
22
+ ```
23
+
24
+ - `gh auth status` 与 `--version` **豁免**(否则无法自检、也永远解不开);
25
+ - 顺序放在**离线模式之前**,让"凭证坏了"的语义在测试里也一致;
26
+ - 工具层那两处重复短路随之删除,死常量 `AUTH_BROKEN_REPLY` 一并清掉。
27
+
28
+ ### 测试
29
+ 新增 1 例:凭证失效时 `watch_ack`(要打标签的内部调用)也走短路。合计 **236 例**。
30
+
31
+ ## [0.9.125] - 2026-11-03 —— 凭证坏了就别再发请求:断路器式短路
32
+
33
+ ### 学到什么(出处)
34
+ Martin Fowler《CircuitBreaker》:
35
+
36
+ > Once the failures reach a certain threshold, the circuit breaker trips, and **all further calls to the
37
+ > circuit breaker return with an error, without the protected call being made at all.**
38
+
39
+ <https://martinfowler.com/bliki/CircuitBreaker.html>
40
+
41
+ 我们上一版(0.9.124)已经把"凭证失效"识别出来了,但**只有轮询路径**用它:
42
+ `github` 工具和 `repo_here` 仍然会照常 spawn `gh`,拿到空内容再走一遍诊断 —— 这就是"明知会失败还去调"。
43
+
44
+ ### 改法
45
+ 1. 抽出 `isAuthBroken()`(`diagnoseEmptyBody` 复用它,避免两处正则各写一份);
46
+ 2. `gh auth status` 的结论缓存 60 秒,`github` / `repo_here` 在**已知凭证失效**时直接返回:
47
+ `[error: 凭证已失效,本次没有发起请求] 跑 gh auth login 重新登录后再试`
48
+ 3. 缓存为空/过期时照常调用。
49
+
50
+ ### 真机背景(本轮实测)
51
+ ```
52
+ - MYCF711/dsh-go | fails 4 | nextAt 2026-11-03T02:40:27.997Z
53
+ lastError: gh: HTTP 502(GitHub 或本地代理短暂故障)
54
+ ```
55
+ 外部网络此刻也不健康(502),所以"不发起这次调用"对客户更友好:少一次必然失败的进程。
56
+
57
+ ### 测试
58
+ 新增 1 例:缓存里是失效结论 → 两个工具短路且提示修复动作;清空缓存 → 恢复调用。合计 **235 例**。
59
+
5
60
  ## [0.9.124] - 2026-11-03 —— 真机实测:令牌失效时我们却在怪代理
6
61
 
7
62
  ### 现场(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: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
- [![Version](https://img.shields.io/badge/version-0.9.124-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.9.126-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 # 234 项单测
126
+ node --test # 236 项单测
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.124'
17
+ const CLIENT_VERSION = '0.9.126'
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 (/token in keyring is invalid|Failed to log in|Bad credentials|requires authentication/i.test(auth)) {
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.124'
43
+ export const SERVER_VERSION = '0.9.126'
44
44
  export const inject = ['tools', 'agents', 'webServer']
45
45
  /** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
46
46
  // 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
@@ -62,7 +62,7 @@ const MAX_WATCHERS_PER_SESSION = 20
62
62
  const CLEANUP_INTERVAL_MS = 10 * 60 * 1000
63
63
 
64
64
  /** 仅供测试:读写状态文件(生产代码不要用)。 */
65
- export const __test = { readState, writeState, hardenSecretsFile, wakeMerged }
65
+ export const __test = { readState, writeState, hardenSecretsFile, wakeMerged, setAuthStatusCache: (text) => { authStatusCache = { at: text ? Date.now() : 0, text } } }
66
66
 
67
67
  const STATE_DIR = process.env.DSH_SUPERAGENT_STATE
68
68
  ? String(process.env.DSH_SUPERAGENT_STATE)
@@ -502,6 +502,14 @@ function offlineGhReply(args) {
502
502
  function run(file, args, options = {}) {
503
503
  const { input, cwd, env, timeoutMs = 60000 } = options
504
504
  return new Promise((resolve) => {
505
+ // 统一断路器:已知凭证失效时,除了`gh auth status`/`--version`,一律不发起调用。
506
+ // 放在 run() 里而不是各个调用点:政策只该有一处(见 KB policy-numbers-have-one-home.md)。
507
+ if (file === 'gh' && !(args || []).includes('--version') && !((args || [])[1] === 'auth')) {
508
+ if (isAuthBroken(authStatusCache.text) && Date.now() - authStatusCache.at < 10 * 60 * 1000) {
509
+ resolve({ code: 1, stdout: '', stderr: '凭证已失效,本次没有发起请求:跑 gh auth login 重新登录后再试' })
510
+ return
511
+ }
512
+ }
505
513
  if (file === 'gh' && process.env.DSH_SUPERAGENT_OFFLINE === '1') {
506
514
  resolve({ code: 0, stdout: offlineGhReply(args), stderr: '' })
507
515
  return
package/lib/watch.js CHANGED
@@ -568,6 +568,7 @@ export {
568
568
  classifyGhError,
569
569
  commentSummaryLine,
570
570
  countReasons,
571
+ isAuthBroken,
571
572
  diagnoseEmptyBody,
572
573
  formatGhCall,
573
574
  jitterMs,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.9.124",
3
+ "version": "0.9.126",
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",