dsh-session-superagent 0.9.179 → 0.9.180
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 +37 -0
- package/README.md +2 -2
- package/client.js +1 -1
- package/lib/gitee.js +22 -0
- package/lib/index.js +117 -50
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,43 @@
|
|
|
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.180] - 2026-11-05 —— 审计发现的三个真故障:precheck 是死代码、watch_start 不认 Gitee、gh 探测误报
|
|
6
|
+
|
|
7
|
+
### 来源
|
|
8
|
+
派单表 T1(子代理只读审计,`docs/报告-gh调用点审计.md`)逐个分类了 `lib/index.js` 里 **18 处 `run('gh'`**:
|
|
9
|
+
7 处 provider-dependent、11 处 github-only、0 处 unknown。以下三条是它挖出来的真故障。
|
|
10
|
+
|
|
11
|
+
### ① `precheckRepo` 从来没跑过(死代码)
|
|
12
|
+
```js
|
|
13
|
+
const created = !(state.watchers && state.watchers[id]) // 新建 = true
|
|
14
|
+
const isNew = !created && !state.watchers[id] // ← 两项互为否定,恒 false
|
|
15
|
+
```
|
|
16
|
+
于是「添加前体检」(仓库不存在/只读/归档/关 Issues 的警告)**一次都没执行**。
|
|
17
|
+
改成 `const isNew = created`。修复后这条路径立刻成为活代码,所以同一轮把它的 Gitee 分支也补上了
|
|
18
|
+
(否则 Gitee 守会去 `gh api repos/<gitee-repo>` 404,还给仓库写上假的「不存在」警告)。
|
|
19
|
+
|
|
20
|
+
### ② `watch_start` 工具不认 Gitee 写法
|
|
21
|
+
面板走 `/watch` 路由(已支持 `gitee:owner/name`),但**工具**走的是另一条创建路径,
|
|
22
|
+
按 `owner/name` 正则校验、且不写 `provider` —— 用工具建的 Gitee 守没有 provider,
|
|
23
|
+
默认走 GitHub 轮询,每轮 404。现在两条路径共用 `parseRepoSpec()`,id 也统一带 `gitee:` 前缀。
|
|
24
|
+
|
|
25
|
+
### ③ 全 Gitee 的客户看到「gh 未登录」假故障
|
|
26
|
+
`/state` 的 `ghHealth()` / `tokenScopes()` 与 `watch_doctor` 的 `gh auth status` 都**无条件**执行。
|
|
27
|
+
按需探测:没有 GitHub 守时跳过,并给出 `ok: null + skipped: '没有 GitHub 守'`(不再伪装成布尔)。
|
|
28
|
+
|
|
29
|
+
### 顺带
|
|
30
|
+
- `viewerLogin(provider)` 分家缓存:Gitee 守拿 GitHub 的 login 去比,自回声判定永远不成立;
|
|
31
|
+
- `probeAccess` 增加 Gitee 分支 + `mapGiteeRepoAccess()`(Gitee 的 `permissions.{push,admin}` 形状);
|
|
32
|
+
- Gitee 的 ack 标签在 doctor 里改成 **INFO**(Gitee 没有建标签端点,不会自动创建,别假装探测过)。
|
|
33
|
+
|
|
34
|
+
### 证据
|
|
35
|
+
```
|
|
36
|
+
node --test → 288/288(新增:repoAccess 映射、state 跳过探测)
|
|
37
|
+
preflight --fast → 除 tag 外全绿
|
|
38
|
+
审计报告:docs/报告-gh调用点审计.md(18 行表格 + 3 条 404 点)
|
|
39
|
+
派单表:docs/派单表.md
|
|
40
|
+
```
|
|
41
|
+
|
|
5
42
|
## [0.9.179] - 2026-11-04 —— 兼容 DSH 0.2.2-rc.1(静态核对)+ Gitee 增量轮询
|
|
6
43
|
|
|
7
44
|
### 一、DSH 0.2.2-rc.1 兼容核对(不装新版也能查)
|
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 # 288 项单测
|
|
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.180'
|
|
18
18
|
let BASE = '/session-superagent'
|
|
19
19
|
/**
|
|
20
20
|
* 挑「最新的那个服务端实例」。
|
package/lib/gitee.js
CHANGED
|
@@ -148,3 +148,25 @@ export async function giteeWhoami({ token = '', fetchImpl } = {}) {
|
|
|
148
148
|
export async function giteeRepo({ repo, token = '', fetchImpl } = {}) {
|
|
149
149
|
return request(`/repos/${repo}`, { token, fetchImpl })
|
|
150
150
|
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Gitee 仓库信息 → 内部 `repoAccess` 形状(与 GitHub 那条 `gh api repos/x --jq` 同构)。
|
|
154
|
+
*
|
|
155
|
+
* Gitee 的 `/repos/{owner}/{name}` 里权限在 `permissions.{admin,push,pull}`;
|
|
156
|
+
* 它**没有** `archived`/`disabled` 这两个字段,所以这两个保持 false 并注明来源,
|
|
157
|
+
* 不要瞎猜成 true(那会让「归档仓库」提示永远不出现,属于静默错误)。
|
|
158
|
+
*/
|
|
159
|
+
export function mapGiteeRepoAccess(repo, info = {}) {
|
|
160
|
+
const perms = info.permissions || {}
|
|
161
|
+
return {
|
|
162
|
+
repo,
|
|
163
|
+
push: perms.push === true || perms.admin === true,
|
|
164
|
+
private: info.private === true,
|
|
165
|
+
fork: Boolean(info.parent) || info.fork === true,
|
|
166
|
+
hasIssues: info.has_issues !== false,
|
|
167
|
+
archived: info.archived === true,
|
|
168
|
+
disabled: info.disabled === true,
|
|
169
|
+
parent: (info.parent && info.parent.full_name) || null,
|
|
170
|
+
checkedAt: new Date().toISOString(),
|
|
171
|
+
}
|
|
172
|
+
}
|
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 } from './gitee.js'
|
|
26
|
+
import { listGiteeItems, fetchGiteeLastComment, addGiteeLabel, giteeWhoami, giteeRepo, mapGiteeRepoAccess } from './gitee.js'
|
|
27
27
|
import {
|
|
28
28
|
advanceSeen, applyWatcherAction, batchFresh, decideWake, DEFAULT_ACK_LABEL, formatWatchText,
|
|
29
29
|
parseRepoSpec,
|
|
@@ -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.180'
|
|
46
46
|
export const inject = ['tools', 'agents', 'webServer']
|
|
47
47
|
/** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
|
|
48
48
|
// 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
|
|
@@ -226,7 +226,7 @@ function secretsSummary() {
|
|
|
226
226
|
// 从不在面板回显路径(Windows 路径里的反斜杠曾让掩码整段漏出)
|
|
227
227
|
sshKeyHint: null,
|
|
228
228
|
// 「用哪个 gh 账号」同理:只回配没配,不回路径(取自 PR #7 的设计)
|
|
229
|
-
ghConfigDir: s.ghConfigDir ? 'configured' : 'none',
|
|
229
|
+
ghConfigDir: s.ghConfigDir ? 'configured' : 'none',
|
|
230
230
|
giteeToken: s.giteeToken ? 'configured' : 'none',
|
|
231
231
|
ghConfigDirHint: null,
|
|
232
232
|
updatedAt: s.updatedAt ?? null,
|
|
@@ -760,9 +760,37 @@ async function tokenScopes() {
|
|
|
760
760
|
* 注意:**只产出警告,不阻止创建** —— 网络抖动不该让客户没法添加;
|
|
761
761
|
* 测试环境(DSH_SUPERAGENT_NO_POLL=1)直接跳过,避免单测依赖网络。
|
|
762
762
|
*/
|
|
763
|
-
async function precheckRepo(repo) {
|
|
763
|
+
async function precheckRepo(repo, provider = 'github') {
|
|
764
764
|
const warnings = []
|
|
765
765
|
if (process.env.DSH_SUPERAGENT_NO_POLL === '1') return { warnings, skipped: true }
|
|
766
|
+
// Gitee 仓库不能走 `gh api repos/...`(必然 404,还会把「不存在」写进警告)
|
|
767
|
+
if (provider === 'gitee') {
|
|
768
|
+
try {
|
|
769
|
+
const res = await giteeRepo({ repo, token: String(readSecrets().giteeToken || '') })
|
|
770
|
+
if (res.ok) {
|
|
771
|
+
const access = mapGiteeRepoAccess(repo, res.data || {})
|
|
772
|
+
const note = repoStructureNote({
|
|
773
|
+
repo,
|
|
774
|
+
hasIssues: access.hasIssues,
|
|
775
|
+
archived: access.archived,
|
|
776
|
+
disabled: access.disabled,
|
|
777
|
+
fork: access.fork,
|
|
778
|
+
parent: access.parent,
|
|
779
|
+
push: access.push,
|
|
780
|
+
private: access.private,
|
|
781
|
+
})
|
|
782
|
+
if (note) warnings.push(note)
|
|
783
|
+
return { warnings, access }
|
|
784
|
+
}
|
|
785
|
+
const status = Number(res.status) || 0
|
|
786
|
+
if (status === 401 || status === 403) warnings.push('Gitee token 无效或没权限(设置 → 凭证里重新填一次)')
|
|
787
|
+
else if (status === 404) warnings.push('Gitee 仓库 ' + repo + ' 不存在,或 token 看不到这个私有仓库')
|
|
788
|
+
else warnings.push('添加前没能确认这个 Gitee 仓库(' + String(res.error || status).slice(0, 80) + '),稍后会在面板里再次探测。')
|
|
789
|
+
return { warnings }
|
|
790
|
+
} catch {
|
|
791
|
+
return { warnings }
|
|
792
|
+
}
|
|
793
|
+
}
|
|
766
794
|
const res = await run('gh', ['api', 'repos/' + repo, '--jq',
|
|
767
795
|
'{push: .permissions.push, hasIssues: .has_issues, archived: .archived, disabled: .disabled, private: .private, fork: .fork, parent: (.parent.full_name // null)}',
|
|
768
796
|
], { timeoutMs: 10000, env: ghEnv() })
|
|
@@ -867,17 +895,24 @@ function installedVersion() {
|
|
|
867
895
|
}
|
|
868
896
|
|
|
869
897
|
/** 当前 token 对应的账号(判断"最后一条评论是不是我们自己发的")。缓存 10 分钟。 */
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
898
|
+
// 两家各自的登录名要分开缓存:Gitee 守拿 GitHub 的 login 去比,自回声判定永远不成立。
|
|
899
|
+
let viewerCache = { github: { at: 0, login: null }, gitee: { at: 0, login: null } }
|
|
900
|
+
async function viewerLogin(provider = 'github') {
|
|
901
|
+
const key = provider === 'gitee' ? 'gitee' : 'github'
|
|
902
|
+
const cached = viewerCache[key]
|
|
903
|
+
if (cached.login && Date.now() - cached.at < 10 * 60 * 1000) return cached.login
|
|
904
|
+
let login = ''
|
|
873
905
|
try {
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
906
|
+
if (key === 'gitee') {
|
|
907
|
+
const res = await giteeWhoami({ token: String(readSecrets().giteeToken || '') })
|
|
908
|
+
if (res.ok && res.data && res.data.login) login = String(res.data.login)
|
|
909
|
+
} else {
|
|
910
|
+
const res = await run('gh', ['api', 'user', '--jq', '.login'], { timeoutMs: 12000, env: ghEnv() })
|
|
911
|
+
if (res.code === 0) login = String(res.stdout || '').trim()
|
|
878
912
|
}
|
|
879
|
-
} catch {}
|
|
880
|
-
|
|
913
|
+
} catch { /* 拿不到就退回上一次的缓存 */ }
|
|
914
|
+
if (login) viewerCache[key] = { at: Date.now(), login }
|
|
915
|
+
return login || cached.login
|
|
881
916
|
}
|
|
882
917
|
|
|
883
918
|
async function fetchLastComments(repo, items, maxItems = 3, options = {}) {
|
|
@@ -887,7 +922,9 @@ async function fetchLastComments(repo, items, maxItems = 3, options = {}) {
|
|
|
887
922
|
const picks = (items || []).slice(0, maxItems)
|
|
888
923
|
await Promise.all(picks.map(async (item) => {
|
|
889
924
|
try {
|
|
890
|
-
const info = await fetchGiteeLastComment({
|
|
925
|
+
const info = await fetchGiteeLastComment({
|
|
926
|
+
repo, token: String(options.token || ''), item, selfLogin: await viewerLogin('gitee'),
|
|
927
|
+
})
|
|
891
928
|
if (info && info.login) item.lastComment = info
|
|
892
929
|
} catch { /* 少一行信息,不阻断唤醒 */ }
|
|
893
930
|
}))
|
|
@@ -950,15 +987,15 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
950
987
|
// Gitee 没有 gh CLI、没有 GraphQL、没有 ETag 条件请求;用 REST v5 拉一页,
|
|
951
988
|
// 在 lib/gitee.js 里归一成和 GitHub 一样的条目形状,下面所有筛选/唤醒逻辑共用。
|
|
952
989
|
if (entry.provider === 'gitee') {
|
|
953
|
-
// 没有 ETag,就用 `since` 只取「上次水位之后更新过」的条目 —— 省的是每轮的解析与带宽。
|
|
954
|
-
// 安全边际 30 分钟:宁可多读一轮,也不能因为时钟偏差漏掉一条。首次轮询没有水位,仍然全量。
|
|
955
|
-
const sinceIso = (() => {
|
|
956
|
-
const base = entry.cursor || entry.lastPoll
|
|
957
|
-
if (!base) return ''
|
|
958
|
-
const t = Date.parse(base)
|
|
959
|
-
if (!Number.isFinite(t)) return ''
|
|
960
|
-
return new Date(Math.max(0, t - 30 * 60 * 1000)).toISOString()
|
|
961
|
-
})()
|
|
990
|
+
// 没有 ETag,就用 `since` 只取「上次水位之后更新过」的条目 —— 省的是每轮的解析与带宽。
|
|
991
|
+
// 安全边际 30 分钟:宁可多读一轮,也不能因为时钟偏差漏掉一条。首次轮询没有水位,仍然全量。
|
|
992
|
+
const sinceIso = (() => {
|
|
993
|
+
const base = entry.cursor || entry.lastPoll
|
|
994
|
+
if (!base) return ''
|
|
995
|
+
const t = Date.parse(base)
|
|
996
|
+
if (!Number.isFinite(t)) return ''
|
|
997
|
+
return new Date(Math.max(0, t - 30 * 60 * 1000)).toISOString()
|
|
998
|
+
})()
|
|
962
999
|
const listed = await listGiteeItems({ repo: entry.repo, token: String(readSecrets().giteeToken || ''), perPage: 20, since: sinceIso })
|
|
963
1000
|
entry.lastPoll = new Date().toISOString()
|
|
964
1001
|
if (!listed.ok) {
|
|
@@ -1361,6 +1398,16 @@ export function apply(ctx) {
|
|
|
1361
1398
|
|
|
1362
1399
|
/** 后台查一次仓库权限:push=false 说明只能读,回写评论/标签都会 403。 */
|
|
1363
1400
|
const probeAccess = async (entry) => {
|
|
1401
|
+
// Gitee 走 REST:`gh api repos/...` 对它必然 404,硬探会把「只读」误报成常态
|
|
1402
|
+
if (entry.provider === 'gitee') {
|
|
1403
|
+
try {
|
|
1404
|
+
const res = await giteeRepo({ repo: entry.repo, token: String(readSecrets().giteeToken || '') })
|
|
1405
|
+
if (!res.ok) return
|
|
1406
|
+
entry.repoAccess = mapGiteeRepoAccess(entry.repo, res.data || {})
|
|
1407
|
+
persistEntry(entry)
|
|
1408
|
+
} catch { /* 探测失败不影响主流程 */ }
|
|
1409
|
+
return
|
|
1410
|
+
}
|
|
1364
1411
|
try {
|
|
1365
1412
|
const res = await run('gh', ['api', 'repos/' + entry.repo, '--jq',
|
|
1366
1413
|
'{push: .permissions.push, private: .private, fork: .fork, hasIssues: .has_issues, archived: .archived, disabled: .disabled, parent: (.parent.full_name // null)}'],
|
|
@@ -1516,10 +1563,12 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
1516
1563
|
const url = new URL(String(req.url || '/'), 'http://127.0.0.1')
|
|
1517
1564
|
const focusSession = url.searchParams.get('sessionId') || ''
|
|
1518
1565
|
const state = readState()
|
|
1519
|
-
// 顺带刷新一次 token scopes(缓存 5 分钟;失败不影响 /state)
|
|
1520
|
-
tokenScopes().catch(() => {})
|
|
1521
|
-
const gh = await ghHealth()
|
|
1522
1566
|
const allWatchers = Object.values(state.watchers || {})
|
|
1567
|
+
// 只有 GitHub 守才需要 `gh`:全 Gitee 的客户看到「gh 未登录」是纯噪音,
|
|
1568
|
+
// 而且那两条探测每次都要 spawn 一个进程(面板 5 秒一刷)。
|
|
1569
|
+
const needsGh = allWatchers.some((w) => w && w.provider !== 'gitee')
|
|
1570
|
+
if (needsGh) tokenScopes().catch(() => {})
|
|
1571
|
+
const gh = needsGh ? await ghHealth() : { ok: null, skipped: '没有 GitHub 守' }
|
|
1523
1572
|
// 全局预算:守越多,每守分到的事件条数越少(100 条守时每人 2 条,总量 ≤ 240)
|
|
1524
1573
|
const perWatcherEvents = Math.max(1, Math.min(STATE_EVENTS_PER_WATCHER, Math.floor(STATE_EVENTS_BUDGET / Math.max(1, allWatchers.length))))
|
|
1525
1574
|
const watchers = allWatchers.map((w) => ({
|
|
@@ -1771,10 +1820,12 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
1771
1820
|
entry.nextAt = null
|
|
1772
1821
|
}
|
|
1773
1822
|
// 只有**新建**时才做添加前体检:编辑已有守不该再打一次网络
|
|
1774
|
-
|
|
1823
|
+
// `created` 的语义就是「新建」;这里原来写成 `!created && !state.watchers[id]`,
|
|
1824
|
+
// 两项互为否定 → 永远 false → 下面的添加前体检从来没跑过(T1 审计发现)。
|
|
1825
|
+
const isNew = created
|
|
1775
1826
|
let warnings = []
|
|
1776
1827
|
if (isNew) {
|
|
1777
|
-
const pre = await precheckRepo(repo)
|
|
1828
|
+
const pre = await precheckRepo(repo, provider)
|
|
1778
1829
|
warnings = pre.warnings || []
|
|
1779
1830
|
if (pre.access) entry.repoAccess = pre.access
|
|
1780
1831
|
}
|
|
@@ -1815,12 +1866,12 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
1815
1866
|
}
|
|
1816
1867
|
// 「用哪个 gh 账号」:指向只登录了智能体账号的配置目录;空串 = 回到宿主当前账号。
|
|
1817
1868
|
// 只收绝对路径:相对路径会随 cwd 漂移,把设置指向一个不存在的地方。
|
|
1818
|
-
// Gitee 私人令牌:和 GitHub token 分开存(两家互不通用)
|
|
1819
|
-
if (typeof body.giteeToken === 'string') {
|
|
1820
|
-
const gt = body.giteeToken.trim()
|
|
1821
|
-
if (gt === '') delete next.giteeToken
|
|
1822
|
-
else next.giteeToken = gt
|
|
1823
|
-
}
|
|
1869
|
+
// Gitee 私人令牌:和 GitHub token 分开存(两家互不通用)
|
|
1870
|
+
if (typeof body.giteeToken === 'string') {
|
|
1871
|
+
const gt = body.giteeToken.trim()
|
|
1872
|
+
if (gt === '') delete next.giteeToken
|
|
1873
|
+
else next.giteeToken = gt
|
|
1874
|
+
}
|
|
1824
1875
|
if (typeof body.ghConfigDir === 'string') {
|
|
1825
1876
|
const dir = body.ghConfigDir.trim()
|
|
1826
1877
|
if (dir === '') delete next.ghConfigDir
|
|
@@ -2221,10 +2272,15 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2221
2272
|
lines.push('WARN 还没有挂载记录(刚装上或从未加载过路由)')
|
|
2222
2273
|
}
|
|
2223
2274
|
|
|
2224
|
-
// 1. gh
|
|
2225
|
-
const
|
|
2226
|
-
|
|
2227
|
-
|
|
2275
|
+
// 1. gh 是否登录(只有 GitHub 守才需要它;全 Gitee 的客户看到 FAIL 是假故障)
|
|
2276
|
+
const hasGithub = all.some((w) => w && w.provider !== 'gitee')
|
|
2277
|
+
if (!hasGithub) {
|
|
2278
|
+
lines.push('INFO 没有 GitHub 守:跳过 gh 登录检查(Gitee 那条走令牌,见上面)')
|
|
2279
|
+
} else {
|
|
2280
|
+
const auth = await run('gh', ['auth', 'status'], { env: ghEnv() })
|
|
2281
|
+
const authed = auth.code === 0
|
|
2282
|
+
lines.push(`${authed ? 'OK ' : 'FAIL'} gh 登录:${auth.code === 0 ? '正常' : redact([auth.stderr, auth.stdout].join(' ')).slice(0, 120)}`)
|
|
2283
|
+
}
|
|
2228
2284
|
|
|
2229
2285
|
if (wanted.length === 0) {
|
|
2230
2286
|
lines.push('INFO 当前没有任何 watcher —— 先 watch_start 或到面板加一条')
|
|
@@ -2280,8 +2336,14 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2280
2336
|
}
|
|
2281
2337
|
// 3. ack 标签是否存在
|
|
2282
2338
|
const label = entry.ackLabel || DEFAULT_ACK_LABEL
|
|
2283
|
-
|
|
2284
|
-
|
|
2339
|
+
if (entry.provider === 'gitee') {
|
|
2340
|
+
// Gitee 没有「建标签」端点,watch_ack 也不会替它建(GitHub 会)——
|
|
2341
|
+
// 所以这里只能交代规则,不能假装探测过。
|
|
2342
|
+
lines.push(`INFO ack 标签「${label}」:Gitee 需要先在仓库里手动建好这个标签,watch_ack 才能打上`)
|
|
2343
|
+
} else {
|
|
2344
|
+
const labRes = await run('gh', ['api', `repos/${entry.repo}/labels/${encodeURIComponent(label)}`, '--jq', '.name'], { env: ghEnv() })
|
|
2345
|
+
lines.push(`${labRes.code === 0 ? 'OK ' : 'WARN'} ack 标签「${label}」:${labRes.code === 0 ? '已存在' : '不存在(首次 watch_ack 会自动创建)'}`)
|
|
2346
|
+
}
|
|
2285
2347
|
|
|
2286
2348
|
// 4. 隔离工作目录
|
|
2287
2349
|
if (entry.isolated) {
|
|
@@ -2414,16 +2476,19 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2414
2476
|
}
|
|
2415
2477
|
|
|
2416
2478
|
// 一次可以加多个仓库:客户三个仓库不用点三次(逗号/空格/换行都认)
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2479
|
+
// 同一个写法解析器给面板和工具共用:`gitee:owner/name` / gitee.com URL 都要能认,
|
|
2480
|
+
// 否则工具建出来的守没有 provider,Gitee 仓库会被当 GitHub 轮询,每轮 404。
|
|
2481
|
+
const parsedSpecs = String(repo).split(/[,\s]+/).map((item) => item.trim()).filter(Boolean).map((item) => ({ item, spec: parseRepoSpec(item) }))
|
|
2482
|
+
const bad = parsedSpecs.filter(({ spec }) => !spec.ok).map(({ item }) => item)
|
|
2483
|
+
if (bad.length > 0) return '[error: 仓库要写成 owner/name 或 gitee:owner/name,这些不对:' + bad.join(', ') + ']'
|
|
2484
|
+
if (parsedSpecs.length === 0) return '[error: 至少给一个仓库(owner/name)]'
|
|
2485
|
+
const repoList = parsedSpecs.map(({ item, spec }) => ({ repo: spec.repo, provider: spec.provider, label: item }))
|
|
2486
|
+
const applyOne = ({ repo, provider }) => {
|
|
2487
|
+
const id = (provider === 'gitee' ? 'gitee:' : '') + `${repo}#${sessionId}`
|
|
2423
2488
|
const state = readState()
|
|
2424
2489
|
const existing = state.watchers && state.watchers[id]
|
|
2425
2490
|
const entry = existing || {
|
|
2426
|
-
id, repo, sessionId,
|
|
2491
|
+
id, repo, provider, sessionId,
|
|
2427
2492
|
intervalSec: 60,
|
|
2428
2493
|
cooldownMs: DEFAULT_COOLDOWN_MS,
|
|
2429
2494
|
ackLabel: DEFAULT_ACK_LABEL,
|
|
@@ -2488,15 +2553,17 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2488
2553
|
{
|
|
2489
2554
|
const snapshot = readState()
|
|
2490
2555
|
const mine = Object.values(snapshot.watchers || {}).filter((w) => w && w.sessionId === sessionId)
|
|
2491
|
-
|
|
2556
|
+
// id 必须和 applyOne 里算的一致(Gitee 带 `gitee:` 前缀),否则上限计数会漏掉它们
|
|
2557
|
+
const idOf = ({ repo, provider }) => (provider === 'gitee' ? 'gitee:' : '') + repo + '#' + sessionId
|
|
2558
|
+
const incoming = repoList.filter((item) => !(snapshot.watchers || {})[idOf(item)])
|
|
2492
2559
|
const room = MAX_WATCHERS_PER_SESSION - mine.length
|
|
2493
2560
|
if (incoming.length > room) {
|
|
2494
2561
|
return '一条会话最多挂 ' + MAX_WATCHERS_PER_SESSION + ' 条守(现在 ' + mine.length + ' 条,这次要新增 ' + incoming.length + ' 条)—— 先 watch_stop 停掉不用的,或把多个仓库合成一条规则'
|
|
2495
2562
|
}
|
|
2496
2563
|
}
|
|
2497
2564
|
const applied = []
|
|
2498
|
-
for (const
|
|
2499
|
-
const result = applyOne(
|
|
2565
|
+
for (const item of repoList) {
|
|
2566
|
+
const result = applyOne(item)
|
|
2500
2567
|
// 单条校验失败(比如相对路径的 workdir)要原地返回,不能继续加后面的
|
|
2501
2568
|
if (typeof result === 'string') return result
|
|
2502
2569
|
applied.push(result)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-superagent",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.180",
|
|
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",
|