dsh-session-superagent 0.8.35 → 0.8.38
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 +91 -0
- package/MAINTENANCE.md +1 -1
- package/README.md +31 -2
- package/client.js +41 -1
- package/lib/index.js +74 -12
- package/lib/watch.js +34 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,84 @@
|
|
|
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.38] - 2026-11-02 —— 面板里就能看到「有没有新版本」
|
|
6
|
+
|
|
7
|
+
### 为什么
|
|
8
|
+
客户在自己电脑上用发布版。我这边修完、发到 npm,**客户不升级就一直跑旧版** ——
|
|
9
|
+
而他并不会主动去 `npm view`。所以「有没有新版本、该跑什么命令」应该长在面板里。
|
|
10
|
+
|
|
11
|
+
### 做法(只读,不替你安装)
|
|
12
|
+
新增 `GET /session-superagent/update`:
|
|
13
|
+
|
|
14
|
+
```json
|
|
15
|
+
{ "current": "0.8.38", "latest": "0.8.38", "hasUpdate": false,
|
|
16
|
+
"command": "dsh plugin --profile <你的 profile> add dsh-session-superagent@0.8.38" }
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
- 问 `registry.npmjs.org/<pkg>/latest`,5 秒超时,**内存缓存 10 分钟**(`?refresh=1` 强制刷新);
|
|
20
|
+
- 面板「设置 → 版本与更新」显示:当前版本 / npm 最新 / 状态,有新版本时给出命令 + 复制按钮;
|
|
21
|
+
- **不自动安装**:装要改 profile,而且装完必须重载宿主才生效 —— 这一步交给客户自己决定,面板里写明了。
|
|
22
|
+
|
|
23
|
+
### 顺带
|
|
24
|
+
- 路由面 6 → 7 条,测试与 preflight 里的断言同步更新;
|
|
25
|
+
- 客户端 hook 顺序变了(多两个 state),测试里的 `deskQueue` 同步补槽位。
|
|
26
|
+
|
|
27
|
+
### 测试
|
|
28
|
+
- 合计 **98 例**。
|
|
29
|
+
|
|
30
|
+
## [0.8.37] - 2026-11-02 —— 状态文件不再丢 watcher
|
|
31
|
+
|
|
32
|
+
### 真机现象(本机复现)
|
|
33
|
+
用 HTTP 建的一条 watcher,几秒后从状态文件里消失,只剩另一条 —— 同一天出现两次。
|
|
34
|
+
|
|
35
|
+
> 更正:早先我把一张**客户**截图(`Betsy20/magpie-Jet-Hub`)也算作案例,这是错的。
|
|
36
|
+
> 那是别人 PC 上跑我们插件的实例,本机的状态文件里当然没有它的条目;
|
|
37
|
+
> 这条修复的依据只是本机那次复现。
|
|
38
|
+
|
|
39
|
+
### 根因
|
|
40
|
+
`writeState()` 是**整份覆盖**。当两个写入者手里的快照不同(宿主热重载时新旧实例交替、
|
|
41
|
+
或工具与面板同时写),后写的那个会把别人刚建的条目一起抹掉 —— 原子写只能防"写一半崩掉",
|
|
42
|
+
防不住"用旧快照覆盖新内容"。
|
|
43
|
+
|
|
44
|
+
### 修法
|
|
45
|
+
`writeState()` 改成**合并写**:
|
|
46
|
+
- 盘上有、内存里没有的条目**一律保留**;
|
|
47
|
+
- 删除时立**墓碑**(`state.deleted[id] = 时间`),只有墓碑里的 id 允许消失,墓碑保留 7 天;
|
|
48
|
+
- 仍然原子落盘(tmp + rename)。
|
|
49
|
+
|
|
50
|
+
### 测试
|
|
51
|
+
- 新增 2 例:① 迟到的旧快照不能抹掉别人刚建的 watcher;② 删除后,一个仍持有旧快照的写入不能把它复活。合计 **97 例**。
|
|
52
|
+
|
|
53
|
+
## [0.8.36] - 2026-11-02 —— 面板上那串 `EOF` 原始报错,应该变成人话
|
|
54
|
+
|
|
55
|
+
真机截图里出现过这样一条:
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
Get "https://api.github.com/repos/…/issues?state=all&sort=updated&direction=desc&per_page=20": EOF
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
它既长又吓人,其实是**网络抖动**(我同一分钟手工跑 `gh api` 返回 14 条,完全正常)。
|
|
62
|
+
之前只有 401/404/找不到 gh 三种情况有提示,`EOF` 这类网络错误就原样怼给用户看。
|
|
63
|
+
|
|
64
|
+
### 改法
|
|
65
|
+
新增纯函数 `classifyGhError(detail)`,把失败分成 `auth / notfound / ratelimit / nogh / network / other`
|
|
66
|
+
六类,各配一句「该怎么做」;同时把长 URL 压成 `GitHub API 请求`,避免一整条 API 地址占满面板。
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
EOF → 网络抖动:这一轮没连上 GitHub,已按退避自动重试,不需要手动处理
|
|
70
|
+
HTTP 401 → gh 登录失效:跑 gh auth login,或在面板填 token
|
|
71
|
+
HTTP 403 rate limit → 被 GitHub 限流:等几分钟,或换成带 token 的凭证
|
|
72
|
+
HTTP 404 → 仓库不存在或没权限:检查 owner/name
|
|
73
|
+
gh: command not found → 找不到 gh 命令:确认已安装且在 PATH
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 顺带修掉的一个隐蔽 bug
|
|
77
|
+
写这个正则时 `` 被写成了**退格符(0x08)**,导致 `EOF` 那条永远匹配不上 ——
|
|
78
|
+
是「分类函数跑起来却发现 kind=other」才暴露的。已清掉文件里 4 个控制字符,并加用例钉住六种输入。
|
|
79
|
+
|
|
80
|
+
### 测试
|
|
81
|
+
- 新增用例:六类输入 + 长 URL 压缩。合计 **95 例**。
|
|
82
|
+
|
|
5
83
|
## [0.8.35] - 2026-11-02 —— 面板在跟哪一代,能查了
|
|
6
84
|
|
|
7
85
|
排查热重载问题时一直卡在一个观测盲点:面板每 5 秒轮询 `/state`,但**轮询不落任何痕迹**,
|
|
@@ -11,6 +89,19 @@
|
|
|
11
89
|
- 客户端探测到前缀并**发生切换**时,写一条 `client-base` 探针(服务端 `CLIENT_NOTE_KEYS` 放行该键)。
|
|
12
90
|
- 于是 `watchers.json → client['note:client-base']` 能直接回答「这个浏览器现在跟的是哪一代」。
|
|
13
91
|
|
|
92
|
+
### 真机闭环(2026-11-02 10:48:40)
|
|
93
|
+
用户打开一次「主理鱼」页之后:
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
note:client-base = /session-superagent/r5 ← 客户端自称在跟 r5
|
|
97
|
+
/session-superagent → routeBase=None(旧 handler,宿主留着)
|
|
98
|
+
/session-superagent/r5 → routeBase=/r5, serverVersion=0.8.35
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
时间线正好证明 0.8.34 的重探逻辑在真实环境里工作:
|
|
102
|
+
`02:41` 客户端加载(当时在 r4)→ `02:44:50` 服务端换到 r5 并释放 r4 →
|
|
103
|
+
`02:48:40` 面板首次轮询命中 404 → 重探 → 切到 r5 → 写探针。
|
|
104
|
+
|
|
14
105
|
### 测试
|
|
15
106
|
- 合计 **94 例**(探针属于运行时行为,靠真机确认)。
|
|
16
107
|
|
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` 98/98 通过
|
|
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,11 +99,40 @@ dsh plugin install /path/to/dsh-session-superagent
|
|
|
99
99
|
## 开发
|
|
100
100
|
|
|
101
101
|
```sh
|
|
102
|
-
node --test #
|
|
102
|
+
node --test # 98 项单测
|
|
103
103
|
```
|
|
104
104
|
|
|
105
105
|
版本与发布流程见 [UPDATING.md](UPDATING.md),交付门见 [CHECKLIST.md](CHECKLIST.md),接手台账见 [MAINTENANCE.md](MAINTENANCE.md)。
|
|
106
106
|
|
|
107
|
+
## 客户(Customer)
|
|
108
|
+
|
|
109
|
+
> **本文档里的「客户」= 在**其它电脑**上使用本插件的使用者**(不是本机的会话,也不是本仓库的贡献者)。
|
|
110
|
+
|
|
111
|
+
客户和本机的差别,决定了排查要看哪里:
|
|
112
|
+
|
|
113
|
+
| | 本机(开发者) | 客户 |
|
|
114
|
+
|---|---|---|
|
|
115
|
+
| 插件来源 | `file:` 硬链接到本仓库 | npm / 市场安装的发布版 |
|
|
116
|
+
| 状态文件 | `<DSH_HOME>/state/session-superagent/watchers.json` | 同路径,但在客户自己的 `~/.dsh/` 下 |
|
|
117
|
+
| 我能不能直接查 | 能 | **不能** —— 只能让客户贴信息 |
|
|
118
|
+
|
|
119
|
+
所以客户报问题时要这三样,缺一件就只能猜:
|
|
120
|
+
|
|
121
|
+
1. **版本**:面板「设置」页,或状态文件里 `client['note:client-version'].detail`;
|
|
122
|
+
2. **挂载状态**:状态文件里的 `server` 字段(`routes` / `failed` / `base`),或让客户跑一次 `watch_doctor`;
|
|
123
|
+
3. **出错那行的原文**:0.8.36 起 gh 失败会被分类成人话(网络抖动 / 凭证失效 / 限流 / 仓库不存在 / 没装 gh)。
|
|
124
|
+
|
|
125
|
+
**客户升级**:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
dsh plugin --profile <profile> add dsh-session-superagent@latest
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
(客户机器上 `npm i` 不会生效 —— 必须装进 profile,见上面的「安装」。)
|
|
132
|
+
|
|
133
|
+
**本机复现不了客户的问题**:`EOF` / 超时 / 代理这类错误取决于客户的网络,本机能访问同一个仓库不代表客户能。
|
|
134
|
+
遇到这种情况,先按上面的三样收集信息,再判断是环境还是代码。
|
|
135
|
+
|
|
107
136
|
## 故障排查(都是真实踩过的)
|
|
108
137
|
|
|
109
138
|
| 症状 | 原因 | 处理 |
|
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.38'
|
|
18
18
|
let BASE = '/session-superagent'
|
|
19
19
|
/**
|
|
20
20
|
* 挑「最新的那个服务端实例」。
|
|
@@ -693,6 +693,9 @@ window.__ModuleLoader__.load({
|
|
|
693
693
|
const [draft, setDraft] = useState({})
|
|
694
694
|
const [search, setSearch] = useState('')
|
|
695
695
|
const [glossary, setGlossary] = useState(false)
|
|
696
|
+
// 版本检查结果(只读):面板里直接告诉客户「有没有新版本、该跑什么命令」
|
|
697
|
+
const [update, setUpdate] = useState(null)
|
|
698
|
+
const [checking, setChecking] = useState(false)
|
|
696
699
|
|
|
697
700
|
const load = useCallback(async () => {
|
|
698
701
|
try {
|
|
@@ -975,6 +978,21 @@ window.__ModuleLoader__.load({
|
|
|
975
978
|
field('Token', h(Input, { type: 'password', value: token, placeholder: 'ghp_… / github_pat_…(留空不改)', onChange: (e) => setToken(e.target.value) })),
|
|
976
979
|
h('div', { className: 'dt-actions' }, h(Btn, { variant: 'primary', onClick: saveCredentials }, '保存凭证')),
|
|
977
980
|
h(Hint, null, '不填也能用:插件直接复用已登录的 gh CLI。')),
|
|
981
|
+
h(Section, { key: 'update', title: '版本与更新' },
|
|
982
|
+
h(KeyValues, { rows: [
|
|
983
|
+
['当前版本', (update && update.current) || CLIENT_VERSION],
|
|
984
|
+
['npm 最新', !update ? '检测中…' : update.error ? '检测失败 · ' + update.error : (update.latest || '未知')],
|
|
985
|
+
['状态', !update ? '…' : update.hasUpdate ? '有新版本,可以升级' : '已是最新'],
|
|
986
|
+
] }),
|
|
987
|
+
update && update.hasUpdate
|
|
988
|
+
? h('div', null,
|
|
989
|
+
h('code', { className: 'dt-code' }, update.command),
|
|
990
|
+
h('div', { className: 'dt-actions' },
|
|
991
|
+
h(Btn, { size: 'sm', onClick: () => { try { navigator.clipboard.writeText(update.command) } catch {} } }, '复制命令')))
|
|
992
|
+
: null,
|
|
993
|
+
h('div', { className: 'dt-actions' },
|
|
994
|
+
h(Btn, { size: 'sm', variant: 'ghost', onClick: () => checkUpdate(true), disabled: checking }, checking ? '检查中…' : '重新检查')),
|
|
995
|
+
h(Hint, null, '升级要改 profile,装完需要重载一次宿主才会用上新版本 —— 所以这里只给命令,不替你执行。')),
|
|
978
996
|
h(Section, { key: 'goal', title: '会话 goal' },
|
|
979
997
|
h('textarea', {
|
|
980
998
|
className: 'dt-textarea', rows: 3, value: goalDraft,
|
|
@@ -984,6 +1002,28 @@ window.__ModuleLoader__.load({
|
|
|
984
1002
|
h('div', { className: 'dt-actions' }, h(Btn, { variant: 'primary', onClick: saveGoal, disabled: !sessionId }, '保存 goal'))),
|
|
985
1003
|
]
|
|
986
1004
|
|
|
1005
|
+
const checkUpdate = useCallback(async (force) => {
|
|
1006
|
+
setChecking(true)
|
|
1007
|
+
try {
|
|
1008
|
+
const value = await call('/update' + (force ? '?refresh=1' : ''))
|
|
1009
|
+
setUpdate(value)
|
|
1010
|
+
} catch (error) {
|
|
1011
|
+
setUpdate({ current: CLIENT_VERSION, latest: null, hasUpdate: false, error: String(error && error.message || error) })
|
|
1012
|
+
} finally {
|
|
1013
|
+
setChecking(false)
|
|
1014
|
+
}
|
|
1015
|
+
}, [])
|
|
1016
|
+
|
|
1017
|
+
useEffect(() => {
|
|
1018
|
+
let alive = true
|
|
1019
|
+
try {
|
|
1020
|
+
Promise.resolve(call('/update'))
|
|
1021
|
+
.then((value) => { if (alive) setUpdate(value) })
|
|
1022
|
+
.catch(() => {})
|
|
1023
|
+
} catch { /* 宿主早期渲染时 fetch 可能还不存在,忽略即可 */ }
|
|
1024
|
+
return () => { alive = false }
|
|
1025
|
+
}, [])
|
|
1026
|
+
|
|
987
1027
|
function field(label, control) {
|
|
988
1028
|
return h('label', { className: 'dt-field', key: label }, h('span', { className: 'dt-field-head' }, label), control)
|
|
989
1029
|
}
|
package/lib/index.js
CHANGED
|
@@ -24,15 +24,18 @@ 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
|
-
filterReason, hasAckLabel, inActiveHours, newestUpdatedAt, nextDelayMs, pushFiltered, normalizeFilters, partitionItems, passesFilters,
|
|
27
|
+
classifyGhError, filterReason, hasAckLabel, 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.38'
|
|
34
34
|
export const inject = ['tools', 'agents', 'webServer']
|
|
35
35
|
|
|
36
|
+
/** 仅供测试:读写状态文件(生产代码不要用)。 */
|
|
37
|
+
export const __test = { readState, writeState }
|
|
38
|
+
|
|
36
39
|
const STATE_DIR = process.env.DSH_SUPERAGENT_STATE
|
|
37
40
|
? String(process.env.DSH_SUPERAGENT_STATE)
|
|
38
41
|
: join(homedir(), '.dsh', 'state', 'session-superagent')
|
|
@@ -75,12 +78,30 @@ function readState() {
|
|
|
75
78
|
function writeState(state) {
|
|
76
79
|
try {
|
|
77
80
|
mkdirSync(STATE_DIR, { recursive: true })
|
|
78
|
-
|
|
81
|
+
// 合并写:调用方手里的 state 可能是很久以前读的快照(宿主重载、两个实例交替写),
|
|
82
|
+
// 直接整份覆盖会把别人刚建的 watcher 抹掉 —— 真机上丢过两条(一条是用户的)。
|
|
83
|
+
// 规则:盘上有、内存里没有的条目一律保留;只有墓碑里的 id 才允许消失。
|
|
84
|
+
const disk = readState()
|
|
85
|
+
const tombstones = { ...(disk.deleted || {}), ...(state.deleted || {}) }
|
|
86
|
+
const merged = { ...disk, ...state }
|
|
87
|
+
merged.watchers = { ...(disk.watchers || {}) }
|
|
88
|
+
for (const [id, watcher] of Object.entries(state.watchers || {})) merged.watchers[id] = watcher
|
|
89
|
+
const now = Date.now()
|
|
90
|
+
for (const [id, at] of Object.entries(tombstones)) {
|
|
91
|
+
delete merged.watchers[id]
|
|
92
|
+
// 墓碑留 7 天足够覆盖任何迟到写入
|
|
93
|
+
if (now - Date.parse(at) > 7 * 24 * 3600 * 1000) delete tombstones[id]
|
|
94
|
+
}
|
|
95
|
+
if (Object.keys(tombstones).length > 0) merged.deleted = tombstones
|
|
96
|
+
else delete merged.deleted
|
|
97
|
+
|
|
98
|
+
const text = JSON.stringify(merged, null, 1)
|
|
79
99
|
// 原子写:写一半崩掉不该把全部 watcher 清空
|
|
80
100
|
const tmp = STATE_FILE + '.tmp'
|
|
81
101
|
writeFileSync(tmp, text)
|
|
82
102
|
try { renameSync(tmp, STATE_FILE) } catch { writeFileSync(STATE_FILE, text) }
|
|
83
|
-
|
|
103
|
+
return merged
|
|
104
|
+
} catch { return state /* state is best-effort: a failed write must not break a turn */ }
|
|
84
105
|
}
|
|
85
106
|
|
|
86
107
|
/** Credentials the operator typed in the panel. Never returned in plain text. */
|
|
@@ -421,14 +442,8 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
421
442
|
if (res.code !== 0) {
|
|
422
443
|
const detail = redact(res.stderr).slice(0, 240)
|
|
423
444
|
// 常见失败给一句能照着做的提示,别只丢原始 stderr
|
|
424
|
-
const
|
|
425
|
-
|
|
426
|
-
: /HTTP 404|Not Found/i.test(detail)
|
|
427
|
-
? '(仓库不存在或没权限:检查 owner/name)'
|
|
428
|
-
: /ENOENT|not found.*gh|gh.*not found/i.test(detail)
|
|
429
|
-
? '(找不到 gh 命令:确认已安装且在 PATH)'
|
|
430
|
-
: ''
|
|
431
|
-
entry.lastError = (detail + hint).slice(0, 300)
|
|
445
|
+
const classified = classifyGhError(detail)
|
|
446
|
+
entry.lastError = (classified.short + classified.hint).slice(0, 300)
|
|
432
447
|
bumpFailure(entry, baseMs)
|
|
433
448
|
return
|
|
434
449
|
}
|
|
@@ -612,6 +627,37 @@ export function apply(ctx) {
|
|
|
612
627
|
return true
|
|
613
628
|
}
|
|
614
629
|
|
|
630
|
+
/**
|
|
631
|
+
* 版本检查(只读):问 npm registry 最新版是多少,和本实例版本比。
|
|
632
|
+
* 不触发安装 —— 装/升级要改 profile,必须由人执行且升级后要重载宿主。
|
|
633
|
+
* 10 分钟内存缓存,避免面板每次刷新都打 registry。
|
|
634
|
+
*/
|
|
635
|
+
const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
636
|
+
let updateCache = null
|
|
637
|
+
const checkUpdate = async (force) => {
|
|
638
|
+
if (!force && updateCache && Date.now() - updateCache.at < UPDATE_CACHE_MS) return updateCache.value
|
|
639
|
+
const current = SERVER_VERSION
|
|
640
|
+
const value = { current, latest: null, publishedAt: null, hasUpdate: false, command: '', error: null }
|
|
641
|
+
try {
|
|
642
|
+
const res = await fetch('https://registry.npmjs.org/' + encodeURIComponent('dsh-session-superagent') + '/latest', {
|
|
643
|
+
signal: AbortSignal.timeout(5000),
|
|
644
|
+
headers: { accept: 'application/json' },
|
|
645
|
+
})
|
|
646
|
+
if (!res.ok) throw new Error('HTTP ' + res.status)
|
|
647
|
+
const body = await res.json()
|
|
648
|
+
value.latest = String(body.version || '')
|
|
649
|
+
const published = typeof body.dist?.tarball === 'string' ? body.dist.tarball : ''
|
|
650
|
+
if (published) value.publishedAt = published
|
|
651
|
+
const score = (v) => String(v || '0').split('.').map((n) => Number(n) || 0).reduce((acc, n) => acc * 1000 + n, 0)
|
|
652
|
+
value.hasUpdate = score(value.latest) > score(current)
|
|
653
|
+
value.command = 'dsh plugin --profile <你的 profile> add dsh-session-superagent@' + (value.latest || 'latest')
|
|
654
|
+
} catch (error) {
|
|
655
|
+
value.error = String((error && error.message) || error).slice(0, 160)
|
|
656
|
+
}
|
|
657
|
+
updateCache = { at: Date.now(), value }
|
|
658
|
+
return value
|
|
659
|
+
}
|
|
660
|
+
|
|
615
661
|
// Read-only status endpoints for the web panel. `httpServer` is looked up
|
|
616
662
|
// through ctx.inject: the service may load after this plugin, and ctx.get()
|
|
617
663
|
// does not wait for it.
|
|
@@ -764,6 +810,10 @@ export function apply(ctx) {
|
|
|
764
810
|
}
|
|
765
811
|
const result = applyWatcherAction(state, { action, id })
|
|
766
812
|
if (!result.ok) return json(res, 400, result)
|
|
813
|
+
if (result.deleted) {
|
|
814
|
+
// 立墓碑:否则一个持有旧快照的写入会把这条又"复活"
|
|
815
|
+
state.deleted = { ...(state.deleted || {}), [id]: new Date().toISOString() }
|
|
816
|
+
}
|
|
767
817
|
if (result.deleted || result.enabled === false) stopWatcher(id)
|
|
768
818
|
writeState(state)
|
|
769
819
|
if (result.enabled === true) startWatcher(state.watchers[id])
|
|
@@ -856,6 +906,18 @@ export function apply(ctx) {
|
|
|
856
906
|
},
|
|
857
907
|
})
|
|
858
908
|
|
|
909
|
+
// 版本检查(只读;面板「设置」页那一行「有新版本」靠它)
|
|
910
|
+
addRoute({
|
|
911
|
+
kind: 'exact',
|
|
912
|
+
path: '/session-superagent/update',
|
|
913
|
+
handler: async (req, res) => {
|
|
914
|
+
if (req.method !== 'GET') return json(res, 405, { error: 'method not allowed' })
|
|
915
|
+
const url = new URL(String(req.url || '/'), 'http://127.0.0.1')
|
|
916
|
+
const value = await checkUpdate(url.searchParams.get('refresh') === '1')
|
|
917
|
+
json(res, 200, value)
|
|
918
|
+
},
|
|
919
|
+
})
|
|
920
|
+
|
|
859
921
|
// Set / edit / clear the session's REAL goal through ctx.goals — the same
|
|
860
922
|
// service the /goal command drives, so the panel and the conversation are
|
|
861
923
|
// one source of truth (polling reads it back).
|
package/lib/watch.js
CHANGED
|
@@ -383,3 +383,37 @@ export function mergeFilters(base, patch) {
|
|
|
383
383
|
if ('assignee' in patch) next.assignee = normalizeFilters({ assignee: patch.assignee }).assignee
|
|
384
384
|
return next
|
|
385
385
|
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* 把 gh 失败时的原始文本归类成「一句话原因 + 该怎么做」。
|
|
389
|
+
*
|
|
390
|
+
* 真机上出现过 `Get "https://api.github.com/...": EOF` 这种直接怼给用户看的原始报错 ——
|
|
391
|
+
* 它既长又吓人,其实是**网络抖动**,自动退避重试就会好。这里把它变成人话。
|
|
392
|
+
*
|
|
393
|
+
* @returns {{ kind: string, short: string, hint: string }}
|
|
394
|
+
*/
|
|
395
|
+
export function classifyGhError(detail) {
|
|
396
|
+
const text = String(detail || '')
|
|
397
|
+
// 长 URL 压缩,避免一整条 API 地址占满面板
|
|
398
|
+
const short = text
|
|
399
|
+
.replace(/Get "https?:\/\/[^"]{16,}"/g, 'GitHub API 请求')
|
|
400
|
+
.replace(/Post "https?:\/\/[^"]{16,}"/g, 'GitHub API 请求')
|
|
401
|
+
.slice(0, 200)
|
|
402
|
+
|
|
403
|
+
if (/HTTP 401|Bad credentials|requires authentication/i.test(text)) {
|
|
404
|
+
return { kind: 'auth', short, hint: '(gh 登录失效:跑 gh auth login,或在面板填 token)' }
|
|
405
|
+
}
|
|
406
|
+
if (/HTTP 403|rate limit|API rate limit exceeded/i.test(text)) {
|
|
407
|
+
return { kind: 'ratelimit', short, hint: '(被 GitHub 限流:等几分钟,或换成带 token 的凭证)' }
|
|
408
|
+
}
|
|
409
|
+
if (/ENOENT|not found.*gh|gh: command not found/i.test(text)) {
|
|
410
|
+
return { kind: 'nogh', short, hint: '(找不到 gh 命令:确认已安装且在 PATH)' }
|
|
411
|
+
}
|
|
412
|
+
if (/HTTP 404|HTTP 403|Not Found[\s\S]*404|Not Found/.test(text)) {
|
|
413
|
+
return { kind: 'notfound', short, hint: '(仓库不存在或没权限:检查 owner/name)' }
|
|
414
|
+
}
|
|
415
|
+
if (/EOF|i\/o timeout|connection reset|dial tcp|TLS handshake|no such host|proxyconnect|timeout/i.test(text)) {
|
|
416
|
+
return { kind: 'network', short, hint: '(网络抖动:这一轮没连上 GitHub,已按退避自动重试,不需要手动处理)' }
|
|
417
|
+
}
|
|
418
|
+
return { kind: 'other', short, hint: '' }
|
|
419
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-superagent",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.38",
|
|
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",
|