dsh-session-superagent 0.9.43 → 0.9.44

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,22 @@
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.44] - 2026-11-02 —— 三个只读工具口径统一:都支持 `format=json` + `schemaVersion`
6
+
7
+ ### 做了什么
8
+ - `watch_doctor` 与 `watch_trace` 补上 `format` 参数(与 0.9.43 的 `watch_status` 一致);
9
+ - 三者统一带 `schemaVersion: 1`;
10
+ - **错误也走 JSON**(`{ schemaVersion, error }`)—— 消费方不用在两种格式间猜;
11
+ - `watch_doctor` 的 JSON 从同一份文本行解析(`OK/WARN/FAIL/INFO`),单一来源。
12
+
13
+ ### 踩到的两个坑
14
+ 1. 用 `rfind` + 精确字符串匹配去插代码,连续两次 `anchor missing`(CRLF 与转义细节)——
15
+ 最后改成**按索引插入**才稳定;每次生成后都 `node --check`。
16
+ 2. 空态没带 `schemaVersion`(`{session:null,watchers:[]}`),被新用例当场抓到。
17
+
18
+ ### 测试
19
+ - 新增 1 例(三工具参数 + status/doctor 可解析 + trace 错误态 JSON + 建守后 results)。合计 **181 例**。
20
+
5
21
  ## [0.9.43] - 2026-11-02 —— `watch_status` 支持 `format=json`(同一份数据两种渲染)
6
22
 
7
23
  ### 学到的(知识库第 91 条)
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.43-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.9.44-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
 
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.43'
17
+ const CLIENT_VERSION = '0.9.44'
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.43'
43
+ export const SERVER_VERSION = '0.9.44'
44
44
  export const inject = ['tools', 'agents', 'webServer']
