dsh-session-superagent 0.9.178 → 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 CHANGED
@@ -2,6 +2,79 @@
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
+
42
+ ## [0.9.179] - 2026-11-04 —— 兼容 DSH 0.2.2-rc.1(静态核对)+ Gitee 增量轮询
43
+
44
+ ### 一、DSH 0.2.2-rc.1 兼容核对(不装新版也能查)
45
+ `npm dist-tags` 显示 `next = 0.2.2-rc.1`。逐个比对 `.d.ts`(而不是读 release notes):
46
+
47
+ | 检查 | 结果 |
48
+ |---|---|
49
+ | CLI 包 `lib/types/*.d.ts` | 与 0.2.1-rc.5 **逐字相同** |
50
+ | `dsh-web-app`(webServer 服务) | 逐字相同 |
51
+ | `dsh-goal`(goals 服务) | 逐字相同 |
52
+ | cordis 4.0.5 → 4.1.0 | `ctx.effect` / `ctx.on` / `ctx.get` 契约不变;**日志级别数值重排**(INFO/WARN 互换);provision 形状 `{fiber}` → `{ctx,uid}` |
53
+ | Node 引擎 | 新宿主要求 **≥24.9.0**(我们声明 ≥22.19,是下界,没问题) |
54
+
55
+ **改了一处**:`apply()` 先检查 `ctx.tools`,缺了只打一条日志就返回 ——
56
+ 即使某个服务改名,也只是"这个插件不工作",不会拖垮整棵插件树。
57
+
58
+ ### 二、Gitee 增量轮询(看 Gitee 帮助中心时顺手挖到的)
59
+ Gitee 没有 ETag,之前每轮全量读。实测它**支持 `since`**:
60
+
61
+ ```
62
+ 全量 34 条 → since(24h) 5 条
63
+ ```
64
+
65
+ 现在按「上次水位 - 30 分钟安全边际」传 `since`;首次轮询仍全量。
66
+
67
+ ### 三、关于 `help.gitee.com/ide-plugin`
68
+ 那一页是 **IDE 插件**(IDEA / VS / Eclipse / Atom)的集成说明,与守护进程无关 ——
69
+ 没有可用的 CLI 或服务端接口可抄。真正的可用面是 Open API v5,`since` 就是从那儿试出来的。
70
+
71
+ ### 证据
72
+ ```
73
+ node --test → 287/287(新增 since 拼 URL、缺 tools 不抛)
74
+ preflight 全量 → 37/37
75
+ 真机:listGiteeItems 全量 34 条 / since 5 条
76
+ ```
77
+
5
78
  ## [0.9.178] - 2026-11-04 —— 用真实 Gitee 响应校对:编号是字符串,不是数字
6
79
 
