@restregular/dsh-powerup 0.4.0 → 0.4.1

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
@@ -66,6 +66,10 @@ update dialog:
66
66
  a version that is both uses one **Current · latest** tag.
67
67
  3. Confirming removes the installed copy, checks the new spec the way **Add
68
68
  plugin** does, and installs the selected version without enabling it.
69
+ Because the old copy is already gone at that point, a refused check or a
70
+ failed install automatically re-installs the removed version with its
71
+ previous enabled state; the dialog reports both the failure and the rollback
72
+ result.
69
73
  4. The dialog then asks whether to enable the new version.
70
74
  5. After enabling, it asks whether to restart DSH. On the desktop app the
71
75
  `lib/restart-helper.cjs` helper relaunches the exact executable after the old
@@ -124,7 +128,9 @@ refresh the page when the install finishes.
124
128
  through the built-in manager service. Removing the bundle unloads Power-Up's
125
129
  own Host fiber, but the manager service and the pending promise stay in the
126
130
  Host process, so the reinstall finishes; failures are appended to
127
- `~/.dsh/powerup/self-update.log`.
131
+ `~/.dsh/powerup/self-update.log`. The Host captures the version it was loaded
132
+ from before removal and re-installs that version if the check or install
133
+ fails, so a failed self-update does not leave Power-Up missing.
128
134
  - **Restart status lives in this browser session.** A management result that
129
135
  says `restart-required` is written to `sessionStorage`; the card gets a
130
136
  **Restart needed** tag and the group heading gets a count plus a restart
package/client.js CHANGED
@@ -44,7 +44,7 @@
44
44
 
45
45
  const NS = 'dsh-powerup';
46
46
  const SETTINGS_KEY = 'dsh-powerup:settings:v1';
47
- const VERSION = '0.4.0';
47
+ const VERSION = '0.4.1';
48
48
  const MENU_GAP = 8;
49
49
  const MENU_WIDTH = 248;
50
50
 
@@ -151,6 +151,7 @@
151
151
  'update.step.checking': '正在校验版本…',
152
152
  'update.step.removing': '正在卸载旧版…',
153
153
  'update.step.installing': '正在安装 {version}…',
154
+ 'update.step.rollback': '正在恢复旧版本 {version}…',
154
155
  'update.step.enabling': '正在启用…',
155
156
  'update.log': '安装输出',
156
157
  'update.enableTitle': '安装完成,是否立即启用?',
@@ -187,6 +188,11 @@
187
188
  'update.doneRestart': '部分更改需要重启 DSH 后生效。',
188
189
  'update.doneButton': '完成',
189
190
  'update.errorTitle': '更新失败',
191
+ 'update.rollbackOkTitle': '已恢复旧版本',
192
+ 'update.rollbackOkDesc': '更新失败,{name} 已自动回滚到 {version},仍可继续使用。',
193
+ 'update.rollbackFailedTitle': '旧版本恢复失败',
194
+ 'update.rollbackFailedDesc': '自动回滚失败:{message}。请到「插件」页用「添加插件」重新安装。',
195
+ 'update.rollbackUnavailable': '无法确定旧版本号,未能自动回滚。请到「插件」页重新安装。',
190
196
  'update.selfTitle': '请用「添加插件」更新 Power-Up 自身',
191
197
  'update.selfDesc': '更新 Power-Up 会先卸载本插件,更新流程会随之中断。',
192
198
  'update.notRemovable': '该插件受 DSH 管理,不能在这里更新。',
@@ -299,6 +305,7 @@
299
305
  'update.step.checking': 'Checking the version…',
300
306
  'update.step.removing': 'Removing the old version…',
301
307
  'update.step.installing': 'Installing {version}…',
308
+ 'update.step.rollback': 'Restoring {version}…',
302
309
  'update.step.enabling': 'Enabling…',
303
310
  'update.log': 'Install output',
304
311
  'update.enableTitle': 'Installed. Enable it now?',
@@ -335,6 +342,11 @@
335
342
  'update.doneRestart': 'Some changes apply only after DSH restarts.',
336
343
  'update.doneButton': 'Done',
337
344
  'update.errorTitle': 'Update failed',
