dsh-session-superagent 0.8.67 → 0.8.69
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/MAINTENANCE.md +1 -1
- package/README.md +2 -2
- package/client.js +8 -3
- package/lib/index.js +68 -3
- package/lib/watch.js +20 -0
- 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.8.69] - 2026-11-02 —— 填错仓库名时给个"是不是想填 X"
|
|
6
|
+
|
|
7
|
+
### 学到的(知识库第 18 条,实测数字)
|
|
8
|
+
`search/repositories` 的响应头本机实测:`x-ratelimit-limit: 30`(30 次/分钟);
|
|
9
|
+
对照 core 的 `5000` —— **两个池差 166 倍**。
|
|
10
|
+
<https://docs.github.com/en/rest/search/search#search-repositories>
|
|
11
|
+
|
|
12
|
+
这给知识库第 16 条(限流分池)补上了具体数字,也决定了本轮实现的边界。
|
|
13
|
+
|
|
14
|
+
### 改了什么
|
|
15
|
+
添加守时若仓库 404,用搜索找最像的仓库,提示「是不是想填 owner/name?」。因为 search 池很紧:
|
|
16
|
+
- 只在 **404 之后**才搜(正常路径零调用);
|
|
17
|
+
- 名字短于 5 字符不搜;
|
|
18
|
+
- `per_page=5` 拿到就停;
|
|
19
|
+
- 搜索失败/被限流**静默放弃**,不影响添加。
|
|
20
|
+
|
|
21
|
+
排序规则:**仓库名完全相同 > 名字包含**;owner 相同但仓库名不相关的**不给建议**(避免误导)。
|
|
22
|
+
|
|
23
|
+
### 测试
|
|
24
|
+
- 新增 1 例(同名优先 / 包含关系 / 不相关不乱猜 / 空输入 / 无候选 / 短名同名)。合计 **122 例**。
|
|
25
|
+
|
|
26
|
+
## [0.8.68] - 2026-11-02 —— 添加时就告诉你仓库有问题,不用等十几秒
|
|
27
|
+
|
|
28
|
+
### 学到的(知识库第 17 条)
|
|
29
|
+
`GET /repos/{owner}/{repo}` 对**不存在**和**无权访问**都返回 404 —— 所以文案必须同时覆盖两种可能,
|
|
30
|
+
否则会误导。而 `has_issues` / `archived` / `permissions.push` 都是"读一次就知道"的事实,
|
|
31
|
+
没有理由等运行失败才说。
|
|
32
|
+
<https://docs.github.com/en/rest/repos/repos#get-a-repository>
|
|
33
|
+
|
|
34
|
+
### 改了什么
|
|
35
|
+
- 新建守时**同步**体检(10 秒超时),结论直接放进 `POST /watch` 的响应 `warnings`;
|
|
36
|
+
- 面板拿到就立刻提示:`已添加,但注意:仓库 o/x 不存在,或当前 token 没有访问权限 …`;
|
|
37
|
+
- **只告警不阻断**(网络抖动不该让人加不了守);编辑已有守不做体检;测试环境跳过网络但字段保留。
|
|
38
|
+
|
|
39
|
+
### 测试
|
|
40
|
+
- 新增 1 例:`POST /watch` 的 `warnings` 必须始终是数组。合计 **121 例**。
|
|
41
|
+
|
|
5
42
|
## [0.8.67] - 2026-11-02 —— 能力徽章可点筛选;顺手记下「限流是分池的」
|
|
6
43
|
|
|
7
44
|
### 学到的(知识库第 16 条,判断准则)
|
package/MAINTENANCE.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## 二、当前状态(2026-11-01)
|
|
11
11
|
|
|
12
|
-
- [x] 七个工具可用(github / repo_here / watch_start / watch_status / watch_stop / watch_ack / watch_doctor),`node --test`
|
|
12
|
+
- [x] 七个工具可用(github / repo_here / watch_start / watch_status / watch_stop / watch_ack / watch_doctor),`node --test` 122/122 通过
|
|
13
13
|
- [x] 自回声抑制(逐条水位)
|
|
14
14
|
- [x] 仅空闲注入(避免草稿回放)
|
|
15
15
|
- [x] 唤醒失败不推进水位
|
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
|
|
|
@@ -99,7 +99,7 @@ dsh plugin install /path/to/dsh-session-superagent
|
|
|
99
99
|
## 开发
|
|
100
100
|
|
|
101
101
|
```sh
|
|
102
|
-
node --test #
|
|
102
|
+
node --test # 122 项单测
|
|
103
103
|
```
|
|
104
104
|
|
|
105
105
|
版本与发布流程见 [UPDATING.md](UPDATING.md),交付门见 [CHECKLIST.md](CHECKLIST.md),接手台账见 [MAINTENANCE.md](MAINTENANCE.md)。
|
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.8.
|
|
17
|
+
const CLIENT_VERSION = '0.8.69'
|
|
18
18
|
let BASE = '/session-superagent'
|
|
19
19
|
/**
|
|
20
20
|
* 挑「最新的那个服务端实例」。
|
|
@@ -925,7 +925,7 @@ window.__ModuleLoader__.load({
|
|
|
925
925
|
}, action === 'pause' ? '全部已暂停' : '全部已恢复')
|
|
926
926
|
|
|
927
927
|
const addWatcher = () => run(async () => {
|
|
928
|
-
await call('/watch', {
|
|
928
|
+
const created = await call('/watch', {
|
|
929
929
|
method: 'POST',
|
|
930
930
|
body: JSON.stringify({
|
|
931
931
|
repo: form.repo.trim(),
|
|
@@ -945,7 +945,12 @@ window.__ModuleLoader__.load({
|
|
|
945
945
|
}),
|
|
946
946
|
})
|
|
947
947
|
setForm({ repo: '', intervalSec: form.intervalSec, goal: '', labels: '', onlyAssigned: false, activeHours: form.activeHours, isolated: form.isolated, workdir: form.workdir, observe: form.observe })
|
|
948
|
-
|
|
948
|
+
// 添加前体检的警告直接说出来:填错仓库名 / 只读 / 归档,这一刻讲最省事
|
|
949
|
+
const warnings = (created && Array.isArray(created.warnings)) ? created.warnings : []
|
|
950
|
+
if (warnings.length > 0) notify('已添加,但注意:' + warnings.join(' / '), 'error')
|
|
951
|
+
else notify('已添加,首轮立即开始轮询', 'info')
|
|
952
|
+
return warnings
|
|
953
|
+
}, null)
|
|
949
954
|
|
|
950
955
|
const saveCredentials = () => run(async () => {
|
|
951
956
|
const payload = {}
|
package/lib/index.js
CHANGED
|
@@ -24,13 +24,13 @@ import { redact } from './redact.js'
|
|
|
24
24
|
import { decodeBody } from './body.js'
|
|
25
25
|
import {
|
|
26
26
|
advanceSeen, applyWatcherAction, batchFresh, decideWake, DEFAULT_ACK_LABEL, formatWatchText,
|
|
27
|
-
accessNote, classifyGhError, repoStructureNote, countReasons, filterReason, hasAckLabel, jitterMs, parseGhInclude, retryAfterMs, throttleDelayMs, inActiveHours, newestUpdatedAt, nextDelayMs, pushFiltered, normalizeFilters, partitionItems, passesFilters,
|
|
27
|
+
accessNote, classifyGhError, pickSuggestion, repoStructureNote, countReasons, filterReason, hasAckLabel, jitterMs, parseGhInclude, retryAfterMs, throttleDelayMs, inActiveHours, newestUpdatedAt, nextDelayMs, pushFiltered, normalizeFilters, partitionItems, passesFilters,
|
|
28
28
|
mergeFilters, mergePollResult, pruneSeen, pruneWakeTimes, pushHistory, recordReported, staleWorktrees, worktreePlan,
|
|
29
29
|
} from './watch.js'
|
|
30
30
|
|
|
31
31
|
export const name = 'dsh-session-superagent'
|
|
32
32
|
/** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
|
|
33
|
-
export const SERVER_VERSION = '0.8.
|
|
33
|
+
export const SERVER_VERSION = '0.8.69'
|
|
34
34
|
export const inject = ['tools', 'agents', 'webServer']
|
|
35
35
|
|
|
36
36
|
/** 仅供测试:读写状态文件(生产代码不要用)。 */
|
|
@@ -549,6 +549,62 @@ async function tokenScopes() {
|
|
|
549
549
|
return value
|
|
550
550
|
}
|
|
551
551
|
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* 新增守之前的即时体检:仓库在不在、能不能写、有没有 issue。
|
|
555
|
+
*
|
|
556
|
+
* 为什么放在这里:`probeAccess` 是后台跑的,客户要等到下一次 /state 才看到提示;
|
|
557
|
+
* 而"填错仓库名"是最常见的输入错误,应该在点「添加」那一刻就说。
|
|
558
|
+
*
|
|
559
|
+
* 依据:`GET /repos/{owner}/{repo}` 对不存在的仓库(或无权访问的私有仓库)返回 404 ——
|
|
560
|
+
* 官方文档把这两种情况归为同一个响应,所以文案要一起说「不存在或没有权限」。
|
|
561
|
+
* 出处:https://docs.github.com/en/rest/repos/repos#get-a-repository
|
|
562
|
+
*
|
|
563
|
+
* 注意:**只产出警告,不阻止创建** —— 网络抖动不该让客户没法添加;
|
|
564
|
+
* 测试环境(DSH_SUPERAGENT_NO_POLL=1)直接跳过,避免单测依赖网络。
|
|
565
|
+
*/
|
|
566
|
+
async function precheckRepo(repo) {
|
|
567
|
+
const warnings = []
|
|
568
|
+
if (process.env.DSH_SUPERAGENT_NO_POLL === '1') return { warnings, skipped: true }
|
|
569
|
+
const res = await run('gh', ['api', 'repos/' + repo, '--jq',
|
|
570
|
+
'{push: .permissions.push, hasIssues: .has_issues, archived: .archived, disabled: .disabled, private: .private, fork: .fork, parent: (.parent.full_name // null)}',
|
|
571
|
+
], { timeoutMs: 10000, env: ghEnv() })
|
|
572
|
+
if (res.code !== 0) {
|
|
573
|
+
const detail = redact(res.stderr)
|
|
574
|
+
if (detail.includes('404')) {
|
|
575
|
+
let hint = ''
|
|
576
|
+
// 只在 404 之后才搜一次:search 池是 30 次/分钟(core 是 5000),不能滥用
|
|
577
|
+
const name = repo.split('/')[1] || repo
|
|
578
|
+
if (name.length >= 5) {
|
|
579
|
+
const search = await run('gh', ['api', 'search/repositories?q=' + encodeURIComponent(name + ' in:name') + '&per_page=5', '--jq', '.items[].full_name'],
|
|
580
|
+
{ timeoutMs: 10000, env: ghEnv() })
|
|
581
|
+
if (search.code === 0) {
|
|
582
|
+
const picked = pickSuggestion(repo, String(search.stdout || '').split(String.fromCharCode(10)).map((v) => v.trim()).filter(Boolean))
|
|
583
|
+
if (picked) hint = ' 是不是想填 ' + picked + '?'
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
warnings.push('仓库 ' + repo + ' 不存在,或当前 token 没有访问权限 —— 先确认名字(owner/name)与权限。' + hint)
|
|
587
|
+
return { warnings, notFound: true }
|
|
588
|
+
}
|
|
589
|
+
warnings.push('添加前没能确认这个仓库(' + detail.slice(0, 100) + '),稍后会在面板里再次探测。')
|
|
590
|
+
return { warnings }
|
|
591
|
+
}
|
|
592
|
+
let info = {}
|
|
593
|
+
try { info = JSON.parse(res.stdout) } catch { return { warnings } }
|
|
594
|
+
const note = repoStructureNote({
|
|
595
|
+
repo,
|
|
596
|
+
hasIssues: info.hasIssues !== false,
|
|
597
|
+
archived: info.archived === true,
|
|
598
|
+
disabled: info.disabled === true,
|
|
599
|
+
fork: info.fork === true,
|
|
600
|
+
parent: info.parent || null,
|
|
601
|
+
push: info.push === true,
|
|
602
|
+
private: info.private === true,
|
|
603
|
+
})
|
|
604
|
+
if (note) warnings.push(note)
|
|
605
|
+
return { warnings, access: { repo, push: info.push === true, private: info.private === true, fork: info.fork === true, hasIssues: info.hasIssues !== false, archived: info.archived === true, disabled: info.disabled === true, parent: info.parent || null, checkedAt: new Date().toISOString() } }
|
|
606
|
+
}
|
|
607
|
+
|
|
552
608
|
/** 隔离区占用:客户长期运行会攒下一堆一次性 worktree,面板上得看得见。 */
|
|
553
609
|
function isolationReport(entries) {
|
|
554
610
|
const roots = new Map()
|
|
@@ -1074,6 +1130,7 @@ export function apply(ctx) {
|
|
|
1074
1130
|
const state = readState()
|
|
1075
1131
|
state.watchers = state.watchers || {}
|
|
1076
1132
|
const id = repo + '#' + sessionId
|
|
1133
|
+
const created = !(state.watchers && state.watchers[id])
|
|
1077
1134
|
const entry = state.watchers[id] || {
|
|
1078
1135
|
id, repo, sessionId, cursor: null, seen: {}, lastReported: {},
|
|
1079
1136
|
cooldownMs: 180000, createdAt: new Date().toISOString(),
|
|
@@ -1105,6 +1162,14 @@ export function apply(ctx) {
|
|
|
1105
1162
|
entry.nextAt = null
|
|
1106
1163
|
// 没传 enabled 就保持原值:只改间隔/标签不该把暂停的 watcher 悄悄恢复
|
|
1107
1164
|
entry.enabled = body.enabled === undefined ? (entry.enabled !== false) : body.enabled !== false
|
|
1165
|
+
// 只有**新建**时才做添加前体检:编辑已有守不该再打一次网络
|
|
1166
|
+
const isNew = !created && !state.watchers[id]
|
|
1167
|
+
let warnings = []
|
|
1168
|
+
if (isNew) {
|
|
1169
|
+
const pre = await precheckRepo(repo)
|
|
1170
|
+
warnings = pre.warnings || []
|
|
1171
|
+
if (pre.access) entry.repoAccess = pre.access
|
|
1172
|
+
}
|
|
1108
1173
|
state.watchers[id] = entry
|
|
1109
1174
|
writeState(state)
|
|
1110
1175
|
// 编辑已有 watcher 时,间隔/配置变化要立刻生效:startWatcher 会因为 timer 已存在而直接返回
|
|
@@ -1114,7 +1179,7 @@ export function apply(ctx) {
|
|
|
1114
1179
|
|
|
1115
1180
|
startWatcher(entry)
|
|
1116
1181
|
}
|
|
1117
|
-
json(res, 200, { ok: true, id, repo, intervalSec, enabled: entry.enabled })
|
|
1182
|
+
json(res, 200, { ok: true, id, repo, intervalSec, enabled: entry.enabled, warnings })
|
|
1118
1183
|
},
|
|
1119
1184
|
})
|
|
1120
1185
|
|
package/lib/watch.js
CHANGED
|
@@ -619,3 +619,23 @@ export function repoBadges(repoAccess) {
|
|
|
619
619
|
if (repoAccess.private === true) badges.push({ text: '私有', tone: 'outline' })
|
|
620
620
|
return badges
|
|
621
621
|
}
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* 仓库名纠错:404 之后从搜索结果里挑一个最像的,别让客户自己猜。
|
|
625
|
+
*
|
|
626
|
+
* 依据:`GET /search/repositories?q=<name>+in:name` 能按仓库名检索;
|
|
627
|
+
* **但它走独立的 search 池**(本机实测 response header:`x-ratelimit-limit: 30`,
|
|
628
|
+
* 即 30 次/分钟,远小于 core 的 5000)—— 所以只能在 404 之后偶尔调用,绝不能每轮轮询都用。
|
|
629
|
+
* 出处:https://docs.github.com/en/rest/search/search#search-repositories
|
|
630
|
+
*/
|
|
631
|
+
export function pickSuggestion(query, candidates) {
|
|
632
|
+
const wanted = String(query || '').trim().toLowerCase()
|
|
633
|
+
if (!wanted) return null
|
|
634
|
+
const list = Array.isArray(candidates) ? candidates.filter((name) => typeof name === 'string') : []
|
|
635
|
+
const exactName = wanted.includes('/') ? wanted.split('/')[1] : wanted
|
|
636
|
+
// 优先级:仓库名完全相同 > 名字里包含 > 仅 owner 相同(最后这种基本没价值,直接丢)
|
|
637
|
+
const sameName = list.find((name) => name.toLowerCase().endsWith('/' + exactName))
|
|
638
|
+
if (sameName) return sameName
|
|
639
|
+
const contains = list.find((name) => name.toLowerCase().includes(exactName) && exactName.length >= 4)
|
|
640
|
+
return contains || null
|
|
641
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-superagent",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.69",
|
|
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",
|