dsh-session-superagent 0.9.259 → 0.9.261

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,77 @@
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.261] - 2026-11-05 —— 完整解构官方结构树,并落地 Delivery + Outbox
6
+
7
+ ### 完整解构,不只列功能清单
8
+
9
+ 新增 `docs/official-decomp/` 五篇文档(约 1900 行):
10
+
11
+ - `01-structure-tree.md`:完整目录树、分层图、吸收取舍与落地状态;
12
+ - `02-runtime-execution.md`:61 个运行时文件、Trigger→Eval→Ticket→Executor 全链;
13
+ - `03-sources.md`:26 个来源文件、GitHub/Feishu 数据流、读位与幂等;
14
+ - `04-panel-tree.md`:6 Tab、Thread/Ticket 详情、设置分区与全部二三级页面;
15
+ - `05-prompts-skills-operations.md`:提示词、skills、SETUP、迁移、i18n 与测试组织。
16
+
17
+ 所有关键结论锚定官方提交 `8c32a9d` 的文件与行号;不吸收的团队级复杂度也写明理由。
18
+
19
+ ### 吸收 ①:Delivery —— 处理结论可以回写原条目
20
+
21
+ `watch_ack` 新增 `comment: true`:把同一个 `note` 评论到原 issue/PR,而不是只存在本地。
22
+
23
+ ```js
24
+ watch_ack({ number: 7, note: '已修,见 #57', comment: true })
25
+ ```
26
+
27
+ - 默认仍只打标签,不自动发评论;
28
+ - Gitee 通过 `kind: 'issue' | 'pull'` 选择正确端点;
29
+ - `comment:true` 缺 `note` 时,在**任何外部写操作之前**拒绝;
30
+ - 评论失败会明确区分 `phase:'comment'`,不会把「标签已打」误报成完整成功。
31
+
32
+ ### 吸收 ②:Outbox FIFO —— 会话忙时排队,空闲按顺序送
33
+
34
+ 以前忙时只保留水位、下轮重算:不丢事件,但没有真正的队列。
35
+ 现在同一会话的唤醒进入 FIFO:
36
+
37
+ - 忙时入队,回调仍 `ok:false`,**不计次数、不推进水位**;
38
+ - 空闲后按顺序 `followup`,真正发送成功才结算;
39
+ - 相同 `queueKey` 去重,不重复排队;
40
+ - 插件实例隔离,热重载不会误送旧实例消息;
41
+ - 队列在内存中,重启后由未推进的水位重建;
42
+ - 面板行内显示「排队 N」。
43
+
44
+ ### 证据
45
+
46
+ ```
47
+ npm test → 429/429(新增:Delivery 3 + FIFO 3;旧 wake-accounting 也全过)
48
+ test/entry-parity-final.test.mjs → 3/3(上一轮 W9-W11 仍全绿)
49
+ ```
50
+
51
+ ## [0.9.260] - 2026-11-05 —— T40 入口对等收尾:同一件事,不再两套行为
52
+
53
+ ### 工具新建也会做「添加前体检」
54
+
55
+ `watch_start` 新建时与 HTTP 一样调用 `precheckRepo()`:仓库不存在、只读、归档等问题在创建时就警告,
56
+ 并把 `repoAccess` 写进状态。只警告、不阻止创建;编辑已有守不重复打网络。
57
+
58
+ 文本回执追加 `WARN <repo>:…`;JSON 在确有警告时增加 `warnings: string[]`,正常创建形状不变。
59
+
60
+ ### 隔离目录默认值两条路一致
61
+
62
+ `isolated: true` 且未给 `workdir` 时,工具与 HTTP 都明确兜底 `process.cwd()`,
63
+ 不再出现「面板创建不告警、工具创建被 doctor 警告」。
64
+
65
+ ### 工具与面板追溯共用一套模板
66
+
67
+ `formatTraceText()` 统一缩进、标点、冷却吸收与「最近一次唤醒」省略规则;
68
+ 独立验收还抓出无痕迹分支 HTTP 少一个前导空格,也已对齐。
69
+
70
+ ### 证据
71
+
72
+ ```
73
+ npm test → 423/423(新增 3 条独立验收:Gitee 假 fetch 真体检、隔离 cwd、正常/异常/无痕迹逐字一致)
74
+ ```
75
+
5
76
  ## [0.9.259] - 2026-11-05 —— 工具不再只能「暂停」,优先级也不再只有面板能调
6
77
 