345
+ 'update.rollbackOkTitle': 'Previous version restored',
346
+ 'update.rollbackOkDesc': 'The update failed, so {name} was rolled back to {version} and is ready to use.',
347
+ 'update.rollbackFailedTitle': 'Could not restore the previous version',
348
+ 'update.rollbackFailedDesc': 'Automatic rollback failed: {message}. Reinstall it from the Plugins page with “Add plugin”.',
349
+ 'update.rollbackUnavailable': 'The previous version is unknown, so no automatic rollback was possible. Reinstall it from the Plugins page.',
338
350
  'update.selfTitle': 'Update Power-Up with Add plugin',
339
351
  'update.selfDesc': 'Updating Power-Up removes this plugin first, which interrupts this flow.',
340
352
  'update.notRemovable': 'DSH manages this plugin; it cannot be updated here.',
@@ -1661,6 +1673,35 @@
1661
1673
  return `powerup-${Date.now()}-${Math.random().toString(16).slice(2)}`;
1662
1674
  }
1663
1675
 
1676
+ /**
1677
+ * Reinstall the version an update removed. The update removes the old
1678
+ * copy before the new spec is inspected, so a refused inspection or a
1679
+ * failed install leaves the plugin missing; this puts the old version
1680
+ * back with the enabled state it had before the update.
1681
+ * @param {{ installBundle: Function }} manager
1682
+ * @param {{ name: string, version: string | null | undefined, enabled?: boolean, registry?: string | null }} target
1683
+ * @param {(key: string, params?: object) => string} t
1684
+ * @returns {Promise<{ version: string }>}
1685
+ */
1686
+ async function restorePreviousBundle(manager, target, t) {
1687
+ const version = typeof target.version === 'string' ? target.version.trim() : '';
1688
+ if (version === '') throw new Error(t('update.rollbackUnavailable'));
1689
+ const installed = await manager.installBundle(`${target.name}@${version}`, {
1690
+ enabled: target.enabled !== false,
1691
+ requestId: newRequestId(),
1692
+ registry: target.registry ?? null,
1693
+ });
1694
+ if (!installed.ok) throw new Error(installed.error?.message ?? t('update.unknown'));
1695
+ const value = installed.value ?? {};
1696
+ if (value.error !== undefined || value.application === 'failed') throw new Error(operationReason(value, t));
1697
+ if (value.application === 'cancelled') throw new Error(t('update.cancelled'));
1698
+ return {
1699
+ version: typeof value.version === 'string' && value.version !== '' ? value.version : version,
1700
+ restartRequired: value.application === 'restart-required',
1701
+ restartReason: typeof value.restartReason === 'string' ? value.restartReason : '',
1702
+ };
1703
+ }
1704
+
1664
1705
  /**
1665
1706
  * The package name of a registry install spec. Git, tarball, and local
1666
1707
  * paths return null; their installed name comes from the Host result.
@@ -2379,6 +2420,7 @@
2379
2420
  title: packageDisplayTitle(pkg),
2380
2421
  currentVersion: pkg.version ?? null,
2381
2422
  installed: pkg.installed === true,
2423
+ enabled: pkg.enabled !== false,
2382
2424
  phase: 'choose',
2383
2425
  choices,
2384
2426
  registryKey: choice.key,
@@ -2614,6 +2656,9 @@
2614
2656
  const registry = registryValue(choice);
2615
2657
  const spec = `${current.name}@${version}`;
2616
2658
  const requestId = newRequestId();
2659
+ const previousVersion = typeof current.currentVersion === 'string' && current.currentVersion !== '' ? current.currentVersion : null;
2660
+ const previousEnabled = current.enabled !== false;
2661
+ let removedOld = false;
2617
2662
  patch(token, { phase: 'working', step: current.self === true ? 'installing' : 'removing', error: null, formError: null, log: '', logLabel: spec });
2618
2663
  if (current.self === true) {
2619
2664
  // Power-Up cannot reinstall itself from its own client: removing
@@ -2645,7 +2690,9 @@
2645
2690
  const removed = await manager.removeBundle(current.name);
2646
2691
  if (tokenRef.current !== token) return;
2647
2692
  if (!removed.ok) throw new Error(removed.error?.message ?? t('update.unknown'));
2648
- if (removed.value.error !== undefined) throw new Error(operationReason(removed.value, t));
2693
+ if (removed.value.error !== undefined || removed.value.application === 'failed') throw new Error(operationReason(removed.value, t));
2694
+ if (removed.value.application === 'cancelled') throw new Error(t('update.cancelled'));
2695
+ removedOld = true;
2649
2696
  patch(token, { step: 'checking' });
2650
2697
  const checked = await manager.inspect(spec, { registry });
2651
2698
  if (tokenRef.current !== token) return;
@@ -2675,7 +2722,40 @@
2675
2722
  enabling: false,
2676
2723
  });
2677
2724
  } catch (error) {
2678
- patch(token, { phase: 'error', step: null, error: errorText(error) || t('update.unknown') });
2725
+ const original = errorText(error) || t('update.unknown');
2726
+ // Before the first successful step the old copy is still installed;
2727
+ // after it, a failed inspect/install must put the old version back.
2728
+ if (!removedOld) {
2729
+ patch(token, { phase: 'error', step: null, error: original });
2730
+ return;
2731
+ }
2732
+ if (previousVersion === null) {
2733
+ patch(token, { phase: 'error', step: null, error: original, rollbackUnavailable: true });
2734
+ return;
2735
+ }
2736
+ patch(token, { phase: 'working', step: 'rollback', rollbackVersion: previousVersion, error: null, formError: null });
2737
+ try {
2738
+ const restored = await restorePreviousBundle(manager, {
2739
+ name: current.name,
2740
+ version: previousVersion,
2741
+ enabled: previousEnabled,
2742
+ registry,
2743
+ }, t);
2744
+ if (tokenRef.current !== token) return;
2745
+ if (restored.restartRequired === true) {
2746
+ recordPending({ name: current.name, version: restored.version, reason: restored.restartReason });
2747
+ }
2748
+ patch(token, { phase: 'error', step: null, error: original, rolledBack: true, rollbackVersion: restored.version });
2749
+ } catch (rollbackFailure) {
2750
+ if (tokenRef.current !== token) return;
2751
+ patch(token, {
2752
+ phase: 'error',
2753
+ step: null,
2754
+ error: original,
2755
+ rollbackVersion: previousVersion,
2756
+ rollbackError: errorText(rollbackFailure) || t('update.unknown'),
2757
+ });
2758
+ }
2679
2759
  }
2680
2760
  };
2681
2761
 
@@ -3020,7 +3100,9 @@
3020
3100
  ? t('update.step.removing')
3021
3101
  : view.step === 'installing'
3022
3102
  ? t('update.step.installing', { version: view.logLabel ?? '' })
3023
- : t('update.step.checking');
3103
+ : view.step === 'rollback'
3104
+ ? t('update.step.rollback', { version: view.rollbackVersion ?? view.currentVersion ?? '' })
3105
+ : t('update.step.checking');
3024
3106
  return [
3025
3107
  h('div', { key: 'status', className: 'dsh-powerup-update-status' },
3026
3108
  h('span', { className: 'dsh-powerup-update-spinner', 'aria-hidden': 'true' }),
@@ -3084,6 +3166,18 @@
3084
3166
  if (view.phase === 'error') {
3085
3167
  return [
3086
3168
  notice('error', h(WarnIcon, { size: 15 }), t('update.errorTitle'), view.error ?? t('update.unknown')),
3169
+ view.rolledBack === true
3170
+ ? notice('success', h(CheckIcon, { size: 15 }), t('update.rollbackOkTitle'), t('update.rollbackOkDesc', {
3171
+ name: view.name,
3172
+ version: view.rollbackVersion ?? view.currentVersion ?? '',
3173
+ }))
3174
+ : null,
3175
+ view.rollbackError !== undefined && view.rollbackError !== null
3176
+ ? notice('warn', h(WarnIcon, { size: 15 }), t('update.rollbackFailedTitle'), t('update.rollbackFailedDesc', { message: view.rollbackError }))
3177
+ : null,
3178
+ view.rollbackUnavailable === true
3179
+ ? notice('warn', h(WarnIcon, { size: 15 }), t('update.rollbackFailedTitle'), t('update.rollbackUnavailable'))
3180
+ : null,
3087
3181
  h('span', { key: 'name', className: 'dsh-powerup-update-name' }, view.name),
3088
3182
  ];
3089
3183
  }
@@ -3606,6 +3700,7 @@
3606
3700
  normalizeVersionInput,
3607
3701
  inspectReason,
3608
3702
  operationReason,
3703
+ restorePreviousBundle,
3609
3704
  },
3610
3705
  };
3611
3706
  },
package/index.js CHANGED
@@ -9,7 +9,9 @@
9
9
  * GET /dsh-powerup/api/audit → profile bundles newer than this Host
10
10
  * POST /dsh-powerup/api/self-update → removes and reinstalls this plugin
11
11
  * in the background, surviving the
12
- * plugin's own unload
12
+ * plugin's own unload; a failed step
13
+ * reinstalls the version that was
14
+ * removed
13
15
  * POST /dsh-powerup/api/job-kill → stops one background job with an
14
16
  * optional human reason
15
17
  *
@@ -21,7 +23,7 @@
21
23
  */
