dsh-session-superagent 0.8.79 → 0.8.80

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,27 @@
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.80] - 2026-11-02 —— 「已经有 PR 在做了」:避免重复劳动
6
+
7
+ ### 学到的(知识库第 29 条)
8
+ GraphQL `CrossReferencedEvent` 能拿到引用过这条 issue 的 PR;`source` 是 **union**,
9
+ 必须 `source { __typename ... on PullRequest { … } }`,否则报
10
+ `Selections can't be made directly on unions`(实测踩到)。
11
+ <https://docs.github.com/en/graphql/reference/objects#crossreferencedevent>
12
+
13
+ ### 为什么值得
14
+ 评论只能看出"有人在说话",**关联 PR** 才能看出"已经有人在写代码"。
15
+ 会话最怕重复劳动:其实已经有人开了 PR,它又从零改一遍。
16
+
17
+ ### 改了什么(零额外请求)
18
+ 把时间线查询**挂进已有的批量 GraphQL**,解析出关联 PR:
19
+ - 去重、忽略非 PR 引用;
20
+ - 排序 `OPEN > MERGED > CLOSED`;
21
+ - 消息里提示 `已有 PR #20(进行中)` / `已有 PR #21(已合并)` / `等 N 个`。
22
+
23
+ ### 测试
24
+ - 新增 1 例(open 优先/去重/忽略 Issue 类型/null 源/各状态文案/等 N 个/消息提醒)。合计 **132 例**。
25
+
5
26
  ## [0.8.79] - 2026-11-02 —— 「躺了 62 天」:积压看得见
6
27
 
