dsh-session-superagent 0.9.95 → 0.9.97

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,42 @@
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.97] - 2026-11-02 —— 状态文件坏了会全丢:因为第一次写入没留备份
6
+
7
+ ### 查出来的(三条路径都跑了一遍)
8
+ | 场景 | 修复前 | 修复后 |
9
+ |---|---|---|
10
+ | 正常写入 | 1 条守 | 1 条守 + `.bak` |
11
+ | 主文件被截断 | **0 条守(全丢!)** | 1 条守(从备份恢复) |
12
+ | 主 + 备份都坏 | 0 条守 + `.corrupt-*` 留证 | 同左(本就正确) |
13
+
14
+ 根因很具体:`writeState` **只在"盘上已有好的主文件"时才写 `.bak`** ——
15
+ 所以**第一次写入之后、第二次写入之前**这段时间里,一次损坏就是全部丢失。
16
+
17
+ ### 改法
18
+ 1. 写完主文件后,如果 `.bak` 不存在就补一份(引导备份);
19
+ 2. `watch_doctor` 增加状态来源说明:`状态文件坏过一次,已从备份恢复(原文件留在 .corrupt-*)`;
20
+ 都坏时明确说「已从空状态开始……请重新添加守」。
21
+
22
+ ### 测试
23
+ - 新增 2 例:第一次写入就有备份、主文件截断后能恢复 1 条守;都坏时从空开始且留 `.corrupt-*`。合计 **209 例**。
24
+
25
+ ## [0.9.96] - 2026-11-02 —— 刚重启 ≠ 定时器丢了
26
+
27
+ ### 为什么
28
+ 上一版加的停滞检查(`age > max(3×interval, 5min)`)有一个假警报:
29
+ **宿主重启后**,`lastPoll` 天然是几小时前的,doctor 立刻报「定时器可能丢了」——
30
+ 而客户只是刚重启。**假故障比没检查更糟**,客户会开始不信这个自检。
31
+
32
+ ### 改法
33
+ - 记录 `PROCESS_STARTED_AT`,写进 `state.server.startedAt`;
34
+ - 停滞判断加一个前提:**进程 uptime 也超过停滞周期**才报故障;
35
+ - 否则给一条如实说明:`上次轮询是 120 分钟前,但进程才启动 1 分钟 —— 刚重启,等下一轮即可`。
36
+
37
+ ### 测试
38
+ - 更新 1 例(原「定时器丢了」用例补上"进程已跑 4 小时"的前提);
39
+ - 新增 1 例:刚重启 → 出现「刚重启」、不出现「定时器可能丢了」;进程跑够 3 小时 → 才报故障。合计 **207 例**。
40
+
5
41
  ## [0.9.95] - 2026-11-02 —— 长跑体积实测:20 条守跑 30 天 204 KB → 165 KB
6
42
 
7
43
  ### 怎么量的
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.95-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.9.97-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
 
@@ -121,7 +121,7 @@ dsh plugin install /path/to/dsh-session-superagent
121
121
  ## 开发
122
122
 
123
123
  ```sh
124
- node --test # 206 项单测
124
+ node --test # 209 项单测
125
125
  ```
126
126
 
127
127
  ### 工具输出:文本给人和 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.95'
17
+ const CLIENT_VERSION = '0.9.97'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
package/lib/index.js CHANGED
@@ -40,9 +40,11 @@ import {
40
40
 
41
41
  export const name = 'dsh-session-superagent'
42
42
  /** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
43
- export const SERVER_VERSION = '0.9.95'
43
+ export const SERVER_VERSION = '0.9.97'
44
44
  export const inject = ['tools', 'agents', 'webServer']
45
45
  /** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
46
+ // 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
47
+ const PROCESS_STARTED_AT = Date.now()
46
48
  const DEFAULT_SESSION_WAKES = 12
47
49
  // 一条会话最多挂多少守:再多轮询压力与上下文都会失控(20 条 × 每 60 秒已很密)
48
50
  const MAX_WATCHERS_PER_SESSION = 20
@@ -156,6 +158,11 @@ function writeState(state) {
156
158
  writeFileSync(STATE_FILE + '.bak', current)
157
159
  } catch {}
158
160
  try { renameSync(tmp, STATE_FILE) } catch { writeFileSync(STATE_FILE, text) }
161
+ // 第一次写入时盘上还没有好文件,`.bak` 会是空的 —— 那就等于没有备份。
162
+ // 主文件一坏(断电/手改/磁盘满)就会丢掉全部守。所以这里补一份引导备份。
163
+ if (!existsSync(STATE_FILE + '.bak')) {
164
+ try { writeFileSync(STATE_FILE + '.bak', text) } catch {}
165
+ }
159
166
  return merged
160
167
  } catch { return state /* state is best-effort: a failed write must not break a turn */ }