22
24
 
23
25
  import { randomUUID } from 'node:crypto';
24
- import { appendFileSync, mkdirSync, statSync } from 'node:fs';
26
+ import { appendFileSync, mkdirSync, readFileSync, statSync } from 'node:fs';
25
27
  import { dirname, join } from 'node:path';
26
28
  import { homedir } from 'node:os';
27
29
  import { describeRestart, requestRestart } from './lib/restart.js';
@@ -41,6 +43,24 @@ const BODY_LIMIT = 16 * 1024;
41
43
  /** The moment this Host process started; a profile file newer than it may await a restart. */
42
44
  const HOST_STARTED_AT = Date.now() - process.uptime() * 1000;
43
45
 
46
+ /**
47
+ * The version this Host module was loaded from. A self-update removes the only
48
+ * installed copy before inspecting the target, so a failure must reinstall this
49
+ * exact version instead of leaving Power-Up missing.
50
+ * @returns {string}
51
+ */
52
+ function selfVersion() {
53
+ try {
54
+ const manifest = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'));
55
+ return typeof manifest?.version === 'string' ? manifest.version : '';
56
+ } catch {
57
+ return '';
58
+ }
59
+ }
60
+
61
+ /** Captured at load time, before self-update touches the package directory. */
62
+ const SELF_VERSION = selfVersion();
63
+
44
64
  /**
45
65
  * The desktop profile directory, resolved without depending on the shell tool.
46
66
  * @returns {string}
@@ -225,12 +245,13 @@ function normalizeVersion(value) {
225
245
  * @param {import('@deepseek-ai/cordis').Context} ctx
226
246
  * @param {string} version
227
247
  * @param {string | null} registry
228
- * @param {{ manager?: unknown, log?: (line: string) => void }} [options]
229
- * @returns {Promise<{ ok: boolean, stage?: string, error?: string }>}
248
+ * @param {{ manager?: unknown, log?: (line: string) => void, previousVersion?: string }} [options]
249
+ * @returns {Promise<{ ok: boolean, stage?: string, error?: string, rolledBack?: boolean, rollbackError?: string }>}
230
250
  */
