dsh-session-superagent 0.9.193 → 0.9.196
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 +53 -0
- package/README.md +2 -2
- package/client.js +1 -1
- package/lib/index.js +87 -15
- package/lib/watch.js +33 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,59 @@
|
|
|
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.196] - 2026-11-05 —— watch 审计「值得改」三条:定时器诈尸、字符串暂停、坏数组
|
|
6
|
+
|
|
7
|
+
### W1 · 首轮的错峰定时器不能取消
|
|
8
|
+
`startWatcher` 为了错峰开了个一次性 `setTimeout`,但**没登记** —— `stopWatcher` 取消不掉它。
|
|
9
|
+
于是删掉/暂停的守还会「诈尸」轮询一轮。现在登记进 `bootTimers`,stop 与 teardown 都会清。
|
|
10
|
+
|
|
11
|
+
### W2 · `enabled: "false"` 字符串不会暂停
|
|
12
|
+
`watchers.json` 是**人也会手改**的文件。全仓 11 处 `entry.enabled === false` 都只认真布尔,
|
|
13
|
+
写成字符串 `"false"` 或数字 `0` 时守照常轮询。统一走 `isEnabled()`:缺省 = 启用,
|
|
14
|
+
`false` / `0` / `"false"` / `"0"` / `"no"` / `"off"` 都算暂停。
|
|
15
|
+
|
|
16
|
+
### W7 · `partitionItems` 收到非数组会抛
|
|
17
|
+
`items ?? []` 只防 null。手写坏的状态或上游返回对象时 `for-of` 抛 `TypeError`,
|
|
18
|
+
而 tick 的 `catch` 会把它当成「这一轮失败」→ 该守**永久退避**。非数组一律当空。
|
|
19
|
+
|
|
20
|
+
### W5 · 暂缓(记录理由)
|
|
21
|
+
「teardown 只清本实例的定时器」改完会让 routes 注册路径整片挂掉 —— 风险/收益不划算。
|
|
22
|
+
先按原样全清,等能拆得更小时再做。**这条不进「已修」清单。**
|
|
23
|
+
|
|
24
|
+
### 证据
|
|
25
|
+
```
|
|
26
|
+
node --test → 336/336(新增:非数组 partitionItems、enabled 字符串/0 两条)
|
|
27
|
+
```
|
|
28
|
+
## [0.9.195] - 2026-11-05 —— watch 并发审计:4 条必须修(全部真跑出来)
|
|
29
|
+
|
|
30
|
+
### M1 · 白名单还漏 13 个字段
|
|
31
|
+
`POLL_RESULT_FIELDS` 是**手维护**的:漏一个 = 「算出来了但没存」。上一轮补的 `lastReopened`/`lastStates` 只是同一类漏的两个。
|
|
32
|
+
这次补上 `etag`(丢了它条件请求永远带不上,每轮全量拉)、`needsReauth`/`lastErrorAt`(doctor 的凭证失效分支永不触发)、
|
|
33
|
+
`filterCounts`(面板「本轮跳过多少」恒 0)等 13 个。**334 条测试全绿挡不住它** —— 用例只枚举了已知的那两个。
|
|
34
|
+
|
|
35
|
+
### M2 · 水位会被并发 tick 写回去
|
|
36
|
+
`watch_ack` 把 `seen[42]` 推到 05:00,并发的那次 tick 手里是 04:59 的快照,收尾整份覆盖 → 水位后退 →
|
|
37
|
+
180 秒冷却期一过,同一条又被算成「新动态」再叫醒一次。两个合并点(`mergePollResult` 与 `writeState`)都改成**只许前进**。
|
|
38
|
+
|
|
39
|
+
### M3 · 写盘失败是静默的
|
|
40
|
+
唤醒已经发出去了、`seen` 却没落盘 → 下一轮重复唤醒,而 `/state` 显示一切正常。
|
|
41
|
+
现在失败会记进 `writeError`(含时间与原因),面板能看见。
|
|
42
|
+
|
|
43
|
+
### M4 · 手写坏的 `wakeTimes` 能让整个面板 500
|
|
44
|
+
`pruneWakeTimes(abc)` 抛 `TypeError` → 该守被 tick 的 catch 抓走进**永久退避**,`/state` 整条 500。
|
|
45
|
+
非数组一律当空处理 —— **坏数据的代价不该是「整个面板挂掉」**。
|
|
46
|
+
|
|
47
|
+
### 证据
|
|
48
|
+
```
|
|
49
|
+
node --test → 334/334(新增:白名单完整性、水位不后退、坏 wakeTimes 三组)
|
|
50
|
+
审核报告:docs/报告-watch并发审计.md(4 必须修 / 7 值得改 / 16 确认没问题)
|
|
51
|
+
```
|
|
52
|
+
## [0.9.194] - 2026-11-05 —— 对比度的「为什么先不修」写进规则对照表
|
|
53
|
+
|
|
54
|
+
面板有独立门禁(,基线 16/13 组)。剩下的全是**官方设计语言的控件细边框**(1.19–1.92)——
|
|
55
|
+
要到 3:1 得用 以上的深灰,那是另一套设计语言。判据写进 ,
|
|
56
|
+
免得下一个接手的人再问一遍「这些红点为什么不修」。
|
|
57
|
+
|
|
5
58
|
## [0.9.193] - 2026-11-05 —— 对比度豁免规则:把「看起来不达标、实际可分辨」的放行
|
|
6
59
|
|
|
7
60
|
### 来源
|
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 # 336 项单测
|
|
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.196'
|
|
18
18
|
let BASE = '/session-superagent'
|
|
19
19
|
/**
|
|
20
20
|
* 挑「最新的那个服务端实例」。
|
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.196'
|
|
46
46
|
export const inject = ['tools', 'agents', 'webServer']
|
|
47
47
|
/** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
|
|
48
48
|
// 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
|
|
@@ -115,6 +115,9 @@ let stateSource = 'new'
|
|
|
115
115
|
* 当空的后果是「客户所有守一夜消失」,这比多留一个备份文件糟糕得多。
|
|
116
116
|
* 思路同 SQLite 的 WAL:**先保证有一份已提交的好副本**,再覆盖。
|
|
117
117
|
*/
|
|
118
|
+
/** 最近一次写盘失败(null = 没失败过)。给 /state 与 doctor 用。 */
|
|
119
|
+
let lastWriteError = null
|
|
120
|
+
|
|
118
121
|
function readState() {
|
|
119
122
|
let raw
|
|
120
123
|
try {
|
|
@@ -158,8 +161,23 @@ function normalizeAckLabel(entry) {
|
|
|
158
161
|
return entry
|
|
159
162
|
}
|
|
160
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
|
+
|
|
161
179
|
function normalizePaused(entry) {
|
|
162
|
-
if (!entry || entry
|
|
180
|
+
if (!entry || isEnabled(entry)) return entry
|
|
163
181
|
if (entry.lastError || entry.lastErrorAt || entry.consecutiveFailures) {
|
|
164
182
|
entry.lastError = null
|
|
165
183
|
entry.lastErrorAt = null
|
|
@@ -168,6 +186,30 @@ function normalizePaused(entry) {
|
|
|
168
186
|
}
|
|
169
187
|
return entry
|
|
170
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* 合并同一个 watcher 的两份记录:**水位只许前进**。
|
|
191
|
+
*
|
|
192
|
+
* 真机事故(0.9.194 审核 M2):`watch_ack` 把 `seen[42]` 推到 05:00,
|
|
193
|
+
* 但并发的那次 tick 手里是 04:59 的快照,收尾整份覆盖 → 水位后退 →
|
|
194
|
+
* 180 秒冷却期一过,同一条又被算成「新动态」再叫醒一次。
|
|
195
|
+
*/
|
|
196
|
+
function mergeWatermark(diskEntry, memEntry) {
|
|
197
|
+
if (!diskEntry) return memEntry
|
|
198
|
+
if (!memEntry) return diskEntry
|
|
199
|
+
const out = { ...diskEntry, ...memEntry }
|
|
200
|
+
const seen = { ...(diskEntry.seen || {}) }
|
|
201
|
+
for (const [key, at] of Object.entries(memEntry.seen || {})) {
|
|
202
|
+
const prev = seen[key]
|
|
203
|
+
if (!prev || Date.parse(at) >= Date.parse(prev)) seen[key] = at
|
|
204
|
+
}
|
|
205
|
+
out.seen = seen
|
|
206
|
+
// lastPoll 同理:晚的那个才是事实
|
|
207
|
+
if (diskEntry.lastPoll && (!out.lastPoll || Date.parse(diskEntry.lastPoll) > Date.parse(out.lastPoll))) {
|
|
208
|
+
out.lastPoll = diskEntry.lastPoll
|
|
209
|
+
}
|
|
210
|
+
return out
|
|
211
|
+
}
|
|
212
|
+
|
|
171
213
|
function writeState(state) {
|
|
172
214
|
try {
|
|
173
215
|
mkdirSync(STATE_DIR, { recursive: true })
|
|
@@ -178,7 +220,9 @@ function writeState(state) {
|
|
|
178
220
|
const tombstones = { ...(disk.deleted || {}), ...(state.deleted || {}) }
|
|
179
221
|
const merged = { ...disk, ...state }
|
|
180
222
|
merged.watchers = { ...(disk.watchers || {}) }
|
|
181
|
-
for (const [id, watcher] of Object.entries(state.watchers || {}))
|
|
223
|
+
for (const [id, watcher] of Object.entries(state.watchers || {})) {
|
|
224
|
+
merged.watchers[id] = mergeWatermark(merged.watchers[id], watcher)
|
|
225
|
+
}
|
|
182
226
|
const now = Date.now()
|
|
183
227
|
for (const [id, at] of Object.entries(tombstones)) {
|
|
184
228
|
delete merged.watchers[id]
|
|
@@ -206,7 +250,19 @@ function writeState(state) {
|
|
|
206
250
|
try { writeFileSync(STATE_FILE + '.bak', text) } catch {}
|
|
207
251
|
}
|
|
208
252
|
return merged
|
|
209
|
-
} catch {
|
|
253
|
+
} catch (error) {
|
|
254
|
+
// 写盘失败以前是**静默**的:唤醒已经发出去了,`seen` 却没落盘 → 下一轮重复唤醒,
|
|
255
|
+
// 而 /state 显示一切正常(审核 M3)。把失败记进状态,让它能被看见。
|
|
256
|
+
lastWriteError = {
|
|
257
|
+
at: new Date().toISOString(),
|
|
258
|
+
message: String((error && error.message) || error).slice(0, 200),
|
|
259
|
+
}
|
|
260
|
+
try {
|
|
261
|
+
const live = state && state.watchers ? state : { watchers: {} }
|
|
262
|
+
live.writeError = lastWriteError
|
|
263
|
+
return live
|
|
264
|
+
} catch { return state /* 兜底:写状态的失败不该让一个 turn 崩掉 */ }
|
|
265
|
+
}
|
|
210
266
|
}
|
|
211
267
|
|
|
212
268
|
/** Credentials the operator typed in the panel. Never returned in plain text. */
|
|
@@ -1277,7 +1333,7 @@ async function pollWithItems(ctx, entry, baseMs, parsed) {
|
|
|
1277
1333
|
const { listed, rest } = splitBatch(fresh, Number(entry.batchLimit) || 3, entry.priorityOrder || entry.priority)
|
|
1278
1334
|
// 暂停/删除可能发生在这一轮轮询期间:以盘上为准
|
|
1279
1335
|
const liveEntry = (readState().watchers || {})[entry.id]
|
|
1280
|
-
if (!liveEntry || liveEntry
|
|
1336
|
+
if (!liveEntry || !isEnabled(liveEntry)) {
|
|
1281
1337
|
entry.lastDeferred = '本轮期间被暂停或删除,跳过唤醒'
|
|
1282
1338
|
return
|
|
1283
1339
|
}
|
|
@@ -1417,6 +1473,10 @@ export function apply(ctx) {
|
|
|
1417
1473
|
return
|
|
1418
1474
|
}
|
|
1419
1475
|
const timers = sharedTimers
|
|
1476
|
+
// 一次性定时器(首轮错峰):**每实例一份** —— teardown 只清自己的,不碰别人的(审核 W5)
|
|
1477
|
+
const bootTimers = new Map()
|
|
1478
|
+
|
|
1479
|
+
|
|
1420
1480
|
// 并发闸的唯一事实源:tick 和 HTTP「立刻」拿到的是两个不同的 entry 对象,
|
|
1421
1481
|
// 靠 entry.polling 标记永远对不上(审核专员 probe-c 实证:同一条被唤醒 3 次)。
|
|
1422
1482
|
// 跨模块实例共享:旧实例还没跑完的那轮,新实例不能同时再跑一遍。
|
|
@@ -1464,7 +1524,7 @@ export function apply(ctx) {
|
|
|
1464
1524
|
const tick = async () => {
|
|
1465
1525
|
// A pause (or delete) can land between two ticks; never poll a watcher
|
|
1466
1526
|
// the operator has just switched off.
|
|
1467
|
-
if (entry
|
|
1527
|
+
if (!isEnabled(entry)) return
|
|
1468
1528
|
// 连续失败后的退避窗口:到点之前一律不碰 API
|
|
1469
1529
|
if (entry.nextAt && Date.now() < Date.parse(entry.nextAt)) return
|
|
1470
1530
|
// 同一个 watcher 不允许两轮并跑(手动「立刻」+ 定时器撞一起会开两个隔离区)
|
|
@@ -1487,12 +1547,16 @@ export function apply(ctx) {
|
|
|
1487
1547
|
}
|
|
1488
1548
|
// unref:宿主本来不会退出,但测试进程不该被这个定时器吊住
|
|
1489
1549
|
timers.set(entry.id, setInterval(tick, every).unref?.())
|
|
1550
|
+
|
|
1490
1551
|
// DSH_SUPERAGENT_NO_POLL=1 只登记不轮询(路由层单测用,避免真去请求 GitHub)
|
|
1491
1552
|
if (process.env.DSH_SUPERAGENT_NO_POLL === '1') return
|
|
1492
1553
|
// 首轮按确定性抖动错峰(0~5 秒),之后按 every 稳定推进
|
|
1493
1554
|
if (firstDelay > 0) {
|
|
1494
|
-
|
|
1555
|
+
// 这个一次性定时器**也要能取消**:以前只 unref 不登记,stop 之后它还会 fire 一次
|
|
1556
|
+
// (审核 W1)—— 删掉/暂停的守会「诈尸」轮询一轮。
|
|
1557
|
+
const boot = setTimeout(() => { bootTimers.delete(entry.id); tick() }, firstDelay)
|
|
1495
1558
|
boot.unref?.()
|
|
1559
|
+
bootTimers.set(entry.id, boot)
|
|
1496
1560
|
} else {
|
|
1497
1561
|
tick()
|
|
1498
1562
|
}
|
|
@@ -1501,6 +1565,9 @@ export function apply(ctx) {
|
|
|
1501
1565
|
// Must run before the entry leaves the state file: a live tick would
|
|
1502
1566
|
// otherwise `persistEntry` the just-deleted watcher straight back.
|
|
1503
1567
|
const stopWatcher = (id) => {
|
|
1568
|
+
// 首轮的错峰定时器也要取消,否则删掉的守还会 tick 一次(W1)
|
|
1569
|
+
const pending = bootTimers.get(id)
|
|
1570
|
+
if (pending) { clearTimeout(pending); bootTimers.delete(id) }
|
|
1504
1571
|
const timer = timers.get(id)
|
|
1505
1572
|
if (timer === undefined) return false
|
|
1506
1573
|
clearInterval(timer)
|
|
@@ -1556,8 +1623,12 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
1556
1623
|
if (!httpServer || typeof httpServer.register !== 'function') return
|
|
1557
1624
|
for (const dispose of activeRoutes) { try { dispose() } catch {} }
|
|
1558
1625
|
activeRoutes.length = 0
|
|
1626
|
+
// W5(旧实例晚到 dispose 会掐死新实例)**暂缓**:改成「只清自己的」会让 routes 注册路径整片挂掉,
|
|
1627
|
+
// 风险/收益不划算。先按原样全清 —— 等能拆得更小时再做。
|
|
1559
1628
|
for (const handle of timers.values()) { try { clearInterval(handle) } catch {} }
|
|
1560
1629
|
timers.clear()
|
|
1630
|
+
for (const handle of bootTimers.values()) { try { clearTimeout(handle) } catch { /* 已停 */ } }
|
|
1631
|
+
bootTimers.clear()
|
|
1561
1632
|
const routes = []
|
|
1562
1633
|
// 宿主热重载时旧实例的路由可能还没 dispose;一条重复会让整个 try 崩掉,
|
|
1563
1634
|
// 面板和所有接口一起 404(2026-11-02 真机踩到 webserver: duplicate exact route)。
|
|
@@ -1604,7 +1675,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
1604
1675
|
provider: w.provider === 'gitee' ? 'gitee' : 'github',
|
|
1605
1676
|
sessionId: w.sessionId,
|
|
1606
1677
|
intervalSec: w.intervalSec,
|
|
1607
|
-
enabled: w
|
|
1678
|
+
enabled: isEnabled(w),
|
|
1608
1679
|
cursor: w.cursor ?? null,
|
|
1609
1680
|
lastPoll: w.lastPoll ?? null,
|
|
1610
1681
|
lastWake: w.lastWake ?? null,
|
|
@@ -1750,7 +1821,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
1750
1821
|
if (action === 'poll') {
|
|
1751
1822
|
const entry = state.watchers && state.watchers[id]
|
|
1752
1823
|
if (!entry) return json(res, 404, { error: 'unknown watcher: ' + id })
|
|
1753
|
-
if (entry
|
|
1824
|
+
if (!isEnabled(entry)) return json(res, 409, { error: 'watcher is paused' })
|
|
1754
1825
|
if (inFlight.has(id)) return json(res, 409, { error: 'already polling', id })
|
|
1755
1826
|
const every = Math.max(30, Number(entry.intervalSec) || 60) * 1000
|
|
1756
1827
|
inFlight.add(id)
|
|
@@ -1765,9 +1836,10 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
1765
1836
|
// 立墓碑:否则一个持有旧快照的写入会把这条又"复活"
|
|
1766
1837
|
state.deleted = { ...(state.deleted || {}), [id]: new Date().toISOString() }
|
|
1767
1838
|
}
|
|
1768
|
-
if (result.deleted || result
|
|
1839
|
+
if (result.deleted || !isEnabled(result)) stopWatcher(id)
|
|
1769
1840
|
writeState(state)
|
|
1770
|
-
|
|
1841
|
+
// 只有「显式启用」才重启轮询:result 可能是部分字段,缺 enabled 时不该把守拉起来
|
|
1842
|
+
if ((result.enabled === true || String(result.enabled) === 'true') && state.watchers[id]) startWatcher(state.watchers[id])
|
|
1771
1843
|
return json(res, 200, result)
|
|
1772
1844
|
}
|
|
1773
1845
|
// 认三种写法:`owner/name` / `gitee:owner/name` / `https://gitee.com/owner/name`。
|
|
@@ -1838,7 +1910,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
1838
1910
|
entry.consecutiveFailures = 0
|
|
1839
1911
|
entry.nextAt = null
|
|
1840
1912
|
// 没传 enabled 就保持原值:只改间隔/标签不该把暂停的 watcher 悄悄恢复
|
|
1841
|
-
entry.enabled = body.enabled === undefined ? (entry
|
|
1913
|
+
entry.enabled = body.enabled === undefined ? isEnabled(entry) : isEnabled({ enabled: body.enabled })
|
|
1842
1914
|
// 暂停/恢复时清掉「上一次的错误」:暂停后不再轮询,旧错误会一直挂在面板上变成假异常
|
|
1843
1915
|
if (body.enabled === false || body.enabled === true) {
|
|
1844
1916
|
entry.lastError = null
|
|
@@ -1935,7 +2007,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
1935
2007
|
lines.push('值守: ' + entries.length + ' 条')
|
|
1936
2008
|
for (const entry of entries) {
|
|
1937
2009
|
lines.push('- ' + entry.repo
|
|
1938
|
-
+ ' | ' + (entry
|
|
2010
|
+
+ ' | ' + (isEnabled(entry) ? '启用' : '已暂停')
|
|
1939
2011
|
+ ' | 间隔 ' + entry.intervalSec + 's'
|
|
1940
2012
|
+ ' | 会话 ' + String(entry.sessionId || '').slice(0, 20)
|
|
1941
2013
|
+ ' | 上次轮询 ' + String(entry.lastPoll || '-')
|
|
@@ -2420,7 +2492,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2420
2492
|
}
|
|
2421
2493
|
|
|
2422
2494
|
// 5. 轮询停滞:定时器丢了或进程被挂起时,面板上一切「正常」,其实早就不看了
|
|
2423
|
-
if (entry
|
|
2495
|
+
if (isEnabled(entry) && entry.lastPoll) {
|
|
2424
2496
|
const intervalMs = (Number(entry.intervalSec) || 60) * 1000
|
|
2425
2497
|
const staleMs = Math.max(intervalMs * 3, 5 * 60 * 1000)
|
|
2426
2498
|
const age = Date.now() - Date.parse(entry.lastPoll)
|
|
@@ -2439,7 +2511,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2439
2511
|
|
|
2440
2512
|
// 6. 最近一次状态
|
|
2441
2513
|
const last = entry.lastError ? `错误:${entry.lastError}` : entry.lastDeferred ? `等待:${entry.lastDeferred}` : '正常'
|
|
2442
|
-
lines.push(`INFO ${entry
|
|
2514
|
+
lines.push(`INFO ${isEnabled(entry) ? '运行中' : '已暂停'} · 上次轮询 ${entry.lastPoll || '无'} · ${last}`)
|
|
2443
2515
|
}
|
|
2444
2516
|
// format=json 时从同一份文本行解析出结构 —— 单一来源,不会出现两套逻辑走偏
|
|
2445
2517
|
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
|
|
@@ -412,7 +415,10 @@ export function nextDelayMs(entry, baseMs) {
|
|
|
412
415
|
/** 每小时唤醒上限:把过去一小时的唤醒时间戳剪掉再判断。 */
|
|
413
416
|
export function pruneWakeTimes(times, now = Date.now()) {
|
|
414
417
|
const floor = now - 60 * 60 * 1000
|
|
415
|
-
|
|
418
|
+
// 手写坏的值("abc" / {} / 0)以前会让这里抛 TypeError:①该守被 tick 的 catch 抓走进永久退避,
|
|
419
|
+
// ②/state 整条 500(面板全灭)。非数组一律当空处理 —— 坏数据的代价不该是「整个面板挂掉」。
|
|
420
|
+
const list = Array.isArray(times) ? times : []
|
|
421
|
+
return list.map(Number).filter((t) => Number.isFinite(t) && t >= floor)
|
|
416
422
|
}
|
|
417
423
|
|
|
418
424
|
|
|
@@ -563,9 +569,16 @@ export const POLL_RESULT_FIELDS = [
|
|
|
563
569
|
'history', 'lastWorktree', 'lastAcked', 'lastTrigger',
|
|
564
570
|
// 过滤记录也是轮询结果:漏了它面板上的「最近被过滤」永远是空的
|
|
565
571
|
'filteredLog',
|
|
566
|
-
// lastReopened / lastStates 是「这一轮判出重新打开」的产物:漏了它们,
|
|
567
|
-
// /state 永远回 null,面板上的 ⚠ 与 problems 也永远不出现(对 GitHub 同样成立)。
|
|
568
|
-
'lastReopened', 'lastStates',
|
|
572
|
+
// lastReopened / lastStates 是「这一轮判出重新打开」的产物:漏了它们,
|
|
573
|
+
// /state 永远回 null,面板上的 ⚠ 与 problems 也永远不出现(对 GitHub 同样成立)。
|
|
574
|
+
'lastReopened', 'lastStates',
|
|
575
|
+
// 审核(0.9.194)又数出 13 个:**都是轮询结果,却全被写盘丢掉**。
|
|
576
|
+
// 最关键的是 etag —— 丢了它,条件请求永远带不上,每轮都在全量拉;
|
|
577
|
+
// 其次是 needsReauth / lastErrorAt —— doctor 的「凭证失效」分支永远不会触发。
|
|
578
|
+
// 教训:白名单是**手维护的**,新增字段时必须同时加进来,否则「算出来了但没存」。
|
|
579
|
+
'etag', 'needsReauth', 'lastErrorAt', 'deferReason', 'silentWakes', 'prevWakeAt',
|
|
580
|
+
'dailyWakes', 'absorbedLog', 'filterCounts', 'repoAccess', 'sessionMissingSince',
|
|
581
|
+
'minIntervalSec', 'lastCleanupAt',
|
|
569
582
|
]
|
|
570
583
|
|
|
571
584
|
/**
|
|
@@ -577,6 +590,22 @@ export function mergePollResult(stored, polled) {
|
|
|
577
590
|
for (const key of POLL_RESULT_FIELDS) {
|
|
578
591
|
if (polled && polled[key] !== undefined) merged[key] = polled[key]
|
|
579
592
|
}
|
|
593
|
+
// 水位只许前进:`seen` / `lastPoll` 是「处理到哪」的标记,不是普通字段。
|
|
594
|
+
// 真机事故(0.9.194 审核 M2):`watch_ack` 把 seen[42] 推到 05:00,
|
|
595
|
+
// 并发 tick 手里还是 04:59 的快照,收尾整份覆盖 → 水位后退 → 冷却期一过同一条又被叫醒。
|
|
596
|
+
if (stored && polled) {
|
|
597
|
+
if (stored.seen && polled.seen) {
|
|
598
|
+
const seen = { ...polled.seen }
|
|
599
|
+
for (const [key, at] of Object.entries(stored.seen)) {
|
|
600
|
+
const prev = seen[key]
|
|
601
|
+
if (!prev || Date.parse(at) > Date.parse(prev)) seen[key] = at
|
|
602
|
+
}
|
|
603
|
+
merged.seen = seen
|
|
604
|
+
}
|
|
605
|
+
if (stored.lastPoll && merged.lastPoll && Date.parse(stored.lastPoll) > Date.parse(merged.lastPoll)) {
|
|
606
|
+
merged.lastPoll = stored.lastPoll
|
|
607
|
+
}
|
|
608
|
+
}
|
|
580
609
|
return merged
|
|
581
610
|
}
|
|
582
611
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-superagent",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.196",
|
|
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",
|