dsh-session-superagent 0.9.183 → 0.9.184
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 +35 -0
- package/README.md +2 -2
- package/client.js +1 -1
- package/lib/gh-format.js +4 -1
- package/lib/gitee.js +57 -0
- package/lib/index.js +20 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,41 @@
|
|
|
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.184] - 2026-11-05 —— Gitee 的 ack 标签根本建不出来:半角冒号非法
|
|
6
|
+
|
|
7
|
+
### 真机发现(不是猜的)
|
|
8
|
+
给 Gitee 仓库自动建 ack 标签时,Gitee 直接回:
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
{"message":"Name只允许汉字、字母、数字或者小数点(.)、下划线(_)、中划线(-)、
|
|
12
|
+
正斜杠(/)、反斜杠(\)以及全角符号,长度必须在 2 到 20 个字符之间"}
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
我们默认的标签是 `主理鱼:已处理` —— **半角冒号不在允许集合里**,所以这个标签在 Gitee 上永远建不出来,
|
|
16
|
+
`watch_ack` 每次都 404,面板上看到的就是「需要你处理」+ 一句「没归类的错误」。
|
|
17
|
+
|
|
18
|
+
### 改法
|
|
19
|
+
- `DEFAULT_ACK_LABEL_GITEE = '主理鱼-已处理'`(连字符),`defaultAckLabel(provider)` 按 provider 选默认值
|
|
20
|
+
(轮询 / 建守 / `watch_ack` / `watch_doctor` / `watch_start` 五处);
|
|
21
|
+
- `ensureGiteeLabel()` 打标签前先确保标签存在:先 `GET /labels` 查,不存在才 `POST` 建;
|
|
22
|
+
**名字非法时先拦下并给建议**(`suggestGiteeLabel` 把冒号换成连字符),不发无谓请求;
|
|
23
|
+
- `classifyGhError()` 补 **中文 401**:`{"message":"登录失效,无权限访问该资源","code":40001}` → `auth`
|
|
24
|
+
(以前只认英文,这条会落进 `other`)。
|
|
25
|
+
|
|
26
|
+
### 真机验证
|
|
27
|
+
```
|
|
28
|
+
ensureGiteeLabel({ repo:'MYCF711/workbuddy-pro', label:'主理鱼-已处理' })
|
|
29
|
+
→ {"ok":true,"created":true,"reason":"created"} # 标签真的建出来了
|
|
30
|
+
ensureGiteeLabel({ ..., label:'主理鱼:已处理' })
|
|
31
|
+
→ {"ok":false,"reason":"invalid-name","suggestion":"主理鱼-已处理"} # 请求都没发
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### 证据
|
|
35
|
+
```
|
|
36
|
+
node --test → 301/301(新增:标签名规则 6 条断言、中文 401)
|
|
37
|
+
preflight 全量 → 37/37
|
|
38
|
+
```
|
|
39
|
+
|
|
5
40
|
## [0.9.183] - 2026-11-05 —— 门禁互斥锁 + 来源页三条文案
|
|
6
41
|
|
|
7
42
|
### ① 门禁互斥锁(本轮最重要)
|
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 # 301 项单测
|
|
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.184'
|
|
18
18
|
let BASE = '/session-superagent'
|
|
19
19
|
/**
|
|
20
20
|
* 挑「最新的那个服务端实例」。
|
package/lib/gh-format.js
CHANGED
|
@@ -86,7 +86,10 @@ export function classifyGhError(detail) {
|
|
|
86
86
|
// 标签不存在(JSON)→ {"message":"404 Not Found"} / {"message":"Not Found Project"}
|
|
87
87
|
// token 失效(JSON)→ {"message":"401 Unauthorized: Access token does not exist"}
|
|
88
88
|
// 限流 → HTTP 429(常常只有状态行,没有正文)
|
|
89
|
-
|
|
89
|
+
// Gitee 的 401 还有**中文**版本(真机 2026-11-05 实测):
|
|
90
|
+
// {"message":"登录失效,无权限访问该资源","code":40001}
|
|
91
|
+
// 只认英文会把这条放进 other,客户看到「没归类的错误」而不知道该重新登录。
|
|
92
|
+
if (/Access token does not exist|401\s+Unauthorized|登录失效|无权限访问该资源/i.test(text)) {
|
|
90
93
|
return {
|
|
91
94
|
kind: 'auth',
|
|
92
95
|
short,
|
package/lib/gitee.js
CHANGED
|
@@ -170,3 +170,60 @@ export function mapGiteeRepoAccess(repo, info = {}) {
|
|
|
170
170
|
checkedAt: new Date().toISOString(),
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* 确保 ack 标签存在(Gitee 不会像 GitHub 那样「打标签时自动建」)。
|
|
176
|
+
*
|
|
177
|
+
* 真机核对(2026-11-05):`GET /repos/{owner}/{repo}/labels` 返回 200 与标签数组,
|
|
178
|
+
* 说明标签端点族存在;不存在时 `POST .../issues/{n}/labels` 会回 HTML 404 页(不是 JSON)。
|
|
179
|
+
*
|
|
180
|
+
* 先 GET 再 POST:Gitee 对「已存在」的 POST 行为没有文档保证,先查一次能省掉一次无谓写入,
|
|
181
|
+
* 也让返回能说清「是新建的,还是本来就有」。
|
|
182
|
+
*
|
|
183
|
+
* 失败不抛:调用方(watch_ack)要能继续尝试打标签,并把真实原因带回给客户。
|
|
184
|
+
*/
|
|
185
|
+
export async function ensureGiteeLabel({ repo, token = '', label, color = 'ededed', fetchImpl } = {}) {
|
|
186
|
+
const name = String(label || '').trim()
|
|
187
|
+
if (!name) return { ok: false, error: 'label is required' }
|
|
188
|
+
// 先按 Gitee 的规则校验:名字非法时 POST 回来的是一句中文报错,客户看不懂该改什么
|
|
189
|
+
if (!isValidGiteeLabel(name)) {
|
|
190
|
+
return {
|
|
191
|
+
ok: false,
|
|
192
|
+
reason: 'invalid-name',
|
|
193
|
+
error: 'Gitee 标签名只允许汉字/字母/数字/._-/ 与全角符号,长度 2–20(半角冒号不行)',
|
|
194
|
+
suggestion: suggestGiteeLabel(name),
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const listed = await request(`/repos/${repo}/labels`, { token, fetchImpl })
|
|
198
|
+
if (listed.ok) {
|
|
199
|
+
const names = (Array.isArray(listed.data) ? listed.data : []).map((item) => String(item && item.name || ''))
|
|
200
|
+
if (names.includes(name)) return { ok: true, created: false, reason: 'already-exists' }
|
|
201
|
+
}
|
|
202
|
+
const created = await request(`/repos/${repo}/labels`, { token, method: 'POST', body: { name, color }, fetchImpl })
|
|
203
|
+
if (created.ok) return { ok: true, created: true, reason: 'created' }
|
|
204
|
+
return { ok: false, status: created.status, error: created.error, reason: 'create-failed' }
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Gitee 的标签名规则比 GitHub 严(真机 2026-11-05 实测的报错原文):
|
|
209
|
+
*
|
|
210
|
+
* 只允许汉字、字母、数字或者小数点(.)、下划线(_)、中划线(-)、正斜杠(/)、反斜杠(\)
|
|
211
|
+
* 以及全角符号,长度必须在 2 到 20 个字符之间
|
|
212
|
+
*
|
|
213
|
+
* 注意**半角冒号不在允许集合里** —— 我们默认的 `主理鱼:已处理` 在 Gitee 上根本建不出来,
|
|
214
|
+
* 于是 ack 永远 404。所以 Gitee 用连字符版本。
|
|
215
|
+
*/
|
|
216
|
+
export const DEFAULT_ACK_LABEL_GITEE = '主理鱼-已处理'
|
|
217
|
+
|
|
218
|
+
// 允许集:汉字 / 字母 / 数字 / . _ - / 与全角符号;**半角冒号不在其中**(Gitee 实测拒绝)
|
|
219
|
+
const GITEE_LABEL_RE = /^[一-龥A-Za-z0-9._/ -〿--]{2,20}$/
|
|
220
|
+
|
|
221
|
+
export function isValidGiteeLabel(name) {
|
|
222
|
+
return GITEE_LABEL_RE.test(String(name || '').trim())
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** 把 GitHub 风格的标签名换成 Gitee 能接受的(主要就是把半角冒号换成连字符)。 */
|
|
226
|
+
export function suggestGiteeLabel(name) {
|
|
227
|
+
const fixed = String(name || '').trim().split(':').join('-').slice(0, 20)
|
|
228
|
+
return isValidGiteeLabel(fixed) ? fixed : DEFAULT_ACK_LABEL_GITEE
|
|
229
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -23,7 +23,7 @@ import { zstdDecompressSync } from 'node:zlib'
|
|
|
23
23
|
|
|
24
24
|
import { redact } from './redact.js'
|
|
25
25
|
import { decodeBody } from './body.js'
|
|
26
|
-
import { listGiteeItems, fetchGiteeLastComment, addGiteeLabel, giteeWhoami, giteeRepo, mapGiteeRepoAccess } from './gitee.js'
|
|
26
|
+
import { listGiteeItems, fetchGiteeLastComment, addGiteeLabel, ensureGiteeLabel, giteeWhoami, giteeRepo, mapGiteeRepoAccess, DEFAULT_ACK_LABEL_GITEE } from './gitee.js'
|
|
27
27
|
import {
|
|
28
28
|
advanceSeen, applyWatcherAction, batchFresh, decideWake, DEFAULT_ACK_LABEL, formatWatchText,
|
|
29
29
|
parseRepoSpec, markGiteeReopened,
|
|
@@ -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.184'
|
|
46
46
|
export const inject = ['tools', 'agents', 'webServer']
|
|
47
47
|
/** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
|
|
48
48
|
// 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
|
|
@@ -578,6 +578,11 @@ function run(file, args, options = {}) {
|
|
|
578
578
|
})
|
|
579
579
|
}
|
|
580
580
|
|
|
581
|
+
/** 默认 ack 标签按 provider 走:Gitee 的标签名不允许半角冒号(真机实测拒建)。 */
|
|
582
|
+
function defaultAckLabel(provider) {
|
|
583
|
+
return provider === 'gitee' ? DEFAULT_ACK_LABEL_GITEE : DEFAULT_ACK_LABEL
|
|
584
|
+
}
|
|
585
|
+
|
|
581
586
|
function defineTool(options) {
|
|
582
587
|
const properties = {}
|
|
583
588
|
const required = []
|
|
@@ -1170,7 +1175,7 @@ async function pollWithItems(ctx, entry, baseMs, parsed) {
|
|
|
1170
1175
|
// 触发要有许可:过滤器不通过的条目根本不进候选集,也不写 seen 水位
|
|
1171
1176
|
// 记忆要有遗忘:seen 只增不减会问成几 MB 的字典
|
|
1172
1177
|
entry.seen = pruneSeen(entry.seen)
|
|
1173
|
-
const ackLabel = entry.ackLabel ||
|
|
1178
|
+
const ackLabel = entry.ackLabel || defaultAckLabel(entry.provider)
|
|
1174
1179
|
// 幂等痕迹留在 GitHub 上:带 ack 标签的条目直接跳过(换机器、删状态都不会重报)
|
|
1175
1180
|
const considered = []
|
|
1176
1181
|
// 每轮重置:这行要被读成「本轮跳过多少」,累计值会越滚越大、误导客户
|
|
@@ -1777,7 +1782,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
1777
1782
|
id, repo, provider, sessionId, cursor: null, seen: {}, lastReported: {},
|
|
1778
1783
|
cooldownMs: 180000, createdAt: new Date().toISOString(),
|
|
1779
1784
|
filters: normalizeFilters(), batchLimit: 5, maxWakesPerHour: 6,
|
|
1780
|
-
wakeTimes: [], consecutiveFailures: 0, ackLabel:
|
|
1785
|
+
wakeTimes: [], consecutiveFailures: 0, ackLabel: defaultAckLabel(provider),
|
|
1781
1786
|
isolated: false, workdir: null,
|
|
1782
1787
|
}
|
|
1783
1788
|
entry.provider = provider
|
|
@@ -2109,7 +2114,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2109
2114
|
? watchers.find((w) => w && w.repo === String(args.repo))
|
|
2110
2115
|
: watchers.find((w) => w && w.enabled)
|
|
2111
2116
|
if (!entry) return '[error: no watcher for that repo — start one with watch_start first]'
|
|
2112
|
-
const label = String(args.label || entry.ackLabel ||
|
|
2117
|
+
const label = String(args.label || entry.ackLabel || defaultAckLabel(entry.provider))
|
|
2113
2118
|
// GitHub 不会因为加标签而自动建标签:不存在时返回 422。先幂等建一次(已存在也返回 422,忽略)。
|
|
2114
2119
|
// Gitee 没有「建标签」的独立端点(标签必须先存在),所以这边只打标签;
|
|
2115
2120
|
// 标签不存在时它会 404 —— 让调用方看到真实原因,别假装成功。
|
|
@@ -2118,6 +2123,13 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2118
2123
|
}
|
|
2119
2124
|
const results = []
|
|
2120
2125
|
let failed = null
|
|
2126
|
+
let labelNote = ''
|
|
2127
|
+
// Gitee 打标签前要先确保标签存在(它不会像 GitHub 那样自动建)
|
|
2128
|
+
if (entry.provider === 'gitee') {
|
|
2129
|
+
const ensured = await ensureGiteeLabel({ repo: entry.repo, token: String(readSecrets().giteeToken || ''), label })
|
|
2130
|
+
if (ensured.ok) labelNote = ensured.created ? '(已自动新建标签「' + label + '」)' : ''
|
|
2131
|
+
else labelNote = '(标签「' + label + '」建不出来:' + String(ensured.error || ensured.status || '').slice(0, 80) + ')'
|
|
2132
|
+
}
|
|
2121
2133
|
for (const number of numbers) {
|
|
2122
2134
|
const res = entry.provider === 'gitee'
|
|
2123
2135
|
? await (async () => {
|
|
@@ -2167,7 +2179,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2167
2179
|
if (args && args.format === 'json') {
|
|
2168
2180
|
return JSON.stringify({ schemaVersion: 1, ok: true, repo: entry.repo, label, acked: results, at: nowIso })
|
|
2169
2181
|
}
|
|
2170
|
-
|
|
2182
|
+
return `acked ${entry.repo} #${results.join(' #')} with label "${label}"` + labelNote
|
|
2171
2183
|
},
|
|
2172
2184
|
}))
|
|
2173
2185
|
|
|
@@ -2352,7 +2364,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2352
2364
|
}
|
|
2353
2365
|
}
|
|
2354
2366
|
// 3. ack 标签是否存在(两家都要看:Gitee 不会自动建标签,更要说清楚)
|
|
2355
|
-
const label = entry.ackLabel ||
|
|
2367
|
+
const label = entry.ackLabel || defaultAckLabel(entry.provider)
|
|
2356
2368
|
if (isGitee) {
|
|
2357
2369
|
// Gitee 没有「建标签」端点,watch_ack 也不会替它建(GitHub 会)——
|
|
2358
2370
|
// 所以这里只能交代规则,不能假装探测过。
|
|
@@ -2508,7 +2520,7 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2508
2520
|
id, repo, provider, sessionId,
|
|
2509
2521
|
intervalSec: 60,
|
|
2510
2522
|
cooldownMs: DEFAULT_COOLDOWN_MS,
|
|
2511
|
-
ackLabel:
|
|
2523
|
+
ackLabel: defaultAckLabel(provider),
|
|
2512
2524
|
cursor: null,
|
|
2513
2525
|
seen: {},
|
|
2514
2526
|
lastReported: {},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-superagent",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.184",
|
|
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",
|