dsh-session-superagent 0.8.62 → 0.8.64
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 +38 -0
- package/MAINTENANCE.md +1 -1
- package/README.md +2 -2
- package/client.js +11 -1
- package/lib/index.js +57 -2
- package/lib/watch.js +19 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,44 @@
|
|
|
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.64] - 2026-11-02 —— 只读仓库提前说清楚,别等它吃 403
|
|
6
|
+
|
|
7
|
+
### 学到的(知识库第 13 条)
|
|
8
|
+
`GET /repos/{owner}/{repo}` 返回 `permissions: { admin, push, pull … }` ——
|
|
9
|
+
「你对这个仓库能做什么」的权威答案,读之前就知道,不用试一次拿 403。
|
|
10
|
+
<https://docs.github.com/en/rest/repos/repos#get-a-repository>
|
|
11
|
+
|
|
12
|
+
### 改了什么
|
|
13
|
+
- 新增守时**后台**查一次仓库权限(不阻塞创建),存 `entry.repoAccess`;
|
|
14
|
+
- `push === false` 时唤醒消息多一行 `【权限提示】… 只有读权限 …`;
|
|
15
|
+
- 还没探测到(未知)时**不猜、不提示**。
|
|
16
|
+
|
|
17
|
+
### 测试
|
|
18
|
+
- 新增 1 例:有写权限不提示 / null 与空对象不提示 / 只读给人话 / 消息里单独成行。合计 **117 例**。
|
|
19
|
+
|
|
20
|
+
## [0.8.63] - 2026-11-02 —— 面板显示 token 权限范围,宽 scope 会提醒
|
|
21
|
+
|
|
22
|
+
### 学到的(知识库第 12 条)
|
|
23
|
+
GitHub 细粒度 token 按「资源 × 操作 × 仓库」授权,经典 PAT 的 `repo` 却是该账号可见仓库的**全部读写**。
|
|
24
|
+
最小权限的意义在于泄漏后的影响面 —— 对一个跑在客户机器上的插件尤其重要。
|
|
25
|
+
|
|
26
|
+
本机实测当前 token 的 scopes:
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
admin:repo_hook, delete:packages, gist, notifications, project,
|
|
30
|
+
read:org, read:user, repo, workflow, write:discussion, write:packages
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
其中 `delete:packages` / `admin:repo_hook` / `workflow` **我们一个都用不到**。
|
|
34
|
+
|
|
35
|
+
### 改了什么
|
|
36
|
+
- `gh api -i user` 读 `x-oauth-scopes`(**缓存 5 分钟**,不额外给每次 `/state` 加一次网络往返);
|
|
37
|
+
- `/state` 带 `tokenScopes`;设置页「来源」显示「权限范围: …」;
|
|
38
|
+
- 命中宽 scope 时多一行提示:建议换细粒度 token,只授 Issues 读写。
|
|
39
|
+
|
|
40
|
+
### 测试
|
|
41
|
+
- 合计 **116 例**(复用既有 /state 契约用例,未新增网络依赖)。
|
|
42
|
+
|
|
5
43
|
## [0.8.62] - 2026-11-02 —— Windows 上 `chmod 0600` 是假的,改用 ACL
|
|
6
44
|
|
|
7
45
|
### 学到的(知识库第 11 条,安全问题)
|
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` 117/117 通过
|
|
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 # 117 项单测
|
|
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.64'
|
|
18
18
|
let BASE = '/session-superagent'
|
|
19
19
|
/**
|
|
20
20
|
* 挑「最新的那个服务端实例」。
|
|
@@ -1173,6 +1173,16 @@ window.__ModuleLoader__.load({
|
|
|
1173
1173
|
['仓库', watchers.length === 0 ? '未绑定' : watchers.map((w) => w.repo).join(', ')],
|
|
1174
1174
|
['gh CLI', !body.gh ? '检测中…' : body.gh.ok ? '可用 · ' + (body.gh.version || '') : '不可用 · ' + (body.gh.error || '')],
|
|
1175
1175
|
['凭证', credentials.token === 'none' ? '回退到 gh CLI 登录态' : '使用面板配置的 token'],
|
|
1176
|
+
['权限范围', (() => {
|
|
1177
|
+
const info = body.tokenScopes
|
|
1178
|
+
if (!info) return '正在探测…'
|
|
1179
|
+
if (!info.ok) return '探测失败:' + String(info.error || '').slice(0, 60)
|
|
1180
|
+
if (!info.scopes.length) return '细粒度 token(无 OAuth scope)'
|
|
1181
|
+
return info.scopes.join(', ')
|
|
1182
|
+
})()],
|
|
1183
|
+
(body.tokenScopes && body.tokenScopes.broad && body.tokenScopes.broad.length > 0)
|
|
1184
|
+
? ['提示', '这个 token 带 ' + body.tokenScopes.broad.join(', ') + ' —— 我们的功能只需要「读 issue/PR + 写评论和标签」,建议换细粒度 token 只授 Issues 读写']
|
|
1185
|
+
: null,
|
|
1176
1186
|
['隔离占用', !body.isolation || (body.isolation.roots || []).length === 0
|
|
1177
1187
|
? '没有开隔离执行'
|
|
1178
1188
|
: (body.isolation.roots || []).map((r) => r.count + ' 个 · ' + bytesText(r.bytes)).join(';')
|
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
|
-
classifyGhError, countReasons, filterReason, hasAckLabel, jitterMs, parseGhInclude, retryAfterMs, throttleDelayMs, inActiveHours, newestUpdatedAt, nextDelayMs, pushFiltered, normalizeFilters, partitionItems, passesFilters,
|
|
27
|
+
accessNote, classifyGhError, 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.64'
|
|
34
34
|
export const inject = ['tools', 'agents', 'webServer']
|
|
35
35
|
|
|
36
36
|
/** 仅供测试:读写状态文件(生产代码不要用)。 */
|
|
@@ -512,6 +512,43 @@ function hardenSecretsFile(file) {
|
|
|
512
512
|
return secretsHardened
|
|
513
513
|
}
|
|
514
514
|
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* token 的权限范围(scopes)。
|
|
518
|
+
*
|
|
519
|
+
* 为什么值得看:GitHub 明确建议「最小权限」——细粒度 token 按端点授予,
|
|
520
|
+
* 而经典 PAT 的 `repo` 一把就是全仓库读写。我们的实现只需要
|
|
521
|
+
* 「读 issue/PR + 写评论和标签」,用 `delete:packages`、`admin:repo_hook` 这类 scope 纯属多余暴露。
|
|
522
|
+
* 出处:https://docs.github.com/en/rest/authentication/permissions-required-for-fine-grained-personal-access-tokens
|
|
523
|
+
*
|
|
524
|
+
* 探测成本约 0.5 秒(起一个 gh 进程),所以缓存 5 分钟,别在每次 /state 里都跑。
|
|
525
|
+
*/
|
|
526
|
+
let scopesCache = { at: 0, value: null }
|
|
527
|
+
const BROAD_SCOPES = ['delete:packages', 'admin:repo_hook', 'admin:org', 'workflow', 'write:packages', 'admin:public_key']
|
|
528
|
+
|
|
529
|
+
async function tokenScopes() {
|
|
530
|
+
if (scopesCache.value && Date.now() - scopesCache.at < 5 * 60 * 1000) return scopesCache.value
|
|
531
|
+
const res = await run('gh', ['api', '-i', 'user'], { timeoutMs: 20000, env: ghEnv() })
|
|
532
|
+
let value = { ok: false, scopes: [], broad: [], error: null, checkedAt: new Date().toISOString() }
|
|
533
|
+
if (res.code !== 0) {
|
|
534
|
+
value.error = redact(res.stderr).slice(0, 160)
|
|
535
|
+
} else {
|
|
536
|
+
const text = String(res.stdout || '')
|
|
537
|
+
const line = text.split(String.fromCharCode(10)).find((l) => l.toLowerCase().startsWith('x-oauth-scopes:'))
|
|
538
|
+
const raw = line ? line.slice('x-oauth-scopes:'.length).trim() : ''
|
|
539
|
+
const scopes = raw ? raw.split(',').map((v) => v.trim()).filter(Boolean) : []
|
|
540
|
+
value = {
|
|
541
|
+
ok: true,
|
|
542
|
+
scopes,
|
|
543
|
+
broad: scopes.filter((scope) => BROAD_SCOPES.includes(scope)),
|
|
544
|
+
error: null,
|
|
545
|
+
checkedAt: new Date().toISOString(),
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
scopesCache = { at: Date.now(), value }
|
|
549
|
+
return value
|
|
550
|
+
}
|
|
551
|
+
|
|
515
552
|
/** 隔离区占用:客户长期运行会攒下一堆一次性 worktree,面板上得看得见。 */
|
|
516
553
|
function isolationReport(entries) {
|
|
517
554
|
const roots = new Map()
|
|
@@ -701,6 +738,8 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
701
738
|
isolation,
|
|
702
739
|
// entry.goal 之前只写不读:现在真的进唤醒消息
|
|
703
740
|
goal: entry.goal || '',
|
|
741
|
+
// 只读仓库要在任务书里直说,否则会话会去试写然后吃 403
|
|
742
|
+
access: accessNote(entry.repoAccess),
|
|
704
743
|
// 完成标准要可观测(Given-When-Then 的思路):三件事缺一不算完成
|
|
705
744
|
criteria: [
|
|
706
745
|
'改了什么:文件清单 + 一句话为什么(别只写"已修复")',
|
|
@@ -746,6 +785,17 @@ export function apply(ctx) {
|
|
|
746
785
|
// 跨模块实例共享:旧实例还没跑完的那轮,新实例不能同时再跑一遍。
|
|
747
786
|
const inFlight = sharedInFlight
|
|
748
787
|
|
|
788
|
+
/** 后台查一次仓库权限:push=false 说明只能读,回写评论/标签都会 403。 */
|
|
789
|
+
const probeAccess = async (entry) => {
|
|
790
|
+
try {
|
|
791
|
+
const res = await run('gh', ['api', 'repos/' + entry.repo, '--jq', '{push: .permissions.push, private: .private}'], { timeoutMs: 20000, env: ghEnv() })
|
|
792
|
+
if (res.code !== 0) return
|
|
793
|
+
const info = JSON.parse(res.stdout)
|
|
794
|
+
entry.repoAccess = { repo: entry.repo, push: info.push === true, private: info.private === true, checkedAt: new Date().toISOString() }
|
|
795
|
+
persistEntry(entry)
|
|
796
|
+
} catch { /* 探测失败不影响主流程 */ }
|
|
797
|
+
}
|
|
798
|
+
|
|
749
799
|
const startWatcher = (entry) => {
|
|
750
800
|
if (timers.has(entry.id)) return
|
|
751
801
|
const every = Math.max(30, Number(entry.intervalSec) || 60) * 1000
|
|
@@ -867,6 +917,8 @@ export function apply(ctx) {
|
|
|
867
917
|
const url = new URL(String(req.url || '/'), 'http://127.0.0.1')
|
|
868
918
|
const focusSession = url.searchParams.get('sessionId') || ''
|
|
869
919
|
const state = readState()
|
|
920
|
+
// 顺带刷新一次 token scopes(缓存 5 分钟;失败不影响 /state)
|
|
921
|
+
tokenScopes().catch(() => {})
|
|
870
922
|
const gh = await ghHealth()
|
|
871
923
|
const watchers = Object.values(state.watchers || {}).map((w) => ({
|
|
872
924
|
id: w.id || (w.repo + '#' + w.sessionId),
|
|
@@ -910,6 +962,7 @@ export function apply(ctx) {
|
|
|
910
962
|
credentials: secretsSummary(),
|
|
911
963
|
sessionGoal: goalView(ctx, focusSession),
|
|
912
964
|
stateSource,
|
|
965
|
+
tokenScopes: scopesCache.value || null,
|
|
913
966
|
isolation: isolationReport(Object.values(state.watchers || {})),
|
|
914
967
|
sessionTitle: sessionTitle(focusSession),
|
|
915
968
|
watchers: watchers.map((w) => ({ ...w, goal: goalView(ctx, w.sessionId) })),
|
|
@@ -1044,6 +1097,8 @@ export function apply(ctx) {
|
|
|
1044
1097
|
// 编辑已有 watcher 时,间隔/配置变化要立刻生效:startWatcher 会因为 timer 已存在而直接返回
|
|
1045
1098
|
if (entry.enabled) {
|
|
1046
1099
|
stopWatcher(id)
|
|
1100
|
+
probeAccess(entry).catch(() => {})
|
|
1101
|
+
|
|
1047
1102
|
startWatcher(entry)
|
|
1048
1103
|
}
|
|
1049
1104
|
json(res, 200, { ok: true, id, repo, intervalSec, enabled: entry.enabled })
|
package/lib/watch.js
CHANGED
|
@@ -133,6 +133,7 @@ export function formatWatchText(repo, fresh, options = {}) {
|
|
|
133
133
|
})()
|
|
134
134
|
// 完成标准要「可观测」:只说"做好它"等于没说。
|
|
135
135
|
// 依据:Given-When-Then 的核心是把验收写成可观察的结果(martinfowler.com/bliki/GivenWhenThen.html)。
|
|
136
|
+
const accessLine = options.access ? String.fromCharCode(10) + '【权限提示】' + options.access : ''
|
|
136
137
|
const criteria = Array.isArray(options.criteria) ? options.criteria.filter(Boolean).slice(0, 4) : []
|
|
137
138
|
const criteriaLine = criteria.length > 0
|
|
138
139
|
? String.fromCharCode(10) + '【完成标准】' + String.fromCharCode(10)
|
|
@@ -145,6 +146,7 @@ export function formatWatchText(repo, fresh, options = {}) {
|
|
|
145
146
|
moreLine +
|
|
146
147
|
isoLine +
|
|
147
148
|
goalLine +
|
|
149
|
+
accessLine +
|
|
148
150
|
criteriaLine +
|
|
149
151
|
'\n\n先读仓库 AGENTS.md 的判断规则,再决定「修 / 回 / 待定」。完成标准 = 有测试结果:没跑测试不算完成,跑不了就写清原因;做完一条就写回 GitHub,并调用 watch_ack 打上已处理标签,不要扩大范围。'
|
|
150
152
|
)
|
|
@@ -552,3 +554,20 @@ export function countReasons(counts, reason, { maxKinds = 12 } = {}) {
|
|
|
552
554
|
const entries = Object.entries(map).sort((a, b) => b[1] - a[1]).slice(0, maxKinds)
|
|
553
555
|
return Object.fromEntries(entries)
|
|
554
556
|
}
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* 仓库权限提示:只读仓库上我们**没法**回写结果(评论、打标签都会 403)。
|
|
560
|
+
*
|
|
561
|
+
* 依据:`GET /repos/{owner}/{repo}` 返回 `permissions.push`,官方文档里这个对象就是
|
|
562
|
+
* "你有没有写权限"的权威来源。事先知道,比跑到一半才发现 403 好。
|
|
563
|
+
* 出处:https://docs.github.com/en/rest/repos/repos#get-a-repository
|
|
564
|
+
*/
|
|
565
|
+
export function accessNote(repoAccess) {
|
|
566
|
+
if (!repoAccess || typeof repoAccess !== 'object') return ''
|
|
567
|
+
if (repoAccess.push === true) return ''
|
|
568
|
+
if (repoAccess.push === false) {
|
|
569
|
+
return '你对 ' + String(repoAccess.repo || '这个仓库') + ' 只有读权限:能看、能被叫醒,但没法回写评论或打标签 —— '
|
|
570
|
+
+ '要么换有写权限的 token,要么把结论写在本地/PR 描述里。'
|
|
571
|
+
}
|
|
572
|
+
return ''
|
|
573
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-superagent",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.64",
|
|
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",
|