dsh-session-superagent 0.8.35 → 0.8.37

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,56 @@
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.37] - 2026-11-02 —— 状态文件不再丢 watcher(真机丢过两条)
6
+
7
+ ### 真机现象
8
+ 面板上一条盯 `Betsy20/magpie-Jet-Hub` 的主理鱼「异常 / 唤醒 4 小时前」,
9
+ 但状态文件里**一条 watcher 都没有**;另一次是刚用 HTTP 建的 ghost 条目,几秒后就没了。
10
+
11
+ ### 根因
12
+ `writeState()` 是**整份覆盖**。当两个写入者手里的快照不同(宿主热重载时新旧实例交替、
13
+ 或工具与面板同时写),后写的那个会把别人刚建的条目一起抹掉 —— 原子写只能防"写一半崩掉",
14
+ 防不住"用旧快照覆盖新内容"。
15
+
16
+ ### 修法
17
+ `writeState()` 改成**合并写**:
18
+ - 盘上有、内存里没有的条目**一律保留**;
19
+ - 删除时立**墓碑**(`state.deleted[id] = 时间`),只有墓碑里的 id 允许消失,墓碑保留 7 天;
20
+ - 仍然原子落盘(tmp + rename)。
21
+
22
+ ### 测试
23
+ - 新增 2 例:① 迟到的旧快照不能抹掉别人刚建的 watcher;② 删除后,一个仍持有旧快照的写入不能把它复活。合计 **97 例**。
24
+
25
+ ## [0.8.36] - 2026-11-02 —— 面板上那串 `EOF` 原始报错,应该变成人话
26
+
27
+ 真机截图里出现过这样一条:
28
+
29
+ ```
30
+ Get "https://api.github.com/repos/…/issues?state=all&sort=updated&direction=desc&per_page=20": EOF
31
+ ```
32
+
33
+ 它既长又吓人,其实是**网络抖动**(我同一分钟手工跑 `gh api` 返回 14 条,完全正常)。
34
+ 之前只有 401/404/找不到 gh 三种情况有提示,`EOF` 这类网络错误就原样怼给用户看。
35
+
36
+ ### 改法
37
+ 新增纯函数 `classifyGhError(detail)`,把失败分成 `auth / notfound / ratelimit / nogh / network / other`
38
+ 六类,各配一句「该怎么做」;同时把长 URL 压成 `GitHub API 请求`,避免一整条 API 地址占满面板。
39
+
40
+ ```
41
+ EOF → 网络抖动:这一轮没连上 GitHub,已按退避自动重试,不需要手动处理
42
+ HTTP 401 → gh 登录失效:跑 gh auth login,或在面板填 token
43
+ HTTP 403 rate limit → 被 GitHub 限流:等几分钟,或换成带 token 的凭证
44
+ HTTP 404 → 仓库不存在或没权限:检查 owner/name
45
+ gh: command not found → 找不到 gh 命令:确认已安装且在 PATH
46
+ ```
47
+
48
+ ### 顺带修掉的一个隐蔽 bug
49
+ 写这个正则时 `` 被写成了**退格符(0x08)**,导致 `EOF` 那条永远匹配不上 ——
50
+ 是「分类函数跑起来却发现 kind=other」才暴露的。已清掉文件里 4 个控制字符,并加用例钉住六种输入。
51
+
52
+ ### 测试
53
+ - 新增用例:六类输入 + 长 URL 压缩。合计 **95 例**。
54
+
5
55
  ## [0.8.35] - 2026-11-02 —— 面板在跟哪一代,能查了
6
56
 
7
57
  排查热重载问题时一直卡在一个观测盲点:面板每 5 秒轮询 `/state`,但**轮询不落任何痕迹**,
@@ -11,6 +61,19 @@
11
61
  - 客户端探测到前缀并**发生切换**时,写一条 `client-base` 探针(服务端 `CLIENT_NOTE_KEYS` 放行该键)。
12
62
  - 于是 `watchers.json → client['note:client-base']` 能直接回答「这个浏览器现在跟的是哪一代」。
13
63
 
