dsh-session-superagent 0.9.270 → 0.9.272
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 +55 -0
- package/README.md +3 -3
- package/client.js +76 -11
- package/lib/index.js +86 -13
- package/lib/update.js +346 -0
- package/package.json +2 -1
- package/ui-orbit-popover.js +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,61 @@
|
|
|
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.272] - 2026-11-06 —— 界面更新补上真实 DSH CLI 入口
|
|
6
|
+
|
|
7
|
+
### 修复 mock 全绿但真机 `cli_not_found`
|
|
8
|
+
|
|
9
|
+
0.9.271 的 CLI 候选漏掉了本机 asar 内的官方入口,直接调用 `resolveDshCommand({})`
|
|
10
|
+
会返回 `cli_not_found`。现在补充 `DSH_PROFILE_DIR / DSH_HOME / resourcesPath` 对应的:
|
|
11
|
+
|
|
12
|
+
```text
|
|
13
|
+
app.asar/dsh/node_modules/@deepseek-ai/dsh/lib/bin.js
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Electron 实测解析成功:`profile=desktop`,可执行文件为 DSH 自己的 Electron,
|
|
17
|
+
参数指向上述官方 `bin.js`。该 `bin.js --help` 也已真实运行成功。
|
|
18
|
+
|
|
19
|
+
### 证据
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
更新路由定向 → 20/20
|
|
23
|
+
npm test → 571/571
|
|
24
|
+
真实 Electron CLI 解析与 bin.js --help → 通过(未执行 plugin add)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
只验证入口可执行性,没有真实安装,没有重启。
|
|
28
|
+
|
|
29
|
+
## [0.9.271] - 2026-11-06 —— 界面内安装更新 + Toast/响应式真实验收 39/39
|
|
30
|
+
|
|
31
|
+
### 设置页可以直接安装更新
|
|
32
|
+
|
|
33
|
+
「版本与更新」不再只给复制命令:hasUpdate 时显示官方 primary「安装更新」,
|
|
34
|
+
经 DSH Modal 确认后 POST `/session-superagent/update`,busy 防重复,成功/失败均有反馈。
|
|
35
|
+
保留复制命令作手动回退,不自动重启。
|
|
36
|
+
|
|
37
|
+
后端使用受 `guardWrite` 保护的固定 argv:`dsh plugin --profile <profile> add dsh-session-superagent@<version>`。
|
|
38
|
+
严格 semver、execFile/spawn(shell:false)、CLI 解析、并发锁、超时、输出截断与非零处理均已覆盖。
|
|
39
|
+
响应明确区分 installedVersion/runningVersion/needsReload,安装成功不冒充运行中代码已切换。
|
|
40
|
+
|
|
41
|
+
### Toast / Modal / 响应式 / 双主题真实验收
|
|
42
|
+
|
|
43
|
+
新增独立 Chromium 验收:Toast 6/6、Modal 9/9、响应式 11/11、双主题 9/9,
|
|
44
|
+
连同环境 4/4,总计 **39/39**。Toast 3 秒 hold + 1 秒 fade、连续通知 id guard、
|
|
45
|
+
Modal 焦点圈/Escape/焦点归还、真实 resize 与官方主题 DOM/token 均通过。
|
|
46
|
+
|
|
47
|
+
真实浏览器发现固定 368px 在 320/360px 视口左溢出;现在先缩到 `视口 - 16px`
|
|
48
|
+
再交给 DSH clamp,实测 360→344px、320→304px,均零溢出。
|
|
49
|
+
|
|
50
|
+
### 证据
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
更新路由 19/19;更新 UI 5/5;窄屏回归 2/2
|
|
54
|
+
真实 Chromium 156.0.8078.74 → 39/39
|
|
55
|
+
npm test → 570/570
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
真实认证 DSH WebView 的会话 slot、物理读屏、touch 与真实 watcher 请求仍列入走查。
|
|
59
|
+
|
|
5
60
|
## [0.9.270] - 2026-11-05 —— 真实 Chromium 验收 27/27,Orbit 焦点链修复
|
|
6
61
|
|
|
7
62
|
独立 `ui-host-primitives.js` 的 Tooltip 需要 `React.cloneElement` 合并 trigger ref。
|
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
|
[](https://github.com/awesome-dsh-plugin/awesome-dsh-plugin)
|
|
@@ -148,7 +148,7 @@ Gitee 私有仓库要在「设置 → 凭证」填私人令牌;公开仓库不
|
|
|
148
148
|
## 开发
|
|
149
149
|
|
|
150
150
|
```sh
|
|
151
|
-
npm test #
|
|
151
|
+
npm test # 571 项单测(带离线开关;裸 node --test 会真去 spawn gh,两分半)
|
|
152
152
|
```
|
|
153
153
|
|
|
154
154
|
### 工具输出:文本给人和 agent,JSON 给程序
|
|
@@ -208,7 +208,7 @@ dsh plugin --profile <profile> add dsh-session-superagent@latest
|
|
|
208
208
|
|
|
209
209
|
|
|
210
210
|
```bash
|
|
211
|
-
npm test #
|
|
211
|
+
npm test # 571 项单测(带离线开关,约 1.6 秒)
|
|
212
212
|
node scripts/ui-audit.mjs # 11 项 UI 指标(写死颜色 / 自造 token / 官方结构采用 …)
|
|
213
213
|
node scripts/preflight.mjs # 41 项门禁(含上面两条,外加 profile 一致性、路由面、包内容)
|
|
214
214
|
node scripts/render-preview.mjs preview.html # 双主题静态预览,直接浏览器打开
|
package/client.js
CHANGED
|
@@ -317,6 +317,9 @@ window.__ModuleLoader__.load({
|
|
|
317
317
|
if (!portalTarget) {
|
|
318
318
|
throw new Error('OrbitPopover portal target 不可用;不会退化为非 portal surface')
|
|
319
319
|
}
|
|
320
|
+
// 与独立适配器一致:先缩到视口内,再交给 DSH 计算坐标。
|
|
321
|
+
const viewportWidth = typeof window !== 'undefined' && Number.isFinite(window.innerWidth) ? window.innerWidth : width + 16
|
|
322
|
+
const effectiveWidth = Math.min(width, Math.max(1, viewportWidth - 16))
|
|
320
323
|
|
|
321
324
|
const surface = hostH(MenuSurface, {
|
|
322
325
|
ref: panelRef,
|
|
@@ -329,7 +332,7 @@ window.__ModuleLoader__.load({
|
|
|
329
332
|
position: 'fixed',
|
|
330
333
|
left: position ? position.left : 0,
|
|
331
334
|
top: position ? position.top : 0,
|
|
332
|
-
width,
|
|
335
|
+
width: effectiveWidth,
|
|
333
336
|
zIndex,
|
|
334
337
|
visibility: position ? 'visible' : 'hidden',
|
|
335
338
|
},
|
|
@@ -342,10 +345,13 @@ window.__ModuleLoader__.load({
|
|
|
342
345
|
|
|
343
346
|
// 老宿主没有这个映射时 require 会抛错;可选探测失败必须完整保留本地实现。
|
|
344
347
|
let hostUi = null
|
|
348
|
+
let hostButton = null
|
|
345
349
|
let hostTooltip = null
|
|
346
350
|
let hostOrbit = null
|
|
347
351
|
try {
|
|
348
352
|
const primitives = require('@deepseek-ai/dsh-client-ui-primitives')
|
|
353
|
+
// Button 独立探测:老宿主缺 Modal/Toast 时仍可复用官方按钮;缺 Button 则由 UpdateButton 回退 Btn。
|
|
354
|
+
hostButton = primitives.Button || null
|
|
349
355
|
if (primitives && primitives.Modal && primitives.Toast && primitives.IconWarningOutlineMedium) {
|
|
350
356
|
hostUi = createHostUi({ React, primitives })
|
|
351
357
|
// Tooltip 独立探测:缺少它只回退 InfoTip,不把已接入的 Modal/Toast 一起降级。
|
|
@@ -353,6 +359,7 @@ window.__ModuleLoader__.load({
|
|
|
353
359
|
}
|
|
354
360
|
} catch {
|
|
355
361
|
hostUi = null
|
|
362
|
+
hostButton = null
|
|
356
363
|
hostTooltip = null
|
|
357
364
|
}
|
|
358
365
|
|
|
@@ -372,7 +379,7 @@ window.__ModuleLoader__.load({
|
|
|
372
379
|
}
|
|
373
380
|
|
|
374
381
|
// 客户端版本探针:每次模块加载写一次,用来确认浏览器里跑的是哪一版
|
|
375
|
-
const CLIENT_VERSION = '0.9.
|
|
382
|
+
const CLIENT_VERSION = '0.9.272'
|
|
376
383
|
let BASE = '/session-superagent'
|
|
377
384
|
/**
|
|
378
385
|
* 挑「最新的那个服务端实例」。
|
|
@@ -610,6 +617,9 @@ window.__ModuleLoader__.load({
|
|
|
610
617
|
children)
|
|
611
618
|
}
|
|
612
619
|
|
|
620
|
+
// 安装动作优先用 DSH Button;老宿主缺该导出时完整保留同源 Btn 的尺寸、variant 与交互。
|
|
621
|
+
const UpdateButton = hostButton || Btn
|
|
622
|
+
|
|
613
623
|
function Tag({ tone = 'outline', title, children }) {
|
|
614
624
|
return h('span', { className: 'dt-tag', 'data-tone': tone, title }, children)
|
|
615
625
|
}
|
|
@@ -1126,7 +1136,7 @@ window.__ModuleLoader__.load({
|
|
|
1126
1136
|
const PanelModal = hostUi ? hostUi.Modal : Modal
|
|
1127
1137
|
|
|
1128
1138
|
/** 确认层与触发器分离:DSH orbit 关闭后,同一个本地 Modal 仍能由 StatusOrbit 持有。 */
|
|
1129
|
-
function ConfirmDialog({ open, label, confirmLabel = '确定执行', title = confirmLabel, message, onConfirm, onClose, modalContext = 'panel' }) {
|
|
1139
|
+
function ConfirmDialog({ open, label, confirmLabel = '确定执行', title = confirmLabel, message, onConfirm, onClose, modalContext = 'panel', ButtonComponent = Btn, danger = true }) {
|
|
1130
1140
|
const [busy, setBusy] = useState(false)
|
|
1131
1141
|
const busyRef = useRef(false)
|
|
1132
1142
|
const confirm = async () => {
|
|
@@ -1152,10 +1162,10 @@ window.__ModuleLoader__.load({
|
|
|
1152
1162
|
onClose,
|
|
1153
1163
|
children: null,
|
|
1154
1164
|
footer: h(React.Fragment, null,
|
|
1155
|
-
h(
|
|
1156
|
-
h(
|
|
1165
|
+
h(ButtonComponent, { variant: 'ghost', onClick: onClose }, '取消'),
|
|
1166
|
+
h(ButtonComponent, {
|
|
1157
1167
|
variant: 'primary',
|
|
1158
|
-
className: cx('dt-danger', busy && 'dt-btn-busy'),
|
|
1168
|
+
className: cx(danger && 'dt-danger', busy && 'dt-btn-busy'),
|
|
1159
1169
|
disabled: busy,
|
|
1160
1170
|
'aria-label': confirmLabel,
|
|
1161
1171
|
'aria-busy': busy ? 'true' : undefined,
|
|
@@ -1165,11 +1175,11 @@ window.__ModuleLoader__.load({
|
|
|
1165
1175
|
}
|
|
1166
1176
|
|
|
1167
1177
|
/** 官方 ConfirmButton 动线:触发按钮只开 Modal,取消不执行,确认期间 busy 防重复。 */
|
|
1168
|
-
function ConfirmButton({ label, confirmLabel = '确定执行', title = confirmLabel, message, onConfirm, variant = 'ghost', icon, size, modalContext = 'panel' }) {
|
|
1178
|
+
function ConfirmButton({ label, confirmLabel = '确定执行', title = confirmLabel, message, onConfirm, variant = 'ghost', icon, size, modalContext = 'panel', ButtonComponent = Btn, danger = true }) {
|
|
1169
1179
|
const [open, setOpen] = useState(false)
|
|
1170
1180
|
const close = useCallback(() => setOpen(false), [])
|
|
1171
1181
|
return h(React.Fragment, null,
|
|
1172
|
-
h(
|
|
1182
|
+
h(ButtonComponent, {
|
|
1173
1183
|
variant,
|
|
1174
1184
|
size,
|
|
1175
1185
|
icon,
|
|
@@ -1177,7 +1187,7 @@ window.__ModuleLoader__.load({
|
|
|
1177
1187
|
'aria-haspopup': 'dialog',
|
|
1178
1188
|
onClick: () => setOpen(true),
|
|
1179
1189
|
}, label),
|
|
1180
|
-
h(ConfirmDialog, { open, label, confirmLabel, title, message, onConfirm, onClose: close, modalContext }))
|
|
1190
|
+
h(ConfirmDialog, { open, label, confirmLabel, title, message, onConfirm, onClose: close, modalContext, ButtonComponent, danger }))
|
|
1181
1191
|
}
|
|
1182
1192
|
|
|
1183
1193
|
const watcherId = (w) => (w && w.id) || String((w && w.repo) || '') + '#' + String((w && w.sessionId) || '')
|
|
@@ -1796,6 +1806,8 @@ window.__ModuleLoader__.load({
|
|
|
1796
1806
|
const [giteeToken, setGiteeToken] = useState('')
|
|
1797
1807
|
// 判定页内联追溯结果(官方 Thread 详情最小吸收):不再只塞进一条 Toast。
|
|
1798
1808
|
const [traceResult, setTraceResult] = useState(null)
|
|
1809
|
+
// 安装回执与版本检查分开:POST 失败不能冲掉当前版本和命令回退。
|
|
1810
|
+
const [updateResult, setUpdateResult] = useState(null)
|
|
1799
1811
|
// 去设置页时必须同时定位分区;只切 Tab 会把人留在上次看的分区(官方 settingsRoute(group) 的最小等价)。
|
|
1800
1812
|
const openSettings = (section) => {
|
|
1801
1813
|
setSettingsSection(section)
|
|
@@ -2732,12 +2744,28 @@ window.__ModuleLoader__.load({
|
|
|
2732
2744
|
h(KeyValues, { rows: [
|
|
2733
2745
|
['当前版本', (update && update.current) || CLIENT_VERSION],
|
|
2734
2746
|
['npm 最新', !update ? '检测中…' : update.error ? '检测失败 · ' + update.error : (update.latest || '未知')],
|
|
2735
|
-
['状态',
|
|
2747
|
+
['状态', updateResult
|
|
2748
|
+
? (updateResult.needsReload ? '安装完成,需要重载才生效' : '安装完成')
|
|
2749
|
+
: !update ? '…' : update.error ? '检查失败' : update.hasUpdate ? '有新版本,可以升级' : '已是最新'],
|
|
2750
|
+
updateResult ? ['安装副本(installedVersion)', updateResult.installedVersion] : null,
|
|
2751
|
+
updateResult ? ['运行版本(runningVersion)', updateResult.runningVersion] : null,
|
|
2752
|
+
updateResult ? ['重载要求(needsReload)', updateResult.needsReload ? 'true · 需要重载才生效' : 'false · 当前无需重载'] : null,
|
|
2736
2753
|
] }),
|
|
2737
2754
|
update && update.hasUpdate
|
|
2738
2755
|
? h('div', null,
|
|
2739
2756
|
h('code', { className: 'dt-code' }, update.command),
|
|
2740
2757
|
h('div', { className: 'dt-actions' },
|
|
2758
|
+
h(ConfirmButton, {
|
|
2759
|
+
label: '安装更新',
|
|
2760
|
+
confirmLabel: '确认安装',
|
|
2761
|
+
title: '安装更新',
|
|
2762
|
+
message: '将安装 ' + update.latest + '(当前 ' + (update.current || CLIENT_VERSION) + ')。这会修改安装副本;安装完成后需要重载宿主才生效,不会自动重启。',
|
|
2763
|
+
variant: 'primary',
|
|
2764
|
+
size: 'sm',
|
|
2765
|
+
ButtonComponent: UpdateButton,
|
|
2766
|
+
danger: false,
|
|
2767
|
+
onConfirm: installUpdate,
|
|
2768
|
+
}),
|
|
2741
2769
|
h(Btn, {
|
|
2742
2770
|
size: 'sm',
|
|
2743
2771
|
// 审核 T24 W2:以前点了零反馈,writeText 的 rejection 也没人接 —— 客户不知道复制没成。
|
|
@@ -2747,7 +2775,7 @@ window.__ModuleLoader__.load({
|
|
|
2747
2775
|
: null,
|
|
2748
2776
|
h('div', { className: 'dt-actions' },
|
|
2749
2777
|
h(Btn, { size: 'sm', variant: 'ghost', onClick: () => checkUpdate(true), disabled: checking }, checking ? '检查中…' : '重新检查')),
|
|
2750
|
-
h(Hint, null, '
|
|
2778
|
+
h(Hint, null, '安装会修改当前安装副本,不会自动重启;安装成功后需要重载宿主才生效。复制命令保留作手动回退。'),
|
|
2751
2779
|
h(Hint, null, '反馈问题时把下面这份诊断贴给对方:里面有版本、挂载状态和每条守的最近错误(凭证已脱敏)。'),
|
|
2752
2780
|
h('div', { className: 'dt-actions' },
|
|
2753
2781
|
h(Btn, {
|
|
@@ -2815,13 +2843,50 @@ window.__ModuleLoader__.load({
|
|
|
2815
2843
|
try {
|
|
2816
2844
|
const value = await call('/update' + (force ? '?refresh=1' : ''))
|
|
2817
2845
|
setUpdate(value)
|
|
2846
|
+
return true
|
|
2818
2847
|
} catch (error) {
|
|
2819
2848
|
setUpdate({ current: CLIENT_VERSION, latest: null, hasUpdate: false, error: String(error && error.message || error) })
|
|
2849
|
+
return false
|
|
2820
2850
|
} finally {
|
|
2821
2851
|
setChecking(false)
|
|
2822
2852
|
}
|
|
2823
2853
|
}, [])
|
|
2824
2854
|
|
|
2855
|
+
async function installUpdate() {
|
|
2856
|
+
const version = update && update.latest
|
|
2857
|
+
if (!version) {
|
|
2858
|
+
const text = '安装更新失败:缺少目标版本,请先重新检查'
|
|
2859
|
+
setNotice({ ok: false, text })
|
|
2860
|
+
notify(text, 'error')
|
|
2861
|
+
return false
|
|
2862
|
+
}
|
|
2863
|
+
setNotice(null)
|
|
2864
|
+
try {
|
|
2865
|
+
const result = await call('/update', {
|
|
2866
|
+
method: 'POST',
|
|
2867
|
+
body: JSON.stringify({ version }),
|
|
2868
|
+
})
|
|
2869
|
+
if (!result || result.ok === false) throw new Error((result && result.error) || '服务端没有返回安装结果')
|
|
2870
|
+
const receipt = {
|
|
2871
|
+
installedVersion: String(result.installedVersion || '未知'),
|
|
2872
|
+
runningVersion: String(result.runningVersion || '未知'),
|
|
2873
|
+
needsReload: result.needsReload === true,
|
|
2874
|
+
}
|
|
2875
|
+
setUpdateResult(receipt)
|
|
2876
|
+
notify('安装完成:installedVersion ' + receipt.installedVersion
|
|
2877
|
+
+ ',runningVersion ' + receipt.runningVersion
|
|
2878
|
+
+ (receipt.needsReload ? ',需要重载才生效' : ''), 'success')
|
|
2879
|
+
// 安装只改副本;重新检查由 GET 完成,不触发重启,也不推断 runningVersion 已变化。
|
|
2880
|
+
await checkUpdate(true)
|
|
2881
|
+
return true
|
|
2882
|
+
} catch (error) {
|
|
2883
|
+
const text = '安装更新失败:' + String((error && error.message) || error)
|
|
2884
|
+
setNotice({ ok: false, text })
|
|
2885
|
+
notify(text, 'error')
|
|
2886
|
+
return false
|
|
2887
|
+
}
|
|
2888
|
+
}
|
|
2889
|
+
|
|
2825
2890
|
useEffect(() => {
|
|
2826
2891
|
// 初始检查与手动「重新检查」共用一条错误路径:失败要显示「检查失败」,不能吞掉后永远检测中。
|
|
2827
2892
|
checkUpdate(false)
|
package/lib/index.js
CHANGED
|
@@ -26,6 +26,7 @@ import { decodeBody, truncateUtf8 } from './body.js'
|
|
|
26
26
|
import { quotaDeferText, isOfflineMode } from './gh-format.js'
|
|
27
27
|
import { listGiteeItems, fetchGiteeLastComment, addGiteeLabel, addGiteeComment, ensureGiteeLabel, giteeWhoami, giteeRepo, mapGiteeRepoAccess, DEFAULT_ACK_LABEL_GITEE, giteeLabels, giteeHasLabel, isValidGiteeLabel, suggestGiteeLabel } from './gitee.js'
|
|
28
28
|
import { migrateState, CURRENT_STATE_SCHEMA } from './state-migration.js'
|
|
29
|
+
import { isStrictSemver, runExclusiveUpdate, spawnPluginUpdate, validateUpdateBody } from './update.js'
|
|
29
30
|
import {
|
|
30
31
|
effectiveIntervalMs, planWakeSettlement, advanceSeen, applyWatcherAction, batchFresh, decideWake, DEFAULT_ACK_LABEL, DEFAULT_PRIORITY, formatWatchText,
|
|
31
32
|
recordPendingWake, clearPending, pendingRetry,
|
|
@@ -47,7 +48,7 @@ import {
|
|
|
47
48
|
|
|
48
49
|
export const name = 'dsh-session-superagent'
|
|
49
50
|
/** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
|
|
50
|
-
export const SERVER_VERSION = '0.9.
|
|
51
|
+
export const SERVER_VERSION = '0.9.272'
|
|
51
52
|
export const inject = ['tools', 'agents', 'webServer']
|
|
52
53
|
/** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
|
|
53
54
|
// 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
|
|
@@ -1644,7 +1645,11 @@ async function pollWithItems(ctx, entry, baseMs, parsed) {
|
|
|
1644
1645
|
}, wakeQueueKey)
|
|
1645
1646
|
}
|
|
1646
1647
|
|
|
1647
|
-
export function apply(ctx) {
|
|
1648
|
+
export function apply(ctx, options = {}) {
|
|
1649
|
+
// 更新 runner 可注入:路由测试绝不发起真实安装;生产默认走 shell:false 的 CLI runner。
|
|
1650
|
+
const updateRunner = options.updateRunner || spawnPluginUpdate
|
|
1651
|
+
const updateTimeoutMs = options.updateTimeoutMs
|
|
1652
|
+
const readInstalledVersion = options.readInstalledVersion || installedVersion
|
|
1648
1653
|
// 宿主升级(如 0.2.2-rc.1)时最可能变的不是我们的逻辑,而是服务名/形状。
|
|
1649
1654
|
// 一条守挂了不该拖垮整个插件树:缺服务就只打一条日志,其余能力继续挂。
|
|
1650
1655
|
if (!ctx || !ctx.tools || typeof ctx.tools.register !== 'function') {
|
|
@@ -1755,8 +1760,8 @@ export function apply(ctx) {
|
|
|
1755
1760
|
}
|
|
1756
1761
|
|
|
1757
1762
|
/**
|
|
1758
|
-
*
|
|
1759
|
-
*
|
|
1763
|
+
* 版本检查:问 npm registry 最新版是多少,和本实例版本比。
|
|
1764
|
+
* GET 只读;POST 仅在 guardWrite 通过后复用这里的 latest 并交给受控更新 runner。
|
|
1760
1765
|
* 10 分钟内存缓存,避免面板每次刷新都打 registry。
|
|
1761
1766
|
*/
|
|
1762
1767
|
// /state 的体积预算:每守最多 6 条事件、全局最多 240 条(约 100 KB 内)
|
|
@@ -1981,7 +1986,8 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
1981
1986
|
// 审核 T19:64KB 以前只是「读完再截断」—— 48MB 的请求体会先把 RSS 从 105MB 顶到 333MB。
|
|
1982
1987
|
// 现在边读边算,超了立刻 destroy 并返回 413。
|
|
1983
1988
|
const MAX_BODY_BYTES = 64 * 1024
|
|
1984
|
-
const
|
|
1989
|
+
const INVALID_JSON_BODY = Symbol('invalid-json-body')
|
|
1990
|
+
const readBody = (req, res, strict = false) => new Promise((resolve) => {
|
|
1985
1991
|
const chunks = []
|
|
1986
1992
|
let bytes = 0
|
|
1987
1993
|
let aborted = false
|
|
@@ -2002,10 +2008,15 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2002
2008
|
try {
|
|
2003
2009
|
// 按字符边界截断:直接 subarray 会切开汉字,剩下的半截被 decodeBody 当成 GBK 整段重解(T16)
|
|
2004
2010
|
const raw = decodeBody(truncateUtf8(Buffer.concat(chunks), 64 * 1024))
|
|
2005
|
-
|
|
2006
|
-
|
|
2011
|
+
const parsed = JSON.parse(raw || '{}')
|
|
2012
|
+
if (strict && (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))) {
|
|
2013
|
+
resolve(INVALID_JSON_BODY)
|
|
2014
|
+
return
|
|
2015
|
+
}
|
|
2016
|
+
resolve(parsed)
|
|
2017
|
+
} catch { resolve(strict ? INVALID_JSON_BODY : {}) }
|
|
2007
2018
|
})
|
|
2008
|
-
req.on('error', () => resolve({}))
|
|
2019
|
+
req.on('error', () => resolve(strict ? INVALID_JSON_BODY : {}))
|
|
2009
2020
|
})
|
|
2010
2021
|
const json = (res, code, body) => {
|
|
2011
2022
|
res.statusCode = code
|
|
@@ -2325,15 +2336,77 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
|
|
|
2325
2336
|
},
|
|
2326
2337
|
})
|
|
2327
2338
|
|
|
2328
|
-
//
|
|
2339
|
+
// GET 保持只读版本检查;POST 走同一套写来源守卫,执行固定 argv 的插件更新。
|
|
2329
2340
|
addRoute({
|
|
2330
2341
|
kind: 'exact',
|
|
2331
2342
|
path: '/session-superagent/update',
|
|
2332
2343
|
handler: async (req, res) => {
|
|
2333
|
-
if (req.method
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2344
|
+
if (req.method === 'GET') {
|
|
2345
|
+
const url = new URL(String(req.url || '/'), 'http://127.0.0.1')
|
|
2346
|
+
const value = await checkUpdate(url.searchParams.get('refresh') === '1')
|
|
2347
|
+
return json(res, 200, value)
|
|
2348
|
+
}
|
|
2349
|
+
if (req.method !== 'POST') return json(res, 405, { error: 'method not allowed' })
|
|
2350
|
+
if (!guardWrite(req, res)) return
|
|
2351
|
+
const body = await readBody(req, res, true)
|
|
2352
|
+
if (body === null) return // 已回 413
|
|
2353
|
+
if (body === INVALID_JSON_BODY) return json(res, 400, { ok: false, code: 'invalid_body', error: '请求体必须是合法 JSON 对象' })
|
|
2354
|
+
const selected = validateUpdateBody(body)
|
|
2355
|
+
if (!selected.ok) return json(res, 400, selected)
|
|
2356
|
+
|
|
2357
|
+
const versionState = () => {
|
|
2358
|
+
const installed = readInstalledVersion()
|
|
2359
|
+
return {
|
|
2360
|
+
installedVersion: installed,
|
|
2361
|
+
runningVersion: SERVER_VERSION,
|
|
2362
|
+
needsReload: installed !== null && installed !== SERVER_VERSION,
|
|
2363
|
+
}
|
|
2364
|
+
}
|
|
2365
|
+
let version = selected.version
|
|
2366
|
+
if (version === undefined) {
|
|
2367
|
+
const checked = await checkUpdate(false)
|
|
2368
|
+
if (!isStrictSemver(checked.latest)) {
|
|
2369
|
+
return json(res, 503, {
|
|
2370
|
+
...versionState(),
|
|
2371
|
+
ok: false,
|
|
2372
|
+
code: 'latest_unavailable',
|
|
2373
|
+
error: '没有取得严格 semver 的 latest 版本,本次没有执行更新' + (checked.error ? ':' + redact(String(checked.error)) : ''),
|
|
2374
|
+
})
|
|
2375
|
+
}
|
|
2376
|
+
version = checked.latest
|
|
2377
|
+
}
|
|
2378
|
+
|
|
2379
|
+
const result = await runExclusiveUpdate({ version, runner: updateRunner, timeoutMs: updateTimeoutMs })
|
|
2380
|
+
const state = versionState()
|
|
2381
|
+
const common = {
|
|
2382
|
+
...state,
|
|
2383
|
+
// 成功安装了别的版本时,即使测试替身没有改磁盘,也必须提示运行中代码尚未切换。
|
|
2384
|
+
needsReload: state.needsReload || (result.ok === true && version !== SERVER_VERSION),
|
|
2385
|
+
version,
|
|
2386
|
+
profile: result.profile || null,
|
|
2387
|
+
stdout: redact(String(result.stdout || '')),
|
|
2388
|
+
stderr: redact(String(result.stderr || '')),
|
|
2389
|
+
stdoutTruncated: result.stdoutTruncated === true,
|
|
2390
|
+
stderrTruncated: result.stderrTruncated === true,
|
|
2391
|
+
}
|
|
2392
|
+
if (result.ok === true && result.code === 0) {
|
|
2393
|
+
return json(res, 200, {
|
|
2394
|
+
...common,
|
|
2395
|
+
ok: true,
|
|
2396
|
+
code: 0,
|
|
2397
|
+
exitCode: 0,
|
|
2398
|
+
message: 'DSH CLI 更新命令已以退出码 0 结束;运行中代码仍为 ' + SERVER_VERSION + ',needsReload 表示是否还需重载后才能使用新版本',
|
|
2399
|
+
})
|
|
2400
|
+
}
|
|
2401
|
+
const code = result.code || 'update_failed'
|
|
2402
|
+
const status = code === 'update_in_flight' ? 409
|
|
2403
|
+
: code === 'timeout' ? 504
|
|
2404
|
+
: ['cli_not_found', 'cli_unsupported', 'profile_unavailable', 'invalid_profile'].includes(code) ? 503
|
|
2405
|
+
: 500
|
|
2406
|
+
const error = result.error || (typeof code === 'number'
|
|
2407
|
+
? 'DSH CLI 更新命令以非零退出码 ' + code + ' 结束,未确认安装成功'
|
|
2408
|
+
: '插件更新失败,未确认安装成功')
|
|
2409
|
+
return json(res, status, { ...common, ok: false, code, exitCode: typeof code === 'number' ? code : null, error })
|
|
2337
2410
|
},
|
|
2338
2411
|
})
|
|
2339
2412
|
|
package/lib/update.js
ADDED
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process'
|
|
2
|
+
import { statSync } from 'node:fs'
|
|
3
|
+
import { delimiter, dirname, extname, join, resolve } from 'node:path'
|
|
4
|
+
|
|
5
|
+
export const UPDATE_PACKAGE_NAME = 'dsh-session-superagent'
|
|
6
|
+
export const DEFAULT_UPDATE_TIMEOUT_MS = 120_000
|
|
7
|
+
export const UPDATE_OUTPUT_LIMIT_BYTES = 16 * 1024
|
|
8
|
+
|
|
9
|
+
// Official semver grammar: no leading "v", ranges, tags, or option-like values.
|
|
10
|
+
const SEMVER_RE = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/
|
|
11
|
+
const PROFILE_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/
|
|
12
|
+
const UPDATE_LOCK_KEY = Symbol.for('dsh-session-superagent.pluginUpdateInFlight')
|
|
13
|
+
|
|
14
|
+
function updateError(code, message) {
|
|
15
|
+
const error = new Error(message)
|
|
16
|
+
error.code = code
|
|
17
|
+
return error
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function isStrictSemver(value) {
|
|
21
|
+
return typeof value === 'string' && value.length <= 160 && SEMVER_RE.test(value)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The POST body is deliberately closed: no command, args, cwd, env, or profile overrides. */
|
|
25
|
+
export function validateUpdateBody(body) {
|
|
26
|
+
if (!body || typeof body !== 'object' || Array.isArray(body)) {
|
|
27
|
+
return { ok: false, code: 'invalid_body', error: '请求体必须是 JSON 对象,且只允许可选字段 version' }
|
|
28
|
+
}
|
|
29
|
+
const keys = Object.keys(body)
|
|
30
|
+
if (keys.some((key) => key !== 'version')) {
|
|
31
|
+
return { ok: false, code: 'invalid_body', error: '请求体只允许可选字段 version' }
|
|
32
|
+
}
|
|
33
|
+
if (body.version !== undefined && !isStrictSemver(body.version)) {
|
|
34
|
+
return { ok: false, code: 'invalid_version', error: 'version 必须是严格 semver(例如 0.9.271),不接受 latest、范围或命令参数' }
|
|
35
|
+
}
|
|
36
|
+
return { ok: true, version: body.version }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function resolveProfile(env = process.env) {
|
|
40
|
+
const names = ['DSH_PROFILE', 'DSH_PROFILE_NAME', 'DSH_ACTIVE_PROFILE']
|
|
41
|
+
for (const name of names) {
|
|
42
|
+
const value = typeof env[name] === 'string' ? env[name].trim() : ''
|
|
43
|
+
if (!value) continue
|
|
44
|
+
if (!PROFILE_RE.test(value)) {
|
|
45
|
+
throw updateError('invalid_profile', name + ' 含有不支持的字符;profile 只能包含字母、数字、点、下划线和连字符,且不能以连字符开头')
|
|
46
|
+
}
|
|
47
|
+
return value
|
|
48
|
+
}
|
|
49
|
+
throw updateError('profile_unavailable', '无法确定要更新的 DSH profile:宿主环境未提供 DSH_PROFILE(也支持 DSH_PROFILE_NAME / DSH_ACTIVE_PROFILE)')
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function pluginAddArguments(profile, version) {
|
|
53
|
+
if (!PROFILE_RE.test(String(profile || ''))) throw updateError('invalid_profile', 'profile 格式无效')
|
|
54
|
+
if (!isStrictSemver(version)) throw updateError('invalid_version', 'version 必须是严格 semver')
|
|
55
|
+
return ['plugin', '--profile', profile, 'add', UPDATE_PACKAGE_NAME + '@' + version]
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function isFile(path) {
|
|
59
|
+
try { return statSync(path).isFile() } catch { return false }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function pathCandidates(env, platform) {
|
|
63
|
+
const pathValue = typeof env.PATH === 'string' ? env.PATH : ''
|
|
64
|
+
const names = platform === 'win32' ? ['dsh.exe', 'dsh.cmd', 'dsh'] : ['dsh']
|
|
65
|
+
const dirs = pathValue.split(delimiter).map((part) => part.trim()).filter(Boolean)
|
|
66
|
+
const found = []
|
|
67
|
+
for (const dir of dirs) {
|
|
68
|
+
for (const name of names) found.push(join(dir, name))
|
|
69
|
+
}
|
|
70
|
+
return found
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function layoutCandidates(resourcesPath, execPath, platform) {
|
|
74
|
+
const roots = []
|
|
75
|
+
for (const root of [resourcesPath, execPath ? join(dirname(execPath), 'resources') : null]) {
|
|
76
|
+
if (root && !roots.includes(root)) roots.push(root)
|
|
77
|
+
}
|
|
78
|
+
const name = platform === 'win32' ? 'dsh.cmd' : 'dsh'
|
|
79
|
+
return roots.map((root) => join(root, 'runtime', 'cli', 'bin', name))
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Official @deepseek-ai/dsh bin.js inside the installed asar; Electron can execute it directly. */
|
|
83
|
+
function cliJsCandidates(resourcesPath, execPath, env) {
|
|
84
|
+
const relative = ['app.asar', 'dsh', 'node_modules', '@deepseek-ai', 'dsh', 'lib', 'bin.js']
|
|
85
|
+
const roots = []
|
|
86
|
+
for (const root of [resourcesPath, execPath ? join(dirname(execPath), 'resources') : null]) {
|
|
87
|
+
if (root && !roots.includes(root)) roots.push(root)
|
|
88
|
+
}
|
|
89
|
+
const installRoots = []
|
|
90
|
+
if (env.DSH_PROFILE_DIR) installRoots.push(resolve(env.DSH_PROFILE_DIR, '..', '..', '..'))
|
|
91
|
+
if (env.DSH_HOME) installRoots.push(resolve(env.DSH_HOME, '..'))
|
|
92
|
+
const candidates = roots.map((root) => join(root, ...relative))
|
|
93
|
+
for (const root of installRoots) {
|
|
94
|
+
if (root) candidates.push(join(root, 'Desktop', 'resources', ...relative))
|
|
95
|
+
}
|
|
96
|
+
return candidates
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Convert the standard Windows dsh.cmd wrapper into its direct Electron form.
|
|
101
|
+
* This preserves shell:false even on Node versions that refuse to spawn .cmd.
|
|
102
|
+
*/
|
|
103
|
+
function standardWindowsCommand(cmdPath, fileExists) {
|
|
104
|
+
const binDir = dirname(cmdPath)
|
|
105
|
+
const desktopDir = resolve(binDir, '..', '..', '..', '..')
|
|
106
|
+
const resourcesDir = resolve(binDir, '..', '..', '..')
|
|
107
|
+
const executable = join(desktopDir, 'DeepSeek Harness.exe')
|
|
108
|
+
const asar = join(resourcesDir, 'app.asar')
|
|
109
|
+
if (!fileExists(executable) || !fileExists(asar)) return null
|
|
110
|
+
return {
|
|
111
|
+
file: executable,
|
|
112
|
+
args: [
|
|
113
|
+
'--expose-internals',
|
|
114
|
+
join(asar, 'dsh', 'node_modules', '@deepseek-ai', 'dsh-desktop-host', 'lib', 'cli.js'),
|
|
115
|
+
],
|
|
116
|
+
env: { ELECTRON_RUN_AS_NODE: '1' },
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Resolution order is explicit and deterministic:
|
|
122
|
+
* 1. DSH_CLI_PATH
|
|
123
|
+
* 2. each PATH entry
|
|
124
|
+
* 3. resources/runtime/cli/bin/dsh[.cmd] from the DSH installation layout
|
|
125
|
+
* Existing but unusable candidates do not become a false success.
|
|
126
|
+
*/
|
|
127
|
+
export function resolveDshCommand(options = {}) {
|
|
128
|
+
const env = options.env || process.env
|
|
129
|
+
const platform = options.platform || process.platform
|
|
130
|
+
const execPath = options.execPath || process.execPath
|
|
131
|
+
const resourcesPath = options.resourcesPath === undefined ? process.resourcesPath : options.resourcesPath
|
|
132
|
+
const fileExists = options.fileExists || isFile
|
|
133
|
+
const candidates = []
|
|
134
|
+
const add = (path, source) => {
|
|
135
|
+
if (path && !candidates.some((item) => item.path === path)) candidates.push({ path, source })
|
|
136
|
+
}
|
|
137
|
+
if (typeof env.DSH_CLI_PATH === 'string' && env.DSH_CLI_PATH.trim()) add(env.DSH_CLI_PATH.trim(), 'DSH_CLI_PATH')
|
|
138
|
+
for (const path of pathCandidates(env, platform)) add(path, 'PATH')
|
|
139
|
+
for (const path of layoutCandidates(resourcesPath, execPath, platform)) add(path, 'DSH installation')
|
|
140
|
+
for (const path of cliJsCandidates(resourcesPath, execPath, env)) add(path, 'DSH installation CLI JS')
|
|
141
|
+
|
|
142
|
+
let unsupported = false
|
|
143
|
+
for (const candidate of candidates) {
|
|
144
|
+
if (!fileExists(candidate.path)) continue
|
|
145
|
+
const extension = extname(candidate.path).toLowerCase()
|
|
146
|
+
if (['.js', '.mjs', '.cjs'].includes(extension)) {
|
|
147
|
+
return {
|
|
148
|
+
file: execPath,
|
|
149
|
+
args: [candidate.path],
|
|
150
|
+
env: {},
|
|
151
|
+
source: candidate.source,
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (platform === 'win32' && ['.cmd', '.bat'].includes(extension)) {
|
|
155
|
+
const converted = standardWindowsCommand(candidate.path, fileExists)
|
|
156
|
+
if (converted) return { ...converted, source: candidate.source }
|
|
157
|
+
unsupported = true
|
|
158
|
+
continue
|
|
159
|
+
}
|
|
160
|
+
return { file: candidate.path, args: [], env: {}, source: candidate.source }
|
|
161
|
+
}
|
|
162
|
+
if (unsupported) {
|
|
163
|
+
throw updateError('cli_unsupported', '找到了 Windows dsh.cmd/dsh.bat,但它不属于可直接执行的标准 DSH 安装布局;为避免 shell 注入,本次没有执行。请把 DSH_CLI_PATH 指向标准安装中的 dsh.cmd、dsh.exe 或 cli.js')
|
|
164
|
+
}
|
|
165
|
+
throw updateError('cli_not_found', '找不到可执行的 DSH CLI:已按 DSH_CLI_PATH → PATH → DSH 安装布局顺序查找。请把 DSH_CLI_PATH 指向 dsh 可执行文件或 cli.js')
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function outputCollector(limit) {
|
|
169
|
+
const chunks = []
|
|
170
|
+
let bytes = 0
|
|
171
|
+
let truncated = false
|
|
172
|
+
return {
|
|
173
|
+
append(chunk) {
|
|
174
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk ?? ''), 'utf8')
|
|
175
|
+
const remaining = Math.max(0, limit - bytes)
|
|
176
|
+
if (remaining > 0) chunks.push(buffer.subarray(0, Math.min(remaining, buffer.length)))
|
|
177
|
+
bytes += Math.min(remaining, buffer.length)
|
|
178
|
+
if (buffer.length > remaining) truncated = true
|
|
179
|
+
},
|
|
180
|
+
finish() {
|
|
181
|
+
return { text: Buffer.concat(chunks, bytes).toString('utf8'), truncated }
|
|
182
|
+
},
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function normalizeTimeout(value) {
|
|
187
|
+
const number = Number(value)
|
|
188
|
+
return Number.isFinite(number) && number > 0 ? Math.floor(number) : DEFAULT_UPDATE_TIMEOUT_MS
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** Production runner: argv is an array and shell is always false. */
|
|
192
|
+
export function createSpawnRunner(options = {}) {
|
|
193
|
+
const spawnImpl = options.spawn || spawn
|
|
194
|
+
return async function spawnRunner(request) {
|
|
195
|
+
const timeoutMs = normalizeTimeout(request.timeoutMs ?? options.timeoutMs)
|
|
196
|
+
const env = options.env || process.env
|
|
197
|
+
const command = (options.resolveCommand || resolveDshCommand)({
|
|
198
|
+
env,
|
|
199
|
+
platform: options.platform,
|
|
200
|
+
execPath: options.execPath,
|
|
201
|
+
resourcesPath: options.resourcesPath,
|
|
202
|
+
fileExists: options.fileExists,
|
|
203
|
+
})
|
|
204
|
+
const args = [...command.args, ...pluginAddArguments(request.profile, request.version)]
|
|
205
|
+
|
|
206
|
+
return new Promise((resolveResult) => {
|
|
207
|
+
let child
|
|
208
|
+
try {
|
|
209
|
+
child = spawnImpl(command.file, args, {
|
|
210
|
+
env: { ...env, ...(command.env || {}) },
|
|
211
|
+
windowsHide: true,
|
|
212
|
+
shell: false,
|
|
213
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
214
|
+
})
|
|
215
|
+
} catch (error) {
|
|
216
|
+
resolveResult({ code: 'spawn_error', error: String((error && error.message) || error), stdout: '', stderr: '' })
|
|
217
|
+
return
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const stdout = outputCollector(UPDATE_OUTPUT_LIMIT_BYTES)
|
|
221
|
+
const stderr = outputCollector(UPDATE_OUTPUT_LIMIT_BYTES)
|
|
222
|
+
let settled = false
|
|
223
|
+
const finish = (result) => {
|
|
224
|
+
if (settled) return
|
|
225
|
+
settled = true
|
|
226
|
+
clearTimeout(timer)
|
|
227
|
+
const out = stdout.finish()
|
|
228
|
+
const err = stderr.finish()
|
|
229
|
+
resolveResult({
|
|
230
|
+
...result,
|
|
231
|
+
stdout: out.text,
|
|
232
|
+
stderr: err.text,
|
|
233
|
+
stdoutTruncated: out.truncated,
|
|
234
|
+
stderrTruncated: err.truncated,
|
|
235
|
+
})
|
|
236
|
+
}
|
|
237
|
+
const timer = setTimeout(() => {
|
|
238
|
+
try { child.kill('SIGKILL') } catch {}
|
|
239
|
+
finish({ code: 'timeout', error: 'DSH CLI 更新命令超过 ' + timeoutMs + 'ms,已终止该 CLI 子进程;未确认安装成功' })
|
|
240
|
+
}, timeoutMs)
|
|
241
|
+
|
|
242
|
+
child.stdout?.on('data', stdout.append)
|
|
243
|
+
child.stderr?.on('data', stderr.append)
|
|
244
|
+
child.on('error', (error) => {
|
|
245
|
+
finish({ code: 'spawn_error', error: String((error && error.message) || error) })
|
|
246
|
+
})
|
|
247
|
+
child.on('close', (code, signal) => {
|
|
248
|
+
if (typeof code === 'number') finish({ code })
|
|
249
|
+
else finish({ code: 'spawn_error', error: 'DSH CLI 未给出退出码' + (signal ? '(signal=' + signal + ')' : '') })
|
|
250
|
+
})
|
|
251
|
+
})
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export const spawnPluginUpdate = createSpawnRunner()
|
|
256
|
+
|
|
257
|
+
function capInjectedOutput(value) {
|
|
258
|
+
const text = String(value ?? '')
|
|
259
|
+
const buffer = Buffer.from(text, 'utf8')
|
|
260
|
+
if (buffer.length <= UPDATE_OUTPUT_LIMIT_BYTES) return { text, truncated: false }
|
|
261
|
+
// Back off at most three bytes so the cap never splits a UTF-8 continuation sequence.
|
|
262
|
+
let end = UPDATE_OUTPUT_LIMIT_BYTES
|
|
263
|
+
let back = 0
|
|
264
|
+
while (end > 0 && back < 4 && (buffer[end] & 0b1100_0000) === 0b1000_0000) {
|
|
265
|
+
end -= 1
|
|
266
|
+
back += 1
|
|
267
|
+
}
|
|
268
|
+
return { text: buffer.subarray(0, end).toString('utf8'), truncated: true }
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function normalizeRunnerResult(result) {
|
|
272
|
+
const stdout = capInjectedOutput(result && result.stdout)
|
|
273
|
+
const stderr = capInjectedOutput(result && result.stderr)
|
|
274
|
+
return {
|
|
275
|
+
...(result || {}),
|
|
276
|
+
stdout: stdout.text,
|
|
277
|
+
stderr: stderr.text,
|
|
278
|
+
stdoutTruncated: Boolean(result && result.stdoutTruncated) || stdout.truncated,
|
|
279
|
+
stderrTruncated: Boolean(result && result.stderrTruncated) || stderr.truncated,
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function normalizeFailure(error) {
|
|
284
|
+
const rawCode = String((error && error.code) || '')
|
|
285
|
+
const code = rawCode.toLowerCase() === 'cli_not_found' ? 'cli_not_found'
|
|
286
|
+
: rawCode.toLowerCase() === 'cli_unsupported' ? 'cli_unsupported'
|
|
287
|
+
: rawCode || 'update_failed'
|
|
288
|
+
return {
|
|
289
|
+
ok: false,
|
|
290
|
+
code,
|
|
291
|
+
error: String((error && error.message) || error || '更新失败').slice(0, 1000),
|
|
292
|
+
stdout: '',
|
|
293
|
+
stderr: '',
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Single-process/cross-module update gate plus an outer timeout for injected runners.
|
|
299
|
+
* After an outer timeout the lock stays held until a late runner actually settles,
|
|
300
|
+
* so a hung runner can never cause a second installation to overlap the first.
|
|
301
|
+
*/
|
|
302
|
+
export async function runExclusiveUpdate(request) {
|
|
303
|
+
if (!isStrictSemver(request && request.version)) return normalizeFailure(updateError('invalid_version', 'version 必须是严格 semver'))
|
|
304
|
+
let profile
|
|
305
|
+
try { profile = resolveProfile(request.env || process.env) } catch (error) { return normalizeFailure(error) }
|
|
306
|
+
if (globalThis[UPDATE_LOCK_KEY]) {
|
|
307
|
+
return { ok: false, code: 'update_in_flight', error: '已有一个插件更新命令在执行,本次没有重复启动', stdout: '', stderr: '' }
|
|
308
|
+
}
|
|
309
|
+
globalThis[UPDATE_LOCK_KEY] = true
|
|
310
|
+
const runner = request.runner || spawnPluginUpdate
|
|
311
|
+
const timeoutMs = normalizeTimeout(request.timeoutMs)
|
|
312
|
+
let timedOut = false
|
|
313
|
+
let released = false
|
|
314
|
+
const release = () => {
|
|
315
|
+
if (released) return
|
|
316
|
+
released = true
|
|
317
|
+
if (globalThis[UPDATE_LOCK_KEY]) delete globalThis[UPDATE_LOCK_KEY]
|
|
318
|
+
}
|
|
319
|
+
const work = Promise.resolve().then(() => runner({
|
|
320
|
+
version: request.version,
|
|
321
|
+
profile,
|
|
322
|
+
timeoutMs,
|
|
323
|
+
}))
|
|
324
|
+
// Attach both handlers now: a late rejection after the HTTP timeout is still handled.
|
|
325
|
+
work.then(() => { if (timedOut) release() }, () => { if (timedOut) release() })
|
|
326
|
+
let timer
|
|
327
|
+
let outerTimeoutError = null
|
|
328
|
+
try {
|
|
329
|
+
const result = await new Promise((resolveResult, rejectResult) => {
|
|
330
|
+
outerTimeoutError = updateError('timeout', '等待更新命令超过 ' + timeoutMs + 'ms;未确认安装成功,请核对磁盘版本后再试')
|
|
331
|
+
timer = setTimeout(() => rejectResult(outerTimeoutError), timeoutMs)
|
|
332
|
+
work.then(resolveResult, rejectResult)
|
|
333
|
+
})
|
|
334
|
+
const normalized = normalizeRunnerResult(result)
|
|
335
|
+
return { ...normalized, ok: normalized.code === 0, profile, version: request.version }
|
|
336
|
+
} catch (error) {
|
|
337
|
+
if (error === outerTimeoutError) {
|
|
338
|
+
timedOut = true
|
|
339
|
+
return { ...normalizeFailure(error), code: 'timeout', profile, version: request.version }
|
|
340
|
+
}
|
|
341
|
+
return { ...normalizeFailure(error), profile, version: request.version }
|
|
342
|
+
} finally {
|
|
343
|
+
clearTimeout(timer)
|
|
344
|
+
if (!timedOut) release()
|
|
345
|
+
}
|
|
346
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-superagent",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.272",
|
|
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",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"lib/body.js",
|
|
22
22
|
"lib/gitee.js",
|
|
23
23
|
"lib/state-migration.js",
|
|
24
|
+
"lib/update.js",
|
|
24
25
|
"cordis.patch.yml",
|
|
25
26
|
"README.md",
|
|
26
27
|
"SETUP.md",
|
package/ui-orbit-popover.js
CHANGED
|
@@ -153,6 +153,9 @@ export function createOrbitPopover({ React, primitives } = {}) {
|
|
|
153
153
|
if (!portalTarget) {
|
|
154
154
|
throw new Error('OrbitPopover portal target 不可用;不会退化为非 portal surface')
|
|
155
155
|
}
|
|
156
|
+
// DSH 只 clamp 坐标,不会替你缩宽;368px 在 320/360px 视口会把 left 挤成负数。
|
|
157
|
+
const viewportWidth = typeof window !== 'undefined' && Number.isFinite(window.innerWidth) ? window.innerWidth : width + 16
|
|
158
|
+
const effectiveWidth = Math.min(width, Math.max(1, viewportWidth - 16))
|
|
156
159
|
|
|
157
160
|
const surface = h(MenuSurface, {
|
|
158
161
|
ref: panelRef,
|
|
@@ -165,7 +168,7 @@ export function createOrbitPopover({ React, primitives } = {}) {
|
|
|
165
168
|
position: 'fixed',
|
|
166
169
|
left: position ? position.left : 0,
|
|
167
170
|
top: position ? position.top : 0,
|
|
168
|
-
width,
|
|
171
|
+
width: effectiveWidth,
|
|
169
172
|
zIndex,
|
|
170
173
|
// useAnchoredPosition 首帧尚未测量时不在 0,0 闪现;不自行计算另一套坐标。
|
|
171
174
|
visibility: position ? 'visible' : 'hidden',
|