dsh-session-superagent 0.8.59 → 0.8.61

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,53 @@
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.8.61] - 2026-11-02 —— 状态文件写坏了,也别把客户的守当"空"
6
+
7
+ ### 学到的(知识库第 10 条)
8
+ SQLite 的 WAL 思路:**先保证有一份已提交的好副本**,主文件坏了还能恢复;
9
+ 而不是"就地覆盖,坏了就从头开始"。
10
+ <https://www.sqlite.org/wal.html>
11
+
12
+ 我们的 `watchers.json` 有原子写 + 合并写 + 墓碑,但**只有一份**。
13
+ 主文件被写坏(断电、磁盘满、手改、杀软截断)时,`readState()` 直接返回空 ——
14
+ 客户看到的是「所有守一夜消失」。
15
+
16
+ ### 改了什么
17
+ 1. 覆盖前若当前主文件**能正常解析**,先存成 `watchers.json.bak`;
18
+ 2. 读取时主文件坏了 → 退回 `.bak` 并写回主文件;
19
+ 3. 备份也坏 → 坏文件改名 `watchers.json.corrupt-<时间戳>` 留证,再从空状态开始;
20
+ 4. `/state` 暴露 `stateSource`(ok / backup / corrupt / new)。
21
+
22
+ ### 顺带修的测试问题
23
+ `/update` 用例会真的访问 npm registry,机器慢时跑到 **5010ms** 才超时失败(本轮真出现)。
24
+ 已给它 60 秒独立超时 —— 这条要验的是「离线也必须给出 current」,不是网速。
25
+
26
+ ### 测试
27
+ - 新增 1 例:造 `.bak` → 主文件写成非法 JSON → 必须从备份恢复,且主文件被修好。合计 **115 例**。
28
+
29
+ ## [0.8.60] - 2026-11-02 —— 保留天数可配;顺手修掉一个会写坏配置的真 bug
30
+
31
+ ### 学到的(知识库第 9 条)
32
+ GitHub Actions 的产物保留天数可按仓库配(默认 90 天,1–90 可选)——
33
+ 会长期增长的资源(日志/产物/缓存)应当**可调 + 有默认值 + 有上下限**。
34
+ <https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-workflow-runs/removing-workflow-artifacts>
35
+
36
+ 我们的 `isolateKeepDays` 服务端早就支持(默认 3 天),**面板一直没有入口**。
37
+
38
+ ### 改了什么
39
+ 1. 编辑表单加「隔离区保留天数」(留空用默认 3),保存走 `/watch`;
40
+ 2. **修掉一个真 bug**:打开编辑态时只回填了 5 个字段(间隔/标签/时段/目标/已指派),
41
+ `observe / isolated / workdir / batchLimit / maxWakesPerHour` 都没填 ——
42
+ 打开一条"隔离执行"的守、不作修改直接「保存」,会把 `isolated` 写回 `false`。
43
+ 已补齐全部 10 个字段。
44
+
45
+ ### 为什么这条只能用源码级守门
46
+ 假 DOM 的 `setState` 是空实现,点标题触发 `setDraft` 后拿不到新渲染,
47
+ 所以行为测不出来。改成**静态检查**:编辑态初始化块必须包含全部 10 个字段名。
48
+
49
+ ### 测试
50
+ - 合计 **114 例**(新增源码级守门)。
51
+
5
52
  ## [0.8.59] - 2026-11-02 —— 孤儿 worktree 删了目录还得 prune;占用看得见
6
53
 
7
54
  ### 学到的(知识库第 8 条)
package/MAINTENANCE.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## 二、当前状态(2026-11-01)
11
11
 
12
- - [x] 七个工具可用(github / repo_here / watch_start / watch_status / watch_stop / watch_ack / watch_doctor),`node --test` 113/113 通过
12
+ - [x] 七个工具可用(github / repo_here / watch_start / watch_status / watch_stop / watch_ack / watch_doctor),`node --test` 115/115 通过
13
13
  - [x] 自回声抑制(逐条水位)
