dsh-session-superagent 0.9.258 → 0.9.260

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,69 @@
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.260] - 2026-11-05 —— T40 入口对等收尾:同一件事,不再两套行为
6
+
7
+ ### 工具新建也会做「添加前体检」
8
+
9
+ `watch_start` 新建时与 HTTP 一样调用 `precheckRepo()`:仓库不存在、只读、归档等问题在创建时就警告,
10
+ 并把 `repoAccess` 写进状态。只警告、不阻止创建;编辑已有守不重复打网络。
11
+
12
+ 文本回执追加 `WARN <repo>:…`;JSON 在确有警告时增加 `warnings: string[]`,正常创建形状不变。
13
+
14
+ ### 隔离目录默认值两条路一致
15
+
16
+ `isolated: true` 且未给 `workdir` 时,工具与 HTTP 都明确兜底 `process.cwd()`,
17
+ 不再出现「面板创建不告警、工具创建被 doctor 警告」。
18
+
19
+ ### 工具与面板追溯共用一套模板
20
+
21
+ `formatTraceText()` 统一缩进、标点、冷却吸收与「最近一次唤醒」省略规则;
22
+ 独立验收还抓出无痕迹分支 HTTP 少一个前导空格,也已对齐。
23
+
24
+ ### 证据
25
+
26
+ ```
27
+ npm test → 423/423(新增 3 条独立验收:Gitee 假 fetch 真体检、隔离 cwd、正常/异常/无痕迹逐字一致)
28
+ ```
29
+
30
+ ## [0.9.259] - 2026-11-05 —— 工具不再只能「暂停」,优先级也不再只有面板能调
31
+
32
+ ### ① `watch_stop` 可以真正删除,但默认行为不变
33
+
34
+ 新增 `delete: true`:
35
+
36
+ ```js
37
+ watch_stop({ repo: 'owner/name', delete: true })
38
+ ```
39
+
40
+ - 默认仍然只暂停,文本与 JSON 返回形状完全不变;
41
+ - 显式删除时先清轮询 timer 与 `bootTimers`,再删状态并写 ISO 墓碑,防止迟到快照复活;
42
+ - 回执明确 `deleted:true`;Gitee 前缀同样支持;
43
+ - 显式 `watch_start` 可重建同一仓库,只解除该 id 的墓碑,不影响其他 session。
44
+
45
+ ### ② `watch_start` 支持五个优先级开关
46
+
47
+ `priority` 对象支持 `reopened / comments / labels / unassigned / stale`。
48
+ 只覆盖显式传入的布尔键,其他已有设置保留;**只改标签不会重置优先级**。
49
+
50
+ ### ③ doctor 不再写死 `/6`
51
+
52
+ 部分挂载失败按实际的 `routes / (routes + failed.length)` 报告;旧状态没有路由数时显示「未知」,
53
+ 不编造一个看似精确的分母。
54
+
55
+ ### ④ ack 标签从「隐藏配置」变成可见、可改
56
+
57
+ `/state` 回传真实 `ackLabel`(GitHub/Gitee 各自默认值正确)。
58
+ 面板列表显示作者白名单与回执标签,编辑器可修改「已处理标签」。
59
+
60
+ ### 证据
61
+
62
+ ```
63
+ npm test → 420/420(新增 12 条:删除/重建 4、priority 3、doctor/state 4、面板 ack 1)
64
+ node scripts/contract.mjs --update → 登记 watch_start.priority 与 watch_stop.delete
65
+ node scripts/measure-state.mjs → 20 条守 43.8 KB ≤ 50 KB
66
+ ```
67
+
5
68
  ## [0.9.258] - 2026-11-05 —— 新建能一次设好,模型也能看见自己写了什么
6
69
 
7
70
  继续收 T40「两个入口能力不对等」的尾项,并用**真实点击 + 请求体断言**验收,而不是只查字段出现在源码里。
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.258-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.9.260-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 # 408 项单测(带离线开关;裸 node --test 会真去 spawn gh,两分半)
149
+ npm test # 423 项单测(带离线开关;裸 node --test 会真去 spawn gh,两分半)
150
150
  ```
151
151
 
152
152
  ### 工具输出:文本给人和 agent,JSON 给程序
@@ -206,7 +206,7 @@ dsh plugin --profile <profile> add dsh-session-superagent@latest
206
206
 
207
207
 
208
208
  ```bash
