dsh-plugin 1.6.12 → 2.0.0

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.
Files changed (128) hide show
  1. package/README.en.md +1 -1
  2. package/README.md +1 -1
  3. package/client/client.js +615 -741
  4. package/client/client.js.map +1 -1
  5. package/lib/http/catalog.js +2 -3
  6. package/lib/http/diagnostics.js +6 -7
  7. package/lib/http/install.js +47 -213
  8. package/lib/http/logs.js +1 -2
  9. package/lib/http/npm-release-age.js +42 -0
  10. package/lib/http/routes.js +8 -7
  11. package/lib/http/settings.js +2 -2
  12. package/lib/http/shared.js +2 -2
  13. package/lib/http/task.js +1 -2
  14. package/lib/index.js +5 -6
  15. package/lib/services/install/install-types.js +4 -4
  16. package/lib/services/install/install.js +1 -1
  17. package/lib/services/install/npm-check.js +3 -2
  18. package/lib/services/install/npm-resolve.js +9 -96
  19. package/lib/services/install/package-entry.js +6 -11
  20. package/lib/services/install/registry-check.js +2 -2
  21. package/lib/services/install/release-target.js +8 -9
  22. package/lib/services/install/task-queue.js +40 -48
  23. package/lib/services/npm-release-age.js +119 -0
  24. package/lib/services/probe.js +4 -4
  25. package/lib/services/profile/installed-versions.js +15 -21
  26. package/lib/services/profile/profile.js +16 -44
  27. package/lib/services/profile/progress.js +8 -11
  28. package/lib/services/settings.js +2 -5
  29. package/lib/types/http/catalog.d.ts +1 -1
  30. package/lib/types/http/install.d.ts +2 -2
  31. package/lib/types/http/npm-release-age.d.ts +2 -0
  32. package/lib/types/http/routes.d.ts +10 -12
  33. package/lib/types/http/shared.d.ts +5 -6
  34. package/lib/types/index.d.ts +7 -8
  35. package/lib/types/services/install/install-types.d.ts +12 -13
  36. package/lib/types/services/install/install.d.ts +1 -1
  37. package/lib/types/services/install/npm-resolve.d.ts +4 -16
  38. package/lib/types/services/install/package-entry.d.ts +6 -11
  39. package/lib/types/services/install/release-target.d.ts +7 -8
  40. package/lib/types/services/install/task-queue.d.ts +25 -30
  41. package/lib/types/services/npm-release-age.d.ts +15 -0
  42. package/lib/types/services/probe.d.ts +4 -4
  43. package/lib/types/services/profile/installed-versions.d.ts +5 -7
  44. package/lib/types/services/profile/profile.d.ts +14 -18
  45. package/lib/types/services/profile/progress.d.ts +7 -10
  46. package/lib/types/services/settings.d.ts +0 -4
  47. package/package.json +1 -1
  48. package/src/client/components/PluginHubSection.tsx +17 -22
  49. package/src/client/components/catalog/CatalogList.tsx +2 -4
  50. package/src/client/components/catalog/PluginCard.tsx +2 -3
  51. package/src/client/components/layout/CatalogControls.tsx +5 -6
  52. package/src/client/components/layout/CatalogHeader.tsx +1 -2
  53. package/src/client/components/layout/CategoryTabs.tsx +2 -3
  54. package/src/client/components/layout/SectionTabs.tsx +3 -5
  55. package/src/client/components/modals/ConfirmDialog.tsx +4 -6
  56. package/src/client/components/modals/InstalledDetailModal.tsx +3 -6
  57. package/src/client/components/modals/LogsModal.tsx +7 -12
  58. package/src/client/components/modals/NotificationsModal.tsx +35 -16
  59. package/src/client/components/modals/ProgressView.tsx +3 -4
  60. package/src/client/components/modals/modals.tsx +35 -15
  61. package/src/client/components/ui/Dropdown.tsx +4 -6
  62. package/src/client/components/ui/Toggle.tsx +2 -3
  63. package/src/client/components/ui/icons.tsx +1 -2
  64. package/src/client/components/views/CustomInstallView.tsx +20 -178
  65. package/src/client/components/views/DiagnosticsView.tsx +3 -6
  66. package/src/client/components/views/InstalledView.tsx +6 -11
  67. package/src/client/components/views/MarketView.tsx +2 -4
  68. package/src/client/components/views/SettingsView.tsx +9 -32
  69. package/src/client/css-modules.d.ts +1 -1
  70. package/src/client/data/catalog.ts +2 -3
  71. package/src/client/data/host.ts +26 -3
  72. package/src/client/data/hub.ts +2 -3
  73. package/src/client/hooks/useCatalog.ts +79 -24
  74. package/src/client/hooks/useIncrementalList.ts +3 -5
  75. package/src/client/hooks/useLanguage.ts +4 -6
  76. package/src/client/hooks/useSettings.ts +4 -11
  77. package/src/client/hooks/useTaskQueue.ts +36 -42
  78. package/src/client/index.tsx +2 -3
  79. package/src/client/locales.ts +75 -114
  80. package/src/client/logic/constants.ts +1 -2
  81. package/src/client/logic/ensure-plugin-css.ts +8 -12
  82. package/src/client/logic/failures.ts +16 -18
  83. package/src/client/logic/format.ts +1 -1
  84. package/src/client/logic/install-command.ts +14 -35
  85. package/src/client/logic/installed.ts +15 -10
  86. package/src/client/logic/normalize.ts +3 -3
  87. package/src/client/logic/release-age.ts +19 -0
  88. package/src/client/logic/urls.ts +20 -20
  89. package/src/client/styles/CustomInstallView.module.css +3 -30
  90. package/src/client/styles/DiagnosticsView.module.css +3 -5
  91. package/src/client/styles/Dropdown.module.css +2 -4
  92. package/src/client/styles/Header.module.css +6 -7
  93. package/src/client/styles/InstalledView.module.css +4 -7
  94. package/src/client/styles/List.module.css +4 -5
  95. package/src/client/styles/LogsView.module.css +2 -3
  96. package/src/client/styles/Modal.module.css +4 -5
  97. package/src/client/styles/SectionTabs.module.css +2 -4
  98. package/src/client/styles/SettingsView.module.css +3 -5
  99. package/src/client/styles/Toggle.module.css +2 -4
  100. package/src/client/styles/tokens.module.css +14 -18
  101. package/src/client/types.ts +11 -11
  102. package/src/server/http/catalog.ts +2 -3
  103. package/src/server/http/diagnostics.ts +6 -7
  104. package/src/server/http/install.ts +47 -208
  105. package/src/server/http/logs.ts +1 -2
  106. package/src/server/http/npm-release-age.ts +42 -0
  107. package/src/server/http/routes.ts +12 -12
  108. package/src/server/http/settings.ts +2 -2
  109. package/src/server/http/shared.ts +5 -6
  110. package/src/server/http/task.ts +1 -2
  111. package/src/server/index.ts +7 -8
  112. package/src/server/services/install/install-types.ts +12 -13
  113. package/src/server/services/install/install.ts +0 -1
  114. package/src/server/services/install/npm-check.ts +3 -2
  115. package/src/server/services/install/npm-resolve.ts +9 -99
  116. package/src/server/services/install/package-entry.ts +6 -11
  117. package/src/server/services/install/registry-check.ts +2 -2
  118. package/src/server/services/install/release-target.ts +8 -9
  119. package/src/server/services/install/task-queue.ts +47 -54
  120. package/src/server/services/npm-release-age.ts +107 -0
  121. package/src/server/services/probe.ts +4 -4
  122. package/src/server/services/profile/installed-versions.ts +16 -22
  123. package/src/server/services/profile/profile.ts +16 -42
  124. package/src/server/services/profile/progress.ts +8 -11
  125. package/src/server/services/settings.ts +2 -9
  126. package/lib/services/install/preflight.js +0 -178
  127. package/lib/types/services/install/preflight.d.ts +0 -23
  128. package/src/server/services/install/preflight.ts +0 -184
