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
@@ -3,23 +3,19 @@
3
3
  * Website: https://dsh-plugin.org
4
4
  * GitHub: https://github.com/dshplugin/dsh-plugin-hub
5
5
  *
6
- * Installed-plugin version tracking.
6
+ * 已安装插件版本追踪。
7
7
  *
8
- * The installed table (`readInstalled` in routes.ts) only knows the manifest
9
- * spec of each Git dependency, which carries no version.
10
- * To let the Plugin Hub tell "an update is available", we record the catalog
11
- * signal present at install time into a small per-profile JSON file, then
12
- * compare it against the catalog's current signal later.
8
+ * 已安装表(routes.ts 的 `readInstalled`)只知道每个 Git 依赖的 manifest spec,不含版本号。
9
+ * 为让插件中心能判断「有更新」,我们把安装时的目录信号记进一个 per-profile 的小 JSON 文件,
10
+ * 之后再与目录当前信号比对。
13
11
  *
14
- * Two signals cover every repo:
15
- * - version: the catalog's latest release tag (e.g. v1.2.3). Repos that
16
- * publish releases are compared on this.
17
- * - updatedAt: the repo's last push time (GitHub pushed_at, `repoUpdatedAt`).
18
- * Repos that never publish a release fall back to this: a newer push time
19
- * means new commits → an update is available.
12
+ * 两个信号覆盖所有仓库:
13
+ * - version:目录最新 release tag(如 v1.2.3),发 release 的仓库按它比对。
14
+ * - updatedAt:仓库最近 push 时间(GitHub pushed_at,即 `repoUpdatedAt`),
15
+ * 从不发 release 的仓库回退用它:push 时间变新即有新提交 → 有更新。
20
16
  *
21
- * Storage: `DSH_HOME/profiles/<profile>/gro.ngilp-hsd-versions.json`
22
- * { "<owner>/<repo>" (lowercase): { version: string, updatedAt: string, installedAt: string } }
17
+ * 存储:`DSH_HOME/profiles/<profile>/gro.ngilp-hsd-versions.json`
18
+ * { "<owner>/<repo>"(小写): { version, updatedAt, installedAt } }
23
19
  */
24
20
  import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
25
21
  import { homedir } from 'node:os';
@@ -36,20 +32,18 @@ export function readInstalledVersions(profile) {
36
32
  return {};
37
33
  }
38
34
  }
39
- /** Record the catalog signals (version + repo updated time) present at install time for one repo. */
35
+ /** 记录某仓库安装时的目录信号(版本 + 仓库更新时间)。 */
40
36
  export function recordInstalledVersion(profile, repo, version, updatedAt) {
41
37
  const table = readInstalledVersions(profile);
42
38
  const key = repo.toLowerCase();
43
- // 合并写入:保留已记录的 npmPackage(npm 优先通道的 repo → 包名映射),
39
+ // 合并写入:保留已记录的 npmPackage(repo → 包名映射),
44
40
  // 客户端同步版本信号时不能把它覆盖掉
45
41
  table[key] = { ...table[key], version, updatedAt, installedAt: new Date().toISOString() };
46
42
  writeVersions(profile, table);
47
43
  }
48
44
  /**
49
- * Record the npm package name resolved for a repo (npm-first install channel).
50
- * Called at `/install` time so the mapping exists even before the task finishes;
51
- * harmless when the repo is not (yet) installed — the client only treats a repo
52
- * as installed when its dependency key actually exists.
45
+ * 记录某仓库解析出的 npm 包名。在 `/install` 时调用,让映射在任务完成前就存在;
46
+ * 仓库尚未安装时也无害 —— 客户端只在依赖 key 真实存在时才把仓库当作已安装。
53
47
  */
