dsh-session-superagent 0.9.232 → 0.9.233

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,50 @@
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.233] - 2026-11-05 —— 模型照着说明书做,也一定会失败的四条
6
+
7
+ ### ① `watch_stop` 停不掉 Gitee 守(最危险的一条)
8
+
9
+ `watch_status` 的 JSON 给的 `repo` 是 `"Ghandi/workbuddy-pro"`,而 `watch_stop` 用
10
+ `${repo}#${sessionId}` 拼 id —— 可 Gitee 守的实际 id 带 `gitee:` 前缀:
11
+
12
+ ```
13
+ watch_start({repo:"gitee:Ghandi/workbuddy-pro"}) → 建好了
14
+ watch_stop({repo:"Ghandi/workbuddy-pro"}) → no watcher(**守还在每 60 秒轮询**)
15
+ ```
16
+
17
+ **模型每一步都照着说明书做**(读 status → 取 JSON 的 repo → 传给 stop),却仍然失败;
18
+ 而且失败文案是 `(...)` 不是 `[error: …]`,读起来像「已经停了」。
19
+
20
+ 现在两种写法都认,失败文案改成 `[error: …]` 并列出试过的 key。
21
+
22
+ ### ② 20 条上限被 `watch_stop` 卡成死结
23
+
24
+ 报错明说「先 watch_stop 停掉不用的」,但计数**不看 `enabled`**,而 stop 只置 `enabled=false`,
25
+ 8 个工具里又没有删除入口 —— 用户照做之后,同一句报错原样再来。
26
+
27
+ 上限的本意是「同时轮询的定时器别太多」,所以现在**只数还在跑的**。
28
+
29
+ ### ③ `format:'json'` 时错误分支返回纯文本
30
+
31
+ `docs/json-契约.md` 与 README 都承诺「成功/失败都靠 `ok` 判断」,但 7 处 `return '[error: …]'`
32
+ 是纯字符串 —— 模型 `JSON.parse` 直接抛错。
33
+
34
+ 新增 `toolError(args, message)`:`format==='json'` 时返回 `{schemaVersion:1, ok:false, error}`。
35
+
36
+ ### ④ 必填项没进 schema
37
+
38
+ `watch_trace.number` 实现里必填(缺了直接报错),schema 却没标 —— 模型只能靠「调一次失败」才知道。
39
+ 已标 `required: true`;`watch_ack` 的 `number|numbers` 在描述里写明「至少填一个」,
40
+ `number` 类型放宽成 `['number','string']`(Gitee 的编号是 `IKSQJH` 这种字符串)。
41
+
42
+ ### 证据
43
+
44
+ ```
45
+ npm test → 377/377(新增 3 条:JSON 错误结构化 / Gitee 守能停 / 停一条后能加新的)
46
+ ui-audit → 11/11(100 分)
47
+ ```
48
+
5
49
  ## [0.9.232] - 2026-11-05 —— 一个**决定不做**的改动(附理由)
6
50
 
7
51
  T31 建议把「未认领」从唤醒消息里去掉:它无条件出现在每一条上(5 条消息 5 次),
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.232-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.9.233-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 # 374 项单测(带离线开关;裸 node --test 会真去 spawn gh,两分半)
149
+ npm test # 377 项单测(带离线开关;裸 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 # 374 项单测(带离线开关,约 1.6 秒)
201
+ npm test # 377 项单测(带离线开关,约 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.232'
17
+ const CLIENT_VERSION = '0.9.233'
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.232'
46
+ export const SERVER_VERSION = '0.9.233'
47
47
  export const inject = ['tools', 'agents', 'webServer']
