dsh-session-superagent 0.8.69 → 0.8.71
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 +38 -0
- package/MAINTENANCE.md +1 -1
- package/README.md +2 -2
- package/client.js +1 -1
- package/lib/index.js +39 -2
- package/lib/watch.js +29 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,44 @@
|
|
|
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.71] - 2026-11-02 —— 「最后一条是我发的」不能当成"有人在处理"
|
|
6
|
+
|
|
7
|
+
### 学到的(知识库第 20 条)
|
|
8
|
+
REST 用 `GET /user` 表示"我是谁"(GraphQL 叫 `viewer`)。本机实测 `gh api user --jq .login` 可用。
|
|
9
|
+
<https://docs.github.com/en/rest/users/users#get-the-authenticated-user>
|
|
10
|
+
|
|
11
|
+
### 为什么这是要命的 bug 级歧义
|
|
12
|
+
上一轮加了「最后评论: @helper 时间」。可如果最后一条**是我们自己**在上一轮留下的,
|
|
13
|
+
会话会误判成"已经有人在处理",于是什么都不做 —— **最坏的一种静默失效**。
|
|
14
|
+
|
|
15
|
+
### 改了什么
|
|
16
|
+
- 取评论时同时拿 `/user`(**缓存 10 分钟**),比较后标记 `self`;
|
|
17
|
+
- 消息里呈现 `最后评论: 我(上一轮留的) 2026-11-02T06:00:00Z`;
|
|
18
|
+
- 大小写不敏感;拿不到"我是谁"时**照常显示 @login**,不猜。
|
|
19
|
+
|
|
20
|
+
### 测试
|
|
21
|
+
- 新增 1 例(4 种情况)。合计 **124 例**。
|
|
22
|
+
|
|
23
|
+
## [0.8.70] - 2026-11-02 —— 唤醒消息补「最后是谁在说话」
|
|
24
|
+
|
|
25
|
+
### 学到的(知识库第 19 条)
|
|
26
|
+
评论是**独立资源**(issue 对象只带 `comments` 计数),要"最后一条评论是谁"必须单独取一次
|
|
27
|
+
—— 这是有成本的信息。`sort=created&direction=desc&per_page=1` 一次拿到。
|
|
28
|
+
<https://docs.github.com/en/rest/issues/comments#list-issue-comments>
|
|
29
|
+
|
|
30
|
+
### 为什么值得
|
|
31
|
+
会话被叫醒后第一件事是判断「是不是已经有人处理了」。我们原来只给 issue 作者 + 更新时间,
|
|
32
|
+
但**更新时间可能是我自己打标签引起的**,作者永远是开 issue 的人 —— 真正该看的是最后一条评论。
|
|
33
|
+
|
|
34
|
+
### 改了什么(成本受控)
|
|
35
|
+
- 只对批次**前 3 条**且 `comments > 0` 的条目取;
|
|
36
|
+
- 并发取、单条 12 秒超时;
|
|
37
|
+
- 失败**静默省略**该行,绝不阻断唤醒;
|
|
38
|
+
- 消息里呈现 `最后评论: @helper 2026-11-02T07:00:00Z`。
|
|
39
|
+
|
|
40
|
+
### 测试
|
|
41
|
+
- 新增 1 例:null / 空对象 / 只有 login / 完整信息 / 出现在消息里。合计 **123 例**。
|
|
42
|
+
|
|
5
43
|
## [0.8.69] - 2026-11-02 —— 填错仓库名时给个"是不是想填 X"
|
|
6
44
|
|
|
7
45
|
### 学到的(知识库第 18 条,实测数字)
|
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` 124/124 通过
|
|
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 # 124 项单测
|
|
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.71'
|
|
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, pickSuggestion, repoStructureNote, countReasons, filterReason, hasAckLabel, jitterMs, parseGhInclude, retryAfterMs, throttleDelayMs, inActiveHours, newestUpdatedAt, nextDelayMs, pushFiltered, normalizeFilters, partitionItems, passesFilters,
|
|
27
|
+
accessNote, classifyGhError, commentSummaryLine, 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.71'
|
|
34
34
|
export const inject = ['tools', 'agents', 'webServer']
|
|
35
35
|
|
|
36
36
|
/** 仅供测试:读写状态文件(生产代码不要用)。 */
|
|
@@ -647,6 +647,41 @@ function dirSize(path, depth) {
|
|
|
647
647
|
return total
|
|
648
648
|
}
|
|
649
649
|
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* 取一批 issue 的「最后评论」。并发跑、短超时、最多 3 条、失败静默 ——
|
|
653
|
+
* 多出来的 API 调用只在这几种条件下发生,别让它变成常态开销。
|
|
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
|
+
|
|
670
|
+
async function fetchLastComments(repo, items, maxItems = 3) {
|
|
671
|
+
const targets = (items || []).filter((item) => Number(item.comments) > 0).slice(0, maxItems)
|
|
672
|
+
if (targets.length === 0) return
|
|
673
|
+
const me = await viewerLogin()
|
|
674
|
+
await Promise.all(targets.map(async (item) => {
|
|
675
|
+
try {
|
|
676
|
+
const res = await run('gh', ['api', `repos/${repo}/issues/${item.number}/comments?per_page=1&sort=created&direction=desc`,
|
|
677
|
+
'--jq', '.[0] | {login: .user.login, at: .created_at}'], { timeoutMs: 12000, env: ghEnv() })
|
|
678
|
+
if (res.code !== 0) return
|
|
679
|
+
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()) }
|
|
681
|
+
} catch { /* 少一行信息,不阻断唤醒 */ }
|
|
682
|
+
}))
|
|
683
|
+
}
|
|
684
|
+
|
|
650
685
|
async function pollOnce(ctx, entry, baseMs) {
|
|
651
686
|
// 条件请求:带上上次的 ETag,没变化时 GitHub 回 304,且**不计入**速率限制
|
|
652
687
|
const args = ['api', '--include', `repos/${entry.repo}/issues?state=all&sort=updated&direction=desc&per_page=20`]
|
|
@@ -788,6 +823,8 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
788
823
|
|
|
789
824
|
const isolation = await prepareIsolation(entry)
|
|
790
825
|
if (isolation && isolation.dir) entry.lastWorktree = isolation.dir
|
|
826
|
+
// 批次前几条补「最后是谁在说话」(最多 3 条,失败静默)
|
|
827
|
+
await fetchLastComments(entry.repo, listed)
|
|
791
828
|
const result = wake(ctx, entry.sessionId, formatWatchText(entry.repo, listed, {
|
|
792
829
|
more: rest.length,
|
|
793
830
|
restNumbers: rest.map((item) => item.number),
|
package/lib/watch.js
CHANGED
|
@@ -102,6 +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
|
|
106
|
+
? '最后评论: ' + commentSummaryLine({
|
|
107
|
+
login: item.lastComment.self ? '' : item.lastComment.login,
|
|
108
|
+
at: item.lastComment.at,
|
|
109
|
+
}, null) + (item.lastComment.self ? '我(上一轮留的)' : '')
|
|
110
|
+
: null,
|
|
105
111
|
].filter(Boolean).join(' ')
|
|
106
112
|
return `#${item.number} [${item.state}] ${item.title} — @${who} ${tail}`
|
|
107
113
|
})
|
|
@@ -639,3 +645,26 @@ export function pickSuggestion(query, candidates) {
|
|
|
639
645
|
const contains = list.find((name) => name.toLowerCase().includes(exactName) && exactName.length >= 4)
|
|
640
646
|
return contains || null
|
|
641
647
|
}
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* 「最后是谁在说话」:一条 issue 的最后评论者与时间。
|
|
651
|
+
*
|
|
652
|
+
* 为什么要它:会话被叫醒后第一件事就是判断「是不是已经有人处理了」。
|
|
653
|
+
* 只给 issue 作者和更新时间不够 —— 更新时间可能是我自己打的标签引起的。
|
|
654
|
+
*
|
|
655
|
+
* 代价:每条 issue 一次 `GET /issues/{n}/comments`,所以只在**评论数 > 0** 且**批次前几条**里取,
|
|
656
|
+
* 失败就静默省略(宁可少一行,不要拖慢唤醒)。
|
|
657
|
+
* 出处:https://docs.github.com/en/rest/issues/comments#list-issue-comments
|
|
658
|
+
*/
|
|
659
|
+
export function commentSummaryLine(lastComment, viewer) {
|
|
660
|
+
if (!lastComment || typeof lastComment !== 'object') return ''
|
|
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) : ''
|
|
667
|
+
const when = lastComment.at ? String(lastComment.at) : ''
|
|
668
|
+
if (!who && !when) return ''
|
|
669
|
+
return [who, when].filter(Boolean).join(' ')
|
|
670
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-superagent",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.71",
|
|
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",
|