209
- npm test # 408 项单测(带离线开关,约 1.6 秒)
209
+ npm test # 423 项单测(带离线开关,约 1.6 秒)
210
210
  node scripts/ui-audit.mjs # 11 项 UI 指标(写死颜色 / 自造 token / 官方结构采用 …)
211
211
  node scripts/preflight.mjs # 41 项门禁(含上面两条,外加 profile 一致性、路由面、包内容)
212
212
  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.258'
17
+ const CLIENT_VERSION = '0.9.260'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
@@ -629,6 +629,8 @@ window.__ModuleLoader__.load({
629
629
  if (f.labels && f.labels.length) parts.push('标签: ' + f.labels.join(','))
630
630
  if (f.ignoreLabels && f.ignoreLabels.length) parts.push('排除: ' + f.ignoreLabels.join(','))
631
631
  if (f.onlyAssigned) parts.push(f.assignee ? '只看指派给 @' + f.assignee : '只看已指派')
632
+ // 设了作者白名单就要能自查;只在编辑器里出现,列表上看不出「到底生效的是谁」。
633
+ if (f.allowAuthors && f.allowAuthors.length) parts.push('作者: ' + f.allowAuthors.join(','))
632
634
  return parts.join(' · ')
633
635
  }
634
636
 
@@ -1118,6 +1120,8 @@ window.__ModuleLoader__.load({
1118
1120
  },
1119
1121
  activeHours: draft.activeHours || '',
1120
1122
  goal: draft.goal || '',
1123
+ // 自定义 ack 标签是可写配置;未传时服务端保持原值。
1124
+ ackLabel: String(draft.ackLabel || '').trim() || undefined,
1121
1125
  isolated: !!draft.isolated,
1122
1126
  workdir: draft.workdir || '',
1123
1127
  observe: !!draft.observe,
@@ -1297,6 +1301,7 @@ window.__ModuleLoader__.load({
1297
1301
  // 审核 T26 M2:`watcher.goal` 是**对象**(goalView),当字符串塞进输入框会显示
1298
1302
  // [object Object];保存时后端只收 string,于是静默无效而 Toast 说「已保存」。
1299
1303
  goal: watcher.note || (typeof watcher.goal === 'string' ? watcher.goal : (watcher.goal && watcher.goal.objective) || ''),
1304
+ ackLabel: watcher.ackLabel || (watcher.provider === 'gitee' ? '主理鱼-已处理' : '主理鱼:已处理'),
1300
1305
  onlyAssigned: !!(watcher.filters && watcher.filters.onlyAssigned),
1301
1306
  allowAuthors: (watcher.filters && watcher.filters.allowAuthors ? watcher.filters.allowAuthors : []).join(', '),
1302
1307
  // 下面这些以前没填 —— 打开一条隔离执行的守再直接保存,会把 isolated 写回 false
@@ -1328,6 +1333,8 @@ window.__ModuleLoader__.load({
1328
1333
  watcher.activeHours ? h(Tag, null, '时段 ' + watcher.activeHours) : null,
1329
1334
  watcher.isolated ? h(Tag, null, isolationText(watcher)) : null,
1330
1335
  filterText(watcher.filters) ? h(Tag, null, filterText(watcher.filters)) : null,
1336
+ // ack 标签决定这条是否还会被叫醒,不能只在工具参数里出现。
1337
+ h(Tag, { tone: 'quiet' }, '回执 ' + (watcher.ackLabel || (watcher.provider === 'gitee' ? '主理鱼-已处理' : '主理鱼:已处理'))),
1331
1338
  backoffText(watcher) ? h(Tag, { tone: 'warning' }, backoffText(watcher)) : null),
1332
1339
  // 三行,各管一件事:① 是谁 ② 节律与最近结果 ③ 目标
1333
1340
  // 原来六段用 ' · ' 串成一行(会话 · 每 60s · 轮询 · 唤醒 · 上次唤醒 · 目标),
@@ -1407,6 +1414,7 @@ window.__ModuleLoader__.load({
1407
1414
  // 官方原型的 Policy 第一件事是「谁可以给你派活」。单人场景也要:别人随手提的 issue 不该叫醒你。
1408
1415
  field('只理这些人提的', h(Input, { value: draft.allowAuthors || '', placeholder: AUTHOR_LIST_PLACEHOLDER, onChange: (e) => setField({ ...draft, allowAuthors: e.target.value }) }), '不在名单里的人提的 issue/PR 不会叫醒你(Gitee 也可以填)'),
1409
1416
  field('目标/规则', h(Input, { value: draft.goal || '', placeholder: '可选,会附在唤醒消息里', onChange: (e) => setField({ ...draft, goal: e.target.value }) })),
1417
+ field('已处理标签', h(Input, { value: draft.ackLabel || '', placeholder: '主理鱼:已处理', onChange: (e) => setField({ ...draft, ackLabel: e.target.value }) }), 'watch_ack 会把同名标签打到 issue/PR 上;改名字等于换一套已处理标记'),
1410
1418
  h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: !!draft.onlyAssigned, onChange: (v) => setField({ ...draft, onlyAssigned: v }), label: '只看已指派' }), '只处理已指派给人的条目'),
1411
1419
  draft.onlyAssigned ? field('只看指派给谁', h(Input, { value: draft.assignee || '', placeholder: 'GitHub 登录名,留空 = 只要有指派就行', onChange: (e) => setField({ ...draft, assignee: e.target.value }) })) : null,
1412
1420
  field('单次最多唤醒条数', h(Input, { value: draft.batchLimit || '', placeholder: String(DEFAULTS.batchLimit || 5) + '(1-20)', onChange: (e) => setField({ ...draft, batchLimit: e.target.value }) })),
package/lib/index.js CHANGED
@@ -26,7 +26,7 @@ import { decodeBody, truncateUtf8 } from './body.js'
26
26
  import { quotaDeferText, isOfflineMode } from './gh-format.js'
27
27
  import { listGiteeItems, fetchGiteeLastComment, addGiteeLabel, ensureGiteeLabel, giteeWhoami, giteeRepo, mapGiteeRepoAccess, DEFAULT_ACK_LABEL_GITEE, giteeLabels, giteeHasLabel, isValidGiteeLabel, suggestGiteeLabel } from './gitee.js'
28
28
  import {
29
- effectiveIntervalMs, planWakeSettlement, advanceSeen, applyWatcherAction, batchFresh, decideWake, DEFAULT_ACK_LABEL, formatWatchText,
29
+ effectiveIntervalMs, planWakeSettlement, advanceSeen, applyWatcherAction, batchFresh, decideWake, DEFAULT_ACK_LABEL, DEFAULT_PRIORITY, formatWatchText,
30
30
  recordPendingWake, clearPending, pendingRetry,
31
31
  wakeQuality,
32
32
  parseRepoSpec, markGiteeReopened,
@@ -46,7 +46,7 @@ import {
46
46
 
47
47
  export const name = 'dsh-session-superagent'
48
48
  /** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
49
- export const SERVER_VERSION = '0.9.258'
49
+ export const SERVER_VERSION = '0.9.260'
50
50
  export const inject = ['tools', 'agents', 'webServer']
51
51
  /** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
52
52
  // 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
@@ -63,6 +63,27 @@ const UNCHANGED_TEXT_GITEE = '未变化(Gitee 无 ETag:这一轮是真空读
63
63
  // 追溯找不到任何痕迹时的那句话:两个入口(工具 / HTTP)必须一模一样
64
64
  const noTraceText = (number, scope) => '#' + number + ' 在' + (scope || '所有守') + ' 里都没有痕迹 —— 可能还没被轮询到,或者编号写错了。'
65
65
 
66
+ /** 工具与面板共用同一份追溯文本,别再各写一套缩进、标点和省略规则。 */
67
+ const formatTraceText = (traces) => {
68
+ const lines = []
69
+ for (const trace of traces || []) {
70
+ lines.push('#' + trace.number + ' @ ' + (trace.repo || '?') + ':' + trace.verdict)
71
+ // 例外优先:一切正常时一行说完,只有「被过滤/被吸收/唤醒失败」才展开细节。
72
+ const quiet = trace.filtered.length === 0 && (trace.absorbed || []).length === 0
73
+ && trace.wakes.length > 0 && trace.wakes.every((item) => item.ok)
74
+ if (!quiet) {
75
+ if (trace.seen) lines.push(' 水位 seen:' + trace.seen)
76
+ if (trace.reported) lines.push(' 上次上报:' + trace.reported)
77
+ for (const item of trace.filtered) lines.push(' 被过滤(' + (item.reason || '未知') + '):' + item.at)
78
+ for (const item of trace.absorbed || []) lines.push(' 被冷却期吸收:' + item.at)
79
+ for (const item of trace.wakes) lines.push(' 唤醒尝试:' + item.at + ' ' + (item.ok ? '成功' : '失败(' + (item.reason || '未知') + ')'))
80
+ } else if (trace.wakes.length > 0) {
81
+ lines.push(' 最近一次唤醒:' + trace.wakes[trace.wakes.length - 1].at + '(成功)')
82
+ }
83
+ }
84
+ return lines.join(String.fromCharCode(10))
85
+ }
86
+
66
87
  const DEFAULT_SESSION_WAKES = 12
67
88
  /** 单次唤醒最多铺开几条(面板的占位符要显示这个真值,不能写死)。 */
68
89
  const DEFAULT_BATCH_LIMIT = 5
@@ -70,6 +91,8 @@ const DEFAULT_BATCH_LIMIT = 5
70
91
  // 出处:https://json-schema.org/understanding-json-schema/reference/annotations
71
92
  const DEFAULT_WAKES_PER_HOUR = 6
72
93
  const DEFAULT_ISOLATE_KEEP_DAYS = 3
94
+ // watch.js 的 DEFAULT_PRIORITY 是排序规则的事实源;stale 是后加的扩展键,默认同样关闭。
95
+ const DEFAULT_TOOL_PRIORITY = Object.freeze({ ...DEFAULT_PRIORITY, stale: false })
73
96
  // 一条会话最多挂多少守:再多轮询压力与上下文都会失控(20 条 × 每 60 秒已很密)
74
97
  const MAX_WATCHERS_PER_SESSION = 20
75
98
 
@@ -243,7 +266,7 @@ function mergeWatermark(diskEntry, memEntry) {
243
266
  return out
244
267
  }
245
268
 
246
- function writeState(state) {
269
+ function writeState(state, options = {}) {
247
270
  try {
248
271
  mkdirSync(stateDir(), { recursive: true })
249
272
  // 合并写:调用方手里的 state 可能是很久以前读的快照(宿主重载、两个实例交替写),
@@ -251,6 +274,9 @@ function writeState(state) {
251
274
  // 规则:盘上有、内存里没有的条目一律保留;只有墓碑里的 id 才允许消失。
252
275
  const disk = readState()
253
276
  const tombstones = { ...(disk.deleted || {}), ...(state.deleted || {}) }
277
+ // 只有显式的 watch_start 才能解除墓碑(用户要求重建同 id 的守)。
278
+ // 普通旧快照写入没有这个选项,仍然不能绕过墓碑把已删守复活。
279
+ for (const id of (Array.isArray(options.revive) ? options.revive : [])) delete tombstones[id]
254
280
  const merged = { ...disk, ...state }
255
281
  merged.watchers = { ...(disk.watchers || {}) }
256
282
  for (const [id, watcher] of Object.entries(state.watchers || {})) {
@@ -1754,6 +1780,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
1754
1780
  repo: w.repo,
1755
1781
  // 面板要能一眼分出 GitHub / Gitee:否则行内只能靠 id 前缀猜
1756
1782
  provider: w.provider === 'gitee' ? 'gitee' : 'github',
1783
+ ackLabel: w.ackLabel || defaultAckLabel(w.provider),
1757
1784
  sessionId: w.sessionId,
1758
1785
  intervalSec: w.intervalSec,
1759
1786
  enabled: isEnabled(w),
@@ -2205,21 +2232,11 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2205
2232
  const number = url.searchParams.get('number') || ''
2206
2233
  const state = readState()
2207
2234
  const list = Object.values(state.watchers || {}).filter((entry) => !repo || entry.repo === repo)
2208
- const lines = []
2209
- for (const entry of list) {
2210
- const trace = itemTrace(entry, number)
2211
- if (!trace) continue
2212
- const touched = Boolean(trace.seen || trace.reported || trace.filtered.length || trace.wakes.length)
2213
- if (!touched) continue
2214
- lines.push('#' + trace.number + ' @ ' + (trace.repo || '?') + ':' + trace.verdict)
2215
- if (trace.seen) lines.push('水位 ' + trace.seen)
2216
- if (trace.reported) lines.push('上次上报 ' + trace.reported)
2217
- for (const item of trace.filtered) lines.push('被过滤(' + (item.reason || '未知') + ')' + item.at)
2218
- for (const item of trace.wakes) lines.push('唤醒尝试 ' + item.at + ' ' + (item.ok ? '成功' : '失败(' + (item.reason || '未知') + ')'))
2219
- }
2220
- const text = lines.length > 0
2221
- ? lines.join(String.fromCharCode(10))
2222
- : noTraceText(number, repo || '所有守')
2235
+ const traces = list.map((entry) => itemTrace(entry, number)).filter((trace) => trace
2236
+ && Boolean(trace.seen || trace.reported || trace.filtered.length || trace.wakes.length))
2237
+ const text = traces.length > 0
2238
+ ? formatTraceText(traces)
2239
+ : noTraceText(number, repo ? ' ' + repo : '所有守')
2223
2240
  json(res, 200, { ok: true, text })
2224
2241
  },
2225
2242
  })
@@ -2505,41 +2522,15 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2505
2522
  return toolError(args, why)
2506
2523
  }
2507
2524
  const number = rawNumber
2508
- const lines = []
2509
- for (const entry of list) {
2510
- const trace = itemTrace(entry, number)
2511
- if (!trace) continue
2512
- const touched = Boolean(trace.seen || trace.reported || trace.filtered.length || trace.wakes.length)
2513
- if (!touched) continue
2514
- lines.push('#' + trace.number + ' @ ' + (trace.repo || '?') + ':' + trace.verdict)
2515
- // 例外优先:一切正常时一行说完,只有「被过滤/被吸收/唤醒失败」才展开细节
2516
- const quiet = trace.filtered.length === 0 && (trace.absorbed || []).length === 0
2517
- && trace.wakes.length > 0 && trace.wakes.every((item) => item.ok)
2518
- if (!quiet) {
2519
- if (trace.seen) lines.push(' 水位 seen:' + trace.seen)
2520
- if (trace.reported) lines.push(' 上次上报:' + trace.reported)
2521
- for (const item of trace.filtered) lines.push(' 被过滤(' + item.reason + '):' + item.at)
2522
- for (const item of trace.absorbed || []) lines.push(' 被冷却期吸收:' + item.at)
2523
- for (const item of trace.wakes) lines.push(' 唤醒尝试:' + item.at + ' ' + (item.ok ? '成功' : '失败(' + (item.reason || '未知') + ')'))
2524
- } else if (trace.wakes.length > 0) {
2525
- lines.push(' 最近一次唤醒:' + trace.wakes[trace.wakes.length - 1].at + '(成功)')
2526
- }
2527
- }
2525
+ const traces = list.map((entry) => itemTrace(entry, number)).filter((trace) => trace
2526
+ && Boolean(trace.seen || trace.reported || trace.filtered.length || trace.wakes.length))
2528
2527
  if (args && args.format === 'json') {
2529
- const results = []
2530
- for (const entry of list) {
2531
- const trace = itemTrace(entry, number)
2532
- if (!trace) continue
2533
- const touched = Boolean(trace.seen || trace.reported || trace.filtered.length || trace.wakes.length)
2534
- if (!touched) continue
2535
- results.push(trace)
2536
- }
2537
- return JSON.stringify({ schemaVersion: 1, number: String(number), results }, null, 2)
2528
+ return JSON.stringify({ schemaVersion: 1, number: String(number), results: traces }, null, 2)
2538
2529
  }
2539
- if (lines.length === 0) {
2530
+ if (traces.length === 0) {
2540
2531
  return noTraceText(number, wanted ? ' ' + wanted : '所有守')
2541
2532
  }
2542
- return lines.join(String.fromCharCode(10))
2533
+ return formatTraceText(traces)
2543
2534
  },
2544
2535
  }))
2545
2536
 
@@ -2582,12 +2573,21 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2582
2573
  // 0. 挂载状态:面板/HTTP 靠路由,路由注册失败时工具仍然可用 —— 这种「半死」状态
2583
2574
  // 光看工具是发现不了的(2026-11-02 真机踩过:duplicate exact route 让六条接口全灭)
2584
2575
  if (state.server) {
2585
- const mounted = Number(state.server.routes) || 0
2576
+ const routeCount = Number(state.server.routes)
2577
+ const hasRouteCount = state.server.routes !== undefined && state.server.routes !== null && state.server.routes !== ''
2578
+ && Number.isInteger(routeCount) && routeCount >= 0
2579
+ const mounted = hasRouteCount ? routeCount : null
2586
2580
  const failed = Array.isArray(state.server.failed) ? state.server.failed : []
2587
2581
  if (state.server.error) {
2588
2582
  lines.push(`FAIL 面板接口挂载:${state.server.error}(工具仍可用,但面板会空白;重载一次即可)`)
2589
2583
  } else if (failed.length > 0) {
2590
- lines.push(`WARN 面板接口部分失败(${mounted}/6 成功):${failed.join(';')}`)
2584
+ // routes 是成功的 disposer 数,failed 是实际注册失败数;总数来自这次挂载,不写死。
2585
+ const total = mounted === null ? null : mounted + failed.length
2586
+ lines.push(total === null
2587
+ ? `WARN 面板接口部分失败(成功/总数未知):${failed.join(';')}`
2588
+ : `WARN 面板接口部分失败(${mounted}/${total} 成功):${failed.join(';')}`)
2589
+ } else if (mounted === null) {
2590
+ lines.push('WARN 面板接口挂载:路由数未知(旧版本没有记录 routes)')
2591
2591
  } else {
2592
2592
  lines.push(`OK 面板接口挂载:${mounted} 条,无失败`)
2593
2593
  }
@@ -2801,6 +2801,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2801
2801
  maxIsolated: { type: 'number', description: 'With isolated: keep at most this many worktrees, oldest removed first (1-50, default 5).' },
2802
2802
  goal: { type: 'string', description: 'Optional per-watcher goal appended to the wake message.' },
2803
2803
  ackLabel: { type: 'string', description: 'Label used as the handled marker (default 主理鱼:已处理). Two sessions watching the same repo share it unless each sets its own.' },
2804
+ 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.' },
2804
2805
  },
2805
2806
  async execute(args) {
2806
2807
  const toolAgents = agentsService(ctx)
@@ -2826,7 +2827,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2826
2827
  }
2827
2828
  if (parsedSpecs.length === 0) return toolError(args, '至少给一个仓库(owner/name)')
2828
2829
  const repoList = parsedSpecs.map(({ item, spec }) => ({ repo: spec.repo, provider: spec.provider, label: item }))
2829
- const applyOne = ({ repo, provider }) => {
2830
+ const applyOne = async ({ repo, provider }) => {
2830
2831
  const id = (provider === 'gitee' ? 'gitee:' : '') + `${repo}#${sessionId}`
2831
2832
  const state = readState()
2832
2833
  const existing = state.watchers && state.watchers[id]
@@ -2835,6 +2836,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2835
2836
  intervalSec: 60,
2836
2837
  cooldownMs: DEFAULT_COOLDOWN_MS,
2837
2838
  ackLabel: defaultAckLabel(provider),
2839
+ priority: { ...DEFAULT_TOOL_PRIORITY },
2838
2840
  cursor: null,
2839
2841
  seen: {},
2840
2842
  lastReported: {},
@@ -2856,6 +2858,9 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2856
2858
  if (typeof args.goal === 'string') entry.goal = args.goal.slice(0, 500)
2857
2859
  if (typeof args.observe === 'boolean') entry.observe = args.observe
2858
2860
  if (typeof args.isolated === 'boolean') entry.isolated = args.isolated
2861
+ // 与 HTTP 创建路径同口径:隔离开着但没给目录,就明确兜底到宿主 cwd。
2862
+ // 否则面板创建不告警、工具创建却被 doctor 警告,同一个配置两种结果。
2863
+ if (entry.isolated && !entry.workdir) entry.workdir = process.cwd()
2859
2864
  if (typeof args.workdir === 'string' && args.workdir.trim()) {
2860
2865
  const workdir = args.workdir.trim()
2861
2866
  if (!isAbsolute(workdir)) return toolError(args, 'workdir must be an absolute path')
@@ -2876,6 +2881,15 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2876
2881
  if (typeof args.isolateKeepDays === 'number') entry.isolateKeepDays = Math.max(1, Math.min(30, Math.round(args.isolateKeepDays)))
2877
2882
  if (typeof args.maxIsolated === 'number') entry.maxIsolated = Math.max(1, Math.min(50, Math.round(args.maxIsolated)))
2878
2883
  if (typeof args.ackLabel === 'string' && args.ackLabel.trim()) entry.ackLabel = args.ackLabel.trim().slice(0, 60)
2884
+ // 工具入口与面板一样可以调五个优先级键,但部分更新不能把已有开关重置。
2885
+ if (args.priority && typeof args.priority === 'object' && !Array.isArray(args.priority)) {
2886
+ const current = entry.priority && typeof entry.priority === 'object' && !Array.isArray(entry.priority) ? entry.priority : {}
2887
+ const next = { ...DEFAULT_TOOL_PRIORITY, ...current }
2888
+ for (const key of ['reopened', 'comments', 'labels', 'unassigned', 'stale']) {
2889
+ if (Object.hasOwn(args.priority, key) && typeof args.priority[key] === 'boolean') next[key] = args.priority[key]
2890
+ }
2891
+ entry.priority = next
2892
+ }
2879
2893
  // 审核 T40 W12:`watch_start` 的语义是「开始看」,但**静默恢复**一条暂停的守是意外行为。
2880
2894
  // 保留恢复语义(幂等),但两件事必须做到:
2881
2895
  // ① 如果调用方显式传了 resume:false,就保持原暂停状态(只改配置);
@@ -2893,8 +2907,17 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2893
2907
  return '一条会话最多同时挂 ' + MAX_WATCHERS_PER_SESSION + ' 条在跑的守(现在 ' + mine.length + ' 条)—— 先 watch_stop 停掉不用的,或把多个仓库合成一条规则'
2894
2908
  }
2895
2909
  }
2910
+ // 与 HTTP 创建路径同口径:**新建**才做添加前体检,编辑不重复打网络。
2911
+ // 只警告不阻止:仓库不存在/只读/归档要在创建时就说,而不是等下一次轮询。
2912
+ let warnings = []
2913
+ if (!existing) {
2914
+ const pre = await precheckRepo(repo, provider)
2915
+ warnings = pre.warnings || []
2916
+ if (pre.access) entry.repoAccess = pre.access
2917
+ }
2896
2918
  state.watchers[id] = entry
2897
- writeState(state)
2919
+ // 显式 start 同 repo/session 表示要重建;只解除这个 id 的墓碑,不影响其他已删守。
2920
+ writeState(state, { revive: [id] })
2898
2921
  stopWatcher(id)
2899
2922
  startWatcher(entry)
2900
2923
  const flags = []
@@ -2909,7 +2932,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2909
2932
  if (entry.batchLimit) flags.push('batch=' + entry.batchLimit)
2910
2933
  if (entry.maxWakesPerHour) flags.push('perHour=' + entry.maxWakesPerHour)
2911
2934
  if (entry.goal) flags.push('goal=' + JSON.stringify(entry.goal.slice(0, 40)))
2912
- return { entry, existing, flags, id, repo }
2935
+ return { entry, existing, flags, id, repo, warnings }
2913
2936
 
2914
2937
  }
2915
2938
  // 批量要整批校验:19 条时一次加 2 条,不能只加进去第一条
@@ -2927,22 +2950,29 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2927
2950
  }
2928
2951
  const applied = []
2929
2952
  for (const item of repoList) {
2930
- const result = applyOne(item)
2953
+ const result = await applyOne(item)
2931
2954
  // 单条校验失败(比如相对路径的 workdir)要原地返回,不能继续加后面的
2932
2955
  if (typeof result === 'string') return result
2933
2956
  applied.push(result)
2934
2957
  }
2958
+ // 与 HTTP 创建回执同形状:warnings 是字符串数组;仓库归属在 repos[] 与文本行里表达。
2959
+ const warnings = applied.flatMap((item) => item.warnings || [])
2935
2960
  if (args && args.format === 'json') {
2936
2961
  const first = applied[0]
2937
2962
  const base = JSON.parse(JSON.stringify({ schemaVersion: 1, ok: true, repo: first.repo, sessionId, id: first.id, intervalSec: first.entry.intervalSec,
2938
2963
  flags: first.flags, filters: first.entry.filters || {}, updated: Boolean(first.existing), observe: first.entry.observe === true,
2939
2964
  isolated: first.entry.isolated === true, activeHours: first.entry.activeHours || null }))
2940
- base.repos = applied.map((item) => ({ repo: item.repo, id: item.id, updated: Boolean(item.existing) }))
2965
+ base.repos = applied.map((item) => ({ repo: item.repo, id: item.id, updated: Boolean(item.existing), ...(item.warnings.length ? { warnings: item.warnings } : {}) }))
2966
+ // 只在确有警告时增加字段,保持正常创建的 JSON 形状不变。
2967
+ if (warnings.length) base.warnings = warnings
2941
2968
  return JSON.stringify(base, null, 2)
2942
2969
  }
2943
2970
  const lines = applied.map((item) => `watching ${item.repo} → session ${sessionId} every ${item.entry.intervalSec}s`
2944
2971
  + (item.flags.length ? ' [' + item.flags.join(' ') + ']' : '')
2945
2972
  + (item.existing ? ' (updated existing watcher)' : ''))
2973
+ for (const item of applied) {
2974
+ for (const warning of item.warnings || []) lines.push('WARN ' + item.repo + ':' + warning)
2975
+ }
2946
2976
  return lines.join(String.fromCharCode(10))
2947
2977
  },
2948
2978
  }))
