dsh-session-superagent 0.8.96 → 0.8.98
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 +51 -0
- package/README.md +1 -1
- package/client.js +23 -2
- package/lib/gh-format.js +5 -2
- package/lib/index.js +10 -8
- package/lib/watch.js +21 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,57 @@
|
|
|
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.98] - 2026-11-02 —— 时段外不再空打 API(一夜能省 800+ 次)
|
|
6
|
+
|
|
7
|
+
### 学到的(知识库第 47 条)
|
|
8
|
+
Renovate 的 `schedule`:**不在时间窗内就不去查更新**,而不是"查完再决定"。
|
|
9
|
+
通用原则:把"不做"的判断尽量前移。
|
|
10
|
+
<https://docs.renovatebot.com/configuration-options/#schedule>
|
|
11
|
+
|
|
12
|
+
### 抓到的浪费
|
|
13
|
+
`pollOnce` 里 `activeHours` 的判断原来在**拉完 API 之后**:
|
|
14
|
+
```js
|
|
15
|
+
const res = await run('gh', ...) // 先打一次 GitHub
|
|
16
|
+
if (!inActiveHours(entry.activeHours)) return // 才决定不叫醒
|
|
17
|
+
```
|
|
18
|
+
客户设 `09:00-18:00`,**夜里 14 小时照样每 N 秒打一次**:60 秒间隔 ≈ **一夜 840 次**
|
|
19
|
+
(多数是 304 不计额度,但每次都要起 `gh` 进程 + 一次网络往返),且开门后还要等下一个周期。
|
|
20
|
+
|
|
21
|
+
### 改了什么
|
|
22
|
+
1. 时段判断**移到函数最前**(拉数据之前);
|
|
23
|
+
2. 用 `msUntilActiveWindow()` 算出开门时间,把 `nextAt` 设到那一刻。
|
|
24
|
+
|
|
25
|
+
用例锁死语义:23:30 → 9.5 小时;07:00 → 2 小时;跨夜 15:00 → 7 小时;非法/空 → 0;最小 1 秒。
|
|
26
|
+
|
|
27
|
+
### 测试
|
|
28
|
+
- 新增 1 例(8 种情况)。合计 **141 例**。
|
|
29
|
+
|
|
30
|
+
## [0.8.97] - 2026-11-02 —— 错误提示要回答"我该做什么"
|
|
31
|
+
|
|
32
|
+
### 学到的(知识库第 46 条)
|
|
33
|
+
NN/g《Error-Message Guidelines》:用平实语言说明问题**并给出建设性解决方案**,不要只显示系统错误码。
|
|
34
|
+
<https://www.nngroup.com/articles/error-message-guidelines/>
|
|
35
|
+
|
|
36
|
+
### 拿真机见过的 12 条错误串去测,只命中 8 条
|
|
37
|
+
```
|
|
38
|
+
other | (无提示)| error: unable to get local issuer certificate
|
|
39
|
+
other | (无提示)| HTTP 502 Bad Gateway
|
|
40
|
+
other | (无提示)| repository "o/r" not found
|
|
41
|
+
other | (无提示)| context deadline exceeded
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 补齐到 12/12
|
|
45
|
+
- `notfound`:补 `repository "x" not found` 这类(但不能把 `command not found` 误判进来);
|
|
46
|
+
- `network`:补证书 / `context deadline exceeded` / x509;
|
|
47
|
+
- 新增 `gateway`:GitHub 或本地代理短暂故障 —— 这类最容易被误当成"我的仓库有问题"。
|
|
48
|
+
|
|
49
|
+
### 面板自己的错误也要人话
|
|
50
|
+
面板拉自己接口失败**不经过**上面那套,以前直接显示 `Failed to fetch`。
|
|
51
|
+
现在:连不上宿主 / 5xx / 404 / 超时 各有对应说明 + 动作(去诊断、重启、或"会自动重试不用管")。
|
|
52
|
+
|
|
53
|
+
### 测试
|
|
54
|
+
- 新增 2 例(12 种错误的归类与 hint、面板 `Failed to fetch` 必须翻译且提到「诊断」)。合计 **140 例**。
|
|
55
|
+
|
|
5
56
|
## [0.8.96] - 2026-11-02 —— index.js 量完不拆;顺手加文档体检
|
|
6
57
|
|
|
7
58
|
### 一、为什么**不**拆 index.js(知识库第 45 条)
|
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
|
|
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.98'
|
|
18
18
|
let BASE = '/session-superagent'
|
|
19
19
|
/**
|
|
20
20
|
* 挑「最新的那个服务端实例」。
|
|
@@ -1356,6 +1356,27 @@ window.__ModuleLoader__.load({
|
|
|
1356
1356
|
return () => { alive = false }
|
|
1357
1357
|
}, [])
|
|
1358
1358
|
|
|
1359
|
+
|
|
1360
|
+
/**
|
|
1361
|
+
* 面板自己遇到的错误也要说人话。
|
|
1362
|
+
*
|
|
1363
|
+
* 服务端那边的 gh 错误已经由 classifyGhError 归类(并附了 hint);
|
|
1364
|
+
* 但**面板拉自己接口失败**(宿主正在重启、端口变了、fetch 被拒)不会经过那套,
|
|
1365
|
+
* 以前界面上就是一行 "Failed to fetch" —— 客户看不懂,也不知道要做什么。
|
|
1366
|
+
*/
|
|
1367
|
+
function humanizeError(text) {
|
|
1368
|
+
const raw = String(text == null ? '' : text)
|
|
1369
|
+
if (!raw) return ''
|
|
1370
|
+
if (/Failed to fetch|NetworkError|Load failed/i.test(raw)) {
|
|
1371
|
+
return '连不上宿主:DSH 可能正在重启,或插件刚被重载。稍等几秒会自动重试;一直这样就去「设置 → 诊断」复制信息。'
|
|
1372
|
+
}
|
|
1373
|
+
if (/HTTP 401|HTTP 403/i.test(raw)) return '宿主拒绝了请求(401/403):面板接口可能需要重新挂载,重启宿主即可。'
|
|
1374
|
+
if (/HTTP 5\d\d/.test(raw)) return '宿主内部报错(5xx):先把「设置 → 诊断」里的信息复制出来,再重启宿主试试。'
|
|
1375
|
+
if (/HTTP 404/.test(raw)) return '接口不存在(404):多半还在跑旧版本代码,重启宿主。'
|
|
1376
|
+
if (/timeout|timed out|ETIMEDOUT/i.test(raw)) return '请求超时:宿主可能正忙(比如同时在建隔离 worktree),稍后自动重试。'
|
|
1377
|
+
return raw
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1359
1380
|
/** 仓库能力徽章(与服务端 watch.js:repoBadges 同语义)。 */
|
|
1360
1381
|
function repoBadges(access) {
|
|
1361
1382
|
if (!access || typeof access !== 'object') return []
|
|
@@ -1428,7 +1449,7 @@ window.__ModuleLoader__.load({
|
|
|
1428
1449
|
h('a', { className: 'dt-btn dt-btn-sm dt-btn-outline', href: '#', onClick: (e) => { e.preventDefault(); setTab('settings') } }, '看升级命令'))
|
|
1429
1450
|
: null,
|
|
1430
1451
|
toastView,
|
|
1431
|
-
snap.error ? h('div', { className: 'dt-banner dt-danger' }, '读取失败:' + snap.error) : null,
|
|
1452
|
+
snap.error ? h('div', { className: 'dt-banner dt-danger' }, '读取失败:' + humanizeError(snap.error)) : null,
|
|
1432
1453
|
snap.loading && !snap.body ? h(Hint, null, '正在读取…') : null,
|
|
1433
1454
|
tab === 'overview' ? overview : null,
|
|
1434
1455
|
tab === 'judge' ? judge : null,
|
package/lib/gh-format.js
CHANGED
|
@@ -20,13 +20,16 @@ export function classifyGhError(detail) {
|
|
|
20
20
|
if (/HTTP 403|rate limit|API rate limit exceeded/i.test(text)) {
|
|
21
21
|
return { kind: 'ratelimit', short, hint: '(被 GitHub 限流:等几分钟,或换成带 token 的凭证)' }
|
|
22
22
|
}
|
|
23
|
+
if (/HTTP 50[0234]|Bad Gateway|Service Unavailable|Gateway Time-?out/i.test(text)) {
|
|
24
|
+
return { kind: 'gateway', short, hint: '(GitHub 或本地代理短暂故障:已按退避自动重试,不需要手动处理;持续出现就检查代理)' }
|
|
25
|
+
}
|
|
23
26
|
if (/ENOENT|not found.*gh|gh: command not found/i.test(text)) {
|
|
24
27
|
return { kind: 'nogh', short, hint: '(找不到 gh 命令:确认已安装且在 PATH)' }
|
|
25
28
|
}
|
|
26
|
-
if (/HTTP 404|
|
|
29
|
+
if (/HTTP 404|Not Found|not found/i.test(text) && !/command not found/i.test(text)) {
|
|
27
30
|
return { kind: 'notfound', short, hint: '(仓库不存在或没权限:检查 owner/name)' }
|
|
28
31
|
}
|
|
29
|
-
if (/EOF|i\/o timeout|connection reset|dial tcp|TLS handshake|no such host|proxyconnect|timeout/i.test(text)) {
|
|
32
|
+
if (/EOF|i\/o timeout|connection reset|dial tcp|TLS handshake|no such host|proxyconnect|timeout|context deadline exceeded|certificate|x509|self.signed|unable to get local issuer/i.test(text)) {
|
|
30
33
|
return { kind: 'network', short, hint: '(网络抖动:这一轮没连上 GitHub,已按退避自动重试,不需要手动处理)' }
|
|
31
34
|
}
|
|
32
35
|
return { kind: 'other', short, hint: '' }
|
package/lib/index.js
CHANGED
|
@@ -26,12 +26,12 @@ import { decodeBody } from './body.js'
|
|
|
26
26
|
import {
|
|
27
27
|
advanceSeen, applyWatcherAction, batchFresh, decideWake, DEFAULT_ACK_LABEL, formatWatchText,
|
|
28
28
|
TRIAGE_SIGNALS, accessNote, buildCommentBatchQuery, classifyGhError, commentSummaryLine, parseCommentBatch, pickSuggestion, repoStructureNote, countReasons, filterReason, hasAckLabel, jitterMs, parseGhInclude, retryAfterMs, throttleDelayMs, inActiveHours, newestUpdatedAt, nextDelayMs, pushFiltered, normalizeFilters, partitionItems, passesFilters,
|
|
29
|
-
mergeFilters, mergePollResult, pruneSeen, pruneWakeTimes, pushHistory, recordReported, staleWorktrees, worktreePlan,
|
|
29
|
+
mergeFilters, mergePollResult, msUntilActiveWindow, pruneSeen, pruneWakeTimes, pushHistory, recordReported, staleWorktrees, worktreePlan,
|
|
30
30
|
} from './watch.js'
|
|
31
31
|
|
|
32
32
|
export const name = 'dsh-session-superagent'
|
|
33
33
|
/** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
|
|
34
|
-
export const SERVER_VERSION = '0.8.
|
|
34
|
+
export const SERVER_VERSION = '0.8.98'
|
|
35
35
|
export const inject = ['tools', 'agents', 'webServer']
|
|
36
36
|
|
|
37
37
|
/** 仅供测试:读写状态文件(生产代码不要用)。 */
|
|
@@ -728,6 +728,14 @@ async function fetchLastComments(repo, items, maxItems = 3) {
|
|
|
728
728
|
}
|
|
729
729
|
|
|
730
730
|
async function pollOnce(ctx, entry, baseMs) {
|
|
731
|
+
// 活跃时段要**在拉 API 之前**判断:以前放在后面,夜里照样每 N 秒打一次 GitHub,纯浪费。
|
|
732
|
+
// 不在时段内就把下一次轮询安排到"开门那一刻",攒着的条目不会多等一个周期。
|
|
733
|
+
if (entry.activeHours && !inActiveHours(entry.activeHours)) {
|
|
734
|
+
const wait = msUntilActiveWindow(entry.activeHours)
|
|
735
|
+
entry.nextAt = new Date(Date.now() + wait).toISOString()
|
|
736
|
+
entry.lastDeferred = `不在活跃时段(${entry.activeHours}),${Math.round(wait / 60000)} 分钟后开始`
|
|
737
|
+
return
|
|
738
|
+
}
|
|
731
739
|
// 条件请求:带上上次的 ETag,没变化时 GitHub 回 304,且**不计入**速率限制
|
|
732
740
|
const args = ['api', '--include', `repos/${entry.repo}/issues?state=all&sort=updated&direction=desc&per_page=20`]
|
|
733
741
|
if (entry.etag) args.push('-H', 'If-None-Match: ' + entry.etag)
|
|
@@ -828,12 +836,6 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
828
836
|
return
|
|
829
837
|
}
|
|
830
838
|
|
|
831
|
-
// 活跃时段:夜里不叫醒,攒着(对标 Renovate 的 schedule)
|
|
832
|
-
if (entry.activeHours && !inActiveHours(entry.activeHours)) {
|
|
833
|
-
entry.lastDeferred = `不在活跃时段(${entry.activeHours}),已攒 ${fresh.length} 条`
|
|
834
|
-
return
|
|
835
|
-
}
|
|
836
|
-
|
|
837
839
|
// 每小时唤醒上限:宁可攒着,也不要连续叫醒把上下文打爆
|
|
838
840
|
const cap = Math.max(1, Number(entry.maxWakesPerHour) || 6)
|
|
839
841
|
entry.wakeTimes = pruneWakeTimes(entry.wakeTimes)
|
package/lib/watch.js
CHANGED
|
@@ -484,3 +484,24 @@ export {
|
|
|
484
484
|
stateReasonNote,
|
|
485
485
|
throttleDelayMs,
|
|
486
486
|
} from './gh-format.js'
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* 距离「活跃时段开门」还有多久(毫秒);已在时段内返回 0。
|
|
490
|
+
*
|
|
491
|
+
* 为什么要它:以前 activeHours 的判断在**拉完 API 之后**才做 ——
|
|
492
|
+
* 夜里 8 小时照常每 N 秒打一次 GitHub,纯属白跑。现在提前到最前面,
|
|
493
|
+
* 并把下一次轮询安排在"开门那一刻",既不浪费请求,也不会让攒着的条目干等一个周期。
|
|
494
|
+
*/
|
|
495
|
+
export function msUntilActiveWindow(spec, now = new Date()) {
|
|
496
|
+
if (!spec || typeof spec !== 'string') return 0
|
|
497
|
+
const m = spec.match(/^(\d{1,2}):(\d{2})\s*-\s*(\d{1,2}):(\d{2})$/)
|
|
498
|
+
if (!m) return 0
|
|
499
|
+
if (inActiveHours(spec, now)) return 0
|
|
500
|
+
const startMin = (Number(m[1]) * 60 + Number(m[2])) % (24 * 60)
|
|
501
|
+
const curMin = now.getHours() * 60 + now.getMinutes()
|
|
502
|
+
const curSec = now.getSeconds()
|
|
503
|
+
let diffMin = startMin - curMin
|
|
504
|
+
if (diffMin <= 0) diffMin += 24 * 60
|
|
505
|
+
// 精确到分钟的开头,再减掉当前秒数
|
|
506
|
+
return Math.max(1000, diffMin * 60 * 1000 - curSec * 1000)
|
|
507
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-superagent",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.98",
|
|
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",
|