dsh-session-superagent 0.9.243 → 0.9.244

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 CHANGED
@@ -2,6 +2,55 @@
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.244] - 2026-11-05 —— `lastReported` 是唯一没有上限的集合
6
+
7
+ ### 问题
8
+
9
+ T36 审计「跑久了会怎样」:29 个持久化字段里 **28 个有封顶**,只有一个没有 —— `lastReported`。
10
+
11
+ ```js
12
+ export function recordReported(state, fresh, now = Date.now()) {
13
+ const next = { ...(state.lastReported ?? {}) } // 只增不减
14
+ for (const item of fresh ?? []) next[String(item.number)] = now
15
+ return next
16
+ }
17
+ ```
18
+
19
+ 同一个文件里的 `pruneSeen()` 把 `seen` 剪到 200 条 / 30 天,而**同一个 item 编号也进 `lastReported`,却永不修剪**。
20
+ 它唯一被读的地方是 **180 秒**冷却判断 —— 180 秒以外的记录纯属垃圾。
21
+
22
+ 实测(20 条守 × 4000 轮):`lastReported` 从 8,608 条涨到 **35,019 条**,`watchers.json` 1.56 MB。
23
+ 按 30 天推算约 **14 MB**,每天 28,800 次 `persistEntry` × 每次 2 份全量写 = **0.8 TB/天** 磁盘写入。
24
+
25
+ ### 改法
26
+
27
+ 按「时间窗 + 条数上限」双向封顶(24 小时 / 200 条):
28
+
29
+ ```
30
+ 4000 轮后:35,019 条 → 200 条
31
+ JSON:约 1.4 MB → 4.4 KB
32
+ ```
33
+
34
+ ### 顺带修 W2:暂停一条守之后它还会再 tick 一次
35
+
36
+ `watch_stop` 工具只清 `timers`,漏了 `bootTimers` —— 刚建好还在首轮错峰等待的守被暂停后,
37
+ 那个 `setTimeout` 仍会 fire,于是**已经停掉的守还会再轮询一次**(含真实 gh 请求,甚至建 worktree)。
38
+
39
+ 改用 `stopWatcher()`(两者都清)。
40
+
41
+ ### 确认有界的部分(不必担心)
42
+
43
+ `events` 20 / `history` 20 / `filteredLog` 5 / `absorbedLog` 20 / `seen` 200(30 天) /
44
+ `wakeTimes` 1 小时 / `dailyWakes` 7 天 / `lastStates` ≤100 —— 20 条守理论上限 496 KB;
45
+ worktree 稳态 6 个,与运行时长无关;6 处定时器全部成对清除。
46
+
47
+ ### 证据
48
+
49
+ ```
50
+ npm test → 383/383(新增:lastReported 必须有界)
51
+ 实测:4000 轮后 200 条 / 4.4 KB
52
+ ```
53
+
5
54
  ## [0.9.243] - 2026-11-05 —— 装好了吗?现在有一条客户自己能跑的命令
6
55
 
