dsh-session-superagent 0.9.42 → 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 +32 -0
- package/README.md +1 -1
- package/client.js +1 -1
- package/lib/index.js +67 -39
- package/lib/watch.js +43 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,38 @@
|
|
|
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
|
+
|
|
21
|
+
## [0.9.43] - 2026-11-02 —— `watch_status` 支持 `format=json`(同一份数据两种渲染)
|
|
22
|
+
|
|
23
|
+
### 学到的(知识库第 91 条)
|
|
24
|
+
CLI 的通用形态:**默认给人看,`--json` 给机器**(gh / kubectl -o json 都这样)。
|
|
25
|
+
|
|
26
|
+
### 之前的风险
|
|
27
|
+
`watch_status` 只返回拼接字符串,agent 靠子串解析 —— **我们改一次措辞,agent 的解析就静默失效**。
|
|
28
|
+
|
|
29
|
+
### 改法
|
|
30
|
+
1. 纯函数 `statusView(entries)` 产出结构(session + watchers 全字段);
|
|
31
|
+
2. 工具加 `format` 参数:`text`(默认)/ `json`;
|
|
32
|
+
3. **文本由结构渲染**,所以两者永远一致(不是两份实现)。
|
|
33
|
+
|
|
34
|
+
### 测试
|
|
35
|
+
- 新增 2 例(结构 7 项断言 + 空输入;工具 json 可解析、默认仍是文本)。合计 **180 例**。
|
|
36
|
+
|
|
5
37
|
## [0.9.42] - 2026-11-02 —— `watch_status` 带上诊断字段,agent 能自诊
|
|
6
38
|
|
|
7
39
|
### 学到的(知识库第 90 条)
|
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)
|
|
6
|
-
[](https://github.com/MYCF711/dsh-session-superagent/releases)
|
|
7
7
|
[](https://www.npmjs.com/package/dsh-session-superagent)
|
|
8
8
|
[](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.
|
|
17
|
+
const CLIENT_VERSION = '0.9.44'
|
|
18
18
|
let BASE = '/session-superagent'
|
|
19
19
|
/**
|
|
20
20
|
* 挑「最新的那个服务端实例」。
|
package/lib/index.js
CHANGED
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
bumpDailyWakes,
|
|
31
31
|
busierThanUsual,
|
|
32
32
|
countCapped,
|
|
33
|
+
statusView,
|
|
33
34
|
dailySummary,
|
|
34
35
|
suggestSessionCap,
|
|
35
36
|
itemTrace,
|
|
@@ -39,7 +40,7 @@ import {
|
|
|
39
40
|
|
|
40
41
|
export const name = 'dsh-session-superagent'
|
|
41
42
|
/** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
|
|
42
|
-
export const SERVER_VERSION = '0.9.
|
|
43
|
+
export const SERVER_VERSION = '0.9.44'
|
|
43
44
|
export const inject = ['tools', 'agents', 'webServer']
|
|
44
45
|
/** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
|
|
45
46
|
const DEFAULT_SESSION_WAKES = 12
|
|
@@ -1750,6 +1751,7 @@ export function apply(ctx) {
|
|
|
1750
1751
|
parameters: {
|
|
1751
1752
|
repo: { type: 'string', description: 'owner/name; defaults to the only watched repo' },
|
|
1752
1753
|
number: { type: 'number', description: 'issue or PR number to trace' },
|
|
1754
|
+
format: { type: 'string', description: "'text' (default) or 'json'." },
|
|
1753
1755
|
},
|
|
1754
1756
|
async execute(args) {
|
|
1755
1757
|
const state = readState()
|
|
@@ -1757,10 +1759,14 @@ export function apply(ctx) {
|
|
|
1757
1759
|
const wanted = typeof args.repo === 'string' && args.repo.trim() ? args.repo.trim() : null
|
|
1758
1760
|
const list = wanted ? all.filter((entry) => entry && entry.repo === wanted) : all
|
|
1759
1761
|
if (list.length === 0) {
|
|
1760
|
-
|
|
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 + ']'
|
|
1761
1765
|
}
|
|
1762
1766
|
const number = Number(args.number)
|
|
1763
|
-
if (!Number.isFinite(number))
|
|
1767
|
+
if (!Number.isFinite(number)) {
|
|
1768
|
+
return (args && args.format === 'json') ? JSON.stringify({ schemaVersion: 1, error: 'number is required' }) : '[error: number is required]'
|
|
1769
|
+
}
|
|
1764
1770
|
const lines = []
|
|
1765
1771
|
for (const entry of list) {
|
|
1766
1772
|
const trace = itemTrace(entry, number)
|
|
@@ -1773,6 +1779,17 @@ export function apply(ctx) {
|
|
|
1773
1779
|
for (const item of trace.filtered) lines.push(' 被过滤(' + item.reason + '):' + item.at)
|
|
1774
1780
|
for (const item of trace.wakes) lines.push(' 唤醒尝试:' + item.at + ' ' + (item.ok ? '成功' : '失败(' + (item.reason || '未知') + ')'))
|
|
1775
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
|
+
}
|
|
1776
1793
|
if (lines.length === 0) {
|
|
1777
1794
|
return '#' + number + ' 在' + (wanted ? ' ' + wanted : '所有守') + ' 里都没有痕迹 —— 可能还没被轮询到,或者编号写错了。'
|
|
1778
1795
|
}
|
|
@@ -1786,6 +1803,7 @@ export function apply(ctx) {
|
|
|
1786
1803
|
'Self-check the watchers: gh login, repo access, ack label existence, isolation workdir. Read-only; prints a checklist.',
|
|
1787
1804
|
parameters: {
|
|
1788
1805
|
repo: { type: 'string', description: 'only check this owner/name; default = every watcher' },
|
|
1806
|
+
format: { type: 'string', description: "'text' (default) or 'json'." },
|
|
1789
1807
|
},
|
|
1790
1808
|
async execute(args) {
|
|
1791
1809
|
const lines = []
|
|
@@ -1824,6 +1842,13 @@ export function apply(ctx) {
|
|
|
1824
1842
|
|
|
1825
1843
|
if (wanted.length === 0) {
|
|
1826
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
|
+
}
|
|
1827
1852
|
return lines.join('\n')
|
|
1828
1853
|
}
|
|
1829
1854
|
|
|
@@ -1852,6 +1877,14 @@ export function apply(ctx) {
|
|
|
1852
1877
|
const last = entry.lastError ? `错误:${entry.lastError}` : entry.lastDeferred ? `等待:${entry.lastDeferred}` : '正常'
|
|
1853
1878
|
lines.push(`INFO ${entry.enabled === false ? '已暂停' : '运行中'} · 上次轮询 ${entry.lastPoll || '无'} · ${last}`)
|
|
1854
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
|
+
}
|
|
1855
1888
|
return lines.join('\n')
|
|
1856
1889
|
},
|
|
1857
1890
|
}))
|
|
@@ -1991,44 +2024,39 @@ export function apply(ctx) {
|
|
|
1991
2024
|
|
|
1992
2025
|
ctx.tools.register(defineTool({
|
|
1993
2026
|
name: 'watch_status',
|
|
1994
|
-
description: 'Report active watchers
|
|
1995
|
-
parameters: {
|
|
1996
|
-
|
|
2027
|
+
description: 'Report active watchers: schedule, why one is paused, unanswered wakes, and how much of the session wake budget is used. Use format=json for machine-readable output. Read-only.',
|
|
2028
|
+
parameters: {
|
|
2029
|
+
format: { type: 'string', description: "'text' (default, human) or 'json' (same data, structured)." },
|
|
2030
|
+
},
|
|
2031
|
+
async execute(args) {
|
|
1997
2032
|
const state = readState()
|
|
1998
2033
|
const list = Object.values(state.watchers || {})
|
|
1999
|
-
if (!list.length) return '(no watchers)'
|
|
2000
|
-
|
|
2001
|
-
const
|
|
2002
|
-
|
|
2003
|
-
const
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
].filter(Boolean).join(' ')
|
|
2026
|
-
})
|
|
2027
|
-
.join(String.fromCharCode(10))
|
|
2028
|
-
const suggestion = suggestSessionCap({ used: sessionUsed, cap, capped })
|
|
2029
|
-
const summary = 'session: ' + sessionUsed + '/' + cap + ' wakes last hour'
|
|
2030
|
-
+ (capped > 0 ? ',' + capped + ' 条守正因上限暂停' : '')
|
|
2031
|
-
+ (suggestion ? ',建议把会话上限调到 ' + suggestion : '')
|
|
2034
|
+
if (!list.length) return args && args.format === 'json' ? JSON.stringify({ schemaVersion: 1, session: null, watchers: [] }) : '(no watchers)'
|
|
2035
|
+
// 同一份数据:结构化视图 -> 文本只是它的一种渲染,两边永远对得上
|
|
2036
|
+
const view = statusView(list)
|
|
2037
|
+
if (args && args.format === 'json') return JSON.stringify(view, null, 2)
|
|
2038
|
+
const body = view.watchers.map((w) => {
|
|
2039
|
+
const flags = []
|
|
2040
|
+
if (w.observe) flags.push('observe')
|
|
2041
|
+
if (w.isolated) flags.push('isolated')
|
|
2042
|
+
if (!w.enabled) flags.push('paused')
|
|
2043
|
+
if (w.activeHours) flags.push('hours=' + w.activeHours)
|
|
2044
|
+
if (w.labels.length) flags.push('labels=' + w.labels.join(','))
|
|
2045
|
+
if (w.onlyAssigned) flags.push('onlyAssigned')
|
|
2046
|
+
if (w.deferReason) flags.push('defer=' + w.deferReason)
|
|
2047
|
+
if (w.silentWakes > 0) flags.push('silent=' + w.silentWakes)
|
|
2048
|
+
return [w.repo, '→', w.sessionId,
|
|
2049
|
+
'| every ' + w.intervalSec + 's',
|
|
2050
|
+
flags.length ? '| ' + flags.join(' ') : '',
|
|
2051
|
+
'| lastPoll=' + (w.lastPoll || '-'),
|
|
2052
|
+
'| lastWake=' + (w.lastWake || '-'),
|
|
2053
|
+
'| err=' + (w.lastError || '-'),
|
|
2054
|
+
].filter(Boolean).join(' ')
|
|
2055
|
+
}).join(String.fromCharCode(10))
|
|
2056
|
+
const s2 = view.session
|
|
2057
|
+
const summary = 'session: ' + s2.used + '/' + s2.cap + ' wakes last hour'
|
|
2058
|
+
+ (s2.capped > 0 ? ',' + s2.capped + ' 条守正因上限暂停' : '')
|
|
2059
|
+
+ (s2.suggest ? ',建议把会话上限调到 ' + s2.suggest : '')
|
|
2032
2060
|
return body + String.fromCharCode(10) + summary
|
|
2033
2061
|
},
|
|
2034
2062
|
}))
|
package/lib/watch.js
CHANGED
|
@@ -854,3 +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
|
+
// 消费方靠它判断字段语义有没有变;改字段时这个数一起加
|
|
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.
|
|
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",
|