dsh-version-manager 0.1.6 → 0.1.8

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 ADDED
@@ -0,0 +1,20 @@
1
+ # Changelog
2
+
3
+ ## 0.1.8
4
+
5
+ - Fix bounded vertical scrolling and automatically expand version checks.
6
+ - Add confirmed sequential batch updates and opt-in migration from local archives to the same named stable npm bundle.
7
+ - Validate source, identity, compatibility and archive digest; snapshot before writes, serialize mutations, verify installed state and attempt rollback on failure.
8
+ - Retain all admission hardening from 0.1.7.
9
+
10
+ ## 0.1.7
11
+
12
+ - Apply DSH Host/Origin and authentication admission to every HTTP route before owner authorization, body parsing or profile service access. Refuse missing, throwing and invalid synchronous checks.
13
+ - Refuse asynchronous host verdicts and consume rejected promises so an incompatible host check cannot leave an unhandled rejection.
14
+ - Apply the same synchronous contract to owner admission: consume rejected promises/thenables, refuse invalid rejection statuses and catch unreadable service or principal fields before any route work.
15
+ - Keep owner authorization, HTTP method checks, explicit write confirmation and route disposal. Add regressions for rejected asynchronous checks and unavailable connection services across all 16 routes.
16
+ - Retain the 0.1.6 client presentation and existing Node.js/DSH version ranges. See the [bilingual release notes](docs/release-notes-0.1.7.md).
17
+
18
+ ## 0.1.6
19
+
20
+ - Keep long names and source paths from squeezing version and action columns; contain table scrolling on narrow windows. See the [bilingual release notes](docs/release-notes-0.1.6.md).
package/README.md CHANGED
@@ -18,19 +18,21 @@
18
18
 
19
19
  ## Get started
20
20
 
21
- Desktop: install the release `.tgz` through Extensions → Plugin Management → Add Plugin. For a Web profile you explicitly control:
21
+ Desktop: enter `dsh-version-manager` in Extensions → Plugin Management → Add Plugin. Prefer the npm source to enable future online updates. Release `.tgz` files are for offline installation; the host cannot update local archives online. For a Web profile you explicitly control:
22
22
 
23
23
  ```sh
24
- dsh plugin --profile web add dsh-version-manager@0.1.6
24
+ dsh plugin --profile web add dsh-version-manager@0.1.8
25
25
  ```
26
26
 
27
27
  Install into an existing Desktop/Web profile and open Version manager. Review inventory and the exact from → to update first; a new empty profile also needs the Web app bundle.
28
28
 
29
+ The panel scrolls vertically and supports horizontal scrolling on narrow screens. “Check all updates” defaults to writable npm plugins; “Update all” previews exact changes and asks for confirmation. Updates run sequentially, snapshot each target first, and stop on failure. Opt into “Include local archives (change source to npm)” to migrate local `.tgz` installs to the same named stable npm bundle, showing the source change before confirmation. Failed installs attempt rollback to the retained original archive and preserve disabled state. Missing archives, identity mismatch, downgrades and unconfirmed compatibility refuse migration. Prerelease, deprecated, non-bundle, Git, directory, alias and official sources are not automatically updated. Single checks expand their results automatically.
30
+
29
31
  ## Status and compatibility
30
32
 
31
33
  | Item | Current source of truth |
32
34
  | --- | --- |