54
48
  export function recordResolvedNpmPackage(profile, repo, npmPackage) {
55
49
  const table = readInstalledVersions(profile);
@@ -57,7 +51,7 @@ export function recordResolvedNpmPackage(profile, repo, npmPackage) {
57
51
  table[key] = { ...table[key], npmPackage };
58
52
  writeVersions(profile, table);
59
53
  }
60
- /** Forget the recorded version for one repo (called on uninstall). */
54
+ /** 清除某仓库记录的版本(卸载时调用)。 */
61
55
  export function removeInstalledVersion(profile, repo) {
62
56
  const table = readInstalledVersions(profile);
63
57
  delete table[repo.toLowerCase()];
@@ -11,7 +11,7 @@ import { homedir } from 'node:os';
11
11
  import { basename, dirname, join } from 'node:path';
12
12
  import { PACKAGE_RE, REPO_RE } from '../install/install-types.js';
13
13
  import { githubReleaseTarget } from '../install/release-target.js';
14
- /** Resolve the active profile from the booted CLI args, falling back to `web`. */
14
+ /** 从启动参数解析当前 profile,取不到落回 `web`。 */
15
15
  export function readProfileArg(fallback = 'web') {
16
16
  return profileFromArgv(process.argv, fallback);
17
17
  }
@@ -46,44 +46,18 @@ export function profileFromArgv(argv, fallback = 'web') {
46
46
  }
47
47
  return fallback;
48
48
  }
49
- /** Resolve a profile directory (`DSH_HOME` or `~/.dsh`). */
49
+ /** 解析 profile 目录(`DSH_HOME` 或 `~/.dsh`)。 */
50
50
  export function profileDirectory(profile) {
51
51
  return join(process.env.DSH_HOME ?? join(homedir(), '.dsh'), 'profiles', profile);
52
52
  }
53
- /** Build a safe explicit HTTPS Git target, or null when the repo is unsafe.
54
- * When `ref` is given it is appended as a Git ref (`#tag` / `#commit`) so an
55
- * explicitly pinned revision reaches the installer instead of being dropped. */
53
+ /** 把仓库身份转成规范的 GitHub 目标(git+https),仓库不合法时返回 null。
54
+ * 带 ref 时按 Git ref(`#tag` / `#commit`)拼接;安装通道已不再使用 git 目标,此函数仅做身份规范化。 */
56
55
  export function githubTarget(repo, ref) {
57
56
  if (typeof repo !== 'string' || !REPO_RE.test(repo))
58
57
  return null;
59
58
  const url = `git+https://github.com/${repo}.git`;
60
59
  return ref === undefined || ref === null || ref === '' ? url : `${url}#${ref}`;
61
60
  }
62
- /**
63
- * Extract a validated explicit Git ref (`#<ref>`) from a GitHub spec, or null.
64
- * Only the fragment of a Git-style address qualifies — a pinned tag/commit is
65
- * user intent and must survive target normalization, whereas `#…` on a plain
66
- * web URL (`https://github.com/o/r#readme`) is a page anchor, not a ref.
67
- * Git-style = `git+…` / `github:` / `git@…` / `…​.git` / bare `owner/repo`.
68
- * Grammar mirrors a Git ref: no leading `.`/`-`, no `#`/whitespace.
69
- */
70
- const GIT_REF_RE = /^[A-Za-z0-9][A-Za-z0-9._/-]*$/;
71
- export function githubRefOf(value) {
72
- if (typeof value !== 'string')
73
- return null;
74
- const input = value.trim();
75
- const hash = input.indexOf('#');
76
- if (hash <= 0)
77
- return null;
78
- const base = input.slice(0, hash);
79
- if (githubRepoOf(base) === null)
80
- return null;
81
- const gitStyle = /^(?:git\+|github:|git@)/i.test(base) || /\.git$/i.test(base) || !base.includes('://');
82
- if (!gitStyle)
83
- return null;
84
- const ref = input.slice(hash + 1);
85
- return GIT_REF_RE.test(ref) ? ref : null;
86
- }
87
61
  /**
88
62
  * DSH 命令行前缀(官方唯一形式 `dsh plugin --profile <name> <add|update> <target>`)—— 提取其中的安装目标;
89
63
  * 非命令输入原样返回。兼容「直接粘贴完整命令」(防用户输错):--profile 必填且只有长选项
@@ -114,7 +88,7 @@ export function globalNpmPackagesOf(value) {
114
88
  return null;
115
89
  return packages;
116
90
  }
117
- /** Extract an owner/repo identity from a catalog value or an installed Git spec. */
91
+ /** 从目录值或已装 Git spec 中提取 owner/repo 身份。 */
118
92
  export function githubRepoOf(value) {
119
93
  if (typeof value !== 'string')
120
94
  return null;
@@ -142,23 +116,22 @@ export function githubRepoOf(value) {
142
116
  }
143
117
  return null;
144
118
  }
145
- /** Validate an npm package name (uninstall target grammar). */
119
+ /** 校验 npm 包名(卸载目标的语法)。 */
146
120
  export function validPackageName(name) {
147
121
  return typeof name === 'string' && PACKAGE_RE.test(name);
148
122
  }
149
123
  /**
150
- * The exact `allowBuilds` key pnpm printed in its
151
- * `ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED` hint. For Git installs pnpm
152
- * matches against `name@<resolved fetch URL>` — the URL it actually fetches,
153
- * e.g. `https://codeload.github.com/<owner>/<repo>/tar.gz/<commit>` — not the
154
- * `git+ssh://`/branch spec. A bare name or a `git+` spec does not match, so
155
- * the only reliable key is the one pnpm prints verbatim. Null when absent.
124
+ * 取 pnpm 在 `ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED` 提示里原样打印的 `allowBuilds` key。
125
+ * Git 安装时 pnpm 按 `name@<实际 fetch URL>`(如
126
+ * `https://codeload.github.com/<owner>/<repo>/tar.gz/<commit>`)匹配,而不是 `git+ssh://`
127
+ * 或分支 spec —— 裸包名与 `git+` spec 都匹配不上,唯一可靠的 key 就是 pnpm 原样输出的那个。
128
+ * 无则返回 null。
156
129
  */
157
130
  export function parseAllowBuildsKey(output) {
158
131
  const m = /^[ \t]*(\S+@\S+):[ \t]*true[ \t]*$/m.exec(output);
159
132
  return m === null ? null : m[1].trim();
160
133
  }
161
- /** Quote a YAML block-mapping key when a plain scalar would be invalid. */
134
+ /** 当裸标量非法时,为 YAML 块映射 key 加引号。 */
162
135
  function quoteYamlKey(key) {
163
136
  if (/^[-?:,[\]{}#&*!|>'"%@`]/.test(key) || /:(\s|$)/.test(key)) {
164
137
  return `'${key.replace(/'/g, "''")}'`;
@@ -166,10 +139,9 @@ function quoteYamlKey(key) {
166
139
  return key;
167
140
  }
168
141
  /**
169
- * Add one `allowBuilds` entry to the profile's pnpm-workspace.yaml, merging
170
- * with existing entries and leaving the rest of the yaml intact. Broken
171
- * placeholder entries (pnpm's failed-install bug writes a literal
172
- * `set this to true or false` value) are dropped on rewrite.
142
+ * 向 profile 的 pnpm-workspace.yaml 追加一条 `allowBuilds` 记录:与已有条目合并,
143
+ * 其余 yaml 保持不变;重写时丢弃损坏的占位条目(pnpm 安装失败的 bug 会写入
144
+ * 字面量 `set this to true or false`)。
173
145
  */
174
146
  export function addAllowBuildsKey(profile, key) {
175
147
  const file = join(profileDirectory(profile), 'pnpm-workspace.yaml');
@@ -177,7 +149,7 @@ export function addAllowBuildsKey(profile, key) {
177
149
  try {
178
150
  yaml = readFileSync(file, 'utf8');
179
151
  }
180
- catch { /* created below */ }
152
+ catch { /* 文件不存在,下方创建 */ }
181
153
  const eol = /\r\n/.test(yaml) ? '\r\n' : '\n';
182
154
  const blockRe = /allowBuilds:[ \t]*\r?\n((?:[ \t]+[^\r\n]*\r?\n?)*)/g;
183
155
  const map = new Map();
@@ -3,22 +3,19 @@
3
3
  * Website: https://dsh-plugin.org
4
4
  * GitHub: https://github.com/dshplugin/dsh-plugin-hub
5
5
  *
6
- * Pure progress-estimation helpers shared by the install runner.
6
+ * 安装执行器共用的纯进度估算工具。
7
7
  *
8
- * The dsh CLI wraps pnpm, which refreshes its `Progress: …` line in place
9
- * with carriage returns, so raw output arrives as a stream of partial
10
- * fragments. These helpers normalize one fragment into a clean terminal
11
- * line and map it onto a 0-100 estimate; keeping them free of I/O makes the
12
- * estimation logic directly unit-testable (see tests/progress.test.ts).
8
+ * dsh CLI 包装了 pnpm,pnpm 用回车原地刷新 `Progress: …` 行,因此原始输出是一串碎片。
9
+ * 这些工具把单个碎片归一化成干净的终端行,并映射到 0-100 估算值;不碰 I/O
10
+ * 让估算逻辑可直接单测(见 tests/progress.test.ts)。
13
11
  */
14
- /** Strip the `[out]` / `[err]` source prefix and ANSI escape sequences. */
12
+ /** 剥掉 `[out]` / `[err]` 来源前缀与 ANSI 转义序列。 */
15
13
  export function cleanLine(raw) {
16
14
  return raw.replace(/^\[(?:err|out)\]\s*/, '').replace(/\x1b\[[0-9;]*[A-Za-z]/g, '').trim();
17
15
  }
18
16
  /**
19
- * Estimate 0-100 progress from one CLI output line. pnpm emits
20
- * `Progress: resolved N, reused X, downloaded Y, added Z` during the fetch
21
- * phase; resolution/install phase lines bump the estimate towards done.
17
+ * 从单行 CLI 输出估算 0-100 进度。pnpm 在 fetch 阶段输出
18
+ * `Progress: resolved N, reused X, downloaded Y, added Z`;解析/安装阶段的行把估算值推向完成。
22
19
  */
23
20
  export function estimateProgress(line) {
24
21
  const progress = line.match(/Progress:\s*(.+)/);
@@ -26,7 +23,7 @@ export function estimateProgress(line) {
26
23
  let resolved = 0;
27
24
  let handled = 0;
28
25
  for (const part of progress[1].split(',')) {
29
- // pnpm emits `label count` tokens, e.g. `resolved 100, reused 40`
26
+ // pnpm 输出 `label count` 形式的 token,如 `resolved 100, reused 40`
30
27
  const [label, raw] = part.trim().split(/\s+/);
31
28
  const value = Number(raw);
32
29
  if (label === 'resolved')
@@ -3,9 +3,8 @@
3
3
  * Website: https://dsh-plugin.org
4
4
  * GitHub: https://github.com/dshplugin/dsh-plugin-hub
5
5
  *
6
- * Hub settings persistence: one `hub-settings.json` per active profile
7
- * (next to pnpm-workspace.yaml). All fields optional; missing keys fall
8
- * back to DEFAULT_SETTINGS so old files stay readable as new options land.
6
+ * 插件中心设置持久化:每个活跃 profile 一个 `hub-settings.json`(与 pnpm-workspace.yaml 同目录)。
7
+ * 所有字段可选;缺失的 key 回退到 DEFAULT_SETTINGS,新选项上线后旧文件仍可读。
9
8
  */
10
9
  import { readFileSync, writeFileSync, mkdirSync, rmSync } from 'node:fs';
11
10
  import { dirname, join } from 'node:path';
@@ -15,8 +14,6 @@ export const DEFAULT_SETTINGS = {
15
14
  proxy: '',
16
15
  npmRegistry: '',
17
16
  enableNpmInstall: true,
18
- enableGitInstall: true,
19
- enableDshInstall: true,
20
17
  logPath: '',
21
18
  };
22
19
  export function settingsFile(profile) {
@@ -1,6 +1,6 @@
1
1
  import { type WebRoute, type WebServerService } from './shared.ts';
2
2
  export declare function profileDirectory(profile: string): string;
3
- /** Read non-official dependencies installed into one profile. */
3
+ /** 读取安装进某 profile 的非官方依赖。 */
4
4
  export declare function readInstalled(profile: string): Record<string, string>;
5
5
  /** 读已装依赖实际落在磁盘上的仓库身份(`owner/repo`):解析 node_modules/<name>/package.json
6
6
  * 的 repository 字段。已装 spec 可能是纯版本号(丢了仓库身份),但真实包元数据仍指向来源仓库,
@@ -3,8 +3,8 @@
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
9
  import { type LoaderHandle } from '../services/install/install.ts';
10
10
  import { type WebRoute, type WebServerService } from './shared.ts';
@@ -0,0 +1,2 @@
1
+ import { type WebRoute, type WebServerService } from './shared.ts';
2
+ export declare function registerNpmReleaseAgeRoutes(webServer: WebServerService, profile: string): WebRoute[];
@@ -3,24 +3,22 @@
3
3
  * Website: https://dsh-plugin.org
4
4
  * GitHub: https://github.com/dshplugin/dsh-plugin-hub
5
5
  *
6
- * Local HTTP routes exposing real installs to the in-app Plugin Hub UI.
7
- * The client fetches the same-origin `/dsh-plugin-hub/*` endpoints; the
8
- * install handler validates the target, then spawns the official dsh CLI
9
- * (see services/install/install.ts) and reports the captured result back.
6
+ * 本地 HTTP 路由:把真实安装能力暴露给应用内的插件中心 UI。客户端请求同源
7
+ * `/dsh-plugin-hub/*` 端点;安装处理校验目标后 spawn 官方 dsh CLI(见
8
+ * services/install/install.ts)并回传捕获的结果。
10
9
  */
11
10
  import { type LoaderHandle } from '../services/install/install.ts';
12
11
  import { type WebServerService } from './shared.ts';
13
12
  /**
14
- * Register the Plugin Hub API on the host web server and return a disposer.
15
- * @param webServer - DSH web server service.
16
- * @param profile - profile that owns plugin mutations.
17
- * @param loader - running loader (optional): lets uninstall remove the entry
18
- * immediately so the page survives a refresh without a host restart.
13
+ * 在宿主 web server 上注册插件中心 API 并返回 dispose 函数。
14
+ * @param webServer - DSH web server 服务。
15
+ * @param profile - 拥有插件变更权限的 profile。
16
+ * @param loader - 运行中 loader(可选):让卸载立即移除条目,页面刷新即生效、无需重启宿主。
19
17
  */
20
18
  export declare function mountPluginHubRoutes(webServer: WebServerService, profile: string, loader?: LoaderHandle): () => void;
21
- /** Profile resolution shared with the client route docs. */
19
+ /** 与客户端路由文档共用的 profile 解析。 */
22
20
  export { readProfileArg } from '../services/install/install.ts';
23
- /** Re-exported so the host entry (index.ts) keeps importing it from this module. */
21
+ /** 转出以便宿主入口(index.ts)继续从本模块引入。 */
24
22
  export type { WebServerService } from './shared.ts';
25
- /** Re-exported so tests/routes.test.ts keeps importing these from this module. */
23
+ /** 转出以便 tests/routes.test.ts 继续从本模块引入。 */
26
24
  export { isDesktopHost, isSameOrigin } from './shared.ts';
@@ -3,9 +3,8 @@
3
3
  * Website: https://dsh-plugin.org
4
4
  * GitHub: https://github.com/dshplugin/dsh-plugin-hub
5
5
  *
6
- * Shared HTTP utilities: route/service types, request validation helpers and
7
- * the same-origin check guarding every POST mutation. Imported by the other
8
- * route modules in this directory.
6
+ * 共享 HTTP 工具:路由/服务类型、请求校验助手,以及守卫每个 POST 变更的同源校验。
7
+ * 由本目录其它路由模块引入。
9
8
  */
10
9
  import type { IncomingMessage, ServerResponse } from 'node:http';
11
10
  /**
@@ -26,7 +25,7 @@ export interface WebRoute {
26
25
  path: string;
27
26
  handler: (request: IncomingMessage, response: ServerResponse) => void | Promise<void>;
28
27
  }
29
- /** The subset of the host web-server service this plugin touches. */
28
+ /** 本插件用到的宿主 web-server 服务子集。 */
30
29
  export interface WebServerService {
31
30
  register(route: WebRoute): () => void;
32
31
  }
@@ -36,8 +35,8 @@ export declare const COMMAND_TIMEOUT_MS: number;
36
35
  * 不重复走 curl 拉远程 —— 重启宿主后首次打开同样秒开(缓存跨重启存活)。 */
37
36
  export declare const CATALOG_CACHE_TTL_MS: number;
38
37
  export declare function sendJson(response: ServerResponse, status: number, value: unknown): void;
39
- /** POST mutations are only accepted from the local web server origin or the desktop host page.
40
- * Exported for tests (tests/routes.test.ts) — the origin check is the whole CSRF defence. */
38
+ /** POST 变更只接受来自本地 web server 来源或桌面宿主页面。转出供测试(tests/routes.test.ts)使用 ——
39
+ * 来源校验就是全部的 CSRF 防御。 */
41
40
  export declare function isSameOrigin(request: IncomingMessage): boolean;
42
41
  export declare function requireMethod(request: IncomingMessage, response: ServerResponse, method: 'GET' | 'POST'): boolean;
43
42
  export declare function requireTrustedPost(request: IncomingMessage, response: ServerResponse): boolean;
@@ -3,18 +3,17 @@
3
3
  * Website: https://dsh-plugin.org
4
4
  * GitHub: https://github.com/dshplugin/dsh-plugin-hub
5
5
  *
6
- * dsh-plugin host entry: mounts the Plugin Hub HTTP routes once the host
7
- * web server service is available. The browser bundle (src/client) talks to
8
- * these same-origin routes to perform real installs from inside the app.
6
+ * dsh-plugin 宿主入口:宿主 webServer 服务就绪后挂载插件中心的 HTTP 路由。
7
+ * 浏览器 bundle(src/client)通过这些同源路由在应用内执行真正的安装。
9
8
  */
10
9
  import { type LoaderHandle } from './services/install/install.ts';
11
10
  import { type WebServerService } from './http/routes.ts';
12
11
  export declare const name = "dsh-plugin";
13
12
  export interface Config {
14
- /** DSH profile that owns plugin mutations. Defaults to the booted profile. */
13
+ /** 拥有插件变更权限的 DSH profile,缺省用启动时的 profile。 */
15
14
  profile?: string;
16
15
  }
17
- /** The subset of the cordis host context this plugin touches. */
16
+ /** 本插件用到的 cordis 宿主上下文子集。 */
18
17
  interface HostContext {
19
18
  webServer: WebServerService;
20
19
  /** 运行中 loader:卸载成功后主动移除条目、立即生效(宿主未提供时卸载仍需重启) */
@@ -23,9 +22,9 @@ interface HostContext {
23
22
  effect(callback: () => void, label?: string): void;
24
23
  }
25
24
  /**
26
- * Mount the Plugin Hub routes after the web server service becomes available.
27
- * @param ctx - cordis host context.
28
- * @param config - optional profile override.
25
+ * webServer 服务就绪后挂载插件中心路由。
26
+ * @param ctx - cordis 宿主上下文。
27
+ * @param config - 可选的 profile 覆盖。
29
28
  */
30
29
  export declare function apply(ctx: HostContext, config?: Config): void;
31
30
  export {};
@@ -15,27 +15,26 @@ export interface InstallResult {
15
15
  }
16
16
  export interface InstallTask {
17
17
  id: number;
18
- /** 操作目标:显式 HTTPS Git URL(安装)或 npm 包名(卸载),冲突/恢复时需要展示给用户 */
18
+ /** 操作目标:npm 包名(安装、更新、卸载一致),冲突/恢复时需要展示给用户 */
19
19
  target: string;
20
20
  /** 展示用目标(owner/repo):npm 安装时 target 是包名,前端恢复用此字段显示仓库名,保持用户无感知 */
21
21
  displayTarget?: string;
22
- /** 尝试过的安装方式(npm registry 反查 + 实际执行的 CLI 命令,按先后顺序):
23
- * 失败提 Issue 时如实贴给作者,作者据此反推正确的 npm 包名(组织 scope 与 GitHub 用户名不一致时
24
- * 仅凭仓库名猜不到,作者看到我们查过/试过的命令就能直接指认)。 */
22
+ /** 尝试过的安装方式(实际执行过的 CLI 命令,按先后顺序):
23
+ * 失败提 Issue 时如实贴给作者,作者据此判断我们真正执行了什么。 */
25
24
  attempts: string[];
26
25
  /** 全局 npm 安装(官方 `npm install -g <pkgs>`):非空时任务执行全局 npm 安装,不进任何 profile */
27
26
  globalNpm?: string[];
28
27
  action: 'add' | 'remove' | 'update';
29
- /** 自定义安装入口渠道(客户端三张卡片:NPM 包 / GitHub 源码 / DSH 命令):
28
+ /** 自定义安装入口渠道(NPM 包卡片):
30
29
  * 任务输出行与系统日志据此溯源「从哪个入口发起」;目录插件安装无此字段。 */
31
- installChannel?: 'npm' | 'git' | 'dsh';
30
+ installChannel?: 'npm';
32
31
  /** 队列语义:pending 排队中 / running 执行中 / done / failed / cancelled(用户取消) */
33
32
  status: 'pending' | 'running' | 'done' | 'failed' | 'cancelled';
34
33
  timedOut: boolean;
35
34
  exitCode: number | null;
36
35
  /** 0-100 估算进度:解析 pnpm 的 `Progress: resolved…` 输出,阶段行兜底 */
37
36
  progress: number;
38
- /** Newest output lines first (consumer shows the tail). */
37
+ /** 输出行最新在前(消费方展示尾部)。 */
39
38
  lines: string[];
40
39
  /** 完成后是否仍需宿主重启才生效:仅「热挂载失败 / 非 dsh 插件 / 更新(ESM 缓存取不到新代码)/
41
40
  * 无 loader」等刷新解决不了的兜底场景为 true(弹窗给「立即重启」);其余一律 false。 */
@@ -66,7 +65,7 @@ export interface QueueItem {
66
65
  timeoutMs?: number;
67
66
  env?: NodeJS.ProcessEnv;
68
67
  globalNpm?: string[];
69
- installChannel?: 'npm' | 'git' | 'dsh';
68
+ installChannel?: 'npm';
70
69
  };
71
70
  }
72
71
  /**
@@ -74,20 +73,20 @@ export interface QueueItem {
74
73
  * 它自然清空,正好等于「重启后提醒消失」的语义,无需任何重启探测。
75
74
  */
76
75
  export interface PendingRestart {
77
- /** Git 安装目标(与任务一致;卸载时为展示用的 owner/repo) */
76
+ /** 安装目标(与任务一致;卸载时为展示用的 owner/repo) */
78
77
  target: string;
79
78
  /** 待重启语义:install 装完等挂载生效 / uninstall 卸完等清理 loader 残留 */
80
79
  kind: 'install' | 'uninstall';
81
80
  /** 任务完成时刻(epoch ms) */
82
81
  at: number;
83
82
  }
84
- /** Grammar of a catalog GitHub repository identity (`owner/repo`). */
83
+ /** 目录 GitHub 仓库身份(`owner/repo`)的语法。 */
85
84
  export declare const REPO_RE: RegExp;
86
- /** Grammar of an npm package name (used for uninstall targets). */
85
+ /** npm 包名的语法(用于卸载目标)。 */
87
86
  export declare const PACKAGE_RE: RegExp;
88
87
  /** 捕获输出上限:stdout/stderr 各保留尾部 N 字节。 */
89
88
  export declare const CAPTURE_LIMIT_BYTES: number;
90
- /** Max output lines kept per task (newest wins). */
89
+ /** 每个任务保留的最大输出行数(最新优先)。 */
91
90
  export declare const MAX_TASK_LINES = 200;
92
- /** Max tracked tasks; oldest finished tasks are dropped first. */
91
+ /** 最多跟踪的任务数;超出时先丢弃最早结束的任务。 */
93
92
  export declare const MAX_TASKS = 50;
@@ -18,5 +18,5 @@ export type { InstallResult, InstallTask, Invocation, PendingRestart, QueueItem
18
18
  export type { LoaderHandle } from '../loader.ts';
19
19
  export { addPendingRestart, clearPendingRestart, listPendingRestarts } from '../profile/pending-restart.ts';
20
20
  export { dumpLoaderEntries, removeLoadedEntry } from '../loader.ts';
21
- export { addAllowBuildsKey, githubRefOf, githubRepoOf, githubTarget, globalNpmPackagesOf, installTargetOf, parseAllowBuildsKey, readProfileArg, validPackageName, } from '../profile/profile.ts';
21
+ export { addAllowBuildsKey, githubRepoOf, githubTarget, globalNpmPackagesOf, installTargetOf, parseAllowBuildsKey, readProfileArg, validPackageName, } from '../profile/profile.ts';
22
22
  export { activeTask, cancelTask, getTask, hasQueuedTarget, hasRunningTask, runPluginMutation, startPluginMutation } from './task-queue.ts';
@@ -1,15 +1,3 @@
1
- /**
2
- * 反查 repo(`owner/repo`)对应的官方 npm 包名;未命中、网络异常或超时返回 null。
3
- * 返回 null 不代表仓库一定没有 npm 包,只代表本次未能确认 —— 调用方应保留
4
- * 原有错误路径,反查只是额外的一次尝试。只有「已确认」的结果(包名,或 200
5
- * 响应下确认无匹配)会进缓存;网络异常/超时/解析失败不缓存,同一会话内下次
6
- * 安装仍会重试反查,避免一次瞬时故障把整个会话锁死在 git 通道。
7
- * registry 参数:npm 镜像源地址,空串 = 官方源;与安装通道吃同一 registry,
8
- * 保证「配置了镜像」时反查和安装走同一个源(镜像节点同步完整时结果一致)。
9
- * proxy 参数:GitHub 改名跳转探测走的代理(与安装/诊断同一口径)。
10
- * 慢网络下失败不阻塞安装。
11
- */
12
- export declare function resolveNpmPackage(repo: string, registry?: string, proxy?: string): Promise<string | null>;
13
1
  type NpmSearchPackage = {
14
2
  name?: unknown;
15
3
  keywords?: unknown;
@@ -19,10 +7,10 @@ type NpmSearchPackage = {
19
7
  repository?: unknown;
20
8
  dsh?: unknown;
21
9
  };
22
- type NpmSearchObject = {
23
- package?: NpmSearchPackage;
24
- };
25
10
  export declare function isDshPackageMetadataForRepo(pkg: NpmSearchPackage, repo: string): boolean;
11
+ /**
12
+ * 校验包名对应的 npm 包确实属于该仓库且声明为 DSH 插件:取 registry 上的 `latest`
13
+ * 元数据比对 repository 与插件标记。网络异常、超时、非 200 一律返回 false,不阻塞调用方。
14
+ */
26
15
  export declare function isDshNpmPackageForRepo(packageName: string, repo: string, registry?: string, proxy?: string): Promise<boolean>;
27
- export declare function selectNpmPackageForRepo(objects: NpmSearchObject[], repo: string): string | null;
28
16
  export {};
@@ -4,17 +4,12 @@
4
4
  * GitHub: https://github.com/dshplugin/dsh-plugin-hub
5
5
  *
6
6
  * 分发文件解析:从 package.json 推出装完后必须真实存在的文件 —— 作者声明的入口
7
- * (exports["."] / main)与 bundle 声明的补丁(dsh.bundle.patch)。git 通道(tar 预检)
8
- * 与 npm 通道(装后 statSync 校验)共用,保证两条通道对同一个包判定一致。
7
+ * (exports["."] / main)与 bundle 声明的补丁(dsh.bundle.patch),供装后校验使用。
9
8
  *
10
- * 这里不替作者补一个 index.js:宿主加载一个 bundle 读的是它的 package.json 和它声明的
11
- * 补丁文件(官方 bundleManifest 的注释即「Read bundle metadata without loading its
12
- * JavaScript」),从不 import 包本身。凭空要求一个作者没声明的入口,只会把完整的
13
- * 技能包判成分发残缺,并把一条假缺陷推到作者仓库(见 QingYunA/answer-me-with-html#209)。
14
- *
15
- * 例外是补丁自己 mount 了本包:dsh 的《打包与安装插件》里组合包的常规写法就是
16
- * `- insert: - name: <本包名>`,宿主随后按包名 import 本包,入口那时必须存在。
17
- * 所以只有补丁真的写了自己的包名,才把这个入口算进分发要求。
9
+ * 只在包自己声明了入口时才要求它存在:宿主加载 bundle 读的是它的 package.json 与声明的补丁,
10
+ * 从不 import 包本身。硬要一个作者没声明过的 index.js,会把完整的包判成分发残缺、把一条假缺陷
11
+ * 推到作者仓库。例外是补丁自己 mount 了本包(组合包的常规写法)—— 那时宿主按包名 import 本包,
12
+ * 入口必须存在,所以只有补丁真的写了自己的包名才把这个入口算进分发要求。
18
13
  */
19
14
  /** 解析所需的 manifest 字段;其余字段不读。 */
20
15
  export interface PackageManifest {
@@ -36,7 +31,7 @@ export declare function resolvePackageEntry(meta: PackageManifest): string | nul
36
31
  /**
37
32
  * 解析 `dsh.bundle.patch` 声明的补丁文件(相对包根,不带 `./` 前缀)。
38
33
  * 形状不合规范(既不是字符串也不是字符串数组)在这里不判定:那是 dsh 启动时
39
- * bundlePatchFiles 的报错职责,预检只负责「声明了就要在包里存在」。
34
+ * bundlePatchFiles 的报错职责,装后校验只负责「声明了就要在包里存在」。
40
35
  */
41
36
  export declare function resolveBundlePatchFiles(meta: PackageManifest): string[];
42
37
  /** 分发里必须存在的全部文件:作者声明的入口,加上 bundle 声明的补丁,入口在前。
@@ -3,14 +3,13 @@
3
3
  * Website: https://dsh-plugin.org
4
4
  * GitHub: https://github.com/dshplugin/dsh-plugin-hub
5
5
  *
6
- * 预构建 GitHub release 安装目标(目录权威命令 → 可安装直链)。
7
- * 部分插件(如 loopx)把构建产物发布成 GitHub release 的 .tgz,仓库 HEAD 反而是
8
- * monorepo 根、走 git 直装会因缺入口文件失败;目录下发的权威安装命令直接指向该
9
- * release 包。这里把「目录命令」解析成安全的 release 目标,供客户端选路与服务端
10
- * 校验共用(单一事实来源,避免两端口径漂移)。
6
+ * 预构建 release 直链的仓库身份解析。部分插件(如 loopx)当初以 GitHub release 的 .tgz
7
+ * 安装过,仓库 HEAD 反而是 monorepo 根、走 git 直装会因缺入口文件失败;老安装记录里留的
8
+ * 就是这种 release 直链。这里把「历史安装目标」还原成所属仓库身份,供已装态读回、队列
9
+ * 去重与展示复用(单一事实来源,避免两端口径漂移)。
11
10
  *
12
11
  * 只接受固定形态的 HTTPS `github.com/<owner>/<repo>/releases/download/<tag>/<asset>.tgz`:
13
- * 目录命令是展示数据、绝非 shell 代码,绝不执行命令文本;跨仓跳转、外部主机、凭据、
12
+ * 输入是记录/展示数据、绝非 shell 代码,绝不执行其文本;跨仓跳转、外部主机、凭据、
14
13
  * 移动的 latest 链接、query/fragment、多余 CLI 参数与 shell 片段一律拒绝。
15
14
  */
16
15
  /** release 包目标及其所属仓库身份(owner/repo);非法返回 null。 */
@@ -21,8 +20,8 @@ export interface GithubReleaseTarget {
21
20
  repo: string;
22
21
  }
23
22
  /**
24
- * 解析一个 release 安装目标。
25
- * @param value - 目录命令(`dsh plugin --profile web add <url>`)或裸直链。
23
+ * 解析一个历史安装目标里的 release 直链。
24
+ * @param value - 完整命令(`dsh plugin --profile web add <url>`)或裸直链。
26
25
  * @returns 命中返回 `{ target, repo }`,否则 null。
27
26
  */
28
27
  export declare function githubReleaseTarget(value: string): GithubReleaseTarget | null;