dsh-plugin-update-center 1.0.2 → 1.0.5

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/README.md CHANGED
@@ -15,7 +15,7 @@ GitHub: https://github.com/darkings/dsh-plugin-update-center · npm: https://www
15
15
  - 点击更新 chip 打开 DSH 原生风格的弹窗:勾选要更新的插件,点「更新 N 个插件」。
16
16
  - 有任务在运行时,按钮变成「任务完成后自动更新」;点击进入队列,任务全部结束并静默后自动开始。
17
17
  - 更新开始后弹窗切换为进度视图:总进度条、当前插件、每个插件的状态(等待 / 核对版本 / 移除旧版 / 安装新版 / 已更新 / 待重启 / 失败)。
18
- - 全部完成后统一提示:需要重启就只提示重启;否则需要刷新页面就自动刷新(3 秒倒计时,可取消)。
18
+ - 全部完成后统一提示:更新了带客户端的插件就提示**完整重启 DSH**,提示条带「完整重启」按钮,点击后关闭并重新启动桌面应用;不再自动刷新页面。
19
19
  - 不需要时可以关闭弹窗、让任务在后台继续;完成后再打开查看结果。
20
20
 
21
21
  ## 检查逻辑
@@ -56,9 +56,9 @@ installBundle(`${name}@${latest}`, { enabled: 原状态, saveExact: true, regist
56
56
  - 队列等待所有任务空闲,再静默 10 秒,然后 5 秒倒计时开始;倒计时内来新任务会退回等待。
57
57
  - 每个插件开始前再查一次任务;运行中来新 conversation,当前插件安装完后暂停,任务结束再恢复。
58
58
  - 队列在页面刷新/关闭后保留(Host 内存);Host 重启后不自动续跑。
59
- - 全部完成后聚合:任意失败项 → 不自动刷新,显示失败状态和「重试失败项」;否则任意 `restart-required` → 只提示重启;否则任意成功插件带 `dsh.client` → 自动刷新页面(3 秒倒计时可取消);都没有 → 不提示。
59
+ - 全部完成后聚合:任意失败项 → 不自动刷新,显示失败状态和「重试失败项」;任意成功插件带 `dsh.client` 或 `restart-required` → 只提示**完整重启 DSH**;不再自动刷新页面(页面刷新只换客户端、不换 Host,可能启动失败);Host-only 更新由插件管理器按 applied 处理。
60
60
  - 失败插件保持旧版本,仍是「可更新」状态;可以立即重试,或重启 DSH 后在更新列表里重新检查/更新。
61
- - 启动层客户端插件更新按「需要重启」处理,避免只刷新后启动层失败。
61
+ - 客户端插件更新一律按「需要完整重启」处理,避免只刷新页面导致 Host/客户端版本不一致。
62
62
 
63
63
  ## DSH 本体更新
64
64
 
@@ -126,7 +126,7 @@ plugin_manager install_bundle C:\Users\Jie\Projects\dsh-plugins\dsh-plugin-updat
126
126
  npm test
127
127
  ```
128
128
 
129
- 覆盖:版本比较与 engines 范围、更新计划筛选、remove → install → 回滚顺序、发布变化中止、队列空闲等待/取消、重启优先于刷新、残留扫描与安全清理、HTTP 路由的鉴权头/请求体/错误码、registry 回退与范围检查。
129
+ 覆盖:版本比较与 engines 范围、更新计划筛选、remove → install → 回滚顺序、发布变化中止、队列空闲等待/取消、失败重试与回滚续跑、重启与完整重启、残留扫描与安全清理、HTTP 路由的鉴权头/请求体/错误码、registry 回退与范围检查。
130
130
 
131
131
  ## 文件
132
132
 
@@ -139,6 +139,7 @@ npm test
139
139
  | `lib/registry.js` | npm registry 读取与回退 |
140
140
  | `lib/versions.js` | 无依赖的 semver 比较与范围判断 |
141
141
  | `lib/http.js` | 同源 POST 路由与有界请求体 |
142
+ | `lib/restart.js` | 完整重启:关闭桌面应用并重新启动同路径可执行文件 |
142
143
  | `client.js` | 登录名右侧 chip、排队/生效提示、残留窗口、进度条 |
143
144
  | `repair.mjs` / `repair.cmd` | DSH 打不开时的离线恢复脚本 |
144
145
  | `locale/*.json` | 插件管理页显示标题与描述 |
package/client.js CHANGED
@@ -57,7 +57,10 @@ window.__ModuleLoader__.load({
57
57
  'done.retryBusy': '正在重试…',
58
58
  'done.unreconciled': '更新未完成,请勿重启;请先重试失败项或恢复快照。',
59
59
  'done.skipped': '{count} 个依赖项已跳过。',
60
- 'done.restart': '新版本已安装,重启 DSH 后生效。',
60
+ 'done.restart': '新版本已安装。请完整重启 DSH 后再使用。',
61
+ 'done.restartButton': '完整重启',
62
+ 'done.restarting': '正在重启 DSH…',
63
+ 'done.restartUnavailable': '自动重启不可用,请手动退出并重新打开 DSH。',
61
64
  'done.refresh': '更新已安装;如界面仍是旧版本,请刷新页面或重启 DSH。',
62
65
  'done.snapshot': '更新前快照:{path}',
63
66
  'risk.boot': '启动关键',
@@ -149,7 +152,10 @@ window.__ModuleLoader__.load({
149
152
  'done.retryBusy': 'Retrying…',
150
153
  'done.unreconciled': 'The update did not finish. Do not restart yet; retry the failed plugins or restore the snapshot.',
151
154
  'done.skipped': '{count} dependent plugins skipped.',
152
- 'done.restart': 'New versions are installed. Restart DSH to load them.',
155
+ 'done.restart': 'New versions are installed. Restart DSH completely to use them.',
156
+ 'done.restartButton': 'Restart DSH',
157
+ 'done.restarting': 'Restarting DSH…',
158
+ 'done.restartUnavailable': 'Automatic restart is unavailable. Quit and reopen DSH manually.',
153
159
  'done.refresh': 'Updates are installed. Refresh the page or restart DSH if the UI still shows the old version.',
154
160
  'done.snapshot': 'Pre-update snapshot: {path}',
155
161
  'risk.boot': 'Boot-critical',
@@ -234,6 +240,9 @@ window.__ModuleLoader__.load({
234
240
  '.dshpu-status[data-tone="success"]{color:var(--dsw-alias-state-success-primary,#1a8a4a)}',
235
241
  '.dshpu-status[data-tone="error"]{color:var(--dsw-alias-state-error-primary,#d93025)}',
236
242
  '.dshpu-status[data-tone="warn"]{color:var(--dsw-alias-state-warn-primary,#b26a00)}',
243
+ '.dshpu-restart{border:0;border-radius:6px;background:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6);color:#fff;font:inherit;font-size:12px;line-height:18px;padding:4px 10px;cursor:pointer;flex:none;margin-left:8px}',
244
+ '.dshpu-restart:disabled{opacity:.6;cursor:default}',
245
+ '.dshpu-restartError{color:var(--dsw-alias-state-error-primary,#d93025);margin-left:8px}',
237
246
  '.dshpu-status[data-tone="busy"]{color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6)}',
238
247
  '.dshpu-progress{display:flex;flex-direction:column;gap:8px}',
239
248
  '.dshpu-progressHead{display:flex;align-items:baseline;justify-content:space-between;gap:12px;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary,#657080)}',
@@ -522,7 +531,7 @@ window.__ModuleLoader__.load({
522
531
  )
523
532
  }
524
533
 
525
- function ProgressView({ job, refresh, retryFailed, retryBusy }) {
534
+ function ProgressView({ job, refresh, retryFailed, retryBusy, restartApp, restarting, restartError }) {
526
535
  const [, setTick] = useState(0)
527
536
  const waiting = job.state === 'queued' || job.state === 'starting'
528
537
  const needsReload = refresh?.needsReload === true
@@ -646,9 +655,18 @@ window.__ModuleLoader__.load({
646
655
  ? h(StatusNote, { tone: 'info', icon: h(UI.IconInfoOutlineRegular, { size: 16 }) },
647
656
  t('done.skipped', { count: skipped.length }))
648
657
  : null,
649
- // Restart wins over reload: a full restart reloads the page too.
650
658
  job.state === 'done' && failures.length === 0 && job.restartRequired === true
651
- ? h(StatusNote, { tone: 'info', icon: h(UI.IconInfoOutlineRegular, { size: 16 }) }, t('done.restart'))
659
+ ? h(StatusNote, { tone: 'info', icon: h(UI.IconInfoOutlineRegular, { size: 16 }) },
660
+ t('done.restart'),
661
+ h('button', {
662
+ type: 'button',
663
+ className: 'dshpu-restart',
664
+ disabled: restarting === true,
665
+ onClick: () => { void restartApp?.() },
666
+ }, restarting === true ? t('done.restarting') : t('done.restartButton')),
667
+ restartError !== null && restartError !== undefined
668
+ ? h('span', { className: 'dshpu-restartError' }, t('done.restartUnavailable'))
669
+ : null)
652
670
  : null,
653
671
  job.state === 'done' && refresh?.reloaded === true
654
672
  ? h(StatusNote, { tone: 'info', icon: h(UI.IconRefreshOutlineRegular, { size: 16 }) }, t('refresh.done'))
@@ -765,7 +783,7 @@ window.__ModuleLoader__.load({
765
783
  )
766
784
  }
767
785
 
768
- function UpdatePanel({ open, onClose, refresh, retryFailed, retryBusy }) {
786
+ function UpdatePanel({ open, onClose, refresh, retryFailed, retryBusy, restartApp, restarting, restartError }) {
769
787
  const state = useStoreValue()
770
788
  const snapshot = state.snapshot
771
789
  const job = snapshot?.job ?? null
@@ -836,7 +854,7 @@ window.__ModuleLoader__.load({
836
854
 
837
855
  const loading = snapshot === null || snapshot === undefined || (checking && updates.length === 0)
838
856
  let body
839
- if (showJob) body = h(ProgressView, { job, refresh, retryFailed, retryBusy })
857
+ if (showJob) body = h(ProgressView, { job, refresh, retryFailed, retryBusy, restartApp, restarting, restartError })
840
858
  else if (loading) body = h(EmptyOrLoading, { state })
841
859
  else body = h(ListView, { state, updates, selected, toggle, busy, queueOffer, desktopBlocked, desktopPhase })
842
860
 
@@ -1060,6 +1078,25 @@ window.__ModuleLoader__.load({
1060
1078
  const alreadyReloaded = reloadPending && hasReloadMarker(job.id)
1061
1079
  const needsReload = reloadPending && alreadyReloaded !== true
1062
1080
  const [retryBusy, setRetryBusy] = useState(false)
1081
+ const [restarting, setRestarting] = useState(false)
1082
+ const [restartError, setRestartError] = useState(null)
1083
+
1084
+ const restartApp = async () => {
1085
+ if (restarting === true) return
1086
+ setRestarting(true)
1087
+ setRestartError(null)
1088
+ try {
1089
+ await api({ action: 'restart-app' })
1090
+ } catch (error) {
1091
+ setRestarting(false)
1092
+ setRestartError(errorCodeOf(error))
1093
+ }
1094
+ }
1095
+
1096
+ useEffect(() => {
1097
+ setRestarting(false)
1098
+ setRestartError(null)
1099
+ }, [job?.id])
1063
1100
 
1064
1101
  const retryFailed = async () => {
1065
1102
  if (retryBusy === true || job === null) return
@@ -1184,7 +1221,7 @@ window.__ModuleLoader__.load({
1184
1221
  return h(React.Fragment, null,
1185
1222
  h('style', null, STYLE),
1186
1223
  chips,
1187
- h(UpdatePanel, { open, onClose: () => setOpen(false), refresh, retryFailed, retryBusy }),
1224
+ h(UpdatePanel, { open, onClose: () => setOpen(false), refresh, retryFailed, retryBusy, restartApp, restarting, restartError }),
1188
1225
  h(ResiduePanel, { open: openResidue, onClose: () => setOpenResidue(false) }),
1189
1226
  )
1190
1227
  }
package/index.js CHANGED
@@ -12,9 +12,10 @@ import { createEngine } from './lib/engine.js'
12
12
  import { createHandler, ROUTE } from './lib/http.js'
13
13
  import { createRegistry } from './lib/registry.js'
14
14
  import { createResidueService } from './lib/residue.js'
15
+ import { createRestartService } from './lib/restart.js'
15
16
 
16
17
  export const name = 'dsh-plugin-update-center'
17
- export const inject = ['connection', 'pluginManager']
18
+ export const inject = ['connection']
18
19
 
19
20
  function readActivity(ctx) {
20
21
  try {
@@ -36,14 +37,40 @@ function readActivity(ctx) {
36
37
  }
37
38
 
38
39
  export function apply(ctx) {
39
- const manager = ctx.pluginManager
40
+ let manager = ctx.pluginManager
41
+ try {
42
+ manager = ctx.get?.('pluginManager') ?? manager
43
+ } catch {
44
+ // A profile without the service still loads the plugin in fallback mode.
45
+ }
40
46
  const connection = ctx.connection
41
- if (
42
- typeof manager?.listBundles !== 'function'
43
- || typeof manager?.installBundle !== 'function'
44
- || typeof manager?.removeBundle !== 'function'
45
- ) return
46
47
  if (typeof connection?.fetch?.register !== 'function') return
48
+ const hasManager = Boolean(manager)
49
+ && typeof manager.listBundles === 'function'
50
+ && typeof manager.installBundle === 'function'
51
+ && typeof manager.removeBundle === 'function'
52
+ if (!hasManager) {
53
+ // Minimal/headless profiles (for example dsh.so's L5 profile) do not mount
54
+ // the profile plugin manager. Still load the plugin and answer its route so
55
+ // the web boot and the endpoint check pass; the UI reports that updates are
56
+ // unavailable in this profile.
57
+ ctx.effect(
58
+ () => connection.fetch.register({
59
+ path: ROUTE,
60
+ methods: ['POST'],
61
+ requestBody: 'streaming',
62
+ fetch: async () => new Response(JSON.stringify({ ok: false, code: 'service-unavailable' }), {
63
+ status: 200,
64
+ headers: {
65
+ 'content-type': 'application/json; charset=utf-8',
66
+ 'cache-control': 'no-store',
67
+ },
68
+ }),
69
+ }),
70
+ 'dsh-plugin-update-center: unavailable route',
71
+ )
72
+ return
73
+ }
47
74
 
48
75
  const profile = ctx.get?.('profileContext')
49
76
  const profileDir = typeof profile?.dir === 'string' && profile.dir !== '' ? profile.dir : undefined
@@ -54,6 +81,7 @@ export function apply(ctx) {
54
81
  const residue = profileDir !== undefined
55
82
  ? createResidueService({ profileDir, homeDir, manager, backup })
56
83
  : null
84
+ const restart = createRestartService()
57
85
 
58
86
  const engine = createEngine({
59
87
  manager,
@@ -74,7 +102,7 @@ export function apply(ctx) {
74
102
  path: ROUTE,
75
103
  methods: ['POST'],
76
104
  requestBody: 'streaming',
77
- fetch: createHandler(engine, residue),
105
+ fetch: createHandler(engine, residue, restart),
78
106
  }),
79
107
  'dsh-plugin-update-center: http route',
80
108
  )
package/lib/engine.js CHANGED
@@ -607,9 +607,10 @@ export function createEngine({
607
607
  }
608
608
 
609
609
  /**
610
- * Restart wins over reload: a full restart reloads the page too, so the UI
611
- * never asks for both. A boot-tier client plugin is treated as restart-only
612
- * because a failed reload of that tier leaves a dead window.
610
+ * A client-half update needs a full DSH restart: reloading only the page
611
+ * swaps the client while the old Host half keeps running, and the next web
612
+ * boot can fail on a missing Host API (seen as `refresh is not a function`).
613
+ * Host-only changes never need a page reload.
613
614
  */
614
615
  function summarize(job) {
615
616
  const successes = job.results.filter((entry) => entry.ok === true)
@@ -618,15 +619,10 @@ export function createEngine({
618
619
  job.failures = failures.length
619
620
  job.skipped = skipped.length
620
621
  job.unreconciled = job.unreconciled === true || failures.some((entry) => entry.reconciled !== true)
622
+ const clientSuccess = successes.some((entry) => entry.hasClient === true)
621
623
  const bootClient = successes.some((entry) => entry.bootCritical === true && entry.hasClient === true)
622
- job.restartRequired = job.restartRequired === true || bootClient
623
- // A failed item leaves the profile usable, but an automatic reload would
624
- // make a half-finished batch look complete. Require an explicit retry or a
625
- // restart instead of the three-second refresh.
626
- job.reloadRequired = job.unreconciled !== true
627
- && failures.length === 0
628
- && job.restartRequired !== true
629
- && successes.some((entry) => entry.hasClient === true)
624
+ job.restartRequired = job.restartRequired === true || bootClient || clientSuccess
625
+ job.reloadRequired = false
630
626
  }
631
627
 
632
628
  function orderByDependencies(selected) {
package/lib/http.js CHANGED
@@ -71,6 +71,7 @@ function statusFor(code) {
71
71
  if (code === 'registry-unavailable') return 502
72
72
  if (code === 'snapshot-failed' || code === 'verification-failed') return 500
73
73
  if (code === 'busy' || code === 'busy-session' || code === 'check-first' || code === 'rollback-unavailable' || code === 'dsh-update') return 409
74
+ if (code === 'restart-unavailable') return 501
74
75
  return EXPECTED.has(code) ? 400 : 500
75
76
  }
76
77
 
@@ -78,8 +79,9 @@ function statusFor(code) {
78
79
  * Create the route handler for one engine.
79
80
  * @param {ReturnType<import('./engine.js').createEngine>} engine
80
81
  * @param {{ scan: Function, clean: Function } | null} [residue]
82
+ * @param {{ restart: Function } | null} [restart]
81
83
  */
82
- export function createHandler(engine, residue = null) {
84
+ export function createHandler(engine, residue = null, restart = null) {
83
85
  if (!engine || typeof engine.snapshot !== 'function') throw new TypeError('an update engine is required')
84
86
  return async function handle(request) {
85
87
  let action = 'unknown'
@@ -111,6 +113,20 @@ export function createHandler(engine, residue = null) {
111
113
  ok: true,
112
114
  value: engine.acknowledgeReload(typeof input.jobId === 'string' ? input.jobId : undefined),
113
115
  })
116
+ case 'restart-app': {
117
+ const jobState = engine.snapshot()?.job?.state
118
+ if (jobState === 'queued' || jobState === 'starting' || jobState === 'running') {
119
+ return respond({ ok: false, code: 'busy' }, 409)
120
+ }
121
+ if (restart === null || typeof restart.restart !== 'function') {
122
+ return respond({ ok: false, code: 'restart-unavailable' }, 501)
123
+ }
124
+ const result = restart.restart()
125
+ if (result?.ok !== true) {
126
+ return respond({ ok: false, code: result?.code ?? 'restart-unavailable' }, 501)
127
+ }
128
+ return respond({ ok: true, value: { restarting: true } })
129
+ }
114
130
  case 'desktop-update':
115
131
  return respond({ ok: true, value: engine.setDesktopUpdate({ phase: input.phase, version: input.version }) })
116
132
  case 'residue':
package/lib/restart.js ADDED
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Full desktop restart for the restart button.
3
+ *
4
+ * A page reload only replaces the renderer; the DSH Host keeps running the old
5
+ * plugin code, which is exactly how the client/Host mismatch crash happens.
6
+ * The desktop app exposes no restart bridge to plugins, so the Host launches a
7
+ * detached PowerShell script, waits for the HTTP response to flush, closes the
8
+ * app (and the Host itself), then starts the same executable again.
9
+ */
10
+
11
+ import { spawn } from 'node:child_process'
12
+ import { existsSync } from 'node:fs'
13
+ import { basename } from 'node:path'
14
+
15
+ const APP_EXE = /^DeepSeek Harness\.exe$/i
16
+
17
+ /** Quote one PowerShell single-quoted string. */
18
+ function quotePowerShell(value) {
19
+ return `'${String(value).replaceAll("'", "''")}'`
20
+ }
21
+
22
+ /** Build the script that closes and relaunches the desktop app. */
23
+ export function buildRestartScript(execPath) {
24
+ return [
25
+ 'Start-Sleep -Milliseconds 900',
26
+ `$exe = ${quotePowerShell(execPath)}`,
27
+ "Get-Process -Name 'DeepSeek Harness' -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue",
28
+ 'Start-Sleep -Milliseconds 1200',
29
+ 'Start-Process -FilePath $exe',
30
+ ].join('\r\n')
31
+ }
32
+
33
+ /**
34
+ * @param {object} [options]
35
+ * @param {string} [options.execPath] desktop executable (the Host runs inside it)
36
+ * @param {NodeJS.Platform} [options.platform]
37
+ * @param {Function} [options.spawn]
38
+ * @param {Function} [options.exists]
39
+ */
40
+ export function createRestartService({
41
+ execPath = process.execPath,
42
+ platform = process.platform,
43
+ spawn: spawnChild = spawn,
44
+ exists = existsSync,
45
+ } = {}) {
46
+ function canRestart() {
47
+ if (platform !== 'win32') return false
48
+ if (typeof execPath !== 'string' || !APP_EXE.test(basename(execPath))) return false
49
+ try {
50
+ return exists(execPath)
51
+ } catch {
52
+ return false
53
+ }
54
+ }
55
+
56
+ function restart() {
57
+ if (!canRestart()) return { ok: false, code: 'restart-unavailable' }
58
+ const script = buildRestartScript(execPath)
59
+ const encoded = Buffer.from(script, 'utf16le').toString('base64')
60
+ const child = spawnChild('powershell.exe', [
61
+ '-NoProfile',
62
+ '-NonInteractive',
63
+ '-WindowStyle',
64
+ 'Hidden',
65
+ '-EncodedCommand',
66
+ encoded,
67
+ ], {
68
+ detached: true,
69
+ stdio: 'ignore',
70
+ windowsHide: true,
71
+ })
72
+ child.unref?.()
73
+ return { ok: true }
74
+ }
75
+
76
+ return { canRestart, restart }
77
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-update-center",
3
- "version": "1.0.2",
3
+ "version": "1.0.5",
4
4
  "description": "尊重 DSH 原始风格的插件更新插件:在侧边栏检查、排队更新已安装插件,支持快照回滚、安装后校验、卸载残留清理与离线恢复。 A DSH-native plugin update center for the sidebar with snapshots, rollback, queued updates and leftover cleanup.",
5
5
  "keywords": [
6
6
  "dsh",
@@ -44,9 +44,6 @@
44
44
  "client": {
45
45
  "platform": "web",
46
46
  "immediately": true,
47
- "inject": [
48
- "@deepseek-ai/dsh-client-ui-sidebar"
49
- ],
50
47
  "external": [
51
48
  "@deepseek-ai/dsh-client-ui-primitives"
52
49
  ]