7
78
  ### ① `watch_stop` 可以真正删除,但默认行为不变
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.259-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.9.261-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 # 420 项单测(带离线开关;裸 node --test 会真去 spawn gh,两分半)
149
+ npm test # 429 项单测(带离线开关;裸 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 # 420 项单测(带离线开关,约 1.6 秒)
209
+ npm test # 429 项单测(带离线开关,约 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.259'
17
+ const CLIENT_VERSION = '0.9.261'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
@@ -1335,6 +1335,7 @@ window.__ModuleLoader__.load({
1335
1335
  filterText(watcher.filters) ? h(Tag, null, filterText(watcher.filters)) : null,
1336
1336
  // ack 标签决定这条是否还会被叫醒,不能只在工具参数里出现。
1337
1337
  h(Tag, { tone: 'quiet' }, '回执 ' + (watcher.ackLabel || (watcher.provider === 'gitee' ? '主理鱼-已处理' : '主理鱼:已处理'))),
1338
+ watcher.queuedWakes > 0 ? h(Tag, { tone: 'warning' }, '排队 ' + watcher.queuedWakes) : null,
1338
1339
  backoffText(watcher) ? h(Tag, { tone: 'warning' }, backoffText(watcher)) : null),
1339
1340
  // 三行,各管一件事:① 是谁 ② 节律与最近结果 ③ 目标
1340
1341
  // 原来六段用 ' · ' 串成一行(会话 · 每 60s · 轮询 · 唤醒 · 上次唤醒 · 目标),
package/docs/README.md CHANGED
@@ -11,6 +11,7 @@
11
11
  | [awesome-submission](awesome-submission.md) | 要提交到 awesome-dsh-plugin:现成的 YAML、图标、核对结论 |
12
12
  | [为什么做这个产品](为什么做这个产品.md) | **动任何功能之前先读**:谁在痛、三条不变量(不打断 / 不留手尾 / 不失控)、明确不做什么 |
13
13
  | [对比-官方原型](对比-官方原型.md) | 想知道和官方 `dsh-superagent-prototype` 的功能差距、哪些该抄哪些不该 |
14
+ | [official-decomp/](official-decomp/01-structure-tree.md) | **完整官方结构树**:运行时/事件源/面板/提示词运维逐文件解构,以及已落地与待吸收清单 |
14
15
  | [competitive-analysis](competitive-analysis.md) | 想知道和 Sweep / CodeRabbit 这类工具的差别 |
15
16
  | [deepseek-papers](deepseek-papers.md) | 想知道设计取舍背后的研究依据 |
16
17
  | [真机验证清单](真机验证清单.md) | 重启后三条命令 + 三个动作,5 分钟确认新代码在跑 |
package/lib/gitee.js CHANGED
@@ -163,6 +163,12 @@ export async function addGiteeLabel({ repo, token = '', number, label, fetchImpl
163
163
  return request(`/repos/${repo}/issues/${number}/labels`, { token, method: 'POST', body: { labels: [label] }, fetchImpl })
164
164
  }
165
165
 
166
+ /** 回写处理结论(ack 的可选 Delivery)。PR 与 issue 的端点不同,调用方必须给 kind。 */
167
+ export async function addGiteeComment({ repo, token = '', number, body, kind = 'issue', fetchImpl } = {}) {
168
+ const segment = kind === 'pull' ? 'pulls' : 'issues'
169
+ return request(`/repos/${repo}/${segment}/${number}/comments`, { token, method: 'POST', body: { body: String(body || '') }, fetchImpl })
170
+ }
171
+
166
172
  /** 当前 token 是谁(doctor 用)。 */
167
173
  export async function giteeWhoami({ token = '', fetchImpl } = {}) {
168
174
  return request('/user', { token, fetchImpl })
package/lib/index.js CHANGED
@@ -24,7 +24,7 @@ import { zstdDecompressSync } from 'node:zlib'
24
24
  import { redact } from './redact.js'
25
25
  import { decodeBody, truncateUtf8 } from './body.js'
26
26
  import { quotaDeferText, isOfflineMode } from './gh-format.js'
27
- import { listGiteeItems, fetchGiteeLastComment, addGiteeLabel, ensureGiteeLabel, giteeWhoami, giteeRepo, mapGiteeRepoAccess, DEFAULT_ACK_LABEL_GITEE, giteeLabels, giteeHasLabel, isValidGiteeLabel, suggestGiteeLabel } from './gitee.js'
27
+ import { listGiteeItems, fetchGiteeLastComment, addGiteeLabel, addGiteeComment, ensureGiteeLabel, giteeWhoami, giteeRepo, mapGiteeRepoAccess, DEFAULT_ACK_LABEL_GITEE, giteeLabels, giteeHasLabel, isValidGiteeLabel, suggestGiteeLabel } from './gitee.js'
28
28
  import {
29
29
  effectiveIntervalMs, planWakeSettlement, advanceSeen, applyWatcherAction, batchFresh, decideWake, DEFAULT_ACK_LABEL, DEFAULT_PRIORITY, formatWatchText,
30
30
  recordPendingWake, clearPending, pendingRetry,
@@ -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.259'
49
+ export const SERVER_VERSION = '0.9.261'
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
@@ -90,7 +111,7 @@ const MAX_WATCHERS_TOTAL = 200
90
111
  const CLEANUP_INTERVAL_MS = 10 * 60 * 1000
91
112
 
92
113
  /** 仅供测试:读写状态文件(生产代码不要用)。 */
93
- export const __test = { readState, writeState, hardenSecretsFile, wakeMerged, setAuthStatusCache: (text) => { authStatusCache = { at: text ? Date.now() : 0, text } } }
114
+ export const __test = { readState, writeState, hardenSecretsFile, wakeMerged, flushWakeQueue, wakeQueueCount, clearWakeQueues, setAuthStatusCache: (text) => { authStatusCache = { at: text ? Date.now() : 0, text } } }
94
115
 
95
116
  // 审核 T30:这四个路径以前在**模块加载那一刻**定死 ——
96
117
  // 测试里改 `process.env.DSH_SUPERAGENT_STATE` 之后,已经加载的实例仍然指着老目录,
@@ -736,7 +757,81 @@ function defineTool(options) {
736
757
  const WAKE_WINDOW_MS = Number(process.env.DSH_SUPERAGENT_WAKE_WINDOW_MS) || 3000
737
758
  const wakeBuffers = new Map()
738
759
 
739
- function wakeMerged(ctx, sessionId, text, onSettled) {
760
+ // 会话级 FIFO Outbox:忙时排队,空闲按顺序送。
761
+ // 只存内存;**未送达不推进水位**,所以宿主重启后下一轮会按原事件重建队列,不会丢。
762
+ const WAKE_QUEUE_RETRY_MS = Number(process.env.DSH_SUPERAGENT_WAKE_QUEUE_RETRY_MS) || 5000
763
+ const wakeQueues = new Map()
764
+ const isBusyWakeResult = (result) => /agent busy|会话正忙/i.test(String(result && result.reason || ''))
765
+
766
+ function wakeQueueCount(sessionId, ctx) {
767
+ const queue = wakeQueues.get(sessionId)
768
+ if (ctx && queue && queue.ctx !== ctx) return 0
769
+ return queue ? queue.items.length : 0
770
+ }
771
+
772
+ function scheduleWakeFlush(ctx, sessionId, delay = WAKE_QUEUE_RETRY_MS) {
773
+ const queue = wakeQueues.get(sessionId)
774
+ if (!queue || queue.timer || queue.items.length === 0) return
775
+ queue.timer = setTimeout(() => {
776
+ queue.timer = null
777
+ flushWakeQueue(ctx, sessionId)
778
+ }, delay)
779
+ if (queue.timer && typeof queue.timer.unref === 'function') queue.timer.unref()
780
+ }
781
+
782
+ function flushWakeQueue(ctx, sessionId) {
783
+ const queue = wakeQueues.get(sessionId)
784
+ if (!queue || queue.items.length === 0 || (queue.ctx && queue.ctx !== ctx)) return
785
+ const item = queue.items[0]
786
+ const result = wake(ctx, sessionId, item.text)
787
+ if (isBusyWakeResult(result)) {
788
+ scheduleWakeFlush(ctx, sessionId)
789
+ return
790
+ }
791
+ // 只有离开队首的这一条才结算:成功记已送达;非 busy 失败交给原有错误/重试逻辑。
792
+ queue.items.shift()
793
+ for (const cb of item.settled) {
794
+ try { cb(result) } catch { /* 单个 watcher 的结算失败不能堵住后面的队列 */ }
795
+ }
796
+ if (queue.items.length > 0) scheduleWakeFlush(ctx, sessionId, 0)
797
+ else wakeQueues.delete(sessionId)
798
+ }
799
+
800
+ function enqueueWake(ctx, sessionId, text, settled, key) {
801
+ let queue = wakeQueues.get(sessionId)
802
+ // 热重载后的新实例不能接管旧实例的回调与上下文;未送达水位未推进,旧事件会由新轮询重建。
803
+ if (queue && queue.ctx !== ctx) {
804
+ if (queue.timer) clearTimeout(queue.timer)
805
+ queue = null
806
+ }
807
+ queue = queue || { items: [], timer: null, ctx }
808
+ queue.items.push({ text, settled, key, queuedAt: new Date().toISOString() })
809
+ wakeQueues.set(sessionId, queue)
810
+ scheduleWakeFlush(ctx, sessionId)
811
+ return { ok: false, queued: true, reason: '会话正忙(agent busy),已排队(第 ' + queue.items.length + ' 条)—— 空闲后按顺序送达' }
812
+ }
813
+
814
+ function hasQueuedWake(sessionId, key, ctx) {
815
+ const queue = wakeQueues.get(sessionId)
816
+ return Boolean(key && queue && (!ctx || queue.ctx === ctx) && queue.items.some((item) => item.key === key))
817
+ }
818
+
819
+ function clearWakeQueues(ctx) {
820
+ for (const [sessionId, queue] of wakeQueues) {
821
+ if (ctx && queue.ctx !== ctx) continue
822
+ if (queue.timer) clearTimeout(queue.timer)
823
+ wakeQueues.delete(sessionId)
824
+ }
825
+ }
826
+
827
+ function wakeMerged(ctx, sessionId, text, onSettled, queueKey = '') {
828
+ // 同一事件已在队列里时不重复入队;先尝试 flush,空闲时会立即把旧队列送完。
829
+ flushWakeQueue(ctx, sessionId)
830
+ if (hasQueuedWake(sessionId, queueKey, ctx)) {
831
+ const result = { ok: false, queued: true, reason: '会话正忙(agent busy),该事件已在队列中,不重复入队' }
832
+ if (onSettled) onSettled(result)
833
+ return { ok: true, merged: false, queued: true }
834
+ }
740
835
  const now = Date.now()
741
836
  const buf = wakeBuffers.get(sessionId) || { parts: [], timer: null, openedAt: now, settled: [] }
742
837
  buf.parts.push(text)
@@ -747,7 +842,10 @@ function wakeMerged(ctx, sessionId, text, onSettled) {
747
842
  let result = { ok: false, reason: '合并后没有内容可发(这几条都已被处理过)—— 不用管,下一轮会重新判断' }
748
843
  try {
749
844
  const merged = mergeWakeTexts(buf.parts)
750
- if (merged) result = wake(ctx, sessionId, merged)
845
+ if (merged) {
846
+ result = wake(ctx, sessionId, merged)
847
+ if (isBusyWakeResult(result)) result = enqueueWake(ctx, sessionId, merged, buf.settled, queueKey)
848
+ }
751
849
  } catch (error) {
752
850
  result = { ok: false, reason: String((error && error.message) || error) }
753
851
  }
@@ -1500,6 +1598,7 @@ async function pollWithItems(ctx, entry, baseMs, parsed) {
1500
1598
  // 记账一律放到「真正发送之后」:
1501
1599
  // 之前是入队即记账 —— 会话忙时 decideWake 会拒绝,次数却已经记了、seen 也已经推进,
1502
1600
  // 于是那几条既不会重试(seen 已推进)又白白占掉名额。这是会丢消息的 bug。
1601
+ const wakeQueueKey = entry.id + '|' + fresh.map((item) => String(item.number) + '@' + String(item.updated_at || '')).join(',')
1503
1602
  wakeMerged(ctx, entry.sessionId, wakeText, (result) => {
1504
1603
  // 审核 T20:结算逻辑抽成纯函数 planWakeSettlement()(有单测),这里只负责落副作用。
1505
1604
  const settled = planWakeSettlement(entry, {
@@ -1539,7 +1638,7 @@ async function pollWithItems(ctx, entry, baseMs, parsed) {
1539
1638
  if (settled.lastDeferred) entry.lastDeferred = settled.lastDeferred
1540
1639
  if (settled.bumpBackoff) bumpFailure(entry, baseMs)
1541
1640
  } persistEntry(entry)
1542
- })
1641
+ }, wakeQueueKey)
1543
1642
  }
1544
1643
 
1545
1644
  export function apply(ctx) {
@@ -1760,6 +1859,8 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
1760
1859
  // 面板要能一眼分出 GitHub / Gitee:否则行内只能靠 id 前缀猜
1761
1860
  provider: w.provider === 'gitee' ? 'gitee' : 'github',
1762
1861
  ackLabel: w.ackLabel || defaultAckLabel(w.provider),
1862
+ // 会话忙时真正排在 FIFO 里的条数;0 表示没有排队,不靠猜 lastDeferred。
1863
+ queuedWakes: wakeQueueCount(w.sessionId, ctx),
1763
1864
  sessionId: w.sessionId,
1764
1865
  intervalSec: w.intervalSec,
1765
1866
  enabled: isEnabled(w),
@@ -2211,21 +2312,11 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2211
2312
  const number = url.searchParams.get('number') || ''
2212
2313
  const state = readState()
2213
2314
  const list = Object.values(state.watchers || {}).filter((entry) => !repo || entry.repo === repo)
2214
- const lines = []
2215
- for (const entry of list) {
2216
- const trace = itemTrace(entry, number)
2217
- if (!trace) continue
2218
- const touched = Boolean(trace.seen || trace.reported || trace.filtered.length || trace.wakes.length)
2219
- if (!touched) continue
2220
- lines.push('#' + trace.number + ' @ ' + (trace.repo || '?') + ':' + trace.verdict)
2221
- if (trace.seen) lines.push('水位 ' + trace.seen)
2222
- if (trace.reported) lines.push('上次上报 ' + trace.reported)
2223
- for (const item of trace.filtered) lines.push('被过滤(' + (item.reason || '未知') + ')' + item.at)
2224
- for (const item of trace.wakes) lines.push('唤醒尝试 ' + item.at + ' ' + (item.ok ? '成功' : '失败(' + (item.reason || '未知') + ')'))
2225
- }
2226
- const text = lines.length > 0
2227
- ? lines.join(String.fromCharCode(10))
2228
- : noTraceText(number, repo || '所有守')
2315
+ const traces = list.map((entry) => itemTrace(entry, number)).filter((trace) => trace
2316
+ && Boolean(trace.seen || trace.reported || trace.filtered.length || trace.wakes.length))
2317
+ const text = traces.length > 0
2318
+ ? formatTraceText(traces)
2319
+ : noTraceText(number, repo ? ' ' + repo : '所有守')
2229
2320
  json(res, 200, { ok: true, text })
2230
2321
  },
2231
2322
  })
@@ -2312,6 +2403,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2312
2403
  // 插件卸载/热重载后旧定时器不能继续跑:它们还持有已 dispose 的 ctx
2313
2404
  for (const handle of timers.values()) { try { clearInterval(handle) } catch {} }
2314
2405
  timers.clear()
2406
+ clearWakeQueues(ctx)
2315
2407
  try { clearInterval(sweepHandle) } catch {}
2316
2408
  }
2317
2409
  // 两条路都挂上:ctx.effect 的清理函数在 effect 作用域销毁时一定被调用;
@@ -2372,6 +2464,8 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2372
2464
  numbers: { type: 'string', description: '逗号分隔的多个编号,如 "12,13,14"(number 与 numbers 至少填一个)' },
2373
2465
  label: { type: 'string', description: 'ack label, default 主理鱼:已处理' },
2374
2466
  note: { type: 'string', description: '可选:一句话记下这条最后怎么处理的(如「已修,见 #57」「不修,上游已修」)。下次这条再被叫醒时会带回来,省得会话重新判一遍。' },
2467
+ comment: { type: 'boolean', description: '把 note 作为评论回写到原 issue/PR(默认 false)。必须同时给 note;这是显式写操作。' },
2468
+ kind: { type: 'string', description: "Gitee 评论回写时的条目类型:'issue'(默认)或 'pull';GitHub 不需要。" },
2375
2469
  format: { type: 'string', description: "'text' (default) or 'json'." },
2376
2470
  },
2377
2471
  async execute(args) {
@@ -2395,6 +2489,8 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2395
2489
  : watchers.find((w) => w && w.enabled)
2396
2490
  if (!entry) return toolError(args, 'no watcher for that repo — start one with watch_start first')
2397
2491
  const label = String(args.label || entry.ackLabel || defaultAckLabel(entry.provider))
2492
+ const note = typeof args.note === 'string' ? args.note.trim().slice(0, 200) : ''
2493
+ if (args.comment === true && !note) return toolError(args, 'comment:true 需要同时提供 note —— 不会发一条空评论')
2398
2494
  // GitHub 不会因为加标签而自动建标签:不存在时返回 422。先幂等建一次(已存在也返回 422,忽略)。
2399
2495
  // Gitee 没有「建标签」的独立端点(标签必须先存在),所以这边只打标签;
2400
2496
  // 标签不存在时它会 404 —— 让调用方看到真实原因,别假装成功。
@@ -2418,9 +2514,22 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2418
2514
  })()
2419
2515
  : await run('gh', ['api', '-X', 'POST', `repos/${entry.repo}/issues/${number}/labels`, '-f', `labels[]=${label}`], { env: ghEnv() })
2420
2516
  if (res.code !== 0) {
2421
- failed = { number, text: redact([res.stdout, res.stderr].filter(Boolean).join(' ').trim()).slice(0, 200) }
2517
+ failed = { number, text: redact([res.stdout, res.stderr].filter(Boolean).join(' ').trim()).slice(0, 200), phase: 'label' }
2422
2518
  break
2423
2519
  }
2520
+ // Delivery(官方原型可吸收的一部分):处理结论不只留在本地,显式 comment:true 时回写原条目。
2521
+ if (args.comment === true) {
2522
+ const posted = entry.provider === 'gitee'
2523
+ ? await (async () => {
2524
+ const r = await addGiteeComment({ repo: entry.repo, token: String(readSecrets().giteeToken || ''), number, body: note, kind: args.kind === 'pull' ? 'pull' : 'issue' })
2525
+ return { code: r.ok ? 0 : 1, stdout: '', stderr: r.ok ? '' : String(r.status || '') + ' ' + String(r.error || '') }
2526
+ })()
2527
+ : await run('gh', ['api', '-X', 'POST', `repos/${entry.repo}/issues/${number}/comments`, '-f', `body=${note}`], { env: ghEnv() })
2528
+ if (posted.code !== 0) {
2529
+ failed = { number, text: redact([posted.stdout, posted.stderr].filter(Boolean).join(' ').trim()).slice(0, 200), phase: 'comment' }
2530
+ break
2531
+ }
2532
+ }
2424
2533
  results.push(number)
2425
2534
  }
2426
2535
  if (failed) {
@@ -2439,12 +2548,13 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2439
2548
  if (args && args.format === 'json') {
2440
2549
  return JSON.stringify({
2441
2550
  schemaVersion: 1, ok: false, repo: entry.repo, acked: results,
2442
- failed: { number: failed.number, text: failed.text, kind: why.kind, retryable, advice },
2551
+ failed: { number: failed.number, text: failed.text, kind: why.kind, retryable, advice, phase: failed.phase || 'label' },
2443
2552
  })
2444
2553
  }
2554
+ const phaseNote = failed.phase === 'comment' ? '(标签已打,评论回写失败)' : ''
2445
2555
  return retryable
2446
- ? `[error: #${failed.number} ${advice}(${label})]`
2447
- : `[error: #${failed.number} ${advice}] ${why.hint}`
2556
+ ? `[error: #${failed.number} ${advice}(${label})]${phaseNote}`
2557
+ : `[error: #${failed.number} ${advice}] ${why.hint}${phaseNote}`
2448
2558
  }
2449
2559
  const latest = readState()
2450
2560
  const live = latest.watchers && latest.watchers[entry.id]
@@ -2459,7 +2569,6 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2459
2569
  // 「叫醒之后」的闭环(见 docs/为什么做这个产品.md 诉求 2):
2460
2570
  // 以前只记「叫醒过」,不记「怎么处理的」—— 同一条被重开时会话只能重新判一遍。
2461
2571
  // 有界:只留最近 20 条,超出丢最旧的。
2462
- const note = typeof args.note === 'string' ? args.note.trim().slice(0, 200) : ''
2463
2572
  if (note) {
2464
2573
  const acked = { ...(live.acked || {}) }
2465
2574
  for (const number of results) acked[String(number)] = { at: nowIso, note }
@@ -2470,10 +2579,11 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2470
2579
  }
2471
2580
  if (args && args.format === 'json') {
2472
2581
  // labelNote 是「标签是新建的还是本来就有的」——JSON 分支以前把它丢了,消费方只能猜
2473
- return JSON.stringify({ schemaVersion: 1, ok: true, repo: entry.repo, label, acked: results, at: nowIso, labelNote: labelNote || null })
2582
+ return JSON.stringify({ schemaVersion: 1, ok: true, repo: entry.repo, label, acked: results, at: nowIso, labelNote: labelNote || null, ...(args.comment === true ? { commented: true } : {}) })
2474
2583
  }
2475
2584
  return `acked ${entry.repo} #${results.join(' #')} with label "${label}"` + labelNote
2476
2585
  + (typeof args.note === 'string' && args.note.trim() ? '|记下了:' + args.note.trim().slice(0, 200) : '')
2586
+ + (args.comment === true ? '|已回写评论' : '')
2477
2587
  },
2478
2588
  }))