@@ -3008,9 +3038,10 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
3008
3038
 
3009
3039
  ctx.tools.register(defineTool({
3010
3040
  name: 'watch_stop',
3011
- description: 'Stop watching a repository for the current session.',
3041
+ description: 'Stop watching a repository for the current session. By default this pauses it and keeps its state; pass delete:true to remove it and leave a tombstone.',
3012
3042
  parameters: {
3013
3043
  repo: { type: 'string', required: true, description: 'owner/name' },
3044
+ delete: { type: 'boolean', description: 'Delete the watcher and persist a tombstone instead of only pausing it (default false).' },
3014
3045
  format: { type: 'string', description: "'text' (default) or 'json'." },
3015
3046
  },
3016
3047
  async execute(args) {
@@ -3032,13 +3063,19 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
3032
3063
  const message = 'no watcher for ' + rawRepo + '(试过 ' + candidates.join(' / ') + ')'
3033
3064
  return (args && args.format === 'json') ? JSON.stringify({ schemaVersion: 1, ok: false, id, error: message }) : '[error: ' + message + ']'
3034
3065
  }
3066
+ // 审核 T36 W2:`stopWatcher()` 同时清 timers 与 bootTimers;删除时必须先停再抹状态,
3067
+ // 否则正在收尾的 tick 可能把刚删的守写回来。
3068
+ stopWatcher(id)
3069
+ if (args.delete === true) {
3070
+ delete state.watchers[id]
3071
+ state.deleted = { ...(state.deleted || {}), [id]: new Date().toISOString() }
3072
+ writeState(state)
3073
+ if (args && args.format === 'json') return JSON.stringify({ schemaVersion: 1, ok: true, id, repo: args.repo, deleted: true })
3074
+ return `deleted ${id}(deleted:true)`
3075
+ }
3035
3076
  state.watchers[id].enabled = false
3036
3077
  writeState(state)
3037
- // 审核 T36 W2:以前这里只清 `timers`,漏了 `bootTimers` ——
3038
- // 刚建好还没开始轮询的守(首轮错峰等待中)被暂停后,那个 `setTimeout` 仍会 fire,
3039
- // 于是**已经停掉的守还会再 tick 一次**(含 gh 请求、可能建 worktree)。
3040
- // `stopWatcher()` 两者都清,直接用它。
3041
- stopWatcher(id)
3078
+ // 默认 JSON / 文本保持旧形状:只是暂停,不新增 deleted/stopped 字段。
3042
3079
  if (args && args.format === 'json') return JSON.stringify({ schemaVersion: 1, ok: true, id, repo: args.repo })
3043
3080
  return `stopped ${id}`
3044
3081
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.9.258",
3
+ "version": "0.9.260",
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",