48
48
  /** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
49
49
  // 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
@@ -69,6 +69,16 @@ const DEFAULT_WAKES_PER_HOUR = 6
69
69
  const DEFAULT_ISOLATE_KEEP_DAYS = 3
70
70
  // 一条会话最多挂多少守:再多轮询压力与上下文都会失控(20 条 × 每 60 秒已很密)
71
71
  const MAX_WATCHERS_PER_SESSION = 20
72
+
73
+ /**
74
+ * 工具的错误返回(审核 T32 M2):`format: 'json'` 时必须是**结构化**的。
75
+ * 以前这些分支一律返回纯文本 `[error: …]`,而文档承诺「成功/失败都靠 ok 判断」——
76
+ * 模型拿到纯文本再 JSON.parse 就直接抛错。
77
+ */
78
+ function toolError(args, message) {
79
+ if (args && args.format === 'json') return JSON.stringify({ schemaVersion: 1, ok: false, error: message })
80
+ return '[error: ' + message + ']'
81
+ }
72
82
  /** 全局上限:每条守一个定时器,无限建等于自造 DoS(审核 T19)。 */
73
83
  const MAX_WATCHERS_TOTAL = 200
74
84
  /** 隔离区回收的最小间隔:没有超额时不必每次唤醒都跑 git。 */
@@ -2278,8 +2288,9 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2278
2288
  'Mark an issue/PR as handled: adds the ack label on GitHub (主理鱼:已处理 by default) and advances the local watermark, so the same item will never wake this session again — even after a restart or on another machine.',
2279
2289
  parameters: {
2280
2290
  repo: { type: 'string', description: 'owner/name; defaults to the only watched repo' },
2281
- number: { type: 'number', description: 'issue or PR number' },
2282
- numbers: { type: 'string', description: '逗号分隔的多个编号,如 "12,13,14"(与 number 二选一)' },
2291
+ // 审核 T32 M4:实现里这两个必填其一(缺了直接报错),schema 却没标。
2292
+ number: { type: ['number', 'string'], description: 'issue or PR number(Gitee 的编号是字符串,如 IKSQJH)' },
2293
+ numbers: { type: 'string', description: '逗号分隔的多个编号,如 "12,13,14"(number 与 numbers 至少填一个)' },
2283
2294
  label: { type: 'string', description: 'ack label, default 主理鱼:已处理' },
2284
2295
  format: { type: 'string', description: "'text' (default) or 'json'." },
2285
2296
  },
@@ -2290,13 +2301,13 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2290
2301
  .split(',')
2291
2302
  .map((v) => v.trim())
2292
2303
  .filter((v) => /^[A-Za-z0-9_-]+$/.test(v))
2293
- if (numbers.length === 0) return '[error: number (or numbers) is required]'
2304
+ if (numbers.length === 0) return toolError(args, 'number (or numbers) is required')
2294
2305
  const state = readState()
2295
2306
  const watchers = Object.values(state.watchers || {})
2296
2307
  const entry = args.repo
2297
2308
  ? watchers.find((w) => w && w.repo === String(args.repo))
2298
2309
  : watchers.find((w) => w && w.enabled)
2299
- if (!entry) return '[error: no watcher for that repo — start one with watch_start first]'
2310
+ if (!entry) return toolError(args, 'no watcher for that repo — start one with watch_start first')
2300
2311
  const label = String(args.label || entry.ackLabel || defaultAckLabel(entry.provider))
2301
2312
  // GitHub 不会因为加标签而自动建标签:不存在时返回 422。先幂等建一次(已存在也返回 422,忽略)。
2302
2313
  // Gitee 没有「建标签」的独立端点(标签必须先存在),所以这边只打标签;
@@ -2375,7 +2386,8 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2375
2386
  parameters: {
2376
2387
  repo: { type: 'string', description: 'owner/name; defaults to the only watched repo' },
2377
2388
  // Gitee 的 issue 编号是字符串(IKSQJH),写成 number 会被宿主直接拒掉
2378
- number: { type: ['number', 'string'], description: 'issue or PR number to trace' },
2389
+ // 审核 T32 M4:实现里它是必填(缺了直接报错),schema 却没标 —— 模型只能靠调一次失败才知道
2390
+ number: { type: ['number', 'string'], required: true, description: 'issue or PR number to trace' },
2379
2391
  format: { type: 'string', description: "'text' (default) or 'json'." },
2380
2392
  },
