dsh-session-superagent 0.9.44 → 0.9.46

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,48 @@
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.46] - 2026-11-02 —— 写工具也给 JSON:成功与否不再靠读中文
6
+
7
+ ### 学到的(延续知识库第 91 条)
8
+ 只读工具有了 `format=json`,但**写工具**仍返回自然语言:
9
+ `acked o/r #12 with label …` / `stopped o/r#s` —— agent 判断成功与否只能读中文,改一次措辞就误判。
10
+
11
+ ### 改法
12
+ `watch_start` / `watch_stop` / `watch_ack` 补上 `format: 'json'`:
13
+ | 场景 | JSON |
14
+ |---|---|
15
+ | start 成功 | `{ schemaVersion, ok: true, repo, id, intervalSec, flags, updated }` |
16
+ | stop 成功 | `{ schemaVersion, ok: true, id }` |
17
+ | ack 成功 | `{ schemaVersion, ok: true, repo, label, acked, at }` |
18
+ | 失败 | `{ schemaVersion, ok: false, error }` |
19
+
20
+ 文本形态**保持不变**(老调用方不受影响),顺序是"先判断 json,再拼文本"。
21
+
22
+ ### 测试
23
+ - 新增 1 例(start 新建/更新、stop 成功/不存在、默认仍返回文本)。合计 **182 例**。
24
+
25
+ ## [0.9.45] - 2026-11-02 —— README 写着 136 项单测,实际 181(现在会自动报错)
26
+
27
+ ### 学到的(知识库第 92 条)
28
+ 散文里的数字最容易过期:结构性内容有人维护,顺带提的数字没人看。
29
+
30
+ ### 发现
31
+ README「开发」小节写着 `node --test # 136 项单测` —— 实际 **181 项**,
32
+ 跨了四十多个版本没人发现(谁加用例都不会想起改 README 注释)。
33
+
34
+ ### 改法
35
+ `preflight` 跑完 `node --test` 后顺手比对 README 里的数字:
36
+ ```
37
+ FAIL README 单测数 README 写 136,实际 181(改 README)
38
+ ```
39
+ 改成 181 后 → `PASS README 单测数 README 写 181,实际 181`。
40
+
41
+ 顺带把这个数字同时当作"用例数只增不减"的哨兵:数字变小也会立刻暴露。
42
+
43
+ ### 顺带补的对外契约
44
+ README 新增「工具输出」小节:三个只读工具的 `format: 'json'` 形态与 `schemaVersion: 1`;
45
+ `docs/规则对照表.md` 加一行(协议类约定也进对照表)。
46
+
5
47
  ## [0.9.44] - 2026-11-02 —— 三个只读工具口径统一:都支持 `format=json` + `schemaVersion`
6
48
 
7
49
  ### 做了什么
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.44-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.9.46-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,9 +121,22 @@ dsh plugin install /path/to/dsh-session-superagent
121
121
  ## 开发
122
122
 
123
123
  ```sh
124
- node --test # 136 项单测
124
+ node --test # 182 项单测
125
125
  ```
126
126
 
127
+ ### 工具输出:文本给人和 agent,JSON 给程序
128
+
129
+ 三个只读工具都支持 `format: 'json'`,返回带 `schemaVersion` 的对象:
130
+
131
+ | 工具 | 文本(默认) | `format: 'json'` |
132
+ |---|---|---|
133
+ | `watch_status` | 每条守一行 + 会话用量行 | `{ schemaVersion, session, watchers[] }` |
134
+ | `watch_doctor` | `OK/WARN/FAIL` 检查清单 | `{ schemaVersion, checks[{status,text}] }` |
135
+ | `watch_trace` | 单条条目的追溯文字 | `{ schemaVersion, number, results[] }`(错误时 `{ schemaVersion, error }`) |
136
+ | `watch_start` / `watch_stop` / `watch_ack` | 一句话结果 | `{ schemaVersion, ok, … }` —— 成功/失败都靠 `ok` 判断,不用读中文 |
137
+
138
+ `schemaVersion` 现在是 `1`;**字段语义一变就会加这个数**,程序可以据此决定要不要重新解析。
139
+
127
140
  版本与发布流程见 [UPDATING.md](UPDATING.md),交付门见 [CHECKLIST.md](CHECKLIST.md),接手台账见 [MAINTENANCE.md](MAINTENANCE.md)。
128
141
 