231
251
  export async function performSelfUpdate(ctx, version, registry, options = {}) {
232
252
  const log = options.log ?? appendSelfUpdateLog;
233
253
  const manager = options.manager ?? ctx?.get?.('pluginManager');
254
+ const previousVersion = typeof options.previousVersion === 'string' ? options.previousVersion : SELF_VERSION;
234
255
  if (manager === undefined || typeof manager.installBundle !== 'function') {
235
256
  log('self-update: pluginManager service is unavailable');
236
257
  return { ok: false, stage: 'manager', error: 'pluginManager service is unavailable' };
@@ -238,11 +259,16 @@ export async function performSelfUpdate(ctx, version, registry, options = {}) {
238
259
  const spec = `${MODULE_ID}@${version}`;
239
260
  log(`self-update: start ${spec} registry=${String(registry)}`);
240
261
  let stage = 'remove';
262
+ let removedOld = false;
241
263
  try {
242
264
  const removed = await manager.removeBundle(MODULE_ID);
243
265
  if (removed?.error !== undefined) {
244
266
  throw new Error(`remove failed: ${removed.error.code ?? 'error'} ${removed.error.diagnostic ?? ''}`.trim());
245
267
  }
268
+ if (removed?.application === 'cancelled' || removed?.application === 'failed') {
269
+ throw new Error(`remove ${removed.application}`);
270
+ }
271
+ removedOld = true;
246
272
  log(`self-update: removed (application=${removed?.application ?? 'unknown'})`);
247
273
  stage = 'inspect';
248
274
  const checked = await manager.inspect(spec, { registry });
@@ -256,15 +282,54 @@ export async function performSelfUpdate(ctx, version, registry, options = {}) {
256
282
  registry,
257
283
  requestId: randomUUID(),
258
284
  });
259
- if (installed?.error !== undefined) {
260
- throw new Error(`install failed: ${installed.error.code ?? 'error'} ${installed.error.diagnostic ?? ''}`.trim());
285
+ if (installed?.error !== undefined || installed?.application === 'failed') {
286
+ const detail = installed?.error === undefined
287
+ ? ''
288
+ : `${installed.error.code ?? 'error'} ${installed.error.diagnostic ?? ''}`.trim();
289
+ throw new Error(`install failed${detail === '' ? '' : `: ${detail}`}`);
261
290
  }
262
291
  log(`self-update: installed (application=${installed?.application ?? 'unknown'}, version=${installed?.version ?? 'unknown'})`);
263
292
  return { ok: true, stage: 'install' };
264
293
  } catch (error) {
265
294
  const message = String(error?.message ?? error);
266
295
  log(`self-update: failed at ${stage}: ${message}${error?.stack === undefined ? '' : `\n${error.stack}`}`);
267
- return { ok: false, stage, error: message };
296
+ // Removing the old copy is the first step, so any later failure leaves
297
+ // Power-Up uninstalled. Put the running version back instead.
298
+ let rolledBack = false;
299
+ let rollbackError;
300
+ if (removedOld) {
301
+ if (previousVersion === '') {
302
+ rollbackError = 'the previous version is unknown';
303
+ log('self-update: cannot roll back: previous version unknown');
304
+ } else {
305
+ log(`self-update: rolling back to ${MODULE_ID}@${previousVersion}`);
306
+ try {
307
+ const restored = await manager.installBundle(`${MODULE_ID}@${previousVersion}`, {
308
+ enabled: true,
309
+ registry,
310
+ requestId: randomUUID(),
311
+ });
312
+ if (restored?.error !== undefined || restored?.application === 'failed') {
313
+ const detail = restored?.error === undefined
314
+ ? ''
315
+ : `${restored.error.code ?? 'error'} ${restored.error.diagnostic ?? ''}`.trim();
316
+ throw new Error(`rollback install failed${detail === '' ? '' : `: ${detail}`}`);
317
+ }
318
+ rolledBack = true;
319
+ log(`self-update: rolled back to ${previousVersion} (application=${restored?.application ?? 'unknown'})`);
320
+ } catch (rollbackFailure) {
321
+ rollbackError = String(rollbackFailure?.message ?? rollbackFailure);
322
+ log(`self-update: rollback failed: ${rollbackError}`);
323
+ }
324
+ }
325
+ }
326
+ return {
327
+ ok: false,
328
+ stage,
329
+ error: message,
330
+ rolledBack,
331
+ ...(rollbackError === undefined ? {} : { rollbackError }),
332
+ };
268
333
  }
269
334
  }
270
335
 
@@ -414,9 +479,11 @@ export const __test = {
414
479
  normalizeVersion,
415
480
  normalizeStopReason,
416
481
  killReasonFor,
482
+ selfVersion,
417
483
  auditProfileBundles,
418
484
  profileDirectory,
419
485
  HOST_STARTED_AT,
486
+ SELF_VERSION,
420
487
  ROUTE,
421
488
  MODULE_ID,
422
489
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@restregular/dsh-powerup",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Power-Up — small, opt-in upgrades for DeepSeek Harness. Adds a right-click action menu to the Trajectory ledger, an optional stop reason in the session header's background jobs panel (appended to the injected completion notice), and an update control for third-party plugins installed from the Plugins page, with version lookup from the configured registries, a starred default source, uninstall-and-reinstall through the Add plugin path, restart-needed markers, a background self-update, and an optional DSH restart. · 为 DeepSeek Harness 提供小型增强:在轨迹页面右键记录即可复制、引用、查看详情或从该记录 Fork;在会话顶部的后台任务面板手动停止任务时可填写停止原因,原因会附加到任务结束后的会话提示;并在插件页为已安装插件提供带版本查询的更新按钮,安装源可设默认,沿用「添加插件」的安装流程,支持待重启标记、后台自更新与一键重启。",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",