dsh-session-superagent 0.8.78 → 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,48 @@
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
+
26
+ ## [0.8.79] - 2026-11-02 —— 「躺了 62 天」:积压看得见
27
+
28
+ ### 学到的(知识库第 28 条)
29
+ `actions/stale` 的 `days-before-stale` 默认 **60 天**;社区 30/60 两档都常见。
30
+ <https://github.com/actions/stale#readme>
31
+
32
+ 我们的定位不是清理而是**提醒还有积压**,所以用 **30 天**(早一档,留人工决策时间):
33
+ - 只标 `open`(closed 不吵);
34
+ - 默认**只展示**(`躺了 62 天`),加权默认关,开启后 +2;
35
+ - 阈值可配置。
36
+
37
+ ### 写代码时踩的一个坑(已修)
38
+ ```js
39
+ // 错:Number(now) || (Date.now() - at) —— 传了 now 就把 epoch 毫秒当成天数差
40
+ const days = Math.floor((Number(options.now) || Date.now() - at) / 86400000)
41
+ ```
42
+ 用例立刻抓到(显示成 `躺了 20759 天`)。运算符优先级这类错误,有测试就是一行红,没测试就上线错。
43
+
44
+ ### 测试
45
+ - 新增 1 例(62 天会标/刚更新不标/closed 不标/无时间戳不猜/阈值可调/默认 0/开启 +2)。合计 **131 例**。
46
+
5
47
  ## [0.8.78] - 2026-11-02 —— 分诊信号收成一张表,界面上直接看
6
48
 