129
142
  ## 客户(Customer)
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.44'
17
+ const CLIENT_VERSION = '0.9.46'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
package/lib/index.js CHANGED
@@ -40,7 +40,7 @@ import {
40
40
 
41
41
  export const name = 'dsh-session-superagent'
42
42
  /** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
43
- export const SERVER_VERSION = '0.9.44'
43
+ export const SERVER_VERSION = '0.9.46'
44
44
  export const inject = ['tools', 'agents', 'webServer']
45
45
  /** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
46
46
  const DEFAULT_SESSION_WAKES = 12
@@ -1702,6 +1702,7 @@ export function apply(ctx) {
1702
1702
  number: { type: 'number', description: 'issue or PR number' },
1703
1703
  numbers: { type: 'string', description: '逗号分隔的多个编号,如 "12,13,14"(与 number 二选一)' },
1704
1704
  label: { type: 'string', description: 'ack label, default 主理鱼:已处理' },
1705
+ format: { type: 'string', description: "'text' (default) or 'json'." },
1705
1706
  },
1706
1707
  async execute(args) {
1707
1708
  const numbers = String(args.numbers || args.number || '')
@@ -1728,7 +1729,11 @@ export function apply(ctx) {
1728
1729
  }
1729
1730
  results.push(number)
1730
1731
  }
1731
- if (failed) return `[error: #${failed.number} gh exited ${failed.code}] ${failed.text}`
1732
+ if (failed) {
1733
+ return (args && args.format === 'json')
1734
+ ? JSON.stringify({ schemaVersion: 1, ok: false, repo: entry.repo, acked: results, failed: { number: failed.number, text: failed.text } })
1735
+ : `[error: #${failed.number} gh exited ${failed.code}] ${failed.text}`
1736
+ }
1732
1737
  const latest = readState()
1733
1738
  const live = latest.watchers && latest.watchers[entry.id]
1734
1739
  const nowIso = new Date().toISOString()
@@ -1739,6 +1744,9 @@ export function apply(ctx) {
1739
1744
  live.lastAcked = { numbers: results, label, at: nowIso }
1740
1745
  writeState(latest)
1741
1746
  }
1747
+ if (args && args.format === 'json') {
1748
+ return JSON.stringify({ schemaVersion: 1, ok: true, repo: entry.repo, label, acked: results, at: nowIso })
1749
+ }
1742
1750
  return `acked ${entry.repo} #${results.join(' #')} with label "${label}"`
1743
1751
  },
1744
1752
  }))
@@ -1943,6 +1951,7 @@ export function apply(ctx) {
1943
1951
  isolated: { type: 'boolean', description: 'Run each wake in a throwaway git worktree.' },
1944
1952
  workdir: { type: 'string', description: 'Repository used for isolation worktrees (absolute path).' },
1945
1953
  activeHours: { type: 'string', description: 'Wake only inside this window, e.g. "09:00-23:00" (supports overnight).' },
1954
+ format: { type: 'string', description: "'text' (default) or 'json'." },
1946
1955
  batchLimit: { type: 'number', description: 'Max items listed per wake (1-20, default 5).' },
1947
1956
  maxWakesPerHour: { type: 'number', description: 'Max wakes per hour per watcher (1-60, default 6).' },
1948
1957
  sessionMaxWakes: { type: 'number', description: 'Max wakes per hour for the whole session, summed across watchers (1-60, default 12).' },
@@ -2016,6 +2025,11 @@ export function apply(ctx) {
2016
2025
  if (entry.batchLimit) flags.push('batch=' + entry.batchLimit)
2017
2026
  if (entry.maxWakesPerHour) flags.push('perHour=' + entry.maxWakesPerHour)
2018
2027
  if (entry.goal) flags.push('goal=' + JSON.stringify(entry.goal.slice(0, 40)))
2028
+ if (args && args.format === 'json') {
2029
+ return JSON.stringify({ schemaVersion: 1, ok: true, repo, sessionId, id, intervalSec: entry.intervalSec,
2030
+ flags, filters: entry.filters || {}, updated: Boolean(existing), observe: entry.observe === true,
2031
+ isolated: entry.isolated === true, activeHours: entry.activeHours || null }, null, 2)
2032
+ }
2019
2033
  return `watching ${repo} → session ${sessionId} every ${entry.intervalSec}s` +
2020
2034
  (flags.length ? ' [' + flags.join(' ') + ']' : '') +
2021
2035
  (existing ? ' (updated existing watcher)' : '')
@@ -2064,18 +2078,25 @@ export function apply(ctx) {
2064
2078
  ctx.tools.register(defineTool({
2065
2079
  name: 'watch_stop',
2066
2080
  description: 'Stop watching a repository for the current session.',
2067
- parameters: { repo: { type: 'string', required: true, description: 'owner/name' } },
2081
+ parameters: {
2082
+ repo: { type: 'string', required: true, description: 'owner/name' },
2083
+ format: { type: 'string', description: "'text' (default) or 'json'." },
2084
+ },
2068
2085
  async execute(args) {
2069
2086
  const toolAgents = agentsService(ctx)
2070
2087
  const agent = toolAgents && typeof toolAgents.currentInitiator === 'function' ? toolAgents.currentInitiator() : undefined
2071
2088
  const sessionId = agent && agent.id
2072
2089
  const id = `${args.repo}#${sessionId}`
2073
2090
  const state = readState()
2074
- if (!state.watchers || !state.watchers[id]) return `(no watcher for ${id})`
2091
+ if (!state.watchers || !state.watchers[id]) {
2092
+ const message = 'no watcher for ' + id
2093
+ return (args && args.format === 'json') ? JSON.stringify({ schemaVersion: 1, ok: false, id, error: message }) : '(' + message + ')'
2094
+ }
2075
2095
  state.watchers[id].enabled = false
2076
2096
  writeState(state)
2077
2097
  const timer = timers.get(id)
2078
2098
  if (timer) { clearInterval(timer); timers.delete(id) }
2099
+ if (args && args.format === 'json') return JSON.stringify({ schemaVersion: 1, ok: true, id, repo: args.repo })
2079
2100
  return `stopped ${id}`
2080
2101
  },
2081
2102
  }))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.9.44",
3
+ "version": "0.9.46",
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",