45
45
  /** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
46
46
  const DEFAULT_SESSION_WAKES = 12
@@ -1751,6 +1751,7 @@ export function apply(ctx) {
1751
1751
  parameters: {
1752
1752
  repo: { type: 'string', description: 'owner/name; defaults to the only watched repo' },
1753
1753
  number: { type: 'number', description: 'issue or PR number to trace' },
1754
+ format: { type: 'string', description: "'text' (default) or 'json'." },
1754
1755
  },
1755
1756
  async execute(args) {
1756
1757
  const state = readState()
@@ -1758,10 +1759,14 @@ export function apply(ctx) {
1758
1759
  const wanted = typeof args.repo === 'string' && args.repo.trim() ? args.repo.trim() : null
1759
1760
  const list = wanted ? all.filter((entry) => entry && entry.repo === wanted) : all
1760
1761
  if (list.length === 0) {
1761
- return '[error: no watcher for that repo — ' + (wanted ? 'nothing is watching ' + wanted : 'run watch_status to see what is watched') + ']'
1762
+ const message = 'no watcher for that repo — ' + (wanted ? 'nothing is watching ' + wanted : 'run watch_status to see what is watched')
1763
+ // format=json 时错误也要是 JSON:消费方不该在两种格式间猜
1764
+ return (args && args.format === 'json') ? JSON.stringify({ schemaVersion: 1, error: message }) : '[error: ' + message + ']'
1762
1765
  }
1763
1766
  const number = Number(args.number)
1764
- if (!Number.isFinite(number)) return '[error: number is required]'
1767
+ if (!Number.isFinite(number)) {
1768
+ return (args && args.format === 'json') ? JSON.stringify({ schemaVersion: 1, error: 'number is required' }) : '[error: number is required]'
1769
+ }
1765
1770
  const lines = []
1766
1771
  for (const entry of list) {
1767
1772
  const trace = itemTrace(entry, number)
@@ -1774,6 +1779,17 @@ export function apply(ctx) {
1774
1779
  for (const item of trace.filtered) lines.push(' 被过滤(' + item.reason + '):' + item.at)
1775
1780
  for (const item of trace.wakes) lines.push(' 唤醒尝试:' + item.at + ' ' + (item.ok ? '成功' : '失败(' + (item.reason || '未知') + ')'))
1776
1781
  }
1782
+ if (args && args.format === 'json') {
1783
+ const results = []
1784
+ for (const entry of list) {
1785
+ const trace = itemTrace(entry, number)
1786
+ if (!trace) continue
1787
+ const touched = Boolean(trace.seen || trace.reported || trace.filtered.length || trace.wakes.length)
1788
+ if (!touched) continue
1789
+ results.push(trace)
1790
+ }
1791
+ return JSON.stringify({ schemaVersion: 1, number: String(number), results }, null, 2)
1792
+ }
1777
1793
  if (lines.length === 0) {
1778
1794
  return '#' + number + ' 在' + (wanted ? ' ' + wanted : '所有守') + ' 里都没有痕迹 —— 可能还没被轮询到,或者编号写错了。'
1779
1795
  }
@@ -1787,6 +1803,7 @@ export function apply(ctx) {
1787
1803
  'Self-check the watchers: gh login, repo access, ack label existence, isolation workdir. Read-only; prints a checklist.',
1788
1804
  parameters: {
1789
1805
  repo: { type: 'string', description: 'only check this owner/name; default = every watcher' },
1806
+ format: { type: 'string', description: "'text' (default) or 'json'." },
1790
1807
  },
1791
1808
  async execute(args) {
1792
1809
  const lines = []
@@ -1825,6 +1842,13 @@ export function apply(ctx) {
1825
1842
 
1826
1843
  if (wanted.length === 0) {
1827
1844
  lines.push('INFO 当前没有任何 watcher —— 先 watch_start 或到面板加一条')
1845
+ if (args && args.format === 'json') {
1846
+ const checks = lines.map((line) => {
1847
+ const m = /^(OK|WARN|FAIL|INFO)\s*(.*)$/.exec(line)
1848
+ return { status: m ? m[1].toLowerCase() : 'info', text: (m ? m[2] : line).trim() }
1849
+ })
1850
+ return JSON.stringify({ schemaVersion: 1, checks }, null, 2)
1851
+ }
1828
1852
  return lines.join('\n')
1829
1853
  }
1830
1854
 
@@ -1853,6 +1877,14 @@ export function apply(ctx) {
1853
1877
  const last = entry.lastError ? `错误:${entry.lastError}` : entry.lastDeferred ? `等待:${entry.lastDeferred}` : '正常'
1854
1878
  lines.push(`INFO ${entry.enabled === false ? '已暂停' : '运行中'} · 上次轮询 ${entry.lastPoll || '无'} · ${last}`)
1855
1879
  }
1880
+ // format=json 时从同一份文本行解析出结构 —— 单一来源,不会出现两套逻辑走偏
1881
+ if (args && args.format === 'json') {
1882
+ const checks = lines.map((line) => {
1883
+ const m = /^(OK|WARN|FAIL|INFO)\s*(.*)$/.exec(line)
1884
+ return { status: m ? m[1].toLowerCase() : 'info', text: (m ? m[2] : line).trim() }
1885
+ })
1886
+ return JSON.stringify({ schemaVersion: 1, checks }, null, 2)
1887
+ }
1856
1888
  return lines.join('\n')
1857
1889
  },
1858
1890
  }))
@@ -1999,7 +2031,7 @@ export function apply(ctx) {
1999
2031
  async execute(args) {
2000
2032
  const state = readState()
2001
2033
  const list = Object.values(state.watchers || {})
2002
- if (!list.length) return args && args.format === 'json' ? JSON.stringify({ session: null, watchers: [] }) : '(no watchers)'
2034
+ if (!list.length) return args && args.format === 'json' ? JSON.stringify({ schemaVersion: 1, session: null, watchers: [] }) : '(no watchers)'
2003
2035
  // 同一份数据:结构化视图 -> 文本只是它的一种渲染,两边永远对得上
2004
2036
  const view = statusView(list)
2005
2037
  if (args && args.format === 'json') return JSON.stringify(view, null, 2)
package/lib/watch.js CHANGED
@@ -854,44 +854,46 @@ export function busierThanUsual(summary, { factor = 2, minDays = 3 } = {}) {
854
854
  if (avg <= 0) return false // 历史为 0 时没有可比基线
855
855
  return today >= avg * Math.max(1.5, Number(factor) || 2)
856
856
  }
857
-
858
- /**
859
- * `watch_status` 的结构化视图:同一份数据,既能渲染成人读的文本,也能给 agent 解析。
860
- *
861
- * 为什么要有它:工具输出原来是拼接的字符串,agent 只能靠字符串匹配 —— 一改文案就崩。
862
- * 现在纯函数产出结构,文本只是它的一种渲染(两边永远一致)。
863
- */
864
- export function statusView(entries, options = {}) {
865
- const list = (Array.isArray(entries) ? entries : Object.values(entries || {})).filter(Boolean)
866
- const sessionId = options.sessionId || (list[0] && list[0].sessionId) || null
867
- const capped = countCapped(list)
868
- const used = sessionId ? sessionWakesLastHour(list, sessionId) : 0
869
- const cap = Number((list[0] && list[0].sessionMaxWakes)) || 12
870
- return {
871
- session: {
872
- id: sessionId,
873
- used,
874
- cap,
875
- capped,
876
- suggest: list.length === 0 ? null : suggestSessionCap({ used, cap, capped }),
877
- },
878
- watchers: list.map((w) => ({
879
- repo: w.repo || null,
880
- sessionId: w.sessionId || null,
881
- enabled: w.enabled !== false,
882
- intervalSec: Number(w.intervalSec) || 60,
883
- observe: w.observe === true,
884
- isolated: w.isolated === true,
885
- activeHours: w.activeHours || null,
886
- labels: (w.filters && Array.isArray(w.filters.labels)) ? w.filters.labels : [],
887
- onlyAssigned: Boolean(w.filters && w.filters.onlyAssigned),
888
- deferReason: w.deferReason || null,
889
- lastDeferred: w.lastDeferred || null,
890
- silentWakes: Number(w.silentWakes) || 0,
891
- cursor: w.cursor || null,
892
- lastPoll: w.lastPoll || null,
893
- lastWake: w.lastWake || null,
894
- lastError: w.lastError || null,
895
- })),
896
- }
897
- }
857
+
858
+ /**
859
+ * `watch_status` 的结构化视图:同一份数据,既能渲染成人读的文本,也能给 agent 解析。
860
+ *
861
+ * 为什么要有它:工具输出原来是拼接的字符串,agent 只能靠字符串匹配 —— 一改文案就崩。
862
+ * 现在纯函数产出结构,文本只是它的一种渲染(两边永远一致)。
863
+ */
864
+ export function statusView(entries, options = {}) {
865
+ const list = (Array.isArray(entries) ? entries : Object.values(entries || {})).filter(Boolean)
866
+ const sessionId = options.sessionId || (list[0] && list[0].sessionId) || null
867
+ const capped = countCapped(list)
868
+ const used = sessionId ? sessionWakesLastHour(list, sessionId) : 0
869
+ const cap = Number((list[0] && list[0].sessionMaxWakes)) || 12
870
+ return {
871
+ // 消费方靠它判断字段语义有没有变;改字段时这个数一起加
872
+ schemaVersion: 1,
873
+ session: {
874
+ id: sessionId,
875
+ used,
876
+ cap,
877
+ capped,
878
+ suggest: list.length === 0 ? null : suggestSessionCap({ used, cap, capped }),
879
+ },
880
+ watchers: list.map((w) => ({
881
+ repo: w.repo || null,
882
+ sessionId: w.sessionId || null,
883
+ enabled: w.enabled !== false,
884
+ intervalSec: Number(w.intervalSec) || 60,
885
+ observe: w.observe === true,
886
+ isolated: w.isolated === true,
887
+ activeHours: w.activeHours || null,
888
+ labels: (w.filters && Array.isArray(w.filters.labels)) ? w.filters.labels : [],
889
+ onlyAssigned: Boolean(w.filters && w.filters.onlyAssigned),
890
+ deferReason: w.deferReason || null,
891
+ lastDeferred: w.lastDeferred || null,
892
+ silentWakes: Number(w.silentWakes) || 0,
893
+ cursor: w.cursor || null,
894
+ lastPoll: w.lastPoll || null,
895
+ lastWake: w.lastWake || null,
896
+ lastError: w.lastError || null,
897
+ })),
898
+ }
899
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.9.43",
3
+ "version": "0.9.44",
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",