2479
2589
 
@@ -2511,41 +2621,15 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2511
2621
  return toolError(args, why)
2512
2622
  }
2513
2623
  const number = rawNumber
2514
- const lines = []
2515
- for (const entry of list) {
2516
- const trace = itemTrace(entry, number)
2517
- if (!trace) continue
2518
- const touched = Boolean(trace.seen || trace.reported || trace.filtered.length || trace.wakes.length)
2519
- if (!touched) continue
2520
- lines.push('#' + trace.number + ' @ ' + (trace.repo || '?') + ':' + trace.verdict)
2521
- // 例外优先:一切正常时一行说完,只有「被过滤/被吸收/唤醒失败」才展开细节
2522
- const quiet = trace.filtered.length === 0 && (trace.absorbed || []).length === 0
2523
- && trace.wakes.length > 0 && trace.wakes.every((item) => item.ok)
2524
- if (!quiet) {
2525
- if (trace.seen) lines.push(' 水位 seen:' + trace.seen)
2526
- if (trace.reported) lines.push(' 上次上报:' + trace.reported)
2527
- for (const item of trace.filtered) lines.push(' 被过滤(' + item.reason + '):' + item.at)
2528
- for (const item of trace.absorbed || []) lines.push(' 被冷却期吸收:' + item.at)
2529
- for (const item of trace.wakes) lines.push(' 唤醒尝试:' + item.at + ' ' + (item.ok ? '成功' : '失败(' + (item.reason || '未知') + ')'))
2530
- } else if (trace.wakes.length > 0) {
2531
- lines.push(' 最近一次唤醒:' + trace.wakes[trace.wakes.length - 1].at + '(成功)')
2532
- }
2533
- }
2624
+ const traces = list.map((entry) => itemTrace(entry, number)).filter((trace) => trace
2625
+ && Boolean(trace.seen || trace.reported || trace.filtered.length || trace.wakes.length))
2534
2626
  if (args && args.format === 'json') {
2535
- const results = []
2536
- for (const entry of list) {
2537
- const trace = itemTrace(entry, number)
2538
- if (!trace) continue
2539
- const touched = Boolean(trace.seen || trace.reported || trace.filtered.length || trace.wakes.length)
2540
- if (!touched) continue
2541
- results.push(trace)
2542
- }
2543
- return JSON.stringify({ schemaVersion: 1, number: String(number), results }, null, 2)
2627
+ return JSON.stringify({ schemaVersion: 1, number: String(number), results: traces }, null, 2)
2544
2628
  }