7
80
  ### 怎么发现的
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.178-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.9.180-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 # 285 项单测
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.178'
17
+ const CLIENT_VERSION = '0.9.180'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
package/lib/gitee.js CHANGED
@@ -95,8 +95,12 @@ async function request(path, { token, method = 'GET', body = null, fetchImpl = g
95
95
  }
96
96
 
97
97
  /** 拉一页 issue + PR(Gitee 两者分属不同端点,缺 token 时公开仓库也能读)。 */
98
- export async function listGiteeItems({ repo, token = '', perPage = 20, fetchImpl } = {}) {
99
- const q = 'state=all&sort=updated&direction=desc&per_page=' + Math.max(1, Math.min(100, Number(perPage) || 20))
98
+ export async function listGiteeItems({ repo, token = '', perPage = 20, since = '', fetchImpl } = {}) {
99
+ // `since` 是 Gitee 少有的、能省流量的手段(没有 ETag 条件请求)。
100
+ // 真机验证:since 传给未来时间 → 返回 [];传今天 → 只返回今天之后更新的。
101
+ // 两个端点都支持,缺了它就只能每轮全量读。
102
+ const sinceQ = since ? '&since=' + encodeURIComponent(String(since)) : ''
103
+ const q = 'state=all&sort=updated&direction=desc&per_page=' + Math.max(1, Math.min(100, Number(perPage) || 20)) + sinceQ
100
104
  const [issues, pulls] = await Promise.all([
101
105
  request(`/repos/${repo}/issues?${q}`, { token, fetchImpl }),
102
106
  request(`/repos/${repo}/pulls?${q}`, { token, fetchImpl }),
@@ -144,3 +148,25 @@ export async function giteeWhoami({ token = '', fetchImpl } = {}) {
144
148
  export async function giteeRepo({ repo, token = '', fetchImpl } = {}) {
145
149
  return request(`/repos/${repo}`, { token, fetchImpl })
146
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.178'
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
- let viewerCache = { at: 0, login: null }
871
- async function viewerLogin() {
872
- if (viewerCache.login && Date.now() - viewerCache.at < 10 * 60 * 1000) return viewerCache.login
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
- const res = await run('gh', ['api', 'user', '--jq', '.login'], { timeoutMs: 12000, env: ghEnv() })
875
- if (res.code === 0) {
876
- const login = String(res.stdout || '').trim()
877
- if (login) { viewerCache = { at: Date.now(), login }; return login }
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
- return viewerCache.login
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({ repo, token: String(options.token || ''), item })
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,7 +987,16 @@ 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
- const listed = await listGiteeItems({ repo: entry.repo, token: String(readSecrets().giteeToken || ''), perPage: 20 })
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
+ })()
999
+ const listed = await listGiteeItems({ repo: entry.repo, token: String(readSecrets().giteeToken || ''), perPage: 20, since: sinceIso })
954
1000
  entry.lastPoll = new Date().toISOString()
955
1001
  if (!listed.ok) {
956
1002
  const status = Number(listed.status) || 0
@@ -1338,6 +1384,12 @@ async function pollWithItems(ctx, entry, baseMs, parsed) {
1338
1384
  }
1339
1385
 
1340
1386
  export function apply(ctx) {
1387
+ // 宿主升级(如 0.2.2-rc.1)时最可能变的不是我们的逻辑,而是服务名/形状。
1388
+ // 一条守挂了不该拖垮整个插件树:缺服务就只打一条日志,其余能力继续挂。
1389
+ if (!ctx || !ctx.tools || typeof ctx.tools.register !== 'function') {
1390
+ try { console.error('[session-superagent] 宿主没有提供 tools 服务:插件能力不可用,但不影响宿主') } catch {}
1391
+ return
1392
+ }
1341
1393
  const timers = sharedTimers
1342
1394
  // 并发闸的唯一事实源:tick 和 HTTP「立刻」拿到的是两个不同的 entry 对象,
1343
1395
  // 靠 entry.polling 标记永远对不上(审核专员 probe-c 实证:同一条被唤醒 3 次)。
@@ -1346,6 +1398,16 @@ export function apply(ctx) {
1346
1398
 
1347
1399
  /** 后台查一次仓库权限:push=false 说明只能读,回写评论/标签都会 403。 */
1348
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
+ }
1349
1411
  try {
1350
1412
  const res = await run('gh', ['api', 'repos/' + entry.repo, '--jq',
1351
1413
  '{push: .permissions.push, private: .private, fork: .fork, hasIssues: .has_issues, archived: .archived, disabled: .disabled, parent: (.parent.full_name // null)}'],
@@ -1501,10 +1563,12 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
1501
1563
  const url = new URL(String(req.url || '/'), 'http://127.0.0.1')
1502
1564
  const focusSession = url.searchParams.get('sessionId') || ''
1503
1565
  const state = readState()
1504
- // 顺带刷新一次 token scopes(缓存 5 分钟;失败不影响 /state)
1505
- tokenScopes().catch(() => {})
1506
- const gh = await ghHealth()
1507
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 守' }
1508
1572
  // 全局预算:守越多,每守分到的事件条数越少(100 条守时每人 2 条,总量 ≤ 240)
1509
1573
  const perWatcherEvents = Math.max(1, Math.min(STATE_EVENTS_PER_WATCHER, Math.floor(STATE_EVENTS_BUDGET / Math.max(1, allWatchers.length))))
1510
1574
  const watchers = allWatchers.map((w) => ({
@@ -1756,10 +1820,12 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
1756
1820
  entry.nextAt = null
1757
1821
  }
1758
1822
  // 只有**新建**时才做添加前体检:编辑已有守不该再打一次网络
1759
- const isNew = !created && !state.watchers[id]
1823
+ // `created` 的语义就是「新建」;这里原来写成 `!created && !state.watchers[id]`,
1824
+ // 两项互为否定 → 永远 false → 下面的添加前体检从来没跑过(T1 审计发现)。
1825
+ const isNew = created
1760
1826
  let warnings = []
1761
1827
  if (isNew) {
1762
- const pre = await precheckRepo(repo)
1828
+ const pre = await precheckRepo(repo, provider)
1763
1829
  warnings = pre.warnings || []
1764
1830
  if (pre.access) entry.repoAccess = pre.access
1765
1831
  }
@@ -1800,12 +1866,12 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
1800
1866
  }
1801
1867
  // 「用哪个 gh 账号」:指向只登录了智能体账号的配置目录;空串 = 回到宿主当前账号。
1802
1868
  // 只收绝对路径:相对路径会随 cwd 漂移,把设置指向一个不存在的地方。
1803
- // Gitee 私人令牌:和 GitHub token 分开存(两家互不通用)
1804
- if (typeof body.giteeToken === 'string') {
1805
- const gt = body.giteeToken.trim()
1806
- if (gt === '') delete next.giteeToken
1807
- else next.giteeToken = gt
1808
- }
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
+ }
1809
1875
  if (typeof body.ghConfigDir === 'string') {
1810
1876
  const dir = body.ghConfigDir.trim()
1811
1877
  if (dir === '') delete next.ghConfigDir
@@ -2206,10 +2272,15 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2206
2272
  lines.push('WARN 还没有挂载记录(刚装上或从未加载过路由)')
2207
2273
  }
2208
2274
 
2209
- // 1. gh 是否登录
2210
- const auth = await run('gh', ['auth', 'status'], { env: ghEnv() })
2211
- const authed = auth.code === 0
2212
- lines.push(`${authed ? 'OK ' : 'FAIL'} gh 登录:${auth.code === 0 ? '正常' : redact([auth.stderr, auth.stdout].join(' ')).slice(0, 120)}`)
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
+ }
2213
2284
 
2214
2285
  if (wanted.length === 0) {
2215
2286
  lines.push('INFO 当前没有任何 watcher —— 先 watch_start 或到面板加一条')
@@ -2265,8 +2336,14 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2265
2336
  }
2266
2337
  // 3. ack 标签是否存在
2267
2338
  const label = entry.ackLabel || DEFAULT_ACK_LABEL
2268
- const labRes = await run('gh', ['api', `repos/${entry.repo}/labels/${encodeURIComponent(label)}`, '--jq', '.name'], { env: ghEnv() })
2269
- lines.push(`${labRes.code === 0 ? 'OK ' : 'WARN'} ack 标签「${label}」:${labRes.code === 0 ? '已存在' : '不存在(首次 watch_ack 会自动创建)'}`)
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
+ }
2270
2347
 
2271
2348
  // 4. 隔离工作目录
2272
2349
  if (entry.isolated) {
@@ -2399,16 +2476,19 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2399
2476
  }
2400
2477
 
2401
2478
  // 一次可以加多个仓库:客户三个仓库不用点三次(逗号/空格/换行都认)
2402
- const repoList = String(repo).split(/[,\s]+/).map((item) => item.trim()).filter(Boolean)
2403
- const bad = repoList.filter((item) => !/^[^/\s]+\/[^/\s]+$/.test(item))
2404
- if (bad.length > 0) return '[error: 仓库要写成 owner/name,这些不对:' + bad.join(', ') + ']'
2405
- if (repoList.length === 0) return '[error: 至少给一个仓库(owner/name)]'
2406
- const applyOne = (repo) => {
2407
- const id = `${repo}#${sessionId}`
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}`
2408
2488
  const state = readState()
2409
2489
  const existing = state.watchers && state.watchers[id]
2410
2490
  const entry = existing || {
2411
- id, repo, sessionId,
2491
+ id, repo, provider, sessionId,
2412
2492
  intervalSec: 60,
2413
2493
  cooldownMs: DEFAULT_COOLDOWN_MS,
2414
2494
  ackLabel: DEFAULT_ACK_LABEL,
@@ -2473,15 +2553,17 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2473
2553
  {
2474
2554
  const snapshot = readState()
2475
2555
  const mine = Object.values(snapshot.watchers || {}).filter((w) => w && w.sessionId === sessionId)
2476
- const incoming = repoList.filter((name) => !(snapshot.watchers || {})[name + '#' + sessionId])
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)])
2477
2559
  const room = MAX_WATCHERS_PER_SESSION - mine.length
2478
2560
  if (incoming.length > room) {
2479
2561
  return '一条会话最多挂 ' + MAX_WATCHERS_PER_SESSION + ' 条守(现在 ' + mine.length + ' 条,这次要新增 ' + incoming.length + ' 条)—— 先 watch_stop 停掉不用的,或把多个仓库合成一条规则'
2480
2562
  }
2481
2563
  }
2482
2564
  const applied = []
2483
- for (const name of repoList) {
2484
- const result = applyOne(name)
2565
+ for (const item of repoList) {
2566
+ const result = applyOne(item)
2485
2567
  // 单条校验失败(比如相对路径的 workdir)要原地返回,不能继续加后面的
2486
2568
  if (typeof result === 'string') return result
2487
2569
  applied.push(result)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.9.178",
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",