dsh-session-superagent 0.8.70 → 0.8.72
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 +41 -0
- package/MAINTENANCE.md +1 -1
- package/README.md +2 -2
- package/client.js +1 -1
- package/lib/index.js +44 -3
- package/lib/watch.js +54 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,47 @@
|
|
|
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.72] - 2026-11-02 —— 取「最后评论」改成一次 GraphQL 批量
|
|
6
|
+
|
|
7
|
+
### 学到的(知识库第 21 条)
|
|
8
|
+
GraphQL 可以在同一请求里用别名查多个对象 —— 3 条 issue 的最后评论,从 **3 次 REST + 1 次 `/user`**
|
|
9
|
+
变成 **1 次请求**。
|
|
10
|
+
<https://docs.github.com/en/graphql>
|
|
11
|
+
|
|
12
|
+
### 本机实测
|
|
13
|
+
```
|
|
14
|
+
批量 GraphQL: 671ms,命中 2/3 条(第 3 条作者已注销)
|
|
15
|
+
逐条 REST : 1443ms(3 次调用)
|
|
16
|
+
```
|
|
17
|
+
→ 耗时约 **1/2.1**,调用次数 **3 → 1**。
|
|
18
|
+
|
|
19
|
+
### 两个坑(都处理了)
|
|
20
|
+
1. **`gh api graphql` 有 `errors` 时退出码是 1,但 `stdout` 的 `data` 仍然完整** ——
|
|
21
|
+
必须先解析 stdout,不能因退出码非 0 就整批放弃(否则只要有一条 issue 不存在就白跑)。
|
|
22
|
+
用例专门造了 `i1: null` + `errors` 的形态锁这个行为。
|
|
23
|
+
2. 保留**逐条 REST 兜底**(GraphQL 不可用时仍能工作)。
|
|
24
|
+
|
|
25
|
+
### 测试
|
|
26
|
+
- 新增 1 例。合计 **125 例**。
|
|
27
|
+
|
|
28
|
+
## [0.8.71] - 2026-11-02 —— 「最后一条是我发的」不能当成"有人在处理"
|
|
29
|
+
|
|
30
|
+
### 学到的(知识库第 20 条)
|
|
31
|
+
REST 用 `GET /user` 表示"我是谁"(GraphQL 叫 `viewer`)。本机实测 `gh api user --jq .login` 可用。
|
|
32
|
+
<https://docs.github.com/en/rest/users/users#get-the-authenticated-user>
|
|
33
|
+
|
|
34
|
+
### 为什么这是要命的 bug 级歧义
|
|
35
|
+
上一轮加了「最后评论: @helper 时间」。可如果最后一条**是我们自己**在上一轮留下的,
|
|
36
|
+
会话会误判成"已经有人在处理",于是什么都不做 —— **最坏的一种静默失效**。
|
|
37
|
+
|
|
38
|
+
### 改了什么
|
|
39
|
+
- 取评论时同时拿 `/user`(**缓存 10 分钟**),比较后标记 `self`;
|
|
40
|
+
- 消息里呈现 `最后评论: 我(上一轮留的) 2026-11-02T06:00:00Z`;
|
|
41
|
+
- 大小写不敏感;拿不到"我是谁"时**照常显示 @login**,不猜。
|
|
42
|
+
|
|
43
|
+
### 测试
|
|
44
|
+
- 新增 1 例(4 种情况)。合计 **124 例**。
|
|
45
|
+
|
|
5
46
|
## [0.8.70] - 2026-11-02 —— 唤醒消息补「最后是谁在说话」
|
|
6
47
|
|
|
7
48
|
### 学到的(知识库第 19 条)
|
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`
|
|
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)
|
|
6
|
-
[](https://github.com/MYCF711/dsh-session-superagent/releases)
|
|
7
7
|
[](https://www.npmjs.com/package/dsh-session-superagent)
|
|
8
8
|
[](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 #
|
|
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.
|
|
17
|
+
const CLIENT_VERSION = '0.8.72'
|
|
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.
|
|
33
|
+
export const SERVER_VERSION = '0.8.72'
|
|
34
34
|
export const inject = ['tools', 'agents', 'webServer']
|
|
35
35
|
|
|
36
36
|
/** 仅供测试:读写状态文件(生产代码不要用)。 */
|
|
@@ -652,16 +652,57 @@ function dirSize(path, depth) {
|
|
|
652
652
|
* 取一批 issue 的「最后评论」。并发跑、短超时、最多 3 条、失败静默 ——
|
|
653
653
|
* 多出来的 API 调用只在这几种条件下发生,别让它变成常态开销。
|
|
654
654
|
*/
|
|
655
|
+
|
|
656
|
+
/** 当前 token 对应的账号(判断"最后一条评论是不是我们自己发的")。缓存 10 分钟。 */
|
|
657
|
+
let viewerCache = { at: 0, login: null }
|
|
658
|
+
async function viewerLogin() {
|
|
659
|
+
if (viewerCache.login && Date.now() - viewerCache.at < 10 * 60 * 1000) return viewerCache.login
|
|
660
|
+
try {
|
|
661
|
+
const res = await run('gh', ['api', 'user', '--jq', '.login'], { timeoutMs: 12000, env: ghEnv() })
|
|
662
|
+
if (res.code === 0) {
|
|
663
|
+
const login = String(res.stdout || '').trim()
|
|
664
|
+
if (login) { viewerCache = { at: Date.now(), login }; return login }
|
|
665
|
+
}
|
|
666
|
+
} catch {}
|
|
667
|
+
return viewerCache.login
|
|
668
|
+
}
|
|
669
|
+
|
|
655
670
|
async function fetchLastComments(repo, items, maxItems = 3) {
|
|
656
671
|
const targets = (items || []).filter((item) => Number(item.comments) > 0).slice(0, maxItems)
|
|
657
672
|
if (targets.length === 0) return
|
|
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 不可用时仍要能工作)
|
|
658
699
|
await Promise.all(targets.map(async (item) => {
|
|
659
700
|
try {
|
|
660
701
|
const res = await run('gh', ['api', `repos/${repo}/issues/${item.number}/comments?per_page=1&sort=created&direction=desc`,
|
|
661
702
|
'--jq', '.[0] | {login: .user.login, at: .created_at}'], { timeoutMs: 12000, env: ghEnv() })
|
|
662
703
|
if (res.code !== 0) return
|
|
663
704
|
const parsed = JSON.parse(res.stdout)
|
|
664
|
-
if (parsed && parsed.login) item
|
|
705
|
+
if (parsed && parsed.login) mark(item, { login: parsed.login, at: parsed.at })
|
|
665
706
|
} catch { /* 少一行信息,不阻断唤醒 */ }
|
|
666
707
|
}))
|
|
667
708
|
}
|
package/lib/watch.js
CHANGED
|
@@ -102,7 +102,12 @@ export function formatWatchText(repo, fresh, options = {}) {
|
|
|
102
102
|
labels.length > 0 ? `标签: ${labels.join(', ')}` : null,
|
|
103
103
|
(item.assignees ?? []).length > 0 ? `指派: ${item.assignees.map((a) => '@' + a.login).join(' ')}` : null,
|
|
104
104
|
item.html_url,
|
|
105
|
-
item.lastComment
|
|
105
|
+
item.lastComment
|
|
106
|
+
? '最后评论: ' + commentSummaryLine({
|
|
107
|
+
login: item.lastComment.self ? '' : item.lastComment.login,
|
|
108
|
+
at: item.lastComment.at,
|
|
109
|
+
}, null) + (item.lastComment.self ? '我(上一轮留的)' : '')
|
|
110
|
+
: null,
|
|
106
111
|
].filter(Boolean).join(' ')
|
|
107
112
|
return `#${item.number} [${item.state}] ${item.title} — @${who} ${tail}`
|
|
108
113
|
})
|
|
@@ -651,10 +656,56 @@ export function pickSuggestion(query, candidates) {
|
|
|
651
656
|
* 失败就静默省略(宁可少一行,不要拖慢唤醒)。
|
|
652
657
|
* 出处:https://docs.github.com/en/rest/issues/comments#list-issue-comments
|
|
653
658
|
*/
|
|
654
|
-
export function commentSummaryLine(lastComment) {
|
|
659
|
+
export function commentSummaryLine(lastComment, viewer) {
|
|
655
660
|
if (!lastComment || typeof lastComment !== 'object') return ''
|
|
656
|
-
const
|
|
661
|
+
const login = lastComment.login ? String(lastComment.login) : ''
|
|
662
|
+
// 最后一条是"我们自己"发的,意义完全不同:那不是"有人在处理",而是上一轮留下的痕迹。
|
|
663
|
+
// 依据:GET /user 返回当前 token 对应的账号(本机实测:`gh api user --jq .login` → 我们的账号名)。
|
|
664
|
+
// 出处:https://docs.github.com/en/rest/users/users#get-the-authenticated-user
|
|
665
|
+
const isSelf = Boolean(login && viewer && login.toLowerCase() === String(viewer).toLowerCase())
|
|
666
|
+
const who = login ? (isSelf ? '我(上一轮留的)' : '@' + login) : ''
|
|
657
667
|
const when = lastComment.at ? String(lastComment.at) : ''
|
|
658
668
|
if (!who && !when) return ''
|
|
659
669
|
return [who, when].filter(Boolean).join(' ')
|
|
660
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.
|
|
3
|
+
"version": "0.8.72",
|
|
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",
|