2545
- if (lines.length === 0) {
2629
+ if (traces.length === 0) {
2546
2630
  return noTraceText(number, wanted ? ' ' + wanted : '所有守')
2547
2631
  }
2548
- return lines.join(String.fromCharCode(10))
2632
+ return formatTraceText(traces)
2549
2633
  },
2550
2634
  }))
2551
2635
 
@@ -2842,7 +2926,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2842
2926
  }
2843
2927
  if (parsedSpecs.length === 0) return toolError(args, '至少给一个仓库(owner/name)')
2844
2928
  const repoList = parsedSpecs.map(({ item, spec }) => ({ repo: spec.repo, provider: spec.provider, label: item }))
2845
- const applyOne = ({ repo, provider }) => {
2929
+ const applyOne = async ({ repo, provider }) => {
2846
2930
  const id = (provider === 'gitee' ? 'gitee:' : '') + `${repo}#${sessionId}`
2847
2931
  const state = readState()
2848
2932
  const existing = state.watchers && state.watchers[id]
@@ -2873,6 +2957,9 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2873
2957
  if (typeof args.goal === 'string') entry.goal = args.goal.slice(0, 500)
2874
2958
  if (typeof args.observe === 'boolean') entry.observe = args.observe
2875
2959
  if (typeof args.isolated === 'boolean') entry.isolated = args.isolated
2960
+ // 与 HTTP 创建路径同口径:隔离开着但没给目录,就明确兜底到宿主 cwd。
2961
+ // 否则面板创建不告警、工具创建却被 doctor 警告,同一个配置两种结果。
2962
+ if (entry.isolated && !entry.workdir) entry.workdir = process.cwd()
2876
2963
  if (typeof args.workdir === 'string' && args.workdir.trim()) {
2877
2964
  const workdir = args.workdir.trim()
2878
2965
  if (!isAbsolute(workdir)) return toolError(args, 'workdir must be an absolute path')
@@ -2919,6 +3006,14 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2919
3006
  return '一条会话最多同时挂 ' + MAX_WATCHERS_PER_SESSION + ' 条在跑的守(现在 ' + mine.length + ' 条)—— 先 watch_stop 停掉不用的,或把多个仓库合成一条规则'
2920
3007
  }
2921
3008
  }
3009
+ // 与 HTTP 创建路径同口径:**新建**才做添加前体检,编辑不重复打网络。
3010
+ // 只警告不阻止:仓库不存在/只读/归档要在创建时就说,而不是等下一次轮询。
3011
+ let warnings = []
3012
+ if (!existing) {
3013
+ const pre = await precheckRepo(repo, provider)
3014
+ warnings = pre.warnings || []
3015
+ if (pre.access) entry.repoAccess = pre.access
3016
+ }
2922
3017
  state.watchers[id] = entry
2923
3018
  // 显式 start 同 repo/session 表示要重建;只解除这个 id 的墓碑,不影响其他已删守。
2924
3019
  writeState(state, { revive: [id] })
@@ -2936,7 +3031,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2936
3031
  if (entry.batchLimit) flags.push('batch=' + entry.batchLimit)
2937
3032
  if (entry.maxWakesPerHour) flags.push('perHour=' + entry.maxWakesPerHour)
2938
3033
  if (entry.goal) flags.push('goal=' + JSON.stringify(entry.goal.slice(0, 40)))
2939
- return { entry, existing, flags, id, repo }
3034
+ return { entry, existing, flags, id, repo, warnings }
2940
3035
 
2941
3036
  }