64
+ ### 真机闭环(2026-11-02 10:48:40)
65
+ 用户打开一次「主理鱼」页之后:
66
+
67
+ ```
68
+ note:client-base = /session-superagent/r5 ← 客户端自称在跟 r5
69
+ /session-superagent → routeBase=None(旧 handler,宿主留着)
70
+ /session-superagent/r5 → routeBase=/r5, serverVersion=0.8.35
71
+ ```
72
+
73
+ 时间线正好证明 0.8.34 的重探逻辑在真实环境里工作:
74
+ `02:41` 客户端加载(当时在 r4)→ `02:44:50` 服务端换到 r5 并释放 r4 →
75
+ `02:48:40` 面板首次轮询命中 404 → 重探 → 切到 r5 → 写探针。
76
+
14
77
  ### 测试
15
78
  - 合计 **94 例**(探针属于运行时行为,靠真机确认)。
16
79
 
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` 88/88 通过
12
+ - [x] 七个工具可用(github / repo_here / watch_start / watch_status / watch_stop / watch_ack / watch_doctor),`node --test` 97/97 通过
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.35-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.8.37-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 # 88 项单测
102
+ node --test # 97 项单测
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.35'
17
+ const CLIENT_VERSION = '0.8.37'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
package/lib/index.js CHANGED
@@ -24,15 +24,18 @@ import { redact } from './redact.js'
24
24
  import { decodeBody } from './body.js'
25
25
  import {
26
26
  advanceSeen, applyWatcherAction, batchFresh, decideWake, DEFAULT_ACK_LABEL, formatWatchText,
27
- filterReason, hasAckLabel, inActiveHours, newestUpdatedAt, nextDelayMs, pushFiltered, normalizeFilters, partitionItems, passesFilters,
27
+ classifyGhError, filterReason, hasAckLabel, inActiveHours, newestUpdatedAt, nextDelayMs, pushFiltered, normalizeFilters, partitionItems, passesFilters,
28
28
  mergeFilters, mergePollResult, pruneSeen, pruneWakeTimes, pushHistory, recordReported, staleWorktrees, worktreePlan,
29
29
  } from './watch.js'
30
30
 
31
31
  export const name = 'dsh-session-superagent'
32
32
  /** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
33
- export const SERVER_VERSION = '0.8.35'
33
+ export const SERVER_VERSION = '0.8.37'
34
34
  export const inject = ['tools', 'agents', 'webServer']
35
35
 
36
+ /** 仅供测试:读写状态文件(生产代码不要用)。 */
37
+ export const __test = { readState, writeState }
38
+
36
39
  const STATE_DIR = process.env.DSH_SUPERAGENT_STATE
37
40
  ? String(process.env.DSH_SUPERAGENT_STATE)
38
41
  : join(homedir(), '.dsh', 'state', 'session-superagent')
@@ -75,12 +78,30 @@ function readState() {
75
78
  function writeState(state) {
76
79
  try {
77
80
  mkdirSync(STATE_DIR, { recursive: true })
78
- const text = JSON.stringify(state, null, 1)
81
+ // 合并写:调用方手里的 state 可能是很久以前读的快照(宿主重载、两个实例交替写),
82
+ // 直接整份覆盖会把别人刚建的 watcher 抹掉 —— 真机上丢过两条(一条是用户的)。
83
+ // 规则:盘上有、内存里没有的条目一律保留;只有墓碑里的 id 才允许消失。
84
+ const disk = readState()
85
+ const tombstones = { ...(disk.deleted || {}), ...(state.deleted || {}) }
86
+ const merged = { ...disk, ...state }
87
+ merged.watchers = { ...(disk.watchers || {}) }
88
+ for (const [id, watcher] of Object.entries(state.watchers || {})) merged.watchers[id] = watcher
89
+ const now = Date.now()
90
+ for (const [id, at] of Object.entries(tombstones)) {
91
+ delete merged.watchers[id]
92
+ // 墓碑留 7 天足够覆盖任何迟到写入
93
+ if (now - Date.parse(at) > 7 * 24 * 3600 * 1000) delete tombstones[id]
94
+ }
95
+ if (Object.keys(tombstones).length > 0) merged.deleted = tombstones
96
+ else delete merged.deleted
97
+
98
+ const text = JSON.stringify(merged, null, 1)
79
99
  // 原子写:写一半崩掉不该把全部 watcher 清空
80
100
  const tmp = STATE_FILE + '.tmp'
81
101
  writeFileSync(tmp, text)
82
102
  try { renameSync(tmp, STATE_FILE) } catch { writeFileSync(STATE_FILE, text) }
83
- } catch { /* state is best-effort: a failed write must not break a turn */ }
103
+ return merged
104
+ } catch { return state /* state is best-effort: a failed write must not break a turn */ }
84
105
  }
85
106
 
86
107
  /** Credentials the operator typed in the panel. Never returned in plain text. */
@@ -421,14 +442,8 @@ async function pollOnce(ctx, entry, baseMs) {
421
442
  if (res.code !== 0) {
422
443
  const detail = redact(res.stderr).slice(0, 240)
423
444
  // 常见失败给一句能照着做的提示,别只丢原始 stderr
424
- const hint = /HTTP 401|Bad credentials/i.test(detail)
425
- ? '(gh 登录失效:跑 gh auth login,或在面板填 token)'
426
- : /HTTP 404|Not Found/i.test(detail)
427
- ? '(仓库不存在或没权限:检查 owner/name)'
428
- : /ENOENT|not found.*gh|gh.*not found/i.test(detail)
429
- ? '(找不到 gh 命令:确认已安装且在 PATH)'
430
- : ''
431
- entry.lastError = (detail + hint).slice(0, 300)
445
+ const classified = classifyGhError(detail)
446
+ entry.lastError = (classified.short + classified.hint).slice(0, 300)
432
447
  bumpFailure(entry, baseMs)
433
448
  return
434
449
  }
@@ -764,6 +779,10 @@ export function apply(ctx) {
764
779
  }
765
780
  const result = applyWatcherAction(state, { action, id })
766
781
  if (!result.ok) return json(res, 400, result)
782
+ if (result.deleted) {
783
+ // 立墓碑:否则一个持有旧快照的写入会把这条又"复活"
784
+ state.deleted = { ...(state.deleted || {}), [id]: new Date().toISOString() }
785
+ }
767
786
  if (result.deleted || result.enabled === false) stopWatcher(id)
768
787
  writeState(state)
769
788
  if (result.enabled === true) startWatcher(state.watchers[id])
package/lib/watch.js CHANGED
@@ -383,3 +383,37 @@ export function mergeFilters(base, patch) {
383
383
  if ('assignee' in patch) next.assignee = normalizeFilters({ assignee: patch.assignee }).assignee
384
384
  return next
385
385
  }
386
+
387
+ /**
388
+ * 把 gh 失败时的原始文本归类成「一句话原因 + 该怎么做」。
389
+ *
390
+ * 真机上出现过 `Get "https://api.github.com/...": EOF` 这种直接怼给用户看的原始报错 ——
391
+ * 它既长又吓人,其实是**网络抖动**,自动退避重试就会好。这里把它变成人话。
392
+ *
393
+ * @returns {{ kind: string, short: string, hint: string }}
394
+ */
395
+ export function classifyGhError(detail) {
396
+ const text = String(detail || '')
397
+ // 长 URL 压缩,避免一整条 API 地址占满面板
398
+ const short = text
399
+ .replace(/Get "https?:\/\/[^"]{16,}"/g, 'GitHub API 请求')
400
+ .replace(/Post "https?:\/\/[^"]{16,}"/g, 'GitHub API 请求')
401
+ .slice(0, 200)
402
+
403
+ if (/HTTP 401|Bad credentials|requires authentication/i.test(text)) {
404
+ return { kind: 'auth', short, hint: '(gh 登录失效:跑 gh auth login,或在面板填 token)' }
405
+ }
406
+ if (/HTTP 403|rate limit|API rate limit exceeded/i.test(text)) {
407
+ return { kind: 'ratelimit', short, hint: '(被 GitHub 限流:等几分钟,或换成带 token 的凭证)' }
408
+ }
409
+ if (/ENOENT|not found.*gh|gh: command not found/i.test(text)) {
410
+ return { kind: 'nogh', short, hint: '(找不到 gh 命令:确认已安装且在 PATH)' }
411
+ }
412
+ if (/HTTP 404|HTTP 403|Not Found[\s\S]*404|Not Found/.test(text)) {
413
+ return { kind: 'notfound', short, hint: '(仓库不存在或没权限:检查 owner/name)' }
414
+ }
415
+ if (/EOF|i\/o timeout|connection reset|dial tcp|TLS handshake|no such host|proxyconnect|timeout/i.test(text)) {
416
+ return { kind: 'network', short, hint: '(网络抖动:这一轮没连上 GitHub,已按退避自动重试,不需要手动处理)' }
417
+ }
418
+ return { kind: 'other', short, hint: '' }
419
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.8.35",
3
+ "version": "0.8.37",
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",