7
56
  ### 问题
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: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
- [![Version](https://img.shields.io/badge/version-0.9.243-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.9.244-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
7
7
  [![npm](https://img.shields.io/npm/v/dsh-session-superagent.svg)](https://www.npmjs.com/package/dsh-session-superagent)
8
8
  [![dsh](https://img.shields.io/badge/DeepSeek%20Harness-plugin-orange.svg)](https://github.com/topics/dsh-plugin)
9
9
  [![awesome](https://img.shields.io/badge/awesome-dsh--plugin-%E2%9C%93-success.svg)](https://github.com/awesome-dsh-plugin/awesome-dsh-plugin)
@@ -146,7 +146,7 @@ Gitee 私有仓库要在「设置 → 凭证」填私人令牌;公开仓库不
146
146
  ## 开发
147
147
 
148
148
  ```sh
149
- npm test # 382 项单测(带离线开关;裸 node --test 会真去 spawn gh,两分半)
149
+ npm test # 383 项单测(带离线开关;裸 node --test 会真去 spawn gh,两分半)
150
150
  ```
151
151
 
152
152
  ### 工具输出:文本给人和 agent,JSON 给程序
@@ -206,7 +206,7 @@ dsh plugin --profile <profile> add dsh-session-superagent@latest
206
206
 
207
207
 
208
208
  ```bash
209
- npm test # 382 项单测(带离线开关,约 1.6 秒)
209
+ npm test # 383 项单测(带离线开关,约 1.6 秒)
210
210
  node scripts/ui-audit.mjs # 11 项 UI 指标(写死颜色 / 自造 token / 官方结构采用 …)
211
211
  node scripts/preflight.mjs # 40 项门禁(含上面两条,外加 profile 一致性、路由面、包内容)
212
212
  node scripts/render-preview.mjs preview.html # 双主题静态预览,直接浏览器打开
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.243'
17
+ const CLIENT_VERSION = '0.9.244'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
package/lib/index.js CHANGED
@@ -44,7 +44,7 @@ import {
44
44
 
45
45
  export const name = 'dsh-session-superagent'
46
46
  /** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
47
- export const SERVER_VERSION = '0.9.243'
47
+ export const SERVER_VERSION = '0.9.244'
48
48
  export const inject = ['tools', 'agents', 'webServer']
49
49
  /** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
50
50
  // 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
@@ -2947,8 +2947,11 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2947
2947
  }
2948
2948
  state.watchers[id].enabled = false
2949
2949
  writeState(state)
2950
- const timer = timers.get(id)
2951
- if (timer) { clearInterval(timer); timers.delete(id) }
2950
+ // 审核 T36 W2:以前这里只清 `timers`,漏了 `bootTimers` ——
2951
+ // 刚建好还没开始轮询的守(首轮错峰等待中)被暂停后,那个 `setTimeout` 仍会 fire,
2952
+ // 于是**已经停掉的守还会再 tick 一次**(含 gh 请求、可能建 worktree)。
2953
+ // `stopWatcher()` 两者都清,直接用它。
2954
+ stopWatcher(id)
2952
2955
  if (args && args.format === 'json') return JSON.stringify({ schemaVersion: 1, ok: true, id, repo: args.repo })
2953
2956
  return `stopped ${id}`
2954
2957
  },
package/lib/watch.js CHANGED
@@ -58,11 +58,29 @@ export function splitFresh(items, state = {}, options = {}) {
58
58
  return partitionItems(items, state, options).fresh
59
59
  }
60
60
 
61
- /** Remember when each item was reported, so the cooldown window can start. */
62
- export function recordReported(state, fresh, now = Date.now()) {
63
- const next = { ...(state.lastReported ?? {}) }
61
+ /**
62
+ * Remember when each item was reported, so the cooldown window can start.
63
+ *
64
+ * 审核 T36 M1:这是**唯一没有上限的集合**。`seen` 有 `pruneSeen()`(200 条 / 30 天),
65
+ * 而 `lastReported` 只增不减 —— 每次唤醒写一条,20 条守 × 60 秒跑 30 天约 **14 MB**,
66
+ * 而它唯一被读的地方是 180 秒冷却判断(`REPORT_COOLDOWN_MS`)。180 秒以外的记录纯属垃圾。
67
+ *
68
+ * 现在只保留「冷却窗口还有意义」的那一段,并加一道条数上限兜底。
69
+ */
70
+ export function recordReported(state, fresh, now = Date.now(), options = {}) {
71
+ const maxAgeMs = Number(options.maxAgeMs) || 24 * 3600 * 1000
72
+ const maxEntries = Number(options.maxEntries) || 200
73
+ const next = {}
74
+ // 先按时间窗留下还有用的(下一步再写入新的)
75
+ for (const [key, at] of Object.entries(state.lastReported ?? {})) {
76
+ const t = Number(at)
77
+ if (Number.isFinite(t) && now - t <= maxAgeMs) next[key] = t
78
+ }
64
79
  for (const item of fresh ?? []) next[String(item.number)] = now
65
- return next
80
+ const trimmed = Object.entries(next)
81
+ .sort((a, b) => b[1] - a[1])
82
+ .slice(0, maxEntries)
83
+ return Object.fromEntries(trimmed)
66
84
  }
67
85
 
68
86
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.9.243",
3
+ "version": "0.9.244",
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",