2942
3037
  // 批量要整批校验:19 条时一次加 2 条,不能只加进去第一条
@@ -2954,22 +3049,29 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2954
3049
  }
2955
3050
  const applied = []
2956
3051
  for (const item of repoList) {
2957
- const result = applyOne(item)
3052
+ const result = await applyOne(item)
2958
3053
  // 单条校验失败(比如相对路径的 workdir)要原地返回,不能继续加后面的
2959
3054
  if (typeof result === 'string') return result
2960
3055
  applied.push(result)
2961
3056
  }
3057
+ // 与 HTTP 创建回执同形状:warnings 是字符串数组;仓库归属在 repos[] 与文本行里表达。
3058
+ const warnings = applied.flatMap((item) => item.warnings || [])
2962
3059
  if (args && args.format === 'json') {
2963
3060
  const first = applied[0]
2964
3061
  const base = JSON.parse(JSON.stringify({ schemaVersion: 1, ok: true, repo: first.repo, sessionId, id: first.id, intervalSec: first.entry.intervalSec,
2965
3062
  flags: first.flags, filters: first.entry.filters || {}, updated: Boolean(first.existing), observe: first.entry.observe === true,
2966
3063
  isolated: first.entry.isolated === true, activeHours: first.entry.activeHours || null }))
2967
- base.repos = applied.map((item) => ({ repo: item.repo, id: item.id, updated: Boolean(item.existing) }))
3064
+ base.repos = applied.map((item) => ({ repo: item.repo, id: item.id, updated: Boolean(item.existing), ...(item.warnings.length ? { warnings: item.warnings } : {}) }))
3065
+ // 只在确有警告时增加字段,保持正常创建的 JSON 形状不变。
3066
+ if (warnings.length) base.warnings = warnings
2968
3067
  return JSON.stringify(base, null, 2)
2969
3068
  }
2970
3069
  const lines = applied.map((item) => `watching ${item.repo} → session ${sessionId} every ${item.entry.intervalSec}s`
2971
3070
  + (item.flags.length ? ' [' + item.flags.join(' ') + ']' : '')
2972
3071
  + (item.existing ? ' (updated existing watcher)' : ''))
3072
+ for (const item of applied) {
3073
+ for (const warning of item.warnings || []) lines.push('WARN ' + item.repo + ':' + warning)
3074
+ }
2973
3075
  return lines.join(String.fromCharCode(10))
2974
3076
  },
2975
3077
  }))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.9.259",
3
+ "version": "0.9.261",
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",