dsh-session-superagent 0.9.29 → 0.9.31

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,45 @@
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.31] - 2026-11-02 —— 面板也能追溯了(`/trace` 路由,路由面 8 → 9)
6
+
7
+ ### 做了什么
8
+ - 新增 `GET /session-superagent/trace?repo=&number=`:返回结论 + 水位 + 上次上报 + 过滤原因 + 唤醒历史;
9
+ - 面板「判定」页新增「追溯一条」:在右上角搜索框输入编号(如 `42`),点「追溯 #42」把结论显示在提示区。
10
+
11
+ ### 为什么走服务端而不是在客户端再算一遍
12
+ 客户端本地算需要 `seen` / `lastReported` —— 那是**大字段**,而既有用例明确要求
13
+ `/state` 不回传服务端自己用的字段(面板每 5 秒拉一次,省的是真流量)。
14
+ 所以走 `/trace`,按需请求、只回传结论。**同时避免了第三份重复实现**(服务端有 `itemTrace`,客户端不需要再有)。
15
+
16
+ ### 连带改动
17
+ 路由面从 8 条变 9 条:相关用例(跨实例接管 / 撞车重放 / 卸载 / 路由清单)与 preflight 的期望值一并更新。
18
+
19
+ ### 测试
20
+ - 新增 1 例(未输入时给提示、输入编号后出现追溯按钮、单守时说明在哪个仓库查)。合计 **170 例**。
21
+
22
+ ## [0.9.30] - 2026-11-02 —— 单条追溯:`watch_trace` 工具 + `trace-item` 脚本
23
+
24
+ ### 学到的(知识库第 78 条)
25
+ PostgreSQL 的 `EXPLAIN`:不改变执行,只解释"为什么是这个结果"。
26
+
27
+ ### 之前的状态
28
+ 同一件事的数据散在三处:`seen[number]`(水位)、`filteredLog`(过滤记录)、`history`(唤醒历史)。
29
+ 客户问"#42 为什么没叫醒我",得在脑子里拼 —— 拼错就给错答案。
30
+
31
+ ### 做了什么
32
+ `itemTrace(watcher, number)` 拼成一条结论 + 明细:
33
+ `被过滤掉了:已关闭` / `已经唤醒过 N 次` / `已记入水位但没唤醒` / `尝试唤醒过 N 次但都没成功` / `还没轮到它`。
34
+
35
+ 两个入口:工具 **`watch_trace`**(agent 直接查)+ 脚本 `node scripts/trace-item.mjs <编号>`
36
+ (支持 `--demo` 和 `--state <path>`)。
37
+
38
+ ### 一个真实实现坑
39
+ `String(null) === 'null'` 是真值 → `if (!target)` 拦不住 null 入参,用例当场红。先判入参再转字符串。
40
+
41
+ ### 测试
42
+ - 新增 1 例(5 种情况)。合计 **169 例**;工具已进契约快照。
43
+
5
44
  ## [0.9.29] - 2026-11-02 —— 「多久会叫醒我」现在能算给人看
6
45
 
