dsh-session-superagent 0.8.71 → 0.8.73

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,54 @@
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.8.73] - 2026-11-02 —— 主轮询要不要换 GraphQL:测完结论是**不换**(并留下基准脚本)
6
+
7
+ ### 学到/测到的(知识库第 22 条)
8
+ 新增可复现基准 `node scripts/bench-api.mjs owner/name`,实测:
9
+
10
+ | 场景 | REST(我们现在的) | GraphQL |
11
+ |---|---|---|
12
+ | 小仓库 20 条 | 769ms / 13.9 KB | 709ms / 1.0 KB |
13
+ | 大仓库 20 条 | 1418ms / 113 KB | 1067ms / 6.9 KB |
14
+ | 取 3 条最后评论 | 逐条 1786ms | 批量 439ms |
15
+
16
+ ### 为什么**不**换主路径
17
+ 1. 我们已经用 **ETag**:没变化时整轮 304,**零解析零传输**。GraphQL 没有等价用法,
18
+ 换过去等于把"大多数轮次几乎免费"变成"每轮都拉一遍"——净亏。
19
+ 2. GraphQL 的优势只在"确实有变化"时兑现,而那时我们的评论请求已在 0.8.72 批量化了(快 4 倍)。
20
+ 3. 主路径是核心,收益要靠侧证;**侧证不支持就不动**。
21
+
22
+ ### 顺带证伪一个"想当然"
23
+ "用 `state=open` 代替 `state=all` 能减小响应" —— 实测同仓库同 20 条:
24
+ `all` **113,895 字节** vs `open` **130,274 字节**(反而更大)。所以这条优化不做。
25
+
26
+ ### 本版改动
27
+ - 新增 `scripts/bench-api.mjs`(这只是量具,不改变运行时行为);
28
+ - 版本号/文档同步。**没有改主轮询逻辑 —— 这是有意识的选择。**
29
+
30
+ ## [0.8.72] - 2026-11-02 —— 取「最后评论」改成一次 GraphQL 批量
31
+
32
+ ### 学到的(知识库第 21 条)
33
+ GraphQL 可以在同一请求里用别名查多个对象 —— 3 条 issue 的最后评论,从 **3 次 REST + 1 次 `/user`**
34
+ 变成 **1 次请求**。
35
+ <https://docs.github.com/en/graphql>
36
+
37
+ ### 本机实测
38
+ ```
39
+ 批量 GraphQL: 671ms,命中 2/3 条(第 3 条作者已注销)
40
+ 逐条 REST : 1443ms(3 次调用)
41
+ ```
42
+ → 耗时约 **1/2.1**,调用次数 **3 → 1**。
43
+
44
+ ### 两个坑(都处理了)
45
+ 1. **`gh api graphql` 有 `errors` 时退出码是 1,但 `stdout` 的 `data` 仍然完整** ——
46
+ 必须先解析 stdout,不能因退出码非 0 就整批放弃(否则只要有一条 issue 不存在就白跑)。
47
+ 用例专门造了 `i1: null` + `errors` 的形态锁这个行为。
48
+ 2. 保留**逐条 REST 兜底**(GraphQL 不可用时仍能工作)。
49
+
50
+ ### 测试
51
+ - 新增 1 例。合计 **125 例**。
52
+
5
53
  ## [0.8.71] - 2026-11-02 —— 「最后一条是我发的」不能当成"有人在处理"
6
54
 
7
55
  ### 学到的(知识库第 20 条)
package/MAINTENANCE.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## 二、当前状态(2026-11-01)
11
11
 
12
- - [x] 七个工具可用(github / repo_here / watch_start / watch_status / watch_stop / watch_ack / watch_doctor),`node --test` 124/124 通过
12
+ - [x] 七个工具可用(github / repo_here / watch_start / watch_status / watch_stop / watch_ack / watch_doctor),`node --test` 125/125 通过
13
13
  - [x] 自回声抑制(逐条水位)