14
14
  - [x] 仅空闲注入(避免草稿回放)
15
15
  - [x] 唤醒失败不推进水位
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.8.59-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.8.61-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
 
@@ -99,7 +99,7 @@ dsh plugin install /path/to/dsh-session-superagent
99
99
  ## 开发
100
100
 
101
101
  ```sh
102
- node --test # 113 项单测
102
+ node --test # 115 项单测
103
103
  ```
104
104
 
105
105
  版本与发布流程见 [UPDATING.md](UPDATING.md),交付门见 [CHECKLIST.md](CHECKLIST.md),接手台账见 [MAINTENANCE.md](MAINTENANCE.md)。
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.8.59'
17
+ const CLIENT_VERSION = '0.8.61'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
@@ -902,6 +902,7 @@ window.__ModuleLoader__.load({
902
902
  isolated: !!draft.isolated,
903
903
  workdir: draft.workdir || '',
904
904
  observe: !!draft.observe,
905
+ isolateKeepDays: Number(draft.isolateKeepDays) || undefined,
905
906
  batchLimit: Number(draft.batchLimit) || undefined,
906
907
  maxWakesPerHour: Number(draft.maxWakesPerHour) || undefined,
907
908
  }),
@@ -982,8 +983,15 @@ window.__ModuleLoader__.load({
982
983
  intervalSec: String(watcher.intervalSec ?? 60),
983
984
  labels: (watcher.filters && watcher.filters.labels ? watcher.filters.labels : []).join(','),
984
985
  activeHours: watcher.activeHours || '',
985
- goal: watcher.note || '',
986
+ goal: watcher.note || watcher.goal || '',
986
987
  onlyAssigned: !!(watcher.filters && watcher.filters.onlyAssigned),
988
+ // 下面这些以前没填 —— 打开一条隔离执行的守再直接保存,会把 isolated 写回 false
989
+ observe: !!watcher.observe,
990
+ isolated: !!watcher.isolated,
991
+ workdir: watcher.workdir || '',
992
+ batchLimit: watcher.batchLimit ? String(watcher.batchLimit) : '',
993
+ maxWakesPerHour: watcher.maxWakesPerHour ? String(watcher.maxWakesPerHour) : '',
994
+ isolateKeepDays: watcher.isolateKeepDays ? String(watcher.isolateKeepDays) : '',
987
995
  })
988
996
  },
989
997
  }, watcher.repo)),
@@ -1029,6 +1037,7 @@ window.__ModuleLoader__.load({
1029
1037
  h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: !!draft.observe, onChange: (v) => setDraft({ ...draft, observe: v }), label: '仅观察' }), '仅观察(只记录不唤醒)'),
1030
1038
  h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: !!draft.isolated, onChange: (v) => setDraft({ ...draft, isolated: v }), label: '隔离执行' }), '隔离执行(每次唤醒开一次性 worktree)'),
1031
1039
  draft.isolated ? field('隔离工作目录', h(Input, { value: draft.workdir || '', placeholder: '绝对路径,留空 = 当前工作目录', onChange: (e) => setDraft({ ...draft, workdir: e.target.value }) })) : null,
1040
+ draft.isolated ? field('隔离区保留天数', h(Input, { value: draft.isolateKeepDays || '', placeholder: '3(1-30)', onChange: (e) => setDraft({ ...draft, isolateKeepDays: e.target.value }) }), '每次唤醒前回收这个天数之前的一次性工作区;留空用默认 3 天') : null,
1032
1041
  h('div', { className: 'dt-actions' },
1033
1042
  h(Btn, { size: 'sm', variant: 'primary', onClick: () => saveEdit(watcher) }, '保存'),
1034
1043
  h(Btn, { size: 'sm', onClick: () => setEditing(null) }, '放弃')))
