dsh-session-superagent 0.9.227 → 0.9.228

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,44 @@
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.228] - 2026-11-05 —— 状态路径惰性化:改 env 立刻生效,不用重新 import
6
+
7
+ ### 上一轮试过、回退了;这一轮做成了
8
+
9
+ T30 的必须修 #2:`lib/index.js` 的四个状态路径在**模块加载那一刻**定死。
10
+ 上一轮尝试惰性化时失败了 —— 因为测试侧「改 env 后从不还原」,惰性化反而让串目录更明显。
11
+
12
+ 这一轮先修好了测试侧(`afterEach` 还原 + `assertTempStateDir()` 守卫),再惰性化,通过了:
13
+
14
+ ```
15
+ npm test → 371/371
16
+ node --test --experimental-test-isolation=none → 371/371
17
+ ```
18
+
19
+ ### 改法
20
+
21
+ ```js
22
+ const stateDir = () => (process.env.DSH_SUPERAGENT_STATE
23
+ ? String(process.env.DSH_SUPERAGENT_STATE)
24
+ : join(homedir(), '.dsh', 'state', 'session-superagent'))
25
+ const stateFile = () => join(stateDir(), 'watchers.json')
26
+ ```
27
+
28
+ 新增一条用例钉住行为:**同一个模块实例,改完 env 之后不重新 import 也要立刻指向新目录**
29
+ (老目录的文件不会被搬走,符合预期)。
30
+
31
+ ### 为什么值得费两轮
32
+
33
+ 「写进真实状态目录」这件事已经真实发生过一次 —— `o/parity#session-parity` 那条假守就是这么进去的,
34
+ 在你机器上一直轮询失败。惰性化把这类事故的根断掉:**路径不再是加载时的快照,而是每次现取**。
35
+
36
+ ### 证据
37
+
38
+ ```
39
+ npm test → 371/371
40
+ node --test --experimental-test-isolation=none → 371/371(新增 1 条惰性用例)
41
+ ```
42
+
5
43
  ## [0.9.227] - 2026-11-05 —— 测试把假的守写进了**真实**状态目录
6
44
 
