dsh-session-superagent 0.9.242 → 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,102 @@
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
+
54
+ ## [0.9.243] - 2026-11-05 —— 装好了吗?现在有一条客户自己能跑的命令
55
+
56
+ ### 问题
57
+
58
+ T35 指出:装完之后客户**没有任何一条自己能跑的确认命令**。
59
+
60
+ - 没有 `bin`;
61
+ - `watch_doctor` 是**模型工具** —— 只有插件**已经挂载**时才存在。拿它证明「装好了」是**循环论证**;
62
+ - `dsh --profile desktop --dump-config` 被宿主拒绝(Electron 独占该 profile)。
63
+
64
+ ### 改法:`bin/check.mjs`(命令名 `dsh-zhuli`)
65
+
66
+ 不依赖宿主加载,检查五件事:
67
+
68
+ | 检查 | 不通过时说什么 |
69
+ |---|---|
70
+ | 安装副本完整(5 个必需文件) | 缺哪几份 → 重装一次 |
71
+ | 版本号 | 读不出来 = 副本损坏(真的见过这种) |
72
+ | 状态目录与 `watchers.json` | 还没配过 / JSON 坏了(先备份再删掉重配) |
73
+ | 凭证文件 | 存在与否 + **权限**(不打印内容) |
74
+ | 宿主端口 | 连不上只是提醒;宿主在但没挂插件 → 没装进 profile |
75
+
76
+ 本机实跑:
77
+
78
+ ```
79
+ OK 安装副本完整(5 个必需文件都在)
80
+ OK 版本 0.9.242
81
+ OK 已配置 4 条主理鱼(其中 4 条在跑)
82
+ OK 凭证文件存在(权限 666) —— 内容不会被这个命令打印
83
+ OK 宿主在 65466 上,插件已加载,运行版本 0.9.179
84
+ 警告 磁盘上是 0.9.242,宿主跑的是 0.9.179 —— 重启宿主才生效(不是重装)
85
+ ```
86
+
87
+ **最后那行警告正是现在这台机器的真实状态。**
88
+
89
+ ### 顺带
90
+
91
+ - `package.json` 加 `bin` + `files`(打包 12 → 13 个文件),`audit-pack` 的必需清单同步;
92
+ - 新增用例:`bin` 必须存在、指向的文件必须真实、必须在 `files` 里(否则打不进包)。
93
+
94
+ ### 证据
95
+
96
+ ```
97
+ npm test → 382/382(新增:自检命令必须在包里)
98
+ audit-pack → 13 个文件 PASS
99
+ ```
100
+
5
101
  ## [0.9.242] - 2026-11-05 —— 全新客户的第一个 5 分钟
6
102
 
7
103
  T35 走了一遍「从零装这个插件」:**没有任何代码缺陷会挡住安装**,3 条必须修全是文档与可发现性。
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.242-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 # 381 项单测(带离线开关;裸 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 # 381 项单测(带离线开关,约 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 # 双主题静态预览,直接浏览器打开
@@ -236,6 +236,29 @@ node scripts/render-preview.mjs preview.html # 双主题静态预览,直接
236
236
 
237
237
  `pnpm run preflight` 一条命令可自查:单测、语法、profile 一致性、版本一致、路由面、包内容、冒烟。
238
238
 
239
+ ## 装好了吗?跑一条命令就能确认
240
+
241
+ ```bash
242
+ npx dsh-session-superagent
243
+ ```
244
+
245
+ (全局装过的话直接 `dsh-zhuli`。)
246
+
247
+ 它会检查五件事,并告诉你该怎么办:
248
+
249
+ | 检查 | 不通过时它会说 |
250
+ |---|---|
251
+ | 安装副本完整(5 个必需文件) | 缺哪几份 → 重装一次 |
252
+ | 版本号 | 读不出来 = 副本损坏,重装 |
253
+ | 状态目录与 `watchers.json` | 还没配过 / JSON 坏了(先备份再删掉重配) |
254
+ | 凭证文件 | 存在与否、**权限**(不会打印内容) |
255
+ | 宿主端口(默认 65466) | 连不上只是提醒;宿主在但没挂插件 → 没装进 profile |
256
+
257
+ 加 `--port 12345` 指定别的端口。退出码 0 = 通过,1 = 有问题。
258
+
259
+ > 这条命令**不需要宿主加载插件** —— 它只看安装副本、状态目录和端口。
260
+ > 面板里的 `watch_doctor` 也能自查,但那个只有插件**已经挂载**时才存在。
261
+
239
262
  ## 卸载与回滚