14
14
  - [x] 仅空闲注入(避免草稿回放)
15
15
  - [x] 唤醒失败不推进水位
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.8.71-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.8.73-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
 
@@ -99,7 +99,7 @@ dsh plugin install /path/to/dsh-session-superagent
99
99
  ## 开发
100
100
 
101
101
  ```sh
102
- node --test # 124 项单测
102
+ node --test # 125 项单测
103
103
  ```
104
104
 
105
105
  版本与发布流程见 [UPDATING.md](UPDATING.md),交付门见 [CHECKLIST.md](CHECKLIST.md),接手台账见 [MAINTENANCE.md](MAINTENANCE.md)。
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.8.71'
17
+ const CLIENT_VERSION = '0.8.73'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
package/lib/index.js CHANGED
@@ -24,13 +24,13 @@ import { redact } from './redact.js'
24
24
  import { decodeBody } from './body.js'
25
25
  import {
26
26
  advanceSeen, applyWatcherAction, batchFresh, decideWake, DEFAULT_ACK_LABEL, formatWatchText,
27
- accessNote, classifyGhError, commentSummaryLine, pickSuggestion, repoStructureNote, countReasons, filterReason, hasAckLabel, jitterMs, parseGhInclude, retryAfterMs, throttleDelayMs, inActiveHours, newestUpdatedAt, nextDelayMs, pushFiltered, normalizeFilters, partitionItems, passesFilters,
27
+ accessNote, buildCommentBatchQuery, classifyGhError, commentSummaryLine, parseCommentBatch, pickSuggestion, repoStructureNote, countReasons, filterReason, hasAckLabel, jitterMs, parseGhInclude, retryAfterMs, throttleDelayMs, inActiveHours, newestUpdatedAt, nextDelayMs, pushFiltered, normalizeFilters, partitionItems, passesFilters,
28
28
  mergeFilters, mergePollResult, pruneSeen, pruneWakeTimes, pushHistory, recordReported, staleWorktrees, worktreePlan,
29
29
  } from './watch.js'
30
30
 
31
31
  export const name = 'dsh-session-superagent'
32
32
  /** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
33
- export const SERVER_VERSION = '0.8.71'
33
+ export const SERVER_VERSION = '0.8.73'
34
34
  export const inject = ['tools', 'agents', 'webServer']
35
35
 
36
36
  /** 仅供测试:读写状态文件(生产代码不要用)。 */
@@ -671,13 +671,38 @@ async function fetchLastComments(repo, items, maxItems = 3) {
671
671
  const targets = (items || []).filter((item) => Number(item.comments) > 0).slice(0, maxItems)
672
672
  if (targets.length === 0) return
673
673
  const me = await viewerLogin()
674
+ const mark = (item, info) => {
675
+ item.lastComment = {
676
+ login: info.login,
677
+ at: info.at,
678
+ self: Boolean(me && String(info.login).toLowerCase() === me.toLowerCase()),
679
+ }
680
+ }
681
+ // 首选:一次 GraphQL 批量(N 条评论 → 1 个请求)
682
+ try {
683
+ const [owner, name] = String(repo).split('/')
684
+ const query = buildCommentBatchQuery(targets.length)
685
+ const args = ['api', 'graphql', '-f', 'query=' + query, '-F', 'owner=' + owner, '-F', 'name=' + name]
686
+ targets.forEach((item, i) => args.push('-F', 'n' + i + '=' + item.number))
687
+ const res = await run('gh', args, { timeoutMs: 15000, env: ghEnv() })
688
+ // 有 errors 但 data 有值时仍然可用(别的 issue 不存在不影响这一条)
689
+ const payload = JSON.parse(String(res.stdout || '{}'))
690
+ const parsed = parseCommentBatch(payload)
691
+ let hit = 0
692
+ for (const item of targets) {
693
+ const info = parsed[String(item.number)]
694
+ if (info) { mark(item, info); hit += 1 }
695
+ }
696
+ if (hit > 0) return
697
+ } catch { /* 落到 REST 兜底 */ }
698
+ // 兜底:逐条 REST(GraphQL 不可用时仍要能工作)
674
699
  await Promise.all(targets.map(async (item) => {
675
700
  try {
676
701
  const res = await run('gh', ['api', `repos/${repo}/issues/${item.number}/comments?per_page=1&sort=created&direction=desc`,
677
702
  '--jq', '.[0] | {login: .user.login, at: .created_at}'], { timeoutMs: 12000, env: ghEnv() })
678
703
  if (res.code !== 0) return
679
704
  const parsed = JSON.parse(res.stdout)
680
- if (parsed && parsed.login) item.lastComment = { login: parsed.login, at: parsed.at, self: Boolean(me && String(parsed.login).toLowerCase() === me.toLowerCase()) }
705
+ if (parsed && parsed.login) mark(item, { login: parsed.login, at: parsed.at })
681
706
  } catch { /* 少一行信息,不阻断唤醒 */ }
682
707
  }))
683
708
  }