package/lib/index.js CHANGED
@@ -30,7 +30,7 @@ import {
30
30
 
31
31
  export const name = 'dsh-session-superagent'
32
32
  /** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
33
- export const SERVER_VERSION = '0.8.59'
33
+ export const SERVER_VERSION = '0.8.61'
34
34
  export const inject = ['tools', 'agents', 'webServer']
35
35
 
36
36
  /** 仅供测试:读写状态文件(生产代码不要用)。 */
@@ -71,8 +71,41 @@ let activeBase = DEFAULT_ROUTE_BASE
71
71
  const ROUTES_KEY = Symbol.for('dsh-session-superagent.activeRoutes')
72
72
  const activeRoutes = (globalThis[ROUTES_KEY] ||= [])
73
73
 
74
+ // 最后一次成功读取的来源:正常 / 备份恢复 / 全新。面板与 /diagnose 会带上它。
75
+ let stateSource = 'new'
76
+
77
+ /**
78
+ * 读状态文件。主文件坏了就退回上一次的备份(`.bak`),而不是直接当空状态 ——
79
+ * 当空的后果是「客户所有守一夜消失」,这比多留一个备份文件糟糕得多。
80
+ * 思路同 SQLite 的 WAL:**先保证有一份已提交的好副本**,再覆盖。
81
+ */
74
82
  function readState() {
75
- try { return JSON.parse(readFileSync(STATE_FILE, 'utf8')) } catch { return { watchers: {} } }
83
+ let raw
84
+ try {
85
+ raw = readFileSync(STATE_FILE, 'utf8')
86
+ } catch {
87
+ stateSource = 'new'
88
+ return { watchers: {} }
89
+ }
90
+ try {
91
+ const parsed = JSON.parse(raw)
92
+ stateSource = 'ok'
93
+ return parsed
94
+ } catch {
95
+ // 主文件坏了:试试备份
96
+ try {
97
+ const backup = JSON.parse(readFileSync(STATE_FILE + '.bak', 'utf8'))
98
+ stateSource = 'backup'
99
+ // 把备份写回主文件,避免下次还走恢复路径
100
+ try { writeFileSync(STATE_FILE, JSON.stringify(backup, null, 2)) } catch {}
101
+ return backup
102
+ } catch {
103
+ // 备份也没了/也坏了:把坏文件留个证据,再从空状态开始
104
+ stateSource = 'corrupt'
105
+ try { renameSync(STATE_FILE, STATE_FILE + '.corrupt-' + Date.now()) } catch {}
106
+ return { watchers: {} }
107
+ }
108
+ }
76
109
  }
77
110
 
78
111
  function writeState(state) {
@@ -99,6 +132,13 @@ function writeState(state) {
99
132
  // 原子写:写一半崩掉不该把全部 watcher 清空
100
133
  const tmp = STATE_FILE + '.tmp'
101
134
  writeFileSync(tmp, text)
135
+ // 覆盖前先把「当前这份好的」留成备份:主文件将来被写坏(断电、磁盘满、手改),
136
+ // readState 还能退回来,而不是把客户所有守当成空状态。
137
+ try {
138
+ const current = readFileSync(STATE_FILE, 'utf8')
139
+ JSON.parse(current) // 只有当前文件是好的才备份,别把坏文件备份成"好版本"
140
+ writeFileSync(STATE_FILE + '.bak', current)
141
+ } catch {}
102
142
  try { renameSync(tmp, STATE_FILE) } catch { writeFileSync(STATE_FILE, text) }
103
143
  return merged
104
144
  } catch { return state /* state is best-effort: a failed write must not break a turn */ }
@@ -838,6 +878,7 @@ export function apply(ctx) {
838
878
  updatedAt: new Date().toISOString(),
839
879
  credentials: secretsSummary(),
840
880
  sessionGoal: goalView(ctx, focusSession),
881
+ stateSource,
841
882
  isolation: isolationReport(Object.values(state.watchers || {})),
842
883
  sessionTitle: sessionTitle(focusSession),
843
884
  watchers: watchers.map((w) => ({ ...w, goal: goalView(ctx, w.sessionId) })),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.8.59",
3
+ "version": "0.8.61",
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",