240
263
 
241
264
  **卸插件**(一条命令):
package/bin/check.mjs ADDED
@@ -0,0 +1,119 @@
1
+ #!/usr/bin/env node
2
+ // 装完能跑的自检命令(审核 T35)。
3
+ //
4
+ // 为什么需要它:装完之后客户**没有任何一条自己能跑的命令**来确认「到底装上没有」。
5
+ // `watch_doctor` 是模型工具 —— 只有插件**已经挂载**时才存在,拿它证明「装好了」是循环论证。
6
+ //
7
+ // 这个脚本**不依赖宿主加载**:它只看包本身、状态目录、凭证文件,以及(可选)探测宿主端口。
8
+ //
9
+ // 用法:
10
+ // npx dsh-session-superagent # = check
11
+ // npx dsh-session-superagent check # 同上
12
+ // npx dsh-session-superagent check --port 65466
13
+ //
14
+ // 退出码:0 = 一切正常;1 = 有问题(详情会打印出来)。
15
+ import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs'
16
+ import { homedir } from 'node:os'
17
+ import { dirname, join } from 'node:path'
18
+ import { fileURLToPath } from 'node:url'
19
+
20
+ // 这个文件在 bin/ 里,包根是上一层
21
+ const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')
22
+ const args = process.argv.slice(2)
23
+ const portArg = args.includes('--port') ? args[args.indexOf('--port') + 1] : null
24
+
25
+ const lines = []
26
+ let bad = 0
27
+ const ok = (text) => lines.push('OK ' + text)
28
+ const warn = (text) => lines.push('警告 ' + text)
29
+ const fail = (text) => { lines.push('FAIL ' + text); bad += 1 }
30
+
31
+ // ① 包本身完整吗(这几份缺一份,插件就挂不上)
32
+ const NEEDED = ['package.json', 'client.js', 'lib/index.js', 'lib/watch.js', 'cordis.patch.yml']
33
+ const missing = NEEDED.filter((rel) => !existsSync(join(ROOT, rel)))
34
+ if (missing.length > 0) fail('安装副本缺文件:' + missing.join('、') + '(重装一次)')
35
+ else ok('安装副本完整(' + NEEDED.length + ' 个必需文件都在)')
36
+
37
+ let version = '?'
38
+ try {
39
+ version = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8')).version
40
+ ok('版本 ' + version)
41
+ } catch {
42
+ fail('package.json 读不出来 —— 安装副本损坏,重装一次')
43
+ }
44
+
45
+ // ② 状态目录(不读内容,只看在不在)
46
+ const stateDir = process.env.DSH_SUPERAGENT_STATE
47
+ ? String(process.env.DSH_SUPERAGENT_STATE)
48
+ : join(homedir(), '.dsh', 'state', 'session-superagent')
49
+ if (!existsSync(stateDir)) {
50
+ warn('还没有状态目录(' + stateDir + ')—— 装好但还没添加过主理鱼,属正常')
51
+ } else {
52
+ const watchers = join(stateDir, 'watchers.json')
53
+ if (!existsSync(watchers)) warn('有状态目录但没有 watchers.json —— 还没添加过主理鱼')
54
+ else {
55
+ try {
56
+ const state = JSON.parse(readFileSync(watchers, 'utf8'))
57
+ const count = Object.keys(state.watchers || {}).length
58
+ const enabled = Object.values(state.watchers || {}).filter((w) => w && w.enabled !== false).length
59
+ ok('已配置 ' + count + ' 条主理鱼(其中 ' + enabled + ' 条在跑)')
60
+ } catch {
61
+ fail('watchers.json 不是合法 JSON —— 面板会读不出来;先备份它再删掉重配')
62
+ }
63
+ }
64
+ const secrets = join(stateDir, 'secrets.json')
65
+ if (existsSync(secrets)) {
66
+ // 只看权限,不打印内容
67
+ let mode = ''
68
+ try { mode = (statSync(secrets).mode & 0o777).toString(8) } catch {}
69
+ ok('凭证文件存在' + (mode ? '(权限 ' + mode + ')' : '') + ' —— 内容不会被这个命令打印')
70
+ } else {
71
+ ok('没有单独存凭证(回退到已登录的 gh CLI)')
72
+ }
73
+ }
74
+
75
+ // ③ 宿主端口(可选探测:连不上不算失败 —— 插件可能没装进任何 profile)
76
+ const port = Number(portArg || process.env.DSH_PORT || 65466)
77
+ const probe = async () => {
78
+ try {
79
+ const res = await fetch('http://127.0.0.1:' + port + '/session-superagent/state', { signal: AbortSignal.timeout(2500) })
80
+ if (res.status === 404) {
81
+ warn('宿主在 ' + port + ' 上,但没挂这个插件 —— 装进 profile 了吗?(dsh plugin --profile <p> add dsh-session-superagent)')
82
+ return
83
+ }
84
+ if (!res.ok) {
85
+ fail('宿主返回 HTTP ' + res.status + '(' + port + ')—— 插件装上了但报错,去面板「设置 → 版本与更新 → 复制诊断信息」')
86
+ return
87
+ }
88
+ const body = await res.json()
89
+ const running = body.runningVersion || body.serverVersion || '?'
90
+ ok('宿主在 ' + port + ' 上,插件已加载,运行版本 ' + running)
91
+ if (version !== '?' && running !== version) {
92
+ warn('磁盘上是 ' + version + ',宿主跑的是 ' + running + ' —— 重启宿主才生效(不是重装)')
93
+ }
94
+ } catch (error) {
95
+ warn('连不上 ' + port + '(' + String((error && error.message) || error).slice(0, 60) + ')'
96
+ + ' —— 宿主没开、或端口不是这个。用 --port 指定,或忽略(这项不是必过项)')
97
+ }
98
+ }
99
+
100
+ await probe()
101
+
102
+ // ④ 隔离工作区残留(只说有没有,不删)
103
+ const zhuliDirs = []
104
+ try {
105
+ for (const name of readdirSync(homedir())) {
106
+ if (name !== 'projects') continue
107
+ }
108
+ } catch {}
109
+ void zhuliDirs
110
+
111
+ console.log(lines.join('\n'))
112
+ console.log('---')
113
+ if (bad === 0) {
114
+ console.log('自检通过(' + lines.filter((l) => l.startsWith('OK')).length + ' 项 OK,'
115
+ + lines.filter((l) => l.startsWith('警告')).length + ' 项提醒)')
116
+ } else {
117
+ console.log(bad + ' 项不通过 —— 看上面的 FAIL 行')
118
+ process.exitCode = 1
119
+ }
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.242'
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.242'
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.242",
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",
@@ -22,7 +22,8 @@
22
22
  "README.md",
23
23
  "CHANGELOG.md",
24
24
  "LICENSE",
25
- "client.js"
25
+ "client.js",
26
+ "bin/check.mjs"
26
27
  ],
27
28
  "engines": {
28
29
  "node": ">=22.19.0",
@@ -79,5 +80,8 @@
79
80
  "homepage": "https://github.com/MYCF711/dsh-session-superagent#readme",
80
81
  "bugs": {
81
82
  "url": "https://github.com/MYCF711/dsh-session-superagent/issues"
83
+ },
84
+ "bin": {
85
+ "dsh-zhuli": "bin/check.mjs"
82
86
  }
83
87
  }