dsh-session-superagent 0.10.0 → 0.10.1
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 +8 -0
- package/README.md +29 -3
- package/SETUP.md +1 -1
- package/client.js +41 -27
- package/lib/index.js +102 -25
- package/lib/watch.js +44 -5
- package/package.json +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
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.10.1] - 2026-11-06 —— 品牌与默认 ack 可配置(issue #11,@modusensus)
|
|
6
|
+
|
|
7
|
+
- 新增 `Config`:`brandName`、`defaultAckLabel`、`defaultAckLabelGitee`,默认值与 0.10.0 逐字相同。
|
|
8
|
+
- 唤醒抬头/合并抬头、面板主标题与关键空态、默认 ack 派生(watch_start/watch_ack//state)统一读配置。
|
|
9
|
+
- `/state` 下发 `brandName` 与 `defaultAckLabels`;client 三处重复回落字面量改为读它。
|
|
10
|
+
- 已有 watcher 的显式 `ackLabel` 不被覆盖;非法 Gitee 标签回落默认。
|
|
11
|
+
- 验证:689/689、UI 11/11、Chromium 47/47。
|
|
12
|
+
|
|
5
13
|
## [0.10.0] - 2026-11-06 —— 功能稳定版
|
|
6
14
|
|
|
7
15
|
这是严格审查后收口的功能稳定版。上一轮 11 项必须修、18 项值得改全部处理,终审新增 N1/N2/N3 也已修复。
|
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
|
[](https://github.com/awesome-dsh-plugin/awesome-dsh-plugin)
|
|
@@ -103,6 +103,32 @@ https://gitee.com/owner/name # 直接粘地址栏(.git 结尾也行)
|
|
|
103
103
|
|
|
104
104
|
Gitee 私有仓库要在「设置 → 凭证」填私人令牌;公开仓库不填也能读,但打不了 ack 标签。
|
|
105
105
|
|
|
106
|
+
## 配置:品牌与默认 ack 标签(issue #11)
|
|
107
|
+
|
|
108
|
+
插件行配置支持三项,都有默认值;不配就是原来的行为:
|
|
109
|
+
|
|
110
|
+
| 键 | 默认 | 作用 |
|
|
111
|
+
|---|---|---|
|
|
112
|
+
| `brandName` | `主理鱼` | 唤醒抬头 `【品牌】…`、合并抬头、面板标题与关键空态 |
|
|
113
|
+
| `defaultAckLabel` | `主理鱼:已处理` | 新建 **GitHub** 守的默认 ack 标签 |
|
|
114
|
+
| `defaultAckLabelGitee` | `主理鱼-已处理` | 新建 **Gitee** 守的默认 ack 标签 |
|
|
115
|
+
|
|
116
|
+
配置写在 profile 的插件行里(`cordis.patch.yml` 中该行的 `config:`,或宿主提供的插件配置项),例如:
|
|
117
|
+
|
|
118
|
+
```yaml
|
|
119
|
+
config:
|
|
120
|
+
brandName: 夜莺
|
|
121
|
+
defaultAckLabel: '夜莺:已处理'
|
|
122
|
+
defaultAckLabelGitee: 夜莺-已处理
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
规则:
|
|
126
|
+
|
|
127
|
+
- 只影响**新建**的守,以及历史数据里**没有写** `ackLabel` 的守;已有 watcher 的显式 `ackLabel` 不会被覆盖。
|
|
128
|
+
- `brandName` 只改抬头与面板标题,唤醒消息的结构(`【品牌】<repo> 有 N 条新动态:`)不变。
|
|
129
|
+
- `defaultAckLabelGitee` 按 Gitee 的标签规则校验(汉字/字母/数字/`. _ - / \`,2–20 字,**不能有半角冒号**);非法值回落到默认 —— 否则每次 `watch_ack` 都会 404,而错误看起来像仓库问题。
|
|
130
|
+
- 配置在插件 `apply()` 时读取,改完要重载宿主才生效。`/state` 顶层会下发 `brandName` 与 `defaultAckLabels { github, gitee }`,面板据此显示;老客户端没有这两个字段时仍按原样回落到 `主理鱼` 与旧标签。
|
|
131
|
+
|
|
106
132
|
## 一次真实运行长什么样
|
|
107
133
|
|
|
108
134
|
1. `watch_start` 登记 watcher(状态存 `~/.dsh/state/session-superagent/watchers.json`);
|
|
@@ -148,7 +174,7 @@ Gitee 私有仓库要在「设置 → 凭证」填私人令牌;公开仓库不
|
|
|
148
174
|
## 开发
|
|
149
175
|
|
|
150
176
|
```sh
|
|
151
|
-
npm test #
|
|
177
|
+
npm test # 689 项单测(带离线开关;裸 node --test 会真去 spawn gh,两分半)
|
|
152
178
|
```
|
|
153
179
|
|
|
154
180
|
### 工具输出:文本给人和 agent,JSON 给程序
|
|
@@ -208,7 +234,7 @@ dsh plugin --profile <profile> add dsh-session-superagent@latest
|
|
|
208
234
|
|
|
209
235
|
|
|
210
236
|
```bash
|
|
211
|
-
npm test #
|
|
237
|
+
npm test # 689 项单测(带离线开关,约 1.6 秒)
|
|
212
238
|
node scripts/ui-audit.mjs # 11 项 UI 指标(写死颜色 / 自造 token / 官方结构采用 …)
|
|
213
239
|
node scripts/preflight.mjs # 41 项门禁(含上面两条,外加 profile 一致性、路由面、包内容)
|
|
214
240
|
node scripts/render-preview.mjs preview.html # 双主题静态预览,直接浏览器打开
|
package/SETUP.md
CHANGED
|
@@ -54,7 +54,7 @@ printf 'DSH_PROFILE=%s\nDSH_HOME=%s\n' "${DSH_PROFILE-}" "${DSH_HOME-}"
|
|
|
54
54
|
|
|
55
55
|
- **安装**:目标 profile;执行 `dsh plugin --profile <profile> add dsh-session-superagent`,已挂载则跳过重复安装。
|
|
56
56
|
- **绑定**:仓库、当前会话、过滤/作者白名单、`isolated`(开启时含 `workdir`)、goal。
|
|
57
|
-
- **默认值**:`intervalSec:60`、单次 5 条、单 watcher 每小时 6 次、整会话每小时 12 次、默认 ack 标签(GitHub `主理鱼:已处理` / Gitee
|
|
57
|
+
- **默认值**:`intervalSec:60`、单次 5 条、单 watcher 每小时 6 次、整会话每小时 12 次、默认 ack 标签(GitHub `主理鱼:已处理` / Gitee `主理鱼-已处理`)—— 这三项(`brandName` / `defaultAckLabel` / `defaultAckLabelGitee`)可由插件配置覆盖,计划里按**实际配置**写,见 README「配置」一节;未选的过滤参数省略。
|
|
58
58
|
- **操作者步骤**:需要登录时在自己终端跑 `gh auth login`;token 只填面板凭证字段。Gitee 需要 ack 时先建标签 `主理鱼-已处理`(Gitee 不允许半角冒号),GitHub 首次 ack 会自动建 `主理鱼:已处理`。
|
|
59
59
|
- **写入与回滚**:`watch_start` 会保存 watcher 并开始轮询;可用 `watch_stop({repo})` 暂停,确认不再需要时用 `watch_stop({repo,delete:true})` 删除配置。
|
|
60
60
|
- **验收**:下列第 5 节全部步骤;`watch_ack` 是否执行、是否回写评论,以及评论正文,都列清楚。
|
package/client.js
CHANGED
|
@@ -418,7 +418,7 @@ window.__ModuleLoader__.load({
|
|
|
418
418
|
}
|
|
419
419
|
|
|
420
420
|
// 客户端版本探针:每次模块加载写一次,用来确认浏览器里跑的是哪一版
|
|
421
|
-
const CLIENT_VERSION = '0.10.
|
|
421
|
+
const CLIENT_VERSION = '0.10.1'
|
|
422
422
|
// SEMVER_COMPARATOR_SOURCE_START
|
|
423
423
|
// This block is duplicated verbatim in client.js because the browser UMD cannot import ESM.
|
|
424
424
|
// test/update-semver.test.mjs audits both copies and exercises their behavior.
|
|
@@ -1038,7 +1038,14 @@ window.__ModuleLoader__.load({
|
|
|
1038
1038
|
const parsed = Number(value)
|
|
1039
1039
|
return Number.isFinite(parsed) ? parsed : undefined
|
|
1040
1040
|
}
|
|
1041
|
-
|
|
1041
|
+
// ack 默认值来自 /state.defaultAckLabels(issue #11);老服务端没有这个字段时仍回落旧字面量。
|
|
1042
|
+
const ACK_LABEL_FALLBACK = { github: '主理鱼:已处理', gitee: '主理鱼-已处理' }
|
|
1043
|
+
const ackLabelFallback = (watcher, defaults) => {
|
|
1044
|
+
const provider = watcher && watcher.provider === 'gitee' ? 'gitee' : 'github'
|
|
1045
|
+
const fromState = defaults && typeof defaults[provider] === 'string' ? defaults[provider].trim() : ''
|
|
1046
|
+
return fromState || ACK_LABEL_FALLBACK[provider]
|
|
1047
|
+
}
|
|
1048
|
+
const watcherValuesFrom = (watcher, ackDefaults) => ({
|
|
1042
1049
|
repo: watcher.repo || '',
|
|
1043
1050
|
intervalSec: watcherNumberText(watcher.intervalSec ?? 60),
|
|
1044
1051
|
labels: (watcher.filters && Array.isArray(watcher.filters.labels) ? watcher.filters.labels : []).join(','),
|
|
@@ -1046,7 +1053,7 @@ window.__ModuleLoader__.load({
|
|
|
1046
1053
|
assignee: (watcher.filters && watcher.filters.assignee) || '',
|
|
1047
1054
|
activeHours: watcher.activeHours || '',
|
|
1048
1055
|
goal: watcher.note || (typeof watcher.goal === 'string' ? watcher.goal : (watcher.goal && watcher.goal.objective) || ''),
|
|
1049
|
-
ackLabel: watcher.ackLabel || (watcher
|
|
1056
|
+
ackLabel: watcher.ackLabel || ackLabelFallback(watcher, ackDefaults),
|
|
1050
1057
|
onlyAssigned: !!(watcher.filters && watcher.filters.onlyAssigned),
|
|
1051
1058
|
allowAuthors: (watcher.filters && Array.isArray(watcher.filters.allowAuthors) ? watcher.filters.allowAuthors : []).join(', '),
|
|
1052
1059
|
observe: !!watcher.observe,
|
|
@@ -1684,6 +1691,9 @@ window.__ModuleLoader__.load({
|
|
|
1684
1691
|
const [orbitError, setOrbitError] = useState(null)
|
|
1685
1692
|
const [open, setOpen] = useState(false)
|
|
1686
1693
|
const [anchor, setAnchor] = useState(null)
|
|
1694
|
+
// 品牌名(issue #11):/state 下发;老服务端没有这个字段时仍是「主理鱼」。
|
|
1695
|
+
// 只能在末尾追加状态槽,前面的位置契约(观测/删除确认)保持不变。
|
|
1696
|
+
const [brandName, setBrandName] = useState('主理鱼')
|
|
1687
1697
|
const btnRef = useRef(null)
|
|
1688
1698
|
const panelRef = useRef(null)
|
|
1689
1699
|
const actionLocks = useRef(new Set())
|
|
@@ -1706,6 +1716,7 @@ window.__ModuleLoader__.load({
|
|
|
1706
1716
|
const body = await call('/state')
|
|
1707
1717
|
if (!orbitAlive.current || sequence !== stateSequence.current) return { applied: false, ok: true }
|
|
1708
1718
|
setWatchers(Array.isArray(body && body.watchers) ? body.watchers : [])
|
|
1719
|
+
setBrandName((typeof (body && body.brandName) === 'string' && body.brandName.trim()) || '主理鱼')
|
|
1709
1720
|
setOrbitError((current) => isReadError(current) ? null : current)
|
|
1710
1721
|
return { applied: true, ok: true }
|
|
1711
1722
|
} catch (error) {
|
|
@@ -1784,9 +1795,9 @@ window.__ModuleLoader__.load({
|
|
|
1784
1795
|
const running = list.filter((w) => orbitStateOf(w) === 'active').length
|
|
1785
1796
|
const broken = list.filter((w) => orbitStateOf(w) === 'error').length
|
|
1786
1797
|
const summary = readError && watchers === null
|
|
1787
|
-
? '
|
|
1798
|
+
? '读不到' + brandName + '状态'
|
|
1788
1799
|
: list.length === 0
|
|
1789
|
-
? '
|
|
1800
|
+
? '还没有' + brandName
|
|
1790
1801
|
: '会话级 superagent:' + running + ' 运行中'
|
|
1791
1802
|
+ (broken ? ',' + broken + ' 异常' : '')
|
|
1792
1803
|
+ '(共 ' + list.length + ' 条)'
|
|
@@ -1809,7 +1820,7 @@ window.__ModuleLoader__.load({
|
|
|
1809
1820
|
? readError
|
|
1810
1821
|
: list.length
|
|
1811
1822
|
? list.map((w) => (w.repo + ' · ' + (w.title || '未命名会话') + ' · ' + sessionTag(w.sessionId) + ' · ' + STATE_TEXT[orbitStateOf(w)])).join('\n')
|
|
1812
|
-
: '
|
|
1823
|
+
: '还没有' + brandName + ' —— 在「' + brandName + '」页加一条',
|
|
1813
1824
|
'aria-label': summary,
|
|
1814
1825
|
'aria-expanded': open ? 'true' : 'false',
|
|
1815
1826
|
className: cx('dt-btn', 'dt-btn-ghost', 'sa-orbit-trigger', watchers === null && 'is-loading'),
|
|
@@ -1979,7 +1990,7 @@ window.__ModuleLoader__.load({
|
|
|
1979
1990
|
|
|
1980
1991
|
const panelBody = h(React.Fragment, null,
|
|
1981
1992
|
h('div', { className: 'sa-dock-head' },
|
|
1982
|
-
h('span', { className: 'sa-dock-title' },
|
|
1993
|
+
h('span', { className: 'sa-dock-title' }, brandName),
|
|
1983
1994
|
// 和面板统计条同一套官方素材:dt-stat(数值强 + 单位弱),不再自己发明 sa-dock-metric-*
|
|
1984
1995
|
h(Stat, {
|
|
1985
1996
|
className: 'sa-dock-metric',
|
|
@@ -1990,13 +2001,13 @@ window.__ModuleLoader__.load({
|
|
|
1990
2001
|
watchers === null
|
|
1991
2002
|
? (!readError ? h('div', { className: 'sa-dock-empty' }, '正在读取…') : null)
|
|
1992
2003
|
: list.length === 0
|
|
1993
|
-
? h('div', { className: 'sa-dock-empty' }, '
|
|
2004
|
+
? h('div', { className: 'sa-dock-empty' }, '还没有。在「' + brandName + '」标签页填 owner/name 加一条。')
|
|
1994
2005
|
: h(hostOrbitRow ? 'ul' : 'div', { className: 'sa-dock-rows' }, rows),
|
|
1995
2006
|
// 读失败与写操作失败分开说;旧列表仍可保留在错误上方。
|
|
1996
2007
|
readError ? h('div', { className: 'sa-dock-err', role: 'alert' }, readError) : null,
|
|
1997
2008
|
!readError && orbitError ? h('div', { className: 'sa-dock-err', role: 'alert' }, '操作失败:' + orbitError) : null,
|
|
1998
2009
|
list.length > 0
|
|
1999
|
-
? h('div', { className: 'sa-dock-foot' }, '
|
|
2010
|
+
? h('div', { className: 'sa-dock-foot' }, '详细状态与凭证在「' + brandName + '」标签页')
|
|
2000
2011
|
: null)
|
|
2001
2012
|
|
|
2002
2013
|
const panel = hostOrbit
|
|
@@ -2285,10 +2296,13 @@ window.__ModuleLoader__.load({
|
|
|
2285
2296
|
const body = snap.body || {}
|
|
2286
2297
|
// 默认值提示从后端读:写死 12/3/6 会在常量变化后变成谎话(JSON Schema 的 default 也是这个用法)
|
|
2287
2298
|
const DEFAULTS = body.defaults || {}
|
|
2299
|
+
// 品牌与默认 ack 都来自 /state(issue #11);缺省时保持 0.10.0 的文案。
|
|
2300
|
+
const BRAND = (typeof body.brandName === 'string' && body.brandName.trim()) || '主理鱼'
|
|
2301
|
+
const ACK_DEFAULTS = body.defaultAckLabels || null
|
|
2288
2302
|
const watchers = body.watchers || []
|
|
2289
2303
|
// 行内编辑只有这一条入口:clean 维持原直达行为;dirty 先确认,取消绝不重置 draft/touched。
|
|
2290
2304
|
const applyWatcherEditor = (watcher, nextKey) => {
|
|
2291
|
-
const values = watcherValuesFrom(watcher)
|
|
2305
|
+
const values = watcherValuesFrom(watcher, ACK_DEFAULTS)
|
|
2292
2306
|
setEditing(nextKey)
|
|
2293
2307
|
touchedRef.current = new Set()
|
|
2294
2308
|
editSnapshotRef.current = nextKey ? { key: nextKey, values } : null
|
|
@@ -2300,7 +2314,7 @@ window.__ModuleLoader__.load({
|
|
|
2300
2314
|
activeHours: watcher.activeHours || '',
|
|
2301
2315
|
// `watcher.goal` 可能是 goalView 对象;输入框只能接收已展开的字符串。
|
|
2302
2316
|
goal: watcher.note || (typeof watcher.goal === 'string' ? watcher.goal : (watcher.goal && watcher.goal.objective) || ''),
|
|
2303
|
-
ackLabel: watcher.ackLabel || (watcher
|
|
2317
|
+
ackLabel: watcher.ackLabel || ackLabelFallback(watcher, ACK_DEFAULTS),
|
|
2304
2318
|
onlyAssigned: !!(watcher.filters && watcher.filters.onlyAssigned),
|
|
2305
2319
|
allowAuthors: (watcher.filters && watcher.filters.allowAuthors ? watcher.filters.allowAuthors : []).join(', '),
|
|
2306
2320
|
observe: !!watcher.observe,
|
|
@@ -2321,7 +2335,7 @@ window.__ModuleLoader__.load({
|
|
|
2321
2335
|
const editingWatcher = watchers.find((watcher) => watcher.repo + '#' + watcher.sessionId === editing)
|
|
2322
2336
|
const editingOpening = editSnapshotRef.current && editSnapshotRef.current.key === editing
|
|
2323
2337
|
? editSnapshotRef.current.values
|
|
2324
|
-
: editingWatcher ? watcherValuesFrom(editingWatcher) : null
|
|
2338
|
+
: editingWatcher ? watcherValuesFrom(editingWatcher, ACK_DEFAULTS) : null
|
|
2325
2339
|
const editingDirty = Boolean(editing && editingOpening && (
|
|
2326
2340
|
touchedRef.current.size > 0 || watcherDirty({ ...editingOpening, ...draft }, editingOpening)))
|
|
2327
2341
|
const pendingCollapseKey = glossary && glossary.type === 'watcher-draft' && !glossary.nextKey
|
|
@@ -2624,7 +2638,7 @@ window.__ModuleLoader__.load({
|
|
|
2624
2638
|
const rowBody = h('div', { className: 'dt-ticket-body' },
|
|
2625
2639
|
h('div', { className: 'dt-row-title' },
|
|
2626
2640
|
h('button', {
|
|
2627
|
-
type: 'button', className: 'dt-open', title: '
|
|
2641
|
+
type: 'button', className: 'dt-open', title: '展开或收起这条' + BRAND + '的设置',
|
|
2628
2642
|
'aria-expanded': displayedEditing === key, onClick: () => toggleWatcherEditor(watcher),
|
|
2629
2643
|
}, watcher.repo)),
|
|
2630
2644
|
pauseNote(watcher),
|
|
@@ -2640,7 +2654,7 @@ window.__ModuleLoader__.load({
|
|
|
2640
2654
|
watcher.isolated ? h(Tag, null, isolationText(watcher)) : null,
|
|
2641
2655
|
filterText(watcher.filters) ? h(Tag, null, filterText(watcher.filters)) : null,
|
|
2642
2656
|
// ack 标签决定这条是否还会被叫醒,不能只在工具参数里出现。
|
|
2643
|
-
h(Tag, { tone: 'quiet' }, '回执 ' + (watcher.ackLabel || (watcher
|
|
2657
|
+
h(Tag, { tone: 'quiet' }, '回执 ' + (watcher.ackLabel || ackLabelFallback(watcher, ACK_DEFAULTS))),
|
|
2644
2658
|
watcher.queuedWakes > 0 ? h(Tag, { tone: 'warning' }, '排队 ' + watcher.queuedWakes) : null,
|
|
2645
2659
|
backoffText(watcher) ? h(Tag, { tone: 'warning' }, backoffText(watcher)) : null),
|
|
2646
2660
|
// 三行,各管一件事:① 是谁 ② 节律与最近结果 ③ 目标
|
|
@@ -2714,7 +2728,7 @@ window.__ModuleLoader__.load({
|
|
|
2714
2728
|
})))
|
|
2715
2729
|
const opening = editSnapshotRef.current && editSnapshotRef.current.key === key
|
|
2716
2730
|
? editSnapshotRef.current.values
|
|
2717
|
-
: watcherValuesFrom(watcher)
|
|
2731
|
+
: watcherValuesFrom(watcher, ACK_DEFAULTS)
|
|
2718
2732
|
const editorValue = { ...opening, ...draft }
|
|
2719
2733
|
const editor = displayedEditing === key
|
|
2720
2734
|
? h(WatcherForm, {
|
|
@@ -2881,7 +2895,7 @@ window.__ModuleLoader__.load({
|
|
|
2881
2895
|
filterSummary,
|
|
2882
2896
|
h('div', { className: 'dt-stats', key: 'stats' },
|
|
2883
2897
|
h(Stat, {
|
|
2884
|
-
key: 'all', value: watchers.length, unit: '
|
|
2898
|
+
key: 'all', value: watchers.length, unit: '条' + BRAND,
|
|
2885
2899
|
active: stateFilter === null, onClick: () => setStateFilter(null),
|
|
2886
2900
|
}),
|
|
2887
2901
|
h(Stat, {
|
|
@@ -2958,16 +2972,16 @@ window.__ModuleLoader__.load({
|
|
|
2958
2972
|
'代码已更新到 ' + body.installedVersion + ',但宿主还在跑 ' + body.runningVersion
|
|
2959
2973
|
+ ' —— 服务端改动需要重启宿主才生效(客户端部分已生效,所以界面可能看起来是新的)。')
|
|
2960
2974
|
: null,
|
|
2961
|
-
h(Section, { key: 'list', title: needle ? '搜索结果' :
|
|
2975
|
+
h(Section, { key: 'list', title: needle ? '搜索结果' : BRAND, count: visible.length },
|
|
2962
2976
|
watchers.length === 0
|
|
2963
2977
|
? h(Onboarding, { onStart: () => setTab('trigger') })
|
|
2964
2978
|
: visible.length === 0
|
|
2965
2979
|
? h('div', { className: 'dt-empty' },
|
|
2966
2980
|
h(Hint, null, needle
|
|
2967
|
-
? '没有匹配「' + search.trim() + '
|
|
2981
|
+
? '没有匹配「' + search.trim() + '」的' + BRAND + '。'
|
|
2968
2982
|
: hasActiveFilters
|
|
2969
|
-
? '
|
|
2970
|
-
: '
|
|
2983
|
+
? '没有符合当前筛选条件的' + BRAND + '。'
|
|
2984
|
+
: '当前没有可显示的' + BRAND + '。'),
|
|
2971
2985
|
hasActiveFilters
|
|
2972
2986
|
? h('div', { className: 'dt-actions' },
|
|
2973
2987
|
h(Btn, { size: 'sm', variant: 'outline', onClick: clearAllFilters }, '清除全部筛选'))
|
|
@@ -3055,7 +3069,7 @@ window.__ModuleLoader__.load({
|
|
|
3055
3069
|
// 判定页的空态也要给路径:说清「加一条之后这里会出现什么」,而不是一句「还没有主理鱼」
|
|
3056
3070
|
? h('div', { className: 'dt-empty' },
|
|
3057
3071
|
h('p', { className: 'dt-step-title' }, '还没有可判定的记录'),
|
|
3058
|
-
h('p', { className: 'dt-step-detail' }, '
|
|
3072
|
+
h('p', { className: 'dt-step-detail' }, '添加一条' + BRAND + '之后,每轮判定都会记在这里:唤醒、仅观察,或跳过及其原因。'),
|
|
3059
3073
|
h('div', { className: 'dt-actions' },
|
|
3060
3074
|
h(Btn, { size: 'sm', variant: 'primary', onClick: () => setTab('trigger') }, '去添加第一条')))
|
|
3061
3075
|
: (() => {
|
|
@@ -3208,7 +3222,7 @@ window.__ModuleLoader__.load({
|
|
|
3208
3222
|
group.silentWakes > 0 ? h('span', { className: 'dt-error-text' }, '未回音 ' + group.silentWakes + ' 次') : null,
|
|
3209
3223
|
group.errors > 0 ? h('span', { className: 'dt-error-text' }, group.errors + ' 条报错') : null))))))
|
|
3210
3224
|
|
|
3211
|
-
const trigger = h(Section, { title: '
|
|
3225
|
+
const trigger = h(Section, { title: '新增' + BRAND },
|
|
3212
3226
|
h(WatcherForm, {
|
|
3213
3227
|
mode: 'create', idPrefix: 'watcher-new', value: { ...CREATE_WATCHER_VALUES, ...form },
|
|
3214
3228
|
snapshot: createSnapshotRef.current, defaults: DEFAULTS, disabled: !sessionId, sessionId,
|
|
@@ -3567,7 +3581,7 @@ window.__ModuleLoader__.load({
|
|
|
3567
3581
|
return h('div', { className: 'dt-page' },
|
|
3568
3582
|
h('div', { className: 'dt-page-head' },
|
|
3569
3583
|
h('div', null,
|
|
3570
|
-
h('h1', { className: 'dt-page-title' },
|
|
3584
|
+
h('h1', { className: 'dt-page-title' }, BRAND),
|
|
3571
3585
|
h('span', { className: 'dt-hint' },
|
|
3572
3586
|
(body.sessionTitle ? '会话:' + body.sessionTitle + ' · ' : '')
|
|
3573
3587
|
+ (sessionId ? '盯办 + 主动办:仓库有动静就叫醒本会话' : '(在会话里打开本面板,才能把仓库绑到会话上)'))),
|
|
@@ -3662,16 +3676,16 @@ window.__ModuleLoader__.load({
|
|
|
3662
3676
|
onClick: () => copyText(AGENTS_SNIPPET, '规则已复制,粘贴到 AGENTS.md 末尾即可'),
|
|
3663
3677
|
}, '复制这段规则'),
|
|
3664
3678
|
h(Btn, { size: 'sm', variant: 'ghost', onClick: () => setGlossary(false) }, '关闭'))) : null,
|
|
3665
|
-
h(PanelModal, { open: glossary === true, title: '
|
|
3679
|
+
h(PanelModal, { open: glossary === true, title: BRAND + '术语表', onClose: () => setGlossary(false) },
|
|
3666
3680
|
h(KeyValues, { rows: [
|
|
3667
|
-
[
|
|
3681
|
+
[BRAND, '一条「盯办」绑定:某个仓库 → 某个会话'],
|
|
3668
3682
|
['盯', '轮询 issue/PR、按水位去重、冷却期吸收自己的操作'],
|
|
3669
3683
|
['办', '唤醒会话后按仓库 AGENTS.md 主动处理,完成后 watch_ack 打标签'],
|
|
3670
|
-
['唤醒', '只在会话空闲(idle
|
|
3684
|
+
['唤醒', '只在会话空闲(idle)时注入一条【' + BRAND + '】消息'],
|
|
3671
3685
|
['过滤', '标签白名单/黑名单、只看已指派、跳过机器人/草稿/已关闭'],
|
|
3672
3686
|
['时段', 'activeHours,比如 09:00-23:00,时段外只攒不唤醒'],
|
|
3673
3687
|
['隔离', 'isolated:每次唤醒开一次性 git worktree,改副本不碰主工作区'],
|
|
3674
|
-
['ack', '
|
|
3688
|
+
['ack', '处理完给条目打「' + (ACK_DEFAULTS && ACK_DEFAULTS.github ? ACK_DEFAULTS.github : '主理鱼:已处理') + '」标签,轮询直接跳过'],
|
|
3675
3689
|
['goal', '会话目标(ctx.goals),和 /goal 命令同一份状态'],
|
|
3676
3690
|
['凭证', 'token 存在服务端 secrets.json,面板只显示是否已配置'],
|
|
3677
3691
|
['上限', '两种:单条守每小时最多 6 次、整条会话 12 次(面板里可调);和 GitHub 的限流不是一回事'],
|
package/lib/index.js
CHANGED
|
@@ -21,6 +21,8 @@ import { fileURLToPath } from 'node:url'
|
|
|
21
21
|
|
|
22
22
|
import { zstdDecompressSync } from 'node:zlib'
|
|
23
23
|
|
|
24
|
+
import Schema from '@deepseek-ai/schemastery'
|
|
25
|
+
|
|
24
26
|
import { redact } from './redact.js'
|
|
25
27
|
import { decodeBody, truncateUtf8 } from './body.js'
|
|
26
28
|
import { quotaDeferText, isOfflineMode } from './gh-format.js'
|
|
@@ -29,7 +31,8 @@ import { migrateState, CURRENT_STATE_SCHEMA } from './state-migration.js'
|
|
|
29
31
|
import { runExclusiveUpdate, spawnPluginUpdate, validateUpdateBody } from './update.js'
|
|
30
32
|
import { compareSemver, isStrictSemver } from './semver.js'
|
|
31
33
|
import {
|
|
32
|
-
effectiveIntervalMs, planWakeSettlement, advanceSeen, applyWatcherAction, batchFresh, decideWake, DEFAULT_ACK_LABEL, DEFAULT_PRIORITY, formatWatchText,
|
|
34
|
+
effectiveIntervalMs, planWakeSettlement, advanceSeen, applyWatcherAction, batchFresh, decideWake, DEFAULT_ACK_LABEL, DEFAULT_BRAND_NAME, DEFAULT_PRIORITY, formatWatchText,
|
|
35
|
+
defaultAckLabelFor, normalizeBrandName,
|
|
33
36
|
recordPendingWake, clearPending, pendingRetry,
|
|
34
37
|
wakeQuality,
|
|
35
38
|
parseRepoSpec, markGiteeReopened,
|
|
@@ -49,7 +52,7 @@ import {
|
|
|
49
52
|
|
|
50
53
|
export const name = 'dsh-session-superagent'
|
|
51
54
|
/** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
|
|
52
|
-
export const SERVER_VERSION = '0.10.
|
|
55
|
+
export const SERVER_VERSION = '0.10.1'
|
|
53
56
|
export const inject = ['tools', 'agents', 'webServer']
|
|
54
57
|
/** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
|
|
55
58
|
// 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
|
|
@@ -110,11 +113,64 @@ function toolError(args, message) {
|
|
|
110
113
|
}
|
|
111
114
|
/** 全局上限:每条守一个定时器,无限建等于自造 DoS(审核 T19)。 */
|
|
112
115
|
const MAX_WATCHERS_TOTAL = 200
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 插件配置(issue #11):品牌名 + 两家默认 ack 标签。
|
|
119
|
+
*
|
|
120
|
+
* 为什么用官方 schemastery:DSH 的 loader 会在 `apply()` 之前按这份 schema 校验并补默认值,
|
|
121
|
+
* 设置页也直接吃它的 `default` / `description`。手写一遍校验等于把同一套规则维护两次。
|
|
122
|
+
*
|
|
123
|
+
* 三个字段各自独立:`brandName` 只影响抬头与面板标题;两个 ack 标签按 provider 分开,
|
|
124
|
+
* 因为 Gitee 的标签名不允许半角冒号(真机 2026-11-05 实测),默认值本来就不一样。
|
|
125
|
+
*/
|
|
126
|
+
export const Config = Schema.object({
|
|
127
|
+
brandName: Schema.string().default(DEFAULT_BRAND_NAME)
|
|
128
|
+
.description('唤醒抬头与面板标题里的品牌名(默认「' + DEFAULT_BRAND_NAME + '」)'),
|
|
129
|
+
defaultAckLabel: Schema.string().default(DEFAULT_ACK_LABEL)
|
|
130
|
+
.description('新建 GitHub 守的默认已处理标签(默认「' + DEFAULT_ACK_LABEL + '」)'),
|
|
131
|
+
defaultAckLabelGitee: Schema.string().default(DEFAULT_ACK_LABEL_GITEE)
|
|
132
|
+
.description('新建 Gitee 守的默认已处理标签;只能用 Gitee 允许的字符,不能带半角冒号(默认「' + DEFAULT_ACK_LABEL_GITEE + '」)'),
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* ack 标签归一化:trim、空值回落、Gitee 校验非法字符。
|
|
137
|
+
*
|
|
138
|
+
* Gitee 的规则比 GitHub 严(见 lib/gitee.js 的 `isValidGiteeLabel`)——
|
|
139
|
+
* 配一个带半角冒号的值如果不校验,每次 `watch_ack` 都会 404,而错误信息还指向仓库。
|
|
140
|
+
* 宁可回落默认,也不要让整条守废掉。
|
|
141
|
+
*/
|
|
142
|
+
export function normalizeDefaultAckLabel(value, provider, fallback) {
|
|
143
|
+
const text = String(value ?? '').trim()
|
|
144
|
+
if (provider === 'gitee') {
|
|
145
|
+
if (!text || !isValidGiteeLabel(text)) return fallback || DEFAULT_ACK_LABEL_GITEE
|
|
146
|
+
return text
|
|
147
|
+
}
|
|
148
|
+
if (!text) return fallback || DEFAULT_ACK_LABEL
|
|
149
|
+
// 与手工填写的上限一致(watch_start / 面板保存都截 60)
|
|
150
|
+
return text.slice(0, 60)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* 把 `apply()` 的 options 归一成运行时品牌配置。
|
|
155
|
+
*
|
|
156
|
+
* 正常情况下 options 是 cordis 用 `Config` 校验后的对象(默认值已补齐);
|
|
157
|
+
* 单测/直接调用会传 `{}` 或只传更新 runner —— 这里必须自己兜住默认值。
|
|
158
|
+
*/
|
|
159
|
+
export function resolveBrandConfig(options = {}) {
|
|
160
|
+
const source = options && typeof options === 'object' ? options : {}
|
|
161
|
+
return Object.freeze({
|
|
162
|
+
brandName: normalizeBrandName(source.brandName),
|
|
163
|
+
defaultAckLabels: Object.freeze({
|
|
164
|
+
github: normalizeDefaultAckLabel(source.defaultAckLabel, 'github', DEFAULT_ACK_LABEL),
|
|
165
|
+
gitee: normalizeDefaultAckLabel(source.defaultAckLabelGitee, 'gitee', DEFAULT_ACK_LABEL_GITEE),
|
|
166
|
+
}),
|
|
167
|
+
})
|
|
168
|
+
}
|
|
113
169
|
/** 隔离区回收的最小间隔:没有超额时不必每次唤醒都跑 git。 */
|
|
114
170
|
const CLEANUP_INTERVAL_MS = 10 * 60 * 1000
|
|
115
171
|
|
|
116
172
|
/** 仅供测试:读写状态文件(生产代码不要用)。 */
|
|
117
|
-
export const __test = { readState, writeState, hardenSecretsFile, wakeMerged, flushWakeQueue, wakeQueueCount, clearWakeQueues, setAuthStatusCache: (text) => { authStatusCache = { at: text ? Date.now() : 0, text } } }
|
|
173
|
+
export const __test = { readState, writeState, hardenSecretsFile, wakeMerged, flushWakeQueue, wakeQueueCount, clearWakeQueues, pollWithItems, setAuthStatusCache: (text) => { authStatusCache = { at: text ? Date.now() : 0, text } } }
|
|
118
174
|
|
|
119
175
|
// 审核 T30:这四个路径以前在**模块加载那一刻**定死 ——
|
|
120
176
|
// 测试里改 `process.env.DSH_SUPERAGENT_STATE` 之后,已经加载的实例仍然指着老目录,
|
|
@@ -217,6 +273,10 @@ function readState() {
|
|
|
217
273
|
// 读取时归一,写盘时自然带走(同 normalizePaused 的思路)。
|
|
218
274
|
function normalizeAckLabel(entry) {
|
|
219
275
|
if (!entry || entry.provider !== 'gitee') return entry
|
|
276
|
+
// issue #11:**没有** ackLabel 的历史守不能在这里补默认值 —— 补了就会把插件配置的
|
|
277
|
+
// `defaultAckLabelGitee` 短路掉(`entry.ackLabel ||` 永远先命中旧默认)。
|
|
278
|
+
// 这里只修「存了一个 Gitee 建不出来的旧标签」,空值留给调用方按配置派生。
|
|
279
|
+
if (typeof entry.ackLabel !== 'string' || !entry.ackLabel.trim()) return entry
|
|
220
280
|
if (!isValidGiteeLabel(entry.ackLabel)) entry.ackLabel = suggestGiteeLabel(entry.ackLabel)
|
|
221
281
|
return entry
|
|
222
282
|
}
|
|
@@ -713,9 +773,12 @@ function run(file, args, options = {}) {
|
|
|
713
773
|
})
|
|
714
774
|
}
|
|
715
775
|
|
|
716
|
-
/**
|
|
717
|
-
|
|
718
|
-
|
|
776
|
+
/**
|
|
777
|
+
* 默认 ack 标签按 provider 走:Gitee 的标签名不允许半角冒号(真机实测拒建)。
|
|
778
|
+
* `labels` 来自插件配置(见 resolveBrandConfig);不传时保持 0.10.0 的默认。
|
|
779
|
+
*/
|
|
780
|
+
function defaultAckLabel(provider, labels) {
|
|
781
|
+
return defaultAckLabelFor(provider, labels)
|
|
719
782
|
}
|
|
720
783
|
|
|
721
784
|
function defineTool(options) {
|
|
@@ -829,7 +892,7 @@ function clearWakeQueues(ctx) {
|
|
|
829
892
|
}
|
|
830
893
|
}
|
|
831
894
|
|
|
832
|
-
function wakeMerged(ctx, sessionId, text, onSettled, queueKey = '') {
|
|
895
|
+
function wakeMerged(ctx, sessionId, text, onSettled, queueKey = '', brandName = DEFAULT_BRAND_NAME) {
|
|
833
896
|
// 同一事件已在队列里时不重复入队;先尝试 flush,空闲时会立即把旧队列送完。
|
|
834
897
|
flushWakeQueue(ctx, sessionId)
|
|
835
898
|
if (hasQueuedWake(sessionId, queueKey, ctx)) {
|
|
@@ -846,7 +909,7 @@ function wakeMerged(ctx, sessionId, text, onSettled, queueKey = '') {
|
|
|
846
909
|
wakeBuffers.delete(sessionId)
|
|
847
910
|
let result = { ok: false, reason: '合并后没有内容可发(这几条都已被处理过)—— 不用管,下一轮会重新判断' }
|
|
848
911
|
try {
|
|
849
|
-
const merged = mergeWakeTexts(buf.parts)
|
|
912
|
+
const merged = mergeWakeTexts(buf.parts, { brandName })
|
|
850
913
|
if (merged) {
|
|
851
914
|
result = wake(ctx, sessionId, merged)
|
|
852
915
|
if (isBusyWakeResult(result)) result = enqueueWake(ctx, sessionId, merged, buf.settled, queueKey)
|
|
@@ -1197,7 +1260,7 @@ async function fetchLastComments(repo, items, maxItems = 3, options = {}) {
|
|
|
1197
1260
|
}))
|
|
1198
1261
|
}
|
|
1199
1262
|
|
|
1200
|
-
async function pollOnce(ctx, entry, baseMs) {
|
|
1263
|
+
async function pollOnce(ctx, entry, baseMs, brand = null) {
|
|
1201
1264
|
// 活跃时段要**在拉 API 之前**判断:以前放在后面,夜里照样每 N 秒打一次 GitHub,纯浪费。
|
|
1202
1265
|
// 不在时段内就把下一次轮询安排到"开门那一刻",攒着的条目不会多等一个周期。
|
|
1203
1266
|
if (entry.activeHours && !inActiveHours(entry.activeHours)) {
|
|
@@ -1270,7 +1333,7 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
1270
1333
|
return
|
|
1271
1334
|
}
|
|
1272
1335
|
// 归一后的条目直接交给共用判定:形状已和 GitHub 一致,后面不该再分两家
|
|
1273
|
-
return pollWithItems(ctx, entry, baseMs, { status: 200, etag: null, body: JSON.stringify(items) })
|
|
1336
|
+
return pollWithItems(ctx, entry, baseMs, { status: 200, etag: null, body: JSON.stringify(items) }, brand)
|
|
1274
1337
|
}
|
|
1275
1338
|
|
|
1276
1339
|
const args = ['api', '--include', `repos/${entry.repo}/issues?state=all&sort=updated&direction=desc&per_page=20`]
|
|
@@ -1363,7 +1426,7 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
1363
1426
|
// 原因:下面有多个提前 return 的分支(会话正忙 / 会话上限 / 每小时上限 / 本轮被暂停 / 会话已不在)。
|
|
1364
1427
|
// 它们刻意不动 seen/cursor(注释也写了「否则攒着等于丢掉」),但 ETag 若已前移,
|
|
1365
1428
|
// 下一轮条件请求就会拿到 304 并在上面直接 return,fresh 永远不再重算 —— 效果同样是「攒着=丢掉」。
|
|
1366
|
-
return pollWithItems(ctx, entry, baseMs, parsed)
|
|
1429
|
+
return pollWithItems(ctx, entry, baseMs, parsed, brand)
|
|
1367
1430
|
}
|
|
1368
1431
|
|
|
1369
1432
|
/**
|
|
@@ -1372,7 +1435,7 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
1372
1435
|
* 抽出来是为了让 GitHub 与 Gitee 共用同一套判定 —— 两家只有「怎么拿数据」不同,
|
|
1373
1436
|
* 「要不要叫醒、叫醒说什么、水位怎么走」必须完全一致,否则同一条 bug 要修两遍。
|
|
1374
1437
|
*/
|
|
1375
|
-
async function pollWithItems(ctx, entry, baseMs, parsed) {
|
|
1438
|
+
async function pollWithItems(ctx, entry, baseMs, parsed, brand = null) {
|
|
1376
1439
|
const pendingEtag = parsed.etag
|
|
1377
1440
|
const commitEtag = () => { if (pendingEtag) entry.etag = pendingEtag }
|
|
1378
1441
|
let items
|
|
@@ -1403,7 +1466,7 @@ async function pollWithItems(ctx, entry, baseMs, parsed) {
|
|
|
1403
1466
|
// 触发要有许可:过滤器不通过的条目根本不进候选集,也不写 seen 水位
|
|
1404
1467
|
// 记忆要有遗忘:seen 只增不减会问成几 MB 的字典
|
|
1405
1468
|
entry.seen = pruneSeen(entry.seen)
|
|
1406
|
-
const ackLabel = entry.ackLabel || defaultAckLabel(entry.provider)
|
|
1469
|
+
const ackLabel = entry.ackLabel || defaultAckLabel(entry.provider, brand && brand.defaultAckLabels)
|
|
1407
1470
|
// 幂等痕迹留在 GitHub 上:带 ack 标签的条目直接跳过(换机器、删状态都不会重报)
|
|
1408
1471
|
const considered = []
|
|
1409
1472
|
// 每轮重置:这行要被读成「本轮跳过多少」,累计值会越滚越大、误导客户
|
|
@@ -1567,6 +1630,8 @@ async function pollWithItems(ctx, entry, baseMs, parsed) {
|
|
|
1567
1630
|
// 此时"有动态"其实是"仓库里本来就有这些待处理",说成新动态会让人以为刚刚发生。
|
|
1568
1631
|
const firstSync = !entry.cursor
|
|
1569
1632
|
const wakeText = formatWatchText(entry.repo, listed, {
|
|
1633
|
+
// 品牌名(issue #11):抬头【…】与面板/诊断共用同一份配置
|
|
1634
|
+
brandName: brand ? brand.brandName : undefined,
|
|
1570
1635
|
more: rest.length,
|
|
1571
1636
|
firstSync,
|
|
1572
1637
|
restNumbers: rest.map((item) => item.number),
|
|
@@ -1643,10 +1708,13 @@ async function pollWithItems(ctx, entry, baseMs, parsed) {
|
|
|
1643
1708
|
if (settled.lastDeferred) entry.lastDeferred = settled.lastDeferred
|
|
1644
1709
|
if (settled.bumpBackoff) bumpFailure(entry, baseMs)
|
|
1645
1710
|
} persistEntry(entry)
|
|
1646
|
-
}, wakeQueueKey)
|
|
1711
|
+
}, wakeQueueKey, brand ? brand.brandName : undefined)
|
|
1647
1712
|
}
|
|
1648
1713
|
|
|
1649
1714
|
export function apply(ctx, options = {}) {
|
|
1715
|
+
// 品牌配置(issue #11):options 是 cordis 按 Config 校验后的对象;
|
|
1716
|
+
// 直接调用(单测 / 老宿主)时由 resolveBrandConfig 兜住默认值。
|
|
1717
|
+
const brand = resolveBrandConfig(options)
|
|
1650
1718
|
// 更新 runner 可注入:路由测试绝不发起真实安装;生产默认走 shell:false 的 CLI runner。
|
|
1651
1719
|
const updateRunner = options.updateRunner || spawnPluginUpdate
|
|
1652
1720
|
const updateTimeoutMs = options.updateTimeoutMs
|
|
@@ -1716,7 +1784,7 @@ export function apply(ctx, options = {}) {
|
|
|
1716
1784
|
if (inFlight.has(entry.id)) return
|
|
1717
1785
|
inFlight.add(entry.id)
|
|
1718
1786
|
try {
|
|
1719
|
-
await pollOnce(ctx, entry, every)
|
|
1787
|
+
await pollOnce(ctx, entry, every, brand)
|
|
1720
1788
|
// GitHub 要求的间隔比我们的长:把下一轮推到它之后(成功路径也生效)
|
|
1721
1789
|
const floor = (Number(entry.minIntervalSec) || 0) * 1000
|
|
1722
1790
|
if (floor > every) entry.nextAt = new Date(Date.now() + floor).toISOString()
|
|
@@ -1892,7 +1960,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
1892
1960
|
repo: w.repo,
|
|
1893
1961
|
// 面板要能一眼分出 GitHub / Gitee:否则行内只能靠 id 前缀猜
|
|
1894
1962
|
provider: w.provider === 'gitee' ? 'gitee' : 'github',
|
|
1895
|
-
ackLabel: w.ackLabel || defaultAckLabel(w.provider),
|
|
1963
|
+
ackLabel: w.ackLabel || defaultAckLabel(w.provider, brand.defaultAckLabels),
|
|
1896
1964
|
// 会话忙时真正排在 FIFO 里的条数;0 表示没有排队,不靠猜 lastDeferred。
|
|
1897
1965
|
queuedWakes: wakeQueueCount(w.sessionId, ctx),
|
|
1898
1966
|
sessionId: w.sessionId,
|
|
@@ -1968,6 +2036,10 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
1968
2036
|
sessionTitle: sessionTitle(focusSession),
|
|
1969
2037
|
retryPolicy: { budgetAttempts: RETRY_BUDGET_ATTEMPTS, slowCapMinutes: RETRY_SLOW_CAP_MINUTES },
|
|
1970
2038
|
defaults: { sessionMaxWakes: DEFAULT_SESSION_WAKES, maxWakesPerHour: DEFAULT_WAKES_PER_HOUR, isolateKeepDays: DEFAULT_ISOLATE_KEEP_DAYS, batchLimit: DEFAULT_BATCH_LIMIT },
|
|
2039
|
+
// issue #11:品牌与两家默认 ack 标签由服务端下发 —— 客户端不再各自写死「主理鱼」。
|
|
2040
|
+
// 放在 stateBody 里就自动进了 ETag 的稳定字段:配置变了,下一次轮询一定不是 304。
|
|
2041
|
+
brandName: brand.brandName,
|
|
2042
|
+
defaultAckLabels: brand.defaultAckLabels,
|
|
1971
2043
|
watchers: watchers.map((w) => ({ ...w, goal: goalView(ctx, w.sessionId) })),
|
|
1972
2044
|
}
|
|
1973
2045
|
// ETag/304:面板每 5 秒拉一次 /state,没变化时没必要重传整份 JSON ——
|
|
@@ -2108,7 +2180,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2108
2180
|
if (inFlight.has(id)) return json(res, 409, { error: '上一轮轮询还没结束(网络慢或 GitHub 慢)—— 等十几秒再看', code: 'in_flight', id })
|
|
2109
2181
|
const every = Math.max(30, Number(entry.intervalSec) || 60) * 1000
|
|
2110
2182
|
inFlight.add(id)
|
|
2111
|
-
pollOnce(ctx, entry, every)
|
|
2183
|
+
pollOnce(ctx, entry, every, brand)
|
|
2112
2184
|
.catch(() => {})
|
|
2113
2185
|
.finally(() => { inFlight.delete(id); persistEntry(entry) })
|
|
2114
2186
|
return json(res, 202, { ok: true, action, id, polling: true })
|
|
@@ -2169,7 +2241,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2169
2241
|
id, repo, provider, sessionId, cursor: null, seen: {}, lastReported: {},
|
|
2170
2242
|
cooldownMs: 180000, createdAt: new Date().toISOString(),
|
|
2171
2243
|
filters: normalizeFilters(), batchLimit: 5, maxWakesPerHour: 6,
|
|
2172
|
-
wakeTimes: [], consecutiveFailures: 0, ackLabel: defaultAckLabel(provider),
|
|
2244
|
+
wakeTimes: [], consecutiveFailures: 0, ackLabel: defaultAckLabel(provider, brand.defaultAckLabels),
|
|
2173
2245
|
isolated: false, workdir: null,
|
|
2174
2246
|
}
|
|
2175
2247
|
entry.provider = provider
|
|
@@ -2574,13 +2646,14 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2574
2646
|
ctx.tools.register(defineTool({
|
|
2575
2647
|
name: 'watch_ack',
|
|
2576
2648
|
description:
|
|
2577
|
-
'Mark an issue/PR as handled: adds the ack label
|
|
2649
|
+
'Mark an issue/PR as handled: adds the ack label (' + brand.defaultAckLabels.github + ' by default on GitHub, '
|
|
2650
|
+
+ brand.defaultAckLabels.gitee + ' on Gitee) and advances the local watermark, so the same item will never wake this session again — even after a restart or on another machine.',
|
|
2578
2651
|
parameters: {
|
|
2579
2652
|
repo: { type: 'string', description: 'owner/name; defaults to the only watched repo' },
|
|
2580
2653
|
// 审核 T32 M4:实现里这两个必填其一(缺了直接报错),schema 却没标。
|
|
2581
2654
|
number: { type: ['number', 'string'], description: 'issue or PR number(Gitee 的编号是字符串,如 IKSQJH)' },
|
|
2582
2655
|
numbers: { type: 'string', description: '逗号分隔的多个编号,如 "12,13,14"(number 与 numbers 至少填一个)' },
|
|
2583
|
-
label: { type: 'string', description: 'ack label, default
|
|
2656
|
+
label: { type: 'string', description: 'ack label, default ' + brand.defaultAckLabels.github + ' on GitHub / ' + brand.defaultAckLabels.gitee + ' on Gitee' },
|
|
2584
2657
|
note: { type: 'string', description: '可选:一句话记下这条最后怎么处理的(如「已修,见 #57」「不修,上游已修」)。下次这条再被叫醒时会带回来,省得会话重新判一遍。' },
|
|
2585
2658
|
comment: { type: 'boolean', description: '把 note 作为评论回写到原 issue/PR(默认 false)。必须同时给 note;这是显式写操作。' },
|
|
2586
2659
|
kind: { type: 'string', description: "Gitee 评论回写时的条目类型:'issue'(默认)或 'pull';GitHub 不需要。" },
|
|
@@ -2606,7 +2679,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2606
2679
|
? watchers.find((w) => w && w.repo === String(args.repo))
|
|
2607
2680
|
: watchers.find((w) => w && w.enabled)
|
|
2608
2681
|
if (!entry) return toolError(args, 'no watcher for that repo — start one with watch_start first')
|
|
2609
|
-
const label = String(args.label || entry.ackLabel || defaultAckLabel(entry.provider))
|
|
2682
|
+
const label = String(args.label || entry.ackLabel || defaultAckLabel(entry.provider, brand.defaultAckLabels))
|
|
2610
2683
|
const note = typeof args.note === 'string' ? args.note.trim().slice(0, 200) : ''
|
|
2611
2684
|
if (args.comment === true && !note) return toolError(args, 'comment:true 需要同时提供 note —— 不会发一条空评论')
|
|
2612
2685
|
// GitHub 不会因为加标签而自动建标签:不存在时返回 422。先幂等建一次(已存在也返回 422,忽略)。
|
|
@@ -2876,7 +2949,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2876
2949
|
}
|
|
2877
2950
|
}
|
|
2878
2951
|
// 3. ack 标签是否存在(两家都要看:Gitee 不会自动建标签,更要说清楚)
|
|
2879
|
-
const label = entry.ackLabel || defaultAckLabel(entry.provider)
|
|
2952
|
+
const label = entry.ackLabel || defaultAckLabel(entry.provider, brand.defaultAckLabels)
|
|
2880
2953
|
if (isGitee) {
|
|
2881
2954
|
// Gitee 的标签必须先存在(watch_ack 会先查再建,但建不出来时要能看出是哪一步)——
|
|
2882
2955
|
// 以前这里只写一句规则,等于没检查。现在真的去查一次。
|
|
@@ -3017,7 +3090,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
3017
3090
|
isolateKeepDays: { type: 'number', description: 'With isolated: remove isolation worktrees older than this many days (1-30, default 3).' },
|
|
3018
3091
|
maxIsolated: { type: 'number', description: 'With isolated: keep at most this many worktrees, oldest removed first (1-50, default 5).' },
|
|
3019
3092
|
goal: { type: 'string', description: 'Optional per-watcher goal appended to the wake message.' },
|
|
3020
|
-
ackLabel: { type: 'string', description: 'Label used as the handled marker (default
|
|
3093
|
+
ackLabel: { type: 'string', description: 'Label used as the handled marker (default ' + brand.defaultAckLabels.github + ' on GitHub / ' + brand.defaultAckLabels.gitee + ' on Gitee). Two sessions watching the same repo share it unless each sets its own.' },
|
|
3021
3094
|
priority: { type: 'object', description: 'Priority switches; only explicitly supplied keys are changed. Boolean keys: reopened, comments, labels, unassigned, stale. Defaults: reopened/comments/labels=true; unassigned/stale=false. additionalProperties are unrestricted.' },
|
|
3022
3095
|
},
|
|
3023
3096
|
async execute(args) {
|
|
@@ -3052,7 +3125,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
3052
3125
|
id, repo, provider, sessionId,
|
|
3053
3126
|
intervalSec: 60,
|
|
3054
3127
|
cooldownMs: DEFAULT_COOLDOWN_MS,
|
|
3055
|
-
ackLabel: defaultAckLabel(provider),
|
|
3128
|
+
ackLabel: defaultAckLabel(provider, brand.defaultAckLabels),
|
|
3056
3129
|
priority: { ...DEFAULT_TOOL_PRIORITY },
|
|
3057
3130
|
cursor: null,
|
|
3058
3131
|
seen: {},
|
|
@@ -3210,7 +3283,11 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
3210
3283
|
const wsAgent = wsAgents && typeof wsAgents.currentInitiator === 'function' ? wsAgents.currentInitiator() : undefined
|
|
3211
3284
|
const wsSessionId = (wsAgent && wsAgent.id) || undefined
|
|
3212
3285
|
// 同一份数据:结构化视图 -> 文本只是它的一种渲染,两边永远对得上
|
|
3213
|
-
const view = statusView(list,
|
|
3286
|
+
const view = statusView(list, {
|
|
3287
|
+
...(wsSessionId ? { sessionId: wsSessionId } : {}),
|
|
3288
|
+
// 状态视图里的默认 ack 与 /state 同源(issue #11)
|
|
3289
|
+
defaultAckLabels: brand.defaultAckLabels,
|
|
3290
|
+
})
|
|
3214
3291
|
if (args && args.format === 'json') return JSON.stringify(view, null, 2)
|
|
3215
3292
|
// 默认只写「这条守是什么」;只有当它需要你注意时才追加原因。
|
|
3216
3293
|
// 以前每行都带 lastPoll/lastWake/err=-,十条守就是十行长日志。
|
package/lib/watch.js
CHANGED
|
@@ -5,6 +5,30 @@
|
|
|
5
5
|
* is allowed, what the wake text says) is unit-testable without a DSH host.
|
|
6
6
|
*/
|
|
7
7
|
import { repoBadges, classifyGhError } from './gh-format.js'
|
|
8
|
+
// Gitee 的标签名不允许半角冒号,它的默认 ack 与 GitHub 不同。
|
|
9
|
+
// 这里只取常量,不碰网络:gitee.js 的顶层没有任何副作用。
|
|
10
|
+
import { DEFAULT_ACK_LABEL_GITEE } from './gitee.js'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 品牌名的唯一默认值(issue #11)。
|
|
14
|
+
*
|
|
15
|
+
* 它出现在两处**结构性**文本里:唤醒抬头的「【品牌】…」和合并抬头的「【品牌】这一小段时间内…」。
|
|
16
|
+
* 这两处是会话解析消息的依据,所以默认值必须与 0.10.0 完全一致;
|
|
17
|
+
* 只有插件 Config 明确改了 `brandName` 时才换。
|
|
18
|
+
*/
|
|
19
|
+
export const DEFAULT_BRAND_NAME = '主理鱼'
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 归一化品牌名:trim、压平换行、空值回落默认。
|
|
23
|
+
*
|
|
24
|
+
* 抬头是**单行**结构(`【品牌】<repo> 有 N 条新动态:`)。品牌名里夹一个换行,
|
|
25
|
+
* 整段就会变成两行,看起来像第二条消息 —— 外部可配的文本必须先压平再进结构。
|
|
26
|
+
*/
|
|
27
|
+
export function normalizeBrandName(value, fallback = DEFAULT_BRAND_NAME) {
|
|
28
|
+
const text = String(value ?? '').trim()
|
|
29
|
+
if (!text) return fallback
|
|
30
|
+
return text.replace(/[\r\n]+/g, ' ')
|
|
31
|
+
}
|
|
8
32
|
|
|
9
33
|
/**
|
|
10
34
|
* Split items into "report now" and "absorb silently".
|
|
@@ -139,6 +163,7 @@ export function wakeCriteria({ isolation } = {}) {
|
|
|
139
163
|
*/
|
|
140
164
|
export function buildWakeSections(repo, items, options = {}) {
|
|
141
165
|
const list = items ?? []
|
|
166
|
+
const brandName = normalizeBrandName(options.brandName)
|
|
142
167
|
const more = Number(options.more) || 0
|
|
143
168
|
const lines = list.map((item) => {
|
|
144
169
|
const kind = item.pull_request ? 'PR' : 'issue'
|
|
@@ -262,8 +287,8 @@ export function buildWakeSections(repo, items, options = {}) {
|
|
|
262
287
|
? ['【完成标准】', ...criteria.map((line, i) => (i + 1) + '. ' + line)]
|
|
263
288
|
: []
|
|
264
289
|
const headerLine = options.firstSync
|
|
265
|
-
?
|
|
266
|
-
:
|
|
290
|
+
? `【${brandName}】${repo} 首次同步:仓库里现有 ${lines.length} 条待处理(接上之前就在的,不是刚刚发生):`
|
|
291
|
+
: `【${brandName}】${repo} 有 ${lines.length} 条新动态:`
|
|
267
292
|
const nextLine = '接下来:先读仓库 AGENTS.md 定「修 / 回 / 待定」;没有测试结果不算完成;'
|
|
268
293
|
+ (options.provider === 'gitee'
|
|
269
294
|
// Gitee 没有 gh CLI:回写走网页/API,别让会话去跑 gh 命令
|
|
@@ -832,7 +857,7 @@ export function sessionWakesLastHour(entries, sessionId, now = Date.now()) {
|
|
|
832
857
|
*
|
|
833
858
|
* 合并而不是"设个间隔挡掉":硬间隔会让先到的守永远赢,后面的守被饿死。
|
|
834
859
|
*/
|
|
835
|
-
export function mergeWakeTexts(parts) {
|
|
860
|
+
export function mergeWakeTexts(parts, options = {}) {
|
|
836
861
|
const list = (Array.isArray(parts) ? parts : []).filter((t) => typeof t === 'string' && t.trim())
|
|
837
862
|
if (list.length === 0) return ''
|
|
838
863
|
if (list.length === 1) return list[0]
|
|
@@ -878,7 +903,8 @@ export function mergeWakeTexts(parts) {
|
|
|
878
903
|
return at < 0 ? text : text.slice(0, at).replace(/[\s]+$/, '')
|
|
879
904
|
})
|
|
880
905
|
|
|
881
|
-
const
|
|
906
|
+
const brandName = normalizeBrandName(options && options.brandName)
|
|
907
|
+
const head = '【' + brandName + '】这一小段时间内有 ' + list.length + ' 处变化,合并成一条:'
|
|
882
908
|
const body = stripped.map((text, i) => String.fromCharCode(10, 10) + '—— 第 ' + (i + 1) + ' 处 ——' + String.fromCharCode(10) + text).join('')
|
|
883
909
|
return head + body + (tailBlock ? String.fromCharCode(10, 10) + tailBlock : '')
|
|
884
910
|
}
|
|
@@ -1132,6 +1158,19 @@ export function busierThanUsual(summary, { factor = 2, minDays = 3 } = {}) {
|
|
|
1132
1158
|
return today >= avg * Math.max(1.5, Number(factor) || 2)
|
|
1133
1159
|
}
|
|
1134
1160
|
|
|
1161
|
+
/**
|
|
1162
|
+
* 默认 ack 标签(issue #11):GitHub 用 `主理鱼:已处理`,Gitee 因为标签名不允许半角冒号用
|
|
1163
|
+
* `主理鱼-已处理`。品牌配置可以从 `labels` 传进来;不传时保持 0.10.0 的默认。
|
|
1164
|
+
*
|
|
1165
|
+
* @param {'github'|'gitee'|undefined} provider
|
|
1166
|
+
* @param {{github?: string, gitee?: string}} [labels]
|
|
1167
|
+
*/
|
|
1168
|
+
export function defaultAckLabelFor(provider, labels) {
|
|
1169
|
+
const map = labels && typeof labels === 'object' ? labels : null
|
|
1170
|
+
if (provider === 'gitee') return (map && map.gitee) || DEFAULT_ACK_LABEL_GITEE
|
|
1171
|
+
return (map && map.github) || DEFAULT_ACK_LABEL
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1135
1174
|
/**
|
|
1136
1175
|
* `watch_status` 的结构化视图:同一份数据,既能渲染成人读的文本,也能给 agent 解析。
|
|
1137
1176
|
*
|
|
@@ -1172,7 +1211,7 @@ export function statusView(entries, options = {}) {
|
|
|
1172
1211
|
sessionMaxWakes: w.sessionMaxWakes ?? 12,
|
|
1173
1212
|
isolateKeepDays: w.isolateKeepDays ?? 3,
|
|
1174
1213
|
maxIsolated: w.maxIsolated ?? 5,
|
|
1175
|
-
ackLabel: w.ackLabel ??
|
|
1214
|
+
ackLabel: w.ackLabel ?? defaultAckLabelFor(w.provider, options.defaultAckLabels),
|
|
1176
1215
|
workdir: w.workdir ?? null,
|
|
1177
1216
|
// 补齐缺省开关,同时保留面板写入的 stale 等扩展项;拷贝对象避免共享引用。
|
|
1178
1217
|
priority: { ...DEFAULT_PRIORITY, ...((w.priority && typeof w.priority === 'object' && !Array.isArray(w.priority)) ? w.priority : {}) },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-superagent",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.1",
|
|
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",
|
|
@@ -100,5 +100,8 @@
|
|
|
100
100
|
},
|
|
101
101
|
"devDependencies": {
|
|
102
102
|
"semver": "7.8.6"
|
|
103
|
+
},
|
|
104
|
+
"dependencies": {
|
|
105
|
+
"@deepseek-ai/schemastery": "3.18.5"
|
|
103
106
|
}
|
|
104
107
|
}
|