33
- | Source version | `0.1.6` · 以 [package.json](package.json) 为准 |
35
+ | Source version | `0.1.8` · see [package.json](package.json) |
34
36
  | Distribution | `npm` · [Releases](https://github.com/tangyixiao/dsh-version-manager/releases) |
35
37
  | DSH | `>=0.2.2-rc.1` |
36
38
  | Node.js | `>=22` |
@@ -40,6 +42,8 @@ Restore is not a full backup: restoring a plugin version does not roll back conf
40
42
 
41
43
  [Detailed usage, configuration and troubleshooting](docs/guide.en.md)
42
44
 
45
+ HTTP routes require the host's synchronous `connection.requestRejection(request)` check before owner authorization, request bodies or profile services. Missing, throwing or asynchronous checks refuse access. See the [0.1.8 release notes](docs/release-notes-0.1.8.md) and [changelog](CHANGELOG.md).
46
+
43
47
  ## Development and participation
44
48
 
45
49
  ```sh
package/README.zh-CN.md CHANGED
@@ -18,19 +18,21 @@
18
18
 
19
19
  ## 开始使用
20
20
 
21
- Desktop:从发行页下载 `.tgz`,在“扩展 → 插件管理 → 添加插件”中安装。命令行示例用于你明确控制的 Web profile:
21
+ Desktop:在“扩展 → 插件管理 → 添加插件”中输入 `dsh-version-manager`,优先使用 npm 来源,以便后续在线更新。发行页 `.tgz` 用于离线安装;宿主把本地安装包视为不可在线更新来源。命令行示例用于你明确控制的 Web profile:
22
22
 
23
23
  ```sh
24
- dsh plugin --profile web add dsh-version-manager@0.1.6
24
+ dsh plugin --profile web add dsh-version-manager@0.1.8
25
25
  ```
26
26
 
27
27
  在原有 Desktop/Web profile 中安装并打开“版本管理”。先查看清单与更新预览,再确认具体 from → to;新建空 profile 还需要 Web 应用 bundle。
28
28
 
29
+ 面板支持上下滚动与窄屏横向滚动。“检查全部更新”默认检查当前 profile 中可写入的 npm 插件,展示版本变化后可“一键更新”;更新逐项执行,每项先拍快照,失败即停。勾选“包含本地安装包(切换到 npm 来源)”后,可将本地 `.tgz` 安装迁移到同名 npm 正式版;确认前展示来源变化,失败时尝试恢复原安装包,保留停用状态。原包不存在、身份不符、版本过旧或兼容性未确认时拒绝迁移。预发布、已废弃、非 bundle、Git、目录、别名及官方内置来源不自动更新。单项检查会自动展开结果。
30
+
29
31
  ## 当前状态与兼容性
30
32
 
31
33
  | 项目 | 当前依据 |
32
34
  | --- | --- |
33
- | 源码版本 | `0.1.6` · 以 [package.json](package.json) 为准 |
35
+ | 源码版本 | `0.1.8` · 以 [package.json](package.json) 为准 |
34
36
  | 分发方式 | `npm` · [Releases](https://github.com/tangyixiao/dsh-version-manager/releases) |
35
37
  | DSH | `>=0.2.2-rc.1` |
36
38
  | Node.js | `>=22` |
@@ -40,6 +42,8 @@ dsh plugin --profile web add dsh-version-manager@0.1.6
40
42
 
41
43
  [Detailed guide](docs/guide.en.md)
42
44
 
45
+ HTTP 路由先调用宿主同步的 `connection.requestRejection(request)` 检查,再验证 owner 权限、读取请求体和访问 profile 服务。宿主检查缺失、抛错或返回异步结果时拒绝访问。参见 [0.1.8 发行说明](docs/release-notes-0.1.8.md)与[更新记录](CHANGELOG.md)。
46
+
43
47
  ## 开发与参与
44
48
 
45
49
  ```sh
@@ -0,0 +1,21 @@
1
+ # dsh-version-manager 0.1.7
2
+
3
+ ## 简体中文
4
+
5
+ - 将主分支已有的 HTTP 路由准入修复纳入发行包:全部 16 条路由先调用宿主 `connection.requestRejection(request)`,执行 Host/Origin 与身份检查,再验证 owner 权限、读取请求体和访问 profile 服务。
6
+ - 宿主检查缺失、抛错或返回非法值时拒绝访问。该接口必须同步返回 `undefined`、`401` 或 `403`;异步结果也拒绝,并消费其 Promise 拒绝,避免出现未处理拒绝。
7
+ - owner 准入同样要求同步结果;异步结果及不可读取的服务、拒绝状态或身份字段会安全拒绝,Promise/thenable 的拒绝被消费。
8
+ - 保留只允许 owner、HTTP 方法限制、写操作显式确认和路由卸载清理;新增异步拒绝及 connection 服务不可读的全路由回归测试。
9
+ - 已核对的官方 rc.3 宿主中,`requestRejection` 委托 `admit`,而 `admit` 本身已检查 Host/Origin;本次明确调用宿主公开检查接口并加强失败时拒绝访问的处理,不据此宣称该宿主已有准入绕过。
10
+ - 保留 0.1.6 的客户端布局和现有 Node.js `>=22`、DSH `>=0.2.2-rc.1` 声明。宿主必须提供上述同步准入接口;无法验证该接口时 HTTP 功能不可用。
11
+ - 更新既有 profile 中的插件后,确认宿主已重新加载新版,再打开版本管理。版本恢复仍不回滚配置、依赖树或 agent presets。
12
+
13
+ ## English
14
+
15
+ - Include the HTTP route admission fix already on main in the distribution: all 16 routes call the host's `connection.requestRejection(request)` for Host/Origin and authentication checks before owner authorization, body parsing or profile service access.
16
+ - Refuse access if the host check is missing, throws or returns an invalid value. The contract is synchronous and accepts only `undefined`, `401` or `403`. Asynchronous results are refused and their promise rejections are consumed to avoid unhandled rejections.
17
+ - Owner admission also requires a synchronous result. Asynchronous results and unreadable service, rejection or principal fields fail closed, and rejected promises/thenables are consumed.
18
+ - Preserve owner-only access, HTTP method checks, explicit write confirmation and route disposal. Add regressions across every route for rejected asynchronous verdicts and unavailable connection services.
19
+ - In the verified official rc.3 host, `requestRejection` delegates to `admit`, which already checks Host/Origin. This release explicitly uses the host's public check and strengthens fail-closed handling; it does not establish an admission bypass in that host.
20
+ - Retain the 0.1.6 client layout and declared Node.js `>=22` / DSH `>=0.2.2-rc.1` ranges. The host must provide the synchronous admission API above; HTTP features remain unavailable when that check cannot be verified.
21
+ - After updating the plugin in the existing profile, confirm that the host has reloaded the new version before opening Version manager. Version restore still does not roll back configuration, dependency trees or agent presets.
@@ -0,0 +1,33 @@
1
+ # dsh-version-manager 0.1.8
2
+
3
+ ## 简体中文
4
+
5
+ - 修复主面板纵向滚动,根据窗口与宿主裁切区域计算可见高度;保留窄屏横向滚动。
6
+ - 单项检查自动展开结果;新增批量检查、版本变化预览与统一确认更新,逐项执行且失败即停。
7
+ - 支持明确确认后将本地 `.tgz` 安装迁移到同名 npm 正式版;检查包身份、兼容性、旧来源及安装包指纹,失败时尝试恢复原来源,保留停用状态。
8
+ - 批量迁移默认关闭;不替换 Git、目录、别名和官方内置来源,不自动降级或选择预发布。
9
+ - 更新前保存快照,共享写入锁;完成后回读实际版本及来源。保留 DSH Host/Origin 与 owner 认证检查。
10
+ - 推荐使用 npm 安装,后续可以直接在线更新。
11
+ - 将主分支已有的 HTTP 路由准入修复纳入发行包:全部 16 条路由先调用宿主 `connection.requestRejection(request)`,执行 Host/Origin 与身份检查,再验证 owner 权限、读取请求体和访问 profile 服务。
12
+ - 宿主检查缺失、抛错或返回非法值时拒绝访问。该接口必须同步返回 `undefined`、`401` 或 `403`;异步结果也拒绝,并消费其 Promise 拒绝,避免出现未处理拒绝。
13
+ - owner 准入同样要求同步结果;异步结果及不可读取的服务、拒绝状态或身份字段会安全拒绝,Promise/thenable 的拒绝被消费。
14
+ - 保留只允许 owner、HTTP 方法限制、写操作显式确认和路由卸载清理;新增异步拒绝及 connection 服务不可读的全路由回归测试。
15
+ - 已核对的官方 rc.3 宿主中,`requestRejection` 委托 `admit`,而 `admit` 本身已检查 Host/Origin;本次明确调用宿主公开检查接口并加强失败时拒绝访问的处理,不据此宣称该宿主已有准入绕过。
16
+ - 保留现有 Node.js `>=22`、DSH `>=0.2.2-rc.1` 声明。宿主必须提供上述同步准入接口;无法验证该接口时 HTTP 功能不可用。
17
+ - 更新既有 profile 中的插件后,确认宿主已重新加载新版,再打开版本管理。版本恢复仍不回滚配置、依赖树或 agent presets。
18
+
19
+ ## English
20
+
21
+ - Bound vertical scrolling to the actual visible host area while retaining narrow-screen horizontal scrolling.
22
+ - Expand individual version results automatically; add batch checks, exact previews and confirmed sequential updates that stop on failure.
23
+ - Opt into migrating local `.tgz` installs to the same named stable npm bundle. Validate identity, compatibility, source and archive fingerprint, preserve disabled state, and attempt rollback to the retained original archive on failure.
24
+ - Local migration is off by default. Git, directories, aliases, official bundles, downgrades and prereleases are excluded.
25
+ - Snapshot before changes, serialize writes and verify the installed version/source after completion. Preserve host admission and owner authentication.
26
+ - Prefer npm installation for subsequent online updates.
27
+ - Include the HTTP route admission fix already on main in the distribution: all 16 routes call the host's `connection.requestRejection(request)` for Host/Origin and authentication checks before owner authorization, body parsing or profile service access.
28
+ - Refuse access if the host check is missing, throws or returns an invalid value. The contract is synchronous and accepts only `undefined`, `401` or `403`. Asynchronous results are refused and their promise rejections are consumed to avoid unhandled rejections.
29
+ - Owner admission also requires a synchronous result. Asynchronous results and unreadable service, rejection or principal fields fail closed, and rejected promises/thenables are consumed.
30
+ - Preserve owner-only access, HTTP method checks, explicit write confirmation and route disposal. Add regressions across every route for rejected asynchronous verdicts and unavailable connection services.
31
+ - In the verified official rc.3 host, `requestRejection` delegates to `admit`, which already checks Host/Origin. This release explicitly uses the host's public check and strengthens fail-closed handling; it does not establish an admission bypass in that host.
32
+ - Retain the declared Node.js `>=22` / DSH `>=0.2.2-rc.1` ranges. The host must provide the synchronous admission API above; HTTP features remain unavailable when that check cannot be verified.
33
+ - After updating the plugin in the existing profile, confirm that the host has reloaded the new version before opening Version manager. Version restore still does not roll back configuration, dependency trees or agent presets.
package/lib/client.js CHANGED
@@ -79,6 +79,21 @@ window.__ModuleLoader__.load({
79
79
  colCompat: '兼容性',
80
80
  colActions: '操作',
81
81
  tableScroll: '插件列表,可横向滚动',
82
+ panelScroll: '版本管理,可上下滚动',
83
+ checkAll: '检查全部更新',
84
+ updateAll: '一键更新',
85
+ batchChecking: (done, total) => `正在检查 ${done}/${total}`,
86
+ batchReady: (count) => `发现 ${count} 个可更新插件`,
87
+ batchConfirm: '更新下列插件?',
88
+ batchNotes: '依次更新,每项更新前自动拍快照;失败即停。跳过预发布、不兼容和已废弃版本。本地安装包仅在明确勾选后切换到 npm 来源。',
89
+ batchDone: (done, total) => `已更新 ${done}/${total} 个插件`,
90
+ batchEmpty: '未发现可直接更新的正式版。',
91
+ localInstall: '本地安装包',
92
+ localUpdateHelp: '可检查同名 npm 正式版,确认后切换来源并更新。原本地安装包保留,安装失败时尝试恢复原来源。',
93
+ includeLocal: '包含本地安装包(切换到 npm 来源)',
94
+ migrateAction: '检查在线版本',
95
+ migrateConfirm: '切换到 npm 来源并更新',
96
+ migrateBody: (name, source, version) => `将 ${name} 的安装来源从 ${source} 切换为 npm 正式版 ${version}。之后可以直接在线更新。`,
82
97
  skillTableScroll: 'Skill 列表,可横向滚动',
83
98
  checkVersions: '检查更新',
84
99
  checking: '检查中…',
@@ -349,6 +364,21 @@ window.__ModuleLoader__.load({
349
364
  colCompat: 'Compatibility',
350
365
  colActions: 'Actions',
351
366
  tableScroll: 'Plugin list, scroll horizontally',
367
+ panelScroll: 'Version manager, scroll vertically',
368
+ checkAll: 'Check all updates',
369
+ updateAll: 'Update all',
370
+ batchChecking: (done, total) => `Checking ${done}/${total}`,
371
+ batchReady: (count) => `${count} plugins can be updated`,
372
+ batchConfirm: 'Update these plugins?',
373
+ batchNotes: 'Update sequentially with a snapshot before each change; stop on failure. Skip prerelease, incompatible and deprecated versions. Local archives change to npm only after explicit opt-in.',
374
+ batchDone: (done, total) => `Updated ${done}/${total} plugins`,
375
+ batchEmpty: 'No stable versions available for direct update.',
376
+ localInstall: 'Local archive',
377
+ localUpdateHelp: 'Check the same named stable npm bundle, then confirm a source change and update. The original archive is retained and used for rollback if installation fails.',
378
+ includeLocal: 'Include local archives (change source to npm)',
379
+ migrateAction: 'Check online version',
380
+ migrateConfirm: 'Change source to npm and update',
381
+ migrateBody: (name, source, version) => `Change ${name} from ${source} to stable npm version ${version}. Future updates can then use the registry directly.`,
352
382
  skillTableScroll: 'Skill list, scroll horizontally',
353
383
  checkVersions: 'Check versions',
354
384
  checking: 'Checking…',
@@ -782,6 +812,132 @@ window.__ModuleLoader__.load({
782
812
  // local tarball paths must not take space away from versions and actions.
783
813
  const ELLIPSIS = { display: 'block', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', minWidth: 0 }
784
814
 
815
+ function usePanelViewport() {
816
+ const element = useRef(null)
817
+ const [height, setHeight] = useState(null)
818
+ useEffect(() => {
819
+ const node = element.current
820
+ if (node === null) return undefined
821
+ const measure = () => {
822
+ const top = node.getBoundingClientRect().top
823
+ let bottom = window.visualViewport
824
+ ? window.visualViewport.offsetTop + window.visualViewport.height
825
+ : window.innerHeight
826
+ for (let parent = node.parentElement; parent; parent = parent.parentElement) {
827
+ const rect = parent.getBoundingClientRect()
828
+ if (rect.height > 0 && /hidden|clip|auto|scroll/.test(window.getComputedStyle(parent).overflowY)) {
829
+ bottom = Math.min(bottom, rect.bottom)
830
+ }
831
+ }
832
+ setHeight(Math.max(0, Math.floor(bottom - top)))
833
+ }
834
+ measure()
835
+ const observer = typeof ResizeObserver === 'function' ? new ResizeObserver(measure) : null
836
+ if (node.parentElement) observer?.observe(node.parentElement)
837
+ window.addEventListener('resize', measure)
838
+ window.visualViewport?.addEventListener('resize', measure)
839
+ return () => {
840
+ observer?.disconnect()
841
+ window.removeEventListener('resize', measure)
842
+ window.visualViewport?.removeEventListener('resize', measure)
843
+ }
844
+ }, [])
845
+ return { ref: element, height }
846
+ }
847
+
848
+ function localArchive(row) {
849
+ return row.updateRefusal === 'not-registry:tarball' && row.source?.kind === 'tarball' &&
850
+ (/^file:/i.test(row.declaredSpec ?? '') || (row.declaredSpec ?? '').startsWith(`${row.targetId}@file:`))
851
+ }
852
+
853
+ function safeUpdate(item, installed, migration = false) {
854
+ return item.isBundle === true && !item.deprecated && !item.prerelease &&
855
+ (migration || item.version !== installed) && item.incompatible == null &&
856
+ (item.compatibility == null || !item.compatibility.requirements || item.compatibility.exempted === true)
857
+ }
858
+
859
+ function BatchUpdates({ rows, t, onRefresh }) {
860
+ const [state, setState] = useState({ phase: 'idle', items: [], messages: [], done: 0, total: 0 })
861
+ const busy = state.phase === 'checking' || state.phase === 'updating'
862
+ const active = useRef(false)
863
+ const [includeLocal, setIncludeLocal] = useState(false)
864
+ const check = async () => {
865
+ if (active.current) return
866
+ active.current = true
867
+ const targets = rows.filter(row => row.updateRefusal === null || (includeLocal && localArchive(row)))
868
+ const items = []
869
+ const messages = []
870
+ setState({ phase: 'checking', items: [], messages: [], done: 0, total: targets.length })
871
+ try {
872
+ for (let index = 0; index < targets.length; index++) {
873
+ const row = targets[index]
874
+ try {
875
+ const listing = await request(`/versions?target=${encodeURIComponent(row.targetId)}${localArchive(row) ? '&migrateToRegistry=true' : ''}`)
876
+ if (listing.status !== 'ok') throw new Error(listing.message ?? listing.reason ?? listing.status)
877
+ const candidate = listing.stable.find(item => safeUpdate(item, row.installedVersion, !!listing.sourceMigration))
878
+ if (candidate) items.push({ targetId: row.targetId, from: row.installedVersion, version: candidate.version, sourceMigration: listing.sourceMigration })
879
+ } catch (error) {
880
+ messages.push(`${row.targetId}: ${describeError(error, t)}`)
881
+ }
882
+ setState({ phase: 'checking', items: [...items], messages: [...messages], done: index + 1, total: targets.length })
883
+ }
884
+ // Updating the running manager can unmount this panel. Finish it last.
885
+ items.sort((a, b) => Number(a.targetId === PANEL_ID) - Number(b.targetId === PANEL_ID))
886
+ setState({ phase: 'ready', items, messages, done: 0, total: items.length })
887
+ } finally {
888
+ active.current = false
889
+ }
890
+ }
891
+ const update = async () => {
892
+ if (active.current || state.phase !== 'confirm') return
893
+ active.current = true
894
+ let done = 0
895
+ const messages = [...state.messages]
896
+ setState(previous => ({ ...previous, phase: 'updating', done }))
897
+ try {
898
+ for (const item of state.items) {
899
+ const result = await request('/update', {
900
+ method: 'POST',
901
+ body: { targetId: item.targetId, toVersion: item.version, fromVersion: item.from, confirm: true,
902
+ ...(item.sourceMigration ? { migrateToRegistry: true, expectedSource: item.sourceMigration.from, archiveDigest: item.sourceMigration.archiveDigest } : {}) },
903
+ })
904
+ if (result.ok !== true) throw new Error(`${item.targetId}: ${result.message ?? t.updateFailed}`)
905
+ done++
906
+ setState(previous => ({ ...previous, done }))
907
+ }
908
+ } catch (error) {
909
+ messages.push(describeError(error, t))
910
+ } finally {
911
+ setState(previous => ({ ...previous, phase: 'done', done, messages }))
912
+ active.current = false
913
+ await onRefresh()
914
+ }
915
+ }
916
+ return h('div', { style: { margin: '10px 0', fontSize: 12 } },
917
+ h('label', { style: { display: 'block', marginBottom: 6 } },
918
+ h('input', { type: 'checkbox', checked: includeLocal, disabled: busy, onChange: event => {
919
+ setIncludeLocal(event.target.checked)
920
+ setState({ phase: 'idle', items: [], messages: [], done: 0, total: 0 })
921
+ } }), ' ', t.includeLocal),
922
+ h('div', { style: { display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' } },
923
+ h(Button, { onClick: check, disabled: busy }, state.phase === 'checking' ? t.batchChecking(state.done, state.total) : t.checkAll),
924
+ state.phase === 'ready' && state.items.length > 0
925
+ ? h(Button, { primary: true, onClick: () => setState(previous => ({ ...previous, phase: 'confirm' })) }, `${t.updateAll} (${state.items.length})`)
926
+ : null,
927
+ h('span', { role: 'status' },
928
+ state.phase === 'ready' ? (state.items.length ? t.batchReady(state.items.length) : t.batchEmpty) :
929
+ state.phase === 'updating' || state.phase === 'done' ? t.batchDone(state.done, state.total) : ''),
930
+ ),
931
+ state.items.length > 0 ? h('ul', { style: { margin: '6px 0', paddingLeft: 20 } },
932
+ state.items.map(item => h('li', { key: item.targetId }, `${item.targetId}: ${item.from} → ${item.version}${item.sourceMigration ? ` · ${item.sourceMigration.from} → ${item.sourceMigration.to}` : ''}`))) : null,
933
+ state.phase === 'confirm' ? h(ConfirmBar, {
934
+ title: t.batchConfirm, body: t.batchNotes, notes: state.items.some(item => item.sourceMigration) ? [t.includeLocal] : [], t, busy: false,
935
+ onConfirm: update, onCancel: () => setState(previous => ({ ...previous, phase: 'ready' })),
936
+ }) : null,
937
+ state.messages.map((message, index) => h(Notice, { key: index, tone: 'warn', title: t.errorLabel }, message)),
938
+ )
939
+ }
940
+
785
941
  function TableViewport({ label, children }) {
786
942
  return h('div', {
787
943
  role: 'region',
@@ -945,6 +1101,7 @@ window.__ModuleLoader__.load({
945
1101
  item.version === installed ? h(Badge, null, t.colVersion) : null,
946
1102
  item.deprecated !== null && item.deprecated !== undefined ? h(Badge, null, t.deprecated) : null,
947
1103
  item.isBundle === false ? h(Badge, null, 'not a bundle') : null,
1104
+ item.incompatible != null ? h(Badge, { tone: 'warn' }, t.compatFail) : null,
948
1105
  item.compatibility !== null && item.compatibility !== undefined && item.compatibility.exempted !== true
949
1106
  ? h(Badge, null, item.compatibility.requirements ? t.compatFail : t.compatOk)
950
1107
  : null,
@@ -954,7 +1111,7 @@ window.__ModuleLoader__.load({
954
1111
  Button,
955
1112
  {
956
1113
  onClick: () => onPick(item),
957
- disabled: busyVersion !== null,
1114
+ disabled: busyVersion !== null || (item.version === installed && !data.sourceMigration) || !item.isBundle || item.incompatible != null,
958
1115
  primary: false,
959
1116
  ariaLabel: `${t.updateTo} ${item.version}`,
960
1117
  },
@@ -1089,7 +1246,7 @@ window.__ModuleLoader__.load({
1089
1246
  }
1090
1247
 
1091
1248
  function Row(props) {
1092
- const { row, t, language, expanded, onToggle, onRefresh } = props
1249
+ const { row, t, language, expanded, onToggle, onExpand, onRefresh } = props
1093
1250
  const [versions, setVersions] = useState(null)
1094
1251
  const [versionsBusy, setVersionsBusy] = useState(false)
1095
1252
  const [versionsError, setVersionsError] = useState(null)
@@ -1102,16 +1259,17 @@ window.__ModuleLoader__.load({
1102
1259
  const [pruneBusy, setPruneBusy] = useState(false)
1103
1260
  const [pendingPrune, setPendingPrune] = useState(false)
1104
1261
  const loadVersions = useCallback(async () => {
1262
+ onExpand()
1105
1263
  setVersionsBusy(true)
1106
1264
  setVersionsError(null)
1107
1265
  try {
1108
- setVersions(await request(`/versions?target=${encodeURIComponent(row.targetId)}`))
1266
+ setVersions(await request(`/versions?target=${encodeURIComponent(row.targetId)}${localArchive(row) ? '&migrateToRegistry=true' : ''}`))
1109
1267
  } catch (error) {
1110
1268
  setVersionsError(error)
1111
1269
  } finally {
1112
1270
  setVersionsBusy(false)
1113
1271
  }
1114
- }, [row.targetId])
1272
+ }, [row.targetId, onExpand])
1115
1273
 
1116
1274
  const takeSnapshot = useCallback(async () => {
1117
1275
  setSnapshotBusy(true)
@@ -1167,6 +1325,8 @@ window.__ModuleLoader__.load({
1167
1325
  targetId: row.targetId,
1168
1326
  toVersion: pendingUpdate.version,
1169
1327
  allowPrerelease: pendingUpdate.prerelease === true,
1328
+ fromVersion: row.installedVersion,
1329
+ ...(pendingUpdate.sourceMigration ? { migrateToRegistry: true, expectedSource: pendingUpdate.sourceMigration.from, archiveDigest: pendingUpdate.sourceMigration.archiveDigest } : {}),
1170
1330
  confirm: true,
1171
1331
  },
1172
1332
  })
@@ -1262,7 +1422,7 @@ window.__ModuleLoader__.load({
1262
1422
  'div',
1263
1423
  { style: { display: 'flex', gap: 4, marginTop: 3, flexWrap: 'wrap' } },
1264
1424
  row.official === true ? h(Badge, null, t.official) : null,
1265
- writable ? null : h(Badge, null, t.readOnly),
1425
+ writable ? null : h(Badge, { tone: 'warn' }, row.source.kind === 'tarball' || row.source.kind === 'file' ? t.localInstall : t.readOnly),
1266
1426
  row.prerelease === true ? h(Badge, null, t.prerelease) : null,
1267
1427
  ),
1268
1428
  ),
@@ -1294,14 +1454,14 @@ window.__ModuleLoader__.load({
1294
1454
  h(
1295
1455
  Button,
1296
1456
  {
1297
- onClick: loadVersions,
1298
- disabled: !writable || versionsBusy,
1457
+ onClick: writable || localArchive(row) ? loadVersions : onExpand,
1458
+ disabled: versionsBusy,
1299
1459
  title: writable ? undefined : refusalLabel(row.updateRefusal, t) ?? '',
1300
1460
  // Every row renders the same words, so the label alone leaves
1301
1461
  // eight identical "检查更新" buttons in the accessibility tree.
1302
1462
  ariaLabel: `${t.checkVersions}: ${row.targetId}`,
1303
1463
  },
1304
- versionsBusy ? t.checking : t.checkVersions,
1464
+ versionsBusy ? t.checking : writable ? t.checkVersions : localArchive(row) ? t.migrateAction : t.details,
1305
1465
  ),
1306
1466
  h(
1307
1467
  Button,
@@ -1354,7 +1514,7 @@ window.__ModuleLoader__.load({
1354
1514
  }),
1355
1515
  row.updateRefusal === null
1356
1516
  ? null
1357
- : h(Field, { label: t.readOnly, value: refusalLabel(row.updateRefusal, t) }),
1517
+ : h(Field, { label: t.readOnly, value: row.source.kind === 'tarball' || row.source.kind === 'file' ? t.localUpdateHelp : refusalLabel(row.updateRefusal, t) }),
1358
1518
 
1359
1519
  h('div', { style: { marginTop: 10 } }, h('div', { style: { fontSize: 12, fontWeight: 600 } }, t.snapshots),
1360
1520
  h(SnapshotList, {
@@ -1393,7 +1553,7 @@ window.__ModuleLoader__.load({
1393
1553
  data: versions,
1394
1554
  installed: row.installedVersion,
1395
1555
  busyVersion: updateBusy ? pendingUpdate?.version ?? null : null,
1396
- onPick: (item) => setPendingUpdate({ version: item.version, prerelease: item.prerelease }),
1556
+ onPick: (item) => setPendingUpdate({ version: item.version, prerelease: item.prerelease, sourceMigration: versions?.sourceMigration }),
1397
1557
  }),
1398
1558
 
1399
1559
  pendingUpdate === null
@@ -1401,7 +1561,7 @@ window.__ModuleLoader__.load({
1401
1561
  : h(ConfirmBar, {
1402
1562
  t,
1403
1563
  title: t.confirmTitle,
1404
- body: t.confirmBody(row.targetId, row.installedVersion ?? t.unknown, pendingUpdate.version),
1564
+ body: pendingUpdate.sourceMigration ? t.migrateBody(row.targetId, pendingUpdate.sourceMigration.from, pendingUpdate.version) : t.confirmBody(row.targetId, row.installedVersion ?? t.unknown, pendingUpdate.version),
1405
1565
  notes: t.confirmNotes,
1406
1566
  busy: updateBusy,
1407
1567
  onCancel: () => setPendingUpdate(null),
@@ -2193,6 +2353,7 @@ window.__ModuleLoader__.load({
2193
2353
  const [skills, setSkills] = useState({ status: 'idle', data: null, error: null })
2194
2354
  const abortRef = useRef(null)
2195
2355
  const skillsAbortRef = useRef(null)
2356
+ const viewport = usePanelViewport()
2196
2357
 
2197
2358
  const refresh = useCallback(async () => {
2198
2359
  abortRef.current?.abort()
@@ -2391,6 +2552,7 @@ window.__ModuleLoader__.load({
2391
2552
  language,
2392
2553
  expanded: expanded === row.targetId,
2393
2554
  onToggle: () => setExpanded((current) => (current === row.targetId ? null : row.targetId)),
2555
+ onExpand: () => setExpanded(row.targetId),
2394
2556
  onRefresh: refresh,
2395
2557
  }),
2396
2558
  ),
@@ -2399,6 +2561,8 @@ window.__ModuleLoader__.load({
2399
2561
 
2400
2562
  return h(
2401
2563
  'div',
2564
+ { ref: viewport.ref, role: 'region', 'aria-label': t.panelScroll, tabIndex: 0, style: { height: viewport.height ?? '100%', maxHeight: '100dvh', flex: '0 0 auto', minHeight: 0, width: '100%', overflowY: 'scroll', overflowX: 'hidden', scrollbarWidth: 'auto', scrollbarGutter: 'stable', scrollbarColor: '#85858b transparent', boxSizing: 'border-box' } },
2565
+ h('div',
2402
2566
  { style: { padding: '18px 20px 32px', width: '100%', minWidth: 0, boxSizing: 'border-box', maxWidth: 1240, margin: '0 auto', overflowWrap: 'anywhere', lineHeight: 1.5 } },
2403
2567
  header,
2404
2568
  state.error === null
@@ -2472,7 +2636,7 @@ window.__ModuleLoader__.load({
2472
2636
  loading: skills.status === 'loading',
2473
2637
  onReload: loadSkills,
2474
2638
  })
2475
- : toolbar,
2639
+ : h(React.Fragment, null, h(BatchUpdates, { rows, t, onRefresh: refresh }), toolbar),
2476
2640
  tab !== 'plugins'
2477
2641
  ? skills.error === null
2478
2642
  ? null
@@ -2491,6 +2655,7 @@ window.__ModuleLoader__.load({
2491
2655
  h(OperationsList, { t, language, operations: state.data.operations ?? [] }),
2492
2656
  ),
2493
2657
  ),
2658
+ ),
2494
2659
  )
2495
2660
  }
2496
2661
 
@@ -0,0 +1,93 @@
1
+ import { createHash } from 'node:crypto'
2
+ import { readFile, stat } from 'node:fs/promises'
3
+ import { resolve } from 'node:path'
4
+ import { classifySpec } from './spec.js'
5
+ import { evaluateCompatibility, parseVersion } from './compat.js'
6
+
7
+ export const REGISTRY = 'https://registry.npmjs.org/'
8
+
9
+ export function canMigrate(row) {
10
+ if (!row || row.official || row.availability !== 'profile' || row.source?.kind !== 'tarball') return false
11
+ if (row.updateRefusal !== 'not-registry:tarball') return false
12
+ const spec = row.declaredSpec ?? ''
13
+ return /^file:/i.test(spec) || spec.startsWith(`${row.targetId}@file:`)
14
+ }
15
+
16
+ export async function archiveDigest(row, profileDir) {
17
+ if (!canMigrate(row)) throw new Error('Only installed local archives can change to a registry source.')
18
+ const source = classifySpec(row.declaredSpec)
19
+ const file = resolve(profileDir, source.detail)
20
+ const info = await stat(file)
21
+ if (!info.isFile() || info.size > 32 * 1024 * 1024) throw new Error('The original archive is missing or exceeds 32 MiB.')
22
+ return createHash('sha256').update(await readFile(file)).digest('hex')
23
+ }
24
+
25
+ export async function previewMigration(row, profile, options = {}) {
26
+ if (!canMigrate(row)) throw new Error('This source cannot migrate to npm.')
27
+ if (!/^(?:@[a-z0-9._-]+\/)?[a-z0-9][a-z0-9._-]*$/.test(row.targetId)) throw new Error('Invalid npm package name.')
28
+ const installed = JSON.parse(await readFile(resolve(profile.dir, 'node_modules', row.targetId, 'package.json'), 'utf8'))
29
+ if (installed.name !== row.targetId || installed.version !== row.installedVersion) throw new Error('The installed package identity changed.')
30
+ const digest = await archiveDigest(row, profile.dir)
31
+ const response = await (options.fetch ?? fetch)(`${REGISTRY}${encodeURIComponent(row.targetId)}/latest`, {
32
+ redirect: 'error', signal: AbortSignal.timeout(15000), headers: { accept: 'application/json' },
33
+ })
34
+ if (!response.ok) throw new Error(`npm metadata request failed: HTTP ${response.status}`)
35
+ const reader = response.body.getReader()
36
+ const chunks = []
37
+ let bytes = 0
38
+ try {
39
+ while (true) {
40
+ const { done, value } = await reader.read()
41
+ if (done) break
42
+ bytes += value.byteLength
43
+ if (bytes > 1024 * 1024) throw new Error('npm metadata exceeds 1 MiB.')
44
+ chunks.push(Buffer.from(value))
45
+ }
46
+ } finally { await reader.cancel().catch(() => {}); reader.releaseLock() }
47
+ const manifest = JSON.parse(Buffer.concat(chunks).toString('utf8'))
48
+ const version = parseVersion(manifest.version)
49
+ const current = parseVersion(row.installedVersion)
50
+ if (manifest.name !== row.targetId || !version || !current || version.prerelease.length || manifest.deprecated ||
51
+ typeof manifest.dsh?.bundle?.patch !== 'string' || !manifest.dsh.bundle.patch || !manifest.dist?.integrity) throw new Error('npm latest is not a verified stable bundle with the same package name.')
52
+ const numeric = v => [v.major, v.minor, v.patch]
53
+ const latestParts = numeric(version), currentParts = numeric(current)
54
+ const differing = latestParts.findIndex((part, index) => part !== currentParts[index])
55
+ if (differing >= 0 && latestParts[differing] < currentParts[differing]) throw new Error('npm latest is older than the installed version.')
56
+ const compatibility = evaluateCompatibility({ manifest, runtimeVersion: row.compatibility?.runtimeVersion })
57
+ if (compatibility.verdict !== 'satisfied') throw new Error('npm latest compatibility could not be confirmed.')
58
+ return {
59
+ status: 'ok', installed: row.installedVersion, registry: REGISTRY,
60
+ sourceMigration: { from: row.declaredSpec, to: `${row.targetId}@${manifest.version}`, archiveDigest: digest },
61
+ stable: [{ version: manifest.version, isBundle: true, prerelease: false, deprecated: null, incompatible: null }],
62
+ prerelease: [], versions: [{ version: manifest.version, isBundle: true, prerelease: false, deprecated: null, incompatible: null }],
63
+ }
64
+ }
65
+
66
+ function applied(result) {
67
+ const inner = result?.result ?? result
68
+ return inner?.changed === true && inner?.application === 'applied'
69
+ }
70
+
71
+ export async function applyMigration(manager, row, version, profile, digest) {
72
+ const replace = async (spec, expectedVersion, registry) => {
73
+ const settings = { saveExact: true, enabled: row.enabledState !== 'disabled', expected: { name: row.targetId, version: expectedVersion }, ...(registry ? { registry } : {}) }
74
+ let result = await manager.installBundle(spec, settings)
75
+ if ((result?.result ?? result)?.error?.code === 'already-installed') {
76
+ const removed = await manager.removeBundle(row.targetId)
77
+ if (!applied(removed)) throw new Error('The host did not remove the previous bundle.')
78
+ result = await manager.installBundle(spec, settings)
79
+ }
80
+ if (!applied(result)) throw new Error('The host did not apply the requested installation.')
81
+ return result
82
+ }
83
+ try {
84
+ return await replace(`${row.targetId}@${version}`, version, REGISTRY)
85
+ } catch (error) {
86
+ let rollback
87
+ try {
88
+ if (await archiveDigest(row, profile.dir) !== digest) throw new Error('The original archive changed; automatic rollback refused.')
89
+ rollback = { ok: true, result: await replace(`file:${classifySpec(row.declaredSpec).detail}`, row.installedVersion) }
90
+ } catch (restoreError) { rollback = { ok: false, message: restoreError.message } }
91
+ return { changed: false, application: 'failed', error: { message: error.message }, rollback }
92
+ }
93
+ }
@@ -7,10 +7,10 @@
7
7
  * no work starts on its own: a refresh is a request, and a change is a request,
8
8
  * which keeps the plugin's cost equal to what the user asked for.
9
9
  *
10
- * Admission comes from `connection.admit(req)`, the same check the host applies
11
- * to its own browser traffic. When that service is absent the route refuses
12
- * rather than falling back to "it is localhost so it is fine" — a local port is
13
- * shared by every process on the machine.
10
+ * Every registered handler first calls `connection.requestRejection(req)` for
11
+ * the host's Host/Origin and authentication checks, then `connection.admit(req)`
12
+ * requires an owner principal. Missing or unverifiable admission refuses the
13
+ * request before its body or any profile service is read.
14
14
  *
15
15
  * @module dsh-version-manager/lib/host/routes
16
16
  */
@@ -48,6 +48,8 @@ import {
48
48
  writeSnapshot,
49
49
  } from './snapshot-store.js'
50
50
  import { classifySpec, declaredSpecMatches, isPrerelease, updateRefusal } from './spec.js'
51
+ import { applyMigration, canMigrate, previewMigration } from './registry-migration.js'
52
+ import { withMutationLock } from './mutation-lock.js'
51
53
 
52
54
  /** Every route this plugin publishes, so the panel and the tests share one list. */
53
55
  export const ROUTE_BASE = '/dsh-version-manager'
@@ -107,23 +109,26 @@ export async function readJsonBody(request) {
107
109
  * @returns {{ ok: true, principal: string } | { ok: false, status: number }}
108
110
  */
109
111
  export function admit(ctx, request) {
110
- const connection = ctx?.get?.('connection')
111
- if (connection === undefined || connection === null || typeof connection.admit !== 'function') {
112
- // No admission service means no way to tell the browser from any other local
113
- // process. Refusing is the only answer that does not invent a security model.
114
- return { ok: false, status: 401 }
115
- }
116
- let admission
117
112
  try {
118
- admission = connection.admit(request)
113
+ const connection = ctx?.get?.('connection')
114
+ if (connection === undefined || connection === null || typeof connection.admit !== 'function') {
115
+ // No admission service means no way to tell the browser from any other local
116
+ // process. Refusing is the only answer that does not invent a security model.
117
+ return { ok: false, status: 401 }
118
+ }
119
+ const admission = connection.admit(request)
120
+ if (admission === null || typeof admission !== 'object') return { ok: false, status: 401 }
121
+ if (typeof admission.then === 'function') {
122
+ Promise.resolve(admission).catch(() => {})
123
+ return { ok: false, status: 401 }
124
+ }
125
+ if ('rejection' in admission) return { ok: false, status: admission.rejection === 403 ? 403 : 401 }
126
+ const kind = admission.peer?.principal?.kind
127
+ if (kind !== 'owner') return { ok: false, status: 403 }
128
+ return { ok: true, principal: kind }
119
129
  } catch {
120
130
  return { ok: false, status: 401 }
121
131
  }
122
- if (admission === null || typeof admission !== 'object') return { ok: false, status: 401 }
123
- if ('rejection' in admission) return { ok: false, status: admission.rejection }
124
- const kind = admission.peer?.principal?.kind
125
- if (kind !== 'owner') return { ok: false, status: 403 }
126
- return { ok: true, principal: kind }
127
132
  }
128
133
 
129
134
  /**
@@ -445,6 +450,11 @@ export async function readVersions(ctx, name, options = {}) {
445
450
  }
446
451
  const parsed = classifySpec(row.source, { official: row.official })
447
452
  const refusal = updateRefusal(row, parsed)
453
+ if (refusal !== null && options.migrateToRegistry === true) {
454
+ const overview = await buildOverview(ctx)
455
+ const target = overview.plugins.find(entry => entry.targetId === name)
456
+ return previewMigration(target, profile, options)
457
+ }
448
458
  if (refusal !== null) {
449
459
  return {
450
460
  status: 'read_only',
@@ -482,6 +492,7 @@ export async function readVersions(ctx, name, options = {}) {
482
492
  deprecated: entry.deprecated ?? null,
483
493
  isBundle: entry.bundle === true,
484
494
  compatibility: entry.compatibility ?? null,
495
+ incompatible: entry.incompatible ?? null,
485
496
  prerelease: isPrerelease(entry.version),
486
497
  }
487
498
  if (item.version === null) continue
@@ -758,7 +769,14 @@ export async function takeSnapshot(ctx, body) {
758
769
  * @param {{ targetId: string, toVersion: string, allowPrerelease?: boolean }} body
759
770
  * @returns {Promise<{ status: number, body: object }>}
760
771
  */
761
- export async function runUpdate(ctx, body) {
772
+ export async function runUpdate(ctx, body, options = {}) {
773
+ const profile = readProfileContext(ctx)
774
+ if (profile.dir === null || profile.id === 'unknown') return { status: 409, body: { error: 'profile-identity-unknown' } }
775
+ const result = await withMutationLock({ dshHome: profile.home }, () => updateTarget(ctx, body, options))
776
+ return result?.reason === 'operation-in-progress' ? { status: 409, body: { error: result.reason } } : result
777
+ }
778
+
779
+ async function updateTarget(ctx, body, options) {
762
780
  const profile = readProfileContext(ctx)
763
781
  if (profile.dir === null || profile.id === 'unknown') {
764
782
  return { status: 409, body: { error: 'profile-identity-unknown' } }
@@ -775,9 +793,23 @@ export async function runUpdate(ctx, body) {
775
793
  const overview = await buildOverview(ctx)
776
794
  const row = overview.plugins.find((entry) => entry.targetId === body.targetId)
777
795
  if (row === undefined) return { status: 404, body: { error: 'unknown-target' } }
778
- if (row.updateRefusal !== null) {
796
+ const migration = body.migrateToRegistry === true && canMigrate(row)
797
+ if (row.updateRefusal !== null && !migration) {
779
798
  return { status: 409, body: { error: 'not-updatable', message: row.updateRefusal } }
780
799
  }
800
+ if (body.fromVersion !== undefined && body.fromVersion !== row.installedVersion) {
801
+ return { status: 409, body: { error: 'stale-update-plan', message: 'Installed version changed; check updates again.' } }
802
+ }
803
+ let migrationPreview
804
+ if (migration) {
805
+ if (body.expectedSource !== row.declaredSpec || body.fromVersion !== row.installedVersion) {
806
+ return { status: 409, body: { error: 'source-confirmation-required' } }
807
+ }
808
+ migrationPreview = await previewMigration(row, profile, options)
809
+ if (migrationPreview.stable[0].version !== toVersion || body.archiveDigest !== migrationPreview.sourceMigration.archiveDigest) {
810
+ return { status: 409, body: { error: 'stale-update-plan' } }
811
+ }
812
+ }
781
813
  if (isPrerelease(toVersion) && body.allowPrerelease !== true) {
782
814
  return {
783
815
  status: 409,
@@ -787,7 +819,7 @@ export async function runUpdate(ctx, body) {
787
819
  },
788
820
  }
789
821
  }
790
- if (toVersion === row.installedVersion) {
822
+ if (toVersion === row.installedVersion && !migration) {
791
823
  return { status: 409, body: { error: 'already-at-version' } }
792
824
  }
793
825
 
@@ -824,7 +856,9 @@ export async function runUpdate(ctx, body) {
824
856
  // installation; a failure between them is the host's `restore` path, not ours.
825
857
  let result
826
858
  try {
827
- result = await pluginManager.updateBundle(row.targetId, toVersion, {})
859
+ result = migration
860
+ ? await applyMigration(pluginManager, row, toVersion, profile, migrationPreview.sourceMigration.archiveDigest)
861
+ : await pluginManager.updateBundle(row.targetId, toVersion, {})
828
862
  } catch (error) {
829
863
  await transition(profile.home, profile.id, record, 'failed', { error: messageOf(error) })
830
864
  return {
@@ -835,14 +869,17 @@ export async function runUpdate(ctx, body) {
835
869
 
836
870
  await transition(profile.home, profile.id, record, 'verifying')
837
871
  const outcome = classifyUpdateResult(result)
872
+ const after = await buildOverview(ctx.root ?? ctx)
873
+ const afterRow = after.plugins.find((entry) => entry.targetId === body.targetId)
874
+ if (outcome.ok && (afterRow?.installedVersion !== toVersion || (migration && afterRow.source.kind !== 'registry'))) {
875
+ outcome.ok = false
876
+ outcome.message = 'The installed version or source does not match the requested result.'
877
+ }
838
878
  const finalState = outcome.ok ? 'succeeded' : 'recovery_required'
839
879
  await transition(profile.home, profile.id, record, finalState, {
840
880
  error: outcome.message,
841
881
  })
842
882
 
843
- const after = await buildOverview(ctx)
844
- const afterRow = after.plugins.find((entry) => entry.targetId === body.targetId)
845
-
846
883
  return {
847
884
  status: outcome.ok ? 200 : 502,
848
885
  body: {
@@ -1209,7 +1246,35 @@ export function registerRoutes(ctx, scope) {
1209
1246
  const { webServer } = scope
1210
1247
  const disposers = []
1211
1248
  const publish = (path, handler) => {
1212
- const dispose = webServer.register({ kind: 'exact', path: `${ROUTE_BASE}${path}`, handler })
1249
+ const dispose = webServer.register({
1250
+ kind: 'exact',
1251
+ path: `${ROUTE_BASE}${path}`,
1252
+ handler: async (request, response) => {
1253
+ // webServer.register is a physical route registry, so it does not apply
1254
+ // Connection's trust fence for us. Only undefined is a verified pass
1255
+ // under the synchronous requestRejection contract (401 | 403 | undefined).
1256
+ let rejection = 401
1257
+ try {
1258
+ const connection = ctx?.get?.('connection')
1259
+ if (typeof connection?.requestRejection === 'function') {
1260
+ const verdict = connection.requestRejection(request)
1261
+ if (verdict === undefined || verdict === 401 || verdict === 403) rejection = verdict
1262
+ else if (typeof verdict?.then === 'function') {
1263
+ // An asynchronous verdict cannot authorize this synchronous fence.
1264
+ // Consume its rejection without letting it crash the host later.
1265
+ Promise.resolve(verdict).catch(() => {})
1266
+ }
1267
+ }
1268
+ } catch {
1269
+ // The host could not establish trust; no route work may start.
1270
+ }
1271
+ if (rejection !== undefined) {
1272
+ sendJson(response, rejection, { error: rejection === 403 ? 'forbidden' : 'unauthorized' })
1273
+ return
1274
+ }
1275
+ return handler(request, response)
1276
+ },
1277
+ })
1213
1278
  disposers.push(dispose)
1214
1279
  }
1215
1280
 
@@ -1284,7 +1349,7 @@ export function registerRoutes(ctx, scope) {
1284
1349
  return
1285
1350
  }
1286
1351
  try {
1287
- sendJson(response, 200, await readVersions(ctx, name))
1352
+ sendJson(response, 200, await readVersions(ctx, name, { migrateToRegistry: url.searchParams.get('migrateToRegistry') === 'true' }))
1288
1353
  } catch (error) {
1289
1354
  sendJson(response, 500, { error: 'versions-failed', message: messageOf(error) })
1290
1355
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-version-manager",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Version management for DSH plugins and skills: an honest inventory of what is installed, a preview of what an update would change, a verifiable snapshot taken before the change, and a recovery path that is only offered when it can actually work.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -24,7 +24,10 @@
24
24
  "docs/assets",
25
25
  "docs/git-write-safety.md",
26
26
  "docs/guide.en.md",
27
- "docs/release-notes-0.1.6.md"
27
+ "docs/release-notes-0.1.6.md",
28
+ "docs/release-notes-0.1.7.md",
29
+ "CHANGELOG.md",
30
+ "docs/release-notes-0.1.8.md"
28
31
  ],
29
32
  "keywords": [
30
33
  "deepseek",