7
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: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
- [![Version](https://img.shields.io/badge/version-0.9.227-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.9.228-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 # 370 项单测(带离线开关;裸 node --test 会真去 spawn gh,两分半)
149
+ npm test # 371 项单测(带离线开关;裸 node --test 会真去 spawn gh,两分半)
150
150
  ```
151
151
 
152
152
  ### 工具输出:文本给人和 agent,JSON 给程序
@@ -198,7 +198,7 @@ dsh plugin --profile <profile> add dsh-session-superagent@latest
198
198
  ## 验收(不用装宿主也能跑)
199
199
 
200
200
  ```bash
201
- npm test # 370 项单测(带离线开关,约 1.6 秒)
201
+ npm test # 371 项单测(带离线开关,约 1.6 秒)
202
202
  node scripts/ui-audit.mjs # 11 项 UI 指标(写死颜色 / 自造 token / 官方结构采用 …)
203
203
  node scripts/preflight.mjs # 40 项门禁(含上面两条,外加 profile 一致性、路由面、包内容)
204
204
  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.227'
17
+ const CLIENT_VERSION = '0.9.228'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
package/lib/index.js CHANGED
@@ -43,7 +43,7 @@ import {
43
43
 
44
44
  export const name = 'dsh-session-superagent'
45
45
  /** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
46
- export const SERVER_VERSION = '0.9.227'
46
+ export const SERVER_VERSION = '0.9.228'
47
47
  export const inject = ['tools', 'agents', 'webServer']
48
48
  /** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
49
49
  // 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
@@ -77,12 +77,16 @@ const CLEANUP_INTERVAL_MS = 10 * 60 * 1000
77
77
  /** 仅供测试:读写状态文件(生产代码不要用)。 */
78
78
  export const __test = { readState, writeState, hardenSecretsFile, wakeMerged, setAuthStatusCache: (text) => { authStatusCache = { at: text ? Date.now() : 0, text } } }
79
79
 
80
- const STATE_DIR = process.env.DSH_SUPERAGENT_STATE
80
+ // 审核 T30:这四个路径以前在**模块加载那一刻**定死 ——
81
+ // 测试里改 `process.env.DSH_SUPERAGENT_STATE` 之后,已经加载的实例仍然指着老目录,
82
+ // 于是「写进真实状态目录」这种事就会发生(`o/parity` 那条假守就是这么进去的)。
83
+ // 改成惰性求值:每次用到时现读 env。
84
+ const stateDir = () => (process.env.DSH_SUPERAGENT_STATE
81
85
  ? String(process.env.DSH_SUPERAGENT_STATE)
82
- : join(homedir(), '.dsh', 'state', 'session-superagent')
83
- const SECRETS_FILE = join(STATE_DIR, 'secrets.json')
84
- const STATE_FILE = join(STATE_DIR, 'watchers.json')
85
- const TRIGGER_FILE = join(STATE_DIR, 'trigger.json')
86
+ : join(homedir(), '.dsh', 'state', 'session-superagent'))
87
+ const secretsFile = () => join(stateDir(), 'secrets.json')
88
+ const stateFile = () => join(stateDir(), 'watchers.json')
89
+ const triggerFile = () => join(stateDir(), 'trigger.json')
86
90
  // 客户端探针只认这几个键(别的键一律丢弃,防止被任意网页写盘)
87
91
  const CLIENT_NOTE_KEYS = new Set(['client-version', 'client-base', 'apply', 'desk-registered', 'desk-fail', 'orbit-registered', 'orbit-fail', 'orbit-mount', 'badge-registered', 'badge-mount', 'badge-state', 'error'])
88
92
  const DEFAULT_COOLDOWN_MS = 180_000
@@ -126,7 +130,7 @@ let lastWriteError = null
126
130
  function readState() {
127
131
  let raw
128
132
  try {
129
- raw = readFileSync(STATE_FILE, 'utf8')
133
+ raw = readFileSync(stateFile(), 'utf8')
130
134
  } catch {
131
135
  stateSource = 'new'
132
136
  return { watchers: {} }
@@ -139,16 +143,16 @@ function readState() {
139
143
  } catch {
140
144
  // 主文件坏了:试试备份
141
145
  try {
142
- const backup = JSON.parse(readFileSync(STATE_FILE + '.bak', 'utf8'))
146
+ const backup = JSON.parse(readFileSync(stateFile() + '.bak', 'utf8'))
143
147
  for (const entry of Object.values(backup.watchers || {})) { normalizePaused(entry); normalizeAckLabel(entry) }
144
148
  stateSource = 'backup'
145
149
  // 把备份写回主文件,避免下次还走恢复路径
146
- try { writeFileSync(STATE_FILE, JSON.stringify(backup, null, 2)) } catch {}
150
+ try { writeFileSync(stateFile(), JSON.stringify(backup, null, 2)) } catch {}
147
151
  return backup
148
152
  } catch {
149
153
  // 备份也没了/也坏了:把坏文件留个证据,再从空状态开始
150
154
  stateSource = 'corrupt'
151
- try { renameSync(STATE_FILE, STATE_FILE + '.corrupt-' + Date.now()) } catch {}
155
+ try { renameSync(stateFile(), stateFile() + '.corrupt-' + Date.now()) } catch {}
152
156
  return { watchers: {} }
153
157
  }
154
158
  }
@@ -217,7 +221,7 @@ function mergeWatermark(diskEntry, memEntry) {
217
221
 
218
222
  function writeState(state) {
219
223
  try {
220
- mkdirSync(STATE_DIR, { recursive: true })
224
+ mkdirSync(stateDir(), { recursive: true })
221
225
  // 合并写:调用方手里的 state 可能是很久以前读的快照(宿主重载、两个实例交替写),
222
226
  // 直接整份覆盖会把别人刚建的 watcher 抹掉 —— 真机上丢过两条(一条是用户的)。
223
227
  // 规则:盘上有、内存里没有的条目一律保留;只有墓碑里的 id 才允许消失。
@@ -239,20 +243,20 @@ function writeState(state) {
239
243
 
240
244
  const text = JSON.stringify(merged, null, 1)
241
245
  // 原子写:写一半崩掉不该把全部 watcher 清空
242
- const tmp = STATE_FILE + '.tmp'
246
+ const tmp = stateFile() + '.tmp'
243
247
  writeFileSync(tmp, text)
244
248
  // 覆盖前先把「当前这份好的」留成备份:主文件将来被写坏(断电、磁盘满、手改),
245
249
  // readState 还能退回来,而不是把客户所有守当成空状态。
246
250
  try {
247
- const current = readFileSync(STATE_FILE, 'utf8')
251
+ const current = readFileSync(stateFile(), 'utf8')
248
252
  JSON.parse(current) // 只有当前文件是好的才备份,别把坏文件备份成"好版本"
249
- writeFileSync(STATE_FILE + '.bak', current)
253
+ writeFileSync(stateFile() + '.bak', current)
250
254
  } catch {}
251
- try { renameSync(tmp, STATE_FILE) } catch { writeFileSync(STATE_FILE, text) }
255
+ try { renameSync(tmp, stateFile()) } catch { writeFileSync(stateFile(), text) }
252
256
  // 第一次写入时盘上还没有好文件,`.bak` 会是空的 —— 那就等于没有备份。
253
257
  // 主文件一坏(断电/手改/磁盘满)就会丢掉全部守。所以这里补一份引导备份。
254
- if (!existsSync(STATE_FILE + '.bak')) {
255
- try { writeFileSync(STATE_FILE + '.bak', text) } catch {}
258
+ if (!existsSync(stateFile() + '.bak')) {
259
+ try { writeFileSync(stateFile() + '.bak', text) } catch {}
256
260
  }
257
261
  return merged
258
262
  } catch (error) {
@@ -273,17 +277,17 @@ function writeState(state) {
273
277
  /** Credentials the operator typed in the panel. Never returned in plain text. */
274
278
  function readSecrets() {
275
279
  try {
276
- const raw = JSON.parse(readFileSync(SECRETS_FILE, 'utf8'))
280
+ const raw = JSON.parse(readFileSync(secretsFile(), 'utf8'))
277
281
  return raw && typeof raw === 'object' ? raw : {}
278
282
  } catch { return {} }
279
283
  }
280
284
 
281
285
  function writeSecrets(next) {
282
286
  try {
283
- mkdirSync(STATE_DIR, { recursive: true })
284
- writeFileSync(SECRETS_FILE, JSON.stringify(next, null, 1), { mode: 0o600 })
287
+ mkdirSync(stateDir(), { recursive: true })
288
+ writeFileSync(secretsFile(), JSON.stringify(next, null, 1), { mode: 0o600 })
285
289
  // mode 在 Windows 上几乎无效,补 ACL(见 hardenSecretsFile 注释)
286
- hardenSecretsFile(SECRETS_FILE)
290
+ hardenSecretsFile(secretsFile())
287
291
  } catch {}
288
292
  }
289
293
 
@@ -2246,10 +2250,10 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2246
2250
  const sweepTrigger = () => {
2247
2251
  // 测试通道:默认关闭。开着等于给本机任意进程一个「以用户口吻注入任意文本」的入口。
2248
2252
  if (process.env.DSH_SUPERAGENT_TRIGGER !== '1') return
2249
- if (!existsSync(TRIGGER_FILE)) return
2253
+ if (!existsSync(triggerFile())) return
2250
2254
  let payload = {}
2251
- try { payload = JSON.parse(readFileSync(TRIGGER_FILE, 'utf8')) } catch {}
2252
- try { unlinkSync(TRIGGER_FILE) } catch {}
2255
+ try { payload = JSON.parse(readFileSync(triggerFile(), 'utf8')) } catch {}
2256
+ try { unlinkSync(triggerFile()) } catch {}
2253
2257
  const state = readState()
2254
2258
  const any = Object.values(state.watchers || {}).find((w) => w && w.enabled)
2255
2259
  const sessionId = payload.sessionId || (any && any.sessionId)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.9.227",
3
+ "version": "0.9.228",
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",