7
28
  ### 学到的(知识库第 28 条)
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` 131/131 通过
12
+ - [x] 七个工具可用(github / repo_here / watch_start / watch_status / watch_stop / watch_ack / watch_doctor),`node --test` 132/132 通过
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.79-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.8.80-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 # 131 项单测
102
+ node --test # 132 项单测
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.79'
17
+ const CLIENT_VERSION = '0.8.80'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
package/lib/index.js CHANGED
@@ -30,7 +30,7 @@ import {
30
30
 
31
31
  export const name = 'dsh-session-superagent'
32
32
  /** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
33
- export const SERVER_VERSION = '0.8.79'
33
+ export const SERVER_VERSION = '0.8.80'
34
34
  export const inject = ['tools', 'agents', 'webServer']
35
35
 
36
36
  /** 仅供测试:读写状态文件(生产代码不要用)。 */
@@ -691,7 +691,10 @@ async function fetchLastComments(repo, items, maxItems = 3) {
691
691
  let hit = 0
692
692
  for (const item of targets) {
693
693
  const info = parsed[String(item.number)]
694
- if (info) { mark(item, info); hit += 1 }
694
+ if (!info) continue
695
+ if (info.login) mark(item, info)
696
+ if (Array.isArray(info.linked) && info.linked.length > 0) item.linkedPr = info.linked
697
+ hit += 1
695
698
  }
696
699
  if (hit > 0) return
697
700
  } catch { /* 落到 REST 兜底 */ }
package/lib/watch.js CHANGED
@@ -105,6 +105,7 @@ export function formatWatchText(repo, fresh, options = {}) {
105
105
  (stateReasonNote(item) && String(item.state_reason || '') === 'reopened') ? '⚠ ' + stateReasonNote(item) : null,
106
106
  assignmentNote(item) || null,
107
107
  (item.state === 'open' ? stalenessNote(item) : '') || null,
108
+ linkedPrNote(item.linkedPr) || null,
108
109
  item.lastComment
109
110
  ? '最后评论: ' + commentSummaryLine({
110
111
  login: item.lastComment.self ? '' : item.lastComment.login,
@@ -716,7 +717,10 @@ export function buildCommentBatchQuery(count) {
716
717
  const n = Math.max(0, Math.min(10, Number(count) || 0))
717
718
  const parts = []
718
719
  for (let i = 0; i < n; i += 1) {
719
- parts.push(' i' + i + ': issue(number: $n' + i + ') { number comments(last: 1) { nodes { author { login } createdAt } } }')
720
+ parts.push(' i' + i + ': issue(number: $n' + i + ') { number'
721
+ + ' comments(last: 1) { nodes { author { login } createdAt } }'
722
+ + ' timelineItems(last: 5, itemTypes: [CROSS_REFERENCED_EVENT]) { nodes { ... on CrossReferencedEvent {'
723
+ + ' source { __typename ... on PullRequest { number state url } } } } } }')
720
724
  }
721
725
  const vars = Array.from({ length: n }, (_, i) => '$n' + i + ': Int!').join(', ')
722
726
  return 'query($owner: String!, $name: String!' + (n > 0 ? ', ' + vars : '') + ') {'
@@ -740,8 +744,13 @@ export function parseCommentBatch(payload) {
740
744
  const node = Array.isArray(nodes) && nodes.length > 0 ? nodes[nodes.length - 1] : null
741
745
  if (!node) continue
742
746
  const login = node.author && node.author.login ? String(node.author.login) : ''
743
- if (!login) continue
744
- out[String(value.number)] = { login, at: node.createdAt ? String(node.createdAt) : '' }
747
+ const linked = pickLinkedPullRequests(value.timelineItems && value.timelineItems.nodes)
748
+ if (!login && linked.length === 0) continue
749
+ out[String(value.number)] = {
750
+ login,
751
+ at: node.createdAt ? String(node.createdAt) : '',
752
+ linked,
753
+ }
745
754
  }
746
755
  return out
747
756
  }
@@ -819,3 +828,36 @@ export function stalenessNote(item, options = {}) {
819
828
  if (days < threshold) return ''
820
829
  return '躺了 ' + days + ' 天'
821
830
  }
831
+
832
+ /**
833
+ * 从 cross-reference 时间线里挑出关联的 PR。
834
+ *
835
+ * 依据:`timelineItems(itemTypes: [CROSS_REFERENCED_EVENT])` 会给出引用过这条 issue 的 PR;
836
+ * 注意 `source` 是 union,**必须带 `__typename`** 才能选到 PullRequest 的字段
837
+ * (直接选 `source { number }` 会报 "Selections can't be made directly on unions")。
838
+ * 出处:https://docs.github.com/en/graphql/reference/objects#crossreferencedevent
839
+ */
840
+ export function pickLinkedPullRequests(nodes) {
841
+ const list = Array.isArray(nodes) ? nodes : []
842
+ const seen = new Set()
843
+ const out = []
844
+ for (const node of list) {
845
+ const source = node && node.source
846
+ if (!source || source.__typename !== 'PullRequest' || !source.number) continue
847
+ if (seen.has(source.number)) continue
848
+ seen.add(source.number)
849
+ out.push({ number: source.number, state: String(source.state || ''), url: String(source.url || '') })
850
+ }
851
+ // open 的排前面(说明真在做),merged 其次,closed 最后
852
+ const rank = { OPEN: 0, MERGED: 1, CLOSED: 2 }
853
+ return out.sort((a, b) => (rank[a.state] ?? 9) - (rank[b.state] ?? 9))
854
+ }
855
+
856
+ /** 「已经有 PR 在做了」——避免会话重复干活。 */
857
+ export function linkedPrNote(linked) {
858
+ const list = Array.isArray(linked) ? linked.filter((item) => item && item.number) : []
859
+ if (list.length === 0) return ''
860
+ const first = list[0]
861
+ const stateText = first.state === 'OPEN' ? '进行中' : first.state === 'MERGED' ? '已合并' : first.state === 'CLOSED' ? '已关闭' : String(first.state || '')
862
+ return '已有 PR #' + first.number + (stateText ? '(' + stateText + ')' : '') + (list.length > 1 ? ' 等 ' + list.length + ' 个' : '')
863
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.8.79",
3
+ "version": "0.8.80",
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",