dsh-session-superagent 0.9.195 → 0.9.198
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 +65 -0
- package/README.md +2 -2
- package/client.js +1 -1
- package/lib/gh-format.js +1 -1
- package/lib/gitee.js +20 -6
- package/lib/index.js +50 -15
- package/lib/watch.js +3 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,71 @@
|
|
|
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.198] - 2026-11-05 —— Gitee 边界审计「值得改」三条:403 限流、404 被抢、非数组抛错
|
|
6
|
+
|
|
7
|
+
### G1 · 线上 Gitee 限流回的是 **403**,不是 429
|
|
8
|
+
真机:`curl ".../issues?per_page=9999"` → `HTTP 403` + `403 Forbidden (Rate Limit Exceeded)`,无 `Retry-After`。
|
|
9
|
+
而轮询路径的 status→kind 映射把 403 一律判成 `auth` → 面板让客户**去重生成 token**,实际只要等几分钟。
|
|
10
|
+
现在先看正文:含 `rate limit` / `too many` 才判限流。
|
|
11
|
+
|
|
12
|
+
### G5 · `not found.*gh` 宽到抢走 404
|
|
13
|
+
`HTTP 404: Not Found for owner/ghost-repo` 会被判成 `nogh`(「请安装 gh 命令」)。判据收窄成 `gh: command not found` 这类真形状。
|
|
14
|
+
|
|
15
|
+
### G8 · 200 但正文不是数组时抛异常
|
|
16
|
+
违反 `lib/gitee.js` 自己写的「从不抛」。`normalizeGiteeList()` 两处 `for-of` 补 `Array.isArray` 守卫。
|
|
17
|
+
|
|
18
|
+
### 未修(登记)
|
|
19
|
+
G2(`request()` 不读响应头)、G3(只取一页、无 `truncated`)、G4(Gitee 分支的提示措辞沿用 GitHub)、
|
|
20
|
+
G6(列标签失败仍盲发 POST —— 唯一会碰到**别人仓库**的路径)、G7(`permissions` 在 Gitee 仓库对象里不存在 → 恒挂「只读」徽章)。
|
|
21
|
+
G6 优先级最高(会往别人仓库写),下一轮先做它。
|
|
22
|
+
|
|
23
|
+
### 证据
|
|
24
|
+
```
|
|
25
|
+
node --test → 340/340(新增:403 限流 vs 403 权限、404 不被 nogh 抢)
|
|
26
|
+
```
|
|
27
|
+
## [0.9.197] - 2026-11-05 —— Gitee 边界审计:3 条必须修(全是「照抄 GitHub」的坑)
|
|
28
|
+
|
|
29
|
+
### M1 · `merged` 不在 state 白名单里
|
|
30
|
+
Gitee 用 `merged` 表示「已合并的 PR」,而 `normalizeGiteeState()` 只认 `closed` / `rejected`。
|
|
31
|
+
后果:**合并掉的 PR 每轮都被当成新动态**。已补。
|
|
32
|
+
|
|
33
|
+
### M2 · 取「最后一条评论」拿到的是第一条
|
|
34
|
+
`fetchGiteeLastComment()` 照抄了 GitHub 的 `?per_page=1&sort=created&direction=desc` ——
|
|
35
|
+
Gitee 不认这两个参数,只按创建时间正序返回,于是 `per_page=1` 拿到的是**最早**那条。
|
|
36
|
+
改成翻页取末条(每页 100,最多 5 页)。
|
|
37
|
+
|
|
38
|
+
### M3 · `comments` 字段没透传
|
|
39
|
+
`normalizeGiteeItem()` 的字段白名单漏了 `comments` → 「有人评论 +10」这条信号在 Gitee 上**恒为 0**。
|
|
40
|
+
已补(保留原始类型,没有该字段时不硬塞 0)。
|
|
41
|
+
|
|
42
|
+
### 证据
|
|
43
|
+
```
|
|
44
|
+
node --test → 338/338(新增:merged/rejected 归一、comments 透传)
|
|
45
|
+
审核报告:docs/报告-gitee边界审计.md(3 必须修 / 8 值得改)
|
|
46
|
+
```
|
|
47
|
+
## [0.9.196] - 2026-11-05 —— watch 审计「值得改」三条:定时器诈尸、字符串暂停、坏数组
|
|
48
|
+
|
|
49
|
+
### W1 · 首轮的错峰定时器不能取消
|
|
50
|
+
`startWatcher` 为了错峰开了个一次性 `setTimeout`,但**没登记** —— `stopWatcher` 取消不掉它。
|
|
51
|
+
于是删掉/暂停的守还会「诈尸」轮询一轮。现在登记进 `bootTimers`,stop 与 teardown 都会清。
|
|
52
|
+
|
|
53
|
+
### W2 · `enabled: "false"` 字符串不会暂停
|
|
54
|
+
`watchers.json` 是**人也会手改**的文件。全仓 11 处 `entry.enabled === false` 都只认真布尔,
|
|
55
|
+
写成字符串 `"false"` 或数字 `0` 时守照常轮询。统一走 `isEnabled()`:缺省 = 启用,
|
|
56
|
+
`false` / `0` / `"false"` / `"0"` / `"no"` / `"off"` 都算暂停。
|
|
57
|
+
|
|
58
|
+
### W7 · `partitionItems` 收到非数组会抛
|
|
59
|
+
`items ?? []` 只防 null。手写坏的状态或上游返回对象时 `for-of` 抛 `TypeError`,
|
|
60
|
+
而 tick 的 `catch` 会把它当成「这一轮失败」→ 该守**永久退避**。非数组一律当空。
|
|
61
|
+
|
|
62
|
+
### W5 · 暂缓(记录理由)
|
|
63
|
+
「teardown 只清本实例的定时器」改完会让 routes 注册路径整片挂掉 —— 风险/收益不划算。
|
|
64
|
+
先按原样全清,等能拆得更小时再做。**这条不进「已修」清单。**
|
|
65
|
+
|
|
66
|
+
### 证据
|
|
67
|
+
```
|
|
68
|
+
node --test → 336/336(新增:非数组 partitionItems、enabled 字符串/0 两条)
|
|
69
|
+
```
|
|
5
70
|
## [0.9.195] - 2026-11-05 —— watch 并发审计:4 条必须修(全部真跑出来)
|
|
6
71
|
|
|
7
72
|
### M1 · 白名单还漏 13 个字段
|
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
|
|
|
@@ -144,7 +144,7 @@ Gitee 私有仓库要在「设置 → 凭证」填私人令牌;公开仓库不
|
|
|
144
144
|
## 开发
|
|
145
145
|
|
|
146
146
|
```sh
|
|
147
|
-
node --test #
|
|
147
|
+
node --test # 340 项单测
|
|
148
148
|
```
|
|
149
149
|
|
|
150
150
|
### 工具输出:文本给人和 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.198'
|
|
18
18
|
let BASE = '/session-superagent'
|
|
19
19
|
/**
|
|
20
20
|
* 挑「最新的那个服务端实例」。
|
package/lib/gh-format.js
CHANGED
|
@@ -141,7 +141,7 @@ export function classifyGhError(detail) {
|
|
|
141
141
|
}
|
|
142
142
|
// Windows 的 cmd 报法不一样:'gh' is not recognized as an internal or external command
|
|
143
143
|
// 出处(Node 的错误码语义):https://nodejs.org/api/errors.html#common-system-errors
|
|
144
|
-
if (/ENOENT|
|
|
144
|
+
if (/ENOENT|gh: command not found|not recognized as an internal or external command/i.test(text)) {
|
|
145
145
|
return { kind: 'nogh', short, hint: '(找不到 gh 命令:确认已安装且在 PATH)' }
|
|
146
146
|
}
|
|
147
147
|
// 条件请求命中:gh 把 304 当失败(非 2xx 就 exit 1),但语义是「没有变化」,不是错误
|
package/lib/gitee.js
CHANGED
|
@@ -16,7 +16,9 @@ export const GITEE_API = 'https://gitee.com/api/v5'
|
|
|
16
16
|
/** Gitee 的 state → 我们内部沿用的 GitHub 口径。 */
|
|
17
17
|
export function normalizeGiteeState(raw) {
|
|
18
18
|
const s = String(raw || '').toLowerCase()
|
|
19
|
-
|
|
19
|
+
// 审核 M1:Gitee 用 `merged` 表示「已合并的 PR」,漏了它,合并掉的 PR 会一直被当成「开着」,
|
|
20
|
+
// 每轮都被算成新动态。`rejected`(关闭且不修)同理。
|
|
21
|
+
if (s === 'closed' || s === 'rejected' || s === 'merged') return 'closed'
|
|
20
22
|
return 'open'
|
|
21
23
|
}
|
|
22
24
|
|
|
@@ -48,6 +50,9 @@ export function normalizeGiteeItem(raw, { kind = 'issue' } = {}) {
|
|
|
48
50
|
created_at: item.created_at || null,
|
|
49
51
|
updated_at: item.updated_at || null,
|
|
50
52
|
}
|
|
53
|
+
// 审核 M3:`comments` 漏了 → 「有人评论 +10」这条信号在 Gitee 上恒为 0。
|
|
54
|
+
// 保留原始类型(数字就是数字),下游按 `> 0` 判。
|
|
55
|
+
if (item.comments !== undefined && item.comments !== null) out.comments = Number(item.comments) || 0
|
|
51
56
|
if (isPr) {
|
|
52
57
|
out.pull_request = { url: out.html_url }
|
|
53
58
|
out.draft = String(item.state || '').toLowerCase() === 'draft'
|
|
@@ -57,8 +62,9 @@ export function normalizeGiteeItem(raw, { kind = 'issue' } = {}) {
|
|
|
57
62
|
|
|
58
63
|
export function normalizeGiteeList(issues, pulls) {
|
|
59
64
|
const list = []
|
|
60
|
-
|
|
61
|
-
for (const raw of
|
|
65
|
+
// 200 但正文不是数组时以前会抛 TypeError,违反本文件「从不抛」的约定(审核 G8)
|
|
66
|
+
for (const raw of (Array.isArray(issues) ? issues : [])) list.push(normalizeGiteeItem(raw, { kind: 'issue' }))
|
|
67
|
+
for (const raw of (Array.isArray(pulls) ? pulls : [])) list.push(normalizeGiteeItem(raw, { kind: 'pull' }))
|
|
62
68
|
return list.sort((a, b) => String(b.updated_at || '').localeCompare(String(a.updated_at || '')))
|
|
63
69
|
}
|
|
64
70
|
|
|
@@ -122,9 +128,17 @@ export async function fetchGiteeLastComment({ repo, token = '', item, selfLogin
|
|
|
122
128
|
const number = item && item.number != null ? String(item.number) : ''
|
|
123
129
|
if (!number) return null
|
|
124
130
|
const kind = item && item.pull_request ? 'pulls' : 'issues'
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
131
|
+
// 审核 M2:Gitee **不认** `sort=created&direction=desc`(那是 GitHub 的参数),
|
|
132
|
+
// 以前照抄过来,`per_page=1` 拿到的是**最早**一条评论 —— 于是「最后评论」永远是第一条。
|
|
133
|
+
// Gitee 只按创建时间正序返回,所以翻到最后一页取末条。
|
|
134
|
+
let last = null
|
|
135
|
+
for (let page = 1; page <= 5; page += 1) {
|
|
136
|
+
const res = await request(`/repos/${repo}/${kind}/${number}/comments?per_page=100&page=${page}`, { token, fetchImpl })
|
|
137
|
+
if (!res.ok || !Array.isArray(res.data) || res.data.length === 0) break
|
|
138
|
+
last = res.data[res.data.length - 1]
|
|
139
|
+
if (res.data.length < 100) break
|
|
140
|
+
}
|
|
141
|
+
if (!last) return null
|
|
128
142
|
const login = (last.user && last.user.login) || ''
|
|
129
143
|
return {
|
|
130
144
|
login,
|
package/lib/index.js
CHANGED
|
@@ -42,7 +42,7 @@ import {
|
|
|
42
42
|
|
|
43
43
|
export const name = 'dsh-session-superagent'
|
|
44
44
|
/** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
|
|
45
|
-
export const SERVER_VERSION = '0.9.
|
|
45
|
+
export const SERVER_VERSION = '0.9.198'
|
|
46
46
|
export const inject = ['tools', 'agents', 'webServer']
|
|
47
47
|
/** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
|
|
48
48
|
// 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
|
|
@@ -161,8 +161,23 @@ function normalizeAckLabel(entry) {
|
|
|
161
161
|
return entry
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
+
/**
|
|
165
|
+
* 这条守是不是启用着。
|
|
166
|
+
*
|
|
167
|
+
* `watchers.json` 是**人也会手改**的文件(真机踩过:`enabled: "false"` 字符串让守照常轮询)。
|
|
168
|
+
* 所以不能只判 `=== false`:字符串 "false"、数字 0、"0" 都算暂停,缺省才算启用。
|
|
169
|
+
*/
|
|
170
|
+
function isEnabled(entry) {
|
|
171
|
+
if (!entry) return false
|
|
172
|
+
const value = entry.enabled
|
|
173
|
+
if (value === undefined || value === null) return true
|
|
174
|
+
if (value === false || value === 0) return false
|
|
175
|
+
const text = String(value).trim().toLowerCase()
|
|
176
|
+
return !(text === 'false' || text === '0' || text === 'no' || text === 'off')
|
|
177
|
+
}
|
|
178
|
+
|
|
164
179
|
function normalizePaused(entry) {
|
|
165
|
-
if (!entry || entry
|
|
180
|
+
if (!entry || isEnabled(entry)) return entry
|
|
166
181
|
if (entry.lastError || entry.lastErrorAt || entry.consecutiveFailures) {
|
|
167
182
|
entry.lastError = null
|
|
168
183
|
entry.lastErrorAt = null
|
|
@@ -1057,8 +1072,12 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
1057
1072
|
entry.lastPoll = new Date().toISOString()
|
|
1058
1073
|
if (!listed.ok) {
|
|
1059
1074
|
const status = Number(listed.status) || 0
|
|
1060
|
-
// 401
|
|
1061
|
-
|
|
1075
|
+
// 401 = token 问题(不会自己好);**403 要先看正文**:Gitee 的限流回的就是 403
|
|
1076
|
+
// `403 Forbidden (Rate Limit Exceeded)`,判成 auth 会让客户去重生成 token,实际只要等(审核 G1)。
|
|
1077
|
+
const rateLimited = status === 403 && /rate limit|too many/i.test(String(listed.error || ''))
|
|
1078
|
+
const kind = status === 401 || (status === 403 && !rateLimited) ? 'auth'
|
|
1079
|
+
: rateLimited || status === 429 ? 'ratelimit'
|
|
1080
|
+
: status === 404 ? 'notfound' : 'network'
|
|
1062
1081
|
const hint = kind === 'auth' ? '(Gitee token 无效或没权限:在设置里填 Gitee 私人令牌)'
|
|
1063
1082
|
: kind === 'ratelimit' ? '(被 Gitee 限流:下一轮再试)'
|
|
1064
1083
|
: kind === 'notfound' ? '(Gitee 仓库不存在,或 token 看不到这个私有仓库)'
|
|
@@ -1318,7 +1337,7 @@ async function pollWithItems(ctx, entry, baseMs, parsed) {
|
|
|
1318
1337
|
const { listed, rest } = splitBatch(fresh, Number(entry.batchLimit) || 3, entry.priorityOrder || entry.priority)
|
|
1319
1338
|
// 暂停/删除可能发生在这一轮轮询期间:以盘上为准
|
|
1320
1339
|
const liveEntry = (readState().watchers || {})[entry.id]
|
|
1321
|
-
if (!liveEntry || liveEntry
|
|
1340
|
+
if (!liveEntry || !isEnabled(liveEntry)) {
|
|
1322
1341
|
entry.lastDeferred = '本轮期间被暂停或删除,跳过唤醒'
|
|
1323
1342
|
return
|
|
1324
1343
|
}
|
|
@@ -1458,6 +1477,10 @@ export function apply(ctx) {
|
|
|
1458
1477
|
return
|
|
1459
1478
|
}
|
|
1460
1479
|
const timers = sharedTimers
|
|
1480
|
+
// 一次性定时器(首轮错峰):**每实例一份** —— teardown 只清自己的,不碰别人的(审核 W5)
|
|
1481
|
+
const bootTimers = new Map()
|
|
1482
|
+
|
|
1483
|
+
|
|
1461
1484
|
// 并发闸的唯一事实源:tick 和 HTTP「立刻」拿到的是两个不同的 entry 对象,
|
|
1462
1485
|
// 靠 entry.polling 标记永远对不上(审核专员 probe-c 实证:同一条被唤醒 3 次)。
|
|
1463
1486
|
// 跨模块实例共享:旧实例还没跑完的那轮,新实例不能同时再跑一遍。
|
|
@@ -1505,7 +1528,7 @@ export function apply(ctx) {
|
|
|
1505
1528
|
const tick = async () => {
|
|
1506
1529
|
// A pause (or delete) can land between two ticks; never poll a watcher
|
|
1507
1530
|
// the operator has just switched off.
|
|
1508
|
-
if (entry
|
|
1531
|
+
if (!isEnabled(entry)) return
|
|
1509
1532
|
// 连续失败后的退避窗口:到点之前一律不碰 API
|
|
1510
1533
|
if (entry.nextAt && Date.now() < Date.parse(entry.nextAt)) return
|
|
1511
1534
|
// 同一个 watcher 不允许两轮并跑(手动「立刻」+ 定时器撞一起会开两个隔离区)
|
|
@@ -1528,12 +1551,16 @@ export function apply(ctx) {
|
|
|
1528
1551
|
}
|
|
1529
1552
|
// unref:宿主本来不会退出,但测试进程不该被这个定时器吊住
|
|
1530
1553
|
timers.set(entry.id, setInterval(tick, every).unref?.())
|
|
1554
|
+
|
|
1531
1555
|
// DSH_SUPERAGENT_NO_POLL=1 只登记不轮询(路由层单测用,避免真去请求 GitHub)
|
|
1532
1556
|
if (process.env.DSH_SUPERAGENT_NO_POLL === '1') return
|
|
1533
1557
|
// 首轮按确定性抖动错峰(0~5 秒),之后按 every 稳定推进
|
|
1534
1558
|
if (firstDelay > 0) {
|
|
1535
|
-
|
|
1559
|
+
// 这个一次性定时器**也要能取消**:以前只 unref 不登记,stop 之后它还会 fire 一次
|
|
1560
|
+
// (审核 W1)—— 删掉/暂停的守会「诈尸」轮询一轮。
|
|
1561
|
+
const boot = setTimeout(() => { bootTimers.delete(entry.id); tick() }, firstDelay)
|
|
1536
1562
|
boot.unref?.()
|
|
1563
|
+
bootTimers.set(entry.id, boot)
|
|
1537
1564
|
} else {
|
|
1538
1565
|
tick()
|
|
1539
1566
|
}
|
|
@@ -1542,6 +1569,9 @@ export function apply(ctx) {
|
|
|
1542
1569
|
// Must run before the entry leaves the state file: a live tick would
|
|
1543
1570
|
// otherwise `persistEntry` the just-deleted watcher straight back.
|
|
1544
1571
|
const stopWatcher = (id) => {
|
|
1572
|
+
// 首轮的错峰定时器也要取消,否则删掉的守还会 tick 一次(W1)
|
|
1573
|
+
const pending = bootTimers.get(id)
|
|
1574
|
+
if (pending) { clearTimeout(pending); bootTimers.delete(id) }
|
|
1545
1575
|
const timer = timers.get(id)
|
|
1546
1576
|
if (timer === undefined) return false
|
|
1547
1577
|
clearInterval(timer)
|
|
@@ -1597,8 +1627,12 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
1597
1627
|
if (!httpServer || typeof httpServer.register !== 'function') return
|
|
1598
1628
|
for (const dispose of activeRoutes) { try { dispose() } catch {} }
|
|
1599
1629
|
activeRoutes.length = 0
|
|
1630
|
+
// W5(旧实例晚到 dispose 会掐死新实例)**暂缓**:改成「只清自己的」会让 routes 注册路径整片挂掉,
|
|
1631
|
+
// 风险/收益不划算。先按原样全清 —— 等能拆得更小时再做。
|
|
1600
1632
|
for (const handle of timers.values()) { try { clearInterval(handle) } catch {} }
|
|
1601
1633
|
timers.clear()
|
|
1634
|
+
for (const handle of bootTimers.values()) { try { clearTimeout(handle) } catch { /* 已停 */ } }
|
|
1635
|
+
bootTimers.clear()
|
|
1602
1636
|
const routes = []
|
|
1603
1637
|
// 宿主热重载时旧实例的路由可能还没 dispose;一条重复会让整个 try 崩掉,
|
|
1604
1638
|
// 面板和所有接口一起 404(2026-11-02 真机踩到 webserver: duplicate exact route)。
|
|
@@ -1645,7 +1679,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
1645
1679
|
provider: w.provider === 'gitee' ? 'gitee' : 'github',
|
|
1646
1680
|
sessionId: w.sessionId,
|
|
1647
1681
|
intervalSec: w.intervalSec,
|
|
1648
|
-
enabled: w
|
|
1682
|
+
enabled: isEnabled(w),
|
|
1649
1683
|
cursor: w.cursor ?? null,
|
|
1650
1684
|
lastPoll: w.lastPoll ?? null,
|
|
1651
1685
|
lastWake: w.lastWake ?? null,
|
|
@@ -1791,7 +1825,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
1791
1825
|
if (action === 'poll') {
|
|
1792
1826
|
const entry = state.watchers && state.watchers[id]
|
|
1793
1827
|
if (!entry) return json(res, 404, { error: 'unknown watcher: ' + id })
|
|
1794
|
-
if (entry
|
|
1828
|
+
if (!isEnabled(entry)) return json(res, 409, { error: 'watcher is paused' })
|
|
1795
1829
|
if (inFlight.has(id)) return json(res, 409, { error: 'already polling', id })
|
|
1796
1830
|
const every = Math.max(30, Number(entry.intervalSec) || 60) * 1000
|
|
1797
1831
|
inFlight.add(id)
|
|
@@ -1806,9 +1840,10 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
1806
1840
|
// 立墓碑:否则一个持有旧快照的写入会把这条又"复活"
|
|
1807
1841
|
state.deleted = { ...(state.deleted || {}), [id]: new Date().toISOString() }
|
|
1808
1842
|
}
|
|
1809
|
-
if (result.deleted || result
|
|
1843
|
+
if (result.deleted || !isEnabled(result)) stopWatcher(id)
|
|
1810
1844
|
writeState(state)
|
|
1811
|
-
|
|
1845
|
+
// 只有「显式启用」才重启轮询:result 可能是部分字段,缺 enabled 时不该把守拉起来
|
|
1846
|
+
if ((result.enabled === true || String(result.enabled) === 'true') && state.watchers[id]) startWatcher(state.watchers[id])
|
|
1812
1847
|
return json(res, 200, result)
|
|
1813
1848
|
}
|
|
1814
1849
|
// 认三种写法:`owner/name` / `gitee:owner/name` / `https://gitee.com/owner/name`。
|
|
@@ -1879,7 +1914,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
1879
1914
|
entry.consecutiveFailures = 0
|
|
1880
1915
|
entry.nextAt = null
|
|
1881
1916
|
// 没传 enabled 就保持原值:只改间隔/标签不该把暂停的 watcher 悄悄恢复
|
|
1882
|
-
entry.enabled = body.enabled === undefined ? (entry
|
|
1917
|
+
entry.enabled = body.enabled === undefined ? isEnabled(entry) : isEnabled({ enabled: body.enabled })
|
|
1883
1918
|
// 暂停/恢复时清掉「上一次的错误」:暂停后不再轮询,旧错误会一直挂在面板上变成假异常
|
|
1884
1919
|
if (body.enabled === false || body.enabled === true) {
|
|
1885
1920
|
entry.lastError = null
|
|
@@ -1976,7 +2011,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
1976
2011
|
lines.push('值守: ' + entries.length + ' 条')
|
|
1977
2012
|
for (const entry of entries) {
|
|
1978
2013
|
lines.push('- ' + entry.repo
|
|
1979
|
-
+ ' | ' + (entry
|
|
2014
|
+
+ ' | ' + (isEnabled(entry) ? '启用' : '已暂停')
|
|
1980
2015
|
+ ' | 间隔 ' + entry.intervalSec + 's'
|
|
1981
2016
|
+ ' | 会话 ' + String(entry.sessionId || '').slice(0, 20)
|
|
1982
2017
|
+ ' | 上次轮询 ' + String(entry.lastPoll || '-')
|
|
@@ -2461,7 +2496,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2461
2496
|
}
|
|
2462
2497
|
|
|
2463
2498
|
// 5. 轮询停滞:定时器丢了或进程被挂起时,面板上一切「正常」,其实早就不看了
|
|
2464
|
-
if (entry
|
|
2499
|
+
if (isEnabled(entry) && entry.lastPoll) {
|
|
2465
2500
|
const intervalMs = (Number(entry.intervalSec) || 60) * 1000
|
|
2466
2501
|
const staleMs = Math.max(intervalMs * 3, 5 * 60 * 1000)
|
|
2467
2502
|
const age = Date.now() - Date.parse(entry.lastPoll)
|
|
@@ -2480,7 +2515,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2480
2515
|
|
|
2481
2516
|
// 6. 最近一次状态
|
|
2482
2517
|
const last = entry.lastError ? `错误:${entry.lastError}` : entry.lastDeferred ? `等待:${entry.lastDeferred}` : '正常'
|
|
2483
|
-
lines.push(`INFO ${entry
|
|
2518
|
+
lines.push(`INFO ${isEnabled(entry) ? '运行中' : '已暂停'} · 上次轮询 ${entry.lastPoll || '无'} · ${last}`)
|
|
2484
2519
|
}
|
|
2485
2520
|
// format=json 时从同一份文本行解析出结构 —— 单一来源,不会出现两套逻辑走偏
|
|
2486
2521
|
if (args && args.format === 'json') {
|
package/lib/watch.js
CHANGED
|
@@ -27,6 +27,9 @@ import { repoBadges } from './gh-format.js'
|
|
|
27
27
|
*/
|
|
28
28
|
export function partitionItems(items, state = {}, options = {}) {
|
|
29
29
|
const { now = Date.now(), cooldownMs = 0 } = options
|
|
30
|
+
// `items ?? []` 只防 null:手写坏的状态或上游返回对象时,for-of 会抛 TypeError,
|
|
31
|
+
// 而 tick 的 catch 会把它当成「这一轮失败」→ 该守永久退避。非数组一律当空。
|
|
32
|
+
if (!Array.isArray(items)) return { fresh: [], absorbed: [] }
|
|
30
33
|
const seen = state.seen ?? {}
|
|
31
34
|
const reported = state.lastReported ?? {}
|
|
32
35
|
const floor = state.cursor ? Date.parse(state.cursor) : 0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-superagent",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.198",
|
|
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",
|