161
168
  }
@@ -1659,11 +1666,11 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
1659
1666
  }
1660
1667
  }
1661
1668
  const state = readState()
1662
- state.server = { at: new Date().toISOString(), routes: routes.length, failed: failedRoutes, base: activeBase }
1669
+ state.server = { at: new Date().toISOString(), routes: routes.length, failed: failedRoutes, base: activeBase, startedAt: new Date(PROCESS_STARTED_AT).toISOString() }
1663
1670
  writeState(state)
1664
1671
  } catch (error) {
1665
1672
  const state = readState()
1666
- state.server = { at: new Date().toISOString(), routes: routes.length, failed: failedRoutes, error: String((error && error.message) || error).slice(0, 300) }
1673
+ state.server = { at: new Date().toISOString(), routes: routes.length, failed: failedRoutes, error: String((error && error.message) || error).slice(0, 300), startedAt: new Date(PROCESS_STARTED_AT).toISOString() }
1667
1674
  writeState(state)
1668
1675
  }
1669
1676
  const teardown = () => {
@@ -1862,6 +1869,12 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
1862
1869
  const all = Object.values(state.watchers || {})
1863
1870
  const wanted = args.repo ? all.filter((w) => w && w.repo === String(args.repo)) : all
1864
1871
 
1872
+ // -2. 状态来源:从备份或损坏里恢复过,客户有权知道(否则他会纳闷「我的守怎么少了一条」)
1873
+ if (stateSource === 'backup') {
1874
+ lines.push('WARN 状态文件坏过一次,已从备份恢复(原文件留在 .corrupt-* 里,可人工检查)')
1875
+ } else if (stateSource === 'corrupt') {
1876
+ lines.push('FAIL 状态文件和备份都读不了 —— 已从空状态开始,原文件留在 .corrupt-*;请重新添加守')
1877
+ }
1865
1878
  // -1. 版本一致性:文件换了但没重启时,服务端仍然跑老代码(客户端热重载会掩盖这件事)
1866
1879
  const installed = installedVersion()
1867
1880
  if (installed && installed !== SERVER_VERSION) {
@@ -1943,8 +1956,12 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
1943
1956
  const intervalMs = (Number(entry.intervalSec) || 60) * 1000
1944
1957
  const staleMs = Math.max(intervalMs * 3, 5 * 60 * 1000)
1945
1958
  const age = Date.now() - Date.parse(entry.lastPoll)
1946
- if (Number.isFinite(age) && age > staleMs) {
1959
+ const uptimeMs = state.server && state.server.startedAt ? Date.now() - Date.parse(state.server.startedAt) : Infinity
1960
+ // 刚重启时 uptime 还不够一个停滞周期:陈旧只是「还没轮到」,不是故障
1961
+ if (Number.isFinite(age) && age > staleMs && uptimeMs > staleMs) {
1947
1962
  lines.push(`WARN ${entry.repo} 已经 ${Math.round(age / 60000)} 分钟没轮询过(预期每 ${Math.round(intervalMs / 1000)} 秒)—— 定时器可能丢了`)
1963
+ } else if (Number.isFinite(age) && age > staleMs) {
1964
+ lines.push(`INFO ${entry.repo} 上次轮询是 ${Math.round(age / 60000)} 分钟前,但进程才启动 ${Math.round(uptimeMs / 60000)} 分钟 —— 刚重启,等下一轮即可`)
1948
1965
  }
1949
1966
  }
1950
1967
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.9.95",
3
+ "version": "0.9.97",
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",