dsh-session-superagent 0.8.50 → 0.8.52
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 +47 -0
- package/MAINTENANCE.md +1 -1
- package/README.md +2 -2
- package/client.js +1 -1
- package/lib/index.js +26 -5
- package/lib/watch.js +46 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,53 @@
|
|
|
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.8.52] - 2026-11-02 —— 首轮抖动:多条守不再同一毫秒一起发车
|
|
6
|
+
|
|
7
|
+
### 学到的一条(知识库第 2 条)
|
|
8
|
+
AWS《Exponential Backoff And Jitter》:固定周期的客户端会同步成 thundering herd,加抖动摊平峰值。
|
|
9
|
+
<https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/>
|
|
10
|
+
|
|
11
|
+
我们的 `inFlight` 闸是**按 watcher**的,挡不住「N 条守在同一毫秒一起打 gh api」。
|
|
12
|
+
|
|
13
|
+
### 改了什么
|
|
14
|
+
`jitterMs(entry.id, min(5000, 间隔×10%))` 用 **id 哈希**算偏移(可复现,不是随机数),
|
|
15
|
+
只延迟**首轮**,之后按 `every` 稳定推进。
|
|
16
|
+
|
|
17
|
+
### 顺带做了三组实测(都写进知识库)
|
|
18
|
+
| 测什么 | 结果 |
|
|
19
|
+
|---|---|
|
|
20
|
+
| 单条 watcher 满载状态 | **21.8 KB**(seen 500 + history 20 + filteredLog 5),10 条 ≈ 218 KB,有上限 |
|
|
21
|
+
| `gh api` vs `gh api --include` | 稳态几乎同速(~500-650 ms)—— 0.8.51 的 `--include` 没有额外开销 |
|
|
22
|
+
| 抖动分布 | 20 条守 → 17 个不同偏移(用例里要求 >8) |
|
|
23
|
+
|
|
24
|
+
### 测试
|
|
25
|
+
- 合计 **105 例**;UI 体检 11/11。
|
|
26
|
+
|
|
27
|
+
## [0.8.51] - 2026-11-02 —— 条件请求:没变化不计入速率限制
|
|
28
|
+
|
|
29
|
+
### 学到了什么(新知识库 `docs/kb/` 的第一条)
|
|
30
|
+
GitHub 官方最佳实践原文:*"Make authenticated conditional requests, so that unchanged data does not
|
|
31
|
+
count against your primary rate limit."*
|
|
32
|
+
出处:<https://docs.github.com/en/rest/using-the-rest-api/best-practices-for-using-the-rest-api>
|
|
33
|
+
|
|
34
|
+
主理鱼每 N 秒拉一次 issue 列表,**大多数轮次其实什么都没变** —— 全量拉属于纯浪费,还占额度。
|
|
35
|
+
|
|
36
|
+
### 改了什么
|
|
37
|
+
- 每条 watcher 记住 `etag`;下一轮带 `-H 'If-None-Match: <etag>'`;
|
|
38
|
+
- 收到 **304** 当「本轮无变化」:不解析、不记失败、**不动退避**(退避是给失败的,304 是成功);
|
|
39
|
+
- `gh api --include` 会输出「状态行 + 头 + 空行 + 正文」,新增纯函数 `parseGhInclude` 解析,
|
|
40
|
+
用例覆盖 200 / 304 / 纯正文三种形态。
|
|
41
|
+
|
|
42
|
+
### 效果
|
|
43
|
+
没变化时:网络传输从「20 条 issue 的 JSON」降到「一个空响应」,且**不计入 rate limit**。
|
|
44
|
+
|
|
45
|
+
### 附带
|
|
46
|
+
- 新建 `docs/kb/`(入口索引 + 按主题分组),本轮第一条 `github-conditional-requests.md`;
|
|
47
|
+
- 小时级定时任务改为「先学一条 → 再改一处 → 报三段」,作为保底。
|
|
48
|
+
|
|
49
|
+
### 测试
|
|
50
|
+
- 合计 **104 例**;UI 体检 11/11。
|
|
51
|
+
|
|
5
52
|
## [0.8.50] - 2026-11-02 —— 双主题预览进「一键命令 + 门禁」
|
|
6
53
|
|
|
7
54
|
以前 `render-preview.mjs` 是个内部脚本,没人知道它存在;现在:
|
package/MAINTENANCE.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## 二、当前状态(2026-11-01)
|
|
11
11
|
|
|
12
|
-
- [x] 七个工具可用(github / repo_here / watch_start / watch_status / watch_stop / watch_ack / watch_doctor),`node --test`
|
|
12
|
+
- [x] 七个工具可用(github / repo_here / watch_start / watch_status / watch_stop / watch_ack / watch_doctor),`node --test` 105/105 通过
|
|
13
13
|
- [x] 自回声抑制(逐条水位)
|
|
14
14
|
- [x] 仅空闲注入(避免草稿回放)
|
|
15
15
|
- [x] 唤醒失败不推进水位
|
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
|
|
|
@@ -99,7 +99,7 @@ dsh plugin install /path/to/dsh-session-superagent
|
|
|
99
99
|
## 开发
|
|
100
100
|
|
|
101
101
|
```sh
|
|
102
|
-
node --test #
|
|
102
|
+
node --test # 105 项单测
|
|
103
103
|
```
|
|
104
104
|
|
|
105
105
|
版本与发布流程见 [UPDATING.md](UPDATING.md),交付门见 [CHECKLIST.md](CHECKLIST.md),接手台账见 [MAINTENANCE.md](MAINTENANCE.md)。
|
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.8.
|
|
17
|
+
const CLIENT_VERSION = '0.8.52'
|
|
18
18
|
let BASE = '/session-superagent'
|
|
19
19
|
/**
|
|
20
20
|
* 挑「最新的那个服务端实例」。
|
package/lib/index.js
CHANGED
|
@@ -24,13 +24,13 @@ import { redact } from './redact.js'
|
|
|
24
24
|
import { decodeBody } from './body.js'
|
|
25
25
|
import {
|
|
26
26
|
advanceSeen, applyWatcherAction, batchFresh, decideWake, DEFAULT_ACK_LABEL, formatWatchText,
|
|
27
|
-
classifyGhError, filterReason, hasAckLabel, inActiveHours, newestUpdatedAt, nextDelayMs, pushFiltered, normalizeFilters, partitionItems, passesFilters,
|
|
27
|
+
classifyGhError, filterReason, hasAckLabel, jitterMs, parseGhInclude, inActiveHours, newestUpdatedAt, nextDelayMs, pushFiltered, normalizeFilters, partitionItems, passesFilters,
|
|
28
28
|
mergeFilters, mergePollResult, pruneSeen, pruneWakeTimes, pushHistory, recordReported, staleWorktrees, worktreePlan,
|
|
29
29
|
} from './watch.js'
|
|
30
30
|
|
|
31
31
|
export const name = 'dsh-session-superagent'
|
|
32
32
|
/** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
|
|
33
|
-
export const SERVER_VERSION = '0.8.
|
|
33
|
+
export const SERVER_VERSION = '0.8.52'
|
|
34
34
|
export const inject = ['tools', 'agents', 'webServer']
|
|
35
35
|
|
|
36
36
|
/** 仅供测试:读写状态文件(生产代码不要用)。 */
|
|
@@ -437,7 +437,10 @@ function wake(ctx, sessionId, text) {
|
|
|
437
437
|
}
|
|
438
438
|
|
|
439
439
|
async function pollOnce(ctx, entry, baseMs) {
|
|
440
|
-
|
|
440
|
+
// 条件请求:带上上次的 ETag,没变化时 GitHub 回 304,且**不计入**速率限制
|
|
441
|
+
const args = ['api', '--include', `repos/${entry.repo}/issues?state=all&sort=updated&direction=desc&per_page=20`]
|
|
442
|
+
if (entry.etag) args.push('-H', 'If-None-Match: ' + entry.etag)
|
|
443
|
+
const res = await run('gh', args, { timeoutMs: 45000, env: ghEnv() })
|
|
441
444
|
entry.lastPoll = new Date().toISOString()
|
|
442
445
|
if (res.code !== 0) {
|
|
443
446
|
const detail = redact(res.stderr).slice(0, 240)
|
|
@@ -447,8 +450,18 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
447
450
|
bumpFailure(entry, baseMs)
|
|
448
451
|
return
|
|
449
452
|
}
|
|
453
|
+
const parsed = parseGhInclude(res.stdout)
|
|
454
|
+
if (parsed.status === 304) {
|
|
455
|
+
// 没变化:不解析、不算失败、不重置退避,只记一笔
|
|
456
|
+
entry.lastError = null
|
|
457
|
+
entry.consecutiveFailures = 0
|
|
458
|
+
entry.nextAt = null
|
|
459
|
+
entry.lastDeferred = '未变化(304,不计入速率限制)'
|
|
460
|
+
return
|
|
461
|
+
}
|
|
462
|
+
if (parsed.etag) entry.etag = parsed.etag
|
|
450
463
|
let items
|
|
451
|
-
try { items = JSON.parse(
|
|
464
|
+
try { items = JSON.parse(parsed.body) } catch { entry.lastError = 'bad json'; bumpFailure(entry, baseMs); return }
|
|
452
465
|
if (!Array.isArray(items)) { entry.lastError = 'unexpected payload'; bumpFailure(entry, baseMs); return }
|
|
453
466
|
|
|
454
467
|
entry.lastError = null
|
|
@@ -588,6 +601,8 @@ export function apply(ctx) {
|
|
|
588
601
|
const startWatcher = (entry) => {
|
|
589
602
|
if (timers.has(entry.id)) return
|
|
590
603
|
const every = Math.max(30, Number(entry.intervalSec) || 60) * 1000
|
|
604
|
+
// 首轮错峰:多条守同间隔时不要整点一起发车(之后按 every 稳定推进,不累积漂移)
|
|
605
|
+
const firstDelay = jitterMs(entry.id, Math.min(5000, every * 0.1))
|
|
591
606
|
|
|
592
607
|
const tick = async () => {
|
|
593
608
|
// A pause (or delete) can land between two ticks; never poll a watcher
|
|
@@ -614,7 +629,13 @@ export function apply(ctx) {
|
|
|
614
629
|
timers.set(entry.id, setInterval(tick, every).unref?.())
|
|
615
630
|
// DSH_SUPERAGENT_NO_POLL=1 只登记不轮询(路由层单测用,避免真去请求 GitHub)
|
|
616
631
|
if (process.env.DSH_SUPERAGENT_NO_POLL === '1') return
|
|
617
|
-
|
|
632
|
+
// 首轮按确定性抖动错峰(0~5 秒),之后按 every 稳定推进
|
|
633
|
+
if (firstDelay > 0) {
|
|
634
|
+
const boot = setTimeout(() => { tick() }, firstDelay)
|
|
635
|
+
boot.unref?.()
|
|
636
|
+
} else {
|
|
637
|
+
tick()
|
|
638
|
+
}
|
|
618
639
|
}
|
|
619
640
|
|
|
620
641
|
// Must run before the entry leaves the state file: a live tick would
|
package/lib/watch.js
CHANGED
|
@@ -417,3 +417,49 @@ export function classifyGhError(detail) {
|
|
|
417
417
|
}
|
|
418
418
|
return { kind: 'other', short, hint: '' }
|
|
419
419
|
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* 解析 `gh api --include` 的输出:状态行 / 响应头 / 空行 / 正文。
|
|
423
|
+
*
|
|
424
|
+
* 为什么用它而不是直接 `gh api`:GitHub 官方文档明确说
|
|
425
|
+
* 「Make authenticated conditional requests, so that unchanged data does not count against
|
|
426
|
+
* your primary rate limit」—— 带上 If-None-Match 后,没变化时拿 304,
|
|
427
|
+
* 304 **不计入**速率限制。对一个每 N 秒轮询的工具,这是最直接的省额度手段。
|
|
428
|
+
*
|
|
429
|
+
* 出处:https://docs.github.com/en/rest/using-the-rest-api/best-practices-for-using-the-rest-api
|
|
430
|
+
*/
|
|
431
|
+
export function parseGhInclude(stdout) {
|
|
432
|
+
const text = String(stdout || '')
|
|
433
|
+
const LF = String.fromCharCode(10)
|
|
434
|
+
const blank = LF + LF
|
|
435
|
+
const idx = text.indexOf(blank)
|
|
436
|
+
const head = idx < 0 ? text : text.slice(0, idx)
|
|
437
|
+
const body = idx < 0 ? text.trim() : text.slice(idx + blank.length)
|
|
438
|
+
const lines = head.split(LF)
|
|
439
|
+
// 状态行形如 `HTTP/2.0 200 OK`
|
|
440
|
+
const statusParts = String(lines[0] || '').split(' ')
|
|
441
|
+
const status = Number(statusParts[1]) || 0
|
|
442
|
+
let etag = null
|
|
443
|
+
for (const line of lines) {
|
|
444
|
+
if (line.toLowerCase().startsWith('etag:')) etag = line.slice(5).trim()
|
|
445
|
+
}
|
|
446
|
+
return { status, etag, body }
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* 去同步抖动:给每个 watcher 一个**确定性的**起始偏移,避免 N 条守在同一条时间线上一起发车。
|
|
451
|
+
*
|
|
452
|
+
* 为什么不用随机数:随机数每次启动都不同,调试时对不上;用 id 的哈希则「同一条守永远同一个偏移」,
|
|
453
|
+
* 既错峰又可复现。范围固定在 [0, windowMs)。
|
|
454
|
+
*
|
|
455
|
+
* 依据:AWS Architecture Blog 的《Exponential Backoff And Jitter》——同步发车会让
|
|
456
|
+
* 下游在整点承压,加入抖动后峰值被摊平。(https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/)
|
|
457
|
+
*/
|
|
458
|
+
export function jitterMs(key, windowMs) {
|
|
459
|
+
const width = Math.max(0, Math.floor(Number(windowMs) || 0))
|
|
460
|
+
if (width === 0) return 0
|
|
461
|
+
const text = String(key || '')
|
|
462
|
+
let hash = 0
|
|
463
|
+
for (let i = 0; i < text.length; i += 1) hash = (hash * 31 + text.charCodeAt(i)) % 1000003
|
|
464
|
+
return hash % width
|
|
465
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-superagent",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.52",
|
|
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",
|