dsh-session-superagent 0.8.61 → 0.8.63
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 +47 -0
- package/MAINTENANCE.md +1 -1
- package/README.md +2 -2
- package/client.js +11 -1
- package/lib/index.js +76 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,53 @@
|
|
|
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.63] - 2026-11-02 —— 面板显示 token 权限范围,宽 scope 会提醒
|
|
6
|
+
|
|
7
|
+
### 学到的(知识库第 12 条)
|
|
8
|
+
GitHub 细粒度 token 按「资源 × 操作 × 仓库」授权,经典 PAT 的 `repo` 却是该账号可见仓库的**全部读写**。
|
|
9
|
+
最小权限的意义在于泄漏后的影响面 —— 对一个跑在客户机器上的插件尤其重要。
|
|
10
|
+
|
|
11
|
+
本机实测当前 token 的 scopes:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
admin:repo_hook, delete:packages, gist, notifications, project,
|
|
15
|
+
read:org, read:user, repo, workflow, write:discussion, write:packages
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
其中 `delete:packages` / `admin:repo_hook` / `workflow` **我们一个都用不到**。
|
|
19
|
+
|
|
20
|
+
### 改了什么
|
|
21
|
+
- `gh api -i user` 读 `x-oauth-scopes`(**缓存 5 分钟**,不额外给每次 `/state` 加一次网络往返);
|
|
22
|
+
- `/state` 带 `tokenScopes`;设置页「来源」显示「权限范围: …」;
|
|
23
|
+
- 命中宽 scope 时多一行提示:建议换细粒度 token,只授 Issues 读写。
|
|
24
|
+
|
|
25
|
+
### 测试
|
|
26
|
+
- 合计 **116 例**(复用既有 /state 契约用例,未新增网络依赖)。
|
|
27
|
+
|
|
28
|
+
## [0.8.62] - 2026-11-02 —— Windows 上 `chmod 0600` 是假的,改用 ACL
|
|
29
|
+
|
|
30
|
+
### 学到的(知识库第 11 条,安全问题)
|
|
31
|
+
Node 文档 `fs.chmod` Caveats 原文:*"on Windows only the write permission can be changed,
|
|
32
|
+
and the distinction among the permissions of group, owner, or others is not implemented."*
|
|
33
|
+
|
|
34
|
+
我们把 GitHub token 写在 `<state>/secrets.json`,一直用 `{ mode: 0o600 }` —— **Windows 上约等于没保护**。
|
|
35
|
+
|
|
36
|
+
### 改了什么
|
|
37
|
+
写完立刻收紧:
|
|
38
|
+
- POSIX → `chmod 0600`;
|
|
39
|
+
- Windows → `icacls <file> /inheritance:r /grant:r <当前用户>:F`(断开继承,只留本人)。
|
|
40
|
+
结果记进 `secretsHardened`,`/diagnose` 显示「凭证保护: win32-acl」。
|
|
41
|
+
|
|
42
|
+
### 本机实测
|
|
43
|
+
```
|
|
44
|
+
收紧前: SYSTEM:(I)(F) / BUILTIN\Administrators:(I)(F) / OWNER RIGHTS:(I)(F)
|
|
45
|
+
收紧后: <用户>:(F)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 测试
|
|
49
|
+
- 新增 `test/secrets-acl.test.mjs`(Windows 专用):调 `hardenSecretsFile` 后用 `icacls` 回读,
|
|
50
|
+
断言当前用户有 `(F)`、且没有残留 Users 组。合计 **116 例**。
|
|
51
|
+
|
|
5
52
|
## [0.8.61] - 2026-11-02 —— 状态文件写坏了,也别把客户的守当"空"
|
|
6
53
|
|
|
7
54
|
### 学到的(知识库第 10 条)
|
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` 116/116 通过
|
|
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 # 116 项单测
|
|
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.63'
|
|
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
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
* - per-item watermarks, so our own writes never wake us (no self-echo);
|
|
13
13
|
* - advance the watermark only after a wake actually landed.
|
|
14
14
|
*/
|
|
15
|
-
import { spawn } from 'node:child_process'
|
|
15
|
+
import { execFileSync, spawn } from 'node:child_process'
|
|
16
16
|
import { randomUUID } from 'node:crypto'
|
|
17
17
|
import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from 'node:fs'
|
|
18
|
-
import { homedir } from 'node:os'
|
|
18
|
+
import os, { homedir } from 'node:os'
|
|
19
19
|
import { isAbsolute, join } from 'node:path'
|
|
20
20
|
|
|
21
21
|
import { zstdDecompressSync } from 'node:zlib'
|
|
@@ -30,11 +30,11 @@ import {
|
|
|
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.63'
|
|
34
34
|
export const inject = ['tools', 'agents', 'webServer']
|
|
35
35
|
|
|
36
36
|
/** 仅供测试:读写状态文件(生产代码不要用)。 */
|
|
37
|
-
export const __test = { readState, writeState }
|
|
37
|
+
export const __test = { readState, writeState, hardenSecretsFile }
|
|
38
38
|
|
|
39
39
|
const STATE_DIR = process.env.DSH_SUPERAGENT_STATE
|
|
40
40
|
? String(process.env.DSH_SUPERAGENT_STATE)
|
|
@@ -156,6 +156,8 @@ function writeSecrets(next) {
|
|
|
156
156
|
try {
|
|
157
157
|
mkdirSync(STATE_DIR, { recursive: true })
|
|
158
158
|
writeFileSync(SECRETS_FILE, JSON.stringify(next, null, 1), { mode: 0o600 })
|
|
159
|
+
// mode 在 Windows 上几乎无效,补 ACL(见 hardenSecretsFile 注释)
|
|
160
|
+
hardenSecretsFile(SECRETS_FILE)
|
|
159
161
|
} catch {}
|
|
160
162
|
}
|
|
161
163
|
|
|
@@ -481,6 +483,72 @@ function wake(ctx, sessionId, text) {
|
|
|
481
483
|
}
|
|
482
484
|
|
|
483
485
|
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* 收紧凭证文件权限。
|
|
489
|
+
*
|
|
490
|
+
* Node 文档明确:**on Windows only the write permission can be changed, and the distinction
|
|
491
|
+
* among the permissions of group, owner, or others is not implemented** —— 也就是说
|
|
492
|
+
* 光靠 `mode: 0o600` 在 Windows 上约等于没有保护,同机其他账户仍可能读到 token。
|
|
493
|
+
* 所以在 Windows 上补一条 icacls:断开继承,只给当前用户完全控制。
|
|
494
|
+
* 出处:https://nodejs.org/api/fs.html(fs.chmod 的 Caveats)
|
|
495
|
+
*/
|
|
496
|
+
let secretsHardened = 'unknown'
|
|
497
|
+
function hardenSecretsFile(file) {
|
|
498
|
+
if (process.platform !== 'win32') {
|
|
499
|
+
try {
|
|
500
|
+
chmodSync(file, 0o600)
|
|
501
|
+
secretsHardened = 'posix-0600'
|
|
502
|
+
} catch { secretsHardened = 'failed' }
|
|
503
|
+
return secretsHardened
|
|
504
|
+
}
|
|
505
|
+
try {
|
|
506
|
+
const user = os.userInfo().username
|
|
507
|
+
execFileSync('icacls', [file, '/inheritance:r', '/grant:r', user + ':F'], { stdio: 'ignore', timeout: 15000 })
|
|
508
|
+
secretsHardened = 'win32-acl'
|
|
509
|
+
} catch {
|
|
510
|
+
secretsHardened = 'failed'
|
|
511
|
+
}
|
|
512
|
+
return secretsHardened
|
|
513
|
+
}
|
|
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
|
+
|
|
484
552
|
/** 隔离区占用:客户长期运行会攒下一堆一次性 worktree,面板上得看得见。 */
|
|
485
553
|
function isolationReport(entries) {
|
|
486
554
|
const roots = new Map()
|
|
@@ -836,6 +904,8 @@ export function apply(ctx) {
|
|
|
836
904
|
const url = new URL(String(req.url || '/'), 'http://127.0.0.1')
|
|
837
905
|
const focusSession = url.searchParams.get('sessionId') || ''
|
|
838
906
|
const state = readState()
|
|
907
|
+
// 顺带刷新一次 token scopes(缓存 5 分钟;失败不影响 /state)
|
|
908
|
+
tokenScopes().catch(() => {})
|
|
839
909
|
const gh = await ghHealth()
|
|
840
910
|
const watchers = Object.values(state.watchers || {}).map((w) => ({
|
|
841
911
|
id: w.id || (w.repo + '#' + w.sessionId),
|
|
@@ -879,6 +949,7 @@ export function apply(ctx) {
|
|
|
879
949
|
credentials: secretsSummary(),
|
|
880
950
|
sessionGoal: goalView(ctx, focusSession),
|
|
881
951
|
stateSource,
|
|
952
|
+
tokenScopes: scopesCache.value || null,
|
|
882
953
|
isolation: isolationReport(Object.values(state.watchers || {})),
|
|
883
954
|
sessionTitle: sessionTitle(focusSession),
|
|
884
955
|
watchers: watchers.map((w) => ({ ...w, goal: goalView(ctx, w.sessionId) })),
|
|
@@ -1060,6 +1131,7 @@ export function apply(ctx) {
|
|
|
1060
1131
|
lines.push('主理鱼诊断 · ' + new Date().toISOString())
|
|
1061
1132
|
lines.push('插件版本: ' + SERVER_VERSION)
|
|
1062
1133
|
lines.push('宿主: DSH / node ' + String(process.version || ''))
|
|
1134
|
+
lines.push('凭证保护: ' + (secretsHardened === 'unknown' ? '未写入过 token' : secretsHardened))
|
|
1063
1135
|
lines.push('挂载: routes=' + String(mounted.routes ?? '?')
|
|
1064
1136
|
+ ' failed=' + String((mounted.failed || []).length)
|
|
1065
1137
|
+ ' base=' + String(mounted.base || '-')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-superagent",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.63",
|
|
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",
|