7
46
  ### 学到的(知识库第 77 条)
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.29-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.9.31-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
7
7
  [![npm](https://img.shields.io/npm/v/dsh-session-superagent.svg)](https://www.npmjs.com/package/dsh-session-superagent)
8
8
  [![dsh](https://img.shields.io/badge/DeepSeek%20Harness-plugin-orange.svg)](https://github.com/topics/dsh-plugin)
9
9
 
package/client.js CHANGED
@@ -14,7 +14,7 @@ window.__ModuleLoader__.load({
14
14
  const { useCallback, useEffect, useRef, useState } = React
15
15
 
16
16
  // 客户端版本探针:每次模块加载写一次,用来确认浏览器里跑的是哪一版
17
- const CLIENT_VERSION = '0.9.29'
17
+ const CLIENT_VERSION = '0.9.31'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
@@ -1228,6 +1228,31 @@ window.__ModuleLoader__.load({
1228
1228
  count: watchers.reduce((n, w) => n + (w.history || []).length, 0),
1229
1229
  action: h(InfoTip, { text: '每轮判定都会记一条:唤醒、仅观察,或跳过及其原因。只存最近若干条。' }),
1230
1230
  },
1231
+ (() => {
1232
+ const needle = search.trim()
1233
+ const asNumber = /^#?[0-9]+$/.test(needle) ? needle.replace('#', '') : ''
1234
+ if (!asNumber) {
1235
+ return h(Section, { key: 'trace', title: '追溯一条', hint: '在右上角搜索框输入编号(如 42),这里就能查它经历了什么' },
1236
+ h(Hint, null, '追溯会告诉你:它被过滤了、已经唤醒过、还是根本没轮到。'))
1237
+ }
1238
+ const onlyRepo = watchers.length === 1 ? watchers[0].repo : ''
1239
+ return h(Section, { key: 'trace', title: '追溯一条' },
1240
+ h('div', { className: 'dt-row-meta' },
1241
+ h('button', {
1242
+ className: 'dt-textlink',
1243
+ type: 'button',
1244
+ onClick: async () => {
1245
+ try {
1246
+ const query = '/trace?number=' + encodeURIComponent(asNumber) + (onlyRepo ? '&repo=' + encodeURIComponent(onlyRepo) : '')
1247
+ const payload = await call(query)
1248
+ notify(String((payload && payload.text) || '没有结果').split(String.fromCharCode(10)).join(' · '), 'info')
1249
+ } catch (error) {
1250
+ notify('追溯失败:' + String((error && error.message) || error), 'error')
1251
+ }
1252
+ },
1253
+ }, '追溯 #' + asNumber),
1254
+ h('span', { className: 'dt-row-meta' }, onlyRepo ? '(在 ' + onlyRepo + ' 里查)' : '(在所有守里查)')))
1255
+ })(),
1231
1256
  (() => {
1232
1257
  const counts = new Map()
1233
1258
  for (const w of watchers) if (w.deferReason) counts.set(w.deferReason, (counts.get(w.deferReason) || 0) + 1)
package/lib/index.js CHANGED
@@ -28,13 +28,14 @@ import {
28
28
  TRIAGE_SIGNALS, accessNote, buildCommentBatchQuery, classifyGhError, commentSummaryLine, parseCommentBatch, pickSuggestion, repoStructureNote, countReasons, filterReason, hasAckLabel, jitterMs, parseGhInclude, retryAfterMs, throttleDelayMs, inActiveHours, newestUpdatedAt, nextDelayMs, pushFiltered, normalizeFilters, partitionItems, passesFilters,
29
29
  shouldRunCleanup,
30
30
  countCapped,
31
+ itemTrace,
31
32
  splitBatch,
32
33
  mergeFilters, mergePollResult, mergeWakeTexts, pushEvent, silentStreak, msUntilActiveWindow, nextWaketimeAt, pruneSeen, sessionWakesLastHour, pruneWakeTimes, pushHistory, recordReported, staleWorktrees, worktreePlan,
33
34
  } from './watch.js'
34
35
 
35
36
  export const name = 'dsh-session-superagent'
36
37
  /** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
37
- export const SERVER_VERSION = '0.9.29'
38
+ export const SERVER_VERSION = '0.9.31'
38
39
  export const inject = ['tools', 'agents', 'webServer']
39
40
  /** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
40
41
  const DEFAULT_SESSION_WAKES = 12
@@ -1525,6 +1526,36 @@ export function apply(ctx) {
1525
1526
  },
1526
1527
  })
1527
1528
 
1529
+ // 单条追溯:面板点「追溯」时来问。只回传结论与明细,不回传 seen/lastReported 这类大字段。
1530
+ addRoute({
1531
+ kind: 'exact',
1532
+ path: '/session-superagent/trace',
1533
+ handler: async (req, res) => {
1534
+ if (req.method !== 'GET') return json(res, 405, { error: 'method not allowed' })
1535
+ const url = new URL(String(req.url || '/'), 'http://127.0.0.1')
1536
+ const repo = url.searchParams.get('repo') || ''
1537
+ const number = url.searchParams.get('number') || ''
1538
+ const state = readState()
1539
+ const list = Object.values(state.watchers || {}).filter((entry) => !repo || entry.repo === repo)
1540
+ const lines = []
1541
+ for (const entry of list) {
1542
+ const trace = itemTrace(entry, number)
1543
+ if (!trace) continue
1544
+ const touched = Boolean(trace.seen || trace.reported || trace.filtered.length || trace.wakes.length)
1545
+ if (!touched) continue
1546
+ lines.push('#' + trace.number + ' @ ' + (trace.repo || '?') + ':' + trace.verdict)
1547
+ if (trace.seen) lines.push('水位 ' + trace.seen)
1548
+ if (trace.reported) lines.push('上次上报 ' + trace.reported)
1549
+ for (const item of trace.filtered) lines.push('被过滤(' + (item.reason || '未知') + ')' + item.at)
1550
+ for (const item of trace.wakes) lines.push('唤醒尝试 ' + item.at + ' ' + (item.ok ? '成功' : '失败(' + (item.reason || '未知') + ')'))
1551
+ }
1552
+ const text = lines.length > 0
1553
+ ? lines.join(String.fromCharCode(10))
1554
+ : '#' + number + ' 在' + (repo || '所有守') + ' 里都没有痕迹 —— 可能还没被轮询到,或者编号写错了。'
1555
+ json(res, 200, { ok: true, text })
1556
+ },
1557
+ })
1558
+
1528
1559
  // 版本检查(只读;面板「设置」页那一行「有新版本」靠它)
1529
1560
  addRoute({
1530
1561
  kind: 'exact',
@@ -1702,6 +1733,44 @@ export function apply(ctx) {
1702
1733
  },
1703
1734
  }))
1704
1735
 
1736
+ // 单条追溯:agent 被问"这条为什么没叫醒我"时不用猜,直接查
1737
+ ctx.tools.register(defineTool({
1738
+ name: 'watch_trace',
1739
+ description:
1740
+ 'Explain what happened to one issue/PR: whether it was filtered (and why), absorbed by the cooldown, already reported, or never seen. Read-only — changes nothing. Use it when the customer asks "why did this not wake me".',
1741
+ parameters: {
1742
+ repo: { type: 'string', description: 'owner/name; defaults to the only watched repo' },
1743
+ number: { type: 'number', description: 'issue or PR number to trace' },
1744
+ },
1745
+ async execute(args) {
1746
+ const state = readState()
1747
+ const all = Object.values(state.watchers || {})
1748
+ const wanted = typeof args.repo === 'string' && args.repo.trim() ? args.repo.trim() : null
1749
+ const list = wanted ? all.filter((entry) => entry && entry.repo === wanted) : all
1750
+ if (list.length === 0) {
1751
+ return '[error: no watcher for that repo — ' + (wanted ? 'nothing is watching ' + wanted : 'run watch_status to see what is watched') + ']'
1752
+ }
1753
+ const number = Number(args.number)
1754
+ if (!Number.isFinite(number)) return '[error: number is required]'
1755
+ const lines = []
1756
+ for (const entry of list) {
1757
+ const trace = itemTrace(entry, number)
1758
+ if (!trace) continue
1759
+ const touched = Boolean(trace.seen || trace.reported || trace.filtered.length || trace.wakes.length)
1760
+ if (!touched) continue
1761
+ lines.push('#' + trace.number + ' @ ' + (trace.repo || '?') + ':' + trace.verdict)
1762
+ if (trace.seen) lines.push(' 水位 seen:' + trace.seen)
1763
+ if (trace.reported) lines.push(' 上次上报:' + trace.reported)
1764
+ for (const item of trace.filtered) lines.push(' 被过滤(' + item.reason + '):' + item.at)
1765
+ for (const item of trace.wakes) lines.push(' 唤醒尝试:' + item.at + ' ' + (item.ok ? '成功' : '失败(' + (item.reason || '未知') + ')'))
1766
+ }
1767
+ if (lines.length === 0) {
1768
+ return '#' + number + ' 在' + (wanted ? ' ' + wanted : '所有守') + ' 里都没有痕迹 —— 可能还没被轮询到,或者编号写错了。'
1769
+ }
1770
+ return lines.join(String.fromCharCode(10))
1771
+ },
1772
+ }))
1773
+
1705
1774
  ctx.tools.register(defineTool({
1706
1775
  name: 'watch_doctor',
1707
1776
  description:
package/lib/watch.js CHANGED
@@ -750,3 +750,35 @@ export function splitBatch(fresh, limit = 3, priority) {
750
750
  const rest = (Array.isArray(fresh) ? fresh : []).filter((item) => !picked.has(item.number))
751
751
  return { listed, rest }
752
752
  }
753
+
754
+ /**
755
+ * 单条条目的追踪:它到底经历了什么(被过滤 / 被冷却吸收 / 上报过 / 还在等)。
756
+ *
757
+ * 客户会问"这条 issue 为什么没叫醒我"。这个问题以前只能靠三处分散的数据
758
+ * (seen 水位、filteredLog、history)自己在脑子里拼 —— 这里拼好并返回结构化结果。
759
+ * 类比 SQL 的 EXPLAIN:不改变行为,只解释"为什么是这个结果"。
760
+ * 出处:https://www.postgresql.org/docs/current/sql-explain.html
761
+ */
762
+ export function itemTrace(watcher, number) {
763
+ // 注意 String(null) === 'null' —— 先判断入参本身,别让 null 变成一个合法编号
764
+ if (!watcher || number === null || number === undefined || number === '') return null
765
+ const target = String(number).trim()
766
+ if (!target) return null
767
+ const seen = (watcher.seen && watcher.seen[target]) || null
768
+ const reported = (watcher.lastReported && watcher.lastReported[target]) || null
769
+ const filtered = (Array.isArray(watcher.filteredLog) ? watcher.filteredLog : [])
770
+ .filter((entry) => String(entry.number) === target)
771
+ .map((entry) => ({ at: entry.at, reason: entry.reason, title: entry.title }))
772
+ const wakes = (Array.isArray(watcher.history) ? watcher.history : [])
773
+ .filter((entry) => Array.isArray(entry.numbers) && entry.numbers.map(String).includes(target))
774
+ .map((entry) => ({ at: entry.at, ok: Boolean(entry.ok), reason: entry.reason || null }))
775
+
776
+ let verdict
777
+ if (filtered.length > 0 && !seen && !reported) verdict = '被过滤掉了:' + (filtered[filtered.length - 1].reason || '未知原因')
778
+ else if (wakes.some((w) => w.ok)) verdict = '已经唤醒过 ' + wakes.filter((w) => w.ok).length + ' 次'
779
+ else if (seen) verdict = '已记入水位但没唤醒(被吸收/仅观察/或上报前就已存在)'
780
+ else if (wakes.length > 0) verdict = '尝试唤醒过 ' + wakes.length + ' 次但都没成功'
781
+ else verdict = '还没轮到它(可能还没被轮询到,或在批外)'
782
+
783
+ return { number: target, repo: watcher.repo || null, seen, reported, filtered, wakes, verdict }
784
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.9.29",
3
+ "version": "0.9.31",
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",