@@ -2,11 +2,9 @@
2
2
  * Website: https://dsh-plugin.org
3
3
  * GitHub: https://github.com/dshplugin/dsh-plugin-hub
4
4
  *
5
- * Settings view: desktop-settings navigation — a fixed left sidebar lists
6
- * the sections (icon + label, click to switch), the right pane shows one
7
- * card per active section (rows: label left, control right, hairline
8
- * separators). High density, no whitespace waste: rows are 12px padding,
9
- * 28px controls, 11px descriptions. */
5
+ * 设置视图:桌面设置式导航 —— 固定左侧栏列出各分组(图标 + 名称,点击切换),
6
+ * 右侧面板每个分组一张卡片(行:标签左、控件右,细线分隔)。高密度、不浪费留白:
7
+ * 行内边距 12px、控件 28px、说明 11px。 */
10
8
 
11
9
  /* 整体:占满剩余高度,左导航右内容两栏 */
12
10
  .root {
@@ -2,10 +2,8 @@
2
2
  * Website: https://dsh-plugin.org
3
3
  * GitHub: https://github.com/dshplugin/dsh-plugin-hub
4
4
  *
5
- * Toggle switch for settings rows: a small 34×18 track with a sliding
6
- * knob. Off = neutral hairline track; on = brand fill. Sized for the
7
- * compact settings row height (18px vs the 28px input rows), so labels
8
- * stay vertically centered without extra whitespace. */
5
+ * 设置行用的开关:小号 34×18 轨道 + 滑动圆钮。关 = 中性细线轨道;开 = 品牌填充。
6
+ * 尺寸贴合紧凑的设置行高(18px,输入行是 28px),让标签垂直居中且无多余留白。 */
9
7
 
10
8
  .toggle,
11
9
  .toggleOn {
@@ -2,26 +2,22 @@
2
2
  * Website: https://dsh-plugin.org
3
3
  * GitHub: https://github.com/dshplugin/dsh-plugin-hub
4
4
  *
5
- * Plugin Hub design tokens.
5
+ * 插件中心设计变量。
6
6
  *
7
- * Semantic aliases over the host's --dsw-alias-* theme tokens, each with the
8
- * original light-mode literal as fallback for hosts that do not define the
9
- * underlying token. Declared on :root and on the dark body so every theme
10
- * re-resolves the aliases against its own token set; the custom property is
11
- * then inherited by all section elements.
7
+ * 对宿主 --dsw-alias-* 主题变量的语义别名,各带原始浅色字面量,供未定义底层变量的宿主兜底。
8
+ * 声明在 :root 与暗色 body 上,让每种主题都按自己的变量集重新解析别名,再由所有板块元素继承。
12
9
  *
13
- * Keep raw colors out of the per-area stylesheets: reference --hub-* here so
14
- * new styles pick up the theme automatically. */
10
+ * 各区域样式表不要写颜色字面量:在此引用 --hub-*,新样式即可自动跟随主题。 */
15
11
  :root,
16
12
  body[data-ds-dark-theme] {
17
- /* text */
13
+ /* 文本 */
18
14
  --hub-text-primary: var(--dsw-alias-label-primary, #1f2328);
19
15
  --hub-text-secondary: var(--dsw-alias-label-secondary, #6b7280);
20
16
  --hub-text-tertiary: var(--dsw-alias-label-tertiary, #8b93a1);
21
17
  --hub-text-disabled: var(--dsw-alias-label-disabled, #aab1bd);
22
18
  --hub-text-on-fill: var(--dsw-alias-label-primary-foreground, #ffffff);
23
19
 
24
- /* surfaces */
20
+ /* 表面/背景 */
25
21
  --hub-bg-1: var(--dsw-alias-bg-layer-1, #ffffff);
26
22
  --hub-bg-2: var(--dsw-alias-bg-layer-2, rgba(128, 128, 128, 0.08));
27
23
  --hub-bg-3: rgba(128, 128, 128, 0.1);
@@ -30,13 +26,13 @@ body[data-ds-dark-theme] {
30
26
  --hub-bg-hover: var(--dsw-alias-interactive-bg-hover, rgba(128, 128, 128, 0.16));
31
27
  --hub-bg-on-fill: rgba(128, 128, 128, 0.22);
32
28
 
33
- /* borders */
29
+ /* 边框 */
34
30
  --hub-border-1: var(--dsw-alias-border-l1, #eceef1);
35
31
  --hub-border-2: var(--dsw-alias-border-l2, #e5e7eb);
36
32
  --hub-border-ghost: var(--dsw-alias-button-ghost-active-border, rgba(79, 110, 247, 0.25));
37
33
  --hub-border-input: var(--dsw-alias-input-border, rgba(107, 114, 128, 0.25));
38
34
 
39
- /* brand (fixed in both themes) */
35
+ /* 品牌色(两种主题固定) */
40
36
  --hub-brand: var(--dsw-alias-state-business-primary, #4f6ef7);
41
37
  --hub-brand-hover: #3b5bdb;
42
38
  --hub-brand-tint: rgba(79, 110, 247, 0.06);
@@ -44,7 +40,7 @@ body[data-ds-dark-theme] {
44
40
  --hub-brand-border: rgba(79, 110, 247, 0.35);
45
41
  --hub-brand-border-soft: rgba(79, 110, 247, 0.22);
46
42
 
47
- /* purple brand accents (fixed in both themes) */
43
+ /* 紫色品牌点缀(两种主题固定) */
48
44
  --hub-purple-1: #4f46e5;
49
45
  --hub-purple-2: #7c3aed;
50
46
  --hub-purple-border: rgba(139, 92, 246, 0.55);
@@ -52,28 +48,28 @@ body[data-ds-dark-theme] {
52
48
  --hub-purple-shadow: rgba(79, 70, 229, 0.28);
53
49
  --hub-purple-shadow-strong: rgba(124, 58, 237, 0.42);
54
50
 
55
- /* primary action button */
51
+ /* 主操作按钮 */
56
52
  --hub-btn-fill: var(--dsw-alias-button-primary-fill, #1f2328);
57
53
  --hub-btn-hover: var(--dsw-alias-button-primary-hover, #43454a);
58
54
 
59
- /* success */
55
+ /* 成功 */
60
56
  --hub-success: #16a34a;
61
57
  --hub-success-tint: rgba(22, 163, 74, 0.12);
62
58
  --hub-success-border: rgba(22, 163, 74, 0.3);
63
59
 
64
- /* warning (amber) */
60
+ /* 警告(琥珀) */
65
61
  --hub-warn: var(--dsw-alias-state-warn-primary, #b8860b);
66
62
  --hub-warn-tint: rgba(184, 134, 11, 0.08);
67
63
  --hub-warn-border: rgba(184, 134, 11, 0.35);
68
64
  --hub-warn-strong: rgba(184, 134, 11, 0.85);
69
65
 
70
- /* warning (deep amber) */
66
+ /* 警告(深琥珀) */
71
67
  --hub-warning: var(--dsw-alias-state-warning-primary, #b45309);
72
68
  --hub-warning-hover: #92400e;
73
69
  --hub-warning-tint: rgba(180, 83, 9, 0.08);
74
70
  --hub-warning-border: rgba(180, 83, 9, 0.3);
75
71
 
76
- /* danger */
72
+ /* 危险 */
77
73
  --hub-danger: var(--dsw-alias-state-danger-primary, #d1242f);
78
74
  --hub-danger-hover: var(--dsw-alias-state-danger-hover, #b91c1c);
79
75
  --hub-danger-strong: #b0202a;
@@ -3,20 +3,20 @@
3
3
  * Website: https://dsh-plugin.org
4
4
  * GitHub: https://github.com/dshplugin/dsh-plugin-hub
5
5
  *
6
- * Shared types for the dsh-plugin browser client. Kept dependency-free so
7
- * any client module can import them without pulling in components or styles.
6
+ * dsh-plugin 浏览器客户端的共享类型。保持零依赖,任何客户端模块都能直接引入,
7
+ * 而不会连带拉入组件或样式。
8
8
  */
9
9
 
10
10
  export type LocaleId = 'zh' | 'en'
11
11
 
12
- /** 自定义安装入口渠道:三张卡片(NPM 包 / GitHub 源码 / DSH 命令)。
13
- * 客户端提交时显式上报,服务端落日志/报错提示据此溯源「从哪个入口发起」。 */
14
- export type InstallChannel = 'npm' | 'git' | 'dsh'
12
+ /** 自定义安装入口渠道:仅 NPM 包。
13
+ * 客户端提交时显式上报,服务端落日志/报错提示据此溯源「从哪个入口发起」。 */
14
+ export type InstallChannel = 'npm'
15
15
 
16
- /** Translation function signature shared by the host binder and the in-component dictionary. */
16
+ /** 宿主绑定与组件内字典共用的翻译函数签名。 */
17
17
  export type Translate = (key: string, params?: Record<string, string | number>) => string
18
18
 
19
- /** The subset of the locale service this plugin touches. */
19
+ /** 本插件用到的 locale 服务子集。 */
20
20
  export interface LocaleService {
21
21
  register(namespace: string, dicts: { zh: Record<string, string>; en: Record<string, string> }): unknown
22
22
  bind(namespace: string): (key: string, params?: Record<string, string | number>) => string
@@ -27,13 +27,13 @@ export interface LocaleService {
27
27
  setLocale(id: string): void
28
28
  }
29
29
 
30
- /** The subset of the slots service this plugin touches. */
30
+ /** 本插件用到的 slots 服务子集。 */
31
31
  export interface SlotsService {
32
32
  inject(slot: string, register: () => unknown): void
33
33
  register(meta: Record<string, unknown>, component: () => unknown): unknown
34
34
  }
35
35
 
36
- /** The client cordis context shape this plugin relies on (structural). */
36
+ /** 本插件依赖的客户端 cordis 上下文形态(结构化)。 */
37
37
  export interface HubClientContext {
38
38
  effect(callback: () => unknown, label?: string): void
39
39
  slots: SlotsService
@@ -45,7 +45,7 @@ export interface SectionProps {
45
45
  locale: LocaleService
46
46
  }
47
47
 
48
- /** Slim projection of the site's DirectoryPlugin entries. */
48
+ /** 官网 DirectoryPlugin 条目的精简投影。 */
49
49
  export interface HubPlugin {
50
50
  /** 作者小写 key,与 slug 共同构成唯一身份(两级路径 /plugins/{ownerSlug}/{slug});可能缺省 */
51
51
  ownerSlug?: string
@@ -60,7 +60,7 @@ export interface HubPlugin {
60
60
  source?: { repo?: string; npmPackage?: string }
61
61
  /** 安装信息:能否网页一键安装(false = 仅支持命令行/专属 profile,缺省视为 true);
62
62
  * manualInstall = 人工干预标记(网页端一键安装替代不了终端的构建/装配,必须用户自己去终端装);
63
- * command/githubCommand = 目录下发的权威安装命令(npm/git 通道各一条),
63
+ * command/githubCommand = 目录下发的权威安装命令,
64
64
  * 仅供展示/复制 —— CLI-only 插件(如 dsh-tui)需专属 profile(--profile dsh-tui),
65
65
  * 无法从 repo/npm 包名推断,必须用目录命令。 */
66
66
  install?: { webInstallable?: boolean; manualInstall?: boolean; command?: string; githubCommand?: string }
@@ -3,8 +3,7 @@
3
3
  * Website: https://dsh-plugin.org
4
4
  * GitHub: https://github.com/dshplugin/dsh-plugin-hub
5
5
  *
6
- * Catalog proxy routes: server-side caching of the directory/stats payloads
7
- * and profile-level installed-package reads shared with the install/task modules.
6
+ * 目录代理路由:目录/统计载荷的服务端缓存,以及与安装/任务模块共享的 profile 级已装包读取。
8
7
  */
9
8
  import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
10
9
  import { homedir } from 'node:os'
@@ -53,7 +52,7 @@ export function profileDirectory(profile: string): string {
53
52
  return join(process.env.DSH_HOME ?? join(homedir(), '.dsh'), 'profiles', profile)
54
53
  }
55
54
 
56
- /** Read non-official dependencies installed into one profile. */
55
+ /** 读取安装进某 profile 的非官方依赖。 */
57
56
  export function readInstalled(profile: string): Record<string, string> {
58
57
  try {
59
58
  const manifest = JSON.parse(readFileSync(join(profileDirectory(profile), 'package.json'), 'utf8')) as {
@@ -3,8 +3,7 @@
3
3
  * Website: https://dsh-plugin.org
4
4
  * GitHub: https://github.com/dshplugin/dsh-plugin-hub
5
5
  *
6
- * Diagnostics routes: streaming connectivity self-check, proxy verification,
7
- * and the host environment snapshot shared with the task module's /env route.
6
+ * 诊断路由:流式连通性自检、代理校验,以及与任务模块 /env 路由共享的宿主环境快照。
8
7
  */
9
8
  import { readFileSync } from 'node:fs'
10
9
  import { homedir, release } from 'node:os'
@@ -31,7 +30,7 @@ function hostDshVersion(): string | null {
31
30
  return manifest.version
32
31
  }
33
32
  } catch {
34
- /* not a package root — keep walking up */
33
+ /* 不是包根,继续向上查找 */
35
34
  }
36
35
  const parent = dirname(dir)
37
36
  if (parent === dir) break
@@ -95,8 +94,8 @@ export function registerDiagnosticsRoutes(webServer: WebServerService, profile:
95
94
  path: '/dsh-plugin-hub/diagnostics',
96
95
  handler: async (request, response) => {
97
96
  if (!requireTrustedPost(request, response)) return
98
- // 连通性自检:npm registry(镜像/官方)/ GitHub API / 目录站点,逐路探测并测速。
99
- // 与安装通道一一对应 —— npm 反查与 npm 安装走 registry、git 源走 github、目录数据走 dsh-plugin.org。
97
+ // 连通性自检:npm registry(镜像/官方)/ GitHub / 目录站点,逐路探测并测速。
98
+ // npm 安装走 registry、目录数据走 dsh-plugin.org、GitHub 那一行用于反映插件运行时对 github.com 的可达性。
100
99
  // 流式(NDJSON)逐条上报:每个探测先发命令行,完成后发结果行,客户端以黑窗口终端实时展示。
101
100
  // 可选 body { key }:只重测指定通道(页面列表「重测」单项时用),缺省全量串行探测。
102
101
  let onlyKey = ''
@@ -112,8 +111,8 @@ export function registerDiagnosticsRoutes(webServer: WebServerService, profile:
112
111
  // npm 通道:设置里配置了镜像源就探测该镜像(安装通道吃同一个 registry);
113
112
  // 未配置(空串)时探测官方源作为「跟随本机 npm 配置」的基础连通性参考。
114
113
  const registry = settings.npmRegistry.replace(/\/+$/, '') || 'https://registry.npmjs.org'
115
- // 连通性自检直接打安装通道真实访问的轻量资源:npm 源拉包元数据、git 通道探
116
- // 仓库主页、目录站探 badge 小文件,避免拉取目录全量 JSON。
114
+ // 连通性自检打各通道的轻量资源:npm 源拉包元数据、GitHub 行探小仓库、目录站探
115
+ // 小文件,避免拉取目录全量 JSON。
117
116
  // npm 行 display:配置了镜像就显示镜像地址;未配置置空 —— 客户端显示「未配置(跟随本机 npm 配置)」。
118
117
  const allChecks: Array<{ key: string; url: string; display: string; cmd: string; proxy?: string; git?: boolean }> = [
119
118
  { key: 'npm', url: `${registry}/dsh-plugin`, display: settings.npmRegistry !== '' ? registry : '', cmd: `npm view dsh-plugin version --registry ${registry}` },
@@ -3,23 +3,19 @@
3
3
  * Website: https://dsh-plugin.org
4
4
  * GitHub: https://github.com/dshplugin/dsh-plugin-hub
5
5
  *
6
- * Install/uninstall routes: validate the target and spawn the official dsh CLI
7
- * (see services/install/install.ts), reporting the captured result back.
6
+ * 安装/卸载路由:校验目标后 spawn 官方 dsh CLI(见 services/install/install.ts),
7
+ * 并回传捕获的结果。自定义安装只接受 npm 包名。
8
8
  */
9
- import { githubRefOf, githubRepoOf, githubTarget, globalNpmPackagesOf, hasQueuedTarget, installTargetOf, startPluginMutation, validPackageName, type LoaderHandle } from '../services/install/install.ts'
10
- import { githubReleaseTarget } from '../services/install/release-target.ts'
9
+ import { githubRepoOf, globalNpmPackagesOf, hasQueuedTarget, installTargetOf, startPluginMutation, validPackageName, type LoaderHandle } from '../services/install/install.ts'
11
10
  import { recordResolvedNpmPackage } from '../services/profile/installed-versions.ts'
12
- import { isDshNpmPackageForRepo, resolveNpmPackage } from '../services/install/npm-resolve.ts'
13
- import { preflightTarget } from '../services/install/preflight.ts'
14
- import { gitLsRemote, probeUrl, systemProxy } from '../services/probe.ts'
11
+ import { isDshNpmPackageForRepo } from '../services/install/npm-resolve.ts'
12
+ import { probeUrl, systemProxy } from '../services/probe.ts'
15
13
  import { loadSettings, type HubSettings } from '../services/settings.ts'
16
- import { installedRepoOf, readInstalled } from './catalog.ts'
14
+ import { readInstalled } from './catalog.ts'
17
15
  import { COMMAND_TIMEOUT_MS, readJsonBody, requireTrustedPost, sendJson, type WebRoute, type WebServerService } from './shared.ts'
18
16
 
19
- /** 安装/卸载 CLI 的子进程环境:透传宿主环境,并按设置注入 HTTP(S) 代理。
20
- * 不注入 npm registry —— 安装完全沿用用户本机 npm 配置(~/.npmrc / 全局配置)。
21
- * 代理优先级:设置里的代理 → 系统代理(macOS scutil / Windows 注册表)→ 宿主 env 原有值。
22
- * 使安装通道与诊断使用相同的代理来源。 */
17
+ /** 安装/卸载 CLI 的子进程环境:透传宿主环境并注入 HTTP(S) 代理,
18
+ * 代理来源与诊断一致(设置代理 → 系统代理 → 宿主 env);不注入 npm registry,沿用用户本机 npm 配置。 */
23
19
  function mutationEnv(settings: HubSettings): NodeJS.ProcessEnv {
24
20
  const env: NodeJS.ProcessEnv = { ...process.env, CI: 'true' }
25
21
  const proxy = settings.proxy !== '' ? settings.proxy : (systemProxy() ?? '')
@@ -32,17 +28,6 @@ function mutationEnv(settings: HubSettings): NodeJS.ProcessEnv {
32
28
  return env
33
29
  }
34
30
 
35
- /** Match a GitHub install target against the installed table; returns the package name when already installed. */
36
- function installedByRepo(installed: Record<string, string>, target: string): string | null {
37
- const repo = githubRepoOf(target)
38
- if (repo === null) return null
39
- const needle = repo.toLowerCase()
40
- for (const [name, spec] of Object.entries(installed)) {
41
- if (githubRepoOf(spec)?.toLowerCase() === needle) return name
42
- }
43
- return null
44
- }
45
-
46
31
  export function registerInstallRoutes(webServer: WebServerService, profile: string, loader: LoaderHandle | undefined): WebRoute[] {
47
32
  return [
48
33
  {
@@ -54,43 +39,37 @@ export function registerInstallRoutes(webServer: WebServerService, profile: stri
54
39
  try {
55
40
  const body = await readJsonBody(request)
56
41
  // mode: 'update' = 已安装目标的覆盖更新(放行 add,pnpm 对已存在依赖原位覆盖重装)。
57
- // 后续「同仓库残留」检测可能把 install 就地升级为 update(见包名冲突检测),故用 let。
58
42
  let mode = body !== null && typeof body === 'object' && (body as { mode?: unknown }).mode === 'update'
59
43
  ? 'update'
60
44
  : 'install'
61
- // installTargetOf 先把完整 DSH 命令(`dsh plugin [--profile <p>] add <target>`)剥成裸目标,
62
- // 兼容用户直接粘贴命令行(防输错),真正语法判定交给下面 githubRepoOf / validPackageName。
45
+ // installTargetOf 把完整 DSH 命令剥成裸目标;自定义目标只接受 npm 包名,语法判定交给 validPackageName。
63
46
  const rawRepo = typeof body === 'object' && body !== null && typeof (body as { repo?: unknown }).repo === 'string'
64
47
  ? installTargetOf((body as { repo: string }).repo)
65
48
  : ''
66
- // 前端决策的展示用仓库名(owner/repo):npm 安装时 body.repo 是包名,display 用于
67
- // 待重启行 / 任务恢复时展示仓库名,保证用户无感知(安装通道变化不改变所见目标)
49
+ // 展示用仓库名(owner/repo):npm 安装时 body.repo 是包名,display 供待重启行 / 任务恢复展示仓库名。
68
50
  const displayRepo = typeof body === 'object' && body !== null && typeof (body as { display?: unknown }).display === 'string'
69
51
  ? (body as { display: string }).display.trim()
70
52
  : rawRepo
71
- // 请求来源:目录插件安装(catalog)走目录白名单;命令行安装(custom)按通道受安全开关控制
53
+ // 请求来源:目录插件安装(catalog)走目录白名单;命令行安装(custom)受安全开关控制
72
54
  const source = typeof body === 'object' && body !== null && typeof (body as { source?: unknown }).source === 'string'
73
55
  ? (body as { source: string }).source
74
56
  : ''
75
- // 自定义安装入口渠道(客户端三张卡片:NPM 包 / GitHub 源码 / DSH 命令):
76
- // 客户端显式上报,服务端日志/报错据此精准溯源「从哪个入口发起」;目录插件安装不传。
57
+ // 自定义安装入口渠道(仅 NPM 包):日志/报错据此溯源发起入口。
77
58
  const installChannel = (() => {
78
59
  const raw = body !== null && typeof body === 'object' ? (body as { installChannel?: unknown }).installChannel : undefined
79
- return raw === 'git' || raw === 'dsh' || raw === 'npm' ? raw : undefined
60
+ return raw === 'npm' ? 'npm' : undefined
80
61
  })()
81
62
  const settings = loadSettings(profile)
82
63
  // 界面语言(客户端随请求携带):错误消息按用户当前语言提示(中文界面给中文,英文界面给英文)
83
64
  const lang = typeof body === 'object' && body !== null && (body as { lang?: unknown }).lang === 'en'
84
65
  ? 'en'
85
66
  : 'zh'
86
- // 全局 npm 安装(官方 README 的 `npm install -g <pkgs>`,如 dsh-tui 的安装命令):
87
- // 直接从命令框输入格式执行全局安装,不进任何 profile、无需宿主重启。
88
- // 包列表优先取 body.globalNpm(客户端命令框解析后显式携带);兜底再从 rawRepo 解析,
89
- // 保证直接调 API 传完整命令也能识别。
67
+ // 全局 npm 安装(`npm install -g <pkgs>`):不进任何 profile、无需宿主重启。
68
+ // 包列表优先取 body.globalNpm,兜底从 rawRepo 解析,保证直接调 API 传完整命令也能识别。
90
69
  const bodyGlobalNpm = Array.isArray((body as { globalNpm?: unknown }).globalNpm)
91
70
  ? (body as { globalNpm: unknown[] }).globalNpm.filter((x): x is string => typeof x === 'string' && x !== '')
92
71
  : []
93
- let globalNpm: string[] = bodyGlobalNpm.length > 0 ? bodyGlobalNpm : (globalNpmPackagesOf(rawRepo) ?? [])
72
+ const globalNpm: string[] = bodyGlobalNpm.length > 0 ? bodyGlobalNpm : (globalNpmPackagesOf(rawRepo) ?? [])
94
73
  if (globalNpm.length > 0) {
95
74
  // 包名逐个按 npm 包名语法校验 + 拒绝以 - 开头的 token(npm 会把 --xxx 当参数而非包名),数量封顶防滥用
96
75
  if (globalNpm.length > 20 || globalNpm.some((p) => !validPackageName(p) || p.startsWith('-'))) {
@@ -122,216 +101,76 @@ export function registerInstallRoutes(webServer: WebServerService, profile: stri
122
101
  sendJson(response, 200, { ok: true, task: task.id })
123
102
  return
124
103
  }
125
- // 目标语法三态:固定 GitHub release .tgz(保留其包根目录,不转成仓库 HEAD);
126
- // GitHub 地址(owner/repo、github:、https/ssh 链接等任意写法)→ 显式 HTTPS Git 源
127
- // (走装前预检);npm 包名(@scope/name 或 name)→ 信任 registry 直接安装。
128
- // githubRepoOf 先把各种 GitHub 地址归一成 owner/repo,让「输入地址即装」兼容粘贴完整链接。
129
- const gitRepo = githubRepoOf(rawRepo)
130
- const release = githubReleaseTarget(rawRepo)
131
- // 显式 pin 的 Git ref(`#tag` / `#commit`)是用户意图:保留它,且不让 npm 反查
132
- // 把这个精确修订换成 registry 上的默认版本。
133
- const pinnedRef = githubRefOf(rawRepo)
134
- const repoTarget = gitRepo !== null && release === null ? githubTarget(gitRepo, pinnedRef) : null
135
- let target: string | null = release?.target ?? repoTarget ?? (validPackageName(rawRepo) ? rawRepo : null)
136
- if (target === null) {
137
- sendJson(response, 400, { error: 'unsupported install target' })
104
+ // 自定义安装目标只接受 npm 包名(@scope/name 或 name)。
105
+ if (!validPackageName(rawRepo)) {
106
+ sendJson(response, 400, { error: 'unsupported install target: expected an npm package name' })
138
107
  return
139
108
  }
109
+ const target = rawRepo
110
+ // 已尝试的安装方式(供失败提 Issue 预填):保持为空
140
111
  const attempts: string[] = []
141
112
  // 代理口径与诊断/安装通道一致:设置里的代理 → 系统代理 → 环境变量 → 直连。
142
- // 供 npm 反查时跟随 GitHub 改名跳转用(Node https 读不到系统代理,交给 curl)。
143
113
  const effectiveProxy = settings.proxy !== ''
144
114
  ? settings.proxy
145
115
  : (systemProxy() ?? process.env.HTTPS_PROXY ?? process.env.https_proxy ?? '')
146
- // Catalog metadata may outlive a packaging split: one repository can publish both a
147
- // CLI/helper package and a dedicated DSH plugin package. Keep the catalog target when
148
- // registry metadata confirms it is a DSH package for this repo. Otherwise inspect the
149
- // repository root package.json and use its package name only when that exact registry
150
- // package also points back to the repo and identifies as a DSH plugin. This avoids
151
- // relying on npm search ranking, which is not a repository index and can omit the
152
- // correct package even with a large result window.
116
+ // 目录插件安装:目录数据可能滞后于打包拆分,确认目录下发的 npm 目标确为该仓库的 DSH 包,
117
+ // 命中则记录 repo → 包名映射,客户端据此把依赖 key 匹配回仓库、列表立即显示「已安装」。
153
118
  const catalogRepo = source === 'catalog' ? githubRepoOf(displayRepo) : null
154
- if (catalogRepo !== null && release === null && repoTarget === null && validPackageName(rawRepo)) {
119
+ if (catalogRepo !== null) {
155
120
  const catalogTargetIsDsh = await isDshNpmPackageForRepo(rawRepo, catalogRepo, settings.npmRegistry, effectiveProxy)
156
- if (catalogTargetIsDsh) {
157
- recordResolvedNpmPackage(profile, catalogRepo, rawRepo)
158
- } else {
159
- const catalogGitTarget = githubTarget(catalogRepo)
160
- if (catalogGitTarget !== null) {
161
- const root = await preflightTarget(catalogGitTarget)
162
- const rootName = root.ok && root.name !== null && validPackageName(root.name) ? root.name : null
163
- if (rootName !== null && rootName !== rawRepo
164
- && await isDshNpmPackageForRepo(rootName, catalogRepo, settings.npmRegistry, effectiveProxy)) {
165
- attempts.push(`catalog npm target: \`${target}\` → repository root DSH package \`${rootName}\``)
166
- target = rootName
167
- recordResolvedNpmPackage(profile, catalogRepo, rootName)
168
- }
169
- }
170
- }
171
- }
172
- // npm 优先:git 目标先反查该仓库的官方 npm 包,命中则改走 npm 通道。
173
- // git 分发常缺构建产物/子模块,npm 包是作者发布的完整产物;未命中或
174
- // 查询失败保留 github 直装(不阻塞安装,预检仍会拦截缺入口文件的情况)。
175
- // 通用机制,不针对具体插件。
176
- // 反查本身计入「已尝试的安装方式」:组织 scope 与 GitHub 用户名不一致时仅凭
177
- // 仓库名猜不到包名,失败提 Issue 时作者看到我们查过的命令就能直接指认正确包名。
178
- // 显式 pin 了 Git ref 时跳过 npm 反查:用户要的就是那个精确修订,
179
- // 不能用 registry 上的默认版本覆盖它。
180
- if (repoTarget !== null && pinnedRef === null) {
181
- // 反查/记录统一用归一化后的 owner/repo(gitRepo),保证「输入完整链接」也走同一套 npm 反查
182
- const repoIdentity = gitRepo ?? rawRepo
183
- const npmName = await resolveNpmPackage(repoIdentity, settings.npmRegistry, effectiveProxy)
184
- if (npmName !== null) {
185
- target = npmName
186
- attempts.push(`npm registry search: \`npm search repository:${repoIdentity}\` → found \`${npmName}\``)
187
- // 持久化 repo → npm 包名映射:目录数据未下发 npmPackage(组织 scope 与 GitHub
188
- // 用户名不一致)时,客户端仍能通过 /installed 的 versions 把依赖 key 匹配回仓库,
189
- // 列表立即显示「已安装」,避免安装成功后仍显示可安装
190
- recordResolvedNpmPackage(profile, repoIdentity, npmName)
191
- } else {
192
- attempts.push(`npm registry search: \`npm search repository:${repoIdentity}\` → no matching package found (falling back to git install)`)
193
- }
121
+ if (catalogTargetIsDsh) recordResolvedNpmPackage(profile, catalogRepo, rawRepo)
194
122
  }
195
- // 命令行安装(目录外)按通道门禁:GitHub 源码通道受「启用 GitHub 源码安装」控制,
196
- // npm 通道受「启用 NPM 安装」控制 —— 目录插件安装走目录白名单,不受开关影响。
197
- // 通道判定看反查后的最终 target:release 包与 git 目标同属 GitHub 通道,否则走 npm。
198
- if (source !== 'catalog') {
199
- const isGitChannel = release !== null || (repoTarget !== null && target === repoTarget)
200
- if (isGitChannel && !settings.enableGitInstall) {
201
- sendJson(response, 403, { error: 'git installs are disabled by the security settings' })
202
- return
203
- }
204
- if (!isGitChannel && !settings.enableNpmInstall) {
205
- sendJson(response, 403, { error: 'npm installs are disabled by the security settings' })
206
- return
207
- }
123
+ // 命令行安装(目录外)受「启用 NPM 安装」开关控制;目录插件安装走目录白名单,不受开关影响。
124
+ if (source !== 'catalog' && !settings.enableNpmInstall) {
125
+ sendJson(response, 403, { error: 'npm installs are disabled by the security settings' })
126
+ return
208
127
  }
209
- // 命中已安装目标时一律按「更新」语义执行(pnpm add 对已存在依赖本就是原位覆盖重装),
210
- // 不再抛 409:客户端的已装列表与服务端实读可能不同步(如页面列表滞后),此时用户点
211
- // 「安装」会撞上重复安装守卫,直接覆盖重装比让用户看到一句看不懂的 already installed
212
- // 报错友好,最终状态也一致(都是已安装)。命中判定双通道:npm 包名按 dependencies
213
- // 键直接命中,GitHub 目标按仓库身份匹配。
128
+ // 命中已安装目标时按「更新」执行(pnpm add 对已存在依赖即原位覆盖重装):
129
+ // 客户端已装列表可能与服务端不同步,覆盖重装比报错更友好且终态一致。
214
130
  const installed = readInstalled(profile)
215
- const already = installedByRepo(installed, target) ?? (installed[target] !== undefined ? target : null)
131
+ const already = installed[target] !== undefined ? target : null
216
132
  if (already !== null) mode = 'update'
217
133
  // 队列级去重:同一目标已在排队/执行中时拒绝,避免客户端防重竞态导致重复入队
218
134
  if (hasQueuedTarget(target)) {
219
135
  sendJson(response, 409, { error: `already queued: ${target}` })
220
136
  return
221
137
  }
222
- // 安装前网络连通性预检:npm 通道探 registry、git 通道探 github.com 连通性。
223
- // 探测目标固定为通道的稳定入口(registry 根 / github.com 主页),不探具体包或仓库
224
- // 页 —— 404 表示「目标不存在」而非网络不通,不该被当成网络故障拦截。
225
- // 仅新安装预检(更新是已信任目标的覆盖重装,跳过);不通直接 400 拦下并打
226
- // [network] 标记,客户端据此提示「你的网络不通」,而不是把网络失败当成
227
- // 插件侧问题引导去作者仓库提 Issue。
228
- // 代理口径与诊断一致:设置里的代理 → 系统代理 → 环境变量 → 直连。
138
+ // 安装前网络探测:探 registry 根而非具体包(404 是「包不存在」而非网络不通);仅新安装执行,更新跳过。
139
+ // 不通则 400 拦下并打 [network] 标记,客户端据此提示网络问题,而非插件问题。
229
140
  if (already === null) {
230
- const isGitChannel = release !== null || (repoTarget !== null && target === repoTarget)
231
- // release 包是 https://github.com/ 直链下载(非 git 克隆),探针按 HTTP 打 github.com 主页;
232
- // npm 通道探 registry 根。两者都是通道的稳定入口,不探具体包/仓库(404 会被误判成网络故障)。
233
- const httpProbeTarget = release !== null
234
- ? 'https://github.com/'
235
- : `${(settings.npmRegistry.replace(/\/+$/, '') || 'https://registry.npmjs.org')}/`
236
- // git 通道的探针换成克隆握手本身:git ls-remote 走的就是 pnpm 克隆前的同一套
237
- // https 传输。curl 打 github.com 主页会被按协议/端口区分的防火墙与 TLS 复检
238
- // 拦截(能 git 克隆、打不开网页),把可装的仓库误判成 [network] 而中止。
239
- // 握手失败时再用 curl 复核一次主页连通性:只有两者都不通
240
- // 才判「网络不通」;仅握手失败(仓库不存在、私有仓库、需要凭据)放行,
241
- // 交给后续预检与真实安装给出准确原因。
242
- // 探针只握手仓库本身(去掉 git+ 前缀与 #ref 片段):ls-remote 认的是仓库地址,
243
- // 带 ref 片段会干扰 URL 解析
244
- const gitProbeTarget = repoTarget === null ? null : repoTarget.replace(/^git\+/, '').replace(/#.*$/, '')
245
- let net: Awaited<ReturnType<typeof probeUrl>>
246
- if (gitProbeTarget !== null) {
247
- net = await gitLsRemote(gitProbeTarget, effectiveProxy, 6000)
248
- if (!net.ok) {
249
- const reachable = await probeUrl('https://github.com/', effectiveProxy, 6000)
250
- if (reachable.ok) net = reachable
251
- }
252
- } else {
253
- net = await probeUrl(httpProbeTarget, effectiveProxy, 6000)
254
- }
255
- const probeTarget = gitProbeTarget ?? httpProbeTarget
141
+ const probeTarget = `${(settings.npmRegistry.replace(/\/+$/, '') || 'https://registry.npmjs.org')}/`
142
+ const net = await probeUrl(probeTarget, effectiveProxy, 6000)
256
143
  if (!net.ok) {
257
- // 错误消息按客户端界面语言提示:中文界面给中文、英文界面给英文,
258
- // 让用户一眼看懂是网络问题而非插件问题
259
- const channelName = isGitChannel
260
- ? (lang === 'zh' ? 'GitHub' : 'github.com')
261
- : (lang === 'zh' ? 'npm 源' : 'the npm registry')
144
+ // 错误消息按界面语言输出,让用户看清是网络问题而非插件问题
262
145
  const error = lang === 'zh'
263
- ? `[network] 安装已中止:安装前无法连接到 ${channelName}(${probeTarget})—— 您的网络似乎不通或被拦截(断网 / DNS 解析失败 / 防火墙 / 代理配置问题)。这不是插件本身的问题,请检查网络连接或代理设置,运行「系统诊断」检测各通道连通性后重试。`
264
- : `[network] install aborted: cannot reach ${channelName} (${probeTarget}) before install — your network connection appears to be down or blocked (DNS / proxy / firewall). This is not a problem with the plugin itself. Check your connection or proxy settings, run the connectivity diagnostic, then retry.`
146
+ ? `[network] 安装已中止:安装前无法连接到 npm 源(${probeTarget})—— 您的网络似乎不通或被拦截(断网 / DNS 解析失败 / 防火墙 / 代理配置问题)。这不是插件本身的问题,请检查网络连接或代理设置,运行「系统诊断」检测各通道连通性后重试。`
147
+ : `[network] install aborted: cannot reach the npm registry (${probeTarget}) before install — your network connection appears to be down or blocked (DNS / proxy / firewall). This is not a problem with the plugin itself. Check your connection or proxy settings, run the connectivity diagnostic, then retry.`
265
148
  sendJson(response, 400, { error, attempts })
266
149
  return
267
150
  }
268
151
  }
269
- // 安装前预检:仅新安装走预检(github 源分发缺 package.json 声明的文件时直接拦截)。
270
- // 更新是已信任目标的覆盖重装,跳过预检避免重复下载 tarball。
271
- // npm 包信任 registry 直接放行;github 源拦截时标记 [packaging] 前缀,
272
- // 供客户端归类为「插件分发不完整」并引导去仓库提 Issue
273
- if (already === null) {
274
- const preflight = await preflightTarget(target)
275
- if (!preflight.ok) {
276
- // 预检拦截(git 分发缺作者声明的文件):同步 400 返回,附上已尝试的安装方式,
277
- // 客户端失败弹窗提 Issue 时一并贴给作者
278
- sendJson(response, 400, {
279
- error: `[packaging] ${target}: plugin distribution is incomplete — the file ${preflight.missing ?? '?'} the package needs (its declared entry, an entry a bundled patch mounts, or the patch itself) is not present in the git distribution (build output not committed). Report to the author.`,
280
- attempts,
281
- })
282
- return
283
- }
284
- // 包名冲突检测(仅 git 通道):git 目标包内声明的 name 若与 profile 已装依赖同名,
285
- // pnpm 会以该 name 做依赖键撞车,抛出的 CLI 报错晦涩难懂 —— 且该包名在 registry 上
286
- // 可能被别的仓库占用,npm 反查搜不到,git 直装就会撞上已装的同名依赖。
287
- // 到这里已装依赖要么来源不同仓库、要么 spec 是版本号解析不出仓库身份。
288
- // 读 node_modules 里已装包的真实 repository 区分两种情况:
289
- // - 指向同一仓库 → 是「同仓库残留」(spec 丢了仓库身份),就地转 update 覆盖重装(幂等);
290
- // - 指向别的仓库 / 读不到 → 跨仓库包名冲突,入队前转成明确 409,指导用户先卸载或改装。
291
- if (preflight.name !== null && repoTarget !== null && target === repoTarget) {
292
- const declared = preflight.name
293
- if (installed[declared] !== undefined) {
294
- const installedRepo = installedRepoOf(profile, declared)
295
- if (installedRepo !== null && gitRepo !== null && installedRepo.toLowerCase() === gitRepo.toLowerCase()) {
296
- // 同名且同源:已装 spec 丢了仓库身份导致的残留,直接按 update 覆盖重装,不打扰用户
297
- attempts.push(`same-repo residual: \`${declared}\` resolves to \`${installedRepo}\` → reinstall as update`)
298
- mode = 'update'
299
- } else {
300
- attempts.push(`package name conflict: \`${gitRepo}\` declares npm name \`${declared}\`, which is already present in the profile and cannot be matched to this repo (that npm name is likely registered by another repository)`)
301
- const error = lang === 'zh'
302
- ? `already installed: ${declared} —— ${gitRepo} 声明的 npm 包名「${declared}」已存在于当前 profile,且无法匹配到本仓库(该包名在 npm 上可能被其他仓库占用)。请先移除现有的 ${declared}(dsh plugin remove ${declared}),再重新安装;或改装该包名对应的官方 npm 包。`
303
- : `already installed: ${declared} — ${gitRepo} declares the npm package name "${declared}", which is already present in the profile and cannot be matched to this repo (that npm name is likely registered by another repository). Remove the existing ${declared} dependency (dsh plugin remove ${declared}) first, then retry; or install the official npm package under that name.`
304
- sendJson(response, 409, { error, attempts })
305
- return
306
- }
307
- }
308
- }
309
- }
310
- // 入队前复检(与上方检查同语义,但必须在同步块内):preflight 的 await 期间并发请求
311
- // 可能已通过上方检查、任务却尚未入队——此处检查与 startPluginMutation 之间无 await,
312
- // JS 单线程保证同一目标至多一个任务,杜绝双击/并发产生双任务
152
+ // 入队前复检:网络探测的 await 期间并发请求可能已通过上方检查,而此处到 startPluginMutation
153
+ // 之间无 await,JS 单线程保证同一目标至多一个任务,杜绝双击/并发双任务。
313
154
  if (hasQueuedTarget(target)) {
314
155
  sendJson(response, 409, { error: `already queued: ${target}` })
315
156
  return
316
157
  }
317
- // Kick off the CLI in the background; the client polls /status for progress
158
+ // 后台启动 CLI;客户端轮询 /status 获取进度
318
159
  const task = startPluginMutation({
319
160
  // mode=update(已安装目标的覆盖更新)以 update 动作入队:
320
161
  // 日志按 update 类别落盘(update.start/done/fail),实际 CLI 执行仍是 add <target>@latest
321
162
  action: mode === 'update' ? 'update' : 'add',
322
163
  profile,
323
164
  target,
324
- // npm 安装时 target 是包名:displayTarget 固定展示仓库名,待重启行/前端恢复不受通道变化影响
165
+ // npm 安装时 target 是包名:displayTarget 固定展示仓库名,待重启行/前端恢复不因安装目标形态而变
325
166
  displayTarget: githubRepoOf(displayRepo) ?? undefined,
326
- // 已尝试的安装方式(npm 反查):实际执行命令由 spawn 时追加,失败 issue 一并展示
327
- attempts,
328
- timeoutMs: COMMAND_TIMEOUT_MS,
329
- env: mutationEnv(settings),
330
- // 覆盖更新:npm 通道命令显式 @latest(pnpm add 无版本对已存在依赖是幂等的,不加版本不会真更新)
167
+ // 覆盖更新:npm 命令显式 @latest(pnpm add 无版本对已存在依赖是幂等的,不加版本不会真更新)
331
168
  updateNpm: mode === 'update',
332
169
  // 运行中 loader:安装成功后把新插件热挂进 loader,非桌面端 + 纯服务端插件无需重启即生效
333
170
  loader,
334
- // 自定义安装入口渠道(NPM 包 / GitHub 源码 / DSH 命令卡片):日志/报错据此溯源
171
+ timeoutMs: COMMAND_TIMEOUT_MS,
172
+ env: mutationEnv(settings),
173
+ // 自定义安装入口渠道:日志/报错据此溯源
335
174
  installChannel,
336
175
  })
337
176
  sendJson(response, 200, { ok: true, task: task.id })
@@ -3,8 +3,7 @@
3
3
  * Website: https://dsh-plugin.org
4
4
  * GitHub: https://github.com/dshplugin/dsh-plugin-hub
5
5
  *
6
- * Log routes: paginated log viewer, clearing, reveal-in-file-manager and the
7
- * native folder picker for choosing a log directory.
6
+ * 日志路由:分页日志查看器、清空、在文件管理器中定位,以及选择日志目录的原生文件夹选择器。
8
7
  */
9
8
  import { spawn } from 'node:child_process'
10
9
  import { dirname } from 'node:path'