7
49
  ### 学到的(知识库第 27 条)
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` 130/130 通过
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.78-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 # 130 项单测
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.78'
17
+ const CLIENT_VERSION = '0.8.80'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
@@ -910,6 +910,7 @@ window.__ModuleLoader__.load({
910
910
  comments: draft.priorityComments !== false,
911
911
  labels: draft.priorityLabels !== false,
912
912
  unassigned: draft.priorityUnassigned === true,
913
+ stale: draft.priorityStale === true,
913
914
  },
914
915
  batchLimit: Number(draft.batchLimit) || undefined,
915
916
  maxWakesPerHour: Number(draft.maxWakesPerHour) || undefined,
@@ -1009,6 +1010,7 @@ window.__ModuleLoader__.load({
1009
1010
  priorityComments: (watcher.priority && watcher.priority.comments) !== false,
1010
1011
  priorityLabels: (watcher.priority && watcher.priority.labels) !== false,
1011
1012
  priorityUnassigned: Boolean(watcher.priority && watcher.priority.unassigned) === true,
1013
+ priorityStale: Boolean(watcher.priority && watcher.priority.stale) === true,
1012
1014
  })
1013
1015
  },
1014
1016
  }, watcher.repo)),
@@ -1060,7 +1062,8 @@ window.__ModuleLoader__.load({
1060
1062
  h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: draft.priorityReopened !== false, onChange: (v) => setDraft({ ...draft, priorityReopened: v }), label: '重开优先' }), '被重开的排最前'),
1061
1063
  h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: draft.priorityComments !== false, onChange: (v) => setDraft({ ...draft, priorityComments: v }), label: '评论优先' }), '有人在等回应的靠前'),
1062
1064
  h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: draft.priorityLabels !== false, onChange: (v) => setDraft({ ...draft, priorityLabels: v }), label: '标签优先' }), '带标签的靠前'),
1063
- h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: draft.priorityUnassigned === true, onChange: (v) => setDraft({ ...draft, priorityUnassigned: v }), label: '未认领优先' }), '没人认领的靠前(默认关:这是我们的判断,不是规则)')), '全部关掉时按 GitHub 的「最近更新」顺序处理'),
1065
+ h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: draft.priorityUnassigned === true, onChange: (v) => setDraft({ ...draft, priorityUnassigned: v }), label: '未认领优先' }), '没人认领的靠前(默认关:这是我们的判断,不是规则)'),
1066
+ h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: draft.priorityStale === true, onChange: (v) => setDraft({ ...draft, priorityStale: v }), label: '积压优先' }), '躺了 30 天以上的靠前(默认关,只展示)')), '全部关掉时按 GitHub 的「最近更新」顺序处理'),
1064
1067
  h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: !!draft.observe, onChange: (v) => setDraft({ ...draft, observe: v }), label: '仅观察' }), '仅观察(只记录不唤醒)'),
1065
1068
  h('label', { className: 'dt-switch-row' }, h(Toggle, { checked: !!draft.isolated, onChange: (v) => setDraft({ ...draft, isolated: v }), label: '隔离执行' }), '隔离执行(每次唤醒开一次性 worktree)'),
1066
1069
  draft.isolated ? field('隔离工作目录', h(Input, { value: draft.workdir || '', placeholder: '绝对路径,留空 = 当前工作目录', onChange: (e) => setDraft({ ...draft, workdir: e.target.value }) })) : null,
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.78'
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 兜底 */ }
@@ -1222,6 +1225,7 @@ export function apply(ctx) {
1222
1225
  labels: body.priority.labels !== false,
1223
1226
  // 默认关:没有官方依据支持"无人认领更紧急"
1224
1227
  unassigned: body.priority.unassigned === true,
1228
+ stale: body.priority.stale === true,
1225
1229
  }
1226
1230
  }
1227
1231
  // 隔离执行(对标 DeepSeek DSec):每次唤醒开一次性 worktree,改副本不碰主工作区
package/lib/watch.js CHANGED
@@ -104,6 +104,8 @@ export function formatWatchText(repo, fresh, options = {}) {
104
104
  item.html_url,
105
105
  (stateReasonNote(item) && String(item.state_reason || '') === 'reopened') ? '⚠ ' + stateReasonNote(item) : null,
106
106
  assignmentNote(item) || null,
107
+ (item.state === 'open' ? stalenessNote(item) : '') || null,
108
+ linkedPrNote(item.linkedPr) || null,
107
109
  item.lastComment
108
110
  ? '最后评论: ' + commentSummaryLine({
109
111
  login: item.lastComment.self ? '' : item.lastComment.login,
@@ -260,6 +262,7 @@ export function priorityScore(item, options) {
260
262
  if (on.labels !== false && Array.isArray(item.labels) && item.labels.length > 0) score += 5
261
263
  // 默认关闭:这是产品判断而非规则,客户想用再开
262
264
  if (on.unassigned === true && assignmentNote(item) !== '') score += 3
265
+ if (on.stale === true && stalenessNote(item) !== '') score += 2
263
266
  return score
264
267
  }
265
268
 
@@ -714,7 +717,10 @@ export function buildCommentBatchQuery(count) {
714
717
  const n = Math.max(0, Math.min(10, Number(count) || 0))
715
718
  const parts = []
716
719
  for (let i = 0; i < n; i += 1) {
717
- 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 } } } } } }')
718
724
  }
719
725
  const vars = Array.from({ length: n }, (_, i) => '$n' + i + ': Int!').join(', ')
720
726
  return 'query($owner: String!, $name: String!' + (n > 0 ? ', ' + vars : '') + ') {'
@@ -738,8 +744,13 @@ export function parseCommentBatch(payload) {
738
744
  const node = Array.isArray(nodes) && nodes.length > 0 ? nodes[nodes.length - 1] : null
739
745
  if (!node) continue
740
746
  const login = node.author && node.author.login ? String(node.author.login) : ''
741
- if (!login) continue
742
- 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
+ }
743
754
  }
744
755
  return out
745
756
  }
@@ -793,5 +804,60 @@ export const TRIAGE_SIGNALS = [
793
804
  { key: 'comments', label: '有人评论', kind: 'fact', weight: 10, default: true, why: '在等回应' },
794
805
  { key: 'labels', label: '带标签', kind: 'fact', weight: 5, default: true, why: '命中过某个分类' },
795
806
  { key: 'unassigned', label: '无人认领', kind: 'judgment', weight: 3, default: false, why: '团队经验:没人认领更该看 —— 无官方依据,故默认关' },
796
- { key: 'stale', label: '长期没动静', kind: 'fact', weight: 0, default: false, why: '仅展示(由 updated_at 计算),不参与排序' },
807
+ { key: 'stale', label: '长期没动静', kind: 'fact', weight: 2, default: false, why: 'open 且超过 30 天没更新(stale bot 默认 60 天)—— 默认只展示,开启后 +2 分' },
797
808
  ]
809
+
810
+ /**
811
+ * 「躺了多久」:open 且长期没更新 —— stale bot 的世界标准是 60 天(actions/stale 默认值)。
812
+ *
813
+ * 依据:actions/stale 的 `days-before-stale` 默认 **60** 天
814
+ * (https://github.com/actions/stale#readme),社区普遍用 30/60 两档。
815
+ * 我们只**展示**,默认不参与排序(和 unassigned 一样:先给事实,判断交给用户)。
816
+ */
817
+ export function stalenessNote(item, options = {}) {
818
+ if (!item || typeof item !== 'object') return ''
819
+ const state = String(item.state || '')
820
+ if (state && state !== 'open') return ''
821
+ const stamp = item.updated_at || item.updatedAt
822
+ const at = Date.parse(stamp || '')
823
+ if (!Number.isFinite(at)) return ''
824
+ // 括号别省:Number(now) || (Date.now() - at) 会把 now 自己当成毫秒差(写错过一次)
825
+ const days = Math.floor(((Number(options.now) || Date.now()) - at) / (24 * 3600 * 1000))
826
+ if (!Number.isFinite(days) || days < 0) return ''
827
+ const threshold = Number(options.thresholdDays) || 30
828
+ if (days < threshold) return ''
829
+ return '躺了 ' + days + ' 天'
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.78",
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",