dsh-session-superagent 0.9.196 → 0.9.198

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.9.198] - 2026-11-05 —— Gitee 边界审计「值得改」三条:403 限流、404 被抢、非数组抛错
6
+
7
+ ### G1 · 线上 Gitee 限流回的是 **403**,不是 429
8
+ 真机:`curl ".../issues?per_page=9999"` → `HTTP 403` + `403 Forbidden (Rate Limit Exceeded)`,无 `Retry-After`。
9
+ 而轮询路径的 status→kind 映射把 403 一律判成 `auth` → 面板让客户**去重生成 token**,实际只要等几分钟。
10
+ 现在先看正文:含 `rate limit` / `too many` 才判限流。
11
+
12
+ ### G5 · `not found.*gh` 宽到抢走 404
13
+ `HTTP 404: Not Found for owner/ghost-repo` 会被判成 `nogh`(「请安装 gh 命令」)。判据收窄成 `gh: command not found` 这类真形状。
14
+
15
+ ### G8 · 200 但正文不是数组时抛异常
16
+ 违反 `lib/gitee.js` 自己写的「从不抛」。`normalizeGiteeList()` 两处 `for-of` 补 `Array.isArray` 守卫。
17
+
18
+ ### 未修(登记)
19
+ G2(`request()` 不读响应头)、G3(只取一页、无 `truncated`)、G4(Gitee 分支的提示措辞沿用 GitHub)、
20
+ G6(列标签失败仍盲发 POST —— 唯一会碰到**别人仓库**的路径)、G7(`permissions` 在 Gitee 仓库对象里不存在 → 恒挂「只读」徽章)。
21
+ G6 优先级最高(会往别人仓库写),下一轮先做它。
22
+
23
+ ### 证据
24
+ ```
25
+ node --test → 340/340(新增:403 限流 vs 403 权限、404 不被 nogh 抢)
26
+ ```
27
+ ## [0.9.197] - 2026-11-05 —— Gitee 边界审计:3 条必须修(全是「照抄 GitHub」的坑)
28
+
29
+ ### M1 · `merged` 不在 state 白名单里
30
+ Gitee 用 `merged` 表示「已合并的 PR」,而 `normalizeGiteeState()` 只认 `closed` / `rejected`。
31
+ 后果:**合并掉的 PR 每轮都被当成新动态**。已补。
32
+
33
+ ### M2 · 取「最后一条评论」拿到的是第一条
34
+ `fetchGiteeLastComment()` 照抄了 GitHub 的 `?per_page=1&sort=created&direction=desc` ——
35
+ Gitee 不认这两个参数,只按创建时间正序返回,于是 `per_page=1` 拿到的是**最早**那条。
36
+ 改成翻页取末条(每页 100,最多 5 页)。
37
+
38
+ ### M3 · `comments` 字段没透传
39
+ `normalizeGiteeItem()` 的字段白名单漏了 `comments` → 「有人评论 +10」这条信号在 Gitee 上**恒为 0**。
40
+ 已补(保留原始类型,没有该字段时不硬塞 0)。
41
+
42
+ ### 证据
43
+ ```
44
+ node --test → 338/338(新增:merged/rejected 归一、comments 透传)
45
+ 审核报告:docs/报告-gitee边界审计.md(3 必须修 / 8 值得改)
46
+ ```
5
47
  ## [0.9.196] - 2026-11-05 —— watch 审计「值得改」三条:定时器诈尸、字符串暂停、坏数组
6
48
 
7
49
  ### 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: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
- [![Version](https://img.shields.io/badge/version-0.9.196-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.9.198-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
 
@@ -144,7 +144,7 @@ Gitee 私有仓库要在「设置 → 凭证」填私人令牌;公开仓库不
144
144
  ## 开发
145
145
 
146
146
  ```sh
147
- node --test # 336 项单测
147
+ node --test # 340 项单测
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.196'
17
+ const CLIENT_VERSION = '0.9.198'
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|not found.*gh|gh: command not found|not recognized as an internal or external command/i.test(text)) {
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
- if (s === 'closed' || s === 'rejected') return 'closed'
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
- for (const raw of issues || []) list.push(normalizeGiteeItem(raw, { kind: 'issue' }))
61
- for (const raw of pulls || []) list.push(normalizeGiteeItem(raw, { kind: 'pull' }))
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
 
@@ -122,9 +128,17 @@ export async function fetchGiteeLastComment({ repo, token = '', item, selfLogin
122
128
  const number = item && item.number != null ? String(item.number) : ''
123
129
  if (!number) return null
124
130
  const kind = item && item.pull_request ? 'pulls' : 'issues'
125
- const res = await request(`/repos/${repo}/${kind}/${number}/comments?per_page=1&sort=created&direction=desc`, { token, fetchImpl })
126
- if (!res.ok || !Array.isArray(res.data) || res.data.length === 0) return null
127
- const last = res.data[res.data.length - 1]
131
+ // 审核 M2:Gitee **不认** `sort=created&direction=desc`(那是 GitHub 的参数),
132
+ // 以前照抄过来,`per_page=1` 拿到的是**最早**一条评论 —— 于是「最后评论」永远是第一条。
133
+ // Gitee 只按创建时间正序返回,所以翻到最后一页取末条。
134
+ let last = null
135
+ for (let page = 1; page <= 5; page += 1) {
136
+ const res = await request(`/repos/${repo}/${kind}/${number}/comments?per_page=100&page=${page}`, { token, fetchImpl })
137
+ if (!res.ok || !Array.isArray(res.data) || res.data.length === 0) break
138
+ last = res.data[res.data.length - 1]
139
+ if (res.data.length < 100) break
140
+ }
141
+ if (!last) return null
128
142
  const login = (last.user && last.user.login) || ''
129
143
  return {
130
144
  login,
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.196'
45
+ export const SERVER_VERSION = '0.9.198'
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/403 = token 问题(不会自己好);429 = 限流(会);其它按网络抖动处理
1076
- const kind = status === 401 || status === 403 ? 'auth' : status === 429 ? 'ratelimit' : status === 404 ? 'notfound' : 'network'
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 看不到这个私有仓库)'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.9.196",
3
+ "version": "0.9.198",
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",