2381
2393
  async execute(args) {
@@ -2691,7 +2703,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2691
2703
  const toolAgents = agentsService(ctx)
2692
2704
  const agent = toolAgents && typeof toolAgents.currentInitiator === 'function' ? toolAgents.currentInitiator() : undefined
2693
2705
  const sessionId = agent && agent.id
2694
- if (!sessionId) return '[error: no live session — watch_start must be called from a session turn]'
2706
+ if (!sessionId) return toolError(args, 'no live session — watch_start must be called from a session turn')
2695
2707
 
2696
2708
  let repo = args.repo
2697
2709
  if (!repo) {
@@ -2704,8 +2716,8 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2704
2716
  // 否则工具建出来的守没有 provider,Gitee 仓库会被当 GitHub 轮询,每轮 404。
2705
2717
  const parsedSpecs = String(repo).split(/[,\s]+/).map((item) => item.trim()).filter(Boolean).map((item) => ({ item, spec: parseRepoSpec(item) }))
2706
2718
  const bad = parsedSpecs.filter(({ spec }) => !spec.ok).map(({ item }) => item)
2707
- if (bad.length > 0) return '[error: 仓库要写成 owner/name 或 gitee:owner/name,这些不对:' + bad.join(', ') + ']'
2708
- if (parsedSpecs.length === 0) return '[error: 至少给一个仓库(owner/name)]'
2719
+ if (bad.length > 0) return toolError(args, '仓库要写成 owner/name 或 gitee:owner/name,这些不对:' + bad.join(', '))
2720
+ if (parsedSpecs.length === 0) return toolError(args, '至少给一个仓库(owner/name)')
2709
2721
  const repoList = parsedSpecs.map(({ item, spec }) => ({ repo: spec.repo, provider: spec.provider, label: item }))
2710
2722
  const applyOne = ({ repo, provider }) => {
2711
2723
  const id = (provider === 'gitee' ? 'gitee:' : '') + `${repo}#${sessionId}`
@@ -2737,8 +2749,8 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2737
2749
  if (typeof args.isolated === 'boolean') entry.isolated = args.isolated
2738
2750
  if (typeof args.workdir === 'string' && args.workdir.trim()) {
2739
2751
  const workdir = args.workdir.trim()
2740
- if (!isAbsolute(workdir)) return '[error: workdir must be an absolute path]'
2741
- if (!existsSync(workdir)) return '[error: workdir does not exist: ' + workdir + ']'
2752
+ if (!isAbsolute(workdir)) return toolError(args, 'workdir must be an absolute path')
2753
+ if (!existsSync(workdir)) return toolError(args, 'workdir does not exist: ' + workdir)
2742
2754
  entry.workdir = workdir
2743
2755
  }
2744
2756
  if (typeof args.activeHours === 'string') entry.activeHours = args.activeHours.trim() || null
@@ -2752,9 +2764,12 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2752
2764
  entry.enabled = true
2753
2765
  state.watchers = state.watchers || {}
2754
2766
  if (!existing) {
2755
- const mine = Object.values(state.watchers).filter((w) => w && w.sessionId === sessionId)
2767
+ // 审核 T32 M3:以前数**全部**守(含已停用的),于是报错让用户「先 watch_stop」,
2768
+ // 而 watch_stop 只是置 enabled=false —— 数完还是 20,同一句报错原样再来,成了死结。
2769
+ // 上限的本意是「同时轮询的定时器别太多」,所以只数**还在跑的**。
2770
+ const mine = Object.values(state.watchers).filter((w) => w && w.sessionId === sessionId && w.enabled !== false)
2756
2771
  if (mine.length >= MAX_WATCHERS_PER_SESSION) {
2757
- return '一条会话最多挂 ' + MAX_WATCHERS_PER_SESSION + ' 条守(现在 ' + mine.length + ' 条)—— 先 watch_stop 停掉不用的,或把多个仓库合成一条规则'
2772
+ return '一条会话最多同时挂 ' + MAX_WATCHERS_PER_SESSION + ' 条在跑的守(现在 ' + mine.length + ' 条)—— 先 watch_stop 停掉不用的,或把多个仓库合成一条规则'
2758
2773
  }
2759
2774
  }
2760
2775
  state.watchers[id] = entry
@@ -2776,13 +2791,14 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2776
2791
  // 批量要整批校验:19 条时一次加 2 条,不能只加进去第一条
2777
2792
  {
2778
2793
  const snapshot = readState()
2779
- const mine = Object.values(snapshot.watchers || {}).filter((w) => w && w.sessionId === sessionId)
2794
+ // 审核 T32 M3:与 applyOne 同口径 —— 只数**还在跑的**(watch_stop 只是置 enabled=false)
2795
+ const mine = Object.values(snapshot.watchers || {}).filter((w) => w && w.sessionId === sessionId && w.enabled !== false)
2780
2796
  // id 必须和 applyOne 里算的一致(Gitee 带 `gitee:` 前缀),否则上限计数会漏掉它们
2781
2797
  const idOf = ({ repo, provider }) => (provider === 'gitee' ? 'gitee:' : '') + repo + '#' + sessionId
2782
2798
  const incoming = repoList.filter((item) => !(snapshot.watchers || {})[idOf(item)])
2783
2799
  const room = MAX_WATCHERS_PER_SESSION - mine.length
2784
2800
  if (incoming.length > room) {
2785
- return '一条会话最多挂 ' + MAX_WATCHERS_PER_SESSION + ' 条守(现在 ' + mine.length + ' 条,这次要新增 ' + incoming.length + ' 条)—— 先 watch_stop 停掉不用的,或把多个仓库合成一条规则'
2801
+ return '一条会话最多同时挂 ' + MAX_WATCHERS_PER_SESSION + ' 条在跑的守(现在 ' + mine.length + ' 条,这次要新增 ' + incoming.length + ' 条)—— 先 watch_stop 停掉不用的,或把多个仓库合成一条规则'
2786
2802
  }
2787
2803
  }
2788
2804
  const applied = []
@@ -2864,11 +2880,20 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2864
2880
  const toolAgents = agentsService(ctx)
2865
2881
  const agent = toolAgents && typeof toolAgents.currentInitiator === 'function' ? toolAgents.currentInitiator() : undefined
2866
2882
  const sessionId = agent && agent.id
2867
- const id = `${args.repo}#${sessionId}`
2883
+ // 审核 T32 M1:id 是「repo#sessionId」,而 Gitee 守的 repo 带 `gitee:` 前缀。
2884
+ // 模型照 watch_status 的 JSON 里那个 `repo`(不带前缀)来调,就永远停不掉 ——
2885
+ // 而且失败文案是 `(...)` 不是 `[error: ...]`,读起来像「已经停了」。
2886
+ // 现在两种写法都认:先按原样找,找不到再试加/去 `gitee:` 前缀。
2868
2887
  const state = readState()
2888
+ const rawRepo = String(args.repo || '')
2889
+ const candidates = [
2890
+ `${rawRepo}#${sessionId}`,
2891
+ rawRepo.startsWith('gitee:') ? `${rawRepo.slice(6)}#${sessionId}` : `gitee:${rawRepo}#${sessionId}`,
2892
+ ]
2893
+ const id = candidates.find((key) => state.watchers && state.watchers[key]) || candidates[0]
2869
2894
  if (!state.watchers || !state.watchers[id]) {
2870
- const message = 'no watcher for ' + id
2871
- return (args && args.format === 'json') ? JSON.stringify({ schemaVersion: 1, ok: false, id, error: message }) : '(' + message + ')'
2895
+ const message = 'no watcher for ' + rawRepo + '(试过 ' + candidates.join(' / ') + ')'
2896
+ return (args && args.format === 'json') ? JSON.stringify({ schemaVersion: 1, ok: false, id, error: message }) : '[error: ' + message + ']'
2872
2897
  }
2873
2898
  state.watchers[id].enabled = false
2874
2899
  writeState(state)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.9.232",
3
+ "version": "0.9.233",
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",