dsh-session-superagent 0.9.196 → 0.9.199
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 +66 -0
- package/README.md +2 -2
- package/client.js +1 -1
- package/lib/gh-format.js +1 -1
- package/lib/gitee.js +43 -8
- package/lib/index.js +15 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,72 @@
|
|
|
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.9.199] - 2026-11-05 —— Gitee 边界审计剩余三条(其中最危险的会往**别人仓库**写)
|
|
6
|
+
|
|
7
|
+
### G6 · 列标签失败仍盲发 POST —— 唯一会碰别人仓库的路径
|
|
8
|
+
`ensureGiteeLabel()` 先 `GET /labels` 查重,再 `POST` 建。但**查失败时它也照发**:
|
|
9
|
+
读不到现有标签就建 —— 等于在**别人仓库**里造重复标签。现在读失败就老实回报 `list-failed`。
|
|
10
|
+
实测:403 时 POST 次数 = **0**。
|
|
11
|
+
|
|
12
|
+
### G7 · 每条 Gitee 守都恒挂「只读」徽章
|
|
13
|
+
`mapGiteeRepoAccess()` 读 `permissions.push`,而 Gitee 的仓库对象里**根本没有** `permissions` 字段(67 个键都没有它)。
|
|
14
|
+
`undefined === true` 恒 false → 每条 Gitee 守都显示「只读」+「你只有读权限」假警告。
|
|
15
|
+
改成「字段不存在 → `push: null`(不知道)」,面板按 `=== false` 才提示只读。
|
|
16
|
+
|
|
17
|
+
### G3 · 只取一页,截断的部分静默消失
|
|
18
|
+
`listGiteeItems()` 只读一页且不告诉调用方「满了」。停机恢复/首次轮询时最危险:
|
|
19
|
+
**攒了 30 条只看到 20 条,另外 10 条永远不再出现**(`cursor` 还会推进过去)。
|
|
20
|
+
现在回 `truncated: true`,轮询路径**这一轮不推进水位**并留一条事件。
|
|
21
|
+
|
|
22
|
+
### 证据
|
|
23
|
+
```
|
|
24
|
+
node --test → 343/343(新增:盲发 POST 守卫、permissions 缺失、truncated 三条)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### 仍未修(登记)
|
|
28
|
+
G2(`request()` 不读响应头)、G4(Gitee 分支沿用 GitHub 措辞)。
|
|
29
|
+
## [0.9.198] - 2026-11-05 —— Gitee 边界审计「值得改」三条:403 限流、404 被抢、非数组抛错
|
|
30
|
+
|
|
31
|
+
### G1 · 线上 Gitee 限流回的是 **403**,不是 429
|
|
32
|
+
真机:`curl ".../issues?per_page=9999"` → `HTTP 403` + `403 Forbidden (Rate Limit Exceeded)`,无 `Retry-After`。
|
|
33
|
+
而轮询路径的 status→kind 映射把 403 一律判成 `auth` → 面板让客户**去重生成 token**,实际只要等几分钟。
|
|
34
|
+
现在先看正文:含 `rate limit` / `too many` 才判限流。
|
|
35
|
+
|
|
36
|
+
### G5 · `not found.*gh` 宽到抢走 404
|
|
37
|
+
`HTTP 404: Not Found for owner/ghost-repo` 会被判成 `nogh`(「请安装 gh 命令」)。判据收窄成 `gh: command not found` 这类真形状。
|
|
38
|
+
|
|
39
|
+
### G8 · 200 但正文不是数组时抛异常
|
|
40
|
+
违反 `lib/gitee.js` 自己写的「从不抛」。`normalizeGiteeList()` 两处 `for-of` 补 `Array.isArray` 守卫。
|
|
41
|
+
|
|
42
|
+
### 未修(登记)
|
|
43
|
+
G2(`request()` 不读响应头)、G3(只取一页、无 `truncated`)、G4(Gitee 分支的提示措辞沿用 GitHub)、
|
|
44
|
+
G6(列标签失败仍盲发 POST —— 唯一会碰到**别人仓库**的路径)、G7(`permissions` 在 Gitee 仓库对象里不存在 → 恒挂「只读」徽章)。
|
|
45
|
+
G6 优先级最高(会往别人仓库写),下一轮先做它。
|
|
46
|
+
|
|
47
|
+
### 证据
|
|
48
|
+
```
|
|
49
|
+
node --test → 340/340(新增:403 限流 vs 403 权限、404 不被 nogh 抢)
|
|
50
|
+
```
|
|
51
|
+
## [0.9.197] - 2026-11-05 —— Gitee 边界审计:3 条必须修(全是「照抄 GitHub」的坑)
|
|
52
|
+
|
|
53
|
+
### M1 · `merged` 不在 state 白名单里
|
|
54
|
+
Gitee 用 `merged` 表示「已合并的 PR」,而 `normalizeGiteeState()` 只认 `closed` / `rejected`。
|
|
55
|
+
后果:**合并掉的 PR 每轮都被当成新动态**。已补。
|
|
56
|
+
|
|
57
|
+
### M2 · 取「最后一条评论」拿到的是第一条
|
|
58
|
+
`fetchGiteeLastComment()` 照抄了 GitHub 的 `?per_page=1&sort=created&direction=desc` ——
|
|
59
|
+
Gitee 不认这两个参数,只按创建时间正序返回,于是 `per_page=1` 拿到的是**最早**那条。
|
|
60
|
+
改成翻页取末条(每页 100,最多 5 页)。
|
|
61
|
+
|
|
62
|
+
### M3 · `comments` 字段没透传
|
|
63
|
+
`normalizeGiteeItem()` 的字段白名单漏了 `comments` → 「有人评论 +10」这条信号在 Gitee 上**恒为 0**。
|
|
64
|
+
已补(保留原始类型,没有该字段时不硬塞 0)。
|
|
65
|
+
|
|
66
|
+
### 证据
|
|
67
|
+
```
|
|
68
|
+
node --test → 338/338(新增:merged/rejected 归一、comments 透传)
|
|
69
|
+
审核报告:docs/报告-gitee边界审计.md(3 必须修 / 8 值得改)
|
|
70
|
+
```
|
|
5
71
|
## [0.9.196] - 2026-11-05 —— watch 审计「值得改」三条:定时器诈尸、字符串暂停、坏数组
|
|
6
72
|
|
|
7
73
|
### W1 · 首轮的错峰定时器不能取消
|
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
|
|
|
@@ -144,7 +144,7 @@ Gitee 私有仓库要在「设置 → 凭证」填私人令牌;公开仓库不
|
|
|
144
144
|
## 开发
|
|
145
145
|
|
|
146
146
|
```sh
|
|
147
|
-
node --test #
|
|
147
|
+
node --test # 343 项单测
|
|
148
148
|
```
|
|
149
149
|
|
|
150
150
|
### 工具输出:文本给人和 agent,JSON 给程序
|
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.9.
|
|
17
|
+
const CLIENT_VERSION = '0.9.199'
|
|
18
18
|
let BASE = '/session-superagent'
|
|
19
19
|
/**
|
|
20
20
|
* 挑「最新的那个服务端实例」。
|
package/lib/gh-format.js
CHANGED
|
@@ -141,7 +141,7 @@ export function classifyGhError(detail) {
|
|
|
141
141
|
}
|
|
142
142
|
// Windows 的 cmd 报法不一样:'gh' is not recognized as an internal or external command
|
|
143
143
|
// 出处(Node 的错误码语义):https://nodejs.org/api/errors.html#common-system-errors
|
|
144
|
-
if (/ENOENT|
|
|
144
|
+
if (/ENOENT|gh: command not found|not recognized as an internal or external command/i.test(text)) {
|
|
145
145
|
return { kind: 'nogh', short, hint: '(找不到 gh 命令:确认已安装且在 PATH)' }
|
|
146
146
|
}
|
|
147
147
|
// 条件请求命中:gh 把 304 当失败(非 2xx 就 exit 1),但语义是「没有变化」,不是错误
|
package/lib/gitee.js
CHANGED
|
@@ -16,7 +16,9 @@ export const GITEE_API = 'https://gitee.com/api/v5'
|
|
|
16
16
|
/** Gitee 的 state → 我们内部沿用的 GitHub 口径。 */
|
|
17
17
|
export function normalizeGiteeState(raw) {
|
|
18
18
|
const s = String(raw || '').toLowerCase()
|
|
19
|
-
|
|
19
|
+
// 审核 M1:Gitee 用 `merged` 表示「已合并的 PR」,漏了它,合并掉的 PR 会一直被当成「开着」,
|
|
20
|
+
// 每轮都被算成新动态。`rejected`(关闭且不修)同理。
|
|
21
|
+
if (s === 'closed' || s === 'rejected' || s === 'merged') return 'closed'
|
|
20
22
|
return 'open'
|
|
21
23
|
}
|
|
22
24
|
|
|
@@ -48,6 +50,9 @@ export function normalizeGiteeItem(raw, { kind = 'issue' } = {}) {
|
|
|
48
50
|
created_at: item.created_at || null,
|
|
49
51
|
updated_at: item.updated_at || null,
|
|
50
52
|
}
|
|
53
|
+
// 审核 M3:`comments` 漏了 → 「有人评论 +10」这条信号在 Gitee 上恒为 0。
|
|
54
|
+
// 保留原始类型(数字就是数字),下游按 `> 0` 判。
|
|
55
|
+
if (item.comments !== undefined && item.comments !== null) out.comments = Number(item.comments) || 0
|
|
51
56
|
if (isPr) {
|
|
52
57
|
out.pull_request = { url: out.html_url }
|
|
53
58
|
out.draft = String(item.state || '').toLowerCase() === 'draft'
|
|
@@ -57,8 +62,9 @@ export function normalizeGiteeItem(raw, { kind = 'issue' } = {}) {
|
|
|
57
62
|
|
|
58
63
|
export function normalizeGiteeList(issues, pulls) {
|
|
59
64
|
const list = []
|
|
60
|
-
|
|
61
|
-
for (const raw of
|
|
65
|
+
// 200 但正文不是数组时以前会抛 TypeError,违反本文件「从不抛」的约定(审核 G8)
|
|
66
|
+
for (const raw of (Array.isArray(issues) ? issues : [])) list.push(normalizeGiteeItem(raw, { kind: 'issue' }))
|
|
67
|
+
for (const raw of (Array.isArray(pulls) ? pulls : [])) list.push(normalizeGiteeItem(raw, { kind: 'pull' }))
|
|
62
68
|
return list.sort((a, b) => String(b.updated_at || '').localeCompare(String(a.updated_at || '')))
|
|
63
69
|
}
|
|
64
70
|
|
|
@@ -100,7 +106,8 @@ export async function listGiteeItems({ repo, token = '', perPage = 20, since = '
|
|
|
100
106
|
// 真机验证:since 传给未来时间 → 返回 [];传今天 → 只返回今天之后更新的。
|
|
101
107
|
// 两个端点都支持,缺了它就只能每轮全量读。
|
|
102
108
|
const sinceQ = since ? '&since=' + encodeURIComponent(String(since)) : ''
|
|
103
|
-
const
|
|
109
|
+
const size = Math.max(1, Math.min(100, Number(perPage) || 20))
|
|
110
|
+
const q = 'state=all&sort=updated&direction=desc&per_page=' + size + sinceQ
|
|
104
111
|
const [issues, pulls] = await Promise.all([
|
|
105
112
|
request(`/repos/${repo}/issues?${q}`, { token, fetchImpl }),
|
|
106
113
|
request(`/repos/${repo}/pulls?${q}`, { token, fetchImpl }),
|
|
@@ -108,11 +115,16 @@ export async function listGiteeItems({ repo, token = '', perPage = 20, since = '
|
|
|
108
115
|
if (!issues.ok && !pulls.ok) {
|
|
109
116
|
return { ok: false, status: issues.status || pulls.status, error: issues.error || pulls.error }
|
|
110
117
|
}
|
|
118
|
+
// 审核 G3:只取一页时,超出的部分会**静默消失**,而 cursor 还会推进过去 ——
|
|
119
|
+
// 停机恢复/首次轮询时最危险(攒了 30 条只看到 20 条,另外 10 条永远不再出现)。
|
|
120
|
+
// 这里如实告诉调用方「满了,可能被截断」,由它决定是否推迟推进水位。
|
|
121
|
+
const truncated = [issues, pulls].some((res) => res.ok && Array.isArray(res.data) && res.data.length >= size)
|
|
111
122
|
return {
|
|
112
123
|
ok: true,
|
|
113
124
|
items: normalizeGiteeList(issues.ok ? issues.data : [], pulls.ok ? pulls.data : []),
|
|
114
125
|
// 一半成功也要说清楚:否则客户以为 PR 一条都没有
|
|
115
126
|
partial: !issues.ok || !pulls.ok ? (issues.ok ? 'pulls' : 'issues') : null,
|
|
127
|
+
truncated,
|
|
116
128
|
}
|
|
117
129
|
}
|
|
118
130
|
|
|
@@ -122,9 +134,17 @@ export async function fetchGiteeLastComment({ repo, token = '', item, selfLogin
|
|
|
122
134
|
const number = item && item.number != null ? String(item.number) : ''
|
|
123
135
|
if (!number) return null
|
|
124
136
|
const kind = item && item.pull_request ? 'pulls' : 'issues'
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
137
|
+
// 审核 M2:Gitee **不认** `sort=created&direction=desc`(那是 GitHub 的参数),
|
|
138
|
+
// 以前照抄过来,`per_page=1` 拿到的是**最早**一条评论 —— 于是「最后评论」永远是第一条。
|
|
139
|
+
// Gitee 只按创建时间正序返回,所以翻到最后一页取末条。
|
|
140
|
+
let last = null
|
|
141
|
+
for (let page = 1; page <= 5; page += 1) {
|
|
142
|
+
const res = await request(`/repos/${repo}/${kind}/${number}/comments?per_page=100&page=${page}`, { token, fetchImpl })
|
|
143
|
+
if (!res.ok || !Array.isArray(res.data) || res.data.length === 0) break
|
|
144
|
+
last = res.data[res.data.length - 1]
|
|
145
|
+
if (res.data.length < 100) break
|
|
146
|
+
}
|
|
147
|
+
if (!last) return null
|
|
128
148
|
const login = (last.user && last.user.login) || ''
|
|
129
149
|
return {
|
|
130
150
|
login,
|
|
@@ -158,9 +178,14 @@ export async function giteeRepo({ repo, token = '', fetchImpl } = {}) {
|
|
|
158
178
|
*/
|
|
159
179
|
export function mapGiteeRepoAccess(repo, info = {}) {
|
|
160
180
|
const perms = info.permissions || {}
|
|
181
|
+
// 审核 G7:Gitee 的仓库对象里**没有** `permissions` 字段(67 个键都没有它)。
|
|
182
|
+
// 以前 `perms.push === true` 恒 false → 每条 Gitee 守都恒挂「只读」徽章 + 「你只有读权限」假警告。
|
|
183
|
+
// 没有这个字段时 `push` 应该是 `null`(不知道),不是 `false`(只读)——
|
|
184
|
+
// 调用方按 `=== false` 才提示只读。
|
|
185
|
+
const known = info.permissions && typeof info.permissions === 'object'
|
|
161
186
|
return {
|
|
162
187
|
repo,
|
|
163
|
-
push: perms.push === true || perms.admin === true,
|
|
188
|
+
push: known ? (perms.push === true || perms.admin === true) : null,
|
|
164
189
|
private: info.private === true,
|
|
165
190
|
fork: Boolean(info.parent) || info.fork === true,
|
|
166
191
|
hasIssues: info.has_issues !== false,
|
|
@@ -207,6 +232,16 @@ export async function ensureGiteeLabel({ repo, token = '', label, color = 'edede
|
|
|
207
232
|
if (listed.ok) {
|
|
208
233
|
const names = (Array.isArray(listed.data) ? listed.data : []).map((item) => String(item && item.name || ''))
|
|
209
234
|
if (names.includes(name)) return { ok: true, created: false, reason: 'already-exists' }
|
|
235
|
+
} else {
|
|
236
|
+
// 审核 G6:**列标签失败时不许盲发 POST**。
|
|
237
|
+
// 这是唯一会往「别人仓库」写的路径 —— 读不到现有标签就去建,等于在别人仓库里造重复标签。
|
|
238
|
+
// 读失败就老实回报失败,让客户知道是「查不到」而不是「没有」。
|
|
239
|
+
return {
|
|
240
|
+
ok: false,
|
|
241
|
+
reason: 'list-failed',
|
|
242
|
+
status: listed.status,
|
|
243
|
+
error: '查不到现有标签(HTTP ' + (listed.status || '?') + '):' + String(listed.error || '').slice(0, 120),
|
|
244
|
+
}
|
|
210
245
|
}
|
|
211
246
|
const created = await request(`/repos/${repo}/labels`, { token, method: 'POST', body: { name, color }, fetchImpl })
|
|
212
247
|
if (created.ok) return { ok: true, created: true, reason: 'created' }
|
package/lib/index.js
CHANGED
|
@@ -42,7 +42,7 @@ import {
|
|
|
42
42
|
|
|
43
43
|
export const name = 'dsh-session-superagent'
|
|
44
44
|
/** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
|
|
45
|
-
export const SERVER_VERSION = '0.9.
|
|
45
|
+
export const SERVER_VERSION = '0.9.199'
|
|
46
46
|
export const inject = ['tools', 'agents', 'webServer']
|
|
47
47
|
/** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
|
|
48
48
|
// 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
|
|
@@ -1072,8 +1072,12 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
1072
1072
|
entry.lastPoll = new Date().toISOString()
|
|
1073
1073
|
if (!listed.ok) {
|
|
1074
1074
|
const status = Number(listed.status) || 0
|
|
1075
|
-
// 401
|
|
1076
|
-
|
|
1075
|
+
// 401 = token 问题(不会自己好);**403 要先看正文**:Gitee 的限流回的就是 403
|
|
1076
|
+
// `403 Forbidden (Rate Limit Exceeded)`,判成 auth 会让客户去重生成 token,实际只要等(审核 G1)。
|
|
1077
|
+
const rateLimited = status === 403 && /rate limit|too many/i.test(String(listed.error || ''))
|
|
1078
|
+
const kind = status === 401 || (status === 403 && !rateLimited) ? 'auth'
|
|
1079
|
+
: rateLimited || status === 429 ? 'ratelimit'
|
|
1080
|
+
: status === 404 ? 'notfound' : 'network'
|
|
1077
1081
|
const hint = kind === 'auth' ? '(Gitee token 无效或没权限:在设置里填 Gitee 私人令牌)'
|
|
1078
1082
|
: kind === 'ratelimit' ? '(被 Gitee 限流:下一轮再试)'
|
|
1079
1083
|
: kind === 'notfound' ? '(Gitee 仓库不存在,或 token 看不到这个私有仓库)'
|
|
@@ -1093,6 +1097,14 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
1093
1097
|
}
|
|
1094
1098
|
// 一半成功(issue 拿到、PR 没拿到)要说出来,否则客户以为 PR 一条都没有
|
|
1095
1099
|
if (listed.partial) noteEvent(entry, 'partial', 'Gitee ' + (listed.partial === 'pulls' ? 'PR' : 'issue') + ' 列表这一轮没拿到')
|
|
1100
|
+
// 审核 G3:一页满了 = 可能被截断。这一轮**不推进水位**,否则被截掉的那些永远不再出现
|
|
1101
|
+
// (停机恢复/首次轮询时最危险:攒了 30 条只看到 20 条,另外 10 条静默丢掉)。
|
|
1102
|
+
if (listed.truncated) {
|
|
1103
|
+
noteEvent(entry, 'partial', 'Gitee 列表满了一页(可能被截断):这一轮不推进水位,下一轮接着读')
|
|
1104
|
+
entry.lastDeferred = 'Gitee 列表可能被截断,水位先不动'
|
|
1105
|
+
entry.deferReason = 'truncated'
|
|
1106
|
+
return
|
|
1107
|
+
}
|
|
1096
1108
|
const items = listed.items || []
|
|
1097
1109
|
if (items.length === 0) {
|
|
1098
1110
|
entry.lastError = null
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-superagent",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.199",
|
|
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",
|