package/lib/watch.js CHANGED
@@ -668,3 +668,44 @@ export function commentSummaryLine(lastComment, viewer) {
668
668
  if (!who && !when) return ''
669
669
  return [who, when].filter(Boolean).join(' ')
670
670
  }
671
+
672
+ /**
673
+ * 批量取"最后一条评论"的 GraphQL 查询:一次请求拿 N 条,别一条一个 REST 调用。
674
+ *
675
+ * 依据:GraphQL 支持别名(alias)在同一请求里查多个 issue,且计费按点数而非请求数;
676
+ * 但我们只用它的"批量"能力,复杂度极低(一个 repository + N 个 issue 别名)。
677
+ * 出处:https://docs.github.com/en/graphql
678
+ */
679
+ export function buildCommentBatchQuery(count) {
680
+ const n = Math.max(0, Math.min(10, Number(count) || 0))
681
+ const parts = []
682
+ for (let i = 0; i < n; i += 1) {
683
+ parts.push(' i' + i + ': issue(number: $n' + i + ') { number comments(last: 1) { nodes { author { login } createdAt } } }')
684
+ }
685
+ const vars = Array.from({ length: n }, (_, i) => '$n' + i + ': Int!').join(', ')
686
+ return 'query($owner: String!, $name: String!' + (n > 0 ? ', ' + vars : '') + ') {'
687
+ + ' repository(owner: $owner, name: $name) {'
688
+ + String.fromCharCode(10) + parts.join(String.fromCharCode(10)) + String.fromCharCode(10)
689
+ + '} }'
690
+ }
691
+
692
+ /**
693
+ * 解析批量结果:把 {i0: {number, comments:{nodes:[…]}}} 摊平成 {number: {login, at}}。
694
+ * 单个 issue 不存在时 GraphQL 会在 `errors` 里报 NOT_FOUND,但同请求里别的 issue 仍然有值 ——
695
+ * 所以我们**只看 data,不因为 errors 整体放弃**。
696
+ */
697
+ export function parseCommentBatch(payload) {
698
+ const out = {}
699
+ const repo = payload && payload.data && payload.data.repository
700
+ if (!repo || typeof repo !== 'object') return out
701
+ for (const value of Object.values(repo)) {
702
+ if (!value || typeof value !== 'object') continue
703
+ const nodes = value.comments && value.comments.nodes
704
+ const node = Array.isArray(nodes) && nodes.length > 0 ? nodes[nodes.length - 1] : null
705
+ if (!node) continue
706
+ const login = node.author && node.author.login ? String(node.author.login) : ''
707
+ if (!login) continue
708
+ out[String(value.number)] = { login, at: node.createdAt ? String(node.createdAt) : '' }
709
+ }
710
+ return out
711
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.8.71",
3
+ "version": "0.8.73",
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",