dsh-session-superagent 0.9.112 → 0.9.114
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 +42 -0
- package/README.md +2 -2
- package/client.js +1 -1
- package/lib/gh-format.js +2 -0
- package/lib/index.js +34 -3
- package/lib/watch.js +12 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,48 @@
|
|
|
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.114] - 2026-11-03 —— 按 GitHub 官方最佳实践补两条:x-poll-interval、永久错误等更久
|
|
6
|
+
|
|
7
|
+
### 学到什么(出处)
|
|
8
|
+
GitHub《Best practices for using the REST API》明确两条我们没做:
|
|
9
|
+
|
|
10
|
+
1. **`x-poll-interval`**:「If a response includes an `x-poll-interval` header, wait at least that many seconds
|
|
11
|
+
before you poll the same endpoint again.」
|
|
12
|
+
2. **重复 404**:「Once you have confirmed that your credentials are correct, **wait much longer** before you check
|
|
13
|
+
again… Repeatedly requesting a missing resource wastes your rate limit and can trigger a secondary rate limit.」
|
|
14
|
+
|
|
15
|
+
出处:<https://docs.github.com/en/rest/using-the-rest-api/best-practices-for-using-the-rest-api>
|
|
16
|
+
|
|
17
|
+
### 改了什么
|
|
18
|
+
1. `parseGhInclude` 解析 `x-poll-interval`(修了一个坑:`Number(null) === 0` 会让"没有这个头"被当成 0);
|
|
19
|
+
2. 轮询取 `max(配置间隔, x-poll-interval)` 作为下限 —— **成功路径也生效**
|
|
20
|
+
(此前 `nextAt` 只在失败退避时设置,成功后清空,间隔下限等于没用);
|
|
21
|
+
3. 永久性错误(`notfound` / `moved`)新增 **30 分钟**最低等待(`permanentBackoffMs`),
|
|
22
|
+
不再按普通指数退避反复撞不存在的仓库。
|
|
23
|
+
|
|
24
|
+
### 测试
|
|
25
|
+
新增 2 例:`x-poll-interval` 解析(有/无头)+ 间隔下限逻辑;`permanentBackoffMs` 四种 kind 的取值。
|
|
26
|
+
合计 **222 例**。
|
|
27
|
+
|
|
28
|
+
## [0.9.113] - 2026-11-03 —— 把「不是错误的状态码」理一遍:204 也补上了
|
|
29
|
+
|
|
30
|
+
### 梳理结果
|
|
31
|
+
| 状态码 | 语义 | 我们的处理 |
|
|
32
|
+
|---|---|---|
|
|
33
|
+
| 200 | 正常 | 解析 body |
|
|
34
|
+
| **204** | 没有内容(DELETE / 空列表) | **本轮补上**:按「未变化」处理(此前会掉进"不是合法 JSON") |
|
|
35
|
+
| **304** | 没有变化(条件请求命中) | 0.9.110 修好:按「未变化」处理,不计入速率限制 |
|
|
36
|
+
| 301 | 改名/转移 | 归 `moved`,提示换新地址 |
|
|
37
|
+
| 401 / 403 / 404 | 要人动手 | 归 `auth` / `ratelimit` / `notfound` |
|
|
38
|
+
| 5xx | 服务端/网关 | 归 `gateway`,暗示可重试 |
|
|
39
|
+
|
|
40
|
+
### 改法
|
|
41
|
+
`pollOnce` 在 304 之外再认 204:清 `lastError`、重置退避、记 `unchanged` 事件。
|
|
42
|
+
|
|
43
|
+
### 测试
|
|
44
|
+
新增 1 例:`parseGhInclude` 能认 200/204/304 三种状态码与 ETag;304 的分类提示必须直说「不是错误」。
|
|
45
|
+
合计 **220 例**。
|
|
46
|
+
|
|
5
47
|
## [0.9.112] - 2026-11-03 —— 错误旁边写上「多久之前」,超过一小时标「旧记录」
|
|
6
48
|
|
|
7
49
|
### 为什么
|
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
|
|
|
@@ -122,7 +122,7 @@ dsh plugin install /path/to/dsh-session-superagent
|
|
|
122
122
|
## 开发
|
|
123
123
|
|
|
124
124
|
```sh
|
|
125
|
-
node --test #
|
|
125
|
+
node --test # 222 项单测
|
|
126
126
|
```
|
|
127
127
|
|
|
128
128
|
### 工具输出:文本给人和 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.114'
|
|
18
18
|
let BASE = '/session-superagent'
|
|
19
19
|
/**
|
|
20
20
|
* 挑「最新的那个服务端实例」。
|
package/lib/gh-format.js
CHANGED
|
@@ -86,6 +86,8 @@ export function parseGhInclude(stdout) {
|
|
|
86
86
|
limit: numeric('x-ratelimit-limit'),
|
|
87
87
|
resetAt: resetSeconds ? new Date(resetSeconds * 1000).toISOString() : null,
|
|
88
88
|
retryAfter: Number.isFinite(Number(retryAfterRaw)) ? Number(retryAfterRaw) : null,
|
|
89
|
+
// GitHub 用这个头告诉你「这个 endpoint 至少隔多久再问」——忽略它会白撞额度
|
|
90
|
+
pollInterval: (() => { const raw = header('x-poll-interval'); return raw && Number.isFinite(Number(raw)) ? Number(raw) : null })(),
|
|
89
91
|
body,
|
|
90
92
|
}
|
|
91
93
|
}
|
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, hasAckLabel, jitterMs, parseGhInclude, retryAfterMs, throttleDelayMs, inActiveHours, newestUpdatedAt, nextDelayMs, pushAbsorbed, pushFiltered, normalizeFilters, partitionItems, passesFilters,
|
|
28
|
+
TRIAGE_SIGNALS, accessNote, buildCommentBatchQuery, classifyGhError, commentSummaryLine, parseCommentBatch, pickSuggestion, repoStructureNote, countReasons, filterReason, hasAckLabel, jitterMs, parseGhInclude, retryAfterMs, throttleDelayMs, inActiveHours, newestUpdatedAt, nextDelayMs, permanentBackoffMs, 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.114'
|
|
44
44
|
export const inject = ['tools', 'agents', 'webServer']
|
|
45
45
|
/** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
|
|
46
46
|
// 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
|
|
@@ -365,9 +365,15 @@ function noteEvent(entry, kind, text) {
|
|
|
365
365
|
} catch { /* 观测失败不能影响主流程 */ }
|
|
366
366
|
}
|
|
367
367
|
|
|
368
|
+
// 实际间隔:自己的配置与 GitHub 要求的 x-poll-interval 取大者
|
|
369
|
+
function effectiveIntervalMs(entry, baseMs) {
|
|
370
|
+
const floor = (Number(entry.minIntervalSec) || 0) * 1000
|
|
371
|
+
return Math.max(Number(baseMs) || 0, floor)
|
|
372
|
+
}
|
|
373
|
+
|
|
368
374
|
function bumpFailure(entry, baseMs) {
|
|
369
375
|
entry.consecutiveFailures = (Number(entry.consecutiveFailures) || 0) + 1
|
|
370
|
-
entry.nextAt = new Date(Date.now() + nextDelayMs(entry, baseMs || 60000)).toISOString()
|
|
376
|
+
entry.nextAt = new Date(Date.now() + nextDelayMs(entry, effectiveIntervalMs(entry, baseMs || 60000))).toISOString()
|
|
371
377
|
}
|
|
372
378
|
|
|
373
379
|
/**
|
|
@@ -888,9 +894,21 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
888
894
|
const classified = classifyGhError(detail)
|
|
889
895
|
setEntryError(entry, (classified.short + classified.hint).slice(0, 300))
|
|
890
896
|
bumpFailure(entry, baseMs)
|
|
897
|
+
// 永久性错误(404 / 仓库改名)不要按普通退避重试:至少等半小时
|
|
898
|
+
const permanent = permanentBackoffMs(classified.kind, baseMs)
|
|
899
|
+
if (permanent > 0) {
|
|
900
|
+
entry.nextAt = new Date(Date.now() + permanent).toISOString()
|
|
901
|
+
entry.deferReason = classified.kind === 'moved' ? 'moved' : 'notfound'
|
|
902
|
+
}
|
|
891
903
|
return
|
|
892
904
|
}
|
|
893
905
|
const parsed = parseGhInclude(res.stdout)
|
|
906
|
+
// GitHub 的 x-poll-interval 是硬下限:比我们的间隔大就照它等,别硬撞
|
|
907
|
+
if (parsed.pollInterval && parsed.pollInterval * 1000 > baseMs) {
|
|
908
|
+
entry.minIntervalSec = parsed.pollInterval
|
|
909
|
+
} else if (entry.minIntervalSec && (!parsed.pollInterval || parsed.pollInterval * 1000 <= baseMs)) {
|
|
910
|
+
entry.minIntervalSec = null
|
|
911
|
+
}
|
|
894
912
|
// 额度自适应:剩余低于 500 时不再按固定间隔撞墙,直接把下一轮推到额度重置(最多 1 小时)
|
|
895
913
|
const throttle = throttleDelayMs({ remaining: parsed.remaining, resetAt: parsed.resetAt })
|
|
896
914
|
if (throttle > 0) {
|
|
@@ -901,6 +919,16 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
901
919
|
entry.lastError = null
|
|
902
920
|
return
|
|
903
921
|
}
|
|
922
|
+
// 204 No Content 也是「没有新东西」:DELETE/空列表都会这样,别当 JSON 解析失败
|
|
923
|
+
if (parsed.status === 204) {
|
|
924
|
+
entry.lastError = null
|
|
925
|
+
entry.consecutiveFailures = 0
|
|
926
|
+
entry.nextAt = null
|
|
927
|
+
entry.lastDeferred = '没有内容(204)'
|
|
928
|
+
entry.deferReason = 'unchanged'
|
|
929
|
+
noteEvent(entry, 'unchanged', entry.lastDeferred)
|
|
930
|
+
return
|
|
931
|
+
}
|
|
904
932
|
if (parsed.status === 304) {
|
|
905
933
|
// 没变化:不解析、不算失败、不重置退避,只记一笔
|
|
906
934
|
entry.lastError = null
|
|
@@ -1160,6 +1188,9 @@ export function apply(ctx) {
|
|
|
1160
1188
|
inFlight.add(entry.id)
|
|
1161
1189
|
try {
|
|
1162
1190
|
await pollOnce(ctx, entry, every)
|
|
1191
|
+
// GitHub 要求的间隔比我们的长:把下一轮推到它之后(成功路径也生效)
|
|
1192
|
+
const floor = (Number(entry.minIntervalSec) || 0) * 1000
|
|
1193
|
+
if (floor > every) entry.nextAt = new Date(Date.now() + floor).toISOString()
|
|
1163
1194
|
} catch (error) {
|
|
1164
1195
|
// 未预期的异常(比如宿主上下文/服务不可用)也必须退避:
|
|
1165
1196
|
// 之前只写 lastError,于是坏掉的 watcher 会按 intervalSec 无限重试(真机踩到过)。
|
package/lib/watch.js
CHANGED
|
@@ -312,6 +312,18 @@ export function batchFresh(fresh, limit = 3, priority) {
|
|
|
312
312
|
}
|
|
313
313
|
|
|
314
314
|
/** 连续失败指数退避:30s → 60 → 120 → … 上限 30 分钟;成功即复位。 */
|
|
315
|
+
/**
|
|
316
|
+
* 永久性错误(仓库不存在 / 已改名)要等多久再试。
|
|
317
|
+
*
|
|
318
|
+
* 依据 GitHub 官方最佳实践:确认凭据没问题后,「wait much longer before you check again」——
|
|
319
|
+
* 反复请求不存在的资源既浪费额度,还可能触发 secondary rate limit。
|
|
320
|
+
* 出处:https://docs.github.com/en/rest/using-the-rest-api/best-practices-for-using-the-rest-api
|
|
321
|
+
*/
|
|
322
|
+
export function permanentBackoffMs(kind, baseMs = 60000) {
|
|
323
|
+
const PERMANENT = new Set(['notfound', 'moved'])
|
|
324
|
+
if (!PERMANENT.has(kind)) return 0
|
|
325
|
+
return Math.max(30 * 60 * 1000, Number(baseMs) || 0)
|
|
326
|
+
}
|
|
315
327
|
export function nextDelayMs(entry, baseMs) {
|
|
316
328
|
const failures = Number((entry && entry.consecutiveFailures) || 0)
|
|
317
329
|
if (failures <= 0) return baseMs
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-superagent",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.114",
|
|
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",
|